如果產品已經存在於購物車中,如何更新商品數量?如果產品存在,Codeigniter更新購物車
這裏是我的添加到購物車功能:
public function add() {
$product= $this->products_model->listProduct($this->input->post('id_product'));
$data = array(
'id' => $this->input->post('id_product'),
'qty' => $this->input->post('qty'),
'price' => $product->price,
'name' => $product->title );
$this->cart->insert($data);
redirect('product/'.$product->id.'/'.url_title($product->title, 'dash', TRUE));
}
有了這個功能,如果產品在購物車中存在,讓我們用8量說,如果我的1數量增加同樣的產品,它會是1而不是9.
在此先感謝。
嗨達米安皮爾西,感謝您的答覆。這實際上是一個錯字。我粘貼了這些代碼,並更改了一些變量名稱,以便在英語中更有意義,因爲它們是用其他語言編寫的。看起來有些保持不變。但功能實際上起作用。我需要知道的是如何檢查產品是否存在於購物車中。如果沒有,我運行'$ this-> cart-> insert()'如果它運行'$ this-> cart-> update()'。但是我想把所有的東西放在函數add()中,這樣當產品被添加到購物車時,我總是運行相同的函數。謝謝。 – AFRC 2011-06-17 08:02:01