How would I get a list of all orders in Magento that have a certain product on the order?
I have built an extension and need to know all orders which contain a certain product.
How would I get a list of all orders in Magento that have a certain product on the order?
I have built an extension and need to know all orders which contain a certain product.
This is not a duplicate question per se, so here 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 which contain an orderitem for the given {PRODUCT_ID}.