簡體   English   中英

Opencart-購物車中的即時更新數量

[英]Opencart - Instant update quantity in cart

對於標准的opencart行為,將產品添加到購物車后,用戶需要手動單擊“更新”按鈕以進行數量更新。 有關示例,請訪問http://demo.opencart.com/ 但是,我想更改為當我更改數量時,購物車信息可以立即刷新。 我試過下面的代碼,但是不起作用:

  1. 對於商品目錄/視圖/主題/默認/模板/簽出/cart.tpl,我更新了:

按鈕type =“ submit” data-toggle =“工具提示” title =“” class =“ btn btn-primary”> i class =“ fa fa-refresh”> / button>

(不知道為什么我不能在上面的行中正確粘貼代碼。我刪除了一些<使其顯示)

<button type="button" data-toggle="tooltip" title="<?php echo $button_update; ?>" class="btn btn-primary" onchange="cart.update('<?php echo $product['key']; ?>', '<?php echo $product['quantity']; ?>');"><i class="fa fa-refresh"></i></button>
  1. 在catalog / view / javascript / common.js中

有功能

var cart = {
  //skip some lines for other function
    'update': function(key, quantity) {
        $.ajax({
            url: 'index.php?route=checkout/cart/edit',
            type: 'post',
            data: 'key=' + key + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1),
            dataType: 'json',
            beforeSend: function() {
                $('#cart > button').button('loading');
            },
            complete: function() {
                $('#cart > button').button('reset');
            },          
            success: function(json) {
                // Need to set timeout otherwise it wont update the total
                setTimeout(function () {
                    $('#cart > button').html('<img src="image/catalog/content/cart/quote-icon.png" alt="quote"><span class="badge badge-giftu rounded-x">' + json['totallines'] + '</span>');
                }, 100);

                if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') {
                    $('#cart > ul').load('index.php?route=common/cart/info ul li');
                } else {
                    $('#cart > ul').load('index.php?route=common/cart/info ul li');
                }
            }
        });
    },
}

我嘗試過在on.change函數下更改為cart.remove,它可以工作。 但是,它不適用於cart.udpate。 有誰知道觸發ajax更新問題的問題是什么?

我自己有這樣的問題解決了

舊代碼(我對它們進行了自定義):

<input type="text" name="quantity[<?php echo $product['key']; ?>]" value="<?php echo $product['quantity']; ?>" size="1" class="form-control"/>
<span class="input-group-btn">
<button type="submit" data-toggle="tooltip" title="<?php echo $button_update; ?>" class="btn btn-primary"><i class="fa fa-refresh"></i></button>
<button type="button" data-toggle="tooltip" title="<?php echo $button_remove; ?>" class="btn btn-danger"
        onclick="cart.remove('<?php echo $product['key']; ?>');"><i class="fa fa-times-circle"></i></button>

在輸入和刪除上查找新代碼(固定)(按鈕類型=“按鈕”,如果他也不起作用)

<input type="text" name="quantity[<?php echo $product['cart_id']; ?>]" value="<?php echo $product['quantity']; ?>" 
       size="1" class="form-control"/>
<span class="input-group-btn">
    <button type="submit" data-toggle="tooltip" title="<?php echo $button_update; ?>" 
            class="btn btn-primary"><i class="fa fa-refresh"></i></button>
    <button type="button" data-toggle="tooltip" title="<?php echo $button_remove; ?>" class="btn btn-danger"
            onclick="cart.remove('<?php echo $product['cart_id']; ?>');"><i class="fa fa-times-circle"></i></button>

存在一個問題,即錯誤地為字段指定了符號,因此有必要將密鑰放入cart_id

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM