1

SELECT main_table.sku, main_table.order_id, main_table.parent_item_id, main_table.name, main_table.product_id FROM sales_order_item AS main_table WHERE (order_id = '3') AND (parent_item_id IS NULL) AND ( (sku LIKE 'WSH06%') OR (sku LIKE 'MS10%') OR (sku LIKE 'MT08%') )

$sku = ['WSH06','MS10','MT08'];
$this->itemF ->create()->getCollection()
                       ->addAttributeToSelect('sku')
                       ->addAttributeToSelect('order_id')
                       ->addAttributeToSelect('parent_item_id')
                       ->addAttributeToSelect('name')
                       ->addAttributeToSelect('product_id')
                       ->addAttributeToFilter('order_id', array('eq' => $order_id))
                      ->addAttributeToFilter('parent_item_id', array('null' => true));
foreach ($sku as $key => $value) {
    $collectionData->addFieldToFilter('sku',array('like' => $value.'%'));
}
0
1

if you want to make or condition in the collection you need to follow the below steps.

$sku = ['WSH06','MS10','MT08'];
$this->itemF ->create()->getCollection()
                       ->addAttributeToSelect('sku')
                       ->addAttributeToSelect('order_id')
                       ->addAttributeToSelect('parent_item_id')
                       ->addAttributeToSelect('name')
                       ->addAttributeToSelect('product_id')
                       ->addAttributeToFilter('order_id', array('eq' => $order_id))
                      ->addAttributeToFilter('parent_item_id', array('null' => true));

$likeField = [];
$likeValue = []
foreach ($sku as $key => $value) {
    $likeField[] = 'sku';
    $likeValue[] = array('like' => $value.'%');
}

$collectionData->addFieldToFilter($likeField, $likeValue);
echo $collectionData->getSelect()->__toString();

you need to pass array argument in addFieldToFilter to apply or condition.

hope this will work for you!

Thanks & Regards, Nirav Patel

1
  • Thank You for your quick supports – Hardik Patel Aug 17 '20 at 11:04

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.