Magento 1.9 – Get Last 3 Added Products from Cart

cartmagento-1.9mini-cart

How can i get last 3 added products of cart in magento.

I am using $session->getQuote()->getAllVisibleItems() for that.

Please Provide me if any other feasible solution

Best Answer

You can find answer by looking at getRecentItems method inside Mage_Checkout_Block_Cart_Sidebar class.

/**
 * Get array of last added items
 *
 * @param null $count
 * @return array
 */
public function getRecentItems($count = null)
{
    if (!$this->getSummaryCount()) {
        return array();
    }
    if ($count === null) {
        $count = $this->getItemCount();
    }
    return array_slice(array_reverse($this->getItems()), 0, $count);
}

This applies to current customer session.