-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Description
Preconditions (*)
- Centos OS 7 x64
- Magento 2.3.3
- PHP 7.2
Steps to reproduce (*)
- Create lots of carts / quotes, both as logged in user and guest
- Keep one customer without any quotes
- Goto backend, edit customer, click on Shopping Cart tab
- Grid shows thousand of items
Expected result (*)
- Shopping cart tab should show customer's cart items if available, or none if no carts available for customer
Actual result (*)
I am experiencing this issue in the backend admin, in the customer record, Shopping Cart tab. It looks like the getQuote() function returns all cart items (without a parent id), if no active quote is found for customer id [X].
See screenshot:
This getQuote() function is at fault from what I can tell.
The quoteRepository->getForCustomer() function throws the exception as shown here:
The trouble is if no quote is found, then _prepareCollection() will return all quote_items regardless of quote id, regardless of customer_id, as shown by this query:
SELECT main_table.* FROM quote_item AS main_table WHERE (parent_item_id IS NULL)
I fixed in by adding this check:
protected function _prepareCollection()
{
$quote = $this->getQuote();
if ($quote) {
$collection = $quote->getItemsCollection(false);
} else {
$collection = $this->_dataCollectionFactory->create();
}
$collection->addFieldToFilter('parent_item_id', ['null' => true]);
/**** Added by me as temporary fix ***/
if(is_null($quote->getId()))
$collection->addFieldToFilter('quote_id', -1);
/**** Added by me as temporary fix ***/
$this->setCollection($collection);
return parent::_prepareCollection();
}
It probably isn't the best or most elegant fix, but it works, or so it seems.
Does anyone have a better idea?
Thanks,
Michael Mussulis


