/** * Test process method with shipping_address */ public function testProcessShippingAddress() { $this->orderMock->expects($this->exactly(2))->method('getAddresses')->willReturn([$this->addressMock]); $this->addressMock->expects($this->once())->method('save')->will($this->returnSelf()); $this->orderMock->expects($this->once())->method('getBillingAddress')->will($this->returnValue(null)); $this->orderMock->expects($this->once())->method('getShippingAddress')->will($this->returnValue($this->addressMock)); $this->addressMock->expects($this->exactly(2))->method('getId')->will($this->returnValue(2)); $this->orderMock->expects($this->once())->method('setShippingAddressId')->will($this->returnSelf()); $this->attributeMock->expects($this->once())->method('saveAttribute')->with($this->orderMock, ['shipping_address_id'])->will($this->returnSelf()); $this->assertEquals($this->address, $this->address->process($this->orderMock)); }
/** * Save relations for Order * * @param \Magento\Framework\Model\AbstractModel $object * @return void * @throws \Exception */ public function processRelation(\Magento\Framework\Model\AbstractModel $object) { /** @var \Magento\Sales\Model\Order $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->orderItemRepository->save($item); } } if (null !== $object->getPayment()) { $payment = $object->getPayment(); $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(); } } $this->addressHandler->removeEmptyAddresses($object); $this->addressHandler->process($object); }