I need to alter the logic of "add product in a category" based on category rule.

enter image description here

My effort:

After add rule, When I save category, it redirects to http://host/admin/catalog/category/save/key/cae5eaa5332d3c8a4be400eb667530bfba2727445ce1a072d5f006f4a9f10be4/ but in that controller I'm not seeing any add product logic, in that controller dispatch event catalog_category_prepare_save while check I found one observer vendor/magento/module-visual-merchandiser/Observer/CategorySaveMerchandiserData.php are listening to this event, I have checked that observer too but I can't found where it is the add product logic.

Please help me to identify.



You tried wrong way. Try following way:

Open vendor/magento/module-visual-merchandiser/Observer/CatalogCategorySaveBefore.php Following line actually build this according to rule.


Now go to vendor/magento/module-visual-merchandiser/Model/Category/Builder.php

Following line build this:

$this->rules->applyAllRules($category, $collection);

Now finally open vendor/magento/module-visual-merchandiser/Model/Rules.php

And check here:

public function applyAllRules(
    \Magento\Catalog\Model\Category $category,
    \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
) {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.