Get a list of orders in the magento extension that have a specific product

How do I get a list of all orders in Magento that have a specific product in an order?

I built the extension and should know all the orders containing a particular product.

+1
source share
1 answer

This is not a duplicate question, so here is a solution that might work for you:

$productId = {PRODUCT_ID};
$orders = array();
$collection = Mage::getResourceModel('sales/order_item_collection')
    ->addAttributeToFilter('product_id', array('eq' => $productId))
    ->load();
foreach($collection as $orderItem) {
    $orders[$orderItem->getOrder()->getIncrementId()] = $orderItem->getOrder();
}

You’ll end up with an array of orders that contains the orderitem for this {PRODUCT_ID}.

+5
source

All Articles