Example #1
0
    public function testEmail()
    {
        $orderId = 10000031;
        $this->request->expects($this->once())
            ->method('getParam')
            ->with('order_id')
            ->will($this->returnValue($orderId));
        $this->orderRepositoryMock->expects($this->once())
            ->method('get')
            ->with($orderId)
            ->willReturn($this->orderMock);
        $this->orderMock->expects($this->atLeastOnce())
            ->method('getEntityId')
            ->will($this->returnValue($orderId));
        $this->orderManagementMock->expects($this->once())
            ->method('notify')
            ->with($orderId)
            ->willReturn(true);
        $this->messageManager->expects($this->once())
            ->method('addSuccess')
            ->with('You sent the order email.');
        $this->resultRedirect->expects($this->once())
            ->method('setPath')
            ->with('sales/order/view', ['order_id' => $orderId])
            ->willReturnSelf();

        $this->assertInstanceOf(
            'Magento\Backend\Model\View\Result\Redirect',
            $this->orderEmail->executeInternal()
        );
        $this->assertEquals($this->response, $this->orderEmail->getResponse());
    }
 /**
  * Submit quote
  *
  * @param Quote $quote
  * @param array $orderData
  * @return \Magento\Framework\Model\AbstractExtensibleModel|\Magento\Sales\Api\Data\OrderInterface|object
  * @throws \Exception
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function submitQuote(QuoteEntity $quote, $orderData = [])
 {
     $order = $this->orderFactory->create();
     $this->quoteValidator->validateBeforeSubmit($quote);
     if (!$quote->getCustomerIsGuest()) {
         if ($quote->getCustomerId()) {
             $this->_prepareCustomerQuote($quote);
         }
         $this->customerManagement->populateCustomerInfo($quote);
     }
     $addresses = [];
     $quote->reserveOrderId();
     if ($quote->isVirtual()) {
         $this->dataObjectHelper->mergeDataObjects('\\Magento\\Sales\\Api\\Data\\OrderInterface', $order, $this->quoteAddressToOrder->convert($quote->getBillingAddress(), $orderData));
     } else {
         $this->dataObjectHelper->mergeDataObjects('\\Magento\\Sales\\Api\\Data\\OrderInterface', $order, $this->quoteAddressToOrder->convert($quote->getShippingAddress(), $orderData));
         $shippingAddress = $this->quoteAddressToOrderAddress->convert($quote->getShippingAddress(), ['address_type' => 'shipping', 'email' => $quote->getCustomerEmail()]);
         $addresses[] = $shippingAddress;
         $order->setShippingAddress($shippingAddress);
         $order->setShippingMethod($quote->getShippingAddress()->getShippingMethod());
     }
     $billingAddress = $this->quoteAddressToOrderAddress->convert($quote->getBillingAddress(), ['address_type' => 'billing', 'email' => $quote->getCustomerEmail()]);
     $addresses[] = $billingAddress;
     $order->setBillingAddress($billingAddress);
     $order->setAddresses($addresses);
     $order->setPayment($this->quotePaymentToOrderPayment->convert($quote->getPayment()));
     $order->setItems($this->resolveItems($quote));
     if ($quote->getCustomer()) {
         $order->setCustomerId($quote->getCustomer()->getId());
     }
     $order->setQuoteId($quote->getId());
     //To Set Vat Exempt Quote values to Order
     $order->setVatpername($quote->getVatpername());
     $order->setVatcomment($quote->getVatcomment());
     $order->setVatdeclare($quote->getVatdeclare());
     $order->setCustomerEmail($quote->getCustomerEmail());
     $order->setCustomerFirstname($quote->getCustomerFirstname());
     $order->setCustomerMiddlename($quote->getCustomerMiddlename());
     $order->setCustomerLastname($quote->getCustomerLastname());
     $this->eventManager->dispatch('sales_model_service_quote_submit_before', ['order' => $order, 'quote' => $quote]);
     try {
         $order = $this->orderManagement->place($order);
         $quote->setIsActive(false);
         $this->eventManager->dispatch('sales_model_service_quote_submit_success', ['order' => $order, 'quote' => $quote]);
         $this->quoteRepository->save($quote);
     } catch (\Exception $e) {
         $this->eventManager->dispatch('sales_model_service_quote_submit_failure', ['order' => $order, 'quote' => $quote, 'exception' => $e]);
         throw $e;
     }
     return $order;
 }
Example #3
0
 /**
  * Hold selected orders
  *
  * @param AbstractCollection $collection
  * @return \Magento\Backend\Model\View\Result\Redirect
  */
 protected function massAction(AbstractCollection $collection)
 {
     $countHoldOrder = 0;
     foreach ($collection->getItems() as $order) {
         if (!$order->canHold()) {
             continue;
         }
         $this->orderManagement->hold($order->getEntityId());
         $countHoldOrder++;
     }
     $countNonHoldOrder = $collection->count() - $countHoldOrder;
     if ($countNonHoldOrder && $countHoldOrder) {
         $this->messageManager->addError(__('%1 order(s) were not put on hold.', $countNonHoldOrder));
     } elseif ($countNonHoldOrder) {
         $this->messageManager->addError(__('No order(s) were put on hold.'));
     }
     if ($countHoldOrder) {
         $this->messageManager->addSuccess(__('You have put %1 order(s) on hold.', $countHoldOrder));
     }
     $resultRedirect = $this->resultRedirectFactory->create();
     $resultRedirect->setPath($this->getComponentRefererUrl());
     return $resultRedirect;
 }
 /**
  * @param int $orderId
  * @param string $message
  */
 protected function addOrderComment($orderId, $message)
 {
     /* @var $order \Magento\Sales\Api\Data\OrderInterface */
     $order = $this->orderRepository->get($orderId);
     // create comment
     $orderStatusHistory = $this->orderStatusHistoryFactory->create();
     $orderStatusHistory->setParentId($orderId);
     $orderStatusHistory->setComment($message);
     $orderStatusHistory->setIsCustomerNotified(false);
     $orderStatusHistory->setIsVisibleOnFront(false);
     $orderStatusHistory->setEntityName(Queue::ENTITY_TYPE_CODE_ORDER);
     $orderStatusHistory->setStatus($order->getStatus());
     // add comment to order
     $this->orderManagement->addComment($orderId, $orderStatusHistory);
 }
Example #5
0
 public function testExecuteOneOrderPutOnHold()
 {
     $order1 = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock();
     $order2 = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock();
     $orders = [$order1, $order2];
     $countOrders = count($orders);
     $this->orderCollectionMock->expects($this->any())->method('getItems')->willReturn($orders);
     $order1->expects($this->once())->method('canHold')->willReturn(true);
     $this->orderManagementMock->expects($this->once())->method('hold');
     $this->orderCollectionMock->expects($this->once())->method('count')->willReturn($countOrders);
     $order2->expects($this->once())->method('canHold')->willReturn(false);
     $this->messageManagerMock->expects($this->once())->method('addError')->with('1 order(s) were not put on hold.');
     $this->messageManagerMock->expects($this->once())->method('addSuccess')->with('You have put 1 order(s) on hold.');
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('sales/*/')->willReturnSelf();
     $this->massAction->execute();
 }
Example #6
0
 /**
  * Create new order
  *
  * @return \Magento\Sales\Model\Order
  */
 public function createOrder()
 {
     $this->_prepareCustomer();
     $this->_validate();
     $quote = $this->getQuote();
     $this->_prepareQuoteItems();
     $orderData = [];
     if ($this->getSession()->getOrder()->getId()) {
         $oldOrder = $this->getSession()->getOrder();
         $originalId = $oldOrder->getOriginalIncrementId();
         if (!$originalId) {
             $originalId = $oldOrder->getIncrementId();
         }
         $orderData = ['original_increment_id' => $originalId, 'relation_parent_id' => $oldOrder->getId(), 'relation_parent_real_id' => $oldOrder->getIncrementId(), 'edit_increment' => $oldOrder->getEditIncrement() + 1, 'increment_id' => $originalId . '-' . ($oldOrder->getEditIncrement() + 1)];
         $quote->setReservedOrderId($orderData['increment_id']);
     }
     $order = $this->quoteManagement->submit($quote, $orderData);
     if ($this->getSession()->getOrder()->getId()) {
         $oldOrder = $this->getSession()->getOrder();
         $oldOrder->setRelationChildId($order->getId());
         $oldOrder->setRelationChildRealId($order->getIncrementId());
         $this->orderManagement->cancel($oldOrder->getEntityId());
         $order->save();
     }
     if ($this->getSendConfirmation()) {
         $this->emailSender->send($order);
     }
     $this->_eventManager->dispatch('checkout_submit_all_after', ['order' => $order, 'quote' => $quote]);
     return $order;
 }