Magento 2.3 – Cart & Checkout Blank After Adding Product to Cart

addtocartcartcheckoutmagento2

In Magento 2.3 I am attempting to add an item to cart, however the cart shows empty and if I 'proceed to checkout' the checkout page is blank with just the loading gif icon.

If I go to 'checkout/cart' then the cart page is blank and just has 'estimate shipping & tax' towards the top of the page.

The console error I get when I click 'add to cart' is below:

customer-data.js:91 Uncaught Error: [object Object]
at Object.<anonymous> (customer-data.js:91)
at fire (jquery.js:3232)
at Object.fireWith [as rejectWith] (jquery.js:3362)
at done (jquery.js:9842)
at XMLHttpRequest.callback (jquery.js:10311)

The server error logs show the below message:

500 GET /customer/section/load/?sections=cart%2Cmessages&update_section_id=true&_=1552910808681 HTTP/1.0

500 GET /customer/section/load/?sections=cart%2Cmessages&update_section_id=true&_=1552910808681 HTTP/1.0

AH01071: Got error 'PHP message: PHP Fatal error: Uncaught Error: Call to a member function getFinalProduct() on null in /var/www/vhosts/mysite.co.uk/httpdocs/vendor/magento/module-checkout/CustomerData/DefaultItem.php:129\nStack trace:\n#0 /var/www/vhosts/mysite.co.uk/httpdocs/app/code/MGS/Mpanel/CustomerData/DefaultItem.php(81): Magento\\Checkout\\CustomerData\\DefaultItem->getProductForThumbnail()\n#1 /var/www/vhosts/mysite.co.uk/httpdocs/vendor/magento/module-checkout/CustomerData/AbstractItem.php(32): MGS\\Mpanel\\CustomerData\\DefaultItem->doGetItemData()\n#2 /var/www/vhosts/mysite.co.uk/httpdocs/vendor/magento/module-checkout/CustomerData/ItemPool.php(63): Magento\\Checkout\\CustomerData\\AbstractItem->getItemData(Object(Magento\\Quote\\Model\\Quote\\Item))\n#3 /var/www/vhosts/mysite.co.uk/httpdocs/vendor/magento/module-checkout/CustomerData/Cart.php(167): Magento\\Checkout\\CustomerData\\ItemPool->getItemData(Object(Magento\\Quote\\Model\\Quote\\Item))\n#4 /var/www/vhosts/...\n', referer: https://www.mysite.co.uk/coastal-chic-large-rectangular-dining-table.html

Can anyone please advise a solution?

Best Answer

I happen to use the same theme you're using, or at least the module. In the file app\code\MGS\Mpanel\etc\di.xml you can see that the wishlist class is overridden <preference for="Magento\Wishlist\CustomerData\Wishlist" type="MGS\Mpanel\CustomerData\Wishlist" /> but in the constructor the parent constructor is not called what you have to do is to make the constructor look like this:

public function __construct(
    \Magento\Wishlist\Helper\Data $wishlistHelper,
    \Magento\Wishlist\Block\Customer\Sidebar $block,
    \Magento\Catalog\Helper\ImageFactory $imageHelperFactory,
    \Magento\Framework\App\ViewInterface $view,
    \MGS\Mpanel\Helper\Data $panelHelper,
    \MGS\Mpanel\Helper\Image $panelImageHelper,
    \Magento\Catalog\Model\Product\Configuration\Item\ItemResolverInterface $itemResolver = null
) {
    $this->wishlistHelper = $wishlistHelper;
    $this->imageHelperFactory = $imageHelperFactory;
    $this->block = $block;
    $this->view = $view;
    $this->panelHelper = $panelHelper;
    $this->panelImageHelper = $panelImageHelper;
    parent::__construct($wishlistHelper,$block,$imageHelperFactory,$view,$itemResolver);
}

instead of this:

public function __construct(
    \Magento\Wishlist\Helper\Data $wishlistHelper,
    \Magento\Wishlist\Block\Customer\Sidebar $block,
    \Magento\Catalog\Helper\ImageFactory $imageHelperFactory,
    \Magento\Framework\App\ViewInterface $view,
    \MGS\Mpanel\Helper\Data $panelHelper,
    \MGS\Mpanel\Helper\Image $panelImageHelper
) {
    $this->wishlistHelper = $wishlistHelper;
    $this->imageHelperFactory = $imageHelperFactory;
    $this->block = $block;
    $this->view = $view;
    $this->panelHelper = $panelHelper;
    $this->panelImageHelper = $panelImageHelper;
}

the difference is, I injected the ItemResolverInterface and called the parent constructor like this: parent::__construct($wishlistHelper,$block,$imageHelperFactory,$view,$itemResolver);. Give it a setup:di:compile and you should be good to go.

Good luck.

Related Topic