I have changed my checkout/cart/
page promo code to ajax
call so that it doesn't get reloaded, while on the success of that ajax call, I have to update the total price summary dynamically without reloading.
How to achieve that.
Need to update this(price summary) as soon as user apply the promo code, I am using ajax instead of reloading the page as it was happening earlier.
I referred some links,
define([
'jquery',
'Magento_Checkout/js/model/cart/totals-processor/default',
'Magento_Checkout/js/model/quote',
'OtherDependencies'
], function ($,totalsProvider, quote){
'use strict';
//Your code here
totalsProvider.estimateTotals(quote.shippingAddress());
});
How this code supposed to work as i dont have any shippingAddress here.
It just promo code and have to update the subtotal and order total with promo amount applied.
Best Answer
You can use an action like this:
It will update the cart totals from the cart page using default shipping address from the quote. If there was no address it is another issue.
I tested it in the browser console this way:
and all works fine on Magento 2.3.1 for not logged in customer.
PS: I know that my answer is not a complete, but maybe this information will be useful for you.
Update:
Here is simplified example:
Add our component which submit coupon code using AJAX and update cart totals:
Create js file with action (it is simplified, you need to write own logic):
Add simple block with template into layout for the cart page (simplified, you need to write own):
Create template (simplified too, write your own with desired design):
As a result after clean cache and redeploy static content you will see the
<div>
having a textSubmit Coupon
. When you have press it the coupon code entered in the default input will be sent to a server and after it will be processed the cart totals will be updated.PPS: As I said, it is just a very simplified scheme which serves to understand "how it will work". For your purposes you need to write something more complicated and well designed.