@@ -1433,17 +1433,16 @@ public function getItemsCollection($useCache = true)
1433
1433
*/
1434
1434
public function getAllItems ()
1435
1435
{
1436
- if (!empty ($ this ->allItemsCache )) {
1437
- return $ this ->allItemsCache ;
1438
- }
1436
+ $ items = [];
1439
1437
/** @var \Magento\Quote\Model\Quote\Item $item */
1440
1438
foreach ($ this ->getItemsCollection () as $ item ) {
1441
1439
$ product = $ item ->getProduct ();
1442
1440
if (!$ item ->isDeleted () && ($ product && (int )$ product ->getStatus () !== ProductStatus::STATUS_DISABLED )) {
1443
- $ this -> allItemsCache [ $ product -> getSku () ] = $ item ;
1441
+ $ items [ ] = $ item ;
1444
1442
}
1445
1443
}
1446
- return $ this ->allItemsCache ;
1444
+
1445
+ return $ items ;
1447
1446
}
1448
1447
1449
1448
/**
@@ -1578,7 +1577,7 @@ public function removeItem($itemId)
1578
1577
if ($ parent ) {
1579
1578
$ parent ->isDeleted (true );
1580
1579
}
1581
- unset( $ this -> allItemsCache [ $ item -> getSku ()]);
1580
+
1582
1581
$ this ->_eventManager ->dispatch ('sales_quote_remove_item ' , ['quote_item ' => $ item ]);
1583
1582
}
1584
1583
@@ -1849,8 +1848,14 @@ public function updateItem($itemId, $buyRequest, $params = null)
1849
1848
*/
1850
1849
public function getItemByProduct ($ product )
1851
1850
{
1852
- $ item = $ this ->getAllItems ()[$ product ->getSku ()] ?? null ;
1853
- if ($ item && $ item ->representProduct ($ product )) {
1851
+ /** @var \Magento\Quote\Model\Quote\Item $item */
1852
+ $ item = $ this ->getItemsCollection ()->getItemByColumnValue ('product_id ' , $ product ->getId ()) ?? null ;
1853
+ if ($ item
1854
+ && !$ item ->isDeleted ()
1855
+ && $ item ->getProduct ()
1856
+ && $ product ->getStatus () !== ProductStatus::STATUS_DISABLED
1857
+ && $ item ->representProduct ($ product )
1858
+ ) {
1854
1859
return $ item ;
1855
1860
}
1856
1861
return false ;
0 commit comments