0

Vers. Magento 1.9.3.8

Due to new duties in Australia I need to add taxes on cart if subtotal is lower than 1000 AUD.

So I'm planing to set a specific tax rate for that country, but it should be applied only if the order subtotal is lower than 1000 AUD.

Any help?

EDIT

Creating a specific tax rate is not what i need. In this way taxes are added to products. They should be applied only to "subtotal < 1000 AUD".

EDIT

To acive this result i've created a new Product Tax Class:

Class Name: Australian GST
Class Id: 6

a new Tax Rate:

Country: Australia
Rate:10

and a new Tax Rule to associate them.

Then I've created an observer fo the event:

sales_quote_collect_totals_before

Observer.php

<?php
class MyCompany_AdditionalTaxes_Model_Observer 
{
    public function addTaxes(Varien_Event_Observer $observer)
    {
        $quote = $observer->getQuote();
        $country = $quote->getShippingAddress()->getCountryId();

        if ($country == 'AU') {
            $currency = $quote->getQuoteCurrencyCode();

            if ($currency == 'AUD') {
                $subtotal = $quote->getSubtotal();
            } else {
                $baseCurrencyCode = Mage::app()->getBaseCurrencyCode();  
                $currencyRates = Mage::getModel('directory/currency')->getCurrencyRates($baseCurrencyCode, array('AUD'));
                $base_subtotal = $quote->getBaseSubtotal();
                $subtotal = $base_subtotal*$currencyRates['AUD'];
            }

            if ($subtotal < 1000) {
                foreach ($quote->getAllItems() as $item){
                    $product = $item->getProduct();
                    $product->setTaxClassId(6);
                }
            }
        }
        return $this;
    }
}

It seems to work fine for cart and checkout page.

If country is Australia and subtotal is lower than 1000AUD tax rate of 10% is applied. In all other cases normal configuration of taxes is applied.

I've still got problem with PayPal Express Checkout.

The callbak API hits shippingOptionsCallbackAction()

public function shippingOptionsCallbackAction()
{
    try {
        $quoteId = $this->getRequest()->getParam('quote_id');
        $this->_quote = Mage::getModel('sales/quote')->load($quoteId);
        $this->_initCheckout();
        $response = $this->_checkout->getShippingOptionsCallbackResponse($this->getRequest()->getParams());
        $this->getResponse()->setBody($response);
    } catch (Exception $e) {
        Mage::logException($e);
    }
}

but when quote is loaded with

Mage::getModel('sales/quote')->load($quoteId);

seems to ignore the observer

0

I had to fire

sales_quote_address_collect_totals_before

instead of

sales_quote_collect_totals_before

and made some change ti the observer

<?php
class MyCompany_AdditionalTaxes_Model_Observer 
{
    public function addTaxes(Varien_Event_Observer $observer)
    {
        $quoteAddress = $observer->getQuoteAddress()->getQuote();
        $quote = Mage::getModel('sales/quote')->load($quoteAddress->getId());;
        $country = $quoteAddress->getShippingAddress()->getCountryId();

        if ($country == 'AU') {
            $currency = $quote->getQuoteCurrencyCode();

            if ($currency == 'AUD') {
                $subtotal = $quote->getSubtotal();
            } else {
                $baseCurrencyCode = Mage::app()->getBaseCurrencyCode();  
                $currencyRates = Mage::getModel('directory/currency')->getCurrencyRates($baseCurrencyCode, array('AUD'));
                $base_subtotal = $quote->getBaseSubtotal();
                $subtotal = $base_subtotal*$currencyRates['AUD'];
            }

            if ($subtotal < 1000) {
                foreach ($quoteAddress->getAllItems() as $item){
                    $product = $item->getProduct();
                    $product->setTaxClassId(6);
                }
            }
        }
        return $this;
    }
}

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.