AW_Onpulse - Version 1.0.15

Version Notes

* stability improvements
* minor bug fixes

Download this release

Release Info

Developer AW_Core_Team
Extension AW_Onpulse
Version 1.0.15
Comparing to
See all releases


Code changes from version 1.0.14 to 1.0.15

Files changed (27) hide show
  1. app/code/local/AW/Onpulse/Helper/Data.php +58 -15
  2. app/code/local/AW/Onpulse/Helper/Data.php.orig +0 -249
  3. app/code/local/AW/Onpulse/Model/Aggregator/Components/Statistics.php +12 -12
  4. app/code/local/AW/Onpulse/Model/Aggregator/Components/Statistics.php.orig +0 -260
  5. app/code/local/AW/Onpulse/Model/Credentials.php +66 -72
  6. app/code/local/AW/Onpulse/controllers/IndexController.php +43 -4
  7. app/code/local/AW/Onpulse/etc/config.xml +17 -6
  8. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-install-1.0.0.php +1 -0
  9. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.0-1.0.1.php +1 -0
  10. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.1-1.0.2.php +1 -0
  11. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.10-1.0.11.php +1 -0
  12. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.11-1.0.12.php +1 -0
  13. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.12-1.0.13.php +1 -0
  14. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.13-1.0.14.php +1 -0
  15. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.14-1.0.15.php +2 -0
  16. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.14-1.0.16.php +3 -0
  17. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.15-1.0.16.php +2 -0
  18. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.2-1.0.3.php +1 -0
  19. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.3-1.0.4.php +1 -0
  20. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.4-1.0.5.php +1 -0
  21. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.5-1.0.6.php +1 -0
  22. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.6-1.0.7.php +1 -0
  23. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.7-1.0.8.php +1 -0
  24. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.8-1.0.9.php +1 -0
  25. app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.9-1.0.10.php +1 -0
  26. app/design/adminhtml/default/default/template/aw_onpulse/settings.phtml +5 -5
  27. package.xml +5 -5
app/code/local/AW/Onpulse/Helper/Data.php CHANGED
@@ -7,6 +7,49 @@ class AW_Onpulse_Helper_Data extends Mage_Core_Helper_Abstract
7
 
8
  public $dateTimeFormat = null;
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  public function getPriceFormat($price)
11
  {
12
  $price = sprintf("%01.2f", $price);
@@ -51,14 +94,14 @@ class AW_Onpulse_Helper_Data extends Mage_Core_Helper_Abstract
51
  $country = $this->_countries[$customer->getData("{$addresType}_country_id")];
52
  }
53
  return array(
54
- 'first_name' => $customer->getData("{$addresType}_firstname"),
55
- 'last_name' => $customer->getData("{$addresType}_lastname"),
56
- 'postcode' => $customer->getData("{$addresType}_postcode"),
57
- 'city' => $customer->getData("{$addresType}_city"),
58
- 'street' => $customer->getData("{$addresType}_street"),
59
- 'telephone' => $this->escapeHtml($customer->getData("{$addresType}_telephone")),
60
- 'region' => $customer->getData("{$addresType}_region"),
61
- 'country' => $country,
62
  );
63
  }
64
  return array();
@@ -72,14 +115,14 @@ class AW_Onpulse_Helper_Data extends Mage_Core_Helper_Abstract
72
  $country = $this->_countries[$order->getData("country_id")];
73
  }
74
  return array(
75
- 'first_name' => $order->getData("firstname"),
76
- 'last_name' => $order->getData("lastname"),
77
- 'postcode' => $order->getData("postcode"),
78
- 'city' => $order->getData("city"),
79
- 'street' => $order->getData("street"),
80
  'telephone' => $this->escapeHtml($order->getData("telephone")),
81
- 'region' => $order->getData("region"),
82
- 'country' => $country,
83
  );
84
  }
85
 
7
 
8
  public $dateTimeFormat = null;
9
 
10
+ const EE_PLATFORM = 100;
11
+ const PE_PLATFORM = 10;
12
+ const CE_PLATFORM = 0;
13
+
14
+ const ENTERPRISE_DETECT_COMPANY = 'Enterprise';
15
+ const ENTERPRISE_DETECT_EXTENSION = 'Enterprise';
16
+ const ENTERPRISE_DESIGN_NAME = "enterprise";
17
+ const PROFESSIONAL_DESIGN_NAME = "pro";
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
+ }
44
+ }
45
+ self::$_platform = self::EE_PLATFORM;
46
+ }
47
+ }
48
+ return self::$_platform;
49
+ }
50
+
51
+
52
+
53
  public function getPriceFormat($price)
54
  {
55
  $price = sprintf("%01.2f", $price);
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();
115
  $country = $this->_countries[$order->getData("country_id")];
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
 
app/code/local/AW/Onpulse/Helper/Data.php.orig DELETED
@@ -1,249 +0,0 @@
1
- <?php
2
-
3
- class AW_Onpulse_Helper_Data extends Mage_Core_Helper_Abstract
4
- {
5
- const RECENT_ORDERS_COUNT = 5;
6
- const PRECISION = 2;
7
-
8
- public $dateTimeFormat = null;
9
-
10
- public function getPriceFormat($data)
11
- {
12
- $data = round($data,2);
13
- //$data = Mage::getModel('core/store')->formatPrice($data,false);
14
- //$data = number_format($data, self::PRECISION, '.', '');
15
- return $data;
16
- }
17
-
18
- private $_countries = array();
19
-
20
- private function _getItemOptions($item)
21
- {
22
- $result = array();
23
- if ($options = $item->getProductOptions()) {
24
- if (isset($options['options'])) {
25
- $result = array_merge($result, $options['options']);
26
- }
27
- if (isset($options['additional_options'])) {
28
- $result = array_merge($result, $options['additional_options']);
29
- }
30
- if (isset($options['attributes_info'])) {
31
- $result = array_merge($result, $options['attributes_info']);
32
- }
33
- }
34
- return $result;
35
- }
36
-
37
- private function _getAddresInfoArray($customer, $addresType = 'billing')
38
- {
39
-
40
- if ($customer->getData("default_{$addresType}")) {
41
-
42
- //Prevent Notice if can't find country name by code
43
- $country = $customer->getData("{$addresType}_country_id");
44
- if (isset($this->_countries[$customer->getData("{$addresType}_country_id")])) {
45
- $country = $this->_countries[$customer->getData("{$addresType}_country_id")];
46
- }
47
- return array(
48
- 'first_name' => $customer->getData("{$addresType}_firstname"),
49
- 'last_name' => $customer->getData("{$addresType}_lastname"),
50
- 'postcode' => $customer->getData("{$addresType}_postcode"),
51
- 'city' => $customer->getData("{$addresType}_city"),
52
- 'street' => $customer->getData("{$addresType}_street"),
53
- 'telephone' => $this->escapeHtml($customer->getData("{$addresType}_telephone")),
54
- 'region' => $customer->getData("{$addresType}_region"),
55
- 'country' => $country,
56
- );
57
- }
58
- return array();
59
- }
60
-
61
- private function _getAddresInfoFromOrderToArray($order)
62
- {
63
- //Prevent Notice if can't find country name by code
64
- $country = $order->getData("country_id");
65
- if (isset($this->_countries[$order->getData("country_id")])) {
66
- $country = $this->_countries[$order->getData("country_id")];
67
- }
68
- return array(
69
- 'first_name' => $order->getData("firstname"),
70
- 'last_name' => $order->getData("lastname"),
71
- 'postcode' => $order->getData("postcode"),
72
- 'city' => $order->getData("city"),
73
- 'street' => $order->getData("street"),
74
- 'telephone' => $this->escapeHtml($order->getData("telephone")),
75
- 'region' => $order->getData("region"),
76
- 'country' => $country,
77
- );
78
- }
79
-
80
- private function _getCustomersRecentOrders($customer)
81
- {
82
- /** @var $orderCollection Mage_Sales_Model_Resource_Order_Collection */
83
- $orderCollection = Mage::getModel('sales/order')->getCollection();
84
- $orderCollection->addAddressFields()
85
- ->addAttributeToFilter('customer_id', array('eq' => $customer->getId()))
86
- ->addAttributeToSelect('*')
87
- ->addOrder('entity_id', 'DESC')
88
- ->setPageSize(self::RECENT_ORDERS_COUNT);
89
- return $orderCollection;
90
- }
91
-
92
- private function _getProductsArrayFromOrder($order)
93
- {
94
- $products = array();
95
-
96
- foreach ($order->getItemsCollection() as $item) {
97
- $product = array();
98
- if ($item->getParentItem()) continue;
99
- if ($_options = $this->_getItemOptions($item)) {
100
- foreach ($_options as $_option) {
101
- $product['options'][$_option['label']] = $_option['value'];
102
- }
103
- }
104
- $product['name'] = $this->escapeHtml($item->getName());
105
- $product['price'] = $this->getPriceFormat($item->getBaseRowTotal());
106
- $product['qty'] = round($item->getQtyOrdered(), self::PRECISION);
107
- $products[] = $product;
108
-
109
- }
110
- return $products;
111
- }
112
-
113
- public function processOutput($data)
114
- {
115
- $this->dateTimeFormat = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
116
- //var_dump($this->dateTimeFormat);die;
117
- $clients = $data->getData('clients');
118
- $orders = $data->getData('orders');
119
- $dashboard = $data->getData('dashboard');
120
- $processedClients = array();
121
- $processedDashboardClients = array();
122
- $processedOrders = array();
123
- foreach (Mage::helper('directory')->getCountryCollection() as $country) {
124
- $this->_countries[$country->getId()] = $country->getName();
125
- }
126
-
127
- if ($clients->getSize())
128
- foreach ($clients as $customer) {
129
- $processedClients[] = $this->processCustomerToArray($customer, true);
130
-
131
- }
132
-
133
- if($orders->getSize())
134
- foreach($orders as $order) {
135
- $processedOrders[] = $this->processOrderToArray($order);
136
- }
137
- //var_dump($processedOrders);
138
- //die;
139
-
140
- $processedDashboardClientsToday = array();
141
- $processedDashboardClientsYesterday = array();
142
- if ($dashboard['customers']['today_customers']['registered']->getSize()) {
143
- foreach ($dashboard['customers']['today_customers']['registered'] as $customer) {
144
- $processedDashboardClientsToday[] = $this->processCustomerToArray($customer, true);
145
- }
146
- }
147
-
148
- if ($dashboard['customers']['yesterday_customers']['registered']->getSize()) {
149
- foreach ($dashboard['customers']['yesterday_customers']['registered'] as $customer) {
150
- $processedDashboardClientsYesterday[] = $this->processCustomerToArray($customer, true);
151
- }
152
- }
153
- $dashboard['customers']['today_customers']['registered'] = count($processedDashboardClientsToday);
154
- $dashboard['customers']['yesterday_customers']['registered'] = count($processedDashboardClientsYesterday);
155
-
156
- return array(
157
- 'connector_version' => (string)Mage::getConfig()->getNode()->modules->AW_Onpulse->version,
158
- 'clients' => $processedClients,
159
- 'orders' => $processedOrders,
160
- 'dashboard' => $dashboard,
161
- 'storename' => strip_tags(Mage::getStoreConfig('general/store_information/name')),
162
- 'curSymbol' => Mage::app()->getLocale()->currency(Mage::app()->getStore()->getBaseCurrencyCode())->getSymbol(),
163
- );
164
- }
165
-
166
-
167
- public function processOrderToArray($order)
168
- {
169
-
170
- $customer = '';
171
- if ($order->getCustomerId()) {
172
- $customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
173
- if ($customer)
174
- $customer = $this->processCustomerToArray($customer);
175
- }
176
- if(!$order->getGiftCardsAmount()) {
177
- $order->setGiftCardsAmount(0);
178
- }
179
-
180
- $orderInfo = array(
181
- 'increment_id' => $order->getIncrementId(),
182
- 'creation_date' => $order->getCreatedAtFormated($this->dateTimeFormat)->toString($this->dateTimeFormat),
183
- 'customer_firstname' => $this->escapeHtml($order->getCustomerFirstname()),
184
- 'customer_lastname' => $this->escapeHtml($order->getCustomerLastname()),
185
- 'customer_email' => $order->getCustomerEmail(),
186
- 'status_code' => $order->getStatus(),
187
- 'status' => htmlspecialchars($order->getStatusLabel()),
188
- 'subtotal' => $this->getPriceFormat($order->getBaseSubtotal()),
189
- 'discount' => $this->getPriceFormat($order->getBaseDiscountAmount()),
190
- 'grand_total' => $this->getPriceFormat($order->getBaseGrandTotal()),
191
- 'shipping_amount' => $this->getPriceFormat($order->getBaseShippingAmount()),
192
- 'tax' => $this->getPriceFormat($order->getBaseTaxAmount()),
193
- 'gift_cards_amount' => $this->getPriceFormat($order->getGiftCardsAmount()),
194
- 'currency' => Mage::app()->getLocale()->currency(Mage::app()->getStore()->getBaseCurrencyCode())->getSymbol(),
195
-
196
- //-----------------------------------------------------
197
- 'items' => $this->_getProductsArrayFromOrder($order),
198
- 'customer' => $customer,
199
- 'billing' => $this->_getAddresInfoFromOrderToArray($order->getBillingAddress()),
200
- );
201
-
202
- if (!$order->getIsVirtual()) {
203
- $orderInfo['shipping'] = $this->_getAddresInfoFromOrderToArray($order->getShippingAddress());
204
- }
205
-
206
- return $orderInfo;
207
- }
208
-
209
-
210
- public function processCustomerToArray($customer, $additional = false)
211
- {
212
- $client = array();
213
-
214
- $client['id'] = $customer->getId();
215
- $client['first_name'] = $this->escapeHtml($customer->getFirstname());
216
- $client['last_name'] = $this->escapeHtml($customer->getLastname());
217
- $client['email'] = $customer->getEmail();
218
- //$client['date_registered'] = $customer->getCreatedAt();
219
- $client['date_registered'] = Mage::app()->getLocale()->date($customer->getCreatedAt())->toString($this->dateTimeFormat);
220
-
221
- $client['country'] = '';
222
- if ($customer->getData('billing_country_id')) {
223
- $client['country'] = $this->_countries[$customer->getData('billing_country_id')];
224
- }
225
-
226
- $client['phone'] = '';
227
- if ($customer->getData('billing_telephone')) {
228
- $client['phone'] = $this->escapeHtml($customer->getData('billing_telephone'));
229
- }
230
-
231
- if ($additional) {
232
- // Format billing address data
233
- $client['billing'] = $this->_getAddresInfoArray($customer, 'billing');
234
-
235
- // Format shipping address data
236
- $client['shipping'] = $this->_getAddresInfoArray($customer, 'shipping');
237
-
238
- $orders = $this->_getCustomersRecentOrders($customer);
239
- $customerOrders = array();
240
- if ($orders->getSize()) {
241
- foreach ($orders as $order) {
242
- $customerOrders[] = $this->processOrderToArray($order);
243
- }
244
- }
245
- $client['orders'] = $customerOrders;
246
- }
247
- return $client;
248
- }
249
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/AW/Onpulse/Model/Aggregator/Components/Statistics.php CHANGED
@@ -21,17 +21,15 @@ class AW_Onpulse_Model_Aggregator_Components_Statistics extends AW_Onpulse_Model
21
  //set default timezone for store (admin)
22
  $dateObj->setTimezone(Mage::app()->getStore()->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE));
23
 
24
- //set begining of day
25
- $dateObj->setHour(00);
26
- $dateObj->setMinute(00);
27
- $dateObj->setSecond(00);
28
-
29
  //set date with applying timezone of store
30
  $dateObj->set($now, Zend_Date::DATE_SHORT, Mage::app()->getLocale()->getDefaultLocale());
31
 
32
  //convert store date to default date in UTC timezone without DST
33
  $dateObj->setTimezone(Mage_Core_Model_Locale::DEFAULT_TIMEZONE);
34
-
 
 
 
35
  return $dateObj;
36
  }
37
 
@@ -99,7 +97,7 @@ class AW_Onpulse_Model_Aggregator_Components_Statistics extends AW_Onpulse_Model
99
  private function _getBestsellers($date)
100
  {
101
  /** @var $date Zend_Date */
102
- $orderstatus = Mage::getStoreConfig('awonpulse/general/ordersstatus');
103
  $orderstatus = explode(',', $orderstatus);
104
  if (count($orderstatus)==0){
105
  $orderstatus = array(Mage_Sales_Model_Order::STATE_COMPLETE);
@@ -132,7 +130,7 @@ class AW_Onpulse_Model_Aggregator_Components_Statistics extends AW_Onpulse_Model
132
  }*/
133
  //$product = Mage::getModel('catalog/product')->load($orderItem->getProductId());
134
  $items[$orderItem['product_id']] = array(
135
- 'name'=>$orderItem['name'],
136
  'qty'=>0,
137
  'amount' => 0
138
  );
@@ -157,7 +155,7 @@ class AW_Onpulse_Model_Aggregator_Components_Statistics extends AW_Onpulse_Model
157
  {
158
 
159
  //collect yesterday orders count
160
- $ordersstatus = Mage::getStoreConfig('awonpulse/general/ordersstatus');
161
  $ordersstatus = explode(',', $ordersstatus);
162
  if (count($ordersstatus)==0){
163
  $ordersstatus = array(Mage_Sales_Model_Order::STATE_COMPLETE);
@@ -213,7 +211,7 @@ class AW_Onpulse_Model_Aggregator_Components_Statistics extends AW_Onpulse_Model
213
 
214
  private function _getSales($date)
215
  {
216
- $ordersstatus = Mage::getStoreConfig('awonpulse/general/ordersstatus');
217
  $ordersstatus = explode(',', $ordersstatus);
218
  if (count($ordersstatus)==0){
219
  $ordersstatus = array(Mage_Sales_Model_Order::STATE_COMPLETE);
@@ -239,9 +237,11 @@ class AW_Onpulse_Model_Aggregator_Components_Statistics extends AW_Onpulse_Model
239
  }
240
  }
241
  }
 
242
  $daysFrom1st=$copyDate->get(Zend_Date::DAY);
 
243
  $orders = Mage::getModel('sales/order')->getCollection();
244
- $orders->addAttributeToFilter('created_at', array('from' => $copyDate->addDay(-($daysFrom1st-1))->toString(Varien_Date::DATETIME_INTERNAL_FORMAT),'to'=>$copyDate->addDay($daysFrom1st)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)))
245
  ->addAttributeToSelect('*')
246
  ->addAttributeToFilter('status', array('in' => $ordersstatus));
247
  $thisMonthSoFar = 0;
@@ -250,7 +250,7 @@ class AW_Onpulse_Model_Aggregator_Components_Statistics extends AW_Onpulse_Model
250
  $thisMonthSoFar+=$order->getBaseGrandTotal();
251
  }
252
  }
253
- $thisMonthForecast = 0;
254
  $numberDaysInMonth = $copyDate->get(Zend_Date::MONTH_DAYS);
255
  $thisMonthAvg = $thisMonthSoFar /($daysFrom1st-1);
256
  $thisMonthForecast = $thisMonthAvg * $numberDaysInMonth;
21
  //set default timezone for store (admin)
22
  $dateObj->setTimezone(Mage::app()->getStore()->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE));
23
 
 
 
 
 
 
24
  //set date with applying timezone of store
25
  $dateObj->set($now, Zend_Date::DATE_SHORT, Mage::app()->getLocale()->getDefaultLocale());
26
 
27
  //convert store date to default date in UTC timezone without DST
28
  $dateObj->setTimezone(Mage_Core_Model_Locale::DEFAULT_TIMEZONE);
29
+ //set begining of day
30
+ $dateObj->setHour(00);
31
+ $dateObj->setMinute(00);
32
+ $dateObj->setSecond(00);
33
  return $dateObj;
34
  }
35
 
97
  private function _getBestsellers($date)
98
  {
99
  /** @var $date Zend_Date */
100
+ $orderstatus = Mage::getStoreConfig('awonpulse/general/ordersstatus',Mage::app()->getDefaultStoreView()->getId());
101
  $orderstatus = explode(',', $orderstatus);
102
  if (count($orderstatus)==0){
103
  $orderstatus = array(Mage_Sales_Model_Order::STATE_COMPLETE);
130
  }*/
131
  //$product = Mage::getModel('catalog/product')->load($orderItem->getProductId());
132
  $items[$orderItem['product_id']] = array(
133
+ 'name'=>Mage::helper('awonpulse')->escapeHtml($orderItem['name']),
134
  'qty'=>0,
135
  'amount' => 0
136
  );
155
  {
156
 
157
  //collect yesterday orders count
158
+ $ordersstatus = Mage::getStoreConfig('awonpulse/general/ordersstatus',Mage::app()->getDefaultStoreView()->getId());
159
  $ordersstatus = explode(',', $ordersstatus);
160
  if (count($ordersstatus)==0){
161
  $ordersstatus = array(Mage_Sales_Model_Order::STATE_COMPLETE);
211
 
212
  private function _getSales($date)
213
  {
214
+ $ordersstatus = Mage::getStoreConfig('awonpulse/general/ordersstatus',Mage::app()->getDefaultStoreView()->getId());
215
  $ordersstatus = explode(',', $ordersstatus);
216
  if (count($ordersstatus)==0){
217
  $ordersstatus = array(Mage_Sales_Model_Order::STATE_COMPLETE);
237
  }
238
  }
239
  }
240
+ /** @var $copyDate Zend_Date */
241
  $daysFrom1st=$copyDate->get(Zend_Date::DAY);
242
+
243
  $orders = Mage::getModel('sales/order')->getCollection();
244
+ $orders->addAttributeToFilter('created_at', array('from' => $copyDate->addDay(-($daysFrom1st-1))->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)))
245
  ->addAttributeToSelect('*')
246
  ->addAttributeToFilter('status', array('in' => $ordersstatus));
247
  $thisMonthSoFar = 0;
250
  $thisMonthSoFar+=$order->getBaseGrandTotal();
251
  }
252
  }
253
+
254
  $numberDaysInMonth = $copyDate->get(Zend_Date::MONTH_DAYS);
255
  $thisMonthAvg = $thisMonthSoFar /($daysFrom1st-1);
256
  $thisMonthForecast = $thisMonthAvg * $numberDaysInMonth;
app/code/local/AW/Onpulse/Model/Aggregator/Components/Statistics.php.orig DELETED
@@ -1,260 +0,0 @@
1
- <?php
2
-
3
- class AW_Onpulse_Model_Aggregator_Components_Statistics extends AW_Onpulse_Model_Aggregator_Component
4
- {
5
- const COUNT_CUSTOMERS = 5;
6
- const MYSQL_DATE_FORMAT = 'Y-d-m';
7
-
8
- private function _getShiftedDate()
9
- {
10
- $timeShift = Mage::app()->getLocale()->date()->get(Zend_Date::TIMEZONE_SECS);
11
- $now = date(self::MYSQL_DATE_FORMAT, time() + $timeShift);
12
- $now = new Zend_Date($now);
13
- return $now;
14
- }
15
-
16
- private function _getCurrentDate()
17
- {
18
- $now = Mage::app()->getLocale()->date();
19
- $dateObj = Mage::app()->getLocale()->date(null, null, Mage::app()->getLocale()->getDefaultLocale(), false);
20
-
21
- //set default timezone for store (admin)
22
- $dateObj->setTimezone(Mage::app()->getStore()->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE));
23
-
24
- //set begining of day
25
- $dateObj->setHour(00);
26
- $dateObj->setMinute(00);
27
- $dateObj->setSecond(00);
28
-
29
- //set date with applying timezone of store
30
- $dateObj->set($now, Zend_Date::DATE_SHORT, Mage::app()->getLocale()->getDefaultLocale());
31
-
32
- //convert store date to default date in UTC timezone without DST
33
- $dateObj->setTimezone(Mage_Core_Model_Locale::DEFAULT_TIMEZONE);
34
-
35
- return $dateObj;
36
- }
37
-
38
- public function pushData($event = null)
39
- {
40
- $aggregator = $event->getEvent()->getAggregator();
41
- $dashboard = array();
42
- $today = $this->_getCurrentDate();
43
-
44
- $dashboard['sales'] = $this->_getSales($today);
45
- $today = $this->_getCurrentDate();
46
- $dashboard['orders'] = $this->_getOrders($today);
47
- $today = $this->_getCurrentDate();
48
- $dashboard['customers'] = $this->_getCustomers($today);
49
- $dashboard['bestsellers'] = $this->_getBestsellers($today);
50
- $aggregator->setData('dashboard',$dashboard);
51
-
52
- }
53
-
54
- private function _getByers($date) {
55
- /** @var $todayRegistered Mage_Customer_Model_Resource_Customer_Collection */
56
- $todayRegistered = Mage::getModel('customer/customer')->getCollection();
57
- $todayRegistered->addAttributeToFilter('created_at', array(
58
- 'from' => $date->toString(Varien_Date::DATETIME_INTERNAL_FORMAT),
59
- 'to' => $date->addDay(1)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)
60
- ));
61
- $todayRegistered->addAttributeToSelect('*');
62
-
63
- $date->addDay(-1);
64
- /* @var $collection Mage_Reports_Model_Mysql4_Order_Collection */
65
- $customerArray = array();
66
- $todayOrders = Mage::getModel('sales/order')->getCollection();
67
- $todayOrders->addAttributeToFilter('created_at', array(
68
- 'from' => $date->toString(Varien_Date::DATETIME_INTERNAL_FORMAT),
69
- 'to' => $date->addDay(1)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)
70
- ));
71
- foreach ($todayOrders as $order) {
72
- if ($order->getCustomerId()){
73
- $customerArray[] = $order->getCustomerId();
74
- }
75
- }
76
- $customerArray = array_unique($customerArray);
77
- $buyers = count($customerArray);
78
- return array(
79
- 'buyers'=>$buyers,
80
- 'registered'=>$todayRegistered,
81
- );
82
- }
83
-
84
- private function _getCustomers($date)
85
- {
86
-
87
- //collect online visitors
88
- $online = Mage::getModel('log/visitor_online')
89
- ->prepare()
90
- ->getCollection()->getSize();
91
- $todayCustomers = null;
92
- $yesterdayCustomers = null;
93
- $todayCustomers = $this->_getByers($date);
94
- $yesterdayCustomers = $this->_getByers($date->addDay(-2));
95
-
96
- return array('online_visistors' => $online, 'today_customers' => $todayCustomers, 'yesterday_customers' => $yesterdayCustomers);
97
- }
98
-
99
- private function _getBestsellers($date)
100
- {
101
- /** @var $date Zend_Date */
102
- $orderstatus = Mage::getStoreConfig('awonpulse/general/ordersstatus');
103
- $orderstatus = explode(',', $orderstatus);
104
- if (count($orderstatus)==0){
105
- $orderstatus = array(Mage_Sales_Model_Order::STATE_COMPLETE);
106
- }
107
- //Collect all orders for last 30 days
108
- /** @var $orders Mage_Sales_Model_Resource_Order_Collection */
109
- $orders = Mage::getResourceModel('sales/order_collection');
110
- $orders->addAttributeToFilter('created_at', array(
111
- 'from' => $date->addDay(-30)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT),
112
- 'to'=>$date->addDay(31)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)
113
- ))->addAttributeToSelect('*')
114
- ->addAttributeToFilter('status', array('in' => $orderstatus));
115
- $items = array();
116
-
117
- /** @var $order Mage_Sales_Model_Order */
118
- foreach($orders as $order) {
119
- $orderItems = $order->getAllVisibleItems();
120
- if(count($orderItems)>0) {
121
- foreach($orderItems as $orderItem) {
122
-
123
- $key = array_key_exists($orderItem->getProductId(),$items);
124
- if($key === false) {
125
- if(count($items) > 15) {
126
- continue;
127
- }
128
- $product = Mage::getModel('catalog/product')->load($orderItem->getProductId());
129
- $items[$product->getId()] = array(
130
- 'name'=>$product->getName(),
131
- 'qty'=>0,
132
- 'amount' => 0
133
- );
134
- }
135
- $items[$orderItem->getProductId()]['qty'] += $orderItem->getQtyOrdered();
136
- $items[$orderItem->getProductId()]['amount'] += Mage::helper('awonpulse')->getPriceFormat($orderItem->getBaseRowTotal()-$orderItem->getBaseDiscountInvoiced());
137
- }
138
- }
139
- }
140
- if(count($items) > 0) {
141
- foreach ($items as $id => $row) {
142
-
143
- $name[$id] = $row['name'];
144
- $qty[$id] = $row['qty'];
145
- }
146
- array_multisort($qty, SORT_DESC, $name, SORT_ASC, $items);
147
- }
148
- return $items;
149
- }
150
-
151
-
152
- private function _getOrders($date)
153
- {
154
-
155
- //collect yesterday orders count
156
- $ordersstatus = Mage::getStoreConfig('awonpulse/general/ordersstatus');
157
- $ordersstatus = explode(',', $ordersstatus);
158
- if (count($ordersstatus)==0){
159
- $ordersstatus = array(Mage_Sales_Model_Order::STATE_COMPLETE);
160
- }
161
- /** @var $yesterdayOrders Mage_Sales_Model_Resource_Order_Collection */
162
- $yesterdayOrders = Mage::getResourceModel('sales/order_collection');
163
-
164
- $yesterdayOrders->addAttributeToFilter('created_at', array(
165
- 'from' => $date->addDay(-1)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT),
166
- 'to'=>$date->addDay(1)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)
167
- ))->addAttributeToSelect('*')
168
- ->addAttributeToFilter('status', array('in' => $ordersstatus));
169
-
170
-
171
- //collect today orders count
172
-
173
- /** @var $yesterdayOrders Mage_Sales_Model_Resource_Order_Collection */
174
- $todayOrders = Mage::getResourceModel('sales/order_collection');
175
- $todayOrders->addAttributeToFilter('created_at', array('from' => $date->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)))
176
- ->addAttributeToSelect('*')
177
- ->addAttributeToFilter('status', array('in' => $ordersstatus));
178
-
179
- //collect max, min, average orders
180
- $order = array();
181
- if ($todayOrders->getSize()) {
182
- $order['max'] = 0;
183
- $order['min'] = 999999999999999;
184
- $order['average'] = 0;
185
- $ordersSum = 0;
186
-
187
- foreach ($todayOrders as $item) {
188
-
189
- if ($item->getBaseGrandTotal() > $order['max']) {
190
- $order['max'] = Mage::helper('awonpulse')->getPriceFormat($item->getBaseGrandTotal());
191
- }
192
-
193
- if ($item->getBaseGrandTotal() < $order['min']) {
194
- $order['min'] = Mage::helper('awonpulse')->getPriceFormat($item->getBaseGrandTotal());
195
- }
196
-
197
- $ordersSum += Mage::helper('awonpulse')->getPriceFormat($item->getBaseGrandTotal());
198
-
199
- }
200
- $order['average'] = Mage::helper('awonpulse')->getPriceFormat($ordersSum / $todayOrders->getSize());
201
- } else {
202
- $order['max'] = 0;
203
- $order['min'] = 0;
204
- $order['average'] = 0;
205
- }
206
-
207
- return array('yesterday_orders' => $yesterdayOrders->getSize(), 'today_orders' => $todayOrders->getSize(), 'orders_totals' => $order);
208
- }
209
-
210
- private function _getSales($date)
211
- {
212
- $ordersstatus = Mage::getStoreConfig('awonpulse/general/ordersstatus');
213
- $ordersstatus = explode(',', $ordersstatus);
214
- if (count($ordersstatus)==0){
215
- $ordersstatus = array(Mage_Sales_Model_Order::STATE_COMPLETE);
216
- }
217
- $shiftedDate = $this->_getShiftedDate();
218
- $shiftedDate->addDay(1);
219
- $date->addDay(1);
220
- $copyDate = clone $date;
221
- $revenue = array();
222
- for($i=0;$i<15;$i++){
223
- /** @var $yesterdayOrders Mage_Sales_Model_Resource_Order_Collection */
224
- $orders = Mage::getModel('sales/order')->getCollection();
225
- $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)))
226
- ->addAttributeToSelect('*')
227
- ->addAttributeToFilter('status', array('in' => $ordersstatus));
228
- $date->addDay(-1);
229
- $shiftedDate->addDay(-1);
230
- $revenue[$i]['revenue']=0;
231
- $revenue[$i]['date']=$shiftedDate->toString(Varien_Date::DATE_INTERNAL_FORMAT);
232
- if($orders->getSize() > 0){
233
- foreach($orders as $order){
234
- $revenue[$i]['revenue']+=$order->getBaseGrandTotal();
235
- }
236
- }
237
- }
238
- $daysFrom1st=$copyDate->get(Zend_Date::DAY);
239
- $orders = Mage::getModel('sales/order')->getCollection();
240
- $orders->addAttributeToFilter('created_at', array('from' => $copyDate->addDay(-$daysFrom1st)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT),'to'=>$copyDate->addDay($daysFrom1st-1)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)))
241
- ->addAttributeToSelect('*')
242
- ->addAttributeToFilter('status', array('in' => $ordersstatus));
243
- $thisMonthSoFar = 0;
244
- if($orders->getSize() > 0){
245
- foreach($orders as $order){
246
- $thisMonthSoFar+=$order->getBaseGrandTotal();
247
- }
248
- }
249
- $thisMonthForecast = 0;
250
- $numberDaysInMonth = $copyDate->get(Zend_Date::MONTH_DAYS);
251
- $thisMonthAvg = $thisMonthSoFar /($daysFrom1st - 1);
252
- $thisMonthForecast = $thisMonthAvg * $numberDaysInMonth;
253
- $thisMonth = array();
254
- $thisMonth['thisMonthSoFar'] = Mage::helper('awonpulse')->getPriceFormat($thisMonthSoFar);
255
- $thisMonth['thisMonthAvg'] = Mage::helper('awonpulse')->getPriceFormat($thisMonthAvg);
256
- $thisMonth['thisMonthForecast'] = Mage::helper('awonpulse')->getPriceFormat($thisMonthForecast);
257
-
258
- return array('revenue'=>$revenue, 'thisMonth'=>$thisMonth);
259
- }
260
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/AW/Onpulse/Model/Credentials.php CHANGED
@@ -7,91 +7,85 @@ class AW_Onpulse_Model_Credentials extends Mage_Core_Model_Abstract
7
  private $qrhash = null;
8
  private $ddl = null;
9
 
10
- private function _readConfig()
 
11
  {
12
- if(!$this->qrhash) {
13
- //Read configuration
14
- if ((Mage::getStoreConfig('awonpulse/general/credurlkey'))&&(Mage::getStoreConfig('awonpulse/general/credhash'))) {
15
- $this->hash = Mage::getStoreConfig('awonpulse/general/credhash');
16
- $this->key = Mage::getStoreConfig('awonpulse/general/credurlkey');
17
- $this->qrhash = md5($this->key.$this->hash);
18
- } else {
19
- return false;
20
- }
21
- }
22
- return true;
23
  }
24
 
25
-
26
- protected function _checkDirectLink()
27
  {
28
- $qrcode = null;
29
- if(!Mage::getStoreConfig('awonpulse/general/ddl')){
30
- $data = Mage::app()->getFrontController();
31
- $qrcode = mb_substr($data->getRequest()->getOriginalPathInfo(),-32);
32
- if(!preg_match('/[a-z0-9]{32}/',$qrcode)) return false;
33
- //Check request
34
- //if QRcode authorization
35
- if($qrcode) {
36
- if($this->_readConfig()){
37
- if($qrcode != $this->qrhash) {
38
- return false;
39
- }
40
- } else {
41
- return false;
42
- }
43
- } else {
44
- return false;
45
- }
46
- return true;
47
  }
48
- return false;
 
 
 
 
 
 
 
 
 
 
49
  }
50
 
51
- protected function _checkUrlKey()
52
  {
53
- $credurlkey = mb_substr(Mage::app()->getFrontController()->getRequest()->getOriginalPathInfo(), 1);
54
- $credhash = Mage::app()->getFrontController()->getRequest()->getParam('key');
55
- if($this->_readConfig()){
56
- if(($this->key!=$credurlkey) || ($this->hash!=$credhash)){
57
- return false;
58
- }
59
- } else {
60
- return false;
61
  }
62
- return true;
63
- }
64
 
65
 
66
- public function checkAuthorization()
67
- {
68
- $authFlag = false;
69
- //Check direct link
70
- $authFlag = $this->_checkDirectLink();
71
- //Check url + ket
72
- if(!$authFlag) {
73
- $authFlag = $this->_checkUrlKey();
74
  }
75
- if(!$authFlag) {
76
- $result = array(
77
- 'result'=>false,
78
- 'error'=>1,
79
- 'message'=>'Incorrect credentials'
 
 
 
 
 
 
80
  );
81
- // echo '['.serialize($result).']';
82
- } else {
83
- if (Mage::getStoreConfig('advanced/modules_disable_output/AW_Onpulse')) {
84
- $result = array(
85
- 'result'=>false,
86
- 'error'=>4,
87
- 'message'=>'Connector disabled'
88
- );
89
- die('['.serialize($result).']');
90
- }
91
- $aggregator = Mage::getSingleton('awonpulse/aggregator')->Aggregate();
92
- $output = Mage::helper('awonpulse')->processOutput($aggregator);
93
- echo serialize($output);
94
- die;
95
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  }
97
  }
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
  }
app/code/local/AW/Onpulse/controllers/IndexController.php CHANGED
@@ -1,13 +1,52 @@
1
  <?php
2
  class AW_Onpulse_IndexController extends Mage_Core_Controller_Front_Action {
3
 
4
- //TODO Remove before publish
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  public function indexAction()
6
  {
7
- $this->loadLayout();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  $aggregator = Mage::getSingleton('awonpulse/aggregator')->Aggregate();
9
  $output = Mage::helper('awonpulse')->processOutput($aggregator);
10
- echo serialize($output);
11
-
12
  }
13
  }
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
  }
app/code/local/AW/Onpulse/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <AW_Onpulse>
5
- <version>1.0.14</version>
6
  </AW_Onpulse>
7
  </modules>
8
  <global>
@@ -42,15 +42,15 @@
42
  </awonpulse>
43
  </helpers>
44
  <events>
45
- <controller_action_predispatch_cms_index_noRoute>
46
  <observers>
47
- <onpulse_authorization>
48
  <type>singleton</type>
49
  <class>awonpulse/credentials</class>
50
- <method>checkAuthorization</method>
51
- </onpulse_authorization>
52
  </observers>
53
- </controller_action_predispatch_cms_index_noRoute>
54
  <onpulse_aggregate_data>
55
  <observers>
56
  <onpulse_aggregator_component_customer>
@@ -112,6 +112,17 @@
112
  </resources>
113
  </acl>
114
  </adminhtml>
 
 
 
 
 
 
 
 
 
 
 
115
  <default>
116
  <awonpulse>
117
  <general>
2
  <config>
3
  <modules>
4
  <AW_Onpulse>
5
+ <version>1.0.15</version>
6
  </AW_Onpulse>
7
  </modules>
8
  <global>
42
  </awonpulse>
43
  </helpers>
44
  <events>
45
+ <admin_system_config_changed_section_awonpulse>
46
  <observers>
47
+ <onpulse_settings>
48
  <type>singleton</type>
49
  <class>awonpulse/credentials</class>
50
+ <method>updateSettings</method>
51
+ </onpulse_settings>
52
  </observers>
53
+ </admin_system_config_changed_section_awonpulse>
54
  <onpulse_aggregate_data>
55
  <observers>
56
  <onpulse_aggregator_component_customer>
112
  </resources>
113
  </acl>
114
  </adminhtml>
115
+ <frontend>
116
+ <routers>
117
+ <awonpulse>
118
+ <use>standard</use>
119
+ <args>
120
+ <module>AW_Onpulse</module>
121
+ <frontName>awonpulse</frontName>
122
+ </args>
123
+ </awonpulse>
124
+ </routers>
125
+ </frontend>
126
  <default>
127
  <awonpulse>
128
  <general>
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-install-1.0.0.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.0-1.0.1.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.1-1.0.2.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.10-1.0.11.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.11-1.0.12.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.12-1.0.13.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.13-1.0.14.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.14-1.0.15.php ADDED
@@ -0,0 +1,2 @@
 
 
1
+ <?php
2
+ Mage::getModel('awonpulse/credentials')->updateSettings(null);
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.14-1.0.16.php ADDED
@@ -0,0 +1,3 @@
 
 
 
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 ADDED
@@ -0,0 +1,2 @@
 
 
1
+ <?php
2
+ Mage::getModel('awonpulse/credentials')->updateSettings(null);
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.2-1.0.3.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.3-1.0.4.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.4-1.0.5.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.5-1.0.6.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.6-1.0.7.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.7-1.0.8.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.8-1.0.9.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php
app/code/local/AW/Onpulse/sql/awonpulse_setup/mysql4-upgrade-1.0.9-1.0.10.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php
app/design/adminhtml/default/default/template/aw_onpulse/settings.phtml CHANGED
@@ -1,14 +1,14 @@
1
  <?php
2
  $directLoginLink = null;
3
- $ddl = Mage::getStoreConfig('awonpulse/general/ddl');
4
  $ordersStatusCollection = Mage::getSingleton('sales/order_config')->getStatuses();
5
- $ordersstatus = Mage::getStoreConfig('awonpulse/general/ordersstatus');
6
  $ordersstatus = explode(',', $ordersstatus);
7
  $size = count($ordersStatusCollection);
8
 
9
- if ((Mage::getStoreConfig('awonpulse/general/credurlkey')) && (Mage::getStoreConfig('awonpulse/general/credhash'))) {
10
- $credurlkey = Mage::getStoreConfig('awonpulse/general/credurlkey');
11
- $credhash = Mage::getStoreConfig('awonpulse/general/credhash');
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);
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);
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>AW_Onpulse</name>
4
- <version>1.0.14</version>
5
  <stability>stable</stability>
6
  <license uri="http://onpulse.info/TOS.pdf">EULA</license>
7
  <channel>community</channel>
@@ -9,12 +9,12 @@
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>+ currency formatting&#xD;
13
  * minor bug fixes</notes>
14
  <authors><author><name>AW_Core_Team</name><user>aheadworks</user><email>no-reply@aheadworks.com</email></author></authors>
15
- <date>2013-09-03</date>
16
- <time>06:22:41</time>
17
- <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="88a0b32ce2c65c1850d072f41bb521e6"/><file name="Data.php.orig" hash="fb2ab95d3268d3d8a689143dff7ffdb8"/></dir><dir name="Model"><dir name="Aggregator"><file name="Component.php" hash="721719d0df46da388b229c10d137864b"/><dir name="Components"><file name="Customer.php" hash="52df2d3be2d6196ee957b2e2c0d92cb2"/><file name="Order.php" hash="a9a23d8f678a68f1b245b97126cc3116"/><file name="Statistics.php" hash="c2ee05f14c1d6b4ff27b910ecb3c0649"/><file name="Statistics.php.orig" hash="919ccaa59b981eb624387937fa4390f1"/></dir></dir><file name="Aggregator.php" hash="fcb4342d583403a99ca7bc245115854f"/><file name="Credentials.php" hash="526d3b476480552ae03f38696bd6fc93"/></dir><dir name="controllers"><file name="IndexController.php" hash="b37753e87cfb6a18045cf9af7a255a84"/></dir><dir name="etc"><file name="config.xml" hash="9e5b3dd18372f8d7a573d86614536956"/><file name="system.xml" hash="11fa0896cc56063c5c572d992622e224"/></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="10c6eea6457de53e501360b25eb50f1d"/></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>
18
  <compatible/>
19
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
20
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>AW_Onpulse</name>
4
+ <version>1.0.15</version>
5
  <stability>stable</stability>
6
  <license uri="http://onpulse.info/TOS.pdf">EULA</license>
7
  <channel>community</channel>
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>* stability improvements&#xD;
13
  * minor bug fixes</notes>
14
  <authors><author><name>AW_Core_Team</name><user>aheadworks</user><email>no-reply@aheadworks.com</email></author></authors>
15
+ <date>2013-11-18</date>
16
+ <time>07:15:06</time>
17
+ <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="721719d0df46da388b229c10d137864b"/><dir name="Components"><file name="Customer.php" hash="52df2d3be2d6196ee957b2e2c0d92cb2"/><file name="Order.php" hash="a9a23d8f678a68f1b245b97126cc3116"/><file name="Statistics.php" hash="d6aa86c82bf6dcb727fd45253fd351ac"/></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="215e05f124664d0d623b0d9319b7f7d9"/><file name="system.xml" hash="11fa0896cc56063c5c572d992622e224"/></dir><dir name="sql"><dir name="awonpulse_setup"><file name="mysql4-install-1.0.0.php" hash="feabe5cc691b088d6ade3e04d6b120fc"/><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="6b71e37948074480ac6598397935a69f"/><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>
18
  <compatible/>
19
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
20
  </package>