I have a custom attribute delivery_date set for my orders however I want to create a collection that groups all these dates together and tells me the order count for each date. I have attempted with something like below and other methods however not having much like in returning anything:

$orders = $this->_orderCollectionFactory->create()->addAttributeToSelect('*')->addFieldToFilter('delivery_date', array('gteq' => $fromDay))->getSelect()->columns(['count' => new \Zend_Db_Expr('COUNT(delivery_date)')])->group('delivery_date');

How can this be achieved?


This did the trick for me:

    $orders = $this->_orderCollectionFactory->create()->addAttributeToSelect('delivery_date')->addFieldToFilter('delivery_date', array('gteq' => $fromDay));
    $orders->getSelect()->columns(['day_count' => new \Zend_Db_Expr('COUNT(*)')])->group('delivery_date');

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.