0

I had a complaint about the cart stopping working on a Magento 2.2.3 instance and noticed the following errors showing within php logs:

[Fri Apr 06 15:28:54.964616 2018] 
[:error] [pid 58985] [client 77.96.38.47:55599] PHP Fatal error: Uncaught Error: Call to a member function getThumbnail() on null in /home/sites/magento/public_html/vendor/magento/module-configurable-product/CustomerData/ConfigurableItem.php:63
Stack trace:
#0 
/home/sites/magento/public_html/vendor/magento/module-checkout/CustomerData/DefaultItem.php(66): Magento\ConfigurableProduct\CustomerData\ConfigurableItem->getProductForThumbnail()
#1 
/home/sites/magento/public_html/vendor/magento/module-checkout/CustomerData/AbstractItem.php(31): Magento\Checkout\CustomerData\DefaultItem->doGetItemData()
#2 
/home/sites/magento/public_html/vendor/magento/module-checkout/CustomerData/ItemPool.php(63): Magento\Checkout\CustomerData\AbstractItem->getItemData(Object(Magento\Quote\Model\Quote\Item))
#3 
/home/sites/magento/public_html/vendor/magento/module-checkout/CustomerData/Cart.php(167): Magento\Checkout\CustomerData\ItemPool->getItemData(Object(Magento\Quote\Model\Quote\Item))
#4 
/home/sites/magento/public_html/vendor/magento/module-checkout/CustomerData/Cart.php(98): Magento\Checkou in /home/sites/magento/public_html/vendor/magento/module-configurable-product/CustomerData/ConfigurableItem.php on line 63

Cart seemed to be working for most people except a new user who had just started and a few customers seemed to have been having the issues from looking over the logs.

I flushed the redis cache as felt it was session related and this was handled by redis. This stopped the issue occurring for now however am worried it will come back so was wondering if anyone can suggest what may have gone wrong here?

Redis does not have any memory limits configured and there were no errors in Redis logs so feel that is fine but am out of ideas of how this has happened.

1

This issue because the function $this->getChildProduct() is empty or this product is not available now, there are two files use this:

vendor/magento/module-configurable-product/Block/Cart/Item/Renderer/Configurable.php line 71

vendor/magento/module-configurable-product/CustomerData/ConfigurableItem.php line 63

I add a new condition as below:

vendor/magento/module-configurable-product/Block/Cart/Item/Renderer/Configurable.php:71

if (empty($this->getChildProduct()) && ($this->_scopeConfig->getValue(
            self::CONFIG_THUMBNAIL_SOURCE,
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE
        ) == ThumbnailSource::OPTION_USE_PARENT_IMAGE ||
            !($this->getChildProduct()->getThumbnail() && $this->getChildProduct()->getThumbnail() != 'no_selection'))
        ) {
            $product = $this->getProduct();
        } else {
            $product = $this->getChildProduct();
        }
        return $product;

vendor/magento/module-configurable-product/CustomerData/ConfigurableItem.php:63

$product = $config == empty($this->getChildProduct()) && (ThumbnailSource::OPTION_USE_PARENT_IMAGE
            || (!$this->getChildProduct()->getThumbnail() || $this->getChildProduct()->getThumbnail() == 'no_selection'))
            ? $this->getProduct()
            : $this->getChildProduct();

Now it is working properly you can use override block on Magento to do this.

0

I have seen and implemented your suggestions and seems it's perfect solutions, i just want to modify some more detail, i faced this issue in Magento 2.2.5 and i have used some more corrections to resolve the issue.



You can see the following code which can help you to get rid the mentioned issue
PHP Fatal error: Uncaught Error: Call to a member function getThumbnail()
/vendor/magento/module-configurable-product/Block/Cart/Item/Renderer/Configurable.php

public function getChildProduct(){
    $option = $this->getItem()->getCustomOption('simple_product');

    if ($option !== null ) {
        return $option->getProduct();
    }
    return $this->getProduct();
}


And in the following file, you can modify the code and this issue will be resolved.
/vendor/magento/module-catalog/Block/Product/ImageBuilder.php

 public function create() {
    $simpleOption = $this->product->getCustomOption('simple_product');
    if ($simpleOption !== null) {
        $optionProduct = $simpleOption->getProduct();
        //$this->setProduct($optionProduct);
        if ($optionProduct->getThumbnail() !== null) {
            $this->setProduct($optionProduct);
        }
    }

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.