dotmailermagento - Version 3.2.3

Version Notes

Transactional Emails, Custom Customer Attributes, Reports & More

This release includes some great new functionality as well as including a number of fixes.

##IMPORTANT## Dynamic content URL's have been changed so will need updating within your dotMailer account to ensure they continue working correctly. ##IMPORTANT##

Release Highlights:

+ Transactional Emails: Replace the standard emails Magento currently sends to your customers and guests with beautifully created campaigns from dotMailer. Emails include new account, new order, dispatch, cancel and refund emails. **A dotMailer child account is required to enable this functionality**

+ Custom Customer Attributes: Sync your custom created customer attributes to dotMailer

+ Dynamic Content Styling: Apply custom CSS to all dynamic content pages e.g. font size, colour and type.

+ Reporting: Now within the Newsletter section in Magento you can view the import status of contacts and orders, as well as the sending status of transactional and lost basket emails.

Download this release

Release Info

Developer Calin Diacon
Extension dotmailermagento
Version 3.2.3
Comparing to
See all releases


Code changes from version 1.5.1 to 3.2.3

Files changed (266) hide show
  1. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Campaign.php +18 -0
  2. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Campaign/Edit.php +39 -0
  3. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Campaign/Edit/Form.php +54 -0
  4. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Campaign/Grid.php +212 -0
  5. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Column/Renderer/Imported.php +16 -0
  6. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Column/Renderer/Status.php +18 -0
  7. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Column/Renderer/Sync.php +16 -0
  8. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Config.php +18 -0
  9. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Config/Customdatafields.php +112 -0
  10. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Config/Select.php +14 -0
  11. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Config/Template/Templatefields.php +149 -0
  12. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Contact.php +18 -0
  13. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Contact/Edit.php +36 -0
  14. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Contact/Edit/Form.php +26 -0
  15. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Contact/Grid.php +207 -0
  16. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard.php +52 -0
  17. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Switcher.php +92 -0
  18. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs.php +58 -0
  19. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Analysis.php +61 -0
  20. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Analysis/Abandonedcarts.php +57 -0
  21. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Analysis/Customer.php +55 -0
  22. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Analysis/Rfm.php +91 -0
  23. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Analysis/Sales.php +54 -0
  24. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Analysis/Subscriber.php +56 -0
  25. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Config.php +123 -0
  26. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/General.php +107 -0
  27. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/General/Data.php +43 -0
  28. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Status.php +1008 -0
  29. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Order.php +15 -0
  30. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Order/Grid.php +110 -0
  31. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Sales/Order/Creditmemo/View.php +196 -0
  32. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/.DS_Store +0 -0
  33. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Deletecontactids.php +22 -0
  34. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Notification.php +11 -0
  35. app/code/{local/Dotdigitalgroup/Email/Block/Debug/Countcontacts.php → community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Reimportorders.php} +7 -6
  36. app/code/{local/Dotdigitalgroup/Email/Block/Debug/Deletecontacts.php → community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Reimportsubscribers.php} +7 -6
  37. app/code/{local/Dotdigitalgroup/Email/Block/Debug/Initialsync.php → community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Resetcustomersimport.php} +9 -7
  38. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Runcontactsync.php +22 -0
  39. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Runordersync.php +22 -0
  40. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Runsubscribersync.php +22 -0
  41. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Setupdatafields.php +24 -0
  42. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Suppressedcontacts.php +23 -0
  43. app/code/{local/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Password.php → community/Dotdigitalgroup/Email/Block/Adminhtml/System/Ajaxvalidate.php} +1 -1
  44. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Automation/Connect.php +43 -0
  45. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Addressbook.php +38 -0
  46. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Datafield.php +41 -0
  47. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Resetcontacts.php +28 -0
  48. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Resetguests.php +28 -0
  49. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Resetsubscribers.php +28 -0
  50. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Validator.php +87 -0
  51. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Waitingfield.php +65 -0
  52. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Wrapper.php +59 -0
  53. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Addressbookbutton.php +22 -0
  54. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Bestsellers.php +24 -0
  55. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Couponinfo.php +26 -0
  56. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Creditmemonew.php +25 -0
  57. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Crosssell.php +26 -0
  58. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Datafieldbutton.php +21 -0
  59. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Gridlist.php +106 -0
  60. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Lostbasket.php +23 -0
  61. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Mostviewed.php +21 -0
  62. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Nosto.php +22 -0
  63. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Productpush.php +21 -0
  64. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Recentlyviewed.php +24 -0
  65. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Related.php +26 -0
  66. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Upsell.php +24 -0
  67. app/code/{local/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Wrapper.php → community/Dotdigitalgroup/Email/Block/Adminhtml/System/Emailapivalidate.php} +9 -8
  68. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Sms/Smsmessagefour.php +24 -0
  69. app/code/{local/Dotdigitalgroup/Email/Block/Adminhtml/System/Config → community/Dotdigitalgroup/Email/Block/Adminhtml/System/Sms}/Smsmessageone.php +13 -8
  70. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Sms/Smsmessagethree.php +26 -0
  71. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Sms/Smsmessagetwo.php +25 -0
  72. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Creditmemoupdate.php +32 -0
  73. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Creditmemoupdateguest.php +30 -0
  74. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Customerconfirmation.php +36 -0
  75. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Customerconfirmed.php +36 -0
  76. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Customernew.php +36 -0
  77. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Invoiceupdate.php +33 -0
  78. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Invoiceupdateguest.php +33 -0
  79. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Newcreditmemo.php +36 -0
  80. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Newcreditmemoguest.php +35 -0
  81. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Newinvoice.php +34 -0
  82. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Newinvoiceguest.php +34 -0
  83. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Neworder.php +33 -0
  84. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Neworderguest.php +32 -0
  85. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Newshipment.php +34 -0
  86. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Newshipmentguest.php +33 -0
  87. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Orderupdate.php +31 -0
  88. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Orderupdateguest.php +31 -0
  89. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Shipmentupdate.php +33 -0
  90. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Shipmentupdateguest.php +32 -0
  91. app/code/community/Dotdigitalgroup/Email/Block/Basket.php +64 -0
  92. app/code/{local → community}/Dotdigitalgroup/Email/Block/Coupon.php +12 -11
  93. app/code/community/Dotdigitalgroup/Email/Block/Order.php +41 -0
  94. app/code/community/Dotdigitalgroup/Email/Block/Order/Creditmemo.php +48 -0
  95. app/code/community/Dotdigitalgroup/Email/Block/Order/Invoice.php +39 -0
  96. app/code/community/Dotdigitalgroup/Email/Block/Order/Shipping.php +48 -0
  97. app/code/community/Dotdigitalgroup/Email/Block/Products.php +67 -0
  98. app/code/community/Dotdigitalgroup/Email/Block/Recommended/Bestsellers.php +71 -0
  99. app/code/community/Dotdigitalgroup/Email/Block/Recommended/Mostviewed.php +66 -0
  100. app/code/community/Dotdigitalgroup/Email/Block/Recommended/Products.php +149 -0
  101. app/code/community/Dotdigitalgroup/Email/Block/Recommended/Push.php +66 -0
  102. app/code/community/Dotdigitalgroup/Email/Block/Recommended/Recentlyviewed.php +73 -0
  103. app/code/community/Dotdigitalgroup/Email/Helper/Config.php +163 -0
  104. app/code/community/Dotdigitalgroup/Email/Helper/Data.php +480 -0
  105. app/code/{local → community}/Dotdigitalgroup/Email/Helper/File.php +71 -29
  106. app/code/community/Dotdigitalgroup/Email/Helper/Recommended.php +178 -0
  107. app/code/community/Dotdigitalgroup/Email/Helper/Transactional.php +287 -0
  108. app/code/community/Dotdigitalgroup/Email/Model/Abstract/Rest.php +435 -0
  109. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Content.php +121 -0
  110. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Abandoned.php +59 -0
  111. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Customer.php +48 -0
  112. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Orders.php +122 -0
  113. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Rfm.php +173 -0
  114. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Subscriber.php +91 -0
  115. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Observer.php +214 -0
  116. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Addressbooks.php +44 -0
  117. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Abandonedlimit.php +43 -0
  118. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Frequency.php +15 -0
  119. app/code/{local/Dotdigitalgroup/Email/Model/System/Config/Source/Orderlimit.php → community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Transdata.php} +1 -1
  120. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Automation/Programme.php +40 -0
  121. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Campaigns.php +44 -0
  122. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Contact/Imported.php +17 -0
  123. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Customer/Attributes/Select.php +34 -0
  124. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Datafields.php +46 -0
  125. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Datamapping/Datafieldaccess.php +17 -0
  126. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Datamapping/Datafieldtype.php +22 -0
  127. app/code/{local/Dotdigitalgroup/Email/Model/System/Config/Source → community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Dynamic}/Displaytype.php +7 -2
  128. app/code/{local/Dotdigitalgroup/Email/Model/System/Config/Source → community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Dynamic}/Gridview.php +6 -1
  129. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Lostbaskets/Interval.php +40 -0
  130. app/code/{local/Dotdigitalgroup/Email/Model/System/Config/Source/Lostbasket.php → community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Lostbaskets/Intervalminute.php} +1 -1
  131. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Orderdelete.php +21 -0
  132. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Orderstatus.php +28 -0
  133. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Sweettooth/Yesno.php +26 -0
  134. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Transactional/Campaigns.php +57 -0
  135. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Transactional/Customselect.php +19 -0
  136. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Transactional/Defaultselect.php +31 -0
  137. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Transactional/Fromaddress.php +57 -0
  138. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Transactional/Replyactions.php +22 -0
  139. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Transactional/Sendtype.php +21 -0
  140. app/code/community/Dotdigitalgroup/Email/Model/Apiconnector/Client.php +1125 -0
  141. app/code/community/Dotdigitalgroup/Email/Model/Apiconnector/Contact.php +394 -0
  142. app/code/community/Dotdigitalgroup/Email/Model/Apiconnector/Customer.php +621 -0
  143. app/code/community/Dotdigitalgroup/Email/Model/Apiconnector/Test.php +81 -0
  144. app/code/community/Dotdigitalgroup/Email/Model/Campaign.php +367 -0
  145. app/code/community/Dotdigitalgroup/Email/Model/Config.php +65 -0
  146. app/code/{local → community}/Dotdigitalgroup/Email/Model/Connector/Account.php +10 -8
  147. app/code/community/Dotdigitalgroup/Email/Model/Connector/Campaign.php +100 -0
  148. app/code/community/Dotdigitalgroup/Email/Model/Connector/Datafield.php +323 -0
  149. app/code/community/Dotdigitalgroup/Email/Model/Connector/Order.php +207 -0
  150. app/code/community/Dotdigitalgroup/Email/Model/Contact.php +205 -0
  151. app/code/community/Dotdigitalgroup/Email/Model/Controller/Observer.php +43 -0
  152. app/code/community/Dotdigitalgroup/Email/Model/Cron.php +98 -0
  153. app/code/community/Dotdigitalgroup/Email/Model/Customer/Guest.php +60 -0
  154. app/code/community/Dotdigitalgroup/Email/Model/Customer/Observer.php +158 -0
  155. app/code/community/Dotdigitalgroup/Email/Model/Customer/Wishlist.php +94 -0
  156. app/code/{local → community}/Dotdigitalgroup/Email/Model/Customer/Wishlist/Item.php +25 -12
  157. app/code/community/Dotdigitalgroup/Email/Model/Email/Template.php +335 -0
  158. app/code/community/Dotdigitalgroup/Email/Model/Feed.php +88 -0
  159. app/code/community/Dotdigitalgroup/Email/Model/Newsletter/Observer.php +120 -0
  160. app/code/community/Dotdigitalgroup/Email/Model/Newsletter/Subscriber.php +171 -0
  161. app/code/community/Dotdigitalgroup/Email/Model/Order.php +159 -0
  162. app/code/community/Dotdigitalgroup/Email/Model/Resource/Campaign.php +13 -0
  163. app/code/community/Dotdigitalgroup/Email/Model/Resource/Campaign/Collection.php +13 -0
  164. app/code/community/Dotdigitalgroup/Email/Model/Resource/Config.php +14 -0
  165. app/code/community/Dotdigitalgroup/Email/Model/Resource/Config/Collection.php +14 -0
  166. app/code/community/Dotdigitalgroup/Email/Model/Resource/Contact.php +14 -0
  167. app/code/community/Dotdigitalgroup/Email/Model/Resource/Contact/Collection.php +25 -0
  168. app/code/community/Dotdigitalgroup/Email/Model/Resource/Order.php +12 -0
  169. app/code/community/Dotdigitalgroup/Email/Model/Resource/Order/Collection.php +18 -0
  170. app/code/community/Dotdigitalgroup/Email/Model/Resource/Setup.php +26 -0
  171. app/code/community/Dotdigitalgroup/Email/Model/Sales/Observer.php +153 -0
  172. app/code/community/Dotdigitalgroup/Email/Model/Sales/Order.php +214 -0
  173. app/code/community/Dotdigitalgroup/Email/Model/Sales/Quote.php +256 -0
  174. app/code/community/Dotdigitalgroup/Email/Model/Sms/Campaign.php +112 -0
  175. app/code/community/Dotdigitalgroup/Email/Model/Sweettooth/Observer.php +21 -0
  176. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/ConnectorController.php +272 -0
  177. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/AutomationController.php +109 -0
  178. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/CampaignController.php +252 -0
  179. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/ContactController.php +192 -0
  180. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/DashboardController.php +76 -0
  181. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/OrderController.php +26 -0
  182. app/code/community/Dotdigitalgroup/Email/controllers/CreditmemoController.php +69 -0
  183. app/code/community/Dotdigitalgroup/Email/controllers/DynamicContentController.php +32 -0
  184. app/code/community/Dotdigitalgroup/Email/controllers/EmailController.php +135 -0
  185. app/code/community/Dotdigitalgroup/Email/controllers/InvoiceController.php +71 -0
  186. app/code/community/Dotdigitalgroup/Email/controllers/OrderController.php +71 -0
  187. app/code/community/Dotdigitalgroup/Email/controllers/ProductsController.php +94 -0
  188. app/code/community/Dotdigitalgroup/Email/controllers/ReportController.php +63 -0
  189. app/code/community/Dotdigitalgroup/Email/controllers/ShippingController.php +84 -0
  190. app/code/community/Dotdigitalgroup/Email/etc/adminhtml.xml +148 -0
  191. app/code/community/Dotdigitalgroup/Email/etc/config.xml +546 -0
  192. app/code/community/Dotdigitalgroup/Email/etc/files.yaml +252 -0
  193. app/code/community/Dotdigitalgroup/Email/etc/system.xml +2178 -0
  194. app/code/{local/Dotdigitalgroup/Email/sql/connector_setup → community/Dotdigitalgroup/Email/sql/email_connector_setup}/mysql4-install-0.1.0.php +4 -11
  195. app/code/community/Dotdigitalgroup/Email/sql/email_connector_setup/mysql4-install-3.0.0.php +307 -0
  196. app/code/{local/Dotdigitalgroup/Email/sql/connector_setup → community/Dotdigitalgroup/Email/sql/email_connector_setup}/mysql4-upgrade-1.1.1-1.1.2.php +0 -0
  197. app/code/community/Dotdigitalgroup/Email/sql/email_connector_setup/mysql4-upgrade-1.1.2-1.5.0.php +8 -0
  198. app/code/community/Dotdigitalgroup/Email/sql/email_connector_setup/mysql4-upgrade-1.5.0-2.0.0.php +75 -0
  199. app/code/community/Dotdigitalgroup/Email/sql/email_connector_setup/mysql4-upgrade-2.0.0-2.0.1.php +9 -0
  200. app/code/community/Dotdigitalgroup/Email/sql/email_connector_setup/mysql4-upgrade-2.0.1-2.0.2.php +52 -0
  201. app/code/community/Dotdigitalgroup/Email/sql/email_connector_setup/mysql4-upgrade-2.0.3-2.0.4.php +28 -0
  202. app/code/community/Dotdigitalgroup/Email/sql/email_connector_setup/mysql4-upgrade-2.0.4-2.0.5.php +9 -0
  203. app/code/community/Dotdigitalgroup/Email/sql/email_connector_setup/mysql4-upgrade-2.0.5-2.0.6.php +103 -0
  204. app/code/community/Dotdigitalgroup/Email/sql/email_connector_setup/mysql4-upgrade-3.0.1-3.0.2.php +18 -0
  205. app/code/community/Dotdigitalgroup/Email/sql/email_connector_setup/mysql4-upgrade-3.0.3-3.0.4.php +12 -0
  206. app/code/community/Dotdigitalgroup/Email/sql/email_connector_setup/mysql4-upgrade-3.0.4-3.0.5.php +121 -0
  207. app/code/community/Dotdigitalgroup/Email/sql/email_connector_setup/mysql4-upgrade-3.1.2-3.1.3.php +123 -0
  208. app/code/community/Dotdigitalgroup/Mailcheck/Helper/Data.php +6 -0
  209. app/code/community/Dotdigitalgroup/Mailcheck/etc/config.xml +31 -0
  210. app/code/community/Dotdigitalgroup/Mailcheck/etc/jstranslator.xml +5 -0
  211. app/code/community/Dotdigitalgroup/Mailcheck/etc/system.xml +28 -0
  212. app/code/local/Dotdigitalgroup/Email/Block/Adminhtml/System/Bestsellers.php +0 -18
  213. app/code/local/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Gridlist.php +0 -104
  214. app/code/local/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Insertvariable.php +0 -13
  215. app/code/local/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Messagedefault.php +0 -46
  216. app/code/local/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Smsmessagefour.php +0 -23
  217. app/code/local/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Smsmessagethree.php +0 -23
  218. app/code/local/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Smsmessagetwo.php +0 -23
  219. app/code/local/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Validator.php +0 -73
  220. app/code/local/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Waitingfield.php +0 -43
  221. app/code/local/Dotdigitalgroup/Email/Block/Adminhtml/System/Couponinfo.php +0 -18
  222. app/code/local/Dotdigitalgroup/Email/Block/Adminhtml/System/Crosssell.php +0 -20
  223. app/code/local/Dotdigitalgroup/Email/Block/Adminhtml/System/Lostbasket.php +0 -19
  224. app/code/local/Dotdigitalgroup/Email/Block/Adminhtml/System/Mostviewed.php +0 -18
  225. app/code/local/Dotdigitalgroup/Email/Block/Adminhtml/System/Productpush.php +0 -19
  226. app/code/local/Dotdigitalgroup/Email/Block/Adminhtml/System/Recentlyviewed.php +0 -20
  227. app/code/local/Dotdigitalgroup/Email/Block/Adminhtml/System/Related.php +0 -19
  228. app/code/local/Dotdigitalgroup/Email/Block/Adminhtml/System/Upsell.php +0 -19
  229. app/code/local/Dotdigitalgroup/Email/Block/Basket.php +0 -43
  230. app/code/local/Dotdigitalgroup/Email/Block/Debug/Forcecustomersync.php +0 -21
  231. app/code/local/Dotdigitalgroup/Email/Block/Debug/Forcelostbasketsync.php +0 -21
  232. app/code/local/Dotdigitalgroup/Email/Block/Debug/Forcesuppressedsync.php +0 -21
  233. app/code/local/Dotdigitalgroup/Email/Block/Debug/Rescuenow.php +0 -21
  234. app/code/local/Dotdigitalgroup/Email/Block/Debug/Testcredentials.php +0 -21
  235. app/code/local/Dotdigitalgroup/Email/Block/Debug/Transactionalsync.php +0 -20
  236. app/code/local/Dotdigitalgroup/Email/Block/Products.php +0 -53
  237. app/code/local/Dotdigitalgroup/Email/Helper/Api/DotNetExample.php +0 -182
  238. app/code/local/Dotdigitalgroup/Email/Helper/Api/Restrequest.php +0 -298
  239. app/code/local/Dotdigitalgroup/Email/Helper/Data.php +0 -96
  240. app/code/local/Dotdigitalgroup/Email/Helper/Recommended.php +0 -191
  241. app/code/local/Dotdigitalgroup/Email/Model/Account/Test.php +0 -40
  242. app/code/local/Dotdigitalgroup/Email/Model/Api/Rest.php +0 -729
  243. app/code/local/Dotdigitalgroup/Email/Model/Connector/Customer.php +0 -286
  244. app/code/local/Dotdigitalgroup/Email/Model/Connector/Order.php +0 -118
  245. app/code/local/Dotdigitalgroup/Email/Model/Connector/Quote.php +0 -75
  246. app/code/local/Dotdigitalgroup/Email/Model/Connector/Wishlist.php +0 -86
  247. app/code/local/Dotdigitalgroup/Email/Model/Cron.php +0 -58
  248. app/code/local/Dotdigitalgroup/Email/Model/Customer/Customer.php +0 -480
  249. app/code/local/Dotdigitalgroup/Email/Model/Customer/Suppressed.php +0 -85
  250. app/code/local/Dotdigitalgroup/Email/Model/Dynamic/Product/Mapper.php +0 -90
  251. app/code/local/Dotdigitalgroup/Email/Model/Dynamic/Recommended.php +0 -228
  252. app/code/local/Dotdigitalgroup/Email/Model/Newsletter/Subscriber.php +0 -19
  253. app/code/local/Dotdigitalgroup/Email/Model/Observer.php +0 -189
  254. app/code/local/Dotdigitalgroup/Email/Model/Order.php +0 -33
  255. app/code/local/Dotdigitalgroup/Email/Model/Sales/Order.php +0 -96
  256. app/code/local/Dotdigitalgroup/Email/Model/Sales/Quote.php +0 -289
  257. app/code/local/Dotdigitalgroup/Email/Model/Sales/Sms.php +0 -70
  258. app/code/local/Dotdigitalgroup/Email/Model/System/Config/Backend/Syncschedule/Customer.php +0 -50
  259. app/code/local/Dotdigitalgroup/Email/Model/System/Config/Backend/Syncschedule/Suppressed.php +0 -54
  260. app/code/local/Dotdigitalgroup/Email/Model/System/Config/Source/Activebasket.php +0 -12
  261. app/code/local/Dotdigitalgroup/Email/Model/System/Config/Source/Addressbooks.php +0 -30
  262. app/code/local/Dotdigitalgroup/Email/Model/System/Config/Source/Campaigns.php +0 -30
  263. app/code/local/Dotdigitalgroup/Email/Model/System/Config/Source/Datafields.php +0 -35
  264. app/code/local/Dotdigitalgroup/Email/Model/System/Config/Source/Displayifnot.php +0 -12
  265. app/code/local/Dotdigitalgroup/Email/Model/System/Config/Source/Orderstatus.php +0 -16
  266. app/code/local/Dotdigitalgroup/Email/Model/System/Config/Source/Sendcampain.php +0 -24
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Campaign.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Campaign extends Mage_Adminhtml_Block_Widget_Grid_Container
4
+ {
5
+ /**
6
+ * Set the template.
7
+ */
8
+ public function __construct()
9
+ {
10
+ $this->_controller = 'adminhtml_campaign';
11
+ $this->_blockGroup = 'email_connector';
12
+ parent::__construct();
13
+ $this->_headerText = Mage::helper('connector')->__('Campaigns');
14
+ $this->_removeButton('add');
15
+
16
+ $this->setTemplate('connector/grid.phtml');
17
+ }
18
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Campaign/Edit.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Campaign_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
4
+ {
5
+ /**
6
+ * Construct.
7
+ */
8
+ public function __construct()
9
+ {
10
+ parent::__construct();
11
+ $this->_blockGroup = 'email_connector';
12
+ $this->_controller = 'adminhtml_campaign';
13
+ $this->_mode = 'edit';
14
+ $this->_updateButton('save', 'label', Mage::helper('connector')->__('Save Campaign'));
15
+ $this->_updateButton('delete', 'label', Mage::helper('connector')->__('Delete Campaign'));
16
+ $this->_addButton('saveandcontinue', array(
17
+ 'label' => Mage::helper('connector')->__('Save And Continue Edit'),
18
+ 'onclick' => 'saveAndContinueEdit()',
19
+ 'class' => 'save',
20
+ ), -100);
21
+ $this->_formScripts[] = "
22
+ function saveAndContinueEdit(){
23
+ editForm.submit($('edit_form').action+'back/edit/');
24
+ }";
25
+ }
26
+
27
+ /**
28
+ * Header text for the campaign.
29
+ * @return string
30
+ */
31
+ public function getHeaderText()
32
+ {
33
+ if ( Mage::registry('email_campaign') && Mage::registry('email_campaign')->getId() ) {
34
+ return Mage::helper('connector')->__("Edit Campaign '%s'", $this->htmlEscape(Mage::registry('email_campaign')->getContact()));
35
+ } else {
36
+ return Mage::helper('connector')->__('Add Contact');
37
+ }
38
+ }
39
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Campaign/Edit/Form.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Campaign_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
4
+ {
5
+ /**
6
+ * Init class
7
+ */
8
+ public function __construct()
9
+ {
10
+ parent::__construct();
11
+
12
+ $this->setId('id');
13
+ $this->setTitle($this->__('Campaign Information'));
14
+ }
15
+
16
+ /**
17
+ * Setup form fields for inserts/updates
18
+ *
19
+ * return Mage_Adminhtml_Block_Widget_Form
20
+ */
21
+ protected function _prepareForm()
22
+ {
23
+ $model = Mage::registry('email_campaign');
24
+
25
+ $form = new Varien_Data_Form(array(
26
+ 'id' => 'edit_form',
27
+ 'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
28
+ 'method' => 'post')
29
+ );
30
+
31
+ $fieldset = $form->addFieldset('base_fieldset', array(
32
+ 'legend' => Mage::helper('connector')->__('Campaign Information')
33
+ ));
34
+
35
+ if ($model->getId()) {
36
+ $fieldset->addField('id', 'hidden', array(
37
+ 'name' => 'id',
38
+ ));
39
+ }
40
+
41
+ $fieldset->addField('name', 'text', array(
42
+ 'name' => 'name',
43
+ 'label' => Mage::helper('connector')->__('Name'),
44
+ 'title' => Mage::helper('connector')->__('Name'),
45
+ 'required' => true,
46
+ ));
47
+
48
+ $form->setValues($model->getData());
49
+ $form->setUseContainer(true);
50
+ $this->setForm($form);
51
+
52
+ return parent::_prepareForm();
53
+ }
54
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Campaign/Grid.php ADDED
@@ -0,0 +1,212 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Campaign_Grid extends Mage_Adminhtml_Block_Widget_Grid
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+ $this->setId('id');
9
+ $this->setDefaultSort('entity_id');
10
+ $this->setDefaultDir('ASC');
11
+ $this->setSaveParametersInSession(true);
12
+ $this->setUseAjax(true);
13
+ }
14
+
15
+ /**
16
+ * Prepare grid collection object.
17
+ * @return Mage_Adminhtml_Block_Widget_Grid
18
+ */
19
+ protected function _prepareCollection()
20
+ {
21
+ $collection = Mage::getModel('email_connector/campaign')->getCollection();
22
+ $this->setCollection($collection);
23
+ $this->setDefaultSort('created_at');
24
+ $this->setDefaultDir('DESC');
25
+ return parent::_prepareCollection();
26
+ }
27
+
28
+ protected function _prepareColumns()
29
+ {
30
+ $this->addColumn('id', array(
31
+ 'header' => Mage::helper('connector')->__('Campaign ID'),
32
+ 'width' => '20px',
33
+ 'index' => 'campaign_id',
34
+ 'type' => 'number',
35
+ 'truncate' => 50,
36
+ 'escape' => true,
37
+ ))->addColumn('email', array(
38
+ 'header' => Mage::helper('connector')->__('Email'),
39
+ 'align' => 'left',
40
+ 'width' => '50px',
41
+ 'index' => 'email',
42
+ 'type' => 'text',
43
+ 'escape' => true
44
+ ))->addColumn('is_created', array(
45
+ 'header' => Mage::helper('connector')->__('Is Created'),
46
+ 'align' => 'center',
47
+ 'width' => '20px',
48
+ 'index' => 'is_created',
49
+ 'escape' => true,
50
+ 'type' => 'options',
51
+ 'renderer' => 'email_connector/adminhtml_column_renderer_imported',
52
+ 'options' => array(
53
+ '1' => 'Is Created',
54
+ 'null' => 'Not Created'
55
+ ),
56
+ 'filter_condition_callback' => array($this, 'filterCallbackContact')
57
+ ))->addColumn('is_sent', array(
58
+ 'header' => Mage::helper('connector')->__('Is Sent'),
59
+ 'align' => 'center',
60
+ 'width' => '20px',
61
+ 'index' => 'is_sent',
62
+ 'escape' => true,
63
+ 'type' => 'options',
64
+ 'renderer' => 'email_connector/adminhtml_column_renderer_imported',
65
+ 'options' => array(
66
+ '1' => 'Is Send',
67
+ 'null' => 'Not Send'
68
+ ),
69
+ 'filter_condition_callback' => array($this, 'filterCallbackContact')
70
+ ))->addColumn('is_copy', array(
71
+ 'header' => Mage::helper('connector')->__('Is Copy'),
72
+ 'align' => 'center',
73
+ 'width' => '20px',
74
+ 'index' => 'is_copy',
75
+ 'escape' => true,
76
+ 'type' => 'options',
77
+ 'renderer' => 'email_connector/adminhtml_column_renderer_imported',
78
+ 'options' => array(
79
+ '1' => 'Is A Copy',
80
+ 'null' => 'Not A Copy'
81
+ ),
82
+ 'filter_condition_callback' => array($this, 'filterCallbackContact')
83
+ ))->addColumn('order_increment_id', array(
84
+ 'header' => Mage::helper('connector')->__('Increment ID'),
85
+ 'align' => 'left',
86
+ 'width' => '50px',
87
+ 'index' => 'order_increment_id',
88
+ 'type' => 'number',
89
+ 'escape' => true
90
+ ))->addColumn('create_message', array(
91
+ 'header' => Mage::helper('connector')->__('Create Message'),
92
+ 'align' => 'left',
93
+ 'width' => '300px',
94
+ 'index' => 'create_message',
95
+ 'type' => 'text',
96
+ 'escape' => true
97
+ ))->addColumn('contact_message', array(
98
+ 'header' => Mage::helper('connector')->__('Contact Message'),
99
+ 'align' => 'left',
100
+ 'width' => '300px',
101
+ 'index' => 'contact_message',
102
+ 'type' => 'text',
103
+ 'escape' => true
104
+ ))->addColumn('message', array(
105
+ 'header' => Mage::helper('connector')->__('Send Message'),
106
+ 'align' => 'left',
107
+ 'width' => '300px',
108
+ 'index' => 'message',
109
+ 'type' => 'text',
110
+ 'escape' => true
111
+ ))->addColumn('event_name', array(
112
+ 'header' => Mage::helper('connector')->__('Email Name'),
113
+ 'align' => 'left',
114
+ 'index' => 'event_name',
115
+ 'width' => '100px',
116
+ 'type' => 'string',
117
+ 'escape' => true,
118
+ ))->addColumn('created_at', array(
119
+ 'header' => Mage::helper('connector')->__('Created At'),
120
+ 'align' => 'center',
121
+ 'width' => '100px',
122
+ 'index' => 'created_at',
123
+ 'type' => 'datetime',
124
+ 'escape' => true
125
+ ))->addColumn('updated_at', array(
126
+ 'header' => Mage::helper('connector')->__('Updated At'),
127
+ 'align' => 'center',
128
+ 'width' => '100px',
129
+ 'index' => 'updated_at',
130
+ 'type' => 'datetime',
131
+ 'escape' => true
132
+ ))->addColumn('sent_at', array(
133
+ 'header' => Mage::helper('connector')->__('Sent At'),
134
+ 'align' => 'center',
135
+ 'width' => '100px',
136
+ 'index' => 'sent_at',
137
+ 'type' => 'datetime',
138
+ 'escape' => true
139
+ ));
140
+ if (!Mage::app()->isSingleStoreMode()) {
141
+ $this->addColumn('website_id', array(
142
+ 'header' => Mage::helper('customer')->__('Website'),
143
+ 'align' => 'center',
144
+ 'width' => '80px',
145
+ 'type' => 'options',
146
+ 'options' => Mage::getSingleton('adminhtml/system_store')->getWebsiteOptionHash(true),
147
+ 'index' => 'website_id',
148
+ ));
149
+ }
150
+
151
+ $this->addExportType('*/*/exportCsv', Mage::helper('connector')->__('CSV'));
152
+ return parent::_prepareColumns();
153
+ }
154
+
155
+ /**
156
+ * Get the store selected.
157
+ * @return Mage_Core_Model_Store
158
+ * @throws Exception
159
+ */
160
+ protected function _getStore()
161
+ {
162
+ $storeId = (int) $this->getRequest()->getParam('store', 0);
163
+ return Mage::app()->getStore($storeId);
164
+ }
165
+
166
+
167
+ /**
168
+ * @return $this|Mage_Adminhtml_Block_Widget_Grid
169
+ */
170
+ protected function _prepareMassaction()
171
+ {
172
+ $this->setMassactionIdField('id');
173
+ $this->getMassactionBlock()->setFormFieldName('campaign');
174
+ $this->getMassactionBlock()->addItem('delete', array (
175
+ 'label'=> Mage::helper('connector')->__('Delete'),
176
+ 'url' => $this->getUrl('*/*/massDelete'),
177
+ 'confirm' => Mage::helper('connector')->__('Are you sure?')
178
+ )
179
+ );
180
+
181
+ $this->getMassactionBlock()->addItem('resend', array('label'=>Mage::helper('connector')->__('Resend'),'url'=>$this->getUrl('*/*/massResend')));
182
+ $this->getMassactionBlock()->addItem('re-create', array('label'=>Mage::helper('connector')->__('Recreate'),'url'=>$this->getUrl('*/*/massRecreate')));
183
+ return $this;
184
+ }
185
+
186
+ /**
187
+ * Grid selected url.
188
+ * @return string
189
+ */
190
+ public function getGridUrl()
191
+ {
192
+ return $this->getUrl('*/*/grid', array('_current'=>true));
193
+ }
194
+ /**
195
+ * Custom callback action for the campaign.
196
+ *
197
+ * @param $collection
198
+ * @param $column
199
+ */
200
+ public function filterCallbackContact($collection, $column)
201
+ {
202
+ $field = $column->getFilterIndex() ? $column->getFilterIndex() : $column->getIndex();
203
+ $value = $column->getFilter()->getValue();
204
+
205
+ if ($value == 'null') {
206
+ $collection->addFieldToFilter($field, array('null' => true) );
207
+ } else {
208
+ $collection->addFieldToFilter($field, array('notnull' => true));
209
+ }
210
+ }
211
+
212
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Column/Renderer/Imported.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Column_Renderer_Imported extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
4
+ {
5
+ /**
6
+ * Render grid columns.
7
+ * @param Varien_Object $row
8
+ *
9
+ * @return string
10
+ */
11
+ public function render(Varien_Object $row)
12
+ {
13
+ return '<img style="padding-top:2px" '.(($this->_getValue($row)=='1' || $this->_getValue($row)==true) ? 'src="'.$this->getSkinUrl('images/success_msg_icon.gif').'" alt="YES" ' : 'src="'.
14
+ $this->getSkinUrl('images/error_msg_icon.gif').'" alt="NO" ').'>';
15
+ }
16
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Column/Renderer/Status.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Column_Renderer_Status extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
4
+ {
5
+ /**
6
+ * Render the grid columns.
7
+ *
8
+ * @param Varien_Object $row
9
+ * @return string
10
+ */
11
+ public function render(Varien_Object $row)
12
+ {
13
+ if($this->getValue($row) == '1')
14
+ return 'Subscribed';
15
+ return 'Unsubscribed';
16
+ }
17
+
18
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Column/Renderer/Sync.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Column_Renderer_Sync extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
4
+ {
5
+ /**
6
+ * Render the grid columns.
7
+ *
8
+ * @param Varien_Object $row
9
+ * @return string
10
+ */
11
+ public function render(Varien_Object $row)
12
+ {
13
+ return '<button title="Connect" type="button" style=""><span><span><span>Sync Now</span></span></span></button>';
14
+ }
15
+
16
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Config.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Config extends Mage_Adminhtml_Block_Widget_Grid_Container
4
+ {
5
+ /**
6
+ * Set the template.
7
+ */
8
+ public function __construct()
9
+ {
10
+ $this->_controller = 'adminhtml_config';
11
+ $this->_blockGroup = 'email_connector';
12
+ parent::__construct();
13
+ $this->_headerText = Mage::helper('connector')->__('Config');
14
+ $this->_removeButton('add');
15
+
16
+ $this->setTemplate('connector/grid.phtml');
17
+ }
18
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Config/Customdatafields.php ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Config_Customdatafields extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
4
+ {
5
+ /**
6
+ * Customer attribute
7
+ *
8
+ */
9
+ protected $_getAttributeRenderer;
10
+
11
+ /**
12
+ * Datafields
13
+ */
14
+ protected $_getDatafieldRenderer;
15
+
16
+
17
+ /**
18
+ * Construct.
19
+ */
20
+ public function __construct()
21
+ {
22
+ $this->_addAfter = false;
23
+ $this->_addButtonLabel = Mage::helper('adminhtml')->__('Add New Attribute');
24
+ parent::__construct();
25
+
26
+ }
27
+
28
+ protected function _prepareToRender()
29
+ {
30
+ $this->_getDatafieldRenderer = null;
31
+ $this->_getAttributeRenderer = null;
32
+ $this->addColumn('attribute',
33
+ array(
34
+ 'label' => Mage::helper('adminhtml')->__('Attribute'),
35
+ 'style' => 'width:120px',
36
+ )
37
+ );
38
+ $this->addColumn('datafield', array(
39
+ 'label' => Mage::helper('adminhtml')->__('DataField'),
40
+ 'style' => 'width:120px',
41
+ )
42
+ );
43
+ }
44
+
45
+ protected function _renderCellTemplate($columnName)
46
+ {
47
+ $inputName = $this->getElement()->getName() . '[#{_id}][' . $columnName . ']';
48
+ if ($columnName=="attribute") {
49
+ return $this->_getAttributeRenderer()
50
+ ->setName($inputName)
51
+ ->setTitle($columnName)
52
+ ->setExtraParams('style="width:160px"')
53
+ ->setOptions(
54
+ $this->getElement()->getValues()
55
+ )
56
+ ->toHtml();
57
+ } elseif ($columnName == "datafield") {
58
+ return $this->_getDatafieldRenderer()
59
+ ->setName($inputName)
60
+ ->setTitle($columnName)
61
+ ->setExtraParams('style="width:160px"')
62
+ ->setOptions(Mage::getModel('email_connector/adminhtml_source_datafields')->toOptionArray())
63
+ ->toHtml();
64
+ }
65
+ return parent::_renderCellTemplate($columnName);
66
+ }
67
+
68
+ /**
69
+ * Assign extra parameters to row
70
+ *
71
+ * @param Varien_Object $row
72
+ */
73
+ protected function _prepareArrayRow(Varien_Object $row)
74
+ {
75
+
76
+ $row->setData(
77
+ 'option_extra_attr_' . $this->_getAttributeRenderer()->calcOptionHash($row->getData('attribute')),
78
+ 'selected="selected"'
79
+ );
80
+
81
+ $row->setData(
82
+ 'option_extra_attr_' . $this->_getDatafieldRenderer()->calcOptionHash($row->getData('datafield')),
83
+ 'selected="selected"'
84
+ );
85
+ }
86
+ protected function _getAttributeRenderer()
87
+ {
88
+ if (!$this->_getAttributeRenderer) {
89
+ $this->_getAttributeRenderer = $this->getLayout()
90
+ ->createBlock('email_connector/adminhtml_config_select')
91
+ ->setIsRenderToJsTemplate(true);
92
+ }
93
+ return $this->_getAttributeRenderer;
94
+ }
95
+
96
+ protected function _getDatafieldRenderer()
97
+ {
98
+ if (!$this->_getDatafieldRenderer) {
99
+ $this->_getDatafieldRenderer = $this->getLayout()
100
+ ->createBlock('email_connector/adminhtml_config_select')
101
+ ->setIsRenderToJsTemplate(true);
102
+ }
103
+ return $this->_getDatafieldRenderer;
104
+ }
105
+
106
+ public function _toHtml()
107
+ {
108
+ return '<input type="hidden" id="'.$this->getElement()->getHtmlId().'"/>'.parent::_toHtml();
109
+
110
+ }
111
+
112
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Config/Select.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Config_Select extends Mage_Core_Block_Html_Select
4
+ {
5
+ /**
6
+ * Return output in one line
7
+ *
8
+ * @return string
9
+ */
10
+ public function _toHtml()
11
+ {
12
+ return trim(preg_replace('/\s+/', ' ',parent::_toHtml()));
13
+ }
14
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Config/Template/Templatefields.php ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Config_Template_Templatefields extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
4
+ {
5
+ /**
6
+ * Templates
7
+ *
8
+ */
9
+ protected $_getTemplateRenderer;
10
+
11
+ /**
12
+ * Datafields
13
+ */
14
+ protected $_getDatafieldRenderer;
15
+
16
+ /**
17
+ * Send Type
18
+ */
19
+ protected $_getSendtypeRenderer;
20
+
21
+
22
+ /**
23
+ * Construct.
24
+ */
25
+ public function __construct()
26
+ {
27
+ $this->_addAfter = false;
28
+ $this->_addButtonLabel = Mage::helper('adminhtml')->__('Map Template');
29
+ parent::__construct();
30
+
31
+ }
32
+
33
+ protected function _prepareToRender()
34
+ {
35
+ $this->_getDatafieldRenderer = null;
36
+ $this->_getTemplateRenderer = null;
37
+ $this->_getSendtypeRenderer = null;
38
+ $this->addColumn('template',
39
+ array(
40
+ 'label' => Mage::helper('adminhtml')->__('Magento Template'),
41
+ 'style' => 'width:120px',
42
+ )
43
+ );
44
+ $this->addColumn('sendtype', array(
45
+ 'label' => Mage::helper('adminhtml')->__('Send Type'),
46
+ 'style' => 'width:120px',
47
+ )
48
+ );
49
+ $this->addColumn('datafield', array(
50
+ 'label' => Mage::helper('adminhtml')->__("Campaign Template <br> (Need For Design + Send)"),
51
+ 'style' => 'width:120px',
52
+ )
53
+ );
54
+ }
55
+
56
+ protected function _renderCellTemplate($columnName)
57
+ {
58
+ $inputName = $this->getElement()->getName() . '[#{_id}][' . $columnName . ']';
59
+ if ($columnName=="template") {
60
+ return $this->_getTemplateRenderer()
61
+ ->setName($inputName)
62
+ ->setTitle($columnName)
63
+ ->setExtraParams('style="width:160px"')
64
+ ->setOptions(
65
+ $this->getElement()->getValues()
66
+ )
67
+ ->toHtml();
68
+ } elseif ($columnName == "sendtype") {
69
+ return $this->_getSendtypeRenderer()
70
+ ->setName($inputName)
71
+ ->setTitle($columnName)
72
+ ->setExtraParams('style="width:160px"')
73
+ ->setOptions(Mage::getModel('email_connector/adminhtml_source_transactional_sendtype')->toOptionArray())
74
+ ->toHtml();
75
+ } elseif ($columnName == "datafield") {
76
+ return $this->_getDatafieldRenderer()
77
+ ->setName($inputName)
78
+ ->setTitle($columnName)
79
+ ->setExtraParams('style="width:160px"')
80
+ ->setOptions(Mage::getModel('email_connector/adminhtml_source_transactional_campaigns')->toOptionArray())
81
+ ->toHtml();
82
+ }
83
+ return parent::_renderCellTemplate($columnName);
84
+ }
85
+
86
+ /**
87
+ * Assign extra parameters to row
88
+ *
89
+ * @param Varien_Object $row
90
+ */
91
+ protected function _prepareArrayRow(Varien_Object $row)
92
+ {
93
+
94
+ $row->setData(
95
+ 'option_extra_attr_' . $this->_getTemplateRenderer()->calcOptionHash($row->getData('template')),
96
+ 'selected="selected"'
97
+ );
98
+
99
+ $row->setData(
100
+ 'option_extra_attr_' . $this->_getSendtypeRenderer()->calcOptionHash($row->getData('sendtype')),
101
+ 'selected="selected"'
102
+ );
103
+
104
+ $row->setData(
105
+ 'option_extra_attr_' . $this->_getDatafieldRenderer()->calcOptionHash($row->getData('datafield')),
106
+ 'selected="selected"'
107
+ );
108
+ }
109
+ protected function _getTemplateRenderer()
110
+ {
111
+ if (!$this->_getTemplateRenderer) {
112
+ $this->_getTemplateRenderer = $this->getLayout()
113
+ ->createBlock('email_connector/adminhtml_config_select')
114
+ ->setIsRenderToJsTemplate(true);
115
+ }
116
+ return $this->_getTemplateRenderer;
117
+ }
118
+
119
+ protected function _getDatafieldRenderer()
120
+ {
121
+ if (!$this->_getDatafieldRenderer) {
122
+ $this->_getDatafieldRenderer = $this->getLayout()
123
+ ->createBlock('email_connector/adminhtml_config_select')
124
+ ->setIsRenderToJsTemplate(true);
125
+ }
126
+ return $this->_getDatafieldRenderer;
127
+ }
128
+
129
+ protected function _getSendtypeRenderer()
130
+ {
131
+ if (!$this->_getSendtypeRenderer) {
132
+ $this->_getSendtypeRenderer = $this->getLayout()
133
+ ->createBlock('email_connector/adminhtml_config_select')
134
+ ->setIsRenderToJsTemplate(true);
135
+ }
136
+ return $this->_getSendtypeRenderer;
137
+ }
138
+ public function _toHtml()
139
+ {
140
+ if(count($this->getElement()->getValues())){
141
+ return '<input type="hidden" id="'.$this->getElement()->getHtmlId().'"/>'.parent::_toHtml();
142
+ }
143
+ else {
144
+ return "<p class='notice'>". Mage::helper('adminhtml')->__("There are no email templates to map.") . "</p>";
145
+ }
146
+
147
+ }
148
+
149
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Contact.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Contact extends Mage_Adminhtml_Block_Widget_Grid_Container
4
+ {
5
+ /**
6
+ * Set the template.
7
+ */
8
+ public function __construct()
9
+ {
10
+ $this->_controller = 'adminhtml_contact';
11
+ $this->_blockGroup = 'email_connector';
12
+ parent::__construct();
13
+ $this->_headerText = Mage::helper('connector')->__('Contacts');
14
+ $this->_removeButton('add');
15
+
16
+ $this->setTemplate('connector/grid.phtml');
17
+ }
18
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Contact/Edit.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Contact_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+ $this->_blockGroup = 'email_connector';
9
+ $this->_controller = 'adminhtml_contact';
10
+ $this->_updateButton('save', 'label', Mage::helper('connector')->__('Save Contact'));
11
+ $this->_updateButton('delete', 'label', Mage::helper('connector')->__('Delete Contact'));
12
+ $this->_addButton('saveandcontinue', array(
13
+ 'label' => Mage::helper('connector')->__('Save And Continue Edit'),
14
+ 'onclick' => 'saveAndContinueEdit()',
15
+ 'class' => 'save',
16
+ ), -100);
17
+ $this->_formScripts[] = "
18
+ function saveAndContinueEdit(){
19
+ editForm.submit($('edit_form').action+'back/edit/');
20
+ }
21
+ ";
22
+ }
23
+
24
+ /**
25
+ * HEader text.
26
+ * @return string
27
+ */
28
+ public function getHeaderText()
29
+ {
30
+ if ( Mage::registry('contact_data') && Mage::registry('contact_data')->getId() ) {
31
+ return Mage::helper('connnector')->__("Edit Contact '%s'", $this->htmlEscape(Mage::registry('contact_data')->getContact()));
32
+ } else {
33
+ return Mage::helper('connector')->__('Add Contact');
34
+ }
35
+ }
36
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Contact/Edit/Form.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Contact_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
4
+ {
5
+
6
+ /**
7
+ * Contact Form.
8
+ * @return Mage_Adminhtml_Block_Widget_Form
9
+ * @throws Exception
10
+ */
11
+ protected function _prepareForm()
12
+ {
13
+ $form = new Varien_Data_Form(array(
14
+ 'id' => 'edit_form',
15
+ 'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'), 'store' => $this->getRequest()->getParam('store'))),
16
+ 'method' => 'post',
17
+ 'enctype' => 'multipart/form-data'
18
+ )
19
+ );
20
+ $form->setUseContainer(true);
21
+
22
+ $this->setForm($form);
23
+ return parent::_prepareForm();
24
+ }
25
+
26
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Contact/Grid.php ADDED
@@ -0,0 +1,207 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Contact_Grid extends Mage_Adminhtml_Block_Widget_Grid
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+ $this->setId('email_contact_id');
9
+ $this->setDefaultSort('entity_id');
10
+ $this->setDefaultDir('ASC');
11
+ $this->setSaveParametersInSession(true);
12
+ $this->setUseAjax(true);
13
+ }
14
+
15
+ protected function _prepareCollection()
16
+ {
17
+ $collection = Mage::getModel('email_connector/contact')->getCollection();
18
+ $this->setCollection($collection);
19
+ $this->setDefaultSort('updated_at');
20
+ $this->setDefaultDir('DESC');
21
+ return parent::_prepareCollection();
22
+ }
23
+
24
+ protected function _prepareColumns()
25
+ {
26
+ $this->addColumn('email_contact_id', array(
27
+ 'header' => Mage::helper('connector')->__('Email Contact ID'),
28
+ 'width' => '20px',
29
+ 'index' => 'email_contact_id',
30
+ 'type' => 'number',
31
+ 'escape' => true,
32
+ ))->addColumn('email', array(
33
+ 'header' => Mage::helper('connector')->__('Email'),
34
+ 'align' => 'left',
35
+ 'width' => '50px',
36
+ 'index' => 'email',
37
+ 'type' => 'text',
38
+ 'escape' => true
39
+ ))->addColumn('is_guest', array(
40
+ 'header' => Mage::helper('connector')->__('Is Guest'),
41
+ 'align' => 'right',
42
+ 'width' => '50px',
43
+ 'index' => 'is_guest',
44
+ 'type' => 'options',
45
+ 'options' => array(
46
+ '1' => 'Guest',
47
+ 'null' => 'Not Guest'
48
+ ),
49
+ 'escape' => true,
50
+ 'filter_condition_callback' => array($this, 'filterCallbackContact')
51
+ ))->addColumn('customer_id', array(
52
+ 'header' => Mage::helper('connector')->__('Customer ID'),
53
+ 'align' => 'left',
54
+ 'width' => '20px',
55
+ 'index' => 'customer_id',
56
+ 'type' => 'number',
57
+ 'escape' => true
58
+ ))->addColumn('is_subscriber', array(
59
+ 'header' => Mage::helper('connector')->__('Is Subscriber'),
60
+ 'width' => '50px',
61
+ 'align' => 'right',
62
+ 'index' => 'is_subscriber',
63
+ 'type' => 'options',
64
+ 'options' => array(
65
+ '1' => 'Subscriber',
66
+ 'null' => 'Not Subscriber'
67
+ ),
68
+ 'filter_condition_callback' => array($this, 'filterCallbackContact'),
69
+ 'escape' => true,
70
+ ))->addColumn('subscriber_status', array(
71
+ 'header' => Mage::helper('connector')->__('Subscriber Status'),
72
+ 'align' => 'center',
73
+ 'width' => '50px',
74
+ 'index' => 'subscriber_status',
75
+ 'type' => 'options',
76
+ 'options' => array(
77
+ '1' => 'Subscribed',
78
+ '2' => 'Not Active',
79
+ '3' => 'Unsubscribed',
80
+ '4' => 'Unconfirmed'
81
+ ),
82
+ 'escape' => true,
83
+ ))->addColumn('email_imported', array(
84
+ 'header' => Mage::helper('connector')->__('Email Imported'),
85
+ 'width' => '20px',
86
+ 'align' => 'center',
87
+ 'index' => 'email_imported',
88
+ 'escape' => true,
89
+ 'type' => 'options',
90
+ 'options' => Mage::getModel('email_connector/adminhtml_source_contact_imported')->getOptions(),
91
+ 'renderer' => 'email_connector/adminhtml_column_renderer_imported',
92
+ 'filter_condition_callback' => array($this, 'filterCallbackContact')
93
+ ))->addColumn('subscriber_imported', array(
94
+ 'header' => Mage::helper('connector')->__('Subscriber Imported'),
95
+ 'width' => '20px',
96
+ 'align' => 'center',
97
+ 'index' => 'subscriber_imported',
98
+ 'type' => 'options',
99
+ 'escape' => true,
100
+ 'renderer' => 'email_connector/adminhtml_column_renderer_imported',
101
+ 'options' => Mage::getModel('email_connector/adminhtml_source_contact_imported')->getOptions(),
102
+ 'filter_condition_callback' => array($this, 'filterCallbackContact')
103
+ ))->addColumn('suppressed', array(
104
+ 'header' => Mage::helper('connector')->__('Suppressed'),
105
+ 'align' => 'right',
106
+ 'width' => '50px',
107
+ 'index' => 'suppressed',
108
+ 'escape' => true,
109
+ 'type' => 'options',
110
+ 'options' => array(
111
+ '1' => 'Suppressed',
112
+ 'null' => 'Not Suppressed'
113
+ ),
114
+ 'filter_condition_callback' => array($this, 'filterCallbackContact')
115
+ ));
116
+ if (!Mage::app()->isSingleStoreMode()) {
117
+ $this->addColumn('website_id', array(
118
+ 'header' => Mage::helper('customer')->__('Website'),
119
+ 'align' => 'center',
120
+ 'width' => '80px',
121
+ 'type' => 'options',
122
+ 'options' => Mage::getSingleton('adminhtml/system_store')->getWebsiteOptionHash(true),
123
+ 'index' => 'website_id',
124
+ ));
125
+ }
126
+
127
+ $this->addColumn('sync', array(
128
+ 'header' => Mage::helper('connector')->__('Sync Contact'),
129
+ 'align' => 'center',
130
+ 'width' => '80px',
131
+ 'renderer' => 'email_connector/adminhtml_column_renderer_sync'
132
+
133
+ ));
134
+
135
+ $this->addExportType('*/*/exportCsv', Mage::helper('connector')->__('CSV'));
136
+ return parent::_prepareColumns();
137
+ }
138
+
139
+ /**
140
+ * Get the store.
141
+ *
142
+ * @return Mage_Core_Model_Store
143
+ * @throws Exception
144
+ */
145
+ protected function _getStore()
146
+ {
147
+ $storeId = (int) $this->getRequest()->getParam('store', 0);
148
+ return Mage::app()->getStore($storeId);
149
+ }
150
+
151
+ /**
152
+ * Prepare the grid massaction.
153
+ * @return $this|Mage_Adminhtml_Block_Widget_Grid
154
+ */
155
+ protected function _prepareMassaction()
156
+ {
157
+ $this->setMassactionIdField('email_contact_id');
158
+ $this->getMassactionBlock()->setFormFieldName('contact');
159
+ $this->getMassactionBlock()->addItem('delete', array(
160
+ 'label'=> Mage::helper('connector')->__('Delete'),
161
+ 'url' => $this->getUrl('*/*/massDelete'),
162
+ 'confirm' => Mage::helper('connector')->__('Are you sure?')));
163
+ $this->getMassactionBlock()->addItem('resend', array(
164
+ 'label' => Mage::helper('connector')->__('Resend'),
165
+ 'url' => $this->getUrl('*/*/massResend'),
166
+
167
+ ));
168
+ return $this;
169
+ }
170
+
171
+ /**
172
+ * Custom callback action for the subscribers/contacts.
173
+ * @param $collection
174
+ * @param $column
175
+ */
176
+ public function filterCallbackContact($collection, $column)
177
+ {
178
+ $field = $column->getFilterIndex() ? $column->getFilterIndex() : $column->getIndex();
179
+ $value = $column->getFilter()->getValue();
180
+
181
+ if ($value == 'null')
182
+ $collection->addFieldToFilter($field, array('null' => true));
183
+ else
184
+ $collection->addFieldToFilter($field, array('notnull' => true));
185
+ }
186
+
187
+ /**
188
+ * Edit the row.
189
+ * @param $row
190
+ *
191
+ * @return string
192
+ */
193
+ public function getRowUrl($row)
194
+ {
195
+ return $this->getUrl('*/*/edit', array('id' => $row->getEmailContactId()));
196
+ }
197
+
198
+ /**
199
+ * Grid url.
200
+ * @return string
201
+ */
202
+ public function getGridUrl()
203
+ {
204
+ return $this->getUrl('*/*/grid', array('_current'=>true));
205
+ }
206
+
207
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Dashboard extends Mage_Adminhtml_Block_Dashboard_Bar
4
+
5
+ {
6
+ /**
7
+ * Set the template.
8
+ */
9
+ public function __construct()
10
+ {
11
+ parent::_construct();
12
+
13
+ $this->setTemplate('connector/dashboard/accountbar.phtml');
14
+ }
15
+
16
+ /**
17
+ * Prepare the layout.
18
+ *
19
+ * @return Mage_Core_Block_Abstract|void
20
+ * @throws Exception
21
+ */
22
+ protected function _prepareLayout() {
23
+
24
+
25
+ $website = 0;
26
+ //request store param
27
+ if ($store = $this->getRequest()->getParam('store')) {
28
+ $website = Mage::app()->getStore($store)->getWebsite();
29
+ //website param
30
+ } elseif ($this->getRequest()->getParam('website')) {
31
+ $website = $this->getRequest()->getParam('website');
32
+ }
33
+
34
+ $apiUsername = Mage::helper('connector')->getApiUsername($website);
35
+ $apiPassword = Mage::helper('connector')->getApiPassword($website);
36
+
37
+ //api get account info
38
+ $data = Mage::getModel('email_connector/apiconnector_client')
39
+ ->setApiUsername($apiUsername)
40
+ ->setApiPassword($apiPassword)
41
+ ->getAccountInfo();
42
+
43
+ //check if properties for the data exists
44
+ if (isset($data->properties)) {
45
+ foreach ( $data->properties as $one ) {
46
+ //add total for the api calls
47
+ $this->addTotal( $this->__( $one->name ), $one->value, true );
48
+ }
49
+ }
50
+ }
51
+
52
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Switcher.php ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Dashboard_Switcher extends Mage_Adminhtml_Block_Template
4
+ {
5
+ protected function _prepareLayout()
6
+ {
7
+ $this->setTemplate('system/config/switcher.phtml');
8
+ return parent::_prepareLayout();
9
+ }
10
+
11
+ /**
12
+ *
13
+ * @return array
14
+ */
15
+ public function getStoreSelectOptions()
16
+ {
17
+ $section = $this->getRequest()->getParam('section');
18
+
19
+ $curWebsite = $this->getRequest()->getParam('website');
20
+ $curStore = $this->getRequest()->getParam('store');
21
+
22
+ $storeModel = Mage::getSingleton('adminhtml/system_store');
23
+ /* @var $storeModel Mage_Adminhtml_Model_System_Store */
24
+
25
+ $url = Mage::getModel('adminhtml/url');
26
+
27
+ $options = array();
28
+ $options['default'] = array(
29
+ 'label' => Mage::helper('adminhtml')->__('Default Config'),
30
+ 'url' => $url->getUrl('*/*/*', array('section'=>$section)),
31
+ 'selected' => !$curWebsite && !$curStore,
32
+ 'style' => 'background:#ccc; font-weight:bold;',
33
+ );
34
+
35
+ foreach ($storeModel->getWebsiteCollection() as $website) {
36
+ $websiteShow = false;
37
+ foreach ($storeModel->getGroupCollection() as $group) {
38
+ if ($group->getWebsiteId() != $website->getId()) {
39
+ continue;
40
+ }
41
+ $groupShow = false;
42
+ foreach ($storeModel->getStoreCollection() as $store) {
43
+ if ($store->getGroupId() != $group->getId()) {
44
+ continue;
45
+ }
46
+ if (!$websiteShow) {
47
+ $websiteShow = true;
48
+ $options['website_' . $website->getId()] = array(
49
+ 'label' => $website->getName(),
50
+ 'url' => $url->getUrl('*/*/*', array('section'=>$section, 'website'=>$website->getId())),
51
+ 'selected' => !$curStore && $curWebsite == $website->getId(),
52
+ 'style' => 'padding-left:16px; background:#DDD; font-weight:bold;',
53
+ );
54
+ }
55
+ if (!$groupShow) {
56
+ $groupShow = true;
57
+ $options['group_' . $group->getId() . '_open'] = array(
58
+ 'is_group' => true,
59
+ 'is_close' => false,
60
+ 'label' => $group->getName(),
61
+ 'style' => 'padding-left:32px;'
62
+ );
63
+ }
64
+ $options['store_' . $store->getId()] = array(
65
+ 'label' => $store->getName(),
66
+ 'url' => $url->getUrl('*/*/*', array('section'=>$section, 'store'=>$store->getId())),
67
+ 'selected' => $curStore == $store->getId(),
68
+ 'style' => '',
69
+ );
70
+ }
71
+ if ($groupShow) {
72
+ $options['group_' . $group->getId() . '_close'] = array(
73
+ 'is_group' => true,
74
+ 'is_close' => true,
75
+ );
76
+ }
77
+ }
78
+ }
79
+
80
+ return $options;
81
+ }
82
+
83
+ /**
84
+ * Return store switcher hint html
85
+ *
86
+ * @return mixed
87
+ */
88
+ public function getHintHtml()
89
+ {
90
+ return Mage::getBlockSingleton('adminhtml/store_switcher')->getHintHtml();
91
+ }
92
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Dashboard_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
4
+ {
5
+
6
+ public function __construct()
7
+ {
8
+ parent::__construct();
9
+ $this->setId('connector_dashboard_tabs');
10
+ $this->setTitle($this->__('Dashboards' ));
11
+ $this->setTemplate('connector/dashboard/tabs.phtml');
12
+ }
13
+
14
+ /**
15
+ * set tabs
16
+ *
17
+ * @return Mage_Core_Block_Abstract
18
+ * @throws Exception
19
+ */
20
+ protected function _beforeToHtml()
21
+ {
22
+ $this->addTab(
23
+ 'general',
24
+ array (
25
+ 'label' => $this->__('Account Information'),
26
+ 'title' => $this->__('Account Information'),
27
+ 'content' => $this->getLayout()->createBlock('email_connector/adminhtml_dashboard_tabs_general')->toHtml(),
28
+ )
29
+ );
30
+ $this->addTab(
31
+ 'status',
32
+ array (
33
+ 'label' => $this->__('Connector Status'),
34
+ 'title' => $this->__('Connector Status'),
35
+ 'url' => $this->getUrl('*/*/statusGrid'),
36
+ 'class' => 'ajax',
37
+ 'active' => true
38
+ )
39
+ );
40
+ $this->addTab(
41
+ 'analysis',
42
+ array (
43
+ 'label' => $this->__('Data Analysis'),
44
+ 'title' => $this->__('Data Analysis'),
45
+ 'content' => $this->getLayout()->createBlock('email_connector/adminhtml_dashboard_tabs_analysis')->toHtml()
46
+ )
47
+ );
48
+ $this->addTab(
49
+ 'config',
50
+ array (
51
+ 'label' => $this->__('API Status'),
52
+ 'title' => $this->__('API Status'),
53
+ 'content' => $this->getLayout()->createBlock('email_connector/adminhtml_dashboard_tabs_config')->toHtml()
54
+ )
55
+ );
56
+ return parent::_beforeToHtml();
57
+ }
58
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Analysis.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Dashboard_Tabs_Analysis extends Mage_Adminhtml_Block_Dashboard_Bar
4
+ {
5
+ /**
6
+ * set template
7
+ *
8
+ * @throws Exception
9
+ */
10
+ public function __construct()
11
+ {
12
+ parent::_construct();
13
+ $this->setTemplate('connector/dashboard/tabs/analysis/index.phtml');
14
+ }
15
+
16
+ /**
17
+ * Prepare the layout. set child blocks
18
+ *
19
+ * @return Mage_Core_Block_Abstract|void
20
+ * @throws Exception
21
+ */
22
+ protected function _prepareLayout()
23
+ {
24
+ $this->setChild('sales',
25
+ $this->getLayout()->createBlock('email_connector/adminhtml_dashboard_tabs_analysis_sales')
26
+ );
27
+ $this->setChild('abandoned_cart',
28
+ $this->getLayout()->createBlock('email_connector/adminhtml_dashboard_tabs_analysis_abandonedcarts')
29
+ );
30
+ $this->setChild('customer',
31
+ $this->getLayout()->createBlock('email_connector/adminhtml_dashboard_tabs_analysis_customer')
32
+ );
33
+ $this->setChild('subscriber',
34
+ $this->getLayout()->createBlock('email_connector/adminhtml_dashboard_tabs_analysis_subscriber')
35
+ );
36
+ $this->setChild('rfm',
37
+ $this->getLayout()->createBlock('email_connector/adminhtml_dashboard_tabs_analysis_rfm')
38
+ );
39
+ parent::_prepareLayout();
40
+ }
41
+
42
+ /**
43
+ * get Tab content title
44
+ *
45
+ * @return string
46
+ */
47
+ public function getTitle()
48
+ {
49
+ return "Marketing Automation Data Analysis";
50
+ }
51
+
52
+ /**
53
+ * get column width
54
+ *
55
+ * @return string
56
+ */
57
+ public function getColumnWidth()
58
+ {
59
+ return "290px";
60
+ }
61
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Analysis/Abandonedcarts.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Dashboard_Tabs_Analysis_Abandonedcarts extends Dotdigitalgroup_Email_Block_Adminhtml_Dashboard_Tabs_Analysis
4
+ {
5
+ protected $_store = 0;
6
+ protected $_group = 0;
7
+ protected $_website = 0;
8
+
9
+ /**
10
+ * set template
11
+ *
12
+ * @throws Exception
13
+ */
14
+ public function __construct()
15
+ {
16
+ parent::_construct();
17
+
18
+ $this->_store = $this->getRequest()->getParam('store');
19
+ $this->_group = $this->getRequest()->getParam('group');
20
+ $this->_website = $this->getRequest()->getParam('website');
21
+ $this->setTemplate('connector/dashboard/tabs/data.phtml');
22
+ }
23
+
24
+ /**
25
+ * Prepare the layout.
26
+ *
27
+ * @return Mage_Core_Block_Abstract|void
28
+ * @throws Exception
29
+ */
30
+ protected function _prepareLayout()
31
+ {
32
+ $lifetimeAbanodned = $this->getAbandonedCartInformationForTab();
33
+ $this->addTotal($this->__('Total Abandoned Cart Lost Revenue'), $lifetimeAbanodned->getLifetime());
34
+ $this->addTotal($this->__('Average Abandoned Cart Lost Revenue'), $lifetimeAbanodned->getAverage());
35
+ $this->addTotal($this->__('Total Number Of Abandoned Carts'), $lifetimeAbanodned->getTotalCount(), true);
36
+ $this->addTotal($this->__('Average Abandoned Carts Created Per Day'), $lifetimeAbanodned->getDayCount(), true);
37
+ }
38
+
39
+ /**
40
+ * get abandoned cart information for tab from abandoned analysis model
41
+ *
42
+ * @return Varien_Object
43
+ */
44
+ protected function getAbandonedCartInformationForTab()
45
+ {
46
+ $abandonedAnalysisModel = Mage::getModel('email_connector/adminhtml_dashboard_tabs_analysis_abandoned');
47
+ return $abandonedAnalysisModel->getLifeTimeAbandoned($this->_store, $this->_website, $this->_group);
48
+ }
49
+
50
+ /**
51
+ * @return string
52
+ */
53
+ public function getTitle()
54
+ {
55
+ return "Abandoned Carts";
56
+ }
57
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Analysis/Customer.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Dashboard_Tabs_Analysis_Customer extends Dotdigitalgroup_Email_Block_Adminhtml_Dashboard_Tabs_Analysis
4
+ {
5
+ protected $_store = 0;
6
+ protected $_group = 0;
7
+ protected $_website = 0;
8
+
9
+ /**
10
+ * set template
11
+ *
12
+ * @throws Exception
13
+ */
14
+ public function __construct()
15
+ {
16
+ parent::_construct();
17
+
18
+ $this->_store = $this->getRequest()->getParam('store');
19
+ $this->_group = $this->getRequest()->getParam('group');
20
+ $this->_website = $this->getRequest()->getParam('website');
21
+ $this->setTemplate('connector/dashboard/tabs/data.phtml');
22
+ }
23
+
24
+ /**
25
+ * Prepare the layout.
26
+ *
27
+ * @return Mage_Core_Block_Abstract|void
28
+ * @throws Exception
29
+ */
30
+ protected function _prepareLayout()
31
+ {
32
+ $lifetimeCustomer = $this->getCustomerInformationForTab();
33
+ $this->addTotal($this->__('Total Number Of Customers'), $lifetimeCustomer->getTotalCount(), true);
34
+ $this->addTotal($this->__('Average Customers Created Per Day'), $lifetimeCustomer->getDayCount(), true);
35
+ }
36
+
37
+ /**
38
+ * get customer information for tab from customer analysis model
39
+ *
40
+ * @return Varien_Object
41
+ */
42
+ protected function getCustomerInformationForTab()
43
+ {
44
+ $customerAnalysisModel = Mage::getModel('email_connector/adminhtml_dashboard_tabs_analysis_customer');
45
+ return $customerAnalysisModel->getLifeTimeTimeCustomer($this->_store, $this->_website, $this->_group);
46
+ }
47
+
48
+ /**
49
+ * @return string
50
+ */
51
+ public function getTitle()
52
+ {
53
+ return "Customers";
54
+ }
55
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Analysis/Rfm.php ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Dashboard_Tabs_Analysis_Rfm extends Dotdigitalgroup_Email_Block_Adminhtml_Dashboard_Tabs_Analysis
4
+ {
5
+ protected $rfm = array();
6
+ protected $_store = 0;
7
+ protected $_group = 0;
8
+ protected $_website = 0;
9
+
10
+ /**
11
+ * set template
12
+ *
13
+ * @throws Exception
14
+ */
15
+ public function __construct()
16
+ {
17
+ parent::_construct();
18
+
19
+ $this->_store = $this->getRequest()->getParam('store');
20
+ $this->_group = $this->getRequest()->getParam('group');
21
+ $this->_website = $this->getRequest()->getParam('website');
22
+ $this->setTemplate('connector/dashboard/tabs/analysis/rfm.phtml');
23
+ }
24
+
25
+ /**
26
+ * Prepare the layout.
27
+ *
28
+ * @return Mage_Core_Block_Abstract|void
29
+ * @throws Exception
30
+ */
31
+ protected function _prepareLayout()
32
+ {
33
+ $rfmAnalysisModel = Mage::getModel('email_connector/adminhtml_dashboard_tabs_analysis_rfm');
34
+ $this->rfm = $rfmAnalysisModel->getPreparedRfm($this->_store, $this->_website, $this->_group);
35
+ foreach($this->rfm['Monetary'] as $key => $value)
36
+ {
37
+ $this->rfm['Monetary'][$key] = $this->format($value);
38
+ }
39
+ }
40
+
41
+ /**
42
+ * @return array
43
+ */
44
+ protected function getRfm()
45
+ {
46
+ foreach($this->rfm as $k => $type){
47
+ foreach($type as $p => $value){
48
+ if($value == '')
49
+ $this->rfm[$k][$p] = '0';
50
+ }
51
+ }
52
+ return $this->rfm;
53
+ }
54
+
55
+ /**
56
+ * get currency
57
+ *
58
+ * @return Mage_Directory_Model_Currency
59
+ * @throws Exception
60
+ * @throws Mage_Core_Exception
61
+ */
62
+ public function getCurrency()
63
+ {
64
+ if ($this->_store) {
65
+ $currencyCode = Mage::app()->getStore($this->getRequest()->getParam('store'))->getBaseCurrency();
66
+ } else if ($this->_website){
67
+ $currencyCode = Mage::app()->getWebsite($this->getRequest()->getParam('website'))->getBaseCurrency();
68
+ } else if ($this->_group){
69
+ $currencyCode = Mage::app()->getGroup($this->getRequest()->getParam('group'))->getWebsite()->getBaseCurrency();
70
+ } else {
71
+ $currencyCode = Mage::app()->getStore()->getBaseCurrency();
72
+ }
73
+ return $currencyCode;
74
+ }
75
+
76
+ /**
77
+ * format price from currency
78
+ *
79
+ * @param $price
80
+ * @return string
81
+ */
82
+ public function format($price)
83
+ {
84
+ return $this->getCurrency()->format($price);
85
+ }
86
+
87
+ public function getTitle()
88
+ {
89
+ return $this->__("RFM Matrix") . "(<a href='https://econsultancy.com/blog/64481-finding-your-best-customers-with-the-rfm-matrix' target='_blank'>" . $this->__("Find out more") . "</a>)";
90
+ }
91
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Analysis/Sales.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Dashboard_Tabs_Analysis_Sales extends Dotdigitalgroup_Email_Block_Adminhtml_Dashboard_Tabs_Analysis
4
+ {
5
+ protected $_store = 0;
6
+ protected $_group = 0;
7
+ protected $_website = 0;
8
+
9
+ /**
10
+ * set template
11
+ *
12
+ * @throws Exception
13
+ */
14
+ public function __construct()
15
+ {
16
+ parent::_construct();
17
+
18
+ $this->_store = $this->getRequest()->getParam('store');
19
+ $this->_group = $this->getRequest()->getParam('group');
20
+ $this->_website = $this->getRequest()->getParam('website');
21
+ $this->setTemplate('connector/dashboard/tabs/data.phtml');
22
+ }
23
+
24
+ /**
25
+ * Prepare the layout.
26
+ *
27
+ * @return Mage_Core_Block_Abstract|void
28
+ * @throws Exception
29
+ */
30
+ protected function _prepareLayout()
31
+ {
32
+ $lifetimeSales = $this->getSalesInformationForTab();
33
+ $this->addTotal($this->__('Total Sales Revenue'), $lifetimeSales->getLifetime());
34
+ $this->addTotal($this->__('Average Order Value'), $lifetimeSales->getAverage());
35
+ $this->addTotal($this->__('Total Number Of Orders'), $lifetimeSales->getTotalCount(), true);
36
+ $this->addTotal($this->__('Average Orders Created Per Day'), $lifetimeSales->getDayCount(), true);
37
+ }
38
+
39
+ /**
40
+ * get sales information from order analysis model
41
+ *
42
+ * @return Varien_Object
43
+ */
44
+ protected function getSalesInformationForTab()
45
+ {
46
+ $orderAnalysisModel = Mage::getModel('email_connector/adminhtml_dashboard_tabs_analysis_orders');
47
+ return $orderAnalysisModel->getLifetimeSales($this->_store, $this->_website, $this->_group);
48
+ }
49
+
50
+ public function getTitle()
51
+ {
52
+ return "Sales";
53
+ }
54
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Analysis/Subscriber.php ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Dashboard_Tabs_Analysis_Subscriber extends Dotdigitalgroup_Email_Block_Adminhtml_Dashboard_Tabs_Analysis
4
+ {
5
+ protected $_store = 0;
6
+ protected $_group = 0;
7
+ protected $_website = 0;
8
+
9
+ /**
10
+ * set template
11
+ *
12
+ * @throws Exception
13
+ */
14
+ public function __construct()
15
+ {
16
+ parent::_construct();
17
+
18
+ $this->_store = $this->getRequest()->getParam('store');
19
+ $this->_group = $this->getRequest()->getParam('group');
20
+ $this->_website = $this->getRequest()->getParam('website');
21
+ $this->setTemplate('connector/dashboard/tabs/data.phtml');
22
+ }
23
+
24
+ /**
25
+ * Prepare the layout.
26
+ *
27
+ * @return Mage_Core_Block_Abstract|void
28
+ * @throws Exception
29
+ */
30
+ protected function _prepareLayout()
31
+ {
32
+ $lifetimeSubscribers = $this->getSubscriberInformationForTab();
33
+ $this->addTotal($this->__('Total Number Of Subscribers'), $lifetimeSubscribers->getTotalSubscriber(), true);
34
+ $this->addTotal($this->__('Subscribers Who Are Also Customers'), $lifetimeSubscribers->getTotalSubscriberCustomer(), true);
35
+ $this->addTotal($this->__('Average Subscribers Created Per Day'), $lifetimeSubscribers->getSubscribersPerDay(), true);
36
+ }
37
+
38
+ /**
39
+ * get subscriber information for tab from subscriber analysis model
40
+ *
41
+ * @return Varien_Object
42
+ */
43
+ protected function getSubscriberInformationForTab()
44
+ {
45
+ $subscriberAnalysisModel = Mage::getModel('email_connector/adminhtml_dashboard_tabs_analysis_subscriber');
46
+ return $subscriberAnalysisModel->getLifetimeSubscribers($this->_store, $this->_website, $this->_group);
47
+ }
48
+
49
+ /**
50
+ * @return string
51
+ */
52
+ public function getTitle()
53
+ {
54
+ return "Subscribers";
55
+ }
56
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Config.php ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Dashboard_Tabs_Config extends Mage_Adminhtml_Block_Dashboard_Bar
4
+ {
5
+ /**
6
+ * set template
7
+ *
8
+ * @throws Exception
9
+ */
10
+ public function __construct()
11
+ {
12
+ parent::_construct();
13
+ $this->setTemplate('connector/dashboard/tabs/config.phtml');
14
+ }
15
+
16
+ /**
17
+ * Prepare the layout. set child blocks
18
+ *
19
+ * @return Mage_Core_Block_Abstract|void
20
+ * @throws Exception
21
+ */
22
+ protected function _prepareLayout()
23
+ {
24
+
25
+ }
26
+
27
+ /**
28
+ * get Tab content title
29
+ *
30
+ * @return string
31
+ */
32
+ public function getTitle()
33
+ {
34
+ return 'Dashboard';
35
+ }
36
+
37
+ /**
38
+ * Load the config data.
39
+ * @return array
40
+ */
41
+ public function getConfigData()
42
+ {
43
+ //config data collection
44
+ $collection = Mage::getModel('email_connector/config')->getCollection()
45
+ ->addFieldToFilter('path', array('neq' => 'connector_api_hour_trigger'))
46
+ ->addFieldToFilter('is_api', true);
47
+
48
+ //@todo sorting is not working due the value types stored
49
+ //$collection->getSelect()->order('value DESC');
50
+
51
+ $data = $collection->getData();
52
+
53
+ return $data;
54
+ }
55
+
56
+ /**
57
+ * Get the time trigger from collection.
58
+ * @return mixed
59
+ */
60
+ public function getTimeTrigger()
61
+ {
62
+ $timeData = Mage::getModel('email_connector/config')->getCollection()
63
+ ->addFieldToFilter('path', Dotdigitalgroup_Email_Helper_Config::CONNECTOR_EMAIL_CONFIG_HOUR_TRIGGER)
64
+ ->setPageSize(1)
65
+ ->getFirstItem();
66
+
67
+ return $timeData->getValue();
68
+ }
69
+
70
+ /**
71
+ * Format the date string.
72
+ * @param $date
73
+ *
74
+ * @return string
75
+ */
76
+ public function formatDateString($date)
77
+ {
78
+ if ($date) {
79
+ $date = new Zend_Date($date);
80
+ return $date->toString(Zend_Date::DATETIME);
81
+ }
82
+ return 'First Time Run';
83
+ }
84
+
85
+ /**
86
+ * get column width
87
+ *
88
+ * @return string
89
+ */
90
+ public function getColumnWidth()
91
+ {
92
+ return "620px";
93
+ }
94
+
95
+
96
+ /**
97
+ * Get doc desription for the Apiconnector reflection class.
98
+ * reutrn the comment for each method.
99
+ * @param $method
100
+ *
101
+ * @return string
102
+ */
103
+ public function getDocDocument($method)
104
+ {
105
+ //reflection class for client
106
+ $rc = new ReflectionClass('Dotdigitalgroup_Email_Model_Apiconnector_Client');
107
+
108
+ //method data
109
+ $meth = $rc->getMethod( $method );
110
+ //grab the doc block for the method
111
+ $docCommment = $meth->getDocComment();
112
+
113
+ //select only the first text
114
+ preg_match( '/([A-Z])+.*\./', $docCommment, $matches );
115
+
116
+ if ( isset( $matches[0] ) ) {
117
+ //return only selected text
118
+ return $matches[0];
119
+ }
120
+ //return all doc block
121
+ return $docCommment;
122
+ }
123
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/General.php ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Dashboard_Tabs_General extends Mage_Adminhtml_Block_Dashboard_Bar
4
+ {
5
+ protected $group = array();
6
+
7
+ /**
8
+ * Set the template.
9
+ */
10
+ public function __construct()
11
+ {
12
+ $this->initiateGroupArray();
13
+ parent::_construct();
14
+ $this->setTemplate('connector/dashboard/tabs/general/index.phtml');
15
+ }
16
+
17
+ /**
18
+ * Prepare the layout.
19
+ *
20
+ * @return Mage_Core_Block_Abstract|void
21
+ * @throws Exception
22
+ */
23
+ protected function _prepareLayout()
24
+ {
25
+ $website = 0;
26
+ if ($store = $this->getRequest()->getParam('store')) {
27
+ $website = Mage::app()->getStore($store)->getWebsite();
28
+ } elseif ($this->getRequest()->getParam('website')) {
29
+ $website = $this->getRequest()->getParam('website');
30
+ }
31
+ $apiUsername = Mage::helper('connector')->getApiUsername($website);
32
+ $apiPassword = Mage::helper('connector')->getApiPassword($website);
33
+ $data = Mage::getModel('email_connector/apiconnector_client')
34
+ ->setApiUsername($apiUsername)
35
+ ->setApiPassword($apiPassword)
36
+ ->getAccountInfo();
37
+
38
+ if(isset($data->id))
39
+ $this->prepareGroupArray($data);
40
+
41
+ $this->_setChild();
42
+
43
+ parent::_prepareLayout();
44
+ }
45
+
46
+ protected function _setChild()
47
+ {
48
+ foreach($this->group as $key => $data){
49
+ $this->setChild($key,
50
+ $this->getLayout()->createBlock('email_connector/adminhtml_dashboard_tabs_general_data', '', $data)
51
+ );
52
+ }
53
+ }
54
+
55
+ protected function prepareGroupArray($data)
56
+ {
57
+ foreach ($data->properties as $one) {
58
+ foreach($this->group as $key => $type){
59
+ if(array_key_exists($one->name, $type)){
60
+ $this->group[$key][$one->name] = $one->value;
61
+ }
62
+ }
63
+ }
64
+ }
65
+
66
+ protected function initiateGroupArray()
67
+ {
68
+ $this->group['account'] = array(
69
+ 'Title' => 'Account',
70
+ 'Name' => $this->__('Not Available'),
71
+ 'MainMobilePhoneNumber' => $this->__('Not Available'),
72
+ 'MainEmail' => $this->__('Not Available'),
73
+ 'AvailableEmailSendsCredits' => $this->__('Not Available')
74
+ );
75
+ $this->group['data'] = array(
76
+ 'Title' => 'Data',
77
+ 'TransactionalDataAllowanceInMegabytes' => $this->__('Not Available'),
78
+ 'TransactionalDataUsageInMegabytes' => $this->__('Not Available')
79
+ );
80
+ $this->group['api'] = array(
81
+ 'Title' => 'Api',
82
+ 'APILocale' => $this->__('Not Available'),
83
+ 'ApiCallsInLastHour' => $this->__('Not Available'),
84
+ 'ApiCallsRemaining' => $this->__('Not Available')
85
+ );
86
+ }
87
+
88
+ /**
89
+ * get Tab content title
90
+ *
91
+ * @return string
92
+ */
93
+ public function getTitle()
94
+ {
95
+ return "Connector Account Information";
96
+ }
97
+
98
+ /**
99
+ * get column width
100
+ *
101
+ * @return string
102
+ */
103
+ public function getColumnWidth()
104
+ {
105
+ return "400px;";
106
+ }
107
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/General/Data.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Dashboard_Tabs_General_Data extends Dotdigitalgroup_Email_Block_Adminhtml_Dashboard_Tabs_General
4
+ {
5
+ protected $data = array();
6
+ protected $title = "";
7
+
8
+ /**
9
+ * set template
10
+ * @param $info
11
+ * @throws Exception
12
+ */
13
+ public function __construct($info = array())
14
+ {
15
+ $this->title = $info['Title'];
16
+ unset($info['Title']);
17
+ $this->data = $info;
18
+
19
+ parent::_construct();
20
+ $this->setTemplate('connector/dashboard/tabs/data.phtml');
21
+ }
22
+
23
+ /**
24
+ * Prepare the layout.
25
+ *
26
+ * @return Mage_Core_Block_Abstract|void
27
+ * @throws Exception
28
+ */
29
+ protected function _prepareLayout()
30
+ {
31
+ foreach($this->data as $key => $value){
32
+ $this->addTotal($this->__($key), $value, true);
33
+ }
34
+ }
35
+
36
+ /**
37
+ * @return string
38
+ */
39
+ public function getTitle()
40
+ {
41
+ return $this->title;
42
+ }
43
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Status.php ADDED
@@ -0,0 +1,1008 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Dashboard_Tabs_Status extends Mage_Adminhtml_Block_Widget implements Mage_Adminhtml_Block_Widget_Tab_Interface
4
+ {
5
+
6
+ const CONNECTOR_DASHBOARD_PASSED = 'available';
7
+ const CONNECTOR_DASHBOARD_WARRNING = 'connector_warning';
8
+ const CONNECTOR_DASHBOARD_FAILED = 'error';
9
+
10
+ private $_checkpoints = array(
11
+ 'extention_installed' => 'Extension And CURL Installed',
12
+ 'cron_running' => 'Cron running',
13
+ 'address_book_mapped' => 'Address Book Mapping',
14
+ 'roi_tracking_enabled' => 'ROI And Page Tracking',
15
+ 'transactional_emails' => 'Transactional Emails',
16
+ 'file_permission_setttings' => 'File Permission Settings',
17
+ 'missing_files' => 'Missing Files',
18
+ 'contact_sync_enabled' => 'Contact Sync Enabled',
19
+ 'contact_syncing' => 'Contacts Syncing',
20
+ 'subscriber_sync_enabled' => 'Subscribers Sync Enabled',
21
+ 'subscribers_syncing' => 'Subscribers Syncing',
22
+ 'abandoned_carts_enabled' => 'Abandoned Carts Enabled',
23
+ 'data_field_mapped' => 'Data Field Mapped',
24
+ 'valid_api_credentials' => 'API Credentials',
25
+ 'order_enabled' => 'Order Sync Enabled',
26
+ 'order_syncing' => 'Orders Syncing',
27
+ 'order_delete' => 'Orders Expiry',
28
+ 'last_abandoned_cart_sent_day' => 'Last Abandoned Cart Sent Day',
29
+ 'conflict_check' => 'Conflict Check',
30
+ 'system_information' => 'System Information'
31
+ );
32
+ /**
33
+ * Set the template.
34
+ */
35
+ public function __construct()
36
+ {
37
+ parent::_construct();
38
+
39
+ $this->setTemplate('connector/dashboard/status.phtml');
40
+ }
41
+
42
+ /**
43
+ * Prepare the layout.
44
+ *
45
+ * @return Mage_Core_Block_Abstract|void
46
+ * @throws Exception
47
+ */
48
+ protected function _prepareLayout()
49
+ {
50
+ }
51
+
52
+ public function canShowTab()
53
+ {
54
+ return true;
55
+ }
56
+ public function isHidden()
57
+ {
58
+ return true;
59
+ }
60
+
61
+ public function getTabLabel()
62
+ {
63
+ return Mage::helper('connector')->__('Marketing Automation System Status');
64
+ }
65
+
66
+ public function getTabTitle()
67
+ {
68
+ return Mage::helper('connector')->__('Marketing Automation System Status');
69
+ }
70
+
71
+ /**
72
+ * Collapse key for the fieldset state.
73
+ * @param $key
74
+ *
75
+ * @return bool
76
+ */
77
+ protected function _getCollapseState($key)
78
+ {
79
+ $extra = Mage::getSingleton('admin/session')->getUser()->getExtra();
80
+ if (isset($extra['configState'][$key])) {
81
+ return $extra['configState'][$key];
82
+ }
83
+
84
+ return false;
85
+ }
86
+
87
+ public function getCheckpoints() {
88
+ return $this->_checkpoints;
89
+ }
90
+
91
+
92
+ public function addCheckpoint($checkpoint)
93
+ {
94
+ $this->_checkpoints[$checkpoint->getName()] = $checkpoint;
95
+ }
96
+
97
+ /**
98
+ * Extension modules and curl check.
99
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
100
+ */
101
+ public function extentionInstalled()
102
+ {
103
+ $resultContent = Mage::getModel('email_connector/adminhtml_dashboard_content');
104
+
105
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
106
+ ->setTitle('Extension Status : ')
107
+ ->setMessage('Extension active and PHP Curl extension installed.');
108
+
109
+ $installed = (bool)Mage::getConfig()->getModuleConfig('Dotdigitalgroup_Email')->is('active', 'true');
110
+
111
+ if (! $installed || ! function_exists('curl_version')) {
112
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED );
113
+ $resultContent->setMessage('Sync May Not Work Properly.');
114
+ $resultContent->setHowto((! function_exists('curl_version'))? 'PHP Curl extention not found !' : 'PHP and Curl extension installed');
115
+ }
116
+ return $resultContent;
117
+ }
118
+
119
+ /**
120
+ * Check cron for the customer sync.
121
+ * @return array
122
+ */
123
+ public function cronRunning()
124
+ {
125
+ $resultContent = Mage::getModel('email_connector/adminhtml_dashboard_content');
126
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
127
+ ->setTitle('Cron Status : ')
128
+ ->setMessage('Cron is running.');
129
+ $message = 'No cronjob task found. Check if cron is configured correctly.';
130
+ $howToSetupCron = 'For more information <a href="http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/how_to_setup_a_cron_job">how to setup the Magento cronjob.</a>';
131
+ $lastCustomerSync = Mage::getModel('email_connector/cron')->getLastCustomerSync();
132
+
133
+ if ($lastCustomerSync === false) {
134
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
135
+ ->setHowto($howToSetupCron);
136
+ } else {
137
+ $timespan = Mage::helper('connector')->dateDiff($lastCustomerSync);
138
+ //last cron was less then 5min
139
+ if ($timespan <= 5 * 60) {
140
+ $resultContent->setTitle('Cronjob is working : ');
141
+ $message = sprintf('(Last execution: %s minute(s) ago) ', round($timespan/60));
142
+ } elseif ($timespan > 5 * 60 && $timespan <= 60 * 60 ) {
143
+ //last cron execution was between 15min and 60min
144
+ $resultContent->setTitle('Last customer sync : ' )
145
+ ->setStyle(self::CONNECTOR_DASHBOARD_FAILED);
146
+ $message = sprintf(' %s minutes. ', round($timespan/60));
147
+ } else {
148
+ //last cron was more then an hour
149
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
150
+ ->setHowto('Last customer sync is older than one hour.')
151
+ ->setHowto($howToSetupCron);
152
+ }
153
+ }
154
+
155
+ $resultContent->setMessage($message);
156
+ return $resultContent;
157
+ }
158
+
159
+ /**
160
+ * Address Book Mapping.
161
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
162
+ */
163
+ public function addressBookMapped()
164
+ {
165
+ $resultContent = Mage::getModel('email_connector/adminhtml_dashboard_content');
166
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
167
+ ->setTitle('Configuration For Address Book Status : ')
168
+ ->setMessage('Looks Great.');
169
+
170
+ foreach (Mage::app()->getWebsites() as $website ) {
171
+
172
+ $websiteName = $website->getName();
173
+ $link = Mage::helper('adminhtml')->getUrl('*/system_config/edit/section/connector_sync_settings/website/' . $website->getCode());
174
+
175
+ $customerMapped = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMERS_ADDRESS_BOOK_ID))? true :
176
+ 'Not mapped !';
177
+ $subscriberMapped = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SUBSCRIBERS_ADDRESS_BOOK_ID))? true :
178
+ 'Not mapped !';
179
+ $guestMapped = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_GUEST_ADDRESS_BOOK_ID))? true :
180
+ 'Not mapped !';
181
+
182
+ if ($customerMapped !== true || $subscriberMapped !== true || $guestMapped !== true) {
183
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
184
+ ->setMessage('')
185
+ ->setTable(array(
186
+ 'Website' => $websiteName,
187
+ 'Customers' => ($customerMapped !== true)? $customerMapped . '<a href="' . $link . '"> Click to map</a>' : 'Mapped.',
188
+ 'Subscribers' => ($subscriberMapped !== true)? $subscriberMapped . '<a href="' . $link . '"> Click to map</a>' : 'Mapped.',
189
+ 'Guests' => ($guestMapped !== true)? $guestMapped . '<a href="' . $link . '"> Click to map</a>' : 'Mapped.'
190
+ ));
191
+ }
192
+ }
193
+
194
+ return $resultContent;
195
+ }
196
+
197
+ /**
198
+ * ROI Tracking.
199
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
200
+ */
201
+ public function roiTrackingEnabled()
202
+ {
203
+ $resultContent = Mage::getModel('email_connector/adminhtml_dashboard_content');
204
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
205
+ ->setTitle('ROI Tracking Status : ')
206
+ ->setMessage('Looks Great.');
207
+
208
+ foreach ( Mage::app()->getWebsites() as $website ) {
209
+ $websiteName = $website->getName();
210
+
211
+ $roiConfig = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_ROI_TRACKING_ENABLED))? true : 'Not Mapped! ';
212
+ $pageTracking = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_PAGE_TRACKING_ENABLED))? true : 'Not Mapped! ';
213
+ //not mapped show options
214
+ if ($roiConfig !== true || $pageTracking !== true) {
215
+
216
+ //links to enable and get redirected back
217
+ $roiUrl = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_ROI_TRACKING_ENABLED', 'website' => $website->getId()));
218
+ $pageUrl = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_PAGE_TRACKING_ENABLED', 'website' => $website->getId()));
219
+
220
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
221
+ ->setMessage('')
222
+ ->setTable(array(
223
+ 'Website' => $websiteName,
224
+ 'ROI' => ($roiConfig !== true)? $roiConfig . '<a href="' . $roiUrl . '"> Click to enable</a>' : 'Mapped.',
225
+ 'PAGE' => ($pageTracking !== true)? $pageTracking . '<a href="' . $pageUrl . '"> Click to enable</a>' : 'Mapped.'
226
+ ));
227
+ }
228
+ }
229
+
230
+ return $resultContent;
231
+ }
232
+
233
+ /**
234
+ * Transactional Data.
235
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
236
+ */
237
+ public function transactionalEmails()
238
+ {
239
+ $resultContent = Mage::getModel('email_connector/adminhtml_dashboard_content');
240
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
241
+ ->setTitle('Transactional Emails Status : ')
242
+ ->setMessage('Enabled.')
243
+ ;
244
+
245
+ foreach ( Mage::app()->getWebsites() as $website ) {
246
+ $websiteName = $website->getName();
247
+ $transactional = ($website->getConfig(Dotdigitalgroup_Email_Helper_Transactional::XML_PATH_TRANSACTIONAL_API_ENABLED))? true :
248
+ 'Disabled ';
249
+ if ($transactional !== true){
250
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_TRANSACTIONAL_API_ENABLED', 'website' => $website->getId()));
251
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
252
+ ->setMessage('')
253
+ ->setTable(array(
254
+ 'Website' => $websiteName,
255
+ 'Status' => ($transactional)? $transactional . '<a href="' . $url . '">Click to enable</a>' : 'Enabled.'
256
+ ));
257
+ }
258
+ }
259
+
260
+ return $resultContent;
261
+ }
262
+
263
+ /**
264
+ * File Permissions.
265
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
266
+ */
267
+ public function filePermissionSetttings()
268
+ {
269
+ $resultContent = Mage::getModel('email_connector/adminhtml_dashboard_content');
270
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
271
+ ->setTitle('Files/Folders Permission Settings : ')
272
+ ->setMessage('Looks Great.');
273
+
274
+ /**
275
+ * Arhive and email export directories.
276
+ */
277
+ $emailDir = Mage::getBaseDir('var') . DIRECTORY_SEPARATOR . 'export' . DIRECTORY_SEPARATOR . 'email';
278
+ $archiveDir = Mage::getBaseDir('var') . DIRECTORY_SEPARATOR . 'export' . DIRECTORY_SEPARATOR . 'email' . DIRECTORY_SEPARATOR . 'archive';
279
+
280
+ $checkEmail = Mage::helper('connector/file')->checkPathPermission($emailDir);
281
+ $checkArchive = Mage::helper('connector/file')->checkPathPermission($archiveDir);
282
+ if($checkEmail != Dotdigitalgroup_Email_Helper_File::FILE_FULL_ACCESS_PERMISSION || $checkArchive != Dotdigitalgroup_Email_Helper_File::FILE_FULL_ACCESS_PERMISSION) {
283
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
284
+ ->setMessage('Wrong Permission For Directory : ');
285
+
286
+ //list of directory permission checked
287
+ if ($checkEmail != Dotdigitalgroup_Email_Helper_File::FILE_FULL_ACCESS_PERMISSION)
288
+ $resultContent->setHowto( $emailDir . ' is set to : ' . $checkEmail);
289
+ if ($checkArchive != Dotdigitalgroup_Email_Helper_File::FILE_FULL_ACCESS_PERMISSION)
290
+ $resultContent->setHowto( $archiveDir . ' is set to : ' . $checkArchive);
291
+ }
292
+
293
+ return $resultContent;
294
+ }
295
+
296
+ /**
297
+ * Check for missing files.
298
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
299
+ */
300
+ public function missingFiles()
301
+ {
302
+ $resultContent = Mage::getModel('email_connector/adminhtml_dashboard_content');
303
+
304
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
305
+ ->setTitle('Missing Files : ')
306
+ ->setMessage('Looks Great.');
307
+
308
+ $filePath = Mage::getModuleDir('etc', Dotdigitalgroup_Email_Helper_Config::MODULE_NAME).DS.'files.yaml';
309
+ $config = Zend_Config_Yaml::decode(file_get_contents($filePath));
310
+
311
+
312
+ /**
313
+ * Code dirs.
314
+ */
315
+ $etcDir = Mage::getModuleDir('etc', Dotdigitalgroup_Email_Helper_Config::MODULE_NAME);
316
+ $controllerDir = Mage::getModuleDir('controllers', Dotdigitalgroup_Email_Helper_Config::MODULE_NAME);
317
+ $sqlDir = Mage::getModuleDir('sql', Dotdigitalgroup_Email_Helper_Config::MODULE_NAME);
318
+ $localeDir = Mage::getBaseDir('locale');
319
+ $rootDir = Mage::getModuleDir('', Dotdigitalgroup_Email_Helper_Config::MODULE_NAME);
320
+ $blockDir = $rootDir .DS. 'Block';
321
+ $helperDir = $rootDir .DS. 'Helper';
322
+ $modelDir = $rootDir .DS. 'Model';
323
+
324
+ /**
325
+ * Design dir.
326
+ */
327
+ $designDir = Mage::getBaseDir('design');
328
+
329
+ /**
330
+ * Skin dir.
331
+ */
332
+ $skinDir = Mage::getBaseDir('skin');
333
+
334
+ $filesToCheck = array($config['etc'], $config['controllers'], $config['sql'], $config['locale'], $config['block'], $config['helper'], $config['model'], $config['design'], $config['skin']);
335
+ $pathToCheck = array($etcDir, $controllerDir, $sqlDir, $localeDir, $blockDir, $helperDir, $modelDir, $designDir, $skinDir);
336
+ foreach ( $filesToCheck as $subdir ) {
337
+ foreach ( $subdir as $path ) {
338
+ $file = $pathToCheck[0] . DS . str_replace( '#', DS, $path );
339
+
340
+ if ( !file_exists( $file ) ) {
341
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED )
342
+ ->setMessage('')
343
+ ->setHowto('File not found : ' . $file );
344
+ }
345
+ }
346
+ array_shift($pathToCheck);
347
+ }
348
+
349
+ return $resultContent;
350
+ }
351
+
352
+
353
+
354
+ /**
355
+ * Contact Sync Status.
356
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
357
+ */
358
+ public function contactSyncEnabled()
359
+ {
360
+ $resultContent = Mage::getModel('email_connector/adminhtml_dashboard_content');
361
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
362
+ ->setTitle('Contacts Sync Status : ')
363
+ ->setMessage('Looks Great.');
364
+
365
+ foreach ( Mage::app()->getWebsites() as $website ) {
366
+ $websiteName = $website->getName();
367
+ $contact = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_CONTACT_ENABLED))? true :
368
+ 'Disabled ';
369
+ //disabled show data table
370
+ if ($contact !== true){
371
+ //redirection url to enable website config
372
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_SYNC_CONTACT_ENABLED', 'website' => $website->getId()));
373
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
374
+ ->setMessage('')
375
+ ->setTable(array(
376
+ 'Website' => $websiteName,
377
+ 'Status' => ($contact)? $contact : 'Enabled.',
378
+ 'Fast Fix' => '<a href="' . $url . '">Click to enable</a>'
379
+ ));
380
+ }
381
+ }
382
+
383
+ return $resultContent;
384
+ }
385
+
386
+ /**
387
+ * Check if contact is syncing by counting the number of contacts imported.
388
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
389
+ */
390
+ public function contactSyncing()
391
+ {
392
+ $resultContent = Mage::getModel('email_connector/adminhtml_dashboard_content');
393
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
394
+ ->setTitle('Contacts Sync : ')
395
+ ->setMessage('Looks Great.');
396
+
397
+ //duplicate email customers
398
+ $customers = Mage::helper('connector')->getCustomersWithDuplicateEmails();
399
+ $duplicates = $customers->count();
400
+ if ($duplicates) {
401
+
402
+ $customerEmails = implode(', ', $customers->getColumnValues('email'));
403
+ $resultContent->setHowto('Found Duplicate Customers Emails :')
404
+ ->setHowto($customerEmails);
405
+ }
406
+
407
+ foreach ( Mage::app()->getWebsites() as $website ) {
408
+ $websiteName = $website->getName();
409
+ $websiteId = $website->getId();
410
+ //number of customers for website
411
+ $cusotmerForWebsite = Mage::getModel('customer/customer')->getCollection()
412
+ ->addAttributeToFilter('website_id', $websiteId)
413
+ ->getSize();
414
+ //skip if no customers
415
+ if (! $cusotmerForWebsite)
416
+ continue;
417
+ //number of contacts imported
418
+ $contacts = Mage::getModel('email_connector/contact')->getCollection()
419
+ ->addFieldToFilter('email_imported', 1)
420
+ ->addFieldToFilter('customer_id', array('neq' => '0'))
421
+ ->addFieldToFilter('website_id', $websiteId)
422
+ ->getSize();
423
+ $tableData = array(
424
+ 'Website' => $websiteName,
425
+ 'Status' => 'Syncing',
426
+ 'Total Customers' => $cusotmerForWebsite,
427
+ 'Imported Contacts' => $contacts
428
+ );
429
+ //missing contacts
430
+ $missing = $cusotmerForWebsite - $contacts;
431
+
432
+ //no contacts
433
+ if (! $contacts) {
434
+
435
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
436
+ ->setTitle('Contacts Sync (ignore if you have reset contacts for reimport) : ')
437
+ ->setMessage('');
438
+ $tableData['Status'] = 'No Imported Contacts Found';
439
+ unset($tableData['Imported Contacts']);
440
+ } elseif ($missing) {
441
+
442
+ $tableData['Status'] = 'Sync Not Complete';
443
+ $tableData['Missing'] = $missing;
444
+ }
445
+
446
+ $resultContent->setTable($tableData);
447
+ }
448
+
449
+ return $resultContent;
450
+ }
451
+
452
+ /**
453
+ * Check for subscribers sync status.
454
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
455
+ */
456
+ public function subscriberSyncEnabled()
457
+ {
458
+ $resultContent = Mage::getModel('email_connector/adminhtml_dashboard_content');
459
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
460
+ ->setTitle('Subscribers Sync Status : ')
461
+ ->setMessage('Looks Great.');
462
+
463
+ foreach ( Mage::app()->getWebsites() as $website ) {
464
+ $websiteName = $website->getName();
465
+ $contact = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_SUBSCRIBER_ENABLED))? true :
466
+ 'Disabled ';
467
+ //disabled show data table
468
+ if ($contact !== true){
469
+ //redirection url to enable website config
470
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_SYNC_SUBSCRIBER_ENABLED', 'website' => $website->getId()));
471
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
472
+ ->setMessage('')
473
+ ->setTable(array(
474
+ 'Website' => $websiteName,
475
+ 'Status' => ($contact)? $contact : 'Enabled.',
476
+ 'Fast Fix' => '<a href="' . $url . '">Click to enable</a>'
477
+ ));
478
+ }
479
+ }
480
+
481
+ return $resultContent;
482
+
483
+ }
484
+
485
+ /**
486
+ * Subscribers syncing status.
487
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
488
+ */
489
+ public function subscribersSyncing()
490
+ {
491
+ $resultContent = Mage::getModel('email_connector/adminhtml_dashboard_content');
492
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
493
+ ->setTitle('Subscribers Sync : ')
494
+ ->setMessage('Looks Great.');
495
+
496
+ foreach ( Mage::app()->getWebsites() as $website ) {
497
+ $websiteName = $website->getName();
498
+ $storeIds = $website->getStoreIds();
499
+ //number of customers for website
500
+ $subscriberForWebsite = Mage::getModel('newsletter/subscriber')->getCollection()
501
+ ->addFieldToFilter('store_id', array('in' => $storeIds))
502
+ ->getSize()
503
+ ;
504
+
505
+ //skip if no subscriber
506
+ if (! $subscriberForWebsite)
507
+ continue;
508
+ //number of contacts imported as subscribers
509
+ $contacts = Mage::getModel('email_connector/contact')->getCollection()
510
+ ->addFieldToFilter('subscriber_imported', 1)
511
+ ->addFieldToFilter('is_subscriber', 1)
512
+ ->addFieldToFilter('store_id', array('in' => $storeIds))
513
+ ->getSize();
514
+ //no contacts
515
+ if (! $contacts) {
516
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
517
+ ->setTitle('Subscriber Sync (ignore if you have reset subscribers for reimport) : ')
518
+ ->setMessage('')
519
+ ->setTable(array(
520
+ 'Website' => $websiteName,
521
+ 'Status' => 'No Imported Subscribers Found.'
522
+ ));
523
+ }
524
+ }
525
+
526
+ return $resultContent;
527
+ }
528
+
529
+ /**
530
+ * Abandoned carts status.
531
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
532
+ */
533
+ public function abandonedCartsEnabled()
534
+ {
535
+ $resultContent = Mage::getModel('email_connector/adminhtml_dashboard_content');
536
+
537
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
538
+ ->setTitle('Abandoned Carts Status : ')
539
+ ->setMessage('Looks Great.');
540
+
541
+ foreach ( Mage::app()->getWebsites() as $website ) {
542
+ $websiteName = $website->getName();
543
+ $abandonedCusomer_1 = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CARTS_ENABLED_1))? true :
544
+ 'Disabled ';
545
+ $abandonedCusomer_2 = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CARTS_ENABLED_2))? true :
546
+ 'Disabled ';
547
+ $abandonedCusomer_3 = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CARTS_ENABLED_3))? true :
548
+ 'Disabled ';
549
+ $abandonedGuest_1 = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_GUEST_ABANDONED_CARTS_ENABLED_1))? true :
550
+ 'Disabled ';
551
+ $abandonedGuest_2 = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_GUEST_ABANDONED_CARTS_ENABLED_2))? true :
552
+ 'Disabled ';
553
+ $abandonedGuest_3 = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_GUEST_ABANDONED_CARTS_ENABLED_3))? true :
554
+ 'Disabled ';
555
+
556
+ if ($abandonedCusomer_1 !== true || $abandonedCusomer_2 !== true || $abandonedCusomer_3 !== true || $abandonedGuest_1 !== true || $abandonedGuest_2 !== true || $abandonedGuest_3 !== true){
557
+ //customer abandoned links to enable
558
+ $customer1 = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CARTS_ENABLED_1', 'website' => $website->getId()));
559
+ $customer2 = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CARTS_ENABLED_2', 'website' => $website->getId()));
560
+ $customer3 = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CARTS_ENABLED_3', 'website' => $website->getId()));
561
+ //guests abandoned links to enable
562
+ $guest1 = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_GUEST_ABANDONED_CARTS_ENABLED_1', 'website' => $website->getId()));
563
+ $guest2 = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_GUEST_ABANDONED_CARTS_ENABLED_2', 'website' => $website->getId()));
564
+ $guest3 = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_GUEST_ABANDONED_CARTS_ENABLED_3', 'website' => $website->getId()));
565
+
566
+
567
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
568
+ ->setMessage('Don\'t forget to map')
569
+ ->setTable(array(
570
+ 'Website' => $websiteName,
571
+ 'Customer Abandoned 1' => ($abandonedCusomer_1 !== true)? $abandonedCusomer_1 . '<a href="' . $customer1 . '">Click to enable</a>' : 'Enabled',
572
+ 'Customer Abandoned 2' => ($abandonedCusomer_2 !== true)? $abandonedCusomer_2 . '<a href="' . $customer2 . '">Click to enable</a>' : 'Enabled',
573
+ 'Customer Abandoned 3' => ($abandonedCusomer_3 !== true)? $abandonedCusomer_3 . '<a href="' . $customer3 . '">Click to enable</a>' : 'Enabled',
574
+ 'Guest Abandoned 1' => ($abandonedGuest_1 !== true)? $abandonedGuest_1 . '<a href="' . $guest1 . '">Click to enable</a>' : 'Enabled',
575
+ 'Guest Abandoned 2' => ($abandonedGuest_2 !== true)? $abandonedGuest_2 . '<a href="' . $guest2 . '">Click to enable</a>' : 'Enabled',
576
+ 'Guest Abandoned 3' => ($abandonedGuest_3 !== true)? $abandonedGuest_3 . '<a href="' . $guest3 . '">Click to enable</a>' : 'Enabled',
577
+ ));
578
+ }
579
+ }
580
+
581
+ return $resultContent;
582
+ }
583
+
584
+ /**
585
+ * Crazy mapping checking.
586
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
587
+ */
588
+ public function dataFieldMapped()
589
+ {
590
+ $resultContent = Mage::getModel('email_connector/adminhtml_dashboard_content');
591
+
592
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
593
+ ->setTitle('Default Datafields Mapped Status : ')
594
+ ->setMessage('All Datafields Are Mapped.');
595
+
596
+ foreach ( Mage::app()->getWebsites() as $website ) {
597
+ $passed = true;
598
+ $mapped = 0;
599
+ $nm = 'Not Mapped';
600
+ $tableData = array();
601
+ //website name for table data
602
+ $websiteName = $website->getName();
603
+ $tableData['Website'] = $websiteName;
604
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_ID)) {
605
+ $passed = false;
606
+ $mapped += 1;
607
+ }
608
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_FIRSTNAME)) {
609
+ $passed = false;
610
+ $mapped += 1;
611
+ }
612
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_LASTNAME)) {
613
+ $passed = false;
614
+ $mapped += 1;
615
+ }
616
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_DOB)) {
617
+ $passed = false;
618
+ $mapped += 1;
619
+ }
620
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_GENDER)) {
621
+ $passed = false;
622
+ $mapped += 1;
623
+ }
624
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_WEBSITE_NAME)) {
625
+ $passed = false;
626
+ $mapped += 1;
627
+ }
628
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_STORE_NAME)) {
629
+ $passed = false;
630
+ $mapped += 1;
631
+ }
632
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_CREATED_AT)) {
633
+ $passed = false;
634
+ $mapped += 1;
635
+ }
636
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_LAST_LOGGED_DATE)) {
637
+ $passed = false;
638
+ $mapped += 1;
639
+ }
640
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_CUSTOMER_GROUP)) {
641
+ $passed = false;
642
+ $mapped += 1;
643
+ }
644
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_REVIEW_COUNT)) {
645
+ $passed = false;
646
+ $mapped += 1;
647
+ }
648
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_LAST_REVIEW_DATE)) {
649
+ $passed = false;
650
+ $mapped += 1;
651
+ }
652
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_BILLING_ADDRESS_1)) {
653
+ $passed = false;
654
+ $mapped += 1;
655
+ }
656
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_BILLING_ADDRESS_2)) {
657
+ $passed = false;
658
+ $mapped += 1;
659
+ }
660
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_BILLING_CITY)) {
661
+ $passed = false;
662
+ $mapped += 1;
663
+ }
664
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_BILLING_STATE)) {
665
+ $passed = false;
666
+ $mapped += 1;
667
+ }
668
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_BILLING_COUNTRY)) {
669
+ $passed = false;
670
+ $mapped += 1;
671
+ }
672
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_BILLING_POSTCODE)) {
673
+ $passed = false;
674
+ $mapped += 1;
675
+ }
676
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_BILLING_TELEPHONE)) {
677
+ $passed = false;
678
+ $mapped += 1;
679
+ }
680
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_ADDRESS_1)) {
681
+ $passed = false;
682
+ $mapped += 1;
683
+ }
684
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_ADDRESS_2)) {
685
+ $passed = false;
686
+ $mapped += 1;
687
+ }
688
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_CITY)) {
689
+ $passed = false;
690
+ $mapped += 1;
691
+ }
692
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_STATE)) {
693
+ $passed = false;
694
+ $mapped += 1;
695
+ }
696
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_COUNTRY)) {
697
+ $passed = false;
698
+ $mapped += 1;
699
+ }
700
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_POSTCODE)) {
701
+ $passed = false;
702
+ $mapped += 1;
703
+ }
704
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_TELEPHONE)) {
705
+ $passed = false;
706
+ $mapped += 1;
707
+ }
708
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_TOTAL_NUMBER_ORDER)) {
709
+ $passed = false;
710
+ $mapped += 1;
711
+ }
712
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_AOV)) {
713
+ $passed = false;
714
+ $mapped += 1;
715
+ }
716
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_TOTAL_SPEND)) {
717
+ $passed = false;
718
+ $mapped += 1;
719
+ }
720
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_LAST_ORDER_DATE)) {
721
+ $passed = false;
722
+ $mapped += 1;
723
+ }
724
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_LAST_ORDER_ID)) {
725
+ $passed = false;
726
+ $mapped += 1;
727
+ }
728
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_CUSTOMER_TOTALREFUND)) {
729
+ $passed = false;
730
+ $mapped += 1;
731
+ }
732
+ $tableData['Mapped Percentage'] = number_format((1 - $mapped / 32) * 100, 2) . ' %';
733
+ //mapping not complete.
734
+ if (! $passed ){
735
+ $url = Mage::helper('adminhtml')->getUrl('*/system_config/edit/section/connector_data_mapping/website/' . $website->getCode());
736
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
737
+ ->setMessage('Click <a href="' . $url . '">here</a> to change mapping configuration.')
738
+ ;
739
+ }
740
+ $resultContent->setTable($tableData);
741
+ }
742
+
743
+ return $resultContent;
744
+
745
+ }
746
+
747
+
748
+ /**
749
+ * Validate API Credentials.
750
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
751
+ */
752
+ public function validApiCredentials()
753
+ {
754
+ $resultContent = Mage::getModel('email_connector/adminhtml_dashboard_content');
755
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
756
+ ->setTitle('API Credentials Status : ')
757
+ ->setMessage('Valid.');
758
+ $helper = Mage::helper('connector');
759
+ foreach ( Mage::app()->getWebsites() as $website ) {
760
+ $websiteName = $website->getName();
761
+ $websiteId = $website->getId();
762
+
763
+ $apiUsername = $helper->getApiUsername($websiteId);
764
+ $apiPassword = $helper->getApiPassword($websiteId);
765
+
766
+ $api = Mage::getModel('email_connector/apiconnector_test')->ajaxvalidate($apiUsername, $apiPassword);
767
+
768
+ if ($api != 'Credentials Valid.'){
769
+ $url = Mage::helper('adminhtml')->getUrl('*/system_config/edit/section/connector_api_credentials/website/' . $website->getCode());
770
+
771
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
772
+ ->setMessage('')
773
+ ->setTable(array(
774
+ 'Website' => $websiteName,
775
+ 'Status' => $api,
776
+ 'Fast Fix' => 'Click <a href="' . $url . '">here</a> to enter new api credentials.'
777
+ ));
778
+ }
779
+ }
780
+
781
+ return $resultContent;
782
+
783
+
784
+ }
785
+
786
+ /**
787
+ * Order sync enabled.
788
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
789
+ */
790
+ public function orderEnabled()
791
+ {
792
+ $resultContent = Mage::getModel('email_connector/adminhtml_dashboard_content');
793
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
794
+ ->setTitle('Order Sync : ')
795
+ ->setMessage('Enabled.');
796
+
797
+ foreach ( Mage::app()->getWebsites() as $website ) {
798
+ $websiteName = $website->getName();
799
+ $order = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_ORDER_ENABLED))? true :
800
+ 'Disabled';
801
+
802
+ if ($order !== true){
803
+
804
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_SYNC_ORDER_ENABLED', 'website' => $website->getId()));
805
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
806
+ ->setMessage('')
807
+ ->setTable(array(
808
+ 'Website' => $websiteName,
809
+ 'Status' => $order,
810
+ 'Fast Fix' => 'Click <a href="' . $url . '">here </a>to enable.'
811
+ ));
812
+ }
813
+ }
814
+
815
+ return $resultContent;
816
+ }
817
+
818
+ /**
819
+ * Check if any orders are imported.
820
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
821
+ */
822
+ public function orderSyncing()
823
+ {
824
+ $resultContent = Mage::getModel('email_connector/adminhtml_dashboard_content');
825
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
826
+ ->setTitle('Order Syncing : ')
827
+ ->setMessage('Looks Great.');
828
+
829
+ foreach ( Mage::app()->getWebsites() as $website ) {
830
+ $websiteName = $website->getName();
831
+ $storeIds = $website->getStoreIds();
832
+
833
+ //numbser of orders marked as imported
834
+ $numOrders = Mage::getModel('email_connector/order')->getCollection()
835
+ ->addFieldToFilter('email_imported', 1)
836
+ ->addFieldToFilter('store_id', array('in', $storeIds))->getSize();
837
+
838
+ if (! $numOrders) {
839
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
840
+ ->setTitle('Order Syncing (ignore if you have reset orders for reimport) :')
841
+ ->setMessage('')
842
+ ->setTable(array(
843
+ 'Website' => $websiteName,
844
+ 'Status' => 'No Imported Orders Found'
845
+ ));
846
+ }
847
+ }
848
+
849
+ return $resultContent;
850
+
851
+ }
852
+
853
+ /**
854
+ *
855
+ */
856
+ public function orderDelete()
857
+ {
858
+ $resultContent = Mage::getModel('email_connector/adminhtml_dashboard_content');
859
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
860
+ ->setTitle('Order Expiry : ')
861
+ ->setMessage('Looks Great. ');
862
+
863
+ foreach ( Mage::app()->getWebsites() as $website ) {
864
+ $websiteName = $website->getName();
865
+ $delete = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_ORDER_DELETE))? true :
866
+ 'Do Not Delete';
867
+
868
+ if ($delete !== true){
869
+
870
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_SYNC_ORDER_DELETE', 'website' => $website->getId(), 'value' => '180'));
871
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
872
+ ->setMessage('')
873
+ ->setTable(array(
874
+ 'Website' => $websiteName,
875
+ 'Status' => $delete,
876
+ 'Fast Fix' => 'Click <a href="' . $url . '">here </a>to configure order delete.'
877
+ ));
878
+ }else
879
+ $resultContent->setMessage($resultContent->getMessage() . $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_ORDER_DELETE) . ' Days Set.');
880
+ }
881
+
882
+ return $resultContent;
883
+ }
884
+
885
+ /**
886
+ * Get the last date for abandaned carts.
887
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
888
+ */
889
+ public function lastAbandonedCartSentDay()
890
+ {
891
+ $resultContent = Mage::getModel('email_connector/adminhtml_dashboard_content');
892
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
893
+ ->setTitle('Last Abandoned Summary : ');
894
+
895
+ foreach ( Mage::app()->getWebsites() as $website ) {
896
+
897
+ $websiteName = $website->getName();
898
+ $client = Mage::helper('connector')->getWebsiteApiClient($website);
899
+
900
+ //customer carts
901
+ $customerCampaign1 = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CAMPAIGN_1);
902
+ $customerCampaign2 = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CAMPAIGN_2);
903
+ $customerCampaign3 = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CAMPAIGN_3);
904
+
905
+ //guests carts
906
+ $guestCampaign1 = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_GUEST_ABANDONED_CAMPAIGN_1);
907
+ $guestCampaign2 = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_GUEST_ABANDONED_CAMPAIGN_2);
908
+ $guestCampaign3 = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_GUEST_ABANDONED_CAMPAIGN_3);
909
+
910
+
911
+ //date customer carts
912
+
913
+ $cusDateSent1 = ($customerCampaign1)? $client->getCampaignSummary($customerCampaign1) : '';
914
+ $cusDateSent2 = ($customerCampaign2)? $client->getCampaignSummary($customerCampaign2) : '';
915
+ $cusDateSent3 = ($customerCampaign3)? $client->getCampaignSummary($customerCampaign3) : '';
916
+
917
+ //date guest carts
918
+ $resGuest1 = ($guestCampaign1)? $client->getCampaignSummary($guestCampaign1) : '';
919
+ $resGuest2 = ($guestCampaign2)? $client->getCampaignSummary($guestCampaign2) : '';
920
+ $resGuest3 = ($guestCampaign3)? $client->getCampaignSummary($guestCampaign3) : '';
921
+
922
+ /**
923
+ * Customers.
924
+ */
925
+ $customerCampaign1 = (isset($cusDateSent1->dateSent)? $cusDateSent1->dateSent : 'Not Sent/Selected');
926
+ $customerCampaign2 = (isset($cusDateSent2->dateSent)? $cusDateSent2->dateSent : 'Not Sent/Selected');
927
+ $customerCampaign3 = (isset($cusDateSent3->dateSent)? $cusDateSent3->dateSent : 'Not Sent/Selected');
928
+
929
+ /**
930
+ * Guests.
931
+ */
932
+ $guestCampaign1 = (isset($resGuest1->dateSent)? $resGuest1->dateSent : 'Not Sent/Selected');
933
+ $guestCampaign2 = (isset($resGuest2->dateSent)? $resGuest2->dateSent : 'Not Sent/Selected');
934
+ $guestCampaign3 = (isset($resGuest3->dateSent)? $resGuest3->dateSent : 'Not Sent/Selected');
935
+
936
+
937
+ $resultContent->setTable(array(
938
+ 'Website' => $websiteName,
939
+ 'Customer Campaign 1' => $customerCampaign1,
940
+ 'Customer Campaign 2' => $customerCampaign2,
941
+ 'Customer Campaign 3' => $customerCampaign3,
942
+ 'Guest Campaign 1' => $guestCampaign1,
943
+ 'Guest Campaign 2' => $guestCampaign2,
944
+ 'Guest Campaign 3' => $guestCampaign3
945
+ ));
946
+ }
947
+
948
+ return $resultContent;
949
+ }
950
+
951
+ /**
952
+ * Conflict checker.
953
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
954
+ */
955
+ public function conflictCheck()
956
+ {
957
+ /**
958
+ * Check the API accounts for different websites and posible mapping conflicts.
959
+ */
960
+ $resultContent = Mage::getModel('email_connector/adminhtml_dashboard_content');
961
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
962
+ ->setTitle('Conflict Status : ')
963
+ ->setMessage('Looks Great.')
964
+ ;
965
+
966
+ $lastApi = false;
967
+ foreach ( Mage::app()->getWebsites() as $website )
968
+ {
969
+ $apiUsername = $website->getConfig( Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_USERNAME );
970
+ if ($lastApi === false)
971
+ $lastApi = $apiUsername;
972
+ //check difference for the previous api usename
973
+ if ($lastApi != $apiUsername) {
974
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
975
+ ->setMessage('Possible configuration conflict.')
976
+ ->setTable( array(
977
+ 'Website' => $website->getName(),
978
+ 'Multiple API Usernames' => $apiUsername
979
+ ));
980
+ $lastApi = $apiUsername;
981
+ }
982
+ }
983
+
984
+ return $resultContent;
985
+ }
986
+
987
+ /**
988
+ * System information about the version used and the memory limits.
989
+ *
990
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
991
+ */
992
+ public function systemInformation()
993
+ {
994
+ $resultContent = Mage::getModel('email_connector/adminhtml_dashboard_content');
995
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED);
996
+
997
+ //check for php version
998
+ $resultContent->setHowTo('PHP version : V' . PHP_VERSION)
999
+ ->setHowto('PHP Memory : ' . ini_get('memory_limit'))
1000
+ ->setHowto('PHP Max Execution Time : ' . ini_get('max_execution_time') . ' sec')
1001
+ ->setHowto('Magento version : ' . Mage::getEdition() . ' V' . Mage::getVersion())
1002
+ ->setHowto('Connector version : V' . Mage::helper('connector')->getConnectorVersion());
1003
+
1004
+
1005
+
1006
+ return $resultContent;
1007
+ }
1008
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Order.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Order extends Mage_Adminhtml_Block_Widget_Grid_Container
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+
9
+ $this->_blockGroup = 'email_connector';
10
+ $this->_controller = 'adminhtml_order';
11
+ $this->_headerText = Mage::helper('connector')->__('Email Order(s)');
12
+
13
+ $this->_removeButton('add');
14
+ }
15
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Order/Grid.php ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Order_Grid extends Mage_Adminhtml_Block_Widget_Grid
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+
9
+ // Set some defaults for our grid
10
+ $this->setDefaultSort('email_order_id');
11
+ $this->setId('email_order_id');
12
+ $this->setDefaultDir('asc');
13
+ }
14
+
15
+ /**
16
+ * Collection class;
17
+ * @return string
18
+ */
19
+ protected function _getCollectionClass()
20
+ {
21
+ // This is the model we are using for the grid
22
+ return 'email_connector/order_collection';
23
+ }
24
+
25
+ /**
26
+ * Prepare the grid collection.
27
+ * @return Mage_Adminhtml_Block_Widget_Grid
28
+ */
29
+ protected function _prepareCollection()
30
+ {
31
+ // Get and set our collection for the grid
32
+ $collection = Mage::getResourceModel($this->_getCollectionClass());
33
+ $this->setCollection($collection);
34
+ return parent::_prepareCollection();
35
+ }
36
+
37
+ /**
38
+ * Prepare the grid collumns.
39
+ * @return $this
40
+ * @throws Exception
41
+ */
42
+ protected function _prepareColumns()
43
+ {
44
+ $this->addColumn('order_id', array(
45
+ 'header' => Mage::helper('connector')->__('Order ID'),
46
+ 'align' => 'left',
47
+ 'width' => '50px',
48
+ 'index' => 'order_id',
49
+ 'type' => 'number',
50
+ 'escape' => true
51
+ ))->addColumn('order_status', array(
52
+ 'header' => Mage::helper('connector')->__('Order Status'),
53
+ 'align' => 'right',
54
+ 'width' => '50px',
55
+ 'index' => 'order_status',
56
+ 'type' => 'options',
57
+ 'escape' => true,
58
+ 'options' => Mage::getSingleton('sales/order_config')->getStatuses(),
59
+ ))->addColumn('store_id', array(
60
+ 'header' => Mage::helper('connector')->__('Store ID'),
61
+ 'width' => '50px',
62
+ 'index' => 'store_id',
63
+ 'type' => 'number',
64
+ 'escape' => true,
65
+ ))->addColumn('email_imported', array(
66
+ 'header' => Mage::helper('connector')->__('Email Imported'),
67
+ 'align' => 'center',
68
+ 'width' => '50px',
69
+ 'index' => 'email_imported',
70
+ 'type' => 'options',
71
+ 'escape' => true,
72
+ 'renderer' => 'email_connector/adminhtml_column_renderer_imported',
73
+ 'options' => Mage::getModel('email_connector/adminhtml_source_contact_imported')->getOptions(),
74
+ 'filter_condition_callback' => array($this, 'filterCallbackContact')
75
+ ))->addColumn('created_at', array(
76
+ 'header' => Mage::helper('connector')->__('Created At'),
77
+ 'width' => '50px',
78
+ 'align' => 'center',
79
+ 'index' => 'created_at',
80
+ 'type' => 'datetime',
81
+ 'escape' => true,
82
+ ))->addColumn('updated_at', array(
83
+ 'header' => Mage::helper('connector')->__('Updated At'),
84
+ 'width' => '50px',
85
+ 'align' => 'center',
86
+ 'index' => 'updated_at',
87
+ 'type' => 'datetime',
88
+ 'escape' => true,
89
+ ));
90
+
91
+ return parent::_prepareColumns();
92
+ }
93
+
94
+ /**
95
+ * Callback action for the imported subscribers/contacts.
96
+ *
97
+ * @param $collection
98
+ * @param $column
99
+ */
100
+ public function filterCallbackContact($collection, $column)
101
+ {
102
+ $field = $column->getFilterIndex() ? $column->getFilterIndex() : $column->getIndex();
103
+ $value = $column->getFilter()->getValue();
104
+ if ($value == 'null') {
105
+ $collection->addFieldToFilter($field, array('null' => true));
106
+ } else {
107
+ $collection->addFieldToFilter($field, array('notnull' => true));
108
+ }
109
+ }
110
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Sales/Order/Creditmemo/View.php ADDED
@@ -0,0 +1,196 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Block_Adminhtml_Sales_Order_Creditmemo_View extends Mage_Adminhtml_Block_Widget_Form_Container
3
+ {
4
+
5
+ public function __construct()
6
+ {
7
+ $this->_objectId = 'creditmemo_id';
8
+ $this->_controller = 'sales_order_creditmemo';
9
+ $this->_mode = 'view';
10
+
11
+ parent::__construct();
12
+
13
+ $this->_removeButton('save');
14
+ $this->_removeButton('reset');
15
+ $this->_removeButton('delete');
16
+
17
+ if ($this->getCreditmemo()->canCancel()) {
18
+ $this->_addButton('cancel', array(
19
+ 'label' => Mage::helper('sales')->__('Cancel'),
20
+ 'class' => 'delete',
21
+ 'onclick' => 'setLocation(\''.$this->getCancelUrl().'\')'
22
+ )
23
+ );
24
+ }
25
+
26
+ if ($this->_isAllowedAction('emails')) {
27
+ $this->addButton('send_notification', array(
28
+ 'label' => Mage::helper('sales')->__('Send Email'),
29
+ 'onclick' => 'confirmSetLocation(\''
30
+ . Mage::helper('sales')->__('Are you sure you want to send Creditmemo email to customer?')
31
+ . '\', \'' . $this->getEmailUrl() . '\')'
32
+ ));
33
+ }
34
+
35
+ if ($this->getCreditmemo()->canRefund()) {
36
+ $this->_addButton('refund', array(
37
+ 'label' => Mage::helper('sales')->__('Refund'),
38
+ 'class' => 'save',
39
+ 'onclick' => 'setLocation(\''.$this->getRefundUrl().'\')'
40
+ )
41
+ );
42
+ }
43
+
44
+ if ($this->getCreditmemo()->canVoid()) {
45
+ $this->_addButton('void', array(
46
+ 'label' => Mage::helper('sales')->__('Void'),
47
+ 'class' => 'save',
48
+ 'onclick' => 'setLocation(\''.$this->getVoidUrl().'\')'
49
+ )
50
+ );
51
+ }
52
+
53
+ if ($this->getCreditmemo()->getId()) {
54
+ $this->_addButton('print', array(
55
+ 'label' => Mage::helper('sales')->__('Print'),
56
+ 'class' => 'save',
57
+ 'onclick' => 'setLocation(\''.$this->getPrintUrl().'\')'
58
+ )
59
+ );
60
+ }
61
+ }
62
+
63
+ /**
64
+ * Retrieve creditmemo model instance
65
+ *
66
+ * @return Mage_Sales_Model_Order_Creditmemo
67
+ */
68
+ public function getCreditmemo()
69
+ {
70
+ return Mage::registry('current_creditmemo');
71
+ }
72
+
73
+ /**
74
+ * Retrieve text for header
75
+ *
76
+ * @return string
77
+ */
78
+ public function getHeaderText()
79
+ {
80
+ if ($this->getCreditmemo()->getEmailSent()) {
81
+ $emailSent = Mage::helper('sales')->__('the credit memo email was sent');
82
+ }
83
+ else {
84
+ $emailSent = Mage::helper('sales')->__('the credit memo email is not sent');
85
+ }
86
+ return Mage::helper('sales')->__('Credit Memo #%1$s | %3$s | %2$s (%4$s)', $this->getCreditmemo()->getIncrementId(), $this->formatDate($this->getCreditmemo()->getCreatedAtDate(), 'medium', true), $this->getCreditmemo()->getStateName(), $emailSent);
87
+ }
88
+
89
+ /**
90
+ * Retrieve back url
91
+ *
92
+ * @return string
93
+ */
94
+ public function getBackUrl()
95
+ {
96
+ return $this->getUrl(
97
+ '*/sales_order/view',
98
+ array(
99
+ 'order_id' => $this->getCreditmemo()->getOrderId(),
100
+ 'active_tab'=> 'order_creditmemos'
101
+ ));
102
+ }
103
+
104
+ /**
105
+ * Retrieve capture url
106
+ *
107
+ * @return string
108
+ */
109
+ public function getCaptureUrl()
110
+ {
111
+ return $this->getUrl('*/*/capture', array('creditmemo_id'=>$this->getCreditmemo()->getId()));
112
+ }
113
+
114
+ /**
115
+ * Retrieve void url
116
+ *
117
+ * @return string
118
+ */
119
+ public function getVoidUrl()
120
+ {
121
+ return $this->getUrl('*/*/void', array('creditmemo_id'=>$this->getCreditmemo()->getId()));
122
+ }
123
+
124
+ /**
125
+ * Retrieve cancel url
126
+ *
127
+ * @return string
128
+ */
129
+ public function getCancelUrl()
130
+ {
131
+ return $this->getUrl('*/*/cancel', array('creditmemo_id'=>$this->getCreditmemo()->getId()));
132
+ }
133
+
134
+ /**
135
+ * Retrieve email url
136
+ *
137
+ * @return string
138
+ */
139
+ public function getEmailUrl()
140
+ {
141
+ return $this->getUrl('*/*/email', array(
142
+ 'creditmemo_id' => $this->getCreditmemo()->getId(),
143
+ 'order_id' => $this->getCreditmemo()->getOrderId()
144
+ ));
145
+ }
146
+
147
+ /**
148
+ * Retrieve print url
149
+ *
150
+ * @return string
151
+ */
152
+ public function getPrintUrl()
153
+ {
154
+ return $this->getUrl('*/*/print', array(
155
+ 'creditmemo_id' => $this->getCreditmemo()->getId()
156
+ ));
157
+ }
158
+
159
+ /**
160
+ * Update 'back' button url.
161
+ *
162
+ * @param $flag
163
+ *
164
+ * @return $this|Mage_Adminhtml_Block_Widget_Container
165
+ */
166
+ public function updateBackButtonUrl($flag)
167
+ {
168
+ if ($flag) {
169
+ if ($this->getCreditmemo()->getBackUrl()) {
170
+ return $this->_updateButton(
171
+ 'back',
172
+ 'onclick',
173
+ 'setLocation(\'' . $this->getCreditmemo()->getBackUrl() . '\')'
174
+ );
175
+ }
176
+
177
+ return $this->_updateButton(
178
+ 'back',
179
+ 'onclick',
180
+ 'setLocation(\'' . $this->getUrl('*/sales_creditmemo/') . '\')'
181
+ );
182
+ }
183
+ return $this;
184
+ }
185
+
186
+ /**
187
+ * Check whether action is allowed
188
+ *
189
+ * @param string $action
190
+ * @return bool
191
+ */
192
+ public function _isAllowedAction($action)
193
+ {
194
+ return Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/' . $action);
195
+ }
196
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/.DS_Store ADDED
Binary file
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Deletecontactids.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Advanced_Deletecontactids extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+
6
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
7
+ {
8
+ $this->setElement($element);
9
+ return $this->_getAddRowButtonHtml($this->__("Run Now"));
10
+ }
11
+
12
+ protected function _getAddRowButtonHtml($title)
13
+ {
14
+ $url = Mage::helper('adminhtml')->getUrl("*/connector/deletecontactids");
15
+
16
+ return $this->getLayout()->createBlock('adminhtml/widget_button')
17
+ ->setType('button')
18
+ ->setLabel($this->__($title))
19
+ ->setOnClick("window.location.href='" . $url . "'")
20
+ ->toHtml();
21
+ }
22
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Notification.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Advanced_Notification extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
6
+ {
7
+ $element->setValue(Mage::app()->loadCache(Dotdigitalgroup_Email_Helper_Config::CONNECTOR_FEED_LAST_CHECK_TIME));
8
+ $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
9
+ return Mage::app()->getLocale()->date(intval($element->getValue()))->toString($format);
10
+ }
11
+ }
app/code/{local/Dotdigitalgroup/Email/Block/Debug/Countcontacts.php → community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Reimportorders.php} RENAMED
@@ -1,15 +1,16 @@
1
  <?php
2
-
3
- class Dotdigitalgroup_Email_Block_Debug_Countcontacts extends Mage_Adminhtml_Block_System_Config_Form_Field
4
  {
5
 
6
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) {
 
7
  $this->setElement($element);
8
- return $this->_getAddRowButtonHtml($this->__('Check Customers Now'));
9
  }
10
 
11
- protected function _getAddRowButtonHtml($title) {
12
- $url = Mage::helper('adminhtml')->getUrl("connector/debug/countcontacts");
 
13
 
14
  return $this->getLayout()->createBlock('adminhtml/widget_button')
15
  ->setType('button')
1
  <?php
2
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Advanced_Reimportorders extends Mage_Adminhtml_Block_System_Config_Form_Field
 
3
  {
4
 
5
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
6
+ {
7
  $this->setElement($element);
8
+ return $this->_getAddRowButtonHtml($this->__("Run Now"));
9
  }
10
 
11
+ protected function _getAddRowButtonHtml($title)
12
+ {
13
+ $url = $this->getUrl("*/connector/resetorders");
14
 
15
  return $this->getLayout()->createBlock('adminhtml/widget_button')
16
  ->setType('button')
app/code/{local/Dotdigitalgroup/Email/Block/Debug/Deletecontacts.php → community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Reimportsubscribers.php} RENAMED
@@ -1,15 +1,16 @@
1
  <?php
2
-
3
- class Dotdigitalgroup_Email_Block_Debug_Deletecontacts extends Mage_Adminhtml_Block_System_Config_Form_Field
4
  {
5
 
6
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) {
 
7
  $this->setElement($element);
8
- return $this->_getAddRowButtonHtml($this->__("Delete ID's Now"));
9
  }
10
 
11
- protected function _getAddRowButtonHtml($title) {
12
- $url = Mage::helper('adminhtml')->getUrl("connector/debug/deletecontactsid");
 
13
 
14
  return $this->getLayout()->createBlock('adminhtml/widget_button')
15
  ->setType('button')
1
  <?php
2
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Advanced_Reimportsubscribers extends Mage_Adminhtml_Block_System_Config_Form_Field
 
3
  {
4
 
5
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
6
+ {
7
  $this->setElement($element);
8
+ return $this->_getAddRowButtonHtml($this->__("Run Now"));
9
  }
10
 
11
+ protected function _getAddRowButtonHtml($title)
12
+ {
13
+ $url = $this->getUrl("*/connector/reimoprtsubscribers");
14
 
15
  return $this->getLayout()->createBlock('adminhtml/widget_button')
16
  ->setType('button')
app/code/{local/Dotdigitalgroup/Email/Block/Debug/Initialsync.php → community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Resetcustomersimport.php} RENAMED
@@ -1,14 +1,16 @@
1
  <?php
2
-
3
- class Dotdigitalgroup_Email_Block_Debug_Initialsync extends Mage_Adminhtml_Block_System_Config_Form_Field
4
  {
5
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) {
 
 
6
  $this->setElement($element);
7
- return $this->_getAddRowButtonHtml($this->__('Run Initialisation Synchronization'));
8
  }
9
 
10
- protected function _getAddRowButtonHtml($title) {
11
- $url = Mage::helper('adminhtml')->getUrl("connector/debug/initialSync");
 
12
 
13
  return $this->getLayout()->createBlock('adminhtml/widget_button')
14
  ->setType('button')
@@ -17,4 +19,4 @@ class Dotdigitalgroup_Email_Block_Debug_Initialsync extends Mage_Adminhtml_Block
17
  ->toHtml();
18
  }
19
 
20
- }
1
  <?php
2
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Advanced_Resetcustomersimport extends Mage_Adminhtml_Block_System_Config_Form_Field
 
3
  {
4
+
5
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
6
+ {
7
  $this->setElement($element);
8
+ return $this->_getAddRowButtonHtml($this->__("Run Now"));
9
  }
10
 
11
+ protected function _getAddRowButtonHtml($title)
12
+ {
13
+ $url = $this->getUrl("*/connector/resetcustomersimport");
14
 
15
  return $this->getLayout()->createBlock('adminhtml/widget_button')
16
  ->setType('button')
19
  ->toHtml();
20
  }
21
 
22
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Runcontactsync.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Advanced_Runcontactsync extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+
6
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
7
+ {
8
+ $this->setElement($element);
9
+ return $this->_getAddRowButtonHtml($this->__("Run Now"));
10
+ }
11
+
12
+ protected function _getAddRowButtonHtml($title)
13
+ {
14
+ $url = Mage::helper('adminhtml')->getUrl("*/connector/runcontactsync");
15
+
16
+ return $this->getLayout()->createBlock('adminhtml/widget_button')
17
+ ->setType('button')
18
+ ->setLabel($this->__($title))
19
+ ->setOnClick("window.location.href='" . $url . "'")
20
+ ->toHtml();
21
+ }
22
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Runordersync.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Advanced_Runordersync extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+
6
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
7
+ {
8
+ $this->setElement($element);
9
+ return $this->_getAddRowButtonHtml($this->__("Run Now"));
10
+ }
11
+
12
+ protected function _getAddRowButtonHtml($title)
13
+ {
14
+ $url = Mage::helper('adminhtml')->getUrl("*/connector/runordersync");
15
+
16
+ return $this->getLayout()->createBlock('adminhtml/widget_button')
17
+ ->setType('button')
18
+ ->setLabel($this->__($title))
19
+ ->setOnClick("window.location.href='" . $url . "'")
20
+ ->toHtml();
21
+ }
22
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Runsubscribersync.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Advanced_Runsubscribersync extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+
6
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
7
+ {
8
+ $this->setElement($element);
9
+ return $this->_getAddRowButtonHtml($this->__("Run Now"));
10
+ }
11
+
12
+ protected function _getAddRowButtonHtml($title)
13
+ {
14
+ $url = Mage::helper('adminhtml')->getUrl("*/connector/runsubscribersync");
15
+
16
+ return $this->getLayout()->createBlock('adminhtml/widget_button')
17
+ ->setType('button')
18
+ ->setLabel($this->__($title))
19
+ ->setOnClick("window.location.href='" . $url . "'")
20
+ ->toHtml();
21
+ }
22
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Setupdatafields.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Advanced_Setupdatafields extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+
6
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
7
+ {
8
+ $this->setElement($element);
9
+ return $this->_getAddRowButtonHtml($this->__("Run Now"));
10
+ }
11
+
12
+ protected function _getAddRowButtonHtml($title)
13
+ {
14
+ $website = $this->getRequest()->getParam('website', 0);
15
+ $url = $this->getUrl("*/connector/setupdatafields/website/" . $website );
16
+
17
+ return $this->getLayout()->createBlock('adminhtml/widget_button')
18
+ ->setType('button')
19
+ ->setLabel($this->__($title))
20
+ ->setOnClick("window.location.href='" . $url . "'")
21
+ ->toHtml();
22
+ }
23
+
24
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Suppressedcontacts.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Advanced_Suppressedcontacts extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+
6
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
7
+ {
8
+ $this->setElement($element);
9
+ return $this->_getAddRowButtonHtml($this->__('Run Now'));
10
+ }
11
+
12
+ protected function _getAddRowButtonHtml($title)
13
+ {
14
+ $url = $this->getUrl("*/connector/suppresscontacts");
15
+
16
+ return $this->getLayout()->createBlock('adminhtml/widget_button')
17
+ ->setType('button')
18
+ ->setLabel($this->__($title))
19
+ ->setOnClick("window.location.href='" . $url . "'")
20
+ ->toHtml();
21
+ }
22
+
23
+ }
app/code/{local/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Password.php → community/Dotdigitalgroup/Email/Block/Adminhtml/System/Ajaxvalidate.php} RENAMED
@@ -1,6 +1,6 @@
1
  <?php
2
 
3
- class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Password extends Mage_Adminhtml_Block_System_Config_Form_Field
4
  {
5
  public function _getElementHtml(Varien_Data_Form_Element_Abstract$element){
6
 
1
  <?php
2
 
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Ajaxvalidate extends Mage_Adminhtml_Block_System_Config_Form_Field
4
  {
5
  public function _getElementHtml(Varien_Data_Form_Element_Abstract$element){
6
 
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Automation/Connect.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Automation_Connect extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
6
+ {
7
+ $this->setElement($element);
8
+ return $this->_getAddRowButtonHtml();
9
+ }
10
+
11
+ protected function _getAddRowButtonHtml()
12
+ {
13
+ $url = Mage::helper('connector')->getAuthoriseUrl();
14
+ $ssl = $this->_checkForSecureUrl();
15
+ $disabled = false;
16
+ if (!$ssl) {
17
+ $disabled = true;
18
+ //Mage::getSingleton('adminhtml/session')->addNotice('Cannot Use the Authorization For Non SSL Server!');
19
+
20
+ }
21
+
22
+ $adminUser = Mage::getSingleton('admin/session')->getUser();
23
+ $refreshToken = $adminUser->getRefreshToken();
24
+ $title = ($refreshToken)? $this->__('Disconnect') : $this->__('Connect');
25
+ $url = ($refreshToken)? $this->getUrl('*/email_automation/disconnect') : $url;
26
+
27
+ return $this->getLayout()->createBlock('adminhtml/widget_button')
28
+ ->setType('button')
29
+ ->setLabel($this->__($title))
30
+ ->setDisabled($disabled)
31
+ ->setOnClick("window.location.href='" . $url . "'")
32
+ ->toHtml();
33
+ }
34
+
35
+ private function _checkForSecureUrl()
36
+ {
37
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB, true);
38
+ if (!preg_match('/https/',$baseUrl)) {
39
+ return false;
40
+ }
41
+ return $this;
42
+ }
43
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Addressbook.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Addressbook extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+
6
+ /**
7
+ * Ajax Create the addressbooks.
8
+ * @param Varien_Data_Form_Element_Abstract $element
9
+ *
10
+ * @return string
11
+ */
12
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
13
+ {
14
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/createnewaddressbook');
15
+ $website = Mage::app()->getRequest()->getParam('website', 0);
16
+
17
+ $element->setData('after_element_html',
18
+ "<script>
19
+ function createAddressbook(form, element) {
20
+ var name = $('connector_sync_settings_dynamic_addressbook_addressbook_name').value;
21
+ var reloadurl = '{$url}';
22
+ if(name){
23
+ new Ajax.Request(reloadurl, {
24
+ method: 'post',
25
+ parameters: {'name' : name, 'website': '$website'},
26
+ onComplete: function(transport) {
27
+ window.location.reload();
28
+ }
29
+ });
30
+ }
31
+ return false;
32
+ }
33
+ </script>"
34
+ );
35
+
36
+ return parent::_getElementHtml($element);
37
+ }
38
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Datafield.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Datafield extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+
6
+ /**
7
+ * Ajax Create the datafields.
8
+ * @param Varien_Data_Form_Element_Abstract $element
9
+ *
10
+ * @return string
11
+ */
12
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
13
+ {
14
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/createnewdatafield');
15
+ $website = Mage::app()->getRequest()->getParam('website', 0);
16
+
17
+ $element->setData('after_element_html',
18
+ "<script>
19
+ function createDatafield(form, element) {
20
+ var datafield_name = $('connector_data_mapping_dynamic_datafield_datafield_name').value;
21
+ var datafield_type = $('connector_data_mapping_dynamic_datafield_datafield_type').value;
22
+ var datafield_default = $('connector_data_mapping_dynamic_datafield_datafield_default').value;
23
+ var datafield_access = $('connector_data_mapping_dynamic_datafield_datafield_access').value;
24
+
25
+ var reloadurl = '{$url}';
26
+
27
+ if(datafield_name && datafield_type && datafield_default && datafield_access){
28
+ new Ajax.Request(reloadurl, {
29
+ method: 'post',
30
+ parameters: {'name' : datafield_name, 'type' : datafield_type, 'default' : datafield_default, 'access' : datafield_access, 'website': '$website'},
31
+ onComplete: function(transport) {
32
+ window.location.reload();
33
+ }
34
+ });
35
+ }
36
+ return false;}</script>"
37
+ );
38
+
39
+ return parent::_getElementHtml($element);
40
+ }
41
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Resetcontacts.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Resetcontacts extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ public function _getElementHtml(Varien_Data_Form_Element_Abstract$element){
6
+
7
+ $element->setData('onchange', "resetContacts();");
8
+ //url to reset the contacs
9
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/resetcontactsajax');
10
+
11
+ $element->setData('after_element_html', "
12
+ <script>
13
+ function resetContacts(){
14
+ new Ajax.Request('{$url}', {
15
+ method: 'get',
16
+ onComplete: function(transport) {
17
+ }
18
+ });
19
+ return false;
20
+ }
21
+ </script>
22
+ ");
23
+
24
+ return parent::_getElementHtml($element);
25
+
26
+
27
+ }
28
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Resetguests.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Resetguests extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ public function _getElementHtml(Varien_Data_Form_Element_Abstract$element){
6
+
7
+ $element->setData('onchange', "resetGuests();");
8
+ //url to reset the guests
9
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/ajaxresetguests');
10
+
11
+ $element->setData('after_element_html', "
12
+ <script>
13
+ function resetGuests(){
14
+ new Ajax.Request('{$url}', {
15
+ method: 'get',
16
+ onComplete: function(transport) {
17
+ }
18
+ });
19
+ return false;
20
+ }
21
+ </script>
22
+ ");
23
+
24
+ return parent::_getElementHtml($element);
25
+
26
+
27
+ }
28
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Resetsubscribers.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Resetsubscribers extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ public function _getElementHtml(Varien_Data_Form_Element_Abstract$element){
6
+
7
+ $element->setData('onchange', "resetSubscribers();");
8
+ //url to reset the subscribers
9
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/ajaxresetsubscribers');
10
+
11
+ $element->setData('after_element_html', "
12
+ <script>
13
+ function resetSubscribers(){
14
+ new Ajax.Request('{$url}', {
15
+ method: 'get',
16
+ onComplete: function(transport) {
17
+ }
18
+ });
19
+ return false;
20
+ }
21
+ </script>
22
+ ");
23
+
24
+ return parent::_getElementHtml($element);
25
+
26
+
27
+ }
28
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Validator.php ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Validator extends Mage_Adminhtml_Block_System_Config_Form_Field
5
+ {
6
+
7
+ /**
8
+ * Ajax Validate the duplicate selection.
9
+ * @param Varien_Data_Form_Element_Abstract $element
10
+ *
11
+ * @return string
12
+ */
13
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
14
+ {
15
+ // Get the default HTML for this option
16
+ $html = parent::_getElementHtml($element);
17
+
18
+ // Set up additional JavaScript for our validation using jQuery.
19
+
20
+ $jquery = '<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>';
21
+
22
+ $html .=$jquery;
23
+ $javaScript = "<script type=\"text/javascript\"> var show_warning = 0;";
24
+
25
+ if(!Mage::helper('connector')->isSweetToothEnabled()){
26
+ $javaScript .= "show_warning = 1;";
27
+ }
28
+
29
+ $javaScript .=
30
+ "jQuery.noConflict();
31
+
32
+ jQuery(document).ready(function() {
33
+ // Handler for .ready() called.
34
+
35
+ //Show sweet tooth notice
36
+ if(show_warning == 1) jQuery('#sweet-tooth-warning').show();
37
+
38
+ // Hide our validation block
39
+ jQuery('#row_connector_data_mapping_customer_data_validator').hide();
40
+
41
+ // Add listener for changing select box
42
+
43
+ jQuery('#connector_data_mapping_customer_data select').on('change', function() {
44
+ var currentSelection = jQuery(this).val();
45
+ var currentDropdownId = jQuery(this).attr('id');
46
+ check(currentSelection, currentDropdownId);
47
+ });
48
+
49
+ jQuery('#connector_data_mapping_sweet_tooth select').on('change', function() {
50
+ var currentSelection = jQuery(this).val();
51
+ var currentDropdownId = jQuery(this).attr('id');
52
+ check(currentSelection, currentDropdownId);
53
+ });
54
+
55
+ function check(currentSelection, currentDropdownId){
56
+ // foreach of the select fields on our mapping page:
57
+ jQuery('select').each(function(){
58
+ var thisId = jQuery(this).attr('id');
59
+ if (thisId != currentDropdownId) {
60
+
61
+ var currentLabel = jQuery('label[for=\\'' + thisId + '\\']').text();
62
+ var thisVal = jQuery(this).val();
63
+
64
+ switch (thisVal) {
65
+ case '0':
66
+ // ignore DO NOT MAP fields
67
+ break;
68
+ case currentSelection:
69
+ // warning, that field is already mapped somewhere else - reset that value to 'Do not map''
70
+ alert('Warning! You have overwritten: '+currentLabel);
71
+ jQuery(this).val(0);
72
+ break;
73
+ default:
74
+ break;
75
+ break;
76
+ }
77
+ }
78
+ });
79
+ }
80
+ });
81
+ </script>";
82
+
83
+ $html .= $javaScript;
84
+ return $html;
85
+ }
86
+
87
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Waitingfield.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Waitingfield extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ /**
6
+ * Unscope the website level.
7
+ * @param Varien_Data_Form_Element_Abstract $element
8
+ *
9
+ * @return string
10
+ */
11
+ public function render(Varien_Data_Form_Element_Abstract $element)
12
+ {
13
+
14
+ $element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
15
+ return parent::render($element);
16
+
17
+ }
18
+
19
+ /**
20
+ * Loading background on save.
21
+ * @param Varien_Data_Form_Element_Abstract $element
22
+ *
23
+ * @return string
24
+ */
25
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
26
+ {
27
+ // Get the default HTML for this option
28
+ $html = parent::_getElementHtml($element);
29
+
30
+
31
+ $html .= sprintf('<div id="loadingmask" style="position: fixed;">
32
+ <div class="loader" id="loading-mask-loader">
33
+ <img src="%sskin/adminhtml/default/default/images/ajax-loader-tr.gif" alt="%s"/>%s', preg_replace('/index.php\//', '', $this->getBaseUrl()), $this->__('Loading...'), $this->__('Loading...'))
34
+ . '<div id="loading-mask"></div></div>';
35
+
36
+ $jQuery = '<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>';
37
+
38
+ $jQuery .=
39
+ '<script type="text/javascript">
40
+ jQuery.noConflict();
41
+ jQuery(document).ready(function() {
42
+ //hide the load image field
43
+ jQuery("#row_connector_api_credentials_api_credentials_validator").hide();
44
+ jQuery("#row_connector_sync_settings_sync_customer_schedule_validator").hide();
45
+ var loadingmask = jQuery("#loadingmask");
46
+ loadingmask.hide();
47
+ loadingmask.css({top : "50\%", left: "50\%"});
48
+ //var thisButton = jQuery("button");
49
+ //console.log(thisButton);
50
+ //jQuery("button").click(function(){
51
+ // jQuery("body").css({"background-color": "black", "opacity": "0.4"});
52
+ // jQuery("#row_connector_api_settings_api_credentials_validator").show();
53
+ // jQuery("#row_connector_sync_settings_sync_customer_schedule_validator").show();
54
+ // loadingmask.show();
55
+ // loadingmask.css({"display": "block", "opacity" : "1"});
56
+ //})
57
+ });
58
+ </script>';
59
+
60
+ $html .= $jQuery;
61
+
62
+ return $html;
63
+ }
64
+
65
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Wrapper.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Wrapper extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+
6
+ /**
7
+ * Ajax Validate the api credentials.
8
+ *
9
+ * @param Varien_Data_Form_Element_Abstract $element
10
+ *
11
+ * @return string
12
+ */
13
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
14
+ {
15
+ $element->setData('onchange', "apiValidation(this.form, this);");
16
+
17
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/ajaxvalidation');
18
+
19
+ $element->setData('after_element_html', "
20
+ <script>
21
+ document.observe('dom:loaded', function(){
22
+ apiValidation();
23
+ });
24
+ function apiValidation(form, element) {
25
+ var api_username = $('connector_api_credentials_api_username');
26
+ var api_password = $('connector_api_credentials_api_password');
27
+ var reloadurl = '{$url}';
28
+ var encoded = btoa(api_password.value);
29
+ if(api_username.value && api_password.value){
30
+ new Ajax.Request(reloadurl, {
31
+ method: 'post',
32
+ parameters: {'api_username' : api_username.value, 'api_password' : encoded},
33
+ onComplete: function(transport) {
34
+ Element.hide('loadingmask');
35
+ if(transport.responseText == '\"Credentials Valid.\"'){
36
+ api_username.setStyle({
37
+ fontWeight: 'bold',
38
+ color: 'green' ,
39
+ background: 'transparent url(\"" . $this->getSkinUrl('images/success_msg_icon.gif') . "\") no-repeat right center'
40
+ })
41
+ }else{
42
+ api_username.setStyle({
43
+ fontWeight: 'bold',
44
+ color: 'red',
45
+ background: 'transparent url(\"" . $this->getSkinUrl('images/error_msg_icon.gif') . "\") no-repeat right center'
46
+ });
47
+ }
48
+ }
49
+ });
50
+ }
51
+ return false;
52
+ }
53
+ </script>
54
+ ");
55
+
56
+ return parent::_getElementHtml($element);
57
+
58
+ }
59
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Addressbookbutton.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Addressbookbutton extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+
6
+ protected function _getAddRowButtonHtml($title)
7
+ {
8
+ return $this->getLayout()->createBlock('adminhtml/widget_button')
9
+ ->setType('button')
10
+ ->setLabel($this->__($title))
11
+ ->setOnClick("createAddressbook(this.form, this);")
12
+ ->toHtml();
13
+ }
14
+
15
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
16
+ {
17
+ $this->setElement($element);
18
+ $originalData = $element->getOriginalData();
19
+
20
+ return $this->_getAddRowButtonHtml($this->__($originalData['button_label']));
21
+ }
22
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Bestsellers.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Bestsellers extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ /** label */
6
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) {
7
+
8
+ //base url
9
+ $baseUrl = Mage::helper('connector')->generateDynamicUrl();
10
+
11
+ //config passcode
12
+ $passcode = Mage::helper('connector')->getPasscode();
13
+
14
+ if (!strlen($passcode))
15
+ $passcode = '[PLEASE SET UP A PASSCODE]';
16
+
17
+ //full url
18
+ $text = sprintf('%sconnector/report/bestsellers/code/%s', $baseUrl, $passcode);
19
+ $element->setData('value', $text);
20
+ $element->setData('disabled', 'disabled');
21
+
22
+ return parent::_getElementHtml($element);
23
+ }
24
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Couponinfo.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Couponinfo extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ /** label */
6
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
7
+ {
8
+ //base url
9
+ $baseUrl = Mage::helper('connector')->generateDynamicUrl();
10
+
11
+
12
+ //config code
13
+ $code = Mage::helper('connector')->getPasscode();
14
+
15
+ if (!strlen($code))
16
+ $code = '[PLEASE SET UP A PASSCODE]';
17
+
18
+ //full url
19
+ $text = $baseUrl . 'connector/email/coupon/id/[INSERT ID HERE]/code/'. $code;
20
+
21
+ $element->setData('value', $text);
22
+ $element->setData('disabled', 'disabled');
23
+ return parent::_getElementHtml($element);
24
+ }
25
+
26
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Creditmemonew.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Creditmemonew extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) {
6
+
7
+ //base url
8
+ $baseUrl = Mage::helper('connector')->generateDynamicUrl();
9
+
10
+ //config code
11
+ $code = Mage::helper('connector')->getPasscode();
12
+ $orderId = Mage::helper('connector')->getMappedOrderId();
13
+
14
+ //message to set up the passcode
15
+ if (!strlen($code))
16
+ $code = '[PLEASE SET UP A PASSCODE]';
17
+ //full url for dynamic content
18
+ $text = sprintf('%s/connector/creditmemo/new/code/%s/id/@%s@', $baseUrl, $code, $orderId);
19
+
20
+ $element->setData('value', $text);
21
+
22
+ return parent::_getElementHtml($element);
23
+ }
24
+
25
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Crosssell.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Crosssell extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
6
+ {
7
+ //base url
8
+ $baseUrl = Mage::helper('connector')->generateDynamicUrl();
9
+ //config passcode
10
+ $passcode = Mage::helper('connector')->getPasscode();
11
+ //last order id for dynamic page
12
+ $lastOrderId = Mage::helper('connector')->getLastOrderId();
13
+
14
+ if (!strlen($passcode))
15
+ $passcode = '[PLEASE SET UP A PASSCODE]';
16
+ //alert message for last order id is not mapped
17
+ if (!$lastOrderId)
18
+ $lastOrderId = '[PLEASE MAP THE LAST ORDER ID]';
19
+
20
+ //full url for dynamic content
21
+ $text = sprintf('%sconnector/products/crosssell/code/%s/order_id/@%s@', $baseUrl, $passcode, $lastOrderId);
22
+ $element->setData('value', $text);
23
+
24
+ return parent::_getElementHtml($element);
25
+ }
26
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Datafieldbutton.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Datafieldbutton extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ protected function _getAddRowButtonHtml($title)
6
+ {
7
+ return $this->getLayout()->createBlock('adminhtml/widget_button')
8
+ ->setType('button')
9
+ ->setLabel($this->__($title))
10
+ ->setOnClick("createDatafield(this.form, this);")
11
+ ->toHtml();
12
+ }
13
+
14
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
15
+ {
16
+ $this->setElement($element);
17
+ $originalData = $element->getOriginalData();
18
+
19
+ return $this->_getAddRowButtonHtml($this->__($originalData['button_label']));
20
+ }
21
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Gridlist.php ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Gridlist extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ /**
6
+ * Dynamic contaent dysplay type.
7
+ *
8
+ * @param Varien_Data_Form_Element_Abstract $element
9
+ *
10
+ * @return string
11
+ */
12
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
13
+ {
14
+ // Get the default HTML for this option
15
+ $html = parent::_getElementHtml($element);
16
+
17
+
18
+ $jQuery = '<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>';
19
+
20
+ $jQuery .=
21
+ '<script type="text/javascript">
22
+ jQuery.noConflict();
23
+ jQuery(document).ready(function() {
24
+ var gridOptions = {
25
+ "4" : "4",
26
+ "8" : "8",
27
+ "12" : "12",
28
+ "16" : "16",
29
+ "20" : "20",
30
+ "24" : "24",
31
+ "28" : "28",
32
+ "32" : "32"
33
+
34
+ };
35
+ var listOptions = {
36
+ "2" : "2",
37
+ "4" : "4",
38
+ "6" : "6",
39
+ "8" : "8"
40
+ }
41
+
42
+ jQuery("#connector_dynamic_content_products_related_display_type").change(function(){
43
+ var display_type = jQuery(this).closest("tr").next().find("select");
44
+ var display_mode = jQuery(this).val();
45
+ changeOptions(display_type, display_mode);
46
+ });
47
+
48
+ jQuery("#connector_dynamic_content_products_upsell_display_type").change(function(){
49
+ var display_type = jQuery(this).closest("tr").next().find("select");
50
+ var display_mode = jQuery(this).val();
51
+ changeOptions(display_type, display_mode);
52
+
53
+ });
54
+ jQuery("#connector_dynamic_content_products_crosssell_display_type").change(function(){
55
+ var display_type = jQuery(this).closest("tr").next().find("select");
56
+ var display_mode = jQuery(this).val();
57
+ changeOptions(display_type, display_mode);
58
+ });
59
+ jQuery("#connector_dynamic_content_products_bestsellers_display_type").change(function(){
60
+ var display_type = jQuery(this).closest("tr").next().find("select");
61
+ var display_mode = jQuery(this).val();
62
+ changeOptions(display_type, display_mode);
63
+ });
64
+ jQuery("#connector_dynamic_content_products_most_viewed_display_type").change(function(){
65
+ var display_type = jQuery(this).closest("tr").next().find("select");
66
+ var display_mode = jQuery(this).val();
67
+ changeOptions(display_type, display_mode);
68
+ });
69
+ jQuery("#connector_dynamic_content_products_recently_viewed_display_type").change(function(){
70
+ var display_type = jQuery(this).closest("tr").next().find("select");
71
+ var display_mode = jQuery(this).val();
72
+ changeOptions(display_type, display_mode);
73
+ });
74
+ jQuery("#connector_dynamic_content_manual_product_search_display_type").change(function(){
75
+ var display_type = jQuery(this).closest("tr").next().find("select");
76
+ var display_mode = jQuery(this).val();
77
+ changeOptions(display_type, display_mode);
78
+ });
79
+ function changeOptions(display_type, display_mode){
80
+ if(display_mode == "list"){
81
+ display_type.empty();
82
+
83
+ jQuery.each(listOptions, function(key, value) {
84
+ display_type.append(jQuery("<option></option>")
85
+ .attr("value", value).text(key));
86
+ });
87
+
88
+ }
89
+ if(display_mode == "grid"){
90
+ display_type.empty();
91
+ jQuery.each(gridOptions, function(key, value) {
92
+ display_type.append(jQuery("<option></option>")
93
+ .attr("value", value).text(key));
94
+ });
95
+ }
96
+ }
97
+ });
98
+ </script>';
99
+
100
+ $html .= $jQuery;
101
+
102
+ return $html;
103
+ }
104
+
105
+
106
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Lostbasket.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Lostbasket extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+
6
+ /** label */
7
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
8
+ {
9
+ //base url for dynamic content
10
+ $baseUrl = Mage::helper('connector')->generateDynamicUrl();
11
+ $code = Mage::helper('connector')->getPasscode();
12
+
13
+ //config passcode
14
+ if(!strlen($code))
15
+ $code = '[PLEASE SET UP A PASSCODE]';
16
+ // full url
17
+ $text = $baseUrl . 'connector/email/basket/email/@EMAIL@/code/'. $code;
18
+
19
+ $element->setData('value', $text);
20
+ return parent::_getElementHtml($element);
21
+ }
22
+
23
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Mostviewed.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Mostviewed extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ /** label */
6
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
7
+ {
8
+ //base url for dynamic content
9
+ $baseUrl = Mage::helper('connector')->generateDynamicUrl();
10
+ $passcode = Mage::helper('connector')->getPasscode();
11
+
12
+ if (!strlen($passcode))
13
+ $passcode = '[PLEASE SET UP A PASSCODE]';
14
+
15
+ //full url for dynamic content
16
+ $text = sprintf('%sconnector/report/mostviewed/code/%s', $baseUrl, $passcode);
17
+ $element->setData('value', $text);
18
+
19
+ return parent::_getElementHtml($element);
20
+ }
21
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Nosto.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Nosto extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
6
+ {
7
+ //passcode to append for url
8
+ $passcode = Mage::helper('connector')->getPasscode();
9
+
10
+ if(!strlen($passcode))
11
+ $passcode = '[PLEASE SET UP A PASSCODE]';
12
+
13
+ //generate the base url and display for default store id
14
+ $baseUrl = Mage::helper('connector')->generateDynamicUrl();
15
+
16
+ //display the full url
17
+ $text = sprintf('%sconnector/products/nosto/code/%s/slot/@SLOT_NAME@/email/@EMAIL@', $baseUrl, $passcode);
18
+ $element->setData('value', $text);
19
+
20
+ return parent::_getElementHtml($element);
21
+ }
22
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Productpush.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Productpush extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ /** label */
6
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
7
+ {
8
+ //generate base url
9
+ $baseUrl = Mage::helper('connector')->generateDynamicUrl();
10
+ $passcode = Mage::helper('connector')->getPasscode();
11
+
12
+ if (!strlen($passcode))
13
+ $passcode = '[PLEASE SET UP A PASSCODE]';
14
+
15
+ //full url for dynamic content
16
+ $text = sprintf('%sconnector/products/push/code/%s', $baseUrl, $passcode);
17
+ $element->setData('value', $text);
18
+
19
+ return parent::_getElementHtml($element);
20
+ }
21
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Recentlyviewed.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Recentlyviewed extends Mage_Adminhtml_Block_System_Config_Form_Field
3
+ {
4
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
5
+ {
6
+ //generate base url for dynamic content
7
+ $baseUrl = Mage::helper('connector')->generateDynamicUrl();
8
+
9
+ //config passcode
10
+ $passcode = Mage::helper('connector')->getPasscode();
11
+ $customerId = Mage::helper('connector')->getMappedCustomerId();
12
+
13
+ if (!strlen($passcode))
14
+ $passcode = '[PLEASE SET UP A PASSCODE]';
15
+ if (!$customerId)
16
+ $customerId = '[PLEASE MAP THE CUSTOMER ID]';
17
+ //dynamic content url
18
+ $text = sprintf('%sconnector/report/recentlyviewed/code/%s/customer_id/@%s@', $baseUrl, $passcode, $customerId);
19
+ $element->setData('value', $text);
20
+
21
+ return parent::_getElementHtml($element);
22
+
23
+ }
24
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Related.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Related extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
6
+ {
7
+ //passcode to append for url
8
+ $passcode = Mage::helper('connector')->getPasscode();
9
+ //last order id witch information will be generated
10
+ $lastOrderId = Mage::helper('connector')->getLastOrderId();
11
+
12
+ if(!strlen($passcode))
13
+ $passcode = '[PLEASE SET UP A PASSCODE]';
14
+ if(!$lastOrderId)
15
+ $lastOrderId = '[PLEASE MAP THE LAST ORDER ID]';
16
+
17
+ //generate the base url and display for default store id
18
+ $baseUrl = Mage::helper('connector')->generateDynamicUrl();
19
+
20
+ //display the full url
21
+ $text = sprintf('%sconnector/products/related/code/%s/order_id/@%s@', $baseUrl, $passcode, $lastOrderId);
22
+ $element->setData('value', $text);
23
+
24
+ return parent::_getElementHtml($element);
25
+ }
26
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Upsell.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Upsell extends Mage_Adminhtml_Block_System_Config_Form_Field
3
+ {
4
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
5
+ {
6
+ //passcode to append for url
7
+ $passcode = Mage::helper('connector')->getPasscode();
8
+ //last order id witch information will be generated
9
+ $lastOrderid = Mage::helper('connector')->getLastOrderId();
10
+
11
+ if(!strlen($passcode))
12
+ $passcode = '[PLEASE SET UP A PASSCODE]';
13
+ if(!$lastOrderid)
14
+ $lastOrderid = '[PLEASE MAP THE LAST ORDER ID]';
15
+
16
+ //generate the base url and display for default store id
17
+ $baseUrl = Mage::helper('connector')->generateDynamicUrl();
18
+
19
+ $text = sprintf('%sconnector/products/upsell/code/%s/order_id/@%s@', $baseUrl, $passcode, $lastOrderid);
20
+ $element->setData('value', $text);
21
+
22
+ return parent::_getElementHtml($element);
23
+ }
24
+ }
app/code/{local/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Wrapper.php → community/Dotdigitalgroup/Email/Block/Adminhtml/System/Emailapivalidate.php} RENAMED
@@ -1,12 +1,14 @@
1
  <?php
2
 
3
- class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Wrapper extends Mage_Adminhtml_Block_System_Config_Form_Field
4
  {
5
 
6
  protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
7
  {
8
  $element->setData('onchange', "apiValidation(this.form, this);");
9
 
 
 
10
  $element->setData('after_element_html', "
11
  <script>
12
  document.observe('dom:loaded', function(){
@@ -14,17 +16,16 @@ class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Wrapper extends Mage_A
14
 
15
  });
16
  function apiValidation(form, element) {
17
- var api_user = $('connector_api_settings_api_credentials_username');
18
- var api_password = $('connector_api_settings_api_credentials_password');
19
-
20
- var reloadurl = '{$this->getUrl('connector/debug/ajaxvalidation')}';
21
-
22
  new Ajax.Request(reloadurl, {
23
  method: 'post',
24
- parameters: {'api_user' : api_user.value, 'api_password' : api_password.value},
25
  onComplete: function(transport) {
26
  Element.hide('loadingmask');
27
- if(transport.responseText == '\"Valid\"'){
28
  api_user.setStyle({
29
  fontWeight: 'bold',
30
  color: 'green' ,
1
  <?php
2
 
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Emailapivalidate extends Mage_Adminhtml_Block_System_Config_Form_Field
4
  {
5
 
6
  protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
7
  {
8
  $element->setData('onchange', "apiValidation(this.form, this);");
9
 
10
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/ajaxvalidation');
11
+
12
  $element->setData('after_element_html', "
13
  <script>
14
  document.observe('dom:loaded', function(){
16
 
17
  });
18
  function apiValidation(form, element) {
19
+ var api_user = $('connector_transactional_emails_credentials_api_username');
20
+ var api_password = $('connector_transactional_emails_credentials_api_password');
21
+ var reloadurl = '{$url}';
22
+ var encoded = btoa(api_password.value);
 
23
  new Ajax.Request(reloadurl, {
24
  method: 'post',
25
+ parameters: {'api_username' : api_user.value, 'api_password' : encoded},
26
  onComplete: function(transport) {
27
  Element.hide('loadingmask');
28
+ if(transport.responseText == '\"Credentials Valid.\"'){
29
  api_user.setStyle({
30
  fontWeight: 'bold',
31
  color: 'green' ,
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Sms/Smsmessagefour.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Sms_Smsmessagefour extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ const DEFAULT_TEXT = 'Default SMS Text';
6
+
7
+ /**
8
+ * SMS insert links.
9
+ * @param Varien_Data_Form_Element_Abstract $element
10
+ *
11
+ * @return string
12
+ */
13
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract$element)
14
+ {
15
+ $element->setData('placeholder', self::DEFAULT_TEXT);
16
+ $element->setData('after_element_html',
17
+ "<a href='#' onclick=\"injectText('connector_sms_sms_four_message', '{{var order_number}}');return false;\">Insert Order Number</a>
18
+ <a href='#' onclick=\"injectText('connector_sms_sms_four_message', '{{var customer_name}}');return false;\">Insert Customer Name</a>"
19
+ );
20
+ return parent::_getElementHtml($element);
21
+ }
22
+
23
+
24
+ }
app/code/{local/Dotdigitalgroup/Email/Block/Adminhtml/System/Config → community/Dotdigitalgroup/Email/Block/Adminhtml/System/Sms}/Smsmessageone.php RENAMED
@@ -1,18 +1,23 @@
1
  <?php
2
 
3
- class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Smsmessageone extends Mage_Adminhtml_Block_System_Config_Form_Field
4
  {
5
  const DEFAULT_TEXT = 'Default SMS Text';
6
 
7
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract$element){
8
-
9
-
 
 
 
 
 
 
10
  $element->setData('placeholder', self::DEFAULT_TEXT);
 
11
 
12
- $element->setData('after_element_html', "
13
-
14
- <a href='#' onclick=\"injectText('sms_section_sms_message_one_message', '{{var order_number}}');return false;\">Insert Order Number</a>
15
- <a href='#' onclick=\"injectText('sms_section_sms_message_one_message', '{{var customer_name}}');return false;\">Insert Customer Name</a>
16
 
17
  <script type='text/javascript'>
18
  function injectText(element,value){
1
  <?php
2
 
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Sms_Smsmessageone extends Mage_Adminhtml_Block_System_Config_Form_Field
4
  {
5
  const DEFAULT_TEXT = 'Default SMS Text';
6
 
7
+ /**
8
+ * SMS insert links.
9
+ *
10
+ * @param Varien_Data_Form_Element_Abstract $element
11
+ *
12
+ * @return string
13
+ */
14
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract$element)
15
+ {
16
  $element->setData('placeholder', self::DEFAULT_TEXT);
17
+ $element->setData('after_element_html',
18
 
19
+ "<a href='#' onclick=\"injectText('connector_sms_sms_one_message', '{{var order_number}}');return false;\">Insert Order Number</a>
20
+ <a href='#' onclick=\"injectText('connector_sms_sms_one_message', '{{var customer_name}}');return false;\">Insert Customer Name</a>
 
 
21
 
22
  <script type='text/javascript'>
23
  function injectText(element,value){
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Sms/Smsmessagethree.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Sms_Smsmessagethree extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ const DEFAULT_TEXT = 'Default SMS Text';
6
+
7
+ /**
8
+ * SMS insert links.
9
+ *
10
+ * @param Varien_Data_Form_Element_Abstract $element
11
+ *
12
+ * @return string
13
+ */
14
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract$element)
15
+ {
16
+ $element->setData('placeholder', self::DEFAULT_TEXT);
17
+ $element->setData('after_element_html',
18
+
19
+ "<a href='#' onclick=\"injectText('connector_sms_sms_three_message', '{{var order_number}}');return false;\">Insert Order Number</a>
20
+ <a href='#' onclick=\"injectText('connector_sms_sms_three_message', '{{var customer_name}}');return false;\">Insert Customer Name</a>"
21
+ );
22
+ return parent::_getElementHtml($element);
23
+ }
24
+
25
+
26
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Sms/Smsmessagetwo.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Sms_Smsmessagetwo extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ const DEFAULT_TEXT = 'Default SMS Text';
6
+
7
+ /**
8
+ * SMS insert links.
9
+ *
10
+ * @param Varien_Data_Form_Element_Abstract $element
11
+ *
12
+ * @return string
13
+ */
14
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract$element)
15
+ {
16
+ $element->setData('placeholder', self::DEFAULT_TEXT);
17
+ $element->setData('after_element_html',
18
+ "<a href='#' onclick=\"injectText('connector_sms_sms_two_message', '{{var order_number}}');return false;\">Insert Order Number</a>
19
+ <a href='#' onclick=\"injectText('connector_sms_sms_two_message', '{{var customer_name}}');return false;\">Insert Customer Name</a>"
20
+ );
21
+ return parent::_getElementHtml($element);
22
+ }
23
+
24
+
25
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Creditmemoupdate.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Url_Creditmemoupdate extends Mage_Adminhtml_Block_System_Config_Form_Field
3
+ {
4
+ /**
5
+ * Generate the urls.
6
+ * @param Varien_Data_Form_Element_Abstract $element
7
+ *
8
+ * @return string
9
+ * @throws Mage_Core_Exception
10
+ */
11
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
12
+ {
13
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
14
+ $website = Mage::app()->getRequest()->getParam('website', false);
15
+
16
+ if ($website) {
17
+ $website = Mage::app()->getWebsite($website);
18
+ $baseUrl = $website->getConfig('web/secure/base_url');
19
+ }
20
+ $helper = Mage::helper('connector');
21
+ $passcode = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DYNAMIC_CONTENT_PASSCODE, $website);
22
+ $orderId = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_LAST_ORDER_ID, $website);
23
+
24
+ if(!strlen($passcode)) $passcode = '[PLEASE SET UP A PASSCODE]';
25
+
26
+ $text = sprintf('%sconnector/creditmemo/update/code/%s/order_id/@%s@', $baseUrl, $passcode, $orderId);
27
+
28
+ $element->setData('value', $text);
29
+
30
+ return parent::_getElementHtml($element);
31
+ }
32
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Creditmemoupdateguest.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Url_Creditmemoupdateguest extends Mage_Adminhtml_Block_System_Config_Form_Field
3
+ {
4
+ /**
5
+ * Generate the urls.
6
+ * @param Varien_Data_Form_Element_Abstract $element
7
+ *
8
+ * @return string
9
+ * @throws Mage_Core_Exception
10
+ */
11
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
12
+ {
13
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
14
+ $website = Mage::app()->getRequest()->getParam('website', false);
15
+
16
+ if ($website) {
17
+ $website = Mage::app()->getWebsite($website);
18
+ $baseUrl = $website->getConfig('web/secure/base_url');
19
+ }
20
+ $helper = Mage::helper('connector');
21
+ $passcode = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DYNAMIC_CONTENT_PASSCODE, $website);
22
+ $orderId = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_LAST_ORDER_ID, $website);
23
+ if(!strlen($passcode)) $passcode = '[PLEASE SET UP A PASSCODE]';
24
+
25
+ $text = sprintf('%sconnector/creditmemo/updateguest/code/%s/order_id/@%s@', $baseUrl, $passcode, $orderId);
26
+ $element->setData('value', $text);
27
+
28
+ return parent::_getElementHtml($element);
29
+ }
30
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Customerconfirmation.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Url_Customerconfirmation extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+
6
+ /**
7
+ * Generate the urls.
8
+ *
9
+ * @param Varien_Data_Form_Element_Abstract $element
10
+ *
11
+ * @return string
12
+ * @throws Mage_Core_Exception
13
+ */
14
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
15
+ {
16
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
17
+ $website = Mage::app()->getRequest()->getParam('website', false);
18
+
19
+ if ($website) {
20
+ $website = Mage::app()->getWebsite($website);
21
+ $baseUrl = $website->getConfig('web/secure/base_url');
22
+ }
23
+ $helper = Mage::helper('connector');
24
+ $passcode = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DYNAMIC_CONTENT_PASSCODE, $website);
25
+ $customerId = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_CUSTOMER_ID, $website);
26
+
27
+ if(!strlen($passcode)) $passcode = '[PLEASE SET UP A PASSCODE]';
28
+
29
+ $text = sprintf('%sconnector/customer/confirmation/code/%s/customer_id/@%s@', $baseUrl, $passcode, $customerId);
30
+ $element->setData('value', $text);
31
+
32
+ return parent::_getElementHtml($element);
33
+ }
34
+
35
+
36
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Customerconfirmed.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Url_Customerconfirmed extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+
6
+ /**
7
+ * Generate the urls.
8
+ *
9
+ * @param Varien_Data_Form_Element_Abstract $element
10
+ *
11
+ * @return string
12
+ * @throws Mage_Core_Exception
13
+ */
14
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
15
+ {
16
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
17
+ $website = Mage::app()->getRequest()->getParam('website', false);
18
+
19
+ if ($website) {
20
+ $website = Mage::app()->getWebsite($website);
21
+ $baseUrl = $website->getConfig('web/secure/base_url');
22
+ }
23
+ $helper = Mage::helper('connector');
24
+ $passcode = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DYNAMIC_CONTENT_PASSCODE, $website);
25
+ $customerId = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_CUSTOMER_ID, $website);
26
+
27
+ if(!strlen($passcode)) $passcode = '[PLEASE SET UP A PASSCODE]';
28
+
29
+ $text = sprintf('%sconnector/customer/confirmed/code/%s/customer_id/@%s@', $baseUrl, $passcode, $customerId);
30
+ $element->setData('value', $text);
31
+
32
+ return parent::_getElementHtml($element);
33
+ }
34
+
35
+
36
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Customernew.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Url_Customernew extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+
6
+ /**
7
+ * Generate the urls.
8
+ *
9
+ * @param Varien_Data_Form_Element_Abstract $element
10
+ *
11
+ * @return string
12
+ * @throws Mage_Core_Exception
13
+ */
14
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
15
+ {
16
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
17
+ $website = Mage::app()->getRequest()->getParam('website', false);
18
+
19
+ if ($website) {
20
+ $website = Mage::app()->getWebsite($website);
21
+ $baseUrl = $website->getConfig('web/secure/base_url');
22
+ }
23
+ $helper = Mage::helper('connector');
24
+ $passcode = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DYNAMIC_CONTENT_PASSCODE, $website);
25
+ $customerId = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_CUSTOMER_ID, $website);
26
+
27
+ if(!strlen($passcode)) $passcode = '[PLEASE SET UP A PASSCODE]';
28
+
29
+ $text = sprintf('%sconnector/customer/new/code/%s/customer_id/@%s@', $baseUrl, $passcode, $customerId);
30
+ $element->setData('value', $text);
31
+
32
+ return parent::_getElementHtml($element);
33
+ }
34
+
35
+
36
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Invoiceupdate.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Url_Invoiceupdate extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ /**
6
+ * Generate the urls.
7
+ *
8
+ * @param Varien_Data_Form_Element_Abstract $element
9
+ *
10
+ * @return string
11
+ * @throws Mage_Core_Exception
12
+ */
13
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
14
+ {
15
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
16
+ $website = Mage::app()->getRequest()->getParam('website', false);
17
+
18
+ if ($website) {
19
+ $website = Mage::app()->getWebsite($website);
20
+ $baseUrl = $website->getConfig('web/secure/base_url');
21
+ }
22
+ $helper = Mage::helper('connector');
23
+ $passcode = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DYNAMIC_CONTENT_PASSCODE, $website);
24
+ $orderId = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_LAST_ORDER_ID, $website);
25
+
26
+ if(!strlen($passcode)) $passcode = '[PLEASE SET UP A PASSCODE]';
27
+
28
+ $text = sprintf('%sconnector/invoice/update/code/%s/order_id/@%s@', $baseUrl, $passcode, $orderId);
29
+ $element->setData('value', $text);
30
+
31
+ return parent::_getElementHtml($element);
32
+ }
33
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Invoiceupdateguest.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Url_Invoiceupdateguest extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ /**
6
+ * Generate the urls.
7
+ *
8
+ * @param Varien_Data_Form_Element_Abstract $element
9
+ *
10
+ * @return string
11
+ * @throws Mage_Core_Exception
12
+ */
13
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
14
+ {
15
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
16
+ $website = Mage::app()->getRequest()->getParam('website', false);
17
+
18
+ if ($website) {
19
+ $website = Mage::app()->getWebsite($website);
20
+ $baseUrl = $website->getConfig('web/secure/base_url');
21
+ }
22
+ $helper = Mage::helper('connector');
23
+ $passcode = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DYNAMIC_CONTENT_PASSCODE, $website);
24
+ $orderId = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_LAST_ORDER_ID, $website);
25
+
26
+ if(!strlen($passcode)) $passcode = '[PLEASE SET UP A PASSCODE]';
27
+
28
+ $text = sprintf('%sconnector/invoice/updateguest/code/%s/order_id/@%s@', $baseUrl, $passcode, $orderId);
29
+ $element->setData('value', $text);
30
+
31
+ return parent::_getElementHtml($element);
32
+ }
33
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Newcreditmemo.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Url_Newcreditmemo extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ /**
6
+ * Generate the urls.
7
+ *
8
+ * @param Varien_Data_Form_Element_Abstract $element
9
+ *
10
+ * @return string
11
+ * @throws Mage_Core_Exception
12
+ */
13
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
14
+ {
15
+
16
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
17
+ $website = Mage::app()->getRequest()->getParam('website', false);
18
+
19
+ if ($website) {
20
+ $website = Mage::app()->getWebsite($website);
21
+ $baseUrl = $website->getConfig('web/secure/base_url');
22
+ }
23
+ $helper = Mage::helper('connector');
24
+ $passcode = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DYNAMIC_CONTENT_PASSCODE, $website);
25
+ $orderId = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_LAST_ORDER_ID, $website);
26
+
27
+
28
+ if(!strlen($passcode)) $passcode = '[PLEASE SET UP A PASSCODE]';
29
+
30
+ $text = sprintf('%sconnector/creditmemo/new/code/%s/order_id/@%s@', $baseUrl, $passcode, $orderId);
31
+ $element->setData('value', $text);
32
+
33
+ return parent::_getElementHtml($element);
34
+ }
35
+
36
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Newcreditmemoguest.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Url_Newcreditmemoguest extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ /**
6
+ * Generate the urls.
7
+ *
8
+ * @param Varien_Data_Form_Element_Abstract $element
9
+ *
10
+ * @return string
11
+ * @throws Mage_Core_Exception
12
+ */
13
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
14
+ {
15
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
16
+ $website = Mage::app()->getRequest()->getParam('website', false);
17
+
18
+ if ($website) {
19
+ $website = Mage::app()->getWebsite($website);
20
+ $baseUrl = $website->getConfig('web/secure/base_url');
21
+ }
22
+ $helper = Mage::helper('connector');
23
+ $passcode = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DYNAMIC_CONTENT_PASSCODE, $website);
24
+ $orderId = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_LAST_ORDER_ID, $website);
25
+
26
+
27
+ if(!strlen($passcode)) $passcode = '[PLEASE SET UP A PASSCODE]';
28
+
29
+ $text = sprintf('%sconnector/creditmemo/newguest/code/%s/order_id/@%s@', $baseUrl, $passcode, $orderId);
30
+ $element->setData('value', $text);
31
+
32
+ return parent::_getElementHtml($element);
33
+ }
34
+
35
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Newinvoice.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Url_Newinvoice extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ /**
6
+ * Generate the urls.
7
+ *
8
+ * @param Varien_Data_Form_Element_Abstract $element
9
+ *
10
+ * @return string
11
+ * @throws Mage_Core_Exception
12
+ */
13
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
14
+ {
15
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
16
+ $website = Mage::app()->getRequest()->getParam('website', false);
17
+
18
+ if ($website) {
19
+ $website = Mage::app()->getWebsite($website);
20
+ $baseUrl = $website->getConfig('web/secure/base_url');
21
+ }
22
+ $helper = Mage::helper('connector');
23
+ $passcode = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DYNAMIC_CONTENT_PASSCODE, $website);
24
+ $orderId = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_LAST_ORDER_ID, $website);
25
+
26
+
27
+ if(!strlen($passcode)) $passcode = '[PLEASE SET UP A PASSCODE]';
28
+
29
+ $text = sprintf('%sconnector/invoice/new/code/%s/order_id/@%s@', $baseUrl, $passcode, $orderId);
30
+ $element->setData('value', $text);
31
+
32
+ return parent::_getElementHtml($element);
33
+ }
34
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Newinvoiceguest.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Url_Newinvoiceguest extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ /**
6
+ * Generate the urls.
7
+ *
8
+ * @param Varien_Data_Form_Element_Abstract $element
9
+ *
10
+ * @return string
11
+ * @throws Mage_Core_Exception
12
+ */
13
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
14
+ {
15
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
16
+ $website = Mage::app()->getRequest()->getParam('website', false);
17
+
18
+ if ($website) {
19
+ $website = Mage::app()->getWebsite($website);
20
+ $baseUrl = $website->getConfig('web/secure/base_url');
21
+ }
22
+ $helper = Mage::helper('connector');
23
+ $passcode = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DYNAMIC_CONTENT_PASSCODE, $website);
24
+ $orderId = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_LAST_ORDER_ID, $website);
25
+
26
+
27
+ if(!strlen($passcode)) $passcode = '[PLEASE SET UP A PASSCODE]';
28
+
29
+ $text = sprintf('%sconnector/invoice/newguest/code/%s/order_id/@%s@', $baseUrl, $passcode, $orderId);
30
+ $element->setData('value', $text);
31
+
32
+ return parent::_getElementHtml($element);
33
+ }
34
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Neworder.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Url_Neworder extends Mage_Adminhtml_Block_System_Config_Form_Field
3
+ {
4
+ /**
5
+ * Generate the urls.
6
+ *
7
+ * @param Varien_Data_Form_Element_Abstract $element
8
+ *
9
+ * @return string
10
+ * @throws Mage_Core_Exception
11
+ */
12
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
13
+ {
14
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
15
+ $website = Mage::app()->getRequest()->getParam('website', false);
16
+
17
+ if ($website) {
18
+ $website = Mage::app()->getWebsite($website);
19
+ $baseUrl = $website->getConfig('web/secure/base_url');
20
+ }
21
+ $helper = Mage::helper('connector');
22
+ $passcode = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DYNAMIC_CONTENT_PASSCODE, $website);
23
+ $orderId = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_LAST_ORDER_ID, $website);
24
+
25
+
26
+ if(!strlen($passcode)) $passcode = '[PLEASE SET UP A PASSCODE]';
27
+
28
+ $text = sprintf('%sconnector/order/new/code/%s/order_id/@%s@', $baseUrl, $passcode, $orderId);
29
+ $element->setData('value', $text);
30
+
31
+ return parent::_getElementHtml($element);
32
+ }
33
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Neworderguest.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Url_Neworderguest extends Mage_Adminhtml_Block_System_Config_Form_Field
3
+ {
4
+ /**
5
+ * Generate the urls.
6
+ *
7
+ * @param Varien_Data_Form_Element_Abstract $element
8
+ *
9
+ * @return string
10
+ * @throws Mage_Core_Exception
11
+ */
12
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
13
+ {
14
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
15
+ $website = Mage::app()->getRequest()->getParam('website', false);
16
+
17
+ if ($website) {
18
+ $website = Mage::app()->getWebsite($website);
19
+ $baseUrl = $website->getConfig('web/secure/base_url');
20
+ }
21
+ $helper = Mage::helper('connector');
22
+ $passcode = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DYNAMIC_CONTENT_PASSCODE, $website);
23
+ $orderId = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_LAST_ORDER_ID, $website);
24
+
25
+ if(!strlen($passcode)) $passcode = '[PLEASE SET UP A PASSCODE]';
26
+
27
+ $text = sprintf('%sconnector/order/newguest/code/%s/order_id/@%s@', $baseUrl, $passcode, $orderId);
28
+ $element->setData('value', $text);
29
+
30
+ return parent::_getElementHtml($element);
31
+ }
32
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Newshipment.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Url_Newshipment extends Mage_Adminhtml_Block_System_Config_Form_Field
3
+ {
4
+ /**
5
+ * Generate the urls.
6
+ *
7
+ * @param Varien_Data_Form_Element_Abstract $element
8
+ *
9
+ * @return string
10
+ * @throws Mage_Core_Exception
11
+ */
12
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
13
+ {
14
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
15
+ $website = Mage::app()->getRequest()->getParam('website', false);
16
+
17
+ if ($website) {
18
+ $website = Mage::app()->getWebsite($website);
19
+ $baseUrl = $website->getConfig('web/secure/base_url');
20
+ }
21
+ $helper = Mage::helper('connector');
22
+ $passcode = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DYNAMIC_CONTENT_PASSCODE, $website);
23
+ $orderId = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_LAST_ORDER_ID, $website);
24
+
25
+ if(!strlen($passcode)) $passcode = '[PLEASE SET UP A PASSCODE]';
26
+
27
+ $text = sprintf('%sconnector/shipping/new/code/%s/order_id/@%s@', $baseUrl, $passcode, $orderId);
28
+
29
+
30
+ $element->setData('value', $text);
31
+
32
+ return parent::_getElementHtml($element);
33
+ }
34
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Newshipmentguest.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Url_Newshipmentguest extends Mage_Adminhtml_Block_System_Config_Form_Field
3
+ {
4
+ /**
5
+ * Generate the urls.
6
+ *
7
+ * @param Varien_Data_Form_Element_Abstract $element
8
+ *
9
+ * @return string
10
+ * @throws Mage_Core_Exception
11
+ */
12
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
13
+ {
14
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
15
+ $website = Mage::app()->getRequest()->getParam('website', false);
16
+
17
+ if ($website) {
18
+ $website = Mage::app()->getWebsite($website);
19
+ $baseUrl = $website->getConfig('web/secure/base_url');
20
+ }
21
+ $helper = Mage::helper('connector');
22
+ $passcode = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DYNAMIC_CONTENT_PASSCODE, $website);
23
+ $orderId = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_LAST_ORDER_ID, $website);
24
+
25
+ if(!strlen($passcode)) $passcode = '[PLEASE SET UP A PASSCODE]';
26
+
27
+ $text = sprintf('%sconnector/shipping/newguest/code/%s/order_id/@%s@', $baseUrl, $passcode, $orderId);
28
+
29
+ $element->setData('value', $text);
30
+
31
+ return parent::_getElementHtml($element);
32
+ }
33
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Orderupdate.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Url_Orderupdate extends Mage_Adminhtml_Block_System_Config_Form_Field
3
+ {
4
+ /**
5
+ * Generate the urls.
6
+ *
7
+ * @param Varien_Data_Form_Element_Abstract $element
8
+ *
9
+ * @return string
10
+ * @throws Mage_Core_Exception
11
+ */
12
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
13
+ {
14
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
15
+ $website = Mage::app()->getRequest()->getParam('website', false);
16
+
17
+ if ($website) {
18
+ $website = Mage::app()->getWebsite($website);
19
+ $baseUrl = $website->getConfig('web/secure/base_url');
20
+ }
21
+ $helper = Mage::helper('connector');
22
+ $passcode = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DYNAMIC_CONTENT_PASSCODE, $website);
23
+ $orderId = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_LAST_ORDER_ID, $website);
24
+
25
+ if(!strlen($passcode)) $passcode = '[PLEASE SET UP A PASSCODE]';
26
+ $text = sprintf('%sconnector/order/update/code/%s/order_id/@%s@', $baseUrl, $passcode, $orderId);
27
+ $element->setData('value', $text);
28
+
29
+ return parent::_getElementHtml($element);
30
+ }
31
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Orderupdateguest.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Url_Orderupdateguest extends Mage_Adminhtml_Block_System_Config_Form_Field
3
+ {
4
+ /**
5
+ * Generate the urls.
6
+ *
7
+ * @param Varien_Data_Form_Element_Abstract $element
8
+ *
9
+ * @return string
10
+ * @throws Mage_Core_Exception
11
+ */
12
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
13
+ {
14
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
15
+ $website = Mage::app()->getRequest()->getParam('website', false);
16
+
17
+ if ($website) {
18
+ $website = Mage::app()->getWebsite($website);
19
+ $baseUrl = $website->getConfig('web/secure/base_url');
20
+ }
21
+ $helper = Mage::helper('connector');
22
+ $passcode = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DYNAMIC_CONTENT_PASSCODE, $website);
23
+ $orderId = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_LAST_ORDER_ID, $website);
24
+
25
+ if(!strlen($passcode)) $passcode = '[PLEASE SET UP A PASSCODE]';
26
+ $text = sprintf('%sconnector/order/updateguest/code/%s/order_id/@%s@', $baseUrl, $passcode, $orderId);
27
+ $element->setData('value', $text);
28
+
29
+ return parent::_getElementHtml($element);
30
+ }
31
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Shipmentupdate.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Url_Shipmentupdate extends Mage_Adminhtml_Block_System_Config_Form_Field
3
+ {
4
+ /**
5
+ * Generate the urls.
6
+ *
7
+ * @param Varien_Data_Form_Element_Abstract $element
8
+ *
9
+ * @return string
10
+ * @throws Mage_Core_Exception
11
+ */
12
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
13
+ {
14
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
15
+ $website = Mage::app()->getRequest()->getParam('website', false);
16
+
17
+ if ($website) {
18
+ $website = Mage::app()->getWebsite($website);
19
+ $baseUrl = $website->getConfig('web/secure/base_url');
20
+ }
21
+ $helper = Mage::helper('connector');
22
+ $passcode = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DYNAMIC_CONTENT_PASSCODE, $website);
23
+ $orderId = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_LAST_ORDER_ID, $website);
24
+
25
+ if(!strlen($passcode)) $passcode = '[PLEASE SET UP A PASSCODE]';
26
+
27
+ $text = sprintf('%sconnector/shipping/update/code/%s/order_id/@%s@', $baseUrl, $passcode, $orderId);
28
+
29
+ $element->setData('value', $text);
30
+
31
+ return parent::_getElementHtml($element);
32
+ }
33
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Shipmentupdateguest.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Url_Shipmentupdateguest extends Mage_Adminhtml_Block_System_Config_Form_Field
3
+ {
4
+ /**
5
+ * Generate the urls.
6
+ *
7
+ * @param Varien_Data_Form_Element_Abstract $element
8
+ *
9
+ * @return string
10
+ * @throws Mage_Core_Exception
11
+ */
12
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
13
+ {
14
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
15
+ $website = Mage::app()->getRequest()->getParam('website', false);
16
+
17
+ if ($website) {
18
+ $website = Mage::app()->getWebsite($website);
19
+ $baseUrl = $website->getConfig('web/secure/base_url');
20
+ }
21
+ $helper = Mage::helper('connector');
22
+ $passcode = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DYNAMIC_CONTENT_PASSCODE, $website);
23
+ $orderId = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_LAST_ORDER_ID, $website);
24
+
25
+ if(!strlen($passcode)) $passcode = '[PLEASE SET UP A PASSCODE]';
26
+
27
+ $text = sprintf('%sconnector/shipping/updateguest/code/%s/order_id/@%s@', $baseUrl, $passcode, $orderId);
28
+ $element->setData('value', $text);
29
+
30
+ return parent::_getElementHtml($element);
31
+ }
32
+ }
app/code/community/Dotdigitalgroup/Email/Block/Basket.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Basket extends Mage_Core_Block_Template
4
+ {
5
+ protected $_quote;
6
+
7
+ /**
8
+ * Basket itmes.
9
+ *
10
+ * @return mixed
11
+ * @throws Exception
12
+ * @throws Mage_Core_Exception
13
+ */
14
+ public function getBasketItems()
15
+ {
16
+ $params = $this->getRequest()->getParams();
17
+
18
+ if (!isset($params['email']) && !isset($params['code']))
19
+ exit();
20
+ Mage::helper('connector')->auth($params['code']);
21
+
22
+ $email = $params['email'];
23
+
24
+ $customer = Mage::getModel('customer/customer');
25
+ $customer->setWebsiteId(Mage::app()->getWebsite()->getId())->loadByEmail($email);
26
+
27
+ //last active guest basket
28
+ $quoteModel = Mage::getResourceModel('sales/quote_collection')
29
+ ->addFieldToFilter('is_active', 1)
30
+ ->addFieldToFilter('items_count', array('gt' => 0))
31
+ ->addFieldToFilter('customer_email', $email)
32
+ ->setOrder('updated_at', 'DESC')
33
+ ->setPageSize(1);
34
+
35
+ $quoteModel = $quoteModel->getFirstItem();
36
+
37
+
38
+ //check for any quote for this email, don't want to render further
39
+ if (! $quoteModel->getId()) {
40
+ Mage::helper('connector')->log('no quote found for email : ' . $email);
41
+ exit();
42
+ }
43
+
44
+ $this->_quote = $quoteModel;
45
+
46
+ //Start environment emulation of the specified store
47
+ $storeId = $quoteModel->getStoreId();
48
+ $appEmulation = Mage::getSingleton('core/app_emulation');
49
+ $appEmulation->startEnvironmentEmulation($storeId);
50
+
51
+ return $quoteModel->getAllItems();
52
+ }
53
+
54
+ /**
55
+ * Grand total.
56
+ *
57
+ * @return mixed
58
+ */
59
+ public function getGrandTotal()
60
+ {
61
+ return $this->_quote->getGrandTotal();
62
+
63
+ }
64
+ }
app/code/{local → community}/Dotdigitalgroup/Email/Block/Coupon.php RENAMED
@@ -2,10 +2,15 @@
2
 
3
  class Dotdigitalgroup_Email_Block_Coupon extends Mage_Core_Block_Template
4
  {
 
 
 
 
 
5
  public function generateCoupon()
6
  {
7
  $params = $this->getRequest()->getParams();
8
- if(!isset($params['id']) || !isset($params['code']))
9
  exit();
10
  //coupon rule id
11
  $couponCodeId = $params['id'];
@@ -14,27 +19,23 @@ class Dotdigitalgroup_Email_Block_Coupon extends Mage_Core_Block_Template
14
  //authenticate
15
  Mage::helper('connector')->auth($authCode);
16
 
17
- if($couponCodeId){
18
 
19
  $rule = Mage::getModel('salesrule/rule')->load($couponCodeId);
20
  $generator = Mage::getModel('salesrule/coupon_massgenerator');
21
-
22
  $generator->setFormat( Mage_SalesRule_Helper_Coupon::COUPON_FORMAT_ALPHANUMERIC );
23
  $generator->setRuleId($couponCodeId);
24
  $generator->setUsesPerCoupon(1);
25
- $generator->setDash( 3 );
26
- $generator->setLength( 9);
27
- $generator->setPrefix( '' );
28
- $generator->setSuffix( '' );
29
-
30
  //set the generation settings
31
  $rule->setCouponCodeGenerator($generator);
32
- $rule->setCouponType( Mage_SalesRule_Model_Rule::COUPON_TYPE_AUTO );
33
-
34
  //generate the coupon
35
  $coupon = $rule->acquireCoupon();
36
  $couponCode = $coupon->getCode();
37
-
38
  //save the type of coupon
39
  $couponModel = Mage::getModel('salesrule/coupon')->loadByCode($couponCode);
40
  $couponModel->setType(Mage_SalesRule_Model_Rule::COUPON_TYPE_NO_COUPON);
2
 
3
  class Dotdigitalgroup_Email_Block_Coupon extends Mage_Core_Block_Template
4
  {
5
+ /**
6
+ * Generates the coupon code based on the code id.
7
+ * @return bool
8
+ * @throws Exception
9
+ */
10
  public function generateCoupon()
11
  {
12
  $params = $this->getRequest()->getParams();
13
+ if (!isset($params['id']) || !isset($params['code']))
14
  exit();
15
  //coupon rule id
16
  $couponCodeId = $params['id'];
19
  //authenticate
20
  Mage::helper('connector')->auth($authCode);
21
 
22
+ if ($couponCodeId) {
23
 
24
  $rule = Mage::getModel('salesrule/rule')->load($couponCodeId);
25
  $generator = Mage::getModel('salesrule/coupon_massgenerator');
 
26
  $generator->setFormat( Mage_SalesRule_Helper_Coupon::COUPON_FORMAT_ALPHANUMERIC );
27
  $generator->setRuleId($couponCodeId);
28
  $generator->setUsesPerCoupon(1);
29
+ $generator->setDash(3);
30
+ $generator->setLength(9);
31
+ $generator->setPrefix('');
32
+ $generator->setSuffix('');
 
33
  //set the generation settings
34
  $rule->setCouponCodeGenerator($generator);
35
+ $rule->setCouponType(Mage_SalesRule_Model_Rule::COUPON_TYPE_AUTO);
 
36
  //generate the coupon
37
  $coupon = $rule->acquireCoupon();
38
  $couponCode = $coupon->getCode();
 
39
  //save the type of coupon
40
  $couponModel = Mage::getModel('salesrule/coupon')->loadByCode($couponCode);
41
  $couponModel->setType(Mage_SalesRule_Model_Rule::COUPON_TYPE_NO_COUPON);
app/code/community/Dotdigitalgroup/Email/Block/Order.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Order extends Mage_Core_Block_Template
4
+ {
5
+
6
+ /**
7
+ * Prepare layout, set template and title.
8
+ *
9
+ * @return Mage_Core_Block_Abstract|void
10
+ */
11
+ protected function _prepareLayout()
12
+ {
13
+ if ($root = $this->getLayout()->getBlock('root')) {
14
+ $root->setTemplate('page/blank.phtml');
15
+ }
16
+ if ($headBlock = $this->getLayout()->getBlock('head')) {
17
+ $headBlock->setTitle($this->__('Order # %s', $this->getOrder()->getRealOrderId()));
18
+ }
19
+ }
20
+
21
+ /**
22
+ * Current Order.
23
+ *
24
+ * @return Mage_Core_Model_Abstract|mixed
25
+ */
26
+ public function getOrder()
27
+ {
28
+ $orderId = Mage::registry('order_id');
29
+ $order = Mage::registry('current_order');
30
+ if (! $orderId) {
31
+ $orderId = Mage::app()->getRequest()->getParam('order_id');
32
+ Mage::register('order_id', $orderId);
33
+ }
34
+ if (! $order) {
35
+ $order = Mage::getModel('sales/order')->load($orderId);
36
+ Mage::register('current_order', $order);
37
+ }
38
+
39
+ return $order;
40
+ }
41
+ }
app/code/community/Dotdigitalgroup/Email/Block/Order/Creditmemo.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Block_Order_Creditmemo extends Mage_Sales_Block_Order_Creditmemo_Items
3
+ {
4
+ /**
5
+ * Prepare layout.
6
+ *
7
+ * @return Mage_Core_Block_Abstract|void
8
+ */
9
+ protected function _prepareLayout()
10
+ {
11
+ if ($root = $this->getLayout()->getBlock('root')) {
12
+ $root->setTemplate('page/blank.phtml');
13
+ }
14
+ }
15
+
16
+ /**
17
+ * Get current Order.
18
+ * @return Mage_Core_Model_Abstract|Mage_Sales_Model_Order|mixed
19
+ */
20
+ public function getOrder()
21
+ {
22
+ $orderId = Mage::registry('order_id');
23
+ $order = Mage::registry('current_order');
24
+ if (! $orderId) {
25
+ $orderId = Mage::app()->getRequest()->getParam('order_id');
26
+ Mage::register('order_id', $orderId);
27
+ }
28
+ if (! $order) {
29
+ $order = Mage::getModel('sales/order')->load($orderId);
30
+ Mage::register('current_order', $order);
31
+ }
32
+ if (! $order->hasCreditmemos()) {
33
+ Mage::helper('connector')->log('TE - no creditmemo for order : '. $orderId);
34
+ exit;
35
+ }
36
+
37
+ return $order;
38
+ }
39
+
40
+ /**
41
+ * Order items.
42
+ * @return mixed
43
+ */
44
+ public function getCreditmemoItems()
45
+ {
46
+ return Mage::registry('current_order')->getItemsCollection();
47
+ }
48
+ }
app/code/community/Dotdigitalgroup/Email/Block/Order/Invoice.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Block_Order_Invoice extends Mage_Sales_Block_Order_Invoice_Items
3
+ {
4
+ /**
5
+ * Prepare layout.
6
+ * @return Mage_Core_Block_Abstract|void
7
+ */
8
+ protected function _prepareLayout()
9
+ {
10
+ if ($root = $this->getLayout()->getBlock('root')) {
11
+ $root->setTemplate('page/blank.phtml');
12
+ }
13
+ }
14
+
15
+ /**
16
+ * Get current order.
17
+ * @return Mage_Core_Model_Abstract|Mage_Sales_Model_Order|mixed
18
+ */
19
+ public function getOrder()
20
+ {
21
+ $orderId = Mage::registry('order_id');
22
+ $order = Mage::registry('current_order');
23
+ if (! $orderId) {
24
+ $orderId = Mage::app()->getRequest()->getParam('order_id');
25
+ Mage::register('order_id', $orderId);
26
+ }
27
+ if (! $order) {
28
+ $order = Mage::getModel('sales/order')->load($orderId);
29
+ Mage::register('current_order', $order);
30
+ }
31
+ if (! $order->hasInvoices()) {
32
+ Mage::helper('connector')->log('TE - no invoice for order : '. $orderId);
33
+ exit;
34
+ }
35
+
36
+ return $order;
37
+ }
38
+
39
+ }
app/code/community/Dotdigitalgroup/Email/Block/Order/Shipping.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Block_Order_Shipping extends Mage_Sales_Block_Order_Creditmemo_Items
3
+ {
4
+ /**
5
+ * Prepare layout.
6
+ * @return Mage_Core_Block_Abstract|void
7
+ */
8
+ protected function _prepareLayout()
9
+ {
10
+ if ($root = $this->getLayout()->getBlock('root')) {
11
+ $root->setTemplate('page/blank.phtml');
12
+ }
13
+ }
14
+
15
+ /**
16
+ * Get current order.
17
+ * @return Mage_Core_Model_Abstract|Mage_Sales_Model_Order|mixed
18
+ */
19
+ public function getOrder()
20
+ {
21
+ $orderId = Mage::registry('order_id');
22
+ $order = Mage::registry('current_order');
23
+ if (! $orderId) {
24
+ $orderId = Mage::app()->getRequest()->getParam('order_id');
25
+ Mage::register('order_id', $orderId);
26
+ }
27
+ if (! $order) {
28
+ $order = Mage::getModel('sales/order')->load($orderId);
29
+ Mage::register('current_order', $order);
30
+ }
31
+ if (! $order->hasShipments()) {
32
+ Mage::helper('connector')->log('TE - no shipments for order : '. $orderId);
33
+ exit;
34
+ }
35
+
36
+ return $order;
37
+
38
+ }
39
+
40
+ /**
41
+ * Order shipments.
42
+ * @return mixed
43
+ */
44
+ public function getShipment()
45
+ {
46
+ return $shipment = Mage::registry('current_order')->getShipmentsCollection()->getFirstItem();
47
+ }
48
+ }
app/code/community/Dotdigitalgroup/Email/Block/Products.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Products extends Mage_Core_Block_Template
4
+ {
5
+ /**
6
+ * Prepare layout, set template.
7
+ *
8
+ * @return Mage_Core_Block_Abstract|void
9
+ */
10
+ protected function _prepareLayout()
11
+ {
12
+ if ($root = $this->getLayout()->getBlock('root')) {
13
+ $root->setTemplate('page/blank.phtml');
14
+ }
15
+ }
16
+
17
+ /**
18
+ * get the products to display for table
19
+ */
20
+ public function getRecommendedProducts()
21
+ {
22
+ $productsToDisplay = array();
23
+ $orderId = $this->getRequest()->getParam('order', false);
24
+ $mode = $this->getRequest()->getParam('mode', false);
25
+ if ($orderId && $mode) {
26
+ $orderModel = Mage::getModel('sales/order')->load($orderId);
27
+ if ($orderModel->getId()) {
28
+ $storeId = $orderModel->getStoreId();
29
+ $appEmulation = Mage::getSingleton('core/app_emulation');
30
+ $appEmulation->startEnvironmentEmulation($storeId);
31
+ //order products
32
+ $productRecommended = Mage::getModel('email_connector/dynamic_recommended', $orderModel);
33
+ $productRecommended->setMode($mode);
34
+
35
+ //get the order items recommendations
36
+ $productsToDisplay = $productRecommended->getProducts();
37
+ }
38
+ }
39
+
40
+ return $productsToDisplay;
41
+ }
42
+
43
+
44
+ /**
45
+ * Price html block.
46
+ *
47
+ * @param $product
48
+ *
49
+ * @return string
50
+ */
51
+ public function getPriceHtml($product)
52
+ {
53
+ $this->setTemplate('connector/price.phtml');
54
+ $this->setProduct($product);
55
+ return $this->toHtml();
56
+ }
57
+
58
+ /**
59
+ * Display type mode.
60
+ * @return mixed|string
61
+ */
62
+ public function getDisplayType()
63
+ {
64
+ return Mage::helper('connector/recommended')->getDisplayType();
65
+
66
+ }
67
+ }
app/code/community/Dotdigitalgroup/Email/Block/Recommended/Bestsellers.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Recommended_Bestsellers extends Mage_Core_Block_Template
4
+ {
5
+
6
+ /**
7
+ * Prepare layout.
8
+ * @return Mage_Core_Block_Abstract|void
9
+ */
10
+ protected function _prepareLayout()
11
+ {
12
+ if ($root = $this->getLayout()->getBlock('root')) {
13
+ $root->setTemplate('page/blank.phtml');
14
+ }
15
+ }
16
+
17
+ /**
18
+ * Get product collection.
19
+ * @return array
20
+ * @throws Exception
21
+ */
22
+ public function getLoadedProductCollection()
23
+ {
24
+ $productsToDisplay = array();
25
+ $mode = $this->getRequest()->getActionName();
26
+ $limit = Mage::helper('connector/recommended')->getDisplayLimitByMode($mode);
27
+ $from = Mage::helper('connector/recommended')->getTimeFromConfig($mode);
28
+ $to = Zend_Date::now()->toString(Zend_Date::ISO_8601);
29
+
30
+ $productCollection = Mage::getResourceModel('reports/product_collection')
31
+ ->addOrderedQty($from, $to)
32
+ ->addAttributeToSelect(array('name', 'price', 'small_image'))
33
+ ->setPageSize($limit)
34
+ ->setOrder('ordered_qty', 'desc');
35
+
36
+ foreach ($productCollection as $_product) {
37
+ $productId = $_product->getId();
38
+ $product = Mage::getModel('catalog/product')->load($productId);
39
+ if ($product->isSalable())
40
+ $productsToDisplay[] = $product;
41
+ }
42
+
43
+
44
+ return $productsToDisplay;
45
+ }
46
+
47
+ /**
48
+ * Display type mode.
49
+ *
50
+ * @return mixed|string
51
+ */
52
+ public function getMode()
53
+ {
54
+ return Mage::helper('connector/recommended')->getDisplayType();
55
+
56
+ }
57
+
58
+ /**
59
+ * Price html.
60
+ * @param $product
61
+ *
62
+ * @return string
63
+ */
64
+ public function getPriceHtml($product)
65
+ {
66
+ $this->setTemplate('connector/product/price.phtml');
67
+ $this->setProduct($product);
68
+ return $this->toHtml();
69
+ }
70
+
71
+ }
app/code/community/Dotdigitalgroup/Email/Block/Recommended/Mostviewed.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Recommended_Mostviewed extends Mage_Core_Block_Template
4
+ {
5
+
6
+ /**
7
+ * Prepare layout.
8
+ * @return Mage_Core_Block_Abstract|void
9
+ */
10
+ protected function _prepareLayout()
11
+ {
12
+ if ($root = $this->getLayout()->getBlock('root')) {
13
+ $root->setTemplate('page/blank.phtml');
14
+ }
15
+ }
16
+
17
+ /**
18
+ * Get product collection.
19
+ * @return array
20
+ * @throws Exception
21
+ */
22
+ public function getLoadedProductCollection()
23
+ {
24
+ $productsToDisplay = array();
25
+ $mode = $this->getRequest()->getActionName();
26
+ $limit = Mage::helper('connector/recommended')->getDisplayLimitByMode($mode);
27
+ $from = Mage::helper('connector/recommended')->getTimeFromConfig($mode);
28
+ //@todo localize this value
29
+ $to = Zend_Date::now()->toString(Zend_Date::ISO_8601);
30
+
31
+ $productCollection = Mage::getResourceModel('reports/product_collection')
32
+ ->addViewsCount($from, $to)
33
+ ->setPageSize($limit);
34
+
35
+ foreach ($productCollection as $_product) {
36
+ $productId = $_product->getId();
37
+ $product = Mage::getModel('catalog/product')->load($productId);
38
+ if($product->isSalable())
39
+ $productsToDisplay[] = $product;
40
+ }
41
+
42
+ return $productsToDisplay;
43
+ }
44
+
45
+
46
+ /**
47
+ * Display mode type.
48
+ * @return mixed|string
49
+ */
50
+ public function getMode()
51
+ {
52
+ return Mage::helper('connector/recommended')->getDisplayType();
53
+ }
54
+
55
+ /**
56
+ * @param $product
57
+ *
58
+ * @return string
59
+ */
60
+ public function getPriceHtml($product)
61
+ {
62
+ $this->setTemplate('connector/product/price.phtml');
63
+ $this->setProduct($product);
64
+ return $this->toHtml();
65
+ }
66
+ }
app/code/community/Dotdigitalgroup/Email/Block/Recommended/Products.php ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Recommended_Products extends Mage_Core_Block_Template
4
+ {
5
+ /**
6
+ * Prepare layout, set the template.
7
+ * @return Mage_Core_Block_Abstract|void
8
+ */
9
+ protected function _prepareLayout()
10
+ {
11
+ if ($root = $this->getLayout()->getBlock('root')) {
12
+ $root->setTemplate('page/blank.phtml');
13
+ }
14
+ }
15
+
16
+ /**
17
+ * get the products to display for table
18
+ */
19
+ public function getLoadedProductCollection()
20
+ {
21
+ //products to be diplayd for recommended pages
22
+ $productsToDisplay = array();
23
+ $orderId = $this->getRequest()->getParam('order_id');
24
+ //display mode based on the action name
25
+ $mode = $this->getRequest()->getActionName();
26
+ $orderModel = Mage::getModel('sales/order')->load($orderId);
27
+ //number of product items to be displayed
28
+ $limit = Mage::helper('connector/recommended')->getDisplayLimitByMode($mode);
29
+ $orderItems = $orderModel->getAllItems();
30
+ $numItems = count($orderItems);
31
+
32
+ //no product found to display
33
+ if ($numItems == 0 || ! $limit) {
34
+ return array();
35
+ }elseif (count($orderItems) > $limit) {
36
+ $maxPerChild = 1;
37
+ } else {
38
+ $maxPerChild = number_format($limit / count($orderItems));
39
+ }
40
+
41
+ Mage::helper('connector')->log('DYNAMIC PRODUCTS : limit ' . $limit . ' products : ' . $numItems . ', max per child : '. $maxPerChild);
42
+
43
+ foreach ($orderItems as $item) {
44
+ $i = 0;
45
+ $productId = $item->getProductId();
46
+ //parent product
47
+ $productModel = Mage::getModel('catalog/product')->load($productId);
48
+ //check for product exists
49
+ if ($productModel->getId()) {
50
+ //get single product for current mode
51
+ $recommendedProducts = $this->_getRecommendedProduct($productModel, $mode);
52
+ foreach ($recommendedProducts as $product) {
53
+ //load child product
54
+ $product = Mage::getModel('catalog/product')->load($product->getId());
55
+ //check if still exists
56
+ if ($product->getId() && count($productsToDisplay) < $limit && $i <= $maxPerChild && $product->isSaleable() && !$product->getParentId()) {
57
+ //we have a product to display
58
+ $productsToDisplay[$product->getId()] = $product;
59
+ $i++;
60
+ }
61
+ }
62
+ }
63
+ //have reached the limit don't loop for more
64
+ if (count($productsToDisplay) == $limit) {
65
+ break;
66
+ }
67
+ }
68
+
69
+ //check for more space to fill up the table with fallback products
70
+ if (count($productsToDisplay) < $limit) {
71
+ $fallbackIds = Mage::helper('connector/recommended')->getFallbackIds();
72
+
73
+ foreach ($fallbackIds as $productId) {
74
+ $product = Mage::getModel('catalog/product')->load($productId);
75
+ if($product->isSaleable())
76
+ $productsToDisplay[$product->getId()] = $product;
77
+ //stop the limit was reached
78
+ if (count($productsToDisplay) == $limit) {
79
+ break;
80
+ }
81
+ }
82
+ }
83
+
84
+ Mage::helper('connector')->log('loaded product to display ' . count($productsToDisplay));
85
+ return $productsToDisplay;
86
+ }
87
+
88
+ /**
89
+ * Product related items.
90
+ *
91
+ * @param Mage_Catalog_Model_Product $productModel
92
+ * @param $mode
93
+ *
94
+ * @return array
95
+ */
96
+ private function _getRecommendedProduct(Mage_Catalog_Model_Product $productModel, $mode)
97
+ {
98
+ //array of products to display
99
+ $products = array();
100
+ switch($mode){
101
+ case 'related':
102
+ $products = $productModel->getRelatedProducts();
103
+ break;
104
+ case 'upsell':
105
+ $products = $productModel->getUpSellProducts();
106
+ break;
107
+ case 'crosssell':
108
+ $products = $productModel->getCrossSellProducts();
109
+ break;
110
+
111
+ }
112
+
113
+ return $products;
114
+ }
115
+
116
+ /**
117
+ * Diplay mode type.
118
+ *
119
+ * @return mixed|string
120
+ */
121
+ public function getMode()
122
+ {
123
+ return Mage::helper('connector/recommended')->getDisplayType();
124
+
125
+ }
126
+
127
+ /**
128
+ * Number of the colums.
129
+ * @return int|mixed
130
+ * @throws Exception
131
+ */
132
+ public function getColumnCount()
133
+ {
134
+ return Mage::helper('connector/recommended')->getDisplayLimitByMode($this->getRequest()->getActionName());
135
+ }
136
+
137
+ /**
138
+ * Price html.
139
+ * @param $product
140
+ *
141
+ * @return string
142
+ */
143
+ public function getPriceHtml($product)
144
+ {
145
+ $this->setTemplate('connector/product/price.phtml');
146
+ $this->setProduct($product);
147
+ return $this->toHtml();
148
+ }
149
+ }
app/code/community/Dotdigitalgroup/Email/Block/Recommended/Push.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Recommended_Push extends Mage_Core_Block_Template
4
+ {
5
+ /**
6
+ * Prepare layout, set template.
7
+ * @return Mage_Core_Block_Abstract|void
8
+ */
9
+ protected function _prepareLayout()
10
+ {
11
+ if ($root = $this->getLayout()->getBlock('root')) {
12
+ $root->setTemplate('page/blank.phtml');
13
+ }
14
+ }
15
+
16
+ /**
17
+ * get the products to display for table
18
+ */
19
+ public function getLoadedProductCollection()
20
+ {
21
+ $productsToDisplay = array();
22
+ $mode = $this->getRequest()->getActionName();
23
+ $limit = Mage::helper('connector/recommended')->getDisplayLimitByMode($mode);
24
+
25
+ $productIds = Mage::helper('connector/recommended')->getProductPushIds();
26
+
27
+ $productCollection = Mage::getResourceModel('catalog/product_collection')
28
+ ->addAttributeToFilter('entity_id', array('in' => $productIds))
29
+ ->setPageSize($limit)
30
+ ;
31
+ foreach ($productCollection as $_product) {
32
+ $productId = $_product->getId();
33
+ $product = Mage::getModel('catalog/product')->load($productId);
34
+ if($product->isSaleable())
35
+ $productsToDisplay[] = $product;
36
+
37
+ }
38
+
39
+ return $productsToDisplay;
40
+
41
+ }
42
+
43
+ /**
44
+ * Display type mode.
45
+ *
46
+ * @return mixed|string
47
+ */
48
+ public function getMode()
49
+ {
50
+ return Mage::helper('connector/recommended')->getDisplayType();
51
+
52
+ }
53
+
54
+ /**
55
+ * Price html.
56
+ * @param $product
57
+ *
58
+ * @return string
59
+ */
60
+ public function getPriceHtml($product)
61
+ {
62
+ $this->setTemplate('connector/product/price.phtml');
63
+ $this->setProduct($product);
64
+ return $this->toHtml();
65
+ }
66
+ }
app/code/community/Dotdigitalgroup/Email/Block/Recommended/Recentlyviewed.php ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Recommended_Recentlyviewed extends Mage_Core_Block_Template
4
+ {
5
+
6
+ /**
7
+ * Prepare layout, set template.
8
+ * @return Mage_Core_Block_Abstract|void
9
+ */
10
+ protected function _prepareLayout()
11
+ {
12
+ if ($root = $this->getLayout()->getBlock('root')) {
13
+ $root->setTemplate('page/blank.phtml');
14
+ }
15
+ }
16
+
17
+ /**
18
+ * Products collection.
19
+ *
20
+ * @return array
21
+ * @throws Exception
22
+ */
23
+ public function getLoadedProductCollection()
24
+ {
25
+ $productsToDisplay = array();
26
+ $mode = $this->getRequest()->getActionName();
27
+ $customerId = $this->getRequest()->getParam('customer_id');
28
+ $limit = Mage::helper('connector/recommended')->getDisplayLimitByMode($mode);
29
+ //login customer to receive the recent products
30
+ $session = Mage::getSingleton('customer/session');
31
+ $isLoggedIn = $session->loginById($customerId);
32
+ /** @var Mage_Reports_Block_Product_Viewed $collection */
33
+ $collection = Mage::getSingleton('Mage_Reports_Block_Product_Viewed');
34
+ $items = $collection->getItemsCollection()
35
+ ->setPageSize($limit);
36
+ Mage::helper('connector')->log('Recentlyviewed customer : ' . $customerId . ', mode ' . $mode . ', limit : ' . $limit .
37
+ ', items found : ' . count($items) . ', is customer logged in : ' . $isLoggedIn . ', products :' . count($productsToDisplay));
38
+ foreach ($items as $product) {
39
+ $product = Mage::getModel('catalog/product')->load($product->getId());
40
+ if($product->isSalable())
41
+ $productsToDisplay[$product->getId()] = $product;
42
+
43
+ }
44
+ $session->logout();
45
+
46
+ return $productsToDisplay;
47
+ }
48
+
49
+
50
+ /**
51
+ * Display mode type.
52
+ *
53
+ * @return mixed|string
54
+ */
55
+ public function getMode()
56
+ {
57
+ return Mage::helper('connector/recommended')->getDisplayType();
58
+
59
+ }
60
+
61
+ /**
62
+ * Price html.
63
+ * @param $product
64
+ *
65
+ * @return string
66
+ */
67
+ public function getPriceHtml($product)
68
+ {
69
+ $this->setTemplate('connector/product/price.phtml');
70
+ $this->setProduct($product);
71
+ return $this->toHtml();
72
+ }
73
+ }
app/code/community/Dotdigitalgroup/Email/Helper/Config.php ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Helper_Config
4
+ {
5
+ const MODULE_NAME = 'Dotdigitalgroup_Email';
6
+
7
+ /**
8
+ * API SECTION.
9
+ */
10
+ //API settings
11
+ const XML_PATH_CONNECTOR_API_ENABLED = 'connector_api_credentials/api/enabled';
12
+ const XML_PATH_CONNECTOR_API_USERNAME = 'connector_api_credentials/api/username';
13
+ const XML_PATH_CONNECTOR_API_PASSWORD = 'connector_api_credentials/api/password';
14
+ const XML_PATH_CONNECTOR_CLIENT_ID = 'connector_api_credentials/oauth/client_id';
15
+ const XML_PATH_CONNECTOR_CLIENT_SECRET_ID = 'connector_api_credentials/oauth/client_key';
16
+
17
+ /**
18
+ * SMS SECTION.
19
+ */
20
+ //enabled
21
+ const XML_PATH_CONNECTOR_SMS_ENABLED_1 = 'connector_sms/sms_one/enabled';
22
+ const XML_PATH_CONNECTOR_SMS_ENABLED_2 = 'connector_sms/sms_two/enabled';
23
+ const XML_PATH_CONNECTOR_SMS_ENABLED_3 = 'connector_sms/sms_three/enabled';
24
+ const XML_PATH_CONNECTOR_SMS_ENABLED_4 = 'connector_sms/sms_four/enabled';
25
+ //status
26
+ const XML_PATH_CONNECTOR_SMS_STATUS_1 = 'connector_sms/sms_one/status';
27
+ const XML_PATH_CONNECTOR_SMS_STATUS_2 = 'connector_sms/sms_two/status';
28
+ const XML_PATH_CONNECTOR_SMS_STATUS_3 = 'connector_sms/sms_three/status';
29
+ const XML_PATH_CONNECTOR_SMS_STATUS_4 = 'connector_sms/sms_four/status';
30
+ //message
31
+ const XML_PATH_CONNECTOR_SMS_MESSAGE_1 = 'connector_sms/sms_one/message';
32
+ const XML_PATH_CONNECTOR_SMS_MESSAGE_2 = 'connector_sms/sms_two/message';
33
+ const XML_PATH_CONNECTOR_SMS_MESSAGE_3 = 'connector_sms/sms_three/message';
34
+ const XML_PATH_CONNECTOR_SMS_MESSAGE_4 = 'connector_sms/sms_four/message';
35
+
36
+ /**
37
+ * SYNC SECTION.
38
+ */
39
+ const XML_PATH_CONNECTOR_SYNC_CONTACT_ENABLED = 'connector_sync_settings/sync/contact_enabled';
40
+ const XML_PATH_CONNECTOR_SYNC_SUBSCRIBER_ENABLED = 'connector_sync_settings/sync/subscriber_enabled';
41
+ const XML_PATH_CONNECTOR_SYNC_ORDER_ENABLED = 'connector_sync_settings/sync/order_enabled';
42
+ const XML_PATH_CONNECTOR_SYNC_WISHLIST_ENABLED = 'connector_sync_settings/sync/wishlist_enabled';
43
+
44
+ const XML_PATH_CONNECTOR_CUSTOMERS_ADDRESS_BOOK_ID = 'connector_sync_settings/address_book/customers';
45
+ const XML_PATH_CONNECTOR_SUBSCRIBERS_ADDRESS_BOOK_ID = 'connector_sync_settings/address_book/subscribers';
46
+ const XML_PATH_CONNECTOR_GUEST_ADDRESS_BOOK_ID = 'connector_sync_settings/address_book/guests';
47
+ // Mapping
48
+ const XML_PATH_CONNECTOR_MAPPING_LAST_ORDER_ID = 'connector_data_mapping/customer_data/last_order_id';
49
+ const XML_PATH_CONNECTOR_MAPPING_CUSTOMER_ID = 'connector_data_mapping/customer_data/customer_id';
50
+ const XML_PATH_CONNECTOR_MAPPING_CUSTOM_DATAFIELDS = 'connector_data_mapping/customer_data/custom_attributes';
51
+ const XML_PATH_CONNECTOR_MAPPING_CUSTOMER_STORENAME = 'connector_data_mapping/customer_data/store_name';
52
+ const XML_PATH_CONNECTOR_MAPPING_CUSTOMER_TOTALREFUND = 'connector_data_mapping/customer_data/total_refund';
53
+ const XML_PATH_CONNECTOR_MAPPING_SWEETTOOTH_ACTIVE = 'connector_data_mapping/sweet_tooth/active';
54
+
55
+
56
+ /**
57
+ * Abandoned Carts.
58
+ */
59
+ const XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CARTS_ENABLED_1 = 'connector_lost_baskets/customers/enabled_1';
60
+ const XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CAMPAIGN_1 = 'connector_lost_baskets/customers/campaign_1';
61
+ const XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CARTS_ENABLED_2 = 'connector_lost_baskets/customers/enabled_2';
62
+ const XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CAMPAIGN_2 = 'connector_lost_baskets/customers/campaign_2';
63
+ const XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CARTS_ENABLED_3 = 'connector_lost_baskets/customers/enabled_3';
64
+ const XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CAMPAIGN_3 = 'connector_lost_baskets/customers/campaign_3';
65
+ const XML_PATH_CONNECTOR_GUEST_ABANDONED_CARTS_ENABLED_1 = 'connector_lost_baskets/guests/enabled_1';
66
+ const XML_PATH_CONNECTOR_GUEST_ABANDONED_CAMPAIGN_1 = 'connector_lost_baskets/guests/campaign_1';
67
+ const XML_PATH_CONNECTOR_GUEST_ABANDONED_CARTS_ENABLED_2 = 'connector_lost_baskets/guests/enabled_2';
68
+ const XML_PATH_CONNECTOR_GUEST_ABANDONED_CAMPAIGN_2 = 'connector_lost_baskets/guests/campaign_2';
69
+ const XML_PATH_CONNECTOR_GUEST_ABANDONED_CARTS_ENABLED_3 = 'connector_lost_baskets/guests/enabled_3';
70
+ const XML_PATH_CONNECTOR_GUEST_ABANDONED_CAMPAIGN_3 = 'connector_lost_baskets/guests/campaign_3';
71
+
72
+ /**
73
+ * Datafields Mapping.
74
+ */
75
+ const XML_PATH_CONNECTOR_CUSTOMER_ID = 'connector_data_mapping/customer_data/customer_id';
76
+ const XML_PATH_CONNECTOR_CUSTOMER_FIRSTNAME = 'connector_data_mapping/customer_data/firstname';
77
+ const XML_PATH_CONNECTOR_CUSTOMER_LASTNAME = 'connector_data_mapping/customer_data/lastname';
78
+ const XML_PATH_CONNECTOR_CUSTOMER_DOB = 'connector_data_mapping/customer_data/dob';
79
+ const XML_PATH_CONNECTOR_CUSTOMER_GENDER = 'connector_data_mapping/customer_data/gender';
80
+ const XML_PATH_CONNECTOR_CUSTOMER_WEBSITE_NAME = 'connector_data_mapping/customer_data/website_name';
81
+ const XML_PATH_CONNECTOR_CUSTOMER_STORE_NAME = 'connector_data_mapping/customer_data/store_name';
82
+ const XML_PATH_CONNECTOR_CUSTOMER_CREATED_AT = 'connector_data_mapping/customer_data/created_at';
83
+ const XML_PATH_CONNECTOR_CUSTOMER_LAST_LOGGED_DATE = 'connector_data_mapping/customer_data/last_logged_date';
84
+ const XML_PATH_CONNECTOR_CUSTOMER_CUSTOMER_GROUP = 'connector_data_mapping/customer_data/customer_group';
85
+ const XML_PATH_CONNECTOR_CUSTOMER_REVIEW_COUNT = 'connector_data_mapping/customer_data/review_count';
86
+ const XML_PATH_CONNECTOR_CUSTOMER_LAST_REVIEW_DATE = 'connector_data_mapping/customer_data/last_review_date';
87
+ const XML_PATH_CONNECTOR_CUSTOMER_BILLING_ADDRESS_1 = 'connector_data_mapping/customer_data/billing_address_1';
88
+ const XML_PATH_CONNECTOR_CUSTOMER_BILLING_ADDRESS_2 = 'connector_data_mapping/customer_data/billing_address_2';
89
+ const XML_PATH_CONNECTOR_CUSTOMER_BILLING_CITY = 'connector_data_mapping/customer_data/billing_city';
90
+ const XML_PATH_CONNECTOR_CUSTOMER_BILLING_STATE = 'connector_data_mapping/customer_data/billing_state';
91
+ const XML_PATH_CONNECTOR_CUSTOMER_BILLING_COUNTRY = 'connector_data_mapping/customer_data/billing_country';
92
+ const XML_PATH_CONNECTOR_CUSTOMER_BILLING_POSTCODE = 'connector_data_mapping/customer_data/billing_postcode';
93
+ const XML_PATH_CONNECTOR_CUSTOMER_BILLING_TELEPHONE = 'connector_data_mapping/customer_data/billing_telephone';
94
+ const XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_ADDRESS_1 = 'connector_data_mapping/customer_data/delivery_address_1';
95
+ const XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_ADDRESS_2 = 'connector_data_mapping/customer_data/delivery_address_2';
96
+ const XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_CITY = 'connector_data_mapping/customer_data/delivery_city';
97
+ const XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_STATE = 'connector_data_mapping/customer_data/delivery_state';
98
+ const XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_COUNTRY = 'connector_data_mapping/customer_data/delivery_country';
99
+ const XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_POSTCODE = 'connector_data_mapping/customer_data/delivery_postcode';
100
+ const XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_TELEPHONE = 'connector_data_mapping/customer_data/delivery_telephone';
101
+ const XML_PATH_CONNECTOR_CUSTOMER_TOTAL_NUMBER_ORDER = 'connector_data_mapping/customer_data/number_of_orders';
102
+ const XML_PATH_CONNECTOR_CUSTOMER_AOV = 'connector_data_mapping/customer_data/average_order_value';
103
+ const XML_PATH_CONNECTOR_CUSTOMER_TOTAL_SPEND = 'connector_data_mapping/customer_data/total_spend';
104
+ const XML_PATH_CONNECTOR_CUSTOMER_LAST_ORDER_DATE = 'connector_data_mapping/customer_data/last_order_date';
105
+ const XML_PATH_CONNECTOR_CUSTOMER_LAST_ORDER_ID = 'connector_data_mapping/customer_data/last_order_id';
106
+ const XML_PATH_CONNECTOR_CUSTOMER_TOTAL_REFUND = 'connector_data_mapping/customer_data/total_refund';
107
+
108
+ // Dynamic
109
+ const XML_PATH_CONNECTOR_DYNAMIC_CONTENT_PASSCODE = 'connector_dynamic_content/external_dynamic_content_urls/passcode';
110
+
111
+ /**
112
+ * ADVANCED SECTION.
113
+ */
114
+ const XML_PATH_CONNECTOR_ADVANCED_DEBUG_ENABLED = 'connector_advanced_settings/admin/debug_enabled';
115
+ const XML_PATH_CONNECTOR_SYNC_LIMIT = 'connector_advanced_settings/admin/batch_size';
116
+ const XML_PATH_CONNECTOR_RESOURCE_ALLOCATION = 'connector_advanced_settings/admin/memory_limit';
117
+ const XML_PATH_CONNECTOR_TRANSACTIONAL_DATA_SYNC_LIMIT = 'connector_advanced_settings/sync_limits/orders';
118
+ const XML_PATH_CONNECTOR_TRANSACTIONAL_STYLING = 'connector_advanced_settings/admin/inline_styling';
119
+ const XML_PATH_CONNECTOR_RECOMMENDED_STYLING = 'connector_advanced_settings/admin/recommended_inline';
120
+ const XML_PATH_CONNECTOR_SYNC_ORDER_STATUS = 'connector_advanced_settings/sync_limits/order_statuses';
121
+ const XML_PATH_RAYGUN_APPLICATION_CODE = 'connector_advanced_settings/admin/raygun_code';
122
+ const XML_PATH_CONNECTOR_FEED_ENABLED = 'connector_advanced_settings/admin/feed_enabled';
123
+ const XML_PATH_CONNECTOR_FEED_URL = 'connector_advanced_settings/admin/feed_url';
124
+ const XML_PATH_CONNECTOR_FEED_FREQUENCY = 'connector_advanced_settings/admin/frequency';
125
+ const XML_PATH_CONNECTOR_FEED_USE_HTTPS = 'connector_advanced_settings/admin/use_https';
126
+ const XML_PATH_CONNECTOR_ABANDONED_CART_LIMIT = 'connector_advanced_settings/abandoned_cart/limits';
127
+ const XML_PATH_CONNECTOR_ABANDONED_CART_SHELL = 'connector_advanced_settings/abandoned_cart/shell';
128
+ const XML_PATH_CONNECTOR_SYNC_ORDER_DELETE = 'connector_advanced_settings/sync_limits/order_delete';
129
+ const XML_PATH_CONNECTOR_DEBUG_API_CALLS = 'connector_advanced_settings/admin/debug_api_calls';
130
+
131
+ /**
132
+ * Automation studio.
133
+ */
134
+ const XML_PATH_CONNECTOR_AUTOMATION_STUDIO_SUBSCRIBER = 'connector_automation_studio/automation/subscriber_automation';
135
+ const XML_PATH_CONNECTOR_AUTOMATION_STUDIO_CUSTOMER = 'connector_automation_studio/automation/customer_automation';
136
+
137
+ /**
138
+ * ROI SECTION.
139
+ */
140
+ const XML_PATH_CONNECTOR_ROI_TRACKING_ENABLED = 'connector_roi_tracking/roi_tracking/enabled';
141
+ const XML_PATH_CONNECTOR_PAGE_TRACKING_ENABLED = 'connector_roi_tracking/page_tracking/enabled';
142
+
143
+ /**
144
+ * OAUTH
145
+ */
146
+ const API_CONNECTOR_URL_AUTHORISE = 'https://my.dotmailer.com/OAuth2/authorise.aspx?';
147
+ const API_CONNECTOR_URL_TOKEN = 'https://my.dotmailer.com/OAuth2/Tokens.ashx';
148
+ const API_CONNECTOR_URL_LOG_USER = 'https://my.dotmailer.com/?oauthtoken=';
149
+
150
+ /**
151
+ * Email Config.
152
+ */
153
+ const CONNECTOR_EMAIL_CONFIG_LAST_RUN = 'connector_api_last_call';
154
+ const CONNECTOR_EMAIL_CONFIG_HOUR_TRIGGER = 'connector_api_hour_trigger';
155
+ const CONNECTOR_FEED_LAST_CHECK_TIME = 'connector_feed_last_check_time';
156
+
157
+
158
+ /**
159
+ * Transactional Emails.
160
+ */
161
+ const XML_PATH_TRANSACTIONAL_API_ENABLED = 'connector_transactional_emails/credentials/enabled';
162
+
163
+ }
app/code/community/Dotdigitalgroup/Email/Helper/Data.php ADDED
@@ -0,0 +1,480 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+
6
+ public function isEnabled($website = 0)
7
+ {
8
+ $website = Mage::app()->getWebsite($website);
9
+ return (bool)$website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED);
10
+ }
11
+
12
+ /**
13
+ * @param int/object $website
14
+ * @return mixed
15
+ */
16
+ public function getApiUsername($website = 0)
17
+ {
18
+ $website = Mage::app()->getWebsite($website);
19
+
20
+ return $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_USERNAME);
21
+ }
22
+
23
+ public function getApiPassword($website = 0)
24
+ {
25
+ $website = Mage::app()->getWebsite($website);
26
+
27
+ return $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_PASSWORD);
28
+ }
29
+
30
+ public function auth($authRequest)
31
+ {
32
+ if ($authRequest != Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DYNAMIC_CONTENT_PASSCODE)) {
33
+ $this->log('Authenication failed : ' . $authRequest);
34
+ $this->getRaygunClient()->Send('Authinication failed with code :' . $authRequest);
35
+ exit();
36
+ }
37
+ return true;
38
+ }
39
+
40
+ public function getMappedCustomerId()
41
+ {
42
+ return Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_CUSTOMER_ID);
43
+ }
44
+
45
+ public function getMappedOrderId()
46
+ {
47
+ return Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_LAST_ORDER_ID);
48
+ }
49
+
50
+ public function getPasscode()
51
+ {
52
+ return Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DYNAMIC_CONTENT_PASSCODE);
53
+ }
54
+
55
+ public function getLastOrderId()
56
+ {
57
+ return Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_LAST_ORDER_ID);
58
+
59
+ }
60
+
61
+ public function log($data, $level = Zend_Log::DEBUG, $filename = 'api.log')
62
+ {
63
+ if ($this->getDebugEnabled()) {
64
+ $filename = 'connector_' . $filename;
65
+
66
+ Mage::log($data, $level, $filename, $force = true);
67
+ }
68
+ }
69
+
70
+ public function getDebugEnabled()
71
+ {
72
+ return (bool) Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_ADVANCED_DEBUG_ENABLED);
73
+ }
74
+
75
+ public function getConnectorVersion()
76
+ {
77
+ $modules = (array) Mage::getConfig()->getNode('modules')->children();
78
+ if (isset($modules['Dotdigitalgroup_Email'])) {
79
+ $moduleName = $modules['Dotdigitalgroup_Email'];
80
+ return $moduleName->version;
81
+ }
82
+ return '';
83
+ }
84
+
85
+
86
+ public function getPageTrackingEnabled()
87
+ {
88
+ return (bool)Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_PAGE_TRACKING_ENABLED);
89
+ }
90
+
91
+ public function getRoiTrackingEnabled()
92
+ {
93
+ return (bool)Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_ROI_TRACKING_ENABLED);
94
+ }
95
+
96
+ public function getResourceAllocationEnabled()
97
+ {
98
+ return (bool)Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_RESOURCE_ALLOCATION);
99
+ }
100
+
101
+ public function getMappedStoreName($website)
102
+ {
103
+ $mapped = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_CUSTOMER_STORENAME);
104
+ $storeName = ($mapped)? $mapped : '';
105
+ return $storeName;
106
+ }
107
+
108
+ /**
109
+ * Get the contact id for the custoemer based on website id.
110
+ * @param $email
111
+ * @param $websiteId
112
+ *
113
+ * @return bool
114
+ */
115
+ public function getContactId($email, $websiteId)
116
+ {
117
+ $client = $this->getWebsiteApiClient($websiteId);
118
+ $response = $client->postContacts($email);
119
+
120
+ if (isset($response->message))
121
+ return $response->message;
122
+
123
+ return $response->id;
124
+ }
125
+
126
+ public function getCustomerAddressBook($website)
127
+ {
128
+ $website = Mage::app()->getWebsite($website);
129
+ return $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMERS_ADDRESS_BOOK_ID);
130
+ }
131
+
132
+ public function getSubscriberAddressBook($website)
133
+ {
134
+ $website = Mage::app()->getWebsite($website);
135
+ return $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SUBSCRIBERS_ADDRESS_BOOK_ID);
136
+ }
137
+
138
+ public function getGuestAddressBook($website)
139
+ {
140
+ $website = Mage::app()->getWebsite($website);
141
+ return $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_GUEST_ADDRESS_BOOK_ID);
142
+ }
143
+
144
+ /**
145
+ * @return $this
146
+ */
147
+ public function allowResourceFullExecution()
148
+ {
149
+ if ($this->getResourceAllocationEnabled()) {
150
+
151
+ /* it may be needed to set maximum execution time of the script to longer,
152
+ * like 60 minutes than usual */
153
+ set_time_limit(7200);
154
+
155
+ /* and memory to 512 megabytes */
156
+ ini_set('memory_limit', '512M');
157
+ }
158
+ return $this;
159
+ }
160
+ public function convert($size)
161
+ {
162
+ $unit=array('b','kb','mb','gb','tb','pb');
163
+ return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i];
164
+ }
165
+
166
+ /**
167
+ * @return string
168
+ */
169
+ public function getStringWebsiteApiAccounts()
170
+ {
171
+ $accounts = array();
172
+ foreach (Mage::app()->getWebsites() as $website) {
173
+ $websiteId = $website->getId();
174
+ $apiUsername = $this->getApiUsername($website);
175
+ $accounts[$apiUsername] = $apiUsername . ', websiteId: ' . $websiteId . ' name ' . $website->getName();
176
+ }
177
+ return implode('</br>', $accounts);
178
+ }
179
+
180
+ public function getCustomAttributes($website = 0)
181
+ {
182
+ $website = Mage::app()->getWebsite($website);
183
+ return unserialize($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_CUSTOM_DATAFIELDS));
184
+ }
185
+
186
+ /**
187
+ * @param $path
188
+ * @param null|string|bool|int|Mage_Core_Model_Website $websiteId
189
+ * @return mixed
190
+ */
191
+ public function getWebsiteConfig($path, $websiteId = 0)
192
+ {
193
+ $website = Mage::app()->getWebsite($websiteId);
194
+ return $website->getConfig($path);
195
+ }
196
+
197
+ /**
198
+ * Api client by website.
199
+ *
200
+ * @param int $website
201
+ *
202
+ * @return bool|Dotdigitalgroup_Email_Model_Apiconnector_Client
203
+ */
204
+ public function getWebsiteApiClient($website = 0)
205
+ {
206
+ if (! $apiUsername = $this->getApiUsername($website) || ! $apiPassword = $this->getApiPassword($website))
207
+ return false;
208
+
209
+ $client = Mage::getModel('email_connector/apiconnector_client');
210
+ $client->setApiUsername($this->getApiUsername($website))
211
+ ->setApiPassword($this->getApiPassword($website));
212
+
213
+ return $client;
214
+ }
215
+
216
+ /**
217
+ * Retrieve authorisation code.
218
+ */
219
+ public function getCode()
220
+ {
221
+ $adminUser = Mage::getSingleton('admin/session')->getUser();
222
+ $code = $adminUser->getEmailCode();
223
+
224
+ return $code;
225
+ }
226
+
227
+ /**
228
+ * Autorisation url.
229
+ * @return string
230
+ */
231
+ public function getAuthoriseUrl()
232
+ {
233
+ $clientId = Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CLIENT_ID);
234
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB, true);
235
+ $callback = $baseUrl . 'connector/email/callback';
236
+ $adminUser = Mage::getSingleton('admin/session')->getUser();
237
+
238
+ $params = array(
239
+ 'redirect_uri' => $callback,
240
+ 'scope' => 'Account',
241
+ 'state' => $adminUser->getId(),
242
+ 'response_type' => 'code'
243
+ );
244
+ $url = Dotdigitalgroup_Email_Helper_Config::API_CONNECTOR_URL_AUTHORISE . http_build_query($params) . '&client_id=' . $clientId;
245
+ Mage::helper('connector')->log('Authorization code url : '. $url);
246
+
247
+ return $url;
248
+ }
249
+
250
+ /**
251
+ * order status config value
252
+ * @param int $website
253
+ * @return mixed order status
254
+ */
255
+ public function getConfigSelectedStatus($website = 0)
256
+ {
257
+ $status = $this->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_ORDER_STATUS, $website);
258
+ if($status)
259
+ return explode(',',$status);
260
+ else
261
+ return false;
262
+ }
263
+
264
+ /**
265
+ * check sweet tooth installed/active status
266
+ * @return boolean
267
+ */
268
+ public function isSweetToothEnabled()
269
+ {
270
+ return (bool)Mage::getConfig()->getModuleConfig('TBT_Rewards')->is('active', 'true');
271
+ }
272
+
273
+ /**
274
+ * check sweet tooth installed/active status and active status
275
+ * @param Mage_Core_Model_Website $website
276
+ * @return boolean
277
+ */
278
+ public function isSweetToothToGo($website)
279
+ {
280
+ $stMappingStatus = $this->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_SWEETTOOTH_ACTIVE, $website->getData('website_id'));
281
+ if($stMappingStatus && $this->isSweetToothEnabled()) return true;
282
+ return false;
283
+ }
284
+
285
+ public function setConnectorContactToReImport($customerId)
286
+ {
287
+ $contactModel = Mage::getModel('email_connector/contact');
288
+ $contactModel
289
+ ->loadByCustomerId($customerId)
290
+ ->setEmailImported(Dotdigitalgroup_Email_Model_Contact::EMAIL_CONTACT_NOT_IMPORTED)
291
+ ->save();
292
+ }
293
+
294
+ /**
295
+ * Diff between to times;
296
+ *
297
+ * @param $time1
298
+ * @param $time2
299
+ * @return int
300
+ */
301
+ public function dateDiff($time1, $time2=NULL) {
302
+ if (is_null($time2)) {
303
+ $time2 = Mage::getModel('core/date')->date();
304
+ }
305
+ $time1 = strtotime($time1);
306
+ $time2 = strtotime($time2);
307
+ return $time2 - $time1;
308
+ }
309
+
310
+
311
+ /**
312
+ * Disable website config when the request is made admin area only!
313
+ * @param $path
314
+ *
315
+ * @throws Mage_Core_Exception
316
+ */
317
+ public function disableConfigForWebsite($path)
318
+ {
319
+ $scopeId = 0;
320
+ if ($website = Mage::app()->getRequest()->getParam('website')) {
321
+ $scope = 'websites';
322
+ $scopeId = Mage::app()->getWebsite($website)->getId();
323
+ } else {
324
+ $scope = "default";
325
+ }
326
+ $config = Mage::getConfig();
327
+ $config->saveConfig($path, 0, $scope, $scopeId);
328
+ $config->cleanCache();
329
+ }
330
+
331
+ /**
332
+ * number of customers with duplicate emails, emails as total number
333
+ * @return Mage_Customer_Model_Resource_Customer_Collection
334
+ */
335
+ public function getCustomersWithDuplicateEmails( ) {
336
+ $customers = Mage::getModel('customer/customer')->getCollection();
337
+
338
+ //duplicate emails
339
+ $customers->getSelect()
340
+ ->columns(array('emails' => 'COUNT(e.entity_id)'))
341
+ ->group('email')
342
+ ->having('emails > ?', 1);
343
+
344
+ return $customers;
345
+ }
346
+
347
+ /**
348
+ * Create new raygun client.
349
+ *
350
+ * @return bool|\Raygun4php\RaygunClient
351
+ */
352
+ public function getRaygunClient()
353
+ {
354
+ $code = Mage::getstoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_RAYGUN_APPLICATION_CODE);
355
+
356
+ if ($this->raygunEnabled()) {
357
+ require_once Mage::getBaseDir('lib').DS.'Raygun4php/RaygunClient.php';
358
+ return new Raygun4php\RaygunClient($code, false, true);
359
+ }
360
+
361
+ return false;
362
+ }
363
+
364
+ /**
365
+ * Raygun logs.
366
+ * @param int $errno
367
+ * @param $message
368
+ * @param string $filename
369
+ * @param int $line
370
+ * @param array $tags
371
+ *
372
+ * @return int|null
373
+ */
374
+ public function rayLog($errno = 100, $message, $filename = 'helper/data.php', $line = 1, $tags = array())
375
+ {
376
+ $client = $this->getRaygunClient();
377
+ if ($client) {
378
+ //use tags to log the client baseurl
379
+ if (empty($tags))
380
+ $tags = array(Mage::getBaseUrl('web'));
381
+ //send message
382
+ $code = $client->SendError( $errno, $message, $filename, $line, $tags );
383
+
384
+ return $code;
385
+ }
386
+
387
+ return false;
388
+ }
389
+
390
+
391
+ /**
392
+ * check for raygun application and if enabled.
393
+ * @param int $websiteId
394
+ *
395
+ * @return mixed
396
+ * @throws Mage_Core_Exception
397
+ */
398
+ public function raygunEnabled($websiteId = 0)
399
+ {
400
+ $website = Mage::app()->getWebsite($websiteId);
401
+
402
+ return (bool)$website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_RAYGUN_APPLICATION_CODE);
403
+
404
+ }
405
+
406
+
407
+ /**
408
+ * Create new config if the config was not found.
409
+ * mark the account api datafields was created
410
+ * @param $value
411
+ * @param string $scope
412
+ *
413
+ * @return bool
414
+ */
415
+ public function isConfigCreatedForPath( $value, $scope = 'default' )
416
+ {
417
+ $configModel = Mage::getModel('email_connector/config');
418
+
419
+ //we use path as the transactional usename config value
420
+ $path = Dotdigitalgroup_Email_Helper_Transactional::XML_PATH_TRANSACTIONAL_API_USERNAME;
421
+
422
+ $itemConfig = $configModel->getCollection()
423
+ ->addFieldToFilter('path', $path)
424
+ ->addFieldToFilter('value', $value)
425
+ ->addFieldToFilter('scope', $scope)
426
+ ->getFirstItem();
427
+
428
+ //config was created
429
+ if ($itemConfig->getId()) {
430
+ return true;
431
+ }
432
+
433
+ //new config save data
434
+ $itemConfig->setPath($path)
435
+ ->setScope($scope)
436
+ ->setValue($value)
437
+ ->save();
438
+ return false;
439
+ }
440
+
441
+ /**
442
+ * Generate the baseurl for the default store
443
+ * dynamic content will be displayed
444
+ * @return string
445
+ * @throws Mage_Core_Exception
446
+ */
447
+ public function generateDynamicUrl()
448
+ {
449
+ $website = Mage::app()->getRequest()->getParam('website', false);
450
+
451
+ //set website url for the default store id
452
+ if ($website) {
453
+ $website = Mage::app()->getWebsite( $website );
454
+ }else {
455
+ $website = 0;
456
+ }
457
+ $desfaultStoreId = Mage::app()
458
+ ->getWebsite($website)
459
+ ->getDefaultGroup()
460
+ ->getDefaultStoreId();
461
+
462
+ //base url
463
+ $baseUrl = Mage::app()->getStore($desfaultStoreId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
464
+
465
+ return $baseUrl;
466
+
467
+ }
468
+
469
+ /**
470
+ *
471
+ * @param int $website
472
+ *
473
+ * @return bool|mixed
474
+ */
475
+ public function getOrderDeleteDays($website = 0)
476
+ {
477
+ return $this->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_ORDER_DELETE, $website);
478
+ }
479
+
480
+ }
app/code/{local → community}/Dotdigitalgroup/Email/Helper/File.php RENAMED
@@ -1,10 +1,10 @@
1
  <?php
2
- /*
3
- empty helper to keep admin from breaking
4
- */
5
  class Dotdigitalgroup_Email_Helper_File extends Dotdigitalgroup_Email_Helper_Data
6
  {
7
 
 
 
8
  /**
9
  * Location of files we are building
10
  */
@@ -15,8 +15,8 @@ class Dotdigitalgroup_Email_Helper_File extends Dotdigitalgroup_Email_Helper_Dat
15
  private $delimiter; // set in _construct
16
  private $enclosure; // set in _construct
17
 
18
- public function __construct() {
19
-
20
  $this->_output_folder = Mage::getBaseDir('var') . DS . 'export' . DS . 'email';
21
  $this->_output_archive_folder = $this->_output_folder . DS . 'archive';
22
 
@@ -25,34 +25,37 @@ class Dotdigitalgroup_Email_Helper_File extends Dotdigitalgroup_Email_Helper_Dat
25
  } // end
26
 
27
 
28
- public function getOutputFolder() {
 
29
  $this->pathExists($this->_output_folder);
30
  return $this->_output_folder;
31
  } // end
32
 
33
- public function getArchiveFolder() {
 
34
  $this->pathExists($this->_output_archive_folder);
35
  return $this->_output_archive_folder;
36
  } // end
37
 
38
  /* Return the full filepath */
39
- public function getFilePath($filename) {
 
40
  return $this->getOutputFolder() . DS . $filename;
41
  }
42
 
43
- public function archiveCSV($filename) {
44
-
45
  $this->moveFile($this->getOutputFolder(), $this->getArchiveFolder(), $filename);
46
  }
47
 
48
  /**
49
  * Moves the output file from one folder to the next
50
- *
51
- * @param string $source_folder
52
- * @param string $dest_folder
53
  */
54
- public function moveFile($source_folder, $dest_folder, $filename ){
55
-
56
  // generate the full file paths
57
  $source_filepath = $source_folder . DS . $filename;
58
  $dest_filepath = $dest_folder . DS . $filename;
@@ -68,15 +71,15 @@ class Dotdigitalgroup_Email_Helper_File extends Dotdigitalgroup_Email_Helper_Dat
68
  * @param $filepath
69
  * @param $csv
70
  */
71
- public function outputForceQuotesCSV($filepath, $csv) {
72
-
73
  $fqCsv = $this->arrayToCsv($csv,chr(9),'"',true,false);
74
  // Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it.
75
  $fp = fopen($filepath, "a");
76
 
77
  // for some reason passing the preset delimiter/enclosure variables results in error
78
- if (fwrite($fp, $fqCsv) == 0 ) //$this->delimiter $this->enclosure
79
- {
80
  Mage::throwException('Problem writing CSV file');
81
  }
82
  fclose($fp);
@@ -89,14 +92,14 @@ class Dotdigitalgroup_Email_Helper_File extends Dotdigitalgroup_Email_Helper_Dat
89
  * @param $filepath
90
  * @param $csv
91
  */
92
- public function outputCSV($filepath, $csv) {
93
-
94
  // Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it.
95
  $handle = fopen($filepath, "a");
96
 
97
  // for some reason passing the preset delimiter/enclosure variables results in error
98
- if (fputcsv($handle, $csv, ',', '"') == 0 ) //$this->delimiter $this->enclosure
99
- {
100
  Mage::throwException('Problem writing CSV file');
101
  }
102
 
@@ -109,8 +112,9 @@ class Dotdigitalgroup_Email_Helper_File extends Dotdigitalgroup_Email_Helper_Dat
109
  * If the path does not exist then create it
110
  * @param string $path
111
  */
112
- public function pathExists($path) {
113
- if (!is_dir( $path ) ) {
 
114
  mkdir($path, 0777, true);
115
  } // end
116
 
@@ -119,7 +123,8 @@ class Dotdigitalgroup_Email_Helper_File extends Dotdigitalgroup_Email_Helper_Dat
119
  } // end
120
 
121
 
122
- protected function arrayToCsv( array &$fields, $delimiter, $enclosure, $encloseAll = false, $nullToMysqlNull = false ) {
 
123
  $delimiter_esc = preg_quote($delimiter, '/');
124
  $enclosure_esc = preg_quote($enclosure, '/');
125
 
@@ -131,10 +136,9 @@ class Dotdigitalgroup_Email_Helper_File extends Dotdigitalgroup_Email_Helper_Dat
131
  }
132
 
133
  // Enclose fields containing $delimiter, $enclosure or whitespace
134
- if ( $encloseAll || preg_match( "/(?:${delimiter_esc}|${enclosure_esc}|\s)/", $field ) ) {
135
  $output[] = $enclosure . str_replace($enclosure, $enclosure . $enclosure, $field) . $enclosure;
136
- }
137
- else {
138
  $output[] = $field;
139
  }
140
  }
@@ -156,4 +160,42 @@ class Dotdigitalgroup_Email_Helper_File extends Dotdigitalgroup_Email_Helper_Dat
156
  }
157
 
158
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
  }
1
  <?php
2
+
 
 
3
  class Dotdigitalgroup_Email_Helper_File extends Dotdigitalgroup_Email_Helper_Data
4
  {
5
 
6
+ const FILE_FULL_ACCESS_PERMISSION = '777';
7
+
8
  /**
9
  * Location of files we are building
10
  */
15
  private $delimiter; // set in _construct
16
  private $enclosure; // set in _construct
17
 
18
+ public function __construct()
19
+ {
20
  $this->_output_folder = Mage::getBaseDir('var') . DS . 'export' . DS . 'email';
21
  $this->_output_archive_folder = $this->_output_folder . DS . 'archive';
22
 
25
  } // end
26
 
27
 
28
+ public function getOutputFolder()
29
+ {
30
  $this->pathExists($this->_output_folder);
31
  return $this->_output_folder;
32
  } // end
33
 
34
+ public function getArchiveFolder()
35
+ {
36
  $this->pathExists($this->_output_archive_folder);
37
  return $this->_output_archive_folder;
38
  } // end
39
 
40
  /* Return the full filepath */
41
+ public function getFilePath($filename)
42
+ {
43
  return $this->getOutputFolder() . DS . $filename;
44
  }
45
 
46
+ public function archiveCSV($filename)
47
+ {
48
  $this->moveFile($this->getOutputFolder(), $this->getArchiveFolder(), $filename);
49
  }
50
 
51
  /**
52
  * Moves the output file from one folder to the next
53
+ * @param $source_folder
54
+ * @param $dest_folder
55
+ * @param $filename
56
  */
57
+ public function moveFile($source_folder, $dest_folder, $filename )
58
+ {
59
  // generate the full file paths
60
  $source_filepath = $source_folder . DS . $filename;
61
  $dest_filepath = $dest_folder . DS . $filename;
71
  * @param $filepath
72
  * @param $csv
73
  */
74
+ public function outputForceQuotesCSV($filepath, $csv)
75
+ {
76
  $fqCsv = $this->arrayToCsv($csv,chr(9),'"',true,false);
77
  // Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it.
78
  $fp = fopen($filepath, "a");
79
 
80
  // for some reason passing the preset delimiter/enclosure variables results in error
81
+ // $this->delimiter $this->enclosure
82
+ if (fwrite($fp, $fqCsv) == 0 ) {
83
  Mage::throwException('Problem writing CSV file');
84
  }
85
  fclose($fp);
92
  * @param $filepath
93
  * @param $csv
94
  */
95
+ public function outputCSV($filepath, $csv)
96
+ {
97
  // Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it.
98
  $handle = fopen($filepath, "a");
99
 
100
  // for some reason passing the preset delimiter/enclosure variables results in error
101
+ //$this->delimiter $this->enclosure
102
+ if (fputcsv($handle, $csv, ',', '"') == 0 ) {
103
  Mage::throwException('Problem writing CSV file');
104
  }
105
 
112
  * If the path does not exist then create it
113
  * @param string $path
114
  */
115
+ public function pathExists($path)
116
+ {
117
+ if (!is_dir($path)) {
118
  mkdir($path, 0777, true);
119
  } // end
120
 
123
  } // end
124
 
125
 
126
+ protected function arrayToCsv( array &$fields, $delimiter, $enclosure, $encloseAll = false, $nullToMysqlNull = false )
127
+ {
128
  $delimiter_esc = preg_quote($delimiter, '/');
129
  $enclosure_esc = preg_quote($enclosure, '/');
130
 
136
  }
137
 
138
  // Enclose fields containing $delimiter, $enclosure or whitespace
139
+ if ($encloseAll || preg_match( "/(?:${delimiter_esc}|${enclosure_esc}|\s)/", $field )) {
140
  $output[] = $enclosure . str_replace($enclosure, $enclosure . $enclosure, $field) . $enclosure;
141
+ } else {
 
142
  $output[] = $field;
143
  }
144
  }
160
  }
161
 
162
 
163
+ public function getWebsiteCustomerMappingDatafields($website)
164
+ {
165
+ $store = $website->getDefaultStore();
166
+ $mappedData = Mage::getStoreConfig('connector_data_mapping/customer_data', $store);
167
+ unset($mappedData['custom_attributes']);
168
+
169
+ $mappedRewardData = $this->getWebsiteCustomerRewardMappingDatafields($website);
170
+ if($mappedRewardData) $mappedData = array_merge($mappedData, $mappedRewardData);
171
+
172
+ foreach ($mappedData as $key => $value) {
173
+ if (! $value)
174
+ unset($mappedData[$key]);
175
+ }
176
+
177
+ return $mappedData;
178
+ }
179
+
180
+ public function getWebsiteCustomerRewardMappingDatafields($website)
181
+ {
182
+ $helper = Mage::helper('connector');
183
+ if($helper->isSweetToothToGo($website)) {
184
+ $store = $website->getDefaultStore();
185
+ $mappedData = Mage::getStoreConfig('connector_data_mapping/sweet_tooth', $store);
186
+ unset($mappedData['active']);
187
+ return $mappedData;
188
+ }
189
+ return false;
190
+ }
191
+
192
+ /**
193
+ * @param $path
194
+ *
195
+ * @return string
196
+ */
197
+ public function checkPathPermission($path) {
198
+ clearstatcache(null, $path);
199
+ return decoct( fileperms($path) & 0777 );
200
+ }
201
  }
app/code/community/Dotdigitalgroup/Email/Helper/Recommended.php ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Helper_Recommended extends Mage_Core_Helper_Abstract
4
+ {
5
+ const XML_PATH_RELATED_PRODUCTS_TYPE = 'connector_dynamic_content/products/related_display_type';
6
+ const XML_PATH_UPSELL_PRODUCTS_TYPE = 'connector_dynamic_content/products/upsell_display_type';
7
+ const XML_PATH_CROSSSELL_PRODUCTS_TYPE = 'connector_dynamic_content/products/crosssell_display_type';
8
+ const XML_PATH_BESTSELLER_PRODUCT_TYPE = 'connector_dynamic_content/products/bestsellers_display_type';
9
+ const XML_PATH_MOSTVIEWED_PRODUCT_TYPE = 'connector_dynamic_content/products/most_viewed_display_type';
10
+ const XML_PATH_RECENTLYVIEWED_PRODUCT_TYPE = 'connector_dynamic_content/products/recently_viewed_display_type';
11
+ const XML_PATH_PRODUCTPUSH_TYPE = 'connector_dynamic_content/manual_product_search/display_type';
12
+
13
+
14
+ const XML_PATH_RELATED_PRODUCTS_ITEMS = 'connector_dynamic_content/products/related_items_to_display';
15
+ const XML_PATH_UPSELL_PRODUCTS_ITEMS = 'connector_dynamic_content/products/upsell_items_to_display';
16
+ const XML_PATH_CROSSSELL_PRODUCTS_ITEMS = 'connector_dynamic_content/products/crosssell_items_to_display';
17
+ const XML_PATH_BESTSELLER_PRODUCT_ITEMS = 'connector_dynamic_content/products/bestsellers_items_to_display';
18
+ const XML_PATH_MOSTVIEWED_PRODUCT_ITEMS = 'connector_dynamic_content/products/most_viewed_items_to_display';
19
+ const XML_PATH_RECENTLYVIEWED_PRODUCT_ITEMS = 'connector_dynamic_content/products/recently_viewed_items_to_display';
20
+
21
+ const XML_PATH_PRODUCTPUSH_DISPLAY_ITEMS = 'connector_dynamic_content/manual_product_search/items_to_display';
22
+ const XML_PATH_BESTSELLER_TIME_PERIOD = 'connector_dynamic_content/products/bestsellers_time_period';
23
+ const XML_PATH_MOSTVIEWED_TIME_PERIOD = 'connector_dynamic_content/products/most_viewed_time_period';
24
+ const XML_PATH_PRODUCTPUSH_ITEMS = 'connector_dynamic_content/manual_product_search/products_push_items';
25
+ const XML_PATH_FALLBACK_PRODUCTS_ITEMS = 'connector_dynamic_content/fallback_products/product_list';
26
+
27
+ public $periods = array('week', 'month', 'year');
28
+
29
+ /**
30
+ * Dispay type
31
+ * @return mixed|string grid:list
32
+ */
33
+ public function getDisplayType()
34
+ {
35
+ $mode = Mage::app()->getRequest()->getActionName();
36
+ $type = '';
37
+
38
+ switch($mode){
39
+ case 'related':
40
+ $type = $this->getRelatedProductsType();
41
+ break;
42
+ case 'upsell':
43
+ $type = $this->getUpsellProductsType();
44
+ break;
45
+ case 'crosssell':
46
+ $type = $this->getCrosssellProductsType();
47
+ break;
48
+ case 'bestsellers':
49
+ $type = $this->getBestSellerProductsType();
50
+ break;
51
+ case 'mostviewed':
52
+ $type = $this->getMostViewedProductsType();
53
+ break;
54
+ case 'recentlyviewed':
55
+ $type = $this->getRecentlyviewedProductsType();
56
+ break;
57
+ case 'push':
58
+ $type = $this->getProductpushProductsType();
59
+ }
60
+
61
+ return $type;
62
+ }
63
+
64
+ public function getRelatedProductsType()
65
+ {
66
+ return Mage::getStoreConfig(self::XML_PATH_RELATED_PRODUCTS_TYPE);
67
+ }
68
+
69
+ public function getUpsellProductsType()
70
+ {
71
+ return Mage::getStoreConfig(self::XML_PATH_UPSELL_PRODUCTS_TYPE);
72
+
73
+ }
74
+
75
+ public function getCrosssellProductsType()
76
+ {
77
+ return Mage::getStoreConfig(self::XML_PATH_CROSSSELL_PRODUCTS_TYPE);
78
+ }
79
+
80
+ public function getBestSellerProductsType()
81
+ {
82
+ return Mage::getStoreConfig(self::XML_PATH_BESTSELLER_PRODUCT_TYPE);
83
+ }
84
+
85
+ public function getMostViewedProductsType()
86
+ {
87
+ return Mage::getStoreConfig(self::XML_PATH_MOSTVIEWED_PRODUCT_TYPE);
88
+ }
89
+
90
+ public function getRecentlyviewedProductsType()
91
+ {
92
+ return Mage::getStoreConfig(self::XML_PATH_RECENTLYVIEWED_PRODUCT_TYPE);
93
+ }
94
+
95
+ public function getProductpushProductsType()
96
+ {
97
+ return Mage::getStoreConfig(self::XML_PATH_PRODUCTPUSH_TYPE);
98
+ }
99
+
100
+
101
+ /**
102
+ * Limit of products displayed.
103
+ * @param $mode
104
+ *
105
+ * @return int|mixed
106
+ */
107
+ public function getDisplayLimitByMode($mode)
108
+ {
109
+ $result = 0;
110
+
111
+ switch($mode){
112
+ case 'related':
113
+ $result = Mage::getStoreConfig(self::XML_PATH_RELATED_PRODUCTS_ITEMS);
114
+ break;
115
+ case 'upsell':
116
+ $result = Mage::getStoreConfig(self::XML_PATH_UPSELL_PRODUCTS_ITEMS);
117
+ break;
118
+ case 'crosssell':
119
+ $result = Mage::getStoreConfig(self::XML_PATH_CROSSSELL_PRODUCTS_ITEMS);
120
+ break;
121
+ case 'bestsellers':
122
+ $result = Mage::getStoreConfig(self::XML_PATH_BESTSELLER_PRODUCT_ITEMS);
123
+ break;
124
+ case 'mostviewed':
125
+ $result = Mage::getStoreConfig(self::XML_PATH_MOSTVIEWED_PRODUCT_ITEMS);
126
+ break;
127
+ case 'recentlyviewed':
128
+ $result = Mage::getStoreConfig(self::XML_PATH_RECENTLYVIEWED_PRODUCT_ITEMS);
129
+ break;
130
+ case 'push':
131
+ $result = Mage::getStoreConfig(self::XML_PATH_PRODUCTPUSH_DISPLAY_ITEMS);
132
+ }
133
+
134
+ return $result;
135
+ }
136
+
137
+ public function getFallbackIds()
138
+ {
139
+ $fallbackIds = Mage::getStoreConfig(self::XML_PATH_FALLBACK_PRODUCTS_ITEMS);
140
+ if ($fallbackIds)
141
+ return explode(',', Mage::getStoreConfig(self::XML_PATH_FALLBACK_PRODUCTS_ITEMS));
142
+ return array();
143
+ }
144
+
145
+ public function getTimeFromConfig($config)
146
+ {
147
+ $now = new Zend_Date();
148
+ $period = '';
149
+ if ($config == 'mostviewed')
150
+ $period = Mage::getStoreConfig(self::XML_PATH_MOSTVIEWED_TIME_PERIOD);
151
+ elseif($config == 'bestsellers') {
152
+ $period = Mage::getStoreConfig( self::XML_PATH_BESTSELLER_TIME_PERIOD );
153
+ }elseif($config == 'recentlyviewed')
154
+ $period = Mage::getStoreConfig(self::XML_PATH_MOSTVIEWED_TIME_PERIOD);
155
+
156
+ if ($period == 'week') {
157
+ $sub = Zend_Date::WEEK;
158
+ } elseif ($period == 'month' || $period == 'M') {
159
+ $sub = Zend_Date::MONTH;
160
+ } elseif ($period == 'year') {
161
+ $sub = Zend_Date::YEAR;
162
+ }
163
+
164
+ if (isset($sub)) {
165
+ $period = $now->sub(1, $sub);
166
+
167
+ return $period->tostring(Zend_Date::ISO_8601);
168
+ }
169
+ }
170
+
171
+ public function getProductPushIds()
172
+ {
173
+ $productIds = Mage::getStoreConfig(self::XML_PATH_PRODUCTPUSH_ITEMS);
174
+
175
+ return explode(',', $productIds);
176
+ }
177
+
178
+ }
app/code/community/Dotdigitalgroup/Email/Helper/Transactional.php ADDED
@@ -0,0 +1,287 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Helper_Transactional extends Mage_Core_Helper_Abstract
4
+ {
5
+ const XML_PATH_TRANSACTIONAL_API_ENABLED = 'connector_transactional_emails/credentials/enabled';
6
+ const XML_PATH_TRANSACTIONAL_API_USERNAME = 'connector_transactional_emails/credentials/api_username';
7
+ const XML_PATH_TRANSACTIONAL_API_PASSWORD = 'connector_transactional_emails/credentials/api_password';
8
+
9
+ const XML_PATH_CONNECTOR_TRANSACTIONAL_FROM_ADDRESS = 'connector_transactional_emails/email_settings/from_address';
10
+ const XML_PATH_CONNECTOR_TRANSACTIONAL_REPLY_ACTION = 'connector_transactional_emails/email_settings/reply_action';
11
+ const XML_PATH_CONNECTOR_TRANSACTIONAL_REPLY_ADDRESS = 'connector_transactional_emails/email_settings/reply_address';
12
+ const XML_PATH_CONNECTOR_TRANSACTIONAL_SEND_COPY = 'connector_transactional_emails/email_settings/send_copy';
13
+ const XML_PATH_CONNECTOR_TRANSACTIONAL_UNSUBSCRIBE_LINK = 'connector_transactional_emails/email_settings/unsubscribe_link';
14
+
15
+ const XML_PATH_CONNECTOR_TRANSACTIONAL_EMAIL_DEFAULT = 'connector_transactional_emails/email_mapping/default_email_templates';
16
+ const XML_PATH_CONNECTOR_TRANSACTIONAL_EMAIL_CUSTOM = 'connector_transactional_emails/email_mapping/custom_email_templates';
17
+
18
+ const MAP_COLUMN_KEY_TEMPLATE = 'template';
19
+ const MAP_COLUMN_KEY_SENDTYPE = 'sendtype';
20
+ const MAP_COLUMN_KEY_CAMPAIGN = 'campaign';
21
+ const MAP_COLUMN_KEY_DATAFIELD = 'datafield';
22
+
23
+ const TRANSACTIONAL_SENDTYPE_SYSTEM_DEFAULT = '0';
24
+ const TRANSACTIONAL_SENDTYPE_VIA_CONNECTOR = '1';
25
+ const TRANSACTIOANL_SNEDTYPE_DESIGN_VIA_CONNECTOR = '2';
26
+
27
+
28
+
29
+ /**
30
+ * Get the api enabled.
31
+ *
32
+ * @return mixed
33
+ */
34
+ public function isEnabled()
35
+ {
36
+ return Mage::getStoreConfigFlag(self::XML_PATH_TRANSACTIONAL_API_ENABLED);
37
+ }
38
+
39
+ /**
40
+ * Get api username.
41
+ *
42
+ * @param mixed $website
43
+ *
44
+ * @return mixed
45
+ * @throws Mage_Core_Exception
46
+ */
47
+ public function getApiUsername($website = 0)
48
+ {
49
+ $website = Mage::app()->getWebsite($website);
50
+
51
+ return $website->getConfig(self::XML_PATH_TRANSACTIONAL_API_USERNAME);
52
+ }
53
+
54
+ /**
55
+ * Get api password.
56
+ *
57
+ * @param mixed $website
58
+ *
59
+ * @return mixed
60
+ * @throws Mage_Core_Exception
61
+ */
62
+ public function getApiPassword($website = 0)
63
+ {
64
+ $website = Mage::app()->getWebsite($website);
65
+
66
+ return $website->getConfig(self::XML_PATH_TRANSACTIONAL_API_PASSWORD);
67
+ }
68
+
69
+ /**
70
+ * Website by name.
71
+ * @param $websiteName
72
+ *
73
+ * @return Varien_Object
74
+ */
75
+ public function getWebsiteByName($websiteName)
76
+ {
77
+ $website = Mage::getModel('core/website')->getCollection()
78
+ ->addFieldToFilter('code', $websiteName)->getFirstItem();
79
+
80
+ return $website;
81
+ }
82
+
83
+ /**
84
+ * Find template lable by id.
85
+ * @param mixed $templateId
86
+ *
87
+ * @return string
88
+ */
89
+ public function getTemplateLabelById($templateId)
90
+ {
91
+ $default = Mage::getModel('email_connector/adminhtml_source_transactional_defaultselect')->toOptionArray();
92
+ $custom = Mage::getModel('email_connector/adminhtml_source_transactional_customselect')->toOptionArray();
93
+ $all = array_merge($default,$custom);
94
+
95
+ $label = "";
96
+ foreach($all as $one){
97
+ if($one['value'] == $templateId) {
98
+ $label = $one['label'];
99
+ break;
100
+ }
101
+ }
102
+ return $label;
103
+ }
104
+
105
+ /**
106
+ * get all templates mapping
107
+ * @param $storeId
108
+ * @return array
109
+ */
110
+ public function getAllTemplateMapping($storeId){
111
+ $allTemplateMapping = array();
112
+
113
+ $defaultTemplateMapping = $this->getDefaultEmailTemplates($storeId);
114
+ $customTemplateMapping = $this->getCustomEmailTemplates($storeId);
115
+
116
+ if(is_array($defaultTemplateMapping) && is_array($customTemplateMapping))
117
+ {
118
+ $allTemplateMapping = array_merge($defaultTemplateMapping, $customTemplateMapping);
119
+ }
120
+ elseif(is_array($defaultTemplateMapping))
121
+ {
122
+ $allTemplateMapping = $defaultTemplateMapping;
123
+ }
124
+ elseif(is_array($customTemplateMapping))
125
+ {
126
+ $allTemplateMapping = $customTemplateMapping;
127
+ }
128
+
129
+ return $allTemplateMapping;
130
+ }
131
+
132
+ /**
133
+ * Transactional emails check for campaing id if it's mapped.
134
+ * Default Emails stored in magento
135
+ *
136
+ * @return mixed
137
+ */
138
+ public function getMapping($templateId, $key ,$storeId = null)
139
+ {
140
+ $allTemplateMapping = $this->getAllTemplateMapping($storeId);
141
+ $isMapped = false;
142
+
143
+ foreach($allTemplateMapping as $templateMapping)
144
+ {
145
+ if($isMapped = $this->findTemplateIdInArray($templateId, $templateMapping))
146
+ break;
147
+ }
148
+
149
+ if(is_array($isMapped) && $key == self::MAP_COLUMN_KEY_DATAFIELD)
150
+ return $isMapped[self::MAP_COLUMN_KEY_DATAFIELD];
151
+
152
+ if(is_array($isMapped) && $key == self::MAP_COLUMN_KEY_SENDTYPE)
153
+ return $isMapped[self::MAP_COLUMN_KEY_SENDTYPE];
154
+
155
+ return $isMapped;
156
+ }
157
+
158
+ /**
159
+ * find template id in array
160
+ * @param mixed $id
161
+ * @param array $data
162
+ *
163
+ * @return mixed
164
+ */
165
+ public function findTemplateIdInArray($id, $data)
166
+ {
167
+ $result = false;
168
+ foreach($data as $key => $value){
169
+ if($key == 'template' && $value == $id) {
170
+ $result = $data;
171
+ break;
172
+ }
173
+ }
174
+ return $result;
175
+ }
176
+
177
+ /**
178
+ * get un-serialised config value for all default email templates for all modules
179
+ *
180
+ * @return array
181
+ */
182
+ public function getDefaultEmailTemplates($storeId = null)
183
+ {
184
+ return unserialize(Mage::getStoreConfig(self::XML_PATH_CONNECTOR_TRANSACTIONAL_EMAIL_DEFAULT, $storeId));
185
+ }
186
+
187
+ /**
188
+ * get un-serialised config value for custom templates
189
+ *
190
+ * @return array
191
+ */
192
+ public function getCustomEmailTemplates($storeId = null)
193
+ {
194
+ return unserialize(Mage::getStoreConfig(self::XML_PATH_CONNECTOR_TRANSACTIONAL_EMAIL_CUSTOM, $storeId));
195
+ }
196
+
197
+ /**
198
+ * Get the contact id for the custoemer based on website id.
199
+ * @param $email
200
+ * @param $websiteId
201
+ * @return string contact_id
202
+ */
203
+ public function getContactId($email, $websiteId)
204
+ {
205
+ $client = $this->getWebsiteApiClient($websiteId);
206
+ $response = $client->postContacts($email);
207
+ if (isset($response->message))
208
+ return $response->message;
209
+ return $response->id;
210
+ }
211
+
212
+ /**
213
+ * Update contact default datafields.
214
+ *
215
+ * @param $contacData
216
+ */
217
+ public function updateContactData($contacData)
218
+ {
219
+ $client = $this->getWebsiteApiClient($contacData->getWebsite());
220
+ $email = $contacData->getCustomerEmail();
221
+ /**
222
+ * Transactional account data default datafields.
223
+ */
224
+ $data = array(
225
+ array(
226
+ 'Key' => 'LAST_ORDER_ID',
227
+ 'Value' => $contacData->getOrderId()),
228
+ array(
229
+ 'Key' => 'CUSTOMER_ID',
230
+ 'Value' => $contacData->getCustomerId()),
231
+ array(
232
+ 'Key' => 'ORDER_INCREMENT_ID',
233
+ 'Value' => $contacData->getOrderIncrementId()),
234
+ array(
235
+ 'Key' => 'WEBSITE_NAME',
236
+ 'Value' => $contacData->getWebsiteName()),
237
+ array(
238
+ 'Key' => 'STORE_NAME',
239
+ 'Value' => $contacData->getStoreName()),
240
+ array(
241
+ 'Key' => 'LAST_ORDER_DATE',
242
+ 'Value' => $contacData->getOrderDate())
243
+ );
244
+ $client->updateContactDatafieldsByEmail($email, $data);
245
+ }
246
+
247
+ /**
248
+ * Api client by website.
249
+ * @param int $website
250
+ * @return Dotdigitalgroup_Email_Model_Apiconnector_Client
251
+ */
252
+ public function getWebsiteApiClient($website = 0)
253
+ {
254
+ $client = Mage::getModel('email_connector/apiconnector_client');
255
+ $website = Mage::app()->getWebsite($website);
256
+ if ($website) {
257
+ $client->setApiUsername($this->getApiUsername($website))
258
+ ->setApiPassword($this->getApiPassword($website));
259
+ }
260
+ return $client;
261
+ }
262
+
263
+ public function getEmailSettings($path, $websiteId)
264
+ {
265
+ $helper = Mage::helper('connector');
266
+ return $helper->getWebsiteConfig($path, $websiteId);
267
+ }
268
+
269
+ public function getFromAddress($websiteId){
270
+ return $this->getEmailSettings(self::XML_PATH_CONNECTOR_TRANSACTIONAL_FROM_ADDRESS, $websiteId);
271
+ }
272
+
273
+ public function getReplyAction($websiteId){
274
+ return $this->getEmailSettings(self::XML_PATH_CONNECTOR_TRANSACTIONAL_REPLY_ACTION, $websiteId);
275
+ }
276
+
277
+ public function getReplyAddress($websiteId){
278
+ return $this->getEmailSettings(self::XML_PATH_CONNECTOR_TRANSACTIONAL_REPLY_ADDRESS, $websiteId);
279
+ }
280
+
281
+ public function getSendCopy($websiteId){
282
+ return $this->getEmailSettings(self::XML_PATH_CONNECTOR_TRANSACTIONAL_SEND_COPY, $websiteId);
283
+ }
284
+ public function getUnsubscribeLink($websiteId){
285
+ return $this->getEmailSettings(self::XML_PATH_CONNECTOR_TRANSACTIONAL_UNSUBSCRIBE_LINK, $websiteId);
286
+ }
287
+ }
app/code/community/Dotdigitalgroup/Email/Model/Abstract/Rest.php ADDED
@@ -0,0 +1,435 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ abstract class Dotdigitalgroup_Email_Model_Abstract_Rest
4
+ {
5
+ protected $url;
6
+ protected $verb;
7
+ protected $requestBody;
8
+ protected $requestLength;
9
+ protected $_apiUsername;
10
+ protected $_apiPassword;
11
+ protected $acceptType;
12
+ protected $responseBody;
13
+ protected $responseInfo;
14
+
15
+ public function __construct($website = 0) // ($url = null, $verb = 'GET', $requestBody = null)
16
+ {
17
+ $this->url = null; //$url;
18
+ $this->verb = 'GET'; //$verb;
19
+ $this->requestBody = null; //$requestBody;
20
+ $this->requestLength = 0;
21
+ $this->_apiUsername = (string)Mage::helper('connector')->getApiUsername($website);
22
+ $this->_apiPassword = (string)Mage::helper('connector')->getApiPassword($website);
23
+ $this->acceptType = 'application/json';
24
+ $this->responseBody = null;
25
+ $this->responseInfo = null;
26
+
27
+ if ($this->requestBody !== null) {
28
+ $this->buildPostBody();
29
+ }
30
+ }
31
+
32
+ private function prettyPrint($json)
33
+ {
34
+ $result = '';
35
+ $level = 0;
36
+ $prev_char = '';
37
+ $in_quotes = false;
38
+ $ends_line_level = NULL;
39
+ $json_length = strlen( $json );
40
+
41
+ for ($i = 0; $i < $json_length; $i++) {
42
+ $char = $json[$i];
43
+ $new_line_level = NULL;
44
+ $post = "";
45
+ if ($ends_line_level !== NULL) {
46
+ $new_line_level = $ends_line_level;
47
+ $ends_line_level = NULL;
48
+ }
49
+ if ($char === '"' && $prev_char != '\\') {
50
+ $in_quotes = !$in_quotes;
51
+ } elseif (! $in_quotes) {
52
+ switch ($char) {
53
+ case '}': case ']':
54
+ $level--;
55
+ $ends_line_level = NULL;
56
+ $new_line_level = $level;
57
+ break;
58
+
59
+ case '{': case '[':
60
+ $level++;
61
+ case ',':
62
+ $ends_line_level = $level;
63
+ break;
64
+
65
+ case ':':
66
+ $post = " ";
67
+ break;
68
+
69
+ case " ": case "\t": case "\n": case "\r":
70
+ $char = "";
71
+ $ends_line_level = $new_line_level;
72
+ $new_line_level = NULL;
73
+ break;
74
+ }
75
+ }
76
+ if ($new_line_level !== NULL) {
77
+ $result .= "\n".str_repeat( "\t", $new_line_level );
78
+ }
79
+ $result .= $char.$post;
80
+ $prev_char = $char;
81
+ }
82
+
83
+ return $result;
84
+ }
85
+
86
+ /**
87
+ * returns the object as JSON.
88
+ *
89
+ * @param bool $pretty
90
+ *
91
+ * @return string
92
+ */
93
+ public function toJSON($pretty=false)
94
+ {
95
+
96
+ if (!$pretty) {
97
+ return json_encode($this->expose());
98
+ } else {
99
+ return $this->prettyPrint(json_encode($this->expose()));
100
+ }
101
+ }
102
+
103
+ /**
104
+ * exposes the class as an array of objects
105
+ * @return array
106
+ */
107
+ public function expose()
108
+ {
109
+
110
+ return get_object_vars($this);
111
+
112
+ }
113
+
114
+
115
+ /**
116
+ * Reset the client.
117
+ *
118
+ * @return $this
119
+ */
120
+ public function flush ()
121
+ {
122
+ $this->_apiUsername = '';
123
+ $this->_apiPassword = '';
124
+ $this->requestBody = null;
125
+ $this->requestLength = 0;
126
+ $this->verb = 'GET';
127
+ $this->responseBody = null;
128
+ $this->responseInfo = null;
129
+ return $this;
130
+ }
131
+
132
+ /**
133
+ * Execute the curl request.
134
+ *
135
+ * @return null
136
+ * @throws Exception
137
+ */
138
+ public function execute()
139
+ {
140
+ $ch = curl_init();
141
+ $this->setAuth($ch);
142
+ try
143
+ {
144
+ switch (strtoupper($this->verb))
145
+ {
146
+ case 'GET':
147
+ $this->executeGet($ch);
148
+ break;
149
+ case 'POST':
150
+ $this->executePost($ch);
151
+ break;
152
+ case 'PUT':
153
+ $this->executePut($ch);
154
+ break;
155
+ case 'DELETE':
156
+ $this->executeDelete($ch);
157
+ break;
158
+ default:
159
+ throw new InvalidArgumentException('Current verb (' . $this->verb . ') is an invalid REST verb.');
160
+ }
161
+ }catch (InvalidArgumentException $e){
162
+ curl_close($ch);
163
+ throw $e;
164
+ }catch (Exception $e){
165
+ curl_close($ch);
166
+ throw $e;
167
+ }
168
+
169
+ return $this->responseBody;
170
+ }
171
+
172
+ /**
173
+ * Post data.
174
+ *
175
+ * @param null $data
176
+ *
177
+ * @return $this
178
+ */
179
+ public function buildPostBody($data = null)
180
+ {
181
+ $this->requestBody = json_encode($data);
182
+ return $this;
183
+ }
184
+
185
+ /**
186
+ * Execute curl get request.
187
+ *
188
+ * @param $ch
189
+ */
190
+ protected function executeGet($ch)
191
+ {
192
+ $this->doExecute($ch);
193
+ }
194
+
195
+ /**
196
+ * Execute post request.
197
+ *
198
+ * @param $ch
199
+ */
200
+ protected function executePost($ch)
201
+ {
202
+ if (!is_string($this->requestBody)) {
203
+ $this->buildPostBody();
204
+ }
205
+
206
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $this->requestBody);
207
+ curl_setopt($ch, CURLOPT_POST, true);
208
+
209
+ $this->doExecute($ch);
210
+ }
211
+
212
+ /**
213
+ * Post from the file.
214
+ *
215
+ * @param $filename
216
+ */
217
+ protected function buildPostBodyFromFile($filename)
218
+ {
219
+ $this->requestBody = array (
220
+ 'file' => '@'.$filename
221
+ );
222
+ }
223
+
224
+ /**
225
+ * Execute put.
226
+ *
227
+ * @param $ch
228
+ */
229
+ protected function executePut($ch)
230
+ {
231
+ if (!is_string($this->requestBody)) {
232
+ $this->buildPostBody();
233
+ }
234
+
235
+ $this->requestLength = strlen($this->requestBody);
236
+
237
+ $fh = fopen('php://memory', 'rw');
238
+ fwrite($fh, $this->requestBody);
239
+ rewind($fh);
240
+
241
+ curl_setopt($ch, CURLOPT_INFILE, $fh);
242
+ curl_setopt($ch, CURLOPT_INFILESIZE, $this->requestLength);
243
+ curl_setopt($ch, CURLOPT_PUT, true);
244
+
245
+ $this->doExecute($ch);
246
+
247
+ fclose($fh);
248
+ }
249
+
250
+ /**
251
+ * Ececute delete.
252
+ *
253
+ * @param $ch
254
+ */
255
+ protected function executeDelete($ch)
256
+ {
257
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
258
+
259
+ $this->doExecute($ch);
260
+ }
261
+
262
+ /**
263
+ * Execute request.
264
+ *
265
+ * @param $ch
266
+ */
267
+ protected function doExecute(&$ch)
268
+ {
269
+ $this->setCurlOpts($ch);
270
+ $this->responseBody = json_decode(curl_exec($ch));
271
+ $this->responseInfo = curl_getinfo($ch);
272
+
273
+ curl_close($ch);
274
+ }
275
+
276
+ /**
277
+ * curl options.
278
+ *
279
+ * @param $ch
280
+ */
281
+ protected function setCurlOpts(&$ch)
282
+ {
283
+ curl_setopt($ch, CURLOPT_TIMEOUT, 10);
284
+ curl_setopt($ch, CURLOPT_URL, $this->url);
285
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
286
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
287
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
288
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array ('Accept: ' . $this->acceptType ,'Content-Type: application/json'));
289
+ }
290
+
291
+ /**
292
+ * basic auth.
293
+ *
294
+ * @param $ch
295
+ */
296
+ protected function setAuth(&$ch)
297
+ {
298
+ if ($this->_apiUsername !== null && $this->_apiPassword !== null)
299
+ {
300
+ curl_setopt($ch, CURLAUTH_BASIC, CURLAUTH_DIGEST);
301
+ curl_setopt($ch, CURLOPT_USERPWD, $this->_apiUsername . ':' . $this->_apiPassword);
302
+ }
303
+ }
304
+
305
+ /**
306
+ * Get accept type.
307
+ *
308
+ * @return string
309
+ */
310
+ public function getAcceptType()
311
+ {
312
+ return $this->acceptType;
313
+ }
314
+
315
+ /**
316
+ * set accept type.
317
+ *
318
+ * @param $acceptType
319
+ */
320
+ public function setAcceptType($acceptType)
321
+ {
322
+ $this->acceptType = $acceptType;
323
+ }
324
+
325
+
326
+ /**
327
+ * get api username.
328
+ *
329
+ * @return string
330
+ */
331
+ public function getApiUsername()
332
+ {
333
+ return $this->_apiUsername;
334
+ }
335
+
336
+ /**
337
+ * set api username.
338
+ *
339
+ * @param $apiUsername
340
+ *
341
+ * @return $this
342
+ */
343
+ public function setApiUsername($apiUsername)
344
+ {
345
+ $this->_apiUsername = $apiUsername;
346
+ return $this;
347
+ }
348
+ /**
349
+ * Get api password.
350
+ *
351
+ * @return string
352
+ */
353
+ public function getApiPassword()
354
+ {
355
+ return $this->_apiPassword;
356
+ }
357
+
358
+ /**
359
+ * set api password.
360
+ * @param $apiPassword
361
+ *
362
+ * @return $this
363
+ */
364
+ public function setApiPassword($apiPassword)
365
+ {
366
+ $this->_apiPassword = $apiPassword;
367
+ return $this;
368
+ }
369
+
370
+ /**
371
+ * get response body.
372
+ *
373
+ * @return string/object
374
+ */
375
+ public function getResponseBody()
376
+ {
377
+ return $this->responseBody;
378
+ }
379
+
380
+ /**
381
+ * get response info.
382
+ *
383
+ * @return null
384
+ */
385
+ public function getResponseInfo()
386
+ {
387
+ return $this->responseInfo;
388
+ }
389
+
390
+ /**
391
+ * get url.
392
+ *
393
+ * @return string
394
+ */
395
+ public function getUrl()
396
+ {
397
+ return $this->url;
398
+ }
399
+
400
+ /**
401
+ * set url.
402
+ *
403
+ * @param $url
404
+ *
405
+ * @return $this
406
+ */
407
+ public function setUrl($url)
408
+ {
409
+ $this->url = $url;
410
+ return $this;
411
+ }
412
+
413
+ /**
414
+ * get the verb.
415
+ *
416
+ * @return string
417
+ */
418
+ public function getVerb ()
419
+ {
420
+ return $this->verb;
421
+ }
422
+
423
+ /**
424
+ * set the verb.
425
+ *
426
+ * @param $verb
427
+ *
428
+ * @return $this
429
+ */
430
+ public function setVerb ($verb)
431
+ {
432
+ $this->verb = $verb;
433
+ return $this;
434
+ }
435
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Content.php ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
5
+ */
6
+ class Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
7
+ {
8
+
9
+ /**
10
+ * css style that can be used to alert based on result
11
+ * @var
12
+ */
13
+ public $style;
14
+
15
+ /**
16
+ * @return mixed
17
+ */
18
+ public function getTitle() {
19
+ return $this->title;
20
+ }
21
+
22
+ /**
23
+ * @param $title
24
+ *
25
+ * @return $this
26
+ */
27
+ public function setTitle( $title ) {
28
+ $this->title = $title;
29
+ return $this;
30
+ }
31
+
32
+ /**
33
+ * title to be displayed as a key for the status
34
+ * @var
35
+ */
36
+ public $title;
37
+
38
+ /**
39
+ * message to be displayd in the body
40
+ * @var
41
+ */
42
+ public $message;
43
+
44
+ /**
45
+ * how to fix message
46
+ * @var
47
+ */
48
+ public $howto = array();
49
+
50
+ /**
51
+ * @return mixed
52
+ */
53
+
54
+ /**
55
+ * table data
56
+ * @var
57
+ */
58
+ public $table = array();
59
+
60
+ public function getHowto() {
61
+ return $this->howto;
62
+ }
63
+
64
+ /**
65
+ * @param $howto
66
+ *
67
+ * @return $this
68
+ */
69
+ public function setHowto( $howto ) {
70
+ $this->howto[] = $howto;
71
+ return $this;
72
+ }
73
+
74
+ /**
75
+ * @return mixed
76
+ */
77
+ public function getMessage() {
78
+ return $this->message;
79
+ }
80
+
81
+ /**
82
+ * @param $message
83
+ *
84
+ * @return $this
85
+ */
86
+ public function setMessage( $message ) {
87
+ $this->message = $message;
88
+ return $this;
89
+ }
90
+
91
+ /**
92
+ * @return mixed
93
+ */
94
+ public function getStyle() {
95
+ return $this->style;
96
+ }
97
+
98
+ /**
99
+ * @param $style
100
+ *
101
+ * @return $this
102
+ */
103
+ public function setStyle( $style ) {
104
+ $this->style = $style;
105
+ return $this;
106
+ }
107
+
108
+ public function setTable($table)
109
+ {
110
+ $this->table[] = $table;
111
+ return $this;
112
+ }
113
+
114
+ public function getTable() {
115
+ return $this->table;
116
+ }
117
+
118
+
119
+
120
+
121
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Abandoned.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Tabs_Analysis_Abandoned extends Mage_Core_Model_Abstract
4
+ {
5
+ protected $storeIds;
6
+
7
+ /**
8
+ * prepare collection and needed columns
9
+ *
10
+ * @return Mage_Sales_Model_Resource_Quote_Collection
11
+ */
12
+ protected function getPreparedCollection()
13
+ {
14
+ $collection = Mage::getResourceModel('sales/quote_collection');
15
+ $collection
16
+ ->addFieldToFilter('items_count', array('neq' => '0'))
17
+ ->addFieldToFilter('main_table.is_active', '1')
18
+ ->setOrder('updated_at');
19
+
20
+ if (is_array($this->storeIds) && !empty($this->storeIds)) {
21
+ $collection->addFieldToFilter('store_id', array('in' => $this->storeIds));
22
+ }
23
+
24
+ $adapter = $collection->getConnection();
25
+ $averageExpr = $adapter->getCheckSql(
26
+ 'COUNT(main_table.entity_id) > 0',
27
+ 'SUM(main_table.subtotal)/COUNT(main_table.entity_id)',
28
+ 0);
29
+
30
+ $collection->getSelect()->columns(array(
31
+ 'lifetime' => 'SUM(main_table.subtotal)',
32
+ 'average' => $averageExpr,
33
+ 'total_count' => "COUNT(main_table.entity_id)",
34
+ 'day_count' => "ROUND(COUNT(main_table.entity_id) / DATEDIFF(date(MAX(main_table.updated_at)) , date(MIN(main_table.updated_at))), 2)"
35
+ ));
36
+ return $collection;
37
+ }
38
+
39
+ /**
40
+ * @param int $store
41
+ * @param int $website
42
+ * @param int $group
43
+ * @return Varien_Object
44
+ * @throws Mage_Core_Exception
45
+ */
46
+ public function getLifeTimeAbandoned($store = 0, $website = 0, $group =0)
47
+ {
48
+ if ($store) {
49
+ $this->storeIds = array($store => $store);
50
+ } else if ($website){
51
+ $storeIds = Mage::app()->getWebsite($website)->getStoreIds();
52
+ $this->storeIds = $storeIds;
53
+ } else if ($group){
54
+ $storeIds = Mage::app()->getGroup($group)->getStoreIds();
55
+ $this->storeIds = $storeIds;
56
+ }
57
+ return $this->getPreparedCollection()->getFirstItem();
58
+ }
59
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Customer.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Tabs_Analysis_Customer extends Mage_Core_Model_Abstract
4
+ {
5
+ protected $storeIds;
6
+
7
+ /**
8
+ * prepare collection and needed columns
9
+ *
10
+ * @return Mage_Customer_Model_Resource_Customer_Collection
11
+ */
12
+ protected function getPreparedCollection()
13
+ {
14
+ $collection = Mage::getResourceModel('customer/customer_collection');
15
+
16
+ if (is_array($this->storeIds) && !empty($this->storeIds)) {
17
+ $collection->addAttributeToFilter('store_id', array('in' => $this->storeIds));
18
+ }
19
+
20
+ $collection->getSelect()->columns(array(
21
+ 'total_count' => "COUNT(*)",
22
+ 'day_count' => "ROUND(COUNT(*) / DATEDIFF(date(MAX(created_at)) , date(MIN(created_at))), 2)"
23
+ ));
24
+
25
+ return $collection;
26
+ }
27
+
28
+ /**
29
+ * @param int $store
30
+ * @param int $website
31
+ * @param int $group
32
+ * @return Varien_Object
33
+ * @throws Mage_Core_Exception
34
+ */
35
+ public function getLifeTimeTimeCustomer($store = 0, $website = 0, $group =0)
36
+ {
37
+ if ($store) {
38
+ $this->storeIds = array($store => $store);
39
+ } else if ($website){
40
+ $storeIds = Mage::app()->getWebsite($website)->getStoreIds();
41
+ $this->storeIds = $storeIds;
42
+ } else if ($group){
43
+ $storeIds = Mage::app()->getGroup($group)->getStoreIds();
44
+ $this->storeIds = $storeIds;
45
+ }
46
+ return $this->getPreparedCollection()->getFirstItem();
47
+ }
48
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Orders.php ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Tabs_Analysis_Orders extends Mage_Core_Model_Abstract
4
+ {
5
+ /**
6
+ * calculate sales and prepare columns
7
+ *
8
+ * @param int $isFilter
9
+ * @return Mage_Reports_Model_Resource_Order_Collection
10
+ */
11
+ protected function calculateSales($isFilter = 0)
12
+ {
13
+ $collection = Mage::getResourceModel('reports/order_collection');
14
+
15
+ $statuses = Mage::getSingleton('sales/config')
16
+ ->getOrderStatusesForState(Mage_Sales_Model_Order::STATE_CANCELED);
17
+
18
+ if (empty($statuses)) {
19
+ $statuses = array(0);
20
+ }
21
+ $adapter = $collection->getConnection();
22
+
23
+ if (Mage::getStoreConfig('sales/dashboard/use_aggregated_data')) {
24
+ $collection->setMainTable('sales/order_aggregated_created');
25
+ $collection->removeAllFieldsFromSelect();
26
+ $averageExpr = $adapter->getCheckSql(
27
+ 'SUM(main_table.orders_count) > 0',
28
+ 'SUM(main_table.total_revenue_amount)/SUM(main_table.orders_count)',
29
+ 0);
30
+ $collection->getSelect()->columns(array(
31
+ 'lifetime' => 'SUM(main_table.total_revenue_amount)',
32
+ 'average' => $averageExpr,
33
+ 'total_count' => "SUM(main_table.orders_count)",
34
+ 'day_count' => "ROUND(SUM(main_table.orders_count) / DATEDIFF(date(MAX(period)) , date(MIN(period))), 2)"
35
+ ));
36
+
37
+ if (!$isFilter) {
38
+ $collection->addFieldToFilter('store_id',
39
+ array('eq' => Mage::app()->getStore(Mage_Core_Model_Store::ADMIN_CODE)->getId())
40
+ );
41
+ }
42
+ $collection->getSelect()->where('main_table.order_status NOT IN(?)', $statuses);
43
+ } else {
44
+ $collection->setMainTable('sales/order');
45
+ $collection->removeAllFieldsFromSelect();
46
+
47
+ $expr = $this->_getSalesAmountExpression($collection);
48
+
49
+ if ($isFilter == 0) {
50
+ $expr = '(' . $expr . ') * main_table.base_to_global_rate';
51
+ }
52
+
53
+ $collection->getSelect()
54
+ ->columns(array(
55
+ 'lifetime' => "SUM({$expr})",
56
+ 'average' => "AVG({$expr})",
57
+ 'total_count' => "COUNT({$expr})",
58
+ 'day_count' => "ROUND(COUNT({$expr}) / DATEDIFF(date(MAX(created_at)) , date(MIN(created_at))), 2)"
59
+ ))
60
+ ->where('main_table.status NOT IN(?)', $statuses)
61
+ ->where('main_table.state NOT IN(?)', array(
62
+ Mage_Sales_Model_Order::STATE_NEW,
63
+ Mage_Sales_Model_Order::STATE_PENDING_PAYMENT)
64
+ );
65
+ }
66
+ return $collection;
67
+ }
68
+
69
+ /**
70
+ * get sales amount expression
71
+ *
72
+ * @param $collection
73
+ * @return string
74
+ */
75
+ protected function _getSalesAmountExpression($collection)
76
+ {
77
+ $adapter = $collection->getConnection();
78
+ $expressionTransferObject = new Varien_Object(array(
79
+ 'expression' => '%s - %s - %s - (%s - %s - %s)',
80
+ 'arguments' => array(
81
+ $adapter->getIfNullSql('main_table.base_total_invoiced', 0),
82
+ $adapter->getIfNullSql('main_table.base_tax_invoiced', 0),
83
+ $adapter->getIfNullSql('main_table.base_shipping_invoiced', 0),
84
+ $adapter->getIfNullSql('main_table.base_total_refunded', 0),
85
+ $adapter->getIfNullSql('main_table.base_tax_refunded', 0),
86
+ $adapter->getIfNullSql('main_table.base_shipping_refunded', 0),
87
+ )
88
+ ));
89
+
90
+ return vsprintf(
91
+ $expressionTransferObject->getExpression(),
92
+ $expressionTransferObject->getArguments()
93
+ );
94
+
95
+ }
96
+
97
+ /**
98
+ * @param int $store
99
+ * @param int $website
100
+ * @param int $group
101
+ * @return Varien_Object
102
+ * @throws Mage_Core_Exception
103
+ */
104
+ public function getLifetimeSales($store = 0, $website = 0, $group =0)
105
+ {
106
+ $isFilter = $store || $website || $group;
107
+ $collection = $this->calculateSales($isFilter);
108
+
109
+ if ($store) {
110
+ $collection->addFieldToFilter('store_id', $store);
111
+ } else if ($website){
112
+ $storeIds = Mage::app()->getWebsite($website)->getStoreIds();
113
+ $collection->addFieldToFilter('store_id', array('in' => $storeIds));
114
+ } else if ($group){
115
+ $storeIds = Mage::app()->getGroup($group)->getStoreIds();
116
+ $collection->addFieldToFilter('store_id', array('in' => $storeIds));
117
+ }
118
+
119
+ $collection->load();
120
+ return $collection->getFirstItem();
121
+ }
122
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Rfm.php ADDED
@@ -0,0 +1,173 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Tabs_Analysis_Rfm extends Mage_Core_Model_Abstract
4
+ {
5
+ protected $rfm = array();
6
+ protected $_store = 0;
7
+ protected $_group = 0;
8
+ protected $_website = 0;
9
+
10
+ const RECENCY = 'Recency';
11
+ const FREQUENCY = 'Frequency';
12
+ const MONETARY = 'Monetary';
13
+
14
+ /**
15
+ * prepare collection and needed columns
16
+ *
17
+ * @return Mage_Sales_Model_Resource_Order_Collection
18
+ * @throws Mage_Core_Exception
19
+ */
20
+ protected function getPreparedCollection()
21
+ {
22
+ $statuses = Mage::getSingleton('sales/config')
23
+ ->getOrderStatusesForState(Mage_Sales_Model_Order::STATE_CANCELED);
24
+ if (empty($statuses)) {
25
+ $statuses = array(0);
26
+ }
27
+
28
+ $collection = Mage::getResourceModel('sales/order_collection');
29
+ $collection
30
+ ->addFieldToFilter('status', array('nin' => $statuses))
31
+ ->addFieldToFilter('state',
32
+ array('nin' => array(
33
+ Mage_Sales_Model_Order::STATE_NEW,
34
+ Mage_Sales_Model_Order::STATE_PENDING_PAYMENT)
35
+ )
36
+ )
37
+ ->addFieldToFilter('customer_id', array('neq' => 'null'))
38
+ ->addOrder('created_at');
39
+
40
+ if ($this->_store) {
41
+ $collection->addFieldToFilter('store_id', $this->_store);
42
+ } else if ($this->_website){
43
+ $storeIds = Mage::app()->getWebsite($this->_website)->getStoreIds();
44
+ $collection->addFieldToFilter('store_id', array('in' => $storeIds));
45
+ } else if ($this->_group){
46
+ $storeIds = Mage::app()->getGroup($this->_group)->getStoreIds();
47
+ $collection->addFieldToFilter('store_id', array('in' => $storeIds));
48
+ }
49
+
50
+ $expr = $this->_getSalesAmountExpression($collection);
51
+ $isFilter = $this->_store || $this->_website || $this->_group;
52
+ if ($isFilter == 0) {
53
+ $expr = '(' . $expr . ') * main_table.base_to_global_rate';
54
+ }
55
+
56
+ $collection->getSelect()
57
+ ->reset(Zend_Db_Select::COLUMNS)
58
+ ->columns(array(
59
+ 'customer_total_orders' => "count(*)",
60
+ 'customer_average_order_value' => "SUM({$expr})/count(*)",
61
+ 'last_order_days_ago' => "DATEDIFF(date(NOW()) , date(MAX(created_at)))"
62
+ ))
63
+ ->group('customer_id');
64
+
65
+ return $collection;
66
+ }
67
+
68
+ /**
69
+ * calculate quartiles
70
+ *
71
+ * @param $array
72
+ * @return array
73
+ */
74
+ protected function calculateQuartile($array){
75
+ if(count($array) == 0)
76
+ return array(
77
+ "Low" => 0,
78
+ "Medium" => 0,
79
+ "High" => 0
80
+ );
81
+
82
+ sort($array);
83
+ $count = count($array);
84
+
85
+ $first = intval(round (.25 * ( $count + 1 )));
86
+ $second = intval(round(.50 * ( $count + 1 )));
87
+ $third = intval(round(.75 * ( $count + 1 )));
88
+
89
+ if(!array_key_exists($first, $array))
90
+ $first = $this->getClosest($first, $array);
91
+
92
+ if(!array_key_exists($second, $array))
93
+ $second = $this->getClosest($second, $array);
94
+
95
+ if(!array_key_exists($third, $array))
96
+ $third = $this->getClosest($third, $array);
97
+
98
+ return array(
99
+ "Low" => $array[$first],
100
+ "Medium" => $array[$second],
101
+ "High" => $array[$third]
102
+ );
103
+ }
104
+
105
+ /**
106
+ * find closest index key from array
107
+ *
108
+ * @param $search
109
+ * @param $arr
110
+ * @return mix
111
+ */
112
+ protected function getClosest($search, $arr) {
113
+ $closest = null;
114
+ foreach($arr as $key => $value) {
115
+ if($search == $key)
116
+ return $search;
117
+ if($closest == null || abs($search - $closest) > abs($key - $search)) {
118
+ $closest = $key;
119
+ }
120
+ }
121
+ return $closest;
122
+ }
123
+
124
+ /**
125
+ * prepare rfm data
126
+ */
127
+ protected function prepareRfm()
128
+ {
129
+ $collection = $this->getPreparedCollection();
130
+
131
+ $this->rfm[self::FREQUENCY] = $this->calculateQuartile($collection->getColumnValues('customer_total_orders'));
132
+ $this->rfm[self::RECENCY] = $this->calculateQuartile($collection->getColumnValues('last_order_days_ago'));
133
+ $this->rfm[self::MONETARY] = $this->calculateQuartile($collection->getColumnValues('customer_average_order_value'));
134
+ }
135
+
136
+ protected function _getSalesAmountExpression($collection)
137
+ {
138
+ $adapter = $collection->getConnection();
139
+ $expressionTransferObject = new Varien_Object(array(
140
+ 'expression' => '%s - %s - %s - (%s - %s - %s)',
141
+ 'arguments' => array(
142
+ $adapter->getIfNullSql('main_table.base_total_invoiced', 0),
143
+ $adapter->getIfNullSql('main_table.base_tax_invoiced', 0),
144
+ $adapter->getIfNullSql('main_table.base_shipping_invoiced', 0),
145
+ $adapter->getIfNullSql('main_table.base_total_refunded', 0),
146
+ $adapter->getIfNullSql('main_table.base_tax_refunded', 0),
147
+ $adapter->getIfNullSql('main_table.base_shipping_refunded', 0),
148
+ )
149
+ ));
150
+
151
+ return vsprintf(
152
+ $expressionTransferObject->getExpression(),
153
+ $expressionTransferObject->getArguments()
154
+ );
155
+
156
+ }
157
+
158
+ /**
159
+ * @param int $store
160
+ * @param int $website
161
+ * @param int $group
162
+ * @return array
163
+ */
164
+ public function getPreparedRfm($store = 0, $website = 0, $group =0)
165
+ {
166
+ $this->_store = $store;
167
+ $this->_group = $group;
168
+ $this->_website = $website;
169
+
170
+ $this->prepareRfm();
171
+ return $this->rfm;
172
+ }
173
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Subscriber.php ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Tabs_Analysis_Subscriber extends Mage_Core_Model_Abstract
4
+ {
5
+ protected $storeIds;
6
+
7
+ protected function calculateOperationalDaysFromOrder()
8
+ {
9
+ $collection = Mage::getResourceModel('sales/order_collection');
10
+ $collection->addFieldToSelect('created_at');
11
+
12
+ if (is_array($this->storeIds) && !empty($this->storeIds)) {
13
+ $collection->addFieldToFilter('store_id', array('in' => $this->storeIds));
14
+ }
15
+
16
+ $collection->getSelect()->columns(array(
17
+ 'days' => "DATEDIFF(date(NOW()) , date(MIN(created_at)))"
18
+ ));
19
+ return $collection->getFirstItem()->getDays();
20
+ }
21
+
22
+ protected function _getCollection(){
23
+ $collection = Mage::getResourceModel('newsletter/subscriber_collection');
24
+ $collection->addFieldToFilter('subscriber_status', array('neq' => '3'));
25
+
26
+ if (is_array($this->storeIds) && !empty($this->storeIds)) {
27
+ $collection->addFieldToFilter('store_id', array('in' => $this->storeIds));
28
+ }
29
+ return $collection;
30
+ }
31
+
32
+ /**
33
+ * prepare collection
34
+ *
35
+ * @return Varien_Object
36
+ */
37
+ protected function getPreparedCollection()
38
+ {
39
+ //all active subscribers
40
+ $collection = $this->_getCollection();
41
+ $totalSubscribers = $collection->count();
42
+
43
+ //all active subscribers who are also customers
44
+ $customerSubscribers = $this->_getCollection();
45
+ $customerSubscribers->addFieldToFilter('customer_id', array('neq' => '0'));
46
+ $customerSubscriberCount = $customerSubscribers->count();
47
+
48
+ $days = $this->calculateOperationalDaysFromOrder();
49
+ if($days)
50
+ $subscribersPerDay = number_format($totalSubscribers/$days, 2);
51
+ else
52
+ $subscribersPerDay = $totalSubscribers;
53
+
54
+ $resultObject = new Varien_Object;
55
+ $resultObject
56
+ ->setTotalSubscriber($totalSubscribers)
57
+ ->setTotalSubscriberCustomer($customerSubscriberCount)
58
+ ->setSubscribersPerDay($subscribersPerDay);
59
+
60
+ return $resultObject;
61
+ }
62
+
63
+ /**
64
+ * @param int $store
65
+ * @param int $website
66
+ * @param int $group
67
+ * @return Varien_Object
68
+ * @throws Mage_Core_Exception
69
+ */
70
+ public function getLifetimeSubscribers($store = 0, $website = 0, $group =0)
71
+ {
72
+ if ($store) {
73
+ $this->storeIds = array($store => $store);
74
+ } else if ($website){
75
+ $storeIds = Mage::app()->getWebsite($website)->getStoreIds();
76
+ $this->storeIds = $storeIds;
77
+ } else if ($group){
78
+ $storeIds = Mage::app()->getGroup($group)->getStoreIds();
79
+ $this->storeIds = $storeIds;
80
+ }
81
+ return $this->getPreparedCollection();
82
+ }
83
+
84
+ /**
85
+ * @return string
86
+ */
87
+ public function getTitle()
88
+ {
89
+ return "Subscribers Analytical Data";
90
+ }
91
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Observer.php ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Observer
4
+ {
5
+
6
+ /**
7
+ * API Sync and Data Mapping.
8
+ * Reset contacts for reimport.
9
+ * @return $this
10
+ */
11
+ public function actionConfigResetContacts()
12
+ {
13
+ $contactModel = Mage::getModel('email_connector/contact');
14
+ $numImported = $contactModel->getNumberOfImportedContacs();
15
+ $updated = $contactModel->resetAllContacts();
16
+ Mage::helper('connector')->log('-- Imported contacts: ' . $numImported . ' reseted : ' . $updated . ' --');
17
+
18
+ /**
19
+ * check for addressbook mapping and disable if no address selected.
20
+ */
21
+ $this->_checkAddressBookMapping(Mage::app()->getRequest()->getParam('website'));
22
+
23
+ return $this;
24
+ }
25
+
26
+ /**
27
+ * API Transactional Section.
28
+ * Default data fields for transactional account.
29
+ * @return $this
30
+ */
31
+ public function saveConfigForTransactional()
32
+ {
33
+ //check for the datafields created for this api account
34
+ $username = Mage::helper('connector/transactional')->getApiUsername();
35
+ $configCreated = Mage::helper('connector')->isConfigCreatedForPath($username);
36
+
37
+ // no need to creat new datafields for this account
38
+ if ($configCreated) {
39
+ return $this;
40
+ }
41
+
42
+ //create default datafields for new api account
43
+ $client = Mage::getModel('email_connector/apiconnector_client');
44
+ $username = Mage::helper('connector/transactional')->getApiUsername();
45
+ $password = Mage::helper('connector/transactional')->getApiPassword();
46
+ $client->setApiUsername($username)->setApiPassword($password);
47
+
48
+ //required datafields for transactional
49
+ $dataFields = Mage::getModel('email_connector/connector_datafield')->getTransactionalDefaultDatafields();
50
+
51
+ foreach ($dataFields as $field) {
52
+ //create the datafields
53
+ $client->postDataFields($field);
54
+ }
55
+ return $this;
56
+ }
57
+
58
+ /**
59
+ * Check if the transactional data feature is enabled
60
+ * To use the wishlist and order sync this needs to be enabled.
61
+ */
62
+ public function checkFeatureActive()
63
+ {
64
+ //scope to retrieve the website id
65
+ $scopeId = 0;
66
+ if ($website = Mage::app()->getRequest()->getParam('website')) {
67
+ //use webiste
68
+ $scope = 'websites';
69
+ $scopeId = Mage::app()->getWebsite($website)->getId();
70
+ } else {
71
+ //set to default
72
+ $scope = "default";
73
+ }
74
+ //webiste by id
75
+ $website = Mage::app()->getWebsite($scopeId);
76
+
77
+ //configuration saved for the wishlist and order sync
78
+ $wishlistEnabled = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_WISHLIST_ENABLED, $scope, $scopeId);
79
+ $orderEnabled = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_ORDER_ENABLED);
80
+
81
+ //only for modification for order and wishlist
82
+ if ($orderEnabled || $wishlistEnabled) {
83
+ //client by website id
84
+ $client = Mage::helper('connector')->getWebsiteApiClient($scopeId);
85
+
86
+ //call request for account info
87
+ $response = $client->getAccountInfo();
88
+
89
+ //properties must be checked
90
+ if (isset($response->properties)) {
91
+ $accountInfo = $response->properties;
92
+ $result = $this->_checkForOption(Dotdigitalgroup_Email_Model_Apiconnector_Client::REST_API_TRANSACTIONAL_DATA_ALLOWANCE, $accountInfo);
93
+
94
+ //account is disabled to use transactional data
95
+ if (! $result) {
96
+ $message = 'Transactional Data For This Account Is Disabled. Call Support To Enable.';
97
+ //send admin message
98
+ Mage::getSingleton('adminhtml/session')->addError($message);
99
+
100
+ //send raygun message for trans data
101
+ Mage::helper('connector')->rayLog('100', $message);
102
+ //disable the config for wishlist and order sync
103
+ $config = Mage::getConfig();
104
+ $config->saveConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_WISHLIST_ENABLED, 0, $scope, $scopeId);
105
+ $config->saveConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_ORDER_ENABLED, 0, $scope, $scopeId);
106
+ $config->cleanCache();
107
+ }
108
+ }
109
+ }
110
+
111
+ return $this;
112
+
113
+ }
114
+
115
+ /**
116
+ * API Credentials.
117
+ * Installation and validation confirmation.
118
+ * @return $this
119
+ */
120
+ public function actionConfigSaveApi()
121
+ {
122
+ $groups = Mage::app()->getRequest()->getPost('groups');
123
+ if (isset($groups['api']['fields']['username']['inherit']) || isset($groups['api']['fields']['password']['inherit']))
124
+ return $this;
125
+
126
+ $apiUsername = isset($groups['api']['fields']['username']['value'])? $groups['api']['fields']['username']['value'] : false;
127
+ $apiPassword = isset($groups['api']['fields']['password']['value'])? $groups['api']['fields']['password']['value'] : false;
128
+ //skip if the inherit option is selected
129
+ if ($apiUsername && $apiPassword) {
130
+ Mage::helper('connector')->log('----VALIDATING ACCOUNT---');
131
+ $testModel = Mage::getModel('email_connector/apiconnector_test');
132
+ $isValid = $testModel->validate($apiUsername, $apiPassword);
133
+ if ($isValid) {
134
+ /**
135
+ * Create account contact datafields
136
+ */
137
+ $client = Mage::getModel('email_connector/apiconnector_client');
138
+ $client->setApiUsername($apiUsername)
139
+ ->setApiPassword($apiPassword);
140
+ $datafields = Mage::getModel('email_connector/connector_datafield')->getDefaultDataFields();
141
+ foreach ($datafields as $datafield) {
142
+ $client->postDataFields($datafield);
143
+ }
144
+ /**
145
+ * Send install info
146
+ */
147
+ $testModel->sendInstallConfirmation();
148
+ } else {
149
+ /**
150
+ * Disable invalid Api credentials
151
+ */
152
+ $scopeId = 0;
153
+ if ($website = Mage::app()->getRequest()->getParam('website')) {
154
+ $scope = 'websites';
155
+ $scopeId = Mage::app()->getWebsite($website)->getId();
156
+ } else {
157
+ $scope = "default";
158
+ }
159
+ $config = Mage::getConfig();
160
+ $config->saveConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED, 0, $scope, $scopeId);
161
+ $config->cleanCache();
162
+ }
163
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('connector')->__('API Credentials Valid.'));
164
+ }
165
+ return $this;
166
+ }
167
+
168
+ private function _checkAddressBookMapping( $website ) {
169
+
170
+ $helper = Mage::helper('connector');
171
+ $customerAddressBook = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMERS_ADDRESS_BOOK_ID, $website);
172
+ $subscriberAddressBook = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SUBSCRIBERS_ADDRESS_BOOK_ID, $website);
173
+
174
+ if (! $customerAddressBook && $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_CONTACT_ENABLED, $website)){
175
+
176
+ $helper->disableConfigForWebsite(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_CONTACT_ENABLED);
177
+ Mage::getSingleton('adminhtml/session')->addNotice('The Contact Sync Disabled - No Addressbook Selected !');
178
+ }
179
+ if (! $subscriberAddressBook && $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_SUBSCRIBER_ENABLED, $website)) {
180
+ $helper->disableConfigForWebsite( Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_SUBSCRIBER_ENABLED );
181
+ Mage::getSingleton('adminhtml/session')->addNotice('The Subscriber Sync Disabled - No Addressbook Selected !');
182
+ }
183
+
184
+ }
185
+
186
+ /**
187
+ * Check for name option in array.
188
+ *
189
+ * @param $name
190
+ * @param $data
191
+ *
192
+ * @return bool
193
+ */
194
+ private function _checkForOption($name, $data) {
195
+ //loop for all options
196
+ foreach ( $data as $one ) {
197
+
198
+ if ($one->name == $name) {
199
+ return true;
200
+ }
201
+ }
202
+
203
+ return false;
204
+ }
205
+
206
+ /**
207
+ * Update Feed for latest releases.
208
+ *
209
+ */
210
+ public function updateFeed()
211
+ {
212
+ Mage::getModel('email_connector/feed')->checkForUpgrade();
213
+ }
214
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Addressbooks.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Addressbooks
4
+ {
5
+ /**
6
+ * Returns the address books options.
7
+ *
8
+ * @return array
9
+ */
10
+ public function toOptionArray()
11
+ {
12
+ $fields = array();
13
+
14
+ $website = Mage::app()->getRequest()->getParam('website');
15
+ $client = Mage::getModel('email_connector/apiconnector_client');
16
+
17
+ $client->setApiUsername(Mage::helper('connector')->getApiUsername($website));
18
+ $client->setApiPassword(Mage::helper('connector')->getApiPassword($website));
19
+
20
+ // Add a "Do Not Map" Option
21
+ $fields[] = array('value' => 0, 'label' => Mage::helper('connector')->__('-- Please Select --'));
22
+ $savedAddressBooks = Mage::registry('addressbooks');
23
+ if ($savedAddressBooks) {
24
+ $addressBooks = $savedAddressBooks;
25
+ } else {
26
+ // api all address books
27
+ $addressBooks = $client->getAddressBooks();
28
+ Mage::register('addressbooks', $addressBooks);
29
+ }
30
+
31
+ if (isset($addressBooks->message)) {
32
+ $fields[] = array('value' => 0, 'label' => Mage::helper('connector')->__('-- Please Select --'));
33
+ }
34
+
35
+ //set up fields with book id and label
36
+ foreach ($addressBooks as $book) {
37
+ if(isset($book->id))
38
+ $fields[] = array('value' => $book->id, 'label' => $book->name);
39
+ }
40
+
41
+ return $fields;
42
+ }
43
+
44
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Abandonedlimit.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Advanced_Abandonedlimit
4
+ {
5
+
6
+ /**
7
+ * available times
8
+ * @var array
9
+ */
10
+ protected $_times = array(0,1,2,3,4,5,6,12,24,36,48,60,72,84,96,108,120, 240);
11
+
12
+
13
+ /**
14
+ * send to campain options hours
15
+ * @return array
16
+ */
17
+ public function toOptionArray()
18
+ {
19
+ $result = $row = array();
20
+ $i = 0;
21
+ foreach ($this->_times as $one) {
22
+
23
+
24
+ if ($i == 0)
25
+ $row = array('value' => $one, 'label' => Mage::helper('connector')->__('No Limit'));
26
+ elseif ($i == 1) {
27
+ $row = array(
28
+ 'value' => $one,
29
+ 'label' => Mage::helper( 'connector' )->__( $one . ' Hour' )
30
+ );
31
+ } else {
32
+ $row = array(
33
+ 'value' => $one,
34
+ 'label' => Mage::helper( 'connector' )->__( $one . ' Hours' )
35
+ );
36
+ }
37
+ $result[] = $row;
38
+ $i++;
39
+ }
40
+
41
+ return $result;
42
+ }
43
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Frequency.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Advanced_Frequency
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ return array(
8
+ array('value' => '1', 'label' => Mage::helper('connector')->__('1 Hour')),
9
+ array('value' => '2', 'label' => Mage::helper('connector')->__('2 Hours')),
10
+ array('value' => '6', 'label' => Mage::helper('connector')->__('6 Hours')),
11
+ array('value' => '12', 'label' => Mage::helper('connector')->__('12 Hours')),
12
+ array('value' => '24', 'label' => Mage::helper('connector')->__('24 Hours'))
13
+ );
14
+ }
15
+ }
app/code/{local/Dotdigitalgroup/Email/Model/System/Config/Source/Orderlimit.php → community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Transdata.php} RENAMED
@@ -1,6 +1,6 @@
1
  <?php
2
 
3
- class Dotdigitalgroup_Email_Model_System_Config_Source_Orderlimit
4
  {
5
  /**
6
  * @return array
1
  <?php
2
 
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Advanced_Transdata
4
  {
5
  /**
6
  * @return array
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Automation/Programme.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Automation_Programme
4
+ {
5
+
6
+ public function toOptionArray()
7
+ {
8
+ $fields = array();
9
+ $websiteName = Mage::app()->getRequest()->getParam('website', false);
10
+ //admin
11
+ $website = 0;
12
+ if ($websiteName) {
13
+ $website = Mage::app()->getWebsite($websiteName);
14
+ }
15
+ $client = Mage::helper('connector')->getWebsiteApiClient($website);
16
+
17
+
18
+ /**
19
+ $savedCampaigns = Mage::registry('savedcampigns');
20
+
21
+ if ($savedCampaigns) {
22
+ $campaigns = $savedCampaigns;
23
+ } else {
24
+ $campaigns = $client->getCampaigns();
25
+ Mage::register('savedcampigns', $campaigns);
26
+ }
27
+ **/
28
+
29
+ $programmes = $client->getPrograms();
30
+ $fields[] = array('value' => '0', 'label' => Mage::helper('connector')->__('-- Disabled --'));
31
+
32
+ foreach ($programmes as $one) {
33
+ if(isset($one->id))
34
+ $fields[] = array('value' => $one->id, 'label' => Mage::helper('connector')->__($one->name));
35
+ }
36
+
37
+ return $fields;
38
+ }
39
+
40
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Campaigns.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Campaigns
4
+ {
5
+
6
+ /**
7
+ * Returns the campaigns options.
8
+ *
9
+ * @return array
10
+ * @throws Mage_Core_Exception
11
+ */
12
+ public function toOptionArray()
13
+ {
14
+ $fields = array();
15
+ $websiteName = Mage::app()->getRequest()->getParam('website', false);
16
+ //admin
17
+ $website = 0;
18
+ if ($websiteName) {
19
+ $website = Mage::app()->getWebsite($websiteName);
20
+ }
21
+ $client = Mage::helper('connector')->getWebsiteApiClient($website);
22
+
23
+
24
+ $savedCampaigns = Mage::registry('savedcampigns');
25
+
26
+ if ($savedCampaigns) {
27
+ $campaigns = $savedCampaigns;
28
+ } else {
29
+ $campaigns = $client->getCampaigns();
30
+ Mage::unregister('savedcampigns');
31
+ Mage::register('savedcampigns', $campaigns);
32
+ }
33
+
34
+ $fields[] = array('value' => '0', 'label' => Mage::helper('connector')->__('-- Please Select --'));
35
+
36
+ foreach ($campaigns as $one) {
37
+ if(isset($one->id))
38
+ $fields[] = array('value' => $one->id, 'label' => Mage::helper('connector')->__(addslashes($one->name)));
39
+ }
40
+
41
+ return $fields;
42
+ }
43
+
44
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Contact/Imported.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Contact_Imported
4
+ {
5
+ /**
6
+ * Contact imported options.
7
+ *
8
+ * @return array
9
+ */
10
+ public function getOptions()
11
+ {
12
+ return array(
13
+ '1' => Mage::helper('connector')->__('Imported'),
14
+ 'null' => Mage::helper('connector')->__('Not Imported'),
15
+ );
16
+ }
17
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Customer/Attributes/Select.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Customer_Attributes_Select
4
+ {
5
+
6
+ /**
7
+ * customer custom attributes.
8
+ *
9
+ * @return array
10
+ */
11
+ public function toOptionArray()
12
+ {
13
+
14
+ $options = array();
15
+ //exclude attributes from mapping
16
+ $excluded =
17
+ array('created_at', 'created_in', 'dob', 'dotmailer_contact_id', 'email', 'firstname', 'lastname', 'gender',
18
+ 'group_id', 'password_hash', 'prefix', 'rp_token', 'rp_token_create_at', 'website_id');
19
+ $attributes = Mage::getModel('customer/customer')->getAttributes();
20
+
21
+ foreach ($attributes as $attribute) {
22
+ if ($attribute->getFrontendLabel()) {
23
+ $code = $attribute->getAttributeCode();
24
+ if(!in_array($code, $excluded))
25
+ $options[] = array(
26
+ 'value' => $attribute->getAttributeCode(),
27
+ 'label' => $attribute->getFrontendLabel()
28
+ );
29
+ }
30
+ }
31
+
32
+ return $options;
33
+ }
34
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Datafields.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Datafields
4
+ {
5
+ /**
6
+ * Datafields option.
7
+ * @return array
8
+ */
9
+ public function toOptionArray()
10
+ {
11
+ $fields = array();
12
+ $helper = Mage::helper('connector');
13
+ $client = $helper->getWebsiteApiClient(Mage::app()->getRequest()->getParam('website', 0));
14
+
15
+ //set datafields saved in register
16
+ $savedDatafields = Mage::registry('datafields');
17
+ if ($savedDatafields) {
18
+ $datafields = $savedDatafields;
19
+ } else {
20
+ //grab the datafields request and save to register
21
+ $datafields = $client->getDataFields();
22
+ Mage::register('datafields', $datafields);
23
+ }
24
+
25
+ //default data option
26
+ $fields[] = array('value' => 0, 'label' => Mage::helper('connector')->__('-- Please Select --'));
27
+
28
+ //set the api error message for the first option
29
+ if (isset($datafields->message)) {
30
+
31
+ //message
32
+ $fields[] = array('value' => 0, 'label' => Mage::helper('connector')->__($datafields->message));
33
+
34
+ } else {
35
+
36
+ //loop for all datafields option
37
+ foreach ( $datafields as $datafield ) {
38
+ if ( isset( $datafield->name ) ) {
39
+ $fields[] = array( 'value' => $datafield->name, 'label' => Mage::helper('connector')->__($datafield->name));
40
+ }
41
+ }
42
+ }
43
+
44
+ return $fields;
45
+ }
46
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Datamapping/Datafieldaccess.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Datamapping_Datafieldaccess
4
+ {
5
+ /**
6
+ * @return array
7
+ */
8
+ public function toOptionArray()
9
+ {
10
+ $dataType = array(
11
+ array('value' => 'Public', 'label' => Mage::helper('connector')->__('Public')),
12
+ array('value' => 'Private', 'label' => Mage::helper('connector')->__('Private')),
13
+ );
14
+
15
+ return $dataType;
16
+ }
17
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Datamapping/Datafieldtype.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Datamapping_Datafieldtype
4
+ {
5
+ /**
6
+ * Datafield model type.
7
+ * Data mapping.
8
+ * @return array
9
+ */
10
+ public function toOptionArray()
11
+ {
12
+ $dataType = array(
13
+ array('value' => 'String', 'label' => Mage::helper('connector')->__('String')),
14
+ array('value' => 'Numeric', 'label' => Mage::helper('connector')->__('Numeric')),
15
+ array('value' => 'Date', 'label' => Mage::helper('connector')->__('Date')),
16
+ array('value' => 'Boolean', 'label' => Mage::helper('connector')->__('Yes/No'))
17
+ );
18
+
19
+ return $dataType;
20
+ }
21
+
22
+ }
app/code/{local/Dotdigitalgroup/Email/Model/System/Config/Source → community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Dynamic}/Displaytype.php RENAMED
@@ -1,8 +1,13 @@
1
  <?php
2
 
3
- class Dotdigitalgroup_Email_Model_System_Config_Source_Displaytype
4
  {
5
- public function toOptionArray()
 
 
 
 
 
6
  {
7
  return array(
8
  array('value' => 'grid', 'label' => Mage::helper('connector')->__('Grid')),
1
  <?php
2
 
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Dynamic_Displaytype
4
  {
5
+ /**
6
+ * Display type mode.
7
+ *
8
+ * @return array
9
+ */
10
+ public function toOptionArray()
11
  {
12
  return array(
13
  array('value' => 'grid', 'label' => Mage::helper('connector')->__('Grid')),
app/code/{local/Dotdigitalgroup/Email/Model/System/Config/Source → community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Dynamic}/Gridview.php RENAMED
@@ -1,7 +1,12 @@
1
  <?php
2
 
3
- class Dotdigitalgroup_Email_Model_System_Config_Source_Gridview
4
  {
 
 
 
 
 
5
  public function toOptionArray()
6
  {
7
  return array(
1
  <?php
2
 
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Dynamic_Gridview
4
  {
5
+ /**
6
+ * grid display options.
7
+ *
8
+ * @return array
9
+ */
10
  public function toOptionArray()
11
  {
12
  return array(
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Lostbaskets/Interval.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Lostbaskets_Interval
4
+ {
5
+
6
+ /**
7
+ * available times
8
+ * @var array
9
+ */
10
+ protected $_times = array(1,2,3,4,5,6,12,24,36,48,60,72,84,96,108,120, 240);
11
+
12
+
13
+ /**
14
+ * send to campain options hours
15
+ * @return array
16
+ */
17
+ public function toOptionArray()
18
+ {
19
+ $result = $row = array();
20
+ $i = 0;
21
+ foreach ($this->_times as $one) {
22
+
23
+ if ($i == 0) {
24
+ $row = array(
25
+ 'value' => $one,
26
+ 'label' => Mage::helper( 'connector' )->__( $one . ' Hour' )
27
+ );
28
+ } else {
29
+ $row = array(
30
+ 'value' => $one,
31
+ 'label' => Mage::helper( 'connector' )->__( $one . ' Hours' )
32
+ );
33
+ }
34
+ $result[] = $row;
35
+ $i++;
36
+ }
37
+
38
+ return $result;
39
+ }
40
+ }
app/code/{local/Dotdigitalgroup/Email/Model/System/Config/Source/Lostbasket.php → community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Lostbaskets/Intervalminute.php} RENAMED
@@ -1,6 +1,6 @@
1
  <?php
2
 
3
- class Dotdigitalgroup_Email_Model_System_Config_Source_Lostbasket
4
  {
5
  /**
6
  * lost basket hour options
1
  <?php
2
 
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Lostbaskets_Intervalminute
4
  {
5
  /**
6
  * lost basket hour options
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Orderdelete.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Orderdelete
4
+ {
5
+ /**
6
+ * Returns the values for field order_delete
7
+ * @return array
8
+ */
9
+ public function toOptionArray()
10
+ {
11
+ return array(
12
+ array('value' => 0, 'label' => Mage::helper('connector')->__('Do Not Delete')),
13
+ array('value' => 7, 'label' => Mage::helper('connector')->__('7 Days')),
14
+ array('value' => 30, 'label' => Mage::helper('connector')->__('30 Days')),
15
+ array('value' => 90, 'label' => Mage::helper('connector')->__('90 Days')),
16
+ array('value' => 180, 'label' => Mage::helper('connector')->__('180 Days')),
17
+ array('value' => 360, 'label' => Mage::helper('connector')->__('360 Days')),
18
+ array('value' => 720, 'label' => Mage::helper('connector')->__('720 Days'))
19
+ );
20
+ }
21
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Orderstatus.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Orderstatus
4
+ {
5
+ /**
6
+ * Returns the order statuses for field order_statuses
7
+ * @return array
8
+ */
9
+ public function toOptionArray()
10
+ {
11
+ $source = Mage::getModel('adminhtml/system_config_source_order_status');
12
+ $statuses = $source->toOptionArray();
13
+
14
+ // Remove the "please select" option if present
15
+ if(count($statuses) > 0 && $statuses[0]['value'] == '')
16
+ array_shift($statuses);
17
+
18
+ $options = array();
19
+
20
+ foreach($statuses as $status) {
21
+ $options[] = array(
22
+ 'value' => $status['value'],
23
+ 'label' => $status['label']
24
+ );
25
+ }
26
+ return $options;
27
+ }
28
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Sweettooth/Yesno.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Sweettooth_Yesno
4
+ {
5
+
6
+ /**
7
+ * Options getter
8
+ *
9
+ * @return array
10
+ */
11
+ public function toOptionArray()
12
+ {
13
+ $status = Mage::helper('connector')->isSweetToothEnabled();
14
+ if($status){
15
+ return array(
16
+ array('value' => 1, 'label'=>Mage::helper('adminhtml')->__('Yes')),
17
+ array('value' => 0, 'label'=>Mage::helper('adminhtml')->__('No')),
18
+ );
19
+ }
20
+
21
+ return array(
22
+ array('value' => 0, 'label'=>Mage::helper('adminhtml')->__('No')),
23
+ );
24
+ }
25
+
26
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Transactional/Campaigns.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Transactional_Campaigns
4
+ {
5
+
6
+ /**
7
+ * Option with campaign data.
8
+ *
9
+ * @return array
10
+ * @throws Mage_Core_Exception
11
+ */
12
+ public function toOptionArray()
13
+ {
14
+ $fields = array();
15
+ $client = Mage::getModel('email_connector/apiconnector_client');
16
+
17
+ //website param
18
+ $websiteName = Mage::app()->getRequest()->getParam('website', false);
19
+ if ($websiteName) {
20
+ $website = Mage::app()->getWebsite($websiteName);
21
+ } else {
22
+ $website = 0;
23
+ $website = Mage::app()->getWebsite($website);
24
+ }
25
+
26
+ //default option
27
+ $fields[] = array('value' => '0', 'label' => Mage::helper('connector')->__('-- Use system default --'));
28
+
29
+ if (!$website->getConfig(Dotdigitalgroup_Email_Helper_Transactional::XML_PATH_TRANSACTIONAL_API_ENABLED))
30
+ return $fields;
31
+
32
+ //set client credentials
33
+ $client->setApiUsername(Mage::helper('connector/transactional')->getApiUsername($website))
34
+ ->setApiPassword(Mage::helper('connector/transactional')->getApiPassword($website));
35
+
36
+ //campaigns from registry
37
+ $savedCampaigns = Mage::registry('savedcampigns');
38
+
39
+ //current campaings from registry
40
+ if ($savedCampaigns) {
41
+ $campaigns = $savedCampaigns;
42
+ } else {
43
+ //save into registry
44
+ $campaigns = $client->getCampaigns();
45
+ Mage::unregister('savedcampigns');
46
+ Mage::register('savedcampigns', $campaigns);
47
+ }
48
+
49
+ //add campign options
50
+ foreach ( $campaigns as $one ) {
51
+ if ( isset( $one->id ) )
52
+ $fields[] = array( 'value' => $one->id, 'label' => Mage::helper( 'connector' )->__( addslashes($one->name)) );
53
+ }
54
+
55
+ return $fields;
56
+ }
57
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Transactional/Customselect.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Transactional_Customselect
4
+ {
5
+
6
+ /**
7
+ * custom email templates - admin transactional emails
8
+ *
9
+ * @return array
10
+ */
11
+ public function toOptionArray()
12
+ {
13
+ $collection = Mage::getResourceModel('core/email_template_collection')
14
+ ->load();
15
+ $options = $collection->toOptionArray();
16
+
17
+ return $options;
18
+ }
19
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Transactional/Defaultselect.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Transactional_Defaultselect
4
+ {
5
+
6
+ /**
7
+ * default email templates - all modules
8
+ *
9
+ * @return array
10
+ */
11
+ public function toOptionArray()
12
+ {
13
+ $options = array();
14
+
15
+ $idLabel = array();
16
+ foreach (Mage_Core_Model_Email_Template::getDefaultTemplates() as $templateId => $row) {
17
+ if (isset($row['@']) && isset($row['@']['module'])) {
18
+ $module = $row['@']['module'];
19
+ } else {
20
+ $module = 'adminhtml';
21
+ }
22
+ $idLabel[$templateId] = Mage::helper($module)->__($row['label'] . " [module = $module]");
23
+ }
24
+ asort($idLabel);
25
+ foreach ($idLabel as $templateId => $label) {
26
+ $options[] = array('value' => $templateId, 'label' => $label);
27
+ }
28
+
29
+ return $options;
30
+ }
31
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Transactional/Fromaddress.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Transactional_Fromaddress
4
+ {
5
+
6
+ /**
7
+ * Returns all custom from addresses.
8
+ *
9
+ * @return array
10
+ * @throws Mage_Core_Exception
11
+ */
12
+ public function toOptionArray()
13
+ {
14
+ $fields = array();
15
+ $client = Mage::getModel('email_connector/apiconnector_client');
16
+
17
+ //website param
18
+ $websiteName = Mage::app()->getRequest()->getParam('website', false);
19
+ if ($websiteName) {
20
+ $website = Mage::app()->getWebsite($websiteName);
21
+ } else {
22
+ //not set use default
23
+ $website = 0;
24
+ $website = Mage::app()->getWebsite($website);
25
+ }
26
+
27
+ //default option
28
+ $fields[] = array('value' => '0', 'label' => Mage::helper('connector')->__('-- Please select --'));
29
+
30
+ //transactional disabled return defualt option
31
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Transactional::XML_PATH_TRANSACTIONAL_API_ENABLED))
32
+ return $fields;
33
+
34
+ //set api credentials
35
+ $client->setApiUsername(Mage::helper('connector/transactional')->getApiUsername($website))
36
+ ->setApiPassword(Mage::helper('connector/transactional')->getApiPassword($website));
37
+
38
+ $savedFromAddressList = Mage::registry('savedFromAddressList');
39
+ //load from regirstry
40
+ if ($savedFromAddressList) {
41
+ $fromAddressList = $savedFromAddressList;
42
+ } else {
43
+ // retrive the transactionals
44
+ $fromAddressList = $client->getCustomFromAddresses();
45
+ Mage::unregister('savedFromAddressList');
46
+ Mage::register('savedFromAddressList', $fromAddressList);
47
+ }
48
+
49
+ //add all options
50
+ foreach ($fromAddressList as $one) {
51
+ if(isset($one->id))
52
+ $fields[] = array('value' => $one->id, 'label' => Mage::helper('connector')->__($one->email));
53
+ }
54
+
55
+ return $fields;
56
+ }
57
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Transactional/Replyactions.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Transactional_Replyactions
4
+ {
5
+
6
+ /**
7
+ * Returns all reply actions for campaign
8
+ *
9
+ * @return array
10
+ */
11
+ public function toOptionArray()
12
+ {
13
+ $fields = array(
14
+ array('value' => '0', 'label' => Mage::helper('connector')->__('-- Please select --')),
15
+ array('value' => 'WebMailForward', 'label' => Mage::helper('connector')->__('Report + Forward')),
16
+ array('value' => 'Webmail', 'label' => Mage::helper('connector')->__('Report')),
17
+ array('value' => 'Delete', 'label' => Mage::helper('connector')->__('Delete'))
18
+ );
19
+ return $fields;
20
+ }
21
+
22
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Transactional/Sendtype.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Transactional_Sendtype
4
+ {
5
+
6
+ /**
7
+ * send type options
8
+ *
9
+ * @return array
10
+ */
11
+ public function toOptionArray()
12
+ {
13
+ $options = array(
14
+ array('value' => Dotdigitalgroup_Email_Helper_Transactional::TRANSACTIONAL_SENDTYPE_SYSTEM_DEFAULT, 'label' => Mage::helper('connector')->__('-- Use system default --')),
15
+ array('value' => Dotdigitalgroup_Email_Helper_Transactional::TRANSACTIONAL_SENDTYPE_VIA_CONNECTOR, 'label' => Mage::helper('connector')->__('-- Send via connector --')),
16
+ array('value' => Dotdigitalgroup_Email_Helper_Transactional::TRANSACTIOANL_SNEDTYPE_DESIGN_VIA_CONNECTOR, 'label' => Mage::helper('connector')->__('-- Design + Send via connector --'))
17
+ );
18
+
19
+ return $options;
20
+ }
21
+ }
app/code/community/Dotdigitalgroup/Email/Model/Apiconnector/Client.php ADDED
@@ -0,0 +1,1125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Apiconnector_Client extends Dotdigitalgroup_Email_Model_Abstract_Rest
4
+ {
5
+ const APICONNECTOR_VERSION = 'V2';
6
+
7
+ const REST_WAIT_UPLOAD_TIME = 5;
8
+ //rest api data
9
+ const REST_ACCOUNT_INFO = 'https://apiconnector.com/v2/account-info';
10
+ const REST_CONTACTS = 'https://apiconnector.com/v2/contacts/';
11
+ const REST_CONTACTS_IMPORT = 'https://apiconnector.com/v2/contacts/import/';
12
+ const REST_ADDRESS_BOOKS = 'https://apiconnector.com/v2/address-books/';
13
+ const REST_DATA_FILEDS = 'https://apiconnector.com/v2/data-fields';
14
+ const REST_TRANSACTIONAL_DATA_IMPORT = 'https://apiconnector.com/v2/contacts/transactional-data/import/';
15
+ const REST_TRANSACTIONAL_DATA = 'https://apiconnector.com/v2/contacts/transactional-data/';
16
+ const REST_CAMPAIGN_SEND = 'https://apiconnector.com/v2/campaigns/send';
17
+ const REST_CONTACTS_SUPPRESSED_SINCE = 'https://apiconnector.com/v2/contacts/suppressed-since/';
18
+ const REST_DATA_FIELDS_CAMPAIGNS = 'https://apiconnector.com/v2/campaigns';
19
+ const REST_SMS_MESSAGE_SEND_TO = 'https://apiconnector.com/v2/sms-messages/send-to/';
20
+ const REST_CONTACTS_RESUBSCRIBE = 'https://apiconnector.com/v2/contacts/resubscribe';
21
+ const REST_CAMPAIGN_FROM_ADDRESS_LIST = 'https://apiconnector.com/v2/custom-from-addresses';
22
+ const REST_CREATE_CAMPAIGN = 'https://apiconnector.com/v2/campaigns';
23
+ const REST_PROGRAM = 'https://api.dotmailer.com/v2/programs/';
24
+ const REST_PROGRAM_ENROLMENTS = 'https://apiconnector.com/v2/programs/enrolments';
25
+
26
+ //rest error responces
27
+ const REST_CONTACT_NOT_FOUND = 'Error: ERROR_CONTACT_NOT_FOUND';
28
+ const REST_SEND_MULTI_TRANSACTIONAL_DATA = 'Error: ERROR_FEATURENOTACTIVE';
29
+ const REST_STATUS_IMPORT_REPORT_NOT_FOUND = 'Import is not processed yet or completed with error. ERROR_IMPORT_REPORT_NOT_FOUND';
30
+ const REST_STATUS_REPORT_NOTFINISHED = 'NotFinished';
31
+ const REST_TRANSACTIONAL_DATA_NOT_EXISTS = 'Error: ERROR_TRANSACTIONAL_DATA_DOES_NOT_EXIST';
32
+ const REST_API_USAGE_EXCEEDED = 'Your account has generated excess API activity and is being temporarily capped. Please contact support. ERROR_APIUSAGE_EXCEEDED';
33
+ const REST_API_EMAIL_NOT_VALID = 'Email is not a valid email address. ERROR_PARAMETER_INVALID';
34
+ const REST_API_DATAFILEDS_EXISTS = 'Field already exists. ERROR_NON_UNIQUE_DATAFIELD';
35
+ const REST_API_AUTHORIZATION_DENIED = 'Authorization has been denied for this request.';
36
+ const REST_API_TRANSACTIONAL_DATA_ALLOWANCE = 'TransactionalDataAllowanceInMegabytes';
37
+
38
+ protected $_customers_file_slug = 'customer_sync';
39
+ protected $_subscribers_file_slug = 'subscriber_sync';
40
+ protected $_api_helper;
41
+ protected $_subscribers_address_book_id;
42
+ protected $_customers_address_book_id;
43
+ protected $_filename;
44
+ protected $_subscribers_filename;
45
+ protected $_customers_filename;
46
+ protected $_limit = 10;
47
+ protected $_address_book_id;
48
+ public $fileHelper; /** @var Dotdigitalgroup_Email_Helper_File */
49
+ public $result = array('error' => false, 'message' => '');
50
+
51
+
52
+ public $apiCalls = array(
53
+ 'getContactById' => 'get_contact_by_id',
54
+ 'postAddressBookContactsImport' => 'post_address_book_contacts_import',
55
+ 'postAddressBookContacts' => 'post_address_book_contacts',
56
+ 'deleteAddressBookContact' => 'delete_address_book_contact',
57
+ 'getContactsImportReport' => 'get_contacts_import',
58
+ 'getContactByEmail' => 'get_contact_by_email',
59
+ 'getAddressBooks' => 'get_address_books',
60
+ 'postAddressBooks' => 'post_address_books',
61
+ 'getCampaigns' => 'get_campaigns',
62
+ 'postDataFields' => 'post_data_fields',
63
+ 'deleteDataField' => 'delete_data_field',
64
+ 'getDataFields' => 'get_data_fields',
65
+ 'updateContact' => 'update_contact',
66
+ 'deleteContact' => 'delete_contact',
67
+ 'updateContactDatafieldsByEmail' => 'update_contact_datafields_by_email',
68
+ 'postCampaignsSend' => 'post_campaigns_send',
69
+ 'postContacts' => 'post_contacts',
70
+ 'getContactsSuppressedSinceDate' => 'get_contacts_suppressed_sinse_date',
71
+ 'postContactsTransactionalDataImport' => 'post_contacts_transactional_data_import',
72
+ 'postContactsTransactionalData' => 'post_contacts_transactional_data',
73
+ 'getContactsTransactionalDataByKey' => 'get_contacts_transactional_data_by_key',
74
+ 'deleteContactTransactionalData' => 'delete_contact_transactional_data',
75
+ 'getAccountInfo' => 'get_account_info',
76
+ 'postSmsMessagesSendTo' => 'post_sms_message_send_to',
77
+ 'deleteAddressBookContactsInbulk' => 'delete_addess_book_contacts_in_bulk',
78
+ 'postContactsResubscribe' => 'post_contacts_resubscribe',
79
+ 'getCustomFromAddresses' => 'get_custom_fromaddresses',
80
+ 'postCampaign' => 'post_campaign',
81
+ 'getPrograms' => 'get_programs',
82
+ 'postProgramsEnrolments' => 'post_programs_enrolments',
83
+ 'getProgramById' => 'get_program_by_id',
84
+ 'getCampaignSummary' => 'get_campaign_summary',
85
+ 'deleteContactsTransactionalData' => 'delete_contacts_transactional_data'
86
+ );
87
+
88
+
89
+ /**
90
+ * constructor.
91
+ */
92
+ public function __construct()
93
+ {
94
+ parent::__construct();
95
+ }
96
+
97
+ /**
98
+ * @param $apiUsername
99
+ * @param $apiPassword
100
+ * @return bool|mixed
101
+ */
102
+ public function validate($apiUsername, $apiPassword)
103
+ {
104
+ if ($apiUsername && $apiPassword) {
105
+ $this->setApiUsername($apiUsername)
106
+ ->setApiPassword($apiPassword);
107
+ $accountInfo = $this->getAccountInfo();
108
+ if (isset($accountInfo->message)) {
109
+ Mage::getSingleton('adminhtml/session')->addError($accountInfo->message);
110
+ $message = 'VALIDATION ERROR : ' . $accountInfo->message;
111
+ Mage::helper('connector')->log($message);
112
+ Mage::helper('connector')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
113
+ return false;
114
+ }
115
+ return $accountInfo;
116
+ }
117
+ return false;
118
+ }
119
+ /**
120
+ * Gets a contact by ID. Unsubscribed or suppressed contacts will not be retrieved.
121
+ * @param $id
122
+ * @return null
123
+ */
124
+ public function getContactById($id)
125
+ {
126
+ $this->_addApiCall($this->apiCalls[__FUNCTION__]);
127
+
128
+ $url = self::REST_CONTACTS . $id;
129
+ $this->setUrl($url)
130
+ ->setVerb('GET');
131
+ $response = $this->execute();
132
+
133
+ if(isset($response->message)) {
134
+ $message = 'GET CONTACT INFO ID ' . $url . ', ' . $response->message;
135
+ Mage::helper( 'connector' )->log( $message );
136
+ Mage::helper('connector')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
137
+ }
138
+
139
+ return $response;
140
+ }
141
+
142
+ /**
143
+ * Bulk creates, or bulk updates, contacts. Import format can either be CSV or Excel.
144
+ * Must include one column called "Email". Any other columns will attempt to map to your custom data fields.
145
+ * The ID of returned object can be used to query import progress.
146
+ * @param $filename
147
+ * @param $addressBookId
148
+ * @return mixed
149
+ */
150
+
151
+ public function postAddressBookContactsImport($filename, $addressBookId)
152
+ {
153
+ $this->_addApiCall($this->apiCalls[__FUNCTION__]);
154
+ $url = "https://apiconnector.com/v2/address-books/{$addressBookId}/contacts/import";
155
+ $helper = Mage::helper('connector');
156
+
157
+ $ch = curl_init($url);
158
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
159
+ curl_setopt($ch, CURLOPT_USERPWD, $this->getApiUsername() . ':' . $this->getApiPassword());
160
+ curl_setopt($ch, CURLOPT_POSTFIELDS, array (
161
+ 'file' => '@'.Mage::helper('connector/file')->getFilePath($filename)
162
+ ));
163
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
164
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
165
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array(
166
+ 'Content-Type: multipart/form-data')
167
+ );
168
+
169
+ // send contacts to address book
170
+ $result = curl_exec($ch);
171
+ $result = json_decode($result);
172
+ if (isset($result->message)) {
173
+ $message = 'POST ADDRESS BOOK ' . $addressBookId . ', CONTACT IMPORT : ' . ' filename ' . $filename . ' Username ' . $this->getApiUsername() . $result->message;
174
+ $helper->log($message);
175
+ Mage::helper('connector')->log($result);
176
+ Mage::helper('connector')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
177
+ }
178
+ return $result;
179
+ }
180
+
181
+ /**
182
+ * Adds a contact to a given address book.
183
+ * @param $addressBookId
184
+ * @param $apiContact
185
+ * @return mixed|null
186
+ */
187
+ public function postAddressBookContacts($addressBookId, $apiContact)
188
+ {
189
+ $this->_addApiCall($this->apiCalls[__FUNCTION__]);
190
+
191
+ $url = self::REST_ADDRESS_BOOKS . $addressBookId . '/contacts';
192
+ $this->setUrl($url)
193
+ ->setVerb("POST")
194
+ ->buildPostBody($apiContact);
195
+
196
+ $response = $this->execute();
197
+ if (isset($response->message)) {
198
+ $message = 'POST ADDRESS BOOK CONTACTS ' . $url . ', ' . $response->message;
199
+ Mage::helper('connector')->log($message);
200
+ Mage::helper('connector')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
201
+ }
202
+
203
+ return $response;
204
+ }
205
+
206
+ /**
207
+ * Deletes all contacts from a given address book.
208
+ * @param $addressBookId
209
+ * @param $contactId
210
+ * @return null
211
+ */
212
+ public function deleteAddressBookContact($addressBookId, $contactId)
213
+ {
214
+ $this->_addApiCall($this->apiCalls[__FUNCTION__]);
215
+
216
+ $url = self::REST_ADDRESS_BOOKS . $addressBookId . '/contacts/' . $contactId;
217
+ $this->setUrl($url)
218
+ ->setVerb('DELETE');
219
+ $response = $this->execute();
220
+ if (isset($response->message)) {
221
+ $message = 'DELETE ADDRESS BOOK CONTACT ' . $url . ', ' . $response->message;
222
+ Mage::helper( 'connector' )->log( $message );
223
+ Mage::helper('connector')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
224
+ }
225
+
226
+ return $response;
227
+ }
228
+
229
+ /**
230
+ * Gets a report with statistics about what was successfully imported, and what was unable to be imported.
231
+ * @param $importId
232
+ * @return mixed
233
+ */
234
+ public function getContactsImportReport($importId)
235
+ {
236
+ $this->_addApiCall($this->apiCalls[__FUNCTION__]);
237
+
238
+ $url = self::REST_CONTACTS_IMPORT . $importId . "/report";
239
+ $this->setUrl($url)
240
+ ->setVerb('GET');
241
+ $response = $this->execute();
242
+ if (isset($response->message)) {
243
+ $message = 'GET CONTACTS IMPORT REPORT . ' . $url . ' message : ' . $response->message;
244
+ Mage::helper( 'connector' )->log( $message );
245
+ Mage::helper( 'connector' )->rayLog( '100', $message, 'apiconnector/client.php', __LINE__);
246
+ }
247
+ return $response;
248
+ }
249
+
250
+ /**
251
+ * Gets a contact by email address.
252
+ * @param $email
253
+ * @return mixed
254
+ */
255
+ public function getContactByEmail($email)
256
+ {
257
+ $this->_addApiCall($this->apiCalls[__FUNCTION__]);
258
+
259
+ $url = self::REST_CONTACTS . $email;
260
+ $this->setUrl($url)
261
+ ->setVerb('GET');
262
+
263
+ //should create new one if not exists?!?
264
+ $response = $this->execute();
265
+ if (isset($response->message)) {
266
+ $message = 'GET CONTACT BY email : ' . $email . ' ' . $response->message;
267
+ Mage::helper('connector')->log($message);
268
+ Mage::helper('connector')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
269
+ }
270
+
271
+ return $response;
272
+ }
273
+
274
+ /**
275
+ * Get all address books.
276
+ * @return null
277
+ */
278
+ public function getAddressBooks()
279
+ {
280
+ $this->_addApiCall($this->apiCalls[__FUNCTION__]);
281
+
282
+ $url = self::REST_ADDRESS_BOOKS;
283
+ $this->setUrl($url)
284
+ ->setVerb("GET");
285
+
286
+ $response = $this->execute();
287
+ if (isset($response->message)) {
288
+ $message = 'GET ALL ADDRESS BOOKS : ' . $url . ', ' . $response->message;
289
+ Mage::helper('connector')->log($message);
290
+ Mage::helper('connector')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
291
+ }
292
+ return $response;
293
+ }
294
+
295
+ /**
296
+ * Creates an address book.
297
+ * @param $name
298
+ * @return null
299
+ */
300
+ public function postAddressBooks($name)
301
+ {
302
+ $this->_addApiCall($this->apiCalls[__FUNCTION__]);
303
+
304
+ $data = array(
305
+ 'Name' => $name,
306
+ 'Visibility' => 'Public'
307
+ );
308
+ $url = self::REST_ADDRESS_BOOKS;
309
+ $this->setUrl($url)
310
+ ->setVerb('POST')
311
+ ->buildPostBody($data);
312
+
313
+ $response = $this->execute();
314
+ if (isset($response->message)) {
315
+ $message = 'Postaddressbooks ' . $response->message . ', url :' . $url ;
316
+ Mage::helper('connector')->log($message);
317
+ Mage::helper('connector')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
318
+ }
319
+ return $response;
320
+ }
321
+
322
+ /**
323
+ * Get list of all campaigns.
324
+ * @return mixed
325
+ */
326
+ public function getCampaigns()
327
+ {
328
+ $this->_addApiCall($this->apiCalls[__FUNCTION__]);
329
+
330
+ $url = self::REST_DATA_FIELDS_CAMPAIGNS;
331
+ $this->setUrl($url)
332
+ ->setVerb('GET');
333
+
334
+ $response = $this->execute();
335
+
336
+ if (isset($response->message)) {
337
+ $message = 'GET CAMPAIGNS ' . $response->message . ' api user : ' . $this->getApiUsername();
338
+ Mage::helper('connector')->log($message);
339
+ Mage::helper('connector')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
340
+ }
341
+
342
+ return $response;
343
+ }
344
+
345
+ /**
346
+ * Creates a data field within the account.
347
+ * @param $data string/array
348
+ * @param string $type string, numeric, date, boolean
349
+ * @param string $visibility public, private
350
+ * @param bool $defaultValue
351
+ * @return mixed
352
+ */
353
+ public function postDataFields($data, $type = 'String', $visibility = 'public', $defaultValue = false)
354
+ {
355
+ $this->_addApiCall($this->apiCalls[__FUNCTION__]);
356
+
357
+ $url = self::REST_DATA_FILEDS;
358
+ //set default value for the numeric datatype
359
+ if($type == 'numeric' && !$defaultValue)
360
+ $defaultValue = 0;
361
+ //set data for the string datatype
362
+ if (is_string($data)) {
363
+ $data = array(
364
+ 'Name' => $data,
365
+ 'Type' => $type,
366
+ 'Visibility' => $visibility
367
+ );
368
+ //default value
369
+ if($defaultValue)
370
+ $data['DefaultValue'] = $defaultValue;
371
+ }
372
+ $this->setUrl($url)
373
+ ->buildPostBody($data)
374
+ ->setVerb('POST');
375
+
376
+ $response = $this->execute();
377
+
378
+ if (isset($response->message)) {
379
+ $message = 'POST CREATE DATAFIELDS ' . $response->message;
380
+ Mage::helper('connector')->log($message);
381
+ Mage::helper('connector')->log($data);
382
+ Mage::helper('connector')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
383
+ }
384
+
385
+ return $response;
386
+ }
387
+
388
+ /**
389
+ * Deletes a data field within the account.
390
+ * @param $name
391
+ *
392
+ * @return mixed
393
+ */
394
+ public function deleteDataField($name)
395
+ {
396
+ $this->_addApiCall($this->apiCalls[__FUNCTION__]);
397
+
398
+ $url = self::REST_DATA_FILEDS . '/' . $name;
399
+ $request = Mage::helper('connector/api_restrequest');
400
+ $request->setUrl($url)
401
+ ->setVerb('DELETE');
402
+
403
+ $response = $request->execute();
404
+ if (isset($response->message)) {
405
+ $message = 'DELETE DATA FIELD :' . $name . ' ' . $response->message;
406
+ Mage::helper('connector')->log($message);
407
+ Mage::helper('connector')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
408
+ }
409
+ return $request->execute();
410
+ }
411
+
412
+ /**
413
+ * Lists the data fields within the account.
414
+ * @return mixed
415
+ */
416
+ public function getDataFields()
417
+ {
418
+ $this->_addApiCall($this->apiCalls[__FUNCTION__]);
419
+
420
+ $url = self::REST_DATA_FILEDS;
421
+ $this->setUrl($url)
422
+ ->setVerb('GET');
423
+
424
+ $response = $this->execute();
425
+ if (isset($response->message)) {
426
+ $message = 'GET ALL DATAFIELDS ' . $response->message;
427
+ Mage::helper('connector')->log($message);
428
+ Mage::helper('connector')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
429
+ }
430
+
431
+ return $response;
432
+ }
433
+
434
+ /**
435
+ * Updates a contact.
436
+ * @param $contactId
437
+ * @param $data
438
+ * @return object
439
+ */
440
+ public function updateContact($contactId, $data)
441
+ {
442
+ $this->_addApiCall($this->apiCalls[__FUNCTION__]);
443
+
444
+ $url = self::REST_CONTACTS . $contactId;
445
+ $this->setUrl($url)
446
+ ->setVerb('PUT')
447
+ ->buildPostBody($data);
448
+
449
+ $response = $this->execute();
450
+ if (isset($response->message)) {
451
+ $message = 'ERROR : UPDATE SINGLE CONTACT : ' . $url . ' message : ' . $response->message;
452
+ Mage::helper('connector')->log($message);
453
+ Mage::helper('connector')->log($data);
454
+ Mage::helper('connector')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
455
+ }
456
+
457
+ return $response;
458
+ }
459
+
460
+ /**
461
+ * Deletes a contact.
462
+ * @param $contactId
463
+ * @return null
464
+ */
465
+ public function deleteContact($contactId)
466
+ {
467
+ $this->_addApiCall($this->apiCalls[__FUNCTION__]);
468
+
469
+ $url = self::REST_CONTACTS . $contactId;
470
+ $this->setUrl($url)
471
+ ->setVerb('DELETE');
472
+
473
+ $response = $this->execute();
474
+
475
+ if (isset($response->message)) {
476
+ $message = 'DELETE CONTACT : ' . $url . ', ' . $response->message;
477
+ Mage::helper('connector')->log($message);
478
+ Mage::helper('connector')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
479
+ }
480
+ return $response;
481
+ }
482
+
483
+ /**
484
+ * Update contact datafields by email.
485
+ * @param $email
486
+ * @param $dataFields
487
+ *
488
+ * @return null
489
+ * @throws Exception
490
+ */
491
+ public function updateContactDatafieldsByEmail($email, $dataFields)
492
+ {
493
+ $this->_addApiCall($this->apiCalls[__FUNCTION__]);
494
+
495
+ $apiContact = $this->postContacts($email);
496
+ //do not create for non contact id set
497
+ if (! isset($apiContact->id)) {
498
+ return $apiContact;
499
+ } else {
500
+ //get the contact id for this email
501
+ $contactId = $apiContact->id;
502
+ }
503
+ $data = array(
504
+ 'Email' => $email,
505
+ 'EmailType' => 'Html');
506
+ $data['DataFields'] = $dataFields;
507
+ $url = self::REST_CONTACTS . $contactId;
508
+ $this->setUrl($url)
509
+ ->setVerb('PUT')
510
+ ->buildPostBody($data);
511
+
512
+ $response = $this->execute();
513
+ if (isset($response->message)) {
514
+ $message = 'ERROR: UPDATE CONTACT DATAFIELD ' . $url . ' message : ' . $response->message;
515
+ Mage::helper('connector')->log($message);
516
+ Mage::helper('connector')->log($data);
517
+ Mage::helper('connector')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
518
+ }
519
+
520
+ return $response;
521
+ }
522
+
523
+ /**
524
+ * Sends a specified campaign to one or more address books, segments or contacts at a specified time.
525
+ * Leave the address book array empty to send to All Contacts.
526
+ * @param $campaignId
527
+ * @param $contacts
528
+ * @return mixed
529
+ */
530
+ public function postCampaignsSend($campaignId, $contacts)
531
+ {
532
+ $this->_addApiCall($this->apiCalls[__FUNCTION__]);
533
+
534
+ $helper = Mage::helper('connector');
535
+ $data = array(
536
+ 'username' => $this->getApiUsername(),
537
+ 'password' => $this->getApiPassword(),
538
+ "campaignId" => $campaignId,
539
+ "ContactIds" => $contacts
540
+ );
541
+ $this->setUrl(self::REST_CAMPAIGN_SEND)
542
+ ->setVerb('POST')
543
+ ->buildPostBody($data);
544
+
545
+ $response = $this->execute();
546
+ if (isset($response->message)) {
547
+ $message = 'SENDING CAMPAIGN ' . $response->message;
548
+ $helper->log($message);
549
+ $helper->log($data);
550
+ Mage::helper('connector')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
551
+ }
552
+
553
+ return $response;
554
+ }
555
+
556
+ /**
557
+ * Creates a contact.
558
+ * @param $email
559
+ * @return mixed
560
+ */
561
+ public function postContacts($email)
562
+ {
563
+ $this->_addApiCall($this->apiCalls[__FUNCTION__]);
564
+
565
+ $url = self::REST_CONTACTS;
566
+ $data = array(
567
+ 'Email' => $email,
568
+ 'EmailType' => 'Html',
569
+ );
570
+ $this->setUrl($url)
571
+ ->setVerb('POST')
572
+ ->buildPostBody($data);
573
+
574
+ $response = $this->execute();
575
+ if (isset($response->message)) {
576
+ $message = 'CREATE A NEW CONTACT : ' . $email . ' , url ' . $url . ', ' . $response->message;
577
+ Mage::helper('connector')->log($message);
578
+ Mage::helper('connector')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
579
+ }
580
+
581
+ return $response;
582
+ }
583
+
584
+ /**
585
+ * @param $testEmail
586
+ * @param $contactId
587
+ * @param $campaignId
588
+ */
589
+ public function sendIntallInfo($testEmail, $contactId, $campaignId)
590
+ {
591
+ $helper = Mage::helper('connector');
592
+ $productSize= Mage::getModel('catalog/product')->getCollection()->getSize();
593
+ $customerSize = Mage::getModel('customer/customer')->getCollection()->getSize();
594
+
595
+ $data = array(
596
+ 'Email' => $testEmail,
597
+ 'EmailType' => 'Html',
598
+ 'DataFields' => array(
599
+ array(
600
+ 'Key' => 'INSTALLCUSTOMERS',
601
+ 'Value' => (string)$customerSize),
602
+ array(
603
+ 'Key' => 'INSTALLPRODUCTS',
604
+ 'Value' => (string)$productSize),
605
+ array(
606
+ 'Key' => 'INSTALLURL',
607
+ 'Value' => Mage::getBaseUrl('web')),
608
+ array(
609
+ 'Key' => 'INSTALLAPI',
610
+ 'Value' => Mage::helper('connector')->getStringWebsiteApiAccounts()),
611
+ array(
612
+ 'Key' => 'PHPMEMORY',
613
+ 'Value' => ini_get('memory_limit') . ', Version = ' . $helper->getConnectorVersion()
614
+ )
615
+ )
616
+ );
617
+ $helper->log('SENDING INSTALL INFO DATA...', Zend_Log::INFO, 'api.log');
618
+ $helper->log($data);
619
+ Mage::helper('connector')->rayLog('100', 'SENDING INSTALL INFO DATA...', 'apiconnector/client.php', __LINE__);
620
+ /**
621
+ * Update data fields for a contact
622
+ */
623
+ $this->updateContact($contactId, $data);
624
+ /**
625
+ * Send Install info campaign
626
+ */
627
+ $this->postCampaignsSend($campaignId, array($contactId));
628
+
629
+ return;
630
+ }
631
+
632
+
633
+ /**
634
+ * Gets a list of suppressed contacts after a given date along with the reason for suppression.
635
+ * @param $dateString
636
+ * @param $select
637
+ * @param $skip
638
+ * @return object
639
+ */
640
+ public function getContactsSuppressedSinceDate($dateString, $select = 1000, $skip = 0)
641
+ {
642
+ $this->_addApiCall($this->apiCalls[__FUNCTION__]);
643
+
644
+ $url = self::REST_CONTACTS_SUPPRESSED_SINCE . $dateString . '?select=' . $select . '&skip=' . $skip;
645
+
646
+ $this->setUrl($url)
647
+ ->setVerb("GET");
648
+
649
+ $response = $this->execute();
650
+ if (isset($response->message)) {
651
+
652
+ $message = 'GET CONTACTS SUPPRESSED SINSE : ' . $dateString . ' select ' . $select . ' skip : ' . $skip . ' response : ' . $response->message;
653
+ Mage::helper('connector')->log($message);
654
+ Mage::helper('connector')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
655
+ }
656
+
657
+ return $response;
658
+ }
659
+
660
+ /**
661
+ * Adds multiple pieces of transactional data to contacts asynchronously, returning an identifier that can be used to check for import progress.
662
+ * @param $collectionName
663
+ * @param $transactionalData
664
+ * @return object
665
+ */
666
+ public function postContactsTransactionalDataImport($transactionalData, $collectionName = 'Orders')
667
+ {
668
+ $this->_addApiCall($this->apiCalls[__FUNCTION__]);
669
+
670
+ $orders = array();
671
+ foreach ($transactionalData as $one) {
672
+ if (isset($one->email)) {
673
+ $orders[] = array(
674
+ 'Key' => $one->id,
675
+ 'ContactIdentifier' => $one->email,
676
+ 'Json' => json_encode($one->expose())
677
+ );
678
+ }
679
+ }
680
+ $url = self::REST_TRANSACTIONAL_DATA_IMPORT . $collectionName;
681
+ $this->setURl($url)
682
+ ->setVerb('POST')
683
+ ->buildPostBody($orders);
684
+
685
+ $result = $this->execute();
686
+
687
+ if (isset($result->message)) {
688
+ $message = ' SEND MULTI TRANSACTIONAL DATA ' . $result->message;
689
+ Mage::helper('connector')->log($message);
690
+ Mage::helper('connector')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
691
+ }
692
+
693
+ return $result;
694
+ }
695
+
696
+ /**
697
+ * Adds a single piece of transactional data to a contact.
698
+ *
699
+ * @param $data
700
+ * @param string $name
701
+ * @return null
702
+ */
703
+ public function postContactsTransactionalData($data, $name = 'Orders')
704
+ {
705
+ $this->_addApiCall($this->apiCalls[__FUNCTION__]);
706
+
707
+ $getData = $this->getContactsTransactionalDataByKey($name, $data->id);
708
+ if(isset($getData->message) && $getData->message == self::REST_TRANSACTIONAL_DATA_NOT_EXISTS){
709
+ $url = self::REST_TRANSACTIONAL_DATA . $name;
710
+ }else{
711
+ $url = self::REST_TRANSACTIONAL_DATA . $name . '/' . $getData->key ;
712
+ }
713
+ $apiData = array(
714
+ 'Key' => $data->id,
715
+ 'ContactIdentifier' => $data->connector_id,
716
+ 'Json' => json_encode($data->expose())
717
+ );
718
+
719
+ $this->setUrl($url)
720
+ ->setVerb('POST')
721
+ ->buildPostBody($apiData);
722
+ $response = $this->execute();
723
+ if (isset($response->message)) {
724
+ $message = 'POST CONTACTS TRANSACTIONAL DATA ' . $response->message;
725
+ Mage::helper('connector')->log($message);
726
+ Mage::helper('connector')->log($apiData);
727
+ Mage::helper('connector')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
728
+ }
729
+
730
+ return $response;
731
+ }
732
+
733
+ /**
734
+ * Gets a piece of transactional data by key.
735
+ * @param $name
736
+ * @param $key
737
+ * @return null
738
+ */
739
+ public function getContactsTransactionalDataByKey($name, $key)
740
+ {
741
+ $this->_addApiCall($this->apiCalls[__FUNCTION__]);
742
+
743
+ $url = self::REST_TRANSACTIONAL_DATA . $name . '/' . $key;
744
+ $this->setUrl($url)
745
+ ->setVerb('GET');
746
+ $response = $this->execute();
747
+ if (isset($response->message)) {
748
+ $message = 'GET CONTACTS TRANSACTIONAL DATA name: ' . $name . ' key: ' . $key . ' ' . $response->message;
749
+ Mage::helper('connector')->log($message);
750
+ Mage::helper('connector')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
751
+ }
752
+
753
+ return $response;
754
+ }
755
+
756
+ /**
757
+ * Deletes all transactional data for a contact.
758
+ * @param $email
759
+ * @param string $collectionName
760
+ * @return object
761
+ */
762
+ public function deleteContactTransactionalData($email, $collectionName = 'Orders')
763
+ {
764
+ $this->_addApiCall($this->apiCalls[__FUNCTION__]);
765
+
766
+ $url = 'https://apiconnector.com/v2/contacts/' . $email . '/transactional-data/' . $collectionName ;
767
+ $this->setUrl($url)
768
+ ->setVerb('DELETE');
769
+ $response = $this->execute();
770
+ if (isset($response->message)) {
771
+
772
+ $message = 'DELETE CONTACT TRANSACTIONAL DATA : ' . $url . ' ' . $response->message;
773
+ Mage::helper('connector')->log($message);
774
+ Mage::helper('connector')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
775
+ }
776
+
777
+ return $response;
778
+ }
779
+
780
+ /**
781
+ * Gets a summary of information about the current status of the account.
782
+ * @return mixed
783
+ */
784
+ public function getAccountInfo()
785
+ {
786
+ $this->_addApiCall($this->apiCalls[__FUNCTION__]);
787
+ $url = self::REST_ACCOUNT_INFO;
788
+ $this->setUrl($url)
789
+ ->setVerb('GET');
790
+
791
+ $response = $this->execute();
792
+ if (isset($response->message)) {
793
+ $message = 'GET ACCOUNT INFO for api user : ' . $this->getApiUsername() . ' ' . $response->message;
794
+ Mage::helper('connector')->log($message);
795
+ Mage::helper('connector')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
796
+ }
797
+
798
+ return $response;
799
+ }
800
+
801
+ /**
802
+ * Send a single SMS message.
803
+ * @param $telephoneNumber
804
+ * @param $message
805
+ * @return object
806
+ */
807
+ public function postSmsMessagesSendTo($telephoneNumber, $message)
808
+ {
809
+ $this->_addApiCall($this->apiCalls[__FUNCTION__]);
810
+
811
+ $data = array('Message' => $message);
812
+ $url = self::REST_SMS_MESSAGE_SEND_TO . $telephoneNumber;
813
+ $this->setUrl($url)
814
+ ->setVerb('POST')
815
+ ->buildPostBody($data);
816
+
817
+ $response = $this->execute();
818
+ if (isset($response->message)) {
819
+ $message = 'POST SMS MESSAGE SEND to ' . $telephoneNumber . ' message: ' . $message . ' error: ' . $response->message;
820
+ Mage::helper('connector')->log($message);
821
+ Mage::helper('connector')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
822
+ }
823
+
824
+ return $response;
825
+ }
826
+
827
+
828
+ /**
829
+ * Deletes multiple contacts from an address book.
830
+ * @param $addressBookId
831
+ * @param $contactIds
832
+ * @return object
833
+ */
834
+ public function deleteAddressBookContactsInbulk($addressBookId, $contactIds)
835
+ {
836
+ $this->_addApiCall($this->apiCalls[__FUNCTION__]);
837
+
838
+ $url = 'https://apiconnector.com/v2/address-books/' . $addressBookId . '/contacts/inbulk';
839
+ $data = array('ContactIds' => array($contactIds[0]));
840
+ $this->setUrl($url)
841
+ ->setVerb('DELETE')
842
+ ->buildPostBody($data);
843
+
844
+ $result = $this->execute();
845
+ if (isset($result->message)) {
846
+ $message = 'DELETE BULK ADDRESS BOOK CONTACTS ' . $result->message . ' address book ' . $addressBookId;
847
+ Mage::helper('connector')->log($message);
848
+ Mage::helper('connector')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
849
+ }
850
+ return $result;
851
+ }
852
+
853
+ /**
854
+ * Resubscribes a previously unsubscribed contact.
855
+ *
856
+ * @param $apiContact
857
+ */
858
+ public function postContactsResubscribe($apiContact)
859
+ {
860
+ $this->_addApiCall($this->apiCalls[__FUNCTION__]);
861
+
862
+ $url = self::REST_CONTACTS_RESUBSCRIBE;
863
+ $data = array(
864
+ 'UnsubscribedContact' => $apiContact
865
+ );
866
+ $this->setUrl($url)
867
+ ->setVerb("POST")
868
+ ->buildPostBody($data);
869
+
870
+ $response = $this->execute();
871
+ if (isset($response->message)) {
872
+ $message = 'Resubscribe : ' . $url . ', message :' . $response->message;
873
+ Mage::helper('connector')->log($message);
874
+ Mage::helper('connector')->log($data);
875
+ Mage::helper('connector')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
876
+ }
877
+ }
878
+
879
+ /**
880
+ * Gets all custom from addresses which can be used in a campaign.
881
+ *
882
+ * @return null
883
+ * @throws Exception
884
+ */
885
+
886
+ public function getCustomFromAddresses()
887
+ {
888
+ $this->_addApiCall($this->apiCalls[__FUNCTION__]);
889
+
890
+ $url = self::REST_CAMPAIGN_FROM_ADDRESS_LIST;
891
+ $this->setUrl($url)
892
+ ->setVerb('GET');
893
+
894
+ $response = $this->execute();
895
+
896
+ if (isset($response->message)) {
897
+
898
+ $message = 'GET CampaignFromAddressList ' . $response->message . ' api user : ' . $this->getApiUsername();
899
+ Mage::helper('connector')->log($message);
900
+ Mage::helper('connector')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
901
+ }
902
+
903
+ return $response;
904
+ }
905
+
906
+ /**
907
+ * Creates a campaign.
908
+ * @param $data
909
+ *
910
+ * @return null
911
+ * @throws Exception
912
+ */
913
+ public function postCampaign($data)
914
+ {
915
+ $this->_addApiCall($this->apiCalls[__FUNCTION__]);
916
+
917
+ $url = self::REST_CREATE_CAMPAIGN;
918
+ $this->setURl($url)
919
+ ->setVerb('POST')
920
+ ->buildPostBody($data);
921
+
922
+ $result = $this->execute();
923
+
924
+ if (isset($result->message)) {
925
+ $message = ' CREATE CAMPAIGN ' . $result->message;
926
+ Mage::helper('connector')->log($message);
927
+ Mage::helper('connector')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
928
+ }
929
+
930
+ return $result;
931
+ }
932
+
933
+ /**
934
+ * Gets all programs.
935
+ * https://api.dotmailer.com/v2/programs?select={select}&skip={skip}
936
+ */
937
+ public function getPrograms()
938
+ {
939
+ $this->_addApiCall($this->apiCalls[__FUNCTION__]);
940
+
941
+ $url = 'https://api.dotmailer.com/v2/programs';
942
+
943
+ $this->setUrl($url)
944
+ ->setVerb('GET');
945
+
946
+ $response = $this->execute();
947
+
948
+ if (isset($response->message)) {
949
+ $message = 'Get programmes : ' . $response->message ;
950
+ Mage::helper( 'connector' )->log($message);
951
+ Mage::helper('connector')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
952
+ }
953
+
954
+ return $response;
955
+ }
956
+
957
+ /**
958
+ * Creates an enrolment.
959
+ * @param $data
960
+ *
961
+ * @return null
962
+ * @throws Exception
963
+ */
964
+ public function postProgramsEnrolments($data)
965
+ {
966
+ $this->_addApiCall($this->apiCalls[__FUNCTION__]);
967
+
968
+ $url = self::REST_PROGRAM_ENROLMENTS;
969
+ $this->setUrl($url)
970
+ ->setVerb('POST')
971
+ ->buildPostBody($data);
972
+
973
+ $response = $this->execute();
974
+ if (isset($response->message)) {
975
+ $message = 'Post programs enrolments : ' . $response->message;
976
+ Mage::helper('connector')->log($message);
977
+ Mage::helper('connector')->log($data);
978
+ Mage::helper('connector')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
979
+ }
980
+
981
+ return $response;
982
+ }
983
+
984
+ /**
985
+ * Gets a program by id.
986
+ * @param $id
987
+ *
988
+ * @return null
989
+ * @throws Exception
990
+ */
991
+ public function getProgramById( $id )
992
+ {
993
+ $this->_addApiCall($this->apiCalls[__FUNCTION__]);
994
+
995
+ $url = self::REST_PROGRAM . $id;
996
+ $this->setUrl($url)
997
+ ->setVerb('GET');
998
+
999
+ $response = $this->execute();
1000
+ if (isset($response->message)) {
1001
+ $message = 'Get program by id ' . $response->message . ', id ' . $id;
1002
+ Mage::helper( 'connector' )->log( $message);
1003
+ Mage::helper("connector")->rayLog(100, $message, 'apiconnector/client.php', __LINE__);
1004
+
1005
+ }
1006
+
1007
+ return $response;
1008
+ }
1009
+
1010
+ /**
1011
+ * Gets a summary of reporting information for a specified campaign.
1012
+ * @param $campaignId
1013
+ *
1014
+ * @return null
1015
+ * @throws Exception
1016
+ */
1017
+ public function getCampaignSummary($campaignId)
1018
+ {
1019
+ $this->_addApiCall($this->apiCalls[__FUNCTION__]);
1020
+
1021
+ $url = 'https://apiconnector.com/v2/campaigns/' . $campaignId . '/summary';
1022
+
1023
+ $this->setUrl($url)
1024
+ ->setVerb('GET');
1025
+ $response = $this->execute();
1026
+
1027
+ if (isset($response->message)) {
1028
+ $message = 'Get Campaign Summary ' . $response->message . ' ,url : ' . $url;
1029
+ Mage::helper('connector')->log( $message );
1030
+ Mage::helper('connector')->rayLog(100, $message, 'apiconnector/client.php', __LINE__);
1031
+ }
1032
+
1033
+ return $response;
1034
+ }
1035
+
1036
+ private function _addApiCall($path, $scope = 'default'){
1037
+ //log all api calls
1038
+ if (Mage::getStoreConfigFlag(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DEBUG_API_CALLS))
1039
+ Mage::helper('connector')->log('Api call was made with path : ' . $path);
1040
+
1041
+ $configModel = Mage::getModel('email_connector/config');
1042
+ $configLastRun = $configModel->getHourTrigger();
1043
+
1044
+ try {
1045
+
1046
+ // check for last hour reset
1047
+ if ($configLastRun) {
1048
+
1049
+ //last run found let's check the difference
1050
+ $configLastRun = Mage::app()->getLocale()->date($configLastRun);
1051
+ $now = Mage::app()->getLocale()->date();
1052
+
1053
+ // reset the time and calls for the last hour or older by date
1054
+ if ($now->compareHour($configLastRun) == 1 || $now->compareDay($configLastRun) == 1){
1055
+
1056
+ // update the hour trigger
1057
+ $hourTriggerModel = Mage::getModel('email_connector/config')->getCollection()
1058
+ ->addFieldToFilter('path', Dotdigitalgroup_Email_Helper_Config::CONNECTOR_EMAIL_CONFIG_HOUR_TRIGGER)
1059
+ ->getFirstItem();
1060
+ //reset trigger
1061
+ $hourTriggerModel->setValue($now->toString(Zend_Date::ISO_8601))
1062
+ ->setScope($scope)
1063
+ ->save();
1064
+
1065
+ //reseting the api calls
1066
+ $this->_resetConfigApiCallsForLastHour();
1067
+ } else {
1068
+
1069
+ // increment the number for api call
1070
+ $apiCount = $configModel->getValueByPath($path);
1071
+ $value = $apiCount->getValue();
1072
+ $apiCount->setScope($scope)
1073
+ ->setIsApi('1')
1074
+ ->setValue(++$value)
1075
+ ->save();
1076
+ }
1077
+
1078
+ } else {
1079
+ // save the current date
1080
+ $date = Mage::getModel('core/date')->date(Zend_Date::ISO_8601);
1081
+ $configModel->setPath(Dotdigitalgroup_Email_Helper_Config::CONNECTOR_EMAIL_CONFIG_HOUR_TRIGGER)
1082
+ ->setScope($scope)
1083
+ ->setValue($date)
1084
+ ->save();
1085
+ }
1086
+ }catch (Exception $e){
1087
+ Mage::logException($e);
1088
+ }
1089
+
1090
+ }
1091
+
1092
+ private function _resetConfigApiCallsForLastHour() {
1093
+ foreach ( $this->apiCalls as $key => $path ) {
1094
+ $config = Mage::getModel('email_connector/config')->getCollection()
1095
+ ->addFieldToFilter('is_api', true)
1096
+ ->addFieldToFilter('path', $path)
1097
+ ->getFirstItem()
1098
+ ;
1099
+
1100
+ $config->setPath($path)
1101
+ ->setValue(0)
1102
+ ->save();
1103
+ }
1104
+ }
1105
+
1106
+ /**
1107
+ * Deletes a piece of transactional data by key.
1108
+ * @param $key
1109
+ * @param string $collectionName
1110
+ * @return object
1111
+ */
1112
+ public function deleteContactsTransactionalData($key, $collectionName = 'Orders')
1113
+ {
1114
+ $this->_addApiCall($this->apiCalls[__FUNCTION__]);
1115
+
1116
+ $url = 'https://apiconnector.com/v2/contacts/transactional-data/' . $collectionName .'/' . $key ;
1117
+ $this->setUrl($url)
1118
+ ->setVerb('DELETE');
1119
+ $response = $this->execute();
1120
+ if (isset($response->message))
1121
+ Mage::helper('connector')->log('DELETE CONTACTS TRANSACTIONAL DATA : ' . $url . ' ' . $response->message);
1122
+
1123
+ return $response;
1124
+ }
1125
+ }
app/code/community/Dotdigitalgroup/Email/Model/Apiconnector/Contact.php ADDED
@@ -0,0 +1,394 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Apiconnector_Contact
4
+ {
5
+ private $_start;
6
+ private $_countCustomers;
7
+ private $_wishlists;
8
+
9
+ /**
10
+ * Contact sync.
11
+ *
12
+ * @return array
13
+ */
14
+ public function sync()
15
+ {
16
+ $result = array('success' => true, 'message' => '');
17
+ /** @var Dotdigitalgroup_Email_Helper_Data $helper */
18
+ $helper = Mage::helper('connector');
19
+ $helper->log('---------- Start customer sync ----------');
20
+ $this->_start = microtime(true);
21
+ //resourse allocation
22
+ $helper->allowResourceFullExecution();
23
+ foreach (Mage::app()->getWebsites(true) as $website) {
24
+ $enabled = Mage::helper('connector')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED, $website);
25
+ $sync = Mage::helper('connector')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_CONTACT_ENABLED, $website);
26
+ if ($enabled && $sync) {
27
+
28
+ $numUpdated = $this->exportCustomersForWebsite($website);
29
+ // show message for any number of customers
30
+ if ($numUpdated)
31
+ $result['message'] .= '</br>' . $website->getName() . ', updated customers = ' . $numUpdated;
32
+ }
33
+ }
34
+ $message = 'Total time for sync : ' . gmdate("H:i:s", microtime(true) - $this->_start) . ', Total updated = ' . $this->_countCustomers;
35
+ $helper->log($message);
36
+
37
+ if ($this->_countCustomers) {
38
+ $message .= $result['message'];
39
+ $result['message'] = $message;
40
+ }
41
+
42
+ return $result;
43
+ }
44
+
45
+ /**
46
+ * Execute the contact sync for the website
47
+ * number of customer synced.
48
+ * @param Mage_Core_Model_Website $website
49
+ *
50
+ * @return int|void
51
+ */
52
+ public function exportCustomersForWebsite(Mage_Core_Model_Website $website)
53
+ {
54
+ $updated = 0;
55
+ $customers = $headers = $allMappedHash = array();
56
+ $helper = Mage::helper('connector');
57
+ $pageSize = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_LIMIT, $website);
58
+ //skip if the mapping field is missing
59
+ if ( !$helper->getCustomerAddressBook($website))
60
+ return;
61
+ //reset wishlists
62
+ $this->_wishlists = array();
63
+ $fileHelper = Mage::helper('connector/file');
64
+ $contactModel = Mage::getModel('email_connector/contact');
65
+ $client = Mage::helper('connector')->getWebsiteApiClient($website);
66
+ $contacts = $contactModel->getContactsToImportForWebsite($website->getId(), $pageSize);
67
+
68
+ // no contacts for this webiste
69
+ if (!count($contacts))
70
+ return;
71
+ //create customer filename
72
+ $customersFile = strtolower($website->getCode() . '_customers_' . date('d_m_Y_Hi') . '.csv');
73
+ $helper->log('Customers file : ' . $customersFile);
74
+
75
+ //get customer ids
76
+ $customerIds = array();
77
+ foreach ($contacts as $contact) {
78
+ $customerIds[] = $contact->getCustomerId();
79
+ //remove contact with customer id set and no customer
80
+ if (! Mage::getModel('customer/customer')->load($contact->getCustomerId())->getId())
81
+ $contact->delete();
82
+ }
83
+
84
+ //customer collection
85
+ $customerCollection = $this->getCollection($customerIds, $website);
86
+
87
+ /**
88
+ * HEADERS.
89
+ */
90
+ $mappedHash = $fileHelper->getWebsiteCustomerMappingDatafields($website);
91
+ $headers = $mappedHash;
92
+ //custom customer attributes
93
+ $customAttributes = $helper->getCustomAttributes($website);
94
+ foreach ($customAttributes as $data) {
95
+ $headers[] = $data['datafield'];
96
+ $allMappedHash[$data['attribute']] = $data['datafield'];
97
+ }
98
+ $headers[] = 'Email';
99
+ $headers[] = 'EmailType';
100
+ $fileHelper->outputCSV($fileHelper->getFilePath($customersFile), $headers);
101
+ /**
102
+ * END HEADERS.
103
+ */
104
+
105
+
106
+ foreach ($customerCollection as $customer) {
107
+ $contactModel = Mage::getModel('email_connector/contact')->loadByCustomerEmail($customer->getEmail(), $website->getId());
108
+ //remove contact with customer id set and no customer
109
+ if(!$contactModel->getId()){
110
+ Mage::helper("connector")->log('clean contact email :' . $customer->getEmail());
111
+ $contactModel->delete();
112
+ continue;
113
+ }
114
+ /**
115
+ * DATA.
116
+ */
117
+ $connectorCustomer = Mage::getModel('email_connector/apiconnector_customer', $mappedHash);
118
+ $connectorCustomer->setCustomerData($customer, $website);
119
+ //count number of customers
120
+ $customers[] = $connectorCustomer;
121
+ foreach ($customAttributes as $data) {
122
+ $attribute = $data['attribute'];
123
+ $value = $customer->getData($attribute);
124
+ $connectorCustomer->setData($value);
125
+ }
126
+ //contact email and email type
127
+ $connectorCustomer->setData($customer->getEmail());
128
+ $connectorCustomer->setData('Html');
129
+ // save csv file data for customers
130
+ $fileHelper->outputCSV($fileHelper->getFilePath($customersFile), $connectorCustomer->toCSVArray());
131
+
132
+ /**
133
+ * END DATA.
134
+ */
135
+
136
+ //mark the contact as imported
137
+ $contactModel->setEmailImported(Dotdigitalgroup_Email_Model_Contact::EMAIL_CONTACT_IMPORTED);
138
+ $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($customer->getEmail());
139
+ if ($subscriber->isSubscribed()) {
140
+ $contactModel->setIsSubscriber(1)
141
+ ->setSubscriberStatus($subscriber->getSubscriberStatus());
142
+ }
143
+
144
+ $contactModel->save();
145
+
146
+ //Send wishlist as transactional data
147
+ if ($helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_WISHLIST_ENABLED, $website)) {
148
+ $this->_setCustomerWishList($customer, $website);
149
+ }
150
+ $updated++;
151
+ }
152
+ //send wishlist as transactional data
153
+ if (isset($this->_wishlists[$website->getId()])) {
154
+ //send wishlists as transactional data
155
+ $websiteWishlists = $this->_wishlists[$website->getId()];
156
+ //remove wishlists one by one
157
+ foreach ($websiteWishlists as $wishlist) {
158
+ $email = $wishlist->email;
159
+ $client->deleteContactTransactionalData($email, 'Wishlist');
160
+ }
161
+ //import wishlists in bulk
162
+ $client->postContactsTransactionalDataImport($websiteWishlists, 'Wishlist');
163
+ }
164
+
165
+ $customerNum = count($customers);
166
+ $helper->log('Website : ' . $website->getName() . ', customers = ' . $customerNum);
167
+ $helper->log('---------------------------- execution time :' . gmdate("H:i:s", microtime(true) - $this->_start));
168
+
169
+ if (file_exists($fileHelper->getFilePath($customersFile))) {
170
+ //import contacts
171
+ if ($updated > 0)
172
+ $client->postAddressBookContactsImport($customersFile, $helper->getCustomerAddressBook($website));
173
+ //archive file on success
174
+ $fileHelper->archiveCSV($customersFile);
175
+ }
176
+ $this->_countCustomers += $updated;
177
+ return $customerNum;
178
+ }
179
+
180
+ /**
181
+ * @param $customer
182
+ * @param $website
183
+ */
184
+ private function _setCustomerWishList($customer, $website){
185
+ $website = Mage::app()->getWebsite($website);
186
+ $customerId = $customer->getId();
187
+ $wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($customerId);
188
+ /** @var $connectorWishlist */
189
+ $connectorWishlist = Mage::getModel('email_connector/customer_wishlist', $customer);
190
+ $connectorWishlist->setId($wishlist->getId());
191
+ $wishListItemCollection = $wishlist->getItemCollection();
192
+ if (count($wishListItemCollection)) {
193
+ foreach ($wishListItemCollection as $item) {
194
+ /* @var $product Mage_Catalog_Model_Product */
195
+ $product = $item->getProduct();
196
+ $wishlistItem = Mage::getModel('email_connector/customer_wishlist_item', $product)
197
+ ->setQty($item->getQty())
198
+ ->setPrice($product);
199
+ //store for wishlists
200
+ $connectorWishlist->setItem($wishlistItem);
201
+ }
202
+ //set wishlists for later use
203
+ $this->_wishlists[$website->getId()][] = $connectorWishlist;
204
+ }
205
+ }
206
+
207
+ /**
208
+ * Sync a single contact.
209
+ *
210
+ * @param null $contactId
211
+ *
212
+ * @return mixed
213
+ * @throws Mage_Core_Exception
214
+ */
215
+ public function syncContact($contactId = null)
216
+ {
217
+ if ($contactId)
218
+ $contact = Mage::getModel('email_connector/contact')->load($contactId);
219
+ else {
220
+ $contact = Mage::registry('current_contact');
221
+ }
222
+ if (! $contact->getId()) {
223
+ Mage::getSingleton('adminhtml/session')->addError('No contact found!');
224
+ return false;
225
+ }
226
+
227
+ $websiteId = $contact->getWebsiteId();
228
+ $website = Mage::app()->getWebsite($websiteId);
229
+ $updated = 0;
230
+ $customers = $headers = $allMappedHash = array();
231
+ $helper = Mage::helper('connector');
232
+ $helper->log('---------- Start single customer sync ----------');
233
+ //skip if the mapping field is missing
234
+ if(!$helper->getCustomerAddressBook($website))
235
+ return false;
236
+ //reset wishlists
237
+ $this->_wishlists = array();
238
+ $fileHelper = Mage::helper('connector/file');
239
+
240
+ $customerId = $contact->getCustomerId();
241
+ if (!$customerId) {
242
+ Mage::getSingleton('adminhtml/session')->addError('Cannot manually sync guests!');
243
+ return false;
244
+ }
245
+ $client = Mage::helper('connector')->getWebsiteApiClient($website);
246
+
247
+ //create customer filename
248
+ $customersFile = strtolower($website->getCode() . '_customers_' . date('d_m_Y_Hi') . '.csv');
249
+ $helper->log('Customers file : ' . $customersFile);
250
+
251
+ /**
252
+ * HEADERS.
253
+ */
254
+ $mappedHash = $fileHelper->getWebsiteCustomerMappingDatafields($website);
255
+ $headers = $mappedHash;
256
+ //custom customer attributes
257
+ $customAttributes = $helper->getCustomAttributes($website);
258
+ foreach ($customAttributes as $data) {
259
+ $headers[] = $data['datafield'];
260
+ $allMappedHash[$data['attribute']] = $data['datafield'];
261
+ }
262
+
263
+ $headers[] = 'Email';
264
+ $headers[] = 'EmailType';
265
+ $fileHelper->outputCSV($fileHelper->getFilePath($customersFile), $headers);
266
+ /**
267
+ * END HEADERS.
268
+ */
269
+ $customerCollection = $this->getCollection(array($customerId));
270
+
271
+ foreach ($customerCollection as $customer) {
272
+ $contactModel = Mage::getModel('email_connector/contact')->loadByCustomerEmail($customer->getEmail(), $websiteId);
273
+ //skip contacts without customer id
274
+ if (!$contactModel->getId())
275
+ continue;
276
+ /**
277
+ * DATA.
278
+ */
279
+ $connectorCustomer = Mage::getModel('email_connector/apiconnector_customer', $mappedHash);
280
+ $connectorCustomer->setCustomerData($customer, $website);
281
+ //count number of customers
282
+ $customers[] = $connectorCustomer;
283
+ foreach ($customAttributes as $data) {
284
+ $attribute = $data['attribute'];
285
+ $value = $customer->getData($attribute);
286
+ $connectorCustomer->setData($value);
287
+ }
288
+ //contact email and email type
289
+ $connectorCustomer->setData($customer->getEmail());
290
+ $connectorCustomer->setData('Html');
291
+ // save csv file data for customers
292
+ $fileHelper->outputCSV($fileHelper->getFilePath($customersFile), $connectorCustomer->toCSVArray());
293
+
294
+ /**
295
+ * END DATA.
296
+ */
297
+
298
+ //mark the contact as imported
299
+ $contactModel->setEmailImported(Dotdigitalgroup_Email_Model_Contact::EMAIL_CONTACT_IMPORTED);
300
+ $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($customer->getEmail());
301
+ if ($subscriber->isSubscribed()) {
302
+ $contactModel->setIsSubscriber('1')
303
+ ->setSubscriberStatus($subscriber->getSubscriberStatus());
304
+ }
305
+
306
+ $contactModel->save();
307
+
308
+ Mage::helper("connector")->log($contactModel->getData());
309
+
310
+ //Send wishlist as transactional data
311
+ if ($helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_WISHLIST_ENABLED, $website)) {
312
+ $this->_setCustomerWishList($customer, $website);
313
+ }
314
+ $updated++;
315
+ }
316
+
317
+ //send wishlist as transactional data
318
+ if (isset($this->_wishlists[$website->getId()])) {
319
+ //send wishlists as transactional data
320
+ $websiteWishlists = $this->_wishlists[$website->getId()];
321
+ //remove wishlists one by one
322
+ foreach ($websiteWishlists as $wishlist) {
323
+ $email = $wishlist->email;
324
+ $client->deleteContactTransactionalData($email, 'Wishlist');
325
+ }
326
+ //import wishlists in bulk
327
+ $client->postContactsTransactionalDataImport($websiteWishlists, 'Wishlist');
328
+ }
329
+
330
+ if (file_exists($fileHelper->getFilePath($customersFile))) {
331
+ //import contacts
332
+ if ($updated > 0)
333
+ $client->postAddressBookContactsImport($customersFile, $helper->getCustomerAddressBook($website));
334
+ //archive file on success
335
+ $fileHelper->archiveCSV($customersFile);
336
+ }
337
+ return $contact->getEmail();
338
+ }
339
+
340
+
341
+ /**
342
+ * get customer collection
343
+ * @param $customerIds
344
+ * @param $website null
345
+ * @return Mage_Eav_Model_Entity_Collection_Abstract
346
+ * @throws Mage_Core_Exception
347
+ */
348
+ public function getCollection($customerIds, $website = null)
349
+ {
350
+ $customerCollection = Mage::getResourceModel('customer/customer_collection')
351
+ ->addNameToSelect()
352
+ ->addAttributeToSelect('*')
353
+ ->joinAttribute('billing_street', 'customer_address/street', 'default_billing', null, 'left')
354
+ ->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
355
+ ->joinAttribute('billing_country_code', 'customer_address/country_id', 'default_billing', null, 'left')
356
+ ->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
357
+ ->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')
358
+ ->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
359
+ ->joinAttribute('shipping_street', 'customer_address/street', 'default_shipping', null, 'left')
360
+ ->joinAttribute('shipping_city', 'customer_address/city', 'default_shipping', null, 'left')
361
+ ->joinAttribute('shipping_country_code','customer_address/country_id', 'default_shipping', null, 'left')
362
+ ->joinAttribute('shipping_postcode', 'customer_address/postcode', 'default_shipping', null, 'left')
363
+ ->joinAttribute('shipping_telephone', 'customer_address/telephone', 'default_shipping', null, 'left')
364
+ ->joinAttribute('shipping_region', 'customer_address/region', 'default_shipping', null, 'left')
365
+ ->addAttributeToFilter('entity_id', array('in' => $customerIds));
366
+ $customer_log = Mage::getSingleton('core/resource')->getTableName('log_customer');
367
+ $sales_flat_order_grid = Mage::getSingleton('core/resource')->getTableName('sales_flat_order_grid');
368
+
369
+ // get the last login date from the log_customer table
370
+ $customerCollection->getSelect()->columns(
371
+ array('last_logged_date' => new Zend_Db_Expr ("(SELECT login_at FROM $customer_log WHERE customer_id =e.entity_id ORDER BY log_id DESC LIMIT 1)")));
372
+
373
+ // customer order information
374
+ $alias = 'subselect';
375
+ $subselect = Mage::getModel('Varien_Db_Select', Mage::getSingleton('core/resource')->getConnection('core_read'))
376
+ ->from($sales_flat_order_grid, array(
377
+ 'customer_id as s_customer_id',
378
+ 'sum(grand_total) as total_spend',
379
+ 'count(*) as number_of_orders',
380
+ 'avg(grand_total) as average_order_value',
381
+ )
382
+ )->group('customer_id')
383
+ ;
384
+ $customerCollection->getSelect()->columns(array(
385
+ 'last_order_date' => new Zend_Db_Expr("(SELECT created_at FROM $sales_flat_order_grid WHERE customer_id =e.entity_id ORDER BY created_at DESC LIMIT 1)"),
386
+ 'last_order_id' => new Zend_Db_Expr("(SELECT entity_id FROM $sales_flat_order_grid WHERE customer_id =e.entity_id ORDER BY created_at DESC LIMIT 1)")
387
+ )
388
+ );
389
+ $customerCollection->getSelect()
390
+ ->joinLeft(array($alias => $subselect), "{$alias}.s_customer_id = e.entity_id");
391
+
392
+ return $customerCollection;
393
+ }
394
+ }
app/code/community/Dotdigitalgroup/Email/Model/Apiconnector/Customer.php ADDED
@@ -0,0 +1,621 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Apiconnector_Customer
4
+ {
5
+
6
+ public $customer;
7
+ public $customerData;
8
+ public $reviewCollection;
9
+
10
+ public $rewardCustomer;
11
+ public $rewardLastSpent = "";
12
+ public $rewardLastEarned = "";
13
+ public $rewardExpiry = "";
14
+
15
+ protected $_mapping_hash;
16
+
17
+
18
+ /**
19
+ * constructor, mapping hash to map.
20
+ *
21
+ * @param $mappingHash
22
+ */
23
+ public function __construct( $mappingHash)
24
+ {
25
+ $this->setMappigHash($mappingHash);
26
+ }
27
+
28
+ /**
29
+ * Set key value data.
30
+ *
31
+ * @param $data
32
+ */
33
+ public function setData($data)
34
+ {
35
+ $this->customerData[] = $data;
36
+ }
37
+
38
+ /**
39
+ * Set customer data.
40
+ *
41
+ * @param Mage_Customer_Model_Customer $customer
42
+ */
43
+ public function setCustomerData(Mage_Customer_Model_Customer $customer, $website = null)
44
+ {
45
+ $helper = Mage::helper('connector');
46
+
47
+ $this->customer = $customer;
48
+ $this->setReviewCollection();
49
+
50
+ if($website && $helper->isSweetToothToGo($website))
51
+ $this->setRewardCustomer($customer);
52
+
53
+ foreach ($this->getMappingHash() as $key => $field) {
54
+
55
+ /**
56
+ * call user function based on the attribute mapped.
57
+ */
58
+ $function = 'get';
59
+ $exploded = explode('_', $key);
60
+ foreach ($exploded as $one) {
61
+ $function .= ucfirst($one);
62
+ }
63
+ try{
64
+ $value = call_user_func(array('self', $function));
65
+ $this->customerData[$key] = $value;
66
+ }catch (Exception $e){
67
+ Mage::logException($e);
68
+ }
69
+ }
70
+ }
71
+
72
+ public function setReviewCollection()
73
+ {
74
+ $customer_id = $this->customer->getId();
75
+ $collection = Mage::getModel('review/review')->getCollection();
76
+ $collection
77
+ ->addCustomerFilter($customer_id)
78
+ ->setOrder('review_id','DESC');
79
+ $this->reviewCollection = $collection;
80
+ }
81
+
82
+ public function getReviewCount()
83
+ {
84
+ return count($this->reviewCollection);
85
+ }
86
+
87
+ public function getLastReviewDate(){
88
+ if(count($this->reviewCollection))
89
+ return $this->reviewCollection->getFirstItem()->getCreatedAt();
90
+ return '';
91
+ }
92
+
93
+ /**
94
+ * Set reward customer
95
+ *
96
+ * @param Mage_Customer_Model_Customer $customer
97
+ */
98
+ public function setRewardCustomer(Mage_Customer_Model_Customer $customer)
99
+ {
100
+ $tbt_reward = Mage::getModel('rewards/customer')->getRewardsCustomer($customer);
101
+ $this->rewardCustomer = $tbt_reward;
102
+
103
+ $lastTransfers = $tbt_reward->getTransfers()
104
+ ->selectOnlyActive()
105
+ ->addOrder('last_update_ts', Varien_Data_Collection::SORT_ORDER_DESC);
106
+
107
+ $spent = $earn = null;
108
+
109
+ if($lastTransfers->getSize()) {
110
+ foreach($lastTransfers as $transfer) {
111
+ if(is_null($earn) && $transfer->getQuantity() > 0){
112
+ $earn = $transfer->getEffectiveStart();
113
+ }else if(is_null($spent) && $transfer->getQuantity() < 0) {
114
+ $spent = $transfer->getEffectiveStart();
115
+ }
116
+ if(!is_null($spent) && !is_null($earn)) {
117
+ break;
118
+ }
119
+ }
120
+ }
121
+
122
+ if($earn) $this->rewardLastEarned = $earn;
123
+ if($spent) $this->rewardLastSpent = $spent;
124
+
125
+ $tbt_expiry = Mage::getSingleton('rewards/expiry')
126
+ ->getExpiryDate($tbt_reward);
127
+
128
+ if($tbt_expiry) $this->rewardExpiry = $tbt_expiry;
129
+ }
130
+
131
+ /**
132
+ * get customer id.
133
+ *
134
+ * @return mixed
135
+ */
136
+ public function getCustomerId()
137
+ {
138
+ return $this->customer->getId();
139
+ }
140
+
141
+ /**
142
+ * get first name.
143
+ *
144
+ * @return mixed
145
+ */
146
+ public function getFirstname(){
147
+ return $this->customer->getFirstname();
148
+ }
149
+
150
+ /**
151
+ * get last name.
152
+ *
153
+ * @return mixed
154
+ */
155
+ public function getLastname()
156
+ {
157
+ return $this->customer->getLastname();
158
+ }
159
+
160
+ /**
161
+ * get date of birth.
162
+ *
163
+ * @return mixed
164
+ */
165
+ public function getDob()
166
+ {
167
+ return $this->customer->getDob();
168
+ }
169
+
170
+ /**
171
+ * get customer gender.
172
+ *
173
+ * @return bool|string
174
+ */
175
+ public function getGender(){
176
+ return $this->_getCustomerGender();
177
+ }
178
+
179
+ /**
180
+ * get customer prefix.
181
+ *
182
+ * @return mixed
183
+ */
184
+ public function getPrefix()
185
+ {
186
+ return $this->customer->getPrefix();
187
+ }
188
+
189
+ /**
190
+ * get customer suffix.
191
+ *
192
+ * @return mixed
193
+ */
194
+ public function getSuffix()
195
+ {
196
+ return $this->customer->getSuffix();
197
+ }
198
+
199
+ /**
200
+ * get website name.
201
+ *
202
+ * @return string
203
+ */
204
+ public function getWebsiteName()
205
+ {
206
+ return $this->_getWebsiteName();
207
+ }
208
+
209
+ /**
210
+ * get store name.
211
+ *
212
+ * @return null|string
213
+ */
214
+ public function getStoreName()
215
+ {
216
+ return $this->_getStoreName();
217
+ }
218
+
219
+ /**
220
+ * get customer created at date.
221
+ *
222
+ * @return mixed
223
+ */
224
+ public function getCreatedAt()
225
+ {
226
+ return $this->customer->getCreatedAt();
227
+ }
228
+
229
+ /**
230
+ * get customer last logged in date.
231
+ *
232
+ * @return mixed
233
+ */
234
+ public function getLastLoggedDate()
235
+ {
236
+ return $this->customer->getLastLoggedDate();
237
+ }
238
+
239
+ /**
240
+ * get cutomer group.
241
+ *
242
+ * @return string
243
+ */
244
+ public function getCustomerGroup()
245
+ {
246
+ return $this->_getCustomerGroup();
247
+ }
248
+
249
+ /**
250
+ * get billing address line 1.
251
+ *
252
+ * @return string
253
+ */
254
+ public function getBillingAddress1()
255
+ {
256
+ return $this->_getStreet($this->customer->getBillingStreet(), 1);
257
+ }
258
+
259
+ /**
260
+ * get billing address line 2.
261
+ *
262
+ * @return string
263
+ */
264
+ public function getBillingAddress2()
265
+ {
266
+ return $this->_getStreet($this->customer->getBillingStreet(), 2);
267
+ }
268
+
269
+ /**
270
+ * get billing city.
271
+ *
272
+ * @return mixed
273
+ */
274
+ public function getBillingCity()
275
+ {
276
+ return $this->customer->getBillingCity();
277
+ }
278
+
279
+ /**
280
+ * get billing country.
281
+ *
282
+ * @return mixed
283
+ */
284
+ public function getBillingCountry()
285
+ {
286
+ return $this->customer->getBillingCountryCode();
287
+ }
288
+
289
+ /**
290
+ * get billing state.
291
+ *
292
+ * @return mixed
293
+ */
294
+ public function getBillingState()
295
+ {
296
+ return $this->customer->getBillingRegion();
297
+ }
298
+
299
+ /**
300
+ * get billing postcode.
301
+ *
302
+ * @return mixed
303
+ */
304
+ public function getBillingPostcode()
305
+ {
306
+ return $this->customer->getBillingPostcode();
307
+ }
308
+
309
+ /**
310
+ * get billing phone.
311
+ *
312
+ * @return mixed
313
+ */
314
+ public function getBillingTelephone()
315
+ {
316
+ return $this->customer->getBillingTelephone();
317
+ }
318
+
319
+ /**
320
+ * get delivery address line 1.
321
+ *
322
+ * @return string
323
+ */
324
+ public function getDeliveryAddress1()
325
+ {
326
+ return $this->_getStreet($this->customer->getShippingStreet(), 1);
327
+ }
328
+
329
+ /**
330
+ * get delivery addrss line 2.
331
+ *
332
+ * @return string
333
+ */
334
+ public function getDeliveryAddress2()
335
+ {
336
+ return $this->_getStreet($this->customer->getShippingStreet(), 2);
337
+ }
338
+
339
+ /**
340
+ * get delivery city.
341
+ *
342
+ * @return mixed
343
+ */
344
+ public function getDeliveryCity()
345
+ {
346
+ return $this->customer->getShippingCity();
347
+ }
348
+
349
+ /**
350
+ * get delivery country.
351
+ *
352
+ * @return mixed
353
+ */
354
+ public function getDeliveryCountry(){
355
+ return $this->customer->getShippingCountryCode();
356
+ }
357
+
358
+ /**
359
+ * get delivery state.
360
+ *
361
+ * @return mixed
362
+ */
363
+ public function getDeliveryState()
364
+ {
365
+ return $this->customer->getShippingRegion();
366
+ }
367
+
368
+ /**
369
+ * get delivery postcode.
370
+ *
371
+ * @return mixed
372
+ */
373
+ public function getDeliveryPostcode()
374
+ {
375
+ return $this->customer->getShippingPostcode();
376
+ }
377
+
378
+ /**
379
+ * get delivery phone.
380
+ *
381
+ * @return mixed
382
+ */
383
+ public function getDeliveryTelephone(){
384
+ return $this->customer->getShippingTelephone();
385
+ }
386
+
387
+ /**
388
+ * get numbser of orders.
389
+ *
390
+ * @return mixed
391
+ */
392
+ public function getNumberOfOrders()
393
+ {
394
+ return $this->customer->getNumberOfOrders();
395
+ }
396
+
397
+ /**
398
+ * get average order value.
399
+ *
400
+ * @return mixed
401
+ */
402
+ public function getAverageOrderValue()
403
+ {
404
+ return $this->customer->getAverageOrderValue();
405
+ }
406
+
407
+ /**
408
+ * get total spend.
409
+ *
410
+ * @return mixed
411
+ */
412
+ public function getTotalSpend()
413
+ {
414
+ return $this->customer->getTotalSpend();
415
+ }
416
+
417
+ /**
418
+ * get last order date.
419
+ *
420
+ * @return mixed
421
+ */
422
+ public function getLastOrderDate()
423
+ {
424
+ return $this->customer->getLastOrderDate();
425
+ }
426
+
427
+ /**
428
+ * get last order date.
429
+ *
430
+ * @return mixed
431
+ */
432
+ public function getLastOrderId()
433
+ {
434
+ return $this->customer->getLastOrderId();
435
+ }
436
+
437
+ /**
438
+ * get cutomer id.
439
+ *
440
+ * @return mixed
441
+ */
442
+ public function getId()
443
+ {
444
+ return $this->customer->getId();
445
+ }
446
+
447
+ /**
448
+ * get customer title.
449
+ *
450
+ * @return mixed
451
+ */
452
+ public function getTitle()
453
+ {
454
+ return $this->customer->getPrefix();
455
+ }
456
+
457
+ /**
458
+ * get total refund value.
459
+ *
460
+ * @return float|int
461
+ */
462
+ public function getTotalRefund()
463
+ {
464
+ $orders = Mage::getResourceModel('sales/order_collection')
465
+ ->addAttributeToFilter('customer_id', $this->customer->getId())
466
+ ;
467
+ $totalRefunded = 0;
468
+ foreach ($orders as $order) {
469
+ $refunded = $order->getTotalRefunded();
470
+ $totalRefunded += $refunded;
471
+ }
472
+
473
+ return $totalRefunded;
474
+ }
475
+
476
+ /**
477
+ * export to CSV.
478
+ *
479
+ * @return mixed
480
+ */
481
+ public function toCSVArray()
482
+ {
483
+ $result = $this->customerData;
484
+ return $result;
485
+ }
486
+
487
+ /**
488
+ * customer gender.
489
+ *
490
+ * @return bool|string
491
+ * @throws Mage_Core_Exception
492
+ */
493
+ private function _getCustomerGender()
494
+ {
495
+ $genderId = $this->customer->getGender();
496
+ if (is_numeric($genderId)) {
497
+ $gender = Mage::getResourceModel('customer/customer')
498
+ ->getAttribute('gender')
499
+ ->getSource()
500
+ ->getOptionText($genderId)
501
+ ;
502
+ return $gender;
503
+ }
504
+
505
+ return '';
506
+ }
507
+
508
+ private function _getStreet($street, $line){
509
+ $street = explode("\n", $street);
510
+ if(isset($street[$line - 1]))
511
+ return $street[$line - 1];
512
+ return '';
513
+ }
514
+
515
+ private function _getWebsiteName(){
516
+ $websiteId = $this->customer->getWebsiteId();
517
+ $website = Mage::app()->getWebsite($websiteId);
518
+ if($website)
519
+ return $website->getName();
520
+
521
+ return '';
522
+ }
523
+
524
+ private function _getStoreName()
525
+ {
526
+ $storeId = $this->customer->getStoreId();
527
+ $store = Mage::app()->getStore($storeId);
528
+ if($store)
529
+ return $store->getName();
530
+
531
+ return '';
532
+ }
533
+
534
+ /**
535
+ * @param mixed $mapping_hash
536
+ */
537
+ public function setMappingHash($mapping_hash)
538
+ {
539
+ $this->_mapping_hash = $mapping_hash;
540
+ }
541
+
542
+ /**
543
+ * @return mixed
544
+ */
545
+ public function getMappingHash()
546
+ {
547
+ return $this->_mapping_hash;
548
+ }
549
+
550
+ private function _getCustomerGroup(){
551
+ $groupId = $this->customer->getGroupId();
552
+ $group = Mage::getModel('customer/group')->load($groupId);
553
+ if($group){
554
+ return $group->getCode();
555
+ }
556
+ return '';
557
+ }
558
+
559
+ /**
560
+ * mapping hash value.
561
+ *
562
+ * @param $value
563
+ *
564
+ * @return $this
565
+ */
566
+ public function setMappigHash($value)
567
+ {
568
+ $this->_mapping_hash = $value;
569
+ return $this;
570
+ }
571
+
572
+ public function getRewardPointBalance()
573
+ {
574
+ return $this->cleanString($this->rewardCustomer->getPointsSummary());
575
+ }
576
+
577
+ public function getRewardPointPending()
578
+ {
579
+ return $this->cleanString($this->rewardCustomer->getPendingPointsSummary());
580
+ }
581
+
582
+ public function getRewardPointPendingTime()
583
+ {
584
+ return $this->cleanString($this->rewardCustomer->getPendingTimePointsSummary());
585
+ }
586
+
587
+ public function getRewardPointOnHold()
588
+ {
589
+ return $this->cleanString($this->rewardCustomer->getOnHoldPointsSummary());
590
+ }
591
+
592
+ public function getRewardPointExpiration()
593
+ {
594
+ if($this->rewardExpiry != "")
595
+ return date_format(date_create($this->makeUSDate($this->rewardExpiry)), 'Y-m-d H:i:s');
596
+ return $this->rewardExpiry;
597
+ }
598
+
599
+ public function getRewardPointLastSpent()
600
+ {
601
+ return $this->rewardLastSpent;
602
+ }
603
+
604
+ public function getRewardPointLastEarn()
605
+ {
606
+ return $this->rewardLastEarned;
607
+ }
608
+
609
+ public function makeUSDate($uk_date, $separator_input = '/', $sepatator_output = '/')
610
+ {
611
+ list($day, $month, $year) = explode($separator_input, $uk_date);
612
+ return $month.$sepatator_output.$day.$sepatator_output.$year;
613
+ }
614
+
615
+ public function cleanString($string)
616
+ {
617
+ $cleanedString = preg_replace("/[^0-9]/","",$string);
618
+ if($cleanedString != "") return (int) number_format($cleanedString, 0, '.', '');
619
+ return (int) 0;
620
+ }
621
+ }
app/code/community/Dotdigitalgroup/Email/Model/Apiconnector/Test.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Apiconnector_Test extends Dotdigitalgroup_Email_Model_Apiconnector_Client
4
+ {
5
+ const TEST_API_USERNAME = 'apiuser-8e3b8f244ec9@apiconnector.com';
6
+ const TEST_API_PASSWORD = 'TWFnZW50bzIwMTM=';
7
+ const TEST_API_CAMPAIGN = '2643928';
8
+ const TEST_CONTACT_ID = '13';
9
+ const TEST_CONTACT_EMAIL = 'ben.staveley@dotmailer.co.uk';
10
+
11
+
12
+ /**
13
+ * Validate apiuser on save.
14
+ *
15
+ * @param $apiUsername
16
+ * @param $apiPassword
17
+ *
18
+ * @return bool|mixed
19
+ */
20
+ public function validate($apiUsername, $apiPassword)
21
+ {
22
+ if ($apiUsername && $apiPassword) {
23
+ $this->setApiUsername($apiUsername)
24
+ ->setApiPassword($apiPassword);
25
+
26
+ $accountInfo = $this->getAccountInfo();
27
+ if (isset($accountInfo->message)) {
28
+ Mage::getSingleton('adminhtml/session')->addError($accountInfo->message);
29
+ Mage::helper('connector')->log('VALIDATION ERROR : ' . $accountInfo->message);
30
+ return false;
31
+ }
32
+ return $accountInfo;
33
+ }
34
+ return false;
35
+ }
36
+
37
+ /**
38
+ * Ajax validate api user.
39
+ *
40
+ * @param $apiUsername
41
+ * @param $apiPassword
42
+ *
43
+ * @return bool|string
44
+ */
45
+ public function ajaxvalidate($apiUsername, $apiPassword)
46
+ {
47
+ if ($apiUsername && $apiPassword) {
48
+ $message = 'Credentials Valid.';
49
+ $this->setApiUsername($apiUsername)
50
+ ->setApiPassword($apiPassword);
51
+ $response = $this->getAccountInfo();
52
+ if (isset($response->message)) {
53
+ $message = 'API Username And Password Do Not Match!';
54
+ Mage::helper('connector')->log($message);
55
+ }
56
+ return $message;
57
+ }
58
+ return false;
59
+ }
60
+
61
+ /**
62
+ * Confirm the installation.
63
+ */
64
+ public function sendInstallConfirmation()
65
+ {
66
+ // set test credentials
67
+ $this->setApiUsername(self::TEST_API_USERNAME)
68
+ ->setApiPassword(
69
+ base64_decode(self::TEST_API_PASSWORD));
70
+ $testEmail = self::TEST_CONTACT_EMAIL;
71
+ $contactId = self::TEST_CONTACT_ID;
72
+ $campaignId = self::TEST_API_CAMPAIGN;
73
+
74
+ Mage::log($this->getApiUsername());
75
+ Mage::log($this->getApiPassword());
76
+ /**
77
+ * send initial info
78
+ */
79
+ $this->sendIntallInfo($testEmail, $contactId, $campaignId);
80
+ }
81
+ }
app/code/community/Dotdigitalgroup/Email/Model/Campaign.php ADDED
@@ -0,0 +1,367 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Campaign extends Mage_Core_Model_Abstract
4
+ {
5
+ //xml path configuration
6
+ const XML_PATH_LOSTBASKET_1_ENABLED = 'connector_lost_baskets/customers/enabled_1';
7
+ const XML_PATH_LOSTBASKET_2_ENABLED = 'connector_lost_baskets/customers/enabled_2';
8
+ const XML_PATH_LOSTBASKET_3_ENABLED = 'connector_lost_baskets/customers/enabled_3';
9
+
10
+ const XML_PATH_LOSTBASKET_1_INTERVAL = 'connector_lost_baskets/customers/send_after_1';
11
+ const XML_PATH_LOSTBASKET_2_INTERVAL = 'connector_lost_baskets/customers/send_after_2';
12
+ const XML_PATH_LOSTBASKET_3_INTERVAL = 'connector_lost_baskets/customers/send_after_3';
13
+
14
+ const XML_PATH_TRIGGER_1_CAMPAIGN = 'connector_lost_baskets/customers/campaign_1';
15
+ const XML_PATH_TRIGGER_2_CAMPAIGN = 'connector_lost_baskets/customers/campaign_2';
16
+ const XML_PATH_TRIGGER_3_CAMPAIGN = 'connector_lost_baskets/customers/campaign_3';
17
+
18
+ const XML_PATH_GUEST_LOSTBASKET_1_ENABLED = 'connector_lost_baskets/guests/enabled_1';
19
+ const XML_PATH_GUEST_LOSTBASKET_2_ENABLED = 'connector_lost_baskets/guests/enabled_2';
20
+ const XML_PATH_GUEST_LOSTBASKET_3_ENABLED = 'connector_lost_baskets/guests/enabled_3';
21
+
22
+ const XML_PATH_GUEST_LOSTBASKET_1_INTERVAL = 'connector_lost_baskets/guests/send_after_1';
23
+ const XML_PATH_GUEST_LOSTBASKET_2_INTERVAL = 'connector_lost_baskets/guests/send_after_2';
24
+ const XML_PATH_GUEST_LOSTBASKET_3_INTERVAL = 'connector_lost_baskets/guests/send_after_3';
25
+
26
+ const XML_PATH_GUEST_LOSTBASKET_1_CAMPAIGN = 'connector_lost_baskets/guests/campaign_1';
27
+ const XML_PATH_GUEST_LOSTBASKET_2_CAMPAIGN = 'connector_lost_baskets/guests/campaign_2';
28
+ const XML_PATH_GUEST_LOSTBASKET_3_CAMPAIGN = 'connector_lost_baskets/guests/campaign_3';
29
+
30
+
31
+ //error messages
32
+ const SEND_EMAIL_CONTACT_ID_MISSING = 'Error : missing contact id - will try later to send ';
33
+
34
+ //campaign create vars
35
+ private $fromAddress;
36
+ private $replyAction;
37
+ private $replyAddress;
38
+ private $copyEmail;
39
+
40
+ /**
41
+ * @var object
42
+ */
43
+ public $transactionalClient;
44
+
45
+ /**
46
+ * constructor
47
+ */
48
+ public function _construct()
49
+ {
50
+ parent::_construct();
51
+ $this->_init('email_connector/campaign');
52
+
53
+ $this->transactionalClient = Mage::helper('connector/transactional')->getWebsiteApiClient();
54
+ }
55
+
56
+ /**
57
+ * @return $this|Mage_Core_Model_Abstract
58
+ */
59
+ protected function _beforeSave()
60
+ {
61
+ parent::_beforeSave();
62
+ $now = Mage::getSingleton('core/date')->gmtDate();
63
+ if ($this->isObjectNew()) {
64
+ $this->setCreatedAt($now);
65
+ }
66
+ $this->setUpdatedAt($now);
67
+ return $this;
68
+ }
69
+
70
+ /**
71
+ * @param $quoteId
72
+ * @param $storeId
73
+ * @return mixed
74
+ */
75
+ public function loadByQuoteId($quoteId, $storeId)
76
+ {
77
+ $collection = $this->getCollection()
78
+ ->addFieldToFilter('quote_id', $quoteId)
79
+ ->addFieldToFilter('store_id', $storeId);
80
+
81
+ if ($collection->count()) {
82
+ return $collection->getFirstItem();
83
+ } else {
84
+ $this->setQuoteId($quoteId)
85
+ ->setStoreId($storeId);
86
+ }
87
+
88
+ return $this;
89
+ }
90
+
91
+
92
+ /**
93
+ * Sending the campaigns.
94
+ */
95
+ public function sendCampaigns()
96
+ {
97
+ //create campaign first
98
+ $this->createEmailsToCampaigns();
99
+
100
+ //grab the emails not send
101
+ $emailsToSend = $this->_getEmailCampaigns();
102
+ $templateModel = Mage::getModel('email_connector/email_template');
103
+
104
+ foreach ($emailsToSend as $campaign) {
105
+ $email = $campaign->getEmail();
106
+ $storeId = $campaign->getStoreId();
107
+ $store = Mage::app()->getStore($storeId);
108
+ $websiteId = $store->getWebsiteId();
109
+ $storeName = $store->getName();
110
+ $websiteName = $store->getWebsite()->getName();
111
+ $campaignId = $campaign->getCampaignId();
112
+ if (!$campaignId) {
113
+ $campaign->setMessage('Missing campaign id: ' . $campaignId)
114
+ ->setIsSent(1)
115
+ ->save();
116
+ continue;
117
+ } elseif (!$email) {
118
+ $campaign->setMessage('Missing email : ' . $email)
119
+ ->setIsSent(1)
120
+ ->save();
121
+ continue;
122
+ }
123
+ try{
124
+ if ($campaign->getEventName() == 'Lost Basket') {
125
+ $client = Mage::helper('connector')->getWebsiteApiClient($websiteId);
126
+ $contactId = Mage::helper('connector')->getContactId($campaign->getEmail(), $websiteId);
127
+ if(is_numeric($contactId)) {
128
+ Mage::helper('connector')->log($contactId);
129
+ $response = $client->postCampaignsSend($campaignId, array($contactId));
130
+ if (isset($response->message)) {
131
+ //update the failed to send email message
132
+ $campaign->setMessage($response->message)->setIsSent(1)->save();
133
+ }
134
+ $now = Mage::getSingleton('core/date')->gmtDate();
135
+ //record suscces
136
+ $campaign->setIsSent(1)
137
+ ->setMessage(NULL)
138
+ ->setSentAt($now)
139
+ ->save();
140
+ }else{
141
+ //update the failed to send email message- error message from post contact
142
+ $campaign->setContactMessage($contactId)->setIsSent(1)->save();
143
+ }
144
+ } elseif ($campaign->getEventName() == 'New Customer Account') {
145
+ $contactId = Mage::helper('connector/transactional')->getContactId($campaign->getEmail(), $websiteId);
146
+ if(is_numeric($contactId)){
147
+ Mage::helper('connector')->log($contactId);
148
+ $customerId = $campaign->getCustomerId();
149
+ $customer = Mage::getModel('customer/customer')->load($customerId);
150
+ $firstname = $customer->getFirstname();
151
+ $lastname = $customer->getLastname();
152
+ $data = array(
153
+ array(
154
+ 'Key' => 'STORE_NAME',
155
+ 'Value' => $storeName),
156
+ array(
157
+ 'Key' => 'WEBSITE_NAME',
158
+ 'Value' => $websiteName),
159
+ array(
160
+ 'Key' => 'FIRSTNAME',
161
+ 'Value' => $firstname),
162
+ array(
163
+ 'Key' => 'LASTNAME',
164
+ 'Value' => $lastname),
165
+ array(
166
+ 'Key' => 'CUSTOMER_ID',
167
+ 'Value' => $customerId)
168
+ );
169
+ $this->transactionalClient->updateContactDatafieldsByEmail($email, $data);
170
+
171
+ $response = $this->transactionalClient->postCampaignsSend($campaignId, array($contactId));
172
+ if (isset($response->message)) {
173
+ //update the failed to send email message
174
+ $campaign->setMessage($response->message)->setIsSent(1)->save();
175
+ } else {
176
+ $now = Mage::getSingleton('core/date')->gmtDate();
177
+ //record suscces
178
+ $campaign->setIsSent(1)
179
+ ->setMessage(NULL)
180
+ ->setSentAt($now)
181
+ ->save();
182
+ }
183
+ }else{
184
+ //update the failed to send email message- error message from post contact
185
+ $campaign->setContactMessage($contactId)->setIsSent(1)->save();
186
+ }
187
+
188
+ } elseif ($templateModel->getSalesEvent($campaign->getEventName())) {
189
+ // transactional
190
+ $orderModel = Mage::getModel("sales/order")->loadByIncrementId($campaign->getOrderIncrementId());
191
+ $contactId = Mage::helper('connector/transactional')->getContactId($campaign->getEmail(), $websiteId);
192
+ if (is_numeric($contactId)) {
193
+ Mage::helper('connector')->log($contactId);
194
+ if ($orderModel->getCustomerId()) {
195
+ $firstname = $orderModel->getCustomerFirstname();
196
+ $lastname = $orderModel->getCustomerLastname();
197
+ } else {
198
+ $billing = $orderModel->getBillingAddress();
199
+ $firstname = $billing->getFirstname();
200
+ $lastname = $billing->getLastname();
201
+ }
202
+ $data = array(
203
+ array(
204
+ 'Key' => 'STORE_NAME',
205
+ 'Value' => $storeName),
206
+ array(
207
+ 'Key' => 'WEBSITE_NAME',
208
+ 'Value' => $websiteName),
209
+ array(
210
+ 'Key' => 'FIRSTNAME',
211
+ 'Value' => $firstname),
212
+ array(
213
+ 'Key' => 'LASTNAME',
214
+ 'Value' => $lastname),
215
+ array(
216
+ 'Key' => 'LAST_ORDER_ID',
217
+ 'Value' => $orderModel->getId())
218
+ );
219
+ $this->transactionalClient->updateContactDatafieldsByEmail($email, $data);
220
+ $response = $this->transactionalClient->postCampaignsSend($campaignId, array($contactId));
221
+ if (isset($response->message)) {
222
+ //update the failed to send email message
223
+ $campaign->setMessage($response->message)->setIsSent(1)->save();
224
+ } else {
225
+ $now = Mage::getSingleton('core/date')->gmtDate();
226
+ //record suscces
227
+ $campaign->setIsSent(1)
228
+ ->setMessage(NULL)
229
+ ->setSentAt($now)
230
+ ->save();
231
+ }
232
+ }else{
233
+ //update the failed to send email message- error message from post contact
234
+ $campaign->setContactMessage($contactId)->setIsSent(1)->save();
235
+ }
236
+ }else{
237
+ $contactId = Mage::helper('connector/transactional')->getContactId($campaign->getEmail(), $websiteId);
238
+ if(is_numeric($contactId)){
239
+ Mage::helper('connector')->log($contactId);
240
+ $response = $this->transactionalClient->postCampaignsSend($campaignId, array($contactId));
241
+ if (isset($response->message)) {
242
+ //update the failed to send email message
243
+ $campaign->setMessage($response->message)->setIsSent(1)->save();
244
+ } else{
245
+ $now = Mage::getSingleton('core/date')->gmtDate();
246
+ //record suscces
247
+ $campaign->setIsSent(1)
248
+ ->setMessage(NULL)
249
+ ->setSentAt($now)
250
+ ->save();
251
+ }
252
+ }else{
253
+ //update the failed to send email message- error message from post contact
254
+ $campaign->setContactMessage($contactId)->setIsSent(1)->save();
255
+ }
256
+ }
257
+
258
+ }catch(Exception $e){
259
+ Mage::logException($e);
260
+ }
261
+ }
262
+ return;
263
+ }
264
+
265
+ /**
266
+ * @return mixed
267
+ */
268
+ private function _getEmailCampaigns()
269
+ {
270
+ $emailCollection = $this->getCollection();
271
+ $emailCollection->addFieldToFilter('is_sent', array('null' => true))
272
+ ->addFieldToFilter('campaign_id', array('notnull' => true))
273
+ ->addFieldToFilter('type', 1);
274
+ $emailCollection->getSelect()->order('campaign_id');
275
+ return $emailCollection;
276
+ }
277
+
278
+ /**
279
+ * create emails to campaigns
280
+ */
281
+ public function createEmailsToCampaigns()
282
+ {
283
+ $helper = Mage::helper('connector/transactional');
284
+ $emails = $this->getEmailsToCreateCampaigns();
285
+
286
+ foreach($emails as $email)
287
+ {
288
+ try {
289
+ $websiteId = $email->getWebsiteId();
290
+
291
+ if (!$this->fromAddress)
292
+ $this->fromAddress = $helper->getFromAddress($websiteId);
293
+ if (!$this->replyAction)
294
+ $this->replyAction = $helper->getReplyAction($websiteId);
295
+ if ($this->replyAction == 'WebMailForward') {
296
+ if (!$this->replyAddress) {
297
+ $this->replyAddress = $helper->getReplyAddress($websiteId);
298
+ }
299
+ }
300
+ if (!$this->copyEmail)
301
+ $this->copyEmail = $helper->getSendCopy($websiteId);
302
+
303
+ if ($this->fromAddress && $this->replyAction) {
304
+ $data = array(
305
+ 'Name' => $email->getEventName(),
306
+ 'Subject' => $email->getSubject(),
307
+ 'FromName' => $email->getFromName(),
308
+ 'FromAddress' => $this->fromAddress,
309
+ 'HtmlContent' => $email->getHtmlContent(),
310
+ 'PlainTextContent' => $email->getPlainTextContent(),
311
+ 'ReplyAction' => $this->replyAction,
312
+ 'IsSplitTest' => false,
313
+ 'Status' => 'Unsent'
314
+ );
315
+ if ($this->replyAction == 'WebMailForward' && $this->replyAddress)
316
+ $data['ReplyToAddress'] = $this->replyAddress;
317
+ else
318
+ $data['ReplyToAddress'] = '';
319
+ }
320
+
321
+ if(isset($data)){
322
+ $client = Mage::helper('connector/transactional')->getWebsiteApiClient($websiteId);
323
+ $result = $client->postCampaign($data);
324
+ if (isset($result->message)) {
325
+ $email->setCreateMessage($result->message)
326
+ ->setIsCreated(1)
327
+ ->save();
328
+ continue;
329
+ }
330
+ Mage::helper('connector')->log('createEmailsToCampaigns ' . $result->id);
331
+ $email->setCampaignId($result->id)
332
+ ->setType(1)
333
+ ->setIsCreated(1)
334
+ ->save();
335
+
336
+ if($this->copyEmail){
337
+ $this->setEmail($this->copyEmail)
338
+ ->setIsCopy(1)
339
+ ->setCampaignId($result->id)
340
+ ->setEventName($email->getEventName())
341
+ ->setType(1)
342
+ ->setIsCreated(1)
343
+ ->save();
344
+ }
345
+ }
346
+ }catch(Exception $e){
347
+ Mage::logException($e);
348
+ }
349
+ }
350
+ return;
351
+ }
352
+
353
+ /**
354
+ * get collection to create campaigns
355
+ *
356
+ * @param int $pageSize
357
+ * @return Mage_Eav_Model_Entity_Collection_Abstract
358
+ */
359
+ protected function getEmailsToCreateCampaigns($pageSize = 100)
360
+ {
361
+ $collection = $this->getCollection()
362
+ ->addFieldToFilter('is_created', array('null' => true))
363
+ ->addFieldToFilter('type', 2);
364
+ $collection->getSelect()->limit($pageSize);
365
+ return $collection;
366
+ }
367
+ }
app/code/community/Dotdigitalgroup/Email/Model/Config.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Config extends Mage_Core_Model_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('email_connector/config');
9
+ }
10
+
11
+ /**
12
+ * @return $this|Mage_Core_Model_Abstract
13
+ */
14
+ protected function _beforeSave()
15
+ {
16
+ $now = Mage::getSingleton('core/date')->gmtDate();
17
+ if ($this->isObjectNew()) {
18
+ $this->setCreatedAt($now);
19
+ }
20
+ $this->setUpdatedAt($now);
21
+
22
+ return parent::_beforeSave();
23
+ }
24
+
25
+
26
+ /**
27
+ * Get the date value for the hour trigger.
28
+ * Reset the api calls for more than an hour.
29
+ * @return bool
30
+ */
31
+ public function getHourTrigger()
32
+ {
33
+ $config = $this->getCollection()
34
+ ->addFieldToFilter('path', Dotdigitalgroup_Email_Helper_Config::CONNECTOR_EMAIL_CONFIG_HOUR_TRIGGER);
35
+ //found the config value
36
+ if ($config->count()) {
37
+ return $configData = $config->getFirstItem()->getValue();
38
+ }
39
+
40
+ return false;
41
+ }
42
+
43
+
44
+ /**
45
+ * Get the value for configuration path.
46
+ * @param $path
47
+ *
48
+ * @return mixed
49
+ */
50
+ public function getValueByPath( $path )
51
+ {
52
+ $collection = $this->getCollection()
53
+ ->addFieldToFilter('path', $path)
54
+ ->setPageSize(1);
55
+
56
+ //found the item
57
+ if ($collection->count()) {
58
+ return $collection->getFirstItem();
59
+ }
60
+
61
+ $this->setPath($path);
62
+ return $this;
63
+ }
64
+
65
+ }
app/code/{local → community}/Dotdigitalgroup/Email/Model/Connector/Account.php RENAMED
@@ -16,11 +16,13 @@ class Dotdigitalgroup_Email_Model_Connector_Account
16
  private $_orders = array();
17
 
18
  /**
19
- * @param mixed $api_password
 
20
  */
21
  public function setApiPassword($api_password)
22
  {
23
  $this->_api_password = $api_password;
 
24
  }
25
 
26
  /**
@@ -32,11 +34,13 @@ class Dotdigitalgroup_Email_Model_Connector_Account
32
  }
33
 
34
  /**
35
- * @param mixed $api_username
 
36
  */
37
  public function setApiUsername($api_username)
38
  {
39
  $this->_api_username = $api_username;
 
40
  }
41
 
42
  /**
@@ -68,12 +72,11 @@ class Dotdigitalgroup_Email_Model_Connector_Account
68
  */
69
  public function setContacts($contacts)
70
  {
71
- // if(!empty($this->_contacts)){
72
- // $this->_contacts += $contacts;
73
- // }else{
74
-
75
  $this->_contacts[] = $contacts;
76
- //}
77
  }
78
 
79
  /**
@@ -214,5 +217,4 @@ class Dotdigitalgroup_Email_Model_Connector_Account
214
  return $this->_websites;
215
  }
216
 
217
-
218
  }
16
  private $_orders = array();
17
 
18
  /**
19
+ * @param $api_password
20
+ * @return $this
21
  */
22
  public function setApiPassword($api_password)
23
  {
24
  $this->_api_password = $api_password;
25
+ return $this;
26
  }
27
 
28
  /**
34
  }
35
 
36
  /**
37
+ * @param $api_username
38
+ * @return $this
39
  */
40
  public function setApiUsername($api_username)
41
  {
42
  $this->_api_username = $api_username;
43
+ return $this;
44
  }
45
 
46
  /**
72
  */
73
  public function setContacts($contacts)
74
  {
75
+ if (!empty($this->_contacts)) {
76
+ $this->_contacts += $contacts;
77
+ } else {
 
78
  $this->_contacts[] = $contacts;
79
+ }
80
  }
81
 
82
  /**
217
  return $this->_websites;
218
  }
219
 
 
220
  }
app/code/community/Dotdigitalgroup/Email/Model/Connector/Campaign.php ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Connector_Campaign
4
+ {
5
+
6
+ public $id;
7
+ public $contacts = array();
8
+ public $emails = array();
9
+ public $emailSendId = array();
10
+ private $_storeId;
11
+
12
+ /**
13
+ * @param mixed $storeId
14
+ */
15
+ public function setStoreId($storeId)
16
+ {
17
+ $this->_storeId = $storeId;
18
+ }
19
+
20
+ /**
21
+ * @return mixed
22
+ */
23
+ public function getStoreId()
24
+ {
25
+ return $this->_storeId;
26
+ }
27
+
28
+ /**
29
+ * @param $emailSendId
30
+ * @return $this
31
+ */
32
+ public function setEmailSendId($emailSendId)
33
+ {
34
+ $this->emailSendId[] = $emailSendId;
35
+ return $this;
36
+ }
37
+
38
+ /**
39
+ * @return array
40
+ */
41
+ public function getEmailSendId()
42
+ {
43
+ return $this->emailSendId;
44
+ }
45
+
46
+ /**
47
+ * @param $contact
48
+ * @return $this
49
+ */
50
+ public function setContactId($contact)
51
+ {
52
+ $this->contacts[] = $contact;
53
+ return $this;
54
+ }
55
+
56
+ /**
57
+ * @return array
58
+ */
59
+ public function getContacts()
60
+ {
61
+ return $this->contacts;
62
+ }
63
+
64
+ /**
65
+ * @param $emails
66
+ * @return $this
67
+ */
68
+ public function setEmails($emails)
69
+ {
70
+ $this->emails = $emails;
71
+ return $this;
72
+ }
73
+
74
+ /**
75
+ * @return array
76
+ */
77
+ public function getEmails()
78
+ {
79
+ return $this->emails;
80
+ }
81
+
82
+ /**
83
+ * @param $id
84
+ * @return $this
85
+ */
86
+ public function setId($id)
87
+ {
88
+ $this->id = $id;
89
+ return $this;
90
+ }
91
+
92
+ /**
93
+ * @return mixed
94
+ */
95
+ public function getId()
96
+ {
97
+ return $this->id;
98
+ }
99
+
100
+ }
app/code/community/Dotdigitalgroup/Email/Model/Connector/Datafield.php ADDED
@@ -0,0 +1,323 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Connector_Datafield
4
+ {
5
+ /**
6
+ * @var string
7
+ */
8
+ public $name;
9
+ /**
10
+ * @var string
11
+ */
12
+ public $type;
13
+ /**
14
+ * @var string
15
+ */
16
+ public $visibility;
17
+ /**
18
+ * @var string
19
+ */
20
+ public $defaultValue;
21
+ /**
22
+ * Contact datafields.
23
+ * @var array
24
+ */
25
+ public $datafields = array();
26
+
27
+ /**
28
+ * Default datafields
29
+ * @return array
30
+ */
31
+ protected $_defaultDataFields = array(
32
+ array(
33
+ 'name' => 'CUSTOMER_ID',
34
+ 'type' => 'string',
35
+ 'visibility' => 'private',
36
+ ),array(
37
+ 'name' => 'LAST_ORDER_ID',
38
+ 'type' => 'numeric',
39
+ 'visibility' => 'private',
40
+ ),array(
41
+ 'name' => 'ORDER_INCREMENT_ID',
42
+ 'type' => 'numeric',
43
+ 'visibility' => 'private',
44
+ )
45
+ );
46
+
47
+ /**
48
+ * Contact default datafields.
49
+ *
50
+ * @var array
51
+ */
52
+ private $_contactDatafields = array(
53
+ 'customer_id' => array(
54
+ 'name' => 'CUSTOMER_ID',
55
+ 'type' => 'numeric',
56
+ 'visibility' => 'public',
57
+ ),
58
+ 'firstname' => array(
59
+ 'name' => 'FIRSTNAME',
60
+ 'type' => 'string'
61
+ ),
62
+ 'lastname' => array(
63
+ 'name' => 'LASTNAME',
64
+ 'type' => 'string'
65
+ ),
66
+ 'gender' => array(
67
+ 'name' => 'GENDER',
68
+ 'type' => 'string'
69
+ ),
70
+ 'dob' => array(
71
+ 'name' => 'DOB',
72
+ 'type' => 'date',
73
+ 'visibility' => 'public',
74
+ ),
75
+ 'title' => array(
76
+ 'name' => 'TITLE',
77
+ 'type' => 'string',
78
+ 'visibility' => 'public',
79
+ ),
80
+ 'website_name' => array(
81
+ 'name' => 'WEBSITE_NAME',
82
+ 'type' => 'string',
83
+ 'visibility' => 'public',
84
+ ),
85
+ 'store_name' => array(
86
+ 'name' => 'STORE_NAME',
87
+ 'type' => 'string',
88
+ 'visibility' => 'public',
89
+ ),
90
+ 'created_at' => array(
91
+ 'name' => 'ACCOUNT_CREATED_DATE',
92
+ 'type' => 'date',
93
+ 'visibility' => 'public'
94
+ ),
95
+ 'last_logged_date' => array(
96
+ 'name' => 'LAST_LOGGEDIN_DATE',
97
+ 'type' => 'date',
98
+ 'visibility' => 'public'
99
+ ),
100
+ 'customer_group' => array(
101
+ 'name' => 'CUSTOMER_GROUP',
102
+ 'type' => 'string',
103
+ 'visibility' => 'public',
104
+ ),
105
+ 'billing_address_1' => array(
106
+ 'name' => 'BILLING_ADDRESS_1',
107
+ 'type' => 'string',
108
+ 'visibility' => 'private',
109
+ 'defaultValue' => ''
110
+ ),
111
+ 'billing_address_2' => array(
112
+ 'name' => 'BILLING_ADDRESS_2',
113
+ 'type' => 'string',
114
+ 'visibility' => 'public',
115
+ ),
116
+ 'billing_state' => array(
117
+ 'name' => 'BILLING_STATE',
118
+ 'type' => 'string',
119
+ 'visibility' => 'public'
120
+ ),
121
+ 'billing_city' => array(
122
+ 'name' => 'BILLING_CITY',
123
+ 'type' => 'string',
124
+ 'visibility' => 'public',
125
+ ),
126
+ 'billing_country' => array(
127
+ 'name' => 'BILLING_COUNTRY',
128
+ 'type' => 'string',
129
+ 'visibility' => 'public',
130
+ ),
131
+ 'billing_postcode' => array(
132
+ 'name' => 'BILLING_POSTCODE',
133
+ 'type' => 'string',
134
+ 'visibility' => 'public',
135
+ ),
136
+ 'billing_telephone' => array(
137
+ 'name' => 'BILLING_TELEPHONE',
138
+ 'type' => 'string',
139
+ 'visibility' => 'public',
140
+ ),
141
+ 'delivery_address_1' => array(
142
+ 'name' => 'DELIVERY_ADDRESS_1',
143
+ 'type' => 'string',
144
+ 'visibility' => 'public',
145
+ ),
146
+ 'delivery_address_2' => array(
147
+ 'name' => 'DELIVERY_ADDRESS_2',
148
+ 'type' => 'string',
149
+ 'visibility' => 'public',
150
+ ),
151
+ 'delivery_state' => array(
152
+ 'name' => 'DELIVERY_STATE',
153
+ 'type' => 'string',
154
+ 'visibility' => 'public'
155
+ ),
156
+ 'delivery_city' => array(
157
+ 'name' => 'DELIVERY_CITY',
158
+ 'type' => 'string',
159
+ 'visibility' => 'public',
160
+ ),
161
+ 'delivery_country' => array(
162
+ 'name' => 'DELIVERY_COUNTRY',
163
+ 'type' => 'string',
164
+ 'visibility' => 'public',
165
+ ),
166
+ 'delivery_postcode' => array(
167
+ 'name' => 'DELIVERY_POSTCODE',
168
+ 'type' => 'string',
169
+ 'visibility' => 'public',
170
+ ),
171
+ 'delivery_telephone' => array(
172
+ 'name' => 'DELIVERY_TELEPHONE',
173
+ 'type' => 'string',
174
+ 'visibility' => 'public',
175
+ ),
176
+ 'number_of_orders' => array(
177
+ 'name' => 'NUMBER_OF_ORDERS',
178
+ 'type' => 'numeric',
179
+ 'visibility' => 'public',
180
+ ),
181
+ 'total_spend' => array(
182
+ 'name' => 'TOTAL_SPEND',
183
+ 'type' => 'numeric',
184
+ 'visibility' => 'public',
185
+ ),
186
+ 'average_order_value' => array(
187
+ 'name' => 'AVERAGE_ORDER_VALUE',
188
+ 'type' => 'numeric',
189
+ 'visibility' => 'public',
190
+ ),
191
+ 'last_order_date' => array(
192
+ 'name' => 'LAST_ORDER_DATE',
193
+ 'type' => 'date',
194
+ 'visibility' => 'public',
195
+ ),
196
+ 'last_order_id' => array(
197
+ 'name' => 'LAST_ORDER_ID',
198
+ 'type' => 'numeric',
199
+ 'visibility' => 'private',
200
+ ),
201
+ 'total_refund' => array(
202
+ 'name' => 'TOTAL_REFUND',
203
+ 'type' => 'numeric',
204
+ 'visibility' => 'private',
205
+ ),
206
+ 'review_count' => array(
207
+ 'name' => 'REVIEW_COUNT',
208
+ 'type' => 'numeric',
209
+ 'visibility' => 'private',
210
+ ),
211
+ 'last_review_date' => array(
212
+ 'name' => 'LAST_REVIEW_DATE',
213
+ 'type' => 'date',
214
+ 'visibility' => 'private',
215
+ )
216
+ );
217
+
218
+ /**
219
+ * transactional data default datafields.
220
+ *
221
+ * @var array
222
+ */
223
+ private $_transactionalDefaultDatafields = array(
224
+ array(
225
+ 'name' => 'CUSTOMER_ID',
226
+ 'type' => 'string',
227
+ 'visibility' => 'private',
228
+ ),array(
229
+ 'name' => 'LAST_ORDER_ID',
230
+ 'type' => 'numeric',
231
+ 'visibility' => 'private',
232
+ ),array(
233
+ 'name' => 'ORDER_INCREMENT_ID',
234
+ 'type' => 'numeric',
235
+ 'visibility' => 'private',
236
+ ),
237
+ array(
238
+ 'name' => 'WEBSITE_NAME',
239
+ 'type' => 'string',
240
+ 'visibility' => 'private',
241
+ ),
242
+ array(
243
+ 'name' => 'STORE_NAME',
244
+ 'type' => 'string',
245
+ 'visibility' => 'private',
246
+ ),
247
+ array(
248
+ 'name' => 'LAST_ORDER_DATE',
249
+ 'type' => 'date',
250
+ 'visibility' => 'private',
251
+ )
252
+ );
253
+
254
+ /**
255
+ * @param array $contactDatafields
256
+ */
257
+ public function setContactDatafields($contactDatafields)
258
+ {
259
+ $this->_contactDatafields = $contactDatafields;
260
+ }
261
+
262
+ /**
263
+ * @return array
264
+ */
265
+ public function getContactDatafields()
266
+ {
267
+ return $this->_contactDatafields;
268
+ }
269
+
270
+ /**
271
+ * @param array $transactionalDefaultDatafields
272
+ */
273
+ public function setTransactionalDefaultDatafields($transactionalDefaultDatafields)
274
+ {
275
+ $this->_transactionalDefaultDatafields = $transactionalDefaultDatafields;
276
+ }
277
+
278
+ /**
279
+ * @return array
280
+ */
281
+ public function getTransactionalDefaultDatafields()
282
+ {
283
+ return $this->_transactionalDefaultDatafields;
284
+ }
285
+
286
+ /**
287
+ * @param mixed $defaultDataFields
288
+ */
289
+ public function setDefaultDataFields($defaultDataFields)
290
+ {
291
+ $this->_defaultDataFields = $defaultDataFields;
292
+ }
293
+
294
+ /**
295
+ * @return mixed
296
+ */
297
+ public function getDefaultDataFields()
298
+ {
299
+ return $this->_defaultDataFields;
300
+ }
301
+
302
+ /**
303
+ * set a single datafield.
304
+ *
305
+ * @param $name
306
+ * @param $value
307
+ * @param string $type
308
+ * @param string $visibility
309
+ *
310
+ * @return array
311
+ */
312
+ public function setDatafield($name, $value, $type = 'string', $visibility = 'public')
313
+ {
314
+ $this->datafields[] = array(
315
+ 'name' => $name,
316
+ 'value' => $value,
317
+ 'type' => $type,
318
+ 'visibility' => $visibility
319
+ );
320
+ return $this->datafields;
321
+ }
322
+
323
+ }
app/code/community/Dotdigitalgroup/Email/Model/Connector/Order.php ADDED
@@ -0,0 +1,207 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Connector_Order
4
+ {
5
+ /**
6
+ * Order Increment ID
7
+ * @var string
8
+ */
9
+ public $id;
10
+ /**
11
+ * Email
12
+ * @var string
13
+ */
14
+ public $email;
15
+ /**
16
+ * @var int
17
+ */
18
+ public $quote_id;
19
+ /**
20
+ * @var string
21
+ */
22
+ public $store_name;
23
+ /**
24
+ * @var string
25
+ */
26
+ public $purchase_date;
27
+ /**
28
+ * @var string
29
+ */
30
+ public $delivery_address;
31
+ /**
32
+ * @var string
33
+ */
34
+ public $billing_address;
35
+ /**
36
+ * @var array
37
+ */
38
+ public $products = array();
39
+ /**
40
+ * @var float
41
+ */
42
+ public $order_subtotal;
43
+ /**
44
+ * @var float
45
+ */
46
+ public $discount_ammount;
47
+ /**
48
+ * @var float
49
+ */
50
+ public $order_total;
51
+ /**
52
+ * @var array
53
+ */
54
+ public $categories;
55
+ /**
56
+ * Payment name
57
+ * @var string
58
+ */
59
+ public $payment;
60
+ /**
61
+ * @var string
62
+ */
63
+ public $delivery_method;
64
+ /**
65
+ * @var float
66
+ */
67
+ public $delivery_total;
68
+ /**
69
+ * @var string
70
+ */
71
+ public $currency;
72
+
73
+
74
+ public $couponCode;
75
+
76
+ /**
77
+ * set the order information
78
+ * @param Mage_Sales_Model_Order $orderData
79
+ */
80
+ public function __construct(Mage_Sales_Model_Order $orderData)
81
+ {
82
+ $customerModel = Mage::getModel('customer/customer');
83
+ $customerModel->load($orderData->getCustomerId());
84
+
85
+ $this->id = $orderData->getIncrementId();
86
+ $this->quote_id = $orderData->getQuoteId();
87
+ $this->email = $orderData->getCustomerEmail();
88
+ $this->store_name = $orderData->getStoreName();
89
+
90
+ $created_at = new Zend_Date($orderData->getCreatedAt(), Zend_Date::ISO_8601);
91
+
92
+ $this->purchase_date = $created_at->toString(Zend_Date::ISO_8601);
93
+ $this->delivery_method = $orderData->getShippingDescription();
94
+ $this->delivery_total = $orderData->getShippingAmount();
95
+ $this->currency = $orderData->getStoreCurrencyCode();
96
+
97
+ if ($payment = $orderData->getPayment())
98
+ $this->payment = $payment->getMethodInstance()->getTitle();
99
+ $this->couponCode = $orderData->getCouponCode();
100
+
101
+ /**
102
+ * Billing address.
103
+ */
104
+ if ($orderData->getBillingAddress()) {
105
+ $billingData = $orderData->getBillingAddress()->getData();
106
+ $this->billing_address = array(
107
+ 'billing_address_1' => $this->_getStreet($billingData['street'], 1),
108
+ 'billing_address_2' => $this->_getStreet($billingData['street'], 2),
109
+ 'billing_city' => $billingData['city'],
110
+ 'billing_region' => $billingData['region'],
111
+ 'billing_country' => $billingData['country_id'],
112
+ 'billing_postcode' => $billingData['postcode'],
113
+ );
114
+ }
115
+ /**
116
+ * Shipping address.
117
+ */
118
+ if ($orderData->getShippingAddress()) {
119
+ $shippingData = $orderData->getShippingAddress()->getData();
120
+
121
+ $this->delivery_address = array(
122
+ 'delivery_address_1' => $this->_getStreet($shippingData['street'], 1),
123
+ 'delivery_address_2' => $this->_getStreet($shippingData['street'], 2),
124
+ 'delivery_city' => $shippingData['city'],
125
+ 'delivery_region' => $shippingData['region'],
126
+ 'delivery_country' => $shippingData['country_id'],
127
+ 'delivery_postcode' => $shippingData['postcode']
128
+ );
129
+ }
130
+
131
+ /**
132
+ * Order items.
133
+ */
134
+ foreach ($orderData->getAllItems() as $productItem) {
135
+
136
+ $product = $productItem->getProduct();
137
+ if ($product) {
138
+ // category names
139
+ $categoryCollection = $product->getCategoryCollection()
140
+ ->addAttributeToSelect( 'name' );
141
+
142
+ foreach ( $categoryCollection as $cat ) {
143
+ $categories = array();
144
+ $categories[] = $cat->getName();
145
+ $this->categories[]['Name'] = substr( implode( ', ', $categories ), 0, 244 );
146
+ }
147
+
148
+ $attributeSetModel = Mage::getModel( "eav/entity_attribute_set" );
149
+ $attributeSetModel->load( $product->getAttributeSetId() );
150
+ $attributeSetName = $attributeSetModel->getAttributeSetName();
151
+ $this->products[] = array(
152
+ 'name' => $productItem->getName(),
153
+ 'sku' => $productItem->getSku(),
154
+ 'qty' => (int) number_format( $productItem->getData( 'qty_ordered' ), 2 ),
155
+ 'price' => (float) number_format( $productItem->getPrice(), 2, '.', '' ),
156
+ 'attribute-set' => $attributeSetName
157
+ );
158
+ } else {
159
+ // when no product information is available limit to this data
160
+ $this->products[] = array(
161
+ 'name' => $productItem->getName(),
162
+ 'sku' => $productItem->getSku(),
163
+ 'qty' => (int) number_format( $productItem->getData( 'qty_ordered' ), 2 ),
164
+ 'price' => (float) number_format( $productItem->getPrice(), 2, '.', '' )
165
+ );
166
+ }
167
+ }
168
+
169
+ $this->order_subtotal = (float)number_format($orderData->getData('subtotal'), 2 , '.', '');
170
+ $this->discount_ammount = (float)number_format($orderData->getData('discount_amount'), 2 , '.', '');
171
+ $orderTotal = abs($orderData->getData('grand_total') - $orderData->getTotalRefunded());
172
+ $this->order_total = (float)number_format($orderTotal, 2 , '.', '');
173
+
174
+ return true;
175
+ }
176
+ /**
177
+ * get the street name by line number
178
+ * @param $street
179
+ * @param $line
180
+ * @return string
181
+ */
182
+ private function _getStreet($street, $line)
183
+ {
184
+ $street = explode("\n", $street);
185
+ if ($line == 1) {
186
+ return $street[0];
187
+ }
188
+ if (isset($street[$line -1])) {
189
+
190
+ return $street[$line - 1];
191
+ } else {
192
+
193
+ return '';
194
+ }
195
+ }
196
+
197
+ /**
198
+ * exposes the class as an array of objects.
199
+ * @return array
200
+ */
201
+ public function expose()
202
+ {
203
+ return get_object_vars($this);
204
+
205
+ }
206
+
207
+ }
app/code/community/Dotdigitalgroup/Email/Model/Contact.php ADDED
@@ -0,0 +1,205 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Contact extends Mage_Core_Model_Abstract
4
+ {
5
+
6
+ const EMAIL_CONTACT_IMPORTED = 1;
7
+ const EMAIL_CONTACT_NOT_IMPORTED = null;
8
+ const EMAIL_SUBSCRIBER_NOT_IMPORTED = null;
9
+ /**
10
+ * constructor
11
+ */
12
+ public function _construct()
13
+ {
14
+ parent::_construct();
15
+ $this->_init('email_connector/contact');
16
+ }
17
+
18
+
19
+ /**
20
+ * @return $this|Mage_Core_Model_Abstract
21
+ */
22
+ protected function _beforeSave()
23
+ {
24
+ parent::_beforeSave();
25
+ $now = Mage::getSingleton('core/date')->gmtDate();
26
+ if ($this->isObjectNew()) {
27
+ $this->setCreatedAt($now);
28
+ }
29
+ return $this;
30
+ }
31
+
32
+ /**
33
+ * Reset the imported contacts
34
+ * @return int
35
+ */
36
+ public function resetAllContacts()
37
+ {
38
+
39
+ /** @var $coreResource Mage_Core_Model_Resource */
40
+ $coreResource = Mage::getSingleton('core/resource');
41
+
42
+ /** @var $conn Varien_Db_Adapter_Pdo_Mysql */
43
+ $conn = $coreResource->getConnection('core_write');
44
+
45
+ try{
46
+ $num = $conn->update($coreResource->getTableName('email_connector/contact'),
47
+ array('email_imported' => new Zend_Db_Expr('null')),
48
+ $conn->quoteInto('email_imported is ?', new Zend_Db_Expr('not null'))
49
+ );
50
+ }catch (Exception $e){
51
+ Mage::logException($e);
52
+ Mage::helper('connector')->rayLog('300', $e);
53
+ }
54
+ return $num;
55
+ }
56
+
57
+
58
+ /**
59
+ * Load contact by customer id
60
+ * @param $customerId
61
+ * @return mixed
62
+ */
63
+ public function loadByCustomerId($customerId)
64
+ {
65
+ $collection = $this->getCollection()
66
+ ->addFieldToFilter('customer_id', $customerId)
67
+ ->setPageSize(1);
68
+
69
+ if($collection->count())
70
+ return $collection->getFirstItem();
71
+
72
+ return $this;
73
+ }
74
+
75
+ /**
76
+ * get all customer contacts not imported for a website.
77
+ *
78
+ * @param $websiteId
79
+ * @param int $pageSize
80
+ *
81
+ * @return Dotdigitalgroup_Email_Model_Resource_Contact_Collection
82
+ */
83
+ public function getContactsToImportForWebsite($websiteId, $pageSize = 100)
84
+ {
85
+ $collection = $this->getCollection()
86
+ ->addFieldToFilter('website_id', $websiteId)
87
+ ->addFieldToFilter('email_imported', array('null' => true))
88
+ ->addFieldToFilter('customer_id', array('notnull' => true));
89
+
90
+ $collection->getSelect()->limit($pageSize);
91
+
92
+ return $collection;
93
+ }
94
+
95
+ /**
96
+ * Get missing contacts.
97
+ * @param $websiteId
98
+ * @param int $pageSize
99
+ * @return mixed
100
+ */
101
+ public function getMissingContacts($websiteId, $pageSize = 100)
102
+ {
103
+ $collection = $this->getCollection()
104
+ ->addFieldToFilter('contact_id', array('null' => true))
105
+ ->addFieldToFilter('suppressed', null)
106
+ ->addFieldToFilter('website_id', $websiteId);
107
+
108
+ $collection->getSelect()->limit($pageSize);
109
+
110
+ return $collection->load();
111
+ }
112
+
113
+ /**
114
+ * Load Contact by Email.
115
+ * @param $email
116
+ * @param $websiteId
117
+ * @return $this
118
+ */
119
+ public function loadByCustomerEmail($email, $websiteId)
120
+ {
121
+ $collection = $this->getCollection()
122
+ ->addFieldToFilter('email', $email)
123
+ ->addFieldToFilter('website_id', $websiteId)
124
+ ->setPageSize(1);
125
+
126
+ if ($collection->count()) {
127
+ return $collection->getFirstItem();
128
+ } else {
129
+ $this->setEmail($email)
130
+ ->setWebsiteId($websiteId);
131
+ }
132
+ return $this;
133
+ }
134
+
135
+ /**
136
+ * batch non imported subscribers for a website.
137
+ * @param $website
138
+ * @param int $limit
139
+ *
140
+ * @return Dotdigitalgroup_Email_Model_Resource_Contact_Collection
141
+ */
142
+ public function getSubscribersToImport($website, $limit = 1000)
143
+ {
144
+ $storeIds = $website->getStoreIds();
145
+ $collection = $this->getCollection()
146
+ ->addFieldToFilter('is_subscriber', array('notnull' => true))
147
+ ->addFieldToFilter('subscriber_imported', array('null' => true))
148
+ ->addFieldToFilter('store_id', array('in' => $storeIds));
149
+
150
+ $collection->getSelect()->limit($limit);
151
+
152
+ return $collection;
153
+ }
154
+
155
+ /**
156
+ * get all not imported guests for a website.
157
+ * @param $website
158
+ *
159
+ * @return Dotdigitalgroup_Email_Model_Resource_Contact_Collection
160
+ */
161
+ public function getGuests($website)
162
+ {
163
+ $guestCollection = $this->getCollection()
164
+ ->addFieldToFilter('is_guest', array('notnull' => true))
165
+ ->addFieldToFilter('email_imported', array('null' => true))
166
+ ->addFieldToFilter('website_id', $website->getId());
167
+ return $guestCollection->load();
168
+ }
169
+
170
+ public function getNumberOfImportedContacs()
171
+ {
172
+ $collection = $this->getCollection()
173
+ ->addFieldToFilter('email_imported', array('notnull' => true));
174
+
175
+ return $collection->getSize();
176
+ }
177
+
178
+
179
+ /**
180
+ * Set all imported subscribers for reimport.
181
+ *
182
+ * @return int
183
+ */
184
+ public function resetSubscribers() {
185
+
186
+ /** @var $coreResource Mage_Core_Model_Resource */
187
+ $coreResource = Mage::getSingleton( 'core/resource' );
188
+
189
+ /** @var $conn Varien_Db_Adapter_Pdo_Mysql */
190
+ $conn = $coreResource->getConnection( 'core_write' );
191
+
192
+ try {
193
+ $num = $conn->update(
194
+ $coreResource->getTableName( 'email_connector/contact' ),
195
+ array('subscriber_imported' => new Zend_Db_Expr( 'null' ) ),
196
+ $conn->quoteInto('subscriber_imported is ?', new Zend_Db_Expr('not null')));
197
+
198
+ } catch ( Exception $e ) {
199
+ Mage::logException($e);
200
+ Mage::helper('connector')->getRaygunClient()->SendException($e, array(Mage::getBaseUrl('web')));
201
+ }
202
+
203
+ return $num;
204
+ }
205
+ }
app/code/community/Dotdigitalgroup/Email/Model/Controller/Observer.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Controller_Observer
4
+ {
5
+ /**
6
+ * @param $observer
7
+ *
8
+ * @return $this
9
+ */
10
+ public function controllerActionPostdispatch( $observer )
11
+ {
12
+ //event data
13
+ $event = $observer->getEvent();
14
+
15
+ //check for module name is a match for current request
16
+ if ($event->getControllerAction()->getRequest()->getModuleName() == 'connector') {
17
+
18
+ //check if the geoip module is installed
19
+ $modules = Mage::getConfig()->getNode('modules')->children();
20
+ $modulesArray = (array)$modules;
21
+
22
+ //module installed make sure don't redirect
23
+ if (isset($modulesArray['Sandfox_GeoIP'])) {
24
+
25
+ //order id param
26
+ $orderId = $event->getControllerAction()->getRequest()->getParam( 'order_id', false );
27
+
28
+ //order id param is set
29
+ if ( $orderId ) {
30
+ $order = Mage::getModel( 'sales/order' )->load( $orderId );
31
+ $store = Mage::app()->getStore( $order->getStore() );
32
+ //order still exits and store name is different than the order
33
+ if ( $order->getId() && $store->getName() != Mage::app()->getStore()->getName()) {
34
+
35
+ //redirect to original store
36
+ $event->getControllerAction()->getResponse()->setRedirect( $store->getCurrentUrl( false ) );
37
+ }
38
+ }
39
+ }
40
+ }
41
+ return $this;
42
+ }
43
+ }
app/code/community/Dotdigitalgroup/Email/Model/Cron.php ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Cron
4
+ {
5
+ /**
6
+ * CRON FOR CONTACTS SYNC
7
+ */
8
+ public function contactSync()
9
+ {
10
+ // send customers
11
+ $result = Mage::getModel('email_connector/apiconnector_contact')->sync();
12
+ return $result;
13
+ }
14
+
15
+ /**
16
+ * CRON FOR LOST BASKET
17
+ */
18
+ public function lostBaskets()
19
+ {
20
+ //don't execute if the cron is running from shell
21
+ if (! Mage::getStoreConfigFlag(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_ABANDONED_CART_SHELL)) {
22
+ // send lost basket
23
+ Mage::getModel( 'email_connector/sales_quote' )->proccessLostBaskets();
24
+ }
25
+ }
26
+
27
+ /**
28
+ * CRON FOR ORDER TRANSACTIONAL DATA
29
+ */
30
+ public function orderSync()
31
+ {
32
+ // send order
33
+ $result = Mage::getModel('email_connector/sales_order')->sync();
34
+ return $result;
35
+ }
36
+
37
+ /**
38
+ * CRON FOR SUBSCRIBERS AND GUEST CONTACTS
39
+ */
40
+ public function subscribersAndGuestSync()
41
+ {
42
+ //sync subscribers
43
+ $subscriberModel = Mage::getModel('email_connector/newsletter_subscriber');
44
+ $result = $subscriberModel->sync();
45
+
46
+ //unsubscribe suppressed contacts
47
+ $subscriberModel->unsubscribe();
48
+
49
+ //sync guests
50
+ Mage::getModel('email_connector/customer_guest')->sync();
51
+ return $result;
52
+ }
53
+
54
+ /**
55
+ * CRON FOR EMAILS SENDING
56
+ */
57
+ public function sendMappedEmails()
58
+ {
59
+ Mage::getModel('email_connector/campaign')->sendCampaigns();
60
+
61
+ return $this;
62
+ }
63
+
64
+ /**
65
+ * CLEAN ARHIVED FOLDERS
66
+ */
67
+ public function cleaning()
68
+ {
69
+ $helper = Mage::helper('connector/file');
70
+ $archivedFolder = $helper->getArchiveFolder();
71
+ $result = $helper->deleteDir($archivedFolder);
72
+ $message = 'Cleaning cronjob result : ' . $result;
73
+ $helper->log($message);
74
+ Mage::helper('connector')->rayLog('10', $message, 'model/cron.php');
75
+ return $result;
76
+ }
77
+
78
+
79
+ /**
80
+ * Last customer sync date.
81
+ * @return bool|string
82
+ */
83
+ public function getLastCustomerSync(){
84
+
85
+ $schedules = Mage::getModel('cron/schedule')->getCollection();
86
+ $schedules->getSelect()->limit(1)->order('executed_at DESC');
87
+ $schedules->addFieldToFilter('status', Mage_Cron_Model_Schedule::STATUS_SUCCESS);
88
+ $schedules->addFieldToFilter('job_code', 'connector_email_customer_sync');
89
+ $schedules->load();
90
+
91
+ if (count($schedules) == 0) {
92
+ return false;
93
+ }
94
+ $executedAt = $schedules->getFirstItem()->getExecutedAt();
95
+ return Mage::getModel('core/date')->date(NULL, $executedAt);
96
+ }
97
+
98
+ }
app/code/community/Dotdigitalgroup/Email/Model/Customer/Guest.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Customer_Guest
4
+ {
5
+ protected $_countGuests = 0;
6
+ protected $_start;
7
+
8
+ /**
9
+ * GUEST SYNC.
10
+ */
11
+ public function sync()
12
+ {
13
+ /** @var Dotdigitalgroup_Email_Helper_Data $helper */
14
+ $helper = Mage::helper('connector');
15
+ $helper->log('----------- Start guest sync ----------');
16
+ $this->_start = microtime(true);
17
+ foreach(Mage::app()->getWebsites() as $website) {
18
+
19
+ //check if the guest is mapped and enabled
20
+ $enabled = $helper->getGuestAddressBook($website);
21
+ if ($enabled)
22
+ $this->exportGuestPerWebsite($website);
23
+ }
24
+ $helper->log('---- End Guest total time for guest sync : ' . gmdate("H:i:s", microtime(true) - $this->_start));
25
+ return;
26
+ }
27
+
28
+ public function exportGuestPerWebsite(Mage_Core_Model_Website $website)
29
+ {
30
+ $helper = Mage::helper('connector');
31
+ $fileHelper = Mage::helper('connector/file');
32
+ $guests = Mage::getModel('email_connector/contact')->getGuests($website);
33
+ if ($guests->getSize()) {
34
+ $client = Mage::helper('connector')->getWebsiteApiClient($website);
35
+ $guestFilename = strtolower($website->getCode() . '_guest_' . date('d_m_Y_Hi') . '.csv');
36
+ $helper->log('Guest file: ' . $guestFilename);
37
+ $storeName = $helper->getMappedStoreName($website);
38
+ $fileHelper->outputCSV($fileHelper->getFilePath($guestFilename), array('Email', 'emailType', $storeName));
39
+ foreach ($guests as $guest) {
40
+ $email = $guest->getEmail();
41
+ try{
42
+ $guest->setEmailImported(Dotdigitalgroup_Email_Model_Contact::EMAIL_CONTACT_IMPORTED)
43
+ ->save();
44
+ $storeName = $website->getName();
45
+ // save data for guests
46
+ $fileHelper->outputCSV($fileHelper->getFilePath($guestFilename), array($email, 'Html', $storeName));
47
+ $this->_countGuests++;
48
+ }catch (Exception $e){
49
+ Mage::logException($e);
50
+ }
51
+ }
52
+ if ($this->_countGuests) {
53
+ //Add to guest address book
54
+ $client->postAddressBookContactsImport($guestFilename, $helper->getGuestAddressBook($website));
55
+ }
56
+ //arhive guest file
57
+ $fileHelper->archiveCSV($guestFilename);
58
+ }
59
+ }
60
+ }
app/code/community/Dotdigitalgroup/Email/Model/Customer/Observer.php ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Customer_Observer
4
+ {
5
+ /**
6
+ * Create new contact or update info, also check for email change
7
+ * event: customer_save_before
8
+ * @param Varien_Event_Observer $observer
9
+ * @return $this
10
+ */
11
+ public function handleCustomerSaveBefore(Varien_Event_Observer $observer)
12
+ {
13
+ $customer = $observer->getEvent()->getCustomer();
14
+ $email = $customer->getEmail();
15
+ $websiteId = $customer->getWebsiteId();
16
+ $customerId = $customer->getEntityId();
17
+ $isSubscribed = $customer->getIsSubscribed();
18
+ try{
19
+ $emailBefore = Mage::getModel('customer/customer')->load($customer->getId())->getEmail();
20
+ $contactModel = Mage::getModel('email_connector/contact')->loadByCustomerEmail($emailBefore, $websiteId);
21
+ //email change detection
22
+ if ($email != $emailBefore) {
23
+ Mage::helper('connector')->log('email change detected : ' . $email . ', after : ' . $emailBefore . ', website id : ' . $websiteId);
24
+ $enabled = Mage::helper('connector')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED, $websiteId);
25
+
26
+ if ($enabled) {
27
+ $client = Mage::helper('connector')->getWebsiteApiClient($websiteId);
28
+ $subscribersAddressBook = Mage::helper('connector')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SUBSCRIBERS_ADDRESS_BOOK_ID, $websiteId);
29
+ $response = $client->postContacts($emailBefore);
30
+ //check for matching email
31
+ if (isset($response->id)) {
32
+ if ($email != $response->email) {
33
+ $data = array(
34
+ 'Email' => $email,
35
+ 'EmailType' => 'Html'
36
+ );
37
+ //update the contact with same id - different email
38
+ $client->updateContact($response->id, $data);
39
+
40
+ }
41
+ if (!$isSubscribed && $response->status == 'Subscribed') {
42
+ $client->deleteAddressBookContact($subscribersAddressBook, $response->id);
43
+ }
44
+ } elseif (isset($response->message)) {
45
+ Mage::helper('connector')->log('Email change error : ' . $response->message);
46
+ }
47
+ }
48
+ $contactModel->setEmail($email);
49
+ }
50
+
51
+ $contactModel->setEmailImported(Dotdigitalgroup_Email_Model_Contact::EMAIL_CONTACT_NOT_IMPORTED)
52
+ ->setCustomerId($customerId)
53
+ ->save();
54
+ }catch(Exception $e){
55
+ Mage::logException($e);
56
+ }
57
+
58
+ return $this;
59
+ }
60
+
61
+ /**
62
+ * Add new customers to the automation.
63
+ * @param Varien_Event_Observer $observer
64
+ *
65
+ * @return $this
66
+ */
67
+ public function handleCustomerRegiterSuccess(Varien_Event_Observer $observer)
68
+ {
69
+ $customer = $observer->getEvent()->getCustomer();
70
+ $email = $customer->getEmail();
71
+ $websiteId = $customer->getWebsiteId();
72
+
73
+ // send customer to automation mapped
74
+ $this->_postCustomerToAutomation($email, $websiteId);
75
+
76
+ return $this;
77
+ }
78
+
79
+ /**
80
+ * Remove the contact on customer delete.
81
+ *
82
+ * @param Varien_Event_Observer $observer
83
+ *
84
+ * @return $this
85
+ */
86
+ public function handleCustomerDeleteAfter(Varien_Event_Observer $observer)
87
+ {
88
+ $customer = $observer->getEvent()->getCustomer();
89
+ $email = $customer->getEmail();
90
+ $websiteId = $customer->getWebsiteId();
91
+ /**
92
+ * Remove contact.
93
+ */
94
+ try{
95
+ $contactModel = Mage::getModel('email_connector/contact')->loadByCustomerEmail($email, $websiteId);
96
+ if ($contactModel->getId()) {
97
+ //remove contact
98
+ $contactModel->delete();
99
+ }
100
+ //remove from account
101
+ $client = Mage::helper('connector')->getWebsiteApiClient($websiteId);
102
+ $apiContact = $client->postContacts($email);
103
+ if(! isset($apiContact->message) && isset($apiContact->id))
104
+ $client->deleteContact($apiContact->id);
105
+
106
+ }catch (Exception $e){
107
+ Mage::logException($e);
108
+ }
109
+ return $this;
110
+ }
111
+
112
+ private function _postCustomerToAutomation( $email, $websiteId ) {
113
+ /**
114
+ * Automation Programme
115
+ */
116
+ $customerAutoCamaignId = Mage::helper('connector')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_AUTOMATION_STUDIO_CUSTOMER, $websiteId);
117
+ //forward add customer to automation
118
+ if ($customerAutoCamaignId) {
119
+ Mage::helper( 'connector' )->log( 'AS - customer automation Campaign id : ' . $customerAutoCamaignId );
120
+ $client = Mage::helper( 'connector' )->getWebsiteApiClient( $websiteId );
121
+ $apiContact = $client->postContacts($email);
122
+
123
+ // get a program by id
124
+ $program = $client->getProgramById($customerAutoCamaignId);
125
+ /**
126
+ * id
127
+ * name
128
+ * status
129
+ * dateCreated
130
+ */
131
+ Mage::helper( 'connector' )->log( 'AS - get customer Program id : ' . $program->id);
132
+
133
+ $data = array(
134
+ 'Contacts' => array($apiContact->id),
135
+ 'ProgramId' => $program->id,
136
+ 'Status' => $program->status,
137
+ 'DateCreated' => $program->dateCreated,
138
+ 'AddressBooks' => array()
139
+ );
140
+ $client->postProgramsEnrolments($data);
141
+ }
142
+ }
143
+
144
+ /**
145
+ * Set contact to re-import if registered customer submitted a review
146
+ * @param Varien_Event_Observer $observer
147
+ * @return $this
148
+ */
149
+ public function reviewSaveAfter(Varien_Event_Observer $observer)
150
+ {
151
+ $dataObject = $observer->getEvent()->getDataObject();
152
+ if($customerId = $dataObject->getCustomerId()){
153
+ $helper = Mage::helper('connector');
154
+ $helper->setConnectorContactToReImport($customerId);
155
+ }
156
+ return $this;
157
+ }
158
+ }
app/code/community/Dotdigitalgroup/Email/Model/Customer/Wishlist.php ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Customer_Wishlist
4
+ {
5
+ /**
6
+ * @var int
7
+ */
8
+ public $id;
9
+ /**
10
+ * @var int
11
+ */
12
+ public $customer_id;
13
+ /**
14
+ * @var string
15
+ */
16
+ public $email;
17
+
18
+ /**
19
+ * wishlist items.
20
+ * @var array
21
+ */
22
+ public $items = array();
23
+
24
+ /**
25
+ * @var float
26
+ */
27
+ protected $total_wishlist_value;
28
+
29
+ /**
30
+ * constructor.
31
+ *
32
+ * @param Mage_Customer_Model_Customer $customer
33
+ */
34
+ public function __construct(Mage_Customer_Model_Customer $customer)
35
+ {
36
+
37
+ $this->setCustomerId($customer->getId());
38
+ $this->email = $customer->getEmail();
39
+ }
40
+
41
+ /**
42
+ * @param mixed $customer_id
43
+ */
44
+ public function setCustomerId($customer_id)
45
+ {
46
+ $this->customer_id = $customer_id;
47
+ }
48
+
49
+ /**
50
+ * @return mixed
51
+ */
52
+ public function getCustomerId()
53
+ {
54
+ return $this->customer_id;
55
+ }
56
+
57
+ /**
58
+ * @param $id
59
+ * @return $this
60
+ */
61
+ public function setId($id)
62
+ {
63
+ $this->id = $id;
64
+ return $this;
65
+ }
66
+
67
+ /**
68
+ * @return mixed
69
+ */
70
+ public function getId()
71
+ {
72
+ return $this->id;
73
+ }
74
+
75
+ /**
76
+ * set wishlist item.
77
+ *
78
+ * @param $item
79
+ */
80
+ public function setItem($item)
81
+ {
82
+ $this->items[] = $item->expose();
83
+
84
+ $this->total_wishlist_value += $item->getTotalValueOfProduct();
85
+ }
86
+
87
+ /**
88
+ * @return array
89
+ */
90
+ public function expose()
91
+ {
92
+ return get_object_vars($this);
93
+ }
94
+ }
app/code/{local → community}/Dotdigitalgroup/Email/Model/Customer/Wishlist/Item.php RENAMED
@@ -8,18 +8,26 @@ class Dotdigitalgroup_Email_Model_Customer_Wishlist_Item
8
  protected $qty;
9
  protected $total_value_of_product;
10
 
11
- public function __construct($product)
 
 
 
 
 
 
12
  {
13
  $this->setSku($product->getSku());
14
  $this->setName($product->getName());
15
  }
16
 
17
  /**
18
- * @param mixed $name
 
19
  */
20
  public function setName($name)
21
  {
22
  $this->name = $name;
 
23
  }
24
 
25
  /**
@@ -31,11 +39,13 @@ class Dotdigitalgroup_Email_Model_Customer_Wishlist_Item
31
  }
32
 
33
  /**
34
- * @param mixed $qty
 
35
  */
36
  public function setQty($qty)
37
  {
38
  $this->qty = (int)$qty;
 
39
  }
40
 
41
  /**
@@ -55,14 +65,16 @@ class Dotdigitalgroup_Email_Model_Customer_Wishlist_Item
55
  }
56
 
57
  /**
58
- * @param mixed $price
 
59
  */
60
  public function setPrice($product)
61
  {
62
  $this->price = $product->getFinalPrice();
63
  $total = $this->price * $this->qty;
64
 
65
- $this->total_value_of_product = number_format($total, 2);
 
66
  }
67
 
68
  /**
@@ -74,11 +86,13 @@ class Dotdigitalgroup_Email_Model_Customer_Wishlist_Item
74
  }
75
 
76
  /**
77
- * @param mixed $sku
 
78
  */
79
  public function setSku($sku)
80
  {
81
  $this->sku = $sku;
 
82
  }
83
 
84
  /**
@@ -88,13 +102,12 @@ class Dotdigitalgroup_Email_Model_Customer_Wishlist_Item
88
  {
89
  return $this->sku;
90
  }
91
- public function expose() {
92
 
 
 
 
 
 
93
  return get_object_vars($this);
94
-
95
  }
96
-
97
-
98
-
99
-
100
  }
8
  protected $qty;
9
  protected $total_value_of_product;
10
 
11
+
12
+ /**
13
+ * construnctor.
14
+ *
15
+ * @param $product
16
+ */
17
+ public function __construct($product)
18
  {
19
  $this->setSku($product->getSku());
20
  $this->setName($product->getName());
21
  }
22
 
23
  /**
24
+ * @param $name
25
+ * @return $this
26
  */
27
  public function setName($name)
28
  {
29
  $this->name = $name;
30
+ return $this;
31
  }
32
 
33
  /**
39
  }
40
 
41
  /**
42
+ * @param $qty
43
+ * @return $this
44
  */
45
  public function setQty($qty)
46
  {
47
  $this->qty = (int)$qty;
48
+ return $this;
49
  }
50
 
51
  /**
65
  }
66
 
67
  /**
68
+ * @param $product
69
+ * @return $this
70
  */
71
  public function setPrice($product)
72
  {
73
  $this->price = $product->getFinalPrice();
74
  $total = $this->price * $this->qty;
75
 
76
+ $this->total_value_of_product = number_format($total, 2, '.', ',');
77
+ return $this;
78
  }
79
 
80
  /**
86
  }
87
 
88
  /**
89
+ * @param $sku
90
+ * @return $this
91
  */
92
  public function setSku($sku)
93
  {
94
  $this->sku = $sku;
95
+ return $this;
96
  }
97
 
98
  /**
102
  {
103
  return $this->sku;
104
  }
 
105
 
106
+ /**
107
+ * @return array
108
+ */
109
+ public function expose()
110
+ {
111
  return get_object_vars($this);
 
112
  }
 
 
 
 
113
  }
app/code/community/Dotdigitalgroup/Email/Model/Email/Template.php ADDED
@@ -0,0 +1,335 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Email_Template extends Mage_Core_Model_Email_Template
4
+ {
5
+ /**
6
+ * Registered sales emails that can be mapped as transactional emails.
7
+ *
8
+ * @var array
9
+ */
10
+ private $_registered = array(
11
+ 'sales_email_order_template' => 'New Order',
12
+ 'sales_email_order_guest_template' => 'New Order Guest',
13
+ 'sales_email_order_comment_template' => 'Order Update',
14
+ 'sales_email_order_comment_guest_template' => 'Order Update for Guest',
15
+ 'sales_email_invoice_template' => 'New Invoice',
16
+ 'sales_email_invoice_guest_template' => 'New Invoice for Guest',
17
+ 'sales_email_invoice_comment_template' => 'Invoice Update',
18
+ 'sales_email_invoice_comment_guest_template' => 'Invoice Update for Guest',
19
+ 'sales_email_creditmemo_template' => 'New Credit Memo',
20
+ 'sales_email_creditmemo_guest_template' => 'New Credit Memo for Guest',
21
+ 'sales_email_creditmemo_comment_template' => 'Credit Memo Update',
22
+ 'sales_email_creditmemo_comment_guest_template' => 'Credit Memo Update for Guest',
23
+ 'sales_email_shipment_template' => 'New Shipment',
24
+ 'sales_email_shipment_guest_template' => 'New Shipment for Guest',
25
+ 'sales_email_shipment_comment_template' => 'Shipment Update',
26
+ 'sales_email_shipment_comment_guest_template' => 'Shipment Update for Guest',
27
+ );
28
+ /**
29
+ * customer emails that can be mapped as transactional emails.
30
+ *
31
+ * @var array
32
+ */
33
+ private $_registeredCustomer = array(
34
+ 'customer_create_account_email_template' => 'New Customer Account'
35
+ );
36
+
37
+
38
+ /**
39
+ * Send transactional email to recipient
40
+ *
41
+ * @see Mage_Core_Model_Email_Template::sendTransactional()
42
+ * @param string $templateId
43
+ * @param string|array $sender sneder information, can be declared as part of config path
44
+ * @param string $email recipient email
45
+ * @param string $name recipient name
46
+ * @param array $vars varianles which can be used in template
47
+ * @param int|null $storeId
48
+ * @return Mage_Core_Model_Email_Template
49
+ */
50
+ public function sendTransactional($templateId, $sender, $email, $name, $vars=array(), $storeId=null)
51
+ {
52
+ $sendType = Mage::helper('connector/transactional')->getMapping($templateId,Dotdigitalgroup_Email_Helper_Transactional::MAP_COLUMN_KEY_SENDTYPE);
53
+ $transEnabled = Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Transactional::XML_PATH_TRANSACTIONAL_API_ENABLED);
54
+ $campaignId = Mage::helper('connector/transactional')->getMapping($templateId,Dotdigitalgroup_Email_Helper_Transactional::MAP_COLUMN_KEY_DATAFIELD);
55
+
56
+
57
+ //design and send. campaign id is needed for this option
58
+ if ($sendType == 2 && $transEnabled && $campaignId) {
59
+ if(is_array($email)) {
60
+ foreach($email as $one) {
61
+ $this->setSentSuccess($this->designAndSend($templateId, $vars, $campaignId, $one, $storeId));
62
+ }
63
+ } else {
64
+ $this->setSentSuccess($this->designAndSend($templateId, $vars, $campaignId, $email, $storeId));
65
+ }
66
+ return $this;
67
+ }
68
+
69
+ //send via connector
70
+ if($sendType == 1 && $transEnabled)
71
+ return $this->sendTransactionalForOptionViaConnector($templateId, $sender, $email, $name, $vars, $storeId, $sendType);
72
+
73
+ //templates not mapped or mapped "Use System Default"
74
+ return parent::sendTransactional($templateId, $sender, $email, $name, $vars, $storeId);
75
+ }
76
+
77
+ /**
78
+ * send transactional for option "Send via connector"
79
+ *
80
+ * @param $templateId
81
+ * @param $sender
82
+ * @param $email
83
+ * @param $name
84
+ * @param array $vars
85
+ * @param null $storeId
86
+ * @param $sendType
87
+ * @return $this
88
+ * @throws Mage_Core_Exception
89
+ */
90
+ public function sendTransactionalForOptionViaConnector($templateId, $sender, $email, $name, $vars = array(), $storeId = null, $sendType)
91
+ {
92
+ $this->setSentSuccess(false);
93
+ if (($storeId === null) && $this->getDesignConfig()->getStore()) {
94
+ $storeId = $this->getDesignConfig()->getStore();
95
+ }
96
+
97
+ if (is_numeric($templateId)) {
98
+ $this->load($templateId);
99
+ } else {
100
+ $localeCode = Mage::getStoreConfig('general/locale/code', $storeId);
101
+ $this->loadDefault($templateId, $localeCode);
102
+ }
103
+
104
+ if (!$this->getId()) {
105
+ throw Mage::exception('Mage_Core', Mage::helper('core')->__('Invalid transactional email code: %s', $templateId));
106
+ }
107
+
108
+ if (!is_array($sender)) {
109
+ $this->setSenderName(Mage::getStoreConfig('trans_email/ident_' . $sender . '/name', $storeId));
110
+ $this->setSenderEmail(Mage::getStoreConfig('trans_email/ident_' . $sender . '/email', $storeId));
111
+ } else {
112
+ $this->setSenderName($sender['name']);
113
+ $this->setSenderEmail($sender['email']);
114
+ }
115
+
116
+ if (!isset($vars['store'])) {
117
+ $vars['store'] = Mage::app()->getStore($storeId);
118
+ }
119
+ $this->setSentSuccess($this->send($email, $name, $vars, $sendType));
120
+ return $this;
121
+ }
122
+
123
+ /**
124
+ * Send mail to recipient
125
+ *
126
+ * @see Mage_Core_Model_Email_Template::send()
127
+ * @param array|string $email E-mail(s)
128
+ * @param array|string|null $name receiver name(s)
129
+ * @param array $variables template variables
130
+ * @param int $sendType
131
+ * @return boolean
132
+ **/
133
+ public function send($email, $name = null, array $variables = array(), $sendType = null)
134
+ {
135
+ //not mapped templates or mapped as "Use system default"
136
+ if($sendType == null)
137
+ return parent::send($email, $name, $variables);
138
+
139
+ $transEnabled = Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Transactional::XML_PATH_TRANSACTIONAL_API_ENABLED);
140
+ //mapped option "Send via connector"
141
+ if($sendType == 1 && $transEnabled)
142
+ return $this->sendViaConnector($email, $name, $variables);
143
+
144
+ }
145
+
146
+ /**
147
+ * send via connector
148
+ *
149
+ * @param $email
150
+ * @param $name
151
+ * @param $variables
152
+ * @return bool
153
+ * @throws Exception
154
+ */
155
+ public function sendViaConnector($email, $name, $variables)
156
+ {
157
+ $emails = array_values((array)$email);
158
+ $names = is_array($name) ? $name : (array)$name;
159
+ $names = array_values($names);
160
+ foreach ($emails as $key => $email) {
161
+ if (!isset($names[$key])) {
162
+ $names[$key] = substr($email, 0, strpos($email, '@'));
163
+ }
164
+ }
165
+ $variables['email'] = reset($emails);
166
+ $variables['name'] = reset($names);
167
+ $this->setUseAbsoluteLinks(true);
168
+
169
+ $store = $variables['store'];
170
+ $body = $this->getProcessedTemplate($variables, true);
171
+ $subject = $this->getProcessedTemplateSubject($variables);
172
+ $websiteId = $store->getWebsiteId();
173
+
174
+ $helper = Mage::helper('connector/transactional');
175
+ $templateName = $helper->getTemplateLabelById($this->getId());
176
+
177
+ if($helper->getUnsubscribeLink($websiteId))
178
+ $body .= '<br><br>Want to unsubscribe or change your details ' . '<a href="http://$UNSUB$">Unsubscribe from this newsletter</a>';
179
+
180
+ foreach($emails as $email){
181
+ try{
182
+ $now = Mage::getSingleton('core/date')->gmtDate();
183
+ $emailCreate = Mage::getModel('email_connector/campaign');
184
+ $emailCreate
185
+ ->setEmail($email)
186
+ ->setFromName($this->getSenderName())
187
+ ->setWebsiteId($websiteId)
188
+ ->setEventName($templateName)
189
+ ->setSubject($subject)
190
+ ->setHtmlContent($body)
191
+ ->setPlainTextContent($helper->__('Want to unsubscribe or change your details?') . 'http://$UNSUB$')
192
+ ->setCreatedAt($now)
193
+ ->setType(2)
194
+ ->save();
195
+ }catch (Exception $e) {
196
+ Mage::logException($e);
197
+ }
198
+ }
199
+ return true;
200
+ }
201
+
202
+ /**
203
+ * design and send
204
+ *
205
+ * @param $templateId
206
+ * @param $templateParams
207
+ * @param $campaignId
208
+ * @param $email
209
+ * @param $storeId
210
+ * @return bool
211
+ */
212
+ public function designAndSend($templateId, $templateParams, $campaignId, $email, $storeId)
213
+ {
214
+ if (array_key_exists($templateId, $this->_registered)) {
215
+ $this->_registerOrderCampaign($templateId, $templateParams, $campaignId);
216
+ return true;
217
+ }
218
+ if (array_key_exists($templateId, $this->_registeredCustomer)) {
219
+ $this->_registerCustomer($templateId, $templateParams, $campaignId);
220
+ return true;
221
+ }
222
+
223
+ $this->_registerOtherDesignAndSendCampaign($templateId, $campaignId, $email, $storeId);
224
+ return true;
225
+ }
226
+
227
+ /**
228
+ * register sales order campaign.
229
+ *
230
+ * @param $templateId
231
+ * @param $data
232
+ * @param $campaignId
233
+ */
234
+ protected function _registerOrderCampaign($templateId, $data, $campaignId)
235
+ {
236
+ $order = $data['order'];
237
+ $storeId = $order->getStoreId();
238
+ $websiteId = Mage::getModel('core/store')->load($storeId)->getWebsiteId();
239
+
240
+ Mage::helper('connector')->log('-- Sales Order :' . $campaignId);
241
+ try{
242
+ $now = Mage::getSingleton('core/date')->gmtDate();
243
+ //save email for sending
244
+ $emailCampaign = Mage::getModel('email_connector/campaign');
245
+ $emailCampaign->setOrderIncrementId($order->getRealOrderId())
246
+ ->setQuoteId($order->getQuoteId())
247
+ ->setEmail($order->getCustomerEmail())
248
+ ->setCustomerId($order->getCustomerId())
249
+ ->setStoreId($storeId)
250
+ ->setCampaignId($campaignId)
251
+ ->setEventName($this->_registered[$templateId])
252
+ ->setWebsiteId($websiteId)
253
+ ->setCreatedAt($now)
254
+ ;
255
+ $emailCampaign->save();
256
+ }catch (Exception $e){
257
+ Mage::logException($e);
258
+ }
259
+ }
260
+
261
+ /**
262
+ * register customer campaign.
263
+ *
264
+ * @param $templateId
265
+ * @param $data
266
+ * @param $campaignId
267
+ */
268
+ protected function _registerCustomer($templateId, $data, $campaignId)
269
+ {
270
+ $customer = $data['customer'];
271
+ Mage::helper('connector')->log('-- Customer campaign: ' . $campaignId);
272
+ try{
273
+ $now = Mage::getSingleton('core/date')->gmtDate();
274
+ //save email for sending
275
+ $emailCampaign = Mage::getModel('email_connector/campaign');
276
+ $emailCampaign->setEmail($customer->getEmail())
277
+ ->setCustomerId($customer->getId())
278
+ ->setStoreId($customer->getStoreId())
279
+ ->setCampaignId($campaignId)
280
+ ->setEventName($this->_registeredCustomer[$templateId])
281
+ ->setCreatedAt($now);
282
+ $emailCampaign->save();
283
+ }catch (Exception $e) {
284
+ Mage::logException($e);
285
+ }
286
+ }
287
+
288
+ /**
289
+ * design and send option. all campaign which are not in array _registered or array _registeredCustomer
290
+ *
291
+ * @param $templateId
292
+ * @param $campaignId
293
+ * @param $email
294
+ * @param $storeId
295
+ */
296
+ protected function _registerOtherDesignAndSendCampaign($templateId, $campaignId, $email, $storeId)
297
+ {
298
+ $helper = Mage::helper('connector/transactional');
299
+ Mage::helper('connector')->log('-- Other campaign: ' . $campaignId);
300
+ $websiteId = Mage::getModel('core/store')->load($storeId)->getWebsiteId();
301
+
302
+ try{
303
+ $now = Mage::getSingleton('core/date')->gmtDate();
304
+ if($email){
305
+ //save email for sending
306
+ $emailCampaign = Mage::getModel('email_connector/campaign');
307
+ $emailCampaign
308
+ ->setEmail($email)
309
+ ->setStoreId($storeId)
310
+ ->setCampaignId($campaignId)
311
+ ->setWebsiteId($websiteId)
312
+ ->setEventName($helper->getTemplateLabelById($templateId))
313
+ ->setCreatedAt($now);
314
+ $emailCampaign->save();
315
+ }
316
+ }catch (Exception $e) {
317
+ Mage::logException($e);
318
+ }
319
+ }
320
+
321
+ /**
322
+ * find template id in array _registered
323
+ *
324
+ * @param $templateId
325
+ * @return bool
326
+ */
327
+ public function getSalesEvent($templateId)
328
+ {
329
+ if (array_key_exists($templateId, $this->_registered))
330
+ return true;
331
+
332
+ return false;
333
+ }
334
+
335
+ }
app/code/community/Dotdigitalgroup/Email/Model/Feed.php ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Feed extends Mage_AdminNotification_Model_Feed
4
+ {
5
+ /**
6
+ * Check for and extension update
7
+ *
8
+ * @return $this
9
+ */
10
+ public function checkForUpgrade()
11
+ {
12
+ //not enabled
13
+ if(! (bool)Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_FEED_ENABLED)) {
14
+ return;
15
+ }
16
+
17
+ //time this was last checked
18
+ if (($this->getFrequency() + $this->getLastUpdate()) > time()) {
19
+ return $this;
20
+ }
21
+
22
+ //data feed
23
+ $feedData = array();
24
+
25
+ $feedXml = $this->getFeedData();
26
+
27
+ if ($feedXml) {
28
+ foreach ($feedXml->release as $data) {
29
+
30
+ //only if the version number was updated for the connector
31
+ if (version_compare($data->version, Mage::helper('connector')->getConnectorVersion(), '>')) {
32
+
33
+ $feedData[] = array(
34
+ 'severity' => $data->severity,
35
+ 'date_added' => $this->getDate($data->date_added),
36
+ 'title' => (string) $data->title,
37
+ 'description' => (string) $data->description,
38
+ 'url' => (string) $data->link,
39
+ );
40
+ }
41
+ }
42
+
43
+ //admin notification with updated version
44
+ if ($feedData) {
45
+ Mage::getModel('adminnotification/inbox')->parse(array_reverse($feedData));
46
+ }
47
+
48
+ }
49
+ //set the last update check
50
+ $this->setLastUpdate();
51
+
52
+ return $this;
53
+ }
54
+
55
+ /**
56
+ * Set the last update time.
57
+ * @return $this|Mage_AdminNotification_Model_Feed
58
+ */
59
+ public function setLastUpdate()
60
+ {
61
+ Mage::app()->saveCache(time(), Dotdigitalgroup_Email_Helper_Config::CONNECTOR_FEED_LAST_CHECK_TIME);
62
+ return $this;
63
+ }
64
+
65
+ /**
66
+ * @return SimpleXMLElement|void
67
+ */
68
+ public function getFeedUrl()
69
+ {
70
+ if (is_null($this->_feedUrl)) {
71
+ $this->_feedUrl = (Mage::getStoreConfigFlag(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_FEED_USE_HTTPS) ? 'https://' : 'http://')
72
+ . Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_FEED_URL);
73
+ }
74
+
75
+ return $this->_feedUrl;
76
+ }
77
+
78
+
79
+
80
+ /**
81
+ * @return int|mixed
82
+ */
83
+ public function getFrequency()
84
+ {
85
+ return Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_FEED_FREQUENCY) * 3600;
86
+ }
87
+
88
+ }
app/code/community/Dotdigitalgroup/Email/Model/Newsletter/Observer.php ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Newsletter_Observer
4
+ {
5
+
6
+ /**
7
+ * Change the subscribsion for an contact.
8
+ * Add new subscribers to an automation.
9
+ *
10
+ * @param Varien_Event_Observer $observer
11
+ *
12
+ * @return $this
13
+ */
14
+ public function handleNewsletterSubscriberSave(Varien_Event_Observer $observer)
15
+ {
16
+ $helper = Mage::helper('connector');
17
+ $subscriber = $observer->getEvent()->getSubscriber();
18
+ $storeId = $subscriber->getStoreId();
19
+ $email = $subscriber->getEmail();
20
+ $subscriberStatus = $subscriber->getSubscriberStatus();
21
+
22
+ $websiteId = Mage::app()->getStore($subscriber->getStoreId())->getWebsiteId();
23
+ $contactEmail = Mage::getModel('email_connector/contact')->loadByCustomerEmail($email, $websiteId);
24
+ try{
25
+ // send new subscriber to an automation
26
+ if (! Mage::getModel('newsletter/subscriber')->loadByEmail($email)->getId())
27
+ $this->_postSubscriberToAutomation($email, $websiteId);
28
+
29
+ // only for subsribers
30
+ if ($subscriberStatus == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED) {
31
+ //set contact as subscribed
32
+ $contactEmail->setSubscriberStatus($subscriberStatus)
33
+ ->setIsSubscriber(1);
34
+
35
+ $client = Mage::helper('connector')->getWebsiteApiClient($websiteId);
36
+ $apiContact = $client->postContacts($email);
37
+
38
+ //resubscribe suppressed contacts
39
+ if (isset($apiContact->status) && $apiContact->status == 'Suppressed') {
40
+ $client->postContactsResubscribe($apiContact);
41
+ }
42
+ // reset the subscriber as suppressed
43
+ $contactEmail->setSuppressed(null);
44
+
45
+ } else {
46
+ //skip if contact is suppressed
47
+ if ($contactEmail->getSuppressed())
48
+ return $this;
49
+ //update contact id for the subscriber
50
+ $client = Mage::helper('connector')->getWebsiteApiClient($websiteId);
51
+ $contactId = $contactEmail->getContactId();
52
+ //get the contact id
53
+ if (! $contactId) {
54
+ //if contact id is not set get the contact_id
55
+ $result = $client->postContacts($email);
56
+ if (isset($result->id)) {
57
+ $contactId = $result->id;
58
+ } else {
59
+ //no contact id skip
60
+ $contactEmail->setSuppressed('1')
61
+ ->save();
62
+ return $this;
63
+ }
64
+ }
65
+
66
+ //remove contact from address book
67
+ $client->deleteAddressBookContact($helper->getSubscriberAddressBook($websiteId), $contactId);
68
+
69
+ $contactEmail->setIsSubscriber(null)
70
+ ->setSubscriberStatus(Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED);
71
+ }
72
+
73
+ //update the contact
74
+ $contactEmail->setStoreId($storeId);
75
+ if (isset($contactId))
76
+ $contactEmail->setContactId();
77
+ //update contact
78
+ $contactEmail->save();
79
+
80
+ }catch(Exception $e){
81
+ Mage::logException($e);
82
+ Mage::helper('connector')->getRaygunClient()->SendException($e, array(Mage::getBaseUrl('web')));
83
+ }
84
+ return $this;
85
+ }
86
+
87
+
88
+ private function _postSubscriberToAutomation( $email, $websiteId ) {
89
+ /**
90
+ * Automation Programme
91
+ */
92
+ $subscriberAutoCamaignId = Mage::helper('connector')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_AUTOMATION_STUDIO_SUBSCRIBER, $websiteId);
93
+ if ($subscriberAutoCamaignId) {
94
+ $client = Mage::helper( 'connector' )->getWebsiteApiClient( $websiteId );
95
+ $apiContact = $client->postContacts($email);
96
+
97
+ // get a program by id
98
+ $program = $client->getProgramById($subscriberAutoCamaignId);
99
+ /**
100
+ * id
101
+ * name
102
+ * status
103
+ * dateCreated
104
+ */
105
+ //check for active program
106
+ if (isset($program->status) && $program->status != 'Deactivated') {
107
+
108
+ $data = array(
109
+ 'Contacts' => array( $apiContact->id ),
110
+ 'ProgramId' => $program->id,
111
+ 'Status' => $program->status,
112
+ 'DateCreated' => $program->dateCreated,
113
+ 'AddressBooks' => array()
114
+ );
115
+ //add contact to automation enrolment
116
+ $client->postProgramsEnrolments( $data );
117
+ }
118
+ }
119
+ }
120
+ }
app/code/community/Dotdigitalgroup/Email/Model/Newsletter/Subscriber.php ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Newsletter_Subscriber
4
+ {
5
+ const STATUS_SUBSCRIBED = 1;
6
+ const STATUS_NOT_ACTIVE = 2;
7
+ const STATUS_UNSUBSCRIBED = 3;
8
+ const STATUS_UNCONFIRMED = 4;
9
+
10
+ protected $_start;
11
+
12
+ /**
13
+ * Global number of subscriber updated.
14
+ * @var
15
+ */
16
+ protected $_countSubscriber;
17
+
18
+ /**
19
+ * SUBSCRIBER SYNC.
20
+ * @return $this
21
+ */
22
+ public function sync()
23
+ {
24
+ $response = array('success' => true, 'message' => '');
25
+ /** @var Dotdigitalgroup_Email_Helper_Data $helper */
26
+ $helper = Mage::helper('connector');
27
+ $helper->log('---------------------- Start subscriber sync -------------------');
28
+ $this->_start = microtime(true);
29
+
30
+ foreach (Mage::app()->getWebsites(true) as $website) {
31
+ //if subscriber is enabled and mapped
32
+ $enabled = (bool)$website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_SUBSCRIBER_ENABLED);
33
+ $addressBook = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SUBSCRIBERS_ADDRESS_BOOK_ID);
34
+
35
+ if ( $enabled && $addressBook ) {
36
+ $numUpdated = $this->exportSubscribersPerWebsite($website);
37
+ // show message for any number of customers
38
+ if ($numUpdated)
39
+ $response['message'] .= '</br>' . $website->getName() . ', updated subscribers = ' . $numUpdated;
40
+
41
+ }
42
+ }
43
+
44
+ //global number of subscribers to set the message
45
+ if ($this->_countSubscriber) {
46
+ //reponse message
47
+ $message = 'Total time for sync : ' . gmdate("H:i:s", microtime(true) - $this->_start);
48
+
49
+ //put the message in front
50
+ $message .= $response['message'];
51
+ $result['message'] = $message;
52
+ }
53
+
54
+ return $response;
55
+ }
56
+
57
+ /**
58
+ * Export subscriber per website.
59
+ * @param Mage_Core_Model_Website $website
60
+ *
61
+ * @return int
62
+ */
63
+ public function exportSubscribersPerWebsite(Mage_Core_Model_Website $website)
64
+ {
65
+ $updated = 0;
66
+ $fileHelper = Mage::helper('connector/file');
67
+ $limit = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_LIMIT);
68
+ $subscribers = Mage::getModel('email_connector/contact')->getSubscribersToImport($website, $limit);
69
+ if (count($subscribers)) {
70
+ $client = Mage::helper('connector')->getWebsiteApiClient($website);
71
+ $subscribersFilename = strtolower($website->getCode() . '_subscribers_' . date('d_m_Y_Hi') . '.csv');
72
+ //get mapped storename
73
+ $subscriberStorename = Mage::helper('connector')->getMappedStoreName($website);
74
+ //file headers
75
+ $fileHelper->outputCSV($fileHelper->getFilePath($subscribersFilename), array('Email', 'emailType', $subscriberStorename));
76
+ foreach ($subscribers as $subscriber) {
77
+ try{
78
+ $email = $subscriber->getEmail();
79
+ $subscriber->setSubscriberImported(1)->save();
80
+ $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
81
+ $storeName = Mage::app()->getStore($subscriber->getStoreId())->getName();
82
+ // save data for subscribers
83
+ $fileHelper->outputCSV($fileHelper->getFilePath($subscribersFilename), array($email, 'Html', $storeName));
84
+ $updated++;
85
+ }catch (Exception $e){
86
+ Mage::logException($e);
87
+ }
88
+ }
89
+ Mage::helper('connector')->log('Subscriber filename: ' . $subscribersFilename);
90
+ //Add to subscriber address book
91
+ $client->postAddressBookContactsImport($subscribersFilename, $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SUBSCRIBERS_ADDRESS_BOOK_ID));
92
+ $fileHelper->archiveCSV($subscribersFilename);
93
+ }
94
+ //add updated number for the website
95
+ $this->_countSubscriber += $updated;
96
+ return $updated;
97
+ }
98
+
99
+ /**
100
+ * Unsubscribe suppressed contacts.
101
+ * @param bool $force set 10years old
102
+ * @return mixed
103
+ */
104
+ public function unsubscribe($force = false)
105
+ {
106
+ $result['customers'] = 0;
107
+ $limit = 5;
108
+ $max_to_select = 1000;
109
+ $date = Zend_Date::now()->subHour(1);
110
+ $helper = Mage::helper('connector');
111
+ // force sync all customers
112
+ if($force)
113
+ $date = $date->subYear(10);
114
+ // datetime format string
115
+ $dateString = $date->toString(Zend_Date::W3C);
116
+
117
+ /**
118
+ * 1. Sync all suppressed for each store
119
+ */
120
+ foreach (Mage::app()->getWebsites(true) as $website) {
121
+ $enabled = (bool)$website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED);
122
+ if (! $enabled)
123
+ continue;
124
+ $contacts = array();
125
+ $skip = $i = 0;
126
+ $client = Mage::helper('connector')->getWebsiteApiClient($website);
127
+ //there is a maximum of request we need to loop to get more suppressed contacts
128
+ for ($i=0; $i<= $limit;$i++) {
129
+ $apiContacts = $client->getContactsSuppressedSinceDate($dateString, $max_to_select , $skip);
130
+ // skip no more contacts
131
+ if(empty($apiContacts))
132
+ break;
133
+ $contacts = array_merge($contacts, $apiContacts);
134
+ $skip += 1000;
135
+ }
136
+ $subscriberBookId = $helper->getSubscriberAddressBook($website);
137
+ // suppressed contacts to unsubscibe
138
+ foreach ($contacts as $apiContact) {
139
+ if (isset($apiContact->suppressedContact)) {
140
+ $suppressedContact = $apiContact->suppressedContact;
141
+ $email = $suppressedContact->email;
142
+ $contactId = $suppressedContact->id;
143
+ try{
144
+ /**
145
+ * 2. Unsubscribe customer.
146
+ */
147
+ $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
148
+ if ($subscriber->getStatus() == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED) {
149
+ $subscriber->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED);
150
+ $subscriber->save();
151
+ // remove from subscriber address-book
152
+ $client->deleteAddressBookContact($subscriberBookId, $contactId);
153
+ }
154
+ //mark contact as suppressed and unsubscribe
155
+ $contactCollection = Mage::getModel('email_connector/contact')->getCollection()
156
+ ->addFieldToFilter('email', $email)
157
+ ->addFieldToFilter('website_id', $website->getId());
158
+ //unsubscribe from the email contact table.
159
+ foreach ($contactCollection as $contact) {
160
+ $contact->setIsSubscriber(null)
161
+ ->setSuppressed(1)->save();
162
+ }
163
+ }catch (Exception $e){
164
+ Mage::logException($e);
165
+ }
166
+ }
167
+ }
168
+ }
169
+ return $result;
170
+ }
171
+ }
app/code/community/Dotdigitalgroup/Email/Model/Order.php ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Order extends Mage_Core_Model_Abstract
4
+ {
5
+ const EMAIL_ORDER_NOT_IMPORTED = null;
6
+ /**
7
+ * constructor
8
+ */
9
+ public function _construct()
10
+ {
11
+ parent::_construct();
12
+ $this->_init('email_connector/order');
13
+ }
14
+
15
+ /**
16
+ * @return $this|Mage_Core_Model_Abstract
17
+ */
18
+ protected function _beforeSave()
19
+ {
20
+ parent::_beforeSave();
21
+ $now = Mage::getSingleton('core/date')->gmtDate();
22
+ if ($this->isObjectNew()) {
23
+ $this->setCreatedAt($now);
24
+ }
25
+ return $this;
26
+ }
27
+
28
+
29
+ /**
30
+ * Load the email order by quote id.
31
+ * @param $orderId
32
+ * @param $quoteId
33
+ * @return $this|Varien_Object
34
+ */
35
+ public function loadByOrderId($orderId, $quoteId)
36
+ {
37
+ $collection = $this->getCollection()
38
+ ->addFieldToFilter('order_id', $orderId)
39
+ ->addFieldToFilter('quote_id', $quoteId)
40
+ ->setPageSize(1);
41
+
42
+ if ($collection->count()) {
43
+ return $collection->getFirstItem();
44
+ } else {
45
+ $this->setOrderId($orderId)
46
+ ->setQuoteId($quoteId);
47
+ }
48
+ return $this;
49
+ }
50
+
51
+
52
+ /**
53
+ * @param $orderId
54
+ * @param $quoteId
55
+ * @param $storeId
56
+ *
57
+ * @return $this|Varien_Object
58
+ */
59
+ public function getEmailOrderRow($orderId, $quoteId, $storeId)
60
+ {
61
+ $collection = $this->getCollection()
62
+ ->addFieldToFilter('order_id', $orderId)
63
+ ->addFieldToFilter('quote_id', $quoteId)
64
+ ->addFieldToFilter('store_id', $storeId);
65
+
66
+ if ($collection->count()) {
67
+ return $collection->getFirstItem();
68
+ } else {
69
+ $now = Mage::getSingleton('core/date')->gmtDate();
70
+
71
+ $this->setOrderId($orderId)
72
+ ->setQuoteId($quoteId)
73
+ ->setStoreId($storeId)
74
+ ->setCreatedAt($now);
75
+ }
76
+ return $this;
77
+
78
+ }
79
+
80
+ /**
81
+ * Get all orders with particular status within certain days.
82
+ *
83
+ * @param $storeIds
84
+ * @param $limit
85
+ * @param $orderStatuses
86
+ * @param $days
87
+ *
88
+ * @return Dotdigitalgroup_Email_Model_Resource_Order_Collection
89
+ */
90
+ public function getOrdersToImport($storeIds, $limit, $orderStatuses, $days)
91
+ {
92
+ $collection = $this->getCollection()
93
+ ->addFieldToFilter('email_imported', array('null' => true))
94
+ ->addFieldToFilter('store_id', array('in' => $storeIds))
95
+ ->addFieldToFilter('order_status', array('in' => $orderStatuses));
96
+
97
+ if($days)
98
+ {
99
+ $to = Zend_Date::now()->toString('YYYY-MM-dd HH:mm:ss');
100
+ $from = Zend_Date::now()->subDay($days)->toString('YYYY-MM-dd HH:mm:ss');
101
+ $created = array( 'from' => $from, 'to' => $to, 'date' => true);
102
+ $collection->addFieldToFilter('created_at', $created);
103
+ }
104
+
105
+ $collection->getSelect()->limit($limit);
106
+ return $collection->load();
107
+ }
108
+
109
+ /**
110
+ * Get all sent orders older then certain days.
111
+ *
112
+ * @param $storeIds
113
+ * @param $limit
114
+ * @param $days
115
+ *
116
+ * @return Dotdigitalgroup_Email_Model_Resource_Order_Collection
117
+ */
118
+ public function getAllSentOrders($storeIds, $limit, $days)
119
+ {
120
+ $collection = $this->getCollection()
121
+ ->addFieldToFilter('email_imported', 1)
122
+ ->addFieldToFilter('store_id', array('in' => $storeIds));
123
+
124
+ if($days)
125
+ {
126
+ $to = Zend_Date::now()->subDay($days)->toString('YYYY-MM-dd HH:mm:ss');
127
+ $created = array('to' => $to, 'date' => true);
128
+ $collection->addFieldToFilter('created_at', $created);
129
+ }
130
+
131
+ $collection->getSelect()->limit($limit);
132
+ return $collection->load();
133
+ }
134
+
135
+ /**
136
+ * Reset the email order for reimport.
137
+ *
138
+ * @return int
139
+ */
140
+ public function resetOrders()
141
+ {
142
+ /** @var $coreResource Mage_Core_Model_Resource */
143
+ $coreResource = Mage::getSingleton('core/resource');
144
+
145
+ /** @var $conn Varien_Db_Adapter_Pdo_Mysql */
146
+ $conn = $coreResource->getConnection('core_write');
147
+ try{
148
+ $num = $conn->update($coreResource->getTableName('email_connector/order'),
149
+ array('email_imported' => new Zend_Db_Expr('null')),
150
+ $conn->quoteInto('email_imported is ?', new Zend_Db_Expr('not null'))
151
+ );
152
+ }catch (Exception $e){
153
+ Mage::logException($e);
154
+ }
155
+
156
+ return $num;
157
+ }
158
+
159
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Campaign.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Campaign extends Mage_Core_Model_Resource_Db_Abstract
4
+ {
5
+ /**
6
+ * constructor.
7
+ */
8
+ protected function _construct()
9
+ {
10
+ $this->_init('email_connector/campaign', 'id');
11
+
12
+ }
13
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Campaign/Collection.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Campaign_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
4
+ {
5
+ /**
6
+ * constructor.
7
+ */
8
+ public function _construct()
9
+ {
10
+ parent::_construct();
11
+ $this->_init('email_connector/campaign');
12
+ }
13
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Config.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Config extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+
6
+ /**
7
+ * constructor.
8
+ */
9
+ protected function _construct()
10
+ {
11
+ $this->_init('email_connector/config', 'email_config_id');
12
+
13
+ }
14
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Config/Collection.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Config_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
4
+ {
5
+ /**
6
+ * constructor.
7
+ */
8
+ protected function _construct()
9
+ {
10
+ parent::_construct();
11
+ $this->_init('email_connector/config');
12
+ }
13
+
14
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Contact.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Contact extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+
6
+ /**
7
+ * constructor.
8
+ */
9
+ protected function _construct()
10
+ {
11
+ $this->_init('email_connector/contact', 'email_contact_id');
12
+
13
+ }
14
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Contact/Collection.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Contact_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
4
+ {
5
+ /**
6
+ * constructor.
7
+ */
8
+ protected function _construct()
9
+ {
10
+ parent::_construct();
11
+ $this->_init('email_connector/contact');
12
+ }
13
+
14
+
15
+ /**
16
+ * @param $website
17
+ * @return $this
18
+ */
19
+ public function addWebsiteFilter($website)
20
+ {
21
+ $this->addFilter('website_id', $website);
22
+ return $this;
23
+ }
24
+
25
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Order.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Order extends Mage_Core_Model_Resource_Db_Abstract
4
+ {
5
+ /**
6
+ * cosntructor.
7
+ */
8
+ protected function _construct()
9
+ {
10
+ $this->_init('email_connector/order', 'email_order_id');
11
+ }
12
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Order/Collection.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Order_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
4
+ {
5
+
6
+ /**
7
+ * constructor.
8
+ */
9
+ public function _construct()
10
+ {
11
+ parent::_construct();
12
+ $this->_init('email_connector/order');
13
+ }
14
+
15
+
16
+
17
+
18
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Setup.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Setup extends Mage_Eav_Model_Entity_Setup
4
+ {
5
+ /**
6
+ * This method returns true if the attribute exists.
7
+ *
8
+ * @param string|int $entityTypeId
9
+ * @param string|int $attributeId
10
+ * @return bool
11
+ */
12
+ public function attributeExists($entityTypeId, $attributeId)
13
+ {
14
+ try
15
+ {
16
+ $entityTypeId = $this->getEntityTypeId($entityTypeId);
17
+ $attributeId = $this->getAttributeId($entityTypeId, $attributeId);
18
+ return !empty($attributeId);
19
+ }
20
+ catch(Exception $e)
21
+ {
22
+ return FALSE;
23
+ }
24
+ }
25
+
26
+ }
app/code/community/Dotdigitalgroup/Email/Model/Sales/Observer.php ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Sales_Observer
4
+ {
5
+
6
+ /**
7
+ * Register the order status.
8
+ * @param $observer
9
+ * @return $this
10
+ */
11
+ public function handleSalesOrderSaveBefore($observer)
12
+ {
13
+ $order = $observer->getEvent()->getOrder();
14
+ // the reloaded status
15
+ $reloaded = Mage::getModel('sales/order')->load($order->getId());
16
+ Mage::register('sales_order_status_before', $reloaded->getStatus());
17
+ return $this;
18
+ }
19
+ /**
20
+ * save/reset the order as transactional data.
21
+ *
22
+ * @param Varien_Event_Observer $observer
23
+ * @return $this
24
+ */
25
+ public function handleSalesOrderSaveAfter(Varien_Event_Observer $observer)
26
+ {
27
+ try{
28
+ $order = $observer->getEvent()->getOrder();
29
+ $status = $order->getStatus();
30
+ $storeId = $order->getStoreId();
31
+ // start app emulation
32
+ $appEmulation = Mage::getSingleton('core/app_emulation');
33
+ $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);
34
+ $emailOrder = Mage::getModel('email_connector/order')->loadByOrderId($order->getEntityId(), $order->getQuoteId());
35
+ //reimport email order
36
+ $emailOrder->setUpdatedAt($order->getUpdatedAt())
37
+ ->setStoreId($storeId)
38
+ ->setOrderStatus($status);
39
+ if($emailOrder->getEmailImported() != Dotdigitalgroup_Email_Model_Contact::EMAIL_CONTACT_IMPORTED) {
40
+ $emailOrder->setEmailImported(null);
41
+ }
42
+
43
+ // check for order status change
44
+ $statusBefore = Mage::registry('sales_order_status_before');
45
+ if ( $status!= $statusBefore) {
46
+ //If order status has changed and order is already imported then set imported to null
47
+ if($emailOrder->getEmailImported() == Dotdigitalgroup_Email_Model_Contact::EMAIL_CONTACT_IMPORTED) {
48
+ $emailOrder->setEmailImported(Dotdigitalgroup_Email_Model_Contact::EMAIL_CONTACT_NOT_IMPORTED);
49
+ }
50
+ $smsCampaign = Mage::getModel('email_connector/sms_campaign', $order);
51
+ $smsCampaign->setStatus($status);
52
+ $smsCampaign->sendSms();
53
+ // set back the current store
54
+ $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
55
+ }
56
+ $emailOrder->save();
57
+
58
+ //admin oder when editing the first one is canceled
59
+ Mage::unregister('sales_order_status_before');
60
+ }catch(Exception $e){
61
+ Mage::logException($e);
62
+ }
63
+ return $this;
64
+ }
65
+
66
+
67
+ /**
68
+ * Create new order event.
69
+ * @param Varien_Event_Observer $observer
70
+ *
71
+ * @return $this
72
+ * @throws Mage_Core_Exception
73
+ */
74
+ public function handleSalesOrderPlaceAfter(Varien_Event_Observer $observer)
75
+ {
76
+ $data = new Varien_Object();
77
+ $order = $observer->getEvent()->getOrder();
78
+ $website = Mage::app()->getWebsite($order->getWebsiteId());
79
+ $websiteName = $website->getName();
80
+ if (Mage::helper('connector')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Transactional::XML_PATH_TRANSACTIONAL_API_ENABLED, $website)) {
81
+ $storeName = Mage::app()->getStore($order->getStoreId())->getName();
82
+ $data->setCustomerId($order->getCustomerId())
83
+ ->setCustomerEmail($order->getCustomerEmail())
84
+ ->setOrderId($order->getId())
85
+ ->setOrderIncrementId($order->getIncrementId())
86
+ ->setWebsiteName($websiteName)
87
+ ->setStoreName($storeName)
88
+ ->setWebsite($website)
89
+ ->setOrderDate($order->getCreatedAt());
90
+
91
+ Mage::helper('connector/transactional')->updateContactData($data);
92
+ }
93
+
94
+ return $this;
95
+ }
96
+
97
+ /**
98
+ * Sales order refund event.
99
+ *
100
+ * @param Varien_Event_Observer $observer
101
+ *
102
+ * @return $this
103
+ */
104
+ public function handleSalesOrderRefund(Varien_Event_Observer $observer)
105
+ {
106
+ $creditmemo = $observer->getEvent()->getCreditmemo();
107
+ $storeId = $creditmemo->getStoreId();
108
+ $order = $creditmemo->getOrder();
109
+ $orderId = $order->getEntityId();
110
+ $quoteId = $order->getQuoteId();
111
+
112
+ try{
113
+ /**
114
+ * Reimport transactional data.
115
+ */
116
+ $emailOrder = Mage::getModel('email_connector/order')->loadByOrderId($orderId, $quoteId, $storeId);
117
+ if (!$emailOrder->getId()) {
118
+ Mage::helper('connector')->log('ERROR Creditmemmo Order not found :' . $orderId . ', quote id : ' . $quoteId . ', store id ' . $storeId);
119
+ return $this;
120
+ }
121
+ $emailOrder->setEmailImported(Dotdigitalgroup_Email_Model_Contact::EMAIL_CONTACT_NOT_IMPORTED)->save();
122
+ }catch (Exception $e){
123
+ Mage::logException($e);
124
+ }
125
+
126
+ return $this;
127
+ }
128
+
129
+ /**
130
+ * Sales cancel order event, remove transactional data.
131
+ *
132
+ * @param Varien_Event_Observer $observer
133
+ *
134
+ * @return $this
135
+ */
136
+ public function hangleSalesOrderCancel(Varien_Event_Observer $observer)
137
+ {
138
+ $order = $observer->getEvent()->getOrder();
139
+ $storeId = $order->getStoreId();
140
+ $websiteId = Mage::app()->getStore($storeId)->getWebsiteId();
141
+ $customerEmail = $order->getCustomerEmail();
142
+ $helper = Mage::helper('connector');
143
+ if ($helper->isEnabled($websiteId)) {
144
+ $client = Mage::getModel('email_connector/apiconnector_client');
145
+ $client->setApiUsername($helper->getApiUsername($websiteId));
146
+ $client->setApiPassword($helper->getApiPassword($websiteId));
147
+ // delete the order transactional data
148
+ $client->deleteContactTransactionalData($customerEmail, 'Orders');
149
+ }
150
+
151
+ return $this;
152
+ }
153
+ }
app/code/community/Dotdigitalgroup/Email/Model/Sales/Order.php ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Sales_Order
4
+ {
5
+ /**
6
+ * @var array
7
+ */
8
+ protected $accounts = array();
9
+ /**
10
+ * @var string
11
+ */
12
+ private $_apiUsername;
13
+ /**
14
+ * @var string
15
+ */
16
+ private $_apiPassword;
17
+ /**
18
+ * @var array
19
+ */
20
+ protected $ordersToDelete = array();
21
+
22
+ /**
23
+ * Global number of orders
24
+ * @var int
25
+ */
26
+ private $_countOrders = 0;
27
+
28
+ /**
29
+ * initial sync the transactional data
30
+ * @return array
31
+ */
32
+ public function sync()
33
+ {
34
+ $response = array('success' => true, 'message' => '');
35
+ $client = Mage::getModel('email_connector/apiconnector_client');
36
+ // Initialise a return hash containing results of our sync attempt
37
+ $this->_searchAccounts();
38
+ foreach ($this->accounts as $account) {
39
+ $orders = $account->getOrders();
40
+ $numOrders = count($orders);
41
+ $this->_countOrders += $numOrders;
42
+ //send transactional for any number of orders set
43
+ if ($numOrders) {
44
+ $client->setApiUsername($account->getApiUsername())
45
+ ->setApiPassword($account->getApiPassword());
46
+ Mage::helper('connector')->log('--------- Order sync ---------- : ' . count($orders));
47
+ $client->postContactsTransactionalDataImport($orders, 'Orders');
48
+ Mage::helper('connector')->log('----------end order sync----------');
49
+ }
50
+ unset($this->accounts[$account->getApiUsername()]);
51
+ }
52
+
53
+ foreach ($this->ordersToDelete as $websiteId => $collection) {
54
+ if (count($collection)) {
55
+ $client->setApiUsername(Mage::helper('connector')->getApiUsername($websiteId))
56
+ ->setApiPassword(Mage::helper('connector')->getApiPassword($websiteId));
57
+ foreach($collection as $order) {
58
+ $salesOrder = Mage::getModel('sales/order')->load($order->getOrderId());
59
+ Mage::helper('connector')->log('--------- Order sync - delete order number ---------- : ' . $salesOrder->getIncrementId());
60
+ $response = $client->deleteContactsTransactionalData($salesOrder->getIncrementId(), 'Orders');
61
+ if (!isset($response->message))
62
+ $order->setEmailImported(null)->save();
63
+ Mage::helper('connector')->log('----------end order sync - delete ----------');
64
+ }
65
+ }
66
+ unset($this->ordersToDelete[$websiteId]);
67
+ }
68
+
69
+ if ($this->_countOrders)
70
+ $response['message'] = 'Number of updated orders : ' . $this->_countOrders;
71
+ return $response;
72
+ }
73
+
74
+ /**
75
+ * Search the configuration data per website
76
+ */
77
+ private function _searchAccounts()
78
+ {
79
+ $helper = Mage::helper('connector');
80
+ foreach (Mage::app()->getWebsites(true) as $website) {
81
+ if ($helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_ORDER_ENABLED, $website)) {
82
+
83
+ $this->_apiUsername = $helper->getApiUsername($website);
84
+ $this->_apiPassword = $helper->getApiPassword($website);
85
+
86
+ // limit for orders included to sync
87
+ $limit = Mage::helper('connector')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_TRANSACTIONAL_DATA_SYNC_LIMIT, $website);
88
+ if (!isset($this->accounts[$this->_apiUsername])) {
89
+ $account = Mage::getModel('email_connector/connector_account')
90
+ ->setApiUsername($this->_apiUsername)
91
+ ->setApiPassword($this->_apiPassword);
92
+ $this->accounts[$this->_apiUsername] = $account;
93
+ }
94
+ $this->accounts[$this->_apiUsername]->setOrders($this->getConnectorOrders($website, $limit));
95
+ $this->ordersToDelete[$website->getId()] = $this->getConnectorOrdersToDelete($website, $limit);
96
+ }
97
+ }
98
+ }
99
+
100
+ /**
101
+ * get all order to import.
102
+ * @param $website
103
+ * @param int $limit
104
+ * @return array
105
+ */
106
+ public function getConnectorOrders($website, $limit = 100)
107
+ {
108
+ $orders = $customers = array();
109
+ $storeIds = $website->getStoreIds();
110
+ $orderModel = Mage::getModel('email_connector/order');
111
+ if(empty($storeIds))
112
+ return array();
113
+
114
+ $helper = Mage::helper('connector');
115
+ $orderStatuses = $helper->getConfigSelectedStatus($website);
116
+ $days = $helper->getOrderDeleteDays($website);
117
+
118
+ if($orderStatuses)
119
+ $orderCollection = $orderModel->getOrdersToImport($storeIds, $limit, $orderStatuses, $days);
120
+ else
121
+ return array();
122
+
123
+ foreach ($orderCollection as $order) {
124
+ try {
125
+ $salesOrder = Mage::getModel('sales/order')->load($order->getOrderId());
126
+ $storeId = $order->getStoreId();
127
+ $websiteId = Mage::app()->getStore($storeId)->getWebsiteId();
128
+ /**
129
+ * Add guest to contacts table.
130
+ */
131
+ if ($salesOrder->getCustomerIsGuest()) {
132
+ $this->_createGuestContact($salesOrder->getCustomerEmail(), $websiteId, $storeId);
133
+ }
134
+ if ($salesOrder->getId()) {
135
+ $connectorOrder = Mage::getModel('email_connector/connector_order', $salesOrder);
136
+ $orders[] = $connectorOrder;
137
+ }
138
+ $order->setEmailImported(Dotdigitalgroup_Email_Model_Contact::EMAIL_CONTACT_IMPORTED)
139
+ ->save();
140
+ }catch(Exception $e){
141
+ Mage::logException($e);
142
+ }
143
+ }
144
+ return $orders;
145
+ }
146
+
147
+ /**
148
+ * Create a guest contact.
149
+ * @param $email
150
+ * @param $websiteId
151
+ * @param $storeId
152
+ *
153
+ * @return bool
154
+ */
155
+ private function _createGuestContact($email, $websiteId, $storeId){
156
+ try{
157
+ $client = Mage::helper('connector')->getWebsiteApiClient($websiteId);
158
+
159
+ //no api credentials or the guest has no been mapped
160
+ if (! $client || ! $addressBookId = Mage::helper('connector')->getGuestAddressBook($websiteId))
161
+ return false;
162
+ //get contact by email address
163
+ $contactApi = $client->getContactByEmail($email);
164
+ //contac was not found let's create new one
165
+ if (isset($contactApi->message) && $contactApi->message == Dotdigitalgroup_Email_Model_Apiconnector_Client::REST_CONTACT_NOT_FOUND) {
166
+ $contactApi = $client->postContacts($email);
167
+ } elseif (isset($contactApi->message)) {
168
+ Mage::helper('connector')->getRaygunClient()->Send('Creating guest contact with getContactByEmail message : ' . $contactApi->message);
169
+ return false;
170
+ }
171
+
172
+ //add guest to address book
173
+ $response = $client->postAddressBookContacts($addressBookId, $contactApi);
174
+
175
+ //set contact as was found as guest and
176
+ $contactModel = Mage::getModel('email_connector/contact')->loadByCustomerEmail($email, $websiteId);
177
+ $contactModel->setIsGuest(1)
178
+ ->setStoreId($storeId)
179
+ ->setEmailImported(1);
180
+ //contact id
181
+ if (isset($contactApi->id))
182
+ $contactModel->setContactId();
183
+
184
+ //mark the contact as surpressed
185
+ if (isset($response->message) && $response->message == 'Contact is suppressed. ERROR_CONTACT_SUPPRESSED')
186
+ $contactModel->setSuppressed(1);
187
+
188
+ //save
189
+ $contactModel->save();
190
+
191
+ Mage::helper('connector')->log('-- guest found : ' . $email . ' website : ' . $websiteId . ' ,store : ' . $storeId);
192
+ }catch(Exception $e){
193
+ Mage::helper('connector')->getRaygunClient()->SendException($e, array(Mage::getBaseUrl('web')));
194
+ Mage::logException($e);
195
+ }
196
+
197
+ return true;
198
+ }
199
+
200
+ public function getConnectorOrdersToDelete($website, $limit)
201
+ {
202
+ $storeIds = $website->getStoreIds();
203
+ $days = Mage::helper('connector')->getOrderDeleteDays($website);
204
+
205
+ if(empty($storeIds))
206
+ return;
207
+
208
+ if(!$days)
209
+ return;
210
+
211
+ $orderModel = Mage::getModel('email_connector/order');
212
+ return $orderModel->getAllSentOrders($storeIds, $limit, $days);
213
+ }
214
+ }
app/code/community/Dotdigitalgroup/Email/Model/Sales/Quote.php ADDED
@@ -0,0 +1,256 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Sales_Quote
4
+ {
5
+ //customer
6
+ const XML_PATH_LOSTBASKET_CUSTOMER_ENABLED_1 = 'connector_lost_baskets/customers/enabled_1';
7
+ const XML_PATH_LOSTBASKET_CUSTOMER_ENABLED_2 = 'connector_lost_baskets/customers/enabled_2';
8
+ const XML_PATH_LOSTBASKET_CUSTOMER_ENABLED_3 = 'connector_lost_baskets/customers/enabled_3';
9
+ const XML_PATH_LOSTBASKET_CUSTOMER_INTERVAL_1 = 'connector_lost_baskets/customers/send_after_1';
10
+ const XML_PATH_LOSTBASKET_CUSTOMER_INTERVAL_2 = 'connector_lost_baskets/customers/send_after_2';
11
+ const XML_PATH_LOSTBASKET_CUSTOMER_INTERVAL_3 = 'connector_lost_baskets/customers/send_after_3';
12
+ const XML_PATH_LOSTBASKET_CUSTOMER_CAMPAIGN_1 = 'connector_lost_baskets/customers/campaign_1';
13
+ const XML_PATH_LOSTBASKET_CUSTOMER_CAMPAIGN_2 = 'connector_lost_baskets/customers/campaign_2';
14
+ const XML_PATH_LOSTBASKET_CUSTOMER_CAMPAIGN_3 = 'connector_lost_baskets/customers/campaign_3';
15
+
16
+ //guest
17
+ const XML_PATH_LOSTBASKET_GUEST_ENABLED_1 = 'connector_lost_baskets/guests/enabled_1';
18
+ const XML_PATH_LOSTBASKET_GUEST_ENABLED_2 = 'connector_lost_baskets/guests/enabled_2';
19
+ const XML_PATH_LOSTBASKET_GUEST_ENABLED_3 = 'connector_lost_baskets/guests/enabled_3';
20
+ const XML_PATH_LOSTBASKET_GUEST_INTERVAL_1 = 'connector_lost_baskets/guests/send_after_1';
21
+ const XML_PATH_LOSTBASKET_GUEST_INTERVAL_2 = 'connector_lost_baskets/guests/send_after_2';
22
+ const XML_PATH_LOSTBASKET_GUEST_INTERVAL_3 = 'connector_lost_baskets/guests/send_after_3';
23
+ const XML_PATH_LOSTBASKET_GUEST_CAMPAIGN_1 = 'connector_lost_baskets/guests/campaign_1';
24
+ const XML_PATH_LOSTBASKET_GUEST_CAMPAIGN_2 = 'connector_lost_baskets/guests/campaign_2';
25
+ const XML_PATH_LOSTBASKET_GUEST_CAMPAIGN_3 = 'connector_lost_baskets/guests/campaign_3';
26
+
27
+
28
+ /**
29
+ * number of lost baskets available.
30
+ * @var array
31
+ */
32
+ public $lostBasketCustomers = array(1, 2, 3);
33
+ /**
34
+ * number of guest lost baskets available.
35
+ * @var array
36
+ */
37
+ public $lostBasketGuests = array(1, 2, 3);
38
+
39
+
40
+ /**
41
+ * Proccess lost baskets.
42
+ *
43
+ * @param string $mode
44
+ */
45
+ public function proccessLostBaskets($mode = 'all')
46
+ {
47
+ /**
48
+ * Save lost baskets to be send in Send table.
49
+ */
50
+ $locale = Mage::app()->getLocale()->getLocale();
51
+
52
+ foreach (Mage::app()->getStores() as $store) {
53
+ $storeId = $store->getId();
54
+ $sendModel = Mage::getModel('email_connector/campaign');
55
+
56
+ if ($mode == 'all' || $mode == 'customers') {
57
+ /**
58
+ * Customers campaings
59
+ */
60
+ foreach ( $this->lostBasketCustomers as $num ) {
61
+ //customer enabled
62
+ if ( $this->_getLostBasketCustomerEnabled( $num, $storeId ) ) {
63
+
64
+ //number of the campaign use minutes
65
+ if ( $num == 1 ) {
66
+ $from = Zend_Date::now( $locale )->subMinute( $this->_getLostBasketCustomerInterval( $num, $storeId ) );
67
+ //other use hours
68
+ } else {
69
+ $from = Zend_Date::now( $locale )->subHour( $this->_getLostBasketCustomerInterval( $num, $storeId ) );
70
+ }
71
+
72
+ $to = clone( $from );
73
+ $from->sub( '5', Zend_Date::MINUTE );
74
+
75
+ //active quotes
76
+ $quoteCollection = $this->_getStoreQuotes( $from->toString( 'YYYY-MM-dd HH:mm' ), $to->toString( 'YYYY-MM-dd HH:mm' ), $guest = false, $storeId );
77
+
78
+ if ( $quoteCollection->getSize() ) {
79
+ Mage::helper( 'connector' )->log( 'Customer lost baskets : ' . $num . ', from : ' . $from->toString( 'YYYY-MM-dd HH:mm' ) . ':' . $to->toString( 'YYYY-MM-dd HH:mm' ) );
80
+ }
81
+
82
+ //campaign id for customers
83
+ $campaignId = $this->_getLostBasketCustomerCampaignId( $num, $storeId );
84
+ foreach ( $quoteCollection as $quote ) {
85
+
86
+ $email = $quote->getCustomerEmail();
87
+ //send email only if the interval limit passed, no emails during this interval
88
+ $campignFound = $this->_checkCustomerCartLimit( $email, $storeId );
89
+
90
+ //no campign found for interval pass
91
+ if ( !$campignFound ) {
92
+
93
+ //save lost basket for sending
94
+ $sendModel->loadByQuoteId( $quote->getId(), $storeId )
95
+ ->setEmail( $email )
96
+ ->setCustomerId( $quote->getCustomerId() )
97
+ ->setEventName( 'Lost Basket' )
98
+ ->setCampaignId( $campaignId )
99
+ ->setStoreId( $storeId )
100
+ ->setWebsiteId($store->getWebsiteId())
101
+ ->setIsSent( null )->save();
102
+ }
103
+ }
104
+ }
105
+
106
+ }
107
+ }
108
+ if ($mode == 'all' || $mode == 'guests') {
109
+ /**
110
+ * Guests campaigns
111
+ */
112
+ foreach ( $this->lostBasketGuests as $num ) {
113
+ if ( $this->_getLostBasketGuestEnabled( $num, $storeId ) ) {
114
+ if ( $num == 1 ) {
115
+ $from = Zend_Date::now( $locale )->subMinute( $this->_getLostBasketGuestIterval( $num, $storeId ) );
116
+ } else {
117
+ $from = Zend_Date::now( $locale )->subHour( $this->_getLostBasketGuestIterval( $num, $storeId ) );
118
+ }
119
+ $to = clone( $from );
120
+ $from->sub( '5', Zend_Date::MINUTE );
121
+ $quoteCollection = $this->_getStoreQuotes( $from->toString( 'YYYY-MM-dd HH:mm' ), $to->toString( 'YYYY-MM-dd HH:mm' ), $guest = true, $storeId );
122
+
123
+ if ( $quoteCollection->getSize() ) {
124
+ Mage::helper( 'connector' )->log( 'Guest lost baskets : ' . $num . ', from : ' . $from->toString( 'YYYY-MM-dd HH:mm' ) . ':' . $to->toString( 'YYYY-MM-dd HH:mm' ) );
125
+ }
126
+ $guestCampaignId = $this->_getLostBasketGuestCampaignId( $num, $storeId );
127
+ foreach ( $quoteCollection as $quote ) {
128
+ $email = $quote->getCustomerEmail();
129
+
130
+ //send email only if the interval limit passed, no emails during this interval
131
+ $campignFound = $this->_checkCustomerCartLimit( $email, $storeId );
132
+
133
+ //no campign found for interval pass
134
+ if ( !$campignFound ) {
135
+ //save lost basket for sending
136
+ $sendModel->loadByQuoteId( $quote->getId(), $storeId )
137
+ ->setEmail( $email )
138
+ ->setEventName( 'Lost Basket' )
139
+ ->setCheckoutMethod( 'Guest' )
140
+ ->setCampaignId( $guestCampaignId )
141
+ ->setStoreId( $storeId )
142
+ ->setWebsiteId($store->getWebsiteId())
143
+ ->setIsSent( null )->save();
144
+ }
145
+ }
146
+ }
147
+ }
148
+ }
149
+ }
150
+ }
151
+
152
+ private function _getLostBasketCustomerCampaignId($num, $storeId)
153
+ {
154
+ $store = Mage::app()->getStore($storeId);
155
+ return $store->getConfig(constant('self::XML_PATH_LOSTBASKET_CUSTOMER_CAMPAIGN_' . $num));
156
+ }
157
+ private function _getLostBasketGuestCampaignId($num, $storeId)
158
+ {
159
+ $store = Mage::app()->getStore($storeId);
160
+ return $store->getConfig(constant('self::XML_PATH_LOSTBASKET_GUEST_CAMPAIGN_'. $num));
161
+ }
162
+
163
+ private function _getLostBasketCustomerInterval($num, $storeId)
164
+ {
165
+ $store = Mage::app()->getstore($storeId);
166
+ return $store->getConfig(constant('self::XML_PATH_LOSTBASKET_CUSTOMER_INTERVAL_' . $num));
167
+ }
168
+
169
+ private function _getLostBasketGuestIterval($num, $storeId)
170
+ {
171
+ $store = Mage::app()->getStore($storeId);
172
+ return $store->getConfig(constant('self::XML_PATH_LOSTBASKET_GUEST_INTERVAL_' . $num));
173
+ }
174
+
175
+ protected function _getLostBasketCustomerEnabled($num, $storeId)
176
+ {
177
+ $store = Mage::app()->getStore($storeId);
178
+ $enabled = $store->getConfig(constant('self::XML_PATH_LOSTBASKET_CUSTOMER_ENABLED_' . $num));
179
+ return $enabled;
180
+
181
+ }
182
+
183
+ protected function _getLostBasketGuestEnabled($num, $storeId)
184
+ {
185
+ $store = Mage::app()->getStore($storeId);
186
+ return $store->getConfig(constant('self::XML_PATH_LOSTBASKET_GUEST_ENABLED_' . $num));
187
+ }
188
+
189
+ /**
190
+ * @param string $from
191
+ * @param string $to
192
+ * @param bool $guest
193
+ * @param int $storeId
194
+ * @return Mage_Eav_Model_Entity_Collection_Abstract
195
+ */
196
+ private function _getStoreQuotes($from = null, $to = null, $guest = false, $storeId = 0)
197
+ {
198
+ $updated = array(
199
+ 'from' => $from,
200
+ 'to' => $to,
201
+ 'date' => true);
202
+
203
+ $salesCollection = Mage::getResourceModel('sales/quote_collection')
204
+ ->addFieldToFilter('is_active', 1)
205
+ ->addFieldToFilter('items_count', array('gt' => 0))
206
+ ->addFieldToFilter('customer_email', array('neq' => ''))
207
+ ->addFieldToFilter('store_id', $storeId)
208
+ ->addFieldToFilter('updated_at', $updated);
209
+ if ($guest)
210
+ $salesCollection->addFieldToFilter('checkout_method' , Mage_Checkout_Model_Type_Onepage::METHOD_GUEST);
211
+
212
+ return $salesCollection;
213
+ }
214
+
215
+ /**
216
+ * Check customer campaign that was sent by a limit from config.
217
+ * Return false for any found for this period.
218
+ *
219
+ * @param $email
220
+ * @param $storeId
221
+ *
222
+ * @return bool
223
+ */
224
+ private function _checkCustomerCartLimit($email, $storeId) {
225
+
226
+ $cartLimit = Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_ABANDONED_CART_LIMIT, $storeId);
227
+ $locale = Mage::app()->getLocale()->getLocale();
228
+
229
+ //no limit is set skip
230
+ if (! $cartLimit)
231
+ return false;
232
+
233
+ //time diff
234
+ $to = Zend_Date::now($locale);
235
+ $from = Zend_Date::now($locale)->subHour($cartLimit);
236
+
237
+ $updated = array(
238
+ 'from' => $from,
239
+ 'to' => $to,
240
+ 'date' => true
241
+ );
242
+
243
+ //number of campigns during this time
244
+ $campaignLimit = Mage::getModel('email_connector/campaign')->getCollection()
245
+ ->addFieldToFilter('email', $email)
246
+ ->addFieldToFilter('event_name', 'Lost Basket')
247
+ ->addFieldToFilter('sent_at', $updated)
248
+ ->count()
249
+ ;
250
+
251
+ if ($campaignLimit)
252
+ return true;
253
+
254
+ return false;
255
+ }
256
+ }
app/code/community/Dotdigitalgroup/Email/Model/Sms/Campaign.php ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Sms_Campaign
4
+ {
5
+ const UK_TELEPHONE_PATTERN = '/^(\+44\s?7\d{3}|\(?07\d{3}\)?)\s?\d{3}\s?\d{3}$/';
6
+
7
+ /**
8
+ * @var int
9
+ */
10
+ private $_storeId;
11
+ /**
12
+ * @var string
13
+ */
14
+ private $_status;
15
+ /**
16
+ * @var string
17
+ */
18
+ private $_customerFirstName;
19
+ /**
20
+ * @var string
21
+ */
22
+ private $_customerTelephone;
23
+
24
+ /**
25
+ * @var int
26
+ */
27
+ private $_incrementId;
28
+
29
+ /**
30
+ * @var array
31
+ */
32
+ private $_allsms = array(1, 2, 3, 4);
33
+ /**
34
+ * filter for the variables
35
+ * @var array
36
+ */
37
+ private $_vars = array('/customer_name/', '/order_number/', '/{{var /', '/}}/');
38
+
39
+
40
+ /**
41
+ * constructor.
42
+ *
43
+ * @param $order
44
+ */
45
+ public function __construct($order)
46
+ {
47
+ $this->_storeId = $order->getStoreId();
48
+ $billingAddress = $order->getBillingAddress();
49
+ $this->_customerFirstName = $order->getCustomerFirstname();
50
+ $this->_incrementId = $order->getIncrementId();
51
+ $this->_customerTelephone = $billingAddress->getTelephone();
52
+ }
53
+ /**
54
+ * @return mixed
55
+ */
56
+ public function getStatus()
57
+ {
58
+ return $this->_status;
59
+ }
60
+
61
+ /**
62
+ * @param mixed $status
63
+ */
64
+ public function setStatus($status)
65
+ {
66
+ $this->_status = $status;
67
+ }
68
+
69
+ public function sendSms()
70
+ {
71
+ $website = Mage::app()->getStore($this->_storeId)->getWebsite();
72
+ $client = Mage::helper('connector')->getWebsiteApiClient($website);
73
+ //all available sms in config
74
+ foreach ($this->_allsms as $num) {
75
+
76
+ $enabled = (bool)Mage::getStoreConfig(constant('Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SMS_ENABLED_' . $num));
77
+ if ($enabled) {
78
+ $status = Mage::getStoreConfig(constant('Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SMS_STATUS_' . $num));
79
+ $message = $this->_processMessage(Mage::getStoreConfig(constant('Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SMS_MESSAGE_' . $num)));
80
+ $match = preg_match(self::UK_TELEPHONE_PATTERN, $this->_customerTelephone);
81
+ if ($match != false) {
82
+ $codePhone = preg_replace('/\A(0){1}+/', '+44', $this->_customerTelephone);
83
+ //status and telephone valid
84
+ if ($this->_status == $status) {
85
+ Mage::helper('connector')->log('sending sms message with status : ' . $status . ' and ' . $codePhone);
86
+ $client->postSmsMessagesSendTo($codePhone, $message);
87
+ }
88
+ } else {
89
+ Mage::helper('connector')->log('SMS: phone not valid for UK : ' . $this->_customerTelephone);
90
+ }
91
+ }
92
+ }
93
+ }
94
+
95
+ /**
96
+ * @param $message
97
+ * @return mixed
98
+ */
99
+ protected function _processMessage($message)
100
+ {
101
+ $replacemant = array();
102
+ if (preg_match('/{{var/', $message)) {
103
+ $replacemant[] = $this->_customerFirstName;
104
+ $replacemant[] = $this->_incrementId;
105
+ $replacemant[] = '';
106
+ $replacemant[] = '';
107
+ $message = preg_replace($this->_vars, $replacemant, $message);
108
+ }
109
+ return substr($message, 0, 160);
110
+ }
111
+
112
+ }
app/code/community/Dotdigitalgroup/Email/Model/Sweettooth/Observer.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Sweettooth_Observer
4
+ {
5
+
6
+ public function ConnectorRewardsPointsIndexerUpdate($observer)
7
+ {
8
+ $customer = $observer->getEvent()->getCustomer();
9
+ if (!$customer)
10
+ return $this;
11
+
12
+ $helper = Mage::helper('connector');
13
+ $website = Mage::app()->getWebsite($customer->getWebsiteId());
14
+
15
+ if($helper->isSweetToothToGo($website))
16
+ $helper->setConnectorContactToReImport($customer->getId());
17
+
18
+ return $this;
19
+ }
20
+
21
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/ConnectorController.php ADDED
@@ -0,0 +1,272 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Adminhtml_ConnectorController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+ /**
6
+ * AutoCreate and map datafields.
7
+ */
8
+ public function setupdatafieldsAction()
9
+ {
10
+ $result = array('errors' => false, 'message' => '');
11
+ $websiteParam = $this->getRequest()->getParam('website', 0);
12
+ $website = Mage::app()->getWebsite($websiteParam);
13
+ $apiModel = Mage::helper('connector')->getWebsiteApiClient($website->getId());
14
+ $redirectUrl = Mage::helper('adminhtml')->getUrl('adminhtml/system_config/edit', array('section' => 'connector_data_mapping'));
15
+
16
+ // get all possible datatifileds
17
+ $datafields = Mage::getModel('email_connector/connector_datafield')->getContactDatafields();
18
+ foreach ($datafields as $key => $datafield) {
19
+ $response = $apiModel->postDataFields($datafield);
20
+
21
+ //ignore existing datafields message
22
+ if (isset($response->message) && $response->message != Dotdigitalgroup_Email_Model_Apiconnector_Client::REST_API_DATAFILEDS_EXISTS) {
23
+ $result['errors'] = true;
24
+ $result['message'] .= ' Datafield ' . $datafield['name'] . ' - '. $response->message . '</br>';
25
+ } else {
26
+ if ($websiteParam) {
27
+ $scope = 'websites';
28
+ $scopeId = $website->getId();
29
+ } else {
30
+ $scope = 'default';
31
+ $scopeId = '0';
32
+ }
33
+ /**
34
+ * map the succesful created datafield
35
+ */
36
+ $config = new Mage_Core_Model_Config();
37
+ $config->saveConfig('connector_data_mapping/customer_data/' . $key, strtoupper($datafield['name']), $scope, $scopeId);
38
+ Mage::helper('connector')->log('successfully connected : ' . $datafield['name']);
39
+ }
40
+ }
41
+ if ($result['errors']) {
42
+ Mage::getSingleton('adminhtml/session')->addNotice($result['message']);
43
+ } else {
44
+ Mage::getConfig()->cleanCache();
45
+ Mage::getSingleton('adminhtml/session')->addSuccess('All Datafields Created And Mapped.');
46
+ }
47
+
48
+ $this->_redirectUrl($redirectUrl);
49
+ }
50
+
51
+ /**
52
+ * Reset order for reimport.
53
+ */
54
+ public function resetordersAction()
55
+ {
56
+ $num = Mage::getModel('email_connector/order')->resetOrders();
57
+ Mage::helper('connector')->log('-- Reset Orders for reimport : ' . $num);
58
+ Mage::getSingleton('adminhtml/session')->addSuccess('Done.');
59
+ $this->_redirectReferer();
60
+ }
61
+
62
+ /**
63
+ * Reset customers import.
64
+ */
65
+ public function resetcustomersimportAction()
66
+ {
67
+ Mage::getModel('email_connector/contact')->resetAllContacts();
68
+
69
+ Mage::getSingleton('adminhtml/session')->addSuccess('Customers Refreshed.');
70
+
71
+ $this->_redirectReferer();
72
+ }
73
+
74
+ /**
75
+ * Refresh suppressed contacts.
76
+ */
77
+ public function suppresscontactsAction()
78
+ {
79
+ Mage::getModel('email_connector/newsletter_subscriber')
80
+ ->unsubscribe(true);
81
+ Mage::getSingleton('adminhtml/session')->addSuccess('Done.');
82
+ $this->_redirectReferer();
83
+
84
+ }
85
+ /**
86
+ * Remove contact id's.
87
+ */
88
+ public function deletecontactidsAction()
89
+ {
90
+ /** @var $coreResource Mage_Core_Model_Resource */
91
+ $coreResource = Mage::getSingleton('core/resource');
92
+
93
+ /** @var $conn Varien_Db_Adapter_Pdo_Mysql */
94
+ $conn = $coreResource->getConnection('core_write');
95
+ try{
96
+ $num = $conn->update($coreResource->getTableName('email_connector/contact'),
97
+ array('contact_id' => new Zend_Db_Expr('null')),
98
+ $conn->quoteInto('contact_id is ?', new Zend_Db_Expr('not null'))
99
+ );
100
+ }catch (Exception $e){
101
+ Mage::logException($e);
102
+ }
103
+ Mage::getSingleton('adminhtml/session')->addSuccess('Number Of Contacts Id Removed: '. $num);
104
+ $this->_redirectReferer();
105
+ }
106
+
107
+ /**
108
+ * Ajax API validation.
109
+ */
110
+ public function ajaxvalidationAction()
111
+ {
112
+ $params = $this->getRequest()->getParams();
113
+ $apiUsername = $params['api_username'];
114
+ // use javascript btoa function to encode the password
115
+
116
+ $apiPassword = base64_decode($params['api_password']);
117
+ $message = Mage::getModel('email_connector/apiconnector_test')->ajaxvalidate($apiUsername, $apiPassword);
118
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($message));
119
+ }
120
+
121
+ /**
122
+ * Ajax request to reset the import for contacts.
123
+ */
124
+ public function resetcontactsajaxAction()
125
+ {
126
+ $numReseted = Mage::getModel('email_connector/contact')->resetAllContacts();
127
+ $message = array('reseted' => $numReseted);
128
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($message));
129
+ }
130
+
131
+ /**
132
+ * Ajax requets to reset susbcribers for reimport.
133
+ */
134
+ public function ajaxresetsubscribersAction()
135
+ {
136
+ $num = Mage::getModel('email_connector/contact')->resetSubscribers();
137
+ $message = array('reseted' => $num);
138
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($message));
139
+ }
140
+
141
+ /**
142
+ * Ajax request to reset orders for reimoport.
143
+ */
144
+ public function ajaxresetguestsAction()
145
+ {
146
+ $num = Mage::getModel('email_connector/order')->resetOrders();
147
+ $message = array('reseted' => $num);
148
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($message));
149
+ }
150
+
151
+ public function createnewdatafieldAction()
152
+ {
153
+ //get params required for datafield
154
+ $request = $this->getRequest();
155
+ $name = $request->getParam('name', false);
156
+ $type = $request->getParam('type', false);
157
+ $default = $request->getParam('default', '');
158
+ $access = $request->getParam('access', false);
159
+ $website = $request->getParam('website', 0);
160
+
161
+ //api client for this website
162
+ $client = Mage::helper('connector')->getWebsiteApiClient($website);
163
+ //only if all data is available
164
+ if ($name && $type && $default && $access) {
165
+ //create datafield
166
+ $response = $client->postDataFields($name, $type, $access, $default);
167
+ //error creating datafield message
168
+ if (isset($response->message)) {
169
+ //send error message to backend
170
+ Mage::getSingleton('adminhtml/session')->addError($response->message);
171
+ Mage::helper('connector')->log($response->message);
172
+ } else {
173
+ //success message
174
+ Mage::getSingleton('adminhtml/session')->addSuccess('Datafield created : ' . $name);
175
+ }
176
+ } else {
177
+ $message = 'Name ' . $name . ', type ' . $type . ' default ' . $default . 'access ' . $access;
178
+ Mage::getSingleton('adminhtml/session')->addError('Datafield cannot be empty.');
179
+ Mage::helper('connector')->rayLog('100', $message);
180
+ }
181
+ }
182
+
183
+ public function createnewaddressbookAction()
184
+ {
185
+ $addressBookName = $this->getRequest()->getParam('name');
186
+ $website = $this->getRequest()->getParam('website', 0);
187
+ $client = Mage::helper('connector')->getWebsiteApiClient($website);
188
+ if (strlen($addressBookName)) {
189
+ $response = $client->postAddressBooks($addressBookName);
190
+ if(isset($response->message))
191
+ Mage::getSingleton('adminhtml/session')->addError($response->message);
192
+ else
193
+ Mage::getSingleton('adminhtml/session')->addSuccess('Address book : '. $addressBookName . ' created.');
194
+ }
195
+
196
+ }
197
+
198
+ public function reimoprtsubscribersAction()
199
+ {
200
+ $updated = Mage::getModel('email_connector/contact')->resetSubscribers();
201
+ if ($updated) {
202
+ Mage::getSingleton('adminhtml/session')->addSuccess('Subscribers updated : ' . $updated);
203
+ } else {
204
+ Mage::getSingleton('adminhtml/session')->addNotice('No subscribers imported!');
205
+ }
206
+ $this->_redirectReferer();
207
+ }
208
+
209
+ /**
210
+ * path constant for config helper sent as string.
211
+ */
212
+ public function enablewebsiteconfigurationAction()
213
+ {
214
+ $path = $this->getRequest()->getParam('path');
215
+ $website = $this->getRequest()->getParam('website', 0);
216
+ $value = $this->getRequest()->getParam('value');
217
+
218
+ $path = constant('Dotdigitalgroup_Email_Helper_Config::' . $path);
219
+ $scope = 'websites';
220
+ $scopeId = $website;
221
+
222
+ $config = Mage::getConfig();
223
+
224
+ if(isset($value))
225
+ $config->saveConfig($path, $value, $scope, $scopeId);
226
+ else
227
+ $config->saveConfig($path, 1, $scope, $scopeId);
228
+
229
+ $config->cleanCache();
230
+
231
+ $this->_redirectReferer();
232
+ }
233
+
234
+ /**
235
+ * Trigger to run the contact sync.
236
+ */
237
+ public function runcontactsyncAction()
238
+ {
239
+ $result = Mage::getModel('email_connector/cron')->contactSync();
240
+
241
+ if ($result['message'])
242
+ Mage::getSingleton('adminhtml/session')->addSuccess($result['message']);
243
+
244
+ $this->_redirectReferer();
245
+ }
246
+
247
+ /**
248
+ * Trigger to run the subscriber sync.
249
+ */
250
+ public function runsubscribersyncAction()
251
+ {
252
+ $result = Mage::getModel('email_connector/cron')->subscribersAndGuestSync();
253
+
254
+ if ($result['message'])
255
+ Mage::getSingleton('adminhtml/session')->addSuccess($result['message']);
256
+
257
+ $this->_redirectReferer();
258
+ }
259
+
260
+ /**
261
+ * Trigger to run the order sync.
262
+ */
263
+ public function runordersyncAction()
264
+ {
265
+
266
+ $result = Mage::getModel('email_connector/cron')->orderSync();
267
+ if ($result['message'])
268
+ Mage::getSingleton('adminhtml/session')->addSuccess($result['message']);
269
+
270
+ $this->_redirectReferer();
271
+ }
272
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/AutomationController.php ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Adminhtml_Email_AutomationController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+ /**
6
+ * Main page for automation studio. Must be authinticated.
7
+ */
8
+ public function indexAction()
9
+ {
10
+
11
+ $this->_title($this->__('Automation Studio'));
12
+ $this->loadLayout();
13
+ $this->_setActiveMenu('email_connector');
14
+
15
+ // authorize or create token.
16
+ $token = $this->generatetokenAction();
17
+ $loginuserUrl = Dotdigitalgroup_Email_Helper_Config::API_CONNECTOR_URL_LOG_USER . $token;
18
+
19
+ $block = $this->getLayout()
20
+ ->createBlock('core/text', 'connector_iframe')
21
+ ->setText(
22
+ "<iframe src=" . $loginuserUrl . " width=100% height=1400 frameborder='0' scrolling='no' style='margin:0;padding: 0;display:block;'></iframe>"
23
+ );
24
+
25
+ $this->_addContent($block);
26
+ $this->renderLayout();
27
+ }
28
+
29
+ protected function _isAllowed()
30
+ {
31
+ return Mage::getSingleton('admin/session')->isAllowed('email_connector/automation_studio');
32
+ }
33
+
34
+ /**
35
+ * Generate new token and connect from the admin.
36
+ *
37
+ * POST httpsː//my.dotmailer.com/OAuth2/Tokens.ashx HTTP/1.1
38
+ * Content-Type: application/x-www-form-urlencoded
39
+ * client_id=QVNY867m2DQozogTJfUmqA%253D%253D&
40
+ * redirect_uri=https%3a%2f%2flocalhost%3a10999%2fcallback.aspx
41
+ * &client_secret=SndpTndiSlhRawAAAAAAAA%253D%253D
42
+ * &grant_type=authorization_code
43
+ */
44
+ public function generatetokenAction()
45
+ {
46
+ //check for secure url
47
+ $adminUser = Mage::getSingleton('admin/session')->getUser();
48
+ $refreshToken = Mage::getSingleton('admin/user')->load($adminUser->getId())->getRefreshToken();
49
+
50
+ if ($refreshToken) {
51
+ $code = Mage::helper('connector')->getCode();
52
+ $params = 'client_id=' . Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CLIENT_ID) .
53
+ '&client_secret=' . Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CLIENT_SECRET_ID) .
54
+ '&refresh_token=' . $refreshToken .
55
+ '&grant_type=refresh_token';
56
+
57
+ $url = Dotdigitalgroup_Email_Helper_Config::API_CONNECTOR_URL_TOKEN;
58
+ Mage::helper('connector')->log('token url : ' . $url . ' code : ' . $code);
59
+
60
+ /**
61
+ * Refresh Token request.
62
+ */
63
+ $ch = curl_init();
64
+ curl_setopt($ch, CURLOPT_URL, $url);
65
+ curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
66
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
67
+ curl_setopt($ch, CURLOPT_TIMEOUT, 5);
68
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
69
+ curl_setopt($ch, CURLOPT_POST, count($params));
70
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
71
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
72
+
73
+ $response = json_decode(curl_exec($ch));
74
+
75
+ if (isset($response->error)) {
76
+ Mage::helper('connector')->log("Token Error Num`ber:" . curl_errno($ch) . "Error String:" . curl_error($ch));
77
+ }
78
+ curl_close($ch);
79
+
80
+ $token = $response->access_token;
81
+ return $token;
82
+
83
+ } else {
84
+ Mage::getSingleton('adminhtml/session')->addNotice('Please Connect To Access The Page.');
85
+ }
86
+
87
+ $this->_redirect('*/system_config/edit', array('section' => 'connector_api_credentials'));
88
+ }
89
+
90
+ /**
91
+ * Disconnect and remote the refresh token.
92
+ */
93
+ public function disconnectAction()
94
+ {
95
+ try {
96
+ $adminUser = Mage::getSingleton('admin/session')->getUser();
97
+
98
+ if ($adminUser->getRefreshToken()) {
99
+ $adminUser->setRefreshToken()->save();
100
+ }
101
+ Mage::getSingleton('adminhtml/session')->addSuccess('Successfully disconnected');
102
+ }catch (Exception $e){
103
+ Mage::logException($e);
104
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
105
+ }
106
+
107
+ $this->_redirectReferer('*/*/*');
108
+ }
109
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/CampaignController.php ADDED
@@ -0,0 +1,252 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Adminhtml_Email_CampaignController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+ /**
6
+ * constructor - set the used module name
7
+ */
8
+ protected function _construct()
9
+ {
10
+ $this->setUsedModuleName('Dotdigitalgroup_Email');
11
+ }
12
+
13
+ /**
14
+ * Email campaigns.
15
+ */
16
+ public function indexAction()
17
+ {
18
+ $this->_title($this->__('Email'))
19
+ ->_title($this->__('Manage Campaigns'));
20
+ $this->loadLayout();
21
+ $this->_setActiveMenu('email_connector');
22
+ $this->renderLayout();
23
+ }
24
+
25
+ /**
26
+ * New campaings.
27
+ */
28
+ public function newAction()
29
+ {
30
+ // We just forward the new action to a blank edit form
31
+ $this->_forward('edit');
32
+ }
33
+
34
+
35
+ /**
36
+ * Edit campign.
37
+ */
38
+ public function editAction()
39
+ {
40
+ $contactId = (int) $this->getRequest()->getParam('id');
41
+ $contact = $this->_initAction();
42
+ if ($contactId && !$contact->getId()) {
43
+ $this->_getSession()->addError(Mage::helper('connector')->__('This campaign no longer exists.'));
44
+ $this->_redirect('*/*/');
45
+ return;
46
+ }
47
+ if ($data = Mage::getSingleton('adminhtml/session')->getCampaignData(true)) {
48
+ $contact->setData($data);
49
+ }
50
+ Mage::dispatchEvent('email_campaign_controller_edit_action', array('contact' => $contact));
51
+ $this->loadLayout();
52
+ if ($contact->getId()) {
53
+ if (!Mage::app()->isSingleStoreMode() && ($switchBlock = $this->getLayout()->getBlock('store_switcher'))) {
54
+ $switchBlock->setDefaultStoreName(Mage::helper('connector')->__('Default Values'))
55
+ ->setSwitchUrl($this->getUrl('*/*/*', array('_current'=>true, 'active_tab'=>null, 'tab' => null, 'store'=>null)));
56
+ }
57
+ } else {
58
+ $this->getLayout()->getBlock('left')->unsetChild('store_switcher');
59
+ }
60
+ $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
61
+ $this->renderLayout();
62
+ }
63
+
64
+ /**
65
+ * Save campaign.
66
+ */
67
+ public function saveAction()
68
+ {
69
+ $storeId = $this->getRequest()->getParam('store');
70
+ $redirectBack = $this->getRequest()->getParam('back', false);
71
+ $contactId = $this->getRequest()->getParam('id');
72
+ $data = $this->getRequest()->getPost();
73
+ if ($data) {
74
+ $campaign = $this->_initAction();
75
+
76
+ $campaignData = $this->getRequest()->getPost('campaign', array());
77
+ $campaign->addData($campaignData);
78
+
79
+ try {
80
+ $campaign->save();
81
+ $this->_getSession()->addSuccess(Mage::helper('connector')->__('Campaign was saved.'));
82
+ }catch (Mage_Core_Exception $e) {
83
+ Mage::logException($e);
84
+ $this->_getSession()->addError($e->getMessage())
85
+ ->setContactData($campaignData);
86
+ $redirectBack = true;
87
+ }catch (Exception $e){
88
+ Mage::logException($e);
89
+ $this->_getSession()->addError(Mage::helper('connector')->__('Error saving campaign'))
90
+ ->setContactData($campaignData);
91
+ $redirectBack = true;
92
+ }
93
+ }
94
+ if ($redirectBack) {
95
+ $this->_redirect('*/*/edit', array(
96
+ 'id' => $contactId,
97
+ '_current'=>true
98
+ ));
99
+ } else {
100
+ $this->_redirect('*/*/', array('store'=>$storeId));
101
+ }
102
+ }
103
+
104
+ /**
105
+ * Delete campaign.
106
+ */
107
+ public function deleteAction()
108
+ {
109
+ if ($id = $this->getRequest()->getParam('id')) {
110
+ $campaign = Mage::getModel('email_connector/campaign')->load($id);
111
+ try {
112
+ $campaign->delete();
113
+ $this->_getSession()->addSuccess(Mage::helper('connector')->__('The campaign has been deleted.'));
114
+ }
115
+ catch (Exception $e) {
116
+ $this->_getSession()->addError($e->getMessage());
117
+ }
118
+ }
119
+ $this->getResponse()->setRedirect($this->getUrl('*/*/', array('store'=>$this->getRequest()->getParam('store'))));
120
+ }
121
+
122
+ /**
123
+ * Delete mass campaigns.
124
+ */
125
+ public function massDeleteAction()
126
+ {
127
+ $campaignIds = $this->getRequest()->getParam('campaign');
128
+ if (!is_array($campaignIds)) {
129
+ $this->_getSession()->addError($this->__('Please select campaigns.'));
130
+ } else {
131
+ try {
132
+ foreach ($campaignIds as $campaignId) {
133
+ $campaign = Mage::getSingleton('email_connector/campaign')->load($campaignId);
134
+ Mage::dispatchEvent('connector_controller_campaign_delete', array('campaign' => $campaign));
135
+ $campaign->delete();
136
+ }
137
+ $this->_getSession()->addSuccess(
138
+ Mage::helper('connector')->__('Total of %d record(s) have been deleted.', count($campaignIds))
139
+ );
140
+ } catch (Exception $e) {
141
+ $this->_getSession()->addError($e->getMessage());
142
+ }
143
+ }
144
+ $this->_redirect('*/*/index');
145
+ }
146
+
147
+ /**
148
+ * Mass mark for resend campaings.
149
+ */
150
+ public function massResendAction()
151
+ {
152
+ $campaignIds = $this->getRequest()->getParam('campaign');
153
+ if (!is_array($campaignIds)) {
154
+ $this->_getSession()->addError($this->__('Please select campaigns.'));
155
+ } else {
156
+ try {
157
+ foreach ($campaignIds as $campaignId) {
158
+ $campaign = Mage::getSingleton('email_connector/campaign')->load($campaignId);
159
+ Mage::dispatchEvent('connector_controller_campaign_delete', array('campaign' => $campaign));
160
+ $campaign->setIsSent(null)->save();
161
+ }
162
+ $this->_getSession()->addSuccess(
163
+ Mage::helper('connector')->__('Total of %d record(s) have resend .', count($campaignIds))
164
+ );
165
+ } catch (Exception $e) {
166
+ $this->_getSession()->addError($e->getMessage());
167
+ }
168
+ }
169
+ $this->_redirect('*/*/index');
170
+ }
171
+
172
+ /**
173
+ * Mass mark for recreate campaings.
174
+ */
175
+ public function massRecreateAction()
176
+ {
177
+ $campaignIds = $this->getRequest()->getParam('campaign');
178
+ $count = 0;
179
+ if (!is_array($campaignIds)) {
180
+ $this->_getSession()->addError($this->__('Please select campaigns.'));
181
+ } else {
182
+ try {
183
+ foreach ($campaignIds as $campaignId) {
184
+ $campaign = Mage::getSingleton('email_connector/campaign')->load($campaignId);
185
+ if($campaign->getSubject() && $campaign->getHtmlContent() && ($campaign->getIsSent() == NULL)){
186
+ $count++;
187
+ Mage::dispatchEvent('connector_controller_campaign_recreate', array('campaign' => $campaign));
188
+ $campaign->setIsCreated(null)->save();
189
+ }
190
+ elseif(($campaign->getIsSent() == NULL) && $campaign->getIsCopy() == 1){
191
+ $count++;
192
+ Mage::dispatchEvent('connector_controller_campaign_recreate', array('campaign' => $campaign));
193
+ $campaign->setIsCreated(null)->save();
194
+ }
195
+ }
196
+ $this->_getSession()->addSuccess(
197
+ Mage::helper('connector')->__('Total of %d record(s) have recreate.', $count)
198
+ );
199
+ } catch (Exception $e) {
200
+ $this->_getSession()->addError($e->getMessage());
201
+ }
202
+ }
203
+ $this->_redirect('*/*/index');
204
+ }
205
+
206
+
207
+ /**
208
+ * main page.
209
+ */
210
+ public function gridAction()
211
+ {
212
+ $this->loadLayout();
213
+ $this->renderLayout();
214
+ }
215
+
216
+ /**
217
+ * manage the campaigns.
218
+ *
219
+ * @return Dotdigitalgroup_Email_Model_Campaign
220
+ */
221
+ protected function _initAction()
222
+ {
223
+ $this->_title($this->__('Newsletter'))
224
+ ->_title($this->__('Manage Campaigns'));
225
+
226
+ $campaignId = (int) $this->getRequest()->getParam('id');
227
+ $campaign = Mage::getModel('email_connector/campaign');
228
+
229
+ if ($campaignId) {
230
+ $campaign->load($campaignId);
231
+ }
232
+ Mage::register('email_campaign', $campaign);
233
+ return $campaign;
234
+ }
235
+
236
+ /**
237
+ * Export campaigns to CSV file.
238
+ */
239
+ public function exportCsvAction()
240
+ {
241
+ $fileName = 'campaign.csv';
242
+ $content = $this->getLayout()->createBlock('email_connector/adminhtml_campaign_grid')
243
+ ->getCsvFile();
244
+ $this->_prepareDownloadResponse($fileName, $content);
245
+ }
246
+
247
+ protected function _isAllowed()
248
+ {
249
+ return Mage::getSingleton('admin/session')->isAllowed('newsletter/email_connetor/email_connector_campaign');
250
+ }
251
+
252
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/ContactController.php ADDED
@@ -0,0 +1,192 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Adminhtml_Email_ContactController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+ /**
6
+ * constructor - set the used module name
7
+ */
8
+ protected function _construct(){
9
+ $this->setUsedModuleName('Dotdigitalgroup_Email');
10
+ }
11
+
12
+ /**
13
+ * main page.
14
+ */
15
+ public function indexAction()
16
+ {
17
+ $this->_title($this->__('Email'))
18
+ ->_title($this->__('Manage Contacts'));
19
+ $this->loadLayout();
20
+ $this->_setActiveMenu('email_connector');
21
+ $this->renderLayout();
22
+ }
23
+
24
+ /**
25
+ * Edit contact.
26
+ */
27
+ public function editAction()
28
+ {
29
+ $contactId = (int) $this->getRequest()->getParam('id');
30
+ $contact = $this->_initAction();
31
+ if ($contactId && !$contact->getId()) {
32
+ $this->_getSession()->addError(Mage::helper('connector')->__('This contact no longer exists.'));
33
+ $this->_redirect('*/*/');
34
+ return;
35
+ }
36
+ $contactEmail = Mage::getModel('email_connector/apiconnector_contact')->syncContact();
37
+ if ($contactEmail)
38
+ Mage::getSingleton('adminhtml/session')->addSuccess('Successfully synced : ' . $contactEmail);
39
+
40
+ Mage::dispatchEvent('email_contact_controller_edit_action', array('contact' => $contact));
41
+
42
+ $this->_redirect('*/*');
43
+ }
44
+
45
+ /**
46
+ * Save contact.
47
+ */
48
+ public function saveAction(){
49
+ $storeId = $this->getRequest()->getParam('store');
50
+ $redirectBack = $this->getRequest()->getParam('back', false);
51
+ $contactId = $this->getRequest()->getParam('id');
52
+
53
+ $data = $this->getRequest()->getPost();
54
+ if ($data) {
55
+ $contact = $this->_initAction();
56
+
57
+ $contactData = $this->getRequest()->getPost('contact', array());
58
+ $contact->addData($contactData);
59
+
60
+ try {
61
+ $contact->save();
62
+ $contactId = $contact->getId();
63
+ $this->_getSession()->addSuccess(Mage::helper('connector')->__('Contact was saved.'));
64
+ }catch (Mage_Core_Exception $e) {
65
+ Mage::logException($e);
66
+ $this->_getSession()->addError($e->getMessage())
67
+ ->setContactData($contactData);
68
+ $redirectBack = true;
69
+ }catch (Exception $e){
70
+ Mage::logException($e);
71
+ $this->_getSession()->addError(Mage::helper('connector')->__('Error saving contact'))
72
+ ->setContactData($contactData);
73
+ $redirectBack = true;
74
+ }
75
+ }
76
+ if ($redirectBack) {
77
+ $this->_redirect('*/*/edit', array(
78
+ 'id' => $contactId,
79
+ '_current'=>true
80
+ ));
81
+ } else {
82
+ $this->_redirect('*/*/', array('store'=>$storeId));
83
+ }
84
+ }
85
+
86
+ /**
87
+ * Delete a contact.
88
+ */
89
+ public function deleteAction()
90
+ {
91
+ if ($id = $this->getRequest()->getParam('id')) {
92
+ $contact = Mage::getModel('email_connector/contact')->load($id);
93
+ try {
94
+ $contact->delete();
95
+ $this->_getSession()->addSuccess(Mage::helper('connector')->__('The contact has been deleted.'));
96
+ }
97
+ catch (Exception $e) {
98
+ $this->_getSession()->addError($e->getMessage());
99
+ }
100
+ }
101
+ $this->getResponse()->setRedirect($this->getUrl('*/*/', array('store'=>$this->getRequest()->getParam('store'))));
102
+ }
103
+
104
+ /**
105
+ * Mass delete contacts.
106
+ */
107
+ public function massDeleteAction()
108
+ {
109
+ $contactIds = $this->getRequest()->getParam('contact');
110
+ if (!is_array($contactIds)) {
111
+ $this->_getSession()->addError($this->__('Please select contacts.'));
112
+ }else {
113
+ try {
114
+ foreach ($contactIds as $contactId) {
115
+ $contact = Mage::getSingleton('email_connector/contact')->load($contactId);
116
+ Mage::dispatchEvent('connector_controller_affiliate_delete', array('contact' => $contact));
117
+ $contact->delete();
118
+ }
119
+ $this->_getSession()->addSuccess(
120
+ Mage::helper('connector')->__('Total of %d record(s) have been deleted.', count($contactIds))
121
+ );
122
+ } catch (Exception $e) {
123
+ $this->_getSession()->addError($e->getMessage());
124
+ }
125
+ }
126
+ $this->_redirect('*/*/index');
127
+ }
128
+
129
+ /**
130
+ * Mark a contact to be resend.
131
+ */
132
+ public function massResendAction()
133
+ {
134
+ $contactIds = $this->getRequest()->getParam('contact');
135
+
136
+ if (!is_array($contactIds)) {
137
+ $this->_getSession()->addError($this->__('Please select contacts.'));
138
+ }else {
139
+ try {
140
+ foreach ($contactIds as $contactId) {
141
+ $contact = Mage::getSingleton('email_connector/contact')->load($contactId);
142
+ $contact->setEmailImported(null)->save();
143
+ }
144
+ $this->_getSession()->addSuccess(
145
+ Mage::helper('connector')->__('Total of %d record(s) set for resend.', count($contactIds))
146
+ );
147
+ } catch (Exception $e) {
148
+ $this->_getSession()->addError($e->getMessage());
149
+ }
150
+ }
151
+ $this->_redirect('*/*/index');
152
+ }
153
+
154
+
155
+ /**
156
+ * main grid.
157
+ */
158
+ public function gridAction(){
159
+ $this->loadLayout();
160
+ $this->renderLayout();
161
+ }
162
+
163
+ protected function _initAction()
164
+ {
165
+ $this->_title($this->__('Newsletter'))
166
+ ->_title($this->__('Manage Contacts'));
167
+
168
+ $contactId = (int) $this->getRequest()->getParam('id');
169
+ $contact = Mage::getModel('email_connector/contact')
170
+ ->setStoreId($this->getRequest()->getParam('store', 0));
171
+
172
+ if ($contactId) {
173
+ $contact->load($contactId);
174
+ }
175
+ Mage::register('current_contact', $contact);
176
+ return $contact;
177
+ }
178
+
179
+ public function exportCsvAction()
180
+ {
181
+ $fileName = 'contacts.csv';
182
+ $content = $this->getLayout()->createBlock('email_connector/adminhtml_contact_grid')
183
+ ->getCsvFile();
184
+ $this->_prepareDownloadResponse($fileName, $content);
185
+ }
186
+
187
+ protected function _isAllowed()
188
+ {
189
+ return Mage::getSingleton('admin/session')->isAllowed('newsletter/email_connector/email_connector_contact');
190
+ }
191
+
192
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/DashboardController.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Adminhtml_Email_DashboardController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+ /**
6
+ * main page.
7
+ */
8
+ public function indexAction()
9
+ {
10
+ $this->_title($this->__('Dashboard'));
11
+
12
+ $this->loadLayout();
13
+ $this->_setActiveMenu('email_connector');
14
+ $this->_addContent($this->getLayout()->createBlock('adminhtml/widget_container'))
15
+ ->_addLeft($this->getLayout()->createBlock ('email_connector/adminhtml_dashboard_tabs'));
16
+ $this->renderLayout();
17
+ }
18
+
19
+ /**
20
+ * Load Status Grid as ajax requst.
21
+ */
22
+ public function statusGridAction() {
23
+
24
+ $block = $this->getLayout()->createBlock('email_connector/adminhtml_dashboard_tabs_status');
25
+ $this->getResponse()->setBody($block->toHtml());
26
+
27
+ }
28
+
29
+ /**
30
+ * Ajax tab for config data.
31
+ */
32
+ public function emailConfigAction() {
33
+ $block = $this->getLayout()->createBlock('email_connector/adminhtml_dashboard_tabs_config');
34
+
35
+ $this->getResponse()->setBody($block->toHtml());
36
+ }
37
+
38
+ protected function _isAllowed()
39
+ {
40
+ return Mage::getSingleton('admin/session')->isAllowed('newsletter/email_connector/email_connector_dashboard');
41
+ }
42
+
43
+
44
+ /**
45
+ * Ajax save the state of expandbles fieldsets.
46
+ */
47
+ public function stateAction()
48
+ {
49
+ $configState = array(
50
+ $this->getRequest()->getParam('container') => $this->getRequest()->getParam('value')
51
+ );
52
+ $this->_saveState($configState);
53
+ }
54
+
55
+ protected function _saveState($configState = array())
56
+ {
57
+ $adminUser = Mage::getSingleton('admin/session')->getUser();
58
+ if (is_array($configState)) {
59
+ $extra = $adminUser->getExtra();
60
+ if (!is_array($extra)) {
61
+ $extra = array();
62
+ }
63
+ if (!isset($extra['configState'])) {
64
+ $extra['configState'] = array();
65
+ }
66
+ foreach ($configState as $fieldset => $state) {
67
+ $extra['configState'][$fieldset] = $state;
68
+ }
69
+ $adminUser->saveExtra($extra);
70
+ }
71
+
72
+ return true;
73
+ }
74
+
75
+
76
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/OrderController.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Adminhtml_Email_OrderController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+ /**
6
+ * main page.
7
+ */
8
+ public function indexAction()
9
+ {
10
+ $this->loadLayout();
11
+ $this->_setActiveMenu('email_connector');
12
+ $this->_addContent($this->getLayout()->createBlock('email_connector/adminhtml_order'));
13
+ $this->getLayout()->getBlock('head')->setTitle('Connector Orders');
14
+ $this->renderLayout();
15
+ }
16
+
17
+ /**
18
+ * Check currently called action by permissions for current user
19
+ *
20
+ * @return bool
21
+ */
22
+ protected function _isAllowed()
23
+ {
24
+ return Mage::getSingleton('admin/session')->isAllowed('newsletter/email_connector/email_connector_order');
25
+ }
26
+ }
app/code/community/Dotdigitalgroup/Email/controllers/CreditmemoController.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once 'Dotdigitalgroup' . DS . 'Email' . DS . 'controllers' . DS . 'DynamicContentController.php';
3
+
4
+ class Dotdigitalgroup_Email_CreditmemoController extends Dotdigitalgroup_Email_DynamicContentController
5
+ {
6
+
7
+ /**
8
+ * New creditmemo.
9
+ */
10
+ public function newAction()
11
+ {
12
+ $this->loadLayout();
13
+ $newOrder = $this->getLayout()->createBlock('email_connector/order_creditmemo', 'connector_creditmemo_new', array(
14
+ 'template' => 'connector/creditmemo/new.phtml'
15
+ ));
16
+ $this->getLayout()->getBlock('content')->append($newOrder);
17
+ $items = $this->getLayout()->createBlock('email_connector/order_creditmemo', 'connector_creditmemo_items', array(
18
+ 'template' => 'connector/creditmemo/items.phtml'
19
+ ));
20
+ $this->getLayout()->getBlock('connector_creditmemo_new')->append($items);
21
+ $this->renderLayout();
22
+ }
23
+
24
+ /**
25
+ * New guest action.
26
+ */
27
+ public function newguestAction()
28
+ {
29
+ $this->loadLayout();
30
+ $invoice = $this->getLayout()->createBlock('email_connector/order_invoice', 'connector_creditmemo_guest', array(
31
+ 'template' => 'connector/creditmemo/newguest.phtml'
32
+ ));
33
+ $this->getLayout()->getBlock('content')->append($invoice);
34
+ $items = $this->getLayout()->createBlock('email_connector/order_creditmemo', 'connector_creditmemo_items', array(
35
+ 'template' => 'connector/creditmemo/items.phtml'
36
+ ));
37
+ $this->getLayout()->getBlock('connector_creditmemo_guest')->append($items);
38
+
39
+ $this->renderLayout();
40
+
41
+ }
42
+
43
+ /**
44
+ * update creditmemo.
45
+ */
46
+ public function updateAction()
47
+ {
48
+ $this->loadLayout();
49
+ $newOrder = $this->getLayout()->createBlock('email_connector/order_creditmemo', 'connector_creditmemo_update', array(
50
+ 'template' => 'connector/creditmemo/update.phtml'
51
+ ));
52
+ $this->getLayout()->getBlock('content')->append($newOrder);
53
+
54
+ $this->renderLayout();
55
+ }
56
+
57
+ /**
58
+ * update guest.
59
+ */
60
+ public function updateguestAction()
61
+ {
62
+ $this->loadLayout();
63
+ $newOrder = $this->getLayout()->createBlock('email_connector/order_creditmemo', 'connector_creditmemo_update_guest', array(
64
+ 'template' => 'connector/creditmemo/updateguest.phtml'
65
+ ));
66
+ $this->getLayout()->getBlock('content')->append($newOrder);
67
+ $this->renderLayout();
68
+ }
69
+ }
app/code/community/Dotdigitalgroup/Email/controllers/DynamicContentController.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_DynamicContentController extends Mage_Core_Controller_Front_Action
4
+ {
5
+ /**
6
+ * @return Mage_Core_Controller_Front_Action|void
7
+ */
8
+ public function preDispatch()
9
+ {
10
+ //authenticate
11
+ Mage::helper('connector')->auth($this->getRequest()->getParam('code'));
12
+ $orderId = $this->getRequest()->getParam('order_id', false);
13
+ //check for order_id param
14
+ if ($orderId) {
15
+ $order = Mage::getModel('sales/order')->load($orderId);
16
+ //check if the order still exists
17
+ if ($order->getId()) {
18
+ $storeId = $order->getStoreId();
19
+ //start the emulation for order store
20
+ $appEmulation = Mage::getSingleton('core/app_emulation');
21
+ $appEmulation->startEnvironmentEmulation($storeId);
22
+ } else {
23
+ Mage::helper('connector')->log('TE invoice : order not found: ' . $orderId);
24
+ exit;
25
+ }
26
+ } else {
27
+ Mage::helper('connector')->log('TE invoice : order_id missing :' . $orderId);
28
+ exit;
29
+ }
30
+ parent::preDispatch();
31
+ }
32
+ }
app/code/community/Dotdigitalgroup/Email/controllers/EmailController.php ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_EmailController extends Mage_Core_Controller_Front_Action
4
+ {
5
+ /**
6
+ * Generate coupon for a coupon code id.
7
+ */
8
+ public function couponAction()
9
+ {
10
+ //authinticate
11
+ Mage::helper('connector')->auth($this->getRequest()->getParam('code'));
12
+
13
+ $this->loadLayout();
14
+ //page root template
15
+ if ($root = $this->getLayout()->getBlock('root')) {
16
+ $root->setTemplate('page/blank.phtml');
17
+ }
18
+ //content template
19
+ $coupon = $this->getLayout()->createBlock('email_connector/coupon', 'connector_coupon', array(
20
+ 'template' => 'connector/coupon.phtml'
21
+ ));
22
+ $this->getLayout()->getBlock('content')->append($coupon);
23
+ $this->renderLayout();
24
+ }
25
+
26
+ /**
27
+ * Basket page to display the user items with specific email.
28
+ */
29
+ public function basketAction()
30
+ {
31
+ //authinticate
32
+ Mage::helper('connector')->auth($this->getRequest()->getParam('code'));
33
+ $this->loadLayout();
34
+ if ($root = $this->getLayout()->getBlock('root')) {
35
+ $root->setTemplate('page/blank.phtml');
36
+ }
37
+ $basket = $this->getLayout()->createBlock('email_connector/basket', 'connector_basket', array(
38
+ 'template' => 'connector/basket.phtml'
39
+ ));
40
+ $this->getLayout()->getBlock('content')->append($basket);
41
+ $this->renderLayout();
42
+ }
43
+
44
+ /**
45
+ * Access Log files.
46
+ */
47
+ public function logAction()
48
+ {
49
+ //file name param
50
+ $fileName = $filePath = '';
51
+ $file = $this->getRequest()->getParam('file', false);
52
+ if ($file) {
53
+ $fileName = $file . '.log';
54
+ $filePath = Mage::getBaseDir( 'log' ) . DIRECTORY_SEPARATOR . $fileName;
55
+ } elseif ($csv = $this->getRequest()->getParam('archive', false)){
56
+ $fileName = $csv . '.csv';
57
+ $filePath = Mage::getBaseDir('export') . DIRECTORY_SEPARATOR . 'email' . DIRECTORY_SEPARATOR . 'archive' . DIRECTORY_SEPARATOR . $fileName;
58
+ }
59
+
60
+ $this->_prepareDownloadResponse($fileName, array(
61
+ 'type' => 'filename',
62
+ 'value' => $filePath
63
+ ));
64
+ exit();
65
+ }
66
+
67
+ public function showAction() {
68
+ $list = array();
69
+
70
+ if ($handle = opendir(Mage::getBaseDir('export') . DIRECTORY_SEPARATOR . 'email' . DIRECTORY_SEPARATOR . 'archive')) {
71
+
72
+
73
+ while (false !== ($entry = readdir($handle))) {
74
+
75
+ if ($entry != "." && $entry != "..") {
76
+
77
+ $list[] = $entry;
78
+ }
79
+ }
80
+
81
+ closedir($handle);
82
+ }
83
+
84
+ foreach ( $list as $one ) {
85
+
86
+ echo $one . '</br>';
87
+ }
88
+ return;
89
+ }
90
+
91
+ /**
92
+ * Callback action for the automation studio.
93
+ */
94
+ public function callbackAction()
95
+ {
96
+ $code = $this->getRequest()->getParam('code', false);
97
+ $userId = $this->getRequest()->getParam('state');
98
+ $adminUser = Mage::getModel('admin/user')->load($userId);
99
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB, true);
100
+
101
+ //callback url
102
+ $callback = $baseUrl . 'connector/email/callback';
103
+
104
+ if ($code) {
105
+ $data = 'client_id=' . Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CLIENT_ID) .
106
+ '&client_secret=' . Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CLIENT_SECRET_ID) .
107
+ '&redirect_uri=' . $callback .
108
+ '&grant_type=authorization_code' .
109
+ '&code=' . $code;
110
+
111
+
112
+ $url = Dotdigitalgroup_Email_Helper_Config::API_CONNECTOR_URL_TOKEN;
113
+ $ch = curl_init();
114
+ curl_setopt($ch, CURLOPT_URL, $url);
115
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
116
+ curl_setopt($ch, CURLOPT_TIMEOUT, 10);
117
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
118
+ curl_setopt($ch, CURLOPT_POST, count($data));
119
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
120
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array ('Content-Type: application/x-www-form-urlencoded'));
121
+
122
+
123
+ $response = json_decode(curl_exec($ch));
124
+ if ($response === false) {
125
+ Mage::helper('connector')->rayLog('100', 'Automaion studio number not found : ' . serialize($response));
126
+ Mage::helper('connector')->log("Error Number: " . curl_errno($ch));
127
+ }
128
+
129
+ //save the refresh token to the admin user
130
+ $adminUser->setRefreshToken($response->refresh_token)->save();
131
+ }
132
+ //redirect to automation index page
133
+ $this->_redirectReferer(Mage::helper('adminhtml')->getUrl('adminhtml/email_automation/index'));
134
+ }
135
+ }
app/code/community/Dotdigitalgroup/Email/controllers/InvoiceController.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once 'Dotdigitalgroup' . DS . 'Email' . DS . 'controllers' . DS . 'DynamicContentController.php';
3
+
4
+ class Dotdigitalgroup_Email_InvoiceController extends Dotdigitalgroup_Email_DynamicContentController
5
+ {
6
+ /**
7
+ * New invoice for order.
8
+ */
9
+ public function newAction()
10
+ {
11
+ $this->loadLayout();
12
+ //set content template
13
+ $invoiceNew = $this->getLayout()->createBlock('email_connector/order_invoice', 'connector_invoice_new', array(
14
+ 'template' => 'connector/invoice/new.phtml'
15
+ ));
16
+ $this->getLayout()->getBlock('content')->append($invoiceNew);
17
+ //invoice items
18
+ $items = $this->getLayout()->createBlock('email_connector/order_invoice', 'connector_order_items', array(
19
+ 'template' => 'connector/order/items.phtml'
20
+ ));
21
+ $this->getLayout()->getBlock('connector_invoice_new')->append($items);
22
+ $this->renderLayout();
23
+ }
24
+
25
+ /**
26
+ * New guest invoice.
27
+ */
28
+ public function newguestAction()
29
+ {
30
+ $this->loadLayout();
31
+ $invoiceGuest = $this->getLayout()->createBlock('email_connector/order_invoice', 'connector_invoiceguest_new', array(
32
+ 'template' => 'connector/invoice/newguest.phtml'
33
+ ));
34
+
35
+ $this->getLayout()->getBlock('content')->append($invoiceGuest);
36
+ $items = $this->getLayout()->createBlock('email_connector/order_invoice', 'connector_order_items', array(
37
+ 'template' => 'connector/order/items.phtml'
38
+ ));
39
+ //set invoice items
40
+ $this->getLayout()->getBlock('connector_invoiceguest_new')->append($items);
41
+ $this->renderLayout();
42
+ }
43
+
44
+ /**
45
+ * Invoice update information.
46
+ */
47
+ public function updateAction()
48
+ {
49
+ $this->loadLayout();
50
+ $invoice = $this->getLayout()->createBlock('email_connector/order_invoice', 'connector_invoice_update', array(
51
+ 'template' => 'connector/invoice/update.phtml'
52
+ ));
53
+ //set invoice content
54
+ $this->getLayout()->getBlock('content')->append($invoice);
55
+ $this->renderLayout();
56
+ }
57
+
58
+ /**
59
+ * Invoice guest.
60
+ */
61
+ public function updateguestAction()
62
+ {
63
+ $this->loadLayout();
64
+ $invoice = $this->getLayout()->createBlock('email_connector/order_invoice', 'connector_invoice_updateguest', array(
65
+ 'template' => 'connector/invoice/updateguest.phtml'
66
+ ));
67
+ //set invoice content
68
+ $this->getLayout()->getBlock('content')->append($invoice);
69
+ $this->renderLayout();
70
+ }
71
+ }
app/code/community/Dotdigitalgroup/Email/controllers/OrderController.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once 'Dotdigitalgroup' . DS . 'Email' . DS . 'controllers' . DS . 'DynamicContentController.php';
3
+
4
+ class Dotdigitalgroup_Email_OrderController extends Dotdigitalgroup_Email_DynamicContentController
5
+ {
6
+ /**
7
+ * Display new order content.
8
+ */
9
+ public function newAction()
10
+ {
11
+ $this->loadLayout();
12
+ //set content template
13
+ $newOrder = $this->getLayout()->createBlock('email_connector/order', 'connector_order', array(
14
+ 'template' => 'connector/order/new.phtml'
15
+ ));
16
+ $this->getLayout()->getBlock('content')->append($newOrder);
17
+ //set the items for this order
18
+ $items = $this->getLayout()->createBlock('email_connector/order', 'connector_order_items', array(
19
+ 'template' => 'connector/order/items.phtml'
20
+ ));
21
+ $this->getLayout()->getBlock('connector_order')->append($items);
22
+ $this->renderLayout();
23
+ }
24
+
25
+ /**
26
+ * New order for guest.
27
+ */
28
+ public function newguestAction()
29
+ {
30
+ $this->loadLayout();
31
+ //set content template
32
+ $newGuestOrder = $this->getLayout()->createBlock('email_connector/order', 'connector_order_guest', array(
33
+ 'template' => 'connector/order/newguest.phtml'
34
+ ));
35
+ $this->getLayout()->getBlock('content')->append($newGuestOrder);
36
+ //set the items for this order
37
+ $items = $this->getLayout()->createBlock('email_connector/order', 'connector_order_items', array(
38
+ 'template' => 'connector/order/items.phtml'
39
+ ));
40
+ $this->getLayout()->getBlock('connector_order_guest')->append($items);
41
+ $this->renderLayout();
42
+ }
43
+
44
+ /**
45
+ * Show order update information.
46
+ */
47
+ public function updateAction()
48
+ {
49
+ $this->loadLayout();
50
+ //set content template
51
+ $newOrder = $this->getLayout()->createBlock('email_connector/order', 'connector_order_update', array(
52
+ 'template' => 'connector/order/update.phtml'
53
+ ));
54
+ $this->getLayout()->getBlock('content')->append($newOrder);
55
+ $this->renderLayout();
56
+ }
57
+
58
+ /**
59
+ * Show order update for guest.
60
+ */
61
+ public function updateguestAction()
62
+ {
63
+ $this->loadLayout();
64
+ //set the content template
65
+ $newOrder = $this->getLayout()->createBlock('email_connector/order', 'connector_order_update_guest', array(
66
+ 'template' => 'connector/order/updateguest.phtml'
67
+ ));
68
+ $this->getLayout()->getBlock('content')->append($newOrder);
69
+ $this->renderLayout();
70
+ }
71
+ }
app/code/community/Dotdigitalgroup/Email/controllers/ProductsController.php ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_ProductsController extends Mage_Core_Controller_Front_Action
4
+ {
5
+ /**
6
+ * @return Mage_Core_Controller_Front_Action|void
7
+ */
8
+ public function preDispatch()
9
+ {
10
+ Mage::helper('connector')->auth($this->getRequest()->getParam('code'));
11
+ if ($this->getRequest()->getActionName() != 'push') {
12
+ $orderId = $this->getRequest()->getParam('order_id', false);
13
+ //check for order id param
14
+ if ($orderId) {
15
+ //check if order still exists
16
+ $order = Mage::getModel('sales/order')->load($orderId);
17
+ if ($order->getId()) {
18
+ //start app emulation
19
+ $storeId = $order->getStoreId();
20
+ $appEmulation = Mage::getSingleton('core/app_emulation');
21
+ $appEmulation->startEnvironmentEmulation($storeId);
22
+ } else {
23
+ $message = 'Dynamic : order not found: ' . $orderId;
24
+ Mage::helper('connector')->log($message);
25
+ Mage::helper('connector')->rayLog('100', $message);
26
+ }
27
+ } else {
28
+ Mage::helper('connector')->log('Dynamic : order_id missing :' . $orderId);
29
+ }
30
+ }
31
+
32
+ parent::preDispatch();
33
+ }
34
+
35
+ /**
36
+ * Related products.
37
+ */
38
+ public function relatedAction()
39
+ {
40
+ $this->loadLayout();
41
+ $products = $this->getLayout()->createBlock('email_connector/recommended_products', 'connector_recommended_related', array(
42
+ 'template' => 'connector/product/list.phtml'
43
+ ));
44
+ //append related products
45
+ $this->getLayout()->getBlock('content')->append($products);
46
+
47
+ $this->renderLayout();
48
+
49
+ }
50
+
51
+ /**
52
+ * Crosssell products.
53
+ */
54
+ public function crosssellAction()
55
+ {
56
+ $this->loadLayout();
57
+ $products = $this->getLayout()->createBlock('email_connector/recommended_products', 'connector_recommended_crosssell', array(
58
+ 'template' => 'connector/product/list.phtml'
59
+ ));
60
+ //append crosssell products.
61
+ $this->getLayout()->getBlock('content')->append($products);
62
+
63
+ $this->renderLayout();
64
+ }
65
+
66
+ /**
67
+ * Upsell products.
68
+ */
69
+ public function upsellAction()
70
+ {
71
+ $this->loadLayout();
72
+ $products = $this->getLayout()->createBlock('email_connector/recommended_products', 'connector_recommended_upsell', array(
73
+ 'template' => 'connector/product/list.phtml'
74
+ ));
75
+ //append upsell products
76
+ $this->getLayout()->getBlock('content')->append($products);
77
+
78
+ $this->renderLayout();
79
+ }
80
+
81
+ /**
82
+ * Products that are set to manually push as related.
83
+ */
84
+ public function pushAction()
85
+ {
86
+ $this->loadLayout();
87
+ $products = $this->getLayout()->createBlock('email_connector/recommended_push', 'connector_product_push', array(
88
+ 'template' => 'connector/product/list.phtml'
89
+ ));
90
+ //append push products
91
+ $this->getLayout()->getBlock('content')->append($products);
92
+ $this->renderLayout();
93
+ }
94
+ }
app/code/community/Dotdigitalgroup/Email/controllers/ReportController.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_ReportController extends Mage_Core_Controller_Front_Action
4
+ {
5
+ /**
6
+ * @return Mage_Core_Controller_Front_Action|void
7
+ */
8
+ public function preDispatch()
9
+ {
10
+ //authenticate
11
+ Mage::helper('connector')->auth($this->getRequest()->getParam('code'));
12
+ parent::preDispatch();
13
+ }
14
+
15
+ /**
16
+ * Bestsellers report.
17
+ */
18
+ public function bestsellersAction()
19
+ {
20
+ $this->loadLayout();
21
+ //set the content template
22
+ $products = $this->getLayout()->createBlock('email_connector/recommended_bestsellers', 'connector_customer', array(
23
+ 'template' => 'connector/product/list.phtml'
24
+ ));
25
+ $this->getLayout()->getBlock('content')->append($products);
26
+ $this->renderLayout();
27
+ }
28
+
29
+ /**
30
+ * Most viewed report.
31
+ */
32
+ public function mostviewedAction()
33
+ {
34
+ $this->loadLayout();
35
+ //set the content template
36
+ $products = $this->getLayout()->createBlock('email_connector/recommended_mostviewed', 'connector_customer', array(
37
+ 'template' => 'connector/product/list.phtml'
38
+ ));
39
+ $this->getLayout()->getBlock('content')->append($products);
40
+ $this->renderLayout();
41
+ }
42
+
43
+ /**
44
+ * Recently viewed products for customer.
45
+ */
46
+ public function recentlyviewedAction()
47
+ {
48
+ //customer id param
49
+ $customerId = $this->getRequest()->getParam('customer_id');
50
+ //no customer was found
51
+ if (! $customerId) {
52
+ Mage::helper('connector')->log('Recentlyviewed : no customer id : ' . $customerId);
53
+ exit();
54
+ }
55
+ $this->loadLayout();
56
+ //set content tempalate
57
+ $products = $this->getLayout()->createBlock('email_connector/recommended_recentlyviewed', 'connector_customer', array(
58
+ 'template' => 'connector/product/list.phtml'
59
+ ));
60
+ $this->getLayout()->getBlock('content')->append($products);
61
+ $this->renderLayout();
62
+ }
63
+ }
app/code/community/Dotdigitalgroup/Email/controllers/ShippingController.php ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once 'Dotdigitalgroup' . DS . 'Email' . DS . 'controllers' . DS . 'DynamicContentController.php';
3
+
4
+ class Dotdigitalgroup_Email_ShippingController extends Dotdigitalgroup_Email_DynamicContentController
5
+ {
6
+ /**
7
+ * New shipping for this order.
8
+ */
9
+ public function newAction()
10
+ {
11
+ $this->loadLayout();
12
+ //set content template
13
+ $newOrder = $this->getLayout()->createBlock('email_connector/order_shipping', 'connector_shipping_new', array(
14
+ 'template' => 'connector/shipping/new.phtml'
15
+ ));
16
+ $this->getLayout()->getBlock('content')->append($newOrder);
17
+ //set content items
18
+ $items = $this->getLayout()->createBlock('email_connector/order', 'connector_shipping_items', array(
19
+ 'template' => 'connector/order/items.phtml'
20
+ ));
21
+ $this->getLayout()->getBlock('connector_shipping_new')->append($items);
22
+ //rewrite the items to dislpay the shipped ones
23
+ $items = $this->getLayout()->createBlock('email_connector/order_shipping', 'connector_shipping_track', array(
24
+ 'template' => 'email/order/shipment/track.phtml'
25
+ ));
26
+ $this->getLayout()->getBlock('connector_shipping_new')->append($items);
27
+ $this->renderLayout();
28
+ }
29
+
30
+ /**
31
+ * New shipping for guest.
32
+ */
33
+ public function newguestAction()
34
+ {
35
+ $this->loadLayout();
36
+ //set content template
37
+ $newOrder = $this->getLayout()->createBlock('email_connector/order_shipping', 'connector_shipping_newguest', array(
38
+ 'template' => 'connector/shipping/newguest.phtml'
39
+ ));
40
+ $this->getLayout()->getBlock('content')->append($newOrder);
41
+ //set content items
42
+ $items = $this->getLayout()->createBlock('email_connector/order', 'connector_shipping_items', array(
43
+ 'template' => 'connector/order/items.phtml'
44
+ ));
45
+ //new guest shipping items
46
+ $this->getLayout()->getBlock('connector_shipping_newguest')->append($items);
47
+ //rewrite the items to dislpay the shipped ones
48
+ $items = $this->getLayout()->createBlock('email_connector/order_shipping', 'connector_shipping_track', array(
49
+ 'template' => 'email/order/shipment/track.phtml'
50
+ ));
51
+ //items that was shipped
52
+ $this->getLayout()->getBlock('connector_shipping_newguest')->append($items);
53
+ $this->renderLayout();
54
+ }
55
+
56
+ /**
57
+ * Shipping update for this order.
58
+ */
59
+ public function updateAction()
60
+ {
61
+ $this->loadLayout();
62
+ //set the content template
63
+ $shippingUpdate = $this->getLayout()->createBlock('email_connector/order_shipping', 'connector_shipping_update', array(
64
+ 'template' => 'connector/shipping/update.phtml'
65
+ ));
66
+ //shipping update content
67
+ $this->getLayout()->getBlock('content')->append($shippingUpdate);
68
+ $this->renderLayout();
69
+ }
70
+
71
+ /**
72
+ * Shipping update for guests.
73
+ */
74
+ public function updateguestAction()
75
+ {
76
+ $this->loadLayout();
77
+ $shippingGuest = $this->getLayout()->createBlock('email_connector/order_shipping', 'connector_shipping_updateguest', array(
78
+ 'template' => 'connector/shipping/updateguest.phtml'
79
+ ));
80
+ //set shipping content
81
+ $this->getLayout()->getBlock('content')->append($shippingGuest);
82
+ $this->renderLayout();
83
+ }
84
+ }
app/code/community/Dotdigitalgroup/Email/etc/adminhtml.xml ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <menu>
4
+ <email_connector translate="title">
5
+ <title>Marketing Automation</title>
6
+ <sort_order>70</sort_order>
7
+ <children>
8
+ <email_connector_dashboard translate="title">
9
+ <title>Dashboard</title>
10
+ <sort_order>10</sort_order>
11
+ <action>adminhtml/email_dashboard</action>
12
+ </email_connector_dashboard>
13
+ <automation_studio translate="title">
14
+ <title>Automation Studio</title>
15
+ <sort_order>20</sort_order>
16
+ <action>adminhtml/email_automation</action>
17
+ </automation_studio>
18
+ <reports translate="title">
19
+ <title>Reports</title>
20
+ <sort_order>30</sort_order>
21
+ <children>
22
+ <email_connector_order translate="title">
23
+ <title>Orders Sync</title>
24
+ <sort_order>20</sort_order>
25
+ <action>adminhtml/email_order</action>
26
+ </email_connector_order>
27
+ <email_connector_campaign translate="title">
28
+ <title>Email Send Status</title>
29
+ <sort_order>30</sort_order>
30
+ <action>adminhtml/email_campaign</action>
31
+ </email_connector_campaign>
32
+ <email_connector_contact translate="title">
33
+ <title>Contact Sync</title>
34
+ <sort_order>10</sort_order>
35
+ <action>adminhtml/email_contact</action>
36
+ </email_connector_contact>
37
+ </children>
38
+ </reports>
39
+ <email_configuration translate="title">
40
+ <title>Configuration</title>
41
+ <sort_order>40</sort_order>
42
+ <children>
43
+ <api_credentials translate="title">
44
+ <title>Api Credentials</title>
45
+ <sort_order>20</sort_order>
46
+ <action>adminhtml/system_config/edit/section/connector_api_credentials</action>
47
+ </api_credentials>
48
+ <data_mapping translate="title">
49
+ <title>Data Mapping</title>
50
+ <sort_order>30</sort_order>
51
+ <action>adminhtml/system_config/edit/section/connector_data_mapping</action>
52
+ </data_mapping>
53
+ <sync_settings translate="title">
54
+ <title>Sync Settings</title>
55
+ <sort_order>40</sort_order>
56
+ <action>adminhtml/system_config/edit/section/connector_sync_settings</action>
57
+ </sync_settings>
58
+ </children>
59
+ </email_configuration>
60
+ </children>
61
+ </email_connector>
62
+ </menu>
63
+ <acl>
64
+ <resources>
65
+ <admin>
66
+ <children>
67
+ <email_connector>
68
+ <title>Email Connector</title>
69
+ <children>
70
+ <email_connector_dashboard translate="title">
71
+ <title>Dashboard</title>
72
+ </email_connector_dashboard>
73
+ <automation_studio translate="title">
74
+ <title>Automation Studio</title>
75
+ </automation_studio>
76
+ <reports>
77
+ <title>Reports</title>
78
+ <children>
79
+ <email_connector_order translate="title">
80
+ <title>Email Connector Orders</title>
81
+ </email_connector_order>
82
+ <email_connector_campaign translate="title">
83
+ <title>Email Connector Campaigns</title>
84
+ </email_connector_campaign>
85
+ <email_connector_contact translate="title">
86
+ <title>Email Connector Contacts</title>
87
+ </email_connector_contact>
88
+ </children>
89
+ </reports>
90
+ <email_configuration translate="title">
91
+ <title>Email Configuration</title>
92
+ <children>
93
+ <api_credentials translate="title">
94
+ <title>Api Credentials</title>
95
+ </api_credentials>
96
+ <data_mapping translate="title">
97
+ <title>Data Mapping</title>
98
+ </data_mapping>
99
+ <sync_settings translate="title">
100
+ <title>Sync Settings</title>
101
+ </sync_settings>
102
+ </children>
103
+ </email_configuration>
104
+ </children>
105
+ </email_connector>
106
+ <system>
107
+ <children>
108
+ <config>
109
+ <children>
110
+ <connector_api_credentials translate="title">
111
+ <title><![CDATA[Email API Credentials]]></title>
112
+ </connector_api_credentials>
113
+ <connector_sync_settings translate="title">
114
+ <title><![CDATA[Email Sync Settings]]></title>
115
+ </connector_sync_settings>
116
+ <connector_data_mapping translate="title">
117
+ <title><![CDATA[Email Data Field Mapping]]></title>
118
+ </connector_data_mapping>
119
+ <connector_roi_tracking translate="title">
120
+ <title><![CDATA[Email ROI & Tracking]]></title>
121
+ </connector_roi_tracking>
122
+ <connector_lost_baskets translate="title">
123
+ <title><![CDATA[Abandoned Carts]]></title>
124
+ </connector_lost_baskets>
125
+ <connector_sms translate="title">
126
+ <title><![CDATA[Email SMS Section]]></title>
127
+ </connector_sms>
128
+ <connector_dynamic_content translate="title">
129
+ <title><![CDATA[Email Dynamic Content]]></title>
130
+ </connector_dynamic_content>
131
+ <connector_transactional_emails translate="title">
132
+ <title><![CDATA[Email Transactional Email]]></title>
133
+ </connector_transactional_emails>
134
+ <connector_automation_studio translate="title">
135
+ <title><![CDATA[Automation Studio]]></title>
136
+ </connector_automation_studio>
137
+ <connector_advanced_settings translate="title">
138
+ <title><![CDATA[Email Advanced Settings]]></title>
139
+ </connector_advanced_settings>
140
+ </children>
141
+ </config>
142
+ </children>
143
+ </system>
144
+ </children>
145
+ </admin>
146
+ </resources>
147
+ </acl>
148
+ </config>
app/code/community/Dotdigitalgroup/Email/etc/config.xml ADDED
@@ -0,0 +1,546 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Dotdigitalgroup_Email>
5
+ <version>3.2.3</version>
6
+ </Dotdigitalgroup_Email>
7
+ </modules>
8
+ <frontend>
9
+ <routers>
10
+ <connector>
11
+ <use>standard</use>
12
+ <args>
13
+ <module>Dotdigitalgroup_Email</module>
14
+ <frontName>connector</frontName>
15
+ </args>
16
+ </connector>
17
+ </routers>
18
+ <layout>
19
+ <updates>
20
+ <connector>
21
+ <file>connector.xml</file>
22
+ </connector>
23
+ </updates>
24
+ </layout>
25
+ <events>
26
+             <controller_action_postdispatch>
27
+                 <observers>
28
+                     <connector_switcher>
29
+                         <class>Dotdigitalgroup_Email_Model_Controller_Observer</class>
30
+                         <method>controllerActionPostdispatch</method>
31
+                     </connector_switcher>
32
+                 </observers>
33
+             </controller_action_postdispatch>
34
+         </events>
35
+ </frontend>
36
+ <global>
37
+ <resources>
38
+ <email_connector_setup>
39
+ <setup>
40
+ <module>Dotdigitalgroup_Email</module>
41
+ <class>Dotdigitalgroup_Email_Model_Resource_Setup</class>
42
+ </setup>
43
+ </email_connector_setup>
44
+ </resources>
45
+ <models>
46
+ <email_connector>
47
+ <class>Dotdigitalgroup_Email_Model</class>
48
+ <resourceModel>email_connector_resource</resourceModel>
49
+ </email_connector>
50
+ <email_connector_resource>
51
+ <class>Dotdigitalgroup_Email_Model_Resource</class>
52
+ <entities>
53
+ <order>
54
+ <table>email_order</table>
55
+ </order>
56
+ <contact>
57
+ <table>email_contact</table>
58
+ </contact>
59
+ <campaign>
60
+ <table>email_campaign</table>
61
+ </campaign>
62
+ <create>
63
+ <table>email_create</table>
64
+ </create>
65
+ <config>
66
+ <table>email_config</table>
67
+ </config>
68
+ </entities>
69
+ </email_connector_resource>
70
+ <core>
71
+ <rewrite>
72
+ <email_template>Dotdigitalgroup_Email_Model_Email_Template</email_template>
73
+ </rewrite>
74
+ </core>
75
+ </models>
76
+ <helpers>
77
+ <connector>
78
+ <class>Dotdigitalgroup_Email_Helper</class>
79
+ </connector>
80
+ </helpers>
81
+ <blocks>
82
+ <email_connector>
83
+ <class>Dotdigitalgroup_Email_Block</class>
84
+ </email_connector>
85
+ </blocks>
86
+ <events>
87
+
88
+ <admin_system_config_changed_section_connector_api_credentials>
89
+ <observers>
90
+ <connector_api_save>
91
+ <class>Dotdigitalgroup_Email_Model_Adminhtml_Observer</class>
92
+ <method>actionConfigSaveApi</method>
93
+ </connector_api_save>
94
+ </observers>
95
+ </admin_system_config_changed_section_connector_api_credentials>
96
+ <admin_system_config_changed_section_connector_transactional_emails>
97
+ <observers>
98
+ <connector_transactional_api>
99
+ <class>Dotdigitalgroup_Email_Model_Adminhtml_Observer</class>
100
+ <method>saveConfigForTransactional</method>
101
+ </connector_transactional_api>
102
+ </observers>
103
+ </admin_system_config_changed_section_connector_transactional_emails>
104
+ <admin_system_config_changed_section_connector_data_mapping>
105
+ <observers>
106
+ <connector_data_mapping_reset>
107
+ <class>Dotdigitalgroup_Email_Model_Adminhtml_Observer</class>
108
+ <method>actionConfigResetContacts</method>
109
+ </connector_data_mapping_reset>
110
+ </observers>
111
+ </admin_system_config_changed_section_connector_data_mapping>
112
+ <admin_system_config_changed_section_connector_sync_settings>
113
+ <observers>
114
+ <connector_sys_check_feature_active>
115
+ <class>Dotdigitalgroup_Email_Model_Adminhtml_Observer</class>
116
+ <method>checkFeatureActive</method>
117
+ </connector_sys_check_feature_active>
118
+ </observers>
119
+ </admin_system_config_changed_section_connector_sync_settings>
120
+ <customer_save_after>
121
+ <observers>
122
+ <connector_customer_save_after>
123
+ <class>Dotdigitalgroup_Email_Model_Customer_Observer</class>
124
+ <method>handleCustomerSaveBefore</method>
125
+ </connector_customer_save_after>
126
+ </observers>
127
+ </customer_save_after>
128
+ <customer_register_success>
129
+ <observers>
130
+ <connector_customer_register_success>
131
+ <type>singleton</type>
132
+ <class>Dotdigitalgroup_Email_Model_Customer_Observer</class>
133
+ <method>handleCustomerRegiterSuccess</method>
134
+ </connector_customer_register_success>
135
+ </observers>
136
+ </customer_register_success>
137
+ <customer_delete_after>
138
+ <observers>
139
+ <connector_customer_delete_after>
140
+ <class>Dotdigitalgroup_Email_Model_Customer_Observer</class>
141
+ <method>handleCustomerDeleteAfter</method>
142
+ </connector_customer_delete_after>
143
+ </observers>
144
+ </customer_delete_after>
145
+ <newsletter_subscriber_save_before>
146
+ <observers>
147
+ <connector_newsletter_subscriber_save_before>
148
+ <class>Dotdigitalgroup_Email_Model_Newsletter_Observer</class>
149
+ <method>handleNewsletterSubscriberSave</method>
150
+ </connector_newsletter_subscriber_save_before>
151
+ </observers>
152
+ </newsletter_subscriber_save_before>
153
+ <sales_order_place_after>
154
+ <observers>
155
+ <connector_record_sale>
156
+ <type>singleton</type>
157
+ <class>Dotdigitalgroup_Email_Model_Sales_Observer</class>
158
+ <method>handleSalesOrderPlaceAfter</method>
159
+ </connector_record_sale>
160
+ </observers>
161
+ </sales_order_place_after>
162
+ <sales_order_save_before>
163
+ <observers>
164
+ <connector_sales_save_before>
165
+ <class>Dotdigitalgroup_Email_Model_Sales_Observer</class>
166
+ <method>handleSalesOrderSaveBefore</method>
167
+ </connector_sales_save_before>
168
+ </observers>
169
+ </sales_order_save_before>
170
+ <sales_order_save_after>
171
+ <observers>
172
+ <connector_checkout_type_onepage_save_order_after>
173
+ <class>Dotdigitalgroup_Email_Model_Sales_Observer</class>
174
+ <method>handleSalesOrderSaveAfter</method>
175
+ </connector_checkout_type_onepage_save_order_after>
176
+ </observers>
177
+ </sales_order_save_after>
178
+ <sales_order_creditmemo_save_after>
179
+ <observers>
180
+ <connector_sales_order_payment_refund>
181
+ <class>Dotdigitalgroup_Email_Model_Sales_Observer</class>
182
+ <method>handleSalesOrderRefund</method>
183
+ </connector_sales_order_payment_refund>
184
+ </observers>
185
+ </sales_order_creditmemo_save_after>
186
+ <order_cancel_after>
187
+ <observers>
188
+ <connector_sales_order_cancel>
189
+ <class>Dotdigitalgroup_Email_Model_Sales_Observer</class>
190
+ <method>hangleSalesOrderCancel</method>
191
+ </connector_sales_order_cancel>
192
+ </observers>
193
+ </order_cancel_after>
194
+ <rewards_points_indexer_update>
195
+ <observers>
196
+ <connector_rewards_points_indexer_update>
197
+ <class>Dotdigitalgroup_Email_Model_Sweettooth_Observer</class>
198
+ <method>ConnectorRewardsPointsIndexerUpdate</method>
199
+ </connector_rewards_points_indexer_update>
200
+ </observers>
201
+ </rewards_points_indexer_update>
202
+ <review_save_after>
203
+ <observers>
204
+ <connector_review_save_after>
205
+ <class>Dotdigitalgroup_Email_Model_Customer_Observer</class>
206
+ <method>reviewSaveAfter</method>
207
+ </connector_review_save_after>
208
+ </observers>
209
+ </review_save_after>
210
+ </events>
211
+ </global>
212
+ <adminhtml>
213
+ <layout>
214
+ <updates>
215
+ <connector_email>
216
+ <file>connector/email.xml</file>
217
+ </connector_email>
218
+ </updates>
219
+ </layout>
220
+ <events>
221
+ <controller_action_predispatch>
222
+ <observers>
223
+ <connector_feed>
224
+ <type>singleton</type>
225
+ <class>Dotdigitalgroup_Email_Model_Adminhtml_Observer</class>
226
+ <method>updateFeed</method>
227
+ </connector_feed>
228
+ </observers>
229
+ </controller_action_predispatch>
230
+ </events>
231
+ <translate>
232
+ <modules>
233
+ <Dotdigitalgroup_Email>
234
+ <files>
235
+ <default>Dotdigitalgroup_Email.csv</default>
236
+ </files>
237
+ </Dotdigitalgroup_Email>
238
+ </modules>
239
+ </translate>
240
+ </adminhtml>
241
+ <admin>
242
+ <routers>
243
+ <adminhtml>
244
+ <args>
245
+ <modules>
246
+ <Dotdigitalgroup_Email before="Mage_Adminhtml">Dotdigitalgroup_Email_Adminhtml</Dotdigitalgroup_Email>
247
+ </modules>
248
+ </args>
249
+ </adminhtml>
250
+ </routers>
251
+ </admin>
252
+ <crontab>
253
+ <jobs>
254
+ <connector_email_customer_sync>
255
+ <run><model>email_connector/cron::contactSync</model></run>
256
+ <schedule>
257
+ <cron_expr>*/5 * * * *</cron_expr>
258
+ </schedule>
259
+ </connector_email_customer_sync>
260
+ <connector_email_subscriber_and_guest_sync>
261
+ <run><model>email_connector/cron::subscribersAndGuestSync</model></run>
262
+ <schedule>
263
+ <cron_expr>*/15 * * * *</cron_expr>
264
+ </schedule>
265
+ </connector_email_subscriber_and_guest_sync>
266
+ <connector_email_lostbaskets>
267
+ <run><model>email_connector/cron::lostBaskets</model></run>
268
+ <schedule>
269
+ <cron_expr>*/5 * * * *</cron_expr>
270
+ </schedule>
271
+ </connector_email_lostbaskets>
272
+ <connector_email_campaign>
273
+ <run>
274
+ <model>email_connector/cron::sendMappedEmails</model>
275
+ </run>
276
+ <schedule>
277
+ <cron_expr>*/5 * * * *</cron_expr>
278
+ </schedule>
279
+ </connector_email_campaign>
280
+ <connector_email_order_sync>
281
+ <run><model>email_connector/cron::orderSync</model></run>
282
+ <schedule>
283
+ <cron_expr>*/15 * * * *</cron_expr>
284
+ </schedule>
285
+ </connector_email_order_sync>
286
+ <connector_email_cleaner>
287
+ <run><model>email_connector/cron::cleaning</model></run>
288
+ <schedule>
289
+ <cron_expr>0 0 1 * * </cron_expr>
290
+ </schedule>
291
+ </connector_email_cleaner>
292
+ </jobs>
293
+ </crontab>
294
+ <default>
295
+ <connector_api_credentials>
296
+ <api>
297
+ <enabled>0</enabled>
298
+ <username></username>
299
+ <password></password>
300
+ </api>
301
+ <oauth>
302
+ <client_id></client_id>
303
+ <client_key></client_key>
304
+ <test_connect></test_connect>
305
+ </oauth>
306
+ </connector_api_credentials>
307
+ <connector_sync_settings>
308
+ <address_book>
309
+ <customers>0</customers>
310
+ <subscribers>0</subscribers>
311
+ <guests>0</guests>
312
+ </address_book>
313
+ <sync>
314
+ <contact_enabled>0</contact_enabled>
315
+ <subscriber_enabled>0</subscriber_enabled>
316
+ <order_enabled>0</order_enabled>
317
+ <wishlist_enabled>0</wishlist_enabled>
318
+ </sync>
319
+ <dynamic_addressbook>
320
+ <addressbook_name>0</addressbook_name>
321
+ </dynamic_addressbook>
322
+ </connector_sync_settings>
323
+ <connector_data_mapping>
324
+ <customer_data>
325
+ <customer_id></customer_id>
326
+ <firstname></firstname>
327
+ <lastname></lastname>
328
+ <dob></dob>
329
+ <gender></gender>
330
+ <website_name></website_name>
331
+ <store_name></store_name>
332
+ <created_at></created_at>
333
+ <last_logged_date></last_logged_date>
334
+ <customer_group></customer_group>
335
+ <review_count></review_count>
336
+ <last_review_date></last_review_date>
337
+ <billing_address_1></billing_address_1>
338
+ <billing_address_2></billing_address_2>
339
+ <billing_city></billing_city>
340
+ <billing_state></billing_state>
341
+ <billing_country></billing_country>
342
+ <billing_postcode></billing_postcode>
343
+ <billing_telephone></billing_telephone>
344
+ <delivery_address_1></delivery_address_1>
345
+ <delivery_address_2></delivery_address_2>
346
+ <delivery_city></delivery_city>
347
+ <delivery_state></delivery_state>
348
+ <delivery_country></delivery_country>
349
+ <delivery_postcode></delivery_postcode>
350
+ <delivery_telephone></delivery_telephone>
351
+ <number_of_orders></number_of_orders>
352
+ <average_order_value></average_order_value>
353
+ <total_spend></total_spend>
354
+ <last_order_date></last_order_date>
355
+ <last_order_id></last_order_id>
356
+ <total_refund></total_refund>
357
+ <custom_attributes></custom_attributes>
358
+ <validator></validator>
359
+ </customer_data>
360
+ <dynamic_datafield>
361
+ <datafield_name></datafield_name>
362
+ <datafield_type></datafield_type>
363
+ <datafield_default></datafield_default>
364
+ <datafield_access></datafield_access>
365
+ </dynamic_datafield>
366
+ <sweet_tooth>
367
+ <active>0</active>
368
+ <reward_point_balance></reward_point_balance>
369
+ <reward_point_pending></reward_point_pending>
370
+ <reward_point_pending_time></reward_point_pending_time>
371
+ <reward_point_on_hold></reward_point_on_hold>
372
+ <reward_point_expiration></reward_point_expiration>
373
+ <reward_point_last_earn></reward_point_last_earn>
374
+ <reward_point_last_spent></reward_point_last_spent>
375
+ </sweet_tooth>
376
+ </connector_data_mapping>
377
+ <connector_roi_tracking>
378
+ <page_tracking>
379
+ <enabled>0</enabled>
380
+ </page_tracking>
381
+ <roi_tracking>
382
+ <enabled>0</enabled>
383
+ </roi_tracking>
384
+ </connector_roi_tracking>
385
+ <connector_lost_baskets>
386
+ <customers>
387
+ <enabled_1>0</enabled_1>
388
+ <send_after_1></send_after_1>
389
+ <campaign_1></campaign_1>
390
+ <enabled_2>0</enabled_2>
391
+ <send_after_2></send_after_2>
392
+ <campaign_2></campaign_2>
393
+ <enabled_3>0</enabled_3>
394
+ <send_after_3></send_after_3>
395
+ <campaign_3></campaign_3>
396
+ </customers>
397
+ <guests>
398
+ <enabled_1>0</enabled_1>
399
+ <send_after_1></send_after_1>
400
+ <campaign_1></campaign_1>
401
+ <enabled_2>0</enabled_2>
402
+ <send_after_2></send_after_2>
403
+ <campaign_2></campaign_2>
404
+ <enabled_3>0</enabled_3>
405
+ <send_after_3></send_after_3>
406
+ <campaign_3></campaign_3>
407
+ </guests>
408
+ </connector_lost_baskets>
409
+ <connector_sms>
410
+ <sms_one>
411
+ <enabled>0</enabled>
412
+ <status></status>
413
+ <message></message>
414
+ </sms_one>
415
+ <sms_two>
416
+ <enabled>0</enabled>
417
+ <status></status>
418
+ <message></message>
419
+ </sms_two>
420
+ <sms_three>
421
+ <enabled>0</enabled>
422
+ <status></status>
423
+ <message></message>
424
+ </sms_three>
425
+ <sms_four>
426
+ <enabled>0</enabled>
427
+ <status></status>
428
+ <message></message>
429
+ </sms_four>
430
+ </connector_sms>
431
+ <connector_dynamic_content>
432
+ <products>
433
+ <related_display_type>list</related_display_type>
434
+ <related_items_to_display>2</related_items_to_display>
435
+ <upsell_display_type>list</upsell_display_type>
436
+ <upsell_items_to_display>2</upsell_items_to_display>
437
+ <crosssell_display_type>list</crosssell_display_type>
438
+ <crosssell_items_to_display>2</crosssell_items_to_display>
439
+ <bestsellers_display_type>list</bestsellers_display_type>
440
+ <bestsellers_items_to_display>2</bestsellers_items_to_display>
441
+ <bestsellers_time_period></bestsellers_time_period>
442
+ <most_viewed_display_type>list</most_viewed_display_type>
443
+ <most_viewed_items_to_display>2</most_viewed_items_to_display>
444
+ <most_viewed_time_period></most_viewed_time_period>
445
+ <recently_viewed_display_type>list</recently_viewed_display_type>
446
+ <recently_viewed_items_to_display>2</recently_viewed_items_to_display>
447
+ </products>
448
+ <external_dynamic_content_urls>
449
+ <passcode>secret</passcode>
450
+ <lost_basket_url></lost_basket_url>
451
+ <coupon_code_url></coupon_code_url>
452
+ <dynamic_content_url></dynamic_content_url>
453
+ <related_products_url></related_products_url>
454
+ <upsell_products_url></upsell_products_url>
455
+ <crosssell_products_url></crosssell_products_url>
456
+ <best_sellers_url></best_sellers_url>
457
+ <most_viewed_url></most_viewed_url>
458
+ <product_push_url></product_push_url>
459
+ <recently_viewed_url></recently_viewed_url>
460
+ <new_order_url></new_order_url>
461
+ <new_order_guest_url></new_order_guest_url>
462
+ <order_update_url></order_update_url>
463
+ <order_update_guest_url></order_update_guest_url>
464
+ <new_invoice_url></new_invoice_url>
465
+ <new_invoice_guest_url></new_invoice_guest_url>
466
+ <invoice_update_url></invoice_update_url>
467
+ <invoice_update_guest_url></invoice_update_guest_url>
468
+ <new_creditmemo_url></new_creditmemo_url>
469
+ <new_creditmemo_guest_url></new_creditmemo_guest_url>
470
+ <creditmemo_update_url></creditmemo_update_url>
471
+ <creditmemo_update_guest_url></creditmemo_update_guest_url>
472
+ <new_shipment_url></new_shipment_url>
473
+ <new_shipment_guest_url></new_shipment_guest_url>
474
+ <shipment_update_url></shipment_update_url>
475
+ <shipment_update_guest_url></shipment_update_guest_url>
476
+ </external_dynamic_content_urls>
477
+ <manual_product_search>
478
+ <display_type>list</display_type>
479
+ <items_to_display>2</items_to_display>
480
+ <products_push_items></products_push_items>
481
+ </manual_product_search>
482
+ <fallback_products>
483
+ <product_list></product_list>
484
+ </fallback_products>
485
+ </connector_dynamic_content>
486
+ <connector_transactional_emails>
487
+ <credentials>
488
+ <enabled>0</enabled>
489
+ <api_username></api_username>
490
+ <api_password></api_password>
491
+ </credentials>
492
+ <email_settings>
493
+ <from_address></from_address>
494
+ <unsubscribe_link>1</unsubscribe_link>
495
+ <reply_action>Webmail</reply_action>
496
+ <reply_address></reply_address>
497
+ <send_copy></send_copy>
498
+ </email_settings>
499
+ <email_mapping>
500
+ <default_email_templates></default_email_templates>
501
+ <custom_email_templates></custom_email_templates>
502
+ </email_mapping>
503
+ </connector_transactional_emails>
504
+ <connector_automation_studio>
505
+ <automation>
506
+ <customer_automation>0</customer_automation>
507
+ <subscriber_automation>0</subscriber_automation>
508
+ </automation>
509
+ </connector_automation_studio>
510
+ <connector_advanced_settings>
511
+ <sync_limits>
512
+ <orders>500</orders>
513
+ <order_statuses></order_statuses>
514
+ <order_delete>0</order_delete>
515
+ </sync_limits>
516
+ <abandoned_cart>
517
+ <limits>0</limits>
518
+ <shell></shell>
519
+ </abandoned_cart>
520
+ <sync_settings>
521
+ <contact_sync></contact_sync>
522
+ <subscriber_sync></subscriber_sync>
523
+ <order_sync></order_sync>
524
+ <delete_contact></delete_contact>
525
+ <reimport_customers></reimport_customers>
526
+ <reimport_subscribers></reimport_subscribers>
527
+ <reimport_orders></reimport_orders>
528
+ <suppressed_contacts></suppressed_contacts>
529
+ </sync_settings>
530
+ <admin>
531
+ <setup_data_fields></setup_data_fields>
532
+ <memory_limit>0</memory_limit>
533
+ <batch_size>10000</batch_size>
534
+ <debug_enabled>1</debug_enabled>
535
+ <debug_api_calls>0</debug_api_calls>
536
+ <raygun_code>JOWaQ4nf4Ox7eAFUvr+TAw==</raygun_code>
537
+ <recommended_inline><![CDATA[table{font-family: arial, geneva, sans-serif; font-size:12px;}]]></recommended_inline>
538
+ <feed_enabled>1</feed_enabled>
539
+ <feed_url>dotmailerformagento.co.uk/feed</feed_url>
540
+ <use_https>0</use_https>
541
+ <frequency>1</frequency>
542
+ <last_update></last_update>
543
+ </admin>
544
+ </connector_advanced_settings>
545
+ </default>
546
+ </config>
app/code/community/Dotdigitalgroup/Email/etc/files.yaml ADDED
@@ -0,0 +1,252 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ etc:
2
+ - adminhtml.xml
3
+ - config.xml
4
+ - system.xml
5
+ controllers:
6
+ - Adminhtml#Email#AutomationController.php
7
+ - Adminhtml#Email#CampaignController.php
8
+ - Adminhtml#Email#ContactController.php
9
+ - Adminhtml#Email#DashboardController.php
10
+ - Adminhtml#Email#OrderController.php
11
+ - Adminhtml#ConnectorController.php
12
+ - CreditmemoController.php
13
+ - DynamicContentController.php
14
+ - EmailController.php
15
+ - InvoiceController.php
16
+ - OrderController.php
17
+ - ProductsController.php
18
+ - ReportController.php
19
+ - ShippingController.php
20
+ sql:
21
+ - email_connector_setup#mysql4-install-0.1.0.php
22
+ - email_connector_setup#mysql4-install-3.0.0.php
23
+ - email_connector_setup#mysql4-upgrade-1.1.1-1.1.2.php
24
+ - email_connector_setup#mysql4-upgrade-1.1.2-1.5.0.php
25
+ - email_connector_setup#mysql4-upgrade-2.0.0-2.0.1.php
26
+ - email_connector_setup#mysql4-upgrade-2.0.1-2.0.2.php
27
+ - email_connector_setup#mysql4-upgrade-2.0.4-2.0.5.php
28
+ - email_connector_setup#mysql4-upgrade-2.0.5-2.0.6.php
29
+ - email_connector_setup#mysql4-upgrade-3.0.1-3.0.2.php
30
+ - email_connector_setup#mysql4-upgrade-3.0.3-3.0.4.php
31
+ - email_connector_setup#mysql4-upgrade-3.0.4-3.0.5.php
32
+ - email_connector_setup#mysql4-upgrade-3.1.2-3.1.3.php
33
+ locale:
34
+ - en_US#Dotdigitalgroup_Email.csv
35
+ block:
36
+ - Adminhtml#Campaign#Edit#Form.php
37
+ - Adminhtml#Campaign#Edit.php
38
+ - Adminhtml#Campaign#Grid.php
39
+ - Adminhtml#Column#Renderer#Imported.php
40
+ - Adminhtml#Column#Renderer#Status.php
41
+ - Adminhtml#Column#Renderer#Sync.php
42
+ - Adminhtml#Config#Template#Templatefields.php
43
+ - Adminhtml#Config#Customdatafields.php
44
+ - Adminhtml#Config#Select.php
45
+ - Adminhtml#Contact#Edit#Form.php
46
+ - Adminhtml#Contact#Edit.php
47
+ - Adminhtml#Contact#Grid.php
48
+ - Adminhtml#Dashboard#Tabs#Analysis#Abandonedcarts.php
49
+ - Adminhtml#Dashboard#Tabs#Analysis#Customer.php
50
+ - Adminhtml#Dashboard#Tabs#Analysis#Rfm.php
51
+ - Adminhtml#Dashboard#Tabs#Analysis#Sales.php
52
+ - Adminhtml#Dashboard#Tabs#Analysis#Subscriber.php
53
+ - Adminhtml#Dashboard#Tabs#General#Data.php
54
+ - Adminhtml#Dashboard#Tabs#Analysis.php
55
+ - Adminhtml#Dashboard#Tabs#Config.php
56
+ - Adminhtml#Dashboard#Tabs#General.php
57
+ - Adminhtml#Dashboard#Tabs#Status.php
58
+ - Adminhtml#Dashboard#Switcher.php
59
+ - Adminhtml#Dashboard#Tabs.php
60
+ - Adminhtml#Order#Grid.php
61
+ - Adminhtml#Sales#Order#Creditmemo#View.php
62
+ - Adminhtml#System#Advanced#Deletecontactids.php
63
+ - Adminhtml#System#Advanced#Notification.php
64
+ - Adminhtml#System#Advanced#Reimportorders.php
65
+ - Adminhtml#System#Advanced#Reimportsubscribers.php
66
+ - Adminhtml#System#Advanced#Resetcustomersimport.php
67
+ - Adminhtml#System#Advanced#Runcontactsync.php
68
+ - Adminhtml#System#Advanced#Runordersync.php
69
+ - Adminhtml#System#Advanced#Runsubscribersync.php
70
+ - Adminhtml#System#Advanced#Setupdatafields.php
71
+ - Adminhtml#System#Advanced#Suppressedcontacts.php
72
+ - Adminhtml#System#Automation#Connect.php
73
+ - Adminhtml#System#Config#Addressbook.php
74
+ - Adminhtml#System#Config#Datafield.php
75
+ - Adminhtml#System#Config#Resetcontacts.php
76
+ - Adminhtml#System#Config#Resetguests.php
77
+ - Adminhtml#System#Config#Resetsubscribers.php
78
+ - Adminhtml#System#Config#Validator.php
79
+ - Adminhtml#System#Config#Waitingfield.php
80
+ - Adminhtml#System#Config#Wrapper.php
81
+ - Adminhtml#System#Dynamic#Addressbookbutton.php
82
+ - Adminhtml#System#Dynamic#Bestsellers.php
83
+ - Adminhtml#System#Dynamic#Couponinfo.php
84
+ - Adminhtml#System#Dynamic#Creditmemonew.php
85
+ - Adminhtml#System#Dynamic#Crosssell.php
86
+ - Adminhtml#System#Dynamic#Datafieldbutton.php
87
+ - Adminhtml#System#Dynamic#Gridlist.php
88
+ - Adminhtml#System#Dynamic#Lostbasket.php
89
+ - Adminhtml#System#Dynamic#Mostviewed.php
90
+ - Adminhtml#System#Dynamic#Productpush.php
91
+ - Adminhtml#System#Dynamic#Recentlyviewed.php
92
+ - Adminhtml#System#Dynamic#Related.php
93
+ - Adminhtml#System#Dynamic#Upsell.php
94
+ - Adminhtml#System#Sms#Smsmessagefour.php
95
+ - Adminhtml#System#Sms#Smsmessageone.php
96
+ - Adminhtml#System#Sms#Smsmessagethree.php
97
+ - Adminhtml#System#Sms#Smsmessagetwo.php
98
+ - Adminhtml#System#Url#Creditmemoupdate.php
99
+ - Adminhtml#System#Url#Creditmemoupdateguest.php
100
+ - Adminhtml#System#Url#Customerconfirmation.php
101
+ - Adminhtml#System#Url#Customerconfirmed.php
102
+ - Adminhtml#System#Url#Customernew.php
103
+ - Adminhtml#System#Url#Invoiceupdate.php
104
+ - Adminhtml#System#Url#Invoiceupdateguest.php
105
+ - Adminhtml#System#Url#Newcreditmemo.php
106
+ - Adminhtml#System#Url#Newcreditmemoguest.php
107
+ - Adminhtml#System#Url#Newinvoice.php
108
+ - Adminhtml#System#Url#Newinvoiceguest.php
109
+ - Adminhtml#System#Url#Neworder.php
110
+ - Adminhtml#System#Url#Neworderguest.php
111
+ - Adminhtml#System#Url#Newshipment.php
112
+ - Adminhtml#System#Url#Newshipmentguest.php
113
+ - Adminhtml#System#Url#Orderupdate.php
114
+ - Adminhtml#System#Url#Orderupdateguest.php
115
+ - Adminhtml#System#Url#Shipmentupdate.php
116
+ - Adminhtml#System#Url#Shipmentupdateguest.php
117
+ - Adminhtml#System#Ajaxvalidate.php
118
+ - Adminhtml#System#Emailapivalidate.php
119
+ - Adminhtml#Campaign.php
120
+ - Adminhtml#Config.php
121
+ - Adminhtml#Contact.php
122
+ - Adminhtml#Dashboard.php
123
+ - Adminhtml#Order.php
124
+ - Order#Creditmemo.php
125
+ - Order#Invoice.php
126
+ - Order#Shipping.php
127
+ - Recommended#Bestsellers.php
128
+ - Recommended#Mostviewed.php
129
+ - Recommended#Products.php
130
+ - Recommended#Push.php
131
+ - Recommended#Recentlyviewed.php
132
+ - Basket.php
133
+ - Coupon.php
134
+ - Order.php
135
+ - Products.php
136
+ helper:
137
+ - Config.php
138
+ - Data.php
139
+ - File.php
140
+ - Recommended.php
141
+ - Transactional.php
142
+ model:
143
+ - Abstract#Rest.php
144
+ - Adminhtml#Dashboard#Tabs#Analysis#Abandoned.php
145
+ - Adminhtml#Dashboard#Tabs#Analysis#Customer.php
146
+ - Adminhtml#Dashboard#Tabs#Analysis#Orders.php
147
+ - Adminhtml#Dashboard#Tabs#Analysis#Rfm.php
148
+ - Adminhtml#Dashboard#Tabs#Analysis#Subscriber.php
149
+ - Adminhtml#Dashboard#Content.php
150
+ - Adminhtml#Source#Advanced#Abandonedlimit.php
151
+ - Adminhtml#Source#Advanced#Transdata.php
152
+ - Adminhtml#Source#Automation#Programme.php
153
+ - Adminhtml#Source#Contact#Imported.php
154
+ - Adminhtml#Source#Customer#Attributes#Select.php
155
+ - Adminhtml#Source#Datamapping#Datafieldtype.php
156
+ - Adminhtml#Source#Dynamic#Displaytype.php
157
+ - Adminhtml#Source#Dynamic#Gridview.php
158
+ - Adminhtml#Source#Lostbaskets#Interval.php
159
+ - Adminhtml#Source#Lostbaskets#Intervalminute.php
160
+ - Adminhtml#Source#Sweettooth#Yesno.php
161
+ - Adminhtml#Source#Transactional#Campaigns.php
162
+ - Adminhtml#Source#Transactional#Customselect.php
163
+ - Adminhtml#Source#Transactional#Defaultselect.php
164
+ - Adminhtml#Source#Transactional#Fromaddress.php
165
+ - Adminhtml#Source#Transactional#Replyactions.php
166
+ - Adminhtml#Source#Transactional#Sendtype.php
167
+ - Adminhtml#Source#Addressbooks.php
168
+ - Adminhtml#Source#Campaigns.php
169
+ - Adminhtml#Source#Datafields.php
170
+ - Adminhtml#Source#Orderstatus.php
171
+ - Adminhtml#Observer.php
172
+ - Apiconnector#Client.php
173
+ - Apiconnector#Contact.php
174
+ - Apiconnector#Customer.php
175
+ - Apiconnector#Test.php
176
+ - Connector#Account.php
177
+ - Connector#Campaign.php
178
+ - Connector#Datafield.php
179
+ - Connector#Order.php
180
+ - Controller#Observer.php
181
+ - Customer#Wishlist#Item.php
182
+ - Customer#Guest.php
183
+ - Customer#Observer.php
184
+ - Customer#Wishlist.php
185
+ - Email#Template.php
186
+ - Newsletter#Observer.php
187
+ - Newsletter#Subscriber.php
188
+ - Resource#Campaign#Collection.php
189
+ - Resource#Config#Collection.php
190
+ - Resource#Contact#Collection.php
191
+ - Resource#Order#Collection.php
192
+ - Resource#Campaign.php
193
+ - Resource#Config.php
194
+ - Resource#Contact.php
195
+ - Resource#Order.php
196
+ - Resource#Setup.php
197
+ - Sales#Observer.php
198
+ - Sales#Order.php
199
+ - Sales#Quote.php
200
+ - Sms#Campaign.php
201
+ - Sweettooth#Observer.php
202
+ - Campaign.php
203
+ - Config.php
204
+ - Contact.php
205
+ - Cron.php
206
+ - Order.php
207
+ design:
208
+ - adminhtml#default#default#layout#connector#email.xml
209
+ - adminhtml#default#default#template#connector#dashboard#tabs#analysis#index.phtml
210
+ - adminhtml#default#default#template#connector#dashboard#tabs#analysis#rfm.phtml
211
+ - adminhtml#default#default#template#connector#dashboard#tabs#general#index.phtml
212
+ - adminhtml#default#default#template#connector#dashboard#tabs#config.phtml
213
+ - adminhtml#default#default#template#connector#dashboard#tabs#data.phtml
214
+ - adminhtml#default#default#template#connector#dashboard#accountbar.phtml
215
+ - adminhtml#default#default#template#connector#dashboard#content.phtml
216
+ - adminhtml#default#default#template#connector#dashboard#status.phtml
217
+ - adminhtml#default#default#template#connector#dashboard#tabs.phtml
218
+ - adminhtml#default#default#template#connector#system#config#createdatafield.phtml
219
+ - adminhtml#default#default#template#connector#grid.phtml
220
+ - frontend#base#default#layout#connector.xml
221
+ - frontend#base#default#template#connector#creditmemo#items.phtml
222
+ - frontend#base#default#template#connector#creditmemo#new.phtml
223
+ - frontend#base#default#template#connector#creditmemo#newguest.phtml
224
+ - frontend#base#default#template#connector#creditmemo#update.phtml
225
+ - frontend#base#default#template#connector#creditmemo#updateguest.phtml
226
+ - frontend#base#default#template#connector#invoice#new.phtml
227
+ - frontend#base#default#template#connector#invoice#newguest.phtml
228
+ - frontend#base#default#template#connector#invoice#update.phtml
229
+ - frontend#base#default#template#connector#invoice#updateguest.phtml
230
+ - frontend#base#default#template#connector#order#items.phtml
231
+ - frontend#base#default#template#connector#order#new.phtml
232
+ - frontend#base#default#template#connector#order#newguest.phtml
233
+ - frontend#base#default#template#connector#order#update.phtml
234
+ - frontend#base#default#template#connector#order#updateguest.phtml
235
+ - frontend#base#default#template#connector#product#list.phtml
236
+ - frontend#base#default#template#connector#product#price.phtml
237
+ - frontend#base#default#template#connector#shipping#new.phtml
238
+ - frontend#base#default#template#connector#shipping#newguest.phtml
239
+ - frontend#base#default#template#connector#shipping#update.phtml
240
+ - frontend#base#default#template#connector#shipping#updateguest.phtml
241
+ - frontend#base#default#template#connector#basket.phtml
242
+ - frontend#base#default#template#connector#coupon.phtml
243
+ - frontend#base#default#template#connector#roi_code.phtml
244
+ - frontend#base#default#template#connector#tracking_code.phtml
245
+ - frontend#base#default#template#page#blank.phtml
246
+ skin:
247
+ - adminhtml#default#default#connector#dashboard.css
248
+ - frontend#base#default#js#mailcheck#init.js
249
+ shell:
250
+ - connector.php
251
+ lib:
252
+ - Raygun4php#RaygunClient.php
app/code/community/Dotdigitalgroup/Email/etc/system.xml ADDED
@@ -0,0 +1,2178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <tabs>
4
+ <connector translate="label" module="connector">
5
+ <label>EMAIL</label>
6
+ <sort_order>1000</sort_order>
7
+ </connector>
8
+ </tabs>
9
+ <sections>
10
+ <connector_api_credentials translate="label" module="connector">
11
+ <label><![CDATA[API Credentials]]></label>
12
+ <tab>connector</tab>
13
+ <frontend_type>text</frontend_type>
14
+ <sort_order>1000</sort_order>
15
+ <show_in_default>1</show_in_default>
16
+ <show_in_website>1</show_in_website>
17
+ <show_in_store>0</show_in_store>
18
+ <groups>
19
+ <api translate="label" module="connector">
20
+ <label>Settings</label>
21
+ <frontend_type>text</frontend_type>
22
+ <sort_order>10</sort_order>
23
+ <show_in_default>1</show_in_default>
24
+ <show_in_website>1</show_in_website>
25
+ <show_in_store>0</show_in_store>
26
+ <expanded>1</expanded>
27
+ <fields>
28
+ <enabled translate="label" module="connector">
29
+ <label>Enabled</label>
30
+ <frontend_type>select</frontend_type>
31
+ <source_model>adminhtml/system_config_source_yesno</source_model>
32
+ <sort_order>10</sort_order>
33
+ <show_in_default>1</show_in_default>
34
+ <show_in_website>1</show_in_website>
35
+ <show_in_store>0</show_in_store>
36
+ </enabled>
37
+ <username translate="label" module="connector">
38
+ <label>API Username</label>
39
+ <frontend_type>text</frontend_type>
40
+ <frontend_model>email_connector/adminhtml_system_config_wrapper</frontend_model>
41
+ <sort_order>20</sort_order>
42
+ <show_in_default>1</show_in_default>
43
+ <show_in_website>1</show_in_website>
44
+ <show_in_store>0</show_in_store>
45
+ <depends><enabled>1</enabled></depends>
46
+ </username>
47
+ <password translate="label" module="connector">
48
+ <label>API Password</label>
49
+ <frontend_type>password</frontend_type>
50
+ <frontend_model>email_connector/adminhtml_system_ajaxvalidate</frontend_model>
51
+ <sort_order>30</sort_order>
52
+ <show_in_default>1</show_in_default>
53
+ <show_in_website>1</show_in_website>
54
+ <show_in_store>0</show_in_store>
55
+ <depends><enabled>1</enabled></depends>
56
+ </password>
57
+ <validator>
58
+ <frontend_type>hidden</frontend_type>
59
+ <frontend_model>email_connector/adminhtml_system_config_waitingfield</frontend_model>
60
+ <sort_order>50</sort_order>
61
+ <show_in_default>1</show_in_default>
62
+ <show_in_website>1</show_in_website>
63
+ <show_in_store>0</show_in_store>
64
+ <can_be_empty>1</can_be_empty>
65
+ </validator>
66
+ </fields>
67
+ </api>
68
+ <oauth translate="label" module="connector">
69
+ <label>OAUTH Credentials</label>
70
+ <sort_order>20</sort_order>
71
+ <show_in_default>1</show_in_default>
72
+ <show_in_website>1</show_in_website>
73
+ <show_in_store>0</show_in_store>
74
+ <fields>
75
+ <client_id translate="label" module="connector">
76
+ <label>Client ID</label>
77
+ <frontend_type>text</frontend_type>
78
+ <sort_order>10</sort_order>
79
+ <show_in_default>1</show_in_default>
80
+ <show_in_website>1</show_in_website>
81
+ <show_in_store>0</show_in_store>
82
+ </client_id>
83
+ <client_key translate="label" module="connector">
84
+ <label>Client Secret Key</label>
85
+ <frontend_type>text</frontend_type>
86
+ <sort_order>20</sort_order>
87
+ <show_in_default>1</show_in_default>
88
+ <show_in_website>1</show_in_website>
89
+ <show_in_store>0</show_in_store>
90
+ </client_key>
91
+ <test_connect translate="label" module="connector">
92
+ <label>Connection</label>
93
+ <frontend_model>email_connector/adminhtml_system_automation_connect</frontend_model>
94
+ <sort_order>30</sort_order>
95
+ <show_in_default>1</show_in_default>
96
+ <show_in_website>1</show_in_website>
97
+ <comment>Please Save Client ID and Secret Key Before Test. Generate/Refresh New Token.</comment>
98
+ </test_connect>
99
+ </fields>
100
+ </oauth>
101
+ </groups>
102
+ </connector_api_credentials>
103
+ <connector_sync_settings translate="label" module="connector">
104
+ <label><![CDATA[Sync Settings]]></label>
105
+ <tab>connector</tab>
106
+ <frontend_type>text</frontend_type>
107
+ <sort_order>3000</sort_order>
108
+ <show_in_default>1</show_in_default>
109
+ <show_in_website>1</show_in_website>
110
+ <show_in_store>0</show_in_store>
111
+ <groups>
112
+ <address_book translate="label" module="connector">
113
+ <label>Address Book Mapping</label>
114
+ <sort_order>10</sort_order>
115
+ <show_in_default>1</show_in_default>
116
+ <show_in_website>1</show_in_website>
117
+ <show_in_store>0</show_in_store>
118
+ <expanded>1</expanded>
119
+ <fields>
120
+ <customers translate="label" module="connector">
121
+ <label>Add Customers To</label>
122
+ <frontend_type>select</frontend_type>
123
+ <frontend_model>email_connector/adminhtml_system_config_resetcontacts</frontend_model>
124
+ <source_model>email_connector/adminhtml_source_addressbooks</source_model>
125
+ <sort_order>10</sort_order>
126
+ <show_in_default>1</show_in_default>
127
+ <show_in_website>1</show_in_website>
128
+ <show_in_store>0</show_in_store>
129
+ </customers>
130
+ <subscribers translate="label" module="connector">
131
+ <label>Add Subscribers To</label>
132
+ <frontend_type>select</frontend_type>
133
+ <frontend_model>email_connector/adminhtml_system_config_resetsubscribers</frontend_model>
134
+ <source_model>email_connector/adminhtml_source_addressbooks</source_model>
135
+ <sort_order>20</sort_order>
136
+ <show_in_default>1</show_in_default>
137
+ <show_in_website>1</show_in_website>
138
+ <show_in_store>0</show_in_store>
139
+ </subscribers>
140
+ <guests translate="label" module="connector">
141
+ <label>Add Guests To</label>
142
+ <frontend_type>select</frontend_type>
143
+ <frontend_model>email_connector/adminhtml_system_config_resetguests</frontend_model>
144
+ <source_model>email_connector/adminhtml_source_addressbooks</source_model>
145
+ <sort_order>30</sort_order>
146
+ <show_in_default>1</show_in_default>
147
+ <show_in_website>1</show_in_website>
148
+ <show_in_store>0</show_in_store>
149
+ </guests>
150
+ </fields>
151
+ </address_book>
152
+ <sync translate="label" module="connector">
153
+ <label>Sync</label>
154
+ <frontend_type>text</frontend_type>
155
+ <sort_order>20</sort_order>
156
+ <show_in_default>1</show_in_default>
157
+ <show_in_website>1</show_in_website>
158
+ <show_in_store>0</show_in_store>
159
+ <expanded>1</expanded>
160
+ <fields>
161
+ <contact_title translate="label" module="connector">
162
+ <label>Contact Sync</label>
163
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
164
+ <sort_order>10</sort_order>
165
+ <show_in_default>1</show_in_default>
166
+ <show_in_website>1</show_in_website>
167
+ <show_in_store>0</show_in_store>
168
+ </contact_title>
169
+ <contact_enabled translate="label" module="connector">
170
+ <label>Enabled</label>
171
+ <frontend_type>select</frontend_type>
172
+ <source_model>adminhtml/system_config_source_yesno</source_model>
173
+ <sort_order>20</sort_order>
174
+ <show_in_default>1</show_in_default>
175
+ <show_in_website>1</show_in_website>
176
+ <show_in_store>0</show_in_store>
177
+ </contact_enabled>
178
+ <subscriber_title translate="label" module="connector">
179
+ <label>Subscriber Sync</label>
180
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
181
+ <sort_order>50</sort_order>
182
+ <show_in_default>1</show_in_default>
183
+ <show_in_website>1</show_in_website>
184
+ <show_in_store>0</show_in_store>
185
+ </subscriber_title>
186
+ <subscriber_enabled translate="label" module="connector">
187
+ <label>Enabled</label>
188
+ <frontend_type>select</frontend_type>
189
+ <source_model>adminhtml/system_config_source_yesno</source_model>
190
+ <sort_order>60</sort_order>
191
+ <show_in_default>1</show_in_default>
192
+ <show_in_website>1</show_in_website>
193
+ <show_in_store>0</show_in_store>
194
+ </subscriber_enabled>
195
+ <order_title translate="label" module="connector">
196
+ <label>Order Sync</label>
197
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
198
+ <sort_order>70</sort_order>
199
+ <show_in_default>1</show_in_default>
200
+ <show_in_website>1</show_in_website>
201
+ <show_in_store>0</show_in_store>
202
+ </order_title>
203
+ <order_enabled translate="label" module="connector">
204
+ <label>Enabled</label>
205
+ <frontend_type>select</frontend_type>
206
+ <source_model>adminhtml/system_config_source_yesno</source_model>
207
+ <sort_order>80</sort_order>
208
+ <show_in_default>1</show_in_default>
209
+ <show_in_website>1</show_in_website>
210
+ <show_in_store>0</show_in_store>
211
+ </order_enabled>
212
+ <wishlist_title translate="label" module="connector">
213
+ <label>Wishlist Sync</label>
214
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
215
+ <sort_order>90</sort_order>
216
+ <show_in_default>1</show_in_default>
217
+ <show_in_website>1</show_in_website>
218
+ <show_in_store>0</show_in_store>
219
+ </wishlist_title>
220
+ <wishlist_enabled translate="label" module="connector">
221
+ <label>Enabled</label>
222
+ <frontend_type>select</frontend_type>
223
+ <source_model>adminhtml/system_config_source_yesno</source_model>
224
+ <sort_order>100</sort_order>
225
+ <show_in_default>1</show_in_default>
226
+ <show_in_website>1</show_in_website>
227
+ <show_in_store>0</show_in_store>
228
+ </wishlist_enabled>
229
+ <validator>
230
+ <frontend_type>hidden</frontend_type>
231
+ <frontend_model>email_connector/adminhtml_system_config_waitingfield</frontend_model>
232
+ <sort_order>110</sort_order>
233
+ <show_in_default>1</show_in_default>
234
+ <show_in_website>1</show_in_website>
235
+ <show_in_store>0</show_in_store>
236
+ <can_be_empty>1</can_be_empty>
237
+ </validator>
238
+ </fields>
239
+ </sync>
240
+ <dynamic_addressbook translate="label" module="connector">
241
+ <label>Create Address Book</label>
242
+ <sort_order>30</sort_order>
243
+ <show_in_default>1</show_in_default>
244
+ <show_in_website>1</show_in_website>
245
+ <show_in_store>0</show_in_store>
246
+ <fields>
247
+ <addressbook_name translate="label" module="connector">
248
+ <label>Address Book Name</label>
249
+ <frontend_type>text</frontend_type>
250
+ <frontend_model>email_connector/adminhtml_system_config_addressbook</frontend_model>
251
+ <sort_order>10</sort_order>
252
+ <show_in_default>1</show_in_default>
253
+ <show_in_website>1</show_in_website>
254
+ <show_in_store>0</show_in_store>
255
+ </addressbook_name>
256
+ <addresbook_button translate="label button_label" module="connector">
257
+ <label />
258
+ <button_label>Create New Address Book</button_label>
259
+ <frontend_model>email_connector/adminhtml_system_dynamic_addressbookbutton</frontend_model>
260
+ <sort_order>30</sort_order>
261
+ <show_in_default>1</show_in_default>
262
+ <show_in_website>1</show_in_website>
263
+ <show_in_store>0</show_in_store>
264
+ </addresbook_button>
265
+ </fields>
266
+ </dynamic_addressbook>
267
+ </groups>
268
+ </connector_sync_settings>
269
+ <connector_data_mapping translate="label" module="connector">
270
+ <label><![CDATA[Data Mapping]]></label>
271
+ <tab>connector</tab>
272
+ <frontend_type>text</frontend_type>
273
+ <sort_order>2000</sort_order>
274
+ <show_in_default>1</show_in_default>
275
+ <show_in_website>1</show_in_website>
276
+ <show_in_store>0</show_in_store>
277
+ <groups>
278
+ <customer_data translate="label" module="connector">
279
+ <label>Data Fields Mapping</label>
280
+ <frontend_type>text</frontend_type>
281
+ <sort_order>20</sort_order>
282
+ <show_in_default>1</show_in_default>
283
+ <show_in_website>1</show_in_website>
284
+ <show_in_store>0</show_in_store>
285
+ <expanded>1</expanded>
286
+ <comment><![CDATA[<p class="notice">AUTOMAP AVAILABLE IN ADVANCED SECTION TO MAP ALL DATAFIELDS.</p>]]></comment>
287
+ <fields>
288
+ <customer_title translate="label" module="connector">
289
+ <label>Customer Information</label>
290
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
291
+ <sort_order>10</sort_order>
292
+ <show_in_default>1</show_in_default>
293
+ <show_in_website>1</show_in_website>
294
+ <show_in_store>0</show_in_store>
295
+ </customer_title>
296
+ <title translate="label" module="connector">
297
+ <label>Title</label>
298
+ <frontend_type>select</frontend_type>
299
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
300
+ <sort_order>20</sort_order>
301
+ <show_in_default>1</show_in_default>
302
+ <show_in_website>1</show_in_website>
303
+ <show_in_store>0</show_in_store>
304
+ </title>
305
+ <customer_id translate="label" module="connector">
306
+ <label>Customer ID</label>
307
+ <frontend_type>select</frontend_type>
308
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
309
+ <sort_order>30</sort_order>
310
+ <show_in_default>1</show_in_default>
311
+ <show_in_website>1</show_in_website>
312
+ <show_in_store>0</show_in_store>
313
+ </customer_id>
314
+ <firstname translate="label" module="connector">
315
+ <label>First Name</label>
316
+ <frontend_type>select</frontend_type>
317
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
318
+ <sort_order>40</sort_order>
319
+ <show_in_default>1</show_in_default>
320
+ <show_in_website>1</show_in_website>
321
+ <show_in_store>0</show_in_store>
322
+ </firstname>
323
+ <lastname translate="label" module="connector">
324
+ <label>Last Name</label>
325
+ <frontend_type>select</frontend_type>
326
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
327
+ <sort_order>50</sort_order>
328
+ <show_in_default>1</show_in_default>
329
+ <show_in_website>1</show_in_website>
330
+ <show_in_store>0</show_in_store>
331
+ </lastname>
332
+ <dob translate="label" module="connector">
333
+ <label>D.O.B.</label>
334
+ <frontend_type>select</frontend_type>
335
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
336
+ <sort_order>60</sort_order>
337
+ <show_in_default>1</show_in_default>
338
+ <show_in_website>1</show_in_website>
339
+ <show_in_store>0</show_in_store>
340
+ </dob>
341
+ <gender translate="label" module="connector">
342
+ <label>Gender</label>
343
+ <frontend_type>select</frontend_type>
344
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
345
+ <sort_order>70</sort_order>
346
+ <show_in_default>1</show_in_default>
347
+ <show_in_website>1</show_in_website>
348
+ <show_in_store>0</show_in_store>
349
+ </gender>
350
+ <website_name translate="label" module="connector">
351
+ <label>Website Created On</label>
352
+ <frontend_type>select</frontend_type>
353
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
354
+ <sort_order>80</sort_order>
355
+ <show_in_default>1</show_in_default>
356
+ <show_in_website>1</show_in_website>
357
+ <show_in_store>0</show_in_store>
358
+ </website_name>
359
+ <store_name translate="label" module="connector">
360
+ <label>Store Created On</label>
361
+ <frontend_type>select</frontend_type>
362
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
363
+ <sort_order>90</sort_order>
364
+ <show_in_default>1</show_in_default>
365
+ <show_in_website>1</show_in_website>
366
+ <show_in_store>0</show_in_store>
367
+ </store_name>
368
+ <created_at translate="label" module="connector">
369
+ <label>Account Created Date</label>
370
+ <frontend_type>select</frontend_type>
371
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
372
+ <sort_order>100</sort_order>
373
+ <show_in_default>1</show_in_default>
374
+ <show_in_website>1</show_in_website>
375
+ <show_in_store>0</show_in_store>
376
+ </created_at>
377
+ <last_logged_date translate="label" module="connector">
378
+ <label>Last Logged In Date</label>
379
+ <frontend_type>select</frontend_type>
380
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
381
+ <sort_order>110</sort_order>
382
+ <show_in_default>1</show_in_default>
383
+ <show_in_website>1</show_in_website>
384
+ <show_in_store>0</show_in_store>
385
+ </last_logged_date>
386
+ <customer_group translate="label" module="connector">
387
+ <label>Customer Group</label>
388
+ <frontend_type>select</frontend_type>
389
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
390
+ <sort_order>120</sort_order>
391
+ <show_in_default>1</show_in_default>
392
+ <show_in_website>1</show_in_website>
393
+ <show_in_store>0</show_in_store>
394
+ </customer_group>
395
+ <review_count translate="label" module="connector">
396
+ <label>Customer Review Count</label>
397
+ <frontend_type>select</frontend_type>
398
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
399
+ <sort_order>121</sort_order>
400
+ <show_in_default>1</show_in_default>
401
+ <show_in_website>1</show_in_website>
402
+ <show_in_store>0</show_in_store>
403
+ </review_count>
404
+ <last_review_date translate="label" module="connector">
405
+ <label>Last Review Date</label>
406
+ <frontend_type>select</frontend_type>
407
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
408
+ <sort_order>122</sort_order>
409
+ <show_in_default>1</show_in_default>
410
+ <show_in_website>1</show_in_website>
411
+ <show_in_store>0</show_in_store>
412
+ </last_review_date>
413
+ <address_title translate="label" module="connector">
414
+ <label>Address</label>
415
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
416
+ <sort_order>130</sort_order>
417
+ <show_in_default>1</show_in_default>
418
+ <show_in_website>1</show_in_website>
419
+ <show_in_store>0</show_in_store>
420
+ </address_title>
421
+ <billing_address_1 translate="label" module="connector">
422
+ <label>Billing Address Line 1</label>
423
+ <frontend_type>select</frontend_type>
424
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
425
+ <sort_order>140</sort_order>
426
+ <show_in_default>1</show_in_default>
427
+ <show_in_website>1</show_in_website>
428
+ <show_in_store>0</show_in_store>
429
+ </billing_address_1>
430
+ <billing_address_2 translate="label" module="connector">
431
+ <label>Billing Address Line 2</label>
432
+ <frontend_type>select</frontend_type>
433
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
434
+ <sort_order>150</sort_order>
435
+ <show_in_default>1</show_in_default>
436
+ <show_in_website>1</show_in_website>
437
+ <show_in_store>0</show_in_store>
438
+ </billing_address_2>
439
+ <billing_city translate="label" module="connector">
440
+ <label>Billing City</label>
441
+ <frontend_type>select</frontend_type>
442
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
443
+ <sort_order>160</sort_order>
444
+ <show_in_default>1</show_in_default>
445
+ <show_in_website>1</show_in_website>
446
+ <show_in_store>0</show_in_store>
447
+ </billing_city>
448
+ <billing_state translate="label" module="connector">
449
+ <label>Billing State/Region</label>
450
+ <frontend_type>select</frontend_type>
451
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
452
+ <sort_order>155</sort_order>
453
+ <show_in_default>1</show_in_default>
454
+ <show_in_website>1</show_in_website>
455
+ <show_in_store>0</show_in_store>
456
+ </billing_state>
457
+ <billing_country translate="label" module="connector">
458
+ <label>Billing Country</label>
459
+ <frontend_type>select</frontend_type>
460
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
461
+ <sort_order>170</sort_order>
462
+ <show_in_default>1</show_in_default>
463
+ <show_in_website>1</show_in_website>
464
+ <show_in_store>0</show_in_store>
465
+ </billing_country>
466
+ <billing_postcode translate="label" module="connector">
467
+ <label>Billing Zip/Postcode</label>
468
+ <frontend_type>select</frontend_type>
469
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
470
+ <sort_order>180</sort_order>
471
+ <show_in_default>1</show_in_default>
472
+ <show_in_website>1</show_in_website>
473
+ <show_in_store>0</show_in_store>
474
+ </billing_postcode>
475
+ <billing_telephone translate="label" module="connector">
476
+ <label>Billing Telephone</label>
477
+ <frontend_type>select</frontend_type>
478
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
479
+ <sort_order>190</sort_order>
480
+ <show_in_default>1</show_in_default>
481
+ <show_in_website>1</show_in_website>
482
+ <show_in_store>0</show_in_store>
483
+ </billing_telephone>
484
+ <delivery_address_1 translate="label" module="connector">
485
+ <label>Delivery Address Line 1</label>
486
+ <frontend_type>select</frontend_type>
487
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
488
+ <sort_order>200</sort_order>
489
+ <show_in_default>1</show_in_default>
490
+ <show_in_website>1</show_in_website>
491
+ <show_in_store>0</show_in_store>
492
+ </delivery_address_1>
493
+ <delivery_address_2 translate="label" module="connector">
494
+ <label>Delivery Address Line 2</label>
495
+ <frontend_type>select</frontend_type>
496
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
497
+ <sort_order>210</sort_order>
498
+ <show_in_default>1</show_in_default>
499
+ <show_in_website>1</show_in_website>
500
+ <show_in_store>0</show_in_store>
501
+ </delivery_address_2>
502
+ <delivery_city translate="label" module="connector">
503
+ <label>Delivery City</label>
504
+ <frontend_type>select</frontend_type>
505
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
506
+ <sort_order>220</sort_order>
507
+ <show_in_default>1</show_in_default>
508
+ <show_in_website>1</show_in_website>
509
+ <show_in_store>0</show_in_store>
510
+ </delivery_city>
511
+ <delivery_state translate="label" module="connector">
512
+ <label>Delivery State/Region</label>
513
+ <frontend_type>select</frontend_type>
514
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
515
+ <sort_order>215</sort_order>
516
+ <show_in_default>1</show_in_default>
517
+ <show_in_website>1</show_in_website>
518
+ <show_in_store>0</show_in_store>
519
+ </delivery_state>
520
+ <delivery_country translate="label" module="connector">
521
+ <label>Delivery Country</label>
522
+ <frontend_type>select</frontend_type>
523
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
524
+ <sort_order>230</sort_order>
525
+ <show_in_default>1</show_in_default>
526
+ <show_in_website>1</show_in_website>
527
+ <show_in_store>0</show_in_store>
528
+ </delivery_country>
529
+ <delivery_postcode translate="label" module="connector">
530
+ <label>Delivery Zip/Postcode</label>
531
+ <frontend_type>select</frontend_type>
532
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
533
+ <sort_order>240</sort_order>
534
+ <show_in_default>1</show_in_default>
535
+ <show_in_website>1</show_in_website>
536
+ <show_in_store>0</show_in_store>
537
+ </delivery_postcode>
538
+ <delivery_telephone translate="label" module="connector">
539
+ <label>Delivery Telephone</label>
540
+ <frontend_type>select</frontend_type>
541
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
542
+ <sort_order>250</sort_order>
543
+ <show_in_default>1</show_in_default>
544
+ <show_in_website>1</show_in_website>
545
+ <show_in_store>0</show_in_store>
546
+ </delivery_telephone>
547
+ <sales_title translate="label" module="connector">
548
+ <label>Sales</label>
549
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
550
+ <sort_order>260</sort_order>
551
+ <show_in_default>1</show_in_default>
552
+ <show_in_website>1</show_in_website>
553
+ <show_in_store>0</show_in_store>
554
+ </sales_title>
555
+ <number_of_orders translate="label" module="connector">
556
+ <label>Total Number of Orders</label>
557
+ <frontend_type>select</frontend_type>
558
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
559
+ <sort_order>270</sort_order>
560
+ <show_in_default>1</show_in_default>
561
+ <show_in_website>1</show_in_website>
562
+ <show_in_store>0</show_in_store>
563
+ </number_of_orders>
564
+ <average_order_value translate="label" module="connector">
565
+ <label>Average Order Value</label>
566
+ <frontend_type>select</frontend_type>
567
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
568
+ <sort_order>280</sort_order>
569
+ <show_in_default>1</show_in_default>
570
+ <show_in_website>1</show_in_website>
571
+ <show_in_store>0</show_in_store>
572
+ </average_order_value>
573
+ <total_spend translate="label" module="connector">
574
+ <label>Total Spend</label>
575
+ <frontend_type>select</frontend_type>
576
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
577
+ <sort_order>290</sort_order>
578
+ <show_in_default>1</show_in_default>
579
+ <show_in_website>1</show_in_website>
580
+ <show_in_store>0</show_in_store>
581
+ </total_spend>
582
+ <last_order_date translate="label" module="connector">
583
+ <label>Last Purchase Date</label>
584
+ <frontend_type>select</frontend_type>
585
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
586
+ <sort_order>300</sort_order>
587
+ <show_in_default>1</show_in_default>
588
+ <show_in_website>1</show_in_website>
589
+ <show_in_store>0</show_in_store>
590
+ </last_order_date>
591
+ <last_order_id translate="label" module="connector">
592
+ <label>Last Order ID</label>
593
+ <frontend_type>select</frontend_type>
594
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
595
+ <sort_order>310</sort_order>
596
+ <show_in_default>1</show_in_default>
597
+ <show_in_website>1</show_in_website>
598
+ <show_in_store>0</show_in_store>
599
+ </last_order_id>
600
+ <total_refund translate="label">
601
+ <label>Total Refund</label>
602
+ <frontend_type>select</frontend_type>
603
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
604
+ <show_in_default>1</show_in_default>
605
+ <show_in_website>1</show_in_website>
606
+ <show_in_store>0</show_in_store>
607
+ <sort_order>320</sort_order>
608
+ <comment>Include total refunded ammount for customer.</comment>
609
+ </total_refund>
610
+ <custom_title translate="label" module="connector">
611
+ <label>Custom Attributes</label>
612
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
613
+ <sort_order>330</sort_order>
614
+ <show_in_default>1</show_in_default>
615
+ <show_in_website>1</show_in_website>
616
+ <show_in_store>0</show_in_store>
617
+ </custom_title>
618
+ <custom_attributes translate="label" module="connector">
619
+ <label>Customer</label>
620
+ <frontend_model>email_connector/adminhtml_config_customdatafields</frontend_model>
621
+ <backend_model>adminhtml/system_config_backend_serialized_array</backend_model>
622
+ <source_model>email_connector/adminhtml_source_customer_attributes_select</source_model>
623
+ <sort_order>340</sort_order>
624
+ <show_in_default>1</show_in_default>
625
+ <show_in_website>1</show_in_website>
626
+ <show_in_store>0</show_in_store>
627
+ </custom_attributes>
628
+ <validator translate="label" module="connector">
629
+ <label>Validation Block</label>
630
+ <frontend_type>select</frontend_type>
631
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
632
+ <frontend_model>email_connector/adminhtml_system_config_validator</frontend_model>
633
+ <sort_order>920</sort_order>
634
+ <show_in_default>1</show_in_default>
635
+ <show_in_website>1</show_in_website>
636
+ <show_in_store>0</show_in_store>
637
+ <can_be_empty>1</can_be_empty>
638
+ <expanded>1</expanded>
639
+ </validator>
640
+ </fields>
641
+ </customer_data>
642
+ <dynamic_datafield translate="label" module="connector">
643
+ <label>Create Data Field</label>
644
+ <sort_order>30</sort_order>
645
+ <show_in_default>1</show_in_default>
646
+ <show_in_website>1</show_in_website>
647
+ <show_in_store>0</show_in_store>
648
+ <fields>
649
+ <datafield_name translate="label comment" module="connector">
650
+ <label>Data Field Name</label>
651
+ <frontend_type>text</frontend_type>
652
+ <frontend_model>email_connector/adminhtml_system_config_datafield</frontend_model>
653
+ <sort_order>10</sort_order>
654
+ <show_in_default>1</show_in_default>
655
+ <show_in_website>1</show_in_website>
656
+ <show_in_store>0</show_in_store>
657
+ <comment>(Maximum of 20 characters)</comment>
658
+ </datafield_name>
659
+ <datafield_type translate="label" module="connector">
660
+ <label>Data Field Type</label>
661
+ <frontend_type>select</frontend_type>
662
+ <source_model>email_connector/adminhtml_source_datamapping_datafieldtype</source_model>
663
+ <sort_order>20</sort_order>
664
+ <show_in_default>1</show_in_default>
665
+ <show_in_website>1</show_in_website>
666
+ <show_in_store>0</show_in_store>
667
+ <expended>1</expended>
668
+ </datafield_type>
669
+ <datafield_default translate="label" module="connector">
670
+ <label>Default Value</label>
671
+ <frontend_type>text</frontend_type>
672
+ <sort_order>30</sort_order>
673
+ <show_in_default>1</show_in_default>
674
+ <show_in_website>1</show_in_website>
675
+ <show_in_store>0</show_in_store>
676
+ <comment>When sending a campaign that uses template personalisation, a default value ensures that a value is alwasy displayed even if a data field is blank.</comment>
677
+ </datafield_default>
678
+ <datafield_access translate="label" module="connector">
679
+ <label>Access</label>
680
+ <frontend_type>select</frontend_type>
681
+ <source_model>email_connector/adminhtml_source_datamapping_datafieldaccess</source_model>
682
+ <sort_order>40</sort_order>
683
+ <show_in_default>1</show_in_default>
684
+ <show_in_website>1</show_in_website>
685
+ <show_in_store>0</show_in_store>
686
+ <comment>Make the field pubclic if you want to allow your contacts to view and amends the data you hold on them in this field.</comment>
687
+ </datafield_access>
688
+ <datafield_button translate="label button_label" module="connector">
689
+ <label />
690
+ <button_label>Create New Data Field</button_label>
691
+ <frontend_model>email_connector/adminhtml_system_dynamic_datafieldbutton</frontend_model>
692
+ <sort_order>50</sort_order>
693
+ <show_in_default>1</show_in_default>
694
+ <show_in_website>1</show_in_website>
695
+ <show_in_store>0</show_in_store>
696
+ </datafield_button>
697
+ </fields>
698
+ </dynamic_datafield>
699
+ <sweet_tooth>
700
+ <label>Sweet Tooth Rewards</label>
701
+ <sort_order>40</sort_order>
702
+ <show_in_default>1</show_in_default>
703
+ <show_in_website>1</show_in_website>
704
+ <show_in_store>0</show_in_store>
705
+ <fields>
706
+ <active translate="label" module="connector">
707
+ <label>Enabled</label>
708
+ <frontend_type>select</frontend_type>
709
+ <source_model>email_connector/adminhtml_source_sweettooth_yesno</source_model>
710
+ <sort_order>0</sort_order>
711
+ <show_in_default>1</show_in_default>
712
+ <show_in_website>1</show_in_website>
713
+ <show_in_store>0</show_in_store>
714
+ <comment><![CDATA[<p id="sweet-tooth-warning" style="display:none;" class="notice">SWEET TOOTH EXTENSION HAS TO BE INSTALLED AND ENABLED IN ORDER TO USE THIS FEATURE.</p>]]></comment>
715
+ </active>
716
+ <title translate="label" module="connector">
717
+ <label>Data Fields Mapping</label>
718
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
719
+ <sort_order>10</sort_order>
720
+ <show_in_default>1</show_in_default>
721
+ <show_in_website>1</show_in_website>
722
+ <show_in_store>0</show_in_store>
723
+ <depends><active>1</active></depends>
724
+ </title>
725
+ <reward_point_balance translate="label" module="connector">
726
+ <label>Current Point Balance</label>
727
+ <frontend_type>select</frontend_type>
728
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
729
+ <sort_order>20</sort_order>
730
+ <show_in_default>1</show_in_default>
731
+ <show_in_website>1</show_in_website>
732
+ <show_in_store>0</show_in_store>
733
+ <depends><active>1</active></depends>
734
+ </reward_point_balance>
735
+ <reward_point_pending translate="label" module="connector">
736
+ <label>Points Pending An Event</label>
737
+ <frontend_type>select</frontend_type>
738
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
739
+ <sort_order>30</sort_order>
740
+ <show_in_default>1</show_in_default>
741
+ <show_in_website>1</show_in_website>
742
+ <show_in_store>0</show_in_store>
743
+ <depends><active>1</active></depends>
744
+ </reward_point_pending>
745
+ <reward_point_pending_time translate="label" module="connector">
746
+ <label>Points Pending A Date</label>
747
+ <frontend_type>select</frontend_type>
748
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
749
+ <sort_order>40</sort_order>
750
+ <show_in_default>1</show_in_default>
751
+ <show_in_website>1</show_in_website>
752
+ <show_in_store>0</show_in_store>
753
+ <depends><active>1</active></depends>
754
+ </reward_point_pending_time>
755
+ <reward_point_on_hold translate="label" module="connector">
756
+ <label>Current On Hold Points</label>
757
+ <frontend_type>select</frontend_type>
758
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
759
+ <sort_order>50</sort_order>
760
+ <show_in_default>1</show_in_default>
761
+ <show_in_website>1</show_in_website>
762
+ <show_in_store>0</show_in_store>
763
+ <depends><active>1</active></depends>
764
+ </reward_point_on_hold>
765
+ <reward_point_expiration translate="label" module="connector">
766
+ <label>Points Expiry Date</label>
767
+ <frontend_type>select</frontend_type>
768
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
769
+ <sort_order>60</sort_order>
770
+ <show_in_default>1</show_in_default>
771
+ <show_in_website>1</show_in_website>
772
+ <show_in_store>0</show_in_store>
773
+ <depends><active>1</active></depends>
774
+ </reward_point_expiration>
775
+ <reward_point_last_earn translate="label" module="connector">
776
+ <label>Last Date Points Earned</label>
777
+ <frontend_type>select</frontend_type>
778
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
779
+ <sort_order>70</sort_order>
780
+ <show_in_default>1</show_in_default>
781
+ <show_in_website>1</show_in_website>
782
+ <show_in_store>0</show_in_store>
783
+ <depends><active>1</active></depends>
784
+ </reward_point_last_earn>
785
+ <reward_point_last_spent translate="label" module="connector">
786
+ <label>Last Date Points Spent</label>
787
+ <frontend_type>select</frontend_type>
788
+ <source_model>email_connector/adminhtml_source_datafields</source_model>
789
+ <sort_order>70</sort_order>
790
+ <show_in_default>1</show_in_default>
791
+ <show_in_website>1</show_in_website>
792
+ <show_in_store>0</show_in_store>
793
+ <depends><active>1</active></depends>
794
+ </reward_point_last_spent>
795
+ </fields>
796
+ </sweet_tooth>
797
+ </groups>
798
+ </connector_data_mapping>
799
+ <connector_roi_tracking translate="label" module="connector">
800
+ <label><![CDATA[ROI & Tracking]]></label>
801
+ <tab>connector</tab>
802
+ <frontend_type>text</frontend_type>
803
+ <sort_order>4000</sort_order>
804
+ <show_in_default>1</show_in_default>
805
+ <show_in_website>1</show_in_website>
806
+ <show_in_store>0</show_in_store>
807
+ <groups>
808
+ <page_tracking translate="label" module="connector">
809
+ <label>Page Tracking</label>
810
+ <frontend_type>text</frontend_type>
811
+ <sort_order>10</sort_order>
812
+ <show_in_default>1</show_in_default>
813
+ <show_in_website>1</show_in_website>
814
+ <show_in_store>0</show_in_store>
815
+ <expanded>1</expanded>
816
+ <fields>
817
+ <enabled translate="label" module="connector">
818
+ <label>Enabled</label>
819
+ <frontend_type>select</frontend_type>
820
+ <source_model>adminhtml/system_config_source_yesno</source_model>
821
+ <sort_order>10</sort_order>
822
+ <show_in_default>1</show_in_default>
823
+ <show_in_website>1</show_in_website>
824
+ <show_in_store>0</show_in_store>
825
+ </enabled>
826
+ </fields>
827
+ </page_tracking>
828
+ <roi_tracking translate="label" module="connector">
829
+ <label>ROI Tracking</label>
830
+ <frontend_type>text</frontend_type>
831
+ <sort_order>20</sort_order>
832
+ <show_in_default>1</show_in_default>
833
+ <show_in_website>1</show_in_website>
834
+ <show_in_store>0</show_in_store>
835
+ <expanded>1</expanded>
836
+ <fields>
837
+ <enabled translate="label" module="connector">
838
+ <label>Enabled</label>
839
+ <frontend_type>select</frontend_type>
840
+ <source_model>adminhtml/system_config_source_yesno</source_model>
841
+ <sort_order>10</sort_order>
842
+ <show_in_default>1</show_in_default>
843
+ <show_in_website>1</show_in_website>
844
+ <show_in_store>0</show_in_store>
845
+ </enabled>
846
+ </fields>
847
+ </roi_tracking>
848
+ </groups>
849
+ </connector_roi_tracking>
850
+ <connector_lost_baskets translate="label" module="connector">
851
+ <label><![CDATA[Abandoned Carts]]></label>
852
+ <tab>connector</tab>
853
+ <frontend_type>text</frontend_type>
854
+ <sort_order>6000</sort_order>
855
+ <show_in_default>1</show_in_default>
856
+ <show_in_website>1</show_in_website>
857
+ <show_in_store>0</show_in_store>
858
+ <groups>
859
+ <customers translate="label" module="connector">
860
+ <label>Customers</label>
861
+ <frontend_type>text</frontend_type>
862
+ <sort_order>10</sort_order>
863
+ <show_in_default>1</show_in_default>
864
+ <show_in_website>1</show_in_website>
865
+ <show_in_store>1</show_in_store>
866
+ <expanded>1</expanded>
867
+ <fields>
868
+ <heading_1 translate="label" module="connector">
869
+ <label>Abandoned Cart 1</label>
870
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
871
+ <sort_order>10</sort_order>
872
+ <show_in_default>1</show_in_default>
873
+ <show_in_website>1</show_in_website>
874
+ <show_in_store>1</show_in_store>
875
+ </heading_1>
876
+ <enabled_1 translate="label" module="connector">
877
+ <label>Enabled/Disabled</label>
878
+ <frontend_type>select</frontend_type>
879
+ <source_model>adminhtml/system_config_source_enabledisable</source_model>
880
+ <sort_order>20</sort_order>
881
+ <show_in_default>1</show_in_default>
882
+ <show_in_website>1</show_in_website>
883
+ <show_in_store>1</show_in_store>
884
+ </enabled_1>
885
+ <send_after_1 translate="label" module="connector">
886
+ <label>Send After (min)</label>
887
+ <frontend_type>select</frontend_type>
888
+ <source_model>email_connector/adminhtml_source_lostbaskets_intervalminute</source_model>
889
+ <sort_order>30</sort_order>
890
+ <show_in_default>1</show_in_default>
891
+ <show_in_website>1</show_in_website>
892
+ <show_in_store>1</show_in_store>
893
+ </send_after_1>
894
+ <campaign_1 translate="label" module="connector">
895
+ <label>Campaign To Send</label>
896
+ <frontend_type>select</frontend_type>
897
+ <source_model>email_connector/adminhtml_source_campaigns</source_model>
898
+ <sort_order>40</sort_order>
899
+ <show_in_default>1</show_in_default>
900
+ <show_in_website>1</show_in_website>
901
+ <show_in_store>1</show_in_store>
902
+ </campaign_1>
903
+ <heading_2 translate="label" module="connector">
904
+ <label>Abandoned Cart 2</label>
905
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
906
+ <sort_order>50</sort_order>
907
+ <show_in_default>1</show_in_default>
908
+ <show_in_website>1</show_in_website>
909
+ <show_in_store>1</show_in_store>
910
+ </heading_2>
911
+ <enabled_2 translate="label" module="connector">
912
+ <label>Enabled/Disabled</label>
913
+ <frontend_type>select</frontend_type>
914
+ <source_model>adminhtml/system_config_source_enabledisable</source_model>
915
+ <sort_order>60</sort_order>
916
+ <show_in_default>1</show_in_default>
917
+ <show_in_website>1</show_in_website>
918
+ <show_in_store>1</show_in_store>
919
+ </enabled_2>
920
+ <send_after_2 translate="label" module="connector">
921
+ <label>Send After (hrs)</label>
922
+ <frontend_type>select</frontend_type>
923
+ <source_model>email_connector/adminhtml_source_lostbaskets_interval</source_model>
924
+ <sort_order>70</sort_order>
925
+ <show_in_default>1</show_in_default>
926
+ <show_in_website>1</show_in_website>
927
+ <show_in_store>1</show_in_store>
928
+ </send_after_2>
929
+ <campaign_2 translate="label" module="connector">
930
+ <label>Campaign To Send</label>
931
+ <frontend_type>select</frontend_type>
932
+ <source_model>email_connector/adminhtml_source_campaigns</source_model>
933
+ <sort_order>80</sort_order>
934
+ <show_in_default>1</show_in_default>
935
+ <show_in_website>1</show_in_website>
936
+ <show_in_store>1</show_in_store>
937
+ </campaign_2>
938
+ <heading_3 translate="label" module="connector">
939
+ <label>Abandoned Cart 3</label>
940
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
941
+ <sort_order>90</sort_order>
942
+ <show_in_default>1</show_in_default>
943
+ <show_in_website>1</show_in_website>
944
+ <show_in_store>1</show_in_store>
945
+ </heading_3>
946
+ <enabled_3 translate="label" module="connector">
947
+ <label>Enabled/Disabled</label>
948
+ <frontend_type>select</frontend_type>
949
+ <source_model>adminhtml/system_config_source_enabledisable</source_model>
950
+ <sort_order>100</sort_order>
951
+ <show_in_default>1</show_in_default>
952
+ <show_in_website>1</show_in_website>
953
+ <show_in_store>1</show_in_store>
954
+ </enabled_3>
955
+ <send_after_3 translate="label" module="connector">
956
+ <label>Send After (hrs)</label>
957
+ <frontend_type>select</frontend_type>
958
+ <source_model>email_connector/adminhtml_source_lostbaskets_interval</source_model>
959
+ <sort_order>110</sort_order>
960
+ <show_in_default>1</show_in_default>
961
+ <show_in_website>1</show_in_website>
962
+ <show_in_store>1</show_in_store>
963
+ </send_after_3>
964
+ <campaign_3 translate="label" module="connector">
965
+ <label>Campaign To Send</label>
966
+ <frontend_type>select</frontend_type>
967
+ <source_model>email_connector/adminhtml_source_campaigns</source_model>
968
+ <sort_order>120</sort_order>
969
+ <show_in_default>1</show_in_default>
970
+ <show_in_website>1</show_in_website>
971
+ <show_in_store>1</show_in_store>
972
+ </campaign_3>
973
+ </fields>
974
+ </customers>
975
+ <guests translate="label" module="connector">
976
+ <label>Guests</label>
977
+ <frontend_type>text</frontend_type>
978
+ <sort_order>20</sort_order>
979
+ <show_in_default>1</show_in_default>
980
+ <show_in_website>1</show_in_website>
981
+ <show_in_store>0</show_in_store>
982
+ <fields>
983
+ <heading_1 translate="label" module="connector">
984
+ <label>Abandoned Cart 1</label>
985
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
986
+ <sort_order>10</sort_order>
987
+ <show_in_default>1</show_in_default>
988
+ <show_in_website>1</show_in_website>
989
+ <show_in_store>0</show_in_store>
990
+ </heading_1>
991
+ <enabled_1 translate="label" module="connector">
992
+ <label>Enabled/Disabled</label>
993
+ <frontend_type>select</frontend_type>
994
+ <source_model>adminhtml/system_config_source_enabledisable</source_model>
995
+ <sort_order>20</sort_order>
996
+ <show_in_default>1</show_in_default>
997
+ <show_in_website>1</show_in_website>
998
+ <show_in_store>0</show_in_store>
999
+ </enabled_1>
1000
+ <send_after_1 translate="label" module="connector">
1001
+ <label>Send After (min)</label>
1002
+ <frontend_type>select</frontend_type>
1003
+ <source_model>email_connector/adminhtml_source_lostbaskets_intervalminute</source_model>
1004
+ <sort_order>30</sort_order>
1005
+ <show_in_default>1</show_in_default>
1006
+ <show_in_website>1</show_in_website>
1007
+ <show_in_store>0</show_in_store>
1008
+ </send_after_1>
1009
+ <campaign_1 translate="label" module="connector">
1010
+ <label>Campaign To Send</label>
1011
+ <frontend_type>select</frontend_type>
1012
+ <source_model>email_connector/adminhtml_source_campaigns</source_model>
1013
+ <sort_order>40</sort_order>
1014
+ <show_in_default>1</show_in_default>
1015
+ <show_in_website>1</show_in_website>
1016
+ <show_in_store>0</show_in_store>
1017
+ </campaign_1>
1018
+ <heading_2 translate="label" module="connector">
1019
+ <label>Abandoned Cart 2</label>
1020
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
1021
+ <sort_order>50</sort_order>
1022
+ <show_in_default>1</show_in_default>
1023
+ <show_in_website>1</show_in_website>
1024
+ <show_in_store>0</show_in_store>
1025
+ </heading_2>
1026
+ <enabled_2 translate="label" module="connector">
1027
+ <label>Enabled/Disabled</label>
1028
+ <frontend_type>select</frontend_type>
1029
+ <source_model>adminhtml/system_config_source_enabledisable</source_model>
1030
+ <sort_order>60</sort_order>
1031
+ <show_in_default>1</show_in_default>
1032
+ <show_in_website>1</show_in_website>
1033
+ <show_in_store>0</show_in_store>
1034
+ </enabled_2>
1035
+ <send_after_2 translate="label" module="connector">
1036
+ <label>Send After (hrs)</label>
1037
+ <frontend_type>select</frontend_type>
1038
+ <source_model>email_connector/adminhtml_source_lostbaskets_interval</source_model>
1039
+ <sort_order>70</sort_order>
1040
+ <show_in_default>1</show_in_default>
1041
+ <show_in_website>1</show_in_website>
1042
+ <show_in_store>0</show_in_store>
1043
+ </send_after_2>
1044
+ <campaign_2 translate="label" module="connector">
1045
+ <label>Campaign To Send</label>
1046
+ <frontend_type>select</frontend_type>
1047
+ <source_model>email_connector/adminhtml_source_campaigns</source_model>
1048
+ <sort_order>80</sort_order>
1049
+ <show_in_default>1</show_in_default>
1050
+ <show_in_website>1</show_in_website>
1051
+ <show_in_store>0</show_in_store>
1052
+ </campaign_2>
1053
+ <heading_3 translate="label" module="connector">
1054
+ <label>Abandoned Cart 3</label>
1055
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
1056
+ <sort_order>90</sort_order>
1057
+ <show_in_default>1</show_in_default>
1058
+ <show_in_website>1</show_in_website>
1059
+ <show_in_store>0</show_in_store>
1060
+ </heading_3>
1061
+ <enabled_3 translate="label" module="connector">
1062
+ <label>Enabled/Disabled</label>
1063
+ <frontend_type>select</frontend_type>
1064
+ <source_model>adminhtml/system_config_source_enabledisable</source_model>
1065
+ <sort_order>100</sort_order>
1066
+ <show_in_default>1</show_in_default>
1067
+ <show_in_website>1</show_in_website>
1068
+ <show_in_store>0</show_in_store>
1069
+ </enabled_3>
1070
+ <send_after_3 translate="label" module="connector">
1071
+ <label>Send After (hrs)</label>
1072
+ <frontend_type>select</frontend_type>
1073
+ <source_model>email_connector/adminhtml_source_lostbaskets_interval</source_model>
1074
+ <sort_order>110</sort_order>
1075
+ <show_in_default>1</show_in_default>
1076
+ <show_in_website>1</show_in_website>
1077
+ <show_in_store>0</show_in_store>
1078
+ </send_after_3>
1079
+ <campaign_3 translate="label" module="connector">
1080
+ <label>Campaign To Send</label>
1081
+ <frontend_type>select</frontend_type>
1082
+ <source_model>email_connector/adminhtml_source_campaigns</source_model>
1083
+ <sort_order>120</sort_order>
1084
+ <show_in_default>1</show_in_default>
1085
+ <show_in_website>1</show_in_website>
1086
+ <show_in_store>0</show_in_store>
1087
+ </campaign_3>
1088
+ </fields>
1089
+ </guests>
1090
+ </groups>
1091
+ </connector_lost_baskets>
1092
+ <connector_sms translate="label" module="connector">
1093
+ <label><![CDATA[SMS]]></label>
1094
+ <tab>connector</tab>
1095
+ <frontend_type>text</frontend_type>
1096
+ <sort_order>7000</sort_order>
1097
+ <show_in_default>1</show_in_default>
1098
+ <show_in_website>1</show_in_website>
1099
+ <show_in_store>1</show_in_store>
1100
+ <groups>
1101
+ <sms_one translate="label" module="connector">
1102
+ <label>SMS Message 1</label>
1103
+ <frontend_type>text</frontend_type>
1104
+ <sort_order>10</sort_order>
1105
+ <show_in_default>1</show_in_default>
1106
+ <show_in_website>1</show_in_website>
1107
+ <show_in_store>1</show_in_store>
1108
+ <fields>
1109
+ <enabled translate="label" module="connector">
1110
+ <label>Enabled</label>
1111
+ <frontend_type>select</frontend_type>
1112
+ <source_model>adminhtml/system_config_source_yesno</source_model>
1113
+ <sort_order>10</sort_order>
1114
+ <show_in_default>1</show_in_default>
1115
+ <show_in_website>1</show_in_website>
1116
+ <show_in_store>1</show_in_store>
1117
+ </enabled>
1118
+ <status translate="label" module="connector">
1119
+ <label>Order Status</label>
1120
+ <sort_order>20</sort_order>
1121
+ <frontend_type>select</frontend_type>
1122
+ <source_model>adminhtml/system_config_source_order_status</source_model>
1123
+ <show_in_default>1</show_in_default>
1124
+ <show_in_website>1</show_in_website>
1125
+ <show_in_store>1</show_in_store>
1126
+ </status>
1127
+ <message translate="label" module="connector">
1128
+ <label>Message</label>
1129
+ <frontend_type>textarea</frontend_type>
1130
+ <frontend_model>email_connector/adminhtml_system_sms_smsmessageone</frontend_model>
1131
+ <sort_order>30</sort_order>
1132
+ <show_in_default>1</show_in_default>
1133
+ <show_in_website>1</show_in_website>
1134
+ <show_in_store>1</show_in_store>
1135
+ <validate>validate-length maximum-length-160</validate>
1136
+ </message>
1137
+ </fields>
1138
+ </sms_one>
1139
+ <sms_two translate="label" module="connector">
1140
+ <label>SMS Message 2</label>
1141
+ <frontend_type>text</frontend_type>
1142
+ <sort_order>20</sort_order>
1143
+ <show_in_default>1</show_in_default>
1144
+ <show_in_website>1</show_in_website>
1145
+ <show_in_store>1</show_in_store>
1146
+ <fields>
1147
+ <enabled translate="label" module="connector">
1148
+ <label>Enabled</label>
1149
+ <frontend_type>select</frontend_type>
1150
+ <source_model>adminhtml/system_config_source_yesno</source_model>
1151
+ <sort_order>10</sort_order>
1152
+ <show_in_default>1</show_in_default>
1153
+ <show_in_website>1</show_in_website>
1154
+ <show_in_store>1</show_in_store>
1155
+ </enabled>
1156
+ <status translate="label" module="connector">
1157
+ <label>Order Status</label>
1158
+ <sort_order>20</sort_order>
1159
+ <frontend_type>select</frontend_type>
1160
+ <source_model>adminhtml/system_config_source_order_status</source_model>
1161
+ <show_in_default>1</show_in_default>
1162
+ <show_in_website>1</show_in_website>
1163
+ <show_in_store>1</show_in_store>
1164
+ </status>
1165
+ <message translate="label" module="connector">
1166
+ <label>Message</label>
1167
+ <frontend_type>textarea</frontend_type>
1168
+ <frontend_model>email_connector/adminhtml_system_sms_smsmessagetwo</frontend_model>
1169
+ <sort_order>30</sort_order>
1170
+ <show_in_default>1</show_in_default>
1171
+ <show_in_website>1</show_in_website>
1172
+ <show_in_store>1</show_in_store>
1173
+ <validate>validate-length maximum-length-160</validate>
1174
+ </message>
1175
+ </fields>
1176
+ </sms_two>
1177
+ <sms_three translate="label" module="connector">
1178
+ <label>SMS Message 3</label>
1179
+ <frontend_type>text</frontend_type>
1180
+ <sort_order>30</sort_order>
1181
+ <show_in_default>1</show_in_default>
1182
+ <show_in_website>1</show_in_website>
1183
+ <show_in_store>1</show_in_store>
1184
+ <fields>
1185
+ <enabled translate="label" module="connector">
1186
+ <label>Enabled</label>
1187
+ <frontend_type>select</frontend_type>
1188
+ <source_model>adminhtml/system_config_source_yesno</source_model>
1189
+ <sort_order>10</sort_order>
1190
+ <show_in_default>1</show_in_default>
1191
+ <show_in_website>1</show_in_website>
1192
+ <show_in_store>1</show_in_store>
1193
+ </enabled>
1194
+ <status translate="label" module="connector">
1195
+ <label>Order Status</label>
1196
+ <sort_order>20</sort_order>
1197
+ <frontend_type>select</frontend_type>
1198
+ <source_model>adminhtml/system_config_source_order_status</source_model>
1199
+ <show_in_default>1</show_in_default>
1200
+ <show_in_website>1</show_in_website>
1201
+ <show_in_store>1</show_in_store>
1202
+ </status>
1203
+ <message translate="label" module="connector">
1204
+ <label>Message</label>
1205
+ <frontend_type>textarea</frontend_type>
1206
+ <frontend_model>email_connector/adminhtml_system_sms_smsmessagethree</frontend_model>
1207
+ <sort_order>30</sort_order>
1208
+ <show_in_default>1</show_in_default>
1209
+ <show_in_website>1</show_in_website>
1210
+ <show_in_store>1</show_in_store>
1211
+ <validate>validate-length maximum-length-160</validate>
1212
+ </message>
1213
+ </fields>
1214
+ </sms_three>
1215
+ <sms_four translate="label" module="connector">
1216
+ <label>SMS Message 4</label>
1217
+ <frontend_type>text</frontend_type>
1218
+ <sort_order>40</sort_order>
1219
+ <show_in_default>1</show_in_default>
1220
+ <show_in_website>1</show_in_website>
1221
+ <show_in_store>1</show_in_store>
1222
+ <fields>
1223
+ <enabled translate="label" module="connector">
1224
+ <label>Enabled</label>
1225
+ <frontend_type>select</frontend_type>
1226
+ <source_model>adminhtml/system_config_source_yesno</source_model>
1227
+ <sort_order>10</sort_order>
1228
+ <show_in_default>1</show_in_default>
1229
+ <show_in_website>1</show_in_website>
1230
+ <show_in_store>1</show_in_store>
1231
+ </enabled>
1232
+ <status translate="label" module="connector">
1233
+ <label>Order Status</label>
1234
+ <sort_order>20</sort_order>
1235
+ <frontend_type>select</frontend_type>
1236
+ <source_model>adminhtml/system_config_source_order_status</source_model>
1237
+ <show_in_default>1</show_in_default>
1238
+ <show_in_website>1</show_in_website>
1239
+ <show_in_store>1</show_in_store>
1240
+ </status>
1241
+ <message translate="label" module="connector">
1242
+ <label>Message</label>
1243
+ <frontend_type>textarea</frontend_type>
1244
+ <frontend_model>email_connector/adminhtml_system_sms_smsmessagefour</frontend_model>
1245
+ <sort_order>30</sort_order>
1246
+ <show_in_default>1</show_in_default>
1247
+ <show_in_website>1</show_in_website>
1248
+ <show_in_store>1</show_in_store>
1249
+ <validate>validate-length maximum-length-160</validate>
1250
+ </message>
1251
+ </fields>
1252
+ </sms_four>
1253
+ </groups>
1254
+ </connector_sms>
1255
+ <connector_dynamic_content translate="label" module="connector">
1256
+ <label><![CDATA[Dynamic Content]]></label>
1257
+ <tab>connector</tab>
1258
+ <frontend_type>text</frontend_type>
1259
+ <sort_order>8000</sort_order>
1260
+ <show_in_default>1</show_in_default>
1261
+ <show_in_website>1</show_in_website>
1262
+ <show_in_store>0</show_in_store>
1263
+ <groups>
1264
+ <products translate="label" module="connector">
1265
+ <label>Dynamic Products</label>
1266
+ <frontend_type>text</frontend_type>
1267
+ <sort_order>20</sort_order>
1268
+ <show_in_default>1</show_in_default>
1269
+ <show_in_website>1</show_in_website>
1270
+ <show_in_store>0</show_in_store>
1271
+ <fields>
1272
+ <related translate="label" module="connector">
1273
+ <label>Related Products</label>
1274
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
1275
+ <sort_order>10</sort_order>
1276
+ <show_in_default>1</show_in_default>
1277
+ <show_in_website>1</show_in_website>
1278
+ <show_in_store>0</show_in_store>
1279
+ </related>
1280
+ <related_display_type translate="label" module="connector">
1281
+ <label>Display Type</label>
1282
+ <frontend_type>select</frontend_type>
1283
+ <source_model>email_connector/adminhtml_source_dynamic_displaytype</source_model>
1284
+ <sort_order>20</sort_order>
1285
+ <show_in_default>1</show_in_default>
1286
+ <show_in_website>1</show_in_website>
1287
+ <show_in_store>0</show_in_store>
1288
+ </related_display_type>
1289
+ <related_items_to_display translate="label" module="connector">
1290
+ <label>Items To Display</label>
1291
+ <frontend_type>select</frontend_type>
1292
+ <source_model>email_connector/adminhtml_source_dynamic_gridview</source_model>
1293
+ <sort_order>30</sort_order>
1294
+ <show_in_website>1</show_in_website>
1295
+ <show_in_default>1</show_in_default>
1296
+ <show_in_store>0</show_in_store>
1297
+ </related_items_to_display>
1298
+ <upsell translate="label" module="connector">
1299
+ <label>Up Sell Products</label>
1300
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
1301
+ <sort_order>40</sort_order>
1302
+ <show_in_default>1</show_in_default>
1303
+ <show_in_website>1</show_in_website>
1304
+ <show_in_store>0</show_in_store>
1305
+ </upsell>
1306
+ <upsell_display_type translate="label" module="connector">
1307
+ <label>Display Type</label>
1308
+ <frontend_type>select</frontend_type>
1309
+ <source_model>email_connector/adminhtml_source_dynamic_displaytype</source_model>
1310
+ <sort_order>50</sort_order>
1311
+ <show_in_default>1</show_in_default>
1312
+ <show_in_website>1</show_in_website>
1313
+ <show_in_store>0</show_in_store>
1314
+ </upsell_display_type>
1315
+ <upsell_items_to_display translate="label" module="connector">
1316
+ <label>Items To Display</label>
1317
+ <frontend_type>select</frontend_type>
1318
+ <source_model>email_connector/adminhtml_source_dynamic_gridview</source_model>
1319
+ <sort_order>60</sort_order>
1320
+ <show_in_website>1</show_in_website>
1321
+ <show_in_default>1</show_in_default>
1322
+ <show_in_store>0</show_in_store>
1323
+ </upsell_items_to_display>
1324
+ <crosssell translate="label" module="connector">
1325
+ <label>Cross Sell Products</label>
1326
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
1327
+ <sort_order>70</sort_order>
1328
+ <show_in_default>1</show_in_default>
1329
+ <show_in_website>1</show_in_website>
1330
+ <show_in_store>0</show_in_store>
1331
+ </crosssell>
1332
+ <crosssell_display_type translate="label" module="connector">
1333
+ <label>Display Type</label>
1334
+ <frontend_type>select</frontend_type>
1335
+ <source_model>email_connector/adminhtml_source_dynamic_displaytype</source_model>
1336
+ <sort_order>80</sort_order>
1337
+ <show_in_default>1</show_in_default>
1338
+ <show_in_website>1</show_in_website>
1339
+ <show_in_store>0</show_in_store>
1340
+ </crosssell_display_type>
1341
+ <crosssell_items_to_display translate="label" module="connector">
1342
+ <label>Items To Display</label>
1343
+ <frontend_type>select</frontend_type>
1344
+ <source_model>email_connector/adminhtml_source_dynamic_gridview</source_model>
1345
+ <sort_order>90</sort_order>
1346
+ <show_in_website>1</show_in_website>
1347
+ <show_in_default>1</show_in_default>
1348
+ <show_in_store>0</show_in_store>
1349
+ </crosssell_items_to_display>
1350
+ <bestsellers translate="label" module="connector">
1351
+ <label>Best Sellers</label>
1352
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
1353
+ <sort_order>100</sort_order>
1354
+ <show_in_default>1</show_in_default>
1355
+ <show_in_website>1</show_in_website>
1356
+ <show_in_store>0</show_in_store>
1357
+ </bestsellers>
1358
+ <bestsellers_display_type translate="label" module="connector">
1359
+ <label>Display Type</label>
1360
+ <frontend_type>select</frontend_type>
1361
+ <source_model>email_connector/adminhtml_source_dynamic_displaytype</source_model>
1362
+ <sort_order>110</sort_order>
1363
+ <show_in_default>1</show_in_default>
1364
+ <show_in_website>1</show_in_website>
1365
+ <show_in_store>0</show_in_store>
1366
+ </bestsellers_display_type>
1367
+ <bestsellers_items_to_display translate="label" module="connector">
1368
+ <label>Items To Display</label>
1369
+ <frontend_type>select</frontend_type>
1370
+ <source_model>email_connector/adminhtml_source_dynamic_gridview</source_model>
1371
+ <sort_order>120</sort_order>
1372
+ <show_in_website>1</show_in_website>
1373
+ <show_in_default>1</show_in_default>
1374
+ <show_in_store>0</show_in_store>
1375
+ </bestsellers_items_to_display>
1376
+ <bestsellers_time_period translate="label" module="connector">
1377
+ <label>Time Period</label>
1378
+ <frontend_type>select</frontend_type>
1379
+ <source_model>adminhtml/system_config_source_cron_frequency</source_model>
1380
+ <sort_order>130</sort_order>
1381
+ <show_in_default>1</show_in_default>
1382
+ <show_in_website>1</show_in_website>
1383
+ <show_in_store>0</show_in_store>
1384
+ </bestsellers_time_period>
1385
+ <most_viewed translate="label" module="connector">
1386
+ <label>Most Viewed</label>
1387
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
1388
+ <sort_order>140</sort_order>
1389
+ <show_in_default>1</show_in_default>
1390
+ <show_in_website>1</show_in_website>
1391
+ <show_in_store>0</show_in_store>
1392
+ </most_viewed>
1393
+ <most_viewed_display_type translate="label" module="connector">
1394
+ <label>Display Type</label>
1395
+ <frontend_type>select</frontend_type>
1396
+ <source_model>email_connector/adminhtml_source_dynamic_displaytype</source_model>
1397
+ <sort_order>150</sort_order>
1398
+ <show_in_default>1</show_in_default>
1399
+ <show_in_website>1</show_in_website>
1400
+ <show_in_store>0</show_in_store>
1401
+ </most_viewed_display_type>
1402
+ <most_viewed_items_to_display translate="label" module="connector">
1403
+ <label>Items To Display</label>
1404
+ <frontend_type>select</frontend_type>
1405
+ <source_model>email_connector/adminhtml_source_dynamic_gridview</source_model>
1406
+ <sort_order>160</sort_order>
1407
+ <show_in_website>1</show_in_website>
1408
+ <show_in_default>1</show_in_default>
1409
+ <show_in_store>0</show_in_store>
1410
+ </most_viewed_items_to_display>
1411
+ <most_viewed_time_period translate="label" module="connector">
1412
+ <label>Time Period</label>
1413
+ <frontend_type>select</frontend_type>
1414
+ <source_model>adminhtml/system_config_source_cron_frequency</source_model>
1415
+ <sort_order>170</sort_order>
1416
+ <show_in_default>1</show_in_default>
1417
+ <show_in_website>1</show_in_website>
1418
+ <show_in_store>0</show_in_store>
1419
+ </most_viewed_time_period>
1420
+ <recently_viewed translate="label" module="connector">
1421
+ <label>Recently Viewed</label>
1422
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
1423
+ <sort_order>180</sort_order>
1424
+ <show_in_default>1</show_in_default>
1425
+ <show_in_website>1</show_in_website>
1426
+ <show_in_store>0</show_in_store>
1427
+ </recently_viewed>
1428
+ <recently_viewed_display_type translate="label" module="connector">
1429
+ <label>Display Type</label>
1430
+ <frontend_type>select</frontend_type>
1431
+ <source_model>email_connector/adminhtml_source_dynamic_displaytype</source_model>
1432
+ <sort_order>190</sort_order>
1433
+ <show_in_default>1</show_in_default>
1434
+ <show_in_website>1</show_in_website>
1435
+ <show_in_store>0</show_in_store>
1436
+ </recently_viewed_display_type>
1437
+ <recently_viewed_items_to_display translate="label" module="connector">
1438
+ <label>items To Display</label>
1439
+ <frontend_type>select</frontend_type>
1440
+ <source_model>email_connector/adminhtml_source_dynamic_gridview</source_model>
1441
+ <sort_order>200</sort_order>
1442
+ <show_in_default>1</show_in_default>
1443
+ <show_in_website>1</show_in_website>
1444
+ <show_in_store>0</show_in_store>
1445
+ </recently_viewed_items_to_display>
1446
+ <validator>
1447
+ <frontend_type>hidden</frontend_type>
1448
+ <frontend_model>email_connector/adminhtml_system_dynamic_gridlist</frontend_model>
1449
+ <sort_order>210</sort_order>
1450
+ <show_in_default>1</show_in_default>
1451
+ <show_in_website>1</show_in_website>
1452
+ <show_in_store>0</show_in_store>
1453
+ <can_be_empty>1</can_be_empty>
1454
+ </validator>
1455
+ </fields>
1456
+ </products>
1457
+ <external_dynamic_content_urls translate="label" module="connector">
1458
+ <label><![CDATA[External Dynamic Content URL's]]></label>
1459
+ <frontend_type>text</frontend_type>
1460
+ <sort_order>10</sort_order>
1461
+ <show_in_default>1</show_in_default>
1462
+ <show_in_website>1</show_in_website>
1463
+ <show_in_store>0</show_in_store>
1464
+ <fields>
1465
+ <passcode translate="label comment" module="connector">
1466
+ <label>Passcode</label>
1467
+ <frontend_type>text</frontend_type>
1468
+ <sort_order>10</sort_order>
1469
+ <show_in_default>1</show_in_default>
1470
+ <show_in_website>1</show_in_website>
1471
+ <show_in_store>0</show_in_store>
1472
+ <comment><![CDATA[Recommended: Set a passcode so that basket contents and coupon codes can only be viewed if the following passcode is sent with the request.]]></comment>
1473
+ </passcode>
1474
+ <lost_basket_title translate="label" module="connector">
1475
+ <label>Lost Baskets</label>
1476
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
1477
+ <sort_order>20</sort_order>
1478
+ <show_in_default>1</show_in_default>
1479
+ <show_in_website>1</show_in_website>
1480
+ <show_in_store>0</show_in_store>
1481
+ </lost_basket_title>
1482
+ <lost_basket_url translate="label" module="connector">
1483
+ <label>Baskets Content URL</label>
1484
+ <frontend_type>label</frontend_type>
1485
+ <frontend_model>email_connector/adminhtml_system_dynamic_lostbasket</frontend_model>
1486
+ <sort_order>30</sort_order>
1487
+ <show_in_default>1</show_in_default>
1488
+ <show_in_website>1</show_in_website>
1489
+ <show_in_store>0</show_in_store>
1490
+ </lost_basket_url>
1491
+ <coupon_code_title title="label" module="connector">
1492
+ <label>Coupon Codes</label>
1493
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
1494
+ <sort_order>40</sort_order>
1495
+ <show_in_website>1</show_in_website>
1496
+ <show_in_default>1</show_in_default>
1497
+ <show_in_store>0</show_in_store>
1498
+ </coupon_code_title>
1499
+ <coupon_code_url translate="label" module="connector">
1500
+ <label>Coupon Codes URL</label>
1501
+ <frontend_type>label</frontend_type>
1502
+ <frontend_model>email_connector/adminhtml_system_dynamic_couponinfo</frontend_model>
1503
+ <sort_order>50</sort_order>
1504
+ <show_in_default>1</show_in_default>
1505
+ <show_in_website>1</show_in_website>
1506
+ <show_in_store>0</show_in_store>
1507
+ </coupon_code_url>
1508
+ <dynamic_content_url translate="label" module="connector">
1509
+ <label>Product Recommendation</label>
1510
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
1511
+ <sort_order>60</sort_order>
1512
+ <show_in_default>1</show_in_default>
1513
+ <show_in_website>1</show_in_website>
1514
+ <show_in_store>0</show_in_store>
1515
+ </dynamic_content_url>
1516
+ <related_products_url translate="label" module="connector">
1517
+ <label>Related Products URL</label>
1518
+ <frontend_type>label</frontend_type>
1519
+ <frontend_model>email_connector/adminhtml_system_dynamic_related</frontend_model>
1520
+ <sort_order>70</sort_order>
1521
+ <show_in_default>1</show_in_default>
1522
+ <show_in_website>1</show_in_website>
1523
+ <show_in_store>0</show_in_store>
1524
+ </related_products_url>
1525
+ <upsell_products_url translate="label" module="connector">
1526
+ <label>Up-Sell Products URL</label>
1527
+ <frontend_type>label</frontend_type>
1528
+ <frontend_model>email_connector/adminhtml_system_dynamic_upsell</frontend_model>
1529
+ <sort_order>80</sort_order>
1530
+ <show_in_default>1</show_in_default>
1531
+ <show_in_website>1</show_in_website>
1532
+ <show_in_store>0</show_in_store>
1533
+ </upsell_products_url>
1534
+ <crosssell_products_url translate="label" module="connector">
1535
+ <label>Cross-Sell Products URL</label>
1536
+ <frontend_type>label</frontend_type>
1537
+ <frontend_model>email_connector/adminhtml_system_dynamic_crosssell</frontend_model>
1538
+ <sort_order>90</sort_order>
1539
+ <show_in_default>1</show_in_default>
1540
+ <show_in_website>1</show_in_website>
1541
+ <show_in_store>0</show_in_store>
1542
+ </crosssell_products_url>
1543
+ <best_sellers_url translate="label" module="connector">
1544
+ <label>Best Sellers URL</label>
1545
+ <frontend_type>label</frontend_type>
1546
+ <frontend_model>email_connector/adminhtml_system_dynamic_bestsellers</frontend_model>
1547
+ <sort_order>100</sort_order>
1548
+ <show_in_default>1</show_in_default>
1549
+ <show_in_website>1</show_in_website>
1550
+ <show_in_store>0</show_in_store>
1551
+ </best_sellers_url>
1552
+ <most_viewed_url translate="label" module="connector">
1553
+ <label>Most Viewed URL</label>
1554
+ <frontend_type>label</frontend_type>
1555
+ <frontend_model>email_connector/adminhtml_system_dynamic_mostviewed</frontend_model>
1556
+ <sort_order>110</sort_order>
1557
+ <show_in_default>1</show_in_default>
1558
+ <show_in_website>1</show_in_website>
1559
+ <show_in_store>0</show_in_store>
1560
+ </most_viewed_url>
1561
+ <product_push_url translate="label" module="connector">
1562
+ <label>Product Push URL</label>
1563
+ <frontend_type>label</frontend_type>
1564
+ <frontend_model>email_connector/adminhtml_system_dynamic_productpush</frontend_model>
1565
+ <sort_order>130</sort_order>
1566
+ <show_in_default>1</show_in_default>
1567
+ <show_in_website>1</show_in_website>
1568
+ <show_in_store>0</show_in_store>
1569
+ </product_push_url>
1570
+ <recently_viewed_url translate="label" module="connector">
1571
+ <label>Recently Viewed</label>
1572
+ <frontend_type>label</frontend_type>
1573
+ <frontend_model>email_connector/adminhtml_system_dynamic_recentlyviewed</frontend_model>
1574
+ <sort_order>120</sort_order>
1575
+ <show_in_default>1</show_in_default>
1576
+ <show_in_website>1</show_in_website>
1577
+ <show_in_store>0</show_in_store>
1578
+ </recently_viewed_url>
1579
+ </fields>
1580
+ </external_dynamic_content_urls>
1581
+ <manual_product_search translate="label" module="connector">
1582
+ <label>Manual Product Push</label>
1583
+ <frontend_type>text</frontend_type>
1584
+ <sort_order>30</sort_order>
1585
+ <show_in_default>1</show_in_default>
1586
+ <show_in_website>1</show_in_website>
1587
+ <show_in_store>0</show_in_store>
1588
+ <expanded>1</expanded>
1589
+ <fields>
1590
+ <settings_title tranlate="label" module="connector">
1591
+ <label>Settings</label>
1592
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
1593
+ <sort_order>10</sort_order>
1594
+ <show_in_default>1</show_in_default>
1595
+ <show_in_website>1</show_in_website>
1596
+ <show_in_store>0</show_in_store>
1597
+ </settings_title>
1598
+ <display_type translate="label" module="connector">
1599
+ <label>Display Type</label>
1600
+ <frontend_type>select</frontend_type>
1601
+ <source_model>email_connector/adminhtml_source_dynamic_displaytype</source_model>
1602
+ <sort_order>50</sort_order>
1603
+ <show_in_default>1</show_in_default>
1604
+ <show_in_website>1</show_in_website>
1605
+ <show_in_store>0</show_in_store>
1606
+ </display_type>
1607
+ <items_to_display translate="label" module="connector">
1608
+ <label>Items To Display</label>
1609
+ <frontend_type>select</frontend_type>
1610
+ <source_model>email_connector/adminhtml_source_dynamic_gridview</source_model>
1611
+ <sort_order>60</sort_order>
1612
+ <show_in_website>1</show_in_website>
1613
+ <show_in_default>1</show_in_default>
1614
+ <show_in_store>0</show_in_store>
1615
+ </items_to_display>
1616
+ <products_push_title translate="label" module="connector">
1617
+ <label>Products</label>
1618
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
1619
+ <sort_order>80</sort_order>
1620
+ <show_in_default>1</show_in_default>
1621
+ <show_in_website>1</show_in_website>
1622
+ <show_in_store>0</show_in_store>
1623
+ </products_push_title>
1624
+ <products_push_items translate="label comment" module="connector">
1625
+ <label>Products</label>
1626
+ <frontend_type>text</frontend_type>
1627
+ <sort_order>90</sort_order>
1628
+ <show_in_default>1</show_in_default>
1629
+ <show_in_website>1</show_in_website>
1630
+ <show_in_store>0</show_in_store>
1631
+ <comment><![CDATA[Comma Separated Product Id's]]></comment>
1632
+ </products_push_items>
1633
+ </fields>
1634
+ </manual_product_search>
1635
+ <fallback_products translate="label" module="connector">
1636
+ <label>Fallback Products</label>
1637
+ <frontend_type>text</frontend_type>
1638
+ <sort_order>40</sort_order>
1639
+ <show_in_default>1</show_in_default>
1640
+ <show_in_website>1</show_in_website>
1641
+ <show_in_store>0</show_in_store>
1642
+ <fields>
1643
+ <product_list translate="label comment" module="connector">
1644
+ <label>Products</label>
1645
+ <frontend_type>text</frontend_type>
1646
+ <sort_order>10</sort_order>
1647
+ <show_in_default>1</show_in_default>
1648
+ <show_in_website>1</show_in_website>
1649
+ <show_in_store>0</show_in_store>
1650
+ <comment><![CDATA[Comma Separated Product Id's]]></comment>
1651
+ </product_list>
1652
+ </fields>
1653
+ </fallback_products>
1654
+ </groups>
1655
+ </connector_dynamic_content>
1656
+ <connector_transactional_emails translate="label" module="connector">
1657
+ <label>Transactional Emails</label>
1658
+ <tab>connector</tab>
1659
+ <frontend_type>text</frontend_type>
1660
+ <show_in_default>1</show_in_default>
1661
+ <show_in_website>1</show_in_website>
1662
+ <show_in_store>0</show_in_store>
1663
+ <sort_order>9000</sort_order>
1664
+ <groups>
1665
+ <credentials translate="label" module="connector">
1666
+ <label>API</label>
1667
+ <frontend_type>text</frontend_type>
1668
+ <sort_order>100</sort_order>
1669
+ <show_in_default>1</show_in_default>
1670
+ <show_in_website>1</show_in_website>
1671
+ <show_in_store>0</show_in_store>
1672
+ <expanded>1</expanded>
1673
+ <fields>
1674
+ <enabled translate="label" module="connector">
1675
+ <label>Enabled</label>
1676
+ <frontend_type>select</frontend_type>
1677
+ <source_model>adminhtml/system_config_source_yesno</source_model>
1678
+ <sort_order>10</sort_order>
1679
+ <show_in_default>1</show_in_default>
1680
+ <show_in_website>1</show_in_website>
1681
+ <show_in_store>0</show_in_store>
1682
+ </enabled>
1683
+ <api_username translate="label" module="connector">
1684
+ <label>API Username</label>
1685
+ <frontend_type>text</frontend_type>
1686
+ <frontend_model>email_connector/adminhtml_system_config_wrapper</frontend_model>
1687
+ <sort_order>10</sort_order>
1688
+ <show_in_default>1</show_in_default>
1689
+ <show_in_website>1</show_in_website>
1690
+ <show_in_store>0</show_in_store>
1691
+ <depends>
1692
+ <enabled>1</enabled>
1693
+ </depends>
1694
+ </api_username>
1695
+ <api_password translate="label" module="connector">
1696
+ <label>API Password</label>
1697
+ <frontend_type>password</frontend_type>
1698
+ <frontend_model>email_connector/adminhtml_system_emailapivalidate</frontend_model>
1699
+ <sort_order>20</sort_order>
1700
+ <show_in_default>1</show_in_default>
1701
+ <show_in_website>1</show_in_website>
1702
+ <show_in_store>0</show_in_store>
1703
+ <depends>
1704
+ <enabled>1</enabled>
1705
+ </depends>
1706
+ </api_password>
1707
+ <validator>
1708
+ <frontend_type>hidden</frontend_type>
1709
+ <frontend_model>email_connector/adminhtml_system_config_waitingfield</frontend_model>
1710
+ <sort_order>40</sort_order>
1711
+ <show_in_default>1</show_in_default>
1712
+ <show_in_website>1</show_in_website>
1713
+ <show_in_store>0</show_in_store>
1714
+ <can_be_empty>1</can_be_empty>
1715
+ </validator>
1716
+ </fields>
1717
+ </credentials>
1718
+ <email_settings translate="label" module="connector">
1719
+ <label>Email Settings</label>
1720
+ <frontend_type>text</frontend_type>
1721
+ <sort_order>200</sort_order>
1722
+ <show_in_default>1</show_in_default>
1723
+ <show_in_website>1</show_in_website>
1724
+ <show_in_store>1</show_in_store>
1725
+ <expanded>1</expanded>
1726
+ <fields>
1727
+ <from_address translate="label" module="connector">
1728
+ <label>From Address</label>
1729
+ <frontend_type>select</frontend_type>
1730
+ <source_model>email_connector/adminhtml_source_transactional_fromaddress</source_model>
1731
+ <sort_order>10</sort_order>
1732
+ <show_in_default>1</show_in_default>
1733
+ <show_in_website>1</show_in_website>
1734
+ <show_in_store>0</show_in_store>
1735
+ </from_address>
1736
+ <unsubscribe_link translate="label" module="connector">
1737
+ <label>Include Unsubscribe Link</label>
1738
+ <frontend_type>select</frontend_type>
1739
+ <source_model>adminhtml/system_config_source_yesno</source_model>
1740
+ <sort_order>20</sort_order>
1741
+ <show_in_default>1</show_in_default>
1742
+ <show_in_website>1</show_in_website>
1743
+ <show_in_store>0</show_in_store>
1744
+ </unsubscribe_link>
1745
+ <reply_action translate="label" module="connector">
1746
+ <label>Reply Action</label>
1747
+ <frontend_type>select</frontend_type>
1748
+ <source_model>email_connector/adminhtml_source_transactional_replyactions</source_model>
1749
+ <sort_order>30</sort_order>
1750
+ <show_in_default>1</show_in_default>
1751
+ <show_in_website>1</show_in_website>
1752
+ <show_in_store>0</show_in_store>
1753
+ </reply_action>
1754
+ <reply_address translate="label" module="connector">
1755
+ <label>Reply Address</label>
1756
+ <frontend_type>text</frontend_type>
1757
+ <sort_order>40</sort_order>
1758
+ <show_in_default>1</show_in_default>
1759
+ <show_in_website>1</show_in_website>
1760
+ <show_in_store>0</show_in_store>
1761
+ <depends><reply_action>WebMailForward</reply_action></depends>
1762
+ </reply_address>
1763
+ <send_copy translate="label" module="connector">
1764
+ <label>Send Copy</label>
1765
+ <frontend_type>text</frontend_type>
1766
+ <sort_order>50</sort_order>
1767
+ <show_in_default>1</show_in_default>
1768
+ <show_in_website>1</show_in_website>
1769
+ <show_in_store>0</show_in_store>
1770
+ </send_copy>
1771
+ </fields>
1772
+ </email_settings>
1773
+ <email_mapping translate="label" module="connector">
1774
+ <label>Email Mapping</label>
1775
+ <frontend_type>text</frontend_type>
1776
+ <sort_order>300</sort_order>
1777
+ <show_in_default>1</show_in_default>
1778
+ <show_in_website>1</show_in_website>
1779
+ <show_in_store>1</show_in_store>
1780
+ <expanded>1</expanded>
1781
+ <fields>
1782
+ <default_emails_title translate="label" module="connector">
1783
+ <label>Default Emails (All Modules)</label>
1784
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
1785
+ <sort_order>10</sort_order>
1786
+ <show_in_default>1</show_in_default>
1787
+ <show_in_website>1</show_in_website>
1788
+ <show_in_store>0</show_in_store>
1789
+ </default_emails_title>
1790
+ <default_email_templates translate="label" module="connector">
1791
+ <label>Templates</label>
1792
+ <frontend_model>email_connector/adminhtml_config_template_templatefields</frontend_model>
1793
+ <backend_model>adminhtml/system_config_backend_serialized_array</backend_model>
1794
+ <source_model>email_connector/adminhtml_source_transactional_defaultselect</source_model>
1795
+ <sort_order>20</sort_order>
1796
+ <show_in_default>1</show_in_default>
1797
+ <show_in_website>1</show_in_website>
1798
+ <show_in_store>0</show_in_store>
1799
+ </default_email_templates>
1800
+ <custom_emails_title translate="label" module="connector">
1801
+ <label>Custom Emails (Admin Transactional Emails)</label>
1802
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
1803
+ <sort_order>30</sort_order>
1804
+ <show_in_default>1</show_in_default>
1805
+ <show_in_website>1</show_in_website>
1806
+ <show_in_store>0</show_in_store>
1807
+ </custom_emails_title>
1808
+ <custom_email_templates translate="label" module="connector">
1809
+ <label>Templates</label>
1810
+ <frontend_model>email_connector/adminhtml_config_template_templatefields</frontend_model>
1811
+ <backend_model>adminhtml/system_config_backend_serialized_array</backend_model>
1812
+ <source_model>email_connector/adminhtml_source_transactional_customselect</source_model>
1813
+ <sort_order>40</sort_order>
1814
+ <show_in_default>1</show_in_default>
1815
+ <show_in_website>1</show_in_website>
1816
+ <show_in_store>0</show_in_store>
1817
+ </custom_email_templates>
1818
+ </fields>
1819
+ </email_mapping>
1820
+ </groups>
1821
+ </connector_transactional_emails>
1822
+ <connector_automation_studio translate="label" module="connector">
1823
+ <label>Automation</label>
1824
+ <tab>connector</tab>
1825
+ <frontend_type>text</frontend_type>
1826
+ <sort_order>4000</sort_order>
1827
+ <show_in_default>1</show_in_default>
1828
+ <show_in_website>1</show_in_website>
1829
+ <show_in_store>0</show_in_store>
1830
+ <groups>
1831
+ <automation translate="label" module="connector">
1832
+ <label>Automation</label>
1833
+ <frontend_type>text</frontend_type>
1834
+ <show_in_default>1</show_in_default>
1835
+ <show_in_website>1</show_in_website>
1836
+ <show_in_store>0</show_in_store>
1837
+ <expanded>1</expanded>
1838
+ <fields>
1839
+ <customer_automation translate="label" module="connector">
1840
+ <label>Customer Program</label>
1841
+ <frontend_type>select</frontend_type>
1842
+ <source_model>email_connector/adminhtml_source_automation_programme</source_model>
1843
+ <show_in_default>1</show_in_default>
1844
+ <show_in_website>1</show_in_website>
1845
+ <show_in_store>0</show_in_store>
1846
+ <sort_order>100</sort_order>
1847
+ </customer_automation>
1848
+ <subscriber_automation>
1849
+ <label>Subscriber Program</label>
1850
+ <frontend_type>select</frontend_type>
1851
+ <source_model>email_connector/adminhtml_source_automation_programme</source_model>
1852
+ <show_in_default>1</show_in_default>
1853
+ <show_in_website>1</show_in_website>
1854
+ <show_in_store>0</show_in_store>
1855
+ <sort_order>110</sort_order>
1856
+ </subscriber_automation>
1857
+ </fields>
1858
+ </automation>
1859
+ </groups>
1860
+ </connector_automation_studio>
1861
+ <connector_advanced_settings translate="label" module="connector">
1862
+ <label><![CDATA[Advanced Settings]]></label>
1863
+ <tab>connector</tab>
1864
+ <frontend_type>text</frontend_type>
1865
+ <sort_order>10000</sort_order>
1866
+ <show_in_default>1</show_in_default>
1867
+ <show_in_website>1</show_in_website>
1868
+ <show_in_store>0</show_in_store>
1869
+ <groups>
1870
+ <sync_limits translate="label" module="connector">
1871
+ <label>Transactional Data</label>
1872
+ <frontend_type>text</frontend_type>
1873
+ <sort_order>10</sort_order>
1874
+ <show_in_default>1</show_in_default>
1875
+ <show_in_website>1</show_in_website>
1876
+ <show_in_store>0</show_in_store>
1877
+ <fields>
1878
+ <orders translate="label" module="connector">
1879
+ <label>Transactional Data Import Limit Size</label>
1880
+ <frontend_type>select</frontend_type>
1881
+ <source_model>email_connector/adminhtml_source_advanced_transdata</source_model>
1882
+ <sort_order>40</sort_order>
1883
+ <show_in_default>1</show_in_default>
1884
+ <show_in_website>1</show_in_website>
1885
+ <show_in_store>0</show_in_store>
1886
+ </orders>
1887
+ <order_statuses translate="label" module="connector">
1888
+ <label>Import Orders With Order Status</label>
1889
+ <frontend_type>multiselect</frontend_type>
1890
+ <source_model>email_connector/adminhtml_source_orderstatus</source_model>
1891
+ <sort_order>50</sort_order>
1892
+ <show_in_default>1</show_in_default>
1893
+ <show_in_website>1</show_in_website>
1894
+ <show_in_store>0</show_in_store>
1895
+ <comment><![CDATA[Select multiple statuses by pressing Ctrl button while selecting]]></comment>
1896
+ </order_statuses>
1897
+ <order_delete translate="label" module="connector">
1898
+ <label>Delete Data After (days)</label>
1899
+ <frontend_type>select</frontend_type>
1900
+ <source_model>email_connector/adminhtml_source_orderdelete</source_model>
1901
+ <sort_order>100</sort_order>
1902
+ <show_in_default>1</show_in_default>
1903
+ <show_in_website>1</show_in_website>
1904
+ <show_in_store>0</show_in_store>
1905
+ </order_delete>
1906
+ </fields>
1907
+ </sync_limits>
1908
+ <abandoned_cart translate="label" module="connector">
1909
+ <label>Abandoned Carts</label>
1910
+ <sort_order>20</sort_order>
1911
+ <show_in_default>1</show_in_default>
1912
+ <show_in_website>1</show_in_website>
1913
+ <show_in_store>0</show_in_store>
1914
+ <fields>
1915
+ <limits translate="label" module="connector">
1916
+ <label>Abandoned Cart Limit</label>
1917
+ <frontend_type>select</frontend_type>
1918
+ <source_model>email_connector/adminhtml_source_advanced_abandonedlimit</source_model>
1919
+ <sort_order>10</sort_order>
1920
+ <show_in_default>1</show_in_default>
1921
+ <show_in_website>1</show_in_website>
1922
+ <show_in_store>0</show_in_store>
1923
+ <comment><![CDATA[Do not send an abandoned cart email to a contact if they have received a previous abandoned cart email in previous x hours.]]></comment>
1924
+ </limits>
1925
+ <shell translate="label" module="connector">
1926
+ <label>Run Abandoned Carts From Shell.</label>
1927
+ <frontend_type>select</frontend_type>
1928
+ <source_model>adminhtml/system_config_source_yesno</source_model>
1929
+ <sort_order>20</sort_order>
1930
+ <show_in_default>1</show_in_default>
1931
+ <show_in_website>1</show_in_website>
1932
+ <show_in_store>0</show_in_store>
1933
+ <comment><![CDATA[Use the shell command to run the Abandoned baskets campaigns. Select YES to run separate cron like this :
1934
+ </br><div style="border: 1px solid #808080; padding: 5px">
1935
+ <span class="nobr">*/5 * * * * /usr/bin/php /magentoroot/shell/connector.php -action baskets -mode all</span>
1936
+ <span class="nobr">*/5 * * * * /usr/bin/php /magentoroot/shell/connector.php -action baskets -mode customers </span>
1937
+ <span class="nobr">*/5 * * * * /usr/bin/php /magentoroot/shell/connector.php -action baskets -mode guests</span>
1938
+ </div>
1939
+ ]]></comment>
1940
+ </shell>
1941
+ </fields>
1942
+ </abandoned_cart>
1943
+ <sync_settings tranlate="label" module="connector">
1944
+ <label>Contact Sync Settings</label>
1945
+ <frontend_type>text</frontend_type>
1946
+ <sort_order>30</sort_order>
1947
+ <show_in_default>1</show_in_default>
1948
+ <show_in_website>1</show_in_website>
1949
+ <show_in_store>0</show_in_store>
1950
+ <fields>
1951
+ <contact_title translate="label" module="connector">
1952
+ <label>Manually Run Sync</label>
1953
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
1954
+ <sort_order>10</sort_order>
1955
+ <show_in_default>1</show_in_default>
1956
+ <show_in_website>1</show_in_website>
1957
+ <show_in_store>0</show_in_store>
1958
+ </contact_title>
1959
+ <contact_sync translate="label" module="connector">
1960
+ <label>Contact Sync</label>
1961
+ <frontend_model>email_connector/adminhtml_system_advanced_runcontactsync</frontend_model>
1962
+ <sort_order>20</sort_order>
1963
+ <show_in_default>1</show_in_default>
1964
+ <show_in_website>1</show_in_website>
1965
+ <show_in_store>0</show_in_store>
1966
+ <comment><![CDATA[Run the contact sync manually.]]></comment>
1967
+ </contact_sync>
1968
+ <subscriber_sync tranlate="label" module="connector">
1969
+ <label>Subscriber Sync</label>
1970
+ <frontend_model>email_connector/adminhtml_system_advanced_runsubscribersync</frontend_model>
1971
+ <sort_order>30</sort_order>
1972
+ <show_in_default>1</show_in_default>
1973
+ <show_in_website>1</show_in_website>
1974
+ <show_in_store>0</show_in_store>
1975
+ <comment><![CDATA[Run the subscriber sync manually.]]></comment>
1976
+ </subscriber_sync>
1977
+ <order_sync tranlate="lable" module="connector">
1978
+ <label>Order Sync</label>
1979
+ <frontend_model>email_connector/adminhtml_system_advanced_runordersync</frontend_model>
1980
+ <sort_order>40</sort_order>
1981
+ <show_in_default>1</show_in_default>
1982
+ <show_in_website>1</show_in_website>
1983
+ <show_in_store>0</show_in_store>
1984
+ <comment><![CDATA[Run the order sync manually.]]></comment>
1985
+ </order_sync>
1986
+ <actions_title translate="label" module="connector">
1987
+ <label>Reset Sync Options</label>
1988
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
1989
+ <sort_order>50</sort_order>
1990
+ <show_in_default>1</show_in_default>
1991
+ <show_in_website>1</show_in_website>
1992
+ <show_in_store>0</show_in_store>
1993
+ </actions_title>
1994
+ <delete_contact translate="label comment" module="connector">
1995
+ <label><![CDATA[Delete All Contact ID'S]]></label>
1996
+ <frontend_model>email_connector/adminhtml_system_advanced_deletecontactids</frontend_model>
1997
+ <sort_order>60</sort_order>
1998
+ <show_in_default>1</show_in_default>
1999
+ <show_in_website>1</show_in_website>
2000
+ <show_in_store>0</show_in_store>
2001
+ <comment><![CDATA[Remove the contact id's. When using different API username account from initial setup please click here to remove all.]]></comment>
2002
+ </delete_contact>
2003
+ <reimport_customers translate="label comment" module="connector" >
2004
+ <label>Refresh Customers</label>
2005
+ <frontend_model>email_connector/adminhtml_system_advanced_resetcustomersimport</frontend_model>
2006
+ <sort_order>70</sort_order>
2007
+ <show_in_default>1</show_in_default>
2008
+ <show_in_website>1</show_in_website>
2009
+ <show_in_store>0</show_in_store>
2010
+ <comment><![CDATA[Mark all customers to be imported.]]></comment>
2011
+ </reimport_customers>
2012
+ <reimport_subscribers module="connector" translate="label">
2013
+ <label>Refresh Subscribers</label>
2014
+ <frontend_model>email_connector/adminhtml_system_advanced_reimportsubscribers</frontend_model>
2015
+ <sort_order>80</sort_order>
2016
+ <show_in_default>1</show_in_default>
2017
+ <show_in_website>1</show_in_website>
2018
+ <show_in_store>0</show_in_store>
2019
+ <comment><![CDATA[Mark all subscribers to be imported.]]></comment>
2020
+ </reimport_subscribers>
2021
+ <reimport_orders module="connector" translate="label">
2022
+ <label>Refresh Orders Data</label>
2023
+ <frontend_model>email_connector/adminhtml_system_advanced_reimportorders</frontend_model>
2024
+ <sort_order>90</sort_order>
2025
+ <show_in_default>1</show_in_default>
2026
+ <show_in_website>1</show_in_website>
2027
+ <show_in_store>0</show_in_store>
2028
+ <comment><![CDATA[Mark all order data to be imported.]]></comment>
2029
+ </reimport_orders>
2030
+ <suppressed_contacts module="connector" translate="label">
2031
+ <label>Refresh Supressed Contacts</label>
2032
+ <frontend_model>email_connector/adminhtml_system_advanced_suppressedcontacts</frontend_model>
2033
+ <sort_order>100</sort_order>
2034
+ <show_in_default>1</show_in_default>
2035
+ <show_in_website>1</show_in_website>
2036
+ <show_in_store>0</show_in_store>
2037
+ <comment>Refresh Historically Suppressed contacts for 10years period.</comment>
2038
+ </suppressed_contacts>
2039
+ </fields>
2040
+ </sync_settings>
2041
+ <admin translate="label comment" module="connector">
2042
+ <label>Admin</label>
2043
+ <frontend_type>text</frontend_type>
2044
+ <sort_order>40</sort_order>
2045
+ <show_in_default>1</show_in_default>
2046
+ <show_in_website>1</show_in_website>
2047
+ <show_in_store>0</show_in_store>
2048
+ <comment><![CDATA[<p class="notice">ADVANCED</p>]]>
2049
+ </comment>
2050
+ <fields>
2051
+ <setup_data_fields translate="label comment" module="connector">
2052
+ <label>Automap Data Fields</label>
2053
+ <frontend_model>email_connector/adminhtml_system_advanced_setupdatafields</frontend_model>
2054
+ <sort_order>10</sort_order>
2055
+ <show_in_default>1</show_in_default>
2056
+ <show_in_website>1</show_in_website>
2057
+ <show_in_store>0</show_in_store>
2058
+ <comment><![CDATA[Create Datafields In Connector And Map Them. Including Customer, Address And Sales Information.]]></comment>
2059
+ </setup_data_fields>
2060
+ <memory_limit translate="label comment" module="connector">
2061
+ <label>Customer Sync Memory Default</label>
2062
+ <frontend_type>select</frontend_type>
2063
+ <source_model>adminhtml/system_config_source_yesno</source_model>
2064
+ <sort_order>50</sort_order>
2065
+ <show_in_default>1</show_in_default>
2066
+ <show_in_website>0</show_in_website>
2067
+ <show_in_store>0</show_in_store>
2068
+ <comment>Set to NO to use system default memory.</comment>
2069
+ </memory_limit>
2070
+ <batch_size translate="label comment" module="connector">
2071
+ <label>Customer Sync Batch Size</label>
2072
+ <frontend_type>text</frontend_type>
2073
+ <show_in_default>1</show_in_default>
2074
+ <show_in_website>1</show_in_website>
2075
+ <show_in_store>0</show_in_store>
2076
+ <sort_order>60</sort_order>
2077
+ <comment>Set the limit size for customers loaded for every sync.</comment>
2078
+ </batch_size>
2079
+ <debug_enabled translate="label comment" module="connector">
2080
+ <label>Debug Mode</label>
2081
+ <frontend_type>select</frontend_type>
2082
+ <source_model>adminhtml/system_config_source_yesno</source_model>
2083
+ <sort_order>70</sort_order>
2084
+ <show_in_default>1</show_in_default>
2085
+ <show_in_website>1</show_in_website>
2086
+ <show_in_store>0</show_in_store>
2087
+ <comment>Log sync info into this file connector_api.log.</comment>
2088
+ </debug_enabled>
2089
+ <debug_api_calls>
2090
+ <label>Debug All API Calls</label>
2091
+ <frontend_type>select</frontend_type>
2092
+ <source_model>adminhtml/system_config_source_yesno</source_model>
2093
+ <sort_order>80</sort_order>
2094
+ <show_in_default>1</show_in_default>
2095
+ <show_in_website>1</show_in_website>
2096
+ <show_in_store>0</show_in_store>
2097
+ <comment>Log all API calls into the connector_api.log file, debug mode must be enabled.</comment>
2098
+ <depends><debug_enabled>1</debug_enabled></depends>
2099
+ </debug_api_calls>
2100
+ <raygun_code translate="label">
2101
+ <label>Raygun Application Code</label>
2102
+ <frontend_type>text</frontend_type>
2103
+ <sort_order>90</sort_order>
2104
+ <show_in_default>1</show_in_default>
2105
+ <show_in_website>1</show_in_website>
2106
+ <show_in_store>1</show_in_store>
2107
+ </raygun_code>
2108
+ <recommended_inline translate="label" module="connector">
2109
+ <label>Dynamic Content Styling</label>
2110
+ <frontend_type>textarea</frontend_type>
2111
+ <sort_order>110</sort_order>
2112
+ <show_in_default>1</show_in_default>
2113
+ <show_in_website>1</show_in_website>
2114
+ <show_in_store>0</show_in_store>
2115
+ <comment><![CDATA[Styling entered here will apply to all dynamic content areas pulled from Magento. Classes References Used : 'product-name', 'product-price', 'product-url']]></comment>
2116
+ </recommended_inline>
2117
+ <feed_header translate="label" module="connector">
2118
+ <label>Feed Configuration</label>
2119
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
2120
+ <sort_order>130</sort_order>
2121
+ <show_in_default>1</show_in_default>
2122
+ <show_in_website>1</show_in_website>
2123
+ <show_in_store>0</show_in_store>
2124
+ </feed_header>
2125
+ <feed_enabled translate="label" module="connector">
2126
+ <label>Enabled</label>
2127
+ <source_model>adminhtml/system_config_source_yesno</source_model>
2128
+ <frontend_type>select</frontend_type>
2129
+ <sort_order>140</sort_order>
2130
+ <show_in_default>1</show_in_default>
2131
+ <show_in_website>1</show_in_website>
2132
+ <show_in_store>0</show_in_store>
2133
+ </feed_enabled>
2134
+ <feed_url translate="label" module="connector">
2135
+ <label>Feed Url</label>
2136
+ <frontend_type>text</frontend_type>
2137
+ <sort_order>150</sort_order>
2138
+ <show_in_default>1</show_in_default>
2139
+ <show_in_website>1</show_in_website>
2140
+ <show_in_store>0</show_in_store>
2141
+ <depends><feed_enabled>1</feed_enabled></depends>
2142
+ </feed_url>
2143
+ <use_https translate="label" module="connector">
2144
+ <label>Use HTTPS to Get Feed</label>
2145
+ <frontend_type>select</frontend_type>
2146
+ <source_model>adminhtml/system_config_source_yesno</source_model>
2147
+ <sort_order>160</sort_order>
2148
+ <show_in_default>1</show_in_default>
2149
+ <show_in_website>1</show_in_website>
2150
+ <show_in_store>0</show_in_store>
2151
+ <depends><feed_enabled>1</feed_enabled></depends>
2152
+ </use_https>
2153
+ <frequency translate="label" module="connector">
2154
+ <label>Update Frequency</label>
2155
+ <frontend_type>select</frontend_type>
2156
+ <source_model>email_connector/adminhtml_source_advanced_frequency</source_model>
2157
+ <sort_order>170</sort_order>
2158
+ <show_in_default>1</show_in_default>
2159
+ <show_in_website>1</show_in_website>
2160
+ <show_in_store>0</show_in_store>
2161
+ <depends><feed_enabled>1</feed_enabled></depends>
2162
+ </frequency>
2163
+ <last_update translate="label">
2164
+ <label>Last Update</label>
2165
+ <frontend_type>label</frontend_type>
2166
+ <frontend_model>email_connector/adminhtml_system_advanced_notification</frontend_model>
2167
+ <sort_order>180</sort_order>
2168
+ <show_in_default>1</show_in_default>
2169
+ <show_in_website>1</show_in_website>
2170
+ <show_in_store>0</show_in_store>
2171
+ <depends><feed_enabled>1</feed_enabled></depends>
2172
+ </last_update>
2173
+ </fields>
2174
+ </admin>
2175
+ </groups>
2176
+ </connector_advanced_settings>
2177
+ </sections>
2178
+ </config>
app/code/{local/Dotdigitalgroup/Email/sql/connector_setup → community/Dotdigitalgroup/Email/sql/email_connector_setup}/mysql4-install-0.1.0.php RENAMED
@@ -1,12 +1,4 @@
1
  <?php
2
- /**
3
- * mag17.
4
- *
5
- * User: chrisroseuk
6
- * Date: 30/04/2013
7
- * Time: 14:17
8
- *
9
- */
10
 
11
  $installer = $this;
12
  $installer->startSetup();
@@ -24,6 +16,7 @@ $setup->addAttribute('customer', 'dotmailer_contact_id', array(
24
  'visible' => 1,
25
  'required' => 0,
26
  'user_defined' => 0,
 
27
  ));
28
 
29
  $setup->addAttributeToGroup(
@@ -42,9 +35,9 @@ $adminData = array();
42
  $adminData[] = array(
43
  'severity' => 4,
44
  'date_added' => gmdate('Y-m-d H:i:s', time()),
45
- 'title' => 'Email Connector was installed. Remmenber to enable cronjob to make it working.',
46
- 'description' => 'Connector synchronization is based on the cronjob please make sure this is setup before running through configuration.',
47
- 'url' => ''
48
  );
49
 
50
  Mage::getModel('adminnotification/inbox')->parse($adminData);
1
  <?php
 
 
 
 
 
 
 
 
2
 
3
  $installer = $this;
4
  $installer->startSetup();
16
  'visible' => 1,
17
  'required' => 0,
18
  'user_defined' => 0,
19
+ ''
20
  ));
21
 
22
  $setup->addAttributeToGroup(
35
  $adminData[] = array(
36
  'severity' => 4,
37
  'date_added' => gmdate('Y-m-d H:i:s', time()),
38
+ 'title' => 'Email Connector Was Installed. Please Enter Your API Credentials & Ensure Cron Jobs Are Running On Your Site (Find Out More)',
39
+ 'description' => 'Email Connector Was Installed. Please Enter Your API Credentials & Ensure Cron Jobs Are Running On Your Site.',
40
+ 'url' => 'http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/how_to_setup_a_cron_job'
41
  );
42
 
43
  Mage::getModel('adminnotification/inbox')->parse($adminData);
app/code/community/Dotdigitalgroup/Email/sql/email_connector_setup/mysql4-install-3.0.0.php ADDED
@@ -0,0 +1,307 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /** @var Mage_Eav_Model_Entity_Setup $installer */
4
+
5
+ $installer = $this;
6
+
7
+ $installer->startSetup();
8
+
9
+ /**
10
+ * create Contact table.
11
+ */
12
+ $contactTable = $installer->getTable('email_connector/contact');
13
+
14
+ if ($installer->getConnection()->isTableExists($contactTable)) {
15
+ $installer->getConnection()->dropTable($contactTable);
16
+ }
17
+
18
+ $table = $installer->getConnection()->newTable($contactTable);
19
+ $table->addColumn('email_contact_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
20
+ 'primary' => true,
21
+ 'identity' => true,
22
+ 'unsigned' => true,
23
+ 'nullable' => false
24
+ ), 'Primary Key')
25
+ ->addColumn('is_guest', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
26
+ 'unsigned' => true,
27
+ 'nullable' => true,
28
+ ), 'Is Guest')
29
+ ->addColumn('contact_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
30
+ 'unsigned' => true,
31
+ 'nullable' => true,
32
+ ), 'Connector Contact ID')
33
+ ->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
34
+ 'unsigned' => true,
35
+ 'nullable' => false,
36
+ ), 'Customer ID')
37
+ ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
38
+ 'unsigned' => true,
39
+ 'nullable' => false,
40
+ 'default' => '0'
41
+ ), 'Website ID')
42
+ ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
43
+ 'unsigned' => true,
44
+ 'nullable' => false,
45
+ 'default' => '0'
46
+ ), 'Store ID')
47
+ ->addColumn('email', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
48
+ 'nullable' => false,
49
+ 'default' => ''
50
+ ), 'Customer Email')
51
+ ->addColumn('is_subscriber', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
52
+ 'unsigned' => true,
53
+ 'nullable' => true,
54
+ ), 'Is Subscriber')
55
+ ->addColumn('subscriber_status', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
56
+ 'unsigned' => true,
57
+ 'nullable' => true,
58
+ ), 'Subscriber status')
59
+ ->addColumn('email_imported', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
60
+ 'unsigned' => true,
61
+ 'nullable' => true,
62
+ ), 'Is Imported')
63
+ ->addColumn('subscriber_imported', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
64
+ 'unsigned' => true,
65
+ 'nullable' => true,
66
+ ), 'Subscriber Imported')
67
+ ->addColumn('suppressed', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
68
+ 'unsigned' => true,
69
+ 'nullable' => true,
70
+ ), 'Is Suppressed')
71
+ ->addIndex($this->getIdxName($contactTable, array('email_contact_id')),
72
+ array('email_contact_id'))
73
+ ->addIndex($this->getIdxName($contactTable, array('is_guest')),
74
+ array('is_guest'))
75
+ ->addIndex($this->getIdxName($contactTable, array('customer_id')),
76
+ array('customer_id'))
77
+ ->addIndex($this->getIdxName($contactTable, array('website_id')),
78
+ array('website_id'))
79
+ ->addIndex($this->getIdxName($contactTable, array('is_subscriber')),
80
+ array('is_subscriber'))
81
+ ->addIndex($this->getIdxName($contactTable, array('subscriber_status')),
82
+ array('subscriber_status'))
83
+ ->addIndex($this->getIdxName($contactTable, array('email_imported')),
84
+ array('email_imported'))
85
+ ->addIndex($this->getIdxName($contactTable, array('subscriber_imported')),
86
+ array('subscriber_imported'))
87
+ ->addIndex($this->getIdxName($contactTable, array('suppressed')),
88
+ array('suppressed'))
89
+
90
+ ->addForeignKey(
91
+ $installer->getFkName($contactTable, 'website_id', 'core/website', 'website_id'),
92
+ 'website_id', $installer->getTable('core/website'), 'website_id',
93
+ Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE)
94
+ ->setComment('Connector Contacts');
95
+ $installer->getConnection()->createTable($table);
96
+
97
+
98
+ /**
99
+ * Order table
100
+ */
101
+ $orderTable = $installer->getTable('email_connector/order');
102
+
103
+ if ($installer->getConnection()->isTableExists($orderTable)) {
104
+ $installer->getConnection()->dropTable($orderTable);
105
+ }
106
+
107
+ $table = $installer->getConnection()->newTable($orderTable);
108
+ $table->addColumn('email_order_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
109
+ 'primary' => true,
110
+ 'identity' => true,
111
+ 'unsigned' => true,
112
+ 'nullable' => false
113
+ ), 'Primary Key')
114
+ ->addColumn('order_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
115
+ 'unsigned' => true,
116
+ 'nullable' => false,
117
+ ), 'Order ID')
118
+ ->addColumn('order_status', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(
119
+ 'unsigned' => true,
120
+ 'nullable' => false,
121
+ ), 'Order Status')
122
+ ->addColumn('quote_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
123
+ 'unsigned' => true,
124
+ 'nullable' => false,
125
+ ), 'Sales Quote ID')
126
+ ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
127
+ 'unsigned' => true,
128
+ 'nullable' => false,
129
+ 'default' => '0'
130
+ ), 'Store ID')
131
+ ->addColumn('email_imported', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
132
+ 'unsigned' => true,
133
+ 'nullable' => true,
134
+ ), 'Is Order Imported')
135
+ ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
136
+ ), 'Creation Time')
137
+ ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
138
+ ), 'Update Time')
139
+ ->addIndex($this->getIdxName($orderTable, array('store_id')),
140
+ array('store_id'))
141
+ ->addIndex($this->getIdxName($orderTable, array('quote_id')),
142
+ array('quote_id'))
143
+
144
+ ->addForeignKey(
145
+ $installer->getFkName($orderTable, 'store_id', 'core/store', 'store_id'),
146
+ 'store_id', $installer->getTable('core/store'), 'store_id',
147
+ Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE)
148
+ ->setComment('Transactional Orders Data');
149
+ $installer->getConnection()->createTable($table);
150
+
151
+
152
+ /**
153
+ * Campaign table.
154
+ */
155
+ $campaignTable = $installer->getTable('email_connector/campaign');
156
+
157
+ if ($installer->getConnection()->isTableExists($campaignTable)) {
158
+ $installer->getConnection()->dropTable($campaignTable);
159
+ }
160
+
161
+ $table = $installer->getConnection()->newTable($campaignTable);
162
+ $table->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
163
+ 'primary' => true,
164
+ 'identity' => true,
165
+ 'unsigned' => true,
166
+ 'nullable' => false
167
+ ), 'Primary Key')
168
+ ->addColumn('campaign_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
169
+ 'unsigned' => true,
170
+ 'nullable' => false,
171
+ ), 'Campaign ID')
172
+ ->addColumn('email', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
173
+ 'nullable' => false,
174
+ 'default' => ''
175
+ ), 'Contact Email')
176
+ ->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
177
+ 'unsigned' => true,
178
+ 'nullable' => false,
179
+ ), 'Customer ID')
180
+ ->addColumn('is_sent', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
181
+ 'unsigned' => true,
182
+ 'nullable' => true,
183
+ ), 'Is Sent')
184
+ ->addColumn('sent_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
185
+ ), 'Send Date')
186
+ ->addColumn('order_increment_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
187
+ 'unsigned' => true,
188
+ 'nullable' => false,
189
+ ), 'Order Increment ID')
190
+ ->addColumn('quote_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
191
+ 'unsigned' => true,
192
+ 'nullable' => false,
193
+ ), 'Sales Quote ID')
194
+ ->addColumn('message', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
195
+ 'nullable' => false,
196
+ 'default' => ''
197
+ ), 'Errror Message')
198
+ ->addColumn('checkout_method', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
199
+ 'nullable' => false,
200
+ 'default' => ''
201
+ ), 'Checkout Method Used')
202
+ ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
203
+ 'unsigned' => true,
204
+ 'nullable' => false,
205
+ 'default' => '0'
206
+ ), 'Store ID')
207
+ ->addColumn('event_name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
208
+ 'nullable' => false,
209
+ 'default' => ''
210
+ ), 'Event Name')
211
+ ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
212
+ ), 'Creation Time')
213
+ ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
214
+ ), 'Update Time')
215
+
216
+ ->addIndex($this->getIdxName($campaignTable, array('store_id')),
217
+ array('store_id'))
218
+ ->addIndex($this->getIdxName($campaignTable, array('campaign_id')),
219
+ array('campaign_id'))
220
+ ->addIndex($this->getIdxName($campaignTable, array('email')),
221
+ array('email'))
222
+ ->addIndex($this->getIdxName($campaignTable, array('is_sent')),
223
+ array('is_sent'))
224
+ ->addForeignKey(
225
+ $installer->getFkName($campaignTable, 'store_id', 'core/store', 'store_id'),
226
+ 'store_id', $installer->getTable('core/store'), 'store_id',
227
+ Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE)
228
+ ->setComment('Connector Campaigns');
229
+ $installer->getConnection()->createTable($table);
230
+
231
+
232
+ /**
233
+ * Admin notification message
234
+ */
235
+
236
+ $adminData = array();
237
+ $adminData[] = array(
238
+ 'severity' => 4,
239
+ 'date_added' => gmdate('Y-m-d H:i:s', time()),
240
+ 'title' => 'Email Connector Was Installed. Please Enter Your API Credentials & Ensure Cron Jobs Are Running On Your Site (Find Out More)',
241
+ 'description' => 'Email Connector Was Installed. Please Enter Your API Credentials & Ensure Cron Jobs Are Running On Your Site.',
242
+ 'url' => 'http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/how_to_setup_a_cron_job'
243
+ );
244
+
245
+ Mage::getModel('adminnotification/inbox')->parse($adminData);
246
+
247
+ /**
248
+ * Populate tables
249
+ */
250
+
251
+ //customers populate
252
+ $select = $installer->getConnection()->select()
253
+ ->from(
254
+ array('customer' => $this->getTable('customer_entity')),
255
+ array('customer_id' => 'entity_id','email','website_id','store_id')
256
+ );
257
+
258
+ $insertArray = array('customer_id','email','website_id','store_id');
259
+ $sqlQuery = $select->insertFromSelect($contactTable, $insertArray, false);
260
+ $installer->getConnection()->query($sqlQuery);
261
+
262
+ // subscribers that are not customers
263
+ $select = $installer->getConnection()->select()
264
+ ->from(
265
+ array('subscriber' => $this->getTable('newsletter_subscriber')),
266
+ array(
267
+ 'email' => 'subscriber_email',
268
+ 'col2' => new Zend_Db_Expr('1'),
269
+ 'col3' => new Zend_Db_Expr('1'),
270
+ 'store_id'
271
+ )
272
+ )
273
+ ->where('customer_id =?', 0 )
274
+ ->where('subscriber_status =?', 1);
275
+ $insertArray = array('email','is_subscriber','subscriber_status','store_id');
276
+ $sqlQuery = $select->insertFromSelect($contactTable, $insertArray, false);
277
+ $installer->getConnection()->query($sqlQuery);
278
+
279
+ //Insert and populate email order the table
280
+ $select = $installer->getConnection()->select()
281
+ ->from(
282
+ $this->getTable('sales/order'),
283
+ array('order_id' => 'entity_id', 'quote_id', 'store_id', 'created_at', 'updated_at', 'order_status' => 'status' )
284
+ );
285
+ $insertArray =
286
+ array('order_id', 'quote_id', 'store_id', 'created_at', 'updated_at', 'order_status');
287
+
288
+ $sqlQuery = $select->insertFromSelect($orderTable, $insertArray, false);
289
+ $installer->getConnection()->query($sqlQuery);
290
+
291
+ //Save all order statuses as string
292
+ $source = Mage::getModel('adminhtml/system_config_source_order_status');
293
+ $statuses = $source->toOptionArray();
294
+
295
+ if(count($statuses) > 0 && $statuses[0]['value'] == '')
296
+ array_shift($statuses);
297
+
298
+ $options = array();
299
+ foreach($statuses as $status) {
300
+ $options[] = $status['value'];
301
+ }
302
+ $statusString = implode(',',$options);
303
+
304
+ $configModel = Mage::getModel('core/config');
305
+ $configModel->saveConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_ORDER_STATUS,$statusString);
306
+
307
+ $installer->endSetup();
app/code/{local/Dotdigitalgroup/Email/sql/connector_setup → community/Dotdigitalgroup/Email/sql/email_connector_setup}/mysql4-upgrade-1.1.1-1.1.2.php RENAMED
File without changes
app/code/community/Dotdigitalgroup/Email/sql/email_connector_setup/mysql4-upgrade-1.1.2-1.5.0.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+
5
+ $installer->startSetup();
6
+
7
+
8
+ $installer->endSetup();
app/code/community/Dotdigitalgroup/Email/sql/email_connector_setup/mysql4-upgrade-1.5.0-2.0.0.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ $installer = $this;
5
+
6
+ $installer->startSetup();
7
+
8
+ try{
9
+
10
+ $installer->run(
11
+ "DROP TABLE IF EXISTS {$this->getTable('email_order')};
12
+ CREATE TABLE `{$this->getTable('email_order')}` (
13
+ `email_order_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
14
+ `order_id` int(15) unsigned DEFAULT NULL,
15
+ `quote_id` int(15) unsigned DEFAULT NULL,
16
+ `store_id` smallint(5) unsigned DEFAULT NULL,
17
+ `email_imported` tinyint(1) DEFAULT NULL,
18
+ `created_at` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
19
+ `updated_at` datetime DEFAULT NULL,
20
+ PRIMARY KEY (`email_order_id`),
21
+ KEY `IDX_EMAIL_STORE_ID` (`store_id`),
22
+ KEY `IDX_EMAIL_QUOTE_ID` (`quote_id`),
23
+ CONSTRAINT `FK_EMAIL_STORE_ID_CORE_STORE_STORE_ID` FOREIGN KEY (`store_id`) REFERENCES `{$this->getTable('core_store')}` (`store_id`) ON DELETE SET NULL ON UPDATE CASCADE
24
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"
25
+ );
26
+
27
+
28
+ //Insert and populate email order the table
29
+ $installer->run(
30
+ "INSERT IGNORE INTO `{$this->getTable('email_order')}` (`order_id`, `quote_id`, `store_id`, `created_at`, `updated_at`)
31
+ SELECT `entity_id`, `quote_id`, `store_id`, `created_at`, `updated_at`
32
+ FROM `{$this->getTable('sales/order')}`;"
33
+ );
34
+
35
+
36
+ $installer->run(
37
+ "DROP TABLE IF EXISTS {$this->getTable('email_contact')};
38
+ CREATE TABLE `{$this->getTable('email_contact')}` (
39
+ `email_contact_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
40
+ `is_guest` smallint(1) DEFAULT NULL,
41
+ `contact_id` int(15) unsigned DEFAULT NULL,
42
+ `customer_id` int(10) unsigned DEFAULT NULL,
43
+ `website_id` smallint(5) unsigned DEFAULT NULL COMMENT 'Website Id',
44
+ `email` varchar(255) DEFAULT NULL,
45
+ `is_subscriber` tinyint(1)unsigned DEFAULT NULL,
46
+ `subscriber_status` int(10) unsigned DEFAULT '0',
47
+ `email_id` smallint(5) unsigned DEFAULT NULL,
48
+ `email_imported` tinyint(1) unsigned DEFAULT NULL,
49
+ `suppressed` smallint(1) DEFAULT NULL,
50
+ PRIMARY KEY (`email_contact_id`),
51
+ KEY `IDX_EMAIL_CONTACT_WEBSITE_ID` (`website_id`),
52
+ CONSTRAINT `FK_EMAIL_CONTACT_WEBSITE_ID_CORE_WEBSITE_WEBSITE_ID` FOREIGN KEY (`website_id`) REFERENCES `core_website` (`website_id`) ON DELETE SET NULL ON UPDATE CASCADE
53
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Email Contact Sync';"
54
+ );
55
+
56
+
57
+ //Insert and populate email contact table
58
+ $installer->run(
59
+ "INSERT IGNORE INTO `{$this->getTable('email_contact')}` (`customer_id`, `email`, `website_id`)
60
+ SELECT `entity_id`, `email`, `website_id`
61
+ FROM `{$this->getTable('customer_entity')}`;"
62
+ );
63
+
64
+ //Remove Order Attribute For Imported Data
65
+ $installer->removeAttribute('order', 'dotmailer_order_imported');
66
+ $installer->removeAttribute('customer', 'dotmailer_contact_id');
67
+
68
+
69
+ }catch (Exception $e){
70
+
71
+ Mage::log($e->getMessage());
72
+
73
+ }
74
+
75
+ $installer->endSetup();
app/code/community/Dotdigitalgroup/Email/sql/email_connector_setup/mysql4-upgrade-2.0.0-2.0.1.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ $installer = $this;
5
+
6
+ $installer->startSetup();
7
+
8
+
9
+ $installer->endSetup();
app/code/community/Dotdigitalgroup/Email/sql/email_connector_setup/mysql4-upgrade-2.0.1-2.0.2.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+
5
+ $installer->startSetup();
6
+
7
+
8
+ $installer->run(
9
+ "DROP TABLE IF EXISTS {$this->getTable('email_contact')};
10
+ CREATE TABLE `{$this->getTable('email_contact')}` (
11
+ `email_contact_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
12
+ `is_guest` smallint(1) DEFAULT NULL,
13
+ `contact_id` int(15) unsigned DEFAULT NULL,
14
+ `customer_id` int(10) unsigned DEFAULT NULL,
15
+ `website_id` smallint(5) unsigned DEFAULT NULL COMMENT 'Website Id',
16
+ `email` varchar(255) DEFAULT NULL,
17
+ `is_subscriber` tinyint(1) unsigned DEFAULT NULL,
18
+ `subscriber_status` int(10) unsigned DEFAULT '0',
19
+ `subscriber_imported` tinyint(1) unsigned DEFAULT NULL,
20
+ `email_imported` tinyint(1) unsigned DEFAULT NULL,
21
+ `suppressed` smallint(1) DEFAULT NULL,
22
+ PRIMARY KEY (`email_contact_id`),
23
+ KEY `IDX_EMAIL_CONTACT_ID` (`email_contact_id`),
24
+ KEY `IDX_EMAIL_CONTACT_IS_GUEST` (`is_guest`),
25
+ KEY `IDX_EMAIL_CONTACT_CUSTOMER_ID` (`customer_id`),
26
+ KEY `IDX_EMAIL_CONTACT_WEBSITE_ID` (`website_id`),
27
+ KEY `IDX_EMAIL_CONTACT_IS_SUBSCRIBER` (`is_subscriber`),
28
+ KEY `IDX_EMAIL_CONTACT_SUBSCRIBER_STATUS` (`subscriber_status`),
29
+ KEY `IDX_EMAIL_CONTACT_SUBSCRIBER_IMPORTED` (`subscriber_imported`),
30
+ KEY `IDX_EMAIL_CONTACT_EMAIL_IMPORTED` (`email_imported`),
31
+ KEY `IDX_EMAIL_CONTACT_suppressed` (`suppressed`),
32
+ UNIQUE KEY `IDX_EMAIL_CONTACT_EMAIL` (`email`),
33
+ CONSTRAINT `FK_EMAIL_CONTACT_WEBSITE_ID_CORE_WEBSITE_WEBSITE_ID` FOREIGN KEY (`website_id`) REFERENCES `core_website` (`website_id`) ON DELETE SET NULL ON UPDATE CASCADE
34
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Email Contacts';"
35
+ );
36
+
37
+
38
+ //Insert and populate email contact table
39
+ $installer->run(
40
+ "INSERT IGNORE INTO `{$this->getTable('email_contact')}` (`customer_id`, `email`, `website_id`)
41
+ SELECT `entity_id`, `email`, `website_id`
42
+ FROM `{$this->getTable('customer_entity')}`;"
43
+ );
44
+
45
+ //Subscribers that are not customers
46
+ $installer->run("
47
+ INSERT IGNORE INTO {$this->getTable('email_contact')} (`email`, `is_subscriber`, `subscriber_status`)
48
+ SELECT `subscriber_email`, '1' as col2, '1' as col3 FROM `{$this->getTable('newsletter/subscriber')}` WHERE `customer_id` = 0 AND `subscriber_status` = 1;
49
+ ");
50
+
51
+
52
+ $installer->endSetup();
app/code/community/Dotdigitalgroup/Email/sql/email_connector_setup/mysql4-upgrade-2.0.3-2.0.4.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+
5
+
6
+ $installer->startSetup();
7
+
8
+
9
+ $installer->run("
10
+ ALTER TABLE `{$this->getTable('email_contact')}`
11
+
12
+ DROP FOREIGN KEY `FK_EMAIL_CONTACT_WEBSITE_ID_CORE_WEBSITE_WEBSITE_ID`,
13
+ CHANGE COLUMN `website_id` `website_id` smallint(5) unsigned DEFAULT '0' AFTER `customer_id`;
14
+ ");
15
+
16
+ $installer->run("
17
+ UPDATE `{$this->getTable('email_contact')}` SET `website_id` = '0'
18
+ WHERE `website_id` IS NULL;
19
+ ");
20
+
21
+ $installer->run("
22
+ ALTER TABLE `{$this->getTable('email_contact')}`
23
+ ADD CONSTRAINT `FK_EMAIL_CONTACT_WEBSITE_ID_CORE_WEBSITE_WEBSITE_ID` FOREIGN KEY (`website_id`) REFERENCES `{$installer->getTable('core_website')}` (`website_id`) ON DELETE CASCADE ON UPDATE CASCADE;
24
+
25
+ ");
26
+
27
+
28
+ $installer->endSetup();
app/code/community/Dotdigitalgroup/Email/sql/email_connector_setup/mysql4-upgrade-2.0.4-2.0.5.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+
5
+
6
+ $installer->startSetup();
7
+
8
+
9
+ $installer->endSetup();
app/code/community/Dotdigitalgroup/Email/sql/email_connector_setup/mysql4-upgrade-2.0.5-2.0.6.php ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ $installer = $this;
5
+
6
+ $installer->startSetup();
7
+ /**
8
+ * Campaign table.
9
+ */
10
+ $campaignTable = $installer->getTable('email_connector/campaign');
11
+
12
+ if ($installer->getConnection()->isTableExists($campaignTable)) {
13
+ $installer->getConnection()->dropTable($campaignTable);
14
+ }
15
+
16
+ $table = $installer->getConnection()->newTable($campaignTable);
17
+ $table->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
18
+ 'primary' => true,
19
+ 'identity' => true,
20
+ 'unsigned' => true,
21
+ 'nullable' => false
22
+ ), 'Primary Key')
23
+ ->addColumn('campaign_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
24
+ 'unsigned' => true,
25
+ 'nullable' => false,
26
+ ), 'Campaign ID')
27
+ ->addColumn('email', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
28
+ 'nullable' => false,
29
+ 'default' => ''
30
+ ), 'Contact Email')
31
+ ->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
32
+ 'unsigned' => true,
33
+ 'nullable' => false,
34
+ ), 'Customer ID')
35
+ ->addColumn('is_sent', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
36
+ 'unsigned' => true,
37
+ 'nullable' => true,
38
+ ), 'Is Sent')
39
+ ->addColumn('sent_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
40
+ ), 'Send Date')
41
+ ->addColumn('order_increment_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
42
+ 'unsigned' => true,
43
+ 'nullable' => false,
44
+ ), 'Order Increment ID')
45
+ ->addColumn('quote_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
46
+ 'unsigned' => true,
47
+ 'nullable' => false,
48
+ ), 'Sales Quote ID')
49
+ ->addColumn('message', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
50
+ 'nullable' => false,
51
+ 'default' => ''
52
+ ), 'Errror Message')
53
+ ->addColumn('checkout_method', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
54
+ 'nullable' => false,
55
+ 'default' => ''
56
+ ), 'Checkout Method Used')
57
+ ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
58
+ 'unsigned' => true,
59
+ 'nullable' => false,
60
+ 'default' => '0'
61
+ ), 'Store ID')
62
+ ->addColumn('event_name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
63
+ 'nullable' => false,
64
+ 'default' => ''
65
+ ), 'Event Name')
66
+ ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
67
+ ), 'Creation Time')
68
+ ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
69
+ ), 'Update Time')
70
+
71
+ ->addIndex($this->getIdxName($campaignTable, array('store_id')),
72
+ array('store_id'))
73
+ ->addIndex($this->getIdxName($campaignTable, array('campaign_id')),
74
+ array('campaign_id'))
75
+ ->addIndex($this->getIdxName($campaignTable, array('email')),
76
+ array('email'))
77
+ ->addIndex($this->getIdxName($campaignTable, array('is_sent')),
78
+ array('is_sent'))
79
+ ->addForeignKey(
80
+ $installer->getFkName($campaignTable, 'store_id', 'core/store', 'store_id'),
81
+ 'store_id', $installer->getTable('core/store'), 'store_id',
82
+ Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE)
83
+ ->setComment('Connector Campaigns');
84
+ $installer->getConnection()->createTable($table);
85
+
86
+ /**
87
+ * remove contact column
88
+ */
89
+ $installer->getConnection()->dropColumn($installer->getTable('email_connector/contact'), 'subscriber_imported');
90
+
91
+ /*
92
+ * Cleaning
93
+ */
94
+ $entityTypeId = $installer->getEntityTypeId('customer');
95
+ if ($installer->attributeExists($entityTypeId, 'dotmailer_contact_id'))
96
+ $installer->removeAttribute($entityTypeId, 'dotmailer_contact_id');
97
+
98
+ $entityTypeId = $installer->getEntityTypeId('order');
99
+ if($installer->attributeExists($entityTypeId, 'dotmailer_order_imported'))
100
+ $installer->removeAttribute($entityTypeId, 'dotmailer_order_imported');
101
+
102
+
103
+ $installer->endSetup();
app/code/community/Dotdigitalgroup/Email/sql/email_connector_setup/mysql4-upgrade-3.0.1-3.0.2.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+
5
+
6
+ $installer->startSetup();
7
+
8
+ $admin = $this->getTable('admin/user');
9
+
10
+ $installer->getConnection()->addColumn($installer->getTable('admin/user'), 'refresh_token', array(
11
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
12
+ 'length' => 256,
13
+ 'nullable' => true,
14
+ 'default' => null,
15
+ 'comment' => 'Email connector refresh token'
16
+ ));
17
+
18
+ $installer->endSetup();
app/code/community/Dotdigitalgroup/Email/sql/email_connector_setup/mysql4-upgrade-3.0.3-3.0.4.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+
5
+
6
+ $installer->startSetup();
7
+
8
+ $campaignTable = $this->getTable('email_campaign');
9
+
10
+ $installer->getConnection()->modifyColumn($campaignTable, 'order_increment_id', 'VARCHAR(50)');
11
+
12
+ $installer->endSetup();
app/code/community/Dotdigitalgroup/Email/sql/email_connector_setup/mysql4-upgrade-3.0.4-3.0.5.php ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /** @var Mage_Eav_Model_Entity_Setup $installer */
4
+
5
+ $installer = $this;
6
+
7
+ $installer->startSetup();
8
+
9
+ //Insert status column to email_order table
10
+ $orderTable = $installer->getTable('email_connector/order');
11
+
12
+ $installer->getConnection()->addColumn($orderTable, 'order_status', array(
13
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
14
+ 'length' => 256,
15
+ 'nullable' => false,
16
+ 'default' => null,
17
+ 'comment' => 'Order Status'
18
+ ));
19
+
20
+ //populate order status in email_order table
21
+
22
+ //select
23
+ $select = $installer->getConnection()->select();
24
+
25
+ //join
26
+ $select->joinLeft(
27
+ array('sfo' => $installer->getTable('sales/order')),
28
+ "eo.order_id = sfo.entity_id",
29
+ array('order_status' => 'sfo.status')
30
+ );
31
+
32
+ //update query from select
33
+ $updateSql = $select->crossUpdateFromSelect(array('eo' => $orderTable));
34
+
35
+ //run query
36
+ $installer->getConnection()->query($updateSql);
37
+
38
+
39
+ /**
40
+ * create table
41
+ */
42
+ $createTable = $installer->getTable('email_connector/create');
43
+
44
+ if ($installer->getConnection()->isTableExists($createTable)) {
45
+ $installer->getConnection()->dropTable($createTable);
46
+ }
47
+
48
+ $table = $installer->getConnection()->newTable($createTable);
49
+ $table->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
50
+ 'primary' => true,
51
+ 'identity' => true,
52
+ 'unsigned' => true,
53
+ 'nullable' => false
54
+ ), 'Primary Key')
55
+ ->addColumn('email', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
56
+ 'nullable' => false,
57
+ 'default' => ''
58
+ ), 'Email')
59
+ ->addColumn('from_name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
60
+ 'nullable' => false,
61
+ 'default' => ''
62
+ ), 'From Name')
63
+ ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
64
+ 'unsigned' => true,
65
+ 'nullable' => false,
66
+ 'default' => '0'
67
+ ), 'Website ID')
68
+ ->addColumn('name', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(
69
+ 'unsigned' => true,
70
+ 'nullable' => false,
71
+ ), 'Template Name')
72
+ ->addColumn('subject', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(
73
+ 'unsigned' => true,
74
+ 'nullable' => false,
75
+ ), 'Subject')
76
+ ->addColumn('html_content', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(
77
+ 'unsigned' => true,
78
+ 'nullable' => false,
79
+ ), 'Html Content')
80
+ ->addColumn('plain_text_content', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(
81
+ 'unsigned' => true,
82
+ 'nullable' => false,
83
+ ), 'Plain Text Content')
84
+ ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
85
+ ), 'Creation Time')
86
+ ->addColumn('message', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
87
+ 'nullable' => false,
88
+ 'default' => ''
89
+ ), 'Error Message')
90
+ ->addColumn('is_created', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
91
+ 'unsigned' => true,
92
+ 'nullable' => true,
93
+ ), 'Is Created')
94
+ ->addColumn('copy', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
95
+ 'nullable' => false,
96
+ 'default' => ''
97
+ ), 'Copy Email')
98
+ ->addIndex($this->getIdxName($createTable, array('is_created')),
99
+ array('is_created'))
100
+
101
+ ->setComment('Transactional Orders Data');
102
+ $installer->getConnection()->createTable($table);
103
+
104
+ //Save all order statuses as string to extension's config value
105
+ $source = Mage::getModel('adminhtml/system_config_source_order_status');
106
+ $statuses = $source->toOptionArray();
107
+
108
+ if(count($statuses) > 0 && $statuses[0]['value'] == '')
109
+ array_shift($statuses);
110
+
111
+ $options = array();
112
+ foreach($statuses as $status) {
113
+ $options[] = $status['value'];
114
+ }
115
+ $statusString = implode(',',$options);
116
+
117
+ $configModel = Mage::getModel('core/config');
118
+ $configModel->saveConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_ORDER_STATUS,$statusString);
119
+
120
+ $installer->endSetup();
121
+
app/code/community/Dotdigitalgroup/Email/sql/email_connector_setup/mysql4-upgrade-3.1.2-3.1.3.php ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /** @var Mage_Eav_Model_Entity_Setup $installer */
4
+
5
+ $installer = $this;
6
+ $installer->startSetup();
7
+
8
+ //drop table
9
+ $createTable = $installer->getTable('email_create');
10
+ if ($installer->getConnection()->isTableExists($createTable)) {
11
+ $installer->getConnection()->dropTable($createTable);
12
+ }
13
+
14
+ //add columns to table
15
+ $campaignTable = $installer->getTable('email_connector/campaign');
16
+ $installer->getConnection()->addColumn($campaignTable, 'subject', array(
17
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
18
+ 'unsigned' => true,
19
+ 'nullable' => false,
20
+ 'default' => '',
21
+ 'comment' => 'Email Subject'
22
+ ));
23
+ $installer->getConnection()->addColumn($campaignTable, 'html_content', array(
24
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
25
+ 'unsigned' => true,
26
+ 'nullable' => false,
27
+ 'default' => '',
28
+ 'comment' => 'Email Html Content'
29
+ ));
30
+ $installer->getConnection()->addColumn($campaignTable, 'plain_text_content', array(
31
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
32
+ 'unsigned' => true,
33
+ 'nullable' => false,
34
+ 'default' => '',
35
+ 'comment' => 'Email Plain Text Content'
36
+ ));
37
+ $installer->getConnection()->addColumn($campaignTable, 'from_name', array(
38
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
39
+ 'unsigned' => true,
40
+ 'nullable' => false,
41
+ 'default' => '',
42
+ 'comment' => 'Email From Name'
43
+ ));
44
+ $installer->getConnection()->addColumn($campaignTable, 'create_message', array(
45
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
46
+ 'unsigned' => true,
47
+ 'nullable' => false,
48
+ 'default' => '',
49
+ 'comment' => 'Create Campaign Message'
50
+ ));
51
+ $installer->getConnection()->addColumn($campaignTable, 'contact_message', array(
52
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
53
+ 'unsigned' => true,
54
+ 'nullable' => false,
55
+ 'default' => '',
56
+ 'comment' => 'Contact Message'
57
+ ));
58
+ $installer->getConnection()->addColumn($campaignTable, 'is_created', array(
59
+ 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
60
+ 'unsigned' => true,
61
+ 'nullable' => true,
62
+ 'comment' => 'Is Campaign Created'
63
+ ));
64
+ $installer->getConnection()->addColumn($campaignTable, 'is_copy', array(
65
+ 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
66
+ 'unsigned' => true,
67
+ 'nullable' => true,
68
+ 'comment' => 'Is Copy'
69
+ ));
70
+ $installer->getConnection()->addColumn($campaignTable, 'type', array(
71
+ 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
72
+ 'unsigned' => true,
73
+ 'nullable' => false,
74
+ 'default' => '1',
75
+ 'comment' => 'Type. 1: Campaign, 2: Create'
76
+ ));
77
+ $installer->getConnection()->addColumn($campaignTable, 'website_id', array(
78
+ 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
79
+ 'unsigned' => true,
80
+ 'nullable' => false,
81
+ 'default' => '0',
82
+ 'comment' => 'Website Id'
83
+ ));
84
+
85
+
86
+ /**
87
+ * create Config table.
88
+ */
89
+ $configTable = $installer->getTable('email_connector/config');
90
+
91
+ if ($installer->getConnection()->isTableExists($configTable)) {
92
+ $installer->getConnection()->dropTable($configTable);
93
+ }
94
+
95
+ $table = $installer->getConnection()->newTable($configTable);
96
+ $table->addColumn('email_config_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
97
+ 'primary' => true,
98
+ 'identity' => true,
99
+ 'unsigned' => true,
100
+ 'nullable' => false
101
+ ), 'Primary Key')
102
+ ->addColumn('path', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
103
+ 'nullable' => true,
104
+ ), 'Config Path')
105
+ ->addColumn('scope', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
106
+ 'nullable' => true,
107
+ ), 'Config Scope')
108
+ ->addColumn('value', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
109
+ 'nullable' => false,
110
+ 'default' => ''
111
+ ), 'Config Value')
112
+ ->addColumn('is_api', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
113
+ 'unsigned' => true,
114
+ 'nullable' => true,
115
+ ), 'Only For Api Calls')
116
+ ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
117
+ ), 'Creation Time')
118
+ ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
119
+ ), 'Update Time')
120
+ ->setComment('Connector Config Data');
121
+ $installer->getConnection()->createTable($table);
122
+
123
+ $installer->endSetup();
app/code/community/Dotdigitalgroup/Mailcheck/Helper/Data.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Mailcheck_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+
6
+ }
app/code/community/Dotdigitalgroup/Mailcheck/etc/config.xml ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Dotdigitalgroup_Mailcheck>
5
+ <version>1.0.0</version>
6
+ </Dotdigitalgroup_Mailcheck>
7
+ </modules>
8
+ <global>
9
+ <helpers>
10
+ <connector_mailcheck>
11
+ <class>Dotdigitalgroup_Mailcheck_Helper</class>
12
+ </connector_mailcheck>
13
+ </helpers>
14
+ </global>
15
+ <frontend>
16
+ <layout>
17
+ <updates>
18
+ <connector_mailcheck>
19
+ <file>mailcheck.xml</file>
20
+ </connector_mailcheck>
21
+ </updates>
22
+ </layout>
23
+ </frontend>
24
+ <default>
25
+ <connector_advanced_settings>
26
+ <mailcheck>
27
+ <enabled>0</enabled>
28
+ </mailcheck>
29
+ </connector_advanced_settings>
30
+ </default>
31
+ </config>
app/code/community/Dotdigitalgroup/Mailcheck/etc/jstranslator.xml ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <jstranslator>
2
+ <mailcheck_suggestion translate="message" module="connector_mailcheck">
3
+ <message>Did you mean</message>
4
+ </mailcheck_suggestion>
5
+ </jstranslator>
app/code/community/Dotdigitalgroup/Mailcheck/etc/system.xml ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <sections>
4
+ <connector_advanced_settings translate="label" module="connector">
5
+ <groups>
6
+ <mailcheck translate="label" module="connector">
7
+ <label>MailCheck Settings</label>
8
+ <frontend_type>text</frontend_type>
9
+ <sort_order>9999</sort_order>
10
+ <show_in_default>1</show_in_default>
11
+ <show_in_website>1</show_in_website>
12
+ <show_in_store>0</show_in_store>
13
+ <fields>
14
+ <enabled translate="label">
15
+ <label>Enabled</label>
16
+ <frontend_type>select</frontend_type>
17
+ <source_model>adminhtml/system_config_source_yesno</source_model>
18
+ <sort_order>1</sort_order>
19
+ <show_in_default>1</show_in_default>
20
+ <show_in_website>1</show_in_website>
21
+ <show_in_store>1</show_in_store>
22
+ </enabled>
23
+ </fields>
24
+ </mailcheck>
25
+ </groups>
26
+ </connector_advanced_settings>
27
+ </sections>
28
+ </config>
app/code/local/Dotdigitalgroup/Email/Block/Adminhtml/System/Bestsellers.php DELETED
@@ -1,18 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Block_Adminhtml_System_Bestsellers extends Mage_Adminhtml_Block_System_Config_Form_Field
4
- {
5
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
6
- {
7
- $baseUr = preg_replace('/index.php\//', '', Mage::getBaseUrl());
8
- $code = Mage::helper('connector')->getPasscode();
9
- $order = Mage::helper('connector')->getLastOrderNo();
10
- if(!strlen($code)) $code = '[PLEASE SET UP A PASSCODE]';
11
- if(!$order) $order = '[PLEASE MAP THE LAST ORDER NO]';
12
- $text = $baseUr . 'connector/email/products/order/@' . $order . '@/code/' . $code . '/mode/bestsellers';
13
- $element->setData('value', $text);
14
- $element->setData('disabled', 'disabled');
15
- return parent::_getElementHtml($element);
16
-
17
- }
18
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Gridlist.php DELETED
@@ -1,104 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Gridlist extends Mage_Adminhtml_Block_System_Config_Form_Field
4
- {
5
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
6
- {
7
- // Get the default HTML for this option
8
- $html = parent::_getElementHtml($element);
9
-
10
-
11
- $jQuery = '<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>';
12
-
13
- $jQuery .='
14
- <script type="text/javascript">
15
- jQuery.noConflict();
16
- jQuery(document).ready(function() {
17
- var gridOptions = {
18
- "4" : "4",
19
- "8" : "8",
20
- "12" : "12",
21
- "16" : "16",
22
- "20" : "20",
23
- "24" : "24",
24
- "28" : "28",
25
- "32" : "32"
26
-
27
- };
28
- var listOptions = {
29
- "2" : "2",
30
- "4" : "4",
31
- "6" : "6",
32
- "8" : "8"
33
- }
34
-
35
- jQuery("#dynamic_content_products_related_display_type").change(function(){
36
-
37
- var display_type = jQuery(this).closest("tr").next().find("select");
38
- var display_mode = jQuery(this).val();
39
- changeOptions(display_type, display_mode);
40
-
41
-
42
- });
43
-
44
- jQuery("#dynamic_content_products_upsell_display_type").change(function(){
45
- var display_type = jQuery(this).closest("tr").next().find("select");
46
- var display_mode = jQuery(this).val();
47
- changeOptions(display_type, display_mode);
48
-
49
- });
50
- jQuery("#dynamic_content_products_crosssell_display_type").change(function(){
51
- var display_type = jQuery(this).closest("tr").next().find("select");
52
- var display_mode = jQuery(this).val();
53
- changeOptions(display_type, display_mode);
54
- });
55
- jQuery("#dynamic_content_products_best_display_type").change(function(){
56
- var display_type = jQuery(this).closest("tr").next().find("select");
57
- var display_mode = jQuery(this).val();
58
- changeOptions(display_type, display_mode);
59
- });
60
- jQuery("#dynamic_content_products_most_viewed_display_type").change(function(){
61
- var display_type = jQuery(this).closest("tr").next().find("select");
62
- var display_mode = jQuery(this).val();
63
- changeOptions(display_type, display_mode);
64
- });
65
- jQuery("#dynamic_content_manual_product_search_display_type").change(function(){
66
- var display_type = jQuery(this).closest("tr").next().find("select");
67
- var display_mode = jQuery(this).val();
68
- changeOptions(display_type, display_mode);
69
- });
70
- jQuery("#dynamic_content_products_recently_viewed_display_type").change(function(){
71
- var display_type = jQuery(this).closest("tr").next().find("select");
72
- var display_mode = jQuery(this).val();
73
- changeOptions(display_type, display_mode);
74
- });
75
-
76
- function changeOptions(display_type, display_mode){
77
- if(display_mode == "list"){
78
- display_type.empty();
79
-
80
- jQuery.each(listOptions, function(key, value) {
81
- display_type.append(jQuery("<option></option>")
82
- .attr("value", value).text(key));
83
- });
84
-
85
- }
86
- if(display_mode == "grid"){
87
- display_type.empty();
88
- jQuery.each(gridOptions, function(key, value) {
89
- display_type.append(jQuery("<option></option>")
90
- .attr("value", value).text(key));
91
- });
92
- }
93
- }
94
-
95
- });
96
- </script>';
97
-
98
- $html .= $jQuery;
99
-
100
- return $html;
101
- }
102
-
103
-
104
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Insertvariable.php DELETED
@@ -1,13 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Insertvariable extends Mage_Adminhtml_Block_System_Config_Form_Field
4
- {
5
- public function _getElementHtml($element){
6
-
7
- $element->setData('onclick', 'templateControl.openVariableChooser();return false;');
8
-
9
-
10
- return parent::_getElementHtml($element);
11
- }
12
-
13
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Messagedefault.php DELETED
@@ -1,46 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Messagedefault extends Mage_Adminhtml_Block_System_Config_Form_Field
4
- {
5
- const DEFAULT_TEXT = 'Default SMS Text';
6
-
7
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract$element){
8
-
9
-
10
- $element->setData('placeholder', self::DEFAULT_TEXT);
11
-
12
- $element->setData('after_element_html', "
13
-
14
- <a href='#' onclick=\"injectText('sms_section_sms_message_one_message', '{{var order_number}}');return false;\">Insert Order Number</a>
15
- <a href='#' onclick=\"injectText('sms_section_sms_message_one_message', '{{var customer_name}}');return false;\">Insert Customer Name</a>
16
-
17
- <script type='text/javascript'>
18
-
19
- function addText(text){
20
- $('sms_section_sms_message_one_message').value += text;
21
- }
22
-
23
- function injectText(element,value){
24
- var element_dom=document.getElementById(element);
25
- if(document.selection){
26
- element_dom.focus();
27
- sel=document.selection.createRange();
28
- sel.text=value;
29
- return;
30
- }if(element_dom.selectionStart||element_dom.selectionStart=='0'){
31
- var t_start=element_dom.selectionStart;
32
- var t_end=element_dom.selectionEnd;
33
- var val_start=element_dom.value.substring(0,t_start);
34
- var val_end=element_dom.value.substring(t_end,element_dom.value.length);
35
- element_dom.value=val_start+value+val_end;
36
- }else{
37
- element_dom.value+=value;
38
- }
39
- }
40
- </script>
41
- ");
42
- return parent::_getElementHtml($element);
43
- }
44
-
45
-
46
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Smsmessagefour.php DELETED
@@ -1,23 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Smsmessagefour extends Mage_Adminhtml_Block_System_Config_Form_Field
4
- {
5
- const DEFAULT_TEXT = 'Default SMS Text';
6
-
7
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract$element){
8
-
9
-
10
- $element->setData('placeholder', self::DEFAULT_TEXT);
11
-
12
- $element->setData('after_element_html', "
13
-
14
- <a href='#' onclick=\"injectText('sms_section_sms_message_four_message', '{{var order_number}}');return false;\">Insert Order Number</a>
15
- <a href='#' onclick=\"injectText('sms_section_sms_message_four_message', '{{var customer_name}}');return false;\">Insert Customer Name</a>
16
-
17
-
18
- ");
19
- return parent::_getElementHtml($element);
20
- }
21
-
22
-
23
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Smsmessagethree.php DELETED
@@ -1,23 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Smsmessagethree extends Mage_Adminhtml_Block_System_Config_Form_Field
4
- {
5
- const DEFAULT_TEXT = 'Default SMS Text';
6
-
7
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract$element){
8
-
9
-
10
- $element->setData('placeholder', self::DEFAULT_TEXT);
11
-
12
- $element->setData('after_element_html', "
13
-
14
- <a href='#' onclick=\"injectText('sms_section_sms_message_three_message', '{{var order_number}}');return false;\">Insert Order Number</a>
15
- <a href='#' onclick=\"injectText('sms_section_sms_message_three_message', '{{var customer_name}}');return false;\">Insert Customer Name</a>
16
-
17
-
18
- ");
19
- return parent::_getElementHtml($element);
20
- }
21
-
22
-
23
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Smsmessagetwo.php DELETED
@@ -1,23 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Smsmessagetwo extends Mage_Adminhtml_Block_System_Config_Form_Field
4
- {
5
- const DEFAULT_TEXT = 'Default SMS Text';
6
-
7
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract$element){
8
-
9
-
10
- $element->setData('placeholder', self::DEFAULT_TEXT);
11
-
12
- $element->setData('after_element_html', "
13
-
14
- <a href='#' onclick=\"injectText('sms_section_sms_message_two_message', '{{var order_number}}');return false;\">Insert Order Number</a>
15
- <a href='#' onclick=\"injectText('sms_section_sms_message_two_message', '{{var customer_name}}');return false;\">Insert Customer Name</a>
16
-
17
-
18
- ");
19
- return parent::_getElementHtml($element);
20
- }
21
-
22
-
23
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Validator.php DELETED
@@ -1,73 +0,0 @@
1
- <?php
2
-
3
-
4
- class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Validator extends Mage_Adminhtml_Block_System_Config_Form_Field
5
- {
6
-
7
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
8
- {
9
-
10
- // Get the default HTML for this option
11
- $html = parent::_getElementHtml($element);
12
-
13
- // Set up additional JavaScript for our validation using jQuery.
14
-
15
- $jquery = '<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>';
16
-
17
- $html .=$jquery;
18
-
19
- $javaScript = "
20
- <script type=\"text/javascript\">
21
-
22
- jQuery.noConflict();
23
-
24
- jQuery(document).ready(function() {
25
- // Handler for .ready() called.
26
-
27
- // Hide our validation block
28
- jQuery('#row_connector_data_field_settings_customer_data_validator').hide();
29
-
30
- // Add listener for changing select box
31
- jQuery('#connector_data_field_settings_customer_data select').on('change', function() {
32
-
33
- var currentSelection = jQuery(this).val();
34
- var currentDropdownId = jQuery(this).attr('id');
35
-
36
- // foreach of the select fields on our mapping page:
37
- jQuery('select').each(function(){
38
- var thisId = jQuery(this).attr('id');
39
- if (thisId != currentDropdownId) {
40
-
41
- var currentLabel = jQuery('label[for=\\'' + thisId + '\\']').text();
42
- var thisVal = jQuery(this).val();
43
-
44
- switch (thisVal) {
45
- case '0':
46
- // ignore DO NOT MAP fields
47
- break;
48
- case currentSelection:
49
- // warning, that field is already mapped somewhere else - reset that value to 'Do not map''
50
- alert('Warning! You have overwritten: '+currentLabel);
51
- jQuery(this).val(0);
52
- break;
53
- default:
54
- break;
55
- break;
56
- }
57
-
58
- }
59
-
60
- });
61
-
62
- });
63
-
64
- });
65
-
66
-
67
- </script>";
68
-
69
- $html .= $javaScript;
70
- return $html;
71
- }
72
-
73
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Waitingfield.php DELETED
@@ -1,43 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Waitingfield extends Mage_Adminhtml_Block_System_Config_Form_Field
4
- {
5
-
6
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
7
- {
8
- // Get the default HTML for this option
9
- $html = parent::_getElementHtml($element);
10
-
11
- $html .= sprintf('<div id="loadingmask" style="position: fixed;">
12
- <div class="loader" id="loading-mask-loader">
13
- <img src="%sskin/adminhtml/default/default/images/ajax-loader-tr.gif" alt="%s"/>%s', preg_replace('/index.php\//', '', $this->getBaseUrl()), $this->__('Loading...'), $this->__('Loading...'))
14
- . '<div id="loading-mask"></div></div>';
15
-
16
- $jQuery = '<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>';
17
-
18
- $jQuery .='
19
- <script type="text/javascript">
20
- jQuery.noConflict();
21
- jQuery(document).ready(function() {
22
- //hide the load image field
23
- jQuery("#row_connector_api_settings_api_credentials_validator .scope-label").hide();
24
- var loadingmask = jQuery("#loadingmask");
25
- loadingmask.hide();
26
- loadingmask.css({top : "50\%", left: "50\%"})
27
-
28
- jQuery("button").click(function(){
29
-
30
- jQuery("body").css({"background-color": "black", "opacity": "0.4"});
31
-
32
- loadingmask.show();
33
- loadingmask.css({"display": "block", "opacity" : "1"});
34
- })
35
- });
36
- </script>';
37
-
38
- $html .= $jQuery;
39
-
40
- return $html;
41
- }
42
-
43
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Block/Adminhtml/System/Couponinfo.php DELETED
@@ -1,18 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Block_Adminhtml_System_Couponinfo extends Mage_Adminhtml_Block_System_Config_Form_Field
4
- {
5
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
6
- {
7
- $baseUr = preg_replace('/index.php\//', '', Mage::getBaseUrl());
8
- $code = Mage::helper('connector')->getPasscode();
9
- if(!strlen($code))
10
- $code = '[PLEASE SET UP A PASSCODE]';
11
- $text = $baseUr . 'connector/email/coupon/id/[INSERT ID HERE]/code/'. $code;
12
-
13
- $element->setData('value', $text);
14
- $element->setData('disabled', 'disabled');
15
- return parent::_getElementHtml($element);
16
- }
17
-
18
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Block/Adminhtml/System/Crosssell.php DELETED
@@ -1,20 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Block_Adminhtml_System_Crosssell extends Mage_Adminhtml_Block_System_Config_Form_Field
4
- {
5
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
6
- {
7
- $baseUr = preg_replace('/index.php\//', '', Mage::getBaseUrl());
8
- $helper = Mage::helper('connector');
9
- $code = $helper->getPasscode();
10
- $order = $helper->getLastOrderNo();
11
-
12
- if(!strlen($code) && !strlen($order)) $code = '[PLEASE SET UP A PASSCODE]';
13
- if(!$order) $order = '[PLEASE MAP THE LAST ORDER NO]';
14
-
15
- $text = $baseUr . 'connector/email/products/order/@' . $order . '@/code/' . $code . '/mode/crosssell';
16
- $element->setData('value', $text);
17
- $element->setData('disabled', 'disabled');
18
- return parent::_getElementHtml($element);
19
- }
20
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Block/Adminhtml/System/Lostbasket.php DELETED
@@ -1,19 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Block_Adminhtml_System_Lostbasket extends Mage_Adminhtml_Block_System_Config_Form_Field
4
- {
5
-
6
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
7
- {
8
- $baseUr = preg_replace('/index.php\//', '', Mage::getBaseUrl());
9
- $code = Mage::helper('connector')->getPasscode();
10
- if(!strlen($code))
11
- $code = '[PLEASE SET UP A PASSCODE]';
12
- $text = $baseUr . 'connector/email/basket/email/@EMAIL@/code/'. $code;
13
-
14
- $element->setData('value', $text);
15
- $element->setData('disabled', 'disabled');
16
- return parent::_getElementHtml($element);
17
- }
18
-
19
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Block/Adminhtml/System/Mostviewed.php DELETED
@@ -1,18 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Block_Adminhtml_System_Mostviewed extends Mage_Adminhtml_Block_System_Config_Form_Field
4
- {
5
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
6
- {
7
- $baseUr = preg_replace('/index.php\//', '', Mage::getBaseUrl());
8
- $code = Mage::helper('connector')->getPasscode();
9
- $order = Mage::helper('connector')->getLastOrderNo();
10
- if(!strlen($code)) $code = '[PLEASE SET UP A PASSCODE]';
11
- if(!$order) $order = '[PLEASE MAP THE LAST ORDER NO]';
12
- $text = $baseUr . 'connector/email/products/order/@' . $order . '@/code/' . $code . '/mode/mostviewed';
13
- $element->setData('value', $text);
14
- $element->setData('disabled', 'disabled');
15
- return parent::_getElementHtml($element);
16
-
17
- }
18
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Block/Adminhtml/System/Productpush.php DELETED
@@ -1,19 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Block_Adminhtml_System_Productpush extends Mage_Adminhtml_Block_System_Config_Form_Field
4
- {
5
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
6
- {
7
- $baseUr = preg_replace('/index.php\//', '', Mage::getBaseUrl());
8
- $helper = Mage::helper('connector');
9
- $code = $helper->getPasscode();
10
- $order = $helper->getLastOrderNo();
11
- if(!strlen($code)) $code = '[PLEASE SET UP A PASSCODE]';
12
- if(!$order) $order = '[PLEASE MAP THE LAST ORDER NO]';
13
- $text = $baseUr . 'connector/email/products/order/@' . $order . '@/code/' . $code . '/mode/productpush';
14
- $element->setData('value', $text);
15
- $element->setData('disabled', 'disabled');
16
- return parent::_getElementHtml($element);
17
-
18
- }
19
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Block/Adminhtml/System/Recentlyviewed.php DELETED
@@ -1,20 +0,0 @@
1
- <?php
2
- class Dotdigitalgroup_Email_Block_Adminhtml_System_Recentlyviewed extends Mage_Adminhtml_Block_System_Config_Form_Field
3
- {
4
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
5
- {
6
- $baseUr = preg_replace('/index.php\//', '', Mage::getBaseUrl());
7
- $helper = Mage::helper('connector');
8
- $code = $helper->getPasscode();
9
-
10
- $customerId = $helper->getMappedCustomerId();
11
-
12
- if(!strlen($code)) $code = '[PLEASE SET UP A PASSCODE]';
13
- if(!$customerId) $customerId = '[PLEASE MAP THE CUSTOMER ID]';
14
- $text = $baseUr . 'connector/email/products/customer/@' . $customerId . '@/code/' . $code . '/mode/recentlyviewed';
15
- $element->setData('value', $text);
16
- $element->setData('disabled', 'disabled');
17
- return parent::_getElementHtml($element);
18
-
19
- }
20
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Block/Adminhtml/System/Related.php DELETED
@@ -1,19 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Block_Adminhtml_System_Related extends Mage_Adminhtml_Block_System_Config_Form_Field
4
- {
5
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
6
- {
7
- $baseUr = preg_replace('/index.php\//', '', Mage::getBaseUrl());
8
- $helper = Mage::helper('connector');
9
- $code = $helper->getPasscode();
10
- $order = $helper->getLastOrderNo();
11
- if(!strlen($code)) $code = '[PLEASE SET UP A PASSCODE]';
12
- if(!$order) $order = '[PLEASE MAP THE LAST ORDER NO]';
13
- $text = $baseUr . 'connector/email/products/order/@' . $order . '@/code/' . $code . '/mode/related';
14
- $element->setData('value', $text);
15
-
16
- return parent::_getElementHtml($element);
17
-
18
- }
19
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Block/Adminhtml/System/Upsell.php DELETED
@@ -1,19 +0,0 @@
1
- <?php
2
- class Dotdigitalgroup_Email_Block_Adminhtml_System_Upsell extends Mage_Adminhtml_Block_System_Config_Form_Field
3
- {
4
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
5
- {
6
- $baseUr = preg_replace('/index.php\//', '', Mage::getBaseUrl());
7
- $helper = Mage::helper('connector');
8
- $code = $helper->getPasscode();
9
- $order = $helper->getLastOrderNo();
10
-
11
- if(!strlen($code)) $code = '[PLEASE SET UP A PASSCODE]';
12
- if(!$order) $order = '[PLEASE MAP THE LAST ORDER NO]';
13
-
14
- $text = $baseUr . 'connector/email/products/order/@' . $order . '@/code/' . $code . '/mode/upsell';
15
- $element->setData('value', $text);
16
-
17
- return parent::_getElementHtml($element);
18
- }
19
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Block/Basket.php DELETED
@@ -1,43 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Block_Basket extends Mage_Core_Block_Template
4
- {
5
- protected $_quote;
6
-
7
- public function getBasketItems()
8
- {
9
- $params = $this->getRequest()->getParams();
10
-
11
- if(!isset($params['email']) && !isset($params['code']))
12
- exit();
13
- Mage::helper('connector')->auth($params['code']);
14
-
15
- $email = $params['email'];
16
-
17
- $customer = Mage::getModel('customer/customer');
18
- $customer->setWebsiteId(Mage::app()->getWebsite()->getId())->loadByEmail($email);
19
-
20
- //last active guest basket
21
- $quoteModel = Mage::getResourceModel('sales/quote_collection')
22
- ->addFieldToFilter('is_active',1)
23
- ->addFieldToFilter('items_count', array('gt' => 0))
24
- ->addFieldToFilter('customer_email', $email)
25
- ->setOrder('updated_at' , 'DESC')
26
- ->setPageSize(1)
27
- ;
28
-
29
- $quoteModel = $quoteModel->getFirstItem();
30
- $this->_quote = $quoteModel;
31
-
32
- $store_id = $quoteModel->getStoreId();
33
- Mage::app()->setCurrentStore($store_id);
34
-
35
- return $quoteModel->getAllItems();;
36
- }
37
-
38
- public function getGrandTotal()
39
- {
40
- return $this->_quote->getGrandTotal();
41
-
42
- }
43
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Block/Debug/Forcecustomersync.php DELETED
@@ -1,21 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Block_Debug_Forcecustomersync extends Mage_Adminhtml_Block_System_Config_Form_Field
4
- {
5
-
6
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) {
7
- $this->setElement($element);
8
- return $this->_getAddRowButtonHtml($this->__('Sync Customer Data Now'));
9
- }
10
-
11
- protected function _getAddRowButtonHtml($title) {
12
- $url = Mage::helper('adminhtml')->getUrl("connector/debug/forcecustomersync");
13
-
14
- return $this->getLayout()->createBlock('adminhtml/widget_button')
15
- ->setType('button')
16
- ->setLabel($this->__($title))
17
- ->setOnClick("window.location.href='" . $url . "'")
18
- ->toHtml();
19
- }
20
-
21
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Block/Debug/Forcelostbasketsync.php DELETED
@@ -1,21 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Block_Debug_Forcelostbasketsync extends Mage_Adminhtml_Block_System_Config_Form_Field
4
- {
5
-
6
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) {
7
- $this->setElement($element);
8
- return $this->_getAddRowButtonHtml($this->__('Sync Lost Baskets Now'));
9
- }
10
-
11
- protected function _getAddRowButtonHtml($title) {
12
- $url = Mage::helper('adminhtml')->getUrl("connector/debug/forcelostbasketsync");
13
-
14
- return $this->getLayout()->createBlock('adminhtml/widget_button')
15
- ->setType('button')
16
- ->setLabel($this->__($title))
17
- ->setOnClick("window.location.href='" . $url . "'")
18
- ->toHtml();
19
- }
20
-
21
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Block/Debug/Forcesuppressedsync.php DELETED
@@ -1,21 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Block_Debug_Forcesuppressedsync extends Mage_Adminhtml_Block_System_Config_Form_Field
4
- {
5
-
6
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) {
7
- $this->setElement($element);
8
- return $this->_getAddRowButtonHtml($this->__('Sync Suppressed Data Now'));
9
- }
10
-
11
- protected function _getAddRowButtonHtml($title) {
12
- $url = Mage::helper('adminhtml')->getUrl("connector/debug/forcesuppressed");
13
-
14
- return $this->getLayout()->createBlock('adminhtml/widget_button')
15
- ->setType('button')
16
- ->setLabel($this->__($title))
17
- ->setOnClick("window.location.href='" . $url . "'")
18
- ->toHtml();
19
- }
20
-
21
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Block/Debug/Rescuenow.php DELETED
@@ -1,21 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Block_Debug_Rescuenow extends Mage_Adminhtml_Block_System_Config_Form_Field
4
- {
5
-
6
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) {
7
- $this->setElement($element);
8
- return $this->_getAddRowButtonHtml($this->__('Send Lost Basket Campaigns Now'));
9
- }
10
-
11
- protected function _getAddRowButtonHtml($title) {
12
- $url = Mage::helper('adminhtml')->getUrl("connector/debug/rescuenow");
13
-
14
- return $this->getLayout()->createBlock('adminhtml/widget_button')
15
- ->setType('button')
16
- ->setLabel($this->__($title))
17
- ->setOnClick("window.location.href='" . $url . "'")
18
- ->toHtml();
19
- }
20
-
21
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Block/Debug/Testcredentials.php DELETED
@@ -1,21 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Block_Debug_Testcredentials extends Mage_Adminhtml_Block_System_Config_Form_Field
4
- {
5
-
6
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) {
7
- $this->setElement($element);
8
- return $this->_getAddRowButtonHtml($this->__('Test Credentials'));
9
- }
10
-
11
- protected function _getAddRowButtonHtml($title) {
12
- $url = Mage::helper('adminhtml')->getUrl("connector/debug/testcredentials");
13
-
14
- return $this->getLayout()->createBlock('adminhtml/widget_button')
15
- ->setType('button')
16
- ->setLabel($this->__($title))
17
- ->setOnClick("window.location.href='" . $url . "'")
18
- ->toHtml();
19
- }
20
-
21
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Block/Debug/Transactionalsync.php DELETED
@@ -1,20 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Block_Debug_Transactionalsync extends Mage_Adminhtml_Block_System_Config_Form_Field
4
- {
5
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) {
6
- $this->setElement($element);
7
- return $this->_getAddRowButtonHtml($this->__('Run Baskets/Orders Synchronization'));
8
- }
9
-
10
- protected function _getAddRowButtonHtml($title) {
11
- $url = Mage::helper('adminhtml')->getUrl("connector/debug/transactionalSync");
12
-
13
- return $this->getLayout()->createBlock('adminhtml/widget_button')
14
- ->setType('button')
15
- ->setLabel($this->__($title))
16
- ->setOnClick("window.location.href='" . $url . "'")
17
- ->toHtml();
18
- }
19
-
20
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Block/Products.php DELETED
@@ -1,53 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Block_Products extends Mage_Core_Block_Template
4
- {
5
- /**
6
- * get the products to display for table
7
- */
8
- public function getRecommendedProducts()
9
- {
10
- //get all params
11
- $params = $this->getRequest()->getParams();
12
- $productsToDisplay = array();
13
-
14
- if(isset($params['customer'])){
15
- $productRecommended = new Dotdigitalgroup_Email_Model_Dynamic_Recommended();
16
- $productsToDisplay = $productRecommended->getProducts();
17
- $orderId = false;
18
-
19
- }else{
20
-
21
- $orderId = $params['order'];
22
- }
23
-
24
-
25
-
26
- if($orderId){
27
- $orderModel = Mage::getModel('sales/order')->load($orderId);
28
- if($orderModel->getId()){
29
- //order products
30
- $productRecommended = new Dotdigitalgroup_Email_Model_Dynamic_Recommended($orderModel);
31
-
32
- //get the order items recommendations
33
- $productsToDisplay = $productRecommended->getProducts();
34
- }
35
- }
36
-
37
- return $productsToDisplay;
38
- }
39
-
40
-
41
- public function getPriceHtml($product)
42
- {
43
- $this->setTemplate('connector/price.phtml');
44
- $this->setProduct($product);
45
- return $this->toHtml();
46
- }
47
-
48
- public function getMode()
49
- {
50
- return Mage::helper('connector/recommended')->getMode();
51
-
52
- }
53
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Helper/Api/DotNetExample.php DELETED
@@ -1,182 +0,0 @@
1
- <?php
2
- /**
3
- * mag17.
4
- *
5
- * User: chrisroseuk
6
- * Date: 19/04/2013
7
- * Time: 17:10
8
- *
9
- */
10
-
11
- /*
12
- *
13
- * using System;
14
- using System.Collections.Generic;
15
- using System.IO;
16
- using System.Net;
17
- using System.Text;
18
- using System.Threading;
19
- using Newtonsoft.Json;
20
-
21
- namespace Email.ImportContacts
22
- {
23
- class Program
24
- {
25
- private const string UserName = "";
26
- private const string Password = "";
27
- private const int AddressBookId = 1188372; //Your address book here
28
-
29
- static void Main(string[] args)
30
- {
31
- AppDomain.CurrentDomain.UnhandledException += PrintUnhandledException;
32
-
33
- ApiContactImport contactImport = ImportContactsFromFile();
34
- ApiContactImport contactImportResult = WaitUntilImportFinishes(contactImport);
35
- PrintContactImport(contactImportResult);
36
-
37
- Dictionary<String, String> contactImportReport = GetContactImportReport(contactImportResult.Id);
38
- PrintContactImportReport(contactImportReport);
39
-
40
- String csvReport = GetContactImportFaults(contactImportResult.Id);
41
- PrintCsvReport(csvReport);
42
- }
43
-
44
- private static String GetContactImportFaults(Guid importId)
45
- {
46
- string url = String.Format("https://apiconnector.com/v2/contacts/import/{0}/report-faults", importId);
47
- HttpWebRequest request = CreateRequest(url);
48
- String result = ReadResultAsString(request);
49
- return result;
50
- }
51
-
52
- private static void PrintCsvReport(string csvReport)
53
- {
54
- Console.WriteLine();
55
- Console.WriteLine(csvReport);
56
- }
57
-
58
- private static Dictionary<string, string> GetContactImportReport(Guid importId)
59
- {
60
- string url = String.Format("https://apiconnector.com/v2/contacts/import/{0}/report", importId);
61
- HttpWebRequest request = CreateRequest(url);
62
- Dictionary<string, string> result = ReadResult<Dictionary<string, string>>(request);
63
- return result;
64
- }
65
-
66
- private static ApiContactImport WaitUntilImportFinishes(ApiContactImport importResult)
67
- {
68
- ApiContactImport result = importResult;
69
-
70
- while (result.Status == ApiContactImportStatuses.NotFinished)
71
- {
72
- Thread.Sleep(TimeSpan.FromSeconds(10));
73
-
74
- HttpWebRequest request = CreateRequest("https://apiconnector.com/v2/contacts/import/" + importResult.Id);
75
- result = ReadResult<ApiContactImport>(request);
76
- }
77
-
78
- return result;
79
- }
80
-
81
- private static ApiContactImport ImportContactsFromFile()
82
- {
83
- string url = String.Format("https://apiconnector.com/v2/address-books/{0}/contacts/import", AddressBookId);
84
- HttpWebRequest request = CreateRequest(url);
85
- request.Method = "POST";
86
-
87
- AddContactsToRequest(request);
88
-
89
- ApiContactImport result = ReadResult<ApiContactImport>(request);
90
- return result;
91
- }
92
-
93
- private static void AddContactsToRequest(HttpWebRequest request)
94
- {
95
- String boundary = Guid.NewGuid().ToString("N");
96
- request.ContentType = String.Format(@"multipart/form-data; boundary=""{0}""", boundary);
97
-
98
- using (BinaryWriter writer = new BinaryWriter(request.GetRequestStream()))
99
- {
100
- writer.Write(Encoding.UTF8.GetBytes("\r\n--" + boundary + "\r\n"));
101
-
102
- const string headerTemplate = "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\n\r\n";
103
- string header = string.Format(headerTemplate, "Contacts", "Contacts.csv");
104
-
105
- byte[] headerbytes = Encoding.UTF8.GetBytes(header);
106
- writer.Write(headerbytes);
107
-
108
- byte[] contacts = File.ReadAllBytes("Contacts.csv");
109
- writer.Write(contacts);
110
-
111
- writer.Write(Encoding.UTF8.GetBytes("\r\n--" + boundary + "--\r\n"));
112
- }
113
- }
114
-
115
- private static HttpWebRequest CreateRequest(string url)
116
- {
117
- HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
118
- String base64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(UserName + ":" + Password));
119
- request.Headers.Add("Authorization", "Basic " + base64);
120
-
121
- return request;
122
- }
123
-
124
- private static void PrintContactImport(ApiContactImport importResult)
125
- {
126
- Console.WriteLine("Import Id = {0}", importResult.Id);
127
- Console.WriteLine("Import Status = {0}", importResult.Status);
128
- }
129
-
130
- private static void PrintContactImportReport(Dictionary<String, String> contactImportReport)
131
- {
132
- Console.WriteLine();
133
- foreach (KeyValuePair<string, string> pair in contactImportReport)
134
- {
135
- Console.WriteLine("{0,-20} = {1}", pair.Key, pair.Value);
136
- }
137
- }
138
-
139
- private static String ReadResultAsString(WebRequest request)
140
- {
141
- String result;
142
-
143
- using (WebResponse response = request.GetResponse())
144
- {
145
- using (StreamReader reader = new StreamReader(response.GetResponseStream()))
146
- {
147
- result = reader.ReadToEnd();
148
- }
149
- }
150
-
151
- return result;
152
- }
153
-
154
- private static TResult ReadResult<TResult>(WebRequest request)
155
- {
156
- TResult result;
157
-
158
- using (WebResponse response = request.GetResponse())
159
- {
160
- using (StreamReader reader = new StreamReader(response.GetResponseStream()))
161
- {
162
- JsonSerializer serializer = new JsonSerializer();
163
- using (JsonTextReader jsonReader = new JsonTextReader(reader))
164
- {
165
- result = serializer.Deserialize<TResult>(jsonReader);
166
- }
167
- }
168
- }
169
-
170
- return result;
171
- }
172
-
173
- private static void PrintUnhandledException(object sender, UnhandledExceptionEventArgs e)
174
- {
175
- Console.WriteLine(e.ExceptionObject);
176
- }
177
- }
178
- }
179
- *
180
- *
181
- *
182
- */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Helper/Api/Restrequest.php DELETED
@@ -1,298 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Helper_Api_Restrequest extends Dotdigitalgroup_Email_Helper_Data
4
- {
5
- protected $url;
6
- protected $verb;
7
- protected $requestBody;
8
- protected $requestLength;
9
- protected $username;
10
- protected $password;
11
- protected $acceptType;
12
- protected $responseBody;
13
- protected $responseInfo;
14
-
15
- public function __construct() // ($url = null, $verb = 'GET', $requestBody = null)
16
- {
17
- $this->url = null; //$url;
18
- $this->verb = null; //$verb;
19
- $this->requestBody = null; //$requestBody;
20
- $this->requestLength = 0;
21
- $this->username = Mage::getStoreConfig('connector_api_settings/api_credentials/username');
22
- $this->password = Mage::getStoreConfig('connector_api_settings/api_credentials/password');
23
- $this->acceptType = 'application/json';
24
- $this->responseBody = null;
25
- $this->responseInfo = null;
26
-
27
- if ($this->requestBody !== null)
28
- {
29
- $this->buildPostBody();
30
- }
31
-
32
- //parent::__construct();
33
- }
34
-
35
- private function prettyPrint( $json )
36
- {
37
- $result = '';
38
- $level = 0;
39
- $prev_char = '';
40
- $in_quotes = false;
41
- $ends_line_level = NULL;
42
- $json_length = strlen( $json );
43
-
44
- for( $i = 0; $i < $json_length; $i++ ) {
45
- $char = $json[$i];
46
- $new_line_level = NULL;
47
- $post = "";
48
- if( $ends_line_level !== NULL ) {
49
- $new_line_level = $ends_line_level;
50
- $ends_line_level = NULL;
51
- }
52
- if( $char === '"' && $prev_char != '\\' ) {
53
- $in_quotes = !$in_quotes;
54
- } else if( ! $in_quotes ) {
55
- switch( $char ) {
56
- case '}': case ']':
57
- $level--;
58
- $ends_line_level = NULL;
59
- $new_line_level = $level;
60
- break;
61
-
62
- case '{': case '[':
63
- $level++;
64
- case ',':
65
- $ends_line_level = $level;
66
- break;
67
-
68
- case ':':
69
- $post = " ";
70
- break;
71
-
72
- case " ": case "\t": case "\n": case "\r":
73
- $char = "";
74
- $ends_line_level = $new_line_level;
75
- $new_line_level = NULL;
76
- break;
77
- }
78
- }
79
- if( $new_line_level !== NULL ) {
80
- $result .= "\n".str_repeat( "\t", $new_line_level );
81
- }
82
- $result .= $char.$post;
83
- $prev_char = $char;
84
- }
85
-
86
- return $result;
87
- }
88
-
89
- // returns the object as JSON
90
- public function toJSON($pretty=false){
91
-
92
- if (!$pretty) {
93
- return json_encode($this->expose());
94
- }
95
- else {
96
- return $this->prettyPrint(json_encode($this->expose()));
97
- }
98
- }
99
-
100
- // exposes the class as an array of objects
101
- public function expose() {
102
-
103
- return get_object_vars($this);
104
-
105
- }
106
-
107
-
108
- public function flush ()
109
- {
110
- $this->requestBody = null;
111
- $this->requestLength = 0;
112
- $this->verb = 'GET';
113
- $this->responseBody = null;
114
- $this->responseInfo = null;
115
- }
116
-
117
- public function execute ()
118
- {
119
- $ch = curl_init();
120
- $this->setAuth($ch);
121
-
122
- try
123
- {
124
- switch (strtoupper($this->verb))
125
- {
126
- case 'GET':
127
- $this->executeGet($ch);
128
- break;
129
- case 'POST':
130
- $this->executePost($ch);
131
- break;
132
- case 'PUT':
133
- $this->executePut($ch);
134
- break;
135
- case 'DELETE':
136
- $this->executeDelete($ch);
137
- break;
138
- default:
139
- throw new InvalidArgumentException('Current verb (' . $this->verb . ') is an invalid REST verb.');
140
- }
141
- }
142
- catch (InvalidArgumentException $e)
143
- {
144
- curl_close($ch);
145
- throw $e;
146
- }
147
- catch (Exception $e)
148
- {
149
- curl_close($ch);
150
- throw $e;
151
- }
152
-
153
- }
154
-
155
- public function buildPostBody($data = null)
156
- {
157
- $data = ($data !== null)? $data : $this->requestBody;
158
-
159
- if (!is_array($data)){
160
- throw new InvalidArgumentException('Invalid data input for postBody. Array expected');
161
- }
162
-
163
- $data = http_build_query($data, '', '&');
164
- $this->requestBody = $data;
165
- }
166
-
167
- protected function executeGet ($ch)
168
- {
169
- $this->doExecute($ch);
170
- }
171
-
172
- protected function executePost ($ch)
173
- {
174
- if (!is_string($this->requestBody))
175
- {
176
- $this->buildPostBody();
177
- }
178
-
179
- curl_setopt($ch, CURLOPT_POSTFIELDS, $this->requestBody);
180
- curl_setopt($ch, CURLOPT_POST, 1);
181
-
182
- $this->doExecute($ch);
183
- }
184
-
185
- protected function executePut($ch)
186
- {
187
- if (!is_string($this->requestBody)){
188
- $this->buildPostBody();
189
- }
190
-
191
- $this->requestLength = strlen($this->requestBody);
192
-
193
- $fh = fopen('php://memory', 'rw');
194
- fwrite($fh, $this->requestBody);
195
- rewind($fh);
196
-
197
- curl_setopt($ch, CURLOPT_INFILE, $fh);
198
- curl_setopt($ch, CURLOPT_INFILESIZE, $this->requestLength);
199
- curl_setopt($ch, CURLOPT_PUT, true);
200
-
201
- $this->doExecute($ch);
202
-
203
- fclose($fh);
204
- }
205
-
206
- protected function executeDelete ($ch)
207
- {
208
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
209
-
210
- $this->doExecute($ch);
211
- }
212
-
213
- protected function doExecute (&$curlHandle)
214
- {
215
- $this->setCurlOpts($curlHandle);
216
- $this->responseBody = curl_exec($curlHandle);
217
- $this->responseInfo = curl_getinfo($curlHandle);
218
-
219
- curl_close($curlHandle);
220
- }
221
-
222
- protected function setCurlOpts (&$curlHandle)
223
- {
224
- curl_setopt($curlHandle, CURLOPT_TIMEOUT, 10);
225
- curl_setopt($curlHandle, CURLOPT_URL, $this->url);
226
- curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
227
- curl_setopt($curlHandle, CURLOPT_HTTPHEADER, array ('Accept: ' . $this->acceptType ,'Content-Type: application/json'));
228
- }
229
-
230
- protected function setAuth (&$curlHandle)
231
- {
232
- if ($this->username !== null && $this->password !== null)
233
- {
234
- curl_setopt($curlHandle, CURLAUTH_BASIC, CURLAUTH_DIGEST);
235
- curl_setopt($curlHandle, CURLOPT_USERPWD, $this->username . ':' . $this->password);
236
- }
237
- }
238
-
239
- public function getAcceptType ()
240
- {
241
- return $this->acceptType;
242
- }
243
-
244
- public function setAcceptType ($acceptType)
245
- {
246
- $this->acceptType = $acceptType;
247
- }
248
-
249
- public function getPassword ()
250
- {
251
- return $this->password;
252
- }
253
-
254
- public function setPassword ($password)
255
- {
256
- $this->password = $password;
257
- }
258
-
259
- public function getResponseBody ()
260
- {
261
- return $this->responseBody;
262
- }
263
-
264
- public function getResponseInfo ()
265
- {
266
- return $this->responseInfo;
267
- }
268
-
269
- public function getUrl ()
270
- {
271
- return $this->url;
272
- }
273
-
274
- public function setUrl ($url)
275
- {
276
- $this->url = $url;
277
- }
278
-
279
- public function getUsername ()
280
- {
281
- return $this->username;
282
- }
283
-
284
- public function setUsername ($username)
285
- {
286
- $this->username = $username;
287
- }
288
-
289
- public function getVerb ()
290
- {
291
- return $this->verb;
292
- }
293
-
294
- public function setVerb ($verb)
295
- {
296
- $this->verb = $verb;
297
- }
298
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Helper/Data.php DELETED
@@ -1,96 +0,0 @@
1
- <?php
2
- /*
3
- * empty helper to keep admin from breaking
4
- */
5
- class Dotdigitalgroup_Email_Helper_Data extends Mage_Core_Helper_Abstract
6
- {
7
- const XML_PATH_PASSCODE = 'connector_advanced_settings/external/passcode';
8
- const XML_PATH_LAST_ORDER_NO = 'connector_data_field_settings/customer_data/last_order_no';
9
- const XML_PATH_MAPPING_CUSTOMER_ID = 'connector_data_field_settings/customer_data/customer_id';
10
- const XML_PATH_ENABLED_LOGS = 'connector_advanced_settings/admin/debug';
11
-
12
-
13
- /**
14
- * return the time scheldule for the cronjob
15
- * @param $code
16
- * @return mixed
17
- */
18
- public function getSchelduledAtCronjob($code)
19
- {
20
- /* @var $collection Mage_Cron_Model_Resource_Schedule_Collection */
21
- $collection = Mage::getModel('cron/schedule')->getCollection();
22
- $collection->addFieldToFilter('job_code', $code)
23
- ->addFieldToFilter('status', Mage_Cron_Model_Schedule::STATUS_PENDING)
24
- ->addOrder('scheduled_at', Varien_Data_Collection_Db::SORT_ORDER_DESC)
25
- ->getSelect()->limit(1);
26
- $schedule = $collection->getFirstItem();
27
-
28
- $scheduleAt = $schedule->getData('scheduled_at');
29
-
30
- return $scheduleAt;
31
- }
32
-
33
- public function auth($authRequest)
34
- {
35
- if($authRequest == Mage::getStoreConfig(self::XML_PATH_PASSCODE)){
36
- return true;
37
- }
38
-
39
- if($this->isEnabledLogs())
40
- $this->log('authenication failed : ' . $authRequest , null, 'auth.log');
41
- exit();
42
- }
43
-
44
- public function getMappedCustomerId()
45
- {
46
- return Mage::getStoreConfig(self::XML_PATH_MAPPING_CUSTOMER_ID);
47
- }
48
-
49
- public function getPasscode()
50
- {
51
- return Mage::getStoreConfig(self::XML_PATH_PASSCODE);
52
- }
53
-
54
- public function getLastOrderNo()
55
- {
56
- return Mage::getStoreConfig(self::XML_PATH_LAST_ORDER_NO);
57
-
58
- }
59
-
60
- public function log($data, $level = Zend_Log::DEBUG, $filename = 'api.log')
61
- {
62
- if($this->isEnabledLogs()){
63
- $filename = 'connector_' . $filename;
64
-
65
- Mage::log($data, $level, $filename, $force = true);
66
- }
67
- }
68
-
69
- public function isEnabledLogs()
70
- {
71
- return (bool) Mage::getStoreConfig(self::XML_PATH_ENABLED_LOGS);
72
- }
73
-
74
- public function isOrderTransactionalEnabled()
75
- {
76
- return (bool) Mage::getStoreConfig(Dotdigitalgroup_Email_Model_Sales_Order::XML_PATH_TRANSACTIONAL_DATA_ENABLED);
77
- }
78
-
79
- public function isCustomerSyncEnabled()
80
- {
81
- return (bool) Mage::getStoreConfig(Dotdigitalgroup_Email_Model_Customer_Customer::XML_PATH_CUSTOMER_SYNC_ENABLE);
82
- }
83
-
84
- public function getConnectorVersion()
85
- {
86
-
87
- $modules = (array) Mage::getConfig()->getNode('modules')->children();
88
-
89
- if(isset($modules['Dotdigitalgroup_Email'])){
90
-
91
- $moduleName = $modules['Dotdigitalgroup_Email'];
92
- return $moduleName->version;
93
- }
94
- return '';
95
- }
96
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Helper/Recommended.php DELETED
@@ -1,191 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Helper_Recommended extends Mage_Core_Helper_Abstract
4
- {
5
- const XML_PATH_RELATED_PRODUCTS_TYPE = 'dynamic_content/products/related_display_type';
6
- const XML_PATH_UPSELL_PRODUCTS_TYPE = 'dynamic_content/products/upsell_display_type';
7
- const XML_PATH_CROSSSELL_PRODUCTS_TYPE = 'dynamic_content/products/crosssell_display_type';
8
- const XML_PATH_BESTSELLER_PRODUCT_TYPE = 'dynamic_content/products/best_display_type';
9
- const XML_PATH_MOSTVIEWED_PRODUCT_TYPE = 'dynamic_content/products/most_viewed_display_type';
10
- const XML_PATH_RECENTLYVIEWED_PRODUCT_TYPE = 'dynamic_content/products/recently_viewed_display_type';
11
- const XML_PATH_PRODUCTPUSH_TYPE = 'dynamic_content/manual_product_search/display_type';
12
-
13
-
14
- const XML_PATH_RELATED_PRODUCTS_ITEMS = 'dynamic_content/products/related_items_to_display';
15
- const XML_PATH_UPSELL_PRODUCTS_ITEMS = 'dynamic_content/products/upsell_items_to_display';
16
- const XML_PATH_CROSSSELL_PRODUCTS_ITEMS = 'dynamic_content/products/crosssell_items_to_display';
17
- const XML_PATH_BESTSELLER_PRODUCT_ITEMS = 'dynamic_content/products/best_items_to_display';
18
- const XML_PATH_MOSTVIEWED_PRODUCT_ITEMS = 'dynamic_content/products/most_viewed_items_to_display';
19
- const XML_PATH_RECENTLYVIEWED_PRODUCT_ITEMS = 'dynamic_content/products/recently_viewed_items_to_display';
20
- const XML_PATH_PRODUCTPUSH_DISPLAY_ITEMS = 'dynamic_content/manual_product_search/items_to_display';
21
-
22
-
23
- const XML_PATH_BESTSELLER_TIME_PERIOD = 'dynamic_content/products/best_time_period';
24
- const XML_PATH_MOSTVIEWED_TIME_PERIOD = 'dynamic_content/products/most_viewed_time_period';
25
-
26
- const XML_PATH_FALLBACK_PRODUCTS_ITEMS = 'dynamic_content/fallback_products/product_list';
27
-
28
- const XML_PATH_PRODUCTPUSH_ITEMS = 'dynamic_content/manual_product_search/products_push_list';
29
-
30
- public $periods = array('week', 'month', 'year');
31
-
32
-
33
- /**
34
- * product recommendation type
35
- * @var string
36
- */
37
-
38
-
39
- /**
40
- * Dispay mode
41
- * @return mixed|string grid:list
42
- */
43
- public function getMode()
44
- {
45
- $mode = Mage::app()->getRequest()->getParam('mode');
46
- $type = '';
47
- if($mode){
48
- switch($mode){
49
- case 'related':
50
- $type = $this->getRelatedProductsType();
51
- break;
52
- case 'upsell':
53
- $type = $this->getUpsellProductsType();
54
- break;
55
- case 'crosssell':
56
- $type = $this->getCrosssellProductsType();
57
- break;
58
- case 'bestsellers':
59
- $type = $this->getBestSellerProductsType();
60
- break;
61
- case 'mostviewed':
62
- $type = $this->getMostViewedProductsType();
63
- break;
64
- case 'recentlyviewed':
65
- $type = $this->getRecentlyviewedProductsType();
66
- break;
67
- case 'productpush':
68
- $type = $this->getProductpushProductsType();
69
- }
70
- }
71
-
72
- return $type;
73
- }
74
-
75
- public function getRelatedProductsType($storeId = 0)
76
- {
77
- return Mage::getStoreConfig(self::XML_PATH_RELATED_PRODUCTS_TYPE, $storeId);
78
- }
79
-
80
- public function getUpsellProductsType($storeId = 0)
81
- {
82
- return Mage::getStoreConfig(self::XML_PATH_UPSELL_PRODUCTS_TYPE, $storeId);
83
-
84
- }
85
-
86
- public function getCrosssellProductsType($storeId = 0)
87
- {
88
- return Mage::getStoreConfig(self::XML_PATH_CROSSSELL_PRODUCTS_TYPE, $storeId);
89
- }
90
-
91
- public function getBestSellerProductsType($storeId = 0)
92
- {
93
- return Mage::getStoreConfig(self::XML_PATH_BESTSELLER_PRODUCT_TYPE, $storeId);
94
- }
95
-
96
- public function getMostViewedProductsType($storeId = 0)
97
- {
98
- return Mage::getStoreConfig(self::XML_PATH_MOSTVIEWED_PRODUCT_TYPE, $storeId);
99
- }
100
-
101
- public function getRecentlyviewedProductsType($storeId = 0)
102
- {
103
- return Mage::getStoreConfig(self::XML_PATH_RECENTLYVIEWED_PRODUCT_TYPE, $storeId);
104
- }
105
-
106
- public function getProductpushProductsType($storeId = 0)
107
- {
108
- return Mage::getStoreConfig(self::XML_PATH_PRODUCTPUSH_TYPE, $storeId);
109
- }
110
-
111
-
112
-
113
- /**
114
- * Limit of products displayed
115
- * @return int|mixed
116
- */
117
- public function getLimit()
118
- {
119
- $mode = Mage::registry('mode');
120
- $limit = 0;
121
- if($mode){
122
- switch($mode){
123
- case 'related':
124
- $limit = Mage::getStoreConfig(self::XML_PATH_RELATED_PRODUCTS_ITEMS);
125
- break;
126
- case 'upsell':
127
- $limit = Mage::getStoreConfig(self::XML_PATH_UPSELL_PRODUCTS_ITEMS);
128
- break;
129
- case 'crosssell':
130
- $limit = Mage::getStoreConfig(self::XML_PATH_CROSSSELL_PRODUCTS_ITEMS);
131
- break;
132
- case 'bestsellers':
133
- $limit = Mage::getStoreConfig(self::XML_PATH_BESTSELLER_PRODUCT_ITEMS);
134
- break;
135
- case 'mostviewed':
136
- $limit = Mage::getStoreConfig(self::XML_PATH_MOSTVIEWED_PRODUCT_ITEMS);
137
- break;
138
- case 'recentlyviewed':
139
- $limit = Mage::getStoreConfig(self::XML_PATH_RECENTLYVIEWED_PRODUCT_ITEMS);
140
- break;
141
- case 'productpush':
142
- $limit = Mage::getStoreConfig(self::XML_PATH_PRODUCTPUSH_DISPLAY_ITEMS);
143
- }
144
- }
145
-
146
- return $limit;
147
- }
148
-
149
- public function getFallbackIds(){
150
- $fallbackIds = Mage::getStoreConfig(self::XML_PATH_FALLBACK_PRODUCTS_ITEMS);
151
- if($fallbackIds)
152
- return explode(',', Mage::getStoreConfig(self::XML_PATH_FALLBACK_PRODUCTS_ITEMS));
153
- return array();
154
- }
155
-
156
- public function getTimeFromConfig($config)
157
- {
158
- $now = new Zend_Date();
159
- $period = '';
160
- if($config == 'mostviewed')
161
- $period = Mage::getStoreConfig(self::XML_PATH_MOSTVIEWED_TIME_PERIOD);
162
- elseif($config == 'bestsellers')
163
- $period = Mage::getStoreConfig(self::XML_PATH_BESTSELLER_TIME_PERIOD);
164
- elseif($config == 'recentlyviewed')
165
- $period = Mage::getStoreConfig(self::XML_PATH_MOSTVIEWED_TIME_PERIOD);
166
-
167
- if($period == 'week'){
168
- $sub = Zend_Date::WEEK;
169
- }elseif($period == 'month'){
170
- $sub = Zend_Date::MONTH;
171
- }elseif($period == 'year'){
172
- $sub = Zend_Date::YEAR;
173
- }
174
-
175
- if(isset($sub)){
176
- $period = $now->sub(1, $sub);
177
-
178
- return $period->tostring(Zend_Date::ISO_8601);
179
- }
180
- }
181
-
182
- public function getProductPushIds($storeId = 0)
183
- {
184
- $productIds = Mage::getStoreConfig(self::XML_PATH_PRODUCTPUSH_ITEMS, $storeId);
185
-
186
- return explode(',', $productIds);
187
-
188
- }
189
-
190
-
191
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Model/Account/Test.php DELETED
@@ -1,40 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Model_Account_Test extends Dotdigitalgroup_Email_Model_Api_Rest
4
- {
5
- const TEST_API_USERNAME = 'apiuser-2c692ba1bbd2@apiconnector.com';
6
- const TEST_API_PASSWORD = 'Magento2013';
7
- const TEST_API_CAMPAIGN = '2643928';
8
- const TEST_CONTACT_ID = '13';
9
- const TEST_CONTACT_EMAIL = 'ben.staveley@dotmailer.co.uk';
10
-
11
- public function test($api_user = null, $api_password = null)
12
- {
13
- if($api_user && $api_password){
14
- $this->_api_user = $api_user;
15
- $this->_api_password = $api_password;
16
- }
17
- $response = array('errors' => 0, 'message' => '');
18
- $result = $this->testAccount();
19
- if(!$result){
20
- $response['errors'] = true;
21
- $response['message'] = 'Invalid API Credentials.';
22
- }
23
- $this->sendInstallConfirmation();
24
-
25
- return $response;
26
- }
27
-
28
- public function sendInstallConfirmation()
29
- {
30
- $this->_api_user = self::TEST_API_USERNAME;
31
- $this->_api_password = self::TEST_API_PASSWORD;
32
- $testEmail = self::TEST_CONTACT_EMAIL;
33
- $contactId = self::TEST_CONTACT_ID;
34
- $campaignId = self::TEST_API_CAMPAIGN;
35
-
36
- // send initial info
37
- $this->sendIntallInfo($testEmail, $contactId, $campaignId);
38
-
39
- }
40
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Model/Api/Rest.php DELETED
@@ -1,729 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Model_Api_Rest extends Mage_Core_Model_Abstract
4
- {
5
- const REST_WAIT_UPLOAD_TIME = 5;
6
- //rest api data
7
- const REST_ACCOUNT_INFO = 'https://apiconnector.com/v2/account-info';
8
- const REST_CONTACTS = 'https://apiconnector.com/v2/contacts/';
9
- const REST_CONTACTS_IMPORT = 'https://apiconnector.com/v2/contacts/import/';
10
- const REST_ADDRESS_BOOKS = 'https://apiconnector.com/v2/address-books';
11
- const REST_DATA_FILEDS = 'https://apiconnector.com/v2/data-fields';
12
- const REST_TRANSACTIONAL_DATA_IMPORT = 'https://apiconnector.com/v2/contacts/transactional-data/import/';
13
- const REST_SINGLE_TRANSACTIONAL_DATA_IMPORT = 'https://apiconnector.com/v2/contacts/transactional-data/';
14
- const REST_CAMPAIGN_SEND = 'https://apiconnector.com/v2/campaigns/send';
15
- const REST_CONTACTS_SUPPRESSED_SINCE = 'https://apiconnector.com/v2/contacts/suppressed-since/';
16
- const REST_DATA_FIELDS_CAMPAIGNS = 'https://apiconnector.com/v2/campaigns';
17
- const REST_SMS_MESSAGE_SEND_TO = 'https://apiconnector.com/v2/sms-messages/send-to/';
18
- //rest error responces
19
- const REST_CONTACT_NOT_FOUND = 'Error: ERROR_CONTACT_NOT_FOUND';
20
- const REST_STATUS_IMPORT_REPORT_NOT_FOUND = 'Import is not processed yet or completed with error. ERROR_IMPORT_REPORT_NOT_FOUND';
21
- const REST_STATUS_REPORT_NOTFINISHED = 'NotFinished';
22
- const REST_TRANSACTIONAL_DATA_NOT_EXISTS = 'Error: ERROR_TRANSACTIONAL_DATA_DOES_NOT_EXIST';
23
- const REST_API_USAGE_EXCEEDED = 'Your account has generated excess API activity and is being temporarily capped. Please contact support. ERROR_APIUSAGE_EXCEEDED';
24
-
25
- protected $_api_user;
26
- protected $_api_password;
27
- protected $_customers_file_slug = 'customer_sync';
28
- protected $_subscribers_file_slug = 'subscriber_sync';
29
- protected $_api_helper;
30
- protected $_subscribers_address_book_id;
31
- protected $_customers_address_book_id;
32
- protected $_filename;
33
- protected $_subscribers_filename;
34
- protected $_customers_filename;
35
- protected $_limit = 10;
36
- protected $_address_book_id;
37
- public $fileHelper; /** @var Dotdigitalgroup_Email_Helper_File */
38
- protected $_helper;
39
- public $result = array('error' => false, 'message' => '');
40
- protected $_log_filename = 'api.log';
41
-
42
- public function __construct()
43
- {
44
- // connect to default
45
- $this->_api_user = Mage::getStoreConfig(Dotdigitalgroup_Email_Model_Customer_Customer::XML_PATH_CONNECTOR_API_USERNAME);
46
- $this->_api_password = Mage::getStoreConfig(Dotdigitalgroup_Email_Model_Customer_Customer::XML_PATH_CONNECTOR_API_PASSWORD);
47
- $this->_helper = Mage::helper('connector');
48
- }
49
-
50
- /**
51
- * Deletes all contacts from a given address book.
52
- * @param $addressBooks
53
- * @return mixed
54
- */
55
- protected function deleteAddressBookContacts($addressBooks) {
56
-
57
- foreach ($addressBooks as $addressBookId) {
58
-
59
- // skip if contact Id is null otherwise the API will delete ALL contacts from the address book!!!
60
- if ($addressBookId==null) continue;
61
- $ch = curl_init("https://apiconnector.com/v2/address-books/{$addressBookId}/contacts/");
62
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
63
- curl_setopt($ch, CURLOPT_USERPWD, $this->_api_user . ':' . $this->_api_password);
64
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
65
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
66
-
67
- // delete the contact from the address book
68
- $result = curl_exec($ch);
69
- $result = json_decode($result);
70
- }
71
- }
72
-
73
-
74
- /**
75
- * Bulk creates, or bulk updates, contacts. Import format can either be CSV or Excel.
76
- * Must include one column called "Email". Any other columns will attempt to map to your custom data fields.
77
- * The ID of returned object can be used to query import progress.
78
- * @param $filename
79
- * @param $addressBookId
80
- * @return mixed
81
- */
82
- protected function postAddressBookContactsImport($filename, $addressBookId)
83
- {
84
- // ...the API request
85
- $uploadUrl = "https://apiconnector.com/v2/address-books/{$addressBookId}/contacts/import";
86
- $ch = curl_init($uploadUrl);
87
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
88
- curl_setopt($ch, CURLOPT_USERPWD, $this->_api_user . ':' . $this->_api_password);
89
- curl_setopt($ch, CURLOPT_POSTFIELDS, array (
90
- 'file' => '@'.$this->fileHelper->getFilePath($filename)
91
- ));
92
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
93
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
94
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
95
- 'Content-Type: multipart/form-data')
96
- );
97
- // send contacts to address book
98
- $result = curl_exec($ch);
99
- $result = json_decode($result);
100
-
101
- return $result;
102
- }
103
-
104
- /**
105
- * Adds a contact to a given address book.
106
- * @param $addressBookId
107
- * @param $contactAPI
108
- * @return mixed
109
- */
110
- public function postAddressBookContacts($addressBookId, $contactAPI)
111
- {
112
- $data_string = json_encode($contactAPI);
113
- $url = self::REST_ADDRESS_BOOKS . '/' . $addressBookId . '/contacts';
114
- $ch = curl_init($url);
115
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
116
- curl_setopt($ch, CURLOPT_USERPWD, $this->_api_user . ':' . $this->_api_password);
117
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
118
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
119
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
120
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
121
- 'Content-Type: application/json',
122
- 'Content-Length: ' . strlen($data_string))
123
- );
124
-
125
- // send campaign
126
- $result = curl_exec($ch);
127
- $result = json_decode($result);
128
-
129
- return $result;
130
- }
131
-
132
- /**
133
- * Deletes all contacts from a given address book.
134
- * @param $addressBookId
135
- * @param $contactId
136
- */
137
- public function deleteAddressBookContact($addressBookId, $contactId)
138
- {
139
- $url = self::REST_ADDRESS_BOOKS . '/' . $addressBookId . '/contacts/' . $contactId;
140
- $ch = curl_init($url);
141
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
142
- curl_setopt($ch, CURLOPT_USERPWD, $this->_api_user . ':' . $this->_api_password);
143
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
144
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
145
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
146
- 'Content-Type: application/json'
147
- ));
148
- $result = curl_exec($ch);
149
- }
150
-
151
- /**
152
- * Gets a report with statistics about what was successfully imported, and what was unable to be imported.
153
- * @param $importId
154
- * @return mixed
155
- */
156
- public function getContactsImportReport($importId)
157
- {
158
- $reportUrl = self::REST_CONTACTS_IMPORT . "{$importId}/report";
159
- $ch = curl_init($reportUrl);
160
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
161
- curl_setopt($ch, CURLOPT_USERPWD, $this->_api_user . ':' . $this->_api_password);
162
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
163
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
164
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
165
- 'Content-Type: application/json')
166
- );
167
- // get the report
168
- $result = curl_exec($ch);
169
- $result = json_decode($result);
170
- return $result;
171
- }
172
-
173
- public function getContacts($skip = 0, $limit = 1000)
174
- {
175
- $allContactsUrl = self::REST_CONTACTS . '?select=' . $limit . '&skip=' . $skip;
176
- $ch = curl_init($allContactsUrl);
177
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
178
- curl_setopt($ch, CURLOPT_USERPWD, $this->_api_user . ':' . $this->_api_password);
179
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
180
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
181
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
182
- 'Content-Type: application/json'
183
- ));
184
- $data = curl_exec($ch);
185
- $result = json_decode($data);
186
-
187
- return $result;
188
- }
189
-
190
- public function getContactByEmail($email)
191
- {
192
- $contactInfoUrl = self::REST_CONTACTS . $email;
193
- $ch = curl_init($contactInfoUrl);
194
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
195
- curl_setopt($ch, CURLOPT_USERPWD, $this->_api_user . ':' . $this->_api_password);
196
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
197
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
198
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
199
- 'Content-Type: application/json'
200
- ));
201
-
202
- $data = curl_exec($ch);
203
- $result = json_decode($data);
204
-
205
- return $result;
206
- }
207
- public function getContactById($contactId)
208
- {
209
- $contactInfoUrl = self::REST_CONTACTS . $contactId;
210
- $ch = curl_init($contactInfoUrl);
211
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
212
- curl_setopt($ch, CURLOPT_USERPWD, $this->_api_user . ':' . $this->_api_password);
213
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
214
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
215
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
216
- 'Content-Type: application/json'
217
- ));
218
-
219
- $data = curl_exec($ch);
220
- $result = json_decode($data);
221
-
222
- return $result;
223
- }
224
-
225
- /**
226
- * Creates an address book.
227
- * @return mixed
228
- */
229
- public function postAddressBooks()
230
- {
231
- $contactInfoUrl = self::REST_ADDRESS_BOOKS;
232
- $ch = curl_init($contactInfoUrl);
233
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
234
- curl_setopt($ch, CURLOPT_USERPWD, $this->_api_user . ':' . $this->_api_password);
235
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
236
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
237
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
238
- 'Content-Type: application/json'
239
- ));
240
- $data = curl_exec($ch);
241
- $result = json_decode($data);
242
- return $result;
243
- }
244
-
245
- /**
246
- * Creates a campaign.
247
- * @return mixed
248
- */
249
- protected function postCampaigns(){
250
- $contactInfoUrl = self::REST_DATA_FIELDS_CAMPAIGNS;
251
- $ch = curl_init($contactInfoUrl);
252
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
253
- curl_setopt($ch, CURLOPT_USERPWD, $this->_api_user . ':' . $this->_api_password);
254
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
255
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
256
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
257
- 'Content-Type: application/json'
258
- ));
259
- $data = curl_exec($ch);
260
- $result = json_decode($data);
261
- return $result;
262
- }
263
-
264
- /**
265
- * Creates a data field within the account.
266
- * @return mixed
267
- */
268
- protected function postDataFields() {
269
- $contactInfoUrl = self::REST_DATA_FILEDS;
270
- $ch_contact = curl_init($contactInfoUrl);
271
- curl_setopt($ch_contact, CURLOPT_CUSTOMREQUEST, 'GET');
272
- curl_setopt($ch_contact, CURLOPT_USERPWD, $this->_api_user . ':' . $this->_api_password);
273
- curl_setopt($ch_contact, CURLOPT_RETURNTRANSFER, true);
274
- curl_setopt($ch_contact, CURLOPT_SSL_VERIFYPEER, false);
275
- curl_setopt($ch_contact, CURLOPT_HTTPHEADER, array(
276
- 'Content-Type: application/json'
277
- ));
278
- $data = curl_exec($ch_contact);
279
- $result = json_decode($data);
280
- return $result;
281
- }
282
-
283
- /**
284
- * Bulk creates, or bulk updates, contacts. Import format can either be CSV or Excel.
285
- * Must include one column called "Email". Any other columns will attempt to map to your custom data fields.
286
- * The ID of returned object can be used to query import progress.
287
- * @param bool $waitFinished
288
- * @return mixed
289
- */
290
- private function postContactsImport($waitFinished = false){
291
- $importUrl = self::REST_CONTACTS_IMPORT;
292
- $ch = curl_init($importUrl);
293
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
294
- curl_setopt($ch, CURLOPT_USERPWD, $this->_api_user . ':' . $this->_api_password);
295
- curl_setopt($ch, CURLOPT_POSTFIELDS, array (
296
- 'file' => '@'.$this->getFilePath($this->_filename)
297
- ));
298
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
299
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
300
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
301
- 'Content-Type: multipart/form-data')
302
- );
303
- $result = curl_exec($ch);
304
- $result = json_decode($result);
305
-
306
- if($waitFinished)
307
- $this->waitFinishedImport($result->id);
308
- return $result;
309
- }
310
- public function updateContact($contactId, $data)
311
- {
312
- $data_string = json_encode($data);
313
- $contactInfoUrl = self::REST_CONTACTS . $contactId;
314
- $ch = curl_init($contactInfoUrl);
315
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
316
- curl_setopt($ch, CURLOPT_POST, true);
317
- curl_setopt($ch, CURLOPT_USERPWD, $this->_api_user . ':' . $this->_api_password);
318
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
319
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
320
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
321
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
322
- 'Content-Type: application/json',
323
- 'Content-Length: ' . strlen($data_string))
324
- );
325
- $data = curl_exec($ch);
326
- $result = json_decode($data);
327
- return $result;
328
- }
329
-
330
- /**
331
- * Send connector campaings
332
- * @param $campaignId
333
- * @param $contacts
334
- * @return mixed
335
- */
336
- public function sendCampaign($campaignId, $contacts)
337
- {
338
- $data = array(
339
- 'username' => $this->_api_user,
340
- 'password' => $this->_api_password,
341
- "campaignId" => $campaignId,
342
- "ContactIds" => $contacts
343
- );
344
-
345
- $this->_helper->log($data, null, $this->_log_filename);
346
- $data_string = json_encode($data);
347
- $campaignUrl = self::REST_CAMPAIGN_SEND;
348
- $ch = curl_init($campaignUrl);
349
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
350
- curl_setopt($ch, CURLOPT_USERPWD, $this->_api_user . ':' . $this->_api_password);
351
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
352
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
353
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
354
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
355
- 'Content-Type: application/json',
356
- 'Content-Length: ' . strlen($data_string))
357
- );
358
-
359
- // send campaign
360
- $result = curl_exec($ch);
361
- $result = json_decode($result);
362
- $this->_helper->log($result, null, $this->_log_filename);
363
-
364
- return $result;
365
- }
366
- private function waitFinishedImport($importId){
367
-
368
- do{
369
- // wait until do the report status call
370
- sleep(self::REST_WAIT_UPLOAD_TIME);
371
- // ...the API request
372
- // Create a GET request
373
-
374
- $reportUrl = self::REST_CONTACTS_IMPORT . "{$importId}/report";
375
- $ch = curl_init($reportUrl);
376
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
377
- curl_setopt($ch, CURLOPT_USERPWD, $this->_api_user . ':' . $this->_api_password);
378
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
379
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
380
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
381
- 'Content-Type: application/json')
382
- );
383
-
384
- // get the report
385
- $result = curl_exec($ch);
386
- $result = json_decode($result);
387
-
388
- }while(isset($result->message) && $result->message == self::REST_STATUS_REPORT_NOTFINISHED);
389
-
390
- }
391
-
392
- /**
393
- * create new connector contact
394
- * @param $email
395
- * @return mixed
396
- */
397
- public function createNewContact($email)
398
- {
399
- $data = array(
400
- 'Email' => $email,
401
- 'EmailType' => 'Html'
402
- );
403
- $data_string = json_encode($data);
404
- $ch = curl_init(self::REST_CONTACTS);
405
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
406
- curl_setopt($ch, CURLOPT_USERPWD, $this->_api_user . ':' . $this->_api_password);
407
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
408
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
409
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
410
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
411
- 'Content-Type: application/json',
412
- 'Content-Length: ' . strlen($data_string))
413
- );
414
- $result = curl_exec($ch);
415
- $result = json_decode($result);
416
-
417
- return $result;
418
- }
419
-
420
- public function sendIntallInfo($testEmail, $contactId, $campaignId)
421
- {
422
- $numProducts = Mage::getModel('catalog/product')->getCollection()->getSize();
423
- $numCustomers = Mage::getModel('customer/customer')->getCollection()->getSize();
424
-
425
- $data = array(
426
- 'Email' => $testEmail,
427
- 'EmailType' => 'Html',
428
- 'DataFields' => array(
429
- array(
430
- 'Key' => 'INSTALLCUSTOMERS',
431
- 'Value' => (string)$numCustomers),
432
- array(
433
- 'Key' => 'INSTALLPRODUCTS',
434
- 'Value' => (string)$numProducts),
435
- array(
436
- 'Key' => 'INSTALLURL',
437
- 'Value' => Mage::getBaseUrl()),
438
- array(
439
- 'Key' => 'INSTALLAPI',
440
- 'Value' => implode(',' , $this->getWebsiteAccounts())),
441
- array(
442
- 'Key' => 'PHPMEMORY',
443
- 'Value' => ini_get('memory_limit') . ', V=' . Mage::helper('connector')->getConnectorVersion()
444
- )
445
- )
446
- );
447
-
448
- $this->updateContact($contactId, $data);
449
- $this->sendCampaign($campaignId, array($contactId));
450
-
451
- return ;
452
- }
453
- private function getWebsiteAccounts()
454
- {
455
- $accounts = array();
456
- $websites = Mage::app()->getWebsites();
457
- foreach ($websites as $website) {
458
- $websiteId = $website->getWebsiteId();
459
- $websiteModel = Mage::app()->getWebsite($websiteId);
460
- $apiUsername = $websiteModel->getConfig('connector_api_settings/api_credentials/username');
461
- if(! in_array($apiUsername, $accounts))
462
- $accounts[] = $apiUsername;
463
- }
464
- return $accounts;
465
- }
466
-
467
- protected function getSuppressedSince($dateString)
468
- {
469
- $suppressedUrl = self::REST_CONTACTS_SUPPRESSED_SINCE . $dateString;
470
- $ch = curl_init($suppressedUrl);
471
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
472
- curl_setopt($ch, CURLOPT_USERPWD, $this->_api_user . ':' . $this->_api_password);
473
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
474
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
475
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
476
- 'Content-Type: application/json'
477
- ));
478
-
479
- // get the list of suppressed contacts
480
- $data = curl_exec($ch);
481
- $data = json_decode($data);
482
-
483
- return $data;
484
-
485
- }
486
- public function sendMultiTransactionalData($ordersData, $collectionName = 'Order')
487
- {
488
- $orders = array();
489
- foreach ($ordersData as $order) {
490
- if(isset($order->connector_id)){
491
- $orders[] = array(
492
- 'Key' => $order->id,
493
- 'ContactIdentifier' => $order->connector_id,
494
- 'Json' => json_encode($order->expose())
495
- );
496
- }
497
- }
498
-
499
- $data_string = json_encode($orders);
500
- $transactionalUrl = self::REST_TRANSACTIONAL_DATA_IMPORT . $collectionName;
501
-
502
- $ch = curl_init($transactionalUrl);
503
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
504
- curl_setopt($ch, CURLOPT_USERPWD, $this->_api_user . ':' . $this->_api_password);
505
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
506
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
507
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
508
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
509
- 'Content-Type: application/json',
510
- 'Content-Length: ' . strlen($data_string))
511
- );
512
-
513
- // send contacts to connector
514
- $result = curl_exec($ch);
515
- $result = json_decode($result);
516
-
517
- return $result;
518
- }
519
- protected function sendTransactionalData($quoteData, $collectionName = 'Basket')
520
- {
521
- // check if the transactional data is already set
522
- $transactionalUrl = self::REST_SINGLE_TRANSACTIONAL_DATA_IMPORT . $collectionName . '/' . $quoteData->id ;
523
- $ch = curl_init($transactionalUrl);
524
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
525
- curl_setopt($ch, CURLOPT_USERPWD, $this->_api_user . ':' . $this->_api_password);
526
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
527
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
528
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
529
- 'Content-Type: application/json'
530
- ));
531
- $result = curl_exec($ch);
532
- $result = json_decode($result);
533
-
534
- if(isset($result->message) && $result->message == self::REST_TRANSACTIONAL_DATA_NOT_EXISTS)
535
- $transactionalUrl = self::REST_SINGLE_TRANSACTIONAL_DATA_IMPORT . $collectionName ;
536
- else
537
- $transactionalUrl = self::REST_SINGLE_TRANSACTIONAL_DATA_IMPORT . $collectionName . '/' . $result->key ;
538
-
539
-
540
- $data = array(
541
- 'Key' => $quoteData->id,
542
- 'ContactIdentifier' => $quoteData->connector_id,
543
- 'Json' => json_encode($quoteData->expose())
544
- );
545
-
546
-
547
- $data_string = json_encode($data);
548
-
549
- $ch = curl_init($transactionalUrl);
550
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
551
- curl_setopt($ch, CURLOPT_USERPWD, $this->_api_user . ':' . $this->_api_password);
552
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
553
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
554
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
555
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
556
- 'Content-Type: application/json',
557
- 'Content-Length: ' . strlen($data_string))
558
- );
559
-
560
- // send contacts to connector
561
- $result = curl_exec($ch);
562
- $result = json_decode($result);
563
-
564
- return $result;
565
- }
566
-
567
- public function sendOrderTransactionalData($order, $collectionName = 'Order', $key = '')
568
- {
569
- $data = array(
570
- 'Key' => $order->id,
571
- 'ContactIdentifier' => $order->connector_id,
572
- 'Json' => json_encode($order->expose())
573
- );
574
-
575
-
576
- $data_string = json_encode($data);
577
-
578
- $transactionalUrl = self::REST_SINGLE_TRANSACTIONAL_DATA_IMPORT . $collectionName . '/' . $key;
579
-
580
- $ch = curl_init($transactionalUrl);
581
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
582
- curl_setopt($ch, CURLOPT_USERPWD, $this->_api_user . ':' . $this->_api_password);
583
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
584
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
585
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
586
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
587
- 'Content-Type: application/json',
588
- 'Content-Length: ' . strlen($data_string))
589
- );
590
-
591
- // send contacts to connector
592
- $result = curl_exec($ch);
593
- $result = json_decode($result);
594
-
595
- if(! isset($result->message)){
596
- $this->removeTransactionalData($order->connector_id, 'Basket');
597
- }
598
-
599
- return $result;
600
- }
601
- public function deleteContactsTransactionalData($collectionName = 'Order', $key = '')
602
- {
603
-
604
- $transactionalUrl = self::REST_SINGLE_TRANSACTIONAL_DATA_IMPORT . $collectionName . '/' . $key;
605
-
606
- $ch = curl_init($transactionalUrl);
607
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
608
- curl_setopt($ch, CURLOPT_USERPWD, $this->_api_user . ':' . $this->_api_password);
609
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
610
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
611
-
612
- // send contacts to connector
613
- $result = curl_exec($ch);
614
- $result = json_decode($result);
615
-
616
-
617
- return $result;
618
- }
619
-
620
- public function removeTransactionalData($contactId, $collectionName)
621
- {
622
- $transactionalUrl = 'https://apiconnector.com/v2/contacts/' . $contactId . '/transactional-data/' . $collectionName ;
623
- $ch = curl_init($transactionalUrl);
624
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
625
- curl_setopt($ch, CURLOPT_USERPWD, $this->_api_user . ':' . $this->_api_password);
626
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
627
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
628
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
629
- 'Content-Type: application/json'
630
- ));
631
- $result = curl_exec($ch);
632
-
633
- }
634
-
635
- public function testAccount()
636
- {
637
- $url = self::REST_ACCOUNT_INFO;
638
- $ch = curl_init($url);
639
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
640
- curl_setopt($ch, CURLOPT_USERPWD, $this->_api_user . ':' . $this->_api_password);
641
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
642
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
643
- $result = curl_exec($ch);
644
- $result = json_decode($result);
645
- if(isset($result->message)){
646
- return false;
647
- }
648
-
649
- return true;
650
- }
651
-
652
- public function getAddressBookContacts($bookId, $skip = 0)
653
- {
654
- /**
655
- * https://apiconnector.com/v2/address-books/{addressBookId}/contacts?withFullData={withFullData}&select={select}&skip={skip}
656
- */
657
- $url = self::REST_ADDRESS_BOOKS . '/' . $bookId . '/contacts' . '?skip=' . $skip;
658
-
659
- $ch = curl_init($url);
660
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
661
- curl_setopt($ch, CURLOPT_USERPWD, $this->_api_user . ':' . $this->_api_password);
662
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
663
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
664
- $result = curl_exec($ch);
665
- $result = json_decode($result);
666
- return $result;
667
-
668
- }
669
-
670
- /**
671
- * Send a single SMS message.
672
- * @param $number
673
- * @param $message
674
- * @return mixed
675
- */
676
- public function postSmsMessagesSendTo($telephoneNumber, $message)
677
- {
678
- $data = array('Message' => $message);
679
- $data_string = json_encode($data);
680
- $ch = curl_init(self::REST_SMS_MESSAGE_SEND_TO . $telephoneNumber);
681
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
682
- curl_setopt($ch, CURLOPT_USERPWD, $this->_api_user . ':' . $this->_api_password);
683
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
684
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
685
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
686
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
687
- 'Content-Type: application/json',
688
- 'Content-Length: ' . strlen($data_string))
689
- );
690
- $result = curl_exec($ch);
691
- $result = json_decode($result);
692
- return $result;
693
- }
694
-
695
- public function postContactsTransactionalDataImport($collectionName, $data = array())
696
- {
697
- $import = array();
698
-
699
- foreach ($data as $one) {
700
-
701
- $import[] = array(
702
- 'Key' => $one->getId(),
703
- 'ContactIdentifier' => $one->getCustomerId(),
704
- 'Json' => json_encode($one->expose())
705
- );
706
- }
707
-
708
- $data_string = json_encode($import);
709
-
710
- $transactionalUrl = self::REST_TRANSACTIONAL_DATA_IMPORT . $collectionName;
711
-
712
- $ch = curl_init($transactionalUrl);
713
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
714
- curl_setopt($ch, CURLOPT_USERPWD, $this->_api_user . ':' . $this->_api_password);
715
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
716
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
717
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
718
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
719
- 'Content-Type: application/json',
720
- 'Content-Length: ' . strlen($data_string))
721
- );
722
-
723
- // send contacts to connector
724
- $result = curl_exec($ch);
725
- $result = json_decode($result);
726
-
727
- return $result;
728
- }
729
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Model/Connector/Customer.php DELETED
@@ -1,286 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Model_Connector_Customer{
4
-
5
- // Unique identifier for Dotmail: Email
6
- private $_email;
7
-
8
- // Customer Info Data
9
- private $_firstname;
10
- private $_lastname;
11
- private $_dob;
12
- private $_gender;
13
- private $_title;
14
- private $_website_created_on;
15
- private $_store_created_on;
16
- private $_account_created;
17
- private $_last_logged_in;
18
- private $_customer_group;
19
- // Customer Address Data
20
- private $_billing_address_1;
21
- private $_billing_address_2;
22
- private $_billing_city;
23
- private $_billing_country;
24
- private $_billing_postcode;
25
- private $_billing_telephone;
26
- private $_delivery_address_1;
27
- private $_delivery_address_2;
28
- private $_delivery_city;
29
- private $_delivery_country;
30
- private $_delivery_postcode;
31
- private $_delivery_telephone;
32
- // Customer Sales Data
33
- private $_total_orders;
34
- private $_average_order_value;
35
- private $_total_spend;
36
- private $_last_order;
37
- private $_last_order_no;
38
- // Newletter subscriber?
39
- private $_is_subscribed_to_newsletter;
40
- private $_dotmailer_contact_id;
41
- private $_customer_id;
42
-
43
- /**
44
- 'firstname',
45
- 'lastname',
46
- 'dob',
47
- 'gender',
48
- 'title',
49
- 'website_created_on',
50
- 'store_created_on',
51
- 'account_created',
52
- 'last_logged_in',
53
- 'customer_group',
54
- 'billing_address_1',
55
- 'billing_address_2',
56
- 'billing_city',
57
- 'billing_country',
58
- 'billing_postcode',
59
- 'billing_telephone',
60
- 'delivery_address_1',
61
- 'delivery_address_2',
62
- 'delivery_city',
63
- 'delivery_country',
64
- 'delivery_postcode',
65
- 'delivery_telephone',
66
- 'total_orders',
67
- 'average_order_value',
68
- 'total_spend',
69
- 'last_order',
70
- 'last_order_no'
71
- *
72
- */
73
-
74
- public function getEmail()
75
- {
76
- return $this->_email;
77
- }
78
-
79
-
80
- public function setDotmailerContactId($dotmailer_contact_id)
81
- {
82
- $this->_dotmailer_contact_id = $dotmailer_contact_id;
83
- }
84
-
85
- public function getDotmailerContactId()
86
- {
87
- return $this->_dotmailer_contact_id;
88
- }
89
-
90
- public function isSubscribed()
91
- {
92
- return $this->_is_subscribed_to_newsletter;
93
- }
94
-
95
- private $_mapping_hash;
96
-
97
-
98
- // class constructor - takes
99
- public function __construct(Mage_Customer_Model_Customer $customer, $mapping_hash){
100
-
101
- $this->_mapping_hash = $mapping_hash;
102
-
103
- // map each attribute from the $customer parameter (collection item) to the corresponding scoped variable in this class
104
- $this->id = $customer->getId();
105
- $this->_email = $customer->getEmail();
106
- $this->_firstname = $customer->getFirstname();
107
- $this->_lastname = $customer->getLastname();
108
- $this->_dob = $customer->getDob();
109
- $this->_gender = $this->getCustomerGender($customer->getGender());
110
- $this->_title = $customer->getPrefix();
111
-
112
- $this->_website_created_on = $this->getWebsiteName($customer->getWebsiteId());
113
- $this->_store_created_on = $this->getStoreName($customer->getStoreId());
114
- $this->_account_created = $customer->getCreatedAt();
115
- $this->_last_logged_in = $customer->getLastLoggedIn();
116
- $this->_customer_group = $this->getCustomerGroup($customer->getGroupId());
117
- $this->_billing_address_1 = $this->getStreet($customer->getBillingStreet(), 1);
118
- $this->_billing_address_2 = $this->getStreet($customer->getBillingStreet(), 2);
119
-
120
- $this->_billing_city = $customer->getBillingCity();
121
- $this->_billing_country = $customer->getBillingCountryCode();
122
- $this->_billing_postcode = $customer->getBillingPostcode();
123
- $this->_billing_telephone = $customer->getBillingTelephone();
124
-
125
- $this->_delivery_address_1 = $this->getStreet($customer->getShippingStreet(), 1);
126
- $this->_delivery_address_2 = $this->getStreet($customer->getShippingStreet(), 2);
127
-
128
- $this->_delivery_city = $customer->getShippingCity();
129
- $this->_delivery_country = $customer->getShippingCountryCode();
130
- $this->_delivery_postcode = $customer->getShippingPostcode();
131
- $this->_delivery_telephone = $customer->getShippingTelephone();
132
-
133
- $this->_total_orders = $customer->getTotalOrders();
134
- $this->_average_order_value = $customer->getAverageOrderValue();
135
- $this->_total_spend = $customer->getTotalSpend();
136
-
137
- $lastOrder = new Zend_Date($customer->getLastPurchase());
138
- //$this->_last_order = $lastOrder->toString(Zend_Date::ISO_8601);
139
- $this->_last_order = $customer->getLastPurchase();
140
- $this->_last_order_no = $customer->getLastOrderNo();
141
-
142
- $this->_is_subscribed_to_newsletter = ($customer->getSubscriberStatus() == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED)? true : false;
143
- $this->_dotmailer_contact_id = $customer->getDotmailerContactId();
144
- $this->_customer_id = $customer->getId();
145
- }
146
-
147
- public function toCSVArray() {
148
-
149
- // no iterating, just create an array()
150
-
151
- $result = array();
152
-
153
- // Email is the only required field in the CSV upload
154
- $result[] = $this->_email;
155
-
156
- if ($this->_mapping_hash[0]!="0") $result[] = $this->_firstname;
157
- if ($this->_mapping_hash[1]!="0") $result[] = $this->_lastname;
158
- if ($this->_mapping_hash[2]!="0") $result[] = $this->_dob;
159
- if ($this->_mapping_hash[3]!="0") $result[] = $this->_gender;
160
- if ($this->_mapping_hash[4]!="0") $result[] = $this->_title;
161
-
162
- if ($this->_mapping_hash[5]!="0") $result[] = $this->_website_created_on;
163
- if ($this->_mapping_hash[6]!="0") $result[] = $this->_store_created_on;
164
- if ($this->_mapping_hash[7]!="0") $result[] = $this->_account_created;
165
- if ($this->_mapping_hash[8]!="0") $result[] = $this->_last_logged_in;
166
- if ($this->_mapping_hash[9]!="0") $result[] = $this->_customer_group;
167
-
168
- if ($this->_mapping_hash[10]!="0") $result[] = $this->_billing_address_1;
169
- if ($this->_mapping_hash[11]!="0") $result[] = $this->_billing_address_2;
170
- if ($this->_mapping_hash[12]!="0") $result[] = $this->_billing_city;
171
- if ($this->_mapping_hash[13]!="0") $result[] = $this->_billing_country;
172
- if ($this->_mapping_hash[14]!="0") $result[] = $this->_billing_postcode;
173
- if ($this->_mapping_hash[15]!="0") $result[] = $this->_billing_telephone;
174
-
175
- if ($this->_mapping_hash[16]!="0") $result[] = $this->_delivery_address_1;
176
- if ($this->_mapping_hash[17]!="0") $result[] = $this->_delivery_address_2;
177
- if ($this->_mapping_hash[18]!="0") $result[] = $this->_delivery_city;
178
- if ($this->_mapping_hash[19]!="0") $result[] = $this->_delivery_country;
179
- if ($this->_mapping_hash[20]!="0") $result[] = $this->_delivery_postcode;
180
- if ($this->_mapping_hash[21]!="0") $result[] = $this->_delivery_telephone;
181
-
182
- if ($this->_mapping_hash[22]!="0") $result[] = $this->_total_orders;
183
- if ($this->_mapping_hash[23]!="0") $result[] = $this->_average_order_value;
184
- if ($this->_mapping_hash[24]!="0") $result[] = $this->_total_spend;
185
- if ($this->_mapping_hash[25]!="0") $result[] = $this->_last_order;
186
- if ($this->_mapping_hash[26]!="0") $result[] = $this->_last_order_no;
187
- if ($this->_mapping_hash[27]!="0") $result[] = $this->_customer_id;
188
-
189
- $result[] = 'Html';
190
-
191
- return $result;
192
-
193
- }
194
-
195
- // returns the object as JSON
196
- public function toJSON(){
197
-
198
- return json_encode($this->expose());
199
-
200
- }
201
-
202
- // exposes the class as an array of objects
203
- public function expose() {
204
-
205
- return get_object_vars($this);
206
-
207
- }
208
-
209
- /**
210
- * return the gender text label
211
- * @param $genderId customer option id
212
- * @return string
213
- */
214
- public function getCustomerGender($genderId)
215
- {
216
- if(is_numeric($genderId)){
217
- $gender = Mage::getResourceModel('customer/customer')
218
- ->getAttribute('gender')
219
- ->getSource()
220
- ->getOptionText($genderId)
221
- ;
222
- return $gender;
223
- }
224
-
225
- return '';
226
- }
227
-
228
- /**
229
- * get the street name by line number
230
- * @param $street
231
- * @param $line
232
- * @return string
233
- */
234
- public function getStreet($street, $line)
235
- {
236
- $street = explode("\n", $street);
237
- if($line == 1){
238
- return $street[0];
239
- }
240
- if(isset($street[$line -1])){
241
-
242
- return $street[$line - 1];
243
- }else{
244
-
245
- return '';
246
- }
247
- }
248
-
249
- /**
250
- * get website name
251
- * @param $websiteId
252
- * @return null|string
253
- */
254
- public function getWebsiteName($websiteId)
255
- {
256
- $website = Mage::app()->getWebsite($websiteId);
257
- if($website)
258
- return $website->getName();
259
-
260
- return '';
261
- }
262
-
263
- public function getStoreName($storeId)
264
- {
265
- $store = Mage::app()->getStore($storeId);
266
- if($store)
267
- return $store->getName();
268
-
269
- return '';
270
- }
271
-
272
- /**
273
- * get the group name
274
- * @param $groupId
275
- * @return string
276
- */
277
- public function getCustomerGroup($groupId)
278
- {
279
- $group = Mage::getModel('customer/group')->load($groupId);
280
- if($group){
281
- return $group->getCode();
282
- }
283
- return '';
284
- }
285
-
286
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Model/Connector/Order.php DELETED
@@ -1,118 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Model_Connector_Order
4
- {
5
- public $id;
6
- public $connector_id;
7
- public $customer_id;
8
- protected $store_name;
9
- protected $purchase_date;
10
- protected $delivery_address;
11
- protected $billing_address;
12
- protected $products = array();
13
- protected $order_subtotal;
14
- protected $discount_ammount;
15
- protected $order_total;
16
- public $quote_id;
17
-
18
- /**
19
- * set the order information
20
- * @param Mage_Sales_Model_Order $orderData
21
- */
22
- public function __construct(Mage_Sales_Model_Order $orderData)
23
- {
24
- $this->id = $orderData->getIncrementId();
25
- $this->store_name = $orderData->getStoreName();
26
-
27
- $created_at = new Zend_Date($orderData->getCreatedAt(), Zend_Date::ISO_8601);
28
- $this->purchase_date = $created_at->toString(Zend_Date::ISO_8601);
29
- $this->customer_id = $orderData->getCustomerId();
30
-
31
- $customerModel = Mage::getModel('customer/customer')->load($this->customer_id);
32
- if(!$customerModel->getDotmailerContactId()){
33
- Mage::helper('connector')->log('dotmailer id not found : ' . $customerModel->getDotmailerContactId() . ' ' . $this->customer_id . ' ' . $this->id);
34
- }
35
-
36
-
37
-
38
- $this->connector_id = $customerModel->getDotmailerContactId();
39
- $this->quote_id = $orderData->getQuoteId();
40
-
41
- /**
42
- * billing and shipping address
43
- */
44
- $deliveryData = $orderData->getShippingAddress()->getData();
45
- $this->delivery_address = array(
46
- 'delivery_address_1' => $this->getStreet($deliveryData['street'], 1),
47
- 'delivery_address_2' => $this->getStreet($deliveryData['street'], 2),
48
- 'delivery_city' => $deliveryData['city'],
49
- 'delivery_country' => $deliveryData['country_id'],
50
- 'delivery_postcode' => $deliveryData['postcode']
51
- );
52
- $billingData = $orderData->getBillingAddress()->getData();
53
- $this->billing_address = array(
54
- 'billing_address_1' => $this->getStreet($billingData['street'], 1),
55
- 'billing_address_2' => $this->getStreet($billingData['street'], 2),
56
- 'billing_city' => $billingData['city'],
57
- 'billing_country' => $billingData['country_id'],
58
- 'billing_postcode' => $billingData['postcode'],
59
- );
60
- //order products information
61
- $products = $orderData->getAllItems();
62
- $categories = array();
63
- foreach ($products as $productItem) {
64
- // product model
65
- $product = $productItem->getProduct();
66
- if($product){
67
- // category names
68
- $categoryCollection = $product->getCategoryCollection()
69
- ->addAttributeToSelect('name');
70
-
71
- foreach ($categoryCollection as $cat) {
72
- $categories[] = $cat->getName();
73
- }
74
- $categoryNames = implode(',', $categories);
75
- }
76
-
77
- $this->products[] = array(
78
- 'name' => $productItem->getName(),
79
- 'sku' => $productItem->getSku(),
80
- 'category' => $categoryNames,
81
- 'qty' => (int)number_format($productItem->getData('qty_ordered'), 2),
82
- 'price' => (float)number_format($productItem->getPrice(), 2),
83
- );
84
- }
85
- $this->order_subtotal = (float)number_format($orderData->getData('subtotal'), 2);
86
- $this->discount_ammount = (float)number_format($orderData->getData('discount_amount'), 2);
87
- $orderTotal = abs($orderData->getData('grand_total') - $orderData->getTotalRefunded());
88
- $this->order_total = (float)number_format($orderTotal, 2);
89
-
90
- }
91
- /**
92
- * get the street name by line number
93
- * @param $street
94
- * @param $line
95
- * @return string
96
- */
97
- private function getStreet($street, $line)
98
- {
99
- $street = explode("\n", $street);
100
- if($line == 1){
101
- return $street[0];
102
- }
103
- if(isset($street[$line -1])){
104
-
105
- return $street[$line - 1];
106
- }else{
107
-
108
- return '';
109
- }
110
- }
111
- // exposes the class as an array of objects
112
- public function expose() {
113
-
114
- return get_object_vars($this);
115
-
116
- }
117
-
118
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Model/Connector/Quote.php DELETED
@@ -1,75 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Model_Connector_Quote
4
- {
5
-
6
- public $id;
7
- public $connector_id;
8
- public $customer_id;
9
- protected $store_name;
10
- protected $create_date;
11
- protected $update_date;
12
- protected $delivery_address;
13
- protected $billing_address;
14
- protected $products = array();
15
- protected $order_subtotal;
16
- protected $order_total;
17
-
18
- /**
19
- * set the quote information
20
- * @param Mage_Sales_Model_Quote $quote
21
- */
22
- public function __construct(Mage_Sales_Model_Quote $quote)
23
- {
24
- $this->id = $quote->getId();
25
- $this->customer_id = $quote->getCustomerId();
26
- $customerModel = Mage::getModel('customer/customer')->load($this->customer_id);
27
- $this->connector_id = $customerModel->getData('dotmailer_contact_id');
28
-
29
- $this->store_name = $this->getStoreName($quote->getStoreId());
30
- $this->order_subtotal = (float)number_format($quote->getSubtotal(), 2);
31
- $this->order_total = (float)number_format($quote->getGrandTotal(), 2);
32
-
33
- $created_at = new Zend_Date($quote->getCreatedAt(), Zend_Date::ISO_8601);
34
- $updated_at = new Zend_Date($quote->getUpdatedAt(), Zend_Date::ISO_8601);
35
- $this->create_date = $created_at->toString(Zend_Date::ISO_8601);
36
- $this->update_date = $updated_at->toString(Zend_Date::ISO_8601);
37
-
38
- $items = $quote->getAllVisibleItems();
39
- foreach ($items as $product) {
40
- $this->products[] = array(
41
- 'name' => $product->getName(),
42
- 'sku' => $product->getSku(),
43
- 'category' => $this->getCategory($product),
44
- 'qty' => (float)number_format($product->getQty(), 2),
45
- 'price' => (float)number_format($product->getPrice(), 2)
46
- );
47
- }
48
- }
49
- private function getStoreName($storeId)
50
- {
51
- $storeModel = Mage::getModel('core/store')->load($storeId);
52
- return $storeModel->getName();
53
- }
54
- private function getCategory($product)
55
- {
56
- $product = Mage::getModel('catalog/product')->load($product->getProductId());
57
- $categories = $product->getCategoryCollection()
58
- ->addAttributeToSelect('name');
59
- $categoryNames = array();
60
- foreach ($categories as $cat) {
61
- $categoryNames[] = $cat->getName();
62
- }
63
-
64
- $categoryNames = implode(',', $categoryNames);
65
- return $categoryNames;
66
-
67
- }
68
- // exposes the class as an array of objects
69
- public function expose() {
70
-
71
- return get_object_vars($this);
72
-
73
- }
74
-
75
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Model/Connector/Wishlist.php DELETED
@@ -1,86 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Model_Connector_Wishlist
4
- {
5
- protected $id;
6
- protected $customer_id;
7
- protected $connector_id;
8
-
9
- public $name;
10
-
11
- public $items = array();
12
-
13
- protected $total_wishlist_value;
14
-
15
- public function __construct($customer){
16
-
17
- $this->setConnectorId($customer->getDotmailerContactId());
18
- $this->setCustomerId($customer->id);
19
- }
20
-
21
- /**
22
- * @param mixed $connector_id
23
- */
24
- public function setConnectorId($connector_id)
25
- {
26
- $this->connector_id = $connector_id;
27
- }
28
-
29
- /**
30
- * @return mixed
31
- */
32
- public function getConnectorId()
33
- {
34
- return $this->connector_id;
35
- }
36
-
37
-
38
- /**
39
- * @param mixed $customer_id
40
- */
41
- public function setCustomerId($customer_id)
42
- {
43
- $this->customer_id = $customer_id;
44
- }
45
-
46
-
47
- /**
48
- * @return mixed
49
- */
50
- public function getCustomerId()
51
- {
52
- return $this->customer_id;
53
- }
54
-
55
- /**
56
- * @param mixed $id
57
- */
58
- public function setId($id)
59
- {
60
- $this->id = $id;
61
- }
62
-
63
- /**
64
- * @return mixed
65
- */
66
- public function getId()
67
- {
68
- return $this->id;
69
- }
70
-
71
- public function setItem($item)
72
- {
73
- $this->items[] = $item->expose();
74
-
75
- $this->total_wishlist_value += $item->getTotalValueOfProduct();
76
- }
77
-
78
- public function expose() {
79
-
80
- return get_object_vars($this);
81
-
82
- }
83
-
84
-
85
-
86
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Model/Cron.php DELETED
@@ -1,58 +0,0 @@
1
- <?php
2
- class Dotdigitalgroup_Email_Model_Cron
3
- {
4
- /**
5
- * CRON FOR CUSTOMER SYNC
6
- */
7
- public function customersync()
8
- {
9
- if(Mage::getStoreConfig(Dotdigitalgroup_Email_Model_Customer_Customer::XML_PATH_CUSTOMER_SYNC_ENABLE))
10
- Mage::getModel('connector/customer_customer')->sync();
11
- return;
12
- }
13
-
14
- /**
15
- * CRON FOR LOST BASKET
16
- */
17
- public function lostbasketssync()
18
- {
19
- //look for lost baskets
20
- Mage::getModel('connector/sales_quote')->proccessCampaigns();
21
- $helper = Mage::helper('connector');
22
- if($helper->isOrderTransactionalEnabled()){
23
- //send transactional data and mark as imported
24
- Mage::getModel('connector/sales_order')->sync();
25
- }
26
- if($helper->isCustomerSyncEnabled()){
27
- //check for customer that have no connector id
28
- $numUpdated = Mage::getModel('connector/customer_customer')->syncContacts();
29
- Mage::helper('connector')->log('SYNC CONTACTS : '. $numUpdated);
30
- }
31
- }
32
-
33
- /**
34
- * CRON FOR SUPRESSED CONTACTS
35
- */
36
- public function suppressedsync()
37
- {
38
- if(Mage::getStoreConfig(Dotdigitalgroup_Email_Model_Customer_Customer::XML_PATH_CUSTOMER_SUPPRESSED_ENABLE)){
39
- //check suppressed contacts from connector
40
- Mage::getModel('connector/customer_suppressed')->unsubscribe();
41
- }
42
-
43
- }
44
-
45
- /**
46
- * CLEAN ARHIVED FOLDERS
47
- */
48
-
49
- public function cleaning()
50
- {
51
- $helper = Mage::helper('connector/file');
52
- $archivedFolder = $helper->getArchiveFolder();
53
- $result = $helper->deleteDir($archivedFolder);
54
- Mage::helper('connector')->log('Cleaning cronjob result : ' . $result, null, 'api.log');
55
- return $result;
56
- }
57
-
58
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Model/Customer/Customer.php DELETED
@@ -1,480 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Model_Customer_Customer extends Dotdigitalgroup_Email_Model_Api_Rest
4
- {
5
- // xml configuration
6
- const XML_PATH_CONNECTOR_API_USERNAME = 'connector_api_settings/api_credentials/username';
7
- const XML_PATH_CONNECTOR_API_PASSWORD = 'connector_api_settings/api_credentials/password';
8
- const XML_PATH_CUSTOMER_SYNC_ENABLE = 'connector_sync_settings/sync_customer_schedule/enabled';
9
- const XML_PATH_CUSTOMER_SYNC_LIMIT = 'connector_advanced_settings/sync_limits/contact';
10
- const XML_PATH_CUSTOMER_SUPPRESSED_ENABLE = 'connector_sync_settings/sync_suppressed_schedule/enabled';
11
- const XML_PATH_CUSTOMERS_ADDRESS_BOOK_ID = 'connector_data_field_settings/address_book/customers';
12
- const XML_PATH_CUSTOMERS_SUPPRESSED_INTERVAL = 'connector_sync_settings/sync_suppressed_schedule/frequency';
13
- const XML_PATH_GUEST_ADDRESS_BOOK_ID = 'connector_data_field_settings/address_book/guest';
14
- const XML_PATH_CUSTOMER_WISHLIST_ENABLED = 'connector_sync_settings/transactional_data/wishlist_enabled';
15
-
16
- const FORCE_CUSTOMERS_YEARS = '10';
17
-
18
- protected $_customers_address_book_id;
19
- protected $_customers = array();
20
- protected $_mapping_hash;
21
- protected $_website; // website model
22
- private $countSubscribers = 0;
23
- private $countCustomers = 0;
24
-
25
- protected $accounts = array();// api accounts
26
- protected $wishlists = array();// wishlists
27
- protected $_proccessing;
28
- protected $_websiteId;
29
- public $apiLimit = 450;
30
-
31
- public function sync()
32
- {
33
- /** @var Dotdigitalgroup_Email_Helper_Data $helper */
34
- $helper = Mage::helper('connector');
35
- $helper->log('Start customer sync..', null, $this->_log_filename);
36
- $result = array('error' => false, 'message' => "Done.");
37
-
38
- // check for default settings to use memory limit
39
- if(Mage::getStoreConfig('connector_advanced_settings/admin/memory_limit'))
40
- $this->allowResourceFullExecution();
41
-
42
- // get all websites
43
- foreach(Mage::app()->getWebsites() as $website){
44
-
45
- // skip any actions if sync disabled
46
- if(! $website->getConfig(self::XML_PATH_CUSTOMER_SYNC_ENABLE))
47
- continue;
48
- //API credentials
49
- $this->_api_user = $website->getConfig(self::XML_PATH_CONNECTOR_API_USERNAME);
50
- $this->_api_password = $website->getConfig(self::XML_PATH_CONNECTOR_API_PASSWORD);
51
-
52
- if(strlen($this->_api_user) > 10 && strlen($this->_api_password)){
53
-
54
- $result = $this->exportCustomersForWebsite($website);
55
- if($website->getConfig(self::XML_PATH_CUSTOMER_WISHLIST_ENABLED)){
56
- $this->exportWishlistsForWebsite($website);
57
- }
58
- }else{
59
- $result['error'] = true;
60
- $message = 'The Credentials For Website :' . $website->getCode() . ' is not set!';
61
- $result['message'] = $message;
62
- $helper->log($message, null, $this->_log_filename);
63
- }
64
- }
65
- //set result check
66
- if($this->countCustomers != 0){
67
-
68
- $message = 'Total Exported : ' . $this->countCustomers . ' Customers, ' . $this->countSubscribers . ' Subscribers.';
69
-
70
- $result['message'] = $message;
71
- $helper->log($message, null, $this->_log_filename);
72
- }else{
73
- $result['error'] = true;
74
- $message = 'Check the logs for more information, the number of updated customers is : 0.';
75
- $result['message'] = $message;
76
- }
77
-
78
- $helper->log('Customer sync end!', null, $this->_log_filename);
79
- return $result;
80
- }
81
-
82
- /**
83
- * Get the customer for the website
84
- * @param bool $websiteId
85
- * @return mixed
86
- */
87
- public function getContactsCustomers($websiteId = false)
88
- {
89
- /** @var Mage_Customer_Model_Customer $customerCollection */
90
- $customerCollection = Mage::getModel('customer/customer')->getCollection()
91
- ->addAttributeToSelect('dotmailer_contact_id')
92
- ->addAttributeToFilter('dotmailer_contact_id', array('notnull' => true), 'left')
93
- ;
94
- if($websiteId !== false)
95
- $customerCollection->addAttributeToFilter('website_id', $websiteId);
96
-
97
- return $customerCollection;
98
- }
99
-
100
- private function countNumOfContacts($contacts)
101
- {
102
- $total = 0;
103
- // Get contacts number with contact id
104
- foreach ($contacts as $contact) {
105
- if($contact->getDotmailerContactId())
106
- $total++;
107
- }
108
- unset($contacts);
109
- return $total;
110
- }
111
-
112
- public function syncContacts()
113
- {
114
- $updated = 0;
115
- /**
116
- * Customers at website level
117
- */
118
- foreach (Mage::app()->getWebsites(true) as $website) {
119
- $websiteId = $website->getId();
120
- $missingContacts = $this->getMissingContacts($websiteId, $this->apiLimit);
121
- Mage::helper('connector')->log('API LIMIT : ' . $this->apiLimit, null, 'api.log');
122
- Mage::helper('connector')->log($missingContacts->count(), null, 'api.log');
123
- if(count($missingContacts) == 0)
124
- continue;
125
- //save customer and trigger the obsever
126
- foreach($missingContacts as $customer){
127
- try{
128
- $customer->save();
129
- $updated++;
130
- //limit the number of updated contacts
131
- if($this->apiLimit == $updated){
132
- return $updated;
133
- }
134
- }catch (Exception $e){
135
- Mage::logException($e);
136
- }
137
- }
138
- }
139
- return $updated;
140
- }
141
- public function getMissingContacts($websiteId = null, $limit = 200)
142
- {
143
- $customerCollection = Mage::getModel('customer/customer')->getCollection()
144
- ->addAttributeToSelect('dotmailer_contact_id')
145
- ->addAttributeToFilter('dotmailer_contact_id', array('null' => true), 'left')
146
- ->setPageSize($limit)
147
- ;
148
- if($websiteId !== null)
149
- $customerCollection->addAttributeToFilter('website_id', $websiteId);
150
-
151
- return $customerCollection;
152
- }
153
- public function getTotalNumberCustomers()
154
- {
155
- $customers = Mage::getModel('customer/customer')->getCollection();
156
- $totalCustomers = $customers->getSize();
157
-
158
- return $totalCustomers;
159
- }
160
-
161
- public function countSkipContacts($contacts = false, $websiteId)
162
- {
163
- if($contacts)
164
- $numContactIds = $this->countNumOfContacts($contacts);
165
- else
166
- $numContactIds = count($this->getContactsCustomers($websiteId));
167
-
168
-
169
- return $numContactIds;
170
- }
171
-
172
- /**
173
- * @param Mage_Core_Model_Website $website
174
- * @return $this
175
- */
176
- public function exportCustomersForWebsite(Mage_Core_Model_Website $website)
177
- {
178
- $websiteCode = $website->getCode();
179
- $websiteId = $website->getId();
180
- $customer_filename = $websiteCode . '_' . $this->_customers_file_slug . '_' . date('d-M-Y_hms') . '.csv';
181
- $subscriber_filename = $websiteCode . '_' . $this->_subscribers_file_slug . '_' . date('d-M-Y_hms') . '.csv';
182
- $helper = Mage::helper('connector');
183
-
184
- $helper->log('customer filename : ' . $customer_filename . ', subscriber filename : ' . $subscriber_filename, null, $this->_log_filename);
185
-
186
- $pageNum = 1;
187
- $pageSize = $website->getConfig('connector_advanced_settings/admin/batch_size');
188
- if($pageSize == '') $pageSize = 5000;
189
- $this->fileHelper = Mage::helper('connector/file');
190
-
191
- do{
192
- $time_start = microtime(true);
193
-
194
- $currentBatch = $this->getCustomersToExport($pageSize, $pageNum, $this->getMappingHash($website), $website->getId());
195
- $condition = count($currentBatch);
196
- //write the csv headers
197
- if($pageNum == 1 && count($currentBatch)){
198
- $this->fileHelper->outputCSV($this->fileHelper->getFilePath($customer_filename), $this->getCsvHeaderArray($website));
199
- $this->fileHelper->outputCSV($this->fileHelper->getFilePath($subscriber_filename), array('Email', 'emailType'));
200
- }
201
- foreach ($currentBatch as $customer) {
202
-
203
- /**
204
- * Send wishlist as transactional data
205
- */
206
- if($website->getConfig(self::XML_PATH_CUSTOMER_WISHLIST_ENABLED)){
207
- $this->setWishlists($customer, $website);
208
- }
209
- // check if customer is subscribed
210
- if($customer->isSubscribed()){
211
- // save data for subscribers
212
- $this->fileHelper->outputCSV($this->fileHelper->getFilePath($subscriber_filename), array($customer->getEmail(), 'Html'));
213
- $this->countSubscribers++;
214
- }
215
-
216
- // save data for csutomers
217
- $this->fileHelper->outputCSV($this->fileHelper->getFilePath($customer_filename), $customer->toCSVArray());
218
- $this->countCustomers++;
219
- }
220
- $time_end = microtime(true);
221
- $time_in_seconds = $time_end - $time_start;
222
-
223
- $helper->log('-----------------------------------------------execution time :' . gmdate("H:i:s", $time_in_seconds), null, $this->_log_filename);
224
- $pageNum++;
225
- unset($currentBatch);
226
-
227
- }while( $condition == $pageSize );
228
-
229
- $storeIds = Mage::getModel('core/website')->load($websiteId)
230
- ->getStoreIds();
231
- $subscriberModel = new Dotdigitalgroup_Email_Model_Newsletter_Subscriber();
232
- $subscribersNotCustomers = $subscriberModel->getSubscribersNotCustomers($storeIds);
233
-
234
- foreach ($subscribersNotCustomers as $one) {
235
- $this->fileHelper->outputCSV($this->fileHelper->getFilePath($subscriber_filename), array($one->getSubscriberEmail()));
236
- $this->countSubscribers++;
237
- }
238
-
239
- /**
240
- * Save customers and subscribers to address books
241
- */
242
- $this->postAddressBookContactsImport($customer_filename, $website->getConfig(self::XML_PATH_CUSTOMERS_ADDRESS_BOOK_ID));
243
- $this->postAddressBookContactsImport($subscriber_filename, $website->getConfig(Dotdigitalgroup_Email_Model_Newsletter_Subscriber::XML_PATH_SUBSCRIBERS_ADDRESS_BOOK_ID));
244
-
245
- //If successful, archive the CSV file and Log something in the Magento Log - success/failure
246
- if(file_exists($this->fileHelper->getFilePath($customer_filename)) && file_exists($this->fileHelper->getFilePath($subscriber_filename))){
247
- $this->fileHelper->archiveCSV($customer_filename);
248
- $this->fileHelper->archiveCSV($subscriber_filename);
249
- }
250
- return $this;
251
-
252
- }
253
-
254
- private function exportWishlistsForWebsite(Mage_Core_Model_Website $website){
255
-
256
- $this->_api_user = $website->getConfig(self::XML_PATH_CONNECTOR_API_USERNAME);
257
- $this->_api_password = $website->getConfig(self::XML_PATH_CONNECTOR_API_PASSWORD);
258
- //wishlists for the website key
259
- if(isset($this->wishlists[$website->getId()])){
260
-
261
- //send wishlists as transactional data
262
- $wishlists = $this->wishlists[$website->getId()];
263
-
264
- $this->postContactsTransactionalDataImport($collectionName = 'Wishlist', $wishlists);
265
- }
266
- }
267
-
268
- public function getCustomersToExport($pageSize = 0, $pageNum = 1, $mappingHash, $websiteId)
269
- {
270
- // the filtering and aggregation of all the customer data here
271
- $customers = array();
272
- $helper = Mage::helper('connector');
273
-
274
- $customerCollection = Mage::getModel('customer/customer')->getCollection()
275
- ->addAttributeToSelect('email')
276
- ->addAttributeToSelect('firstname')
277
- ->addAttributeToSelect('lastname')
278
- ->addAttributeToSelect('dob')
279
- ->addAttributeToSelect('gender')
280
- ->addAttributeToSelect('prefix')
281
- ->addAttributeToSelect('website_id')
282
- ->addAttributeToSelect('store_id')
283
- ->addAttributeToSelect('created_at')
284
- ->addAttributeToSelect('last_logged_in')
285
- ->addAttributeToSelect('group_id')
286
- ->addAttributeToSelect('dob')
287
- ->addAttributeToSelect('dotmailer_contact_id')
288
-
289
- ->addAttributeToFilter('website_id', $websiteId)
290
-
291
- ->joinAttribute('billing_street', 'customer_address/street', 'default_billing', null, 'left')
292
- ->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
293
- ->joinAttribute('billing_country_code', 'customer_address/country_id', 'default_billing', null, 'left')
294
- ->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
295
- ->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')
296
- ->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
297
- ->joinAttribute('shipping_street', 'customer_address/street', 'default_shipping', null, 'left')
298
- ->joinAttribute('shipping_city', 'customer_address/city', 'default_shipping', null, 'left')
299
- ->joinAttribute('shipping_country_code', 'customer_address/country_id', 'default_shipping', null, 'left')
300
- ->joinAttribute('shipping_postcode', 'customer_address/postcode', 'default_shipping', null, 'left')
301
- ->joinAttribute('shipping_telephone', 'customer_address/telephone', 'default_shipping', null, 'left')
302
- ->joinAttribute('shipping_region', 'customer_address/region', 'default_shipping', null, 'left')
303
- ->joinTable('newsletter/subscriber','subscriber_email=email',array('subscriber_status' => 'subscriber_status'), null, 'left')
304
-
305
- ;
306
- if( $pageSize ){
307
- $customerCollection->setPage($pageNum, $pageSize);
308
- }
309
-
310
- $customer_log = Mage::getSingleton('core/resource')->getTableName('log_customer');
311
- $sales_flat_order_grid = Mage::getSingleton('core/resource')->getTableName('sales_flat_order_grid');
312
- $sales_flat_order = Mage::getSingleton('core/resource')->getTableName('sales_flat_order');
313
-
314
- // get the last login from the log_customer table
315
- $customerCollection->getSelect()->columns(array('last_logged_in' => new Zend_Db_Expr ("(SELECT login_at
316
- FROM $customer_log
317
- WHERE customer_id =e.entity_id
318
- ORDER BY log_id DESC
319
- LIMIT 1)")));
320
-
321
- // customer order information
322
- $alias = 'subselect';
323
- $subselect = Mage::getModel('Varien_Db_Select',
324
- Mage::getSingleton('core/resource')->getConnection('core_read')
325
- )->from($sales_flat_order_grid, array(
326
- 'customer_id as s_customer_id',
327
- 'sum(grand_total) as total_spend',
328
- 'count(*) as total_orders',
329
- 'avg(grand_total) as average_order_value',
330
- )
331
- )->group('customer_id')
332
- ;
333
- $customerCollection->getSelect()->columns(array(
334
- 'last_purchase' => new Zend_Db_Expr("(SELECT created_at
335
- FROM $sales_flat_order
336
- WHERE customer_id =e.entity_id
337
- ORDER BY created_at DESC
338
- LIMIT 1)"),
339
- 'last_order_no' => new Zend_Db_Expr("(SELECT entity_id
340
- FROM $sales_flat_order
341
- WHERE customer_id =e.entity_id
342
- ORDER BY created_at DESC
343
- LIMIT 1)")
344
- ));
345
-
346
- $customerCollection->getSelect()
347
- ->joinLeft(array($alias => $subselect),
348
- "{$alias}.s_customer_id = e.entity_id");
349
-
350
-
351
-
352
- $time = microtime(true);
353
- // create a customer object for each item in our collection
354
- foreach ($customerCollection as $item) {
355
-
356
- $customers[] = new Dotdigitalgroup_Email_Model_Connector_Customer($item, $mappingHash);
357
- }
358
-
359
- unset($customerCollection);
360
- $end_time = microtime(true);
361
- $end = $end_time - $time;
362
-
363
-
364
- $helper->log($pageSize . ': page' . $pageNum . ' for website: ' . $websiteId, null, $this->_log_filename);
365
- $helper->log('created dotmailer customers from collection: ' . gmdate("H:i:s", $end), null, $this->_log_filename);
366
-
367
- return $customers;
368
- }
369
-
370
- protected function allowResourceFullExecution() {
371
-
372
- /* it may be needed to set maximum execution time of the script to longer,
373
- * like 60 minutes than usual */
374
- set_time_limit ( 7200 );
375
-
376
- /* and memory to 512 megabytes */
377
- ini_set ( 'memory_limit', '512M' );
378
-
379
- return $this;
380
- }
381
- function convert($size)
382
- {
383
- $unit=array('b','kb','mb','gb','tb','pb');
384
- return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i];
385
- }
386
-
387
- /**
388
- * Create an array of columns we have chosen to map in our System->Config
389
- * @param Mage_Core_Model_Website $website
390
- * @return array
391
- */
392
- public function getCsvHeaderArray(Mage_Core_Model_Website $website) {
393
-
394
- $result = array();
395
-
396
- $result[] = 'Email';
397
-
398
- foreach ($this->getMappingHash($website) as $header) {
399
- if ($header != "0") $result[] = $header;
400
- }
401
- $result[] = 'emailType';
402
-
403
- return $result;
404
- }
405
-
406
- /**
407
- * Gets the datafield mapping hash from the system config
408
- * @param Mage_Core_Model_Website $website
409
- * @return array
410
- */
411
- protected function getMappingHash(Mage_Core_Model_Website $website){
412
-
413
-
414
- $customer_fields = array(
415
- 'customer_data/firstname',
416
- 'customer_data/lastname',
417
- 'customer_data/dob',
418
- 'customer_data/gender',
419
- 'customer_data/title',
420
- 'customer_data/website_created_on',
421
- 'customer_data/store_created_on',
422
- 'customer_data/account_created',
423
- 'customer_data/last_logged_in',
424
- 'customer_data/customer_group',
425
- 'customer_data/billing_address_1',
426
- 'customer_data/billing_address_2',
427
- 'customer_data/billing_city',
428
- 'customer_data/billing_country',
429
- 'customer_data/billing_postcode',
430
- 'customer_data/billing_telephone',
431
- 'customer_data/delivery_address_1',
432
- 'customer_data/delivery_address_2',
433
- 'customer_data/delivery_city',
434
- 'customer_data/delivery_country',
435
- 'customer_data/delivery_postcode',
436
- 'customer_data/delivery_telephone',
437
- 'customer_data/total_orders',
438
- 'customer_data/average_order_value',
439
- 'customer_data/total_spend',
440
- 'customer_data/last_order',
441
- 'customer_data/last_order_no',
442
- 'customer_data/customer_id'
443
- );
444
-
445
- $result = array();
446
-
447
- foreach ($customer_fields as $field) {
448
-
449
- $result[] = $website->getConfig('connector_data_field_settings/' . $field);
450
-
451
- }
452
- return $result;
453
- }
454
-
455
- public function setWishlists($customer, $website)
456
- {
457
- $customerId = $customer->id;
458
- $wishList = Mage::getModel('wishlist/wishlist')->loadByCustomer($customerId);
459
-
460
- /** @var $connectorWishlist */
461
- $connectorWishlist = new Dotdigitalgroup_Email_Model_Connector_Wishlist($customer);
462
- $connectorWishlist->setId($wishList->getId());
463
-
464
- $wishListItemCollection = $wishList->getItemCollection();
465
-
466
- if (count($wishListItemCollection)) {
467
- foreach ($wishListItemCollection as $item) {
468
- /* @var $product Mage_Catalog_Model_Product */
469
- $product = $item->getProduct();
470
- $connectorItem = new Dotdigitalgroup_Email_Model_Customer_Wishlist_Item($product);
471
- $connectorItem->setQty($item->getQty());
472
- $connectorItem->setPrice($product);
473
- $connectorWishlist->setItem($connectorItem);//store for wishlists
474
- }
475
- //set wishlists for later use
476
- $this->wishlists[$website->getId()][] = $connectorWishlist;
477
- }
478
- }
479
-
480
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Model/Customer/Suppressed.php DELETED
@@ -1,85 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Model_Customer_Suppressed extends Dotdigitalgroup_Email_Model_Api_Rest
4
- {
5
-
6
- private $suppressedContacts = array();
7
-
8
- public function unsubscribe($force = false)
9
- {
10
- // result of sync
11
- $result = array('errors' => false, 'message' => '', 'customers');
12
- $result['customers'] = 0;
13
- $date = new Zend_Date();
14
-
15
- /**
16
- * 1. calculate from frequency
17
- */
18
- if(! $force){
19
- $frequency = Mage::getStoreConfig(Dotdigitalgroup_Email_Model_Customer_Customer::XML_PATH_CUSTOMERS_SUPPRESSED_INTERVAL);
20
- // get the frequency of sinse date
21
- switch($frequency){
22
- case('H'):
23
- $date = $date->subHour(1);
24
- break;
25
- case('D'):
26
- $date = $date->subDay(1);
27
- break;
28
- case('W'):
29
- $date = $date->subWeek(1);
30
- break;
31
- case('M'):
32
- $date = $date->subMonth(1);
33
- break;
34
- }
35
- }else{
36
-
37
- // force sync all customers
38
- $date = $date->subYear(Dotdigitalgroup_Email_Model_Customer_Customer::FORCE_CUSTOMERS_YEARS);
39
- }
40
-
41
- // datetime format string
42
- $dateString = $date->toString(Zend_Date::W3C);
43
- /**
44
- * Sync all suppressed for each store
45
- */
46
- foreach (Mage::app()->getWebsites(true) as $website) {
47
- $this->_api_user = $website->getConfig(Dotdigitalgroup_Email_Model_Customer_Customer::XML_PATH_CONNECTOR_API_USERNAME);
48
- $this->_api_password = $website->getConfig(Dotdigitalgroup_Email_Model_Customer_Customer::XML_PATH_CONNECTOR_API_PASSWORD);
49
- $contacts = $this->getSuppressedSince($dateString);
50
- if(! empty($contacts)){
51
- foreach ($contacts as $suppressed){
52
- $contactEmail = false;
53
- if(isset($suppressed->suppressedContact)){
54
-
55
- $contactEmail = $suppressed->suppressedContact->email;
56
- $contactId = $suppressed->suppressedContact->id;
57
- }
58
-
59
- if($contactEmail){
60
- try{
61
- /**
62
- * 3. Unsubscribe customer
63
- */
64
- $newsletterModel = Mage::getModel('newsletter/subscriber')->loadByEmail($contactEmail);
65
- if($newsletterModel->getStatus() == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED){
66
- $unsubscribe = $newsletterModel->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED);
67
- $unsubscribe->save();
68
- // remove from subscriber address-book
69
- $this->deleteAddressBookContact($website->getConfig(Dotdigitalgroup_Email_Model_Newsletter_Subscriber::XML_PATH_SUBSCRIBERS_ADDRESS_BOOK_ID), $contactId);
70
- $this->suppressedContacts[$newsletterModel->getSubscriberEmail()] = $newsletterModel->getSubscriberEmail();
71
- }
72
- }catch (Exception $e){
73
- $result['errors'] = true;
74
- $result['message'] = 'Error Saving Customer!';
75
- }
76
- }
77
- }
78
- }
79
- }
80
- $result['customers'] = count($this->suppressedContacts);
81
-
82
- return $result;
83
- }
84
-
85
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Model/Dynamic/Product/Mapper.php DELETED
@@ -1,90 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Model_Dynamic_Product_Mapper extends Mage_Core_Model_Abstract
4
- {
5
- protected $_max_per_child;
6
-
7
- protected $_num_order_items;
8
-
9
- protected $_helper;
10
-
11
- public $_products = array();
12
-
13
- public $filename = 'mapper.log';
14
-
15
- public function __construct($num_order_items)
16
- {
17
- $this->_helper = Mage::helper('connector');
18
- $items_to_display = Mage::helper('connector/recommended')->getLimit();
19
- if($num_order_items < $items_to_display)
20
- $this->_max_per_child = number_format($items_to_display / $num_order_items);
21
- $this->_helper->log('max items per child : ' . $this->_max_per_child . ', items to display : ' . $items_to_display . ', number of order items : ' . $num_order_items, null, $this->filename);
22
-
23
- }
24
-
25
- /**
26
- * Set the products with parent limit
27
- * @param $products
28
- */
29
- public function setProducts($products)
30
- {
31
- $count = 0;
32
- foreach ($products as $product) {
33
- if($count < $this->_max_per_child)
34
- $this->setProduct($product);
35
- $count++;
36
- }
37
-
38
- }
39
- public function setProduct(Mage_Catalog_Model_Product $product)
40
- {
41
- $productId = $product->getEntityId();
42
-
43
- if(!isset($this->_products[$productId])){
44
- $this->_products[$productId] = $product;
45
- return true;
46
- }
47
- return false;
48
- }
49
-
50
- public function countProducts()
51
- {
52
- return count($this->_products);
53
- }
54
-
55
- public function getProducts()
56
- {
57
- return $this->_products;
58
- }
59
-
60
- public function getFallbackProducts($limit)
61
- {
62
- $count = 0;
63
- $fallbackIds = Mage::helper('connector/recommended')->getFallbackIds();
64
- $this->_helper->log('fallback products from helper : '. count($fallbackIds), null, $this->filename);
65
-
66
- if(!empty($fallbackIds)){
67
- foreach ($fallbackIds as $id) {
68
- /** @var Mage_Catalog_Model_Product $product */
69
- $product = Mage::getModel('catalog/product')->load($id);
70
-
71
- if($product->getEntityId()){
72
-
73
- $result = $this->setProduct($product);
74
- if($result)
75
- $count++;
76
-
77
- }
78
-
79
- $this->_helper->log('result for products ' . $this->countProducts() . ', count : ' . $count . ', limit : ' . $limit, null, $this->filename);
80
-
81
- if($count == $limit){
82
-
83
- break;
84
- }
85
- }
86
- }
87
-
88
- return;
89
- }
90
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Model/Dynamic/Recommended.php DELETED
@@ -1,228 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Model_Dynamic_Recommended extends Dotdigitalgroup_Email_Model_Dynamic_Product_Mapper
4
- {
5
- protected $_result_limit;
6
-
7
- protected $_storeId;//order store id
8
-
9
- protected $_order_items = 0;//order product items
10
-
11
- protected $_num_order_items;//number of items from order
12
-
13
- protected $_productMapper;
14
-
15
- protected $_is_log_enabled;
16
-
17
- protected $_helper;
18
-
19
- /**
20
- * @param $orderModel
21
- */
22
- public function __construct(Mage_Sales_Model_Order $orderModel = null)
23
- {
24
- if($orderModel){
25
- $this->_storeId = $orderModel->getStoreId();
26
- $this->_order_items = $orderModel->getAllItems();
27
- }
28
- $this->_num_order_items = count($this->_order_items);
29
- $this->_productMapper = new Dotdigitalgroup_Email_Model_Dynamic_Product_Mapper($this->_num_order_items);
30
- $this->_helper = Mage::helper('connector/recommended');
31
- $this->_result_limit = $this->_helper->getLimit();
32
- }
33
-
34
- /**
35
- * Get the recommended products
36
- * @return array
37
- */
38
- public function getProducts()
39
- {
40
- $mode = Mage::registry('mode');
41
- if($mode == 'related' || $mode == 'upsell' || $mode == 'crosssell'){
42
-
43
- //set the order items
44
- $this->setOrderItems();
45
- }else{
46
- //set products directly without looking for order items
47
- $this->setRecommendedProduct();
48
- }
49
-
50
- return $this->_productMapper->getProducts();
51
- }
52
-
53
- public function setOrderItems()
54
- {
55
- foreach ($this->_order_items as $item) {
56
- $productId = $item->getProductId();
57
- /** @var Mage_Catalog_Model_Product $product */
58
- $product = Mage::getModel('catalog/product')->load($productId);//make sure the product is loaded
59
-
60
- $this->setRecommendedProduct($product);
61
- }
62
-
63
- if($this->_productMapper->countProducts() < $this->_result_limit){
64
- $limit = $this->_result_limit - $this->_productMapper->countProducts();
65
- $this->_productMapper->getFallbackProducts($limit);
66
- }
67
-
68
- return $this->_productMapper->getProducts();
69
- }
70
-
71
- public function setRecommendedProduct(Mage_Catalog_Model_Product $productModel = null)
72
- {
73
- //array of products to display
74
- $products = array();
75
-
76
- $mode = Mage::registry('mode');
77
- switch($mode){
78
- case 'related':
79
- $products = $productModel->getRelatedProducts();
80
- break;
81
- case 'upsell':
82
- $products = $productModel->getUpSellProducts();
83
- break;
84
- case 'crosssell':
85
- $products = $productModel->getCrossSellProducts();
86
- break;
87
- case 'bestsellers':
88
- $products = $this->getBestSellersProducts();
89
- break;
90
- case 'mostviewed':
91
- $products = $this->getMostViewedProducts();
92
- break;
93
- case 'recentlyviewed':
94
- $products = $this->getRecentlyViewedProducts();
95
- break;
96
- case 'productpush':
97
- $products = $this->getPushProducts();
98
- break;
99
- }
100
- if($mode == 'related' || $mode == 'upsell' || $mode == 'crosssell'){
101
-
102
- $this->_productMapper->setProducts($products, $this->_result_limit);
103
- }
104
-
105
-
106
- Mage::helper('connector')->log('number of all recommended products : ' . $this->_productMapper->countProducts() . ', max : ' . $this->_result_limit, null, $this->filename);
107
-
108
- }
109
- public function getNumberOfOrderItems()
110
- {
111
- return $this->_order_items;
112
- }
113
-
114
- /**
115
- * Best Selling products
116
- * @return array
117
- */
118
- public function getBestSellersProducts()
119
- {
120
- $limit = $this->_helper->getLimit();
121
- $from = $this->_helper->getTimeFromConfig($config = 'bestsellers');
122
- $to = new Zend_Date();
123
- $to = $to->toString(Zend_Date::ISO_8601);
124
-
125
- $productCollection = Mage::getResourceModel('reports/product_collection')
126
- ->addOrderedQty($from, $to)
127
- ->addAttributeToSelect('*')
128
- ->addAttributeToSelect(array('name', 'price', 'small_image')) //edit to suit tastes
129
- ->setOrder('ordered_qty', 'desc') //best sellers on top
130
- ->setPageSize($limit);
131
-
132
- $productCollection->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
133
- $productCollection->addAttributeToFilter('visibility', Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
134
-
135
- foreach ($productCollection as $_product) {
136
- $this->_productMapper->setProduct($_product);
137
- }
138
-
139
- return array();
140
- }
141
-
142
- /**
143
- * Most viwed products
144
- * @return array
145
- */
146
- public function getMostViewedProducts()
147
- {
148
- $limit = $this->_helper->getLimit();
149
- $from = $this->_helper->getTimeFromConfig($config = 'mostviewed');
150
-
151
- $to = new Zend_Date();
152
- $to = $to->toString(Zend_Date::ISO_8601);
153
- $productCollection = Mage::getResourceModel('reports/product_collection')
154
- ->addViewsCount()
155
- ->addViewsCount($from, $to)
156
- ->setPageSize($limit);
157
-
158
- $productCollection->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
159
- $productCollection->addAttributeToFilter('visibility', Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
160
-
161
- foreach ($productCollection as $_product) {
162
- $this->_productMapper->setProduct($_product);
163
- }
164
-
165
-
166
- return $this->_productMapper->getProducts();
167
- }
168
-
169
- /**
170
- * Recently viewed products
171
- * @return $this
172
- */
173
- public function getRecentlyViewedProducts()
174
- {
175
- $customerId = Mage::registry('customer');
176
- $helper = Mage::helper('connector');
177
- $helper->log('recentlyviewed customer : ' . $customerId, null, $this->filename);
178
- if($customerId){
179
-
180
- $limit = $this->_helper->getLimit();
181
-
182
- //login customer to receive the recent products
183
- $session = Mage::getSingleton('customer/session');
184
- $session->loginById($customerId);
185
-
186
- /** @var Mage_Reports_Block_Product_Viewed $collection */
187
- $collection = Mage::getSingleton('Mage_Reports_Block_Product_Viewed');
188
- $items = $collection->getItemsCollection()
189
- ->setPageSize($limit)
190
- ;
191
-
192
-
193
- foreach ($items as $product) {
194
- $this->_productMapper->setProduct($product);
195
- }
196
-
197
-
198
- return $this->_productMapper->getProducts();
199
- }else{
200
-
201
- $helper->log('Get recently viewd products, customer id not found : ' . $customerId, null, $this->filename);
202
- }
203
-
204
- return null;
205
- }
206
-
207
- public function getPushProducts()
208
- {
209
- $productIds = $this->_helper->getProductPushIds();
210
-
211
- Mage::helper('connector')->log('proudcts push ids : ' . implode(',', $productIds), null, $this->filename);
212
-
213
-
214
- $productCollection = Mage::getModel('catalog/product')->getCollection()
215
- ->addAttributeToFilter('entity_id', array('in' => $productIds))
216
- ->setPageSize(Mage::helper('connector/recommended')->getLimit())
217
- ;
218
-
219
- foreach ($productCollection as $_product) {
220
- $this->_productMapper->setProduct($_product);
221
-
222
- }
223
-
224
- return $this->_productMapper->getProducts();
225
- }
226
-
227
-
228
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Model/Newsletter/Subscriber.php DELETED
@@ -1,19 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Model_Newsletter_Subscriber extends Mage_Core_Helper_Abstract
4
- {
5
- const XML_PATH_SUBSCRIBERS_ADDRESS_BOOK_ID = 'connector_data_field_settings/address_book/subscribers';
6
-
7
- // select subscribers that are not registred as customers
8
- public function getSubscribersNotCustomers($storeIds = array())
9
- {
10
- $newsletterCollection = Mage::getModel('newsletter/subscriber')->getCollection()
11
- ->addFieldToFilter('main_table.customer_id', array('eq' => 0))
12
- ->addFieldToFilter('subscriber_status', array('eq' => Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED))
13
- ->addStoreFilter($storeIds)
14
- ;
15
-
16
- return $newsletterCollection;
17
- }
18
-
19
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Model/Observer.php DELETED
@@ -1,189 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Model_Observer extends Dotdigitalgroup_Email_Model_Api_Rest
4
- {
5
- /**
6
- * Create new contact or update info also check for email change
7
- * event: customer_save_before
8
- * @param Varien_Event_Observer $observer
9
- * @return $this
10
- */
11
- public function handleCustomerSaveBefore(Varien_Event_Observer $observer)
12
- {
13
- // skip update customer for first time sync
14
- if(! Mage::registry('first_time_sync')){
15
-
16
- /* @var $customer Mage_Customer_Model_Customer */
17
- $customer = $observer->getEvent()->getCustomer();
18
- $email = $customer->getEmail();
19
- $websiteId = $customer->getWebsiteId();
20
- $subscribed = $customer->getIsSubscribed();
21
-
22
- $this->_api_user = Mage::app()->getWebsite($websiteId)->getConfig(Dotdigitalgroup_Email_Model_Customer_Customer::XML_PATH_CONNECTOR_API_USERNAME);
23
- $this->_api_password = Mage::app()->getWebsite($websiteId)->getConfig(Dotdigitalgroup_Email_Model_Customer_Customer::XML_PATH_CONNECTOR_API_PASSWORD);
24
- $subscribersAddressBook = Mage::app()->getWebsite($websiteId)->getConfig(Dotdigitalgroup_Email_Model_Newsletter_Subscriber::XML_PATH_SUBSCRIBERS_ADDRESS_BOOK_ID);
25
-
26
- if($customer->getData('dotmailer_contact_id')){
27
- $dotmailerId = $customer->getData('dotmailer_contact_id');
28
- //get contact infrmation by id
29
- $response = $this->getContactById($dotmailerId);
30
-
31
- //check for matching email
32
- if(isset($response->email)){
33
- if($email != $response->email){
34
- $data = array(
35
- 'Email' => $email,
36
- 'EmailType' => 'Html'
37
- );
38
- //update the contact with same id - different email
39
- $this->updateContact($dotmailerId, $data);
40
- }
41
-
42
- if(!$subscribed && $response->status == 'Subscribed'){
43
- $this->deleteAddressBookContact($subscribersAddressBook, $response->id);
44
- }
45
- }
46
- }else{
47
- //get contact info by email
48
- $response = $this->getContactByEmail($email);
49
- //create new contact and add to address books
50
- if(isset($response->message) && $response->message == Dotdigitalgroup_Email_Model_Api_Rest::REST_CONTACT_NOT_FOUND){
51
- $contactApi = $this->createNewContact($email);
52
- $this->postAddressBookContacts(Mage::getStoreConfig(Dotdigitalgroup_Email_Model_Customer_Customer::XML_PATH_CUSTOMERS_ADDRESS_BOOK_ID), $contactApi);
53
-
54
- if($subscribed){
55
- $this->postAddressBookContacts($subscribersAddressBook, $contactApi);
56
- }
57
- }
58
- }
59
-
60
- if(isset($response->id))
61
- $customer->setData('dotmailer_contact_id', $response->id);//set the id from contact info
62
- }
63
- return $this;
64
- }
65
- /**
66
- * event: sales_order_save_after
67
- * @param Varien_Event_Observer $observer
68
- * @return $this
69
- */
70
- public function handleSalesOrderSaveAfter(Varien_Event_Observer $observer)
71
- {
72
- $order = $observer->getEvent()->getOrder();
73
- $storeId = $order->getStoreId();
74
- $customerId = $order->getCustomerId();
75
-
76
- $customerModel = Mage::getModel('customer/customer')->load($customerId);
77
-
78
-
79
- if(!$customerModel->getData('dotmailer_contact_id'))
80
- $customerModel->save();
81
-
82
- $this->_api_user = Mage::getStoreConfig(Dotdigitalgroup_Email_Model_Customer_Customer::XML_PATH_CONNECTOR_API_USERNAME, $storeId);
83
- $this->_api_password = Mage::getStoreConfig(Dotdigitalgroup_Email_Model_Customer_Customer::XML_PATH_CONNECTOR_API_PASSWORD, $storeId);
84
- $is_enabled = Mage::getStoreConfig(Dotdigitalgroup_Email_Model_Sales_Order::XML_PATH_TRANSACTIONAL_DATA_ENABLED, $storeId);
85
-
86
- // store scope enabled
87
- if($is_enabled){
88
- $dotmailer = new Dotdigitalgroup_Email_Model_Connector_Order($order);
89
- $this->sendOrderTransactionalData($dotmailer, 'Order');
90
- }
91
-
92
-
93
- return $this;
94
- }
95
-
96
- /**
97
- * event: quote_save_after
98
- * @param Varien_Event_Observer $observer
99
- * @return $this
100
- */
101
- public function handleSalesQuoteSaveAfter(Varien_Event_Observer $observer)
102
- {
103
- $quote = $observer->getQuote();
104
- $customerIsNotGuest = $quote->getCustomerId();
105
- $storeId = $quote->getStoreId();
106
-
107
- $this->_api_user = Mage::getStoreConfig(Dotdigitalgroup_Email_Model_Customer_Customer::XML_PATH_CONNECTOR_API_USERNAME, $storeId);
108
- $this->_api_password = Mage::getStoreConfig(Dotdigitalgroup_Email_Model_Customer_Customer::XML_PATH_CONNECTOR_API_PASSWORD, $storeId);
109
- $is_enabled = Mage::getStoreConfig(Dotdigitalgroup_Email_Model_Sales_Order::XML_PATH_TRANSACTIONAL_DATA_ENABLED, $storeId);
110
-
111
- // save quotes that are active
112
- if($customerIsNotGuest && $is_enabled && $quote->getIsActive()){
113
- $dotmailer = new Dotdigitalgroup_Email_Model_Connector_Quote($quote);
114
- $this->sendTransactionalData($dotmailer, 'Basket');
115
- }
116
-
117
- return $this;
118
- }
119
-
120
- public function handleSalesOrderStatusChange(Varien_Event_Observer $observer)
121
- {
122
- $order = $observer->getEvent()->getOrder();
123
- $status = $order->getStatus();
124
-
125
- /**
126
- * SMS functinality
127
- */
128
- $smsStatusOne = Mage::getStoreConfig(Dotdigitalgroup_Email_Model_Sales_Sms::XML_PATH_SMS_MESSAGE_ONE_STATUS);
129
- $smsStatusTwo = Mage::getStoreConfig(Dotdigitalgroup_Email_Model_Sales_Sms::XML_PATH_SMS_MESSAGE_TWO_STATUS);
130
- $smsStatusThree = Mage::getStoreConfig(Dotdigitalgroup_Email_Model_Sales_Sms::XML_PATH_SMS_MESSAGE_THREE_STATUS);
131
- $smsStatusFour = Mage::getStoreConfig(Dotdigitalgroup_Email_Model_Sales_Sms::XML_PATH_SMS_MESSAGE_FOUR_STATUS);
132
- $smsModel = new Dotdigitalgroup_Email_Model_Sales_Sms();
133
-
134
- switch($status){
135
- case $smsStatusOne:
136
- $smsModel->sendMessage($order, 'ONE');
137
- break;
138
- case $smsStatusTwo:
139
- $smsModel->sendMessage($order, 'TWO');
140
- break;
141
- case $smsStatusThree:
142
- $smsModel->sendMessage($order, 'THREE');
143
- break;
144
- case $smsStatusFour:
145
- $smsModel->sendMessage($order, 'FOUR');
146
- break;
147
- }
148
-
149
- return $this;
150
- }
151
-
152
- public function handleSalesOrderRefund(Varien_Event_Observer $observer)
153
- {
154
- $creditmemo = $observer->getEvent()->getCreditmemo();
155
- $storeId = $creditmemo->getStoreId();
156
-
157
- $this->_api_user = Mage::getStoreConfig(Dotdigitalgroup_Email_Model_Customer_Customer::XML_PATH_CONNECTOR_API_USERNAME, $storeId);
158
- $this->_api_password = Mage::getStoreConfig(Dotdigitalgroup_Email_Model_Customer_Customer::XML_PATH_CONNECTOR_API_PASSWORD, $storeId);
159
- $is_enabled = Mage::getStoreConfig(Dotdigitalgroup_Email_Model_Sales_Order::XML_PATH_TRANSACTIONAL_DATA_ENABLED, $storeId);
160
- $order = $creditmemo->getOrder();
161
-
162
- // store scope enabled
163
- if($is_enabled){
164
- $connectorOrder = new Dotdigitalgroup_Email_Model_Connector_Order($order);
165
- $result = $this->sendOrderTransactionalData($connectorOrder, 'Order', $order->getIncrementId());
166
- $this->_helper->log($result, null, $this->_log_filename);
167
-
168
- }
169
-
170
- return $this;
171
- }
172
- public function hangleSalesOrderCancel(Varien_Event_Observer $observer)
173
- {
174
- $order = $observer->getEvent()->getOrder();
175
- $storeId = $order->getStoreId();
176
- $key = $order->getIncrementId();
177
-
178
- $this->_api_user = Mage::getStoreConfig(Dotdigitalgroup_Email_Model_Customer_Customer::XML_PATH_CONNECTOR_API_USERNAME, $storeId);
179
- $this->_api_password = Mage::getStoreConfig(Dotdigitalgroup_Email_Model_Customer_Customer::XML_PATH_CONNECTOR_API_PASSWORD, $storeId);
180
- $is_enabled = Mage::getStoreConfig(Dotdigitalgroup_Email_Model_Sales_Order::XML_PATH_TRANSACTIONAL_DATA_ENABLED, $storeId);
181
-
182
- if($is_enabled)
183
- $this->deleteContactsTransactionalData('Order', $key);
184
-
185
-
186
-
187
- return $this;
188
- }
189
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Model/Order.php DELETED
@@ -1,33 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Model_Order extends Mage_Sales_Model_Order
4
- {
5
- protected function _setState($state, $status = false, $comment = '', $isCustomerNotified = null, $shouldProtectState = false)
6
- {
7
- // dispatch an event before we attempt to do anything
8
- Mage::dispatchEvent('sales_order_status_before', array('order' => $this, 'state' => $state, 'status' => $status, 'comment' => $comment, 'isCustomerNotified' => $isCustomerNotified, 'shouldProtectState' => $shouldProtectState));
9
-
10
- // attempt to set the specified state
11
- if ($shouldProtectState) {
12
- if ($this->isStateProtected($state)) {
13
- Mage::throwException(Mage::helper('sales')->__('The Order State "%s" must not be set manually.', $state));
14
- }
15
- }
16
- $this->setData('state', $state);
17
-
18
- // add status history
19
- if ($status) {
20
- if ($status === true) {
21
- $status = $this->getConfig()->getStateDefaultStatus($state);
22
- }
23
- $this->setStatus($status);
24
- $history = $this->addStatusHistoryComment($comment, false); // no sense to set $status again
25
- $history->setIsCustomerNotified($isCustomerNotified); // for backwards compatibility
26
- }
27
-
28
- // dispatch an event after status has changed
29
- Mage::dispatchEvent('sales_order_status_after', array('order' => $this, 'state' => $state, 'status' => $status, 'comment' => $comment, 'isCustomerNotified' => $isCustomerNotified, 'shouldProtectState' => $shouldProtectState));
30
-
31
- return $this;
32
- }
33
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Model/Sales/Order.php DELETED
@@ -1,96 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Model_Sales_Order extends Dotdigitalgroup_Email_Model_Api_Rest
4
- {
5
- const XML_PATH_TRANSACTIONAL_DATA_ENABLED = 'connector_sync_settings/transactional_data/order_enabled';
6
- const XML_PATH_TRANSACTIONAL_DATA_SYNC_LIMIT = 'connector_advanced_settings/sync_limits/orders';
7
-
8
- protected $accounts = array();
9
-
10
- /**
11
- * initial sync the transactional data
12
- * @return array
13
- */
14
- public function sync()
15
- {
16
- // Initialise a return hash containing results of our sync attempt
17
- $this->_searchAccounts();
18
-
19
- foreach ($this->accounts as $account){
20
- if(count($account->getOrders())){
21
- $this->sendMultiTransactionalData($account->getOrders(), 'Order');
22
-
23
- }
24
-
25
- unset($this->accounts[$account->getApiUsername()]);
26
- }
27
- return $this;
28
- }
29
-
30
- /**
31
- *Search the configuration data per website
32
- */
33
- private function _searchAccounts()
34
- {
35
- foreach (Mage::app()->getWebsites() as $website){
36
- $enabled = $website->getConfig(self::XML_PATH_TRANSACTIONAL_DATA_ENABLED);
37
-
38
- if(!$enabled)
39
- continue;
40
-
41
- $this->_api_user = $website->getConfig(Dotdigitalgroup_Email_Model_Customer_Customer::XML_PATH_CONNECTOR_API_USERNAME);
42
- $limit = $website->getConfig(self::XML_PATH_TRANSACTIONAL_DATA_SYNC_LIMIT);
43
-
44
- if(!isset($this->accounts[$this->_api_user])){
45
- $account = new Dotdigitalgroup_Email_Model_Connector_Account();
46
- $account->setApiUsername($this->_api_user);
47
- $account->setApiPassword($this->_api_password);
48
- $this->accounts[$this->_api_user] = $account;
49
- }
50
- $this->accounts[$this->_api_user]->setOrders($this->getConnectorOrders($limit));
51
- }
52
- }
53
-
54
- /**
55
- * get all connector orders data
56
- * @param $limit
57
- * @return array
58
- */
59
- public function getConnectorOrders($limit = 100)
60
- {
61
- $orders = $customers = array();
62
- $orderCollection = Mage::getModel('sales/order')->getCollection()
63
- ->addAttributeToFilter('dotmailer_order_imported', array('null' => true), 'left')
64
- ->setPageSize($limit);
65
-
66
- $this->_helper->log('GET CONNECTOR ORDERS ' . $orderCollection->count() . ' limit ' . $limit, null, $this->_log_filename);
67
-
68
- //mark as imported for customers with contact id
69
- foreach ($orderCollection as $order) {
70
- try {
71
- $customerEmail = $order->getCustomerEmail();
72
- $storeId = $order->getStoreId();
73
- $this->setStoreId(Mage::app()->getStore(true)->getId());
74
- $websiteId = Mage::getModel('core/store')->load($storeId)->getWebsiteId();
75
-
76
- $customerModel = Mage::getModel('customer/customer')->setWebsiteId($websiteId)
77
- ->loadByEmail($customerEmail);
78
-
79
- if($customerModel){
80
- $contactId = $customerModel->getData('dotmailer_contact_id');
81
- if($contactId){
82
- $orders[] = new Dotdigitalgroup_Email_Model_Connector_Order($order);
83
- $order->setData('dotmailer_order_imported', 1);
84
- $order->save();
85
- }
86
- }
87
- }catch(Exception $e){
88
-
89
-
90
- $this->_helper->log($order->getIncrementId(), null, $this->_log_filename);
91
- $this->_helper->log($e->getMessage(), null, $this->_log_filename);
92
- }
93
- }
94
- return $orders;
95
- }
96
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Model/Sales/Quote.php DELETED
@@ -1,289 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Model_Sales_Quote extends Dotdigitalgroup_Email_Model_Api_Rest
4
- {
5
- //xml path configuration
6
- const XML_PATH_LOSTBASKET_1_ENABLED = 'lostbaskets/customers/enabled_1';
7
- const XML_PATH_LOSTBASKET_2_ENABLED = 'lostbaskets/customers/enabled_2';
8
- const XML_PATH_LOSTBASKET_3_ENABLED = 'lostbaskets/customers/enabled_3';
9
-
10
- const XML_PATH_LOSTBASKET_1_INTERVAL = 'lost_basket_settings/customers/send_after_1';
11
- const XML_PATH_LOSTBASKET_2_INTERVAL = 'lost_basket_settings/customers/send_after_2';
12
- const XML_PATH_LOSTBASKET_3_INTERVAL = 'lost_basket_settings/customers/send_after_3';
13
-
14
- const XML_PATH_TRIGGER_1_CAMPAIGN = 'lost_basket_settings/customers/campaign_1';
15
- const XML_PATH_TRIGGER_2_CAMPAIGN = 'lost_basket_settings/customers/campaign_2';
16
- const XML_PATH_TRIGGER_3_CAMPAIGN = 'lost_basket_settings/customers/campaign_3';
17
-
18
- const XML_PATH_GUEST_LOSTBASKET_1_ENABLED = 'lostbaskets/guests/enabled_1';
19
- const XML_PATH_GUEST_LOSTBASKET_2_ENABLED = 'lostbaskets/guests/enabled_2';
20
- const XML_PATH_GUEST_LOSTBASKET_3_ENABLED = 'lostbaskets/guests/enabled_3';
21
-
22
- const XML_PATH_GUEST_LOSTBASKET_1_INTERVAL = 'lost_basket_settings/guests/send_after_1';
23
- const XML_PATH_GUEST_LOSTBASKET_2_INTERVAL = 'lost_basket_settings/guests/send_after_2';
24
- const XML_PATH_GUEST_LOSTBASKET_3_INTERVAL = 'lost_basket_settings/guests/send_after_3';
25
-
26
- const XML_PATH_GUEST_LOSTBASKET_1_CAMPAIGN = 'lost_basket_settings/guests/campaign_1';
27
- const XML_PATH_GUEST_LOSTBASKET_2_CAMPAIGN = 'lost_basket_settings/guests/campaign_2';
28
- const XML_PATH_GUEST_LOSTBASKET_3_CAMPAIGN = 'lost_basket_settings/guests/campaign_3';
29
-
30
- const XML_PATH_TEST_LOSTBASKET_EMAIL = 'lost_basket_settings/test/email';
31
-
32
-
33
- /**
34
- * send the lost baskets to campains
35
- * @return array
36
- */
37
- public function proccessCampaigns()
38
- {
39
- foreach (Mage::app()->getStores(true) as $store){
40
-
41
- //skip any action if all lost basket campaings are disabled
42
- if(!$store->getConfig(self::XML_PATH_LOSTBASKET_1_ENABLED) && !$store->getConfig(self::XML_PATH_LOSTBASKET_2_ENABLED) &&
43
- !$store->getConfig(self::XML_PATH_LOSTBASKET_3_ENABLED) && !$store->getConfig(self::XML_PATH_GUEST_LOSTBASKET_1_ENABLED) &&
44
- !$store->getconfig(self::XML_PATH_GUEST_LOSTBASKET_2_ENABLED) && !$store->getConfig(self::XML_PATH_GUEST_LOSTBASKET_3_ENABLED)
45
- )continue;
46
-
47
- // set credentials for every store
48
- $storeId = $store->getId();
49
- $this->_api_user = $store->getConfig(Dotdigitalgroup_Email_Model_Customer_Customer::XML_PATH_CONNECTOR_API_USERNAME);
50
- $this->_api_password = $store->getConfig(Dotdigitalgroup_Email_Model_Customer_Customer::XML_PATH_CONNECTOR_API_PASSWORD);
51
-
52
- /**
53
- * Customers campaings
54
- */
55
-
56
- //first campign
57
- if($store->getConfig(self::XML_PATH_LOSTBASKET_1_ENABLED)){
58
-
59
- $contacts = array();
60
- $from = Zend_Date::now()->subMinute($store->getConfig(self::XML_PATH_LOSTBASKET_1_INTERVAL));
61
- $to = clone($from);
62
- $from->sub('5', Zend_Date::MINUTE);
63
- // lost baskets
64
- $quoteCollection = $this->_getStoreQuotes($storeId, $from->toString('YYYY-MM-dd HH:mm:ss'), $to->toString('YYYY-MM-dd HH:mm:ss'));
65
- if(count($quoteCollection)){
66
-
67
- // get collection contacts id
68
- foreach ($quoteCollection as $quote) {
69
- $customerId = $quote->getCustomerId();
70
- $dotmailerContactId = $this->_getContactIdByCustomerId($customerId);
71
-
72
- if($dotmailerContactId)
73
- $contacts[] = $dotmailerContactId;
74
- }
75
- //check for empty contacts to avoid mass emails
76
- if(!empty($contacts))
77
- $this->sendCampaign($store->getConfig(self::XML_PATH_TRIGGER_1_CAMPAIGN), $contacts);
78
- }
79
- }
80
-
81
- //second campaign
82
- if($store->getConfig(self::XML_PATH_LOSTBASKET_2_ENABLED)){
83
- $contacts = array();
84
- $from = Zend_Date::now()->subHour($store->getConfig(self::XML_PATH_LOSTBASKET_2_INTERVAL));
85
- $to = clone($from);
86
- $from->sub('5', Zend_Date::MINUTE);
87
- // lost baskets
88
- $quoteCollection = $this->_getStoreQuotes($storeId, $from->toString('YYYY-MM-dd HH:mm:ss'), $to->toString('YYYY-MM-dd HH:mm:ss'));
89
- if(count($quoteCollection)){
90
- // get collection contacts id
91
- foreach ($quoteCollection as $quote) {
92
- $customerId = $quote->getCustomerId();
93
- $dotmailerContactId = $this->_getContactIdByCustomerId($customerId);
94
- if($dotmailerContactId)
95
- $contacts[] = $dotmailerContactId;
96
- }
97
- if(!empty($contacts))
98
- $this->sendCampaign($store->getConfig(self::XML_PATH_TRIGGER_2_CAMPAIGN), $contacts);
99
- }
100
- }
101
-
102
- //third campign
103
- if($store->getConfig(self::XML_PATH_LOSTBASKET_3_ENABLED)){
104
- $contacts = array();
105
- $from = Zend_Date::now()->subHour($store->getConfig(self::XML_PATH_LOSTBASKET_3_INTERVAL));
106
- $to = clone($from);
107
- $from->sub('5', Zend_Date::MINUTE);
108
- // lost baskets
109
- $quoteCollection = $this->_getStoreQuotes($storeId, $from->toString('YYYY-MM-dd HH:mm:ss'), $to->toString('YYYY-MM-dd HH:mm:ss'));
110
- if(count($quoteCollection)){
111
- // get collection contacts id
112
- foreach ($quoteCollection as $quote) {
113
- $customerId = $quote->getCustomerId();
114
- $dotmailerContactId = $this->_getContactIdByCustomerId($customerId);
115
- if($dotmailerContactId)
116
- $contacts[] = $dotmailerContactId;
117
- }
118
- if(!empty($contacts))
119
- $this->sendCampaign($store->getConfig(self::XML_PATH_TRIGGER_3_CAMPAIGN), $contacts);
120
- }
121
- }
122
- /**
123
- * Guests campaings
124
- */
125
- //first guest campaign
126
- if($store->getConfig(self::XML_PATH_GUEST_LOSTBASKET_1_ENABLED))
127
- {
128
- $contacts = array();
129
- $from = Zend_Date::now()->subMinute($store->getConfig(self::XML_PATH_GUEST_LOSTBASKET_1_INTERVAL));
130
- $to = clone($from);
131
- $from->sub('5', Zend_Date::MINUTE);
132
- $quoteCollection = $this->_getStoreQuotes($storeId, $from->toString('YYYY-MM-dd HH:mm:ss'), $to->toString('YYYY-MM-dd HH:mm:ss'), true);
133
- if(count($quoteCollection)){
134
- // get collection contacts id
135
- foreach ($quoteCollection as $quote) {
136
- $email = $quote->getCustomerEmail();
137
- //check if the customer exists
138
- $response = $this->getContactByEmail($email);
139
-
140
- if(isset($response->message) && $response->message == self::REST_CONTACT_NOT_FOUND){
141
- //create new contact before sending campaign
142
- $contactAPI = $this->createNewContact($email);
143
- if(!isset($contactAPI->message))
144
- $response = $this->postAddressBookContacts($store->getConfig(Dotdigitalgroup_Email_Model_Customer_Customer::XML_PATH_GUEST_ADDRESS_BOOK_ID), $contactAPI);
145
- }
146
- $contacts[] = $response->id;
147
- }
148
- if(!empty($contacts))
149
- $this->sendCampaign($store->getConfig(self::XML_PATH_GUEST_LOSTBASKET_1_CAMPAIGN), $contacts);
150
- }
151
- }
152
- // second guest campaign
153
- if($store->getConfig(self::XML_PATH_GUEST_LOSTBASKET_2_ENABLED))
154
- {
155
- $contacts = array();
156
- $from = Zend_Date::now()->subHour($store->getConfig(self::XML_PATH_GUEST_LOSTBASKET_2_INTERVAL));
157
- $to = clone($from);
158
- $from->sub('5', Zend_Date::MINUTE);
159
- // lost baskets
160
- $quoteCollection = $this->_getStoreQuotes($storeId, $from->toString('YYYY-MM-dd HH:mm:ss'), $to->toString('YYYY-MM-dd HH:mm:ss'), true);
161
- if(count($quoteCollection)){
162
- // get collection contacts id
163
- foreach ($quoteCollection as $quote) {
164
- $email = $quote->getCustomerEmail();
165
- //check if the customer exists
166
- $response = $this->getContactByEmail($email);
167
- if(isset($response->message) && $response->message == self::REST_CONTACT_NOT_FOUND){
168
- //create new contact before sending campaign
169
- $contactAPI = $this->createNewContact($email);
170
- if(!isset($contactAPI->message))
171
- $this->postAddressBookContacts($store->getConfig(Dotdigitalgroup_Email_Model_Customer_Customer::XML_PATH_GUEST_ADDRESS_BOOK_ID), $contactAPI);
172
- }
173
- $contacts[] = $response->id;
174
- }
175
- if(!empty($contacts))
176
- $this->sendCampaign($store->getConfig(self::XML_PATH_GUEST_LOSTBASKET_2_CAMPAIGN), $contacts);
177
- }
178
- }
179
- //third guest campaign
180
- if($store->getConfig(self::XML_PATH_GUEST_LOSTBASKET_3_ENABLED)){
181
- $contacts = array();
182
- $from = Zend_Date::now()->subHour($store->getConfig(self::XML_PATH_GUEST_LOSTBASKET_3_INTERVAL));
183
- $to = clone($from);
184
- $from->sub('5', Zend_Date::MINUTE);
185
-
186
- // lost baskets
187
- $quoteCollection = $this->_getStoreQuotes($storeId, $from->toString('YYYY-MM-dd HH:mm:ss'), $to->toString('YYYY-MM-dd HH:mm:ss'), true);
188
- if(count($quoteCollection)){
189
- // get collection contacts id
190
- foreach ($quoteCollection as $quote) {
191
- $email = $quote->getCustomerEmail();
192
- //check if the customer exists
193
- $response = $this->getContactByEmail($email);
194
-
195
- if(isset($response->message) && $response->message == self::REST_CONTACT_NOT_FOUND){
196
- //create new contact before sending campaign
197
- $contactAPI = $this->createNewContact($email);
198
- if(!isset($contactAPI->message))
199
- $this->postAddressBookContacts($store->getConfig(Dotdigitalgroup_Email_Model_Customer_Customer::XML_PATH_GUEST_ADDRESS_BOOK_ID), $contactAPI);
200
- }
201
- $contacts[] = $response->id;
202
- }
203
- if(!empty($contacts))
204
- $this->sendCampaign($store->getConfig(self::XML_PATH_GUEST_LOSTBASKET_3_CAMPAIGN), $contacts);
205
- }
206
- }
207
- }
208
- return;
209
- }
210
-
211
- /**
212
- * @param $storeId
213
- * @param null $from
214
- * @param null $to
215
- * @param bool $guest
216
- * @return Varien_Data_Collection_Db
217
- */
218
- private function _getStoreQuotes($storeId, $from = null, $to = null, $guest = false){
219
-
220
- $salesCollection = Mage::getResourceModel('sales/quote_collection')
221
- ->addFieldToFilter('is_active',1)
222
- ->addFieldToFilter('items_count', array('gt' => 0))
223
- ->addFieldToFilter('customer_email', array('neq' => ''))
224
- ->addFieldToFilter('store_id', $storeId)
225
- ->addFieldToFilter('updated_at',array(
226
- 'from' => $from,
227
- 'to' => $to,
228
- 'date' => true)
229
- );
230
- if($guest)
231
- $salesCollection->addFieldToFilter('checkout_method' , Mage_Checkout_Model_Type_Onepage::METHOD_GUEST);
232
-
233
- return $salesCollection->load();
234
- }
235
-
236
- private function _getContactIdByCustomerId($customerId)
237
- {
238
- $customerModel = Mage::getModel('customer/customer')->load($customerId);
239
-
240
- if($customerModel){
241
- return $customerModel->getData('dotmailer_contact_id');
242
- }
243
- return false;
244
-
245
- }
246
- public function forceProccess()
247
- {
248
- $result = array('errors' => false, 'message' => '');
249
- $contacts = array();
250
- $customerEmail = Mage::getStoreConfig(self::XML_PATH_TEST_LOSTBASKET_EMAIL);
251
-
252
-
253
- $salesCollection = Mage::getResourceModel('sales/quote_collection')
254
- ->addFieldToFilter('is_active',1)
255
- ->addFieldToFilter('items_count', array('gt' => 0))
256
- ->addFieldToFilter('customer_id', array('neq' => ''))
257
- ->addFieldToFilter('customer_email', $customerEmail)
258
-
259
- //->addFieldToFilter('store_id', $storeId)
260
- ;
261
- $salesCollection->getSelect()->order("updated_at desc");
262
-
263
-
264
- $quote = $salesCollection->getFirstItem();
265
-
266
- if($quote){
267
-
268
- $contactId = $this->_getContactIdByCustomerId($quote->getCustomerId());
269
-
270
- if($contactId)
271
- $contacts[] = $contactId;
272
-
273
- if(!empty($contacts)){
274
-
275
- $responce = $this->sendCampaign(Mage::getStoreConfig(self::XML_PATH_TRIGGER_1_CAMPAIGN), $contacts);
276
- if(isset($responce->message)){
277
- $result['errors'] = true;
278
- $result['message'] = $responce->message;
279
- }else{
280
-
281
- $result['message'] = 'First Test Campaign Sent ';
282
- }
283
- }
284
- }
285
- return $result;
286
-
287
- }
288
-
289
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Model/Sales/Sms.php DELETED
@@ -1,70 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Model_Sales_Sms extends Dotdigitalgroup_Email_Model_Api_Rest
4
- {
5
- const XML_PATH_SMS_MESSAGE_ONE_STATUS = 'sms_section/sms_message_one/order_status';
6
- const XML_PATH_SMS_MESSAGE_TWO_STATUS = 'sms_section/sms_message_two/order_status';
7
- const XML_PATH_SMS_MESSAGE_THREE_STATUS = 'sms_section/sms_message_three/order_status';
8
- const XML_PATH_SMS_MESSAGE_FOUR_STATUS = 'sms_section/sms_message_four/order_status';
9
-
10
- const XML_PATH_SMS_MESSAGE_ONE = 'sms_section/sms_message_one/message';
11
- const XML_PATH_SMS_MESSAGE_TWO = 'sms_section/sms_message_two/message';
12
- const XML_PATH_SMS_MESSAGE_THREE = 'sms_section/sms_message_three/message';
13
- const XML_PATH_SMS_MESSAGE_FOUR = 'sms_section/sms_message_four/message';
14
-
15
- public $_available = array('/customer_name/', '/order_number/', '/{{var /', '/}}/');
16
-
17
- public function sendMessage($order, $number)
18
- {
19
- $storeId = $order->getStoreId();
20
- $billing = $order->getBillingAddress();
21
- $customerTelephone = $billing->getTelephone();
22
-
23
- $message = Mage::getStoreConfig(constant('self::XML_PATH_SMS_MESSAGE_' . $number), $storeId);
24
-
25
- $message = $this->_processVariables($order, $message);
26
-
27
-
28
- $pattern = "/^(\+44\s?7\d{3}|\(?07\d{3}\)?)\s?\d{3}\s?\d{3}$/";
29
-
30
- $match = preg_match($pattern, $customerTelephone);
31
- $this->_helper->log('sms number to send : ' . $customerTelephone, null, $this->_log_filename);
32
-
33
- if ($match != false) {
34
- $telephoneNumber = preg_replace('/\A(0){1}+/', '+44', $customerTelephone);
35
- Mage::helper('connector')->log($telephoneNumber, null, 'api.log');
36
- $this->postSmsMessagesSendTo($telephoneNumber, $message);
37
- } else {
38
-
39
- $this->_helper->log('telephone number not valid ' . $customerTelephone, null, $this->_log_filename);
40
- }
41
- }
42
-
43
- /**
44
- * @param $order
45
- * @param $message
46
- * @return mixed
47
- */
48
- protected function _processVariables($order, $message)
49
- {
50
- $helper = Mage::helper('connector');
51
- if(preg_match('/{{var/', $message)){
52
-
53
- $firstname = $order->getCustomerFirstname();
54
-
55
- $replacemant = array();
56
- $replacemant[] = $firstname;
57
- $replacemant[] = $order->getIncrementId();
58
- $replacemant[] = '';
59
- $replacemant[] = '';
60
-
61
- $message = preg_replace($this->_available, $replacemant, $message);
62
-
63
- $helper->log($message, null, $this->_log_filename);
64
-
65
- }
66
-
67
- return $message;
68
- }
69
-
70
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Model/System/Config/Backend/Syncschedule/Customer.php DELETED
@@ -1,50 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Model_System_Config_Backend_Syncschedule_Customer extends Mage_Core_Model_Config_Data
4
- {
5
- const CRON_STRING_PATH = 'connector_sync_settings/sync_customer_schedule/cronschedule';
6
-
7
- /**
8
- * Cron settings after save
9
- *
10
- *
11
- */
12
- protected function _afterSave()
13
- {
14
-
15
- $enabled = $this->getData('groups/sync_customer_schedule/fields/enabled/value');
16
- $time = $this->getData('groups/sync_customer_schedule/fields/time/value');
17
- $frequency = $this->getData('groups/sync_customer_schedule/fields/frequency/value');
18
-
19
- $frequencyHourly = Dotdigitalgroup_Email_Model_System_Config_Source_Syncfrequency::CRON_HOURLY;
20
- $frequencyDaily = Dotdigitalgroup_Email_Model_System_Config_Source_Syncfrequency::CRON_DAILY;
21
- $frequencyWeekly = Dotdigitalgroup_Email_Model_System_Config_Source_Syncfrequency::CRON_WEEKLY;
22
- $frequencyMonthly = Dotdigitalgroup_Email_Model_System_Config_Source_Syncfrequency::CRON_MONTHLY;
23
-
24
- if ($enabled) {
25
- $cronDayOfWeek = date('N');
26
- $cronExprArray = array(
27
- ($frequency == $frequencyHourly) ? intval($time[1]) : '*', # Minute
28
- ($frequency == $frequencyDaily) ? intval($time[0]) : '*', # Hour
29
- ($frequency == $frequencyMonthly) ? '1' : '*', # Day of the Month
30
- '*', # Month of the Year
31
- ($frequency == $frequencyWeekly) ? $cronDayOfWeek : '*', # Day of the Week
32
- );
33
- $cronExprString = join(' ', $cronExprArray);
34
- }
35
- else {
36
- $cronExprString = '';
37
- }
38
-
39
- try {
40
- // store config $cronExprString
41
- Mage::getModel('core/config_data')
42
- ->load(self::CRON_STRING_PATH, 'path')
43
- ->setValue($cronExprString)
44
- ->setPath(self::CRON_STRING_PATH)
45
- ->save();
46
- }catch (Exception $e) {
47
- Mage::throwException('Unable to save the cron expression.');
48
- }
49
- }
50
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Model/System/Config/Backend/Syncschedule/Suppressed.php DELETED
@@ -1,54 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Model_System_Config_Backend_Syncschedule_Suppressed extends Mage_Core_Model_Config_Data
4
- {
5
- const CRON_STRING_PATH = 'connector_sync_settings/sync_suppressed_schedule/cronschedulesupp';
6
-
7
- /**
8
- * Cron settings after save
9
- *
10
- *
11
- */
12
- protected function _afterSave()
13
- {
14
-
15
- $enabled = $this->getData('groups/sync_suppressed_schedule/fields/enabled/value');
16
- $time = $this->getData('groups/sync_suppressed_schedule/fields/time/value');
17
- $frequency = $this->getData('groups/sync_suppressed_schedule/fields/frequency/value');
18
-
19
- $frequencyHourly = Dotdigitalgroup_Email_Model_System_Config_Source_Syncfrequency::CRON_HOURLY;
20
- $frequencyDaily = Dotdigitalgroup_Email_Model_System_Config_Source_Syncfrequency::CRON_DAILY;
21
- $frequencyWeekly = Dotdigitalgroup_Email_Model_System_Config_Source_Syncfrequency::CRON_WEEKLY;
22
- $frequencyMonthly = Dotdigitalgroup_Email_Model_System_Config_Source_Syncfrequency::CRON_MONTHLY;
23
-
24
- if ($enabled) {
25
- $cronDayOfWeek = date('N');
26
- $cronExprArray = array(
27
- ($frequency == $frequencyHourly) ? intval($time[1]) : '*', # Minute
28
- ($frequency == $frequencyDaily) ? intval($time[0]) : '*', # Hour
29
- ($frequency == $frequencyMonthly) ? '1' : '*', # Day of the Month
30
- '*', # Month of the Year
31
- ($frequency == $frequencyWeekly) ? $cronDayOfWeek : '*', # Day of the Week
32
- );
33
- $cronExprString = join(' ', $cronExprArray);
34
- }
35
- else {
36
- $cronExprString = '';
37
- }
38
-
39
- try {
40
- // store config $cronExprString
41
-
42
-
43
- Mage::getModel('core/config_data')
44
- ->load(self::CRON_STRING_PATH, 'path')
45
- ->setValue($cronExprString)
46
- ->setPath(self::CRON_STRING_PATH)
47
- ->save();
48
-
49
- }
50
- catch (Exception $e) {
51
- Mage::throwException('Unable to save the cron expression.');
52
- }
53
- }
54
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Model/System/Config/Source/Activebasket.php DELETED
@@ -1,12 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Model_System_Config_Source_Activebasket
4
- {
5
- function toOptionArray()
6
- {
7
- return array(
8
- array('value' => '0', 'label' => Mage::helper('connector')->__('Success Page')),
9
- array('value' => '1', 'label' => Mage::helper('connector')->__('Complete Order'))
10
- );
11
- }
12
- }
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Model/System/Config/Source/Addressbooks.php DELETED
@@ -1,30 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Model_System_Config_Source_Addressbooks extends Dotdigitalgroup_Email_Model_Api_Rest
4
- {
5
- // Returns the account's datafields
6
- public function toOptionArray()
7
- {
8
- $fields = array();
9
- //load the configuration for website select in admin
10
- $websiteName = Mage::app()->getRequest()->getParam('website');
11
- if(! empty($websiteName)){
12
- $websites = Mage::getModel('core/website')->getCollection()
13
- ->addFieldToFilter('code', $websiteName);
14
- $website = $websites->getFirstItem();
15
- $this->_api_user = $website->getConfig(Dotdigitalgroup_Email_Model_Customer_Customer::XML_PATH_CONNECTOR_API_USERNAME);
16
- $this->_api_password = $website->getConfig(Dotdigitalgroup_Email_Model_Customer_Customer::XML_PATH_CONNECTOR_API_PASSWORD);
17
- }
18
- $addressBooks = $this->postAddressBooks();
19
-
20
- //set up fields with book id and label
21
- foreach ($addressBooks as $book){
22
-
23
- if(isset($book->id))
24
- $fields[] = array('value' => $book->id, 'label' => $book->name);
25
- }
26
-
27
- return $fields;
28
- }
29
-
30
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Model/System/Config/Source/Campaigns.php DELETED
@@ -1,30 +0,0 @@
1
- <?php
2
- /**
3
- * Date: 15/04/2013
4
- * Time: 13:46
5
- */
6
- class Dotdigitalgroup_Email_Model_System_Config_Source_Campaigns extends Dotdigitalgroup_Email_Model_Api_Rest
7
- {
8
-
9
- // Returns the account's datafields
10
- public function toOptionArray()
11
- {
12
- $fields = array();
13
- $websiteName = Mage::app()->getRequest()->getParam('website');
14
- if(! empty($websiteName)){
15
- $websites = Mage::getModel('core/website')->getCollection()
16
- ->addFieldToFilter('code', $websiteName);
17
- $website = $websites->getFirstItem();
18
- $this->_api_user = $website->getConfig(Dotdigitalgroup_Email_Model_Customer_Customer::XML_PATH_CONNECTOR_API_USERNAME);
19
- $this->_api_password = $website->getConfig(Dotdigitalgroup_Email_Model_Customer_Customer::XML_PATH_CONNECTOR_API_PASSWORD);
20
- }
21
- $campaigns = $this->postCampaigns();
22
- foreach ($campaigns as $one){
23
- if(isset($one->id))
24
- $fields[] = array('value' => $one->id, 'label' => $one->name);
25
- }
26
-
27
- return $fields;
28
- }
29
-
30
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Model/System/Config/Source/Datafields.php DELETED
@@ -1,35 +0,0 @@
1
- <?php
2
- /**
3
- * Date: 15/04/2013
4
- * Time: 13:46
5
- */
6
- class Dotdigitalgroup_Email_Model_System_Config_Source_Datafields extends Dotdigitalgroup_Email_Model_Api_Rest
7
- {
8
-
9
- // Returns the account's datafields
10
- public function toOptionArray()
11
- {
12
- $fields = array();
13
- //load the configuration for website select in admin
14
- $websiteName = Mage::app()->getRequest()->getParam('website');
15
- if(! empty($websiteName)){
16
- $websites = Mage::getModel('core/website')->getCollection()
17
- ->addFieldToFilter('code', $websiteName);
18
- $website = $websites->getFirstItem();
19
- $this->_api_user = $website->getConfig(Dotdigitalgroup_Email_Model_Customer_Customer::XML_PATH_CONNECTOR_API_USERNAME);
20
- $this->_api_password = $website->getConfig(Dotdigitalgroup_Email_Model_Customer_Customer::XML_PATH_CONNECTOR_API_PASSWORD);
21
- }
22
-
23
- // Add a "Do Not Map" Option
24
- $fields[] = array('value' => 0, 'label' => 'Do Not Map');
25
-
26
- $datafileds = $this->postDataFields();
27
- foreach ($datafileds as $datafield) {
28
- if(isset($datafield->name))
29
- $fields[] = array('value' => $datafield->name, 'label' => $datafield->name);
30
- }
31
-
32
- return $fields;
33
- }
34
-
35
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Model/System/Config/Source/Displayifnot.php DELETED
@@ -1,12 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Model_System_Config_Source_Displayifnot
4
- {
5
- public function toOptionArray()
6
- {
7
- return array(
8
- array('value' => 'best-sellers', 'label' => Mage::helper('connector')->__('Best Sellers')),
9
- array('value' => 'most-viewed', 'label' => Mage::helper('connector')->__('Most Viewed'))
10
- );
11
- }
12
- }
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Model/System/Config/Source/Orderstatus.php DELETED
@@ -1,16 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Model_System_Config_Source_Orderstatus
4
- {
5
- public function toOptionArray(){
6
-
7
- $statusCollection = Mage::getModel('sales/order_status')->getCollection();
8
- $statuses = array();
9
-
10
- foreach ($statusCollection as $one) {
11
- $statuses[] = array('value' => $one->getStatus(), 'label' => Mage::helper('connector')->__($one->getLabel()));
12
- }
13
-
14
- return $statuses;
15
- }
16
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Dotdigitalgroup/Email/Model/System/Config/Source/Sendcampain.php DELETED
@@ -1,30 +0,0 @@
1
- <?php
2
-
3
- class Dotdigitalgroup_Email_Model_System_Config_Source_SendCampain
4
- {
5
- /**
6
- * send to campain options hours
7
- * @return array
8
- */
9
- public function toOptionArray()
10
- {
11
- return array(
12
- array('value'=>1 , 'label'=>Mage::helper('adminhtml')->__('1 Hour')),
13
- array('value'=>2 , 'label'=>Mage::helper('adminhtml')->__('2 Hours')),
14
- array('value'=>3 , 'label'=>Mage::helper('adminhtml')->__('3 Hours')),
15
- array('value'=>4 , 'label'=>Mage::helper('adminhtml')->__('4 Hours')),
16
- array('value'=>5 , 'label'=>Mage::helper('adminhtml')->__('5 Hours')),
17
- array('value'=>6 , 'label'=>Mage::helper('adminhtml')->__('6 Hours')),
18
- array('value'=>12 , 'label'=>Mage::helper('adminhtml')->__('12 Hours')),
19
- array('value'=>36 , 'label'=>Mage::helper('adminhtml')->__('36 Hours')),
20
- array('value'=>48 , 'label'=>Mage::helper('adminhtml')->__('48 Hours')),
21
- array('value'=>60 , 'label'=>Mage::helper('adminhtml')->__('60 Hours')),
22
- array('value'=>72 , 'label'=>Mage::helper('adminhtml')->__('72 Hours')),
23
- array('value'=>84 , 'label'=>Mage::helper('adminhtml')->__('84 Hours')),
24
- array('value'=>96 , 'label'=>Mage::helper('adminhtml')->__('96