2017-04-04 46 views
-1

我在Codeigniter中使用購物車會話。我的問題是買家註銷時,購物車會話被破壞。如何保留尚未處理的購物車數據,以便再次登錄的顧客返回?用戶註銷時有什麼方法可以保存購物車數據?

+0

我已經刪除了我的答案,因爲這不是正確的答案感到很抱歉我認爲[ShadowElf](http://stackoverflow.com/users/7821496/shadowelf)是正確的。來自CI的 –

+0

文檔:購物車庫已被刪除,不應使用。目前僅保留用於向後兼容。 https://www.codeigniter.com/userguide3/libraries/cart.html#shopping-cart-class – Vickel

回答

1

您必須在註銷時添加一個過程以將數據保存到數據庫中。

而且,當登錄時...從數據庫中取出並添加到購物車。

是唯一的解決方案,或者您必須重寫整個購物車代碼。

我的解決方案:數據庫車,和一個cookie :)所以如果你已經登錄與否沒有關係。你可以看到管理員在購物車中有什麼。

當你退出......你必須添加這樣的事情:

foreach ($this->cart->contents() as $items){ 
$this->db->from('temp_cart'); 
$this->db->set('id_user', LOGGED USER ID); 
$this->db->set('cart_row', json_encode($items)); 
$this->db->insert(); 
} 

,當你登錄

$this->db->select('*'); 
$this->db->from('temp_cart'); 
$this->db->where('id_user', LOGGED USER ID); 
$res=$this->db->get(); 
foreach($res->result_array() as $row{ 
    $row=json_decode($row, TRUE); 
    $this->cart->insert($row); 
} 

$this->db->from('temp_cart'); 
$this->db->where('id_user', LOGGED USER ID); 
$this->db->delete(); 
+0

嗯不真的明白,你能給我一些參考鏈接或教程? – devitamnda

相關問題