Version Notes
customer and order report using coupon code
Download this release
Release Info
Developer | wonder |
Extension | WF_Reports |
Version | 1.0.0 |
Comparing to | |
See all releases |
Version 1.0.0
- app/code/local/WF/Reports/Block/Adminhtml/Coupons/Filter/Abstract.php +153 -0
- app/code/local/WF/Reports/Block/Adminhtml/Coupons/Filter/Coupons.php +37 -0
- app/code/local/WF/Reports/Block/Adminhtml/Coupons/Grid/Coupons.php +130 -0
- app/code/local/WF/Reports/Block/Adminhtml/Coupons/Search.php +26 -0
- app/code/local/WF/Reports/Block/Adminhtml/Coupons/Search/Grid.php +76 -0
- app/code/local/WF/Reports/Helper/Data.php +5 -0
- app/code/local/WF/Reports/Model/Resource/Order/Collection.php +51 -0
- app/code/local/WF/Reports/controllers/Adminhtml/CouponsController.php +98 -0
- app/code/local/WF/Reports/etc/adminhtml.xml +32 -0
- app/code/local/WF/Reports/etc/config.xml +74 -0
- app/etc/modules/WF_Reports.xml +12 -0
- package.xml +18 -0
app/code/local/WF/Reports/Block/Adminhtml/Coupons/Filter/Abstract.php
ADDED
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Adminhtml report filter form
|
4 |
+
*
|
5 |
+
* @category Mage
|
6 |
+
* @package Mage_Adminhtml
|
7 |
+
* @author Magento Core Team <core@magentocommerce.com>
|
8 |
+
*/
|
9 |
+
class WF_Reports_Block_Adminhtml_Coupons_Filter_Abstract extends Mage_Adminhtml_Block_Widget_Form
|
10 |
+
{
|
11 |
+
/**
|
12 |
+
* Report type options
|
13 |
+
*/
|
14 |
+
protected $_reportTypeOptions = array();
|
15 |
+
|
16 |
+
/**
|
17 |
+
* Report field visibility
|
18 |
+
*/
|
19 |
+
protected $_fieldVisibility = array();
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Report field opions
|
23 |
+
*/
|
24 |
+
protected $_fieldOptions = array();
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Set field visibility
|
28 |
+
*
|
29 |
+
* @param string Field id
|
30 |
+
* @param bool Field visibility
|
31 |
+
*/
|
32 |
+
public function setFieldVisibility($fieldId, $visibility)
|
33 |
+
{
|
34 |
+
$this->_fieldVisibility[$fieldId] = (bool)$visibility;
|
35 |
+
}
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Get field visibility
|
39 |
+
*
|
40 |
+
* @param string Field id
|
41 |
+
* @param bool Default field visibility
|
42 |
+
* @return bool
|
43 |
+
*/
|
44 |
+
public function getFieldVisibility($fieldId, $defaultVisibility = true)
|
45 |
+
{
|
46 |
+
if (!array_key_exists($fieldId, $this->_fieldVisibility)) {
|
47 |
+
return $defaultVisibility;
|
48 |
+
}
|
49 |
+
return $this->_fieldVisibility[$fieldId];
|
50 |
+
}
|
51 |
+
|
52 |
+
/**
|
53 |
+
* Set field option(s)
|
54 |
+
*
|
55 |
+
* @param string $fieldId Field id
|
56 |
+
* @param mixed $option Field option name
|
57 |
+
* @param mixed $value Field option value
|
58 |
+
*/
|
59 |
+
public function setFieldOption($fieldId, $option, $value = null)
|
60 |
+
{
|
61 |
+
if (is_array($option)) {
|
62 |
+
$options = $option;
|
63 |
+
} else {
|
64 |
+
$options = array($option => $value);
|
65 |
+
}
|
66 |
+
if (!array_key_exists($fieldId, $this->_fieldOptions)) {
|
67 |
+
$this->_fieldOptions[$fieldId] = array();
|
68 |
+
}
|
69 |
+
foreach ($options as $k => $v) {
|
70 |
+
$this->_fieldOptions[$fieldId][$k] = $v;
|
71 |
+
}
|
72 |
+
}
|
73 |
+
|
74 |
+
/**
|
75 |
+
* Add report type option
|
76 |
+
*
|
77 |
+
* @param string $key
|
78 |
+
* @param string $value
|
79 |
+
* @return Mage_Adminhtml_Block_Report_Filter_Form
|
80 |
+
*/
|
81 |
+
public function addReportTypeOption($key, $value)
|
82 |
+
{
|
83 |
+
$this->_reportTypeOptions[$key] = $this->__($value);
|
84 |
+
return $this;
|
85 |
+
}
|
86 |
+
|
87 |
+
/**
|
88 |
+
* Add fieldset with general report fields
|
89 |
+
*
|
90 |
+
* @return Mage_Adminhtml_Block_Report_Filter_Form
|
91 |
+
*/
|
92 |
+
protected function _prepareForm()
|
93 |
+
{
|
94 |
+
$actionUrl = $this->getUrl('*/*/search');
|
95 |
+
$form = new Varien_Data_Form(
|
96 |
+
array('id' => 'filter_form', 'action' => $actionUrl, 'method' => 'post')
|
97 |
+
);
|
98 |
+
$htmlIdPrefix = 'sales_report_';
|
99 |
+
$form->setHtmlIdPrefix($htmlIdPrefix);
|
100 |
+
$fieldset = $form->addFieldset('base_fieldset', array('legend'=>Mage::helper('reports')->__('Filter')));
|
101 |
+
|
102 |
+
$form->setUseContainer(true);
|
103 |
+
$this->setForm($form);
|
104 |
+
|
105 |
+
return parent::_prepareForm();
|
106 |
+
}
|
107 |
+
|
108 |
+
/**
|
109 |
+
* Initialize form fileds values
|
110 |
+
* Method will be called after prepareForm and can be used for field values initialization
|
111 |
+
*
|
112 |
+
* @return Mage_Adminhtml_Block_Widget_Form
|
113 |
+
*/
|
114 |
+
protected function _initFormValues()
|
115 |
+
{
|
116 |
+
$this->getForm()->addValues($this->getFilterData()->getData());
|
117 |
+
return parent::_initFormValues();
|
118 |
+
}
|
119 |
+
|
120 |
+
/**
|
121 |
+
* This method is called before rendering HTML
|
122 |
+
*
|
123 |
+
* @return Mage_Adminhtml_Block_Widget_Form
|
124 |
+
*/
|
125 |
+
protected function _beforeToHtml()
|
126 |
+
{
|
127 |
+
$result = parent::_beforeToHtml();
|
128 |
+
|
129 |
+
/** @var Varien_Data_Form_Element_Fieldset $fieldset */
|
130 |
+
$fieldset = $this->getForm()->getElement('base_fieldset');
|
131 |
+
|
132 |
+
if (is_object($fieldset) && $fieldset instanceof Varien_Data_Form_Element_Fieldset) {
|
133 |
+
// apply field visibility
|
134 |
+
foreach ($fieldset->getElements() as $field) {
|
135 |
+
if (!$this->getFieldVisibility($field->getId())) {
|
136 |
+
$fieldset->removeField($field->getId());
|
137 |
+
}
|
138 |
+
}
|
139 |
+
// apply field options
|
140 |
+
foreach ($this->_fieldOptions as $fieldId => $fieldOptions) {
|
141 |
+
$field = $fieldset->getElements()->searchById($fieldId);
|
142 |
+
/** @var Varien_Object $field */
|
143 |
+
if ($field) {
|
144 |
+
foreach ($fieldOptions as $k => $v) {
|
145 |
+
$field->setDataUsingMethod($k, $v);
|
146 |
+
}
|
147 |
+
}
|
148 |
+
}
|
149 |
+
}
|
150 |
+
|
151 |
+
return $result;
|
152 |
+
}
|
153 |
+
}
|
app/code/local/WF/Reports/Block/Adminhtml/Coupons/Filter/Coupons.php
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class WF_Reports_Block_Adminhtml_Coupons_Filter_Coupons extends WF_Reports_Block_Adminhtml_Coupons_Filter_Abstract
|
4 |
+
{
|
5 |
+
|
6 |
+
protected function _prepareForm()
|
7 |
+
{
|
8 |
+
parent::_prepareForm();
|
9 |
+
$form = $this->getForm();
|
10 |
+
$htmlIdPrefix = $form->getHtmlIdPrefix();
|
11 |
+
$fieldset = $this->getForm()->getElement('base_fieldset');
|
12 |
+
if (is_object($fieldset) && $fieldset instanceof Varien_Data_Form_Element_Fieldset) {
|
13 |
+
|
14 |
+
$fieldset->addField('couponcode', 'text', array(
|
15 |
+
'name' => 'couponcode',
|
16 |
+
'label' => Mage::helper('reports')->__('Coupon Code'),
|
17 |
+
'title' => Mage::helper('reports')->__('Coupon Code'),
|
18 |
+
'required' => true,
|
19 |
+
));
|
20 |
+
|
21 |
+
|
22 |
+
$fieldset->addField('flag_type', 'select', array(
|
23 |
+
'name' => 'flag_type',
|
24 |
+
'options' => array(
|
25 |
+
'yes' => Mage::helper('reports')->__('Yes'),
|
26 |
+
'no' => Mage::helper('reports')->__('No')
|
27 |
+
|
28 |
+
),
|
29 |
+
'label' => Mage::helper('reports')->__('Who Use This Coupon Code'),
|
30 |
+
'title' => Mage::helper('reports')->__('Who Use This Coupon Code')
|
31 |
+
));
|
32 |
+
|
33 |
+
}
|
34 |
+
|
35 |
+
return $this;
|
36 |
+
}
|
37 |
+
}
|
app/code/local/WF/Reports/Block/Adminhtml/Coupons/Grid/Coupons.php
ADDED
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class WF_Reports_Block_Adminhtml_Coupons_Grid_Coupons extends Mage_Adminhtml_Block_Widget_Grid
|
4 |
+
{
|
5 |
+
protected $_resourceCollectionName = '';
|
6 |
+
protected $_currentCurrencyCode = null;
|
7 |
+
protected $_storeIds = array();
|
8 |
+
protected $_aggregatedColumns = null;
|
9 |
+
|
10 |
+
public function __construct()
|
11 |
+
{
|
12 |
+
parent::__construct();
|
13 |
+
$this->setFilterVisibility(false);
|
14 |
+
$this->setPagerVisibility(false);
|
15 |
+
$this->setUseAjax(false);
|
16 |
+
if (isset($this->_columnGroupBy)) {
|
17 |
+
$this->isColumnGrouped($this->_columnGroupBy, true);
|
18 |
+
}
|
19 |
+
$this->setEmptyCellLabel(Mage::helper('reports')->__('No records found for this period.'));
|
20 |
+
}
|
21 |
+
|
22 |
+
public function getResourceCollectionName()
|
23 |
+
{
|
24 |
+
return $this->_resourceCollectionName;
|
25 |
+
}
|
26 |
+
|
27 |
+
public function getCollection()
|
28 |
+
{
|
29 |
+
$filterData = $this->getFilterData();
|
30 |
+
$couponcode = $filterData->getData('couponcode');
|
31 |
+
$flag = $filterData->getData('flag_type');
|
32 |
+
if(isset($flag)&& $flag == 'yes'){
|
33 |
+
if (is_null($this->_collection)) {
|
34 |
+
$collect = Mage::getResourceModel('wfreports/order_collection')->addFieldToSelect('customer_email','email')->addExtraInfo();
|
35 |
+
$collect->getSelect()->distinct(true)->columns(array("name"=>"concat(main_table.customer_firstname,' ',main_table.customer_lastname)"))->where(" main_table.coupon_code like ?",'%'.$couponcode.'%');
|
36 |
+
$this->setCollection($collect);
|
37 |
+
}
|
38 |
+
}else{
|
39 |
+
$collect = Mage::getResourceModel('wfreports/order_collection')->addFieldToSelect('customer_email','email')->addExtraInfo();
|
40 |
+
$collect->getSelect()->distinct(true)->columns(array("name"=>"concat(main_table.customer_firstname,' ',main_table.customer_lastname)"))->where(" main_table.coupon_code not like ?",'%'.$couponcode.'%');
|
41 |
+
$this->setCollection($collect);
|
42 |
+
}
|
43 |
+
return $this->_collection;
|
44 |
+
}
|
45 |
+
|
46 |
+
protected function _getAggregatedColumns()
|
47 |
+
{
|
48 |
+
if (is_null($this->_aggregatedColumns)) {
|
49 |
+
foreach ($this->getColumns() as $column) {
|
50 |
+
if (!is_array($this->_aggregatedColumns)) {
|
51 |
+
$this->_aggregatedColumns = array();
|
52 |
+
}
|
53 |
+
if ($column->hasTotal()) {
|
54 |
+
$this->_aggregatedColumns[$column->getId()] = "{$column->getTotal()}({$column->getIndex()})";
|
55 |
+
}
|
56 |
+
}
|
57 |
+
}
|
58 |
+
return $this->_aggregatedColumns;
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* Add column to grid
|
63 |
+
* Overriden to add support for visibility_filter column option
|
64 |
+
* It stands for conditional visibility of the column depending on filter field values
|
65 |
+
* Value of visibility_filter supports (filter_field_name => filter_field_value) pairs
|
66 |
+
*
|
67 |
+
* @param string $columnId
|
68 |
+
* @param array $column
|
69 |
+
* @return Mage_Adminhtml_Block_Report_Grid_Abstract
|
70 |
+
*/
|
71 |
+
public function addColumn($columnId, $column)
|
72 |
+
{
|
73 |
+
if (is_array($column) && array_key_exists('visibility_filter', $column)) {
|
74 |
+
$filterData = $this->getFilterData();
|
75 |
+
$visibilityFilter = $column['visibility_filter'];
|
76 |
+
if (!is_array($visibilityFilter)) {
|
77 |
+
$visibilityFilter = array($visibilityFilter);
|
78 |
+
}
|
79 |
+
foreach ($visibilityFilter as $k => $v) {
|
80 |
+
if (is_int($k)) {
|
81 |
+
$filterFieldId = $v;
|
82 |
+
$filterFieldValue = true;
|
83 |
+
} else {
|
84 |
+
$filterFieldId = $k;
|
85 |
+
$filterFieldValue = $v;
|
86 |
+
}
|
87 |
+
if (
|
88 |
+
!$filterData->hasData($filterFieldId) ||
|
89 |
+
$filterData->getData($filterFieldId) != $filterFieldValue
|
90 |
+
) {
|
91 |
+
return $this; // don't add column
|
92 |
+
}
|
93 |
+
}
|
94 |
+
}
|
95 |
+
return parent::addColumn($columnId, $column);
|
96 |
+
}
|
97 |
+
|
98 |
+
|
99 |
+
|
100 |
+
protected function _prepareCollection()
|
101 |
+
{
|
102 |
+
$this->getCollection();
|
103 |
+
return parent::_prepareCollection();
|
104 |
+
}
|
105 |
+
|
106 |
+
public function getCountTotals()
|
107 |
+
{
|
108 |
+
if (!$this->getTotals()) {
|
109 |
+
$totalsCollection = $this->getCollection();
|
110 |
+
if (count($totalsCollection->getItems()) < 1 ) {
|
111 |
+
$this->setTotals(new Varien_Object());
|
112 |
+
} else {
|
113 |
+
foreach ($totalsCollection->getItems() as $item) {
|
114 |
+
$this->setTotals($item);
|
115 |
+
break;
|
116 |
+
}
|
117 |
+
}
|
118 |
+
}
|
119 |
+
return parent::getCountTotals();
|
120 |
+
}
|
121 |
+
|
122 |
+
public function getSubTotals()
|
123 |
+
{
|
124 |
+
$subTotalsCollection = $this->getCollection();
|
125 |
+
$this->setSubTotals($subTotalsCollection->getItems());
|
126 |
+
return parent::getSubTotals();
|
127 |
+
}
|
128 |
+
|
129 |
+
|
130 |
+
}
|
app/code/local/WF/Reports/Block/Adminhtml/Coupons/Search.php
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
|
4 |
+
class WF_Reports_Block_Adminhtml_Coupons_Search extends Mage_Adminhtml_Block_Widget_Grid_Container
|
5 |
+
{
|
6 |
+
protected $_blockGroup = 'wfreports';
|
7 |
+
|
8 |
+
public function __construct()
|
9 |
+
{
|
10 |
+
$this->_controller = 'adminhtml_coupons_search';
|
11 |
+
$this->_headerText = Mage::helper('reports')->__('Customers Report');
|
12 |
+
parent::__construct();
|
13 |
+
$this->setTemplate('report/grid/container.phtml');
|
14 |
+
$this->_removeButton('add');
|
15 |
+
$this->addButton('filter_form_submit', array(
|
16 |
+
'label' => Mage::helper('reports')->__('Show Report'),
|
17 |
+
'onclick' => 'filterFormSubmit()'
|
18 |
+
));
|
19 |
+
}
|
20 |
+
|
21 |
+
public function getFilterUrl()
|
22 |
+
{
|
23 |
+
$this->getRequest()->setParam('filter', null);
|
24 |
+
return $this->getUrl('*/*/search', array('_current' => true));
|
25 |
+
}
|
26 |
+
}
|
app/code/local/WF/Reports/Block/Adminhtml/Coupons/Search/Grid.php
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class WF_Reports_Block_Adminhtml_Coupons_Search_Grid extends WF_Reports_Block_Adminhtml_Coupons_Grid_Coupons
|
4 |
+
{
|
5 |
+
protected $_columnGroupBy = 'email';
|
6 |
+
|
7 |
+
public function __construct()
|
8 |
+
{
|
9 |
+
parent::__construct();
|
10 |
+
}
|
11 |
+
|
12 |
+
public function getResourceCollectionName()
|
13 |
+
{
|
14 |
+
|
15 |
+
}
|
16 |
+
|
17 |
+
protected function _prepareColumns()
|
18 |
+
{
|
19 |
+
$this->addColumn('real_order_id', array(
|
20 |
+
'header'=> Mage::helper('sales')->__('Order #'),
|
21 |
+
'width' => '100px',
|
22 |
+
'type' => 'text',
|
23 |
+
'index' => 'increment_id',
|
24 |
+
));
|
25 |
+
|
26 |
+
$this->addColumn('email', array(
|
27 |
+
'header' => Mage::helper('sales')->__('Email'),
|
28 |
+
'index' => 'email',
|
29 |
+
'width' => "180px",
|
30 |
+
'sortable' => false,
|
31 |
+
'html_decorators' => array('nobr'),
|
32 |
+
));
|
33 |
+
|
34 |
+
$this->addColumn('name', array(
|
35 |
+
'header' => Mage::helper('sales')->__('Name'),
|
36 |
+
'index' => 'name',
|
37 |
+
'type' => 'text',
|
38 |
+
'sortable' => false
|
39 |
+
));
|
40 |
+
|
41 |
+
$this->addColumn('street', array(
|
42 |
+
'header' => Mage::helper('sales')->__('Street'),
|
43 |
+
'index' => 'street',
|
44 |
+
'type' => 'text',
|
45 |
+
'sortable' => false
|
46 |
+
));
|
47 |
+
|
48 |
+
$this->addColumn('city', array(
|
49 |
+
'header' => Mage::helper('sales')->__('City'),
|
50 |
+
'index' => 'city',
|
51 |
+
'type' => 'text',
|
52 |
+
'sortable' => false
|
53 |
+
));
|
54 |
+
$this->addColumn('region', array(
|
55 |
+
'header' => Mage::helper('sales')->__('State'),
|
56 |
+
'index' => 'region',
|
57 |
+
'type' => 'text',
|
58 |
+
'sortable' => false
|
59 |
+
));
|
60 |
+
$this->addColumn('postcode', array(
|
61 |
+
'header' => Mage::helper('sales')->__('Zip'),
|
62 |
+
'index' => 'postcode',
|
63 |
+
'type' => 'text',
|
64 |
+
'sortable' => false
|
65 |
+
));
|
66 |
+
$this->addColumn('country_id', array(
|
67 |
+
'header' => Mage::helper('sales')->__('Country'),
|
68 |
+
'index' => 'country_id',
|
69 |
+
'type' => 'text',
|
70 |
+
'sortable' => false
|
71 |
+
));
|
72 |
+
$this->addExportType('*/*/exportSalesCsv', Mage::helper('adminhtml')->__('CSV'));
|
73 |
+
|
74 |
+
return parent::_prepareColumns();
|
75 |
+
}
|
76 |
+
}
|
app/code/local/WF/Reports/Helper/Data.php
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class WF_Reports_Helper_Data extends Mage_Core_Helper_Abstract
|
3 |
+
{
|
4 |
+
|
5 |
+
}
|
app/code/local/WF/Reports/Model/Resource/Order/Collection.php
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class WF_Reports_Model_Resource_Order_Collection extends Mage_Sales_Model_Resource_Order_Collection
|
3 |
+
{
|
4 |
+
|
5 |
+
|
6 |
+
public function addExtraInfo(){
|
7 |
+
|
8 |
+
$orderGridTable = $this->getTable('sales/order_grid');
|
9 |
+
|
10 |
+
$this->getSelect()->join(array("orderGridTable"=>$orderGridTable),
|
11 |
+
"(main_table.entity_id = orderGridTable.entity_id)",
|
12 |
+
array("orderGridTable.increment_id")
|
13 |
+
);
|
14 |
+
|
15 |
+
$billingAliasName = 'billing_o_a';
|
16 |
+
|
17 |
+
$joinTable = $this->getTable('sales/order_address');
|
18 |
+
|
19 |
+
$this
|
20 |
+
->addFilterToMap('street', $billingAliasName . '.street')
|
21 |
+
->addFilterToMap('city', $billingAliasName . '.city')
|
22 |
+
->addFilterToMap('region', $billingAliasName . '.region')
|
23 |
+
->addFilterToMap('postcode', $billingAliasName . '.postcode')
|
24 |
+
->addFilterToMap('country_id', $billingAliasName . '.country_id');
|
25 |
+
|
26 |
+
|
27 |
+
$this
|
28 |
+
->getSelect()
|
29 |
+
->joinLeft(
|
30 |
+
array($billingAliasName => $joinTable),
|
31 |
+
"(main_table.entity_id = {$billingAliasName}.parent_id"
|
32 |
+
. " AND {$billingAliasName}.address_type = 'billing')",
|
33 |
+
array(
|
34 |
+
$billingAliasName . '.street',
|
35 |
+
$billingAliasName . '.city',
|
36 |
+
$billingAliasName . '.region',
|
37 |
+
$billingAliasName . '.postcode',
|
38 |
+
$billingAliasName . '.country_id'
|
39 |
+
)
|
40 |
+
);
|
41 |
+
|
42 |
+
|
43 |
+
if (version_compare(Mage::getVersion(), '1.6.0.0', '>=')===true){
|
44 |
+
Mage::getResourceHelper('core')->prepareColumnsList($this->getSelect());
|
45 |
+
}
|
46 |
+
|
47 |
+
return $this;
|
48 |
+
|
49 |
+
}
|
50 |
+
|
51 |
+
}
|
app/code/local/WF/Reports/controllers/Adminhtml/CouponsController.php
ADDED
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class WF_Reports_Adminhtml_CouponsController extends Mage_Adminhtml_Controller_action
|
3 |
+
{
|
4 |
+
protected $_adminSession = null;
|
5 |
+
|
6 |
+
public function _initAction()
|
7 |
+
{
|
8 |
+
$this->loadLayout()
|
9 |
+
->_addBreadcrumb(Mage::helper('reports')->__('Reports'), Mage::helper('reports')->__('Reports'))
|
10 |
+
->_addBreadcrumb(Mage::helper('reports')->__('Coupons'), Mage::helper('reports')->__('Coupons'));
|
11 |
+
return $this;
|
12 |
+
}
|
13 |
+
|
14 |
+
|
15 |
+
public function _initReportAction($blocks)
|
16 |
+
{
|
17 |
+
if (!is_array($blocks)) {
|
18 |
+
$blocks = array($blocks);
|
19 |
+
}
|
20 |
+
$requestData = Mage::helper('adminhtml')->prepareFilterString($this->getRequest()->getParam('filter'));
|
21 |
+
|
22 |
+
$params = new Varien_Object();
|
23 |
+
|
24 |
+
foreach ($requestData as $key => $value) {
|
25 |
+
if (!empty($value)) {
|
26 |
+
$params->setData($key, $value);
|
27 |
+
}
|
28 |
+
}
|
29 |
+
|
30 |
+
foreach ($blocks as $block) {
|
31 |
+
if ($block) {
|
32 |
+
$block->setFilterData($params);
|
33 |
+
}
|
34 |
+
}
|
35 |
+
|
36 |
+
return $this;
|
37 |
+
}
|
38 |
+
|
39 |
+
public function searchAction()
|
40 |
+
{
|
41 |
+
|
42 |
+
$this->_title($this->__('Reports'))->_title($this->__('Coupons'))->_title($this->__('Coupons'));
|
43 |
+
|
44 |
+
$this->_initAction()
|
45 |
+
->_setActiveMenu('report/wfreports/search')
|
46 |
+
->_addBreadcrumb(Mage::helper('adminhtml')->__('Customer Report'), Mage::helper('adminhtml')->__('Customer Report'));
|
47 |
+
|
48 |
+
$gridBlock = $this->getLayout()->getBlock('adminhtml_coupons_search.grid');
|
49 |
+
|
50 |
+
$filterFormBlock = $this->getLayout()->getBlock('grid.filter.form');
|
51 |
+
|
52 |
+
$this->_initReportAction(array(
|
53 |
+
$gridBlock,
|
54 |
+
$filterFormBlock
|
55 |
+
));
|
56 |
+
|
57 |
+
$this->renderLayout();
|
58 |
+
}
|
59 |
+
|
60 |
+
|
61 |
+
protected function _getCollectionNames()
|
62 |
+
{
|
63 |
+
return array();
|
64 |
+
}
|
65 |
+
|
66 |
+
|
67 |
+
public function exportSalesCsvAction()
|
68 |
+
{
|
69 |
+
$fileName = 'customer.csv';
|
70 |
+
$grid = $this->getLayout()->createBlock('wfreports/adminhtml_coupons_search_grid');
|
71 |
+
$this->_initReportAction($grid);
|
72 |
+
$this->_prepareDownloadResponse($fileName, $grid->getCsvFile());
|
73 |
+
}
|
74 |
+
|
75 |
+
|
76 |
+
|
77 |
+
protected function _isAllowed()
|
78 |
+
{
|
79 |
+
switch ($this->getRequest()->getActionName()) {
|
80 |
+
case 'search':
|
81 |
+
return Mage::getSingleton('admin/session')->isAllowed('report/wfreports');
|
82 |
+
break;
|
83 |
+
default:
|
84 |
+
return Mage::getSingleton('admin/session')->isAllowed('report');
|
85 |
+
break;
|
86 |
+
}
|
87 |
+
}
|
88 |
+
|
89 |
+
|
90 |
+
protected function _getSession()
|
91 |
+
{
|
92 |
+
if (is_null($this->_adminSession)) {
|
93 |
+
$this->_adminSession = Mage::getSingleton('admin/session');
|
94 |
+
}
|
95 |
+
return $this->_adminSession;
|
96 |
+
}
|
97 |
+
|
98 |
+
}
|
app/code/local/WF/Reports/etc/adminhtml.xml
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<adminhtml>
|
3 |
+
|
4 |
+
<menu>
|
5 |
+
<report module="reports">
|
6 |
+
<children>
|
7 |
+
<wfreports translate="title" module="reports">
|
8 |
+
<title>Search Customers By Coupon Code</title>
|
9 |
+
<sort_order>65537</sort_order>
|
10 |
+
<action>wfreports/adminhtml_coupons/search</action>
|
11 |
+
</wfreports>
|
12 |
+
</children>
|
13 |
+
</report>
|
14 |
+
</menu>
|
15 |
+
|
16 |
+
<acl>
|
17 |
+
<resources>
|
18 |
+
<admin>
|
19 |
+
<children>
|
20 |
+
<report translate="title" module="reports">
|
21 |
+
<children>
|
22 |
+
<wfreports translate="title">
|
23 |
+
<title>Search Customers By Coupon Code</title>
|
24 |
+
</wfreports>
|
25 |
+
</children>
|
26 |
+
</report>
|
27 |
+
</children>
|
28 |
+
</admin>
|
29 |
+
</resources>
|
30 |
+
</acl>
|
31 |
+
|
32 |
+
</adminhtml>
|
app/code/local/WF/Reports/etc/config.xml
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<config>
|
3 |
+
|
4 |
+
<modules>
|
5 |
+
<WF_Reports>
|
6 |
+
<version>1.0.0</version>
|
7 |
+
</WF_Reports>
|
8 |
+
</modules>
|
9 |
+
|
10 |
+
<global>
|
11 |
+
<models>
|
12 |
+
<wfreports>
|
13 |
+
<class>WF_Reports_Model</class>
|
14 |
+
<resourceModel>wfreports_resource</resourceModel>
|
15 |
+
</wfreports>
|
16 |
+
<wfreports_resource>
|
17 |
+
<class>WF_Reports_Model_Resource</class>
|
18 |
+
</wfreports_resource>
|
19 |
+
</models>
|
20 |
+
<blocks>
|
21 |
+
<wfreports>
|
22 |
+
<class>WF_Reports_Block</class>
|
23 |
+
</wfreports>
|
24 |
+
</blocks>
|
25 |
+
<helpers>
|
26 |
+
<wfreports>
|
27 |
+
<class>WF_Reports_Helper</class>
|
28 |
+
</wfreports>
|
29 |
+
</helpers>
|
30 |
+
<resources>
|
31 |
+
<wfreports_setup>
|
32 |
+
<setup>
|
33 |
+
<module>WF_Reports</module>
|
34 |
+
</setup>
|
35 |
+
<connection>
|
36 |
+
<use>core_setup</use>
|
37 |
+
</connection>
|
38 |
+
</wfreports_setup>
|
39 |
+
<wfreports_write>
|
40 |
+
<connection>
|
41 |
+
<use>core_write</use>
|
42 |
+
</connection>
|
43 |
+
</wfreports_write>
|
44 |
+
<wfreports_read>
|
45 |
+
<connection>
|
46 |
+
<use>core_read</use>
|
47 |
+
</connection>
|
48 |
+
</wfreports_read>
|
49 |
+
</resources>
|
50 |
+
</global>
|
51 |
+
|
52 |
+
<admin>
|
53 |
+
<routers>
|
54 |
+
<wfreports>
|
55 |
+
<use>admin</use>
|
56 |
+
<args>
|
57 |
+
<module>WF_Reports</module>
|
58 |
+
<frontName>wfreports</frontName>
|
59 |
+
</args>
|
60 |
+
</wfreports>
|
61 |
+
</routers>
|
62 |
+
</admin>
|
63 |
+
<adminhtml>
|
64 |
+
<layout>
|
65 |
+
<updates>
|
66 |
+
<wfreports>
|
67 |
+
<file>wfreports.xml</file>
|
68 |
+
</wfreports>
|
69 |
+
</updates>
|
70 |
+
</layout>
|
71 |
+
</adminhtml>
|
72 |
+
|
73 |
+
|
74 |
+
</config>
|
app/etc/modules/WF_Reports.xml
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<WF_Reports>
|
5 |
+
<active>true</active>
|
6 |
+
<codePool>local</codePool>
|
7 |
+
<depends>
|
8 |
+
<Mage_Admin/>
|
9 |
+
</depends>
|
10 |
+
</WF_Reports>
|
11 |
+
</modules>
|
12 |
+
</config>
|
package.xml
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>WF_Reports</name>
|
4 |
+
<version>1.0.0</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL)</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>This report can show the cutomer and order report by its used coupon code.</summary>
|
10 |
+
<description>Given the coupon code, we can easy have the customer report and order report which use the coupon code.</description>
|
11 |
+
<notes>customer and order report using coupon code</notes>
|
12 |
+
<authors><author><name>wonder</name><user>wonderfan2000</user><email>fanjiahe2000@163.com</email></author></authors>
|
13 |
+
<date>2012-02-12</date>
|
14 |
+
<time>07:36:43</time>
|
15 |
+
<contents><target name="magelocal"><dir name="WF"><dir name="Reports"><dir name="Block"><dir name="Adminhtml"><dir name="Coupons"><dir name="Filter"><file name="Abstract.php" hash="431d925497883373894ed5e27b705aed"/><file name="Coupons.php" hash="1e7ff104b71a7fc3b82e0e0cb79c0884"/></dir><dir name="Grid"><file name="Coupons.php" hash="7b176a39ecf35925befa8986ba614aaf"/></dir><dir name="Search"><file name="Grid.php" hash="414e5ef9dd6d22da78cc4023cbcb82a5"/></dir><file name="Search.php" hash="f59a6fbd7994ee650c03fa11434dbd6d"/></dir></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="CouponsController.php" hash="8a09e1f6c65ded2aee048483ca7f4c82"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="7403a6c24f9ab89376b8413773b0fa48"/><file name="config.xml" hash="f1e7cc94e7061a8380e94bcfff92960c"/></dir><dir name="Helper"><file name="Data.php" hash="afddb6e42f6e38104f2ae2e47976a57a"/></dir><dir name="Model"><dir name="Resource"><dir name="Order"><file name="Collection.php" hash="3823bae569e24435ab2ee5d150f78022"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="WF_Reports.xml" hash="389529836d0aed8e3dbd196492ee72b5"/></dir></target></contents>
|
16 |
+
<compatible/>
|
17 |
+
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
|
18 |
+
</package>
|