Skip to content

Commit f7984c8

Browse files
Roman HaninRoman Hanin
authored andcommitted
B2B-2423: Optimize addProductsToCart operations
- CR fixes
1 parent 06b427f commit f7984c8

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

app/code/Magento/Quote/Model/Quote.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,15 +1843,16 @@ public function updateItem($itemId, $buyRequest, $params = null)
18431843
*/
18441844
public function getItemByProduct($product)
18451845
{
1846-
/** @var \Magento\Quote\Model\Quote\Item $item */
1847-
$item = $this->getItemsCollection()->getItemByColumnValue('product_id', $product->getId()) ?? null;
1848-
if ($item
1849-
&& !$item->isDeleted()
1850-
&& $item->getProduct()
1851-
&& $product->getStatus() !== ProductStatus::STATUS_DISABLED
1852-
&& $item->representProduct($product)
1853-
) {
1854-
return $item;
1846+
/** @var \Magento\Quote\Model\Quote\Item[] $items */
1847+
$items = $this->getItemsCollection()->getItemsByColumnValue('product_id', $product->getId()) ?? null;
1848+
foreach ($items as $item) {
1849+
if (!$item->isDeleted()
1850+
&& $item->getProduct()
1851+
&& $item->getProduct()->getStatus() !== ProductStatus::STATUS_DISABLED
1852+
&& $item->representProduct($product)
1853+
) {
1854+
return $item;
1855+
}
18551856
}
18561857
return false;
18571858
}

0 commit comments

Comments
 (0)