*/ class Mage_Checkout_Model_Observer { public function unsetAll() { Mage::getSingleton('checkout/session')->unsetAll(); } public function loadCustomerQuote() { // We do not want to merge items from last login into current cart. However, we want // to keep any items from the current session (before login) in the cart. try { $lastQid = Mage::getSingleton('checkout/session')->getQuoteId(); //quote id during session before login; if ($lastQid) { //cart before login has items $customerQuote = Mage::getModel('sales/quote') ->loadByCustomer(Mage::getSingleton('customer/session')->getCustomerId()); //the cart from last login //set it to the session before login and remove any old items from last login $customerQuote->setQuoteId($lastQid); $this->_removeAllItems($customerQuote); } else { //no session before login, so empty the cart (current cart is the old cart) $quote = Mage::getModel('checkout/session')->getQuote(); $this->_removeAllItems($quote); } } catch (Mage_Core_Exception $e) { Mage::getSingleton('checkout/session')->addError($e->getMessage()); } catch (Exception $e) { Mage::getSingleton('checkout/session')->addException( $e, Mage::helper('checkout')->__('Load customer quote error') ); } } /** * iterate through quote and remove all items * * @return nothing */ protected function _removeAllItems($quote){ //reset all custom attributes in the quote object here, eg: // $quote->setDestinationCity(''); foreach ($quote->getAllItems() as $item) { $item->isDeleted(true); if ($item->getHasChildren()) foreach ($item->getChildren() as $child) $child->isDeleted(true); } $quote->collectTotals()->save(); } //_removeAllItems public function salesQuoteSaveAfter($observer) { $quote = $observer->getEvent()->getQuote(); /* @var $quote Mage_Sales_Model_Quote */ if ($quote->getIsCheckoutCart()) { Mage::getSingleton('checkout/session')->getQuoteId($quote->getId()); } } }