1

i am trying to filter orders that have sku in its item collection I am not sure if we can use filters directly for product attributes on order collection using function.

is their any way to do so ?

3

2 Answers 2

1

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

$sku = "YOUR SKU NAME HERE";
 $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.'%')));

Let me know if it's help you...!! Thank You

1
  • Thankyou for the answer, what does "$orders" returns ? Aug 25, 2020 at 10:37
0
$orderItem->getSelect()
    ->joinInner(array('order' => Mage::getSingleton('core/resource')->getTableName('sales/order')), 'order.entity_id = main_table.order_id')
    ->where('product_id=?', 'anysku')
    ->order('main_table.order_id DESC');

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.