Advertisement:

Author Topic: SOLVED Price - currency are shown on item-edit when category has price disabled  (Read 2016 times)

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Hi. I saw that if I edit as a logged user an item that is in a category with price disabled, the   osc_price_enabled_at_items() function doesn't work (edit - this function refers to the whole site but the problem still remains) and only the price input tag is hidden via css.

« Last Edit: October 12, 2017, 04:42:23 pm by marius-ciclistu »

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: osc_price_enabled_at_items() doesn't work on item edit
« Reply #1 on: September 25, 2017, 11:18:27 pm »
What do you mean is not working ?

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: osc_price_enabled_at_items() doesn't work on item edit
« Reply #2 on: September 25, 2017, 11:21:42 pm »
I mean that if I edit an item from a category that has the price field dissabled, in the item-edit page , the "Price" and "Currency" texts are shown.

So that function doesn't work to make that if work properly.

EDIT: so osc_price_enabled_at_items() returns true in item-edit mode when it should return false.
In item-post it works fine.
« Last Edit: September 25, 2017, 11:48:51 pm by marius-ciclistu »

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: osc_price_enabled_at_items() doesn't work on item edit
« Reply #3 on: September 26, 2017, 12:47:55 am »
Nice catch, doing some investigation it seems both "currency" selector and price "label" also are untouched by the javascript when changing category to categeory with price disabled. Definately something to be improved in core.

Thanks,
Eric

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: osc_price_enabled_at_items() doesn't work on item edit
« Reply #4 on: September 26, 2017, 12:51:40 am »
When I tought I'm done modifying :)) everytime something comes up.

But, leaving aside the js, why isn't that function working in edit mode?

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: osc_price_enabled_at_items() doesn't work on item edit
« Reply #5 on: September 26, 2017, 01:34:43 am »
Because the price check is checking the admin 'price' enabled option and not the category price enabled.
The reason it seems to be working with categories aslo is because of the javascript that is responsible for category / price behanviour.

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: osc_price_enabled_at_items() doesn't work on item edit
« Reply #6 on: September 26, 2017, 12:56:32 pm »
Ok. Maybe it will be fixed by the osclass team then, and hopefully will get an github link with the  mods.


EDIT: I changed the title of the topic.
« Last Edit: September 26, 2017, 01:04:22 pm by marius-ciclistu »

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: Price - currency are shown on item-edit when category has price disabled
« Reply #7 on: September 26, 2017, 01:26:40 pm »
Actually, in my Osclass 3.7.4 with 1 category price disabled when logged in and publishing a new ad in this cat the price field is *not* displayed to me. After posting the new ad and going back in edit mode for me the price field is still not being displayed which means it is working as intended as far as price field goes.

What is not being hidden is the price currency selector and the price label, this should probably be fixed in JS (easy fix) since it makes sense not to display anything related to the price when it is disabled. IF you have disabled price for items in admin (not category) the function discussed here will hide both price label field and currency selector.

If your price field is displayed when editing an item in a category with price disabled there might be somethingelse going on related to your code/theme. The JS used to hide the price field is the same for publishing and editing.

Regards,
Eric

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Price - currency are shown on item-edit when category has price disabled
« Reply #8 on: September 26, 2017, 01:28:25 pm »
I have the same behavior as you have.

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Price - currency are shown on item-edit when category has price disabled
« Reply #9 on: October 12, 2017, 01:50:30 pm »
EDiT: I removed this because I was thinking in words before I came to the solution from the next answer.
« Last Edit: October 12, 2017, 02:38:10 pm by marius-ciclistu »

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Price - currency are shown on item-edit when category has price disabled
« Reply #10 on: October 12, 2017, 02:33:10 pm »
EDIT: Teseo's solution from the next reply is better than this one

THE SOLUTION IS:
(can be included in osclass core on the next update if I'm not wrong)

in /oc-includes/osclass/frm/Item.form.class.php

Replace

Code: [Select]
    $(document).ready(function(){
        var cat_id = $("#catId").val();
        <?php if(OC_ADMIN) { ?>
        var url = '<?php echo osc_admin_base_url(true); ?>';
        <?php } else { ?>
        var url = '<?php echo osc_base_url(true); ?>';
        <?php ?>
        var result = '';

        if(cat_id != '') {
if(catPriceEnabled[cat_id] == 1) {
$("#price").closest("div").show();
} else {
$("#price").closest("div").hide();
$('#price').val('') ;
}

with

Code: [Select]
    $(document).ready(function(){
        var cat_id = $("#catId").val();
        <?php if(OC_ADMIN) { ?>
        var url = '<?php echo osc_admin_base_url(true); ?>';
        <?php } else { ?>
        var url = '<?php echo osc_base_url(true); ?>';
        <?php ?>
        var result = '';

        if(cat_id != '') {
if(catPriceEnabled[cat_id] == 1) {
$("#price").closest("div").show();
} else {
$("#price").closest("div").hide();
$('#price').val('') ;
            // trigger hide-price event
                            $('#price').trigger('hide-price');
}
« Last Edit: October 12, 2017, 04:11:29 pm by marius-ciclistu »

teseo

  • Hero Member
  • *****
  • Posts: 6169
Hi,

This is a theme problem (Bender and Bender-based themes), your solution would solve Bender issues but it might throw an error on other themes... ???

Code: [Select]
$('#price').bind('hide-price', function(){
                $('.control-group-price').hide();
            });

            $('#price').bind('show-price', function(){
                $('.control-group-price').show();
            });

This is Bender specific code, it's what you are invoking with that "$('#price').trigger('hide-price');".

So better to solve this inside the theme, find in item-post.php:

Code: [Select]
        <script type="text/javascript">
            $('#price').bind('hide-price', function(){
                $('.control-group-price').hide();
            });

            $('#price').bind('show-price', function(){
                $('.control-group-price').show();
            });

    <?php if(osc_locale_thousands_sep()!='' || osc_locale_dec_point() != '') { ?>
    $().ready(function(){

and replace with:

Code: [Select]
        <script type="text/javascript">
            $('#price').bind('hide-price', function(){
                $('.control-group-price').hide();
            });

            $('#price').bind('show-price', function(){
                $('.control-group-price').show();
            });

            <?php if ($edit && !osc_item_category_price_enabled(osc_item_category_id())) { ?>
                $('#price').trigger('hide-price');
            <?php ?>

    <?php if(osc_locale_thousands_sep()!='' || osc_locale_dec_point() != '') { ?>
    $().ready(function(){

Regards

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Thank you very much:)
So I gues it must be put in the next update of Bender theme then.

teseo

  • Hero Member
  • *****
  • Posts: 6169
Nice work :)

Yes, if you want to make a formal request:

https://github.com/osclass/theme-bender/issues

Regards

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
I did. Thank you.