MACMAN February 2016

Tax Estimate in Magento

I am struggling with the tax estimate. The scenario is this. When a logged in user changes the state, the tax is not estimated on the basis changed state but based on the state (region) that is in his profile. Can anybody point me to the right direction why this is happening? Thanks.

$post = Mage::app()->getFrontController()->getRequest()->getPost();
$quote= Mage::getSingleton('checkout/cart')->getQuote();
$country    = (string) $post['country_id'];
$postcode   = (string) $post['estimate_postcode'];
$city       = (string) $post['estimate_city'];
$regionId   = (string) $post['region_id'];
$region     = (string) $post['region'];

$quote->getShippingAddress()
->setCountryId($country)
->setCity($city)
->setPostcode($postcode)
->setRegionId($regionId)
->setRegion($region)
->setCollectShippingRates(true);
$quote->collectTotals();
$quote->save();

As i am seeing, the database table sales_flat_quote_address is updated with the new regionid. But if browse once again I can see that the region is reverted to the one that is from customer profile.

Answers


Muhammad Azam February 2016

Please try to add price rules from catalog -> price rules and create rules on basis of your state.


MACMAN February 2016

I finally found the issue. I was using an Ajax request to the cart controller method estimatePostAction and on successful return, the page where tax is supposed to be shown was reloaded. What actually happened was the new quote shipping address was replaced with the address information from the logged in user. This I found by checking the sales_flat_quote_address table that changes to the new region_id and instantly reverted to the original region_id.

When I stopped reloading the page the estimated region_id was retained. Now I update the tax and grand total html controls simply by using jquery. Hopefully somebody will later find this information useful.

Post Status

Asked in February 2016
Viewed 3,341 times
Voted 8
Answered 2 times

Search




Leave an answer