Magento 1.9: addAttributeToFilter not working with table sales_flat_order_items

  • Open
  • Pankaj Sharma
    Participant
    February 11, 2019 at 11:24 am #1968
    Pankaj Sharma

    I am using the below code, I want it to get a list of simple products from the table sales_flat_order_items.

    $order = Mage::getModel('sales/order')->load($orderId);
    $orderItems = $order->getItemsCollection()
            ->addAttributeToSelect('*')
            ->addAttributeToFilter('product_type', array('eq'=>'simple'))
            ->load();

    The problem is with addAttributeTofilter() is not working, it shows me all items in that table instead of simple products. any solution?

  1. Shiwani
    Participant
    Posts: 52
    February 13, 2019 at 11:27 am #1990
    Shiwani

    Hi Pankaj

    You can do this code, it will return all the simple product from that order

    $orderCollection = Mage::getResourceModel(‘sales/order_item_collection’)
    ->addFieldToSelect(‘*’)
    ->addFieldToFilter(‘order_id’, $order_id)
    ->addFieldToFilter(‘product_type’, ‘simple’)
    ->load();

    Thanks

  2. Pankaj Sharma
    Participant
    Posts: 154
    September 20, 2019 at 4:56 am #3088
    Pankaj Sharma

    Hi Shiwani,

    I’ll check and confirm.

    Thanks