I am running an observer on Magento 1.9 on the following event:
sales_quote_merge_after
This event occurs when a guest customer with items in their cart logs into their account. When doing this the quote item IDs are dropped from the current session and the products are re-added with new IDs. What I need to know (using an observer or otherwise), is what each quote item ID was before, and what it has changed into.
I have tried countless observers on the Mage_Sale_Model_Quote::addItem method, but Magento does not return the new quote item ID on any method I have seen.
In the observer above I have managed to make it pass the original quote and new quote into the observer, but there's no way of matching the quote item IDs.
I have tried adding the original quote item ID as an option to the quote item which works, but as soon as the merge is carried out the options are wiped!
$item->addOption(array(
'code' => 'original_quote_item_id',
'product' => $item->getProduct()->getId(),
'value' => $item->getId()
));
I'm left perplexed on where to try next – any advice or suggestions would be greatly appreciated!
Best Answer
So based on what you said I have now got a solution that I belive works 100% of the time and matched the items nicely.
When merging there are 3 things that can happen.
Because the for the first two possibilitys the item is in both the quotes I used the compare function to find when the items matched and populated the newIds and OriginalIds at that point.
We can then say if there was no match this item was not in the guest quote so just use the newId as there was no originalId.