/**
  * Handles asynchronous email sending
  * @return void
  */
 public function sendEmails()
 {
     if ($this->globalConfig->getValue('sales_email/general/async_sending')) {
         $this->entityCollection->addFieldToFilter('send_email', ['eq' => 1]);
         $this->entityCollection->addFieldToFilter('email_sent', ['null' => true]);
         /** @var \Magento\Sales\Model\AbstractModel $item */
         foreach ($this->entityCollection->getItems() as $item) {
             if ($this->emailSender->send($item, true)) {
                 $this->entityResource->save($item->setEmailSent(true));
             }
         }
     }
 }
示例#2
0
 /**
  * Perform actions after object save
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
 {
     /** @var \Magento\Sales\Model\Order\Invoice\Item $object */
     if (null == !$object->getOrderItem()) {
         $object->getOrderItem()->save();
     }
     return parent::_afterSave($object);
 }
示例#3
0
 /**
  * Perform actions before object save
  *
  * @param \Magento\Framework\Model\AbstractModel|\Magento\Framework\DataObject $object
  * @return $this
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     /** @var \Magento\Sales\Model\Order\Shipment\Item $object */
     if (!$object->getParentId() && $object->getShipment()) {
         $object->setParentId($object->getShipment()->getId());
     }
     return parent::_beforeSave($object);
 }
示例#4
0
 /**
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     /**@var $object \Magento\Sales\Model\Order\Creditmemo\Item*/
     if (!$object->getParentId() && $object->getCreditmemo()) {
         $object->setParentId($object->getCreditmemo()->getId());
     }
     return parent::_beforeSave($object);
 }
示例#5
0
 /**
  * Perform actions before object save
  *
  * @param \Magento\Framework\Model\AbstractModel|\Magento\Framework\DataObject $object
  * @return $this
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     /** @var \Magento\Sales\Model\Order\Invoice $object */
     if (!$object->getOrderId() && $object->getOrder()) {
         $object->setOrderId($object->getOrder()->getId());
         $object->setBillingAddressId($object->getOrder()->getBillingAddress()->getId());
     }
     return parent::_beforeSave($object);
 }
示例#6
0
 /**
  * Perform actions before object save
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     parent::_beforeSave($object);
     $warnings = $this->validator->validate($object);
     if (!empty($warnings)) {
         throw new \Magento\Framework\Exception\LocalizedException(__("Cannot save comment:\n%1", implode("\n", $warnings)));
     }
     return $this;
 }
示例#7
0
 /**
  * Perform actions before object save
  *
  * @param \Magento\Framework\Model\AbstractModel|\Magento\Framework\DataObject $object
  * @return $this
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     /**@var $object \Magento\Sales\Model\Order\Payment */
     parent::_beforeSave($object);
     if (!$object->getParentId() && $object->getOrder()) {
         $object->setParentId($object->getOrder()->getId());
     }
     return $this;
 }
 /**
  * @param int $configValue
  * @param array|null $collectionItems
  * @param bool|null $emailSendingResult
  * @dataProvider executeDataProvider
  * @return void
  */
 public function testExecute($configValue, $collectionItems, $emailSendingResult)
 {
     $path = 'sales_email/general/async_sending';
     $this->globalConfig->expects($this->once())->method('getValue')->with($path)->willReturn($configValue);
     if ($configValue) {
         $this->entityCollection->expects($this->at(0))->method('addFieldToFilter')->with('send_email', ['eq' => 1]);
         $this->entityCollection->expects($this->at(1))->method('addFieldToFilter')->with('email_sent', ['null' => true]);
         $this->entityCollection->expects($this->any())->method('getItems')->willReturn($collectionItems);
         if ($collectionItems) {
             /** @var \Magento\Sales\Model\AbstractModel|\PHPUnit_Framework_MockObject_MockObject $collectionItem */
             $collectionItem = $collectionItems[0];
             $this->emailSender->expects($this->once())->method('send')->with($collectionItem, true)->willReturn($emailSendingResult);
             if ($emailSendingResult) {
                 $collectionItem->expects($this->once())->method('setEmailSent')->with(true)->willReturn($collectionItem);
                 $this->entityResource->expects($this->once())->method('save')->with($collectionItem);
             }
         }
     }
     $this->object->sendEmails();
 }
示例#9
0
 /**
  * Perform actions before object save
  *
  * @param \Magento\Framework\Model\AbstractModel|\Magento\Framework\DataObject $object
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     /** @var \Magento\Sales\Model\Order\Shipment $object */
     if ((!$object->getId() || null !== $object->getItems()) && !count($object->getAllItems())) {
         throw new \Magento\Framework\Exception\LocalizedException(__('We cannot create an empty shipment.'));
     }
     if (!$object->getOrderId() && $object->getOrder()) {
         $object->setOrderId($object->getOrder()->getId());
         $object->setShippingAddressId($object->getOrder()->getShippingAddress()->getId());
     }
     return parent::_beforeSave($object);
 }
示例#10
0
 /**
  * Performs validation before save
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     /** @var \Magento\Sales\Model\Order\Shipment\Comment $object */
     if (!$object->getParentId() && $object->getShipment()) {
         $object->setParentId($object->getShipment()->getId());
     }
     parent::_beforeSave($object);
     $errors = $this->validator->validate($object);
     if (!empty($errors)) {
         throw new \Magento\Framework\Exception\LocalizedException(__("Cannot save comment:\n%1", implode("\n", $errors)));
     }
     return $this;
 }
 /**
  * @param bool $isVirtualOrder
  * @param int $formatCallCount
  * @param string|null $expectedShippingAddress
  * @dataProvider sendVirtualOrderDataProvider
  */
 public function testSendVirtualOrder($isVirtualOrder, $formatCallCount, $expectedShippingAddress)
 {
     $address = 'address_test';
     $this->orderMock->setData(\Magento\Sales\Api\Data\OrderInterface::IS_VIRTUAL, $isVirtualOrder);
     $this->shipmentMock->expects($this->once())->method('setSendEmail')->with(true);
     $this->globalConfig->expects($this->once())->method('getValue')->with('sales_email/general/async_sending')->willReturn(false);
     $addressMock = $this->getMock('Magento\\Sales\\Model\\Order\\Address', [], [], '', false);
     $this->addressRenderer->expects($this->exactly($formatCallCount))->method('format')->with($addressMock, 'html')->willReturn($address);
     $this->stepAddressFormat($addressMock, $isVirtualOrder);
     $this->shipmentMock->expects($this->once())->method('getCustomerNoteNotify')->willReturn(false);
     $this->templateContainerMock->expects($this->once())->method('setTemplateVars')->with(['order' => $this->orderMock, 'shipment' => $this->shipmentMock, 'comment' => '', 'billing' => $addressMock, 'payment_html' => 'payment', 'store' => $this->storeMock, 'formattedShippingAddress' => $expectedShippingAddress, 'formattedBillingAddress' => $address]);
     $this->identityContainerMock->expects($this->once())->method('isEnabled')->willReturn(false);
     $this->shipmentResourceMock->expects($this->once())->method('saveAttribute')->with($this->shipmentMock, 'send_email');
     $this->assertFalse($this->sender->send($this->shipmentMock));
 }
示例#12
0
 /**
  * Performs validation before save
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     parent::_beforeSave($object);
     if (!$object->getParentId() && $object->getOrder()) {
         $object->setParentId($object->getOrder()->getId());
     }
     // Init customer address id if customer address is assigned
     $customerData = $object->getCustomerAddressData();
     if ($customerData) {
         $object->setCustomerAddressId($customerData->getId());
     }
     $warnings = $this->_validator->validate($object);
     if (!empty($warnings)) {
         throw new \Magento\Framework\Exception\LocalizedException(__("We can't save the address:\n%1", implode("\n", $warnings)));
     }
     return $this;
 }
示例#13
0
 /**
  * {@inheritdoc}
  */
 public function save(\Magento\Framework\Model\AbstractModel $object)
 {
     /** @var \Magento\Sales\Model\Order $object */
     $this->stateHandler->check($object);
     return parent::save($object);
 }
示例#14
0
 /**
  * Lookup for parent_id in already saved transactions of this payment by the order_id
  * Also serialize additional information, if any
  *
  * @param \Magento\Framework\Model\AbstractModel|\Magento\Sales\Model\Order\Payment\Transaction $transaction
  * @throws \Magento\Framework\Exception\LocalizedException
  * @return $this
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $transaction)
 {
     $parentTxnId = $transaction->getData('parent_txn_id');
     $txnId = $transaction->getData('txn_id');
     $orderId = $transaction->getData('order_id');
     $paymentId = $transaction->getData('payment_id');
     $idFieldName = $this->getIdFieldName();
     if ($parentTxnId) {
         if (!$txnId || !$orderId || !$paymentId) {
             throw new \Magento\Framework\Exception\LocalizedException(__('We don\'t have enough information to save the parent transaction ID.'));
         }
         $parentId = (int) $this->_lookupByTxnId($orderId, $paymentId, $parentTxnId, $idFieldName);
         if ($parentId) {
             $transaction->setData('parent_id', $parentId);
         }
     }
     // make sure unique key won't cause trouble
     if ($transaction->isFailsafe()) {
         $autoincrementId = (int) $this->_lookupByTxnId($orderId, $paymentId, $txnId, $idFieldName);
         if ($autoincrementId) {
             $transaction->setData($idFieldName, $autoincrementId)->isObjectNew(false);
         }
     }
     return parent::_beforeSave($transaction);
 }
示例#15
0
 /**
  * Update related grid table after object save
  *
  * @param \Magento\Framework\Model\AbstractModel|\Magento\Framework\DataObject $object
  * @return \Magento\Framework\Model\ModelResource\Db\AbstractDb
  */
 protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
 {
     $resource = parent::_afterSave($object);
     if ($object->getParentId()) {
         $this->gridPool->refreshByOrderId($object->getParentId());
     }
     return $resource;
 }