0

https://github.com/mageplaza/magento-2-product-slider

When using the CMS shortcode for selecting a category:

{{block class="Mageplaza\Productslider\Block\CategoryId" template="Mageplaza_Productslider::productslider.phtml" products_count="8" heading="test heading" category_id="5" description="test"}}

the category_id field apparently is wrong/incorrect? My category 5 is a child category of the Default Category in Magento 2.2.7

I get the following error:

Error filtering template: Warning: Invalid argument supplied for foreach() in /Applications/MAMP/htdocs/MYFOLDER/vendor/mageplaza/magento-2-product-slider/Block/CategoryId.php on line 96

Can anyone help ASAP?

I have products within this category so it should be fine?

  • Put screenshot of your categories with selection of category which have id 5. – Saurabh Dwivedi Jan 8 '19 at 16:48
0

The issue with the Magento version some of version its working fine and for some of version its not working.

To solve the problem, you should add the following code in 2 files:

  • app/code/Mageplaza/Productslider/Block/CategoryId.php
  • app/code/Mageplaza/Productslider/Block/AbstractSlider.php

-At Category.php file, change

foreach ($catIds as $catId) {
            $category   = $this->_categoryFactory->create()->load($catId);

in line 96 & 97 into

if ($this->getSlider()) {
            foreach ($catIds as $catId) {
                $category   = $this->_categoryFactory->create()->load($catId);
                $collection = $this->_productCollectionFactory->create()
                    ->addAttributeToSelect('*')
                    ->addCategoryFilter($category);

                foreach ($collection as $item) {
                    $productIds[] = $item->getData('entity_id');
                }
            }
        }
        if ($this->getData('category_id')) {
            $category   = $this->_categoryFactory->create()->load($catIds);

At AbstractSlider.php, change code in function getDisplayAdditional() into

public function getDisplayAdditional()
    {
        if($this->getSlider()) {
            $display = $this->getSlider()->getDisplayAdditional();
            if (!is_array($display)) {
                $display = explode(',', $display);
            }
        }
        else{
            $display = $this->_helperData->getModuleConfig('general/display_information');
            if (!is_array($display)) {
                $display = explode(',', $display);
            }
        }
        return $display;
    }

Reference :You can check the below Git URL they have given some solution :

https://github.com/mageplaza/magento-2-product-slider/issues/31

https://github.com/mageplaza/magento-2-product-slider/issues/49

| improve this answer | |

Your Answer

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

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