Vinícius
Vinícius

Reputation: 483

How to edit the value of a variable in a TPL file

I'm trying to edit a TPL file from the OpenCart platform, I would put the "price" divided into 6 parts, but when I put $pricecard = $ price / 6; And Echo $ pricecard; No value is returned.

Here's my code

  <span> <?php echo "Ou em 6x de: " ?></span>
  <?php $a = 6; ?>
  <?php $pricecard = $price; ?>
  <span><?php $pricecard = $tbData->priceFormat($pricecard); ?></span>
  <span class="price-cartao"><?php echo $pricecard; ?></span>

I put $pricecard getting the value of $price and displayed normally, any suggestions?

Upvotes: 0

Views: 573

Answers (1)

Konstantinos
Konstantinos

Reputation: 417

Usually all the calculations and the variables should be inside the controller before the load of the view.

In your product.tpl the $price is already loaded as string because it has the currency symbol in it, so you cannot divide it by other variable.

I will attach a solution but by using the product controller.

So you open the file: catalog/controller/product/product.php and you search for line:

For Opencart 1.5.x

$this->data['options'] = array();

Before that line, you add:

$a = 6; $this->data['custom_price'] = $product_info['price'] / $a;

For Opencart 2.x

$data['options'] = array();

Before that line, you add:

$a = 6; $data['custom_price'] = $product_info['price'] / $a;

Of course you need to change the $a variable to whatever you want to have there.

Then you open the product.tpl file and you just show the information easily. For example:

<span><?php echo $custom_price; ?></span>

Hope I helped you. Cheers

Upvotes: 1

Related Questions