2

I am trying to intercept when a category is moved inside the category tree. At the beginning I thought to observe the event catalog_category_tree_move_after with an Observer class but I found that this event has been removed from Magento 2. In the CHANGELOG file it is said to use plugins instead of observers.

I tried to do with plugin with no success: this is the di.xml file

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Catalog\Model\Category">
        <plugin name="MoveCategoryTree" type="Vendor\Module\Model\Plugin\Category" sortOrder="1" />
    </type>
</config>

this is the Vendor/Module/Model/plugin/Category.php class

namespace Vendor\Module\Model\Plugin;

class Category
{
    public function afterCatalogCategoryTreeMove(\Magento\Catalog\Model\Category $category, $result) {
        echo 'Testing...';
        exit();
    }
}

I tried also to rename the function afterCatalogCategoryTreeMove in afterTreeMove but nothing works also in this way.

is this the correct way to intercept this event?

1 Answer 1

2

I looked at this briefly and couldn't find the method you were trying to write a plugin for. The method move does exist and should be appropriate for what you're trying to do, try the code below instead:

namespace Vendor\Module\Model\Plugin;

class Category
{
    public function afterMove(\Magento\Catalog\Model\Category $subject, $result) {
        echo 'Testing...';
        exit();
    }
}

I hope that helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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