Post by WayneSallee » Wed Sep 18, 2019 4:08 am

Continuing from the OpenCart 1.5+ Support thread "Tax by zip code, getting close... "

Using the code provided there, I made modifications and got things working for OpenCart 3.


Add the 1 session line:
$this->session = $registry->get('session');

Code: Select all

	public function __construct($registry) {
		$this->config = $registry->get('config');
		$this->db = $registry->get('db');
		$this->session = $registry->get('session');


Code: Select all

	public function getRates($value, $tax_class_id) {
		$tax_rate_data = array();

		if (isset($this->tax_rates[$tax_class_id])) {
			foreach ($this->tax_rates[$tax_class_id] as $tax_rate) {
				if (isset($tax_rate_data[$tax_rate['tax_rate_id']])) {
					$amount = $tax_rate_data[$tax_rate['tax_rate_id']]['amount'];
				} else {
					$amount = 0;

Place the following afterwards:

Code: Select all

				$sales_tax_name = "Sales Tax";
				if ($tax_rate['name']==$sales_tax_name) {
					$zip_tax_postcode = $this->session->data['shipping_address']['postcode'];
					$getnewtaxrate = $this->db->query("SELECT zip_tax_rate FROM " . DB_PREFIX . "zip_tax WHERE zip_code = '" . (int)$zip_tax_postcode . "'");
					if ($newtaxrate!=0)
					$tax_rate['rate']= $newtaxrate;

In admin control:
System - Localization
Create a Geo Zone for the Country and State, named after the State.
Create a Tax Rate named "Sales Tax" and give it your local percentage for the State Geo Zone just created. If postcode lookup fails, this default tax rate will be used.
Edit Tax Class, Taxable Goods, adding the "Sales Tax" tax rate.

Insert oc_zip_tax.sql into database.

Code: Select all


SET time_zone = "+00:00";

/*!40101 SET NAMES utf8mb4 */;


-- --------------------------------------------------------

-- Table structure for table `oc_zip_tax`

CREATE TABLE `oc_zip_tax` (
  `zip_code` int(11) NOT NULL,
  `zip_tax_rate` decimal(15,4) NOT NULL DEFAULT '0.0000'

-- Dumping data for table `oc_zip_tax`

INSERT INTO `oc_zip_tax` (`zip_code`, `zip_tax_rate`) VALUES
(32003, '7'),
(32004, '6.5'),
(32006, '7'),
(32007, '7'),
(32008, '7'),
(32009, '7'),
(32011, '7'),
(34997, '6.5'),
(1234567890, '10');

-- Indexes for dumped tables

-- Indexes for table `oc_zip_tax`
ALTER TABLE `oc_zip_tax`
  ADD PRIMARY KEY (`zip_code`);


Update this oc_zip_tax.sql with zip codes, and tax rates for your state.
I have a complete one for Florida if anyone wants it. I can't guarantee it's accuracy.

Wayne Sallee



Sat Jul 13, 2019 11:31 pm

Post by junk4u » Sat Nov 09, 2019 12:02 am

Hey glad to see someone from Florida.
At sometime in 2015 I was testing and trying to figure out how to use this program. I have looked at other and there are plenty of scripts out there for self hosting. I am not a programmer nor want to be, just want to do my own thing and enjoy learning how it all works along the way.

I am back at this thing and hoping to soon have my own website selling goods if at all possible. I think at this point in time it will be a little more cumbersome to do with all the tax configurations and filing that may have to be setup and confirmed with almost all the States coming into play. I'm guessing next year Florida will fall under the new economic nexus. With that I read somewhere that a bunch of websites could close because of the cost of this economic nexus setup could become cost burden, so may are running to marketplace facilitator (amazon, best buy, walmart, rakuten, ebay, etc...) which would handle all the taxing for the merchant as it is already. Basically it comes down to most states are looking to get those aforementioned big players who rake in a good amount of revenue. States are requiring registration of tax certificate and some as well registration of business which have varying cost from one time to annually. As well most States have a minimum amount of sales before they require to collect tax for that State.

What I don't understand is how the law changed to make it so cumbersome for a business to succeed in this Country. Instead they created a system that divides many... In other words there are 50 States, instead of saying merchants are now required to collect USE TAXES for each out of State customer on behalf of the 50 States they let each State collect Sales Tax from out of State merchants along with allowing local governments within their States to collect Discretionary aka local tax, surtax, etc... thus instead of 50 we have probably well over 5000 tax tables to be looked at. To top that off not only making each merchant apply for a states revenue certificate some want you to apply for a business license. I can understand a revenue tax certificate for each state as this is how you have to submit your month/bi-annually/annual tax collected, but a business license.

Not here to start something, going over the fact that this new database would have to absorb a vast new table of TAXs to do business online. Can't wait for this to change the retail sales to foreign countries and its coming.



Tue Aug 18, 2015 5:45 am

Post by WayneSallee » Sat Nov 09, 2019 12:59 am

Yes it's getting ridiculous. What a lot of states are doing, is stating that if you sell over a certain annual dollar amount to that state, you must register, and collect, otherwise you don't have to worry about it. So what's next? Trade wars between the states? :-)

But instead of getting discouraged, just address sales tax in Florida, and don't worry about the other states until a certain state is getting sales over it's limit, then address that state, and continue on. One step at a time. :-)

Worst case scenario; if a certain State is ridiculously difficult, just refuse to sell to that State.

Wayne Sallee



Sat Jul 13, 2019 11:31 pm
Who is online

Users browsing this forum: Baidu [Spider], thekrotek and 19 guests