Post by thomash2 » Mon Apr 20, 2015 10:27 pm

Opencart 1.5.x seems to calculate tax based on the default customer group when checking out as a guest, even when a different customer group is selected during checkout.

in tax.php in the system folder:

Code: Select all

 public function getRates($value, $tax_class_id) {
		$tax_rates = array();
		
		if ($this->customer->isLogged()) {
			$customer_group_id = $this->customer->getCustomerGroupId();
		} else {
			$customer_group_id = $this->config->get('config_customer_group_id');
		}
Suppose I have 2 groups:
1: Default (taxed)
2: Not-to-be-taxed

If I have an account in group 2: Not-to-be-taxed.
If I checkout while logged in, the above code will return customer_group_id = 2, and I don't get taxed.
But if I checkout as a guest and not logged in, even when I select customer group 2, then it will still return the default group, customer_group_id = 1 and get taxed.

If I want customers to be able to checkout as a guest and still calculate tax using the selected customer groups instead of being set to default, can I change the code to this?

Code: Select all

if ($this->customer->isLogged()) {
			$customer_group_id = $this->customer->getCustomerGroupId();
		} elseif ($this->data['customer_group_id']) {
			$customer_group_id = $this->data['customer_group_id'];
		} else {
			$customer_group_id = $this->config->get('config_customer_group_id');
		}

New member

Posts

Joined
Tue Jul 30, 2013 12:44 am

Post by thomash2 » Tue Apr 21, 2015 12:54 am

I changed the code to this, to prevent undefined errors, and it seems to work.
Now the tax will evaluate the customer's selected group even if not logged in.

Code: Select all

if ($this->customer->isLogged()) {
         $customer_group_id = $this->customer->getCustomerGroupId();
} elseif (isset($this->session->data['guest']['customer_group_id'])) {
	$customer_group_id = $this->session->data['guest']['customer_group_id'];      
} else {
        $customer_group_id = $this->config->get('config_customer_group_id');
}
The vqmod is:

Code: Select all

<file name="system/library/tax.php">  
		<operation info="allow customer group guest checkout tax calcuation, normally uses default customer group when not logged in">
			<search position="after" ><![CDATA[$customer_group_id = $this->customer->getCustomerGroupId();]]></search>
			<add><![CDATA[
			} elseif (isset($this->session->data['guest']['customer_group_id'])) {
				$customer_group_id = $this->session->data['guest']['customer_group_id'];
			]]></add>
		</operation>
</file>

New member

Posts

Joined
Tue Jul 30, 2013 12:44 am

Post by soundzgood-nz » Tue Apr 21, 2015 7:36 pm

Ok, if I was in group 1 I wouldn't bother logging in though and go for tax-free shopping. Faster and cheaper all round!
So by bypassing login and allowing customers to choose group 2 you may hv opened a different can of worms.

Simon

User avatar
Active Member

Posts

Joined
Sat Oct 25, 2014 5:15 pm
Location - New Zealand

Post by thomash2 » Tue Apr 21, 2015 7:40 pm

For group 2, they have to enter a valid VAT ID and Opencart checks this automatically against the European database, so customers without a valid ID can't checkout.

New member

Posts

Joined
Tue Jul 30, 2013 12:44 am

Post by kryllem » Fri Feb 16, 2018 11:36 pm

Hello,

I'm stuck in same situation as in this topic. The only problem is that there is no longer if ($this->customer->isLogged()) { variable in version 2.0.X.X.
Anybody that knows how to solve that problem in versions of 2.0?

OR

To set a new customer group ID if job true and customer not logged in.
If true set customer group id 5.

Newbie

Posts

Joined
Wed Feb 18, 2015 10:08 pm
Who is online

Users browsing this forum: No registered users and 36 guests