1

I have an error that occurs in production only. And even then it is about 3/10 times that it occurs. Refresh, seems alright, refresh again, seems broken etc. On the staging site + my docker box it seems to work fine.

So the problem: The configurable product page is not being build 3 out of 10 times. Only a part of the following theme template is visible: Magento_ConfigurableProduct/templates/product/view/type/options/configurable.phtml .

The error starts from the $block->getJsonConfig() function in the template. It eventually calls on the function: $this->getData('media_gallery_images')->count(). This resides in: vendor/magento/module-catalog/Model/Product.php

This results in the error: Call to a member function count() on array.

The function: $this->getData('media_gallery_images') should always return an object as far as I know. So when it is an array it seem logical that it errors. I just cant figure out why it returns an array. Before that piece of code it also does the hasData check (with the setData) if it the check is false.

If you have an idea of the source of this problem, please post. I will investigate it then because I am at a loss at the moment.

Data: Magento 2.3.5 PHP 7.1.33

1
  • Could you specify where the script was located?
    – Marco
    Commented Jun 17, 2021 at 9:41

2 Answers 2

2

Turns out there was a script running on production that runs $this->setData on all products turning objects into arrays and thus crashing when it runs a pre-defined method $this->getData('media_gallery_images')->count().

2
  • I am having the same issue, could you explain the fix some more? Commented Jun 18, 2021 at 13:07
  • I have only been able to zoom into the problem, I have not been able to fix this
    – JerGrun
    Commented Jun 21, 2021 at 7:57
0

I found this bug too. Documented it on https://github.com/magento/magento2/issues/33965

It's an interaction between this collection cache and the Product model.

The collection cache via \Magento\ConfigurableProduct\Model\Plugin\Front\UsedProductsCache stores the loaded data for that product as serialized data and when the product is restored by getUsedProducts in \Magento\ConfigurableProduct\Block\Plugin\Product\Media\Gallery, it's restored with the media_gallery_images data value as an array.

You can just do a beforeGetMediaGalleryImages plugin on \Magento\Catalog\Model\Product to check if

if($subject->hasData('media_gallery_images') && !is_object($subject->getData('media_gallery_images'))) 
{
    $subject->setData('media_gallery_images', null);
}

Your Answer

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

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