/**
  * 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);
 }
 /**
  * Converts a specified rate model to a shipping method data object.
  *
  * @param string $quoteCurrencyCode The quote currency code.
  * @param \Magento\Quote\Model\Quote\Address\Rate $rateModel The rate model.
  * @return mixed Shipping method data object.
  */
 public function modelToDataObject($rateModel, $quoteCurrencyCode)
 {
     /** @var \Magento\Directory\Model\Currency $currency */
     $currency = $this->storeManager->getStore()->getBaseCurrency();
     $errorMessage = $rateModel->getErrorMessage();
     return $this->shippingMethodDataFactory->create()->setCarrierCode($rateModel->getCarrier())->setMethodCode($rateModel->getMethod())->setCarrierTitle($rateModel->getCarrierTitle())->setMethodTitle($rateModel->getMethodTitle())->setAmount($currency->convert($rateModel->getPrice(), $quoteCurrencyCode))->setBaseAmount($rateModel->getPrice())->setAvailable(empty($errorMessage));
 }
 /**
  * Get Shipping Price including or excluding tax
  *
  * @param \Magento\Quote\Model\Quote\Address\Rate $rateModel
  * @param bool $flag
  * @return float
  */
 private function getShippingPriceWithFlag($rateModel, $flag)
 {
     return $this->taxHelper->getShippingPrice($rateModel->getPrice(), $flag, $rateModel->getAddress(), $rateModel->getAddress()->getQuote()->getCustomerTaxClassId());
 }
Esempio n. 4
0
 /**
  * Get Shipping Price
  *
  * @return float
  */
 public function getShippingPrice()
 {
     return $this->priceCurrency->convertAndFormat($this->shippingRate->getPrice());
 }