2016-10-12 8 views
3

ajaxを使用してカートマジェント2カートページの1つのアイテムの数量を変更したいと考えています。Magento 2 - ajax変更数量後のリロード合計カート

私はこのJavaScriptを追加しました:

$('.cart.item .qty').on({ 
    change: function() { 
     var post_url = $(this).attr('data-post-url'); 

     $.post(post_url, $(this).serialize(), function(data) { 
      $(".form-cart").replaceWith(data.cart_html); 
      $("#cart-totals").replaceWith(data.totals_html); 
      $("#cart-totals").trigger('contentUpdated'); 
     }, "json"); 
    } 
}); 

data.totals_htmlの値は、私は数量を変更した場合、合計成分量が更新されていない

<div id="cart-totals" class="cart-totals" data-bind="scope:'block-totals'"> 
<!-- ko template: getTemplate() --><!-- /ko --> 
<script type="text/x-magento-init"> 
     { 
      "#cart-totals": { 
       "Magento_Ui/js/core/app": {"components":{"block-totals":....} 
</script> 

あります..

誰でも、rの後に合計コンポーネントを動的に更新するアイデアがありますhtmlコードを置き換えますか?

あなたがカートにAJAX再ロードブロックの合計にこの方法を相談することができます

答えて

0

define([ 
    "jquery", 
    'Magento_Checkout/js/action/get-payment-information', 
    'Magento_Checkout/js/model/totals' 
], function($, getPaymentInformationAction, totals) { 
    $('.cart.item .qty').on({ 
     change: function() { 
      var post_url = $(this).attr('data-post-url'); 
      $.post(post_url, $(this).serialize(), function(data) { 
       //custom your update 
       $(".form-cart").replaceWith(data.cart_html); 
       $("#cart-totals").replaceWith(data.totals_html); 
       //reload block total 
       var deferred = $.Deferred(); 
       totals.isLoading(true); 
       getPaymentInformationAction(deferred); 
       $.when(deferred).done(function() { 
        totals.isLoading(false); 
       }); 
       //end 
      }, "json"); 
     } 
    }); 
}); 
関連する問題