Esempio n. 1
0
 public function testSave()
 {
     $this->orderMock->expects($this->exactly(3))->method('getId')->willReturn(null);
     $this->orderItemMock->expects($this->once())->method('getChildrenItems')->willReturn([]);
     $this->orderItemMock->expects($this->once())->method('getQuoteParentItemId')->willReturn(null);
     $this->orderMock->expects($this->once())->method('setTotalItemCount')->with(1);
     $this->storeGroupMock->expects($this->once())->method('getDefaultStoreId')->willReturn(1);
     $this->orderMock->expects($this->once())->method('getAllItems')->willReturn([$this->orderItemMock]);
     $this->orderMock->expects($this->once())->method('validateBeforeSave')->willReturnSelf();
     $this->orderMock->expects($this->once())->method('beforeSave')->willReturnSelf();
     $this->orderMock->expects($this->once())->method('isSaveAllowed')->willReturn(true);
     $this->orderMock->expects($this->once())->method('getEntityType')->willReturn('order');
     $this->orderMock->expects($this->exactly(2))->method('getStore')->willReturn($this->storeMock);
     $this->storeMock->expects($this->exactly(2))->method('getGroup')->willReturn($this->storeGroupMock);
     $this->storeMock->expects($this->once())->method('getWebsite')->willReturn($this->websiteMock);
     $this->storeGroupMock->expects($this->once())->method('getDefaultStoreId')->willReturn(1);
     $this->salesSequenceManagerMock->expects($this->once())->method('getSequence')->with('order', 1)->willReturn($this->salesSequenceMock);
     $this->salesSequenceMock->expects($this->once())->method('getNextValue')->willReturn('10000001');
     $this->orderMock->expects($this->once())->method('setIncrementId')->with('10000001')->willReturnSelf();
     $this->orderMock->expects($this->once())->method('getIncrementId')->willReturn(null);
     $this->orderMock->expects($this->once())->method('getData')->willReturn(['increment_id' => '10000001']);
     $this->objectRelationProcessorMock->expects($this->once())->method('validateDataIntegrity')->with(null, ['increment_id' => '10000001']);
     $this->relationCompositeMock->expects($this->once())->method('processRelations')->with($this->orderMock);
     $this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->connectionMock);
     $this->connectionMock->expects($this->any())->method('quoteInto');
     $this->connectionMock->expects($this->any())->method('describeTable')->will($this->returnValue([]));
     $this->connectionMock->expects($this->any())->method('update');
     $this->connectionMock->expects($this->any())->method('lastInsertId');
     $this->orderMock->expects($this->any())->method('getId')->will($this->returnValue(1));
     $this->entitySnapshotMock->expects($this->once())->method('isModified')->with($this->orderMock)->will($this->returnValue(true));
     $this->resource->save($this->orderMock);
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function load(\Magento\Framework\Model\AbstractModel $object, $value, $field = null)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'load');
     if (!$pluginInfo) {
         return parent::load($object, $value, $field);
     } else {
         return $this->___callPlugins('load', func_get_args(), $pluginInfo);
     }
 }
Esempio n. 3
0
 /**
  * @magentoDataFixture Magento/Catalog/_files/product_simple.php
  */
 public function testSaveOrder()
 {
     $addressData = ['region' => 'CA', 'postcode' => '11111', 'lastname' => 'lastname', 'firstname' => 'firstname', 'street' => 'street', 'city' => 'Los Angeles', 'email' => '*****@*****.**', 'telephone' => '11111111', 'country_id' => 'US'];
     $billingAddress = $this->objectManager->create('Magento\\Sales\\Model\\Order\\Address', ['data' => $addressData]);
     $billingAddress->setAddressType('billing');
     $shippingAddress = clone $billingAddress;
     $shippingAddress->setId(null)->setAddressType('shipping');
     $payment = $this->objectManager->create('Magento\\Sales\\Model\\Order\\Payment');
     $payment->setMethod('checkmo');
     /** @var \Magento\Sales\Model\Order\Item $orderItem */
     $orderItem = $this->objectManager->create('Magento\\Sales\\Model\\Order\\Item');
     $orderItem->setProductId(1)->setQtyOrdered(2)->setBasePrice(10)->setPrice(10)->setRowTotal(10);
     /** @var \Magento\Sales\Model\Order $order */
     $order = $this->objectManager->create('Magento\\Sales\\Model\\Order');
     $order->setIncrementId($this->orderIncrementId)->setState(\Magento\Sales\Model\Order::STATE_PROCESSING)->setStatus($order->getConfig()->getStateDefaultStatus(\Magento\Sales\Model\Order::STATE_PROCESSING))->setSubtotal(100)->setBaseSubtotal(100)->setBaseGrandTotal(100)->setCustomerIsGuest(true)->setCustomerEmail('*****@*****.**')->setBillingAddress($billingAddress)->setShippingAddress($shippingAddress)->setStoreId($this->objectManager->get('Magento\\Store\\Model\\StoreManagerInterface')->getStore()->getId())->addItem($orderItem)->setPayment($payment);
     $this->resourceModel->save($order);
     $this->assertNotNull($order->getCreatedAt());
     $this->assertNotNull($order->getUpdatedAt());
 }
 /**
  * Sends order email to the customer.
  *
  * Email will be sent immediately in two cases:
  *
  * - if asynchronous email sending is disabled in global settings
  * - if $forceSyncMode parameter is set to TRUE
  *
  * Otherwise, email will be sent later during running of
  * corresponding cron job.
  *
  * @param Order $order
  * @param bool $forceSyncMode
  * @return bool
  */
 public function send(Order $order, $forceSyncMode = false)
 {
     $order->setSendEmail(true);
     if (!$this->globalConfig->getValue('sales_email/general/async_sending') || $forceSyncMode) {
         if ($this->checkAndSend($order)) {
             $order->setEmailSent(true);
             $this->orderResource->saveAttribute($order, ['send_email', 'email_sent']);
             return true;
         }
     }
     $this->orderResource->saveAttribute($order, 'send_email');
     return false;
 }
Esempio n. 5
0
 /**
  * {@inheritdoc}
  */
 public function getValidationRulesBeforeSave()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getValidationRulesBeforeSave');
     if (!$pluginInfo) {
         return parent::getValidationRulesBeforeSave();
     } else {
         return $this->___callPlugins('getValidationRulesBeforeSave', func_get_args(), $pluginInfo);
     }
 }