Post by pvtsales » Sun Apr 04, 2010 5:45 pm

How to hide Add to cart if price is negative and show cart if price is >= 0.
If it's equal to 0 must show add to cart.

I've tried this in product.tpl:

<?php if ($price < 0 ) { echo "See related products"; } else { ?>
<div class="content"><?php echo $text_qty; ?>
<input type="text" name="quantity" size="3" value="1" />
<a onclick="$('#product').submit();" id="add_to_cart" class="button"><span><?php echo $button_add_to_cart; ?></span></a></div>
<div><input type="hidden" name="product_id" value="<?php echo $product_id; ?>" />
<?php }?>

But don't work. Always show add to cart

If use

<?php if ($price == 0 ) { echo "See related products"; } else { ?>

I get See related products for negative price too.

Seems that negative price becomes equal to zero.

Version: 1.4.6

Newbie

Posts

Joined
Sat Jan 16, 2010 1:50 am

Post by rph » Sun Apr 04, 2010 11:35 pm

The problem is $price is a string, not a float number, because it's been formatted with the currency symbol. You can do something quick and dirty like:

Code: Select all

<?php if ((float)str_replace('$', '', $price) < 0) { echo "See related products"; } else { ?>

-Ryan


rph
Expert Member

Posts

Joined
Fri Jan 08, 2010 5:05 am
Location - Lincoln, Nebraska

Post by pvtsales » Mon Apr 05, 2010 12:29 am

Don't work. I'm using Euro maybe a problem?

Newbie

Posts

Joined
Sat Jan 16, 2010 1:50 am

Post by rph » Mon Apr 05, 2010 12:30 am

Well yeah. Just change the dollar sign to a euro.

-Ryan


rph
Expert Member

Posts

Joined
Fri Jan 08, 2010 5:05 am
Location - Lincoln, Nebraska

Post by pvtsales » Mon Apr 05, 2010 2:31 am

Tried this:

<?php if ((float)str_replace('€', '', $price) < 0) { echo "See related products"; } else { ?>

But don't work.

Price is shown like this: 13,26€

€ is after price. May be a problem?

Newbie

Posts

Joined
Sat Jan 16, 2010 1:50 am

Post by pvtsales » Mon Apr 05, 2010 2:34 am

Don't work either I put € on left or right in admin

Newbie

Posts

Joined
Sat Jan 16, 2010 1:50 am

Post by rph » Mon Apr 05, 2010 3:57 am

It's because you're using a comma decimal separator.

-Ryan


rph
Expert Member

Posts

Joined
Fri Jan 08, 2010 5:05 am
Location - Lincoln, Nebraska

Post by dirtyharry » Wed Aug 10, 2011 10:36 pm

Any changes made in view/theme/default/template/product.tpl
are not recommended!

Because any other existing and up coming template would be affected by this modification!!!

So here is my idea of how this bug could be fixed, without changing the template.

May there could be some further adjustments. If so, feel free to let me know.

add to upload/catalog/controller/product/product.php

if ($product_info['quantity'] > 0) {
$this->data['button_cart'] = $this->language->get('button_cart');
} else {
$this->data['text_qty'] = $this->language->get('');
$this->data['minimum'] = $this->language->get('');
$this->data['button_cart'] = $this->language->get('1');
$this->data['text_or'] = $this->language->get('');
$this->data['button_wishlist'] = $this->language->get('');
$this->data['button_compare'] = $this->language->get('');

}

Newbie

Posts

Joined
Wed Aug 10, 2011 10:23 pm

Post by GoGo OpenCart » Thu Nov 24, 2011 8:16 am

I just released an extension for doing that. This extension will display "Call for Price" or any other text that you like, for products that have 0 (zero) price, but I can modify it to work with negative prices, if you want.

It works independent from different currencies, multiple currencies, left or right currencies, etc. With other words, all you need to do, is to install the extension, and put 0 price, or any negative price, as I mentioned before to make it to work like that, for the products you don't want to have prices.

It will also disable the "Add to Cart" button for 0 priced products, or any negative price, same as before, making it gray, so costumers can't add that product into the cart.

Look at the pictures to see how it looks like.

Extension's page: http://www.opencart.com/index.php?route ... on_id=4067

See all my extensions: https://www.opencart.com/index.php?rout ... 20OpenCart


User avatar
Active Member

Posts

Joined
Mon Nov 14, 2011 11:30 pm
Who is online

Users browsing this forum: No registered users and 53 guests