コード例 #1
4
 /**
  * Creates a sample order
  *
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function createOrder()
 {
     $store = $this->storeManager->getStore();
     $websiteId = $this->storeManager->getStore()->getWebsiteId();
     $customer = $this->getCustomer();
     $repositoryCustomer = $this->customerRepository->getById($customer->getId());
     $quote = $this->quoteFactory->create();
     $quote->setStore($store);
     $quote->assignCustomer($repositoryCustomer);
     $this->addItemsToQuote($quote);
     $quote->getBillingAddress()->addData($this->orderSampleData['address']);
     $quote->getShippingAddress()->addData($this->orderSampleData['address']);
     $this->addressRate->setCode(self::ORDER_SHIPPING_METHOD_CODE);
     $this->addressRate->getPrice(1);
     $shippingAddress = $quote->getShippingAddress();
     $shippingAddress->addShippingRate($this->addressRate);
     $shippingAddress->setCollectShippingRates(true)->collectShippingRates()->setShippingMethod(self::ORDER_SHIPPING_METHOD_CODE);
     $quote->setPaymentMethod(self::ORDER_PAYMENT_METHOD_CODE);
     $quote->setInventoryProcessed(false);
     $quote->save();
     $quote->getPayment()->importData(['method' => self::ORDER_PAYMENT_METHOD_CODE]);
     $quote->collectTotals()->save();
     $order = $this->quoteManagement->submit($quote);
     $order->setEmailSent(0);
 }
コード例 #2
0
 public function testGetCartForCustomer()
 {
     $customerId = 100;
     $cartMock = $this->getMock('\\Magento\\Quote\\Model\\Quote', [], [], '', false);
     $this->quoteRepositoryMock->expects($this->once())->method('getActiveForCustomer')->with($customerId)->willReturn($cartMock);
     $this->assertEquals($cartMock, $this->model->getCartForCustomer($customerId));
 }
コード例 #3
0
 /**
  * @param Quote $quote
  *
  * @return Order
  */
 public function submitOrder($quote)
 {
     /* ev. use placeOrder? */
     /* $this->_quoteManagement->placeOrder() */
     /** @var Order $order */
     $order = $this->_quoteManagement->submit($quote);
     $order->save();
     return $order;
 }
コード例 #4
0
 /**
  * Add one order to customer.
  *
  * @param $customer
  * @param $itemsData
  */
 public function addOrder($customer, $itemsData)
 {
     /* create order for Russian store/stock */
     $this->_manStore->setCurrentStore(self::STORE_ID_RUS);
     $store = $this->_manStore->getStore();
     /** @var \Magento\Quote\Model\Quote $quote */
     $quote = $this->_manObj->create(\Magento\Quote\Model\Quote::class);
     $quote->setStore($store);
     $quote->assignCustomer($customer);
     $quote->setInventoryProcessed(false);
     //not effect inventory
     /** Populate orders with data. */
     $this->_populateQuoteItems($quote);
     $this->_populateQuoteAddrShipping($quote, $customer);
     $this->_populateQuoteAddrBilling($quote, $customer);
     $this->_populateQuoteShippingMethod($quote);
     $this->_populateQuotePaymentMethod($quote);
     /* save quote then reload it by ID to create IDs for items (see MOBI-434, $_items, $_data['items'], $_data['items_collection']) */
     $quote->collectTotals();
     $quote->save();
     $id = $quote->getId();
     $quote = $this->_manObj->create(\Magento\Quote\Model\Quote::class);
     $quote->load($id);
     $quoteItems = $quote->getItemsCollection();
     // Create Order From Quote
     /** @var \Magento\Sales\Api\Data\OrderInterface $order */
     $order = $this->_manQuote->submit($quote);
     $items = $order->getItems();
     $item = reset($items);
     $item->setBaseOriginalPrice(8);
     $item->save();
     $order->save();
     /* register PV */
     $this->_manEvent->dispatch('checkout_submit_all_after', ['order' => $order, 'quote' => $quote]);
     /* prepare invoice */
     $invoice = $this->_manInvoice->prepareInvoice($order);
     $invoice->register();
     $invoice->save();
     //        $invoiceId = $invoice->getEntityId();
     /* update date paid in PV register */
     //        $orderId = $order->getEntityId();
     //        $bind = [
     //            \Praxigento\Pv\Data\Entity\Sale::ATTR_DATE_PAID => self::DATE_PAID
     //        ];
     //        $this->_repoPvSale->updateById($orderId, $bind);
     /* transfer PV to customer account */
     //        $invoice->load($invoiceId);
     //        $order->load($orderId);
     $order->setState(\Magento\Sales\Model\Order::STATE_PROCESSING);
     $this->_manEvent->dispatch('sales_order_invoice_pay', ['order' => $order, 'invoice' => $invoice]);
 }
コード例 #5
0
ファイル: Onepage.php プロジェクト: nja78/magento2
 /**
  * Create order based on checkout type. Create customer if necessary.
  *
  * @return $this
  */
 public function saveOrder()
 {
     $this->validate();
     $isNewCustomer = false;
     switch ($this->getCheckoutMethod()) {
         case self::METHOD_GUEST:
             $this->_prepareGuestQuote();
             break;
         case self::METHOD_REGISTER:
             $this->_prepareNewCustomerQuote();
             $isNewCustomer = true;
             break;
         default:
             $this->_prepareCustomerQuote();
             break;
     }
     $order = $this->quoteManagement->submit($this->getQuote());
     if ($isNewCustomer) {
         try {
             $this->_involveNewCustomer();
         } catch (\Exception $e) {
             $this->_logger->critical($e);
         }
     }
     $this->_checkoutSession->setLastQuoteId($this->getQuote()->getId())->setLastSuccessQuoteId($this->getQuote()->getId())->clearHelperData();
     if ($order) {
         $this->_eventManager->dispatch('checkout_type_onepage_save_order_after', ['order' => $order, 'quote' => $this->getQuote()]);
         /**
          * a flag to set that there will be redirect to third party after confirmation
          */
         $redirectUrl = $this->getQuote()->getPayment()->getOrderPlaceRedirectUrl();
         /**
          * we only want to send to customer about new order when there is no redirect to third party
          */
         if (!$redirectUrl && $order->getCanSendNewEmailFlag()) {
             try {
                 $this->orderSender->send($order);
             } catch (\Exception $e) {
                 $this->_logger->critical($e);
             }
         }
         // add order information to the session
         $this->_checkoutSession->setLastOrderId($order->getId())->setRedirectUrl($redirectUrl)->setLastRealOrderId($order->getIncrementId())->setLastOrderStatus($order->getStatus());
     }
     $this->_eventManager->dispatch('checkout_submit_all_after', ['order' => $order, 'quote' => $this->getQuote()]);
     return $this;
 }
コード例 #6
0
ファイル: Create.php プロジェクト: whoople/magento2-testing
 /**
  * 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;
 }
コード例 #7
0
ファイル: Checkout.php プロジェクト: whoople/magento2-testing
 /**
  * Place the order when customer returned from PayPal until this moment all quote data must be valid.
  *
  * @param string $token
  * @param string|null $shippingMethodCode
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function place($token, $shippingMethodCode = null)
 {
     if ($shippingMethodCode) {
         $this->updateShippingMethod($shippingMethodCode);
     }
     $isNewCustomer = false;
     switch ($this->getCheckoutMethod()) {
         case \Magento\Checkout\Model\Type\Onepage::METHOD_GUEST:
             $this->_prepareGuestQuote();
             break;
         case \Magento\Checkout\Model\Type\Onepage::METHOD_REGISTER:
             $this->_prepareNewCustomerQuote();
             $isNewCustomer = true;
             break;
         default:
             $this->_prepareCustomerQuote();
             break;
     }
     $this->_ignoreAddressValidation();
     $this->_quote->collectTotals();
     $order = $this->quoteManagement->submit($this->_quote);
     if ($isNewCustomer) {
         try {
             $this->_involveNewCustomer();
         } catch (\Exception $e) {
             $this->_logger->critical($e);
         }
     }
     if (!$order) {
         return;
     }
     // commence redirecting to finish payment, if paypal requires it
     if ($order->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_REDIRECT)) {
         $this->_redirectUrl = $this->_config->getExpressCheckoutCompleteUrl($token);
     }
     switch ($order->getState()) {
         // even after placement paypal can disallow to authorize/capture, but will wait until bank transfers money
         case \Magento\Sales\Model\Order::STATE_PENDING_PAYMENT:
             // TODO
             break;
             // regular placement, when everything is ok
         // regular placement, when everything is ok
         case \Magento\Sales\Model\Order::STATE_PROCESSING:
         case \Magento\Sales\Model\Order::STATE_COMPLETE:
         case \Magento\Sales\Model\Order::STATE_PAYMENT_REVIEW:
             $this->orderSender->send($order);
             $this->_checkoutSession->start();
             break;
         default:
             break;
     }
     $this->_order = $order;
 }