本文整理汇总了PHP中Magento\Tax\Model\Config::applyTaxAfterDiscount方法的典型用法代码示例。如果您正苦于以下问题:PHP Config::applyTaxAfterDiscount方法的具体用法?PHP Config::applyTaxAfterDiscount怎么用?PHP Config::applyTaxAfterDiscount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Tax\Model\Config
的用法示例。
在下文中一共展示了Config::applyTaxAfterDiscount方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: applyTaxAfterDiscount
/**
* Check what taxes should be applied after discount
*
* @param null|int|string|Store $store
* @return bool
*/
public function applyTaxAfterDiscount($store = null)
{
return $this->_config->applyTaxAfterDiscount($store);
}
示例2: totalBaseCalculation
/**
* Calculate item price and row total including/excluding tax based on total price rounding level
*
* @param QuoteDetailsItem $item
* @param \Magento\Framework\Object $taxRateRequest
* @param int $storeId
* @return TaxDetailsItem
*/
protected function totalBaseCalculation(QuoteDetailsItem $item, \Magento\Framework\Object $taxRateRequest, $storeId)
{
/** @var \Magento\Tax\Service\V1\Data\TaxDetails\AppliedTax[] $appliedTaxes */
$appliedTaxes = [];
$appliedTaxBuilder = $this->taxDetailsItemBuilder->getAppliedTaxBuilder();
$appliedTaxRateBuilder = $appliedTaxBuilder->getAppliedTaxRateBuilder();
$taxRateRequest->setProductClassId($item->getTaxClassId());
$appliedRates = $this->calculator->getAppliedRates($taxRateRequest);
$rate = $this->calculator->getRate($taxRateRequest);
$quantity = $this->getTotalQuantity($item);
$price = $priceInclTax = $this->calculator->round($item->getUnitPrice());
$rowTotal = $rowTotalInclTax = $taxableAmount = $this->calcRowTotal($item);
$discountAmount = $item->getDiscountAmount();
$applyTaxAfterDiscount = $this->config->applyTaxAfterDiscount($storeId);
$discountTaxCompensationAmount = 0;
$isTotalBasedCalculation = $this->config->getAlgorithm($storeId) == Calculation::CALC_TOTAL_BASE;
if ($item->getTaxIncluded()) {
if ($taxRateRequest->getSameRateAsStore()) {
$rowTaxExact = $this->calculator->calcTaxAmount($rowTotalInclTax, $rate, true, false);
if ($isTotalBasedCalculation) {
$rowTax = $this->deltaRound($rowTaxExact, $rate, true);
} else {
$rowTax = $this->calculator->round($rowTaxExact);
}
$rowTotal = $rowTotalInclTax - $rowTax;
$price = $this->calculator->round($rowTotal / $quantity);
} else {
$storeRate = $this->calculator->getStoreRate($taxRateRequest, $storeId);
$priceInclTax = $this->calculatePriceInclTax($price, $storeRate, $rate);
$rowTotalInclTax = $priceInclTax * $quantity;
$taxableAmount = $rowTotalInclTax;
if ($isTotalBasedCalculation) {
$rowTax = $this->deltaRound($this->calculator->calcTaxAmount($rowTotalInclTax, $rate, true, false), $rate, true);
} else {
$rowTax = $this->calculator->calcTaxAmount($rowTotalInclTax, $rate, true, true);
}
$rowTotal = $rowTotalInclTax - $rowTax;
$price = $this->calculator->round($rowTotal / $quantity);
}
//Handle discount
if ($discountAmount && $applyTaxAfterDiscount) {
//TODO: handle originalDiscountAmount
$taxableAmount = max($taxableAmount - $discountAmount, 0);
$rowTaxAfterDiscount = $this->calculator->calcTaxAmount($taxableAmount, $rate, true, false);
if ($isTotalBasedCalculation) {
//Round the row tax using a different type so that we don't pollute the rounding deltas
$rowTaxAfterDiscount = $this->deltaRound($rowTaxAfterDiscount, $rate, true, self::KEY_TAX_AFTER_DISCOUNT_DELTA_ROUNDING);
} else {
$rowTaxAfterDiscount = $this->calculator->round($rowTaxAfterDiscount);
}
// Set discount tax compensation
$discountTaxCompensationAmount = $rowTax - $rowTaxAfterDiscount;
$rowTax = $rowTaxAfterDiscount;
}
//save applied taxes
$appliedTaxes = $this->getAppliedTaxes($appliedTaxBuilder, $rowTax, $rate, $appliedRates);
} else {
//catalog price does not include tax
$appliedRates = $this->calculator->getAppliedRates($taxRateRequest);
$rowTaxes = [];
$rowTaxesBeforeDiscount = [];
//Apply each tax rate separately
foreach ($appliedRates as $appliedRate) {
$taxId = $appliedRate['id'];
$taxRate = $appliedRate['percent'];
if ($isTotalBasedCalculation) {
$rowTaxPerRate = $this->deltaRound($this->calculator->calcTaxAmount($rowTotal, $taxRate, false, false), $taxId, false);
} else {
$rowTaxPerRate = $this->calculator->calcTaxAmount($rowTotal, $taxRate, false, true);
}
$rowTaxAfterDiscount = $rowTaxPerRate;
//Handle discount
if ($discountAmount && $applyTaxAfterDiscount) {
//TODO: handle originalDiscountAmount
$rowTaxAfterDiscount = $this->calculator->calcTaxAmount(max($rowTotal - $discountAmount, 0), $taxRate, false, false);
if ($isTotalBasedCalculation) {
//Round the row tax using a different type so that we don't pollute the rounding deltas
$rowTaxAfterDiscount = $this->deltaRound($rowTaxAfterDiscount, $taxRate, false, self::KEY_TAX_AFTER_DISCOUNT_DELTA_ROUNDING);
} else {
$rowTaxAfterDiscount = $this->calculator->round($rowTaxAfterDiscount);
}
}
$appliedTaxes[$appliedRate['id']] = $this->getAppliedTax($appliedTaxBuilder, $rowTaxAfterDiscount, $appliedRate);
$rowTaxes[] = $rowTaxAfterDiscount;
$rowTaxesBeforeDiscount[] = $rowTaxPerRate;
}
$rowTax = array_sum($rowTaxes);
$rowTaxBeforeDiscount = array_sum($rowTaxesBeforeDiscount);
$rowTotalInclTax = $rowTotal + $rowTaxBeforeDiscount;
$priceInclTax = $this->calculator->round($rowTotalInclTax / $quantity);
}
$this->taxDetailsItemBuilder->setCode($item->getCode());
//.........这里部分代码省略.........
示例3: checkDiscountSettings
/**
* Check if tax discount settings are compatible
*
* Matrix for invalid discount settings is as follows:
* Before Discount / Excluding Tax
* Before Discount / Including Tax
*
* @param null|int|bool|string|\Magento\Store\Model\Store $store $store
* @return bool
*/
public function checkDiscountSettings($store = null)
{
return $this->taxConfig->applyTaxAfterDiscount($store);
}