$category = $this->categoryFactory->create()->load($categoryId);
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $collection = $objectManager->create('Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection');
    if ($category->getIsVirtualCategory()) {
        $queryFilter = $category->getVirtualRule()->getCategorySearchQuery($category);
    } else {

    echo "<pre>";

This piece of code is work in every where but i past this code on category save after event catalog_category_save_after it through exception

No such entity with id = 0 {"exception":"[object] (Magento\Framework\Exception\NoSuchEntityException(code: 0): No such entity with id = 0 at /var/www/html/vendor/magento/framework/Exception/NoSuchEntityException.php:50)"}

I don't understand why it through exception on observer.

I also try this code in plugin

<type name="Magento\Catalog\Model\Category">
    <plugin name="categoryaftersaveplugin" type="TM\WhiteListEmails\Model\CatgeoryAfterSave" />

But it not working.

I have also try to replace object manager with argument contructor

<type name="Vendor\ModuleName\Cron\GetVirtualCategory">
        <argument name="collectionFactory" xsi:type="object">Magento\CatalogSearch\Model\ResourceModel\Fulltext\CollectionFactory</argument>

but the same result does not work In the observer any suggestions about this?

Your Answer

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

Browse other questions tagged or ask your own question.