获取具有特定产品的magento扩展中的订单列表

问题描述:

我如何获得Magento中订单上有特定产品的所有订单的列表?

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();
}

您最终将获得一系列订单,其中包含给定{PRODUCT_ID}的订单项.

You'll end up with an array of orders which contain an orderitem for the given {PRODUCT_ID}.