DigitalPianism_CustomReports - Version 0.1.0

Version Notes

- Improve memory management when dealing with large collection for all reports. 30% memory use decrease.
- Fix a bug where people were unable to set dates for the wishlist report.

Download this release

Release Info

Developer Digital Pianism
Extension DigitalPianism_CustomReports
Version 0.1.0
Comparing to
See all releases


Code changes from version 0.0.16 to 0.1.0

app/code/community/DigitalPianism/CustomReports/Block/Bestsellersbycategory/Grid.php CHANGED
@@ -1,14 +1,91 @@
1
  <?php
2
  class DigitalPianism_CustomReports_Block_Bestsellersbycategory_Grid extends Mage_Adminhtml_Block_Widget_Grid
3
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
- public function __construct()
6
- {
7
- Mage_Adminhtml_Block_Widget_Grid::__construct();
8
- $this->setId('bestsellersbycategoryReportGrid');
9
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
- protected function _prepareCollection()
12
  {
13
  // Get the session
14
  $session = Mage::getSingleton('core/session');
@@ -52,106 +129,30 @@ class DigitalPianism_CustomReports_Block_Bestsellersbycategory_Grid extends Mage
52
  ->addOrderedQtyAndTotal($sDate, $eDate)
53
  ->addAttributeToSelect('*');
54
 
55
- $this->setCollection($bestSellers);
56
-
57
  // Remove the limitation so we get all the bestsellers to be able to create accurate data
58
- $this->getCollection()->getSelect()->reset(Zend_Db_Select::LIMIT_COUNT);
59
 
60
  // echo $this->getCollection()->getSelect();
61
 
62
- // Array that will contain the data
63
- $arrayBestSellers = array();
64
- foreach ($this->getCollection() as $productSold)
65
- {
66
- // Get Product ID
67
- $id = $productSold->getData('entity_id');
68
-
69
- // Get Sold Quantity and Total
70
- $sumQty = $productSold->getData('ordered_qty');
71
- $sumTotal = $productSold->getData('ordered_total');
72
-
73
- // Load the potential parent product ids
74
- $parentProduct = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($id);
75
-
76
- // If a product is an associated product
77
- if (!empty($parentProduct) && isset($parentProduct[0]))
78
- {
79
- // Get the parent configurable product id
80
- $productId = $parentProduct[0];
81
- }
82
- else
83
- {
84
- // Get the simple product id
85
- $productId = $id;
86
- }
87
-
88
- // Get all categories of this product
89
- $categories = Mage::getResourceModel('catalog/category_collection')
90
- ->joinField('product_id',
91
- 'catalog/category_product',
92
- 'product_id',
93
- 'category_id = entity_id',
94
- null)
95
- ->addAttributeToSelect('name')
96
- ->addAttributeToSelect('parent_id')
97
- ->addFieldToFilter('product_id', $productId);
98
-
99
- // Export this collection to array so we could iterate on it's elements
100
- $categories = $categories->exportToArray();
101
-
102
- // Get categories names
103
- foreach($categories as $category)
104
- {
105
- // Get Category ID
106
- $categoryID = $category['entity_id'];
107
- // Get Category Name
108
- $categoryName = $category['name'];
109
-
110
- // If category already in the array, we add data
111
- if (array_key_exists($categoryID, $arrayBestSellers))
112
- {
113
- // We update the ordered quantity
114
- $arrayBestSellers[$categoryID]['ordered_qty'] += $sumQty;
115
-
116
- // We udpate the ordered total
117
- $arrayBestSellers[$categoryID]['ordered_total'] += $sumTotal;
118
- }
119
- else
120
- {
121
- // For the categories called 'ALL' we need to add the parent category name
122
- if (strtolower($categoryName)=='all')
123
- {
124
- // Get the parent category Name
125
- $parentCategoryName = Mage::getModel('catalog/category')->load($category['parent_id'])->getName();
126
- // Add the parent category name
127
- $categoryName = $parentCategoryName . " > " . $categoryName;
128
- }
129
-
130
- // Else we create a new entry with the data
131
- $arrayBestSellers[$categoryID] = array(
132
- 'name' => $categoryName,
133
- 'ordered_qty' => $sumQty,
134
- 'ordered_total' => $sumTotal
135
- );
136
- }
137
- }
138
- }
139
 
140
  // Obtain a list of columns to sort the array using subkeys
141
  $total = array();
142
  $qty = array();
143
- foreach ($arrayBestSellers as $key => $row) {
144
  $total[$key] = $row['ordered_total'];
145
  $qty[$key] = $row['ordered_qty'];
146
  }
147
 
148
  // Sort the data with qty ascending, views descending
149
  // Add $arrayBestSellers as the last parameter, to sort by the common key
150
- array_multisort($total, SORT_DESC, $qty, SORT_DESC, $arrayBestSellers);
151
 
152
  // Convert the array to a collection
153
  $collection = new Varien_Data_Collection();
154
- foreach($arrayBestSellers as $category){
155
  $rowObj = new Varien_Object();
156
  $rowObj->setData($category);
157
  $collection->addItem($rowObj);
@@ -164,30 +165,29 @@ class DigitalPianism_CustomReports_Block_Bestsellersbycategory_Grid extends Mage
164
  return $this;
165
  }
166
 
167
- protected function _prepareColumns()
168
- {
169
- $this->addColumn('name', array(
170
- 'header' => Mage::helper('reports')->__('Category Name'),
171
  'width' => '50',
172
- 'index' => 'name'
173
- ));
174
-
175
- $this->addColumn('ordered_qty', array(
176
- 'header' => Mage::helper('reports')->__('Ordered Quantity'),
177
- 'width' => '150',
178
- 'index' => 'ordered_qty',
179
- ));
180
 
181
- $this->addColumn('ordered_total', array(
182
- 'header' => Mage::helper('reports')->__('Ordered Total'),
183
- 'width' => '150',
184
- 'index' => 'ordered_total',
185
- ));
186
 
187
- $this->addExportType('*/*/exportBestsellersbycategoryCsv', Mage::helper('reports')->__('CSV'));
188
- $this->addExportType('*/*/exportBestsellersbycategoryExcel', Mage::helper('reports')->__('Excel'));
 
 
 
189
 
190
- return Mage_Adminhtml_Block_Widget_Grid::_prepareColumns();
191
- }
192
 
 
 
193
  }
1
  <?php
2
  class DigitalPianism_CustomReports_Block_Bestsellersbycategory_Grid extends Mage_Adminhtml_Block_Widget_Grid
3
  {
4
+ protected $arrayBestSellers = array();
5
+
6
+ public function __construct()
7
+ {
8
+ Mage_Adminhtml_Block_Widget_Grid::__construct();
9
+ $this->setId('bestsellersbycategoryReportGrid');
10
+ }
11
+
12
+ public function fillBestsellersArray($args)
13
+ {
14
+ // Get Product ID
15
+ $id = $args['row']['entity_id'];
16
+
17
+ // Get Sold Quantity and Total
18
+ $sumQty = $args['row']['ordered_qty'];
19
+ $sumTotal = $args['row']['ordered_total'];
20
+
21
+ // Load the potential parent product ids
22
+ $parentProduct = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($id);
23
+
24
+ // If a product is an associated product
25
+ if (!empty($parentProduct) && isset($parentProduct[0]))
26
+ {
27
+ // Get the parent configurable product id
28
+ $productId = $parentProduct[0];
29
+ }
30
+ else
31
+ {
32
+ // Get the simple product id
33
+ $productId = $id;
34
+ }
35
+
36
+ // Get all categories of this product
37
+ $categories = Mage::getResourceModel('catalog/category_collection')
38
+ ->joinField('product_id',
39
+ 'catalog/category_product',
40
+ 'product_id',
41
+ 'category_id = entity_id',
42
+ null)
43
+ ->addAttributeToSelect('name')
44
+ ->addAttributeToSelect('parent_id')
45
+ ->addFieldToFilter('product_id', $productId);
46
+
47
+ // Export this collection to array so we could iterate on it's elements
48
+ $categories = $categories->exportToArray();
49
 
50
+ // Get categories names
51
+ foreach($categories as $category)
52
+ {
53
+ // Get Category ID
54
+ $categoryID = $category['entity_id'];
55
+ // Get Category Name
56
+ $categoryName = $category['name'];
57
+
58
+ // If category already in the array, we add data
59
+ if (array_key_exists($categoryID, $this->arrayBestSellers))
60
+ {
61
+ // We update the ordered quantity
62
+ $this->arrayBestSellers[$categoryID]['ordered_qty'] += $sumQty;
63
+
64
+ // We udpate the ordered total
65
+ $this->arrayBestSellers[$categoryID]['ordered_total'] += $sumTotal;
66
+ }
67
+ else
68
+ {
69
+ // For the categories called 'ALL' we need to add the parent category name
70
+ if (strtolower($categoryName)=='all')
71
+ {
72
+ // Get the parent category Name
73
+ $parentCategoryName = Mage::getModel('catalog/category')->load($category['parent_id'])->getName();
74
+ // Add the parent category name
75
+ $categoryName = $parentCategoryName . " > " . $categoryName;
76
+ }
77
+
78
+ // Else we create a new entry with the data
79
+ $this->arrayBestSellers[$categoryID] = array(
80
+ 'name' => $categoryName,
81
+ 'ordered_qty' => $sumQty,
82
+ 'ordered_total' => $sumTotal
83
+ );
84
+ }
85
+ }
86
+ }
87
 
88
+ protected function _prepareCollection()
89
  {
90
  // Get the session
91
  $session = Mage::getSingleton('core/session');
129
  ->addOrderedQtyAndTotal($sDate, $eDate)
130
  ->addAttributeToSelect('*');
131
 
 
 
132
  // Remove the limitation so we get all the bestsellers to be able to create accurate data
133
+ $bestSellers->getSelect()->reset(Zend_Db_Select::LIMIT_COUNT);
134
 
135
  // echo $this->getCollection()->getSelect();
136
 
137
+ // Call iterator walk method with collection query string and callback method as parameters
138
+ // Has to be used to handle massive collection instead of foreach
139
+ Mage::getSingleton('core/resource_iterator')->walk($bestSellers->getSelect(), array(array($this, 'fillBestsellersArray')));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
 
141
  // Obtain a list of columns to sort the array using subkeys
142
  $total = array();
143
  $qty = array();
144
+ foreach ($this->arrayBestSellers as $key => $row) {
145
  $total[$key] = $row['ordered_total'];
146
  $qty[$key] = $row['ordered_qty'];
147
  }
148
 
149
  // Sort the data with qty ascending, views descending
150
  // Add $arrayBestSellers as the last parameter, to sort by the common key
151
+ array_multisort($total, SORT_DESC, $qty, SORT_DESC, $this->arrayBestSellers);
152
 
153
  // Convert the array to a collection
154
  $collection = new Varien_Data_Collection();
155
+ foreach($this->arrayBestSellers as $category){
156
  $rowObj = new Varien_Object();
157
  $rowObj->setData($category);
158
  $collection->addItem($rowObj);
165
  return $this;
166
  }
167
 
168
+ protected function _prepareColumns()
169
+ {
170
+ $this->addColumn('name', array(
171
+ 'header' => Mage::helper('reports')->__('Category Name'),
172
  'width' => '50',
173
+ 'index' => 'name'
174
+ ));
 
 
 
 
 
 
175
 
176
+ $this->addColumn('ordered_qty', array(
177
+ 'header' => Mage::helper('reports')->__('Ordered Quantity'),
178
+ 'width' => '150',
179
+ 'index' => 'ordered_qty',
180
+ ));
181
 
182
+ $this->addColumn('ordered_total', array(
183
+ 'header' => Mage::helper('reports')->__('Ordered Total'),
184
+ 'width' => '150',
185
+ 'index' => 'ordered_total',
186
+ ));
187
 
188
+ $this->addExportType('*/*/exportBestsellersbycategoryCsv', Mage::helper('reports')->__('CSV'));
189
+ $this->addExportType('*/*/exportBestsellersbycategoryExcel', Mage::helper('reports')->__('Excel'));
190
 
191
+ return Mage_Adminhtml_Block_Widget_Grid::_prepareColumns();
192
+ }
193
  }
app/code/community/DigitalPianism/CustomReports/Block/Noupsells/Grid.php CHANGED
@@ -1 +1 @@
1
- <?php
2
  public function __construct()
3
  {
4
  parent::__construct();
5
  $this->setId('noupsellsReportGrid');
6
  $this->setDefaultSort('entity_id');
7
  $this->setDefaultDir('desc');
8
  }
9
  {
10
  foreach ($upsellsItemsCollection->getItems() as $item)
11
  {
12
  $product_with_upsell_id = $item->getProductId();
13
  }
14
  return $filterArray;
15
  }
16
  protected function _prepareCollection()
17
  {
18
  $collection = Mage::getResourceModel('catalog/product_collection')
19
  $this->setCollection($collection);
20
  parent::_prepareCollection();
21
  return $this;
22
  }
23
  protected function _prepareColumns()
24
  {
25
  $this->addColumn('entity_id', array(
26
  'header' =>Mage::helper('reports')->__('Product ID'),
27
  'width' =>'50px',
28
  'index' =>'entity_id'
29
  ));
30
  $this->addColumn('name', array(
31
  'header' =>Mage::helper('reports')->__('Product Name'),
32
  'index' =>'name'
33
  ));
34
  'header' =>Mage::helper('reports')->__('Sku'),
35
  'index' =>'sku'
36
  ));
37
  array(
38
  'header'=> Mage::helper('catalog')->__('Visibility'),
39
  'width' => '70px',
40
  'index' => 'visibility',
41
  'type' => 'options',
42
  'options' => Mage::getModel('catalog/product_visibility')->getOptionArray(),
43
  ));
44
  $this->addColumn('status',
45
  array(
46
  'header'=> Mage::helper('catalog')->__('Status'),
47
  'width' => '70px',
48
  'index' => 'status',
49
  'type' => 'options',
50
  'options' => Mage::getSingleton('catalog/product_status')->getOptionArray(),
51
  ));
52
  array(
53
  'header' => Mage::helper('reports')->__('Action'),
54
  'width' => '100',
55
  'type' => 'action',
56
  'getter' => 'getId',
57
  'actions' => array(
58
  array(
59
  'caption' => Mage::helper('reports')->__('Edit Product'),
60
  'url' => array('base'=> 'adminhtml/catalog_product/edit'),
61
  'field' => 'id'
62
  )
63
  ),
64
  'filter' => false,
65
  'sortable' => false,
66
  'index' => 'stores',
67
  'is_system' => true,
68
  ));
69
  $this->addExportType('*/*/exportNoupsellsCsv', Mage::helper('reports')->__('CSV'));
70
  $this->addExportType('*/*/exportNoupsellsExcel', Mage::helper('reports')->__('Excel'));
71
  return parent::_prepareColumns();
72
  }
 
73
  protected $filterArray = array();
74
  public function __construct()
75
  {
76
  parent::__construct();
77
  $this->setId('noupsellsReportGrid');
78
  $this->setDefaultSort('entity_id');
79
  $this->setDefaultDir('desc');
80
  }
81
  {
82
  return $filterArray;
83
  }
84
  protected function _prepareCollection()
85
  {
86
  $collection = Mage::getResourceModel('catalog/product_collection')
87
  $this->setCollection($collection);
88
  parent::_prepareCollection();
89
  return $this;
90
  }
91
  protected function _prepareColumns()
92
  {
93
  $this->addColumn('entity_id', array(
94
  'header' =>Mage::helper('reports')->__('Product ID'),
95
  'width' =>'50px',
96
  'index' =>'entity_id'
97
  ));
98
  $this->addColumn('name', array(
99
  'header' =>Mage::helper('reports')->__('Product Name'),
100
  'index' =>'name'
101
  ));
102
  'header' =>Mage::helper('reports')->__('Sku'),
103
  'index' =>'sku'
104
  ));
105
  array(
106
  'header'=> Mage::helper('catalog')->__('Visibility'),
107
  'width' => '70px',
108
  'index' => 'visibility',
109
  'type' => 'options',
110
  'options' => Mage::getModel('catalog/product_visibility')->getOptionArray(),
111
  ));
112
  $this->addColumn('status',
113
  array(
114
  'header'=> Mage::helper('catalog')->__('Status'),
115
  'width' => '70px',
116
  'index' => 'status',
117
  'type' => 'options',
118
  'options' => Mage::getSingleton('catalog/product_status')->getOptionArray(),
119
  ));
120
  array(
121
  'header' => Mage::helper('reports')->__('Action'),
122
  'width' => '100',
123
  'type' => 'action',
124
  'getter' => 'getId',
125
  'actions' => array(
126
  array(
127
  'caption' => Mage::helper('reports')->__('Edit Product'),
128
  'url' => array('base'=> 'adminhtml/catalog_product/edit'),
129
  'field' => 'id'
130
  )
131
  ),
132
  'filter' => false,
133
  'sortable' => false,
134
  'index' => 'stores',
135
  'is_system' => true,
136
  ));
137
  $this->addExportType('*/*/exportNoupsellsCsv', Mage::helper('reports')->__('CSV'));
138
  $this->addExportType('*/*/exportNoupsellsExcel', Mage::helper('reports')->__('Excel'));
139
  return parent::_prepareColumns();
140
  }
 
1
  public function __construct()
2
  {
3
  parent::__construct();
4
  $this->setId('noupsellsReportGrid');
5
  $this->setDefaultSort('entity_id');
6
  $this->setDefaultDir('desc');
7
  }
8
  {
9
  foreach ($upsellsItemsCollection->getItems() as $item)
10
  {
11
  $product_with_upsell_id = $item->getProductId();
12
  }
13
  return $filterArray;
14
  }
15
  protected function _prepareCollection()
16
  {
17
  $collection = Mage::getResourceModel('catalog/product_collection')
18
  $this->setCollection($collection);
19
  parent::_prepareCollection();
20
  return $this;
21
  }
22
  protected function _prepareColumns()
23
  {
24
  $this->addColumn('entity_id', array(
25
  'header' =>Mage::helper('reports')->__('Product ID'),
26
  'width' =>'50px',
27
  'index' =>'entity_id'
28
  ));
29
  $this->addColumn('name', array(
30
  'header' =>Mage::helper('reports')->__('Product Name'),
31
  'index' =>'name'
32
  ));
33
  'header' =>Mage::helper('reports')->__('Sku'),
34
  'index' =>'sku'
35
  ));
36
  array(
37
  'header'=> Mage::helper('catalog')->__('Visibility'),
38
  'width' => '70px',
39
  'index' => 'visibility',
40
  'type' => 'options',
41
  'options' => Mage::getModel('catalog/product_visibility')->getOptionArray(),
42
  ));
43
  $this->addColumn('status',
44
  array(
45
  'header'=> Mage::helper('catalog')->__('Status'),
46
  'width' => '70px',
47
  'index' => 'status',
48
  'type' => 'options',
49
  'options' => Mage::getSingleton('catalog/product_status')->getOptionArray(),
50
  ));
51
  array(
52
  'header' => Mage::helper('reports')->__('Action'),
53
  'width' => '100',
54
  'type' => 'action',
55
  'getter' => 'getId',
56
  'actions' => array(
57
  array(
58
  'caption' => Mage::helper('reports')->__('Edit Product'),
59
  'url' => array('base'=> 'adminhtml/catalog_product/edit'),
60
  'field' => 'id'
61
  )
62
  ),
63
  'filter' => false,
64
  'sortable' => false,
65
  'index' => 'stores',
66
  'is_system' => true,
67
  ));
68
  $this->addExportType('*/*/exportNoupsellsCsv', Mage::helper('reports')->__('CSV'));
69
  $this->addExportType('*/*/exportNoupsellsExcel', Mage::helper('reports')->__('Excel'));
70
  return parent::_prepareColumns();
71
  }
72
+ <?php
73
  protected $filterArray = array();
74
  public function __construct()
75
  {
76
  parent::__construct();
77
  $this->setId('noupsellsReportGrid');
78
  $this->setDefaultSort('entity_id');
79
  $this->setDefaultDir('desc');
80
  }
81
  {
82
  return $filterArray;
83
  }
84
  protected function _prepareCollection()
85
  {
86
  $collection = Mage::getResourceModel('catalog/product_collection')
87
  $this->setCollection($collection);
88
  parent::_prepareCollection();
89
  return $this;
90
  }
91
  protected function _prepareColumns()
92
  {
93
  $this->addColumn('entity_id', array(
94
  'header' =>Mage::helper('reports')->__('Product ID'),
95
  'width' =>'50px',
96
  'index' =>'entity_id'
97
  ));
98
  $this->addColumn('name', array(
99
  'header' =>Mage::helper('reports')->__('Product Name'),
100
  'index' =>'name'
101
  ));
102
  'header' =>Mage::helper('reports')->__('Sku'),
103
  'index' =>'sku'
104
  ));
105
  array(
106
  'header'=> Mage::helper('catalog')->__('Visibility'),
107
  'width' => '70px',
108
  'index' => 'visibility',
109
  'type' => 'options',
110
  'options' => Mage::getModel('catalog/product_visibility')->getOptionArray(),
111
  ));
112
  $this->addColumn('status',
113
  array(
114
  'header'=> Mage::helper('catalog')->__('Status'),
115
  'width' => '70px',
116
  'index' => 'status',
117
  'type' => 'options',
118
  'options' => Mage::getSingleton('catalog/product_status')->getOptionArray(),
119
  ));
120
  array(
121
  'header' => Mage::helper('reports')->__('Action'),
122
  'width' => '100',
123
  'type' => 'action',
124
  'getter' => 'getId',
125
  'actions' => array(
126
  array(
127
  'caption' => Mage::helper('reports')->__('Edit Product'),
128
  'url' => array('base'=> 'adminhtml/catalog_product/edit'),
129
  'field' => 'id'
130
  )
131
  ),
132
  'filter' => false,
133
  'sortable' => false,
134
  'index' => 'stores',
135
  'is_system' => true,
136
  ));
137
  $this->addExportType('*/*/exportNoupsellsCsv', Mage::helper('reports')->__('CSV'));
138
  $this->addExportType('*/*/exportNoupsellsExcel', Mage::helper('reports')->__('Excel'));
139
  return parent::_prepareColumns();
140
  }
app/code/community/DigitalPianism/CustomReports/Block/Signedupnoorder/Grid.php CHANGED
@@ -1 +1 @@
1
- <?php
2
  public function __construct()
3
  {
4
  parent::__construct();
5
  $this->setId('signedupnoorderReportGrid');
6
  $this->setDefaultSort('subscriber_subscriptiondate');
7
  $this->setDefaultDir('desc');
8
  }
9
  protected function _prepareCollection()
10
  {
11
  $collection = Mage::getModel('newsletter/subscriber')->getCollection()
12
  $this->setCollection($collection);
13
  parent::_prepareCollection();
14
  return $this;
15
  }
16
  protected function _prepareColumns()
17
  {
18
  $this->addColumn('subscriber_id', array(
19
  'header' => Mage::helper('reports')->__('Subscriber ID'),
20
  'index' => 'subscriber_id'
21
  ));
22
  $this->addColumn('subscriber_email', array(
23
  'header' => Mage::helper('reports')->__('Subscriber Email'),
24
  'width' => '300',
25
  'index' => 'subscriber_email'
26
  ));
27
  $this->addColumn('subscriber_status', array(
28
  'header' => Mage::helper('reports')->__('Status'),
29
  'width' => '300',
30
  'index' => 'subscriber_status',
31
  ));
32
  $this->addExportType('*/*/exportSignedupnoorderCsv', Mage::helper('reports')->__('CSV'));
33
  $this->addExportType('*/*/exportSignedupnoorderExcel', Mage::helper('reports')->__('Excel'));
34
  return parent::_prepareColumns();
35
  }
 
36
  public function __construct()
37
  {
38
  parent::__construct();
39
  $this->setId('signedupnoorderReportGrid');
40
  $this->setDefaultSort('subscriber_subscriptiondate');
41
  $this->setDefaultDir('desc');
42
  }
43
  protected function _prepareCollection()
44
  {
45
  $collection = Mage::getModel('newsletter/subscriber')->getCollection()
46
  $this->setCollection($collection);
47
  parent::_prepareCollection();
48
  return $this;
49
  }
50
  protected function _prepareColumns()
51
  {
52
  $this->addColumn('subscriber_id', array(
53
  'header' => Mage::helper('reports')->__('Subscriber ID'),
54
  'index' => 'subscriber_id'
55
  ));
56
  $this->addColumn('subscriber_email', array(
57
  'header' => Mage::helper('reports')->__('Subscriber Email'),
58
  'width' => '300',
59
  'index' => 'subscriber_email'
60
  ));
61
  $this->addColumn('subscriber_status', array(
62
  'header' => Mage::helper('reports')->__('Status'),
63
  'width' => '300',
64
  'index' => 'subscriber_status',
65
  ));
66
  $this->addExportType('*/*/exportSignedupnoorderCsv', Mage::helper('reports')->__('CSV'));
67
  $this->addExportType('*/*/exportSignedupnoorderExcel', Mage::helper('reports')->__('Excel'));
68
  return parent::_prepareColumns();
69
  }
 
1
  public function __construct()
2
  {
3
  parent::__construct();
4
  $this->setId('signedupnoorderReportGrid');
5
  $this->setDefaultSort('subscriber_subscriptiondate');
6
  $this->setDefaultDir('desc');
7
  }
8
  protected function _prepareCollection()
9
  {
10
  $collection = Mage::getModel('newsletter/subscriber')->getCollection()
11
  $this->setCollection($collection);
12
  parent::_prepareCollection();
13
  return $this;
14
  }
15
  protected function _prepareColumns()
16
  {
17
  $this->addColumn('subscriber_id', array(
18
  'header' => Mage::helper('reports')->__('Subscriber ID'),
19
  'index' => 'subscriber_id'
20
  ));
21
  $this->addColumn('subscriber_email', array(
22
  'header' => Mage::helper('reports')->__('Subscriber Email'),
23
  'width' => '300',
24
  'index' => 'subscriber_email'
25
  ));
26
  $this->addColumn('subscriber_status', array(
27
  'header' => Mage::helper('reports')->__('Status'),
28
  'width' => '300',
29
  'index' => 'subscriber_status',
30
  ));
31
  $this->addExportType('*/*/exportSignedupnoorderCsv', Mage::helper('reports')->__('CSV'));
32
  $this->addExportType('*/*/exportSignedupnoorderExcel', Mage::helper('reports')->__('Excel'));
33
  return parent::_prepareColumns();
34
  }
35
+ <?php
36
  public function __construct()
37
  {
38
  parent::__construct();
39
  $this->setId('signedupnoorderReportGrid');
40
  $this->setDefaultSort('subscriber_subscriptiondate');
41
  $this->setDefaultDir('desc');
42
  }
43
  protected function _prepareCollection()
44
  {
45
  $collection = Mage::getModel('newsletter/subscriber')->getCollection()
46
  $this->setCollection($collection);
47
  parent::_prepareCollection();
48
  return $this;
49
  }
50
  protected function _prepareColumns()
51
  {
52
  $this->addColumn('subscriber_id', array(
53
  'header' => Mage::helper('reports')->__('Subscriber ID'),
54
  'index' => 'subscriber_id'
55
  ));
56
  $this->addColumn('subscriber_email', array(
57
  'header' => Mage::helper('reports')->__('Subscriber Email'),
58
  'width' => '300',
59
  'index' => 'subscriber_email'
60
  ));
61
  $this->addColumn('subscriber_status', array(
62
  'header' => Mage::helper('reports')->__('Status'),
63
  'width' => '300',
64
  'index' => 'subscriber_status',
65
  ));
66
  $this->addExportType('*/*/exportSignedupnoorderCsv', Mage::helper('reports')->__('CSV'));
67
  $this->addExportType('*/*/exportSignedupnoorderExcel', Mage::helper('reports')->__('Excel'));
68
  return parent::_prepareColumns();
69
  }
app/code/community/DigitalPianism/CustomReports/Block/Wishlist.php CHANGED
@@ -4,8 +4,10 @@ class DigitalPianism_CustomReports_Block_Wishlist extends DigitalPianism_CustomR
4
  public function __construct()
5
  {
6
  parent::__construct();
7
- $this->setTemplate('digitalpianism/customreports/grid.phtml');
8
  $this->setTitle('Wishlist Report');
 
 
9
  }
10
 
11
  public function _beforeToHtml()
4
  public function __construct()
5
  {
6
  parent::__construct();
7
+ $this->setTemplate('digitalpianism/customreports/advancedgrid.phtml');
8
  $this->setTitle('Wishlist Report');
9
+ // Set the right URL for the form which handles the dates
10
+ $this->setFormAction(Mage::getUrl('*/*/index'));
11
  }
12
 
13
  public function _beforeToHtml()
app/code/community/DigitalPianism/CustomReports/Block/Wishlist/Grid.php CHANGED
@@ -1 +1 @@
1
- <?php
2
  public function __construct()
3
  {
4
  parent::__construct();
5
  $this->setId('wishlistReportGrid');
6
  $this->setDefaultSort('updated_at');
7
  $this->setDefaultDir('desc');
8
  }
9
  {
10
  foreach ($wishlistItemsCollection->getItems() as $item)
11
  {
12
  $wishlist_id = $item->getWishlistId();
13
  }
14
  return $filterArray;
15
  }
16
  protected function _prepareCollection()
17
  {
18
  else
19
  else
20
  $end = new Zend_Date($eDate);
21
  $collection = Mage::getModel('wishlist/wishlist')
22
  //->addAttributeToSelect('entity_id')
23
  $this->setCollection($collection);
24
  parent::_prepareCollection();
25
  return $this;
26
  }
27
  protected function _prepareColumns()
28
  {
29
  $this->addColumn('wishlist_id', array(
30
  'header' =>Mage::helper('reports')->__('Wishlist ID'),
31
  'width' =>'50px',
32
  'index' =>'wishlist_id'
33
  ));
34
  $this->addColumn('customer_id', array(
35
  'header' =>Mage::helper('reports')->__('Customer ID'),
36
  'index' =>'customer_id'
37
  ));
38
  'header' =>Mage::helper('reports')->__('Has Been Shared ?'),
39
  'index' =>'shared',
40
  'options' => array(
41
  0 => Mage::helper('reports')->__('No'),
42
  1 => Mage::helper('reports')->__('Yes')
43
  )
44
  ));
45
  $this->addColumn('updated_at', array(
46
  'header' =>Mage::helper('reports')->__('Updated At'),
47
  'align' =>'right',
48
  'index' =>'updated_at'
49
  ));
50
  array(
51
  'header' => Mage::helper('reports')->__('Action'),
52
  'width' => '100',
53
  'type' => 'action',
54
  'getter' => 'getCustomerId',
55
  'actions' => array(
56
  array(
57
  'caption' => Mage::helper('reports')->__('Edit Customer'),
58
  'url' => array('base'=> 'adminhtml/customer/edit'),
59
  'field' => 'id'
60
  )
61
  ),
62
  'filter' => false,
63
  'sortable' => false,
64
  'index' => 'stores',
65
  'is_system' => true,
66
  ));
67
  $this->addExportType('*/*/exportWishlistCsv', Mage::helper('reports')->__('CSV'));
68
  $this->addExportType('*/*/exportWishlistExcel', Mage::helper('reports')->__('Excel'));
69
  return parent::_prepareColumns();
70
  }
 
71
  protected $filterArray = array();
72
  public function __construct()
73
  {
74
  parent::__construct();
75
  $this->setId('wishlistReportGrid');
76
  $this->setDefaultSort('updated_at');
77
  $this->setDefaultDir('desc');
78
  }
79
  {
80
  return $filterArray;
81
  }
82
  protected function _prepareCollection()
83
  {
84
  else
85
  else
86
  $end = new Zend_Date($eDate);
87
  $collection = Mage::getModel('wishlist/wishlist')
88
  $this->setCollection($collection);
89
  parent::_prepareCollection();
90
  return $this;
91
  }
92
  protected function _prepareColumns()
93
  {
94
  $this->addColumn('wishlist_id', array(
95
  'header' =>Mage::helper('reports')->__('Wishlist ID'),
96
  'width' =>'50px',
97
  'index' =>'wishlist_id'
98
  ));
99
  $this->addColumn('customer_id', array(
100
  'header' =>Mage::helper('reports')->__('Customer ID'),
101
  'index' =>'customer_id'
102
  ));
103
  'header' =>Mage::helper('reports')->__('Customer Email'),
104
  'index' =>'email'
105
  ));
106
  'header' =>Mage::helper('reports')->__('Has Been Shared ?'),
107
  'index' =>'shared',
108
  'options' => array(
109
  0 => Mage::helper('reports')->__('No'),
110
  1 => Mage::helper('reports')->__('Yes')
111
  )
112
  ));
113
  $this->addColumn('updated_at', array(
114
  'header' =>Mage::helper('reports')->__('Updated At'),
115
  'align' =>'right',
116
  'index' =>'updated_at',
117
  'filter_index' =>'main_table.updated_at'
118
  ));
119
  array(
120
  'header' => Mage::helper('reports')->__('Action'),
121
  'width' => '100',
122
  'type' => 'action',
123
  'getter' => 'getCustomerId',
124
  'actions' => array(
125
  array(
126
  'caption' => Mage::helper('reports')->__('Edit Customer'),
127
  'url' => array('base'=> 'adminhtml/customer/edit'),
128
  'field' => 'id'
129
  )
130
  ),
131
  'filter' => false,
132
  'sortable' => false,
133
  'index' => 'stores',
134
  'is_system' => true,
135
  ));
136
  $this->addExportType('*/*/exportWishlistCsv', Mage::helper('reports')->__('CSV'));
137
  $this->addExportType('*/*/exportWishlistExcel', Mage::helper('reports')->__('Excel'));
138
  return parent::_prepareColumns();
139
  }
 
1
  public function __construct()
2
  {
3
  parent::__construct();
4
  $this->setId('wishlistReportGrid');
5
  $this->setDefaultSort('updated_at');
6
  $this->setDefaultDir('desc');
7
  }
8
  {
9
  foreach ($wishlistItemsCollection->getItems() as $item)
10
  {
11
  $wishlist_id = $item->getWishlistId();
12
  }
13
  return $filterArray;
14
  }
15
  protected function _prepareCollection()
16
  {
17
  else
18
  else
19
  $end = new Zend_Date($eDate);
20
  $collection = Mage::getModel('wishlist/wishlist')
21
  //->addAttributeToSelect('entity_id')
22
  $this->setCollection($collection);
23
  parent::_prepareCollection();
24
  return $this;
25
  }
26
  protected function _prepareColumns()
27
  {
28
  $this->addColumn('wishlist_id', array(
29
  'header' =>Mage::helper('reports')->__('Wishlist ID'),
30
  'width' =>'50px',
31
  'index' =>'wishlist_id'
32
  ));
33
  $this->addColumn('customer_id', array(
34
  'header' =>Mage::helper('reports')->__('Customer ID'),
35
  'index' =>'customer_id'
36
  ));
37
  'header' =>Mage::helper('reports')->__('Has Been Shared ?'),
38
  'index' =>'shared',
39
  'options' => array(
40
  0 => Mage::helper('reports')->__('No'),
41
  1 => Mage::helper('reports')->__('Yes')
42
  )
43
  ));
44
  $this->addColumn('updated_at', array(
45
  'header' =>Mage::helper('reports')->__('Updated At'),
46
  'align' =>'right',
47
  'index' =>'updated_at'
48
  ));
49
  array(
50
  'header' => Mage::helper('reports')->__('Action'),
51
  'width' => '100',
52
  'type' => 'action',
53
  'getter' => 'getCustomerId',
54
  'actions' => array(
55
  array(
56
  'caption' => Mage::helper('reports')->__('Edit Customer'),
57
  'url' => array('base'=> 'adminhtml/customer/edit'),
58
  'field' => 'id'
59
  )
60
  ),
61
  'filter' => false,
62
  'sortable' => false,
63
  'index' => 'stores',
64
  'is_system' => true,
65
  ));
66
  $this->addExportType('*/*/exportWishlistCsv', Mage::helper('reports')->__('CSV'));
67
  $this->addExportType('*/*/exportWishlistExcel', Mage::helper('reports')->__('Excel'));
68
  return parent::_prepareColumns();
69
  }
70
+ <?php
71
  protected $filterArray = array();
72
  public function __construct()
73
  {
74
  parent::__construct();
75
  $this->setId('wishlistReportGrid');
76
  $this->setDefaultSort('updated_at');
77
  $this->setDefaultDir('desc');
78
  }
79
  {
80
  return $filterArray;
81
  }
82
  protected function _prepareCollection()
83
  {
84
  else
85
  else
86
  $end = new Zend_Date($eDate);
87
  $collection = Mage::getModel('wishlist/wishlist')
88
  $this->setCollection($collection);
89
  parent::_prepareCollection();
90
  return $this;
91
  }
92
  protected function _prepareColumns()
93
  {
94
  $this->addColumn('wishlist_id', array(
95
  'header' =>Mage::helper('reports')->__('Wishlist ID'),
96
  'width' =>'50px',
97
  'index' =>'wishlist_id'
98
  ));
99
  $this->addColumn('customer_id', array(
100
  'header' =>Mage::helper('reports')->__('Customer ID'),
101
  'index' =>'customer_id'
102
  ));
103
  'header' =>Mage::helper('reports')->__('Customer Email'),
104
  'index' =>'email'
105
  ));
106
  'header' =>Mage::helper('reports')->__('Has Been Shared ?'),
107
  'index' =>'shared',
108
  'options' => array(
109
  0 => Mage::helper('reports')->__('No'),
110
  1 => Mage::helper('reports')->__('Yes')
111
  )
112
  ));
113
  $this->addColumn('updated_at', array(
114
  'header' =>Mage::helper('reports')->__('Updated At'),
115
  'align' =>'right',
116
  'index' =>'updated_at',
117
  'filter_index' =>'main_table.updated_at'
118
  ));
119
  array(
120
  'header' => Mage::helper('reports')->__('Action'),
121
  'width' => '100',
122
  'type' => 'action',
123
  'getter' => 'getCustomerId',
124
  'actions' => array(
125
  array(
126
  'caption' => Mage::helper('reports')->__('Edit Customer'),
127
  'url' => array('base'=> 'adminhtml/customer/edit'),
128
  'field' => 'id'
129
  )
130
  ),
131
  'filter' => false,
132
  'sortable' => false,
133
  'index' => 'stores',
134
  'is_system' => true,
135
  ));
136
  $this->addExportType('*/*/exportWishlistCsv', Mage::helper('reports')->__('CSV'));
137
  $this->addExportType('*/*/exportWishlistExcel', Mage::helper('reports')->__('Excel'));
138
  return parent::_prepareColumns();
139
  }
app/code/community/DigitalPianism/CustomReports/Block/Worstsellers/Grid.php CHANGED
@@ -1,6 +1,7 @@
1
  <?php
2
  class DigitalPianism_CustomReports_Block_Worstsellers_Grid extends Mage_Adminhtml_Block_Widget_Grid
3
  {
 
4
 
5
  public function __construct()
6
  {
@@ -8,6 +9,85 @@ class DigitalPianism_CustomReports_Block_Worstsellers_Grid extends Mage_Adminhtm
8
  $this->setId('worstsellersReportGrid');
9
  }
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  protected function _prepareCollection()
12
  {
13
  // Get the session
@@ -63,49 +143,10 @@ class DigitalPianism_CustomReports_Block_Worstsellers_Grid extends Mage_Adminhtm
63
  $bestSellers->getSelect()->join( array ('catalog_product' => Mage::getSingleton('core/resource')->getTableName('catalog/product')), 'catalog_product.entity_id = order_items.product_id', array('catalog_product.sku'));
64
 
65
  //echo $bestSellers->printlogquery(true);
66
-
67
- // Array that will contain the data
68
- $arrayBestSellers = array();
69
- foreach ($bestSellers as $productSold)
70
- {
71
- // Get Sku and Name
72
- $sku = $productSold->getData('sku') ? $productSold->getData('sku') : $productSold->getData('catalog_product.sku');
73
- $name = $productSold->getData('name') ? $productSold->getData('name') : $productSold->getData('order_items_name');
74
-
75
- // If the sku is not set
76
- if (!$sku)
77
- {
78
- // We get the sku by loading the product
79
- $sku = Mage::getModel('catalog/product')->load($productSold->getEntityId())->getSku();
80
- // If there's still no sku
81
- if (!$sku)
82
- {
83
- // That means the product has been deleted
84
- $sku = "UNKNOWN";
85
- }
86
- }
87
- // If the name is not set
88
- if (!$name)
89
- {
90
- // We get the name by loading the product
91
- $name = Mage::getModel('catalog/product')->load($productSold->getEntityId())->getName();
92
- // If there's still no name
93
- if (!$name)
94
- {
95
- // That means the product has been deleted
96
- $name = "PRODUCT NO LONGER EXISTS";
97
- }
98
- }
99
-
100
- // We fill the array with the data
101
- $arrayBestSellers[$productSold->getEntityId()] = array(
102
- 'sku' => $sku,
103
- 'name' => $name,
104
- 'ordered_qty' => $productSold->getOrderedQty(),
105
- 'views' => 0,
106
- 'product_id' => $productSold->getEntityId()
107
- );
108
- }
109
 
110
  // Get the most viewed products
111
  $mostViewed = Mage::getResourceModel('reports/product_collection')
@@ -113,54 +154,18 @@ class DigitalPianism_CustomReports_Block_Worstsellers_Grid extends Mage_Adminhtm
113
  ->addViewsCount($from, $to);
114
 
115
  //echo $mostViewed->printlogquery(true);
116
-
117
- // Array that will contain the data
118
- $arrayMostViewed = array();
119
- foreach ($mostViewed as $productViewed)
120
- {
121
- // If the product has been pushed to the first array
122
- // That means it has been sold
123
- if (array_key_exists($productViewed->getEntityId(),$arrayBestSellers) && is_array($arrayBestSellers[$productViewed->getEntityId()]))
124
- {
125
- // We get the number of views
126
- $arrayBestSellers[$productViewed->getEntityId()]['views'] = $productViewed->getViews();
127
- }
128
- // Else it is a product that has never been sold
129
- else
130
- {
131
- // Get Sku and Name
132
- $sku = $productViewed->getSku();
133
- $name = $productViewed->getName();
134
- // If the sku is not set
135
- if (!$sku)
136
- {
137
- // We get the sku by loading the product
138
- $sku = Mage::getModel('catalog/product')->load($productViewed->getEntityId())->getSku();
139
- }
140
- // If the name is not set
141
- if (!$name)
142
- {
143
- // We get the name by loading the product
144
- $name = Mage::getModel('catalog/product')->load($productViewed->getEntityId())->getName();
145
- }
146
- // We fill the array with the data
147
- $arrayBestSellers[$productViewed->getEntityId()] = array(
148
- 'sku' => $sku,
149
- 'name' => $name,
150
- 'ordered_qty' => 0,
151
- 'views' => $productViewed->getViews(),
152
- 'product_id' => $productViewed->getEntityId()
153
- );
154
- }
155
- }
156
 
157
  // Obtain a list of columns to sort the array using subkeys
158
  $views = array();
159
  $qty = array();
160
- foreach ($arrayBestSellers as $key => $row) {
161
  // Remove the unexisting products
162
  if ($row['sku'] == "UNKNOWN") {
163
- unset($arrayBestSellers[$key]);
164
  continue;
165
  }
166
  $views[$key] = $row['views'];
@@ -169,11 +174,11 @@ class DigitalPianism_CustomReports_Block_Worstsellers_Grid extends Mage_Adminhtm
169
 
170
  // Sort the data with qty ascending, views descending
171
  // Add $arrayBestSellers as the last parameter, to sort by the common key
172
- array_multisort($qty, SORT_ASC, $views, SORT_DESC, $arrayBestSellers);
173
 
174
  // Convert the array to a collection
175
  $collection = new Varien_Data_Collection();
176
- foreach($arrayBestSellers as $product){
177
  $rowObj = new Varien_Object();
178
  $rowObj->setData($product);
179
  $collection->addItem($rowObj);
1
  <?php
2
  class DigitalPianism_CustomReports_Block_Worstsellers_Grid extends Mage_Adminhtml_Block_Widget_Grid
3
  {
4
+ protected $arrayBestSellers = array();
5
 
6
  public function __construct()
7
  {
9
  $this->setId('worstsellersReportGrid');
10
  }
11
 
12
+ public function fillBestsellersArray($args)
13
+ {
14
+ // Get Sku and Name
15
+ $sku = array_key_exists('sku',$args['row']) ? $args['row']['sku'] : $args['row']['catalog_product.sku'];
16
+ $name = array_key_exists('name',$args['row']) ? $args['row']['name'] : $args['row']['order_items_name'];
17
+
18
+ // If the sku is not set
19
+ if (!$sku)
20
+ {
21
+ // We get the sku by loading the product
22
+ $sku = Mage::getModel('catalog/product')->load($args['row']['entity_id'])->getSku();
23
+ // If there's still no sku
24
+ if (!$sku)
25
+ {
26
+ // That means the product has been deleted
27
+ $sku = "UNKNOWN";
28
+ }
29
+ }
30
+ // If the name is not set
31
+ if (!$name)
32
+ {
33
+ // We get the name by loading the product
34
+ $name = Mage::getModel('catalog/product')->load($args['row']['entity_id'])->getName();
35
+ // If there's still no name
36
+ if (!$name)
37
+ {
38
+ // That means the product has been deleted
39
+ $name = "PRODUCT NO LONGER EXISTS";
40
+ }
41
+ }
42
+
43
+ // We fill the array with the data
44
+ $this->arrayBestSellers[$args['row']['entity_id']] = array(
45
+ 'sku' => $sku,
46
+ 'name' => $name,
47
+ 'ordered_qty' => $args['row']['ordered_qty'],
48
+ 'views' => 0,
49
+ 'product_id' => $args['row']['entity_id']
50
+ );
51
+ }
52
+
53
+ public function addMostViewedData($args)
54
+ {
55
+ // If the product has been pushed to the first array
56
+ // That means it has been sold
57
+ if (array_key_exists($args['row']['entity_id'],$this->arrayBestSellers) && is_array($this->arrayBestSellers[$args['row']['entity_id']]))
58
+ {
59
+ // We get the number of views
60
+ $this->arrayBestSellers[$args['row']['entity_id']]['views'] = $args['row']['views'];
61
+ }
62
+ // Else it is a product that has never been sold
63
+ else
64
+ {
65
+ // Get Sku and Name
66
+ $sku = array_key_exists('sku',$args['row']) ? $args['row']['sku'] : "";
67
+ $name = array_key_exists('name',$args['row']) ? $args['row']['name'] : "";
68
+ // If the sku is not set
69
+ if (!$sku)
70
+ {
71
+ // We get the sku by loading the product
72
+ $sku = Mage::getModel('catalog/product')->load($args['row']['entity_id'])->getSku();
73
+ }
74
+ // If the name is not set
75
+ if (!$name)
76
+ {
77
+ // We get the name by loading the product
78
+ $name = Mage::getModel('catalog/product')->load($args['row']['entity_id'])->getName();
79
+ }
80
+ // We fill the array with the data
81
+ $this->arrayBestSellers[$args['row']['entity_id']] = array(
82
+ 'sku' => $sku,
83
+ 'name' => $name,
84
+ 'ordered_qty' => 0,
85
+ 'views' => $args['row']['views'],
86
+ 'product_id' => $args['row']['entity_id']
87
+ );
88
+ }
89
+ }
90
+
91
  protected function _prepareCollection()
92
  {
93
  // Get the session
143
  $bestSellers->getSelect()->join( array ('catalog_product' => Mage::getSingleton('core/resource')->getTableName('catalog/product')), 'catalog_product.entity_id = order_items.product_id', array('catalog_product.sku'));
144
 
145
  //echo $bestSellers->printlogquery(true);
146
+
147
+ // Call iterator walk method with collection query string and callback method as parameters
148
+ // Has to be used to handle massive collection instead of foreach
149
+ Mage::getSingleton('core/resource_iterator')->walk($bestSellers->getSelect(), array(array($this, 'fillBestsellersArray')));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
 
151
  // Get the most viewed products
152
  $mostViewed = Mage::getResourceModel('reports/product_collection')
154
  ->addViewsCount($from, $to);
155
 
156
  //echo $mostViewed->printlogquery(true);
157
+
158
+ // Call iterator walk method with collection query string and callback method as parameters
159
+ // Has to be used to handle massive collection instead of foreach
160
+ Mage::getSingleton('core/resource_iterator')->walk($mostViewed->getSelect(), array(array($this, 'addMostViewedData')));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
 
162
  // Obtain a list of columns to sort the array using subkeys
163
  $views = array();
164
  $qty = array();
165
+ foreach ($this->arrayBestSellers as $key => $row) {
166
  // Remove the unexisting products
167
  if ($row['sku'] == "UNKNOWN") {
168
+ unset($this->arrayBestSellers[$key]);
169
  continue;
170
  }
171
  $views[$key] = $row['views'];
174
 
175
  // Sort the data with qty ascending, views descending
176
  // Add $arrayBestSellers as the last parameter, to sort by the common key
177
+ array_multisort($qty, SORT_ASC, $views, SORT_DESC, $this->arrayBestSellers);
178
 
179
  // Convert the array to a collection
180
  $collection = new Varien_Data_Collection();
181
+ foreach($this->arrayBestSellers as $product){
182
  $rowObj = new Varien_Object();
183
  $rowObj->setData($product);
184
  $collection->addItem($rowObj);
app/code/community/DigitalPianism/CustomReports/Block/Worstsellersbycategory/Grid.php CHANGED
@@ -1,6 +1,7 @@
1
  <?php
2
  class DigitalPianism_CustomReports_Block_Worstsellersbycategory_Grid extends Mage_Adminhtml_Block_Widget_Grid
3
  {
 
4
 
5
  public function __construct()
6
  {
@@ -8,6 +9,37 @@ class DigitalPianism_CustomReports_Block_Worstsellersbycategory_Grid extends Mag
8
  $this->setId('worstsellersbycategoryReportGrid');
9
  }
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  protected function _prepareCollection()
12
  {
13
  // Get the session
@@ -69,17 +101,9 @@ class DigitalPianism_CustomReports_Block_Worstsellersbycategory_Grid extends Mag
69
 
70
  //echo $bestSellers->printlogquery(true);
71
 
72
- // Array that will contain the data
73
- $arrayBestSellers = array();
74
- foreach ($bestSellers as $productSold)
75
- {
76
- // We fill the array with the data
77
- $arrayBestSellers[$productSold->getEntityId()] = array(
78
- 'ordered_qty' => $productSold->getOrderedQty(),
79
- 'views' => 0,
80
- 'product_id' => $productSold->getEntityId()
81
- );
82
- }
83
 
84
  // Get the most viewed products
85
  $mostViewed = Mage::getResourceModel('reports/product_collection')
@@ -87,33 +111,14 @@ class DigitalPianism_CustomReports_Block_Worstsellersbycategory_Grid extends Mag
87
  ->addViewsCount($from, $to);
88
 
89
  //echo $mostViewed->printlogquery(true);
90
-
91
- // Array that will contain the data
92
- $arrayMostViewed = array();
93
- foreach ($mostViewed as $productViewed)
94
- {
95
- // If the product has been pushed to the first array
96
- // That means it has been sold
97
- if (array_key_exists($productViewed->getEntityId(),$arrayBestSellers) && is_array($arrayBestSellers[$productViewed->getEntityId()]))
98
- {
99
- // We get the number of views
100
- $arrayBestSellers[$productViewed->getEntityId()]['views'] = $productViewed->getViews();
101
- }
102
- // Else it is a product that has never been sold
103
- else
104
- {
105
- // We fill the array with the data
106
- $arrayBestSellers[$productViewed->getEntityId()] = array(
107
- 'ordered_qty' => 0,
108
- 'views' => $productViewed->getViews(),
109
- 'product_id' => $productViewed->getEntityId()
110
- );
111
- }
112
- }
113
 
114
  // Array that will contain the data
115
  $arrayWorstSellers = array();
116
- foreach ($arrayBestSellers as $worstSellerProductId => $worstSellerProduct)
117
  {
118
  // Get Product ID
119
  $id = $worstSellerProduct['product_id'];
1
  <?php
2
  class DigitalPianism_CustomReports_Block_Worstsellersbycategory_Grid extends Mage_Adminhtml_Block_Widget_Grid
3
  {
4
+ protected $arrayBestSellers = array();
5
 
6
  public function __construct()
7
  {
9
  $this->setId('worstsellersbycategoryReportGrid');
10
  }
11
 
12
+ public function fillBestsellersArray($args)
13
+ {
14
+ // We fill the array with the data
15
+ $this->arrayBestSellers[$args['row']['entity_id']] = array(
16
+ 'ordered_qty' => $args['row']['ordered_qty'],
17
+ 'views' => 0,
18
+ 'product_id' => $args['row']['entity_id']
19
+ );
20
+ }
21
+
22
+ public function addMostViewedData($args)
23
+ {
24
+ // If the product has been pushed to the first array
25
+ // That means it has been sold
26
+ if (array_key_exists($args['row']['entity_id'],$this->arrayBestSellers) && is_array($this->arrayBestSellers[$args['row']['entity_id']]))
27
+ {
28
+ // We get the number of views
29
+ $this->arrayBestSellers[$args['row']['entity_id']]['views'] = $args['row']['views'];
30
+ }
31
+ // Else it is a product that has never been sold
32
+ else
33
+ {
34
+ // We fill the array with the data
35
+ $this->arrayBestSellers[$args['row']['entity_id']] = array(
36
+ 'ordered_qty' => 0,
37
+ 'views' => $args['row']['views'],
38
+ 'product_id' => $args['row']['entity_id']
39
+ );
40
+ }
41
+ }
42
+
43
  protected function _prepareCollection()
44
  {
45
  // Get the session
101
 
102
  //echo $bestSellers->printlogquery(true);
103
 
104
+ // Call iterator walk method with collection query string and callback method as parameters
105
+ // Has to be used to handle massive collection instead of foreach
106
+ Mage::getSingleton('core/resource_iterator')->walk($bestSellers->getSelect(), array(array($this, 'fillBestsellersArray')));
 
 
 
 
 
 
 
 
107
 
108
  // Get the most viewed products
109
  $mostViewed = Mage::getResourceModel('reports/product_collection')
111
  ->addViewsCount($from, $to);
112
 
113
  //echo $mostViewed->printlogquery(true);
114
+
115
+ // Call iterator walk method with collection query string and callback method as parameters
116
+ // Has to be used to handle massive collection instead of foreach
117
+ Mage::getSingleton('core/resource_iterator')->walk($mostViewed->getSelect(), array(array($this, 'addMostViewedData')));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
 
119
  // Array that will contain the data
120
  $arrayWorstSellers = array();
121
+ foreach ($this->arrayBestSellers as $worstSellerProductId => $worstSellerProduct)
122
  {
123
  // Get Product ID
124
  $id = $worstSellerProduct['product_id'];
app/code/community/DigitalPianism/CustomReports/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <DigitalPianism_CustomReports>
5
- <version>0.0.16</version>
6
  </DigitalPianism_CustomReports>
7
  </modules>
8
 
2
  <config>
3
  <modules>
4
  <DigitalPianism_CustomReports>
5
+ <version>0.1.0</version>
6
  </DigitalPianism_CustomReports>
7
  </modules>
8
 
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>DigitalPianism_CustomReports</name>
4
- <version>0.0.16</version>
5
  <stability>stable</stability>
6
  <license>Open GPL</license>
7
  <channel>community</channel>
@@ -48,11 +48,12 @@ This module includes the following reports to Magento:&#xD;
48
  &lt;/ul&gt;&#xD;
49
  &#xD;
50
  &lt;p&gt;Thus, if a product is in several categories, it will be counted as a sale for all of these categories.&lt;/p&gt;</description>
51
- <notes>- Improve memory management when dealing with large subscribers collection.</notes>
 
52
  <authors><author><name>Digital Pianism</name><user>digitalpianism</user><email>contact@digital-pianism.com</email></author></authors>
53
- <date>2014-09-18</date>
54
- <time>14:50:45</time>
55
- <contents><target name="magecommunity"><dir name="DigitalPianism"><dir name="CustomReports"><dir name="Block"><dir name="Bestsellersbycategory"><file name="Grid.php" hash="6f4c37753db0005e899e2a989d752f15"/></dir><file name="Bestsellersbycategory.php" hash="60483ad3e57dc461f5943c805d149c01"/><file name="Customreport.php" hash="e6bbb8a7baf7acc47f39b02e64ccbc94"/><dir name="Lifetimesales"><file name="Grid.php" hash="b36706d8594b934d1d13b236537b39cd"/></dir><file name="Lifetimesales.php" hash="94d685421ecb611a871d99c1c593ac46"/><dir name="Noupsells"><file name="Grid.php" hash="4dd16b05ccd8b703486fa0064759c91e"/></dir><file name="Noupsells.php" hash="bbc28aa60bd78b8c3ccf2fb94f470751"/><dir name="Shoppedonce"><file name="Grid.php" hash="28401d7c968100aec911545a8074dd70"/></dir><file name="Shoppedonce.php" hash="bc3b20a05d2859a710850cde353599d5"/><dir name="Signedupnoorder"><file name="Grid.php" hash="e938295dd831a8180f35830439190730"/></dir><file name="Signedupnoorder.php" hash="30d952fcc1fa6e913c98134f195342eb"/><dir name="Wishlist"><file name="Grid.php" hash="94cd0ac0dd2b46e759510ba6f120c93e"/></dir><file name="Wishlist.php" hash="ee711134bdecd35b26fd9ae0f933195a"/><dir name="Worstsellers"><file name="Grid.php" hash="90f13fa28b33da82da46c3bb3b63f300"/></dir><file name="Worstsellers.php" hash="f31350020ae1d4207a49270a226a6df4"/><dir name="Worstsellersbycategory"><file name="Grid.php" hash="0005af367353a778690b9629674ab2ae"/></dir><file name="Worstsellersbycategory.php" hash="4b94e31f8297c38904a073240b7af85e"/></dir><dir name="Model"><dir name="Reports"><dir name="Resource"><dir name="Product"><file name="Collection.php" hash="5e544f160b1916ce3e6c0ace949a8dc9"/></dir></dir></dir></dir><dir name="controllers"><file name="BestsellersbycategoryController.php" hash="bcb8ba02dbfbb37880830c24c88c4791"/><file name="LifetimesalesController.php" hash="36c23ba7464e5b23d7803babdc092097"/><file name="NoupsellsController.php" hash="ccdf273757694494daec860361c0ec52"/><file name="ShoppedonceController.php" hash="0c599676dbb5722feb9bc437cfb985f1"/><file name="SignedupnoorderController.php" hash="0d996537ef4affe736b1aa3437152bc6"/><file name="WishlistController.php" hash="1ee8c24d7ce1ffc28493aedba17505a5"/><file name="WorstsellersController.php" hash="20e935b7f822abd346f76e6a934234da"/><file name="WorstsellersbycategoryController.php" hash="bc37e6b7a41c4ed918018ecdf2042259"/></dir><dir name="etc"><file name="adminhtml.xml" hash="2233874893d9dcc82540d61aa0668328"/><file name="config.xml" hash="36cd854e2899d555811bd021d84550e2"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="DigitalPianism_CustomReports.xml" hash="2244af82c076ed3abf5064672036ef0b"/></dir></target><target name="magelocale"><dir name="en_US"><file name="DigitalPianism_CustomReports.csv" hash="0fcee0228d1044be8c0b76f02079bf55"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="digitalpianism"><dir name="customreports"><file name="advancedgrid.phtml" hash="0254a130e6c76bf9c8f7a9b7ce1d27ca"/><file name="grid.phtml" hash="a8d2cbad8327390e2b9cd3b7717c384d"/></dir></dir></dir></dir></dir></dir></target></contents>
56
  <compatible/>
57
  <dependencies><required><php><min>4.1.0</min><max>6.0.0</max></php></required></dependencies>
58
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>DigitalPianism_CustomReports</name>
4
+ <version>0.1.0</version>
5
  <stability>stable</stability>
6
  <license>Open GPL</license>
7
  <channel>community</channel>
48
  &lt;/ul&gt;&#xD;
49
  &#xD;
50
  &lt;p&gt;Thus, if a product is in several categories, it will be counted as a sale for all of these categories.&lt;/p&gt;</description>
51
+ <notes>- Improve memory management when dealing with large collection for all reports. 30% memory use decrease.&#xD;
52
+ - Fix a bug where people were unable to set dates for the wishlist report.</notes>
53
  <authors><author><name>Digital Pianism</name><user>digitalpianism</user><email>contact@digital-pianism.com</email></author></authors>
54
+ <date>2014-09-19</date>
55
+ <time>10:04:52</time>
56
+ <contents><target name="magecommunity"><dir name="DigitalPianism"><dir name="CustomReports"><dir name="Block"><dir name="Bestsellersbycategory"><file name="Grid.php" hash="8f8b0b637b77370d6b6590df7a6db54a"/></dir><file name="Bestsellersbycategory.php" hash="60483ad3e57dc461f5943c805d149c01"/><file name="Customreport.php" hash="e6bbb8a7baf7acc47f39b02e64ccbc94"/><dir name="Lifetimesales"><file name="Grid.php" hash="b36706d8594b934d1d13b236537b39cd"/></dir><file name="Lifetimesales.php" hash="94d685421ecb611a871d99c1c593ac46"/><dir name="Noupsells"><file name="Grid.php" hash="50d635cdc4268bde22ae7d029dfb125b"/></dir><file name="Noupsells.php" hash="bbc28aa60bd78b8c3ccf2fb94f470751"/><dir name="Shoppedonce"><file name="Grid.php" hash="28401d7c968100aec911545a8074dd70"/></dir><file name="Shoppedonce.php" hash="bc3b20a05d2859a710850cde353599d5"/><dir name="Signedupnoorder"><file name="Grid.php" hash="12e5f83a722b58818f0b01e6296eadef"/></dir><file name="Signedupnoorder.php" hash="30d952fcc1fa6e913c98134f195342eb"/><dir name="Wishlist"><file name="Grid.php" hash="1a77ff075cfda65ccee9c63d62725300"/></dir><file name="Wishlist.php" hash="873881855ff4b280b5c7ec84d7082808"/><dir name="Worstsellers"><file name="Grid.php" hash="cc386907b3d3bf89460989f948a45e81"/></dir><file name="Worstsellers.php" hash="f31350020ae1d4207a49270a226a6df4"/><dir name="Worstsellersbycategory"><file name="Grid.php" hash="cac879e7fa0bb1f74624f04cb5007ee5"/></dir><file name="Worstsellersbycategory.php" hash="4b94e31f8297c38904a073240b7af85e"/></dir><dir name="Model"><dir name="Reports"><dir name="Resource"><dir name="Product"><file name="Collection.php" hash="5e544f160b1916ce3e6c0ace949a8dc9"/></dir></dir></dir></dir><dir name="controllers"><file name="BestsellersbycategoryController.php" hash="bcb8ba02dbfbb37880830c24c88c4791"/><file name="LifetimesalesController.php" hash="36c23ba7464e5b23d7803babdc092097"/><file name="NoupsellsController.php" hash="ccdf273757694494daec860361c0ec52"/><file name="ShoppedonceController.php" hash="0c599676dbb5722feb9bc437cfb985f1"/><file name="SignedupnoorderController.php" hash="0d996537ef4affe736b1aa3437152bc6"/><file name="WishlistController.php" hash="1ee8c24d7ce1ffc28493aedba17505a5"/><file name="WorstsellersController.php" hash="20e935b7f822abd346f76e6a934234da"/><file name="WorstsellersbycategoryController.php" hash="bc37e6b7a41c4ed918018ecdf2042259"/></dir><dir name="etc"><file name="adminhtml.xml" hash="2233874893d9dcc82540d61aa0668328"/><file name="config.xml" hash="0af5b83640b8bdb629171618b0c59398"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="DigitalPianism_CustomReports.xml" hash="2244af82c076ed3abf5064672036ef0b"/></dir></target><target name="magelocale"><dir name="en_US"><file name="DigitalPianism_CustomReports.csv" hash="0fcee0228d1044be8c0b76f02079bf55"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="digitalpianism"><dir name="customreports"><file name="advancedgrid.phtml" hash="0254a130e6c76bf9c8f7a9b7ce1d27ca"/><file name="grid.phtml" hash="a8d2cbad8327390e2b9cd3b7717c384d"/></dir></dir></dir></dir></dir></dir></target></contents>
57
  <compatible/>
58
  <dependencies><required><php><min>4.1.0</min><max>6.0.0</max></php></required></dependencies>
59
  </package>