1

I'm using this code to get grouped product price in this file "Magento_GroupedProduct\templates\product\price\final_price.phtml":

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

$priceForAll = 0;
foreach ($products as $product) {
    $priceForAll += $product
        ->getPrice(\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE);
}
?>
<div class="price-box" itemprop="offers" itemscope itemtype="http://schema.org/Offer">
    <?php if ($priceForAll && \Magento\Framework\Pricing\Render::ZONE_ITEM_VIEW != $block->getZone()): ?>
    <span class="price">$<?php echo number_format($priceForAll,2,'.',',')?></span>
    <?php endif ?>
</div>

But this sums up the total cost of all added goods without counting the quantity. I have no problem on the product page because I'm using JS to count price dynamically

enter image description here

But I have an incorrect price on the category page

enter image description here

How can I check the quantity of all added products and show the correct price?

Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.