public function aroundReindex(\Magento\Catalog\Model\Category $category, \Closure $proceed)
    {
        $proceed();

        // Reindex only if attached product list has changed.
        // This prevent reindexing if the category is just created and set to virtual.
        if ($category->dataHasChangedFor('is_virtual_category') && ($category->getIsChangedProductList() === true)) {
            if (((bool) $category->getIsVirtualCategory() === true) && ($category->getId())) {
                if (!$this->getIndexer()->isScheduled()) {
                    // Remove default root category (1) and Store Root.
                    $this->getIndexer()->reindexList(array_slice($category->getPathIds(), 2));
                }
            }
        }
    }
public function aroundReindex(\Magento\Catalog\Model\Category $category, \Closure $proceed)
    {
        $proceed();

        // Reindex only if attached product list has changed.
        // This prevent reindexing if the category is just created and set to virtual.
        if ($category->dataHasChangedFor('is_virtual_category') && ($category->getIsChangedProductList() === true)) {
            if (((bool) $category->getIsVirtualCategory() === true) && ($category->getId())) {
                if (!$this->getIndexer()->isScheduled()) {
                    // Remove default root category (1) and Store Root.
                    $this->getIndexer()->reindexList(array_slice($category->getPathIds(), 2));
                }
            }
        }
    }
public function aroundReindex ( \ Magento \ Catalog \ Model \ Category $ category , \ Closure $ proceed ) { $ proceed ( ) ; // Reindex only if attached product list has changed. // This prevent reindexing if the category is just created and set to virtual. if ( $ category -> dataHasChangedFor ( 'is_virtual_category' ) && ( $ category -> getIsChangedProductList ( ) === true ) ) { if ( ( ( bool ) $ category -> getIsVirtualCategory ( ) === true ) && ( $ category -> getId ( ) ) ) { if ( ! $ this -> getIndexer ( ) -> isScheduled ( ) ) { // Remove default root category (1) and Store Root. $ this -> getIndexer ( ) -> reindexList ( array_slice ( $ category -> getPathIds ( ) , 2 ) ) ; } } } }
Enforce reindexing of path ids if the category has just been set to 'is_virtual_category' = true.

@param \Magento\Catalog\Model\Category $category The category
@param \Closure                        $proceed  The Category::reindex() method
Enforce reindexing of path ids if the category has just been set to is_virtual_category = true .