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
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
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('');
}
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('');
}
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
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
Who is online
Users browsing this forum: Bing [Bot] and 361 guests