I am trying to get the ID of the product that was most recently added to a user’s cart. A quick google search revealed this function 

```
Mage::getSingleton('checkout/session')->getLastAddedProductId(true);

```

which is also used in Mage\_Checkout\_Block\_Cart\_Crosssell. When I try calling the function in my own controller however, it returns nothing.
I have tried to instantiate a core session via 

```
Mage::getSingleton('core/session', array('name'=>'frontend'))

```

however this approach does not seem to work. I also tried to create the Crossell block and making the protected method that wraps around `getLastAddedProductId` function public however that returns null just like it does when I try calling it on its own.

Is there something I have to call or instantiate in order to use this function? Here’s my source listing for reference.

```
class Mymodule_Addcartaftermath_ItemaddedController extends Mage_Core_Controller_Front_Action {
    public function generatemessageAction() {
        $parameters = $this->getRequest()->getParams();
        if (isset($parameters['ajax_call'])) {
            $latest_item_id = Mage::getSingleton('checkout/session')->getLastAddedProductId(true);
            $response = array('response' => $latest_item_id);
            echo json_encode($response);
        } else {
            $this->_redirect('/');
        }
    }
}

```

I tried poking through the source code, particularly the checkout/model/session.php file in the core and I cannot seem to find the definition of the function. I also looked at it’s parent’s class definition but could not find it there either.

If this method is not available to me is there another way of retrieving the most recent item added? I know that the items are added sequentially and I could perhaps just get the last item of the list of items from the cart however this would not work in the case where the user adds the same item to the cart essentially increasing the quantity rather than actual item itself (e.g. the user adds a laptop the cart when there already is one)