如何在添加产品前清空篮子 - 打开购物车

时间:2014-04-25 23:42:28

标签: opencart

点击此链接: Opencart: Adding Buy Now Button in Opencart Product Page

我在页面上添加了以下脚本:

 $('#button-cart-buy').bind('click', function() {
                $.ajax({
                    url: 'index.php?route=checkout/cart/add',
                    type: 'post',
                    data: $('.product-info input[type=\'text\'], .product-info input[type=\'hidden\'], .product-info input[type=\'radio\']:checked, .product-info input[type=\'checkbox\']:checked, .product-info select, .product-info textarea'),
                    dataType: 'json',
                    success: function(json) {
                        $('.success, .warning, .attention, information, .error').remove();

                        if (json['error']) {
                            if (json['error']['option']) {
                                for (i in json['error']['option']) {
                                    $('#option-' + i).after('<span class="error">' + json['error']['option'][i] + '</span>');
                                }
                            }

                            if (json['error']['profile']) {
                                $('select[name="profile_id"]').after('<span class="error">' + json['error']['profile'] + '</span>');
                            }
                        } 

                        if (json['success']) {window.location='<?php echo $this->url->link('checkout/checkout', '', 'SSL'); ?>'; 
                        }

                    }
                });
            });

但是,我想在添加相关产品之前清空购物车。

有谁知道怎么做或有任何提示?

1 个答案:

答案 0 :(得分:2)

最简单的方法是编辑购物车类/system/library/cart.php

找到这一行(从1.5.5.1安装 - 任何其他版本可能略有不同,但不太可能有重大差异)

public function add($product_id, $qty = 1, $option = array()) {

在它之后的新行上添加

$this->cart->clear();

并保存。请注意,这允许客户在购物车中添加大于1的数量,只要它是相同的产品

相关问题