示例#1
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));
 }
示例#2
0
 /**
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
 {
     /** @var \Magento\Sales\Model\Order $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);
             $item->save();
         }
     }
     if (null !== $object->getPayments()) {
         /** @var \Magento\Sales\Model\Order\Payment $payment */
         foreach ($object->getPayments() as $payment) {
             $payment->setParentId($object->getId());
             $payment->setOrder($object);
             $payment->save();
         }
     }
     if (null !== $object->getStatusHistories()) {
         /** @var \Magento\Sales\Model\Order\Status\History $statusHistory */
         foreach ($object->getStatusHistories() as $statusHistory) {
             $statusHistory->setParentId($object->getId());
             $statusHistory->save();
             $statusHistory->setOrder($object);
         }
     }
     foreach ($object->getRelatedObjects() as $relatedObject) {
         $relatedObject->save();
         $relatedObject->setOrder($object);
     }
     return parent::_afterSave($object);
 }
示例#3
0
 public function testSave()
 {
     $this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->adapterMock);
     $this->adapterMock->expects($this->any())->method('quoteInto');
     $this->adapterMock->expects($this->any())->method('describeTable')->will($this->returnValue([]));
     $this->adapterMock->expects($this->any())->method('update');
     $this->adapterMock->expects($this->any())->method('lastInsertId');
     $this->addressHandlerMock->expects($this->once())->method('removeEmptyAddresses')->with($this->equalTo($this->orderMock))->will($this->returnSelf());
     $this->stateHandlerMock->expects($this->once())->method('check')->with($this->equalTo($this->orderMock))->will($this->returnSelf());
     $this->orderMock->expects($this->any())->method('getId')->will($this->returnValue(1));
     $this->orderMock->expects($this->once())->method('getRelatedObjects')->willReturn([]);
     $this->resource->save($this->orderMock);
 }
示例#4
0
 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);
 }
示例#5
0
 /**
  * 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();
         }
     }
 }
示例#6
0
 /**
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
 {
     /** @var \Magento\Sales\Model\Order $object */
     $this->addressHandler->process($object);
     if (null !== $object->getItemsCollection()) {
         $object->getItemsCollection()->save();
     }
     if (null !== $object->getPaymentsCollection()) {
         $object->getPaymentsCollection()->save();
     }
     if (null !== $object->getStatusHistoryCollection()) {
         $object->getStatusHistoryCollection()->save();
     }
     foreach ($object->getRelatedObjects() as $relatedObject) {
         $relatedObject->save();
     }
     return parent::_afterSave($object);
 }