3

How to customize tax in shopping cart page. If the customer have some certification**(eav_attr)** then not showing tax in all pages.

We already tried sales_quote_collect_totals_before

1

You can observe to the event sales_quote_address_collect_totals_after and achieve it.

File : app\code\Vendor\Module\etc\events.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="sales_quote_address_collect_totals_after">
        <observer name="changeTax" instance="Vendor\Module\Observer\ChangeTax"/>
    </event>
</config>

File : app\code\Vendor\Module\Observer\ChangeTax.php

<?php
namespace Vendor\Module\Observer;

use \Magento\Framework\Event\ObserverInterface;
use \Magento\Framework\Event\Observer;

class ChangeTax implements ObserverInterface
{
    public function execute(Observer $observer)
    {
        $quote = $observer->getQuote();
        foreach ($quote->getAllItems() as $quoteItem) {
              $product = $quoteItem->getProduct();
              $product->setTaxClassId(0); 
        }
    }
}
-1

After searching we got solution for this issue

vendor/module/etc/event.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">              
    <event name="checkout_cart_update_items_after">
        <observer name="updatemessage" instance="DCKAP\Checkout\Observer\UpdateMessage" />
    </event>

</config>

vendor/module/Observer

<?php
namespace DCKAP\Checkout\Observer;

use \Magento\Framework\Event\ObserverInterface;
use \Magento\Framework\Event\Observer;

class ChangeTaxTotal implements ObserverInterface
{
    public function execute(Observer $observer)
    {
        $quote = $observer->getQuote();
        foreach ($quote->getAllItems() as $quoteItem) {
            $product = $quoteItem->getProduct();
             $product->setTaxClassId(0); // tax class removed.now the price is with no tax

        }
    }
}

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.