php - Item disappearing from cart when logging in when Mage_Sales_Order_Quote is overridden not to
Magento version is 1.6.2.0. I have overriddenMage_Sales_Order_Quote
inapp/code/local
to not just increase quantity if thedesiger
option is set. I have a design system that a person can click a link in the product view and they are taken to the designer that we made, then the product is added pragmatically to cart.
I changed thegetItemByProduct
to the following:
public function getItemByProduct($product)
{
$_options = unserialize($product->getCustomOption('info_buyRequest')->getValue());
$_designs = $_options['options']['designer'];
foreach ($this->getAllItems() as $item) {
if ($item->representProduct($product)) {
$_itemOptions = unserialize($item->getProduct()->getCustomOption('info_buyRequest')->getValue());
if (!empty($_designs) && !empty($_itemOptions['options']['designer'])) { // consider detecting if this was a re-design
return false;
} else {
return $item;
}
}
}
return false;
}
Now, the functionality works as intended, except for the fact that if I am logged out and have items in the cart, when I log in the items are merged once again like default functionality used to be and not my override. Where else would I look to remove this? I have the "Save Cart to Database" setting enabled to make carts persistent, in case that is relevant.
Answer
Solution:
Create an Observer that listens to the event
sales_quote_merge_before
and clears the customer's saved cart:Create an Observer class at
/app/code/local/{namespace}/{yourmodule}/Model/Observer.php
Then, add the following to your /app/code/local/{namespace}/{yourmodule}/etc/config.xml file for the module: