如何在Opencart中设置访问权限以仅向购物车添加/购买一件商品


How to set access to add/purchase only one item to the cart in Opencart?

我想让顾客只从我的商店购买一种产品。客户只能将一种产品添加到购物车中,数量也应该只有一个,但当前的 opencart 系统正在将多个产品添加到购物车中。如何在 Opencart 1.5.5 中创建这样的系统?

我使用此论坛帖子创建了系统:http://forum.opencart.com/viewtopic.php?t=28181

  1. 编辑:system/library/cart.php

  2. 找到:

    $this->会话>数据['购物车'][$key] += (int)$qty;

  3. 替换为:

    $this->会话>数据['购物车'][$key] = (int)$qty;

然后

  1. 编辑:system/library/cart.php

2a. 查找 (1.4.x):

如果 (!$options) {

2b. 查找 (1.5.x):

如果 (!$option) {

  1. 之前,添加:

$this->clear();

这将设置客户仅将一个产品添加到购物车。但是当您从购物车页面更新数量时,它将更新为给定数量。为了解决这个问题,我们应该更改代码/catalog/controller/checkout/cart.php

/catalog/controller/checkout/cart 的第 13 行找到if (!empty($this->request->post['quantity'])).php

替换现有的 forloop,如下所示。我的意思是将值 1 设置为在循环内$value。即使客户尝试更新购物车页面中的数量,它也会将数量重置为 1。

foreach ($this->request->post['quantity'] as $key => $value) { 
$value=1;                        
$this->cart->update($key, $value);
}