Community Forums

[Mod]Displaying something other than $0 if no price is given

Free manual modifications can be contributed here. Modifications are manual snippets of code that are pasted into the forums for others to use.

[Mod]Displaying something other than $0 if no price is given

Postby dashik » Sat Nov 14, 2009 12:52 am

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.
dashik
 
Posts: 32
Joined: Fri Jul 31, 2009 12:10 pm

Re: Displaying something other than $0 when no price is given

Postby fido-x » Sat Nov 14, 2009 1:34 am

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;
   }
}
Image
If you're not living on the edge ... you're taking up too much space!
Multi-Vendor Plugin for OpenCart 1.5.1.x
Have I helped you?
User avatar
fido-x
 
Posts: 1960
Joined: Fri Jun 27, 2008 5:09 pm
Location: Tasmania, Australia

Re: Displaying something other than $0 when no price is given

Postby dashik » Sat Nov 14, 2009 5:42 am

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;
                  
               }
dashik
 
Posts: 32
Joined: Fri Jul 31, 2009 12:10 pm

Re: Displaying something other than $0 when no price is given

Postby fido-x » Sat Nov 14, 2009 6:25 am

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:
Code: Select all
'price'  => $price,
Image
If you're not living on the edge ... you're taking up too much space!
Multi-Vendor Plugin for OpenCart 1.5.1.x
Have I helped you?
User avatar
fido-x
 
Posts: 1960
Joined: Fri Jun 27, 2008 5:09 pm
Location: Tasmania, Australia

Re: Displaying something other than $0 when no price is given

Postby dashik » Sat Nov 14, 2009 12:58 pm

Absolutely spot on! Thank you :)
dashik
 
Posts: 32
Joined: Fri Jul 31, 2009 12:10 pm

Re: Displaying something other than $0 when no price is given

Postby Donce » Sat Nov 14, 2009 4:53 pm

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!
Donce
 
Posts: 68
Joined: Fri Aug 28, 2009 12:22 pm

Re: Displaying something other than $0 when no price is give

Postby Qphoria » Sat Nov 14, 2009 10:46 pm

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:
Code: Select all
$string = '';


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
Image Image
Donate!|OpenCart Basics|GeoZones
Help me get more development cloud storage - Click Here to get DropBox
User avatar
Qphoria
Administrator
 
Posts: 18213
Joined: Mon Jul 21, 2008 7:02 pm
Donate to Qphoria

Re: Displaying something other than $0 when no price is given

Postby Donce » Sun Nov 15, 2009 12:11 am

Cha!
awesome, works! Thank you very much!
Donce
 
Posts: 68
Joined: Fri Aug 28, 2009 12:22 pm

Re: Displaying something other than $0 when no price is given

Postby dashik » Sun Nov 15, 2009 4:11 am

Good stuff!
dashik
 
Posts: 32
Joined: Fri Jul 31, 2009 12:10 pm

Re: [Mod]Displaying something other than $0 if no price is given

Postby nzjollyroger » Mon Feb 08, 2010 12:22 am

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 ?
nzjollyroger
 
Posts: 54
Joined: Sun Nov 15, 2009 9:26 pm

Re: [Mod]Displaying something other than $0 if no price is given

Postby Qphoria » Thu Feb 11, 2010 12:57 pm

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';
   }
}
Image Image
Donate!|OpenCart Basics|GeoZones
Help me get more development cloud storage - Click Here to get DropBox
User avatar
Qphoria
Administrator
 
Posts: 18213
Joined: Mon Jul 21, 2008 7:02 pm
Donate to Qphoria

Re: [Mod]Displaying something other than $0 if no price is given

Postby pepiw » Tue Mar 30, 2010 1:39 am

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
pepiw
 
Posts: 4
Joined: Thu Mar 25, 2010 11:17 am

Re: [Mod]Displaying something other than $0 if no price is given

Postby Marcel » Tue Mar 30, 2010 9:44 pm

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
OpenCart Newbie | Using v1.5.1.1
Marcel
 
Posts: 29
Joined: Mon Mar 08, 2010 7:04 pm
Location: Colorado

Re: [Mod]Displaying something other than $0 if no price is given

Postby Marcel » Wed Mar 31, 2010 6:39 pm

Anybody …I need to fix this problem with SOLD displaying in the Totals column instead of 0.00
OpenCart Newbie | Using v1.5.1.1
Marcel
 
Posts: 29
Joined: Mon Mar 08, 2010 7:04 pm
Location: Colorado

Re: [Mod]Displaying something other than $0 if no price is g

Postby cmebd » Sun Jul 18, 2010 6:12 pm

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
A stupid question is the one you -don't- ask.........(Anon)

)C1.5.0.1 (IN devel)
OC V1.4.9.5
OC V1.4.9.2
OC V1.4.7
OC V1.3.4
User avatar
cmebd
 
Posts: 405
Joined: Fri Nov 13, 2009 3:17 am
Location: Tasmania, Australia

Re: Displaying something other than $0 when no price is give

Postby dbe » Thu Sep 23, 2010 2:11 pm

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:
Code: Select all
$string = '';


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...

:-\
Dimitri Backaert
Web Development, OOP, .NET, IBM Cognos BI, SQL
dbe
 
Posts: 48
Joined: Tue Sep 21, 2010 5:01 pm
Location: Erembodegem - Belgium

Re: [Mod]Displaying something other than $0 if no price is g

Postby Qphoria » Thu Sep 23, 2010 3:25 pm

add an entry into the main language file for each language (english.php, spanish.php, etc)
Code: Select all
$_['text_free']             = 'Free';



Then change the currency.php file to use
Code: Select all
if ($format && (int)$value == 0) {
   return $this->language->get('text_free');
}
Image Image
Donate!|OpenCart Basics|GeoZones
Help me get more development cloud storage - Click Here to get DropBox
User avatar
Qphoria
Administrator
 
Posts: 18213
Joined: Mon Jul 21, 2008 7:02 pm
Donate to Qphoria

Re: [Mod]Displaying something other than $0 if no price is g

Postby dbe » Thu Sep 23, 2010 5:43 pm

Qphoria wrote:add an entry into the main language file for each language (english.php, spanish.php, etc)
Code: Select all
$_['text_free']             = 'Free';



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
Dimitri Backaert
Web Development, OOP, .NET, IBM Cognos BI, SQL
dbe
 
Posts: 48
Joined: Tue Sep 21, 2010 5:01 pm
Location: Erembodegem - Belgium

Re: [Mod]Displaying something other than $0 if no price is g

Postby Qphoria » Thu Sep 23, 2010 7:11 pm

You need to put that same in the admin/language/english/english.php file
Image Image
Donate!|OpenCart Basics|GeoZones
Help me get more development cloud storage - Click Here to get DropBox
User avatar
Qphoria
Administrator
 
Posts: 18213
Joined: Mon Jul 21, 2008 7:02 pm
Donate to Qphoria

Re: [Mod]Displaying something other than $0 if no price is g

Postby dbe » Fri Sep 24, 2010 3:44 pm

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.
Dimitri Backaert
Web Development, OOP, .NET, IBM Cognos BI, SQL
dbe
 
Posts: 48
Joined: Tue Sep 21, 2010 5:01 pm
Location: Erembodegem - Belgium

Next

Return to Modifications

Who is online

Users browsing this forum: mokazhar and 4 guests

Hosted by Arvixe Web Hosting