コード例 #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
ファイル: ShippingTest.php プロジェクト: nblair/magescotch
 public function testCollect()
 {
     $this->shippingAssignment->expects($this->exactly(3))->method('getShipping')->willReturn($this->shipping);
     $this->shipping->expects($this->exactly(2))->method('getAddress')->willReturn($this->address);
     $this->shipping->expects($this->once())->method('getMethod')->willReturn('flatrate');
     $this->shippingAssignment->expects($this->atLeastOnce())->method('getItems')->willReturn([$this->cartItem]);
     $this->freeShipping->expects($this->once())->method('isFreeShipping')->with($this->quote, [$this->cartItem])->willReturn(true);
     $this->address->expects($this->once())->method('setFreeShipping')->with(true);
     $this->total->expects($this->atLeastOnce())->method('setTotalAmount');
     $this->total->expects($this->atLeastOnce())->method('setBaseTotalAmount');
     $this->cartItem->expects($this->atLeastOnce())->method('getProduct')->willReturnSelf();
     $this->cartItem->expects($this->atLeastOnce())->method('isVirtual')->willReturn(false);
     $this->cartItem->expects($this->once())->method('getParentItem')->willReturn(false);
     $this->cartItem->expects($this->once())->method('getHasChildren')->willReturn(false);
     $this->cartItem->expects($this->once())->method('getWeight')->willReturn(2);
     $this->cartItem->expects($this->atLeastOnce())->method('getQty')->willReturn(2);
     $this->address->expects($this->once())->method('getFreeShipping')->willReturn(true);
     $this->cartItem->expects($this->once())->method('setRowWeight')->with(0);
     $this->address->expects($this->once())->method('setItemQty')->with(2);
     $this->address->expects($this->atLeastOnce())->method('setWeight');
     $this->address->expects($this->atLeastOnce())->method('setFreeMethodWeight');
     $this->address->expects($this->once())->method('collectShippingRates');
     $this->address->expects($this->once())->method('getAllShippingRates')->willReturn([$this->rate]);
     $this->rate->expects($this->once())->method('getCode')->willReturn('flatrate');
     $this->quote->expects($this->once())->method('getStore')->willReturn($this->store);
     $this->rate->expects($this->atLeastOnce())->method('getPrice')->willReturn(5);
     $this->priceCurrency->expects($this->once())->method('convert')->with(5, $this->store)->willReturn(5);
     $this->total->expects($this->once())->method('setShippingAmount')->with(5);
     $this->rate->expects($this->once())->method('getCarrierTitle')->willReturn('Carrier title');
     $this->rate->expects($this->once())->method('getMethodTitle')->willReturn('Method title');
     $this->address->expects($this->once())->method('setShippingDescription')->with('Carrier title - Method title');
     $this->address->expects($this->once())->method('getShippingDescription')->willReturn('Carrier title - Method title');
     $this->total->expects($this->once())->method('setShippingDescription')->with('Carrier title - Method title');
     $this->shippingModel->collect($this->quote, $this->shippingAssignment, $this->total);
 }
コード例 #3
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));
 }
コード例 #4
0
ファイル: Address.php プロジェクト: nja78/magento2
 /**
  * Add shipping rate
  *
  * @param \Magento\Quote\Model\Quote\Address\Rate $rate
  * @return $this
  */
 public function addShippingRate(\Magento\Quote\Model\Quote\Address\Rate $rate)
 {
     $rate->setAddress($this);
     $this->getShippingRatesCollection()->addItem($rate);
     return $this;
 }
コード例 #5
0
 /**
  * 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());
 }
コード例 #6
0
ファイル: Price.php プロジェクト: kidaa30/magento2-platformsh
 /**
  * Get Shipping Price
  *
  * @return float
  */
 public function getShippingPrice()
 {
     return $this->priceCurrency->convertAndFormat($this->shippingRate->getPrice());
 }