public function testProcessRelation() { $this->addressHandlerMock->expects($this->once())->method('removeEmptyAddresses')->with($this->orderMock)->willReturnSelf(); $this->addressHandlerMock->expects($this->once())->method('process')->with($this->orderMock)->willReturnSelf(); $this->orderMock->expects($this->exactly(2))->method('getItems')->willReturn([$this->orderItemMock]); $this->orderMock->expects($this->exactly(3))->method('getId')->willReturn('order-id-value'); $this->orderItemMock->expects($this->once())->method('setOrderId')->with('order-id-value')->willReturnSelf(); $this->orderItemMock->expects($this->once())->method('setOrder')->with($this->orderMock)->willReturnSelf(); $this->orderItemResourceMock->expects($this->once())->method('save')->with($this->orderItemMock)->willReturnSelf(); $this->orderMock->expects($this->exactly(2))->method('getPayments')->willReturn([$this->orderPaymentMock]); $this->orderPaymentMock->expects($this->once())->method('setParentId')->with('order-id-value')->willReturnSelf(); $this->orderPaymentMock->expects($this->once())->method('setOrder')->with($this->orderMock)->willReturnSelf(); $this->orderPaymentResourceMock->expects($this->once())->method('save')->with($this->orderPaymentMock)->willReturnSelf(); $this->orderMock->expects($this->exactly(2))->method('getStatusHistories')->willReturn([$this->orderStatusHistoryMock]); $this->orderStatusHistoryMock->expects($this->once())->method('setParentId')->with('order-id-value')->willReturnSelf(); $this->orderStatusHistoryMock->expects($this->once())->method('setOrder')->with($this->orderMock)->willReturnSelf(); $this->statusHistoryResource->expects($this->once())->method('save')->with($this->orderStatusHistoryMock)->willReturnSelf(); $this->orderMock->expects($this->exactly(2))->method('getRelatedObjects')->willReturn([$this->orderInvoiceMock]); $this->orderInvoiceMock->expects($this->once())->method('setOrder')->with($this->orderMock)->willReturnSelf(); $this->orderInvoiceMock->expects($this->once())->method('save')->willReturnSelf(); $this->relationProcessor->processRelation($this->orderMock); }
/** * Save relations for Order * * @param AbstractModel $object * @return void * @throws \Exception */ public function processRelation(AbstractModel $object) { /** @var \Magento\Sales\Model\Order $object */ $this->addressHandler->removeEmptyAddresses($object); $this->addressHandler->process($object); if (null !== $object->getItems()) { /** @var \Magento\Sales\Model\Order\Item $item */ foreach ($object->getItems() as $item) { $item->setOrderId($object->getId()); $item->setOrder($object); $this->orderItemResource->save($item); } } if (null !== $object->getPayments()) { /** @var \Magento\Sales\Model\Order\Payment $payment */ foreach ($object->getPayments() as $payment) { $payment->setParentId($object->getId()); $payment->setOrder($object); $this->orderPaymentResource->save($payment); } } if (null !== $object->getStatusHistories()) { /** @var \Magento\Sales\Model\Order\Status\History $statusHistory */ foreach ($object->getStatusHistories() as $statusHistory) { $statusHistory->setParentId($object->getId()); $statusHistory->setOrder($object); $this->orderStatusHistoryResource->save($statusHistory); } } if (null !== $object->getRelatedObjects()) { foreach ($object->getRelatedObjects() as $relatedObject) { $relatedObject->setOrder($object); $relatedObject->save(); } } }