AW_Onpulse - Version 2.0.0

Version Notes

The update includes a number of all-new reports, improved sales forecast algorithm and the ability to search and view order and customer data. Here is the full list of new features:
- Ability to search and view all clients and orders by name, email or ID
- Displays sales stats as profit or revenue
- Sales by country report
- Items per order report (IPO)
- Average order value report (AOV)
- Last orders with items on the dashboard
- Improved sales forecast algorithm

Download this release

Release Info

Developer AW_Core_Team
Extension AW_Onpulse
Version 2.0.0
Comparing to
See all releases


Code changes from version 1.0.16 to 2.0.0

Files changed (41) hide show
  1. app/code/local/AW/Onpulse/Block/System/Config/Form/Fieldset/Onpulse/Access.php +18 -0
  2. app/code/local/AW/Onpulse/Block/System/Config/Form/Fieldset/Onpulse/Settings.php +0 -12
  3. app/code/local/AW/Onpulse/Helper/Data.php +137 -90
  4. app/code/local/AW/Onpulse/Model/Aggregator.php +9 -8
  5. app/code/local/AW/Onpulse/Model/Aggregator/Component.php +6 -6
  6. app/code/local/AW/Onpulse/Model/Aggregator/Components/Customer.php +69 -38
  7. app/code/local/AW/Onpulse/Model/Aggregator/Components/Order.php +115 -40
  8. app/code/local/AW/Onpulse/Model/Aggregator/Components/Statistics.php +609 -300
  9. app/code/local/AW/Onpulse/Model/Credentials.php +92 -90
  10. app/code/local/AW/Onpulse/Model/Source/OrderStatus.php +12 -0
  11. app/code/local/AW/Onpulse/Model/Source/ProfitRevenue.php +23 -0
  12. app/code/local/AW/Onpulse/controllers/Adminhtml/ConfigController.php +20 -0
  13. app/code/local/AW/Onpulse/controllers/IndexController.php +92 -51
  14. app/code/local/AW/Onpulse/etc/config.xml +14 -2
  15. app/code/local/AW/Onpulse/etc/system.xml +40 -17
  16. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-install-1.0.0.php +5 -1
  17. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.0-1.0.1.php +0 -1
  18. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.0-1.0.14.php +5 -0
  19. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.1-1.0.2.php +0 -1
  20. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.10-1.0.11.php +0 -1
  21. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.11-1.0.12.php +0 -1
  22. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.12-1.0.13.php +0 -1
  23. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.13-1.0.14.php +0 -1
  24. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.14-1.0.15.php +7 -2
  25. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.14-1.0.16.php +0 -3
  26. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.15-1.0.16.php +0 -2
  27. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.15-1.0.17.php +5 -0
  28. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.17-2.0.0.php +8 -0
  29. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.2-1.0.3.php +0 -1
  30. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.3-1.0.4.php +0 -1
  31. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.4-1.0.5.php +0 -1
  32. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.5-1.0.6.php +0 -1
  33. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.6-1.0.7.php +0 -1
  34. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.7-1.0.8.php +0 -1
  35. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.8-1.0.9.php +0 -1
  36. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.9-1.0.10.php +0 -1
  37. app/design/adminhtml/default/default/layout/aw_onpulse.xml +11 -11
  38. app/design/adminhtml/default/default/template/aw_onpulse/access.phtml +118 -0
  39. app/design/adminhtml/default/default/template/aw_onpulse/settings.phtml +0 -155
  40. app/locale/en_US/AW_Onpulse.csv +17 -13
  41. package.xml +14 -8
app/code/local/AW/Onpulse/Block/System/Config/Form/Fieldset/Onpulse/Access.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class AW_Onpulse_Block_System_Config_Form_Fieldset_Onpulse_Access
4
+ extends Mage_Adminhtml_Block_System_Config_Form_Fieldset
5
+ {
6
+ public function render(Varien_Data_Form_Element_Abstract $element)
7
+ {
8
+ $html = $this->_getHeaderHtml($element);
9
+ $html .= $this->setTemplate('aw_onpulse/access.phtml')->_toHtml();
10
+ $html .= $this->_getFooterHtml($element);
11
+ return $html;
12
+ }
13
+
14
+ public function getGenerateUrl()
15
+ {
16
+ return $this->getUrl('awonpulse_admin/adminhtml_config/generate', array('section' => 'awonpulse'));
17
+ }
18
+ }
app/code/local/AW/Onpulse/Block/System/Config/Form/Fieldset/Onpulse/Settings.php DELETED
@@ -1,12 +0,0 @@
1
- <?php
2
-
3
- class AW_Onpulse_Block_System_Config_Form_Fieldset_Onpulse_Settings extends Mage_Adminhtml_Block_System_Config_Form_Fieldset
4
- {
5
- public function render(Varien_Data_Form_Element_Abstract $element)
6
- {
7
- $html = $this->_getHeaderHtml($element);
8
- $html .=$this->setTemplate('aw_onpulse/settings.phtml')->_toHtml();
9
- $html .= $this->_getFooterHtml($element);
10
- return $html;
11
- }
12
- }
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/AW/Onpulse/Helper/Data.php CHANGED
@@ -18,26 +18,35 @@ class AW_Onpulse_Helper_Data extends Mage_Core_Helper_Abstract
18
 
19
  protected static $_platform = -1;
20
 
 
 
21
  /**
22
  * Checks which edition is used
 
23
  * @return int
24
  */
25
  public static function getPlatform()
26
  {
27
  if (self::$_platform == -1) {
28
- $pathToClaim = BP . DS . "app" . DS . "etc" . DS . "modules" . DS . self::ENTERPRISE_DETECT_COMPANY . "_" . self::ENTERPRISE_DETECT_EXTENSION . ".xml";
29
- $pathToEEConfig = BP . DS . "app" . DS . "code" . DS . "core" . DS . self::ENTERPRISE_DETECT_COMPANY . DS . self::ENTERPRISE_DETECT_EXTENSION . DS . "etc" . DS . "config.xml";
30
- $isCommunity = !file_exists($pathToClaim) || !file_exists($pathToEEConfig);
31
- if ($isCommunity) {
 
 
 
 
32
  self::$_platform = self::CE_PLATFORM;
33
  } else {
34
- $_xml = @simplexml_load_file($pathToEEConfig,'SimpleXMLElement', LIBXML_NOCDATA);
35
- if(!$_xml===FALSE) {
36
  $package = (string)$_xml->default->design->package->name;
37
  $theme = (string)$_xml->install->design->theme->default;
38
  $skin = (string)$_xml->stores->admin->design->theme->skin;
39
- $isProffessional = ($package == self::PROFESSIONAL_DESIGN_NAME) && ($theme == self::PROFESSIONAL_DESIGN_NAME) && ($skin == self::PROFESSIONAL_DESIGN_NAME);
40
- if ($isProffessional) {
 
 
41
  self::$_platform = self::PE_PLATFORM;
42
  return self::$_platform;
43
  }
@@ -49,23 +58,22 @@ class AW_Onpulse_Helper_Data extends Mage_Core_Helper_Abstract
49
  }
50
 
51
 
52
-
53
  public function getPriceFormat($price)
54
  {
55
  $price = sprintf("%01.2f", $price);
56
  return $price;
57
  }
58
 
59
- private $_countries = array();
60
-
61
- public function escapeHtml($data,$allowedTags = NULL) {
62
- if(version_compare(Mage::getVersion(),'1.4.1','<')) {
63
  $data = htmlspecialchars($data);
64
  } else {
65
  $data = parent::escapeHtml($data);
66
  }
67
  return $data;
68
  }
 
69
  private function _getItemOptions($item)
70
  {
71
  $result = array();
@@ -83,31 +91,31 @@ class AW_Onpulse_Helper_Data extends Mage_Core_Helper_Abstract
83
  return $result;
84
  }
85
 
86
- private function _getAddresInfoArray($customer, $addresType = 'billing')
87
  {
88
-
89
- if ($customer->getData("default_{$addresType}")) {
90
-
91
  //Prevent Notice if can't find country name by code
92
- $country = $customer->getData("{$addresType}_country_id");
93
- if (isset($this->_countries[$customer->getData("{$addresType}_country_id")])) {
94
- $country = $this->_countries[$customer->getData("{$addresType}_country_id")];
95
  }
96
  return array(
97
- 'first_name' => $this->escapeHtml($customer->getData("{$addresType}_firstname")),
98
- 'last_name' => $this->escapeHtml($customer->getData("{$addresType}_lastname")),
99
- 'postcode' => $this->escapeHtml($customer->getData("{$addresType}_postcode")),
100
- 'city' => $this->escapeHtml($customer->getData("{$addresType}_city")),
101
- 'street' => $this->escapeHtml($customer->getData("{$addresType}_street")),
102
- 'telephone' => $this->escapeHtml($this->escapeHtml($customer->getData("{$addresType}_telephone"))),
103
- 'region' => $this->escapeHtml($customer->getData("{$addresType}_region")),
104
- 'country' => $this->escapeHtml($country),
 
 
105
  );
106
  }
107
  return array();
108
  }
109
 
110
- private function _getAddresInfoFromOrderToArray($order)
111
  {
112
  //Prevent Notice if can't find country name by code
113
  $country = $order->getData("country_id");
@@ -116,39 +124,45 @@ class AW_Onpulse_Helper_Data extends Mage_Core_Helper_Abstract
116
  }
117
  return array(
118
  'first_name' => $this->escapeHtml($order->getData("firstname")),
119
- 'last_name' => $this->escapeHtml($order->getData("lastname")),
120
- 'postcode' => $this->escapeHtml($order->getData("postcode")),
121
- 'city' => $this->escapeHtml($order->getData("city")),
122
- 'street' => $this->escapeHtml($order->getData("street")),
123
- 'telephone' => $this->escapeHtml($order->getData("telephone")),
124
- 'region' => $this->escapeHtml($order->getData("region")),
125
- 'country' => $this->escapeHtml($country),
126
  );
127
  }
128
 
129
  private function _getCustomersRecentOrders($customer)
130
  {
131
- if(version_compare(Mage::getVersion(),'1.4.1','<')) {
132
- $orderCollection=Mage::getModel('awonpulse/aggregator_components_order')->getCollectionForOldMegento();
 
 
133
  } else {
134
- /** @var $orderCollection Mage_Sales_Model_Resource_Order_Collection */
135
- $orderCollection = Mage::getModel('sales/order')->getCollection();
136
- $orderCollection->addAddressFields()
137
- ->addAttributeToSelect('*')
138
- ->addOrder('entity_id', 'DESC');
 
139
  }
140
- $orderCollection->addAttributeToFilter('customer_id', array('eq' => $customer->getId()))
141
- ->setPageSize(self::RECENT_ORDERS_COUNT);
 
 
142
  return $orderCollection;
143
  }
144
 
145
  private function _getProductsArrayFromOrder($order)
146
  {
147
  $products = array();
148
-
149
  foreach ($order->getItemsCollection() as $item) {
150
  $product = array();
151
- if ($item->getParentItem()) continue;
 
 
152
  if ($_options = $this->_getItemOptions($item)) {
153
  foreach ($_options as $_option) {
154
  $product['options'][$_option['label']] = $_option['value'];
@@ -165,25 +179,22 @@ class AW_Onpulse_Helper_Data extends Mage_Core_Helper_Abstract
165
 
166
  public function processOutput($data)
167
  {
168
- $this->dateTimeFormat = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
 
 
169
  $clients = $data->getData('clients');
170
  $orders = $data->getData('orders');
171
  $dashboard = $data->getData('dashboard');
172
  $processedClients = array();
173
- $processedDashboardClients = array();
174
  $processedOrders = array();
175
  foreach (Mage::helper('directory')->getCountryCollection() as $country) {
176
  $this->_countries[$country->getId()] = $country->getName();
177
  }
178
 
179
- if ($clients->getSize())
180
- foreach ($clients as $customer) {
181
- $processedClients[] = $this->processCustomerToArray($customer, true);
182
-
183
- }
184
-
185
- if($orders->getSize())
186
- foreach($orders as $order) {
187
  $processedOrders[] = $this->processOrderToArray($order);
188
  }
189
 
@@ -200,58 +211,84 @@ class AW_Onpulse_Helper_Data extends Mage_Core_Helper_Abstract
200
  $processedDashboardClientsYesterday[] = $this->processCustomerToArray($customer, true);
201
  }
202
  }
203
- $dashboard['customers']['today_customers']['registered'] = count($processedDashboardClientsToday);
204
- $dashboard['customers']['yesterday_customers']['registered'] = count($processedDashboardClientsYesterday);
 
 
 
 
205
 
206
  return array(
207
  'connector_version' => (string)Mage::getConfig()->getNode()->modules->AW_Onpulse->version,
208
- 'price_format' =>Mage::app()->getLocale()->getJsPriceFormat(),
209
- 'clients' => $processedClients,
210
- 'orders' => $processedOrders,
211
- 'dashboard' => $dashboard,
212
- 'storename' => strip_tags(Mage::getStoreConfig('general/store_information/name')),
213
- 'curSymbol' => Mage::app()->getLocale()->currency(Mage::app()->getStore()->getBaseCurrencyCode())->getSymbol(),
 
 
214
  );
215
  }
216
 
217
 
218
  public function processOrderToArray($order)
219
  {
220
-
221
  $customer = '';
222
  if ($order->getCustomerId()) {
223
  $customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
224
- if ($customer)
225
  $customer = $this->processCustomerToArray($customer);
 
226
  }
227
- if(!$order->getGiftCardsAmount()) {
228
  $order->setGiftCardsAmount(0);
229
  }
230
 
231
  $orderInfo = array(
232
- 'increment_id' => $order->getIncrementId(),
233
- 'creation_date' => $order->getCreatedAtFormated($this->dateTimeFormat)->toString($this->dateTimeFormat),
 
 
234
  'customer_firstname' => $this->escapeHtml($order->getCustomerFirstname()),
235
- 'customer_lastname' => $this->escapeHtml($order->getCustomerLastname()),
236
- 'customer_email' => $order->getCustomerEmail(),
237
- 'status_code' => $order->getStatus(),
238
- 'status' => htmlspecialchars($order->getStatusLabel()),
239
- 'subtotal' => $this->getPriceFormat($order->getBaseSubtotal()),
240
- 'discount' => $this->getPriceFormat($order->getBaseDiscountAmount()),
241
- 'grand_total' => $this->getPriceFormat($order->getBaseGrandTotal()),
242
- 'shipping_amount' => $this->getPriceFormat($order->getBaseShippingAmount()),
243
- 'tax' => $this->getPriceFormat($order->getBaseTaxAmount()),
244
- 'gift_cards_amount' => $this->getPriceFormat($order->getGiftCardsAmount()),
245
- 'currency' => Mage::app()->getLocale()->currency(Mage::app()->getStore()->getBaseCurrencyCode())->getSymbol(),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
246
 
247
  //-----------------------------------------------------
248
- 'items' => $this->_getProductsArrayFromOrder($order),
249
- 'customer' => $customer,
250
- 'billing' => $this->_getAddresInfoFromOrderToArray($order->getBillingAddress()),
 
 
251
  );
252
 
253
  if (!$order->getIsVirtual()) {
254
- $orderInfo['shipping'] = $this->_getAddresInfoFromOrderToArray($order->getShippingAddress());
 
 
255
  }
256
 
257
  return $orderInfo;
@@ -267,24 +304,34 @@ class AW_Onpulse_Helper_Data extends Mage_Core_Helper_Abstract
267
  $client['last_name'] = $this->escapeHtml($customer->getLastname());
268
  $client['email'] = $customer->getEmail();
269
  //$client['date_registered'] = $customer->getCreatedAt();
270
- $client['date_registered'] = Mage::app()->getLocale()->date($customer->getCreatedAt())->toString($this->dateTimeFormat);
 
 
271
 
272
  $client['country'] = '';
273
  if ($customer->getData('billing_country_id')) {
274
- $client['country'] = $this->_countries[$customer->getData('billing_country_id')];
 
 
275
  }
276
 
277
  $client['phone'] = '';
278
  if ($customer->getData('billing_telephone')) {
279
- $client['phone'] = $this->escapeHtml($customer->getData('billing_telephone'));
 
 
280
  }
281
 
282
  if ($additional) {
283
  // Format billing address data
284
- $client['billing'] = $this->_getAddresInfoArray($customer, 'billing');
 
 
285
 
286
  // Format shipping address data
287
- $client['shipping'] = $this->_getAddresInfoArray($customer, 'shipping');
 
 
288
 
289
  $orders = $this->_getCustomersRecentOrders($customer);
290
  $customerOrders = array();
18
 
19
  protected static $_platform = -1;
20
 
21
+ private $_countries = array();
22
+
23
  /**
24
  * Checks which edition is used
25
+ *
26
  * @return int
27
  */
28
  public static function getPlatform()
29
  {
30
  if (self::$_platform == -1) {
31
+ $pathToClaim = BP . DS . "app" . DS . "etc" . DS . "modules" . DS . self::ENTERPRISE_DETECT_COMPANY . "_"
32
+ . self::ENTERPRISE_DETECT_EXTENSION . ".xml"
33
+ ;
34
+ $pathToEEConfig = BP . DS . "app" . DS . "code" . DS . "core" . DS
35
+ . self::ENTERPRISE_DETECT_COMPANY . DS . self::ENTERPRISE_DETECT_EXTENSION . DS . "etc" . DS
36
+ . "config.xml"
37
+ ;
38
+ if (!file_exists($pathToClaim) || !file_exists($pathToEEConfig)) {
39
  self::$_platform = self::CE_PLATFORM;
40
  } else {
41
+ $_xml = @simplexml_load_file($pathToEEConfig, 'SimpleXMLElement', LIBXML_NOCDATA);
42
+ if (!$_xml === false) {
43
  $package = (string)$_xml->default->design->package->name;
44
  $theme = (string)$_xml->install->design->theme->default;
45
  $skin = (string)$_xml->stores->admin->design->theme->skin;
46
+ $isProfessional = ($package == self::PROFESSIONAL_DESIGN_NAME)
47
+ && ($theme == self::PROFESSIONAL_DESIGN_NAME) && ($skin == self::PROFESSIONAL_DESIGN_NAME)
48
+ ;
49
+ if ($isProfessional) {
50
  self::$_platform = self::PE_PLATFORM;
51
  return self::$_platform;
52
  }
58
  }
59
 
60
 
 
61
  public function getPriceFormat($price)
62
  {
63
  $price = sprintf("%01.2f", $price);
64
  return $price;
65
  }
66
 
67
+ public function escapeHtml($data, $allowedTags = null)
68
+ {
69
+ if (version_compare(Mage::getVersion(), '1.4.1', '<')) {
 
70
  $data = htmlspecialchars($data);
71
  } else {
72
  $data = parent::escapeHtml($data);
73
  }
74
  return $data;
75
  }
76
+
77
  private function _getItemOptions($item)
78
  {
79
  $result = array();
91
  return $result;
92
  }
93
 
94
+ private function _getAddressInfoArray($customer, $addressType = 'billing')
95
  {
96
+ if ($customer->getData("default_{$addressType}")) {
 
 
97
  //Prevent Notice if can't find country name by code
98
+ $country = $customer->getData("{$addressType}_country_id");
99
+ if (isset($this->_countries[$customer->getData("{$addressType}_country_id")])) {
100
+ $country = $this->_countries[$customer->getData("{$addressType}_country_id")];
101
  }
102
  return array(
103
+ 'first_name' => $this->escapeHtml($customer->getData("{$addressType}_firstname")),
104
+ 'last_name' => $this->escapeHtml($customer->getData("{$addressType}_lastname")),
105
+ 'postcode' => $this->escapeHtml($customer->getData("{$addressType}_postcode")),
106
+ 'city' => $this->escapeHtml($customer->getData("{$addressType}_city")),
107
+ 'street' => $this->escapeHtml($customer->getData("{$addressType}_street")),
108
+ 'telephone' => $this->escapeHtml(
109
+ $this->escapeHtml($customer->getData("{$addressType}_telephone"))
110
+ ),
111
+ 'region' => $this->escapeHtml($customer->getData("{$addressType}_region")),
112
+ 'country' => $this->escapeHtml($country),
113
  );
114
  }
115
  return array();
116
  }
117
 
118
+ private function _getAddressInfoFromOrderToArray($order)
119
  {
120
  //Prevent Notice if can't find country name by code
121
  $country = $order->getData("country_id");
124
  }
125
  return array(
126
  'first_name' => $this->escapeHtml($order->getData("firstname")),
127
+ 'last_name' => $this->escapeHtml($order->getData("lastname")),
128
+ 'postcode' => $this->escapeHtml($order->getData("postcode")),
129
+ 'city' => $this->escapeHtml($order->getData("city")),
130
+ 'street' => $this->escapeHtml($order->getData("street")),
131
+ 'telephone' => $this->escapeHtml($order->getData("telephone")),
132
+ 'region' => $this->escapeHtml($order->getData("region")),
133
+ 'country' => $this->escapeHtml($country),
134
  );
135
  }
136
 
137
  private function _getCustomersRecentOrders($customer)
138
  {
139
+ if (version_compare(Mage::getVersion(), '1.4.1.0', '<=')) {
140
+ $orderCollection = Mage::getModel(
141
+ 'awonpulse/aggregator_components_order'
142
+ )->getCollectionForOldMagento();
143
  } else {
144
+ /** @var $orderCollection Mage_Sales_Model_Resource_Order_Collection */
145
+ $orderCollection = Mage::getModel('sales/order')->getCollection();
146
+ $orderCollection->addAddressFields()
147
+ ->addAttributeToSelect('*')
148
+ ->addOrder('entity_id', 'DESC')
149
+ ;
150
  }
151
+ $orderCollection
152
+ ->addAttributeToFilter('main_table.customer_id', array('eq' => $customer->getId()))
153
+ ->setPageSize(self::RECENT_ORDERS_COUNT)
154
+ ;
155
  return $orderCollection;
156
  }
157
 
158
  private function _getProductsArrayFromOrder($order)
159
  {
160
  $products = array();
 
161
  foreach ($order->getItemsCollection() as $item) {
162
  $product = array();
163
+ if ($item->getParentItem()) {
164
+ continue;
165
+ }
166
  if ($_options = $this->_getItemOptions($item)) {
167
  foreach ($_options as $_option) {
168
  $product['options'][$_option['label']] = $_option['value'];
179
 
180
  public function processOutput($data)
181
  {
182
+ $this->dateTimeFormat = Mage::app()->getLocale()->getDateTimeFormat(
183
+ Mage_Core_Model_Locale::FORMAT_TYPE_SHORT
184
+ );
185
  $clients = $data->getData('clients');
186
  $orders = $data->getData('orders');
187
  $dashboard = $data->getData('dashboard');
188
  $processedClients = array();
 
189
  $processedOrders = array();
190
  foreach (Mage::helper('directory')->getCountryCollection() as $country) {
191
  $this->_countries[$country->getId()] = $country->getName();
192
  }
193
 
194
+ foreach ($clients as $customer) {
195
+ $processedClients[] = $this->processCustomerToArray($customer, true);
196
+ }
197
+ foreach ($orders as $order) {
 
 
 
 
198
  $processedOrders[] = $this->processOrderToArray($order);
199
  }
200
 
211
  $processedDashboardClientsYesterday[] = $this->processCustomerToArray($customer, true);
212
  }
213
  }
214
+ $dashboard['customers']['today_customers']['registered'] = count(
215
+ $processedDashboardClientsToday
216
+ );
217
+ $dashboard['customers']['yesterday_customers']['registered'] = count(
218
+ $processedDashboardClientsYesterday
219
+ );
220
 
221
  return array(
222
  'connector_version' => (string)Mage::getConfig()->getNode()->modules->AW_Onpulse->version,
223
+ 'price_format' => Mage::app()->getLocale()->getJsPriceFormat(),
224
+ 'clients' => $processedClients,
225
+ 'orders' => $processedOrders,
226
+ 'dashboard' => $dashboard,
227
+ 'storename' => strip_tags(Mage::getStoreConfig('general/store_information/name')),
228
+ 'curSymbol' => Mage::app()->getLocale()->currency(
229
+ Mage::app()->getStore()->getBaseCurrencyCode()
230
+ )->getSymbol(),
231
  );
232
  }
233
 
234
 
235
  public function processOrderToArray($order)
236
  {
 
237
  $customer = '';
238
  if ($order->getCustomerId()) {
239
  $customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
240
+ if ($customer) {
241
  $customer = $this->processCustomerToArray($customer);
242
+ }
243
  }
244
+ if (!$order->getGiftCardsAmount()) {
245
  $order->setGiftCardsAmount(0);
246
  }
247
 
248
  $orderInfo = array(
249
+ 'increment_id' => $order->getIncrementId(),
250
+ 'creation_date' => $order->getCreatedAtFormated($this->dateTimeFormat)->toString(
251
+ $this->dateTimeFormat
252
+ ),
253
  'customer_firstname' => $this->escapeHtml($order->getCustomerFirstname()),
254
+ 'customer_lastname' => $this->escapeHtml($order->getCustomerLastname()),
255
+ 'customer_email' => $order->getCustomerEmail(),
256
+ 'status_code' => $order->getStatus(),
257
+ 'status' => htmlspecialchars($order->getStatusLabel()),
258
+ 'subtotal' => $this->getPriceFormat(
259
+ $order->getBaseSubtotal()
260
+ ),
261
+ 'discount' => $this->getPriceFormat(
262
+ $order->getBaseDiscountAmount()
263
+ ),
264
+ 'grand_total' => $this->getPriceFormat(
265
+ $order->getBaseGrandTotal()
266
+ ),
267
+ 'shipping_amount' => $this->getPriceFormat(
268
+ $order->getBaseShippingAmount()
269
+ ),
270
+ 'tax' => $this->getPriceFormat(
271
+ $order->getBaseTaxAmount()
272
+ ),
273
+ 'gift_cards_amount' => -$this->getPriceFormat(
274
+ $order->getGiftCardsAmount()
275
+ ),
276
+ 'currency' => Mage::app()->getLocale()->currency(
277
+ Mage::app()->getStore()->getBaseCurrencyCode()
278
+ )->getSymbol(),
279
 
280
  //-----------------------------------------------------
281
+ 'items' => $this->_getProductsArrayFromOrder($order),
282
+ 'customer' => $customer,
283
+ 'billing' => $this->_getAddressInfoFromOrderToArray(
284
+ $order->getBillingAddress()
285
+ ),
286
  );
287
 
288
  if (!$order->getIsVirtual()) {
289
+ $orderInfo['shipping'] = $this->_getAddressInfoFromOrderToArray(
290
+ $order->getShippingAddress()
291
+ );
292
  }
293
 
294
  return $orderInfo;
304
  $client['last_name'] = $this->escapeHtml($customer->getLastname());
305
  $client['email'] = $customer->getEmail();
306
  //$client['date_registered'] = $customer->getCreatedAt();
307
+ $client['date_registered'] = Mage::app()->getLocale()->date(
308
+ $customer->getCreatedAt()
309
+ )->toString($this->dateTimeFormat);
310
 
311
  $client['country'] = '';
312
  if ($customer->getData('billing_country_id')) {
313
+ $client['country'] = $this->_countries[$customer->getData(
314
+ 'billing_country_id'
315
+ )];
316
  }
317
 
318
  $client['phone'] = '';
319
  if ($customer->getData('billing_telephone')) {
320
+ $client['phone'] = $this->escapeHtml(
321
+ $customer->getData('billing_telephone')
322
+ );
323
  }
324
 
325
  if ($additional) {
326
  // Format billing address data
327
+ $client['billing'] = $this->_getAddressInfoArray(
328
+ $customer, 'billing'
329
+ );
330
 
331
  // Format shipping address data
332
+ $client['shipping'] = $this->_getAddressInfoArray(
333
+ $customer, 'shipping'
334
+ );
335
 
336
  $orders = $this->_getCustomersRecentOrders($customer);
337
  $customerOrders = array();
app/code/local/AW/Onpulse/Model/Aggregator.php CHANGED
@@ -1,9 +1,10 @@
1
- <?php
2
-
3
- class AW_Onpulse_Model_Aggregator extends Mage_Core_Model_Abstract
4
- {
5
- public function Aggregate() {
6
- Mage::dispatchEvent('onpulse_aggregate_data',array('aggregator'=>$this));
7
- return $this;
8
- }
 
9
  }
1
+ <?php
2
+
3
+ class AW_Onpulse_Model_Aggregator extends Mage_Core_Model_Abstract
4
+ {
5
+ public function Aggregate()
6
+ {
7
+ Mage::dispatchEvent('onpulse_aggregate_data', array('aggregator' => $this));
8
+ return $this;
9
+ }
10
  }
app/code/local/AW/Onpulse/Model/Aggregator/Component.php CHANGED
@@ -1,6 +1,6 @@
1
- <?php
2
-
3
- abstract class AW_Onpulse_Model_Aggregator_Component extends Mage_Core_Model_Abstract
4
- {
5
- public function pushData($event){}
6
- }
1
+ <?php
2
+
3
+ abstract class AW_Onpulse_Model_Aggregator_Component extends Mage_Core_Model_Abstract
4
+ {
5
+ public function pushData($event = null){}
6
+ }
app/code/local/AW/Onpulse/Model/Aggregator/Components/Customer.php CHANGED
@@ -1,38 +1,69 @@
1
- <?php
2
-
3
- class AW_Onpulse_Model_Aggregator_Components_Customer extends AW_Onpulse_Model_Aggregator_Component
4
- {
5
- const COUNT_CUSTOMERS = 5;
6
-
7
- public function pushData($event = null)
8
- {
9
-
10
- /** @var $customerCollection Mage_Customer_Model_Resource_Customer_Collection */
11
- $customerCollection = Mage::getModel('customer/customer')->getCollection()
12
- ->setPageSize(self::COUNT_CUSTOMERS)
13
- ->addNameToSelect()
14
- ->addAttributeToSelect('email')
15
- ->addAttributeToSelect('created_at')
16
- ->joinAttribute('billing_firstname', 'customer_address/firstname', 'default_billing', null, 'left')
17
- ->joinAttribute('billing_lastname', 'customer_address/lastname', 'default_billing', null, 'left')
18
- ->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
19
- ->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
20
- ->joinAttribute('billing_street', 'customer_address/street', 'default_billing', null, 'left')
21
- ->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')
22
- ->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
23
- ->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left')
24
- ->joinAttribute('shipping_firstname', 'customer_address/firstname', 'default_shipping', null, 'left')
25
- ->joinAttribute('shipping_lastname', 'customer_address/lastname', 'default_shipping', null, 'left')
26
- ->joinAttribute('shipping_postcode', 'customer_address/postcode', 'default_shipping', null, 'left')
27
- ->joinAttribute('shipping_city', 'customer_address/city', 'default_shipping', null, 'left')
28
- ->joinAttribute('shipping_street', 'customer_address/street', 'default_shipping', null, 'left')
29
- ->joinAttribute('shipping_telephone', 'customer_address/telephone', 'default_shipping', null, 'left')
30
- ->joinAttribute('shipping_region', 'customer_address/region', 'default_shipping', null, 'left')
31
- ->joinAttribute('shipping_country_id', 'customer_address/country_id', 'default_shipping', null, 'left');
32
- $customerCollection->getSelect()->order('entity_id DESC');
33
-
34
- $aggregator = $event->getEvent()->getAggregator();
35
-
36
- $aggregator->setData('clients', $customerCollection->load());
37
- }
38
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class AW_Onpulse_Model_Aggregator_Components_Customer extends AW_Onpulse_Model_Aggregator_Component
4
+ {
5
+ const COUNT_CUSTOMERS = 30;
6
+
7
+ public function pushData($event = null)
8
+ {
9
+ $customerCollection = $this->_getCustomerCollection();
10
+ $aggregator = $event->getEvent()->getAggregator();
11
+ $aggregator->setData('clients', $customerCollection->load());
12
+ }
13
+
14
+ public function pushSearchedData($aggregator, $query)
15
+ {
16
+ $customerCollection = $this->_getCustomerCollection();
17
+ if (strpos($query, '@') !== FALSE) {
18
+ $customerCollection->addAttributeToFilter('email', array('like' => '%' . $query . '%'));
19
+ } else {
20
+ $countryOptionArray = Mage::helper('directory')->getCountryCollection()->toOptionArray(false);
21
+ $countryResultIdList = array();
22
+ foreach ($countryOptionArray as $option) {
23
+ if (stripos($option['label'], $query) !== FALSE) {
24
+ $countryResultIdList[] = $option['value'];
25
+ }
26
+ }
27
+ $customerCollection->addAttributeToFilter(array(
28
+ array('attribute' => 'email', 'like' => '%' . $query . '%'),
29
+ array('attribute' => 'firstname', 'like' => '%' . $query . '%'),
30
+ array('attribute' => 'lastname', 'like' => '%' . $query . '%'),
31
+ array('attribute' => 'billing_postcode', 'like' => '%' . $query . '%'),
32
+ array('attribute' => 'billing_country_id', 'in' => $countryResultIdList)
33
+ ));
34
+ }
35
+ $aggregator->setData('clients', $customerCollection->load());
36
+ }
37
+
38
+ /**
39
+ * @return Mage_Customer_Model_Resource_Customer_Collection
40
+ */
41
+ protected function _getCustomerCollection()
42
+ {
43
+ /** @var $customerCollection Mage_Customer_Model_Resource_Customer_Collection */
44
+ $customerCollection = Mage::getModel('customer/customer')->getCollection()
45
+ ->setPageSize(self::COUNT_CUSTOMERS)
46
+ ->addNameToSelect()
47
+ ->addAttributeToSelect('email')
48
+ ->addAttributeToSelect('created_at')
49
+ ->joinAttribute('billing_firstname', 'customer_address/firstname', 'default_billing', null, 'left')
50
+ ->joinAttribute('billing_lastname', 'customer_address/lastname', 'default_billing', null, 'left')
51
+ ->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
52
+ ->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
53
+ ->joinAttribute('billing_street', 'customer_address/street', 'default_billing', null, 'left')
54
+ ->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')
55
+ ->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
56
+ ->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left')
57
+ ->joinAttribute('shipping_firstname', 'customer_address/firstname', 'default_shipping', null, 'left')
58
+ ->joinAttribute('shipping_lastname', 'customer_address/lastname', 'default_shipping', null, 'left')
59
+ ->joinAttribute('shipping_postcode', 'customer_address/postcode', 'default_shipping', null, 'left')
60
+ ->joinAttribute('shipping_city', 'customer_address/city', 'default_shipping', null, 'left')
61
+ ->joinAttribute('shipping_street', 'customer_address/street', 'default_shipping', null, 'left')
62
+ ->joinAttribute('shipping_telephone', 'customer_address/telephone', 'default_shipping', null, 'left')
63
+ ->joinAttribute('shipping_region', 'customer_address/region', 'default_shipping', null, 'left')
64
+ ->joinAttribute('shipping_country_id', 'customer_address/country_id', 'default_shipping', null, 'left')
65
+ ;
66
+ $customerCollection->getSelect()->order('entity_id DESC');
67
+ return $customerCollection;
68
+ }
69
+ }
app/code/local/AW/Onpulse/Model/Aggregator/Components/Order.php CHANGED
@@ -1,40 +1,115 @@
1
- <?php
2
-
3
- class AW_Onpulse_Model_Aggregator_Components_Order extends AW_Onpulse_Model_Aggregator_Component
4
- {
5
- const COUNT_CUSTOMERS = 5;
6
-
7
- public function getCollectionForOldMegento()
8
- {
9
- $collection = Mage::getResourceModel('sales/order_collection')
10
- ->addAttributeToSelect('*')
11
- ->joinAttribute('billing_firstname', 'order_address/firstname', 'billing_address_id', null, 'left')
12
- ->joinAttribute('billing_lastname', 'order_address/lastname', 'billing_address_id', null, 'left')
13
- ->joinAttribute('shipping_firstname', 'order_address/firstname', 'shipping_address_id', null, 'left')
14
- ->joinAttribute('shipping_lastname', 'order_address/lastname', 'shipping_address_id', null, 'left')
15
- ->addExpressionAttributeToSelect('billing_name',
16
- 'CONCAT({{billing_firstname}}, " ", {{billing_lastname}})',
17
- array('billing_firstname', 'billing_lastname'))
18
- ->addExpressionAttributeToSelect('shipping_name',
19
- 'CONCAT({{shipping_firstname}}, " ", {{shipping_lastname}})',
20
- array('shipping_firstname', 'shipping_lastname'));
21
-
22
- return $collection;
23
- }
24
-
25
- public function pushData($event = null){
26
-
27
- if(version_compare(Mage::getVersion(),'1.4.1','<')) {
28
- $orderCollection=$this->getCollectionForOldMegento();
29
- } else {
30
- $orderCollection = Mage::getModel('sales/order')->getCollection()
31
- ->addAddressFields()
32
- ->addAttributeToSelect('*')
33
- ->addOrder('entity_id','DESC')
34
- ->setPageSize(self::COUNT_CUSTOMERS);
35
- }
36
- $aggregator = $event->getEvent()->getAggregator();
37
-
38
- $aggregator->setData('orders', $orderCollection->load());
39
- }
40
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class AW_Onpulse_Model_Aggregator_Components_Order extends AW_Onpulse_Model_Aggregator_Component
4
+ {
5
+ const COUNT_ORDERS = 30;
6
+
7
+ public function getCollectionForOldMagento()
8
+ {
9
+ $collection = Mage::getResourceModel('sales/order_collection')
10
+ ->addAttributeToSelect('*')
11
+ ;
12
+ $collection = $this->_addAddressFields($collection);
13
+ if (!method_exists(get_class($collection), 'addExpressionFieldToSelect')) {
14
+ $collection
15
+ ->getSelect()
16
+ ->columns(array('billing_name' => 'CONCAT(billing_o_a.firstname, " ",billing_o_a.lastname)'))
17
+ ->columns(array('shipping_name' => 'CONCAT(shipping_o_a.firstname, " ",shipping_o_a.lastname)'))
18
+ ;
19
+ } else {
20
+ $collection
21
+ ->_addExpressionFieldToSelect('billing_name',
22
+ 'CONCAT({{billing_firstname}}, " ", {{billing_lastname}})',
23
+ array('billing_firstname', 'billing_lastname')
24
+ )
25
+ ->_addExpressionFieldToSelect('shipping_name',
26
+ 'CONCAT({{shipping_firstname}}, " ", {{shipping_lastname}})',
27
+ array('shipping_firstname', 'shipping_lastname')
28
+ )
29
+ ;
30
+ }
31
+ return $collection;
32
+ }
33
+
34
+ public function pushData($event = null)
35
+ {
36
+ $orderCollection = $this->_getOrderCollection();
37
+ $aggregator = $event->getEvent()->getAggregator();
38
+ $aggregator->setData('orders', $orderCollection->load());
39
+ }
40
+
41
+ public function pushSearchedData($aggregator, $query)
42
+ {
43
+ /** @var Mage_Sales_Model_Mysql4_Order_Collection $orderCollection */
44
+ $orderCollection = $this->_getOrderCollection();
45
+
46
+ if (strpos($query, '/') !== FALSE) {
47
+ $date = new Zend_Date($query, 'dd/MM/YYYY');
48
+ $orderCollection->addAttributeToSearchFilter(
49
+ 'created_at', array('like' => $date->toString('YYYY-MM-dd') . '%')
50
+ );
51
+ } else if (strpos($query, '#') !== FALSE) {
52
+ $orderCollection->addAttributeToSearchFilter(
53
+ 'increment_id', array('like' => str_replace('#', '', $query) . '%')
54
+ );
55
+ } else if (is_numeric($query) !== FALSE) {
56
+ $orderCollection->addAttributeToSearchFilter('increment_id', array('like' => '%' . $query . '%'));
57
+ } else if (strpos($query, '@') !== FALSE) {
58
+ $orderCollection->addAttributeToSearchFilter('customer_email', array('like' => '%' . $query . '%'));
59
+ } else {
60
+ $orderCollection
61
+ ->addFieldToSearchFilter('customer_firstname', array('like' => '%' . $query . '%'))
62
+ ->addFieldToSearchFilter('customer_lastname', array('like' => '%' . $query . '%'));
63
+ ;
64
+ }
65
+ $aggregator->setData('orders', $orderCollection->load());
66
+ }
67
+
68
+ protected function _getOrderCollection()
69
+ {
70
+ if (version_compare(Mage::getVersion(), '1.4.1.0', '<=')) {
71
+ $orderCollection = $this->getCollectionForOldMagento();
72
+ $orderCollection
73
+ ->addOrder('entity_id', 'DESC')
74
+ ->setPageSize(self::COUNT_ORDERS);
75
+ } else {
76
+ $orderCollection = Mage::getModel('sales/order')->getCollection()
77
+ ->addAddressFields()
78
+ ->addAttributeToSelect('*')
79
+ ->addOrder('entity_id', 'DESC')
80
+ ->setPageSize(self::COUNT_ORDERS);
81
+ }
82
+ return $orderCollection;
83
+ }
84
+
85
+ protected function _addAddressFields($collection)
86
+ {
87
+ $billingAliasName = 'billing_o_a';
88
+ $shippingAliasName = 'shipping_o_a';
89
+ $joinTable = $collection->getTable('sales/order_address');
90
+ $collection
91
+ ->getSelect()
92
+ ->joinLeft(
93
+ array($billingAliasName => $joinTable),
94
+ "(main_table.entity_id = $billingAliasName.parent_id AND $billingAliasName.address_type = 'billing')",
95
+ array(
96
+ $billingAliasName . '.firstname',
97
+ $billingAliasName . '.lastname',
98
+ $billingAliasName . '.telephone',
99
+ $billingAliasName . '.postcode'
100
+ )
101
+ )
102
+ ->joinLeft(
103
+ array($shippingAliasName => $joinTable),
104
+ "(main_table.entity_id = $shippingAliasName.parent_id AND $shippingAliasName.address_type = 'shipping')",
105
+ array(
106
+ $shippingAliasName . '.firstname',
107
+ $shippingAliasName . '.lastname',
108
+ $shippingAliasName . '.telephone',
109
+ $shippingAliasName . '.postcode'
110
+ )
111
+ )
112
+ ;
113
+ return $collection;
114
+ }
115
+ }
app/code/local/AW/Onpulse/Model/Aggregator/Components/Statistics.php CHANGED
@@ -1,300 +1,609 @@
1
- <?php
2
-
3
- class AW_Onpulse_Model_Aggregator_Components_Statistics extends AW_Onpulse_Model_Aggregator_Component
4
- {
5
- /**
6
- * How much last registered customers is to display
7
- */
8
- const COUNT_CUSTOMERS = 5;
9
-
10
- const MYSQL_DATE_FORMAT = 'Y-d-m';
11
-
12
- const BESTSELLERS_DAYS_PERIOD = 15;
13
-
14
- /**
15
- * @return Zend_Date
16
- */
17
- private function _getShiftedDate()
18
- {
19
- $timeShift = Mage::app()->getLocale()->date()->get(Zend_Date::TIMEZONE_SECS);
20
- $now = date(self::MYSQL_DATE_FORMAT, time() + $timeShift);
21
- $now = new Zend_Date($now);
22
- return $now;
23
- }
24
-
25
- /**
26
- * @return Zend_Date
27
- */
28
- private function _getCurrentDate()
29
- {
30
- $now = Mage::app()->getLocale()->date();
31
- $dateObj = Mage::app()->getLocale()->date(null, null, Mage::app()->getLocale()->getDefaultLocale(), false);
32
-
33
- //set default timezone for store (admin)
34
- $dateObj->setTimezone(Mage::app()->getStore()->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE));
35
-
36
- //set begining of day
37
- $dateObj->setHour(00);
38
- $dateObj->setMinute(00);
39
- $dateObj->setSecond(00);
40
-
41
- //set date with applying timezone of store
42
- $dateObj->set($now, Zend_Date::DATE_SHORT, Mage::app()->getLocale()->getDefaultLocale());
43
-
44
- //convert store date to default date in UTC timezone without DST
45
- $dateObj->setTimezone(Mage_Core_Model_Locale::DEFAULT_TIMEZONE);
46
-
47
- return $dateObj;
48
- }
49
-
50
- /**
51
- * @param $event
52
- */
53
- public function pushData($event)
54
- {
55
- $aggregator = $event->getEvent()->getAggregator();
56
- $dashboard = array();
57
- $today = $this->_getCurrentDate();
58
-
59
- //Load sales revenue
60
- $dashboard['sales'] = $this->_getSales(clone $today);
61
-
62
- //Load last orders
63
- $dashboard['orders'] = $this->_getOrders(clone $today);
64
-
65
- //Load last customer registrations
66
- $dashboard['customers'] = $this->_getCustomers(clone $today);
67
-
68
- //Load best selling products
69
- $dashboard['bestsellers'] = $this->_getBestsellers(clone $today);
70
-
71
- $aggregator->setData('dashboard',$dashboard);
72
- }
73
-
74
- /**
75
- * @param Zend_Date $date
76
- *
77
- * @return array
78
- */
79
- private function _getByers(Zend_Date $date) {
80
- /** @var $todayRegistered Mage_Customer_Model_Resource_Customer_Collection */
81
- $todayRegistered = Mage::getModel('customer/customer')->getCollection();
82
- $todayRegistered->addAttributeToFilter('created_at', array(
83
- 'from' => $date->toString(Varien_Date::DATETIME_INTERNAL_FORMAT),
84
- 'to' => $date->addDay(1)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)
85
- ));
86
- $todayRegistered->addAttributeToSelect('*');
87
-
88
- $date->addDay(-1);
89
- /* @var $collection Mage_Reports_Model_Mysql4_Order_Collection */
90
- $customerArray = array();
91
- $todayOrders = Mage::getModel('sales/order')->getCollection();
92
- $todayOrders->addAttributeToFilter('created_at', array(
93
- 'from' => $date->toString(Varien_Date::DATETIME_INTERNAL_FORMAT),
94
- 'to' => $date->addDay(1)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)
95
- ));
96
- foreach ($todayOrders as $order) {
97
- if ($order->getCustomerId()){
98
- $customerArray[] = $order->getCustomerId();
99
- }
100
- }
101
- $customerArray = array_unique($customerArray);
102
- $buyers = count($customerArray);
103
- return array(
104
- 'buyers'=>$buyers,
105
- 'registered'=>$todayRegistered,
106
- );
107
- }
108
-
109
- /**
110
- * @param Zend_Date $date
111
- *
112
- * @return array
113
- */
114
- private function _getCustomers(Zend_Date $date)
115
- {
116
- //collect online visitors
117
- $online = Mage::getModel('log/visitor_online')
118
- ->prepare()
119
- ->getCollection()->addFieldToFilter('remote_addr',array('neq'=>Mage::helper('core/http')->getRemoteAddr(true)))->getSize();
120
- $todayCustomers = $this->_getByers($date);
121
- $yesterdayCustomers = $this->_getByers($date->addDay(-2));
122
-
123
- return array('online_visistors' => $online, 'today_customers' => $todayCustomers, 'yesterday_customers' => $yesterdayCustomers);
124
- }
125
-
126
- /**
127
- * @param Zend_Date $date
128
- *
129
- * @return array
130
- */
131
- private function _getBestsellers(Zend_Date $date)
132
- {
133
- $orderstatus = explode(',', Mage::getStoreConfig('awonpulse/general/ordersstatus',Mage::app()->getDefaultStoreView()->getId()));
134
- if (count($orderstatus)==0){
135
- $orderstatus = array(Mage_Sales_Model_Order::STATE_COMPLETE);
136
- }
137
- //Collect all orders for last N days
138
- /** @var $orders Mage_Sales_Model_Resource_Order_Collection */
139
- $orders = Mage::getResourceModel('sales/order_collection');
140
- $orders->addAttributeToFilter('created_at', array(
141
- 'from' => $date->addDay(-self::BESTSELLERS_DAYS_PERIOD)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)
142
- ))->addAttributeToFilter('status', array('in' => $orderstatus));
143
-
144
- $orderIds = Mage::getSingleton('core/resource')->getConnection('sales_read')->query($orders->getSelect()->resetJoinLeft())->fetchAll(PDO::FETCH_COLUMN,0);
145
- unset($orders);
146
-
147
- $orders = Mage::getModel('sales/order_item')->getCollection()
148
- ->addFieldToFilter('order_id',array('in'=>$orderIds))
149
- ->addFieldToFilter('parent_item_id', array('null'=> true));
150
- $orders = Mage::getSingleton('core/resource')->getConnection('sales_read')->query($orders->getSelect()->resetJoinLeft())->fetchAll();
151
-
152
- $items = array();
153
-
154
- /** @var $order Mage_Sales_Model_Order */
155
- foreach($orders as $orderItem) {
156
- $key = array_key_exists($orderItem['product_id'],$items);
157
- if($key === false) {
158
- $items[$orderItem['product_id']] = array(
159
- 'name'=>Mage::helper('awonpulse')->escapeHtml($orderItem['name']),
160
- 'qty'=>0,
161
- 'amount' => 0
162
- );
163
- }
164
- $items[$orderItem['product_id']]['qty'] += $orderItem['qty_ordered'];
165
- $items[$orderItem['product_id']]['amount'] += Mage::helper('awonpulse')->getPriceFormat($orderItem['base_row_total']-$orderItem['base_discount_invoiced']);
166
- }
167
-
168
- if(count($items) > 0) {
169
- foreach ($items as $id => $row) {
170
- $name[$id] = $row['name'];
171
- $qty[$id] = $row['qty'];
172
- }
173
- array_multisort($qty, SORT_DESC, $name, SORT_ASC, $items);
174
- }
175
- return $items;
176
- }
177
-
178
-
179
- /**
180
- * @param Zend_Date $date
181
- *
182
- * @return array
183
- */
184
- private function _getOrders(Zend_Date $date)
185
- {
186
-
187
- //collect yesterday orders count
188
- $ordersstatus = Mage::getStoreConfig('awonpulse/general/ordersstatus',Mage::app()->getDefaultStoreView()->getId());
189
- $ordersstatus = explode(',', $ordersstatus);
190
- if (count($ordersstatus)==0){
191
- $ordersstatus = array(Mage_Sales_Model_Order::STATE_COMPLETE);
192
- }
193
- /** @var $yesterdayOrders Mage_Sales_Model_Resource_Order_Collection */
194
- $yesterdayOrders = Mage::getResourceModel('sales/order_collection');
195
-
196
- $yesterdayOrders->addAttributeToFilter('created_at', array(
197
- 'from' => $date->addDay(-1)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT),
198
- 'to'=>$date->addDay(1)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)
199
- ))->addAttributeToSelect('*')
200
- ->addAttributeToFilter('status', array('in' => $ordersstatus));
201
-
202
-
203
- //collect today orders count
204
-
205
- /** @var $yesterdayOrders Mage_Sales_Model_Resource_Order_Collection */
206
- $todayOrders = Mage::getResourceModel('sales/order_collection');
207
- $todayOrders->addAttributeToFilter('created_at', array('from' => $date->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)))
208
- ->addAttributeToSelect('*')
209
- ->addAttributeToFilter('status', array('in' => $ordersstatus));
210
-
211
- //collect max, min, average orders
212
- $order = array();
213
- if ($todayOrders->getSize()) {
214
- $order['max'] = 0;
215
- $order['min'] = 999999999999999;
216
- $order['average'] = 0;
217
- $ordersSum = 0;
218
-
219
- foreach ($todayOrders as $item) {
220
-
221
- if ($item->getBaseGrandTotal() > $order['max']) {
222
- $order['max'] = Mage::helper('awonpulse')->getPriceFormat($item->getBaseGrandTotal());
223
- }
224
-
225
- if ($item->getBaseGrandTotal() < $order['min']) {
226
- $order['min'] = Mage::helper('awonpulse')->getPriceFormat($item->getBaseGrandTotal());
227
- }
228
-
229
- $ordersSum += Mage::helper('awonpulse')->getPriceFormat($item->getBaseGrandTotal());
230
-
231
- }
232
- $order['average'] = Mage::helper('awonpulse')->getPriceFormat($ordersSum / $todayOrders->getSize());
233
- } else {
234
- $order['max'] = 0;
235
- $order['min'] = 0;
236
- $order['average'] = 0;
237
- }
238
-
239
- return array('yesterday_orders' => $yesterdayOrders->getSize(), 'today_orders' => $todayOrders->getSize(), 'orders_totals' => $order);
240
- }
241
-
242
- /**
243
- * @param Zend_Date $date
244
- *
245
- * @return array
246
- */
247
- private function _getSales(Zend_Date $date)
248
- {
249
-
250
- $ordersstatus = Mage::getStoreConfig('awonpulse/general/ordersstatus',Mage::app()->getDefaultStoreView()->getId());
251
- $ordersstatus = explode(',', $ordersstatus);
252
- if (count($ordersstatus)==0){
253
- $ordersstatus = array(Mage_Sales_Model_Order::STATE_COMPLETE);
254
- }
255
- $shiftedDate = $this->_getShiftedDate();
256
- $date->addDay(1);
257
- $copyDate = clone $date;
258
- $numberDaysInMonth = $copyDate->get(Zend_Date::MONTH_DAYS);
259
- $revenue = array();
260
- for($i=0;$i<15;$i++){
261
- /** @var $yesterdayOrders Mage_Sales_Model_Resource_Order_Collection */
262
- $orders = Mage::getModel('sales/order')->getCollection();
263
- $orders->addAttributeToFilter('created_at', array('from' => $date->addDay(-1)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT),'to'=>$date->addDay(1)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)))
264
- ->addAttributeToSelect('*')
265
- ->addAttributeToFilter('status', array('in' => $ordersstatus));
266
- $date->addDay(-1);
267
- $shiftedDate->addDay(-1);
268
- $revenue[$i]['revenue']=0;
269
- $revenue[$i]['date']=$shiftedDate->toString(Varien_Date::DATE_INTERNAL_FORMAT);
270
- if($orders->getSize() > 0){
271
- foreach($orders as $order){
272
- $revenue[$i]['revenue']+=$order->getBaseGrandTotal();
273
- }
274
- }
275
- }
276
- /** @var $copyDate Zend_Date */
277
- $daysFrom1st=$copyDate->get(Zend_Date::DAY);
278
-
279
- $orders = Mage::getModel('sales/order')->getCollection();
280
- $orders->addAttributeToFilter('created_at', array('from' => $copyDate->addDay(-($daysFrom1st))->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)))
281
- ->addAttributeToSelect('*')
282
- ->addAttributeToFilter('status', array('in' => $ordersstatus));
283
- $thisMonthSoFar = 0;
284
- if($orders->getSize() > 0){
285
- foreach($orders as $order){
286
- $thisMonthSoFar+=$order->getBaseGrandTotal();
287
- }
288
- }
289
-
290
- $thisMonthAvg = $thisMonthSoFar /($daysFrom1st);
291
-
292
- $thisMonthForecast = $thisMonthAvg * $numberDaysInMonth;
293
- $thisMonth = array();
294
- $thisMonth['thisMonthSoFar'] = Mage::helper('awonpulse')->getPriceFormat($thisMonthSoFar);
295
- $thisMonth['thisMonthAvg'] = Mage::helper('awonpulse')->getPriceFormat($thisMonthAvg);
296
- $thisMonth['thisMonthForecast'] = Mage::helper('awonpulse')->getPriceFormat($thisMonthForecast);
297
-
298
- return array('revenue'=>$revenue, 'thisMonth'=>$thisMonth);
299
- }
300
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class AW_Onpulse_Model_Aggregator_Components_Statistics extends AW_Onpulse_Model_Aggregator_Component
4
+ {
5
+ /**
6
+ * How much last registered customers is to display
7
+ */
8
+ const COUNT_CUSTOMERS = 5;
9
+
10
+ const MYSQL_DATE_FORMAT = 'Y-d-m';
11
+
12
+ /**
13
+ * @return Zend_Date
14
+ */
15
+ private function _getShiftedDate()
16
+ {
17
+ $timeShift = Mage::app()->getLocale()->date()->get(Zend_Date::TIMEZONE_SECS);
18
+ $now = date(self::MYSQL_DATE_FORMAT, time() + $timeShift);
19
+ $now = new Zend_Date($now);
20
+ return $now;
21
+ }
22
+
23
+ /**
24
+ * @return Zend_Date
25
+ */
26
+ private function _getCurrentDate()
27
+ {
28
+ $now = Mage::app()->getLocale()->date();
29
+ $dateObj = Mage::app()->getLocale()->date(null, null, Mage::app()->getLocale()->getDefaultLocale(), false);
30
+
31
+ //set default timezone for store (admin)
32
+ $dateObj->setTimezone(Mage::app()->getStore()->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE));
33
+
34
+ //set begining of day
35
+ $dateObj->setHour(00);
36
+ $dateObj->setMinute(00);
37
+ $dateObj->setSecond(00);
38
+
39
+ //set date with applying timezone of store
40
+ $dateObj->set($now, Zend_Date::DATE_SHORT, Mage::app()->getLocale()->getDefaultLocale());
41
+
42
+ //convert store date to default date in UTC timezone without DST
43
+ $dateObj->setTimezone(Mage_Core_Model_Locale::DEFAULT_TIMEZONE);
44
+
45
+ return $dateObj;
46
+ }
47
+
48
+ /**
49
+ * @param $event
50
+ */
51
+ public function pushData($event = null)
52
+ {
53
+ $aggregator = $event->getEvent()->getAggregator();
54
+ $dashboard = array();
55
+ $today = $this->_getCurrentDate();
56
+
57
+ //Load sales revenue
58
+ $dashboard['sales'] = $this->_getSales(clone $today);
59
+
60
+ //Load last orders
61
+ $dashboard['orders'] = $this->_getOrders(clone $today);
62
+
63
+ //Load last customer registrations
64
+ $dashboard['customers'] = $this->_getCustomers(clone $today);
65
+
66
+ //Load last orders
67
+ $dashboard['last_orders'] = $this->_getLastOrders(clone $today);
68
+
69
+ //Load best selling products
70
+ $dashboard['bestsellers'] = $this->_getBestsellers(clone $today);
71
+
72
+ //Load sales grouped by country
73
+ $dashboard['sales_by_country'] = $this->_getSalesByCountry(clone $today);
74
+
75
+ //Load items per order revenue
76
+ $dashboard['items_per_order'] = $this->_getItemsPerOrder(clone $today);
77
+
78
+ //Load average order value
79
+ $dashboard['average_order_value'] = $this->_getAverageOrderValue(clone $today);
80
+
81
+ //Load signups
82
+ $dashboard['signups'] = $this->_getSignups(clone $today);
83
+
84
+ $aggregator->setData('dashboard', $dashboard);
85
+ }
86
+
87
+ /**
88
+ * @param Zend_Date $date
89
+ *
90
+ * @return array
91
+ */
92
+ private function _getByers(Zend_Date $date) {
93
+ /** @var $todayRegistered Mage_Customer_Model_Resource_Customer_Collection */
94
+ $todayRegistered = Mage::getModel('customer/customer')->getCollection();
95
+ $todayRegistered->addAttributeToFilter('created_at', array(
96
+ 'from' => $date->toString(Varien_Date::DATETIME_INTERNAL_FORMAT),
97
+ 'to' => $date->addDay(1)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)
98
+ ));
99
+ $todayRegistered->addAttributeToSelect('*');
100
+
101
+ $date->addDay(-1);
102
+ /* @var $collection Mage_Reports_Model_Mysql4_Order_Collection */
103
+ $customerArray = array();
104
+ $todayOrders = Mage::getModel('sales/order')->getCollection();
105
+ $todayOrders->addAttributeToFilter('created_at', array(
106
+ 'from' => $date->toString(Varien_Date::DATETIME_INTERNAL_FORMAT),
107
+ 'to' => $date->addDay(1)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)
108
+ ));
109
+ foreach ($todayOrders as $order) {
110
+ if ($order->getCustomerId()){
111
+ $customerArray[] = $order->getCustomerId();
112
+ }
113
+ }
114
+ $customerArray = array_unique($customerArray);
115
+ $buyers = count($customerArray);
116
+ return array(
117
+ 'buyers'=>$buyers,
118
+ 'registered'=>$todayRegistered,
119
+ );
120
+ }
121
+
122
+ /**
123
+ * @param Zend_Date $date
124
+ *
125
+ * @return array
126
+ */
127
+ private function _getCustomers(Zend_Date $date)
128
+ {
129
+ //collect online visitors
130
+ $online = Mage::getModel('log/visitor_online')
131
+ ->prepare()
132
+ ->getCollection()->addFieldToFilter('remote_addr',array('neq'=>Mage::helper('core/http')->getRemoteAddr(true)))->getSize();
133
+ $todayCustomers = $this->_getByers($date);
134
+ $yesterdayCustomers = $this->_getByers($date->addDay(-2));
135
+
136
+ return array('online_visistors' => $online, 'today_customers' => $todayCustomers, 'yesterday_customers' => $yesterdayCustomers);
137
+ }
138
+
139
+ /**
140
+ * @param Zend_Date $date
141
+ *
142
+ * @return array
143
+ */
144
+ private function _getBestsellers(Zend_Date $date)
145
+ {
146
+ $orderstatus = explode(',', Mage::getStoreConfig('awonpulse/general/ordersstatus',Mage::app()->getDefaultStoreView()->getId()));
147
+ if (count($orderstatus)==0){
148
+ $orderstatus = array(Mage_Sales_Model_Order::STATE_COMPLETE);
149
+ }
150
+ //Collect all orders for last N days
151
+ /** @var $orders Mage_Sales_Model_Resource_Order_Collection */
152
+ $orders = Mage::getResourceModel('sales/order_collection');
153
+ $orders->addAttributeToFilter('created_at', array(
154
+ 'from' => $date->addDay(-15)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)
155
+ ))->addAttributeToFilter('status', array('in' => $orderstatus));
156
+
157
+ $orderIds = Mage::getSingleton('core/resource')->getConnection('sales_read')->query($orders->getSelect()->resetJoinLeft())->fetchAll(PDO::FETCH_COLUMN,0);
158
+ unset($orders);
159
+
160
+ $orders = Mage::getModel('sales/order_item')->getCollection()
161
+ ->addFieldToFilter('order_id',array('in'=>$orderIds))
162
+ ->addFieldToFilter('parent_item_id', array('null'=> true));
163
+ $orders = Mage::getSingleton('core/resource')->getConnection('sales_read')->query($orders->getSelect()->resetJoinLeft())->fetchAll();
164
+
165
+ $items = array();
166
+
167
+ /** @var $order Mage_Sales_Model_Order */
168
+ foreach ($orders as $orderItem) {
169
+ $key = array_key_exists($orderItem['product_id'], $items);
170
+ if ($key === false) {
171
+ $items[$orderItem['product_id']] = array(
172
+ 'name' => Mage::helper('awonpulse')->escapeHtml($orderItem['name']),
173
+ 'qty' => 0,
174
+ 'amount' => 0
175
+ );
176
+ }
177
+ $items[$orderItem['product_id']]['qty'] += $orderItem['qty_ordered'];
178
+ $items[$orderItem['product_id']]['amount'] += Mage::helper('awonpulse')->getPriceFormat(
179
+ $orderItem['base_row_total'] - $orderItem['base_discount_invoiced']
180
+ );
181
+ }
182
+
183
+ if(count($items) > 0) {
184
+ foreach ($items as $id => $row) {
185
+ $name[$id] = $row['name'];
186
+ $qty[$id] = $row['qty'];
187
+ }
188
+ array_multisort($qty, SORT_DESC, $name, SORT_ASC, $items);
189
+ }
190
+ return $items;
191
+ }
192
+
193
+
194
+ /**
195
+ * @param Zend_Date $date
196
+ *
197
+ * @return array
198
+ */
199
+ private function _getOrders(Zend_Date $date)
200
+ {
201
+
202
+ //collect yesterday orders count
203
+ $ordersstatus = Mage::getStoreConfig('awonpulse/general/ordersstatus',Mage::app()->getDefaultStoreView()->getId());
204
+ $ordersstatus = explode(',', $ordersstatus);
205
+ if (count($ordersstatus)==0){
206
+ $ordersstatus = array(Mage_Sales_Model_Order::STATE_COMPLETE);
207
+ }
208
+ /** @var $yesterdayOrders Mage_Sales_Model_Resource_Order_Collection */
209
+ $yesterdayOrders = Mage::getResourceModel('sales/order_collection');
210
+
211
+ $yesterdayOrders->addAttributeToFilter('created_at', array(
212
+ 'from' => $date->addDay(-1)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT),
213
+ 'to'=>$date->addDay(1)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)
214
+ ))->addAttributeToSelect('*')
215
+ ->addAttributeToFilter('status', array('in' => $ordersstatus));
216
+
217
+
218
+ //collect today orders count
219
+
220
+ /** @var $yesterdayOrders Mage_Sales_Model_Resource_Order_Collection */
221
+ $todayOrders = Mage::getResourceModel('sales/order_collection');
222
+ $todayOrders->addAttributeToFilter('created_at', array('from' => $date->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)))
223
+ ->addAttributeToSelect('*')
224
+ ->addAttributeToFilter('status', array('in' => $ordersstatus));
225
+
226
+ //collect max, min, average orders
227
+ $order = array();
228
+ if ($todayOrders->getSize()) {
229
+ $order['max'] = 0;
230
+ $order['min'] = 999999999999999;
231
+ $order['average'] = 0;
232
+ $ordersSum = 0;
233
+
234
+ foreach ($todayOrders as $item) {
235
+
236
+ if ($item->getBaseGrandTotal() > $order['max']) {
237
+ $order['max'] = Mage::helper('awonpulse')->getPriceFormat($item->getBaseGrandTotal());
238
+ }
239
+
240
+ if ($item->getBaseGrandTotal() < $order['min']) {
241
+ $order['min'] = Mage::helper('awonpulse')->getPriceFormat($item->getBaseGrandTotal());
242
+ }
243
+
244
+ $ordersSum += Mage::helper('awonpulse')->getPriceFormat($item->getBaseGrandTotal());
245
+
246
+ }
247
+ $order['average'] = Mage::helper('awonpulse')->getPriceFormat($ordersSum / $todayOrders->getSize());
248
+ } else {
249
+ $order['max'] = 0;
250
+ $order['min'] = 0;
251
+ $order['average'] = 0;
252
+ }
253
+
254
+ return array('yesterday_orders' => $yesterdayOrders->getSize(), 'today_orders' => $todayOrders->getSize(), 'orders_totals' => $order);
255
+ }
256
+
257
+ /**
258
+ * @param Zend_Date $date
259
+ *
260
+ * @return array
261
+ */
262
+ private function _getSales(Zend_Date $date)
263
+ {
264
+ $orderStatus = Mage::getStoreConfig('awonpulse/general/ordersstatus', Mage::app()->getDefaultStoreView()->getId());
265
+ $orderStatus = explode(',', $orderStatus);
266
+ if (count($orderStatus)==0){
267
+ $orderStatus = array(Mage_Sales_Model_Order::STATE_COMPLETE);
268
+ }
269
+ $salesStatisticUnit = Mage::getStoreConfig(
270
+ 'awonpulse/general/show_sales_statistics_as', Mage::app()->getDefaultStoreView()->getId()
271
+ );
272
+ $shiftedDate = $this->_getShiftedDate();
273
+ $date->addDay(1);
274
+ $shiftedDate->addDay(1);
275
+ $copyDate = clone $date;
276
+ $revenue = array();
277
+ for ($i = 0; $i < 15; $i++) {
278
+ /** @var $yesterdayOrders Mage_Sales_Model_Resource_Order_Collection */
279
+ $orders = Mage::getModel('sales/order')->getCollection();
280
+ $orders->addAttributeToFilter('created_at',
281
+ array(
282
+ 'from' => $date->addDay(-1)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT),
283
+ 'to' => $date->addDay(1)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)
284
+ )
285
+ )->addAttributeToSelect('*')
286
+ ->addAttributeToFilter('status', array('in' => $orderStatus))
287
+ ;
288
+ $date->addDay(-1);
289
+ $shiftedDate->addDay(-1);
290
+ $revenue[$i]['revenue'] = 0;
291
+ $revenue[$i]['date'] = $shiftedDate->toString(Varien_Date::DATE_INTERNAL_FORMAT);
292
+ if ($orders->getSize() > 0) {
293
+ foreach ($orders as $order) {
294
+ if ($salesStatisticUnit == AW_Onpulse_Model_Source_ProfitRevenue::PROFIT_VALUE) {
295
+ $baseTotalCost = 0;
296
+ foreach ($order->getItemsCollection() as $item) {
297
+ $baseTotalCost += $item->getBaseCost();
298
+ }
299
+ $revenue[$i]['revenue'] += $order->getBaseSubtotal() - $baseTotalCost;
300
+ } else {
301
+ $revenue[$i]['revenue'] += $order->getBaseGrandTotal();
302
+ }
303
+ }
304
+ }
305
+ }
306
+ /** @var $copyDate Zend_Date */
307
+ $daysFrom1st = $copyDate->get(Zend_Date::DAY);
308
+ $startDate = clone $copyDate;
309
+ $orders = Mage::getModel('sales/order')->getCollection();
310
+ $orders->addAttributeToFilter('created_at', array('from' => $startDate->addDay(-($daysFrom1st))->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)))
311
+ ->addAttributeToSelect('*')
312
+ ->addAttributeToFilter('status', array('in' => $orderStatus));
313
+ $thisMonthSoFar = array();
314
+ foreach($orders as $order){
315
+ if ($salesStatisticUnit == AW_Onpulse_Model_Source_ProfitRevenue::PROFIT_VALUE) {
316
+ $baseTotalCost = 0;
317
+ foreach ($order->getItemsCollection() as $item) {
318
+ $baseTotalCost += $item->getBaseCost();
319
+ }
320
+ $thisMonthSoFar[] = $order->getBaseSubtotal() - $baseTotalCost;
321
+ } else {
322
+ $thisMonthSoFar[] = $order->getBaseGrandTotal();
323
+ }
324
+ }
325
+ $thisMonthAvg = array_sum($thisMonthSoFar) /($daysFrom1st);
326
+
327
+ $weekendConfigStr = Mage::getStoreConfig('general/locale/weekend', Mage::app()->getDefaultStoreView()->getId());
328
+ $weekdayConfig = array();
329
+ if (strlen($weekendConfigStr) > 0) {
330
+ $weekdayConfig = explode(',', $weekendConfigStr);
331
+ }
332
+ $workDayList = array();
333
+ $weekendDayList = array();
334
+ $workDayLeft = 0;
335
+ $weekendDayLeft = 0;
336
+ $copyDate->subDay(intval($date->get(Zend_Date::DAY_SHORT)) - 1);
337
+ for ($i = 0; $i < $copyDate->get(Zend_Date::MONTH_DAYS); $i++) {
338
+ $weekdayDigit = intval($date->get(Zend_Date::WEEKDAY_DIGIT));//from Sunday to Saturday -> from 0 to 6;
339
+ $isWeekday = in_array($weekdayDigit, $weekdayConfig);
340
+ if (array_key_exists($i, $thisMonthSoFar)) {
341
+ if ($isWeekday) {
342
+ $weekendDayList[] = $thisMonthSoFar[$i];
343
+ } else {
344
+ $workDayList[] = $thisMonthSoFar[$i];
345
+ }
346
+ } else {
347
+ $isWeekday?$weekendDayLeft++:$workDayLeft++;
348
+ }
349
+ $copyDate->addDay(1);
350
+ }
351
+ $workMedian = $this->_getMedianFromArray($workDayList);
352
+ $weekendMedian = $this->_getMedianFromArray($weekendDayList);
353
+ $thisMonthForecast = array_sum($thisMonthSoFar) + $workMedian * $workDayLeft + $weekendMedian * $workDayLeft;
354
+
355
+ $thisMonth = array();
356
+ $thisMonth['thisMonthSoFar'] = Mage::helper('awonpulse')->getPriceFormat(array_sum($thisMonthSoFar));
357
+ $thisMonth['thisMonthAvg'] = Mage::helper('awonpulse')->getPriceFormat($thisMonthAvg);
358
+ $thisMonth['thisMonthForecast'] = Mage::helper('awonpulse')->getPriceFormat($thisMonthForecast);
359
+
360
+ return array('revenue'=>$revenue, 'thisMonth'=>$thisMonth);
361
+ }
362
+
363
+ /**
364
+ * @param Zend_Date $date
365
+ *
366
+ * @return array
367
+ */
368
+ private function _getLastOrders(Zend_Date $date)
369
+ {
370
+ $orderCollection = Mage::getModel('sales/order')->getCollection()
371
+ ->addAddressFields()
372
+ ->addAttributeToSelect('*')
373
+ ->addOrder('entity_id', 'DESC')
374
+ ->setPageSize(3)
375
+ ;
376
+ $processedOrders = array();
377
+ foreach ($orderCollection as $order) {
378
+ $processedOrders[] = Mage::helper('awonpulse')->processOrderToArray($order);
379
+ }
380
+ return $processedOrders;
381
+ }
382
+
383
+ /**
384
+ * @param Zend_Date $date
385
+ *
386
+ * @return array
387
+ */
388
+ private function _getItemsPerOrder(Zend_Date $date)
389
+ {
390
+ $orderStatus = Mage::getStoreConfig(
391
+ 'awonpulse/general/ordersstatus', Mage::app()->getDefaultStoreView()->getId()
392
+ );
393
+ $orderStatus = explode(',', $orderStatus);
394
+ if (count($orderStatus)==0){
395
+ $orderStatus = array(Mage_Sales_Model_Order::STATE_COMPLETE);
396
+ }
397
+ $shiftedDate = $this->_getShiftedDate();
398
+ $date->addDay(1);
399
+ $shiftedDate->addDay(1);
400
+ $copyDate = clone $date;
401
+ $numberDaysInMonth = $copyDate->get(Zend_Date::MONTH_DAYS);
402
+ $revenue = array();
403
+ $thisMonthAvgList = array();
404
+ for ($i = 0; $i < 15; $i++) {
405
+ /** @var $yesterdayOrders Mage_Sales_Model_Resource_Order_Collection */
406
+ $orders = Mage::getModel('sales/order')->getCollection();
407
+ $orders->addAttributeToFilter(
408
+ 'created_at',
409
+ array(
410
+ 'from' => $date->addDay(-1)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT),
411
+ 'to' => $date->addDay(1)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)
412
+ )
413
+ )->addAttributeToSelect('*')
414
+ ->addAttributeToFilter('status', array('in' => $orderStatus))
415
+ ;
416
+ $date->addDay(-1);
417
+ $shiftedDate->addDay(-1);
418
+ $revenue[$i]['revenue'] = 0;
419
+ $revenue[$i]['date'] = $shiftedDate->toString(Varien_Date::DATE_INTERNAL_FORMAT);
420
+ foreach($orders as $order){
421
+ $revenue[$i]['revenue'] += $order->getTotalItemCount();
422
+ }
423
+ $thisMonthAvgList[] = $revenue[$i]['revenue'];
424
+ }
425
+
426
+ $thisMonthAvg = 0;
427
+ if (count($thisMonthAvgList) > 0) {
428
+ $thisMonthAvg = array_sum($thisMonthAvgList) / count($thisMonthAvgList);
429
+ }
430
+ $thisMonth = array();
431
+ $thisMonth['thisMonthAvg'] = Mage::helper('awonpulse')->getPriceFormat($thisMonthAvg);
432
+ return array('revenue' => $revenue, 'thisMonth' => $thisMonth);
433
+ }
434
+
435
+ /**
436
+ * @param Zend_Date $date
437
+ *
438
+ * @return array
439
+ */
440
+ private function _getAverageOrderValue(Zend_Date $date)
441
+ {
442
+ $orderStatus = Mage::getStoreConfig(
443
+ 'awonpulse/general/ordersstatus', Mage::app()->getDefaultStoreView()->getId()
444
+ );
445
+ $orderStatus = explode(',', $orderStatus);
446
+ if (count($orderStatus)==0){
447
+ $orderStatus = array(Mage_Sales_Model_Order::STATE_COMPLETE);
448
+ }
449
+ $shiftedDate = $this->_getShiftedDate();
450
+ $date->addDay(1);
451
+ $shiftedDate->addDay(1);
452
+ $copyDate = clone $date;
453
+ $numberDaysInMonth = $copyDate->get(Zend_Date::MONTH_DAYS);
454
+ $revenue = array();
455
+ $thisMonthAvgList = array();
456
+ for ($i = 0; $i < 15; $i++) {
457
+ /** @var $yesterdayOrders Mage_Sales_Model_Resource_Order_Collection */
458
+ $orders = Mage::getModel('sales/order')->getCollection();
459
+ $orders->addAttributeToFilter(
460
+ 'created_at',
461
+ array(
462
+ 'from' => $date->addDay(-1)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT),
463
+ 'to' => $date->addDay(1)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)
464
+ )
465
+ )->addAttributeToSelect('*')
466
+ ->addAttributeToFilter('status', array('in' => $orderStatus))
467
+ ;
468
+ $date->addDay(-1);
469
+ $shiftedDate->addDay(-1);
470
+ $revenue[$i]['revenue']=0;
471
+ $revenue[$i]['date']=$shiftedDate->toString(Varien_Date::DATE_INTERNAL_FORMAT);
472
+ if($orders->getSize() > 0) {
473
+ foreach($orders as $order){
474
+ $revenue[$i]['revenue'] += $order->getBaseGrandTotal();
475
+ }
476
+ $revenue[$i]['revenue'] /= $orders->getSize();
477
+ }
478
+ $thisMonthAvgList[] = $revenue[$i]['revenue'];
479
+ }
480
+
481
+ $thisMonthAvg = 0;
482
+ if (count($thisMonthAvgList) > 0) {
483
+ $thisMonthAvg = array_sum($thisMonthAvgList) / count($thisMonthAvgList);
484
+ }
485
+ $thisMonth = array();
486
+ $thisMonth['thisMonthAvg'] = Mage::helper('awonpulse')->getPriceFormat($thisMonthAvg);
487
+ return array('revenue' => $revenue, 'thisMonth' => $thisMonth);
488
+ }
489
+
490
+ /**
491
+ * @param Zend_Date $date
492
+ *
493
+ * @return array
494
+ */
495
+ private function _getSalesByCountry(Zend_Date $date)
496
+ {
497
+ $orderStatus = explode(
498
+ ',', Mage::getStoreConfig('awonpulse/general/ordersstatus', Mage::app()->getDefaultStoreView()->getId())
499
+ );
500
+ if (count($orderStatus) == 0) {
501
+ $orderStatus = array(Mage_Sales_Model_Order::STATE_COMPLETE);
502
+ }
503
+ /** @var $orders Mage_Sales_Model_Resource_Order_Collection */
504
+ $orderCollection = Mage::getResourceModel('sales/order_collection');
505
+ $orderCollection
506
+ ->addAttributeToFilter(
507
+ 'created_at', array('from' => $date->addDay(-15)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT))
508
+ )
509
+ ->addAttributeToFilter('status', array('in' => $orderStatus))
510
+ ;
511
+ //join billing address to order
512
+ $billingAliasName = 'billing_o_a';
513
+ $orderCollection->getSelect()->joinLeft(
514
+ array($billingAliasName => $orderCollection->getTable('sales/order_address')),
515
+ "(main_table.entity_id = {$billingAliasName}.parent_id"
516
+ . " AND {$billingAliasName}.address_type = 'billing')",
517
+ array(
518
+ 'country_id' => $billingAliasName . '.country_id',
519
+ )
520
+ );
521
+
522
+ $countryOptionArray = Mage::helper('directory')->getCountryCollection()->toOptionArray(false);
523
+ $countryOptionHash = array();
524
+ foreach ($countryOptionArray as $option) {
525
+ $countryOptionHash[$option['value']] = $option['label'];
526
+ }
527
+ $result = array();
528
+ foreach ($orderCollection as $order) {
529
+ /** @var $order Mage_Sales_Model_Order */
530
+ $countryCode = $order->getData('country_id');
531
+ $item = array(
532
+ 'country_label' => $countryOptionHash[$countryCode],
533
+ 'qty' => 1,
534
+ 'amount' => Mage::helper('awonpulse')->getPriceFormat($order->getBaseGrandTotal())
535
+ );
536
+ if (array_key_exists($countryCode, $result)) {
537
+ $item['qty'] += $result[$countryCode]['qty'];
538
+ $item['amount'] += $result[$countryCode]['amount'];
539
+ }
540
+ $result[$countryCode] = $item;
541
+ }
542
+
543
+ if(count($result) > 0) {
544
+ $name = array();
545
+ $qty = array();
546
+ foreach ($result as $key => $row) {
547
+ $name[$key] = $row['country_label'];
548
+ $qty[$key] = $row['qty'];
549
+ }
550
+ array_multisort($qty, SORT_DESC, $name, SORT_ASC, $result);
551
+ }
552
+ return array_values($result);
553
+ }
554
+
555
+ /**
556
+ * @param Zend_Date $date
557
+ *
558
+ * @return array
559
+ */
560
+ private function _getSignups(Zend_Date $date)
561
+ {
562
+ $shiftedDate = $this->_getShiftedDate();
563
+ $date->addDay(1);
564
+ $shiftedDate->addDay(1);
565
+ $copyDate = clone $date;
566
+ $numberDaysInMonth = $copyDate->get(Zend_Date::MONTH_DAYS);
567
+ $data = array();
568
+ $thisMonthAvgList = array();
569
+ for ($i = 0; $i < 15; $i++) {
570
+ $customers = Mage::getModel('customer/customer')->getCollection();
571
+ $customers->addAttributeToFilter(
572
+ 'created_at',
573
+ array(
574
+ 'from' => $date->addDay(-1)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT),
575
+ 'to' => $date->addDay(1)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)
576
+ )
577
+ )->addAttributeToSelect('*');
578
+ $date->addDay(-1);
579
+ $shiftedDate->addDay(-1);
580
+ $data[$i]['data'] = $customers->getSize();
581
+ $data[$i]['date'] = $shiftedDate->toString(Varien_Date::DATE_INTERNAL_FORMAT);
582
+ $thisMonthAvgList[] = $data[$i]['data'];
583
+ }
584
+
585
+ $thisMonthAvg = array_sum($thisMonthAvgList) / count($thisMonthAvgList);
586
+ $thisMonth = array();
587
+ $thisMonth['thisMonthAvg'] = Mage::helper('awonpulse')->getPriceFormat($thisMonthAvg);
588
+ return array('data' => $data, 'thisMonth' => $thisMonth);
589
+ }
590
+
591
+ /**
592
+ * @param array $data
593
+ *
594
+ * @return float
595
+ */
596
+ private function _getMedianFromArray($data)
597
+ {
598
+ if (count($data) === 0) {
599
+ return 0;
600
+ }
601
+ sort($data);
602
+ $dataCount = count($data);
603
+ $middleValue = (int)floor($dataCount / 2);
604
+ if ($dataCount % 2 === 1) {
605
+ return floatval($data[$middleValue]);
606
+ }
607
+ return ($data[$middleValue - 1] + $data[$middleValue]) / 2;
608
+ }
609
+ }
app/code/local/AW/Onpulse/Model/Credentials.php CHANGED
@@ -1,91 +1,93 @@
1
- <?php
2
-
3
- class AW_Onpulse_Model_Credentials extends Mage_Core_Model_Abstract
4
- {
5
- private $key = null;
6
- private $hash = null;
7
- private $qrhash = null;
8
- private $ddl = null;
9
-
10
-
11
- private function _updateURLRedirectEE($idPath,$oldRequestPath, $requestPath)
12
- {
13
- $keyRewrite = Mage::getModel('enterprise_urlrewrite/redirect')->loadByRequestPath($oldRequestPath, 0);
14
- $keyRewrite
15
- ->setOptions()
16
- ->setIdPath($idPath)
17
- ->setTargetPath('awonpulse')
18
- ->setIdentifier($requestPath)
19
- ->save();
20
- }
21
-
22
- private function _updateURLRewrite($idPath,$requestPath)
23
- {
24
- if(!$requestPath) {
25
- return;
26
- }
27
- $keyRewrite = Mage::getModel('core/url_rewrite')->loadByIdPath($idPath);
28
- $oldRequestPath = $keyRewrite->getRequestPath();
29
- $defaultStore = Mage::app()->getStore()->getId();
30
- if(Mage::app()->getDefaultStoreView() !== null) {
31
- $defaultStore = Mage::app()->getDefaultStoreView()->getId();
32
- }
33
- if(AW_Onpulse_Helper_Data::getPlatform() == AW_Onpulse_Helper_Data::EE_PLATFORM) {
34
- $this->_updateURLRedirectEE($idPath,$oldRequestPath, $requestPath);
35
- }
36
- $keyRewrite
37
- ->setIsSystem(0)
38
- ->setStoreId($defaultStore)
39
- ->setOptions('')
40
- ->setIdPath($idPath)
41
- ->setTargetPath('awonpulse')
42
- ->setRequestPath($requestPath)
43
- ->save();
44
- }
45
-
46
- public function readConfig()
47
- {
48
-
49
- $defaultStore = Mage::app()->getStore()->getId();
50
- if(Mage::app()->getDefaultStoreView() !== null) {
51
- $defaultStore = Mage::app()->getDefaultStoreView()->getId();
52
- }
53
-
54
-
55
- if ((!Mage::getStoreConfig('awonpulse/general/credurlkey', $defaultStore))
56
- && (!Mage::getStoreConfig('awonpulse/general/credhash', $defaultStore))
57
- ) {
58
- Mage::app()->setUpdateMode(false);
59
- Mage::app()->init('','store');
60
- }
61
-
62
- //Read configuration
63
- if ((Mage::getStoreConfig('awonpulse/general/credurlkey', $defaultStore))
64
- && (Mage::getStoreConfig('awonpulse/general/credhash', $defaultStore))
65
- ) {
66
- $this->hash = Mage::getStoreConfig(
67
- 'awonpulse/general/credhash', $defaultStore
68
- );
69
- $this->ddl = Mage::getStoreConfig('awonpulse/general/ddl', $defaultStore);
70
- $this->key = Mage::getStoreConfig(
71
- 'awonpulse/general/credurlkey', $defaultStore
72
- );
73
- $this->qrhash = md5($this->key . $this->hash);
74
- }
75
-
76
- return array(
77
- 'hash' => $this->hash,
78
- 'key' => $this->key,
79
- 'qrhash' => $this->qrhash,
80
- 'ddl' => $this->ddl
81
- );
82
-
83
- }
84
-
85
- public function updateSettings($observer)
86
- {
87
- $this->readConfig();
88
- $this->_updateURLRewrite('onpulse/qrhash',$this->qrhash);
89
- $this->_updateURLRewrite('onpulse/key',$this->key);
90
- }
 
 
91
  }
1
+ <?php
2
+
3
+ class AW_Onpulse_Model_Credentials extends Mage_Core_Model_Abstract
4
+ {
5
+ private $key = null;
6
+ private $hash = null;
7
+ private $qrhash = null;
8
+ private $ddl = null;
9
+
10
+
11
+ private function _updateURLRedirectEE($idPath,$oldRequestPath, $requestPath)
12
+ {
13
+ $keyRewrite = Mage::getModel('enterprise_urlrewrite/redirect')->loadByRequestPath($oldRequestPath, 0);
14
+ $keyRewrite
15
+ ->setOptions()
16
+ ->setIdPath($idPath)
17
+ ->setTargetPath('awonpulse')
18
+ ->setIdentifier($requestPath)
19
+ ->save();
20
+ }
21
+
22
+ private function _updateURLRewrite($idPath,$requestPath)
23
+ {
24
+ if(!$requestPath) {
25
+ return;
26
+ }
27
+ $keyRewrite = Mage::getModel('core/url_rewrite')->loadByIdPath($idPath);
28
+ $oldRequestPath = $keyRewrite->getRequestPath();
29
+ $defaultStore = Mage::app()->getStore()->getId();
30
+ if(Mage::app()->getDefaultStoreView() !== null) {
31
+ $defaultStore = Mage::app()->getDefaultStoreView()->getId();
32
+ }
33
+ if(AW_Onpulse_Helper_Data::getPlatform() == AW_Onpulse_Helper_Data::EE_PLATFORM
34
+ && version_compare(Mage::getVersion(), '1.13.0.0', '>=')
35
+ ) {
36
+ $this->_updateURLRedirectEE($idPath,$oldRequestPath, $requestPath);
37
+ }
38
+ $keyRewrite
39
+ ->setIsSystem(0)
40
+ ->setStoreId($defaultStore)
41
+ ->setOptions('')
42
+ ->setIdPath($idPath)
43
+ ->setTargetPath('awonpulse')
44
+ ->setRequestPath($requestPath)
45
+ ->save();
46
+ }
47
+
48
+ public function readConfig()
49
+ {
50
+
51
+ $defaultStore = Mage::app()->getStore()->getId();
52
+ if(Mage::app()->getDefaultStoreView() !== null) {
53
+ $defaultStore = Mage::app()->getDefaultStoreView()->getId();
54
+ }
55
+
56
+
57
+ if ((!Mage::getStoreConfig('awonpulse/access/credurlkey', $defaultStore))
58
+ && (!Mage::getStoreConfig('awonpulse/access/credhash', $defaultStore))
59
+ ) {
60
+ Mage::app()->setUpdateMode(false);
61
+ Mage::app()->init('','store');
62
+ }
63
+
64
+ //Read configuration
65
+ if ((Mage::getStoreConfig('awonpulse/access/credurlkey', $defaultStore))
66
+ && (Mage::getStoreConfig('awonpulse/access/credhash', $defaultStore))
67
+ ) {
68
+ $this->hash = Mage::getStoreConfig(
69
+ 'awonpulse/access/credhash', $defaultStore
70
+ );
71
+ $this->ddl = Mage::getStoreConfig('awonpulse/general/ddl', $defaultStore);
72
+ $this->key = Mage::getStoreConfig(
73
+ 'awonpulse/access/credurlkey', $defaultStore
74
+ );
75
+ $this->qrhash = md5($this->key . $this->hash);
76
+ }
77
+
78
+ return array(
79
+ 'hash' => $this->hash,
80
+ 'key' => $this->key,
81
+ 'qrhash' => $this->qrhash,
82
+ 'ddl' => $this->ddl
83
+ );
84
+
85
+ }
86
+
87
+ public function updateSettings($observer)
88
+ {
89
+ $this->readConfig();
90
+ $this->_updateURLRewrite('onpulse/qrhash',$this->qrhash);
91
+ $this->_updateURLRewrite('onpulse/key',$this->key);
92
+ }
93
  }
app/code/local/AW/Onpulse/Model/Source/OrderStatus.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class AW_Onpulse_Model_Source_OrderStatus
4
+ extends Mage_Adminhtml_Model_System_Config_Source_Order_Status
5
+ {
6
+ public function toOptionArray()
7
+ {
8
+ $options = parent::toOptionArray();
9
+ array_shift($options);
10
+ return $options;
11
+ }
12
+ }
app/code/local/AW/Onpulse/Model/Source/ProfitRevenue.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class AW_Onpulse_Model_Source_ProfitRevenue
4
+ {
5
+ const REVENUE_VALUE = 0;
6
+ const PROFIT_VALUE = 1;
7
+ const REVENUE_LABEL = 'Revenue';
8
+ const PROFIT_LABEL = 'Profit';
9
+
10
+ public function toOptionArray()
11
+ {
12
+ return array(
13
+ array(
14
+ 'value' => self::REVENUE_VALUE,
15
+ 'label' => Mage::helper('awonpulse')->__('Revenue'),
16
+ ),
17
+ array(
18
+ 'value' => self::PROFIT_VALUE,
19
+ 'label' => Mage::helper('awonpulse')->__('Profit'),
20
+ ),
21
+ );
22
+ }
23
+ }
app/code/local/AW/Onpulse/controllers/Adminhtml/ConfigController.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ include_once("app/code/core/Mage/Adminhtml/controllers/System/ConfigController.php");
4
+ class AW_Onpulse_Adminhtml_ConfigController extends Mage_Adminhtml_System_ConfigController
5
+ {
6
+ public function generateAction()
7
+ {
8
+ $this->saveAction();
9
+ $session = Mage::getSingleton('adminhtml/session');
10
+ $lastSessionMessage = $session->getMessages()->getLastAddedMessage();
11
+ if (null === $lastSessionMessage) {
12
+ return;
13
+ }
14
+ if ($lastSessionMessage->getType() !== 'success') {
15
+ return;
16
+ }
17
+ $session->getMessages()->clear();
18
+ $session->addSuccess(Mage::helper('awonpulse')->__('New login credentials has been generated.'));
19
+ }
20
+ }
app/code/local/AW/Onpulse/controllers/IndexController.php CHANGED
@@ -1,52 +1,93 @@
1
- <?php
2
- class AW_Onpulse_IndexController extends Mage_Core_Controller_Front_Action {
3
-
4
- protected $_accessDeniedAlias = 'awonpulse';
5
- protected $_config = array();
6
-
7
- protected function _isAllowed()
8
- {
9
- //if strpos gives boolean result it means what alias is denied
10
- return is_bool(strpos($this->getRequest()->getRequestString(),$this->_accessDeniedAlias));
11
- }
12
-
13
- protected function _isAllowedByDirectLink()
14
- {
15
- if($this->_config['ddl']) {
16
- return false;
17
- }
18
- //if strpos gives non boolean result it means what qrhash in url - OK
19
- return !is_bool(strpos($this->getRequest()->getRequestString(),$this->_config['qrhash']));
20
- }
21
-
22
- protected function _isAllowedByKeyHash()
23
- {
24
- $key = $this->getRequest()->getParam('key');
25
- return $key && $key == $this->_config['hash'];
26
- }
27
-
28
- public function indexAction()
29
- {
30
- if( ! $this->_isAllowed()) {
31
- return $this->_forward('noRoute');
32
- }
33
- $this->_config = Mage::getModel('awonpulse/credentials')->readConfig();
34
-
35
-
36
- //First of all check Direct link login by QR code
37
- $noRouteFlag = !$this->_isAllowedByDirectLink();
38
-
39
- //Second step: check login by key and hash
40
- if($noRouteFlag) {
41
- $noRouteFlag = !$this->_isAllowedByKeyHash();
42
- }
43
-
44
- if($noRouteFlag) {
45
- return $this->_forward('noRoute');
46
- }
47
-
48
- $aggregator = Mage::getSingleton('awonpulse/aggregator')->Aggregate();
49
- $output = Mage::helper('awonpulse')->processOutput($aggregator);
50
- return $this->getResponse()->setBody(serialize($output));
51
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  }
1
+ <?php
2
+
3
+ class AW_Onpulse_IndexController extends Mage_Core_Controller_Front_Action
4
+ {
5
+
6
+ protected $_accessDeniedAlias = 'awonpulse';
7
+ protected $_config = array();
8
+
9
+ protected function _isAllowed()
10
+ {
11
+ //if strpos gives boolean result it means what alias is denied
12
+ return is_bool(
13
+ strpos(
14
+ $this->getRequest()->getRequestString(),
15
+ $this->_accessDeniedAlias
16
+ )
17
+ );
18
+ }
19
+
20
+ protected function _isAllowedByDirectLink()
21
+ {
22
+ if ($this->_config['ddl']) {
23
+ return false;
24
+ }
25
+ //if strpos gives non boolean result it means what qrhash in url - OK
26
+ return !is_bool(
27
+ strpos(
28
+ $this->getRequest()->getRequestString(),
29
+ $this->_config['qrhash']
30
+ )
31
+ );
32
+ }
33
+
34
+ protected function _isAllowedByKeyHash()
35
+ {
36
+ $key = $this->getRequest()->getParam('key');
37
+ return $key && $key == $this->_config['hash'];
38
+ }
39
+
40
+ public function indexAction()
41
+ {
42
+ if (!$this->_isAllowed()) {
43
+ $this->_forward('noRoute');
44
+ return $this;
45
+ }
46
+ $this->_config = Mage::getModel('awonpulse/credentials')->readConfig();
47
+
48
+
49
+ //First of all check Direct link login by QR code
50
+ $noRouteFlag = !$this->_isAllowedByDirectLink();
51
+
52
+ //Second step: check login by key and hash
53
+ if ($noRouteFlag) {
54
+ $noRouteFlag = !$this->_isAllowedByKeyHash();
55
+ }
56
+
57
+ if ($noRouteFlag) {
58
+ $this->_forward('noRoute');
59
+ return $this;
60
+ }
61
+
62
+ $type = $this->getRequest()->getParam('type', null);
63
+ if ($type === "search") {
64
+ return $this->_search();
65
+ }
66
+
67
+ $aggregator = Mage::getSingleton('awonpulse/aggregator')->Aggregate();
68
+ $output = Mage::helper('awonpulse')->processOutput($aggregator);
69
+ return $this->getResponse()->setBody(serialize($output));
70
+ }
71
+
72
+ protected function _search()
73
+ {
74
+ $query = $this->getRequest()->getParam('query', null);
75
+ $entity = $this->getRequest()->getParam('entity', null);
76
+ if (null === $query || null === $entity) {
77
+ $this->_forward('noRoute');
78
+ return $this;
79
+ }
80
+
81
+ $aggregator = Mage::getSingleton('awonpulse/aggregator')->Aggregate();
82
+ switch($entity) {
83
+ case 'customer':
84
+ Mage::getModel('awonpulse/aggregator_components_customer')->pushSearchedData($aggregator, $query);
85
+ break;
86
+ case 'order':
87
+ Mage::getModel('awonpulse/aggregator_components_order')->pushSearchedData($aggregator, $query);
88
+ break;
89
+ }
90
+ $output = Mage::helper('awonpulse')->processOutput($aggregator);
91
+ return $this->getResponse()->setBody(serialize($output));
92
+ }
93
  }
app/code/local/AW/Onpulse/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <AW_Onpulse>
5
- <version>1.0.16</version>
6
  </AW_Onpulse>
7
  </modules>
8
  <global>
@@ -101,7 +101,7 @@
101
  <config>
102
  <children>
103
  <awonpulse>
104
- <title>aheadWorks - Onpulse</title>
105
  </awonpulse>
106
  </children>
107
  </config>
@@ -112,6 +112,17 @@
112
  </resources>
113
  </acl>
114
  </adminhtml>
 
 
 
 
 
 
 
 
 
 
 
115
  <frontend>
116
  <routers>
117
  <awonpulse>
@@ -128,6 +139,7 @@
128
  <general>
129
  <ddl>0</ddl>
130
  <ordersstatus>complete</ordersstatus>
 
131
  </general>
132
  </awonpulse>
133
  </default>
2
  <config>
3
  <modules>
4
  <AW_Onpulse>
5
+ <version>2.0.0</version>
6
  </AW_Onpulse>
7
  </modules>
8
  <global>
101
  <config>
102
  <children>
103
  <awonpulse>
104
+ <title>aheadWorks - OnPulse</title>
105
  </awonpulse>
106
  </children>
107
  </config>
112
  </resources>
113
  </acl>
114
  </adminhtml>
115
+ <admin>
116
+ <routers>
117
+ <awonpulse_admin>
118
+ <use>admin</use>
119
+ <args>
120
+ <module>AW_Onpulse</module>
121
+ <frontName>awonpulse_admin</frontName>
122
+ </args>
123
+ </awonpulse_admin>
124
+ </routers>
125
+ </admin>
126
  <frontend>
127
  <routers>
128
  <awonpulse>
139
  <general>
140
  <ddl>0</ddl>
141
  <ordersstatus>complete</ordersstatus>
142
+ <show_sales_statistics_as>0</show_sales_statistics_as>
143
  </general>
144
  </awonpulse>
145
  </default>
app/code/local/AW/Onpulse/etc/system.xml CHANGED
@@ -8,7 +8,7 @@
8
  </tabs>
9
  <sections>
10
  <awonpulse translate="label" module="awonpulse">
11
- <label>Onpulse</label>
12
  <tab>awall</tab>
13
  <frontend_type>text</frontend_type>
14
  <sort_order>99</sort_order>
@@ -18,40 +18,63 @@
18
  <groups>
19
  <general translate="label">
20
  <label>General</label>
21
- <frontend_type>text</frontend_type>
22
- <frontend_model>awonpulse/system_config_form_fieldset_onpulse_settings</frontend_model>
23
- <sort_order>2</sort_order>
24
  <show_in_default>1</show_in_default>
25
  <show_in_website>1</show_in_website>
26
  <show_in_store>1</show_in_store>
27
  <fields>
28
- <credurlkey>
29
- <frontend_type>text</frontend_type>
30
- <show_in_default>1</show_in_default>
31
- <show_in_website>1</show_in_website>
32
- <show_in_store>1</show_in_store>
33
- </credurlkey>
34
- <credhash>
35
- <frontend_type>text</frontend_type>
36
  <show_in_default>1</show_in_default>
37
  <show_in_website>1</show_in_website>
38
  <show_in_store>1</show_in_store>
39
- </credhash>
40
- <ddl>
 
 
41
  <frontend_type>select</frontend_type>
42
  <source_model>adminhtml/system_config_source_yesno</source_model>
43
  <show_in_default>1</show_in_default>
44
  <show_in_website>1</show_in_website>
45
  <show_in_store>1</show_in_store>
 
46
  </ddl>
47
- <ordersstatus>
48
- <frontend_type>multiselect</frontend_type>
 
 
49
  <show_in_default>1</show_in_default>
50
  <show_in_website>1</show_in_website>
51
  <show_in_store>1</show_in_store>
52
- </ordersstatus>
 
53
  </fields>
54
  </general>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  </groups>
56
  </awonpulse>
57
  </sections>
8
  </tabs>
9
  <sections>
10
  <awonpulse translate="label" module="awonpulse">
11
+ <label>OnPulse</label>
12
  <tab>awall</tab>
13
  <frontend_type>text</frontend_type>
14
  <sort_order>99</sort_order>
18
  <groups>
19
  <general translate="label">
20
  <label>General</label>
21
+ <sort_order>1</sort_order>
 
 
22
  <show_in_default>1</show_in_default>
23
  <show_in_website>1</show_in_website>
24
  <show_in_store>1</show_in_store>
25
  <fields>
26
+ <ordersstatus translate="label">
27
+ <label>Show Statistic for Orders with Statuses</label>
28
+ <frontend_type>multiselect</frontend_type>
29
+ <source_model>awonpulse/source_orderStatus</source_model>
 
 
 
 
30
  <show_in_default>1</show_in_default>
31
  <show_in_website>1</show_in_website>
32
  <show_in_store>1</show_in_store>
33
+ <sort_order>10</sort_order>
34
+ </ordersstatus>
35
+ <ddl translate="label">
36
+ <label>Disable Direct Login Link</label>
37
  <frontend_type>select</frontend_type>
38
  <source_model>adminhtml/system_config_source_yesno</source_model>
39
  <show_in_default>1</show_in_default>
40
  <show_in_website>1</show_in_website>
41
  <show_in_store>1</show_in_store>
42
+ <sort_order>20</sort_order>
43
  </ddl>
44
+ <show_sales_statistics_as translate="label">
45
+ <label>Show Sales Statistics As</label>
46
+ <frontend_type>select</frontend_type>
47
+ <source_model>awonpulse/source_profitRevenue</source_model>
48
  <show_in_default>1</show_in_default>
49
  <show_in_website>1</show_in_website>
50
  <show_in_store>1</show_in_store>
51
+ <sort_order>30</sort_order>
52
+ </show_sales_statistics_as>
53
  </fields>
54
  </general>
55
+ <access translate="label">
56
+ <label>Access</label>
57
+ <frontend_type>text</frontend_type>
58
+ <frontend_model>awonpulse/system_config_form_fieldset_onpulse_access</frontend_model>
59
+ <sort_order>10</sort_order>
60
+ <show_in_default>1</show_in_default>
61
+ <show_in_website>1</show_in_website>
62
+ <show_in_store>1</show_in_store>
63
+ <fields>
64
+ <credurlkey>
65
+ <frontend_type>text</frontend_type>
66
+ <show_in_default>1</show_in_default>
67
+ <show_in_website>1</show_in_website>
68
+ <show_in_store>1</show_in_store>
69
+ </credurlkey>
70
+ <credhash>
71
+ <frontend_type>text</frontend_type>
72
+ <show_in_default>1</show_in_default>
73
+ <show_in_website>1</show_in_website>
74
+ <show_in_store>1</show_in_store>
75
+ </credhash>
76
+ </fields>
77
+ </access>
78
  </groups>
79
  </awonpulse>
80
  </sections>
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-install-1.0.0.php CHANGED
@@ -1 +1,5 @@
1
- <?php
 
 
 
 
1
+ <?php
2
+ /* @var $installer Mage_Core_Model_Resource_Setup */
3
+ $installer = $this;
4
+ $installer = $this->startSetup();
5
+ $installer->endSetup();
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.0-1.0.1.php DELETED
@@ -1 +0,0 @@
1
- <?php
 
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.0-1.0.14.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+ /* @var $installer Mage_Core_Model_Resource_Setup */
3
+ $installer = $this;
4
+ $installer = $this->startSetup();
5
+ $installer->endSetup();
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.1-1.0.2.php DELETED
@@ -1 +0,0 @@
1
- <?php
 
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.10-1.0.11.php DELETED
@@ -1 +0,0 @@
1
- <?php
 
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.11-1.0.12.php DELETED
@@ -1 +0,0 @@
1
- <?php
 
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.12-1.0.13.php DELETED
@@ -1 +0,0 @@
1
- <?php
 
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.13-1.0.14.php DELETED
@@ -1 +0,0 @@
1
- <?php
 
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.14-1.0.15.php CHANGED
@@ -1,2 +1,7 @@
1
- <?php
2
- Mage::getModel('awonpulse/credentials')->updateSettings(null);
 
 
 
 
 
1
+ <?php
2
+ /* @var $installer Mage_Core_Model_Resource_Setup */
3
+ $installer = $this;
4
+ $installer = $this->startSetup();
5
+ Mage::getModel('awonpulse/credentials')->updateSettings(null);
6
+ $installer->endSetup();
7
+
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.14-1.0.16.php DELETED
@@ -1,3 +0,0 @@
1
- <?php
2
- die('yhju');
3
- Mage::getModel('awonpulse')->updateSettings(null);
 
 
 
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.15-1.0.16.php DELETED
@@ -1,2 +0,0 @@
1
- <?php
2
- Mage::getModel('awonpulse/credentials')->updateSettings(null);
 
 
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.15-1.0.17.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+ /* @var $installer Mage_Core_Model_Resource_Setup */
3
+ $installer = $this;
4
+ $installer = $this->startSetup();
5
+ $installer->endSetup();
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.17-2.0.0.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $installer = $this;
3
+ $installer->startSetup();
4
+ $installer->run("
5
+ UPDATE {$this->getTable('core/config_data')} SET path='awonpulse/access/credurlkey' WHERE path='awonpulse/general/credurlkey';
6
+ UPDATE {$this->getTable('core/config_data')} SET path='awonpulse/access/credhash' WHERE path='awonpulse/general/credhash';
7
+ ");
8
+ $installer->endSetup();
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.2-1.0.3.php DELETED
@@ -1 +0,0 @@
1
- <?php
 
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.3-1.0.4.php DELETED
@@ -1 +0,0 @@
1
- <?php
 
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.4-1.0.5.php DELETED
@@ -1 +0,0 @@
1
- <?php
 
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.5-1.0.6.php DELETED
@@ -1 +0,0 @@
1
- <?php
 
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.6-1.0.7.php DELETED
@@ -1 +0,0 @@
1
- <?php
 
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.7-1.0.8.php DELETED
@@ -1 +0,0 @@
1
- <?php
 
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.8-1.0.9.php DELETED
@@ -1 +0,0 @@
1
- <?php
 
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.9-1.0.10.php DELETED
@@ -1 +0,0 @@
1
- <?php
 
app/design/adminhtml/default/default/layout/aw_onpulse.xml CHANGED
@@ -1,12 +1,12 @@
1
- <?xml version="1.0"?>
2
- <layout>
3
- <default>
4
-
5
- </default>
6
- <adminhtml_system_config_edit>
7
- <reference name="content">
8
- <!--<block type="awonpulse/system_config_form_fieldset_onpulse_settings" name="aw_onpulse_settings" template="aw_onpulse/settings.phtml"></block>-->
9
- </reference>
10
- </adminhtml_system_config_edit>
11
-
12
  </layout>
1
+ <?xml version="1.0"?>
2
+ <layout>
3
+ <default>
4
+
5
+ </default>
6
+ <adminhtml_system_config_edit>
7
+ <reference name="content">
8
+ <!--<block type="awonpulse/system_config_form_fieldset_onpulse_settings" name="aw_onpulse_settings" template="aw_onpulse/settings.phtml"></block>-->
9
+ </reference>
10
+ </adminhtml_system_config_edit>
11
+
12
  </layout>
app/design/adminhtml/default/default/template/aw_onpulse/access.phtml ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $directLoginLink = null;
3
+ if ((Mage::getStoreConfig('awonpulse/access/credurlkey', Mage::app()->getDefaultStoreView()->getId())) && (Mage::getStoreConfig('awonpulse/access/credhash',Mage::app()->getDefaultStoreView()->getId()))) {
4
+ $credurlkey = Mage::getStoreConfig('awonpulse/access/credurlkey', Mage::app()->getDefaultStoreView()->getId());
5
+ $credhash = Mage::getStoreConfig('awonpulse/access/credhash', Mage::app()->getDefaultStoreView()->getId());
6
+ $qrsrc = 'http://chart.apis.google.com/chart?chs=250x250&cht=qr&chld=1/1&choe=utf-8&chl=';
7
+ $backUrl = Mage::app()->getDefaultStoreView()->getBaseUrl() . md5($credurlkey . $credhash);
8
+ $qrsrc .= 'http://m.onpulse.info/?qrhash=' . base64_encode($backUrl);
9
+ $directLoginLink = 'http://m.onpulse.info/?qrhash=' . base64_encode($backUrl);
10
+ } else {
11
+ $credurlkey = '';
12
+ $credhash = '';
13
+ $qrsrc = null;
14
+ }
15
+ $isDirectLoginLinkDisabled = !!Mage::getStoreConfig('awonpulse/general/ddl', Mage::app()->getDefaultStoreView()->getId());
16
+ ?>
17
+
18
+ <table class="form-list" id="access-fieldset">
19
+ <tbody>
20
+ <tr>
21
+ <td class="label">
22
+ <label><?php echo Mage::helper('awonpulse')->__('URL') ?></label>
23
+ </td>
24
+ <td class="value">
25
+ <input type="hidden" name="groups[access][fields][credurlkey][value]"
26
+ id="urlkey" value="<?php echo $credurlkey;?>"/>
27
+ <input class="input-text" style="width: 100%;" onclick="this.setSelectionRange(0, 9999)" type="text"
28
+ value="<?php echo Mage::app()->getDefaultStoreView()->getBaseUrl() . $credurlkey;?>"/>
29
+ <p class="note">
30
+ <span><?php echo Mage::helper('awonpulse')->__('Your login name to access OnPulse service') ?></span>
31
+ </p>
32
+ </td>
33
+ </tr>
34
+ <tr>
35
+ <td class="label">
36
+ <label><?php echo Mage::helper('awonpulse')->__('Key') ?></label>
37
+ </td>
38
+ <td class="value">
39
+ <input type="hidden" name="groups[access][fields][credhash][value]"
40
+ id="hash" value="<?php echo $credhash;?>"/>
41
+ <input class="input-text" style="width: 100%;" type="text" onclick="this.setSelectionRange(0, 9999)"
42
+ value="<?php echo $credhash;?>"/>
43
+ </td>
44
+ </tr>
45
+ <?php if ($directLoginLink && !$isDirectLoginLinkDisabled) : ?>
46
+ <tr>
47
+ <td class="label">
48
+ <label><?php echo Mage::helper('awonpulse')->__('Direct Login URL') ?></label>
49
+ </td>
50
+ <td style="padding-left: 6px; ">
51
+ <a href="<?php echo $directLoginLink;?>" style="display: block; width: 400px; padding-top: 5px;"
52
+ target="_blank"><?php echo substr($directLoginLink, 0, 60) . '...'; ?></a>
53
+ </td>
54
+ </tr>
55
+ <?php endif; ?>
56
+ <?php if ($qrsrc && !$isDirectLoginLinkDisabled) : ?>
57
+ <tr>
58
+ <td class="label">
59
+ <label><?php echo Mage::helper('awonpulse')->__('Direct Login QR') ?></label>
60
+ </td>
61
+ <td>
62
+ <img src="<?php echo $qrsrc; ?>" style="margin:-10px -30px;">
63
+ </td>
64
+ </tr>
65
+ <?php endif; ?>
66
+ <tr>
67
+ <td>
68
+ </td>
69
+ <td style="padding-left: 6px;">
70
+ <button><?php echo Mage::helper('awonpulse')->__('Generate new credentials') ?></button>
71
+ <p class="note">
72
+ <span><?php echo Mage::helper('awonpulse')->__('Each time you reset credentials OnPulse generates new URL, key, direct login and QR code') ?></span>
73
+ </p>
74
+ </td>
75
+ </tr>
76
+ </tbody>
77
+ </table>
78
+
79
+ <script type="text/javascript">
80
+ $$('#access-fieldset button').first().observe('click', function(e){
81
+ key = mkPass(8);
82
+ hash = mkPass(8);
83
+ $('urlkey').setValue(key);
84
+ $('hash').setValue(hash);
85
+ var el = new Element('form');
86
+ el.setStyle({display: 'none'});
87
+ el.setAttribute('action', <?php echo Zend_Json::encode($this->getGenerateUrl());?>);
88
+ el.setAttribute('method', 'post');
89
+ el.innerHTML += $$('#config_edit_form input[name=form_key]').first().outerHTML;
90
+ el.innerHTML += ($('access-fieldset').innerHTML);
91
+ document.body.appendChild(el);
92
+ el.submit();
93
+ Event.stop(e);
94
+ });
95
+
96
+ function mtRand(min, max) {
97
+ var range = max - min + 1;
98
+ return Math.floor(Math.random() * range) + min;
99
+ }
100
+
101
+ function mkPass(len) {
102
+ len = 8;
103
+ var pass = '';
104
+ var rnd = 0;
105
+ var c = '';
106
+ for (i = 0; i < len; i++) {
107
+ rnd = mtRand(0, 1); // Латиница или цифры
108
+ if (rnd == 0) {
109
+ c = String.fromCharCode(mtRand(48, 57));
110
+ }
111
+ if (rnd == 1) {
112
+ c = String.fromCharCode(mtRand(97, 122));
113
+ }
114
+ pass += c;
115
+ }
116
+ return pass;
117
+ }
118
+ </script>
app/design/adminhtml/default/default/template/aw_onpulse/settings.phtml DELETED
@@ -1,155 +0,0 @@
1
- <?php
2
- $directLoginLink = null;
3
- $ddl = Mage::getStoreConfig('awonpulse/general/ddl',Mage::app()->getDefaultStoreView()->getId());
4
- $ordersStatusCollection = Mage::getSingleton('sales/order_config')->getStatuses();
5
- $ordersstatus = Mage::getStoreConfig('awonpulse/general/ordersstatus',Mage::app()->getDefaultStoreView()->getId());
6
- $ordersstatus = explode(',', $ordersstatus);
7
- $size = count($ordersStatusCollection);
8
-
9
- if ((Mage::getStoreConfig('awonpulse/general/credurlkey',Mage::app()->getDefaultStoreView()->getId())) && (Mage::getStoreConfig('awonpulse/general/credhash',Mage::app()->getDefaultStoreView()->getId()))) {
10
- $credurlkey = Mage::getStoreConfig('awonpulse/general/credurlkey',Mage::app()->getDefaultStoreView()->getId());
11
- $credhash = Mage::getStoreConfig('awonpulse/general/credhash',Mage::app()->getDefaultStoreView()->getId());
12
- $qrsrc = 'http://chart.apis.google.com/chart?chs=250x250&cht=qr&chld=1/1&choe=utf-8&chl=';
13
- $backUrl = Mage::app()->getDefaultStoreView()->getBaseUrl() . md5($credurlkey . $credhash);
14
- $qrsrc .= 'http://m.onpulse.info/?qrhash=' . base64_encode($backUrl);
15
- $directLoginLink = 'http://m.onpulse.info/?qrhash=' . base64_encode($backUrl);
16
- } else {
17
- $credurlkey = '';
18
- $credhash = '';
19
- $qrsrc = null;
20
- }
21
- ?>
22
-
23
- <table class="form-list">
24
- <tbody>
25
- <form method="post">
26
- <tr>
27
- <td class="label">
28
- <label><?php echo Mage::helper('awonpulse')->__('URL') ?></label>
29
- </td>
30
- <td class="value">
31
- <input class="input-text" style="width: 600px;" onclick="this.select()" type="text" readonly="readonly"
32
- name="groups[general][fields][credurlkey][value]" id="urlkey"
33
- value="<?php echo Mage::app()->getDefaultStoreView()->getBaseUrl() . $credurlkey;?>">
34
-
35
- <p class="note">
36
- <span><?php echo Mage::helper('awonpulse')->__('Your login name to access OnPulse service') ?></span>
37
- </p>
38
- </td>
39
- </tr>
40
- <tr>
41
- <td class="label">
42
- <label><?php echo Mage::helper('awonpulse')->__('Key') ?></label>
43
- </td>
44
- <td class="value">
45
- <input class="input-text" style="width: 600px;" type="text" onclick="this.select()" readonly="readonly"
46
- name="groups[general][fields][credhash][value]" id="hash" value="<?php echo $credhash;?>">
47
- </td>
48
- </tr>
49
- <tr>
50
- <td class="label">
51
- <label><?php echo Mage::helper('awonpulse')->__('Disable direct login link') ?></label>
52
- </td>
53
- <td class="value">
54
- <select name="groups[general][fields][ddl][value]" id="ddl" autofocus>
55
- <option <?php if($ddl=="1") echo "selected" ?> value="1"><?php echo Mage::helper('awonpulse')->__('Yes') ?></option>
56
- <option <?php if($ddl=="0") echo "selected" ?> value="0"><?php echo Mage::helper('awonpulse')->__('No') ?></option>
57
- </select>
58
- </td>
59
- </tr>
60
- <?php if ($directLoginLink) : ?>
61
- <tr>
62
- <td class="label">
63
- <label><?php echo Mage::helper('awonpulse')->__('Direct login URL') ?></label>
64
- </td>
65
- <td style="padding-left: 6px; ">
66
- <a href="<?php echo $directLoginLink;?>" style="display: block; width: 600px; padding-top: 5px;"
67
- target="_blank"><?php echo substr($directLoginLink, 0, 80) . '...'; ?></a>
68
- </td>
69
- </tr>
70
- <?php endif; ?>
71
- <?php if ($qrsrc) : ?>
72
- <tr>
73
- <td class="label">
74
- <label><?php echo Mage::helper('awonpulse')->__('Direct login QR') ?></label>
75
- </td>
76
- <td>
77
- <br/>&nbsp;&nbsp;<img src="<?php echo $qrsrc; ?>">
78
- </td>
79
- </tr>
80
- <?php endif; ?>
81
-
82
- <tr>
83
- <td class="label">
84
- <label><?php echo Mage::helper('awonpulse')->__('Show statistic for orders with statuses') ?></label>
85
- </td>
86
- <td class="value">
87
- <select multiple name="groups[general][fields][ordersstatus][value][]" id="ordersstatus" size="<?php echo $size?>">
88
- <?php foreach ($ordersStatusCollection as $storeOrderStatus => $statusLabel): ?>
89
- <?php
90
- if (in_array($storeOrderStatus,$ordersstatus)){
91
- $selected = "selected";
92
- } else {
93
- $selected = "";
94
- }
95
- ?>
96
- <option <?php echo $selected; ?> value="<?php echo $storeOrderStatus; ?>"><?php echo $statusLabel; ?></option>
97
- <?php endforeach;?>
98
- </select>
99
- </td>
100
- </tr>
101
- <tr>
102
- <td>
103
- </td>
104
- <td style="padding-left: 6px; padding-top: 10px;">
105
- <button onclick="generate(this);"><?php echo Mage::helper('awonpulse')->__('Save and generate new login credentials') ?></button>
106
- <p class="note">
107
- <span><?php echo Mage::helper('awonpulse')->__('Each time you reset credentials OnPulse generates new URL, key, direct login and QR code') ?></span>
108
- </p>
109
- </td>
110
- </tr>
111
- </form>
112
- </tbody>
113
- </table>
114
-
115
- <script type="text/javascript">
116
- var flagSubmit = false;
117
- function generate() {
118
- if (!flagSubmit) {
119
- key = mkPass(8);
120
- hash = mkPass(8);
121
- document.getElementById('urlkey').value = key;
122
- document.getElementById('hash').value = hash;
123
- flagSubmit = true;
124
- }
125
- }
126
-
127
- function mtRand(min, max) {
128
- var range = max - min + 1;
129
- var n = Math.floor(Math.random() * range) + min;
130
- return n;
131
- }
132
-
133
- function mkPass(len) {
134
- var len = 8;
135
- var pass = '';
136
- var rnd = 0;
137
- var c = '';
138
- for (i = 0; i < len; i++) {
139
- rnd = mtRand(0, 1); // Латиница или цифры
140
- if (rnd == 0) {
141
- c = String.fromCharCode(mtRand(48, 57));
142
- }
143
- if (rnd == 1) {
144
- c = String.fromCharCode(mtRand(97, 122));
145
- }
146
- pass += c;
147
- }
148
- return pass;
149
- }
150
-
151
- document.getElementsByClassName('form-buttons')[0].style.display = 'none';
152
- document.getElementsByClassName('form-buttons')[1].style.display = 'none';
153
-
154
-
155
- </script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/locale/en_US/AW_Onpulse.csv CHANGED
@@ -1,13 +1,17 @@
1
- "Hash","Hash"
2
- "Url key","Url key"
3
- "URL","URL"
4
- "Your login name to access OnPulse service","Your login name to access OnPulse service"
5
- "Key","Key"
6
- "Direct login URL","Direct login URL"
7
- "Direct login QR","Direct login QR"
8
- "Save and generate new login credentials","Save and generate new login credentials"
9
- "Each time you reset credentials OnPulse generates new URL, key, direct login and QR code","Each time you reset credentials OnPulse generates new URL, key, direct login and QR code"
10
- "Disable direct login link","Disable direct login link"
11
- "Yes","Yes"
12
- "No","No"
13
- "Show statistic for orders with statuses","Show statistic for orders with statuses"
 
 
 
 
1
+ "Hash","Hash"
2
+ "Url key","Url key"
3
+ "URL","URL"
4
+ "Your login name to access OnPulse service","Your login name to access OnPulse service"
5
+ "Key","Key"
6
+ "Direct Login URL","Direct Login URL"
7
+ "Direct Login QR","Direct Login QR"
8
+ "Generate new credentials","Generate new credentials"
9
+ "Each time you reset credentials OnPulse generates new URL, key, direct login and QR code","Each time you reset credentials OnPulse generates new URL, key, direct login and QR code"
10
+ "Disable Direct Login Link","Disable Direct Login Link"
11
+ "Yes","Yes"
12
+ "No","No"
13
+ "Show Statistic for Orders with Statuses","Show Statistic for Orders with Statuses"
14
+ "New login credentials has been generated.","New login credentials has been generated."
15
+ "Revenue","Revenue"
16
+ "Profit","Profit"
17
+ "Show Sales Statistics As","Show Sales Statistics As"
package.xml CHANGED
@@ -1,19 +1,25 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>AW_Onpulse</name>
4
- <version>1.0.16</version>
5
  <stability>stable</stability>
6
  <license uri="http://onpulse.info/TOS.pdf">EULA</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Mobile administration for Magento</summary>
10
- <description>OnPulse provides you with an access to your sales statistics, the latest orders, and the clients list through any iOS or Android powered mobile device.&#xD;
11
- </description>
12
- <notes>* minor bug fixes</notes>
 
 
 
 
 
 
13
  <authors><author><name>AW_Core_Team</name><user>aheadworks</user><email>no-reply@aheadworks.com</email></author></authors>
14
- <date>2013-11-27</date>
15
- <time>08:28:15</time>
16
- <contents><target name="magelocal"><dir name="AW"><dir name="Onpulse"><dir name="Block"><dir name="System"><dir name="Config"><dir name="Form"><dir name="Fieldset"><dir name="Onpulse"><file name="Settings.php" hash="6ba04d380ea7140b42c54f00a0acc452"/></dir></dir></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="e3365bfa6343d642d8b59179bc4036d9"/></dir><dir name="Model"><dir name="Aggregator"><file name="Component.php" hash="47a0a36eaca33135f61c1e422008dd95"/><dir name="Components"><file name="Customer.php" hash="52df2d3be2d6196ee957b2e2c0d92cb2"/><file name="Order.php" hash="a9a23d8f678a68f1b245b97126cc3116"/><file name="Statistics.php" hash="77cac36504884fac83e957ee86708d7b"/></dir></dir><file name="Aggregator.php" hash="fcb4342d583403a99ca7bc245115854f"/><file name="Credentials.php" hash="5ba6633fd12f1f140060935ed129568f"/></dir><dir name="controllers"><file name="IndexController.php" hash="098362320754126d5fc3b009c97bdc05"/></dir><dir name="etc"><file name="config.xml" hash="2e0489c24773988e471405a7c5c43070"/><file name="system.xml" hash="11fa0896cc56063c5c572d992622e224"/></dir><dir name="sql"><dir name="awonpulse_setup"><file name="mysql4-install-1.0.0.php" hash="f84214fc43f665c79b92dc7a092b364f"/><file name="mysql4-upgrade-1.0.0-1.0.1.php" hash="f84214fc43f665c79b92dc7a092b364f"/><file name="mysql4-upgrade-1.0.1-1.0.2.php" hash="f84214fc43f665c79b92dc7a092b364f"/><file name="mysql4-upgrade-1.0.10-1.0.11.php" hash="f84214fc43f665c79b92dc7a092b364f"/><file name="mysql4-upgrade-1.0.11-1.0.12.php" hash="f84214fc43f665c79b92dc7a092b364f"/><file name="mysql4-upgrade-1.0.12-1.0.13.php" hash="f84214fc43f665c79b92dc7a092b364f"/><file name="mysql4-upgrade-1.0.13-1.0.14.php" hash="f84214fc43f665c79b92dc7a092b364f"/><file name="mysql4-upgrade-1.0.14-1.0.15.php" hash="1aa80829989638f96e7281d7f449a804"/><file name="mysql4-upgrade-1.0.14-1.0.16.php" hash="1a81b17c6d1a2030d4676e186516b325"/><file name="mysql4-upgrade-1.0.15-1.0.16.php" hash="6b71e37948074480ac6598397935a69f"/><file name="mysql4-upgrade-1.0.2-1.0.3.php" hash="f84214fc43f665c79b92dc7a092b364f"/><file name="mysql4-upgrade-1.0.3-1.0.4.php" hash="f84214fc43f665c79b92dc7a092b364f"/><file name="mysql4-upgrade-1.0.4-1.0.5.php" hash="f84214fc43f665c79b92dc7a092b364f"/><file name="mysql4-upgrade-1.0.5-1.0.6.php" hash="f84214fc43f665c79b92dc7a092b364f"/><file name="mysql4-upgrade-1.0.6-1.0.7.php" hash="f84214fc43f665c79b92dc7a092b364f"/><file name="mysql4-upgrade-1.0.7-1.0.8.php" hash="f84214fc43f665c79b92dc7a092b364f"/><file name="mysql4-upgrade-1.0.8-1.0.9.php" hash="f84214fc43f665c79b92dc7a092b364f"/><file name="mysql4-upgrade-1.0.9-1.0.10.php" hash="f84214fc43f665c79b92dc7a092b364f"/></dir></dir></dir></dir></target><target name="mage"><dir name="app"><dir name="design"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="aw_onpulse"><file name="settings.phtml" hash="259e3fd0947f216455a33862dfb1930e"/></dir></dir></dir></dir></dir></dir><dir name="etc"><dir name="modules"><file name="AW_Onpulse.xml" hash="de39a5ffebb31ee697fbaf56bb1bfb8a"/></dir></dir><dir name="locale"><dir name="en_US"><file name="AW_Onpulse.csv" hash="23f7bee483404129d0f811a2f53cf38d"/></dir></dir></dir><dir><dir name="app"><dir name="design"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="aw_onpulse.xml" hash="5036d3b89b9a204c9420f40f3983d987"/></dir></dir></dir></dir></dir></dir></dir></target></contents>
17
  <compatible/>
18
- <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
19
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>AW_Onpulse</name>
4
+ <version>2.0.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://onpulse.info/TOS.pdf">EULA</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Mobile administration for Magento</summary>
10
+ <description>OnPulse provides you with an access to your sales statistics, the latest orders, and the clients list through any iOS or Android powered mobile device.</description>
11
+ <notes>The update includes a number of all-new reports, improved sales forecast algorithm and the ability to search and view order and customer data. Here is the full list of new features:&#xD;
12
+ - Ability to search and view all clients and orders by name, email or ID&#xD;
13
+ - Displays sales stats as profit or revenue&#xD;
14
+ - Sales by country report&#xD;
15
+ - Items per order report (IPO)&#xD;
16
+ - Average order value report (AOV)&#xD;
17
+ - Last orders with items on the dashboard&#xD;
18
+ - Improved sales forecast algorithm</notes>
19
  <authors><author><name>AW_Core_Team</name><user>aheadworks</user><email>no-reply@aheadworks.com</email></author></authors>
20
+ <date>2015-03-17</date>
21
+ <time>13:21:25</time>
22
+ <contents><target name="mageetc"><dir name="modules"><file name="AW_Onpulse.xml" hash="de39a5ffebb31ee697fbaf56bb1bfb8a"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="aw_onpulse.xml" hash="d09056058d50d23c5c6d23c977dd5597"/></dir><dir name="template"><dir name="aw_onpulse"><file name="access.phtml" hash="83d79128f5e5311afa966d14922e5639"/></dir></dir></dir></dir></dir></target><target name="magelocale"><dir name="en_US"><file name="AW_Onpulse.csv" hash="4aa10dde01a5cdcd2cf8393dad7c3307"/></dir></target><target name="magelocal"><dir name="AW"><dir name="Onpulse"><dir name="Block"><dir name="System"><dir name="Config"><dir name="Form"><dir name="Fieldset"><dir name="Onpulse"><file name="Access.php" hash="fd13a1db644a64d8c94f3d4a4c6d7209"/></dir></dir></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="739f1a113831f84b57e340faaf81b0b4"/></dir><dir name="Model"><dir name="Aggregator"><file name="Component.php" hash="f5fad1561e9416e2180915eb27338de0"/><dir name="Components"><file name="Customer.php" hash="154fc0cd3d6f05328297d2c210d074dc"/><file name="Order.php" hash="4d73ae227b6b259268207f9fdea11215"/><file name="Statistics.php" hash="b6c68cb748c294fc2ed506fce8443f86"/></dir></dir><file name="Aggregator.php" hash="25c9afc28898537ba928261ba6039d46"/><file name="Credentials.php" hash="5e47eeda766011b0c62eb3950a266013"/><dir name="Source"><file name="OrderStatus.php" hash="ee2303fe70a4079444f78c9f7f4b26f7"/><file name="ProfitRevenue.php" hash="9d62f0d63ee294a85952a59fe67865b8"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="ConfigController.php" hash="c2f131fd09f9bcf903c4a759fcd7a3c4"/></dir><file name="IndexController.php" hash="10fb4c82c9d718b25cbc41b11ba390d5"/></dir><dir name="etc"><file name="config.xml" hash="2ef39dbb27830686ca3042dee1c3d67d"/><file name="system.xml" hash="1208189b11076e1f29a54fce5ea22eeb"/></dir><dir name="sql"><dir name="awonpulse_setup"><file name="mysql4-install-1.0.0.php" hash="f9df2f05fb3189102247b4c6fcee81e9"/><file name="mysql4-upgrade-1.0.0-1.0.14.php" hash="f9df2f05fb3189102247b4c6fcee81e9"/><file name="mysql4-upgrade-1.0.14-1.0.15.php" hash="82ed6ef244e3a14e61846f5dce1c7125"/><file name="mysql4-upgrade-1.0.15-1.0.17.php" hash="f9df2f05fb3189102247b4c6fcee81e9"/><file name="mysql4-upgrade-1.0.17-2.0.0.php" hash="a7ce80bcd8e64c2b7f2a4ee227664680"/></dir></dir></dir></dir></target></contents>
23
  <compatible/>
24
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
25
  </package>