/** * Attempt to collect address shipping rates and return them for further usage in instant update API * Returns empty array if it was impossible to obtain any shipping rate * If there are shipping rates obtained, the method must return one of them as default. * * @param Address $address * @param bool $mayReturnEmpty * @param bool $calculateTax * @return array|false * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ protected function _prepareShippingOptions(Address $address, $mayReturnEmpty = false, $calculateTax = false) { $options = []; $i = 0; $iMin = false; $min = false; $userSelectedOption = null; foreach ($address->getGroupedAllShippingRates() as $group) { foreach ($group as $rate) { $amount = (double) $rate->getPrice(); if ($rate->getErrorMessage()) { continue; } $isDefault = $address->getShippingMethod() === $rate->getCode(); $amountExclTax = $this->_taxData->getShippingPrice($amount, false, $address); $amountInclTax = $this->_taxData->getShippingPrice($amount, true, $address); $options[$i] = new \Magento\Framework\DataObject(['is_default' => $isDefault, 'name' => trim("{$rate->getCarrierTitle()} - {$rate->getMethodTitle()}", ' -'), 'code' => $rate->getCode(), 'amount' => $amountExclTax]); if ($calculateTax) { $options[$i]->setTaxAmount($amountInclTax - $amountExclTax + $address->getTaxAmount() - $address->getShippingTaxAmount()); } if ($isDefault) { $userSelectedOption = $options[$i]; } if (false === $min || $amountInclTax < $min) { $min = $amountInclTax; $iMin = $i; } $i++; } } if ($mayReturnEmpty && $userSelectedOption === null) { $options[] = new \Magento\Framework\DataObject(['is_default' => true, 'name' => __('N/A'), 'code' => 'no_rate', 'amount' => 0.0]); if ($calculateTax) { $options[$i]->setTaxAmount($address->getTaxAmount()); } } elseif ($userSelectedOption === null && isset($options[$iMin])) { $options[$iMin]->setIsDefault(true); } // Magento will transfer only first 10 cheapest shipping options if there are more than 10 available. if (count($options) > 10) { usort($options, [get_class($this), 'cmpShippingOptions']); array_splice($options, 10); // User selected option will be always included in options list if ($userSelectedOption !== null && !in_array($userSelectedOption, $options)) { $options[9] = $userSelectedOption; } } return $options; }
/** * Get selected shipping method price * * @param bool $inclTax * @return string */ protected function _getShippingPrice($inclTax) { $address = $this->getQuote()->getShippingAddress(); $rate = $address->getShippingRateByCode($address->getShippingMethod()); return $this->formatPrice($this->_taxData->getShippingPrice($rate->getPrice(), $inclTax, $address)); }
/** * @param float $price * @param bool|null $flag * @return float */ public function getShippingPrice($price, $flag) { return $this->getQuote()->getStore()->convertPrice($this->_taxData->getShippingPrice($price, $flag, $this->getAddress()), true); }
/** * Return formatted shipping price * * @param float $price * @param bool $isInclTax * @return string */ protected function _getShippingPrice($price, $isInclTax) { return $this->_formatPrice($this->_taxHelper->getShippingPrice($price, $isInclTax, $this->_address)); }
/** * Get shipping price * * @param float $price * @param bool $flag * @return float */ public function getShippingPrice($price, $flag) { return $this->priceCurrency->convertAndFormat($this->_taxData->getShippingPrice($price, $flag, $this->getAddress(), null, $this->getAddress()->getQuote()->getStore()), true, PriceCurrencyInterface::DEFAULT_PRECISION, $this->getQuote()->getStore()); }
/** * Get Shipping Price including or excluding tax * * @param bool $flag * @return float */ protected function getShippingPriceWithFlag($flag) { $price = $this->taxHelper->getShippingPrice($this->getShippingRate()->getPrice(), $flag, $this->getAddress(), $this->getQuote()->getCustomerTaxClassId()); return $this->priceCurrency->convertAndFormat($price, true, PriceCurrencyInterface::DEFAULT_PRECISION, $this->getQuote()->getStore()); }
/** * 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()); }
/** * @param Address $address * @param float $price * @param bool $flag * @return float */ public function getShippingPrice($address, $price, $flag) { return $address->getQuote()->getStore()->convertPrice($this->_taxHelper->getShippingPrice($price, $flag, $address), true); }
/** * @param Address $address * @param float $price * @param bool $flag * @return float */ public function getShippingPrice($address, $price, $flag) { return $this->priceCurrency->convertAndFormat($this->_taxHelper->getShippingPrice($price, $flag, $address), true, PriceCurrencyInterface::DEFAULT_PRECISION, $address->getQuote()->getStore()); }
/** * Get Shipping Price * * @param float $price * @param bool $flag * @return float */ public function getShippingPrice($price, $flag) { return $this->formatPrice($this->_taxHelper->getShippingPrice($price, $flag, $this->getAddress(), $this->getQuote()->getCustomerTaxClassId())); }
/** * Get Shipping Price including or excluding tax * * @param bool $flag * @return float */ protected function getShippingPriceWithFlag($flag) { $price = $this->taxHelper->getShippingPrice($this->getShippingRate()->getPrice(), $flag, $this->getAddress(), $this->getQuote()->getCustomerTaxClassId()); return $this->getQuote()->getStore()->convertPrice($price, true); }