Find Orders Containing a specific Product

The way in Magento to find all orders that contain a given product

Posted on March 29, 2016 in Magento

The sample code is shown following:

$productId = /*product id*/;
$orders = array();

$collection = Mage::getResourceModel('sales/order_item_collection')
     ->addAttributeToFilter('product_id', array('eq'=>$productId))

foreach ( $collection as $orderItem) {
    $orders[$orderItem->getOrder->getIncrementId()] = $orderItem->getOrder();

Create a copy of catalog/product/price.phtml and put it in YOURTEMPLATE/template/catalog/product/product_price_page.phtml. This will override the price.phtml in the template, and replace it with product_price_page.phtml.

comments powered by Disqus