I want to apply filter as follow, I want to get All orders having product of specific attribute, my product has a custom attribute ii_id,my sql query may be like this "get all orders having product where ii_id==123", here more than two tables (sales_flat_order,sales_flat_order_item,and tables for product)are involved, I am bit confused, how should I do this?

  • This can be simplify, If I can get all product_id's in array, having ii_id==123 – Abdul Ghaffar Dec 4 '15 at 7:16
$productId = 123;
$orders = array();
$collection = Mage::getResourceModel('sales/order_item_collection')
    ->addAttributeToFilter('product_id', array('eq' => $productId))
foreach($collection as $orderItem) {
  echo $orderItem->getOrder();
  • Bro I don't have productId, I want order collection in return, – Abdul Ghaffar Dec 4 '15 at 7:17
  • I just have ii_id value, nothing else, filter is based on ii_id,ii-id can be single or multiple select type – Abdul Ghaffar Dec 4 '15 at 7:20
  • As i mentioned in my comment "if I have all product_id's in array, having ii_id==123 or ii_id=1234", then My problem by your answer will be solved – Abdul Ghaffar Dec 4 '15 at 7:22
  • I am using this for refereance, How can I get just entity_id means product_id from this '$orderCollection = Mage::getModel('catalog/product') ->getCollection() ->addAttributeToFilter('ii_id',1);' – Abdul Ghaffar Dec 4 '15 at 7:25
  • $orderCollection = Mage::getModel('catalog/product') ->getCollection() ->addAttributeToFilter('ii_id',1); and $orderCollection->getAllIds(); will return you array of product ids. – Qaisar Satti Dec 4 '15 at 7:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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