0

We need to apply all the taxes after applying discount. But currently taxes are calculated before applying discount.

Screenshot: ScreenshotAs you can see how the tax are being calculate on 200 rather than on (200-14) = 186.

Here are tax settings in store - Configuration - Sales - Tax. (We have set it to calculate taxes after discount)

enter image description here

Discounts are being applied here programmatically following this link because we have discounts based on the type of user logged in.

Any suggestion is much appreciated. Thanks.

2 Answers 2

2

Under System > Configuration > Tax > Calculation Settings there are options for the order tax rules are applied, including Apply Customer Tax which can be either Before Discount or After Discount.

I'm assuming you currently have it set to Before Discount.

0

I had the same issue but in my case I set the tax amount programmatically. So if you are into controlling and manipulating the tax in your module, follow these steps:

in your di.xml file add the following:

<preference for="Magento\Tax\Model\Sales\Total\Quote\Tax" type="Vendor\Module\Model\Sales\Total\Quote\Tax"/>

Add the following class override (in Vendor/Module/Model/Sales/Total/Quote/Tax.php):

<?php

namespace Vendor\Module\Model\Sales\Total\Quote;

use Magento\Customer\Api\Data\AddressInterfaceFactory as CustomerAddressFactory;
use Magento\Customer\Api\Data\RegionInterfaceFactory as CustomerAddressRegionFactory;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Quote\Api\Data\ShippingAssignmentInterface;
use Magento\Quote\Model\Quote\Address;
use Magento\Tax\Api\Data\TaxClassKeyInterface;
use Magento\Tax\Model\Calculation;

class Tax extends \Magento\Tax\Model\Sales\Total\Quote\Tax
{


    /**
    * Class constructor
    *
    * @param \Magento\Tax\Model\Config $taxConfig
    * @param \Magento\Tax\Api\TaxCalculationInterface $taxCalculationService
    * @param \Magento\Tax\Api\Data\QuoteDetailsInterfaceFactory $quoteDetailsDataObjectFactory
    * @param \Magento\Tax\Api\Data\QuoteDetailsItemInterfaceFactory $quoteDetailsItemDataObjectFactory
    * @param \Magento\Tax\Api\Data\TaxClassKeyInterfaceFactory $taxClassKeyDataObjectFactory
    * @param CustomerAddressFactory $customerAddressFactory
    * @param CustomerAddressRegionFactory $customerAddressRegionFactory
    * @param \Magento\Tax\Helper\Data $taxData
    */
    public function __construct(
        \Magento\Tax\Model\Config $taxConfig,
        \Magento\Tax\Api\TaxCalculationInterface $taxCalculationService,
        \Magento\Tax\Api\Data\QuoteDetailsInterfaceFactory $quoteDetailsDataObjectFactory,
        \Magento\Tax\Api\Data\QuoteDetailsItemInterfaceFactory $quoteDetailsItemDataObjectFactory,
        \Magento\Tax\Api\Data\TaxClassKeyInterfaceFactory $taxClassKeyDataObjectFactory,
        CustomerAddressFactory $customerAddressFactory,
        CustomerAddressRegionFactory $customerAddressRegionFactory,
        \Magento\Tax\Helper\Data $taxData
    ) {
        $this->setCode('tax');
        parent::__construct(
            $taxConfig,
            $taxCalculationService,
            $quoteDetailsDataObjectFactory,
            $quoteDetailsItemDataObjectFactory,
            $taxClassKeyDataObjectFactory,
            $customerAddressFactory,
            $customerAddressRegionFactory,
            $taxData
        );
    }

    /**
    * Custom Collect tax totals for quote address
    *
    * @param Quote $quote
    * @param ShippingAssignmentInterface $shippingAssignment
    * @param Address\Total $total
    * @return $this
    * @throws RemoteServiceUnavailableException
    */
    public function collect(
        \Magento\Quote\Model\Quote $quote,
        \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment,
        \Magento\Quote\Model\Quote\Address\Total $total
    ) {
        $total->setTotalAmount('tax', $set_your_tax_here);
        $total->setBaseTotalAmount('tax', $set_your_tax_here);
        return $this;
    }

}
1
  • I have use your code but setTaxAmount is working but grand total count default magento tax not count custom ser tax amount. Sep 14, 2019 at 5:57

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.