Question

For an US webshop, I need to remove taxes from a quote item for some customers. I can't use groups because there are in use for a loyalty program. I have added a customer attribute names "is_tax_exempt".

I have rewritten the following Model : Mage_Tax_Model_Sales_Total_Quote_Tax

In the _aggregateTaxPerRate() function I have modified the code like this :

$customer_id = Mage::getSingleton('customer/session')->getId();
$customer = Mage::getModel("customer/customer")->load($customer_id);

if($customer->getIsTaxExempt() == 1)
{
    $item->setTaxAmount(0);
    $item->setBaseTaxAmount(0);
}
else
{
    $item->setTaxAmount(max(0, $rowTax));
    $item->setBaseTaxAmount(max(0, $baseRowTax));
}

I have tested this code, it's working : tax_amount and base_tax_amount are setted to zero in the database.

My problem is : the price for the cart is wrong.

There is one item in the cart with price : 100$. The cart price is like :

Subtotal : $100.00

Grand Total Excl. Tax : $100.00

Tax : $6.50

Grand Total Incl. Tax : $106.50

I need to get Tax : 0 and Grand Total Incl/ tax : 0.

I have used the following configuration for tax parameters : http://www.magentocommerce.com/knowledge-base/entry/ce18-and-ee113-tax-config-us

How to do this ? Thank you in advance.

Était-ce utile?

La solution

I've managed to solve my problem by following this thread : Modify tax rate on cart quote items and recalculate

I have added an Observer to the event sales_quote_collect_totals_before.

And here is the content of my observer, very simple :

public function removetax($observer)
{
    $customer_id = Mage::getSingleton('customer/session')->getId();
    $customer = Mage::getModel("customer/customer")->load($customer_id);

    if($customer->getIsTaxExempt() == 1)
    {
        $items = $observer->getEvent()->getQuote()->getAllVisibleItems();
        foreach($items as $item)
            $item->getProduct()->setTaxClassId(0);
    }
}

Explanation : I load the current customer object in order to access the is_tax_exempt attribute. If customer is tax exempt, I grab the current cart content and for each item, I set the product tax class to 0. It is mandatory to not save the product or the item. The aim here is to set a value for the following calculation, not to save it in the database. Tax classes need to stay to the initial value in the db.

So by setting the tax class for this event, the following calculation will use the information setted in the observer. This seems to be a very clean method to achieve my first problem.

Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange
scroll top