0

I would like to know how to filter order collection by using a product item name in magento 2?

$collection = $this->_orderCollectionFactory->create()->addAttributeToSelect('*');
$collection->getSelect()->join(
        ["soi" => "sales_order_item"],
        'main_table.entity_id = soi.order_id',
        array('name')
    )
     ->where('soi.name', array('like' => '% '.$params['filter-text'].' %'))
    ->group('main_table.entity_id');

Just tried this way and it didn't work. I get no order collection using this collection filter. Any help will be appreciated! Thanks!

1 Answer 1

2

Try this

$collection = $this->_orderCollectionFactory->create()->addAttributeToSelect('*');    
$collection->getSelect()->join(array('order_item' => 'sales_order_item'),'main_table.entity_id = order_item.order_id');
$collection->addFieldToFilter('order_item.product_type',['neq' => 'configurable']);
$collection->addFieldToFilter('order_item.name', array(array('like' => '%'.$params['filter-text'].'%')));
0

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.