0

For a given configurable product is it possible to loop over the available product options outputing the option value and price?

For example:

foreach($configurableProduct->getOptions() as $option) {
    $price = $option->getPrice();
    $value = $option->getValue();
    $label = $option->getLabel();
}

This obviously doesnt work but is there anything similar in the codebase that can be used to get these values?

1
  • By options do you mean the simple products related to configs? Oct 26, 2013 at 19:37

1 Answer 1

1

You can use following code snippet:

    $attributes = $product->getTypeInstance(true)
        ->getConfigurableAttributes($product);

    $options = array();
    $store   = Mage::app()->getStore();
    foreach ($attributes as $attribute) {
        $prices = $attribute->getPrices();
        if (is_array($prices)) {
            foreach ($prices as $value) {
                $price    = $value['pricing_value'];
                $oldPrice = $value['pricing_value'];
                if ($value['is_percent'] && $price) {
                    $price    = $product->getFinalPrice() * $price / 100;
                    $oldPrice = $product->getPrice() * $price / 100;
                }
                $price    = $store->roundPrice($store->convertPrice($price));
                $oldPrice = $store->roundPrice($store->convertPrice($oldPrice));

                $options[] = array(
                    'value'    => $value['value_index'],
                    'label'    => $value['label'],
                    'price'    => $price,
                    'oldPrice' => $oldPrice
                );
            }
        }
    }

    print_r($options);

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.