At the request of TR I've opened a duplicate issue of an older issue that is identical to this issue.

Anyways, here is what I did. I DL'd vanilla D6, installed a basic Ubercart with nothing in it and created a few attributes/options. I then arranged these new attributes on a product node so that they made sense. Once this was done, I then went to the add product to cart screen and the attributes were in the proper order. So I selected options from the dropdowns and clicked "Check out". Once I got to the checkout screen, the attributes were listed in the order of 4,3,1,2 which is NOT the correct order. The correct order should have been 1,2,3,4. Why this is, is explained below.

After MUCH debugging and head banging against the wall, I FINALLY figured out why I was getting this odd behavior because the weights were simply not altering the order at all in the checkout screen like they should have been. At first I was convinced that it was a drupal_render() issue because this is where the problem was coming from. But after about 3 hours of debugging, I finally figured out WHY it was coming back unordered. It is because the uc_product.module version of $description is MISSING the #sort element. Without this, it's simply NOT possible to have the attributes in any coherent order and frankly I'm dumbfounded as to how people are getting the proper sorting without this key element because drupal_render clearly has a check for this element and if it doesnt exist, it adds it and then sorts it based on uasort which is alphabetical. The ONLY possibilty I can think of is that maybe there is an option somewhere to click "Sort by" in the configuration that sets the #sort element, but I certainly cannot find it if it is there. My guess is that this is suppose to have been added if the weights of each attribute are not defaulted to 0? I have no idea.

Anyways, here is the fix:

In uc_product.module on line 1837, add the sort element and set it to TRUE
<?php
function uc_product_get_description($product) {
// Run through implementations of hook_product_description()
$description = module_invoke_all('product_description', $product);

// Now allow alterations via hook_product_description_alter()
drupal_alter('product_description', $description, $product);
$description['attributes']['#sorted'] = TRUE; //Fix the sorting bug in UC 2.4
return drupal_render($description);
}

If anyone has an explanation as to WHY this would be missing, then I'm all ears because I have no clue why this critical element is missing if I've manipulated the Weights for the attributes in admin/store/attributes/AID/edit screen where it has "Weight" at the very bottom. I set them to 0,1,2,3 for each of my attributes but this only affected the product screen, it did not affect the checkout description screen unless I add the above fix.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

crystaldawn’s picture

bah, forgot closing tag for php. I hate that I cant edit that. anyways, heres a more readable version of the fix I had to add. BTW, it's my belief that this is NOT the proper fix. The proper fix is going to be to add the #sorted element only when weights are changed which is in a different area of the module that I am still unfamiliar with. But in my case, this fixes the issue since I always want attributes listed by weight anyways.

function uc_product_get_description($product) {
// Run through implementations of hook_product_description()
$description = module_invoke_all('product_description', $product);

// Now allow alterations via hook_product_description_alter()
drupal_alter('product_description', $description, $product);
$description['attributes']['#sorted'] = TRUE; //Fix the sorting bug in UC 2.4
return drupal_render($description);
}
goingbeyond’s picture

Beautiful. Thank you for posting!

JonM’s picture

Version: 6.x-2.4 » 6.x-2.10
FileSize
417 bytes

Ok, so I ran into this issue with 2.9, updated to 2.10 and still had it. Opened this issue: http://drupal.org/node/1810634 and discovered it duplicated this issue.

It was said
"No one has posted a patch that passes the automated tests, and no one has tested and reviewed the proposed solution. If you would like to help out and get that accomplished, please do so and follow up in that other issue. This is how Open Source works - community members like you who have a need drive the development."

So here is the patch file, attached. I hope it can make it into 2.11, so I don't need to re-apply it when I next upgrade.

TR’s picture

Status: Active » Needs review

Need to set the status to "needs review" to get the testbot to test the patch.

Status: Needs review » Needs work

The last submitted patch, uc_product.sort_.patch, failed testing.

JonM’s picture

Status: Needs work » Needs review
FileSize
541 bytes

Whoops, bad patch format. Sigh. Ok, got the git and did it the right way.

Status: Needs review » Needs work

The last submitted patch, attribute_sort_fix-1135258-6.patch, failed testing.

JonM’s picture

Status: Needs work » Needs review

#6: attribute_sort_fix-1135258-6.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, attribute_sort_fix-1135258-6.patch, failed testing.

JonM’s picture

I don't get why the patch failed testing, it's a one line addition to uc_product, and the failures appear to have nothing to do with the patch, but the test environment.

JonM’s picture

Status: Needs work » Needs review

#6: attribute_sort_fix-1135258-6.patch queued for re-testing.

Giving it another shot. What was that definition of insanity again?

Status: Needs review » Needs work

The last submitted patch, attribute_sort_fix-1135258-6.patch, failed testing.

JonM’s picture

Status: Needs work » Needs review

#6: attribute_sort_fix-1135258-6.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, attribute_sort_fix-1135258-6.patch, failed testing.

longwave’s picture

Testbot is not downloading Token module, which is a dependency of Ubercart and the source of the failing tests.

longwave’s picture

Version: 6.x-2.10 » 6.x-2.x-dev
Status: Needs work » Needs review
longwave’s picture

Setting the version to -dev used to avoid some testbot issues, let's see if that helps here.

longwave’s picture

#6: attribute_sort_fix-1135258-6.patch queued for re-testing.

JonM’s picture

Version: 6.x-2.x-dev » 6.x-2.10
Status: Needs review » Needs work

Thank you, that did it.

longwave’s picture

Version: 6.x-2.10 » 6.x-2.x-dev
Status: Needs work » Needs review

Not sure why you reset this back; 6.x-2.x-dev and needs review are correct.

JonM’s picture

I wasn't paying attention to the issue settings, not sure how they went over to 2.10 and needs work, I didn't do it on purpose, and when I saw that, couldn't edit the issue settings after.

TR’s picture

Title: The product description shown in cart doesn't display attributes in their weight order. » Product description on /cart and /cart/checkout doesn't display attributes in weight order
Status: Needs review » Needs work

uc_product_get_description() is the wrong place to make a change that affects only the attribute order. The fix should be done in the uc_attribute module, in uc_attribute_product_description(). And the first thing that should be tried is to return the actual weights from this hook - right now the returned weights are just autoincremented.

JonM’s picture

So can we leave this fix in the wrong place with a nice note that perhaps a better fix is needed? If it took a year and a half before I wandered by to try and get this, perhaps not optimal, fix put into code, I'd rather live with it like this until someone motivated to do the right thing wanders by.

TR’s picture

Version: 6.x-2.x-dev » 8.x-4.x-dev

Moving to D8, D6 is obsolete.

TR’s picture

Component: Code » Product attributes