HARDIK SHAH
HARDIK SHAH

Reputation: 163

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

i want customer only add single item in her cart with any number of quantity. if cart already have item it's should be remove and newly added item add to cart in Opencart 2.x.

Upvotes: 1

Views: 622

Answers (2)

Pritam Parua
Pritam Parua

Reputation: 692

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

    }

This is complete function.

Upvotes: 0

Pritam Parua
Pritam Parua

Reputation: 692

open system/library/cart.php. You will find follwoing function.

public function add 

You can run delete query at very fast in this function.

Upvotes: 1

Related Questions