Retrieve simple product price for configurable product
-
16-10-2019 - |
Question
We have a configurable product called with sku TEST and under it are simple products (for example) red-ven1, red-ven2, blue-ven3, etc. The configurable product itself does not have a price but each simple product does. I need to retrieve the price for the simple product based on the attributes that are selected. So I need the price for red product with vendor 2. How do I get this specific price? I am currently trying to dynamically display the price next to the vendor attribute (so vendor attribute is not selected). Will I have to "invisibly" select the vendor attribute value to get the price? Please advise.
Currently Trying:
<?php $_product = $this->getProduct(); ?>
<?php $_price = $_taxHelper->getPrice($_product, $_product->getPrice()) ?>
<script>
var price = <?=$_price ?>;
/...lots of non-applicable code
for(var i=0; i < IDs.length; i++)//traversing the vendor detail nodes
{
//Invisibly make selection of vendor so as to gather correct price
var optionToSelect = $j('option', '#attribute136').filter(function() {
return $j(this).text().indexOf(data[i].vendor_id) != -1;
}).val();
var vals = $j('#attribute136').val() || [];
vals.push(optionToSelect);
$j('#attribute136').val(vals);
$j('.details'+data[i].vendor_id).append('<li class="priceBlock">$'+price+'</li>');
}
});
</script>
Solution
There are two extension which does this for you:
Simple Configurable Products
http://www.magentocommerce.com/magento-connect/simple-configurable-products.html
BCP - Better Configurable Products
http://www.magentocommerce.com/magento-connect/better-configurable-products.html
OTHER TIPS
Check following link. This helps you. In this post can get product id of selected simple product of configurable product. And using that simple product id you can get price, qty, sku, etc...
I did this in list.phtml
.
It's a hack, but it works (and it's free!)
<?php
foreach ($_productCollection as $_product):
$_modifiedProduct = $_product;
?>
<?php
if ($_product->isConfigurable()) {
$conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
$simple_collection = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();
$appliedFilters = Mage::getSingleton('catalog/layer')->getState()->getFilters();
$itemArr = array();
foreach ($appliedFilters as $item) {
$itemArr[] = $item->getLabel();
}
$attributesToFilter = array();
foreach ($simple_collection as $simple_product) {
$productModel = Mage::getModel('catalog/product')->setProduct($simple_product);
$sizeAttr = $productModel->getResource()->getAttribute("size");
$qualityAttr = $productModel->getResource()->getAttribute("quality");
$attributesToFilter[] = $sizeAttrName = $sizeAttr->getSource()->getOptionText($simple_product->getSize());
$attributesToFilter[] = $qualityAttrName = $qualityAttr->getSource()->getOptionText($simple_product->getQuality());
sort($attributesToFilter);
sort($itemArr);
if ($attributesToFilter == $itemArr) {
$_modifiedProduct = $simple_product;
break(1);
}
unset($attributesToFilter);
}
}
// continue in foreach.
endforeach;
?>
Now you can show price like this:
<?php echo $this->getPriceHtml($_modifiedProduct, true) ?>