Opencart 2.x 只在购物车中添加任意数量的单件商品

Opencart 2.x add only single item in cart with any quantity

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

打开 system/library/cart。php。您会发现以下分数。

public function add 

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

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()");

    }

这是完整的功能。