本文整理汇总了PHP中Magento\Tax\Model\Config::needPriceConversion方法的典型用法代码示例。如果您正苦于以下问题:PHP Config::needPriceConversion方法的具体用法?PHP Config::needPriceConversion怎么用?PHP Config::needPriceConversion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Tax\Model\Config
的用法示例。
在下文中一共展示了Config::needPriceConversion方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getTaxPrice
/**
* Get product price with all tax settings processing
*
* @param \Magento\Catalog\Model\Product $product
* @param float $price inputted product price
* @param bool $includingTax return price include tax flag
* @param null|\Magento\Customer\Model\Address\AbstractAddress $shippingAddress
* @param null|\Magento\Customer\Model\Address\AbstractAddress $billingAddress
* @param null|int $ctc customer tax class
* @param null|string|bool|int|\Magento\Store\Model\Store $store
* @param bool $priceIncludesTax flag what price parameter contain tax
* @param bool $roundPrice
* @return float
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function getTaxPrice($product, $price, $includingTax = null, $shippingAddress = null, $billingAddress = null, $ctc = null, $store = null, $priceIncludesTax = null, $roundPrice = true)
{
if (!$price) {
return $price;
}
$store = $this->_storeManager->getStore($store);
if ($this->_taxConfig->needPriceConversion($store)) {
if ($priceIncludesTax === null) {
$priceIncludesTax = $this->_taxConfig->priceIncludesTax($store);
}
$shippingAddressDataObject = null;
if ($shippingAddress === null) {
$shippingAddressDataObject = $this->convertDefaultTaxAddress($this->_customerSession->getDefaultTaxShippingAddress());
} elseif ($shippingAddress instanceof \Magento\Customer\Model\Address\AbstractAddress) {
$shippingAddressDataObject = $shippingAddress->getDataModel();
}
$billingAddressDataObject = null;
if ($billingAddress === null) {
$billingAddressDataObject = $this->convertDefaultTaxAddress($this->_customerSession->getDefaultTaxBillingAddress());
} elseif ($billingAddress instanceof \Magento\Customer\Model\Address\AbstractAddress) {
$billingAddressDataObject = $billingAddress->getDataModel();
}
$taxClassKey = $this->_taxClassKeyFactory->create();
$taxClassKey->setType(TaxClassKeyInterface::TYPE_ID)->setValue($product->getTaxClassId());
if ($ctc === null && $this->_customerSession->getCustomerGroupId() != null) {
$ctc = $this->customerGroupRepository->getById($this->_customerSession->getCustomerGroupId())->getTaxClassId();
}
$customerTaxClassKey = $this->_taxClassKeyFactory->create();
$customerTaxClassKey->setType(TaxClassKeyInterface::TYPE_ID)->setValue($ctc);
$item = $this->_quoteDetailsItemFactory->create();
$item->setQuantity(1)->setCode($product->getSku())->setShortDescription($product->getShortDescription())->setTaxClassKey($taxClassKey)->setIsTaxIncluded($priceIncludesTax)->setType('product')->setUnitPrice($price);
$quoteDetails = $this->_quoteDetailsFactory->create();
$quoteDetails->setShippingAddress($shippingAddressDataObject)->setBillingAddress($billingAddressDataObject)->setCustomerTaxClassKey($customerTaxClassKey)->setItems([$item])->setCustomerId($this->_customerSession->getCustomerId());
$storeId = null;
if ($store) {
$storeId = $store->getId();
}
$taxDetails = $this->_taxCalculationService->calculateTax($quoteDetails, $storeId, $roundPrice);
$items = $taxDetails->getItems();
$taxDetailsItem = array_shift($items);
if ($includingTax !== null) {
if ($includingTax) {
$price = $taxDetailsItem->getPriceInclTax();
} else {
$price = $taxDetailsItem->getPrice();
}
} else {
switch ($this->_taxConfig->getPriceDisplayType($store)) {
case Config::DISPLAY_TYPE_EXCLUDING_TAX:
case Config::DISPLAY_TYPE_BOTH:
$price = $taxDetailsItem->getPrice();
break;
case Config::DISPLAY_TYPE_INCLUDING_TAX:
$price = $taxDetailsItem->getPriceInclTax();
break;
default:
break;
}
}
}
if ($roundPrice) {
return $this->priceCurrency->round($price);
} else {
return $price;
}
}
示例2: needPriceConversion
/**
* Check if necessary do product price conversion
* If it necessary will be returned conversion type (minus or plus)
*
* @param null|int|string|Store $store
* @return bool
*/
public function needPriceConversion($store = null)
{
return $this->_config->needPriceConversion($store);
}
示例3: getTaxPrice
/**
* Get product price with all tax settings processing
*
* @param \Magento\Catalog\Model\Product $product
* @param float $price inputted product price
* @param bool $includingTax return price include tax flag
* @param null|Address $shippingAddress
* @param null|Address $billingAddress
* @param null|int $ctc customer tax class
* @param null|string|bool|int|Store $store
* @param bool $priceIncludesTax flag what price parameter contain tax
* @param bool $roundPrice
* @return float
*/
public function getTaxPrice($product, $price, $includingTax = null, $shippingAddress = null, $billingAddress = null, $ctc = null, $store = null, $priceIncludesTax = null, $roundPrice = true)
{
if (!$price) {
return $price;
}
$store = $this->_storeManager->getStore($store);
if ($this->_taxConfig->needPriceConversion($store)) {
if (is_null($priceIncludesTax)) {
$priceIncludesTax = $this->_taxConfig->priceIncludesTax($store);
}
$shippingAddressDataObject = null;
if ($shippingAddress instanceof \Magento\Customer\Model\Address\AbstractAddress) {
$shippingAddressDataObject = $this->_addressConverter->createAddressFromModel($shippingAddress, null, null);
}
$billingAddressDataObject = null;
if ($billingAddress instanceof \Magento\Customer\Model\Address\AbstractAddress) {
$billingAddressDataObject = $this->_addressConverter->createAddressFromModel($billingAddress, null, null);
}
$item = $this->_quoteDetailsItemBuilder->setQuantity(1)->setCode($product->getSku())->setShortDescription($product->getShortDescription())->setTaxClassKey($this->_taxClassKeyBuilder->setType(TaxClassKey::TYPE_ID)->setValue($product->getTaxClassId())->create())->setTaxIncluded($priceIncludesTax)->setType('product')->setUnitPrice($price)->create();
$quoteDetails = $this->_quoteDetailsBuilder->setShippingAddress($shippingAddressDataObject)->setBillingAddress($billingAddressDataObject)->setCustomerTaxClassKey($this->_taxClassKeyBuilder->setType(TaxClassKey::TYPE_ID)->setValue($ctc)->create())->setItems([$item])->setCustomerId($this->_customerSession->getCustomerId())->create();
$storeId = null;
if ($store) {
$storeId = $store->getId();
}
$taxDetails = $this->_taxCalculationService->calculateTax($quoteDetails, $storeId);
$items = $taxDetails->getItems();
$taxDetailsItem = array_shift($items);
if (!is_null($includingTax)) {
if ($includingTax) {
$price = $taxDetailsItem->getPriceInclTax();
} else {
$price = $taxDetailsItem->getPrice();
}
} else {
switch ($this->_taxConfig->getPriceDisplayType($store)) {
case Config::DISPLAY_TYPE_EXCLUDING_TAX:
case Config::DISPLAY_TYPE_BOTH:
$price = $taxDetailsItem->getPrice();
break;
case Config::DISPLAY_TYPE_INCLUDING_TAX:
$price = $taxDetailsItem->getPriceInclTax();
break;
default:
break;
}
}
}
if ($roundPrice) {
return $store->roundPrice($price);
} else {
return $price;
}
}