I can set Normal price along with Special price while put custom function in core file


public function getUnitItemPriceExclTax()
    $priceExclTax = $this->getItem()->getProduct()->getPrice();

    return $priceExclTax;

And calling this function into core file, vendor/magento/module-weee/view/frontend/templates/checkout/cart/item/price/sidebar.phtml

So getting both price correctly, but i want to override that

vendor/magento/module-weee/Block/Item/Price/Renderer.php block on my custom module.

I have created di.xml with below code :

<preference for="Magento\Weee\Block\Item\Price\Renderer" type="<namespace\<module_name>\Block\Item\Price\Renderer"/>

And just put that getUnitItemPriceExclTax() function in that block.

enter image description here


You dont need to override Renderer.php file in core and you should never do in core. You can just changes in sidebar.phtml file and set your changes.

You can get price from below method:

$finalPrice = $item->getProduct()->getFinalPrice();
$normalPrice = $item->getProduct()->getPrice();

After getting above changes you can do it below code in your template file:

<?php if ($block->displayPriceWithWeeeDetails()): ?>
        <span class="minicart-tax-total">
    <?php else: ?>
        <span class="minicart-price">
    <?php endif; ?>
        <?php /* @escapeNotVerified */ echo $block->formatPrice($block->getUnitDisplayPriceExclTax()); ?> 

    <?php if($normalPrice != $finalPrice){ ?>
    <span class="minicart-old-price">
            <?php /* @escapeNotVerified */ echo $block->formatPrice($normalPrice); ?>
    <?php }   ?>

I have done changes in Magento Version 2.1.1.

  • 2
    in Magento2.1.8 It is no longer render in sidebar.phtml. I see from vendor/magento/module-checkout/view/frontend/layout/checkout_cart_sidebar_item_price_renderers.xml, The template is vendor/magento/module-checkout/view/frontend/web/template/minicart/item/price.html Now I do not know how to get origin price. Sep 11 '17 at 4:39

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.