Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ShippingMethodConverter.php
Go to the documentation of this file.
1 <?php
7 
13 {
20 
24  protected $taxHelper;
25 
33  public function __construct(
34  \Magento\Quote\Api\Data\ShippingMethodInterfaceFactory $shippingMethodDataFactory,
36  \Magento\Tax\Helper\Data $taxHelper
37  ) {
38  $this->shippingMethodDataFactory = $shippingMethodDataFactory;
39  $this->storeManager = $storeManager;
40  $this->taxHelper = $taxHelper;
41  }
42 
50  public function modelToDataObject($rateModel, $quoteCurrencyCode)
51  {
53  $currency = $this->storeManager->getStore()->getBaseCurrency();
54 
55  $errorMessage = $rateModel->getErrorMessage();
56  return $this->shippingMethodDataFactory->create()
57  ->setCarrierCode($rateModel->getCarrier())
58  ->setMethodCode($rateModel->getMethod())
59  ->setCarrierTitle($rateModel->getCarrierTitle())
60  ->setMethodTitle($rateModel->getMethodTitle())
61  ->setAmount($currency->convert($rateModel->getPrice(), $quoteCurrencyCode))
62  ->setBaseAmount($rateModel->getPrice())
63  ->setAvailable(empty($errorMessage))
64  ->setErrorMessage(empty($errorMessage) ? false : $errorMessage)
65  ->setPriceExclTax(
66  $currency->convert($this->getShippingPriceWithFlag($rateModel, false), $quoteCurrencyCode)
67  )
68  ->setPriceInclTax(
69  $currency->convert($this->getShippingPriceWithFlag($rateModel, true), $quoteCurrencyCode)
70  );
71  }
72 
80  private function getShippingPriceWithFlag($rateModel, $flag)
81  {
82  return $this->taxHelper->getShippingPrice(
83  $rateModel->getPrice(),
84  $flag,
85  $rateModel->getAddress(),
86  $rateModel->getAddress()->getQuote()->getCustomerTaxClassId()
87  );
88  }
89 }
return false
Definition: gallery.phtml:36
$storeManager
__construct(\Magento\Quote\Api\Data\ShippingMethodInterfaceFactory $shippingMethodDataFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Tax\Helper\Data $taxHelper)