문제

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!

도움이 되었습니까?

해결책

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'].'%')));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top