Page 1 of 2 12 LastLast
Results 1 to 10 of 14
  1. #1
    Join Date
    Nov 2007
    Location
    Massachusetts
    Posts
    2
    Plugin Contributions
    0

    bug Getting the default attribute radio button checked

    I set up attributes for a product and wanted to have the radio button associated with
    the default choice be checked when the page opens.

    I set the "Default Attribute to be Marked Selected:" as yes for my default attribute
    but none of the buttons were checked when the page opened. If I press the "preview attributes" button the proper button is checked.

    Chaning the call of zen_draw_radio_field in the file html_output.php seems to have corrected
    this problem (and hopefully not created new problems ;) Changing the $checked parameter
    from false to true gives me a checked="checked" parameter in the <input> field for the
    radiobutton associated with the default choice.

    Is this a known bug? Since I am not familiar with the code I am wondering if I broke
    something else.

    (* jcl *)

    ---
    www.luciani.org

  2. #2
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: Getting the default attribute radio button checked

    It's certainly not a known bug. I've never heard of the default selector not functioning before.

    I would be wary of changing a parameter in a common function unless you know exactly what all the repercussions will be.

  3. #3
    Join Date
    Feb 2008
    Posts
    1
    Plugin Contributions
    0

    Default Re: Getting the default attribute radio button checked

    Hey John,

    It's been a little while since you posted this problem so you may have already found another solution to your problem. Here goes my stab at it anyways...

    I also ran into the same problem that you reported and have hunted down what I think is the fix

    In <your zen cart path>/includes/modules/attributes.php, you will find the following block of code (in around line 200):

    if ($_SESSION['cart']->contents[$prod_id]['attributes'][$products_options_names->fields['products_options_id']] == $products_options->fields['products_options_values_id']) {
    $selected_attribute = $_SESSION['cart']->contents[$prod_id]['attributes'][$products_options_names->fields['products_options_id']];
    } else {
    //$selected_attribute = false;
    // JEFF - fix for default attribute:
    $selected_attribute = ($products_options->fields['attributes_default']=='1' ? true : ($products_options->RecordCount() == 1 ? true : false));
    }


    It looks like it has something to do with choosing the same attribute as previously selected if something is in the cart already. When I was playing, I added an item without any attributes to the cart. With attributes tied to price and with no attributes chosen, it added an item with 0 cost. Anyhoo, since my item wasn't found with an attribute in the cart, it did not allow a default radio button to be selected.

    To fix this, I added the line that will set the default correctly if there is one, or if there is only one radio button option, it will make that the default. (the line following my comment: // JEFF - fix for default attribute:

    In your fix when you set the default to be 'true', it changed all items to be selected or to be 'default'. This appears to work by selecting the first item in your list to be the default, however, if you have an alternate default item, it won't ever get set when viewing the page.

    I've only started with ZenCart so if anyone else has more insight than me, feel free to add it here!

    Regards,
    Jeff

  4. #4
    Join Date
    Nov 2007
    Location
    Massachusetts
    Posts
    2
    Plugin Contributions
    0

    Default Re: Getting the default attribute radio button checked

    Thanks for the reply.

    It has been a while since I've looked at the code. I will take a look at your fix when I get
    back to playing with Zencart.

    (* jcl *)
    ---
    www.luciani.org

  5. #5
    Join Date
    Nov 2008
    Posts
    2
    Plugin Contributions
    0

    Default Re: Getting the default attribute radio button checked

    Great Job!! This seems to be a bug.. I used your code Jeff and it works like a charm!!

    Thanks again!!

  6. #6
    Join Date
    Dec 2008
    Posts
    11
    Plugin Contributions
    0

    bug Re: Getting the default attribute radio button checked

    I can attest to this issue. Here is how to reproduce it:

    1) Go to Admin, and add a new item, NO ATTRIBUTES
    2) Go to your front end and add this item to your shopping cart.
    3) Go back to Admin, and add a couple of radio button attributes, and set one to default.
    4) Go back to front end to the products info page, and you will see that there is no default radio button selected.

    In <your zen cart path>/includes/modules/attributes.php, you will find the following block of code (in around line 200):

    if ($_SESSION['cart']->contents[$prod_id]['attributes'][$products_options_names->fields['products_options_id']] == $products_options->fields['products_options_values_id']) {
    $selected_attribute = $_SESSION['cart']->contents[$prod_id]['attributes'][$products_options_names->fields['products_options_id']];
    } else {
    //$selected_attribute = false;
    // JEFF - fix for default attribute:
    $selected_attribute = ($products_options->fields['attributes_default']=='1' ? true : ($products_options->RecordCount() == 1 ? true : false));
    }
    So Yes, I think the problem has something to do with that code, trying to reselect the last picked option and overriding the default radio button.

    I have not checked if it does the something on other attribute types.

    Not a big bug per say, as long as you don't change attributes in the middle of your customers placing orders.

    I noticed it when working on an Ajax attribute gallery, and my script kept complaining there was no default radio button for an attribute gallery, when testing on some new items.

  7. #7
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: Getting the default attribute radio button checked

    Rule of thumb: If you have not finished everything on a new Product ... set it to products_status = 0 or In Stock NO ... so that this does not happen ...

    Thanks for the suggestions ...
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  8. #8
    Join Date
    Feb 2008
    Posts
    129
    Plugin Contributions
    0

    Default Re: Getting the default attribute radio button checked

    Hi,

    I'm having the same problem, but it has nothing to do with the cart.

    I have a teststore that nobody is using but me. I've added 3 attributes--two dropdowns and 1 radio buttons.

    The two dropdown defaults are working fine.

    The radio buttons have no default.

    I have nothing in the cart. I tried Jeff's fix from the previous post and it did not fix it.

    I'm on 1.3.8a. I'm using the add on improved_attributes_controller_1-1b2
    but that's not the problem because I just changed back to the original attributes controller and same problem.

    When I change that attribute to dropdown or checkboxes, it works fine. But for some reason radio buttons does not show me a default.

    Hmm....

  9. #9
    Join Date
    Feb 2008
    Posts
    129
    Plugin Contributions
    0

    Default Re: Getting the default attribute radio button checked

    Ha ha!

    Well, my problem was unique to me. Total operator error.

    I had edited my product display page so that I had the Add To Cart button at both the top and bottom, and hen I added the product attributes, I also added them to both the top and bottom.

    So it was defaulting the radio button correctly--it was doing it in the second set of radio buttons because that's the last one it saw with that id.

    I was looking at the top set of radio buttons and that one wasn't getting set.

    I guess the moral is, it's ok to have an Add to Cart button in more than one place, but not attributes if you're going to have defaults.

  10. #10
    Join Date
    Jun 2009
    Posts
    9
    Plugin Contributions
    0

    Idea or Suggestion Re: Getting the default attribute radio button checked

    Hey! Guys

    I too ran across this problem and found a solution! with out making any changes in the code.
    http://www.imakewebsites.ca/zen-cart...able-products/

    Check this out they have explained it very clear.

    -Ram

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. v139h Attribute radio buttons not checked on product listing pages.
    By swdstudios in forum Templates, Stylesheets, Page Layout
    Replies: 4
    Last Post: 20 Jan 2015, 12:46 AM
  2. Priority as the default radio button?
    By Eridian in forum Built-in Shipping and Payment Modules
    Replies: 0
    Last Post: 13 Jun 2011, 01:41 AM
  3. radio button checked when shouldn't be
    By domsmom in forum Setting Up Categories, Products, Attributes
    Replies: 7
    Last Post: 5 Jun 2009, 04:51 PM
  4. HOW TO? radio button checked or won't proceed through checkout?
    By blackpig in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 9 Dec 2008, 09:24 PM
  5. how the radio button for credit card payment should be default selection???
    By lastpirate007 in forum Templates, Stylesheets, Page Layout
    Replies: 13
    Last Post: 7 Nov 2007, 12:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg