I have added a custom discount and added a discount within the sidebar section, The Order total is getting refreshed but my custom discount remains the same, How can we reload it?
checkout_index_index.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="checkout.root">
<arguments>
<argument name="jsLayout" xsi:type="array">
<item name="components" xsi:type="array">
<item name="checkout" xsi:type="array">
<item name="children" xsi:type="array">
<item name="steps" xsi:type="array">
<item name="children" xsi:type="array">
<item name="billing-step" xsi:type="array">
<item name="children" xsi:type="array">
<item name="payment" xsi:type="array">
<item name="children" xsi:type="array">
<item name="beforeMethods" xsi:type="array">
<item name="children" xsi:type="array">
<item name="lms-rewardpoint" xsi:type="array">
<item name="component" xsi:type="string">Geekay_Rewardpoint/js/checkout/lms</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
<item name="sidebar" xsi:type="array">
<item name="children" xsi:type="array">
<item name="summary" xsi:type="array">
<item name="children" xsi:type="array">
<item name="totals" xsi:type="array">
<item name="children" xsi:type="array">
<item name="custom_discount" xsi:type="array">
<item name="component" xsi:type="string">Geekay_Rewardpoint/js/view/checkout/summary/lmsusedpoint</item>
<item name="sortOrder" xsi:type="string">20</item>
<item name="config" xsi:type="array">
<item name="custom_discount" xsi:type="string" translate="true">Used Points</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</argument>
</arguments>
</referenceBlock>
</body>
</page>
Js Teamplate:
<!-- ko if: getCustomDiscount() -->
<tr class="totals customdiscount excl">
<th class="mark" colspan="1" scope="row" data-bind="text: custom_discount"></th>
<td class="amount">
<span class="price" data-bind="text: getCustomDiscount(), attr: {'data-th': custom_discount}"></span>
</td>
</tr>
<tr>
<td><button data-bind="click: removePoints">Remove Geekay XP</button></td>
</tr>
<!-- /ko -->
Js file
define(
[
'ko',
'jquery',
'uiComponent',
'mage/url'
],
function (ko, $, Component,url) {
'use strict';
return Component.extend({
defaults: {
template: 'Geekay_Rewardpoint/checkout/summary/lmsusedpoint'
},
getCustomDiscount: function(){
var amount = 0;
var ajaxUrl=BASE_URL+"rewardpoint/index/usedpoint";
$.ajax({
type: "POST",
dataType: 'json',
async:false,
url: ajaxUrl,
data: {points:0},
}).done(function (result){
if(result.status==200 && result.amount>0){
amount = result.symbol+result.amount;
}
});
return amount;
}
});
}
);
This is the second file from which I want to reload above discount template:
define(
[
'ko',
'jquery',
'uiComponent',
'mage/url',
'Magento_Checkout/js/action/get-totals',
'Magento_Checkout/js/action/get-payment-information',
],
function (ko, $, Component,url,getTotalsAction,getPaymentInformationAction) {
'use strict';
return Component.extend({
defaults: {
template: 'Geekay_Rewardpoint/checkout/lmspoint'
},
getCustomDiscount: function(){
var amount = 0;
var ajaxUrl=BASE_URL+"rewardpoint/index/amount";
$.ajax({
type: "POST",
dataType: 'json',
async:false,
url: ajaxUrl,
data: {points:0},
}).done(function (result){
if(result.status==200 && result.amount>0){
amount = result.symbol+result.amount;
}
});
return amount;
},
submitLmsform : function() {
$('body').trigger('processStart');
let lms_point = $('#lms_point').val();
if(lms_point<1){
$('.lms_point_message').text("Please enter valid Point");
$('#lms_point').val('').trigger("change");
setTimeout(function(){ $('.lms_point_message').text("");},5000);
}else{
var linkUrls = url.build('rewardpoint/index/apply');
$.ajax({
url: linkUrls,
showLoader: true,
data: {lms_point:lms_point},
type: "POST",
dataType: 'json'
}).done(function (data) {
if(data.status=='success'){
var deferred = $.Deferred();
getTotalsAction([], deferred);
getPaymentInformationAction(deferred);
// $('#lms_point').attr('disabled','disabled').trigger("change");
// $('#vstbtn').attr('disabled','disabled');
$('.lms_point_success').text(data.message);
setTimeout(function(){
$('.lms_point_success').text("");
},4000);
}else{
$('.lms_point_message').text(data.message);
$('#lms_point').val('').trigger("change");
setTimeout(function(){
$('.lms_point_message').text("");
},5000);
}
// location.reload();
});
}
$('body').trigger('processStop');
}
});
}
);