0

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.

  • 1
    For your requirement you need to customized magento functionality. – Dhiren Vasoya Dec 19 '16 at 13:32
  • Maybe you know what exactly? – Tautvydas Banys Dec 20 '16 at 0:56
  • Have you try any thing for this? – Dhiren Vasoya Dec 20 '16 at 3:04
4

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!

  • Can you show all code in final_price.phtml file? – Tautvydas Banys Jan 6 '17 at 19:22
  • Edited the code snippet. – skymeissner Jan 9 '17 at 8:25
0

I've refactored the code of @skymeissner:

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

/**
 * Template for displaying grouped product price
 */
?>
<?php
$allProducts = $block->getSaleableItem()->getTypeInstance()->getAssociatedProducts($block->getSaleableItem());
$priceHelper = $this->helper(\Magento\Framework\Pricing\Helper\Data::class);


if ($allProducts) {

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

?>

<div class="price-box" itemprop="offers" itemscope itemtype="http://schema.org/Offer">
    <?php if ($priceForAll > 0 && \Magento\Framework\Pricing\Render::ZONE_ITEM_VIEW != $block->getZone()): ?>
        <p class="grouped-price">
            <span class="price-label">
                <?= /* @escapeNotVerified */ __('Starting at') ?>
            </span>
            <span class="price">
                <?= $formattedPrice = $priceHelper->currency($priceForAll, true, false); ?>
            </span>
        </p>
    <?php endif ?>
</div>

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.