Skip to main content

Magento 2 Minicart - Display line item subtotal rather than unit price

url: https://magento.stackexchange.com/questions/173028/magento-2-minicart-display-line-item-subtotal-rather-than-unit-price

 

 Final Solution,

You can get item qty using $qty = $item->getQty(); Now just you have to set $block->getUnitDisplayPriceInclTax()*$qty to get lineItem subtotal for each item.

app/design/frontend/{Packagename}/{themename}/Magento_Weee/templates/checkout/cart/item/price/sidebar.phtml

 

<?php
/** @var $block \Magento\Weee\Block\Item\Price\Renderer */
$item = $block->getItem();

$originalZone = $block->getZone();
$block->setZone(\Magento\Framework\Pricing\Render::ZONE_CART);
/* custom logic*/
$qty = $item->getQty();
?>
<?php if ($block->displayPriceInclTax() || $block->displayBothPrices()): ?>
    <span class="price-including-tax" data-label="<?php echo $block->escapeHtml(__('Incl. Tax')); ?>">
    <?php if ($block->displayPriceWithWeeeDetails()): ?>
        <span class="minicart-tax-total">
    <?php else: ?>
        <span class="minicart-price">
    <?php endif; ?>
        <!-- custom logic -->
        <?php /* @escapeNotVerified */ echo $block->formatPrice($block->getUnitDisplayPriceInclTax()*$qty); ?>
        </span>

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

            <?php if ($block->displayFinalPrice()): ?>
                <span class="minicart-tax-total">
                    <span class="weee" data-label="<?php echo $block->escapeHtml(__('Total Incl. Tax')); ?>">
                        <!-- custom logic -->
                        <?php /* @escapeNotVerified */ echo $block->formatPrice($block->getFinalUnitDisplayPriceInclTax()*$qty); ?>
                    </span>
                </span>
            <?php endif; ?>
        <?php endif; ?>
    <?php endif; ?>
    </span>
<?php endif; ?>

<?php if ($block->displayPriceExclTax() || $block->displayBothPrices()): ?>
    <span class="price-excluding-tax" data-label="<?php echo $block->escapeHtml(__('Excl. Tax')); ?>">
    <?php if ($block->displayPriceWithWeeeDetails()): ?>
        <span class="minicart-tax-total">
    <?php else: ?>
        <span class="minicart-price">
    <?php endif; ?>
        <!-- custom logic -->
        <?php /* @escapeNotVerified */ echo $block->formatPrice($block->getUnitDisplayPriceExclTax()*$qty); ?>
        </span>

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

            <?php if ($block->displayFinalPrice()): ?>
                <span class="minicart-tax-total">
                    <span class="weee" data-label="<?php echo $block->escapeHtml(__('Total')); ?>">
                        <!-- custom logic -->
                        <?php /* @escapeNotVerified */ echo $block->formatPrice($block->getFinalUnitDisplayPriceExclTax()*$qty); ?>
                    </span>
                </span>
            <?php endif; ?>
        <?php endif; ?>
    <?php endif; ?>
    </span>
<?php endif; ?>
<?php $block->setZone($originalZone); ?>
 

In above file i have just comment as custom logic at which place i have added price multiply $qty to get lineitem subtotal.

Clear cache and check it again.

 

 

Comments

Popular posts from this blog

Magento 2: Category list for custom magento system configuration section ( Backend )

In system.xml file field for multi select of category is like: NOTE: Use Select for Single item and multiselect for multiple in - <field id = "bannerlist" translate = "label" type = " multiselect " <group id = "bannerblock_setting" translate = "label" type = "text" delault = "1" sortOrder = "3" showInDefault = "1" showInWebsite = "1" showInStore = "1" > <label> Setting </label> <field id = "bannerlist" translate = "label" type = "multiselect" sortOrder = "10" showInDefault = "1" showInWebsite = "1" showInStore = "1" > <label> Select Category </label> <!-- <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>--> <source_model> Ipragmatech\Bannerblock\Model\Config\Source\C...

Magento 2: Add new tab in Product detail page

New tab in product detail page is very easy task with product attribute. Use below steps and check it out. Step 1. Create Product Attribute “video”. Step 2. Create file “ catalog_product_view.xml ” in the app/design/frontend/{vender name}/{theme name}/Magento_Catalog/layout In the file write the below code: <!-- this is code to add new tab start --> <referenceBlock name="product.info.details"> <block class="Magento\Catalog\Block\Product\View\Description" name="product.info.video" template="product/view/attribute.phtml" group="detailed_info"> <arguments> <argument name="at_call" xsi:type="string">getVideo</argument> <argument name="at_code" xsi:type="string">video</argument> <argument name="css_class" xsi:type="string">video</argument> <argument name="at_label" xsi:type="string">non...