/** * Check if we have display prices including and excluding tax * With corrections for Dynamic prices * * @return bool */ public function displayBothPrices() { $product = $this->getProduct(); if ($product->getPriceType() == \Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC && $product->getPriceModel()->getIsPricesCalculatedByIndex() !== false) { return false; } return $this->_taxHelper->displayBothPrices(); }
/** * Get Tax Adjustments for configurable product * * @param \Magento\ConfigurableProduct\Pricing\Price\AttributePrice $attribute * @param array $result * @return array */ public function afterPrepareAdjustmentConfig(\Magento\ConfigurableProduct\Pricing\Price\AttributePrice $attribute, array $result) { $product = $result['product']; $productClassId = $product->getTaxClassId(); $defaultValue = $this->taxCalculationService->getDefaultCalculatedRate($productClassId, $result['customerId']); $result['defaultTax'] = $defaultValue + $result['defaultTax']; $currentTax = $this->taxCalculationService->getCalculatedRate($productClassId, $result['customerId']); $result['currentTax'] = $currentTax + $result['currentTax']; $adjustment = $product->getPriceInfo()->getAdjustment(\Magento\Tax\Pricing\Adjustment::ADJUSTMENT_CODE); $result['includeTax'] = $adjustment->isIncludedInBasePrice(); $result['showIncludeTax'] = $this->taxHelper->displayPriceIncludingTax(); $result['showBothPrices'] = $this->taxHelper->displayBothPrices(); return $result; }
/** * 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; }
/** * Define if both prices should be displayed * * @return bool */ public function displayBothPrices() { return $this->taxHelper->displayBothPrices(); }
/** * Define if adjustment is included in display price * * @return bool */ public function isIncludedInDisplayPrice() { return $this->taxHelper->displayPriceIncludingTax() || $this->taxHelper->displayBothPrices(); }