mailplatformconnector - Version 2.0.1

Version Notes

Changed code style to PSR-2
Moved code files from local to community
Removed unnecessary files
Removed unnecessary code lines
Removed unnecessary code logic
Fixed file names
Alternated code by Magento standards
Corrected English grammar
Tested on Magento CE 1.7, 1.8 and 1.9

Download this release

Release Info

Developer ADEO WEB
Extension mailplatformconnector
Version 2.0.1
Comparing to
See all releases


Code changes from version 1.0.1 to 2.0.1

Files changed (26) hide show
  1. app/code/community/Mp/Mailplatform/Block/Adminhtml/Newsletter/Subscriber.php +1 -1
  2. app/code/community/Mp/Mailplatform/Block/Adminhtml/System/Config/Form/Button/Synccategories.php +64 -0
  3. app/code/community/Mp/Mailplatform/Helper/Data.php +80 -2
  4. app/code/community/Mp/Mailplatform/Model/Cron.php +110 -0
  5. app/code/community/Mp/Mailplatform/Model/Customfields.php +58 -0
  6. app/code/community/Mp/Mailplatform/Model/Listids.php +12 -61
  7. app/code/community/Mp/Mailplatform/Model/Lists.php +20 -0
  8. app/code/community/Mp/Mailplatform/Model/Mailplatform.php +0 -283
  9. app/code/community/Mp/Mailplatform/Model/Mailplatform/Emailtype.php +0 -14
  10. app/code/community/Mp/Mailplatform/Model/Mailplatform/Listids.php +0 -92
  11. app/code/community/Mp/Mailplatform/Model/Mailplatform/Mailplatform.php +0 -344
  12. app/code/community/Mp/Mailplatform/Model/Newsletter/Subscriber.php +23 -98
  13. app/code/community/Mp/Mailplatform/Model/Observer.php +92 -0
  14. app/code/community/Mp/Mailplatform/Model/Request.php +252 -0
  15. app/code/community/Mp/Mailplatform/Model/Subscribers.php +139 -0
  16. app/code/community/Mp/Mailplatform/controllers/AccountController.php +0 -105
  17. app/code/community/Mp/Mailplatform/controllers/Adminhtml/MailplatformController.php +23 -0
  18. app/code/community/Mp/Mailplatform/controllers/IndexController.php +0 -21
  19. app/code/community/Mp/Mailplatform/etc/config.xml +68 -17
  20. app/code/community/Mp/Mailplatform/etc/system.xml +136 -5
  21. app/code/community/Mp/Mailplatform/sql/mp_mailplatform_setup/mysql4-install-0.0.1.php +0 -0
  22. app/design/adminhtml/default/default/template/mailplatform/system/config/button.phtml +17 -0
  23. app/design/frontend/base/default/layout/mailplatform.xml +8 -0
  24. app/design/frontend/base/default/template/mailplatform/checkout/subscribe.phtml +14 -0
  25. app/etc/modules/Mp_Mailplattform.xml +0 -9
  26. package.xml +6 -6
app/code/community/Mp/Mailplatform/Block/Adminhtml/Newsletter/Subscriber.php CHANGED
@@ -10,6 +10,6 @@ class Mp_mailplatform_Block_Adminhtml_Newsletter_Subscriber extends Mage_Adminht
10
 
11
  public function getmailplatformSyn()
12
  {
13
- return $this->getUrl('mailplatform/index/index');
14
  }
15
  }
10
 
11
  public function getmailplatformSyn()
12
  {
13
+ return $this->getUrl('adminhtml/mailplatform/index');
14
  }
15
  }
app/code/community/Mp/Mailplatform/Block/Adminhtml/System/Config/Form/Button/Synccategories.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Mp_Mailplatform_Block_Adminhtml_System_Config_Form_Button_Synccategories extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+
6
+ /*
7
+ * Set template
8
+ */
9
+ protected function _construct()
10
+ {
11
+ parent::_construct();
12
+ $this->setTemplate('mailplatform/system/config/button.phtml');
13
+ }
14
+
15
+ /**
16
+ * Return element html
17
+ *
18
+ * @param Varien_Data_Form_Element_Abstract $element
19
+ * @return string
20
+ */
21
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
22
+ {
23
+ return $this->_toHtml();
24
+ }
25
+
26
+ /**
27
+ * Return ajax url for button
28
+ *
29
+ * @return string
30
+ */
31
+ public function getAjaxCheckUrl()
32
+ {
33
+ return Mage::helper('adminhtml')->getUrl('adminhtml/mailplatform/syncCategories');
34
+ }
35
+
36
+ /**
37
+ * Generate button html
38
+ *
39
+ * @return string
40
+ */
41
+ public function getButtonHtml()
42
+ {
43
+ $button = $this->getLayout()
44
+ ->createBlock('adminhtml/widget_button')
45
+ ->setData(
46
+ array(
47
+ 'id' => $this->getButtonId(),
48
+ 'label' => $this->helper('adminhtml')->__('Sync'),
49
+ )
50
+ );
51
+
52
+ return $button->toHtml();
53
+ }
54
+
55
+ public function getButtonId()
56
+ {
57
+ return 'sync_categories';
58
+ }
59
+
60
+ public function getResponseFieldId()
61
+ {
62
+ return 'sync_categories_response';
63
+ }
64
+ }
app/code/community/Mp/Mailplatform/Helper/Data.php CHANGED
@@ -1,6 +1,84 @@
1
  <?php
 
2
  class Mp_Mailplatform_Helper_Data extends Mage_Core_Helper_Abstract
3
  {
4
 
5
- }
6
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
+
3
  class Mp_Mailplatform_Helper_Data extends Mage_Core_Helper_Abstract
4
  {
5
 
6
+ public function isEnabled()
7
+ {
8
+ $requestUri = Mage::app()->getRequest()->getRequestUri();
9
+
10
+ if (
11
+ Mage::getStoreConfig('mailplatform/general/active') == true
12
+ && $this->getUsername() != ''
13
+ && $this->getToken() != ''
14
+ && $this->getListId() != ''
15
+ && (strstr($requestUri, 'newsletter/')
16
+ || strstr($requestUri, 'newsletter_subscriber/')
17
+ || strstr($requestUri, 'customer/')
18
+ || strstr($requestUri, 'mailplatform/index')
19
+ || strstr($requestUri, 'checkout/onepage/'))
20
+ )
21
+ {
22
+ return true;
23
+ }
24
+
25
+ if (Mage::app()->getStore()->getId() == 0) {
26
+ if (Mage::getStoreConfig('mailplatform/general/active') != true)
27
+ Mage::getSingleton('adminhtml/session')->addError('Mailplatform Configuration Error: Mailplatform is innactive');
28
+ if ($this->getUsername() == '')
29
+ Mage::getSingleton('adminhtml/session')->addError('Mailplatform Configuration Error: API Username field is empty');
30
+ if ($this->getToken() == '')
31
+ Mage::getSingleton('adminhtml/session')->addError('Mailplatform Configuration Error: API Token field is empty');
32
+ if ($this->getListId() == '')
33
+ Mage::getSingleton('adminhtml/session')->addError('Mailplatform Configuration Error: Mailplatform list field is empty');
34
+ }
35
+
36
+ return false;
37
+ }
38
+
39
+ public function logError()
40
+ {
41
+ return Mage::getStoreConfig('mailplatform/log/error');
42
+ }
43
+
44
+ public function logSuccess()
45
+ {
46
+ return Mage::getStoreConfig('mailplatform/log/success');
47
+ }
48
+
49
+ public function getLogFileName()
50
+ {
51
+ return Mage::getStoreConfig('mailplatform/log/file_name');
52
+ }
53
+
54
+ public function getListId()
55
+ {
56
+ return trim(Mage::getStoreConfig('mailplatform/general/listid'));
57
+ }
58
+
59
+ public function getToken()
60
+ {
61
+ return trim(Mage::getStoreConfig('mailplatform/general/token'));
62
+ }
63
+
64
+ public function getUsername()
65
+ {
66
+ return trim(Mage::getStoreConfig('mailplatform/general/username'));
67
+ }
68
+
69
+ public function getFormat()
70
+ {
71
+ return trim(Mage::getStoreConfig('mailplatform/general/format'));
72
+ }
73
+
74
+ public function getUrl()
75
+ {
76
+ return trim(Mage::getStoreConfig('mailplatform/general/url'));
77
+ }
78
+
79
+ public function getCronTab($crontab)
80
+ {
81
+ return (boolean) Mage::getStoreConfig('mailplatform/crontab/' . $crontab);
82
+ }
83
+
84
+ }
app/code/community/Mp/Mailplatform/Model/Cron.php ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Mp_Mailplatform_Model_Cron {
4
+
5
+ public function sync($crontab = true) {
6
+ if (! Mage::helper('mailplatform')->getCronTab('sync_subscribers') && $crontab) {
7
+ return $this;
8
+ }
9
+
10
+ // collect all subscribers users
11
+ $collectionarray = Mage::getResourceModel('newsletter/subscriber_collection')->showStoreInfo()
12
+ ->showCustomerInfo()
13
+ ->useOnlySubscribed()
14
+ ->toArray()
15
+ ;
16
+
17
+ if ($collectionarray['totalRecords'] == 0) {
18
+ return $this;
19
+ }
20
+
21
+ $items = $collectionarray['items'];
22
+
23
+ $customerInList = array();
24
+
25
+ foreach ($items as $item) {
26
+ $customerInList[$item['store_id']][] = $item['subscriber_email'];
27
+ }
28
+
29
+ try {
30
+ foreach ($customerInList as $storeId => $emails) {
31
+ $this->_bulkCustomers($storeId, $emails, $crontab);
32
+ }
33
+
34
+ Mage::app()->setCurrentStore(0);
35
+ } catch (Exception $e) {
36
+ if (! $crontab) {
37
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
38
+ }
39
+ }
40
+
41
+ return $this;
42
+ }
43
+
44
+ protected function _bulkCustomers($storeId, $emails, $crontab) {
45
+ Mage::app()->setCurrentStore($storeId);
46
+
47
+ $subscribers = Mage::getModel('mailplatform/subscribers');
48
+
49
+ foreach ($emails as $email) {
50
+ $isSubscriber = $subscribers->isSubscriberOnList($email);
51
+
52
+ if ($isSubscriber === true) {
53
+ $result = $subscribers->activateSubscriber($email);
54
+ if ($result && ! $crontab) {
55
+ Mage::getSingleton('adminhtml/session')->addSuccess("Mailplatform - " . $email . " updated.");
56
+ } elseif (! $crontab) {
57
+ Mage::getSingleton('adminhtml/session')->addError("Mailplatform - " . $subscribers->getErrorMessage() . '<br/>');
58
+ }
59
+ } else {
60
+ $details['confirmed'] = true;
61
+ $result = $subscribers->addSubscriberToList($email, null, $details);
62
+
63
+ if ($result && ! $crontab) {
64
+ Mage::getSingleton('adminhtml/session')->addSuccess("Mailplatform - " . $email . " added to list.");
65
+ } elseif (! $crontab) {
66
+ Mage::getSingleton('adminhtml/session')->addError("Mailplatform - " . $subscribers->getErrorMessage() . '<br/>');
67
+ }
68
+ }
69
+ }
70
+
71
+ return $this;
72
+ }
73
+
74
+ public function updateCategories($crontab = true)
75
+ {
76
+ if (! Mage::helper('mailplatform')->getCronTab('sync_categories') && $crontab) {
77
+ return $this;
78
+ }
79
+
80
+ $customField = Mp_Mailplatform_Model_Subscribers::getCustomFieldId('product_categories');
81
+
82
+ if (! $customField) {
83
+ return $this;
84
+ }
85
+
86
+ $categories = Mage::getModel('catalog/category')
87
+ ->getCollection()
88
+ ->addAttributeToSelect(array('entity_id', 'name'))
89
+ ->addIsActiveFilter()
90
+ ;
91
+
92
+ if (! $categories->count()) {
93
+ return $this;
94
+ }
95
+
96
+ $data = array();
97
+
98
+ foreach ($categories as $id => $category) {
99
+ $data['keys'][] = $category->getId();
100
+ $data['values'][] = $category->getName();
101
+ }
102
+
103
+ $customfields = Mage::getModel('mailplatform/customfields');
104
+
105
+ $customfields->update('checkbox', $customField, $data);
106
+
107
+ return $this;
108
+ }
109
+
110
+ }
app/code/community/Mp/Mailplatform/Model/Customfields.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Mp_Mailplatform_Model_Customfields extends Mp_Mailplatform_Model_Request
4
+ {
5
+ protected function _construct()
6
+ {
7
+ parent::_construct();
8
+
9
+ $this->setRequestType('Customfields');
10
+ }
11
+
12
+ public function update($type, $fieldId, $values)
13
+ {
14
+ $this->setRequestMethod('Update');
15
+
16
+ switch ($type) {
17
+ case 'checkbox':
18
+ $response = $this->_updateCheckbox($fieldId, $values);
19
+ break;
20
+ default:
21
+ $response = false;
22
+ }
23
+
24
+ return $response;
25
+ }
26
+
27
+ protected function _updateCheckbox($fieldId, array $data)
28
+ {
29
+ if (empty($data)) {
30
+ return $this;
31
+ }
32
+
33
+ if (! isset($data['keys']) || ! isset($data['values'])) {
34
+ Mage::throwException('Custom field type checkbox need keys and values.');
35
+ }
36
+
37
+ $details['fieldid'] = $fieldId;
38
+
39
+ $this->addDetails($details);
40
+
41
+ $details = $this->_xml->details;
42
+
43
+ if (! $details) {
44
+ Mage::throwException('XML tree don\'t have details branch.');
45
+ }
46
+
47
+ $settings = $details->addChild('Settings');
48
+
49
+ $keys = implode(',', $data['keys']);
50
+ $values = implode(',', $data['values']);
51
+
52
+ $settings->addChild('Key', self::xmlEscape($keys));
53
+ $settings->addChild('Value', self::xmlEscape($values));//Can see
54
+
55
+ return $this->send();
56
+ }
57
+
58
+ }
app/code/community/Mp/Mailplatform/Model/Listids.php CHANGED
@@ -5,84 +5,35 @@ class Mp_Mailplatform_Model_Listids extends Varien_Object
5
 
6
  protected $_options;
7
 
8
- protected $_lists = array();
9
-
10
- protected function getmodeloptions()
11
- {
12
- return Mage::getModel('mailplatform/mailplatform');
13
- }
14
-
15
  public function toOptionArray($isMultiselect = false)
16
  {
17
  if (! $this->_options) {
18
- $arrresult = explode("/", Mage::app()->getRequest()->getRequestUri());
19
 
20
- $i = 0;
21
- $store = "";
22
- $storetoload = 0;
23
- foreach ($arrresult as $arr) {
24
- if ($arr == "store") {
25
- $store = $arrresult[$i + 1];
26
- }
27
- $i ++;
28
- }
29
-
30
- $allstores = Mage::getModel('core/store')->getCollection();
31
-
32
- foreach ($allstores as $actualstore) {
33
- if ($actualstore->getCode() == $store) {
34
- $storetoload = (int) $actualstore->getId();
35
- }
36
  }
37
 
38
- Mage::app()->setCurrentStore($storetoload);
39
- $url2 = Mage::getStoreConfig('mailplatform/general/url');
40
 
41
- $url = $this->getmodeloptions()->getXMLGeneralConfig("url", 1);
42
-
43
- $username = $this->getmodeloptions()->getXMLGeneralConfig("username");
44
- $token = $this->getmodeloptions()->getXMLGeneralConfig("token");
45
-
46
- $xml = '<xmlrequest>
47
- <username>' . trim($username) . '</username>
48
- <usertoken>' . trim($token) . '</usertoken>
49
- <requesttype>lists</requesttype>
50
- <requestmethod>GetLists</requestmethod>
51
- <details>all</details></xmlrequest>';
52
-
53
- $ch = curl_init($url);
54
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
55
- curl_setopt($ch, CURLOPT_POST, 1);
56
- curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
57
- $result = @curl_exec($ch);
58
- $xml_doc = simplexml_load_string($result);
59
-
60
- if ($result === false) {
61
- Mage::getSingleton('adminhtml/session')->addError('Mailplatform Configuration Error!');
62
- } else {
63
- if ($xml_doc->status == 'SUCCESS') {
64
- foreach ($xml_doc->data->item as $item) {
65
- if ($item->username == $username) {
66
- $this->_lists[] = array(
67
- 'value' => $item->listid,
68
- 'label' => $item->name
69
- );
70
- }
71
- }
72
- }
73
  }
74
-
75
- $this->_options = $this->_lists;
76
  }
77
 
78
  $options = $this->_options;
 
79
  if (! $isMultiselect) {
80
  array_unshift($options, array(
81
  'value' => '',
82
  'label' => Mage::helper('adminhtml')->__('--Please Select--')
83
  ));
84
  }
85
- Mage::app()->setCurrentStore(0);
86
  return $options;
87
  }
88
  }
5
 
6
  protected $_options;
7
 
 
 
 
 
 
 
 
8
  public function toOptionArray($isMultiselect = false)
9
  {
10
  if (! $this->_options) {
11
+ $lists = Mage::getModel('mailplatform/lists');
12
 
13
+ if ($lists->getLists() === false) {
14
+ Mage::getSingleton('adminhtml/session')->addError('Mailplatform Configuration Error!');
15
+ return $this->_options;
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  }
17
 
18
+ $data = $lists->getResponseData();
 
19
 
20
+ foreach ($data->item as $item) {
21
+ $this->_options[] = array(
22
+ 'value' => $item->listid,
23
+ 'label' => $item->name
24
+ );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  }
 
 
26
  }
27
 
28
  $options = $this->_options;
29
+
30
  if (! $isMultiselect) {
31
  array_unshift($options, array(
32
  'value' => '',
33
  'label' => Mage::helper('adminhtml')->__('--Please Select--')
34
  ));
35
  }
36
+
37
  return $options;
38
  }
39
  }
app/code/community/Mp/Mailplatform/Model/Lists.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Mp_Mailplatform_Model_Lists extends Mp_Mailplatform_Model_Request
4
+ {
5
+
6
+ protected function _construct()
7
+ {
8
+ parent::_construct();
9
+
10
+ $this->setRequestType('lists');
11
+ }
12
+
13
+ public function getLists()
14
+ {
15
+ $this->setRequestMethod('GetLists');
16
+
17
+ return $this->send();
18
+ }
19
+
20
+ }
app/code/community/Mp/Mailplatform/Model/Mailplatform.php DELETED
@@ -1,283 +0,0 @@
1
- <?php
2
-
3
- class Mp_Mailplatform_Model_Mailplatform extends Varien_Object
4
- {
5
-
6
- public function getXMLGeneralConfig($field)
7
- {
8
- return Mage::getStoreConfig('mailplatform/general/' . $field);
9
- }
10
-
11
- public function mailplatformAvailable()
12
- {
13
- $requestUri = Mage::app()->getRequest()->getRequestUri();
14
- if ($this->getXMLGeneralConfig('active') == true && $this->getXMLGeneralConfig('username') != '' && $this->getXMLGeneralConfig('token') != '' && $this->getXMLGeneralConfig('listid') != '' && (strstr($requestUri, 'newsletter/') || strstr($requestUri, 'newsletter_subscriber/') || strstr($requestUri, 'customer/') || strstr($requestUri, 'mailplatform/index') || strstr($requestUri, 'checkout/onepage/'))) {
15
- return true;
16
- }
17
- if (Mage::app()->getStore()->getId() == 0) {
18
- if ($this->getXMLGeneralConfig('active') != true)
19
- Mage::getSingleton('adminhtml/session')->addError('Mailplatform Configuration Error: Mailplatform is innactive');
20
- if ($this->getXMLGeneralConfig('username') == '')
21
- Mage::getSingleton('adminhtml/session')->addError('Mailplatform Configuration Error: API Username field is empty');
22
- if ($this->getXMLGeneralConfig('token') == '')
23
- Mage::getSingleton('adminhtml/session')->addError('Mailplatform Configuration Error: API Token field is empty');
24
- if ($this->getXMLGeneralConfig('listid') == '')
25
- Mage::getSingleton('adminhtml/session')->addError('Mailplatform Configuration Error: Mailplatform list field is empty');
26
- }
27
- return false;
28
- }
29
-
30
- private function getCustomerByEmail($email)
31
- {
32
- if ($email instanceof Mage_Customer_Model_Customer) {
33
-
34
- $customer = $email;
35
-
36
- return $customer;
37
- }
38
-
39
- $collection = Mage::getResourceModel('newsletter/subscriber_collection');
40
- $collection->showCustomerInfo(true)
41
- ->addSubscriberTypeField()
42
- ->showStoreInfo()
43
- ->addFieldToFilter('subscriber_email', $email)
44
- ;
45
-
46
- return $collection->getFirstItem();
47
- }
48
-
49
- private function getListIdByStoreId($storeId)
50
- {
51
- $store = Mage::getModel('core/store')->load($storeId);
52
- $list_id = $store->getConfig('mailplatform/general/listid');
53
-
54
- return $list_id;
55
- }
56
-
57
- public function subscribe($email)
58
- {
59
- if (! $this->mailplatformAvailable()) {
60
- return;
61
- }
62
-
63
- $customer = $this->getCustomerByEmail($email);
64
- $customerOldMail = $this->getCustomerOldEmail();
65
-
66
- $merge_vars = array();
67
-
68
- if ($email instanceof Mage_Customer_Model_Customer) {
69
-
70
- $email = $customer->getEmail();
71
-
72
- $merge_vars['FNAME'] = $customer->getFirstname();
73
- $merge_vars['LNAME'] = $customer->getLastname();
74
- } elseif ($customer->getCustomerId() != 0) {
75
- $merge_vars['FNAME'] = $customer->getCustomerFirstname();
76
- $merge_vars['LNAME'] = $customer->getCustomerLastname();
77
- } else {
78
- $merge_vars['FNAME'] = 'Guest';
79
- $merge_vars['LNAME'] = 'Guest';
80
- }
81
-
82
- try {
83
-
84
- $url2 = Mage::getStoreConfig('mailplatform/general/url');
85
- $username = Mage::getStoreConfig('mailplatform/general/username');
86
- $token = Mage::getStoreConfig('mailplatform/general/token');
87
- $listid = Mage::getStoreConfig('mailplatform/general/listid');
88
-
89
- $xml = '<xmlrequest>
90
- <username>' . $username . '</username>
91
- <usertoken>' . $token . '</usertoken>
92
- <requesttype>subscribers</requesttype>
93
- <requestmethod>AddSubscriberToList</requestmethod>
94
- <details>';
95
- $xml = $xml . '<emailaddress>' . $email . '</emailaddress>';
96
- $xml = $xml . '<mailinglist>' . $listid . '</mailinglist>
97
- <format>html</format>
98
- <confirmed>yes</confirmed>
99
- </details>
100
- </xmlrequest>';
101
- $ch = curl_init($url2);
102
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
103
- curl_setopt($ch, CURLOPT_POST, 1);
104
- curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
105
- $result = @curl_exec($ch);
106
- if ($result === false) {
107
- Mage::getSingleton('customer/session')->addError("Mailplatform - Error Performing the Request");
108
- } else {
109
- $xml_doc = simplexml_load_string($result);
110
- Mage::getSingleton('customer/session')->addSuccess("Mailplatform - Added - " . $email . " OK");
111
- if ($xml_doc->status != 'SUCCESS') {
112
- Mage::getSingleton('customer/session')->addError("Mailplatform -" . $xml_doc->errormessage . '<br/>');
113
- }
114
- }
115
-
116
- } catch (exception $e) {
117
- Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
118
- }
119
- }
120
-
121
- public function unsubscribe($email)
122
- {
123
- if (! $this->mailplatformAvailable()) {
124
- return;
125
- }
126
-
127
- try {
128
-
129
- $url2 = Mage::getStoreConfig('mailplatform/general/url');
130
- $username = Mage::getStoreConfig('mailplatform/general/username');
131
- $token = Mage::getStoreConfig('mailplatform/general/token');
132
- $listid = Mage::getStoreConfig('mailplatform/general/listid');
133
-
134
- $xml = '<xmlrequest>
135
- <username>' . $username . '</username>
136
- <usertoken>' . $token . '</usertoken>
137
- <requesttype>subscribers</requesttype>
138
- <requestmethod>DeleteSubscriber</requestmethod>
139
- <details>
140
- <emailaddress>' . $email->getEmail() . '</emailaddress>
141
- <list>' . $listid . '</list>
142
- </details>
143
- </xmlrequest>';
144
-
145
- $ch = curl_init($url2);
146
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
147
- curl_setopt($ch, CURLOPT_POST, 1);
148
- curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
149
- $result = @curl_exec($ch);
150
- if ($result === false) {
151
- Mage::getSingleton('customer/session')->addError("Mailplatform - Error Performing the Request");
152
- } else {
153
- $xml_doc = simplexml_load_string($result);
154
-
155
- Mage::getSingleton('customer/session')->addSuccess("Mailplatform - Removal - " . $email . " OK");
156
-
157
- if ($xml_doc->status != 'SUCCESS') {
158
- Mage::getSingleton('customer/session')->addError("Mailplatform -" . $xml_doc->errormessage . '<br/>');
159
- }
160
- }
161
-
162
- /**
163
- * Submit to Mailplatform
164
- */
165
- } catch (exception $e) {
166
- Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
167
- }
168
- }
169
-
170
- public function batchSubscribe($items)
171
- {
172
- if (! $this->mailplatformAvailable()) {
173
- return;
174
- }
175
-
176
- $batch = array();
177
- $customerInList = array();
178
- foreach ($items as $item) {
179
-
180
- $merge_vars = array();
181
-
182
- if ($item['customer_id'] != 0) {
183
- $merge_vars['FNAME'] = $item['customer_firstname'];
184
- $merge_vars['LNAME'] = $item['customer_lastname'];
185
- $merge_vars['StoreId'] = $item['store_id'];
186
- } else {
187
- $merge_vars['FNAME'] = 'Guest';
188
- $merge_vars['LNAME'] = 'Guest';
189
- $merge_vars['StoreId'] = $item['store_id'];
190
- }
191
-
192
- $merge_vars['EMAIL'] = $item['subscriber_email'];
193
-
194
- $customerInList[$item['store_id']][] = $merge_vars;
195
- }
196
-
197
- try {
198
- foreach ($customerInList as $store => $customers) {
199
-
200
- Mage::app()->setCurrentStore($store);
201
- $url2 = Mage::getStoreConfig('mailplatform/general/url');
202
- $username = Mage::getStoreConfig('mailplatform/general/username');
203
- $token = Mage::getStoreConfig('mailplatform/general/token');
204
- $listid = Mage::getStoreConfig('mailplatform/general/listid');
205
-
206
- if (count($customers) == 1) {
207
-
208
- $xml = '<xmlrequest>
209
- <username>' . $username . '</username>
210
- <usertoken>' . $token . '</usertoken>
211
- <requesttype>subscribers</requesttype>
212
- <requestmethod>AddSubscriberToList</requestmethod>
213
- <details>';
214
- $xml = $xml . '<emailaddress>' . $customers[0]["EMAIL"] . '</emailaddress>';
215
- $xml = $xml . '<mailinglist>' . $listid . '</mailinglist>
216
- <format>html</format>
217
- <confirmed>yes</confirmed>
218
- </details>
219
- </xmlrequest>';
220
- $ch = curl_init($url2);
221
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
222
- curl_setopt($ch, CURLOPT_POST, 1);
223
- curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
224
- $result = @curl_exec($ch);
225
- if ($result === false) {
226
- Mage::getSingleton('adminhtml/session')->addError("Mailplatform - Error Performing the Request");
227
- } else {
228
- $xml_doc = simplexml_load_string($result);
229
- Mage::getSingleton('adminhtml/session')->addSuccess("Mailplatform - " . $customers[0]["EMAIL"] . " OK");
230
-
231
- if ($xml_doc->status != 'SUCCESS') {
232
- Mage::getSingleton('adminhtml/session')->addError("Mailplatform -" . $xml_doc->errormessage . '<br/>');
233
- }
234
- }
235
-
236
- } else {
237
- foreach ($customers as $custom) {
238
-
239
- $xml = '<xmlrequest>
240
- <username>' . $username . '</username>
241
- <usertoken>' . $token . '</usertoken>
242
- <requesttype>subscribers</requesttype>
243
- <requestmethod>AddSubscriberToList</requestmethod>
244
- <details>';
245
- $xml = $xml . '<emailaddress>' . $custom["EMAIL"] . '</emailaddress>';
246
- $xml = $xml . '<mailinglist>' . $listid . '</mailinglist>
247
- <format>html</format>
248
- <confirmed>yes</confirmed>
249
- </details>
250
- </xmlrequest>';
251
-
252
- $ch = curl_init($url2);
253
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
254
- curl_setopt($ch, CURLOPT_POST, 1);
255
- curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
256
- $result = @curl_exec($ch);
257
- if ($result === false) {
258
- Mage::getSingleton('adminhtml/session')->addError("Mailplatform - Error Performing the Request");
259
- } else {
260
- $xml_doc = simplexml_load_string($result);
261
-
262
- Mage::getSingleton('adminhtml/session')->addSuccess("Mailplatform - " . $custom["EMAIL"] . " OK");
263
- if ($xml_doc->status != 'SUCCESS') {
264
- Mage::getSingleton('adminhtml/session')->addError("Mailplatform -" . $xml_doc->errormessage . '<br/>');
265
- }
266
- }
267
- }
268
- }
269
- }
270
-
271
- Mage::app()->setCurrentStore(0);
272
-
273
- } catch (exception $e) {
274
- Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
275
- }
276
- }
277
-
278
- public function getCustomerOldEmail()
279
- {
280
- return Mage::getSingleton('core/session', array('name' => 'frontend'))->getData('customer_old_email');
281
- }
282
-
283
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Mp/Mailplatform/Model/Mailplatform/Emailtype.php DELETED
@@ -1,14 +0,0 @@
1
- <?php
2
-
3
- class Mp_Mailplatform_Model_Mailplatform_emailtype
4
- {
5
-
6
- public function toOptionArray()
7
- {
8
- return array(
9
- array('value'=>'html', 'label'=>Mage::helper('adminhtml')->__('HTML')),
10
- array('value'=>'text', 'label'=>Mage::helper('adminhtml')->__('Text')),
11
- );
12
- }
13
-
14
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Mp/Mailplatform/Model/Mailplatform/Listids.php DELETED
@@ -1,92 +0,0 @@
1
- <?php
2
- class Mp_Mailplatform_Model_Mailplatform_Listids extends Varien_Object
3
- {
4
- protected $_options;
5
- protected $_lists = array();
6
-
7
- protected function getmodeloptions()
8
- {
9
- return Mage::getModel('mailplatform/mailplatform');
10
- }
11
-
12
- public function toOptionArray($isMultiselect=false)
13
- {
14
- if (!$this->_options) {
15
- $arrresult = explode("/", $_SERVER["REQUEST_URI"]);
16
- //$arrresult;
17
- //Zend_Debug::dump($arrresult);
18
- $i = 0;
19
- $store = "";
20
- $storetoload = 0;
21
- foreach($arrresult as $arr)
22
- {
23
- if($arr == "store")
24
- {
25
- $store = $arrresult[$i+1];
26
- }
27
- $i++;
28
- }
29
-
30
- $allstores = Mage::getModel('core/store')->getCollection();
31
-
32
- foreach($allstores as $actualstore)
33
- {
34
- if($actualstore->getCode() == $store)
35
- {
36
- $storetoload = (int)$actualstore->getId();
37
- }
38
- }
39
-
40
- Mage::app()->setCurrentStore($storetoload);
41
- $url2 = Mage::getStoreConfig('mailplatform/general/url');
42
-
43
- $url = $this->getmodeloptions()->getXMLGeneralConfig("url" ,1);
44
- //Zend_Debug::dump($url);
45
-
46
- $username = $this->getmodeloptions()->getXMLGeneralConfig("username");
47
- $tocken = $this->getmodeloptions()->getXMLGeneralConfig("tocken");
48
-
49
-
50
-
51
- $xml = '<xmlrequest>
52
- <username>'. trim($username) .'</username>
53
- <usertoken>'. trim($tocken) .'</usertoken>
54
- <requesttype>lists</requesttype>
55
- <requestmethod>GetLists</requestmethod>
56
- <details>all</details></xmlrequest>';
57
- //Zend_Debug::dump($xml);
58
-
59
- $ch = curl_init($url);
60
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
61
- curl_setopt($ch, CURLOPT_POST, 1);
62
- curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
63
- $result = @curl_exec($ch);
64
- $xml_doc = simplexml_load_string($result);
65
- //Zend_Debug::dump($result);
66
- if($result === false) {
67
- Mage::getSingleton('adminhtml/session')->addError('Mailplatform Configuration Error!');
68
- }else {
69
- if ($xml_doc->status == 'SUCCESS')
70
- {
71
- foreach($xml_doc->data->item as $item)
72
- {
73
- if($item->username == $username){
74
- $this->_lists[] = array('value'=>$item->listid,
75
- 'label'=>$item->name);
76
- }
77
- }
78
- }
79
- }
80
-
81
- $this->_options = $this->_lists;
82
- }
83
-
84
-
85
- $options = $this->_options;
86
- if(!$isMultiselect){
87
- array_unshift($options, array('value'=>'', 'label'=> Mage::helper('adminhtml')->__('--Please Select--')));
88
- }
89
- Mage::app()->setCurrentStore(0);
90
- return $options;
91
- }
92
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Mp/Mailplatform/Model/Mailplatform/Mailplatform.php DELETED
@@ -1,344 +0,0 @@
1
- <?php
2
- class Mp_Mailplatform_Model_Mailplatform_Mailplatform extends Varien_Object
3
- {
4
-
5
- public function getXMLGeneralConfig($field) {
6
- return Mage::getStoreConfig('mailplatform/general/'.$field);
7
- }
8
-
9
- public function mailplatformAvailable() {
10
- if ( $this->getXMLGeneralConfig('active') == true &&
11
- $this->getXMLGeneralConfig('username') != '' &&
12
- $this->getXMLGeneralConfig('tocken') != '' &&
13
- $this->getXMLGeneralConfig('listid') != ''
14
- &&
15
- (
16
- strstr($_SERVER['REQUEST_URI'], 'newsletter/') ||
17
- strstr($_SERVER['REQUEST_URI'], 'newsletter_subscriber/') ||
18
- strstr($_SERVER['REQUEST_URI'], 'customer/') ||
19
- strstr($_SERVER['REQUEST_URI'], 'mailplatform/index') ||
20
- strstr($_SERVER['REQUEST_URI'], 'checkout/onepage/')
21
- )
22
- ) {
23
- return true;
24
- }
25
- if (Mage::app()->getStore()->getId() == 0){
26
- if($this->getXMLGeneralConfig('active') != true) Mage::getSingleton('adminhtml/session')->addError('Mailplatform Configuration Error: Mailplatform is innactive');
27
- if($this->getXMLGeneralConfig('username') == '' ) Mage::getSingleton('adminhtml/session')->addError('Mailplatform Configuration Error: API Username field is empty');
28
- if($this->getXMLGeneralConfig('tocken') == '' ) Mage::getSingleton('adminhtml/session')->addError('Mailplatform Configuration Error: API Tocken field is empty');
29
- if($this->getXMLGeneralConfig('listid') == '' ) Mage::getSingleton('adminhtml/session')->addError('Mailplatform Configuration Error: Mailplatform list field is empty');
30
- }
31
- return false;
32
- }
33
-
34
- private function getCustomerByEmail($email)
35
- {
36
- if (($email instanceof Mage_Customer_Model_Customer)) {
37
-
38
- $customer = $email;
39
-
40
- return $customer;
41
- }
42
-
43
- $collection = Mage::getResourceModel('newsletter/subscriber_collection');
44
- $collection
45
- ->showCustomerInfo(true)
46
- ->addSubscriberTypeField()
47
- ->showStoreInfo()
48
- ->addFieldToFilter('subscriber_email',$email);
49
-
50
- return $collection->getFirstItem();
51
- }
52
-
53
- private function getListIdByStoreId($storeId)
54
- {
55
- $store = Mage::getModel('core/store')->load($storeId);
56
- $list_id = $store->getConfig('mailplatform/general/listid');
57
-
58
- return $list_id;
59
-
60
- }
61
-
62
- public function subscribe($email) {
63
- if ($this->mailplatformAvailable()) {
64
-
65
- $customer = $this->getCustomerByEmail($email);
66
- $customerOldMail = $this->getCustomerOldEmail();
67
-
68
- $merge_vars = array();
69
-
70
- if (($email instanceof Mage_Customer_Model_Customer)) {
71
-
72
- $email = $customer->getEmail();
73
-
74
- $merge_vars['FNAME'] = $customer->getFirstname();
75
- $merge_vars['LNAME'] = $customer->getLastname();
76
-
77
- }elseif ($customer->getCustomerId() !=0 ) {
78
- $merge_vars['FNAME'] = $customer->getCustomerFirstname();
79
- $merge_vars['LNAME'] = $customer->getCustomerLastname();
80
- } else {
81
- $merge_vars['FNAME'] = 'Guest';
82
- $merge_vars['LNAME'] = 'Guest';
83
- }
84
- try {
85
-
86
-
87
- $url2 = Mage::getStoreConfig('mailplatform/general/url');
88
- //$url = $this->getMailplatform()->getXMLGeneralConfig("url");
89
- $username = Mage::getStoreConfig('mailplatform/general/username');
90
- $tocken = Mage::getStoreConfig('mailplatform/general/tocken');
91
- $listid = Mage::getStoreConfig('mailplatform/general/listid');
92
-
93
- //Zend_Debug::dump($url2);
94
- //Zend_Debug::dump($username);
95
- //Zend_Debug::dump($tocken);
96
- //Zend_Debug::dump($listid);
97
- //Zend_Debug::dump($email);
98
- //Zend_Debug::dump($customers);
99
-
100
- $xml = '<xmlrequest>
101
- <username>' . $username . '</username>
102
- <usertoken>' . $tocken . '</usertoken>
103
- <requesttype>subscribers</requesttype>
104
- <requestmethod>AddSubscriberToList</requestmethod>
105
- <details>';
106
- $xml = $xml . '<emailaddress>' . $email . '</emailaddress>';
107
- $xml = $xml . '<mailinglist>'. $listid .'</mailinglist>
108
- <format>html</format>
109
- <confirmed>yes</confirmed>
110
- </details>
111
- </xmlrequest>';
112
- $ch = curl_init($url2);
113
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
114
- curl_setopt($ch, CURLOPT_POST, 1);
115
- curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
116
- $result = @curl_exec($ch);
117
- if($result === false) {
118
- Mage::getSingleton('customer/session')->addError("Mailplatform - Error Performing the Request");
119
- } else {
120
- $xml_doc = simplexml_load_string($result);
121
- //Zend_Debug::dump($result);
122
- Mage::getSingleton('customer/session')->addSuccess("Mailplatform - Addet - " . $email . " OK");
123
- if ($xml_doc->status == 'SUCCESS') {
124
- // echo 'Data is ', $xml_doc->data, '<br/>';
125
- } else {
126
- Mage::getSingleton('customer/session')->addError("Mailplatform -" . $xml_doc->errormessage . '<br/>');
127
- }
128
- }
129
-
130
- //Zend_Debug::dump($result);
131
- //echo "AAAAAAAAA";
132
- //die("AAAAAA");
133
-
134
- } catch ( exception $e ) {
135
- Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
136
- }
137
-
138
- }
139
- }
140
-
141
- public function unsubscribe($email) {
142
- //Zend_Debug::dump($email->getEmail());
143
- if ( $this->mailplatformAvailable() ) {
144
-
145
- try {
146
-
147
- $url2 = Mage::getStoreConfig('mailplatform/general/url');
148
- //$url = $this->getMailplatform()->getXMLGeneralConfig("url");
149
- $username = Mage::getStoreConfig('mailplatform/general/username');
150
- $tocken = Mage::getStoreConfig('mailplatform/general/tocken');
151
- $listid = Mage::getStoreConfig('mailplatform/general/listid');
152
-
153
- //Zend_Debug::dump($url2);
154
- //Zend_Debug::dump($username);
155
- //Zend_Debug::dump($tocken);
156
- //Zend_Debug::dump($listid);
157
- //Zend_Debug::dump($store);
158
- //Zend_Debug::dump($customers);
159
- $xml = '<xmlrequest>
160
- <username>' . $username . '</username>
161
- <usertoken>' . $tocken . '</usertoken>
162
- <requesttype>subscribers</requesttype>
163
- <requestmethod>DeleteSubscriber</requestmethod>
164
- <details>
165
- <emailaddress>' . $email->getEmail() . '</emailaddress>
166
- <list>' .$listid. '</list>
167
- </details>
168
- </xmlrequest>';
169
-
170
- $ch = curl_init($url2);
171
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
172
- curl_setopt($ch, CURLOPT_POST, 1);
173
- curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
174
- $result = @curl_exec($ch);
175
- if($result === false) {
176
- Mage::getSingleton('customer/session')->addError("Mailplatform - Error Performing the Request");
177
- } else {
178
- $xml_doc = simplexml_load_string($result);
179
- //Zend_Debug::dump($result);
180
- Mage::getSingleton('customer/session')->addSuccess("Mailplatform - Removal - " . $email . " OK");
181
- if ($xml_doc->status == 'SUCCESS') {
182
- // echo 'Data is ', $xml_doc->data, '<br/>';
183
- } else {
184
- Mage::getSingleton('customer/session')->addError("Mailplatform -" . $xml_doc->errormessage . '<br/>');
185
- }
186
- }
187
-
188
- //Zend_Debug::dump($result);
189
- //echo "AAAAAAAAAAAA";
190
- //die($email);
191
- /**
192
- * Submit to Mailplatform
193
- * */
194
-
195
- } catch ( exception $e ) {
196
- Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
197
- }
198
- }
199
- }
200
- public function batchSubscribe($items) {
201
- //echo "In batch";
202
-
203
- if ( $this->mailplatformAvailable() ) {
204
-
205
- // echo "ENABLED";
206
- $batch = array();
207
- $customerInList = array();
208
- foreach($items as $item) {
209
-
210
- $merge_vars = array();
211
-
212
- if($item['customer_id'] !=0) {
213
- $merge_vars['FNAME'] = $item['customer_firstname'];
214
- $merge_vars['LNAME'] = $item['customer_lastname'];
215
- $merge_vars['StoreId'] = $item['store_id'];
216
-
217
- } else {
218
- $merge_vars['FNAME'] = 'Guest';
219
- $merge_vars['LNAME'] = 'Guest';
220
- $merge_vars['StoreId'] = $item['store_id'];
221
- }
222
-
223
- $merge_vars['EMAIL'] = $item['subscriber_email'];
224
-
225
- //$batch[] = $merge_vars;
226
- $customerInList[$item['store_id']][]= $merge_vars;
227
-
228
- }
229
-
230
- //Zend_Debug::dump($customerInList);
231
-
232
- try {
233
- foreach ($customerInList as $store => $customers)
234
- {
235
-
236
- Mage::app()->setCurrentStore($store);
237
- $url2 = Mage::getStoreConfig('mailplatform/general/url');
238
- //$url = $this->getMailplatform()->getXMLGeneralConfig("url");
239
- $username = Mage::getStoreConfig('mailplatform/general/username');
240
- $tocken = Mage::getStoreConfig('mailplatform/general/tocken');
241
- $listid = Mage::getStoreConfig('mailplatform/general/listid');
242
- //echo "<hr>";
243
- //Zend_Debug::dump($url2);
244
- //Zend_Debug::dump($username);
245
- //Zend_Debug::dump($tocken);
246
- //Zend_Debug::dump($listid);
247
- //Zend_Debug::dump($store);
248
- //Zend_Debug::dump($customers);
249
- if(count($customers) == 1)
250
- {
251
-
252
- $xml = '<xmlrequest>
253
- <username>' . $username . '</username>
254
- <usertoken>' . $tocken . '</usertoken>
255
- <requesttype>subscribers</requesttype>
256
- <requestmethod>AddSubscriberToList</requestmethod>
257
- <details>';
258
- $xml = $xml . '<emailaddress>' . $customers[0]["EMAIL"] . '</emailaddress>';
259
- $xml = $xml . '<mailinglist>'. $listid .'</mailinglist>
260
- <format>html</format>
261
- <confirmed>yes</confirmed>
262
- </details>
263
- </xmlrequest>';
264
- $ch = curl_init($url2);
265
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
266
- curl_setopt($ch, CURLOPT_POST, 1);
267
- curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
268
- $result = @curl_exec($ch);
269
- if($result === false) {
270
- Mage::getSingleton('adminhtml/session')->addError("Mailplatform - Error Performing the Request");
271
- }
272
- else {
273
- $xml_doc = simplexml_load_string($result);
274
- //Zend_Debug::dump($result);
275
- Mage::getSingleton('adminhtml/session')->addSuccess("Mailplatform - " . $customers[0]["EMAIL"] . " OK");
276
- if ($xml_doc->status == 'SUCCESS') {
277
- // echo 'Data is ', $xml_doc->data, '<br/>';
278
- } else {
279
- Mage::getSingleton('adminhtml/session')->addError("Mailplatform -" . $xml_doc->errormessage . '<br/>');
280
- }
281
- }
282
- // Zend_Debug::dump($xml);
283
- }else{
284
- foreach($customers as $custom)
285
- {
286
-
287
- $xml = '<xmlrequest>
288
- <username>' . $username . '</username>
289
- <usertoken>' . $tocken . '</usertoken>
290
- <requesttype>subscribers</requesttype>
291
- <requestmethod>AddSubscriberToList</requestmethod>
292
- <details>';
293
- $xml = $xml . '<emailaddress>' . $custom["EMAIL"] . '</emailaddress>';
294
- $xml = $xml . '<mailinglist>'. $listid .'</mailinglist>
295
- <format>html</format>
296
- <confirmed>yes</confirmed>
297
- </details>
298
- </xmlrequest>';
299
- //Zend_Debug::dump($xml);
300
- $ch = curl_init($url2);
301
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
302
- curl_setopt($ch, CURLOPT_POST, 1);
303
- curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
304
- $result = @curl_exec($ch);
305
- if($result === false) {
306
- Mage::getSingleton('adminhtml/session')->addError("Mailplatform - Error Performing the Request");
307
- }
308
- else {
309
- $xml_doc = simplexml_load_string($result);
310
- //Zend_Debug::dump($result);
311
- Mage::getSingleton('adminhtml/session')->addSuccess("Mailplatform - " . $custom["EMAIL"] . " OK");
312
- if ($xml_doc->status == 'SUCCESS') {
313
- //echo 'Data is ', $xml_doc->data, '<br/>';
314
- } else {
315
- Mage::getSingleton('adminhtml/session')->addError("Mailplatform -" . $xml_doc->errormessage . '<br/>');
316
- }
317
- }
318
- }
319
- //echo "more then 1";
320
- }
321
-
322
- }
323
- Mage::app()->setCurrentStore(0);
324
- } catch ( exception $e ) {
325
- Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
326
- }
327
- }
328
- }
329
-
330
- public function getCustomerOldEmail()
331
- {
332
- if(isset($_SESSION['customer_old_email']))
333
- {
334
- $customer_old_email = $_SESSION['customer_old_email'];
335
- return $customer_old_email;
336
- }else
337
- {
338
- return '';
339
-
340
- }
341
-
342
- }
343
- }
344
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Mp/Mailplatform/Model/Newsletter/Subscriber.php CHANGED
@@ -5,62 +5,24 @@ class Mp_Mailplatform_Model_Newsletter_Subscriber extends Mage_Newsletter_Model_
5
 
6
  public function subscribe($email)
7
  {
8
- $this->loadByEmail($email);
9
- $customer = Mage::getModel('customer/customer')
10
- ->setWebsiteId(Mage::app()->getStore()->getWebsiteId())
11
- ->loadByEmail($email)
12
- ;
13
- $isNewSubscriber = false;
14
-
15
- $customerSession = Mage::getSingleton('customer/session');
16
-
17
- if (! $this->getId()) {
18
- $this->setSubscriberConfirmCode($this->randomSequence());
19
- }
20
 
21
- if (
22
- ! $this->getId()
23
- || $this->getStatus() == self::STATUS_UNSUBSCRIBED
24
- || $this->getStatus() == self::STATUS_NOT_ACTIVE
25
- ) {
26
- if (Mage::getStoreConfig(self::XML_PATH_CONFIRMATION_FLAG) == 1) {
27
- $this->setStatus(self::STATUS_NOT_ACTIVE);
28
- } else {
29
- $this->setStatus(self::STATUS_SUBSCRIBED);
30
  }
31
- $this->setSubscriberEmail($email);
32
- }
33
 
34
- if ($customerSession->isLoggedIn()) {
35
- $this->setStoreId($customerSession->getCustomer()
36
- ->getStoreId());
37
- $this->setStatus(self::STATUS_SUBSCRIBED);
38
- $this->setCustomerId($customerSession->getCustomerId());
39
- } else
40
- if ($customer->getId()) {
41
- $this->setStoreId($customer->getStoreId());
42
- $this->setSubscriberStatus(self::STATUS_SUBSCRIBED);
43
- $this->setCustomerId($customer->getId());
44
- } else {
45
- $this->setStoreId(Mage::app()->getStore()
46
- ->getId());
47
- $this->setCustomerId(0);
48
- $isNewSubscriber = true;
49
- }
50
 
51
- $this->setIsStatusChanged(true);
52
 
53
- try {
54
- $this->save();
55
- if (Mage::getStoreConfig(self::XML_PATH_CONFIRMATION_FLAG) == 1 && $this->getSubscriberStatus() == self::STATUS_NOT_ACTIVE) {
56
- $this->sendConfirmationRequestEmail();
57
- } else {
58
- $this->sendConfirmationSuccessEmail();
59
  }
60
 
61
- Mage::getSingleton('mailplatform/mailplatform')->subscribe($email);
62
 
63
- return $this->getStatus();
64
  } catch (Exception $e) {
65
  throw new Exception($e->getMessage());
66
  }
@@ -68,14 +30,9 @@ class Mp_Mailplatform_Model_Newsletter_Subscriber extends Mage_Newsletter_Model_
68
 
69
  public function unsubscribe()
70
  {
71
- if ($this->hasCheckCode() && $this->getCode() != $this->getCheckCode()) {
72
- Mage::throwException(Mage::helper('newsletter')->__('Invalid subscription confirmation code'));
73
- }
74
-
75
- $this->setSubscriberStatus(self::STATUS_UNSUBSCRIBED)->save();
76
- $this->sendUnsubscriptionEmail();
77
 
78
- Mage::getModel('mailplatform/mailplatform')->unsubscribe($this->getEmail());
79
 
80
  return $this;
81
  }
@@ -88,60 +45,28 @@ class Mp_Mailplatform_Model_Newsletter_Subscriber extends Mage_Newsletter_Model_
88
  */
89
  public function subscribeCustomer($customer)
90
  {
91
- $this->loadByCustomer($customer);
92
-
93
- if ($customer->getImportMode()) {
94
- $this->setImportMode(true);
95
- }
96
 
97
- if (! $customer->getIsSubscribed() && ! $this->getId()) {
98
- // If subscription flag not seted or customer not subscriber
99
- // and no subscribe bellow
100
  return $this;
101
  }
102
 
103
- if (! $this->getId()) {
104
- $this->setSubscriberConfirmCode($this->randomSequence());
105
- }
106
 
107
- if ($customer->hasIsSubscribed()) {
108
- $status = $customer->getIsSubscribed() ? self::STATUS_SUBSCRIBED : self::STATUS_UNSUBSCRIBED;
109
- } else {
110
- $status = ($this->getStatus() == self::STATUS_NOT_ACTIVE ? self::STATUS_UNSUBSCRIBED : $this->getStatus());
111
- }
112
 
113
- if ($status != $this->getStatus()) {
114
- $this->setIsStatusChanged(true);
115
- }
116
 
117
- $this->setStatus($status);
 
 
118
 
119
- if (! $this->getId()) {
120
- $this->setStoreId($customer->getStoreId())
121
- ->setCustomerId($customer->getId())
122
- ->setEmail($customer->getEmail());
123
  } else {
124
- $this->setEmail($customer->getEmail());
125
  }
126
 
127
- $this->save();
128
-
129
- if ((! $customer->isConfirmationRequired()) && ! $customer->getConfirmation()) {
130
- if ($this->getStatus() == self::STATUS_SUBSCRIBED) {
131
- Mage::getSingleton('mailplatform/mailplatform')->subscribe($customer);
132
- } else {
133
- Mage::getSingleton('mailplatform/mailplatform')->unsubscribe($customer);
134
- }
135
- }
136
-
137
- $sendSubscription = $customer->getData('sendSubscription');
138
- if (is_null($sendSubscription) xor $sendSubscription) {
139
- if ($this->getIsStatusChanged() && $status == self::STATUS_UNSUBSCRIBED) {
140
- $this->sendUnsubscriptionEmail();
141
- } elseif ($this->getIsStatusChanged() && $status == self::STATUS_SUBSCRIBED) {
142
- $this->sendConfirmationSuccessEmail();
143
- }
144
- }
145
  return $this;
146
  }
147
  }
5
 
6
  public function subscribe($email)
7
  {
8
+ try {
9
+ $status = parent::subscribe($email);
 
 
 
 
 
 
 
 
 
 
10
 
11
+ if (! Mage::helper('mailplatform')->isEnabled()) {
12
+ return $status;
 
 
 
 
 
 
 
13
  }
 
 
14
 
15
+ $subscribers = Mage::getModel('mailplatform/subscribers');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
+ $isSubscriber = $subscribers->isSubscriberOnList($email);
18
 
19
+ if ($isSubscriber === true) {
20
+ return $status;
 
 
 
 
21
  }
22
 
23
+ $subscribers->addSubscriberToList($email);
24
 
25
+ return $status;
26
  } catch (Exception $e) {
27
  throw new Exception($e->getMessage());
28
  }
30
 
31
  public function unsubscribe()
32
  {
33
+ parent::unsubscribe();
 
 
 
 
 
34
 
35
+ Mage::getModel('mailplatform/subscribers')->unsubscribeSubscriber($this->getEmail());
36
 
37
  return $this;
38
  }
45
  */
46
  public function subscribeCustomer($customer)
47
  {
48
+ parent::subscribeCustomer($customer);
 
 
 
 
49
 
50
+ if ($customer->isConfirmationRequired() && $customer->getConfirmation()) {
 
 
51
  return $this;
52
  }
53
 
54
+ $email = $customer->getEmail();
 
 
55
 
56
+ if ($this->getStatus() == self::STATUS_SUBSCRIBED) {
57
+ $subscribers = Mage::getModel('mailplatform/subscribers');
 
 
 
58
 
59
+ $isSubscriber = $subscribers->isSubscriberOnList($email);
 
 
60
 
61
+ if ($isSubscriber === true) {
62
+ return $this;
63
+ }
64
 
65
+ $subscribers->addSubscriberToList($email);
 
 
 
66
  } else {
67
+ Mage::getModel('mailplatform/subscribers')->unsubscribeSubscriber($email);
68
  }
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  return $this;
71
  }
72
  }
app/code/community/Mp/Mailplatform/Model/Observer.php ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Mp_Mailplatform_Model_Observer
4
+ {
5
+
6
+ public function onCheckoutSubmit(Varien_Event_Observer $observer)
7
+ {
8
+ if (! Mage::helper('mailplatform')->isEnabled()) {
9
+ return $this;
10
+ }
11
+
12
+ $order = $observer->getOrder();
13
+ $quote = $observer->getQuote();
14
+
15
+ $confirmed = false;
16
+
17
+ $isSubscribed = Mage::app()->getRequest()->getParam('is_subscribed');
18
+
19
+ if ($isSubscribed) {
20
+ $confirmed = true;
21
+ }
22
+
23
+ $billingAddress = $order->getBillingAddress();
24
+
25
+ $email = $billingAddress->getEmail();
26
+
27
+ $subscribers = Mage::getModel('mailplatform/subscribers');
28
+
29
+ $details = array(
30
+ 'confirmed' => $confirmed
31
+ );
32
+
33
+ $customFields = array(
34
+ array( // First Name
35
+ 'fieldid' => $subscribers->getCustomFieldId('firstname'),
36
+ 'value' => $billingAddress->getFirstname(),
37
+ ),
38
+ array( // Last Name
39
+ 'fieldid' => $subscribers->getCustomFieldId('lastname'),
40
+ 'value' => $billingAddress->getLastname(),
41
+ ),
42
+ array( //City
43
+ 'fieldid' => $subscribers->getCustomFieldId('city'),
44
+ 'value' => $billingAddress->getCity(),
45
+ )
46
+ );
47
+
48
+ if ($subscribers->getCustomFieldId('purchase_date')) {
49
+ $date = new Zend_Date(strtotime($order->getCreatedAt()), null, Mage::app()->getLocale()->getLocaleCode());
50
+ $customFields[] = array( //Purchase Date
51
+ 'fieldid' => $subscribers->getCustomFieldId('purchase_date'),
52
+ 'value' => array('dd' => $date->getDay()->get('dd'), 'mm' => $date->getMonth()->get('MM'), 'yy' => $date->getYear()->get('yyyy')),
53
+ );
54
+ }
55
+
56
+ if ($subscribers->getCustomFieldId('product_categories')) {
57
+ $categories = array();
58
+
59
+ foreach ($order->getAllItems() as $item) {
60
+ if ($item->getParentItem()) {
61
+ continue;
62
+ }
63
+
64
+ $categoryIds = Mage::getModel('catalog/product')->load($item->getProductId())->getCategoryIds();
65
+ $categories = array_merge($categories, $categoryIds);
66
+ }
67
+
68
+ $categories = array_unique($categories);
69
+
70
+ foreach ($categories as $id => $category) {
71
+ $productCategories['key' . $id] = $category;
72
+ }
73
+
74
+ $customFields[] = array(//Product Categories
75
+ 'fieldid' => $subscribers->getCustomFieldId('product_categories'),
76
+ 'value' => $productCategories,
77
+ 'strategy' => 'add',
78
+ );
79
+ }
80
+
81
+ $isSubscriber = $subscribers->isSubscriberOnList($email);
82
+
83
+ if ($isSubscriber === true) {
84
+ $subscribers->update($email, null, $customFields);
85
+ } else {
86
+ $subscribers->addSubscriberToList($email, null, $details, $customFields);
87
+ }
88
+
89
+ return $this;
90
+ }
91
+
92
+ }
app/code/community/Mp/Mailplatform/Model/Request.php ADDED
@@ -0,0 +1,252 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Mp_Mailplatform_Model_Request extends Varien_Object
4
+ {
5
+
6
+ protected $_xml;
7
+
8
+ protected $_mailingList;
9
+
10
+ protected $_format;
11
+
12
+ protected $_responseXml;
13
+
14
+ protected $_requestType;
15
+
16
+ const STATUS_SUCCESS = 'SUCCESS';
17
+
18
+ const STATUS_FAILED = 'FAILED';
19
+
20
+ protected function _construct()
21
+ {
22
+ parent::_construct();
23
+
24
+ $this->_initXml();
25
+ }
26
+
27
+ protected function _initXml()
28
+ {
29
+ $this->_xml = new SimpleXMLElement('<xmlrequest/>');
30
+
31
+ $this->_xml->addChild('username', $this->_getUsername());
32
+ $this->_xml->addChild('usertoken', $this->_getToken());
33
+
34
+ $this->setFormat('html');
35
+
36
+ $this->setUrl(Mage::helper('mailplatform')->getUrl());
37
+
38
+ if ($this->_requestType) {
39
+ $this->_setRequestType($this->_requestType);
40
+ }
41
+ }
42
+
43
+ protected function _getUsername()
44
+ {
45
+ return Mage::helper('mailplatform')->getUsername();
46
+ }
47
+
48
+ protected function _getToken()
49
+ {
50
+ return Mage::helper('mailplatform')->getToken();
51
+ }
52
+
53
+ protected function _getMailingList()
54
+ {
55
+ if ($this->_mailingList) {
56
+ return $this->_mailingList;
57
+ }
58
+
59
+ return Mage::helper('mailplatform')->getListId();
60
+ }
61
+
62
+ protected function _getFormat()
63
+ {
64
+ if ($this->_format) {
65
+ return $this->_format;
66
+ }
67
+
68
+ return Mage::helper('mailplatform')->getFormat();
69
+ }
70
+
71
+ public function setFormat($format = null)
72
+ {
73
+ if ($format) {
74
+ $this->_format = $format;
75
+ } else {
76
+ $this->_format = $this->_getFormat();
77
+ }
78
+
79
+ return $this;
80
+ }
81
+
82
+ public function setMailingList($mailingList = null)
83
+ {
84
+ if ($mailingList) {
85
+ $this->_mailingList = $mailingList;
86
+ } else {
87
+ $this->_mailingList = $this->_getMailingList();
88
+ }
89
+
90
+ return $this;
91
+ }
92
+
93
+ public function setRequestType($type)
94
+ {
95
+ $this->_requestType = $type;
96
+
97
+ $this->_setRequestType($type);
98
+
99
+ return $this;
100
+ }
101
+
102
+ protected function _setRequestType($type)
103
+ {
104
+ $requestType = $this->_xml->requesttype;
105
+
106
+ if (! $requestType) {
107
+ $this->_xml->addChild('requesttype', $type);
108
+ } else {
109
+ $requestType = $type;
110
+ }
111
+
112
+ return $this;
113
+ }
114
+
115
+ public function setRequestMethod($method)
116
+ {
117
+ $this->_xml->addChild('requestmethod', $method);
118
+
119
+ return $this;
120
+ }
121
+
122
+ public function addDetails(array $detailsArray = array())
123
+ {
124
+ $details = $this->_xml->details;
125
+
126
+ if (! $details) {
127
+ $details = $this->_xml->addChild('details');
128
+ }
129
+
130
+ foreach ($detailsArray as $label => $detail) {
131
+ $details->addChild($label, $detail);
132
+ }
133
+
134
+ return $this;
135
+ }
136
+
137
+ public function addCustomfields(array $data = array())
138
+ {
139
+ if (empty($data)) {
140
+ return $this;
141
+ }
142
+
143
+ $details = $this->_xml->details;
144
+
145
+ if (! $details) {
146
+ Mage::throwException('XML tree don\'t have details branch.');
147
+ }
148
+
149
+ $customfields = $details->customfields;
150
+
151
+ if (! $customfields) {
152
+ $customfields = $this->_xml->details->addChild('customfields');
153
+ }
154
+
155
+ foreach ($data as $field) {
156
+ $item = $customfields->addChild('item');
157
+ $item->addChild('fieldid', $field['fieldid']);
158
+
159
+ if (is_array($field['value'])) {
160
+ $value = $item->addChild('value');
161
+ foreach ($field['value'] as $key => $val) {
162
+ $value->addChild($key, self::xmlEscape($val));
163
+ }
164
+ } else {
165
+ $item->addChild('value', self::xmlEscape($field['value']));
166
+ }
167
+
168
+ if (isset($field['strategy'])) {
169
+ $item->addChild('strategy', $field['strategy']);
170
+ }
171
+ }
172
+
173
+ return $this;
174
+ }
175
+
176
+ public function getReponseXml()
177
+ {
178
+ return $this->_responseXml;
179
+ }
180
+
181
+ public function send()
182
+ {
183
+ $ch = curl_init($this->getUrl());
184
+
185
+ $xml = $this->_xml->asXml();
186
+
187
+ $this->_initXml();
188
+
189
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
190
+ curl_setopt($ch, CURLOPT_POST, 1);
191
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
192
+
193
+ $result = @curl_exec($ch);
194
+
195
+ if ($result === false) {
196
+ $this->logError('Curl return null: ' . (string) $xml);
197
+ return null;
198
+ }
199
+
200
+ $this->_responseXml = new SimpleXMLElement($result);
201
+
202
+ if ((string) $this->_responseXml->status === self::STATUS_SUCCESS) {
203
+ $this->setResponseData($this->_responseXml->data);
204
+ $this->logSuccess((string) $this->_responseXml->data);
205
+ return true;
206
+ } elseif ((string) $this->_responseXml->status === self::STATUS_FAILED) {
207
+ $this->setErrorMessage((string) $this->_responseXml->errormessage);
208
+ $this->logError((string) $this->_responseXml->errormessage);
209
+ return false;
210
+ }
211
+
212
+ $this->logError('Unknown status: ' . $this->_responseXml->status);
213
+
214
+ return null;
215
+ }
216
+
217
+ protected function logError($text)
218
+ {
219
+ $helper = Mage::helper('mailplatform');
220
+
221
+ if (! $helper->logError()) {
222
+ return;
223
+ }
224
+
225
+ $text = $helper->__($text);
226
+
227
+ Mage::log($text, Zend_Log::ERR, $helper->getLogFileName(), true);
228
+
229
+ return $this;
230
+ }
231
+
232
+ protected function logSuccess($text)
233
+ {
234
+ $helper = Mage::helper('mailplatform');
235
+
236
+ if (! $helper->logSuccess()) {
237
+ return;
238
+ }
239
+
240
+ $text = $helper->__($text);
241
+
242
+ Mage::log($text, Zend_Log::INFO, $helper->getLogFileName(), true);
243
+
244
+ return $this;
245
+ }
246
+
247
+ static public function xmlEscape($string)
248
+ {
249
+ return str_replace(array('&', '<', '>', '\'', '"'), array('&amp;', '&lt;', '&gt;', '&apos;', '&quot;'), $string);
250
+ }
251
+
252
+ }
app/code/community/Mp/Mailplatform/Model/Subscribers.php ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Mp_Mailplatform_Model_Subscribers extends Mp_Mailplatform_Model_Request
4
+ {
5
+
6
+ protected function _construct()
7
+ {
8
+ parent::_construct();
9
+
10
+ $this->setRequestType('subscribers');
11
+ }
12
+
13
+ public function addSubscriberToList($email, $mailingList = null, $details = null, $customFields = null)
14
+ {
15
+ $this->setRequestMethod('AddSubscriberToList');
16
+
17
+ $this->setMailingList($mailingList);
18
+
19
+ if (isset($details['format'])) {
20
+ $this->setFormat($details['format']);
21
+ }
22
+
23
+ //Custom details
24
+ $allowed = array('confirmed', 'confirm_language', 'add_to_autoresponders');
25
+
26
+ if ($details) {
27
+ $details = array_intersect_key($details, array_flip($allowed));
28
+ }
29
+
30
+ $details['format'] = $this->_getFormat();
31
+
32
+ //Required
33
+ $details['mailinglist'] = $this->_getMailingList();
34
+
35
+ $details['emailaddress'] = $email;
36
+
37
+ $this->addDetails($details);
38
+
39
+ if (! empty($customFields)) {
40
+ $this->addCustomfields($customFields);
41
+ }
42
+
43
+ return $this->send();
44
+ }
45
+
46
+ public function isSubscriberOnList($email, $mailingList = null)
47
+ {
48
+ $this->setRequestMethod('IsSubscriberOnList');
49
+
50
+ $this->setMailingList($mailingList);
51
+
52
+ //Required
53
+ $details['mailinglist'] = $this->_getMailingList();
54
+
55
+ $details['emailaddress'] = $email;
56
+
57
+ $this->addDetails($details);
58
+
59
+ if ($this->send() && (string) $this->getResponseData() != '') {
60
+ return true;
61
+ }
62
+
63
+ return false;
64
+ }
65
+
66
+ public function update($email, $mailingList = null, $customFields = null)
67
+ {
68
+ $this->setRequestMethod('Update');
69
+
70
+ $this->setMailingList($mailingList);
71
+
72
+ //Required
73
+ $details['listid'] = $this->_getMailingList();
74
+
75
+ $details['emailaddress'] = $email;
76
+
77
+ $this->addDetails($details);
78
+
79
+ if (! empty($customFields)) {
80
+ $this->addCustomfields($customFields);
81
+ }
82
+
83
+ if ($this->send() && $this->getResponseData() == 'TRUE') {
84
+ return true;
85
+ }
86
+
87
+ return false;
88
+ }
89
+
90
+ static public function getCustomFieldId($customField)
91
+ {
92
+ $id = trim(Mage::getStoreConfig('mailplatform/subscribe/' . $customField));
93
+
94
+ if (! $id || $id == '') {
95
+ return;
96
+ }
97
+
98
+ return (int) $id;
99
+ }
100
+
101
+ public function getSendThankYou()
102
+ {
103
+ return (boolean) Mage::getStoreConfig('mailplatform/unsubscribe/sendthankyou');
104
+ }
105
+
106
+ public function unsubscribeSubscriber($email, $mailingList = null)
107
+ {
108
+ $this->setRequestMethod('UnsubscribeSubscriber');
109
+
110
+ $this->setMailingList($mailingList);
111
+
112
+ //Required
113
+ $details['listid'] = $this->_getMailingList();
114
+
115
+ $details['emailaddress'] = $email;
116
+
117
+ $details['sendthankyou'] = $this->getSendThankYou();
118
+
119
+ $this->addDetails($details);
120
+
121
+ return $this->send();
122
+ }
123
+
124
+ public function activateSubscriber($email, $mailingList = null)
125
+ {
126
+ $this->setRequestMethod('ActivateSubscriber');
127
+
128
+ $this->setMailingList($mailingList);
129
+
130
+ //Required
131
+ $details['listid'] = $this->_getMailingList();
132
+
133
+ $details['emailaddress'] = $email;
134
+
135
+ $this->addDetails($details);
136
+
137
+ return $this->send();
138
+ }
139
+ }
app/code/community/Mp/Mailplatform/controllers/AccountController.php DELETED
@@ -1,105 +0,0 @@
1
- <?php
2
- require_once (Mage::getModuleDir('controllers', 'Mage_Customer') . DS . 'AccountController.php');
3
-
4
- class Mp_Mailplatform_AccountController extends Mage_Customer_AccountController
5
- {
6
-
7
- public function editAction()
8
- {
9
- $this->loadLayout(array(
10
- 'default',
11
- 'customer_account_edit'
12
- ));
13
-
14
- $this->_initLayoutMessages('customer/session');
15
- $this->_initLayoutMessages('catalog/session');
16
-
17
- if ($block = $this->getLayout()->getBlock('customer_edit')) {
18
- $block->setRefererUrl($this->_getRefererUrl());
19
- }
20
-
21
- $data = $this->_getSession()->getCustomerFormData(true);
22
- $customer = $this->_getSession()->getCustomer();
23
- if (! empty($data)) {
24
- $customer->addData($data);
25
- }
26
-
27
- if ($this->getRequest()->getParam('changepass') == 1) {
28
- $customer->setChangePassword(1);
29
- }
30
-
31
- Mage::getSingleton('core/session', array('name' => 'frontend'))
32
- ->setData('customer_old_email', $customer->getEmail())
33
- ;
34
-
35
- $this->getLayout()
36
- ->getBlock('head')
37
- ->setTitle($this->__('Account Information'))
38
- ;
39
-
40
- $this->renderLayout();
41
- }
42
-
43
- public function confirmAction()
44
- {
45
- if ($this->_getSession()->isLoggedIn()) {
46
- $this->_redirect('*/*/');
47
- return;
48
- }
49
-
50
- try {
51
- $id = $this->getRequest()->getParam('id', false);
52
- $key = $this->getRequest()->getParam('key', false);
53
- $backUrl = $this->getRequest()->getParam('back_url', false);
54
- if (empty($id) || empty($key)) {
55
- throw new Exception($this->__('Bad request.'));
56
- }
57
-
58
- // load customer by id (try/catch in case if it throws exceptions)
59
- try {
60
- $customer = Mage::getModel('customer/customer')->load($id);
61
- if ((! $customer) || (! $customer->getId())) {
62
- throw new Exception('Failed to load customer by id.');
63
- }
64
- } catch (Exception $e) {
65
- throw new Exception($this->__('Wrong customer account specified.'));
66
- }
67
-
68
- // check if it is inactive
69
- if ($customer->getConfirmation()) {
70
- if ($customer->getConfirmation() !== $key) {
71
- throw new Exception($this->__('Wrong confirmation key.'));
72
- }
73
-
74
- // activate customer
75
- try {
76
- $customer->setConfirmation(null);
77
- $customer->save();
78
-
79
- $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($customer->getEmail());
80
-
81
- if ($subscriber->isSubscribed() && Mage::getStoreConfig('mailplatform/general/active')) {
82
- Mage::getSingleton('mailplatform/mailplatform')->subscribe($customer);
83
- }
84
- } catch (Exception $e) {
85
- throw new Exception($this->__('Failed to confirm customer account.'));
86
- }
87
-
88
- // log in and send greeting email, then die happy
89
- $this->_getSession()->setCustomerAsLoggedIn($customer);
90
- $successUrl = $this->_welcomeCustomer($customer, true);
91
- $this->_redirectSuccess($backUrl ? $backUrl : $successUrl);
92
- return;
93
- }
94
-
95
- // die happy
96
- $this->_redirectSuccess(Mage::getUrl('*/*/index', array('_secure' => true)));
97
- return;
98
- } catch (Exception $e) {
99
- // die unhappy
100
- $this->_getSession()->addError($e->getMessage());
101
- $this->_redirectError(Mage::getUrl('*/*/index', array('_secure' => true)));
102
- return;
103
- }
104
- }
105
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Mp/Mailplatform/controllers/Adminhtml/MailplatformController.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Mp_Mailplatform_Adminhtml_MailplatformController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+
6
+ public function indexAction()
7
+ {
8
+ Mage::getModel('mailplatform/cron')->sync(false);
9
+
10
+ $this->_redirect('adminhtml/newsletter_subscriber/');
11
+ }
12
+
13
+ public function syncCategoriesAction()
14
+ {
15
+ try {
16
+ Mage::getModel('mailplatform/cron')->updateCategories(false);
17
+ $this->getResponse()->setBody(Mage::helper('adminhtml')->__('Status: %s', 'OK'));
18
+ } catch (Exception $e) {
19
+ $this->getResponse()->setBody(Mage::helper('adminhtml')->__('Status: %s', 'FAILED'));
20
+ }
21
+ }
22
+
23
+ }
app/code/community/Mp/Mailplatform/controllers/IndexController.php DELETED
@@ -1,21 +0,0 @@
1
- <?php
2
-
3
- class Mp_Mailplatform_IndexController extends Mage_Adminhtml_Controller_Action
4
- {
5
-
6
- public function indexAction()
7
- {
8
- // collect all subscribers users
9
- $collectionarray = Mage::getResourceModel('newsletter/subscriber_collection')->showStoreInfo()
10
- ->showCustomerInfo()
11
- ->useOnlySubscribed()
12
- ->toArray()
13
- ;
14
-
15
- if ($collectionarray['totalRecords'] > 0) {
16
- Mage::getSingleton('mailplatform/mailplatform')->batchSubscribe($collectionarray['items']);
17
- }
18
-
19
- $this->_redirect('adminhtml/newsletter_subscriber/');
20
- }
21
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Mp/Mailplatform/etc/config.xml CHANGED
@@ -2,21 +2,14 @@
2
  <config>
3
  <modules>
4
  <Mp_Mailplatform>
5
- <version>1.0.1</version>
6
  </Mp_Mailplatform>
7
  </modules>
8
  <global>
9
- <rewrite>
10
- <pnpweb_mailplatform_account_edit>
11
- <from><![CDATA[#^/customer/account/edit/(.*)#]]></from>
12
- <to>mailplatform/account/edit</to>
13
- </pnpweb_mailplatform_account_edit>
14
- <pnpweb_mailplatform_account_confirm>
15
- <from><![CDATA[#^/customer/account/confirm/(.*)#]]></from>
16
- <to>mailplatform/account/confirm</to>
17
- </pnpweb_mailplatform_account_confirm>
18
- </rewrite>
19
  <blocks>
 
 
 
20
  <adminhtml>
21
  <rewrite>
22
  <newsletter_subscriber>Mp_Mailplatform_Block_Adminhtml_Newsletter_Subscriber</newsletter_subscriber>
@@ -33,7 +26,32 @@
33
  </rewrite>
34
  </newsletter>
35
  </models>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  </global>
 
 
 
 
 
 
 
 
 
37
  <adminhtml>
38
  <acl>
39
  <resources>
@@ -58,24 +76,27 @@
58
  </adminhtml>
59
  <admin>
60
  <routers>
61
- <mailplatform>
62
- <use>admin</use>
63
  <args>
64
- <module>Mp_Mailplatform</module>
65
- <frontName>mailplatform</frontName>
 
66
  </args>
67
- </mailplatform>
68
  </routers>
69
  </admin>
70
  <default>
71
  <mailplatform>
72
  <general>
73
  <active>0</active>
74
- <url>http://mailmailmail.net/xml.php</url>
75
  <username>admin</username>
76
  <token></token>
77
  </general>
78
  <subscribe>
 
 
 
79
  <email_type>html</email_type>
80
  <double_optin>0</double_optin>
81
  <update_existing>1</update_existing>
@@ -84,7 +105,37 @@
84
  <delete_member>0</delete_member>
85
  <send_goodbye>0</send_goodbye>
86
  <send_notify>0</send_notify>
 
87
  </unsubscribe>
 
 
 
 
 
 
 
 
 
88
  </mailplatform>
89
  </default>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  </config>
2
  <config>
3
  <modules>
4
  <Mp_Mailplatform>
5
+ <version>2.0.1</version>
6
  </Mp_Mailplatform>
7
  </modules>
8
  <global>
 
 
 
 
 
 
 
 
 
 
9
  <blocks>
10
+ <mailplatform>
11
+ <class>Mp_Mailplatform_Block</class>
12
+ </mailplatform>
13
  <adminhtml>
14
  <rewrite>
15
  <newsletter_subscriber>Mp_Mailplatform_Block_Adminhtml_Newsletter_Subscriber</newsletter_subscriber>
26
  </rewrite>
27
  </newsletter>
28
  </models>
29
+ <helpers>
30
+ <mailplatform>
31
+ <class>Mp_Mailplatform_Helper</class>
32
+ </mailplatform>
33
+ </helpers>
34
+ <events>
35
+ <checkout_submit_all_after>
36
+ <observers>
37
+ <mailplatform_checkout_submit_all_after>
38
+ <type>singleton</type>
39
+ <class>mailplatform/observer</class>
40
+ <method>onCheckoutSubmit</method>
41
+ </mailplatform_checkout_submit_all_after>
42
+ </observers>
43
+ </checkout_submit_all_after>
44
+ </events>
45
  </global>
46
+ <frontend>
47
+ <layout>
48
+ <updates>
49
+ <mp_mailplatform module="Mp_Mailplatform">
50
+ <file>mailplatform.xml</file>
51
+ </mp_mailplatform>
52
+ </updates>
53
+ </layout>
54
+ </frontend>
55
  <adminhtml>
56
  <acl>
57
  <resources>
76
  </adminhtml>
77
  <admin>
78
  <routers>
79
+ <adminhtml>
 
80
  <args>
81
+ <modules>
82
+ <mailplatform after="Mage_Adminhtml">Mp_Mailplatform_Adminhtml</mailplatform>
83
+ </modules>
84
  </args>
85
+ </adminhtml>
86
  </routers>
87
  </admin>
88
  <default>
89
  <mailplatform>
90
  <general>
91
  <active>0</active>
92
+ <url>http://client2.mailmailmail.net/xml.php</url>
93
  <username>admin</username>
94
  <token></token>
95
  </general>
96
  <subscribe>
97
+ <firstname>2</firstname>
98
+ <lastname>3</lastname>
99
+ <city>8</city>
100
  <email_type>html</email_type>
101
  <double_optin>0</double_optin>
102
  <update_existing>1</update_existing>
105
  <delete_member>0</delete_member>
106
  <send_goodbye>0</send_goodbye>
107
  <send_notify>0</send_notify>
108
+ <sendthankyou>1</sendthankyou>
109
  </unsubscribe>
110
+ <log>
111
+ <error>1</error>
112
+ <success>0</success>
113
+ <file_name>mailplatform.log</file_name>
114
+ </log>
115
+ <crontab>
116
+ <sync_subscribers>0</sync_subscribers>
117
+ <sync_categories>0</sync_categories>
118
+ </crontab>
119
  </mailplatform>
120
  </default>
121
+ <crontab>
122
+ <jobs>
123
+ <mailplatform_sync>
124
+ <schedule>
125
+ <cron_expr>0 */12 * * *</cron_expr>
126
+ </schedule>
127
+ <run>
128
+ <model>mailplatform/cron::sync</model>
129
+ </run>
130
+ </mailplatform_sync>
131
+ <mailplatform_sync_categories>
132
+ <schedule>
133
+ <cron_expr>0 */12 * * *</cron_expr>
134
+ </schedule>
135
+ <run>
136
+ <model>mailplatform/cron::updateCategories</model>
137
+ </run>
138
+ </mailplatform_sync_categories>
139
+ </jobs>
140
+ </crontab>
141
  </config>
app/code/community/Mp/Mailplatform/etc/system.xml CHANGED
@@ -71,6 +71,15 @@
71
  should be sent.
72
  </comment>
73
  </url>
 
 
 
 
 
 
 
 
 
74
  </fields>
75
  </general>
76
  <subscribe>
@@ -81,10 +90,55 @@
81
  <show_in_website>0</show_in_website>
82
  <show_in_store>1</show_in_store>
83
  <fields>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  <opt-in translate="label comment">
85
  <label>Opt-in</label>
86
  <frontend_type>text</frontend_type>
87
- <sort_order>2</sort_order>
88
  <show_in_default>0</show_in_default>
89
  <show_in_website>0</show_in_website>
90
  <show_in_store>0</show_in_store>
@@ -94,7 +148,7 @@
94
  <label>Email type</label>
95
  <frontend_type>select</frontend_type>
96
  <source_model>mailplatform/emailtype</source_model>
97
- <sort_order>3</sort_order>
98
  <show_in_default>1</show_in_default>
99
  <show_in_website>0</show_in_website>
100
  <show_in_store>0</show_in_store>
@@ -104,7 +158,7 @@
104
  <label>Double optin</label>
105
  <frontend_type>select</frontend_type>
106
  <source_model>adminhtml/system_config_source_yesno</source_model>
107
- <sort_order>4</sort_order>
108
  <show_in_default>0</show_in_default>
109
  <show_in_website>0</show_in_website>
110
  <show_in_store>0</show_in_store>
@@ -124,8 +178,6 @@
124
  updated instead of throwing and error
125
  </comment>
126
  </update_existing>
127
-
128
-
129
  </fields>
130
  </subscribe>
131
  <unsubscribe>
@@ -171,8 +223,87 @@
171
  address defined in the list email notification settings
172
  </comment>
173
  </send_notify>
 
 
 
 
 
 
 
 
 
 
174
  </fields>
175
  </unsubscribe>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
  </groups>
177
  </mailplatform>
178
  </sections>
71
  should be sent.
72
  </comment>
73
  </url>
74
+ <sync_cat_button translate="label">
75
+ <label>Categories</label>
76
+ <frontend_type>button</frontend_type>
77
+ <frontend_model>mailplatform/adminhtml_system_config_form_button_synccategories</frontend_model>
78
+ <sort_order>20</sort_order>
79
+ <show_in_default>1</show_in_default>
80
+ <show_in_website>1</show_in_website>
81
+ <show_in_store>1</show_in_store>
82
+ </sync_cat_button>
83
  </fields>
84
  </general>
85
  <subscribe>
90
  <show_in_website>0</show_in_website>
91
  <show_in_store>1</show_in_store>
92
  <fields>
93
+ <firstname translate="label comment">
94
+ <label>Custom Field "Firstname" ID</label>
95
+ <frontend_type>text</frontend_type>
96
+ <sort_order>1</sort_order>
97
+ <show_in_default>1</show_in_default>
98
+ <show_in_website>0</show_in_website>
99
+ <show_in_store>1</show_in_store>
100
+ <comment>ID must match mailplatform's custom field ID.</comment>
101
+ </firstname>
102
+ <lastname translate="label comment">
103
+ <label>Custom Field "Lastname" ID</label>
104
+ <frontend_type>text</frontend_type>
105
+ <sort_order>2</sort_order>
106
+ <show_in_default>1</show_in_default>
107
+ <show_in_website>0</show_in_website>
108
+ <show_in_store>1</show_in_store>
109
+ <comment>ID must match mailplatform's custom field ID.</comment>
110
+ </lastname>
111
+ <city translate="label comment">
112
+ <label>Custom Field "City" ID</label>
113
+ <frontend_type>text</frontend_type>
114
+ <sort_order>3</sort_order>
115
+ <show_in_default>1</show_in_default>
116
+ <show_in_website>0</show_in_website>
117
+ <show_in_store>1</show_in_store>
118
+ <comment>ID must match mailplatform's custom field ID.</comment>
119
+ </city>
120
+ <purchase_date translate="label comment">
121
+ <label>Custom Field "Purchase Date" ID</label>
122
+ <frontend_type>text</frontend_type>
123
+ <sort_order>4</sort_order>
124
+ <show_in_default>1</show_in_default>
125
+ <show_in_website>0</show_in_website>
126
+ <show_in_store>1</show_in_store>
127
+ <comment>ID must match mailplatform's custom field ID.</comment>
128
+ </purchase_date>
129
+ <product_categories translate="label comment">
130
+ <label>Custom Field "Product Categories" ID</label>
131
+ <frontend_type>text</frontend_type>
132
+ <sort_order>5</sort_order>
133
+ <show_in_default>1</show_in_default>
134
+ <show_in_website>0</show_in_website>
135
+ <show_in_store>1</show_in_store>
136
+ <comment>ID must match mailplatform's custom field ID.</comment>
137
+ </product_categories>
138
  <opt-in translate="label comment">
139
  <label>Opt-in</label>
140
  <frontend_type>text</frontend_type>
141
+ <sort_order>6</sort_order>
142
  <show_in_default>0</show_in_default>
143
  <show_in_website>0</show_in_website>
144
  <show_in_store>0</show_in_store>
148
  <label>Email type</label>
149
  <frontend_type>select</frontend_type>
150
  <source_model>mailplatform/emailtype</source_model>
151
+ <sort_order>7</sort_order>
152
  <show_in_default>1</show_in_default>
153
  <show_in_website>0</show_in_website>
154
  <show_in_store>0</show_in_store>
158
  <label>Double optin</label>
159
  <frontend_type>select</frontend_type>
160
  <source_model>adminhtml/system_config_source_yesno</source_model>
161
+ <sort_order>8</sort_order>
162
  <show_in_default>0</show_in_default>
163
  <show_in_website>0</show_in_website>
164
  <show_in_store>0</show_in_store>
178
  updated instead of throwing and error
179
  </comment>
180
  </update_existing>
 
 
181
  </fields>
182
  </subscribe>
183
  <unsubscribe>
223
  address defined in the list email notification settings
224
  </comment>
225
  </send_notify>
226
+ <sendthankyou translate="label">
227
+ <label>Send Thank You</label>
228
+ <frontend_type>select</frontend_type>
229
+ <source_model>adminhtml/system_config_source_yesno</source_model>
230
+ <sort_order>1</sort_order>
231
+ <show_in_default>1</show_in_default>
232
+ <show_in_website>0</show_in_website>
233
+ <show_in_store>1</show_in_store>
234
+ <comment>Specifies if thank you email should be send for the unsubscribed contact.</comment>
235
+ </sendthankyou>
236
  </fields>
237
  </unsubscribe>
238
+ <log>
239
+ <label>Log settings</label>
240
+ <frontend_type>text</frontend_type>
241
+ <sort_order>3</sort_order>
242
+ <show_in_default>1</show_in_default>
243
+ <show_in_website>0</show_in_website>
244
+ <show_in_store>1</show_in_store>
245
+ <fields>
246
+ <error translate="label">
247
+ <label>Enable Error log</label>
248
+ <frontend_type>select</frontend_type>
249
+ <source_model>adminhtml/system_config_source_yesno</source_model>
250
+ <sort_order>1</sort_order>
251
+ <show_in_default>1</show_in_default>
252
+ <show_in_website>0</show_in_website>
253
+ <show_in_store>1</show_in_store>
254
+ <comment>Enable logs on XML API request error.</comment>
255
+ </error>
256
+ <success translate="label">
257
+ <label>Enable Success log</label>
258
+ <frontend_type>select</frontend_type>
259
+ <source_model>adminhtml/system_config_source_yesno</source_model>
260
+ <sort_order>2</sort_order>
261
+ <show_in_default>1</show_in_default>
262
+ <show_in_website>0</show_in_website>
263
+ <show_in_store>1</show_in_store>
264
+ <comment>Enable logs on XML API request success.</comment>
265
+ </success>
266
+ <file_name translate="label comment">
267
+ <label>Log file name</label>
268
+ <frontend_type>text</frontend_type>
269
+ <sort_order>3</sort_order>
270
+ <show_in_default>1</show_in_default>
271
+ <show_in_website>0</show_in_website>
272
+ <show_in_store>1</show_in_store>
273
+ <comment>XML API request log file name.</comment>
274
+ </file_name>
275
+ </fields>
276
+ </log>
277
+ <crontab>
278
+ <label>Crontab settings</label>
279
+ <frontend_type>text</frontend_type>
280
+ <sort_order>3</sort_order>
281
+ <show_in_default>1</show_in_default>
282
+ <show_in_website>0</show_in_website>
283
+ <show_in_store>1</show_in_store>
284
+ <fields>
285
+ <sync_subscribers translate="label">
286
+ <label>Enable Sync Subscribers</label>
287
+ <frontend_type>select</frontend_type>
288
+ <source_model>adminhtml/system_config_source_yesno</source_model>
289
+ <sort_order>1</sort_order>
290
+ <show_in_default>1</show_in_default>
291
+ <show_in_website>0</show_in_website>
292
+ <show_in_store>1</show_in_store>
293
+ <comment>Every 12 h. sync enabled users.</comment>
294
+ </sync_subscribers>
295
+ <sync_categories translate="label">
296
+ <label>Enable Sync "Product Categories"</label>
297
+ <frontend_type>select</frontend_type>
298
+ <source_model>adminhtml/system_config_source_yesno</source_model>
299
+ <sort_order>1</sort_order>
300
+ <show_in_default>1</show_in_default>
301
+ <show_in_website>0</show_in_website>
302
+ <show_in_store>1</show_in_store>
303
+ <comment>Every 12 h. sync custom field "Product Categories" values.</comment>
304
+ </sync_categories>
305
+ </fields>
306
+ </crontab>
307
  </groups>
308
  </mailplatform>
309
  </sections>
app/code/community/Mp/Mailplatform/sql/mp_mailplatform_setup/mysql4-install-0.0.1.php DELETED
File without changes
app/design/adminhtml/default/default/template/mailplatform/system/config/button.phtml ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php echo $this->getButtonHtml() ?>
2
+ <div id="<?php echo $this->getResponseFieldId() ?>" class="response" style="display: none" ></div>
3
+
4
+ <script type="text/javascript">
5
+ document.getElementById("<?php echo $this->getButtonId() ?>").addEventListener("click", function() {
6
+ var div = document.getElementById('<?php echo $this->getResponseFieldId() ?>');
7
+ div.style.display = "block";
8
+ new Ajax.Request("<?php echo $this->getAjaxCheckUrl() ?>", {
9
+ 'onComplete': function(response) {
10
+ div.innerHTML = response.responseText;
11
+ },
12
+ 'onFailure': function( $response ) {
13
+ div.innerHTML = '<?php echo $this->__('Status: ') ?>' + response.status;
14
+ }
15
+ });
16
+ });
17
+ </script>
app/design/frontend/base/default/layout/mailplatform.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <checkout_onepage_review>
4
+ <reference name="checkout.onepage.review.info.items.after">
5
+ <block type="core/template" name="is_subscribed" template="mailplatform/checkout/subscribe.phtml" />
6
+ </reference>
7
+ </checkout_onepage_review>
8
+ </layout>
app/design/frontend/base/default/template/mailplatform/checkout/subscribe.phtml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php if (Mage::helper('mailplatform')->isEnabled()): ?>
2
+ <input id="frontend-is-subscribe" type="checkbox" name="is_subscribed" title="<?php echo $this->__('Subscribe to newsletter') ?>" checked="checked" />
3
+ <label for="is_subscribed"><?php echo $this->__('Subscribe to newsletter') ?></label>
4
+ <script type="text/javascript">
5
+ if (! jQuery('#co-payment-form').find('input[name="is_subscribed"]').length) {
6
+ jQuery('#co-payment-form').append('<input name="is_subscribed" type="hidden" value="1">');
7
+ }
8
+
9
+ jQuery('#frontend-is-subscribe').on('change', function() {
10
+ var val = jQuery(this).prop('checked') ? 1 : 0;
11
+ jQuery('#co-payment-form').find('input[name="is_subscribed"]').val(val);
12
+ });
13
+ </script>
14
+ <?php endif ?>
app/etc/modules/Mp_Mailplattform.xml DELETED
@@ -1,9 +0,0 @@
1
- <?xml version="1.0"?>
2
- <config>
3
- <modules>
4
- <Mp_Mailplatform>
5
- <active>true</active>
6
- <codePool>community</codePool>
7
- </Mp_Mailplatform>
8
- </modules>
9
- </config>
 
 
 
 
 
 
 
 
 
package.xml CHANGED
@@ -1,13 +1,13 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>mailplatformconnector</name>
4
- <version>1.0.1</version>
5
  <stability>stable</stability>
6
- <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Sign-up for a free 30 days trial of award winning MailPlatform email marketing system - and connect Magento.</summary>
10
- <description>MailPlatform is a danish company serving large international and national retailers. Among the reference customers are: BoConcept, Toyota, Blockbuster, Guldbageren, Kop &amp;amp; Kande, TravelMarket, Skoringen, Zjoos, NEYE and hundreds of other clients.&#xD;
11
  &#xD;
12
  Try us for free the first month, signup here:&#xD;
13
  (all european countries)&#xD;
@@ -27,9 +27,9 @@ Alternated code by Magento standards&#xD;
27
  Corrected English grammar&#xD;
28
  Tested on Magento CE 1.7, 1.8 and 1.9</notes>
29
  <authors><author><name>ADEO WEB</name><user>adeoweb</user><email>info@adeoweb.biz</email></author></authors>
30
- <date>2015-07-01</date>
31
- <time>14:54:44</time>
32
- <contents><target name="magecommunity"><dir name="Mp"><dir name="Mailplatform"><dir name="Block"><dir name="Adminhtml"><dir name="Newsletter"><file name="Subscriber.php" hash="c493b153d8a1fb000b84695c04f3424f"/></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="43f52f0bc701ffd903d9e1cd88bcbc91"/></dir><dir name="Model"><file name="Emailtype.php" hash="f36192a5e1049df8794c5b76b8531b44"/><file name="Listids.php" hash="9962e23f391753c58389351c78763294"/><dir name="Mailplatform"><file name="Emailtype.php" hash="a1642c3a488fdf2bd4dc209d445d9e3c"/><file name="Listids.php" hash="0c459e26f6064dd59dd4b3a6f0551d82"/><file name="Mailplatform.php" hash="a418ea5de60146650d5bd8b95f0c2eef"/></dir><file name="Mailplatform.php" hash="951d2ec0a92d6b64a2e00992f4c90797"/><dir name="Newsletter"><file name="Subscriber.php" hash="dc4425c7238597310bce656fef96e297"/></dir></dir><dir name="controllers"><file name="AccountController.php" hash="27adffc92b19306ce4b1bd81a621a59c"/><file name="IndexController.php" hash="c51427dd3d390822dfd41995a3de99e5"/></dir><dir name="etc"><file name="config.xml" hash="d835123d7c5ef961f93de038928ab938"/><file name="system.xml" hash="c146365b6c17fdde937698a2e5817d25"/></dir><dir name="sql"><dir name="mp_mailplatform_setup"><file name="mysql4-install-0.0.1.php" hash="d41d8cd98f00b204e9800998ecf8427e"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Mp_Mailplattform.xml" hash="4a03e6902800e6435720616ed9c29826"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="newsletter"><dir name="subscriber"><file name="list_mailplatform.phtml" hash="9360f96d57fb8c9d2ade7b2cd564f5d7"/></dir></dir></dir></dir></dir></dir></target></contents>
33
  <compatible/>
34
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
35
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>mailplatformconnector</name>
4
+ <version>2.0.1</version>
5
  <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Sign-up for a free 30 days trial of award winning MailPlatform email marketing system - and connect Magento.</summary>
10
+ <description>MailPlatform is a danish company serving large international and national retailers. Among the reference customers are: BoConcept, Toyota, Blockbuster, Guldbageren, Kop &amp;amp;amp; Kande, TravelMarket, Skoringen, Zjoos, NEYE and hundreds of other clients.&#xD;
11
  &#xD;
12
  Try us for free the first month, signup here:&#xD;
13
  (all european countries)&#xD;
27
  Corrected English grammar&#xD;
28
  Tested on Magento CE 1.7, 1.8 and 1.9</notes>
29
  <authors><author><name>ADEO WEB</name><user>adeoweb</user><email>info@adeoweb.biz</email></author></authors>
30
+ <date>2015-08-28</date>
31
+ <time>11:10:05</time>
32
+ <contents><target name="magecommunity"><dir name="Mp"><dir name="Mailplatform"><dir name="Block"><dir name="Adminhtml"><dir name="Newsletter"><file name="Subscriber.php" hash="04d5f7999eb5e18cbe528f585177428b"/></dir><dir name="System"><dir name="Config"><dir name="Form"><dir name="Button"><file name="Synccategories.php" hash="237a2c689a921fdd1748343716b3d7f4"/></dir></dir></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="4a1873bfdc8c736ae3f8d281cb1276cf"/></dir><dir name="Model"><file name="Cron.php" hash="1e02e375198838ab25293bb6d87caba5"/><file name="Customfields.php" hash="bbf9a084f878cd3d41d5377b791070fb"/><file name="Emailtype.php" hash="f36192a5e1049df8794c5b76b8531b44"/><file name="Listids.php" hash="e2d44e356c32f0f2e0712e1b1b629b6b"/><file name="Lists.php" hash="06bebcece5b71cfdc8aaca78b991eabb"/><dir name="Newsletter"><file name="Subscriber.php" hash="7dc000082f10fd959e49ec7fe7f84c40"/></dir><file name="Observer.php" hash="d246f5c88ce2e3e95fe0e8e91ab8caf2"/><file name="Request.php" hash="92d34f897a63646c962fc5c716addbdd"/><file name="Subscribers.php" hash="e65553389baba4d6083d1cfff5d74dd2"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="MailplatformController.php" hash="ac3f091ea5aa85930c716d35898e49ef"/></dir></dir><dir name="etc"><file name="config.xml" hash="4777cbbe653f2ef9f2ee377cc7a58280"/><file name="system.xml" hash="540080ea0e3cef7a1d4678c20b05e535"/></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="mailplatform"><dir name="system"><dir name="config"><file name="button.phtml" hash="319d6ec55fc8a3cdf595aacfc42cfa8c"/></dir></dir></dir><dir name="newsletter"><dir name="subscriber"><file name="list_mailplatform.phtml" hash="9360f96d57fb8c9d2ade7b2cd564f5d7"/></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="mailplatform.xml" hash="7c7bb306998b8773091791b2c9650e8c"/></dir><dir name="template"><dir name="mailplatform"><dir name="checkout"><file name="subscribe.phtml" hash="01b1aaf72784ab6d1bf36d748e13bec2"/></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Mp_Mailplatform.xml" hash=""/></dir></target></contents>
33
  <compatible/>
34
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
35
  </package>