3

The size attribute options on my configurable products are not displaying in the correct position on the frontend. They are displaying in the order of product ID instead

I have set the position on the size attribute in the admin panel (i.e. XS is position 1, S is position 2), but this appears to be disregarded on shop frontend. I've already reindexed and flushed all caches.

Is this a known error? How do I fix this?

3

Meogi has a great fix for this here: Magento 1.9.1 configurable product attribute sorting

Unfortunately I'm using Amasty Color Swatches Pro and that breaks it so I had to come up with another solution.

For now, I am re-sorting the getJsonConfig() object in my configurable.phtml template for the hard-coded size attribute (175):

$attribs = json_decode($this->getJsonConfig());
if($attribs->attributes)
{
    foreach($attribs->attributes as $attr)
    {
        if($attr->id == 175) //re-sort size
            {
                usort($attr->options, function ($a, $b){
                $sortOrder = Array("one size","petite","x-small","small","medium","large","x-large","24","25","26","27","28","29","30","31");
                return (array_search($a->label, $sortOrder) > array_search($b->label, $sortOrder)) ? 1 : -1;
                });
            }
    }
}
$attribs_json = json_encode($attribs);

And then in my JS, I'm calling this:

var spConfig = new Product.Config(<?php echo $attribs_json; ?>);

instead of

var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.