Skip to content

Commit 8ecf7a1

Browse files
ENGCOM-1532: [Port 2.3-develop]Add parent item to order item #15168
2 parents f2b8d9b + 6a3e338 commit 8ecf7a1

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

app/code/Magento/Sales/Model/Order/ItemRepository.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ public function get($id)
117117
}
118118

119119
$this->addProductOption($orderItem);
120+
$this->addParentItem($orderItem);
120121
$this->registry[$id] = $orderItem;
121122
}
122123
return $this->registry[$id];
@@ -216,6 +217,20 @@ protected function addProductOption(OrderItemInterface $orderItem)
216217
return $this;
217218
}
218219

220+
/**
221+
* Set parent item.
222+
*
223+
* @param OrderItemInterface $orderItem
224+
* @throws InputException
225+
* @throws NoSuchEntityException
226+
*/
227+
private function addParentItem(OrderItemInterface $orderItem)
228+
{
229+
if ($parentId = $orderItem->getParentItemId()) {
230+
$orderItem->setParentItem($this->get($parentId));
231+
}
232+
}
233+
219234
/**
220235
* Set product options data
221236
*
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Sales\Model\Order;
9+
10+
class ItemRepositoryTest extends \PHPUnit\Framework\TestCase
11+
{
12+
/** @var \Magento\Sales\Model\Order */
13+
private $order;
14+
15+
/** @var \Magento\Sales\Api\OrderItemRepositoryInterface */
16+
private $orderItemRepository;
17+
18+
/** @var \Magento\Framework\Api\SearchCriteriaBuilder */
19+
private $searchCriteriaBuilder;
20+
21+
protected function setUp()
22+
{
23+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
24+
25+
$this->order = $objectManager->create(\Magento\Sales\Model\Order::class);
26+
$this->orderItemRepository = $objectManager->create(\Magento\Sales\Api\OrderItemRepositoryInterface::class);
27+
$this->searchCriteriaBuilder = $objectManager->create(\Magento\Framework\Api\SearchCriteriaBuilder::class);
28+
}
29+
30+
/**
31+
* @magentoDataFixture Magento/Sales/_files/order_configurable_product.php
32+
*/
33+
public function testAddOrderItemParent()
34+
{
35+
$this->order->load('100000001', 'increment_id');
36+
37+
foreach ($this->order->getItems() as $item) {
38+
if ($item->getProductType() === \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE) {
39+
$orderItem = $this->orderItemRepository->get($item->getItemId());
40+
$this->assertInstanceOf(\Magento\Sales\Api\Data\OrderItemInterface::class, $orderItem->getParentItem());
41+
}
42+
}
43+
44+
$itemList = $this->orderItemRepository->getList(
45+
$this->searchCriteriaBuilder->addFilter('order_id', $this->order->getId())->create()
46+
);
47+
48+
foreach ($itemList->getItems() as $item) {
49+
if ($item->getProductType() === \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE) {
50+
$this->assertInstanceOf(\Magento\Sales\Api\Data\OrderItemInterface::class, $item->getParentItem());
51+
}
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)