javascript - 如何刷新页面并删除删除产品,当单击 opencart 标题下拉购物车中的删除按钮时

标签 javascript jquery opencart

当点击 opencart 中标题下拉购物车上的删除按钮时,我尝试刷新页面并删除购物车删除数据。我在 cart.tpl 上找到了位置,但是当我点击那个按钮时我找不到功能的位置。

onclick="cart.remove('<?php echo $product['key']; ?>');

然后我尝试使用 jquery 刷新页面

    <script type="text/javascript">
  jQuery(document).ready(function(){
    $('.dropdown-menu .text-center .btn-xs').click(function(){
      location.reload(); 
    });

  });  
</script>

它刷新页面但不删除购物车产品。

最佳答案

打开文件 catalog/view/javascript/common.js。转到 第 200 行

改变这个

'remove': function(key) {
        $.ajax({
            url: 'index.php?route=checkout/cart/remove',
            type: 'post',
            data: 'key=' + key,
            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('<span id="cart-total"><i class="fa fa-shopping-cart"></i> ' + json['total'] + '</span>');
                }, 100);

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

为此

'remove': function(key) {
        $.ajax({
            url: 'index.php?route=checkout/cart/remove',
            type: 'post',
            data: 'key=' + key,
            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('<span id="cart-total"><i class="fa fa-shopping-cart"></i> ' + json['total'] + '</span>');
                }, 100);

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

关于javascript - 如何刷新页面并删除删除产品,当单击 opencart 标题下拉购物车中的删除按钮时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37561455/

相关文章:

javascript - 如何在 Javascript/Node 中的异步函数上调用 Await 后超时

c# - 在 MVC 4 的部分 View 中使用 PagedList 在导航 'paged' 页面时抛出 jQuery/JS

php - 如何使用 MySQL Group by 选择多条记录?

php - 如何使用 OTP(一次性密码)登录/注册 Opencart

opencart - Opencart 系统/修改文件夹功能如何?

javascript - 在 JavaScript 中通过键从嵌套对象数组中查找对象

javascript - 如何检索已解析的 url

javascript - 单击页面任意位置时,下拉隐藏

javascript - 使用 DOM 创建父子元素

javascript - 尝试在 ajax 加载上显示 gif 时,Dojo "TypeError {stack: (...), message: "未定义不是函数"}"