Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Order totals including tax in order totals [OpenCart]

Tags:

opencart

I have prices in my store including 20% TAX. The problem is with order totals, let me explain.

Default view in OpenCart (shipping cost is 3€ incl. TAX):

Product X ........................1,50 EUR
------------------------------------------
Shipping  ........................2,50 EUR

Subtotal without tax..............1,25 EUR
TAX 20%...........................0,75 EUR
Total (incl Tax)..................4,50 EUR

The problem is:

  • subtotal does not includes shipping cost = confusing
  • shipping cost is displayed without TAX = confusing

Expected result:

Product X ........................1,50 EUR
------------------------------------------
Shipping  ...........................3 EUR

Subtotal without tax..............3,75 EUR
TAX 20%...........................0,75 EUR
Total (incl Tax)..................4,50 EUR

Is there any way to display order totals as I showed?

like image 825
Adrian Avatar asked Nov 20 '15 21:11

Adrian


1 Answers

Not sure why this super old question hasn't been answered but in case anyone still cares, here you go (for Opencart v1.5 but you could easily adapt these concepts for newer versions)...

In order to preserve the actual cost calcs I'm only going to be manipulating the displayed amount for each total. The underlying value will stay as is, which will save us from needing to make any adjustment to the calculations and possibly affecting other parts of the totals in an undesired way.

To show shipping with tax, in catalog/model/total/shipping, change:

'text' => $this->currency->format($this->session->data['shipping_method']['cost']),

to

'text' => $this->currency->format($this->tax->calculate($this->session->data['shipping_method']['cost'], $this->session->data['shipping_method']['tax_class_id'], $this->config->get('config_tax'))),

We're just using the tax class to add the shipping tax into the displayed total based on your "Display Prices With Tax" setting.

Please note, the shipping estimator and shipping charge options in checkout will not be affected by the above changes and will still be displayed without tax as usual - only once you have selected a shipping method and you are looking at the total in the totals section of your cart summary will it be affected. If you want to change the shipping charges to include tax in the estimator and during checkout process there would be other files involved.

Now to include the untaxed shipping total in the displayed subtotal you can edit catalog/model/total/sub_total.php and change:

'text' => $this->currency->format($sub_total),

to

'text' => $this->currency->format($sub_total + (isset($this->session->data['shipping_method']['cost']) ? $this->session->data['shipping_method']['cost'] : 0)),
like image 174
Eaten by a Grue Avatar answered Nov 13 '22 23:11

Eaten by a Grue