File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed
app/code/Magento/Quote/Model
dev/tests/integration/testsuite/Magento/Quote/Model Expand file tree Collapse file tree 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)
14451445 * Retrieve item model object by item identifier
14461446 *
14471447 * @param int $itemId
1448- * @return \Magento\Quote\Model\Quote\Item
1448+ * @return \Magento\Quote\Model\Quote\Item|false
14491449 */
14501450 public function getItemById ($ itemId )
14511451 {
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 ;
14531459 }
14541460
14551461 /**
Original file line number Diff line number Diff line change @@ -449,4 +449,27 @@ public function testAddedProductToQuoteIsSalable()
449449 $ quote = $ objectManager ->create (\Magento \Quote \Model \Quote::class);
450450 $ quote ->addProduct ($ product );
451451 }
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+ }
452475}
You can’t perform that action at this time.
0 commit comments