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 |
Definition at line 28 of file Collection.php.
__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 }
getAttribute | ( | $ | attr | ) |
getEntity | ( | ) |
Enter description here...
Definition at line 169 of file Collection.php.
getItems | ( | ) |
getIterator | ( | ) |
getSelect | ( | ) |
getTotals | ( | ) |
Enter description here...
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
boolean | $printQuery | |
boolean | $logQuery |
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 | ) |
$_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.