[SOLVED] Products Module - Attributes appear in random order
-
- Forum Members
- Posts: 130
- Joined: Fri Feb 25, 2011 3:58 pm
[SOLVED] Products Module - Attributes appear in random order
In my Products module, I am using attributes to display various price options, and date options which can be selected by the user.
When I upload the dates, I put them all in calendar order, however as soon as I click 'submit' or 'update', somewhere along the line they get jumbled into what appears to be no logical order.
This random order is reflected both where they are displayed in the Cart, and also if I go back into editing the Attribute in the Products Admin module.
Some web research has thrown up this forum thread: http://forum.cmsmadesimple.org/viewtopic.php?t=22539 but having looked in Products.module.php it appears the attributes already have sort by id applied.
I've also had a quick look in action.add_attrib_set.php to see if I could find any clues there, however nothing immediately jumped out at me.
I would be grateful for any pointers on how I can sort the dates correctly.
When I upload the dates, I put them all in calendar order, however as soon as I click 'submit' or 'update', somewhere along the line they get jumbled into what appears to be no logical order.
This random order is reflected both where they are displayed in the Cart, and also if I go back into editing the Attribute in the Products Admin module.
Some web research has thrown up this forum thread: http://forum.cmsmadesimple.org/viewtopic.php?t=22539 but having looked in Products.module.php it appears the attributes already have sort by id applied.
I've also had a quick look in action.add_attrib_set.php to see if I could find any clues there, however nothing immediately jumped out at me.
I would be grateful for any pointers on how I can sort the dates correctly.
Last edited by JimboDavies on Thu Feb 16, 2012 8:42 am, edited 1 time in total.
-
- Forum Members
- Posts: 130
- Joined: Fri Feb 25, 2011 3:58 pm
Re: Products Module - Attributes appear in random order
I upgraded to the latest version of CMS Made Simple (1.10.3) and updated all modules to see if that would help, and I'm still experiencing this problem.
I can see on the forum that a number of people seem to have come across similar anomalies, so there must be a fix somewhere!
I can see on the forum that a number of people seem to have come across similar anomalies, so there must be a fix somewhere!
Re: Products Module - Attributes appear in random order
I had this problem and my very basic solution was just to suffix each field name with '1_', '2_', etc then loop through the fields twice. On the inner loop I just used the field that had the suffix that matched the foreach index number. Was all done in smarty with was simple enough.
I was watching this post looking for a more elegant solution... and still am
.
Chris
I was watching this post looking for a more elegant solution... and still am

Chris
-
- Forum Members
- Posts: 130
- Joined: Fri Feb 25, 2011 3:58 pm
Re: Products Module - Attributes appear in random order
I'm wondering if I can use jQuery to sort the dropdown box - again not very elegant, but possible.
What is confusing is that there is no logic to it - you can edit other product information in the project manager and not touch the attributes, and they will change order... completely unpredictable!
Like yourself, I'm still hoping there is a more elegant, probably hard coded, solution.
What is confusing is that there is no logic to it - you can edit other product information in the project manager and not touch the attributes, and they will change order... completely unpredictable!
Like yourself, I'm still hoping there is a more elegant, probably hard coded, solution.
-
- Forum Members
- Posts: 130
- Joined: Fri Feb 25, 2011 3:58 pm
Re: Products Module - Attributes appear in random order
If I look in CGEcommerceBase, and go to "Supplier Settings", I can find a few more options that look interesting, and possibly relevant.
At the bottom of the page is "Product Attribute Display Template" which sounds like it's configuring how the attributes are retrieved and displayed. Mine currently displays:
Does anyone know if this is helpful to getting my attributes sorted?
At the bottom of the page is "Product Attribute Display Template" which sounds like it's configuring how the attributes are retrieved and displayed. Mine currently displays:
Code: Select all
{$attrib_text} {*if !empty($attrib_adjust)*} {*+*}{*$currency_symbol*}{*$attrib_adjust|number_format:2*} {*/if*}
-
- Forum Members
- Posts: 130
- Joined: Fri Feb 25, 2011 3:58 pm
Re: Products Module - Attributes appear in random order
This is really frustrating me, as I can't seem to find a way of doing it.
One of my attributes generally only has three options, so it's less of an issue, but the dates are super frustrating. If there's anyone who has ever used the Products module as more of a 'Booking' system, I'd be really interested to hear how they handled dates.
One of my attributes generally only has three options, so it's less of an issue, but the dates are super frustrating. If there's anyone who has ever used the Products module as more of a 'Booking' system, I'd be really interested to hear how they handled dates.
Re: Products Module - Attributes appear in random order
I've tried this and I think it works:
create at UDT called 'sort_attributes' with the Code:
Then call this UDT using:
{sort_attributes unsortedattributes=$attributes}
then use a foreach loop of:
{foreach from=$sortedattributes item='attrib'}
instead of:
{foreach from=$attributes item='attrib'}
I hope it helps.
create at UDT called 'sort_attributes' with the Code:
Code: Select all
$Xattributes = $params['unsortedattributes'];
foreach ($Xattributes as &$Xattrib) {
sort($Xattrib->attrib_options);
}
$smarty->assign('sortedattributes',$Xattributes);
{sort_attributes unsortedattributes=$attributes}
then use a foreach loop of:
{foreach from=$sortedattributes item='attrib'}
instead of:
{foreach from=$attributes item='attrib'}
I hope it helps.
-
- Forum Members
- Posts: 130
- Joined: Fri Feb 25, 2011 3:58 pm
Re: Products Module - Attributes appear in random order
Chris, that's fantastic, thanks so much! So far, so good!
Hopefully that that will work for chrisbt too.
Hopefully that that will work for chrisbt too.
Re: [SOLVED] Products Module - Attributes appear in random o
Yup - that's me. A few more weeks using php and it was quite easy to step out of smarty and find a much simpler and more elegant solution.
-
- Forum Members
- Posts: 130
- Joined: Fri Feb 25, 2011 3:58 pm
Re: [SOLVED] Products Module - Attributes appear in random o
Sorry Chris - too early in the morning and I thought I was talking to two people! I didn't realise it was you that had come up with the solution...!
Re: Products Module - Attributes appear in random order
I'm using CMSMS 1.10.2, Products 2.15.1. I used the following instructions ----
Correct me if I am wrong, but I called the UDT from the AddtoCart template and changed out the foreach loop inside that template as noted above. I still cannot get the attributes to reorder themselves according to what the admin UI shows. Did I do something wrong?chrisbt wrote:I've tried this and I think it works:
create at UDT called 'sort_attributes' with the Code:Then call this UDT using:Code: Select all
$Xattributes = $params['unsortedattributes']; foreach ($Xattributes as &$Xattrib) { sort($Xattrib->attrib_options); } $smarty->assign('sortedattributes',$Xattributes);
{sort_attributes unsortedattributes=$attributes}
then use a foreach loop of:
{foreach from=$sortedattributes item='attrib'}
instead of:
{foreach from=$attributes item='attrib'}
I hope it helps.
Re: [SOLVED] Products Module - Attributes appear in random o
Has it output them sorted alphabetically?
I actually prefixed each of my attribute names with '1_','2_','3_', etc so they were sorted by that. I then just trimmed off the first 2 characters when I used the attribute names.
The other alternative would be to use the full attributes and sort on the contents of the SKU field.
I actually prefixed each of my attribute names with '1_','2_','3_', etc so they were sorted by that. I then just trimmed off the first 2 characters when I used the attribute names.
The other alternative would be to use the full attributes and sort on the contents of the SKU field.
Re: [SOLVED] Products Module - Attributes appear in random o
I pretty much have only 2 attributes for the Products (No Design Needed [which is listed 1st in the admin panel] & Design Needed); I always want it to default to No Design Needed since there is no extra charge for it. Would your solution work for this? Is there any way to just tell it to always default to attribute id 1?chrisbt wrote:Has it output them sorted alphabetically?
I actually prefixed each of my attribute names with '1_','2_','3_', etc so they were sorted by that. I then just trimmed off the first 2 characters when I used the attribute names.
The other alternative would be to use the full attributes and sort on the contents of the SKU field.
Re: [SOLVED] Products Module - Attributes appear in random o
if you've just got the 2 attributes try using rsort instead of sort in the UDT:
rsort($Xattrib->attrib_options);
Chris
... http://www.php.net/manual/en/function.rsort.php
rsort($Xattrib->attrib_options);
Chris
... http://www.php.net/manual/en/function.rsort.php
Re: [SOLVED] Products Module - Attributes appear in random o
OK, I threw in the "rsort" function instead and some product attributes show correctly - and some don't.chrisbt wrote:if you've just got the 2 attributes try using rsort instead of sort in the UDT:
rsort($Xattrib->attrib_options);
Chris
... http://www.php.net/manual/en/function.rsort.php
