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:instead of this:
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.