Last active
June 10, 2019 11:54
-
-
Save magevision/e9a7bfadbbb8a9fe93096a31fb530a71 to your computer and use it in GitHub Desktop.
DisplayCartTotalToMiniCart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace MageVision\Blog45\Plugin\Checkout\CustomerData; | |
use Magento\Checkout\Model\Session as CheckoutSession; | |
use Magento\Checkout\Helper\Data as CheckoutHelper; | |
use Magento\Quote\Model\Quote; | |
class Cart | |
{ | |
/** | |
* @var CheckoutSession | |
*/ | |
protected $checkoutSession; | |
/** | |
* @var CheckoutHelper | |
*/ | |
protected $checkoutHelper; | |
/** | |
* @var Quote|null | |
*/ | |
protected $quote = null; | |
/** | |
* @param CheckoutSession $checkoutSession | |
* @param CheckoutHelper $checkoutHelper | |
*/ | |
public function __construct( | |
CheckoutSession $checkoutSession, | |
CheckoutHelper $checkoutHelper | |
) { | |
$this->checkoutSession = $checkoutSession; | |
$this->checkoutHelper = $checkoutHelper; | |
} | |
/** | |
* Add grand total to result | |
* | |
* @param \Magento\Checkout\CustomerData\Cart $subject | |
* @param array $result | |
* @return array | |
*/ | |
public function afterGetSectionData( | |
\Magento\Checkout\CustomerData\Cart $subject, | |
$result | |
) { | |
$totals = $this->getQuote()->getTotals(); | |
$result['grand_total'] = isset($totals['grand_total']) | |
? $this->checkoutHelper->formatPrice($totals['grand_total']->getValue()) | |
: 0; | |
return $result; | |
} | |
/** | |
* Get active quote | |
* | |
* @return Quote | |
*/ | |
protected function getQuote() | |
{ | |
if (null === $this->quote) { | |
$this->quote = $this->checkoutSession->getQuote(); | |
} | |
return $this->quote; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | |
<type name="Magento\Checkout\CustomerData\Cart"> | |
<plugin name="blog45_minicart_grand_total" type="MageVision\Blog45\Plugin\Checkout\CustomerData\Cart"/> | |
</type> | |
</config> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="grand-total"> | |
<span class="label"> | |
<!-- ko i18n: 'Cart Total :' --><!-- /ko --> | |
</span> | |
<div class="amount"> | |
<span class="price-wrapper" data-bind="html: cart().grand_total"></span> | |
</div> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- ko foreach: elems --> | |
<!-- ko template: getTemplate() --><!-- /ko --> | |
<!-- /ko --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment