I'm trying to render products the same as Magento_CatalogWidget::product/widget/content/grid.phtml displaying.

I have created a custom ajax controller.


        $block = $layout->createBlock('Vendor\Module\Block\Product\ProductsList')->setTemplate('Vendor_Module::product/widget/content/grid.phtml')

        $html = $block->toHtml();

        $result = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_RAW);
        return $result;

In Ajax response, I get the below error message:

1 exception(s): Exception #0 (Exception): Warning: foreach() argument must be of type array|object, null given in /var/www/html/development/vendor/magento/module-catalog-widget/Block/Product/ProductsList.php on line 406

#1 Magento\CatalogWidget\Block\Product\ProductsList->getConditions() called at [vendor/magento/module-catalog-widget/Block/Product/ProductsList.php:350]

  • Share the complete code which you try? Commented May 16 at 5:12
  • @DhirenVasoya I got an answer from the link magento.stackexchange.com/a/171667/112419. I have to add the setConditionsEncoded in the controller file instead of setProductCollection
    – Arun
    Commented May 16 at 5:41


Your Answer

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

Browse other questions tagged or ask your own question.