1

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 :)

1

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.

0

Is this what you are after?

$price = $configurableProduct->getPrice();

$associatedProduct = $configurableProduct->getTypeInstance()->getUsedProducts(); 
foreach($associatedProduct as $childProduct){
    $price += $childProduct->getPrice();
}
echo "Combined Price : " . $price;
  • I guess this would give me the total sum of all prices of all simple products associated with my configurable product added together. What I want is the price for just one combination of my configurable product, calculated by adding the option mark-ups of each option id to the base price of the configurable product like shown in my pseudo example above. – ericstumper Aug 25 '13 at 15:17
  • Ah, ok, way off mark then, sorry ;) – ProxiBlue Aug 25 '13 at 22:20

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.