We sacrifice by not doing any other technology, so that you get the best of Magento.

We sacrifice by not doing any other technology, so that you get the best of Magento.

    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

    <?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="MagentoCustomerBlockAdminhtmlEditTabCart" type="VendorModuleRewriteCustomerBlockAdminhtmlEditTabCart"/>
        <type name="MagentoSalesBlockAdminhtmlShoppingCartsTab">
            <plugin sortOrder="1" name="FixShoppingCartsTab"
                    type="VendorModulePluginBlockSalesShoppingCartsTab"/>
        </type>
    </config>
    

    2)Vendor/Module/Rewrite/Customer/Block/Adminhtml/Edit/Tab/Cart.php

    <?php
    namespace VendorModuleRewriteCustomerBlockAdminhtmlEditTab;
    
    use MagentoBackendBlockWidgetGridExtended;
    use MagentoFrameworkExceptionNoSuchEntityException;
    
    class Cart extends MagentoCustomerBlockAdminhtmlEditTabCart
    {
        /**
         * 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

    <?php
    namespace VendorModulePluginBlock;
    
    use MagentoSalesBlockAdminhtmlShoppingCartsTab;
    
    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.

    field_5bfb909c5ccae

      Get a Free Quote