First You need to call Sales Order item collection:
$collection = Mage::getResourceModel('sales/order_item_collection')
->addAttributeToSelect('*');
Then put relation with sales_flat_order for getting customer email,customer id
$collection->getSelect()->join( array('orders'=> sales_flat_order),
'orders.order_id=main_table.order_id',array('orders.customer_email','orders.customer_id'));
then get current customer id from session and filter by customer id using below code
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
$customer = Mage::getSingleton('customer/session')->getCustomer();
$customer->getId();
$collection->->addFieldToFilter('customer_id',$customer->getId())
}
Then get Product Id from collection:
foreach($collection as $EachItem){
$EachItem->getProductId();
}
Full code:
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
$collection = Mage::getResourceModel('sales/order_item_collection')
->addAttributeToSelect('*');
$collection->getSelect()->join( array('orders'=> sales_flat_order),
'orders.order_id=main_table.order_id',array('orders.customer_email','orders.customer_id'));
$customer = Mage::getSingleton('customer/session')->getCustomer();
$collection->addFieldToFilter('customer_id',$customer->getId());
foreach($collection as $EachItem){
$EachItem->getProductId();
}
}
Alternative solution:
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
$orders= Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('customer_id',Mage::getSingleton('customer/session')->getCustomer()->getId());
foreach($orders as $eachOrder){
$order = Mage::getModel("sales/order")->load($eachOrder->getId());
$items = $order->getAllVisibleItems();
foreach($items as $item):
echo $item->getProductId();
endforeach;
}
}