From f9ccb51551943b2e841c64aef1f7eb6e12be2521 Mon Sep 17 00:00:00 2001 From: Sean Templeton Date: Mon, 9 Jul 2018 22:55:49 -0500 Subject: [PATCH] Prevent running SQL query on every item in the database when the quote is empty --- .../Quote/Model/ResourceModel/Quote/Item/Collection.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php b/app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php index 161ff159a2df9..12bb78b0c75ad 100644 --- a/app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php +++ b/app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php @@ -272,6 +272,10 @@ protected function _assignProducts() */ private function removeItemsWithAbsentProducts() { + if (count($this->_productIds) === 0) { + return; + } + $productCollection = $this->_productCollectionFactory->create()->addIdFilter($this->_productIds); $existingProductsIds = $productCollection->getAllIds(); $absentProductsIds = array_diff($this->_productIds, $existingProductsIds);