Mage_Reports_Model_Mysql4_Coupons_Collection Class Reference

Inheritance diagram for Mage_Reports_Model_Mysql4_Coupons_Collection:

Mage_Sales_Model_Entity_Order_Collection Mage_Eav_Model_Entity_Collection_Abstract Varien_Data_Collection_Db Varien_Data_Collection

List of all members.

Public Member Functions

 setDateRange ($from, $to)
 setStoreIds ($storeIds)
 joinFields ($from, $to, $storeIds=array())
 getSelectCountSql ()

Protected Attributes

 $_from = ''
 $_to = ''


Detailed Description

Definition at line 35 of file Collection.php.


Member Function Documentation

getSelectCountSql (  ) 

Get SQL for get record count

Returns:
Varien_Db_Select

Reimplemented from Varien_Data_Collection_Db.

Definition at line 95 of file Collection.php.

00096     {
00097         $countSelect = clone $this->getSelect();
00098         $countSelect->reset(Zend_Db_Select::ORDER);
00099         $countSelect->reset(Zend_Db_Select::LIMIT_COUNT);
00100         $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET);
00101         $countSelect->reset(Zend_Db_Select::COLUMNS);
00102         $countSelect->reset(Zend_Db_Select::GROUP);
00103         $countSelect->reset(Zend_Db_Select::HAVING);
00104         $countSelect->from("", "count(DISTINCT main_table.rule_id)");
00105         $sql = $countSelect->__toString();
00106         return $sql;
00107     }

joinFields ( from,
to,
storeIds = array() 
)

Definition at line 55 of file Collection.php.

00056     {
00057         $this->groupByAttribute('coupon_code')
00058             ->addAttributeToFilter('created_at', array('from' => $from, 'to' => $to, 'datetime' => true))
00059             ->addAttributeToFilter('coupon_code', array('neq' => ''))
00060             ->getselect()->from('', array('uses' => 'COUNT(e.entity_id)'))
00061             ->having('uses > 0')
00062             ->order('uses desc');
00063         //die($this->getSelect());
00064         $storeIds = array_values($storeIds);
00065         if (count($storeIds) >= 1 && $storeIds[0] != '') {
00066             $this->addAttributeToFilter('store_id', array('in' => $storeIds));
00067             $this->addExpressionAttributeToSelect(
00068                     'subtotal',
00069                     'SUM({{base_subtotal}})',
00070                     array('base_subtotal'))
00071                 ->addExpressionAttributeToSelect(
00072                     'discount',
00073                     'SUM({{base_discount_amount}})',
00074                     array('base_discount_amount'))
00075                 ->addExpressionAttributeToSelect(
00076                     'total',
00077                     'SUM({{base_subtotal}}-{{base_discount_amount}})',
00078                     array('base_subtotal', 'base_discount_amount'));
00079         } else {
00080             $this->addExpressionAttributeToSelect(
00081                     'subtotal',
00082                     'SUM({{base_subtotal}}*{{base_to_global_rate}})',
00083                     array('base_subtotal', 'base_to_global_rate'))
00084                 ->addExpressionAttributeToSelect(
00085                     'discount',
00086                     'SUM({{base_discount_amount}}*{{base_to_global_rate}})',
00087                     array('base_discount_amount', 'base_to_global_rate'))
00088                 ->addExpressionAttributeToSelect(
00089                     'total',
00090                     'SUM(({{base_subtotal}}-{{base_discount_amount}})*{{base_to_global_rate}})',
00091                     array('base_subtotal', 'base_discount_amount', 'base_to_global_rate'));
00092         }
00093     }

setDateRange ( from,
to 
)

Definition at line 41 of file Collection.php.

00042     {
00043         $this->_from = $from;
00044         $this->_to = $to;
00045         $this->_reset();
00046         return $this;
00047     }

setStoreIds ( storeIds  ) 

Definition at line 49 of file Collection.php.

00050     {
00051         $this->joinFields($this->_from, $this->_to, $storeIds);
00052         return $this;
00053     }


Member Data Documentation

$_from = '' [protected]

Definition at line 38 of file Collection.php.

$_to = '' [protected]

Definition at line 39 of file Collection.php.


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

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