2

How can I get recent 100 orders in magento 2.Currently I am getting orders but those are coming from starting onwords.I want recently placed 100 orders only. Can you help me on this ? I am getting orders collection using this

$this->_orderCollectionFactory->create()->addFieldToSelect('*')->setPageSize(200);
  • Add your code in question – Prashant Valanda Nov 30 '16 at 11:00
  • Do I need to add complete code ? – shankar boss Nov 30 '16 at 11:06
3

you can get recent order with below code..

protected $_orderCollectionFactory;

public function __construct(
    .....
            \Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory,
           .......
        ) {
    ...
    $this->_orderCollectionFactory = $orderCollectionFactory;
    ........

}


public function getOrders()
{


        $ordercollection =$this->_orderCollectionFactory->create()->addFieldToSelect(array('*'));
        $ordercollection->setOrder('entity_id','DESC');
        $ordercollection->setPageSize(100);
        $ordercollection->setCurPage(1);

    return $ordercollection;
}
3

Use below code:

$collection = $this->_orderCollectionFactory->create();
$collection->setOrder('entity_id','desc');
$collection->addFieldToSelect('*')->setPageSize(100);

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.