From a6649f83bbe95eee8c55f5b01500365671458cba Mon Sep 17 00:00:00 2001 From: Jeroen Date: Tue, 10 Apr 2018 11:48:49 +0200 Subject: [PATCH] Add parent item to order item --- .../Sales/Model/Order/ItemRepository.php | 15 ++++++ .../Sales/Model/Order/ItemRepositoryTest.php | 54 +++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 dev/tests/integration/testsuite/Magento/Sales/Model/Order/ItemRepositoryTest.php diff --git a/app/code/Magento/Sales/Model/Order/ItemRepository.php b/app/code/Magento/Sales/Model/Order/ItemRepository.php index f1bbb7d39469b..7916eb9db2b80 100644 --- a/app/code/Magento/Sales/Model/Order/ItemRepository.php +++ b/app/code/Magento/Sales/Model/Order/ItemRepository.php @@ -117,6 +117,7 @@ public function get($id) } $this->addProductOption($orderItem); + $this->addParentItem($orderItem); $this->registry[$id] = $orderItem; } return $this->registry[$id]; @@ -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 * diff --git a/dev/tests/integration/testsuite/Magento/Sales/Model/Order/ItemRepositoryTest.php b/dev/tests/integration/testsuite/Magento/Sales/Model/Order/ItemRepositoryTest.php new file mode 100644 index 0000000000000..8f0c255a903b9 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Sales/Model/Order/ItemRepositoryTest.php @@ -0,0 +1,54 @@ +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()); + } + } + } +}