Magento – Show Grouped product price in catalog view as sum of associated products in grouped product

catalog-price-rulesgrouped-productsmagento2price

In my magento store majority of products are "grouped products". Right now when you go in category you can see the label under the product image says "Price starting at" and the lower price of two associated products.

For example if one associated product cost $150 and the second $210, so the price in category view will be displayed as "Price starting at – $150".

In my case I want that the grouped product price would be displayed as the sum of two associated products without any labels like "Price starting at".

It should be displayed as a sum which in this case equal to "$360".

I hope someone could help me to find the solution.

Best Answer

I just had the same requirement. For a quick solution copy theme file

Magento_GroupedProduct\templates\product\price\final_price.phtml

to your custom theme and sum prices in template with

<?php

/*
 * Show combined price instead of minimal price for grouped products.
 */

$products = $block->getSaleableItem()->getTypeInstance()->getAssociatedProducts($block->getSaleableItem());

$priceForAll = 0;
foreach ($products as $product) {
    $priceForAll += $product->getPrice();
}

?>

<div class="price-box price-final_price" data-role="priceBox" data-product-id="284">
    <span class="price-container price-final_price tax weee">
            <span id="product-price-284" data-price-amount="<?php echo $priceForAll?>" data-price-type="finalPrice" class="price-wrapper ">
                <span class="price"><?php echo number_format($priceForAll,2,',','.')?> €</span>
            </span>
    </span>
</div>

Please note that the final price formatting in html is a quick hack and just fits my requirements. A more felxible solution taking into account magento's price formatting features is welcome!

Related Topic