File tree 2 files changed +31
-2
lines changed
app/code/Magento/Quote/Model
dev/tests/integration/testsuite/Magento/Quote/Model 2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -1445,11 +1445,17 @@ public function hasProductId($productId)
1445
1445
* Retrieve item model object by item identifier
1446
1446
*
1447
1447
* @param int $itemId
1448
- * @return \Magento\Quote\Model\Quote\Item
1448
+ * @return \Magento\Quote\Model\Quote\Item|false
1449
1449
*/
1450
1450
public function getItemById ($ itemId )
1451
1451
{
1452
- return $ this ->getItemsCollection ()->getItemById ($ itemId );
1452
+ foreach ($ this ->getItemsCollection () as $ item ) {
1453
+ if ($ item ->getId () == $ itemId ) {
1454
+ return $ item ;
1455
+ }
1456
+ }
1457
+
1458
+ return false ;
1453
1459
}
1454
1460
1455
1461
/**
Original file line number Diff line number Diff line change @@ -449,4 +449,27 @@ public function testAddedProductToQuoteIsSalable()
449
449
$ quote = $ objectManager ->create (\Magento \Quote \Model \Quote::class);
450
450
$ quote ->addProduct ($ product );
451
451
}
452
+
453
+ /**
454
+ * @magentoDataFixture Magento/Sales/_files/quote.php
455
+ * @magentoDataFixture Magento/Catalog/_files/product_simple.php
456
+ */
457
+ public function testGetItemById ()
458
+ {
459
+ $ objectManager = Bootstrap::getObjectManager ();
460
+ $ quote = $ objectManager ->create (\Magento \Quote \Model \Quote::class);
461
+ $ quote ->load ('test01 ' , 'reserved_order_id ' );
462
+
463
+ $ quoteItem = $ objectManager ->create (\Magento \Quote \Model \Quote \Item::class);
464
+
465
+ $ productRepository = $ objectManager ->create (\Magento \Catalog \Api \ProductRepositoryInterface::class);
466
+ $ product = $ productRepository ->get ('simple ' );
467
+
468
+ $ quoteItem ->setProduct ($ product );
469
+ $ quote ->addItem ($ quoteItem );
470
+ $ quote ->save ();
471
+
472
+ $ this ->assertInstanceOf (\Magento \Quote \Model \Quote \Item::class, $ quote ->getItemById ($ quoteItem ->getId ()));
473
+ $ this ->assertEquals ($ quoteItem ->getId (), $ quote ->getItemById ($ quoteItem ->getId ())->getId ());
474
+ }
452
475
}
You can’t perform that action at this time.
0 commit comments