Search code examples
magento-1.9

Magento Tax Rate Based on Shipping Destination


How can I change tax rates, when changing the shipping destination while checkout?

I didn't find settings for that in the backend (correct my if I'm wrong) so I think I have to solve that with an own module.

Where do I start with that project?

Example-Goal:

  • German Shop (19% VAT)
  • Swiss Client (Export from Germany to non-EU country: 0% VAT)
  • Shipping to border Germany-Switzerland to save shipping costs => I have to calculate with 19% VAT because the product is not (yet) leaving the country, even the customer is in Switzerland and gets still 0% VAT from Magento)

Any ideas, which classes and methods have to be changed for that?

Thanks in advance.


Solution

  • I solved my task.

    I override the Mage_Tax_Model_Calculation method getRateRequest. Here I can add my own logic before the switch statement which used $basedOn to assign the $address.

        //override basedOn
        $basedOn = 'billing';
        if ($shippingAddress != null && $billingAddress != null) {
            if ($shippingAddress->getData('country_id') != $billingAddress->getData('country_id') && $shippingAddress->getData('country_id') == 'DE') {
                $basedOn = 'shipping';
            }
        }
        // needed to still work if one of both addresses is null
        if ($shippingAddress == null || $billingAddress == null) {
            $basedOn = 'default';
        }
        else  {
            $ship = $shippingAddress->getData('country_id');
            $bill = $billingAddress->getData('country_id');
            if(empty($ship) || empty($bill))  {
                $basedOn = 'default';
            }
        }