shopymind - Version 1.1.2

Version Notes

Compatibilité guest order
Prise en charge fonctionnalités de segmentation avancées
Appels vers shopymind en ajax asynchrone
Gestion des erreurs silencieuses
Test sur Magento 1.9.0.1
Suppression message d'erreur sur les droits du fichier de configuration
Modification hooking footer (before_body_end in replacement of footer)

Download this release

Release Info

Developer Jean-Sébastien
Extension shopymind
Version 1.1.2
Comparing to
See all releases


Code changes from version 1.0.2 to 1.1.2

Files changed (25) hide show
  1. app/code/local/SPM/ShopyMind/Model/Observer.php +7 -17
  2. app/code/local/SPM/ShopyMind/ShopymindClient/bin/Configuration.php +2 -1
  3. app/code/local/SPM/ShopyMind/ShopymindClient/call.php +12 -12
  4. app/code/local/SPM/ShopyMind/ShopymindClient/callback.php +1092 -1
  5. app/code/local/SPM/ShopyMind/ShopymindClient/configuration.php +5 -2
  6. app/code/local/SPM/ShopyMind/ShopymindClient/src/Client.php +24 -18
  7. app/code/local/SPM/ShopyMind/ShopymindClient/src/Reminders/BirthdayClients.php +1 -1
  8. app/code/local/SPM/ShopyMind/ShopymindClient/src/Reminders/DroppedOutCart.php +1 -1
  9. app/code/local/SPM/ShopyMind/ShopymindClient/src/Reminders/GoodClientsByAmount.php +1 -1
  10. app/code/local/SPM/ShopyMind/ShopymindClient/src/Reminders/GoodClientsByNumberOrders.php +1 -1
  11. app/code/local/SPM/ShopyMind/ShopymindClient/src/Reminders/MissingClients.php +1 -1
  12. app/code/local/SPM/ShopyMind/ShopymindClient/src/Reminders/OrdersByStatus.php +1 -1
  13. app/code/local/SPM/ShopyMind/ShopymindClient/src/Reminders/VoucherUnused.php +1 -1
  14. app/code/local/SPM/ShopyMind/ShopymindClient/src/definitions.php +2 -2
  15. app/code/local/SPM/ShopyMind/ShopymindClient/src/library/SZend/Loader.php +1 -1
  16. app/code/local/SPM/ShopyMind/controllers/Adminhtml/ConfigurationController.php +0 -3
  17. app/code/local/SPM/ShopyMind/controllers/AjaxController.php +58 -0
  18. app/code/local/SPM/ShopyMind/etc/config.xml +4 -20
  19. app/code/local/SPM/ShopyMind/sql/shopymind_setup/{mysql4-install-1.0.2.php → mysql4-install-1.1.2.php} +0 -0
  20. app/code/local/SPM/ShopyMind/sql/shopymind_setup/{upgrade-1.0.1-1.0.2.php → upgrade-1.0.0-1.1.2.php} +0 -0
  21. app/code/local/SPM/ShopyMind/sql/shopymind_setup/upgrade-1.0.1-1.1.2.php +31 -0
  22. app/code/local/SPM/ShopyMind/sql/shopymind_setup/upgrade-1.0.2-1.1.2.php +31 -0
  23. app/design/frontend/base/default/layout/shopymind.xml +1 -1
  24. app/design/frontend/base/default/template/shopymind/footer.phtml +23 -30
  25. package.xml +10 -5
app/code/local/SPM/ShopyMind/Model/Observer.php CHANGED
@@ -2,25 +2,15 @@
2
  class SPM_ShopyMind_Model_Observer extends Varien_Event_Observer {
3
  public function __construct() {
4
  }
5
-
6
- public function frontCheck($observer) {
7
-
8
- if(Mage::getSingleton('customer/session')->isLoggedIn()) {
9
- include_once(Mage::getBaseDir('base').'/app/code/local/SPM/ShopyMind/ShopymindClient/bin/Notify.php');
10
- }
11
- include_once(Mage::getBaseDir('base').'/app/code/local/SPM/ShopyMind/ShopymindClient/callback.php');
12
- ShopymindClient_Callback::checkNewCart();
13
- }
14
  public function newOrderObserver($observer) {
15
  include_once(Mage::getBaseDir('base').'/app/code/local/SPM/ShopyMind/ShopymindClient/callback.php');
16
- $m= new Mage;
17
- $mageVersion=$m->getVersion();
18
- $order = $observer->getEvent()->getInvoice()->getOrder();
19
- ShopymindClient_Callback::checkNewOrder($order);
20
- }
21
- public function checkIsSPMUser($observer)
22
- {
23
-
24
  }
25
  public static function getUserLocale($id_customer,$store_id) {
26
  $locale_shop = Mage::getStoreConfig('general/locale/code', $store_id);
2
  class SPM_ShopyMind_Model_Observer extends Varien_Event_Observer {
3
  public function __construct() {
4
  }
 
 
 
 
 
 
 
 
 
5
  public function newOrderObserver($observer) {
6
  include_once(Mage::getBaseDir('base').'/app/code/local/SPM/ShopyMind/ShopymindClient/callback.php');
7
+ try {
8
+ $m= new Mage;
9
+ $mageVersion=$m->getVersion();
10
+ $order = $observer->getEvent()->getInvoice()->getOrder();
11
+ ShopymindClient_Callback::checkNewOrder($order);
12
+ }catch (Exception $e) {
13
+ }
 
14
  }
15
  public static function getUserLocale($id_customer,$store_id) {
16
  $locale_shop = Mage::getStoreConfig('general/locale/code', $store_id);
app/code/local/SPM/ShopyMind/ShopymindClient/bin/Configuration.php CHANGED
@@ -195,6 +195,7 @@ class ShopymindClient_Configuration {
195
  * @return boolean
196
  */
197
  public function saveConfig() {
 
198
  global $SHOPYMIND_CLIENT_CONFIGURATION;
199
  $lastConfig = require dirname(__FILE__) . '/../configuration.php';
200
 
@@ -207,7 +208,7 @@ class ShopymindClient_Configuration {
207
  }
208
 
209
  if ($this->getApiUrl() !== null) {
210
- $lastConfig['api']['url'] = $this-getApiUrl();
211
  }
212
 
213
  $content = "<?php\n"
195
  * @return boolean
196
  */
197
  public function saveConfig() {
198
+ return true;
199
  global $SHOPYMIND_CLIENT_CONFIGURATION;
200
  $lastConfig = require dirname(__FILE__) . '/../configuration.php';
201
 
208
  }
209
 
210
  if ($this->getApiUrl() !== null) {
211
+ $lastConfig['api']['url'] = $this->getApiUrl();
212
  }
213
 
214
  $content = "<?php\n"
app/code/local/SPM/ShopyMind/ShopymindClient/call.php CHANGED
@@ -18,20 +18,20 @@ if ($server->isValid() === true) {
18
  $server->sendResponse(array('version' => $config['version']));
19
  }
20
  elseif ($server->getTypeRequest() === 'orderStatus') {
21
- require dirname(__FILE__) . '/callback.php';
22
  if (method_exists('ShopymindClient_Callback', 'getOrdersStatus')) {
23
  $server->sendResponse(array('status' => ShopymindClient_Callback::getOrdersStatus()), true);
24
  }
25
  }
26
  elseif ($server->getTypeRequest() === 'getTimezones') {
27
- require dirname(__FILE__) . '/callback.php';
28
  if (method_exists('ShopymindClient_Callback', 'getTimezones')) {
29
  $params = $server->retrieveParams();
30
  $server->sendResponse(array('lastUpdateTimezone' => date('Y-m-d H:i:s'), 'timezones' => ShopymindClient_Callback::getTimezones($params['lastUpdate'])), true);
31
  }
32
  }
33
  elseif ($server->getTypeRequest() === 'dailyUpdate') {
34
- require dirname(__FILE__) . '/callback.php';
35
  $response = array();
36
  $params = $server->retrieveParams();
37
  if (method_exists('ShopymindClient_Callback', 'deleteUnusedVouchers')) {
@@ -40,7 +40,7 @@ if ($server->isValid() === true) {
40
  $server->sendResponse($response, true);
41
  }
42
  elseif ($server->getTypeRequest() === 'getTestData') {
43
- require dirname(__FILE__) . '/callback.php';
44
  if (method_exists('ShopymindClient_Callback', 'getTestData')) {
45
  $params = $server->retrieveParams();
46
  $server->sendResponse(array('testData' => ShopymindClient_Callback::getTestData((isset($params['lang']) ? $params['lang']:false))), true);
@@ -48,14 +48,14 @@ if ($server->isValid() === true) {
48
  $server->sendResponse($response, true);
49
  }
50
  elseif ($server->getTypeRequest() === 'generateVouchers') {
51
- require dirname(__FILE__) . '/callback.php';
52
  if (method_exists('ShopymindClient_Callback', 'generateVouchers')) {
53
  $params = $server->retrieveParams();
54
  $server->sendResponse(array('vouchers' => ShopymindClient_Callback::generateVouchers($params['voucherInfos'],$params['voucherEmails'])), true);
55
  }
56
  }
57
  elseif ($server->getTypeRequest() === 'generateKeysAccess') {
58
- require dirname(__FILE__) . '/callback.php';
59
  if (method_exists('ShopymindClient_Callback', 'generateKeysAccess')) {
60
  $params = $server->retrieveParams();
61
  ShopymindClient_Callback::generateKeysAccess($params['keysAccess']);
@@ -63,35 +63,35 @@ if ($server->isValid() === true) {
63
  }
64
  }
65
  elseif ($server->getTypeRequest() === 'getCountries') {
66
- require dirname(__FILE__) . '/callback.php';
67
  if (method_exists('ShopymindClient_Callback', 'getCountries')) {
68
  $params = $server->retrieveParams();
69
  $server->sendResponse(array('countries' => ShopymindClient_Callback::getCountries()), true);
70
  }
71
  }
72
  elseif ($server->getTypeRequest() === 'getCurrencies') {
73
- require dirname(__FILE__) . '/callback.php';
74
  if (method_exists('ShopymindClient_Callback', 'getCurrencies')) {
75
  $params = $server->retrieveParams();
76
  $server->sendResponse(array('currencies' => ShopymindClient_Callback::getCurrencies()), true);
77
  }
78
  }
79
  elseif ($server->getTypeRequest() === 'getCustomerGroups') {
80
- require dirname(__FILE__) . '/callback.php';
81
  if (method_exists('ShopymindClient_Callback', 'getCustomerGroups')) {
82
  $params = $server->retrieveParams();
83
  $server->sendResponse(array('customerGroups' => ShopymindClient_Callback::getCustomerGroups()), true);
84
  }
85
  }
86
  elseif ($server->getTypeRequest() === 'getShopLangs') {
87
- require dirname(__FILE__) . '/callback.php';
88
  if (method_exists('ShopymindClient_Callback', 'getShopLangs')) {
89
  $params = $server->retrieveParams();
90
  $server->sendResponse(array('lastUpdateTimezone' => date('Y-m-d H:i:s'), 'timezones' => ShopymindClient_Callback::getTimezones($params['lastUpdate'])), true);
91
  }
92
  }
93
  elseif ($server->getTypeRequest() === 'getProducts') {
94
- require dirname(__FILE__) . '/callback.php';
95
  if (method_exists('ShopymindClient_Callback', 'getProducts')) {
96
  $params = $server->retrieveParams();
97
  $server->sendResponse(array('articles' => ShopymindClient_Callback::getProducts($params['lang'],(isset($params['products']) ? $params['products']:false),(isset($params['random']) ? $params['random']:false),(isset($params['maxProducts']) ? $params['maxProducts']:null))), true);
@@ -124,4 +124,4 @@ if ($server->isValid() === true) {
124
  }
125
  }
126
 
127
- $server->sendResponse(array(), false);
18
  $server->sendResponse(array('version' => $config['version']));
19
  }
20
  elseif ($server->getTypeRequest() === 'orderStatus') {
21
+ require_once dirname(__FILE__) . '/callback.php';
22
  if (method_exists('ShopymindClient_Callback', 'getOrdersStatus')) {
23
  $server->sendResponse(array('status' => ShopymindClient_Callback::getOrdersStatus()), true);
24
  }
25
  }
26
  elseif ($server->getTypeRequest() === 'getTimezones') {
27
+ require_once dirname(__FILE__) . '/callback.php';
28
  if (method_exists('ShopymindClient_Callback', 'getTimezones')) {
29
  $params = $server->retrieveParams();
30
  $server->sendResponse(array('lastUpdateTimezone' => date('Y-m-d H:i:s'), 'timezones' => ShopymindClient_Callback::getTimezones($params['lastUpdate'])), true);
31
  }
32
  }
33
  elseif ($server->getTypeRequest() === 'dailyUpdate') {
34
+ require_once dirname(__FILE__) . '/callback.php';
35
  $response = array();
36
  $params = $server->retrieveParams();
37
  if (method_exists('ShopymindClient_Callback', 'deleteUnusedVouchers')) {
40
  $server->sendResponse($response, true);
41
  }
42
  elseif ($server->getTypeRequest() === 'getTestData') {
43
+ require_once dirname(__FILE__) . '/callback.php';
44
  if (method_exists('ShopymindClient_Callback', 'getTestData')) {
45
  $params = $server->retrieveParams();
46
  $server->sendResponse(array('testData' => ShopymindClient_Callback::getTestData((isset($params['lang']) ? $params['lang']:false))), true);
48
  $server->sendResponse($response, true);
49
  }
50
  elseif ($server->getTypeRequest() === 'generateVouchers') {
51
+ require_once dirname(__FILE__) . '/callback.php';
52
  if (method_exists('ShopymindClient_Callback', 'generateVouchers')) {
53
  $params = $server->retrieveParams();
54
  $server->sendResponse(array('vouchers' => ShopymindClient_Callback::generateVouchers($params['voucherInfos'],$params['voucherEmails'])), true);
55
  }
56
  }
57
  elseif ($server->getTypeRequest() === 'generateKeysAccess') {
58
+ require_once dirname(__FILE__) . '/callback.php';
59
  if (method_exists('ShopymindClient_Callback', 'generateKeysAccess')) {
60
  $params = $server->retrieveParams();
61
  ShopymindClient_Callback::generateKeysAccess($params['keysAccess']);
63
  }
64
  }
65
  elseif ($server->getTypeRequest() === 'getCountries') {
66
+ require_once dirname(__FILE__) . '/callback.php';
67
  if (method_exists('ShopymindClient_Callback', 'getCountries')) {
68
  $params = $server->retrieveParams();
69
  $server->sendResponse(array('countries' => ShopymindClient_Callback::getCountries()), true);
70
  }
71
  }
72
  elseif ($server->getTypeRequest() === 'getCurrencies') {
73
+ require_once dirname(__FILE__) . '/callback.php';
74
  if (method_exists('ShopymindClient_Callback', 'getCurrencies')) {
75
  $params = $server->retrieveParams();
76
  $server->sendResponse(array('currencies' => ShopymindClient_Callback::getCurrencies()), true);
77
  }
78
  }
79
  elseif ($server->getTypeRequest() === 'getCustomerGroups') {
80
+ require_once dirname(__FILE__) . '/callback.php';
81
  if (method_exists('ShopymindClient_Callback', 'getCustomerGroups')) {
82
  $params = $server->retrieveParams();
83
  $server->sendResponse(array('customerGroups' => ShopymindClient_Callback::getCustomerGroups()), true);
84
  }
85
  }
86
  elseif ($server->getTypeRequest() === 'getShopLangs') {
87
+ require_once dirname(__FILE__) . '/callback.php';
88
  if (method_exists('ShopymindClient_Callback', 'getShopLangs')) {
89
  $params = $server->retrieveParams();
90
  $server->sendResponse(array('lastUpdateTimezone' => date('Y-m-d H:i:s'), 'timezones' => ShopymindClient_Callback::getTimezones($params['lastUpdate'])), true);
91
  }
92
  }
93
  elseif ($server->getTypeRequest() === 'getProducts') {
94
+ require_once dirname(__FILE__) . '/callback.php';
95
  if (method_exists('ShopymindClient_Callback', 'getProducts')) {
96
  $params = $server->retrieveParams();
97
  $server->sendResponse(array('articles' => ShopymindClient_Callback::getProducts($params['lang'],(isset($params['products']) ? $params['products']:false),(isset($params['random']) ? $params['random']:false),(isset($params['maxProducts']) ? $params['maxProducts']:null))), true);
124
  }
125
  }
126
 
127
+ $server->sendResponse(array(), false);
app/code/local/SPM/ShopyMind/ShopymindClient/callback.php CHANGED
@@ -1 +1,1092 @@
1
- <?php function IaUzFRekjRaayyJgBsTD($ANGueYGZVX){$r=base64_decode("YmFzZTY0X2RlY29kZSgkQU5HdWVZR1pWWCk=");return eval("return $r;");} eval('?>'.IaUzFRekjRaayyJgBsTD('PD9waHAgIHJlcXVpcmVfb25jZSBkaXJuYW1lKF9fRklMRV9fKS4nLy4uLy4uLy4uLy4uLy4uL01hZ2UucGhwJzsgIHVtYXNrKDApOyAgTWFnZTo6YXBwKCk7ICBpZihmaWxlX2V4aXN0cyhNYWdlOjpnZXRCYXNlRGlyKCdiYXNlJykuJy9hcHAvY29kZS9sb2NhbC9TUE0vU2hvcHlNaW5kL1Nob3B5bWluZENsaWVudC9jYWxsYmFja19vdmVycmlkZ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ZGApICAgICAgICAgICAgV0hFUkUgIGBvcmRlcl9hZGRyZXNzYC5gZW1haWxgIElOKCInLihpbXBsb2RlKCciLCAiJywgKGFycmF5KSRpZCkpLiciKSBBTkQgYG9yZGVyX2FkZHJlc3NgLmBhZGRyZXNzX3R5cGVgID0gImJpbGxpbmciICAgICAgICAgICAgR1JPVVAgQlkgYG9yZGVyX2FkZHJlc3NgLmBlbWFpbGAgICAgICAgICAgICBPUkRFUiBCWSBgb3JkZXJgLmBlbnRpdHlfaWRgIEFTQyc7ICAgICAgICAgICB9ICAgICAgICAgIH0gICAgICAgICAgJHJlc3VsdHMgPSAkcmVhZENvbm5lY3Rpb24tPmZldGNoQWxsKCRxdWVyeSk7ICAgICAgICAgIGlmKCRyZXN1bHRzICYmIGlzX2FycmF5KCRyZXN1bHRzKSAmJiBzaXplb2YoJHJlc3VsdHMpKSB7ICAgICAgICAgICAgICBmb3JlYWNoKCRyZXN1bHRzIGFzICRyb3cpIHsgICAgICAgICAgICAgICAkc3Vic2NyaWJlciA9IE1hZ2U6OmdldE1vZGVsKCduZXdzbGV0dGVyL3N1YnNjcmliZXInKS0+bG9hZEJ5RW1haWwoJHJvd1snZW1haWwnXSk7ICAgICAgICAgICAgICAgICAgJHJldHVybltdID0gYXJyYXkoICAgICAgICAgICAgICAgICAgICAnaWRfY3VzdG9tZXInICA9PiAkcm93WydlbnRpdHlfaWQnXSwgICAgICAgICAgICAgICAgICAgICdvcHRpbicgICA9PiAkc3Vic2NyaWJlci0+aXNTdWJzY3JpYmVkKCksICAgICAgICAgICAgICAgICAgICAgICAgICAnY3VzdG9tZXJfc2luY2UnID0+ICRyb3dbJ2NyZWF0ZWRfYXQnXSwgICAgICAgICAgICAgICAgICAgICAgICAgICdsYXN0X25hbWUnICAgICAgPT4gJHJvd1snbGFzdG5hbWUnXSwgICAgICAgICAgICAgICAgICAgICAgICAgICdmaXJzdF9uYW1lJyAgICAgPT4gJHJvd1snZmlyc3RuYW1lJ10sICAgICAgICAgICAgICAgICAgICAgICAgICAnZW1haWxfYWRkcmVzcycgID0+ICRyb3dbJ2VtYWlsJ10sICAgICAgICAgICAgICAgICAgICAgICAgICAncGhvbmUxJyAgICA9PiAoaXNzZXQoJHJvd1sncGhvbmUnXSkgJiYgJHJvd1sncGhvbmUnXT8kcm93WydwaG9uZSddOicnKSwgICAgICAgICAgICAgICAgICAgICAgICAgICdwaG9uZTInICAgID0+ICcnLCAgICAgICAgICAgICAgICAgICAgICAgICAgJ2dlbmRlcicgICAgPT4gKGlzc2V0KCRyb3dbJ2dlbmRlcl9pZCddKSAmJiAoJHJvd1snZ2VuZGVyX2lkJ10gPT0gMSB8fCAkcm93WydnZW5kZXJfaWQnXSA9PSAyKT8kcm93WydnZW5kZXJfaWQnXTowKSwgICAgICAgICAgICAgICAgICAgICAgICAgICdiaXJ0aGRheScgICA9PiAoaXNzZXQoJHJvd1snYmlydGhkYXknXSkgPyAkcm93WydiaXJ0aGRheSddIDogMCksICAgICAgICAgICAgICAgICAgICAgICAgICAnbG9jYWxlJyAgICAgICAgPT4gc2VsZjo6Z2V0VXNlckxvY2FsZSgkcm93WydlbnRpdHlfaWQnXSwkcm93WydzdG9yZV9pZCddLCRyb3dbJ2NvdW50cnlfY29kZSddKSwgICAgICAgICAgICAgICAgICAgICAgICAgICdkYXRlX2xhc3Rfb3JkZXInICA9PiBzZWxmOjpnZXREYXRlTGFzdE9yZGVyKCRyb3dbJ2VudGl0eV9pZCddKSwgICAgICAgICAgICAgICAgICAgICAgICAgICduYl9vcmRlcicgID0+IHNlbGY6OmNvdW50Q3VzdG9tZXJPcmRlcigkcm93WydlbnRpdHlfaWQnXSksICAgICAgICAgICAgICAgICAgICAgICAgICAnc3VtX29yZGVyJyAgPT4gc2VsZjo6c3VtQ3VzdG9tZXJPcmRlcigkcm93WydlbnRpdHlfaWQnXSksICAgICAgICAgICAgICAgICAgICAgICAnZ3JvdXBzJyAgPT4gYXJyYXkoJHJvd1snZ3JvdXBfaWQnXSksICAgICAgIC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gICAgICAgICAgICAgICBMRUZUIEpPSU4gYCcuJHRhYmxlUHJlZml4LidkaXJlY3RvcnlfY291bnRyeV9yZWdpb25gIEFTIGBjdXN0b21lcl9kZWZhdWx0X2JpbGxpbmdfc3RhdGVgIE9OKGBjdXN0b21lcl9kZWZhdWx0X2JpbGxpbmdfc3RhdGVgLmByZWdpb25faWRgID0gYG9yZGVyX2FkZHJlc3NgLmByZWdpb25faWRgKSAgICAgICAgICAgICAgIFdIRVJFIGBvcmRlcl9wcmltYXJ5YC5gY3VzdG9tZXJfaXNfZ3Vlc3RgID0gMSBBTkQgREFURV9GT1JNQVQoYG9yZGVyX3ByaW1hcnlgLmBjdXN0b21lcl9kb2JgLCIlbS0lZCIpID0gIicuJGJpcnRoRGF0ZS4nIiBBTkQgJy4kdGltZXpvbmVzV2hlcmUuJyAgICAgICAgICAgICAgIEdST1VQIEJZIGBvcmRlcl9wcmltYXJ5YC5gY3VzdG9tZXJfZW1haWxgJzsgICAgICAgICAgICRyZXN1bHRzID0gJHJlYWRDb25uZWN0aW9uLT5mZXRjaEFsbCgkcXVlcnkpOyAgICAgICAgICBpZigkcmVzdWx0cyAmJiBpc19hcnJheSgkcmVzdWx0cykgJiYgc2l6ZW9mKCRyZXN1bHRzKSkgeyAgICAgICAgICAgICAgIGZvcmVhY2goJHJlc3VsdHMgYXMgJHJvdykgeyAgICAgICAgICAgICAgICAgICAkcmV0dXJuW10gPSBhcnJheSggICAgICAgICAgICAgICAgICAgICAgICAgICAnY3VzdG9tZXInID0+IHNlbGY6OmdldFVzZXIoJHJvd1snY3VzdG9tZXJfZW1haWwnXSkgICAgICAgICAgICAgICAgICAgKTsgICAgICAgICAgICAgICB9ICAgICAgICAgICB9ICAgICAgICAgIH0gICAgICAgICAgICByZXR1cm4gKCRqdXN0Q291bnQgPyBhcnJheSgnY291bnQnPT5zaXplb2YoJHJldHVybikpIDogJHJldHVybik7ICAgICAgfSAgICAgICAgICAgICAgcHVibGljIHN0YXRpYyBmdW5jd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UoYmFzZW5hbWUoJF9TRVJWRVJbJ1NDUklQVF9OQU1FJ10pLicvJywnJywkcHJvZHVjdC0+Z2V0U21hbGxJbWFnZVVybCgyMDAsMjAwKSk7ICAgICAgICB9IGNhdGNoIChFeGNlcHRpb24gJGUpIHsgICAgICAgICAgICAkaW1hZ2VfdXJsID0gJyc7ICAgICAgICB9ICAgICAgICAgICAgICAgICAgICAgICAgICAkcHJvZHVjdF91cmwgPSBzdHJfcmVwbGFjZShiYXNlbmFtZSgkX1NFUlZFUlsnU0NSSVBUX05BTUUnXSkuJy8nLCcnLCRwcm9kdWN0LT5nZXRQcm9kdWN0VXJsKGZhbHNlKSk7ICAgICAgICAgICAgICAgICAgICAgICAgICAkcmV0dXJuUHJvZHVjdHNbXSA9IGFycmF5KCAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAnZGVzY3JpcHRpb24nID0+ICRyb3cyWyduYW1lJ10sICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICdxdHknID0+ICRyb3cyWydxdHknXSwgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJ3ByaWNlJyA9PiAkcm93MlsncHJpY2VfaW5jbF90YXgnXSwgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJ2ltYWdlX3VybCcgPT4gJGltYWdlX3VybCwgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJ3Byb2R1Y3RfdXJsJyA9PiAkcHJvZHVjdF91cmwgICAgICAgICAgICAgICAgICAgICAgICAgICk7ICAgICAgICAgICAgICAgICAgICAgIH0gICAgICAgICAgICAgICAgICB9ICAgICAgICAgICAgICAgICAgaWYoc2l6ZW9mKCRyZXR1cm5Qcm9kdWN0cykpICAgICAgICAgICAgICAgICAgICAgICRyZXR1cm5bXSA9IGFycmF5KCAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICdzdW1fY2FydCcgICAgICA9PiAoJHJvd1snYmFzZV9ncmFuZF90b3RhbCddLyRyb3dbJ3N0b3JlX3RvX2Jhc2VfcmF0ZSddKSwgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAnY3VycmVuY3knICAgICAgPT4gJHJvd1snYmFzZV9jdXJyZW5jeV9jb2RlJ10sICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJ3RheF9yYXRlJyAgICAgID0+ICRyb3dbJ3N0b3JlX3RvX2Jhc2VfcmF0ZSddLCAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICdpZF9jYXJ0JyAgICAgICA9PiAkcm93WydlbnRpdHlfaWQnXSwgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAnbGlua19jYXJ0JyAgICAgID0+IHN0cl9yZXBsYWNlKGJhc2VuYW1lKCRfU0VSVkVSWydTQ1JJUFRfTkFNRSddKS4nLycsJycsTWFnZTo6Z2V0VXJsKCdjaGVja291dC9jYXJ0JyxhcnJheSgnX25vc2lkJz0+dHJ1ZSkpKSwgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAnYXJ0aWNsZXMnICAgICAgPT4gJHJldHVyblByb2R1Y3RzLCAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICdjdXN0b21lcicgID0+IHNlbGY6OmdldFVzZXIoKCRyb3dbJ2N1c3RvbWVyX2lkJ10/JHJvd1snY3VzdG9tZXJfaWQnXTokcm93WydjdXN0b21lcl9lbWFpbCddKSx0cnVlKSAgICAgICAgICAgICAgICAgICAgICApOyAgICAgICAgICAgICAgICAgc2VsZjo6c3RvcExhbmdFbXVsYXRpb24oKTsgICAgICAgICAgICAgIH0gICAgICAgICAgfSAgICAgICAgICByZXR1cm4gKCRqdXN0Q291bnQgPyBhcnJheSgnY291bnQnPT5zaXplb2YoJHJldHVybikpIDogJHJldHVybik7ICAgICAgfSAgICAgICAgICAgICAgcHVibGljIHN0YXRpYyBmdW5jdGlvbiBnZXRHb29kQ2xpZW50c0J5QW1vdW50KCRkYXRlUmVmZXJlbmNlLCAkdGltZXpvbmVzLCAkYW1vdW50LCAkYW1vdW50TWF4LCA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wgICAgICAgICAgICAgIEdST1VQIEJZIGBvcmRlcl9wcmltYXJ5YC5gY3VzdG9tZXJfZW1haWxgICAgICAgICBIQVZJTkcgYFRvdGFsYCA+PSAnLihpbnQpJG5iT3JkZXIuJyAgICAgICAgJy4oJG5iT3JkZXJNYXggPyAnIEFORCBgVG90YWxgIDw9ICcuKGludCkkbmJPcmRlck1heCA6ICcnKTsgICAgICAgICAgJHJlc3VsdHMgPSAkcmVhZENvbm5lY3Rpb24tPmZldGNoQWxsKCRxdWVyeSk7ICAgICAgICAgICAgICBpZigkcmVzdWx0cyAmJiBpc19hcnJheSgkcmVzdWx0cykgJiYgc2l6ZW9mKCRyZXN1bHRzKSkgeyAgICAgICAgICAgICAgZm9yZWFjaCgkcmVzdWx0cyBhcyAkcm93KSB7ICAgICAgICAgICAgICAgICAgJHJldHVybltdID0gYXJyYXkoICAgICAgICAgICAgICAgICAgICAgICAgICAnY3VzdG9tZXInICA9PiBzZWxmOjpnZXRVc2VyKCgkcm93WydjdXN0b21lcl9pZCddPyRyb3dbJ2N1c3RvbWVyX2lkJ106JHJvd1snY3VzdG9tZXJfZW1haWwnXSkpICAgICAgICAgICAgICAgICAgKTsgICAgICAgICAgICAgIH0gICAgICAgICAgfSAgICAgICAgICByZXR1cm4gKCRqdXN0Q291bnQgPyBhcnJheSgnY291bnQnPT5zaXplb2YoJHJldHVybikpIDogJHJldHVybik7ICAgICAgfSAgICAgICAgICAgICAgcHVibGljIHN0YXRpYyBmdW5jdGlvbiBnZXRNaXNzaW5nQ2xpZW50cygkZGF0ZVJlZmVyZW5jZSwgJHRpbWV6b25lcywgJG5iRGF5cyA9IDAsICRyZWxhdW5jaE9sZGVyID0gZmFsc2UsJGp1c3RDb3VudCA9IGZhbHNlKSB7ICAgICAgICAgIGlmKGNsYXNzX2V4aXN0cygnU2hvcHltaW5kQ2xpZW50X0NhbGxiYWNrT3ZlcnJpZGUnLCBmYWxzZSkgJiYgbWV0aG9kX2V4aXN0cygnU2hvcHltaW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3VsdHMgJiYgaXNfYXJyYXkoJHJlc3VsdHMpICYmIHNpemVvZigkcmVzdWx0cykpIHsgICAgICAgICAgICAgIGZvcmVhY2goJHJlc3VsdHMgYXMgJHJvdykgeyAgICAgICAgICAgICAgIGlmKCEkcm93WydlbnRpdHlfaWQnXSkgY29udGludWU7ICAgICAgICAgICAgICAgICAgJHJldHVybltdID0gYXJyYXkoICAgICAgICAgICAgICAgICAgICAgICAgICAnY3VzdG9tZXInICA9PiBzZWxmOjpnZXRVc2VyKCRyb3dbJ2VudGl0eV9pZCddKSAgICAgICAgICAgICAgICAgICk7ICAgICAgICAgICAgICB9ICAgICAgICAgIH0gICAgICAgICAgICByZXR1cm4gKCRqdXN0Q291bnQgPyBhcnJheSgnY291bnQnPT5zaXplb2YoJHJldHVybikpIDogJHJldHVybik7ICAgICAgfSAgICAgICAgICAgICAgcHVibGljIHN0YXRpYyBmdW5jdGlvbiBnZXRPcmRlcnNCeVN0YXR1cygkZGF0ZVJlZmVyZW5jZSwgJHRpbWV6b25lcywgJG5iRGF5cywgJGlkU3RhdHVzLCRqdXN0Q291bnQgPSBmYWxzZSkgeyAgICAgICAgICBpZihjbGFzc19leGlzdHMoJ1Nob3B5bWluZENsaWVudF9DYWxsYmFja092ZXJyaWRlJywgZmFsc2UpICYmIG1ldGhvZF9leGlzdHMoJ1Nob3B5bWluZENsaWVudF9DYWxsYmFja092ZXJyaWRlJyxfX0ZVTkNUSU9OX18pKSByZXR1cm4gY2FsbF91c2VyX2Z1bmNfYXJyYXkoYXJyYXkoJ1Nob3B5bWluZENsaWVudF9DYWxsYmFja092ZXJyaWRlJywgX19GVU5DVElPTl9fKSwgZnVuY19nZXRfYXJncygpKTsgICAgICAgJHJldHVybiA9IGFycmF5KCk7ICAgICAgICAgICR0YWJsZVByZWZpeCA9IE1hZ2U6OmdldENvbmZpZygpLT5nZXRUYWJsZVByZWZpeCgpOyAgICAgICAgICAkcmVzb3VyY2UgPSBNYWdlOjpnZXRTaW5nbGV0b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gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJ3F0eScgPT4gJHJvdzJbJ3F0eV9pbnZvaWNlZCddLCAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAncHJpY2UnID0+ICRyb3cyWydwcmljZV9pbmNsX3RheCddLCAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAnaW1hZ2VfdXJsJyA9PiAkaW1hZ2VfdXJsLCAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAncHJvZHVjdF91cmwnID0+ICRwcm9kdWN0X3VybCAgICAgICAgICAgICAgICAgICAgICAgICAgKTsgICAgICAgICAgICAgICAgICAgICAgfSAgICAgICAgICAgICAgICAgIH0gICAgICAgICAgICAgICAgICBpZihzaXplb2YoJHJldHVyblByb2R1Y3RzKSkgICAgICAgICAgICAgICAgICAgICAgJHJldHVybltdID0gYXJyYXkoICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJ2N1cnJlbmN5JyAgICAgICA9PiAkcm93WydvcmRlcl9jdXJyZW5jeV9jb2RlJ10sICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJ3RvdGFsX2Ftb3VudCcgICA9PiAkcm93WydiYXNlX2dyYW5kX3RvdGFsJ10sICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJ2FydGljbGVzJyAgICAgICA9PiAkcmV0dXJuUHJvZHVjdHMsICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJ2lkX29yZGVyJyAgID0+ICRyb3dbJ2VudGl0eV9pZCddLCAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICdjdXN0b21lcicgID0+IHNlbGY6OmdldFVzZXIoKCRyb3dbJ2N1c3RvbWVyX2lkJ10/JHJvd1snY3VzdG9tZXJfaWQnXTokcm93WydjdXN0b21lcl9lbWFpbCddKSkgICAgICAgICAgICAgICAgICAgICAgKTsgICAgICAgICAgICAgICAgICAgc2VsZjo6c3RvcExhbmdFbXVsYXRpb24oKTsgICAgICAgICAgICAgIH0g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ikpKSkpICAgICAgICAgIC0+c2V0VXNlc1BlckN1c3RvbWVyKCcxJykgICAgICAgICAgLT5zZXRJc0FjdGl2ZSgnMScpICAgICAgICAgIC0+c2V0U3RvcFJ1bGVzUHJvY2Vzc2luZygnMCcpICAgICAgICAgIC0+c2V0SXNBZHZhbmNlZCgnMScpICAgICAgICAgIC0+c2V0UHJvZHVjdElkcyhOVUxMKSAgICAgICAgICAtPnNldFNvcnRPcmRlcignMCcpOyAgICAgICAgICBpZigkdHlwZSA9PSAncGVyY2VudCcpIHsgICAgICAgICAgICAgICRjb3Vwb24tPnNldFNpbXBsZUFjdGlvbignYnlfcGVyY2VudCcpICAgICAgICAgICAgICAtPnNldERpc2NvdW50QW1vdW50KCRhbW91bnQpICAgICAgICAgICAgICAtPnNldERpc2NvdW50UXR5KE5VTEwpICAgICAgICAgICAgICAtPnNldFNpbXBsZUZyZWVTaGlwcGluZygnMCcpOyAgICAgICAgICB9aWYoJHR5cGUgPT0gJ2Ftb3VudCcpIHsgICAgICAgICAgICAgICRjb3Vwb24tPnNldFNpbXBsZUFjdGlvbignY2FydF9maXhlZCcpICAgICAgICAgICAgICAtPnNldERpc2NvdW50QW1vdW50KCRhbW91bnQpICAgICAgICAgICAgICAtPnNldERpc2NvdW50UXR5KE5VTEwpICAgICAgICAgICAgICAtPnNldFNpbXBsZUZyZWVTaGlwcGluZygnMCcpOyAgICAgICAgICB9ZWxzZWlmKCR0eXBlID09ICdzaGlwcGluZycpIHsgICAgICAgICAgICAgICRjb3Vwb24tPnNldFNpbXBsZUZyZWVTaGlwcGluZygxKTsgICAgICAgICAgfSAgICAgICAgICAkY291cG9uLT5zZXREaXNjb3VudFN0ZXAoJzAnKSAgICAgICAgICAtPnNldEFwcGx5VG9TaGlwcGluZygnMCcpICAgICAgICAgIC0+c2V0VGltZXNVc2VkKCcwJykgICAgICAgICAgLT5zZXRJc1JzcygnMCcpICAgICAgICAgIC0+c2V0Q291cG9uVHlwZSgnMicpICAgICAgICAgIC0+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IEZST00gYCcuJHRhYmxlUHJlZml4LidzcG1jYXJ0b29yZGVyYCBXSEVSRSAoYHZvdWNoZXJfbnVtYmVyYCA9ICInLmFkZHNsYXNoZXMoJHZvdWNoZXIpLiciKSBBTkQgYGlzX2NvbnZlcnRlZGAgPSAwIEFORCBgZGF0ZV91cGRgID49IERBVEVfU1VCKCInLmRhdGUoJ1ktbS1kIEg6aTpzJykuJyIsIElOVEVSVkFMIDEgTU9OVEgpIE9SREVSIEJZIGBkYXRlX2FkZGAgREVTQycpOyAgICAgICAgICAgICAgICAgICAgICAgICAgZWxzZSBicmVhazsgICAgICAgICAgICAgICAgICAgICAgfSAgICAgICAgICAgICAgICAgIH0gICAgICAgICAgICAgIH0gICAgICAgICAgICAgIGlmKCRzcG1fa2V5ICYmIGlzc2V0KCRzcG1fa2V5WydzcG1fa2V5J10pICYmICRzcG1fa2V5WydzcG1fa2V5J10pICRfR0VUWydzcG1fa2V5J10gPSAkc3BtX2tleVsnc3BtX2tleSddOyAgICAgICAgICAgICAgZWxzZSB7ICAgICAgICAgICAgICAgICAgJGNvb2tpZS0+c2V0KCdzcG1rZXljaGVja2VkJywgJGtleV9jaGVja2VkLDApOyAgICAgICAgICAgICAgfSAgICAgICAgICB9ICAgICAgICAgIGlmKGlzc2V0KCRfR0VUWydzcG1fa2V5J10pIHx8ICRjb29raWUtPmdldCgnc3BtY2FydG9vcmRlcicpIHx8ICRjb29raWUtPmdldCgnc3BtY2FydG9vcmRlcl9wZXJzaXN0ZW50JykpIHsgICAgICAgICAgICAgICRxdW90ZSA9IE1hZ2U6OmdldFNpbmdsZXRvbignY2hlY2tvdXQvY2FydCcpLT5nZXRRdW90ZSgpOyAgICAgICAgICAgICAgaWYoISRjYXJ0X2lkIHx8ICghJGN1c3RvbWVyX2lkICYmICEkY3VzdG9tZXJfZW1haWwpIHx8ICEkcXVvdGUtPmdldEdyYW5kVG90YWwoKSkgeyAgICAgICAgICAgICAgICAgIGlmKGlzc2V0KCRfR0VUWydzcG1fa2V5J10pKSB7ICAgICAgICAgICAgICAgICAgICAgICRjb29raWUtPnNldCgnc3BtY2FydG9vcmRlcl9wZXJzaXN0ZW50JywgJF9HRVRbJ3NwbV9rZXknXSwgNjU3MDAwKTsgICAgICAgICAgICAgICAgICAgICAgJGNvb2tpZS0+c2V0KCdzcG1jYXJ0b29yZGVyJywgJF9HRVRbJ3NwbV9rZXknXSwwKTsgICAgICAgICAgICAgICAgICB9ICAgICAgICAgICAgICB9ZWxzZSB7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZigkY29va2llLT5nZXQoJ3NwbWxhc3RjYXJ0cmVnaXN0ZXInKSAmJiAkY29va2llLT5nZXQoJ3NwbWxhc3RjYXJ0cmVnaXN0ZXInKSA9PSAkc3BtX2tleS4kY2FydF9pZCkgcmV0dXJuOyAgICAgICAgICAgICAgICAgICR0YWJsZVByZWZpeCA9IE1hZ2U6OmdldENvbmZpZygpLT5nZXRUYWJsZVByZWZpeCgpOyAgICAgICAgICAgICAgICAgICAgaWYoaXNzZXQoJF9HRVRbJ3NwbV9rZXknXSkpICAgICAgICAgICAgICAgICAgICAgICRzcG1fa2V5ID0gJF9HRVRbJ3NwbV9rZXknXTsgICAgICAgICAgICAgICAgICBlbHNlaWYoJGNvb2tpZS0+Z2V0KCdzcG1jYXJ0b29yZGVyJykgIT0gJycpICAgICAgICAgICAgICAgICAgICAgICRzcG1fa2V5ID0gJGNvb2tpZS0+Z2V0KCdzcG1jYXJ0b29yZGVyJyk7ICAgICAgICAgICAgICAgICAgZWxzZWlmKCRjb29raWUtPmdldCgnc3BtY2FydG9vcmRlcl9wZXJzaXN0ZW50JykgIT0gJycpIHsgICAgICAgICAgICAgICAgICAgICAgJHNwbV9rZXkgPSAkY29va2llLT5nZXQoJ3NwbWNhcnRvb3JkZXJfcGVyc2lzdGVudCcpOyAgICAgICAgICAgICAgICAgICAgICAkcmVhZCA9IE1hZ2U6OmdldFNpbmdsZXRvbignY29yZS9yZXNvdXJj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../Mage.php';
3
+ umask(0);
4
+ Mage::app();
5
+ if(file_exists(Mage::getBaseDir('base').'/app/code/local/SPM/ShopyMind/ShopymindClient/callback_override.php'))
6
+ require_once(Mage::getBaseDir('base').'/app/code/local/SPM/ShopyMind/ShopymindClient/callback_override.php');
7
+ class ShopymindClient_Callback {
8
+
9
+ protected static $appEmulation = false;
10
+ protected static $initialEnvironmentInfo = false;
11
+
12
+ /**
13
+ * Permet de récupérer les informations utilisateur(s)
14
+ * en fonction de son identifiant
15
+ *
16
+ * Paramètre : $id -> L'ID de l'utilisateur ou liste d'utilisateurs
17
+ *
18
+ * Retour attendu : Tableau attendu (ou tableau de tableaux) :
19
+ * [
20
+ * 'last_name',
21
+ * 'first_name',
22
+ * 'email_address',
23
+ * 'locale'
24
+ * ]
25
+ *
26
+ * @param mixed|array $id
27
+ * @return array
28
+ */
29
+
30
+ public static function getUser($id,$fromQuotes = false) {
31
+ if(class_exists('ShopymindClient_CallbackOverride', false) && method_exists('ShopymindClient_CallbackOverride',__FUNCTION__)) return call_user_func_array(array('ShopymindClient_CallbackOverride', __FUNCTION__), func_get_args());
32
+ $return = array();
33
+ $tablePrefix = Mage::getConfig()->getTablePrefix();
34
+ $resource = Mage::getSingleton('core/resource');
35
+ $readConnection = $resource->getConnection('core_read');
36
+ if(is_numeric($id)) {
37
+ $query = 'SELECT `customer_default_phone`.`value` as `phone`,`customer_default_billing_country`.`value` as `country_code`,`customer_primary_table`.`entity_id`, `customer_primary_table`.`store_id`, `customer_firstname_table`.`value` as `firstname`, `customer_lastname_table`.`value` as `lastname`, `customer_primary_table`.`email`, `customer_primary_table`.`created_at`, `customer_primary_table`.`group_id`, `customer_gender`.`value` AS `gender_id`, `customer_birth_table`.`value` AS `birthday`
38
+ FROM `'.$tablePrefix.'customer_entity` AS `customer_primary_table`
39
+ LEFT JOIN `'.$tablePrefix.'customer_entity_datetime` AS `customer_birth_table` ON(`customer_birth_table`.`entity_id` = `customer_primary_table`.`entity_id` AND `customer_birth_table`.`attribute_id` = '.self::getMagentoAttributeCode('customer','dob').')
40
+ LEFT JOIN `'.$tablePrefix.'customer_entity_varchar` AS `customer_firstname_table` ON(`customer_firstname_table`.`entity_id` = `customer_primary_table`.`entity_id`) AND (`customer_firstname_table`.`attribute_id` = '.self::getMagentoAttributeCode('customer','firstname').')
41
+ LEFT JOIN `'.$tablePrefix.'customer_entity_varchar` AS `customer_lastname_table` ON(`customer_lastname_table`.`entity_id` = `customer_primary_table`.`entity_id`) AND (`customer_lastname_table`.`attribute_id` = '.self::getMagentoAttributeCode('customer','lastname').')
42
+ LEFT JOIN `'.$tablePrefix.'customer_entity_int` AS `customer_default_billing_jt` ON (`customer_default_billing_jt`.`entity_id` = `customer_primary_table`.`entity_id`) AND (`customer_default_billing_jt`.`attribute_id` = '.self::getMagentoAttributeCode('customer','default_shipping').')
43
+ LEFT JOIN `'.$tablePrefix.'customer_address_entity_varchar` AS `customer_default_billing_country` ON (`customer_default_billing_jt`.`value` = `customer_default_billing_country`.`entity_id`) AND (`customer_default_billing_country`.`attribute_id` = '.self::getMagentoAttributeCode('customer_address','country_id').')
44
+ LEFT JOIN `'.$tablePrefix.'customer_address_entity_varchar` AS `customer_default_phone` ON (`customer_default_billing_jt`.`value` = `customer_default_phone`.`entity_id`) AND (`customer_default_phone`.`attribute_id` = '.self::getMagentoAttributeCode('customer_address','telephone').')
45
+ LEFT JOIN `'.$tablePrefix.'customer_address_entity_int` AS `customer_default_billing_state_jt` ON (`customer_default_billing_country`.`entity_id` = `customer_default_billing_state_jt`.`entity_id`) AND (`customer_default_billing_state_jt`.`attribute_id` = '.self::getMagentoAttributeCode('customer_address','region_id').' OR `customer_default_billing_state_jt`.`attribute_id` IS NULL)
46
+ LEFT JOIN `'.$tablePrefix.'directory_country_region` AS `customer_default_billing_state` ON(`customer_default_billing_state`.`region_id` = `customer_default_billing_state_jt`.`value`)
47
+ LEFT JOIN `'.$tablePrefix.'customer_entity_int` AS `customer_gender` ON(`customer_gender`.`entity_id` = `customer_primary_table`.`entity_id`) AND (`customer_gender`.`attribute_id` = '.self::getMagentoAttributeCode('customer','gender').')
48
+ WHERE `customer_primary_table`.`entity_id` IN('.(implode(', ', (array)$id)).')
49
+ GROUP BY `customer_primary_table`.`entity_id`';
50
+ }else {
51
+
52
+ if($fromQuotes) {
53
+ $query = 'SELECT `quote_address`.`telephone` as `phone`,`quote_address`.`country_id` as `country_code`,`quote_address`.`email` AS `entity_id`, `quote`.`store_id`, `quote_address`.`firstname`, `quote_address`.`lastname`, `quote_address`.`email`, `quote`.`created_at`, `quote`.`customer_group_id` AS `group_id`, `quote`.`customer_gender` AS `gender_id`, `quote`.`customer_dob` AS `birthday`
54
+ FROM `'.$tablePrefix.'sales_flat_quote_address` AS `quote_address`
55
+ INNER JOIN `'.$tablePrefix.'sales_flat_quote` AS `quote` ON(`quote`.`entity_id` = `quote_address`.`quote_id`)
56
+ WHERE `quote_address`.`email` IN("'.(implode('", "', (array)$id)).'") AND `quote_address`.`address_type` = "billing"
57
+ GROUP BY `quote_address`.`email`
58
+ ORDER BY `quote`.`entity_id` ASC';
59
+ }else {
60
+ $query = 'SELECT `order_address`.`telephone` as `phone`,`order_address`.`country_id` as `country_code`,`order_address`.`email` AS `entity_id`, `order`.`store_id`, `order_address`.`firstname`, `order_address`.`lastname`, `order_address`.`email`, `order`.`created_at`, `order`.`customer_group_id` AS `group_id`, `order`.`customer_gender` AS `gender_id`, `order`.`customer_dob` AS `birthday`
61
+ FROM `'.$tablePrefix.'sales_flat_order_address` AS `order_address`
62
+ INNER JOIN `'.$tablePrefix.'sales_flat_order` AS `order` ON(`order`.`entity_id` = `order_address`.`parent_id`)
63
+ WHERE `order_address`.`email` IN("'.(implode('", "', (array)$id)).'") AND `order_address`.`address_type` = "billing"
64
+ GROUP BY `order_address`.`email`
65
+ ORDER BY `order`.`entity_id` ASC';
66
+ }
67
+ }
68
+ $results = $readConnection->fetchAll($query);
69
+ if($results && is_array($results) && sizeof($results)) {
70
+ foreach($results as $row) {
71
+ $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($row['email']);
72
+ $return[] = array(
73
+ 'id_customer' => $row['entity_id'],
74
+ 'optin' => $subscriber->isSubscribed(),
75
+ 'customer_since' => $row['created_at'],
76
+ 'last_name' => $row['lastname'],
77
+ 'first_name' => $row['firstname'],
78
+ 'email_address' => $row['email'],
79
+ 'phone1' => (isset($row['phone']) && $row['phone']?$row['phone']:''),
80
+ 'phone2' => '',
81
+ 'gender' => (isset($row['gender_id']) && ($row['gender_id'] == 1 || $row['gender_id'] == 2)?$row['gender_id']:0),
82
+ 'birthday' => (isset($row['birthday']) ? $row['birthday'] : 0),
83
+ 'locale' => self::getUserLocale($row['entity_id'],$row['store_id'],$row['country_code']),
84
+ 'date_last_order' => self::getDateLastOrder($row['entity_id']),
85
+ 'nb_order' => self::countCustomerOrder($row['entity_id']),
86
+ 'sum_order' => self::sumCustomerOrder($row['entity_id']),
87
+ 'groups' => array($row['group_id']),
88
+ 'products_ordered' => self::getCustomerProductsOrdered($row['entity_id'])
89
+ );
90
+ }
91
+ }
92
+ return (sizeof($return) === 1 ? $return[0] : $return);
93
+ }
94
+
95
+ /**
96
+ * Récupère la liste des status de commandes différents
97
+ *
98
+ * Retour attendu : un tableau avec la liste des statuts de commande de la boutique
99
+ * [
100
+ * 'idStatus1': 'labelStatus1',
101
+ * 'idStatus2': 'labelStatus2',
102
+ * ...
103
+ * ]
104
+ *
105
+ * @return array
106
+ */
107
+ public static function getOrdersStatus() {
108
+ if(class_exists('ShopymindClient_CallbackOverride', false) && method_exists('ShopymindClient_CallbackOverride',__FUNCTION__)) return call_user_func_array(array('ShopymindClient_CallbackOverride', __FUNCTION__), func_get_args());
109
+ $return = array();
110
+ $m= new Mage;
111
+ $mageVersion=$m->getVersion();
112
+ if($mageVersion >= 1.5) {
113
+ $results= Mage::getModel('sales/order_status')
114
+ ->getCollection()
115
+ ->addFieldToSelect('status')
116
+ ->addFieldToSelect('label')
117
+ ->getData();
118
+ }else {
119
+ $tablePrefix = Mage::getConfig()->getTablePrefix();
120
+ $resource = Mage::getSingleton('core/resource');
121
+
122
+ $readConnection = $resource->getConnection('core_read');
123
+ $query = 'SELECT `value` as `status`, `value` as `label`
124
+ FROM `'.$tablePrefix.'sales_order_entity_varchar`
125
+ WHERE `attribute_id` = '.self::getMagentoAttributeCode('order_status_history','status').'
126
+ GROUP BY `value`';
127
+ $results = $readConnection->fetchAll($query);
128
+ }
129
+ if($results && is_array($results) && sizeof($results)) {
130
+ foreach($results as $row) {
131
+ $return[$row['status']] = $row['label'];
132
+ }
133
+ }
134
+ return $return;
135
+ }
136
+
137
+ /**
138
+ * Récupération de la liste des timezones de la boutique (des clients)
139
+ *
140
+ * Retour attendu : un tableau avec la liste des fuseaux horaires des clients de la boutique
141
+ * [
142
+ * [
143
+ * 'country_code': 'US',
144
+ * 'region_code': 'GA',
145
+ * ]
146
+ * ]
147
+ *
148
+ * @param string|false $lastUpdate
149
+ * @return array
150
+ */
151
+ public static function getTimezones($lastUpdate) {
152
+ if(class_exists('ShopymindClient_CallbackOverride', false) && method_exists('ShopymindClient_CallbackOverride',__FUNCTION__)) return call_user_func_array(array('ShopymindClient_CallbackOverride', __FUNCTION__), func_get_args());
153
+ $return = array();
154
+ $tablePrefix = Mage::getConfig()->getTablePrefix();
155
+ $resource = Mage::getSingleton('core/resource');
156
+
157
+ $readConnection = $resource->getConnection('core_read');
158
+ $query = 'SELECT a.`value` as `country_code`, c.`code` as `region_code`
159
+ FROM `'.$tablePrefix.'customer_entity` AS d
160
+ LEFT JOIN `'.$tablePrefix.'customer_address_entity_varchar` a ON(d.`entity_id` = a.`entity_id`)
161
+ LEFT JOIN `'.$tablePrefix.'customer_address_entity_int` b ON(a.`entity_id` = b.`entity_id`)
162
+ LEFT JOIN `'.$tablePrefix.'directory_country_region` c ON(c.`region_id` = b.`value`)
163
+ WHERE (b.`attribute_id` = '.self::getMagentoAttributeCode('customer_address','region_id').' OR b.`attribute_id` IS NULL) AND ( a.`attribute_id` = '.self::getMagentoAttributeCode('customer_address','country_id').')
164
+ '.($lastUpdate ? ' AND d.`updated_at` >= "'.$lastUpdate.'"':'').'
165
+ GROUP BY country_code,region_code';
166
+ $results = $readConnection->fetchAll($query);
167
+ if($results && is_array($results) && sizeof($results)) {
168
+ foreach($results as $row) {
169
+ $return[] = $row;
170
+ }
171
+ }
172
+ return $return;
173
+ }
174
+
175
+ /**
176
+ * Récupérer la liste des clients qui fêtent leur anniversaire
177
+ *
178
+ * Params : $dateReference = La date de référence à prendre en compte format envoyé : Y-m-d H:i:s
179
+ * $timezones = fuseaux horaires concernés par la demande format : array(array('country' => 'FR', 'region' => '13'), array('country' => 'US', 'region' => 'ny'))
180
+ * $nbDays = Nombre de jours de l'envoi avant la date anniv
181
+ * $generateVoucher = false | array('amount' => '', 'type' => '', 'nbDaysValidate' => '')
182
+ *
183
+ * Retour attendu : Un tableau de liste utilisateur
184
+ * [
185
+ * [
186
+ * 'id_customer',
187
+ * 'last_name',
188
+ * 'first_name',
189
+ * 'email_address',
190
+ * 'gender',(1 = homme, 2 = femme, 0 = inconnu)(optionnel)
191
+ * 'locale', (optionnel)
192
+ * 'voucher_number' (optionnel)
193
+ * ]
194
+ * ]
195
+ *
196
+ * @return array
197
+ */
198
+ public static function getBirthdayClients($dateReference, $timezones, $nbDays = 0, $justCount = false) {
199
+ if(class_exists('ShopymindClient_CallbackOverride', false) && method_exists('ShopymindClient_CallbackOverride',__FUNCTION__)) return call_user_func_array(array('ShopymindClient_CallbackOverride', __FUNCTION__), func_get_args());
200
+ $return = array();
201
+ $birthDate = date("m", strtotime($dateReference. ' + '.$nbDays.' days')).'-'.date("d", strtotime($dateReference. ' + '.$nbDays.' days'));
202
+ $timezonesWhere = self::generateTimezonesWhere($timezones);
203
+ if(!$timezonesWhere) return false;
204
+ $tablePrefix = Mage::getConfig()->getTablePrefix();
205
+ $resource = Mage::getSingleton('core/resource');
206
+
207
+
208
+
209
+ $readConnection = $resource->getConnection('core_read');
210
+ $query = 'SELECT `customer_primary_table`.`entity_id`
211
+ FROM `'.$tablePrefix.'customer_entity` AS `customer_primary_table`
212
+ INNER JOIN `'.$tablePrefix.'customer_entity_datetime` AS `customer_birth_table` ON(`customer_birth_table`.`entity_id` = `customer_primary_table`.`entity_id` AND `customer_birth_table`.`attribute_id` = '.self::getMagentoAttributeCode('customer','dob').')
213
+ LEFT JOIN `'.$tablePrefix.'customer_entity_int` AS `customer_default_billing_jt` ON (`customer_default_billing_jt`.`entity_id` = `customer_primary_table`.`entity_id`) AND (`customer_default_billing_jt`.`attribute_id` = '.self::getMagentoAttributeCode('customer','default_shipping').')
214
+ LEFT JOIN `'.$tablePrefix.'customer_address_entity_varchar` AS `customer_default_billing_country` ON (`customer_default_billing_jt`.`value` = `customer_default_billing_country`.`entity_id`) AND (`customer_default_billing_country`.`attribute_id` = '.self::getMagentoAttributeCode('customer_address','country_id').')
215
+ LEFT JOIN `'.$tablePrefix.'customer_address_entity_int` AS `customer_default_billing_state_jt` ON (`customer_default_billing_country`.`entity_id` = `customer_default_billing_state_jt`.`entity_id`) AND (`customer_default_billing_state_jt`.`attribute_id` = '.self::getMagentoAttributeCode('customer_address','region_id').' OR `customer_default_billing_state_jt`.`attribute_id` IS NULL)
216
+ LEFT JOIN `'.$tablePrefix.'directory_country_region` AS `customer_default_billing_state` ON(`customer_default_billing_state`.`region_id` = `customer_default_billing_state_jt`.`value`)
217
+ WHERE DATE_FORMAT(`customer_birth_table`.`value`,"%m-%d") = "'.$birthDate.'" AND '.$timezonesWhere.' AND `customer_primary_table`.`is_active` = 1
218
+ GROUP BY `customer_primary_table`.`entity_id`';
219
+ $results = $readConnection->fetchAll($query);
220
+
221
+ if($results && is_array($results) && sizeof($results)) {
222
+ foreach($results as $row) {
223
+ if(!$row['entity_id']) continue;
224
+ $return[] = array(
225
+ 'customer' => self::getUser($row['entity_id'])
226
+ );
227
+ }
228
+ }
229
+ $timezonesWhere = self::generateTimezonesWhere($timezones,'order_address','country_id');
230
+ if($timezonesWhere) {
231
+ //Guest customer
232
+ $query = 'SELECT `order_primary`.`customer_email`
233
+ FROM `'.$tablePrefix.'sales_flat_order` AS `order_primary`
234
+ LEFT JOIN `'.$tablePrefix.'sales_flat_order_address` AS `order_address` ON(`order_address`.`parent_id` = `order_primary`.`entity_id`) AND (`order_address`.`address_type` = "billing")
235
+ LEFT JOIN `'.$tablePrefix.'directory_country_region` AS `customer_default_billing_state` ON(`customer_default_billing_state`.`region_id` = `order_address`.`region_id`)
236
+ WHERE `order_primary`.`customer_is_guest` = 1 AND DATE_FORMAT(`order_primary`.`customer_dob`,"%m-%d") = "'.$birthDate.'" AND '.$timezonesWhere.'
237
+ GROUP BY `order_primary`.`customer_email`';
238
+ $results = $readConnection->fetchAll($query);
239
+
240
+ if($results && is_array($results) && sizeof($results)) {
241
+ foreach($results as $row) {
242
+ $return[] = array(
243
+ 'customer' => self::getUser($row['customer_email'])
244
+ );
245
+ }
246
+ }
247
+ }
248
+
249
+ return ($justCount ? array('count'=>sizeof($return)) : $return);
250
+ }
251
+
252
+ /**
253
+ * Permet de récupérer les paniers abandonnés depuis un nombre de secondes
254
+ *
255
+ * Paramètre : $nbSeconds -> Nombre d'heure depuis l'abandon
256
+ * $generateVoucher = false | array('amount' => '', 'type' => '', 'nbDaysValidate' => '')
257
+ *
258
+ * Retour attendu : Un tableau de liste utilisateur
259
+ * [
260
+ * [
261
+ * 'id_customer',
262
+ * 'last_name',
263
+ * 'first_name',
264
+ * 'email_address',
265
+ * 'currency',
266
+ * 'articles' [
267
+ * [
268
+ * 'designation',
269
+ * 'qty',
270
+ * 'price',
271
+ * 'image_url',
272
+ * 'product_url'
273
+ * ]
274
+ * ],
275
+ * 'link_cart',
276
+ * 'locale', (optionnel),
277
+ * 'voucher_number' (optionnel)
278
+ * ]
279
+ * ]
280
+ *
281
+ * @param int $nbSeconds
282
+ * @return array
283
+ */
284
+ public static function getDroppedOutCart($nbSeconds,$justCount = false) {
285
+ if(class_exists('ShopymindClient_CallbackOverride', false) && method_exists('ShopymindClient_CallbackOverride',__FUNCTION__)) return call_user_func_array(array('ShopymindClient_CallbackOverride', __FUNCTION__), func_get_args());
286
+ $return = array();
287
+ $date = date('Y-m-d H:i:s');
288
+ $tablePrefix = Mage::getConfig()->getTablePrefix();
289
+ $resource = Mage::getSingleton('core/resource');
290
+ $readConnection = $resource->getConnection('core_read');
291
+ $m= new Mage;
292
+ $mageVersion=$m->getVersion();
293
+ $query = 'SELECT `quote_table`.* FROM `'.$tablePrefix.'sales_flat_quote` AS `quote_table`
294
+ LEFT JOIN `'.$tablePrefix.'sales_flat_order` AS `order_table` ON (`order_table`.`customer_email` = `quote_table`.`customer_email` AND `order_table`.`customer_id` = `quote_table`.`customer_id` AND `order_table`.`created_at` >= DATE_SUB("'.$date.'", INTERVAL 7 DAY) )
295
+ WHERE (((`quote_table`.`reserved_order_id` = "" OR `quote_table`.`reserved_order_id` IS NULL)))
296
+ AND (DATE_FORMAT(`quote_table`.`updated_at`,"%Y-%m-%d %H:%i:%s") >= DATE_SUB("'.$date.'", INTERVAL '.($nbSeconds*2).' SECOND))
297
+ AND (DATE_FORMAT(`quote_table`.`updated_at`,"%Y-%m-%d %H:%i:%s") <= DATE_SUB("'.$date.'", INTERVAL '.($nbSeconds).' SECOND))
298
+ AND (`quote_table`.`items_count` > 0)
299
+ AND (`quote_table`.`customer_id` IS NOT NULL OR `quote_table`.`customer_email` IS NOT NULL)
300
+ AND (`order_table`.`entity_id` IS NULL)
301
+ GROUP BY `quote_table`.`customer_email`';
302
+
303
+ $results = $readConnection->fetchAll($query);
304
+ if($results && is_array($results) && sizeof($results)) {
305
+ foreach($results as $row) {
306
+ self::startLangEmulationByStoreId($row['store_id']);
307
+ //if(!$row['customer_id']) continue;
308
+ $resultProducts = Mage::getModel("sales/quote_item")
309
+ ->getCollection()
310
+ ->addFieldToFilter("quote_id", $row['entity_id'])
311
+ ->addFieldToFilter("parent_item_id", array('null' => true))
312
+ ->getData();
313
+ if($resultProducts && is_array($resultProducts) && sizeof($resultProducts)) {
314
+ $returnProducts = array();
315
+ foreach($resultProducts as $row2) {
316
+ $product = Mage::getModel('catalog/product')->load($row2['product_id']);
317
+ try {
318
+ $image_url = str_replace(basename($_SERVER['SCRIPT_NAME']).'/','',$product->getSmallImageUrl(200,200));
319
+ } catch (Exception $e) {
320
+ $image_url = '';
321
+ }
322
+ $product_url = str_replace(basename($_SERVER['SCRIPT_NAME']).'/','',$product->getProductUrl(false));
323
+ $returnProducts[] = array(
324
+ 'description' => $row2['name'],
325
+ 'qty' => $row2['qty'],
326
+ 'price' => $row2['price_incl_tax'],
327
+ 'image_url' => $image_url,
328
+ 'product_url' => $product_url
329
+ );
330
+ }
331
+ }
332
+ if(sizeof($returnProducts))
333
+ $return[] = array(
334
+ 'sum_cart' => ($row['base_grand_total']/$row['store_to_base_rate']),
335
+ 'currency' => $row['base_currency_code'],
336
+ 'tax_rate' => $row['store_to_base_rate'],
337
+ 'id_cart' => $row['entity_id'],
338
+ 'link_cart' => str_replace(basename($_SERVER['SCRIPT_NAME']).'/','',Mage::getUrl('checkout/cart',array('_nosid'=>true))),
339
+ 'articles' => $returnProducts,
340
+ 'customer' => self::getUser(($row['customer_id']?$row['customer_id']:$row['customer_email']),true)
341
+ );
342
+ self::stopLangEmulation();
343
+ }
344
+ }
345
+ return ($justCount ? array('count'=>sizeof($return)) : $return);
346
+ }
347
+
348
+ /**
349
+ * Permet de récupérer la liste des bons clients
350
+ * par montant de commande sur une période donnée
351
+ *
352
+ * Paramètres : $dateReference = La date de référence à prendre en compte format envoyé : Y-m-d H:i:s
353
+ * $timezones = fuseaux horaires concernés par la demande format : array(array('country' => 'FR', 'region' => '13'), array('country' => 'US', 'region' => 'ny'))
354
+ * $amount -> Le montant total de commandes
355
+ * $currency -> Devise du montant saisi
356
+ * $duration -> Le nombre de jours comptabilisé
357
+ * $generateVoucher = false | array('amount' => '', 'type' => '', 'nbDaysValidate' => '')
358
+ *
359
+ * Retour attendu : Un tableau de liste d'utilisateur
360
+ * [
361
+ * [
362
+ * 'id_customer',
363
+ * 'last_name',
364
+ * 'first_name',
365
+ * 'email_address',
366
+ * 'gender',(1 = homme, 2 = femme, 0 = inconnu)(optionnel)
367
+ * 'locale', (optionnel)
368
+ * 'voucher_number' (optionnel)
369
+ * ]
370
+ * ]
371
+ *
372
+ * @param int $amount
373
+ * @param int $duration
374
+ * @return array
375
+ */
376
+ public static function getGoodClientsByAmount($dateReference, $timezones, $amount, $amountMax, $duration, $nbDaysLastOrder, $justCount = false) {
377
+ if(class_exists('ShopymindClient_CallbackOverride', false) && method_exists('ShopymindClient_CallbackOverride',__FUNCTION__)) return call_user_func_array(array('ShopymindClient_CallbackOverride', __FUNCTION__), func_get_args());
378
+ $return = array();
379
+ $tablePrefix = Mage::getConfig()->getTablePrefix();
380
+ $resource = Mage::getSingleton('core/resource');
381
+ $readConnection = $resource->getConnection('core_read');
382
+ $timezonesWhere = self::generateTimezonesWhere($timezones,'order_address','country_id');
383
+ if(!$timezonesWhere) return false;
384
+ $query = 'SELECT `order_last`.`entity_id`, `order_primary`.`customer_id`, `order_primary`.`customer_email`,
385
+ SUM((`order_primary`.`base_total_invoiced`)) AS Total
386
+ FROM `'.$tablePrefix.'sales_flat_order` AS `order_primary`
387
+ LEFT JOIN `'.$tablePrefix.'sales_flat_order` AS `order_last` ON (((`order_last`.`customer_id` IS NOT NULL AND `order_last`.`customer_id` = `order_primary`.`customer_id`) OR ((`order_last`.`customer_id` IS NULL OR `order_last`.`customer_id` = 0) AND `order_last`.`customer_email` = `order_primary`.`customer_email`)) AND DATE_FORMAT(`order_last`.`created_at`,"%Y-%m-%d %H:%i:%s") >= DATE_FORMAT(DATE_SUB("'.$dateReference.'", INTERVAL '.(int)$nbDaysLastOrder.' DAY),"%Y-%m-%d %H:%i:%s"))
388
+ LEFT JOIN `'.$tablePrefix.'sales_flat_order_address` AS `order_address` ON(`order_address`.`parent_id` = `order_primary`.`entity_id`) AND (`order_address`.`address_type` = "billing")
389
+ LEFT JOIN `'.$tablePrefix.'directory_country_region` AS `customer_default_billing_state` ON(`customer_default_billing_state`.`region_id` = `order_address`.`region_id`)
390
+ WHERE DATE_FORMAT(DATE_SUB("'.$dateReference.'",INTERVAL '.(int)$duration.' DAY),"%Y-%m-%d %H:%i:%s") <= DATE_FORMAT(`order_primary`.`created_at`,"%Y-%m-%d %H:%i:%s")
391
+ AND '.$timezonesWhere.'
392
+ AND `order_primary`.`base_total_invoiced` IS NOT NULL
393
+ AND `order_last`.`entity_id` IS NULL
394
+ GROUP BY `order_primary`.`customer_email`
395
+ HAVING `Total` >= '.(float)$amount.'
396
+ '.($amountMax ? ' AND `Total` <= '.(float)$amountMax : '');
397
+ $results = $readConnection->fetchAll($query);
398
+ if($results && is_array($results) && sizeof($results)) {
399
+ foreach($results as $row) {
400
+ $return[] = array(
401
+ 'customer' => self::getUser(($row['customer_id']?$row['customer_id']:$row['customer_email']))
402
+ );
403
+ }
404
+ }
405
+ return ($justCount ? array('count'=>sizeof($return)) : $return);
406
+ }
407
+
408
+ /**
409
+ * Permet de récupérer la liste des bons clients
410
+ * par nombre de commandes sur une période donnée
411
+ *
412
+ * Paramètres : $dateReference = La date de référence à prendre en compte format envoyé : Y-m-d H:i:s
413
+ * $timezones = fuseaux horaires concernés par la demande format : array(array('country' => 'FR', 'region' => '13'), array('country' => 'US', 'region' => 'ny'))
414
+ * $nbOrder -> Le nombre de commandes passées
415
+ * $duration -> Le nombre de jours comptabilisé
416
+ * $generateVoucher = false | array('amount' => '', 'type' => '', 'nbDaysValidate' => '')
417
+ *
418
+ * Retour attendu : Un tableau de liste d'utilisateur
419
+ * [
420
+ * [
421
+ * 'id_customer',
422
+ * 'last_name',
423
+ * 'first_name',
424
+ * 'email_address',
425
+ * 'locale', (optionnel)
426
+ * 'voucher_number' (optionnel)
427
+ * ]
428
+ * ]
429
+ *
430
+ * @param int $nbOrder
431
+ * @param int $duration
432
+ * @return array
433
+ */
434
+ public static function getGoodClientsByNumberOrders($dateReference, $timezones, $nbOrder, $nbOrderMax, $duration, $nbDaysLastOrder, $justCount = false) {
435
+ if(class_exists('ShopymindClient_CallbackOverride', false) && method_exists('ShopymindClient_CallbackOverride',__FUNCTION__)) return call_user_func_array(array('ShopymindClient_CallbackOverride', __FUNCTION__), func_get_args());
436
+ $return = array();
437
+ $tablePrefix = Mage::getConfig()->getTablePrefix();
438
+ $resource = Mage::getSingleton('core/resource');
439
+ $readConnection = $resource->getConnection('core_read');
440
+ $timezonesWhere = self::generateTimezonesWhere($timezones,'order_address','country_id');
441
+ if(!$timezonesWhere) return false;
442
+ $query = 'SELECT `order_last`.`entity_id`, `order_primary`.`customer_id`, `order_primary`.`customer_email`,
443
+ COUNT(`order_primary`.`entity_id`) AS Total
444
+ FROM `'.$tablePrefix.'sales_flat_order` AS `order_primary`
445
+ LEFT JOIN `'.$tablePrefix.'sales_flat_order` AS `order_last` ON (((`order_last`.`customer_id` IS NOT NULL AND `order_last`.`customer_id` = `order_primary`.`customer_id`) OR ((`order_last`.`customer_id` IS NULL OR `order_last`.`customer_id` = 0) AND `order_last`.`customer_email` = `order_primary`.`customer_email`)) AND DATE_FORMAT(`order_last`.`created_at`,"%Y-%m-%d %H:%i:%s") >= DATE_FORMAT(DATE_SUB("'.$dateReference.'", INTERVAL '.(int)$nbDaysLastOrder.' DAY),"%Y-%m-%d %H:%i:%s"))
446
+ LEFT JOIN `'.$tablePrefix.'sales_flat_order_address` AS `order_address` ON(`order_address`.`parent_id` = `order_primary`.`entity_id`) AND (`order_address`.`address_type` = "billing")
447
+ LEFT JOIN `'.$tablePrefix.'directory_country_region` AS `customer_default_billing_state` ON(`customer_default_billing_state`.`region_id` = `order_address`.`region_id`)
448
+ WHERE DATE_FORMAT(DATE_SUB("'.$dateReference.'",INTERVAL '.(int)$duration.' DAY),"%Y-%m-%d %H:%i:%s") <= DATE_FORMAT(`order_primary`.`created_at`,"%Y-%m-%d %H:%i:%s")
449
+ AND '.$timezonesWhere.'
450
+ AND `order_primary`.`base_total_invoiced` IS NOT NULL
451
+ AND `order_last`.`entity_id` IS NULL
452
+ GROUP BY `order_primary`.`customer_email`
453
+ HAVING `Total` >= '.(int)$nbOrder.'
454
+ '.($nbOrderMax ? ' AND `Total` <= '.(int)$nbOrderMax : '');
455
+ $results = $readConnection->fetchAll($query);
456
+
457
+
458
+ if($results && is_array($results) && sizeof($results)) {
459
+ foreach($results as $row) {
460
+ $return[] = array(
461
+ 'customer' => self::getUser(($row['customer_id']?$row['customer_id']:$row['customer_email']))
462
+ );
463
+ }
464
+ }
465
+ return ($justCount ? array('count'=>sizeof($return)) : $return);
466
+ }
467
+
468
+ /**
469
+ * Permet de récupérer la liste des clients n'ayants pas effectués de commandes
470
+ * depuis un certaint temps
471
+ *
472
+ * Paramètres : $dateReference = La date de référence à prendre en compte format envoyé : Y-m-d H:i:s
473
+ * $timezones = fuseaux horaires concernés par la demande format : array(array('country' => 'FR', 'region' => '13'), array('country' => 'US', 'region' => 'ny'))
474
+ * $nbDays -> Le nombre de jours d'innactivité. Si $nbDays = 0, alors récupérer la
475
+ * liste des clients n'ayant jamais effectués de commandes
476
+ * $generateVoucher = false | array('amount' => '', 'type' => '', 'nbDaysValidate' => '')
477
+ *
478
+ * Retour attendu : Un tableau de liste d'utilisateur
479
+ * [
480
+ * [
481
+ * 'id_customer',
482
+ * 'last_name',
483
+ * 'first_name',
484
+ * 'email_address',
485
+ * 'gender',(1 = homme, 2 = femme, 0 = inconnu)(optionnel)
486
+ * 'locale', (optionnel)
487
+ * 'voucher_number' (optionnel)
488
+ * ]
489
+ * ]
490
+ *
491
+ * @param int $nbDays
492
+ * @return array
493
+ */
494
+ public static function getMissingClients($dateReference, $timezones, $nbDays = 0, $relaunchOlder = false,$justCount = false) {
495
+ if(class_exists('ShopymindClient_CallbackOverride', false) && method_exists('ShopymindClient_CallbackOverride',__FUNCTION__)) return call_user_func_array(array('ShopymindClient_CallbackOverride', __FUNCTION__), func_get_args());
496
+ $return = array();
497
+
498
+ $timezonesWhere = self::generateTimezonesWhere($timezones);
499
+ if(!$timezonesWhere) return false;
500
+
501
+ $tablePrefix = Mage::getConfig()->getTablePrefix();
502
+ $date = date('Y-m-d 00:00:00');
503
+ $resource = Mage::getSingleton('core/resource');
504
+ $readConnection = $resource->getConnection('core_read');
505
+ $query = 'SELECT `customer_primary_table`.`entity_id`
506
+ FROM `'.$tablePrefix.'customer_entity` AS `customer_primary_table`
507
+ LEFT JOIN `'.$tablePrefix.'sales_flat_order` AS `customer_order` ON(`customer_primary_table`.`entity_id` = `customer_order`.`customer_id`)
508
+ LEFT JOIN `'.$tablePrefix.'customer_entity_int` AS `customer_default_billing_jt` ON (`customer_default_billing_jt`.`entity_id` = `customer_order`.`customer_id`) AND (`customer_default_billing_jt`.`attribute_id` = '.self::getMagentoAttributeCode('customer','default_shipping').')
509
+ LEFT JOIN `'.$tablePrefix.'customer_address_entity_varchar` AS `customer_default_billing_country` ON (`customer_default_billing_jt`.`value` = `customer_default_billing_country`.`entity_id`) AND (`customer_default_billing_country`.`attribute_id` = '.self::getMagentoAttributeCode('customer_address','country_id').')
510
+ LEFT JOIN `'.$tablePrefix.'customer_address_entity_int` AS `customer_default_billing_state_jt` ON (`customer_default_billing_country`.`entity_id` = `customer_default_billing_state_jt`.`entity_id`) AND (`customer_default_billing_state_jt`.`attribute_id` = '.self::getMagentoAttributeCode('customer_address','region_id').' OR `customer_default_billing_state_jt`.`attribute_id` IS NULL)
511
+ LEFT JOIN `'.$tablePrefix.'directory_country_region` AS `customer_default_billing_state` ON(`customer_default_billing_state`.`region_id` = `customer_default_billing_state_jt`.`value`)
512
+ WHERE `customer_order`.`entity_id` IS NULL
513
+ AND DATE_FORMAT(`customer_primary_table`.`created_at`,"%Y-%m-%d") = DATE_FORMAT(DATE_SUB("'.$dateReference.'", INTERVAL '.(int)($nbDays).' DAY),"%Y-%m-%d")
514
+ AND '.$timezonesWhere.'
515
+ AND `customer_primary_table`.`is_active` = 1
516
+ GROUP BY `customer_order`.`customer_id`';
517
+ $results = $readConnection->fetchAll($query);
518
+
519
+ if($results && is_array($results) && sizeof($results)) {
520
+ foreach($results as $row) {
521
+ if(!$row['entity_id']) continue;
522
+ $return[] = array(
523
+ 'customer' => self::getUser($row['entity_id'])
524
+ );
525
+ }
526
+ }
527
+
528
+ return ($justCount ? array('count'=>sizeof($return)) : $return);
529
+ }
530
+
531
+ /**
532
+ * Permet de récupérer les commandes ayant un certain statut, depuis $nbDays jours
533
+ *
534
+ * Paramètre : $dateReference = La date de référence à prendre en compte format envoyé : Y-m-d H:i:s
535
+ * $timezones = fuseaux horaires concernés par la demande format : array(array('country' => 'FR', 'region' => '13'), array('country' => 'US', 'region' => 'ny'))
536
+ * $nbDays -> Nombre de jours depuis que la commande a été passée
537
+ * $idStatus -> L'ID du statut concerné par la relance
538
+ * $generateVoucher = false | array('amount' => '', 'type' => '', 'nbDaysValidate' => '')
539
+ *
540
+ * Retour attendu : Un tableau de liste utilisateur
541
+ * [
542
+ * [
543
+ * 'id_customer',
544
+ * 'last_name',
545
+ * 'first_name',
546
+ * 'email_address',
547
+ * 'currency',
548
+ * 'total_amount',
549
+ * 'gender',(1 = homme, 2 = femme, 0 = inconnu)(optionnel)
550
+ * 'articles' [
551
+ * [
552
+ * 'designation',
553
+ * 'qty',
554
+ * 'price',
555
+ * 'currency',
556
+ * 'image_url',
557
+ * 'product_url',
558
+ * ]
559
+ * ],
560
+ * 'locale', (optionnel),
561
+ * 'voucher_number' (optionnel)
562
+ * ]
563
+ * ]
564
+ *
565
+ * @param int $nbDays
566
+ * @return array
567
+ */
568
+ public static function getOrdersByStatus($dateReference, $timezones, $nbDays, $idStatus,$justCount = false) {
569
+ if(class_exists('ShopymindClient_CallbackOverride', false) && method_exists('ShopymindClient_CallbackOverride',__FUNCTION__)) return call_user_func_array(array('ShopymindClient_CallbackOverride', __FUNCTION__), func_get_args());
570
+ $return = array();
571
+ $tablePrefix = Mage::getConfig()->getTablePrefix();
572
+ $resource = Mage::getSingleton('core/resource');
573
+ $readConnection = $resource->getConnection('core_read');
574
+
575
+ $timezonesWhere = self::generateTimezonesWhere($timezones,'order_address','country_id');
576
+ if(!$timezonesWhere) return false;
577
+ $query = 'SELECT `order_primary`.`store_id`, `order_primary`.`entity_id`, `order_primary`.`order_currency_code`, `order_primary`.`base_grand_total`, `order_primary`.`customer_id`, `order_primary`.`customer_email`
578
+ FROM `'.$tablePrefix.'sales_flat_order` AS `order_primary`
579
+ LEFT JOIN `'.$tablePrefix.'sales_flat_order` AS `order_last` ON (((`order_last`.`customer_id` IS NOT NULL AND `order_last`.`customer_id` = `order_primary`.`customer_id`) OR ((`order_last`.`customer_id` IS NULL OR `order_last`.`customer_id` = 0) AND `order_last`.`customer_email` = `order_primary`.`customer_email`)) AND `order_last`.`created_at` > `order_primary`.`created_at`)
580
+ LEFT JOIN `'.$tablePrefix.'sales_flat_order_status_history` AS `order_status` ON (`order_status`.`status` = `order_primary`.`status` AND `order_status`.`parent_id` = `order_primary`.`entity_id`)
581
+ LEFT JOIN `'.$tablePrefix.'sales_flat_order_address` AS `order_address` ON(`order_address`.`parent_id` = `order_primary`.`entity_id`) AND (`order_address`.`address_type` = "billing")
582
+ LEFT JOIN `'.$tablePrefix.'directory_country_region` AS `customer_default_billing_state` ON(`customer_default_billing_state`.`region_id` = `order_address`.`region_id`)
583
+ WHERE `order_primary`.status = "'.$idStatus.'" AND DATE_FORMAT(`order_primary`.`created_at`,"%Y-%m-%d") >= DATE_FORMAT(DATE_SUB("'.$dateReference.'", INTERVAL '.($nbDays+14).' DAY),"%Y-%m-%d")
584
+ AND DATE_FORMAT(`order_status`.`created_at`,"%Y-%m-%d") = DATE_FORMAT(DATE_SUB("'.$dateReference.'", INTERVAL '.($nbDays).' DAY),"%Y-%m-%d")
585
+ AND '.$timezonesWhere.'
586
+ AND `order_last`.`entity_id` IS NULL
587
+ GROUP BY `order_primary`.`customer_email`';
588
+ $results = $readConnection->fetchAll($query);
589
+
590
+ if($results && is_array($results) && sizeof($results)) {
591
+ foreach($results as $row) {
592
+ self::startLangEmulationByStoreId($row['store_id']);
593
+ $resultProducts = Mage::getModel("sales/order_item")
594
+ ->getCollection()
595
+ ->addFieldToFilter("order_id", $row['entity_id'])
596
+ ->addFieldToFilter("parent_item_id", array('null' => true))
597
+ ->getData();
598
+ if($resultProducts && is_array($resultProducts) && sizeof($resultProducts)) {
599
+ $returnProducts = array();
600
+ foreach($resultProducts as $row2) {
601
+ $product = Mage::getModel('catalog/product')->load($row2['product_id']);
602
+ try {
603
+ $image_url = str_replace(basename($_SERVER['SCRIPT_NAME']).'/','',$product->getSmallImageUrl(200,200));
604
+ } catch (Exception $e) {
605
+ $image_url = '';
606
+ }
607
+ $product_url = str_replace(basename($_SERVER['SCRIPT_NAME']).'/','',$product->getProductUrl(false));
608
+
609
+ $returnProducts[] = array(
610
+ 'description' => $row2['name'],
611
+ 'qty' => $row2['qty_invoiced'],
612
+ 'price' => $row2['price_incl_tax'],
613
+ 'image_url' => $image_url,
614
+ 'product_url' => $product_url
615
+ );
616
+ }
617
+ }
618
+ if(sizeof($returnProducts))
619
+ $return[] = array(
620
+ 'currency' => $row['order_currency_code'],
621
+ 'total_amount' => $row['base_grand_total'],
622
+ 'articles' => $returnProducts,
623
+ 'id_order' => $row['entity_id'],
624
+ 'customer' => self::getUser(($row['customer_id']?$row['customer_id']:$row['customer_email']))
625
+ );
626
+
627
+ self::stopLangEmulation();
628
+ }
629
+ }
630
+ return ($justCount ? array('count'=>sizeof($return)) : $return);
631
+ }
632
+ public static function generateVouchers($voucherInfos,$emails) {
633
+ if(class_exists('ShopymindClient_CallbackOverride', false) && method_exists('ShopymindClient_CallbackOverride',__FUNCTION__)) return call_user_func_array(array('ShopymindClient_CallbackOverride', __FUNCTION__), func_get_args());
634
+ $vouchers = array();
635
+ if($voucherInfos && is_array($voucherInfos) && $emails && is_array($emails) && sizeof($emails)) {
636
+ foreach ($emails as $email) {
637
+ $voucher = self::generateVoucher($email, $voucherInfos['type'], ($voucherInfos['type'] == 'shipping' ? false : $voucherInfos['amount']), ($voucherInfos['type'] == 'amount' ? $voucherInfos['amountCurrency'] : false), $voucherInfos['minimumOrder'], $voucherInfos['nbDayValidate'], '');
638
+ if(!$voucher) continue;
639
+ $vouchers[$email] = $voucher;
640
+ }
641
+ }
642
+ return $vouchers;
643
+ }
644
+
645
+ public static function generateKeysAccess($keysAccess) {
646
+ if(class_exists('ShopymindClient_CallbackOverride', false) && method_exists('ShopymindClient_CallbackOverride',__FUNCTION__)) return call_user_func_array(array('ShopymindClient_CallbackOverride', __FUNCTION__), func_get_args());
647
+ if($keysAccess && is_array($keysAccess) && sizeof($keysAccess)) {
648
+ foreach ($keysAccess as $keyAccessInfo) {
649
+ $keyAccess = $keyAccessInfo['key'];
650
+ $id_customer = (int)$keyAccessInfo['id_customer'];
651
+ $id_cart = (int)$keyAccessInfo['id_cart'];
652
+ $id_order = $keyAccessInfo['id_order'];
653
+ $email = $keyAccessInfo['email'];
654
+ $voucher_number = $keyAccessInfo['voucher_number'];
655
+ $tablePrefix = Mage::getConfig()->getTablePrefix();
656
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
657
+ $now = date('Y-m-d H:i:s');
658
+ $write->query('INSERT IGNORE INTO `'.$tablePrefix.'spmcartoorder` (`spm_key`'.($id_customer ? ',`id_customer`':'').($voucher_number ? ',`voucher_number`':'').($id_cart ? ',`id_cart`':'').($email ? ',`email`':'').($id_order ? ',`id_order`':'').',`date_add`,`date_upd`) values ("'.$keyAccess.'"'.($id_customer ? ','.$id_customer:'').($voucher_number ? ',"'.$voucher_number.'"':'').($id_cart ? ','.$id_cart:'').($email ? ',"'.$email.'"':'').($id_order ? ','.$id_order:'').',"'.$now.'","'.$now.'")');
659
+ }
660
+ }
661
+ return true;
662
+ }
663
+
664
+ public static function generateVoucher($id_customer, $type, $amount = false, $amountCurrency = false, $minimumOrder = false, $nbDayValidate, $description) {
665
+ if(class_exists('ShopymindClient_CallbackOverride', false) && method_exists('ShopymindClient_CallbackOverride',__FUNCTION__)) return call_user_func_array(array('ShopymindClient_CallbackOverride', __FUNCTION__), func_get_args());
666
+ $coupon_code = 'SPM-'.strtoupper(uniqid());
667
+ $date = date('Y-m-d H:i:s');
668
+ $coupon = Mage::getModel('salesrule/rule');
669
+ $coupon->setName($coupon_code)
670
+ ->setFromDate($date)
671
+ ->setToDate((date('Y-m-d 23:59:59',mktime(date("H"), date("i"), date("s"), date("m") , date("d")+$nbDayValidate, date("Y")))))
672
+ ->setUsesPerCustomer('1')
673
+ ->setIsActive('1')
674
+ ->setStopRulesProcessing('0')
675
+ ->setIsAdvanced('1')
676
+ ->setProductIds(NULL)
677
+ ->setSortOrder('0');
678
+ if($type == 'percent') {
679
+ $coupon->setSimpleAction('by_percent')
680
+ ->setDiscountAmount($amount)
681
+ ->setDiscountQty(NULL)
682
+ ->setSimpleFreeShipping('0');
683
+ }if($type == 'amount') {
684
+ $coupon->setSimpleAction('cart_fixed')
685
+ ->setDiscountAmount($amount)
686
+ ->setDiscountQty(NULL)
687
+ ->setSimpleFreeShipping('0');
688
+ }elseif($type == 'shipping') {
689
+ $coupon->setSimpleFreeShipping(1);
690
+ }
691
+ $coupon->setDiscountStep('0')
692
+ ->setApplyToShipping('0')
693
+ ->setTimesUsed('0')
694
+ ->setIsRss('0')
695
+ ->setCouponType('2')
696
+ ->setUsesPerCoupon(1)
697
+ ->setCustomerGroupIds(self::getAllCustomerGroupsIds())
698
+ ->setWebsiteIds(array('1'))
699
+ ->setCouponCode($coupon_code);
700
+ if($minimumOrder) {
701
+ $condition = Mage::getModel('salesrule/rule_condition_address')
702
+ ->setType('salesrule/rule_condition_address')
703
+ ->setAttribute('base_subtotal')
704
+ ->setOperator('>=')
705
+ ->setValue((int)$minimumOrder);
706
+ $coupon->getConditions()->addCondition($condition);
707
+ }
708
+ if($coupon->save())
709
+ return $coupon_code;
710
+ return false;
711
+ }
712
+
713
+ public static function getAllCustomerGroupsIds(){
714
+ if(class_exists('ShopymindClient_CallbackOverride', false) && method_exists('ShopymindClient_CallbackOverride',__FUNCTION__)) return call_user_func_array(array('ShopymindClient_CallbackOverride', __FUNCTION__), func_get_args());
715
+ $return = array();
716
+ $results = Mage::getResourceModel('customer/group_collection')->toOptionArray();
717
+ if($results) {
718
+ foreach($results as $row){
719
+ $return[] = $row['value'];
720
+ }
721
+ }
722
+ return $return;
723
+ }
724
+ public static function getCustomerGroups() {
725
+ if(class_exists('ShopymindClient_CallbackOverride', false) && method_exists('ShopymindClient_CallbackOverride',__FUNCTION__)) return call_user_func_array(array('ShopymindClient_CallbackOverride', __FUNCTION__), func_get_args());
726
+ $return = array();
727
+ $results = Mage::getResourceModel('customer/group_collection')->toOptionArray();
728
+ if($results) {
729
+ foreach($results as $row){
730
+ $return[$row['value']] = $row['label'];
731
+ }
732
+ }
733
+ return $return;
734
+
735
+ }
736
+ public static function getCountries() {
737
+ if(class_exists('ShopymindClient_CallbackOverride', false) && method_exists('ShopymindClient_CallbackOverride',__FUNCTION__)) return call_user_func_array(array('ShopymindClient_CallbackOverride', __FUNCTION__), func_get_args());
738
+ $return = array();
739
+ $results = Mage::getResourceModel('directory/country_collection')->loadByStore()->toOptionArray();
740
+ if($results) {
741
+ foreach($results as $row){
742
+ if($row['value'])
743
+ $return[$row['value']] = $row['label'];
744
+ }
745
+ }
746
+ return $return;
747
+ }
748
+ public static function startLangEmulationByStoreId($store_id) {
749
+ if($store_id == Mage::app()->getStore()->getId()) return false;
750
+ $storeCode = Mage::app()->getStore($store_id)->getCode();
751
+ self::$appEmulation = Mage::getSingleton('core/app_emulation');
752
+ self::$initialEnvironmentInfo = self::$appEmulation->startEnvironmentEmulation($storeCode);
753
+ }
754
+ public static function startLangEmulationByIsoLang($lang) {
755
+ if(self::$appEmulation !== false) return;
756
+ $stores = Mage::app()->getStores();
757
+ foreach($stores as $store) {
758
+ $store_id = $store->getId();
759
+ $locale_store = Mage::getStoreConfig('general/locale/code', $store_id);
760
+ if($lang === substr($locale_store,0,-3)) {
761
+ self::startLangEmulationByStoreId($store_id);
762
+ }
763
+ }
764
+ }
765
+ public static function stopLangEmulation($lang) {
766
+ if(self::$appEmulation === false) return;
767
+ self::$appEmulation->stopEnvironmentEmulation(self::$initialEnvironmentInfo);
768
+ self::$appEmulation = false;
769
+ self::$initialEnvironmentInfo = false;
770
+ }
771
+ public static function getCurrencies() {
772
+ if(class_exists('ShopymindClient_CallbackOverride', false) && method_exists('ShopymindClient_CallbackOverride',__FUNCTION__)) return call_user_func_array(array('ShopymindClient_CallbackOverride', __FUNCTION__), func_get_args());
773
+ $return = array();
774
+ $results = Mage::app()->getStore()->getAvailableCurrencyCodes(true);
775
+ if($results) {
776
+ foreach($results as $value){
777
+ if($value)
778
+ $return[$value] = Mage::app()->getLocale()->getTranslation($value, 'nametocurrency');
779
+ }
780
+ }
781
+ return $return;
782
+ }
783
+ public static function getTestData($lang = false) {
784
+ if(class_exists('ShopymindClient_CallbackOverride', false) && method_exists('ShopymindClient_CallbackOverride',__FUNCTION__)) return call_user_func_array(array('ShopymindClient_CallbackOverride', __FUNCTION__), func_get_args());
785
+ if($lang) self::startLangEmulationByIsoLang($lang);
786
+ $return = array();
787
+ //Lien vers panier
788
+ $return['link_cart'] = str_replace(basename($_SERVER['SCRIPT_NAME']).'/','',Mage::getUrl('checkout/cart',array('_nosid'=>true)));
789
+ //Article au hasard
790
+ $return['articles'] = self::getProducts($lang,false,true);
791
+ if($lang) self::stopLangEmulation();
792
+ return $return;
793
+ }
794
+ public static function deleteUnusedVouchers() {
795
+ if(class_exists('ShopymindClient_CallbackOverride', false) && method_exists('ShopymindClient_CallbackOverride',__FUNCTION__)) return call_user_func_array(array('ShopymindClient_CallbackOverride', __FUNCTION__), func_get_args());
796
+ $date = date('Y-m-d H:i:s');
797
+ $tablePrefix = Mage::getConfig()->getTablePrefix();
798
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
799
+ $results = $read->fetchAll('SELECT `rule_id` AS `id`
800
+ FROM `'.$tablePrefix.'salesrule`
801
+ WHERE `name` LIKE "SPM-%" AND `to_date` <= DATE_SUB("'.$date.'", INTERVAL 7 DAY)');
802
+ if($results && is_array($results) && sizeof($results)) {
803
+ foreach($results as $row) {
804
+ $cartRule = Mage::getModel('salesrule/rule')->load($row['id']);
805
+ $cartRule->delete();
806
+ }
807
+ }
808
+ return true;
809
+ }
810
+ public static function getProducts( $lang, $products = false, $random = false, $maxProducts = 3) {
811
+ if(class_exists('ShopymindClient_CallbackOverride', false) && method_exists('ShopymindClient_CallbackOverride',__FUNCTION__)) return call_user_func_array(array('ShopymindClient_CallbackOverride', __FUNCTION__), func_get_args());
812
+ if($lang) self::startLangEmulationByIsoLang($lang);
813
+ $return = array();
814
+
815
+ $collection = array();
816
+ if($products) {
817
+ $collection = Mage::getResourceModel('catalog/product_collection');
818
+ Mage::getModel('catalog/layer')->prepareProductCollection($collection);
819
+ $collection->addAttributeToFilter('entity_id', array('in' => $products))->getSelect();
820
+ $collection->addStoreFilter();
821
+ $collection->setPage(1);
822
+ }elseif($random) {
823
+ $collection = Mage::getResourceModel('catalog/product_collection');
824
+ Mage::getModel('catalog/layer')->prepareProductCollection($collection);
825
+ $collection->getSelect()->order('rand()');
826
+ $collection->addStoreFilter();
827
+ $collection->setPage(1, ($maxProducts ? $maxProducts : 3));
828
+
829
+ }
830
+ if($collection && sizeof($collection)) {
831
+ foreach($collection as $product) {
832
+ $image_url = str_replace(basename($_SERVER['SCRIPT_NAME']).'/','',$product->getSmallImageUrl(200,200));
833
+ $product_url = str_replace(basename($_SERVER['SCRIPT_NAME']).'/','',$product->getProductUrl(false));
834
+ $return[] = array(
835
+ 'description' => $product->getName(),
836
+ 'price' => $product->getPrice(),
837
+ 'image_url' => $image_url,
838
+ 'product_url' => $product_url
839
+ );
840
+ }
841
+ }
842
+ if($lang) self::stopLangEmulation();
843
+ return $return;
844
+ }
845
+
846
+ public static function getUserLocale($id_customer,$store_id,$country_code = false) {
847
+ if(class_exists('ShopymindClient_CallbackOverride', false) && method_exists('ShopymindClient_CallbackOverride',__FUNCTION__)) return call_user_func_array(array('ShopymindClient_CallbackOverride', __FUNCTION__), func_get_args());
848
+ $locale_shop = Mage::getStoreConfig('general/locale/code', $store_id);
849
+ if(!$country_code) {
850
+ $customer = Mage::getModel('customer/customer')->load($id_customer);
851
+ $defaultBilling = $customer->getDefaultBillingAddress();
852
+ if($defaultBilling)
853
+ return substr($locale_shop,0,3).$defaultBilling->getCountry();
854
+ } else return substr($locale_shop,0,3).$country_code;
855
+
856
+ $locale_shop = explode('_',$locale_shop);
857
+ $locale_shop = strtolower($locale_shop[0]).'_00';
858
+
859
+ return $locale_shop;
860
+ }
861
+ public static function generateTimezonesWhere($timezones,$country_alias = 'customer_default_billing_country',$country_field = 'value',$state_alias = 'customer_default_billing_state',$state_field = 'code') {
862
+ if(class_exists('ShopymindClient_CallbackOverride', false) && method_exists('ShopymindClient_CallbackOverride',__FUNCTION__)) return call_user_func_array(array('ShopymindClient_CallbackOverride', __FUNCTION__), func_get_args());
863
+ if(is_array($timezones) AND !sizeof($timezones)) return false;
864
+ $where = array();
865
+ foreach($timezones as $zones) {
866
+ if(!is_array($zones)) $where[] = '(`'.$country_alias.'`.`'.$country_field.'` IS NULL)';
867
+ elseif(!isset($zones['region']) || !$zones['region'])
868
+ $where[] = '(`'.$country_alias.'`.`'.$country_field.'` = "'.$zones['country'].'")';
869
+ else $where[] = '(`'.$country_alias.'`.`'.$country_field.'` = "'.$zones['country'].'" AND `'.$state_alias.'`.`'.$state_field.'` = "'.$zones['region'].'")';
870
+ }
871
+ if(sizeof($where)) return '('.implode(' OR ',$where).')';
872
+ return false;
873
+ }
874
+ public static function getDateLastOrder($id_customer) {
875
+ if(class_exists('ShopymindClient_CallbackOverride', false) && method_exists('ShopymindClient_CallbackOverride',__FUNCTION__)) return call_user_func_array(array('ShopymindClient_CallbackOverride', __FUNCTION__), func_get_args());
876
+ $tablePrefix = Mage::getConfig()->getTablePrefix();
877
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
878
+ if(is_numeric($id_customer)) {
879
+ $result = $read->fetchRow('SELECT MAX(`created_at`) AS `created_at`
880
+ FROM `'.$tablePrefix.'sales_flat_order`
881
+ WHERE `customer_id` = '.(int)$id_customer.' AND `base_total_invoiced` IS NOT NULL');
882
+ }else {
883
+ $result = $read->fetchRow('SELECT MAX(`created_at`) AS `created_at`
884
+ FROM `'.$tablePrefix.'sales_flat_order`
885
+ WHERE `customer_email` = "'.$id_customer.'" AND `base_total_invoiced` IS NOT NULL');
886
+ }
887
+ return isset($result['created_at']) ? $result['created_at'] : 0;
888
+ }
889
+ public static function countCustomerOrder($id_customer) {
890
+ if(class_exists('ShopymindClient_CallbackOverride', false) && method_exists('ShopymindClient_CallbackOverride',__FUNCTION__)) return call_user_func_array(array('ShopymindClient_CallbackOverride', __FUNCTION__), func_get_args());
891
+ $tablePrefix = Mage::getConfig()->getTablePrefix();
892
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
893
+ if(is_numeric($id_customer)) {
894
+ $result = $read->fetchRow('SELECT COUNT(`entity_id`) AS `nbOrder`
895
+ FROM `'.$tablePrefix.'sales_flat_order`
896
+ WHERE `customer_id` = '.(int)$id_customer.' AND `base_total_invoiced` IS NOT NULL');
897
+ }else {
898
+ $result = $read->fetchRow('SELECT COUNT(`entity_id`) AS `nbOrder`
899
+ FROM `'.$tablePrefix.'sales_flat_order`
900
+ WHERE `customer_email` = "'.$id_customer.'" AND `base_total_invoiced` IS NOT NULL');
901
+ }
902
+ return isset($result['nbOrder']) ? $result['nbOrder'] : 0;
903
+ }
904
+ public static function sumCustomerOrder($id_customer) {
905
+ if(class_exists('ShopymindClient_CallbackOverride', false) && method_exists('ShopymindClient_CallbackOverride',__FUNCTION__)) return call_user_func_array(array('ShopymindClient_CallbackOverride', __FUNCTION__), func_get_args());
906
+ $m= new Mage;
907
+ $mageVersion=$m->getVersion();
908
+ $tablePrefix = Mage::getConfig()->getTablePrefix();
909
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
910
+ if(is_numeric($id_customer)) {
911
+ $result = $read->fetchRow('SELECT SUM((`base_total_invoiced`/base_to_order_rate)) AS `sumOrder`
912
+ FROM `'.$tablePrefix.'sales_flat_order`
913
+ WHERE `customer_id` = '.(int)$id_customer.' AND `base_total_invoiced` IS NOT NULL');
914
+ }else {
915
+ $result = $read->fetchRow('SELECT SUM((`base_total_invoiced`/base_to_order_rate)) AS `sumOrder`
916
+ FROM `'.$tablePrefix.'sales_flat_order`
917
+ WHERE `customer_email` = "'.$id_customer.'" AND `base_total_invoiced` IS NOT NULL');
918
+ }
919
+ return isset($result['sumOrder']) ? $result['sumOrder'] : 0;
920
+ }
921
+ public static function getCustomerProductsOrdered($id_customer) {
922
+ if(class_exists('ShopymindClient_CallbackOverride', false) && method_exists('ShopymindClient_CallbackOverride',__FUNCTION__)) return call_user_func_array(array('ShopymindClient_CallbackOverride', __FUNCTION__), func_get_args());
923
+ $tablePrefix = Mage::getConfig()->getTablePrefix();
924
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
925
+ if(is_numeric($id_customer)) {
926
+ $result = $read->fetchAll('SELECT `product_id` AS `id_product`, `sku` AS `reference_product`
927
+ FROM `'.$tablePrefix.'sales_flat_order_item` AS `order_detail`
928
+ LEFT JOIN `'.$tablePrefix.'sales_flat_order` AS `orders` ON (`orders`.`entity_id` = `order_detail`.`order_id`)
929
+ WHERE `customer_id` = '.(int)$id_customer.' AND `orders`.`base_total_invoiced` IS NOT NULL
930
+ GROUP BY `product_id`');
931
+ }else {
932
+ $result = $read->fetchAll('SELECT `product_id` AS `id_product`, `sku` AS `reference_product`
933
+ FROM `'.$tablePrefix.'sales_flat_order_item` AS `order_detail`
934
+ LEFT JOIN `'.$tablePrefix.'sales_flat_order` AS `orders` ON (`orders`.`entity_id` = `order_detail`.`order_id`)
935
+ WHERE `customer_email` = "'.$id_customer.'" AND `orders`.`base_total_invoiced` IS NOT NULL
936
+ GROUP BY `product_id`');
937
+ }
938
+ return $result;
939
+ }
940
+ public static function getMagentoAttributeCode($model,$attribute_code) {
941
+ if(class_exists('ShopymindClient_CallbackOverride', false) && method_exists('ShopymindClient_CallbackOverride',__FUNCTION__)) return call_user_func_array(array('ShopymindClient_CallbackOverride', __FUNCTION__), func_get_args());
942
+ $eavAttribute = new Mage_Eav_Model_Mysql4_Entity_Attribute();
943
+ return $eavAttribute->getIdByCode($model, $attribute_code);
944
+ }
945
+ public static function getSessionCustomerId() {
946
+ if(class_exists('ShopymindClient_CallbackOverride', false) && method_exists('ShopymindClient_CallbackOverride',__FUNCTION__)) return call_user_func_array(array('ShopymindClient_CallbackOverride', __FUNCTION__), func_get_args());
947
+ if(Mage::getSingleton('customer/session')->isLoggedIn()) {
948
+ $customerData = Mage::getSingleton('customer/session')->getCustomer();
949
+ return $customerData->getId();
950
+ }
951
+ return false;
952
+ }
953
+ public static function getSessionCustomerEmail() {
954
+ if(class_exists('ShopymindClient_CallbackOverride', false) && method_exists('ShopymindClient_CallbackOverride',__FUNCTION__)) return call_user_func_array(array('ShopymindClient_CallbackOverride', __FUNCTION__), func_get_args());
955
+ if(Mage::getSingleton('customer/session')->isLoggedIn()) {
956
+ $customerData = Mage::getSingleton('customer/session')->getCustomer();
957
+ return $customerData->getEmail();
958
+ }else {
959
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
960
+ return $quote->getCustomerEmail();
961
+ }
962
+ return false;
963
+ }
964
+ public static function getSessionCartId() {
965
+ $session = Mage::getSingleton('checkout/session');
966
+ $cart_id = $session->getQuote()->getId();
967
+ return $cart_id;
968
+ }
969
+ public static function checkNewCart() {
970
+ if(class_exists('ShopymindClient_CallbackOverride', false) && method_exists('ShopymindClient_CallbackOverride',__FUNCTION__)) return call_user_func_array(array('ShopymindClient_CallbackOverride', __FUNCTION__), func_get_args());
971
+ $cookie = Mage::app()->getCookie();
972
+ $cart_id = self::getSessionCartId();
973
+ $customer_id = self::getSessionCustomerId();
974
+ $customer_email = self::getSessionCustomerEmail();
975
+ $vouchersCart = (array)Mage::getSingleton('checkout/session')->getQuote()->getCouponCode();
976
+ $key_checked = md5($cart_id.'-'.$customer_id.'-'.$customer_email.'-'.serialize($vouchersCart));
977
+ if((!isset($_GET['spm_key']) || !$_GET['spm_key']) && (!$cookie->get('spmkeychecked') || $key_checked !== $cookie->get('spmkeychecked')) && !$cookie->get('spmcartoorder') && !$cookie->get('spmcartoorder_persistent') && $cart_id) {
978
+ $tablePrefix = Mage::getConfig()->getTablePrefix();
979
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
980
+ $spm_key = $read->fetchRow('SELECT `spm_key` FROM `'.$tablePrefix.'spmcartoorder` WHERE (`id_cart` = '.(int)$cart_id.') AND `is_converted` = 0 AND `date_upd` >= DATE_SUB("'.date('Y-m-d H:i:s').'", INTERVAL 1 MONTH) ORDER BY `date_add` DESC');
981
+ if(!$spm_key && $customer_id)
982
+ $spm_key = $read->fetchRow('SELECT `spm_key` FROM `'.$tablePrefix.'spmcartoorder` WHERE (`id_customer` = '.(int)$customer_id.') AND `is_converted` = 0 AND `date_upd` >= DATE_SUB("'.date('Y-m-d H:i:s').'", INTERVAL 1 MONTH) ORDER BY `date_add` DESC');
983
+ if(!$spm_key && $customer_email !== null && $customer_email !== false && $customer_email)
984
+ $spm_key = $read->fetchRow('SELECT `spm_key` FROM `'.$tablePrefix.'spmcartoorder` WHERE (`email` = "'.$customer_email.'") AND `is_converted` = 0 AND `date_upd` >= DATE_SUB("'.date('Y-m-d H:i:s').'", INTERVAL 1 MONTH) ORDER BY `date_add` DESC');
985
+ if(!$spm_key) {
986
+ if($vouchersCart && sizeof($vouchersCart)) {
987
+ foreach($vouchersCart as $voucher) {
988
+ if(!$spm_key && $voucher)
989
+ $spm_key = $read->fetchRow('SELECT `spm_key` FROM `'.$tablePrefix.'spmcartoorder` WHERE (`voucher_number` = "'.addslashes($voucher).'") AND `is_converted` = 0 AND `date_upd` >= DATE_SUB("'.date('Y-m-d H:i:s').'", INTERVAL 1 MONTH) ORDER BY `date_add` DESC');
990
+ else break;
991
+ }
992
+ }
993
+ }
994
+ if($spm_key && isset($spm_key['spm_key']) && $spm_key['spm_key']) { $_GET['spm_key'] = $spm_key['spm_key'];$cookie->delete('spmkeychecked');}
995
+ else {
996
+ $cookie->set('spmkeychecked', $key_checked,0);
997
+ }
998
+ }
999
+ if((isset($_GET['spm_key']) && $_GET['spm_key']) || $cookie->get('spmcartoorder') || $cookie->get('spmcartoorder_persistent')) {
1000
+ $quote = Mage::getSingleton('checkout/cart')->getQuote();
1001
+ if(!$cart_id || (!$customer_id && !$customer_email) || !$quote->getGrandTotal()) {
1002
+ if(isset($_GET['spm_key']) && $_GET['spm_key']) {
1003
+ $cookie->set('spmcartoorder_persistent', $_GET['spm_key'], 657000);
1004
+ $cookie->set('spmcartoorder', $_GET['spm_key'],0);
1005
+ }
1006
+ }else {
1007
+
1008
+ $tablePrefix = Mage::getConfig()->getTablePrefix();
1009
+
1010
+ if(isset($_GET['spm_key']) && $_GET['spm_key'])
1011
+ $spm_key = $_GET['spm_key'];
1012
+ elseif($cookie->get('spmcartoorder') != '')
1013
+ $spm_key = $cookie->get('spmcartoorder');
1014
+ elseif($cookie->get('spmcartoorder_persistent') != '') {
1015
+ $spm_key = $cookie->get('spmcartoorder_persistent');
1016
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
1017
+ $test = $read->fetchRow('SELECT `spm_key` FROM `'.$tablePrefix.'spmcartoorder` WHERE `spm_key` = "'.addslashes($spm_key).'" AND `is_converted` = 1');
1018
+ if($test && isset($test['spm_key'])) return;
1019
+ }
1020
+
1021
+ //Cart already registred
1022
+ if($cookie->get('spmlastcartregister') && $cookie->get('spmlastcartregister') == $spm_key.$cart_id) return;
1023
+ $now = date('Y-m-d H:i:s');
1024
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
1025
+ $write->query('INSERT INTO `'.$tablePrefix.'spmcartoorder` (`id_cart`,`id_customer`,`email`,`spm_key`,`date_upd`) values ('.(int)$cart_id.','.(int)$customer_id.',"'.addslashes($customer_email).'","'.addslashes($spm_key).'","'.$now.'") ON DUPLICATE KEY UPDATE id_cart = '.(int)$cart_id.',id_customer = '.(int)$customer_id.', email="'.addslashes($customer_email).'", spm_key="'.addslashes($spm_key).'", date_upd="'.$now.'"');
1026
+ include_once(Mage::getBaseDir('base').'/app/code/local/SPM/ShopyMind/ShopymindClient/bin/Notify.php');
1027
+ if(ShopymindClient_Notify::newCart(array('idRemindersSend'=>$spm_key,'idCart'=>$cart_id,'totalCart'=>$quote->getGrandTotal(),'currencyCart'=>$quote->getQuoteCurrencyCode(),'taxRateCart'=>$quote->getStoreToQuoteRate()))) {
1028
+ $cookie->set('spmlastcartregister', $spm_key.$cart_id,0);/*keep cookie to avoid session problem */
1029
+ $cookie->delete('spmcartoorder');
1030
+ $cookie->delete('spmcartoorder_persistent');
1031
+ }
1032
+ }
1033
+ }
1034
+ }
1035
+ public static function checkNewOrder($order) {
1036
+ if(class_exists('ShopymindClient_CallbackOverride', false) && method_exists('ShopymindClient_CallbackOverride',__FUNCTION__)) return call_user_func_array(array('ShopymindClient_CallbackOverride', __FUNCTION__), func_get_args());
1037
+ $orderData = $order->getData();
1038
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
1039
+ $tablePrefix = Mage::getConfig()->getTablePrefix();
1040
+ $spm_key = $read->fetchRow('SELECT `spm_key` FROM `'.$tablePrefix.'spmcartoorder` WHERE (`id_cart` = '.(int)$orderData['quote_id'].') AND `date_upd` >= DATE_SUB("'.date('Y-m-d H:i:s').'", INTERVAL 1 MONTH) AND DATE_FORMAT(`date_add`,"%Y-%m-%d %H:%i:%s") < DATE_FORMAT("'.$orderData['created_at'].'","%Y-%m-%d %H:%i:%s") AND `is_converted` = 0 ORDER BY `date_add` DESC');
1041
+
1042
+ $voucherUsed = array();
1043
+ $vouchersOrder = $order->getCouponCode();
1044
+ if($vouchersOrder) $voucherUsed[] = $vouchersOrder;
1045
+
1046
+ if(sizeof($voucherUsed) && !$spm_key) {
1047
+ foreach($voucherUsed as $voucher) {
1048
+ if(!$spm_key && $voucher)
1049
+ $spm_key = $read->fetchRow('SELECT `spm_key` FROM `'.$tablePrefix.'spmcartoorder` WHERE (`voucher_number` = "'.addslashes($voucher).'") AND `date_upd` >= DATE_SUB("'.date('Y-m-d H:i:s').'", INTERVAL 1 MONTH) AND DATE_FORMAT(`date_add`,"%Y-%m-%d %H:%i:%s") < DATE_FORMAT("'.$orderData['created_at'].'","%Y-%m-%d %H:%i:%s") AND `is_converted` = 0 ORDER BY `date_add` DESC');
1050
+ else break;
1051
+ }
1052
+ }
1053
+
1054
+ if(!$spm_key)
1055
+ $spm_key = $read->fetchRow('SELECT `spm_key` FROM `'.$tablePrefix.'spmcartoorder` WHERE (`id_order` = '.(int)$orderData['entity_id'].') AND `date_upd` >= DATE_SUB("'.date('Y-m-d H:i:s').'", INTERVAL 1 MONTH) AND DATE_FORMAT(`date_add`,"%Y-%m-%d %H:%i:%s") < DATE_FORMAT("'.$orderData['created_at'].'","%Y-%m-%d %H:%i:%s") AND `is_converted` = 0 ORDER BY `date_add` DESC');
1056
+ if(!$spm_key && isset($orderData['customer_id']) && $orderData['customer_id'])
1057
+ $spm_key = $read->fetchRow('SELECT `spm_key` FROM `'.$tablePrefix.'spmcartoorder` WHERE (`id_customer` = '.(int)$orderData['customer_id'].') AND `date_upd` >= DATE_SUB("'.date('Y-m-d H:i:s').'", INTERVAL 1 MONTH) AND DATE_FORMAT(`date_add`,"%Y-%m-%d %H:%i:%s") < DATE_FORMAT("'.$orderData['created_at'].'","%Y-%m-%d %H:%i:%s") AND `is_converted` = 0 ORDER BY `date_add` DESC');
1058
+ if(!$spm_key && isset($orderData['customer_email']) && $orderData['customer_email'])
1059
+ $spm_key = $read->fetchRow('SELECT `spm_key` FROM `'.$tablePrefix.'spmcartoorder` WHERE (`email` = "'.$orderData['customer_email'].'") AND `date_upd` >= DATE_SUB("'.date('Y-m-d H:i:s').'", INTERVAL 1 MONTH) AND DATE_FORMAT(`date_add`,"%Y-%m-%d %H:%i:%s") < DATE_FORMAT("'.$orderData['created_at'].'","%Y-%m-%d %H:%i:%s") AND `is_converted` = 0 ORDER BY `date_add` DESC');
1060
+
1061
+
1062
+
1063
+ if($spm_key && isset($spm_key['spm_key']) && $spm_key['spm_key']) {
1064
+
1065
+ self::sendOrderToSPM( $order,$orderData,$spm_key['spm_key'],$voucherUsed);
1066
+ }
1067
+ }
1068
+ public static function sendOrderToSPM($order,$orderData,$spm_key,$voucherUsed) {
1069
+ if(class_exists('ShopymindClient_CallbackOverride', false) && method_exists('ShopymindClient_CallbackOverride',__FUNCTION__)) return call_user_func_array(array('ShopymindClient_CallbackOverride', __FUNCTION__), func_get_args());
1070
+
1071
+ include_once(Mage::getBaseDir('base').'/app/code/local/SPM/ShopyMind/ShopymindClient/bin/Notify.php');
1072
+ $quote = Mage::getSingleton('sales/quote')->load((int)$orderData['quote_id']);
1073
+ $params = array(
1074
+ 'idRemindersSend' => $spm_key,
1075
+ 'idCart' => $orderData['quote_id'],
1076
+ 'dateCart' => ($quote->getUpdatedAt() !== null && $quote->getUpdatedAt() !== ''?$quote->getUpdatedAt():$orderData ['created_at']),
1077
+ 'idOrder' => $orderData ['increment_id'],
1078
+ 'amount' => $orderData ['base_total_paid'],
1079
+ 'taxRate' => $orderData ['base_to_order_rate'],
1080
+ 'currency' => $orderData['order_currency_code'],
1081
+ 'dateOrder' => $orderData ['created_at'],
1082
+ 'voucherUsed' => $voucherUsed,
1083
+ 'customer' => self::getUser(($orderData['customer_id']?$orderData['customer_id']:$orderData['customer_email']))
1084
+ );
1085
+ $spm_key = ShopymindClient_Notify::newOrder($params);
1086
+ if($spm_key && isset($spm_key['idRemindersSend']) && $spm_key['idRemindersSend']) {
1087
+ $tablePrefix = Mage::getConfig()->getTablePrefix();
1088
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
1089
+ $write->query('UPDATE `'.$tablePrefix.'spmcartoorder` SET `is_converted` = 1 WHERE `spm_key` = "'.$spm_key['idRemindersSend'].'"');
1090
+ }
1091
+ }
1092
+ }
app/code/local/SPM/ShopyMind/ShopymindClient/configuration.php CHANGED
@@ -1,8 +1,11 @@
1
  <?php
 
 
 
2
  return array (
3
  'api' =>
4
  array (
5
- 'identifiant' => '',
6
- 'password' => '',
7
  ),
8
  );
1
  <?php
2
+ require_once dirname(__FILE__).'/../../../../../Mage.php';
3
+ umask(0);
4
+ Mage::app();
5
  return array (
6
  'api' =>
7
  array (
8
+ 'identifiant' => Mage::getStoreConfig('shopymind/configuration/apiidentification'),
9
+ 'password' => Mage::getStoreConfig('shopymind/configuration/apipassword'),
10
  ),
11
  );
app/code/local/SPM/ShopyMind/ShopymindClient/src/Client.php CHANGED
@@ -64,23 +64,23 @@ final class ShopymindClient_Client {
64
  ->setHeaders($config['header']['version'], $config['version'])
65
  ->setHeaders('version', $config['version']);
66
  }
67
- protected function formatString($value, $key, $options) {
68
- if (!empty($value)) {
69
- $options['glued_string'] .= $key.$options['glue'];
70
- $options['glued_string'] .= $value.$options['glue'];
71
- }
72
- }
73
- private function implode_recursive(array $array, $glue = ';') {
74
- $glued_string = '';
75
- // Recursively iterates array and adds key/value to glued string
76
- array_walk_recursive($array, array($this, 'formatString'), array('glue' => $glue, 'glued_string' => &$glued_string));
77
- // Removes last $glue from string
78
- strlen($glue) > 0 and $glued_string = substr($glued_string, 0, -strlen($glue));
79
-
80
- // Trim ALL whitespace
81
- $glued_string = preg_replace("/(\s)/ixsm", '', $glued_string);
82
-
83
- return (string) $glued_string;
84
  }
85
 
86
 
@@ -153,8 +153,14 @@ final class ShopymindClient_Client {
153
  public function sendRequest($method = 'GET') {
154
  global $SHOPYMIND_CLIENT_CONFIGURATION;
155
  $config = $SHOPYMIND_CLIENT_CONFIGURATION;
156
-
 
157
  $this->getClient()->setMethod($method);
 
 
 
 
 
158
  $token = $this->getToken();
159
  $this->getClient()->setHeaders($config['header']['hmac'], $token);
160
 
64
  ->setHeaders($config['header']['version'], $config['version'])
65
  ->setHeaders('version', $config['version']);
66
  }
67
+ protected function formatString($value, $key, $options) {
68
+ if (!empty($value)) {
69
+ $options['glued_string'] .= $key.$options['glue'];
70
+ $options['glued_string'] .= $value.$options['glue'];
71
+ }
72
+ }
73
+ private function implode_recursive(array $array, $glue = ';') {
74
+ $glued_string = '';
75
+ // Recursively iterates array and adds key/value to glued string
76
+ array_walk_recursive($array, array($this, 'formatString'), array('glue' => $glue, 'glued_string' => &$glued_string));
77
+ // Removes last $glue from string
78
+ strlen($glue) > 0 and $glued_string = substr($glued_string, 0, -strlen($glue));
79
+
80
+ // Trim ALL whitespace
81
+ $glued_string = preg_replace("/(\s)/ixsm", '', $glued_string);
82
+
83
+ return (string) $glued_string;
84
  }
85
 
86
 
153
  public function sendRequest($method = 'GET') {
154
  global $SHOPYMIND_CLIENT_CONFIGURATION;
155
  $config = $SHOPYMIND_CLIENT_CONFIGURATION;
156
+
157
+ //$this->getClient()->setAdapter('SZend_Http_Client_Adapter_Curl');
158
  $this->getClient()->setMethod($method);
159
+
160
+ $this->getClient()->setConfig(array(
161
+ 'timeout' => 10
162
+ )
163
+ );
164
  $token = $this->getToken();
165
  $this->getClient()->setHeaders($config['header']['hmac'], $token);
166
 
app/code/local/SPM/ShopyMind/ShopymindClient/src/Reminders/BirthdayClients.php CHANGED
@@ -44,7 +44,7 @@ class ShopymindClient_Reminders_BirthdayClients extends ShopymindClient_Reminder
44
  * @return array
45
  */
46
  public function get() {
47
- require dirname(__FILE__) . '/../../callback.php';
48
  if (method_exists('ShopymindClient_Callback', 'getBirthdayClients')) {
49
  return ShopymindClient_Callback::getBirthdayClients($this->getDateReference(), $this->getTimezones(), $this->getNbDays(), $this->getJustCount());
50
  }
44
  * @return array
45
  */
46
  public function get() {
47
+ require_once dirname(__FILE__) . '/../../callback.php';
48
  if (method_exists('ShopymindClient_Callback', 'getBirthdayClients')) {
49
  return ShopymindClient_Callback::getBirthdayClients($this->getDateReference(), $this->getTimezones(), $this->getNbDays(), $this->getJustCount());
50
  }
app/code/local/SPM/ShopyMind/ShopymindClient/src/Reminders/DroppedOutCart.php CHANGED
@@ -61,7 +61,7 @@ class ShopymindClient_Reminders_DroppedOutCart extends ShopymindClient_Reminders
61
  * @return array
62
  */
63
  public function get() {
64
- require dirname(__FILE__) . '/../../callback.php';
65
  if (method_exists('ShopymindClient_Callback', 'getDroppedOutCart')) {
66
  return ShopymindClient_Callback::getDroppedOutCart($this->getIntervalAction(), $this->getJustCount());
67
  }
61
  * @return array
62
  */
63
  public function get() {
64
+ require_once dirname(__FILE__) . '/../../callback.php';
65
  if (method_exists('ShopymindClient_Callback', 'getDroppedOutCart')) {
66
  return ShopymindClient_Callback::getDroppedOutCart($this->getIntervalAction(), $this->getJustCount());
67
  }
app/code/local/SPM/ShopyMind/ShopymindClient/src/Reminders/GoodClientsByAmount.php CHANGED
@@ -153,7 +153,7 @@ class ShopymindClient_Reminders_GoodClientsByAmount extends ShopymindClient_Remi
153
  }
154
 
155
  public function get() {
156
- require dirname(__FILE__) . '/../../callback.php';
157
  if (method_exists('ShopymindClient_Callback', 'getGoodClientsByAmount')) {
158
  return ShopymindClient_Callback::getGoodClientsByAmount($this->getDateReference(), $this->getTimezones(), $this->getAmount(), $this->getAmountMax(), $this->getNbDays(), $this->getNbDaysLastOrder(), $this->getJustCount());
159
  }
153
  }
154
 
155
  public function get() {
156
+ require_once dirname(__FILE__) . '/../../callback.php';
157
  if (method_exists('ShopymindClient_Callback', 'getGoodClientsByAmount')) {
158
  return ShopymindClient_Callback::getGoodClientsByAmount($this->getDateReference(), $this->getTimezones(), $this->getAmount(), $this->getAmountMax(), $this->getNbDays(), $this->getNbDaysLastOrder(), $this->getJustCount());
159
  }
app/code/local/SPM/ShopyMind/ShopymindClient/src/Reminders/GoodClientsByNumberOrders.php CHANGED
@@ -172,7 +172,7 @@ class ShopymindClient_Reminders_GoodClientsByNumberOrders extends ShopymindClien
172
  }
173
 
174
  public function get() {
175
- require dirname(__FILE__) . '/../../callback.php';
176
  if (method_exists('ShopymindClient_Callback', 'getGoodClientsByNumberOrders')) {
177
  return ShopymindClient_Callback::getGoodClientsByNumberOrders($this->getDateReference(), $this->getTimezones(), $this->getNumber(), $this->getNumberMax(), $this->getNbDays(), $this->getNbDaysLastOrder(), $this->getJustCount());
178
  }
172
  }
173
 
174
  public function get() {
175
+ require_once dirname(__FILE__) . '/../../callback.php';
176
  if (method_exists('ShopymindClient_Callback', 'getGoodClientsByNumberOrders')) {
177
  return ShopymindClient_Callback::getGoodClientsByNumberOrders($this->getDateReference(), $this->getTimezones(), $this->getNumber(), $this->getNumberMax(), $this->getNbDays(), $this->getNbDaysLastOrder(), $this->getJustCount());
178
  }
app/code/local/SPM/ShopyMind/ShopymindClient/src/Reminders/MissingClients.php CHANGED
@@ -96,7 +96,7 @@ class ShopymindClient_Reminders_MissingClients extends ShopymindClient_Reminders
96
  * @return array
97
  */
98
  public function get() {
99
- require dirname(__FILE__) . '/../../callback.php';
100
  if (method_exists('ShopymindClient_Callback', 'getMissingClients')) {
101
  return ShopymindClient_Callback::getMissingClients($this->getDateReference(), $this->getTimezones(), $this->getNbDays(), $this->getRelaunchOlder(), $this->getJustCount());
102
  }
96
  * @return array
97
  */
98
  public function get() {
99
+ require_once dirname(__FILE__) . '/../../callback.php';
100
  if (method_exists('ShopymindClient_Callback', 'getMissingClients')) {
101
  return ShopymindClient_Callback::getMissingClients($this->getDateReference(), $this->getTimezones(), $this->getNbDays(), $this->getRelaunchOlder(), $this->getJustCount());
102
  }
app/code/local/SPM/ShopyMind/ShopymindClient/src/Reminders/OrdersByStatus.php CHANGED
@@ -84,7 +84,7 @@ class ShopymindClient_Reminders_OrdersByStatus extends ShopymindClient_Reminders
84
  * @return array
85
  */
86
  public function get() {
87
- require dirname(__FILE__) . '/../../callback.php';
88
  if (method_exists('ShopymindClient_Callback', 'getOrdersStatus')) {
89
  return ShopymindClient_Callback::getOrdersByStatus($this->getDateReference(), $this->getTimezones(), $this->getNbDays(), $this->getIdStatus(), $this->getJustCount());
90
  }
84
  * @return array
85
  */
86
  public function get() {
87
+ require_once dirname(__FILE__) . '/../../callback.php';
88
  if (method_exists('ShopymindClient_Callback', 'getOrdersStatus')) {
89
  return ShopymindClient_Callback::getOrdersByStatus($this->getDateReference(), $this->getTimezones(), $this->getNbDays(), $this->getIdStatus(), $this->getJustCount());
90
  }
app/code/local/SPM/ShopyMind/ShopymindClient/src/Reminders/VoucherUnused.php CHANGED
@@ -117,7 +117,7 @@ class ShopymindClient_Reminders_VoucherUnused extends ShopymindClient_Reminders_
117
  * @return array
118
  */
119
  public function get() {
120
- require dirname(__FILE__) . '/../../callback.php';
121
  if (method_exists('ShopymindClient_Callback', 'getVoucherUnused')) {
122
  return ShopymindClient_Callback::getVoucherUnused($this->getDateReference(), $this->getTimezones(), $this->getNbDays(), $this->getStartBy(), $this->getJustCount());
123
  }
117
  * @return array
118
  */
119
  public function get() {
120
+ require_once dirname(__FILE__) . '/../../callback.php';
121
  if (method_exists('ShopymindClient_Callback', 'getVoucherUnused')) {
122
  return ShopymindClient_Callback::getVoucherUnused($this->getDateReference(), $this->getTimezones(), $this->getNbDays(), $this->getStartBy(), $this->getJustCount());
123
  }
app/code/local/SPM/ShopyMind/ShopymindClient/src/definitions.php CHANGED
@@ -14,11 +14,11 @@ return array(
14
  'type-request' => 'type-request',
15
  ),
16
 
17
- 'version' => '1.0.3.1',
18
 
19
  'api' => array(
20
  'salt' => 'zPz<j.[EaX,]$s3gzkCW;^N.2',
21
- 'url' => 'http://client.shopymind.com/rest'
22
  ),
23
 
24
  );
14
  'type-request' => 'type-request',
15
  ),
16
 
17
+ 'version' => '1.0.3.2',
18
 
19
  'api' => array(
20
  'salt' => 'zPz<j.[EaX,]$s3gzkCW;^N.2',
21
+ 'url' => 'https://client.shopymind.com/rest'
22
  ),
23
 
24
  );
app/code/local/SPM/ShopyMind/ShopymindClient/src/library/SZend/Loader.php CHANGED
@@ -227,7 +227,7 @@ class SZend_Loader
227
  /**
228
  * Security check
229
  */
230
- if (preg_match('/[^a-z0-9\\/\\\\_.-]/i', $filename)) {
231
  require_once dirname(__FILE__) . '/Exception.php';
232
  throw new SZend_Exception('Security check: Illegal character in filename');
233
  }
227
  /**
228
  * Security check
229
  */
230
+ if (preg_match('/[^a-z0-9\\/\\\\_.:-]/i', $filename)) {
231
  require_once dirname(__FILE__) . '/Exception.php';
232
  throw new SZend_Exception('Security check: Illegal character in filename');
233
  }
app/code/local/SPM/ShopyMind/controllers/Adminhtml/ConfigurationController.php CHANGED
@@ -4,9 +4,6 @@ class SPM_ShopyMind_Adminhtml_ConfigurationController extends Mage_Adminhtml_Con
4
  {
5
  public function indexAction()
6
  {
7
- if(!is_writable(Mage::getBaseDir('base').'/app/code/local/SPM/ShopyMind/ShopymindClient/configuration.php')) {
8
- Mage::getSingleton('adminhtml/session')->addError($this->__('File').' '.realpath(Mage::getBaseDir('base').'/app/code/local/SPM/ShopyMind/ShopymindClient/configuration.php').' '.$this->__('need to be writable'));
9
- }
10
  if(!function_exists('curl_init')) {
11
  Mage::getSingleton('adminhtml/session')->addError($this->__('Shopymind needs the PHP Curl extension, please ask your hosting provider to enable it prior to use this module.'));
12
  }
4
  {
5
  public function indexAction()
6
  {
 
 
 
7
  if(!function_exists('curl_init')) {
8
  Mage::getSingleton('adminhtml/session')->addError($this->__('Shopymind needs the PHP Curl extension, please ask your hosting provider to enable it prior to use this module.'));
9
  }
app/code/local/SPM/ShopyMind/controllers/AjaxController.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class SPM_ShopyMind_AjaxController extends Mage_Core_Controller_Front_Action {
3
+ public function indexAction() {
4
+ include_once(Mage::getBaseDir('base').'/app/code/local/SPM/ShopyMind/ShopymindClient/callback.php');
5
+ switch($this->getRequest()->getParam('action')) {
6
+ case 'frontCheck':
7
+ try {
8
+ $json_return = array('success'=>1);
9
+ //Check if cart following a reminder
10
+ ShopymindClient_Callback::checkNewCart();
11
+
12
+ //Get optin client for future retargeting service
13
+ if(Mage::getSingleton('customer/session')->isLoggedIn()) {
14
+ include_once(Mage::getBaseDir('base').'/app/code/local/SPM/ShopyMind/ShopymindClient/bin/Notify.php');
15
+ $cookie = Mage::app()->getCookie();
16
+ $email = Mage::getSingleton('customer/session')->getCustomer()->getEmail();
17
+ $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
18
+ if($subscriber->isSubscribed()) {
19
+ $customer = Mage::helper('customer')->getCustomer()->getData();
20
+ $params = array(
21
+ 'last_name' => @$customer['lastname'],
22
+ 'first_name' => @$customer['firstname'],
23
+ 'email_address' => @$customer['email'],
24
+ 'birthday' => @$customer['dob'],
25
+ 'locale' => self::getUserLocale($customer['entity_id'],$customer['store_id']),
26
+ 'gender' => @$customer['gender'],
27
+ 'ip' => Mage::helper('core/http')->getRemoteAddr()
28
+ );
29
+ $signature = sha1(serialize($params));
30
+ if($cookie->get('spmoptinchecksum') != '' && $cookie->get('spmoptinchecksum') == $signature) {
31
+
32
+ }else {
33
+ $optinkey = ShopymindClient_Notify::addOptInClient($params);
34
+ if($optinkey) {
35
+ $cookie->set('spmoptinchecksum', $signature, ((3600*24)*365));
36
+ $json_return['optinkey'] = $optinkey;
37
+ }
38
+ }
39
+ }
40
+ }
41
+ }catch (Exception $e) {
42
+ $json_return['success'] = 0;
43
+ $json_return['error'] = $e->getMessage();
44
+ }
45
+ echo json_encode($json_return);die;
46
+ break;
47
+ }
48
+ }
49
+ public static function getUserLocale($id_customer,$store_id) {
50
+ $locale_shop = Mage::getStoreConfig('general/locale/code', $store_id);
51
+ $customer = Mage::getModel('customer/customer')->load($id_customer);
52
+ $defaultBilling = $customer->getDefaultBillingAddress();
53
+ if($defaultBilling)
54
+ return substr($locale_shop,0,3).$defaultBilling->getCountry();
55
+ return $locale_shop;
56
+ }
57
+ }
58
+ ?>
app/code/local/SPM/ShopyMind/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <SPM_ShopyMind>
5
- <version>1.0.2</version>
6
  </SPM_ShopyMind>
7
  </modules>
8
 
@@ -41,25 +41,6 @@
41
  </SPM_ShopyMind_Model_Observer>
42
  </observers>
43
  </sales_order_invoice_pay>
44
-
45
- <controller_front_init_before>
46
- <observers>
47
- <SPM_ShopyMind_Model_Observer>
48
- <type>singleton</type>
49
- <class>shopymind/observer</class>
50
- <method>checkIsSPMUser</method>
51
- </SPM_ShopyMind_Model_Observer>
52
- </observers>
53
- </controller_front_init_before>
54
- <controller_action_layout_generate_blocks_before>
55
- <observers>
56
- <SPM_ShopyMind_Model_Observer>
57
- <type>singleton</type>
58
- <class>shopymind/observer</class>
59
- <method>frontCheck</method>
60
- </SPM_ShopyMind_Model_Observer>
61
- </observers>
62
- </controller_action_layout_generate_blocks_before>
63
  </events>
64
  </global>
65
 
@@ -119,6 +100,9 @@
119
  </layout>
120
  </adminhtml>
121
  <frontend>
 
 
 
122
  <layout>
123
  <updates>
124
  <shopymind>
2
  <config>
3
  <modules>
4
  <SPM_ShopyMind>
5
+ <version>1.1.2</version>
6
  </SPM_ShopyMind>
7
  </modules>
8
 
41
  </SPM_ShopyMind_Model_Observer>
42
  </observers>
43
  </sales_order_invoice_pay>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  </events>
45
  </global>
46
 
100
  </layout>
101
  </adminhtml>
102
  <frontend>
103
+ <secure_url>
104
+ <shopymind_ajax>/shopymind/index</shopymind_ajax>
105
+ </secure_url>
106
  <layout>
107
  <updates>
108
  <shopymind>
app/code/local/SPM/ShopyMind/sql/shopymind_setup/{mysql4-install-1.0.2.php → mysql4-install-1.1.2.php} RENAMED
File without changes
app/code/local/SPM/ShopyMind/sql/shopymind_setup/{upgrade-1.0.1-1.0.2.php → upgrade-1.0.0-1.1.2.php} RENAMED
File without changes
app/code/local/SPM/ShopyMind/sql/shopymind_setup/upgrade-1.0.1-1.1.2.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $installer = $this;
3
+ $installer->startSetup();
4
+ $installer->run ( "CREATE TABLE IF NOT EXISTS {$this->getTable('spmcartoorder')} (`id_cart` int(10) unsigned NOT NULL,`id_customer` int(10) unsigned NOT NULL DEFAULT '0',`id_order` int(10) unsigned NOT NULL DEFAULT '0',`spm_key` varchar(40) COLLATE utf8_bin NOT NULL DEFAULT '',`is_converted` tinyint(1) unsigned NOT NULL DEFAULT '0',`date_add` datetime NOT NULL,`date_upd` datetime NOT NULL,PRIMARY KEY (`spm_key`),KEY `is_converted` (`is_converted`),KEY `date_upd` (`date_upd`),KEY `date_add` (`date_add`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;" );
5
+ $installer->getConnection()->addColumn(
6
+ $installer->getTable('spmcartoorder'),
7
+ 'email',
8
+ array(
9
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
10
+ 'length' => 255,
11
+ 'unsigned' => true,
12
+ 'nullable' => true,
13
+ 'comment' => 'Customer email'
14
+ )
15
+ );
16
+ $installer->getConnection()->addIndex($installer->getTable('spmcartoorder'), 'email', 'email');
17
+
18
+ $installer->getConnection()->addColumn(
19
+ $installer->getTable('spmcartoorder'),
20
+ 'voucher_number',
21
+ array(
22
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
23
+ 'length' => 20,
24
+ 'unsigned' => true,
25
+ 'nullable' => true,
26
+ 'comment' => 'Voucher used'
27
+ )
28
+ );
29
+ $installer->getConnection()->addIndex($installer->getTable('spmcartoorder'), 'voucher_number', 'voucher_number');
30
+ $installer->endSetup();
31
+ ?>
app/code/local/SPM/ShopyMind/sql/shopymind_setup/upgrade-1.0.2-1.1.2.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $installer = $this;
3
+ $installer->startSetup();
4
+ $installer->run ( "CREATE TABLE IF NOT EXISTS {$this->getTable('spmcartoorder')} (`id_cart` int(10) unsigned NOT NULL,`id_customer` int(10) unsigned NOT NULL DEFAULT '0',`id_order` int(10) unsigned NOT NULL DEFAULT '0',`spm_key` varchar(40) COLLATE utf8_bin NOT NULL DEFAULT '',`is_converted` tinyint(1) unsigned NOT NULL DEFAULT '0',`date_add` datetime NOT NULL,`date_upd` datetime NOT NULL,PRIMARY KEY (`spm_key`),KEY `is_converted` (`is_converted`),KEY `date_upd` (`date_upd`),KEY `date_add` (`date_add`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;" );
5
+ $installer->getConnection()->addColumn(
6
+ $installer->getTable('spmcartoorder'),
7
+ 'email',
8
+ array(
9
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
10
+ 'length' => 255,
11
+ 'unsigned' => true,
12
+ 'nullable' => true,
13
+ 'comment' => 'Customer email'
14
+ )
15
+ );
16
+ $installer->getConnection()->addIndex($installer->getTable('spmcartoorder'), 'email', 'email');
17
+
18
+ $installer->getConnection()->addColumn(
19
+ $installer->getTable('spmcartoorder'),
20
+ 'voucher_number',
21
+ array(
22
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
23
+ 'length' => 20,
24
+ 'unsigned' => true,
25
+ 'nullable' => true,
26
+ 'comment' => 'Voucher used'
27
+ )
28
+ );
29
+ $installer->getConnection()->addIndex($installer->getTable('spmcartoorder'), 'voucher_number', 'voucher_number');
30
+ $installer->endSetup();
31
+ ?>
app/design/frontend/base/default/layout/shopymind.xml CHANGED
@@ -22,7 +22,7 @@
22
  -->
23
  <layout version="0.1.0">
24
  <default>
25
- <reference name="footer">
26
  <action method="unsetData"><key>cache_lifetime</key></action>
27
  <action method="unsetData"><key>cache_tags</key></action>
28
  <block type="core/template" name="shopymind_footer" template="shopymind/footer.phtml" />
22
  -->
23
  <layout version="0.1.0">
24
  <default>
25
+ <reference name="before_body_end">
26
  <action method="unsetData"><key>cache_lifetime</key></action>
27
  <action method="unsetData"><key>cache_tags</key></action>
28
  <block type="core/template" name="shopymind_footer" template="shopymind/footer.phtml" />
app/design/frontend/base/default/template/shopymind/footer.phtml CHANGED
@@ -1,30 +1,23 @@
1
- <?php
2
- if(Mage::getSingleton('customer/session')->isLoggedIn()) {
3
- $cookie = Mage::app()->getCookie();
4
-
5
- $email = Mage::getSingleton('customer/session')->getCustomer()->getEmail();
6
- $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
7
- if($subscriber->isSubscribed()) {
8
- $customer = Mage::helper('customer')->getCustomer()->getData();
9
- $params = array(
10
- 'last_name' => @$customer['lastname'],
11
- 'first_name' => @$customer['firstname'],
12
- 'email_address' => @$customer['email'],
13
- 'birthday' => @$customer['dob'],
14
- 'locale' => self::getUserLocale($customer['entity_id'],$customer['store_id']),
15
- 'gender' => @$customer['gender'],
16
- 'ip' => Mage::helper('core/http')->getRemoteAddr()
17
- );
18
- $signature = sha1(serialize($params));
19
- if($cookie->get('spmoptinchecksum') != '' && $cookie->get('spmoptinchecksum') == $signature) {
20
- return;
21
- }
22
- $optinkey = ShopymindClient_Notify::addOptInClient($params);
23
- if($optinkey) {
24
- $cookie->set('spmoptinchecksum', $signature, ((3600*24)*365));
25
- echo '<img src="http://client.shopymind.com/optin/'.$optinkey.'.png" style="display:none;" />';
26
- }
27
- }
28
- }
29
-
30
- ?>
1
+ <script type="text/javascript">
2
+ var xmlhttp;
3
+ if (window.XMLHttpRequest) {
4
+ xmlhttp=new XMLHttpRequest();
5
+ }
6
+ else {
7
+ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
8
+ }
9
+ xmlhttp.open("GET","<?php echo Mage::getUrl('shopymind/ajax/index', array('action' => 'frontCheck','spm_key' => (isset($_GET['spm_key']) && $_GET['spm_key'] ? $_GET['spm_key']:0)));?>",true);
10
+ xmlhttp.setRequestHeader('Content-type','application/json; charset=utf-8');
11
+ xmlhttp.onreadystatechange = function(){
12
+ if (xmlhttp.readyState != 4) return;
13
+ if (xmlhttp.status != 200 && xmlhttp.status != 304) {
14
+ return;
15
+ }
16
+ var result = JSON.parse(xmlhttp.responseText);
17
+ if(typeof(result.optinkey) !== 'undefined' && result.optinkey) {
18
+ var img = new Image();
19
+ img.src='https://client.shopymind.com/optin/'+result.optinkey+'.png';
20
+ }
21
+ }
22
+ xmlhttp.send();
23
+ </script>
 
 
 
 
 
 
 
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>shopymind</name>
4
- <version>1.0.2</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/GPL-3.0">GPL v3.0</license>
7
  <channel>community</channel>
@@ -9,11 +9,16 @@
9
  <summary>Connecteur pour le service d'email marketing ShopyMind</summary>
10
  <description>Connecteur pour le service d'email marketing ShopyMind</description>
11
  <notes>Compatibilit&#xE9; guest order&#xD;
12
- Prise en charge fonctionnalit&#xE9;s de segmentation avanc&#xE9;es</notes>
 
 
 
 
 
13
  <authors><author><name>Jean-S&#xE9;bastien</name><user>shopymind</user><email>contact@shopymind.com</email></author></authors>
14
- <date>2014-04-07</date>
15
- <time>15:57:45</time>
16
- <contents><target name="magelocal"><dir name="SPM"><dir name="ShopyMind"><dir name="Block"><file name="Configuration.php" hash="d41d8cd98f00b204e9800998ecf8427e"/></dir><dir name="Helper"><file name="Data.php" hash="233ff6d4066636dfe76a6d0fcc3837ea"/></dir><dir name="Model"><file name="Observer.php" hash="e301e143c0484d7398c8e4602a4841f0"/></dir><dir name="ShopymindClient"><dir name="bin"><file name="Configuration.php" hash="f3d0cef466e2394cb822ac27e003951e"/><file name="Notify.php" hash="1c1d359da754b2abe0ab874ef43e535b"/><file name="RequestServer.php" hash="98f6647a822f8c3b81fa5b1e1b9befee"/></dir><file name="call.php" hash="42e156192ce1399a3304918e0e399898"/><file name="callback.php" hash="79c59da98f597a08c003c196b291b736"/><file name="configuration.php" hash="8bceaafd452353a9d354ecd1edb197b3"/><dir name="doc"><file name="CHANGELOG.md" hash="83e5eac956d477a6d375c39a7f2d786f"/><file name="README.md" hash="fb69c4a24b741a83ce6d52f737e27188"/></dir><dir name="src"><file name="Client.php" hash="dd15a8676a86cd2b43085a57ce97b696"/><dir name="Reminders"><file name="Abstract.php" hash="50931470009af2fa17b8ed0f0cbda115"/><file name="BirthdayClients.php" hash="83ade73e1b70e8b7e6534890f6929d52"/><file name="DroppedOutCart.php" hash="6534d4a827131294a29389addf7eb0fa"/><file name="GoodClientsByAmount.php" hash="dd2d1d7fd57bfb04cc3ecf2d0b81edf9"/><file name="GoodClientsByNumberOrders.php" hash="7a7a8e82e4527efb7c582edd0441abbd"/><file name="MissingClients.php" hash="eaef3516c7e02c5f60fba29234f81fb4"/><file name="OrdersByStatus.php" hash="998d5a9a571cc50d839c0d5fd313731a"/><file name="VoucherUnused.php" hash="64c1258b19d80cf5d444875c194dcb27"/></dir><file name="Server.php" hash="16454422468e0e4ef20dc52638f0e3f5"/><file name="definitions.php" hash="fc658b642d678ba252304cd073652fe4"/><dir name="library"><dir name="SZend"><dir name="Controller"><file name="Exception.php" hash="f1237afdaffbd144257b107770618eac"/><dir name="Request"><file name="Abstract.php" hash="54596831d5dc5fda331e393b8a478379"/><file name="Exception.php" hash="cc838555e9115befa50dc1af49b17577"/><file name="Http.php" hash="4dd5b595b9fc44e815040e2e6ba689ba"/></dir></dir><file name="Exception.php" hash="2bf61e21546b8f0aa3b2769355f2dc7e"/><dir name="Http"><dir name="Client"><dir name="Adapter"><file name="Exception.php" hash="2537f0b6f539f8e48c038324a0d628e8"/><file name="Interface.php" hash="d999c7f241a1f19af0e8865cb9b5d10d"/><file name="Proxy.php" hash="4981dc0fcd46adb3a43af4eac257d8e9"/><file name="Socket.php" hash="9ebca7242be11891ebd9bc49209ff09b"/><file name="Test.php" hash="176910209997f08742c9b01bbc3d5a7c"/></dir><file name="Exception.php" hash="6e1996a825c541b3b88e3d85e85a20ba"/></dir><file name="Client.php" hash="f2242e7dd86105a877ad5aa0d12e4f50"/><file name="Exception.php" hash="1fa7eabe51eecc8296610f3767215413"/><file name="Response.php" hash="fb8acaa8d9c3993ecc01efce0b372ae6"/></dir><dir name="Json"><file name="Decoder.php" hash="5d93754ec797bad1a110728389c3ee8c"/><file name="Encoder.php" hash="a84449a2792fad49e7d1aa7d783ec174"/><file name="Exception.php" hash="96e6fefe64b68c5ef4848af6d0bb4e82"/></dir><file name="Json.php" hash="0695e495093dbfa46fb57e7ad9579aac"/><file name="Loader.php" hash="5e3ae1b4235fcb6aad2a67ea98f3d2b8"/><dir name="Uri"><file name="Exception.php" hash="3883d68acc73300df64e1c985c57cf75"/><file name="Http.php" hash="e956bd37f9ec96b19d3429fbe8d50f09"/></dir><file name="Uri.php" hash="8a04b4728ad7b609143e9060e110e1d1"/><dir name="Validate"><file name="Abstract.php" hash="c5e7fafa362afe2809abfd63a481d46b"/><dir name="Hostname"><file name="At.php" hash="0e553eeab4854d0acc2b278a83e6ae4d"/><file name="Ch.php" hash="56959ede41ad28062c0a02c35a6325bd"/><file name="De.php" hash="860ad7d2c007980dcc9935ffafdfb47f"/><file name="Fi.php" hash="46b399d55d8f6d60eace39a9d04a0a20"/><file name="Hu.php" hash="aace5a75ab79a6b3730cdcd500b9cfbb"/><file name="Interface.php" hash="5e04ae45e72d695d45d19d4893722718"/><file name="Li.php" hash="ea875839c91646e73ef3e75a2da27a2e"/><file name="No.php" hash="42f57854fe2f265c48d131b999535a4c"/><file name="Se.php" hash="3ab64c0f1c4a8d404c2b92f40d8b9c49"/></dir><file name="Hostname.php" hash="2d8942bfa2d462f712c16e9bbbd7a637"/><file name="Interface.php" hash="2269e3299d88d13b1e73ba3f0b8c9619"/><file name="Ip.php" hash="3f12e46be79290359362e65f829ff52d"/></dir></dir></dir></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="ConfigurationController.php" hash="30e6fdc25bf5ebc63d332173fa3341e7"/></dir></dir><dir name="etc"><file name="config.xml" hash="49bd477f361d7d3ec7d2e8a2f83d34b1"/></dir><dir name="sql"><dir name="shopymind_setup"><file name="mysql4-install-1.0.2.php" hash="8c0be5e2d86533c6789f59571ae35295"/><file name="upgrade-1.0.0-1.0.1.php" hash=""/><file name="upgrade-1.0.1-1.0.2.php" hash="8c0be5e2d86533c6789f59571ae35295"/></dir></dir><file name=".htaccess" hash="a04a22aa9c4e19789afcc2d4f1b23fce"/></dir></dir></target><target name="mageetc"><dir name="modules"><file name="SPM_ShopyMind.xml" hash="33bac8c042bc58f7d15565e8e95a8d25"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="shopymind.xml" hash="cf7214ff0b2df43a38908b53e8ab92ff"/></dir><dir name="template"><dir name="shopymind"><file name="configuration.phtml" hash="177d33849e46e5700f157a121331d7a3"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="shopymind.xml" hash="707507d1f3dca58ba918eb2dec3a276f"/></dir><dir name="template"><dir name="shopymind"><file name="footer.phtml" hash="3538f2a0052c65aeb1e7887fe47fe828"/></dir></dir></dir></dir></dir></target></contents>
17
  <compatible/>
18
  <dependencies><required><php><min>5.0.0</min><max>6.0.0</max></php></required></dependencies>
19
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>shopymind</name>
4
+ <version>1.1.2</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/GPL-3.0">GPL v3.0</license>
7
  <channel>community</channel>
9
  <summary>Connecteur pour le service d'email marketing ShopyMind</summary>
10
  <description>Connecteur pour le service d'email marketing ShopyMind</description>
11
  <notes>Compatibilit&#xE9; guest order&#xD;
12
+ Prise en charge fonctionnalit&#xE9;s de segmentation avanc&#xE9;es&#xD;
13
+ Appels vers shopymind en ajax asynchrone&#xD;
14
+ Gestion des erreurs silencieuses&#xD;
15
+ Test sur Magento 1.9.0.1&#xD;
16
+ Suppression message d'erreur sur les droits du fichier de configuration&#xD;
17
+ Modification hooking footer (before_body_end in replacement of footer)</notes>
18
  <authors><author><name>Jean-S&#xE9;bastien</name><user>shopymind</user><email>contact@shopymind.com</email></author></authors>
19
+ <date>2014-09-01</date>
20
+ <time>12:40:15</time>
21
+ <contents><target name="magelocal"><dir name="SPM"><dir name="ShopyMind"><dir name="Block"><file name="Configuration.php" hash="d41d8cd98f00b204e9800998ecf8427e"/></dir><dir name="Helper"><file name="Data.php" hash="233ff6d4066636dfe76a6d0fcc3837ea"/></dir><dir name="Model"><file name="Observer.php" hash="683b72fd6feaf47de9dd10729273ad16"/></dir><dir name="ShopymindClient"><dir name="bin"><file name="Configuration.php" hash="f9b308b90ee9c07b81c87e7d37493e8e"/><file name="Notify.php" hash="1c1d359da754b2abe0ab874ef43e535b"/><file name="RequestServer.php" hash="98f6647a822f8c3b81fa5b1e1b9befee"/></dir><file name="call.php" hash="5ada42c2c109a0e0756569f0364e3dc5"/><file name="callback.php" hash="7c87250c87932b3eac19f5c2fe29c1ce"/><file name="configuration.php" hash="3d16bab4ef985407cf0eeb100d9ae295"/><dir name="doc"><file name="CHANGELOG.md" hash="83e5eac956d477a6d375c39a7f2d786f"/><file name="README.md" hash="fb69c4a24b741a83ce6d52f737e27188"/></dir><dir name="src"><file name="Client.php" hash="012d0b8dff053606c8d9013ea9d9e044"/><dir name="Reminders"><file name="Abstract.php" hash="50931470009af2fa17b8ed0f0cbda115"/><file name="BirthdayClients.php" hash="a0d078800732a43831f1a554f3c65035"/><file name="DroppedOutCart.php" hash="6b8326b61b5a379c4ecb20e860721f8c"/><file name="GoodClientsByAmount.php" hash="ec057a0b35fff3cdad955b714d4a9f37"/><file name="GoodClientsByNumberOrders.php" hash="114ce84e673bc6415e0425ab2b570bdf"/><file name="MissingClients.php" hash="1f2376c0a7a39356bf6b17d3e7feb6d1"/><file name="OrdersByStatus.php" hash="16cbe6988239538256b66efc16e2d7ef"/><file name="VoucherUnused.php" hash="5bd950ddcf2a6075152882c0ccae0a6f"/></dir><file name="Server.php" hash="16454422468e0e4ef20dc52638f0e3f5"/><file name="definitions.php" hash="ce3a713e2c682df50961b62e2d3e325b"/><dir name="library"><dir name="SZend"><dir name="Controller"><file name="Exception.php" hash="f1237afdaffbd144257b107770618eac"/><dir name="Request"><file name="Abstract.php" hash="54596831d5dc5fda331e393b8a478379"/><file name="Exception.php" hash="cc838555e9115befa50dc1af49b17577"/><file name="Http.php" hash="4dd5b595b9fc44e815040e2e6ba689ba"/></dir></dir><file name="Exception.php" hash="2bf61e21546b8f0aa3b2769355f2dc7e"/><dir name="Http"><dir name="Client"><dir name="Adapter"><file name="Exception.php" hash="2537f0b6f539f8e48c038324a0d628e8"/><file name="Interface.php" hash="d999c7f241a1f19af0e8865cb9b5d10d"/><file name="Proxy.php" hash="4981dc0fcd46adb3a43af4eac257d8e9"/><file name="Socket.php" hash="9ebca7242be11891ebd9bc49209ff09b"/><file name="Test.php" hash="176910209997f08742c9b01bbc3d5a7c"/></dir><file name="Exception.php" hash="6e1996a825c541b3b88e3d85e85a20ba"/></dir><file name="Client.php" hash="f2242e7dd86105a877ad5aa0d12e4f50"/><file name="Exception.php" hash="1fa7eabe51eecc8296610f3767215413"/><file name="Response.php" hash="fb8acaa8d9c3993ecc01efce0b372ae6"/></dir><dir name="Json"><file name="Decoder.php" hash="5d93754ec797bad1a110728389c3ee8c"/><file name="Encoder.php" hash="a84449a2792fad49e7d1aa7d783ec174"/><file name="Exception.php" hash="96e6fefe64b68c5ef4848af6d0bb4e82"/></dir><file name="Json.php" hash="0695e495093dbfa46fb57e7ad9579aac"/><file name="Loader.php" hash="88166e517fa41a4b32db60f1d36f5965"/><dir name="Uri"><file name="Exception.php" hash="3883d68acc73300df64e1c985c57cf75"/><file name="Http.php" hash="e956bd37f9ec96b19d3429fbe8d50f09"/></dir><file name="Uri.php" hash="8a04b4728ad7b609143e9060e110e1d1"/><dir name="Validate"><file name="Abstract.php" hash="c5e7fafa362afe2809abfd63a481d46b"/><dir name="Hostname"><file name="At.php" hash="0e553eeab4854d0acc2b278a83e6ae4d"/><file name="Ch.php" hash="56959ede41ad28062c0a02c35a6325bd"/><file name="De.php" hash="860ad7d2c007980dcc9935ffafdfb47f"/><file name="Fi.php" hash="46b399d55d8f6d60eace39a9d04a0a20"/><file name="Hu.php" hash="aace5a75ab79a6b3730cdcd500b9cfbb"/><file name="Interface.php" hash="5e04ae45e72d695d45d19d4893722718"/><file name="Li.php" hash="ea875839c91646e73ef3e75a2da27a2e"/><file name="No.php" hash="42f57854fe2f265c48d131b999535a4c"/><file name="Se.php" hash="3ab64c0f1c4a8d404c2b92f40d8b9c49"/></dir><file name="Hostname.php" hash="2d8942bfa2d462f712c16e9bbbd7a637"/><file name="Interface.php" hash="2269e3299d88d13b1e73ba3f0b8c9619"/><file name="Ip.php" hash="3f12e46be79290359362e65f829ff52d"/></dir></dir></dir></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="ConfigurationController.php" hash="e9b13307a219947c9960de465f290e3b"/></dir><file name="AjaxController.php" hash="08f3eaee733ed784a09fb10f5b28b9de"/></dir><dir name="etc"><file name="config.xml" hash="6ea17dc34a7f7189797de3201e4fb221"/></dir><dir name="sql"><dir name="shopymind_setup"><file name="mysql4-install-1.1.2.php" hash="8c0be5e2d86533c6789f59571ae35295"/><file name="upgrade-1.0.0-1.1.2.php" hash="8c0be5e2d86533c6789f59571ae35295"/><file name="upgrade-1.0.1-1.1.2.php" hash="8c0be5e2d86533c6789f59571ae35295"/><file name="upgrade-1.0.2-1.1.2.php" hash="8c0be5e2d86533c6789f59571ae35295"/></dir></dir><file name=".htaccess" hash="a04a22aa9c4e19789afcc2d4f1b23fce"/></dir></dir></target><target name="mageetc"><dir name="modules"><file name="SPM_ShopyMind.xml" hash="33bac8c042bc58f7d15565e8e95a8d25"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="shopymind.xml" hash="cf7214ff0b2df43a38908b53e8ab92ff"/></dir><dir name="template"><dir name="shopymind"><file name="configuration.phtml" hash="177d33849e46e5700f157a121331d7a3"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="shopymind.xml" hash="e4d6aec6f724d0a9d1ea99238132444b"/></dir><dir name="template"><dir name="shopymind"><file name="footer.phtml" hash="403c61dae813fa3e3c60d7af95cf27a8"/></dir></dir></dir></dir></dir></target></contents>
22
  <compatible/>
23
  <dependencies><required><php><min>5.0.0</min><max>6.0.0</max></php></required></dependencies>
24
  </package>