How can I get price of grouped product?
-
12-12-2019 - |
Question
I need to set Open Graph price grouped product in <head>
section.
I can get price of simple product in this way:
<meta property="og:price:amount" content="<?php echo $_product->getPriceHtml($_item, true) ?>">
and it works well. But... how can I get price of grouped product (the price of the product associated with the lowest price)?
Solution
I solved this way getting the price of the last product associated (the prices of my products associated are the same for each product so I need to check what is the lowest):
<meta property="og:price:amount" content="<?php
$product = Mage::getModel('catalog/product');
$product->load(Mage::registry('current_product')->getId());
$grouped_product_model = Mage::getModel('catalog/product_type_grouped');
$groupedParentId = $grouped_product_model->getParentIdsByChild($product->getId());
$_associatedProducts = $product->getTypeInstance(true)->getAssociatedProducts($product);
foreach($_associatedProducts as $_associatedProduct) {
if($ogPrice = $_associatedProduct->getPrice()) {
$ogPrice = $_associatedProduct->getPrice();
}
}
$ogPrice = number_format((float)$ogPrice, 2, '.', '');
echo $ogPrice . " Euro";
?>" />
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange