Magento 1.9 – Get Product ID from Customer Order

googlestrustedstoremagento-1.9orderssales-order

I am setting up Google trusted stores and I am stuck on one problem which is not compulsory but I would rather it was working.

I need to get the product ID of the item the customer has ordered

So far I have this:

$orderId = $this->getOrderId();
$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);

and I guess I need to get the product ID with something like…$order->get**productID**()

Also what would happen if there is multiple products?

Best Answer

You can do the following after your code:

$items = $order->getAllVisibleItems();
$productIds = array();
foreach($items as $i) {
      $productIds[] = $i->getProductId();
}

The $productIds array will contain all the product ids from the order.

Related Topic