Apply bindings and subscribe on change of discount amount totals.totals() in Magento 2How Does Magento 2 Apply KnockoutJS BindingsMagento2 override admin js fileOneStepCheckout - display subtotals of tax classMagento 2: Initialize calendar widget inside payment uiComponentCan't get Customer Data on frontend in Magento 2Magento 2 - Change maximum order amountMagento 2.3 Can't view module's front end page output?How to create custom form in Magento 2.2.3How to send data from cart page(phtml) to checkout page(html) for each item in knockout Magento 2How to apply bindings and subscribe on change of discount amount totals.totals().items in Magento 2

What is this green alien supposed to be on the American covers of the "Hitchhiker's Guide to the Galaxy"?

Does a hash function have a Upper bound on input length?

Suggestions for how to track down the source of this force:source:push error?

How was Luke's prosthetic hand in Episode V filmed?

Making a Dataset that emulates `ls -tlra`?

Will copper pour help on my single-layer PCB?

When we are talking about black hole evaporation - what exactly happens?

Transistor power dissipation rating

A "Replace" sort problem. Basic but haunts me

What could make large expeditions ineffective for exploring territory full of dangers and valuable resources?

Extract the attribute names from a large number of Shapefiles

Evaluate the limit the following series

Why did my "seldom" get corrected?

Did Hitler say this quote about homeschooling?

Why isn't a binary file shown as 0s and 1s?

Who or what determines if a curse is valid or not?

I want light controlled by one switch, not two

Could a US citizen born through "birth tourism" become President?

Three Subway Escalators

Discontinuous Tube visualization

Why is the Intel 8086 CPU called a 16-bit CPU?

To what extent does asymmetric cryptography secure bitcoin transactions?

Project Euler # 25 The 1000 digit Fibonacci index

Should I work for free if client's requirement changed



Apply bindings and subscribe on change of discount amount totals.totals() in Magento 2


How Does Magento 2 Apply KnockoutJS BindingsMagento2 override admin js fileOneStepCheckout - display subtotals of tax classMagento 2: Initialize calendar widget inside payment uiComponentCan't get Customer Data on frontend in Magento 2Magento 2 - Change maximum order amountMagento 2.3 Can't view module's front end page output?How to create custom form in Magento 2.2.3How to send data from cart page(phtml) to checkout page(html) for each item in knockout Magento 2How to apply bindings and subscribe on change of discount amount totals.totals().items in Magento 2






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








3















in my checkout page when promo code is applied, I am updating a text using some calculation using knockoutjs



In my checkout page, on applying and removing promo code, it changes the discount key in totals.totals().items.
How to apply bindings and subscribe in knockoutjs,
so that I can call my function which I am calling from my HTML.




Magento_Checkout/web/template/summary/item/details.html




 <span class="tag-text">
<!-- ko if: getFinalSale($parent)-->
<u class="product-tag underline-bold-text checkout-final-sale" data-bind="text: getFinalSale($parent)"></u>
<!-- /ko -->
</span>


I have written above code in details.html



and my js is




Magento_Checkout/web/js/view/summary/item/details.js




knockout js



 define([
'uiComponent',
'ko',
'Magento_Checkout/js/model/totals'
], function (Component, ko, totals) {
'use strict';
var finalSaleData = window.checkoutConfig.items;

return Component.extend(
defaults:
template: 'Magento_Checkout/summary/item/details'
,
quoteItemData: quoteItemData,
finalSaleData: finalSaleData,

/**
* @param Object quoteItem
* @return String
*/

getItems: function(item_id)
var itemElement = null;
_.each(this.finalSaleData, function(element, index)
if (element.item_id == item_id)
itemElement = element;

);
return itemElement;
,
getFinalSale : function (quoteItem)
var item = this.getItems(quoteItem.item_id);
var temp_item = this.getTempItems(quoteItem.item_id);
var tagText = '';

if((((temp_item.price*temp_item.qty) - temp_item.discount_amount)/(item.base_old_price*temp_item.qty)) < 0.5)
var tagText = 'Final Sale';
else
if(item.base_old_price && temp_item.price)
// && item.price < item.price && item.base_old_price / item.price <= 0.5)
if(((item.base_old_price - temp_item.price)/item.base_old_price)>0.5)
var tagText = 'Final Sale';



return tagText;
,
);
);


I am using var finalSaleData = window.checkoutConfig.items in my function getFinalSale.



How to make getFinalSale function run every time when window.checkoutConfig.items data is changed without refreshing the page.



1) How can i call getFinalSale on the change of totals.totals().items



2) The issue I am passing the $parent from my HTML and when the totals.totals().items the discount amount is changed for each item after applying promo code then how will I pass this $parent(quoteItem) from the very same js.



How to solve that.



The problem is, this runs only when the page reloads.



How to make getFinalSale function run every time the user applies promo code without refreshing the page so that my HTML gets updated too.



Basically Final Sale text needs to be shown on the basis of that logic in js code in getFinalSale function.



And also, data-bind="text: getFinalSale($parent) i am calling this from HTML and I am using subscribe also but then how i will pass $parent parameter from subscribing so that getFinalSale runs when this.totals changes everytime after applying coupon.



initialize: function()
this._super();
this.totals.subscribe(function (data)
this.getFinalSale(data)
, this);
,


The data parameter is not same as $parent which i passed it from html.
and it breaks the js.










share|improve this question

















This question has an open bounty worth +50
reputation from summu ending ending at 2019-07-21 06:17:42Z">in 6 hours.


Looking for an answer drawing from credible and/or official sources.


Hey guys, help me with the issue of checkout any help would be highly appreciated
















  • Did you override this js?

    – Rohan Hapani
    Jul 15 at 6:00











  • yes vendor/magento/module-checkout/view/frontend/web/js/view/summary/item/details.js this was the vender file

    – summu
    Jul 15 at 6:09

















3















in my checkout page when promo code is applied, I am updating a text using some calculation using knockoutjs



In my checkout page, on applying and removing promo code, it changes the discount key in totals.totals().items.
How to apply bindings and subscribe in knockoutjs,
so that I can call my function which I am calling from my HTML.




Magento_Checkout/web/template/summary/item/details.html




 <span class="tag-text">
<!-- ko if: getFinalSale($parent)-->
<u class="product-tag underline-bold-text checkout-final-sale" data-bind="text: getFinalSale($parent)"></u>
<!-- /ko -->
</span>


I have written above code in details.html



and my js is




Magento_Checkout/web/js/view/summary/item/details.js




knockout js



 define([
'uiComponent',
'ko',
'Magento_Checkout/js/model/totals'
], function (Component, ko, totals) {
'use strict';
var finalSaleData = window.checkoutConfig.items;

return Component.extend(
defaults:
template: 'Magento_Checkout/summary/item/details'
,
quoteItemData: quoteItemData,
finalSaleData: finalSaleData,

/**
* @param Object quoteItem
* @return String
*/

getItems: function(item_id)
var itemElement = null;
_.each(this.finalSaleData, function(element, index)
if (element.item_id == item_id)
itemElement = element;

);
return itemElement;
,
getFinalSale : function (quoteItem)
var item = this.getItems(quoteItem.item_id);
var temp_item = this.getTempItems(quoteItem.item_id);
var tagText = '';

if((((temp_item.price*temp_item.qty) - temp_item.discount_amount)/(item.base_old_price*temp_item.qty)) < 0.5)
var tagText = 'Final Sale';
else
if(item.base_old_price && temp_item.price)
// && item.price < item.price && item.base_old_price / item.price <= 0.5)
if(((item.base_old_price - temp_item.price)/item.base_old_price)>0.5)
var tagText = 'Final Sale';



return tagText;
,
);
);


I am using var finalSaleData = window.checkoutConfig.items in my function getFinalSale.



How to make getFinalSale function run every time when window.checkoutConfig.items data is changed without refreshing the page.



1) How can i call getFinalSale on the change of totals.totals().items



2) The issue I am passing the $parent from my HTML and when the totals.totals().items the discount amount is changed for each item after applying promo code then how will I pass this $parent(quoteItem) from the very same js.



How to solve that.



The problem is, this runs only when the page reloads.



How to make getFinalSale function run every time the user applies promo code without refreshing the page so that my HTML gets updated too.



Basically Final Sale text needs to be shown on the basis of that logic in js code in getFinalSale function.



And also, data-bind="text: getFinalSale($parent) i am calling this from HTML and I am using subscribe also but then how i will pass $parent parameter from subscribing so that getFinalSale runs when this.totals changes everytime after applying coupon.



initialize: function()
this._super();
this.totals.subscribe(function (data)
this.getFinalSale(data)
, this);
,


The data parameter is not same as $parent which i passed it from html.
and it breaks the js.










share|improve this question

















This question has an open bounty worth +50
reputation from summu ending ending at 2019-07-21 06:17:42Z">in 6 hours.


Looking for an answer drawing from credible and/or official sources.


Hey guys, help me with the issue of checkout any help would be highly appreciated
















  • Did you override this js?

    – Rohan Hapani
    Jul 15 at 6:00











  • yes vendor/magento/module-checkout/view/frontend/web/js/view/summary/item/details.js this was the vender file

    – summu
    Jul 15 at 6:09













3












3








3


1






in my checkout page when promo code is applied, I am updating a text using some calculation using knockoutjs



In my checkout page, on applying and removing promo code, it changes the discount key in totals.totals().items.
How to apply bindings and subscribe in knockoutjs,
so that I can call my function which I am calling from my HTML.




Magento_Checkout/web/template/summary/item/details.html




 <span class="tag-text">
<!-- ko if: getFinalSale($parent)-->
<u class="product-tag underline-bold-text checkout-final-sale" data-bind="text: getFinalSale($parent)"></u>
<!-- /ko -->
</span>


I have written above code in details.html



and my js is




Magento_Checkout/web/js/view/summary/item/details.js




knockout js



 define([
'uiComponent',
'ko',
'Magento_Checkout/js/model/totals'
], function (Component, ko, totals) {
'use strict';
var finalSaleData = window.checkoutConfig.items;

return Component.extend(
defaults:
template: 'Magento_Checkout/summary/item/details'
,
quoteItemData: quoteItemData,
finalSaleData: finalSaleData,

/**
* @param Object quoteItem
* @return String
*/

getItems: function(item_id)
var itemElement = null;
_.each(this.finalSaleData, function(element, index)
if (element.item_id == item_id)
itemElement = element;

);
return itemElement;
,
getFinalSale : function (quoteItem)
var item = this.getItems(quoteItem.item_id);
var temp_item = this.getTempItems(quoteItem.item_id);
var tagText = '';

if((((temp_item.price*temp_item.qty) - temp_item.discount_amount)/(item.base_old_price*temp_item.qty)) < 0.5)
var tagText = 'Final Sale';
else
if(item.base_old_price && temp_item.price)
// && item.price < item.price && item.base_old_price / item.price <= 0.5)
if(((item.base_old_price - temp_item.price)/item.base_old_price)>0.5)
var tagText = 'Final Sale';



return tagText;
,
);
);


I am using var finalSaleData = window.checkoutConfig.items in my function getFinalSale.



How to make getFinalSale function run every time when window.checkoutConfig.items data is changed without refreshing the page.



1) How can i call getFinalSale on the change of totals.totals().items



2) The issue I am passing the $parent from my HTML and when the totals.totals().items the discount amount is changed for each item after applying promo code then how will I pass this $parent(quoteItem) from the very same js.



How to solve that.



The problem is, this runs only when the page reloads.



How to make getFinalSale function run every time the user applies promo code without refreshing the page so that my HTML gets updated too.



Basically Final Sale text needs to be shown on the basis of that logic in js code in getFinalSale function.



And also, data-bind="text: getFinalSale($parent) i am calling this from HTML and I am using subscribe also but then how i will pass $parent parameter from subscribing so that getFinalSale runs when this.totals changes everytime after applying coupon.



initialize: function()
this._super();
this.totals.subscribe(function (data)
this.getFinalSale(data)
, this);
,


The data parameter is not same as $parent which i passed it from html.
and it breaks the js.










share|improve this question
















in my checkout page when promo code is applied, I am updating a text using some calculation using knockoutjs



In my checkout page, on applying and removing promo code, it changes the discount key in totals.totals().items.
How to apply bindings and subscribe in knockoutjs,
so that I can call my function which I am calling from my HTML.




Magento_Checkout/web/template/summary/item/details.html




 <span class="tag-text">
<!-- ko if: getFinalSale($parent)-->
<u class="product-tag underline-bold-text checkout-final-sale" data-bind="text: getFinalSale($parent)"></u>
<!-- /ko -->
</span>


I have written above code in details.html



and my js is




Magento_Checkout/web/js/view/summary/item/details.js




knockout js



 define([
'uiComponent',
'ko',
'Magento_Checkout/js/model/totals'
], function (Component, ko, totals) {
'use strict';
var finalSaleData = window.checkoutConfig.items;

return Component.extend(
defaults:
template: 'Magento_Checkout/summary/item/details'
,
quoteItemData: quoteItemData,
finalSaleData: finalSaleData,

/**
* @param Object quoteItem
* @return String
*/

getItems: function(item_id)
var itemElement = null;
_.each(this.finalSaleData, function(element, index)
if (element.item_id == item_id)
itemElement = element;

);
return itemElement;
,
getFinalSale : function (quoteItem)
var item = this.getItems(quoteItem.item_id);
var temp_item = this.getTempItems(quoteItem.item_id);
var tagText = '';

if((((temp_item.price*temp_item.qty) - temp_item.discount_amount)/(item.base_old_price*temp_item.qty)) < 0.5)
var tagText = 'Final Sale';
else
if(item.base_old_price && temp_item.price)
// && item.price < item.price && item.base_old_price / item.price <= 0.5)
if(((item.base_old_price - temp_item.price)/item.base_old_price)>0.5)
var tagText = 'Final Sale';



return tagText;
,
);
);


I am using var finalSaleData = window.checkoutConfig.items in my function getFinalSale.



How to make getFinalSale function run every time when window.checkoutConfig.items data is changed without refreshing the page.



1) How can i call getFinalSale on the change of totals.totals().items



2) The issue I am passing the $parent from my HTML and when the totals.totals().items the discount amount is changed for each item after applying promo code then how will I pass this $parent(quoteItem) from the very same js.



How to solve that.



The problem is, this runs only when the page reloads.



How to make getFinalSale function run every time the user applies promo code without refreshing the page so that my HTML gets updated too.



Basically Final Sale text needs to be shown on the basis of that logic in js code in getFinalSale function.



And also, data-bind="text: getFinalSale($parent) i am calling this from HTML and I am using subscribe also but then how i will pass $parent parameter from subscribing so that getFinalSale runs when this.totals changes everytime after applying coupon.



initialize: function()
this._super();
this.totals.subscribe(function (data)
this.getFinalSale(data)
, this);
,


The data parameter is not same as $parent which i passed it from html.
and it breaks the js.







magento2 checkout cart knockoutjs coupon-codes






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 15 at 6:30







summu

















asked Jul 11 at 10:21









summusummu

1841 silver badge11 bronze badges




1841 silver badge11 bronze badges






This question has an open bounty worth +50
reputation from summu ending ending at 2019-07-21 06:17:42Z">in 6 hours.


Looking for an answer drawing from credible and/or official sources.


Hey guys, help me with the issue of checkout any help would be highly appreciated








This question has an open bounty worth +50
reputation from summu ending ending at 2019-07-21 06:17:42Z">in 6 hours.


Looking for an answer drawing from credible and/or official sources.


Hey guys, help me with the issue of checkout any help would be highly appreciated














  • Did you override this js?

    – Rohan Hapani
    Jul 15 at 6:00











  • yes vendor/magento/module-checkout/view/frontend/web/js/view/summary/item/details.js this was the vender file

    – summu
    Jul 15 at 6:09

















  • Did you override this js?

    – Rohan Hapani
    Jul 15 at 6:00











  • yes vendor/magento/module-checkout/view/frontend/web/js/view/summary/item/details.js this was the vender file

    – summu
    Jul 15 at 6:09
















Did you override this js?

– Rohan Hapani
Jul 15 at 6:00





Did you override this js?

– Rohan Hapani
Jul 15 at 6:00













yes vendor/magento/module-checkout/view/frontend/web/js/view/summary/item/details.js this was the vender file

– summu
Jul 15 at 6:09





yes vendor/magento/module-checkout/view/frontend/web/js/view/summary/item/details.js this was the vender file

– summu
Jul 15 at 6:09










2 Answers
2






active

oldest

votes


















0














Please check with below url. Its demo for windows.checkoutConfig.items



https://www.webnexs.com/blog/kb/include-variable-window-checkout-config-magento-checkout/



https://webkul.com/blog/update-cart-totals-by-js-on-checkout-page-magento2/



I hope its helpful to you.






share|improve this answer























  • Updated the question

    – summu
    Jul 15 at 6:13











  • have you checked in inspect element, when you update data than details.js execute every-time/

    – Anas Mansuri
    Jul 15 at 6:19











  • when I apply or remove coupon , totals.totals() still gives me old value and i get discount 0 when i apply for coupon, that means my function getFinalSale runs before the apply coupon thats why it gets the old values from totals.totals() and my logic doesnt work, and when i inspect totals.totals() after the apply coupon has finished, it then shows the latest discounted values

    – summu
    Jul 15 at 6:25











  • Updated the question as well

    – summu
    Jul 15 at 6:30











  • apply with this lines cartCache.set('totals',null); defaultTotal.estimateTotals();

    – Anas Mansuri
    Jul 15 at 6:35



















0














So the solution was simple,
To make getFinalSale function run every time data of price/discount changes



Use totals: quote.getTotals()



 return Component.extend(
defaults:
template: 'Magento_Checkout/summary/item/details'
,
quoteItemData: quoteItemData,
finalSaleData: finalSaleData,
saleData: saleData,
totals: quote.getTotals(),
/**
* @param Object quoteItem
* @return String
*/


getFinalSale : function (quoteItem)
var tagText = '';
var price = 0;
if(this.totals())
var item = null;
_.each(this.finalSaleData , function(element, index)
if (element.item_id == quoteItem.item_id)
item = element;

);

var temp_item = null;
_.each(this.totals().items, function(element, index)
if (element.item_id == quoteItem.item_id)
temp_item = element;

);

var discount = this.getDiscountPureValue(quoteItem.item_id);

if ((((temp_item.price * temp_item.qty) - discount) / (item.base_old_price * temp_item.qty)) < 0.5)
price = totals.getSegment('grand_total').value;
else
if (item.base_old_price && temp_item.price)
if (((item.base_old_price - temp_item.price) / item.base_old_price) > 0.5)
price = totals.getSegment('grand_total').value




return price;
,
);


and also to get the updated discount value always



Use this.totals() instead of this.totals which was the mistake, I was doing.



 getDiscountPureValue: function (id) 
var price = 0;
var item = null;
if (this.totals() && this.totals().items)
_.each(this.totals().items , function(element, index)
if (element.item_id == id)
item = element;

);
price = item.discount_amount;


return price;
,





share|improve this answer

























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "479"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f281711%2fapply-bindings-and-subscribe-on-change-of-discount-amount-totals-totals-in-mag%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Please check with below url. Its demo for windows.checkoutConfig.items



    https://www.webnexs.com/blog/kb/include-variable-window-checkout-config-magento-checkout/



    https://webkul.com/blog/update-cart-totals-by-js-on-checkout-page-magento2/



    I hope its helpful to you.






    share|improve this answer























    • Updated the question

      – summu
      Jul 15 at 6:13











    • have you checked in inspect element, when you update data than details.js execute every-time/

      – Anas Mansuri
      Jul 15 at 6:19











    • when I apply or remove coupon , totals.totals() still gives me old value and i get discount 0 when i apply for coupon, that means my function getFinalSale runs before the apply coupon thats why it gets the old values from totals.totals() and my logic doesnt work, and when i inspect totals.totals() after the apply coupon has finished, it then shows the latest discounted values

      – summu
      Jul 15 at 6:25











    • Updated the question as well

      – summu
      Jul 15 at 6:30











    • apply with this lines cartCache.set('totals',null); defaultTotal.estimateTotals();

      – Anas Mansuri
      Jul 15 at 6:35
















    0














    Please check with below url. Its demo for windows.checkoutConfig.items



    https://www.webnexs.com/blog/kb/include-variable-window-checkout-config-magento-checkout/



    https://webkul.com/blog/update-cart-totals-by-js-on-checkout-page-magento2/



    I hope its helpful to you.






    share|improve this answer























    • Updated the question

      – summu
      Jul 15 at 6:13











    • have you checked in inspect element, when you update data than details.js execute every-time/

      – Anas Mansuri
      Jul 15 at 6:19











    • when I apply or remove coupon , totals.totals() still gives me old value and i get discount 0 when i apply for coupon, that means my function getFinalSale runs before the apply coupon thats why it gets the old values from totals.totals() and my logic doesnt work, and when i inspect totals.totals() after the apply coupon has finished, it then shows the latest discounted values

      – summu
      Jul 15 at 6:25











    • Updated the question as well

      – summu
      Jul 15 at 6:30











    • apply with this lines cartCache.set('totals',null); defaultTotal.estimateTotals();

      – Anas Mansuri
      Jul 15 at 6:35














    0












    0








    0







    Please check with below url. Its demo for windows.checkoutConfig.items



    https://www.webnexs.com/blog/kb/include-variable-window-checkout-config-magento-checkout/



    https://webkul.com/blog/update-cart-totals-by-js-on-checkout-page-magento2/



    I hope its helpful to you.






    share|improve this answer













    Please check with below url. Its demo for windows.checkoutConfig.items



    https://www.webnexs.com/blog/kb/include-variable-window-checkout-config-magento-checkout/



    https://webkul.com/blog/update-cart-totals-by-js-on-checkout-page-magento2/



    I hope its helpful to you.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jul 15 at 5:47









    Anas MansuriAnas Mansuri

    9841 silver badge16 bronze badges




    9841 silver badge16 bronze badges












    • Updated the question

      – summu
      Jul 15 at 6:13











    • have you checked in inspect element, when you update data than details.js execute every-time/

      – Anas Mansuri
      Jul 15 at 6:19











    • when I apply or remove coupon , totals.totals() still gives me old value and i get discount 0 when i apply for coupon, that means my function getFinalSale runs before the apply coupon thats why it gets the old values from totals.totals() and my logic doesnt work, and when i inspect totals.totals() after the apply coupon has finished, it then shows the latest discounted values

      – summu
      Jul 15 at 6:25











    • Updated the question as well

      – summu
      Jul 15 at 6:30











    • apply with this lines cartCache.set('totals',null); defaultTotal.estimateTotals();

      – Anas Mansuri
      Jul 15 at 6:35


















    • Updated the question

      – summu
      Jul 15 at 6:13











    • have you checked in inspect element, when you update data than details.js execute every-time/

      – Anas Mansuri
      Jul 15 at 6:19











    • when I apply or remove coupon , totals.totals() still gives me old value and i get discount 0 when i apply for coupon, that means my function getFinalSale runs before the apply coupon thats why it gets the old values from totals.totals() and my logic doesnt work, and when i inspect totals.totals() after the apply coupon has finished, it then shows the latest discounted values

      – summu
      Jul 15 at 6:25











    • Updated the question as well

      – summu
      Jul 15 at 6:30











    • apply with this lines cartCache.set('totals',null); defaultTotal.estimateTotals();

      – Anas Mansuri
      Jul 15 at 6:35

















    Updated the question

    – summu
    Jul 15 at 6:13





    Updated the question

    – summu
    Jul 15 at 6:13













    have you checked in inspect element, when you update data than details.js execute every-time/

    – Anas Mansuri
    Jul 15 at 6:19





    have you checked in inspect element, when you update data than details.js execute every-time/

    – Anas Mansuri
    Jul 15 at 6:19













    when I apply or remove coupon , totals.totals() still gives me old value and i get discount 0 when i apply for coupon, that means my function getFinalSale runs before the apply coupon thats why it gets the old values from totals.totals() and my logic doesnt work, and when i inspect totals.totals() after the apply coupon has finished, it then shows the latest discounted values

    – summu
    Jul 15 at 6:25





    when I apply or remove coupon , totals.totals() still gives me old value and i get discount 0 when i apply for coupon, that means my function getFinalSale runs before the apply coupon thats why it gets the old values from totals.totals() and my logic doesnt work, and when i inspect totals.totals() after the apply coupon has finished, it then shows the latest discounted values

    – summu
    Jul 15 at 6:25













    Updated the question as well

    – summu
    Jul 15 at 6:30





    Updated the question as well

    – summu
    Jul 15 at 6:30













    apply with this lines cartCache.set('totals',null); defaultTotal.estimateTotals();

    – Anas Mansuri
    Jul 15 at 6:35






    apply with this lines cartCache.set('totals',null); defaultTotal.estimateTotals();

    – Anas Mansuri
    Jul 15 at 6:35














    0














    So the solution was simple,
    To make getFinalSale function run every time data of price/discount changes



    Use totals: quote.getTotals()



     return Component.extend(
    defaults:
    template: 'Magento_Checkout/summary/item/details'
    ,
    quoteItemData: quoteItemData,
    finalSaleData: finalSaleData,
    saleData: saleData,
    totals: quote.getTotals(),
    /**
    * @param Object quoteItem
    * @return String
    */


    getFinalSale : function (quoteItem)
    var tagText = '';
    var price = 0;
    if(this.totals())
    var item = null;
    _.each(this.finalSaleData , function(element, index)
    if (element.item_id == quoteItem.item_id)
    item = element;

    );

    var temp_item = null;
    _.each(this.totals().items, function(element, index)
    if (element.item_id == quoteItem.item_id)
    temp_item = element;

    );

    var discount = this.getDiscountPureValue(quoteItem.item_id);

    if ((((temp_item.price * temp_item.qty) - discount) / (item.base_old_price * temp_item.qty)) < 0.5)
    price = totals.getSegment('grand_total').value;
    else
    if (item.base_old_price && temp_item.price)
    if (((item.base_old_price - temp_item.price) / item.base_old_price) > 0.5)
    price = totals.getSegment('grand_total').value




    return price;
    ,
    );


    and also to get the updated discount value always



    Use this.totals() instead of this.totals which was the mistake, I was doing.



     getDiscountPureValue: function (id) 
    var price = 0;
    var item = null;
    if (this.totals() && this.totals().items)
    _.each(this.totals().items , function(element, index)
    if (element.item_id == id)
    item = element;

    );
    price = item.discount_amount;


    return price;
    ,





    share|improve this answer



























      0














      So the solution was simple,
      To make getFinalSale function run every time data of price/discount changes



      Use totals: quote.getTotals()



       return Component.extend(
      defaults:
      template: 'Magento_Checkout/summary/item/details'
      ,
      quoteItemData: quoteItemData,
      finalSaleData: finalSaleData,
      saleData: saleData,
      totals: quote.getTotals(),
      /**
      * @param Object quoteItem
      * @return String
      */


      getFinalSale : function (quoteItem)
      var tagText = '';
      var price = 0;
      if(this.totals())
      var item = null;
      _.each(this.finalSaleData , function(element, index)
      if (element.item_id == quoteItem.item_id)
      item = element;

      );

      var temp_item = null;
      _.each(this.totals().items, function(element, index)
      if (element.item_id == quoteItem.item_id)
      temp_item = element;

      );

      var discount = this.getDiscountPureValue(quoteItem.item_id);

      if ((((temp_item.price * temp_item.qty) - discount) / (item.base_old_price * temp_item.qty)) < 0.5)
      price = totals.getSegment('grand_total').value;
      else
      if (item.base_old_price && temp_item.price)
      if (((item.base_old_price - temp_item.price) / item.base_old_price) > 0.5)
      price = totals.getSegment('grand_total').value




      return price;
      ,
      );


      and also to get the updated discount value always



      Use this.totals() instead of this.totals which was the mistake, I was doing.



       getDiscountPureValue: function (id) 
      var price = 0;
      var item = null;
      if (this.totals() && this.totals().items)
      _.each(this.totals().items , function(element, index)
      if (element.item_id == id)
      item = element;

      );
      price = item.discount_amount;


      return price;
      ,





      share|improve this answer

























        0












        0








        0







        So the solution was simple,
        To make getFinalSale function run every time data of price/discount changes



        Use totals: quote.getTotals()



         return Component.extend(
        defaults:
        template: 'Magento_Checkout/summary/item/details'
        ,
        quoteItemData: quoteItemData,
        finalSaleData: finalSaleData,
        saleData: saleData,
        totals: quote.getTotals(),
        /**
        * @param Object quoteItem
        * @return String
        */


        getFinalSale : function (quoteItem)
        var tagText = '';
        var price = 0;
        if(this.totals())
        var item = null;
        _.each(this.finalSaleData , function(element, index)
        if (element.item_id == quoteItem.item_id)
        item = element;

        );

        var temp_item = null;
        _.each(this.totals().items, function(element, index)
        if (element.item_id == quoteItem.item_id)
        temp_item = element;

        );

        var discount = this.getDiscountPureValue(quoteItem.item_id);

        if ((((temp_item.price * temp_item.qty) - discount) / (item.base_old_price * temp_item.qty)) < 0.5)
        price = totals.getSegment('grand_total').value;
        else
        if (item.base_old_price && temp_item.price)
        if (((item.base_old_price - temp_item.price) / item.base_old_price) > 0.5)
        price = totals.getSegment('grand_total').value




        return price;
        ,
        );


        and also to get the updated discount value always



        Use this.totals() instead of this.totals which was the mistake, I was doing.



         getDiscountPureValue: function (id) 
        var price = 0;
        var item = null;
        if (this.totals() && this.totals().items)
        _.each(this.totals().items , function(element, index)
        if (element.item_id == id)
        item = element;

        );
        price = item.discount_amount;


        return price;
        ,





        share|improve this answer













        So the solution was simple,
        To make getFinalSale function run every time data of price/discount changes



        Use totals: quote.getTotals()



         return Component.extend(
        defaults:
        template: 'Magento_Checkout/summary/item/details'
        ,
        quoteItemData: quoteItemData,
        finalSaleData: finalSaleData,
        saleData: saleData,
        totals: quote.getTotals(),
        /**
        * @param Object quoteItem
        * @return String
        */


        getFinalSale : function (quoteItem)
        var tagText = '';
        var price = 0;
        if(this.totals())
        var item = null;
        _.each(this.finalSaleData , function(element, index)
        if (element.item_id == quoteItem.item_id)
        item = element;

        );

        var temp_item = null;
        _.each(this.totals().items, function(element, index)
        if (element.item_id == quoteItem.item_id)
        temp_item = element;

        );

        var discount = this.getDiscountPureValue(quoteItem.item_id);

        if ((((temp_item.price * temp_item.qty) - discount) / (item.base_old_price * temp_item.qty)) < 0.5)
        price = totals.getSegment('grand_total').value;
        else
        if (item.base_old_price && temp_item.price)
        if (((item.base_old_price - temp_item.price) / item.base_old_price) > 0.5)
        price = totals.getSegment('grand_total').value




        return price;
        ,
        );


        and also to get the updated discount value always



        Use this.totals() instead of this.totals which was the mistake, I was doing.



         getDiscountPureValue: function (id) 
        var price = 0;
        var item = null;
        if (this.totals() && this.totals().items)
        _.each(this.totals().items , function(element, index)
        if (element.item_id == id)
        item = element;

        );
        price = item.discount_amount;


        return price;
        ,






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 2 days ago









        summusummu

        1841 silver badge11 bronze badges




        1841 silver badge11 bronze badges



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f281711%2fapply-bindings-and-subscribe-on-change-of-discount-amount-totals-totals-in-mag%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Grendel Contents Story Scholarship Depictions Notes References Navigation menu10.1093/notesj/gjn112Berserkeree

            Area configuration aggregation error after install Porto themeMagento 2.1 CE Installed but front/backend not loading/workingCSS not loading on page within Magento 2 pageCannot install module in Magento 2no commands defined in the “setup” namespace. in Magento2Magento 2: Static files are present but shows 404Why do i have to always run the commands to clean cache in Magento 2.1.8?Failure reason: 'Unable to unserialize value.'Error 500 after magento migrationIn production mode the site does not loadMagento 2 : Error 500 after installing

            Middle Expansion Olielle Resaix Definition: Uttering songs of triumph shouting with joy triumphant exulting Sejunction Journal 붙다 달 고급 품목 외출 The stretch trades the screeching tin. Definition: The act of speaking with a drawl a drawl Cough Sand Definition: An uproar a quarrel a noisy outbreak Shake Iron Publicize Horse House Baby 사과 Resaix Flaggy Jelly Temporary Unequaled Puppet A drop in the bucket Shrew 성격 회원 성질 미팅 The burn frames the tacky quality. Materialistic The smoke reduces the way. Yammoe Nondescript Cheek 얼굴 배 약하다 날리다 타다 The illegal country shows the iron. Help Rule Drearien Smoke Teaching Meaty Wasp Abraham Lincoln Jaws 진심 수리하다 Size Cork Idea Convert Think Lark John Lennon 거울 청소 군 추천하다 아이스크림