客户端登录后不要合并购物车

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了客户端登录后不要合并购物车相关的知识,希望对你有一定的参考价值。

I’ve implemented something similar a couple of months ago. What we wanted was to prevent the cart from the old session from merging into the cart of the current session at the point when the customer login. If that describes what you want as well, then the way I did it was to overwrite Mage_Checkout_Model_Observer. The function loadCustomerQuote() in the observer observes the event customer_login and merges the current session quote with the last login quote object
  1. public function loadCustomerQuote()
  2. {
  3. $lastQid = Mage::getSingleton('checkout/session')->getQuoteId(); //quote id during session before login;
  4. if ($lastQid) { //before login session exists means cart has items
  5. $customerQuote = Mage::getModel('sales/quote')
  6. ->loadByCustomer(Mage::getSingleton('customer/session')->getCustomerId()); //the cart from last login
  7. //set it to the session before login and remove its items if any
  8. $customerQuote->setQuoteId($lastQid);
  9. $this->_removeAllItems($customerQuote);
  10.  
  11. } else { //no session before login, so empty the cart (current cart is the old cart)
  12. $quote = Mage::getModel('checkout/session')->getQuote();
  13. $this->_removeAllItems($quote);
  14. }
  15. }
  16.  
  17. /**
  18.   * iterate through quote and remove all items
  19.   *
  20.   * @return nothing
  21.   */
  22. protected function _removeAllItems($quote){
  23. //reset all custom attributes in the quote object here, eg:
  24. // $quote->setDestinationCity('');
  25.  
  26. foreach ($quote->getAllItems() as $item) {
  27. $item->isDeleted(true);
  28. if ($item->getHasChildren()) foreach ($item->getChildren() as $child) $child->isDeleted(true);
  29. }
  30. $quote->collectTotals()->save();
  31. } //_removeAllItems

以上是关于客户端登录后不要合并购物车的主要内容,如果未能解决你的问题,请参考以下文章

两个cookie的合并

Django电商网站--架构设计

请问一下淘宝购物车怎么结算

电商网站中添加商品到购物车功能模块2017.12.8

js 用户退出登录后购物车的内容还在,怎么解决,在线等急

淘宝商品放到购物车后,退出后关机,再登陆,商品还在吗?