This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

iSnaker
iSnaker

Hi everyone. In my project i making a promoaction functionality. Choosing some products by selecting in list. But I want to give functionality to add, for example, all products of a category. They should be attached just like they checked individually.

In backend form i made relation config that displays list of products and can attach them one by one. But how to show list of categories, which adds depending products by selecting one?

Last updated

Adrien - ACTE Solutions
Adrien - ACTE Solutions

Hello iSnaker, I believe you have 3 models? Promoaction, Product, Category?

hasManyThrough relationship might be helpful (https://octobercms.com/docs/database/relations#has-many-through)

Class Promoaction extends Model{
    public $hasManyThrough = [
        'products' => [
            'xxx\xxx\Models\Products',
            'through' => 'xxx\xxx\Models\Category'
        ],
    ];
}

You can show us a bit of your code if you need more help.

Cheers.

iSnaker
iSnaker

Adrien - ACTE Solutions said:

Hello iSnaker, I believe you have 3 models? Promoaction, Product, Category?

hasManyThrough relationship might be helpful (https://octobercms.com/docs/database/relations#has-many-through)

Class Promoaction extends Model{
   public $hasManyThrough = [
       'products' => [
           'xxx\xxx\Models\Products',
           'through' => 'xxx\xxx\Models\Category'
       ],
   ];
}

You can show us a bit of your code if you need more help.

Cheers.

Adrien, thank you for your answer!

This is not exactly, what I'm looking for. I need to configure backend form, not Model. So I believe I need properly setup Relation Config (https://octobercms.com/docs/api/backend/behaviors/relationcontroller) to show a list of categories, but on select one of them - add to relation all products of a selected category.

1-3 of 3

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.