0
votes

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%)
2
Perhaps if you post the code you tried someone can offer a fix or suggestion for improvement.billynoah
What is the purpose of doing this: <td class="price"><?php echo "Price ex-tax"; ?></td>??? Isn't this <td class="price">Price ex-tax</td> enough? Maybe some advanced learning of PHP, HTML, CSS, JS (and recommended is MySQL as well!) should happen before you start implementing something in bigger applications... This is your price excl. tax: find this line $this->data['products'][] = array( and add a new line into this array: 'price_extax' => $product['price'], - this is it.shadyyx

2 Answers

1
votes

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']

0
votes

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>