Question: 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!

Answer: 
Maybe you should observe also the `sales_quote_merge_before` event.  

use the same observer class, but a different method, and declare your observer class to be a singleton.  

Then, you can remember the ids from the quote before the merging is done.  

in the `sales_quote_merge_after` get again all the item ids in the cart and calculate the difference. You should get the newly added item ids.
Okay, in the end it's not perfect but I used two events:

**sales\_quote\_merge\_before** - in the observer I grabbed the old quote items

```
public function setOldQuoteIntoSession($observer)
{
    $this->_source = $observer->getEvent()->getSource();
}

```

**controller\_front\_send\_response\_after** - in the observer I grabbed the new quote items. This is one of the last events fired and at this stage the quote is updated saved.

```
public function updateQuoteItems($observer)
{
    if (isset($this->_source))
    {
        $oldQuote = $this->_source;
        $newQuote = Mage::getSingleton('checkout/session')->getQuote();

        // do code
    }
}

```

It's not perfect because I can't 100% match the old IDs with the new IDs - I'm literally doing it based on the product ID set against each quote item. I've exhausted every other possibility.

Magento, if you read this can please explain why we have to wait so long before we get quote IDs back from added items? I know we need to wait for setCartWasUpdated(true), but there must be something we can do.