0

I tried updating the cart using JS and summary container is updating properly. But I want to update the quantity of the item. So basically I have added a custom button in checkout/cart page. When this button is click I add one product into the cart. Now this product is fix and the quantiity added per click is fix. Now everything is working just fine including the summary container. But I want to update the Quantity field in the form-cart container. But I don't know how to do that.

I found out that getTotalsAction contains the total that want but I don't know how to retrieve this result. I'm thinking of looping through the result to update the quantity value. How can I do this?

Note: I don't want a page refresh.

Below is my code

define([
    'jquery',
    'Magento_Checkout/js/action/get-totals',
    'Magento_Checkout/js/model/cart/cache',
    'Magento_Checkout/js/model/cart/totals-processor/default',
    'Magento_Checkout/js/model/quote',
    'Magento_Customer/js/customer-data',
    'jquery/ui'    
], function ($, getTotalsAction, cartCache, totalsProcessor, quote, customerData) {
'use strict';

 $.widget('mage.poundToCart', {
     _create: function () {          
       this.processAddCart();       
    },
    processAddCart: function(form) {
        formData = new FormData(form[0]);
        $.ajax({
            url: form.attr('action'),
            data: formData,
            type: 'post',
            dataType: 'json',
            cache: false,
            contentType: false,
            processData: false,
            success: function (res) {  
              var deferred = $.Deferred();
              getTotalsAction([], deferred); // <--- I want to retrieve this value
              return false;
            }
       });
    }
 });

How can I do this?

I tried this link but this does not apply in my situation as there is no validate response that I get. So I just want to refresh the cart form page like the image below

enter image description here

So basically I want to update the quantity field since adding the product is done via Ajax

1
  • I don't think even magento has written anything for the qty update, magento refresh the page Commented Feb 21, 2020 at 7:25

1 Answer 1

0

You can log the value inside this function in this way:

var deferredAction  = getTotalsAction([], deferred);
console.log(deferredAction);

then you have : enter image description here

Now you can use for example 'success' like this :

deferredAction.success(function(){
     // you can do whatever you want here
     //$('.ccfidelity').attr('disabled',false);
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.