예제 #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
파일: Relation.php 프로젝트: kid17/magento2
 /**
  * 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();
         }
     }
 }
예제 #3
0
파일: Order.php 프로젝트: opexsw/magento2
 /**
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     /** @var \Magento\Sales\Model\Order $object */
     $this->addressHandler->removeEmptyAddresses($object);
     $this->stateHandler->check($object);
     if (!$object->getId()) {
         /** @var \Magento\Store\Model\Store $store */
         $store = $object->getStore();
         $name = [$store->getWebsite()->getName(), $store->getGroup()->getName(), $store->getName()];
         $object->setStoreName(implode("\n", $name));
         $object->setTotalItemCount($this->calculateItems($object));
     }
     $object->setData('protect_code', substr(md5(uniqid(Random::getRandomNumber(), true) . ':' . microtime(true)), 5, 6));
     $isNewCustomer = !$object->getCustomerId() || $object->getCustomerId() === true;
     if ($isNewCustomer && $object->getCustomer()) {
         $object->setCustomerId($object->getCustomer()->getId());
     }
     return parent::_beforeSave($object);
 }