0

I need to get order collection, Those orders have a specific product sku, Like I have a series of sku's "NT", So get all orders which are starting with "NT"

$SKU = NP;
$orders = array();
$collection = Mage::getResourceModel('sales/order_item_collection')
    ->addAttributeToFilter('sku', array('like' => $SKU))
    ->load();
foreach($collection as $orderItem) {
  echo $orderItem->getOrder();
}
4

2 Answers 2

1

Try the below code to filter the orders based on product sku,

 $sku = "NP";
 $orders = Mage::getModel('sales/order')
                ->getCollection()
                ->join(array('order_item' => 'sales/order_item'),'main_table.entity_id = order_item.order_id');

 $orders->addFieldToFilter('order_item.sku', array(array('like' => '%'.$sku.'%')));
2
  • using this i'm not able to print specific name or date Jan 12, 2019 at 6:59
  • This does not work Aug 25, 2020 at 10:42
0

Your code is correct. but you can't echo Order Object. Try echo $orderItem->getOrder()->getRealOrderId(); or $orderItem->getOrder()->getId();
Also update your $sku to add quotes like $SKU = 'NP'; And make sure You have a product with sku including 'NP'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.