Magento Zip+4 Tax Calculation During Checkout – Solution Restrict Length to 5 Digits
on November 14, 2012
Problem
There is a bug in Magento that prevents Zip+4 tax codes from accurately being calculated. If a customer enters their zip code during Magento checkout in the Zip+4 format (XXXXX-XXXX) or makes a typo during entry, i.e. includes an extra or non-digit character, any applicable taxes are not calculated by Magento. This causes headaches for orders where tax should have been collected: following up with customers, running additional charges, and keeping track of these manual tax collections is an inconvenience for business owners and customers alike.
Since the solution to this problem is not well-documented by the Magento community, we have posted it below for others to refer to. Plus note that the instructions are for Magento 1.7.x (see the bottom of the post for info about applying this fix in Magento 1.4.x):
Solution
To fix the Magento Zip+4 tax calculation problem please take the follow steps:
- Access the site via an FTP Client
- Download app/code/core/Mage/Tax/Model/Resource/Calculation.php
- Create a new folder in the local section (this will preserve the fix during Magento upgrades): app/code/local/Mage/Tax/Model/Resource/
- Find the following code in Calculation.php (it should be around line 235):
$postcode = $request->getPostcode();
and replace it with
$postcode = substr($request->getPostcode(),0,5);
- Save Calculation.php and upload it to the new folder created in Step 3 app/code/local/Mage/Tax/Model/Resource/
Once the file has been uploaded the Magento zip+4 tax calculation issue should be fixed, remember to test checkout with a taxable address to verify that it is indeed working.
Fixing the Zip+4 Tax Calculation Issue in Magento 1.4x
The file structure in Magento 1.4.x differs from 1.7.x, so for the above steps you will need to:
- Locate Calculation.php in /app/code/core/Mage/Tax/Model/Mysql4
- Replace the /Resource/ directory with the /Mysql14/ directory
If you have any questions regarding this Magento tax+4 (or tax4) calculation issue, please leave a comment on this post and we will respond.
[…] the following code in Calculation.php (it should be around line 235): view sourceprint? 1.$postcode = […]
What about solving this issue for Postal Codes also?
Hi Patrick, what do you mean specifically? Are you trying to truncate the postal code to 5 digits in the shipping model?
I must be doing something wrong because I can’t get this to work in 1.7. It’s really straight forward but when I am in the shopping cart area and put in an zip+4 into the estimate shipping and tax area this does not work.
Thoughts?
Just discovered this problem and found your post. Easy solution, worked like a charm, and your post saved me time trying to troubleshoot it myself. Thanks!
Great post! You saved me a lot of troubleshooting time.
Surprised this isn’t talked about more, or fixed. It’s a pretty common bug in Magento and for larger companies that have a presence in multiple states, its downright annoying.
Thanks for your assistance!