Jump to content

How to override product main_variants array by using filterProductSearch hook in prestashop 1.7.6


Recommended Posts

When i am trying to override the catalog product listing product main_variants data in filterProductSearch hook in prestashop 1.7.6 then i am getting below error.

Notice: Indirect modification of overloaded element of PrestaShop\PrestaShop\Adapter\Presenter\Product\ProductListingLazyArray has no effect

Here is my code:

if (Module::isInstalled($this->name) && Module::isEnabled($this->name)) {
            if ($params['searchVariables']['products'] && $this->configVals['ATS_SWATCH_IMAGE_CATALOG_ENABLE']) {
                foreach ($params['searchVariables']['products'] as &$product) {
                    if ($product['main_variants']) {
                        $productObj = new Product($product['id_product'], $product['id_lang']);
                        $combinationImages = $productObj->getCombinationImages($product['id_lang']);
                        foreach ($product['main_variants'] as &$variant) {
                            if (isset($combinationImages[$variant['id_product_attribute']][0]['id_image'])) {
                                $variant['html_color_code'] = '';
                                $variant['texture'] = $this->context->link->getImageLink(
                                    $product['link_rewrite'],
                                    $combinationImages[$variant['id_product_attribute']][0]['id_image'],
                                    ImageType::getFormattedName('small')
                                );
                            }
                        }
                    }
                }
            }
        }
        return $params;

This code is working perfectly in prestahop 1.7.3.2

 

Please help

Thanks

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...