Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. $orders = Mage::getResourceModel('sales/order_collection')
  2. ->addFieldToSelect('*')
  3. ->addFieldToFilter('customer_id', Mage::getSingleton('customer/session')->getCustomer()->getId())
  4. ->addFieldToFilter('state', array('in' => Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates()))
  5. ->setOrder('created_at', 'desc')
  6. ;
  7.  
  8.  
  9.  
  10. count($orders->getData()) returns 3; OK
  11.  
  12. count($orders) returns 2; NOK
  13.  
  14. or
  15.  
  16. $orders->getSize() returns 3 : OK
  17.  
  18. $orders->count() returns 2 : NOK
  19.  
  20. <?php
  21. $customerCollection = Mage::getModel('customer/customer')->getCollection()
  22. ->addAttributeToSelect('entity_id');
  23.  
  24. foreach($customerCollection as $customer){
  25. $_orders = Mage::getModel('sales/order')->getCollection()
  26. ->addFieldToFilter('customer_id',$customer->getId());
  27. $_orderCnt = $_orders->count(); //orders count
  28. echo 'Customer with ID '.$customer_id.' has '.$_orderCnt.' orders';
  29. }
  30. ?>
  31.  
  32. <?php
  33. $orders = Mage::getModel('sales/order')->getCollection()
  34. ->addAttributeToFilter('status', array('eq' => Mage_Sales_Model_Order::STATE_COMPLETE));
  35. ?>
  36.  
  37. $orders = Mage::getModel('sales/order')->getCollection()
  38. ->addAttributeToFilter('status', 'your_status');
  39. $array = array_count_values($orders->getColumnValues('customer_id'));
  40.  
  41. foreach ($array as $customerId => $orderCount) {
  42. echo "Customer ID : " . $customerId . " Order Count : ". $orderCount. "<br>";
  43. }
  44.  
  45. $orders->getColumnValues('customer_id')
  46.  
  47. $array = array_count_values(array_map(function($v) {
  48. return (is_null($v)) ? "?" : $v;
  49. }, $orders->getColumnValues('customer_id')));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement