예제 #1
0
 /**
  * Send email to customer
  *
  * @param Order $order
  * @return bool
  */
 public function send(Order $order)
 {
     $result = $this->checkAndSend($order);
     if ($result) {
         $order->setEmailSent(true);
         $this->orderResource->saveAttribute($order, 'email_sent');
     }
     return $result;
 }
예제 #2
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->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->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);
 }
예제 #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());
 }
예제 #4
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->orderMock->expects($this->any())->method('getId')->will($this->returnValue(1));
     $this->orderMock->expects($this->once())->method('hasDataChanges')->will($this->returnValue(true));
     $this->resource->save($this->orderMock);
 }
예제 #5
0
 /**
  * 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;
 }
예제 #6
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);
 }
예제 #7
0
 /**
  * Before load action
  *
  * @return $this
  */
 protected function _beforeLoad()
 {
     $this->getSelect()->from(array('sales' => $this->_orderResource->getMainTable()), array('store_id', 'lifetime' => new \Zend_Db_Expr('SUM(sales.base_grand_total)'), 'base_lifetime' => new \Zend_Db_Expr('SUM(sales.base_grand_total * sales.base_to_global_rate)'), 'avgsale' => new \Zend_Db_Expr('AVG(sales.base_grand_total)'), 'base_avgsale' => new \Zend_Db_Expr('AVG(sales.base_grand_total * sales.base_to_global_rate)'), 'num_orders' => new \Zend_Db_Expr('COUNT(sales.base_grand_total)')))->group('sales.store_id');
     if ($this->_customerId) {
         $this->addFieldToFilter('sales.customer_id', $this->_customerId);
     }
     if (!is_null($this->_state)) {
         $condition = '';
         switch ($this->_orderStateCondition) {
             case 'IN':
                 $condition = 'in';
                 break;
             case 'NOT IN':
                 $condition = 'nin';
                 break;
         }
         $this->addFieldToFilter('state', array($condition => $this->_state));
     }
     $this->_eventManager->dispatch('sales_sale_collection_query_before', array('collection' => $this));
     return $this;
 }