Search code examples
phpmagentoproductecommerce-sales

getProductId from an order


I am new to Magento, so I am really confused. I need some help with the following: I am trying to make a script wherein I can see all the orders from a particular status of Magento of a timesperiod. This script should mail me everyday how many products I sold, so I can know how many orders I have to place. I count them manual now for each product

In the generated e-mail I would only like to have product name , product id, amount.

I currently have the following code:

$content = '';
$yesterday = date('Y-m-d', strtotime("-1 day"));
$orders = Mage::getModel('sales/order')->getCollection()
->addFieldToFilter('status', Mage_Sales_Model_Order::STATE_PROCESSING)
->addAttributeToFilter('created_at', array('from'  => $yesterday));

foreach($orders as $order) {
 //this does not work
    $productId = $order->getProductId();

}

Can anyone help me to get the product id from the orders? So I can get the product name from the product class. I also need the productId to group the elements to get the total orders of a product. I did not group it yet, because I did not manage to retrieve the product Id.


Solution

  • Try

    ...
    foreach($orders as $order) {
       //this does not work
       $items = $order->getAllItems();  //$order->getAllVisibleItems() 
       foreach($items as $item){
         $productId = $item->getProductId();
       }
    
    }
    

    Take a look @ http://www.magentocommerce.com/boards/viewthread/18629/