Sarbacane_Mailify - Version 1.0.0.8

Version Notes

We improved performance on synchronization.
It should be more efficient and nearly instant on most websites.

Download this release

Release Info

Developer Sarbacane Software
Extension Sarbacane_Mailify
Version 1.0.0.8
Comparing to
See all releases


Code changes from version 1.0.0.7 to 1.0.0.8

Files changed (24) hide show
  1. app/code/community/Sarbacane/Mailify/Block/Adminhtml/Mailify.php +1 -2
  2. app/code/community/Sarbacane/Mailify/Helper/Data.php +188 -121
  3. app/code/community/Sarbacane/Mailify/Model/Observer.php +155 -0
  4. app/code/community/Sarbacane/Mailify/controllers/Adminhtml/MailifyController.php +118 -94
  5. app/code/community/Sarbacane/Mailify/controllers/IndexController.php +519 -366
  6. app/code/community/Sarbacane/Mailify/etc/config.xml +139 -125
  7. app/code/community/Sarbacane/Mailify/sql/mailify_setup/mysql4-install-1.0.0.0.php +0 -52
  8. app/code/community/Sarbacane/Mailify/sql/mailify_setup/mysql4-upgrade-1.0.0.0-1.0.0.1.php +0 -25
  9. app/code/community/Sarbacane/Mailify/sql/mailify_setup/mysql4-upgrade-1.0.0.1-1.0.0.2.php +0 -25
  10. app/code/community/Sarbacane/Mailify/sql/mailify_setup/mysql4-upgrade-1.0.0.2-1.0.0.3.php +0 -25
  11. app/code/community/Sarbacane/Mailify/sql/mailify_setup/mysql4-upgrade-1.0.0.3-1.0.0.4.php +0 -87
  12. app/code/community/Sarbacane/Mailify/sql/mailify_setup/mysql4-upgrade-1.0.0.7-1.0.0.8.php +113 -0
  13. app/design/adminhtml/default/default/layout/mailify.xml +6 -6
  14. app/design/adminhtml/default/default/template/mailify/mailify.phtml +261 -245
  15. app/etc/modules/Sarbacane_Mailify.xml +1 -1
  16. app/locale/de_DE/Sarbacane_Mailify.csv +60 -0
  17. app/locale/en_US/Sarbacane_Mailify.csv +7 -5
  18. app/locale/es_ES/Sarbacane_Mailify.csv +7 -5
  19. package.xml +7 -7
  20. skin/adminhtml/default/default/css/Sarbacane_Mailify/mailify.css +0 -107
  21. skin/adminhtml/default/default/images/{sd.png → mailify.png} +0 -0
  22. skin/adminhtml/default/default/js/Sarbacane_Mailify/mailify.js +0 -95
  23. skin/adminhtml/default/default/mailify.css +105 -0
  24. skin/adminhtml/default/default/mailify.js +74 -0
app/code/community/Sarbacane/Mailify/Block/Adminhtml/Mailify.php CHANGED
@@ -18,8 +18,7 @@
18
* @copyright 2015 Sarbacane Software
19
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
20
*/
21
-
22
class Sarbacane_Mailify_Block_Adminhtml_Mailify extends Mage_Adminhtml_Block_Template
23
{
24
25
- }
18
* @copyright 2015 Sarbacane Software
19
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
20
*/
21
class Sarbacane_Mailify_Block_Adminhtml_Mailify extends Mage_Adminhtml_Block_Template
22
{
23
24
+ }
app/code/community/Sarbacane/Mailify/Helper/Data.php CHANGED
@@ -13,139 +13,206 @@
13
* to license@magentocommerce.com so we can send you a copy immediately.
14
*
15
* @category Sarbacane
16
- * @package Sarbacane_Sarbacanedesktop
17
* @author Sarbacane Software <contact@sarbacane.com>
18
* @copyright 2015 Sarbacane Software
19
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
20
*/
21
-
22
class Sarbacane_Mailify_Helper_Data extends Mage_Core_Helper_Abstract
23
{
24
25
- public function getStoresArray()
26
- {
27
- $stores = Mage::app()->getStores();
28
- $stores_array = array();
29
- foreach ($stores as $store) {
30
- $stores_array[] = array('store_id' => $store->store_id, 'store_name' => $store->name);
31
- }
32
- return $stores_array;
33
- }
34
35
- public function getStoreidFromList($list)
36
- {
37
- if (substr($list, -1) == 'N' || substr($list, -1) == 'C') {
38
- return substr($list, 0, -1);
39
- } else {
40
- return substr($list, 0, -2);
41
- }
42
- }
43
44
- public function getListTypeFromList($list)
45
- {
46
- if (substr($list, -1) == 'N' || substr($list, -1) == 'C') {
47
- return substr($list, -1);
48
- } else {
49
- return substr($list, -2, 1);
50
- }
51
- }
52
53
- public function getListTypeArray()
54
- {
55
- return array('N', 'C');
56
- }
57
58
- public function getListConfiguration($return = 'string')
59
- {
60
- $sd_list = $this->getConfiguration('sd_list');
61
- if ($return == 'string') {
62
- return $sd_list;
63
- } else {
64
- if (strlen($sd_list) != 0) {
65
- return explode(',', $sd_list);
66
- }
67
- return array();
68
- }
69
- }
70
71
- public function resetList($list_id = '')
72
- {
73
- $id_shop = $this->getStoreidFromList($list_id);
74
- $list_type = $this->getListTypeFromList($list_id);
75
-
76
- $resource = Mage::getSingleton('core/resource');
77
- $db_write = $resource->getConnection('core_write');
78
- $sarbacanedesktop = $resource->getTableName('sarbacanedesktop_users');
79
- $rq_sql = '
80
- DELETE FROM `' . $sarbacanedesktop . '`
81
- WHERE `sd_type` = "sd_id"
82
- AND `list_id` = ' . $db_write->quote($id_shop.$list_type);
83
- $db_write->query($rq_sql);
84
- }
85
-
86
- public function getToken()
87
- {
88
- $str = $this->getConfiguration('sd_token');
89
- $str = $str . substr(Mage::helper('core')->encrypt('SecurityTokenForModule'), 0, 11) . $str;
90
- $str = md5($str);
91
- return $str;
92
- }
93
94
- public function getConfiguration($return = 'nb_configured')
95
- {
96
- $resource = Mage::getSingleton('core/resource');
97
- $db_read = $resource->getConnection('core_read');
98
- $sarbacanedesktop_users = $resource->getTableName('sarbacanedesktop_users');
99
- $rq_sql = '
100
- SELECT *
101
- FROM `' . $sarbacanedesktop_users . '`
102
- WHERE `sd_type` = \'sd_token\'
103
- OR `sd_type` = \'sd_list\'';
104
- $rq = $db_read->query($rq_sql);
105
- $sd_token = '';
106
- $sd_list = '';
107
- while ($r = $rq->fetch()) {
108
- if ($r['sd_type'] == 'sd_token') {
109
- $sd_token = $r['sd_value'];
110
- }
111
- else if ($r['sd_type'] == 'sd_list') {
112
- $sd_list = $r['sd_value'];
113
- }
114
- }
115
- if ($return == 'sd_token' || $return == 'sd_list') {
116
- if ($return == 'sd_token') {
117
- return $sd_token;
118
- }
119
- else if ($return == 'sd_list') {
120
- return $sd_list;
121
- }
122
- } else {
123
- if ($return == 'all') {
124
- return array(
125
- 'sd_token' => $sd_token,
126
- 'sd_list' => $sd_list
127
- );
128
- } else {
129
- $nb_configured = 0;
130
- if ($sd_token != '') {
131
- $nb_configured++;
132
- }
133
- if ($sd_list != '') {
134
- $nb_configured++;
135
- }
136
- return $nb_configured;
137
- }
138
- }
139
- }
140
141
-
142
- public function deleteSdid($sd_id){
143
- $resource = Mage::getSingleton('core/resource');
144
- $db_write = $resource->getConnection('core_write');
145
- $sarbacanedesktop_users = $resource->getTableName('sarbacanedesktop_users');
146
-
147
- $rq_sql = 'DELETE FROM '.$sarbacanedesktop_users.' WHERE sd_value ="'.$sd_id.' AND sd_type="sd_id"';
148
- $db_write->query($rq_sql);
149
- }
150
151
- }
13
* to license@magentocommerce.com so we can send you a copy immediately.
14
*
15
* @category Sarbacane
16
+ * @package Sarbacane_Mailify
17
* @author Sarbacane Software <contact@sarbacane.com>
18
* @copyright 2015 Sarbacane Software
19
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
20
*/
21
class Sarbacane_Mailify_Helper_Data extends Mage_Core_Helper_Abstract
22
{
23
24
+ public function getShopsArray()
25
+ {
26
+ $shops = Mage::app()->getStores();
27
+ $shops_array = array();
28
+ foreach ($shops as $shop) {
29
+ $shops_array[] = array(
30
+ 'store_id' => $shop->store_id,
31
+ 'name' => $shop->name
32
+ );
33
+ }
34
+ $shops_array[] = array(
35
+ 'store_id' => '0',
36
+ 'name' => $this->__('Other')
37
+ );
38
+ return $shops_array;
39
+ }
40
+
41
+ public function getIdShopFromList($list)
42
+ {
43
+ if (substr($list, -1) == 'N' || substr($list, -1) == 'C') {
44
+ return substr($list, 0, -1);
45
+ } else {
46
+ return substr($list, 0, -2);
47
+ }
48
+ }
49
+
50
+ public function getListTypeFromList($list)
51
+ {
52
+ if (substr($list, -1) == 'N' || substr($list, -1) == 'C') {
53
+ return substr($list, -1);
54
+ } else {
55
+ return substr($list, -2, 1);
56
+ }
57
+ }
58
+
59
+ public function getListTypeArray()
60
+ {
61
+ return array('N', 'C');
62
+ }
63
+
64
+ public function getListConfiguration($return = 'string')
65
+ {
66
+ $sd_list = $this->getConfiguration('sd_list');
67
+ if ($return == 'string') {
68
+ return $sd_list;
69
+ } else {
70
+ if (strlen($sd_list) != 0) {
71
+ return explode(',', $sd_list);
72
+ }
73
+ return array();
74
+ }
75
+ }
76
77
+ public function getToken()
78
+ {
79
+ $str = $this->getConfiguration('sd_token');
80
+ $str = explode('-', $str);
81
+ $token = '';
82
+ foreach ($str as $key => $s) {
83
+ if ($key == 0) {
84
+ $token = $s . substr(Mage::helper('core')->encrypt('SecurityTokenForModule'), 0, 11) . $s;
85
+ $token = md5($token);
86
+ }else {
87
+ $token .= $s;
88
+ }
89
+ }
90
+ return $token;
91
+ }
92
93
+ public function getConfiguration($return = 'nb_configured')
94
+ {
95
+ $sd_configuration_loaded = false;
96
+ if (isset($this->sd_configuration)) {
97
+ if (isset($this->sd_configuration['sd_token']) && isset($this->sd_configuration['sd_list'])
98
+ && isset($this->sd_configuration['sd_is_user']) && isset($this->sd_configuration['sd_last_update'])
99
+ && isset($this->sd_configuration['sd_nb_failed'])) {
100
+ $sd_configuration_loaded = true;
101
+ }
102
+ }
103
+ if ( ! $sd_configuration_loaded) {
104
+ $resource = Mage::getSingleton('core/resource');
105
+ $db_read = $resource->getConnection('core_read');
106
+ $sd_data = $resource->getTableName('sd_data');
107
+ $sd_configuration = array(
108
+ 'sd_token' => '',
109
+ 'sd_list' => '',
110
+ 'sd_is_user' => '',
111
+ 'sd_last_update' => '',
112
+ 'sd_nb_failed' => 0
113
+ );
114
+ $rq_sql = '
115
+ SELECT *
116
+ FROM `' . $sd_data . '`
117
+ WHERE `sd_type` IN (\'sd_token\', \'sd_list\', \'sd_is_user\', \'sd_last_update\', \'sd_nb_failed\')';
118
+ $rq = $db_read->query($rq_sql);
119
+ while ($r = $rq->fetch()) {
120
+ $sd_configuration[$r['sd_type']] = $r['sd_value'];
121
+ }
122
+ $sd_configuration['sd_nb_failed'] = (int)$sd_configuration['sd_nb_failed'];
123
+ $this->sd_configuration = $sd_configuration;
124
+ }
125
+ if ($return == 'sd_token' || $return == 'sd_list' || $return == 'sd_is_user' || $return == 'sd_last_update' || $return == 'sd_nb_failed') {
126
+ return $this->sd_configuration[$return];
127
+ } else {
128
+ if ($return == 'all') {
129
+ return $this->sd_configuration;
130
+ } else {
131
+ $nb_configured = 0;
132
+ if ($this->sd_configuration['sd_token'] != '') {
133
+ $nb_configured = 3;
134
+ } else {
135
+ if ($this->sd_configuration['sd_list'] != '') {
136
+ $nb_configured++;
137
+ }
138
+ if ($this->sd_configuration['sd_is_user'] != '') {
139
+ $nb_configured++;
140
+ }
141
+ }
142
+ return $nb_configured;
143
+ }
144
+ }
145
+ }
146
147
+ public function updateConfiguration($name, $value) {
148
+ $resource = Mage::getSingleton('core/resource');
149
+ $db_write = $resource->getConnection('core_write');
150
+ $sd_data = $resource->getTableName('sd_data');
151
+ $rq_sql = '
152
+ UPDATE `' . $sd_data . '`
153
+ SET `sd_value` = ' . $db_write->quote($value) . '
154
+ WHERE `sd_type` = ' . $db_write->quote($name);
155
+ $db_write->query($rq_sql);
156
+ unset($this->sd_configuration);
157
+ }
158
159
+ public function deleteSdid($sd_id)
160
+ {
161
+ $resource = Mage::getSingleton('core/resource');
162
+ $db_write = $resource->getConnection('core_write');
163
+ $sd_users = $resource->getTableName('sd_users');
164
+ $rq_sql = '
165
+ DELETE
166
+ FROM `' . $sd_users . '`
167
+ WHERE `sd_id` = ' . $db_write->quote($sd_id);
168
+ $db_write->query($rq_sql);
169
+ }
170
171
+ public function checkNeedUserInsertSdUpdates($store_id, $list_type)
172
+ {
173
+ $sd_list_array = $this->getListConfiguration('array');
174
+ $sd_list_string = implode(',', $sd_list_array);
175
+ if (strpos($sd_list_string, $list_type) === false) {
176
+ return false;
177
+ }
178
+ if ($list_type == 'N') {
179
+ $in_array = in_array($store_id . 'N0', $sd_list_array);
180
+ } else {
181
+ $in_array = in_array($store_id . 'C0', $sd_list_array) || in_array($store_id . 'C1', $sd_list_array);
182
+ }
183
+ if ($in_array) {
184
+ $sd_synchronized_lists_array = $this->getSynchronizedListsArray();
185
+ if (in_array($store_id . $list_type, $sd_synchronized_lists_array)) {
186
+ return true;
187
+ }
188
+ }
189
+ return false;
190
+ }
191
192
+ public function getSynchronizedListsArray() {
193
+ if ( ! isset($this->sd_synchronized_lists_array)) {
194
+ $resource = Mage::getSingleton('core/resource');
195
+ $db_read = $resource->getConnection('core_read');
196
+ $sd_users = $resource->getTableName('sd_users');
197
+ $sd_synchronized_lists_array = array();
198
+ $rq_sql = '
199
+ SELECT `list_id`
200
+ FROM `' . $sd_users . '`
201
+ GROUP BY `list_id`';
202
+ $rq = $db_read->query($rq_sql);
203
+ while ($r = $rq->fetch()) {
204
+ $sd_synchronized_lists_array[] = $r['list_id'];
205
+ }
206
+ $this->sd_synchronized_lists_array = $sd_synchronized_lists_array;
207
+ }
208
+ return $this->sd_synchronized_lists_array;
209
+ }
210
211
+ public function checkFailed() {
212
+ if ($this->getConfiguration('sd_nb_failed') < 1000000) {
213
+ return false;
214
+ }
215
+ return true;
216
+ }
217
218
+ }
app/code/community/Sarbacane/Mailify/Model/Observer.php ADDED
@@ -0,0 +1,155 @@
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Sarbacane
16
+ * @package Sarbacane_Mailify
17
+ * @author Sarbacane Software <contact@sarbacane.com>
18
+ * @copyright 2015 Sarbacane Software
19
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
20
+ */
21
+ class Sarbacane_Mailify_Model_Observer
22
+ {
23
+
24
+ public function customerSave(Varien_Event_Observer $observer)
25
+ {
26
+ try {
27
+ if (Mage::app()->getRequest()->getActionName() != 'saveOrder') {
28
+ $old_data = $observer->getCustomer()->getOrigData();
29
+ $new_data = $observer->getCustomer()->getData();
30
+ if (isset($old_data['email']) && isset($new_data['email']) && isset($old_data['store_id']) && isset($new_data['store_id']) && isset($old_data['website_id']) && isset($new_data['website_id'])) {
31
+ $old_website_id = $old_data['website_id'];
32
+ $new_website_id = $new_data['website_id'];
33
+ if ($old_website_id != 0 || $new_website_id != 0) {
34
+ $old_email = $old_data['email'];
35
+ $new_email = $new_data['email'];
36
+ $old_store_id = $old_data['store_id'];
37
+ $new_store_id = $new_data['store_id'];
38
+ if ($old_email != $new_email || $old_store_id != $new_store_id) {
39
+ $now = gmdate('Y-m-d H:i:s');
40
+ $this->userInsertSdUpdatesIfNecessary($old_email, $old_store_id, 'C', 'U', $now);
41
+ }
42
+ }
43
+ }
44
+ }
45
+ }
46
+ catch(Exception $e) {}
47
+ }
48
+
49
+ public function customerDelete(Varien_Event_Observer $observer)
50
+ {
51
+ try {
52
+ $data = $observer->getCustomer()->getData();
53
+ if (isset($data['email']) && isset($data['entity_id']) && isset($data['store_id']) && isset($data['website_id'])) {
54
+ $website_id = $data['website_id'];
55
+ if ($website_id != 0) {
56
+ $email = $data['email'];
57
+ $store_id = $data['store_id'];
58
+ $now = gmdate('Y-m-d H:i:s');
59
+ $this->userInsertSdUpdatesIfNecessary($email, $store_id, 'C', 'U', $now);
60
+ }
61
+ }
62
+ }
63
+ catch(Exception $e) {}
64
+ }
65
+
66
+ public function newsletterSubscriberSave(Varien_Event_Observer $observer)
67
+ {
68
+ try {
69
+ $action_name = Mage::app()->getRequest()->getActionName();
70
+ if ($action_name != 'saveOrder') {
71
+ $data = $observer->getSubscriber()->getData();
72
+ if (isset($data['subscriber_email']) && isset($data['store_id']) && isset($data['subscriber_status'])) {
73
+ $new_email = $data['subscriber_email'];
74
+ $new_store_id = $data['store_id'];
75
+ $new_status = $data['subscriber_status'];
76
+ if ($new_status == '1' || $new_status == '3') {
77
+ $now = gmdate('Y-m-d H:i:s');
78
+ $mass_unsubscribe_subscribers = false;
79
+ if ($action_name == 'massUnsubscribe') {
80
+ if (Mage::app()->getRequest()->getParam('subscriber')) {
81
+ $mass_unsubscribe_subscribers = true;
82
+ }
83
+ }
84
+ if ($mass_unsubscribe_subscribers) {
85
+ $this->userInsertSdUpdatesIfNecessary($new_email, $new_store_id, 'N', 'U', $now);
86
+ } else {
87
+ if (isset($data['subscriber_id'])) {
88
+ $resource = Mage::getSingleton('core/resource');
89
+ $db_read = $resource->getConnection('core_read');
90
+ $newsletter_subscriber = $resource->getTableName('newsletter_subscriber');
91
+ $rq_sql = '
92
+ SELECT `subscriber_email`, `store_id`, `subscriber_status`
93
+ FROM `' . $newsletter_subscriber . '`
94
+ WHERE `subscriber_id` = ' . (int)$data['subscriber_id'];
95
+ $rq = $db_read->query($rq_sql);
96
+ while ($r = $rq->fetch()) {
97
+ $old_email = $r['subscriber_email'];
98
+ $old_store_id = $r['store_id'];
99
+ $old_status = $r['subscriber_status'];
100
+ if ($old_email != $new_email || $old_store_id != $new_store_id) {
101
+ if ($old_status == '1') {
102
+ $this->userInsertSdUpdatesIfNecessary($old_email, $old_store_id, 'N', 'U', $now);
103
+ }
104
+ } else {
105
+ if ($old_status == '1' && $new_status == '3') {
106
+ $this->userInsertSdUpdatesIfNecessary($new_email, $new_store_id, 'N', 'U', $now);
107
+ }
108
+ }
109
+ }
110
+ }
111
+ if ($new_status == '1') {
112
+ $this->userInsertSdUpdatesIfNecessary($new_email, $new_store_id, 'N', 'S', $now);
113
+ }
114
+ }
115
+ }
116
+ }
117
+ }
118
+ }
119
+ catch(Exception $e) {}
120
+ }
121
+
122
+ public function newsletterSubscriberDelete(Varien_Event_Observer $observer)
123
+ {
124
+ try {
125
+ $data = $observer->getSubscriber()->getData();
126
+ if (isset($data['subscriber_email']) && isset($data['store_id']) && isset($data['subscriber_status'])) {
127
+ $subscriber_email = $data['subscriber_email'];
128
+ $store_id = $data['store_id'];
129
+ $subscriber_status = $data['subscriber_status'];
130
+ if ($subscriber_status == '1') {
131
+ $now = gmdate('Y-m-d H:i:s');
132
+ $this->userInsertSdUpdatesIfNecessary($subscriber_email, $store_id, 'N', 'U', $now);
133
+ }
134
+ }
135
+ }
136
+ catch(Exception $e) {}
137
+ }
138
+
139
+ private function userInsertSdUpdatesIfNecessary($email, $store_id, $list_type, $action, $now)
140
+ {
141
+ if (Mage::helper('mailify')->checkNeedUserInsertSdUpdates($store_id, $list_type)) {
142
+ $resource = Mage::getSingleton('core/resource');
143
+ $db_write = $resource->getConnection('core_write');
144
+ $sd_updates = $resource->getTableName('sd_updates');
145
+ $rq_sql = '
146
+ INSERT INTO `' . $sd_updates . '` VALUES
147
+ (' . $db_write->quote($email) . ', ' . (int)$store_id . ', ' . $db_write->quote($list_type) . ', ' . $db_write->quote($action) . ', ' . $db_write->quote($now) . ')
148
+ ON DUPLICATE KEY UPDATE
149
+ `action` = VALUES(`action`),
150
+ `update_date` = VALUES(`update_date`)';
151
+ $db_write->query($rq_sql);
152
+ }
153
+ }
154
+
155
+ }
app/code/community/Sarbacane/Mailify/controllers/Adminhtml/MailifyController.php CHANGED
@@ -18,103 +18,127 @@
18
* @copyright 2015 Sarbacane Software
19
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
20
*/
21
-
22
class Sarbacane_Mailify_Adminhtml_MailifyController extends Mage_Adminhtml_Controller_Action
23
{
24
25
- public function indexAction(){
26
- if (Mage::app()->getRequest()->getParam('submit_configuration') || Mage::app()->getRequest()->getParam('submit_parameter_key')) {
27
- if (Mage::app()->getRequest()->getParam('submit_configuration')) {
28
- $this->saveListConfiguration();
29
- if (Mage::helper('mailify')->getConfiguration('sd_token') == '') {
30
- $this->saveTokenParameterConfiguration();
31
- }
32
- $this->_getSession()->addSuccess($this->__('Your settings have been saved'));
33
- }
34
- else if (Mage::app()->getRequest()->getParam('submit_parameter_key')) {
35
- $this->saveTokenParameterConfiguration();
36
- $this->_getSession()->addSuccess($this->__('Your settings have been saved'));
37
- }
38
- }
39
-
40
- $this->loadLayout();
41
- $block = $this->getLayout()->getBlock('mailify');
42
- $block->setSdFormKey($this->getSdFormKey());
43
- $block->setKeyForSynchronisation($this->getKeyForSynchronisation());
44
- $block->setListConfiguration(Mage::helper('mailify')->getListConfiguration('array'));
45
- $block->setGeneralConfiguration(Mage::helper('mailify')->getConfiguration('nb_configured'));
46
- $block->setStoresArray(Mage::helper('mailify')->getStoresArray());
47
- if(Mage::app()->getRequest()->getParam("sd_is_user")){
48
- Mage::getSingleton("core/session")->setData("sd_is_user",Mage::app()->getRequest()->getParam("sd_is_user"));
49
- }
50
- $this->_title($this->__('Mailify'));
51
- $this->_setActiveMenu('newsletter');
52
- $this->renderLayout();
53
- }
54
-
55
- private function saveListConfiguration()
56
- {
57
- $resource = Mage::getSingleton('core/resource');
58
- $db_write = $resource->getConnection('core_write');
59
- $sarbacanedesktop_users = $resource->getTableName('sarbacanedesktop_users');
60
- $shops = '';
61
- if (Mage::app()->getRequest()->getParam('store_id')) {
62
- $stores_id = Mage::app()->getRequest()->getParam('store_id');
63
- if (is_array($stores_id)) {
64
- foreach ($stores_id as $store_id) {
65
- $shops .= $store_id . ',';
66
- }
67
- $shops = substr($shops, 0, strlen($shops)-1);
68
- }
69
- }
70
- $old_sd_list_array = Mage::helper('mailify')->getListConfiguration('array');
71
- $rq_sql = '
72
- UPDATE `' . $sarbacanedesktop_users . '`
73
- SET `sd_value` = ' . $db_write->quote($shops) . '
74
- WHERE `sd_type` = \'sd_list\'';
75
- $db_write->query($rq_sql);
76
- $sd_list_array = Mage::helper('mailify')->getListConfiguration('array');
77
- foreach ($sd_list_array as $sd_list)
78
- {
79
- if (!in_array($sd_list, $old_sd_list_array))
80
- {
81
- Mage::helper('mailify')->resetList($sd_list);
82
- }
83
- }
84
- }
85
- private function createTokenParameterConfiguration(){
86
- $resource = Mage::getSingleton('core/resource');
87
- $db_write = $resource->getConnection('core_write');
88
- $sarbacanedesktop_users = $resource->getTableName('sarbacanedesktop_users');
89
- $rq_sql = 'TRUNCATE `' . $sarbacanedesktop_users . '`';
90
- $db_write->query($rq_sql);
91
- $token_parameter = rand(100000, 999999) . Mage::getModel('core/date')->timestamp(time());
92
- $rq_sql = 'INSERT INTO `' . $sarbacanedesktop_users . '` (`sd_value`,`sd_type`) VALUES (' . $db_write->quote($token_parameter) . ',\'sd_token\')';
93
- $db_write->query($rq_sql);
94
- return $token_parameter;
95
- }
96
- private function saveTokenParameterConfiguration()
97
- {
98
- $resource = Mage::getSingleton('core/resource');
99
- $db_write = $resource->getConnection('core_write');
100
- $sarbacanedesktop_users = $resource->getTableName('sarbacanedesktop_users');
101
- $token_parameter = rand(100000, 999999) . Mage::getModel('core/date')->timestamp(time());
102
- $rq_sql = '
103
- UPDATE `' . $sarbacanedesktop_users . '`
104
- SET `sd_value` = ' . $db_write->quote($token_parameter) . '
105
- WHERE `sd_type` = \'sd_token\'';
106
- $db_write->query($rq_sql);
107
- return $token_parameter;
108
- }
109
110
- private function getKeyForSynchronisation()
111
- {
112
- return str_rot13('sarbacanedesktop?stk=' . Mage::helper('mailify')->getToken());
113
- }
114
115
- private function getSdFormKey()
116
- {
117
- return substr(Mage::helper('core')->encrypt('SarbacaneDesktopForm'), 0, 15);
118
- }
119
120
- }
18
* @copyright 2015 Sarbacane Software
19
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
20
*/
21
class Sarbacane_Mailify_Adminhtml_MailifyController extends Mage_Adminhtml_Controller_Action
22
{
23
24
+ protected function _isAllowed()
25
+ {
26
+ return Mage::getSingleton('admin/session')->isAllowed('newsletter/mailify');
27
+ }
28
+
29
+ public function indexAction()
30
+ {
31
+ $general_configuration = Mage::helper('mailify')->getConfiguration('nb_configured');
32
+ $displayed_step = 1;
33
+ if ($general_configuration == 1) {
34
+ $displayed_step = 2;
35
+ } else if ($general_configuration == 2 || $general_configuration == 3) {
36
+ $displayed_step = 3;
37
+ }
38
+ if (Mage::app()->getRequest()->getParam('submit_is_user')) {
39
+ $this->saveSdIsUser();
40
+ $general_configuration = Mage::helper('mailify')->getConfiguration('nb_configured');
41
+ $displayed_step = 2;
42
+ } else if (Mage::app()->getRequest()->getParam('submit_configuration')) {
43
+ $this->saveListConfiguration();
44
+ if (Mage::helper('mailify')->getConfiguration('sd_token') == '') {
45
+ $this->saveTokenParameterConfiguration();
46
+ }
47
+ $general_configuration = Mage::helper('mailify')->getConfiguration('nb_configured');
48
+ $displayed_step = 3;
49
+ } else if (Mage::app()->getRequest()->getParam('submit_parameter_key')) {
50
+ $this->saveTokenParameterConfiguration();
51
+ }
52
+ $this->loadLayout();
53
+ $block = $this->getLayout()->getBlock('mailify');
54
+ $block->setSdFormKey($this->getSdFormKey());
55
+ $block->setKeyForSynchronisation($this->getKeyForSynchronisation());
56
+ $block->setCheckFailed(Mage::helper('mailify')->checkFailed());
57
+ $block->setListConfiguration(Mage::helper('mailify')->getListConfiguration('array'));
58
+ $block->setGeneralConfiguration($general_configuration);
59
+ $block->setSdIsUser(Mage::helper('mailify')->getConfiguration('sd_is_user'));
60
+ $block->setDisplayedStep($displayed_step);
61
+ $block->setShopsArray(Mage::helper('mailify')->getShopsArray());
62
+ $this->_title($this->__('Mailify'));
63
+ $this->_setActiveMenu('newsletter');
64
+ $this->renderLayout();
65
+ }
66
+
67
+ private function saveSdIsUser()
68
+ {
69
+ if (Mage::app()->getRequest()->getParam('sd_is_user')) {
70
+ $sd_is_user = Mage::app()->getRequest()->getParam('sd_is_user');
71
+ Mage::helper('mailify')->updateConfiguration('sd_is_user', $sd_is_user);
72
+ }
73
+ }
74
+
75
+ private function saveTokenParameterConfiguration()
76
+ {
77
+ $resource = Mage::getSingleton('core/resource');
78
+ $db_write = $resource->getConnection('core_write');
79
+ $sd_updates = $resource->getTableName('sd_updates');
80
+ $sd_users = $resource->getTableName('sd_users');
81
+ Mage::helper('mailify')->updateConfiguration('sd_nb_failed', '');
82
+ $rq_sql = 'TRUNCATE `' . $sd_updates . '`';
83
+ $db_write->query($rq_sql);
84
+ $rq_sql = 'TRUNCATE `' . $sd_users . '`';
85
+ $db_write->query($rq_sql);
86
+ $token_parameter = rand(100000, 999999) . time() . '-';
87
+ $characters = '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
88
+ $nb_characters = strlen($characters);
89
+ for ($i = 0; $i < 30; $i++) {
90
+ $token_parameter .= substr($characters, mt_rand(0, $nb_characters - 1), 1);
91
+ }
92
+ Mage::helper('mailify')->updateConfiguration('sd_token', $token_parameter);
93
+ }
94
+
95
+ private function getKeyForSynchronisation()
96
+ {
97
+ return str_rot13('sarbacanedesktop?stk=' . Mage::helper('mailify')->getToken());
98
+ }
99
+
100
+ private function saveListConfiguration()
101
+ {
102
+ $shops = '';
103
+ if (Mage::app()->getRequest()->getParam('store_id')) {
104
+ $stores_id = Mage::app()->getRequest()->getParam('store_id');
105
+ if (is_array($stores_id)) {
106
+ $sd_list_array = Mage::helper('mailify')->getListConfiguration('array');
107
+ foreach ($sd_list_array as $sd_list) {
108
+ if ( ! in_array($sd_list, $stores_id)) {
109
+ $store_id = Mage::helper('mailify')->getIdShopFromList($sd_list);
110
+ $list_type = Mage::helper('mailify')->getListTypeFromList($sd_list);
111
+ $this->deleteListData($list_type, $store_id);
112
+ }
113
+ }
114
+ $shops = implode(',', $stores_id);
115
+ }
116
+ }
117
+ Mage::helper('mailify')->updateConfiguration('sd_list', $shops);
118
+ }
119
120
+ private function deleteListData($list_type, $store_id)
121
+ {
122
+ $resource = Mage::getSingleton('core/resource');
123
+ $db_write = $resource->getConnection('core_write');
124
+ $sd_updates = $resource->getTableName('sd_updates');
125
+ $sd_users = $resource->getTableName('sd_users');
126
+ $rq_sql = '
127
+ DELETE
128
+ FROM `' . $sd_updates . '`
129
+ WHERE `store_id` = ' . (int)$store_id . '
130
+ AND `list_type` = ' . $db_write->quote($list_type);
131
+ $db_write->query($rq_sql);
132
+ $rq_sql = '
133
+ DELETE
134
+ FROM `' . $sd_users . '`
135
+ WHERE `list_id` = ' . $db_write->quote($store_id . $list_type);
136
+ $db_write->query($rq_sql);
137
+ }
138
139
+ private function getSdFormKey()
140
+ {
141
+ return substr(Mage::helper('core')->encrypt('SarbacaneDesktopForm'), 0, 15);
142
+ }
143
144
+ }
app/code/community/Sarbacane/Mailify/controllers/IndexController.php CHANGED
@@ -1,366 +1,519 @@
1
- <?php
2
- /**
3
- * Magento
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Academic Free License (AFL 3.0)
8
- * that is bundled with this package in the file LICENSE.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/afl-3.0.php
11
- * If you did not receive a copy of the license and are unable to
12
- * obtain it through the world-wide-web, please send an email
13
- * to license@magentocommerce.com so we can send you a copy immediately.
14
- *
15
- * @category Sarbacane
16
- * @package Sarbacane_Mailify
17
- * @author Sarbacane Software <contact@sarbacane.com>
18
- * @copyright 2015 Sarbacane Software
19
- * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
20
- */
21
- class Sarbacane_Mailify_IndexController extends Mage_Core_Controller_Front_Action {
22
- private function saveSdid($sdid, $list) {
23
- $resource = Mage::getSingleton ( 'core/resource' );
24
- $db_write = $resource->getConnection ( 'core_write' );
25
- $sarbacanedesktop_users = $resource->getTableName ( 'sarbacanedesktop_users' );
26
- $rq_sql = 'DELETE FROM `' . $sarbacanedesktop_users . '` WHERE sd_type=\'sd_id\' AND sd_value=\'' . $sdid . '\' AND list_id=\'' . $list . '\'';
27
- $rq = $db_write->query ( $rq_sql );
28
- $rq_sql = '
29
- INSERT INTO `' . $sarbacanedesktop_users . '` (`sd_type`, `sd_value`, `list_id`, `last_call_date` ) VALUES
30
- (\'sd_id\', ' . $db_write->quote ( $sdid ) . ', \'' . $list . '\', \'' . date ( 'Y-m-d H:i:s' ) . '\')';
31
- $rq = $db_write->query ( $rq_sql );
32
- return;
33
- }
34
- public function indexAction() {
35
- if (Mage::app ()->getRequest ()->getParam ( 'stk' ) && Mage::app ()->getRequest ()->getParam ( 'sdid' )) {
36
- $sdid = Mage::app ()->getRequest ()->getParam ( 'sdid' );
37
- if (Mage::app ()->getRequest ()->getParam ( 'stk' ) == Mage::helper ( 'mailify' )->getToken () && $sdid != '') {
38
- $identifier = Mage::helper ( 'mailify' )->getConfiguration ( 'identifier' );
39
- $sd_id = "";
40
- $configuration = Mage::helper ( 'mailify' )->getConfiguration ( 'all' );
41
- if ($configuration ['sd_token'] != '' && $configuration ['sd_list'] != '') {
42
- $sd_list_array = Mage::helper ( 'mailify' )->getListConfiguration ( 'array' );
43
- if ($sd_list_array != '') {
44
- if (Mage::app ()->getRequest ()->getParam ( 'list' )) {
45
- $list = Mage::app ()->getRequest ()->getParam ( 'list' );
46
- $store_id = Mage::helper ( 'mailify' )->getStoreidFromList ( $list );
47
- $list_type = Mage::helper ( 'mailify' )->getListTypeFromList ( $list );
48
- $list_type_array = Mage::helper ( 'mailify' )->getListTypeArray ();
49
- if (in_array ( $list_type, $list_type_array )) {
50
- $id_and_list = $store_id . $list_type;
51
- if (($list_type == 'N' && in_array ( $id_and_list . '0', $sd_list_array )) || ($list_type == 'C' && (in_array ( $id_and_list . '0', $sd_list_array ) || in_array ( $id_and_list . '1', $sd_list_array )))) {
52
- $this->processNewUnsubcribersAndSubscribers ( $list_type, $store_id, $sdid );
53
- $sd_id = $this->saveSdid ( $sdid, $list );
54
- }else{
55
- header ( 'HTTP/1.1 404 Not found' );
56
- header ( "Content-type: application/json ; charset=utf-8" );
57
- die ( 'FAILED_ID' );
58
- }
59
- } else {
60
- header ( 'HTTP/1.1 404 Not found' );
61
- header ( "Content-type: application/json ; charset=utf-8" );
62
- die ( 'FAILED_ID' );
63
- }
64
- } else {
65
- if ('reset' == Mage::app ()->getRequest ()->getParam ( 'action' )) {
66
- Mage::helper ( 'mailify' )->deleteSdid ( $sd_id );
67
- } else {
68
- $this->getFormattedContentShops ( $sdid );
69
- }
70
- }
71
- }
72
- }
73
- } else {
74
- header ( "HTTP/1.1 403 Unauthorized" );
75
- header ( "Content-type: application/json; charset=utf-8" );
76
- die ( 'FAILED_SDTOKEN' );
77
- }
78
- } else {
79
- echo "Param&egrave;tre[s] manquant[s]";
80
- }
81
- }
82
- private function processNewUnsubcribersAndSubscribers($list_type, $store_id, $sd_id) {
83
- $resource = Mage::getSingleton ( 'core/resource' );
84
- $db_read = $resource->getConnection ( 'core_read' );
85
- $sarbacanedesktop_users = $resource->getTableName ( 'sarbacanedesktop_users' );
86
- $rq_sql = 'SELECT last_call_date FROM ' . $sarbacanedesktop_users . ' WHERE sd_type=\'sd_id\' AND sd_value=\'' . $sd_id . '\' AND list_id=\'' . $store_id . $list_type . '\'';
87
- $last_call_date = $db_read->fetchOne ( $rq_sql );
88
- $line = 'email;lastname;firstname';
89
- if ($list_type == 'C') {
90
- if ($this->checkIfListWithCustomerData ( $list_type, $store_id )) {
91
- $line .= ';date_first_order;date_last_order;amount_min_order;amount_max_order;amount_avg_order;nb_orders;amount_all_orders;most_profitable_category';
92
- }
93
- }
94
- $line .= ';action'."\r\n";
95
- echo $line;
96
- $this->processNewUnsubscribers ( $list_type, $store_id, $sd_id, 'display', $last_call_date );
97
- $this->processNewSubscribers ( $list_type, $store_id, $sd_id, 'display', $last_call_date );
98
- }
99
- private function getListTypeArray() {
100
- return array (
101
- 'N',
102
- 'C'
103
- );
104
- }
105
- private function checkIfListWithCustomerData($list_type, $store_id) {
106
- $sd_list_array = Mage::helper ( 'mailify' )->getListConfiguration ( 'array' );
107
- if (in_array ( $store_id . $list_type . '1', $sd_list_array )) {
108
- return true;
109
- }
110
- return false;
111
- }
112
- private function getFormattedContentShops($sd_id) {
113
- $stores = Mage::helper ( 'mailify' )->getStoresArray ();
114
- echo 'list_id;name;reset;is_updated;type;version' . "\n";
115
- $sd_list_array = Mage::helper ( 'mailify' )->getListConfiguration ( 'array' );
116
- $list_array = array ();
117
- foreach ( $sd_list_array as $list ) {
118
- $store_id = Mage::helper ( 'mailify' )->getStoreidFromList ( $list );
119
- $list_type = Mage::helper ( 'mailify' )->getListTypeFromList ( $list );
120
- array_push ( $list_array, array (
121
- 'store_id' => $store_id,
122
- 'list_type' => $list_type,
123
- 'list_id' => $list
124
- ) );
125
- }
126
- foreach ( $stores as $store ) {
127
- foreach ( $list_array as $list ) {
128
- if ($store ['store_id'] == $list ['store_id']) {
129
- $store_list = "" . $store ['store_id'] . $list ['list_type'] . ';' . $this->dQuote ( $store ['store_name'] ) . ';'; // TEST
130
- $store_list .= $this->listIsResetted ( $store ['store_id'] . $list ['list_type'], $sd_id ) . ';';
131
- $store_list .= $this->listIsUpdated ( $store ['store_id'], $list ['list_type'], $sd_id ) . ';';
132
- $store_list .= 'Magento;1.0.0.7' . "\r\n";
133
- echo $store_list;
134
- }
135
- }
136
- }
137
- }
138
- private function listIsResetted($list_id, $sd_id) {
139
- $resource = Mage::getSingleton ( 'core/resource' );
140
- $db_read = $resource->getConnection ( 'core_read' );
141
- $sarbacanedesktop_users = $resource->getTableName ( 'sarbacanedesktop_users' );
142
- $rq_sql = '
143
- SELECT count(*) AS `nb_in_table`
144
- FROM ' . $sarbacanedesktop_users . '
145
- WHERE `sd_type` = "sd_id"
146
- AND `sd_value` = ' . $db_read->quote ( $sd_id ) . ' AND list_id="' . $list_id . '"';
147
- $nb_in_table = $db_read->fetchOne ( $rq_sql );
148
- if ($nb_in_table == 0)
149
- return 'Y';
150
- return 'N';
151
- }
152
- private function listIsUpdated($store_id, $list_type, $sd_id) {
153
- $resource = Mage::getSingleton ( 'core/resource' );
154
- $db_read = $resource->getConnection ( 'core_read' );
155
- $sarbacanedesktop_users = $resource->getTableName ( 'sarbacanedesktop_users' );
156
- $rq_sql = 'SELECT last_call_date FROM ' . $sarbacanedesktop_users . ' WHERE sd_type=\'sd_id\' AND sd_value=\'' . $sd_id . '\' AND list_id=\'' . $store_id . $list_type . '\'';
157
- $last_call_date = $db_read->fetchOne ( $rq_sql );
158
- $is_updated_list = 'N';
159
- if ($this->processNewUnsubscribers ( $list_type, $store_id, $sd_id, 'is_updated', $last_call_date ) > 0) {
160
- $is_updated_list = 'Y';
161
- }
162
- if ($this->processNewSubscribers ( $list_type, $store_id, $sd_id, 'is_updated', $last_call_date ) > 0) {
163
- $is_updated_list = 'Y';
164
- }
165
- return $is_updated_list;
166
- }
167
- private function dQuote($value) {
168
- $value = str_replace ( '"', '""', $value );
169
- if (strpos ( $value, ' ' ) || strpos ( $value, ';' )) {
170
- $value = '"' . $value . '"';
171
- }
172
- return $value;
173
- }
174
- private function processNewSubscribers($list_type, $store_id, $sd_id, $type_action = 'display', $last_call_date) { $resource = Mage::getSingleton ( 'core/resource' );
175
- $db_read = $resource->getConnection ( 'core_read' );
176
- $db_write = $resource->getConnection ( 'core_write' );
177
- $sd_updates = $resource->getTableName ( 'sd_updates' );
178
- $newsletter_subscriber = $resource->getTableName ( 'newsletter_subscriber' );
179
- $sales_flat_order = $resource->getTableName ( 'sales_flat_order' );
180
- $sales_flat_order_item = $resource->getTableName ( 'sales_flat_order_item' );
181
- $catalog_category_product = $resource->getTableName ( 'catalog_category_product' );
182
- $catalog_category_entity_varchar = $resource->getTableName ( 'catalog_category_entity_varchar' );
183
- $customer_entity = $resource->getTableName ( 'customer_entity' );
184
- $customer_entity_varchar = $resource->getTableName ( 'customer_entity_varchar' );
185
- $core_store = $resource->getTableName ( 'core_store' ); // core store
186
- $attr_firstname = Mage::getModel ( 'customer/customer' )->getAttribute ( 'firstname' )->getAttributeId ();
187
- $attr_lastname = Mage::getModel ( 'customer/customer' )->getAttribute ( 'lastname' )->getAttributeId ();
188
- if ($list_type == 'N') {
189
- if ($last_call_date != null && $last_call_date != '') {
190
- $rq_sql = 'SELECT sdu.`email` AS `email`, IFNULL(lastname.`value`, \'\') AS `lastname`, IFNULL(firstname.`value`, \'\') AS `firstname`
191
- FROM `' . $sd_updates . '` AS `sdu`
192
- LEFT JOIN ' . $newsletter_subscriber . ' ns ON ns.subscriber_email = sdu.email
193
- LEFT JOIN ' . $customer_entity_varchar . ' AS `lastname` ON lastname.`entity_id` = ns.`customer_id` AND lastname.`attribute_id` = ' . ( int ) $attr_lastname . '
194
- LEFT JOIN ' . $customer_entity_varchar . ' AS `firstname` ON firstname.`entity_id` = ns.`customer_id` AND firstname.`attribute_id` = ' . ( int ) $attr_firstname . '
195
- WHERE ns.`subscriber_status` = 1 AND sdu.update_time > "' . $last_call_date . '" AND sdu.list_type="N" AND sdu.action="S"
196
- AND ns.`store_id` = ' . ( int ) $store_id;
197
- } else {
198
- $rq_sql = '
199
- SELECT ns.`subscriber_email` AS `email`, IFNULL(lastname.`value`, \'\') AS `lastname`, IFNULL(firstname.`value`, \'\') AS `firstname`
200
- FROM `' . $newsletter_subscriber . '` AS `ns`
201
- LEFT JOIN ' . $customer_entity_varchar . ' AS `lastname` ON lastname.`entity_id` = ns.`customer_id` AND lastname.`attribute_id` = ' . ( int ) $attr_lastname . '
202
- LEFT JOIN ' . $customer_entity_varchar . ' AS `firstname` ON firstname.`entity_id` = ns.`customer_id` AND firstname.`attribute_id` = ' . ( int ) $attr_firstname . '
203
- WHERE ns.`subscriber_status` = 1
204
- AND ns.`store_id` = ' . ( int ) $store_id;
205
- }
206
- } else if ($list_type == 'C') {
207
- $add_customer_data = $this->checkIfListWithCustomerData ( $list_type, $store_id );
208
- if ($add_customer_data) {
209
- $rq_sql = "SELECT
210
- c.email,
211
- cevln.value AS lastname,
212
- cevfn.value AS firstname,
213
- MAX(sfo.base_grand_total) AS amount_max_order,
214
- MIN(sfo.base_grand_total) AS amount_min_order,
215
- AVG(sfo.base_grand_total) AS amount_avg_order,
216
- MIN(sfo.created_at) AS date_first_order,
217
- MAX(sfo.created_at) AS date_last_order,
218
- COUNT(sfo.entity_id) AS nb_orders,
219
- SUM(sfo.base_grand_total) AS amount_all_orders,
220
- (SELECT
221
- ccev.value AS category
222
- FROM
223
- $sales_flat_order AS sfo2
224
- LEFT JOIN
225
- $sales_flat_order_item AS sfoi ON sfo2.entity_id = sfoi.order_id
226
- LEFT JOIN
227
- $catalog_category_product AS ccp ON ccp.product_id = sfoi.product_id
228
- LEFT JOIN
229
- $catalog_category_entity_varchar AS ccev ON ccev.entity_id = ccp.category_id
230
- AND ccev.attribute_id = 41
231
- AND ccev.entity_type_id = 3
232
- WHERE sfo2.customer_id = c.entity_id AND sfo.store_id=$store_id
233
- GROUP BY category
234
- ORDER BY SUM(sfoi.row_total) DESC
235
- LIMIT 1) AS category
236
- FROM
237
- $customer_entity AS c
238
- LEFT JOIN
239
- $customer_entity_varchar AS cevfn ON cevfn.entity_id = c.entity_id
240
- AND cevfn.attribute_id = 5
241
- LEFT JOIN
242
- $customer_entity_varchar AS cevln ON cevln.entity_id = c.entity_id
243
- AND cevln.attribute_id = 7
244
- LEFT JOIN
245
- $sales_flat_order AS sfo ON sfo.customer_id = c.entity_id AND c.store_id = sfo.store_id
246
- WHERE c.store_id = " . $store_id;
247
- if ($last_call_date != null && $last_call_date != '') {
248
- $rq_sql .= " AND (c.created_at > '" . $last_call_date . "' OR c.updated_at > '" . $last_call_date . "' ";
249
- $rq_sql .= " OR sfo.created_at > '" . $last_call_date . "' OR sfo.updated_at > '" . $last_call_date . "') ";
250
- }
251
- $rq_sql .= " GROUP BY c.entity_id ";
252
- $rq_sql .= " UNION (
253
-
254
- SELECT
255
- sfo.customer_email AS email, sfo.customer_lastname AS lastname,sfo.customer_firstname AS firstname,
256
- MAX(sfo.base_grand_total) AS amount_max_order,
257
- MIN(sfo.base_grand_total) AS amount_min_order,
258
- AVG(sfo.base_grand_total) AS amount_avg_order,
259
- MIN(sfo.created_at) AS date_first_order,
260
- MAX(sfo.created_at) AS date_last_order,
261
- COUNT(sfo.entity_id) AS nb_orders,
262
- SUM(sfo.base_grand_total) AS amount_all_orders,
263
- (SELECT
264
- ccev.value AS category
265
- FROM
266
- $sales_flat_order AS sfo2
267
- LEFT JOIN
268
- $sales_flat_order_item AS sfoi ON sfo2.entity_id = sfoi.order_id
269
- LEFT JOIN
270
- $catalog_category_product AS ccp ON ccp.product_id = sfoi.product_id
271
- LEFT JOIN
272
- $catalog_category_entity_varchar AS ccev ON ccev.entity_id = ccp.category_id
273
- AND ccev.attribute_id = 41
274
- AND ccev.entity_type_id = 3
275
- WHERE sfo2.customer_email = sfo.customer_email AND sfo2.customer_is_guest = 1 AND sfo2.store_id = sfo.store_id
276
- GROUP BY category
277
- ORDER BY SUM(sfoi.row_total) DESC
278
- LIMIT 1) AS most_profitable_category
279
- FROM
280
- $sales_flat_order AS sfo
281
- WHERE sfo.customer_is_guest = 1 AND sfo.store_id = " . $store_id;
282
- if ($last_call_date != null && $last_call_date != '') {
283
- $rq_sql .= " AND (sfo.created_at > '" . $last_call_date . "' OR sfo.updated_at > '" . $last_call_date . "') ";
284
- }
285
- $rq_sql .= " GROUP BY sfo.customer_email)";
286
- } else {
287
- $rq_sql = " SELECT t.email, t.lastname, t.firstname ";
288
- $rq_sql .= " FROM ( SELECT c.email AS email,cevln.value AS lastname, cevfn.value AS firstname ";
289
- $rq_sql .= " FROM $customer_entity c LEFT JOIN $customer_entity_varchar cevln ON cevln.entity_id = c.entity_id AND cevln.attribute_id=7
290
- LEFT JOIN $customer_entity_varchar cevfn ON cevfn.entity_id = c.entity_id AND cevfn.attribute_id = 5";
291
- $rq_sql .= " WHERE c.store_id = " . $store_id;
292
- if ($last_call_date != null && $last_call_date != '') {
293
- $rq_sql .= " AND (c.created_at > '" . $last_call_date . "' OR c.updated_at > '" . $last_call_date . "')";
294
- }
295
- $rq_sql .= " GROUP BY c.email
296
- UNION
297
- SELECT sfo.customer_email AS email ,sfo.customer_lastname as lastname, sfo.customer_firstname as firstname";
298
- $rq_sql .= " FROM $sales_flat_order sfo ";
299
- $rq_sql .= " WHERE sfo.customer_id IS NULL AND sfo.store_id = " . $store_id;
300
- if ($last_call_date != null && $last_call_date != '') {
301
- $rq_sql .= " AND (sfo.created_at > '" . $last_call_date . "' OR sfo.updated_at > '" . $last_call_date . "') ";
302
- }
303
- $rq_sql .= " GROUP BY email ";
304
-
305
- $rq_sql .= " ) as t ";
306
- $rq_sql .= " GROUP BY t.email;";
307
- }
308
- } else {
309
- return;
310
- }
311
- if ($type_action == 'is_updated') {
312
- $rq_sql .= ' LIMIT 0, 1 ';
313
- $rq = $db_read->fetchAll ( $rq_sql );
314
- return count ( $rq );
315
- } else {
316
- $rq = $db_read->query ( $rq_sql );
317
- while ( $r = $rq->fetch () ) {
318
- $line = $this->dQuote ( $r ['email'] ) . ';'; // TEST
319
- $line .= $this->dQuote ( $r ['lastname'] ) . ';' . $this->dQuote ( $r ['firstname'] );
320
- if ($list_type == 'C') {
321
- if ($add_customer_data) {
322
- $line .= ';' . $this->dQuote ( $r ['date_first_order'] ) . ';' . $this->dQuote ( $r ['date_last_order'] );
323
- $line .= ';' . ( float ) $r ['amount_min_order'] . ';' . ( float ) $r ['amount_max_order'] . ';' . ( float ) $r ['amount_avg_order'];
324
- $line .= ';' . $r ['nb_orders'] . ';' . ( float ) $r ['amount_all_orders'] . ';' . $r ['category'];
325
- }
326
- }
327
- $line .= ';S'."\r\n";
328
- echo $line;
329
- }
330
- }
331
- }
332
- private function processNewUnsubscribers($list_type, $store_id, $sd_id, $type_action = 'display', $last_call_date) {
333
- $resource = Mage::getSingleton ( 'core/resource' );
334
- $db_read = $resource->getConnection ( 'core_read' );
335
-
336
- $sd_updates = $resource->getTableName ( 'sd_updates' );
337
-
338
- switch ($list_type) {
339
- case 'N' :
340
- case 'C' :
341
- $rq_sql = 'SELECT email FROM ' . $sd_updates . ' WHERE list_type="' . $list_type . '" AND action = "U"';
342
- if ($last_call_date != null && $last_call_date != '') {
343
- $rq_sql .= ' AND update_time > "' . $last_call_date . '"';
344
- }
345
- break;
346
- default :
347
- return;
348
- }
349
- if ($type_action == 'is_updated') {
350
- $rq = $db_read->fetchAll ( $rq_sql );
351
- return count ( $rq );
352
- } else {
353
- $rq = $db_read->query ( $rq_sql );
354
- while ( $r = $rq->fetch () ) {
355
- $line = $this->dQuote ( $r ['email'] ) . ';;'; // TEST
356
- if ($list_type == 'C') {
357
- if ($this->checkIfListWithCustomerData ( $list_type, $store_id )) {
358
- $line .= ';;;;;;;;';
359
- }
360
- }
361
- $line .= ';U' . "\r\n";
362
- echo $line;
363
- }
364
- }
365
- }
366
- }
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Sarbacane
16
+ * @package Sarbacane_Mailify
17
+ * @author Sarbacane Software <contact@sarbacane.com>
18
+ * @copyright 2015 Sarbacane Software
19
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
20
+ */
21
+ class Sarbacane_Mailify_IndexController extends Mage_Core_Controller_Front_Action
22
+ {
23
+
24
+ public function indexAction()
25
+ {
26
+ if (Mage::app()->getRequest()->getParam('stk') && Mage::app()->getRequest()->getParam('sdid')) {
27
+ $sdid = Mage::app()->getRequest()->getParam('sdid');
28
+ $stk = Mage::helper('mailify')->getToken();
29
+ if (Mage::app()->getRequest()->getParam('stk') == $stk && strlen($stk) > 30 && ! Mage::helper('mailify')->checkFailed()) {
30
+ if ($sdid != '' && Mage::helper('mailify')->getConfiguration('nb_configured') == 3) {
31
+ header('Content-type: text/plain; charset=utf-8');
32
+ $configuration = Mage::helper('mailify')->getConfiguration('all');
33
+ if ($configuration['sd_token'] != '' && $configuration['sd_list'] != '' && $configuration['sd_is_user'] != '') {
34
+ $sd_list_array = Mage::helper('mailify')->getListConfiguration('array');
35
+ if (is_array($sd_list_array) && count($sd_list_array) > 0) {
36
+ if (Mage::app()->getRequest()->getParam('list')) {
37
+ $list = Mage::app()->getRequest()->getParam('list');
38
+ $store_id = Mage::helper('mailify')->getIdShopFromList($list);
39
+ $list_type = Mage::helper('mailify')->getListTypeFromList($list);
40
+ $list_type_array = Mage::helper('mailify')->getListTypeArray();
41
+ if (in_array($list_type, $list_type_array)) {
42
+ if (($list_type == 'N' && in_array($list . '0', $sd_list_array))
43
+ || ($list_type == 'C' && (in_array($list . '0', $sd_list_array) || in_array($list . '1', $sd_list_array)))) {
44
+ $now = gmdate('Y-m-d H:i:s');
45
+ $this->processNewUnsubcribersAndSubscribers($list_type, $store_id, $sdid);
46
+ $this->saveSdid($sdid, $list, $now);
47
+ $this->clearHistory($list_type, $store_id);
48
+ } else {
49
+ header('HTTP/1.1 404 Not found');
50
+ die('FAILED_ID');
51
+ }
52
+ } else {
53
+ header('HTTP/1.1 404 Not found');
54
+ die('FAILED_ID');
55
+ }
56
+ } else {
57
+ if (Mage::app()->getRequest()->getParam('action') == 'reset') {
58
+ Mage::helper('mailify')->deleteSdid($sdid);
59
+ } else {
60
+ $this->setDataToUpdate();
61
+ $this->getFormattedContentShops($sdid);
62
+ }
63
+ }
64
+ }
65
+ }
66
+ }
67
+ } else {
68
+ $this->updateFailed();
69
+ header("HTTP/1.1 403 Unauthorized");
70
+ die('FAILED_SDTOKEN');
71
+ }
72
+ die;
73
+ }
74
+ }
75
+
76
+ private function saveSdid($sd_id, $list, $now)
77
+ {
78
+ $resource = Mage::getSingleton('core/resource');
79
+ $db_write = $resource->getConnection('core_write');
80
+ $sd_users = $resource->getTableName('sd_users');
81
+ $rq_sql = '
82
+ INSERT INTO `' . $sd_users . '` VALUES
83
+ (' . $db_write->quote($sd_id) . ', ' . $db_write->quote($list) . ', ' . $db_write->quote($now) . ')
84
+ ON DUPLICATE KEY UPDATE
85
+ `last_call_date` = VALUES(`last_call_date`)';
86
+ $db_write->query($rq_sql);
87
+ }
88
+
89
+ private function updateFailed() {
90
+ if ( ! Mage::helper('mailify')->checkFailed()) {
91
+ Mage::helper('mailify')->updateConfiguration('sd_nb_failed', Mage::helper('mailify')->getConfiguration('sd_nb_failed') + 1);
92
+ }
93
+ }
94
+
95
+ private function setDataToUpdate()
96
+ {
97
+ $resource = Mage::getSingleton('core/resource');
98
+ $db_write = $resource->getConnection('core_write');
99
+ $sd_updates = $resource->getTableName('sd_updates');
100
+ $sales_flat_order = $resource->getTableName('sales_flat_order');
101
+ $customer_entity = $resource->getTableName('customer_entity');
102
+ $now = gmdate('Y-m-d H:i:s');
103
+ if (count(Mage::helper('mailify')->getSynchronizedListsArray() > 0)) {
104
+ $sd_last_update = Mage::helper('mailify')->getConfiguration('sd_last_update');
105
+ if ($sd_last_update != '') {
106
+ $sd_list_array = Mage::helper('mailify')->getListConfiguration('array');
107
+ if (count($sd_list_array) > 0) {
108
+ $id_shops_customer_array = array();
109
+ foreach ($sd_list_array as $sd_list) {
110
+ $store_id = substr($sd_list, 0, -2);
111
+ if (strpos($sd_list, 'C') !== false) {
112
+ if (Mage::helper('mailify')->checkNeedUserInsertSdUpdates($store_id, 'C')) {
113
+ $id_shops_customer_array[] = (int)$store_id;
114
+ }
115
+ }
116
+ }
117
+ if (count($id_shops_customer_array) > 0) {
118
+ $id_shops_customer = implode(', ', $id_shops_customer_array);
119
+ for ($i = 0; $i < 2; $i++) {
120
+ if ($i == 0) {
121
+ $rq_sql_action = 'S';
122
+ $rq_sql_where = '`is_active` = 1';
123
+ } else {
124
+ $rq_sql_action = 'U';
125
+ $rq_sql_where = '`is_active` = 0';
126
+ }
127
+ $rq_sql = '
128
+ INSERT INTO `' . $sd_updates . '`
129
+ SELECT `email`, `store_id`, \'C\' AS `list_type`, \'' . $rq_sql_action . '\' AS `action`, ' . $db_write->quote($now) . ' AS `update_date`
130
+ FROM `' . $customer_entity . '`
131
+ WHERE `updated_at` >= ' . $db_write->quote($sd_last_update) . '
132
+ AND `updated_at` < ' . $db_write->quote($now) . '
133
+ AND `store_id` IN (' . $id_shops_customer . ')
134
+ AND `website_id` != 0
135
+ AND ' . $rq_sql_where . '
136
+ ON DUPLICATE KEY UPDATE
137
+ `action` = VALUES(`action`),
138
+ `update_date` = VALUES(`update_date`)';
139
+ $db_write->query($rq_sql);
140
+ }
141
+ $rq_sql = '
142
+ INSERT INTO `' . $sd_updates . '`
143
+ SELECT IFNULL(`c`.`email`, `sfo`.`customer_email`) AS `email`, `sfo`.`store_id`, \'C\' AS `list_type`, \'S\' AS `action`, ' . $db_write->quote($now) . ' AS `update_date`
144
+ FROM `' . $sales_flat_order . '` AS `sfo`
145
+ LEFT JOIN `' . $customer_entity . '` AS `c`
146
+ ON `c`.`entity_id` = `sfo`.`customer_id`
147
+ AND `c`.`store_id` = `sfo`.`store_id`
148
+ AND `c`.`website_id` != 0
149
+ WHERE `sfo`.`updated_at` >= ' . $db_write->quote($sd_last_update) . '
150
+ AND `sfo`.`updated_at` < ' . $db_write->quote($now) . '
151
+ AND `sfo`.`store_id` IN (' . $id_shops_customer . ')
152
+ ON DUPLICATE KEY UPDATE
153
+ `action` = VALUES(`action`),
154
+ `update_date` = VALUES(`update_date`)';
155
+ $db_write->query($rq_sql);
156
+ }
157
+ }
158
+ }
159
+ }
160
+ Mage::helper('mailify')->updateConfiguration('sd_last_update', $now);
161
+ }
162
+
163
+ private function processNewUnsubcribersAndSubscribers($list_type, $store_id, $sd_id)
164
+ {
165
+ $resource = Mage::getSingleton('core/resource');
166
+ $db_read = $resource->getConnection('core_read');
167
+ $sd_users = $resource->getTableName('sd_users');
168
+ $rq_sql = '
169
+ SELECT `last_call_date`
170
+ FROM `' . $sd_users . '`
171
+ WHERE `sd_id` = ' . $db_read->quote($sd_id) . '
172
+ AND `list_id` = ' . $db_read->quote($store_id . $list_type);
173
+ $last_call_date = $db_read->fetchOne($rq_sql);
174
+ if ($last_call_date == null || $last_call_date == '') {
175
+ $last_call_date = false;
176
+ }
177
+ $line = 'email;lastname;firstname';
178
+ if ($list_type == 'C') {
179
+ if ($this->checkIfListWithCustomerData('C', $store_id)) {
180
+ $line .= ';date_first_order;date_last_order;amount_min_order;amount_max_order;amount_avg_order;nb_orders;amount_all_orders';
181
+ }
182
+ }
183
+ $line .= ';action' . "\n";
184
+ echo $line;
185
+ $this->processNewUnsubscribers($list_type, $store_id, $last_call_date, 'display');
186
+ $this->processNewSubscribers($list_type, $store_id, $last_call_date, 'display');
187
+ }
188
+
189
+ private function checkIfListWithCustomerData($list_type, $store_id)
190
+ {
191
+ $sd_list_array = Mage::helper('mailify')->getListConfiguration('array');
192
+ if (in_array($store_id . $list_type . '1', $sd_list_array)) {
193
+ return true;
194
+ }
195
+ return false;
196
+ }
197
+
198
+ private function getFormattedContentShops($sd_id)
199
+ {
200
+ $shops = Mage::helper('mailify')->getShopsArray();
201
+ echo 'list_id;name;reset;is_updated;type;version' . "\n";
202
+ $sd_list_array = Mage::helper('mailify')->getListConfiguration('array');
203
+ foreach ($sd_list_array as $list) {
204
+ foreach ($shops as $shop) {
205
+ $store_id = Mage::helper('mailify')->getIdShopFromList($list);
206
+ $list_type = Mage::helper('mailify')->getListTypeFromList($list);
207
+ if ($shop['store_id'] == $store_id) {
208
+ $shop_list = $store_id . $list_type . ';' . $this->dQuote($shop['name']) . ';';
209
+ $shop_list .= $this->listStatus($store_id, $list_type, $sd_id) . ';';
210
+ $shop_list .= 'Magento;1.0.0.8' . "\n";//
211
+ echo $shop_list;
212
+ }
213
+ }
214
+ }
215
+ }
216
+
217
+ private function listStatus($store_id, $list_type, $sd_id)
218
+ {
219
+ $resource = Mage::getSingleton('core/resource');
220
+ $db_read = $resource->getConnection('core_read');
221
+ $sd_users = $resource->getTableName('sd_users');
222
+ $list_is_resetted = 'Y';
223
+ $list_is_updated = 'N';
224
+ $last_call_date = false;
225
+ if ( ! isset($this->sd_used_lists)) {
226
+ $rq_sql = '
227
+ SELECT `sd_id`, `list_id`, `last_call_date`
228
+ FROM `' . $sd_users . '`';
229
+ $this->sd_used_lists = $db_read->fetchAll($rq_sql);
230
+ }
231
+ if (is_array($this->sd_used_lists)) {
232
+ foreach ($this->sd_used_lists as $r) {
233
+ if ($r['sd_id'] == $sd_id && $r['list_id'] == $store_id . $list_type) {
234
+ $list_is_resetted = 'N';
235
+ $last_call_date = $r['last_call_date'];
236
+ if ($last_call_date == null || $last_call_date == '') {
237
+ $last_call_date = false;
238
+ }
239
+ break;
240
+ }
241
+ }
242
+ }
243
+ if ($this->processNewUnsubscribers($list_type, $store_id, $last_call_date, 'is_updated') > 0) {
244
+ $list_is_updated = 'Y';
245
+ } else if ($this->processNewSubscribers($list_type, $store_id, $last_call_date, 'is_updated') > 0) {
246
+ $list_is_updated = 'Y';
247
+ }
248
+ return $list_is_resetted . ';' . $list_is_updated;
249
+ }
250
+
251
+ private function dQuote($value)
252
+ {
253
+ $value = str_replace('"', '""', $value);
254
+ if (strpos($value, ' ') !== false || strpos($value, ';') !== false) {
255
+ $value = '"' . $value . '"';
256
+ }
257
+ return $value;
258
+ }
259
+
260
+ private function processNewSubscribers($list_type, $store_id, $last_call_date, $type_action = 'display')
261
+ {
262
+ $resource = Mage::getSingleton('core/resource');
263
+ $db_read = $resource->getConnection('core_read');
264
+ $sd_updates = $resource->getTableName('sd_updates');
265
+ $newsletter_subscriber = $resource->getTableName('newsletter_subscriber');
266
+ $sales_flat_order = $resource->getTableName('sales_flat_order');
267
+ $customer_entity = $resource->getTableName('customer_entity');
268
+ $customer_entity_varchar = $resource->getTableName('customer_entity_varchar');
269
+ $attr_firstname = Mage::getModel('customer/customer')->getAttribute('firstname')->getAttributeId();
270
+ $attr_lastname = Mage::getModel('customer/customer')->getAttribute('lastname')->getAttributeId();
271
+ if ($list_type == 'N') {
272
+ $rq_sql_select = '
273
+ SELECT `ns`.`subscriber_email` AS `email`,
274
+ IFNULL(`lastname`.`value`, SUBSTRING_INDEX(GROUP_CONCAT(`sfo`.`customer_lastname` ORDER BY `sfo`.`updated_at` DESC SEPARATOR \'||\'), \'||\', 1)) AS `lastname`,
275
+ IFNULL(`firstname`.`value`, SUBSTRING_INDEX(GROUP_CONCAT(`sfo`.`customer_firstname` ORDER BY `sfo`.`updated_at` DESC SEPARATOR \'||\'), \'||\', 1)) AS `firstname`';
276
+ $rq_sql_from = '
277
+ LEFT JOIN `' . $customer_entity . '` AS `c`
278
+ ON `c`.`email` = `ns`.`subscriber_email`
279
+ AND `c`.`store_id` = `ns`.`store_id`
280
+ AND `c`.`website_id` != 0
281
+ LEFT JOIN `' . $customer_entity_varchar . '` AS `lastname`
282
+ ON `lastname`.`entity_id` = `c`.`entity_id`
283
+ AND `lastname`.`attribute_id` = ' . (int)$attr_lastname . '
284
+ LEFT JOIN `' . $customer_entity_varchar . '` AS `firstname`
285
+ ON `firstname`.`entity_id` = `c`.`entity_id`
286
+ AND `firstname`.`attribute_id` = ' . (int)$attr_firstname . '
287
+ LEFT JOIN `' . $sales_flat_order . '` AS `sfo`
288
+ ON `sfo`.`customer_email` = `ns`.`subscriber_email`
289
+ AND `sfo`.`store_id` = `ns`.`store_id`';
290
+ $rq_sql_group_by = '
291
+ GROUP BY `ns`.`subscriber_email`';
292
+ if ( ! $last_call_date) {
293
+ $rq_sql =
294
+ $rq_sql_select . '
295
+ FROM `' . $newsletter_subscriber . '` AS `ns`
296
+ ' . $rq_sql_from . '
297
+ WHERE `ns`.`subscriber_status` = 1
298
+ AND `ns`.`store_id` = ' . (int)$store_id .
299
+ $rq_sql_group_by;
300
+ } else {
301
+ $rq_sql =
302
+ $rq_sql_select . '
303
+ FROM `' . $sd_updates . '` AS `s`
304
+ INNER JOIN `' . $newsletter_subscriber . '` AS `ns`
305
+ ON `ns`.`subscriber_email` = `s`.`email`
306
+ AND `ns`.`store_id` = `s`.`store_id`
307
+ AND `ns`.`subscriber_status` = 1
308
+ ' . $rq_sql_from . '
309
+ WHERE `s`.`update_date` >= ' . $db_read->quote($last_call_date) . '
310
+ AND `s`.`list_type` = \'N\'
311
+ AND `s`.`store_id` = ' . (int)$store_id .
312
+ $rq_sql_group_by;
313
+ }
314
+ } else if ($list_type == 'C') {
315
+ $add_customer_data = $this->checkIfListWithCustomerData('C', $store_id);
316
+ if ($add_customer_data) {
317
+ $rq_sql_select = '
318
+ SELECT `t`.`email`, `t`.`lastname`, `t`.`firstname`,
319
+ MIN(`t`.`date_first_order`) AS `date_first_order`, MAX(`t`.`date_last_order`) AS `date_last_order`,
320
+ MIN(`t`.`amount_min_order`) AS `amount_min_order`, MAX(`t`.`amount_max_order`) AS `amount_max_order`,
321
+ ROUND(SUM(`t`.`amount_all_orders`)/SUM(`t`.`nb_orders`), 6) AS `amount_avg_order`, SUM(`t`.`nb_orders`) AS `nb_orders`,
322
+ SUM(`t`.`amount_all_orders`) AS `amount_all_orders`
323
+ FROM
324
+ (';
325
+ $rq_sql_select_table_1 = '
326
+ SELECT `c`.`email`, `lastname`.`value` AS `lastname`, `firstname`.`value` AS `firstname`,
327
+ MIN(`sfo`.`created_at`) AS `date_first_order`, MAX(`sfo`.`created_at`) AS `date_last_order`,
328
+ MIN(`sfo`.`base_grand_total`) AS `amount_min_order`, MAX(`sfo`.`base_grand_total`) AS `amount_max_order`,
329
+ COUNT(`sfo`.`created_at`) AS `nb_orders`, SUM(`sfo`.`base_grand_total`) AS `amount_all_orders`';
330
+ $rq_sql_select_table_2 = '
331
+ SELECT `sfo`.`customer_email` AS `email`,
332
+ SUBSTRING_INDEX(GROUP_CONCAT(`sfo`.`customer_lastname` ORDER BY `sfo`.`updated_at` DESC SEPARATOR \'||\'), \'||\', 1) AS `lastname`,
333
+ SUBSTRING_INDEX(GROUP_CONCAT(`sfo`.`customer_firstname` ORDER BY `sfo`.`updated_at` DESC SEPARATOR \'||\'), \'||\', 1) AS `firstname`,
334
+ MIN(`sfo`.`created_at`) AS `date_first_order`, MAX(`sfo`.`created_at`) AS `date_last_order`,
335
+ MIN(`sfo`.`base_grand_total`) AS `amount_min_order`, MAX(`sfo`.`base_grand_total`) AS `amount_max_order`,
336
+ COUNT(`sfo`.`created_at`) AS `nb_orders`, SUM(`sfo`.`base_grand_total`) AS `amount_all_orders`';
337
+ $rq_sql_from = '
338
+ INNER JOIN `' . $customer_entity_varchar . '` AS `lastname`
339
+ ON `lastname`.`entity_id` = `c`.`entity_id`
340
+ AND `lastname`.`attribute_id` = 7
341
+ INNER JOIN `' . $customer_entity_varchar . '` AS `firstname`
342
+ ON `firstname`.`entity_id` = `c`.`entity_id`
343
+ AND `firstname`.`attribute_id` = 5
344
+ LEFT JOIN `' . $sales_flat_order . '` AS `sfo`
345
+ ON `sfo`.`customer_id` = `c`.`entity_id`
346
+ AND `sfo`.`store_id` = `c`.`store_id`';
347
+ $rq_sql_group_by = '
348
+ ) AS `t`
349
+ GROUP BY `t`.`email`';
350
+ } else {
351
+ $rq_sql_select = '
352
+ SELECT `t`.`email`, `t`.`lastname`, `t`.`firstname`
353
+ FROM
354
+ (';
355
+ $rq_sql_select_table_1 = '
356
+ SELECT `c`.`email`, `lastname`.`value` AS `lastname`, `firstname`.`value` AS `firstname`';
357
+ $rq_sql_select_table_2 = '
358
+ SELECT `sfo`.`customer_email` AS `email`,
359
+ SUBSTRING_INDEX(GROUP_CONCAT(`sfo`.`customer_lastname` ORDER BY `sfo`.`updated_at` DESC SEPARATOR \'||\'), \'||\', 1) AS `lastname`,
360
+ SUBSTRING_INDEX(GROUP_CONCAT(`sfo`.`customer_firstname` ORDER BY `sfo`.`updated_at` DESC SEPARATOR \'||\'), \'||\', 1) AS `firstname`';
361
+ $rq_sql_from = '
362
+ INNER JOIN `' . $customer_entity_varchar . '` AS `lastname`
363
+ ON `lastname`.`entity_id` = `c`.`entity_id`
364
+ AND `lastname`.`attribute_id` = 7
365
+ INNER JOIN `' . $customer_entity_varchar . '` AS `firstname`
366
+ ON `firstname`.`entity_id` = `c`.`entity_id`
367
+ AND `firstname`.`attribute_id` = 5';
368
+ $rq_sql_group_by = '
369
+ ) AS `t`
370
+ GROUP BY `t`.`email`';
371
+ }
372
+ if ( ! $last_call_date) {
373
+ $rq_sql =
374
+ $rq_sql_select . '
375
+ (
376
+ ' . $rq_sql_select_table_1 . '
377
+ FROM `' . $customer_entity . '` AS `c`
378
+ ' . $rq_sql_from . '
379
+ WHERE `c`.`store_id` = ' . (int)$store_id . '
380
+ AND `c`.`website_id` != 0
381
+ GROUP BY `c`.`email`
382
+ )
383
+ UNION ALL
384
+ (
385
+ ' . $rq_sql_select_table_2 . '
386
+ FROM `' . $sales_flat_order . '` AS `sfo`
387
+ LEFT JOIN `' . $customer_entity . '` AS `c`
388
+ ON `c`.`entity_id` = `sfo`.`customer_id`
389
+ AND `c`.`store_id` = `sfo`.`store_id`
390
+ AND `c`.`website_id` != 0
391
+ WHERE `c`.`entity_id` IS NULL
392
+ AND `sfo`.`store_id` = ' . (int)$store_id . '
393
+ GROUP BY `sfo`.`customer_email`
394
+ )' .
395
+ $rq_sql_group_by;
396
+ } else {
397
+ $rq_sql =
398
+ $rq_sql_select . '
399
+ (
400
+ ' . $rq_sql_select_table_1 . '
401
+ FROM `' . $sd_updates . '` AS `s`
402
+ INNER JOIN `' . $customer_entity . '` AS `c`
403
+ ON `c`.`email` = `s`.`email`
404
+ AND `c`.`store_id` = `s`.`store_id`
405
+ AND `c`.`website_id` != 0
406
+ ' . $rq_sql_from . '
407
+ WHERE `s`.`store_id` = ' . (int)$store_id . '
408
+ AND `s`.`list_type` = \'C\'
409
+ AND `s`.`update_date` >= ' . $db_read->quote($last_call_date) . '
410
+ GROUP BY `c`.`email`
411
+ )
412
+ UNION ALL
413
+ (
414
+ ' . $rq_sql_select_table_2 . '
415
+ FROM `' . $sd_updates . '` AS `s`
416
+ INNER JOIN `' . $sales_flat_order . '` AS `sfo`
417
+ ON `sfo`.`customer_email` = `s`.`email`
418
+ AND `sfo`.`store_id` = `s`.`store_id`
419
+ LEFT JOIN `' . $customer_entity . '` AS `c`
420
+ ON `c`.`entity_id` = `sfo`.`customer_id`
421
+ AND `c`.`store_id` = `s`.`store_id`
422
+ AND `c`.`website_id` != 0
423
+ WHERE `c`.`entity_id` IS NULL
424
+ AND `s`.`store_id` = ' . (int)$store_id . '
425
+ AND `s`.`list_type` = \'C\'
426
+ AND `s`.`update_date` >= ' . $db_read->quote($last_call_date) . '
427
+ GROUP BY `sfo`.`customer_email`
428
+ )' .
429
+ $rq_sql_group_by;
430
+ }
431
+ } else {
432
+ if ($type_action == 'is_updated') {
433
+ return 0;
434
+ } else {
435
+ return;
436
+ }
437
+ }
438
+ $rq = $db_read->query($rq_sql);
439
+ while ($r = $rq->fetch()) {
440
+ if ($type_action == 'is_updated') {
441
+ return 1;
442
+ }
443
+ $line = $this->dQuote($r['email']) . ';';
444
+ $line .= $this->dQuote($r['lastname']) . ';' . $this->dQuote($r['firstname']);
445
+ if ($list_type == 'C') {
446
+ if ($add_customer_data) {
447
+ $line .= ';' . $this->dQuote($r ['date_first_order']) . ';' . $this->dQuote($r['date_last_order']);
448
+ $line .= ';' . (float)$r['amount_min_order'] . ';' . (float)$r['amount_max_order'] . ';' . (float)$r['amount_avg_order'];
449
+ $line .= ';' . $r['nb_orders'] . ';' . (float)$r['amount_all_orders'];
450
+ }
451
+ }
452
+ $line .= ';S' . "\n";
453
+ echo $line;
454
+ }
455
+ }
456
+
457
+ private function processNewUnsubscribers($list_type, $store_id, $last_call_date, $type_action = 'display')
458
+ {
459
+ $resource = Mage::getSingleton('core/resource');
460
+ $db_read = $resource->getConnection('core_read');
461
+ $sd_updates = $resource->getTableName('sd_updates');
462
+ if ($last_call_date !== false && ($list_type == 'N' || $list_type == 'C')) {
463
+ $rq_sql = '
464
+ SELECT `email`
465
+ FROM `' . $sd_updates . '`
466
+ WHERE `list_type` = ' . $db_read->quote($list_type) . '
467
+ AND `store_id` = ' . (int)$store_id . '
468
+ AND `action` = \'U\'
469
+ AND `update_date` >= ' . $db_read->quote($last_call_date);
470
+ $rq = $db_read->query($rq_sql);
471
+ while ($r = $rq->fetch()) {
472
+ if ($type_action == 'is_updated') {
473
+ return 1;
474
+ }
475
+ $line = $this->dQuote($r['email']) . ';;';
476
+ if ($list_type == 'C') {
477
+ if ($this->checkIfListWithCustomerData('C', $store_id)) {
478
+ $line .= ';;;;;;;;';
479
+ }
480
+ }
481
+ $line .= ';U' . "\n";
482
+ echo $line;
483
+ }
484
+ }
485
+ else {
486
+ if ($type_action == 'is_updated') {
487
+ return 0;
488
+ }
489
+ }
490
+ }
491
+
492
+ private function clearHistory($list_type, $store_id)
493
+ {
494
+ $resource = Mage::getSingleton('core/resource');
495
+ $db_write = $resource->getConnection('core_write');
496
+ $sd_updates = $resource->getTableName('sd_updates');
497
+ $sd_users = $resource->getTableName('sd_users');
498
+ $rq_sql = '
499
+ DELETE
500
+ FROM `' . $sd_updates . '`
501
+ WHERE `store_id` = ' . (int)$store_id . '
502
+ AND `list_type` = ' . $db_write->quote($list_type) . '
503
+ AND `update_date` <= (
504
+ SELECT MIN(`last_call_date`)
505
+ FROM `' . $sd_users . '`
506
+ WHERE `list_id` = ' . $db_write->quote($store_id . $list_type) . '
507
+ )';
508
+ $db_write->query($rq_sql);
509
+ $rq_sql = '
510
+ DELETE
511
+ FROM `' . $sd_updates . '`
512
+ WHERE `update_date` <= (
513
+ SELECT MIN(`last_call_date`)
514
+ FROM `' . $sd_users . '`
515
+ )';
516
+ $db_write->query($rq_sql);
517
+ }
518
+
519
+ }
app/code/community/Sarbacane/Mailify/etc/config.xml CHANGED
@@ -21,128 +21,142 @@
21
*/
22
-->
23
<config>
24
- <modules>
25
- <Sarbacane_Mailify>
26
- <version>1.0.0.7</version>
27
- </Sarbacane_Mailify>
28
- </modules>
29
- <frontend>
30
- <routers>
31
- <sarbacanedesktop>
32
- <use>standard</use>
33
- <args>
34
- <module>Sarbacane_Mailify</module>
35
- <frontName>sarbacanedesktop</frontName>
36
- </args>
37
- </sarbacanedesktop>
38
- </routers>
39
- <!--
40
- <layout>
41
- <updates>
42
- <sarbacanedesktop>
43
- <file>sarbacanedesktop.xml</file>
44
- </sarbacanedesktop>
45
- </updates>
46
- </layout>
47
- -->
48
- </frontend>
49
- <admin>
50
- <routers>
51
- <adminhtml>
52
- <args>
53
- <modules>
54
- <mailify before="Mage_Adminhtml">Sarbacane_Mailify_Adminhtml</mailify>
55
- </modules>
56
- </args>
57
- </adminhtml>
58
- </routers>
59
- <!--
60
- <routers>
61
- <sarbacanedesktop>
62
- <use>admin</use>
63
- <args>
64
- <module>Sarbacane_Sarbacanedesktop</module>
65
- <frontName>sarbacanedesktop</frontName>
66
- </args>
67
- </sarbacanedesktop>
68
- </routers>
69
- -->
70
- </admin>
71
- <adminhtml>
72
- <menu>
73
- <newsletter>
74
- <children>
75
- <items module="mailify" translate="title">
76
- <title>Mailify</title>
77
- <sort_order>120</sort_order>
78
- <action>adminhtml/mailify</action>
79
- </items>
80
- </children>
81
- </newsletter>
82
- </menu>
83
- <acl>
84
- <resources>
85
- <admin>
86
- <children>
87
- <newsletter>
88
- <children>
89
- <mailify translate="title">
90
- <title>Mailify</title>
91
- <sort_order>120</sort_order>
92
- </mailify>
93
- </children>
94
- </newsletter>
95
- </children>
96
- </admin>
97
- </resources>
98
- </acl>
99
- <layout>
100
- <updates>
101
- <mailify>
102
- <file>mailify.xml</file>
103
- </mailify>
104
- </updates>
105
- </layout>
106
- <translate>
107
- <modules>
108
- <Sarbacane_Mailify>
109
- <files>
110
- <default>Sarbacane_Mailify.csv</default>
111
- </files>
112
- </Sarbacane_Mailify>
113
- </modules>
114
- </translate>
115
- </adminhtml>
116
- <global>
117
- <helpers>
118
- <mailify>
119
- <class>Sarbacane_Mailify_Helper</class>
120
- </mailify>
121
- </helpers>
122
- <blocks>
123
- <mailify>
124
- <class>Sarbacane_Mailify_Block</class>
125
- </mailify>
126
- </blocks>
127
- <resources>
128
- <mailify_setup>
129
- <setup>
130
- <module>Sarbacane_Mailify</module>
131
- </setup>
132
- <connection>
133
- <use>core_setup</use>
134
- </connection>
135
- </mailify_setup>
136
- <mailify_write>
137
- <connection>
138
- <use>core_write</use>
139
- </connection>
140
- </mailify_write>
141
- <mailify_read>
142
- <connection>
143
- <use>core_read</use>
144
- </connection>
145
- </mailify_read>
146
- </resources>
147
- </global>
148
- </config>
21
*/
22
-->
23
<config>
24
+ <modules>
25
+ <Sarbacane_Mailify>
26
+ <version>1.0.0.8</version>
27
+ </Sarbacane_Mailify>
28
+ </modules>
29
+ <frontend>
30
+ <routers>
31
+ <mailify>
32
+ <use>standard</use>
33
+ <args>
34
+ <module>Sarbacane_Mailify</module>
35
+ <frontName>sarbacanedesktop</frontName>
36
+ </args>
37
+ </mailify>
38
+ </routers>
39
+ </frontend>
40
+ <admin>
41
+ <routers>
42
+ <adminhtml>
43
+ <args>
44
+ <modules>
45
+ <mailify before="Mage_Adminhtml">Sarbacane_Mailify_Adminhtml</mailify>
46
+ </modules>
47
+ </args>
48
+ </adminhtml>
49
+ </routers>
50
+ </admin>
51
+ <adminhtml>
52
+ <menu>
53
+ <newsletter>
54
+ <children>
55
+ <mailify module="mailify" translate="title">
56
+ <title>Mailify</title>
57
+ <sort_order>120</sort_order>
58
+ <action>adminhtml/mailify</action>
59
+ </mailify>
60
+ </children>
61
+ </newsletter>
62
+ </menu>
63
+ <acl>
64
+ <resources>
65
+ <admin>
66
+ <children>
67
+ <newsletter>
68
+ <children>
69
+ <mailify translate="title">
70
+ <title>Mailify</title>
71
+ <sort_order>120</sort_order>
72
+ </mailify>
73
+ </children>
74
+ </newsletter>
75
+ </children>
76
+ </admin>
77
+ </resources>
78
+ </acl>
79
+ <layout>
80
+ <updates>
81
+ <mailify>
82
+ <file>mailify.xml</file>
83
+ </mailify>
84
+ </updates>
85
+ </layout>
86
+ <translate>
87
+ <modules>
88
+ <Sarbacane_Mailify>
89
+ <files>
90
+ <default>Sarbacane_Mailify.csv</default>
91
+ </files>
92
+ </Sarbacane_Mailify>
93
+ </modules>
94
+ </translate>
95
+ </adminhtml>
96
+ <global>
97
+ <events>
98
+ <customer_save_before>
99
+ <observers>
100
+ <mailify_customer_save>
101
+ <class>Sarbacane_Mailify_Model_Observer</class>
102
+ <method>customerSave</method>
103
+ </mailify_customer_save>
104
+ </observers>
105
+ </customer_save_before>
106
+ <customer_delete_before>
107
+ <observers>
108
+ <mailify_customer_delete>
109
+ <class>Sarbacane_Mailify_Model_Observer</class>
110
+ <method>customerDelete</method>
111
+ </mailify_customer_delete>
112
+ </observers>
113
+ </customer_delete_before>
114
+ <newsletter_subscriber_save_before>
115
+ <observers>
116
+ <mailify_newsletter_subscriber_save>
117
+ <class>Sarbacane_Mailify_Model_Observer</class>
118
+ <method>newsletterSubscriberSave</method>
119
+ </mailify_newsletter_subscriber_save>
120
+ </observers>
121
+ </newsletter_subscriber_save_before>
122
+ <newsletter_subscriber_delete_before>
123
+ <observers>
124
+ <mailify_newsletter_subscriber_delete>
125
+ <class>Sarbacane_Mailify_Model_Observer</class>
126
+ <method>newsletterSubscriberDelete</method>
127
+ </mailify_newsletter_subscriber_delete>
128
+ </observers>
129
+ </newsletter_subscriber_delete_before>
130
+ </events>
131
+ <helpers>
132
+ <mailify>
133
+ <class>Sarbacane_Mailify_Helper</class>
134
+ </mailify>
135
+ </helpers>
136
+ <blocks>
137
+ <mailify>
138
+ <class>Sarbacane_Mailify_Block</class>
139
+ </mailify>
140
+ </blocks>
141
+ <resources>
142
+ <mailify_setup>
143
+ <setup>
144
+ <module>Sarbacane_Mailify</module>
145
+ </setup>
146
+ <connection>
147
+ <use>core_setup</use>
148
+ </connection>
149
+ </mailify_setup>
150
+ <mailify_write>
151
+ <connection>
152
+ <use>core_write</use>
153
+ </connection>
154
+ </mailify_write>
155
+ <mailify_read>
156
+ <connection>
157
+ <use>core_read</use>
158
+ </connection>
159
+ </mailify_read>
160
+ </resources>
161
+ </global>
162
+ </config>
app/code/community/Sarbacane/Mailify/sql/mailify_setup/mysql4-install-1.0.0.0.php DELETED
@@ -1,52 +0,0 @@
1
- <?php
2
- /**
3
- * Magento
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Academic Free License (AFL 3.0)
8
- * that is bundled with this package in the file LICENSE.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/afl-3.0.php
11
- * If you did not receive a copy of the license and are unable to
12
- * obtain it through the world-wide-web, please send an email
13
- * to license@magentocommerce.com so we can send you a copy immediately.
14
- *
15
- * @category Sarbacane
16
- * @package Sarbacane_Sarbacanedesktop
17
- * @author Sarbacane Software <contact@sarbacane.com>
18
- * @copyright 2015 Sarbacane Software
19
- * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
20
- */
21
-
22
- $installer = $this;
23
- $installer->startSetup();
24
-
25
- $installer->run("
26
- DROP TABLE IF EXISTS `{$this->getTable('sarbacanedesktop')}`;
27
- DROP TABLE IF EXISTS `{$this->getTable('sarbacanedesktop_users')}`;
28
-
29
- CREATE TABLE `{$this->getTable('sarbacanedesktop')}` (
30
- `email` varchar(150) NOT NULL,
31
- `list_type` varchar(20) NOT NULL,
32
- `store_id` varchar(20) NOT NULL,
33
- `sd_id` varchar(20) NOT NULL,
34
- `lastname` varchar(150) NOT NULL,
35
- `firstname` varchar(150) NOT NULL,
36
- `orders_data` varchar(150) NOT NULL,
37
- PRIMARY KEY(`email`,`store_id`,`list_type`,`sd_id`)
38
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
39
-
40
- CREATE TABLE `{$this->getTable('sarbacanedesktop_users')}` (
41
- `sd_id` int(20) unsigned NOT NULL AUTO_INCREMENT,
42
- `sd_type` varchar(20) NOT NULL,
43
- `sd_value` varchar(200) NOT NULL,
44
- PRIMARY KEY(`sd_id`)
45
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
46
-
47
- INSERT INTO `{$this->getTable('sarbacanedesktop_users')}` (`sd_type`, `sd_value`) VALUES
48
- ('sd_token', ''),
49
- ('sd_list', '');
50
-
51
- ");
52
- $installer->endSetup();
app/code/community/Sarbacane/Mailify/sql/mailify_setup/mysql4-upgrade-1.0.0.0-1.0.0.1.php DELETED
@@ -1,25 +0,0 @@
1
- <?php
2
- /**
3
- * Magento
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Academic Free License (AFL 3.0)
8
- * that is bundled with this package in the file LICENSE.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/afl-3.0.php
11
- * If you did not receive a copy of the license and are unable to
12
- * obtain it through the world-wide-web, please send an email
13
- * to license@magentocommerce.com so we can send you a copy immediately.
14
- *
15
- * @category Sarbacane
16
- * @package Sarbacane_Sarbacanedesktop
17
- * @author Sarbacane Software <contact@sarbacane.com>
18
- * @copyright 2015 Sarbacane Software
19
- * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
20
- */
21
-
22
- $installer = $this;
23
- $installer->startSetup();
24
-
25
- $installer->endSetup();
app/code/community/Sarbacane/Mailify/sql/mailify_setup/mysql4-upgrade-1.0.0.1-1.0.0.2.php DELETED
@@ -1,25 +0,0 @@
1
- <?php
2
- /**
3
- * Magento
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Academic Free License (AFL 3.0)
8
- * that is bundled with this package in the file LICENSE.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/afl-3.0.php
11
- * If you did not receive a copy of the license and are unable to
12
- * obtain it through the world-wide-web, please send an email
13
- * to license@magentocommerce.com so we can send you a copy immediately.
14
- *
15
- * @category Sarbacane
16
- * @package Sarbacane_Sarbacanedesktop
17
- * @author Sarbacane Software <contact@sarbacane.com>
18
- * @copyright 2015 Sarbacane Software
19
- * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
20
- */
21
-
22
- $installer = $this;
23
- $installer->startSetup();
24
-
25
- $installer->endSetup();
app/code/community/Sarbacane/Mailify/sql/mailify_setup/mysql4-upgrade-1.0.0.2-1.0.0.3.php DELETED
@@ -1,25 +0,0 @@
1
- <?php
2
- /**
3
- * Magento
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Academic Free License (AFL 3.0)
8
- * that is bundled with this package in the file LICENSE.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/afl-3.0.php
11
- * If you did not receive a copy of the license and are unable to
12
- * obtain it through the world-wide-web, please send an email
13
- * to license@magentocommerce.com so we can send you a copy immediately.
14
- *
15
- * @category Sarbacane
16
- * @package Sarbacane_Sarbacanedesktop
17
- * @author Sarbacane Software <contact@sarbacane.com>
18
- * @copyright 2015 Sarbacane Software
19
- * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
20
- */
21
-
22
- $installer = $this;
23
- $installer->startSetup();
24
-
25
- $installer->endSetup();
app/code/community/Sarbacane/Mailify/sql/mailify_setup/mysql4-upgrade-1.0.0.3-1.0.0.4.php DELETED
@@ -1,87 +0,0 @@
1
- <?php
2
- /**
3
- * Magento
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Academic Free License (AFL 3.0)
8
- * that is bundled with this package in the file LICENSE.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/afl-3.0.php
11
- * If you did not receive a copy of the license and are unable to
12
- * obtain it through the world-wide-web, please send an email
13
- * to license@magentocommerce.com so we can send you a copy immediately.
14
- *
15
- * @category Sarbacane
16
- * @package Sarbacane_Sarbacanedesktop
17
- * @author Sarbacane Software <contact@sarbacane.com>
18
- * @copyright 2015 Sarbacane Software
19
- * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
20
- */
21
-
22
- $installer = $this;
23
- $installer->startSetup();
24
-
25
- $installer->run("DROP TABLE IF EXISTS `{$this->getTable('sarbacanedesktop')}`;");
26
- $installer->run("DROP TABLE IF EXISTS `{$this->getTable('sd_updates')}`;");
27
-
28
- $installer->run("ALTER TABLE `{$this->getTable('sarbacanedesktop_users')}` ADD COLUMN `list_id` VARCHAR(50) NULL DEFAULT NULL AFTER `sd_value`;");
29
- $installer->run("ALTER TABLE `{$this->getTable('sarbacanedesktop_users')}` ADD COLUMN `last_call_date` VARCHAR(50) NULL DEFAULT NULL AFTER `list_id`;");
30
-
31
- $installer->run("
32
- CREATE TABLE `{$this->getTable('sd_updates')}` (
33
- `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
34
- `email` VARCHAR(50) NOT NULL COLLATE 'utf8_bin',
35
- `update_time` DATETIME NOT NULL,
36
- `action` VARCHAR(5) NOT NULL COLLATE 'utf8_bin',
37
- `list_type` VARCHAR(10) NULL DEFAULT NULL COLLATE 'utf8_bin',
38
- PRIMARY KEY (`id`),
39
- INDEX `update_time_action` (`update_time`, `action`)
40
- )
41
- COMMENT='Contains useful data used by SD/MF plugin'
42
- COLLATE='utf8_bin'
43
- ENGINE=InnoDB
44
- ;");
45
-
46
- $installer->run("DROP TRIGGER IF EXISTS sd_newsletter_update;");
47
- $installer->run("DROP TRIGGER IF EXISTS sd_customer_delete;");
48
-
49
- $write = Mage::getSingleton('core/resource')->getConnection('core_write');
50
-
51
- $sql= "
52
- CREATE TRIGGER `sd_newsletter_update`
53
- AFTER UPDATE ON `{$this->getTable('newsletter_subscriber')}`
54
- FOR EACH ROW BEGIN
55
- DELETE FROM {$this->getTable('sd_updates')} WHERE email=NEW.subscriber_email AND list_type='N';
56
- IF NEW.subscriber_status = 1 THEN
57
- INSERT INTO {$this->getTable('sd_updates')} (email,update_time,action,list_type) VALUES (NEW.subscriber_email,UTC_TIMESTAMP(),'S','N');
58
- ELSE
59
- INSERT INTO {$this->getTable('sd_updates')} (email,update_time,action,list_type) VALUES (NEW.subscriber_email,UTC_TIMESTAMP(),'U','N');
60
- END IF;
61
- END;";
62
- $write->exec($sql);
63
-
64
- $sql= "
65
- CREATE TRIGGER `sd_newsletter_insert`
66
- AFTER INSERT ON `{$this->getTable('newsletter_subscriber')}`
67
- FOR EACH ROW BEGIN
68
- DELETE FROM {$this->getTable('sd_updates')} WHERE email=NEW.subscriber_email AND list_type='N';
69
- IF NEW.subscriber_status = 1 THEN
70
- INSERT INTO {$this->getTable('sd_updates')} (email,update_time,action,list_type) VALUES (NEW.subscriber_email,UTC_TIMESTAMP(),'S','N');
71
- ELSE
72
- INSERT INTO {$this->getTable('sd_updates')} (email,update_time,action,list_type) VALUES (NEW.subscriber_email,UTC_TIMESTAMP(),'U','N');
73
- END IF;
74
- END;";
75
- $write->exec($sql);
76
-
77
- $sql = "
78
- CREATE TRIGGER `sd_customer_delete`
79
- BEFORE DELETE ON `{$this->getTable('customer_entity')}`
80
- FOR EACH ROW BEGIN
81
- DELETE FROM {$this->getTable('sd_updates')} WHERE email=OLD.email AND list_type='C';
82
- INSERT INTO {$this->getTable('sd_updates')} (email,update_time,action,list_type) VALUES (OLD.email,UTC_TIMESTAMP(),'U','C');
83
- END";
84
- $write->exec($sql);
85
-
86
-
87
- $installer->endSetup();
app/code/community/Sarbacane/Mailify/sql/mailify_setup/mysql4-upgrade-1.0.0.7-1.0.0.8.php ADDED
@@ -0,0 +1,113 @@
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Sarbacane
16
+ * @package Sarbacane_Mailify
17
+ * @author Sarbacane Software <contact@sarbacane.com>
18
+ * @copyright 2015 Sarbacane Software
19
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
20
+ */
21
+
22
+ $installer = $this;
23
+ $installer->startSetup();
24
+
25
+ try{
26
+ $installer->run("DROP TRIGGER IF EXISTS sd_newsletter_update;");
27
+ }
28
+ catch(Exception $e) {}
29
+ try{
30
+ $installer->run("DROP TRIGGER IF EXISTS sd_newsletter_insert;");
31
+ }
32
+ catch(Exception $e) {}
33
+ try{
34
+ $installer->run("DROP TRIGGER IF EXISTS sd_customer_delete;");
35
+ }
36
+ catch(Exception $e) {}
37
+
38
+ $installer->run("
39
+ CREATE TABLE IF NOT EXISTS `{$this->getTable('sarbacanedesktop_users')}` (
40
+ `sd_type` varchar(20) NOT NULL,
41
+ `sd_value` varchar(200) NOT NULL,
42
+ PRIMARY KEY(`sd_type`)
43
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
44
+ ");
45
+
46
+ $db_read = Mage::getSingleton('core/resource')->getConnection('core_read');
47
+ $sd_token = '';
48
+ $sd_list = '';
49
+ $sd_is_user = '';
50
+ $sd_nb_failed = '';
51
+ $sd_last_update = '';
52
+
53
+ $rq_sql = "
54
+ SELECT `sd_type`, `sd_value`
55
+ FROM `{$this->getTable('sarbacanedesktop_users')}`
56
+ WHERE `sd_type` IN ('sd_token', 'sd_list');";
57
+ $rq = $db_read->query($rq_sql);
58
+ while ($r = $rq->fetch()) {
59
+ if ($r['sd_type'] == 'sd_token') {
60
+ $sd_token = $r['sd_value'];
61
+ } else if ($r['sd_type'] == 'sd_list') {
62
+ $sd_list = $r['sd_value'];
63
+ }
64
+ }
65
+
66
+ if ($sd_token != '' || $sd_list != '') {
67
+ $sd_is_user = 'yes';
68
+ }
69
+
70
+ $installer->run("
71
+ DROP TABLE IF EXISTS `{$this->getTable('sarbacanedesktop')}`;
72
+
73
+ DROP TABLE IF EXISTS `{$this->getTable('sarbacanedesktop_users')}`;
74
+
75
+ DROP TABLE IF EXISTS `{$this->getTable('sd_updates')}`;
76
+
77
+ DROP TABLE IF EXISTS `{$this->getTable('sd_users')}`;
78
+
79
+ DROP TABLE IF EXISTS `{$this->getTable('sd_data')}`;
80
+
81
+ CREATE TABLE `{$this->getTable('sd_updates')}` (
82
+ `email` varchar(50) NOT NULL,
83
+ `store_id` int(11) unsigned NOT NULL,
84
+ `list_type` varchar(10) NOT NULL,
85
+ `action` varchar(5) NOT NULL,
86
+ `update_date` datetime NOT NULL,
87
+ PRIMARY KEY (`email`, `store_id`, `list_type`)
88
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
89
+
90
+ CREATE TABLE `{$this->getTable('sd_users')}` (
91
+ `sd_id` varchar(200) NOT NULL,
92
+ `list_id` varchar(50) NOT NULL,
93
+ `last_call_date` datetime NOT NULL,
94
+ PRIMARY KEY(`sd_id`, `list_id`)
95
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
96
+
97
+ CREATE TABLE `{$this->getTable('sd_data')}` (
98
+ `sd_type` varchar(20) NOT NULL,
99
+ `sd_value` varchar(200) NOT NULL,
100
+ PRIMARY KEY(`sd_type`)
101
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
102
+
103
+ INSERT INTO `{$this->getTable('sd_data')}`
104
+ (`sd_type`, `sd_value`)
105
+ VALUES
106
+ ('sd_token', {$db_read->quote($sd_token)}),
107
+ ('sd_list', {$db_read->quote($sd_list)}),
108
+ ('sd_is_user', {$db_read->quote($sd_is_user)}),
109
+ ('sd_nb_failed', {$db_read->quote($sd_nb_failed)}),
110
+ ('sd_last_update', {$db_read->quote($sd_last_update)});
111
+ ");
112
+
113
+ $installer->endSetup();
app/design/adminhtml/default/default/layout/mailify.xml CHANGED
@@ -21,9 +21,9 @@
21
*/
22
-->
23
<layout>
24
- <adminhtml_mailify_index>
25
- <reference name="content">
26
- <block type="mailify/adminhtml_mailify" name="mailify" template="mailify/mailify.phtml"/>
27
- </reference>
28
- </adminhtml_mailify_index>
29
- </layout>
21
*/
22
-->
23
<layout>
24
+ <adminhtml_mailify_index>
25
+ <reference name="content">
26
+ <block type="mailify/adminhtml_mailify" name="mailify" template="mailify/mailify.phtml"/>
27
+ </reference>
28
+ </adminhtml_mailify_index>
29
+ </layout>
app/design/adminhtml/default/default/template/mailify/mailify.phtml CHANGED
@@ -18,249 +18,265 @@
18
* @copyright 2015 Sarbacane Software
19
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
20
*/
21
- $key_for_synchronisation = $this->getKeyForSynchronisation ();
22
- $list_configuration = $this->getListConfiguration ();
23
- $general_configuration = $this->getGeneralConfiguration ();
24
- $stores_array = $this->getStoresArray ();
25
?>
26
- <link rel="stylesheet" type="text/css" href="<?=$this->getSkinUrl('css/Sarbacane_Mailify/mailify.css')?>" />
27
- <script type="text/javascript" src="<?=$this->getSkinUrl('js/Sarbacane_Mailify/mailify.js')?>"></script>
28
- <div id="sarbacanedesktop">
29
- <div class="sd_header">
30
- <div class="sd_logo_<?=$this->__('mailify') ?>"></div>
31
- </div>
32
- <p class="sd_title"><?=$this->__('It\'s easy to manage your newsletter and email campaigns')?></p>
33
- <div class="sd_title_separator_page"></div>
34
- <div class="sd_video_config_container">
35
- <div class="sd_video_container">
36
- <iframe width="565" height="315" src="<?=$this->__('https://www.youtube.com/embed/eLMy2tSSYgE')?>?rel=0&showinfo=0" frameborder="0" allowfullscreen></iframe>
37
- </div>
38
- <div class="sd_config_container">
39
- <p><?=$this->__('This Magento module enables you to synchronize clients and accounts that have subscribed to your newsletter from your shop online using Mailify\'s email marketing software.')?></p>
40
- <p>
41
- <input type="button" onclick="document.location = '#sd_step'" class="sd_config_button" value="<?=$this->__('Begin the set-up')?>" />
42
- </p>
43
- </div>
44
- </div>
45
- <div class="sd_separator"></div>
46
- <div class="sd_detail_description_container">
47
- <div>
48
- <div>
49
- <div>
50
- <div class="sd_picto1"></div>
51
- <p class="sd_long_subtitle"><?=$this->__('Synchronization of your shop data')?></p>
52
- </div>
53
- </div>
54
- <div>
55
- <div>
56
- <div class="sd_picto2"></div>
57
- <p class="sd_long_subtitle"><?=$this->__('Responsive visual editor')?></p>
58
- </div>
59
- </div>
60
- <div>
61
- <div>
62
- <div class="sd_picto3"></div>
63
- <p class="sd_short_subtitle"><?=$this->__('Detailed statistics')?></p>
64
- </div>
65
- </div>
66
- <div>
67
- <div>
68
- <div class="sd_picto4"></div>
69
- <p class="sd_short_subtitle"><?=$this->__('Optimal deliverability')?></p>
70
- </div>
71
- </div>
72
- </div>
73
- <div>
74
- <div>
75
- <div>
76
- <div class="sd_subtitle_separator"></div>
77
- <p><?=$this->__('Synchronize and manage all the email lists from your Magento store')?></p>
78
- </div>
79
- </div>
80
- <div>
81
- <div>
82
- <div class="sd_subtitle_separator"></div>
83
- <p><?=$this->__('NEW! Create awesome, responsive newsletters thanks to the EmailBuilder')?></p>
84
- </div>
85
- </div>
86
- <div>
87
- <div>
88
- <div class="sd_subtitle_separator"></div>
89
- <p><?=$this->__('Geolocation, openings, opening time, clicks, opt-outs...')?></p>
90
- </div>
91
- </div>
92
- <div>
93
- <div>
94
- <div class="sd_subtitle_separator"></div>
95
- <p><?=$this->__('Optimal deliverability thanks to our renowned professional routing platform')?></p>
96
- </div>
97
- </div>
98
- </div>
99
- </div>
100
- <div class="sd_separator"></div>
101
- <div class="sd_account_offer_container">
102
- <p class="sd_account"><?=$this->__('Create your account for free and start sending emails')?></p>
103
- <p class="sd_offer"><?=$this->__('No strings attached')?></p>
104
- <div class="sd_title_separator_account_offer"></div>
105
- </div>
106
- <div class="sd_info_container">
107
- <div class="sd_info_container_left">
108
- <div>
109
- <p class="sd_info_title"><?=$this->__('Why choose Mailify?')?></p>
110
- <div>
111
- <p><?=$this->__('Create your account for free and start sending emails')?></p>
112
- <p><?=$this->__('Trusted by over 20,000 users worldwide.')?></p>
113
- <p><?=$this->__('Awarded Best Emailing Solution by Bsoco Awards (an index that compares emailing solutions)')?></p>
114
- <p><?=$this->__('All you need to succeed: design, customize, send, and follow-up on your campaigns')?></p>
115
- <p><?=$this->__('A tech heldpdesk and a variety of resources to help: videos, tutorials, manuals, tips...')?></p>
116
- </div>
117
- </div>
118
- </div>
119
- <div class="sd_info_container_right">
120
- <div>
121
- <p class="sd_info_title"><?=$this->__('Need help?')?></p>
122
- <div>
123
- <p><?=$this->__('Email:')?> <?=$this->__('support@mailify.com')?></p>
124
- <p><?=$this->__('Tel:')?> <?=$this->__('+33(0) 328 328 040')?></p>
125
- <p>
126
- <?=$this->__('Website:')?>
127
- <a href="<?=$this->__('http://www.mailify.com/?utm_source=module-magento&utm_medium=plugin&utm_content=lien-sarbacane&utm_campaign=magento')?>" target="_blank"><?=$this->__('http://www.mailify.com')?></a>
128
- </p>
129
- </div>
130
- </div>
131
- </div>
132
- </div>
133
- <div id="sd_step"></div>
134
- <!-- ETAPE 1 -->
135
- <div id="sd_step1" class="sd_step <?php if(Mage::getSingleton("core/session")->getData("sd_is_user") == null && $general_configuration<2){?>sd_show_step<?php }?>">
136
- <p class="sd_step_title"><?=$this->__('How to set up the module?')?></p>
137
- <div class="sd_step_line"></div>
138
- <p class="sd_step1_instruction"><?=$this->__('Do you already have a Mailify account?')?></p>
139
- <form autocomplete="off" action="<?= Mage::helper('adminhtml')->getUrl("*/*/*/"); ?>#sd_step" method="post">
140
- <p class="sd_step1_selection">
141
- <span> <input onclick="sdUserYesNoDisplayButton('yes')" type="radio" id="sd_user_click_yes" name="sd_is_user" value="yes" <?php if(Mage::getSingleton("core/session")->getData("sd_is_user") == "yes"){?>checked="checked"<?php }?>/> <label for="sd_user_click_yes"><?=$this->__('Yes')?></label>
142
- </span> <span> <input onclick="sdUserYesNoDisplayButton('no')" type="radio" id="sd_user_click_no" name="sd_is_user" value="no" /> <label for="sd_user_click_no" <?php if(Mage::getSingleton("core/session")->getData("sd_is_user") == "no"){?>checked="checked"<?php }?>><?=$this->__('No')?></label>
143
- </span>
144
- </p>
145
- <div class="sd_step_buttons">
146
- <div class="sd_step_buttons_right">
147
- <input type="hidden" name="submit_is_user" value="1" /> <input type="hidden" name="form_key" value="<?= $this->getFormKey()?>" /> <input type="submit" class="sd_button" value="<?=$this->__('Next')?>" />
148
- </div>
149
- </div>
150