1

At the moment I have this:

$allProducts = $_product->getTypeInstance(true)->getUsedProducts(null, $_product);

which seems to be pulling the Simple Products in order of Product ID. I initially tried swapping this code out for:

$conf=Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
$allProducts =  $conf->getUsedProductCollection()
                                 ->addAttributeToSelect('*')
                                 ->addFilterByRequiredOptions()
                                 ->setOrder('size', 'ASC');

(Size being the only configurable attribute relevant.) But I quickly realised that because this was actually sorting the string value (so numbers came up in the order 120,160,1080,20 which is no good). What I'd like to do is get this ordered by the attribute label's 'position' within that attribute. I've tried changing the 'setOrder' parameter to "position" and "order" without any joy.

Any help would be appreciated :)

2
$collection = $this->getProduct()->getTypeInstance()->getUsedProductCollection()->addAttributeToSort('price');

I hope this will help you

  • Thanks for your reply! This orders by price though, I think? – WillPS Jan 5 '16 at 9:38
0

You can get option_id and sort_order in "eav_attribute_option" table by this code:

$attributeId = 150; //attributeId which you want to get
$options_value = Mage::getResourceModel('eav/entity_attribute_option_collection')
            ->setAttributeFilter($attributeId)
            ->setPositionOrder('desc', true)
            ->load();

foreach($options_value as $option){
    echo $option->getOptionId()
    echo $option->getSortOrder();
}

And add this to product info. Final, use usort() to sort by attribute value position.

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.