1

I'm writing a custom display for certain attributes based on its label. Within the 'configurable.phtml' file, it has the following lines:

$_product = $this->getProduct();
$_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes());

I can loop through the attributes array and check the label no problem:

$special_attr = false;
foreach ($_attributes as $_attribute) {
    echo $_attribute->getLabel().'<br>';
    if ($_attribute->getLabel() === 'FooBar') {
        $special_attr = $_attribute;
    }
}

This will print out all of the labels ("Color", "Size", etc.). I'm trying to get a list of all options and their values given this special attribute now, and I'm completely stumped. All of the other questions I have found have said something along the lines of using ->getSource()->getAllOptions(false), however, calling getSource() on this attribute just returns null.

How can I get all options given this special attribute?

if ($special_attr) {
    $options = $special_attr->??????
    // list all options??
}
2

1 Answer 1

2

You can try below code to get options of configurable attributes within configurable.phtml

$special_attr = false;
foreach ($_attributes as $_attribute) {
    echo $_attribute->getLabel().'<br>';
    if ($_attribute->getLabel() === 'FooBar') {
        $special_attr = $_attribute->getPrices();
    }
}

As you can see, the trick lies in $_attribute->getPrices(). This will give you an output like this for color attribute (if that is configurable)

Array
(
[0] => Array
    (
        [product_super_attribute_id] => 13
        [value_index] => 183
        [label] => Brown
        [default_label] => Brown
        [store_label] => Brown
        [is_percent] => 0
        [pricing_value] => 10.0000
        [use_default_value] => 1
        [value_id] => 15
    )

[1] => Array
    (
        [product_super_attribute_id] => 13
        [value_index] => 174
        [label] => Orange
        [default_label] => Orange
        [store_label] => Orange
        [is_percent] => 0
        [pricing_value] => 20.0000
        [use_default_value] => 1
        [value_id] => 16
    )

)

I believe this will be enough in your case.

2
  • Yes, this is perfect. I wish this info was under something less misleading than "getPrices" though. Thanks! Jul 18, 2016 at 21:49
  • @StevenJeffries In fact, yes it is a misleading terminology. But on another hand, it is logical too. Because each option of a configurable product determine the actual price of configurable product Jul 19, 2016 at 4:29

Your Answer

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

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