Magento – How to get pricing_value for Super Attribute Option

attributesconfigurable-productmagento-1.7priceprogramming

Somehow I can't figure out how to get the pricing values for a configurable product's super attribute options.

Currently I have an array of attribute id and attribute option id which looks like this:

2013-08-24T15:35:01+00:00 DEBUG (7): Array Combination :Array
(
    [135] => 3
    [139] => 19
    [138] => 6
    [140] => 20
    [141] => 22
    [142] => 24
    [143] => 26
    [144] => 28
    [145] => 34
)

Now I want to calculate the total price for the configurable product with all the super attributes additional prices added.

I spend hours looking through the configurable product templates and javascript and still haven't figured out how the new price is calculated.

Through this link http://www.ayasoftware.com/content/magento-update-fly-super-product-attributes-configuration I figured out how to get the configurable options for my product. The data also contains a field "price_value" for each attribute option, but I totally don't know how to simply access the right object values.

I would love to just do something like:

$price = $configurableProductBasePrice;

foreach ($attributeCombination as $attribute => attributeOption)
{
   $attributeOptionPrice = $attribute->getAttributeOption($attributeOption)->getPrice();

   $price = $price + $attributeOptionPrice;
} 

Thanks in advance for every hint 🙂

Best Answer

You can use the same config generated for the configurable products and used in by the javascript that changes the price based on the selected product options. Here is an example that uses this to determine the minimum and maximum price of a configurable product. The answer is not yet accepted by the OP but I think it works. You can use the same technique, walking through the config array and getting summing up the prices for your values. Don't forget to add the base price at the end. Here is how you can get the config array.

$product = Mage::getModel('catalog/product')->load($productId);
$block = Mage::app()->getLayout()->createBlock('catalog/product_view_type_configurable');
$block->setProduct($product);
$config = json_decode($block->getJsonConfig(), true);
$basePrice = $config['basePrice'];

Looping through $config['attributes'] you can get your desired values.

Related Topic