Opencart 1.5.6 How to show price, with and without tax in shopping cart?

I want to show the individual price of each product, tax included and tax excluded on the shopping cart page. I configured opencart to display prices including tax, but I want to add a column to show the price without tax. I have Opencart 1.5.6. Please can someone help me ?. I tried to modify cart.php and cart.tpl but I have not succeeded, $price_extax shows last price in all products in shopping cart. Thank You.

In cart.tpl I added following code: It shows column tittle:

<td class="price"><?php echo "Price ex-tax"; ?></td>

It shows price:

<td class="price"><?php echo $price_extax; ?></td>

In cart.php I added following code:

$this->data['price_extax'] = $this->currency->format($this->tax->calculate($product['price'],$product['tax_class_id'], $this->config->get('config_tax'))/1.12); //My code (tax is 12%)

Upvotes: 0

Views: 4939

Answers (2)

SOLVED

Thanks to billynoah and shaddyx for your help. The solution to the problem, which has worked for me is:

In catalog/controller/checkout/cart.php I added (only commented line //):

$this->data['products'][] = array(
                'extax'           => $this->currency->format($product['price']), //Gets Price tax excluded

In catalog/view/theme/default/template/checkout/cart.tpl I added (only commented lines //):

<td class="price"><?php echo $column_price; ?></td>
<td class="price"><?php echo "Price (tax excluded)"; ?></td> //Shows column tittle
<td class="total"><?php echo $column_total; ?></td>

and

<td class="price"><?php echo $product['price']; ?></td>
<td class="price"><?php echo $product['extax']; ?></td>  //Shows price tax excluded
<td class="total"><?php echo $product['total']; ?></td>

Upvotes: 0

You Old Fool
You Old Fool

Reputation: 22969

You cannot declare a single variable or property and expect it to magically become part of the product array. Learning some php basics will go a long way.

Also, there is no need to use tax method here if your goal is to omit taxes. You can simply use the currency->format method without it.

You need to make price_extax part of the product array. Immediately after $this->data['products'][] = array( add something like:

'extax' => $this->currency->format($product['price']),

Then your table cell should hold $product['extax']

Upvotes: 1

Related Questions