Developer forum

Forum » Ecommerce - Standard features » Sorting variants options does not work in the VariantCombinations

Sorting variants options does not work in the VariantCombinations

Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi,

 

I have been trying to use the sorting variant options in the backend and everything looks good "on paper", but the variant combinations loop does not honor that sorting.

 

 

This is using 9.7.3, but the problem exists in at least 9.7.2 (my local version is just updated)

 

Best Regards,

Nuno Aguiar


Replies

 
Oleg Rodionov Dynamicweb Employee
Oleg Rodionov
Reply

Hi Nuno,

Actually, the issue was risen not once but always rejected due to it cannot be considered as valid bug, since it's feature of the loop. 

BR, Oleg QA

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Oleg,

 

Can you be more specific as how this is a feature and/or why this is rejected as a bug?

 

The issue is that the customer is building the variants as he goes (this one actually happened to be in PIM), and this means we're telling him that he has to create them in the final sorting order, and if he makes a mistake, he needs to delete the variant combinations and start over. That's not a nice response to give customers.

 

Obviously we can change that in code, but that also means creating custom code in Rapido because of sorting variant combinations, which is a "hard sell". We consider that to be a workaround not a custom feature.

 

Best Regards,

Nuno Aguiar

 
Morten Snedker Dynamicweb Employee
Morten Snedker
Reply

Hi Nuno,

You may find this thread useful: https://doc.dynamicweb.com/forum/ecommerce-standard-features/ecommerce-standard-features/wrong-order-of-variant-combinations-on-product

 

Regards
Snedker

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Morten,

 

Thanks for that. I understand the technical difficulty, but this customer does not integrate the data, so I can't ask them to re-enter the data in the right order. I may have a suggestion (my workaround) that would not have the performance impact of altering rows in the database.

 

var variantOptionSort = new List<string>();
foreach (var variantGroup in  GetLoop("VariantGroups"))
{
    variantOptionSort.AddRange(variantGroup.GetLoop("VariantAvailableOptions").Select(option => option.GetString("Ecom:VariantOption.Name")));
}

var variantsLoop = GetLoop("VariantCombinations");
variantsLoop = variantsLoop.OrderBy(v => variantOptionSort.IndexOf(v.GetString("Ecom:VariantCombination.VariantText"))).ToList();

 

This way the variantsLoop is sorted accordingly and we can loop through it accurately.

 

But as you might imagine, I don't want to have to apply this workaround everytime I need the variants, the Variants Loop should already have it sorted (for example I failed to capture applying the workaround in 1 location, and the customer complains again)

 

Best Regards,

Nuno Aguiar

 
Nicolai Pedersen
Reply

What about variants in 2 or more dimensions...?

And when and why would you use variant combinations to render variants - you should use the variants loop that contains the products. The combinations loop is a 'supporting' data structure to groups, options and variants for creating selectors.

BR Nicolai

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Nicolai,

 

There is no "Variants" loop, not at least in 9.7.2. And even the Rapido template use the VariantCombinations loop.

 

That said, what is the actual bug then? A missing "Variants" loop, or the VariantCombinations not having the proper sorting of the variant options? I don't mind either way, as long as the rendered data does not require us to sort the variants in the templates.

 

 

Best Regards,

Nuno Aguiar

 
Kim Søjborg Pedersen
Reply

Hi Nuno

Thanks for sharing the orderby code and I agree it would be nice if the variants was sorted correctly. In my case the customer shows all the variants as products on the productpage, like in a catalog. (DW I see the challenge with multiple variant groups)

/Kim

 

You must be logged in to post in the forum