0

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?

1 Answer 1

1

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 and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.