本文整理汇总了PHP中Magento\Tax\Helper\Data::getCalculationAlgorithm方法的典型用法代码示例。如果您正苦于以下问题:PHP Data::getCalculationAlgorithm方法的具体用法?PHP Data::getCalculationAlgorithm怎么用?PHP Data::getCalculationAlgorithm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Tax\Helper\Data
的用法示例。
在下文中一共展示了Data::getCalculationAlgorithm方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Change default JavaScript templates for options rendering
*
* @param \Magento\Framework\Event\Observer $observer
* @return $this
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
$response = $observer->getEvent()->getResponseObject();
$options = $response->getAdditionalOptions();
$_product = $this->registry->registry('current_product');
if (!$_product) {
return $this;
}
$algorithm = $this->taxData->getCalculationAlgorithm();
$options['calculationAlgorithm'] = $algorithm;
// prepare correct template for options render
if ($this->taxData->displayBothPrices()) {
$options['optionTemplate'] = sprintf('<%%= data.label %%>' . '<%% if (data.finalPrice.value) { %%>' . ' +<%%= data.finalPrice.formatted %%> (%1$s <%%= data.basePrice.formatted %%>)' . '<%% } %%>', __('Excl. tax:'));
} elseif ($this->taxData->priceIncludesTax() && $this->taxData->displayPriceExcludingTax()) {
$options['optionTemplate'] = sprintf('<%%= data.label %%>' . '<%% if (data.basePrice.value) { %%>' . ' +<%%= data.basePrice.formatted %%>' . '<%% } %%>');
}
$response->setAdditionalOptions($options);
return $this;
}
示例2: calculateDynamicBundleAmount
/**
* Calculate amount for dynamic bundle product
*
* @param float $basePriceValue
* @param Product $bundleProduct
* @param \Magento\Bundle\Pricing\Price\BundleSelectionPrice[] $selectionPriceList
* @param null|bool|string|array $exclude
* @return \Magento\Framework\Pricing\Amount\AmountInterface
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
protected function calculateDynamicBundleAmount($basePriceValue, $bundleProduct, $selectionPriceList, $exclude)
{
$fullAmount = 0.0;
$adjustments = [];
$i = 0;
$amountList[$i]['amount'] = $this->calculator->getAmount($basePriceValue, $bundleProduct, $exclude);
$amountList[$i]['quantity'] = 1;
foreach ($selectionPriceList as $selectionPrice) {
++$i;
$amountList[$i]['amount'] = $selectionPrice->getAmount();
// always honor the quantity given
$amountList[$i]['quantity'] = $selectionPrice->getQuantity();
}
/** @var Store $store */
$store = $bundleProduct->getStore();
$roundingMethod = $this->taxHelper->getCalculationAlgorithm($store);
foreach ($amountList as $amountInfo) {
/** @var \Magento\Framework\Pricing\Amount\AmountInterface $itemAmount */
$itemAmount = $amountInfo['amount'];
$qty = $amountInfo['quantity'];
if ($roundingMethod != TaxCalculationInterface::CALC_TOTAL_BASE) {
//We need to round the individual selection first
$fullAmount += $this->priceCurrency->round($itemAmount->getValue()) * $qty;
foreach ($itemAmount->getAdjustmentAmounts() as $code => $adjustment) {
$adjustment = $this->priceCurrency->round($adjustment) * $qty;
$adjustments[$code] = isset($adjustments[$code]) ? $adjustments[$code] + $adjustment : $adjustment;
}
} else {
$fullAmount += $itemAmount->getValue() * $qty;
foreach ($itemAmount->getAdjustmentAmounts() as $code => $adjustment) {
$adjustment = $adjustment * $qty;
$adjustments[$code] = isset($adjustments[$code]) ? $adjustments[$code] + $adjustment : $adjustment;
}
}
}
if (is_array($exclude) == false) {
if ($exclude && isset($adjustments[$exclude])) {
$fullAmount -= $adjustments[$exclude];
unset($adjustments[$exclude]);
}
} else {
foreach ($exclude as $oneExclusion) {
if ($oneExclusion && isset($adjustments[$oneExclusion])) {
$fullAmount -= $adjustments[$oneExclusion];
unset($adjustments[$oneExclusion]);
}
}
}
return $this->amountFactory->create($fullAmount, $adjustments);
}