uc_order pane is unable to add any attributes except last one

Project:Ubercart Contributions
Component:Code
Category:
Priority:critical
Assigned:japerry@drupal.org
Status:patch (needs review)
Description
Project: 
Ubercart

Our shipping manager realized today that when he creates orders from the admin menu that attributes don't work. Basically it comes down to this code in the uc_order.js:

Line 274:

  $('#uc-order-add-product-form :input').each(
    function() {
      if ($(this).attr('name').substr(0, 10) == 'attributes') {
        post_vars[$(this).attr('name')] = $(this).val();
      }
    }
  );

I ran a debug on this, basically the array is being iterated through, resetting the post_vars attributes value to be the last one to iterate through. A simple addition to make sure the attribute is 'checked' will fix this bug:

  $('#uc-order-add-product-form :input').each(
    function() {
      if ($(this).attr('name').substr(0, 10) == 'attributes' && $(this).attr('checked')) {
        post_vars[$(this).attr('name')] = $(this).val();
      }
    }
  );
Version: 
Ubercart 1.3
Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: uc_order pane is unable to add any attributes except last on

.attr('checked') works on attributes displayed as radio buttons. So while this does fix the problem for them, attributes as a select list don't get added in now. The solution to this problem will also have to handle textfield attributes, too.

russelltracey's picture
Offline
Getting busy with the Ubercode.
Joined: 11/24/2008
Juice: 2
Re: Re: uc_order pane is unable to add any attributes except las
Assigned to:Lyle» russelltracey

I just ran into to this problem, i added an additional check for radio buttons. This addresses the problem with the radio buttons while leaving the processing of all other elements the same as before.

  $('#uc-order-add-product-form :input').each(
    function() {
      if ($(this).attr('name').substr(0, 10) == 'attributes') {
        if ($(this).attr('type') == 'radio') {
          if (this.checked) {
            // Only the checked radio button values should be sent
            post_vars[$(this).attr('name')] = $(this).val();
          }
        } else {
          post_vars[$(this).attr('name')] = $(this).val();
        }
      }
    }
  );
Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: Re: Re: uc_order pane is unable to add any attributes except
Assigned to:russelltracey» Ryan

Thanks so much for figuring this one out! I just gave support to someone in the forums last week unable to understand why his SKUs weren't getting adjusted on the order edit form. I was only doing the testing with select list attributes which worked fine. I tested this patch for radio, select list, and textfield attributes, and the options get saved properly and SKUs adjusted as expected. Enjoy your shiny badge. Eye-wink

@Lyle, I'm not sure what this needs to do to accommodate textfield attributes in your opinion, but it's adding them just fine for me with this patch.

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: Re: Re: Re: uc_order pane is unable to add any attributes ex
Assigned to:Ryan» Lyle

Yeah, textfields and select boxes would be handled the same way in this case. My problem with the first patch was that those don't have a "checked" attribute and wouldn't be handled right. The second patch should work just fine.