Page 1 of 4
[Mod]Displaying something other than $0 if no price is given
Posted: Sat Nov 14, 2009 8:52 am
by dashik
Anyone have an easy solution to this? Ideally, I'd love the system to say "Coming soon" if a product is listed at a price of $0.00
Thanks in advance.
Re: Displaying something other than $0 when no price is given
Posted: Sat Nov 14, 2009 9:34 am
by fido-x
There is a solution, I don't know whether you'd call it "easy".
In your top level language file (ie. "catalog/language/english/english.php"), insert the following:-
Code: Select all
$_['text_no_price'] = 'Coming Soon';
Then in the following files:-
- catalog/controller/product/category.php
catalog/controller/product/manufacturer.php
catalog/controller/product/search.php
catalog/controller/product/special.php
catalog/controller/product/product.php
insert:
Code: Select all
$this->data['text_no_price'] = $this->language->get('text_no_price');
Then, (in the same files) find:
Code: Select all
if ($discount) {
$price = $this->currency->format($this->tax->calculate($discount, $result['tax_class_id'], $this->config->get('config_tax')));
} else {
$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
$special = $this->model_catalog_product->getProductSpecial($result['product_id']);
if ($special) {
$special = $this->currency->format($this->tax->calculate($special, $result['tax_class_id'], $this->config->get('config_tax')));
}
}
and replace with:
Code: Select all
if ($discount) {
$price = $this->currency->format($this->tax->calculate($discount, $result['tax_class_id'], $this->config->get('config_tax')));
} else {
if ($result['price'] == 0) {
$price = $this->language->get('text_no_price');
} else {
$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
$special = $this->model_catalog_product->getProductSpecial($result['product_id']);
if ($special) {
$special = $this->currency->format($this->tax->calculate($special, $result['tax_class_id'], $this->config->get('config_tax')));
}
}
Also, in "catalog/controller/product/product.php" find:
Code: Select all
if ($discount) {
$this->data['price'] = $this->currency->format($this->tax->calculate($discount, $product_info['tax_class_id'], $this->config->get('config_tax')));
$this->data['special'] = FALSE;
} else {
$this->data['price'] = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')));
$special = $this->model_catalog_product->getProductSpecial($this->request->get['product_id']);
if ($special) {
$this->data['special'] = $this->currency->format($this->tax->calculate($special, $product_info['tax_class_id'], $this->config->get('config_tax')));
} else {
$this->data['special'] = FALSE;
}
}
and replace with:
Code: Select all
if ($discount) {
$this->data['price'] = $this->currency->format($this->tax->calculate($discount, $product_info['tax_class_id'], $this->config->get('config_tax')));
$this->data['special'] = FALSE;
} else {
if ($product_info['price'] == 0) {
$this->data['price'] = $this->language->get('text_no_price');
} else {
$this->data['price'] = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')));
}
$this->data['price'] = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')));
$special = $this->model_catalog_product->getProductSpecial($this->request->get['product_id']);
if ($special) {
$this->data['special'] = $this->currency->format($this->tax->calculate($special, $product_info['tax_class_id'], $this->config->get('config_tax')));
} else {
$this->data['special'] = FALSE;
}
}
Re: Displaying something other than $0 when no price is given
Posted: Sat Nov 14, 2009 1:42 pm
by dashik
Thanks for the info! My code isn't the same (i'm running 1.3.0) but i was able to get this to work on the product pages.
However, I haven't been able to get it to work on the category pages.
Here's what my code looks like in category.php
Code: Select all
$special = $this->model_catalog_product->getProductSpecial($result['product_id']);
if ($special) {
$special = $this->currency->format($this->tax->calculate($special, $result['tax_class_id'], $this->config->get('config_tax')));
} else {
$special = FALSE;
}
Re: Displaying something other than $0 when no price is given
Posted: Sat Nov 14, 2009 2:25 pm
by fido-x
Ah, 1.3.0. That's slightly different. OK, here goes.
In the controller files previously mentioned, you will find a block of code that reads:
Code: Select all
$this->data['products'][] = array(
'name' => $result['name'],
'model' => $result['model'],
'rating' => $rating,
'stars' => sprintf($this->language->get('text_stars'), $rating),
'thumb' => HelperImage::resize($image, $this->config->get('config_image_related_width'), $this->config->get('config_image_related_height')),
'price' => $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax'))),
'special' => $special,
'href' => $this->model_tool_seo_url->rewrite($this->url->http('product/product&product_id=' . $result['product_id']))
);
Before this, insert:
Code: Select all
if ($result['price'] == 0) {
$price = $this->language->get('text_no_price');
} else {
$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
}
Then in the products array, where it says:
Code: Select all
'price' => $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax'))),
Replace with:
Re: Displaying something other than $0 when no price is given
Posted: Sat Nov 14, 2009 8:58 pm
by dashik
Absolutely spot on! Thank you

Re: Displaying something other than $0 when no price is given
Posted: Sun Nov 15, 2009 12:53 am
by Donce
hi,
i changed only in products.php, and i get error like this..
Parse error: syntax error, unexpected T_ELSE in /catalog/controller/product/product.php on line 306
please, help!
Re: Displaying something other than $0 when no price is give
Posted: Sun Nov 15, 2009 6:46 am
by Qphoria
A little trick to make this a lot easier for you..
Remember all prices pass through the currency->format() function, even if they are 0
1. EDIT: system/library/currency.php (or system/helper/currency.php for certain versions)
2. FIND:
3. BEFORE, ADD:
Code: Select all
if ($format && (float)$value == 0) {
return 'FREE';
}
That's it! One file handles ALL places.. even custom mods are automatically changed
Re: Displaying something other than $0 when no price is given
Posted: Sun Nov 15, 2009 8:11 am
by Donce
Cha!
awesome, works! Thank you very much!
Re: Displaying something other than $0 when no price is given
Posted: Sun Nov 15, 2009 12:11 pm
by dashik
Good stuff!
Re: [Mod]Displaying something other than $0 if no price is given
Posted: Mon Feb 08, 2010 8:22 am
by nzjollyroger
this is perfect for my products that i don't have a price applied to
if ($format && (int)$value == 0) {
return 'coming soon';
}
it shows up perfect.
however when you have pickup for shipping its show ups as:
Pickup Up: and in the price instead of 0.00 is shown as 'coming soon'
which is a problem i completely understand why... but
is there some way to make it apply to everything but the free shipping ?
Re: [Mod]Displaying something other than $0 if no price is given
Posted: Thu Feb 11, 2010 8:57 pm
by Qphoria
nzjollyroger wrote:
however when you have pickup for shipping its show ups as:
is there some way to make it apply to everything but the free shipping ?
Try this:
Code: Select all
if ($format && (int)$value == 0) {
$trace = debug_backtrace();
if (isset($trace[1]) && $trace[1]['class'] == 'ModelShippingFree') {
return "0.00";
} else {
return 'coming soon';
}
}
Re: [Mod]Displaying something other than $0 if no price is given
Posted: Tue Mar 30, 2010 9:39 am
by pepiw
Qphoria wrote:nzjollyroger wrote:
however when you have pickup for shipping its show ups as:
is there some way to make it apply to everything but the free shipping ?
Try this:
Code: Select all
if ($format && (int)$value == 0) {
$trace = debug_backtrace();
if (isset($trace[1]) && $trace[1]['class'] == 'ModelShippingFree') {
return "0.00";
} else {
return 'coming soon';
}
}
Qphoria wrote:Burrito is correct. The way options were designed in OpenCart was to make the product price the default option price. Leaving the default option at 0.00
Example
Ok, I understand this.
But,... I have only one price for the product with 4 diferent optional samples (their price = 0€)
When add a product in this way:
product_A - 12.10 €
options: sample_1 - 0 €, sample _2 - 0 €, sample_3 - 0 €, sample_4 - 0 €
.... The price is clearly visible, but when the product is added to the basket, there is no price, only is displayed 0.00 €, do not fall in the amount of purchase!
and when add a product in second way:
product_A - 0.00 €
options: sample_1 - 12.10 €, sample _2 - 12.10 €, sample_3 - 12.10 €, sample_4 - 12.10 €
Now price is visible in the cart and counted to sub-total but on the product list and view the price of product_A is 0.00 €! I think this is a little frivolous to our customers.
I tried this code:
if ($format && (int)$value == 0) {
$trace = debug_backtrace();
if (isset($trace[1]) && $trace[1]['class'] == 'ModelShippingFree') {
return "0.00";
} else {
return 'Price depends on choice options';
}
}
I think it's not really suitable solution because it is essentially only one price for this product. I have also a few items without options, but their price is less than 1, for example price is € 0.45 and in these item is still visible sign "Price depends on choice options" instead of price!
Otherwise I really like OpenCart. Is friendly, transparent, modern, and so I decided that I worked with him (until now I have used Zencart).
I hope you will help me in eliminating errors and defects that sometimes occur.
Thanks in advance
PS: I Using OC v1.4.4
Re: [Mod]Displaying something other than $0 if no price is given
Posted: Wed Mar 31, 2010 5:44 am
by Marcel
Thanks this works nicely
My sold products are now in a Category called Sold and they show SOLD instead of a price.
My Free Shipping shows as 0.00 in Delivery Information
But here's the problem, in the final step of the checkout under Totals
the Free Shipping item shows as SOLD
Re: [Mod]Displaying something other than $0 if no price is given
Posted: Thu Apr 01, 2010 2:39 am
by Marcel
Anybody …I need to fix this problem with SOLD displaying in the Totals column instead of 0.00
Re: [Mod]Displaying something other than $0 if no price is g
Posted: Mon Jul 19, 2010 2:12 am
by cmebd
When using anything in a product but 0.00 you cannot access free checkout, which defeats the object for me. Any ideas anyone?
I want one specific product to provide a POA type message and the customer be able to complete the order.
Cheers
Re: Displaying something other than $0 when no price is give
Posted: Thu Sep 23, 2010 10:11 pm
by dbe
Qphoria wrote:A little trick to make this a lot easier for you..
Remember all prices pass through the currency->format() function, even if they are 0
1. EDIT: system/library/currency.php (or system/helper/currency.php for certain versions)
2. FIND:
3. BEFORE, ADD:
Code: Select all
if ($format && (int)$value == 0) {
return 'FREE';
}
That's it! One file handles ALL places.. even custom mods are automatically changed
Hi Qphoria,
Concerning the above post I quoted:
is there any way you can display the hardcoded text (in this case 'FREE') in multiple languages?
I'm stuck at that part...

Re: [Mod]Displaying something other than $0 if no price is g
Posted: Thu Sep 23, 2010 11:25 pm
by Qphoria
add an entry into the main language file for each language (english.php, spanish.php, etc)
Then change the currency.php file to use
Code: Select all
if ($format && (int)$value == 0) {
return $this->language->get('text_free');
}
Re: [Mod]Displaying something other than $0 if no price is g
Posted: Fri Sep 24, 2010 1:43 am
by dbe
Qphoria wrote:add an entry into the main language file for each language (english.php, spanish.php, etc)
Then change the currency.php file to use
Code: Select all
if ($format && (int)$value == 0) {
return $this->language->get('text_free');
}
Hi Qphoria,
Thanks for the solution.
In the Front End, it works.
In the Admin part however, i get the message 'text_no_price' (which is the name of my language file entry).
Any solution for that?
Greets
Re: [Mod]Displaying something other than $0 if no price is g
Posted: Fri Sep 24, 2010 3:11 am
by Qphoria
You need to put that same in the admin/language/english/english.php file
Re: [Mod]Displaying something other than $0 if no price is g
Posted: Fri Sep 24, 2010 11:44 pm
by dbe
I See...
The Admin section has a separate language file.
Thanks for pointing that out.
I seem to have some other problems now.
All products having the standard text value 'FREE' are messing up the actual shopping cart.
When adding these products to the cart, the subtotal and total values don't seem to be working
correctly.
Ideally, a customer should not be able to add these products to the shopping cart.
In fact, this section should be some sort of image gallery, displaying the product examples, and
having a standard text or a link to an e-mail address, to ask for more information.