Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $orders = Mage::getResourceModel('sales/order_collection')
- ->addFieldToSelect('*')
- ->addFieldToFilter('customer_id', Mage::getSingleton('customer/session')->getCustomer()->getId())
- ->addFieldToFilter('state', array('in' => Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates()))
- ->setOrder('created_at', 'desc')
- ;
- count($orders->getData()) returns 3; OK
- count($orders) returns 2; NOK
- or
- $orders->getSize() returns 3 : OK
- $orders->count() returns 2 : NOK
- <?php
- $customerCollection = Mage::getModel('customer/customer')->getCollection()
- ->addAttributeToSelect('entity_id');
- foreach($customerCollection as $customer){
- $_orders = Mage::getModel('sales/order')->getCollection()
- ->addFieldToFilter('customer_id',$customer->getId());
- $_orderCnt = $_orders->count(); //orders count
- echo 'Customer with ID '.$customer_id.' has '.$_orderCnt.' orders';
- }
- ?>
- <?php
- $orders = Mage::getModel('sales/order')->getCollection()
- ->addAttributeToFilter('status', array('eq' => Mage_Sales_Model_Order::STATE_COMPLETE));
- ?>
- $orders = Mage::getModel('sales/order')->getCollection()
- ->addAttributeToFilter('status', 'your_status');
- $array = array_count_values($orders->getColumnValues('customer_id'));
- foreach ($array as $customerId => $orderCount) {
- echo "Customer ID : " . $customerId . " Order Count : ". $orderCount. "<br>";
- }
- $orders->getColumnValues('customer_id')
- $array = array_count_values(array_map(function($v) {
- return (is_null($v)) ? "?" : $v;
- }, $orders->getColumnValues('customer_id')));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement