00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_Sales_Model_Mysql4_Order_Collection extends Mage_Eav_Model_Entity_Collection_Abstract
00035 {
00036
00037
00038
00039
00040 protected function _construct()
00041 {
00042 $this->_init('sales/order');
00043 }
00044
00045
00046
00047
00048
00049
00050 public function addItemCountExpr()
00051 {
00052 $orderTable = $this->getEntity()->getEntityTable();
00053 $orderItemEntityTypeId = Mage::getResourceSingleton('sales/order_item')->getTypeId();
00054 $this->getSelect()->join(
00055 array('items'=>$orderTable),
00056 'items.parent_id=e.entity_id and items.entity_type_id='.$orderItemEntityTypeId,
00057 array('items_count'=>new Zend_Db_Expr('COUNT(items.entity_id)'))
00058 )
00059 ->group('e.entity_id');
00060 return $this;
00061 }
00062
00063
00064
00065
00066
00067
00068 public function getSelectCountSql()
00069 {
00070 $countSelect = parent::getSelectCountSql();
00071 $countSelect->resetJoinLeft();
00072 return $countSelect;
00073 }
00074
00075
00076
00077
00078
00079
00080 public function getAllIds($limit=null, $offset=null)
00081 {
00082 $idsSelect = clone $this->getSelect();
00083 $idsSelect->reset(Zend_Db_Select::ORDER);
00084 $idsSelect->reset(Zend_Db_Select::LIMIT_COUNT);
00085 $idsSelect->reset(Zend_Db_Select::LIMIT_OFFSET);
00086 $idsSelect->reset(Zend_Db_Select::COLUMNS);
00087 $idsSelect->from(null, 'e.'.$this->getEntity()->getIdFieldName());
00088 $idsSelect->limit($limit, $offset);
00089 $idsSelect->resetJoinLeft();
00090 return $this->getConnection()->fetchCol($idsSelect, $this->_bindParams);
00091 }
00092 }