To get order collection by customer wise i.e.., customer A and customer B have placed order and it should retrieve by customer wise per collection?

public function getOrdersByCustomer() {  

    $collect = $this->_orderCollectionFactory->create()->addFieldToSelect('*');

    $collection = $collect->getSelect()->group('customer_id');

    return $collection;

The above returns null.Thanks in advance

  • 1
    You want to get customer's order data? – Rohan Hapani Jan 4 at 8:53
  • No, I want to fetch the order collection group by customer_id. Hope you understand the question? – Prathap Gunasekaran Jan 4 at 9:00
  • 1
    Please share full code .Seems code is right – Amit Bera Jan 4 at 9:08
  • That's it from block and retrieving on phtml $_ordersbycustomer = $block->getOrdersByCustomer(); print_r($_ordersbycustomer->getData()); exit(); – Prathap Gunasekaran Jan 4 at 9:11

Try using these cods:

 public function getOrders()
        if (!($customerId = $this->_customerSession->getCustomerId())) {
            return false;
        if (!$this->orders) {
            $this->orders = $this->getOrderCollectionFactory()->create($customerId)->addFieldToSelect(
                ['in' => $this->_orderConfig->getVisibleOnFrontStatuses()]
        return $this->orders;
  • thanks for the answer I'll try it out and let you know. – Prathap Gunasekaran Jan 7 at 11:29

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.