opencart 2.2.0 中的空头购物车
Empty header cart in opencart 2.2.0
我正在尝试在我的 OC 网站的页眉中实现一个空的迷你购物车。我制作了一个 link 按钮并尝试合并一些代码来清除我的迷你购物车,但它不起作用。代码是这样的:
<a class="btn btn-primary" href="<? php header('Location: http://mysitelocation/cart') $this->cart->clear(); ?>">Clear the mini cart</a>
关于如何以不同方式执行此操作的任何建议,因为这不会清除我的购物车。谢谢
经过一番研究,我设法解决了这个问题。
按钮应该是这样的:
<a class="btn btn-primary" onclick="clearCart(); window.location.reload();" ><?php echo "Empty mini cart" ?></a></p>
它正在调用 clearCart() 函数,此函数应如下所示:
<script type="text/javascript">
function clearCart() {
$.ajax({
url: 'index.php?route=checkout/cart/clearcart',
dataType: 'json',
success: function(json) {
$('#cart-total').html(json['total']);
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');
}
}
});
}
</script>
此外,它在清除购物车后重新加载页面(这也在我上面的 link 按钮中调用。)我希望这对某人有所帮助。干杯!
我正在尝试在我的 OC 网站的页眉中实现一个空的迷你购物车。我制作了一个 link 按钮并尝试合并一些代码来清除我的迷你购物车,但它不起作用。代码是这样的:
<a class="btn btn-primary" href="<? php header('Location: http://mysitelocation/cart') $this->cart->clear(); ?>">Clear the mini cart</a>
关于如何以不同方式执行此操作的任何建议,因为这不会清除我的购物车。谢谢
经过一番研究,我设法解决了这个问题。
按钮应该是这样的:
<a class="btn btn-primary" onclick="clearCart(); window.location.reload();" ><?php echo "Empty mini cart" ?></a></p>
它正在调用 clearCart() 函数,此函数应如下所示:
<script type="text/javascript">
function clearCart() {
$.ajax({
url: 'index.php?route=checkout/cart/clearcart',
dataType: 'json',
success: function(json) {
$('#cart-total').html(json['total']);
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');
}
}
});
}
</script>
此外,它在清除购物车后重新加载页面(这也在我上面的 link 按钮中调用。)我希望这对某人有所帮助。干杯!