2017-01-24 69 views
0

我的客戶正在使用Opencart v2.1.0.2。問題是,當我從購物車中移除單個物品時,所有其他物品也會被移除。是的,它使用自定義模板和這裏的,對於刪除函數調用行:從opencart購物車中刪除一個項目會刪除所有內容

<td class="text-center"><button type="button" onclick="cart.remove('<?php echo $product['cart_id']; ?>');" title="<?php echo $button_remove; ?>" class="btn btn-danger btn-xs"><i class="fa fa-times"></i></button></td> 

我還需要找出的js單擊此按鈕時,文件被調用。如果它會幫助,這個我覺得這是從購物車中刪除項目時Opencart的運行的cart.php庫中的函數:

public function remove($cart_id) { 
    $this->db->query("DELETE FROM " . DB_PREFIX . "cart WHERE cart_id = '" . (int)$cart_id . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "'"); 
} 

回答

0
DELETE FROM 

消除一切。它缺少它試圖刪除的產品ID。

WHERE僅指定:cart_id,customer_id和session_id - 因此此查詢將刪除與該條件匹配的所有內容。它並沒有對特定產品進行研究,因此它將全部採用。

不知道什麼變量,它使用的產品ID,一個適當的查詢會是這樣的:

public function remove($cart_id) { 
     $this->db->query("DELETE '".(int)$this->request->post['product_id']."' FROM " . DB_PREFIX . "cart WHERE cart_id = '" . (int)$cart_id . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "'"); 
} 

(int)$this->request->get['product_id']是對於大多數產品ID調用$ _GET請求。 還有一個例子可以是: (int)$this->request->post['product_id']爲$ _ POST調用

模板也可以做類似$product_id等什麼變量及其使用後話了/ GET不工作檢查。

一旦你把查詢收緊了,javascript按鈕只能指定一個cart id(不是產品)。如果你想讓我的例子工作,請在那裏獲取你的產品ID。您需要傳遞product_id和cart_id;否則,如果沒有cart_id,如果其他購物者同時擁有相同的物品,則刪除它的一個人將爲其刪除所有物品。

相關問題