Magento 2 Checkout mini-cart need to show reward point phtml block
Question
I want to show Reward Point content(../vendor/magento/module-reward/view/frontend/layout/checkout_cart_index.xml
) :
<block class="Magento\Reward\Block\Tooltip\Checkout" name="reward.tooltip.checkout" template="tooltip.phtml">
<arguments>
<argument name="reward_type" xsi:type="string">Magento\Reward\Model\Action\OrderExtra</argument>
</arguments>
<action method="setWrapperClass">
<argument name="class" xsi:type="string">reward-checkout</argument>
</action>
<action method="setRewardMessage">
<argument translate="true" name="message" xsi:type="string">Check out now and earn %1 for this order.</argument>
</action>
<action method="setIsGuestNote">
<argument name="value" xsi:type="string">1</argument>
</action>
</block>
Into vendor/magento/module-checkout/view/frontend/web/template/minicart/content.html
to show content of reward point as below :
Solution
You have to override checkout module Customerdata/Cart.php file getSectionData() function in your custom module.
Pass new argument inside function return value,
public function getSectionData()
{
$totals = $this->getQuote()->getTotals();
$rewards = $this->layout->createBlock('Magento\Reward\Block\Tooltip\Checkout','reward.tooltip.checkout',
[
'data' => ['reward_type' => 'Magento\Reward\Model\Action\OrderExtra',
'rewardHelper' => 'Magento\Reward\Helper\Data',
'customerSession' => 'Magento\Customer\Model\Session',
'rewardInstance' => 'Magento\Reward\Model\Reward',
'storeManager' => 'Magento\Store\Model\StoreManager'
]
]);
$rewards->setWrapperClass('reward-checkout')->setRewardMessage("Check out now and earn %1 for this order.")->setIsGuestNote(1);
$rewards->setTemplate('Magento_Reward::tooltip.phtml');
return [
'summary_count' => $this->getSummaryCount(),
'subtotal' => isset($totals['subtotal'])
? $this->checkoutHelper->formatPrice($totals['subtotal']->getValue())
: 0,
'possible_onepage_checkout' => $this->isPossibleOnepageCheckout(),
'items' => $this->getRecentItems(),
'extra_actions' => $this->layout->createBlock('Magento\Catalog\Block\ShortcutButtons')->toHtml(),
'isGuestCheckoutAllowed' => $this->isGuestCheckoutAllowed(),
'rewards' => $rewards->toHtml(),
];
}
Inside your minicart.phtml
file set your span like,
<span data-bind="html: getCartParam('rewards')"></span>
Clear cache.
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange