1

By default, the pre-sale price and sale branding are shown for simple products that are on sale, but for grouped products for which one associated product is on sale, only the sale price is shown, without any indication that it is a sale price.

0

I have already done something that seems to work, but the logic of the one for grouped products is a little suspect: It will show the current price of the associated product with the lowest current price, and then it will show sale branding dependent on whether that product is on sale, even if its regular price happens to not be the minimum regular price among the associated products.


Each of these paths is relative to your theme; whether you purchased a theme or just started with Luma, you should be sure to make a child theme with all changes:

Magento_ConfigurableProduct/Templates/product/price/final_price.phtml

<?php
/** @var \Magento\ConfigurableProduct\Pricing\Render\FinalPriceBox$block */

/** @var \Magento\Framework\Pricing\Price\PriceInterface $priceModel */
$priceModel = $block->getPriceType('regular_price');

/** @var \Magento\Framework\Pricing\Price\PriceInterface $finalPriceModel */
$finalPriceModel = $block->getPriceType('final_price');
$idSuffix = $block->getIdSuffix();
$idSuffix = $idSuffix ? $idSuffix : '';
$schema = $block->getZone() == 'item_view';
$hasSpecial = $block->hasSpecialPrice();
?>
<span class="<?= $hasSpecial ? 'special' : 'normal' ?>-price">
    <?= /* @noEscape */ $block->renderAmount($finalPriceModel->getAmount(), [
        'display_label' => __('As low as'),
        'price_id' => $block->getPriceId('product-price-' . $idSuffix),
        'price_type' => 'finalPrice',
        'include_container' => true,
        'schema' => $schema
    ]) ?>
</span>

<?php if ($hasSpecial): ?>
    <span class="old-price no-display">
        <?= /* @escapeNotVerified */ $block->renderAmount($priceModel->getAmount(), [
            'display_label'     => __('Regular Price'),
            'price_id'          => $block->getPriceId('old-price-' . $idSuffix),
            'price_type'        => 'oldPrice',
            'include_container' => true,
            'skip_adjustments'  => true
        ]) ?>
    </span>
<?php endif; ?>

<?php if ($block->showMinimalPrice()): ?>
    <?php if ($block->getUseLinkForAsLowAs()):?>
        <a href="<?= /* @escapeNotVerified */ $block->getSaleableItem()->getProductUrl() ?>" class="minimal-price-link">
            <?= /* @escapeNotVerified */ $block->renderAmountMinimal() ?>
        </a>
    <?php else: ?>
        <span class="minimal-price-link">
            <?= /* @escapeNotVerified */ $block->renderAmountMinimal() ?>
        </span>
    <?php endif?>
<?php endif; ?>

Magento_GroupedProduct/Templates/product/price/final_price.phtml

<?php
$hasSpecial = false;
$minProduct = $block->getSaleableItem()
    ->getPriceInfo()
    ->getPrice(\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE)
    ->getMinProduct();

if ($minProduct) { 
    $finalPrice = $minProduct->getPriceInfo()->getPrice('final_price');
    $finalAmount = $finalPrice->getAmount();
    $regularPrice = $minProduct->getPriceInfo()->getPrice('regular_price');
    $regularAmount = $regularPrice->getAmount();
    $hasSpecial = $finalAmount < $regularAmount;
    $amountRender = $block->getRendererPool()
        ->createAmountRender(
            $finalAmount,
            $minProduct,
            $finalPrice,
            ['include_container' => true]
        );
}
?>
<div class="price-box" itemprop="offers" itemscope itemtype="http://schema.org/Offer">
    <?php if ($minProduct && \Magento\Framework\Pricing\Render::ZONE_ITEM_VIEW != $block->getZone()): ?>
        <?php $groupedLabel = 'Starting at'; ?>
        <?php if ($hasSpecial) { ?>
    <span class="price-label"><?= /* @escapeNotVerified */ __($groupedLabel) ?></span><span class="special-price"><?= $amountRender->toHtml() ?></span>
    <span class="old-price"><?= $block->getRendererPool()
                                    ->createAmountRender(
                                        $regularAmount,
                                        $minProduct,
                                        $regularPrice,
                                        ['include_container' => true]
                                    )->toHtml() ?></span>
        <?php } else { ?>
    <p class="minimal-price">
        <span class="price-label"><?= /* @escapeNotVerified */ __($groupedLabel) ?></span><?= $amountRender->toHtml() ?>
    </p>
        <?php } ?>
    <?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.