Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions app/code/Magento/Sales/Model/Order/ItemRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public function get($id)
}

$this->addProductOption($orderItem);
$this->addParentItem($orderItem);
$this->registry[$id] = $orderItem;
}
return $this->registry[$id];
Expand Down Expand Up @@ -216,6 +217,20 @@ protected function addProductOption(OrderItemInterface $orderItem)
return $this;
}

/**
* Set parent item.
*
* @param OrderItemInterface $orderItem
* @throws InputException
* @throws NoSuchEntityException
*/
private function addParentItem(OrderItemInterface $orderItem)
{
if ($parentId = $orderItem->getParentItemId()) {
$orderItem->setParentItem($this->get($parentId));
}
}

/**
* Set product options data
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Sales\Model\Order;

class ItemRepositoryTest extends \PHPUnit\Framework\TestCase
{
/** @var \Magento\Sales\Model\Order */
private $order;

/** @var \Magento\Sales\Api\OrderItemRepositoryInterface */
private $orderItemRepository;

/** @var \Magento\Framework\Api\SearchCriteriaBuilder */
private $searchCriteriaBuilder;

protected function setUp()
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();

$this->order = $objectManager->create(\Magento\Sales\Model\Order::class);
$this->orderItemRepository = $objectManager->create(\Magento\Sales\Api\OrderItemRepositoryInterface::class);
$this->searchCriteriaBuilder = $objectManager->create(\Magento\Framework\Api\SearchCriteriaBuilder::class);
}

/**
* @magentoDataFixture Magento/Sales/_files/order_configurable_product.php
*/
public function testAddOrderItemParent()
{
$this->order->load('100000001', 'increment_id');

foreach ($this->order->getItems() as $item) {
if ($item->getProductType() === \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE) {
$orderItem = $this->orderItemRepository->get($item->getItemId());
$this->assertInstanceOf(\Magento\Sales\Api\Data\OrderItemInterface::class, $orderItem->getParentItem());
}
}

$itemList = $this->orderItemRepository->getList(
$this->searchCriteriaBuilder->addFilter('order_id', $this->order->getId())->create()
);

foreach ($itemList->getItems() as $item) {
if ($item->getProductType() === \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE) {
$this->assertInstanceOf(\Magento\Sales\Api\Data\OrderItemInterface::class, $item->getParentItem());
}
}
}
}