SSTech_ExpandReports - Version 0.1.0

Version Notes

stable version release

Download this release

Release Info

Developer SSTech
Extension SSTech_ExpandReports
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

app/code/community/SSTech/ExpandReports/Helper/Data.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class SSTech_ExpandReports_Helper_Data extends Mage_Core_Helper_Abstract {
4
+
5
+ public function getCustomerTotals($customer) {
6
+ if (!($customer instanceof Mage_Customer_Model_Customer)) {
7
+ $customer = Mage::getModel('customer/customer')->load($customer);
8
+ }
9
+ if(!$customer->getId()){
10
+ return false;
11
+ }
12
+ return Mage::getResourceModel('sales/sale_collection')
13
+ ->setCustomerFilter($customer)
14
+ ->load()
15
+ ->getTotals();
16
+ }
17
+ public function isReturningCustomer($customer) {
18
+ $customerTotals = $this->getCustomerTotals($customer);
19
+ return (bool)($customerTotals && $customerTotals->getNumOrders() > 1);
20
+ }
21
+
22
+ public function renderData($renderedValue, $row, $column, $isExport){
23
+ return (int) $renderedValue;
24
+ }
25
+
26
+ }
app/code/community/SSTech/ExpandReports/Model/Observer.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class SSTech_ExpandReports_Model_Observer {
3
+ public function coreBlockAbstractPrepareLayoutAfter(Varien_Event_Observer $observer) {
4
+ if (Mage::app()->getRequest()->getControllerName() !== 'report_customer') {
5
+ return;
6
+ }
7
+
8
+ $block = $observer->getBlock();
9
+ if ($block->getType() == 'adminhtml/page_head') {
10
+ $block->addCss('expandreports/css/expandreports.css');
11
+ }
12
+ if ($block->getType() == 'adminhtml/report_customer_orders_grid') {
13
+ $this->_addReturningCustomerColumn($block);
14
+ }
15
+ }
16
+
17
+ protected function _addReturningCustomerColumn(Mage_Adminhtml_Block_Report_Customer_Orders_Grid $block) {
18
+
19
+ $helper = Mage::helper('expandreports');
20
+
21
+ $block->setSubReportSize(null);
22
+ $block->addColumnAfter('new_customer', array(
23
+ 'header' => Mage::helper('customer')->__('New Customer'),
24
+ 'width' => '100',
25
+ 'filter' => false,
26
+ 'sortable' => false,
27
+ 'total' => 'sum',
28
+ 'type' => 'number',
29
+ 'index' => 'new_customer',
30
+ 'inline_css' => 'new_customer',
31
+ 'frame_callback' => array($helper, 'renderData'),
32
+ ), 'name');
33
+
34
+ $block->addColumnAfter('returning_customer', array(
35
+ 'header' => Mage::helper('customer')->__('Returning Customer'),
36
+ 'width' => '100',
37
+ 'filter' => false,
38
+ 'sortable' => false,
39
+ 'total' => 'sum',
40
+ 'type' => 'number',
41
+ 'index' => 'returning_customer',
42
+ 'inline_css' => 'returning_customer',
43
+ 'frame_callback' => array($helper, 'renderData'),
44
+ ), 'new_customer');
45
+
46
+ $block->sortColumnsByOrder();
47
+ }
48
+
49
+ }
app/code/community/SSTech/ExpandReports/Model/Resource/Customer/Orders/Collection.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class SSTech_ExpandReports_Model_Resource_Customer_Orders_Collection extends Mage_Reports_Model_Resource_Customer_Orders_Collection {
4
+
5
+ protected function _joinFields($from = '', $to = '') {
6
+ $orderTable = Mage::getResourceModel('sales/order_collection')
7
+ ->addAttributeToFilter('created_at', array('to' => $from, 'datetime' => true));
8
+ $orderTable->getSelect()->where('order_table.customer_id = main_table.customer_id');
9
+ $tbl_from = $orderTable->getSelect()->getPart(Zend_Db_Select::FROM);
10
+ $tbl_from['order_table'] = $tbl_from['main_table'];
11
+ unset($tbl_from['main_table']);
12
+ $orderTable->getSelect()->setPart(Zend_Db_Select::FROM, $tbl_from);
13
+ $countSelect = $orderTable->getSelectCountSql()->reset(Zend_Db_Select::COLUMNS)->columns('(COUNT(*) >= 1)');
14
+ $countSelect = $orderTable->getSelectCountSql();
15
+ $this->joinCustomerName()
16
+ ->groupByCustomer()
17
+ ->addOrdersCount()
18
+ ->addAttributeToFilter('created_at', array('from' => $from, 'to' => $to, 'datetime' => true));
19
+
20
+ $this->getSelect()->columns(array('returning_customer' => new Zend_Db_Expr ('(' . $countSelect->reset(Zend_Db_Select::COLUMNS)->columns('(COUNT(*) >= 1)') . ')')));
21
+ $this->getSelect()->columns(array('new_customer' => new Zend_Db_Expr ('(' . $countSelect->reset(Zend_Db_Select::COLUMNS)->columns('(COUNT(*) = 0)') . ')')));
22
+ return $this;
23
+ }
24
+
25
+ }
app/code/community/SSTech/ExpandReports/etc/config.xml ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <SSTech_ExpandReports>
5
+ <version>0.1.0</version>
6
+ </SSTech_ExpandReports>
7
+ </modules>
8
+ <adminhtml>
9
+ <events>
10
+ <core_block_abstract_prepare_layout_after>
11
+ <observers>
12
+ <addExtendReportsAction>
13
+ <type>model</type>
14
+ <class>SSTech_ExpandReports_Model_Observer</class>
15
+ <method>coreBlockAbstractPrepareLayoutAfter</method>
16
+ </addExtendReportsAction>
17
+ </observers>
18
+ </core_block_abstract_prepare_layout_after>
19
+ </events>
20
+ </adminhtml>
21
+ <global>
22
+ <helpers>
23
+ <expandreports>
24
+ <class>SSTech_ExpandReports_Helper</class>
25
+ </expandreports>
26
+ </helpers>
27
+ <models>
28
+ <reports_resource>
29
+ <rewrite>
30
+ <customer_orders_collection>SSTech_ExpandReports_Model_Resource_Customer_Orders_Collection</customer_orders_collection>
31
+ </rewrite>
32
+ </reports_resource>
33
+ </models>
34
+ </global>
35
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>SSTech_ExpandReports</name>
4
+ <version>0.1.0</version>
5
+ <stability>stable</stability>
6
+ <license>Open Source License</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Small Extension which will show New and Recurring Customer in Reports Section </summary>
10
+ <description>Small Extension which will show New and Recurring Customer in Reports Section.</description>
11
+ <notes>stable version release</notes>
12
+ <authors><author><name>STek</name><user>SSTech</user><email>sandynareshg@gmail.com</email></author></authors>
13
+ <date>2014-07-05</date>
14
+ <time>08:05:55</time>
15
+ <contents><target name="mageetc"><dir name="."><file name="SSTech_ExpandReports.xml" hash=""/></dir></target><target name="magecommunity"><dir name="SSTech"><dir name="ExpandReports"><dir name="Helper"><file name="Data.php" hash="c064db293aaabf34ece6e7741581be5a"/></dir><dir name="Model"><file name="Observer.php" hash="d582871bdd66be1088e9298ac9055789"/><dir name="Resource"><dir name="Customer"><dir name="Orders"><file name="Collection.php" hash="bb28d198bc1f00e7c9202cba032f06ed"/></dir></dir></dir></dir><dir name="etc"><file name="config.xml" hash="a99d74ff72ca7a083bbc5d4885712a9f"/></dir></dir></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="expandreports"><dir name="css"><file name="expandreports.css" hash="fa304db787e5b127f19ebbb12ba16348"/></dir></dir></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>
skin/adminhtml/default/default/expandreports/css/expandreports.css ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .new_customer{
2
+ width: 26px;
3
+ height: 26px;
4
+ margin: 0 auto;
5
+ }
6
+ .returning_customer{
7
+ width: 26px;
8
+ height: 26px;
9
+ margin: 0 auto;
10
+ }
11
+ #gridOrdersCustomer_table .subtotal{
12
+ font-size: 13px;
13
+ font-weight: bold;
14
+ }
15
+ #gridOrdersCustomer_table tfoot th{
16
+ font-size: 15px;
17
+ }