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

$orderitem = Mage::getModel('sales/order_item')->getCollection();
$ids =array();
foreach($orderitem as $item){
  $ids[] = $item->getOrderId(); //  sales_flat_order_item.order_id = sales_flat_order.entity_id
return $this;

How would I achieve this in Magento 2.3?


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


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()

   public function getmyorderdetails(array $filters = [])
    { $orders = $this->orderCollectionFactory->create();

        $ids =array();
        foreach($orderitem as $item){
            $ids[] = $item->getOrderId();
     return $this->orderCollectionFactory;

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.