Post by SubatWest » Thu Nov 13, 2014 3:54 am

Hi
Making good progress in learning code and creating my website on Localhost. I have some products which are services and have no price, so I want to hide the price in template/product/Product.tpl ihave altered the code as follows:
After line 146 <ul class="list-unstyled">
I have added:
<h2> <?php if($price == "£0.00") { echo "Contact re cost"; } else { echo $price;} ?> </h2>
To give the following in context:
<?php if ($price) { ?>
<ul class="list-unstyled">
<h2> <?php if($price == "£0.00") { echo "Contact re cost"; } else { echo $price;} ?> </h2>
<?php if (!$special) { ?>
<li>
<h2><?php echo $price; ?></h2>
</li>

This Produces:
£0.00
£0.00
in Product panel.
I have tried other variations and either get code errors are the result above. What am I doing wrong?
As always help appreciated.

Active Member

Posts

Joined
Fri Oct 31, 2014 1:29 am

Post by Martijn ISB » Thu Nov 13, 2014 4:23 am

Add a var_dump to see what exactly you need to validate against.

Code: Select all

var_dump($price);

Newbie

Posts

Joined
Thu Nov 13, 2014 2:48 am

Post by qahar » Fri Nov 14, 2014 9:14 am

You look at wrong place.
The price is already formatted with currency sign, what happen if user change the currency to $ ?

Best way to check is at controller/product/product.php find $data['price'], that is where $price come from.

Add some test code, to change price into text FREE

Code: Select all

if ($this->config->get('config_customer_price') ... ) {
    $data['price'] = $this->currency->format(...);
} else {
    $data['price'] = false;
}

// Add new code as a test!
if (!(int)$product_info['price']) {
    $data['price'] =  'FREE';
}
Be aware code above not check special price!

Other alternative is make new variable as an anchor for front template

Code: Select all

if (!(int)$product_info['price']) {
    $data['isFree'] =  true;
} else {
    $data['isFree'] =  false;
}
And use them at template

Code: Select all

<?php if ($isFree) { ?>
    - Show free image (?)
    - Ignore special price
<?php } else { ?>
    echo $price;
    echo $special;
<?php } ?>
Hope that help

User avatar
Expert Member

Posts

Joined
Tue Jun 29, 2010 10:24 pm
Location - Indonesia

Post by SubatWest » Mon Nov 17, 2014 7:43 am

Many thanks for pointing me in the right direction...appreciated.

Active Member

Posts

Joined
Fri Oct 31, 2014 1:29 am
Who is online

Users browsing this forum: No registered users and 8 guests