0

Magento2.2.5

On a configurable product where each child product has the same special price assigned what i want is on the category listing to show the special price and then the original price crossed out. This is how it works for the simple products however for configurable products it does not seem to work.

I am guessing I would have to edit the configured_price.phtml file located in my

app/design/frontend/luma/Magento_Catalog/templates/product/price folder?

Here is that files code:

 <?php
     /** @var \Magento\Catalog\Pricing\Render\FinalPriceBox $block */
     $schema = ($block->getZone() == 'item_view') ? true : false;
     $idSuffix = $block->getIdSuffix() ? $block->getIdSuffix() : '';
     /** @var \Magento\Catalog\Pricing\Price\ConfiguredPrice 
     $configuredPrice */
     $configuredPrice = $block->getPrice();
     /** @var \Magento\Catalog\Pricing\Price\ConfiguredRegularPrice 
     $configuredRegularPrice */
     $configuredRegularPrice = $block->getPriceType(
\Magento\Catalog\Pricing\Price\ConfiguredPriceInterface::CONFIGURED_REGULAR_PRICE_CODE
     );
 ?>
 <?php if ($configuredPrice->getAmount()->getValue() < 
     $configuredRegularPrice->getAmount()->getValue()) : 
 ?>
  <p class="price-as-configured">
    <span class="special-price">
        <?= /* @noEscape */ $block->renderAmount(
            $configuredPrice->getAmount(),
            [
                'display_label'     => $block->escapeHtml(__('Special Price')),
                'price_id'          => $block->escapeHtml($block->getPriceId('product-price-' . $idSuffix)),
                'price_type'        => 'finalPrice',
                'include_container' => true,
                'schema' => $schema
            ]
        ); ?>
    </span>
    <span class="old-price">
        <?= /* @noEscape */ $block->renderAmount(
            $configuredRegularPrice->getAmount(),
            [
                'display_label'     => $block->escapeHtml(__('Regular Price')),
                'price_id'          => $block->escapeHtml($block->getPriceId('old-price-' . $idSuffix)),
                'price_type'        => 'oldPrice',
                'include_container' => true,
                'skip_adjustments'  => true
            ]
        ); ?>
     </span>
  </p>
  <?php else : ?>
  <?php
    $priceLabel = ($block->getPriceLabel() !== null)
    ? $block->getPriceLabel(): '';
?>
 <p class="price-as-configured">
    <?= /* @noEscape */ $block->renderAmount(
        $configuredPrice->getAmount(),
        [
            'display_label'     => $block->escapeHtml($priceLabel),
            'price_id'          => $block->escapeHtml($block->getPriceId('product-price-' . $idSuffix)),
            'price_type'        => 'finalPrice',
            'include_container' => true,
            'schema' => $schema
        ]
    ); ?>
</p>
<?php endif; ?>

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.