6

I have installed magento 2.0.7 and overide the template minicart.phtml to my custom theme. I want to show total price and total items in the header minicart like the below imageenter image description here

  • Hi, have you found solution to above ? as I am Looking for the same. – Arun Karnawat Jul 25 '16 at 8:00
  • Yes arun.I will post my answer – Asha Jul 28 '16 at 7:03
  • thank you, I have figured it out, but if you can, I want $00 - 0 item to be printed by default if 0 product is in the cart. in Magento 2.1.0. Thank you – Arun Karnawat Jul 28 '16 at 8:20
0

I believe you will need to use AJAX along with the API unless there is already a function for this in the Magento/Checkout/Model... Find the minicart knockout js template for an example already in your code.

http://devdocs.magento.com/guides/v2.0/javascript-dev-guide/javascript/js_overview.html

http://devdocs.magento.com/guides/v2.0/extension-dev-guide/bk-extension-dev-guide.html

0

Please make a copy of minicart.phtml file in your theme (\app\design\frontend\yourpackage\yourtheme\Magento_Checkout\templates\cart\minicart.phtml) and add the below code in it

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

// @codingStandardsIgnoreFile

/** @var $block \Magento\Checkout\Block\Cart\Sidebar */
?>
<?php $helper = $this->helper('\Magento\Checkout\Helper\Cart');?>
<div data-block="minicart" class="minicart-wrapper">
    <a class="action showcart" href="<?php /* @escapeNotVerified */ echo $block->getShoppingCartUrl(); ?>"
       data-bind="scope: 'minicart_content'">
        <span class="text"><?php /* @escapeNotVerified */ echo __('Shopping Cart'); ?></span>
        <span class="counter qty empty"
              data-bind="css: { empty: cart().summary_count < 0 }, blockLoader: isLoading">
            <span class="ex-top-cart-subtotal">
            <!-- ko if: cart().summary_count -->
                <!-- ko if: cart().possible_onepage_checkout -->
                <!-- ko foreach: getRegion('subtotalContainer') -->
                    <!-- ko template: getTemplate() --><!-- /ko -->&nbsp;-&nbsp;
                <!-- /ko -->
                <!-- /ko -->
            <!-- /ko --></span>

            <span class="counter-label">
            <!-- ko ifnot: cart().summary_count -->
            &pound; <!-- ko i18n: ' 0.00 - 0 item ' --><!-- /ko -->
            <!-- /ko -->
            <!-- ko if: cart().summary_count -->
                <!-- ko text: cart().summary_count --><!-- /ko -->
                <!-- ko if: cart().summary_count == 1 -->
                <!-- ko i18n: 'item' --><!-- /ko -->
            <!-- /ko -->
            <!-- ko if: cart().summary_count > 1 -->
                <!-- ko i18n: 'items' --><!-- /ko -->
            <!-- /ko -->
            <!-- /ko -->

            <?php //echo "&pound; ".number_format($helper->getQuote()->getSubtotal(), 2, '.', '');?>
            </span>

        </span>
    </a>
    <?php if ($block->getIsNeedToDisplaySideBar()): ?>
        <div class="block block-minicart empty"
             data-role="dropdownDialog"
             data-mage-init='{"dropdownDialog":{
                "appendTo":"[data-block=minicart]",
                "triggerTarget":".showcart",
                "timeout": "2000",
                "closeOnMouseLeave": false,
                "closeOnEscape": true,
                "triggerClass":"active",
                "parentClass":"active",
                "buttons":[]}}'>
            <div id="minicart-content-wrapper" data-bind="scope: 'minicart_content'">
                <!-- ko template: getTemplate() --><!-- /ko -->
            </div>
        </div>
    <?php endif ?>
    <script>
        window.checkout = <?php /* @escapeNotVerified */ echo \Zend_Json::encode($block->getConfig()); ?>;
    </script>
    <script type="text/x-magento-init">
    {
        "[data-block='minicart']": {
            "Magento_Ui/js/core/app": <?php /* @escapeNotVerified */ echo $block->getJsLayout();?>
        },
        "*": {
            "Magento_Ui/js/block-loader": "<?php /* @escapeNotVerified */ echo $block->getViewFileUrl('images/loader-1.gif'); ?>"
        }
    }
    </script>
</div>
  • please explain what you changed.... – Philipp Sander Dec 16 '16 at 13:10
0

Go to this directory \app\design\frontend\yourpackage\yourtheme\Magento_Checkout\templates\cart\minicart.phtml

and overwrite with below code in minicart.phtml file.

<a class="action showcart" href="<?php /* @escapeNotVerified */ echo $block->getShoppingCartUrl(); ?>"
   data-bind="scope: 'minicart_content'">
    <span class="text"><?php /* @escapeNotVerified */ echo __('My Cart'); ?></span> 
    <span class="counter qty empty" data-bind="css: { empty: cart().summary_count == 0 }, css: { empty: !cart().summary_count }, blockLoader: isLoading">
        <span class="counter-number"> 

            <!-- ko if: !cart().summary_count -->
                <!-- ko i18n: '0 item' --><!-- /ko -->
            <!-- /ko --> 
            <!-- ko if: cart().summary_count >= 1 -->
                <!-- ko text: cart().summary_count --><!-- /ko --> 
                <!-- ko i18n: ' items' --><!-- /ko -->
            <!-- /ko -->  
        </span>  
        <span class="price-wrapper" data-bind="html: cart().subtotal_excl_tax"> </span> 
        <span class="price-custom-minicart">
        <!-- ko if: !cart().subtotal_excl_tax -->
            <!-- ko i18n: '€ 0.00' --><!-- /ko -->
            <!-- /ko -->
            </span>
        <span class="counter-label">
        <!-- ko if: cart().summary_count -->
            <!-- ko text: cart().summary_count --><!-- /ko -->
            <!-- ko i18n: 'items' --><!-- /ko -->
        <!-- /ko -->
        </span>
    </span>
</a>
0

Working code for me. Magento 2.2.4

<a class="action showcart" href="<?php /* @escapeNotVerified */ echo $block->getShoppingCartUrl(); ?>"
           data-bind="scope: 'minicart_content'">
        <span class="counter qty empty"
              data-bind="css: { empty: !!getCartParam('summary_count') == false }, blockLoader: isLoading">
            <span class="counter-number">
            <!-- ko ifnot: getCartParam('summary_count') -->
                <!-- ko text: '0' --><!-- /ko -->
            <!-- /ko -->
            <!-- ko if: getCartParam('summary_count') -->
                <!-- ko text: getCartParam('summary_count') --><!-- /ko -->
            <!-- /ko -->
            </span>
            <span class="counter-label">
            <!-- ko if: getCartParam('summary_count') -->
                <!-- ko text: getCartParam('summary_count') --><!-- /ko -->
                <!-- ko i18n: 'items' --><!-- /ko -->
            <!-- /ko -->
            </span>
        </span>

        <span class="text"><?php /* @escapeNotVerified */ echo __('My Cart'); ?></span>

        <span data-bind="html: getCartParam('subtotal')"></span>
            <!-- /ko -->
            <!-- ko if: getCartParam('summary_count') != 1 -->
                <!-- ko text: getCartParam('summary_count') --><!-- /ko -->
                <!-- ko i18n: 'items' --><!-- /ko -->
                <span data-bind="html: getCartParam('subtotal')"></span>
            <!-- /ko -->
        </span>

        </a>

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.