Post by picobo » Wed Mar 07, 2012 8:33 am

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 && (float)$value == 0) {
	return 'FREE';
}

That's it! One file handles ALL places.. even custom mods are automatically changed
Hello Qphoria, this seems to work but I only have one problem... when displayed in the front end, before the word 'FREE' I have the Currency Symbol in the left which actually overrites the first letters. In my case it displays "RD$E", but if I make the return "___FREE" then it displays "RD$FREE". How can I make it display the word "FREE" without the Currency Symbol?

Also could I disable the "Add To Cart" in this cases?

I have OpenCart Version 1.5.1.3 with the Shoppica theme.

Thank you and amazing work on OpenCart!

Newbie

Posts

Joined
Sat Feb 11, 2012 6:59 am

Post by MrTech » Mon Mar 12, 2012 12:45 am

Code: Select all

if ($format && (float)$value == 0) {
			return 'FREE';
		  }
Just a quick question about getting this to work on 1.5.2.1 - It works as advertised but there must have been some code changes in the new version because it also spits out a divide by zero error when visiting a category page that has a free product on it.

To test it out I placed the product in the 'featured' category and I get the divide by zero error at the top of the page when visiting that category. I checked the logs and the divide by zero error gets logged there as well. It's important to note that if I visit the product page itself, no such error appears.

Any ideas what needs to change to make this work error free?

~
Install Extensions OR OpenCart Fast Service! PayPal Accepted
I will professionally install and configure any free or purchased theme, module or extension.

Visit http://www.mrtech.ca if you need an OpenCart webmaster
~


User avatar
Active Member

Posts

Joined
Mon Jan 09, 2012 2:39 pm
Location - Canada, Eh!

Post by MrTech » Mon Mar 12, 2012 11:54 am

Update in case it happens to someone else: I installed the mod on fresh/local install of oc and the problem goes away. Which means now the hunt is on to find out which other mod is causing this issue since it's a problem on my end.

~
Install Extensions OR OpenCart Fast Service! PayPal Accepted
I will professionally install and configure any free or purchased theme, module or extension.

Visit http://www.mrtech.ca if you need an OpenCart webmaster
~


User avatar
Active Member

Posts

Joined
Mon Jan 09, 2012 2:39 pm
Location - Canada, Eh!

Post by rukhairy » Fri Mar 30, 2012 3:49 am

In my case running on 1.5.2.1 (Shoppica 1.0.12)

Code: Select all

if ($format && (float)$value == 0) {
   return 'FREE';
}
I'm using the Malaysia Ringgit currency and it shows RMEE, instead of FREE. It seems that the FR has been overlap with the left side currency code.

Newbie

Posts

Joined
Tue Jun 07, 2011 1:21 am

Post by rukhairy » Tue May 15, 2012 2:09 pm

BUMP!

Newbie

Posts

Joined
Tue Jun 07, 2011 1:21 am

Post by MrTech » Tue May 15, 2012 2:14 pm

Post a link so we can see the problem, will be easier to help.

~
Install Extensions OR OpenCart Fast Service! PayPal Accepted
I will professionally install and configure any free or purchased theme, module or extension.

Visit http://www.mrtech.ca if you need an OpenCart webmaster
~


User avatar
Active Member

Posts

Joined
Mon Jan 09, 2012 2:39 pm
Location - Canada, Eh!

Post by arrjaytea » Mon Jun 04, 2012 11:02 am

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 && (float)$value == 0) {
	return 'FREE';
}
That's it! One file handles ALL places.. even custom mods are automatically changed
Out of curiosity, could I use a similar bit of code to display a specific option price rather than text?

Our store is still in the testing phases (just moved from localhost to a live domain to prep for office stresstesting), but you can access an example page at:

http://packerfantours.biz/pft-store/ind ... duct_id=50


If you scroll down to option #6 (adults per room), what I'd like to have happen is have the value for "Single" (the bottom option in the drop down menu) display as the base price if a product does not have a price set.

Seems like something I may be able to do with this alteration (I'm already using this one to stop displaying product prices all together if it's value is $0, but I'd like to be able to display that single option as my starting point).

Any help is well appreciated. OC 1.5.3.1, Sellegance theme, only modified files are those used in this mod and a slight alteration in the themes CSS file.

New member

Posts

Joined
Thu May 31, 2012 11:58 pm

Post by jonidfld » Mon Feb 04, 2013 11:44 pm

Any update on how to remove the currency symbol before the text?? =)

Newbie

Posts

Joined
Wed Apr 11, 2012 8:44 pm

Post by labeshops » Sat Apr 06, 2013 12:44 am

Is there a way I could add text next to the price instead of replacing the price if the price is over a certain amount??? Like "Shipped FREE!" or a small graphic? Tried a few things and it broke the store. Using 1.5.2

Running Opencart v2.2 with multi-stores from http://www.labeshops.com which has links to all my stores.

Image


User avatar
Expert Member

Posts

Joined
Thu Aug 04, 2011 4:41 am
Location - Florida, USA

Post by storm-cloud » Tue Aug 06, 2013 8:33 pm

Looking over this thread I am surprised that there has been no mention of free displaying as the shipping cart total in the header of the page when no items have been added. For example, "0 item(s) - FREE". I only tried Q's method so I am not sure if the other solution provided at the beginning of this thread yields a different result.

Actually for myself, I am only interested in using this for the weight based shipping module as we don't have any $0.00 products. Basically, I would like to highlight the fact that shipping is free. What would be the best code to use to change any $0.00 amount in this module to display FREE?

Active Member

Posts

Joined
Wed Feb 22, 2012 8:07 am

Post by Qphoria » Wed Aug 14, 2013 4:40 am

storm-cloud wrote:Looking over this thread I am surprised that there has been no mention of free displaying as the shipping cart total in the header of the page when no items have been added. For example, "0 item(s) - FREE". I only tried Q's method so I am not sure if the other solution provided at the beginning of this thread yields a different result.

Actually for myself, I am only interested in using this for the weight based shipping module as we don't have any $0.00 products. Basically, I would like to highlight the fact that shipping is free. What would be the best code to use to change any $0.00 amount in this module to display FREE?

Using my simplified method, there is a way to filter which pages see it using the php debug_backtrace() function.
I use this exact same method in my request quote mod to show different text on different pages.

I am not at my home pc so I don't have the examples I used but I'll post an example here. Then you can have "free" for some pages and "0.00" for others. When I first created this, it was 1.4.x which didn't have the mini-cart so it wasn't an issue.

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Qphoria » Wed Aug 14, 2013 11:39 pm

ok so to use debug_backtrace to filter which pages show which price format.. here's an example

So starting with my original change:
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';
}

Change step 3 to:

Code: Select all

if ($format && (float)$value == 0) {
    $trace = debug_backtrace();
    if (isset($trace[1]['class']) && $trace[1]['class'] != 'ControllerModuleCart') {
       return 'FREE';
    }
}
This will show "0.00" in the mini-cart
but "Free" for all other. You can adjust it to be separate for each controller level class

So I'm basically saying if the class is NOT set to the module cart, then show FREE, otherwise show the normal number.
Sometimes it is $trace[2] instead of $trace[1] ... basically the index is the callstack order. So you may need to show the entire $trace array and decide where the controller is in respect to the trace.

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by alsami » Thu Aug 15, 2013 3:37 am

Qphoria wrote:ok so to use debug_backtrace to filter which pages show which price format.. here's an example

So starting with my original change:
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';
}

Change step 3 to:

Code: Select all

if ($format && (float)$value == 0) {
    $trace = debug_backtrace();
    if (isset($trace[1]['class']) && $trace[1]['class'] != 'ControllerModuleCart') {
       return 'FREE';
    }
}
This will show "0.00" in the mini-cart
but "Free" for all other. You can adjust it to be separate for each controller level class

So I'm basically saying if the class is NOT set to the module cart, then show FREE, otherwise show the normal number.
Sometimes it is $trace[2] instead of $trace[1] ... basically the index is the callstack order. So you may need to show the entire $trace array and decide where the controller is in respect to the trace.
thank you Qphoria

but i want to display FREE in all pages of pruduct ( homepage, product )

in other pages display 0

New member

Posts

Joined
Sat Jun 22, 2013 12:43 pm

Post by Qphoria » Thu Aug 15, 2013 9:11 pm

alsami wrote: thank you Qphoria

but i want to display FREE in all pages of pruduct ( homepage, product )

in other pages display 0
Yes that will do it. I gave the example. If you want specific pages then you need to adapt the example
What other page do you want 0.00 on? The majority of pages have products, the rest of them don't display any 0.00 totals anyway except the mini cart.

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by alsami » Fri Aug 16, 2013 8:11 pm

Qphoria wrote:
alsami wrote: thank you Qphoria

but i want to display FREE in all pages of pruduct ( homepage, product )

in other pages display 0
Yes that will do it. I gave the example. If you want specific pages then you need to adapt the example
What other page do you want 0.00 on? The majority of pages have products, the rest of them don't display any 0.00 totals anyway except the mini cart.
it's working now

thank you

New member

Posts

Joined
Sat Jun 22, 2013 12:43 pm

Post by storm-cloud » Tue Sep 10, 2013 8:22 am

Qphoria wrote:This will show "0.00" in the mini-cart
but "Free" for all other. You can adjust it to be separate for each controller level class

So I'm basically saying if the class is NOT set to the module cart, then show FREE, otherwise show the normal number.
Sometimes it is $trace[2] instead of $trace[1] ... basically the index is the callstack order. So you may need to show the entire $trace array and decide where the controller is in respect to the trace.
Fantastic, I will apply this modification again with the changes you have recommended. :)

Active Member

Posts

Joined
Wed Feb 22, 2012 8:07 am

Post by rukhairy » Fri Jan 31, 2014 1:48 pm

It's been a while since I last bugged with this problem, and now after I saw a few reply and believe that this thread still has much to offer, I decided to raise back my unsolved problems. Here goes:

Even after trying Q's method in updated 'Step 3' I still encounter the same problem which the left symbol of the currency will override the FREE letter in this case I'm using Malaysian Ringgit as my default currency which will show 'RM' on the left side. The 'RM' will override the first 2 letter of the echoed text in this case is the word 'FREE' and it keeps on showing 'RMEE' for those of products which price has been set to 0.00.

An example can be found on my site from the link below:
http://comicsdirectory.com.my/dark-soul ... -the-light

Newbie

Posts

Joined
Tue Jun 07, 2011 1:21 am

Post by Thirumurugan » Mon May 26, 2014 10:06 pm

Thanaks :) Qphoria...
Its working...

Newbie

Posts

Joined
Mon May 26, 2014 10:00 pm

Post by blue_razorz » Fri Aug 29, 2014 4:20 pm

Is there any way that i can get the code for 1.5.6.1?
thank you very much....

Newbie

Posts

Joined
Sat Jul 14, 2012 3:14 pm

Post by Qphoria » Tue Sep 02, 2014 2:12 am

blue_razorz wrote:Is there any way that i can get the code for 1.5.6.1?
thank you very much....
It's the same code since 1.3.x

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am
Who is online

Users browsing this forum: No registered users and 5 guests