0

I'm trying to solve a Magento 2.1.2 bug (Tier price percentage incorrect if special price set - https://github.com/magento/magento2/issues/6923) by creating a custom module.

My code so far:

<?php

namespace Namespace\TierPricingFix\Pricing\Price;

use Magento\Catalog\Model\Product;
use Magento\Customer\Api\GroupManagementInterface;
use Magento\Customer\Model\Session;
use Magento\Framework\Pricing\Adjustment\CalculatorInterface;
use Magento\Framework\Pricing\Amount\AmountInterface;
use Magento\Framework\Pricing\Price\AbstractPrice;
use Magento\Framework\Pricing\Price\BasePriceProviderInterface;
use Magento\Framework\Pricing\PriceInfoInterface;

//Added
use Magento\Catalog\Pricing\Price\FinalPrice;

 class TierPriceFix extends \Magento\Catalog\Pricing\Price\TierPrice
 {
   const TAXNL = 1.21; // Multiply base amound with NL tax 21%
   /**
    *  TODO: make TAXNL dynamic.
    */

   // Fix for https://github.com/magento/magento2/issues/6923
   public function getSavePercent(AmountInterface $amount)
   {
       return ceil(
           100 - ((100 / $this->priceInfo->getPrice(FinalPrice::PRICE_CODE)->getValue())
               * ($amount->getBaseAmount()*self::TAXNL))
       );
   }
 }

The module works as expected, the tier pricing discount percentage are generated correctly. However I want to make the constant TAXNL variable, so that it also works with other European tax percentages.

What is the best way to get the current tax percentage on a Magento 2 product page with tier pricing?

I've tried addding Magento\Tax\Model\TaxCalculation to the __construct method but this didn't work.

0

This is what I did, trying to solve this Magento 2.1.2 bug:

public function getSavePercent(AmountInterface $amount)
{
    $tax = $amount->getAdjustmentAmounts();
    $sumarTax = $tax['tax'];
    return ceil(
        100 - ((100 / $this->priceInfo->getPrice(FinalPrice::PRICE_CODE)->getValue())
            * ($amount->getBaseAmount() + $sumarTax))
    );
}

It works until they found a right solution

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.