Magento2: Intercept category moved inside tree

by gianis6   Last Updated August 24, 2018 17:09 PM

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="" 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" />

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...';

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?

Related Questions

Magento 2.1: Get ID of saved category

Updated February 24, 2017 19:09 PM

Magento 2: Plugin vs Observer

Updated May 15, 2018 22:09 PM

How to create plugin for observer magento2

Updated June 21, 2018 17:09 PM