Пример #1
0
 /**
  * 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);
 }
Пример #2
0
 /**
  * Test method removeEmptyAddresses
  */
 public function testRemoveEmptyAddresses()
 {
     $this->orderMock->expects($this->once())->method('hasBillingAddressId')->will($this->returnValue(true));
     $this->orderMock->expects($this->once())->method('getBillingAddressId')->will($this->returnValue(null));
     $this->orderMock->expects($this->once())->method('unsBillingAddressId')->will($this->returnSelf());
     $this->orderMock->expects($this->once())->method('hasShippingAddressId')->will($this->returnValue(true));
     $this->orderMock->expects($this->once())->method('getShippingAddressId')->will($this->returnValue(null));
     $this->orderMock->expects($this->once())->method('unsShippingAddressId')->will($this->returnSelf());
     $this->assertEquals($this->address, $this->address->removeEmptyAddresses($this->orderMock));
 }