1

我希望客户只在她的购物车中添加任意数量的单件商品。如果购物车已经有项目,则应将其删除,并将新添加的项目添加到 Opencart 2.x 中的购物车。

4

2 回答 2

1

打开系统/库/cart.php。你会发现以下功能。

public function add 

您可以在此功能中非常快速地运行删除查询。

于 2016-04-06T14:41:52.687 回答
0
public function add($product_id, $quantity = 1, $option = array(), $recurring_id = 0) { 
            $this->db->query("DELETE FROM  " . DB_PREFIX . "cart");
            $this->db->query("INSERT " . DB_PREFIX . "cart SET api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "', customer_id = '" . (int)$this->customer->getId() . "', session_id = '" . $this->db->escape($this->session->getId()) . "', product_id = '" . (int)$product_id . "', recurring_id = '" . (int)$recurring_id . "', `option` = '" . $this->db->escape(json_encode($option)) . "', quantity = '" . (int)$quantity . "', date_added = NOW()");

    }

这是完整的功能。

于 2019-06-22T19:11:16.747 回答