1

On checkout page I want subtotal, shipping and grand total in both "Shipping" and "Payment" steps.

I have followed this https://magento.stackexchange.com/a/235329/31910 :

In view/frontend/requirejs-config.js:

var config = { config: { mixins: { 'Magento_Checkout/js/view/summary/abstract-total': { 'Vendor_Module/js/abstract-total-mixin': true } } } }; 

In view/frontend/web/js/abstract-total-mixin.js:

define([], function () { "use strict"; return function (target) { return target.extend({ /** * @return {*} */ isFullMode: function () { if (!this.getTotals()) { return false; } return true; } }); } }); 

After this I have got Shipping amount and Grand total, but there is no subtotal appearing.
enter image description here

My question is, How can I show subtotal in checkout?

1 Answer 1

0

I have create the custom module and get the subtotal value Please check code hope help you,

Mage/Subtotal/Block/Checkout/Quoteinfo.php

<?php namespace Mage\Subtotal\Block\Checkout; class Quoteinfo extends \Magento\Framework\View\Element\Template { public function __construct( \Magento\Framework\View\Element\Template\Context $context, \Magento\Checkout\Model\Session $checkoutSession, array $data = [] ) { parent::__construct($context, $data); $this->_checkoutSession = $checkoutSession; } public function getQuoteData() { $this->_checkoutSession->getQuote(); if (!$this->hasData('quote')) { $this->setData('quote', $this->_checkoutSession->getQuote()); } return $this->_getData('quote'); } } 

Mage/Subtotal/etc/module.xml

<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> <module name="Mage_Subtotal" setup_version="2.0.0"/> </config> 

Mage/Subtotal/view/frontend/layout/checkout_index_index.xml

<?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> <referenceContainer name="content"> <block class="Mage\Subtotal\Block\Checkout\Quoteinfo" before="" cacheable="false" template="Mage_Subtotal::checkout/quoteinfo.phtml"> </block> </referenceContainer> </body> </page> 

Set Your right position.

Mage/Subtotal/view/frontend/templates/checkout/quoteinfo.phtml

<?php $quote = $block->getQuoteData(); //Get subtotal and grand total of customer current cart ?> <div class="subtotal"> <?php echo __('Cart Subtotal'); ?> <?php echo $subTotal = $quote->getSubtotal(); ?> </div> 

Mage/Subtotal/registration.php

<?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Mage_Subtotal', __DIR__ ); 

Cart subtotal value move your right position

I hope help you

Thanks.

1
  • you code is good, it will show subtotal in content, but I don't want to show subtotal anywhere in content, instead I want to show subtotal at the top of totals block. Which is I guess magento default functionality, but it is not appearing on my website Commented Feb 12, 2020 at 5:18

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.