Conlabz_CrConnect - Version 3.0.0

Version Notes

New 3.0.0 version

Download this release

Release Info

Developer Conlabz GmbH
Extension Conlabz_CrConnect
Version 3.0.0
Comparing to
See all releases


Version 3.0.0

Files changed (45) hide show
  1. CleverReachDocumentation.docx +0 -0
  2. CleverReachDocumentationGerman.docx +0 -0
  3. app/code/community/Conlabz/CrConnect/Block/Adminhtml/Customer/Edit/Tab/Newsletter.php +81 -0
  4. app/code/community/Conlabz/CrConnect/Block/Adminhtml/Newsletter/Subscriber.php +89 -0
  5. app/code/community/Conlabz/CrConnect/Block/Config/GroupsApis.php +99 -0
  6. app/code/community/Conlabz/CrConnect/Block/Config/Key.php +25 -0
  7. app/code/community/Conlabz/CrConnect/Block/Config/Url.php +14 -0
  8. app/code/community/Conlabz/CrConnect/Block/Customer/Newsletter.php +47 -0
  9. app/code/community/Conlabz/CrConnect/Block/Groupsapis.php +55 -0
  10. app/code/community/Conlabz/CrConnect/Helper/Data.php +367 -0
  11. app/code/community/Conlabz/CrConnect/Model/Api.php +577 -0
  12. app/code/community/Conlabz/CrConnect/Model/Checkout/Observer.php +175 -0
  13. app/code/community/Conlabz/CrConnect/Model/Customer/Observer.php +243 -0
  14. app/code/community/Conlabz/CrConnect/Model/Newsletter/Subscriber.php +50 -0
  15. app/code/community/Conlabz/CrConnect/Model/Observer.php +212 -0
  16. app/code/community/Conlabz/CrConnect/Model/Search.php +118 -0
  17. app/code/community/Conlabz/CrConnect/Model/Subscriber.php +32 -0
  18. app/code/community/Conlabz/CrConnect/Model/System/Config/Source/EmptyForms.php +30 -0
  19. app/code/community/Conlabz/CrConnect/Model/System/Config/Source/EmptyList.php +30 -0
  20. app/code/community/Conlabz/CrConnect/Model/Website/Observer.php +31 -0
  21. app/code/community/Conlabz/CrConnect/controllers/AccountController.php +149 -0
  22. app/code/community/Conlabz/CrConnect/controllers/Adminhtml/ConfigController.php +52 -0
  23. app/code/community/Conlabz/CrConnect/controllers/Adminhtml/CrconnectController.php +33 -0
  24. app/code/community/Conlabz/CrConnect/controllers/HookController.php +176 -0
  25. app/code/community/Conlabz/CrConnect/controllers/ManageController.php +63 -0
  26. app/code/community/Conlabz/CrConnect/controllers/SearchController.php +31 -0
  27. app/code/community/Conlabz/CrConnect/controllers/SubscriberController.php +55 -0
  28. app/code/community/Conlabz/CrConnect/controllers/UnsubscribeController.php +84 -0
  29. app/code/community/Conlabz/CrConnect/etc/adminhtml.xml +23 -0
  30. app/code/community/Conlabz/CrConnect/etc/config.xml +158 -0
  31. app/code/community/Conlabz/CrConnect/etc/system.xml +136 -0
  32. app/design/adminhtml/default/default/layout/crconnect.xml +14 -0
  33. app/design/adminhtml/default/default/template/crconnect/config/header.phtml +19 -0
  34. app/design/adminhtml/default/default/template/crconnect/newsletter/subscriber/list.phtml +160 -0
  35. app/design/adminhtml/default/default/template/crconnect/system/config/form/field/array_groups.phtml +157 -0
  36. app/design/adminhtml/default/default/template/crconnect/system/config/form/field/cr_array_groups.phtml +188 -0
  37. app/design/frontend/base/default/layout/crconnect.xml +33 -0
  38. app/design/frontend/base/default/template/crconnect/customer/account/dashboard/info.phtml +48 -0
  39. app/design/frontend/base/default/template/crconnect/customer/form/newsletter.phtml +36 -0
  40. app/etc/modules/Conlabz_CrConnect.xml +9 -0
  41. app/locale/de_DE/Conlabz_CleverReach.csv +77 -0
  42. app/locale/en_US/Conlabz_CleverReach.csv +74 -0
  43. package.xml +28 -0
  44. skin/adminhtml/base/default/images/cleverreach/cleverreach-logo.png +0 -0
  45. skin/adminhtml/base/default/js/crconnect.js +221 -0
CleverReachDocumentation.docx ADDED
Binary file
CleverReachDocumentationGerman.docx ADDED
Binary file
app/code/community/Conlabz/CrConnect/Block/Adminhtml/Customer/Edit/Tab/Newsletter.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Conlabz_CrConnect_Block_Adminhtml_Customer_Edit_Tab_Newsletter extends Mage_Adminhtml_Block_Customer_Edit_Tab_Newsletter
3
+ {
4
+
5
+ public function initForm()
6
+ {
7
+
8
+ $form = new Varien_Data_Form();
9
+ $form->setHtmlIdPrefix('_newsletter');
10
+ $customer = Mage::registry('current_customer');
11
+ $subscriber = Mage::getModel('newsletter/subscriber')->loadByCustomer($customer);
12
+ Mage::register('subscriber', $subscriber);
13
+
14
+ $this->setForm($form);
15
+ return $this;
16
+
17
+
18
+ /*
19
+ * Next code wa have for displaying newsletter groups for subscribe.
20
+ * But In backend we have problems with assigning customers to Store based on previois subscriprion (magento part feature)
21
+ * So this code deaktivated at the moment
22
+ */
23
+ if ($customer->getWebsiteId() == 0) {
24
+ $this->setForm($form);
25
+ return $this;
26
+ }
27
+
28
+ $fieldset = $form->addFieldset('base_fieldset', array('legend'=>Mage::helper('customer')->__('Newsletter Information')));
29
+
30
+ $isMultiply = Mage::helper("crconnect")->getGroupsIds($customer->getGroupId());
31
+ if (!Mage::helper('crconnect')->isShowDefaultGroup() || !$isMultiply){
32
+
33
+ $fieldset->addField('subscription', 'checkbox',
34
+ array(
35
+ 'label' => Mage::helper('customer')->__('Subscribed to Newsletter?'),
36
+ 'name' => 'subscription'
37
+ )
38
+ );
39
+
40
+ if ($customer->isReadonly()) {
41
+ $form->getElement('subscription')->setReadonly(true, true);
42
+ }
43
+ Mage::helper('crconnect')->setCurrentStoreId($subscriber->getStoreId());
44
+ $form->getElement('subscription')->setIsChecked($subscriber->isSubscribed());
45
+
46
+ }
47
+
48
+ if (Mage::helper("crconnect")->isDefaultGroupUser($customer->getGroupId())){
49
+
50
+ $groupName = Mage::getModel('customer/group')->load($customer->getGroupId())->getCode();
51
+ $fieldset->addField('gsubscription', 'checkbox',
52
+ array(
53
+ 'label' => Mage::helper('customer')->__('Subscribed to %s Newsletter?', $groupName),
54
+ 'name' => 'gsubscription'
55
+ )
56
+ );
57
+
58
+ $ifCustomSubscribed = Mage::getModel('crconnect/api')->isSubscribed(
59
+ $customer->getEmail(),
60
+ $customer->getGroupId()
61
+ );
62
+
63
+ $form->getElement('gsubscription')->setIsChecked($ifCustomSubscribed);
64
+
65
+ }
66
+
67
+ if($changedDate = $this->getStatusChangedDate()) {
68
+ $fieldset->addField('change_status_date', 'label',
69
+ array(
70
+ 'label' => $subscriber->isSubscribed() ? Mage::helper('customer')->__('Last Date Subscribed') : Mage::helper('customer')->__('Last Date Unsubscribed'),
71
+ 'value' => $changedDate,
72
+ 'bold' => true
73
+ )
74
+ );
75
+ }
76
+
77
+ $this->setForm($form);
78
+ return $this;
79
+ }
80
+
81
+ }
app/code/community/Conlabz/CrConnect/Block/Adminhtml/Newsletter/Subscriber.php ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Conlabz_CrConnect_Block_Adminhtml_Newsletter_Subscriber extends Mage_Adminhtml_Block_Newsletter_Subscriber
4
+ {
5
+
6
+ protected $_successStatus = "SUCCESS";
7
+
8
+ public function __construct(){
9
+
10
+ $this->setTemplate('crconnect/newsletter/subscriber/list.phtml');
11
+
12
+ }
13
+
14
+ public function getSubscribersListData(){
15
+
16
+ $errorList = array();
17
+ $listInformation = array();
18
+
19
+ $api = Mage::getModel("crconnect/api");
20
+
21
+ if ($api->isConnected()){
22
+ $clientDetails = $api->clientGetDetails();
23
+ if ($clientDetails['error']){
24
+ $errorList[] = $clientDetails['error'];
25
+ }else{
26
+ $listInformation['client'] = $clientDetails['data'];
27
+ }
28
+
29
+ $groupStats = $api->groupGetStats();
30
+ if ($groupStats['error']){
31
+ $errorList[] = $groupStats['error'];
32
+ }else{
33
+ $listInformation['list'] = $groupStats['data'];
34
+ }
35
+
36
+ $groupDetails = $api->groupGetDetails();
37
+ if ($groupDetails['error']){
38
+ $errorList[] = $groupDetails['error'];
39
+ }else{
40
+ $listInformation['list']->name = $groupDetails['data']->name;
41
+ $listInformation['list']->last_mailing = $groupDetails['data']->last_mailing;
42
+ }
43
+
44
+ $listInformation['groups'] = array();
45
+
46
+ // If groups isset, get information for all groups in system
47
+ if ($api->isMultyGroups()){
48
+
49
+ $groups = Mage::helper("crconnect")->getGroupsIds();
50
+ $counter = 0;
51
+ foreach ($groups as $group){
52
+
53
+ $groupStats = $api->groupGetStats($group);
54
+ if ($groupStats['error']){
55
+ $errorList[] = $groupStats['error'];
56
+ }else{
57
+ $listInformation['groups'][$counter] = $groupStats['data'];
58
+ }
59
+
60
+ $groupDetails = $api->groupGetDetails($group);
61
+ if ($groupDetails['error']){
62
+ $errorList[] = $groupDetails['error'];
63
+ }else{
64
+ $listInformation['groups'][$counter]->name = $groupDetails['data']->name;
65
+ }
66
+
67
+ $counter++;
68
+ }
69
+
70
+ }
71
+
72
+
73
+ }else{
74
+
75
+ $errorList[] = Mage::helper("crconnect")->__("Can not connect to CleverReach account. Please check your Cleverreach settings.");
76
+
77
+ }
78
+
79
+ //Get amount of active and not active subscribers in system
80
+ $activeSubscribers = count(Mage::getResourceModel('newsletter/subscriber_collection')->addFieldToFilter("subscriber_status", '1'));
81
+ $inactiveSubscribers = count(Mage::getResourceModel('newsletter/subscriber_collection')->addFieldToFilter("subscriber_status", '0'));
82
+
83
+ $listInformation['actvie_subscribers'] = $activeSubscribers;
84
+ $listInformation['inactive_subscribers'] = $inactiveSubscribers;
85
+
86
+ return array('error'=>$errorList, 'info'=>$listInformation);
87
+
88
+ }
89
+ }
app/code/community/Conlabz/CrConnect/Block/Config/GroupsApis.php ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Conlabz_CrConnect_Block_Config_GroupsApis extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
3
+ {
4
+ protected $magentoOptions;
5
+
6
+ public function __construct()
7
+ {
8
+
9
+ /*
10
+ * Prepare settings columns
11
+ */
12
+ $this->addColumn('magento', array(
13
+ 'label' => Mage::helper('adminhtml')->__('Magento user groups'),
14
+ 'size' => 28,
15
+ ));
16
+ $this->addColumn('crconnect', array(
17
+ 'label' => Mage::helper('adminhtml')->__('CleverReach Group'),
18
+ 'size' => 28
19
+ ));
20
+ $this->addColumn('formid', array(
21
+ 'label' => Mage::helper('adminhtml')->__('CleverReach Form'),
22
+ 'size' => 28
23
+ ));
24
+
25
+ $this->_addAfter = false;
26
+ $this->_addButtonLabel = Mage::helper('adminhtml')->__('Add new group');
27
+
28
+ parent::__construct();
29
+ $this->setTemplate('crconnect/system/config/form/field/cr_array_groups.phtml');
30
+
31
+ // customer options
32
+ // Get Magento Groups List
33
+ $this->magentoOptions = array();
34
+ $allGroups = Mage::getModel('customer/group')->getCollection()->toOptionHash();
35
+ foreach($allGroups as $key=>$allGroup){
36
+ $this->magentoOptions[$key] = $allGroup;
37
+ }
38
+
39
+ }
40
+ /*
41
+ * Render Template
42
+ */
43
+ protected function _renderCellTemplate($columnName)
44
+ {
45
+
46
+ if (empty($this->_columns[$columnName])) {
47
+ throw new Exception('Wrong column name specified.');
48
+ }
49
+
50
+ $column = $this->_columns[$columnName];
51
+ $inputName = $this->getElement()->getName() . '[#{_id}][' . $columnName . ']';
52
+ $inputId = '#{_id}_' . $columnName . '';
53
+
54
+ $api = Mage::getModel("crconnect/api");
55
+ $groups = array();
56
+ if ($api->isConnected()){
57
+ $groups = $api->getGroupsForKey(Mage::helper('crconnect')->getApiKey());
58
+ if (!$groups){
59
+ $groups = array();
60
+ }
61
+ }
62
+
63
+ switch($columnName){
64
+
65
+ case 'magento':
66
+ $rendered = '<select style="width: 200px" name="'.$inputName.'" id="'.$inputId.'">';
67
+ foreach($this->magentoOptions as $att => $name)
68
+ {
69
+ $rendered .= '<option value="'.$att.'">'.$name.'</option>';
70
+ }
71
+ $rendered .= '</select>';
72
+ break;
73
+ case 'crconnect':
74
+ $rendered = '<select style="width: 200px" class="crconnect-groups-select" onchange="Crconnect.changeSubGroup(this)" id="'.$inputId.'" name="'.$inputName.'"><option value="">'.Mage::helper('crconnect')->__('Please select subscribers group').'</option>';
75
+ foreach($groups as $group)
76
+ {
77
+ $rendered .= '<option value="'.$group->id.'">'.$group->name.'</option>';
78
+ }
79
+ $rendered .= '</select>';
80
+ break;
81
+ case 'formid':
82
+ $emptyForms = Mage::getModel("crconnect/system_config_source_emptyForms")->toOptionArray();
83
+ $rendered = '<select style="width: 200px" name="'.$inputName.'" id="'.$inputId.'" class="crconnect-forms-select">';
84
+ foreach($emptyForms as $emptyForm)
85
+ {
86
+ $rendered .= '<option value="'.$emptyForm['value'].'">'.$emptyForm['label'].'</option>';
87
+ }
88
+ $rendered .= '</select>';
89
+ break;
90
+ default:
91
+ // $rendered = '<input type="text" name="' . $inputName . '" value="#{' . $columnName . '}" ' . ($column['size'] ? 'size="' . $column['size'] . '"' : '') . '/>';
92
+ break;
93
+
94
+
95
+ }
96
+
97
+ return $rendered;
98
+ }
99
+ }
app/code/community/Conlabz/CrConnect/Block/Config/Key.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Conlabz_CrConnect_Block_Config_Key extends Mage_Adminhtml_Block_System_Config_Form_Field
3
+ {
4
+
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+ }
9
+
10
+ /*
11
+ * Generate Feed URL for copy/paste
12
+ */
13
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
14
+ {
15
+
16
+ $element = parent::_getElementHtml($element);
17
+ $element .= '<button style="" onkeyup="Crconnect.confirmEnable()" onclick="Crconnect.confirmMainKey(true)" id="confirm-key-button" class="scalable disabled" type="button" disabled>
18
+ <span>'.Mage::helper("crconnect")->__("Confirm key").'</span>
19
+ </button>';
20
+
21
+ return '<div style="width:430px">'.$element."</div>";
22
+
23
+ }
24
+
25
+ }
app/code/community/Conlabz/CrConnect/Block/Config/Url.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Conlabz_CrConnect_Block_Config_Url extends Mage_Adminhtml_Block_System_Config_Form_Field
3
+ {
4
+ /*
5
+ * Generate Feed URL for copy/paste
6
+ */
7
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
8
+ {
9
+ $url = Mage::getUrl('crconnect/search/index');
10
+ $url .= "<font color='red'>store/1/</font>";
11
+ return "<b>".$url."</b>";
12
+ }
13
+
14
+ }
app/code/community/Conlabz/CrConnect/Block/Customer/Newsletter.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Conlabz_CrConnect_Block_Customer_Newsletter extends Mage_Customer_Block_Newsletter
3
+ {
4
+
5
+ private $_api;
6
+
7
+ public function __construct()
8
+ {
9
+ $this->setCustomerGroupId(Mage::getSingleton('customer/session')->getCustomerGroupId());
10
+ $this->_api = Mage::getModel('crconnect/api');
11
+
12
+ parent::__construct();
13
+ }
14
+
15
+ public function getCustomerGroupName(){
16
+
17
+ $groupName = Mage::getModel('customer/group')->load($this->getCustomerGroupId())->getCode();
18
+
19
+ }
20
+ /*
21
+ * Check if Customer Group not default
22
+ *
23
+ * @return bool
24
+ */
25
+ public function isDefaultGroupUser(){
26
+
27
+ return Mage::helper("crconnect")->isDefaultGroupUser($this->getCustomerGroupId());
28
+
29
+ }
30
+
31
+ public function isDefaultSubscribed(){
32
+
33
+ return $this->_api->isSubscribed(Mage::getSingleton('customer/session')->getCustomer()->getEmail());
34
+
35
+ }
36
+
37
+ public function isCustomSubscribed(){
38
+
39
+ return $this->_api->isSubscribed(
40
+ Mage::getSingleton('customer/session')->getCustomer()->getEmail(),
41
+ Mage::getSingleton('customer/session')->getCustomerGroupId()
42
+ );
43
+
44
+ }
45
+
46
+
47
+ }
app/code/community/Conlabz/CrConnect/Block/Groupsapis.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Conlabz_CrConnect_Block_GroupsApis extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
3
+ {
4
+ protected $magentoOptions;
5
+
6
+ public function __construct()
7
+ {
8
+ $this->addColumn('magento', array(
9
+ 'label' => Mage::helper('adminhtml')->__('Magento user groups'),
10
+ 'size' => 28,
11
+ ));
12
+ $this->addColumn('crconnect', array(
13
+ 'label' => Mage::helper('adminhtml')->__('CrConnect group API key'),
14
+ 'size' => 28
15
+ ));
16
+ $this->_addAfter = false;
17
+ $this->_addButtonLabel = Mage::helper('adminhtml')->__('Add API keys for group');
18
+
19
+ parent::__construct();
20
+ $this->setTemplate('crconnect/system/config/form/field/array_groups.phtml');
21
+
22
+ // customer options
23
+ $this->magentoOptions = array();
24
+ $allGroups = Mage::getModel('customer/group')->getCollection()->toOptionHash();
25
+ foreach($allGroups as $key=>$allGroup){
26
+ $this->magentoOptions[$key] = $allGroup;
27
+ }
28
+
29
+ }
30
+
31
+ protected function _renderCellTemplate($columnName)
32
+ {
33
+ if (empty($this->_columns[$columnName])) {
34
+ throw new Exception('Wrong column name specified.');
35
+ }
36
+ $column = $this->_columns[$columnName];
37
+ $inputName = $this->getElement()->getName() . '[#{_id}][' . $columnName . ']';
38
+
39
+ if($columnName == 'magento')
40
+ {
41
+ $rendered = '<select name="'.$inputName.'">';
42
+ foreach($this->magentoOptions as $att => $name)
43
+ {
44
+ $rendered .= '<option value="'.$att.'">'.$name.'</option>';
45
+ }
46
+ $rendered .= '</select>';
47
+ }
48
+ else
49
+ {
50
+ return '<input type="text" name="' . $inputName . '" value="#{' . $columnName . '}" ' . ($column['size'] ? 'size="' . $column['size'] . '"' : '') . '/>';
51
+ }
52
+
53
+ return $rendered;
54
+ }
55
+ }
app/code/community/Conlabz/CrConnect/Helper/Data.php ADDED
@@ -0,0 +1,367 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Conlabz_CrConnect_Helper_Data extends Mage_Core_Helper_Abstract {
4
+
5
+ const XML_WSDL_PATH = "http://api.cleverreach.com/soap/interface_v5.1.php?wsdl";
6
+ const XML_API_KEY_CONFIG_PATH = "crroot/crconnect/api_key";
7
+ const XML_LIST_ID_CONFIG_PATH = "crroot/crconnect/list_id";
8
+ const XML_FORM_ID_CONFIG_PATH = "crroot/crconnect/form_id";
9
+ const XML_SYNC_ORDERS_CONFIG_PATH = "crroot/crconnect/sync_orders";
10
+ const XML_GROUP_SEPARATION_CONFIG_PATH = "crroot/crconnect/auto_separate";
11
+ const XML_GROUP_KEYS = "crroot/crconnect/groups_keys";
12
+ const XML_PATH_LOGGED_CONFIRM_EMAIL_TEMPLATE = 'crroot/crconnect/confirm_newsletter_logged';
13
+ const XML_IS_SHOW_CUSTOMER_GROUP = 'crroot/crconnect/showgroup';
14
+
15
+ const XML_FEED_PASSWORD = 'crroot/csconnect_search/password';
16
+
17
+ const DEFAULT_GROUP_ID = 1;
18
+
19
+ private $_currentStoreId = false;
20
+ private $_currentWebsiteId = false;
21
+
22
+ public function setCurrentStoreId($storeId = false){
23
+ $this->_currentStoreId = $storeId;
24
+ }
25
+ public function setCurrentWebsiteId($storeId = false){
26
+ $this->_currentWebsiteId = $storeId;
27
+ }
28
+
29
+ /*
30
+ * Get Wsdl path
31
+ *
32
+ * @return string - path
33
+ */
34
+
35
+ public function getWsdl() {
36
+ return self::XML_WSDL_PATH;
37
+ }
38
+
39
+ /*
40
+ * Get Feed password (same should be inserted on CleverReach account)
41
+ */
42
+
43
+ public function getCleverReachFeedPassword() {
44
+ return $this->getConfigForStore(self::XML_FEED_PASSWORD);
45
+ }
46
+
47
+ /*
48
+ * Check if Douple Opt In enabled
49
+ */
50
+
51
+ public function isDoubleOptInEnabled() {
52
+ return $this->getConfigForStore(self::XML_PATH_LOGGED_CONFIRM_EMAIL_TEMPLATE);
53
+ }
54
+
55
+ /*
56
+ * Get Api Key
57
+ *
58
+ * @return string - api key
59
+ */
60
+
61
+ public function getApiKey() {
62
+ return $this->getConfigForStore(self::XML_API_KEY_CONFIG_PATH);
63
+ }
64
+
65
+ /*
66
+ * Set Api Key
67
+ *
68
+ * @return string - api key
69
+ */
70
+ public function setApiKey($key) {
71
+ return Mage::getConfig()->saveConfig(self::XML_API_KEY_CONFIG_PATH, $key);
72
+ }
73
+
74
+ /*
75
+ * Get Default List Id
76
+ *
77
+ * @return string - list Id
78
+ */
79
+
80
+ public function getDefaultListId() {
81
+
82
+ return $this->getConfigForStore(self::XML_LIST_ID_CONFIG_PATH);
83
+
84
+ }
85
+
86
+ /*
87
+ * Get Default Form Id
88
+ *
89
+ * @return string - list Id
90
+ */
91
+
92
+ public function getDefaultFormId() {
93
+
94
+ return $this->getConfigForStore(self::XML_FORM_ID_CONFIG_PATH);
95
+
96
+ }
97
+
98
+ /*
99
+ * Check if orders tracking enabled
100
+ *
101
+ * @return bool - 0 or 1
102
+ */
103
+
104
+ public function isTrackingEnabled() {
105
+ return $this->getConfigForStore(self::XML_SYNC_ORDERS_CONFIG_PATH);
106
+ }
107
+
108
+ /*
109
+ * Check if automated separation enabled
110
+ *
111
+ * @return bool - 0 or 1
112
+ */
113
+
114
+ public function isSeparationEnabled() {
115
+ return $this->getConfigForStore(self::XML_GROUP_SEPARATION_CONFIG_PATH);
116
+ }
117
+
118
+ /*
119
+ * Log Clever Reach Connect activity
120
+ *
121
+ * @param - string message
122
+ */
123
+
124
+ public function log($message) {
125
+
126
+ Mage::log($message, null, "crconnect.log", true);
127
+ }
128
+
129
+ /*
130
+ * Get groups keys json value from system settings
131
+ *
132
+ * @return json
133
+ */
134
+ public function getGroupsSystemValue(){
135
+
136
+ return $this->getConfigForStore(self::XML_GROUP_KEYS);
137
+
138
+ }
139
+
140
+ public function getConfigForStore($path){
141
+
142
+ $newsletterConfig = Mage::getStoreConfig($path);
143
+
144
+ if ($store = $this->_currentStoreId){
145
+ return Mage::getStoreConfig($path, $store);
146
+ }
147
+ if ($website = $this->_currentWebsiteId){
148
+ $newsletterConfig = (array)Mage::getConfig()->getNode('websites/'.$website.'/'.$path);
149
+ if (isset($newsletterConfig[0])){
150
+ return $newsletterConfig[0];
151
+ }
152
+ }
153
+ // if ($website = Mage::getSingleton("adminhtml/session")->getCrCustomerWebsite($website)){
154
+ // $newsletterConfig = (array)Mage::getConfig()->getNode('websites/'.$website.'/'.$path);
155
+ // if (isset($newsletterConfig[0])){
156
+ // return $newsletterConfig[0];
157
+ // }
158
+ // }
159
+
160
+ if ($store = Mage::app()->getRequest()->getParam('store')){
161
+ $newsletterConfig = Mage::getStoreConfig($path, $store);
162
+ }else{
163
+ if ($website = Mage::app()->getRequest()->getParam('website')){
164
+ $newsletterConfig = (array)Mage::getConfig()->getNode('websites/'.$website.'/'.$path);
165
+ if (isset($newsletterConfig[0])){
166
+ $newsletterConfig = $newsletterConfig[0];
167
+ }
168
+ }
169
+ }
170
+ return $newsletterConfig;
171
+
172
+ }
173
+ /*
174
+ * get non default groups ids
175
+ *
176
+ * @param int group ID - if isset get key for special group
177
+ * @param bool - if true - return default list if in case if user groups Id key not found
178
+ *
179
+ * @return array | int = array of keys, OR groups ID
180
+ */
181
+
182
+ public function getGroupsIds($groupId = false, $defaultOnFail = false) {
183
+
184
+ $newsletterConfig = unserialize($this->getConfigForStore(self::XML_GROUP_KEYS));
185
+ $keysArray = array();
186
+
187
+ // Generate array of groupId=>key
188
+ if (is_array($newsletterConfig)) {
189
+ foreach ($newsletterConfig as $config) {
190
+ $keysArray[$config['magento']] = $config['crconnect'];
191
+ }
192
+ }
193
+
194
+ if ($groupId !== false) {
195
+ if (isset($keysArray[$groupId])) {
196
+ return $keysArray[$groupId];
197
+ } else {
198
+ if ($defaultOnFail) {
199
+ return $this->getDefaultListId();
200
+ }
201
+ return false;
202
+ }
203
+ }
204
+
205
+ return $keysArray;
206
+ }
207
+
208
+ /*
209
+ * get non default forms ids
210
+ *
211
+ * @param int group ID - if isset get key for special group
212
+ * @param bool - if true - return default list if in case if user groups Id key not found
213
+ *
214
+ * @return array | int = array of keys, OR groups ID
215
+ */
216
+
217
+ public function getFormsIds($groupId = false, $defaultOnFail = false) {
218
+
219
+ $newsletterConfig = unserialize($this->getConfigForStore(self::XML_GROUP_KEYS));
220
+ $keysArray = array();
221
+
222
+ // Generate array of groupId=>key
223
+ if (is_array($newsletterConfig)) {
224
+ foreach ($newsletterConfig as $config) {
225
+ $keysArray[$config['magento']] = $config['formid'];
226
+ }
227
+ }
228
+
229
+ if ($groupId !== false) {
230
+ if (isset($keysArray[$groupId])) {
231
+ return $keysArray[$groupId];
232
+ } else {
233
+ if ($defaultOnFail) {
234
+ return $this->getDefaultFormId();
235
+ }
236
+ return false;
237
+ }
238
+ }
239
+
240
+ return $keysArray;
241
+ }
242
+
243
+ /*
244
+ * get non default forms ids
245
+ *
246
+ * @return array | int = array of keys, OR groups ID
247
+ */
248
+
249
+ public function getFormsIdsByKeys() {
250
+
251
+ $newsletterConfig = unserialize($this->getConfigForStore(self::XML_GROUP_KEYS));
252
+
253
+ $keysArray = array();
254
+
255
+ // Generate array of groupId=>key
256
+ if (is_array($newsletterConfig)) {
257
+ foreach ($newsletterConfig as $key=>$config) {
258
+ if (isset($config['formid'])){
259
+ $keysArray[$key] = $config['formid'];
260
+ }
261
+ }
262
+ }
263
+
264
+ return $keysArray;
265
+ }
266
+
267
+ /*
268
+ * get active subscribers
269
+ */
270
+
271
+ public function getActiveMageSubscribers() {
272
+
273
+ return Mage::getResourceModel('newsletter/subscriber_collection')
274
+ ->showStoreInfo()
275
+ ->showCustomerInfo()
276
+ ->useOnlySubscribed()
277
+ ->getData();
278
+ }
279
+
280
+ public function prepareUserdata($customer, $custom_fields = false, $deactivate = false) {
281
+
282
+ $name = $customer->getFirstname() . " " . $customer->getLastname();
283
+ $newEmail = $customer->getEmail();
284
+ $subscribed = $customer->getIsSubscribed();
285
+ $shippingAddress = false;
286
+ if ($shippingAddress = $customer->getDefaultBillingAddress()){
287
+ $shippingAddress = $shippingAddress->getData();
288
+ }
289
+
290
+ if ($group = Mage::getModel('customer/group')->load($customer->getGroupId())) {
291
+ $group = $group->getData();
292
+ }
293
+
294
+
295
+ if ($shippingAddress) {
296
+ $crReceiver = array(
297
+ 'email' => $newEmail,
298
+ 'source' => 'MAGENTO');
299
+ $crReceiver["attributes"] = array(
300
+ 0 => array("key" => "firstname", "value" => @$shippingAddress["firstname"]),
301
+ 1 => array("key" => "lastname", "value" => @$shippingAddress["lastname"]),
302
+ 2 => array("key" => "street", "value" => @$shippingAddress["street"]),
303
+ 3 => array("key" => "zip", "value" => @$shippingAddress["postcode"]),
304
+ 4 => array("key" => "city", "value" => @$shippingAddress["city"]),
305
+ 5 => array("key" => "country", "value" => @$shippingAddress["country_id"]),
306
+ 6 => array("key" => "salutation", "value" => @$shippingAddress["prefix"]),
307
+ 7 => array("key" => "title", "value" => @$shippingAddress["suffix"]),
308
+ 8 => array("key" => "company", "value" => @$shippingAddress["company"]));
309
+ } else {
310
+ $crReceiver = array(
311
+ 'email' => $newEmail,
312
+ 'source' => "MAGENTO"
313
+ );
314
+ $crReceiver["attributes"] = array(0 => array("key" => 'firstname', "value" => @$customer->getFirstname()),
315
+ 1 => array("key" => 'lastname', "value" => @$customer->getLastname()),
316
+ 2 => array("key" => 'salutation', "value" => @$customer->getPrefix()),
317
+ 3 => array("key" => 'title', "value" => @$customer->getSuffix()));
318
+ }
319
+
320
+ if($deactivate){
321
+ $crReceiver['deactivated'] = 1;
322
+ }
323
+
324
+ array_push($crReceiver["attributes"], array("key" => 'group_id', "value" => @$group["customer_group_id"]));
325
+ array_push($crReceiver["attributes"], array("key" => 'group_name', "value" => @$group["customer_group_code"]));
326
+ array_push($crReceiver["attributes"], array("key" => 'gender', "value" => @$customer->getGender()));
327
+ array_push($crReceiver["attributes"], array("key" => 'store', "value" => @Mage::getModel('customer/customer')->load($customer->getId())->getData("created_in")));
328
+
329
+ if ($custom_fields) {
330
+ foreach ($custom_fields as $key => $val) {
331
+ array_push($crReceiver["attributes"], array("key" => $key, "value" => $val));
332
+ }
333
+ }
334
+
335
+ return $crReceiver;
336
+ }
337
+
338
+ /*
339
+ * Show or not customer group as separate group
340
+ */
341
+ public function isShowDefaultGroup(){
342
+
343
+ return $this->getConfigForStore(self::XML_IS_SHOW_CUSTOMER_GROUP);
344
+
345
+ }
346
+
347
+ /*
348
+ * If more then 1 user group key added, return true
349
+ */
350
+ public function isMultiGroupsSettings(){
351
+
352
+ $groupIds = $this->getGroupsIds();
353
+ if (is_array($groupIds) && sizeof($groupIds) > 1){
354
+ return true;
355
+ }
356
+ return false;
357
+
358
+ }
359
+ public function isDefaultGroupUser($groupId){
360
+
361
+ if ($groupId != self::DEFAULT_GROUP_ID){
362
+ return true;
363
+ }
364
+ return false;
365
+
366
+ }
367
+ }
app/code/community/Conlabz/CrConnect/Model/Api.php ADDED
@@ -0,0 +1,577 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Conlabz_CrConnect_Model_Api extends Mage_Core_Model_Abstract {
4
+
5
+ const SUCCESS_STATUS = "SUCCESS";
6
+
7
+ const ERROR_CODE_DUPLICATED = 50;
8
+ const ERROR_CODE_INVALID = 40;
9
+
10
+ public function __construct() {
11
+
12
+ $this->init();
13
+
14
+ }
15
+
16
+ public function init($storeId = false){
17
+
18
+ $this->_helper = Mage::helper('crconnect');
19
+
20
+ if ($storeId){
21
+ $this->_helper->log($this->_helper->__("SET Helper Store: ". $storeId));
22
+ $this->_helper->setCurrentStoreId($storeId);
23
+ }
24
+
25
+ $this->_apiKey = $this->_helper->getApiKey();
26
+ $this->_listID = $this->_helper->getDefaultListId();
27
+ $this->_client = $this->getSoapClient();
28
+ $this->_groupsListIds = $this->_helper->getGroupsIds();
29
+
30
+ }
31
+ /*
32
+ * Get Connection to CrConnect
33
+ */
34
+
35
+ public function getSoapClient() {
36
+
37
+ try {
38
+ $client = new SoapClient($this->_helper->getWsdl(), array("trace" => true, "exception" => 0));
39
+ return $client;
40
+ } catch (Exception $e) {
41
+ $this->_helper->log(Mage::helper("crconnect")->__("Connection to Cleverreach Server failed"));
42
+ $this->_helper->log($e->getMessage());
43
+ return false;
44
+ }
45
+ return false;
46
+ }
47
+
48
+
49
+ public function subscribe($customer = false, $groupId = 0) {
50
+
51
+ if ($this->isConnected()){
52
+
53
+ if (!$customer) {
54
+ $customer = Mage::getSingleton('customer/session')->getCustomer();
55
+ }
56
+ $crReceiver = $this->_helper->prepareUserdata($customer, array('newsletter' => 1));
57
+ $addResult = $this->receiverAdd($crReceiver, $groupId);
58
+ if ($addResult->status == self::SUCCESS_STATUS) {
59
+
60
+ $this->_helper->log($this->_helper->__("CALL: receiverAdd - SUCCESS"));
61
+ $this->_helper->log($crReceiver);
62
+ $this->_helper->log("receiverAdd: GroupId: ".$groupId);
63
+
64
+ return true;
65
+ } else {
66
+
67
+ $this->_helper->log($this->_helper->__("CALL: receiverAdd - FAIL, then call receiverSetActive:".$customer->getEmail()));
68
+ $this->_helper->log("receiverSetActive: GroupId: ".$groupId);
69
+
70
+ $addResult = $this->receiverSetActive($customer->getEmail(), $groupId);
71
+ }
72
+ return true;
73
+
74
+ }
75
+ return false;
76
+ }
77
+
78
+ public function unsubscribe($email = false, $groupId = 0) {
79
+
80
+ if ($this->isConnected() && $email){
81
+
82
+ $result = $this->receiverSetInactive($email, $groupId);
83
+ if ($result->status == self::SUCCESS_STATUS) {
84
+ $this->_helper->log($this->_helper->__("CALL: receiverSetInactive - SUCCESS, Email:".$email." | GroupId:".$groupId));
85
+ return true;
86
+ }
87
+
88
+ }
89
+ return false;
90
+ }
91
+
92
+ /*
93
+ * Check if connection was successfull
94
+ */
95
+
96
+ public function isConnected() {
97
+
98
+ if ($this->_client !== false && $this->_client !== NULL) {
99
+ return true;
100
+ }
101
+ return false;
102
+ }
103
+
104
+ /*
105
+ * If Account have more then 1 group
106
+ */
107
+
108
+ public function isMultyGroups() {
109
+
110
+ if (is_array($this->_groupsListIds) && sizeof($this->_groupsListIds) > 0) {
111
+ return true;
112
+ }
113
+ return false;
114
+ }
115
+
116
+ public function getGroupKey($groupId){
117
+
118
+ if ($groupId == 0) {
119
+ $listId = $this->_helper->getDefaultListId();
120
+ } else {
121
+ $listId = $this->_helper->getGroupsIds($groupId);
122
+ }
123
+ return $listId;
124
+ }
125
+
126
+ /*
127
+ * Subscriber simple user to special group
128
+ */
129
+ public function receiverAdd($customerData, $groupId = 0) {
130
+
131
+ $listId = $this->getGroupKey($groupId);
132
+
133
+ $this->_helper->log("CALL: receiverAdd");
134
+ $this->_helper->log($customerData);
135
+
136
+ return $this->_client->receiverAdd($this->_apiKey, $listId, $customerData);
137
+
138
+ }
139
+
140
+ /*
141
+ * Deactivates a given receiver/email
142
+ */
143
+ public function receiverSetInactive($email, $groupId = 0) {
144
+
145
+ $listId = $this->getGroupKey($groupId);
146
+ $this->_helper->log("CALL: receiverSetInactive - Email".$email." | GroupId:". $groupId);
147
+ return $this->_client->receiverSetInactive($this->_apiKey, $listId, $email);
148
+
149
+ }
150
+
151
+ public function receiverSetActive($email, $groupId = 0) {
152
+
153
+ $listId = $this->getGroupKey($groupId);
154
+ $this->_helper->log("CALL: receiverSetActive - Email".$email." | GroupId:". $groupId);
155
+ return $this->_client->receiverSetActive($this->_apiKey, $listId, $email);
156
+
157
+ }
158
+
159
+
160
+ /*
161
+ * Return request result
162
+ *
163
+ * @param string result
164
+ * @param error message if exists, or false
165
+ *
166
+ * @return array - result
167
+ */
168
+
169
+ private function returnResult($result, $fail = false) {
170
+
171
+ $return = array();
172
+ $return['error'] = $fail;
173
+ $return['data'] = $result;
174
+ return $return;
175
+ }
176
+
177
+ /*
178
+ * Get user account details
179
+ */
180
+
181
+ public function clientGetDetails() {
182
+
183
+ $result = $this->_client->clientGetDetails($this->_apiKey);
184
+ if ($result->status == self::SUCCESS_STATUS) {
185
+ return $this->returnResult($result->data);
186
+ } else {
187
+
188
+ $this->_helper->log($this->_helper->__("CALL: clientGetDetails - failed"));
189
+ $this->_helper->log($result->message);
190
+
191
+ return $this->returnResult($result->data, $this->_helper->__("Your CleverReach API key seems to be invalid. Please check them and try again! <br /> Have no CleverReach account? Contact <a href='mailto:info@conlabz.de'>Conlabz GmbH</a> for additional information."));
192
+ }
193
+ }
194
+
195
+ /*
196
+ * Get Group Information
197
+ */
198
+
199
+ public function groupGetStats($groupId = false) {
200
+
201
+ if (!$groupId) {
202
+ $groupId = $this->_helper->getDefaultListId();
203
+ }
204
+
205
+ $result = $this->_client->groupGetStats($this->_apiKey, $groupId);
206
+ if ($result->status == self::SUCCESS_STATUS) {
207
+ return $this->returnResult($result->data);
208
+ } else {
209
+
210
+ $this->_helper->log($this->_helper->__("CALL: groupGetStats - failed. List ID: ".$groupId));
211
+ $this->_helper->log($this->_helper->__($result->message));
212
+
213
+ if ($groupId){
214
+ return $this->returnResult($result->data, $this->_helper->__("Your list ID (%s) seem to be wrong. Please select other group!", $groupId));
215
+ }
216
+ return $this->returnResult($result->data, $this->_helper->__("Please set your CleverReach user group in Extension settings section."));
217
+ }
218
+ }
219
+
220
+ /*
221
+ * Get Group Information
222
+ */
223
+
224
+ public function groupGetDetails($listId = false) {
225
+
226
+ if (!$listId) {
227
+ $listId = $this->_helper->getDefaultListId();
228
+ }
229
+
230
+ $result = $this->_client->groupGetDetails($this->_apiKey, $listId);
231
+ if ($result->status == self::SUCCESS_STATUS) {
232
+
233
+ return $this->returnResult($result->data);
234
+ } else {
235
+
236
+ $this->_helper->log($this->_helper->__("CALL: groupGetDetails - failed. List ID: ".$listId));
237
+ $this->_helper->log($this->_helper->__($result->message));
238
+
239
+ if ($listId){
240
+ return $this->returnResult($result->data, $this->_helper->__("Your list ID (%s) seem to be wrong. Please select other group!", $listId));
241
+ }
242
+ return $this->returnResult($result->data, $this->_helper->__("Please set your CleverReach user group in Extension settings section."));
243
+
244
+ }
245
+ }
246
+
247
+ /*
248
+ * Add batch of users to CleverReach
249
+ *
250
+ * @param array - butch of users
251
+ * @param int - Magento Groups ID
252
+ *
253
+ * @return int amount of synced users
254
+ */
255
+
256
+ public function receiverAddBatch($batch, $groupId = 0) {
257
+
258
+ if ($groupId == 0) {
259
+ $listId = $this->_helper->getDefaultListId();
260
+ } else {
261
+ $listId = $this->_helper->getGroupsIds($groupId);
262
+ }
263
+
264
+ $this->_helper->log("CrConnect: receiverAddBatch.");
265
+ $this->_helper->log($batch);
266
+
267
+ $result = $this->_client->receiverAddBatch($this->_apiKey, $listId, $batch);
268
+ if ($result->status == self::SUCCESS_STATUS) {
269
+
270
+ $this->_helper->log("CrConnect: receiverAddBatch - SUCCESS.");
271
+ $this->_helper->log("CrConnect: receiverAddBatch - key:".$this->_apiKey." | listId:".$listId);
272
+
273
+ return count($batch);
274
+ } else {
275
+
276
+ $this->_helper->log("CrConnect: receiverAddBatch - FAIL.");
277
+ $this->_helper->log("CrConnect: receiverAddBatch - key:".$this->_apiKey." | listId:".$listId);
278
+ $this->_helper->log("CrConnect: receiverAddBatch - message:".$result->message);
279
+
280
+ return false;
281
+ }
282
+ }
283
+
284
+ public function receiverAddOrder($email, $orderInfo){
285
+
286
+ $listId = $this->_helper->getDefaultListId();
287
+ $result = $this->_client->receiverAddOrder($this->_apiKey, $listId, $email, $orderInfo);
288
+ Mage::helper("crconnect")->log("CALL receiverAddOrder: ".$email);
289
+ Mage::helper("crconnect")->log($result->message);
290
+ if ($result->status == self::SUCCESS_STATUS) {
291
+ return true;
292
+ } else {
293
+ return false;
294
+ }
295
+
296
+ }
297
+ /*
298
+ * Get and check if user subscribed to group
299
+ *
300
+ * @param string - user email
301
+ * @param int - group Id
302
+ *
303
+ * @return bool true|false
304
+ */
305
+
306
+ public function isSubscribed($email, $groupId = 0) {
307
+
308
+ if ($groupId == 0) {
309
+ $listId = $this->_helper->getDefaultListId();
310
+ } else {
311
+ $listId = $this->_helper->getGroupsIds($groupId);
312
+ }
313
+
314
+ $result = $this->_client->groupGetDetails($this->_apiKey, $listId);
315
+ if ($result->status == self::SUCCESS_STATUS) {
316
+
317
+ $result = $this->_client->receiverGetByEmail($this->_apiKey, $listId, $email);
318
+ if ($result->status == self::SUCCESS_STATUS && $result->data->active) {
319
+ return true;
320
+ }
321
+ }
322
+ return false;
323
+ }
324
+
325
+ /*
326
+ * get groups for API key
327
+ */
328
+ public function getGroupsForKey($apiKey){
329
+
330
+ $result = $this->_client->groupGetList($apiKey);
331
+ if ($result->status == self::SUCCESS_STATUS) {
332
+ return $result->data;
333
+ }else{
334
+ return false;
335
+ }
336
+
337
+ }
338
+
339
+ /*
340
+ * get groups for API key
341
+ */
342
+ public function getFormsForGroup($apiKey, $groupId){
343
+
344
+ $result = $this->_client->formsGetList($apiKey, $groupId);
345
+ if ($result->status == self::SUCCESS_STATUS) {
346
+ return $result->data;
347
+ }else{
348
+ return false;
349
+ }
350
+
351
+ }
352
+
353
+ public function formsSendActivationMail($customer, $groupId = 0){
354
+
355
+ if ($this->isConnected()){
356
+
357
+ // if not customer transfered, get current one from session
358
+ if (!$customer) {
359
+ $customer = Mage::getSingleton('customer/session')->getCustomer();
360
+ }
361
+ $crReceiver = $this->_helper->prepareUserdata($customer, array('newsletter' => 1), true);
362
+
363
+ // Subscriber customer first
364
+ $addResult = $this->receiverAdd($crReceiver, $groupId);
365
+
366
+ $doidata = array(
367
+ "user_ip" => $_SERVER['REMOTE_ADDR'],
368
+ "user_agent" => $_SERVER['HTTP_USER_AGENT'],
369
+ "referer" => Mage::getUrl("/"),
370
+ "postdata" => "",
371
+ "info" => "",
372
+ );
373
+
374
+ if ($addResult->status == self::SUCCESS_STATUS) {
375
+
376
+ // Send activation email for customer
377
+ $formId = $this->_helper->getFormsIds($groupId, true);
378
+ $result = $this->_client->formsSendActivationMail($this->_apiKey, $formId, $customer->getEmail(), $doidata);
379
+
380
+ if ($result->status == self::SUCCESS_STATUS) {
381
+ return true;
382
+ }
383
+
384
+ }else{
385
+
386
+ $this->_helper->log("during formsSendActivationMail :: receiverAdd :: ERROR");
387
+ $this->_helper->log($addResult);
388
+
389
+ if ($addResult->statuscode == self::ERROR_CODE_DUPLICATED){
390
+
391
+ if ($addResult->data->deactivated == 1){
392
+
393
+
394
+ // Send activation email for customer
395
+ $formId = $this->_helper->getFormsIds($groupId, true);
396
+ $result = $this->_client->formsSendActivationMail($this->_apiKey, $formId, $customer->getEmail(), $doidata);
397
+ if ($result->status == self::SUCCESS_STATUS) {
398
+ return true;
399
+ }else{
400
+
401
+ $this->_helper->log("during formsSendActivationMail :: formsSendActivationMail :: ERROR");
402
+ $this->_helper->log($result->message);
403
+
404
+ if ($result->statuscode == self::ERROR_CODE_INVALID){
405
+ Mage::getSingleton("core/session")->addError($this->_helper->__("This Email blocked or wrong"));
406
+ }
407
+ }
408
+
409
+ }else{
410
+
411
+ Mage::getSingleton("core/session")->addError($this->_helper->__("This Email already in our database"));
412
+
413
+ }
414
+
415
+ }
416
+
417
+ }
418
+ return false;
419
+
420
+ }
421
+
422
+ }
423
+
424
+
425
+ /*
426
+ * Sync data between Magento and Cleverreach
427
+ */
428
+
429
+ public function synchronize() {
430
+
431
+ //Check if we connected to Cr account
432
+ if (!$this->isConnected()) {
433
+ return false;
434
+ }
435
+
436
+ $this->_helper->log("RUN SYNCHRONIZATION");
437
+
438
+ $isTrackingEnabled = $this->_helper->isTrackingEnabled();
439
+ $subscribers = $this->_helper->getActiveMageSubscribers();
440
+
441
+ $syncedUsers = 0;
442
+ $batch = array();
443
+ $i = 0;
444
+
445
+ foreach ($subscribers as $subscriber) {
446
+
447
+ $userGroup = 0;
448
+
449
+ $tmp["email"] = "";
450
+
451
+ // If we should separate customers to different groups, then get customer Groups iD if exists
452
+ if ($this->_helper->isSeparationEnabled()) {
453
+ if ($subscriber["subscriber_email"]) {
454
+ // get customer by subscriber E-mail
455
+ $systemCustomer = Mage::getModel("customer/customer")->setWebsiteId($subscriber['website_id'])->loadByEmail($subscriber["subscriber_email"]);
456
+ if ($systemCustomer->getId()) {
457
+ $userGroup = $systemCustomer->getGroupId();
458
+ }
459
+ }
460
+ }
461
+ $tmp["email"] = $subscriber["subscriber_email"];
462
+ $tmp["source"] = "MAGENTO";
463
+
464
+
465
+ // Prepare customer attributes
466
+ $tmp["attributes"] = array(
467
+ 0 => array("key" => "firstname", "value" => @$subscriber["customer_firstname"]),
468
+ 1 => array("key" => "lastname", "value" => @$subscriber["customer_lastname"]),
469
+ 2 => array("key" => "newsletter", "value" => "1")
470
+ );
471
+
472
+ // Separate users by Batch, 25 users in one
473
+ if ($tmp["email"]) {
474
+ $batch[$subscriber["store_id"]][$userGroup][floor($i++ / 25)][] = $tmp; //max 25 per batch
475
+ }
476
+ }
477
+
478
+ try {
479
+
480
+ // send subscribers batch to CleverReach
481
+ if ($batch) {
482
+
483
+ foreach ($batch as $storeId => $groupBatch) {
484
+
485
+ $this->init($storeId);
486
+
487
+ // send for each group
488
+ foreach ($groupBatch as $groupId => $batchStore) {
489
+
490
+ foreach ($batchStore as $part) {
491
+
492
+ $this->_helper->log("SYNCHRONIZATION - receiverAddBatch");
493
+
494
+ $result = $this->receiverAddBatch($part, $groupId);
495
+ if ($result !== false) {
496
+ $this->_helper->log("FINISH SYNCHRONIZATION WITH EMPTY USERS");
497
+ $syncedUsers += $result;
498
+ } else {
499
+ return false;
500
+ }
501
+ }
502
+ }
503
+ }
504
+ }
505
+
506
+ $this->_helper->log("FINISH SYNCHRONIZATION WITH :".$syncedUsers);
507
+ return $syncedUsers;
508
+
509
+ } catch (Exception $e) {
510
+ $this->_helper->log("SYNCHRONIZATION Exception: ".$e->getMessage());
511
+ }
512
+
513
+ $this->_helper->log("FINISH SYNCHRONIZATION");
514
+
515
+ return $synced_users;
516
+ }
517
+
518
+ public function setupDefaultClereReachList(){
519
+
520
+ //Check if we connected to Cr account
521
+ if (!$this->isConnected()) {
522
+ return false;
523
+ }
524
+
525
+ $return = false;
526
+
527
+ try {
528
+
529
+ $return = $this->setupGroupFields($this->_helper->getDefaultListId());
530
+ $groups = $this->_helper->getGroupsIds();
531
+ foreach ($groups as $groupId){
532
+ $return = $this->setupGroupFields($groupId);
533
+ }
534
+
535
+
536
+ } catch(Exception $e) {
537
+
538
+ return false;
539
+
540
+ }
541
+ return $return;
542
+ }
543
+ public function setupGroupFields($listId){
544
+
545
+ $return = false;
546
+
547
+ $fields = array("firstname" => "firstname",
548
+ "lastname" => "lastname",
549
+ "street" => "street",
550
+ "zip" => "zip",
551
+ "city" => "city",
552
+ "country" => "country",
553
+ "salutation" => "salutation",
554
+ "title" => "title",
555
+ "company" => "company",
556
+ "newsletter" => "newsletter",
557
+ "group_id" => "group_id",
558
+ "group_name" => "group_name",
559
+ "gender" => "gender",
560
+ "store" => "store");
561
+
562
+ $return = $this->_client->groupGetDetails($this->_apiKey, $listId);
563
+ if($return->status == "SUCCESS"){
564
+
565
+ foreach($return->data->attributes as $a){
566
+ if(in_array($a->key, $fields)){
567
+ unset($fields[$a->key]);
568
+ }
569
+ }
570
+ foreach($fields as $field){
571
+ $return = $this->_client->groupAttributeAdd($this->_apiKey, $listId, $field, "text", "");
572
+ }
573
+ }
574
+ return $return;
575
+
576
+ }
577
+ }
app/code/community/Conlabz/CrConnect/Model/Checkout/Observer.php ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Conlabz GmbH
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com and you will be sent a copy immediately.
14
+ *
15
+ * @category CleverReach
16
+ * @package Conlabz_CrConnect
17
+ * @copyright Copyright (c) 2012 Conlabz GmbH (http://www.conlabz.de)
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+ class Conlabz_CrConnect_Model_Checkout_Observer
21
+ {
22
+ public function success_action($observer)
23
+ {
24
+ $event = $observer->getEvent();
25
+
26
+ $email = false;
27
+ $apiKey = trim(Mage::getStoreConfig('crroot/crconnect/api_key'));
28
+ $listID = trim(Mage::getStoreConfig('crroot/crconnect/list_id'));
29
+
30
+ $syncOrders = trim(Mage::getStoreConfig('crroot/crconnect/sync_orders'));
31
+ $syncOrderStatus = trim(Mage::getStoreConfig('crroot/crconnect/sync_order_status'));
32
+
33
+ if($syncOrders)
34
+ $lastOrderId = Mage::getSingleton('checkout/session')->getLastOrderId();
35
+ else{
36
+ $lastOrderId = false;
37
+ Mage::log("CleverReach_CrConnect: order sycing deactivated");
38
+ }
39
+ if ($lastOrderId){
40
+ $order = Mage::getModel('sales/order')->load($lastOrderId);
41
+ $customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
42
+
43
+ $subscribed = $customer->getIsSubscribed();
44
+
45
+ if($subscribed === NULL)
46
+ {
47
+ $subscribed = Mage::getModel('newsletter/subscriber')->loadByCustomer($customer)->isSubscribed();
48
+ }
49
+
50
+ if($subscribed){
51
+ $add = array("newsletter" => "1");
52
+ }else{
53
+ $add = array("newsletter" => "0");
54
+ }
55
+
56
+ $email = $order->getCustomerEmail();
57
+
58
+ if($email){
59
+ if($customer->getEmail()){
60
+ $crReceiver = Mage::helper('crconnect')->prepareUserdata($customer, $add, false);
61
+ }else{
62
+ $shippingAddress = $order->getBillingAddress()->getData();
63
+ if($shippingAddress){
64
+ $crReceiver = array (
65
+ 'email' => $email,
66
+ //'registered' => strtotime($shippingAddress["created_at"]),
67
+ //'activated' => strtotime($shippingAddress["updated_at"]),
68
+ 'source' => 'MAGENTO',
69
+ 'attributes' => array(0 => array("key" => "firstname", "value" => @$shippingAddress["firstname"]),
70
+ 1 => array("key" => "lastname", "value" => @$shippingAddress["lastname"]),
71
+ 2 => array("key" => "street", "value" => @$shippingAddress["street"]),
72
+ 3 => array("key" => "zip", "value" => @$shippingAddress["postcode"]),
73
+ 4 => array("key" => "city", "value" => @$shippingAddress["city"]),
74
+ 5 => array("key" => "country", "value" => @$shippingAddress["country_id"]),
75
+ 6 => array("key" => "salutation", "value" => @$shippingAddress["prefix"]),
76
+ 7 => array("key" => "title", "value" => @$shippingAddress["suffix"]),
77
+ 8 => array("key" => "company", "value" => @$shippingAddress["company"]))
78
+ );
79
+
80
+ $cookie = Mage::getSingleton('core/cookie');
81
+ if ($cookie->get('crmailing')){
82
+ $crReceiver['orders'][0]['mailings_id'] = $cookie->get('crmailing');
83
+ }
84
+
85
+ if($subscribed){
86
+ $crReceiver["attributes"][] = array("key" => 'newsletter', "value" => "1");
87
+ }
88
+ }
89
+ }
90
+ }
91
+
92
+ }
93
+
94
+ if($apiKey && $listID && $email && $lastOrderId && $syncOrders)
95
+ {
96
+
97
+ try {
98
+ $client = new SoapClient(Mage::helper('crconnect')->getWsdl(), array("trace" => true));
99
+ } catch(Exception $e) {
100
+ Mage::log("CleverReach_CrConnect: Error connecting to CleverReach server: ".$e->getMessage());
101
+ }
102
+
103
+ /* ########################### */
104
+ if($crReceiver)
105
+ {
106
+ try {
107
+ $tmp = $crReceiver;
108
+ $addTxt="keeping status";
109
+ //if new users should be activated by default. do it
110
+ if($syncOrderStatus){
111
+ $tmp["deactivated"] = 0;
112
+ $addTxt = "forced active";
113
+ }
114
+
115
+ // Get keys for different user groups
116
+ if (Mage::getStoreConfig('crroot/crconnect/showgroup') == '1'){
117
+ $groupKeys = Mage::helper('crconnect')->getKeys();
118
+ if ($groupId = $customer->getGroupId()){
119
+ if (isset($groupKeys[$groupId])){
120
+ $return = $client->receiverAdd($apiKey, $groupKeys[$groupId], $tmp);
121
+ }
122
+ }
123
+ }else{
124
+ $return = $client->receiverAdd($apiKey, $listID, $tmp);
125
+ }
126
+
127
+ if($return->status=="SUCCESS"){
128
+ Mage::log("CleverReach_CrConnect: subscribed ($addTxt) - ".$crReceiver["email"]);
129
+ }else{
130
+ if($return->statuscode=="50"){ //seems to exists allready, try update
131
+ $return = $client->receiverUpdate($apiKey, $listID, $tmp);
132
+ if(!$return->status=="SUCCESS"){
133
+ Mage::log("CleverReach_CrConnect: order insert error - ".$return->message);
134
+ }else{
135
+ Mage::log("CleverReach_CrConnect: resubscribed ($addTxt) - ".$crReceiver["email"]);
136
+ }
137
+ }else{
138
+ Mage::log("CleverReach_CrConnect: error - ".$return->message);
139
+ }
140
+ }
141
+ } catch(Exception $e) {
142
+ Mage::log("CleverReach_CrConnect: Error in SOAP call: ".$e->getMessage());
143
+ }
144
+ }
145
+
146
+ /* ########################### */
147
+
148
+ $items = $order->getAllItems();
149
+ if($items)foreach ($items as $item){
150
+
151
+ $tmpItem = array();
152
+ $tmpItem["order_id"] = $lastOrderId;
153
+ $tmpItem["product"] = $item->getName();
154
+ $tmpItem["product_id"] = $item->getProductId();
155
+ $tmpItem["price"] = round($item->getPrice(),2);
156
+ $tmpItem["quantity"] = (integer)$item->getQtyOrdered();
157
+ $tmpItem["purchase_date"] = time();
158
+ $tmpItem["currency"] = $order->getData('order_currency_code');
159
+ $tmpItem["source"] = "MAGENTO Order";
160
+
161
+ $cookie = Mage::getSingleton('core/cookie');
162
+ if ($cookie->get('crmailing')){
163
+ $tmpItem['mailings_id'] = $cookie->get('crmailing');
164
+ }
165
+
166
+ $tmp = $client->receiverAddOrder($apiKey, $listID, $email, $tmpItem);
167
+ if($tmp->status!="SUCCESS"){
168
+ Mage::log("CleverReach_CrConnect: Error - ".$tmp->message);
169
+ }else{
170
+ Mage::log("CleverReach_CrConnect: submitted: ".$tmpItem["order_id"]." - ".$tmpItem["product"]);
171
+ }
172
+ }
173
+ }
174
+ }
175
+ }
app/code/community/Conlabz/CrConnect/Model/Customer/Observer.php ADDED
@@ -0,0 +1,243 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Conlabz GmbH
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com and you will be sent a copy immediately.
14
+ *
15
+ * @category CleverReach
16
+ * @package Conlabz_CrConnect
17
+ * @copyright Copyright (c) 2012 Conlabz GmbH (http://conlabz.de)
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ class SubscriberCustomField
22
+ {
23
+ function SubscriberCustomField($k, $v)
24
+ {
25
+ $this->Key = $k;
26
+ $this->Value = $v;
27
+ }
28
+ }
29
+
30
+ class Conlabz_CrConnect_Model_Customer_Observer
31
+ {
32
+ public function session_init($observer)
33
+ {
34
+
35
+ $mailingId = Mage::getSingleton('core/app')->getRequest()->getParam('crmailing');
36
+ $cookie = Mage::getSingleton('core/cookie');
37
+ if ($mailingId){
38
+ $cookie->set('crmailing', $mailingId ,time()+3600*24*14,'/');
39
+ }
40
+ $customerId = Mage::getSingleton('core/app')->getRequest()->getParam('crcustomer');
41
+ $cookie = Mage::getSingleton('core/cookie');
42
+ if ($customerId){
43
+ $cookie->set('crcustomer', $customerId ,time()+3600*24*14,'/');
44
+ }
45
+
46
+ }
47
+
48
+ public function check_subscription_status($observer)
49
+ {
50
+
51
+ $event = $observer->getEvent();
52
+ $customer = $event->getCustomer();
53
+
54
+ $apiKey = trim(Mage::getStoreConfig('crroot/crconnect/api_key'));
55
+ $listID = trim(Mage::getStoreConfig('crroot/crconnect/list_id'));
56
+
57
+ $name = $customer->getFirstname() . " " . $customer->getLastname();
58
+ $newEmail = $customer->getEmail();
59
+ $subscribed = $customer->getIsSubscribed();
60
+
61
+ $groupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
62
+
63
+ $shippingAddress = false;
64
+ if($tmp = $customer->getDefaultBillingAddress())
65
+ $shippingAddress = $tmp->getData();
66
+
67
+
68
+ try {
69
+ $client = new SoapClient(Mage::helper('crconnect')->getWsdl(), array("trace" => true));
70
+ } catch(Exception $e) {
71
+ Mage::log("CleverReach_CrConnect: Error connecting to CleverReach server: ".$e->getMessage());
72
+ }
73
+
74
+ $keys = Mage::helper('crconnect')->getKeys();
75
+
76
+ $isCustomSubscribed = false;
77
+ if (isset($keys[$groupId])){
78
+ $isCustomSubscribed = Mage::helper('crconnect')->getSubscriber($newEmail, $groupId);
79
+ }
80
+
81
+ if ($isCustomSubscribed){
82
+ if (isset($_POST['is_gsubscribed']) && $_POST['is_gsubscribed'] == 1){
83
+
84
+ }else{
85
+ try {
86
+
87
+ $return = $client->receiverSetInactive($apiKey, $keys[$groupId], $newEmail);
88
+
89
+ } catch(Exception $e) {
90
+ Mage::log("CleverReach_CrConnect: Error in SOAP call: ".$e->getMessage());
91
+ return;
92
+ }
93
+ }
94
+ }else{
95
+
96
+ if (isset($_POST['is_gsubscribed']) && $_POST['is_gsubscribed'] == 1){
97
+
98
+ $crReceiver = Mage::helper('crconnect')->prepareUserdata($customer, array('newsletter'=>1), true);
99
+ $return = $client->receiverAdd($apiKey, $keys[$groupId], $crReceiver);
100
+ if ($return->status == "ERROR"){
101
+ if($return->statuscode=="50"){ //try update
102
+ $crReceiver["deactivated"] = 0;
103
+ $return = $client->receiverUpdate($apiKey, $keys[$groupId], $crReceiver);
104
+ Mage::log("CleverReach_CrConnect:". $crReceiver["attributes"][1]["key"]);
105
+ if(!$return->status=="SUCCESS"){
106
+ Mage::log("CleverReach_CrConnect: resubscribe error - ".$return->message);
107
+ }
108
+ }
109
+ }
110
+
111
+ }
112
+ }
113
+
114
+ $oldEmail = Mage::getModel('customer/customer')->load($customer->getId())->getEmail();
115
+
116
+ // if subscribed is NULL (i.e. because the form didn't set it one way
117
+ // or the other), get the existing value from the database
118
+
119
+ if($subscribed === NULL)
120
+ {
121
+ $subscribed = Mage::getModel('newsletter/subscriber')->loadByCustomer($customer)->isSubscribed();
122
+ }
123
+
124
+ if($apiKey and $listID)
125
+ {
126
+ if($subscribed)
127
+ {
128
+ $crReceiver = Mage::helper('crconnect')->prepareUserdata($customer, array('newsletter'=>1), true);
129
+ Mage::log("CleverReach_CrConnect: Subscribing new email address (ob): $newEmail");
130
+ try {
131
+
132
+ // Get keys for different user groups
133
+ if (Mage::getStoreConfig('crroot/crconnect/showgroup') == '1'){
134
+ $groupKeys = Mage::helper('crconnect')->getKeys();
135
+ if ($groupId = $customer->getGroupId()){
136
+ if (isset($groupKeys[$groupId])){
137
+ $return = $client->receiverSetInactive($apiKey, $listID, $crReceiver["email"]);
138
+ $listID = $groupKeys[$groupId];
139
+ }
140
+ }
141
+ }
142
+ $return = $client->receiverAdd($apiKey, $listID, $crReceiver);
143
+ if($return->status=="SUCCESS"){
144
+ Mage::log("CleverReach_CrConnect: subscribed - ".$crReceiver["email"]);
145
+ }else{
146
+ if($return->statuscode=="50"){ //try update
147
+ $crReceiver["deactivated"] = 0;
148
+ $return = $client->receiverUpdate($apiKey, $listID, $crReceiver);
149
+ Mage::log("CleverReach_CrConnect:". $crReceiver["attributes"][1]["key"]);
150
+ if(!$return->status=="SUCCESS"){
151
+ Mage::log("CleverReach_CrConnect: resubscribe error - ".$return->message);
152
+ }
153
+ }else{
154
+ Mage::log("CleverReach_CrConnect: error - ".$return->message);
155
+ }
156
+ }
157
+ } catch(Exception $e) {
158
+ Mage::log("CleverReach_CrConnect: Error in SOAP call: ".$e->getMessage());
159
+ }
160
+ }
161
+ elseif($oldEmail)
162
+ {
163
+
164
+ Mage::log("CleverReach_CrConnect: Unsubscribing: $oldEmail");
165
+ $crReceiver = Mage::helper('crconnect')->prepareUserdata($customer, array('newsletter'=>0), false);
166
+ try {
167
+ $return = $client->receiverSetInactive($apiKey, $listID, $crReceiver["email"]);
168
+ if($return->status=="SUCCESS"){
169
+ Mage::log("CleverReach_CrConnect: unsubscribed - ".$crReceiver["email"]);
170
+
171
+ if($return->status == "SUCCESS"){
172
+ Mage::log("CleverReach_CrConnect: updating newsletterflag");
173
+ $client->receiverUpdate($apiKey, $listID, $crReceiver);
174
+ }
175
+ }else{ //call failed
176
+ Mage::log("CleverReach_CrConnect: error - ".$return->message);
177
+ }
178
+ } catch(Exception $e) {
179
+ Mage::log("CleverReach_CrConnect: Error in SOAP call: ".$e->getMessage());
180
+ }
181
+ }
182
+ }
183
+ }
184
+
185
+ public function customer_deleted($observer)
186
+ {
187
+
188
+ $event = $observer->getEvent();
189
+ $customer = $event->getCustomer();
190
+
191
+ $apiKey = trim(Mage::getStoreConfig('newsletter/crconnect/api_key'));
192
+ $listID = trim(Mage::getStoreConfig('newsletter/crconnect/list_id'));
193
+
194
+ $email = $customer->getEmail();
195
+
196
+ $keys = Mage::helper('crconnect')->getKeys();
197
+
198
+ $isCustomSubscribed = false;
199
+ if (isset($keys[$customer->getGroupId()])){
200
+ $isCustomSubscribed = Mage::helper('crconnect')->getSubscriber($email, $customer->getGroupId());
201
+ }
202
+
203
+ if($apiKey and $listID)
204
+ {
205
+ try {
206
+ $client = new SoapClient(Mage::helper('crconnect')->getWsdl(), array("trace" => true));
207
+ } catch(Exception $e) {
208
+ Mage::log("CleverReach_CrConnect: Error connecting to server: ".$e->getMessage());
209
+ }
210
+
211
+ Mage::log("CleverReach_CrConnect: Customer deleted, unsubscribing: $email");
212
+ try {
213
+ $return = $client->receiverDelete($apiKey, $listID, $email);
214
+ if($return->status=="SUCCESS"){
215
+ Mage::log("CleverReach_CrConnect: deleted - ".$email);
216
+ }else{ //call failed
217
+ Mage::log("CleverReach_CrConnect: error - ".$return["message"]);
218
+ }
219
+
220
+ if ($isCustomSubscribed){
221
+ $return = $client->receiverDelete($apiKey, $keys[$groupId], $email);
222
+ if($return->status=="SUCCESS"){
223
+ Mage::log("CleverReach_CrConnect: deleted - ".$email);
224
+ }else{ //call failed
225
+ Mage::log("CleverReach_CrConnect: error - ".$return["message"]);
226
+ }
227
+ }
228
+
229
+ } catch(Exception $e) {
230
+ Mage::log("CleverReach_CrConnect: Error in SOAP call: ".$e->getMessage());
231
+ }
232
+ }
233
+ }
234
+
235
+
236
+ public function getIsSubscribed($observer){
237
+ Mage::log("CleverReach_CrConnect: stat");
238
+ //Mage_Customer_Block_Newsletter
239
+ }
240
+
241
+
242
+ }
243
+ ?>
app/code/community/Conlabz/CrConnect/Model/Newsletter/Subscriber.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Conlabz_CrConnect_Model_Newsletter_Subscriber extends Mage_Newsletter_Model_Subscriber {
4
+
5
+ /*
6
+ * Check If customer is subscribed
7
+ */
8
+ public function isSubscribed($groupId = 0) {
9
+
10
+ if (!$this->getEmail()){
11
+ $this->setEmail(Mage::getSingleton('customer/session')->getCustomer()->getEmail());
12
+ }
13
+ return Mage::getModel("crconnect/api")->isSubscribed($this->getEmail(), $groupId);
14
+ }
15
+
16
+ /**
17
+ * Subscribes by email
18
+ *
19
+ * @param string $email
20
+ * @throws Exception
21
+ * @return int
22
+ */
23
+ public function subscribe($email, $groupId = 0) {
24
+
25
+ if (Mage::helper("customer")->isLoggedIn()) {
26
+ $customerSession = Mage::getSingleton('customer/session');
27
+ $customer = $customerSession->getCustomer();
28
+ } else {
29
+ $customer = Mage::getModel("customer/customer")->setWebsiteId(Mage::app()->getWebsite()->getId())->loadByEmail($email);
30
+ $customer->setEmail($email);
31
+ }
32
+
33
+ if (!$this->isSubscribed($groupId)) {
34
+ if (Mage::helper("crconnect")->isDoubleOptInEnabled()) {
35
+ return Mage::getModel("crconnect/subscriber")->formsSendActivationMail($customer, $groupId);
36
+ } else {
37
+ return Mage::getModel("crconnect/subscriber")->subscribe($customer, $groupId);
38
+ }
39
+ } else {
40
+ return false;
41
+ }
42
+ }
43
+ public function sendConfirmationSuccessEmail()
44
+ {
45
+ if (!Mage::helper("crconnect")->isDoubleOptInEnabled()) {
46
+ parent::sendConfirmationSuccessEmail();
47
+ }
48
+ }
49
+
50
+ }
app/code/community/Conlabz/CrConnect/Model/Observer.php ADDED
@@ -0,0 +1,212 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Conlabz_CrConnect_Model_Observer{
3
+
4
+ // 14 days
5
+ const SESSION_LIFE = 1209600;
6
+
7
+ private $_allowedControllers = array("account");
8
+ private $_allowedActions = array("createpost");
9
+
10
+ public function customerSaveAfter($observer){
11
+
12
+ if (!Mage::registry('cr_aftersave_called')){
13
+ Mage::register('cr_aftersave_called', true);
14
+ }else{
15
+ return true;
16
+ }
17
+
18
+ $controller = Mage::app()->getRequest()->getControllerName();
19
+ $action = Mage::app()->getRequest()->getActionName();
20
+
21
+ $customer = $observer->getCustomer();
22
+
23
+ $email = $customer->getEmail();
24
+ $subscriber = Mage::getModel("newsletter/subscriber")->loadByEmail($email);
25
+ $subscriber->setEmail($email);
26
+ if (Mage::app()->getStore()->isAdmin()){
27
+ return true;
28
+ // $website = Mage::getModel('core/website')->load($customer->getWebsiteId())->getCode();
29
+ // Mage::getSingleton("adminhtml/session")->setCrCustomerWebsite($website);
30
+ }
31
+
32
+ $subscriptionCheckbox1 = Mage::app()->getRequest()->getParam('subscription');
33
+ $subscriptionCheckbox2 = Mage::app()->getRequest()->getParam('is_subscribed');
34
+
35
+ if ($subscriptionCheckbox1 !== null || $subscriptionCheckbox2 !== null){
36
+
37
+ if (!$subscriber->isSubscribed()) {
38
+ $status = Mage::getModel("newsletter/subscriber")->subscribe($email);
39
+ if (Mage::helper("crconnect")->isDoubleOptInEnabled()) {
40
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper("core")->__('Confirmation request has been sent.'));
41
+ } else {
42
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper("core")->__('Thank you for your subscription.'));
43
+ }
44
+ }
45
+
46
+ }else{
47
+
48
+ if (in_array($controller, $this->_allowedControllers) && in_array($action, $this->_allowedActions)){
49
+ if ($subscriber->isSubscribed()) {
50
+ $status = Mage::getModel("crconnect/subscriber")->unsubscribe($email);
51
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper("core")->__('The subscription has been removed.'));
52
+ }
53
+ }
54
+
55
+ }
56
+
57
+ $gsubscription = Mage::app()->getRequest()->getParam('gsubscription');
58
+ $groupId = $customer->getGroupId();
59
+
60
+ if ($gsubscription !== null){
61
+ if (!$subscriber->isSubscribed($groupId)) {
62
+ $status = Mage::getModel("newsletter/subscriber")->subscribe($email, $groupId);
63
+ if (Mage::helper("crconnect")->isDoubleOptInEnabled()) {
64
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper("core")->__('Confirmation request has been sent.'));
65
+ } else {
66
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper("core")->__('Thank you for your subscription.'));
67
+ }
68
+ }
69
+ }else{
70
+
71
+ if (in_array($controller, $this->_allowedControllers) && in_array($action, $this->_allowedActions)){
72
+ if ($subscriber->isSubscribed($groupId)) {
73
+ $status = Mage::getModel("crconnect/subscriber")->unsubscribe($email, $groupId);
74
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper("core")->__('The subscription has been removed.'));
75
+ }
76
+ }
77
+
78
+ }
79
+
80
+ // Mage::getSingleton("adminhtml/session")->unsCrCustomerWebsite();
81
+
82
+ return true;
83
+
84
+ }
85
+
86
+ public function trackingCodesSet($observer){
87
+
88
+ $mailingId = Mage::getSingleton('core/app')->getRequest()->getParam('crmailing');
89
+
90
+ $cookie = Mage::getSingleton('core/cookie');
91
+ if ($mailingId){
92
+ $cookie->set('crmailing', $mailingId ,time()+self::SESSION_LIFE,'/');
93
+ }
94
+
95
+ $customerId = Mage::getSingleton('core/app')->getRequest()->getParam('crcustomer');
96
+ $cookie = Mage::getSingleton('core/cookie');
97
+ if ($customerId){
98
+ $cookie->set('crcustomer', $customerId ,time()+self::SESSION_LIFE,'/');
99
+ }
100
+
101
+ }
102
+ public function checkoutSuccess($observer){
103
+
104
+ $event = $observer->getEvent();
105
+
106
+ $apiKey = trim(Mage::getStoreConfig('crroot/crconnect/api_key'));
107
+ $listID = trim(Mage::getStoreConfig('crroot/crconnect/list_id'));
108
+
109
+ if(Mage::helper("crconnect")->isTrackingEnabled())
110
+ $lastOrderId = Mage::getSingleton('checkout/session')->getLastOrderId();
111
+ else{
112
+ $lastOrderId = false;
113
+ Mage::helper("crconnect")->log("CleverReach_CrConnect: order sycing deactivated");
114
+ }
115
+
116
+ $order = Mage::getModel('sales/order')->load($lastOrderId);
117
+ $customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
118
+ $email = $order->getCustomerEmail();
119
+
120
+ if(Mage::helper("crconnect")->isTrackingEnabled()){
121
+
122
+ $items = $order->getAllItems();
123
+ if ($items){
124
+ foreach ($items as $item){
125
+
126
+ $tmpItem = array();
127
+ $tmpItem["order_id"] = $lastOrderId;
128
+ $tmpItem["product"] = $item->getName();
129
+ $tmpItem["product_id"] = $item->getProductId();
130
+ $tmpItem["price"] = round($item->getPrice(),2);
131
+ $tmpItem["quantity"] = (integer)$item->getQtyOrdered();
132
+ $tmpItem["purchase_date"] = time();
133
+ $tmpItem["currency"] = $order->getData('order_currency_code');
134
+ $tmpItem["source"] = "MAGENTO Order";
135
+
136
+ $cookie = Mage::getSingleton('core/cookie');
137
+ if ($cookie->get('crmailing')){
138
+ $tmpItem['mailings_id'] = $cookie->get('crmailing');
139
+ }
140
+
141
+ Mage::getModel("crconnect/api")->receiverAddOrder($email, $tmpItem);
142
+
143
+ }
144
+ }
145
+
146
+ }
147
+ }
148
+
149
+ public function customerDeleted($observer){
150
+
151
+ $event = $observer->getEvent();
152
+ $customer = $event->getCustomer();
153
+ $email = $customer->getEmail();
154
+ $groupId = $customer->getGroupId();
155
+
156
+ Mage::getModel("crconnect/subscriber")->unsubscribe($email);
157
+ Mage::getModel("crconnect/subscriber")->unsubscribe($email, $groupId);
158
+
159
+ }
160
+ public function configSave(){
161
+
162
+ $postValues = Mage::app()->getRequest()->getPost();
163
+ if (Mage::app()->getRequest()->getParam('section') == "newsletter" || Mage::app()->getRequest()->getParam('section') == "crroot"){
164
+
165
+ $store = Mage::app()->getRequest()->getParam('store');
166
+
167
+ if (Mage::helper("crconnect")->isDoubleOptInEnabled()){
168
+
169
+ $groupsIds = Mage::helper("crconnect")->getGroupsIds();
170
+ $formsIds = Mage::helper("crconnect")->getFormsIds();
171
+
172
+ $allow = true;
173
+ foreach ($groupsIds as $groupsId){
174
+ if (!$groupsId){
175
+ $allow = false;
176
+ }
177
+ }
178
+
179
+ foreach ($formsIds as $formsId){
180
+ if (!$formsId){
181
+ $allow = false;
182
+ }
183
+ }
184
+
185
+ $formId = Mage::helper("crconnect")->getDefaultFormId();
186
+ if (!$formId){
187
+ $allow = false;
188
+ }
189
+
190
+ if (!$allow){
191
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('catalog')->__('Double Opt-In enabled, please select Form(s) and Group(s) for your Customer Groups'));
192
+ }
193
+
194
+ }
195
+
196
+ }
197
+
198
+ }
199
+ public function initCleverReach(){
200
+
201
+ $session = Mage::getSingleton('adminhtml/session');
202
+
203
+ $setupResult = Mage::getModel('crconnect/api')->setupDefaultClereReachList();
204
+ if(!$setupResult){
205
+ $session->addError("Could not connect to CleverReach. Please chech your API keys.");
206
+ }else if($setupResult->status=="ERROR" && $setupResult->statuscode!=50){
207
+ $session->addError("Cleverreach connection Error: ".$data->message);
208
+ }
209
+
210
+
211
+ }
212
+ }
app/code/community/Conlabz/CrConnect/Model/Search.php ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Conlabz_CrConnect_Model_Search {
4
+ /*
5
+ * Get Search Filters values
6
+ */
7
+
8
+ public function getFilter() {
9
+
10
+ $filter = array();
11
+
12
+ // Generate Categories Filter
13
+
14
+ $filter[0] = array();
15
+ $categoryFilter = array();
16
+ $categoryFilter['name'] = Mage::helper("crconnect")->__("Category");
17
+ $categoryFilter['required'] = false;
18
+ $categoryFilter['query_key'] = "category";
19
+ $categoryFilter['type'] = "dropdown";
20
+
21
+ $rootcatId = Mage::app()->getStore()->getRootCategoryId();
22
+ $categories = Mage::getModel('catalog/category')->getCategories($rootcatId);
23
+
24
+
25
+ $categoriesTree = $this->getCategories($categories);
26
+ $categoryFilter['values'] = array_merge(array(array("text" => "", "value" => "")), $categoriesTree);
27
+
28
+ $filter[0] = $categoryFilter;
29
+
30
+ $filter[1] = array();
31
+ $productFilter = array();
32
+ $productFilter['name'] = Mage::helper("crconnect")->__("Product");
33
+ $productFilter['required'] = false;
34
+ $productFilter['query_key'] = "product";
35
+ $productFilter['type'] = "input";
36
+
37
+ $filter[1] = $productFilter;
38
+
39
+ return $filter;
40
+ }
41
+
42
+ /*
43
+ * Get categories tree recurcively function
44
+ *
45
+ * @return array of categories of one level
46
+ */
47
+
48
+ public function getCategories($categories) {
49
+
50
+ foreach ($categories as $category) {
51
+ $cat = Mage::getModel('catalog/category')->load($category->getId());
52
+ $prefix = "";
53
+ for ($i = 0; $i < $category->getLevel() - 2; $i++) {
54
+ $prefix .= "&nbsp;";
55
+ }
56
+ $array[] = array("text" => $prefix . $category->getName(), "value" => $category->getId()); //In this line we get an a link for the product and product count of that category
57
+ if ($category->hasChildren()) {
58
+ $children = Mage::getModel('catalog/category')->getCategories($category->getId()); // $children get a list of all subcategories
59
+ $array = array_merge($array, $this->getCategories($children)); //recursive call the get_categories function again.
60
+ }
61
+ }
62
+ return $array;
63
+ }
64
+
65
+ /*
66
+ * Get Search result
67
+ *
68
+ * @param int category - category ID
69
+ * @param string product - part of name or description
70
+ *
71
+ */
72
+
73
+ public function getSearch($category = false, $product = "", $store = false) {
74
+
75
+ $products = Mage::getModel('catalog/product')->getCollection()
76
+ ->addAttributeToSelect("name")
77
+ ->addAttributeToSelect("description")
78
+ ->addAttributeToSelect("image")
79
+ ->addAttributeToSelect("price");
80
+
81
+ if ($store) {
82
+ $products->setStoreId($store);
83
+ }
84
+
85
+ if ($category) {
86
+ $category = Mage::getModel("catalog/category")->load($category);
87
+ $products->addCategoryFilter($category);
88
+ }
89
+ if ($product) {
90
+ $products->addFieldToFilter("name", array("like" => "%{$product}%"));
91
+ }
92
+
93
+ $search = array();
94
+ $search['settings']['type'] = "product";
95
+ $search['settings']['link_editable'] = true;
96
+ $search['settings']['link_text_editable'] = true;
97
+ $search['settings']['image_size_editable'] = true;
98
+
99
+ $items = array();
100
+ if ($category || $product) {
101
+ foreach ($products as $product) {
102
+
103
+ $item = array();
104
+ $item['title'] = $product->getName();
105
+ $item['description'] = $product->getDescription();
106
+ $item['image'] = $product->getImageUrl();
107
+ $item['url'] = $product->getProductUrl();
108
+ $item['price'] = Mage::helper('core')->formatPrice($product->getPrice());
109
+
110
+ $items[] = $item;
111
+ }
112
+ }
113
+
114
+ $search['items'] = $items;
115
+ return $search;
116
+ }
117
+
118
+ }
app/code/community/Conlabz/CrConnect/Model/Subscriber.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Conlabz_CrConnect_Model_Subscriber extends Mage_Core_Model_Abstract {
4
+
5
+ /*
6
+ * Subscribe cusotmer
7
+ */
8
+ public function subscribe($customer = false, $groupId = 0) {
9
+
10
+ return Mage::getModel("crconnect/api")->subscribe($customer, $groupId);
11
+
12
+ }
13
+
14
+ /*
15
+ * Send activation email for customer
16
+ */
17
+ public function formsSendActivationMail($customer = false, $groupId = 0) {
18
+
19
+ return Mage::getModel("crconnect/api")->formsSendActivationMail($customer, $groupId);
20
+
21
+ }
22
+
23
+ /*
24
+ * Subscribe cusotmer
25
+ */
26
+ public function unsubscribe($email = false, $groupId = 0) {
27
+
28
+ return Mage::getModel("crconnect/api")->unsubscribe($email, $groupId);
29
+
30
+ }
31
+
32
+ }
app/code/community/Conlabz/CrConnect/Model/System/Config/Source/EmptyForms.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Conlabz_CrConnect_Model_System_Config_Source_EmptyForms
3
+ {
4
+
5
+ /**
6
+ * Options getter
7
+ *
8
+ * @return array
9
+ */
10
+ public function toOptionArray()
11
+ {
12
+ return array(
13
+ array('value' => '', 'label'=>Mage::helper('crconnect')->__('No forms to select')),
14
+ );
15
+ }
16
+
17
+ /**
18
+ * Get options in "key-value" format
19
+ *
20
+ * @return array
21
+ */
22
+ // public function toArray()
23
+ // {
24
+ // return array(
25
+ // 0 => Mage::helper('adminhtml')->__('No'),
26
+ // 1 => Mage::helper('adminhtml')->__('Yes'),
27
+ // );
28
+ // }
29
+
30
+ }
app/code/community/Conlabz/CrConnect/Model/System/Config/Source/EmptyList.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Conlabz_CrConnect_Model_System_Config_Source_EmptyList
3
+ {
4
+
5
+ /**
6
+ * Options getter
7
+ *
8
+ * @return array
9
+ */
10
+ public function toOptionArray()
11
+ {
12
+ return array(
13
+ array('value' => '', 'label'=>Mage::helper('crconnect')->__('No groups to select')),
14
+ );
15
+ }
16
+
17
+ /**
18
+ * Get options in "key-value" format
19
+ *
20
+ * @return array
21
+ */
22
+ // public function toArray()
23
+ // {
24
+ // return array(
25
+ // 0 => Mage::helper('adminhtml')->__('No'),
26
+ // 1 => Mage::helper('adminhtml')->__('Yes'),
27
+ // );
28
+ // }
29
+
30
+ }
app/code/community/Conlabz/CrConnect/Model/Website/Observer.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Conlabz GmbH
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com and you will be sent a copy immediately.
14
+ *
15
+ * @category CleverReach
16
+ * @package Conlanz_CrConnect
17
+ * @copyright Copyright (c) 2012 Conlabz GmbH (http://conlabz.de)
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+
22
+ class Conlabz_CrConnect_Model_Website_Observer
23
+ {
24
+ public function trackingCodeCheck(){
25
+ $mailingId = Mage::getSingleton('core/app')->getRequest()->getParam('crmailing');
26
+ $cookie = Mage::getSingleton('core/cookie');
27
+ if ($mailingId){
28
+ $cookie->set('crmailing', $mailingId ,time()+3600*24*14,'/');
29
+ }
30
+ }
31
+ }
app/code/community/Conlabz/CrConnect/controllers/AccountController.php ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ include "Mage/Customer/controllers/AccountController.php";
3
+
4
+ class Conlabz_CrConnect_AccountController extends Mage_Customer_AccountController
5
+ {
6
+
7
+ /**
8
+ * Create customer account action
9
+ */
10
+ public function createPostAction()
11
+ {
12
+ $session = $this->_getSession();
13
+ if ($session->isLoggedIn()) {
14
+ $this->_redirect('*/*/');
15
+ return;
16
+ }
17
+ $session->setEscapeMessages(true); // prevent XSS injection in user input
18
+ if ($this->getRequest()->isPost()) {
19
+ $errors = array();
20
+
21
+ if (!$customer = Mage::registry('current_customer')) {
22
+ $customer = Mage::getModel('customer/customer')->setId(null);
23
+ }
24
+
25
+ /* @var $customerForm Mage_Customer_Model_Form */
26
+ $customerForm = Mage::getModel('customer/form');
27
+ $customerForm->setFormCode('customer_account_create')
28
+ ->setEntity($customer);
29
+
30
+ $customerData = $customerForm->extractData($this->getRequest());
31
+
32
+ if (Mage::getStoreConfig("newsletter/subscription/confirm_logged_email_template") == 1){
33
+
34
+ $status = Mage::getModel("newsletter/subscriber")->subscribe($this->getRequest()->getPost('email'));
35
+ if ($status == Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE) {
36
+ Mage::getSingleton('customer/session')->addSuccess($this->__('Confirmation request has been sent.'));
37
+ }
38
+ else {
39
+ Mage::getSingleton('customer/session')->addSuccess($this->__('Thank you for your subscription.'));
40
+ }
41
+
42
+ }else{
43
+
44
+
45
+ if ($this->getRequest()->getParam('is_subscribed', false)) {
46
+ $customer->setIsSubscribed(1);
47
+ }
48
+
49
+ }
50
+ /**
51
+ * Initialize customer group id
52
+ */
53
+ $customer->getGroupId();
54
+
55
+ if ($this->getRequest()->getPost('create_address')) {
56
+ /* @var $address Mage_Customer_Model_Address */
57
+ $address = Mage::getModel('customer/address');
58
+ /* @var $addressForm Mage_Customer_Model_Form */
59
+ $addressForm = Mage::getModel('customer/form');
60
+ $addressForm->setFormCode('customer_register_address')
61
+ ->setEntity($address);
62
+
63
+ $addressData = $addressForm->extractData($this->getRequest(), 'address', false);
64
+ $addressErrors = $addressForm->validateData($addressData);
65
+ if ($addressErrors === true) {
66
+ $address->setId(null)
67
+ ->setIsDefaultBilling($this->getRequest()->getParam('default_billing', false))
68
+ ->setIsDefaultShipping($this->getRequest()->getParam('default_shipping', false));
69
+ $addressForm->compactData($addressData);
70
+ $customer->addAddress($address);
71
+
72
+ $addressErrors = $address->validate();
73
+ if (is_array($addressErrors)) {
74
+ $errors = array_merge($errors, $addressErrors);
75
+ }
76
+ } else {
77
+ $errors = array_merge($errors, $addressErrors);
78
+ }
79
+ }
80
+
81
+ try {
82
+ $customerErrors = $customerForm->validateData($customerData);
83
+ if ($customerErrors !== true) {
84
+ $errors = array_merge($customerErrors, $errors);
85
+ } else {
86
+ $customerForm->compactData($customerData);
87
+ $customer->setPassword($this->getRequest()->getPost('password'));
88
+ $customer->setConfirmation($this->getRequest()->getPost('confirmation'));
89
+ $customerErrors = $customer->validate();
90
+ if (is_array($customerErrors)) {
91
+ $errors = array_merge($customerErrors, $errors);
92
+ }
93
+ }
94
+
95
+ $validationResult = count($errors) == 0;
96
+
97
+ if (true === $validationResult) {
98
+ $customer->save();
99
+
100
+ Mage::dispatchEvent('customer_register_success',
101
+ array('account_controller' => $this, 'customer' => $customer)
102
+ );
103
+
104
+ if ($customer->isConfirmationRequired()) {
105
+ $customer->sendNewAccountEmail(
106
+ 'confirmation',
107
+ $session->getBeforeAuthUrl(),
108
+ Mage::app()->getStore()->getId()
109
+ );
110
+ $session->addSuccess($this->__('Account confirmation is required. Please, check your email for the confirmation link. To resend the confirmation email please <a href="%s">click here</a>.', Mage::helper('customer')->getEmailConfirmationUrl($customer->getEmail())));
111
+ $this->_redirectSuccess(Mage::getUrl('*/*/index', array('_secure'=>true)));
112
+ return;
113
+ } else {
114
+ $session->setCustomerAsLoggedIn($customer);
115
+ $url = $this->_welcomeCustomer($customer);
116
+ $this->_redirectSuccess($url);
117
+ return;
118
+ }
119
+ } else {
120
+ $session->setCustomerFormData($this->getRequest()->getPost());
121
+ if (is_array($errors)) {
122
+ foreach ($errors as $errorMessage) {
123
+ $session->addError($errorMessage);
124
+ }
125
+ } else {
126
+ $session->addError($this->__('Invalid customer data'));
127
+ }
128
+ }
129
+ } catch (Mage_Core_Exception $e) {
130
+ $session->setCustomerFormData($this->getRequest()->getPost());
131
+ if ($e->getCode() === Mage_Customer_Model_Customer::EXCEPTION_EMAIL_EXISTS) {
132
+ $url = Mage::getUrl('customer/account/forgotpassword');
133
+ $message = $this->__('There is already an account with this email address. If you are sure that it is your email address, <a href="%s">click here</a> to get your password and access your account.', $url);
134
+ $session->setEscapeMessages(false);
135
+ } else {
136
+ $message = $e->getMessage();
137
+ }
138
+ $session->addError($message);
139
+ } catch (Exception $e) {
140
+ $session->setCustomerFormData($this->getRequest()->getPost())
141
+ ->addException($e, $this->__('Cannot save the customer.'));
142
+ }
143
+ }
144
+
145
+ $this->_redirectError(Mage::getUrl('*/*/create', array('_secure' => true)));
146
+ }
147
+
148
+
149
+ }
app/code/community/Conlabz/CrConnect/controllers/Adminhtml/ConfigController.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Conlabz_Crconnect_Adminhtml_ConfigController extends Mage_Adminhtml_Controller_Action {
3
+
4
+
5
+ const EMPTY_CODE = "empty";
6
+
7
+ public function confirmKeyAction(){
8
+
9
+ $apiKey = $this->getRequest()->getParam("key");
10
+ //Mage::helper("crconnect")->setApiKey($apiKey);
11
+
12
+ $api = Mage::getModel("crconnect/api");
13
+ if ($api->isConnected()){
14
+ $groups = $api->getGroupsForKey($apiKey);
15
+ if ($groups){
16
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($groups));
17
+ }else{
18
+ $this->getResponse()->setBody(self::EMPTY_CODE);
19
+ }
20
+ }
21
+
22
+ }
23
+
24
+ public function changeGroupAction(){
25
+
26
+ $groupId = $this->getRequest()->getParam("group");
27
+ $apiKey = $this->getRequest()->getParam("key");
28
+
29
+ $api = Mage::getModel("crconnect/api");
30
+ if ($api->isConnected()){
31
+ $forms = $api->getFormsForGroup($apiKey, $groupId);
32
+ if ($forms){
33
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($forms));
34
+ }else{
35
+ $this->getResponse()->setBody(self::EMPTY_CODE);
36
+ }
37
+ }
38
+
39
+ }
40
+
41
+ public function getGroupsBlockAction(){
42
+
43
+ echo Mage::app()->getLayout()->createBlock('crconnect/config_groupsapis')->toHtml();
44
+
45
+ }
46
+ protected function _isAllowed(){
47
+
48
+ return true;
49
+
50
+ }
51
+
52
+ }
app/code/community/Conlabz/CrConnect/controllers/Adminhtml/CrconnectController.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Conlabz_Crconnect_Adminhtml_CrconnectController extends Mage_Adminhtml_Controller_Action {
3
+
4
+ /*
5
+ * Accounts list action
6
+ */
7
+ public function synchronizeAction() {
8
+
9
+
10
+ $syncedUsers = Mage::getModel("crconnect/api")->synchronize();
11
+ $result = array();
12
+
13
+ if ($syncedUsers !== false){
14
+ $result['error'] = false;
15
+ $result['message'] = Mage::helper('crconnect')->__("Synchronization successfull. %s users were transmitted.", $syncedUsers);
16
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__("Synchronization successfull. %s users were transmitted.", $syncedUsers));
17
+ }else{
18
+ $result['error'] = true;
19
+ $result['message'] = Mage::helper('crconnect')->__("Error occured while synchronization process. Please try again later.");
20
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__("Error occured while synchronization process. Please try again later."));
21
+ }
22
+
23
+ $this->getResponse()->setBody(json_encode($result));
24
+
25
+ }
26
+
27
+ protected function _isAllowed(){
28
+
29
+ return true;
30
+
31
+ }
32
+
33
+ }
app/code/community/Conlabz/CrConnect/controllers/HookController.php ADDED
@@ -0,0 +1,176 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Conlabz GmbH
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com and you will be sent a copy immediately.
14
+ *
15
+ * @category CleverReach
16
+ * @package Conlabz_CrConnect
17
+ * @copyright Copyright (c) 2012 Conlabz GmbH (http://www.cleverreach.com)
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ include "Mage/Newsletter/controllers/SubscriberController.php";
22
+
23
+ // Class that 'hooks' newsletter subscriptions from the frontend sign-up box.
24
+ // This is necessary because the Mage_Newsletter_Model_Subscriber class
25
+ // doesn't extend Mage_Core_Model_Abstract and so can't be observed directly.
26
+ // Instead we redirect all requests for newsletter/subscriber to this
27
+ // controller, which extends Mage_Newsletter_SubscriberController and
28
+ // overrides the newAction method.
29
+ class Conlabz_CrConnect_HookController extends Mage_Newsletter_SubscriberController {
30
+
31
+ public function confirmAction()
32
+ {
33
+ $id = (int) $this->getRequest()->getParam('id');
34
+ $code = (string) $this->getRequest()->getParam('code');
35
+
36
+ if ($id && $code) {
37
+ $subscriber = Mage::getModel('newsletter/subscriber')->load($id);
38
+ $session = Mage::getSingleton('core/session');
39
+
40
+ if($subscriber->getId() && $subscriber->getCode()) {
41
+ if($subscriber->confirm($code)) {
42
+
43
+ Mage::log("Cleverreach_CrConnect: newsletter signup for ".$subscriber->getEmail().", confirmation");
44
+
45
+ $apiKey = trim(Mage::getStoreConfig('crroot/crconnect/api_key'));
46
+ $listID = trim(Mage::getStoreConfig('crroot/crconnect/list_id'));
47
+ $confirm = trim(Mage::getStoreConfig('newsletter/subscription/confirm'));
48
+
49
+
50
+
51
+ $customer = Mage::getModel('customer/customer')->setWebsiteId(Mage::app()->getStore()->getWebsiteId())->loadByEmail($subscriber->getEmail());
52
+
53
+ if ($customer->getId()){
54
+
55
+ if (Mage::getStoreConfig('crroot/crconnect/showgroup') == '1'){
56
+ $groupKeys = Mage::helper('crconnect')->getKeys();
57
+ if ($groupId = $customer->getGroupId()){
58
+ if (isset($groupKeys[$groupId])){
59
+ $listID = $groupKeys[$groupId];
60
+ }
61
+ }
62
+ }
63
+
64
+ }
65
+
66
+ try {
67
+ $client = new SoapClient(Mage::helper('crconnect')->getWsdl(),
68
+ array("trace" => true));
69
+ } catch(Exception $e) {
70
+ Mage::log("CleverReach_CrConnect: Error connecting to server: ".$e->getMessage());
71
+ $session->addException($e, $this->__('There was a problem with the subscription'));
72
+ $this->_redirectReferer();
73
+ }
74
+
75
+ try {
76
+ $result = $client->receiverAdd($apiKey, $listID, array(
77
+ "email" => $subscriber->getEmail(),
78
+ "source" => "MAGENTO (frontend)",
79
+ "attributes" => array("key" => "newsletter", "value" => "1"),
80
+ )
81
+ );
82
+
83
+ if($result->status!="SUCCESS" && $result->statuscode == "50"){
84
+
85
+ $result = $client->receiverUpdate($apiKey, $listID, array(
86
+ "email" => $subscriber->getEmail(),
87
+ "source" => "MAGENTO (frontend)",
88
+ "attributes" => array("key" => "newsletter", "value" => "1"),
89
+ "deactivated"=>0
90
+ ));
91
+
92
+ }
93
+
94
+ } catch (Exception $e) {
95
+ Mage::log("CleverReach_CrConnect: Error in SOAP call: ".$e->getMessage());
96
+ $session->addException($e, $this->__('Subscription was invalid'));
97
+ $this->_redirectReferer();
98
+ }
99
+
100
+ parent::confirmAction();
101
+ } else {
102
+ $session->addError($this->__('Invalid subscription confirmation code'));
103
+ }
104
+ } else {
105
+ $session->addError($this->__('Invalid subscription ID'));
106
+ }
107
+ }
108
+
109
+ $this->_redirectUrl(Mage::getBaseUrl());
110
+ }
111
+
112
+
113
+ public function newAction() {
114
+
115
+ if ($this->getRequest()->isPost() && $this->getRequest()->getPost('email')) {
116
+ $session = Mage::getSingleton('core/session');
117
+ $customerSession = Mage::getSingleton('customer/session');
118
+ $email = (string) $this->getRequest()->getPost('email');
119
+
120
+ $apiKey = trim(Mage::getStoreConfig('crroot/crconnect/api_key'));
121
+ $listID = trim(Mage::getStoreConfig('crroot/crconnect/list_id'));
122
+ $confirm = trim(Mage::getStoreConfig('newsletter/subscription/confirm'));
123
+
124
+ if($apiKey && $listID && !$confirm) {
125
+ Mage::log("Cleverreach_CrConnect: newsletter signup for $email, no confirmation");
126
+
127
+ try {
128
+ $client = new SoapClient(Mage::helper('crconnect')->getWsdl(), array("trace" => true));
129
+ } catch(Exception $e) {
130
+ Mage::log("CleverReach_CrConnect: Error connecting to server: ".$e->getMessage());
131
+ $session->addException($e, $this->__('There was a problem with the subscription'));
132
+ $this->_redirectReferer();
133
+ }
134
+
135
+
136
+ $customerHelper = Mage::helper('customer');
137
+ {
138
+ // otherwise if nobody's logged in, ignore the custom
139
+ // attributes and just set the name to '(Guest)'
140
+ try {
141
+ /* echo "<pre>"; */
142
+ /* $result = $client->receiverGetByEmail($apiKey, $listID, 'alex.nuzil@conlabz.de', 1); */
143
+ /* var_dump($result); */
144
+ /* exit; */
145
+
146
+ if (Mage::getStoreConfig('crroot/crconnect/showgroup') == '1'){
147
+ $groupKeys = Mage::helper('crconnect')->getKeys();
148
+ if ($groupId = $customerSession->getCustomerGroupId()){
149
+ if (isset($groupKeys[$groupId])){
150
+ $return = $listID = $groupKeys[$groupId];
151
+ }
152
+ }
153
+ }
154
+
155
+ $result = $client->receiverAdd($apiKey, $listID, array(
156
+ "email" => $email,
157
+ "source" => "MAGENTO (frontend)",
158
+ "attributes" => array('0'=>array('key'=>'store', 'value'=>Mage::app()->getStore()->getCode(), 'variable'=>'{STORE}'),"newsletter"=>"1"),
159
+ )
160
+ );
161
+ } catch (Exception $e) {
162
+ Mage::log("CleverReach_CrConnect: Error in SOAP call: ".$e->getMessage());
163
+ $session->addException($e, $this->__('There was a problem with the subscription'));
164
+ $this->_redirectReferer();
165
+ }
166
+ }
167
+ } else if($apiKey && $listID && $confirm){
168
+ Mage::log("Cleverreach_CrConnect: skiping $email, waiting for confirmation");
169
+ }else{
170
+ Mage::log("Cleverreach_CrConnect: error: API key and/or ListID missing");
171
+ }
172
+ }
173
+
174
+ parent::newAction();
175
+ }
176
+ }
app/code/community/Conlabz/CrConnect/controllers/ManageController.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ include "Mage/Newsletter/controllers/ManageController.php";
4
+
5
+ class Conlabz_CrConnect_ManageController extends Mage_Newsletter_ManageController {
6
+
7
+ public function saveAction() {
8
+
9
+ if (!$this->_validateFormKey()) {
10
+ return $this->_redirect('customer/account/');
11
+ }
12
+ try {
13
+
14
+ $email = Mage::getSingleton('customer/session')->getCustomer()->getEmail();
15
+ $subscriber = Mage::getModel("newsletter/subscriber")->loadByEmail($email);
16
+ $subscriber->setEmail(Mage::getSingleton('customer/session')->getCustomer()->getEmail());
17
+
18
+ if ((boolean) $this->getRequest()->getParam('is_subscribed', false)) {
19
+ if (!$subscriber->isSubscribed()) {
20
+
21
+ $status = Mage::getModel("newsletter/subscriber")->subscribe($email);
22
+ if (Mage::helper("crconnect")->isDoubleOptInEnabled()) {
23
+ Mage::getSingleton('customer/session')->addSuccess($this->__('Confirmation request has been sent.'));
24
+ } else {
25
+ Mage::getSingleton('customer/session')->addSuccess($this->__('Thank you for your subscription.'));
26
+ }
27
+
28
+ }
29
+ } else {
30
+ if ($subscriber->isSubscribed()) {
31
+ $status = Mage::getModel("crconnect/subscriber")->unsubscribe($email);
32
+ Mage::getSingleton('customer/session')->addSuccess($this->__('The subscription has been removed.'));
33
+ }
34
+ }
35
+
36
+ $groupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
37
+ if ($groupId > 1) {
38
+ if ((boolean) $this->getRequest()->getParam('is_gsubscribed', false)) {
39
+
40
+ if (!$subscriber->isSubscribed($groupId)) {
41
+
42
+ $status = Mage::getModel("newsletter/subscriber")->subscribe(Mage::getSingleton('customer/session')->getCustomer()->getEmail(), $groupId);
43
+ if (Mage::helper("crconnect")->isDoubleOptInEnabled()) {
44
+ Mage::getSingleton('customer/session')->addSuccess($this->__('Confirmation request has been sent.'));
45
+ } else {
46
+ Mage::getSingleton('customer/session')->addSuccess($this->__('Thank you for your subscription.'));
47
+ }
48
+ }
49
+ } else {
50
+ if ($subscriber->isSubscribed($groupId)) {
51
+ $status = Mage::getModel("crconnect/subscriber")->unsubscribe($email, $groupId);
52
+ Mage::getSingleton('customer/session')->addSuccess($this->__('The subscription has been removed.'));
53
+ }
54
+ }
55
+ }
56
+ } catch (Exception $e) {
57
+ Mage::getSingleton('customer/session')->addError($e->getMessage());
58
+ Mage::getSingleton('customer/session')->addError($this->__('An error occurred while saving your subscription.'));
59
+ }
60
+ $this->_redirect('customer/account/');
61
+ }
62
+
63
+ }
app/code/community/Conlabz/CrConnect/controllers/SearchController.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Conlabz_CrConnect_SearchController extends Mage_Core_Controller_Front_Action {
3
+
4
+ public function indexAction() {
5
+
6
+ $systemPassword = Mage::helper("crconnect")->getCleverReachFeedPassword();
7
+
8
+ $store = $this->getRequest()->getParam('store');
9
+ $password = $this->getRequest()->getParam("password");
10
+
11
+ if (($systemPassword || $password) && $password != $systemPassword) {
12
+ die(Mage::helper("crconnect")->__("You have no permissions to view this page"));
13
+ }
14
+
15
+ $search = Mage::getModel('crconnect/search');
16
+ $action = $this->getRequest()->getParam('get');
17
+ switch ($action) {
18
+ case 'filter':
19
+ $returnData = $search->getFilter();
20
+ break;
21
+ case 'search':
22
+ $category = $this->getRequest()->getParam('category', false);
23
+ $product = $this->getRequest()->getParam('product', '');
24
+ $returnData = $search->getSearch($category, $product, $store);
25
+ break;
26
+ }
27
+
28
+ $this->getResponse()->setBody(json_encode($returnData));
29
+ }
30
+
31
+ }
app/code/community/Conlabz/CrConnect/controllers/SubscriberController.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Conlabz GmbH
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com and you will be sent a copy immediately.
15
+ *
16
+ * @category CleverReach
17
+ * @package Conlabz_CrConnect
18
+ * @copyright Copyright (c) 2012 Conlabz GmbH (http://www.cleverreach.com)
19
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
20
+ */
21
+ include "Mage/Newsletter/controllers/SubscriberController.php";
22
+
23
+ class Conlabz_CrConnect_SubscriberController extends Mage_Newsletter_SubscriberController {
24
+
25
+ const XML_PATH_LOGGED_CONFIRM_EMAIL_TEMPLATE = 'newsletter/subscription/confirm_logged_email_template';
26
+
27
+ public function newAction() {
28
+
29
+ if ($this->getRequest()->isPost() && $this->getRequest()->getPost('email')) {
30
+
31
+ $session = Mage::getSingleton('core/session');
32
+ $customerSession = Mage::getSingleton('customer/session');
33
+ $email = (string) $this->getRequest()->getPost('email');
34
+
35
+ try {
36
+
37
+ $status = Mage::getModel("newsletter/subscriber")->subscribe($email);
38
+
39
+ if ($status){
40
+ if (Mage::helper("crconnect")->isDoubleOptInEnabled()) {
41
+ Mage::getSingleton('core/session')->addSuccess($this->__('Confirmation request has been sent.'));
42
+ } else {
43
+ Mage::getSingleton('core/session')->addSuccess($this->__('Thank you for your subscription.'));
44
+ }
45
+ }
46
+
47
+ $this->_redirectReferer();
48
+ } catch (Exception $e) {
49
+ $session->addException($e, $this->__('There was a problem with the subscription'));
50
+ $this->_redirectReferer();
51
+ }
52
+ }
53
+ }
54
+
55
+ }
app/code/community/Conlabz/CrConnect/controllers/UnsubscribeController.php ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Conlabz GmbH
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com and you will be sent a copy immediately.
15
+ *
16
+ * @category CleverReach
17
+ * @package Conlabz_CrConnect
18
+ * @copyright Copyright (c) 2012 Conlabz GmbH (http://conlabz.de)
19
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
20
+ */
21
+
22
+ class Conlabz_CrConnect_UnsubscribeController extends Mage_Core_Controller_Front_Action
23
+ {
24
+ public function indexAction()
25
+ {
26
+ // don't do anything if we didn't get the email parameter
27
+ if(isset($_GET['email']))
28
+ {
29
+ $email = $_GET['email'];
30
+ $apiKey = trim(Mage::getStoreConfig('newsletter/crconnect/api_key'));
31
+ $listID = trim(Mage::getStoreConfig('newsletter/crconnect/list_id'));
32
+
33
+ // Check that the email address actually is unsubscribed in
34
+ // CleverReach
35
+ if($apiKey && $listID)
36
+ {
37
+ try {
38
+ $client = new SoapClient(Mage::helper('crconnect')->getWsdl(), array("trace" => true));
39
+ } catch(Exception $e) {
40
+ Mage::log("CleverReach_CrConnect: Error connecting to CleverReach server: ".$e->getMessage());
41
+ $session->addException($e, $this->__('There was a problem with the subscription'));
42
+ $this->_redirectReferer();
43
+ }
44
+
45
+ //get data from cleverreach
46
+ Mage::log("CleverReach_CrConnect: Error - ".$tmp->message);
47
+ $tmp = $client->receiverGetByEmail($apiKey, $email);
48
+ if($tmp->status!="SUCCESS"){
49
+ Mage::log("CleverReach_CrConnect: Error - ".$tmp->message);
50
+ $session->addException($e, $this->__('There was a problem with the unsubscription'));
51
+ $this->_redirectReferer();
52
+ }else{
53
+ Mage::log("CleverReach_CrConnect: Error - ".$tmp->message);
54
+ }
55
+
56
+ // If we are unsubscribed in cleverreach, mark us as
57
+ // unsubscribed in Magento.
58
+ if($tmp->data->deactivated)
59
+ {
60
+ try
61
+ {
62
+ Mage::log("CleverReach_CrConnect: Unsubscribing $email");
63
+ $collection = Mage::getModel('newsletter/subscriber')
64
+ ->loadByEmail($email)
65
+ ->unsubscribe();
66
+
67
+ Mage::getSingleton('customer/session')->addSuccess($this->__('You were successfully unsubscribed'));
68
+ }
69
+ catch (Exception $e)
70
+ {
71
+ Mage::log("CleverReach_CrConnect: ".$e->getMessage());
72
+ Mage::getSingleton('customer/session')->addError($this->__('There was an error while saving your subscription details'));
73
+ }
74
+ }
75
+ else
76
+ {
77
+ Mage::log("CleverReach_CrConnect: Not unsubscribing $email, not unsubscribed in Campaign Monitor");
78
+ }
79
+ }
80
+ }
81
+
82
+ $this->_redirect('customer/account/');
83
+ }
84
+ }
app/code/community/Conlabz/CrConnect/etc/adminhtml.xml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" ?>
2
+ <config>
3
+ <acl>
4
+ <resources>
5
+ <admin>
6
+ <children>
7
+ <system>
8
+ <children>
9
+ <config>
10
+ <children>
11
+ <crroot translate="title" module="crconnect">
12
+ <title>Cleverreach Settings</title>
13
+ <sort_order>50</sort_order>
14
+ </crroot>
15
+ </children>
16
+ </config>
17
+ </children>
18
+ </system>
19
+ </children>
20
+ </admin>
21
+ </resources>
22
+ </acl>
23
+ </config>
app/code/community/Conlabz/CrConnect/etc/config.xml ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Conlabz_CrConnect>
5
+ <version>3.0.0</version>
6
+ </Conlabz_CrConnect>
7
+ </modules>
8
+ <global>
9
+ <helpers>
10
+ <crconnect>
11
+ <class>Conlabz_CrConnect_Helper</class>
12
+ </crconnect>
13
+ </helpers>
14
+ <blocks>
15
+ <crconnect>
16
+ <class>Conlabz_CrConnect_Block</class>
17
+ </crconnect>
18
+ <adminhtml>
19
+ <rewrite>
20
+ <newsletter_subscriber>Conlabz_CrConnect_Block_Adminhtml_Newsletter_Subscriber</newsletter_subscriber>
21
+ <customer_edit_tab_newsletter>Conlabz_CrConnect_Block_Adminhtml_Customer_Edit_Tab_Newsletter</customer_edit_tab_newsletter>
22
+ </rewrite>
23
+ </adminhtml>
24
+ </blocks>
25
+ <models>
26
+ <crconnect>
27
+ <class>Conlabz_CrConnect_Model</class>
28
+ </crconnect>
29
+ <newsletter>
30
+ <rewrite>
31
+ <subscriber>Conlabz_CrConnect_Model_Newsletter_Subscriber</subscriber>
32
+ </rewrite>
33
+ </newsletter>
34
+ </models>
35
+ <events>
36
+ <controller_front_init_before>
37
+ <observers>
38
+ <crconnect_controller_front_init_before>
39
+ <type>singleton</type>
40
+ <class>crconnect/observer</class>
41
+ <method>trackingCodesSet</method>
42
+ </crconnect_controller_front_init_before>
43
+ </observers>
44
+ </controller_front_init_before>
45
+ <customer_session_init>
46
+ <observers>
47
+ <crconnect_customer_session_init>
48
+ <type>singleton</type>
49
+ <class>crconnect/observer</class>
50
+ <method>trackingCodesSet</method>
51
+ </crconnect_customer_session_init>
52
+ </observers>
53
+ </customer_session_init>
54
+ <checkout_onepage_controller_success_action>
55
+ <observers>
56
+ <crconnect_checkout_onepage_controller_success_action>
57
+ <type>singleton</type>
58
+ <class>crconnect/observer</class>
59
+ <method>checkoutSuccess</method>
60
+ </crconnect_checkout_onepage_controller_success_action>
61
+ </observers>
62
+ </checkout_onepage_controller_success_action>
63
+ <customer_delete_before>
64
+ <observers>
65
+ <crconnect_customer_delete_before>
66
+ <type>singleton</type>
67
+ <class>crconnect/observer</class>
68
+ <method>customerDeleted</method>
69
+ </crconnect_customer_delete_before>
70
+ </observers>
71
+ </customer_delete_before>
72
+ <customer_save_after>
73
+ <observers>
74
+ <crconnect_adminhtml_customer_save_after>
75
+ <type>singleton</type>
76
+ <class>crconnect/observer</class>
77
+ <method>customerSaveAfter</method>
78
+ </crconnect_adminhtml_customer_save_after>
79
+ </observers>
80
+ </customer_save_after>
81
+ </events>
82
+ </global>
83
+ <adminhtml>
84
+ <translate>
85
+ <modules>
86
+ <Conlabz_CrConnect>
87
+ <files>
88
+ <default>Conlabz_CleverReach.csv</default>
89
+ </files>
90
+ </Conlabz_CrConnect>
91
+ </modules>
92
+ </translate>
93
+ <layout>
94
+ <updates>
95
+ <crconnect>
96
+ <file>crconnect.xml</file>
97
+ </crconnect>
98
+ </updates>
99
+ </layout>
100
+ <events>
101
+ <admin_system_config_changed_section_crroot>
102
+ <observers>
103
+ <catalogindex>
104
+ <class>crconnect/observer</class>
105
+ <method>initCleverReach</method>
106
+ </catalogindex>
107
+ </observers>
108
+ </admin_system_config_changed_section_crroot>
109
+ <controller_action_postdispatch_adminhtml_system_config_save>
110
+ <observers>
111
+ <check_forms_ids>
112
+ <type>singleton</type>
113
+ <class>crconnect/observer</class>
114
+ <method>configSave</method>
115
+ </check_forms_ids>
116
+ </observers>
117
+ </controller_action_postdispatch_adminhtml_system_config_save>
118
+ </events>
119
+ </adminhtml>
120
+ <admin>
121
+ <routers>
122
+ <crconnect>
123
+ <use>admin</use>
124
+ <args>
125
+ <module>Conlabz_CrConnect</module>
126
+ <frontName>crconnect</frontName>
127
+ </args>
128
+ </crconnect>
129
+ </routers>
130
+ </admin>
131
+ <frontend>
132
+ <translate>
133
+ <modules>
134
+ <Conlabz_CrConnect>
135
+ <files>
136
+ <default>Conlabz_CleverReach.csv</default>
137
+ </files>
138
+ </Conlabz_CrConnect>
139
+ </modules>
140
+ </translate>
141
+ <routers>
142
+ <newsletter>
143
+ <args>
144
+ <modules>
145
+ <Conlabz_CrConnect before="Mage_Newsletter">Conlabz_CrConnect</Conlabz_CrConnect>
146
+ </modules>
147
+ </args>
148
+ </newsletter>
149
+ </routers>
150
+ <layout>
151
+ <updates>
152
+ <crconnect>
153
+ <file>crconnect.xml</file>
154
+ </crconnect>
155
+ </updates>
156
+ </layout>
157
+ </frontend>
158
+ </config>
app/code/community/Conlabz/CrConnect/etc/system.xml ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <crroot translate="label" module="crconnect">
5
+ <class>separator-top</class>
6
+ <label>CleverReach Connect</label>
7
+ <tab>customer</tab>
8
+ <sort_order>110</sort_order>
9
+ <show_in_default>1</show_in_default>
10
+ <show_in_website>1</show_in_website>
11
+ <show_in_store>1</show_in_store>
12
+ <groups>
13
+ <crconnect translate="label">
14
+ <label>CleverReach Settings</label>
15
+ <frontend_type>text</frontend_type>
16
+ <comment><![CDATA[The CleverReach plugin will synchronize all subscriptions and orders with your account.]]></comment>
17
+ <sort_order>0</sort_order>
18
+ <show_in_default>1</show_in_default>
19
+ <show_in_website>1</show_in_website>
20
+ <show_in_store>1</show_in_store>
21
+ <fields>
22
+ <api_key translate="label">
23
+ <label>API Key</label>
24
+ <frontend_model>crconnect/config_key</frontend_model>
25
+ <frontend_type>text</frontend_type>
26
+ <sort_order>1</sort_order>
27
+ <show_in_default>1</show_in_default>
28
+ <show_in_website>1</show_in_website>
29
+ <show_in_store>1</show_in_store>
30
+ <comment>This can be found on your Listsettings page in CleverReach.</comment>
31
+ </api_key>
32
+ <list_id translate="label">
33
+ <label>General Subscribers List ID</label>
34
+ <frontend_type>select</frontend_type>
35
+ <source_model>crconnect/system_config_source_emptyList</source_model>
36
+ <sort_order>2</sort_order>
37
+ <show_in_default>1</show_in_default>
38
+ <show_in_website>1</show_in_website>
39
+ <show_in_store>1</show_in_store>
40
+ <comment>Magento users who subscribe/unsubscribe to the newsletter will be added/removed from this CleverReach receiver list.</comment>
41
+ </list_id>
42
+ <form_id translate="label">
43
+ <label>CleverReach Form ID</label>
44
+ <frontend_type>select</frontend_type>
45
+ <source_model>crconnect/system_config_source_emptyForms</source_model>
46
+ <sort_order>3</sort_order>
47
+ <show_in_default>1</show_in_default>
48
+ <show_in_website>1</show_in_website>
49
+ <show_in_store>1</show_in_store>
50
+ <comment>Create new Form in your CleverReach backend, if you want to use Double Opt-in</comment>
51
+ </form_id>
52
+
53
+
54
+ <confirm_newsletter_logged translate="label">
55
+ <label>Enable Douple Opi-in</label>
56
+ <frontend_type>select</frontend_type>
57
+ <source_model>adminhtml/system_config_source_yesno</source_model>
58
+ <sort_order>20</sort_order>
59
+ <show_in_default>1</show_in_default>
60
+ <show_in_website>1</show_in_website>
61
+ <show_in_store>1</show_in_store>
62
+ </confirm_newsletter_logged>
63
+ <sync_orders translate="label">
64
+ <label>Enable Orders Tracking</label>
65
+ <frontend_type>select</frontend_type>
66
+ <source_model>adminhtml/system_config_source_yesno</source_model>
67
+ <sort_order>5</sort_order>
68
+ <show_in_default>1</show_in_default>
69
+ <show_in_website>1</show_in_website>
70
+ <show_in_store>1</show_in_store>
71
+ <comment>Sync sales with CleverReach. Required for ordertracking. Note: this will currently NOT work with the Multishipping Checkout</comment>
72
+ </sync_orders>
73
+ <auto_separate translate="label">
74
+ <label>Separate customers by groups automatically</label>
75
+ <frontend_type>select</frontend_type>
76
+ <source_model>adminhtml/system_config_source_yesno</source_model>
77
+ <sort_order>15</sort_order>
78
+ <show_in_default>1</show_in_default>
79
+ <show_in_website>1</show_in_website>
80
+ <show_in_store>1</show_in_store>
81
+ <comment>During customers synchronization, they will be inserted in associated CleverReach groups lists</comment>
82
+ </auto_separate>
83
+ <groups_keys translate="comment">
84
+ <label>API keys for user groups</label>
85
+ <frontend_model>crconnect/config_groupsApis</frontend_model>
86
+ <backend_model>adminhtml/system_config_backend_serialized_array</backend_model>
87
+ <sort_order>25</sort_order>
88
+ <show_in_default>1</show_in_default>
89
+ <show_in_website>1</show_in_website>
90
+ <show_in_store>1</show_in_store>
91
+ <comment></comment>
92
+ </groups_keys>
93
+ <showgroup translate="comment">
94
+ <label>Hide 'General' subscription for groups</label>
95
+ <frontend_type>select</frontend_type>
96
+ <source_model>adminhtml/system_config_source_yesno</source_model>
97
+ <sort_order>30</sort_order>
98
+ <show_in_default>1</show_in_default>
99
+ <show_in_website>1</show_in_website>
100
+ <show_in_store>1</show_in_store>
101
+ <comment>If 'No' - then not 'General' user group users, will have possibility to subscribe for both: 'General' and '% Group' newsletter. If 'Yes' - just to '% Groups' newsletter</comment>
102
+ </showgroup>
103
+ </fields>
104
+ </crconnect>
105
+ <csconnect_search>
106
+ <label>CleverReach Search Settings</label>
107
+ <frontend_type>text</frontend_type>
108
+ <sort_order>2</sort_order>
109
+ <show_in_default>1</show_in_default>
110
+ <show_in_website>1</show_in_website>
111
+ <show_in_store>1</show_in_store>
112
+ <fields>
113
+ <feed_url translate="label comment">
114
+ <label>Feed-URL</label>
115
+ <frontend_model>crconnect/config_url</frontend_model>
116
+ <sort_order>1</sort_order>
117
+ <show_in_default>1</show_in_default>
118
+ <show_in_website>1</show_in_website>
119
+ <show_in_store>1</show_in_store>
120
+ <comment>Copy this Feed-URL to your CleverReach account. Store Id is optional parameter, add it in case, if you want use feed for other stores</comment>
121
+ </feed_url>
122
+ <password translate="label comment">
123
+ <label>Password</label>
124
+ <frontend_type>password</frontend_type>
125
+ <sort_order>1</sort_order>
126
+ <show_in_default>1</show_in_default>
127
+ <show_in_website>1</show_in_website>
128
+ <show_in_store>1</show_in_store>
129
+ <comment>Create your own password for CleverReach feed</comment>
130
+ </password>
131
+ </fields>
132
+ </csconnect_search>
133
+ </groups>
134
+ </crroot>
135
+ </sections>
136
+ </config>
app/design/adminhtml/default/default/layout/crconnect.xml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout>
3
+ <default>
4
+ <reference name="head">
5
+ <action method="addItem"><type>skin_js</type><name>js/crconnect.js</name><params/></action>
6
+ </reference>
7
+ <reference name="root">
8
+ <block type="core/template" name="crconnect_header" output="toHtml">
9
+ <action method="setTemplate"><template>crconnect/config/header.phtml</template></action>
10
+ </block>
11
+ </reference>
12
+ </default>
13
+
14
+ </layout>
app/design/adminhtml/default/default/template/crconnect/config/header.phtml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script>
2
+ var baseConfirmKeyUrl = "<?php echo $this->getUrl("crconnect/adminhtml_config/confirmKey")?>";
3
+ var baseChangeGroupUrl = "<?php echo $this->getUrl("crconnect/adminhtml_config/changeGroup")?>";
4
+ var baseGroupsBlockUrl = "<?php echo $this->getUrl("crconnect/adminhtml_config/getGroupsBlock")?>";
5
+
6
+ var savedDefaultListId = "<?php echo Mage::helper("crconnect")->getDefaultListId();?>";
7
+ var savedDefaultFormId = "<?php echo Mage::helper("crconnect")->getDefaultFormId();?>";
8
+ var savedFormsKeys = new Array();
9
+ <?php foreach (Mage::helper("crconnect")->getFormsIdsByKeys() as $key=>$formKey):?>
10
+ savedFormsKeys[<?php echo "'" . $key . "'";?>] = "<?php echo $formKey;?>";
11
+ <?php endforeach;?>
12
+
13
+ var crconnectLang = new Array();
14
+ crconnectLang['please:select:group:default'] = "<?php echo Mage::helper("crconnect")->__("No groups to select")?>";
15
+ crconnectLang['please:select:form:default'] = "<?php echo Mage::helper("crconnect")->__("No forms to select")?>";
16
+ crconnectLang['please:select:group'] = "<?php echo Mage::helper("crconnect")->__("Please select subscribers group")?>";
17
+ crconnectLang['please:select:form'] = "<?php echo Mage::helper("crconnect")->__("Please select form")?>";
18
+
19
+ </script>
app/design/adminhtml/default/default/template/crconnect/newsletter/subscriber/list.phtml ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script>
2
+ function synchronizeData(){
3
+
4
+ var url = '<?php echo $this->getUrl("crconnect/adminhtml_crconnect/synchronize")?>id/';
5
+ new Ajax.Request(url, {
6
+ method: 'post',
7
+ onSuccess: function(transport) {
8
+ editData = transport.responseText.evalJSON(true);
9
+ if (editData.error == false){
10
+ $("success-messages").show();
11
+ $("success-messages-content").innerHTML = editData.message;
12
+ }else{
13
+ $("error-messages").show();
14
+ $("error-messages-content").innerHTML = editData.message;
15
+ }
16
+ scroll(0,0);
17
+ document.location.assign("<?php echo $this->getUrl("*/*/")?>");
18
+ }
19
+ });
20
+
21
+ }
22
+ </script>
23
+ <style>
24
+ .overview tr td:first-child {
25
+ width: 250px;
26
+ }
27
+ </style>
28
+ <?php $info = $this->getSubscribersListData(); ?>
29
+ <div id="error-messages" <?php if (sizeof($info['error']) == 0): ?>style="display:none"<?php endif; ?>><ul class="messages"><li class="error-msg"><ul><li id="error-messages-content"><?php echo implode("<br />", $info['error'])?></li></ul></li></ul></div>
30
+ <div id="success-messages" style="display:none"><ul class="messages"><li class="success-msg"><ul><li id="success-messages-content"></li></ul></li></ul></div>
31
+ <div class="content-header">
32
+ <table cellspacing="0">
33
+ <tr>
34
+ <td style="width: 50%;">
35
+ <h3><?php echo Mage::helper('newsletter')->__('Newsletter Subscribers') ?></h3>
36
+ </td>
37
+ <td align="right"><img src="<?php echo $this->getSkinUrl('images/cleverreach/cleverreach-logo.png')?>" alt="" /></td>
38
+ </tr>
39
+ </table>
40
+ </div>
41
+ <?php if (sizeof($info['error']) == 0): ?>
42
+ <p><?php echo Mage::helper("crconnect")->__('Magento subscribers list has been deactivated since deactivation will most likly happen in Cleverreach.')?>
43
+ <br /><?php echo Mage::helper("crconnect")->__('Please use your Cleverreach account to activate/deactivate your subscribers.')?></p>
44
+
45
+ <?php if(isset($info['info']) && isset($info['info']['client'])): ?>
46
+ <div class="entry-edit">
47
+ <div class="entry-edit-head"><h4 class="icon-head head-customer-view"><?php echo Mage::helper("crconnect")->__('CleverReach Connect general information');?></h4></div>
48
+ <fieldset>
49
+ <table class="box-left" cellspacing="2">
50
+ <tbody>
51
+ <tr>
52
+ <td><strong><?php echo Mage::helper("crconnect")->__('CleverReach client ID')?>:</strong></td>
53
+ <td><?php echo $info['info']['client']->id?></td>
54
+ </tr>
55
+ <tr>
56
+ <td><strong><?php echo Mage::helper("crconnect")->__('Name')?></strong></td>
57
+ <td><?php echo $info['info']['client']->firstname?> <?php echo $info['info']['client']->name?></td>
58
+ </tr>
59
+ <tr>
60
+ <td><strong><?php echo Mage::helper("crconnect")->__('Company');?></strong></td>
61
+ <td><?php echo $info['info']['client']->company?></td>
62
+ </tr>
63
+ <tr>
64
+ <td><strong><?php echo Mage::helper("crconnect")->__('E-Mail')?></strong></td>
65
+ <td><?php echo $info['info']['client']->email?></td>
66
+ </tr>
67
+ <tr>
68
+ <td><strong><?php echo Mage::helper("crconnect")->__('Active Subscribers in Magento system')?></strong></td>
69
+ <td><?php echo $info['info']['actvie_subscribers']?></td>
70
+ </tr>
71
+ <tr>
72
+ <td><strong><?php echo Mage::helper("crconnect")->__('Inactive Subscribers in Magento system')?></strong></td>
73
+ <td><?php echo $info['info']['inactive_subscribers']?></td>
74
+ </tr>
75
+ </tbody></table>
76
+ <div class="box-right">
77
+ <strong><?php echo Mage::helper("crconnect")->__('Login')?></strong><br />
78
+ <a href="http://<?php echo $info['info']['client']->login_domain?>/admin/" target="_blank"><b><?php echo Mage::helper("crconnect")->__('Cleaverreach login');?></b></a>
79
+ </div>
80
+ </fieldset>
81
+ </div>
82
+ <?php endif; ?>
83
+
84
+ <?php if(isset($info['info']) && isset($info['info']['list']) && $info['info']['list']): ?>
85
+ <div class="entry-edit overview">
86
+ <div class="entry-edit-head"><h4 class="icon-head head-customer-view"><?php echo Mage::helper("crconnect")->__('CleverReach Connect General list information')?></h4></div>
87
+ <fieldset>
88
+ <table class="box-left" cellspacing="2">
89
+ <tbody>
90
+ <tr>
91
+ <td><strong><?php echo Mage::helper("crconnect")->__('List name')?></strong></td>
92
+ <td><?php echo $info['info']['list']->name?></td>
93
+ </tr>
94
+ <tr>
95
+ <td><strong><?php echo Mage::helper("crconnect")->__('Last mailing')?></strong></td>
96
+ <td><?php if (isset($info['info']['list']->last_mailing)):?><?php echo date("r", @$info['info']['list']->last_mailing)?><?php else:?><b><font color="red"><?php echo Mage::helper("crconnect")->__('Never Sent');?></font></b><?php endif;?></td>
97
+ </tr>
98
+ </tbody></table>
99
+ <table class="box-right" cellspacing="2">
100
+ <tbody>
101
+ <tr>
102
+ <td><strong><?php echo Mage::helper("crconnect")->__('Active receivers')?></strong></td>
103
+ <td><?php echo $info['info']['list']->active?></td>
104
+ </tr>
105
+ <tr>
106
+ <td><strong><?php echo Mage::helper("crconnect")->__('Inactive receivers')?></strong></td>
107
+ <td><?php echo $info['info']['list']->inactive?></td>
108
+ </tr>
109
+ <tr>
110
+ <td><strong><?php echo Mage::helper("crconnect")->__('Total receivers');?></strong></td>
111
+ <td><?php echo $info['info']['list']->total?></td>
112
+ </tr>
113
+ </tbody>
114
+ </table>
115
+ </fieldset>
116
+ </div>
117
+ <?php endif; ?>
118
+ <?php if(isset($info['info']) && isset($info['info']['groups']) && is_array($info['info']['groups']) && sizeof($info['info']['groups']) > 0): ?>
119
+ <?php foreach ($info['info']['groups'] as $group):?>
120
+ <div class="entry-edit overview">
121
+ <div class="entry-edit-head"><h4 class="icon-head head-customer-view"><?php echo $group->name?></h4></div>
122
+ <fieldset>
123
+ <table class="box-left" cellspacing="2">
124
+ <tbody>
125
+ <tr>
126
+ <td><strong><?php echo Mage::helper("crconnect")->__('List name')?></strong></td>
127
+ <td><?php echo $group->name?></td>
128
+ </tr>
129
+ <tr>
130
+ <td><strong><?php echo Mage::helper("crconnect")->__('Last mailing')?></strong></td>
131
+ <td><?php if (isset($group->last_mailing)):?><?php echo date("r", @$group->last_mailing)?><?php else:?><b><font color="red"><?php echo Mage::helper("crconnect")->__('Never Sent');?></font></b><?php endif;?></td>
132
+ </tr>
133
+ </tbody></table>
134
+ <table class="box-right" cellspacing="2">
135
+ <tbody>
136
+ <tr>
137
+ <td><strong><?php echo Mage::helper("crconnect")->__('Active receivers')?></strong></td>
138
+ <td><?php echo $group->active?></td>
139
+ </tr>
140
+ <tr>
141
+ <td><strong><?php echo Mage::helper("crconnect")->__('Inactive receivers')?></strong></td>
142
+ <td><?php echo $group->inactive?></td>
143
+ </tr>
144
+ <tr>
145
+ <td><strong><?php echo Mage::helper("crconnect")->__('Total receivers');?></strong></td>
146
+ <td><?php echo $group->total?></td>
147
+ </tr>
148
+ </tbody>
149
+ </table>
150
+ </fieldset>
151
+ </div>
152
+ <?php endforeach;?>
153
+ <?php endif; ?>
154
+ <div id="cr_import">
155
+ <button type="button" class="scalable" onclick="synchronizeData()" style=""><span><span><span><?php echo Mage::helper("crconnect")->__('Synchronize data with CleverReach')?></span></span></span></button>
156
+ &nbsp;&nbsp;&nbsp;&nbsp;<?php echo Mage::helper("crconnect")->__('Warning: Please wait untill the synchronization is finished. Depending on the amount of data this might take a while.')?>
157
+ </div>
158
+ <?php else:?>
159
+ <button type="button" class="scalable" onclick="document.location.assign('<?php echo $this->getUrl('adminhtml/system_config/edit', array('section'=>'crroot'))?>')" style=""><span><span><span><?php echo Mage::helper("crconnect")->__('CleverReach extension configuration')?></span></span></span></button>
160
+ <?php endif; ?>
app/design/adminhtml/default/default/template/crconnect/system/config/form/field/array_groups.phtml ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $_htmlId = $this->getHtmlId() ? $this->getHtmlId() : '_' . uniqid();
3
+
4
+ $_colspan = 2;
5
+ if (!$this->_addAfter) {
6
+ $_colspan -= 1;
7
+ }
8
+ $_colspan = $_colspan > 1 ? 'colspan="' . $_colspan . '"' : '';
9
+ ?>
10
+
11
+ <div class="grid" id="grid<?php echo $_htmlId ?>">
12
+ <table cellpadding="0" cellspacing="0" class="border">
13
+ <tbody>
14
+
15
+ <tr class="headings" id="headings<?php echo $_htmlId ?>">
16
+ <?php foreach ($this->_columns as $columnName => $column):?>
17
+ <th><?php echo $column['label'] ?></th>
18
+ <?php endforeach;?>
19
+ <th <?php echo $_colspan?>></th>
20
+ </tr>
21
+
22
+ <tr id="addRow<?php echo $_htmlId ?>">
23
+ <td colspan="<?php echo count($this->_columns) ?>"></td>
24
+ <td <?php echo $_colspan?>>
25
+ <button style="" onclick="" class="scalable add" type="button" id="addToEndBtn<?php echo $_htmlId ?>">
26
+ <span><?php echo $this->_addButtonLabel ?></span>
27
+ </button>
28
+ </td>
29
+ </tr>
30
+
31
+ </tbody>
32
+ </table>
33
+ <input type="hidden" name="<?php echo $this->getElement()->getName() ?>[__empty]" value="" />
34
+ </div>
35
+ <div id="empty<?php echo $_htmlId ?>">
36
+ <button style="" onclick="" class="scalable add" type="button" id="emptyAddBtn<?php echo $_htmlId ?>">
37
+ <span><?php echo $this->_addButtonLabel ?></span>
38
+ </button>
39
+ </div>
40
+
41
+ <script type="text/javascript">
42
+ // <!--
43
+ // create row creator
44
+ var arrayRow<?php echo $_htmlId ?> = {
45
+ // define row prototypeJS template
46
+ template : new Template(
47
+ '<tr id="#{_id}">'
48
+ <?php foreach ($this->_columns as $columnName => $column):?>
49
+ +'<td class="#{_id}-<?php echo $columnName?>">'
50
+ +'<?php echo $this->_renderCellTemplate($columnName)?>'
51
+ +'</td>'
52
+ <?php endforeach;?>
53
+ <?php if ($this->_addAfter):?>
54
+ +'<td><button onclick="" class="scalable add" type="button" id="addAfterBtn#{_id}"><span><?php echo Mage::helper('adminhtml')->__('Add after') ?></span></button></td>'
55
+ <?php endif;?>
56
+ +'<td><button onclick="arrayRow<?php echo $_htmlId ?>.del(\'#{_id}\')" class="scalable delete" type="button"><span><?php echo Mage::helper('adminhtml')->__('Delete') ?></span></button></td>'
57
+ +'</tr>'
58
+ ),
59
+
60
+ rowsCount : 0,
61
+
62
+ add : function(templateData, insertAfterId)
63
+ {
64
+ // generate default template data
65
+ if ('' == templateData) {
66
+ var d = new Date();
67
+ var templateData = {
68
+ <?php foreach ($this->_columns as $columnName => $column):?>
69
+ <?php echo $columnName ?> : '',
70
+ <?php endforeach;?>
71
+ _id : '_' + d.getTime() + '_' + d.getMilliseconds()
72
+ };
73
+ }
74
+
75
+ // insert before last row
76
+ if ('' == insertAfterId) {
77
+ new Insertion.Before(
78
+ $('addRow<?php echo $_htmlId ?>'),
79
+ this.template.evaluate(templateData)
80
+ );
81
+ }
82
+ // insert after specified row
83
+ else {
84
+ new Insertion.After(
85
+ $(insertAfterId),
86
+ this.template.evaluate(templateData)
87
+ );
88
+ }
89
+ // set the selected drop-down list item
90
+ <?php foreach ($this->_columns as $columnName => $column):?>
91
+ var options = $$('td.' + templateData._id + '-' + '<?php echo $columnName?>' + ' option')
92
+ for(var index = 0; index < options.length; ++index)
93
+ {
94
+ var option = options[index]
95
+ if(option.getAttribute('value') == templateData.<?php echo $columnName?>)
96
+ {
97
+ option.selected = true
98
+ }
99
+ }
100
+ <?php endforeach;?>
101
+
102
+ <?php if ($this->_addAfter):?>
103
+ Event.observe('addAfterBtn' + templateData._id, 'click', this.add.bind(this, '', templateData._id));
104
+ <?php endif;?>
105
+
106
+ this.rowsCount += 1;
107
+ },
108
+
109
+ del : function(rowId)
110
+ {
111
+ $(rowId).remove();
112
+ this.rowsCount -= 1;
113
+ if (0 == this.rowsCount) {
114
+ this.showButtonOnly();
115
+ }
116
+ },
117
+
118
+ showButtonOnly : function()
119
+ {
120
+ $('grid<?php echo $_htmlId ?>').hide();
121
+ $('empty<?php echo $_htmlId ?>').show();
122
+ }
123
+ }
124
+
125
+ // bind add action to "Add" button in last row
126
+ Event.observe('addToEndBtn<?php echo $_htmlId ?>', 'click', arrayRow<?php echo $_htmlId ?>.add.bind(arrayRow<?php echo $_htmlId ?>, '', ''));
127
+
128
+ // add existing rows
129
+ <?php
130
+ $_addAfterId = "headings{$_htmlId}";
131
+ foreach ($this->getArrayRows() as $_rowId => $_row) {
132
+ echo "arrayRow{$_htmlId}.add(" . $_row->toJson() . ", '{$_addAfterId}');\n";
133
+ /*print "%%%%%%%%%%%%%%%";
134
+ print_r($_row->toJson());*/
135
+ $_addAfterId = $_rowId;
136
+ }
137
+ ?>
138
+
139
+ // initialize standalone button
140
+ $('empty<?php echo $_htmlId ?>').hide();
141
+ Event.observe('emptyAddBtn<?php echo $_htmlId ?>', 'click', function () {
142
+ $('grid<?php echo $_htmlId ?>').show();
143
+ $('empty<?php echo $_htmlId ?>').hide();
144
+ arrayRow<?php echo $_htmlId ?>.add('', '');
145
+ });
146
+
147
+ // if no rows, hide grid and show button only
148
+ <?php if (!$this->getArrayRows()):?>
149
+ arrayRow<?php echo $_htmlId ?>.showButtonOnly();
150
+ <?php endif;?>
151
+
152
+ // toggle the grid, if element is disabled (depending on scope)
153
+ <?php if ($this->getElement()->getDisabled()):?>
154
+ toggleValueElements({checked:true}, $('grid<?php echo $_htmlId ?>').parentNode);
155
+ <?php endif;?>
156
+ // -->
157
+ </script>
app/design/adminhtml/default/default/template/crconnect/system/config/form/field/cr_array_groups.phtml ADDED
@@ -0,0 +1,188 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ //var_dump(Mage::helper("crconnect")->getFormsIdsByKeys());
3
+ $_htmlId = $this->getHtmlId() ? $this->getHtmlId() : '_' . uniqid();
4
+ $_colspan = 2;
5
+ if (!$this->_addAfter) {
6
+ $_colspan -= 1;
7
+ }
8
+ $_colspan = $_colspan > 1 ? 'colspan="' . $_colspan . '"' : '';
9
+ ?>
10
+ <script>
11
+ function callRowDelete(id){
12
+ arrayRow<?php echo $_htmlId ?>.del(id);
13
+ }
14
+ </script>
15
+ <div class="grid" id="grid<?php echo $_htmlId ?>">
16
+ <table cellpadding="0" cellspacing="0" class="border">
17
+ <tbody>
18
+ <tr class="headings cleverreach-headings" id="headings<?php echo $_htmlId ?>">
19
+ <?php foreach ($this->_columns as $columnName => $column): ?>
20
+ <th><?php echo $column['label'] ?></th>
21
+ <?php endforeach; ?>
22
+ <th <?php echo $_colspan ?>></th>
23
+ </tr>
24
+ <tr id="addRow<?php echo $_htmlId ?>">
25
+ <td colspan="<?php echo count($this->_columns) ?>"></td>
26
+ <td <?php echo $_colspan ?>>
27
+ <button style="" onclick="arrayRow<?php echo $_htmlId ?>.add('', '')" class="scalable add" type="button" id="addToEndBtn<?php echo $_htmlId ?>">
28
+ <span><?php echo $this->_addButtonLabel ?></span>
29
+ </button>
30
+ </td>
31
+ </tr>
32
+
33
+ </tbody>
34
+ </table>
35
+ <input type="hidden" name="<?php echo $this->getElement()->getName() ?>[__empty]" value="" />
36
+ </div>
37
+ <div id="empty<?php echo $_htmlId ?>">
38
+ <button style="" onclick="emptyAction()" class="scalable add" type="button" id="emptyAddBtn<?php echo $_htmlId ?>">
39
+ <span><?php echo $this->_addButtonLabel ?></span>
40
+ </button>
41
+ </div>
42
+ <script type="text/javascript">
43
+ // <!--
44
+ var editedSelects = new Array();
45
+ var stringElements = new Array();
46
+ <?php foreach ($this->_columns as $columnName => $column): ?>
47
+ stringElements['<?php echo $columnName; ?>'] = '<?php echo $this->_renderCellTemplate($columnName) ?>';
48
+ <?php endforeach; ?>
49
+ var rowTemplate = "";
50
+ function initRowTemplate(){
51
+ rowTemplate = new Template(
52
+ '<tr id="#{_id}" class="simple-added-row">'
53
+ <?php foreach ($this->_columns as $columnName => $column): ?>
54
+ + '<td class="#{_id}-<?php echo $columnName ?>">'
55
+ + stringElements['<?php echo $columnName; ?>']
56
+ + '</td>'
57
+ <?php endforeach; ?>
58
+ <?php if ($this->_addAfter): ?>
59
+ + '<td><button onclick="" class="scalable add" type="button" id="addAfterBtn#{_id}"><span><?php echo Mage::helper('adminhtml')->__('Add after') ?></span></button></td>'
60
+ <?php endif; ?>
61
+ + '<td><button onclick="arrayRow<?php echo $_htmlId ?>.del(\'#{_id}\')" class="scalable delete" type="button"><span><?php echo Mage::helper('adminhtml')->__('Delete') ?></span></button></td>'
62
+ + '</tr>'
63
+ );
64
+ }
65
+ initRowTemplate();
66
+ // create row creator
67
+ var arrayRow<?php echo $_htmlId ?> = {
68
+ // define row prototypeJS template
69
+ template : new Template(
70
+ '<tr id="#{_id}" class="simple-added-row">'
71
+ <?php foreach ($this->_columns as $columnName => $column): ?>
72
+ + '<td class="#{_id}-<?php echo $columnName ?>">'
73
+ + stringElements['<?php echo $columnName; ?>']
74
+ + '</td>'
75
+ <?php endforeach; ?>
76
+ <?php if ($this->_addAfter): ?>
77
+ + '<td><button onclick="" class="scalable add" type="button" id="addAfterBtn#{_id}"><span><?php echo Mage::helper('adminhtml')->__('Add after') ?></span></button></td>'
78
+ <?php endif; ?>
79
+ + '<td><button onclick="arrayRow<?php echo $_htmlId ?>.del(\'#{_id}\')" class="scalable delete" type="button"><span><?php echo Mage::helper('adminhtml')->__('Delete') ?></span></button></td>'
80
+ + '</tr>'
81
+ ),
82
+ rowsCount : 0,
83
+ add : function(templateData, insertAfterId)
84
+ {
85
+ // generate default template data
86
+ if ('' == templateData) {
87
+ var d = new Date();
88
+ var templateData = {
89
+ <?php foreach ($this->_columns as $columnName => $column): ?>
90
+ <?php echo $columnName ?> : '',
91
+ <?php endforeach; ?>
92
+ _id : '_' + d.getTime() + '_' + d.getMilliseconds()
93
+ };
94
+ }
95
+
96
+
97
+ // insert before last row
98
+ if ('' == insertAfterId) {
99
+ new Insertion.Before(
100
+ $('addRow<?php echo $_htmlId ?>'),
101
+ rowTemplate.evaluate(templateData)
102
+ );
103
+ }
104
+ // insert after specified row
105
+ else {
106
+ new Insertion.After(
107
+ $(insertAfterId),
108
+ rowTemplate.evaluate(templateData)
109
+ );
110
+ }
111
+ // set the selected drop-down list item
112
+ <?php foreach ($this->_columns as $columnName => $column): ?>
113
+ var options = $$('td.' + templateData._id + '-' + '<?php echo $columnName ?>' + ' option')
114
+ for (var index = 0; index < options.length; ++index)
115
+ {
116
+ var option = options[index]
117
+ if (option.getAttribute('value') == templateData.<?php echo $columnName ?>)
118
+ {
119
+ option.selected = true
120
+ <?php if ($columnName == "crconnect"): ?>
121
+ editedSelects.push(templateData._id);
122
+ // Event.observe(window, 'load', Crconnect.changeSubGroup($(templateData._id+"_crconnect")));
123
+ <?php endif; ?>
124
+ }
125
+ }
126
+ <?php endforeach; ?>
127
+
128
+ <?php if ($this->_addAfter): ?>
129
+ Event.observe('addAfterBtn' + templateData._id, 'click', this.add.bind(this, '', templateData._id));
130
+ <?php endif; ?>
131
+
132
+ this.rowsCount += 1;
133
+ },
134
+ del : function(rowId)
135
+ {
136
+ $(rowId).remove();
137
+ this.rowsCount -= 1;
138
+ if (0 == this.rowsCount) {
139
+ this.showButtonOnly();
140
+ }
141
+ },
142
+ showButtonOnly : function()
143
+ {
144
+ $('grid<?php echo $_htmlId ?>').hide();
145
+ $('empty<?php echo $_htmlId ?>').show();
146
+ }
147
+ }
148
+
149
+ // bind add action to "Add" button in last row
150
+ //Event.observe('addToEndBtn<?php echo $_htmlId ?>', 'click', arrayRow<?php echo $_htmlId ?>.add.bind(arrayRow<?php echo $_htmlId ?>, '', ''));
151
+
152
+ // add existing rows
153
+ <?php
154
+ $_addAfterId = "headings{$_htmlId}";
155
+ foreach ($this->getArrayRows() as $_rowId => $_row) {
156
+ echo "arrayRow{$_htmlId}.add(" . $_row->toJson() . ", '{$_addAfterId}');\n";
157
+ /* print "%%%%%%%%%%%%%%%";
158
+ print_r($_row->toJson()); */
159
+ $_addAfterId = $_rowId;
160
+ }
161
+ ?>
162
+
163
+ function emptyAction(){
164
+
165
+ $('grid<?php echo $_htmlId ?>').show();
166
+ $('empty<?php echo $_htmlId ?>').hide();
167
+ arrayRow<?php echo $_htmlId ?>.add('', '');
168
+ }
169
+
170
+ // initialize standalone button
171
+ $('empty<?php echo $_htmlId ?>').hide();
172
+ //Event.observe('emptyAddBtn<?php echo $_htmlId ?>', 'click', function () {
173
+ // $('grid<?php echo $_htmlId ?>').show();
174
+ // $('empty<?php echo $_htmlId ?>').hide();
175
+ // arrayRow<?php echo $_htmlId ?>.add('', '');
176
+ //});
177
+
178
+ // if no rows, hide grid and show button only
179
+ <?php if (!$this->getArrayRows()): ?>
180
+ arrayRow<?php echo $_htmlId ?>.showButtonOnly();
181
+ <?php endif; ?>
182
+
183
+ // toggle the grid, if element is disabled (depending on scope)
184
+ <?php if ($this->getElement()->getDisabled()): ?>
185
+ toggleValueElements({checked:true}, $('grid<?php echo $_htmlId ?>').parentNode);
186
+ <?php endif; ?>
187
+ // -->
188
+ </script>
app/design/frontend/base/default/layout/crconnect.xml ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+
4
+ <newsletter_manage_index translate="label">
5
+ <label>Customer My Account Newsletter Subscriptions</label>
6
+ <reference name="my.account.wrapper">
7
+ <block type="crconnect/customer_newsletter" name="customer_newsletter" template="crconnect/customer/form/newsletter.phtml">
8
+ <block type="page/html_wrapper" name="customer.newsletter.form.before" as="form_before" translate="label">
9
+ <label>Newsletter Subscription Form Before</label>
10
+ <action method="setMayBeInvisible"><value>1</value></action>
11
+ </block>
12
+ </block>
13
+ </reference>
14
+ </newsletter_manage_index>
15
+
16
+ <customer_account_index translate="label">
17
+ <label>Customer My Account Dashboard</label>
18
+ <!-- Mage_Customer -->
19
+ <reference name="root">
20
+ <action method="setTemplate"><template>page/2columns-left.phtml</template></action>
21
+ </reference>
22
+ <reference name="my.account.wrapper">
23
+ <block type="customer/account_dashboard" name="customer_account_dashboard" template="customer/account/dashboard.phtml">
24
+ <block type="customer/account_dashboard_hello" name="customer_account_dashboard_hello" as="hello" template="customer/account/dashboard/hello.phtml"/>
25
+ <block type="core/template" name="customer_account_dashboard_top" as="top" />
26
+ <block type="customer/account_dashboard_info" name="customer_account_dashboard_info" as="info" template="crconnect/customer/account/dashboard/info.phtml"/>
27
+ <block type="customer/account_dashboard_newsletter" name="customer_account_dashboard_newsletter" as="newsletter" template="customer/account/dashboard/newsletter.phtml"/>
28
+ <block type="customer/account_dashboard_address" name="customer_account_dashboard_address" as="address" template="customer/account/dashboard/address.phtml"/>
29
+ </block>
30
+ </reference>
31
+ </customer_account_index>
32
+
33
+ </layout>
app/design/frontend/base/default/template/crconnect/customer/account/dashboard/info.phtml ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // Get Groupd Id and group name of user
3
+ $groupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
4
+ $groupName = Mage::getModel('customer/group')->load($groupId)->getCode();
5
+
6
+ $isDefaultSubscribed = Mage::getModel('crconnect/newsletter_subscriber')->isSubscribed();
7
+ $isCustomSubscribed = Mage::getModel('crconnect/newsletter_subscriber')->isSubscribed($groupId);
8
+ ?>
9
+ <div class="col2-set">
10
+ <div class="col-1">
11
+ <div class="box">
12
+ <div class="box-title">
13
+ <h3><?php echo $this->__('Contact Information') ?></h3>
14
+ <a href="<?php echo $this->getUrl('customer/account/edit') ?>"><?php echo $this->__('Edit') ?></a>
15
+ </div>
16
+ <div class="box-content">
17
+ <p>
18
+ <?php echo $this->htmlEscape($this->getCustomer()->getName()) ?><br />
19
+ <?php echo $this->htmlEscape($this->getCustomer()->getEmail()) ?><br />
20
+ <a href="<?php echo $this->getChangePasswordUrl() ?>"><?php echo $this->__('Change Password') ?></a>
21
+ </p>
22
+ </div>
23
+ </div>
24
+ </div>
25
+ <?php if( $this->isNewsletterEnabled() ): ?>
26
+ <div class="col-2">
27
+ <div class="box">
28
+ <div class="box-title">
29
+ <h3><?php echo $this->__('Newsletters') ?></h3>
30
+ <a href="<?php echo $this->getUrl('newsletter/manage') ?>"><?php echo $this->__('Edit') ?></a>
31
+ </div>
32
+ <div class="box-content">
33
+ <p>
34
+ <?php if( $isDefaultSubscribed ): ?>
35
+ <?php echo Mage::helper('crconnect')->__("You are currently subscribed to 'General Subscription'") ?><br>
36
+ <?php endif; ?>
37
+ <?php if( $isCustomSubscribed && $groupId > 1): ?>
38
+ <?php echo Mage::helper('crconnect')->__("You are currently subscribed to '%s Subscription'", $groupName) ?><br>
39
+ <?php endif; ?>
40
+ <?php if( !$isDefaultSubscribed && !$isCustomSubscribed ): ?>
41
+ <?php echo $this->__('You are currently not subscribed to any newsletter.') ?>
42
+ <?php endif; ?>
43
+ </p>
44
+ </div>
45
+ </div>
46
+ </div>
47
+ <?php endif; ?>
48
+ </div>
app/design/frontend/base/default/template/crconnect/customer/form/newsletter.phtml ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $groupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
3
+ $groupName = Mage::getModel('customer/group')->load($groupId)->getCode();
4
+ $isMultiply = Mage::helper("crconnect")->getGroupsIds($groupId);
5
+ ?>
6
+ <div class="page-title">
7
+ <h1><?php echo $this->__('Newsletter Subscription') ?></h1>
8
+ </div>
9
+ <?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
10
+ <?php echo $this->getChildHtml('form_before') ?>
11
+ <form action="<?php echo $this->getAction() ?>" method="post" id="form-validate">
12
+ <fieldset>
13
+ <?php echo $this->getBlockHtml('formkey') ?>
14
+ <ul class="form-list">
15
+ <?php if ($this->isDefaultGroupUser()) { ?>
16
+ <?php if (!Mage::helper('crconnect')->isShowDefaultGroup() || !$isMultiply) { ?>
17
+ <li class="control"><input type="checkbox" name="is_subscribed" id="subscription" value="1" title="<?php echo $this->__('General Subscription') ?>"<?php if ($this->isDefaultSubscribed()): ?> checked="checked"<?php endif; ?> class="checkbox" /><label for="subscription"><?php echo $this->__('General Subscription') ?></label></li>
18
+ <?php } ?>
19
+ <?php if ($isMultiply) { ?>
20
+ <li class="control"><input type="checkbox" name="is_gsubscribed" id="gsubscription" value="1" title="<?php echo $groupName ?> Abonnement"<?php if ($this->isCustomSubscribed()): ?> checked="checked"<?php endif; ?> class="checkbox" /><label for="gsubscription"><?php echo Mage::helper('crconnect')->__('%s Subscription', $groupName) ?> </label></li>
21
+ <?php } ?>
22
+ <?php }else { ?>
23
+ <li class="control"><input type="checkbox" name="is_subscribed" id="subscription" value="1" title="<?php echo $this->__('General Subscription') ?>"<?php if ($this->isDefaultSubscribed()): ?> checked="checked"<?php endif; ?> class="checkbox" /><label for="subscription"><?php echo $this->__('General Subscription') ?></label></li>
24
+ <?php } ?>
25
+ </ul>
26
+ <div class="buttons-set">
27
+ <p class="back-link"><a href="<?php echo $this->getBackUrl() ?>"><small>&laquo; </small><?php echo $this->__('Back') ?></a></p>
28
+ <button type="submit" title="<?php echo $this->__('Save') ?>" class="button"><span><span><?php echo $this->__('Save') ?></span></span></button>
29
+ </div>
30
+ </fieldset>
31
+ </form>
32
+ <script type="text/javascript">
33
+ //<![CDATA[
34
+ var dataForm = new VarienForm('form-validate', true);
35
+ //]]>
36
+ </script>
app/etc/modules/Conlabz_CrConnect.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Conlabz_CrConnect>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </Conlabz_CrConnect>
8
+ </modules>
9
+ </config>
app/locale/de_DE/Conlabz_CleverReach.csv ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "You are currently subscribed to 'General Subscription'","Sie sind momentan für das Abo 'Allgemeines' eingetragen."
2
+ "CleverReach Settings","CleverReach Einstellungen"
3
+ "The CleverReach plugin will synchronize all subscriptions and orders with your account.","Das CleverReach Plugin synchronisiert alle Abos und Bestellungen mit Ihrem Benutzerkonto."
4
+ "API Key","API Schlüssel"
5
+ "This can be found on your Listsettings page in CleverReach.","Dies können Sie auf auf der Seite mit den Listeneinstellungen in CleverReach finden."
6
+ "CleverReach Form ID","CleverReach Formular ID"
7
+ "Create new Form in your CleverReach backend, if you want to use Double Opt-in","Wenn Sie das Double-Opt-In-Verfahren verwenden möchten, erstellen Sie bitte ein neues Formular in Ihrem CleverReach Backend."
8
+ "Enable Douple Opt-in","Double-Opt-In aktivieren"
9
+ "General Subscribers List ID","ID der Generelle-Abonnenten-Liste"
10
+ "Enable Orders Tracking","Bestellungsverfolgung aktivieren"
11
+ "Sync sales with CleverReach. Required for ordertracking. Note: this will currently NOT work with the Multishipping Checkout","Verkäufe mit CleverReach synchronisieren. Notwendig für die Bestellungsverfolgung. Anmerkung: Im Moment funktioniert dieses Feature NICHT für Checkouts mit Mehrfachversand."
12
+ "Force order reactivation","Reaktivierung der Bestellung erzwingen"
13
+ "Separate customers by groups automatically","Kunden automatisch nach Gruppen aufteilen"
14
+ "During customers synchronization, they will be inserted in associated CleverReach groups lists","Während der Synchronisierung der Kundenliste werden die neuen Kunden automatisch in die angegebenen CleverReach-Gruppen Listen einsortiert"
15
+ "API keys for user groups","API Schlüssel für Nutzergruppen"
16
+ "Hide 'General' subscription for groups","Das 'Allgemein' Abo für Gruppen verstecken"
17
+ "If 'No' - then not 'General' user group users, will have possibility to subscribe for both: 'General' and '% Group' newsletter. If 'Yes' - just to '% Groups' newsletter","Bei 'Nein' - Nutzer, die nicht zur Nutzergruppe 'Allgemein' gehören, können sowohl den Newsletter 'Allgemein', als auch den Newsletter '% Gruppe' abonnieren. Bei 'Ja' - Nutzer können nur die entsprechenden '% Gruppe' Newsletter abonnieren"
18
+ "CleverReach Search Settings","CleverReach Einstellungen"
19
+ "Feed-URL","Feed-URL"
20
+ "Copy this Feed-URL to your CleverReach account. Store Id is optional parameter, add it in case, if you want use feed for other stores","Kopieren Sie diese Feed-URL in Ihren CleverReach-Account. Die Store ID ist optional. Fügen Sie diese hinzu, wenn Sie den Feed noch für andere Stores nutzen wollen"
21
+ "Password","Passwort"
22
+ "Create your own password for CleverReach feed","Erstellen Sie Ihr eigenes Passwort für den CleverReach-Feed"
23
+ "Magento user groups","Magento-Nutzergruppen"
24
+ "CleverReach Group","CleverReach-Gruppe"
25
+ "CleverReach Form","CleverReach-Formular"
26
+ "Add keys for group","Schlüssel für Gruppen hinzufügen"
27
+ "Newsletter Subscribers","Newsletter-Abonnenten"
28
+ "Magento subscribers list has been deactivated since deactivation will most likly happen in Cleverreach.","Die Abonnenten Liste in Magento wurde deaktiviert, da die Steuerung hauptsächlich in CleverReach erfolgen wird."
29
+ "Please use your Cleverreach account to activate/deactivate your subscribers.","Bitte verwenden Sie ihren CleverReach Acoount um Abonnenten zu aktivieren oder zu deaktivieren."
30
+ "CleverReach Connect general information","Allgemeine Informationen zu CleverReach Connect"
31
+ "CleverReach client ID","CleverReach Kunden ID"
32
+ "Name","Name"
33
+ "Company","Firma"
34
+ "E-Mail","E-Mail"
35
+ "Login","Anmelden"
36
+ "CleverReach Connect General list information","Information zu allgemeinen Liste in CleverReach Connect"
37
+ "List name","Listenname"
38
+ "Last mailing","Letztes Mailing"
39
+ "Active receivers","Aktive Empfänger"
40
+ "Inactive receivers","Inaktive Empfänger"
41
+ "Total receivers","Empfänger gesamt"
42
+ "Synchronize data with CleverReach","Daten mit CleverReach synchronisieren"
43
+ "Warning: Please wait untill the synchronization is finished. Depending on the amount of data this might take a while.","Warnung: Bitte warten Sie bis die Synchronisierung abgeschlossen ist. Je nach Datenmenge, kann dies einige Minuten dauern."
44
+ "Connection to Cleverreach Server failed","Verbindung mir dem CleverReach-Sever fehlgeschlagen"
45
+ "Your API key seems to be invalid. Please check it!","Ihr API Schlüssel scheint ungültig zu sein. Bitte überprüfen Sie ihn."
46
+ "Your list ID (%s) seem to be wrong. Please correct it!","Ihre Listen ID (%s) scheint falsch zu sein. Bitte berichtigen Sie die ID."
47
+ "Can not connect to CleverReach account. Please check your Cleverreach settings.","Verbindung zum CleverReach-Account nicht möglich. Bitte prüfen sie Ihre CleverReach Einstellungen."
48
+ "Never Sent","Nie versendet"
49
+ "Active Subscribers in Magento system","Aktive Abonnenten im Magento-System"
50
+ "Inactive Subscribers in Magento system","Inaktive Abonnenten im Magento-System"
51
+ "Synchronization successfull. %s users were transmitted.","Synchronisierung erfolgreich. %s Nutzer wurden übertragen."
52
+ "Error occured while synchronization process. Please try again later","Während der Synchronisierung ist ein Fehler aufgetreten. Bitte versuchen Sie es später noch einmal."
53
+ "Add new group","Neue Gruppe hinzufügen"
54
+ "Please select subscribers group","Bitte wählen sie die Abonnenten-Gruppe aus."
55
+ "Confirm key","Schlüssel bestätigen"
56
+ "Your list ID (%s) seem to be wrong. Please select other group!","Ihre Listen-ID (%s) scheint falsch zu sein. Bitte wählen Sie eine andere Gruppe aus."
57
+ "Please set your CleverReach user group in Extension settings section.","Bitte wählen Sie Ihre CleverReach Nutzergruppe in den Einstellungen der Extenion aus"
58
+ "This Email blocked or wrong","E-Mail Adresse falsch oder blockiert"
59
+ "This Email already in our database","Diese E-Mail Adresse ist bereits in unserer Datenbank vorhanden"
60
+ "Double Opt-In enabled, please select Form(s) and Group(s) for your Customer Groups","Double-Opt-In-Verfahren aktiviert. Bitte wählen Sie Formulare und Gruppen für Ihre Kundengruppen aus."
61
+ "Category","Kategorie"
62
+ "Product","ProduKt"
63
+ "No forms to select","Keine Formulare zur Auswahl"
64
+ "No groups to select","Keine Gruppen zur Auswahl"
65
+ "Error occured while synchronization process. Please try again later.","Während der Synchronisierung ist ein Fehler aufgetreten. Bitte versuchen Sie es später noch einmal."
66
+ "Confirmation request has been sent.","Bestätigungsanfrage wurde versendet."
67
+ "Thank you for your subscription.","Vielen Dank für Ihre Registrierung."
68
+ "Please select subscribers group","Bitte wählen sie die Abonnenten-Gruppe aus."
69
+ "Please select form","Bitte wählen sie das Formular aus"
70
+ "%s Subscription","%s Abonnement"
71
+ "You are currently subscribed to '%s Subscription'","Sie sind momentan für das Abo '%s' eingetragen."
72
+
73
+
74
+
75
+
76
+
77
+
app/locale/en_US/Conlabz_CleverReach.csv ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "CleverReach Settings","CleverReach Settings"
2
+ "The CleverReach plugin will synchronize all subscriptions and orders with your account.","The CleverReach plugin will synchronize all subscriptions and orders with your account."
3
+ "API Key","API Key"
4
+ "This can be found on your Listsettings page in CleverReach.","This can be found on your Listsettings page in CleverReach."
5
+ "CleverReach Form ID","CleverReach Form ID"
6
+ "Create new Form in your CleverReach backend, if you want to use Double Opt-in","Create new Form in your CleverReach backend, if you want to use Double Opt-in"
7
+ "Enable Douple Opi-in for registered customers","Enable Douple Opi-in for registered customers"
8
+ "General Subscribers List ID","General Subscribers List ID"
9
+ "Enable Orders Tracking","Enable Orders Tracking"
10
+ "Sync sales with CleverReach. Required for ordertracking. Note: this will currently NOT work with the Multishipping Checkout","Sync sales with CleverReach. Required for ordertracking. Note: this will currently NOT work with the Multishipping Checkout"
11
+ "Force order reactivation","Force order reactivation"
12
+ "Separate customers by groups automatically","Separate customers by groups automatically"
13
+ "During customers synchronization, they will be inserted in associated CleverReach groups lists","During customers synchronization, they will be inserted in associated CleverReach groups lists"
14
+ "API keys for user groups","API keys for user groups"
15
+ "Hide 'General' subscription for groups","Hide 'General' subscription for groups"
16
+ "If 'No' - then not 'General' user group users, will have possibility to subscribe for both: 'General' and '% Group' newsletter. If 'Yes' - just to '% Groups' newsletter","If 'No' - then not 'General' user group users, will have possibility to subscribe for both: 'General' and '% Group' newsletter. If 'Yes' - just to '% Groups' newsletter"
17
+ "CleverReach Search Settings","CleverReach Search Settings"
18
+ "Feed-URL","Feed-URL"
19
+ "Copy this Feed-URL to your CleverReach account. Store Id is optional parameter, add it in case, if you want use feed for other stores","Copy this Feed-URL to your CleverReach account. Store Id is optional parameter, add it in case, if you want use feed for other stores"
20
+ "Password","Password"
21
+ "Create your own password for CleverReach feed","Create your own password for CleverReach feed"
22
+ "Magento user groups","Magento user groups"
23
+ "CleverReach Group","CleverReach Group"
24
+ "CleverReach Form","CleverReach Form"
25
+ "Add keys for group","Add keys for group"
26
+ "Newsletter Subscribers","Newsletter Subscribers"
27
+ "Magento subscribers list has been deactivated since deactivation will most likly happen in Cleverreach.","Magento subscribers list has been deactivated since deactivation will most likly happen in Cleverreach."
28
+ "Please use your Cleverreach account to activate/deactivate your subscribers.","Please use your Cleverreach account to activate/deactivate your subscribers."
29
+ "CleverReach Connect general information","CleverReach Connect general information"
30
+ "CleverReach client ID","CleverReach client ID"
31
+ "Name","Name"
32
+ "Company","Company"
33
+ "E-Mail","E-Mail"
34
+ "Login","Login"
35
+ "CleverReach Connect General list information","CleverReach Connect General list information"
36
+ "List name","List name"
37
+ "Last mailing","Last mailing"
38
+ "Active receivers","Active receivers"
39
+ "Inactive receivers","Inactive receivers"
40
+ "Total receivers","Total receivers"
41
+ "Synchronize data with CleverReach","Synchronize data with CleverReach"
42
+ "Warning: Please wait untill the synchronization is finished. Depending on the amount of data this might take a while.","Warning: Please wait untill the synchronization is finished. Depending on the amount of data this might take a while."
43
+ "Connection to Cleverreach Server failed","Connection to Cleverreach Server failed"
44
+ "Your API key seems to be invalid. Please check it!","Your API key seems to be invalid. Please check it!"
45
+ "Your list ID (%s) seem to be wrong. Please correct it!","Your list ID (%s) seem to be wrong. Please correct it!"
46
+ "Can not connect to CleverReach account. Please check your Cleverreach settings.","Can not connect to CleverReach account. Please check your Cleverreach settings."
47
+ "Never Sent","Never Sent"
48
+ "Active Subscribers in Magento system","Active Subscribers in Magento system"
49
+ "Inactive Subscribers in Magento system","Inactive Subscribers in Magento system"
50
+ "Synchronization successfull. %s users were transmitted.","Synchronization successfull. %s users were transmitted."
51
+ "Error occured while synchronization process. Please try again later","Error occured while synchronization process. Please try again later"
52
+ "Add new group","Add new group"
53
+ "Please select subscribers group","Please select subscribers group"
54
+ "Confirm key","Confirm key"
55
+ "Your list ID (%s) seem to be wrong. Please select other group!","Your list ID (%s) seem to be wrong. Please select other group!"
56
+ "Please set your CleverReach user group in Extension settings section.","Please set your CleverReach user group in Extension settings section."
57
+ "This Email blocked or wrong","This Email blocked or wrong"
58
+ "This Email already in our database","This Email already in our database"
59
+ "Double Opt-In enabled, please select Form(s) and Group(s) for your Customer Groups","Double Opt-In enabled, please select Form(s) and Group(s) for your Customer Groups"
60
+ "Category","Category"
61
+ "Product","Product"
62
+ "No forms to select","No forms to select"
63
+ "No groups to select","No group to select"
64
+ "Error occured while synchronization process. Please try again later.","Error occured while synchronization process. Please try again later."
65
+ "Confirmation request has been sent.","Confirmation request has been sent."
66
+ "Thank you for your subscription.","Thank you for your subscription."
67
+ "Please select subscribers group","Please select subscribers group"
68
+ "Please select form","Please select form"
69
+ "%s Subscription","%s Subscription"
70
+
71
+
72
+
73
+
74
+
package.xml ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Conlabz_CrConnect</name>
4
+ <version>3.0.0</version>
5
+ <stability>stable</stability>
6
+ <license>GNU General Public License</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Synchronizes your Magento subscribers, customers and sales with CleverReach Email Marketing Software.</summary>
10
+ <description>CleverReach Connect extension offers synchronization of your Magento newsletter subscribers and customers (imported from your orders if you like) with the CleverReach subscription groups.&#xD;
11
+ &#xD;
12
+ CleverReach email marketing tool (http://www.cleverreach.de) allows you to create professional emails online, dispatch them reliably, track their success and manage receivers.&#xD;
13
+ &#xD;
14
+ CleverReach is equipped with a particularly user-friendly interface, which is used intuitively and without special knowledge.&#xD;
15
+ &#xD;
16
+ To setup the synchronization, all you need is your CleverReach API key and the respective group's List ID which both can be found in your CleverReach account. Go to "Empf&#xE4;nger &gt; *GRUPPENNAME* &gt; "Einstellungen" &gt; "API Key").&#xD;
17
+ &#xD;
18
+ Once set up, the Extension will handle subscriptions and unsubscribe requests. Users can unsubscribe themselves in Magento or in CleverReach. CleverReach Connect will track users who have followed the links in your email campaign. When a user completes a purchase, the plugin will quietly send the basic details of the order back to your reporting dashboard in the CleverReach tool. Thus you will be able to analyse conversions which originated from your mailings.&#xD;
19
+ &#xD;
20
+ Please note that subscribers imported form an order won't have the "receive newsletter" flag set to 1.</description>
21
+ <notes>New 3.0.0 version</notes>
22
+ <authors><author><name>conlabz GmbH</name><user>conlabz</user><email>info@conlabz.de</email></author></authors>
23
+ <date>2014-08-08</date>
24
+ <time>12:47:24</time>
25
+ <contents><target name="magecommunity"><dir name="Conlabz"><dir name="CrConnect"><dir name="Block"><dir name="Adminhtml"><dir name="Customer"><dir name="Edit"><dir name="Tab"><file name="Newsletter.php" hash="0354815224028e6fc90671a61abb2232"/></dir></dir></dir><dir name="Newsletter"><file name="Subscriber.php" hash="9eaf627b6255229e1861208dd1b9a280"/></dir></dir><dir name="Config"><file name="GroupsApis.php" hash="6ecac377484995a89c7718a015f74a89"/><file name="Key.php" hash="42f31c0d35632948a702106540d5e85b"/><file name="Url.php" hash="f330f299b19ed1b266ec6a3eb5d31fa1"/></dir><dir name="Customer"><file name="Newsletter.php" hash="f645682ece7817b4386538026fa580dc"/></dir><file name="Groupsapis.php" hash="cecd60a67b2e72effd2bc7ac1e1fdc58"/></dir><dir name="Helper"><file name="Data.php" hash="293591f9f29cf83d777454c4f0eed40e"/></dir><dir name="Model"><file name="Api.php" hash="081ceb06ae487bdd87976e0c0d256697"/><dir name="Checkout"><file name="Observer.php" hash="cf99d26d4d85c3106d480b035b98287f"/></dir><dir name="Customer"><file name="Observer.php" hash="6dd8ed2fc9c3dd0e5a2771fb1857ec81"/></dir><dir name="Newsletter"><file name="Subscriber.php" hash="51cb181afbd60baaadd5ed4385497763"/></dir><file name="Observer.php" hash="e133718d99e3a1cff0e87ef1014f22ca"/><file name="Search.php" hash="e2bcaa4e316d028141075cbd0c964e67"/><file name="Subscriber.php" hash="8de289c183682e8ca378a9079698b926"/><dir name="System"><dir name="Config"><dir name="Source"><file name="EmptyForms.php" hash="feb6f16d6b26e0cdaedb06bc68ce1c63"/><file name="EmptyList.php" hash="8f3f19184a183b1f5dce98d70608bcb1"/></dir></dir></dir><dir name="Website"><file name="Observer.php" hash="db48be43fed458ed4169771a55cf2288"/></dir></dir><dir name="controllers"><file name="AccountController.php" hash="009b2b88f4d9a5daeb050ce617d677b6"/><dir name="Adminhtml"><file name="ConfigController.php" hash="d5a14810dea4a39e593f963119fca26e"/><file name="CrconnectController.php" hash="07e1950ceb80342fc006ea00db084596"/></dir><file name="HookController.php" hash="3235db4d5ecf422ff9d58771af94fca5"/><file name="ManageController.php" hash="739fdf9934ca2665b9ffdf43edbef733"/><file name="SearchController.php" hash="2f7947cf6774a6874c815f71d3468152"/><file name="SubscriberController.php" hash="9cd8eb59c885b6f0b9133c0a1271bbe9"/><file name="UnsubscribeController.php" hash="357908ed531f29de19b7ddbb549ed4e4"/></dir><dir name="etc"><file name="adminhtml.xml" hash="00bab70876fc5def3883b74cb1da413c"/><file name="config.xml" hash="58706277640c74b3bbca05e2eee0ff56"/><file name="system.xml" hash="9f5c8170faedd86fcc35df4be9dc93b9"/></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="crconnect"><dir name="config"><file name="header.phtml" hash="727bc6a2a9b67c1e5819faa91c06ffd3"/></dir><dir name="newsletter"><dir name="subscriber"><file name="list.phtml" hash="94952fb1921397c4ad33387d8387c463"/></dir></dir><dir name="system"><dir name="config"><dir name="form"><dir name="field"><file name="array_groups.phtml" hash="ac84db9b1e8b342337a478ecba62e0b1"/><file name="cr_array_groups.phtml" hash="d2f70aa406d8b15f819481acbf0ccbee"/></dir></dir></dir></dir></dir></dir><dir name="layout"><file name="crconnect.xml" hash="94b7574794fc03c3eda297fa4fb13542"/></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="crconnect.xml" hash="956fea6e3eb0e98fc6bbcc7241f9123e"/></dir><dir name="template"><dir name="crconnect"><dir name="customer"><dir name="account"><dir name="dashboard"><file name="info.phtml" hash="a533451e27b90284d3414e391b460231"/></dir></dir><dir name="form"><file name="newsletter.phtml" hash="4a1309d0d6d2587c8534dd4a1ccdf235"/></dir></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Conlabz_CrConnect.xml" hash="282358cc102bf617b7d5afcaa47ec489"/></dir></target><target name="magelocale"><dir name="de_DE"><file name="Conlabz_CleverReach.csv" hash="e4a47ba5f56a39548280773392944f4d"/></dir><dir name="en_US"><file name="Conlabz_CleverReach.csv" hash="7d6b2f9b03bcba2abf2c5eacdd2192e1"/></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="base"><dir name="default"><dir name="images"><dir name="cleverreach"><file name="cleverreach-logo.png" hash="bff60f831ca9e1dc9bcbdb2e3f5a5805"/></dir></dir><dir name="js"><file name="crconnect.js" hash="72c951b0b46862253c7159255d82b2e0"/></dir></dir></dir></dir></target><target name="mage"><dir name="."><file name="CleverReachDocumentation.docx" hash="571866f1b26b6c1ba5881644b2ecf9db"/><file name="CleverReachDocumentationGerman.docx" hash="ed975c640c6fd92115505f0790ba6231"/></dir></target></contents>
26
+ <compatible/>
27
+ <dependencies><required><php><min>5.2.13</min><max>5.4.0</max></php></required></dependencies>
28
+ </package>
skin/adminhtml/base/default/images/cleverreach/cleverreach-logo.png ADDED
Binary file
skin/adminhtml/base/default/js/crconnect.js ADDED
@@ -0,0 +1,221 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Crconnect = Class.create();
2
+ Crconnect.prototype = {
3
+ initialize: function() {
4
+
5
+
6
+ },
7
+ confirmMainKey: function(manual) {
8
+
9
+ var key = $("crroot_crconnect_api_key").value;
10
+
11
+ if (manual){
12
+ $$(".simple-added-row").each(function(el){
13
+ callRowDelete(el.id);
14
+ savedDefaultListId = false;
15
+ savedDefaultFormId = false;
16
+ });
17
+ }
18
+
19
+ if (key){
20
+ var url = baseConfirmKeyUrl + 'key/' + key;
21
+ new Ajax.Request(url, {
22
+ method: 'post',
23
+ onSuccess: function(transport) {
24
+
25
+ var select = $('crroot_crconnect_list_id');
26
+ Crconnect.cleanSelect('crroot_crconnect_list_id');
27
+
28
+ // If no results come, revert all group and form selects to default states
29
+ if (transport.responseText == "empty"){
30
+ Crconnect.resetGroupList();
31
+ Crconnect.resetFormList();
32
+ // Reload block with keys
33
+ Crconnect.reloadKeysBlock();
34
+ Crconnect.confirmDisable();
35
+ return false;
36
+ }
37
+
38
+ // Fill Main groups select with groups list
39
+ var editData = transport.responseText.evalJSON(true);
40
+ Crconnect.reloadKeysBlock(editData);
41
+ select.insert(new Element('option', {value: ''}).update(crconnectLang['please:select:group']));
42
+ for (var i = 0; i < editData.length; i++){
43
+ select.insert(new Element('option', {value: editData[i].id}).update(editData[i].name));
44
+ }
45
+
46
+ if (savedDefaultListId){
47
+ select.value = savedDefaultListId;
48
+ savedDefaultListId = false;
49
+ }
50
+ Crconnect.changeGroupId();
51
+
52
+
53
+ }
54
+ });
55
+ }else{
56
+ Crconnect.resetGroupList();
57
+ }
58
+ Crconnect.confirmDisable();
59
+
60
+ },
61
+ reloadKeysBlock: function(editData){
62
+
63
+ var select = '<select class="crconnect-groups-select" onchange="Crconnect.changeSubGroup(this)" id="#{_id}_crconnect" name="groups[crconnect][fields][groups_keys][value][#{_id}][crconnect]">';
64
+ select += '<option value="">'+crconnectLang['please:select:group']+'</option>';
65
+ if (editData){
66
+ for (var i = 0; i < editData.length; i++){
67
+ select += '<option value="'+editData[i].id+'">'+editData[i].name+'</option>';
68
+ }
69
+ }
70
+ stringElements['crconnect'] = select + '</select>';
71
+ initRowTemplate();
72
+
73
+ },
74
+ changeGroupId: function(){
75
+
76
+ var groupId = $("crroot_crconnect_list_id").value;
77
+ var key = $("crroot_crconnect_api_key").value;
78
+
79
+ if (key && groupId){
80
+ var url = baseChangeGroupUrl + 'group/' + groupId + '/key/' + key;
81
+ new Ajax.Request(url, {
82
+ method: 'post',
83
+ onSuccess: function(transport) {
84
+
85
+ var select = $('crroot_crconnect_form_id');
86
+
87
+ Crconnect.cleanSelect('crroot_crconnect_form_id');
88
+ if (transport.responseText == "empty"){
89
+ Crconnect.resetFormList();
90
+ return false;
91
+ }
92
+ var editData = transport.responseText.evalJSON(true);
93
+ select.insert(new Element('option', {value: ''}).update(crconnectLang['please:select:form']));
94
+ for (var i = 0; i < editData.length; i++){
95
+ select.insert(new Element('option', {value: editData[i].id}).update(editData[i].name));
96
+ }
97
+
98
+ if (savedDefaultFormId){
99
+ select.value = savedDefaultFormId;
100
+ savedDefaultFormId = false;
101
+ }
102
+
103
+ }
104
+ });
105
+ }else{
106
+ Crconnect.resetFormList();
107
+ }
108
+ },
109
+ changeSubGroup: function(element){
110
+
111
+ var selectedValue = element.value;
112
+ var id = element.id;
113
+ id = id.replace("_crconnect", "");
114
+
115
+ var key = $("crroot_crconnect_api_key").value;
116
+ var url = baseChangeGroupUrl + 'group/' + selectedValue + '/key/' + key;
117
+
118
+ new Ajax.Request(url, {
119
+ method: 'post',
120
+ onSuccess: function(transport) {
121
+
122
+ var select = $(id+'_formid');
123
+
124
+ Crconnect.cleanSelect(id+'_formid');
125
+ if (transport.responseText == "empty"){
126
+ Crconnect.resetFormList(id+'_formid');
127
+ return false;
128
+ }
129
+ var editData = transport.responseText.evalJSON(true);
130
+ select.insert(new Element('option', {value: ''}).update(crconnectLang['please:select:form']));
131
+ for (var i = 0; i < editData.length; i++){
132
+ select.insert(new Element('option', {value: editData[i].id}).update(editData[i].name));
133
+ }
134
+
135
+ if (savedFormsKeys){
136
+
137
+ if (savedFormsKeys[id]){
138
+ select.value = savedFormsKeys[id];
139
+ }
140
+
141
+ }
142
+ // if (savedDefaultFormId){
143
+ // select.value = savedDefaultFormId;
144
+ // savedDefaultFormId = false;
145
+ // }
146
+
147
+ }
148
+ });
149
+
150
+ // console.log(id);
151
+
152
+
153
+ },
154
+ confirmEnable: function(){
155
+
156
+ $("confirm-key-button").removeClassName('disabled');
157
+ $("confirm-key-button").disabled = false;
158
+
159
+ },
160
+ confirmDisable: function(){
161
+
162
+ $("confirm-key-button").addClassName('disabled');
163
+ $("confirm-key-button").disabled = true;
164
+
165
+ },
166
+ resetFormList: function(formId){
167
+
168
+ if (!formId){
169
+ formId = 'crroot_crconnect_form_id';
170
+ }
171
+ Crconnect.cleanSelect(formId);
172
+ $(formId).insert(new Element('option', {value: ''}).update(crconnectLang['please:select:form:default']));
173
+
174
+ },
175
+ resetGroupList: function(formId){
176
+
177
+ if (!formId){
178
+ formId = 'crroot_crconnect_list_id';
179
+ }
180
+
181
+ Crconnect.cleanSelect(formId);
182
+ $(formId).insert(new Element('option', {value: ''}).update(crconnectLang['please:select:group:default']));
183
+
184
+ },
185
+ cleanSelect: function (selectId){
186
+
187
+ var options = $$('select#'+selectId+' option');
188
+ var select = $(selectId);
189
+ for (var i = 0; i < options.length; i++) {
190
+ options[i].remove();
191
+ }
192
+
193
+ },
194
+ fillSelectedGroups: function(){
195
+
196
+ if (typeof editedSelects != "undefined"){
197
+ if (editedSelects.length > 0){
198
+ for (var i = 0; i < editedSelects.length; i++){
199
+ Crconnect.changeSubGroup($(editedSelects[i]+"_crconnect"));
200
+ }
201
+ }
202
+ }
203
+
204
+ }
205
+
206
+ }
207
+ Crconnect = new Crconnect();
208
+
209
+ function initCleverReach(){
210
+
211
+ try{
212
+ Crconnect.confirmMainKey();
213
+ Event.observe('crroot_crconnect_list_id', 'change', Crconnect.changeGroupId);
214
+ Event.observe('crroot_crconnect_api_key', 'keyup', Crconnect.confirmEnable);
215
+ Crconnect.fillSelectedGroups();
216
+ }catch(e){
217
+
218
+ }
219
+
220
+ }
221
+ Event.observe(window, 'load', initCleverReach);