2

Am working on a shopping cart site now and am unable to sort the products based on the price.. I have drink size as the configurable product and there are several drink sizes for a single product e.g 100 ml, 250 ml, 500 ml.. The price should be sorted as per the minimum quantity but its not sorting like that..

2 Answers 2

1

When dealing with configurable products (or any time you're dealing with a concept for only one type of product, as configurable attributes are), you'll probably be working with getTypeInstance. See below, I grab the configurable attributes for the product, then find the one for size. You could also just run through every configurable attribute if you wanted. Or if size is the only configurable attribute, just skip that if().

$attrs  = $_product->getTypeInstance(true)->getConfigurableAttributesAsArray($_product);
foreach($attrs as $attr) {
    if(0 == strcmp("size", $attr['attribute_code'])) {
        $options    = $attr['values'];
        foreach($options as $option) {
            print "{$option['store_label']}<br />";
        }
    }
}

Hope that helps!

1

You just need set the sort order for the drink size attribute options under

Catalog > Attributes > Manage Attributes > [Your Attribute] > Manage Label / Options

The sort order of the options listed there will set the sort order for the options list in the configurable options dropdown. POC using sample data:

Screenshot of attribute option admin view

Here's the effect visible on the site frontend:

Screenshot of frontend display of attribute options

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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