Skip to main content
3 of 4
added 467 characters in body
Robert
  • 2.2k
  • 3
  • 37
  • 84

addAttributeToSort() not working

I have configurable product create with attribute size, I try to list this attribute size in the product description, but addAttributeToSort() not working. My code is:

if($_product->getTypeId() == "configurable"):
    $conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);

    $simple_collection = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addAttributeToSort('size','ASC')->addFilterByRequiredOptions();

right now I have something like this:

100g
10g
25g

enter image description here

If I use DESC instead ASC I have this sorting:

25g
10g
100g

The entire code:

if($_product->getTypeId() == "configurable"):
    $conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);

    $simple_collection = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addAttributeToSort('size','ASC')->addFilterByRequiredOptions();
    foreach($simple_collection as $simple_product){
        echo $simple_product->getAttributeText('size');
    }
endif;
Robert
  • 2.2k
  • 3
  • 37
  • 84