Campaigner_Integration - Version 1.0.1

Version Notes

Campaigner Integration for Magento

Download this release

Release Info

Developer Magento Core Team
Extension Campaigner_Integration
Version 1.0.1
Comparing to
See all releases


Version 1.0.1

Files changed (161) hide show
  1. app/code/community/Campaigner/Integration/Block/Adminhtml/Abandoned.php +71 -0
  2. app/code/community/Campaigner/Integration/Block/Adminhtml/Abandoned/Details.php +78 -0
  3. app/code/community/Campaigner/Integration/Block/Adminhtml/Abandoned/Details/Form.php +10 -0
  4. app/code/community/Campaigner/Integration/Block/Adminhtml/Abandoned/Details/Tab/Cart.php +37 -0
  5. app/code/community/Campaigner/Integration/Block/Adminhtml/Abandoned/Details/Tab/Diagnostics.php +90 -0
  6. app/code/community/Campaigner/Integration/Block/Adminhtml/Abandoned/Details/Tab/Diagnostics/Status.php +45 -0
  7. app/code/community/Campaigner/Integration/Block/Adminhtml/Abandoned/Grid.php +269 -0
  8. app/code/community/Campaigner/Integration/Block/Adminhtml/Abandoned/Status.php +9 -0
  9. app/code/community/Campaigner/Integration/Block/Adminhtml/Abandoned/Tabs.php +29 -0
  10. app/code/community/Campaigner/Integration/Block/Adminhtml/Diagnostics/Status/Abstract.php +22 -0
  11. app/code/community/Campaigner/Integration/Block/Adminhtml/Latest.php +63 -0
  12. app/code/community/Campaigner/Integration/Block/Adminhtml/Latest/Grid.php +248 -0
  13. app/code/community/Campaigner/Integration/Block/Adminhtml/Latest/Status.php +9 -0
  14. app/code/community/Campaigner/Integration/Block/Adminhtml/System/Config/Fieldset/Hint.php +39 -0
  15. app/code/community/Campaigner/Integration/Block/Adminhtml/System/Config/Form/Field/Addressmapfields.php +21 -0
  16. app/code/community/Campaigner/Integration/Block/Adminhtml/System/Config/Form/Field/Api.php +30 -0
  17. app/code/community/Campaigner/Integration/Block/Adminhtml/System/Config/Form/Field/Common.php +72 -0
  18. app/code/community/Campaigner/Integration/Block/Adminhtml/System/Config/Form/Field/Diagnostics.php +26 -0
  19. app/code/community/Campaigner/Integration/Block/Adminhtml/System/Config/Form/Field/Info.php +26 -0
  20. app/code/community/Campaigner/Integration/Block/Adminhtml/System/Config/Form/Field/Logging.php +117 -0
  21. app/code/community/Campaigner/Integration/Block/Adminhtml/System/Config/Form/Field/Mapfields.php +21 -0
  22. app/code/community/Campaigner/Integration/Block/Adminhtml/System/Config/Form/Field/Note.php +20 -0
  23. app/code/community/Campaigner/Integration/Block/Adminhtml/System/Config/Form/Field/Shippingmapfields.php +24 -0
  24. app/code/community/Campaigner/Integration/Block/Adminhtml/System/Config/Form/Field/Signup/Test.php +28 -0
  25. app/code/community/Campaigner/Integration/Block/Adminhtml/System/Config/Form/Field/Smtp.php +21 -0
  26. app/code/community/Campaigner/Integration/Block/Adminhtml/System/Config/Form/Field/Smtp/Server.php +13 -0
  27. app/code/community/Campaigner/Integration/Block/Adminhtml/System/Config/Form/Field/Smtp/Test.php +20 -0
  28. app/code/community/Campaigner/Integration/Block/Adminhtml/Troubleshooting/Status.php +9 -0
  29. app/code/community/Campaigner/Integration/Block/Adminhtml/Troubleshooting/Tabs.php +29 -0
  30. app/code/community/Campaigner/Integration/Block/Adminhtml/Troubleshooting/View.php +40 -0
  31. app/code/community/Campaigner/Integration/Block/Adminhtml/Troubleshooting/View/Form.php +10 -0
  32. app/code/community/Campaigner/Integration/Block/Adminhtml/Troubleshooting/View/Tab/Download.php +43 -0
  33. app/code/community/Campaigner/Integration/Block/Adminhtml/Troubleshooting/View/Tab/Help.php +73 -0
  34. app/code/community/Campaigner/Integration/Block/Adminhtml/Troubleshooting/View/Tab/Info.php +42 -0
  35. app/code/community/Campaigner/Integration/Block/Adminhtml/Troubleshooting/View/Tab/Log.php +38 -0
  36. app/code/community/Campaigner/Integration/Block/Adminhtml/Troubleshooting/View/Tab/Settings.php +60 -0
  37. app/code/community/Campaigner/Integration/Block/Adminhtml/Troubleshooting/View/Tab/Submit.php +57 -0
  38. app/code/community/Campaigner/Integration/Block/Capture.php +45 -0
  39. app/code/community/Campaigner/Integration/Block/Checkout/Subscribe.php +27 -0
  40. app/code/community/Campaigner/Integration/Block/Customer/Account/Lists.php +21 -0
  41. app/code/community/Campaigner/Integration/Block/Signup.php +34 -0
  42. app/code/community/Campaigner/Integration/Block/Widget/Grid/Column/Renderer/Abandoned/Minutes.php +25 -0
  43. app/code/community/Campaigner/Integration/Block/Widget/Grid/Column/Renderer/Action.php +38 -0
  44. app/code/community/Campaigner/Integration/Controller/Front/Abstract.php +35 -0
  45. app/code/community/Campaigner/Integration/Helper/Abandoned.php +167 -0
  46. app/code/community/Campaigner/Integration/Helper/Data.php +1061 -0
  47. app/code/community/Campaigner/Integration/Helper/Diagnostic.php +59 -0
  48. app/code/community/Campaigner/Integration/Helper/Email.php +44 -0
  49. app/code/community/Campaigner/Integration/Helper/Fields.php +224 -0
  50. app/code/community/Campaigner/Integration/Helper/Order.php +662 -0
  51. app/code/community/Campaigner/Integration/Helper/Troubleshooting.php +767 -0
  52. app/code/community/Campaigner/Integration/Model/Abandoned.php +44 -0
  53. app/code/community/Campaigner/Integration/Model/Abandoned/Observer.php +332 -0
  54. app/code/community/Campaigner/Integration/Model/Action/List.php +40 -0
  55. app/code/community/Campaigner/Integration/Model/Action/Observer.php +18 -0
  56. app/code/community/Campaigner/Integration/Model/Configuration/Observer.php +54 -0
  57. app/code/community/Campaigner/Integration/Model/Customer/Observer.php +270 -0
  58. app/code/community/Campaigner/Integration/Model/Email/Queue.php +91 -0
  59. app/code/community/Campaigner/Integration/Model/Email/Template.php +112 -0
  60. app/code/community/Campaigner/Integration/Model/Latest/Order.php +59 -0
  61. app/code/community/Campaigner/Integration/Model/Mysql4/Abandoned.php +27 -0
  62. app/code/community/Campaigner/Integration/Model/Mysql4/Abandoned/Collection.php +119 -0
  63. app/code/community/Campaigner/Integration/Model/Mysql4/Action/List.php +30 -0
  64. app/code/community/Campaigner/Integration/Model/Mysql4/Action/List/Collection.php +17 -0
  65. app/code/community/Campaigner/Integration/Model/Mysql4/Latest/Order.php +28 -0
  66. app/code/community/Campaigner/Integration/Model/Mysql4/Latest/Order/Collection.php +111 -0
  67. app/code/community/Campaigner/Integration/Model/Mysql4/Order.php +27 -0
  68. app/code/community/Campaigner/Integration/Model/Mysql4/Order/Collection.php +83 -0
  69. app/code/community/Campaigner/Integration/Model/Mysql4/Session.php +27 -0
  70. app/code/community/Campaigner/Integration/Model/Mysql4/Session/Collection.php +15 -0
  71. app/code/community/Campaigner/Integration/Model/Newsletter/Observer.php +224 -0
  72. app/code/community/Campaigner/Integration/Model/Observer.php +39 -0
  73. app/code/community/Campaigner/Integration/Model/Observer/Abstract.php +34 -0
  74. app/code/community/Campaigner/Integration/Model/Order.php +45 -0
  75. app/code/community/Campaigner/Integration/Model/Order/Observer.php +328 -0
  76. app/code/community/Campaigner/Integration/Model/Resource/Setup.php +45 -0
  77. app/code/community/Campaigner/Integration/Model/Session.php +66 -0
  78. app/code/community/Campaigner/Integration/Model/System/Config/Source/Abandonedlist.php +29 -0
  79. app/code/community/Campaigner/Integration/Model/System/Config/Source/Additionallist.php +23 -0
  80. app/code/community/Campaigner/Integration/Model/System/Config/Source/Checkoutsubscribe.php +15 -0
  81. app/code/community/Campaigner/Integration/Model/System/Config/Source/List.php +21 -0
  82. app/code/community/Campaigner/Integration/Model/System/Config/Source/Send/Field.php +14 -0
  83. app/code/community/Campaigner/Integration/Model/System/Config/Source/Sequence.php +21 -0
  84. app/code/community/Campaigner/Integration/Model/System/Config/Source/Signup/Opacity.php +16 -0
  85. app/code/community/Campaigner/Integration/Model/System/Config/Source/Signup/Recurrence.php +16 -0
  86. app/code/community/Campaigner/Integration/Model/System/Config/Source/Smtp/Encryption.php +15 -0
  87. app/code/community/Campaigner/Integration/Model/System/Config/Source/States.php +39 -0
  88. app/code/community/Campaigner/Integration/Model/System/Config/Source/Statuses.php +20 -0
  89. app/code/community/Campaigner/Integration/Model/System/Config/Source/Store.php +29 -0
  90. app/code/community/Campaigner/Integration/Model/System/Config/Source/Time.php +15 -0
  91. app/code/community/Campaigner/Integration/Model/Wrapper/Abandoned.php +27 -0
  92. app/code/community/Campaigner/Integration/Model/Wrapper/Abstract.php +138 -0
  93. app/code/community/Campaigner/Integration/Model/Wrapper/Database.php +75 -0
  94. app/code/community/Campaigner/Integration/Model/Wrapper/Exception.php +135 -0
  95. app/code/community/Campaigner/Integration/Model/Wrapper/Execute.php +203 -0
  96. app/code/community/Campaigner/Integration/Model/Wrapper/Lists.php +37 -0
  97. app/code/community/Campaigner/Integration/Model/Wrapper/Orders.php +38 -0
  98. app/code/community/Campaigner/Integration/Model/Wrapper/Subscribers.php +204 -0
  99. app/code/community/Campaigner/Integration/Model/Wrapper/Wishlist.php +30 -0
  100. app/code/community/Campaigner/Integration/controllers/AbandonedController.php +270 -0
  101. app/code/community/Campaigner/Integration/controllers/Admin/AbandonedController.php +109 -0
  102. app/code/community/Campaigner/Integration/controllers/Admin/DiagnosticController.php +452 -0
  103. app/code/community/Campaigner/Integration/controllers/Admin/LatestController.php +109 -0
  104. app/code/community/Campaigner/Integration/controllers/Admin/TroubleshootingController.php +300 -0
  105. app/code/community/Campaigner/Integration/controllers/CaptureController.php +26 -0
  106. app/code/community/Campaigner/Integration/controllers/Customer/AccountController.php +106 -0
  107. app/code/community/Campaigner/Integration/controllers/SignupController.php +98 -0
  108. app/code/community/Campaigner/Integration/etc/adminhtml.xml +59 -0
  109. app/code/community/Campaigner/Integration/etc/config.xml +351 -0
  110. app/code/community/Campaigner/Integration/etc/system.xml +548 -0
  111. app/code/community/Campaigner/Integration/sql/campaigner_setup/mysql4-install-1.0.0.php +61 -0
  112. app/design/adminhtml/default/default/layout/campaigner.xml +104 -0
  113. app/design/adminhtml/default/default/template/campaigner/abandoned/details.phtml +15 -0
  114. app/design/adminhtml/default/default/template/campaigner/abandoned/details/form.phtml +1 -0
  115. app/design/adminhtml/default/default/template/campaigner/abandoned/details/tab/cart.phtml +62 -0
  116. app/design/adminhtml/default/default/template/campaigner/abandoned/details/tab/diagnostics/status.phtml +52 -0
  117. app/design/adminhtml/default/default/template/campaigner/abandoned/status.phtml +18 -0
  118. app/design/adminhtml/default/default/template/campaigner/diagnostics.phtml +242 -0
  119. app/design/adminhtml/default/default/template/campaigner/latest/status.phtml +18 -0
  120. app/design/adminhtml/default/default/template/campaigner/order/view/tab/diagnostics/status.phtml +78 -0
  121. app/design/adminhtml/default/default/template/campaigner/system/config/fieldset/hint.phtml +54 -0
  122. app/design/adminhtml/default/default/template/campaigner/system/config/form/field/api.phtml +63 -0
  123. app/design/adminhtml/default/default/template/campaigner/system/config/form/field/array.phtml +170 -0
  124. app/design/adminhtml/default/default/template/campaigner/system/config/form/field/diagnostics.phtml +20 -0
  125. app/design/adminhtml/default/default/template/campaigner/system/config/form/field/export/date_range.phtml +144 -0
  126. app/design/adminhtml/default/default/template/campaigner/system/config/form/field/export/orders.phtml +20 -0
  127. app/design/adminhtml/default/default/template/campaigner/system/config/form/field/export/products.phtml +21 -0
  128. app/design/adminhtml/default/default/template/campaigner/system/config/form/field/info.phtml +12 -0
  129. app/design/adminhtml/default/default/template/campaigner/system/config/form/field/logging.phtml +30 -0
  130. app/design/adminhtml/default/default/template/campaigner/system/config/form/field/note.phtml +4 -0
  131. app/design/adminhtml/default/default/template/campaigner/system/config/form/field/signup/test.phtml +26 -0
  132. app/design/adminhtml/default/default/template/campaigner/system/config/form/field/smtp.phtml +34 -0
  133. app/design/adminhtml/default/default/template/campaigner/system/config/form/field/smtp/test.phtml +106 -0
  134. app/design/adminhtml/default/default/template/campaigner/system/config/setup_check.phtml +29 -0
  135. app/design/adminhtml/default/default/template/campaigner/system/convert/profile/export.phtml +221 -0
  136. app/design/adminhtml/default/default/template/campaigner/troubleshooting/status.phtml +199 -0
  137. app/design/adminhtml/default/default/template/campaigner/troubleshooting/view.phtml +16 -0
  138. app/design/adminhtml/default/default/template/campaigner/troubleshooting/view/form.phtml +1 -0
  139. app/design/adminhtml/default/default/template/campaigner/troubleshooting/view/tab/download.phtml +12 -0
  140. app/design/adminhtml/default/default/template/campaigner/troubleshooting/view/tab/help.phtml +142 -0
  141. app/design/adminhtml/default/default/template/campaigner/troubleshooting/view/tab/info.phtml +63 -0
  142. app/design/adminhtml/default/default/template/campaigner/troubleshooting/view/tab/log.phtml +74 -0
  143. app/design/adminhtml/default/default/template/campaigner/troubleshooting/view/tab/settings.phtml +218 -0
  144. app/design/adminhtml/default/default/template/campaigner/troubleshooting/view/tab/submit.phtml +57 -0
  145. app/design/frontend/base/default/layout/campaigner.xml +52 -0
  146. app/design/frontend/base/default/template/campaigner/capture/email.phtml +13 -0
  147. app/design/frontend/base/default/template/campaigner/checkout/subscribe.phtml +32 -0
  148. app/design/frontend/base/default/template/campaigner/customer/account/dashboard/info.phtml +59 -0
  149. app/design/frontend/base/default/template/campaigner/customer/account/lists.phtml +36 -0
  150. app/design/frontend/base/default/template/campaigner/signup/form.phtml +56 -0
  151. app/etc/modules/Campaigner_Integration.xml +11 -0
  152. app/locale/en_US/template/email/campaigner_relay_test.html +31 -0
  153. app/locale/en_US/template/email/newsletter_subscr_success_campaigner.html +3 -0
  154. app/locale/en_US/template/email/newsletter_unsub_success_campaigner.html +2 -0
  155. package.xml +18 -0
  156. skin/adminhtml/default/default/campaigner/campaigner-tab.png +0 -0
  157. skin/adminhtml/default/default/campaigner/campaigner.css +157 -0
  158. skin/adminhtml/default/default/campaigner/logo.png +0 -0
  159. skin/frontend/base/default/campaigner/campaigner.css +57 -0
  160. skin/frontend/base/default/campaigner/images/window_close.png +0 -0
  161. skin/frontend/base/default/campaigner/integration.js +18 -0
app/code/community/Campaigner/Integration/Block/Adminhtml/Abandoned.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Adminhtml_Abandoned extends Mage_Adminhtml_Block_Widget_Grid_Container
4
+ {
5
+ public function __construct()
6
+ {
7
+ $this->_controller = 'adminhtml_abandoned';
8
+ $this->_blockGroup = 'campaigner';
9
+
10
+ $status = Mage::helper('campaigner')->getAbandonedStatus();
11
+
12
+ if ($status['enabled']) {
13
+
14
+ $this->_headerText = "Abandoned Carts - Cron Last Run: " . Mage::helper('campaigner')->getCronLastRunHtml();
15
+
16
+ $label = 'Run now on all stores';
17
+
18
+ if (Mage::app()->isSingleStoreMode()) {
19
+ $label = 'Run now';
20
+ }
21
+
22
+ $this->addButton('refresh', array(
23
+ 'label' => Mage::helper('campaigner')->__('Refresh'),
24
+ 'onclick' => 'abandonedGridJsObject.reload();return false;',
25
+ ));
26
+
27
+ $this->_addButton('run_now', array(
28
+ 'label' => Mage::helper('campaigner')->__($label),
29
+ 'onclick' => 'setLocation(\'' . $this->getUrl('*/*/run') .'\')',
30
+ ));
31
+ } else {
32
+ $this->_headerText = "Abandoned Carts - <span class='ab_ng'>Disabled</span>";
33
+ }
34
+
35
+ $data = Mage::helper('campaigner')->getCronLastRun(0,'cron_last_run');
36
+
37
+ if ($data['class'] == 'ab_ng') {
38
+ Mage::getSingleton('adminhtml/session')->addWarning("There appears to be a problem with your cron settings. Please make sure that cron is running so that Abandoned Carts can be processed.");
39
+ }
40
+
41
+ parent::__construct();
42
+ $this->_removeButton('add');
43
+ }
44
+
45
+ public function getStatusHtml()
46
+ {
47
+ return $this->getChildHtml('abandoned_status');
48
+ }
49
+
50
+ protected function _prepareLayout()
51
+ {
52
+ $this->setChild('store_switcher',
53
+ $this->getLayout()->createBlock('adminhtml/store_switcher')
54
+ ->setUseConfirm(false)
55
+ ->setSwitchUrl($this->getUrl('*/*/*', array('store'=>null)))
56
+ ->setTemplate('report/store/switcher.phtml')
57
+ );
58
+
59
+ $this->setChild('abandoned_status',
60
+ $this->getLayout()->createBlock('campaigner/adminhtml_abandoned_status')
61
+ ->setTemplate('campaigner/abandoned/status.phtml')
62
+ );
63
+
64
+ return parent::_prepareLayout();
65
+ }
66
+
67
+ public function getGridHtml()
68
+ {
69
+ return $this->getStatusHtml() . parent::getGridHtml();
70
+ }
71
+ }
app/code/community/Campaigner/Integration/Block/Adminhtml/Abandoned/Details.php ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Adminhtml_Abandoned_Details extends Mage_Adminhtml_Block_Widget_Form_Container
4
+ {
5
+
6
+ public function __construct()
7
+ {
8
+ $this->_blockGroup = "campaigner";
9
+ $this->_controller = 'adminhtml_abandoned';
10
+ $this->_mode = 'details';
11
+
12
+ parent::__construct();
13
+
14
+ if (!$this->isGuestCustomer()) {
15
+ $this->_addButton('view_customer', array(
16
+ 'label' => Mage::helper('campaigner')->__('View Customer'),
17
+ 'onclick' => 'setLocation(\'' . $this->getUrl('adminhtml/customer/edit', array('id'=> $this->getCustomerId(), 'active_tab'=>'cart')) . '\')',
18
+ ), 0);
19
+ }
20
+
21
+ $this->_removeButton('delete');
22
+ $this->_removeButton('reset');
23
+ $this->_removeButton('save');
24
+ $this->setId('abandoned_details');
25
+ }
26
+
27
+ public function getCustomerId()
28
+ {
29
+ $abandoned_cart = Mage::helper('campaigner/diagnostic')->getAbandonedCart();
30
+
31
+ return $abandoned_cart->getCustomerId();
32
+ }
33
+
34
+ public function isGuestCustomer()
35
+ {
36
+ $abandoned_cart = Mage::helper('campaigner/diagnostic')->getAbandonedCart();
37
+
38
+ return $abandoned_cart->getCustomerGroupId() == 0;
39
+ }
40
+
41
+ public function getHeaderText()
42
+ {
43
+ $abandoned_cart = Mage::helper('campaigner/diagnostic')->getAbandonedCart();
44
+
45
+ $name = "";
46
+ $additional = "";
47
+
48
+ if ($abandoned_cart->getCustomerGroupId() == 0) {
49
+ // Guest
50
+ $email = $abandoned_cart->getEmail();
51
+
52
+ $additional = "Guest Customer ({$email})";
53
+ } else {
54
+ $email = $abandoned_cart->getCustomerEmail();
55
+ $name = $abandoned_cart->getCustomerFirstname() . " " . $abandoned_cart->getCustomerLastname();
56
+ $additional = "{$name} ({$email})";
57
+ }
58
+
59
+ $date = Mage::helper('core')->formatTime($abandoned_cart->getUpdatedAt(), 'medium', true);
60
+
61
+ return Mage::helper('campaigner')->__('Abandoned Cart - ' . $additional . " - Abandoned On: " . $date);
62
+ }
63
+
64
+ public function getUrl($params='', $params2=array())
65
+ {
66
+ return parent::getUrl($params, $params2);
67
+ }
68
+
69
+ public function getDownloadUrl()
70
+ {
71
+ return $this->getUrl('campaigner_dashboard/admin_troubleshooting/download/');
72
+ }
73
+
74
+ public function getBackUrl()
75
+ {
76
+ return Mage::helper('campaigner')->getAdminUrl('*/*/index');
77
+ }
78
+ }
app/code/community/Campaigner/Integration/Block/Adminhtml/Abandoned/Details/Form.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Adminhtml_Abandoned_Details_Form extends Mage_Adminhtml_Block_Template
4
+ {
5
+ protected function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->setTemplate('campaigner/abandoned/details/form.phtml');
9
+ }
10
+ }
app/code/community/Campaigner/Integration/Block/Adminhtml/Abandoned/Details/Tab/Cart.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Adminhtml_Abandoned_Details_Tab_Cart
4
+ extends Mage_Adminhtml_Block_Template
5
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
6
+ {
7
+ public function getTabLabel()
8
+ {
9
+ return Mage::helper('campaigner')->__('Cart Items');
10
+ }
11
+
12
+ public function getTabTitle()
13
+ {
14
+ return Mage::helper('campaigner')->__('Cart Items');
15
+ }
16
+
17
+ public function canShowTab()
18
+ {
19
+ return true;
20
+ }
21
+
22
+ public function isHidden()
23
+ {
24
+ return false;
25
+ }
26
+
27
+ public function getCartItems()
28
+ {
29
+ return Mage::helper('campaigner/diagnostic')->getCartItems();
30
+ }
31
+
32
+ public function __construct()
33
+ {
34
+ parent::__construct();
35
+ $this->setTemplate('campaigner/abandoned/details/tab/cart.phtml');
36
+ }
37
+ }
app/code/community/Campaigner/Integration/Block/Adminhtml/Abandoned/Details/Tab/Diagnostics.php ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Adminhtml_Abandoned_Details_Tab_Diagnostics
4
+ extends Mage_Adminhtml_Block_Sales_Order_Abstract
5
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
6
+ {
7
+
8
+ public function getDiagnosticOptions()
9
+ {
10
+ $options = array(
11
+ array('code' => 'abandoned_url', 'label' => 'Restore Cart URL', 'description' => 'Get the URL that customers will use to restore their carts.'),
12
+ array('code' => 'abandoned_custom_fields', 'label' => 'Custom Fields', 'description' => 'Custom Fields'),
13
+ array('code' => 'abandoned_request', 'label' => 'Abandoned Request', 'description' => 'Custom Fields'),
14
+ );
15
+
16
+ $full = array(
17
+ 'code' => 'abandoned_request_full',
18
+ 'label' => 'Abandoned Request and Response',
19
+ 'description' => 'Diagnose the request and response for this Cart.',
20
+ 'note' => 'This will send the cart to Campaigner but it will not mark it as sent.'
21
+ );
22
+
23
+ if (!$this->isCampaignerEnabled() || !$this->isCampaignerSetup() || !$this->isAbandonedEnabled()) {
24
+ $full['disabled'] = true;
25
+ $full['disabled_reason'] = 'Campaigner must be enabled (and setup to send abandoned carts) to perform this diagnostic.';
26
+ }
27
+
28
+ $options[] = $full;
29
+
30
+ return $options;
31
+ }
32
+
33
+ public function getStoreId()
34
+ {
35
+ return Mage::app()->getRequest()->getParam('store_id');
36
+ }
37
+
38
+ public function getStore()
39
+ {
40
+ $store_id = $this->getStoreId();
41
+
42
+ return Mage::getModel('core/store')->load($store_id);
43
+ }
44
+
45
+ public function getItemId()
46
+ {
47
+ return Mage::app()->getRequest()->getParam('id');
48
+ }
49
+
50
+ public function isCampaignerEnabled()
51
+ {
52
+ return Mage::helper('campaigner')->config('active',$this->getOrderStore()) == 1;
53
+ }
54
+
55
+ public function isCampaignerSetup()
56
+ {
57
+ return Mage::helper('campaigner')->config('setup',$this->getOrderStore()) == 1;
58
+ }
59
+
60
+ public function isAbandonedEnabled()
61
+ {
62
+ return Mage::helper('campaigner')->getAbandonedEnabled();
63
+ }
64
+
65
+ public function getTabLabel()
66
+ {
67
+ return Mage::helper('campaigner')->__('Campaigner Diagnostics');
68
+ }
69
+
70
+ public function getTabTitle()
71
+ {
72
+ return Mage::helper('campaigner')->__('Campaigner Diagnostics');
73
+ }
74
+
75
+ public function canShowTab()
76
+ {
77
+ return Mage::helper('campaigner/troubleshooting')->isDiagnosticEnabled();
78
+ }
79
+
80
+ public function isHidden()
81
+ {
82
+ return false;
83
+ }
84
+
85
+ public function __construct()
86
+ {
87
+ parent::__construct();
88
+ $this->setTemplate('campaigner/order/view/tab/diagnostics.phtml');
89
+ }
90
+ }
app/code/community/Campaigner/Integration/Block/Adminhtml/Abandoned/Details/Tab/Diagnostics/Status.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Adminhtml_Abandoned_Details_Tab_Diagnostics_Status extends Campaigner_Integration_Block_Adminhtml_Diagnostics_Status_Abstract
4
+ {
5
+ public function isAbandonedEnabled()
6
+ {
7
+ return Mage::helper('campaigner')->getAbandonedEnabled();
8
+ }
9
+
10
+ public function getStoreId()
11
+ {
12
+ return Mage::app()->getRequest()->getParam('store_id');
13
+ }
14
+
15
+ public function getStore()
16
+ {
17
+ $store_id = $this->getStoreId();
18
+
19
+ return Mage::getModel('core/store')->load($store_id);
20
+ }
21
+
22
+ public function getQuoteId()
23
+ {
24
+ return Mage::app()->getRequest()->getParam('id');
25
+ }
26
+
27
+ public function getQuote()
28
+ {
29
+ $quote = Mage::getModel('sales/quote')->setStore($this->getStore())->load($this->getQuoteId());
30
+
31
+ return $quote;
32
+ }
33
+
34
+ public function getAbandonedQuote()
35
+ {
36
+ $abandoned = Mage::getModel('campaigner/abandoned')->loadByQuoteId($this->getQuoteId());
37
+
38
+ return $abandoned;
39
+ }
40
+
41
+ public function getCampaignerDate()
42
+ {
43
+ $abandoned = $this->getAbandonedQuote();
44
+ }
45
+ }
app/code/community/Campaigner/Integration/Block/Adminhtml/Abandoned/Grid.php ADDED
@@ -0,0 +1,269 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Adminhtml_Abandoned_Grid extends Mage_Adminhtml_Block_Widget_Grid
4
+ {
5
+
6
+ /**
7
+ * ids of current stores
8
+ */
9
+ protected $_store_ids = array();
10
+
11
+ protected $_abandoned_status = null;
12
+
13
+ /**
14
+ * stores current currency code
15
+ */
16
+ protected $_currentCurrencyCode = null;
17
+
18
+ public function __construct()
19
+ {
20
+ parent::__construct();
21
+ $this->setId('abandonedGrid');
22
+ $this->setUseAjax(true);
23
+ $this->setDefaultSort('updated_at');
24
+ $this->setSaveParametersInSession(true);
25
+ $this->setPagerVisibility(true);
26
+ $this->setTemplate('widget/grid.phtml');
27
+ $this->setRowClickCallback('openGridRow');
28
+
29
+ $this->_abandoned_status = Mage::helper('campaigner')->getAbandonedStatus();
30
+ }
31
+
32
+ /**
33
+ * Retrieve currency code based on selected store
34
+ *
35
+ * @return string
36
+ */
37
+ public function getCurrentCurrencyCode()
38
+ {
39
+ if (is_null($this->_currentCurrencyCode)) {
40
+ reset($this->_store_ids);
41
+ $this->_currentCurrencyCode = (count($this->_store_ids) > 0)
42
+ ? Mage::app()->getStore(current($this->_store_ids))->getBaseCurrencyCode()
43
+ : Mage::app()->getStore()->getBaseCurrencyCode();
44
+ }
45
+ return $this->_currentCurrencyCode;
46
+ }
47
+
48
+ /**
49
+ * store_ids setter
50
+ *
51
+ * @param array $store_ids
52
+ * @return Mage_Adminhtml_Block_Report_Grid_Shopcart_Abstract
53
+ */
54
+ public function setStoreIds()
55
+ {
56
+ if ($this->getRequest()->getParam('website')) {
57
+ $this->_store_ids = Mage::app()->getWebsite($this->getRequest()->getParam('website'))->getStoreIds();
58
+ } else if ($this->getRequest()->getParam('group')) {
59
+ $this->_store_ids = Mage::app()->getGroup($this->getRequest()->getParam('group'))->getStoreIds();
60
+ } else if ($this->getRequest()->getParam('store')) {
61
+ $this->_store_ids = array((int)$this->getRequest()->getParam('store'));
62
+ } else {
63
+ $this->_store_ids = array();
64
+ }
65
+ }
66
+
67
+ protected function _prepareCollection()
68
+ {
69
+ $collection = Mage::getResourceModel('campaigner/abandoned_collection');
70
+
71
+ $filter = $this->getParam($this->getVarNameFilter(), array());
72
+
73
+ if ($filter) {
74
+ $filter = base64_decode($filter);
75
+ parse_str(urldecode($filter), $data);
76
+ }
77
+
78
+ $this->setCollection($collection);
79
+
80
+ if (!empty($data)) {
81
+ $collection->prepareForAbandonedReport($this->_store_ids, $data);
82
+ } else {
83
+ $collection->prepareForAbandonedReport($this->_store_ids);
84
+ }
85
+
86
+ return parent::_prepareCollection();
87
+ }
88
+
89
+ protected function _addColumnFilterToCollection($column)
90
+ {
91
+ $field = ($column->getFilterIndex()) ? $column->getFilterIndex() : $column->getIndex();
92
+
93
+ parent::_addColumnFilterToCollection($column);
94
+ return $this;
95
+ }
96
+
97
+ private function getCustomerGroups($blank = false)
98
+ {
99
+ $options = array();
100
+
101
+ $groups = Mage::Helper('customer')->getGroups();
102
+
103
+ if ($blank) {
104
+ $options[""] = "";
105
+ }
106
+
107
+ foreach($groups as $group) {
108
+ $options[$group->getData('customer_group_id')] = Mage::helper('catalog')->__($group->getData('customer_group_code'));
109
+ }
110
+
111
+ $options[0] = Mage::helper('catalog')->__('NOT LOGGED IN');
112
+
113
+ return $options;
114
+ }
115
+
116
+ protected function _prepareColumns()
117
+ {
118
+ $this->addColumn('customer_firstname', array(
119
+ 'header' => Mage::helper('campaigner')->__('First Name'),
120
+ 'index' => 'customer_firstname'
121
+ ));
122
+
123
+ $this->addColumn('customer_lastname', array(
124
+ 'header' => Mage::helper('campaigner')->__('Last Name'),
125
+ 'index' => 'customer_lastname'
126
+ ));
127
+
128
+ $this->addColumn('email', array(
129
+ 'header' => Mage::helper('campaigner')->__('Email'),
130
+ 'filter_index' => 'IF(main_table.customer_email IS NOT NULL, main_table.customer_email, email)',
131
+ 'index' => 'email'
132
+ ));
133
+
134
+ $this->addColumn('customer_group_id', array(
135
+ 'header' => Mage::helper('campaigner')->__('Customer Group'),
136
+ 'index' => 'customer_group_id',
137
+ 'type' => 'options',
138
+ 'options' => $this->getCustomerGroups()
139
+ ));
140
+
141
+ $this->addColumn('items_count', array(
142
+ 'header' => Mage::helper('campaigner')->__('Number of Items'),
143
+ 'align' => 'right',
144
+ 'index' => 'items_count',
145
+ 'type' => 'number'
146
+ ));
147
+
148
+ $this->addColumn('items_qty', array(
149
+ 'header' => Mage::helper('campaigner')->__('Quantity of Items'),
150
+ 'align' => 'right',
151
+ 'index' => 'items_qty',
152
+ 'type' => 'number'
153
+ ));
154
+
155
+ $this->setStoreIds();
156
+
157
+ $currencyCode = $this->getCurrentCurrencyCode();
158
+
159
+ $this->addColumn('store_id', array(
160
+ 'header' => Mage::helper('catalog')->__('Store'),
161
+ 'index' => 'store_id',
162
+ 'type' => 'store',
163
+ 'filter_index' => 'main_table.store_id',
164
+ 'store_view' => true,
165
+ 'sortable' => false
166
+ ));
167
+
168
+ $this->addColumn('subtotal', array(
169
+ 'header' => Mage::helper('campaigner')->__('Subtotal'),
170
+ 'width' => '80px',
171
+ 'type' => 'currency',
172
+ 'currency_code' => $currencyCode,
173
+ 'index' => 'subtotal',
174
+ 'renderer' => 'adminhtml/report_grid_column_renderer_currency',
175
+ 'rate' => $this->getRate($currencyCode),
176
+ ));
177
+
178
+ $this->addColumn('updated_at', array(
179
+ 'header' => Mage::helper('campaigner')->__('Abandoned Date'),
180
+ 'type' => 'datetime',
181
+ 'index' => 'updated_at',
182
+ 'filter_index' => 'main_table.updated_at'
183
+ ));
184
+
185
+ $this->addColumn('abandoned_minutes', array(
186
+ 'header' => Mage::helper('campaigner')->__('Minutes'),
187
+ 'width' => '70px',
188
+ 'renderer' => 'Campaigner_Integration_Block_Widget_Grid_Column_Renderer_Abandoned_Minutes',
189
+ 'index' => 'abandoned_minutes',
190
+ 'sortable' => false,
191
+ 'filter' => false,
192
+ ));
193
+
194
+ $this->addColumn('remote_ip', array(
195
+ 'header' => Mage::helper('campaigner')->__('IP Address'),
196
+ 'width' => '80px',
197
+ 'index' => 'remote_ip'
198
+ ));
199
+
200
+ $this->addColumn('date_sent', array(
201
+ 'header' => Mage::helper('campaigner')->__('Date Sent to Campaigner'),
202
+ 'index' => 'date_sent',
203
+ 'type' => 'datetime'
204
+ ));
205
+
206
+ $this->addColumn('status', array(
207
+ 'header' => Mage::helper('campaigner')->__('Status'),
208
+ 'index' => 'status'
209
+ ));
210
+
211
+ if ($this->_abandoned_status['enabled']) {
212
+ $this->addColumn('action',
213
+ array(
214
+ 'header' => Mage::helper('campaigner')->__('Action'),
215
+ 'width' => '50px',
216
+ 'type' => 'action',
217
+ 'getter' => 'getId',
218
+ 'actions' => array(
219
+ array(
220
+ 'caption' => Mage::helper('campaigner')->__('Send'),
221
+ 'url' => array('base'=> '*/*/send', 'params' => Mage::helper('campaigner')->getUrlParams()),
222
+ 'field' => 'id',
223
+ 'sent' => false
224
+ ),
225
+ array(
226
+ 'caption' => Mage::helper('campaigner')->__('Resend'),
227
+ 'url' => array('base'=> '*/*/send', 'params' => Mage::helper('campaigner')->getUrlParams()),
228
+ 'field' => 'id',
229
+ 'sent' => true
230
+ )
231
+ ),
232
+ 'filter' => false,
233
+ 'sortable' => false,
234
+ 'renderer' => 'Campaigner_Integration_Block_Widget_Grid_Column_Renderer_Action',
235
+ 'index' => 'stores',
236
+ 'is_system' => true,
237
+ ));
238
+ }
239
+
240
+ return parent::_prepareColumns();
241
+ }
242
+
243
+ protected function _prepareMassaction()
244
+ {
245
+ if (!$this->_abandoned_status['enabled']) {
246
+ return $this;
247
+ }
248
+
249
+ $this->setMassactionIdField('post_id');
250
+ $this->getMassactionBlock()->setFormFieldName('id');
251
+
252
+ $this->getMassactionBlock()->addItem('send', array(
253
+ 'label' => Mage::helper('campaigner')->__('Send or Resend'),
254
+ 'url' => $this->getUrl('*/*/massSend', Mage::helper('campaigner')->getUrlParams())
255
+ ));
256
+
257
+ return $this;
258
+ }
259
+
260
+ public function getGridUrl()
261
+ {
262
+ return $this->getUrl('*/*/grid', array('_current'=> true));
263
+ }
264
+
265
+ public function getRowUrl($row)
266
+ {
267
+ return $this->getUrl('*/*/details', array('id'=>$row->getId(),'store_id' => $row->getStoreId(), 'active_tab'=>'cart'));
268
+ }
269
+ }
app/code/community/Campaigner/Integration/Block/Adminhtml/Abandoned/Status.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Adminhtml_Abandoned_Status extends Mage_Adminhtml_Block_Template
4
+ {
5
+ public function getAbandonedStatus()
6
+ {
7
+ return Mage::helper('campaigner')->getAbandonedStatus();
8
+ }
9
+ }
app/code/community/Campaigner/Integration/Block/Adminhtml/Abandoned/Tabs.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Adminhtml_Abandoned_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+ $this->setId('abandoned_details_tabs');
9
+ $this->setDestElementId('abandoned_details');
10
+ $this->setTitle(Mage::helper('campaigner')->__('Abandoned Cart Details'));
11
+ }
12
+
13
+ protected function _beforeToHtml()
14
+ {
15
+ $this->_updateActiveTab();
16
+ return parent::_beforeToHtml();
17
+ }
18
+
19
+ protected function _updateActiveTab()
20
+ {
21
+ $tabId = $this->getRequest()->getParam('tab');
22
+ if ($tabId) {
23
+ $tabId = preg_replace("#{$this->getId()}_#", '', $tabId);
24
+ if ($tabId) {
25
+ $this->setActiveTab($tabId);
26
+ }
27
+ }
28
+ }
29
+ }
app/code/community/Campaigner/Integration/Block/Adminhtml/Diagnostics/Status/Abstract.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Adminhtml_Diagnostics_Status_Abstract extends Mage_Adminhtml_Block_Template
4
+ {
5
+ protected $_helper = null;
6
+
7
+ public function _construct()
8
+ {
9
+ $this->_helper = Mage::helper('campaigner');
10
+ parent::_construct();
11
+ }
12
+
13
+ public function isCampaignerEnabled()
14
+ {
15
+ return $this->_helper->config('active',$this->_helper->getCurrentStore()) == 1;
16
+ }
17
+
18
+ public function isCampaignerSetup()
19
+ {
20
+ return $this->_helper->config('setup',$this->_helper->getCurrentStore()) == 1;
21
+ }
22
+ }
app/code/community/Campaigner/Integration/Block/Adminhtml/Latest.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Adminhtml_Latest extends Mage_Adminhtml_Block_Widget_Grid_Container
4
+ {
5
+ public function __construct()
6
+ {
7
+ $this->_controller = 'adminhtml_latest';
8
+ $this->_blockGroup = 'campaigner';
9
+
10
+ $status = Mage::helper('campaigner')->getLatestStatus();
11
+
12
+ if ($status['enabled']) {
13
+ $this->_headerText = "Latest Orders - Cron Last Run: " . Mage::helper('campaigner')->getLatestCronLastRunHtml();
14
+
15
+ $label = 'Run now on all stores';
16
+
17
+ if (Mage::app()->isSingleStoreMode()) {
18
+ $label = 'Run now';
19
+ }
20
+
21
+ $this->addButton('refresh', array(
22
+ 'label' => Mage::helper('campaigner')->__('Refresh'),
23
+ 'onclick' => 'latestGridJsObject.reload();return false;',
24
+ ));
25
+
26
+ $this->_addButton('run_now', array(
27
+ 'label' => Mage::helper('campaigner')->__($label),
28
+ 'onclick' => 'setLocation(\'' . $this->getUrl('*/*/run') .'\')',
29
+ ));
30
+ } else {
31
+ $this->_headerText = "Latest Orders - <span class='ab_ng'>Disabled</span>";
32
+ }
33
+
34
+ $data = Mage::helper('campaigner')->getCronLastRun(0,'latest_cron_last_run');
35
+
36
+ if ($data['class'] == 'ab_ng') {
37
+ Mage::getSingleton('adminhtml/session')->addWarning("There appears to be a problem with your cron settings. Please make sure that cron is running so that Latest Orders can be processed.");
38
+ }
39
+
40
+ parent::__construct();
41
+ $this->_removeButton('add');
42
+ }
43
+
44
+ public function getStatusHtml()
45
+ {
46
+ return $this->getChildHtml('latest_status');
47
+ }
48
+
49
+ protected function _prepareLayout()
50
+ {
51
+ $this->setChild('latest_status',
52
+ $this->getLayout()->createBlock('campaigner/adminhtml_latest_status')
53
+ ->setTemplate('campaigner/latest/status.phtml')
54
+ );
55
+
56
+ return parent::_prepareLayout();
57
+ }
58
+
59
+ public function getGridHtml()
60
+ {
61
+ return $this->getStatusHtml() . parent::getGridHtml();
62
+ }
63
+ }
app/code/community/Campaigner/Integration/Block/Adminhtml/Latest/Grid.php ADDED
@@ -0,0 +1,248 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Adminhtml_Latest_Grid extends Mage_Adminhtml_Block_Widget_Grid
4
+ {
5
+
6
+ /**
7
+ * ids of current stores
8
+ */
9
+ protected $_store_ids = array();
10
+
11
+ protected $_latest_status = null;
12
+
13
+ /**
14
+ * stores current currency code
15
+ */
16
+ protected $_currentCurrencyCode = null;
17
+
18
+ public function __construct()
19
+ {
20
+ parent::__construct();
21
+ $this->setId('latestGrid');
22
+ $this->setUseAjax(true);
23
+ $this->setDefaultSort('updated_at');
24
+ $this->setSaveParametersInSession(true);
25
+ $this->setPagerVisibility(true);
26
+ $this->setTemplate('widget/grid.phtml');
27
+ $this->setRowClickCallback('openGridRow');
28
+
29
+ $this->_latest_status = Mage::helper('campaigner')->getLatestStatus();
30
+ }
31
+
32
+ /**
33
+ * Retrieve currency code based on selected store
34
+ *
35
+ * @return string
36
+ */
37
+ public function getCurrentCurrencyCode()
38
+ {
39
+ if (is_null($this->_currentCurrencyCode))
40
+ {
41
+ reset($this->_store_ids);
42
+ $this->_currentCurrencyCode = (count($this->_store_ids) > 0)
43
+ ? Mage::app()->getStore(current($this->_store_ids))->getBaseCurrencyCode()
44
+ : Mage::app()->getStore()->getBaseCurrencyCode();
45
+ }
46
+ return $this->_currentCurrencyCode;
47
+ }
48
+
49
+ /**
50
+ * store_ids setter
51
+ *
52
+ * @param array $store_ids
53
+ * @return Mage_Adminhtml_Block_Report_Grid_Shopcart_Abstract
54
+ */
55
+ public function setStoreIds()
56
+ {
57
+ if ($this->getRequest()->getParam('website')) {
58
+ $this->_store_ids = Mage::app()->getWebsite($this->getRequest()->getParam('website'))->getStoreIds();
59
+ } else if ($this->getRequest()->getParam('group')) {
60
+ $this->_store_ids = Mage::app()->getGroup($this->getRequest()->getParam('group'))->getStoreIds();
61
+ } else if ($this->getRequest()->getParam('store')) {
62
+ $this->_store_ids = array((int)$this->getRequest()->getParam('store'));
63
+ } else {
64
+ $this->_store_ids = array();
65
+ }
66
+ }
67
+
68
+ protected function _prepareCollection()
69
+ {
70
+ $collection = Mage::getResourceModel('campaigner/latest_order_collection');
71
+
72
+ $filter = $this->getParam($this->getVarNameFilter(), array());
73
+
74
+ if ($filter) {
75
+ $filter = base64_decode($filter);
76
+ parse_str(urldecode($filter), $data);
77
+ }
78
+
79
+ $this->setCollection($collection);
80
+
81
+ if (!empty($data)) {
82
+ $collection->prepareForLatestReport($this->_store_ids, $data);
83
+ } else {
84
+ $collection->prepareForLatestReport($this->_store_ids);
85
+ }
86
+
87
+ return parent::_prepareCollection();
88
+ }
89
+
90
+ protected function _addColumnFilterToCollection($column)
91
+ {
92
+ $field = ($column->getFilterIndex()) ? $column->getFilterIndex() : $column->getIndex();
93
+
94
+ parent::_addColumnFilterToCollection($column);
95
+ return $this;
96
+ }
97
+
98
+ private function getCustomerGroups($blank = false)
99
+ {
100
+ $options = array();
101
+
102
+ $groups = Mage::Helper('customer')->getGroups();
103
+
104
+ if ($blank) {
105
+ $options[""] = "";
106
+ }
107
+
108
+ foreach($groups as $group) {
109
+ $options[$group->getData('customer_group_id')] = Mage::helper('catalog')->__($group->getData('customer_group_code'));
110
+ }
111
+
112
+ $options[0] = Mage::helper('catalog')->__('NOT LOGGED IN');
113
+
114
+ return $options;
115
+ }
116
+
117
+ protected function _prepareColumns()
118
+ {
119
+ $this->addColumn('customer_firstname', array(
120
+ 'header' => Mage::helper('campaigner')->__('First Name'),
121
+ 'index' => 'customer_firstname'
122
+ ));
123
+
124
+ $this->addColumn('customer_lastname', array(
125
+ 'header' => Mage::helper('campaigner')->__('Last Name'),
126
+ 'index' => 'customer_lastname'
127
+ ));
128
+
129
+ $this->addColumn('email', array(
130
+ 'header' => Mage::helper('campaigner')->__('Email'),
131
+ 'filter_index' => 'IF(main_table.customer_email IS NOT NULL, main_table.customer_email, email)',
132
+ 'index' => 'email'
133
+ ));
134
+
135
+ $this->addColumn('customer_group_id', array(
136
+ 'header' => Mage::helper('campaigner')->__('Customer Group'),
137
+ 'index' => 'customer_group_id',
138
+ 'type' => 'options',
139
+ 'options' => $this->getCustomerGroups()
140
+ ));
141
+
142
+ $this->addColumn('items_count', array(
143
+ 'header' => Mage::helper('campaigner')->__('Number of Items'),
144
+ 'align' => 'right',
145
+ 'index' => 'total_item_count',
146
+ 'type' => 'number'
147
+ ));
148
+
149
+ $this->setStoreIds();
150
+
151
+ $currencyCode = $this->getCurrentCurrencyCode();
152
+
153
+ $this->addColumn('store_id', array(
154
+ 'header' => Mage::helper('catalog')->__('Store'),
155
+ 'index' => 'store_id',
156
+ 'type' => 'store',
157
+ 'filter_index' => 'main_table.store_id',
158
+ 'store_view' => true,
159
+ 'sortable' => false
160
+ ));
161
+
162
+ $this->addColumn('subtotal', array(
163
+ 'header' => Mage::helper('campaigner')->__('Subtotal'),
164
+ 'width' => '80px',
165
+ 'type' => 'currency',
166
+ 'currency_code' => $currencyCode,
167
+ 'index' => 'subtotal',
168
+ 'renderer' => 'adminhtml/report_grid_column_renderer_currency',
169
+ 'rate' => $this->getRate($currencyCode),
170
+ ));
171
+
172
+ $this->addColumn('updated_at', array(
173
+ 'header' => Mage::helper('campaigner')->__('Date'),
174
+ 'type' => 'datetime',
175
+ 'index' => 'updated_at',
176
+ 'filter_index' => 'main_table.updated_at'
177
+ ));
178
+
179
+ $this->addColumn('date_sent', array(
180
+ 'header' => Mage::helper('campaigner')->__('Date Sent to Campaigner'),
181
+ 'index' => 'date_sent',
182
+ 'type' => 'datetime'
183
+ ));
184
+
185
+ $this->addColumn('status', array(
186
+ 'header' => Mage::helper('campaigner')->__('Status'),
187
+ 'index' => 'status'
188
+ ));
189
+
190
+ if ($this->_latest_status['enabled']) {
191
+ $this->addColumn('action',
192
+ array(
193
+ 'header' => Mage::helper('campaigner')->__('Action'),
194
+ 'width' => '50px',
195
+ 'type' => 'action',
196
+ 'getter' => 'getId',
197
+ 'actions' => array(
198
+ array(
199
+ 'caption' => Mage::helper('campaigner')->__('Send'),
200
+ 'url' => array('base'=> '*/*/send', 'params' => Mage::helper('campaigner')->getUrlParams()),
201
+ 'field' => 'id',
202
+ 'sent' => false
203
+ ),
204
+ array(
205
+ 'caption' => Mage::helper('campaigner')->__('Resend'),
206
+ 'url' => array('base'=> '*/*/send', 'params' => Mage::helper('campaigner')->getUrlParams()),
207
+ 'field' => 'id',
208
+ 'sent' => true
209
+ )
210
+ ),
211
+ 'filter' => false,
212
+ 'sortable' => false,
213
+ 'renderer' => 'Campaigner_Integration_Block_Widget_Grid_Column_Renderer_Action',
214
+ 'index' => 'stores',
215
+ 'is_system' => true,
216
+ ));
217
+ }
218
+
219
+ return parent::_prepareColumns();
220
+ }
221
+
222
+ protected function _prepareMassaction()
223
+ {
224
+ if (!$this->_latest_status['enabled']) {
225
+ return $this;
226
+ }
227
+
228
+ $this->setMassactionIdField('post_id');
229
+ $this->getMassactionBlock()->setFormFieldName('id');
230
+
231
+ $this->getMassactionBlock()->addItem('send', array(
232
+ 'label' => Mage::helper('campaigner')->__('Send or Resend'),
233
+ 'url' => $this->getUrl('*/*/massSend', Mage::helper('campaigner')->getUrlParams())
234
+ ));
235
+
236
+ return $this;
237
+ }
238
+
239
+ public function getGridUrl()
240
+ {
241
+ return $this->getUrl('*/*/grid', array('_current'=> true));
242
+ }
243
+
244
+ public function getRowUrl($row)
245
+ {
246
+ return $this->getUrl('*/*/details', array('id'=>$row->getId(),'store_id' => $row->getStoreId(), 'active_tab'=>'cart'));
247
+ }
248
+ }
app/code/community/Campaigner/Integration/Block/Adminhtml/Latest/Status.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Adminhtml_Latest_Status extends Mage_Adminhtml_Block_Template
4
+ {
5
+ public function getLatestStatus()
6
+ {
7
+ return Mage::helper('campaigner')->getLatestStatus();
8
+ }
9
+ }
app/code/community/Campaigner/Integration/Block/Adminhtml/System/Config/Fieldset/Hint.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Adminhtml_System_Config_Fieldset_Hint
4
+ extends Mage_Adminhtml_Block_Abstract
5
+ implements Varien_Data_Form_Element_Renderer_Interface
6
+ {
7
+ protected $_template = 'campaigner/system/config/fieldset/hint.phtml';
8
+
9
+ /**
10
+ * Render fieldsetset html
11
+ *
12
+ * @param Varien_Data_Form_Element_Abstract $element
13
+ * @return string
14
+ */
15
+ public function render(Varien_Data_Form_Element_Abstract $element)
16
+ {
17
+ return $this->toHtml();
18
+ }
19
+
20
+ public function getCampaignerVersion()
21
+ {
22
+ return (string) Mage::getConfig()->getNode('modules/Campaigner_Integration/version');
23
+ }
24
+
25
+ public function getAbandonedLastRunHtml()
26
+ {
27
+ return Mage::helper('campaigner')->getAbandonedLastRunHtml();
28
+ }
29
+
30
+ public function getAbandonedEnabled()
31
+ {
32
+ return Mage::helper('campaigner')->getAbandonedEnabled();
33
+ }
34
+
35
+ public function isWebsiteConfig()
36
+ {
37
+ return Mage::helper('campaigner')->isWebsiteConfig();
38
+ }
39
+ }
app/code/community/Campaigner/Integration/Block/Adminhtml/System/Config/Form/Field/Addressmapfields.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Adminhtml_System_Config_Form_Field_Addressmapfields extends Campaigner_Integration_Block_Adminhtml_System_Config_Form_Field_Common
4
+ {
5
+ public function __construct()
6
+ {
7
+ $this->addColumn('magento', array(
8
+ 'label' => Mage::helper('campaigner')->__('Billing Address'),
9
+ 'style' => 'width:120px',
10
+ ));
11
+ $this->addColumn('campaigner', array(
12
+ 'label' => Mage::helper('campaigner')->__('Campaigner'),
13
+ 'type' => 'options',
14
+ 'options' => Mage::helper('campaigner')->getCampaignerColumnOptions(),
15
+ 'style' => 'width:120px',
16
+ ));
17
+ $this->_addAfter = false;
18
+ $this->_addButtonLabel = Mage::helper('campaigner')->__('Add field');
19
+ parent::__construct();
20
+ }
21
+ }
app/code/community/Campaigner/Integration/Block/Adminhtml/System/Config/Form/Field/Api.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Adminhtml_System_Config_Form_Field_Api extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ private $_helper = null;
6
+
7
+ public function __construct()
8
+ {
9
+ parent::__construct();
10
+ $this->setTemplate('campaigner/system/config/form/field/api.phtml');
11
+ $this->_helper = Mage::helper('campaigner');
12
+ }
13
+
14
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
15
+ {
16
+ $this->setElement($element);
17
+ $html = $this->_toHtml();
18
+ return $html;
19
+ }
20
+
21
+ public function isValid()
22
+ {
23
+ return Mage::helper('campaigner')->config('setup') == 1;
24
+ }
25
+
26
+ public function getCurrentApiKey()
27
+ {
28
+ return $this->_helper->getApiKey();
29
+ }
30
+ }
app/code/community/Campaigner/Integration/Block/Adminhtml/System/Config/Form/Field/Common.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Adminhtml_System_Config_Form_Field_Common extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+ $this->setTemplate('campaigner/system/config/form/field/array.phtml');
9
+ }
10
+
11
+ /**
12
+ * Add a column to array-grid
13
+ *
14
+ * @param string $name
15
+ * @param array $params
16
+ */
17
+ public function addColumn($name, $params)
18
+ {
19
+ $this->_columns[$name] = array(
20
+ 'label' => empty($params['label']) ? 'Column' : $params['label'],
21
+ 'size' => empty($params['size']) ? false : $params['size'],
22
+ 'style' => empty($params['style']) ? null : $params['style'],
23
+ 'class' => empty($params['class']) ? null : $params['class'],
24
+ 'type' => empty($params['type']) ? null : $params['type'],
25
+ 'options' => empty($params['options']) ? array() : $params['options'],
26
+ 'renderer' => false,
27
+ );
28
+ if ((!empty($params['renderer'])) && ($params['renderer'] instanceof Mage_Core_Block_Abstract)) {
29
+ $this->_columns[$name]['renderer'] = $params['renderer'];
30
+ }
31
+ }
32
+
33
+ /**
34
+ * Render array cell for prototypeJS template
35
+ *
36
+ * @param string $columnName
37
+ * @return string
38
+ */
39
+ protected function _renderCellTemplate($columnName)
40
+ {
41
+ if (empty($this->_columns[$columnName])) {
42
+ throw new Exception('Wrong column name specified.');
43
+ }
44
+ $column = $this->_columns[$columnName];
45
+ $inputName = $this->getElement()->getName() . '[#{_id}][' . $columnName . ']';
46
+
47
+ if ($column['renderer']) {
48
+ return $column['renderer']->setInputName($inputName)->setColumnName($columnName)->setColumn($column)
49
+ ->toHtml();
50
+ }
51
+
52
+ if ($column['type'] == 'options') {
53
+ $html = '<select name="' . $inputName . '"class="' .
54
+ (isset($column['class']) ? $column['class'] : 'input-text') . '"'.
55
+ (isset($column['style']) ? ' style="'.$column['style'] . '"' : '') . '>';
56
+
57
+ foreach ($column['options'] as $val => $label)
58
+ {
59
+ $html .= '<option #{_selected_' . $this->escapeHtml($val) . '} value="' . $this->escapeHtml($val) . '">';
60
+ $html .= $this->escapeHtml($label) . '</option>';
61
+ }
62
+ $html.='</select>';
63
+
64
+ return $html;
65
+ }
66
+
67
+ return '<input type="text" name="' . $inputName . '" value="#{' . $columnName . '}" ' .
68
+ ($column['size'] ? 'size="' . $column['size'] . '"' : '') . ' class="' .
69
+ (isset($column['class']) ? $column['class'] : 'input-text') . '"'.
70
+ (isset($column['style']) ? ' style="'.$column['style'] . '"' : '') . '/>';
71
+ }
72
+ }
app/code/community/Campaigner/Integration/Block/Adminhtml/System/Config/Form/Field/Diagnostics.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Adminhtml_System_Config_Form_Field_Diagnostics extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ private $_helper = null;
6
+ private $_status = null;
7
+
8
+ public function __construct()
9
+ {
10
+ parent::__construct();
11
+ $this->setTemplate('campaigner/system/config/form/field/diagnostics.phtml');
12
+ $this->_helper = Mage::helper('campaigner');
13
+ }
14
+
15
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
16
+ {
17
+ $this->setElement($element);
18
+ $html = $this->_toHtml();
19
+ return $html;
20
+ }
21
+
22
+ public function getDiagnosticStatus()
23
+ {
24
+ return Mage::helper('campaigner/troubleshooting')->isDiagnosticEnabled();
25
+ }
26
+ }
app/code/community/Campaigner/Integration/Block/Adminhtml/System/Config/Form/Field/Info.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Adminhtml_System_Config_Form_Field_Info extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ private $_helper = null;
6
+
7
+ public function __construct()
8
+ {
9
+ parent::__construct();
10
+ $this->setTemplate('campaigner/system/config/form/field/info.phtml');
11
+ $this->_helper = Mage::helper('campaigner');
12
+ }
13
+
14
+ public function render(Varien_Data_Form_Element_Abstract $element)
15
+ {
16
+ $useContainerId = $element->getData('use_container_id');
17
+ return sprintf('<tr class="system-fieldset-sub-head" id="row_%s"><td colspan="5">%s</td></tr>',
18
+ $element->getHtmlId(), $this->_toHtml()
19
+ );
20
+ }
21
+
22
+ public function isWebsiteConfig()
23
+ {
24
+ return $this->_helper->isWebsiteConfig();
25
+ }
26
+ }
app/code/community/Campaigner/Integration/Block/Adminhtml/System/Config/Form/Field/Logging.php ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Adminhtml_System_Config_Form_Field_Logging extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ private $_helper = null;
6
+ private $_logger = null;
7
+ private $_status = null;
8
+
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+ $this->setTemplate('campaigner/system/config/form/field/logging.phtml');
13
+ $this->_helper = Mage::helper('campaigner');
14
+ $this->_logger = Mage::helper('campaigner/troubleshooting');
15
+ }
16
+
17
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
18
+ {
19
+ $this->setElement($element);
20
+ $html = $this->_toHtml();
21
+ return $html;
22
+ }
23
+
24
+ public function getLoggingStatus()
25
+ {
26
+ if ($this->_status == null) {
27
+ $this->_status = Mage::helper('campaigner/troubleshooting')->getLoggingStatus();
28
+ }
29
+
30
+ return $this->_status;
31
+ }
32
+
33
+ public function isEnabledForStore()
34
+ {
35
+ try {
36
+ $store = $this->_helper->getCurrentStore();
37
+
38
+ if ($store == 0) {
39
+ return true;
40
+ }
41
+
42
+ $status = $this->getLoggingStatus();
43
+
44
+ $stores = $status['stores'];
45
+
46
+ $current_store = $stores[$store];
47
+
48
+ return $current_store['logging_enabled'];
49
+ } catch (Exception $e) {
50
+ return false;
51
+ }
52
+
53
+ return false;
54
+ }
55
+
56
+ public function getStartDate()
57
+ {
58
+ try {
59
+ $date = $this->_helper->troubleConfig('logging_start_date');
60
+
61
+ $date = Mage::helper('core')->formatTime($date, 'long', true);
62
+
63
+ $ago = $this->_helper->timeElapsed2string(strtotime($date));
64
+
65
+ if ($ago != "") {
66
+ $minutes = "<br />({$ago} ago)";
67
+ }
68
+
69
+ return "{$date} {$minutes}";
70
+ } catch (Exception $e) {
71
+ $this->_logger->logException($e);
72
+ Mage::logException($e);
73
+ return "Unknown/Error";
74
+ }
75
+ }
76
+
77
+ public function getLogInfo()
78
+ {
79
+ try {
80
+ $helper = $this->_helper;
81
+
82
+ $file_size = Mage::helper('campaigner/troubleshooting')->getLogFileSize();
83
+ $formatted_size = $helper->formatSize($file_size);
84
+
85
+ $max_size = Mage::helper('campaigner/troubleshooting')->getMaxLogFileSize();
86
+
87
+ if ($file_size > $max_size || $file_size == 0) {
88
+ $formatted_size = "<span class='log_size_warning'>{$formatted_size}</span>";
89
+ }
90
+
91
+ $file_date = Mage::helper('campaigner/troubleshooting')->getLogFilelastUpdate();
92
+
93
+ if ($file_date == "") {
94
+ $last_update = "";
95
+ } else {
96
+ $last_update = "<br />" . Mage::helper('core')->formatTime(date(Campaigner_Integration_Helper_Data::DATE_FORMAT,$file_date), 'long', true);
97
+ }
98
+
99
+ $ago = $helper->timeElapsed2string($file_date);
100
+
101
+ if ($ago != "") {
102
+ $ago = "<br />({$ago} ago.)";
103
+ }
104
+
105
+ return Mage::helper('campaigner/troubleshooting')->getLogFileName() . " ({$formatted_size}){$last_update}{$ago}";
106
+ } catch (Exception $e) {
107
+ $this->_logger->logException($e);
108
+ Mage::logException($e);
109
+ return "Unknown/Error";
110
+ }
111
+ }
112
+
113
+ public function isLoggingEnabled()
114
+ {
115
+ return Mage::helper('campaigner/troubleshooting')->isLoggingEnabled();
116
+ }
117
+ }
app/code/community/Campaigner/Integration/Block/Adminhtml/System/Config/Form/Field/Mapfields.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Adminhtml_System_Config_Form_Field_Mapfields extends Campaigner_Integration_Block_Adminhtml_System_Config_Form_Field_Common
4
+ {
5
+ public function __construct()
6
+ {
7
+ $this->addColumn('magento', array(
8
+ 'label' => Mage::helper('campaigner')->__('Customer'),
9
+ 'style' => 'width:120px',
10
+ ));
11
+ $this->addColumn('campaigner', array(
12
+ 'label' => Mage::helper('campaigner')->__('Campaigner'),
13
+ 'style' => 'width:120px',
14
+ 'type' => 'options',
15
+ 'options' => Mage::helper('campaigner')->getCampaignerColumnOptions(),
16
+ ));
17
+ $this->_addAfter = false;
18
+ $this->_addButtonLabel = Mage::helper('campaigner')->__('Add field');
19
+ parent::__construct();
20
+ }
21
+ }
app/code/community/Campaigner/Integration/Block/Adminhtml/System/Config/Form/Field/Note.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Adminhtml_System_Config_Form_Field_Note extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ private $_helper = null;
6
+
7
+ public function __construct()
8
+ {
9
+ parent::__construct();
10
+ $this->setTemplate('campaigner/system/config/form/field/note.phtml');
11
+ $this->_helper = Mage::helper('campaigner');
12
+ }
13
+
14
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
15
+ {
16
+ $this->setElement($element);
17
+ $html = $this->_toHtml();
18
+ return $html;
19
+ }
20
+ }
app/code/community/Campaigner/Integration/Block/Adminhtml/System/Config/Form/Field/Shippingmapfields.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Adminhtml_System_Config_Form_Field_Shippingmapfields extends Campaigner_Integration_Block_Adminhtml_System_Config_Form_Field_Common
4
+ {
5
+
6
+ public function __construct()
7
+ {
8
+ $this->addColumn('magento', array(
9
+ 'label' => Mage::helper('campaigner')->__('Shipping Field'),
10
+ 'type' => 'options',
11
+ 'options' => Mage::helper('campaigner')->getShippingColumnOptions(),
12
+ 'style' => 'width:120px',
13
+ ));
14
+ $this->addColumn('campaigner', array(
15
+ 'label' => Mage::helper('campaigner')->__('Campaigner'),
16
+ 'type' => 'options',
17
+ 'options' => Mage::helper('campaigner')->getCampaignerColumnOptions(),
18
+ 'style' => 'width:120px',
19
+ ));
20
+ $this->_addAfter = false;
21
+ $this->_addButtonLabel = Mage::helper('campaigner')->__('Add field');
22
+ parent::__construct();
23
+ }
24
+ }
app/code/community/Campaigner/Integration/Block/Adminhtml/System/Config/Form/Field/Signup/Test.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Adminhtml_System_Config_Form_Field_Signup_Test extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ /**
6
+ * Check if columns are defined, set template
7
+ *
8
+ */
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+ $this->setTemplate('campaigner/system/config/form/field/signup/test.phtml');
13
+ }
14
+
15
+ /**
16
+ * Get the grid and scripts contents
17
+ *
18
+ * @param Varien_Data_Form_Element_Abstract $element
19
+ * @return string
20
+ */
21
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
22
+ {
23
+ $this->setElement($element);
24
+ $html = $this->_toHtml();
25
+
26
+ return $html;
27
+ }
28
+ }
app/code/community/Campaigner/Integration/Block/Adminhtml/System/Config/Form/Field/Smtp.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Adminhtml_System_Config_Form_Field_Smtp extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+
6
+ private $_helper = null;
7
+
8
+ public function __construct()
9
+ {
10
+ parent::__construct();
11
+ $this->setTemplate('campaigner/system/config/form/field/smtp.phtml');
12
+ $this->_helper = Mage::helper('campaigner');
13
+ }
14
+
15
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
16
+ {
17
+ $this->setElement($element);
18
+ $html = $this->_toHtml();
19
+ return $html;
20
+ }
21
+ }
app/code/community/Campaigner/Integration/Block/Adminhtml/System/Config/Form/Field/Smtp/Server.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Adminhtml_System_Config_Form_Field_Smtp_Server extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
6
+ {
7
+ return Mage::helper('campaigner')->fullConfig("campaigner_smtp_server","system","smtp");
8
+
9
+ $element->setValue(Mage::app()->loadCache('admin_notifications_lastcheck'));
10
+ $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
11
+ return Mage::app()->getLocale()->date(intval($element->getValue()))->toString($format);
12
+ }
13
+ }
app/code/community/Campaigner/Integration/Block/Adminhtml/System/Config/Form/Field/Smtp/Test.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Adminhtml_System_Config_Form_Field_Smtp_Test extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ private $_helper = null;
6
+
7
+ public function __construct()
8
+ {
9
+ parent::__construct();
10
+ $this->setTemplate('campaigner/system/config/form/field/smtp/test.phtml');
11
+ $this->_helper = Mage::helper('campaigner');
12
+ }
13
+
14
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
15
+ {
16
+ $this->setElement($element);
17
+ $html = $this->_toHtml();
18
+ return $html;
19
+ }
20
+ }
app/code/community/Campaigner/Integration/Block/Adminhtml/Troubleshooting/Status.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Adminhtml_Troubleshooting_Status extends Mage_Adminhtml_Block_Template
4
+ {
5
+ public function getLoggingStatus()
6
+ {
7
+ return Mage::helper('campaigner/troubleshooting')->getLoggingStatus();
8
+ }
9
+ }
app/code/community/Campaigner/Integration/Block/Adminhtml/Troubleshooting/Tabs.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Adminhtml_Troubleshooting_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+ $this->setId('troubleshooting_view_tabs');
9
+ $this->setDestElementId('troubleshooting_view');
10
+ $this->setTitle(Mage::helper('campaigner')->__('Troubleshooting'));
11
+ }
12
+
13
+ protected function _beforeToHtml()
14
+ {
15
+ $this->_updateActiveTab();
16
+ return parent::_beforeToHtml();
17
+ }
18
+
19
+ protected function _updateActiveTab()
20
+ {
21
+ $tabId = $this->getRequest()->getParam('tab');
22
+ if ($tabId) {
23
+ $tabId = preg_replace("#{$this->getId()}_#", '', $tabId);
24
+ if ($tabId) {
25
+ $this->setActiveTab($tabId);
26
+ }
27
+ }
28
+ }
29
+ }
app/code/community/Campaigner/Integration/Block/Adminhtml/Troubleshooting/View.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Adminhtml_Troubleshooting_View extends Mage_Adminhtml_Block_Widget_Form_Container
4
+ {
5
+ public function __construct()
6
+ {
7
+ $this->_blockGroup = "campaigner";
8
+ $this->_controller = 'adminhtml_troubleshooting';
9
+ $this->_mode = 'view';
10
+
11
+ parent::__construct();
12
+
13
+ $this->_removeButton('delete');
14
+ $this->_removeButton('reset');
15
+ $this->_removeButton('save');
16
+ $this->setId('troubleshooting_view');
17
+
18
+ $this->_addButton('refresh', array(
19
+ 'label' => Mage::helper('campaigner')->__('Refresh'),
20
+ 'onclick' => 'window.location.reload();',
21
+ ));
22
+
23
+ $this->setTemplate('campaigner/troubleshooting/view.phtml');
24
+ }
25
+
26
+ public function getHeaderText()
27
+ {
28
+ return Mage::helper('campaigner')->__('Campaigner Troubleshooting');
29
+ }
30
+
31
+ public function getUrl($params='', $params2=array())
32
+ {
33
+ return parent::getUrl($params, $params2);
34
+ }
35
+
36
+ public function getBackUrl()
37
+ {
38
+ return Mage::helper('campaigner')->getAdminUrl('adminhtml/system_config/edit/section/campaigner');
39
+ }
40
+ }
app/code/community/Campaigner/Integration/Block/Adminhtml/Troubleshooting/View/Form.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Adminhtml_Troubleshooting_View_Form extends Mage_Adminhtml_Block_Template
4
+ {
5
+ protected function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->setTemplate('campaigner/troubleshooting/view/form.phtml');
9
+ }
10
+ }
app/code/community/Campaigner/Integration/Block/Adminhtml/Troubleshooting/View/Tab/Download.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Adminhtml_Troubleshooting_View_Tab_Download
4
+ extends Mage_Adminhtml_Block_Template
5
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
6
+ {
7
+
8
+ public function getTabLabel()
9
+ {
10
+ return Mage::helper('campaigner')->__('Download Report');
11
+ }
12
+
13
+ public function getTabTitle()
14
+ {
15
+ return Mage::helper('campaigner')->__('Download Report');
16
+ }
17
+
18
+ public function canShowTab()
19
+ {
20
+ return true;
21
+ }
22
+
23
+ public function isHidden()
24
+ {
25
+ return false;
26
+ }
27
+
28
+ public function __construct()
29
+ {
30
+ parent::__construct();
31
+ $this->setTemplate('campaigner/troubleshooting/view/tab/download.phtml');
32
+ }
33
+
34
+ public function getTroubleEmail()
35
+ {
36
+ return Mage::helper('campaigner')->troubleConfig('email');
37
+ }
38
+
39
+ public function getTroubleSubject()
40
+ {
41
+ return Mage::helper('campaigner')->troubleConfig('subject');
42
+ }
43
+ }
app/code/community/Campaigner/Integration/Block/Adminhtml/Troubleshooting/View/Tab/Help.php ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Adminhtml_Troubleshooting_View_Tab_Help
4
+ extends Mage_Adminhtml_Block_Template
5
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
6
+ {
7
+ private $_columns = 3;
8
+
9
+ public function getTabLabel()
10
+ {
11
+ return Mage::helper('campaigner')->__('Help');
12
+ }
13
+
14
+ public function getTabTitle()
15
+ {
16
+ return Mage::helper('campaigner')->__('Help');
17
+ }
18
+
19
+ public function canShowTab()
20
+ {
21
+ return true;
22
+ }
23
+
24
+ public function isHidden()
25
+ {
26
+ return false;
27
+ }
28
+
29
+ public function __construct()
30
+ {
31
+ parent::__construct();
32
+ $this->setTemplate('campaigner/troubleshooting/view/tab/help.phtml');
33
+ }
34
+
35
+ private function getFields($data)
36
+ {
37
+ $fields = array();
38
+
39
+ foreach ($data as $key => $value) {
40
+ if (!is_object($value) && !is_array($value)) {
41
+ $fields[] = $key;
42
+ }
43
+ }
44
+
45
+ asort($fields);
46
+ return array_chunk($fields, ceil(count($fields) / $this->_columns));
47
+ }
48
+
49
+ public function getCustomerFields()
50
+ {
51
+ $customer = Mage::getModel('customer/customer')->getCollection()->getFirstItem();
52
+
53
+ $customer = Mage::getModel('customer/customer')->load($customer->getId());
54
+
55
+ return $this->getFields($customer->getData());
56
+ }
57
+
58
+ public function getAddressFields()
59
+ {
60
+ $address = Mage::getModel('customer/address')->getCollection()->getFirstItem();
61
+
62
+ $address = Mage::getModel('customer/address')->load($address->getId());
63
+
64
+ return $this->getFields($address->getData());
65
+ }
66
+
67
+ public function getShippingFields()
68
+ {
69
+ $shipping_fields = array('Shipping Code' => 1, 'Shipping Description' => 1, 'Tracking Carrier Code' => 1, 'Tracking Title' => 1, 'Tracking Number' => 1);
70
+
71
+ return $this->getFields($shipping_fields);
72
+ }
73
+ }
app/code/community/Campaigner/Integration/Block/Adminhtml/Troubleshooting/View/Tab/Info.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Adminhtml_Troubleshooting_View_Tab_Info
4
+ extends Mage_Adminhtml_Block_Template
5
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
6
+ {
7
+ public function getTabLabel()
8
+ {
9
+ return Mage::helper('campaigner')->__('Configuration Info');
10
+ }
11
+
12
+ public function getTabTitle()
13
+ {
14
+ return Mage::helper('campaigner')->__('Configuration Information');
15
+ }
16
+
17
+ public function canShowTab()
18
+ {
19
+ return true;
20
+ }
21
+
22
+ public function isHidden()
23
+ {
24
+ return false;
25
+ }
26
+
27
+ public function __construct()
28
+ {
29
+ parent::__construct();
30
+ $this->setTemplate('campaigner/troubleshooting/view/tab/info.phtml');
31
+ }
32
+
33
+ public function getEnvironmentInfo()
34
+ {
35
+ return Mage::helper('campaigner/troubleshooting')->getEnvironmentInfo();
36
+ }
37
+
38
+ public function getConfigurationInfo()
39
+ {
40
+ return Mage::helper('campaigner/troubleshooting')->getConfigurationInfo();
41
+ }
42
+ }
app/code/community/Campaigner/Integration/Block/Adminhtml/Troubleshooting/View/Tab/Log.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Adminhtml_Troubleshooting_View_Tab_Log
4
+ extends Mage_Adminhtml_Block_Template
5
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
6
+ {
7
+
8
+ public function getTabLabel()
9
+ {
10
+ return Mage::helper('campaigner')->__('Log File');
11
+ }
12
+
13
+ public function getTabTitle()
14
+ {
15
+ return Mage::helper('campaigner')->__('Log file');
16
+ }
17
+
18
+ public function canShowTab()
19
+ {
20
+ return true;
21
+ }
22
+
23
+ public function isHidden()
24
+ {
25
+ return false;
26
+ }
27
+
28
+ public function __construct()
29
+ {
30
+ parent::__construct();
31
+ $this->setTemplate('campaigner/troubleshooting/view/tab/log.phtml');
32
+ }
33
+
34
+ public function getLogFile()
35
+ {
36
+ return Mage::helper('campaigner/troubleshooting')->getLogFileContents();
37
+ }
38
+ }
app/code/community/Campaigner/Integration/Block/Adminhtml/Troubleshooting/View/Tab/Settings.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Adminhtml_Troubleshooting_View_Tab_Settings
4
+ extends Mage_Adminhtml_Block_Template
5
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
6
+ {
7
+ private $_helper = null;
8
+
9
+ public function getTabLabel()
10
+ {
11
+ return Mage::helper('campaigner')->__('Settings');
12
+ }
13
+
14
+ public function getTabTitle()
15
+ {
16
+ return Mage::helper('campaigner')->__('Settings');
17
+ }
18
+
19
+ public function canShowTab()
20
+ {
21
+ return true;
22
+ }
23
+
24
+ public function isHidden()
25
+ {
26
+ return false;
27
+ }
28
+
29
+ public function __construct()
30
+ {
31
+ $this->_helper = Mage::helper('campaigner/troubleshooting');
32
+ parent::__construct();
33
+ $this->setTemplate('campaigner/troubleshooting/view/tab/settings.phtml');
34
+ }
35
+
36
+ public function getLoggingStatus()
37
+ {
38
+ return $this->_helper->getLoggingStatus();
39
+ }
40
+
41
+ public function getDurationOptions()
42
+ {
43
+ return array(10 => "10 Minutes", 20 => "20 Minutes", 30 => "30 Minutes", 60 => "1 Hour", 1440 => "1 Day");
44
+ }
45
+
46
+ public function getSetting($setting)
47
+ {
48
+ return Mage::helper('campaigner/troubleshooting')->config($setting);
49
+ }
50
+
51
+ public function getArraySetting($setting)
52
+ {
53
+ return Mage::helper('campaigner/troubleshooting')->arrayConfig($setting);
54
+ }
55
+
56
+ public function getCurrentIP()
57
+ {
58
+ return Mage::helper('core/http')->getRemoteAddr();
59
+ }
60
+ }
app/code/community/Campaigner/Integration/Block/Adminhtml/Troubleshooting/View/Tab/Submit.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Adminhtml_Troubleshooting_View_Tab_Submit
4
+ extends Mage_Adminhtml_Block_Template
5
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
6
+ {
7
+ public function getTabLabel()
8
+ {
9
+ return Mage::helper('campaigner')->__('Send to Campaigner');
10
+ }
11
+
12
+ public function getTabTitle()
13
+ {
14
+ return Mage::helper('campaigner')->__('Send Information to Campaigner');
15
+ }
16
+
17
+ public function canShowTab()
18
+ {
19
+ return true;
20
+ }
21
+
22
+ public function isHidden()
23
+ {
24
+ return false;
25
+ }
26
+
27
+ public function __construct()
28
+ {
29
+ parent::__construct();
30
+ $this->setTemplate('campaigner/troubleshooting/view/tab/submit.phtml');
31
+ }
32
+
33
+ public function getLogFileSize()
34
+ {
35
+ return Mage::helper('campaigner/troubleshooting')->getLogFileSize();
36
+ }
37
+
38
+ public function getMaxLogFileSize()
39
+ {
40
+ return Mage::helper('campaigner')->formatSize(Mage::helper('campaigner/troubleshooting')->getMaxLogFileSize());
41
+ }
42
+
43
+ public function isLogFileTooLarge()
44
+ {
45
+ return Mage::helper('campaigner/troubleshooting')->isLogFileTooLarge();
46
+ }
47
+
48
+ public function getTroubleEmail()
49
+ {
50
+ return Mage::helper('campaigner')->troubleConfig('email');
51
+ }
52
+
53
+ public function getLogFileName()
54
+ {
55
+ return Mage::helper('campaigner/troubleshooting')->getLogFileName();
56
+ }
57
+ }
app/code/community/Campaigner/Integration/Block/Capture.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Capture extends Mage_Core_Block_Template
4
+ {
5
+ private $_active = false;
6
+
7
+ public function __construct()
8
+ {
9
+ if ($this->helper('campaigner')->canCapture()) {
10
+ $this->_active = true;
11
+ }
12
+ }
13
+
14
+ protected function _toHtml()
15
+ {
16
+ if (!$this->_active) {
17
+ return "";
18
+ }
19
+
20
+ return parent::_toHtml();
21
+ }
22
+
23
+ public function getFields()
24
+ {
25
+ $fields = array(
26
+ 'login-email',
27
+ 'newsletter',
28
+ 'email',
29
+ 'billing:email'
30
+ );
31
+
32
+ return $fields;
33
+ }
34
+
35
+ public function getCaptureUrl()
36
+ {
37
+ if (Mage::app()->getStore()->isCurrentlySecure()) {
38
+ return Mage::getUrl('campaigner/capture',array(
39
+ '_secure' => true
40
+ ));
41
+ }
42
+
43
+ return Mage::getUrl('campaigner/capture');
44
+ }
45
+ }
app/code/community/Campaigner/Integration/Block/Checkout/Subscribe.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Checkout_Subscribe extends Mage_Core_Block_Template
4
+ {
5
+ protected function _toHtml()
6
+ {
7
+ $alreadySubscribed = Mage::getModel('newsletter/subscriber')
8
+ ->loadByEmail($this->getQuote()->getCustomerEmail())
9
+ ->isSubscribed();
10
+
11
+ if (!$this->helper('campaigner')->canCheckoutSubscribe() || $alreadySubscribed) {
12
+ return "";
13
+ }
14
+
15
+ return parent::_toHtml();
16
+ }
17
+
18
+ public function getQuote()
19
+ {
20
+ return Mage::getSingleton('checkout/session')->getQuote();
21
+ }
22
+
23
+ public function checkStatus()
24
+ {
25
+ return (int)$this->helper('campaigner')->config('checkout_subscribe');
26
+ }
27
+ }
app/code/community/Campaigner/Integration/Block/Customer/Account/Lists.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Customer_Account_Lists extends Mage_Core_Block_Template
4
+ {
5
+ protected $_form;
6
+
7
+ public function getSubscriptions()
8
+ {
9
+ return Mage::helper('campaigner')->getSubscriptions($this->_getEmail());
10
+ }
11
+
12
+ /**
13
+ * Retrieve email from Customer object in session
14
+ *
15
+ * @return string Email address
16
+ */
17
+ protected function _getEmail()
18
+ {
19
+ return $this->helper('customer')->getCustomer()->getEmail();
20
+ }
21
+ }
app/code/community/Campaigner/Integration/Block/Signup.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Signup extends Mage_Core_Block_Template
4
+ {
5
+ protected function _toHtml()
6
+ {
7
+ if (!$this->helper('campaigner')->campaignerEnabled() || !$this->helper('campaigner')->config('signup_enabled')) {
8
+ return "";
9
+ }
10
+
11
+ return parent::_toHtml();
12
+ }
13
+
14
+ public function isSignupEnabled()
15
+ {
16
+ return $this->helper('campaigner')->isSignupEnabled() ? 'true' : 'false';
17
+ }
18
+
19
+ public function getSignupDelay()
20
+ {
21
+ return (int)$this->helper('campaigner')->config('signup_delay') * 1000;
22
+ }
23
+
24
+ public function getSignupCheckUrl()
25
+ {
26
+ $arguments = array();
27
+
28
+ if (Mage::app()->getStore()->isCurrentlySecure()) {
29
+ $arguments['_secure'] = true;
30
+ }
31
+
32
+ return $this->getUrl('campaigner/signup/check', $arguments);
33
+ }
34
+ }
app/code/community/Campaigner/Integration/Block/Widget/Grid/Column/Renderer/Abandoned/Minutes.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Campaigner_Integration_Block_Widget_Grid_Column_Renderer_Abandoned_Minutes extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
3
+ {
4
+ public function render(Varien_Object $row)
5
+ {
6
+ $processed_date = $row->getData('date_sent');
7
+
8
+ if ($processed_date != "") {
9
+ return "";
10
+ }
11
+
12
+ $abandoned_date = strtotime($row->getData('updated_at'));
13
+
14
+ $current_date = Mage::getModel('core/date')->gmtTimestamp();
15
+
16
+ $minutes = round(abs($current_date - $abandoned_date) / 60,0);
17
+
18
+ $class = 'ab_ok';
19
+ if ($minutes > 60) {
20
+ $class = 'ab_ng';
21
+ }
22
+
23
+ return "<span class='{$class}'>{$minutes}</span>";
24
+ }
25
+ }
app/code/community/Campaigner/Integration/Block/Widget/Grid/Column/Renderer/Action.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Block_Widget_Grid_Column_Renderer_Action extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Action
4
+ {
5
+ public function render(Varien_Object $row)
6
+ {
7
+ $processed_date = $row->getData('date_sent');
8
+
9
+ $store_id = $row->getData('store_id');
10
+
11
+ if (!Mage::helper('campaigner')->getAbandonedEnabled($store_id)) {
12
+ return '';
13
+ }
14
+
15
+ $processed = $processed_date != "";
16
+
17
+ $actions = $this->getColumn()->getActions();
18
+ if (empty($actions) || !is_array($actions)) {
19
+ return '&nbsp;';
20
+ }
21
+
22
+ $out = "";
23
+
24
+ foreach ($actions as $action) {
25
+ if (is_array($action)) {
26
+ // Change text if cart has already been sent
27
+ if ($action['sent'] == $processed) {
28
+ if ($out != "") {
29
+ $out .= "<br />";
30
+ }
31
+
32
+ $out .= $this->_toLinkHtml($action, $row);
33
+ }
34
+ }
35
+ }
36
+ return $out;
37
+ }
38
+ }
app/code/community/Campaigner/Integration/Controller/Front/Abstract.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Controller_Front_Abstract extends Mage_Core_Controller_Front_Action
4
+ {
5
+ protected $_helper = null;
6
+ protected $_logger = null;
7
+
8
+ public function __construct(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response, array $invokeArgs = array())
9
+ {
10
+ $this->_helper = Mage::helper('campaigner');
11
+ $this->_logger = Mage::helper('campaigner/troubleshooting');
12
+
13
+ return parent::__construct($request, $response, $invokeArgs);
14
+ }
15
+
16
+ protected function _log($data, $prefix = "")
17
+ {
18
+ $this->_logger->log($data, $prefix);
19
+ }
20
+
21
+ protected function _logException($e)
22
+ {
23
+ $this->_logger->logException($e);
24
+ }
25
+
26
+ protected function _logReason($data)
27
+ {
28
+ $this->_logger->logReason($data);
29
+ }
30
+
31
+ protected function _setLogArea($area)
32
+ {
33
+ $this->_logger->setLogArea($area);
34
+ }
35
+ }
app/code/community/Campaigner/Integration/Helper/Abandoned.php ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Helper_Abandoned extends Campaigner_Integration_Helper_Data
4
+ {
5
+ private $_sequences = null;
6
+ private $_current_sequence = 0;
7
+ private $_sequence_enabled = false;
8
+ private $_sequence_field = "";
9
+
10
+ public function getAbandonedUrl($quote)
11
+ {
12
+ // We are using comma separated lists for the ID's and Quantities so that it takes up less
13
+ // space when we generate the Querystring
14
+
15
+ $item_data = array();
16
+
17
+ $this->debug("Get Abandoned URL");
18
+
19
+ foreach ($quote->getAllItems() as $item) {
20
+ $product = $this->getProduct($item);
21
+ $parent_id = $item->getParentItemId();
22
+ $item_id = $item->getId();
23
+
24
+ if ($parent_id != null) {
25
+ $item_data[$parent_id]['option'] = $product->getId();
26
+ } else {
27
+ $item_data[$item_id]['product_id'] = $product->getId();
28
+ $item_data[$item_id]['qty'] = $item->getQty();
29
+
30
+ if ($item->getProductType() == 'grouped') {
31
+ $option = $item->getOptionByCode('product_type');
32
+ if ($option) {
33
+ $product = $option->getProduct();
34
+ $item_data[$item_id]['option'] = $product->getId();
35
+ }
36
+ } else if ($item->getProductType() == 'bundle') {
37
+ $option = $item->getOptionByCode('info_buyRequest');
38
+
39
+ if ($option) {
40
+ $data = unserialize($option->getValue());
41
+
42
+ $bundle_option = "";
43
+
44
+ foreach ($data['bundle_option'] as $id => $value) {
45
+ if ($bundle_option != "") {
46
+ $bundle_option .= "-";
47
+ }
48
+
49
+ $bundle_option .= "{$id}=";
50
+
51
+ if (is_array($value)) {
52
+ $bundle_option .= implode(":",$value);
53
+ } else {
54
+ $qty = $data['bundle_option_qty'][$id];
55
+ $bundle_option .= "{$value}~{$qty}";
56
+ }
57
+ }
58
+ $item_data[$item_id]['bundle_option'] = $bundle_option;
59
+ }
60
+ }
61
+ }
62
+ }
63
+
64
+ $ids = "";
65
+ $qtys = "";
66
+
67
+ $this->debug("Item Data:");
68
+ $this->debug($item_data);
69
+
70
+ foreach ($item_data as $item) {
71
+ if ($ids != "") {
72
+ $ids .= ",";
73
+ $qtys .= ",";
74
+ }
75
+
76
+ $ids .= $item['product_id'];
77
+ $qtys .= $item['qty'];
78
+
79
+ if (isset($item['bundle_option'])) {
80
+ $ids .= "|{$item['bundle_option']}";
81
+ } else if (isset($item['option'])) {
82
+ $ids .= "|{$item['option']}";
83
+ }
84
+ }
85
+
86
+ $url_data = array("quote" => $quote->getId(), "id" => $ids, "qty" => $qtys);
87
+
88
+ //$this->logAndDebug($url_data, "Abandoned Url Data");
89
+ $this->debug("URL Data:");
90
+ $this->debug($url_data);
91
+
92
+ $url = base64_encode(serialize($url_data));
93
+
94
+ $url = Mage::getUrl('campaigner/abandoned/restore',array('_secure'=>true)) . "?cart={$url}";
95
+
96
+ $this->debug("URL:");
97
+ $this->debug($url);
98
+
99
+ return $url;
100
+ }
101
+
102
+ public function getLastOrder($quote)
103
+ {
104
+ $this->logAndDebug("Get Last Order");
105
+ $customer_id = $quote->getData('customer_id');
106
+
107
+ $this->logAndDebug("Customer ID: {$customer_id}");
108
+
109
+ $orders = Mage::getResourceModel('sales/order_collection')
110
+ ->addFieldToSelect('*')
111
+ ->addFieldToFilter('customer_id', $customer_id)
112
+ ->addAttributeToSort('created_at', 'DESC')
113
+ ->setPageSize(1);
114
+
115
+ $this->logAndDebug("Order Count: " . $orders->getSize());
116
+ if ($orders->getSize() <= 0) {
117
+ $this->logAndDebug("No Orders Found");
118
+ return null;
119
+ }
120
+
121
+ $this->logAndDebug("Order Found");
122
+ $order = $orders->getFirstItem();
123
+
124
+ return $order;
125
+ }
126
+
127
+ public function addSequence(&$merge_vars)
128
+ {
129
+ if (!$this->_sequence_enabled) {
130
+ return;
131
+ }
132
+
133
+ if (!isset($this->_sequences[$this->_current_sequence])) {
134
+ $this->_current_sequence = 0;
135
+ }
136
+
137
+ $merge_vars[$this->_sequence_field] = $this->_sequences[$this->_current_sequence++];
138
+ }
139
+
140
+ public function setupSequence()
141
+ {
142
+ $this->_sequence_enabled = $this->config('abandonedsequence_enabled');
143
+
144
+ if (!$this->_sequence_enabled) {
145
+ return;
146
+ }
147
+
148
+ $sequences = str_replace("\r\n","\n",$this->config('abandonedsequence_options'));
149
+ $this->_current_sequence = $this->config('abandonedsequence_current');
150
+
151
+ if (!is_numeric($this->_current_sequence)) {
152
+ $this->_current_sequence = 0;
153
+ }
154
+
155
+ $this->_sequences = explode("\n",$sequences);
156
+ $this->_sequence_field = $this->config('abandonedsequence_field');
157
+ }
158
+
159
+ public function saveCurrentSequence()
160
+ {
161
+ if (!$this->_sequence_enabled) {
162
+ return;
163
+ }
164
+
165
+ $this->updateConfig('abandonedsequence_current',$this->_current_sequence);
166
+ }
167
+ }
app/code/community/Campaigner/Integration/Helper/Data.php ADDED
@@ -0,0 +1,1061 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+ const DATE_FORMAT = "Y-m-d H:i:s";
6
+
7
+ const DISABLED_REASON_PREFIX = "Skipping";
8
+
9
+ protected $_logger = null;
10
+
11
+ public function __construct()
12
+ {
13
+ $this->_logger = Mage::helper('campaigner/troubleshooting');
14
+ }
15
+
16
+ protected function logAndDebug($data)
17
+ {
18
+ $this->_logger->logAndDebug($data);
19
+ }
20
+
21
+ public function log($data)
22
+ {
23
+ $this->_logger->log($data);
24
+ }
25
+
26
+ protected function debug($data)
27
+ {
28
+ $this->_logger->debug($data);
29
+ }
30
+
31
+ protected function debugHeader($data, $level = 2)
32
+ {
33
+ $this->_logger->debugHeader($data, $level);
34
+ }
35
+
36
+ public function getQuoteMergeVarsOld($quote)
37
+ {
38
+ // Make it more like getMergeVars where it uses the field maps!!!
39
+ $merge_vars = array();
40
+ $merge_vars['First Name'] = $quote->getData('customer_firstname');
41
+ $merge_vars['Last Name'] = $quote->getData('customer_lastname');
42
+
43
+ $billing = $quote->getBillingAddress();
44
+
45
+ if ($billing) {
46
+ $merge_vars['Phone'] = $billing->getTelephone();
47
+ $merge_vars['Fax'] = $billing->getFax();
48
+ }
49
+
50
+ return $merge_vars;
51
+ }
52
+
53
+ public function getQuoteMergeVars($quote)
54
+ {
55
+ $merge_vars = array();
56
+
57
+ $maps = unserialize( $this->config('map_fields', $quote->getStoreId()) );
58
+
59
+ if ($maps) {
60
+ $customer = new Varien_Object();
61
+ $customer->setData('firstname', $quote->getData('customer_firstname'));
62
+ $customer->setData('lastname', $quote->getData('customer_lastname'));
63
+
64
+ $this->debug("Customer Field Mapping");
65
+ $this->processMap($merge_vars, $maps, $customer);
66
+ }
67
+
68
+ $address_maps = unserialize( $this->config('address_fields', $customer->getStoreId()) );
69
+
70
+ // Process address
71
+ if ($address_maps) {
72
+ $address = $quote->getBillingAddress();
73
+
74
+ if ($address) {
75
+ $this->debug("Address Field Mapping");
76
+ $this->processMap($merge_vars, $address_maps, $address);
77
+ }
78
+ }
79
+
80
+ return $merge_vars;
81
+ }
82
+
83
+ public function getMergeVars($customer)
84
+ {
85
+ $merge_vars = array();
86
+ $maps = unserialize( $this->config('map_fields', $customer->getStoreId()) );
87
+
88
+ if ($maps) {
89
+ $this->debug("Customer Field Mapping");
90
+ $this->processMap($merge_vars, $maps, $customer);
91
+ }
92
+
93
+ $address_maps = unserialize( $this->config('address_fields', $customer->getStoreId()) );
94
+
95
+ // Process address
96
+ if ($address_maps) {
97
+ $address = Mage::getModel('customer/address')->load($customer->getDefaultBilling());
98
+
99
+ if ($address) {
100
+ $this->debug("Address Field Mapping");
101
+ $this->processMap($merge_vars, $address_maps, $address);
102
+ }
103
+ }
104
+
105
+ return $merge_vars;
106
+ }
107
+
108
+ protected function processMap(&$merge_vars,$maps, $data)
109
+ {
110
+ $request = Mage::app()->getRequest();
111
+
112
+ $this->debug("Mappings");
113
+ $this->debug($maps);
114
+
115
+ $this->debug("Map Data");
116
+ $this->debug($data);
117
+
118
+ foreach ($maps as $map) {
119
+ // Make sure we have values for both
120
+ if (!isset($map['magento']) || !isset($map['campaigner'])) {
121
+ continue;
122
+ }
123
+
124
+ $custom_field = $map['magento'];
125
+ $campaigner_field = $map['campaigner'];
126
+
127
+ if ($campaigner_field && $custom_field) {
128
+ switch ($custom_field) {
129
+ case 'state_code':
130
+ {
131
+ $region_id = $data->getData('region_id');
132
+
133
+ if (!$region_id)
134
+ continue;
135
+
136
+ $region = Mage::getModel('directory/region')->load($region_id);
137
+
138
+ if (!$region)
139
+ continue;
140
+
141
+ $state_code = $region->getCode();
142
+
143
+ if ($state_code != "")
144
+ $merge_vars[$campaigner_field] = $state_code;
145
+ } break;
146
+ default:
147
+ {
148
+ if (($value = (string)$data->getData(strtolower($custom_field))) || ($value = (string)$request->getPost(strtolower($custom_field)))) {
149
+ $merge_vars[$campaigner_field] = $value;
150
+ }
151
+ } break;
152
+ }
153
+ }
154
+ }
155
+ }
156
+
157
+ protected function getProduct($item)
158
+ {
159
+ $product_id = $item->getProductId();
160
+
161
+ if (!$product_id) {
162
+ return null;
163
+ }
164
+
165
+ $product = Mage::getModel('catalog/product')->load($product_id);
166
+
167
+ if ($product == null || !$product->getId()) {
168
+ return null;
169
+ }
170
+
171
+ return $product;
172
+ }
173
+
174
+ // Used to restore configurable products to the cart
175
+ public function getConfigurableOptions($product, $simple_product_id)
176
+ {
177
+ $type_instance = $product->getTypeInstance(true);
178
+ $child_products = $type_instance->getUsedProducts(null, $product);
179
+ $attrbutes = $type_instance->getUsedProductAttributes($product);
180
+
181
+ $super_attrbutes = array();
182
+
183
+ foreach ($child_products as $child) {
184
+ if ($child->getId() == $simple_product_id) {
185
+ foreach ($attrbutes as $attribute) {
186
+ $super_attrbutes[$attribute->getAttributeId()] = $child->getData($attribute->getAttributeCode());
187
+ }
188
+ }
189
+ }
190
+
191
+ return $super_attrbutes;
192
+ }
193
+
194
+ public function getStoreId($code)
195
+ {
196
+ if ($code == null) {
197
+ return 0;
198
+ }
199
+
200
+ try {
201
+ $store = Mage::getModel("core/store")->load($code);
202
+ return $store->getId();
203
+ } catch (Exception $e) {
204
+ return 0;
205
+ }
206
+ }
207
+
208
+ public function getAdminStore()
209
+ {
210
+ $code = Mage::app()->getRequest()->getParam('store');
211
+
212
+ return $this->getStoreId($code);
213
+ }
214
+
215
+ public function getUrlParams()
216
+ {
217
+ $param_options = array('store','group','website');
218
+
219
+ $request = Mage::app()->getRequest();
220
+
221
+ foreach ($param_options as $param) {
222
+ if ($request->getParam($param) != null) {
223
+ return array($param => $request->getParam($param));
224
+ }
225
+ }
226
+
227
+ return array();
228
+ }
229
+
230
+ public function forceSubscribe()
231
+ {
232
+ $option = (int)$this->config('checkout_subscribe');
233
+
234
+ // Force subscribe on
235
+ if ($option == 3) {
236
+ return true;
237
+ }
238
+
239
+ return false;
240
+ }
241
+
242
+ public function formatSize($size)
243
+ {
244
+ try {
245
+ if ($size == 0 || $size == null || $size == "") {
246
+ return "0 b";
247
+ }
248
+
249
+ $unit = array('b','kb','mb','gb','tb','pb');
250
+
251
+ $numeric_size = @round($size/pow(1024,($i=$size?floor(log($size,1024)):0)),2);
252
+
253
+ if (!isset($unit[$i])) {
254
+ return "Unknown";
255
+ }
256
+
257
+ return "{$numeric_size} {$unit[$i]}";
258
+ } catch (Exception $e) {
259
+ $this->_logger->logException($e);
260
+ return "Unknown";
261
+ }
262
+ }
263
+
264
+ public function getDuration($timeline, $zero = false)
265
+ {
266
+ $periods = array('day' => 86400, 'hour' => 3600, 'minute' => 60);
267
+
268
+ $ret = "";
269
+
270
+ foreach($periods as $name => $seconds) {
271
+ $num = floor($timeline / $seconds);
272
+
273
+ if ($num > 0 || ($num == 0 && $zero == true)) {
274
+ $timeline -= ($num * $seconds);
275
+ $ret .= $num.' '.$name.(($num > 1 || $num == 0) ? 's' : '').' ';
276
+ }
277
+ }
278
+
279
+ return trim($ret);
280
+ }
281
+
282
+ public function timeElapsed2string($time)
283
+ {
284
+ if ($time == "") {
285
+ return "";
286
+ }
287
+
288
+ if (is_string($time)) {
289
+ $time = strtotime($time);
290
+ }
291
+
292
+ $timeline = time() - $time;
293
+
294
+ return $this->getDuration($timeline);
295
+ }
296
+
297
+ public function getExportFileName($name,$full = true)
298
+ {
299
+ $filename = "{$name}.csv";
300
+
301
+ if ($full) {
302
+ return Mage::getBaseDir('export').'/' . $filename;
303
+ }
304
+
305
+ return $filename;
306
+ }
307
+
308
+ public function getApiKey($store = null)
309
+ {
310
+ return $this->config('apikey',$store);
311
+ }
312
+
313
+ public function isWebsiteConfig()
314
+ {
315
+ $request = Mage::app()->getRequest();
316
+
317
+ if ($request->getParam('website') && !$request->getParam('store')) {
318
+ return true;
319
+ }
320
+
321
+ return false;
322
+ }
323
+
324
+ public function updateConfig($path, $value, $store = 0, $base_path = 'general')
325
+ {
326
+ $scope = "stores";
327
+
328
+ if ($store === null) {
329
+ $store = $this->getCurrentStore();
330
+ }
331
+
332
+ if ($store == 0) {
333
+ $scope = "default";
334
+ }
335
+
336
+ $config = Mage::getConfig();
337
+ $config->saveConfig("campaigner/{$base_path}/{$path}",$value,$scope,$store);
338
+ $config->cleanCache();
339
+ }
340
+
341
+ public function updateConfigForApi($path, $value, $store = 0, $base_path = 'general')
342
+ {
343
+ $scope = "stores";
344
+
345
+ if ($store == null) {
346
+ $store = $this->getCurrentStore();
347
+ }
348
+
349
+ if ($store == 0) {
350
+ $scope = "default";
351
+ } else {
352
+ if (!$this->storeHasCustomAPI($store)) {
353
+
354
+ $this->deleteConfig($path, $store);
355
+ $store = 0;
356
+ $scope = "default";
357
+
358
+ // Remove old one!!!
359
+ }
360
+ }
361
+
362
+ $config = Mage::getConfig();
363
+ $config->saveConfig("campaigner/{$base_path}/{$path}",$value,$scope,$store);
364
+ $config->cleanCache();
365
+ }
366
+
367
+ public function deleteConfig($path, $store = 0, $base_path = 'general')
368
+ {
369
+ $scope = "stores";
370
+
371
+ if ($store == null) {
372
+ $store = $this->getCurrentStore();
373
+ }
374
+
375
+ if ($store == 0) {
376
+ $scope = "default";
377
+ }
378
+
379
+ $config = Mage::getConfig();
380
+ $config->deleteConfig("campaigner/{$base_path}/{$path}",$scope,$store);
381
+ $config->cleanCache();
382
+ }
383
+
384
+ public function resetCurrentStore()
385
+ {
386
+ $this->_current_store = null;
387
+ }
388
+
389
+ public function getCurrentStore()
390
+ {
391
+ $store = Mage::app()->getStore()->getId();
392
+ $config_store = Mage::app()->getRequest()->getParam('store');
393
+ $on_config = $this->onConfigPage();
394
+
395
+ if ($config_store && $on_config) {
396
+ $store = $config_store;
397
+ }
398
+
399
+ if (is_string($store)) {
400
+ return $this->getStoreId($store);
401
+ }
402
+
403
+ return $store;
404
+ }
405
+
406
+ private function _config($value, $section, $store = null)
407
+ {
408
+ if (is_null($store)) {
409
+ $store = (int)$this->getCurrentStore();
410
+ }
411
+
412
+ $realvalue = Mage::getStoreConfig("campaigner/{$section}/{$value}", $store);
413
+
414
+ return $realvalue;
415
+ }
416
+
417
+ public function fullConfig($value, $area, $section, $store = null)
418
+ {
419
+ if (is_null($store)) {
420
+ $store = $this->getCurrentStore();
421
+ }
422
+
423
+ $realvalue = Mage::getStoreConfig("{$area}/{$section}/{$value}", $store);
424
+
425
+ return $realvalue;
426
+ }
427
+
428
+ public function config($value, $store = null)
429
+ {
430
+ return $this->_config($value,'general',$store);
431
+ }
432
+
433
+ public function exportConfig($value, $store = null)
434
+ {
435
+ return $this->_config($value,'export',$store);
436
+ }
437
+
438
+ public function troubleConfig($value, $store = null)
439
+ {
440
+ return $this->_config($value,'troubleshooting',$store);
441
+ }
442
+
443
+ public function getRelayStatus()
444
+ {
445
+ $disable = $this->fullConfig("disable", "system", "smtp");
446
+ $relay = $this->fullConfig("campaigner_use_smtp_relay","system","smtp");
447
+
448
+ return array('smtp_disable' => $disable, 'relay' => $relay);
449
+ }
450
+
451
+ public function getCampaignerColumnOptions()
452
+ {
453
+ $columns = Mage::getSingleton('campaigner/wrapper_database')->getAllColumns(true, true, false);
454
+
455
+ $options = array();
456
+
457
+ if ($columns == null || !isset($columns)) {
458
+ return $options;
459
+ }
460
+
461
+ $custom_fields = Mage::helper('campaigner/fields')->getCustomFields(true, false);
462
+
463
+ $invalid_columns = array();
464
+
465
+ foreach ($custom_fields as $cf) {
466
+ if (strpos($cf['name'],'AbandonedSequence') === false) {
467
+ $invalid_columns[] = $cf['name'];
468
+ }
469
+ }
470
+
471
+ foreach ($columns as $column) {
472
+ if (!in_array((string)$column->Name,$invalid_columns)) {
473
+ $key = (string)$column->Name;
474
+
475
+ $options[$key] = $key;
476
+ }
477
+ }
478
+
479
+ return $options;
480
+ }
481
+
482
+ public function getShippingColumnOptions()
483
+ {
484
+ $options = array(
485
+ 'shipping_code' => 'Shipping Code',
486
+ 'shipping_description' => 'Shipping Description',
487
+ 'carrier_code' => 'Tracking Carrier Code',
488
+ 'title' => 'Tracking Title',
489
+ 'number' => 'Tracking Number');
490
+
491
+ return $options;
492
+ }
493
+
494
+ public function getDefaultPublication($storeId)
495
+ {
496
+ return $this->config('publication', $storeId);
497
+ }
498
+
499
+ public function isSignupTest()
500
+ {
501
+ return Mage::app()->getRequest()->getParam('signup_test') == "true";
502
+ }
503
+
504
+ public function canCapture()
505
+ {
506
+ if (!$this->campaignerEnabled()) {
507
+ return false;
508
+ }
509
+
510
+ if ((bool)($this->config('capture_enabled') != 0) && !Mage::helper('customer')->isLoggedIn()) {
511
+ return true;
512
+ }
513
+
514
+ return false;
515
+ }
516
+
517
+ public function canSendWishlist()
518
+ {
519
+ if (!$this->campaignerEnabled()) {
520
+ return false;
521
+ }
522
+
523
+ if (Mage::helper('customer')->isLoggedIn() && (bool)($this->config('wishlist_enabled') != 0)) {
524
+ return true;
525
+ }
526
+
527
+ return false;
528
+ }
529
+
530
+ public function canSendLastLogin()
531
+ {
532
+ if (!$this->campaignerEnabled()) {
533
+ return false;
534
+ }
535
+
536
+ if (Mage::helper('customer')->isLoggedIn() && (bool)($this->config('lastlogin_enabled') != 0)) {
537
+ return true;
538
+ }
539
+
540
+ return false;
541
+ }
542
+
543
+ public function isSignupEnabled()
544
+ {
545
+ if (!$this->campaignerEnabled()) {
546
+ return false;
547
+ }
548
+
549
+ if ((bool)($this->config('signup_enabled') == 0) || (bool)($this->config('signup_activated') == 0)) {
550
+ return false;
551
+ }
552
+
553
+ return true;
554
+ }
555
+
556
+ public function canShowSignup()
557
+ {
558
+ if ($this->isSignupTest()) {
559
+ return true;
560
+ }
561
+
562
+ if (!$this->isSignupEnabled()) {
563
+ return false;
564
+ }
565
+
566
+ $last_closed = Mage::getModel('core/cookie')->get('ed_signup');
567
+
568
+ $recurrence = $this->config('signup_recurrence');
569
+
570
+ if ($last_closed == "") {
571
+ return true;
572
+ }
573
+
574
+ switch ($recurrence) {
575
+ case "once": return false;
576
+ default:
577
+ $last_closed = strtotime("+{$recurrence}",$last_closed); break;
578
+ }
579
+
580
+ if ($last_closed > time()) {
581
+ return false;
582
+ }
583
+
584
+ return true;
585
+ }
586
+
587
+ public function canCheckoutSubscribe()
588
+ {
589
+ if (!$this->campaignerEnabled()) {
590
+ return false;
591
+ }
592
+
593
+ return (bool)($this->config('checkout_subscribe') != 0);
594
+ }
595
+
596
+ public function campaignerEnabled()
597
+ {
598
+ $active = $this->config('active');
599
+ $setup = $this->config('setup');
600
+ $locked = $this->config('locked');
601
+
602
+ if ($active && $setup) {
603
+ return true;
604
+ }
605
+
606
+ if ($locked) {
607
+ return false;
608
+ }
609
+
610
+ return $this->onConfigPage();
611
+ }
612
+
613
+ private function storeHasCustomAPI($store_id)
614
+ {
615
+ $sql = "SELECT * FROM core_config_data WHERE scope='stores' AND scope_id='{$store_id}' AND path = 'campaigner/general/api_username'";
616
+
617
+ $data = Mage::getSingleton('core/resource')
618
+ ->getConnection('core_read')
619
+ ->query($sql)
620
+ ->fetchAll();
621
+
622
+ if (count($data) == 0) {
623
+ return false;
624
+ }
625
+
626
+ return true;
627
+ }
628
+
629
+ public function disableCampaigner($store_id = 0, $locked = false)
630
+ {
631
+ if (Mage::registry('validation_mode')) {
632
+ return;
633
+ }
634
+
635
+ if ($store_id != 0) {
636
+ if (!$this->storeHasCustomAPI($store_id)) {
637
+ $store_id = 0;
638
+ }
639
+ }
640
+
641
+ $this->updateConfig('setup', 0, $store_id);
642
+ $this->updateConfig('active', 0, $store_id);
643
+ if ($locked) {
644
+ $this->updateConfig('locked', 1, $store_id);
645
+ }
646
+ }
647
+
648
+ public function enableCampaigner($store_id = 0)
649
+ {
650
+ if ($store_id != 0) {
651
+ if (!$this->storeHasCustomAPI($store_id)) {
652
+ $this->deleteConfig('setup',$store_id);
653
+ $this->deleteConfig('locked',$store_id);
654
+ $store_id = 0;
655
+ }
656
+ }
657
+
658
+ $this->updateConfig('setup', true, $store_id);
659
+ $this->updateConfig('locked', false, $store_id);
660
+ }
661
+
662
+ public function onConfigPage()
663
+ {
664
+ $controller = Mage::app()->getRequest()->getControllerName();
665
+
666
+ if ($controller == 'system_config') {
667
+ return true;
668
+ }
669
+
670
+ return false;
671
+ }
672
+
673
+ public function registerGuestCustomer($order)
674
+ {
675
+ if (Mage::registry('campaigner_guest_customer')) {
676
+ return;
677
+ }
678
+
679
+ $customer = new Varien_Object;
680
+
681
+ $customer->setId(time());
682
+ $customer->setEmail($order->getBillingAddress()->getEmail());
683
+ $customer->setStoreId($order->getStoreId());
684
+ $customer->setFirstname($order->getBillingAddress()->getFirstname());
685
+ $customer->setLastname($order->getBillingAddress()->getLastname());
686
+ $customer->setPrimaryBillingAddress($order->getBillingAddress());
687
+ $customer->setPrimaryShippingAddress($order->getShippingAddress());
688
+ Mage::register('campaigner_guest_customer', $customer, TRUE);
689
+ }
690
+
691
+ public function getFullStoreName($store)
692
+ {
693
+ if ($store == null) {
694
+ return "Unknown";
695
+ }
696
+
697
+ $store_name = "";
698
+
699
+ if ($website = $store->getWebsite()) {
700
+ $store_name .= $website->getName() . " - ";
701
+ }
702
+
703
+ if ($group = $store->getGroup()) {
704
+ $store_name .= $group->getName() . " - ";
705
+ }
706
+
707
+ $store_name .= $store->getName();
708
+
709
+ return $store_name;
710
+ }
711
+
712
+ public function getFullStoreNameById($store_id)
713
+ {
714
+ $store = Mage::getModel('core/store')->load($store_id);
715
+
716
+ return $this->getFullStoreName($store);
717
+ }
718
+
719
+ public function getAbandonedStatus()
720
+ {
721
+ $stores = Mage::app()->getStores();
722
+
723
+ $abandoned_status = array(
724
+ 'enabled' => false,
725
+ 'cron_last_run' => $this->getCronLastRunHtml(),
726
+ 'stores' => array()
727
+ );
728
+
729
+ foreach ($stores as $store) {
730
+ $data = array();
731
+
732
+ $data['id'] = $store->getId();
733
+ $data['name'] = $this->getFullStoreName($store);
734
+ $data['enabled'] = $this->getAbandonedEnabled($store->getId());
735
+ if ($data['enabled']) {
736
+ $abandoned_status['enabled'] = true;
737
+ }
738
+
739
+ $data['last_run'] = $this->getAbandonedLastRunhtml($store->getId());
740
+
741
+ $abandoned_status['stores'][] = $data;
742
+ }
743
+
744
+ return $abandoned_status;
745
+ }
746
+
747
+ public function getLatestStatus()
748
+ {
749
+ $stores = Mage::app()->getStores();
750
+
751
+ $latest_status = array(
752
+ 'enabled' => false,
753
+ 'cron_last_run' => $this->getLatestCronLastRunHtml(),
754
+ 'stores' => array()
755
+ );
756
+
757
+ foreach ($stores as $store) {
758
+ $data = array();
759
+
760
+ $data['id'] = $store->getId();
761
+ $data['name'] = $this->getFullStoreName($store);
762
+ $data['enabled'] = $this->config('save_latest_order',$store->getId());
763
+ if ($data['enabled']) {
764
+ $latest_status['enabled'] = true;
765
+ }
766
+
767
+ $data['last_run'] = $this->getLatestLastRunhtml($store->getId());
768
+
769
+ $latest_status['stores'][] = $data;
770
+ }
771
+
772
+ return $latest_status;
773
+ }
774
+
775
+ public function getCronLastRun($store = null, $config = 'abandoned_last_run')
776
+ {
777
+ $last_run = $this->config($config, $store);
778
+
779
+ $data = array();
780
+
781
+ if ($last_run != null) {
782
+ $data['last_run'] = $last_run;
783
+
784
+ $minutes = round(abs(time() - strtotime($last_run)) / 60,0);
785
+
786
+ $data['minutes'] = $minutes;
787
+
788
+ if ($minutes > 60) {
789
+ $data['class'] = 'ab_ng';
790
+ } else {
791
+ $data['class'] = 'ab_ok';
792
+ }
793
+
794
+ $data['last_run_display'] = Mage::helper('core')->formatTime($last_run, 'long', true);
795
+ $data['time_elapsed'] = $this->timeElapsed2string($last_run);
796
+ } else {
797
+ $data['last_run'] = 'NEVER';
798
+ $data['minutes'] = -1;
799
+ $data['last_run_display'] = 'NEVER';
800
+ $data['time_elapsed'] = "";
801
+ $data['class'] = 'ab_ng';
802
+ }
803
+
804
+ return $data;
805
+ }
806
+
807
+ private function getLastRunHtml($store = null, $config = 'abandoned_last_run')
808
+ {
809
+ $data = $this->getCronLastRun($store,$config);
810
+ $warning_img = "";
811
+
812
+ if ($data['class'] == "ab_ng") {
813
+ $warning_img = "<a href='" . $this->getAdminUrl("campaigner_dashboard/admin_troubleshooting/index") . "#abandoned_carts' target='_blank'><img src='" . Mage::getDesign()->getSkinUrl('images/warning_msg_icon.gif') . "' class='cron_warning' /></a>";
814
+ }
815
+
816
+ $time_elapsed = "";
817
+
818
+ if ($data['time_elapsed'] != '') {
819
+ $time_elapsed = "({$data['time_elapsed']})";
820
+ }
821
+
822
+ return "<span class='{$data['class']}'>{$data['last_run_display']} {$time_elapsed}</span>{$warning_img}";
823
+ }
824
+
825
+ public function getAbandonedLastRunHtml($store = null)
826
+ {
827
+ return $this->getLastRunHtml($store);
828
+ }
829
+
830
+ public function getLatestLastRunHtml($store = null)
831
+ {
832
+ return $this->getLastRunHtml($store, 'latest_last_run');
833
+ }
834
+
835
+ public function getCronLastRunHtml()
836
+ {
837
+ return $this->getLastRunHtml(0, 'cron_last_run');
838
+ }
839
+
840
+ public function getLatestCronLastRunHtml()
841
+ {
842
+ return $this->getLastRunHtml(0, 'latest_cron_last_run');
843
+ }
844
+
845
+ public function getAdminUrlParams($params = array())
846
+ {
847
+ $request = Mage::app()->getRequest();
848
+ $url_params = array('website','store');
849
+
850
+ foreach ($url_params as $up) {
851
+ if ($request->getParam($up)) {
852
+ $params[$up] = $request->getParam($up);
853
+ }
854
+ }
855
+
856
+ return $params;
857
+ }
858
+
859
+ public function getAdminUrl($url, $params = array())
860
+ {
861
+ $params = $this->getAdminUrlParams($params);
862
+
863
+ return Mage::helper("adminhtml")->getUrl($url, $params);
864
+ }
865
+
866
+ public function getOrdersEnabled()
867
+ {
868
+ $active = $this->config('active');
869
+ $setup = $this->config('setup');
870
+ $sendit = $this->config('sendorder');
871
+
872
+ if (!$sendit || !$setup || !$active) {
873
+ return false;
874
+ }
875
+
876
+ return true;
877
+ }
878
+
879
+ public function getBatchEnabled()
880
+ {
881
+ $active = $this->config('active');
882
+ $setup = $this->config('setup');
883
+ $batch = $this->config('batch_enabled');
884
+
885
+ if (!$batch || !$setup || !$active) {
886
+ return false;
887
+ }
888
+
889
+ return true;
890
+ }
891
+
892
+ public function getBatchOnly()
893
+ {
894
+ $batch_only = $this->config('batch_only');
895
+
896
+ if (!$batch_only) {
897
+ return false;
898
+ }
899
+
900
+ return true;
901
+ }
902
+
903
+ public function getDisabledReason()
904
+ {
905
+ if (!$this->config('active')) {
906
+ return "Campaigner Module is Disabled.";
907
+ }
908
+
909
+ if (!$this->config('setup')) {
910
+ return "Campaigner Module is not configured with a valid API Key.";
911
+ }
912
+
913
+ return "";
914
+ }
915
+
916
+ public function getOrdersDisabledReason()
917
+ {
918
+ $base = $this->getDisabledReason();
919
+
920
+ if ($base != "") {
921
+ return $base;
922
+ }
923
+
924
+ return "Sending Orders is disabled.";
925
+ }
926
+
927
+ public function getWishlistDisabledReason()
928
+ {
929
+ $base = $this->getDisabledReason();
930
+
931
+ if ($base != "") {
932
+ return $base;
933
+ }
934
+
935
+ if (!Mage::helper('customer')->isLoggedIn()) {
936
+ return "Customer not logged in";
937
+ }
938
+
939
+ return "Wishlist is disabled.";
940
+ }
941
+
942
+ public function getLastLoginDisabledReason()
943
+ {
944
+ $base = $this->getDisabledReason();
945
+
946
+ if ($base != "") {
947
+ return $base;
948
+ }
949
+
950
+ return "Last Login is disabled.";
951
+ }
952
+
953
+ public function getBatchDisabledReason()
954
+ {
955
+ $base = $this->getDisabledReason();
956
+
957
+ if ($base != "") {
958
+ return $base;
959
+ }
960
+
961
+ return "Sending Orders in batch is disabled.";
962
+ }
963
+
964
+ public function getAbandonedEnabled($store = null)
965
+ {
966
+ $active = $this->config('active', $store);
967
+ $setup = $this->config('setup', $store);
968
+ $sendit = $this->config('abandoned_enabled', $store);
969
+ $abandoned_setup = $this->config('abandonedsetup', $store);
970
+
971
+ if (!$sendit || !$setup || !$active || !$abandoned_setup) {
972
+ return false;
973
+ }
974
+
975
+ return true;
976
+ }
977
+
978
+ public function getAbandonedDisabledReason()
979
+ {
980
+ $base = $this->getDisabledReason();
981
+
982
+ if ($base != "") {
983
+ return $base;
984
+ }
985
+
986
+ if (!$this->config('abandonedsetup')) {
987
+ return "Abandoned Cart Processing Not Setup.";
988
+ }
989
+
990
+ return "Sending Abandoned Carts is Disabled";
991
+ }
992
+
993
+ // Newsletter
994
+
995
+ private function getLists()
996
+ {
997
+ $list_data = array();
998
+
999
+ $lists = Mage::getSingleton('campaigner/wrapper_lists')->getLists();
1000
+
1001
+ foreach ($lists as $list) {
1002
+ $list_data[$list['Id']] = array('id' => $list['Id'], 'name' => $list['Name'], 'subscribed' => false);
1003
+ }
1004
+
1005
+ return $list_data;
1006
+ }
1007
+
1008
+ private function getSubscriberData($email, $lists)
1009
+ {
1010
+ $contact_data = Mage::getSingleton("campaigner/wrapper_subscribers")->getContact($email, false, false, true);
1011
+
1012
+ if ($contact_data == null) {
1013
+ return array('status' => 'Unknown', 'lists' => $lists);
1014
+ }
1015
+
1016
+ try {
1017
+ if (isset($contact_data->GroupMembershipData->ContactGroupDescription)) {
1018
+ $contact_lists = $contact_data->GroupMembershipData->ContactGroupDescription;
1019
+
1020
+ if (!is_array($contact_lists)) {
1021
+ $contact_lists = array($contact_lists);
1022
+ }
1023
+
1024
+ foreach ($contact_lists as $list) {
1025
+ $id = $list->Id;
1026
+ if (isset($lists[$id])) {
1027
+ $lists[$id]['subscribed'] = true;
1028
+ }
1029
+ }
1030
+ }
1031
+ return array('status' => $contact_data->SystemAttributes->Status, 'lists' => $lists);
1032
+ }
1033
+ catch (Exception $e) {
1034
+ $this->_logger->logException($e);
1035
+ return array('status' => 'Unknown', 'lists' => $lists);
1036
+ }
1037
+ }
1038
+
1039
+ public function getSubscriptions($email)
1040
+ {
1041
+ $this->_logger->setLogArea(Campaigner_Integration_Helper_Troubleshooting::CUSTOMER);
1042
+ $this->_logger->setLogLevel(Campaigner_Integration_Helper_Troubleshooting::LOG_LEVEL_LOW);
1043
+
1044
+ try {
1045
+ $lists = $this->getLists();
1046
+
1047
+ $subscriptions = $this->getSubscriberData($email, $lists);
1048
+
1049
+ $this->_logger->resetLogLevel();
1050
+
1051
+ return $subscriptions;
1052
+ }
1053
+ catch (Exception $e)
1054
+ {
1055
+ Mage::logException($e);
1056
+ $this->_logger->logException($e);
1057
+ $this->_logger->resetLogLevel();
1058
+ return array('status' => 'Unknown', 'lists' => array());
1059
+ }
1060
+ }
1061
+ }
app/code/community/Campaigner/Integration/Helper/Diagnostic.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Helper_Diagnostic extends Mage_Core_Helper_Abstract
4
+ {
5
+ private $_quote = null;
6
+ private $_cart = null;
7
+
8
+ public function getCurrentStoreId()
9
+ {
10
+ $order = $this->getOrder();
11
+ if ($order)
12
+ return $order->getStore()->getId();
13
+
14
+ return Mage::app()->getRequest()->getParam('store_id');
15
+ }
16
+
17
+ public function getOrder()
18
+ {
19
+ return Mage::registry('current_order');
20
+ }
21
+
22
+ public function getQuote()
23
+ {
24
+ if (!$this->_quote) {
25
+ $quote_id = Mage::app()->getRequest()->getParam('id');
26
+ $store_id = Mage::app()->getRequest()->getParam('store_id');
27
+
28
+ if (!$quote_id || !$store_id) {
29
+ throw Exception("Invalid Parameters");
30
+ }
31
+
32
+ $store = Mage::getModel('core/store')->load($store_id);
33
+
34
+ $this->_quote = Mage::getModel('sales/quote')->setStore($store)->load($quote_id);
35
+ }
36
+
37
+ return $this->_quote;
38
+ }
39
+
40
+ public function getCartItems()
41
+ {
42
+ $quote = $this->getQuote();
43
+ return $quote->getItemsCollection(false);
44
+ }
45
+
46
+ public function getAbandonedCart($quote_id = null)
47
+ {
48
+ if (!$this->_cart) {
49
+ if (!$quote_id) {
50
+ $quote_id = Mage::app()->getRequest()->getParam('id');
51
+ }
52
+
53
+ $collection = Mage::getResourceModel('campaigner/abandoned_collection')->filterByQuoteId($quote_id);
54
+
55
+ $this->_cart = $collection->getFirstItem();
56
+ }
57
+ return $this->_cart;
58
+ }
59
+ }
app/code/community/Campaigner/Integration/Helper/Email.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Helper_Email extends Campaigner_Integration_Helper_Data
4
+ {
5
+ private function getConfigurationItem($item)
6
+ {
7
+ $value = Mage::registry("relay_{$item}");
8
+ if ($value) {
9
+ return $value;
10
+ }
11
+ return Mage::getStoreConfig("system/smtp/campaigner_smtp_{$item}");
12
+ }
13
+
14
+ public function isRelayTest()
15
+ {
16
+ return Mage::registry("relay_test");
17
+ }
18
+
19
+ public function setTransport()
20
+ {
21
+ $host = Mage::getStoreConfig('system/smtp/campaigner_smtp_server');
22
+ $port = $this->getConfigurationItem("port");
23
+
24
+ $username = $this->getConfigurationItem("username");
25
+ $password = $this->getConfigurationItem("password");
26
+
27
+ $config = array(
28
+ 'port' => $port,
29
+ 'auth' => 'plain',
30
+ 'username' => $username,
31
+ 'password' => $password
32
+ );
33
+
34
+ $encryption = Mage::getStoreConfig('system/smtp/campaigner_smtp_encryption');
35
+
36
+ if ($encryption != 'none') {
37
+ $config['ssl'] = $encryption;
38
+ }
39
+
40
+ $transport = new Zend_Mail_Transport_Smtp($host, $config);
41
+
42
+ Zend_Mail::setDefaultTransport($transport);
43
+ }
44
+ }
app/code/community/Campaigner/Integration/Helper/Fields.php ADDED
@@ -0,0 +1,224 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Helper_Fields extends Campaigner_Integration_Helper_Data
4
+ {
5
+ const ABANDONED_SETUP_PATH = 'campaigner/general/abandonedsetup';
6
+ const SETUP_VERSION_PATH = 'campaigner/general/setup_version';
7
+ const DATA_TYPE_TEXT = 'String';
8
+ const DATA_TYPE_NUMBER = 'Number';
9
+ const DATA_TYPE_DATE = 'Date';
10
+
11
+ private $_fieldMap = null;
12
+ private $_globalPrefix = null;
13
+
14
+ private function getGlobalPrefix()
15
+ {
16
+ if ($this->_globalPrefix == null) {
17
+ $this->_globalPrefix = $this->config("field_prefix");
18
+ }
19
+
20
+ return $this->_globalPrefix;
21
+ }
22
+
23
+ private function getVersion()
24
+ {
25
+ return (string) Mage::getConfig()->getNode('modules/Campaigner_Integration/version');
26
+ }
27
+
28
+ private function addDatabaseField($data)
29
+ {
30
+ $name = $data['name'];
31
+ $type = $data['type'];
32
+
33
+ Mage::getSingleton('campaigner/wrapper_database')->add($name,$type);
34
+ }
35
+
36
+ private function getMultiFields($fields, $prefix = "", $count = null)
37
+ {
38
+ if ($count == null) {
39
+ $count = Mage::helper('campaigner')->config('product_fields');
40
+ }
41
+
42
+ for ($i = 1; $i <= $count; $i++) {
43
+ $fields[] =
44
+ $this->addField("{$prefix}ProductName{$i}", self::DATA_TYPE_TEXT, '200');
45
+
46
+ if ($prefix != 'Related') {
47
+ $fields[] = $this->addField("{$prefix}ParentName{$i}", self::DATA_TYPE_TEXT, '200');
48
+ }
49
+ $fields[] = $this->addField("{$prefix}SKU{$i}", self::DATA_TYPE_TEXT, '50');
50
+ $fields[] = $this->addField("{$prefix}URL{$i}", self::DATA_TYPE_TEXT, '200');
51
+ $fields[] = $this->addField("{$prefix}Image{$i}", self::DATA_TYPE_TEXT, '200');
52
+ $fields[] = $this->addField("{$prefix}Description{$i}", self::DATA_TYPE_TEXT, '200');
53
+ $fields[] = $this->addField("{$prefix}Cost{$i}", self::DATA_TYPE_TEXT, '20');
54
+ }
55
+
56
+ return $fields;
57
+ }
58
+
59
+ private function getExistingColumns()
60
+ {
61
+ $columns = Mage::getSingleton('campaigner/wrapper_database')->getAllColumns();
62
+
63
+ $existing = array();
64
+
65
+ if (!isset($columns)) {
66
+ return $existing;
67
+ }
68
+
69
+ foreach ($columns as $column) {
70
+ $name = (string)$column->Name;
71
+
72
+ $existing[$name] = $name;
73
+ }
74
+
75
+ return $existing;
76
+ }
77
+
78
+ private function getMissingColumns($fields)
79
+ {
80
+ $columns = $this->getExistingColumns();
81
+
82
+ $check_columns = array();
83
+
84
+ foreach ($columns as $key => $column) {
85
+ $check_columns[strtolower($key)] = $column;
86
+ }
87
+
88
+ $missing = array();
89
+
90
+ foreach ($fields as $field) {
91
+ if (!isset($check_columns[strtolower($field['name'])])) {
92
+ $missing[] = $field;
93
+ }
94
+ }
95
+
96
+ return $missing;
97
+ }
98
+
99
+ private function addField($name, $type, $size = null)
100
+ {
101
+ $new_field = array('name' => $this->getGlobalPrefix() . $name, 'type' => $type);
102
+
103
+ if ($size != null) {
104
+ $new_field['size'] = $size;
105
+ }
106
+
107
+ return $new_field;
108
+ }
109
+
110
+ public function getAddressFields($fields)
111
+ {
112
+ $fields[] = $this->addField('Address', self::DATA_TYPE_TEXT, '100');
113
+ $fields[] = $this->addField('Zip', self::DATA_TYPE_TEXT, '100');
114
+ $fields[] = $this->addField('City', self::DATA_TYPE_TEXT, '100');
115
+ $fields[] = $this->addField('State', self::DATA_TYPE_TEXT, '100');
116
+
117
+ return $fields;
118
+ }
119
+
120
+ public function getCustomFields($force_product = false, $address_fields = true)
121
+ {
122
+ $fields = array();
123
+
124
+ if (Mage::helper('campaigner')->config('save_latest_order') || $force_product) {
125
+ $fields[] = $this->addField('LastOrderNumber', self::DATA_TYPE_TEXT, '30');
126
+ $fields[] = $this->addField('LastPurchaseDate', self::DATA_TYPE_DATE);
127
+ $fields[] = $this->addField('LastPurchaseTotal', self::DATA_TYPE_TEXT, '20');
128
+
129
+ $fields = $this->getMultiFields($fields);
130
+
131
+ $fields = $this->getMultiFields($fields,"Related", Mage::helper('campaigner')->config('related_fields'));
132
+ }
133
+
134
+ if (Mage::helper('campaigner')->config('wishlist_enabled')) {
135
+ $fields[] = $this->addField('WishListDate', self::DATA_TYPE_DATE);
136
+ $fields[] = $this->addField('WishListUrl', self::DATA_TYPE_TEXT, '200');
137
+ }
138
+
139
+ $fields[] = $this->addField('LastLogin', self::DATA_TYPE_DATE);
140
+
141
+ $fields[] = $this->addField('AbandonedDate', self::DATA_TYPE_DATE);
142
+ $fields[] = $this->addField('AbandonedUrl', self::DATA_TYPE_TEXT, '1000');
143
+
144
+ $fields = $this->getMultiFields($fields,"AB");
145
+
146
+ if ($address_fields) {
147
+ $fields = $this->getAddressFields($fields);
148
+ }
149
+
150
+ $fields[] = $this->addField('Store', self::DATA_TYPE_TEXT, '100');
151
+ $fields[] = $this->addField('AbandonedSequence', self::DATA_TYPE_TEXT, '100');
152
+
153
+ return $fields;
154
+ }
155
+
156
+ public function getDefaultFields()
157
+ {
158
+ $defaults = array(
159
+ "First Name" => "FirstName",
160
+ "Last Name" => "LastName",
161
+ "Phone" => "PhoneNumber",
162
+ "Fax" => "Fax",
163
+ "Status" => "Status"
164
+ );
165
+ return $defaults;
166
+ }
167
+
168
+ public function getFieldMap()
169
+ {
170
+ $mapData = $this->config('field_map');
171
+
172
+ return unserialize($mapData);
173
+ }
174
+
175
+ public function saveFieldMap($attributes)
176
+ {
177
+ $defaults = $this->getDefaultFields();
178
+ $attributeMap = array();
179
+ foreach ($attributes as $attribute) {
180
+ if (!isset($defaults[$attribute->Name])) {
181
+ $attributeMap[$attribute->Name] = $attribute->Id;
182
+ }
183
+ }
184
+
185
+ $this->updateConfigForApi('field_map', serialize($attributeMap));
186
+ }
187
+
188
+ public function verifyFields($force_product = false)
189
+ {
190
+ $fields = $this->getCustomFields($force_product);
191
+
192
+ $missing = $this->getMissingColumns($fields);
193
+
194
+ if (count($missing) > 0) {
195
+ foreach ($missing as $data) {
196
+ $this->addDatabaseField($data);
197
+ }
198
+
199
+ $missing_check = $this->getMissingColumns($fields);
200
+
201
+ if (count($missing_check) != 0) {
202
+ $this->log("Error creating fields");
203
+ $this->log($missing_check, "Missing Check");
204
+ Mage::throwException("Error creating fields");
205
+ }
206
+ }
207
+
208
+ // Save version so we know if we are up to date or not
209
+ Mage::getConfig()->saveConfig(self::ABANDONED_SETUP_PATH, 1,"default","default");
210
+ Mage::getConfig()->saveConfig(self::SETUP_VERSION_PATH, $this->getVersion(),"default","default");
211
+ }
212
+
213
+ public function checkFields()
214
+ {
215
+ $version = $this->getVersion();
216
+
217
+ $setup_version = Mage::helper('campaigner')->config('setup_version');
218
+
219
+ if ($setup_version == NULL || (version_compare($setup_version, $version) < 0)) {
220
+ $this->verifyFields();
221
+ }
222
+ }
223
+
224
+ }
app/code/community/Campaigner/Integration/Helper/Order.php ADDED
@@ -0,0 +1,662 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Helper_Order extends Campaigner_Integration_Helper_Data
4
+ {
5
+ protected function getTrackingData($order)
6
+ {
7
+ $shipmentCollection = Mage::getResourceModel('sales/order_shipment_collection')
8
+ ->setOrderFilter($order)
9
+ ->load();
10
+ foreach($shipmentCollection as $_shipment) {
11
+ foreach($_shipment->getAllTracks() as $tracknum) {
12
+ return $tracknum->getData();
13
+ }
14
+ }
15
+
16
+ return null;
17
+ }
18
+
19
+ public function getTrackingMergeVars($track, $order)
20
+ {
21
+ $this->_logger->log('getTrackingMergeVars Start');
22
+
23
+ $merge_vars = array();
24
+ $maps = unserialize($this->config('shipping_fields', $order->getStoreId()));
25
+
26
+ if (!$maps) {
27
+ return null;
28
+ }
29
+
30
+ $this->_logger->log($maps, "Maps");
31
+
32
+ $this->_logger->log($track->getData(), "Tracking Data");
33
+
34
+ $this->processMap($merge_vars, $maps, $track);
35
+
36
+ return $merge_vars;
37
+ }
38
+
39
+ protected function getShippingData($order)
40
+ {
41
+ $data = array();
42
+
43
+ $data['shipping_code'] = $order->getData('shipping_method');
44
+ $data['shipping_description'] = $order->getData('shipping_description');
45
+
46
+ $track_data = $this->getTrackingData($order);
47
+
48
+ if ($track_data != null) {
49
+ $data['carrier_code'] = $track_data['carrier_code'];
50
+ $data['title'] = $track_data['title'];
51
+ $data['number'] = $track_data['number'];
52
+ }
53
+
54
+ $shipping_data = new Varien_Object();
55
+
56
+ $shipping_data->setData($data);
57
+
58
+ return $shipping_data;
59
+ }
60
+
61
+ protected function getOrderMergeVars(&$merge_vars, $order)
62
+ {
63
+ $this->_logger->logAndDebug('getOrderMergeVars (Tracking Data)');
64
+ $maps = unserialize( $this->config('shipping_fields', $order->getStoreId()) );
65
+
66
+ if ($maps) {
67
+ $this->_logger->log($maps, "Maps");
68
+ $shipping_data = $this->getShippingData($order);
69
+
70
+ $this->_logger->log($shipping_data,'Shipping Data');
71
+
72
+ $this->processMap($merge_vars, $maps, $shipping_data);
73
+ } else {
74
+ $this->debug('No Mappings Found');
75
+ }
76
+
77
+ return $merge_vars;
78
+ }
79
+
80
+ public function getOrderCustomer($order)
81
+ {
82
+ $customer = null;
83
+
84
+ if ($order->getData('customer_is_guest')) {
85
+ $this->_logger->log("Guest Customer");
86
+
87
+ $customer = new Varien_Object;
88
+
89
+ $customer->setData('email',$order->getCustomerEmail());
90
+ $customer->setData('firstname',$order->getData('customer_firstname'));
91
+ $customer->setData('lastname',$order->getData('customer_lastname'));
92
+ $customer->setData('store_id',$order->getStoreId());
93
+
94
+ $customer->setBillingAddress($order->getBillingAddress());
95
+ } else {
96
+ $customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
97
+ $address = Mage::getModel('customer/address')->load($customer->getDefaultBilling());
98
+ $customer->setBillingAddress($address);
99
+ }
100
+
101
+ return $customer;
102
+ }
103
+
104
+ public function processOrderItems($order, &$merge_vars)
105
+ {
106
+ $this->debugHeader("processOrderItems Start",1);
107
+
108
+ $merge_vars = $this->getOrderMergeVars($merge_vars,$order);
109
+
110
+ $this->_logger->logAndDebug("Check Save Lastest");
111
+ if ($this->config('save_latest_order')) {
112
+ $this->_logger->logAndDebug("Adding Latest Order Information");
113
+ $this->_logger->logAndDebug($order);
114
+ $merge_vars['LastOrderNumber'] = $order->getIncrementId();
115
+ $merge_vars['LastPurchaseDate'] = $order->getData('created_at');
116
+ $merge_vars['LastPurchaseTotal'] = Mage::helper('core')->currency($order->getData('total_paid'), true, false);
117
+
118
+ $merge_vars = $this->getMergeOrderItems($order, $merge_vars);
119
+ $merge_vars = $this->getRelatedOrderItems($order, $merge_vars);
120
+ $this->_logger->logAndDebug("Finish Save Latest");
121
+ } else {
122
+ $this->_logger->logAndDebug("Not setup to send latest order info");
123
+ }
124
+
125
+ return $merge_vars;
126
+ }
127
+
128
+ protected function getParentOptions($parent_product,$product_id)
129
+ {
130
+ $parent_options = $this->getConfigurableOptions($parent_product,$product_id);
131
+
132
+ if (count($parent_options) == 0) {
133
+ return "";
134
+ }
135
+
136
+ $options = "";
137
+
138
+ foreach ($parent_options as $key => $value) {
139
+ if ($options == "") {
140
+ $options .= "#";
141
+ } else {
142
+ $options .= "&";
143
+ }
144
+
145
+ $options .= "{$key}={$value}";
146
+ }
147
+
148
+ return $options;
149
+ }
150
+
151
+ protected function getGroupedPrice($grouped_product)
152
+ {
153
+ $min = 0;
154
+ $products = $grouped_product->getTypeInstance()->getAssociatedProducts();
155
+
156
+ foreach ($products as $product) {
157
+ if ($min == 0) {
158
+ $min = $product->getPrice();
159
+ }
160
+
161
+ $min = min($min, $product->getPrice());
162
+ }
163
+
164
+ return $min;
165
+ }
166
+
167
+ protected function getProductImage($product, $parent_product = null)
168
+ {
169
+ try {
170
+ $image = "";
171
+ if ($product->getImage() == 'no_selection' || $product->getImage() == "") {
172
+ if ($parent_product != null && $parent_product->getImage() != "no_selection" && $parent_product->getImage() != "") {
173
+ $image = Mage::getModel('catalog/product_media_config')->getMediaUrl($parent_product->getImage());
174
+ }
175
+ } else {
176
+ $image = Mage::getModel('catalog/product_media_config')->getMediaUrl($product->getImage());
177
+ }
178
+ } catch (Exception $e) {
179
+ Mage::logException($e);
180
+ $this->_logger->logException($e);
181
+ }
182
+
183
+ return $image;
184
+ }
185
+
186
+ private function addMergeItem($item_data, $pos, $merge_vars, $prefix = "")
187
+ {
188
+ $name = "";
189
+ $parent_name = "";
190
+ $sku = "";
191
+ $url = "";
192
+ $image = "";
193
+ $cost = "";
194
+ $description = "";
195
+ $parent_item = null;
196
+ $parent_product = null;
197
+
198
+ $this->debug("--------------------------");
199
+ $this->debug("ADDING MERGE ITEM");
200
+
201
+ if ($item_data != null) {
202
+ $product_id = 0;
203
+
204
+ if (is_array($item_data)) {
205
+ $item = $item_data['item'];
206
+
207
+ if (isset($item_data['parent'])) {
208
+ $parent_item = $item_data['parent'];
209
+ $this->debug("Parent Item:");
210
+ $this->debug($parent_item);
211
+ }
212
+ } else {
213
+ $item = $item_data;
214
+ }
215
+
216
+ $this->debug("Item:");
217
+ $this->debug($item);
218
+
219
+ if (is_string($item)) {
220
+ $product_id = $item;
221
+
222
+ $product = Mage::getModel('catalog/product')->load($product_id);
223
+
224
+ if ($product == null || !$product->getId()) {
225
+ return $merge_vars;
226
+ }
227
+ } else {
228
+ $product = $this->getProduct($item);
229
+ if ($product == null) {
230
+ return $merge_vars; // Can't get product so abort
231
+ }
232
+ }
233
+
234
+ $this->debug("Product:");
235
+ $this->debug($product);
236
+
237
+ if ($parent_item != null) {
238
+ $parent_product = $this->getProduct($parent_item);
239
+ if ($parent_product == null) {
240
+ return $merge_vars; // Can't get product so abort
241
+ }
242
+
243
+ $this->debug("Parent Product:");
244
+ $this->debug($parent_product);
245
+
246
+ $parent_name = $parent_product->getName();
247
+ $url = $parent_product->getProductUrl();
248
+
249
+ if ($parent_product->getTypeId() == 'configurable') {
250
+ $url .= $this->getParentOptions($parent_product,$product_id);
251
+ }
252
+ } else {
253
+ $url = $product->getProductUrl();
254
+ }
255
+
256
+ $name = $product->getName();
257
+ $sku = $product->getSku();
258
+
259
+ $image = $this->getProductImage($product, $parent_product);
260
+
261
+ if (is_string($item)) {
262
+ $this->debug('String Item');
263
+ if ($product->getTypeId() == 'grouped') {
264
+ $cost = $this->getGroupedPrice($product);
265
+ } else {
266
+ $cost = $product->getPrice();
267
+ }
268
+ } else {
269
+ if ($parent_item != null) {
270
+ $cost = $parent_item->getPrice();
271
+ } else {
272
+ $cost = $item->getPrice();
273
+ }
274
+ }
275
+
276
+ $cost = Mage::helper('core')->currency($cost,true,false);
277
+ $description = $product->getShortDescription();
278
+ }
279
+
280
+ $merge_vars["{$prefix}ProductName{$pos}"] = $name;
281
+ if ($prefix != 'Related') {
282
+ $merge_vars["{$prefix}ParentName{$pos}"] = $parent_name;
283
+ }
284
+
285
+ $merge_vars["{$prefix}SKU{$pos}"] = $sku;
286
+ $merge_vars["{$prefix}URL{$pos}"] = $url;
287
+ $merge_vars["{$prefix}Image{$pos}"] = $image;
288
+
289
+ $merge_vars["{$prefix}Cost{$pos}"] = $cost;
290
+ $merge_vars["{$prefix}Description{$pos}"] = $description;
291
+
292
+ return $merge_vars;
293
+ }
294
+
295
+ protected function getRelatedCollection($id_list, $max_count, $grouped_id_list = null)
296
+ {
297
+ $this->debug("getRelatedCollection Start");
298
+ $collection = Mage::getModel('catalog/product_link')
299
+ ->useRelatedLinks()
300
+ ->getCollection()
301
+ ->addFieldToFilter('product_id', array('in' => $id_list))
302
+ ;
303
+
304
+ $this->debug("Collection SQL");
305
+ $this->debug($collection->getSelect()->__toString());
306
+
307
+ // Filter out grouped products from the related list
308
+ if ($grouped_id_list != null && count($grouped_id_list) > 0) {
309
+ $this->debug("Merging Grouped ID's to filter");
310
+ $id_list = array_merge($id_list,$grouped_id_list);
311
+
312
+ }
313
+
314
+ $this->debug("ID Filters");
315
+ $this->debug($id_list);
316
+
317
+ $product_ids = array();
318
+
319
+ // If any of the related products are already in the order we filter them out
320
+ foreach ($collection as $rp) {
321
+ $this->debug("");
322
+ $this->debug("-----------------------------");
323
+ $this->debug("Related Product");
324
+ $this->debug($rp->getData());
325
+ $lp_id = $rp['linked_product_id'];
326
+ if (!in_array($lp_id,$id_list)) {
327
+ $this->debug("Adding Related Product");
328
+ $product_ids[] = $lp_id;
329
+ } else {
330
+ $this->debug("Related product already in order");
331
+ }
332
+ }
333
+
334
+ $this->debug("Product IDs");
335
+ $this->debug($product_ids);
336
+
337
+ $related = Mage::getResourceModel('catalog/product_collection')
338
+ ->addFieldToFilter('entity_id', array('in' => $product_ids))
339
+ ->setPageSize($max_count);
340
+
341
+ Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($related);
342
+
343
+ $this->debug("Related SQL");
344
+ $this->debug($related->getSelect()->__toString());
345
+
346
+ $related_list = array();
347
+
348
+ if (count($related) > 0) {
349
+ foreach ($related as $rp) {
350
+ $related_list[] = $rp;
351
+ }
352
+ }
353
+
354
+ return $related_list;
355
+ }
356
+
357
+ protected function getRelatedProducts($quote)
358
+ {
359
+ $id_list = array();
360
+ $grouped_id_list = array();
361
+ $filter_id_list = array();
362
+
363
+ foreach ($quote->getAllItems() as $item) {
364
+ $this->debug("");
365
+ $this->debug("----------------------------------------------------------");
366
+ $type = $item->getProductType();
367
+ $this->debug("Item ID: {$item->getId()}");
368
+ $this->debug("Item Sku: {$item->getSku()}");
369
+ $this->debug("Item Type: {$type}");
370
+
371
+ // if it is a grouped product get the parent ID and add it to the list (if not already added)
372
+ if ($type == 'grouped') {
373
+ $grouped_product_id = $this->getGroupedProductId($item);
374
+
375
+ $this->debug("Grouped Product ID: {$grouped_product_id}");
376
+
377
+ if (!in_array($grouped_product_id, $grouped_id_list))
378
+ $grouped_id_list[] = $grouped_product_id;
379
+ }
380
+
381
+ if ($product = $this->getProduct($item)) {
382
+ $product_id = $product->getId();
383
+ if (!in_array($product_id, $id_list)) {
384
+ $id_list[] = $product_id;
385
+ }
386
+ }
387
+ }
388
+
389
+ $this->debug("ID List");
390
+ $this->debug($id_list);
391
+ $this->debug("Grouped ID List");
392
+ $this->debug($grouped_id_list);
393
+
394
+ $max_count = $this->config('related_fields');
395
+
396
+ $this->debug("Max Related: {$max_count}");
397
+
398
+ $this->debug("");
399
+ $this->debug("--------------------------------------------------------------------------");
400
+ $this->debug("Get Related Collection (Non Grouped)");
401
+ $this->debug("");
402
+
403
+ $related = $this->getRelatedCollection($id_list, $max_count, $grouped_id_list);
404
+
405
+ $this->debug("");
406
+ $this->debug("# of Related Products Found: " . count($related));
407
+
408
+ if (count($related) < $max_count && count($grouped_id_list) > 0) {
409
+ $this->debug("");
410
+ $this->debug("--------------------------------------------------------------------------");
411
+ $this->debug("Get Related Collection (Grouped)");
412
+ $this->debug("");
413
+
414
+ // get grouped related
415
+ $grouped_related = $this->getRelatedCollection($grouped_id_list, $max_count - count($related), $id_list);
416
+
417
+ // Merge the collections
418
+ if (count($grouped_related) > 0) {
419
+ return array_merge($related, $grouped_related);
420
+ }
421
+ }
422
+
423
+ return $related;
424
+ }
425
+
426
+ public function getRelatedOrderItems($quote, $merge_vars)
427
+ {
428
+ $prefix = "Related";
429
+ $max_count = $this->config('related_fields');
430
+
431
+ $this->debug('');
432
+ $this->debug('Getting Related Products');
433
+
434
+ $related_products = $this->getRelatedProducts($quote);
435
+
436
+ $count = 0;
437
+
438
+ foreach ($related_products as $rp) {
439
+ $count++;
440
+
441
+ if ($count > $max_count) {
442
+ break;
443
+ }
444
+
445
+ $merge_vars = $this->addMergeItem($rp->getId(), $count, $merge_vars, $prefix);
446
+ }
447
+
448
+ while ($count < $max_count) {
449
+ $count++;
450
+ $merge_vars = $this->addMergeItem(null, $count, $merge_vars, $prefix);
451
+ }
452
+
453
+ return $merge_vars;
454
+ }
455
+
456
+ protected function getGroupedProductId($item)
457
+ {
458
+ $this->debug('Get Grouped Product Id');
459
+ $options = $item->getProductOptions();
460
+
461
+ $this->debug('Product Options');
462
+ $this->debug($options);
463
+
464
+ if (isset($options['super_product_config'])) {
465
+ $this->debug('Super config found');
466
+ if (isset($options['super_product_config']['product_id'])) {
467
+ $this->debug('Product Id Found');
468
+ $product_id = $options['super_product_config']['product_id'];
469
+
470
+ return $product_id;
471
+ }
472
+ $this->debug('Product Id Not Found!');
473
+ } else {
474
+ $this->debug('Get Option By Code');
475
+ $option = $item->getOptionByCode('product_type');
476
+ if ($option) {
477
+ $this->debug('Option Found');
478
+ $this->debug($option);
479
+ return $option->getProductId();
480
+ }
481
+ }
482
+
483
+ $this->debug('Unable to get Grouped Product ID');
484
+
485
+ return false;
486
+ }
487
+
488
+ protected function getGroupedProduct($item)
489
+ {
490
+ $this->debug('Get Grouped Product');
491
+ $product_id = $this->getGroupedProductId($item);
492
+
493
+ if ($product_id !== false) {
494
+ $this->debug('Loading Product');
495
+ $product = Mage::getModel('catalog/product')->load($product_id);
496
+
497
+ if ($product->getId()) {
498
+ $this->debug('Grouped Product Found!');
499
+ return $product;
500
+ }
501
+ }
502
+
503
+ $this->debug('Unable to get Grouped Product');
504
+
505
+ return false;
506
+ }
507
+
508
+ protected function isItemVisible($item)
509
+ {
510
+ $vis_flag = Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE;
511
+
512
+ if ($item == null) {
513
+ return true;
514
+ }
515
+
516
+ $product = $this->getProduct($item);
517
+
518
+ if ($product == null) {
519
+ return true;
520
+ }
521
+
522
+ if ($product->getVisibility() != $vis_flag) {
523
+ return true;
524
+ }
525
+
526
+ return false;
527
+ }
528
+
529
+ protected function processParentItems($quote)
530
+ {
531
+ $this->debug("Processing Parent Items");
532
+ $parent_items = array();
533
+
534
+ foreach ($quote->getAllItems() as $item) {
535
+ $this->debug("");
536
+ $this->debug("----------------------------------------------------------");
537
+ $type = $item->getProductType();
538
+
539
+ $this->debug("Item ID: {$item->getId()}");
540
+ $this->debug("Item Sku: {$item->getSku()}");
541
+ $this->debug("Item Type: {$type}");
542
+
543
+ if ($type == "configurable" || $type == "bundle") {
544
+ $this->debug('*** Adding as Parent Item ***');
545
+ $parent_items[$item->getId()] = $item;
546
+ }
547
+
548
+ if ($type == "grouped") {
549
+ $grouped_product = $this->getGroupedProduct($item);
550
+
551
+ if ($grouped_product) {
552
+ $this->debug('*** Adding Grouped Product to Parent Items ***');
553
+ $parent_item = new Varien_Object;
554
+ $parent_item->setProduct($grouped_product);
555
+ $parent_items[$item->getId()] = $parent_item;
556
+ }
557
+ }
558
+ }
559
+
560
+ $this->debug('Parent Items Found: ' . count($parent_items));
561
+
562
+ if (count($parent_items) > 0) {
563
+ $this->debug('Parent Items:');
564
+
565
+ foreach($parent_items as $key => $item) {
566
+ $this->debug('-------------------------');
567
+ $this->debug("ID: {$key}");
568
+ if ($item->getId()) {
569
+ $this->debug("Parent ID: " . $item->getId());
570
+ } else {
571
+ $parent_product = $this->getProduct($item);
572
+ if ($parent_product) {
573
+ $this->debug("Parent ID: " . $parent_product->getId());
574
+ } else {
575
+ $this->debug("Parent ID: Failed to load product");
576
+ }
577
+ }
578
+ }
579
+ }
580
+
581
+ return $parent_items;
582
+ }
583
+
584
+ public function getMergeOrderItems($quote, $merge_vars, $prefix = "")
585
+ {
586
+ $max_count = $this->config('product_fields');
587
+
588
+ $count = 0;
589
+
590
+ $item_data = array();
591
+
592
+ $parent_items = $this->processParentItems($quote);
593
+
594
+ $this->debug('');
595
+ $this->debug('Processing Order Items');
596
+
597
+ foreach ($quote->getAllItems() as $item) {
598
+ $type = $item->getProductType();
599
+
600
+ $this->debug('');
601
+ $this->debug("----------------------------------------------------------");
602
+ $this->debug('Item Sku: ' . $item->getSku());
603
+ $this->debug('Item Type: ' . $type);
604
+
605
+ if ($type == "configurable" || $type == "bundle") {
606
+ $this->debug('Skipping Configurable and Bundle Products (this is a parent product)');
607
+ continue;
608
+ }
609
+
610
+ $item_id = $item->getId();
611
+
612
+ if ($item->getProductType() == 'grouped') {
613
+ $this->debug('Grouped Product');
614
+
615
+ $parent_id = $item->getId();
616
+ } else {
617
+ $parent_id = $item->getParentItemId();
618
+ }
619
+
620
+ $this->debug("Parent Id: {$parent_id}");
621
+
622
+ if ($parent_id != null && isset($parent_items[$parent_id])) {
623
+ $this->debug('Item has a Parent');
624
+ $parent_item = $parent_items[$parent_id];
625
+
626
+ $this->debug('Checking Visibility of Item and Parent (only one needs to be visible)');
627
+ if ($this->isItemVisible($item) || $this->isItemVisible($parent_item)) {
628
+ $this->debug('Adding Item to list');
629
+ $item_data[$item_id] = array('item' => $item, 'parent' => $parent_item);
630
+ } else {
631
+ $this->debug('Visibility check failed');
632
+ }
633
+ } else {
634
+ $this->debug('Checking Visibility of Item');
635
+ if ($this->isItemVisible($item)) {
636
+ $this->debug('Adding Item to list');
637
+ $item_data[$item_id] = array('item' => $item);
638
+ } else {
639
+ $this->debug('Visibility check failed');
640
+ }
641
+ }
642
+ }
643
+
644
+ foreach ($item_data as $item) {
645
+ $count++;
646
+
647
+ if ($count > $max_count) {
648
+ break;
649
+ }
650
+
651
+ $merge_vars = $this->addMergeItem($item, $count, $merge_vars, $prefix);
652
+ }
653
+
654
+ // Blank out other items
655
+ while ($count < $max_count) {
656
+ $count++;
657
+ $merge_vars = $this->addMergeItem(null, $count, $merge_vars, $prefix);
658
+ }
659
+
660
+ return $merge_vars;
661
+ }
662
+ }
app/code/community/Campaigner/Integration/Helper/Troubleshooting.php ADDED
@@ -0,0 +1,767 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Helper_Troubleshooting extends Mage_Core_Helper_Abstract
4
+ {
5
+ const LOG_FILE_NAME = 'campaigner';
6
+ const LOG_FILE_EXT = '.log';
7
+ const LOG_LEVEL_HIGH = 0;
8
+ const LOG_LEVEL_NORMAL = 5;
9
+ const LOG_LEVEL_LOW = 100;
10
+
11
+ const ABANDONED_CART = "AB";
12
+ const ORDERS = "OR";
13
+ const NEWSLETTER = "NL";
14
+ const CUSTOMER = "CU";
15
+ const CONFIG = "CG";
16
+ const IGNORE = "IG";
17
+ const WISHLIST = "WL";
18
+ const DEFAULT_AREA = "CA";
19
+ const ACTIONS = "AC";
20
+
21
+ const DISABLED_REASON_PREFIX = "Skipping";
22
+
23
+ private $_log_level = self::LOG_LEVEL_NORMAL;
24
+ private $_log_level_active = self::LOG_LEVEL_NORMAL;
25
+ private $_log_area = self::DEFAULT_AREA;
26
+ private $_current_store = null;
27
+
28
+ private $_output_log = array();
29
+
30
+ private $_config_options = null;
31
+
32
+ private $_status = array();
33
+ private $_debug_mode = false;
34
+
35
+ private $_debug_execute_mode = "request";
36
+
37
+ private $_debug_request = null;
38
+ private $_debug_response = null;
39
+
40
+ protected $_date_format = Campaigner_Integration_Helper_Data::DATE_FORMAT;
41
+
42
+ private $_areas = array(
43
+ "AB" => "Abandoned Carts",
44
+ "OR" => "Orders",
45
+ "NL" => "Newsletter",
46
+ "CU" => "Customer",
47
+ //"CG" => "Configuration",
48
+ "WL" => "Wishlist"
49
+ );
50
+
51
+ public function validateCredentials($api_username, $api_password, $report_error = false)
52
+ {
53
+ $filters = Mage::getSingleton('campaigner/wrapper_database')->getAttributeFilters();
54
+
55
+ $message_translate = array(
56
+ "invalid username or password." => "Invalid API username or password.",
57
+ "the account is locked." => "Too many failed login attempts. Account is temporarily locked."
58
+ );
59
+
60
+ $service = 'contact';
61
+ $method = "ListAttributes";
62
+ $tag = "filter";
63
+ $valid = true;
64
+ $message = "";
65
+
66
+ try {
67
+ $response = Mage::getSingleton('campaigner/wrapper_execute')
68
+ ->sendCommandDirect($api_username, $api_password, $service, $method, $tag, $filters);
69
+
70
+ } catch (Exception $e) {
71
+ $valid = false;
72
+ $message = $e->getMessage();
73
+
74
+ if (isset($message_translate[strtolower($message)])) {
75
+ $message = $message_translate[strtolower($message)];
76
+ }
77
+ }
78
+
79
+ return array('valid' => $valid, 'message' => $message);
80
+ }
81
+
82
+ public function getDebugExecuteMode()
83
+ {
84
+ return $this->_debug_execute_mode;
85
+ }
86
+
87
+ public function setDebugExecuteMode($mode)
88
+ {
89
+ $this->_debug_execute_mode = $mode;
90
+ }
91
+
92
+ public function setDebugRequest($request)
93
+ {
94
+ $this->_debug_request = $request;
95
+ }
96
+
97
+ public function setDebugResponse($response)
98
+ {
99
+ $this->_debug_response = $response;
100
+ }
101
+
102
+ public function getDebugRequest()
103
+ {
104
+ return $this->_debug_request;
105
+ }
106
+
107
+ public function getDebugResponse()
108
+ {
109
+ return $this->_debug_response;
110
+ }
111
+
112
+ public function getAreas()
113
+ {
114
+ return $this->_areas;
115
+ }
116
+
117
+ public function turnOnDebug()
118
+ {
119
+ $this->_debug_mode = true;
120
+ }
121
+
122
+ public function turnOffDebug()
123
+ {
124
+ $this->_debug_mode = false;
125
+ }
126
+
127
+ public function getDebugData()
128
+ {
129
+ return $this->_output_log;
130
+ }
131
+
132
+ private function safeDumpArray($data, $level)
133
+ {
134
+ $output = "";
135
+ $inner_indent = str_repeat(" ",$level + 1);
136
+ foreach ($data as $key => $value) {
137
+ $output .= "{$inner_indent}[{$key}] => ";
138
+ if (is_object($value)) {
139
+ $output .= $this->safeDump($value, $level + 1);
140
+ } else if (is_array($value)) {
141
+ $output .= $this->safeDump($value,$level + 1);
142
+ } else {
143
+ $output .= $value;
144
+ }
145
+
146
+ $output .= "\n";
147
+ }
148
+
149
+ return $output;
150
+ }
151
+
152
+ public function safeDump($data, $level = 0)
153
+ {
154
+ try
155
+ {
156
+ if ($level > 5) {
157
+ return "";
158
+ }
159
+
160
+ $indent = str_repeat(" ",$level);
161
+
162
+ $output = "";
163
+
164
+ if ($data instanceof stdClass) {
165
+ $output = get_class($data) . " Object\n{$indent}(\n";
166
+ $output .= $this->safeDumpArray(get_object_vars($data), $level);
167
+ //$output .= $this->safeDump(get_object_vars($data), $level + 1);
168
+ $output .= "{$indent})\n";
169
+ } else if (is_object($data)) {
170
+ $output = get_class($data) . " Object\n{$indent}(\n";
171
+
172
+ $output .= $this->safeDump($data->getData(), $level + 1);
173
+ $output .= "{$indent})\n";
174
+ } else if (is_array($data)) {
175
+ $output = "{$indent}Array\n{$indent}(\n";
176
+ //$inner_indent = $indent . " ";
177
+ $output .= $this->safeDumpArray($data, $level);
178
+
179
+ $output .= "{$indent})\n";
180
+ }
181
+
182
+ return $output;
183
+ } catch (Exception $e) {
184
+ return $e->getMessage();
185
+ }
186
+ }
187
+
188
+ private function formatData($data)
189
+ {
190
+ $output = $this->safeDump($data);
191
+
192
+ $output = str_replace("\n","<br />",$output);
193
+ $output = str_replace(" ","&nbsp;&nbsp;",$output);
194
+
195
+ return $output;
196
+ }
197
+
198
+ private function debugFromLog($data)
199
+ {
200
+ if (!$this->_debug_mode) {
201
+ return;
202
+ }
203
+
204
+ $this->debug($data);
205
+ }
206
+
207
+ public function debug($data)
208
+ {
209
+ if (!$this->_debug_mode) {
210
+ return;
211
+ }
212
+
213
+ if (!is_string($data)) {
214
+ $this->_output_log[] = $this->formatData($data);
215
+ } else {
216
+ $this->_output_log[] = $data;
217
+ }
218
+ }
219
+
220
+ public function debugHeader($header, $level = 2)
221
+ {
222
+ $line = str_repeat('==========================================================',$level);
223
+ $this->debug($header);
224
+ $this->debug($line);
225
+ $this->debug('');
226
+ }
227
+
228
+ public function debugXml($data)
229
+ {
230
+ if (!$this->_debug_mode) {
231
+ return;
232
+ }
233
+
234
+ $this->_output_log[] = "<pre>" . htmlentities($this->formatXml($data)) . "</pre>";
235
+ }
236
+
237
+ public function isDebugMode()
238
+ {
239
+ return $this->_debug_mode;
240
+ }
241
+
242
+ public function formatXml($xml_string)
243
+ {
244
+ try {
245
+ $dom = new DOMDocument('1.0');
246
+ $dom->preserveWhiteSpace = false;
247
+ $dom->formatOutput = true;
248
+ $dom->loadXML($xml_string);
249
+ return $dom->saveXML();
250
+ } catch (Exception $e) {
251
+ $this->logException($e);
252
+ return $xml_string;
253
+ }
254
+ }
255
+
256
+ private function getReportTable($heading, $table, $headings = true)
257
+ {
258
+ $output = "<h1>{$heading}</h1>";
259
+ $output .= "<table cellspacing='0' border='1'>";
260
+
261
+ if ($headings) {
262
+ $output .= "<thead>
263
+ <tr class='headings'>
264
+ <th>Setting</th>
265
+ <th>Value</th>
266
+ </tr>
267
+ </thead>";
268
+ }
269
+
270
+ foreach ($table as $key => $value) {
271
+ $output .= "<tr class='border'>
272
+ <td>{$key}</td>
273
+ <td>{$value}</td>
274
+ </tr>";
275
+ }
276
+ $output .= "</table>";
277
+
278
+ return $output;
279
+ }
280
+
281
+ public function getReport($customer = null)
282
+ {
283
+ $environment = $this->getEnvironmentInfo();
284
+ $store_configuration = $this->getConfigurationInfo();
285
+
286
+ $output = "<html><head></head><body>";
287
+
288
+ if ($customer != null) {
289
+ $output .= $this->getReportTable("Customer Information", $customer, false);
290
+ }
291
+
292
+ $output .= $this->getReportTable("General Configuration", $environment);
293
+
294
+ foreach ($store_configuration as $code => $configuration) {
295
+ $output .= $this->getReportTable("Module Configuration for store: {$code}", $configuration);
296
+ }
297
+
298
+ $output .= "<h1>Log File</h1>";
299
+ $output .= "<pre>" . $this->getLogFileContents() . "</pre>";
300
+
301
+ $output .= "</body></html>";
302
+
303
+ return $output;
304
+ }
305
+
306
+ private function getArrayData($data)
307
+ {
308
+ if (count($data) == 0) {
309
+ return "";
310
+ }
311
+
312
+ $first = reset($data);
313
+
314
+ if (isset($first['magento'])) {
315
+ $output = "<table cellspacing='0' class='data ed-config-subtable'>
316
+ <thead>
317
+ <tr class='headings'>
318
+ <th>Magento</th>
319
+ <th>Campaigner</th>
320
+ </tr>
321
+ </thead><tbody>";
322
+
323
+ foreach ($data as $row) {
324
+ $output .= "<tr class='border'><td>{$row['magento']}</td><td>{$row['campaigner']}</td></tr>";
325
+ }
326
+ } else {
327
+ $output = "<table cellspacing='0' class='data ed-config-subtable'>
328
+ <thead>
329
+ <tr class='headings'>
330
+ <th>Key</th>
331
+ <th>Value</th>
332
+ </tr>
333
+ </thead><tbody>";
334
+
335
+ foreach ($data as $key => $value) {
336
+ $output .= "<tr class='border'><td>{$key}</td><td>{$value}</td></tr>";
337
+ }
338
+ }
339
+
340
+ $output .= "</tbody></table>";
341
+
342
+ return $output;
343
+ }
344
+
345
+ public function getEnvironmentInfo()
346
+ {
347
+ $data = array(
348
+ 'Magento Version' => Mage::getVersion(),
349
+ 'Campaigner Version' => (string) Mage::getConfig()->getNode('modules/Campaigner_Integration/version'),
350
+ 'Website URL' => Mage::getBaseUrl(),
351
+ 'PHP Version' => phpversion(),
352
+ 'Server Software' => $_SERVER['SERVER_SOFTWARE']
353
+ );
354
+
355
+ if (method_exists("Mage","getEdition")) {
356
+ $data['Magento Edition'] = Mage::getEdition();
357
+ }
358
+
359
+ return $data;
360
+ }
361
+
362
+ public function getConfigurationInfo()
363
+ {
364
+ $store_data = array();
365
+
366
+ $stores = Mage::app()->getStores();
367
+
368
+ foreach ($stores as $store) {
369
+ $e_config = Mage::getStoreConfig("campaigner/general", $store);
370
+
371
+ $data = array( );
372
+
373
+ $data['store id'] = $store->getId();
374
+ $data['url'] = Mage::getStoreConfig(Mage_Core_Model_Store::XML_PATH_SECURE_BASE_URL, $store);
375
+
376
+ foreach ($e_config as $key => $value) {
377
+ if (is_array($value)) {
378
+ // Skip
379
+ } else {
380
+ // Check if the data is serialized
381
+ $test_data = @unserialize($value);
382
+ if ($test_data !== false) {
383
+ $data[$key] = $this->getArrayData($test_data);
384
+ } else {
385
+ $data[$key] = $value;;
386
+ }
387
+ }
388
+ }
389
+
390
+ $store_data[$store->getName()] = $data;
391
+ }
392
+
393
+ return $store_data;
394
+ }
395
+
396
+ public function getLogFileContents()
397
+ {
398
+ $log_file = $this->getLogFilePath();
399
+
400
+ if (!file_exists($log_file)) {
401
+ return "";
402
+ }
403
+
404
+ $max_size = $this->getMaxLogFileSize();
405
+ $log_file_size = filesize($log_file);
406
+ $offset = 0;
407
+
408
+ if ($log_file_size > $max_size) {
409
+ $offset = $log_file_size - $max_size;
410
+ }
411
+
412
+ return htmlentities(file_get_contents($log_file,false,null,$offset));
413
+ }
414
+
415
+ public function getLogFilePath()
416
+ {
417
+ return Mage::getBaseDir('log') . DS. self::LOG_FILE_NAME . self::LOG_FILE_EXT;
418
+ }
419
+
420
+ public function getLogFileName()
421
+ {
422
+ return self::LOG_FILE_NAME . self::LOG_FILE_EXT;
423
+ }
424
+
425
+ public function getLogFileSize()
426
+ {
427
+ $log_file = $this->getLogFilePath();
428
+
429
+ if (file_exists($log_file)) {
430
+ return filesize($log_file);
431
+ }
432
+
433
+ return 0;
434
+ }
435
+
436
+ public function isLogFileTooLarge()
437
+ {
438
+ if ($this->getLogFileSize() > $this->getMaxLogFileSize()) {
439
+ return true;
440
+ }
441
+
442
+ return false;
443
+ }
444
+
445
+ public function getLoggingStatus()
446
+ {
447
+ $this->checkTimeout();
448
+
449
+ $enabled = $this->config('logging_enabled') == 1;
450
+
451
+ $stores = Mage::app()->getStores();
452
+ $stores_selected = $this->arrayConfig("logging_stores_selected");
453
+
454
+ $areas_selected = $this->arrayConfig("logging_areas_selected");
455
+
456
+ $date = $this->config('logging_start_date');
457
+
458
+ $duration = (int)$this->config('logging_duration') * 60;
459
+
460
+ $trouble_status = array(
461
+ 'enabled' => $enabled,
462
+ 'start_date' => "",
463
+ 'seconds' => "",
464
+ 'duration' => $duration,
465
+ 'duration_display' => Mage::helper('campaigner')->getDuration($duration),
466
+ 'stores' => array()
467
+ );
468
+
469
+ if ($date != "") {
470
+ $trouble_status['start_date'] = $date;
471
+
472
+ $trouble_status['elapsed'] = Mage::helper('campaigner')->timeElapsed2String($date);
473
+ $now = Mage::getModel('core/date')->gmtTimestamp();
474
+ $trouble_status['seconds'] = abs($now - strtotime($date));
475
+ }
476
+
477
+ foreach ($stores as $store) {
478
+ $data = array();
479
+
480
+ $store_id = $store->getId();
481
+
482
+ $selected = in_array($store_id,$stores_selected);
483
+
484
+ $data['id'] = $store_id;
485
+ $data['name'] = Mage::helper('campaigner')->getFullStoreName($store);
486
+
487
+ $data['campaigner_enabled'] = Mage::helper('campaigner')->config('active',$store) == 1;
488
+
489
+ if ($enabled) {
490
+ $data['logging_enabled'] = $this->isLoggingEnabledForStore($store_id);
491
+ } else {
492
+ $data['logging_enabled'] = false;
493
+ }
494
+
495
+ $data['selected'] = $selected;
496
+
497
+ $trouble_status['stores'][$store_id] = $data;
498
+ }
499
+
500
+ $areas = array();
501
+
502
+ foreach ($this->_areas as $area => $label) {
503
+ if ($enabled == false) {
504
+ $area_enabled = false;
505
+ } else {
506
+ $area_enabled = $this->isLoggingEnabledForArea($area);
507
+ }
508
+
509
+ $areas[$area] = array(
510
+ 'area' => $area,
511
+ 'label' => $label,
512
+ 'logging_enabled' => $area_enabled,
513
+ 'selected' => in_array($area,$areas_selected)
514
+ );
515
+ }
516
+
517
+ $trouble_status['areas'] = $areas;
518
+
519
+ return $trouble_status;
520
+ }
521
+
522
+ public function getLogFilelastUpdate()
523
+ {
524
+ $log_file = $this->getLogFilePath();
525
+
526
+ if (file_exists($log_file)) {
527
+ return filemtime($log_file);
528
+ }
529
+
530
+ return "";
531
+ }
532
+
533
+ public function getMaxLogFileSize()
534
+ {
535
+ return $this->config('max_file_size');
536
+ }
537
+
538
+ public function config($value)
539
+ {
540
+ return Mage::getStoreConfig("campaigner/troubleshooting/{$value}", 0);
541
+ }
542
+
543
+ public function arrayConfig($value)
544
+ {
545
+ $data = $this->config($value);
546
+
547
+ if ($data == "") {
548
+ return array();
549
+ }
550
+
551
+ return explode(",",$data);
552
+ }
553
+
554
+ private function updateConfig($path, $value, $scope = "default", $store = 0)
555
+ {
556
+ $config = Mage::getConfig();
557
+ $config->saveConfig("campaigner/troubleshooting/{$path}",$value,$scope,$store);
558
+ $config->cleanCache();
559
+ }
560
+
561
+ public function disable()
562
+ {
563
+ $this->updateConfig("logging_start_date","");
564
+ $this->updateConfig("logging_enabled","0");
565
+ }
566
+
567
+ public function isDiagnosticEnabled()
568
+ {
569
+ return $this->config('diagnostic_enabled') == 1;
570
+ }
571
+
572
+ private function getConfigOptions()
573
+ {
574
+ if ($this->_config_options == null) {
575
+ $options = $this->config('options');
576
+
577
+ if ($options == "") {
578
+ $this->_config_options = "";
579
+ } else {
580
+ $this->_config_options = unserialize($options);
581
+ }
582
+ }
583
+
584
+ return $this->_config_options;
585
+ }
586
+
587
+ private function isLoggingEnabledForArea($area = "")
588
+ {
589
+ if ($area == "") {
590
+ $area = $this->_log_area;
591
+ }
592
+
593
+ if ($this->config('logging_areas') == "all") {
594
+ return true;
595
+ }
596
+
597
+ $areas_selected = $this->arrayConfig("logging_areas_selected");
598
+
599
+ return in_array($area,$areas_selected);
600
+ }
601
+
602
+ private function isLoggingEnabledForStore($store = 0)
603
+ {
604
+ if ($this->config('logging_stores') == "all") {
605
+ return true;
606
+ }
607
+
608
+ $stores_selected = $this->arrayConfig("logging_stores_selected");
609
+
610
+ if (is_object($store)) {
611
+ $store = $store->getId();
612
+ }
613
+
614
+ return in_array($store,$stores_selected);
615
+ }
616
+
617
+ private function isLoggingEnabledForIP()
618
+ {
619
+ $ip = Mage::helper('core/http')->getRemoteAddr();
620
+
621
+ $logging_ip = $this->arrayConfig("logging_ip");
622
+
623
+ if (count($logging_ip) == 0) {
624
+ return true;
625
+ }
626
+
627
+ return in_array($ip,$logging_ip);
628
+ }
629
+
630
+ public function isLoggingEnabled($store = 0)
631
+ {
632
+ // First check the global setting
633
+ if (!$this->config('logging_enabled')) {
634
+ return false;
635
+ }
636
+
637
+ if (!$this->isLoggingEnabledForIP()) {
638
+ return false;
639
+ }
640
+
641
+ if (!$this->isLoggingEnabledForArea()) {
642
+ return false;
643
+ }
644
+
645
+ if (!$this->isLoggingEnabledForStore($store)) {
646
+ return false;
647
+ }
648
+ return $this->checkTimeout();
649
+ }
650
+
651
+ private function checkTimeout()
652
+ {
653
+ $date = $this->config('logging_start_date');
654
+
655
+ if ($date == "" || $date == 0) {
656
+ $this->disable();
657
+ return false;
658
+ }
659
+
660
+ $now = Mage::getModel('core/date')->gmtTimestamp();
661
+
662
+ $seconds = abs($now - strtotime($date));
663
+
664
+ $duration = (int)$this->config('logging_duration');
665
+
666
+ $duration *= 60;
667
+
668
+ if ($seconds > $duration) {
669
+ $this->disable();
670
+ Mage::app()->reinitStores();
671
+ return false;
672
+ }
673
+
674
+ return true;
675
+ }
676
+
677
+ public function logAndDebug($data)
678
+ {
679
+ $this->debug($data);
680
+
681
+ $this->log($data);
682
+ }
683
+
684
+ public function log($data, $prefix = "", $area = "")
685
+ {
686
+ $store = Mage::helper('campaigner')->getCurrentStore();
687
+
688
+ if ($area == "") {
689
+ $area = $this->_log_area;
690
+ }
691
+
692
+ if ($this->_log_level > $this->_log_level_active) {
693
+ return;
694
+ }
695
+
696
+ if ($this->isLoggingEnabled($store, $area)) {
697
+ if (is_array($data) || is_object($data)) {
698
+ if (is_object($data) && get_class($data) == "SimpleXMLElement") {
699
+ $data = $this->formatXml($data->asXml());
700
+ } else {
701
+ $data = $this->safeDump($data);
702
+ }
703
+ }
704
+
705
+ if ($prefix != "") {
706
+ $prefix .= ": ";
707
+ }
708
+
709
+ if ($area != "") {
710
+ $data = "[{$area}] [{$store}] {$prefix}{$data}";
711
+ }
712
+
713
+ $this->forceLog($data);
714
+ }
715
+ }
716
+
717
+ public function forceLog($data)
718
+ {
719
+ Mage::log($data,null,self::LOG_FILE_NAME . self::LOG_FILE_EXT, true);
720
+ }
721
+
722
+ public function eraseLog()
723
+ {
724
+ try {
725
+ $log_file = Mage::getBaseDir('var') . DS . 'log' . DS . self::LOG_FILE_NAME . self::LOG_FILE_EXT;
726
+
727
+ if (!file_exists($log_file)) {
728
+ return true;
729
+ }
730
+
731
+ unlink($log_file);
732
+ return true;
733
+ } catch (Exception $e) {
734
+ return false;
735
+ }
736
+ }
737
+
738
+ public function logReason($data)
739
+ {
740
+ $this->log($data,self::DISABLED_REASON_PREFIX);
741
+ }
742
+
743
+ public function logException($e)
744
+ {
745
+ $this->log($e->__toString(),"Exception");
746
+ }
747
+
748
+ public function logXml($xml, $prefix = "")
749
+ {
750
+ $this->log($this->formatXml($xml),$prefix);
751
+ }
752
+
753
+ public function setLogArea($area)
754
+ {
755
+ $this->_log_area = $area;
756
+ }
757
+
758
+ public function setLogLevel($level)
759
+ {
760
+ $this->_log_level = $level;
761
+ }
762
+
763
+ public function resetLogLevel()
764
+ {
765
+ $this->_log_level = self::LOG_LEVEL_NORMAL;
766
+ }
767
+ }
app/code/community/Campaigner/Integration/Model/Abandoned.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_Abandoned extends Mage_Core_Model_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('campaigner/abandoned');
9
+ }
10
+
11
+ public function loadByQuoteId($quote_id)
12
+ {
13
+ if ($data = $this->getResource()->loadByQuoteId($quote_id)) {
14
+ $this->addData($data);
15
+ }
16
+ else {
17
+ return false;
18
+ }
19
+
20
+ return $this;
21
+ }
22
+
23
+ public function init(Campaigner_Integration_Model_Session $session)
24
+ {
25
+ try {
26
+ $quote_id = Mage::helper('checkout/cart')->getQuote()->getId();
27
+
28
+ if (!$quote_id) {
29
+ return;
30
+ }
31
+
32
+ if (!$this->loadByQuoteId($quote_id)) {
33
+ $this->setQuoteId($quote_id);
34
+ $this->setSessionId($session->getId());
35
+ $this->save();
36
+ }
37
+ }
38
+ catch (Exception $e) {
39
+ Mage::helper('campaigner/troubleshooting')->logException($e);
40
+ Mage::logException($e);
41
+ }
42
+ return $this;
43
+ }
44
+ }
app/code/community/Campaigner/Integration/Model/Abandoned/Observer.php ADDED
@@ -0,0 +1,332 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_Abandoned_Observer extends Campaigner_Integration_Model_Observer_Abstract
4
+ {
5
+ private $_cart_status = array();
6
+
7
+ // START ABANDONED CRON
8
+ private function getAbandonedTime()
9
+ {
10
+ $time = $this->_helper->config('abandonedtime');
11
+ $time *= 60; // Adjust to seconds.
12
+
13
+ $date = date(Mage::getModel('core/date')->gmtTimestamp());
14
+
15
+ $date = $date - $time;
16
+
17
+ return date($this->_date_format, $date);
18
+ }
19
+
20
+ private function setSentToCampaignerDate($quote_id, $date, $status = null)
21
+ {
22
+ try {
23
+ $abandoned = Mage::getModel('campaigner/abandoned')->loadByQuoteId($quote_id);
24
+
25
+ if (!$abandoned) {
26
+ throw new Exception("Failed to load abandoned cart row to update date sent.", 1);
27
+ }
28
+
29
+ if ($status != null) {
30
+ $this->_cart_status[$quote_id] = array('success' => false, 'status' => $status);
31
+ $abandoned->setStatus($status);
32
+ } else {
33
+ $this->_cart_status[$quote_id] = array('success' => true);
34
+ $abandoned->setDateSent($date);
35
+ $abandoned->setStatus("");
36
+ }
37
+ $abandoned->save();
38
+ } catch (Exception $e) {
39
+ Mage::logException($e);
40
+ $this->_logException($e);
41
+ }
42
+ }
43
+
44
+ private function processAbandoned($quote)
45
+ {
46
+ $this->_log("ProcessAbandoned Start");
47
+ $email = $quote->getCustomerEmail();
48
+
49
+ if ($email == null) {
50
+ $email = $quote->getEmail();
51
+ }
52
+
53
+ $abandonedDate = $quote->getUpdatedAt();
54
+
55
+ $merge_vars = Mage::helper('campaigner')->getQuoteMergeVars($quote);
56
+
57
+ $merge_vars['AbandonedDate'] = $abandonedDate;
58
+ $merge_vars['AbandonedUrl'] = Mage::helper('campaigner/abandoned')->getAbandonedUrl($quote);
59
+
60
+ Mage::helper('campaigner/abandoned')->addSequence($merge_vars);
61
+
62
+ $merge_vars = Mage::helper('campaigner/order')->getMergeOrderItems($quote, $merge_vars, "AB");
63
+
64
+ $contactData = Mage::getSingleton('campaigner/wrapper_abandoned')->getOneCart($email,$merge_vars);
65
+
66
+ $this->_log("ProcessAbandoned End");
67
+
68
+ return $contactData;
69
+ }
70
+
71
+ private function updateQuoteList($quote_list, $details)
72
+ {
73
+ if (!isset($details->UploadResultData) || !is_array($details->UploadResultData)) {
74
+
75
+ $status = "Unknown Error";
76
+ if (isset($details->UploadResultData)) {
77
+ $status = $details->UploadResultData->ResultCode;
78
+ }
79
+
80
+ foreach (array_keys($quote_list) as $key) {
81
+ $quote_list[$key]['status'] = $status;
82
+ }
83
+ return $quote_list;
84
+ }
85
+
86
+ foreach ($details->UploadResultData as $result) {
87
+ if ($result->ResultCode != 'Success') {
88
+ $email = $result->ContactKey->ContactUniqueIdentifier;
89
+
90
+ $quote_list[$email]['status'] = $result->ResultCode;
91
+ }
92
+ }
93
+
94
+ return $quote_list;
95
+ }
96
+
97
+ private function _abandonedCartsProcessor($collection, $store = null, $mark_time = true)
98
+ {
99
+ // Store the time we last run
100
+ $date = date(Mage::getModel('core/date')->gmtTimestamp());
101
+ $date = date($this->_date_format, $date);
102
+
103
+ if ($mark_time) {
104
+ $this->_log("Saving Last Run Date: {$date}");
105
+ $this->_helper->updateConfig("abandoned_last_run", $date, $store);
106
+ }
107
+
108
+ $subscribers = false;
109
+
110
+ $contactList = array();
111
+
112
+ $quote_list = array();
113
+
114
+ // Get the data for each abandoned cart
115
+ foreach ($collection as $quote) {
116
+ $contactData = $this->processAbandoned($quote, $date);
117
+
118
+ $contactList[] = $contactData;
119
+
120
+ $email = $contactData['EmailAddress'];
121
+ $quote_list[$email] = array('quote_id' => $quote->getId(), 'status' => null);
122
+
123
+ $subscribers = true;
124
+ }
125
+
126
+ if (!$subscribers) {
127
+ $this->_logReason("No Carts Found");
128
+ return; // No abandoned carts found
129
+ }
130
+
131
+ $this->_log("Sending Abandoned Carts");
132
+ // Send them all at once
133
+
134
+ try {
135
+ Mage::getSingleton('campaigner/wrapper_abandoned')->send($contactList);
136
+ } catch (Campaigner_Integration_Model_Wrapper_Exception $e) {
137
+ $this->_logException($e);
138
+ $details = $e->getDetails();
139
+
140
+ $this->_log($details);
141
+ $quote_list = $this->updateQuoteList($quote_list, $details);
142
+ }
143
+
144
+ $this->_log("Setting date sent for all quotes Start");
145
+
146
+ $this->setDateSent($quote_list,$date);
147
+
148
+ $this->_log("Setting date sent for all quotes End");
149
+ }
150
+
151
+ private function setDateSent($quote_list, $date)
152
+ {
153
+ foreach ($quote_list as $data) {
154
+ $quote_id = $data['quote_id'];
155
+ $status = $data['status'];
156
+
157
+ $this->setSentToCampaignerDate($quote_id, $date, $status);
158
+ }
159
+ }
160
+
161
+ public function abandonedStoreProcessor($store, $check_date)
162
+ {
163
+ $store_code = $store->getCode();
164
+
165
+ $this->_log("Processing Store: {$store_code}");
166
+
167
+ if (!$this->_helper->getAbandonedEnabled()) {
168
+ $this->_logReason($this->_helper->getAbandonedDisabledReason());
169
+ return;
170
+ }
171
+
172
+ Mage::helper('campaigner/fields')->verifyFields();
173
+
174
+ // Setup sequence for this store
175
+ Mage::helper('campaigner/abandoned')->setupSequence();
176
+
177
+ // Get abandoned collection
178
+ $collection = Mage::getResourceModel('campaigner/abandoned_collection');
179
+
180
+ $collection->prepareForAbandonedProcess($check_date, $store->getId());
181
+
182
+ $this->_log("SQL: " . $collection->getSelect()->__toString());
183
+
184
+ $this->_abandonedCartsProcessor($collection, $store->getId());
185
+
186
+ Mage::helper('campaigner/abandoned')->saveCurrentSequence();
187
+
188
+ $this->_log("Finished Processing Store: {$store_code}");
189
+
190
+ }
191
+
192
+ public function manualCartsProcessor($store_id = null)
193
+ {
194
+ try {
195
+ Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
196
+ $this->_setLogArea(Campaigner_Integration_Helper_Troubleshooting::ABANDONED_CART);
197
+ $this->_log("Manual Abandoned Carts Processor Start");
198
+
199
+ $check_date = $this->getAbandonedTime();
200
+
201
+ $this->_log("Check Date: {$check_date}");
202
+
203
+ $stores = Mage::app()->getStores();
204
+
205
+ foreach ($stores as $store) {
206
+ if ($store_id == null || $store_id == $store->getId()) {
207
+ Mage::app()->setCurrentStore($store->getCode());
208
+
209
+ $this->abandonedStoreProcessor($store, $check_date);
210
+ }
211
+ }
212
+
213
+ Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
214
+
215
+ $this->_log("Manual Abandoned Carts Processor End");
216
+ } catch (Exception $e) {
217
+ Mage::logException($e);
218
+ $this->_logException($e);
219
+ }
220
+ }
221
+
222
+ public function abandonedCartsProcessor()
223
+ {
224
+ try {
225
+ Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
226
+ $this->_setLogArea(Campaigner_Integration_Helper_Troubleshooting::ABANDONED_CART);
227
+ $this->_log("Abandoned Carts Processor Start");
228
+
229
+ $check_date = $this->getAbandonedTime();
230
+
231
+ $this->_log("Check Date: {$check_date}");
232
+
233
+ $stores = Mage::app()->getStores();
234
+
235
+ foreach ($stores as $store) {
236
+ Mage::app()->setCurrentStore($store->getCode());
237
+
238
+ $this->abandonedStoreProcessor($store, $check_date);
239
+ }
240
+
241
+ Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
242
+
243
+ $date = date(Mage::getModel('core/date')->gmtTimestamp());
244
+ $date = date($this->_date_format, $date);
245
+
246
+ $this->_log("Saving Last Cron Run Date: {$date}");
247
+ $this->_helper->updateConfig("cron_last_run", $date);
248
+
249
+ $this->_log("Abandoned Carts Processor End");
250
+ } catch (Exception $e) {
251
+ Mage::logException($e);
252
+ $this->_logException($e);
253
+ }
254
+ }
255
+
256
+ public function SendAbandonedCarts($id_list)
257
+ {
258
+ $count = 0;
259
+ $this->_cart_status = array();
260
+
261
+ Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
262
+
263
+ $this->_setLogArea(Campaigner_Integration_Helper_Troubleshooting::ABANDONED_CART);
264
+ $this->_log("Sending Specific Abandoned Carts Start");
265
+
266
+ Mage::helper('campaigner/fields')->verifyFields();
267
+
268
+ $this->_log($id_list, "ID LIST");
269
+
270
+ $stores = Mage::app()->getStores();
271
+
272
+ foreach ($stores as $store) {
273
+ $this->_log("Checking for valid carts in store: {$store->getName()} ({$store->getId()})");
274
+ if (!Mage::helper('campaigner')->getAbandonedEnabled($store->getId())) {
275
+ $this->_log('Abandoned Carts not enabled...');
276
+ continue;
277
+ }
278
+
279
+ Mage::app()->setCurrentStore($store->getCode());
280
+
281
+ // Get abandoned collection
282
+ $collection = Mage::getResourceModel('campaigner/abandoned_collection');
283
+
284
+ $collection->prepareForManualAbandonedProcess($id_list, $store->getId());
285
+
286
+ $count += count($collection);
287
+
288
+ $this->_log("SQL: " . $collection->getSelect()->__toString());
289
+
290
+ // Setup sequence for this store
291
+ Mage::helper('campaigner/abandoned')->setupSequence();
292
+
293
+ $this->_abandonedCartsProcessor($collection, $store, false);
294
+
295
+ Mage::helper('campaigner/abandoned')->saveCurrentSequence();
296
+ }
297
+
298
+ Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
299
+
300
+ $this->_log("Sending Specific Abandoned Carts End");
301
+
302
+ return $this->_cart_status;
303
+
304
+ }
305
+
306
+ // END ABANDONED CRON
307
+
308
+ // START QUOTE SAVE AFTER
309
+ public function quoteSaveAfter(Varien_Event_Observer $observer)
310
+ {
311
+ try {
312
+ $this->_setLogArea(Campaigner_Integration_Helper_Troubleshooting::ABANDONED_CART);
313
+ $this->_logger->setLogLevel(Campaigner_Integration_Helper_Troubleshooting::LOG_LEVEL_LOW);
314
+ $this->_log("Quote Save After Start");
315
+
316
+ if (!$this->_helper->getAbandonedEnabled()) {
317
+ $this->_logReason($this->_helper->getAbandonedDisabledReason());
318
+ return;
319
+ }
320
+
321
+ Mage::getSingleton('campaigner/session')->init();
322
+
323
+ $this->_log("Quote Save After End");
324
+ $this->_logger->resetLogLevel();
325
+ } catch (Exception $e) {
326
+ $this->_logger->resetLogLevel();
327
+ Mage::logException($e);
328
+ $this->_logException($e);
329
+ }
330
+ }
331
+ // END QUOTE SAVE AFTER
332
+ }
app/code/community/Campaigner/Integration/Model/Action/List.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_Action_List extends Mage_Core_Model_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('campaigner/action_list');
9
+ }
10
+
11
+ public function init($email, $action, $action_data, $customer_id = null)
12
+ {
13
+ $this->loadByEmailAndAction($email, $action);
14
+
15
+ $date = date(Mage::getModel('core/date')->gmtTimestamp());
16
+ $date = date(Campaigner_Integration_Helper_Data::DATE_FORMAT, $date);
17
+
18
+ $data = array(
19
+ 'email' => $email,
20
+ 'customer_id' => $customer_id,
21
+ 'action' => $action,
22
+ 'data' => serialize($action_data),
23
+ 'store_id' => Mage::helper('campaigner')->getCurrentStore(),
24
+ 'created_at' => $date
25
+ );
26
+
27
+ $this->addData($data);
28
+
29
+ return $this;
30
+ }
31
+
32
+ public function loadByEmailAndAction($email, $action)
33
+ {
34
+ if ($data = $this->getResource()->loadByEmailAndAction($email, $action)) {
35
+ $this->addData($data);
36
+ return $this;
37
+ }
38
+ return false;
39
+ }
40
+ }
app/code/community/Campaigner/Integration/Model/Action/Observer.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_Action_Observer extends Campaigner_Integration_Model_Observer_Abstract
4
+ {
5
+ public function processActions()
6
+ {
7
+ try {
8
+ $order_helper = Mage::helper('campaigner/order');
9
+ $this->_setLogArea(Campaigner_Integration_Helper_Troubleshooting::ACTIONS);
10
+ $this->_log("processActions Start");
11
+
12
+ $this->_log("processActions End");
13
+ } catch (Exception $e) {
14
+ Mage::logException($e);
15
+ $this->_logException($e);
16
+ }
17
+ }
18
+ }
app/code/community/Campaigner/Integration/Model/Configuration/Observer.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_Configuration_Observer extends Campaigner_Integration_Model_Observer_Abstract
4
+ {
5
+ public function saveConfig(Varien_Event_Observer $observer)
6
+ {
7
+ $this->_logger->setLogArea(Campaigner_Integration_Helper_Troubleshooting::CONFIG);
8
+ $this->_logger->setLogLevel(Campaigner_Integration_Helper_Troubleshooting::LOG_LEVEL_LOW);
9
+ $store = $this->_helper->getStoreId($observer->getEvent()->getStore());
10
+ $post = Mage::app()->getRequest()->getPost();
11
+
12
+ $fields = $post['groups']['general']['fields'];
13
+
14
+ $api_username = isset($fields['api_username']['value']) ? $fields['api_username']['value'] : $this->_helper->config('api_username');
15
+ $api_password = isset($fields['api_password']['value']) ? $fields['api_password']['value'] : $this->_helper->config('api_password');
16
+
17
+ if ($api_username == '' || $api_password == '') {
18
+ $this->_helper->updateConfig('setup', 0, $store);
19
+ $this->_helper->updateConfig('active', false, $store);
20
+ return;
21
+ }
22
+
23
+ $old_username = $fields['old_api_username']['value'];
24
+ $old_password = $fields['old_api_password']['value'];
25
+
26
+ // Need to force check here
27
+
28
+ $result = Mage::helper('campaigner/troubleshooting')->validateCredentials($api_username, $api_password);
29
+
30
+ if ($result['valid'] == false) {
31
+ $message = "Module setup failed: {$result['message']}";
32
+ $this->_logger->log($message);
33
+
34
+ Mage::throwException($message);
35
+ }
36
+
37
+ $this->_helper->enableCampaigner($store);
38
+
39
+ // Now that we know we have a valid configuration we can update our attributes
40
+ $attributes = Mage::getSingleton('campaigner/wrapper_database')->getAllColumns(false,true,false);
41
+
42
+ Mage::helper('campaigner/fields')->saveFieldMap($attributes);
43
+
44
+ $force_product = false;
45
+ if (isset($fields['save_latest_order']['value']) && $fields['save_latest_order']['value'] == true) {
46
+ $force_product = true;
47
+ }
48
+
49
+ // Verify all custom fields are present
50
+ Mage::helper('campaigner/fields')->verifyFields($force_product);
51
+
52
+ $this->_logger->resetLogLevel();
53
+ }
54
+ }
app/code/community/Campaigner/Integration/Model/Customer/Observer.php ADDED
@@ -0,0 +1,270 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_Customer_Observer extends Campaigner_Integration_Model_Observer_Abstract
4
+ {
5
+ private function hasCustomerChanged($customer)
6
+ {
7
+ $maps = unserialize( $this->_helper->config('map_fields', $customer->getStoreId()) );
8
+
9
+ $this->_log('Checking for mapped data changes');
10
+
11
+ foreach ($maps as $map) {
12
+ $field = $map['magento'];
13
+ $original = $customer->getOrigData($field);
14
+ $current = $customer->getData($field);
15
+
16
+ $this->_log("Original: {$original} - Current: {$current}");
17
+
18
+ if ($original != $current) {
19
+ return true;
20
+ }
21
+ }
22
+
23
+ return false;
24
+ }
25
+
26
+ protected function getMergeCustomer($object = NULL)
27
+ {
28
+ //Initialize as GUEST customer
29
+ $customer = new Varien_Object;
30
+
31
+ $this->_log("Observer Merge Vars");
32
+
33
+ $regCustomer = Mage::registry('current_customer');
34
+ $guestCustomer = Mage::registry('campaigner_guest_customer');
35
+
36
+ if (Mage::helper('customer')->isLoggedIn()) {
37
+ $this->_log("Logged in Customer");
38
+ $customer = Mage::helper('customer')->getCustomer();
39
+ } else if ($regCustomer) {
40
+ $this->_log("Current Customer");
41
+ $customer = $regCustomer;
42
+ } else if ($guestCustomer) {
43
+ $this->_log("Guest Customer");
44
+ $customer = $guestCustomer;
45
+ } else {
46
+ $this->_log("Parameter Customer");
47
+ $customer = $object;
48
+ }
49
+
50
+ $address = Mage::getModel('customer/address')->load($customer->getDefaultBilling());
51
+ if ($address) {
52
+ $customer->setBillingAddress($address);
53
+ }
54
+
55
+ return $customer;
56
+ }
57
+
58
+ private function canShowStatus($campaigner_session)
59
+ {
60
+ $last_notified = $campaigner_session->getStatusNotified();
61
+
62
+ if (strtotime($last_notified) <= strtotime('-24 hours')) {
63
+ return true;
64
+ }
65
+ return false;
66
+ }
67
+
68
+ private function checkStatus($customer)
69
+ {
70
+ $campaigner_session = Mage::getSingleton('campaigner/session')->init();
71
+ $session = Mage::getSingleton('customer/session');
72
+
73
+ if ($campaigner_session->getStatus() == null || $this->canShowStatus($campaigner_session) == true) {
74
+ try {
75
+ $contact_data = Mage::getSingleton("campaigner/wrapper_subscribers")->getContact($customer->getEmail(), true, false, true, false);
76
+
77
+ $status = $contact_data->SystemAttributes->Status;
78
+
79
+ switch ($status) {
80
+ case "unsubscribed": {
81
+ $url = Mage::getUrl('campaigner/customer_account/resubscribe');
82
+ $notice = "You have indicated that you no longer wish to receive newsletter emails. <a href='{$url}'>Click here</a> to begin receiving these emails again.";
83
+ Mage::getSingleton('core/session')->addNotice($notice);
84
+ $session->addNotice($notice);
85
+ } break;
86
+ case "hardbounce": {
87
+ $url = Mage::getUrl('customer/account/edit');
88
+ $email = $session->getCustomer()->getEmail();
89
+ $notice = "We've been unable to reach you at {$email}. Please <a href='{$url}'>update</a> your email address.";
90
+ $session->addNotice($notice);
91
+ } break;
92
+ }
93
+
94
+ $campaigner_session->setStatus($status);
95
+
96
+ $date = date(Mage::getModel('core/date')->gmtTimestamp());
97
+ $date = date(Campaigner_Integration_Helper_Data::DATE_FORMAT, $date);
98
+
99
+ $campaigner_session->setStatusNotified($date);
100
+ $campaigner_session->save();
101
+ } catch (Exception $e) {
102
+ $this->_logException($e);
103
+ }
104
+ }
105
+ }
106
+
107
+
108
+ public function customerLogin(Varien_Event_Observer $observer)
109
+ {
110
+ try
111
+ {
112
+ $this->_setLogArea(Campaigner_Integration_Helper_Troubleshooting::CUSTOMER);
113
+ $this->_log("Customer Login Start");
114
+
115
+ $customer = $observer->getEvent()->getCustomer();
116
+
117
+ $this->checkStatus($customer);
118
+
119
+ if (!$this->_helper->canSendLastLogin()) {
120
+ $this->_logReason($this->_helper->getLastLoginDisabledReason());
121
+ return;
122
+ }
123
+
124
+ if (!$customer) {
125
+ $this->_logReason("Customer not found");
126
+ return;
127
+ }
128
+
129
+ $date = date(Mage::getModel('core/date')->gmtTimestamp());
130
+ $date = date($this->_date_format, $date);
131
+
132
+ $this->_log("Last Login Date: {$date}");
133
+
134
+ $email = $customer->getEmail();
135
+
136
+ $this->_log("Email: {$email}");
137
+
138
+ Mage::getSingleton('campaigner/wrapper_subscribers')->sendLastLogin($email, $date);
139
+
140
+ $this->_log("Customer Login End");
141
+ } catch (Exception $e) {
142
+ Mage::logException($e);
143
+ $this->_logException($e);
144
+ }
145
+ }
146
+
147
+ public function updateCustomer(Varien_Event_Observer $observer)
148
+ {
149
+ try {
150
+ $this->_setLogArea(Campaigner_Integration_Helper_Troubleshooting::CUSTOMER);
151
+ $this->_log("Update Customer Start");
152
+
153
+ if (!$this->_helper->campaignerEnabled()) {
154
+ $this->_logReason($this->_helper->getDisabledReason());
155
+ return;
156
+ }
157
+
158
+ $customer = $observer->getEvent()->getCustomer();
159
+
160
+ if (!$customer) {
161
+ $this->_logReason("Customer not found");
162
+ return;
163
+ }
164
+
165
+ $customer = $this->getMergeCustomer($customer);
166
+
167
+ $api = Mage::getSingleton('campaigner/wrapper_subscribers');
168
+
169
+ $oldEmail = $customer->getOrigData('email');
170
+ $email = $customer->getEmail();
171
+
172
+ if ($oldEmail == '') {
173
+ $this->_log("Original Email was blank. Adding Subscriber");
174
+ $api->add($customer);
175
+ } elseif ($oldEmail != $email) {
176
+ $this->_log("Modifying Email");
177
+
178
+ $this->_log("Adding Subscriber");
179
+ $api->add($customer);
180
+ } else {
181
+ if ($this->hasCustomerChanged($customer)) {
182
+ $this->_log("Updating Subscriber");
183
+ $api->add($customer);
184
+ } else {
185
+ $this->_logReason("Neither Email nor Mapped Data changed");
186
+ }
187
+ }
188
+
189
+ $this->_log("Update Customer End");
190
+ } catch (Exception $e) {
191
+ Mage::logException($e);
192
+ $this->_logException($e);
193
+ }
194
+ }
195
+
196
+ public function updateCustomerAdmin(Varien_Event_Observer $observer)
197
+ {
198
+ try {
199
+ $this->_setLogArea(Campaigner_Integration_Helper_Troubleshooting::CUSTOMER);
200
+ $this->_log("Update Customer (Admin) Start");
201
+
202
+ $starting_store = Mage::app()->getStore()->getCode();
203
+
204
+ $customer = $observer->getEvent()->getCustomer();
205
+
206
+ if (!$customer) {
207
+ $this->_logReason("Customer not found");
208
+ return;
209
+ }
210
+
211
+ $customer_store = $customer->getStore()->getId();
212
+
213
+ $current_store = Mage::app()->getStore()->getId();
214
+
215
+ $this->_log("Checking store");
216
+
217
+ if ($current_store == 0) {
218
+ $this->_log("Admin store current");
219
+ if ($customer_store == 0) {
220
+ $this->_logReason("Customer store can't be determined");
221
+ return;
222
+ } else {
223
+ Mage::app()->setCurrentStore($customer_store);
224
+ }
225
+ }
226
+
227
+ $this->_log("Correct store found");
228
+
229
+ if (!$this->_helper->campaignerEnabled()) {
230
+ $this->_logReason($this->_helper->getDisabledReason());
231
+ Mage::app()->setCurrentStore($starting_store);
232
+ return;
233
+ }
234
+
235
+ $merge_vars = $this->_helper->getMergeVars($customer);
236
+
237
+ $this->_log($merge_vars,"Merge Vars");
238
+
239
+ $api = Mage::getSingleton('campaigner/wrapper_subscribers');
240
+
241
+ $oldEmail = $customer->getOrigData('email');
242
+ $email = $customer->getEmail();
243
+
244
+ if ($oldEmail == '') {
245
+ $this->_log("Original Email was blank. Adding Subscriber");
246
+ $api->add($customer);
247
+ } elseif ($oldEmail != $email) {
248
+ $this->_log("Modifying Email");
249
+
250
+ $this->_log("Adding Subscriber");
251
+ $api->add($customer);
252
+ } else {
253
+ if ($this->hasCustomerChanged($customer)) {
254
+ $this->_log("Updating Subscriber");
255
+ $api->add($customer);
256
+ } else {
257
+ $this->_logReason("Neither Email nor Mapped Data changed");
258
+ }
259
+ }
260
+
261
+ $this->_log("Update Customer End");
262
+ } catch (Exception $e) {
263
+ Mage::logException($e);
264
+ $this->_logException($e);
265
+ }
266
+
267
+ Mage::app()->setCurrentStore($starting_store);
268
+ return;
269
+ }
270
+ }
app/code/community/Campaigner/Integration/Model/Email/Queue.php ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Campaigner_Integration_Model_Email_Queue extends Mage_Core_Model_Email_Queue
3
+ {
4
+ /**
5
+ * Send all messages in a queue
6
+ *
7
+ * @return Mage_Core_Model_Email_Queue
8
+ */
9
+ public function send()
10
+ {
11
+ $useCampaignerRelay = Mage::getStoreConfig('system/smtp/campaigner_use_smtp_relay');
12
+
13
+ if ($useCampaignerRelay == 0 && !Mage::helper('campaigner/email')->isRelayTest()) {
14
+ parent::send();
15
+ }
16
+
17
+ /** @var $collection Mage_Core_Model_Resource_Email_Queue_Collection */
18
+ $collection = Mage::getModel('core/email_queue')->getCollection()
19
+ ->addOnlyForSendingFilter()
20
+ ->setPageSize(self::MESSAGES_LIMIT_PER_CRON_RUN)
21
+ ->setCurPage(1)
22
+ ->load();
23
+
24
+ ini_set('SMTP', Mage::getStoreConfig('system/smtp/host'));
25
+ ini_set('smtp_port', Mage::getStoreConfig('system/smtp/port'));
26
+
27
+ // MODIFICATION
28
+ Mage::helper('campaigner/email')->setTransport();
29
+ // END MODIFICATION
30
+
31
+ /** @var $message Mage_Core_Model_Email_Queue */
32
+ foreach ($collection as $message) {
33
+ if ($message->getId()) {
34
+ $parameters = new Varien_Object($message->getMessageParameters());
35
+ if ($parameters->getReturnPathEmail() !== null) {
36
+ // MODIFICATION
37
+ //$mailTransport = new Zend_Mail_Transport_Sendmail("-f" . $parameters->getReturnPathEmail());
38
+ //Zend_Mail::setDefaultTransport($mailTransport);
39
+ }
40
+
41
+ $mailer = new Zend_Mail('utf-8');
42
+ foreach ($message->getRecipients() as $recipient) {
43
+ list($email, $name, $type) = $recipient;
44
+ switch ($type) {
45
+ case self::EMAIL_TYPE_BCC:
46
+ $mailer->addBcc($email, '=?utf-8?B?' . base64_encode($name) . '?=');
47
+ break;
48
+ case self::EMAIL_TYPE_TO:
49
+ case self::EMAIL_TYPE_CC:
50
+ default:
51
+ $mailer->addTo($email, '=?utf-8?B?' . base64_encode($name) . '?=');
52
+ break;
53
+ }
54
+ }
55
+
56
+ if ($parameters->getIsPlain()) {
57
+ $mailer->setBodyText($message->getMessageBody());
58
+ } else {
59
+ $mailer->setBodyHTML($message->getMessageBody());
60
+ }
61
+
62
+ $mailer->setSubject('=?utf-8?B?' . base64_encode($parameters->getSubject()) . '?=');
63
+ $mailer->setFrom($parameters->getFromEmail(), $parameters->getFromName());
64
+ if ($parameters->getReplyTo() !== null) {
65
+ $mailer->setReplyTo($parameters->getReplyTo());
66
+ }
67
+ if ($parameters->getReturnTo() !== null) {
68
+ $mailer->setReturnPath($parameters->getReturnTo());
69
+ }
70
+
71
+ try {
72
+ $mailer->send();
73
+ unset($mailer);
74
+ $message->setProcessedAt(Varien_Date::formatDate(true));
75
+ $message->save();
76
+ }
77
+ catch (Exception $e) {
78
+ unset($mailer);
79
+ $oldDevMode = Mage::getIsDeveloperMode();
80
+ Mage::setIsDeveloperMode(true);
81
+ Mage::logException($e);
82
+ Mage::setIsDeveloperMode($oldDevMode);
83
+
84
+ return false;
85
+ }
86
+ }
87
+ }
88
+
89
+ return $this;
90
+ }
91
+ }
app/code/community/Campaigner/Integration/Model/Email/Template.php ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_Email_Template extends Mage_Core_Model_Email_Template
4
+ {
5
+ /**
6
+ * Retrieve mail object instance
7
+ *
8
+ * @return Zend_Mail
9
+ */
10
+ public function getMail()
11
+ {
12
+ if (is_null($this->_mail)) {
13
+ // MODIFICATION START
14
+
15
+ $useCampaignerRelay = Mage::getStoreConfig('system/smtp/campaigner_use_smtp_relay');
16
+
17
+ if ($useCampaignerRelay == 1 || Mage::helper('campaigner/email')->isRelayTest()) {
18
+ Mage::helper('campaigner/email')->setTransport();
19
+ }
20
+ // MODIFICATION END
21
+
22
+ $this->_mail = new Zend_Mail('utf-8');
23
+ }
24
+
25
+ return $this->_mail;
26
+ }
27
+
28
+ /**
29
+ * Send mail to recipient
30
+ *
31
+ * @param array|string $email E-mail(s)
32
+ * @param array|string|null $name receiver name(s)
33
+ * @param array $variables template variables
34
+ * @return boolean
35
+ **/
36
+ public function send($email, $name = null, array $variables = array())
37
+ {
38
+ // MODIFICATION
39
+ if (!Mage::helper('campaigner/email')->isRelayTest()) {
40
+ return parent::send($email, $name, $variables);
41
+ }
42
+
43
+
44
+ if (!$this->isValidForSend()) {
45
+ throw new Exception('This letter cannot be sent.', 1);
46
+ }
47
+ // MODIFICATION END
48
+
49
+ $emails = array_values((array)$email);
50
+ $names = is_array($name) ? $name : (array)$name;
51
+ $names = array_values($names);
52
+ foreach ($emails as $key => $email) {
53
+ if (!isset($names[$key])) {
54
+ $names[$key] = substr($email, 0, strpos($email, '@'));
55
+ }
56
+ }
57
+
58
+ $variables['email'] = reset($emails);
59
+ $variables['name'] = reset($names);
60
+
61
+ // MODIFICATION START
62
+ //ini_set('SMTP', Mage::getStoreConfig('system/smtp/host'));
63
+ //ini_set('smtp_port', Mage::getStoreConfig('system/smtp/port'));
64
+ // MODIFICATION END
65
+
66
+ $mail = $this->getMail();
67
+
68
+ $setReturnPath = Mage::getStoreConfig(self::XML_PATH_SENDING_SET_RETURN_PATH);
69
+ switch ($setReturnPath) {
70
+ case 1:
71
+ $returnPathEmail = $this->getSenderEmail();
72
+ break;
73
+ case 2:
74
+ $returnPathEmail = Mage::getStoreConfig(self::XML_PATH_SENDING_RETURN_PATH_EMAIL);
75
+ break;
76
+ default:
77
+ $returnPathEmail = null;
78
+ break;
79
+ }
80
+
81
+ if ($returnPathEmail !== null) {
82
+ // MODIFICATION
83
+ throw new Exception("Return-Path setting is not compatible with Campaigner Relay");
84
+ // MODIFICATION END
85
+ $mailTransport = new Zend_Mail_Transport_Sendmail("-f".$returnPathEmail);
86
+ Zend_Mail::setDefaultTransport($mailTransport);
87
+ }
88
+
89
+ foreach ($emails as $key => $email) {
90
+ $mail->addTo($email, '=?utf-8?B?' . base64_encode($names[$key]) . '?=');
91
+ }
92
+
93
+ $this->setUseAbsoluteLinks(true);
94
+ $text = $this->getProcessedTemplate($variables, true);
95
+
96
+ if($this->isPlain()) {
97
+ $mail->setBodyText($text);
98
+ } else {
99
+ $mail->setBodyHTML($text);
100
+ }
101
+
102
+ $mail->setSubject('=?utf-8?B?' . base64_encode($this->getProcessedTemplateSubject($variables)) . '?=');
103
+ $mail->setFrom($this->getSenderEmail(), $this->getSenderName());
104
+
105
+ // MODIFICATION
106
+ $mail->send();
107
+ $this->_mail = null;
108
+ // MODIFICATION END
109
+
110
+ return true;
111
+ }
112
+ }
app/code/community/Campaigner/Integration/Model/Latest/Order.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_Latest_Order extends Mage_Core_Model_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('campaigner/latest_order');
9
+ }
10
+
11
+ public function loadByEmailAndStore($email, $store_id)
12
+ {
13
+ if ($data = $this->getResource()->loadByEmailAndStore($email, $store_id)) {
14
+ $this->addData($data);
15
+ } else {
16
+ return false;
17
+ }
18
+
19
+ return $this;
20
+ }
21
+
22
+ public function init($order)
23
+ {
24
+ try {
25
+ $order_id = $order->getId();
26
+
27
+ if (!$order_id) {
28
+ return;
29
+ }
30
+
31
+ $store_id = $order->getStoreId();
32
+
33
+ $email = $order->getCustomerEmail();
34
+
35
+ if (!$this->loadByEmailAndStore($email, $store_id)) {
36
+ $this->setOrderId($order_id);
37
+ $this->setEmail($email);
38
+ $this->setStoreId($store_id);
39
+ if ($order->getCustomerId()) {
40
+ $this->setCustomerId($order->getCustomerId());
41
+ }
42
+
43
+ $this->save();
44
+ } else {
45
+ if ($this->getOrderId() != $order_id) {
46
+ $this->setOrderId($order_id);
47
+ $this->setData('status',null);
48
+ $this->setData('date_sent',null);
49
+ $this->save();
50
+ }
51
+
52
+ }
53
+ } catch (Exception $e) {
54
+ Mage::helper('campaigner/troubleshooting')->logException($e);
55
+ Mage::logException($e);
56
+ }
57
+ return $this;
58
+ }
59
+ }
app/code/community/Campaigner/Integration/Model/Mysql4/Abandoned.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_Mysql4_Abandoned extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+ protected $_read = null;
6
+ protected $_write = null;
7
+
8
+ protected function _construct()
9
+ {
10
+ $this->_init('campaigner/abandoned', 'id');
11
+ $this->_read = $this->_getReadAdapter();
12
+ $this->_write = $this->_getWriteAdapter();
13
+ }
14
+
15
+ public function loadByQuoteId($quote_id)
16
+ {
17
+ $select = $this->_read->select()
18
+ ->from($this->getTable('campaigner/abandoned'))
19
+ ->where('quote_id=?', $quote_id);
20
+
21
+ if ($result = $this->_read->fetchRow($select)) {
22
+ return $result;
23
+ }
24
+
25
+ return false;
26
+ }
27
+ }
app/code/community/Campaigner/Integration/Model/Mysql4/Abandoned/Collection.php ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_Mysql4_Abandoned_Collection extends Mage_Sales_Model_Mysql4_Quote_Collection
4
+ {
5
+ protected function _construct()
6
+ {
7
+ parent::_construct();
8
+ }
9
+
10
+ private function prepareCollection($store_ids)
11
+ {
12
+ $resource = Mage::getSingleton('core/resource');
13
+
14
+ $this->getSelect()->joinInner(array('camp_ac' => $resource->getTableName("campaigner/abandoned")),"camp_ac.quote_id=main_table.entity_id",array(
15
+ 'date_sent' => "date_sent",
16
+ 'status' => "status"
17
+ ));
18
+ $this->getSelect()->joinInner(array('camp_s' => $resource->getTableName("campaigner/session") ),"camp_s.id=camp_ac.session_id",array(
19
+ 'email' => "IF(main_table.customer_email IS NOT NULL, main_table.customer_email, email)"
20
+ ));
21
+
22
+ $this->addFieldToFilter('items_count', array('neq' => '0'))
23
+ ->addFieldToFilter('main_table.is_active', '1');
24
+
25
+ $this->getSelect()->where('(customer_email IS NOT NULL) OR (email IS NOT NULL)');
26
+
27
+ $this->setOrder('updated_at');
28
+
29
+ if (is_array($store_ids) && !empty($store_ids)) {
30
+ $this->addFieldToFilter('main_table.store_id', array('in' => $store_ids));
31
+ }
32
+ }
33
+
34
+ public function filterByQuoteId($quote_id)
35
+ {
36
+ $this->prepareCollection(array());
37
+ $this->getSelect()->where("quote_id = {$quote_id}");
38
+
39
+ return $this;
40
+ }
41
+
42
+ /**
43
+ * Prepare for abandoned report
44
+ *
45
+ * @param array $store_ids
46
+ * @param string $filter
47
+ * @return Mage_Reports_Model_Resource_Quote_Collection
48
+ */
49
+ public function prepareForAbandonedReport($store_ids, $filter = null)
50
+ {
51
+ $this->prepareCollection($store_ids);
52
+
53
+ $this->addSubtotal($store_ids, $filter);
54
+
55
+ return $this;
56
+ }
57
+
58
+ public function prepareForAbandonedProcess($check_date, $store_id = null)
59
+ {
60
+ $store_ids = array($store_id);
61
+
62
+ $this->prepareCollection($store_ids);
63
+
64
+ $this->addFieldToFilter('date_sent',array('null' => true));
65
+ $this->addFieldToFilter('main_table.updated_at', array('lt' => $check_date));
66
+
67
+ return $this;
68
+ }
69
+
70
+ public function prepareForManualAbandonedProcess($id_list, $store_id)
71
+ {
72
+ $store_ids = array($store_id);
73
+
74
+ $this->prepareCollection($store_ids);
75
+
76
+ $this->addFieldToFilter('entity_id', array('in' => $id_list))
77
+ ->setOrder('updated_at');
78
+
79
+ return $this;
80
+ }
81
+
82
+ /**
83
+ * Add subtotals
84
+ *
85
+ * @param array $store_ids
86
+ * @param array $filter
87
+ * @return Mage_Reports_Model_Resource_Quote_Collection
88
+ */
89
+ public function addSubtotal($store_ids = '', $filter = null)
90
+ {
91
+ if (is_array($store_ids)) {
92
+ $this->getSelect()->columns(array(
93
+ 'subtotal' => '(main_table.base_subtotal_with_discount*main_table.base_to_global_rate)'
94
+ ));
95
+ $this->_joinedFields['subtotal'] =
96
+ '(main_table.base_subtotal_with_discount*main_table.base_to_global_rate)';
97
+ } else {
98
+ $this->getSelect()->columns(array('subtotal' => 'main_table.base_subtotal_with_discount'));
99
+ $this->_joinedFields['subtotal'] = 'main_table.base_subtotal_with_discount';
100
+ }
101
+
102
+ if ($filter && is_array($filter) && isset($filter['subtotal'])) {
103
+ if (isset($filter['subtotal']['from'])) {
104
+ $this->getSelect()->where(
105
+ $this->_joinedFields['subtotal'] . ' >= ?',
106
+ $filter['subtotal']['from'], Zend_Db::FLOAT_TYPE
107
+ );
108
+ }
109
+ if (isset($filter['subtotal']['to'])) {
110
+ $this->getSelect()->where(
111
+ $this->_joinedFields['subtotal'] . ' <= ?',
112
+ $filter['subtotal']['to'], Zend_Db::FLOAT_TYPE
113
+ );
114
+ }
115
+ }
116
+
117
+ return $this;
118
+ }
119
+ }
app/code/community/Campaigner/Integration/Model/Mysql4/Action/List.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_Mysql4_Action_List extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+ protected $_read = null;
6
+ protected $_write = null;
7
+
8
+ protected function _construct()
9
+ {
10
+ $this->_init('campaigner/action_list', 'id');
11
+ $this->_read = $this->_getReadAdapter();
12
+ $this->_write = $this->_getWriteAdapter();
13
+ }
14
+
15
+ public function loadByEmailAndAction($email, $action)
16
+ {
17
+ $select = $this->_read->select()
18
+ ->from($this->getTable('campaigner/action_list'))
19
+ ->where('email=?', $email)
20
+ ->where('action=?', $action)
21
+ ->where('date_sent IS NULL')
22
+ ->where('status IS NULL');
23
+
24
+ if ($result = $this->_read->fetchRow($select)) {
25
+ return $result;
26
+ }
27
+
28
+ return false;
29
+ }
30
+ }
app/code/community/Campaigner/Integration/Model/Mysql4/Action/List/Collection.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_Mysql4_Action_List_Collection extends Mage_Sales_Model_Mysql4_Quote_Collection
4
+ {
5
+ protected function _construct()
6
+ {
7
+ parent::_construct();
8
+ }
9
+
10
+ public function filterByQuoteId($quote_id)
11
+ {
12
+ $this->prepareCollection(array());
13
+ $this->getSelect()->where("quote_id = {$quote_id}");
14
+
15
+ return $this;
16
+ }
17
+ }
app/code/community/Campaigner/Integration/Model/Mysql4/Latest/Order.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_Mysql4_Latest_Order extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+ protected $_read = null;
6
+ protected $_write = null;
7
+
8
+ protected function _construct()
9
+ {
10
+ $this->_init('campaigner/latest_order', 'id');
11
+ $this->_read = $this->_getReadAdapter();
12
+ $this->_write = $this->_getWriteAdapter();
13
+ }
14
+
15
+ public function loadByEmailAndStore($email, $store_id)
16
+ {
17
+ $select = $this->_read->select()
18
+ ->from($this->getTable('campaigner/latest_order'))
19
+ ->where('email=?', $email)
20
+ ->where('store_id=?', $store_id);
21
+
22
+ if ($result = $this->_read->fetchRow($select)) {
23
+ return $result;
24
+ }
25
+
26
+ return false;
27
+ }
28
+ }
app/code/community/Campaigner/Integration/Model/Mysql4/Latest/Order/Collection.php ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_Mysql4_Latest_Order_Collection extends Mage_Sales_Model_Mysql4_Order_Collection
4
+ {
5
+ protected function _construct()
6
+ {
7
+ parent::_construct();
8
+ }
9
+
10
+ private function prepareCollection($store_ids)
11
+ {
12
+ $resource = Mage::getSingleton('core/resource');
13
+
14
+ $this->getSelect()->joinInner(array('camp_lo' => $resource->getTableName("campaigner/latest_order")),"camp_lo.order_id=main_table.entity_id",array(
15
+ 'date_sent' => "date_sent",
16
+ 'status' => "status",
17
+ 'email' => 'email'
18
+ ));
19
+
20
+ $this->setOrder('updated_at');
21
+
22
+ if (is_array($store_ids) && !empty($store_ids)) {
23
+ $this->addFieldToFilter('main_table.store_id', array('in' => $store_ids));
24
+ }
25
+ }
26
+
27
+ public function filterByOrderId($order_id)
28
+ {
29
+ $this->prepareCollection(array());
30
+ $this->getSelect()->where("order_id = {$order_id}");
31
+
32
+ return $this;
33
+ }
34
+
35
+ /**
36
+ * Prepare for latest report
37
+ *
38
+ * @param array $store_ids
39
+ * @param string $filter
40
+ * @return Mage_Reports_Model_Resource_Quote_Collection
41
+ */
42
+ public function prepareForLatestReport($store_ids, $filter = null)
43
+ {
44
+ $this->prepareCollection($store_ids);
45
+
46
+ $this->addSubtotal($store_ids, $filter);
47
+
48
+ return $this;
49
+ }
50
+
51
+ public function prepareForLatestProcess($store_id = null)
52
+ {
53
+ $store_ids = array($store_id);
54
+
55
+ $this->prepareCollection($store_ids);
56
+
57
+ $this->addFieldToFilter('date_sent',array('null' => true));
58
+
59
+ return $this;
60
+ }
61
+
62
+ public function prepareForManualLatestProcess($id_list, $store_id)
63
+ {
64
+ $store_ids = array($store_id);
65
+
66
+ $this->prepareCollection($store_ids);
67
+
68
+ $this->addFieldToFilter('entity_id', array('in' => $id_list))
69
+ ->setOrder('updated_at');
70
+
71
+ return $this;
72
+ }
73
+
74
+ /**
75
+ * Add subtotals
76
+ *
77
+ * @param array $store_ids
78
+ * @param array $filter
79
+ * @return Mage_Reports_Model_Resource_Quote_Collection
80
+ */
81
+ public function addSubtotal($store_ids = '', $filter = null)
82
+ {
83
+ if (is_array($store_ids)) {
84
+ $this->getSelect()->columns(array(
85
+ 'subtotal' => '(main_table.base_subtotal*main_table.base_to_global_rate)'
86
+ ));
87
+ $this->_joinedFields['subtotal'] =
88
+ '(main_table.base_subtotal*main_table.base_to_global_rate)';
89
+ } else {
90
+ $this->getSelect()->columns(array('subtotal' => 'main_table.base_subtotal'));
91
+ $this->_joinedFields['subtotal'] = 'main_table.base_subtotal';
92
+ }
93
+
94
+ if ($filter && is_array($filter) && isset($filter['subtotal'])) {
95
+ if (isset($filter['subtotal']['from'])) {
96
+ $this->getSelect()->where(
97
+ $this->_joinedFields['subtotal'] . ' >= ?',
98
+ $filter['subtotal']['from'], Zend_Db::FLOAT_TYPE
99
+ );
100
+ }
101
+ if (isset($filter['subtotal']['to'])) {
102
+ $this->getSelect()->where(
103
+ $this->_joinedFields['subtotal'] . ' <= ?',
104
+ $filter['subtotal']['to'], Zend_Db::FLOAT_TYPE
105
+ );
106
+ }
107
+ }
108
+
109
+ return $this;
110
+ }
111
+ }
app/code/community/Campaigner/Integration/Model/Mysql4/Order.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_Mysql4_Order extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+ protected $_read = null;
6
+ protected $_write = null;
7
+
8
+ protected function _construct()
9
+ {
10
+ $this->_init('campaigner/order', 'id');
11
+ $this->_read = $this->_getReadAdapter();
12
+ $this->_write = $this->_getWriteAdapter();
13
+ }
14
+
15
+ public function loadByOrderId($order_id)
16
+ {
17
+ $select = $this->_read->select()
18
+ ->from($this->getTable('campaigner/order'))
19
+ ->where('order_id=?', $order_id);
20
+
21
+ if ($result = $this->_read->fetchRow($select)) {
22
+ return $result;
23
+ }
24
+
25
+ return false;
26
+ }
27
+ }
app/code/community/Campaigner/Integration/Model/Mysql4/Order/Collection.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_Mysql4_Order_Collection extends Mage_Sales_Model_Mysql4_Order_Collection
4
+ {
5
+ protected $_helper = null;
6
+
7
+ protected function _construct()
8
+ {
9
+ $this->_helper = Mage::helper('campaigner');
10
+ parent::_construct();
11
+ }
12
+
13
+ public function prepareCollection($store_ids = '')
14
+ {
15
+ $resource = Mage::getSingleton('core/resource');
16
+
17
+ $this->getSelect()->joinLeft(array('ed_or' => $resource->getTableName("campaigner/order")),"ed_or.order_id=main_table.entity_id",array(
18
+ 'date_sent' => "date_sent"
19
+ ));
20
+
21
+ if (is_array($store_ids) && !empty($store_ids)) {
22
+ $this->addFieldToFilter('main_table.store_id', array('in' => $store_ids));
23
+ }
24
+
25
+ $this->getSelect()->order('created_at ASC');
26
+
27
+ return $this;
28
+ }
29
+
30
+ private function stateStatusFilter()
31
+ {
32
+ $mode = $this->_helper->config('send_field');
33
+
34
+ if ($mode == "state") {
35
+ $options = $this->_helper->config('send_states');
36
+ } else {
37
+ $options = $this->_helper->config('send_statuses');
38
+ }
39
+
40
+ $option_list = explode(",",$options);
41
+
42
+ $this->addFieldToFilter($mode, array('in' => $option_list));
43
+ }
44
+
45
+ private function limitByDate()
46
+ {
47
+ $this->_helper = Mage::helper('campaigner');
48
+
49
+ $date_adj = $this->_helper->config('batch_date_adjust');
50
+
51
+ if ($date_adj == null || $date_adj == "") {
52
+ $date_adj = "-1 week";
53
+ }
54
+
55
+ $time = date("Y-m-d",strtotime($date_adj, Mage::getModel('core/date')->timestamp(time())));
56
+
57
+ $limit_date = Mage::getModel('core/date')->gmtDate(null,strtotime($time));
58
+
59
+ $this->addAttributeToFilter('created_at', array('from' => $limit_date));
60
+ }
61
+
62
+ public function getUnsentOrders($store_id = null, $limit = 100)
63
+ {
64
+ $store_ids = null;
65
+ if ($store_id != null) {
66
+ $store_ids = array($store_id);
67
+ }
68
+
69
+ $this->prepareCollection($store_ids);
70
+
71
+ $this->addFieldToFilter('date_sent', array('null' => true));
72
+
73
+ $this->limitByDate();
74
+
75
+ $this->stateStatusFilter();
76
+
77
+ if ($limit != null && $limit != "") {
78
+ $this->getSelect()->limit($limit);
79
+ }
80
+
81
+ return $this;
82
+ }
83
+ }
app/code/community/Campaigner/Integration/Model/Mysql4/Session.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_Mysql4_Session extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+ protected $_read = null;
6
+ protected $_write = null;
7
+
8
+ protected function _construct()
9
+ {
10
+ $this->_init('campaigner/session', 'id');
11
+ $this->_read = $this->_getReadAdapter();
12
+ $this->_write = $this->_getWriteAdapter();
13
+ }
14
+
15
+ public function loadByMagentoSessionId($magento_session_id)
16
+ {
17
+ $select = $this->_read->select()
18
+ ->from($this->getTable('campaigner/session'))
19
+ ->where('magento_session_id=?', $magento_session_id);
20
+
21
+ if ($result = $this->_read->fetchRow($select)) {
22
+ return $result;
23
+ }
24
+
25
+ return false;
26
+ }
27
+ }
app/code/community/Campaigner/Integration/Model/Mysql4/Session/Collection.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_Mysql4_Session_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
4
+ {
5
+ protected function _construct()
6
+ {
7
+ $this->_init('campaigner/session');
8
+ }
9
+
10
+ public function addStoreFilter($store_ids)
11
+ {
12
+ $this->getSelect()->where('main_table.store_id IN (?)', $store_ids);
13
+ return $this;
14
+ }
15
+ }
app/code/community/Campaigner/Integration/Model/Newsletter/Observer.php ADDED
@@ -0,0 +1,224 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_Newsletter_Observer extends Campaigner_Integration_Model_Observer_Abstract
4
+ {
5
+ /**
6
+ * Handle Subscriber object saving process
7
+ */
8
+ public function handleSubscriber(Varien_Event_Observer $observer)
9
+ {
10
+ try
11
+ {
12
+ $this->_setLogArea(Campaigner_Integration_Helper_Troubleshooting::NEWSLETTER);
13
+ $this->_log('handleSubscriber Start');
14
+
15
+ if (!$this->_helper->campaignerEnabled()) {
16
+ $this->_logReason($this->_helper->getDisabledReason());
17
+ return;
18
+ }
19
+
20
+ $subscriber = $observer->getEvent()->getSubscriber();
21
+ $subscriber->setImportMode(false);
22
+
23
+ $customer = Mage::getModel('customer/customer');
24
+
25
+ if ($subscriber->getCustomerId() != 0) {
26
+ $customer->load($subscriber->getCustomerId());
27
+ }
28
+
29
+ $email = $subscriber->getSubscriberEmail();
30
+ $listId = $this->_helper->getDefaultPublication($subscriber->getStoreId());
31
+ $isConfirmNeed = (Mage::getStoreConfig(Mage_Newsletter_Model_Subscriber::XML_PATH_CONFIRMATION_FLAG, $subscriber->getStoreId()) == 1) ? TRUE : FALSE;
32
+
33
+ //New subscriber, just add
34
+ if ($subscriber->isObjectNew()) {
35
+ $this->_log("New Subscriber");
36
+ if (TRUE === $isConfirmNeed) {
37
+ $this->_log("Confirmation Needed");
38
+ $subscriber->setSubscriberStatus(Mage_Newsletter_Model_Subscriber::STATUS_UNCONFIRMED);
39
+ if (!Mage::helper('customer')->isLoggedIn() && Mage::registry('campaigner_guest_customer')) {
40
+ $this->_log("Guest Customer");
41
+ $guestCustomer = Mage::registry('campaigner_guest_customer');
42
+ $subscriber->setFirstname($guestCustomer->getFirstname());
43
+ $subscriber->setLastname($guestCustomer->getLastname());
44
+ Mage::unregister('campaigner_guest_customer');
45
+ $subscriber->save();
46
+ } else {
47
+ $this->_log("Not a Guest Customer (Doing Nothing?)");
48
+ }
49
+ } else {
50
+ $this->_log("Confirmation Not Required");
51
+ $subscriber->setSubscriberStatus(Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED);
52
+ $merge_vars = $this->_helper->getMergeVars($customer);
53
+
54
+ $this->_log($merge_vars,"Merge Vars");
55
+
56
+ $rc = Mage::getSingleton('campaigner/wrapper_subscribers')
57
+ ->addByEmail($email,$merge_vars, true);
58
+ }
59
+ } else {
60
+ $this->_log("Existing Subscriber");
61
+ $status = (int)$subscriber->getData('subscriber_status');
62
+
63
+ $oldSubscriber = Mage::getModel('newsletter/subscriber')
64
+ ->load($subscriber->getId());
65
+ $oldstatus = (int)$oldSubscriber->getOrigData('subscriber_status');
66
+
67
+ if ($oldstatus == Mage_Newsletter_Model_Subscriber::STATUS_UNCONFIRMED && $status == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED) {
68
+ $this->_log("Unconfirmed to Subscribed");
69
+ $subscriber->setSubscriberStatus(Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED);
70
+ $merge_vars = $this->_helper->getMergeVars($customer);
71
+
72
+ $this->_log($merge_vars,"Merge Vars");
73
+ $rc = Mage::getSingleton('campaigner/wrapper_subscribers')
74
+ ->addByEmail($email,$merge_vars, true);
75
+ } elseif( $status !== $oldstatus ) {
76
+ //Status change
77
+ $this->_log("Status Change");
78
+
79
+ //Unsubscribe customer
80
+ if($status == Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED) {
81
+ $this->_log("Unsubscribed");
82
+ $rc = Mage::getSingleton('campaigner/wrapper_publications')
83
+ ->unsubscribe($listId, $email);
84
+ } else if($status == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED) {
85
+ $this->_log("Subscribed");
86
+ if( $oldstatus == Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE || $oldstatus == Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED ) {
87
+ $this->_log("Changing Status");
88
+ $rc = Mage::getSingleton('campaigner/wrapper_publications')
89
+ ->subscribe($listId, $email);
90
+ } else {
91
+ $this->_log("Status Not Changed");
92
+ }
93
+ }
94
+ }
95
+ }
96
+ $this->_log('handleSubscriber End');
97
+ } catch (Exception $e) {
98
+ Mage::logException($e);
99
+ $this->_logException($e);
100
+ }
101
+ }
102
+
103
+ // Remove Unsubscribe option from Newsletter grid
104
+ public function updateNewsletterMassAction($observer)
105
+ {
106
+ try {
107
+ if (!$this->_helper->campaignerEnabled()) {
108
+ return;
109
+ }
110
+
111
+ $block = $observer->getEvent()->getBlock();
112
+
113
+ if (get_class($block) =='Mage_Adminhtml_Block_Widget_Grid_Massaction'
114
+ && $block->getRequest()->getControllerName() == 'newsletter_subscriber') {
115
+ $block->removeItem('unsubscribe');
116
+ }
117
+ } catch (Exception $e) {
118
+ Mage::logException($e);
119
+ $this->_logException($e);
120
+ }
121
+ }
122
+
123
+ /**
124
+ * Handle Subscriber deletion from Magento, unsubcribes email
125
+ * and sends the delete_member flag so the subscriber gets deleted.
126
+ */
127
+ public function handleSubscriberDeletion(Varien_Event_Observer $observer)
128
+ {
129
+ try {
130
+ $this->_setLogArea(Campaigner_Integration_Helper_Troubleshooting::NEWSLETTER);
131
+ $this->_log("Handle Subscriber Deletion Start");
132
+
133
+ if (!$this->_helper->campaignerEnabled()) {
134
+ $this->_logReason($this->_helper->getDisabledReason());
135
+ return;
136
+ }
137
+
138
+ $subscriber = $observer->getEvent()->getSubscriber();
139
+
140
+ $email = $subscriber->getSubscriberEmail();
141
+
142
+ Mage::getSingleton('campaigner/wrapper_subscribers')
143
+ ->delete($email);
144
+
145
+ $this->_log("Handle Subscriber Deletion End");
146
+ } catch (Exception $e) {
147
+ Mage::logException($e);
148
+ $this->_logException($e);
149
+ }
150
+ }
151
+
152
+ public function registerCheckoutSubscribe(Varien_Event_Observer $observer)
153
+ {
154
+ try {
155
+ $this->_setLogArea(Campaigner_Integration_Helper_Troubleshooting::NEWSLETTER);
156
+ $this->_log("Register Checkout Subscribe Start");
157
+ if (!$this->_helper->campaignerEnabled()) {
158
+ $this->_logReason($this->_helper->getDisabledReason());
159
+ return;
160
+ }
161
+ $subscribe = Mage::app()->getRequest()->getPost('campaigner_subscribe');
162
+
163
+ if (!is_null($subscribe) || $this->_helper->forceSubscribe()) {
164
+ Mage::getSingleton('core/session')->setCampaignerCheckout($subscribe);
165
+ }
166
+
167
+ $this->_log("Register Checkout Subscribe End");
168
+ } catch (Exception $e) {
169
+ Mage::logException($e);
170
+ $this->_logException($e);
171
+ }
172
+ }
173
+
174
+ /**
175
+ * Subscribe customer to Newsletter if flag on session is present
176
+ */
177
+ public function registerCheckoutSuccess(Varien_Event_Observer $observer)
178
+ {
179
+ try {
180
+ $this->_setLogArea(Campaigner_Integration_Helper_Troubleshooting::NEWSLETTER);
181
+ $this->_log("Register Checkout Success Start");
182
+
183
+ if (!$this->_helper->campaignerEnabled()) {
184
+ $this->_logReason($this->_helper->getDisabledReason());
185
+ return;
186
+ }
187
+
188
+ $sessionFlag = Mage::getSingleton('core/session')->getCampaignerCheckout(TRUE);
189
+ if (!$sessionFlag && !$this->_helper->forceSubscribe()) {
190
+ $this->_logReason("Session flag not found.");
191
+ return;
192
+ }
193
+
194
+ $order_id = (int)current($observer->getEvent()->getOrderIds());
195
+
196
+ if (!$order_id) {
197
+ $this->_logReason("Order ID not found.");
198
+ return;
199
+ }
200
+
201
+ $order = Mage::getModel('sales/order')->load($order_id);
202
+ if (!$order->getId()) {
203
+ $this->_logReason("Failed to Load Order ({$order_id}).");
204
+ return;
205
+ }
206
+
207
+ $this->_log("Processing Order # " . $order->getIncrementId());
208
+
209
+ //Guest Checkout
210
+ if ((int)$order->getCustomerGroupId() === Mage_Customer_Model_Group::NOT_LOGGED_IN_ID ) {
211
+ $this->_log("Guest Checkout");
212
+ $this->_helper->registerGuestCustomer($order);
213
+ }
214
+
215
+ $subscriber = Mage::getModel('newsletter/subscriber')
216
+ ->subscribe($order->getCustomerEmail());
217
+
218
+ $this->_log("Register Checkout Success End");
219
+ } catch (Exception $e) {
220
+ Mage::logException($e);
221
+ $this->_logException($e);
222
+ }
223
+ }
224
+ }
app/code/community/Campaigner/Integration/Model/Observer.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_Observer extends Campaigner_Integration_Model_Observer_Abstract
4
+ {
5
+ //--------------------------------------------------------------------------------------------------
6
+ // WISHLIST
7
+
8
+ public function onWishlistProductAddAfter(Varien_Event_Observer $observer)
9
+ {
10
+ try
11
+ {
12
+ $this->_setLogArea(Campaigner_Integration_Helper_Troubleshooting::WISHLIST);
13
+ $this->_logger->setLogLevel(Campaigner_Integration_Helper_Troubleshooting::LOG_LEVEL_LOW);
14
+ $this->_log('onWishlistProductAddAfter Start');
15
+
16
+ if (!$this->_helper->canSendWishlist()) {
17
+ $this->_logReason($this->_helper->getWishlistDisabledReason());
18
+ return;
19
+ }
20
+
21
+ $customer = Mage::getSingleton('customer/session')->getCustomer();
22
+
23
+ $merge_vars = array(
24
+ 'WishListUrl' => Mage::getUrl('wishlist'),
25
+ 'WishListDate' => Mage::getModel('core/date')->date($this->_date_format)
26
+ );
27
+
28
+ Mage::getSingleton('campaigner/wrapper_wishlist')->send($customer->getEmail(), $merge_vars);
29
+
30
+ $this->_log('onWishlistProductAddAfter End');
31
+ } catch (Exception $e) {
32
+ Mage::logException($e);
33
+ $this->_logException($e);
34
+ }
35
+ }
36
+
37
+ // WISHLIST END
38
+ //--------------------------------------------------------------------------------------------------
39
+ }
app/code/community/Campaigner/Integration/Model/Observer/Abstract.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_Observer_Abstract
4
+ {
5
+ protected $_helper = null;
6
+ protected $_logger = null;
7
+ protected $_date_format = Campaigner_Integration_Helper_Data::DATE_FORMAT;
8
+
9
+ public function __construct()
10
+ {
11
+ $this->_helper = Mage::helper('campaigner');
12
+ $this->_logger = Mage::helper('campaigner/troubleshooting');
13
+ }
14
+
15
+ protected function _log($data, $prefix = "")
16
+ {
17
+ $this->_logger->log($data, $prefix);
18
+ }
19
+
20
+ protected function _logException($e)
21
+ {
22
+ $this->_logger->logException($e);
23
+ }
24
+
25
+ protected function _logReason($data)
26
+ {
27
+ $this->_logger->logReason($data);
28
+ }
29
+
30
+ protected function _setLogArea($area)
31
+ {
32
+ $this->_logger->setLogArea($area);
33
+ }
34
+ }
app/code/community/Campaigner/Integration/Model/Order.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_Order extends Mage_Core_Model_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('campaigner/order');
9
+ }
10
+
11
+ public function loadByOrderId($order_id)
12
+ {
13
+ try {
14
+ if ($data = $this->getResource()->loadByOrderId($order_id)) {
15
+ $this->addData($data);
16
+ } else {
17
+ return false;
18
+ }
19
+ } catch (Exception $e) {
20
+ Mage::logException($e);
21
+ Mage::helper('campaigner')->logException($e);
22
+ return false;
23
+ }
24
+ return $this;
25
+ }
26
+
27
+ public function saveSent($order, $date)
28
+ {
29
+ try {
30
+ if (!$this->loadByOrderId($order->getId())) {
31
+ $this->setOrderId($order->getId());
32
+ }
33
+
34
+ $this->setDateSent($date);
35
+
36
+ $this->save();
37
+ } catch (Exception $e) {
38
+ Mage::logException($e);
39
+ Mage::helper('campaigner')->logException($e);
40
+ return false;
41
+ }
42
+
43
+ return $this;
44
+ }
45
+ }
app/code/community/Campaigner/Integration/Model/Order/Observer.php ADDED
@@ -0,0 +1,328 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_Order_Observer extends Campaigner_Integration_Model_Observer_Abstract
4
+ {
5
+ private $_order_status = array();
6
+
7
+ private function processLatest($order)
8
+ {
9
+ $this->_log("ProcessLatest Start");
10
+ $email = $order->getCustomerEmail();
11
+
12
+ $merge_vars = Mage::helper('campaigner')->getQuoteMergeVars($order);
13
+
14
+ $merge_vars = Mage::helper('campaigner/order')->processOrderItems($order, $merge_vars);
15
+
16
+ $contactData = Mage::getSingleton('campaigner/wrapper_orders')->getEmailContactData($email, $merge_vars);
17
+
18
+ $this->_log("ProcessLatest End");
19
+
20
+ return $contactData;
21
+ }
22
+
23
+ private function updateOrderList($order_list, $details)
24
+ {
25
+ if (!isset($details->UploadResultData) || !is_array($details->UploadResultData)) {
26
+
27
+ $status = "Unknown Error";
28
+ if (isset($details->UploadResultData)) {
29
+ $status = $details->UploadResultData->ResultCode;
30
+ }
31
+
32
+ foreach (array_keys($order_list) as $key) {
33
+ $order_list[$key]['status'] = $status;
34
+ }
35
+ return $order_list;
36
+ }
37
+
38
+ foreach ($details->UploadResultData as $result) {
39
+ if ($result->ResultCode != 'Success') {
40
+ $email = $result->ContactKey->ContactUniqueIdentifier;
41
+
42
+ $order_list[$email]['status'] = $result->ResultCode;
43
+ }
44
+ }
45
+
46
+ return $order_list;
47
+ }
48
+
49
+ private function setSentToCampaignerDate($email, $order_id, $date, $status = null)
50
+ {
51
+ try {
52
+ $store_id = Mage::app()->getStore()->getId();
53
+ $latest = Mage::getModel('campaigner/latest_order')->loadByEmailAndStore($email, $store_id);
54
+
55
+ if (!$latest) {
56
+ throw new Exception("Failed to load latest order row to update date sent.", 1);
57
+ }
58
+
59
+ if ($status != null) {
60
+ $this->_order_status[$order_id] = array('success' => false, 'status' => $status);
61
+ $latest->setStatus($status);
62
+ } else {
63
+ $this->_order_status[$order_id] = array('success' => true);
64
+ $latest->setDateSent($date);
65
+ $latest->setStatus("");
66
+ }
67
+ $latest->save();
68
+ } catch (Exception $e) {
69
+ Mage::logException($e);
70
+ $this->_logException($e);
71
+ }
72
+ }
73
+
74
+ private function setDateSent($order_list, $date)
75
+ {
76
+ foreach ($order_list as $email => $data) {
77
+ $order_id = $data['order_id'];
78
+ $status = $data['status'];
79
+
80
+ $this->setSentToCampaignerDate($email, $order_id, $date, $status);
81
+ }
82
+ }
83
+
84
+ private function _latestProcessor($collection, $store = null, $mark_time = true)
85
+ {
86
+ // Store the time we last run
87
+ $date = date(Mage::getModel('core/date')->gmtTimestamp());
88
+ $date = date($this->_date_format, $date);
89
+
90
+ if ($mark_time) {
91
+ $this->_log("Saving Last Run Date: {$date}");
92
+ $this->_helper->updateConfig("latest_last_run", $date, $store);
93
+ }
94
+
95
+ $subscribers = false;
96
+
97
+ $contactList = array();
98
+
99
+ $order_list = array();
100
+
101
+ // Get the data for each order
102
+ foreach ($collection as $order) {
103
+ $contactData = $this->processLatest($order);
104
+
105
+ $contactList[] = $contactData;
106
+
107
+ $email = $contactData['EmailAddress'];
108
+ $order_list[$email] = array('order_id' => $order->getId(), 'status' => null);
109
+
110
+ $subscribers = true;
111
+ }
112
+
113
+ if (!$subscribers) {
114
+ $this->_logReason("No Orders Found");
115
+ return; // No abandoned carts found
116
+ }
117
+
118
+ $this->_log("Sending Latest Orders");
119
+ // Send them all at once
120
+
121
+ try {
122
+ Mage::getSingleton('campaigner/wrapper_orders')->send($contactList);
123
+ } catch (Campaigner_Integration_Model_Wrapper_Exception $e) {
124
+ $this->_logException($e);
125
+ $details = $e->getDetails();
126
+
127
+ $this->_log($details);
128
+ $order_list = $this->updateOrderList($order_list, $details);
129
+ }
130
+
131
+ $this->_log("Setting date sent for all orders Start");
132
+
133
+ $this->setDateSent($order_list,$date);
134
+
135
+ $this->_log("Setting date sent for all orders End");
136
+ }
137
+
138
+ public function latestStoreProcessor($store)
139
+ {
140
+ $store_code = $store->getCode();
141
+
142
+ $this->_log("Processing Store: {$store_code}");
143
+
144
+ if (!$this->_helper->config('save_latest_order')) {
145
+ $this->_logReason("Sending latest orders is disabled");
146
+ return;
147
+ }
148
+
149
+ Mage::helper('campaigner/fields')->verifyFields();
150
+
151
+ // Get latest order collection
152
+ $collection = Mage::getResourceModel('campaigner/latest_order_collection');
153
+
154
+ $collection->prepareForLatestProcess($store->getId());
155
+
156
+ $this->_log("SQL: " . $collection->getSelect()->__toString());
157
+
158
+ $this->_latestProcessor($collection, $store->getId());
159
+
160
+ $this->_log("Finished Processing Store: {$store_code}");
161
+ }
162
+
163
+ public function processLatestOrders()
164
+ {
165
+ try {
166
+ Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
167
+ $this->_setLogArea(Campaigner_Integration_Helper_Troubleshooting::ORDERS);
168
+ $this->_log("Latest Orders Processor Start");
169
+
170
+ $stores = Mage::app()->getStores();
171
+
172
+ foreach ($stores as $store) {
173
+ Mage::app()->setCurrentStore($store->getCode());
174
+
175
+ $this->LatestStoreProcessor($store);
176
+ }
177
+
178
+ Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
179
+
180
+ $date = date(Mage::getModel('core/date')->gmtTimestamp());
181
+ $date = date($this->_date_format, $date);
182
+
183
+ $this->_log("Saving Last Cron Run Date: {$date}");
184
+ $this->_helper->updateConfig("latest_cron_last_run", $date);
185
+
186
+ $this->_log("Latest Orders Processor End");
187
+ } catch (Exception $e) {
188
+ Mage::logException($e);
189
+ $this->_logException($e);
190
+ }
191
+ }
192
+
193
+ public function manualLatestProcessor($store_id = null)
194
+ {
195
+ try {
196
+ Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
197
+ $this->_setLogArea(Campaigner_Integration_Helper_Troubleshooting::ORDERS);
198
+ $this->_log("Manual Latest Order Processor Start");
199
+
200
+ $stores = Mage::app()->getStores();
201
+
202
+ foreach ($stores as $store) {
203
+ if ($store_id == null || $store_id == $store->getId()) {
204
+ Mage::app()->setCurrentStore($store->getCode());
205
+
206
+ $this->latestStoreProcessor($store);
207
+ }
208
+ }
209
+
210
+ Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
211
+
212
+ $this->_log("Manual Latest Order Processor End");
213
+ } catch (Exception $e) {
214
+ Mage::logException($e);
215
+ $this->_logException($e);
216
+ }
217
+ }
218
+
219
+ public function SendLatestOrders($id_list)
220
+ {
221
+ $count = 0;
222
+ $this->_order_status = array();
223
+
224
+ Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
225
+
226
+ $this->_setLogArea(Campaigner_Integration_Helper_Troubleshooting::ORDERS);
227
+ $this->_log("Sending Specific Latest Orders Start");
228
+
229
+ Mage::helper('campaigner/fields')->verifyFields();
230
+
231
+ $this->_log($id_list, "ID LIST");
232
+
233
+ $stores = Mage::app()->getStores();
234
+
235
+ foreach ($stores as $store) {
236
+ $this->_log("Checking for valid orders in store: {$store->getName()} ({$store->getId()})");
237
+ if (!$this->_helper->config('save_latest_order',$store->getId())) {
238
+ $this->_log('Latest Orders not enabled...');
239
+ continue;
240
+ }
241
+
242
+ Mage::app()->setCurrentStore($store->getCode());
243
+
244
+ // Get abandoned collection
245
+ $collection = Mage::getResourceModel('campaigner/latest_order_collection');
246
+
247
+ $collection->prepareForManualLatestProcess($id_list, $store->getId());
248
+
249
+ $count += count($collection);
250
+
251
+ $this->_log("SQL: " . $collection->getSelect()->__toString());
252
+
253
+ $this->_latestProcessor($collection, $store, false);
254
+ }
255
+
256
+ Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
257
+
258
+ $this->_log("Sending Specific Latest Orders End");
259
+
260
+ return $this->_order_status;
261
+
262
+ }
263
+
264
+ public function salesOrderSaveAfter(Varien_Event_Observer $observer)
265
+ {
266
+ try {
267
+ $this->_setLogArea(Campaigner_Integration_Helper_Troubleshooting::ORDERS);
268
+ $this->_log("Sales Order Save After Start");
269
+
270
+ if (!$this->_helper->campaignerEnabled()) {
271
+ $this->_logReason($this->_helper->getDisabledReason());
272
+ return;
273
+ }
274
+
275
+ $order = $observer->getEvent()->getOrder();
276
+
277
+ $latest = Mage::getModel('campaigner/latest_order')->init($order);
278
+
279
+ $this->_log("Sales Order Save After End");
280
+ } catch (Exception $e) {
281
+ Mage::logException($e);
282
+ $this->_logException($e);
283
+ }
284
+ }
285
+
286
+ public function salesOrderShipmentTrackSaveAfter(Varien_Event_Observer $observer)
287
+ {
288
+ try {
289
+ $order_helper = Mage::helper('campaigner/order');
290
+ $this->_setLogArea(Campaigner_Integration_Helper_Troubleshooting::ORDERS);
291
+ $this->_log("Sales Order Shipment Track Save After Start");
292
+
293
+ if (!$this->_helper->campaignerEnabled()) {
294
+ $this->_logReason($this->_helper->getDisabledReason());
295
+ return;
296
+ }
297
+ $track = $observer->getEvent()->getTrack();
298
+
299
+ $order = $track->getShipment()->getOrder();
300
+ $shippingMethod = $order->getShippingMethod(); // String in format of 'carrier_method'
301
+
302
+ if (!$shippingMethod) {
303
+ $this->_logReason("Shipping Method not found");
304
+ return;
305
+ }
306
+
307
+ $email = $order->getCustomerEmail();
308
+
309
+ $merge_vars = array();
310
+
311
+ $merge_vars = $order_helper->getTrackingMergeVars($track, $order);
312
+
313
+ if ($merge_vars == null) {
314
+ $this->_logReason("No shipping fields setup");
315
+ return;
316
+ }
317
+
318
+ $this->_log($merge_vars,"Merge Vars");
319
+
320
+ $rc = Mage::getSingleton('campaigner/wrapper_orders')->addSubscriberTracking($email, $merge_vars);
321
+
322
+ $this->_log("Sales Order Shipment Track Save After End");
323
+ } catch (Exception $e) {
324
+ Mage::logException($e);
325
+ $this->_logException($e);
326
+ }
327
+ }
328
+ }
app/code/community/Campaigner/Integration/Model/Resource/Setup.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_Resource_Setup extends Mage_Core_Model_Resource_Setup
4
+ {
5
+ const INSTALL_LOG_FILE_NAME = 'campaigner_install';
6
+
7
+ public function addNotification($title, $description, $url = "", $severity = Mage_AdminNotification_Model_Inbox::SEVERITY_NOTICE)
8
+ {
9
+ $admin_notification = Mage::getSingleton('adminnotification/inbox');
10
+
11
+ // Older versions of Magento don't have this method
12
+ if (method_exists($admin_notification,"add")) {
13
+ $admin_notification->add(
14
+ $severity,
15
+ $title,
16
+ $description,
17
+ $url
18
+ );
19
+ } else {
20
+ $this->addLegacyNotification($title, $description, $url, $severity);
21
+ }
22
+ }
23
+
24
+ private function addLegacyNotification($title, $description, $url = "", $severity = Mage_AdminNotification_Model_Inbox::SEVERITY_NOTICE)
25
+ {
26
+ if (is_array($description)) {
27
+ $description = '<ul><li>' . implode('</li><li>', $description) . '</li></ul>';
28
+ }
29
+
30
+ $date = date(Campaigner_Integration_Helper_Data::DATE_FORMAT);
31
+ Mage::getSingleton('adminnotification/inbox')->parse(array(array(
32
+ 'severity' => $severity,
33
+ 'date_added' => $date,
34
+ 'title' => $title,
35
+ 'description' => $description,
36
+ 'url' => $url,
37
+ 'internal' => $isInternal
38
+ )));
39
+ }
40
+
41
+ public function install_log($data)
42
+ {
43
+ Mage::log($data,null,self::INSTALL_LOG_FILE_NAME . Campaigner_Integration_Helper_Troubleshooting::LOG_FILE_EXT, true);
44
+ }
45
+ }
app/code/community/Campaigner/Integration/Model/Session.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_Session extends Mage_Core_Model_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('campaigner/session');
9
+ }
10
+
11
+ public function loadByMagentoSessionId($magento_session_id)
12
+ {
13
+ if ($data = $this->getResource()->loadByMagentoSessionId($magento_session_id)) {
14
+ $this->addData($data);
15
+ } else {
16
+ return false;
17
+ }
18
+
19
+ return $this;
20
+ }
21
+
22
+ public function init($email = null)
23
+ {
24
+ try {
25
+ $customer_session = Mage::getSingleton("customer/session");
26
+
27
+ $magento_session_id = $customer_session->getEncryptedSessionId();
28
+
29
+ $campaigner_id = Mage::getModel('core/cookie')->get('camp_id');
30
+
31
+ $new = false;
32
+
33
+ if (!empty($campaigner_id)) {
34
+ $this->load($campaigner_id);
35
+ } else {
36
+ $new = true;
37
+ if (!$this->loadByMagentoSessionId($magento_session_id)) {
38
+ $this->setMagentoSessionId($magento_session_id);
39
+ }
40
+ }
41
+
42
+ if ($customer_session->isLoggedIn()) {
43
+ $this->setCustomerId($customer_session->getId());
44
+ }
45
+
46
+ if ($email != null) {
47
+ $this->setEmail($email);
48
+ }
49
+
50
+ if ($new) {
51
+ $this->save();
52
+
53
+ Mage::getModel('core/cookie')->set('camp_id', $this->getId(), true, null, null, null, false);
54
+ } else {
55
+ $this->save();
56
+ }
57
+
58
+ Mage::getModel('campaigner/abandoned')->init($this);
59
+ } catch (Exception $e) {
60
+ Mage::helper('campaigner')->logException($e);
61
+ Mage::logException($e);
62
+ }
63
+
64
+ return $this;
65
+ }
66
+ }
app/code/community/Campaigner/Integration/Model/System/Config/Source/Abandonedlist.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_System_Config_Source_Abandonedlist
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ Mage::helper('campaigner/troubleshooting')->setLogArea(Campaigner_Integration_Helper_Troubleshooting::CONFIG);
8
+ Mage::helper('campaigner/troubleshooting')->setLogLevel(Campaigner_Integration_Helper_Troubleshooting::LOG_LEVEL_LOW);
9
+
10
+ $lists = Mage::getSingleton('campaigner/wrapper_lists')->getLists();
11
+
12
+ $options = array();
13
+
14
+ $options[] = array(
15
+ 'value' => -1,
16
+ 'label' => "-- SELECT LIST --"
17
+ );
18
+
19
+ foreach($lists as $list) {
20
+ if ($list['active']) {
21
+ $options[] = array(
22
+ 'value' => $list['id'],
23
+ 'label' => $list['name']
24
+ );
25
+ }
26
+ }
27
+ return $options;
28
+ }
29
+ }
app/code/community/Campaigner/Integration/Model/System/Config/Source/Additionallist.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_System_Config_Source_Additionallist
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ Mage::helper('campaigner/troubleshooting')->setLogArea(Campaigner_Integration_Helper_Troubleshooting::CONFIG);
8
+ Mage::helper('campaigner/troubleshooting')->setLogLevel(Campaigner_Integration_Helper_Troubleshooting::LOG_LEVEL_LOW);
9
+
10
+ $lists = Mage::getSingleton('campaigner/wrapper_lists')->getLists();
11
+
12
+ $options = array();
13
+
14
+ foreach($lists as $list) {
15
+ if ($list['active']) {
16
+ $options[] = array(
17
+ 'value' => $list['id'],
18
+ 'label' => $list['name']);
19
+ }
20
+ }
21
+ return $options;
22
+ }
23
+ }
app/code/community/Campaigner/Integration/Model/System/Config/Source/Checkoutsubscribe.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_System_Config_Source_Checkoutsubscribe
4
+ {
5
+
6
+ public function toOptionArray()
7
+ {
8
+ return array(
9
+ array('value' => 1, 'label' => Mage::helper('campaigner')->__('Enabled - Checked by default')),
10
+ array('value' => 2, 'label' => Mage::helper('campaigner')->__('Enabled - Not Checked by default')),
11
+ array('value' => 3, 'label' => Mage::helper('campaigner')->__('Enabled - Force subscription')),
12
+ array('value' => 0, 'label' => Mage::helper('campaigner')->__('-- Disabled --'))
13
+ );
14
+ }
15
+ }
app/code/community/Campaigner/Integration/Model/System/Config/Source/List.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_System_Config_Source_List
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ Mage::helper('campaigner/troubleshooting')->setLogArea(Campaigner_Integration_Helper_Troubleshooting::CONFIG);
8
+ Mage::helper('campaigner/troubleshooting')->setLogLevel(Campaigner_Integration_Helper_Troubleshooting::LOG_LEVEL_LOW);
9
+
10
+ $lists = Mage::getSingleton('campaigner/wrapper_lists')->getLists();
11
+
12
+ $options = array();
13
+
14
+ foreach ($lists as $list) {
15
+ $options[] = array(
16
+ 'value' => $list['Id'],
17
+ 'label' => $list['Name']);
18
+ }
19
+ return $options;
20
+ }
21
+ }
app/code/community/Campaigner/Integration/Model/System/Config/Source/Send/Field.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_System_Config_Source_Send_Field extends Varien_Data_Form_Abstract
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ $options = array(
8
+ array('value' => 'state','label' => "State"),
9
+ array('value' => 'status','label' => "Status"),
10
+ );
11
+
12
+ return $options;
13
+ }
14
+ }
app/code/community/Campaigner/Integration/Model/System/Config/Source/Sequence.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_System_Config_Source_Sequence
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ Mage::helper('campaigner/troubleshooting')->setLogArea(Campaigner_Integration_Helper_Troubleshooting::CONFIG);
8
+ Mage::helper('campaigner/troubleshooting')->setLogLevel(Campaigner_Integration_Helper_Troubleshooting::LOG_LEVEL_LOW);
9
+
10
+ $fields = Mage::helper('campaigner')->getCampaignerColumnOptions();
11
+
12
+ $options = array();
13
+
14
+ foreach ($fields as $field) {
15
+ $options[] = array(
16
+ 'value' => $field,
17
+ 'label' => $field);
18
+ }
19
+ return $options;
20
+ }
21
+ }
app/code/community/Campaigner/Integration/Model/System/Config/Source/Signup/Opacity.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_System_Config_Source_Signup_Opacity extends Varien_Data_Form_Abstract
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ $options = array();
8
+
9
+ for($i = 1; $i < 10; $i++) {
10
+ $percent = $i * 10;
11
+ $options[] = array('value' => $percent, 'label' => "{$percent}%");
12
+ }
13
+
14
+ return $options;
15
+ }
16
+ }
app/code/community/Campaigner/Integration/Model/System/Config/Source/Signup/Recurrence.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_System_Config_Source_Signup_Recurrence extends Varien_Data_Form_Abstract
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ $options = array(
8
+ array('value' => 'once','label' => "Only show once"),
9
+ array('value' => '1 day','label' => "1 day"),
10
+ array('value' => '1 week','label' => "1 week"),
11
+ array('value' => '1 month','label' => "1 month"),
12
+ );
13
+
14
+ return $options;
15
+ }
16
+ }
app/code/community/Campaigner/Integration/Model/System/Config/Source/Smtp/Encryption.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_System_Config_Source_Smtp_Encryption
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ $options = array(
8
+ array('value' => 'none', 'label' => 'none'),
9
+ array('value' => 'TLS', 'label' => 'TLS'),
10
+ array('value' => 'SSL', 'label' => 'SSL'),
11
+ );
12
+
13
+ return $options;
14
+ }
15
+ }
app/code/community/Campaigner/Integration/Model/System/Config/Source/States.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_System_Config_Source_States
4
+ {
5
+ private function getStates()
6
+ {
7
+ $states = array();
8
+
9
+ $config_states = Mage::getConfig()->getNode('global/sales/order/states');
10
+
11
+ foreach ($config_states->children() as $state) {
12
+ $label = (string) $state->label;
13
+ $states[$state->getName()] = Mage::helper('sales')->__($label);
14
+ }
15
+
16
+ return $states;
17
+ }
18
+
19
+ public function toOptionArray()
20
+ {
21
+ $sales_config = Mage::getSingleton('sales/order_config');
22
+
23
+ if (!method_exists($sales_config,'getStates')) {
24
+ $states = $this->getStates();
25
+ } else {
26
+ $states = $sales_config->getStates();
27
+ }
28
+
29
+ $options = array();
30
+
31
+ foreach($states as $value => $label) {
32
+ $options[] = array(
33
+ 'value' => $value,
34
+ 'label' => $label
35
+ );
36
+ }
37
+ return $options;
38
+ }
39
+ }
app/code/community/Campaigner/Integration/Model/System/Config/Source/Statuses.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_System_Config_Source_Statuses
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ $sales_config = Mage::getSingleton('sales/order_config');
8
+
9
+ $statuses = $sales_config->getStatuses();
10
+
11
+ $options = array();
12
+
13
+ foreach($statuses as $value => $label) {
14
+ $options[] = array(
15
+ 'value' => $value,
16
+ 'label' => $label);
17
+ }
18
+ return $options;
19
+ }
20
+ }
app/code/community/Campaigner/Integration/Model/System/Config/Source/Store.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_System_Config_Source_Store
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ Mage::helper('campaigner/troubleshooting')->setLogArea(Campaigner_Integration_Helper_Troubleshooting::CONFIG);
8
+ Mage::helper('campaigner/troubleshooting')->setLogLevel(Campaigner_Integration_Helper_Troubleshooting::LOG_LEVEL_LOW);
9
+
10
+ $lists = Mage::getSingleton('campaigner/wrapper_lists')->getLists();
11
+
12
+ $options = array(
13
+ array (
14
+ 'value' => 'id',
15
+ 'label' => 'ID',
16
+ ),
17
+ array (
18
+ 'value' => 'code',
19
+ 'label' => 'Code',
20
+ ),
21
+ array (
22
+ 'value' => 'name',
23
+ 'label' => 'Name',
24
+ )
25
+ );
26
+
27
+ return $options;
28
+ }
29
+ }
app/code/community/Campaigner/Integration/Model/System/Config/Source/Time.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_System_Config_Source_Time
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ $options = array(
8
+ array('value' => 15,'label' => "15 Minutes"),
9
+ array('value' => 30,'label' => "30 Minutes"),
10
+ array('value' => 45,'label' => "45 Minutes"),
11
+ array('value' => 60,'label' => "60 Minutes"));
12
+
13
+ return $options;
14
+ }
15
+ }
app/code/community/Campaigner/Integration/Model/Wrapper/Abandoned.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Campaigner_Integration_Model_Wrapper_Abandoned extends Campaigner_Integration_Model_Wrapper_Abstract
3
+ {
4
+ public function send($contactData)
5
+ {
6
+ $listId = (int)Mage::helper('campaigner')->config('abandoned_list');
7
+
8
+ $data = array(
9
+ 'UpdateExistingContacts' => true,
10
+ 'TriggerWorkflow' => false,
11
+ 'contacts' => Array(
12
+ 'ContactData' => $contactData
13
+ ),
14
+ 'globalAddToGroup' => array($listId)
15
+ );
16
+
17
+ $service = 'contact';
18
+ $method = "ImmediateUpload";
19
+
20
+ $response = $this->sendCommand($service, $method, null, $data);
21
+ }
22
+
23
+ public function getOneCart($email,$merge_vars)
24
+ {
25
+ return $this->getEmailContactData($email, $merge_vars);
26
+ }
27
+ }
app/code/community/Campaigner/Integration/Model/Wrapper/Abstract.php ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_Wrapper_Abstract extends Campaigner_Integration_Model_Wrapper_Execute
4
+ {
5
+ protected $_prefix = "";
6
+
7
+ public function getCommonData($email, $customFields, $newEmail = null, $contactId = 0, $testContact = false)
8
+ {
9
+ if ($newEmail == null) {
10
+ $newEmail = $email;
11
+ }
12
+
13
+ $defaults = Mage::helper('campaigner/fields')->getDefaultFields();
14
+
15
+ $contactData = array(
16
+ 'IsTestContact' => $testContact,
17
+ 'ContactKey' => array(
18
+ 'ContactId' => (int)$contactId,
19
+ 'ContactUniqueIdentifier' => $email,
20
+ ),
21
+ 'EmailAddress' => $newEmail
22
+ );
23
+
24
+ foreach ($defaults as $key => $default) {
25
+ if (isset($customFields[$key])) {
26
+ $contactData[$defaults[$key]] = $customFields[$key];
27
+ unset($customFields[$key]);
28
+ }
29
+ }
30
+
31
+ $contactData['CustomAttributes'] = $this->getCustomFields($customFields);
32
+
33
+ return $contactData;
34
+ }
35
+
36
+ public function getEmailContactData($email, $customFields, $newEmail = null, $contactId = 0, $testContact = false)
37
+ {
38
+ return $this->getCommonData($email, $customFields, $contactId, $testContact);
39
+ }
40
+
41
+ public function getContactData($customer, $extraFields = null, $contactId = 0, $testContact = false)
42
+ {
43
+ $email = $customer->getEmail();
44
+ $originalEmail = $customer->getOrigData('email');
45
+
46
+ if (!$originalEmail || trim($originalEmail) == "") {
47
+ $originalEmail = $email;
48
+ }
49
+
50
+ $customFields = Mage::helper('campaigner')->getMergeVars($customer);
51
+ if ($extraFields) {
52
+ $customFields = array_merge($customFields, $extraFields);
53
+ }
54
+
55
+ return $this->getCommonData($originalEmail, $customFields, $email, $contactId, $testContact);
56
+ }
57
+
58
+ protected function getStoreMap($merge_vars)
59
+ {
60
+ $store = Mage::app()->getStore();
61
+
62
+ $store_config = Mage::helper('campaigner')->config('store_send_type');
63
+
64
+ $store_value = $store->getId();
65
+
66
+ switch ($store_config) {
67
+ case "name": $store_value = $store->getName(); break;
68
+ case "code": $store_value = $store->getCode(); break;
69
+ }
70
+
71
+ $merge_vars["Store"] = $store_value;
72
+
73
+ return $merge_vars;
74
+ }
75
+
76
+ protected function debug($data)
77
+ {
78
+ Mage::helper('campaigner/troubleshooting')->debug($data);
79
+ }
80
+
81
+ public function debugHeader($header, $level = 2)
82
+ {
83
+ Mage::helper('campaigner/troubleshooting')->debugHeader($header, $level);
84
+ }
85
+
86
+ protected function getFieldKeys($key)
87
+ {
88
+ if (strpos($key,$this->_prefix) === FALSE) {
89
+ $prefix_key = "{$this->_prefix}{$key}";
90
+
91
+ return array($prefix_key, $key);
92
+ }
93
+ return array($key);
94
+ }
95
+
96
+ protected function getCustomFields($merge_vars)
97
+ {
98
+ $this->_prefix = Mage::helper('campaigner')->config('field_prefix');
99
+ $merge_vars = $this->getStoreMap($merge_vars);
100
+
101
+ $this->debug('');
102
+ $this->debugHeader('getCustomFields');
103
+ $this->debug('Merge Vars');
104
+ $this->debug($merge_vars);
105
+
106
+ $fieldMap = Mage::helper('campaigner/fields')->getFieldMap();
107
+
108
+ $this->debug('Field Map');
109
+ $this->debug($fieldMap);
110
+
111
+ $data = array();
112
+
113
+ $this->debug('');
114
+ $this->debug('PROCESSING FIELDS');
115
+
116
+ foreach ($merge_vars as $key => $value) {
117
+ $this->debug("KEY: [{$key}] VALUE: [{$value}]");
118
+
119
+ $potential_keys = $this->getFieldKeys($key);
120
+
121
+ foreach ($potential_keys as $key) {
122
+ $this->debug("CHECK KEY: [{$key}] VALUE: [{$value}]");
123
+ if (isset($fieldMap[$key])) {
124
+ $this->debug("Key Found!");
125
+ $id = $fieldMap[$key];
126
+ $data[] = array("_" => $value, "Id" => $id);
127
+ break;
128
+ }
129
+ }
130
+ }
131
+
132
+ $this->debug('');
133
+ $this->debug("FINAL DATA");
134
+ $this->debug($data);
135
+
136
+ return $data;
137
+ }
138
+ }
app/code/community/Campaigner/Integration/Model/Wrapper/Database.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_Wrapper_Database extends Campaigner_Integration_Model_Wrapper_Abstract
4
+ {
5
+ private $_columnCache = null;
6
+
7
+ public function add($name, $type, $default = "")
8
+ {
9
+ $service = 'contact';
10
+ $method = "CreateUpdateAttribute";
11
+ $tag = null;
12
+
13
+ $data = array(
14
+ 'attributeId' => "0",
15
+ 'attributeName' => $name,
16
+ 'attributeType' => $type,
17
+ 'defaultValue' => $default,
18
+ 'clearDefault' => false
19
+ );
20
+
21
+ Mage::getSingleton('campaigner/wrapper_execute')->sendCommand($service, $method, $tag, $data);
22
+ }
23
+
24
+ public function get($name)
25
+ {
26
+ throw new Exception("GET NOT IMPLEMENTED");
27
+ }
28
+
29
+ public function getAttributeFilters($default = true, $custom = true, $system = true)
30
+ {
31
+ return array(
32
+ 'IncludeAllDefaultAttributes' => $default,
33
+ 'IncludeAllCustomAttributes' => $custom,
34
+ 'IncludeAllSystemAttributes' => $system,
35
+ );
36
+ }
37
+
38
+ private function getColumnKey($default, $custom, $system)
39
+ {
40
+ return "{$default}_{$custom}_{$system}";
41
+ }
42
+
43
+ public function getAllColumns($default = true, $custom = true, $system = true)
44
+ {
45
+ $key = $this->getColumnKey($default, $custom, $system);
46
+
47
+ if (isset($this->_columnCache[$key])) {
48
+ return $this->_columnCache[$key];
49
+ }
50
+
51
+ $data = $this->getAttributeFilters($default, $custom, $system);
52
+
53
+ $service = 'contact';
54
+ $method = "ListAttributes";
55
+ $tag = "filter";
56
+
57
+ //$attributes = array();
58
+
59
+ try {
60
+ $response = Mage::getSingleton('campaigner/wrapper_execute')->sendCommand($service, $method, $tag, $data);
61
+ }
62
+ catch (Exception $e) {
63
+ $this->logException($e);
64
+ return null;
65
+ }
66
+
67
+ if (!isset($response->AttributeDescription)) {
68
+ return null;
69
+ }
70
+
71
+ $this->_columnCache[$key] = $response->AttributeDescription;
72
+
73
+ return $response->AttributeDescription;
74
+ }
75
+ }
app/code/community/Campaigner/Integration/Model/Wrapper/Exception.php ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_Wrapper_Exception extends Exception
4
+ {
5
+ /**
6
+ * Return Code from API
7
+ *
8
+ * @var string
9
+ */
10
+ protected $_returnCode;
11
+
12
+ /**
13
+ * Return Type from API
14
+ *
15
+ * @var string
16
+ */
17
+ protected $_returnType;
18
+
19
+ /**
20
+ * Return Label from API
21
+ *
22
+ * @var string
23
+ */
24
+ protected $_returnLabel;
25
+
26
+ /**
27
+ * Details about exception
28
+ *
29
+ * @var stdClass
30
+ */
31
+ protected $_details;
32
+
33
+ // Redefine the exception so message isn't optional
34
+ public function __construct($message, $returnCode = null, $details = null)
35
+ {
36
+ if ($returnCode != null) {
37
+ $this->setReturnCode($returnCode['code']);
38
+ $this->setReturnType($returnCode['type']);
39
+ $this->setReturnLabel($returnCode['label']);
40
+ }
41
+
42
+ $this->_details = $details;
43
+
44
+ // make sure everything is assigned properly
45
+ parent::__construct($message, 0, null);
46
+ }
47
+
48
+ /**
49
+ * Set Details
50
+ *
51
+ * @param stdClass $details
52
+ * @return Campaigner_Integration_Model_Wrapper_Exception
53
+ */
54
+ public function setDetails($details)
55
+ {
56
+ $this->_details = $details;
57
+ return $this;
58
+ }
59
+
60
+ /**
61
+ * Retrieve Details
62
+ *
63
+ * @return stdClass
64
+ */
65
+ public function getDetails()
66
+ {
67
+ return $this->_details;
68
+ }
69
+
70
+ /**
71
+ * Set Return Code
72
+ *
73
+ * @param string $returnCode
74
+ * @return Campaigner_Integration_Model_Wrapper_Exception
75
+ */
76
+ public function setReturnCode($returnCode)
77
+ {
78
+ $this->_returnCode = $returnCode;
79
+ return $this;
80
+ }
81
+
82
+ /**
83
+ * Retrieve Return Code
84
+ *
85
+ * @return string
86
+ */
87
+ public function getReturnCode()
88
+ {
89
+ return $this->_returnCode;
90
+ }
91
+
92
+ /**
93
+ * Set Return Type
94
+ *
95
+ * @param string $returnType
96
+ * @return Campaigner_Integration_Model_Wrapper_Exception
97
+ */
98
+ public function setReturnType($returnType)
99
+ {
100
+ $this->_returnType = $returnType;
101
+ return $this;
102
+ }
103
+
104
+ /**
105
+ * Retrieve Return Message
106
+ *
107
+ * @return string
108
+ */
109
+ public function getReturnType()
110
+ {
111
+ return $this->_returnType;
112
+ }
113
+
114
+ /**
115
+ * Set Return Label
116
+ *
117
+ * @param string $returnLabel
118
+ * @return Campaigner_Integration_Model_Wrapper_Exception
119
+ */
120
+ public function setReturnLabel($returnLabel)
121
+ {
122
+ $this->_returnLabel = $returnLabel;
123
+ return $this;
124
+ }
125
+
126
+ /**
127
+ * Retrieve Return Label
128
+ *
129
+ * @return string
130
+ */
131
+ public function getReturnLabel()
132
+ {
133
+ return $this->_returnLabel;
134
+ }
135
+ }
app/code/community/Campaigner/Integration/Model/Wrapper/Execute.php ADDED
@@ -0,0 +1,203 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_Wrapper_Execute
4
+ {
5
+ protected $_helper = null;
6
+ protected $_logger = null;
7
+
8
+ public function __construct()
9
+ {
10
+ $this->_helper = Mage::helper('campaigner');
11
+ $this->_logger = Mage::helper('campaigner/troubleshooting');
12
+ }
13
+
14
+ public function sendCommand($service, $method, $tag = null, $data = null)
15
+ {
16
+ $debug = $this->_logger->isDebugMode();
17
+
18
+ if ($debug) {
19
+ $this->_logger->setDebugRequest($data);
20
+
21
+ if ($this->_logger->getDebugExecuteMode() == 'request_only')
22
+ return $data;
23
+ }
24
+
25
+ if (!$this->_helper->campaignerEnabled()) {
26
+ return $this->createErrorResponse("Campaigner not enabled");
27
+ }
28
+
29
+ $username = $this->_helper->config('api_username');
30
+ $password = $this->_helper->config('api_password');
31
+
32
+ if ((!$username || $username == "") || (!$password || $password == "")) {
33
+ return $this->createErrorResponse("Invalid or missing credentials");
34
+ }
35
+
36
+ $response = $this->sendCommandDirect($username, $password, $service, $method, $tag, $data);
37
+
38
+ if ($debug) {
39
+ $this->_logger->setDebugResponse($response);
40
+ }
41
+
42
+ return $response;
43
+ }
44
+
45
+ // NOT CURRENTLY USED
46
+ private function createErrorResponse($message, $code = 0)
47
+ {
48
+ $data = array(
49
+ 'ErrorFlag' => true,
50
+ 'ReturnCode' => array('M',$code,$message),
51
+ 'ReturnMessage' => $message,
52
+ 'Response' => null
53
+ );
54
+
55
+ return $data;
56
+ }
57
+
58
+ public function sendCommandDirect($username, $password, $service, $method, $tag = null, $data = null)
59
+ {
60
+ if ((!$username || $username == "") || (!$password || $password == "")) {
61
+ throw new Exception("Invalid or missing credentials");
62
+ }
63
+
64
+ if ($data != null) {
65
+ $this->_logger->log($data,"Input Data ({$method} - {$tag})");
66
+ }
67
+
68
+ if (Mage::registry('execute_failure')) {
69
+ $this->_logger->log("Excute aborting due to previous failure: " . Mage::registry('execute_failure'));
70
+ throw new Exception("Execute Failure");
71
+ }
72
+
73
+ $url = "https://ws.campaigner.com/2013/01/{$service}management.asmx?WSDL";
74
+
75
+ $client = new SoapClient($url, array('exceptions' => false,
76
+ 'compression'=> SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP,
77
+ 'soap_version'=> 'SOAP_1_1',
78
+ 'trace' => true,
79
+ 'connection_timeout' => 300));
80
+
81
+ $authentication = array(
82
+ "Username" => $username,
83
+ "Password" => $password
84
+ );
85
+
86
+ $this->log("URL: {$url}");
87
+
88
+ $request = Array(
89
+ 'authentication' => $authentication,
90
+ );
91
+
92
+ if ($data) {
93
+ if ($tag) {
94
+ $request[$tag] = $data;
95
+ } else {
96
+ $request = array_merge($request,$data);
97
+ }
98
+ }
99
+
100
+ $this->log($request,"Request");
101
+
102
+ $response = $client->$method($request);
103
+
104
+ $lastResponse = $client->__getLastResponse();
105
+
106
+ $this->log($client->__getLastRequest(),"Last Request");
107
+
108
+ $this->log($lastResponse,"Response Header");
109
+
110
+ $finalResponse = $this->processResponse(
111
+ $lastResponse,
112
+ $response,
113
+ "{$method}Result"
114
+ );
115
+
116
+ $this->log($finalResponse,"Final Response");
117
+
118
+ return $finalResponse;
119
+ }
120
+
121
+ private function processReturnCode($returnCode)
122
+ {
123
+ $parts = explode("_", $returnCode);
124
+
125
+ $pieces = array(
126
+ 0 => 'type',
127
+ 1 => 'code',
128
+ 2 => 'label'
129
+ );
130
+
131
+ $data = array();
132
+
133
+ foreach ($pieces as $index => $key) {
134
+ if (isset($parts[$index])) {
135
+ $data[$key] = $parts[$index];
136
+ }
137
+ }
138
+
139
+ return $data;
140
+ }
141
+
142
+ private function checkResponseError($header)
143
+ {
144
+ $returnCode = strtolower((string)$header->ReturnCode);
145
+
146
+ if (strpos($returnCode,"account-locked") !== FALSE) {
147
+ $this->_helper->disableCampaigner($this->_helper->getCurrentStore(),true);
148
+ Mage::register('execute_failure',(string)$header->ReturnMessage);
149
+ } else if (strpos($returnCode,"invalid-username-or-password")) {
150
+ $this->_helper->disableCampaigner($this->_helper->getCurrentStore());
151
+ Mage::register('execute_failure',(string)$header->ReturnMessage);
152
+ }
153
+ }
154
+
155
+ private function processResponse($responseXml, $response, $result)
156
+ {
157
+ $soap = simplexml_load_string($responseXml);
158
+ $header = $soap->children('http://schemas.xmlsoap.org/soap/envelope/')
159
+ ->Header->children()->ResponseHeader;
160
+
161
+ if (((string) $header->ErrorFlag) == "true")
162
+ {
163
+ $this->_logger->log($response,"Raw Response");
164
+
165
+ $this->checkResponseError($header);
166
+ if (isset($response->$result)) {
167
+ throw New Campaigner_Integration_Model_Wrapper_Exception(
168
+ (string) $header->ReturnMessage,
169
+ $this->processReturnCode((string) $header->ReturnCode),
170
+ $response->$result
171
+ );
172
+ } else {
173
+ throw New Campaigner_Integration_Model_Wrapper_Exception(
174
+ (string) $header->ReturnMessage,
175
+ $this->processReturnCode((string) $header->ReturnCode)
176
+ );
177
+ }
178
+ }
179
+
180
+ if (!isset($response->$result)) {
181
+ $this->_logger->log($response,"Raw Response");
182
+ throw new Exception("Result not found", 1);
183
+ ;
184
+ }
185
+
186
+ return $response->$result;
187
+ }
188
+
189
+ protected function debug($data)
190
+ {
191
+ $this->_logger->debug($data);
192
+ }
193
+
194
+ protected function log($data, $prefix = "", $area = "")
195
+ {
196
+ $this->_logger->log($data, $prefix, $area);
197
+ }
198
+
199
+ public function logException($e)
200
+ {
201
+ $this->_logger->logException($e);
202
+ }
203
+ }
app/code/community/Campaigner/Integration/Model/Wrapper/Lists.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_Wrapper_Lists extends Campaigner_Integration_Model_Wrapper_Execute
4
+ {
5
+ protected $_listCache = null;
6
+
7
+ public function getLists()
8
+ {
9
+ if ($this->_listCache != null) {
10
+ return $this->_listCache;
11
+ }
12
+
13
+ $service = 'list';
14
+ $method = 'ListContactGroups';
15
+
16
+ $lists = array();
17
+
18
+ try {
19
+ $response = $this->sendCommand($service, $method);
20
+ } catch (Exception $e) {
21
+ $this->logException($e);
22
+ return $lists;
23
+ }
24
+
25
+ if (isset($response->ContactGroupDescription)) {
26
+ foreach ($response->ContactGroupDescription as $list) {
27
+ if ($list->Type == 'MailingList') {
28
+ $lists[] = get_object_vars($list);
29
+ }
30
+ }
31
+ }
32
+
33
+ $this->_listCache = $lists;
34
+
35
+ return $lists;
36
+ }
37
+ }
app/code/community/Campaigner/Integration/Model/Wrapper/Orders.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_Wrapper_Orders extends Campaigner_Integration_Model_Wrapper_Abstract
4
+ {
5
+ public function send($contactData)
6
+ {
7
+ $data = array(
8
+ 'UpdateExistingContacts' => true,
9
+ 'TriggerWorkflow' => false,
10
+ 'contacts' => Array(
11
+ 'ContactData' => $contactData
12
+ ),
13
+ );
14
+
15
+ $service = 'contact';
16
+ $method = "ImmediateUpload";
17
+
18
+ $response = $this->sendCommand($service, $method, null, $data);
19
+ }
20
+
21
+ public function addSubscriberTracking($email, $merge_vars)
22
+ {
23
+ $contactData = $this->getEmailContactData($email, $merge_vars);
24
+
25
+ $data = array(
26
+ 'UpdateExistingContacts' => true,
27
+ 'TriggerWorkflow' => false,
28
+ 'contacts' => Array(
29
+ 'ContactData' => $contactData
30
+ ),
31
+ );
32
+
33
+ $service = 'contact';
34
+ $method = "ImmediateUpload";
35
+
36
+ $response = $this->sendCommand($service, $method, null, $data);
37
+ }
38
+ }
app/code/community/Campaigner/Integration/Model/Wrapper/Subscribers.php ADDED
@@ -0,0 +1,204 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Model_Wrapper_subscribers extends Campaigner_Integration_Model_Wrapper_Abstract
4
+ {
5
+ protected $_contactCache = null;
6
+
7
+ public function add($customer, $subscribe = false)
8
+ {
9
+ $listId = (int)Mage::helper('campaigner')->config('list');
10
+ $contactData = $this->getContactData($customer);
11
+
12
+ $data = array(
13
+ 'UpdateExistingContacts' => true,
14
+ 'TriggerWorkflow' => false,
15
+ 'contacts' => Array(
16
+ 'ContactData' => $contactData
17
+ ),
18
+ );
19
+
20
+ if ($subscribe) {
21
+ $data['globalAddToGroup'] = array($listId);
22
+ }
23
+
24
+ $service = 'contact';
25
+ $method = "ImmediateUpload";
26
+
27
+ $response = $this->sendCommand($service, $method, null, $data);
28
+ }
29
+
30
+ public function addByEmail($email, $merge_vars, $subscribe = false)
31
+ {
32
+ $listId = (int)Mage::helper('campaigner')->config('list');
33
+ $contactData = $this->getEmailContactData($email, $merge_vars);
34
+
35
+ $data = array(
36
+ 'UpdateExistingContacts' => true,
37
+ 'TriggerWorkflow' => false,
38
+ 'contacts' => Array(
39
+ 'ContactData' => $contactData
40
+ ),
41
+ );
42
+
43
+ if ($subscribe) {
44
+ $data['globalAddToGroup'] = array($listId);
45
+ }
46
+
47
+ $service = 'contact';
48
+ $method = "ImmediateUpload";
49
+
50
+ $response = $this->sendCommand($service, $method, null, $data);
51
+ }
52
+
53
+ public function delete($customer)
54
+ {
55
+ $data = array(
56
+ 'ContactKey' => array(
57
+ 'ContactId' => 0,
58
+ 'ContactUniqueIdentifier' => $customer->getEmail()
59
+ )
60
+ );
61
+
62
+ $service = 'contact';
63
+ $method = "DeleteContacts";
64
+
65
+ return $this->sendCommand($service, $method, 'contactKeys', $data);
66
+ }
67
+
68
+ public function updateSubscriptions($customer, $add, $remove)
69
+ {
70
+ $contactData = array(
71
+ 'ContactKey' => array(
72
+ 'ContactId' => 0,
73
+ 'ContactUniqueIdentifier' => $customer->getEmail()
74
+ )
75
+ );
76
+
77
+ if (count($add) > 0) {
78
+ $contactData['AddToGroup'] = $add;
79
+ }
80
+ if (count($remove) > 0) {
81
+ $contactData['RemoveFromGroup'] = $remove;
82
+ }
83
+
84
+ $data = array(
85
+ 'UpdateExistingContacts' => true,
86
+ 'TriggerWorkflow' => false,
87
+ 'contacts' => Array(
88
+ 'ContactData' => $contactData
89
+ )
90
+ );
91
+
92
+ $service = 'contact';
93
+ $method = "ImmediateUpload";
94
+
95
+ return $this->sendCommand($service, $method, null, $data);
96
+ }
97
+
98
+ public function getAttributeFilters($static = true, $custom = true, $system = true, $group = true)
99
+ {
100
+ return array(
101
+ 'IncludeStaticAttributes' => $static,
102
+ 'IncludeCustomAttributes' => $custom,
103
+ 'IncludeSystemAttributes' => $system,
104
+ 'IncludeGroupMembershipData' => $group,
105
+ );
106
+ }
107
+
108
+ public function getContact($email, $static = true, $custom = true, $system = true, $group = true)
109
+ {
110
+ $infoFilters = $this->getAttributeFilters($static, $custom, $system, $group);
111
+
112
+ $service = 'contact';
113
+ $method = "GetContacts";
114
+ $tag = null;
115
+
116
+ $data = array(
117
+ "contactFilter" => array(
118
+ "ContactKeys" => array(
119
+ "ContactKey" => array("ContactId" => 0, "ContactUniqueIdentifier" => $email)
120
+ )
121
+ ),
122
+ "contactInformationFilter" => $infoFilters
123
+ );
124
+
125
+ try {
126
+ $response = Mage::getSingleton('campaigner/wrapper_execute')->sendCommand($service, $method, $tag, $data);
127
+
128
+ if (!isset($response->ContactData->ContactDetailData)) {
129
+ return null;
130
+ }
131
+
132
+ } catch (Exception $e) {
133
+ return null;
134
+ }
135
+
136
+ return $response->ContactData->ContactDetailData;
137
+ }
138
+
139
+ public function updateContact($email, $merge_vars)
140
+ {
141
+ $contactData = $this->getEmailContactData($email, $merge_vars);
142
+
143
+ $data = array(
144
+ 'UpdateExistingContacts' => true,
145
+ 'TriggerWorkflow' => false,
146
+ 'contacts' => Array(
147
+ 'ContactData' => $contactData
148
+ ),
149
+ );
150
+
151
+ $service = 'contact';
152
+ $method = "ImmediateUpload";
153
+
154
+ $response = $this->sendCommand($service, $method, null, $data);
155
+ return $response;
156
+ }
157
+
158
+ public function resubscribeContact($email)
159
+ {
160
+ $contactData = $this->getEmailContactData($email, array());
161
+
162
+ $data = array(
163
+ 'contactKey' => array(
164
+ 'ContactId' => 0,
165
+ 'ContactUniqueIdentifier' => $email,
166
+ ),
167
+ 'status' => 'Subscribed'
168
+ );
169
+
170
+ $service = 'contact';
171
+ $method = "ResubscribeContact";
172
+
173
+ $response = $this->sendCommand($service, $method, null, $data);
174
+ return $response;
175
+ }
176
+
177
+ public function sendLastLogin($email, $date)
178
+ {
179
+ $merge_vars = array("LastLogin" => $date);
180
+
181
+ if ($this->_helper->config('background_enabled') == 1) {
182
+ $action = Mage::getModel('campaigner/action_list');
183
+
184
+ $action->init($email, "LASTLOGIN",$merge_vars);
185
+ $action->save();
186
+ return;
187
+ }
188
+
189
+ $contactData = $this->getEmailContactData($email, $merge_vars);
190
+
191
+ $data = array(
192
+ 'UpdateExistingContacts' => true,
193
+ 'TriggerWorkflow' => false,
194
+ 'contacts' => Array(
195
+ 'ContactData' => $contactData
196
+ ),
197
+ );
198
+
199
+ $service = 'contact';
200
+ $method = "ImmediateUpload";
201
+
202
+ $response = $this->sendCommand($service, $method, null, $data);
203
+ }
204
+ }
app/code/community/Campaigner/Integration/Model/Wrapper/Wishlist.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Campaigner_Integration_Model_Wrapper_Wishlist extends Campaigner_Integration_Model_Wrapper_Abstract
3
+ {
4
+ public function send($email, $merge_vars)
5
+ {
6
+ if ($this->_helper->config('background_enabled') == 1) {
7
+ $this->log("Background Processing Enabled");
8
+ $action = Mage::getModel('campaigner/action_list');
9
+
10
+ $action->init($email, "WISHLIST",$merge_vars);
11
+ $action->save();
12
+ return;
13
+ }
14
+
15
+ $contactData = $this->getEmailContactData($email, $merge_vars);
16
+
17
+ $data = array(
18
+ 'UpdateExistingContacts' => true,
19
+ 'TriggerWorkflow' => false,
20
+ 'contacts' => Array(
21
+ 'ContactData' => $contactData
22
+ ),
23
+ );
24
+
25
+ $service = 'contact';
26
+ $method = "ImmediateUpload";
27
+
28
+ $response = $this->sendCommand($service, $method, null, $data);
29
+ }
30
+ }
app/code/community/Campaigner/Integration/controllers/AbandonedController.php ADDED
@@ -0,0 +1,270 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_AbandonedController extends Campaigner_Integration_Controller_Front_Abstract
4
+ {
5
+ public function restoreAction()
6
+ {
7
+ try
8
+ {
9
+ $coded_cart = Mage::app()->getRequest()->getParam('cart');
10
+
11
+ $cart_data = unserialize(base64_decode($coded_cart));
12
+
13
+ $this->clearCart($cart_data['quote']);
14
+ $this->restoreCartItems($cart_data);
15
+
16
+ $this->_redirect("checkout/cart");
17
+ }
18
+ catch (Exception $e)
19
+ {
20
+ $this->getCheckout()->addError('Unable to Restore your cart');
21
+ Mage::logException($e);
22
+ $this->_redirect("checkout/cart");
23
+ }
24
+ }
25
+
26
+ private function processBundleOptions($option)
27
+ {
28
+ $option_data = explode("-", $option);
29
+
30
+ $bundle_option = array();
31
+ $bundle_option_qty = array();
32
+
33
+ foreach ($option_data as $od)
34
+ {
35
+ $od_parts = explode("=",$od);
36
+
37
+ $option_id = $od_parts[0];
38
+
39
+ $products = $od_parts[1];
40
+
41
+ if (strpos($products,"~"))
42
+ {
43
+ // Single Item with Qty
44
+ $option_products = explode("~",$products);
45
+
46
+ $bundle_option[$option_id] = $option_products[0];
47
+
48
+ $bundle_option_qty[$option_id] = $option_products[1];
49
+ }
50
+ else
51
+ {
52
+ // 1 or more items with no qty
53
+ $option_products = explode(":",$products);
54
+
55
+ foreach ($option_products as $op)
56
+ {
57
+ $bundle_option[$option_id][] = $op;
58
+ }
59
+ }
60
+ }
61
+
62
+ return array('bundle_option' => $bundle_option, 'bundle_option_qty' => $bundle_option_qty);
63
+ }
64
+
65
+ private function prepareCartItems($cart_data)
66
+ {
67
+ $id_list = explode(",",$cart_data['id']);
68
+ $qty_list = explode(",",$cart_data['qty']);
69
+
70
+ $item_list = array();
71
+ $group_list = array();
72
+ $position = 0;
73
+
74
+ foreach ($id_list as $key => $item_id)
75
+ {
76
+ $position++;
77
+ $qty = $qty_list[$key];
78
+
79
+ $id_parts = explode('|',$item_id);
80
+
81
+ // If there is more than just an id then we have a complex product
82
+ if (count($id_parts) > 1)
83
+ {
84
+ $id = $id_parts[0];
85
+ $option = $id_parts[1];
86
+
87
+ // MAKE SURE WE CAN LOAD THE PRODUCT
88
+ $product = Mage::getModel('catalog/product')->load($id);
89
+ if (!$product)
90
+ continue;
91
+
92
+ switch ($product->getTypeId())
93
+ {
94
+ case "configurable":
95
+ {
96
+ $item_list[$position] = array(
97
+ 'product_type' => 'configurable',
98
+ 'product' => $product,
99
+ 'qty' => $qty,
100
+ 'option' => array('super_attribute' => Mage::helper('campaigner')->getConfigurableOptions($product,$option))
101
+ );
102
+ } break;
103
+ case "simple": // Grouped simple products
104
+ {
105
+ $parent_product = Mage::getModel('catalog/product')->load($option);
106
+
107
+ if (!$parent_product)
108
+ continue;
109
+
110
+ if (!isset($group_list[$option]))
111
+ {
112
+ $group_list[$option] = array(
113
+ 'position' => $position,
114
+ 'product_type' => 'grouped',
115
+ 'product' => $parent_product,
116
+ 'option' => array('super_group' => array())
117
+ );
118
+ }
119
+
120
+ $group_list[$option]['option']['super_group'][$id] = $qty;
121
+ } break;
122
+ case "bundle":
123
+ {
124
+ $item_list[$position] = array(
125
+ 'product_type' => 'bundle',
126
+ 'product' => $product,
127
+ 'qty' => $qty,
128
+ 'option' => $this->processBundleOptions($option)
129
+ );
130
+ } break;
131
+ }
132
+ }
133
+ else
134
+ {
135
+ // Simple Product
136
+
137
+ // MAKE SURE WE CAN LOAD THE PRODUCT
138
+ $product = Mage::getModel('catalog/product')->load($item_id);
139
+ if (!$product)
140
+ continue;
141
+
142
+ $item_list[] = array(
143
+ 'product_type' => 'simple',
144
+ 'product' => $product,
145
+ 'qty' => $qty
146
+ );
147
+ }
148
+ }
149
+
150
+ // Merge the group and simple products
151
+ foreach ($group_list as $group)
152
+ {
153
+ $item_list[$group['position']] = $group;
154
+ }
155
+
156
+ // Sort it so that the order matches the cart order
157
+ ksort($item_list);
158
+
159
+ return $item_list;
160
+ }
161
+
162
+ private function restoreCartItems($cart_data)
163
+ {
164
+ $quote = $this->getQuote();
165
+
166
+ $item_list = $this->prepareCartItems($cart_data);
167
+
168
+ foreach ($item_list as $item)
169
+ {
170
+ $this->addItemToCart($item);
171
+ }
172
+
173
+ // update our totals, save.
174
+ $quote->getBillingAddress();
175
+ $quote->collectTotals();
176
+ $quote->save();
177
+
178
+ $this->getCheckout()->setQuoteId($quote->getId());
179
+ }
180
+
181
+ private function addItemToCart($item)
182
+ {
183
+ try
184
+ {
185
+ $product = $item['product'];
186
+
187
+ $data = array(
188
+ 'options' => array()
189
+ );
190
+
191
+ if (isset($item['qty'])) {
192
+ $data['qty'] = $item['qty'];
193
+ }
194
+
195
+ if (isset($item['option']))
196
+ {
197
+ foreach ($item['option'] as $key => $option)
198
+ {
199
+ $data[$key] = $option;
200
+ }
201
+ }
202
+
203
+ $quote = $this->getQuote();
204
+
205
+ // add the product to our quote
206
+ $quote->addProductAdvanced($product, new Varien_Object($data));
207
+
208
+ return true;
209
+ }
210
+ catch (Exception $e)
211
+ {
212
+ Mage::logException($e);
213
+ return false;
214
+ }
215
+ }
216
+
217
+ private function removeOldQuote($original_quote_id)
218
+ {
219
+ $quote = Mage::getModel('sales/quote')->load($original_quote_id);
220
+
221
+ if ($quote->getId() == $original_quote_id) {
222
+ $quote->delete();
223
+ }
224
+ }
225
+
226
+ private function clearCart($original_quote_id)
227
+ {
228
+ $customer_session = Mage::getSingleton('customer/session');
229
+
230
+ $checkout = $this->getCheckout();
231
+
232
+ $checkout->clear();
233
+
234
+ $quote = $this->getQuote();
235
+
236
+ // Check to see if we need to remove the quote
237
+ // if they aren't logged in then we will need to otherwise when they login the items won't match
238
+ $test_mode = Mage::app()->getRequest()->getParam('test_mode') == "true";
239
+
240
+ if ((!$test_mode && $quote->getId() != $original_quote_id)) {
241
+ $this->removeOldQuote($original_quote_id);
242
+ }
243
+
244
+ foreach ($quote->getItemsCollection() as $item) {
245
+ $item->isDeleted(true);
246
+ }
247
+
248
+ $quote->getBillingAddress();
249
+ $quote->getShippingAddress();
250
+ $quote->getPayment();
251
+ $quote->setCampaignerAbandonedDate(null);
252
+
253
+ $customer = $customer_session->getCustomer();
254
+ if ($customer) {
255
+ $quote->assignCustomer($customer);
256
+ }
257
+
258
+ $quote->save();
259
+ }
260
+
261
+ private function getQuote()
262
+ {
263
+ return Mage::getSingleton('checkout/session')->getQuote();
264
+ }
265
+
266
+ private function getCheckout()
267
+ {
268
+ return Mage::getSingleton('checkout/session');
269
+ }
270
+ }
app/code/community/Campaigner/Integration/controllers/Admin/AbandonedController.php ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Admin_AbandonedController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+ public function indexAction()
6
+ {
7
+ $this->loadLayout();
8
+
9
+ $this->getLayout()->getBlock('head')->setTitle($this->__('Campaigner Abandoned Carts'));
10
+ $this->_setActiveMenu('campaigner');
11
+ $this->renderLayout();
12
+ }
13
+
14
+ public function detailsAction()
15
+ {
16
+ $this->loadLayout();
17
+
18
+ $this->getLayout()->getBlock('head')->setTitle($this->__('Campaigner Abandoned Carts'));
19
+ $this->_setActiveMenu('campaigner');
20
+ $this->renderLayout();
21
+ }
22
+
23
+ public function gridAction()
24
+ {
25
+ $this->showGrid();
26
+ }
27
+
28
+ private function showGrid()
29
+ {
30
+ $this->loadLayout();
31
+ $this->getResponse()->setBody($this->getLayout()->createBlock('campaigner/adminhtml_abandoned_grid')->toHtml());
32
+ }
33
+
34
+ public function runAction()
35
+ {
36
+ $store_id = $this->getRequest()->getParam('store_id');
37
+
38
+ Mage::getSingleton('campaigner/abandoned_observer')->manualCartsProcessor($store_id);
39
+
40
+ $msg = "The Abandoned Cart process has been run";
41
+
42
+ if ($store_id) {
43
+ $msg .= " on store: " . Mage::helper('campaigner')->getFullStoreNameById($store_id);
44
+ }
45
+
46
+ $this->_getSession()->addSuccess(Mage::helper('adminhtml')->__($msg));
47
+ $this->_redirect('*/*/index');
48
+ }
49
+
50
+ public function sendAction()
51
+ {
52
+ try {
53
+ $id = $this->getRequest()->getParam('id');
54
+
55
+ if ($id == null) {
56
+ $this->_getSession()->addError(Mage::helper('adminhtml')->__("No Carts were specified."));
57
+ } else {
58
+ $id_list = array($id);
59
+ Mage::getSingleton('campaigner/abandoned_observer')->SendAbandonedCarts($id_list);
60
+ $this->_getSession()->addSuccess(Mage::helper('adminhtml')->__("Abandoned Cart has been sent."));
61
+ }
62
+ } catch (Exception $e) {
63
+ $this->_getSession()->addError($e->getMessage());
64
+ }
65
+ $this->_redirect('*/*/index');
66
+ }
67
+
68
+ public function massSendAction()
69
+ {
70
+ $params = array();
71
+ if ($this->getRequest()->isPost()) {
72
+ $params = $this->getRequest()->getPost();
73
+ }
74
+
75
+ $id_list = $params['id'];
76
+
77
+ if (!is_array($id_list)) {
78
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select at least one cart to send or resend.'));
79
+ } else {
80
+ try {
81
+ $cart_status = Mage::getSingleton('campaigner/abandoned_observer')->SendAbandonedCarts($id_list);
82
+
83
+ $success_count = 0;
84
+ $failure_count = 0;
85
+ foreach ($cart_status as $status) {
86
+ if ($status['success'] == false) {
87
+ $failure_count++;
88
+ } else {
89
+ $success_count++;
90
+ }
91
+ }
92
+
93
+ if ($success_count > 0) {
94
+ Mage::getSingleton('adminhtml/session')->addSuccess(
95
+ Mage::helper('adminhtml')->__('Total of %d carts(s) were sent.', $success_count));
96
+ }
97
+
98
+ if ($failure_count > 0) {
99
+ Mage::getSingleton('adminhtml/session')->addError(
100
+ Mage::helper('adminhtml')->__('Total of %d carts(s) failed to send.', $failure_count));
101
+ }
102
+ }
103
+ catch (Exception $e) {
104
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
105
+ }
106
+ }
107
+ $this->_redirect('*/*/index', Mage::helper('campaigner')->getUrlParams());
108
+ }
109
+ }
app/code/community/Campaigner/Integration/controllers/Admin/DiagnosticController.php ADDED
@@ -0,0 +1,452 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Admin_DiagnosticController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+ private $_logger = null;
6
+ private $_order = null;
7
+ private $_quote = null;
8
+ private $_result = array();
9
+
10
+ public function downloadAction()
11
+ {
12
+ $filename = $this->getRequest()->getParam('filename');
13
+
14
+ $output = $this->getRequest()->getParam('output');
15
+
16
+ $this->_prepareDownloadResponse($filename, $output);
17
+ }
18
+
19
+ public function ajaxAction()
20
+ {
21
+ $this->_logger = Mage::helper('campaigner/troubleshooting');
22
+ $this->_logger->turnOnDebug();
23
+
24
+ $method = $this->getRequest()->getParam('method');
25
+ $success = false;
26
+
27
+ switch ($method)
28
+ {
29
+ // Orders
30
+ case "order_last_items": $success = $this->lastOrderItems(); break;
31
+ case "order_related_items": $success = $this->relatedOrderItems(); break;
32
+ case "order_full": $success = $this->fullOrder(false); break;
33
+ case "order_full_request": $success = $this->fullOrder(); break;
34
+ case "order_custom_fields": $success = $this->customFields(); break;
35
+ case "tracking_info": $success = $this->trackingInfo(); break;
36
+
37
+ // Abandoned
38
+ case "abandoned_url": $success = $this->AbandonedUrl(); break;
39
+ case "abandoned_custom_fields": $success = $this->AbandonedCustomFields(); break;
40
+ case "abandoned_request": $success = $this->abandonedFull(); break;
41
+ case "abandoned_request_full": $success = $this->abandonedFull(false); break;
42
+ }
43
+
44
+ $this->_logger->turnOffDebug();
45
+
46
+ if ($success) {
47
+ $this->setSuccess($this->_output, $this->_logger->getDebugData());
48
+ }
49
+
50
+ $this->getResponse()->setBody(json_encode($this->_result));
51
+ }
52
+
53
+ private function getCss()
54
+ {
55
+ $css = "<style>
56
+
57
+ .diagnostic_table { border-collapse: collapse; }
58
+ .diagnostic_table tr td { border: solid 1px; padding: 4px; }
59
+ .diagnostic_table tr td:first-child { font-weight: bold; }
60
+
61
+ </style>";
62
+
63
+ return $css;
64
+ }
65
+
66
+ private function setSuccess($output, $details)
67
+ {
68
+ $this->_result['success'] = true;
69
+
70
+ if (is_array($details)) {
71
+ $this->_result['details'] = implode("<br />",$details) . "<br /><br />";
72
+ } else {
73
+ $this->_result['details'] = $details;
74
+ }
75
+
76
+ $this->_result['output'] = $this->getCss() . $output;
77
+
78
+ return true;
79
+ }
80
+
81
+ private function setFailure($message)
82
+ {
83
+ $this->_result['success'] = false;
84
+ $this->_result['error'] = true;
85
+
86
+ $this->_result['message'] = $message;
87
+
88
+ return false;
89
+ }
90
+
91
+ private function debug($data)
92
+ {
93
+ $this->_logger->debug($data);
94
+ }
95
+
96
+ private function debugHeader($data, $level = 2)
97
+ {
98
+ $this->_logger->debugHeader($data, $level);
99
+ }
100
+
101
+ private function getOrder()
102
+ {
103
+ if ($this->_order != null) {
104
+ return $this->_order;
105
+ }
106
+
107
+ $order_id = $this->getRequest()->getParam('item_id');
108
+
109
+ $this->_order = Mage::getModel('sales/order')->load($order_id);
110
+
111
+ if ($this->_order != null && !$this->_order->getId()) {
112
+ $this->_order = null;
113
+ } else {
114
+ Mage::app()->setCurrentStore($this->_order->getStoreId());
115
+ }
116
+
117
+ return $this->_order;
118
+ }
119
+
120
+ private function getQuote()
121
+ {
122
+ if ($this->_quote != null) {
123
+ return $this->_quote;
124
+ }
125
+
126
+ $quote_id = $this->getRequest()->getParam('item_id');
127
+ $store_id = $this->getRequest()->getParam('store_id');
128
+
129
+ $store = Mage::getModel('core/store')->load($store_id);
130
+
131
+ $this->_quote = Mage::getModel('sales/quote')->setStore($store)->load($quote_id);
132
+
133
+ if ($this->_quote != null && !$this->_quote->getId()) {
134
+ $this->_quote = null;
135
+ } else {
136
+ Mage::app()->setCurrentStore($store);
137
+ }
138
+
139
+ return $this->_quote;
140
+ }
141
+
142
+ private function decorateArray($array)
143
+ {
144
+ $output = "<table class='diagnostic_table'>";
145
+ $output .= "<tr>";
146
+ $keys = array_keys($array);
147
+
148
+ foreach ($keys as $key) {
149
+ $output .= "<th>{$key}</th>";
150
+ }
151
+
152
+ $output .= "</tr>";
153
+
154
+ foreach ($array as $row) {
155
+ $output .= "<tr>";
156
+
157
+ foreach ($row as $data) {
158
+ $output .= "<td>{$data}</td>";
159
+ }
160
+
161
+ $output .= "</tr>";
162
+ }
163
+
164
+ $output .= "</table>";
165
+
166
+ return $output;
167
+ }
168
+
169
+ private function arrayToTable($array)
170
+ {
171
+ $output = "<table class='diagnostic_table' cellspacing='0'>";
172
+
173
+ foreach ($array as $key => $value) {
174
+ $output .= "<tr><td>{$key}</td><td>{$value}</td></tr>";
175
+ }
176
+
177
+ return $output . "</table>";
178
+ }
179
+
180
+ private function getNumberedKeys($array)
181
+ {
182
+ $keys = array();
183
+
184
+ foreach ($array as $key => $value) {
185
+ if (strpos($key,"1") === false) {
186
+ return $keys;
187
+ }
188
+
189
+ $keys[] = substr($key,0,strlen($key) - 1);
190
+ }
191
+
192
+ return $keys;
193
+ }
194
+
195
+ private function numberedItemsDisplay($array)
196
+ {
197
+ $output = "";
198
+
199
+ $keys = $this->getNumberedKeys($array);
200
+
201
+ $first_key = $keys[0];
202
+
203
+ $count = 1;
204
+
205
+ while (isset($array["{$first_key}{$count}"])) {
206
+ $output .= "<h3>Item # {$count}</h3>";
207
+
208
+ $output .= "<table class='diagnostic_table' cellspacing='0'>";
209
+
210
+ foreach ($keys as $key) {
211
+ $output .= "<tr><td>{$key}</td><td>" . $array["{$key}{$count}"] . "</td></tr>";
212
+ }
213
+
214
+ $output .= "</table><br />";
215
+
216
+ $count++;
217
+ }
218
+
219
+ return $output;
220
+ }
221
+
222
+ private function lastOrderItems()
223
+ {
224
+ $order = $this->getOrder();
225
+
226
+ if ($order == null) {
227
+ return $this->setFailure("Order not found");
228
+ }
229
+
230
+ $this->debugHeader('Last Order Items');
231
+
232
+ $this->debug('Order #' . $order->getIncrementId());
233
+
234
+ $merge_vars = array();
235
+
236
+ $order_helper = Mage::helper('campaigner/order');
237
+
238
+ $merge_vars = $order_helper->getMergeOrderItems($order, $merge_vars);
239
+
240
+ $this->debug('');
241
+ $this->debugHeader('Latest Order Items',1);
242
+ $this->debug($merge_vars);
243
+
244
+ $this->debugHeader('Last Order Items Complete!');
245
+
246
+ $this->_output = "<h2>Order Items Diagnostic Results</h2>" . $this->numberedItemsDisplay($merge_vars, 3);
247
+
248
+ return true;
249
+ }
250
+
251
+ private function relatedOrderItems()
252
+ {
253
+ $order = $this->getOrder();
254
+
255
+ if ($order == null) {
256
+ return $this->setFailure("Order not found");
257
+ }
258
+
259
+ $this->debugHeader('Related Order Items');
260
+
261
+ $this->debug('Order #' . $order->getIncrementId());
262
+ $this->debug('');
263
+
264
+ $merge_vars = array();
265
+
266
+ $order_helper = Mage::helper('campaigner/order');
267
+
268
+ $merge_vars = $order_helper->getRelatedOrderItems($order, $merge_vars);
269
+
270
+ $this->debugHeader('Related Order Items',1);
271
+ $this->debug($merge_vars);
272
+
273
+ $this->debugHeader('Related Order Items Complete!');
274
+
275
+ $this->_output = "<h2>Related Items Diagnostic Results</h2>" . $this->numberedItemsDisplay($merge_vars, 3);
276
+
277
+ return true;
278
+ }
279
+
280
+ private function fullOrder($request_only = true)
281
+ {
282
+ $order = $this->getOrder();
283
+
284
+ if ($order == null) {
285
+ return $this->setFailure("Order not found");
286
+ }
287
+
288
+ $customer = Mage::helper('campaigner/order')->getOrderCustomer($order);
289
+
290
+ $merge_vars = Mage::helper('campaigner/order')->getMergeVars($customer);
291
+
292
+ $merge_vars = Mage::helper('campaigner/order')->processOrderItems($order, $merge_vars);
293
+
294
+ if ($request_only) {
295
+ $this->_logger->setDebugExecuteMode('request_only');
296
+ } else {
297
+ $this->_logger->setDebugExecuteMode('full');
298
+ }
299
+
300
+ Mage::getSingleton('campaigner/wrapper_orders')->addSubscriberOrder($order->getCustomerEmail(), $order, $merge_vars);
301
+
302
+ $this->_output = "<h2>Full Order Diagnostic Results</h2><h3>Request Xml</h3><pre>" . htmlentities($this->_logger->formatXml($this->_logger->getDebugRequest())) . "</pre>";
303
+
304
+ if (!$request_only) {
305
+ $this->_output .= "<br /><h3>Response Xml</h3><pre>" . htmlentities($this->_logger->formatXml($this->_logger->getDebugResponse())) . "</pre>";
306
+ }
307
+
308
+ return true;
309
+ }
310
+
311
+ private function customFields()
312
+ {
313
+ $order = $this->getOrder();
314
+
315
+ if ($order == null) {
316
+ return $this->setFailure("Order not found");
317
+ }
318
+
319
+ $this->debugHeader('Custom Fields Diagnostic Starting');
320
+
321
+ $customer = Mage::helper('campaigner/order')->getOrderCustomer($order);
322
+
323
+ $this->debugHeader('Customer Related Merge Vars',1);
324
+
325
+ $customer_vars = Mage::helper('campaigner/order')->getMergeVars($customer);
326
+
327
+ $merge_vars = Mage::helper('campaigner/order')->processOrderItems($order, $merge_vars);
328
+
329
+ $this->_output = "<h2>Custom Fields Diagnostic Results</h2><h3>Customer Fields</h3>" . $this->arrayToTable($customer_vars);
330
+ $this->_output .= "<br /><h3>Order Fields</h3>" . $this->arrayToTable($merge_vars);
331
+
332
+ return true;
333
+ }
334
+
335
+ private function abandonedUrl()
336
+ {
337
+ $quote = $this->getQuote();
338
+
339
+ if ($quote == null) {
340
+ return $this->setFailure("Quote not found");
341
+ }
342
+
343
+ $this->debugHeader('Abandoned URL');
344
+
345
+ $url = Mage::helper('campaigner/abandoned')->getAbandonedUrl($quote);
346
+
347
+ $this->_output = "<h2>Abandoned Cart Url (Restore Cart)</h2><p>Click on the link to test it (opens in a new window and won't replace customer cart data)</p>URL: <a target='_blank' href='{$url}&test_mode=true'>{$url}</a>";
348
+
349
+ return true;
350
+ }
351
+
352
+ private function abandonedCustomFields()
353
+ {
354
+ $quote = $this->getQuote();
355
+
356
+ if ($quote == null) {
357
+ return $this->setFailure("Quote not found");
358
+ }
359
+
360
+ $this->debugHeader('Custom Fields Diagnostic Starting');
361
+
362
+ $abandonedDate = $quote->getUpdatedAt();
363
+
364
+ $merge_vars = Mage::helper('campaigner')->getQuoteMergeVars($quote);
365
+
366
+ $merge_vars['AbandonedDate'] = $abandonedDate;
367
+ $merge_vars['AbandonedUrl'] = Mage::helper('campaigner/abandoned')->getAbandonedUrl($quote);
368
+
369
+ // Setup sequence for this store
370
+ Mage::helper('campaigner/abandoned')->setupSequence();
371
+
372
+ Mage::helper('campaigner/abandoned')->addSequence($merge_vars);
373
+
374
+ $merge_vars = Mage::helper('campaigner/order')->getMergeOrderItems($quote, $merge_vars, "AB");
375
+
376
+ $this->_output = "<h2>Custom Fields Diagnostic Results</h2>";
377
+ $this->_output .= "<br /><h3>Fields</h3>" . $this->arrayToTable($merge_vars);
378
+
379
+ return true;
380
+ }
381
+
382
+ private function getQuoteEmail($quote)
383
+ {
384
+ $abandoned_cart = Mage::helper('campaigner/diagnostic')->getAbandonedCart($quote->getId());
385
+
386
+ return $abandoned_cart->getEmail();
387
+ }
388
+
389
+ private function abandonedFull($request_only = true)
390
+ {
391
+ $quote = $this->getQuote();
392
+
393
+ if ($quote == null) {
394
+ return $this->setFailure("Quote not found");
395
+ }
396
+
397
+ $abandonedDate = $quote->getUpdatedAt();
398
+
399
+ $email = $quote->getCustomerEmail();
400
+
401
+ if ($email == null) {
402
+ $email = $this->getQuoteEmail($quote);
403
+ }
404
+
405
+ $merge_vars = Mage::helper('campaigner')->getQuoteMergeVars($quote);
406
+
407
+ $merge_vars['AbandonedDate'] = $abandonedDate;
408
+ $merge_vars['AbandonedUrl'] = Mage::helper('campaigner/abandoned')->getAbandonedUrl($quote);
409
+
410
+ // Setup sequence for this store
411
+ Mage::helper('campaigner/abandoned')->setupSequence();
412
+
413
+ Mage::helper('campaigner/abandoned')->addSequence($merge_vars);
414
+
415
+ $merge_vars = Mage::helper('campaigner/order')->getMergeOrderItems($quote, $merge_vars, "AB");
416
+
417
+ $this->debug("!!Merge Vars!!");
418
+ $this->debug($merge_vars);
419
+
420
+ $contactData = Mage::getSingleton('campaigner/wrapper_abandoned')->getOneCart($email,$merge_vars);
421
+
422
+ if ($request_only) {
423
+ $this->_logger->setDebugExecuteMode('request_only');
424
+ } else {
425
+ $this->_logger->setDebugExecuteMode('full');
426
+ }
427
+
428
+ try {
429
+ Mage::getSingleton('campaigner/wrapper_abandoned')->send($contactData);
430
+ } catch (Campaigner_Integration_Model_Wrapper_Exception $e) {
431
+ $details = $e->getDetails();
432
+
433
+ $this->_output = "<h2>Abandoned Cart</h2><h3>Request</h3><pre>" . $this->_logger->safeDump($this->_logger->getDebugRequest()) . "</pre>";
434
+
435
+ $this->_output .= "<h2>Error: " . $e->getMessage() . "</h2><p>" . $this->_logger->safeDump($details) . "</p>";
436
+
437
+ return true;
438
+ }
439
+
440
+ $this->_output = "<h2>Abandoned Cart</h2><h3>Request</h3><pre>" . $this->_logger->safeDump($this->_logger->getDebugRequest()) . "</pre>";
441
+
442
+ if (!$request_only) {
443
+ $this->_output .= "<br /><h3>Response</h3><pre>" . $this->_logger->safeDump($this->_logger->getDebugResponse()) . "</pre>";
444
+ }
445
+ return true;
446
+ }
447
+
448
+ private function trackingInfo()
449
+ {
450
+ return true;
451
+ }
452
+ }
app/code/community/Campaigner/Integration/controllers/Admin/LatestController.php ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Admin_LatestController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+ public function indexAction()
6
+ {
7
+ $this->loadLayout();
8
+
9
+ $this->getLayout()->getBlock('head')->setTitle($this->__('Campaigner Latest Orders'));
10
+ $this->_setActiveMenu('campaigner');
11
+ $this->renderLayout();
12
+ }
13
+
14
+ public function detailsAction()
15
+ {
16
+ $this->loadLayout();
17
+
18
+ $this->getLayout()->getBlock('head')->setTitle($this->__('Campaigner Latest Orders'));
19
+ $this->_setActiveMenu('campaigner');
20
+ $this->renderLayout();
21
+ }
22
+
23
+ public function gridAction()
24
+ {
25
+ $this->showGrid();
26
+ }
27
+
28
+ private function showGrid()
29
+ {
30
+ $this->loadLayout();
31
+ $this->getResponse()->setBody($this->getLayout()->createBlock('campaigner/adminhtml_latest_grid')->toHtml());
32
+ }
33
+
34
+ public function runAction()
35
+ {
36
+ $store_id = $this->getRequest()->getParam('store_id');
37
+
38
+ Mage::getSingleton('campaigner/order_observer')->manualLatestProcessor($store_id);
39
+
40
+ $msg = "The Latest Order process has been run";
41
+
42
+ if ($store_id) {
43
+ $msg .= " on store: " . Mage::helper('campaigner')->getFullStoreNameById($store_id);
44
+ }
45
+
46
+ $this->_getSession()->addSuccess(Mage::helper('adminhtml')->__($msg));
47
+ $this->_redirect('*/*/index');
48
+ }
49
+
50
+ public function sendAction()
51
+ {
52
+ try {
53
+ $id = $this->getRequest()->getParam('id');
54
+
55
+ if ($id == null) {
56
+ $this->_getSession()->addError(Mage::helper('adminhtml')->__("No Orders were specified."));
57
+ } else {
58
+ $id_list = array($id);
59
+ Mage::getSingleton('campaigner/order_observer')->SendLatestOrders($id_list);
60
+ $this->_getSession()->addSuccess(Mage::helper('adminhtml')->__("Latest Order has been sent."));
61
+ }
62
+ } catch (Exception $e) {
63
+ $this->_getSession()->addError($e->getMessage());
64
+ }
65
+ $this->_redirect('*/*/index');
66
+ }
67
+
68
+ public function massSendAction()
69
+ {
70
+ $params = array();
71
+ if ($this->getRequest()->isPost()) {
72
+ $params = $this->getRequest()->getPost();
73
+ }
74
+
75
+ $id_list = $params['id'];
76
+
77
+ if (!is_array($id_list)) {
78
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select at least one order to send or resend.'));
79
+ } else {
80
+ try {
81
+ $order_status = Mage::getSingleton('campaigner/order_observer')->SendLatestOrders($id_list);
82
+
83
+ $success_count = 0;
84
+ $failure_count = 0;
85
+ foreach ($order_status as $status) {
86
+ if ($status['success'] == false) {
87
+ $failure_count++;
88
+ } else {
89
+ $success_count++;
90
+ }
91
+ }
92
+
93
+ if ($success_count > 0) {
94
+ Mage::getSingleton('adminhtml/session')->addSuccess(
95
+ Mage::helper('adminhtml')->__('Total of %d order(s) were sent.', $success_count));
96
+ }
97
+
98
+ if ($failure_count > 0) {
99
+ Mage::getSingleton('adminhtml/session')->addError(
100
+ Mage::helper('adminhtml')->__('Total of %d order(s) failed to send.', $failure_count));
101
+ }
102
+ }
103
+ catch (Exception $e) {
104
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
105
+ }
106
+ }
107
+ $this->_redirect('*/*/index', Mage::helper('campaigner')->getUrlParams());
108
+ }
109
+ }
app/code/community/Campaigner/Integration/controllers/Admin/TroubleshootingController.php ADDED
@@ -0,0 +1,300 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_Admin_TroubleshootingController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+ private $_output = array();
6
+ private $_config = null;
7
+
8
+ public function indexAction()
9
+ {
10
+ $this->loadLayout();
11
+ $this->getLayout()->getBlock('head')->setTitle($this->__('Campaigner Troubleshooting'));
12
+ $this->_setActiveMenu('campaigner');
13
+ $this->renderLayout();
14
+ }
15
+
16
+ public function testSmtpAction()
17
+ {
18
+ $username = $this->getRequest()->getParam('username');
19
+ $password = $this->getRequest()->getParam('password');
20
+ $email = $this->getRequest()->getParam('email');
21
+ $port = $this->getRequest()->getParam('port');
22
+ $encryption = $this->getRequest()->getParam('encryption');
23
+ $storeId = $this->getRequest()->getParam('store_id');
24
+
25
+ $response = $this->sendTestEmail($email, $port, $encryption, $username, $password, $storeId);
26
+
27
+ $result = array();
28
+
29
+ if ($response === true) {
30
+ $result['success'] = true;
31
+ } else {
32
+ $result['success'] = false;
33
+ $result['message'] = $response;
34
+ }
35
+ $this->getResponse()->setBody(json_encode($result));
36
+ }
37
+
38
+ private function sendTestEmailLegacy($email,$port,$encryption, $username, $password)
39
+ {
40
+ try {
41
+ $host = Mage::getStoreConfig('system/smtp/campaigner_smtp_server');
42
+
43
+ $config = array(
44
+ 'port' => $port,
45
+ 'auth' => 'plain',
46
+ 'username' => $username,
47
+ 'password' => $password
48
+ );
49
+
50
+ if ($encryption != 'none') {
51
+ $config['ssl'] = $encryption;
52
+ }
53
+
54
+ $transport = new Zend_Mail_Transport_Smtp($host, $config);
55
+
56
+ Zend_Mail::setDefaultTransport($transport);
57
+
58
+ $mail = new Zend_Mail('utf-8');
59
+
60
+ $mail->addTo($email);
61
+ $mail->setBodyText("This is a test of the Campaigner Relay");
62
+
63
+ $mail->setSubject("Campaigner Relay Test");
64
+ $mail->setFrom($email, 'Relay Test');
65
+
66
+ $mail->send();
67
+ }
68
+ catch (Exception $e) {
69
+ return $e->getMessage();
70
+ }
71
+
72
+ return true;
73
+ }
74
+
75
+ private function sendTestEmail($email, $port, $encryption, $username, $password, $storeId)
76
+ {
77
+ try {
78
+ Mage::register("relay_test",true);
79
+ Mage::register("relay_port",$port);
80
+ Mage::register("relay_encryption", $encryption);
81
+ Mage::register("relay_username", $username);
82
+ Mage::register("relay_password", $password);
83
+ $mailer = Mage::getModel('core/email_template_mailer');
84
+
85
+ if (!$mailer) {
86
+ return $this->sendTestEmailLegacy($email, $port, $encryption, $username, $password);
87
+ }
88
+ $emailInfo = Mage::getModel('core/email_info');
89
+ if (!$emailInfo) {
90
+ throw Exception("Missing Email Component. Magento version may be too old. Please Contact Campaigner");
91
+ } else {
92
+ $emailInfo->addTo($email, 'Relay Test');
93
+
94
+ $mailer->addEmailInfo($emailInfo);
95
+ }
96
+
97
+ // Set all required params and send emails
98
+ $mailer->setSender(Mage::getStoreConfig('sales_email/order/identity', $storeId));
99
+ $mailer->setStoreId($storeId);
100
+ $mailer->setTemplateId('campaigner_relay_test');
101
+
102
+ $mailer->send();
103
+ }
104
+ catch (Exception $e) {
105
+ return $e->getMessage();
106
+ }
107
+
108
+ return true;
109
+ }
110
+
111
+ public function validateAction()
112
+ {
113
+ $api_username = $this->getRequest()->getParam('api_username');
114
+ $api_password = $this->getRequest()->getParam('api_password');
115
+
116
+ Mage::register('validation_mode',true);
117
+
118
+ $result = Mage::helper('campaigner/troubleshooting')->validateCredentials($api_username, $api_password);
119
+
120
+ $this->getResponse()->setBody(json_encode($result));
121
+ }
122
+
123
+ private function getLogFile()
124
+ {
125
+ $empty = false;
126
+ $too_large = false;
127
+ $file_size = Mage::helper('campaigner/troubleshooting')->getLogFileSize();
128
+
129
+ if ($file_size == 0) {
130
+ $empty = true;
131
+ } else {
132
+ $too_large = Mage::helper('campaigner/troubleshooting')->isLogFileTooLarge();
133
+ }
134
+
135
+ $max_size = Mage::helper('campaigner')->formatSize(Mage::helper('campaigner/troubleshooting')->getMaxLogFileSize());
136
+
137
+ $result = array(
138
+ 'success' => true,
139
+ 'empty' => $empty,
140
+ 'too_large' => $too_large,
141
+ 'max_size' => $max_size,
142
+ 'contents' => utf8_encode(Mage::helper('campaigner/troubleshooting')->getLogFileContents()));
143
+ return $result;
144
+ }
145
+
146
+ public function ajaxAction()
147
+ {
148
+ $method = $this->getRequest()->getParam('method');
149
+
150
+ $result = array('success' => false);
151
+
152
+ switch ($method)
153
+ {
154
+ case "status": $result = $this->getStatus(); break;
155
+ case "log_refresh": $result = $this->getLogFile(); break;
156
+ case "test_logging": $result = $this->testLogging(); break;
157
+ case "erase_log": $result = $this->eraseLog(); break;
158
+ }
159
+
160
+ $this->getResponse()->setBody(json_encode($result));
161
+
162
+ return $result;
163
+ }
164
+
165
+ private function eraseLog()
166
+ {
167
+ Mage::helper('campaigner/troubleshooting')->eraseLog();
168
+
169
+ return $this->getLogFile();
170
+ }
171
+
172
+ private function testLogging()
173
+ {
174
+ Mage::helper('campaigner/troubleshooting')->forceLog('======================= LOG TEST =======================');
175
+
176
+ return $this->getLogFile();
177
+ }
178
+
179
+ private function getStatus()
180
+ {
181
+ $status = Mage::helper('campaigner/troubleshooting')->getStatus();
182
+
183
+ $result = array();
184
+ $result['success'] = true;
185
+ $result['status'] = $status;
186
+
187
+ return $result;
188
+ }
189
+
190
+ public function sendAction()
191
+ {
192
+ $params = $this->getRequest()->getParams();
193
+
194
+ $customer = array();
195
+
196
+ $customer['Customer Name'] = $params['customer_name'];
197
+ $customer['Email'] = $params['customer_email'];
198
+
199
+ if ($params['customer_company'] != "") {
200
+ $customer['Company'] = $params['customer_company'];
201
+ }
202
+
203
+ $customer['Comments'] = $params['customer_comments'];
204
+
205
+ $message = Mage::helper('campaigner/troubleshooting')->getReport($customer);
206
+
207
+ $to = Mage::helper('campaigner')->troubleConfig('email');
208
+ $subject = Mage::helper('campaigner')->troubleConfig('subject');
209
+ $from = $params['customer_email'];
210
+
211
+ $headers = "From: {$from}\r\n";
212
+ $headers .= "Content-type: text/html\r\n";
213
+
214
+ // now lets send the email.
215
+ $sent = mail($to, $subject, $message, $headers);
216
+
217
+ if ($sent)
218
+ {
219
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('campaigner')->__('Troubleshooting Report was sent to Campaigner'));
220
+
221
+ $this->_redirect('adminhtml/system_config/edit/',array('section' => 'campaigner'));
222
+ }
223
+ else
224
+ {
225
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('campaigner')->__('Failed to send Report Email'));
226
+
227
+ $this->_redirect('campaigner_dashboard/admin_troubleshooting/');
228
+ }
229
+ }
230
+
231
+ public function downloadAction()
232
+ {
233
+ $output = Mage::helper('campaigner/troubleshooting')->getReport();
234
+
235
+ $this->_prepareDownloadResponse(Mage::helper('campaigner')->troubleConfig('report_file'), $output);
236
+ }
237
+
238
+ private function updateConfig($path, $value)
239
+ {
240
+ $this->_config->saveConfig("campaigner/troubleshooting/{$path}",$value,"default",0);
241
+ }
242
+
243
+ public function saveAction()
244
+ {
245
+ $params = $this->getRequest()->getParams();
246
+
247
+ $this->_config = Mage::getConfig();
248
+
249
+ $enabled = $params['logging_enabled'];
250
+
251
+ if ($enabled == "yes") {
252
+ $this->updateConfig('logging_enabled',1);
253
+
254
+ $date_format = Campaigner_Integration_Helper_Data::DATE_FORMAT;
255
+ $start_date = date($date_format, Mage::getModel('core/date')->gmtTimestamp());
256
+
257
+ $this->updateConfig("logging_start_date",$start_date);
258
+
259
+ $advanced_enabled = $params['logging_advanced_enabled'];
260
+
261
+ if ($advanced_enabled) {
262
+ $this->updateConfig("logging_advanced_enabled", 1);
263
+
264
+ $logging_stores = $params['logging_stores'];
265
+
266
+ if ($logging_stores == "selected") {
267
+ if (isset($params['logging_stores_selected'])) {
268
+ $this->updateConfig("logging_stores_selected", implode(",",$params['logging_stores_selected']));
269
+ }
270
+ }
271
+
272
+ $this->updateConfig("logging_stores", $logging_stores);
273
+
274
+ $logging_areas = $params['logging_areas'];
275
+
276
+ if ($logging_areas == "selected") {
277
+ if (isset($params['logging_areas_selected'])) {
278
+ $this->updateConfig("logging_areas_selected", implode(",",$params['logging_areas_selected']));
279
+ }
280
+ }
281
+
282
+ $this->updateConfig("logging_areas", $logging_areas);
283
+ $this->updateConfig("logging_duration", $params['logging_duration']);
284
+ } else {
285
+ $this->updateConfig("logging_duration", 10);
286
+ $this->updateConfig("logging_advanced_enabled", 0);
287
+ }
288
+ } else {
289
+ $this->updateConfig('logging_enabled',0);
290
+ }
291
+
292
+ $this->updateConfig('diagnostic_enabled',$params['diagnostic_enabled']);
293
+
294
+ $this->_config->cleanCache();
295
+
296
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('campaigner')->__('Troubleshooting settings updated!'));
297
+
298
+ $this->_redirect("*/*/index",Mage::helper('campaigner')->getAdminUrlParams(array('tab' => 'troubleshooting_view_tabs_trouble_settings')));
299
+ }
300
+ }
app/code/community/Campaigner/Integration/controllers/CaptureController.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_CaptureController extends Mage_Core_Controller_Front_Action
4
+ {
5
+ public function indexAction()
6
+ {
7
+ $result = array();
8
+
9
+ if (!$this->getRequest()->isXmlHttpRequest()) {
10
+ $this->_redirect('*/*/');
11
+ return;
12
+ }
13
+
14
+ $email = Mage::app()->getRequest()->getParam('email');
15
+
16
+ if (!Zend_Validate::is($email, 'EmailAddress')) {
17
+ $result['success'] = false;
18
+ $result['message'] = "Invalid Email";
19
+ } else {
20
+ Mage::getSingleton('campaigner/session')->init($email);
21
+ $result['success'] = true;
22
+ }
23
+
24
+ $this->getResponse()->setBody(json_encode($result));
25
+ }
26
+ }
app/code/community/Campaigner/Integration/controllers/Customer/AccountController.php ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Campaigner_Integration_Customer_AccountController extends Campaigner_Integration_Controller_Front_Abstract
3
+ {
4
+ /**
5
+ * Action predispatch
6
+ *
7
+ * Check customer authentication for some actions
8
+ */
9
+ public function preDispatch()
10
+ {
11
+ parent::preDispatch();
12
+
13
+ if (!$this->getRequest()->isDispatched()) {
14
+ return;
15
+ }
16
+
17
+ if (!$this->_getCustomerSession()->authenticate($this)) {
18
+ $this->setFlag('', 'no-dispatch', true);
19
+ }
20
+ }
21
+
22
+ /**
23
+ * Retrieve customer session model object
24
+ *
25
+ * @return Mage_Customer_Model_Session
26
+ */
27
+ protected function _getCustomerSession()
28
+ {
29
+ return Mage::getSingleton('customer/session');
30
+ }
31
+
32
+ /**
33
+ * Display data
34
+ */
35
+ public function indexAction()
36
+ {
37
+ $this->loadLayout();
38
+ $this->_initLayoutMessages('customer/session');
39
+
40
+ $this->getLayout()->getBlock('head')->setTitle($this->__('Newsletter Subscription'));
41
+ $this->renderLayout();
42
+ }
43
+
44
+ public function resubscribeAction()
45
+ {
46
+ $session = Mage::getSingleton('customer/session');
47
+
48
+ try {
49
+ $customer = $this->_getCustomerSession()->getCustomer();
50
+
51
+ $result = Mage::getSingleton("campaigner/wrapper_subscribers")->resubscribeContact($customer->getEmail());
52
+
53
+ $campaigner_session = Mage::getSingleton('campaigner/session')->init();
54
+
55
+ $campaigner_session->setStatus("Subscribed");
56
+ $campaigner_session->save();
57
+
58
+ $this->_getCustomerSession()->addSuccess("Thank you! You are now eligible to receive newsletter emails.");
59
+
60
+ } catch (Exception $e) {
61
+ $this->_logException($e);
62
+ $this->_getCustomerSession()->addError("Unable to update your preferences. Please try again at a later time.");
63
+ }
64
+
65
+ $this->_redirectReferer();
66
+ }
67
+
68
+ public function saveadditionalAction()
69
+ {
70
+ $this->_setLogArea(Campaigner_Integration_Helper_Troubleshooting::NEWSLETTER);
71
+ $this->_log('Save Additional Start');
72
+
73
+ $arguments = array();
74
+
75
+ if (Mage::app()->getStore()->isCurrentlySecure()) {
76
+ $arguments['_secure'] = true;
77
+ }
78
+
79
+ $session = Mage::getSingleton('customer/session');
80
+
81
+ if ($this->getRequest()->isPost()) {
82
+ $add = array();
83
+ $remove = array();
84
+
85
+ foreach ($this->getRequest()->getPost("lists") as $list) {
86
+ if ($this->getRequest()->getPost($list)) {
87
+ $add[] = $list;
88
+ } else {
89
+ $remove[] = $list;
90
+ }
91
+ }
92
+
93
+ $customer = Mage::helper('customer')->getCustomer();
94
+
95
+ try {
96
+ $result = Mage::getSingleton('campaigner/wrapper_subscribers')->updateSubscriptions($customer, $add, $remove);
97
+ $session->addSuccess('Newsletter Subscriptions updated');
98
+ } catch (Exception $e) {
99
+ $this->_logException($e);
100
+ $session->addError('Failed to update subscriptions');
101
+ }
102
+ }
103
+
104
+ $this->_redirect('*/*/index', $arguments);
105
+ }
106
+ }
app/code/community/Campaigner/Integration/controllers/SignupController.php ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Campaigner_Integration_SignupController extends campaigner_Integration_Controller_Front_Abstract
4
+ {
5
+ private $_test_mode = false;
6
+ private $_signup_width = 0;
7
+ private $_signup_height = 0;
8
+ private $_signup_url = "";
9
+ private $_signup_delay = 0;
10
+ private $_signup_opacity = 0;
11
+
12
+ private $_active = false;
13
+
14
+ public function checkAction()
15
+ {
16
+ $result = array();
17
+ try {
18
+ if ($this->canShow()) {
19
+ $result['can_show'] = true;
20
+ $result['html_content'] = $this->getSignupHtml();
21
+ } else {
22
+ $result['can_show'] = false;
23
+ }
24
+ } catch (Exception $e) {
25
+ Mage::logException($e);
26
+ $result['can_show'] = false;
27
+ $result['error'] = $e->getMessage();
28
+ }
29
+
30
+ $result['test'] = Mage::helper('campaigner')->isSignupTest();
31
+ $this->getResponse()->setBody(json_encode($result));
32
+ }
33
+
34
+ private function canShow()
35
+ {
36
+ if (Mage::helper('campaigner')->isSignupTest()) {
37
+ $request = Mage::app()->getRequest();
38
+
39
+ $this->_width = $request->getParam('width');
40
+ $this->_height = $request->getParam('height');
41
+ $this->_url = $request->getParam('url');
42
+ $this->_opacity = $request->getParam('opacity');
43
+ } else if (!Mage::helper('campaigner')->canShowSignup()) {
44
+ return false;
45
+ }else {
46
+ $this->_width = Mage::helper('campaigner')->config('signup_width');
47
+ $this->_height = Mage::helper('campaigner')->config('signup_height');
48
+ $this->_url = Mage::helper('campaigner')->config('signup_url');
49
+ $this->_opacity = Mage::helper('campaigner')->config('signup_opacity');
50
+ }
51
+
52
+ if ($this->_width == "" || $this->_height == "" || $this->_url == "") {
53
+ return false;
54
+ }
55
+
56
+ return true;
57
+ }
58
+
59
+ private function getSignupHtml()
60
+ {
61
+ $html = "<style type='text/css'>
62
+ #campaigner_signup_background
63
+ {
64
+ background:rgb(0,0,0);
65
+ background: transparent\9;
66
+ background:rgba(0,0,0,{$this->getSignupOpacity()});
67
+ filter:progid:DXImageTransform.Microsoft.gradient(startColorstr={$this->getSignupOpacityHex()},endColorstr={$this->getSignupOpacityHex()});
68
+ zoom: 1;
69
+ }
70
+ .div:nth-child(n) {
71
+ filter: none;
72
+ }
73
+ </style>
74
+
75
+ <div id='campaigner_signup_background'>
76
+ <div id='campaigner_signup' style='width: {$this->_width}px; height: {$this->_height}px;'>
77
+ <a id='campaigner_signup_close' href='#' onclick='return closeSignup();'></a>
78
+ <iframe frameborder='0' src='{$this->_url}' id='camp_form' style='width: 100%; height: 100%;'></iframe>
79
+ </div>
80
+ </div>";
81
+
82
+ return $html;
83
+ }
84
+
85
+ private function getSignupOpacity()
86
+ {
87
+ return ((int)$this->_opacity) / 100;
88
+ }
89
+
90
+ private function getSignupOpacityHex()
91
+ {
92
+ $opacity = $this->getSignupOpacity();
93
+
94
+ $hex_opacity = dechex(255 * $opacity);
95
+
96
+ return "#{$hex_opacity}000000";
97
+ }
98
+ }
app/code/community/Campaigner/Integration/etc/adminhtml.xml ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <menu>
4
+ <campaigner module='campaigner'>
5
+ <title>Campaigner</title>
6
+ <sort_order>80</sort_order>
7
+ <children>
8
+ <campaigner_abandoned module='campaigner'>
9
+ <title>Abandoned Carts</title>
10
+ <sort_order>100</sort_order>
11
+ <action>campaigner_dashboard/admin_abandoned</action>
12
+ </campaigner_abandoned>
13
+ <campaigner_latest module='campaigner'>
14
+ <title>Latest Orders</title>
15
+ <sort_order>105</sort_order>
16
+ <action>campaigner_dashboard/admin_latest</action>
17
+ </campaigner_latest>
18
+ <campaigner_troubleshooting module='campaigner'>
19
+ <title>Troubleshooting</title>
20
+ <sort_order>110</sort_order>
21
+ <action>campaigner_dashboard/admin_troubleshooting</action>
22
+ </campaigner_troubleshooting>
23
+ <campaigner_config module='campaigner'>
24
+ <title>Configuration</title>
25
+ <sort_order>1000</sort_order>
26
+ <action>adminhtml/system_config/edit/section/campaigner</action>
27
+ </campaigner_config>
28
+ </children>
29
+ </campaigner>
30
+ </menu>
31
+ <acl>
32
+ <resources>
33
+ <admin>
34
+ <children>
35
+ <system>
36
+ <children>
37
+ <config>
38
+ <children>
39
+ <campaigner translate="title" module="campaigner">
40
+ <title>Campaigner Configuration</title>
41
+ </campaigner>
42
+ </children>
43
+ </config>
44
+ </children>
45
+ </system>
46
+ </children>
47
+ </admin>
48
+ </resources>
49
+ </acl>
50
+ <translate>
51
+ <modules>
52
+ <Campaigner_Integration>
53
+ <files>
54
+ <default>Campaigner_Integration.csv</default>
55
+ </files>
56
+ </Campaigner_Integration>
57
+ </modules>
58
+ </translate>
59
+ </config>
app/code/community/Campaigner/Integration/etc/config.xml ADDED
@@ -0,0 +1,351 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Campaigner_Integration>
5
+ <version>1.0.1</version>
6
+ </Campaigner_Integration>
7
+ </modules>
8
+ <global>
9
+ <events>
10
+ <wishlist_product_add_after>
11
+ <observers>
12
+ <campaigner_wishlist_product_add_after_observer>
13
+ <class>campaigner/observer</class>
14
+ <method>onWishlistProductAddAfter</method>
15
+ </campaigner_wishlist_product_add_after_observer>
16
+ </observers>
17
+ </wishlist_product_add_after>
18
+ <newsletter_subscriber_save_before>
19
+ <observers>
20
+ <campaigner_subscribe_observer>
21
+ <class>campaigner/newsletter_observer</class>
22
+ <method>handleSubscriber</method>
23
+ </campaigner_subscribe_observer>
24
+ </observers>
25
+ </newsletter_subscriber_save_before>
26
+ <newsletter_subscriber_delete_after>
27
+ <observers>
28
+ <campaigner_subscribe_delete_observer>
29
+ <class>campaigner/newsletter_observer</class>
30
+ <method>handleSubscriberDeletion</method>
31
+ </campaigner_subscribe_delete_observer>
32
+ </observers>
33
+ </newsletter_subscriber_delete_after>
34
+ <sales_order_save_after>
35
+ <observers>
36
+ <campaigner_order_save_after>
37
+ <class>campaigner/order_observer</class>
38
+ <method>salesOrderSaveAfter</method>
39
+ </campaigner_order_save_after>
40
+ </observers>
41
+ </sales_order_save_after>
42
+ </events>
43
+ <models>
44
+ <campaigner>
45
+ <class>Campaigner_Integration_Model</class>
46
+ <resourceModel>campaigner_mysql4</resourceModel>
47
+ </campaigner>
48
+ <campaigner_mysql4>
49
+ <class>Campaigner_Integration_Model_Mysql4</class>
50
+ <entities>
51
+ <abandoned>
52
+ <table>campaigner_abandoned_cart</table>
53
+ </abandoned>
54
+ <order>
55
+ <table>campaigner_order</table>
56
+ </order>
57
+ <latest_order>
58
+ <table>campaigner_latest_order</table>
59
+ </latest_order>
60
+ <session>
61
+ <table>campaigner_session</table>
62
+ </session>
63
+ <action_list>
64
+ <table>campaigner_action_list</table>
65
+ </action_list>
66
+ </entities>
67
+ </campaigner_mysql4>
68
+ <core>
69
+ <rewrite>
70
+ <email_template>Campaigner_Integration_Model_Email_Template</email_template>
71
+ </rewrite>
72
+ <rewrite>
73
+ <email_queue>Campaigner_Integration_Model_Email_Queue</email_queue>
74
+ </rewrite>
75
+ </core>
76
+ </models>
77
+ <template>
78
+ <email>
79
+ <campaigner_relay_test translate="label" module="campaigner_integration">
80
+ <label>Relay Test</label>
81
+ <file>campaigner_relay_test.html</file>
82
+ <type>html</type>
83
+ </campaigner_relay_test>
84
+ </email>
85
+ </template>
86
+ <resources>
87
+ <campaigner_setup>
88
+ <setup>
89
+ <module>Campaigner_Integration</module>
90
+ <class>Campaigner_Integration_Model_Resource_Setup</class>
91
+ </setup>
92
+ <connection>
93
+ <use>core_setup</use>
94
+ </connection>
95
+ </campaigner_setup>
96
+ <campaigner_write>
97
+ <connection>
98
+ <use>core_write</use>
99
+ </connection>
100
+ </campaigner_write>
101
+ <campaigner_read>
102
+ <connection>
103
+ <use>core_read</use>
104
+ </connection>
105
+ </campaigner_read>
106
+ </resources>
107
+ <blocks>
108
+ <campaigner>
109
+ <class>Campaigner_Integration_Block</class>
110
+ </campaigner>
111
+ </blocks>
112
+ <helpers>
113
+ <campaigner>
114
+ <class>Campaigner_Integration_Helper</class>
115
+ </campaigner>
116
+ </helpers>
117
+ </global>
118
+ <frontend>
119
+ <translate>
120
+ <modules>
121
+ <Campaigner_Integration>
122
+ <files>
123
+ <default>Campaigner_Integration.csv</default>
124
+ </files>
125
+ </Campaigner_Integration>
126
+ </modules>
127
+ </translate>
128
+ <routers>
129
+ <campaigner>
130
+ <use>standard</use>
131
+ <args>
132
+ <module>Campaigner_Integration</module>
133
+ <frontName>campaigner</frontName>
134
+ </args>
135
+ </campaigner>
136
+ </routers>
137
+ <layout>
138
+ <updates>
139
+ <campaigner>
140
+ <file>campaigner.xml</file>
141
+ </campaigner>
142
+ </updates>
143
+ </layout>
144
+ <events>
145
+ <controller_action_postdispatch_checkout_onepage_saveOrder>
146
+ <observers>
147
+ <campaigner_subscribe_checkout>
148
+ <class>campaigner/newsletter_observer</class>
149
+ <method>registerCheckoutSubscribe</method>
150
+ </campaigner_subscribe_checkout>
151
+ </observers>
152
+ </controller_action_postdispatch_checkout_onepage_saveOrder>
153
+ <checkout_onepage_controller_success_action>
154
+ <observers>
155
+ <campaigner_subscribe_checkoutsuccess>
156
+ <class>campaigner/newsletter_observer</class>
157
+ <method>registerCheckoutSuccess</method>
158
+ </campaigner_subscribe_checkoutsuccess>
159
+ </observers>
160
+ </checkout_onepage_controller_success_action>
161
+ <sales_quote_save_after>
162
+ <observers>
163
+ <campaigner_quote_save_after>
164
+ <class>campaigner/abandoned_observer</class>
165
+ <method>quoteSaveAfter</method>
166
+ </campaigner_quote_save_after>
167
+ </observers>
168
+ </sales_quote_save_after>
169
+ <customer_save_after>
170
+ <observers>
171
+ <campaigner_update_customer>
172
+ <class>campaigner/customer_observer</class>
173
+ <method>updateCustomer</method>
174
+ </campaigner_update_customer>
175
+ </observers>
176
+ </customer_save_after>
177
+ <customer_login>
178
+ <observers>
179
+ <campaigner_customer_login>
180
+ <class>campaigner/customer_observer</class>
181
+ <method>customerLogin</method>
182
+ </campaigner_customer_login>
183
+ </observers>
184
+ </customer_login>
185
+ </events>
186
+ </frontend>
187
+ <admin>
188
+ <routers>
189
+ <campaigner_dashboard>
190
+ <use>admin</use>
191
+ <args>
192
+ <module>Campaigner_Integration</module>
193
+ <frontName>campaigner_dashboard</frontName>
194
+ </args>
195
+ </campaigner_dashboard>
196
+ </routers>
197
+ </admin>
198
+ <adminhtml>
199
+ <layout>
200
+ <updates>
201
+ <campaigner>
202
+ <file>campaigner.xml</file>
203
+ </campaigner>
204
+ </updates>
205
+ </layout>
206
+ <translate>
207
+ <modules>
208
+ <Campaigner_Integration>
209
+ <files>
210
+ <default>Campaigner_Integration.csv</default>
211
+ </files>
212
+ </Campaigner_Integration>
213
+ </modules>
214
+ </translate>
215
+ <events>
216
+ <core_block_abstract_to_html_before>
217
+ <observers>
218
+ <campaigner_newsletter_massaction>
219
+ <class>campaigner/newsletter_observer</class>
220
+ <method>updateNewsletterMassAction</method>
221
+ </campaigner_newsletter_massaction>
222
+ </observers>
223
+ </core_block_abstract_to_html_before>
224
+ <sales_order_shipment_track_save_after>
225
+ <observers>
226
+ <campaigner_track_save_after>
227
+ <type>model</type>
228
+ <class>campaigner/order_observer</class>
229
+ <method>salesOrderShipmentTrackSaveAfter</method>
230
+ </campaigner_track_save_after>
231
+ </observers>
232
+ </sales_order_shipment_track_save_after>
233
+ <admin_system_config_changed_section_campaigner>
234
+ <observers>
235
+ <campaigner_save_config>
236
+ <class>campaigner/configuration_observer</class>
237
+ <method>saveConfig</method>
238
+ </campaigner_save_config>
239
+ </observers>
240
+ </admin_system_config_changed_section_campaigner>
241
+ <customer_save_after>
242
+ <observers>
243
+ <campaigner_update_customer_admin>
244
+ <class>campaigner/customer_observer</class>
245
+ <method>updateCustomerAdmin</method>
246
+ </campaigner_update_customer_admin>
247
+ </observers>
248
+ </customer_save_after>
249
+ </events>
250
+ </adminhtml>
251
+ <default>
252
+ <campaigner>
253
+ <general>
254
+ <urls>
255
+ <accesspoint>https://rest.campaigner.com/v1/</accesspoint>
256
+ <lists>Lists</lists>
257
+ <subscribers>Subscribers</subscribers>
258
+ <sources>Sources</sources>
259
+ <publications>Publications</publications>
260
+ <products>Products</products>
261
+ <categories>ProductCategories</categories>
262
+ <orders>Orders</orders>
263
+ <database>Database</database>
264
+ <abandoned>Import/Subscribers</abandoned>
265
+ <ftp>FTP</ftp>
266
+ </urls>
267
+ <active>0</active>
268
+ <sourceid>0</sourceid>
269
+ <source>Magento</source>
270
+ <override_source>1</override_source>
271
+ <address_fields><![CDATA[a:5:{s:2:"a1";a:2:{s:7:"magento";s:6:"street";s:10:"campaigner";s:12:"Mage_Address";}s:2:"a2";a:2:{s:7:"magento";s:4:"city";s:10:"campaigner";s:9:"Mage_City";}s:2:"a3";a:2:{s:7:"magento";s:10:"state_code";s:10:"campaigner";s:10:"Mage_State";}s:2:"a4";a:2:{s:7:"magento";s:8:"postcode";s:10:"campaigner";s:8:"Mage_Zip";}s:2:"a5";a:2:{s:7:"magento";s:9:"telephone";s:10:"campaigner";s:5:"Phone";}}]]></address_fields>
272
+ <map_fields><![CDATA[a:2:{i:0;a:2:{s:7:"magento";s:9:"firstname";s:10:"campaigner";s:10:"First Name";}i:1;a:2:{s:7:"magento";s:8:"lastname";s:10:"campaigner";s:9:"Last Name";}}]]></map_fields>
273
+ <abandonedtime>30</abandonedtime>
274
+ <sendabandoned>0</sendabandoned>
275
+ <abandonedsetup>0</abandonedsetup>
276
+ <setup>0</setup>
277
+ <debug>0</debug>
278
+ <save_latest_order>0</save_latest_order>
279
+ <product_fields>3</product_fields>
280
+ <related_fields>2</related_fields>
281
+ <send_states>complete</send_states>
282
+ <send_statuses>complete</send_statuses>
283
+ <abandonedsequence_options><![CDATA[A
284
+ B
285
+ C]]></abandonedsequence_options>
286
+ <abandonedsequence_field>Mage_AbandonedSequence</abandonedsequence_field>
287
+ <signup_enabled>0</signup_enabled>
288
+ <signup_activated>0</signup_activated>
289
+ <signup_delay>3</signup_delay>
290
+ <signup_opacity>30</signup_opacity>
291
+ <signup_recurrence>1 month</signup_recurrence>
292
+ <signup_width>760</signup_width>
293
+ <signup_height>400</signup_height>
294
+ <batch_size>200</batch_size>
295
+ <batch_date_adjust>-1 week</batch_date_adjust>
296
+ <wishlist_enabled>0</wishlist_enabled>
297
+ <field_prefix>Mage_</field_prefix>
298
+ </general>
299
+ <export>
300
+ <include_disabled>1</include_disabled>
301
+ <include_already_sent>0</include_already_sent>
302
+ <batch>100</batch>
303
+ <setup>0</setup>
304
+ </export>
305
+ <troubleshooting>
306
+ <logging_enabled>0</logging_enabled>
307
+ <logging_duration>10</logging_duration>
308
+ <logging_stores>all</logging_stores>
309
+ <logging_areas>all</logging_areas>
310
+ <diagnostic_enabled>0</diagnostic_enabled>
311
+
312
+ <enabled>0</enabled>
313
+ <email>support@campaigner.com</email>
314
+ <subject>Campaigner Magento Module Troubleshooting Report</subject>
315
+ <report_file>troubleshootingreport.html</report_file>
316
+ <max_file_size>1048576</max_file_size>
317
+ <duration>10</duration>
318
+ </troubleshooting>
319
+ </campaigner>
320
+ <system>
321
+ <smtp>
322
+ <campaigner_use_smtp_relay>0</campaigner_use_smtp_relay>
323
+ <campaigner_smtp_server>relay.csmtp.net</campaigner_smtp_server>
324
+ <campaigner_smtp_port>25</campaigner_smtp_port>
325
+ <campaigner_smtp_encryption>none</campaigner_smtp_encryption>
326
+ </smtp>
327
+ </system>
328
+ </default>
329
+ <crontab>
330
+ <jobs>
331
+ <campaigner_integration>
332
+ <schedule>
333
+ <cron_expr>0 */1 * * *</cron_expr>
334
+ <!--<cron_expr>*/5 * * * *</cron_expr>--><!-- every 5 minutes for testing -->
335
+ </schedule>
336
+ <run>
337
+ <model>campaigner/abandoned_observer::abandonedCartsProcessor</model>
338
+ </run>
339
+ </campaigner_integration>
340
+ <campaigner_integration_latest_orders>
341
+ <schedule>
342
+ <cron_expr>30 * * * *</cron_expr>
343
+ <!--<cron_expr>*/5 * * * *</cron_expr>--><!-- every 5 minutes for testing -->
344
+ </schedule>
345
+ <run>
346
+ <model>campaigner/order_observer::processLatestOrders</model>
347
+ </run>
348
+ </campaigner_integration_latest_orders>
349
+ </jobs>
350
+ </crontab>
351
+ </config>
app/code/community/Campaigner/Integration/etc/system.xml ADDED
@@ -0,0 +1,548 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <campaigner translate="label" module="campaigner">
5
+ <class>campaigner-section</class>
6
+ <label>Campaigner Configuration</label>
7
+ <header_css>campaigner-header</header_css>
8
+ <tab>customer</tab>
9
+ <sort_order>404</sort_order>
10
+ <show_in_default>1</show_in_default>
11
+ <show_in_website>1</show_in_website>
12
+ <show_in_store>1</show_in_store>
13
+ <groups>
14
+ <hint>
15
+ <frontend_model>campaigner/adminhtml_system_config_fieldset_hint</frontend_model>
16
+ <sort_order>0</sort_order>
17
+ <show_in_default>1</show_in_default>
18
+ <show_in_website>1</show_in_website>
19
+ <show_in_store>1</show_in_store>
20
+ </hint>
21
+ <general translate="label comment">
22
+ <label>General</label>
23
+ <frontend_type>text</frontend_type>
24
+ <sort_order>660</sort_order>
25
+ <show_in_default>1</show_in_default>
26
+ <show_in_website>1</show_in_website>
27
+ <show_in_store>1</show_in_store>
28
+ <expanded>1</expanded>
29
+ <fields>
30
+ <info translate="label">
31
+ <label>Info</label>
32
+ <frontend_model>campaigner/adminhtml_system_config_form_field_info</frontend_model>
33
+ <sort_order>1</sort_order>
34
+ <show_in_default>1</show_in_default>
35
+ <show_in_website>1</show_in_website>
36
+ <show_in_store>1</show_in_store>
37
+ </info>
38
+ <heading_general translate="label">
39
+ <label>General Configuration</label>
40
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
41
+ <sort_order>5</sort_order>
42
+ <show_in_default>1</show_in_default>
43
+ <show_in_website>0</show_in_website>
44
+ <show_in_store>1</show_in_store>
45
+ </heading_general>
46
+ <active translate="label">
47
+ <label>Enabled</label>
48
+ <frontend_type>select</frontend_type>
49
+ <source_model>adminhtml/system_config_source_yesno</source_model>
50
+ <sort_order>10</sort_order>
51
+ <show_in_default>1</show_in_default>
52
+ <show_in_website>0</show_in_website>
53
+ <show_in_store>1</show_in_store>
54
+ </active>
55
+ <api_username translate="label comment">
56
+ <label>API Username</label>
57
+ <frontend_type>text</frontend_type>
58
+ <sort_order>20</sort_order>
59
+ <show_in_default>1</show_in_default>
60
+ <show_in_website>0</show_in_website>
61
+ <show_in_store>1</show_in_store>
62
+ <comment>Enter your Campaigner API Username here</comment>
63
+ </api_username>
64
+ <api_password translate="label">
65
+ <label>API Password</label>
66
+ <frontend_type>text</frontend_type>
67
+ <sort_order>21</sort_order>
68
+ <show_in_default>1</show_in_default>
69
+ <show_in_website>0</show_in_website>
70
+ <show_in_store>1</show_in_store>
71
+ </api_password>
72
+ <api_validation translate="label">
73
+ <label>API Credential Status</label>
74
+ <frontend_model>campaigner/adminhtml_system_config_form_field_api</frontend_model>
75
+ <sort_order>22</sort_order>
76
+ <show_in_default>1</show_in_default>
77
+ <show_in_website>0</show_in_website>
78
+ <show_in_store>1</show_in_store>
79
+ </api_validation>
80
+ <api_instructions>
81
+ <label>Get your API Credentials</label>
82
+ <frontend_model>campaigner/adminhtml_system_config_form_field_note</frontend_model>
83
+ <sort_order>25</sort_order>
84
+ <show_in_default>1</show_in_default>
85
+ <show_in_website>0</show_in_website>
86
+ <show_in_store>1</show_in_store>
87
+ </api_instructions>
88
+ <smtp_link translate="label">
89
+ <label>SMTP Relay</label>
90
+ <frontend_model>campaigner/adminhtml_system_config_form_field_smtp</frontend_model>
91
+ <sort_order>30</sort_order>
92
+ <show_in_default>1</show_in_default>
93
+ <show_in_website>0</show_in_website>
94
+ <show_in_store>1</show_in_store>
95
+ <comment>Set up Campaigner’s SMTP Relay service to deliver order confirmations, shipment notifications and other transactional emails sent from Magento. Track opens and clicks, and then generate detailed, segmented reports to get the most out of all your essential emails. Benefit from Campaigner’s fast, secure, and reliable delivery today!</comment>
96
+ </smtp_link>
97
+ <checkout_subscribe translate="label comment">
98
+ <label>Subscribe On Checkout</label>
99
+ <frontend_type>select</frontend_type>
100
+ <source_model>campaigner/system_config_source_checkoutsubscribe</source_model>
101
+ <sort_order>50</sort_order>
102
+ <show_in_default>1</show_in_default>
103
+ <show_in_website>0</show_in_website>
104
+ <show_in_store>1</show_in_store>
105
+ <comment><![CDATA[Show Newsletter Subscribe checkbox in the last Checkout Step (Order Review). <span class='warning'>This may not work if your checkout has been customized!</span>]]></comment>
106
+ </checkout_subscribe>
107
+ <list translate="label comment">
108
+ <label>List</label>
109
+ <frontend_type>select</frontend_type>
110
+ <source_model>campaigner/system_config_source_list</source_model>
111
+ <sort_order>60</sort_order>
112
+ <show_in_default>1</show_in_default>
113
+ <show_in_website>0</show_in_website>
114
+ <show_in_store>1</show_in_store>
115
+ <can_be_empty>1</can_be_empty>
116
+ <comment>This is the List that emails will be subscribed to and is required</comment>
117
+ </list>
118
+ <store_send_type translate="label comment">
119
+ <label>Store field to send</label>
120
+ <frontend_type>select</frontend_type>
121
+ <source_model>campaigner/system_config_source_store</source_model>
122
+ <sort_order>65</sort_order>
123
+ <show_in_default>1</show_in_default>
124
+ <show_in_website>0</show_in_website>
125
+ <show_in_store>1</show_in_store>
126
+ <can_be_empty>1</can_be_empty>
127
+ <comment>When sending customer data, this will indicate the store that they are associated with</comment>
128
+ </store_send_type>
129
+ <lastlogin_enabled translate="label">
130
+ <label>Send Last login Date</label>
131
+ <frontend_type>select</frontend_type>
132
+ <source_model>adminhtml/system_config_source_yesno</source_model>
133
+ <sort_order>70</sort_order>
134
+ <show_in_default>1</show_in_default>
135
+ <show_in_website>0</show_in_website>
136
+ <show_in_store>1</show_in_store>
137
+ </lastlogin_enabled>
138
+
139
+ <save_latest_order translate="label">
140
+ <label>Save Latest Order Information</label>
141
+ <frontend_type>select</frontend_type>
142
+ <source_model>adminhtml/system_config_source_yesno</source_model>
143
+ <sort_order>80</sort_order>
144
+ <show_in_default>1</show_in_default>
145
+ <show_in_website>0</show_in_website>
146
+ <show_in_store>1</show_in_store>
147
+ <comment>Save information from the latest order along with the first 3 products from that order</comment>
148
+ </save_latest_order>
149
+
150
+ <heading_mappings translate="label">
151
+ <label>Field Mappings</label>
152
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
153
+ <sort_order>200</sort_order>
154
+ <show_in_default>1</show_in_default>
155
+ <show_in_website>0</show_in_website>
156
+ <show_in_store>1</show_in_store>
157
+ </heading_mappings>
158
+
159
+ <address_fields translate="label comment">
160
+ <label>Address Fields Mapping</label>
161
+ <frontend_model>campaigner/adminhtml_system_config_form_field_addressmapfields</frontend_model>
162
+ <backend_model>adminhtml/system_config_backend_serialized_array</backend_model>
163
+ <sort_order>210</sort_order>
164
+ <show_in_default>1</show_in_default>
165
+ <show_in_website>0</show_in_website>
166
+ <show_in_store>1</show_in_store>
167
+ </address_fields>
168
+ <map_fields translate="label comment">
169
+ <label>Customer Fields Mapping</label>
170
+ <frontend_model>campaigner/adminhtml_system_config_form_field_mapfields</frontend_model>
171
+ <backend_model>adminhtml/system_config_backend_serialized_array</backend_model>
172
+ <sort_order>220</sort_order>
173
+ <show_in_default>1</show_in_default>
174
+ <show_in_website>0</show_in_website>
175
+ <show_in_store>1</show_in_store>
176
+ </map_fields>
177
+ <shipping_fields translate="label comment">
178
+ <label>Shipping Fields Mapping</label>
179
+ <frontend_model>campaigner/adminhtml_system_config_form_field_shippingmapfields</frontend_model>
180
+ <backend_model>adminhtml/system_config_backend_serialized_array</backend_model>
181
+ <sort_order>230</sort_order>
182
+ <show_in_default>1</show_in_default>
183
+ <show_in_website>0</show_in_website>
184
+ <show_in_store>1</show_in_store>
185
+ </shipping_fields>
186
+
187
+ <heading_abandoned translate="label">
188
+ <label>Abandoned Carts</label>
189
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
190
+ <sort_order>300</sort_order>
191
+ <show_in_default>1</show_in_default>
192
+ <show_in_website>0</show_in_website>
193
+ <show_in_store>1</show_in_store>
194
+ </heading_abandoned>
195
+
196
+ <abandoned_enabled translate="label">
197
+ <label>Add Abandoned Carts To Campaigner</label>
198
+ <frontend_type>select</frontend_type>
199
+ <source_model>adminhtml/system_config_source_yesno</source_model>
200
+ <sort_order>310</sort_order>
201
+ <show_in_default>1</show_in_default>
202
+ <show_in_website>0</show_in_website>
203
+ <show_in_store>1</show_in_store>
204
+ <comment>This will add any abandoned shopping carts to the Campaigner database with AbandonedDate and AbandonedURL database fields. These fields can be used with Workflows to time your own Abandoned Shopping Cart emails or send a series of emails. This allows for complete customization of the email.</comment>
205
+ </abandoned_enabled>
206
+ <abandonedtime translate="label comment">
207
+ <label>Abandoned Time</label>
208
+ <frontend_type>select</frontend_type>
209
+ <source_model>campaigner/system_config_source_time</source_model>
210
+ <sort_order>320</sort_order>
211
+ <show_in_default>1</show_in_default>
212
+ <show_in_website>0</show_in_website>
213
+ <show_in_store>1</show_in_store>
214
+ <comment>How long before a cart is considered abandoned?</comment>
215
+ <depends><abandoned_enabled>1</abandoned_enabled></depends>
216
+ </abandonedtime>
217
+ <abandoned_list translate="label comment">
218
+ <label>Abandoned List</label>
219
+ <frontend_type>select</frontend_type>
220
+ <source_model>campaigner/system_config_source_list</source_model>
221
+ <sort_order>330</sort_order>
222
+ <show_in_default>1</show_in_default>
223
+ <show_in_website>0</show_in_website>
224
+ <show_in_store>1</show_in_store>
225
+ <can_be_empty>1</can_be_empty>
226
+ <comment>This is the List that you will put abandoned shoppers into</comment>
227
+ <depends><abandoned_enabled>1</abandoned_enabled></depends>
228
+ </abandoned_list>
229
+
230
+ <capture_enabled translate="label">
231
+ <label>Capture guest emails?</label>
232
+ <frontend_type>select</frontend_type>
233
+ <source_model>adminhtml/system_config_source_yesno</source_model>
234
+ <sort_order>350</sort_order>
235
+ <show_in_default>1</show_in_default>
236
+ <show_in_website>0</show_in_website>
237
+ <show_in_store>1</show_in_store>
238
+ <comment>When enabled, this feature will capture guest emails from various forms within the site to be used with abandoned carts.</comment>
239
+ <depends><abandoned_enabled>1</abandoned_enabled></depends>
240
+ </capture_enabled>
241
+
242
+ <!-- SEQUENCES -->
243
+ <heading_sequence translate="label">
244
+ <label>Abandoned Cart Sequences</label>
245
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
246
+ <sort_order>360</sort_order>
247
+ <show_in_default>1</show_in_default>
248
+ <show_in_website>0</show_in_website>
249
+ <show_in_store>1</show_in_store>
250
+ <depends><abandoned_enabled>1</abandoned_enabled></depends>
251
+ </heading_sequence>
252
+ <abandonedsequence_enabled>
253
+ <label>Add a sequence value to each abandoned cart?</label>
254
+ <frontend_type>select</frontend_type>
255
+ <source_model>adminhtml/system_config_source_yesno</source_model>
256
+ <sort_order>370</sort_order>
257
+ <show_in_default>1</show_in_default>
258
+ <show_in_website>0</show_in_website>
259
+ <show_in_store>1</show_in_store>
260
+ <comment>This will allow you to assign a sequence of values to your subscribers, one for each abandoned cart.</comment>
261
+ <depends><abandoned_enabled>1</abandoned_enabled></depends>
262
+ </abandonedsequence_enabled>
263
+ <abandonedsequence_field translate="label comment">
264
+ <label>Sequence Database Field</label>
265
+ <frontend_type>select</frontend_type>
266
+ <source_model>campaigner/system_config_source_sequence</source_model>
267
+ <sort_order>380</sort_order>
268
+ <show_in_default>1</show_in_default>
269
+ <show_in_website>0</show_in_website>
270
+ <show_in_store>1</show_in_store>
271
+ <can_be_empty>1</can_be_empty>
272
+ <comment>This is the database field in Campaigner that the sequence will be stored in.</comment>
273
+ <depends><abandoned_enabled>1</abandoned_enabled><abandonedsequence_enabled>1</abandonedsequence_enabled></depends>
274
+ </abandonedsequence_field>
275
+ <abandonedsequence_options translate="label comment">
276
+ <label>Sequence Options</label>
277
+ <frontend_type>textarea</frontend_type>
278
+ <sort_order>390</sort_order>
279
+ <show_in_default>1</show_in_default>
280
+ <show_in_website>0</show_in_website>
281
+ <show_in_store>1</show_in_store>
282
+ <can_be_empty>1</can_be_empty>
283
+ <comment>Enter one sequence per line to be appended.</comment>
284
+ <depends><abandoned_enabled>1</abandoned_enabled><abandonedsequence_enabled>1</abandonedsequence_enabled></depends>
285
+ </abandonedsequence_options>
286
+
287
+ <!-- signup -->
288
+ <heading_signup translate="label">
289
+ <label>Campaigner Signup Form</label>
290
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
291
+ <sort_order>400</sort_order>
292
+ <show_in_default>1</show_in_default>
293
+ <show_in_website>0</show_in_website>
294
+ <show_in_store>1</show_in_store>
295
+ </heading_signup>
296
+ <signup_enabled>
297
+ <label>Show Campaigner Signup form?</label>
298
+ <frontend_type>select</frontend_type>
299
+ <source_model>adminhtml/system_config_source_yesno</source_model>
300
+ <sort_order>410</sort_order>
301
+ <show_in_default>1</show_in_default>
302
+ <show_in_website>0</show_in_website>
303
+ <show_in_store>1</show_in_store>
304
+ <comment>This will allow you to show an Campaigner signup form in a popup.</comment>
305
+ </signup_enabled>
306
+ <signup_url>
307
+ <label>URL to Signup Form</label>
308
+ <frontend_type>text</frontend_type>
309
+ <sort_order>420</sort_order>
310
+ <show_in_default>1</show_in_default>
311
+ <show_in_website>0</show_in_website>
312
+ <show_in_store>1</show_in_store>
313
+ <comment>URL to the Campaigner Signup Form.</comment>
314
+ <depends><signup_enabled>1</signup_enabled></depends>
315
+ </signup_url>
316
+ <signup_delay>
317
+ <label>Delay before showing</label>
318
+ <frontend_type>text</frontend_type>
319
+ <sort_order>430</sort_order>
320
+ <show_in_default>1</show_in_default>
321
+ <show_in_website>0</show_in_website>
322
+ <show_in_store>1</show_in_store>
323
+ <depends><signup_enabled>1</signup_enabled></depends>
324
+ <comment>How many seconds before the signup form is shown</comment>
325
+ </signup_delay>
326
+ <signup_recurrence>
327
+ <label>Recurrence</label>
328
+ <frontend_type>select</frontend_type>
329
+ <source_model>campaigner/system_config_source_signup_recurrence</source_model>
330
+ <sort_order>440</sort_order>
331
+ <show_in_default>1</show_in_default>
332
+ <show_in_website>0</show_in_website>
333
+ <show_in_store>1</show_in_store>
334
+ <comment>Time until Signup Form displays again, per visitor.</comment>
335
+ <depends><signup_enabled>1</signup_enabled></depends>
336
+ </signup_recurrence>
337
+ <signup_width>
338
+ <label>Width of Form</label>
339
+ <frontend_type>text</frontend_type>
340
+ <sort_order>450</sort_order>
341
+ <show_in_default>1</show_in_default>
342
+ <show_in_website>0</show_in_website>
343
+ <show_in_store>1</show_in_store>
344
+ <depends><signup_enabled>1</signup_enabled></depends>
345
+ </signup_width>
346
+ <signup_height>
347
+ <label>Height of Form</label>
348
+ <frontend_type>text</frontend_type>
349
+ <sort_order>460</sort_order>
350
+ <show_in_default>1</show_in_default>
351
+ <show_in_website>0</show_in_website>
352
+ <show_in_store>1</show_in_store>
353
+ <depends><signup_enabled>1</signup_enabled></depends>
354
+ </signup_height>
355
+ <signup_opacity>
356
+ <label>Opacity of background</label>
357
+ <frontend_type>select</frontend_type>
358
+ <source_model>campaigner/system_config_source_signup_opacity</source_model>
359
+ <sort_order>470</sort_order>
360
+ <show_in_default>1</show_in_default>
361
+ <show_in_website>0</show_in_website>
362
+ <show_in_store>1</show_in_store>
363
+ <depends><signup_enabled>1</signup_enabled></depends>
364
+ </signup_opacity>
365
+ <signup_test_button>
366
+ <label>Test Signup Form</label>
367
+ <frontend_model>campaigner/adminhtml_system_config_form_field_signup_test</frontend_model>
368
+ <sort_order>480</sort_order>
369
+ <show_in_default>1</show_in_default>
370
+ <show_in_website>0</show_in_website>
371
+ <show_in_store>1</show_in_store>
372
+ <can_be_empty>1</can_be_empty>
373
+ <comment><![CDATA[Test the signup form popup (opens in new window).<br />Note: "Show Campaigner Signup form" must be set to "Yes" and the configuration saved in order to perform a signup test.]]></comment>
374
+ <depends><signup_enabled>1</signup_enabled></depends>
375
+ </signup_test_button>
376
+ <signup_activated>
377
+ <label>Activate Signup Form?</label>
378
+ <frontend_type>select</frontend_type>
379
+ <source_model>adminhtml/system_config_source_yesno</source_model>
380
+ <sort_order>490</sort_order>
381
+ <show_in_default>1</show_in_default>
382
+ <show_in_website>0</show_in_website>
383
+ <show_in_store>1</show_in_store>
384
+ <comment>Do not activate this form until it has been tested.</comment>
385
+ <depends><signup_enabled>1</signup_enabled></depends>
386
+ </signup_activated>
387
+
388
+ <!-- Wishlist -->
389
+ <heading_wishlist translate="label">
390
+ <label>Wishlist</label>
391
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
392
+ <sort_order>600</sort_order>
393
+ <show_in_default>1</show_in_default>
394
+ <show_in_website>0</show_in_website>
395
+ <show_in_store>1</show_in_store>
396
+ </heading_wishlist>
397
+ <wishlist_enabled>
398
+ <label>Activate Wish List Alerts?</label>
399
+ <frontend_type>select</frontend_type>
400
+ <source_model>adminhtml/system_config_source_yesno</source_model>
401
+ <sort_order>610</sort_order>
402
+ <show_in_default>1</show_in_default>
403
+ <show_in_website>0</show_in_website>
404
+ <show_in_store>1</show_in_store>
405
+ <comment>Send subscriber Wishlist URL and their most recent Wishlist Date to your Campaigner database.</comment>
406
+ </wishlist_enabled>
407
+ </fields>
408
+ </general>
409
+
410
+ <troubleshooting translate="label comment">
411
+ <label>Troubleshooting</label>
412
+ <frontend_type>text</frontend_type>
413
+ <sort_order>900</sort_order>
414
+ <show_in_default>1</show_in_default>
415
+ <show_in_website>0</show_in_website>
416
+ <show_in_store>1</show_in_store>
417
+ <expanded>1</expanded>
418
+ <fields>
419
+ <heading_logging translate="label">
420
+ <label>Logging</label>
421
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
422
+ <sort_order>10</sort_order>
423
+ <show_in_default>1</show_in_default>
424
+ <show_in_website>0</show_in_website>
425
+ <show_in_store>1</show_in_store>
426
+ </heading_logging>
427
+ <logging translate="label">
428
+ <label>Status</label>
429
+ <frontend_model>campaigner/adminhtml_system_config_form_field_logging</frontend_model>
430
+ <sort_order>20</sort_order>
431
+ <show_in_default>1</show_in_default>
432
+ <show_in_website>0</show_in_website>
433
+ <show_in_store>1</show_in_store>
434
+ <comment></comment>
435
+ </logging>
436
+ <heading_diagnostics translate="label">
437
+ <label>Diagnostics</label>
438
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
439
+ <sort_order>200</sort_order>
440
+ <show_in_default>1</show_in_default>
441
+ <show_in_website>0</show_in_website>
442
+ <show_in_store>1</show_in_store>
443
+ </heading_diagnostics>
444
+ <diagnostics translate="label">
445
+ <label>Status</label>
446
+ <frontend_model>campaigner/adminhtml_system_config_form_field_diagnostics</frontend_model>
447
+ <sort_order>210</sort_order>
448
+ <show_in_default>1</show_in_default>
449
+ <show_in_website>0</show_in_website>
450
+ <show_in_store>1</show_in_store>
451
+ <comment></comment>
452
+ </diagnostics>
453
+ </fields>
454
+ </troubleshooting>
455
+ </groups>
456
+ </campaigner>
457
+ <system>
458
+ <groups>
459
+ <smtp translate="label">
460
+ <fields>
461
+ <heading_campaigner_smtp translate="label">
462
+ <label>Campaigner SMTP Relay</label>
463
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
464
+ <sort_order>99</sort_order>
465
+ <show_in_default>1</show_in_default>
466
+ <show_in_website>0</show_in_website>
467
+ <show_in_store>1</show_in_store>
468
+ </heading_campaigner_smtp>
469
+
470
+ <campaigner_use_smtp_relay translate="label">
471
+ <label>Use Campaigner SMTP Relay for sending emails</label>
472
+ <frontend_type>select</frontend_type>
473
+ <source_model>adminhtml/system_config_source_yesno</source_model>
474
+ <sort_order>100</sort_order>
475
+ <show_in_default>1</show_in_default>
476
+ <show_in_website>0</show_in_website>
477
+ <show_in_store>1</show_in_store>
478
+ </campaigner_use_smtp_relay>
479
+
480
+ <campaigner_smtp_server translate="label">
481
+ <label>SMTP Server</label>
482
+ <frontend_model>campaigner/adminhtml_system_config_form_field_smtp_server</frontend_model>
483
+ <frontend_type>label</frontend_type>
484
+ <sort_order>110</sort_order>
485
+ <show_in_default>1</show_in_default>
486
+ <show_in_website>0</show_in_website>
487
+ <show_in_store>1</show_in_store>
488
+ <depends><campaigner_use_smtp_relay>1</campaigner_use_smtp_relay></depends>
489
+ </campaigner_smtp_server>
490
+
491
+ <campaigner_smtp_port translate="label">
492
+ <label>SMTP Port</label>
493
+ <frontend_type>text</frontend_type>
494
+ <sort_order>120</sort_order>
495
+ <show_in_default>1</show_in_default>
496
+ <show_in_website>0</show_in_website>
497
+ <show_in_store>1</show_in_store>
498
+ <depends><campaigner_use_smtp_relay>1</campaigner_use_smtp_relay></depends>
499
+ </campaigner_smtp_port>
500
+
501
+
502
+ <campaigner_smtp_encryption translate="label">
503
+ <label>SMTP Encryption</label>
504
+ <source_model>campaigner/system_config_source_smtp_encryption</source_model>
505
+ <frontend_type>select</frontend_type>
506
+ <sort_order>130</sort_order>
507
+ <show_in_default>1</show_in_default>
508
+ <show_in_website>0</show_in_website>
509
+ <show_in_store>1</show_in_store>
510
+ <depends><campaigner_use_smtp_relay>1</campaigner_use_smtp_relay></depends>
511
+ <comment>TLS is available on port 587. SSL is available on port 465.</comment>
512
+ </campaigner_smtp_encryption>
513
+
514
+ <campaigner_smtp_username translate="label">
515
+ <label>SMTP Username</label>
516
+ <frontend_type>text</frontend_type>
517
+ <sort_order>140</sort_order>
518
+ <show_in_default>1</show_in_default>
519
+ <show_in_website>0</show_in_website>
520
+ <show_in_store>1</show_in_store>
521
+ <depends><campaigner_use_smtp_relay>1</campaigner_use_smtp_relay></depends>
522
+ <comment></comment>
523
+ </campaigner_smtp_username>
524
+ <campaigner_smtp_password translate="label">
525
+ <label>SMTP Password</label>
526
+ <frontend_type>text</frontend_type>
527
+ <sort_order>150</sort_order>
528
+ <show_in_default>1</show_in_default>
529
+ <show_in_website>0</show_in_website>
530
+ <show_in_store>1</show_in_store>
531
+ <depends><campaigner_use_smtp_relay>1</campaigner_use_smtp_relay></depends>
532
+ <comment></comment>
533
+ </campaigner_smtp_password>
534
+ <campaigner_smtp_test translate="label">
535
+ <label>SMTP Relay Test</label>
536
+ <frontend_model>campaigner/adminhtml_system_config_form_field_smtp_test</frontend_model>
537
+ <sort_order>160</sort_order>
538
+ <show_in_default>1</show_in_default>
539
+ <show_in_website>0</show_in_website>
540
+ <show_in_store>1</show_in_store>
541
+ <depends><campaigner_use_smtp_relay>1</campaigner_use_smtp_relay></depends>
542
+ </campaigner_smtp_test>
543
+ </fields>
544
+ </smtp>
545
+ </groups>
546
+ </system>
547
+ </sections>
548
+ </config>
app/code/community/Campaigner/Integration/sql/campaigner_setup/mysql4-install-1.0.0.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+
5
+ $installer->startSetup();
6
+
7
+ try
8
+ {
9
+ $this->run("
10
+
11
+ DROP TABLE IF EXISTS {$this->getTable('campaigner/session')};
12
+ CREATE TABLE {$this->getTable('campaigner/session')} (
13
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
14
+ `customer_id` int(11) DEFAULT NULL,
15
+ `magento_session_id` varchar(255) NOT NULL,
16
+ `email` varchar(255) NULL,
17
+ `status` VARCHAR(255) NULL,
18
+ `status_notified` TIMESTAMP NULL,
19
+ PRIMARY KEY (`id`),
20
+ KEY `idx_magento_session_id` (`magento_session_id`)
21
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
22
+
23
+ DROP TABLE IF EXISTS {$this->getTable('campaigner/abandoned')};
24
+ CREATE TABLE {$this->getTable('campaigner/abandoned')} (
25
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
26
+ `session_id` int(11) NOT NULL,
27
+ `date_sent` TIMESTAMP NULL,
28
+ `status` VARCHAR(255) NULL,
29
+ `quote_id` int(11) DEFAULT NULL,
30
+ PRIMARY KEY (`id`),
31
+ KEY `idx_quote_id` (`quote_id`)
32
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
33
+
34
+ DROP TABLE IF EXISTS {$this->getTable('campaigner/latest_order')};
35
+ CREATE TABLE {$this->getTable('campaigner/latest_order')} (
36
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
37
+ `email` VARCHAR(255) NULL,
38
+ `store_id` int(11) NULL,
39
+ `date_sent` TIMESTAMP NULL,
40
+ `status` VARCHAR(255) NULL,
41
+ `order_id` int(11) DEFAULT NULL,
42
+ PRIMARY KEY (`id`),
43
+ KEY `idx_email` (`email`),
44
+ KEY `idx_order_id` (`order_id`)
45
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
46
+ ");
47
+
48
+ // Add install message to inbox
49
+
50
+ $this->addNotification(
51
+ 'The Campaigner extension was installed. Enter your API Username and Password to configure the settings and make sure your cron jobs are running.',
52
+ 'The Campaigner extension was installed. Enter your API Username and Password to configure the settings and make sure your cron jobs are running. Cron Install and Setup Guide (http://campaigner.com/Magento)',
53
+ 'http://campaigner.com/Magento'
54
+ );
55
+ }
56
+ catch (Exception $e)
57
+ {
58
+ $this->install_log($e->getMessage());
59
+ }
60
+
61
+ $installer->endSetup();
app/design/adminhtml/default/default/layout/campaigner.xml ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout>
3
+ <adminhtml_system_config_edit>
4
+ <reference name="head">
5
+ <action method="addCss"><stylesheet>campaigner/campaigner.css</stylesheet></action>
6
+ </reference>
7
+ <reference name="content">
8
+ <block type="core/template" name="campaigner_setup_check" before="-" template="campaigner/system/config/setup_check.phtml" />
9
+ </reference>
10
+ </adminhtml_system_config_edit>
11
+
12
+ <campaigner_dashboard_admin_export_products>
13
+ <remove name="root"/>
14
+ <block type="adminhtml/page" name="convert_root" output="toHtml" template="page.phtml">
15
+ <block type="adminhtml/page_head" name="convert_root_head" as="head" template="page/head.phtml">
16
+ <action method="addJs"><script>prototype/prototype.js</script></action>
17
+ <action method="addJs"><script>prototype/validation.js</script></action>
18
+ <action method="addJs"><script>varien/js.js</script></action>
19
+ <action method="addJs"><script>mage/translate.js</script></action>
20
+ <action method="addJs"><script>mage/adminhtml/tools.js</script></action>
21
+ <action method="setTitle" translate="title"><title>Campaigner - Export Products</title></action>
22
+ </block>
23
+ <block type="campaigner/adminhtml_system_convert_profile_export_products" name="system_convert_profile_run" template="campaigner/system/convert/profile/export.phtml" output="toHtml"/>
24
+ </block>
25
+ </campaigner_dashboard_admin_export_products>
26
+
27
+ <campaigner_dashboard_admin_export_orders>
28
+ <remove name="root"/>
29
+ <block type="adminhtml/page" name="convert_root" output="toHtml" template="page.phtml">
30
+ <block type="adminhtml/page_head" name="convert_root_head" as="head" template="page/head.phtml">
31
+ <action method="addJs"><script>prototype/prototype.js</script></action>
32
+ <action method="addJs"><script>prototype/validation.js</script></action>
33
+ <action method="addJs"><script>varien/js.js</script></action>
34
+ <action method="addJs"><script>mage/translate.js</script></action>
35
+ <action method="addJs"><script>mage/adminhtml/tools.js</script></action>
36
+ <action method="setTitle" translate="title"><title>Campaigner - Export Orders</title></action>
37
+ </block>
38
+ <block type="campaigner/adminhtml_system_convert_profile_export_orders" name="system_convert_profile_run" template="campaigner/system/convert/profile/export.phtml" output="toHtml"/>
39
+ </block>
40
+ </campaigner_dashboard_admin_export_orders>
41
+
42
+ <campaigner_dashboard_admin_troubleshooting_index>
43
+ <reference name="head">
44
+ <action method="addCss"><stylesheet>campaigner/campaigner.css</stylesheet></action>
45
+ </reference>
46
+ <reference name="content">
47
+ <block type="campaigner/adminhtml_troubleshooting_view" name="troubleshooting_view">
48
+ <block type="campaigner/adminhtml_troubleshooting_status" name="troubleshooting_status" template='campaigner/troubleshooting/status.phtml'>
49
+ </block>
50
+ </block>
51
+ </reference>
52
+ <reference name="left">
53
+ <block type="campaigner/adminhtml_troubleshooting_tabs" name="trouble.tabs" as="trouble.tabs" template="widget/tabs.phtml" >
54
+ <action method="addTab"><name>trouble_help</name><block>campaigner/adminhtml_troubleshooting_view_tab_help</block></action>
55
+ <action method="addTab"><name>trouble_settings</name><block>campaigner/adminhtml_troubleshooting_view_tab_settings</block></action>
56
+ <action method="addTab"><name>trouble_info</name><block>campaigner/adminhtml_troubleshooting_view_tab_info</block></action>
57
+ <action method="addTab"><name>trouble_log</name><block>campaigner/adminhtml_troubleshooting_view_tab_log</block></action>
58
+ <action method="addTab"><name>trouble_submit</name><block>campaigner/adminhtml_troubleshooting_view_tab_submit</block></action>
59
+ <action method="addTab"><name>trouble_download</name><block>campaigner/adminhtml_troubleshooting_view_tab_download</block></action>
60
+ </block>
61
+ </reference>
62
+ </campaigner_dashboard_admin_troubleshooting_index>
63
+
64
+ <campaigner_dashboard_admin_latest_index>
65
+ <reference name="head">
66
+ <action method="addCss"><stylesheet>campaigner/campaigner.css</stylesheet></action>
67
+ </reference>
68
+ <reference name="content">
69
+ <block type="campaigner/adminhtml_latest" name="latest_orders">
70
+ </block>
71
+ </reference>
72
+ </campaigner_dashboard_admin_latest_index>
73
+
74
+ <campaigner_dashboard_admin_abandoned_index>
75
+ <reference name="head">
76
+ <action method="addCss"><stylesheet>campaigner/campaigner.css</stylesheet></action>
77
+ </reference>
78
+ <reference name="content">
79
+ <block type="campaigner/adminhtml_abandoned" name="abandoned_cart">
80
+ </block>
81
+ </reference>
82
+ </campaigner_dashboard_admin_abandoned_index>
83
+
84
+ <campaigner_dashboard_admin_abandoned_details>
85
+ <reference name="head">
86
+ <action method="addCss"><stylesheet>campaigner/campaigner.css</stylesheet></action>
87
+ </reference>
88
+ <reference name="content">
89
+ <block type="campaigner/adminhtml_abandoned_details" name="abandoned_details" template="campaigner/abandoned/details.phtml">
90
+ </block>
91
+ </reference>
92
+ <reference name="left">
93
+ <block type="campaigner/adminhtml_abandoned_tabs" name="abandoned.tabs" as="abandoned.tabs" template="widget/tabs.phtml" >
94
+ <block type="campaigner/adminhtml_abandoned_details_tab_diagnostics" name="abandoned_tab_details_campaigner" template="campaigner/diagnostics.phtml">
95
+ <block type="campaigner/adminhtml_abandoned_details_tab_diagnostics_status" name="diagnostic_status" template="campaigner/abandoned/details/tab/diagnostics/status.phtml"></block>
96
+ </block>
97
+
98
+ <action method="addTab"><name>abandoned_cart</name><block>campaigner/adminhtml_abandoned_details_tab_cart</block></action>
99
+ <action method="addTab"><name>abandoned_details</name><block>abandoned_tab_details_campaigner</block></action>
100
+
101
+ </block>
102
+ </reference>
103
+ </campaigner_dashboard_admin_abandoned_details>
104
+ </layout>
app/design/adminhtml/default/default/template/campaigner/abandoned/details.phtml ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php echo $this->getFormInitScripts() ?>
2
+ <div class="content-header">
3
+ <?php echo $this->getHeaderHtml() ?>
4
+ <p class="form-buttons"><?php echo $this->getButtonsHtml('header') ?></p>
5
+ </div>
6
+ <?php echo $this->getFormHtml() ?>
7
+ <?php if ($this->hasFooterButtons()): ?>
8
+ <div class="content-footer">
9
+ <p class="form-buttons"><?php echo $this->getButtonsHtml('footer') ?></p>
10
+ </div>
11
+ <?php endif; ?>
12
+ <script type="text/javascript">
13
+ editForm = new varienForm('edit_form', '<?php echo $this->getValidationUrl() ?>');
14
+ </script>
15
+ <?php echo $this->getFormScripts() ?>
app/design/adminhtml/default/default/template/campaigner/abandoned/details/form.phtml ADDED
@@ -0,0 +1 @@
 
1
+ <div class="entry-edit" id="abandoned_details"></div>
app/design/adminhtml/default/default/template/campaigner/abandoned/details/tab/cart.phtml ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $cart_items = $this->getCartItems(); ?>
2
+ <?php
3
+ $_sub_total = 0;
4
+ $_total = 0;
5
+ $_qty = 0;
6
+ ?>
7
+ <div class="entry-edit">
8
+ <div class="entry-edit-head">
9
+ <h4 class="icon-head head-products">Cart Items</h4>
10
+ </div>
11
+ </div>
12
+
13
+ <div class="grid np">
14
+ <div class="hor-scroll">
15
+ <table cellspacing="0" class="data order-tables">
16
+ <colgroup>
17
+ <col width="1">
18
+ <col>
19
+ <col width="1">
20
+ <col width="1">
21
+ <col width="1">
22
+ <col width="1">
23
+ </colgroup><thead>
24
+ <tr class="headings">
25
+ <th>Product ID</th>
26
+ <th>Product Name</span></th>
27
+ <th>SKU</th>
28
+ <th class="a-center">Qty</th>
29
+ <th>Price</th>
30
+ <th>Total</th>
31
+ </tr>
32
+ </thead>
33
+ <tbody class="even">
34
+
35
+ <?php
36
+ foreach ($cart_items as $item): ?>
37
+ <?php
38
+ $_qty += $item->getQty();
39
+ $_sub_total += $item->getPrice();
40
+ $_total += $item->getRowTotal();
41
+ ?>
42
+ <tr class="border">
43
+ <td><?php echo $item->getId(); ?></td>
44
+ <td><?php echo $item->getName(); ?></td>
45
+ <td><?php echo $item->getSku(); ?></td>
46
+ <td><?php echo $item->getQty(); ?></td>
47
+ <td><?php echo Mage::helper('core')->currency($item->getPrice(), true, false); ?></td>
48
+ <td><?php echo Mage::helper('core')->currency($item->getRowTotal(), true, false); ?></td>
49
+ </tr>
50
+ <?php endforeach; ?>
51
+ <tfoot>
52
+ <tr>
53
+ <td colspan="3"></td>
54
+ <td><?php echo $_qty; ?></td>
55
+ <td><?php echo Mage::helper('core')->currency($_sub_total, true, false); ?></td>
56
+ <td><?php echo Mage::helper('core')->currency($_total, true, false); ?></td>
57
+ </tr>
58
+ </tfoot>
59
+ </tbody>
60
+ </table>
61
+ </div>
62
+ </div>
app/design/adminhtml/default/default/template/campaigner/abandoned/details/tab/diagnostics/status.phtml ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ //$_order = $this->getOrder();
4
+ //$_send_field = $this->getSendField();
5
+ $_date_sent = $this->getCampaignerDate();
6
+ //$_can_send_orders = $this->canSendOrders();
7
+
8
+ $cart = Mage::helper('campaigner/diagnostic')->getAbandonedCart();
9
+
10
+ //Zend_debug::dump($quote->getData());
11
+
12
+ ?>
13
+
14
+ <div class="box-left">
15
+ <!--Diagnostic Information-->
16
+ <div class="entry-edit">
17
+ <div class="entry-edit-head">
18
+ <h4 class="icon-head head-edit-form fieldset-legend">Campaigner Diagnostics for Abandoned Cart</h4>
19
+ </div>
20
+ <div class="fieldset">
21
+ <table cellspacing="0" class="form-list">
22
+ <tbody>
23
+ <tr>
24
+ <td class="label"><label>Sent to Campaigner</label></td>
25
+ <td class="value"><strong>
26
+ <?php if ($_date_sent == null): ?>
27
+ <span style='color: red'>Not Sent</span>
28
+ <?php else: ?>
29
+ <span style='color: green'><?php echo $this->formatDate($_date_sent, 'medium', true); ?></span>
30
+ <?php endif; ?>
31
+ </strong></td>
32
+ </tr>
33
+ <tr>
34
+ <td class="label"><label>Campaigner Status</label></td>
35
+ <td class="value"><strong>
36
+ <?php if (!$this->isCampaignerEnabled()): ?>
37
+ <div style='color: red'>Disabled for this Store</div>
38
+ <?php elseif (!$this->isCampaignerSetup()): ?>
39
+ <div style='color: red'>Api Key Missing/Invalid</div>
40
+ <?php else: ?>
41
+ <div style='color: green'>Enabled</div>
42
+ <?php if (1 == 0 || !$this->isAbandonedEnabled()): ?>
43
+ <div style='color: red'>Abandoned Carts are disabled</div>
44
+ <?php endif; ?>
45
+ <?php endif; ?>
46
+ </strong></td>
47
+ </tr>
48
+ </tbody>
49
+ </table>
50
+ </div>
51
+ </div>
52
+ </div>
app/design/adminhtml/default/default/template/campaigner/abandoned/status.phtml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $status = $this->getAbandonedStatus(); ?>
2
+
3
+ <table class='abandoned_status'>
4
+ <tr>
5
+ <th>Store</th>
6
+ <th>Status</th>
7
+ <th>Last Run</th>
8
+ </tr>
9
+ <?php foreach ($status['stores'] as $state): ?>
10
+ <tr>
11
+ <td><?php echo $state['name']; ?></td>
12
+ <td><?php if ($state['enabled']): ?><span class='ab_ok'>Enabled</span><?php else: ?><span class='ab_ng'>Disabled</span><?php endif; ?></td>
13
+ <td><?php echo $state['last_run']; ?></td>
14
+ <td><?php if ($state['enabled']): ?><button onclick="setLocation('<?php echo $this->getUrl('*/*/run', array('store_id' => $state['id'])); ?>');"><span>Run Now</span></button><?php endif; ?></td>
15
+ </tr>
16
+ <?php endforeach; ?>
17
+ </table>
18
+ <br />
app/design/adminhtml/default/default/template/campaigner/diagnostics.phtml ADDED
@@ -0,0 +1,242 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $options = $this->getDiagnosticOptions(); ?>
2
+ <style>
3
+
4
+ .diagnostic_table { border-collapse: collapse; }
5
+ .diagnostic_table tr td { border: solid 1px; padding: 4px; }
6
+ .diagnostic_table tr td:first-child { font-weight: bold; }
7
+
8
+ a.campaigner_ec {
9
+ color: #fff;
10
+ padding-right: 30px;
11
+ display: block;
12
+ font-weight: bold;
13
+ text-decoration: none;
14
+ }
15
+
16
+ #spacer_output { height: 20px; }
17
+
18
+ a.campaigner_contract {
19
+ background: url(<?php echo $this->getSkinUrl("images/entry_edit_head_arrow_up.gif"); ?>) no-repeat scroll 100% 50% rgba(0, 0, 0, 0);
20
+ }
21
+ a.campaigner_expand {
22
+ background: url(<?php echo $this->getSkinUrl("images/entry_edit_head_arrow_down.gif"); ?>) no-repeat scroll 100% 50% rgba(0, 0, 0, 0);
23
+ }
24
+
25
+ table.diagnostic-options { width: 100%; }
26
+
27
+ .diagnostic-options td {
28
+ background: none repeat scroll 0 center rgba(0, 0, 0, 0) !important;
29
+ border: 0 none !important;
30
+ padding-bottom: 5px !important;
31
+ padding-left: 5px !important;
32
+ padding-top: 5px !important;
33
+ }
34
+
35
+ .diagnostic-note div { font-weight: bold; color: red; margin-left: 15px; }
36
+
37
+ </style>
38
+ <div>
39
+ <?php echo $this->getChildHtml('diagnostic_status') ?>
40
+
41
+ <div class="box-right">
42
+ <!--Account Information-->
43
+ <div class="entry-edit">
44
+ <div class="entry-edit-head">
45
+ <h4 class="icon-head head-account">Run Diagnostics</h4>
46
+ <div class="tools"></div>
47
+ </div>
48
+ <div class="fieldset">
49
+ <div class="hor-scroll">
50
+ <table cellspacing="0" class="diagnostic-options">
51
+ <tbody>
52
+ <!--<tr>
53
+ <td class="label"><label for="clear_after">Clear output before each diagnostic?</label></td>
54
+ <td class="value">
55
+ <input type='checkbox' id='clear_after' checked='checked' />
56
+ </td>
57
+ <td>&nbsp;</td>
58
+ </tr>-->
59
+ <?php foreach ($options as $option): ?>
60
+ <tr>
61
+ <td class='label'><?php echo $option['label'] ?></td>
62
+ <td class='diagnostic-button'>
63
+ <button id='<?php echo $option['code'] ?>_button' <?php if (isset($option['disabled'])) echo "disabled='disabled' class='disabled'"?>onclick="performRequest('<?php echo $option['code'] ?>')">Run Diagnostic</button>
64
+ </td>
65
+ <td class='diagnostic-note'>
66
+ <div>
67
+ <?php
68
+ if (isset($option['disabled_reason']))
69
+ echo "Note: " . $option['disabled_reason'];
70
+ else if (isset($option['note']))
71
+ echo "Note: " . $option['note'];
72
+ ?>
73
+ </div>
74
+ </td>
75
+ </tr>
76
+ <?php endforeach; ?>
77
+
78
+ <tr>
79
+ <td>
80
+ <form id='download_form' method='post' action='<?php echo $this->getUrl("campaigner_dashboard/admin_diagnostic/download") ?>'>
81
+ <input type='hidden' name='form_key' value='<?php echo $this->getFormKey(); ?>'></input>
82
+ <input type='hidden' name='output' id='hidden_output' value='' ></input>
83
+ <input type='hidden' name='filename' value='diagnostic_output.html' ></input>
84
+ </form>
85
+ <button id='download' disabled='disabled' class='disabled' onclick='return performDownload()'>Download</button>
86
+ </td>
87
+ </tr>
88
+ </tbody>
89
+ </table>
90
+ </div>
91
+ </div>
92
+ </div>
93
+ </div>
94
+
95
+ <div class='clear'> </div>
96
+ <div class="entry-edit">
97
+ <div class="entry-edit-head">
98
+ <h4 class="icon-head head-products"><a class='campaigner_ec campaigner_contract' id='diagnostic_output_toggle' href="#" onclick="return toggleSection('diagnostic_output');">Diagnostic Output</a></h4>
99
+ <div class="tools">
100
+ <a href='#' onclick="return selectText('diagnostic_output');">Select</a>
101
+ <!--<span> | </span>
102
+ <a href='#' onclick="return clear('output');">Clear</a>-->
103
+
104
+ </div>
105
+ </div>
106
+ <div id="campaigner_diagnostic_output_fieldset" class="fieldset">
107
+ <div class="hor-scroll">
108
+ <div id='diagnostic_output' style="height: 500px; overflow: scroll;">
109
+ </div>
110
+ </div>
111
+ </div>
112
+ </div>
113
+ <div id='spacer_output' style='display:none'> </div>
114
+
115
+ <div class='clear'> </div>
116
+ <div class="entry-edit">
117
+ <div class="entry-edit-head">
118
+ <h4 class="icon-head head-products"><a class='campaigner_ec campaigner_expand' id='diagnostic_details_toggle' href="#" onclick="return toggleSection('diagnostic_details');">Diagnostic Details</a></h4>
119
+ <div class="tools">
120
+ <a href='#' onclick="return selectText('diagnostic_details');">Select</a>
121
+ <!--<span> | </span>
122
+ <a href='#' onclick="return clear('details');">Clear</a>-->
123
+
124
+ </div>
125
+ </div>
126
+ <div id="campaigner_diagnostic_details_fieldset" class="fieldset" style='display:none'>
127
+ <div class="hor-scroll">
128
+ <div id='diagnostic_details' style="height: 500px; overflow: scroll;">
129
+ </div>
130
+ </div>
131
+ </div>
132
+ </div>
133
+
134
+ </div>
135
+
136
+ <script type='text/javascript'>
137
+ var FORM_KEY = "<?php echo $this->getFormKey();?>";
138
+ var item_id = <?php echo $this->getItemId(); ?>;
139
+ var store_id = <?php echo $this->getStoreId(); ?>;
140
+
141
+ function clear(section)
142
+ {
143
+ $("diagnostic_" + section).update("");
144
+ return false;
145
+ }
146
+
147
+ function toggleSection(section)
148
+ {
149
+ console.log(section);
150
+ $("campaigner_" + section + "_fieldset").toggle();
151
+
152
+ $(section + "_toggle").toggleClassName("camp_expand");
153
+ $(section + "_toggle").toggleClassName("camp_contract");
154
+
155
+ if (section == 'diagnostic_output')
156
+ $('spacer_output').toggle();
157
+
158
+ return false;
159
+ }
160
+
161
+ function selectText(containerid)
162
+ {
163
+ if (document.selection)
164
+ {
165
+ var range = document.body.createTextRange();
166
+ range.moveToElementText(document.getElementById(containerid));
167
+ range.select();
168
+ }
169
+ else if (window.getSelection)
170
+ {
171
+ var range = document.createRange();
172
+ range.selectNode(document.getElementById(containerid));
173
+ window.getSelection().addRange(range);
174
+ }
175
+
176
+ return false;
177
+ }
178
+
179
+ function showOutput(output)
180
+ {
181
+ $("diagnostic_output").insert(output);
182
+ }
183
+
184
+ function showDetails(details)
185
+ {
186
+ $("diagnostic_details").insert(details);
187
+ }
188
+
189
+ function showData(output, details)
190
+ {
191
+ $("hidden_output").value = "<div>" + output + "</div><hr /><h1>Report Details</h1><div>" + details + "</div>";
192
+ $("download").removeClassName('disabled');
193
+ $("download").removeAttribute('disabled');
194
+
195
+ showOutput(output);
196
+ showDetails(details);
197
+ }
198
+
199
+ function performRequest(method)
200
+ {
201
+ //if ($("clear_after").checked)
202
+ {
203
+ clear('output');
204
+ clear('details');
205
+ }
206
+
207
+ new Ajax.Request('<?php echo $this->getUrl('campaigner_dashboard/admin_diagnostic/ajax') ?>',
208
+ {
209
+ parameters: {isAjax: 'true', form_key: FORM_KEY, method: method, item_id: item_id, store_id: store_id},
210
+ onSuccess: function(transport)
211
+ {
212
+ try
213
+ {
214
+ if (transport.responseText.isJSON())
215
+ {
216
+ var response = transport.responseText.evalJSON()
217
+ if (response.error)
218
+ {
219
+ alert(response.message);
220
+ }
221
+ if(response.ajaxExpired && response.ajaxRedirect)
222
+ {
223
+ setLocation(response.ajaxRedirect);
224
+ }
225
+
226
+ showData(response.output,response.details);
227
+ }
228
+ }
229
+ catch (e)
230
+ {
231
+ showOutput(transport.responseText);
232
+ }
233
+ }
234
+ });
235
+ }
236
+
237
+ function performDownload()
238
+ {
239
+ $("download_form").submit();
240
+ return false;
241
+ }
242
+ </script>
app/design/adminhtml/default/default/template/campaigner/latest/status.phtml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $status = $this->getLatestStatus(); ?>
2
+
3
+ <table class='abandoned_status'>
4
+ <tr>
5
+ <th>Store</th>
6
+ <th>Status</th>
7
+ <th>Last Run</th>
8
+ </tr>
9
+ <?php foreach ($status['stores'] as $state): ?>
10
+ <tr>
11
+ <td><?php echo $state['name']; ?></td>
12
+ <td><?php if ($state['enabled']): ?><span class='ab_ok'>Enabled</span><?php else: ?><span class='ab_ng'>Disabled</span><?php endif; ?></td>
13
+ <td><?php echo $state['last_run']; ?></td>
14
+ <td><?php if ($state['enabled']): ?><button onclick="setLocation('<?php echo $this->getUrl('*/*/run', array('store_id' => $state['id'])); ?>');"><span>Run Now</span></button><?php endif; ?></td>
15
+ </tr>
16
+ <?php endforeach; ?>
17
+ </table>
18
+ <br />
app/design/adminhtml/default/default/template/campaigner/order/view/tab/diagnostics/status.phtml ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $_order = $this->getOrder();
4
+ $_send_field = $this->getSendField();
5
+ $_date_sent = $this->getCampaignerDate();
6
+ $_can_send_orders = $this->canSendOrders();
7
+
8
+ ?>
9
+
10
+ <div class="box-left">
11
+ <!--Diagnostic Information-->
12
+ <div class="entry-edit">
13
+ <div class="entry-edit-head">
14
+ <h4 class="icon-head head-edit-form fieldset-legend">Campaigner Diagnostics for <?php echo Mage::helper('sales')->__('Order # %s', $_order->getRealOrderId()) ?></h4>
15
+ </div>
16
+ <div class="fieldset">
17
+ <table cellspacing="0" class="form-list">
18
+ <tbody>
19
+ <tr>
20
+ <td class="label"><label>Sent to Campaigner</label></td>
21
+ <td class="value"><strong>
22
+ <?php if ($_date_sent == null): ?>
23
+ <span style='color: red'>Not Sent</span>
24
+ <?php else: ?>
25
+ <span style='color: green'><?php echo $this->formatDate($_date_sent, 'medium', true); ?></span>
26
+ <?php endif; ?>
27
+ </strong></td>
28
+ </tr>
29
+ <?php if ($_send_field == 'status'): ?>
30
+ <?php $send_status_list = $this->getStatusList(); ?>
31
+ <tr>
32
+ <td class="label"><label>Send on Status</label></td>
33
+ <td class="value"><strong>
34
+ <span id="send_on_status">
35
+ <?php echo implode("<br />",$send_status_list); ?>
36
+ </span></strong>
37
+ </td>
38
+ </tr>
39
+ <tr>
40
+ <td class="label"><label>Order Status</label></td>
41
+ <td class="value"><strong><span id="order_status"><?php echo $_order->getStatusLabel() ?></span></strong></td>
42
+ </tr>
43
+ <?php else: ?>
44
+ <?php $send_state_list = $this->getStateList(); ?>
45
+ <tr>
46
+ <td class="label"><label>Send on State</label></td>
47
+ <td class="value"><strong>
48
+ <span id="send_on_state">
49
+ <?php echo implode("<br />",$send_state_list); ?>
50
+ </span></strong>
51
+ </td>
52
+ </tr>
53
+ <tr>
54
+ <td class="label"><label>Order State</label></td>
55
+ <td class="value"><strong><span id="order_state"><?php echo $this->getOrderState() ?></span></strong></td>
56
+ </tr>
57
+ <?php endif; ?>
58
+
59
+ <tr>
60
+ <td class="label"><label>Campaigner Status</label></td>
61
+ <td class="value"><strong>
62
+ <?php if (!$this->isCampaignerEnabled()): ?>
63
+ <div style='color: red'>Disabled for this Store</div>
64
+ <?php elseif (!$this->isCampaignerSetup()): ?>
65
+ <div style='color: red'>Api Key Missing/Invalid</div>
66
+ <?php else: ?>
67
+ <div style='color: green'>Enabled</div>
68
+ <?php if (!$this->isSendOrdersEnabled()): ?>
69
+ <div style='color: red'>Sending orders is disabled</div>
70
+ <?php endif; ?>
71
+ <?php endif; ?>
72
+ </strong></td>
73
+ </tr>
74
+ </tbody>
75
+ </table>
76
+ </div>
77
+ </div>
78
+ </div>
app/design/adminhtml/default/default/template/campaigner/system/config/fieldset/hint.phtml ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $setup = Mage::helper('campaigner')->config('setup') == 1;
4
+ $locked = Mage::helper('campaigner')->config('locked') == 1;
5
+ $api_username = Mage::helper('campaigner')->config('api_username');
6
+ $api_password = Mage::helper('campaigner')->config('api_password');
7
+ $abandoned_status = Mage::helper('campaigner')->getAbandonedStatus();
8
+ $ab_enabled = $this->getAbandonedEnabled();
9
+ $last_run = $abandoned_status['cron_last_run'];
10
+ $last_run_label = "Cron Last Run";
11
+
12
+ $status_message = "Invalid API Username or Password";
13
+
14
+ if ($locked) {
15
+ $status_message = "Too many failed login attempts. Account is temporarily locked.";
16
+ }
17
+
18
+ ?>
19
+ <div class="campaigner-notice">
20
+ <h4>
21
+ <?php if (!$this->isWebsiteConfig()): ?>
22
+ <div class='abandoned'>Abandoned Cart Processing: <?php if ($ab_enabled) : ?><span class='ab_ok'>Enabled</span><?php else: ?><span class='ab_ng'>Disabled</span><?php endif; ?> - <?php echo $last_run_label ?>: <?php echo $abandoned_status['cron_last_run'] ?> - <button onclick="window.location='<?php echo $this->getUrl('campaigner_dashboard/admin_abandoned/index'); ?>'; return false;" id="campaigner_details">Details</button></div>
23
+ <?php endif; ?>
24
+ <strong>Campaigner Integration v<?php echo $this->getCampaignerVersion() ?><?php if (!$setup && strlen($api_username) > 0): ?> - <span class='ab_ng'><?php echo $status_message ?></span><?php endif; ?></strong>
25
+ </h4>
26
+ </div>
27
+ <script type='text/javascript'>
28
+ var setup = <?php echo $setup == true ? 'true' : 'false'; ?>;
29
+
30
+ document.observe('dom:loaded', function()
31
+ {
32
+ if (setup) {
33
+ $('row_campaigner_general_api_instructions').hide();
34
+ } else {
35
+ $$('#campaigner_general table.form-list tbody tr').each(function(item) {
36
+ var id = item.readAttribute('id');
37
+ var id_parts = id.split('_');
38
+
39
+ if (id_parts[0] == 'row') {
40
+ var name = id_parts.slice(3).join('_');
41
+ switch (name)
42
+ {
43
+ case 'api_validation':
44
+ case 'heading_general':
45
+ case 'info':
46
+ case 'api_username':
47
+ case 'api_password': break;
48
+ default: $(id).remove(); break;
49
+ }
50
+ }
51
+ });
52
+ }
53
+ });
54
+ </script>
app/design/adminhtml/default/default/template/campaigner/system/config/form/field/api.phtml ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $valid = $this->isValid();
3
+
4
+ $element = $this->getElement();
5
+
6
+ //$enabled = $this->isLoggingEnabled();
7
+ ?>
8
+ <div id="<?php echo $this->getElement()->getHtmlId(); ?>" style='display:none'></div>
9
+ <div class='campaigner_api_status'>
10
+ <div id='campaigner_status_indicator' class='<?php if ($valid) echo "api_valid"; else echo "api_invalid" ?>'><?php if ($valid) echo "Valid"; else echo "Invalid" ?></div>
11
+
12
+ <input type='hidden' name='groups[general][fields][old_api_username][value]' value='<?php echo $this->getCurrentApiUsername(); ?>' />
13
+ <input type='hidden' name='groups[general][fields][old_api_password][value]' value='<?php echo $this->getCurrentApiPassword(); ?>' />
14
+ <button id='apikey_validator' onclick='return performValidation();'>Validate</button>
15
+ </div>
16
+
17
+ <script type='text/javascript'>
18
+
19
+ validate_url = '<?php echo $this->getUrl('campaigner_dashboard/admin_troubleshooting/validate'); ?>';
20
+
21
+ function performValidation()
22
+ {
23
+ var api_username = $("campaigner_general_api_username").value;
24
+ var api_password = $("campaigner_general_api_password").value;
25
+
26
+ var indicator = $("campaigner_status_indicator");
27
+
28
+ indicator.update("Validating...");
29
+ indicator.removeClassName("api_valid");
30
+ indicator.removeClassName("api_invalid");
31
+ indicator.addClassName("api_validating");
32
+
33
+ new Ajax.Request(validate_url + (validate_url.match(new RegExp('\\?')) ? '&isAjax=true' : '?isAjax=true' ),
34
+ {
35
+ parameters : {api_username: api_username, api_password: api_password},
36
+ method : 'post',
37
+ onSuccess : function(transport)
38
+ {
39
+ if (transport.responseText.isJSON())
40
+ {
41
+ var response = transport.responseText.evalJSON()
42
+
43
+ if (response.valid)
44
+ {
45
+ indicator.removeClassName("api_validating");
46
+ indicator.addClassName("api_valid");
47
+ $("campaigner_status_indicator").update("Valid");
48
+ }
49
+ else
50
+ {
51
+ indicator.removeClassName("api_validating");
52
+ indicator.addClassName("api_invalid");
53
+ $("campaigner_status_indicator").update(response.message);
54
+ }
55
+
56
+ //console.log(response);
57
+ }
58
+ }
59
+ });
60
+
61
+ return false;
62
+ }
63
+ </script>
app/design/adminhtml/default/default/template/campaigner/system/config/form/field/array.phtml ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package default_default
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+
28
+ <?php
29
+ $_htmlId = $this->getHtmlId() ? $this->getHtmlId() : '_' . uniqid();
30
+
31
+ $_colspan = 2;
32
+ if (!$this->_addAfter) {
33
+ $_colspan -= 1;
34
+ }
35
+ $_colspan = $_colspan > 1 ? 'colspan="' . $_colspan . '"' : '';
36
+
37
+
38
+ ?>
39
+
40
+ <div id="<?php echo $this->getElement()->getHtmlId(); ?>" style='display:none'></div>
41
+ <div class="grid" id="grid<?php echo $_htmlId ?>">
42
+ <table cellpadding="0" cellspacing="0" class="border">
43
+ <tbody>
44
+ <tr class="headings" id="headings<?php echo $_htmlId ?>">
45
+ <?php foreach ($this->_columns as $columnName => $column):?>
46
+ <th><?php echo $column['label'] ?></th>
47
+ <?php endforeach;?>
48
+ <th <?php echo $_colspan?>></th>
49
+ </tr>
50
+ <tr id="addRow<?php echo $_htmlId ?>">
51
+ <td colspan="<?php echo count($this->_columns) ?>"></td>
52
+ <td <?php echo $_colspan?>>
53
+ <button style="" onclick="" class="scalable add" type="button" id="addToEndBtn<?php echo $_htmlId ?>">
54
+ <span><?php echo $this->_addButtonLabel ?></span>
55
+ </button>
56
+ </td>
57
+ </tr>
58
+ </tbody>
59
+ </table>
60
+ <input type="hidden" name="<?php echo $this->getElement()->getName() ?>[__empty]" value="" />
61
+ </div>
62
+ <div id="empty<?php echo $_htmlId ?>">
63
+ <button style="" onclick="" class="scalable add" type="button" id="emptyAddBtn<?php echo $_htmlId ?>">
64
+ <span><?php echo $this->_addButtonLabel ?></span>
65
+ </button>
66
+ </div>
67
+
68
+ <script type="text/javascript">
69
+ //<![CDATA[
70
+ // create row creator
71
+ var arrayRow<?php echo $_htmlId ?> = {
72
+ // define row prototypeJS template
73
+ template : new Template(
74
+ '<tr id="#{_id}">'
75
+ <?php foreach ($this->_columns as $columnName => $column):?>
76
+ +'<td>'
77
+ +'<?php echo $this->_renderCellTemplate($columnName)?>'
78
+ +'<\/td>'
79
+ <?php endforeach;?>
80
+ <?php if ($this->_addAfter):?>
81
+ +'<td><button onclick="" class="scalable add" type="button" id="addAfterBtn#{_id}"><span><?php echo Mage::helper('adminhtml')->__('Add after') ?><\/span><\/button><\/td>'
82
+ <?php endif;?>
83
+ +'<td><button onclick="arrayRow<?php echo $_htmlId ?>.del(\'#{_id}\')" class="scalable delete" type="button"><span><?php echo Mage::helper('adminhtml')->__('Delete') ?><\/span><\/button><\/td>'
84
+ +'<\/tr>'
85
+ ),
86
+
87
+ rowsCount : 0,
88
+
89
+ add : function(templateData, insertAfterId)
90
+ {
91
+ // generate default template data
92
+ if ('' == templateData) {
93
+ var d = new Date();
94
+ var templateData = {
95
+ <?php foreach ($this->_columns as $columnName => $column):?>
96
+ <?php echo $columnName ?> : '',
97
+ <?php endforeach;?>
98
+ _id : '_' + d.getTime() + '_' + d.getMilliseconds()
99
+ };
100
+ }
101
+
102
+ // insert before last row
103
+ if ('' == insertAfterId) {
104
+ Element.insert($('addRow<?php echo $_htmlId ?>'), {before: this.template.evaluate(templateData)});
105
+ }
106
+ // insert after specified row
107
+ else {
108
+ Element.insert($(insertAfterId), {after: this.template.evaluate(templateData)});
109
+ }
110
+
111
+ <?php if ($this->_addAfter):?>
112
+ Event.observe('addAfterBtn' + templateData._id, 'click', this.add.bind(this, '', templateData._id));
113
+ <?php endif;?>
114
+
115
+ this.rowsCount += 1;
116
+ },
117
+
118
+ del : function(rowId)
119
+ {
120
+ $(rowId).remove();
121
+ this.rowsCount -= 1;
122
+ if (0 == this.rowsCount) {
123
+ this.showButtonOnly();
124
+ }
125
+ },
126
+
127
+ showButtonOnly : function()
128
+ {
129
+ $('grid<?php echo $_htmlId ?>').hide();
130
+ $('empty<?php echo $_htmlId ?>').show();
131
+ }
132
+ }
133
+
134
+ // bind add action to "Add" button in last row
135
+ Event.observe('addToEndBtn<?php echo $_htmlId ?>', 'click', arrayRow<?php echo $_htmlId ?>.add.bind(arrayRow<?php echo $_htmlId ?>, '', ''));
136
+
137
+ // add existing rows
138
+ <?php
139
+ $_addAfterId = "headings{$_htmlId}";
140
+
141
+ //Zend_debug::dump($this->getArrayRows());
142
+ foreach ($this->getArrayRows() as $_rowId => $_row) {
143
+
144
+ $_row['_selected_' . $_row['campaigner']] = "selected=\"selected\"";
145
+ $_row['_selected_' . $_row['magento']] = "selected=\"selected\"";
146
+
147
+ echo "arrayRow{$_htmlId}.add(" . $_row->toJson() . ", '{$_addAfterId}');\n";
148
+ $_addAfterId = $_rowId;
149
+ }
150
+ ?>
151
+
152
+ // initialize standalone button
153
+ $('empty<?php echo $_htmlId ?>').hide();
154
+ Event.observe('emptyAddBtn<?php echo $_htmlId ?>', 'click', function () {
155
+ $('grid<?php echo $_htmlId ?>').show();
156
+ $('empty<?php echo $_htmlId ?>').hide();
157
+ arrayRow<?php echo $_htmlId ?>.add('', '');
158
+ });
159
+
160
+ // if no rows, hide grid and show button only
161
+ <?php if (!$this->getArrayRows()):?>
162
+ arrayRow<?php echo $_htmlId ?>.showButtonOnly();
163
+ <?php endif;?>
164
+
165
+ // toggle the grid, if element is disabled (depending on scope)
166
+ <?php if ($this->getElement()->getDisabled()):?>
167
+ toggleValueElements({checked:true}, $('grid<?php echo $_htmlId ?>').parentNode);
168
+ <?php endif;?>
169
+ //]]>
170
+ </script>
app/design/adminhtml/default/default/template/campaigner/system/config/form/field/diagnostics.phtml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $element = $this->getElement();
3
+
4
+ $enabled = $this->getDiagnosticStatus();
5
+ ?>
6
+ <div id="<?php echo $this->getElement()->getHtmlId(); ?>" style='display:none'></div>
7
+ <span class='<?php echo $enabled ? "ab_ok" : "ab_ng" ?>'><?php echo $enabled ? "Enabled" : "Disabled" ?></span>
8
+ <br />
9
+ <br />
10
+ <button id='campaigner_send_trouble' onClick="view_details(); return false;">Change Troubleshooting Settings</button>
11
+ <script type='text/javascript'>
12
+
13
+ function view_details()
14
+ {
15
+ var form = $('config_edit_form');
16
+ var logging_url = '<?php echo Mage::helper('campaigner')->getAdminUrl("campaigner_dashboard/admin_troubleshooting/", array('tab' => 'troubleshooting_view_tabs_trouble_settings')); ?>';
17
+
18
+ window.location = logging_url;
19
+ }
20
+ </script>
app/design/adminhtml/default/default/template/campaigner/system/config/form/field/export/date_range.phtml ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div id="<?php echo $this->getElement()->getHtmlId(); ?>" style='display:none'></div>
2
+ <span>From: </span><input style="width: 75px;" type="text" name="order_export_from" id="order_export_from" value="<?php echo $this->getFromDate() ?>" class="input-text">
3
+ <img src="<?php echo $this->getSkinUrl('images/grid-cal.gif'); ?>" alt="Select From Date" class="v-middle" title="Select From Date" id="from_trig">
4
+ <span>&nbsp;&nbsp;&nbsp; to: </span>
5
+ <input style="width: 75px;" type="text" name="order_export_to" id="order_export_to" value="<?php echo $this->getToDate() ?>" class="input-text">
6
+ <img src="<?php echo $this->getSkinUrl('images/grid-cal.gif'); ?>" alt="Select To Date" class="v-middle" title="Select To Date" id="to_trig">
7
+ <div class='camp_orders_found'>
8
+ <strong>Orders Found: </strong><span id='orders_found'><?php echo $this->getOrdersCount() ?></span>
9
+ </div>
10
+ <script type='text/javascript'>
11
+ var store = <?php echo Mage::helper('campaigner')->getAdminStore(); ?>;
12
+ var start_from = '<?php echo $this->getFromDate() ?>';
13
+ var start_to = '<?php echo $this->getToDate() ?>';
14
+ var orders_count = '<?php echo $this->getOrdersCount(); ?>';
15
+
16
+ var check_from = parseDate(start_from);
17
+
18
+ function setButtonState()
19
+ {
20
+ if (orders_count == 0 || orders_count == 'Unknown')
21
+ toggleValueElements({checked:true}, $('campaigner_export_orders').parentNode);
22
+ else
23
+ toggleValueElements({checked:false}, $('campaigner_export_orders').parentNode);
24
+ }
25
+
26
+ function parseDate(date_string)
27
+ {
28
+ var date_parts = date_string.split('-');
29
+ return new Date(date_parts[0],date_parts[1] - 1,date_parts[2]);
30
+ }
31
+
32
+ var calendarSetupObject = {
33
+ inputField : "order_export_from",
34
+ ifFormat : "%Y-%m-%d",
35
+ showTime : "false",
36
+ button : "from_trig",
37
+ align : "Bl",
38
+ singleClick : true,
39
+ disableFunc : function(date)
40
+ {
41
+ if (date < check_from)
42
+ return true;
43
+ }
44
+ }
45
+ Calendar.setup(calendarSetupObject);
46
+
47
+ var calendarSetupObject2 = {
48
+ inputField : "order_export_to",
49
+ ifFormat : "%Y-%m-%d",
50
+ showTime : "false",
51
+ button : "to_trig",
52
+ align : "Bl",
53
+ singleClick : true,
54
+ disableFunc : function(date)
55
+ {
56
+ if (date < check_from)
57
+ return true;
58
+ }
59
+ }
60
+ Calendar.setup(calendarSetupObject2);
61
+
62
+ var url = '<?php echo $this->getUrl("campaigner_dashboard/admin_export/count/"); ?>';
63
+
64
+ $('campaigner_export_include_already_sent').observe('change', function(event)
65
+ {
66
+ if (!validateDates())
67
+ return;
68
+
69
+ dateRangeChange();
70
+ });
71
+
72
+ $('order_export_from').observe('change', function(event)
73
+ {
74
+ if (!validateDates())
75
+ return;
76
+
77
+ dateRangeChange();
78
+ });
79
+
80
+ $('order_export_to').observe('change', function(event)
81
+ {
82
+ if (!validateDates())
83
+ return;
84
+
85
+ // Check if the date is < to date
86
+ dateRangeChange();
87
+ });
88
+
89
+ function validateDates()
90
+ {
91
+ // Check if the date is < starting date or > to date
92
+ var from = parseDate($('order_export_from').value);
93
+ var to = parseDate($('order_export_to').value);
94
+
95
+ if (from < check_from)
96
+ {
97
+ $('order_export_from').value = start_from;
98
+ return false;
99
+ }
100
+
101
+ if (to < check_from)
102
+ {
103
+ $('order_export_to').value = start_to;
104
+ return false;
105
+ }
106
+
107
+ if (from > to)
108
+ {
109
+ var temp = $('order_export_from').value;
110
+
111
+ $('order_export_from').value = $('order_export_to').value;
112
+ $('order_export_to').value = temp;
113
+ }
114
+
115
+ return true;
116
+ }
117
+
118
+ function dateRangeChange()
119
+ {
120
+ var from = $('order_export_from').value;
121
+ var to = $('order_export_to').value;
122
+ var include = $('campaigner_export_include_already_sent').value;
123
+
124
+ $('orders_found').update("???");
125
+
126
+ new Ajax.Request(url + (url.match(new RegExp('\\?')) ? '&isAjax=true' : '?isAjax=true' ), {
127
+ parameters : {from: from, to: to, include: include, store: store},
128
+ method : 'post',
129
+ loaderArea : false,
130
+ onSuccess : function(transport)
131
+ {
132
+ //console.log(transport.responseText);
133
+ var response = transport.responseText;
134
+ orders_count = response;
135
+ $('orders_found').update(response);
136
+ setButtonState();
137
+ }
138
+ });
139
+ }
140
+
141
+ document.observe("dom:loaded", function() {
142
+ setButtonState();
143
+ });
144
+ </script>
app/design/adminhtml/default/default/template/campaigner/system/config/form/field/export/orders.phtml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div id="<?php echo $this->getElement()->getHtmlId(); ?>" style='display:none'></div>
2
+ <button id='campaigner_export_orders' onClick="perform_order_export(); return false;">Export Orders</button>
3
+ <script type='text/javascript'>
4
+ function perform_order_export()
5
+ {
6
+ var form = $('config_edit_form');
7
+ var from = form['order_export_from'];
8
+ var to = form['order_export_to'];
9
+ var store = <?php echo Mage::helper('campaigner')->getAdminStore(); ?>;
10
+ var include = form['groups[export][fields][include_already_sent][value]'];
11
+ var url = '<?php echo $this->getUrl("campaigner_dashboard/admin_export/orders/"); ?>';
12
+
13
+ url += 'export_from/' + $(from).getValue() + '/export_to/' + $(to).getValue() + '/include_already_sent/' + $(include).getValue() + '/store/' + store + '/';
14
+
15
+ window.open(url);
16
+ }
17
+ <?php if ($this->getElement()->getDisabled()):?>
18
+ toggleValueElements({checked:true}, $('campaigner_export_orders').parentNode);
19
+ <?php endif;?>
20
+ </script>
app/design/adminhtml/default/default/template/campaigner/system/config/form/field/export/products.phtml ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div id="<?php echo $this->getElement()->getHtmlId(); ?>" style='display:none'></div>
2
+ <button id='campaigner_export_products' onClick="perform_product_export(); return false;">Export Products</button>
3
+ <script type='text/javascript'>
4
+ function perform_product_export()
5
+ {
6
+ var form = $('config_edit_form');
7
+ var include_disabled = form['groups[export][fields][include_disabled][value]'];
8
+ var url = '<?php echo $this->getUrl("campaigner_dashboard/admin_export/products/"); ?>';
9
+ var store = <?php echo Mage::helper('campaigner')->getAdminStore() ?>;
10
+
11
+ url += 'include_disabled/' + $(include_disabled).getValue() + '/';
12
+ if (store != 0)
13
+ url += 'store/' + store;
14
+
15
+ window.open(url);
16
+ }
17
+
18
+ <?php if ($this->getElement()->getDisabled()):?>
19
+ toggleValueElements({checked:true}, $('campaigner_export_products').parentNode);
20
+ <?php endif;?>
21
+ </script>
app/design/adminhtml/default/default/template/campaigner/system/config/form/field/info.phtml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <a href='http://www.campaigner.com' target='_blank'><img src='<?php echo $this->getSkinUrl('campaigner/logo.png') ?>' style='width:225px; margin-bottom: 10px;'></a>
2
+ <p>Customer Data and Purchase Behavior Sync by <a href='http://www.campaigner.com' target='_blank'>www.campaigner.com</a></p>
3
+ <p>Copyright &copy;<?php echo date("Y") ?></p>
4
+ <br />
5
+ <p>Download our <a href='http://campaigner.com/downloads/papers/magentoSetupGuide.pdf'>Magento Setup Guide</a> for detailed information on each feature or view the <a href="<?php echo $this->getUrl('campaigner_dashboard/admin_troubleshooting/index') ?>">Help</a> page.</p>
6
+ <p>Please contact support (<a href='mailto:support@campaigner.com'>support@campaigner.com</a>) with any questions that you have.</p>
7
+ <br />
8
+ <?php if ($this->isWebsiteConfig()): ?>
9
+ <strong>Campaigner can only be configured at the Store or Default Level</strong>
10
+ <?php else: ?>
11
+ <hr />
12
+ <?php endif; ?>
app/design/adminhtml/default/default/template/campaigner/system/config/form/field/logging.phtml ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $element = $this->getElement();
3
+
4
+ $status = $this->getLoggingStatus();
5
+
6
+ //Zend_debug::dump($status);
7
+ //$enabled = $this->isLoggingEnabled();
8
+ $enabled_for_store = $this->isEnabledForStore();
9
+ //$store = Mage::getSingleton('adminhtml/config_data')->getStore();
10
+
11
+
12
+ $enabled = $status['enabled'];
13
+ ?>
14
+ <div id="<?php echo $this->getElement()->getHtmlId(); ?>" style='display:none'></div>
15
+ <span class='<?php echo $enabled ? "ab_ok" : "ab_ng" ?>'><?php echo $enabled ? "Enabled" : "Disabled" ?></span>
16
+ <?php if ($enabled): ?>
17
+ <?php if (!$enabled_for_store): ?><span class='ab_ng'>(Not for this store!)</span><?php endif; ?>
18
+ <div id='campaigner_trouble_details'>
19
+ <table>
20
+ <tr>
21
+ <td>Start Date:</td>
22
+ <td><?php echo $this->getStartDate() ?></td>
23
+ </tr>
24
+ <tr>
25
+ <td>Log File:</td>
26
+ <td><?php echo $this->getLogInfo() ?></td>
27
+ </tr>
28
+ </table>
29
+ </div>
30
+ <?php endif; ?>
app/design/adminhtml/default/default/template/campaigner/system/config/form/field/note.phtml ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ <div id="<?php echo $this->getElement()->getHtmlId(); ?>" style='display:none'></div>
2
+ <p>You can retrieve an API Key by going to your Campaigner account and clicking on Account Setup, then navigating to the API Keys tab.</p>
3
+ <br />
4
+ <p>If you do not have an Campaigner account, please email us at <a href="mailto:Sales@Campaigner.com">Sales@Campaigner.com</a> or call 916-439-6948. You can also visit our website at <a href="http://www.Campaigner.com">http://www.Campaigner.com</a> to learn more about this integration and other features that we offer.</p>
app/design/adminhtml/default/default/template/campaigner/system/config/form/field/signup/test.phtml ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div id="<?php echo $this->getElement()->getHtmlId(); ?>" style='display:none'></div>
2
+ <button id='campaigner_signup_test' onClick="perform_signup_test(); return false;">Test Signup</button>
3
+ <script type='text/javascript'>
4
+ function perform_signup_test()
5
+ {
6
+ var form = $('config_edit_form');
7
+ var signup_url = form['campaigner_general_signup_url'];
8
+ var width = form['campaigner_general_signup_width'];
9
+ var height = form['campaigner_general_signup_height'];
10
+ var delay = form['campaigner_general_signup_delay'];
11
+ var opacity = form['campaigner_general_signup_opacity'];
12
+ var store = <?php echo Mage::helper('campaigner')->getAdminStore(); ?>;
13
+ var url = '<?php echo Mage::app()->getStore(Mage::helper('campaigner')->getAdminStore())->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK); ?>';
14
+
15
+ url += '?signup_test=true&url=' + encodeURIComponent($(signup_url).getValue());
16
+ url += '&width=' + $(width).getValue();
17
+ url += '&height=' + $(height).getValue();
18
+ url += '&delay=' + $(delay).getValue();
19
+ url += '&opacity=' + $(opacity).getValue();
20
+
21
+ window.open(url);
22
+ }
23
+ <?php if ($this->getElement()->getDisabled()):?>
24
+ toggleValueElements({checked:true}, $('campaigner_signup_test').parentNode);
25
+ <?php endif;?>
26
+ </script>
app/design/adminhtml/default/default/template/campaigner/system/config/form/field/smtp.phtml ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $element = $this->getElement();
4
+
5
+ $status = Mage::helper('campaigner')->getRelayStatus();
6
+
7
+ $enabled = $status['relay'] == 1;
8
+ ?>
9
+ <div id="<?php echo $this->getElement()->getHtmlId(); ?>" style='display:none'></div>
10
+ <div id='relay_status_container'>
11
+ <div id='campaigner_relay_status'><?php
12
+ if ($enabled) {
13
+ echo "Enabled";
14
+ if ($status['smtp_disable'] == 1) {
15
+ echo "<span class='smtp_disable'>(SMTP DISABLED)</span>";
16
+ }
17
+ }
18
+ else {
19
+ echo "Disabled";
20
+ }
21
+ ?></div>
22
+ <button onclick='showSMTP(); return false;' id='relay_setup_button'>Setup</button>
23
+ </div>
24
+
25
+ <script type='text/javascript'>
26
+
27
+ smtp_url = '<?php echo Mage::helper('campaigner')->getAdminUrl('adminhtml/system_config/edit/section/system'); ?>';
28
+
29
+ function showSMTP()
30
+ {
31
+ window.location = smtp_url;
32
+ return false;
33
+ }
34
+ </script>
app/design/adminhtml/default/default/template/campaigner/system/config/form/field/smtp/test.phtml ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $element = $this->getElement();
3
+ ?>
4
+ <div id="<?php echo $this->getElement()->getHtmlId(); ?>" style='display:none'></div>
5
+ <div class='campaigner_smtp_status'>
6
+
7
+ <label for='smtp_test_email'>Email: </label>
8
+ <input type='text' id='smtp_test_email' value='' />
9
+ <button id='smtp_test' onclick='performValidation(); return false;'>Test</button>
10
+ <div id='campaigner_smtp_status'></div>
11
+ </div>
12
+
13
+ <script type='text/javascript'>
14
+
15
+ validate_smtp_url = '<?php echo $this->getUrl('campaigner_dashboard/admin_troubleshooting/testSmtp'); ?>';
16
+ var indicator = $("campaigner_smtp_status");
17
+ var store_id = <?php echo Mage::helper('campaigner')->getCurrentStore() ?>;
18
+
19
+ function showMessage(msg, type)
20
+ {
21
+ if (type == 'error') {
22
+ msg = "Error: " + msg;
23
+ }
24
+
25
+ indicator.update("<span class='smtp_" + type + "'>" + msg + "</span>");
26
+ }
27
+
28
+ function performValidation()
29
+ {
30
+ var port = $("system_smtp_campaigner_smtp_port").value;
31
+ var encryption = $("system_smtp_campaigner_smtp_encryption").value;
32
+ var username = $("system_smtp_campaigner_smtp_username").value;
33
+ var password = $("system_smtp_campaigner_smtp_password").value;
34
+ var email = $("smtp_test_email").value;
35
+ var disable = $("system_smtp_disable").value;
36
+
37
+ if (disable == "1") {
38
+ showMessage("Email Communications are disabled","error");
39
+ return false;
40
+ }
41
+
42
+ if (email == "") {
43
+ showMessage("Please enter an email address","error");
44
+ return false;
45
+ }
46
+
47
+ if (username == "") {
48
+ showMessage("Please enter a username","error");
49
+ return false;
50
+ }
51
+
52
+ if (password == "") {
53
+ showMessage("Please enter a password","error");
54
+ return false;
55
+ }
56
+
57
+ indicator.update("Sending test email...");
58
+
59
+ new Ajax.Request(validate_smtp_url + (validate_smtp_url.match(new RegExp('\\?')) ? '&isAjax=true' : '?isAjax=true' ),
60
+ {
61
+ parameters : {port: port, encryption: encryption, username: username, password: password, email: email, store_id: store_id},
62
+ method : 'post',
63
+ onSuccess : function(transport)
64
+ {
65
+ if (transport.responseText.isJSON())
66
+ {
67
+ var response = transport.responseText.evalJSON()
68
+
69
+ if (response.success)
70
+ {
71
+ showMessage("Success!","success");
72
+ }
73
+ else
74
+ {
75
+ showMessage(response.message,"error");
76
+ }
77
+
78
+ console.log(response);
79
+ }
80
+ }
81
+ });
82
+
83
+ return false;
84
+ }
85
+
86
+ function relayChange(event)
87
+ {
88
+ if (!$("system_smtp_set_return_path"))
89
+ return;
90
+ var value = $("system_smtp_campaigner_use_smtp_relay").value;
91
+
92
+ if (value == 1) {
93
+ $("system_smtp_set_return_path").value = 0;
94
+ $("system_smtp_set_return_path").disable();
95
+ $("row_system_smtp_return_path_email").hide();
96
+ } else {
97
+ $("system_smtp_set_return_path").enable();
98
+ }
99
+ }
100
+
101
+ document.observe('dom:loaded', function()
102
+ {
103
+ relayChange();
104
+ $("system_smtp_campaigner_use_smtp_relay").observe('change', relayChange);
105
+ });
106
+ </script>
app/design/adminhtml/default/default/template/campaigner/system/config/setup_check.phtml ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php /* Check if the user has logged out before trying Campaigner for the first time */ ?>
2
+
3
+ <?php if ($this->getRequest()->getParam('section') == 'campaigner'):
4
+ $session = Mage::getSingleton('admin/session');
5
+ try
6
+ {
7
+ $acl_valid = $session->isAllowed(
8
+ $session->getData('acl')->get("admin/system/config/campaigner")->getResourceId()
9
+ );
10
+ }
11
+ catch (Exception $e)
12
+ {
13
+ $acl_valid = false;
14
+ }
15
+
16
+ if (!$acl_valid): ?>
17
+ <div id="messages">
18
+ <ul class="messages">
19
+ <li class="warning-msg">
20
+ <ul>
21
+ <li>
22
+ <span><?php echo $this->__("To finish installing Campaigner, log out of Magento and log back in.") ?></span>
23
+ </li>
24
+ </ul>
25
+ </li>
26
+ </ul>
27
+ </div>
28
+ <?php endif;
29
+ endif; ?>
app/design/adminhtml/default/default/template/campaigner/system/convert/profile/export.phtml ADDED
@@ -0,0 +1,221 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $this->getBatchModel() ?>
2
+ <?php $importData = $this->getImportData();?>
3
+ <style type="text/css" >
4
+ ul { list-style-type:none; padding:0; margin:0; }
5
+ li { margin-left:0; border:1px solid #ccc; margin:2px; padding:2px 2px 2px 2px; font:normal 13px sans-serif; }
6
+ img { margin-right:5px; }
7
+ </style>
8
+ <script type="text/javascript">
9
+ var FORM_KEY = "<?php echo $this->getFormKey();?>";
10
+ var export_type = "<?php echo $this->getExportType(); ?>";
11
+ </script>
12
+ <ul>
13
+ <li>
14
+ <img src="<?php echo $this->getSkinUrl('images/note_msg_icon.gif')?>" class="v-middle" style="margin-right:5px"/>
15
+ <?php echo $this->__("Starting Campaigner Export...");?>
16
+ </li>
17
+ <li style="background-color:#FFD;">
18
+ <img src="<?php echo $this->getSkinUrl('images/fam_bullet_error.gif');?>" class="v-middle" style="margin-right:5px"/>
19
+ <?php
20
+ if (count($importData) == 0)
21
+ echo $this->__("No items found to export!");
22
+ else
23
+ echo $this->__("Warning: Please do not close the window during export process!");
24
+ ?>
25
+ </li>
26
+ </ul>
27
+ <ul id="profileRows">
28
+ <li id="liFinished" style="display: <?php if (count($importData) == 0) echo 'block'; else echo 'none' ?>;">
29
+ <img src="<?php echo $this->getSkinUrl('images/note_msg_icon.gif');?>" class="v-middle" style="margin-right:5px"/>
30
+ <?php echo $this->__("Finished Export!.");?>
31
+ <span id='download_link'>
32
+
33
+ </span>
34
+ </li>
35
+ </ul>
36
+ <script type="text/javascript">
37
+ var d = new Date();
38
+ var countOfStartedProfiles = 0;
39
+ var filename = d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate() + "T" + d.getHours() + "_" + d.getMinutes();
40
+ var countOfUpdated = 0;
41
+ var countOfError = 0;
42
+ var importData = <?php echo $this->jsonEncode($importData);?>;
43
+ var totalRecords = <?php echo $this->getBatchItemsCount();?>;
44
+ var config = <?php echo $this->getBatchConfigJson();?>;
45
+ var group = <?php echo $this->getBatchSize() ?>;
46
+ var upload_ed = <?php echo $this->getUploadStatus() ?>;
47
+ var store = <?php echo $this->getStore() ?>;
48
+ </script>
49
+ <script type="text/javascript">
50
+
51
+ function execImportData()
52
+ {
53
+ if (importData.length == 0)
54
+ {
55
+ // Finished
56
+ $("updatedRows_img").src = config.styles.message.icon;
57
+ $("updatedRows").style.backgroundColor = config.styles.message.bg;
58
+ Element.insert($("liFinished"), {before: config.tpl.evaluate({
59
+ style: "background-color:"+config.styles.message.bg,
60
+ image: config.styles.message.icon,
61
+ text: config.tplSccTxt.evaluate({updated:(countOfUpdated-countOfError)}),
62
+ id: "updatedFinish"
63
+ })});
64
+
65
+ if (upload_ed)
66
+ {
67
+ Element.insert($("liFinished"), {before: config.tpl.evaluate({
68
+ style: "background-color:"+config.styles.message.bg,
69
+ image: config.styles.message.icon,
70
+ text: config.tplUploading.evaluate({updated:countOfUpdated}),
71
+ id: "uploadingFinish"
72
+ })});
73
+ }
74
+
75
+ if ($("liBeforeFinish"))
76
+ {
77
+ Element.insert($("liFinished"), {before: $("liBeforeFinish")});
78
+ $("liBeforeFinish").show();
79
+ }
80
+
81
+ new Ajax.Request("<?php echo $this->getUrl('*/*/batchFinish');?>",
82
+ {
83
+ method: "post",
84
+ parameters: {filename: filename, form_key: FORM_KEY, export_type: export_type, store: store},
85
+ onComplete: function(transport)
86
+ {
87
+ if (transport.responseText.isJSON())
88
+ {
89
+ var response = transport.responseText.evalJSON();
90
+
91
+ Element.insert($("download_link"), {bottom: "<a href='" + response.download_link + "'>Download File</a>"});
92
+ if (response.error)
93
+ {
94
+ Element.insert($("liFinished"), {before: config.tpl.evaluate({
95
+ style: "background-color:"+config.styles.error.bg,
96
+ image: config.styles.error.icon,
97
+ text: response.error.escapeHTML(),
98
+ id: "error-finish"
99
+ })});
100
+ }
101
+ }
102
+
103
+ if ($("before-finish-wait-img"))
104
+ $("before-finish-wait-img").hide();
105
+
106
+ $('liFinished').show();
107
+ }
108
+ });
109
+ }
110
+ else
111
+ {
112
+ if (group > 1)
113
+ {
114
+ var ids = [];
115
+ for (var i = 0; i < group; i++)
116
+ {
117
+ ids.push(importData.shift());
118
+
119
+ if (importData.length == 0)
120
+ break;
121
+ }
122
+
123
+ sendImportData(ids,"id[]");
124
+
125
+ }
126
+ else
127
+ {
128
+ sendImportData(importData.shift(),"id");
129
+ }
130
+ }
131
+ }
132
+
133
+ function sendImportData(id,id_name)
134
+ {
135
+ var data = {}
136
+ var updated = 1;
137
+
138
+ data[id_name] = id;
139
+
140
+ if (typeof(id) != 'number')
141
+ updated = id.length;
142
+
143
+ if (!config.tpl)
144
+ {
145
+ config.tpl = new Template(config.template);
146
+ config.tplTxt = new Template(config.text);
147
+ config.tplSccTxt = new Template(config.successText);
148
+ config.tplUploading = new Template(config.uploadText);
149
+ }
150
+ if (!$("updatedRows"))
151
+ {
152
+ Element.insert($("liFinished"), {before: config.tpl.evaluate({
153
+ style: "background-color: #FFD;",
154
+ image: config.styles.loader,
155
+ text: config.tplTxt.evaluate({updated:countOfUpdated, percent:getPercent()}),
156
+ id: "updatedRows"
157
+ })});
158
+ }
159
+ countOfStartedProfiles++;
160
+
161
+ if (!data.form_key)
162
+ data.form_key = FORM_KEY;
163
+
164
+ data.export_type = export_type;
165
+
166
+ data.filename = filename;
167
+
168
+ new Ajax.Request("<?php echo $this->getUrl("*/*/batchRun/");?>",
169
+ {
170
+ method: "post",
171
+ parameters: data,
172
+ onSuccess: function(transport)
173
+ {
174
+ countOfStartedProfiles --;
175
+ countOfUpdated += updated;
176
+ if (transport.responseText.isJSON())
177
+ addProfileRow(transport.responseText.evalJSON());
178
+ else
179
+ {
180
+ Element.insert($("updatedRows"), {before: config.tpl.evaluate({
181
+ style: "background-color: "+config.styles.error.bg,
182
+ image: config.styles.error.icon,
183
+ text: transport.responseText.escapeHTML(),
184
+ id: "error-" + countOfStartedProfiles
185
+ })
186
+ });
187
+ countOfError ++;
188
+ }
189
+ execImportData();
190
+ }
191
+ });
192
+ }
193
+
194
+ function getPercent()
195
+ {
196
+ return Math.ceil((countOfUpdated/totalRecords)*1000)/10;
197
+ }
198
+
199
+ function addProfileRow(data)
200
+ {
201
+ if (data.errors.length > 0)
202
+ {
203
+ for (var i=0, length=data.errors.length; i<length; i++)
204
+ {
205
+ Element.insert($("updatedRows"), {before: config.tpl.evaluate({
206
+ style: "background-color:"+config.styles.error.bg,
207
+ image: config.styles.error.icon,
208
+ text: data.errors[i],
209
+ id: "id-" + (countOfUpdated + i + 1)
210
+ })});
211
+ countOfError ++;
212
+ }
213
+ }
214
+ $("updatedRows_status").update(config.tplTxt.evaluate({updated:countOfUpdated, percent:getPercent()}));
215
+ }
216
+ </script>
217
+
218
+ <script type="text/javascript">
219
+ if (totalRecords > 0)
220
+ execImportData();
221
+ </script>
app/design/adminhtml/default/default/template/campaigner/troubleshooting/status.phtml ADDED
@@ -0,0 +1,199 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $status = $this->getLoggingStatus(); ?>
2
+ <?php if ($status['enabled']): ?>
3
+ <div class="campaigner-status">
4
+ <table>
5
+ <tr id='camp_status_row'>
6
+ <td>Logging: <span id='status_state'>Enabled</span></td>
7
+ <td>Started On: <span><?php echo $status['start_date'] ?></span></td>
8
+ <td>Duration: <span><?php echo $status['duration_display'] ?></span></td>
9
+ <td>Time Remaining: <span id='camp_time_remaining'></span></td>
10
+ </tr>
11
+ </table>
12
+ </div>
13
+
14
+ <script type='text/javascript'>
15
+
16
+ var FORM_KEY = "<?php echo $this->getFormKey();?>";
17
+
18
+ function getStatus()
19
+ {
20
+ new Ajax.Request('<?php echo $this->getUrl('campaigner_dashboard/admin_troubleshooting/ajax') ?>',
21
+ {
22
+ parameters: {isAjax: 'true', form_key: FORM_KEY, method: "status"},
23
+ loaderArea : false,
24
+ onSuccess: function(transport)
25
+ {
26
+ try
27
+ {
28
+ if (transport.responseText.isJSON())
29
+ {
30
+ var response = transport.responseText.evalJSON()
31
+ if (response.error)
32
+ {
33
+ alert(response.message);
34
+ }
35
+ if(response.ajaxExpired && response.ajaxRedirect)
36
+ {
37
+ setLocation(response.ajaxRedirect);
38
+ }
39
+
40
+ var status = response.status;
41
+
42
+ if (status.enabled)
43
+ {
44
+ $("status_state").update("Enabled");
45
+
46
+ seconds = status.duration - status.seconds;
47
+
48
+ statusCounter.setSeconds(seconds);
49
+ statusCounter.start();
50
+ $('status').value = "yes";
51
+ }
52
+ else
53
+ {
54
+ $("status_state").update("Disabled");
55
+ $("camp_status_row").addClassName("disabled");
56
+ $('status').value = "no";
57
+ }
58
+ }
59
+ }
60
+ catch (e)
61
+ {
62
+ //showOutput(transport.responseText);
63
+ }
64
+ }
65
+ });
66
+ }
67
+
68
+ function Countdown(options)
69
+ {
70
+ var timer,
71
+ instance = this,
72
+ seconds = options.seconds || 10,
73
+ updateStatus = options.onUpdateStatus || function () {},
74
+ counterEnd = options.onCounterEnd || function () {};
75
+
76
+ this.setSeconds = function(new_seconds)
77
+ {
78
+ options.seconds = new_seconds;
79
+ }
80
+
81
+ function decrementCounter()
82
+ {
83
+ //console.log(statusCounter.seconds);
84
+ updateStatus(seconds);
85
+
86
+ if (seconds === 0)
87
+ {
88
+ counterEnd();
89
+ instance.stop();
90
+ getStatus();
91
+ }
92
+ seconds--;
93
+ }
94
+
95
+ this.start = function ()
96
+ {
97
+ clearInterval(timer);
98
+ timer = 0;
99
+ seconds = options.seconds;
100
+ timer = setInterval(decrementCounter, 1000);
101
+ };
102
+
103
+ this.stop = function ()
104
+ {
105
+ clearInterval(timer);
106
+ };
107
+ }
108
+
109
+ var statusCounter = new Countdown(
110
+ {
111
+ seconds:<?php echo $status['duration'] - $status['seconds'] ?>,
112
+ onUpdateStatus: function(sec)
113
+ {
114
+ var delta = Math.abs(sec);
115
+
116
+ // calculate (and subtract) whole days
117
+ var days = Math.floor(delta / 86400);
118
+ delta -= days * 86400;
119
+
120
+ // calculate (and subtract) whole hours
121
+ var hours = Math.floor(delta / 3600) % 24;
122
+ delta -= hours * 3600;
123
+
124
+ // calculate (and subtract) whole minutes
125
+ var minutes = Math.floor(delta / 60) % 60;
126
+ delta -= minutes * 60;
127
+
128
+ // what's left is seconds
129
+ var seconds = delta % 60;
130
+
131
+ var display = "";
132
+
133
+ if (days > 0)
134
+ {
135
+ display += " " + days + " day";
136
+ if (days != 1)
137
+ display += "s";
138
+ }
139
+
140
+ if (hours > 0)
141
+ {
142
+ display += " " + hours + " hour";
143
+ if (hours != 1)
144
+ display += "s";
145
+ }
146
+
147
+ if (minutes > 0)
148
+ {
149
+ display += " " + minutes + " minute";
150
+ if (minutes != 1)
151
+ display += "s";
152
+ }
153
+
154
+ display += " " + seconds + " second";
155
+
156
+ if (seconds != 1)
157
+ display += "s";
158
+
159
+ $('camp_time_remaining').update(display);
160
+ }
161
+ });
162
+
163
+ statusCounter.start();
164
+
165
+ var last_focus = 0;
166
+
167
+ function onBlur()
168
+ {
169
+ console.log('window blur');
170
+ };
171
+ function onFocus()
172
+ {
173
+ if (last_focus != 0)
174
+ {
175
+ var current_time = new Date().getTime();
176
+ if (current_time - last_focus > 60000)
177
+ {
178
+ last_focus = current_time;
179
+ getStatus();
180
+ }
181
+ }
182
+ else
183
+ last_focus = new Date().getTime();
184
+ };
185
+
186
+ if (/*@cc_on!@*/false)
187
+ { // check for Internet Explorer
188
+ document.onfocusin = onFocus;
189
+ //document.onfocusout = onBlur;
190
+ }
191
+ else
192
+ {
193
+ window.onfocus = onFocus;
194
+ //window.onblur = onBlur;
195
+ }
196
+
197
+ </script>
198
+
199
+ <?php endif; ?>
app/design/adminhtml/default/default/template/campaigner/troubleshooting/view.phtml ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php echo $this->getFormInitScripts() ?>
2
+ <?php echo $this->getChildHtml('troubleshooting_status'); ?>
3
+ <div class="content-header">
4
+ <?php echo $this->getHeaderHtml() ?>
5
+ <p class="form-buttons"><?php echo $this->getButtonsHtml('header') ?></p>
6
+ </div>
7
+ <?php echo $this->getFormHtml() ?>
8
+ <?php if ($this->hasFooterButtons()): ?>
9
+ <div class="content-footer">
10
+ <p class="form-buttons"><?php echo $this->getButtonsHtml('footer') ?></p>
11
+ </div>
12
+ <?php endif; ?>
13
+ <script type="text/javascript">
14
+ editForm = new varienForm('edit_form', '<?php echo $this->getValidationUrl() ?>');
15
+ </script>
16
+ <?php echo $this->getFormScripts() ?>
app/design/adminhtml/default/default/template/campaigner/troubleshooting/view/form.phtml ADDED
@@ -0,0 +1 @@
 
1
+ <div class="entry-edit" id="troubleshooting_view"></div>
app/design/adminhtml/default/default/template/campaigner/troubleshooting/view/tab/download.phtml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="entry-edit">
2
+ <div class="entry-edit-head">
3
+ <h4>Download Report to send to Campaigner</h4>
4
+ </div>
5
+ <div id="_accountbase_fieldset" class="fieldset ">
6
+ <div class="hor-scroll">
7
+ <p>Click the button below to download the troubleshooting report.</p>
8
+ <p>You can then send this report along with your contact information and description of the problem you are having to <a href="mailto:<?php echo $this->getTroubleEmail() ?>?subject=<?php echo $this->getTroubleSubject() ?>"><?php echo $this->getTroubleEmail() ?></a>.</p>
9
+ <button onclick="setLocation('<?php echo $this->getUrl('campaigner_dashboard/admin_troubleshooting/download/') ?>'); return false;">Download Report</button>
10
+ </div>
11
+ </div>
12
+ </div>
app/design/adminhtml/default/default/template/campaigner/troubleshooting/view/tab/help.phtml ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $customer_fields = $this->getCustomerFields();
3
+ $address_fields = $this->getAddressFields();
4
+ $shipping_fields = $this->getShippingFields();
5
+ ?>
6
+
7
+ <div class='campaigner_help'>
8
+ <h1>Help</h1>
9
+ <h2>Configuration</h2>
10
+ <h3>General Configuration</h3>
11
+ <h4>Enabled</h4>
12
+ <p>Must be set to Yes.</p>
13
+ <h4>API Username/Password</h4>
14
+ <p>You must enter the API credentials that for your Campaigner account.</p>
15
+ <p>After entering your API Username and Password, press the "Validate" button and once the credentials have been validated press the "Save Config" button.</p>
16
+ <h4>Subscribe on Checkout</h4>
17
+ <p>This will give you the option to choose your subscription type during the checkout process. You can make your subscription an opt-in, opt-out, or force a subscription for everyone.</p>
18
+ <p>If you have a customized checkout, this feature may not work properly as we cannot display the subscribe checkbox on customized checkouts without modification. </p>
19
+ <p>The "Force Subscription" option should still work as it does not depend on interacting with your custom checkout. Please contact us if you require assistance integrating Campaigner with your custom checkout.</p>
20
+ <h4>List</h4>
21
+ <p>These are all of your Lists from within Campaigner. Choose which List you wish to subscribe your customers too. This is required to be able to email them from your Campaigner account.</p>
22
+ <h4>Save Latest Order Information</h4>
23
+ <p>Selecting Yes will update a subscribers record with detailed information for up to 3 products per order.</p>
24
+ <p>For each product, the following fields will be sent:</p>
25
+ <table class='map_field_list'>
26
+ <tr>
27
+ <td>Product Name<br />Parent Name (for complex products)<br />SKU<br />URL<br />ImageURL<br />Description<br />Cost</td>
28
+ </tr>
29
+ </table>
30
+ <p>This information can be used to personalize your emails for Product Review emails, Thank You emails, etc.. Old information
31
+ will be erased when a new order is made.</p>
32
+
33
+ <h3>Field Mappings</h3>
34
+ <h4>Customer Fields</h4>
35
+ <p>This allows you to setup the customer fields you wish to map to Campaigner.</p>
36
+ <?php if (count($customer_fields) == 0): ?>
37
+ <p>We are unable to find any customers in your database and so we cannot load a list of available fields. Please create a customer and try again.</p>
38
+ <?php else: ?>
39
+ <p>Here is a list of potential fields available for you to send as part of the customer mapping. These fields are taken directly from your customer object, but note that not all of them are good candidates to map:</p>
40
+ <table class='map_field_list'>
41
+ <tr>
42
+ <?php foreach ($customer_fields as $field_column): ?>
43
+ <td>
44
+ <?php foreach ($field_column as $field): ?>
45
+ <?php echo $field ?><br />
46
+ <?php endforeach; ?>
47
+ </td>
48
+ <?php endforeach; ?>
49
+ </tr>
50
+ </table>
51
+ <?php endif; ?>
52
+ <h4>Address Fields</h4>
53
+ <p>This allows you to setup the address fields you wish to map to Campaigner.</p>
54
+ <?php if (count($address_fields) == 0): ?>
55
+ <p>We are unable to find any customer addresses in your database and so we cannot load a list of available fields. Please create a customer address and try again.</p>
56
+ <?php else: ?>
57
+ <p>Here is a list of potential fields available for you to send as part of the billing address mapping. These fields are taken directly from your billing address object, but note that not all of them are good candidates to map:</p>
58
+ <table class='map_field_list'>
59
+ <tr>
60
+ <?php foreach ($address_fields as $field_column): ?>
61
+ <td>
62
+ <?php foreach ($field_column as $field): ?>
63
+ <?php echo $field ?><br />
64
+ <?php endforeach; ?>
65
+ </td>
66
+ <?php endforeach; ?>
67
+ </tr>
68
+ </table>
69
+ <?php endif; ?>
70
+ <p>The following custom address fields are available:</p>
71
+ <table class='map_field_custom'>
72
+ <tr>
73
+ <td>state_code</td>
74
+ <td>The region_id field is used to load the 2 character state code for the address.</td>
75
+ </tr>
76
+ </table>
77
+ <h4>Shipping Fields</h4>
78
+ <p>This allows you to setup the shipping fields you wish to map to Campaigner.</p>
79
+ <p>The following fields are available for mapping:</p>
80
+ <table class='map_field_list'>
81
+ <tr>
82
+ <?php foreach ($shipping_fields as $field_column): ?>
83
+ <td>
84
+ <?php foreach ($field_column as $field): ?>
85
+ <?php echo $field ?><br />
86
+ <?php endforeach; ?>
87
+ </td>
88
+ <?php endforeach; ?>
89
+ </tr>
90
+ </table>
91
+
92
+ <h3>Abandoned Carts</h3>
93
+ <h4>Add Abandoned Carts to Campaigner</h4>
94
+ <p>Selecting Yes will update a subscribers record with detailed information
95
+ for up to 3 products per abandoned cart.</p>
96
+ <p>For each product, the following fields will be sent:</p>
97
+ <table class='map_field_list'>
98
+ <tr>
99
+ <td>Product Name<br />Parent Name (for complex products)<br />SKU<br />URL<br />ImageURL<br />Description<br />Cost</td>
100
+ </tr>
101
+ </table>
102
+ <p>This information can be used to personalize your emails for Abandoned Cart emails. Old
103
+ information will be erased when a new cart is abandoned.</p>
104
+ <h4>Abandoned Time</h4>
105
+ <p>This is the amount of time before a cart is considered abandoned.</p>
106
+ <h4>Abandoned List</h4>
107
+ <p>This is the List that you will put abandoned shoppers into. Some companies like
108
+ to make this a separate List that a user can unsubscribe from.</p>
109
+ <h4>Capture Guest Emails?</h4>
110
+ <p>When enabled, this feature will capture guest emails from various forms within the site to
111
+ be used with Abandoned Carts.</p>
112
+ <h3>Abandoned Cart Sequences</h3>
113
+ <h4>Add a sequence value to each abandoned cart?</h4>
114
+ <p>This will allow you to assign a sequence of values to your subscribers, one for each abandoned shopping cart. For every abandoned cart, the next value in the list will be applied and over write any past values that were assigned.</p>
115
+ <h4>Sequence Database Field</h4>
116
+ <p>This is the field within Campaigner that the sequence will be stored in.</p>
117
+ <h4>Sequence Options</h4>
118
+ <p>Put a list of sequences that will help you identify and filter for A/B testing your abandoned cart
119
+ process. This can include any identifying information and can include as many as you want, enter one per line.</p>
120
+ <p>Example:</p>
121
+ <div class='sequence_example'>
122
+ A<br />
123
+ B<br />
124
+ C<br />
125
+ </div>
126
+ <p>Or</p>
127
+ <div class='sequence_example'>
128
+ 1<br />2<br />3<br />4<br />5
129
+ </div>
130
+ <!-- ABANDONED CARTS -->
131
+ <h2><a name='abandoned_carts'></a>Abandoned Carts</h2>
132
+ <p>In order for abandoned carts to be processed automatically, cron must be running on your server.</p>
133
+ <p>The Abandoned Cart process is scheduled to run every hour on the hour so if you are seeing a warning icon <img src="<?php echo Mage::getDesign()->getSkinUrl('images/warning_msg_icon.gif') ?>" /> next to your cron Last Run Date (and the module has not just been recently installed) then you need to verify that cron is running properly.</p>
134
+ <p>Please visit this <a href="http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/how_to_setup_a_cron_job">link</a> for detailed information on cron setup in the Magento Wiki.</p>
135
+ <h2><a name='diagnostics'></a>Diagnostics</h2>
136
+ <p>Diagnostics allow you to test specific parts of the Campaigner process. They can be enabled in the settings tab.</p>
137
+ <p>If Campaigner is not enabled or setup for a store, some diagnostics can still be performed but the output may not be 100% accurate depending on what configuration values have been specified.</p>
138
+ <h3>Orders</h3>
139
+ <p>To run Diagnostics on an order, go to the Order View page and select the <strong>Campaigner Diagnostics</strong> tab on the left side of the screen.</p>
140
+ <h3>Abandoned Carts</h3>
141
+ <p>To run Diagnostics on an abandoned cart, go to the <a href='<?php echo $this->getUrl('campaigner_dashboard/admin_abandoned/index') ?>'>Campaigner Abandoned Carts Page</a> and click on a row to run diagnostics on that cart.</p>
142
+ </div>
app/design/adminhtml/default/default/template/campaigner/troubleshooting/view/tab/info.phtml ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $environment = $this->getEnvironmentInfo();
3
+ $store_configuration = $this->getConfigurationInfo();
4
+ $row = "even";
5
+ ?>
6
+
7
+ <div class="entry-edit">
8
+ <div class="entry-edit-head">
9
+ <h4 class="icon-head"><?php echo Mage::helper('campaigner')->__('General Configuration') ?></h4>
10
+ </div>
11
+ </div>
12
+ <div class="grid np">
13
+ <div class="hor-scroll">
14
+ <table cellspacing="0" class="data ed-config-table">
15
+ <thead>
16
+ <tr class="headings">
17
+ <th>Setting</th>
18
+ <th>Value</th>
19
+ </tr>
20
+ </thead>
21
+ <?php foreach ($environment as $key => $value): ?>
22
+ <tbody class="<?php echo $row ?>">
23
+ <tr class='border'>
24
+ <td><?php echo $key; ?></td>
25
+ <td><?php echo $value; ?></td>
26
+ </tr>
27
+ </tbody>
28
+ <?php $row = ($row == 'even' ? 'odd' : 'even'); ?>
29
+ <?php endforeach; ?>
30
+ </table>
31
+ </div>
32
+ </div>
33
+ <br />
34
+ <?php foreach ($store_configuration as $code => $configuration): ?>
35
+ <div class="entry-edit">
36
+ <div class="entry-edit-head">
37
+ <h4 class="icon-head">Module Configuration for store: <?php echo $code ?></h4>
38
+ </div>
39
+ </div>
40
+ <div class="grid np">
41
+ <div class="hor-scroll">
42
+ <table cellspacing="0" class="data ed-config-table">
43
+ <thead>
44
+ <tr class="headings">
45
+ <th>Setting</th>
46
+ <th>Value</th>
47
+ </tr>
48
+ </thead>
49
+ <?php $row = 'even';
50
+ foreach ($configuration as $key => $value): ?>
51
+ <tbody class="<?php echo $row ?>">
52
+ <tr class='border'>
53
+ <td><?php echo $key; ?></td>
54
+ <td><?php echo $value; ?></td>
55
+ </tr>
56
+ </tbody>
57
+ <?php $row = ($row == 'even' ? 'odd' : 'even'); ?>
58
+ <?php endforeach; ?>
59
+ </table>
60
+ </div>
61
+ </div>
62
+ <br />
63
+ <?php endforeach; ?>
app/design/adminhtml/default/default/template/campaigner/troubleshooting/view/tab/log.phtml ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="entry-edit">
2
+ <div class="entry-edit-head">
3
+ <h4 class="icon-head"><?php echo Mage::helper('campaigner')->__('Campaigner Log File') ?></h4>
4
+ <div class="tools">
5
+ <a href='#' onclick="return performRequest('log_refresh',false);">Refresh</a>
6
+ <span> | </span>
7
+ <a href='#' onclick="return performRequest('erase_log',true);">Erase Log</a>
8
+ <span> | </span>
9
+ <a href='#' onclick="return performRequest('test_logging',false);">Test Logging</a>
10
+ </div>
11
+ </div>
12
+ <div class='logfile-fieldset'>
13
+ <div class='logfile-container'>
14
+ <div class="entry-logfile" id='logfile_contents'>
15
+ <pre><?php echo $this->getLogFile() ?></pre>
16
+ </div>
17
+ </div>
18
+ </div>
19
+ </div>
20
+
21
+ <script type='text/javascript'>
22
+ var FORM_KEY = "<?php echo $this->getFormKey();?>";
23
+
24
+ function showLogFile(contents)
25
+ {
26
+ $("logfile_contents").update("<pre>" + contents + "</pre>");
27
+ scrollToBottom();
28
+ }
29
+
30
+ function scrollToBottom()
31
+ {
32
+ var container = document.getElementById("logfile_contents");
33
+ container.scrollTop = container.scrollHeight;
34
+ }
35
+
36
+ function performRequest(method, get_confirmation)
37
+ {
38
+ if (get_confirmation == true)
39
+ {
40
+ if (!window.confirm("Are you sure?"))
41
+ return;
42
+ }
43
+ new Ajax.Request('<?php echo $this->getUrl('campaigner_dashboard/admin_troubleshooting/ajax') ?>',
44
+ {
45
+ parameters: {isAjax: 'true', form_key: FORM_KEY, method: method},
46
+ onSuccess: function(transport)
47
+ {
48
+ try
49
+ {
50
+ if (transport.responseText.isJSON())
51
+ {
52
+ var response = transport.responseText.evalJSON()
53
+ if (response.error)
54
+ {
55
+ alert(response.message);
56
+ }
57
+ if(response.ajaxExpired && response.ajaxRedirect)
58
+ {
59
+ setLocation(response.ajaxRedirect);
60
+ }
61
+
62
+ showLogFile(response.contents);
63
+ }
64
+ }
65
+ catch (e)
66
+ {
67
+ showOutput(transport.responseText);
68
+ }
69
+ }
70
+ });
71
+
72
+ return false;
73
+ }
74
+ </script>
app/design/adminhtml/default/default/template/campaigner/troubleshooting/view/tab/settings.phtml ADDED
@@ -0,0 +1,218 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $status = $this->getLoggingStatus();
3
+ $areas = Mage::helper('campaigner/troubleshooting')->getAreas();
4
+
5
+ $logging_enabled = $this->getSetting('logging_enabled') == 1;
6
+ $advanced_enabled = $this->getSetting('logging_advanced_enabled') == 1;
7
+
8
+ $diagnostic_enabled = Mage::helper('campaigner/troubleshooting')->isDiagnosticEnabled();
9
+
10
+ ?>
11
+
12
+ <div class="entry-edit">
13
+ <div class="entry-edit-head">
14
+ <h4>Troubleshooting Settings</h4>
15
+ </div>
16
+ <div id="_accountbase_fieldset" class="fieldset ">
17
+
18
+
19
+ <div class="hor-scroll">
20
+ <form id='campaigner_settings_form' action='<?php echo Mage::helper('campaigner')->getAdminUrl("campaigner_dashboard/admin_troubleshooting/save"); ?>' method='post'>
21
+ <input type="hidden" name="form_key" value="<?php echo $this->getFormKey(); ?>" />
22
+
23
+ <table cellspacing="0" class="form-list">
24
+ <tbody>
25
+ <tr class="system-fieldset-sub-head"><td colspan="2"><h4>Logging</h4></td></tr>
26
+ <tr>
27
+ <td class="label"><label for="logging_enabled">Enabled</label></td>
28
+ <td class="value">
29
+ <select id='logging_enabled' name='logging_enabled'>
30
+ <option value='yes'>Yes</option>
31
+ <option value='no' <?php if (!$logging_enabled) echo "selected='selected'" ?>>No</option>
32
+ </select>
33
+ </td>
34
+ </tr>
35
+ <tr id='logging_advanced_row' <?php if (!$logging_enabled) echo "style='display:none'" ?>>
36
+ <td class="label"><label for="logging_advanced_enabled">Advanced Settings</label></td>
37
+ <td class="value">
38
+ <select id='logging_advanced_enabled' name='logging_advanced_enabled'>
39
+ <option value='enabled'>Enabled</option>
40
+ <option value='disabled' <?php if (!$advanced_enabled) echo "selected='selected'" ?>>Disabled</option>
41
+ </select>
42
+ </td>
43
+ </tr>
44
+ </tbody>
45
+ </table>
46
+
47
+ <div id='advanced_settings' <?php if (!$logging_enabled || !$advanced_enabled) echo "style='display:none'" ?>>
48
+ <table cellspacing="0" class="form-list">
49
+ <tbody>
50
+ <tr>
51
+ <td class="label"><label for="logging_stores">Stores</label></td>
52
+ <td class="value">
53
+ <select id='logging_stores' name='logging_stores'>
54
+ <option value='all'>All</option>
55
+ <option value='selected' <?php if ($this->getSetting('logging_stores') == "selected") echo "selected='selected'" ?>>Selected</option>
56
+ </select>
57
+ </td>
58
+ </tr>
59
+ </table>
60
+ <table cellspacing="0" class='troubleshooting_details' id='troubleshooting_stores' <?php if ($this->getSetting('logging_stores') == "all") echo "style='display:none'" ?>>
61
+ <tbody>
62
+ <tr>
63
+ <th>Store Name</th>
64
+ <th>Logging</th>
65
+ </tr>
66
+ <?php $stores = $this->getArraySetting("logging_stores_selected"); ?>
67
+ <?php foreach ($status['stores'] as $store): ?>
68
+ <tr>
69
+ <td><?php echo $store['name'] ?> <?php if (!$store['campaigner_enabled']) echo "(disabled)"; ?></td>
70
+ <td align='center'>
71
+ <input type='checkbox' value='<?php echo $store['id'] ?>' name='logging_stores_selected[]' id='logging_stores_selected_<?php echo $store['id'] ?>' <?php if ($store['selected']) echo "checked='checked'"; ?> /></td>
72
+ </tr>
73
+ <?php endforeach; ?>
74
+
75
+ </tbody>
76
+ </table>
77
+
78
+ <table cellspacing="0" class="form-list">
79
+ <tbody>
80
+ <tr>
81
+ <td class="label"><label for="logging_areas">Areas</label></td>
82
+ <td class="value">
83
+ <select id='logging_areas' name='logging_areas'>
84
+ <option value='all'>All</option>
85
+ <option value='selected' <?php if ($this->getSetting('logging_areas') == "selected") echo "selected='selected'" ?>>Selected</option>
86
+ </select>
87
+
88
+ <table cellspacing="0" class='troubleshooting_details' id='troubleshooting_areas' <?php if ($this->getSetting('logging_areas') == "all") echo "style='display:none'" ?>>
89
+ <tbody>
90
+ <?php foreach ($status['areas'] as $key => $area): ?>
91
+ <tr>
92
+ <td><?php echo $area['label'] ?></td>
93
+ <td align='center'><input type='checkbox' value='<?php echo $key ?>' name='logging_areas_selected[]' id='logging_areas_selected_<?php echo $key ?>' <?php if ($area['selected']) echo "checked='checked'"; ?> /></td>
94
+ </tr>
95
+ <?php endforeach; ?>
96
+
97
+ </tbody>
98
+ </table>
99
+ </td>
100
+ </tr>
101
+ </table>
102
+
103
+
104
+ <table cellspacing="0" class="form-list">
105
+ <tbody>
106
+ <tr>
107
+ <td class="label"><label for="ip_address">IP Address</label></td>
108
+ <td class="value">
109
+ <textarea id='ip_address' name='ip_address'><?php echo $this->getSetting('logging_ip') ?></textarea>
110
+ <p id="note_ip_address" class="note"><span>Limit logging to specific IP addresses. For multiple addresses use a comma separated list.</span></p>
111
+ <p class='current_ip'><span class='your_ip'>Your IP:</span><span class='current_ip_address'><?php echo $this->getCurrentIP(); ?></span> <button onclick="return addIP();" class='scalable add'><span>Add</span></button></p>
112
+ </td>
113
+ </tr>
114
+ <tr>
115
+ <td class="label"><label for="duration">Duration</label></td>
116
+ <td class="value">
117
+ <?php $duration_options = $this->getDurationOptions();
118
+ $duration = $this->getSetting('logging_duration');
119
+ ?>
120
+ <select name='logging_duration' id='logging_duration'>
121
+ <?php foreach ($duration_options as $value => $label): ?>
122
+ <option value='<?php echo $value ?>' <?php if ($value == $duration) echo "selected='selected'" ?>><?php echo $label ?></option>
123
+ <?php endforeach; ?>
124
+ </select>
125
+ </td>
126
+ </tr>
127
+ </tbody>
128
+ </table>
129
+
130
+ </div>
131
+ <table cellspacing="0" class="form-list">
132
+ <tbody>
133
+ <tr class="system-fieldset-sub-head"><td colspan="2"><h4>Diagnostics</h4></td></tr>
134
+ <tr>
135
+ <td class="label"><label for="diagnostic_enabled">Enabled</label></td>
136
+ <td class="value">
137
+ <select id='diagnostic_enabled' name='diagnostic_enabled'>
138
+ <option value='1'>Yes</option>
139
+ <option value='0' <?php if (!$diagnostic_enabled) echo "selected='selected'" ?>>No</option>
140
+ </select>
141
+ </td>
142
+ </tr>
143
+ <tr>
144
+ <td class="label"></td>
145
+ <td class="value">
146
+ <button>Save Settings</button>
147
+ </td>
148
+ </tr>
149
+ </tbody>
150
+ </table>
151
+ </form>
152
+ <script type="text/javascript">
153
+
154
+ function addIP()
155
+ {
156
+ var current = $('ip_address').value;
157
+ if (current != "")
158
+ current += ",";
159
+
160
+ current += '<?php echo $this->getCurrentIP(); ?>';
161
+
162
+
163
+
164
+ console.log(current);
165
+
166
+ $('ip_address').value = current;
167
+
168
+ return false;
169
+ }
170
+
171
+ function toggle(evt, target, value)
172
+ {
173
+ var elem = Event.element(evt);
174
+
175
+ if (elem)
176
+ {
177
+ if (elem.value == value)
178
+ $(target).hide();
179
+ else
180
+ $(target).show();
181
+ }
182
+ }
183
+
184
+ function toggleStores(evt)
185
+ {
186
+ toggle(evt,'troubleshooting_stores','all');
187
+ }
188
+
189
+ function toggleAreas(evt)
190
+ {
191
+ toggle(evt,'troubleshooting_areas','all');
192
+ }
193
+
194
+ function toggleAdvanced(evt)
195
+ {
196
+ toggle(evt,'advanced_settings','disabled');
197
+ }
198
+
199
+ function toggleAdvancedRow(evt)
200
+ {
201
+ toggle(evt,'logging_advanced_row','no');
202
+
203
+ //console.log($('logging_advanced_enabled').value);
204
+ if ($('logging_advanced_enabled').value == 'enabled')
205
+ $('advanced_settings').show();
206
+ }
207
+
208
+ Event.observe('logging_stores', 'change', toggleStores);
209
+ Event.observe('logging_areas', 'change', toggleAreas);
210
+ Event.observe('logging_advanced_enabled', 'change', toggleAdvanced);
211
+ Event.observe('logging_enabled', 'change', toggleAdvancedRow);
212
+
213
+ // var ed_form = new varienForm('campaigner_settings_form' );
214
+ </script>
215
+ </div>
216
+ </div>
217
+ </div>
218
+
app/design/adminhtml/default/default/template/campaigner/troubleshooting/view/tab/submit.phtml ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php if ($this->isLogFileTooLarge()): ?>
2
+ <p class='log_note'><strong>Note:</strong> The log file is too large to send the entire file. Only the last <?php echo $this->getMaxLogFileSize() ?> will be sent.</p>
3
+ <p>To send the entire log, please compress the file and send it to <a href="mailto:<?php echo $this->getTroubleEmail() ?>?subject=<?php echo $this->getTroubleSubject() ?>"><?php echo $this->getTroubleEmail() ?></a>.<br />This file will be called <strong><?php echo $this->getLogFileName() ?></strong> and will most likely be located in the <strong>var/log</strong> folder in the root of your Magento Installation.</p>
4
+ <br />
5
+ <?php elseif ($this->getLogFileSize() == 0): ?>
6
+ <p class='log_note'><strong>Note:</strong> The log file is currently empty. Sending the report is not recommended until log data has been captured.</p>
7
+ <br />
8
+ <?php endif; ?>
9
+ <div class="entry-edit">
10
+ <div class="entry-edit-head">
11
+ <h4>Send Information to Campaigner</h4>
12
+ </div>
13
+ <div id="_accountbase_fieldset" class="fieldset ">
14
+ <div class="hor-scroll">
15
+ <form id='campaigner_submit_form' action='<?php echo $this->getUrl("campaigner_dashboard/admin_troubleshooting/send"); ?>' method='post'>
16
+ <input type="hidden" name="form_key" value="<?php echo $this->getFormKey(); ?>" />
17
+ <table cellspacing="0" class="form-list">
18
+ <tbody>
19
+ <tr>
20
+ <td class="label"><label for="customer_name">Your Name <span class="required">*</span></label></td>
21
+ <td class="value">
22
+ <input type="text" class="required-entry input-text required-entry" value="" name="customer_name" id="customer_name">
23
+ </td>
24
+ </tr>
25
+ <tr>
26
+ <td class="label"><label for="customer_email">Email <span class="required">*</span></label></td>
27
+ <td class="value">
28
+ <input type="text" class="input-text required-entry validate-email" value="" name="customer_email" id="customer_email">
29
+ </td>
30
+ </tr>
31
+ <tr>
32
+ <td class="label"><label for="customer_company">Company</label></td>
33
+ <td class="value">
34
+ <input type="text" class="input-text" value="" name="customer_company" id="customer_company">
35
+ </td>
36
+ </tr>
37
+ <tr>
38
+ <td class="label"><label for="customer_comments">Problem(s) encountered <span class="required">*</span></label></td>
39
+ <td class="value">
40
+ <textarea name='customer_comments' id='customer_comments' class='required-entry'></textarea>
41
+ </td>
42
+ </tr>
43
+ <tr>
44
+ <td class="label"></td>
45
+ <td class="value">
46
+ <button>Send to Campaigner</button>
47
+ </td>
48
+ </tr>
49
+ </tbody>
50
+ </table>
51
+ </form>
52
+ <script type="text/javascript">
53
+ var ed_form = new varienForm('campaigner_submit_form' );
54
+ </script>
55
+ </div>
56
+ </div>
57
+ </div>
app/design/frontend/base/default/layout/campaigner.xml ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+
3
+ <layout version="0.1.0">
4
+
5
+ <default>
6
+ <reference name="before_body_end">
7
+ <block type="campaigner/signup" name="campaigner_signup" as="campaigner_signup" template="campaigner/signup/form.phtml"/>
8
+ <block type="campaigner/capture" name="campaigner_capture" as="campaigner_capture" template="campaigner/capture/email.phtml"/>
9
+ </reference>
10
+ <reference name="head">
11
+ <action method="addCss" ifconfig="campaigner/general/active"><stylesheet>campaigner/campaigner.css</stylesheet></action>
12
+ </reference>
13
+ </default>
14
+
15
+ <checkout_onepage_review>
16
+ <reference name="checkout.onepage.review.info.items.after">
17
+ <block type="campaigner/checkout_subscribe" name="campaigner.subscribe" template="campaigner/checkout/subscribe.phtml" />
18
+ </reference>
19
+ </checkout_onepage_review>
20
+
21
+ <!-- Customer -->
22
+ <customer_account>
23
+ <reference name="head">
24
+ <action method="addItem" ifconfig="campaigner/general/active"><type>skin_js</type><name>campaigner/integration.js</name><params/></action>
25
+ </reference>
26
+ <reference name="customer_account_navigation">
27
+ <action method="addLink" ifconfig="campaigner/general/active" translate="label" module="campaigner">
28
+ <name>campaigner</name>
29
+ <path>campaigner/customer_account/index</path>
30
+ <label>Newsletter Subscriptions</label>
31
+ </action>
32
+ </reference>
33
+ </customer_account>
34
+
35
+ <customer_account_index>
36
+ <reference name="customer_account_dashboard_info">
37
+ <action method="setTemplate" ifconfig="campaigner/general/active">
38
+ <template>campaigner/customer/account/dashboard/info.phtml</template>
39
+ </action>
40
+ </reference>
41
+ </customer_account_index>
42
+
43
+ <campaigner_customer_account_index>
44
+ <label>Customer My Account Campaigner</label>
45
+ <update handle="customer_account"/>
46
+ <reference name="my.account.wrapper">
47
+ <block type="campaigner/customer_account_lists" name="campaigner_additionallists" template="campaigner/customer/account/lists.phtml" />
48
+ <block type="customer/account_dashboard" name="customer.account.link.back" template="customer/account/link/back.phtml"/>
49
+ </reference>
50
+ </campaigner_customer_account_index>
51
+ <!-- Customer -->
52
+ </layout>
app/design/frontend/base/default/template/campaigner/capture/email.phtml ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script type='text/javascript'>
2
+ document.observe("dom:loaded", function()
3
+ {
4
+ <?php foreach ($this->getFields() as $field): ?>
5
+ if ($('<?php echo $field ?>')) Event.observe('<?php echo $field ?>','change', capture);
6
+ <?php endforeach; ?>
7
+ });
8
+
9
+ function capture(event)
10
+ {
11
+ new Ajax.Request('<?php echo $this->getCaptureUrl() ?>', { method:'post', parameters: {email: $(this).getValue()} });
12
+ }
13
+ </script>
app/design/frontend/base/default/template/campaigner/checkout/subscribe.phtml ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $check = $this->checkStatus();
3
+ $auto = (($check === 1) OR ($check === 3));
4
+ ?>
5
+ <script type="text/javascript">
6
+ addSubscribeToPost = function (element)
7
+ {
8
+ if ($('campaigner-subscribe'))
9
+ $('campaigner-subscribe').remove();
10
+
11
+ if (element.checked)
12
+ {
13
+ var inputer = new Element('input', { name: "campaigner_subscribe", id: "campaigner-subscribe", value: "1", type: "hidden" });
14
+ try
15
+ {
16
+ Element.insert(Form.findFirstElement(payment.form), inputer);
17
+ }
18
+ catch (notelem)
19
+ {
20
+ $("co-payment-form").insert(inputer);
21
+ }
22
+ }
23
+ }
24
+ </script>
25
+ <div class="buttons-set"<?php if($check === 3): ?> style="display:none;"<?php endif;?>>
26
+ <input<?php if($auto): ?> checked="checked"<?php endif;?> type="checkbox" onchange="addSubscribeToPost(this);" name="campaigner_trigger" id="campaigner-trigger" value="1" title="<?php echo $this->htmlEscape($this->__('Sign Up for Newsletter')) ?>" class="checkbox" />
27
+ <label for="campaigner-trigger"><?php echo $this->htmlEscape($this->__('Sign Up for Newsletter')) ?></label>
28
+ </div>
29
+
30
+ <script type="text/javascript">
31
+ addSubscribeToPost($('campaigner-trigger'));
32
+ </script>
app/design/frontend/base/default/template/campaigner/customer/account/dashboard/info.phtml ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $email = $this->helper('customer')->getCustomer()->getEmail();
3
+ $subscriptions = Mage::helper('campaigner')->getSubscriptions($email);
4
+ $status = strtolower($subscriptions['status']);
5
+ ?>
6
+
7
+ <div class="col2-set">
8
+ <div class="col-1">
9
+ <div class="box">
10
+ <div class="box-title">
11
+ <h3><?php echo $this->__('Contact Information') ?></h3>
12
+ <a href="<?php echo $this->getUrl('customer/account/edit') ?>"><?php echo $this->__('Edit') ?></a>
13
+ </div>
14
+ <div class="box-content">
15
+ <p>
16
+ <?php echo $this->htmlEscape($this->getCustomer()->getName()) ?><br />
17
+ <?php echo $this->htmlEscape($this->getCustomer()->getEmail()) ?><br />
18
+ <a href="<?php echo $this->getChangePasswordUrl() ?>"><?php echo $this->__('Change Password') ?></a>
19
+ </p>
20
+ </div>
21
+ <?php if ($status == 'hardbounce'): ?>
22
+ <p class='camp_hardbounced'>We've been unable to reach you at <?php echo $this->htmlEscape($this->getCustomer()->getEmail()) ?>. Please <a href="<?php echo $this->getUrl('customer/account/edit') ?>"><?php echo $this->__('update') ?></a> your email address.</p>
23
+ <?php endif; ?>
24
+ </div>
25
+ </div>
26
+ <?php if ($this->isNewsletterEnabled()): ?>
27
+ <div class="col-2">
28
+ <div class="box">
29
+ <div class="box-title">
30
+ <h3><?php echo $this->__('Newsletters') ?></h3>
31
+ <a href="<?php echo $this->getUrl('newsletter/manage') ?>"><?php echo $this->__('Edit') ?></a>
32
+ </div>
33
+ <div class="box-content">
34
+ <?php
35
+ $lists = array();
36
+ foreach ($subscriptions['lists'] as $list_id => $subscription) {
37
+ if ($subscription['subscribed']) {
38
+ $lists[] = $subscription['name'];
39
+ }
40
+ }
41
+
42
+ if (count($lists) == 0) {
43
+ echo "<p>" . $this->__('You are currently not subscribed to any newsletter.') . "</p>";
44
+ } else {
45
+ $plural = "";
46
+ if (count($lists) > 1) {
47
+ $plural = "s";
48
+ }
49
+ echo "<p>You are subscribed to the following newsletter{$plural}: " . implode(", ", $lists) . "</p>";
50
+ }
51
+ ?>
52
+ </div>
53
+ <?php if ($status == 'unsubscribed'): ?>
54
+ <p class='camp_unsubscribed'>You have indicated that you no longer wish to receive newsletter emails. <a href="<?php echo Mage::getUrl('campaigner/customer_account/resubscribe') ?>">Click here</a> to begin receiving these emails again.</p>
55
+ <?php endif; ?>
56
+ </div>
57
+ </div>
58
+ <?php endif; ?>
59
+ </div>
app/design/frontend/base/default/template/campaigner/customer/account/lists.phtml ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $subscriptions = $this->getSubscriptions();
4
+ $status = strtolower($subscriptions['status']);
5
+ //Zend_debug::dump($subscriptions);
6
+
7
+
8
+ ?>
9
+ <div class="page-title">
10
+ <h1><?php echo $this->__('Newsletter Subscriptions'); ?></h1>
11
+ </div>
12
+ <?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
13
+ <form action="<?php echo $this->getUrl('campaigner/customer_account/saveadditional'); ?>" name="campaigner_additional" id="campaigner-additional" method="post">
14
+ <div class="fieldset">
15
+ <?php echo $this->getBlockHtml('formkey'); ?>
16
+
17
+ <ul class="campaigner-additional-lists">
18
+ <?php foreach ($subscriptions['lists'] as $list_id => $subscription): ?>
19
+
20
+ <li class="listdata">
21
+
22
+ <input id="<?php echo $list_id ?>" type="checkbox" name="<?php echo $list_id ?>" value="true" <?php if ($subscription['subscribed']) echo 'checked="checked"'; ?> />
23
+ <label for="<?php echo $list_id ?>"><?php echo $subscription['name'] ?></label>
24
+ <input type='hidden' name='lists[]' value='<?php echo $list_id ?>' />
25
+ </li>
26
+ <?php endforeach; ?>
27
+ </ul>
28
+
29
+ <?php if ($status == 'unsubscribed'): ?>
30
+ <p class='camp_unsubscribed'>You have indicated that you no longer wish to receive newsletter emails. <a href="<?php echo Mage::getUrl('campaigner/customer_account/resubscribe') ?>">Click here</a> to begin receiving these emails again.</p>
31
+ <?php endif; ?>
32
+ </div>
33
+ <div class="buttons-set">
34
+ <button type="submit" title="<?php echo $this->__('Save') ?>" class="button"><span><span><?php echo $this->__('Save') ?></span></span></button>
35
+ </div>
36
+ </form>
app/design/frontend/base/default/template/campaigner/signup/form.phtml ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div id='campaigner_signup_placeholder'>
2
+
3
+ </div>
4
+ <script type='text/javascript'>
5
+
6
+ var params = window.location.search.toQueryParams();
7
+
8
+ var signup_enabled = <?php echo $this->isSignupEnabled(); ?>;
9
+ var test_mode = params.signup_test ? true : false;
10
+ var signup_delay = params.delay ? params.delay * 1000 : <?php echo $this->getSignupDelay(); ?>;
11
+
12
+ function showSignup(data)
13
+ {
14
+ $('campaigner_signup_placeholder').update(data);
15
+ $$('body')[0].addClassName('campaigner_signup_open');
16
+ //$('campaigner_signup_background').show();
17
+ }
18
+
19
+ function closeSignup()
20
+ {
21
+ $$('body')[0].removeClassName('campaigner_signup_open');
22
+ $('campaigner_signup_background').hide();
23
+
24
+ if (!test_mode)
25
+ {
26
+ var CookieDate = new Date;
27
+
28
+ var CurrentDate = Math.round(+new Date()/1000);
29
+ CookieDate.setFullYear(CookieDate.getFullYear( ) + 5);
30
+ Mage.Cookies.set('ed_signup', CurrentDate, CookieDate);
31
+ }
32
+
33
+ return false;
34
+ }
35
+
36
+ function showSignupCheck()
37
+ {
38
+ var url = '<?php echo $this->getSignupCheckUrl() ?>' + window.location.search;
39
+ new Ajax.Request(url, {
40
+ onSuccess: function(transport)
41
+ {
42
+ var json = transport.responseText.evalJSON();
43
+
44
+ if (json.can_show == true)
45
+ showSignup(json.html_content);
46
+ }
47
+ });
48
+ }
49
+
50
+ document.observe("dom:loaded", function()
51
+ {
52
+ if (signup_enabled || test_mode)
53
+ window.setTimeout("showSignupCheck()",signup_delay);
54
+ });
55
+
56
+ </script>
app/etc/modules/Campaigner_Integration.xml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <modules>
3
+ <Campaigner_Integration>
4
+ <active>true</active>
5
+ <codePool>community</codePool>
6
+ <depends>
7
+ <Mage_Newsletter />
8
+ </depends>
9
+ </Campaigner_Integration>
10
+ </modules>
11
+ </config>
app/locale/en_US/template/email/campaigner_relay_test.html ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--@subject Campaigner Relay Test @-->
2
+
3
+
4
+ <!--@styles
5
+ body,td { color:#2f2f2f; font:11px/1.35em Verdana, Arial, Helvetica, sans-serif; }
6
+ @-->
7
+
8
+ <body style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
9
+ <div style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
10
+ <table cellspacing="0" cellpadding="0" border="0" height="100%" width="100%">
11
+ <tr>
12
+ <td align="center" valign="top" style="padding:20px 0 20px 0">
13
+ <!-- [ header starts here] -->
14
+ <table bgcolor="FFFFFF" cellspacing="0" cellpadding="10" border="0" width="650" style="border:1px solid #E0E0E0;">
15
+ <tr>
16
+ <td valign="top">
17
+ <a href="{{store url=""}}"><img src="{{var logo_url}}" alt="{{var logo_alt}}" style="margin-bottom:10px;" border="0"/></a></td>
18
+ </tr>
19
+ <!-- [ middle starts here] -->
20
+ <tr>
21
+ <td valign="top">
22
+ <p>This is a test of the Campaigner Relay</p>
23
+ </td>
24
+ </tr>
25
+
26
+ </table>
27
+ </td>
28
+ </tr>
29
+ </table>
30
+ </div>
31
+ </body>
app/locale/en_US/template/email/newsletter_subscr_success_campaigner.html ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <!--@subject Newsletter subscription success @-->
2
+
3
+ Newsletter subscription success to {{var subscriber.getListName()}}
app/locale/en_US/template/email/newsletter_unsub_success_campaigner.html ADDED
@@ -0,0 +1,2 @@
 
 
1
+ <!--@subject Newsletter unsubscription success @-->
2
+ Newsletter unsubscription success to {{var subscriber.getListName()}}
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Campaigner_Integration</name>
4
+ <version>1.0.1</version>
5
+ <stability>stable</stability>
6
+ <license/>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Campaigner integration for Magento</summary>
10
+ <description>Campaigner integration for Magento</description>
11
+ <notes>Campaigner Integration for Magento</notes>
12
+ <authors><author><name>Mark Cerullo</name><user>auto-converted</user><email>integrations@campaigner.com</email></author></authors>
13
+ <date>2015-07-30</date>
14
+ <time>19:45:46</time>
15
+ <contents><target name="magecommunity"><dir name="Campaigner"><dir name="Integration"><dir name="Block"><dir name="Adminhtml"><dir name="Abandoned"><dir name="Details"><dir name="Tab"><dir name="Diagnostics"><file name="Status.php" hash="8a19e2e94944ca44fb36b1f1eea2c57e"/></dir><file name="Cart.php" hash="eeb38260b64b43d9d7ae59e27733b269"/><file name="Diagnostics.php" hash="e8fb26b980ead6d7ce9adaa0ccf391d2"/></dir><file name="Form.php" hash="59f4ae15758308ff52cd951d863f13ce"/></dir><file name="Details.php" hash="ccbce1ea6eb14476937df78c721cfba4"/><file name="Grid.php" hash="1155cba06b4d55f87461845e65f91e2c"/><file name="Status.php" hash="dd498f84c5f6beba1bfb465c5e5f9279"/><file name="Tabs.php" hash="ece0311585223168e00396c449e66c40"/></dir><dir name="Diagnostics"><dir name="Status"><file name="Abstract.php" hash="26a7456053abc173fbf8aaf3f68d7ab8"/></dir></dir><dir name="Latest"><file name="Grid.php" hash="fb6f191f0fd9d27f1550ff2caa75c229"/><file name="Status.php" hash="18c32fdc47887ea3231833ca6585362d"/></dir><dir name="System"><dir name="Config"><dir name="Fieldset"><file name="Hint.php" hash="7d1f4659d72038a03281345bb7798ea1"/></dir><dir name="Form"><dir name="Field"><dir name="Signup"><file name="Test.php" hash="e4489f226eeef06c504b920847ff9593"/></dir><dir name="Smtp"><file name="Server.php" hash="3535455e2c04b70e9a52ef0bc9d00088"/><file name="Test.php" hash="933c8c06879a2e278b4757223fed1c53"/></dir><file name="Addressmapfields.php" hash="55c88d6e85ca0e73e54b842e0e7ab4ba"/><file name="Api.php" hash="549b18aaf277a7ae46408865f195ee81"/><file name="Common.php" hash="c421a4ca9e6bc2c1c64429f3640cc427"/><file name="Diagnostics.php" hash="05bdb6a63bc4742432af8dfb0ffd0a2a"/><file name="Info.php" hash="525c685749a05461e33f3f0df4f146c7"/><file name="Logging.php" hash="183cd28a3156a024455fd854730c859e"/><file name="Mapfields.php" hash="80c79d853273c16e3be073a18c2ec011"/><file name="Note.php" hash="7ba64e042e476f4b8ca6741f3880df23"/><file name="Shippingmapfields.php" hash="741d75b6e332151dba21befccd95ddc7"/><file name="Smtp.php" hash="93eabbd4c24a4001bb5808e51e9d43a0"/></dir></dir></dir></dir><dir name="Troubleshooting"><dir name="View"><dir name="Tab"><file name="Download.php" hash="8d47397381bc8286c22188c2f6e015e3"/><file name="Help.php" hash="192fd3cb04b720506a2d9ac89f267b6a"/><file name="Info.php" hash="6ce83e41898da9792868bc42e889a429"/><file name="Log.php" hash="a9281138b7791a6a4e5ad2a35623a61d"/><file name="Settings.php" hash="bd0b189a1b1cc313ed0bb96b869a04f8"/><file name="Submit.php" hash="7f5481630cd9f115aa801d16314b8edf"/></dir><file name="Form.php" hash="0809b7e09e2a932bab3f2c85e95516da"/></dir><file name="Status.php" hash="5032e69d110bc15a20ddabd492a2c9e3"/><file name="Tabs.php" hash="08299230ebb95078adf10bd9242b42cc"/><file name="View.php" hash="4e045d938bdddfd5af9917db56f2c8df"/></dir><file name="Abandoned.php" hash="a7d349903733493af5cd3713bad1ec70"/><file name="Latest.php" hash="48e49078842a436c7ce662f5ea745020"/></dir><dir name="Checkout"><file name="Subscribe.php" hash="2d31ac46504200508ffb142e35acb0b9"/></dir><dir name="Customer"><dir name="Account"><file name="Lists.php" hash="d3bdd16652fdf1021ab0045a6a9ac226"/></dir></dir><dir name="Widget"><dir name="Grid"><dir name="Column"><dir name="Renderer"><dir name="Abandoned"><file name="Minutes.php" hash="67c46d39f2824b0288974b6927a98dac"/></dir><file name="Action.php" hash="a8454d2d40609f2de12bdbc0a9f3a551"/></dir></dir></dir></dir><file name="Capture.php" hash="e2f1e84334b5e63fbac13399f76be136"/><file name="Signup.php" hash="3cfb414ed7fc6d6b866d38b296fad7cc"/></dir><dir name="Controller"><dir name="Front"><file name="Abstract.php" hash="1ec0fbe702b70b33cf21097f2472f165"/></dir></dir><dir name="Helper"><file name="Abandoned.php" hash="df7d7ffa97e4f69e9797fdefa18193cf"/><file name="Data.php" hash="f5f8f70143d2a1a4c714451125d4dbbc"/><file name="Diagnostic.php" hash="0382ce6337fc845fb099ff79507a64ef"/><file name="Email.php" hash="b23abe06562ae3bfc02093d56ea61807"/><file name="Fields.php" hash="059e0fda027abed6de66e3b039fc191b"/><file name="Order.php" hash="f58695b30fab463a5671bf79f596a149"/><file name="Troubleshooting.php" hash="48915a6a5b68c1b5d60a617e7b4cab8f"/></dir><dir name="Model"><dir name="Abandoned"><file name="Observer.php" hash="d5c951889ce943bb5b2a45d7d1f3fc3c"/></dir><dir name="Action"><file name="List.php" hash="ba8f9239b1c3aba92a870aec4c5e5fd3"/><file name="Observer.php" hash="3d74517e8d5548e06fc669634951b285"/></dir><dir name="Configuration"><file name="Observer.php" hash="582bd07b69dbee600036dbae40b1d5a1"/></dir><dir name="Customer"><file name="Observer.php" hash="f2810c6b274a23f3769c4f42e52454aa"/></dir><dir name="Email"><file name="Queue.php" hash="a755044d7d354ac2d3c31dba230eb005"/><file name="Template.php" hash="26096ed08f0339b836938abd7ecec2c5"/></dir><dir name="Latest"><file name="Order.php" hash="15cff0518a0e053bffaa2d8f6113778a"/></dir><dir name="Mysql4"><dir name="Abandoned"><file name="Collection.php" hash="4f984cd418b4a763967844657a554fd0"/></dir><dir name="Action"><dir name="List"><file name="Collection.php" hash="b901ec897893ace7b3a47b7ce63d1825"/></dir><file name="List.php" hash="d31fdb94086b8c2feca37384af08ae7a"/></dir><dir name="Latest"><dir name="Order"><file name="Collection.php" hash="487eab71efa04552566a1260012a5845"/></dir><file name="Order.php" hash="1b25cfbe2923690187bed3a982968d07"/></dir><dir name="Order"><file name="Collection.php" hash="f751237abc91e49544a473bdf2a5e35d"/></dir><dir name="Session"><file name="Collection.php" hash="629816a4bf1be669d1ed677744357f61"/></dir><file name="Abandoned.php" hash="cd4ca2dbc8f0758a3835a4b870fedcaa"/><file name="Order.php" hash="5bac34cb7dc1d4d2db838894438034fd"/><file name="Session.php" hash="123ec994fcc5b697ceacd370fe52a8af"/></dir><dir name="Newsletter"><file name="Observer.php" hash="d143215522958d1d4cdd4800cf49b224"/></dir><dir name="Observer"><file name="Abstract.php" hash="9ac37b03684b20cddcfd97b6a6f3170b"/></dir><dir name="Order"><file name="Observer.php" hash="0f566abaad6dc86719c75a0b2322b8dc"/></dir><dir name="Resource"><file name="Setup.php" hash="952230e5b0632c3441c20bbfc386ec4f"/></dir><dir name="System"><dir name="Config"><dir name="Source"><dir name="Send"><file name="Field.php" hash="e4ea62f64f043668f00eb627837cc6d4"/></dir><dir name="Signup"><file name="Opacity.php" hash="bd3370611c9551efd53d84565e5cb234"/><file name="Recurrence.php" hash="aa42d1124016892bad804a43dbe0138e"/></dir><dir name="Smtp"><file name="Encryption.php" hash="5447e71037ae34960fff66479d7152c1"/></dir><file name="Abandonedlist.php" hash="64f11bdc40e02d614bb1282c6fb762b8"/><file name="Additionallist.php" hash="84454d9fd80e411efc8540d9dcb51888"/><file name="Checkoutsubscribe.php" hash="c4f2e403652fb6438ec993af3ba0c7b9"/><file name="List.php" hash="6c9784a917109e7b6812b147ffba733e"/><file name="Sequence.php" hash="fa9177180ccb4b91f3c16cbffe9d745d"/><file name="States.php" hash="b3bc4e2c3ee3caac578909b85962bf3d"/><file name="Statuses.php" hash="6cd4cd287608cd0ed30088ded5ee5c42"/><file name="Store.php" hash="e0a4863f576e202e66b6fe4bd1ddc12c"/><file name="Time.php" hash="3c402071ddd3dd01bd49717fe5d5016e"/></dir></dir></dir><dir name="Wrapper"><file name="Abandoned.php" hash="9fbd98b3d5150ba55d1bb5bd2a071c53"/><file name="Abstract.php" hash="0748d215889a2dfda1a164237ff01905"/><file name="Database.php" hash="164de5c78c9912225afed7192a1a3f7c"/><file name="Exception.php" hash="7e2f930f4106b5d91e595dcac75f6c62"/><file name="Execute.php" hash="f30674355173dd9dd27a69dada96ed61"/><file name="Lists.php" hash="38f8e6989bd6cba51e1f2a41b9529042"/><file name="Orders.php" hash="d741e48adf06eecbe76f92c342ce8cca"/><file name="Subscribers.php" hash="c1111e5b118b31e996564b696ea4d3c1"/><file name="Wishlist.php" hash="8139aaef7923f7e9313a85d7ecaed853"/></dir><file name="Abandoned.php" hash="3121570ce6e5faf0fcc7aeea98ffa562"/><file name="Observer.php" hash="8e69e0fe1d659a5413ac578dc72299ad"/><file name="Order.php" hash="9a66161a19226a724ebdaa0df847b847"/><file name="Session.php" hash="04606a68e8f07b19130dcca442bc3d57"/></dir><dir name="controllers"><dir name="Admin"><file name="AbandonedController.php" hash="5cd81b84fce7de2c486de200e5089d7d"/><file name="DiagnosticController.php" hash="bd40fae2dca04a935d1cac9dc3928c6c"/><file name="LatestController.php" hash="9e10c7a6273a6f0855233af85e2131c7"/><file name="TroubleshootingController.php" hash="696734e8d61cb6017e7c197767ca321b"/></dir><dir name="Customer"><file name="AccountController.php" hash="fd758fc7bf3885c6fb18898b1d8c23fe"/></dir><file name="AbandonedController.php" hash="115d5d946e3eb5f917f9e9066b54cd45"/><file name="CaptureController.php" hash="f4b3dbd7fed2ba835679a465999b6e8d"/><file name="SignupController.php" hash="9f22f1599ec5ca4159dca1f5597dc5b8"/></dir><dir name="etc"><file name="adminhtml.xml" hash="622748d98d7492dd22da1c290706b60c"/><file name="config.xml" hash="c3f586eb990d956fcac7b24874af8e86"/><file name="system.xml" hash="e028bf7ebbef652238fe455076c74a11"/></dir><dir name="sql"><dir name="campaigner_setup"><file name="mysql4-install-1.0.0.php" hash="80c1aae7aa0da201429e58f2990128c6"/></dir></dir></dir></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="campaigner"><file name="campaigner-tab.png" hash="181849ccef5e616db6aae38a229a759a"/><file name="campaigner.css" hash="5d8ca056b8b65b04c90d7b6f4596f974"/><file name="logo.png" hash="d73185d0f531abdfb30c95b1305e9c3b"/></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="campaigner"><dir name="images"><file name="window_close.png" hash="3af14f053f360bf31f8ba2df73ec7f1e"/></dir><file name="campaigner.css" hash="57204bebe8e822a80be8ede51d0c0491"/><file name="integration.js" hash="027627a14bfe078ef56c34202d5c9a19"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="campaigner.xml" hash="0a6c410360dd033e295921873e539bb4"/></dir><dir name="template"><dir name="campaigner"><dir name="abandoned"><dir name="details"><dir name="tab"><dir name="diagnostics"><file name="status.phtml" hash="63544ef7009149845d4340dbbcea718e"/></dir><file name="cart.phtml" hash="be7ca2b147fc836c2ca547b290ffe841"/></dir><file name="form.phtml" hash="60633d212382770e99d11d24ae919e47"/></dir><file name="details.phtml" hash="9d467b97a2d773aec950bea7061c6730"/><file name="status.phtml" hash="9e7723dc1fe5f8693345db9cc7cda808"/></dir><dir name="latest"><file name="status.phtml" hash="ca4d0d10d06ba2d26e58720b6e7b6638"/></dir><dir name="order"><dir name="view"><dir name="tab"><dir name="diagnostics"><file name="status.phtml" hash="dbc795e2c4ae8ca1201a91b579a5974a"/></dir></dir></dir></dir><dir name="system"><dir name="config"><dir name="fieldset"><file name="hint.phtml" hash="35e9887ecb401021fc2927c6d8cb25f6"/></dir><dir name="form"><dir name="field"><dir name="export"><file name="date_range.phtml" hash="746bf1adb96eb46b4d43f9f4a39c2040"/><file name="orders.phtml" hash="6264bb43770229c38ce12e57886b4787"/><file name="products.phtml" hash="92deede7e13c573897b84262bb55e16d"/></dir><dir name="signup"><file name="test.phtml" hash="a9921c7483bbaf56c0bf98e41a672e1e"/></dir><dir name="smtp"><file name="test.phtml" hash="b5ed32a1e695c6fdf011dc6e1b5801fd"/></dir><file name="api.phtml" hash="8f406515a32962902a055554ac313261"/><file name="array.phtml" hash="082111176e5dac1d0e1f1eec1b1fc5d4"/><file name="diagnostics.phtml" hash="a6e51e54eade038052caa12542a1b163"/><file name="info.phtml" hash="9d3d76056542cb7ecdbbc03551cea432"/><file name="logging.phtml" hash="eafec906a6f3d67b48e138009b0134bb"/><file name="note.phtml" hash="8df6563e1e33c8047d3c399dbe43d476"/><file name="smtp.phtml" hash="0c3151b4d7f34d6cf96f9fd2bfe210fd"/></dir></dir><file name="setup_check.phtml" hash="74f11286e25cea96fdb87642b96d62ec"/></dir><dir name="convert"><dir name="profile"><file name="export.phtml" hash="c0cc0401d8a4b4cda36b3f28d09c98a8"/></dir></dir></dir><dir name="troubleshooting"><dir name="view"><dir name="tab"><file name="download.phtml" hash="72265504ae19264e31b3e0f5814b219b"/><file name="help.phtml" hash="18ca526a072679d938ff46cd14259a59"/><file name="info.phtml" hash="53d09908246eade525571ef809e40735"/><file name="log.phtml" hash="db325e68b0584162fa3c2c082a029421"/><file name="settings.phtml" hash="218160085bc1745971cb80216704816e"/><file name="submit.phtml" hash="650f228e6be47ed72a8dfd636fb85512"/></dir><file name="form.phtml" hash="d2338bfe3598e9315ca8f5ac8d9b5516"/></dir><file name="status.phtml" hash="2a11a1c817fdcc7ea8c402583a85bbf4"/><file name="view.phtml" hash="6ddfc8c6efe25d30e63f792b19a95c84"/></dir><file name="diagnostics.phtml" hash="ca3b12f1caf598a0006c7a17bc78ea18"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="campaigner.xml" hash="7d17fb72b199bfdededeeecca30df661"/></dir><dir name="template"><dir name="campaigner"><dir name="capture"><file name="email.phtml" hash="fa273ff1a48a12eb386f58f3e3e78f66"/></dir><dir name="checkout"><file name="subscribe.phtml" hash="fd0671d9d8186d7c93e2c2eb5dbffaeb"/></dir><dir name="customer"><dir name="account"><dir name="dashboard"><file name="info.phtml" hash="6352daad22255345cc240a1806e04842"/></dir><file name="lists.phtml" hash="43045ece917bf50ae68bb60d40b7f867"/></dir></dir><dir name="signup"><file name="form.phtml" hash="d85e1fe515ad261609ea464c4715c1db"/></dir></dir></dir></dir></dir></dir></target><target name="magelocale"><dir name="en_US"><dir name="template"><dir name="email"><file name="newsletter_subscr_success_campaigner.html" hash="f6afb69d207bbc3f8920e7a72ac9dd07"/><file name="newsletter_unsub_success_campaigner.html" hash="bd9f97e8f5485180d4420097b5200ef4"/><file name="campaigner_relay_test.html" hash="3e01c93e616154068ea4b841802acf2f"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Campaigner_Integration.xml" hash="d7311dea93c926305f8ed67be1c1fc12"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies/>
18
+ </package>
skin/adminhtml/default/default/campaigner/campaigner-tab.png ADDED
Binary file
skin/adminhtml/default/default/campaigner/campaigner.css ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ul.tabs a.campaigner-section,
2
+ ul.tabs a.campaigner-section:hover {background: url("../images/tabs_span_bg.gif") repeat-x scroll 0 100% transparent; border-bottom:none; padding:0.5em 0.5em 0.5em 1.5em; text-indent:-9999px;}
3
+
4
+ ul.tabs a.campaigner-section:hover { background-color: #D8E6E6; border-right: solid 1px #8BA5A5;}
5
+
6
+ ul.tabs a.campaigner-section span,
7
+ ul.tabs a.campaigner-section:hover span { background:url(campaigner-tab.png) no-repeat 0 0; overflow:hidden; padding:0; width:146px; height:24px; }
8
+ ul.tabs a.campaigner-section.active, ul.tabs a.campaigner-section.active:hover { border-bottom: 1px solid #BEBEBE; background: none repeat scroll 0 0 white;}
9
+
10
+ h3.campaigner-header { background:url(campaigner-tab.png) no-repeat 0 0; height: 24px; overflow:hidden; padding:0; width:146px; text-indent:-9999px; }
11
+
12
+ div.campaigner-notice, div.campaigner-status{
13
+ background:#EAF0EE;
14
+ border:1px solid #CCCCCC;
15
+ margin-bottom:10px;
16
+ padding:11px 10px 5px;
17
+ }
18
+
19
+ div.campaigner-status
20
+ {
21
+ padding:10px;
22
+ font-weight: bold;
23
+ }
24
+
25
+ div.campaigner-status table
26
+ {
27
+ width: 100%;
28
+ }
29
+
30
+ div.campaigner-status table td
31
+ {
32
+ width: 25%;
33
+ }
34
+
35
+ .warning
36
+ {
37
+ color: #ea7601;
38
+ font-weight: bold;
39
+ }
40
+
41
+ #camp_status_row span
42
+ {
43
+ color: green;
44
+ }
45
+
46
+ #camp_status_row.disabled span
47
+ {
48
+ color: red;
49
+ }
50
+
51
+ div.campaigner-notice h4
52
+ {
53
+ color: #EA7601;
54
+ }
55
+
56
+ div.campaigner-notice h4 div.abandoned
57
+ {
58
+ float: right;
59
+ }
60
+
61
+ .ab_ok { color: green; }
62
+ .ab_ng { color: red; }
63
+
64
+ #campaigner_trouble { float: right; }
65
+ #campaigner_trouble_details { margin-top: 10px; }
66
+ #campaigner_trouble_details table { margin-bottom: 10px; width: 100%; border-collapse: collapse;}
67
+ #campaigner_trouble_details table tr td { border: solid 1px; padding: 2px; }
68
+ #campaigner_trouble_details table tr td:first-child{ width: 80px; }
69
+ #campaigner_trouble_details ul { list-style: disc outside none; margin-left: 14px;}
70
+
71
+ #log_file_contents { width: 796px; height: 396px; overflow:scroll; border:solid 1px; padding: 2px;}
72
+ #config_details table { width: 100%; border-collapse: collapse;}
73
+ .ed-config-table tr td:first-child { width: 180px; }
74
+
75
+ .logfile-container { padding: 10px 15px; }
76
+ .entry-logfile { overflow: scroll; height: 600px; width: 100%; }
77
+
78
+ .grid .ed-config-subtable tr.headings {
79
+ background: url("../images/sort_row_bg.gif") repeat-x scroll 0 50% transparent !important;
80
+ }
81
+
82
+ .logfile-fieldset { width: auto;
83
+ background: none repeat scroll 0 0 #fafafa;
84
+ border: 1px solid #d6d6d6;
85
+ margin-bottom: 15px;
86
+ }
87
+
88
+ .log_note { color: red; padding: 5px 0;}
89
+ .log_size_warning { color: red;}
90
+
91
+ .camp_orders_found { margin-top: 10px; }
92
+
93
+ .head-adminhtml-troubleshooting {
94
+ background-image: url("../images/fam_package_go.gif");
95
+ }
96
+
97
+ table.missing_columns { background-color: white; color: black; margin: 10px; border: solid 1px black; border-collapse: collapse;}
98
+
99
+ table.missing_columns tr td, table.missing_columns tr th { border: solid 1px black; border-collapse: collapse; padding: 4px 10px;}
100
+ table.missing_columns tr th { font-weight: bold; color: red; }
101
+
102
+ #campaigner_column_fix { margin-left: 15px; }
103
+
104
+ .abandoned_status tr td { padding-right: 10px; }
105
+
106
+ .head-adminhtml-abandoned { background-image: url("../images/fam_cart.gif"); }
107
+
108
+ .cron_warning { margin: 0 10px; cursor: pointer;}
109
+
110
+ table.troubleshooting_details tr td, table.troubleshooting_details tr th { padding: 4px; }
111
+ table.troubleshooting_details { margin-top: 15px; margin-bottom: 10px; }
112
+
113
+ #troubleshooting_stores { margin-left: 20px; }
114
+
115
+ #ip_address { height: 3em; }
116
+
117
+ #apikey_validator, #relay_setup_button { float: right; }
118
+
119
+ #campaigner_status_indicator, #campaigner_relay_status { font-weight: bold; width: 210px; float: left;}
120
+
121
+ .apikey_valid { color: green; }
122
+ .apikey_invalid { color: red; }
123
+ .apikey_validating { color: black; }
124
+
125
+ .campaigner_api_status { width: 280px; }
126
+
127
+ .campaigner_help { max-width: 700px; font-size: 1.2em;}
128
+
129
+ table.map_field_list, table.map_field_custom { margin-left: 20px; margin-bottom: 10px; width: 90%; }
130
+ table.map_field_list tr td, table.map_field_custom tr td {width: 33%; padding: 5px;}
131
+
132
+ table.map_field_custom tr td:first-child { width: 20%; }
133
+ table.map_field_custom tr td:last-child { width: 80%; }
134
+
135
+ .current_ip { margin-top: 10px; }
136
+ .current_ip button { float: left; }
137
+ .your_ip { float: left; margin-top: 2px; font-weight: bold; }
138
+ .current_ip_address { background-color: #FCFBBB; font-weight: bold; border: solid 1px; padding: 1px 5px 0 5px; margin: 0 10px; float: left;}
139
+
140
+ .campaigner_help h3 { margin-top: 15px; }
141
+ .campaigner_help h2 { border-bottom: solid 1px; margin-top: 15px; color: #F15628;}
142
+
143
+ .sequence_example { border: solid 1px; padding: 3px; margin-bottom: 4px; width: 100px; }
144
+
145
+ #campaigner_smtp_status {margin-top: 5px; }
146
+ .smtp_error { font-weight: bold; color: red; }
147
+ .smtp_success { font-weight: bold; color: green; }
148
+
149
+ #relay_status_container { margin-bottom: 5px; width: 280px;}
150
+
151
+ #relay_status_container:after {
152
+ content:"";
153
+ display:table;
154
+ clear:both;
155
+ }
156
+
157
+ .smtp_disable { color: red; margin-left: 5px; }
skin/adminhtml/default/default/campaigner/logo.png ADDED
Binary file
skin/frontend/base/default/campaigner/campaigner.css ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ body.campaigner_signup_open { overflow: hidden; }
2
+
3
+ #campaigner_signup_background {
4
+ background-color: black;
5
+ width: 100%;
6
+ min-height: 100%;
7
+ overflow: hidden;
8
+ float: absolute;
9
+ position: fixed;
10
+ z-index: 10000;
11
+ top: 0;
12
+ left: 0;
13
+ color: white;
14
+ zoom: 1;
15
+ }
16
+
17
+ #campaigner_signup {
18
+ background-color: white;
19
+ color: black;
20
+ font-size: 16px;
21
+ border: 1px solid gray;
22
+ padding: 20px;
23
+ display:block;
24
+ margin: auto;
25
+ width: auto;
26
+ position: absolute;
27
+ top: 0; left: 0; bottom: 0; right: 0;
28
+ border-radius: 15px;
29
+ z-index: 10001;
30
+ zoom: 1;
31
+ }
32
+
33
+ #campaigner_signup iframe
34
+ {
35
+ border: none;
36
+ }
37
+
38
+ #campaigner_signup_close {
39
+ background: url(images/window_close.png);
40
+ cursor: pointer;
41
+ float: right;
42
+ position: absolute;
43
+ top: 5px;
44
+ right: 5px;
45
+ width: 16px;
46
+ height: 16px;
47
+ }
48
+
49
+ .camp_hardbounced {
50
+ color: red;
51
+ margin-top: 15px;
52
+ }
53
+
54
+ .camp_unsubscribed {
55
+ color: orange;
56
+ margin-top: 15px;
57
+ }
skin/frontend/base/default/campaigner/images/window_close.png ADDED
Binary file
skin/frontend/base/default/campaigner/integration.js ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ removeManageNewsletter = function(){
2
+ var newsletter = $$('div.block-content ul li a[href*="newsletter/manage"]');
3
+ if(newsletter.length){
4
+ newsletter.first().up().remove();
5
+ }
6
+ }
7
+
8
+ document.observe("dom:loaded", function() {
9
+
10
+ var campaignerEnabled = $$('div.block-content ul li a[href*="campaigner/customer_account/index"]');
11
+ if(campaignerEnabled.length){
12
+ removeManageNewsletter();
13
+ var editLink = $$('div.my-account a[href*="newsletter/manage"]');
14
+ if(editLink.length){
15
+ editLink.first().writeAttribute('href', campaignerEnabled.first().readAttribute('href'));
16
+ }
17
+ }
18
+ });