Advertisement:

Author Topic: [SOLVED] How to solve the "zero" free price  (Read 3961 times)

Aficionado

  • Guest
[SOLVED] How to solve the "zero" free price
« on: September 15, 2017, 06:35:32 pm »
Hi,

One of the major problems i have is that most posters of ads, give zero as price and then Free is displayed. Apparently they don't mean Free, they just don't want to give a price.

Any ideas how to solve or improve this ?

Thanks
« Last Edit: September 18, 2017, 08:32:59 pm by Aficionado »

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: How to solve the "zero" free price
« Reply #1 on: September 15, 2017, 06:59:36 pm »
You could recplace the "free" word in language files with "ask for price".

Aficionado

  • Guest
Re: How to solve the "zero" free price
« Reply #2 on: September 15, 2017, 07:14:16 pm »
You could recplace the "free" word in language files with "ask for price".

Tried that, BUT the price field is also shows at Items and the label was totally wrong to display.

Maybe i could inject a message in there, apart from the language file. Next to the Price field or above.

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: How to solve the "zero" free price
« Reply #3 on: September 15, 2017, 09:18:38 pm »
Or you could prevent the input of 0 in the price's field to begin with.

Aficionado

  • Guest
Re: How to solve the "zero" free price
« Reply #4 on: September 15, 2017, 09:21:42 pm »
Or you could prevent the input of 0 in the price's field to begin with.

Sure, if i knew how....

or even better if zero, then a "Are you sure it is Free"  dialogue. Still all those required extra coding, and i don't want to do that.
« Last Edit: September 15, 2017, 09:28:07 pm by Aficionado »

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: How to solve the "zero" free price
« Reply #5 on: September 15, 2017, 09:28:41 pm »
If I would knew I would have wrote the solution in the previous post :D

But let's see:
oc-includes/osclass/helpers/hItems.php:   

Code: [Select]
/**
     * Formats the price using the appropiate currency.
     *
     * @param float $price
     * @return string
     */
    function osc_format_price($price, $symbol = null) {
        if ($price === null) return osc_apply_filter ('item_price_null', __('Check with seller') );
        if ($price == 0) return osc_apply_filter ('item_price_zero', __('Free') );

        if($symbol==null) { $symbol = osc_item_currency_symbol(); }

        $price = $price/1000000;

        $currencyFormat = osc_locale_currency_format();
        $currencyFormat = str_replace('{NUMBER}', number_format($price, osc_locale_num_dec(), osc_locale_dec_point(), osc_locale_thousands_sep()), $currencyFormat);
        $currencyFormat = str_replace('{CURRENCY}', $symbol, $currencyFormat);
        return osc_apply_filter('item_price', $currencyFormat );
    }

replace with

Code: [Select]
/**
     * Formats the price using the appropiate currency.
     *
     * @param float $price
     * @return string
     */
    function osc_format_price($price, $symbol = null) {
        if ($price === null || $price == 0) return osc_apply_filter ('item_price_null', __('Check with seller') );
       /* if ($price == 0) return osc_apply_filter ('item_price_zero', __('Free') );*/

        if($symbol==null) { $symbol = osc_item_currency_symbol(); }

        $price = $price/1000000;

        $currencyFormat = osc_locale_currency_format();
        $currencyFormat = str_replace('{NUMBER}', number_format($price, osc_locale_num_dec(), osc_locale_dec_point(), osc_locale_thousands_sep()), $currencyFormat);
        $currencyFormat = str_replace('{CURRENCY}', $symbol, $currencyFormat);
        return osc_apply_filter('item_price', $currencyFormat );
    }

I'll make this to my website as well. Thank you.
« Last Edit: September 15, 2017, 09:31:03 pm by marius-ciclistu »

Aficionado

  • Guest
Re: How to solve the "zero" free price
« Reply #6 on: September 15, 2017, 09:39:08 pm »
This is the change ?

Code: [Select]
/* if ($price == 0) return osc_apply_filter ('item_price_zero', __('Free') );*/

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: How to solve the "zero" free price
« Reply #7 on: September 15, 2017, 09:39:38 pm »
        if ($price === null || $price == 0) return osc_apply_filter ('item_price_null', __('Check with seller') );
       /* if ($price == 0) return osc_apply_filter ('item_price_zero', __('Free') );*/

Aficionado

  • Guest
Re: How to solve the "zero" free price
« Reply #8 on: September 15, 2017, 09:41:43 pm »
        if ($price === null || $price == 0) return osc_apply_filter ('item_price_null', __('Check with seller') );
       /* if ($price == 0) return osc_apply_filter ('item_price_zero', __('Free') );*/

right. got it. thanks i will change it during the weekend.

 8)

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: How to solve the "zero" free price
« Reply #9 on: September 15, 2017, 09:44:20 pm »
This forum is great:)) I'm learning alot from it even if sometimes I teach my self with the help of others that are just asking:)) (But also I learned alot from others that posted solutions)

So a big THANK YOU to all !

Aficionado

  • Guest
Re: How to solve the "zero" free price
« Reply #10 on: September 15, 2017, 09:47:53 pm »
This forum is great:)) I'm learning alot from it even if sometimes I teach my self with the help of others that are just asking:)) (But also I learned alot from others that posted solutions)

So a big THANK YOU to all !

Nice also to see people like you, that offer help the community of Osclass. 

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: How to solve the "zero" free price
« Reply #11 on: September 15, 2017, 09:55:00 pm »
I received help so I give help when and if I can.... I liked the idea of the man behind linux in comparison with Bill G.

calinbehtuk

  • Sr. Member
  • ****
  • Posts: 450
Re: How to solve the "zero" free price
« Reply #12 on: September 15, 2017, 10:38:19 pm »
If i understand right, you want to change the free text or make some changes on that level free?
You don't have to change the core files, you have some filters in formatted price that you can use.
For example for changing the free tag with the price and symbol:
this in your theme functions.php file
Code: [Select]
function new_filter_for_free_price(){
    return osc_item_price().' '. osc_item_currency_symbol();
}

osc_add_filter ('item_price_zero', 'new_filter_for_free_price');

Of course that you can play more with this
Code: [Select]
function new_filter_for_free_price(){
    return __('your text');
}

In this way you don't have to make this changes every time you update osclass.

You have more filters there that you can use in the same way.

osc_add_filter ('item_price_null', 'your function' ); - for check with seller

osc_add_filter('item_price', 'your function' ); - for final price


marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: How to solve the "zero" free price
« Reply #13 on: September 15, 2017, 10:58:15 pm »
Calin,
This is nice in case the user didn't change osclass files.

But as I saw, there are many that made changes ( like me) , so they can choose the best solution for them from these 2.

PS. While updating, the theme is not updated as well?


calinbehtuk

  • Sr. Member
  • ****
  • Posts: 450
Re: How to solve the "zero" free price
« Reply #14 on: September 15, 2017, 11:03:17 pm »
@marius-ciclistu I think the best way to make the changes it avoid to change osclass core or theme files. You can create a plugin in just a few steps and include all your changes in the plugin, so in this way your core files and theme files will not be changed and you will not have to do this changes on each update.