Question

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

Was it helpful?

Solution

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().

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top