Mage_Sales_Model_Mysql4_Sale_Collection Class Reference

Inheritance diagram for Mage_Sales_Model_Mysql4_Sale_Collection:

Varien_Object

List of all members.

Public Member Functions

 __construct ()
 setCustomerFilter (Mage_Customer_Model_Customer $customer)
 load ($printQuery=false, $logQuery=false)
 printLogQuery ($printQuery=false, $logQuery=false, $sql=null)
 getSelect ()
 getAttribute ($attr)
 getEntity ()
 getIterator ()
 getItems ()
 getTotals ()

Protected Attributes

 $_read
 $_items = array()
 $_totals = array('lifetime' => 0, 'num_orders' => 0)
 $_entity
 $_select
 $_customer


Detailed Description

Definition at line 28 of file Collection.php.


Constructor & Destructor Documentation

__construct (  ) 

Constructor

By default is looking for first argument as array and assignes it as object attributes This behaviour may change in child classes

Reimplemented from Varien_Object.

Definition at line 63 of file Collection.php.

00064     {
00065         $this->_entity = Mage::getModel('sales_entity/order');
00066         $this->_read = $this->_entity->getReadConnection();
00067     }


Member Function Documentation

getAttribute ( attr  ) 

Enter description here...

Returns:
Mage_Eav_Model_Entity_Attribute_Abstract

Definition at line 159 of file Collection.php.

00160     {
00161         return $this->_entity->getAttribute($attr);
00162     }

getEntity (  ) 

Enter description here...

Returns:
Mage_Eav_Model_Entity_Abstract

Definition at line 169 of file Collection.php.

00170     {
00171         return $this->_entity;
00172     }

getItems (  ) 

Enter description here...

Returns:
array

Definition at line 189 of file Collection.php.

00190     {
00191         return $this->_items;
00192     }

getIterator (  ) 

Enter description here...

Returns:
ArrayIterator

Definition at line 179 of file Collection.php.

00180     {
00181         return new ArrayIterator($this->_items);
00182     }

getSelect (  ) 

Get zend db select instance

Returns:
Zend_Db_Select

Definition at line 149 of file Collection.php.

00150     {
00151         return $this->_select;
00152     }

getTotals (  ) 

Enter description here...

Returns:
Varien_Object

Definition at line 199 of file Collection.php.

00200     {
00201         return new Varien_Object($this->_totals);
00202     }

load ( printQuery = false,
logQuery = false 
)

Definition at line 75 of file Collection.php.

00076     {
00077         $this->_select = $this->_read->select();
00078         $entityTable= $this->getEntity()->getEntityTable();
00079         $paidTable  = $this->getAttribute('grand_total')->getBackend()->getTable();
00080         $idField    = $this->getEntity()->getIdFieldName();
00081         $this->getSelect()
00082             ->from(array('sales' => $entityTable),
00083                 array(
00084                     'store_id',
00085                     'lifetime'  => 'sum(sales.base_grand_total)',
00086                     'avgsale'   => 'avg(sales.base_grand_total)',
00087                     'num_orders'=> 'count(sales.base_grand_total)'
00088                 )
00089             )
00090             ->where('sales.entity_type_id=?', $this->getEntity()->getTypeId())
00091             ->group('sales.store_id')
00092         ;
00093         if ($this->_customer instanceof Mage_Customer_Model_Customer) {
00094             $this->getSelect()
00095                 ->where('sales.customer_id=?', $this->_customer->getId());
00096         }
00097 
00098         $this->printLogQuery($printQuery, $logQuery);
00099         try {
00100             $values = $this->_read->fetchAll($this->getSelect()->__toString());
00101         } catch (Exception $e) {
00102             $this->printLogQuery(true, true, $this->getSelect()->__toString());
00103             throw $e;
00104         }
00105         $stores = Mage::getResourceModel('core/store_collection')->setWithoutDefaultFilter()->load()->toOptionHash();
00106         if (! empty($values)) {
00107             foreach ($values as $v) {
00108                 $obj = new Varien_Object($v);
00109                 $storeName = isset($stores[$obj->getStoreId()]) ? $stores[$obj->getStoreId()] : null;
00110 
00111                 $this->_items[ $v['store_id'] ] = $obj;
00112                 $this->_items[ $v['store_id'] ]->setStoreName($storeName);
00113                 $this->_items[ $v['store_id'] ]->setAvgNormalized($obj->getAvgsale() * $obj->getNumOrders());
00114                 foreach ($this->_totals as $key => $value) {
00115                     $this->_totals[$key] += $obj->getData($key);
00116                 }
00117             }
00118             if ($this->_totals['num_orders']) {
00119                 $this->_totals['avgsale'] = $this->_totals['lifetime'] / $this->_totals['num_orders'];
00120             }
00121         }
00122 
00123         return $this;
00124     }

printLogQuery ( printQuery = false,
logQuery = false,
sql = null 
)

Print and/or log query

Parameters:
boolean $printQuery
boolean $logQuery
Returns:
Mage_Sales_Model_Mysql4_Order_Attribute_Collection_Paid

Definition at line 133 of file Collection.php.

00133                                                                                        {
00134         if ($printQuery) {
00135             echo is_null($sql) ? $this->getSelect()->__toString() : $sql;
00136         }
00137 
00138         if ($logQuery){
00139             Mage::log(is_null($sql) ? $this->getSelect()->__toString() : $sql);
00140         }
00141         return $this;
00142     }

setCustomerFilter ( Mage_Customer_Model_Customer customer  ) 

Definition at line 69 of file Collection.php.

00070     {
00071         $this->_customer = $customer;
00072         return $this;
00073     }


Member Data Documentation

$_customer [protected]

Definition at line 61 of file Collection.php.

$_entity [protected]

Definition at line 47 of file Collection.php.

$_items = array() [protected]

Definition at line 38 of file Collection.php.

$_read [protected]

Definition at line 36 of file Collection.php.

$_select [protected]

Definition at line 54 of file Collection.php.

$_totals = array('lifetime' => 0, 'num_orders' => 0) [protected]

Definition at line 40 of file Collection.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:45 2009 for Magento by  doxygen 1.5.8