Question

I am trying to show the special price on the category page in the same way it shows on the item page. I copied final_price.phtml placed this code at the top :

Magento_Catalog/templates/product/price/final_price.phtml

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

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

/** ex: \Magento\Catalog\Pricing\Price\FinalPrice */
/** @var \Magento\Framework\Pricing\Price\PriceInterface $finalPriceModel */
$finalPriceModel = $block->getPriceType('final_price');
$idSuffix = $block->getIdSuffix() ? $block->getIdSuffix() : '';
$schema = ($block->getZone() == 'item_view') ? true : false;

// New code to show on category page
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$requestInterface = $objectManager->get('Magento\Framework\App\RequestInterface');
$showaction = $requestInterface->getFullActionName();
?>
<?php // new category code ?>
<?php if ($showaction == "catalog_category_view"): ?>
    <?php if ($block->hasSpecialPrice()) :?>
        <span class="special-price">
            <?= /* @noEscape */ $block->renderAmount($finalPriceModel->getAmount(), [
                'display_label'     => __('Special Price'),
                'price_id'          => $block->getPriceId('product-price-' . $idSuffix),
                'price_type'        => 'finalPrice',
                'include_container' => true,
                'schema' => $schema
            ]); ?>
        </span>
        <span class="old-price">
            <?= /* @noEscape */ $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 else :?>
        <?= /* @noEscape */ $block->renderAmount($finalPriceModel->getAmount(), [
            'price_id'          => $block->getPriceId('product-price-' . $idSuffix),
            'price_type'        => 'finalPrice',
            'include_container' => true,
            'schema' => $schema
        ]); ?>
    <?php endif; ?>
<?php endif; ?>

<?php //end category code ?>

The remainder of the code is the code that was there for the item page and it still works as expected. All it does on the category page is show the regular price twice.

Thanks, Stan

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top