1

In magento 1, I was able to filter orders by the following:

$orderitem = Mage::getModel('sales/order_item')->getCollection();
$orderitem->addFieldToFilter('name',array('like'=>'%'.$value.'%'));  
$ids =array();
foreach($orderitem as $item){
  $ids[] = $item->getOrderId(); //  sales_flat_order_item.order_id = sales_flat_order.entity_id
}
$this->getCollection()->addFieldToFilter("entity_id",array("in",$ids));
return $this;

How would I achieve this in Magento 2.3?

1 Answer 1

0

You need to think more like class, name space and functions so what you like have to go inside a function, in one of your modules:

also try to learn about ordercollectionfactory. here is an example

<?php

namespace 'moduleNameSpace';
class ModelClass extends \Magento\Framework\View\Element\Template
{

    protected $_orderCollectionFactory;

    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory,
        array $data = []
    ) {
        $this->_orderCollectionFactory = $orderCollectionFactory;

        parent::__construct($context, $data);
        $this->_isScopePrivate = true;
    }

    protected function _construct()
    {
        parent::_construct();
        $this->_orderCollectionFactory->create()->addAttributeToSelect('*')

}
   public function getmyorderdetails(array $filters = [])
    { $orders = $this->orderCollectionFactory->create();
        $orderitem=$orders->addFieldToFilter(('name',$filters);

        $ids =array();
        foreach($orderitem as $item){
            $ids[] = $item->getOrderId();
        }
        $orders->addFieldToFilter("entity_id",array("in",$ids));
     return $this->orderCollectionFactory;
}
}

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.