I am facing this issue in the backend admin, in the customer Information, & Shopping Cart tab. It looks like the getQuote() function returns all cart items if no active quote is found for customer id.
Screenshot :
Please follow the below steps to fix this issue :=>
Please create the following extension with a plugin
1) Vendor/Module/etc/adminhtml/di.xml
1 2 3 4 5 6 7 8 |
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <preference for="Magento\Customer\Block\Adminhtml\Edit\Tab\Cart" type="Vendor\Module\Rewrite\Customer\Block\Adminhtml\Edit\Tab\Cart"/> <type name="Magento\Sales\Block\Adminhtml\ShoppingCartsTab"> <plugin sortOrder="1" name="FixShoppingCartsTab" type="Vendor\Module\Plugin\Block\SalesShoppingCartsTab"/> </type> </config> |
2)Vendor/Module/Rewrite/Customer/Block/Adminhtml/Edit/Tab/Cart.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
<?php namespace Vendor\Module\Rewrite\Customer\Block\Adminhtml\Edit\Tab; use Magento\Backend\Block\Widget\Grid\Extended; use Magento\Framework\Exception\NoSuchEntityException; class Cart extends \Magento\Customer\Block\Adminhtml\Edit\Tab\Cart { /** * Added fix when customer do not have any active quote * Magento 2 issue: https://github.com/magento/magento2/issues/26437 * Pull request: https://github.com/magento/magento2/pull/26489 */ protected function _prepareCollection() { $quote = $this->getQuote(); if ($quote && $quote->getId()) { $collection = $quote->getItemsCollection(false); $collection->addFieldToFilter('parent_item_id', ['null' => true]); } else { $collection = $this->_dataCollectionFactory->create(); } $this->setCollection($collection); return Extended::_prepareCollection(); } protected function getQuote() { if (null === $this->quote) { $customerId = $this->getCustomerId(); $storeIds = $this->_storeManager->getWebsite($this->getWebsiteId())->getStoreIds(); try { $this->quote = $this->quoteFactory->create()->setSharedStoreIds($storeIds)->loadByCustomer($customerId); } catch (NoSuchEntityException $e) { $this->quote = $this->quoteFactory->create()->setSharedStoreIds($storeIds); } } return $this->quote; } } |
3) Vendor/Module/Plugin/Block/SalesShoppingCartsTab.php
1 2 3 4 5 6 7 8 9 10 11 12 |
<?php namespace Vendor\Module\Plugin\Block; use Magento\Sales\Block\Adminhtml\ShoppingCartsTab; class SalesShoppingCartsTab { public function afterGetTabUrl(ShoppingCartsTab $subject, $result) { return $subject->getUrl('customer/*/carts', ['_current' => true]); } } |
That’s it! You are done.
Note: This will only work for Magento 2.3.3 and higher.
Please share your thoughts if this article helpful to you.
Thanks.
[crayon-63e097471f35c501567402/] Using above fucntion Images can be imported directly from...
Override view block using di.xml and add the below code...
You can check a list of called layout XML for...
Follow the below steps to install and set up PWA...
If you want to remove all leading zero's from order,...
Let our Magento expert connect to discuss your requirement.
We offer Magento
certified developers.
Our Magento clientele
is 500+.
We sign NDA for the
security of your projects.
We’ve performed 100+
Magento migration projects.
Free quotation
on your project.
Three months warranty on
code developed by us.