0

I want to show base price and special price both in cart page, right now, by default it just shows special price. How to show exactly like product page or list page. Version 2.1x

1

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()); ?> 
        </span>

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

I have done changes in Magento Version 2.1.1.

another way : copy file to your theme folder and edit:

../vendor/magento/module-weee/view/frontend/templates/item/price/unit.phtml

find :

<span class="cart-price">
        <?php endif; ?>
            <?= /* @escapeNotVerified */ $block->formatPrice($block->getUnitDisplayPriceInclTax()) ?>
            </span>

get product if from item, and after get special price, and echo it. like this:

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

and using css just add styles.

  • Thanks for your answer but I want to do it on cart page not minicart – MGPM Feb 20 '19 at 8:52
  • Then you gotta place you template changes inside vendor/magento/module-wee/view/frontend/template/item/price/unit.phtml and do extend it in theme files. Thanks – Prathap Gunasekaran Feb 20 '19 at 9:05
  • use the same way – alexey boltynov Feb 20 '19 at 9:05
  • edit answer, working with 2.3 version – alexey boltynov Feb 20 '19 at 9:13
  • it doesnt work for me, on magento 2.1.9 – MGPM Feb 20 '19 at 10:12
0

copy file from

../vendor/magento/module-weee/view/frontend/templates/item/price/unit.phtml

to

design/frontend/your_theme_name/Magento_Weee/templates/item/price/unit.phtml

and paste this one :

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

/** @var $block \Magento\Weee\Block\Item\Price\Renderer */

$item = $block->getItem();
?>
<?php if ($block->displayPriceInclTax() || $block->displayBothPrices()): ?>
    <span class="price-including-tax" data-label="<?= $block->escapeHtml(__('Incl. Tax')) ?>">
        <?php if ($block->displayPriceWithWeeeDetails()): ?>
            <span class="cart-tax-total"
                data-mage-init='{"taxToggle": {"itemTaxId" : "#unit-item-tax-details<?= /* @escapeNotVerified */ $item->getId() ?>"}}'>
        <?php else: ?>
            <span class="cart-price">
        <?php endif; ?>
                <?php if($item->getProduct()->getSpecialPrice() != null): ?>
                <label style="color: red;">Old Price :</label>
        <p style="color: red;
    text-decoration: line-through;"><?php echo $block->formatPrice($item->getProduct()->getPrice());?></p>
                <?php endif;?>
            <?= /* @escapeNotVerified */ $block->formatPrice($block->getUnitDisplayPriceInclTax()) ?>
            </span>

        <?php if ($this->helper('Magento\Weee\Helper\Data')->getApplied($item)): ?>
            <span class="cart-tax-info" id="unit-item-tax-details<?= /* @escapeNotVerified */ $item->getId() ?>" style="display: none;">
                <?php foreach ($this->helper('Magento\Weee\Helper\Data')->getApplied($item) as $tax): ?>
                    <span class="weee" data-label="<?= /* @escapeNotVerified */ $tax['title'] ?>">
                        <?= /* @escapeNotVerified */ $block->formatPrice($tax['amount_incl_tax'], true, true) ?>
                    </span>
                <?php endforeach; ?>
            </span>

            <?php if ($block->displayFinalPrice()): ?>
                <span class="cart-tax-total"
                    data-mage-init='{"taxToggle": {"itemTaxId" : "#unit-item-tax-details<?= /* @escapeNotVerified */ $item->getId() ?>"}}'>
                    <span class="weee" data-label="<?= $block->escapeHtml(__('Total Incl. Tax')) ?>">
                        <?= /* @escapeNotVerified */ $block->formatPrice($block->getFinalUnitDisplayPriceInclTax()) ?>
                    </span>
                </span>
            <?php endif; ?>
        <?php endif; ?>
    </span>
<?php endif; ?>

<?php if ($block->displayPriceExclTax() || $block->displayBothPrices()): ?>
    <span class="price-excluding-tax" data-label="<?= $block->escapeHtml(__('Excl. Tax')) ?>">
        <?php if ($block->displayPriceWithWeeeDetails()): ?>
            <span class="cart-tax-total"
                data-mage-init='{"taxToggle": {"itemTaxId" : "#eunit-item-tax-details<?= /* @escapeNotVerified */ $item->getId() ?>"}}'>
        <?php else: ?>
            <span class="cart-price">
        <?php endif; ?>
                <?= /* @escapeNotVerified */ $block->formatPrice($block->getUnitDisplayPriceExclTax()) ?>
            </span>

        <?php if ($this->helper('Magento\Weee\Helper\Data')->getApplied($item)): ?>
            <span class="cart-tax-info" id="eunit-item-tax-details<?= /* @escapeNotVerified */ $item->getId() ?>"
                style="display: none;">
                <?php foreach ($this->helper('Magento\Weee\Helper\Data')->getApplied($item) as $tax): ?>
                    <span class="weee" data-label="<?= /* @escapeNotVerified */ $tax['title'] ?>">
                        <?= /* @escapeNotVerified */ $block->formatPrice($tax['amount'], true, true) ?>
                    </span>
                <?php endforeach; ?>
            </span>

            <?php if ($block->displayFinalPrice()): ?>
                <span class="cart-tax-total"
                      data-mage-init='{"taxToggle": {"itemTaxId" : "#eunit-item-tax-details<?= /* @escapeNotVerified */ $item->getId() ?>"}}'>
                    <span class="weee" data-label="<?= $block->escapeHtml(__('Total')) ?>">
                        <?= /* @escapeNotVerified */ $block->formatPrice($block->getFinalUnitDisplayPriceExclTax()) ?>
                    </span>
                </span>
            <?php endif; ?>
        <?php endif; ?>
    </span>
<?php endif; ?>

use bin/magento cache:clean && bin/magento cache:flush. And all work!!

in my variant path next :

design/frontend/Smartwave/tropenkost/Magento_Weee/templates/item/price/unit.phtml

enter image description here

  • Thanks but it doesnt work :( – MGPM Feb 20 '19 at 12:51
  • LOL, whats all that I can say – alexey boltynov Feb 20 '19 at 14:34
  • I just tried to add an alert to <?php if ($block->displayPriceInclTax() || $block->displayBothPrices()): ?> but it doesnt goes to this line at all. what are you thinking about? – MGPM Feb 21 '19 at 6:10
  • omg, just copy paste and all will work fine, just copy vendor file to your destination... – alexey boltynov Feb 21 '19 at 10:38
0

The above answers are good and work. I am proving a full answer here with proper solution so it will not affect other sections of the website.

  1. create Magento_Weee folder at app\design\frontend\{your_vendor_name}\{your_theme_name} if folder already not exist.
  2. create a file named checkout_item_price_renderers.xml if not exist.
  3. Put below line of code into a file.

    <?xml version="1.0"?>
         <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
            <body>
                 <block class="Magento\Weee\Block\Item\Price\Renderer" name="checkout.item.price.unit" template="Magento_Weee::cart/item/price/unit.phtml">
                    <arguments>
                       <argument name="zone" xsi:type="string">cart</argument>
                    </arguments>
                  </block>
            </body>
        </page>
    
  4. create a file unit.phtml at app\design\frontend\Etales\fashion\Magento_Weee\templates\cart\item\price

  5. And copy paste below line of code into that file.

        <?php
    /**
     * Copyright © Magento, Inc. All rights reserved.
     * See COPYING.txt for license details.
     */
    
    // @codingStandardsIgnoreFile
    
    /** @var $block \Magento\Weee\Block\Item\Price\Renderer */
    
    $item = $block->getItem();
    ?>
    <?php if ($block->displayPriceInclTax() || $block->displayBothPrices()): ?>
        <span class="price-including-tax" data-label="<?= $block->escapeHtml(__('Incl. Tax')) ?>">
            <?php if ($block->displayPriceWithWeeeDetails()): ?>
                <span class="cart-tax-total"
                    data-mage-init='{"taxToggle": {"itemTaxId" : "#unit-item-tax-details<?= /* @escapeNotVerified */ $item->getId() ?>"}}'>
            <?php else: ?>
                <span class="cart-price">
            <?php endif; ?>
                <?php $finalPrice = $item->getProduct()->getFinalPrice(); ?>
                <?php $normalPrice = $item->getProduct()->getPrice(); ?>
                <?php if($normalPrice != $finalPrice):?>
                    <p style="color: red;text-decoration: line-through;">
                        <?php echo $block->formatPrice($normalPrice);?>
                    </p>
                <?php endif; ?>
                <?= /* @escapeNotVerified */ $block->formatPrice($block->getUnitDisplayPriceInclTax()) ?>                    
                </span>
    
            <?php if ($this->helper('Magento\Weee\Helper\Data')->getApplied($item)): ?>
                <span class="cart-tax-info" id="unit-item-tax-details<?= /* @escapeNotVerified */ $item->getId() ?>" style="display: none;">
                    <?php foreach ($this->helper('Magento\Weee\Helper\Data')->getApplied($item) as $tax): ?>
                        <span class="weee" data-label="<?= /* @escapeNotVerified */ $tax['title'] ?>">
                            <?= /* @escapeNotVerified */ $block->formatPrice($tax['amount_incl_tax'], true, true) ?>
                        </span>
                    <?php endforeach; ?>
                </span>
    
                <?php if ($block->displayFinalPrice()): ?>
                    <span class="cart-tax-total"
                        data-mage-init='{"taxToggle": {"itemTaxId" : "#unit-item-tax-details<?= /* @escapeNotVerified */ $item->getId() ?>"}}'>
                        <span class="weee" data-label="<?= $block->escapeHtml(__('Total Incl. Tax')) ?>">
                            <?= /* @escapeNotVerified */ $block->formatPrice($block->getFinalUnitDisplayPriceInclTax()) ?>
                        </span>
                    </span>
                <?php endif; ?>
            <?php endif; ?>
        </span>
    <?php endif; ?>
    
    <?php if ($block->displayPriceExclTax() || $block->displayBothPrices()): ?>
        <span class="price-excluding-tax" data-label="<?= $block->escapeHtml(__('Excl. Tax')) ?>">
            <?php if ($block->displayPriceWithWeeeDetails()): ?>
                <span class="cart-tax-total"
                    data-mage-init='{"taxToggle": {"itemTaxId" : "#eunit-item-tax-details<?= /* @escapeNotVerified */ $item->getId() ?>"}}'>
            <?php else: ?>
                <span class="cart-price">
            <?php endif; ?>
                    <?= /* @escapeNotVerified */ $block->formatPrice($block->getUnitDisplayPriceExclTax()) ?>
                </span>
    
            <?php if ($this->helper('Magento\Weee\Helper\Data')->getApplied($item)): ?>
                <span class="cart-tax-info" id="eunit-item-tax-details<?= /* @escapeNotVerified */ $item->getId() ?>"
                    style="display: none;">
                    <?php foreach ($this->helper('Magento\Weee\Helper\Data')->getApplied($item) as $tax): ?>
                        <span class="weee" data-label="<?= /* @escapeNotVerified */ $tax['title'] ?>">
                            <?= /* @escapeNotVerified */ $block->formatPrice($tax['amount'], true, true) ?>
                        </span>
                    <?php endforeach; ?>
                </span>
    
                <?php if ($block->displayFinalPrice()): ?>
                    <span class="cart-tax-total"
                          data-mage-init='{"taxToggle": {"itemTaxId" : "#eunit-item-tax-details<?= /* @escapeNotVerified */ $item->getId() ?>"}}'>
                        <span class="weee" data-label="<?= $block->escapeHtml(__('Total')) ?>">
                            <?= /* @escapeNotVerified */ $block->formatPrice($block->getFinalUnitDisplayPriceExclTax()) ?>
                        </span>
                    </span>
                <?php endif; ?>
            <?php endif; ?>
        </span>
    <?php endif; ?>
    <style type="text/css">
        #shopping-cart-table .item-info .col.price span{text-decoration: inherit;}
    </style>
    

coding is done not need to deploy if you are in production mode.

Need to flush the cache.

If production mode than

 php bin/magento s:s:d --theme {your_vendor_name}\{your_theme_name} -language {langauge_code}

Or just run

php bin/magento s:s:d

At last clear or flush the cache.

php bin/magento cache:flush 

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.