Skip links

Magento 2 Get All Order Collection with Filters

<?php
namespace N2u\HelloWorld\Block;

use Magento\Framework\App\Action\Context;
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory as OrderCollectionFactory;

class Products extends \Magento\Framework\View\Element\Template
{
    /**
     * @var OrderCollectionFactory
     */
    protected $_orderCollectionFactory;

    /**
     * Constructor
     *
     * @param Context $context
     * @param OrderCollectionFactory $orderCollectionFactory
     */
    public function __construct(
        Context $context,
        OrderCollectionFactory $orderCollectionFactory 
    ) {
        $this->_orderCollectionFactory = $orderCollectionFactory;
        parent::__construct($context);
    }

    /**
     * Get Order Collection
     * @return OrderCollectionFactory
     */
   public function getOrderCollection()
   {
       $collection = $this->_orderCollectionFactory->create()
         ->addAttributeToSelect('*')
         ->addFieldToFilter($field, $condition); //Add condition if you wish

       return $collection;     
    }
}
This website uses cookies to improve your web experience.
Home
Account
Cart
Search