dotmailermagento - Version 4.1.3

Version Notes

New Automation improvements.

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 4.1.3
Comparing to
See all releases


Code changes from version 1.5.1 to 4.1.3

Files changed (268) hide show
  1. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Automation.php +17 -0
  2. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Automation/Edit.php +35 -0
  3. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Automation/Edit/Form.php +26 -0
  4. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Automation/Grid.php +153 -0
  5. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Campaign.php +17 -0
  6. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Campaign/Edit.php +39 -0
  7. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Campaign/Edit/Form.php +54 -0
  8. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Campaign/Grid.php +173 -0
  9. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Column/Renderer/Imported.php +16 -0
  10. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Column/Renderer/Status.php +18 -0
  11. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Column/Renderer/Sync.php +16 -0
  12. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Column/Renderer/Website.php +15 -0
  13. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Config.php +18 -0
  14. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Config/Customdatafields.php +112 -0
  15. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Config/Select.php +14 -0
  16. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Contact.php +17 -0
  17. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Contact/Edit.php +36 -0
  18. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Contact/Edit/Form.php +26 -0
  19. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Contact/Grid.php +219 -0
  20. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard.php +52 -0
  21. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Switcher.php +92 -0
  22. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs.php +58 -0
  23. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Analysis.php +61 -0
  24. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Analysis/Abandonedcarts.php +57 -0
  25. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Analysis/Customer.php +55 -0
  26. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Analysis/Rfm.php +91 -0
  27. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Analysis/Sales.php +54 -0
  28. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Analysis/Subscriber.php +56 -0
  29. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Config.php +120 -0
  30. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/General.php +107 -0
  31. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/General/Data.php +43 -0
  32. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Status.php +1773 -0
  33. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Order.php +15 -0
  34. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Order/Grid.php +110 -0
  35. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Quote.php +15 -0
  36. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Quote/Grid.php +130 -0
  37. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Review.php +15 -0
  38. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Review/Grid.php +109 -0
  39. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Sales/Order/Creditmemo/View.php +196 -0
  40. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/.DS_Store +0 -0
  41. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Deletecontactids.php +22 -0
  42. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Notification.php +11 -0
  43. app/code/{local/Dotdigitalgroup/Email/Block/Debug/Countcontacts.php → community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Reimportorders.php} +7 -6
  44. app/code/{local/Dotdigitalgroup/Email/Block/Debug/Deletecontacts.php → community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Reimportquotes.php} +7 -6
  45. app/code/{local/Dotdigitalgroup/Email/Block/Debug/Initialsync.php → community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Reimportreviews.php} +9 -7
  46. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Reimportsubscribers.php +22 -0
  47. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Reimportwishlists.php +22 -0
  48. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Resetcustomersimport.php +22 -0
  49. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Runcontactsync.php +22 -0
  50. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Runordersync.php +22 -0
  51. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Runquotesync.php +22 -0
  52. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Runreviewsync.php +22 -0
  53. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Runsubscribersync.php +22 -0
  54. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Runwishlistsync.php +22 -0
  55. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Setupdatafields.php +24 -0
  56. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Suppressedcontacts.php +23 -0
  57. app/code/{local/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Password.php → community/Dotdigitalgroup/Email/Block/Adminhtml/System/Ajaxvalidate.php} +1 -1
  58. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Automation/Connect.php +41 -0
  59. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Addressbook.php +39 -0
  60. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Colorpicker.php +66 -0
  61. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Datafield.php +41 -0
  62. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Enterprisevalidator.php +30 -0
  63. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Resetcontacts.php +28 -0
  64. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Resetguests.php +28 -0
  65. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Resetsubscribers.php +28 -0
  66. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Smtpvalidator.php +36 -0
  67. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Validator.php +87 -0
  68. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Waitingfield.php +65 -0
  69. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Wrapper.php +59 -0
  70. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Addressbookbutton.php +22 -0
  71. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Basket/Crosssell.php +26 -0
  72. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Basket/Related.php +27 -0
  73. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Basket/Upsell.php +25 -0
  74. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Bestsellers.php +24 -0
  75. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Couponinfo.php +26 -0
  76. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Creditmemonew.php +25 -0
  77. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Crosssell.php +26 -0
  78. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Datafieldbutton.php +21 -0
  79. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Fallbackchooser.php +25 -0
  80. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Fallbackcontainer.php +27 -0
  81. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Feefo/Reviews.php +22 -0
  82. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Feefo/Score.php +22 -0
  83. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Gridlist.php +106 -0
  84. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Lostbasket.php +31 -0
  85. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Manualchooser.php +25 -0
  86. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Manualcontainer.php +27 -0
  87. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Mostviewed.php +21 -0
  88. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Nosto.php +22 -0
  89. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Productpush.php +21 -0
  90. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Recentlyviewed.php +24 -0
  91. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Related.php +26 -0
  92. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Review.php +29 -0
  93. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Upsell.php +24 -0
  94. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Wishlist.php +33 -0
  95. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Wishlist/Crosssell.php +32 -0
  96. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Wishlist/Related.php +32 -0
  97. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Wishlist/Upsell.php +31 -0
  98. app/code/{local/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Wrapper.php → community/Dotdigitalgroup/Email/Block/Adminhtml/System/Emailapivalidate.php} +9 -8
  99. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Sms/Smsmessagefour.php +24 -0
  100. app/code/{local/Dotdigitalgroup/Email/Block/Adminhtml/System/Config → community/Dotdigitalgroup/Email/Block/Adminhtml/System/Sms}/Smsmessageone.php +13 -8
  101. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Sms/Smsmessagethree.php +26 -0
  102. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Sms/Smsmessagetwo.php +25 -0
  103. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Creditmemoupdate.php +32 -0
  104. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Creditmemoupdateguest.php +30 -0
  105. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Customerconfirmation.php +36 -0
  106. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Customerconfirmed.php +36 -0
  107. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Customernew.php +36 -0
  108. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Invoiceupdate.php +33 -0
  109. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Invoiceupdateguest.php +33 -0
  110. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Newcreditmemo.php +36 -0
  111. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Newcreditmemoguest.php +35 -0
  112. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Newinvoice.php +34 -0
  113. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Newinvoiceguest.php +34 -0
  114. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Neworder.php +33 -0
  115. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Neworderguest.php +32 -0
  116. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Newshipment.php +34 -0
  117. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Newshipmentguest.php +33 -0
  118. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Orderupdate.php +31 -0
  119. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Orderupdateguest.php +31 -0
  120. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Shipmentupdate.php +33 -0
  121. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Shipmentupdateguest.php +32 -0
  122. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Widget/Chooser/Product.php +163 -0
  123. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Wishlist.php +15 -0
  124. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Wishlist/Grid.php +120 -0
  125. app/code/community/Dotdigitalgroup/Email/Block/Basket.php +56 -0
  126. app/code/{local → community}/Dotdigitalgroup/Email/Block/Coupon.php +16 -16
  127. app/code/community/Dotdigitalgroup/Email/Block/Customer/Account/Books.php +217 -0
  128. app/code/community/Dotdigitalgroup/Email/Block/Feefo.php +101 -0
  129. app/code/community/Dotdigitalgroup/Email/Block/Order.php +87 -0
  130. app/code/community/Dotdigitalgroup/Email/Block/Order/Creditmemo.php +50 -0
  131. app/code/community/Dotdigitalgroup/Email/Block/Order/Invoice.php +45 -0
  132. app/code/community/Dotdigitalgroup/Email/Block/Order/Shipping.php +45 -0
  133. app/code/community/Dotdigitalgroup/Email/Block/Products.php +67 -0
  134. app/code/community/Dotdigitalgroup/Email/Block/Recommended/Bestsellers.php +96 -0
  135. app/code/community/Dotdigitalgroup/Email/Block/Recommended/Mostviewed.php +98 -0
  136. app/code/community/Dotdigitalgroup/Email/Block/Recommended/Products.php +194 -0
  137. app/code/community/Dotdigitalgroup/Email/Block/Recommended/Push.php +66 -0
  138. app/code/community/Dotdigitalgroup/Email/Block/Recommended/Quoteproducts.php +149 -0
  139. app/code/community/Dotdigitalgroup/Email/Block/Recommended/Recentlyviewed.php +73 -0
  140. app/code/community/Dotdigitalgroup/Email/Block/Recommended/Wishlistproducts.php +176 -0
  141. app/code/community/Dotdigitalgroup/Email/Block/System/Email/Template/Edit.php +15 -0
  142. app/code/community/Dotdigitalgroup/Email/Block/Wishlist.php +53 -0
  143. app/code/community/Dotdigitalgroup/Email/Helper/Config.php +323 -0
  144. app/code/community/Dotdigitalgroup/Email/Helper/Dashboard.php +171 -0
  145. app/code/community/Dotdigitalgroup/Email/Helper/Data.php +726 -0
  146. app/code/{local → community}/Dotdigitalgroup/Email/Helper/File.php +89 -31
  147. app/code/community/Dotdigitalgroup/Email/Helper/Recommended.php +178 -0
  148. app/code/community/Dotdigitalgroup/Email/Helper/Review.php +90 -0
  149. app/code/community/Dotdigitalgroup/Email/Model/Abstract/Rest.php +435 -0
  150. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Content.php +121 -0
  151. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Abandoned.php +59 -0
  152. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Customer.php +48 -0
  153. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Orders.php +122 -0
  154. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Rfm.php +173 -0
  155. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Subscriber.php +91 -0
  156. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Observer.php +230 -0
  157. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Addressbooks.php +46 -0
  158. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Addressbookspref.php +71 -0
  159. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Abandonedlimit.php +43 -0
  160. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Attributes.php +22 -0
  161. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Frequency.php +15 -0
  162. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Quoteattributes.php +21 -0
  163. app/code/{local/Dotdigitalgroup/Email/Model/System/Config/Source/Orderlimit.php → community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Transdata.php} +1 -1
  164. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Automation/Programme.php +32 -0
  165. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Campaigns.php +54 -0
  166. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Contact/Imported.php +17 -0
  167. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Customer/Attributes/Select.php +34 -0
  168. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Datafields.php +55 -0
  169. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Datamapping/Datafieldaccess.php +17 -0
  170. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Datamapping/Datafieldtype.php +22 -0
  171. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Dynamic/Displaytype.php +18 -0
  172. app/code/{local/Dotdigitalgroup/Email/Model/System/Config/Source → community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Dynamic}/Gridview.php +6 -1
  173. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Fontpicker.php +35 -0
  174. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Fontsize.php +30 -0
  175. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Lostbaskets/Interval.php +40 -0
  176. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Lostbaskets/Intervalminute.php +21 -0
  177. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Orderstatus.php +28 -0
  178. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Publicdatafields.php +63 -0
  179. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Reviews/Campaigns.php +48 -0
  180. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Reviews/Delay.php +26 -0
  181. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Styling.php +18 -0
  182. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Sweettooth/Yesno.php +26 -0
  183. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Transactional/Yesno.php +26 -0
  184. app/code/community/Dotdigitalgroup/Email/Model/Api2/Subscriber/Rest/Admin/V1.php +111 -0
  185. app/code/community/Dotdigitalgroup/Email/Model/Apiconnector/Client.php +1291 -0
  186. app/code/community/Dotdigitalgroup/Email/Model/Apiconnector/Contact.php +423 -0
  187. app/code/community/Dotdigitalgroup/Email/Model/Apiconnector/Customer.php +901 -0
  188. app/code/community/Dotdigitalgroup/Email/Model/Apiconnector/Test.php +54 -0
  189. app/code/community/Dotdigitalgroup/Email/Model/Automation.php +284 -0
  190. app/code/community/Dotdigitalgroup/Email/Model/Campaign.php +144 -0
  191. app/code/community/Dotdigitalgroup/Email/Model/Config.php +65 -0
  192. app/code/{local → community}/Dotdigitalgroup/Email/Model/Connector/Account.php +10 -8
  193. app/code/community/Dotdigitalgroup/Email/Model/Connector/Campaign.php +100 -0
  194. app/code/community/Dotdigitalgroup/Email/Model/Connector/Datafield.php +293 -0
  195. app/code/community/Dotdigitalgroup/Email/Model/Connector/Order.php +279 -0
  196. app/code/community/Dotdigitalgroup/Email/Model/Connector/Quote.php +282 -0
  197. app/code/community/Dotdigitalgroup/Email/Model/Contact.php +290 -0
  198. app/code/community/Dotdigitalgroup/Email/Model/Controller/Observer.php +43 -0
  199. app/code/community/Dotdigitalgroup/Email/Model/Cron.php +155 -0
  200. app/code/community/Dotdigitalgroup/Email/Model/Customer.php +20 -0
  201. app/code/community/Dotdigitalgroup/Email/Model/Customer/Guest.php +67 -0
  202. app/code/community/Dotdigitalgroup/Email/Model/Customer/Observer.php +358 -0
  203. app/code/community/Dotdigitalgroup/Email/Model/Customer/Review.php +240 -0
  204. app/code/community/Dotdigitalgroup/Email/Model/Customer/Review/Rating.php +46 -0
  205. app/code/community/Dotdigitalgroup/Email/Model/Customer/Wishlist.php +120 -0
  206. app/code/{local → community}/Dotdigitalgroup/Email/Model/Customer/Wishlist/Item.php +25 -12
  207. app/code/community/Dotdigitalgroup/Email/Model/Feed.php +88 -0
  208. app/code/community/Dotdigitalgroup/Email/Model/Newsletter/Observer.php +124 -0
  209. app/code/community/Dotdigitalgroup/Email/Model/Newsletter/Sub.php +12 -0
  210. app/code/community/Dotdigitalgroup/Email/Model/Newsletter/Subscriber.php +186 -0
  211. app/code/community/Dotdigitalgroup/Email/Model/Order.php +142 -0
  212. app/code/community/Dotdigitalgroup/Email/Model/Quote.php +246 -0
  213. app/code/community/Dotdigitalgroup/Email/Model/Resource/Automation.php +14 -0
  214. app/code/community/Dotdigitalgroup/Email/Model/Resource/Automation/Collection.php +25 -0
  215. app/code/community/Dotdigitalgroup/Email/Model/Resource/Campaign.php +13 -0
  216. app/code/community/Dotdigitalgroup/Email/Model/Resource/Campaign/Collection.php +13 -0
  217. app/code/community/Dotdigitalgroup/Email/Model/Resource/Config.php +14 -0
  218. app/code/community/Dotdigitalgroup/Email/Model/Resource/Config/Collection.php +14 -0
  219. app/code/community/Dotdigitalgroup/Email/Model/Resource/Contact.php +14 -0
  220. app/code/community/Dotdigitalgroup/Email/Model/Resource/Contact/Collection.php +25 -0
  221. app/code/community/Dotdigitalgroup/Email/Model/Resource/Order.php +12 -0
  222. app/code/community/Dotdigitalgroup/Email/Model/Resource/Order/Collection.php +18 -0
  223. app/code/community/Dotdigitalgroup/Email/Model/Resource/Quote.php +12 -0
  224. app/code/community/Dotdigitalgroup/Email/Model/Resource/Quote/Collection.php +14 -0
  225. app/code/community/Dotdigitalgroup/Email/Model/Resource/Review.php +13 -0
  226. app/code/community/Dotdigitalgroup/Email/Model/Resource/Review/Collection.php +13 -0
  227. app/code/community/Dotdigitalgroup/Email/Model/Resource/Segment.php +154 -0
  228. app/code/community/Dotdigitalgroup/Email/Model/Resource/Setup.php +26 -0
  229. app/code/community/Dotdigitalgroup/Email/Model/Resource/Wishlist.php +13 -0
  230. app/code/community/Dotdigitalgroup/Email/Model/Resource/Wishlist/Collection.php +13 -0
  231. app/code/community/Dotdigitalgroup/Email/Model/Review.php +147 -0
  232. app/code/community/Dotdigitalgroup/Email/Model/Sales/Observer.php +283 -0
  233. app/code/community/Dotdigitalgroup/Email/Model/Sales/Order.php +323 -0
  234. app/code/community/Dotdigitalgroup/Email/Model/Sales/Quote.php +269 -0
  235. app/code/community/Dotdigitalgroup/Email/Model/Sms/Campaign.php +112 -0
  236. app/code/community/Dotdigitalgroup/Email/Model/Sweettooth/Observer.php +21 -0
  237. app/code/community/Dotdigitalgroup/Email/Model/Wishlist.php +202 -0
  238. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/ConnectorController.php +385 -0
  239. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/AutomationController.php +97 -0
  240. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/CampaignController.php +252 -0
  241. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/ContactController.php +192 -0
  242. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/DashboardController.php +91 -0
  243. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/OrderController.php +26 -0
  244. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/QuoteController.php +26 -0
  245. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/ReviewController.php +26 -0
  246. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/StudioController.php +111 -0
  247. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/WishlistController.php +26 -0
  248. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/System/Email/TemplateController.php +36 -0
  249. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Widget/ChooserController.php +19 -0
  250. app/code/community/Dotdigitalgroup/Email/controllers/AjaxController.php +21 -0
  251. app/code/community/Dotdigitalgroup/Email/controllers/CreditmemoController.php +70 -0
  252. app/code/community/Dotdigitalgroup/Email/controllers/Customer/NewsletterController.php +129 -0
  253. app/code/community/Dotdigitalgroup/Email/controllers/DynamicContentController.php +39 -0
  254. app/code/community/Dotdigitalgroup/Email/controllers/EmailController.php +119 -0
  255. app/code/community/Dotdigitalgroup/Email/controllers/FeefoController.php +63 -0
  256. app/code/community/Dotdigitalgroup/Email/controllers/InvoiceController.php +75 -0
  257. app/code/community/Dotdigitalgroup/Email/controllers/OrderController.php +75 -0
  258. app/code/community/Dotdigitalgroup/Email/controllers/ProductsController.php +114 -0
  259. app/code/community/Dotdigitalgroup/Email/controllers/QuoteproductsController.php +96 -0
  260. app/code/community/Dotdigitalgroup/Email/controllers/ReportController.php +70 -0
  261. app/code/community/Dotdigitalgroup/Email/controllers/ResponseController.php +42 -0
  262. app/code/community/Dotdigitalgroup/Email/controllers/ShippingController.php +88 -0
  263. app/code/community/Dotdigitalgroup/Email/controllers/WishlistController.php +50 -0
  264. app/code/community/Dotdigitalgroup/Email/etc/adminhtml.xml +186 -0
  265. app/code/community/Dotdigitalgroup/Email/etc/api2.xml +43 -0
  266. app/code/community/Dotdigitalgroup/Email/etc/config.xml +692 -0
  267. app/code/community/Dotdigitalgroup/Email/etc/files.yaml +292 -0
  268. app/code/community/Dotdigitalgroup/Email/etc/system.xml +2249 -0
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Automation.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Automation extends Mage_Adminhtml_Block_Widget_Grid_Container
4
+ {
5
+ /**
6
+ * Set the template.
7
+ */
8
+ public function __construct()
9
+ {
10
+ $this->_controller = 'adminhtml_automation';
11
+ $this->_blockGroup = 'ddg_automation';
12
+ parent::__construct();
13
+ $this->_headerText = Mage::helper('ddg')->__('Automation Status');
14
+ $this->_removeButton('add');
15
+
16
+ }
17
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Automation/Edit.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Automation_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+ $this->_blockGroup = 'ddg_automation';
9
+ $this->_controller = 'adminhtml_automation';
10
+ $this->_updateButton('delete', 'label', Mage::helper('ddg')->__('Delete Contact'));
11
+ $this->_addButton('saveandcontinue', array(
12
+ 'label' => Mage::helper('ddg')->__('Save And Continue Edit'),
13
+ 'onclick' => 'saveAndContinueEdit()',
14
+ 'class' => 'save',
15
+ ), -100);
16
+ $this->_formScripts[] = "
17
+ function saveAndContinueEdit(){
18
+ editForm.submit($('edit_form').action+'back/edit/');
19
+ }
20
+ ";
21
+ }
22
+
23
+ /**
24
+ * HEader text.
25
+ * @return string
26
+ */
27
+ public function getHeaderText()
28
+ {
29
+ if ( Mage::registry('automation_data') && Mage::registry('contact_data')->getId() ) {
30
+ return Mage::helper('ddg')->__("Edit Automation '%s'", $this->htmlEscape(Mage::registry('contact_data')->getContact()));
31
+ } else {
32
+ return Mage::helper('ddg')->__('Add Automation');
33
+ }
34
+ }
35
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Automation/Edit/Form.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Automation_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/Automation/Grid.php ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Automation_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
+ protected function _prepareCollection()
17
+ {
18
+ $collection = Mage::getModel('ddg_automation/automation')->getCollection();
19
+ $this->setCollection($collection);
20
+ $this->setDefaultSort('updated_at');
21
+ $this->setDefaultDir('DESC');
22
+ return parent::_prepareCollection();
23
+ }
24
+
25
+ protected function _prepareColumns()
26
+ {
27
+ $this->addColumn('id', array(
28
+ 'header' => Mage::helper('ddg')->__('ID'),
29
+ 'index' => 'id',
30
+ 'type' => 'number',
31
+ 'escape' => true,
32
+ ))->addColumn('program_id', array(
33
+ 'header' => Mage::helper('ddg')->__('Program ID'),
34
+ 'align' => 'center',
35
+ 'index' => 'program_id',
36
+ 'type' => 'number',
37
+ 'escape' => true,
38
+ ))->addColumn('automation_type', array(
39
+ 'header' => Mage::helper('ddg')->__('Automation Type'),
40
+ 'align' => 'right',
41
+ 'index' => 'automation_type',
42
+ 'type' => 'text',
43
+ 'escape' => true
44
+ ))->addColumn('enrolment_status', array(
45
+ 'header' => Mage::helper('ddg')->__('Enrollment Status'),
46
+ 'align' => 'left',
47
+ 'index' => 'enrolment_status',
48
+ 'type' => 'options',
49
+ 'options' => array(
50
+ 'pending' => 'Pending',
51
+ 'Active' => 'Active',
52
+ 'Draft' => 'Draft',
53
+ 'Deactivated' => 'Deactivated',
54
+ 'ReadOnly' => 'ReadOnly',
55
+ 'NotAvailableInThisVersion' => 'NotAvailableInThisVersion',
56
+ 'Failed' => 'Failed',
57
+ 'Suppressed' => 'Suppressed'
58
+ ),
59
+ 'escape' => true
60
+ ))->addColumn('email', array(
61
+ 'header' => Mage::helper('ddg')->__('Email'),
62
+ 'align' => 'right',
63
+ 'index' => 'email',
64
+ 'type' => 'text',
65
+ 'escape' => true,
66
+ ))->addColumn('type_id', array(
67
+ 'header' => Mage::helper('ddg')->__('Type ID'),
68
+ 'align' => 'center',
69
+ 'index' => 'type_id',
70
+ 'type' => 'number',
71
+ 'escape' => true,
72
+ ))->addColumn('message', array(
73
+ 'header' => Mage::helper('ddg')->__('Message'),
74
+ 'align' => 'right',
75
+ 'index' => 'message',
76
+ 'type' => 'text',
77
+ 'escape' => true
78
+ ))->addColumn('created_at', array(
79
+ 'header' => Mage::helper('ddg')->__('Created_at'),
80
+ 'align' => 'center',
81
+ 'index' => 'created_at',
82
+ 'escape' => true,
83
+ 'type' => 'datetime'
84
+
85
+ ));
86
+ if (!Mage::app()->isSingleStoreMode()) {
87
+ $this->addColumn('website_id', array(
88
+ 'header' => Mage::helper('customer')->__('Website'),
89
+ 'align' => 'center',
90
+ 'type' => 'options',
91
+ 'options' => Mage::getSingleton('adminhtml/system_store')->getWebsiteOptionHash(true),
92
+ 'index' => 'website_id',
93
+ ));
94
+ }
95
+
96
+ $this->addExportType('*/*/exportCsv', Mage::helper('ddg')->__('CSV'));
97
+ return parent::_prepareColumns();
98
+ }
99
+
100
+ /**
101
+ * Get the store.
102
+ *
103
+ * @return Mage_Core_Model_Store
104
+ * @throws Exception
105
+ */
106
+ protected function _getStore()
107
+ {
108
+ $storeId = (int) $this->getRequest()->getParam('store', 0);
109
+ return Mage::app()->getStore($storeId);
110
+ }
111
+
112
+ /**
113
+ * Prepare the grid massaction.
114
+ * @return $this|Mage_Adminhtml_Block_Widget_Grid
115
+ */
116
+ protected function _prepareMassaction()
117
+ {
118
+ $this->setMassactionIdField('id');
119
+ $this->getMassactionBlock()->setFormFieldName('automation');
120
+ $this->getMassactionBlock()->addItem('resend', array(
121
+ 'label' => Mage::helper('ddg')->__('Resend'),
122
+ 'url' => $this->getUrl('*/*/massResend'),
123
+
124
+ ));
125
+ $this->getMassactionBlock()->addItem('delete', array(
126
+ 'label'=> Mage::helper('ddg')->__('Delete'),
127
+ 'url' => $this->getUrl('*/*/massDelete'),
128
+ 'confirm' => Mage::helper('ddg')->__('Are you sure?')));
129
+
130
+ return $this;
131
+ }
132
+
133
+ /**
134
+ * Edit the row.
135
+ * @param $row
136
+ *
137
+ * @return string
138
+ */
139
+ public function getRowUrl($row)
140
+ {
141
+ return $this->getUrl('*/*/edit', array('id' => $row->getEmailContactId()));
142
+ }
143
+
144
+ /**
145
+ * Grid url.
146
+ * @return string
147
+ */
148
+ public function getGridUrl()
149
+ {
150
+ return $this->getUrl('*/*/grid', array('_current'=>true));
151
+ }
152
+
153
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Campaign.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 = 'ddg_automation';
12
+ parent::__construct();
13
+ $this->_headerText = Mage::helper('ddg')->__('Campaigns');
14
+ $this->_removeButton('add');
15
+
16
+ }
17
+ }
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 = 'ddg_automation';
12
+ $this->_controller = 'adminhtml_campaign';
13
+ $this->_mode = 'edit';
14
+ $this->_updateButton('save', 'label', Mage::helper('ddg')->__('Save Campaign'));
15
+ $this->_updateButton('delete', 'label', Mage::helper('ddg')->__('Delete Campaign'));
16
+ $this->_addButton('saveandcontinue', array(
17
+ 'label' => Mage::helper('ddg')->__('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('ddg')->__("Edit Campaign '%s'", $this->htmlEscape(Mage::registry('email_campaign')->getContact()));
35
+ } else {
36
+ return Mage::helper('ddg')->__('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('ddg')->__('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('ddg')->__('Name'),
44
+ 'title' => Mage::helper('ddg')->__('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,173 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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('ddg_automation/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('ddg')->__('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('ddg')->__('Email'),
39
+ 'align' => 'left',
40
+ 'width' => '50px',
41
+ 'index' => 'email',
42
+ 'type' => 'text',
43
+ 'escape' => true
44
+ ))->addColumn('is_sent', array(
45
+ 'header' => Mage::helper('ddg')->__('Is Sent'),
46
+ 'align' => 'center',
47
+ 'width' => '20px',
48
+ 'index' => 'is_sent',
49
+ 'escape' => true,
50
+ 'type' => 'options',
51
+ 'renderer' => 'ddg_automation/adminhtml_column_renderer_imported',
52
+ 'options' => array(
53
+ '1' => 'Is Send',
54
+ 'null' => 'Not Send'
55
+ ),
56
+ 'filter_condition_callback' => array($this, 'filterCallbackContact')
57
+ ))->addColumn('order_increment_id', array(
58
+ 'header' => Mage::helper('ddg')->__('Increment ID'),
59
+ 'align' => 'left',
60
+ 'width' => '50px',
61
+ 'index' => 'order_increment_id',
62
+ 'type' => 'number',
63
+ 'escape' => true
64
+ ))->addColumn('message', array(
65
+ 'header' => Mage::helper('ddg')->__('Send Message'),
66
+ 'align' => 'left',
67
+ 'width' => '300px',
68
+ 'index' => 'message',
69
+ 'type' => 'text',
70
+ 'escape' => true
71
+ ))->addColumn('event_name', array(
72
+ 'header' => Mage::helper('ddg')->__('Email Name'),
73
+ 'align' => 'left',
74
+ 'index' => 'event_name',
75
+ 'width' => '100px',
76
+ 'type' => 'string',
77
+ 'escape' => true,
78
+ ))->addColumn('created_at', array(
79
+ 'header' => Mage::helper('ddg')->__('Created At'),
80
+ 'align' => 'center',
81
+ 'width' => '100px',
82
+ 'index' => 'created_at',
83
+ 'type' => 'datetime',
84
+ 'escape' => true
85
+ ))->addColumn('updated_at', array(
86
+ 'header' => Mage::helper('ddg')->__('Updated At'),
87
+ 'align' => 'center',
88
+ 'width' => '100px',
89
+ 'index' => 'updated_at',
90
+ 'type' => 'datetime',
91
+ 'escape' => true
92
+ ))->addColumn('sent_at', array(
93
+ 'header' => Mage::helper('ddg')->__('Sent At'),
94
+ 'align' => 'center',
95
+ 'width' => '100px',
96
+ 'index' => 'sent_at',
97
+ 'type' => 'datetime',
98
+ 'escape' => true
99
+ ));
100
+ if (!Mage::app()->isSingleStoreMode()) {
101
+ $this->addColumn('website_id', array(
102
+ 'header' => Mage::helper('customer')->__('Website'),
103
+ 'align' => 'center',
104
+ 'width' => '80px',
105
+ 'type' => 'options',
106
+ 'options' => Mage::getSingleton('adminhtml/system_store')->getWebsiteOptionHash(true),
107
+ 'index' => 'store_id',
108
+ 'renderer' => 'ddg_automation/adminhtml_column_renderer_website',
109
+ ));
110
+ }
111
+
112
+ $this->addExportType('*/*/exportCsv', Mage::helper('ddg')->__('CSV'));
113
+ return parent::_prepareColumns();
114
+ }
115
+
116
+ /**
117
+ * Get the store selected.
118
+ * @return Mage_Core_Model_Store
119
+ * @throws Exception
120
+ */
121
+ protected function _getStore()
122
+ {
123
+ $storeId = (int) $this->getRequest()->getParam('store', 0);
124
+ return Mage::app()->getStore($storeId);
125
+ }
126
+
127
+
128
+ /**
129
+ * @return $this|Mage_Adminhtml_Block_Widget_Grid
130
+ */
131
+ protected function _prepareMassaction()
132
+ {
133
+ $this->setMassactionIdField('id');
134
+ $this->getMassactionBlock()->setFormFieldName('campaign');
135
+ $this->getMassactionBlock()->addItem('delete', array (
136
+ 'label'=> Mage::helper('ddg')->__('Delete'),
137
+ 'url' => $this->getUrl('*/*/massDelete'),
138
+ 'confirm' => Mage::helper('ddg')->__('Are you sure?')
139
+ )
140
+ );
141
+
142
+ $this->getMassactionBlock()->addItem('resend', array('label'=>Mage::helper('ddg')->__('Resend'),'url'=>$this->getUrl('*/*/massResend')));
143
+ $this->getMassactionBlock()->addItem('re-create', array('label'=>Mage::helper('ddg')->__('Recreate'),'url'=>$this->getUrl('*/*/massRecreate')));
144
+ return $this;
145
+ }
146
+
147
+ /**
148
+ * Grid selected url.
149
+ * @return string
150
+ */
151
+ public function getGridUrl()
152
+ {
153
+ return $this->getUrl('*/*/grid', array('_current'=>true));
154
+ }
155
+ /**
156
+ * Custom callback action for the campaign.
157
+ *
158
+ * @param $collection
159
+ * @param $column
160
+ */
161
+ public function filterCallbackContact($collection, $column)
162
+ {
163
+ $field = $column->getFilterIndex() ? $column->getFilterIndex() : $column->getIndex();
164
+ $value = $column->getFilter()->getValue();
165
+
166
+ if ($value == 'null') {
167
+ $collection->addFieldToFilter($field, array('null' => true) );
168
+ } else {
169
+ $collection->addFieldToFilter($field, array('notnull' => true));
170
+ }
171
+ }
172
+
173
+ }
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/Column/Renderer/Website.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Column_Renderer_Website 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 Mage::app()->getStore($this->_getValue($row))->getWebsiteId();
14
+ }
15
+ }
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 = 'ddg_automation';
12
+ parent::__construct();
13
+ $this->_headerText = Mage::helper('ddg')->__('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('ddg_automation/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('ddg_automation/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('ddg_automation/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/Contact.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 = 'ddg_automation';
12
+ parent::__construct();
13
+ $this->_headerText = Mage::helper('ddg')->__('Contacts');
14
+ $this->_removeButton('add');
15
+
16
+ }
17
+ }
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 = 'ddg_automation';
9
+ $this->_controller = 'adminhtml_contact';
10
+ $this->_updateButton('save', 'label', Mage::helper('ddg')->__('Save Contact'));
11
+ $this->_updateButton('delete', 'label', Mage::helper('ddg')->__('Delete Contact'));
12
+ $this->_addButton('saveandcontinue', array(
13
+ 'label' => Mage::helper('ddg')->__('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('ddg')->__("Edit Contact '%s'", $this->htmlEscape(Mage::registry('contact_data')->getContact()));
32
+ } else {
33
+ return Mage::helper('ddg')->__('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,219 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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('ddg_automation/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('ddg')->__('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('ddg')->__('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('ddg')->__('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('ddg')->__('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('ddg')->__('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('ddg')->__('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('ddg')->__('Email Imported'),
85
+ 'width' => '20px',
86
+ 'align' => 'center',
87
+ 'index' => 'email_imported',
88
+ 'escape' => true,
89
+ 'type' => 'options',
90
+ 'options' => Mage::getModel('ddg_automation/adminhtml_source_contact_imported')->getOptions(),
91
+ 'renderer' => 'ddg_automation/adminhtml_column_renderer_imported',
92
+ 'filter_condition_callback' => array($this, 'filterCallbackContact')
93
+ ))->addColumn('subscriber_imported', array(
94
+ 'header' => Mage::helper('ddg')->__('Subscriber Imported'),
95
+ 'width' => '20px',
96
+ 'align' => 'center',
97
+ 'index' => 'subscriber_imported',
98
+ 'type' => 'options',
99
+ 'escape' => true,
100
+ 'renderer' => 'ddg_automation/adminhtml_column_renderer_imported',
101
+ 'options' => Mage::getModel('ddg_automation/adminhtml_source_contact_imported')->getOptions(),
102
+ 'filter_condition_callback' => array($this, 'filterCallbackContact')
103
+ ))->addColumn('suppressed', array(
104
+ 'header' => Mage::helper('ddg')->__('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
+
117
+ //Enterprise customer segments.
118
+ if (Mage::helper('ddg')->isEnterprise()) {
119
+ $this->addColumn( 'segment_ids', array(
120
+ 'header' => Mage::helper( 'ddg' )->__( 'Segment Id\'s' ),
121
+ 'align' => 'right',
122
+ 'width' => '50px',
123
+ 'index' => 'segment_ids',
124
+ 'escape' => true,
125
+ 'type' => 'text'
126
+ ) );
127
+ }
128
+ if (!Mage::app()->isSingleStoreMode()) {
129
+ $this->addColumn('website_id', array(
130
+ 'header' => Mage::helper('customer')->__('Website'),
131
+ 'align' => 'center',
132
+ 'width' => '80px',
133
+ 'type' => 'options',
134
+ 'options' => Mage::getSingleton('adminhtml/system_store')->getWebsiteOptionHash(true),
135
+ 'index' => 'website_id',
136
+ ));
137
+ }
138
+
139
+ $this->addColumn('sync', array(
140
+ 'header' => Mage::helper('ddg')->__('Sync Contact'),
141
+ 'align' => 'center',
142
+ 'width' => '80px',
143
+ 'renderer' => 'ddg_automation/adminhtml_column_renderer_sync'
144
+
145
+ ));
146
+
147
+ $this->addExportType('*/*/exportCsv', Mage::helper('ddg')->__('CSV'));
148
+ return parent::_prepareColumns();
149
+ }
150
+
151
+ /**
152
+ * Get the store.
153
+ *
154
+ * @return Mage_Core_Model_Store
155
+ * @throws Exception
156
+ */
157
+ protected function _getStore()
158
+ {
159
+ $storeId = (int) $this->getRequest()->getParam('store', 0);
160
+ return Mage::app()->getStore($storeId);
161
+ }
162
+
163
+ /**
164
+ * Prepare the grid massaction.
165
+ * @return $this|Mage_Adminhtml_Block_Widget_Grid
166
+ */
167
+ protected function _prepareMassaction()
168
+ {
169
+ $this->setMassactionIdField('email_contact_id');
170
+ $this->getMassactionBlock()->setFormFieldName('contact');
171
+ $this->getMassactionBlock()->addItem('delete', array(
172
+ 'label'=> Mage::helper('ddg')->__('Delete'),
173
+ 'url' => $this->getUrl('*/*/massDelete'),
174
+ 'confirm' => Mage::helper('ddg')->__('Are you sure?')));
175
+ $this->getMassactionBlock()->addItem('resend', array(
176
+ 'label' => Mage::helper('ddg')->__('Resend'),
177
+ 'url' => $this->getUrl('*/*/massResend'),
178
+
179
+ ));
180
+ return $this;
181
+ }
182
+
183
+ /**
184
+ * Custom callback action for the subscribers/contacts.
185
+ * @param $collection
186
+ * @param $column
187
+ */
188
+ public function filterCallbackContact($collection, $column)
189
+ {
190
+ $field = $column->getFilterIndex() ? $column->getFilterIndex() : $column->getIndex();
191
+ $value = $column->getFilter()->getValue();
192
+
193
+ if ($value == 'null')
194
+ $collection->addFieldToFilter($field, array('null' => true));
195
+ else
196
+ $collection->addFieldToFilter($field, array('notnull' => true));
197
+ }
198
+
199
+ /**
200
+ * Edit the row.
201
+ * @param $row
202
+ *
203
+ * @return string
204
+ */
205
+ public function getRowUrl($row)
206
+ {
207
+ return $this->getUrl('*/*/edit', array('id' => $row->getEmailContactId()));
208
+ }
209
+
210
+ /**
211
+ * Grid url.
212
+ * @return string
213
+ */
214
+ public function getGridUrl()
215
+ {
216
+ return $this->getUrl('*/*/grid', array('_current'=>true));
217
+ }
218
+
219
+ }
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('ddg')->getApiUsername($website);
35
+ $apiPassword = Mage::helper('ddg')->getApiPassword($website);
36
+
37
+ //api get account info
38
+ $data = Mage::getModel('ddg_automation/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('ddg_automation/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('ddg_automation/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('ddg_automation/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('ddg_automation/adminhtml_dashboard_tabs_analysis_sales')
26
+ );
27
+ $this->setChild('abandoned_cart',
28
+ $this->getLayout()->createBlock('ddg_automation/adminhtml_dashboard_tabs_analysis_abandonedcarts')
29
+ );
30
+ $this->setChild('customer',
31
+ $this->getLayout()->createBlock('ddg_automation/adminhtml_dashboard_tabs_analysis_customer')
32
+ );
33
+ $this->setChild('subscriber',
34
+ $this->getLayout()->createBlock('ddg_automation/adminhtml_dashboard_tabs_analysis_subscriber')
35
+ );
36
+ $this->setChild('rfm',
37
+ $this->getLayout()->createBlock('ddg_automation/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('ddg_automation/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('ddg_automation/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('ddg_automation/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('ddg_automation/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('ddg_automation/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,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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('ddg_automation/config')->getCollection()
45
+ ->addFieldToFilter('path', array('neq' => 'connector_api_hour_trigger'))
46
+ ->addFieldToFilter('is_api', true);
47
+
48
+ $data = $collection->getData();
49
+
50
+ return $data;
51
+ }
52
+
53
+ /**
54
+ * Get the time trigger from collection.
55
+ * @return mixed
56
+ */
57
+ public function getTimeTrigger()
58
+ {
59
+ $timeData = Mage::getModel('ddg_automation/config')->getCollection()
60
+ ->addFieldToFilter('path', Dotdigitalgroup_Email_Helper_Config::CONNECTOR_EMAIL_CONFIG_HOUR_TRIGGER)
61
+ ->setPageSize(1)
62
+ ->getFirstItem();
63
+
64
+ return $timeData->getValue();
65
+ }
66
+
67
+ /**
68
+ * Format the date string.
69
+ * @param $date
70
+ *
71
+ * @return string
72
+ */
73
+ public function formatDateString($date)
74
+ {
75
+ if ($date) {
76
+ $date = new Zend_Date($date);
77
+ return $date->toString(Zend_Date::DATETIME);
78
+ }
79
+ return 'First Time Run';
80
+ }
81
+
82
+ /**
83
+ * get column width
84
+ *
85
+ * @return string
86
+ */
87
+ public function getColumnWidth()
88
+ {
89
+ return "620px";
90
+ }
91
+
92
+
93
+ /**
94
+ * Get doc desription for the Apiconnector reflection class.
95
+ * reutrn the comment for each method.
96
+ * @param $method
97
+ *
98
+ * @return string
99
+ */
100
+ public function getDocDocument($method)
101
+ {
102
+ //reflection class for client
103
+ $rc = new ReflectionClass('Dotdigitalgroup_Email_Model_Apiconnector_Client');
104
+
105
+ //method data
106
+ $meth = $rc->getMethod( $method );
107
+ //grab the doc block for the method
108
+ $docCommment = $meth->getDocComment();
109
+
110
+ //select only the first text
111
+ preg_match( '/([A-Z])+.*\./', $docCommment, $matches );
112
+
113
+ if ( isset( $matches[0] ) ) {
114
+ //return only selected text
115
+ return $matches[0];
116
+ }
117
+ //return all doc block
118
+ return $docCommment;
119
+ }
120
+ }
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('ddg')->getApiUsername($website);
32
+ $apiPassword = Mage::helper('ddg')->getApiPassword($website);
33
+ $data = Mage::getModel('ddg_automation/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('ddg_automation/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,1773 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ const FAST_FIX_MESSAGE = 'Fast Fix Available, Click To Enable The Mapping And Redirect Back.';
11
+
12
+ private $_checkpoints = array(
13
+ 'extention_installed' => 'Extension And CURL Installed',
14
+ 'cron_running' => 'Cron running',
15
+ 'conflict_check' => 'Conflict Check',
16
+ 'address_book_mapped' => 'Address Book Mapping',
17
+ 'file_permission_setttings' => 'File Permission Settings',
18
+ 'missing_files' => 'Missing Files',
19
+ 'contact_sync_enabled' => 'Contact Sync Enabled',
20
+ 'contact_syncing' => 'Contacts Syncing',
21
+ 'subscriber_sync_enabled' => 'Subscribers Sync Enabled',
22
+ 'subscribers_syncing' => 'Subscribers Syncing',
23
+ 'automation_active' => 'Automation Programs Active',
24
+ 'abandoned_carts_enabled' => 'Abandoned Carts Enabled',
25
+ 'data_field_mapped' => 'Data Field Mapped',
26
+ 'valid_api_credentials' => 'API Credentials',
27
+ 'order_enabled' => 'Order Sync Enabled',
28
+ 'custom_order_attributes' => 'Custom Order Attributes',
29
+ 'order_syncing' => 'Orders Syncing',
30
+ 'quote_enabled' => 'Quote Sync Enabled',
31
+ 'custom_quote_attributes' => 'Custom Quote Attributes',
32
+ 'quote_syncing' => 'Quote Syncing',
33
+ 'last_abandoned_cart_sent_day' => 'Last Abandoned Cart Sent Day',
34
+ 'easy_email_capture_enabled' => 'Easy Email Capture Enabled',
35
+ 'disable_newsletter_success_enabled' => 'Disable Newsletter Success Enabled',
36
+ 'system_information' => 'System Information'
37
+
38
+ );
39
+ /**
40
+ * Set the template.
41
+ */
42
+ public function __construct()
43
+ {
44
+ parent::_construct();
45
+
46
+ $this->setTemplate('connector/dashboard/status.phtml');
47
+ }
48
+
49
+ /**
50
+ * Prepare the layout.
51
+ *
52
+ * @return Mage_Core_Block_Abstract|void
53
+ * @throws Exception
54
+ */
55
+ protected function _prepareLayout()
56
+ {
57
+ }
58
+
59
+ public function canShowTab()
60
+ {
61
+ return true;
62
+ }
63
+ public function isHidden()
64
+ {
65
+ return true;
66
+ }
67
+
68
+ public function getTabLabel()
69
+ {
70
+ return Mage::helper('ddg')->__('Marketing Automation System Status');
71
+ }
72
+
73
+ public function getTabTitle()
74
+ {
75
+ return Mage::helper('ddg')->__('Marketing Automation System Status');
76
+ }
77
+
78
+ /**
79
+ * Collapse key for the fieldset state.
80
+ * @param $key
81
+ *
82
+ * @return bool
83
+ */
84
+ protected function _getCollapseState($key)
85
+ {
86
+ $extra = Mage::getSingleton('admin/session')->getUser()->getExtra();
87
+ if (isset($extra['configState'][$key])) {
88
+ return $extra['configState'][$key];
89
+ }
90
+
91
+ return false;
92
+ }
93
+
94
+ public function getCheckpoints() {
95
+ return $this->_checkpoints;
96
+ }
97
+
98
+
99
+ public function addCheckpoint($checkpoint)
100
+ {
101
+ $this->_checkpoints[$checkpoint->getName()] = $checkpoint;
102
+ }
103
+
104
+ /**
105
+ * Extension modules and curl check.
106
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
107
+ */
108
+ public function extentionInstalled()
109
+ {
110
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
111
+
112
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
113
+ ->setTitle('Extension Status : ')
114
+ ->setMessage('Extension active and PHP Curl extension installed.');
115
+
116
+ $installed = (bool)Mage::getConfig()->getModuleConfig('Dotdigitalgroup_Email')->is('active', 'true');
117
+
118
+ if (! $installed || ! function_exists('curl_version')) {
119
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED );
120
+ $resultContent->setMessage('Sync May Not Work Properly.');
121
+ $resultContent->setHowto((! function_exists('curl_version'))? 'PHP Curl extention not found !' : 'PHP and Curl extension installed');
122
+ }
123
+ return $resultContent;
124
+ }
125
+
126
+ /**
127
+ * Check cron for the customer sync.
128
+ * @return array
129
+ */
130
+ public function cronRunning()
131
+ {
132
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
133
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
134
+ ->setTitle('Cron Status : ')
135
+ ->setMessage('Cron is running.');
136
+ $message = 'No cronjob task found. Check if cron is configured correctly.';
137
+ $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>';
138
+ $lastCustomerSync = Mage::getModel('ddg_automation/cron')->getLastCustomerSync();
139
+
140
+ if ($lastCustomerSync === false) {
141
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
142
+ ->setHowto($howToSetupCron);
143
+ } else {
144
+ $timespan = Mage::helper('ddg')->dateDiff($lastCustomerSync);
145
+ //last cron was less then 5min
146
+ if ($timespan <= 5 * 60) {
147
+ $resultContent->setTitle('Cronjob is working : ');
148
+ $message = sprintf('(Last execution: %s minute(s) ago) ', round($timespan/60));
149
+ } elseif ($timespan > 5 * 60 && $timespan <= 60 * 60 ) {
150
+ //last cron execution was between 15min and 60min
151
+ $resultContent->setTitle('Last customer sync : ' )
152
+ ->setStyle(self::CONNECTOR_DASHBOARD_FAILED);
153
+ $message = sprintf(' %s minutes. ', round($timespan/60));
154
+ } else {
155
+ //last cron was more then an hour
156
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
157
+ ->setHowto('Last customer sync is older than one hour.')
158
+ ->setHowto($howToSetupCron);
159
+ }
160
+ }
161
+
162
+ $resultContent->setMessage($message);
163
+ return $resultContent;
164
+ }
165
+
166
+ /**
167
+ * Address Book Mapping.
168
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
169
+ */
170
+ public function addressBookMapped()
171
+ {
172
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
173
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
174
+ ->setTitle('Configuration For Address Book Status : ')
175
+ ->setMessage('Looks Great.');
176
+
177
+ foreach (Mage::app()->getWebsites() as $website ) {
178
+
179
+ $websiteName = $website->getName();
180
+ $link = Mage::helper('adminhtml')->getUrl('*/system_config/edit/section/connector_sync_settings/website/' . $website->getCode());
181
+
182
+ $customerMapped = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMERS_ADDRESS_BOOK_ID))? true :
183
+ 'Not mapped!';
184
+ $subscriberMapped = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SUBSCRIBERS_ADDRESS_BOOK_ID))? true :
185
+ 'Not mapped!';
186
+ $guestMapped = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_GUEST_ADDRESS_BOOK_ID))? true :
187
+ 'Not mapped!';
188
+
189
+ if ($customerMapped !== true || $subscriberMapped !== true || $guestMapped !== true) {
190
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
191
+ ->setMessage('')
192
+ ->setTable(array(
193
+ 'Website' => $websiteName,
194
+ 'Customers' => ($customerMapped !== true)? $customerMapped . ' <a href="' . $link . '">configuration</a>' : 'Mapped.',
195
+ 'Subscribers' => ($subscriberMapped !== true)? $subscriberMapped . ' <a href="' . $link . '">configuration</a>' : 'Mapped.',
196
+ 'Guests' => ($guestMapped !== true)? $guestMapped . ' <a href="' . $link . '">configuration</a>' : 'Mapped.'
197
+ ));
198
+ }
199
+ }
200
+
201
+ return $resultContent;
202
+ }
203
+
204
+ /**
205
+ * ROI Tracking.
206
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
207
+ */
208
+ public function roiTrackingEnabled()
209
+ {
210
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
211
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
212
+ ->setTitle('ROI Tracking Status : ')
213
+ ->setMessage('Looks Great.');
214
+
215
+ $valid = true;
216
+ foreach ( Mage::app()->getWebsites() as $website ) {
217
+ $websiteName = $website->getName();
218
+
219
+ $roiConfig = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_ROI_TRACKING_ENABLED))? true : 'Not Mapped! ';
220
+ $pageTracking = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_PAGE_TRACKING_ENABLED))? true : 'Not Mapped! ';
221
+ //not mapped show options
222
+ if ($roiConfig !== true || $pageTracking !== true) {
223
+
224
+ //links to enable and get redirected back
225
+ $roiUrl = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_ROI_TRACKING_ENABLED', 'website' => $website->getId()));
226
+ $pageUrl = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_PAGE_TRACKING_ENABLED', 'website' => $website->getId()));
227
+
228
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
229
+ ->setMessage('')
230
+ ->setTable(array(
231
+ 'Website' => $websiteName,
232
+ 'ROI' => ($roiConfig !== true)? $roiConfig . ' <a href="' . $roiUrl . '">enable</a>' : 'Mapped.',
233
+ 'PAGE' => ($pageTracking !== true)? $pageTracking . ' <a href="' . $pageUrl . '">enable</a>' : 'Mapped.'
234
+ ));
235
+ $valid = false;
236
+ }
237
+ }
238
+ //validation failed
239
+ if (! $valid) {
240
+ $resultContent->setHowto(self::FAST_FIX_MESSAGE);
241
+ }
242
+
243
+ return $resultContent;
244
+ }
245
+
246
+ /**
247
+ * File Permissions.
248
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
249
+ */
250
+ public function filePermissionSetttings()
251
+ {
252
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
253
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
254
+ ->setTitle('Files/Folders Permission Settings : ')
255
+ ->setMessage('Looks Great.');
256
+
257
+ /**
258
+ * Arhive and email export directories.
259
+ */
260
+ $emailDir = Mage::getBaseDir('var') . DIRECTORY_SEPARATOR . 'export' . DIRECTORY_SEPARATOR . 'email';
261
+ $archiveDir = Mage::getBaseDir('var') . DIRECTORY_SEPARATOR . 'export' . DIRECTORY_SEPARATOR . 'email' . DIRECTORY_SEPARATOR . 'archive';
262
+
263
+ $checkEmail = Mage::helper('ddg/file')->getPathPermission($emailDir);
264
+ $checkArchive = Mage::helper('ddg/file')->getPathPermission($archiveDir);
265
+
266
+ //file persmission failed
267
+ if ($checkEmail != 755 && $checkEmail != 777 || $checkArchive != 755 && $checkArchive != 777) {
268
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
269
+ ->setMessage('Wrong Permission For Directory : 777 or 755');
270
+
271
+ //list of directory permission checked
272
+ if ($checkEmail != 755 || $checkEmail != 777)
273
+ $resultContent->setHowto( $emailDir . ' is set to : ' . $checkEmail);
274
+ if ($checkArchive != 755 || $checkArchive != 777)
275
+ $resultContent->setHowto( $archiveDir . ' is set to : ' . $checkArchive);
276
+ }
277
+
278
+ return $resultContent;
279
+ }
280
+
281
+ /**
282
+ * Check for missing files.
283
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
284
+ */
285
+ public function missingFiles()
286
+ {
287
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
288
+
289
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
290
+ ->setTitle('Missing Files : ')
291
+ ->setMessage('Looks Great.');
292
+
293
+ $filePath = Mage::getModuleDir('etc', Dotdigitalgroup_Email_Helper_Config::MODULE_NAME).DS.'files.yaml';
294
+ $config = Zend_Config_Yaml::decode(file_get_contents($filePath));
295
+
296
+ /**
297
+ * Code dirs.
298
+ */
299
+ $etcDir = Mage::getModuleDir('etc', Dotdigitalgroup_Email_Helper_Config::MODULE_NAME);
300
+ $controllerDir = Mage::getModuleDir('controllers', Dotdigitalgroup_Email_Helper_Config::MODULE_NAME);
301
+ $sqlDir = Mage::getModuleDir('sql', Dotdigitalgroup_Email_Helper_Config::MODULE_NAME);
302
+ $localeDir = Mage::getBaseDir('locale');
303
+ $rootDir = Mage::getModuleDir('', Dotdigitalgroup_Email_Helper_Config::MODULE_NAME);
304
+ $blockDir = $rootDir .DS. 'Block';
305
+ $helperDir = $rootDir .DS. 'Helper';
306
+ $modelDir = $rootDir .DS. 'Model';
307
+
308
+ /**
309
+ * Design dir.
310
+ */
311
+ $designDir = Mage::getBaseDir('design');
312
+
313
+ /**
314
+ * Skin dir.
315
+ */
316
+ $skinDir = Mage::getBaseDir('skin');
317
+
318
+ /**
319
+ * Js dir
320
+ */
321
+ $jsDir = Mage::getBaseDir('base') . DS . 'js';
322
+
323
+ /**
324
+ * lib dir
325
+ */
326
+ $libDir = Mage::getBaseDir('lib');
327
+
328
+ $filesToCheck = array($config['etc'], $config['controllers'], $config['sql'], $config['locale'], $config['block'],
329
+ $config['helper'], $config['model'], $config['design'], $config['skin'], $config['lib'], $config['js']);
330
+ $pathToCheck = array($etcDir, $controllerDir, $sqlDir, $localeDir, $blockDir, $helperDir,
331
+ $modelDir, $designDir, $skinDir, $libDir, $jsDir);
332
+ foreach ( $filesToCheck as $subdir ) {
333
+ foreach ( $subdir as $path ) {
334
+ $file = $pathToCheck[0] . DS . str_replace( '#', DS, $path );
335
+
336
+ if ( !file_exists( $file ) ) {
337
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED )
338
+ ->setMessage('')
339
+ ->setHowto('File not found : ' . $file );
340
+ }
341
+ }
342
+ array_shift($pathToCheck);
343
+ }
344
+
345
+ return $resultContent;
346
+ }
347
+
348
+ /**
349
+ * Contact Sync Status.
350
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
351
+ */
352
+ public function contactSyncEnabled()
353
+ {
354
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
355
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
356
+ ->setTitle('Contacts Sync Status : ')
357
+ ->setMessage('Looks Great.');
358
+
359
+ $valid = true;
360
+ foreach ( Mage::app()->getWebsites() as $website ) {
361
+ $websiteName = $website->getName();
362
+ $contact = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_CONTACT_ENABLED))? true : 'Disabled!';
363
+ //disabled show data table
364
+ if ($contact !== true){
365
+ //redirection url to enable website config
366
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_SYNC_CONTACT_ENABLED', 'website' => $website->getId()));
367
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
368
+ ->setMessage('')
369
+ ->setTable(array(
370
+ 'Website' => $websiteName,
371
+ 'Status' => ($contact)? $contact . ' <a href="' . $url . '">enable</a>' : 'Enabled.'
372
+ ))
373
+ ;
374
+ $valid = false;
375
+ }
376
+ }
377
+ //validation failed
378
+ if (! $valid) {
379
+ $resultContent->setHowto(self::FAST_FIX_MESSAGE);
380
+ }
381
+
382
+ return $resultContent;
383
+ }
384
+
385
+ /**
386
+ * Check if contact is syncing by counting the number of contacts imported.
387
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
388
+ */
389
+ public function contactSyncing()
390
+ {
391
+ //content to render
392
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
393
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
394
+ ->setTitle('Contacts Sync : ')
395
+ ->setMessage('Looks Great.');
396
+ $contactModel = Mage::getModel('ddg_automation/contact');
397
+
398
+ //global email duplicates
399
+ if (Mage::getResourceModel('customer/customer')->findEmailDuplicates()) {
400
+
401
+ //duplicate email customers
402
+ $customers = Mage::helper('ddg')->getCustomersWithDuplicateEmails();
403
+ $customerEmails = implode(', ', $customers->getColumnValues('email'));
404
+ //render the email duplicates
405
+ $resultContent->setHowto('Found Duplicate Customers Emails :')
406
+ ->setHowto($customerEmails);
407
+ }
408
+
409
+ foreach ( Mage::app()->getWebsites() as $website ) {
410
+
411
+ $websiteId = $website->getId();
412
+ //total customers for website
413
+ $countCustomers = Mage::getModel('customer/customer')->getCollection()
414
+ ->addAttributeToFilter('website_id', $websiteId)
415
+ ->getSize();
416
+
417
+ //skip if no customers
418
+ if (! $countCustomers)
419
+ continue;
420
+
421
+ //total contacts from customer address book
422
+ $customerAddressBook = $this->_getAddressBookContacts($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMERS_ADDRESS_BOOK_ID), $website);
423
+ $countAddressbookContacts = ($customerAddressBook)? $customerAddressBook->contacts : 0;
424
+ //total contacts as customers
425
+ $countCustomerContacts = $contactModel->getNumberCustomerContacts($websiteId);
426
+
427
+ //suppressed contacts
428
+ $suppressed = $contactModel->getNumberCustomerSuppressed($websiteId);
429
+
430
+ //table data
431
+ $tableData = array(
432
+ 'Website' => $website->getName(),
433
+ 'Total Customers/Contacts' => $countCustomers . '/ ' . $countCustomerContacts,
434
+ 'Customer AddressBook Contacts' => ($customerAddressBook)? $customerAddressBook->name . ' : ' . $countAddressbookContacts : 'Not Mapped.',
435
+ 'Suppressed' => $suppressed,
436
+ 'Synced' => $contactModel->getNumberCustomerSynced($websiteId)
437
+ );
438
+
439
+ //number of customers not match, try to update
440
+ if ($countCustomers != $countCustomerContacts) {
441
+
442
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/populatecontacts', array('type' => 'customers', 'website' => $website->getId()));
443
+ $link = ' <a href="' . $url . '"> populate</a>';
444
+ $tableData['Status'] = 'Customers not matching the contact table. ' . $link;
445
+ //customers not synced yet
446
+ } elseif ($countCustomers > $countCustomerContacts + $suppressed){
447
+ $tableData['Status'] = 'Syncing..';
448
+ //all customers syned.
449
+ } else {
450
+ $tableData['Status'] = 'Synced';
451
+ }
452
+
453
+ //not valid response remove status
454
+ if (!$countAddressbookContacts)
455
+ unset($tableData['Status']);
456
+
457
+ //no contacts
458
+ if (! $countCustomers) {
459
+
460
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
461
+ ->setTitle('Contacts Sync (ignore if you have reset contacts for reimport) : ')
462
+ ->setMessage('');
463
+ $tableData['Status'] = 'No Imported Contacts Found!';
464
+ unset($tableData['Imported Contacts']);
465
+ }
466
+
467
+ $resultContent->setTable($tableData);
468
+ }
469
+
470
+ return $resultContent;
471
+ }
472
+
473
+ /**
474
+ * Check for subscribers sync status.
475
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
476
+ */
477
+ public function subscriberSyncEnabled()
478
+ {
479
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
480
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
481
+ ->setTitle('Subscribers Sync Status : ')
482
+ ->setMessage('Looks Great.');
483
+
484
+ $passed = true;
485
+ foreach ( Mage::app()->getWebsites() as $website ) {
486
+ $websiteName = $website->getName();
487
+ $contact = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_SUBSCRIBER_ENABLED))? true :
488
+ 'Disabled!';
489
+ //disabled show data table
490
+ if ($contact !== true){
491
+ //redirection url to enable website config
492
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_SYNC_SUBSCRIBER_ENABLED', 'website' => $website->getId()));
493
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
494
+ ->setMessage('')
495
+ ->setTable(array(
496
+ 'Website' => $websiteName,
497
+ 'Status' => ($contact)? $contact . ' <a href="' . $url . '">enable</a>' : 'Enabled.'
498
+ ));
499
+ $passed = false;
500
+ }
501
+ }
502
+ //if validation not passed
503
+ if (! $passed)
504
+ $resultContent->setHowto(self::FAST_FIX_MESSAGE);
505
+
506
+ return $resultContent;
507
+ }
508
+
509
+ /**
510
+ * Subscribers syncing status.
511
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
512
+ */
513
+ public function subscribersSyncing()
514
+ {
515
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
516
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
517
+ ->setTitle('Subscribers Sync : ')
518
+ ->setMessage('Looks Great.');
519
+ $contactModel = Mage::getModel('ddg_automation/contact');
520
+
521
+ foreach ( Mage::app()->getWebsites() as $website ) {
522
+ $websiteId = $website->getId();
523
+ $websiteName = $website->getName();
524
+ $storeIds = $website->getStoreIds();
525
+ //total subscribers
526
+ $countSubscribers = Mage::getModel('newsletter/subscriber')->getCollection()
527
+ ->useOnlySubscribed()
528
+ ->addStoreFilter($storeIds)
529
+ ->getSize();
530
+ //skip if no subscriber
531
+ if (! $countSubscribers)
532
+ continue;
533
+
534
+ //total contacts subscribed
535
+ $countSubscribedContacts = $contactModel->getNumberSubscribers($websiteId);
536
+ //total contacts subscribed imported
537
+ $countSubscribersImported = $contactModel->getNumberSubscribersSynced($websiteId);
538
+
539
+ //number of address
540
+ $countAddressbookContacts = $this->_getAddressBookContacts($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SUBSCRIBERS_ADDRESS_BOOK_ID), $website);
541
+
542
+ $tableData = array(
543
+ 'Website' => $websiteName,
544
+ 'Total Subscribers/Contacts' => $countSubscribers . '/ ' . $countSubscribedContacts,
545
+ 'Subscriber AddressBook Contacts' => ($countAddressbookContacts)? $countAddressbookContacts->name . ' : ' . $countAddressbookContacts->contacts : 'Not Mapped.',
546
+ 'Imported' => $countSubscribersImported
547
+ );
548
+
549
+ $tableData['Status'] = '';
550
+
551
+ //no imported contacts
552
+ if (! $countSubscribersImported) {
553
+
554
+ $tableData['Status'] = 'No Imported Subscribers Found.';
555
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
556
+ ->setTitle('Subscriber Sync (ignore if you have reset subscribers for reimport) : ')
557
+ ->setMessage('');
558
+ }
559
+ $resultContent->setTable($tableData);
560
+ }
561
+
562
+ return $resultContent;
563
+ }
564
+ //check the mapped programs are active
565
+ public function automationActive()
566
+ {
567
+ $disableCustomer = $disableSubscriber = $disableOrder = $disableGuestOrder = $disableReviews = $disableWishlist = '';
568
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
569
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
570
+ ->setTitle('Automation Program Status :')
571
+ ->setMessage('');
572
+
573
+ foreach ( Mage::app()->getWebsites() as $website ) {
574
+ $customerProgram = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_AUTOMATION_STUDIO_CUSTOMER);
575
+ $subscriberProgram = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_AUTOMATION_STUDIO_SUBSCRIBER);
576
+ $orderProgram = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_AUTOMATION_STUDIO_ORDER);
577
+ $guestOrderProgram = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_AUTOMATION_STUDIO_GUEST_ORDER);
578
+ $reviewsProgram = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_AUTOMATION_STUDIO_REVIEW);
579
+ $wishlistProgram = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_AUTOMATION_STUDIO_WISHLIST);
580
+
581
+ //programs
582
+ $cusProgram = $this->_getWebisteProgram($customerProgram, $website);
583
+ $subProgram = $this->_getWebisteProgram($subscriberProgram, $website);
584
+ $orderProgram = $this->_getWebisteProgram($orderProgram, $website);
585
+ $guestOrderProgram = $this->_getWebisteProgram($guestOrderProgram, $website);
586
+ $reviewsProgram = $this->_getWebisteProgram($reviewsProgram, $website);
587
+ $wishlistProgram = $this->_getWebisteProgram($wishlistProgram, $website);
588
+
589
+ //check for wishlist program
590
+ if ($wishlistProgram) {
591
+
592
+ if ($wishlistProgram->status != 'Active') {
593
+
594
+ //set the status as failed
595
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
596
+ ->setMessage(' Consider to disable not active programs');
597
+
598
+ $disableWishlist = Mage::helper( 'adminhtml' )->getUrl( '*/connector/enablewebsiteconfiguration', array(
599
+ 'path' => 'XML_PATH_CONNECTOR_AUTOMATION_STUDIO_WISHLIST',
600
+ 'value' => '0',
601
+ 'website' => $website->getId()
602
+ )
603
+ );
604
+ $disableWishlist = 'Deactivated! <a href="' . $disableWishlist . '">click</a> to disable';
605
+
606
+ } else {
607
+
608
+ $disableWishlist = $wishlistProgram->status;
609
+ }
610
+ }
611
+
612
+ //check for order program
613
+ if ($orderProgram) {
614
+
615
+ if ($orderProgram->status != 'Active') {
616
+
617
+ //set the status as failed
618
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
619
+ ->setMessage(' Consider to disable not active programs');
620
+
621
+ $disableOrder = Mage::helper( 'adminhtml' )->getUrl( '*/connector/enablewebsiteconfiguration', array(
622
+ 'path' => 'XML_PATH_CONNECTOR_AUTOMATION_STUDIO_ORDER',
623
+ 'value' => '0',
624
+ 'website' => $website->getId()
625
+ )
626
+ );
627
+ $disableOrder = 'Deactivated! <a href="' . $disableOrder . '">click</a> to disable';
628
+
629
+ } else {
630
+
631
+ $disableOrder = $orderProgram->status;
632
+ }
633
+ }
634
+
635
+ //check for review program
636
+ if ($reviewsProgram) {
637
+
638
+ if ($reviewsProgram->status != 'Active') {
639
+
640
+ //set the status as failed
641
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
642
+ ->setMessage(' Consider to disable not active programs');
643
+
644
+ $disableReviews = Mage::helper( 'adminhtml' )->getUrl( '*/connector/enablewebsiteconfiguration', array(
645
+ 'path' => 'XML_PATH_CONNECTOR_AUTOMATION_STUDIO_REVIEW',
646
+ 'value' => '0',
647
+ 'website' => $website->getId()
648
+ )
649
+ );
650
+ $disableReviews = 'Deactivated! <a href="' . $disableReviews . '">click</a> to disable';
651
+
652
+ } else {
653
+
654
+ $disableReviews = $reviewsProgram->status;
655
+ }
656
+ }
657
+
658
+ //check for guest order program
659
+ if ($guestOrderProgram) {
660
+
661
+ if ($guestOrderProgram->status != 'Active') {
662
+
663
+ //set the status as failed
664
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
665
+ ->setMessage(' Consider to disable not active programs');
666
+
667
+ $disableGuestOrder = Mage::helper( 'adminhtml' )->getUrl( '*/connector/enablewebsiteconfiguration', array(
668
+ 'path' => 'XML_PATH_CONNECTOR_AUTOMATION_STUDIO_GUEST_ORDER',
669
+ 'value' => '0',
670
+ 'website' => $website->getId()
671
+ )
672
+ );
673
+ $disableGuestOrder = 'Deactivated! <a href="' . $disableGuestOrder . '">click</a> to disable';
674
+
675
+ } else {
676
+
677
+ $disableGuestOrder = $guestOrderProgram->status;
678
+ }
679
+ }
680
+
681
+ //check for customer program
682
+ if ($cusProgram) {
683
+
684
+ if ($cusProgram->status != 'Active') {
685
+
686
+ //set the status as failed
687
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
688
+ ->setMessage(' Consider to disable not active programs');
689
+
690
+ $disableCustomer = Mage::helper( 'adminhtml' )->getUrl( '*/connector/enablewebsiteconfiguration', array(
691
+ 'path' => 'XML_PATH_CONNECTOR_AUTOMATION_STUDIO_CUSTOMER',
692
+ 'value' => '0',
693
+ 'website' => $website->getId()
694
+ )
695
+ );
696
+ $disableCustomer = 'Deactivated! <a href="' . $disableCustomer . '">click</a> to disable';
697
+
698
+ } else {
699
+
700
+ $disableCustomer = $cusProgram->status;
701
+ }
702
+ }
703
+
704
+ //check for subscriber program
705
+ if ($subProgram) {
706
+
707
+ if ($subProgram->status != 'Active') {
708
+ // set the status failed
709
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
710
+ ->setMessage(' Consider to disable not active programs');
711
+
712
+ //link to disbale config
713
+ $disableSubscriber = Mage::helper( 'adminhtml' )->getUrl( '*/connector/enablewebsiteconfiguration', array(
714
+ 'path' => 'XML_PATH_CONNECTOR_AUTOMATION_STUDIO_SUBSCRIBER',
715
+ 'value' => '0',
716
+ 'website' => $website->getId()
717
+ )
718
+ );
719
+ $disableSubscriber = 'Deactivated <a href="' . $disableSubscriber . '">click</a> to disable';
720
+
721
+ } else {
722
+ $disableSubscriber = $subProgram->status;
723
+ }
724
+ }
725
+
726
+ $tableData = array(
727
+ 'Website' => $website->getName(),
728
+ 'Customer Program' => (isset($cusProgram->name))? $cusProgram->name : 'Disabled',
729
+ 'Customer Status' => (isset($cusProgram->status))? $disableCustomer : '',
730
+ 'Subscriber Program' => (isset($subProgram->name))? $subProgram->name : 'Disabled',
731
+ 'Subscriber Status' => (isset($subProgram->status))? $disableSubscriber : '',
732
+ 'Order Program' => (isset($orderProgram->name))? $orderProgram->name : 'Disabled',
733
+ 'Order Status' => (isset($orderProgram->status))? $disableOrder : '',
734
+ 'Guest Order Program' => (isset($guestOrderProgram->name))? $guestOrderProgram->name : 'Disabled',
735
+ 'Guest Order Status' => (isset($guestOrderProgram->status))? $disableGuestOrder : '',
736
+ 'Review Program' => (isset($reviewsProgram->name))? $reviewsProgram->name : 'Disabled',
737
+ 'Review Status' => (isset($reviewsProgram->status))? $disableReviews : '',
738
+ 'Wishlist Program' => (isset($wishlistProgram->name))? $wishlistProgram->name : 'Disabled',
739
+ 'Wishlist Status' => (isset($wishlistProgram->status))? $disableWishlist : '',
740
+ );
741
+
742
+ //set the content with table data
743
+ $resultContent->setTable($tableData);
744
+
745
+ }
746
+
747
+ return $resultContent;
748
+ }
749
+
750
+ /**
751
+ * Abandoned carts status.
752
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
753
+ */
754
+ public function abandonedCartsEnabled()
755
+ {
756
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
757
+
758
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
759
+ ->setTitle('Abandoned Carts Status : ')
760
+ ->setMessage('Looks Great.');
761
+
762
+ foreach ( Mage::app()->getWebsites() as $website ) {
763
+ $websiteName = $website->getName();
764
+ $abandonedCusomer_1 = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CARTS_ENABLED_1))? true :
765
+ 'Disabled!';
766
+ $abandonedCusomer_2 = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CARTS_ENABLED_2))? true :
767
+ 'Disabled!';
768
+ $abandonedCusomer_3 = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CARTS_ENABLED_3))? true :
769
+ 'Disabled!';
770
+ $abandonedGuest_1 = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_GUEST_ABANDONED_CARTS_ENABLED_1))? true :
771
+ 'Disabled!';
772
+ $abandonedGuest_2 = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_GUEST_ABANDONED_CARTS_ENABLED_2))? true :
773
+ 'Disabled!';
774
+ $abandonedGuest_3 = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_GUEST_ABANDONED_CARTS_ENABLED_3))? true :
775
+ 'Disabled!';
776
+
777
+ if ($abandonedCusomer_1 !== true || $abandonedCusomer_2 !== true || $abandonedCusomer_3 !== true || $abandonedGuest_1 !== true || $abandonedGuest_2 !== true || $abandonedGuest_3 !== true){
778
+ //customer abandoned links to enable
779
+ $customer1 = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CARTS_ENABLED_1', 'website' => $website->getId()));
780
+ $customer2 = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CARTS_ENABLED_2', 'website' => $website->getId()));
781
+ $customer3 = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CARTS_ENABLED_3', 'website' => $website->getId()));
782
+ //guests abandoned links to enable
783
+ $guest1 = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_GUEST_ABANDONED_CARTS_ENABLED_1', 'website' => $website->getId()));
784
+ $guest2 = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_GUEST_ABANDONED_CARTS_ENABLED_2', 'website' => $website->getId()));
785
+ $guest3 = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_GUEST_ABANDONED_CARTS_ENABLED_3', 'website' => $website->getId()));
786
+
787
+
788
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
789
+ ->setMessage('Don\'t forget to map')
790
+ ->setTable(array(
791
+ 'Website' => $websiteName,
792
+ 'Customer Abandoned 1' => ($abandonedCusomer_1 !== true)? $abandonedCusomer_1 . ' <a href="' . $customer1 . '">enable</a>' : 'Enabled',
793
+ 'Customer Abandoned 2' => ($abandonedCusomer_2 !== true)? $abandonedCusomer_2 . ' <a href="' . $customer2 . '">enable</a>' : 'Enabled',
794
+ 'Customer Abandoned 3' => ($abandonedCusomer_3 !== true)? $abandonedCusomer_3 . ' <a href="' . $customer3 . '">enable</a>' : 'Enabled',
795
+ 'Guest Abandoned 1' => ($abandonedGuest_1 !== true)? $abandonedGuest_1 . ' <a href="' . $guest1 . '">enable</a>' : 'Enabled',
796
+ 'Guest Abandoned 2' => ($abandonedGuest_2 !== true)? $abandonedGuest_2 . ' <a href="' . $guest2 . '">enable</a>' : 'Enabled',
797
+ 'Guest Abandoned 3' => ($abandonedGuest_3 !== true)? $abandonedGuest_3 . ' <a href="' . $guest3 . '">enable</a>' : 'Enabled',
798
+ ));
799
+ }
800
+ }
801
+
802
+ return $resultContent;
803
+ }
804
+
805
+ /**
806
+ * Crazy mapping checking.
807
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
808
+ */
809
+ public function dataFieldMapped()
810
+ {
811
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
812
+
813
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
814
+ ->setTitle('Default Datafields Mapped Status : ')
815
+ ->setMessage('All Datafields Are Mapped.');
816
+
817
+ foreach ( Mage::app()->getWebsites() as $website ) {
818
+ $passed = true;
819
+ $mapped = 0;
820
+ $tableData = array();
821
+ //website name for table data
822
+ $websiteName = $website->getName();
823
+ $tableData['Website'] = $websiteName;
824
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_ID)) {
825
+ $passed = false;
826
+ $mapped++;
827
+ }
828
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_FIRSTNAME)) {
829
+ $passed = false;
830
+ $mapped++;
831
+ }
832
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_LASTNAME)) {
833
+ $passed = false;
834
+ $mapped++;
835
+ }
836
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_DOB)) {
837
+ $passed = false;
838
+ $mapped++;
839
+ }
840
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_GENDER)) {
841
+ $passed = false;
842
+ $mapped++;
843
+ }
844
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_WEBSITE_NAME)) {
845
+ $passed = false;
846
+ $mapped++;
847
+ }
848
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_STORE_NAME)) {
849
+ $passed = false;
850
+ $mapped++;
851
+ }
852
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_CREATED_AT)) {
853
+ $passed = false;
854
+ $mapped++;
855
+ }
856
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_LAST_LOGGED_DATE)) {
857
+ $passed = false;
858
+ $mapped++;
859
+ }
860
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_CUSTOMER_GROUP)) {
861
+ $passed = false;
862
+ $mapped++;
863
+ }
864
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_REVIEW_COUNT)) {
865
+ $passed = false;
866
+ $mapped++;
867
+ }
868
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_LAST_REVIEW_DATE)) {
869
+ $passed = false;
870
+ $mapped++;
871
+ }
872
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_BILLING_ADDRESS_1)) {
873
+ $passed = false;
874
+ $mapped++;
875
+ }
876
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_BILLING_ADDRESS_2)) {
877
+ $passed = false;
878
+ $mapped++;
879
+ }
880
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_BILLING_CITY)) {
881
+ $passed = false;
882
+ $mapped++;
883
+ }
884
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_BILLING_STATE)) {
885
+ $passed = false;
886
+ $mapped++;
887
+ }
888
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_BILLING_COUNTRY)) {
889
+ $passed = false;
890
+ $mapped++;
891
+ }
892
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_BILLING_POSTCODE)) {
893
+ $passed = false;
894
+ $mapped++;
895
+ }
896
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_BILLING_TELEPHONE)) {
897
+ $passed = false;
898
+ $mapped++;
899
+ }
900
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_ADDRESS_1)) {
901
+ $passed = false;
902
+ $mapped++;
903
+ }
904
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_ADDRESS_2)) {
905
+ $passed = false;
906
+ $mapped++;
907
+ }
908
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_CITY)) {
909
+ $passed = false;
910
+ $mapped++;
911
+ }
912
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_STATE)) {
913
+ $passed = false;
914
+ $mapped++;
915
+ }
916
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_COUNTRY)) {
917
+ $passed = false;
918
+ $mapped++;
919
+ }
920
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_POSTCODE)) {
921
+ $passed = false;
922
+ $mapped++;
923
+ }
924
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_TELEPHONE)) {
925
+ $passed = false;
926
+ $mapped++;
927
+ }
928
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_TOTAL_NUMBER_ORDER)) {
929
+ $passed = false;
930
+ $mapped++;
931
+ }
932
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_AOV)) {
933
+ $passed = false;
934
+ $mapped++;
935
+ }
936
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_TOTAL_SPEND)) {
937
+ $passed = false;
938
+ $mapped++;
939
+ }
940
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_LAST_ORDER_DATE)) {
941
+ $passed = false;
942
+ $mapped++;
943
+ }
944
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_LAST_ORDER_ID)) {
945
+ $passed = false;
946
+ $mapped++;
947
+ }
948
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_CUSTOMER_TOTALREFUND)) {
949
+ $passed = false;
950
+ $mapped++;
951
+ }
952
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_SUBSCRIBER_STATUS)) {
953
+ $passed = false;
954
+ $mapped++;
955
+ }
956
+ $tableData['Mapped Percentage'] = number_format((1 - $mapped / 32) * 100, 2) . ' %';
957
+ //mapping not complete.
958
+ if (! $passed ){
959
+ $url = Mage::helper('adminhtml')->getUrl('*/system_config/edit/section/connector_data_mapping/website/' . $website->getCode());
960
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
961
+ ->setMessage('Click <a href="' . $url . '">here</a> to change mapping configuration.')
962
+ ;
963
+ }
964
+ $resultContent->setTable($tableData);
965
+ }
966
+
967
+ return $resultContent;
968
+ }
969
+
970
+
971
+ /**
972
+ * Validate API Credentials.
973
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
974
+ */
975
+ public function validApiCredentials()
976
+ {
977
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
978
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
979
+ ->setTitle('API Credentials Status : ')
980
+ ->setMessage('Valid.');
981
+ $helper = Mage::helper('ddg');
982
+ foreach ( Mage::app()->getWebsites() as $website ) {
983
+ $websiteName = $website->getName();
984
+ $websiteId = $website->getId();
985
+
986
+ $apiUsername = $helper->getApiUsername($websiteId);
987
+ $apiPassword = $helper->getApiPassword($websiteId);
988
+
989
+ $api = Mage::getModel('ddg_automation/apiconnector_test')->ajaxvalidate($apiUsername, $apiPassword);
990
+
991
+ if ($api != 'Credentials Valid.') {
992
+ $url = Mage::helper('adminhtml')->getUrl('*/system_config/edit/section/connector_api_credentials/website/' . $website->getCode());
993
+
994
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
995
+ ->setMessage('')
996
+ ->setTable(array(
997
+ 'Website' => $websiteName,
998
+ 'Status' => $api,
999
+ 'Fast Fix' => 'Click <a href="' . $url . '">here</a> to enter new api credentials.'
1000
+ ));
1001
+ }
1002
+ }
1003
+
1004
+ return $resultContent;
1005
+ }
1006
+
1007
+ /**
1008
+ * Order sync enabled.
1009
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1010
+ */
1011
+ public function orderEnabled()
1012
+ {
1013
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1014
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1015
+ ->setTitle('Order Sync : ')
1016
+ ->setMessage('Enabled.');
1017
+
1018
+ $passed = true;
1019
+ foreach ( Mage::app()->getWebsites() as $website ) {
1020
+ $websiteName = $website->getName();
1021
+ $order = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_ORDER_ENABLED))? true :
1022
+ 'Disabled!';
1023
+
1024
+ if ($order !== true){
1025
+
1026
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_SYNC_ORDER_ENABLED', 'website' => $website->getId()));
1027
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
1028
+ ->setMessage('')
1029
+ ->setTable(array(
1030
+ 'Website' => $websiteName,
1031
+ 'Status' => $order . ' <a href="' . $url . '">enable</a>'
1032
+ ));
1033
+ $passed = false;
1034
+ }
1035
+ }
1036
+ //validation failed
1037
+ if (! $passed) {
1038
+ $resultContent->setHowto(self::FAST_FIX_MESSAGE);
1039
+ }
1040
+
1041
+ return $resultContent;
1042
+ }
1043
+
1044
+ /**
1045
+ * check if any custom order attribute selected
1046
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1047
+ */
1048
+ public function customOrderAttributes()
1049
+ {
1050
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1051
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1052
+ ->setTitle('Custom Order Attributes : ')
1053
+ ->setMessage('Selected.');
1054
+
1055
+ foreach ( Mage::app()->getWebsites() as $website ) {
1056
+ $websiteName = $website->getName();
1057
+ $customOrderAttibute = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOM_ORDER_ATTRIBUTES))? true : false;
1058
+
1059
+ if ($customOrderAttibute !== true){
1060
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
1061
+ ->setTitle('Custom order attribute not selected (ignore if you do not want to import custom order attributes) :')
1062
+ ->setMessage('')
1063
+ ->setTable(array(
1064
+ 'Website' => $websiteName,
1065
+ 'Status' => 'No Custom Order Attribute Selected'
1066
+ ));
1067
+ }
1068
+ }
1069
+
1070
+ return $resultContent;
1071
+ }
1072
+
1073
+ /**
1074
+ * Check if any orders are imported.
1075
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1076
+ */
1077
+ public function orderSyncing()
1078
+ {
1079
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1080
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1081
+ ->setTitle('Order Syncing : ')
1082
+ ->setMessage('Looks Great.');
1083
+
1084
+ foreach ( Mage::app()->getWebsites() as $website ) {
1085
+ $websiteName = $website->getName();
1086
+ $storeIds = $website->getStoreIds();
1087
+
1088
+ //numbser of orders marked as imported
1089
+ $numOrders = Mage::getModel('ddg_automation/order')->getCollection()
1090
+ ->addFieldToFilter('email_imported', 1)
1091
+ ->addFieldToFilter('store_id', array('in', $storeIds))->getSize();
1092
+
1093
+ if (! $numOrders) {
1094
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
1095
+ ->setTitle('Order Syncing (ignore if you have reset orders for reimport) :')
1096
+ ->setMessage('')
1097
+ ->setTable(array(
1098
+ 'Website' => $websiteName,
1099
+ 'Status' => 'No Imported Orders Found'
1100
+ ));
1101
+ }
1102
+ }
1103
+
1104
+ return $resultContent;
1105
+
1106
+ }
1107
+
1108
+ /**
1109
+ * Quote sync enabled.
1110
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1111
+ */
1112
+ public function quoteEnabled()
1113
+ {
1114
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1115
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1116
+ ->setTitle('Quote Sync : ')
1117
+ ->setMessage('Enabled.');
1118
+
1119
+ $passed = true;
1120
+ foreach ( Mage::app()->getWebsites() as $website ) {
1121
+ $websiteName = $website->getName();
1122
+ $quote = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_QUOTE_ENABLED))? true :
1123
+ 'Disabled!';
1124
+
1125
+ if ($quote !== true){
1126
+
1127
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_SYNC_QUOTE_ENABLED', 'website' => $website->getId()));
1128
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
1129
+ ->setMessage('')
1130
+ ->setTable(array(
1131
+ 'Website' => $websiteName,
1132
+ 'Status' => $quote . ' <a href="' . $url . '">enable</a>'
1133
+ ));
1134
+ $passed = false;
1135
+ }
1136
+ }
1137
+ //validation failed
1138
+ if (! $passed) {
1139
+ $resultContent->setHowto(self::FAST_FIX_MESSAGE);
1140
+ }
1141
+
1142
+ return $resultContent;
1143
+ }
1144
+
1145
+ /**
1146
+ * check if any custom quote attribute selected
1147
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1148
+ */
1149
+ public function customQuoteAttributes()
1150
+ {
1151
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1152
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1153
+ ->setTitle('Custom Quote Attributes : ')
1154
+ ->setMessage('Selected.');
1155
+
1156
+ foreach ( Mage::app()->getWebsites() as $website ) {
1157
+ $websiteName = $website->getName();
1158
+ $customQuoteAttribute = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOM_QUOTE_ATTRIBUTES))? true : false;
1159
+
1160
+ if ($customQuoteAttribute !== true){
1161
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
1162
+ ->setTitle('Custom quote attribute not selected (ignore if you do not want to import custom quote attributes) :')
1163
+ ->setMessage('')
1164
+ ->setTable(array(
1165
+ 'Website' => $websiteName,
1166
+ 'Status' => 'No Custom Quote Attribute Selected'
1167
+ ));
1168
+ }
1169
+ }
1170
+
1171
+ return $resultContent;
1172
+ }
1173
+
1174
+ /**
1175
+ * Check if any quote are imported.
1176
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1177
+ */
1178
+ public function quoteSyncing()
1179
+ {
1180
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1181
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1182
+ ->setTitle('Quote Syncing : ')
1183
+ ->setMessage('Looks Great.');
1184
+
1185
+ foreach ( Mage::app()->getWebsites() as $website ) {
1186
+ $websiteName = $website->getName();
1187
+ $storeIds = $website->getStoreIds();
1188
+
1189
+ //number of quote marked as imported
1190
+ $numQuotes = Mage::getModel('ddg_automation/quote')->getCollection()
1191
+ ->addFieldToFilter('imported', 1)
1192
+ ->addFieldToFilter('store_id', array('in', $storeIds))->getSize();
1193
+
1194
+ if (! $numQuotes) {
1195
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
1196
+ ->setTitle('Quote Syncing (ignore if you have reset quote for re-import) :')
1197
+ ->setMessage('')
1198
+ ->setTable(array(
1199
+ 'Website' => $websiteName,
1200
+ 'Status' => 'No Imported Quotes Found'
1201
+ ));
1202
+ }
1203
+ }
1204
+
1205
+ return $resultContent;
1206
+
1207
+ }
1208
+
1209
+ /**
1210
+ * review sync enabled.
1211
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1212
+ * Display the transactional data for orders to be removed.
1213
+ */
1214
+ public function reviewEnabled()
1215
+ {
1216
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1217
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1218
+ ->setTitle('Review Sync : ')
1219
+ ->setMessage('Enabled.');
1220
+
1221
+ foreach ( Mage::app()->getWebsites() as $website ) {
1222
+ $websiteName = $website->getName();
1223
+ $review = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_REVIEW_ENABLED))? true :
1224
+ 'Disabled';
1225
+
1226
+ if ($review !== true){
1227
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_SYNC_REVIEW_ENABLED', 'website' => $website->getId()));
1228
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
1229
+ ->setMessage('Don\'t forget to enable if you want to sync reviews.' )
1230
+ ->setTable(array(
1231
+ 'Website' => $websiteName,
1232
+ 'Status' => $review,
1233
+ 'Fast Fix' => 'Click <a href="' . $url . '">here </a>to enable.'
1234
+ ));
1235
+ }
1236
+ }
1237
+ return $resultContent;
1238
+ }
1239
+
1240
+ /**
1241
+ * Check if any reviews are imported.
1242
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1243
+ */
1244
+ public function reviewSyncing()
1245
+ {
1246
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1247
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1248
+ ->setTitle('Review Syncing : ')
1249
+ ->setMessage('Looks Great.');
1250
+
1251
+ foreach ( Mage::app()->getWebsites() as $website ) {
1252
+ $websiteName = $website->getName();
1253
+ $storeIds = $website->getStoreIds();
1254
+
1255
+ //number of reviews marked as imported
1256
+ $numReview = Mage::getModel('ddg_automation/review')->getCollection()
1257
+ ->addFieldToFilter('review_imported', 1)
1258
+ ->addFieldToFilter('store_id', array('in', $storeIds))
1259
+ ->getSize();
1260
+
1261
+ //total reviews
1262
+ $totalReview = Mage::getModel('ddg_automation/review')->getCollection()
1263
+ ->addFieldToFilter('store_id', array('in', $storeIds))
1264
+ ->getSize();
1265
+
1266
+ $tableData = array(
1267
+ 'Website' => $websiteName,
1268
+ 'Total Reviews' => $totalReview,
1269
+ 'Imported' => $numReview
1270
+ );
1271
+
1272
+ $tableData['Status'] = 'Importing';
1273
+
1274
+ if (! $numReview) {
1275
+ $tableData['Status'] = 'No Imported Review Found.';
1276
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
1277
+ ->setTitle('Review Sync (ignore if you have reset wishlist) : ')
1278
+ ->setMessage('');
1279
+ }
1280
+ $resultContent->setTable($tableData);
1281
+ }
1282
+ return $resultContent;
1283
+ }
1284
+
1285
+ /**
1286
+ * review campaign enabled.
1287
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1288
+ */
1289
+ public function reviewCampaignStatus()
1290
+ {
1291
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1292
+
1293
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1294
+ ->setTitle('Review Status : ')
1295
+ ->setMessage('Looks Great.');
1296
+
1297
+ foreach ( Mage::app()->getWebsites() as $website ) {
1298
+ $websiteName = $website->getName();
1299
+ $enabled = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_REVIEWS_ENABLED))? true :
1300
+ 'Disabled ';
1301
+ $orderStatus = ($website->getConfig(Dotdigitalgroup_Email_Helper_Review::XML_PATH_REVIEW_STATUS))? true :
1302
+ 'Disabled ';
1303
+ $delayPeriod = ($website->getConfig(Dotdigitalgroup_Email_Helper_Review::XML_PATH_REVIEW_DELAY))? true :
1304
+ 'Disabled ';
1305
+ $newProduct = ($website->getConfig(Dotdigitalgroup_Email_Helper_Review::XML_PATH_REVIEW_NEW_PRODUCT))? true :
1306
+ 'Disabled ';
1307
+ $campaign = ($website->getConfig(Dotdigitalgroup_Email_Helper_Review::XML_PATH_REVIEW_CAMPAIGN))? true :
1308
+ 'Disabled ';
1309
+
1310
+ if ($enabled !== true || $orderStatus !== true || $delayPeriod !== true || $newProduct !== true || $campaign !== true){
1311
+ $enabledUrl = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_REVIEWS_ENABLED', 'website' => $website->getId()));
1312
+
1313
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
1314
+ ->setMessage('Don\'t forget to map')
1315
+ ->setTable(array(
1316
+ 'Website' => $websiteName,
1317
+ 'Enabled' => ($enabled !== true)? $enabled . '<a href="' . $enabledUrl . '">Click to enable</a>' : 'Enabled',
1318
+ 'Order Status' => ($orderStatus !== true)? 'Not Set' : 'Enabled',
1319
+ 'Delay Period' => ($delayPeriod !== true)? 'Not Set' : 'Enabled',
1320
+ 'New Product Only' => ($newProduct !== true)? 'Not Set' : 'Enabled',
1321
+ 'Campaign To Select' => ($campaign !== true)? 'Not Set' : 'Enabled',
1322
+ ));
1323
+ }
1324
+ }
1325
+ return $resultContent;
1326
+ }
1327
+
1328
+ /**
1329
+ * Get the last date for abandaned carts.
1330
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1331
+ */
1332
+ public function lastAbandonedCartSentDay()
1333
+ {
1334
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1335
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1336
+ ->setTitle('Last Abandoned Summary : ');
1337
+
1338
+ foreach ( Mage::app()->getWebsites() as $website ) {
1339
+
1340
+ $websiteName = $website->getName();
1341
+ $client = Mage::helper('ddg')->getWebsiteApiClient($website);
1342
+
1343
+ //customer carts
1344
+ $customerCampaign1 = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CAMPAIGN_1);
1345
+ $customerCampaign2 = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CAMPAIGN_2);
1346
+ $customerCampaign3 = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CAMPAIGN_3);
1347
+
1348
+ //guests carts
1349
+ $guestCampaign1 = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_GUEST_ABANDONED_CAMPAIGN_1);
1350
+ $guestCampaign2 = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_GUEST_ABANDONED_CAMPAIGN_2);
1351
+ $guestCampaign3 = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_GUEST_ABANDONED_CAMPAIGN_3);
1352
+
1353
+
1354
+ //date customer carts
1355
+
1356
+ $cusDateSent1 = ($customerCampaign1)? $client->getCampaignSummary($customerCampaign1) : '';
1357
+ $cusDateSent2 = ($customerCampaign2)? $client->getCampaignSummary($customerCampaign2) : '';
1358
+ $cusDateSent3 = ($customerCampaign3)? $client->getCampaignSummary($customerCampaign3) : '';
1359
+
1360
+ //date guest carts
1361
+ $resGuest1 = ($guestCampaign1)? $client->getCampaignSummary($guestCampaign1) : '';
1362
+ $resGuest2 = ($guestCampaign2)? $client->getCampaignSummary($guestCampaign2) : '';
1363
+ $resGuest3 = ($guestCampaign3)? $client->getCampaignSummary($guestCampaign3) : '';
1364
+
1365
+ /**
1366
+ * Customers.
1367
+ */
1368
+ $customerCampaign1 = (isset($cusDateSent1->dateSent)? $cusDateSent1->dateSent : 'Not Sent/Selected');
1369
+ $customerCampaign2 = (isset($cusDateSent2->dateSent)? $cusDateSent2->dateSent : 'Not Sent/Selected');
1370
+ $customerCampaign3 = (isset($cusDateSent3->dateSent)? $cusDateSent3->dateSent : 'Not Sent/Selected');
1371
+
1372
+ /**
1373
+ * Guests.
1374
+ */
1375
+ $guestCampaign1 = (isset($resGuest1->dateSent)? $resGuest1->dateSent : 'Not Sent/Selected');
1376
+ $guestCampaign2 = (isset($resGuest2->dateSent)? $resGuest2->dateSent : 'Not Sent/Selected');
1377
+ $guestCampaign3 = (isset($resGuest3->dateSent)? $resGuest3->dateSent : 'Not Sent/Selected');
1378
+
1379
+
1380
+ $resultContent->setTable(array(
1381
+ 'Website' => $websiteName,
1382
+ 'Customer Campaign 1' => $customerCampaign1,
1383
+ 'Customer Campaign 2' => $customerCampaign2,
1384
+ 'Customer Campaign 3' => $customerCampaign3,
1385
+ 'Guest Campaign 1' => $guestCampaign1,
1386
+ 'Guest Campaign 2' => $guestCampaign2,
1387
+ 'Guest Campaign 3' => $guestCampaign3
1388
+ ));
1389
+ }
1390
+
1391
+ return $resultContent;
1392
+ }
1393
+
1394
+ /**
1395
+ * Conflict checker.
1396
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1397
+ */
1398
+ public function conflictCheck()
1399
+ {
1400
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1401
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1402
+ ->setTitle('Conflict Status : ')
1403
+ ->setMessage('Looks Great.');
1404
+
1405
+ //check the module override and conflict
1406
+ $rewrites = Mage::helper('ddg/dashboard')->getRewrites();
1407
+
1408
+
1409
+ if ($rewrites === false) {
1410
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1411
+ ->setMessage('No Conflict Rewrites Found.');
1412
+ } else {
1413
+
1414
+ $types = array('blocks', 'models', 'helpers');
1415
+ foreach ($types as $t) {
1416
+
1417
+ if (!empty($rewrites[$t])) {
1418
+
1419
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
1420
+ ->setMessage('Conflicting Rewrite Found : ');
1421
+
1422
+ foreach ($rewrites[$t] as $node => $rewriteInfo) {
1423
+
1424
+ $resultContent->setTable(array(
1425
+ 'Type' => $t,
1426
+ 'Class' => implode(', ', array_values($rewriteInfo['classes'])),
1427
+ 'Rewrites' => '',
1428
+ 'Loaded Class' => ''
1429
+ ));
1430
+ }
1431
+ }
1432
+ }
1433
+
1434
+ $conflictCounter = 0;
1435
+ $tableData = array();
1436
+ foreach ($rewrites as $type => $data) {
1437
+ if (count($data) > 0 && is_array($data)) {
1438
+
1439
+ foreach ($data as $class => $rewriteClass) {
1440
+
1441
+ if (count($rewriteClass) > 1) {
1442
+ if ($this->_isInheritanceConflict($rewriteClass)) {
1443
+
1444
+ $resultContent->setTable(array(
1445
+ 'Type' => $type,
1446
+ 'Class' => $class,
1447
+ 'Rewrites' => implode(', ', $rewriteClass['classes']),
1448
+ 'Loaded Class' => $this->_getLoadedClass($type, $class),
1449
+ ));
1450
+
1451
+ $conflictCounter++;
1452
+ }
1453
+ }
1454
+ }
1455
+ }
1456
+ }
1457
+ if (! empty($tableData))
1458
+ $resultContent->setTable($tableData);
1459
+
1460
+ }
1461
+
1462
+ return $resultContent;
1463
+ }
1464
+
1465
+ /**
1466
+ * Returns loaded class by type like models or blocks
1467
+ *
1468
+ * @param string $type
1469
+ * @param string $class
1470
+ * @return string
1471
+ */
1472
+ protected function _getLoadedClass($type, $class)
1473
+ {
1474
+ switch ($type) {
1475
+ case 'blocks':
1476
+ return Mage::getConfig()->getBlockClassName($class);
1477
+
1478
+ case 'helpers':
1479
+ return Mage::getConfig()->getHelperClassName($class);
1480
+
1481
+ default:
1482
+ case 'models':
1483
+ return Mage::getConfig()->getModelClassName($class);
1484
+ break;
1485
+ }
1486
+ }
1487
+
1488
+ /**
1489
+ * Check if rewritten class has inherited the parent class.
1490
+ * If yes we have no conflict. The top class can extend every core class.
1491
+ * So we cannot check this.
1492
+ *
1493
+ * @var array $classes
1494
+ * @return bool
1495
+ */
1496
+ protected function _isInheritanceConflict($classes)
1497
+ {
1498
+ $classes = array_reverse($classes);
1499
+ for ($i = 0; $i < count($classes) - 1; $i++) {
1500
+ try {
1501
+ if (class_exists($classes[$i])
1502
+ && class_exists($classes[$i + 1])
1503
+ ) {
1504
+ if (! is_a($classes[$i], $classes[$i + 1], true)) {
1505
+ return true;
1506
+ }
1507
+ }
1508
+ } catch (\Exception $e) {
1509
+ return true;
1510
+ }
1511
+ }
1512
+
1513
+ return false;
1514
+ }
1515
+
1516
+ /**
1517
+ * System information about the version used and the memory limits.
1518
+ *
1519
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1520
+ */
1521
+ public function systemInformation()
1522
+ {
1523
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1524
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED);
1525
+
1526
+ //compatibility with the old versions
1527
+ if (version_compare(Mage::getVersion(), '1.6.2.0', '>')) {
1528
+ $version = 'Magento ' . Mage::getEdition() . ' ' . Mage::getVersion() . 'V';
1529
+ } else {
1530
+ $version = 'Magento version : ' . Mage::getVersion() . 'V';
1531
+ }
1532
+
1533
+ $fh = @fopen('/proc/meminfo', 'r');
1534
+ $mem = 0;
1535
+ if ($fh) {
1536
+ while ($line = fgets($fh)) {
1537
+ $pieces = array();
1538
+ if (preg_match('^MemTotal:\s+(\d+)\skB$^', $line, $pieces)) {
1539
+ $mem = $pieces[1];
1540
+ break;
1541
+ }
1542
+ }
1543
+ fclose($fh);
1544
+ }
1545
+ if ($mem > 0) {
1546
+ $mem = $mem / 1024 . 'M';
1547
+ } else {
1548
+ $mem = $this->_getTopMemoryInfo();
1549
+ }
1550
+
1551
+ //check for php version
1552
+ $resultContent->setHowTo('PHP version : V' . PHP_VERSION)
1553
+ ->setHowto('PHP Memory : ' . $mem)
1554
+ ->setHowto('PHP Max Execution Time : ' . ini_get('max_execution_time') . ' sec')
1555
+ ->setHowto($version)
1556
+ ->setHowto('Connector version : V' . Mage::helper('ddg')->getConnectorVersion());
1557
+
1558
+ return $resultContent;
1559
+ }
1560
+
1561
+
1562
+ /**
1563
+ * Returns memory size. Alternative way
1564
+ *
1565
+ * @return string|null
1566
+ */
1567
+ public function _getTopMemoryInfo()
1568
+ {
1569
+ $memInfo = exec('top -l 1 | head -n 10 | grep PhysMem');
1570
+ $memInfo = str_ireplace('PhysMem: ', '', $memInfo);
1571
+
1572
+ if (!empty($memInfo)) {
1573
+ return $memInfo;
1574
+ } else {
1575
+ return null;
1576
+ }
1577
+ }
1578
+
1579
+ /**
1580
+ * Check if the mapped program is active.
1581
+
1582
+ */
1583
+ protected function _getWebisteProgram($program, $website) {
1584
+ $client = Mage::helper('ddg')->getWebsiteApiClient($website);
1585
+
1586
+ if (! $client || !$program){
1587
+ return false;
1588
+ }
1589
+
1590
+ $data = $client->getProgramById($program);
1591
+
1592
+ if (isset($data->message))
1593
+ return false;
1594
+
1595
+
1596
+ return $data;
1597
+ }
1598
+
1599
+ /**
1600
+ * Get the contacts address book.
1601
+ * @param $addressBook
1602
+ * @param $webiste
1603
+ *
1604
+ * @return bool|null
1605
+ */
1606
+ protected function _getAddressBookContacts($addressBook, $webiste) {
1607
+ $client = Mage::helper('ddg')->getWebsiteApiClient($webiste);
1608
+
1609
+ if (! $client && $addressBook)
1610
+ return false;
1611
+
1612
+ $response = $client->getAddressBookById($addressBook);
1613
+
1614
+ if (isset($response->message))
1615
+ return false;
1616
+ return $response;
1617
+ }
1618
+
1619
+ /**
1620
+ * Get the method name
1621
+ * @param $name
1622
+ *
1623
+ * @return string
1624
+ */
1625
+ public function getFormatedMethodName($name)
1626
+ {
1627
+ //version that not support the lcfirst method
1628
+ if(function_exists('lcfirst') === false) {
1629
+
1630
+ $method = strtolower(substr(uc_words($name, '') ,0,1)).substr(uc_words($name, ''), 1);
1631
+
1632
+ } else {
1633
+ $method = lcfirst(uc_words($name, ''));
1634
+ }
1635
+
1636
+ return $method;
1637
+ }
1638
+
1639
+ /**
1640
+ * easy email capture enabled
1641
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1642
+ */
1643
+ public function easyEmailCaptureEnabled()
1644
+ {
1645
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1646
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1647
+ ->setTitle('Easy Email Capture : ')
1648
+ ->setMessage('Enabled.');
1649
+
1650
+ foreach ( Mage::app()->getWebsites() as $website ) {
1651
+ $websiteName = $website->getName();
1652
+ $enabled = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_EMAIL_CAPTURE))? true :
1653
+ 'Disabled';
1654
+
1655
+ if ($enabled !== true){
1656
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_EMAIL_CAPTURE', 'website' => $website->getId()));
1657
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
1658
+ ->setMessage('Don\'t forget to enable if you want to enable easy email capture.' )
1659
+ ->setTable(array(
1660
+ 'Website' => $websiteName,
1661
+ 'Status' => $enabled,
1662
+ 'Fast Fix' => 'Click <a href="' . $url . '">here </a>to enable.'
1663
+ ));
1664
+ }
1665
+ }
1666
+ return $resultContent;
1667
+ }
1668
+
1669
+ /**
1670
+ * disabled newsletter success enabled
1671
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1672
+ */
1673
+ public function disableNewsletterSuccessEnabled()
1674
+ {
1675
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1676
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1677
+ ->setTitle('Disable Newsletter Success : ')
1678
+ ->setMessage('Enabled.');
1679
+
1680
+ foreach ( Mage::app()->getWebsites() as $website ) {
1681
+ $websiteName = $website->getName();
1682
+ $enabled = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DISABLE_NEWSLETTER_SUCCESS))? true :
1683
+ 'Disabled';
1684
+
1685
+ if ($enabled !== true){
1686
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_DISABLE_NEWSLETTER_SUCCESS', 'website' => $website->getId()));
1687
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
1688
+ ->setMessage('Don\'t forget to enable if you want to disable Magento newsletter success email.' )
1689
+ ->setTable(array(
1690
+ 'Website' => $websiteName,
1691
+ 'Status' => $enabled,
1692
+ 'Fast Fix' => 'Click <a href="' . $url . '">here </a>to enable.'
1693
+ ));
1694
+ }
1695
+ }
1696
+ return $resultContent;
1697
+ }
1698
+
1699
+ /**
1700
+ * wishlist sync enabled.
1701
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1702
+ */
1703
+ public function wishlistEnabled()
1704
+ {
1705
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1706
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1707
+ ->setTitle('Wishlist Sync : ')
1708
+ ->setMessage('Enabled.');
1709
+
1710
+ foreach ( Mage::app()->getWebsites() as $website ) {
1711
+ $websiteName = $website->getName();
1712
+ $wishlist = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_WISHLIST_ENABLED))? true :
1713
+ 'Disabled';
1714
+
1715
+ if ($wishlist !== true){
1716
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_SYNC_WISHLIST_ENABLED', 'website' => $website->getId()));
1717
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
1718
+ ->setMessage('Don\'t forget to enable if you want to sync wishlist.' )
1719
+ ->setTable(array(
1720
+ 'Website' => $websiteName,
1721
+ 'Status' => $wishlist,
1722
+ 'Fast Fix' => 'Click <a href="' . $url . '">here </a>to enable.'
1723
+ ));
1724
+ }
1725
+ }
1726
+ return $resultContent;
1727
+ }
1728
+
1729
+ /**
1730
+ * Check if any wishlist are imported.
1731
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1732
+ */
1733
+ public function wishlistSyncing()
1734
+ {
1735
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1736
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1737
+ ->setTitle('Wishlist Syncing : ')
1738
+ ->setMessage('Looks Great.');
1739
+
1740
+ foreach ( Mage::app()->getWebsites() as $website ) {
1741
+ $websiteName = $website->getName();
1742
+ $storeIds = $website->getStoreIds();
1743
+
1744
+ //number of wishlist marked as imported
1745
+ $numWishlist = Mage::getModel('ddg_automation/wishlist')->getCollection()
1746
+ ->addFieldToFilter('wishlist_imported', 1)
1747
+ ->addFieldToFilter('store_id', array('in', $storeIds))
1748
+ ->getSize();
1749
+
1750
+ //total wishlist
1751
+ $totalWishlist = Mage::getModel('ddg_automation/wishlist')->getCollection()
1752
+ ->addFieldToFilter('store_id', array('in', $storeIds))
1753
+ ->getSize();
1754
+
1755
+ $tableData = array(
1756
+ 'Website' => $websiteName,
1757
+ 'Total Wishlist' => $totalWishlist,
1758
+ 'Imported' => $numWishlist
1759
+ );
1760
+
1761
+ $tableData['Status'] = 'Importing';
1762
+
1763
+ if (! $numWishlist) {
1764
+ $tableData['Status'] = 'No Imported Wishlist Found.';
1765
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
1766
+ ->setTitle('Wishlist Sync (ignore if you have reset wishlist) : ')
1767
+ ->setMessage('');
1768
+ }
1769
+ $resultContent->setTable($tableData);
1770
+ }
1771
+ return $resultContent;
1772
+ }
1773
+ }
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->_controller = 'adminhtml_order';
10
+ $this->_blockGroup = 'ddg_automation';
11
+ $this->_headerText = Mage::helper('ddg')->__('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 'ddg_automation/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('ddg')->__('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('ddg')->__('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('ddg')->__('Store ID'),
61
+ 'width' => '50px',
62
+ 'index' => 'store_id',
63
+ 'type' => 'number',
64
+ 'escape' => true,
65
+ ))->addColumn('email_imported', array(
66
+ 'header' => Mage::helper('ddg')->__('Email Imported'),
67
+ 'align' => 'center',
68
+ 'width' => '50px',
69
+ 'index' => 'email_imported',
70
+ 'type' => 'options',
71
+ 'escape' => true,
72
+ 'renderer' => 'ddg_automation/adminhtml_column_renderer_imported',
73
+ 'options' => Mage::getModel('ddg_automation/adminhtml_source_contact_imported')->getOptions(),
74
+ 'filter_condition_callback' => array($this, 'filterCallbackContact')
75
+ ))->addColumn('created_at', array(
76
+ 'header' => Mage::helper('ddg')->__('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('ddg')->__('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/Quote.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Quote extends Mage_Adminhtml_Block_Widget_Grid_Container
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+
9
+ $this->_controller = 'adminhtml_quote';
10
+ $this->_blockGroup = 'ddg_automation';
11
+ $this->_headerText = Mage::helper('ddg')->__('Email Quote(s)');
12
+
13
+ $this->_removeButton('add');
14
+ }
15
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Quote/Grid.php ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Quote_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('id');
11
+ $this->setId('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 'ddg_automation/quote_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('quote_id', array(
45
+ 'header' => Mage::helper('ddg')->__('Quote ID'),
46
+ 'align' => 'left',
47
+ 'width' => '50px',
48
+ 'index' => 'quote_id',
49
+ 'type' => 'number',
50
+ 'escape' => true
51
+ ))->addColumn('customer_id', array(
52
+ 'header' => Mage::helper('ddg')->__('Customer ID'),
53
+ 'align' => 'left',
54
+ 'width' => '50px',
55
+ 'index' => 'customer_id',
56
+ 'type' => 'number',
57
+ 'escape' => true
58
+ ))->addColumn('store_id', array(
59
+ 'header' => Mage::helper('ddg')->__('Store ID'),
60
+ 'align' => 'left',
61
+ 'width' => '50px',
62
+ 'index' => 'store_id',
63
+ 'type' => 'number',
64
+ 'escape' => true
65
+ ))->addColumn('imported', array(
66
+ 'header' => Mage::helper('ddg')->__('Quote Imported'),
67
+ 'align' => 'center',
68
+ 'width' => '50px',
69
+ 'index' => 'imported',
70
+ 'type' => 'options',
71
+ 'escape' => true,
72
+ 'renderer' => 'ddg_automation/adminhtml_column_renderer_imported',
73
+ 'options' => Mage::getModel('ddg_automation/adminhtml_source_contact_imported')->getOptions(),
74
+ 'filter_condition_callback' => array($this, 'filterCallbackContact')
75
+ ))->addColumn('modified', array(
76
+ 'header' => Mage::helper('ddg')->__('Quote Modified'),
77
+ 'align' => 'center',
78
+ 'width' => '50px',
79
+ 'index' => 'modified',
80
+ 'type' => 'options',
81
+ 'escape' => true,
82
+ 'renderer' => 'ddg_automation/adminhtml_column_renderer_imported',
83
+ 'options' => Mage::getModel('ddg_automation/adminhtml_source_contact_imported')->getOptions(),
84
+ 'filter_condition_callback' => array($this, 'filterCallbackContact')
85
+ ))->addColumn('converted_to_order', array(
86
+ 'header' => Mage::helper('ddg')->__('Converted To Order'),
87
+ 'align' => 'center',
88
+ 'width' => '50px',
89
+ 'index' => 'converted_to_order',
90
+ 'type' => 'options',
91
+ 'escape' => true,
92
+ 'renderer' => 'ddg_automation/adminhtml_column_renderer_imported',
93
+ 'options' => Mage::getModel('ddg_automation/adminhtml_source_contact_imported')->getOptions(),
94
+ 'filter_condition_callback' => array($this, 'filterCallbackContact')
95
+ ))->addColumn('created_at', array(
96
+ 'header' => Mage::helper('ddg')->__('Created At'),
97
+ 'width' => '50px',
98
+ 'align' => 'center',
99
+ 'index' => 'created_at',
100
+ 'type' => 'datetime',
101
+ 'escape' => true,
102
+ ))->addColumn('updated_at', array(
103
+ 'header' => Mage::helper('ddg')->__('Updated At'),
104
+ 'width' => '50px',
105
+ 'align' => 'center',
106
+ 'index' => 'updated_at',
107
+ 'type' => 'datetime',
108
+ 'escape' => true,
109
+ ));
110
+
111
+ return parent::_prepareColumns();
112
+ }
113
+
114
+ /**
115
+ * Callback action for the imported subscribers/contacts.
116
+ *
117
+ * @param $collection
118
+ * @param $column
119
+ */
120
+ public function filterCallbackContact($collection, $column)
121
+ {
122
+ $field = $column->getFilterIndex() ? $column->getFilterIndex() : $column->getIndex();
123
+ $value = $column->getFilter()->getValue();
124
+ if ($value == 'null') {
125
+ $collection->addFieldToFilter($field, array('null' => true));
126
+ } else {
127
+ $collection->addFieldToFilter($field, array('notnull' => true));
128
+ }
129
+ }
130
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Review.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Review extends Mage_Adminhtml_Block_Widget_Grid_Container
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+
9
+ $this->_controller = 'adminhtml_review';
10
+ $this->_blockGroup = 'ddg_automation';
11
+ $this->_headerText = Mage::helper('ddg')->__('Email Review(s)');
12
+
13
+ $this->_removeButton('add');
14
+ }
15
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Review/Grid.php ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Review_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('id');
11
+ $this->setId('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 'ddg_automation/review_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('review_id', array(
45
+ 'header' => Mage::helper('ddg')->__('Review ID'),
46
+ 'align' => 'left',
47
+ 'width' => '50px',
48
+ 'index' => 'review_id',
49
+ 'type' => 'number',
50
+ 'escape' => true
51
+ ))->addColumn('customer_id', array(
52
+ 'header' => Mage::helper('ddg')->__('Customer ID'),
53
+ 'align' => 'left',
54
+ 'width' => '50px',
55
+ 'index' => 'customer_id',
56
+ 'type' => 'number',
57
+ 'escape' => true
58
+ ))->addColumn('store_id', array(
59
+ 'header' => Mage::helper('ddg')->__('Store ID'),
60
+ 'width' => '50px',
61
+ 'index' => 'store_id',
62
+ 'type' => 'number',
63
+ 'escape' => true,
64
+ ))->addColumn('review_imported', array(
65
+ 'header' => Mage::helper('ddg')->__('Review Imported'),
66
+ 'align' => 'center',
67
+ 'width' => '50px',
68
+ 'index' => 'review_imported',
69
+ 'type' => 'options',
70
+ 'escape' => true,
71
+ 'renderer' => 'ddg_automation/adminhtml_column_renderer_imported',
72
+ 'options' => Mage::getModel('ddg_automation/adminhtml_source_contact_imported')->getOptions(),
73
+ 'filter_condition_callback' => array($this, 'filterCallbackContact')
74
+ ))->addColumn('created_at', array(
75
+ 'header' => Mage::helper('ddg')->__('Created At'),
76
+ 'width' => '50px',
77
+ 'align' => 'center',
78
+ 'index' => 'created_at',
79
+ 'type' => 'datetime',
80
+ 'escape' => true,
81
+ ))->addColumn('updated_at', array(
82
+ 'header' => Mage::helper('ddg')->__('Updated At'),
83
+ 'width' => '50px',
84
+ 'align' => 'center',
85
+ 'index' => 'updated_at',
86
+ 'type' => 'datetime',
87
+ 'escape' => true,
88
+ ));
89
+
90
+ return parent::_prepareColumns();
91
+ }
92
+
93
+ /**
94
+ * Callback action for the imported subscribers/contacts.
95
+ *
96
+ * @param $collection
97
+ * @param $column
98
+ */
99
+ public function filterCallbackContact($collection, $column)
100
+ {
101
+ $field = $column->getFilterIndex() ? $column->getFilterIndex() : $column->getIndex();
102
+ $value = $column->getFilter()->getValue();
103
+ if ($value == 'null') {
104
+ $collection->addFieldToFilter($field, array('null' => true));
105
+ } else {
106
+ $collection->addFieldToFilter($field, array('notnull' => true));
107
+ }
108
+ }
109
+ }
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/Reimportquotes.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_Reimportquotes 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/resetquotes");
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/Reimportreviews.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_Reimportreviews 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/resetreviews");
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/Reimportsubscribers.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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')
17
+ ->setLabel($this->__($title))
18
+ ->setOnClick("window.location.href='" . $url . "'")
19
+ ->toHtml();
20
+ }
21
+
22
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Reimportwishlists.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Advanced_Reimportwishlists 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/resetwishlists");
14
+
15
+ return $this->getLayout()->createBlock('adminhtml/widget_button')
16
+ ->setType('button')
17
+ ->setLabel($this->__($title))
18
+ ->setOnClick("window.location.href='" . $url . "'")
19
+ ->toHtml();
20
+ }
21
+
22
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Resetcustomersimport.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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')
17
+ ->setLabel($this->__($title))
18
+ ->setOnClick("window.location.href='" . $url . "'")
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/Runquotesync.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Advanced_Runquotesync 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/runquotesync");
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/Runreviewsync.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Advanced_Runreviewsync 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/runreviewsync");
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/Runwishlistsync.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Advanced_Runwishlistsync 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/runwishlistsync");
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,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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('ddg')->getAuthoriseUrl();
14
+ $ssl = $this->_checkForSecureUrl();
15
+ $disabled = false;
16
+ //disable for ssl missing
17
+ if (!$ssl) {
18
+ $disabled = true;
19
+ }
20
+
21
+ $adminUser = Mage::getSingleton('admin/session')->getUser();
22
+ $refreshToken = $adminUser->getRefreshToken();
23
+ $title = ($refreshToken)? $this->__('Disconnect') : $this->__('Connect');
24
+ $url = ($refreshToken)? $this->getUrl('*/email_automation/disconnect') : $url;
25
+
26
+ return $this->getLayout()->createBlock('adminhtml/widget_button')
27
+ ->setType('button')
28
+ ->setLabel($this->__($title))
29
+ ->setDisabled($disabled)
30
+ ->setOnClick("window.location.href='" . $url . "'")
31
+ ->toHtml();
32
+ }
33
+
34
+ private function _checkForSecureUrl() {
35
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB, true);
36
+ if (!preg_match('/https/',$baseUrl)) {
37
+ return false;
38
+ }
39
+ return $this;
40
+ }
41
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Addressbook.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 visibility = $('connector_sync_settings_dynamic_addressbook_visibility').value;
22
+ var reloadurl = '{$url}';
23
+ if(name && visibility){
24
+ new Ajax.Request(reloadurl, {
25
+ method: 'post',
26
+ parameters: {'name' : name, 'visibility' : visibility, 'website': '$website'},
27
+ onComplete: function(transport) {
28
+ window.location.reload();
29
+ }
30
+ });
31
+ }
32
+ return false;
33
+ }
34
+ </script>"
35
+ );
36
+
37
+ return parent::_getElementHtml($element);
38
+ }
39
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Colorpicker.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Colorpicker extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ /**
6
+ * Generate HTML code for color picker
7
+ *
8
+ * @param Varien_Data_Form_Element_Abstract $element
9
+ * @return string
10
+ */
11
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
12
+ {
13
+ // Include Procolor library JS file
14
+ $html = '<script type="text/javascript" src="' . Mage::getBaseUrl('js') . 'connector/procolor-1.0/procolor.compressed.js' .'"></script>';
15
+
16
+ // Use Varien text element as a basis
17
+ $input = new Varien_Data_Form_Element_Text();
18
+
19
+ // Set data from config element on Varien text element
20
+ $input->setForm($element->getForm())
21
+ ->setElement($element)
22
+ ->setValue($element->getValue())
23
+ ->setHtmlId($element->getHtmlId())
24
+ ->setName($element->getName())
25
+ ->setStyle('width: 60px') // Update style in order to shrink width
26
+ ->addClass('validate-hex'); // Add some Prototype validation to make sure color code is correct
27
+
28
+ // Inject updated Varien text element HTML in our current HTML
29
+ $html .= $input->getHtml();
30
+
31
+ // Inject Procolor JS code to display color picker
32
+ $html .= $this->_getProcolorJs($element->getHtmlId());
33
+
34
+ // Inject Prototype validation
35
+ $html .= $this->_addHexValidator();
36
+
37
+ return $html;
38
+ }
39
+
40
+ /**
41
+ * Procolor JS code to display color picker
42
+ *
43
+ * @see http://procolor.sourceforge.net/examples.php
44
+ * @param string $htmlId
45
+ * @return string
46
+ */
47
+ protected function _getProcolorJs($htmlId)
48
+ {
49
+ return '<script type="text/javascript">ProColor.prototype.attachButton(\'' . $htmlId . '\', { imgPath:\'' . Mage::getBaseUrl('js') . 'connector/procolor-1.0/' . 'img/procolor_win_\', showInField: true });</script>';
50
+ }
51
+
52
+ /**
53
+ * Prototype validation
54
+ *
55
+ * @return string
56
+ */
57
+ protected function _addHexValidator()
58
+ {
59
+ return
60
+ '<script type="text/javascript">
61
+ Validation.add(\'validate-hex\', \'' . Mage::helper('ddg')->__('Please enter a valid hex color code') . '\', function(v) {
62
+ return /^#(?:[0-9a-fA-F]{3}){1,2}$/.test(v);
63
+ });
64
+ </script>';
65
+ }
66
+ }
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_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/Enterprisevalidator.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Enterprisevalidator extends Mage_Adminhtml_Block_System_Config_Form_Field
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
+ // Set up additional JavaScript for our validation using jQuery.
12
+
13
+ $jquery = '<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>';
14
+
15
+ if (! Mage::helper('ddg')->isEnterprise()) {
16
+ $html .=$jquery;
17
+ $javaScript = "<script type=\"text/javascript\">
18
+ jQuery.noConflict();
19
+ jQuery(document).ready(function() {
20
+ jQuery('#connector_data_mapping_enterprise_data-head').parent().hide();
21
+
22
+ });
23
+ </script>";
24
+ $html .= $javaScript;
25
+ }
26
+
27
+
28
+ return $html;
29
+ }
30
+ }
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/Smtpvalidator.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Smtpvalidator extends Mage_Adminhtml_Block_System_Config_Form_Field
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
+ // Set up additional JavaScript for our validation using jQuery.
12
+
13
+ $jquery = '<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>';
14
+
15
+ $html .=$jquery;
16
+ $javaScript = "<script type=\"text/javascript\"> var show_warning = 0;";
17
+
18
+ if(!Mage::helper('ddg')->isSmtpEnabled()){
19
+ $javaScript .= "show_warning = 1;";
20
+ }
21
+
22
+ $javaScript .=
23
+ "jQuery.noConflict();
24
+
25
+ jQuery(document).ready(function() {
26
+ // Handler for .ready() called.
27
+
28
+ //Show sweet tooth notice
29
+ if(show_warning == 1) jQuery('#smtp-warning').show();
30
+ });
31
+ </script>";
32
+
33
+ $html .= $javaScript;
34
+ return $html;
35
+ }
36
+ }
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('ddg')->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/Basket/Crosssell.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Basket_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('ddg')->generateDynamicUrl();
9
+ //config passcode
10
+ $passcode = Mage::helper('ddg')->getPasscode();
11
+ //last quote id for dynamic page
12
+ $lastQuoteId = Mage::helper('ddg')->getLastQuoteId();
13
+
14
+ if (!strlen($passcode))
15
+ $passcode = '[PLEASE SET UP A PASSCODE]';
16
+ //alert message for last order id is not mapped
17
+ if (!$lastQuoteId)
18
+ $lastQuoteId = '[PLEASE MAP THE LAST QUOTE ID]';
19
+
20
+ //full url for dynamic content
21
+ $text = sprintf('%sconnector/quoteproducts/crosssell/code/%s/quote_id/@%s@', $baseUrl, $passcode, $lastQuoteId);
22
+ $element->setData('value', $text);
23
+
24
+ return parent::_getElementHtml($element);
25
+ }
26
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Basket/Related.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Basket_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('ddg')->getPasscode();
9
+ //last quote id for dynamic page
10
+ $lastQuoteId = Mage::helper('ddg')->getLastQuoteId();
11
+
12
+ if (!strlen($passcode))
13
+ $passcode = '[PLEASE SET UP A PASSCODE]';
14
+ //alert message for last order id is not mapped
15
+ if (!$lastQuoteId)
16
+ $lastQuoteId = '[PLEASE MAP THE LAST QUOTE ID]';
17
+
18
+ //generate the base url and display for default store id
19
+ $baseUrl = Mage::helper('ddg')->generateDynamicUrl();
20
+
21
+ //display the full url
22
+ $text = sprintf('%sconnector/quoteproducts/related/code/%s/quote_id/@%s@', $baseUrl, $passcode, $lastQuoteId);
23
+ $element->setData('value', $text);
24
+
25
+ return parent::_getElementHtml($element);
26
+ }
27
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Basket/Upsell.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Basket_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('ddg')->getPasscode();
8
+ //last quote id for dynamic page
9
+ $lastQuoteId = Mage::helper('ddg')->getLastQuoteId();
10
+
11
+ if (!strlen($passcode))
12
+ $passcode = '[PLEASE SET UP A PASSCODE]';
13
+ //alert message for last order id is not mapped
14
+ if (!$lastQuoteId)
15
+ $lastQuoteId = '[PLEASE MAP THE LAST QUOTE ID]';
16
+
17
+ //generate the base url and display for default store id
18
+ $baseUrl = Mage::helper('ddg')->generateDynamicUrl();
19
+
20
+ $text = sprintf('%sconnector/quoteproducts/upsell/code/%s/quote_id/@%s@', $baseUrl, $passcode, $lastQuoteId);
21
+ $element->setData('value', $text);
22
+
23
+ return parent::_getElementHtml($element);
24
+ }
25
+ }
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('ddg')->generateDynamicUrl();
10
+
11
+ //config passcode
12
+ $passcode = Mage::helper('ddg')->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('ddg')->generateDynamicUrl();
10
+
11
+
12
+ //config code
13
+ $code = Mage::helper('ddg')->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 . '/@EMAIL@';
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('ddg')->generateDynamicUrl();
9
+
10
+ //config code
11
+ $code = Mage::helper('ddg')->getPasscode();
12
+ $orderId = Mage::helper('ddg')->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('ddg')->generateDynamicUrl();
9
+ //config passcode
10
+ $passcode = Mage::helper('ddg')->getPasscode();
11
+ //last order id for dynamic page
12
+ $lastOrderId = Mage::helper('ddg')->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/Fallbackchooser.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Fallbackchooser 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->__("Choose Products"));
10
+ }
11
+
12
+ protected function _getAddRowButtonHtml($title)
13
+ {
14
+ $action = 'getFallbackProductChooser(\'' . Mage::getUrl(
15
+ '*/widget_chooser/product/form/fallback_product_selector',
16
+ array('_secure' => Mage::app()->getStore()->isAdminUrlSecure())
17
+ ) . '?isAjax=true\'); return false;';
18
+
19
+ return $this->getLayout()->createBlock('adminhtml/widget_button')
20
+ ->setType('button')
21
+ ->setLabel($this->__($title))
22
+ ->setOnClick($action)
23
+ ->toHtml();
24
+ }
25
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Fallbackcontainer.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Fallbackcontainer 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
10
+ "<script type='text/javascript'>
11
+ var fallback_product_selector = new ConnectorProductSelectorForm('connector_dynamic_content_fallback_products_product_list');
12
+ //ajax call and handler
13
+ getFallbackProductChooser = function (url) {
14
+ new Ajax.Request(
15
+ url, {
16
+ method: 'post',
17
+ onSuccess: function (b) {
18
+ var a = $('connector-fallback-product-chooser-container');
19
+ a.update(b.responseText);
20
+ a.scrollTo()
21
+ }
22
+ })
23
+ };
24
+ </script>
25
+ <div id = 'connector-fallback-product-chooser-container'></div>";
26
+ }
27
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Feefo/Reviews.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Feefo_Reviews 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('ddg')->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('ddg')->generateDynamicUrl();
15
+
16
+ //display the full url
17
+ $text = sprintf('%sconnector/feefo/reviews/code/%s/quote_id/@QUOTE_ID@', $baseUrl, $passcode);
18
+ $element->setData('value', $text);
19
+
20
+ return parent::_getElementHtml($element);
21
+ }
22
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Feefo/Score.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Feefo_Score 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('ddg')->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('ddg')->generateDynamicUrl();
15
+
16
+ //display the full url
17
+ $text = sprintf('%sconnector/feefo/score/code/%s', $baseUrl, $passcode);
18
+ $element->setData('value', $text);
19
+
20
+ return parent::_getElementHtml($element);
21
+ }
22
+ }
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,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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('ddg')->generateDynamicUrl();
11
+ $passcode = Mage::helper('ddg')->getPasscode();
12
+
13
+ //last quote id for dynamic page
14
+ $lastQuoteId = Mage::helper('ddg')->getLastQuoteId();
15
+
16
+ //config passcode
17
+ if(!strlen($passcode))
18
+ $passcode = '[PLEASE SET UP A PASSCODE]';
19
+ //alert message for last order id is not mapped
20
+ if (!$lastQuoteId)
21
+ $lastQuoteId = '[PLEASE MAP THE LAST QUOTE ID]';
22
+
23
+ // full url
24
+
25
+ $text = sprintf("%sconnector/email/basket/code/%s/quote_id/@%s@", $baseUrl, $passcode, $lastQuoteId);
26
+
27
+ $element->setData('value', $text);
28
+ return parent::_getElementHtml($element);
29
+ }
30
+
31
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Manualchooser.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Manualchooser 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->__("Choose Products"));
10
+ }
11
+
12
+ protected function _getAddRowButtonHtml($title)
13
+ {
14
+ $action = 'getManualProductChooser(\'' . Mage::getUrl(
15
+ '*/widget_chooser/product/form/manual_product_selector',
16
+ array('_secure' => Mage::app()->getStore()->isAdminUrlSecure())
17
+ ) . '?isAjax=true\'); return false;';
18
+
19
+ return $this->getLayout()->createBlock('adminhtml/widget_button')
20
+ ->setType('button')
21
+ ->setLabel($this->__($title))
22
+ ->setOnClick($action)
23
+ ->toHtml();
24
+ }
25
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Manualcontainer.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Manualcontainer 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
10
+ "<script type='text/javascript'>
11
+ var manual_product_selector = new ConnectorProductSelectorForm('connector_dynamic_content_manual_product_search_products_push_items');
12
+ //ajax call and handler
13
+ getManualProductChooser = function (url) {
14
+ new Ajax.Request(
15
+ url, {
16
+ method: 'post',
17
+ onSuccess: function (b) {
18
+ var a = $('connector-product-chooser-container');
19
+ a.update(b.responseText);
20
+ a.scrollTo()
21
+ }
22
+ })
23
+ };
24
+ </script>
25
+ <div id = 'connector-product-chooser-container'></div>";
26
+ }
27
+ }
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('ddg')->generateDynamicUrl();
10
+ $passcode = Mage::helper('ddg')->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('ddg')->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('ddg')->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('ddg')->generateDynamicUrl();
10
+ $passcode = Mage::helper('ddg')->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('ddg')->generateDynamicUrl();
8
+
9
+ //config passcode
10
+ $passcode = Mage::helper('ddg')->getPasscode();
11
+ $customerId = Mage::helper('ddg')->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('ddg')->getPasscode();
9
+ //last order id witch information will be generated
10
+ $lastOrderId = Mage::helper('ddg')->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('ddg')->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/Review.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Review extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+
6
+ /** label */
7
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
8
+ {
9
+ //passcode to append for url
10
+ $passcode = Mage::helper('ddg')->getPasscode();
11
+ //last order id witch information will be generated
12
+ $lastOrderId = Mage::helper('ddg')->getLastOrderId();
13
+
14
+ if(!strlen($passcode))
15
+ $passcode = '[PLEASE SET UP A PASSCODE]';
16
+ if(!$lastOrderId)
17
+ $lastOrderId = '[PLEASE MAP THE LAST ORDER ID]';
18
+
19
+ //generate the base url and display for default store id
20
+ $baseUrl = Mage::helper('ddg')->generateDynamicUrl();
21
+
22
+ //display the full url
23
+ $text = sprintf('%sconnector/email/review/code/%s/order_id/@%s@', $baseUrl, $passcode, $lastOrderId);
24
+ $element->setData('value', $text);
25
+
26
+ return parent::_getElementHtml($element);
27
+ }
28
+
29
+ }
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('ddg')->getPasscode();
8
+ //last order id witch information will be generated
9
+ $lastOrderid = Mage::helper('ddg')->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('ddg')->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/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Wishlist.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Wishlist extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ /**
6
+ * label
7
+ *
8
+ * @param Varien_Data_Form_Element_Abstract $element
9
+ * @return string
10
+ */
11
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
12
+ {
13
+ //passcode to append for url
14
+ $passcode = Mage::helper('ddg')->getPasscode();
15
+ //last order id witch information will be generated
16
+ $customerId = Mage::helper('ddg')->getMappedCustomerId();
17
+
18
+ if(!strlen($passcode))
19
+ $passcode = '[PLEASE SET UP A PASSCODE]';
20
+ if(!$customerId)
21
+ $customerId = '[PLEASE MAP THE CUSTOMER ID]';
22
+
23
+ //generate the base url and display for default store id
24
+ $baseUrl = Mage::helper('ddg')->generateDynamicUrl();
25
+
26
+ //display the full url
27
+ $text = sprintf('%sconnector/email/wishlist/code/%s/customer_id/@%s@', $baseUrl, $passcode, $customerId);
28
+ $element->setData('value', $text);
29
+
30
+ return parent::_getElementHtml($element);
31
+ }
32
+
33
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Wishlist/Crosssell.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Wishlist_Crosssell extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ /**
6
+ * label
7
+ *
8
+ * @param Varien_Data_Form_Element_Abstract $element
9
+ * @return string
10
+ */
11
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
12
+ {
13
+ //passcode to append for url
14
+ $passcode = Mage::helper('ddg')->getPasscode();
15
+ //last order id witch information will be generated
16
+ $customerId = Mage::helper('ddg')->getMappedCustomerId();
17
+
18
+ if(!strlen($passcode))
19
+ $passcode = '[PLEASE SET UP A PASSCODE]';
20
+ if(!$customerId)
21
+ $customerId = '[PLEASE MAP THE CUSTOMER ID]';
22
+
23
+ //generate the base url and display for default store id
24
+ $baseUrl = Mage::helper('ddg')->generateDynamicUrl();
25
+
26
+ //display the full url
27
+ $text = sprintf('%sconnector/wishlist/crosssell/code/%s/customer_id/@%s@', $baseUrl, $passcode, $customerId);
28
+ $element->setData('value', $text);
29
+
30
+ return parent::_getElementHtml($element);
31
+ }
32
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Wishlist/Related.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Wishlist_Related extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ /**
6
+ * label
7
+ *
8
+ * @param Varien_Data_Form_Element_Abstract $element
9
+ * @return string
10
+ */
11
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
12
+ {
13
+ //passcode to append for url
14
+ $passcode = Mage::helper('ddg')->getPasscode();
15
+ //last order id witch information will be generated
16
+ $customerId = Mage::helper('ddg')->getMappedCustomerId();
17
+
18
+ if(!strlen($passcode))
19
+ $passcode = '[PLEASE SET UP A PASSCODE]';
20
+ if(!$customerId)
21
+ $customerId = '[PLEASE MAP THE CUSTOMER ID]';
22
+
23
+ //generate the base url and display for default store id
24
+ $baseUrl = Mage::helper('ddg')->generateDynamicUrl();
25
+
26
+ //display the full url
27
+ $text = sprintf('%sconnector/wishlist/related/code/%s/customer_id/@%s@', $baseUrl, $passcode, $customerId);
28
+ $element->setData('value', $text);
29
+
30
+ return parent::_getElementHtml($element);
31
+ }
32
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Wishlist/Upsell.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Wishlist_Upsell extends Mage_Adminhtml_Block_System_Config_Form_Field
3
+ {
4
+ /**
5
+ * label
6
+ *
7
+ * @param Varien_Data_Form_Element_Abstract $element
8
+ * @return string
9
+ */
10
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
11
+ {
12
+ //passcode to append for url
13
+ $passcode = Mage::helper('ddg')->getPasscode();
14
+ //last order id witch information will be generated
15
+ $customerId = Mage::helper('ddg')->getMappedCustomerId();
16
+
17
+ if(!strlen($passcode))
18
+ $passcode = '[PLEASE SET UP A PASSCODE]';
19
+ if(!$customerId)
20
+ $customerId = '[PLEASE MAP THE CUSTOMER ID]';
21
+
22
+ //generate the base url and display for default store id
23
+ $baseUrl = Mage::helper('ddg')->generateDynamicUrl();
24
+
25
+ //display the full url
26
+ $text = sprintf('%sconnector/wishlist/upsell/code/%s/customer_id/@%s@', $baseUrl, $passcode, $customerId);
27
+ $element->setData('value', $text);
28
+
29
+ return parent::_getElementHtml($element);
30
+ }
31
+ }
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('ddg');
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('ddg');
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('ddg');
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('ddg');
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('ddg');
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('ddg');
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('ddg');
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('ddg');
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('ddg');
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('ddg');
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('ddg');
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('ddg');
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('ddg');
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('ddg');
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('ddg');
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('ddg');
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('ddg');
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('ddg');
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('ddg');
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/Adminhtml/Widget/Chooser/Product.php ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Widget_Chooser_Product extends Mage_Adminhtml_Block_Widget_Grid
4
+ {
5
+
6
+ public function __construct($arguments=array())
7
+ {
8
+ parent::__construct($arguments);
9
+
10
+ if ($this->getRequest()->getParam('current_grid_id')) {
11
+ $this->setId($this->getRequest()->getParam('current_grid_id'));
12
+ } else {
13
+ $this->setId('skuChooserGrid_'.$this->getId());
14
+ }
15
+
16
+ //change to 10
17
+ $this->setDefaultLimit(10);
18
+ $form = $this->getJsFormObject();
19
+ $this->setRowClickCallback("$form.chooserGridRowClick.bind($form)");
20
+ $this->setCheckboxCheckCallback("$form.chooserGridCheckboxCheck.bind($form)");
21
+ $this->setRowInitCallback("$form.chooserGridRowInit.bind($form)");
22
+ $this->setDefaultSort('entity_id');
23
+ $this->setUseAjax(true);
24
+ if ($this->getRequest()->getParam('collapse')) {
25
+ $this->setIsCollapsed(true);
26
+ }
27
+ }
28
+
29
+ /**
30
+ * Retrieve quote store object
31
+ * @return Mage_Core_Model_Store
32
+ */
33
+ public function getStore()
34
+ {
35
+ return Mage::app()->getStore();
36
+ }
37
+
38
+ protected function _addColumnFilterToCollection($column)
39
+ {
40
+ // Set custom filter for in product flag
41
+ if ($column->getId() == 'in_products') {
42
+ $selected = $this->_getSelectedProducts();
43
+ if (empty($selected)) {
44
+ $selected = '';
45
+ }
46
+ if ($column->getFilter()->getValue()) {
47
+ $this->getCollection()->addFieldToFilter('entity_id', array('in'=>$selected));
48
+ } else {
49
+ $this->getCollection()->addFieldToFilter('entity_id', array('nin'=>$selected));
50
+ }
51
+ } else {
52
+ parent::_addColumnFilterToCollection($column);
53
+ }
54
+ return $this;
55
+ }
56
+
57
+ /**
58
+ * Prepare Catalog Product Collection for attribute SKU in Promo Conditions SKU chooser
59
+ *
60
+ * @return Mage_Adminhtml_Block_Promo_Widget_Chooser_Sku
61
+ */
62
+ protected function _prepareCollection()
63
+ {
64
+ $collection = Mage::getResourceModel('catalog/product_collection')
65
+ ->setStoreId(0)
66
+ ->addAttributeToSelect('name', 'type_id', 'attribute_set_id');
67
+
68
+ $this->setCollection($collection);
69
+
70
+ return parent::_prepareCollection();
71
+ }
72
+
73
+ /**
74
+ * Define Cooser Grid Columns and filters
75
+ *
76
+ * @return Mage_Adminhtml_Block_Promo_Widget_Chooser_Sku
77
+ */
78
+ protected function _prepareColumns()
79
+ {
80
+ $this->addColumn('in_products', array(
81
+ 'header_css_class' => 'a-center',
82
+ 'type' => 'checkbox',
83
+ 'name' => 'in_products',
84
+ 'values' => $this->_getSelectedProducts(),
85
+ 'align' => 'center',
86
+ 'index' => 'entity_id',
87
+ 'use_index' => true,
88
+ ));
89
+
90
+ $this->addColumn('entity_id', array(
91
+ 'header' => Mage::helper('sales')->__('ID'),
92
+ 'sortable' => true,
93
+ 'width' => '60px',
94
+ 'index' => 'entity_id'
95
+ ));
96
+
97
+ $this->addColumn('type',
98
+ array(
99
+ 'header'=> Mage::helper('catalog')->__('Type'),
100
+ 'width' => '60px',
101
+ 'index' => 'type_id',
102
+ 'type' => 'options',
103
+ 'options' => Mage::getSingleton('catalog/product_type')->getOptionArray(),
104
+ ));
105
+
106
+ $sets = Mage::getResourceModel('eav/entity_attribute_set_collection')
107
+ ->setEntityTypeFilter(Mage::getModel('catalog/product')->getResource()->getTypeId())
108
+ ->load()
109
+ ->toOptionHash();
110
+
111
+ $this->addColumn('set_name',
112
+ array(
113
+ 'header'=> Mage::helper('catalog')->__('Attrib. Set Name'),
114
+ 'width' => '100px',
115
+ 'index' => 'attribute_set_id',
116
+ 'type' => 'options',
117
+ 'options' => $sets,
118
+ ));
119
+
120
+ $this->addColumn('chooser_sku', array(
121
+ 'header' => Mage::helper('sales')->__('SKU'),
122
+ 'name' => 'chooser_sku',
123
+ 'width' => '80px',
124
+ 'index' => 'sku'
125
+ ));
126
+ $this->addColumn('chooser_name', array(
127
+ 'header' => Mage::helper('sales')->__('Product Name'),
128
+ 'name' => 'chooser_name',
129
+ 'index' => 'name'
130
+ ));
131
+
132
+ return parent::_prepareColumns();
133
+ }
134
+
135
+ public function getGridUrl()
136
+ {
137
+ return $this->getUrl('*/*/product', array(
138
+ '_current' => true,
139
+ 'current_grid_id' => $this->getId(),
140
+ 'collapse' => null
141
+ ));
142
+ }
143
+
144
+ protected function _getSelectedProducts()
145
+ {
146
+ $products = $this->getRequest()->getPost('selected', array());
147
+
148
+ return $products;
149
+ }
150
+
151
+ /**
152
+ * set default limit
153
+ *
154
+ * @param $limit
155
+ * @return $this
156
+ */
157
+ public function setDefaultLimit($limit)
158
+ {
159
+ $this->_defaultLimit = $limit;
160
+ return $this;
161
+ }
162
+ }
163
+
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Wishlist.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Wishlist extends Mage_Adminhtml_Block_Widget_Grid_Container
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+
9
+ $this->_controller = 'adminhtml_wishlist';
10
+ $this->_blockGroup = 'ddg_automation';
11
+ $this->_headerText = Mage::helper('ddg')->__('Email Wishlist(s)');
12
+
13
+ $this->_removeButton('add');
14
+ }
15
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Wishlist/Grid.php ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Wishlist_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('id');
11
+ $this->setId('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 'ddg_automation/wishlist_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('wishlist_id', array(
45
+ 'header' => Mage::helper('ddg')->__('Wishlist ID'),
46
+ 'align' => 'left',
47
+ 'width' => '50px',
48
+ 'index' => 'wishlist_id',
49
+ 'type' => 'number',
50
+ 'escape' => true
51
+ ))->addColumn('item_count', array(
52
+ 'header' => Mage::helper('ddg')->__('Item Count'),
53
+ 'align' => 'left',
54
+ 'width' => '50px',
55
+ 'index' => 'item_count',
56
+ 'type' => 'number',
57
+ 'escape' => true
58
+ ))->addColumn('customer_id', array(
59
+ 'header' => Mage::helper('ddg')->__('Customer ID'),
60
+ 'align' => 'left',
61
+ 'width' => '50px',
62
+ 'index' => 'customer_id',
63
+ 'type' => 'number',
64
+ 'escape' => true
65
+ ))->addColumn('wishlist_imported', array(
66
+ 'header' => Mage::helper('ddg')->__('Wishlist Imported'),
67
+ 'align' => 'center',
68
+ 'width' => '50px',
69
+ 'index' => 'wishlist_imported',
70
+ 'type' => 'options',
71
+ 'escape' => true,
72
+ 'renderer' => 'ddg_automation/adminhtml_column_renderer_imported',
73
+ 'options' => Mage::getModel('ddg_automation/adminhtml_source_contact_imported')->getOptions(),
74
+ 'filter_condition_callback' => array($this, 'filterCallbackContact')
75
+ ))->addColumn('wishlist_modified', array(
76
+ 'header' => Mage::helper('ddg')->__('Wishlist Modified'),
77
+ 'align' => 'center',
78
+ 'width' => '50px',
79
+ 'index' => 'wishlist_modified',
80
+ 'type' => 'options',
81
+ 'escape' => true,
82
+ 'renderer' => 'ddg_automation/adminhtml_column_renderer_imported',
83
+ 'options' => Mage::getModel('ddg_automation/adminhtml_source_contact_imported')->getOptions(),
84
+ 'filter_condition_callback' => array($this, 'filterCallbackContact')
85
+ ))->addColumn('created_at', array(
86
+ 'header' => Mage::helper('ddg')->__('Created At'),
87
+ 'width' => '50px',
88
+ 'align' => 'center',
89
+ 'index' => 'created_at',
90
+ 'type' => 'datetime',
91
+ 'escape' => true,
92
+ ))->addColumn('updated_at', array(
93
+ 'header' => Mage::helper('ddg')->__('Updated At'),
94
+ 'width' => '50px',
95
+ 'align' => 'center',
96
+ 'index' => 'updated_at',
97
+ 'type' => 'datetime',
98
+ 'escape' => true,
99
+ ));
100
+
101
+ return parent::_prepareColumns();
102
+ }
103
+
104
+ /**
105
+ * Callback action for the imported subscribers/contacts.
106
+ *
107
+ * @param $collection
108
+ * @param $column
109
+ */
110
+ public function filterCallbackContact($collection, $column)
111
+ {
112
+ $field = $column->getFilterIndex() ? $column->getFilterIndex() : $column->getIndex();
113
+ $value = $column->getFilter()->getValue();
114
+ if ($value == 'null') {
115
+ $collection->addFieldToFilter($field, array('null' => true));
116
+ } else {
117
+ $collection->addFieldToFilter($field, array('notnull' => true));
118
+ }
119
+ }
120
+ }
app/code/community/Dotdigitalgroup/Email/Block/Basket.php ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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['quote_id']) && !isset($params['code'])){
19
+ Mage::helper('ddg')->log('Basket no quote id or code is set');
20
+ return false;
21
+ }
22
+
23
+ $quoteId = $params['quote_id'];
24
+ $quoteModel = Mage::getModel('sales/quote')->load($quoteId);
25
+
26
+ //check for any quote for this email, don't want to render further
27
+ if (! $quoteModel->getId()) {
28
+ Mage::helper('ddg')->log('no quote found for ');
29
+ return false;
30
+ }
31
+ if (! $quoteModel->getIsActive()) {
32
+ Mage::helper('ddg')->log('Cart is not active');
33
+ return false;
34
+ }
35
+
36
+ $this->_quote = $quoteModel;
37
+
38
+ //Start environment emulation of the specified store
39
+ $storeId = $quoteModel->getStoreId();
40
+ $appEmulation = Mage::getSingleton('core/app_emulation');
41
+ $appEmulation->startEnvironmentEmulation($storeId);
42
+
43
+ return $quoteModel->getAllItems();
44
+ }
45
+
46
+ /**
47
+ * Grand total.
48
+ *
49
+ * @return mixed
50
+ */
51
+ public function getGrandTotal()
52
+ {
53
+ return $this->_quote->getGrandTotal();
54
+
55
+ }
56
+ }
app/code/{local → community}/Dotdigitalgroup/Email/Block/Coupon.php RENAMED
@@ -2,39 +2,39 @@
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'];
12
- $authCode = $params['code'];
13
-
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
+ //throw new Exception('Coupon no id or code is set');
15
+ Mage::helper('ddg')->log('Coupon no id or code is set');
16
+ return false;
17
+ }
18
  //coupon rule id
19
  $couponCodeId = $params['id'];
 
 
 
 
20
 
21
+ if ($couponCodeId) {
22
 
23
  $rule = Mage::getModel('salesrule/rule')->load($couponCodeId);
24
  $generator = Mage::getModel('salesrule/coupon_massgenerator');
 
25
  $generator->setFormat( Mage_SalesRule_Helper_Coupon::COUPON_FORMAT_ALPHANUMERIC );
26
  $generator->setRuleId($couponCodeId);
27
  $generator->setUsesPerCoupon(1);
28
+ $generator->setDash(3);
29
+ $generator->setLength(9);
30
+ $generator->setPrefix('');
31
+ $generator->setSuffix('');
 
32
  //set the generation settings
33
  $rule->setCouponCodeGenerator($generator);
34
+ $rule->setCouponType(Mage_SalesRule_Model_Rule::COUPON_TYPE_AUTO);
 
35
  //generate the coupon
36
  $coupon = $rule->acquireCoupon();
37
  $couponCode = $coupon->getCode();
 
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);
app/code/community/Dotdigitalgroup/Email/Block/Customer/Account/Books.php ADDED
@@ -0,0 +1,217 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Customer_Account_Books extends Mage_Customer_Block_Account_Dashboard
4
+ {
5
+ private $_client;
6
+ private $contact_id;
7
+
8
+ /**
9
+ * subscription pref save url
10
+ *
11
+ * @return string
12
+ */
13
+ public function getSaveUrl()
14
+ {
15
+ return $this->getUrl('connector/customer_newsletter/save');
16
+ }
17
+
18
+ /**
19
+ * get config values
20
+ *
21
+ * @param $path
22
+ * @param $website
23
+ * @return mixed
24
+ */
25
+ private function _getWebsiteConfigFromHelper($path, $website)
26
+ {
27
+ return Mage::helper('ddg')->getWebsiteConfig($path, $website);
28
+ }
29
+
30
+ /**
31
+ * get api client
32
+ *
33
+ * @return Dotdigitalgroup_Email_Model_Apiconnector_Client
34
+ */
35
+ private function _getApiClient()
36
+ {
37
+ if(empty($this->_client)) {
38
+ $website = $this->getCustomer()->getStore()->getWebsite();
39
+ $client = Mage::getModel('ddg_automation/apiconnector_client');
40
+ $client->setApiUsername(Mage::helper('ddg')->getApiUsername($website))
41
+ ->setApiPassword(Mage::helper('ddg')->getApiPassword($website));
42
+ $this->_client = $client;
43
+ }
44
+ return $this->_client;
45
+ }
46
+
47
+ /**
48
+ * can show additional books?
49
+ *
50
+ * @return mixed
51
+ */
52
+ public function getCanShowAdditionalBooks()
53
+ {
54
+ return $this->_getWebsiteConfigFromHelper(
55
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_ADDRESSBOOK_PREF_CAN_CHANGE_BOOKS,
56
+ $this->getCustomer()->getStore()->getWebsite()
57
+ );
58
+ }
59
+
60
+ /**
61
+ * getter for additional books. Fully processed.
62
+ *
63
+ * @return array
64
+ */
65
+ public function getAdditionalBooksToShow()
66
+ {
67
+ $additionalBooksToShow = array();
68
+ $additionalFromConfig = $this->_getWebsiteConfigFromHelper(
69
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_ADDRESSBOOK_PREF_SHOW_BOOKS,
70
+ $this->getCustomer()->getStore()->getWebsite()
71
+ );
72
+
73
+ if(strlen($additionalFromConfig))
74
+ {
75
+ $additionalFromConfig = explode(',', $additionalFromConfig);
76
+ $this->getConnectorContact();
77
+ if($this->contact_id){
78
+ $addressBooks = $this->_getApiClient()->getContactAddressBooks($this->contact_id);
79
+ $processedAddressBooks = array();
80
+ if(is_array($addressBooks)){
81
+ foreach($addressBooks as $addressBook){
82
+ $processedAddressBooks[$addressBook->id] = $addressBook->name;
83
+ }
84
+ }
85
+ foreach($additionalFromConfig as $bookId){
86
+ $connectorBook = $this->_getApiClient()->getAddressBookById($bookId);
87
+ if(isset($connectorBook->id))
88
+ {
89
+ $subscribed = 0;
90
+ if(isset($processedAddressBooks[$bookId]))
91
+ $subscribed = 1;
92
+ $additionalBooksToShow[] = array(
93
+ "name" => $connectorBook->name,
94
+ "value" => $connectorBook->id,
95
+ "subscribed" => $subscribed
96
+ );
97
+ }
98
+ }
99
+ }
100
+ }
101
+ return $additionalBooksToShow;
102
+ }
103
+
104
+ /**
105
+ * can show data fields?
106
+ *
107
+ * @return mixed
108
+ */
109
+ public function getCanShowDataFields()
110
+ {
111
+ return $this->_getWebsiteConfigFromHelper(
112
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_ADDRESSBOOK_PREF_CAN_SHOW_FIELDS,
113
+ $this->getCustomer()->getStore()->getWebsite()
114
+ );
115
+ }
116
+
117
+ /**
118
+ * getter for data fields to show. Fully processed.
119
+ *
120
+ * @return array
121
+ */
122
+ public function getDataFieldsToShow()
123
+ {
124
+ $datafieldsToShow = array();
125
+ $dataFieldsFromConfig = $this->_getWebsiteConfigFromHelper(
126
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_ADDRESSBOOK_PREF_SHOW_FIELDS,
127
+ $this->getCustomer()->getStore()->getWebsite()
128
+ );
129
+ if(strlen($dataFieldsFromConfig))
130
+ {
131
+ $dataFieldsFromConfig = explode(',', $dataFieldsFromConfig);
132
+ $contact = $this->getConnectorContact();
133
+ if($this->contact_id)
134
+ {
135
+ $contactDataFields = $contact->dataFields;
136
+ $processedContactDataFields = array();
137
+ foreach($contactDataFields as $contactDataField){
138
+ $processedContactDataFields[$contactDataField->key] = $contactDataField->value;
139
+ }
140
+
141
+ $connectorDataFields = $this->_getApiClient()->getDataFields();
142
+ $processedConnectorDataFields = array();
143
+ foreach($connectorDataFields as $connectorDataField){
144
+ $processedConnectorDataFields[$connectorDataField->name] = $connectorDataField;
145
+ }
146
+ foreach($dataFieldsFromConfig as $dataFieldFromConfig){
147
+ if(isset($processedConnectorDataFields[$dataFieldFromConfig])){
148
+ $value = "";
149
+ $type = "";
150
+ if(isset($processedContactDataFields[$processedConnectorDataFields[$dataFieldFromConfig]->name])){
151
+ if($processedConnectorDataFields[$dataFieldFromConfig]->type == "Date"){
152
+ $type = "Date";
153
+ $value = $processedContactDataFields[$processedConnectorDataFields[$dataFieldFromConfig]->name];
154
+ $value = Mage::app()->getLocale()->date($value)->toString("Y/M/d");
155
+ }
156
+ else
157
+ $value = $processedContactDataFields[$processedConnectorDataFields[$dataFieldFromConfig]->name];
158
+ }
159
+
160
+ $datafieldsToShow[] = array(
161
+ 'name' => $processedConnectorDataFields[$dataFieldFromConfig]->name,
162
+ 'type' => $processedConnectorDataFields[$dataFieldFromConfig]->type,
163
+ 'value' => $value
164
+ );
165
+ }
166
+ }
167
+
168
+ }
169
+ }
170
+ return $datafieldsToShow;
171
+ }
172
+
173
+ /**
174
+ * find out if anything is true
175
+ *
176
+ * @return bool
177
+ */
178
+ public function canShowAnything()
179
+ {
180
+ if($this->getCanShowDataFields() or $this->getCanShowAdditionalBooks()){
181
+ $books = $this->getAdditionalBooksToShow();
182
+ $fields = $this->getDataFieldsToShow();
183
+ if(!empty($books) or !empty($fields))
184
+ return true;
185
+ }
186
+ return false;
187
+ }
188
+
189
+ /**
190
+ * get connector contact
191
+ *
192
+ * @return mixed
193
+ */
194
+ public function getConnectorContact()
195
+ {
196
+ $contact = $this->_getApiClient()->getContactByEmail($this->getCustomer()->getEmail());
197
+ if($contact->id){
198
+ $this->contact_id = $contact->id;
199
+ }else{
200
+ $contact = $this->_getApiClient()->postContacts($this->getCustomer()->getEmail());
201
+ if($contact->id){
202
+ $this->contact_id = $contact->id;
203
+ }
204
+ }
205
+ return $contact;
206
+ }
207
+
208
+ /**
209
+ * getter for contact id
210
+ *
211
+ * @return mixed
212
+ */
213
+ public function getConnectorContactId()
214
+ {
215
+ return $this->contact_id;
216
+ }
217
+ }
app/code/community/Dotdigitalgroup/Email/Block/Feefo.php ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ const FEEFO_URL = 'http://www.feefo.com/feefo/xmlfeed.jsp?';
4
+
5
+ class Dotdigitalgroup_Email_Block_Feefo extends Mage_Core_Block_Template
6
+ {
7
+ /**
8
+ * Prepare layout, set the template.
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
+ }
17
+
18
+ /**
19
+ * get customer's service score logo and output it
20
+ *
21
+ * @return string
22
+ */
23
+ public function getServiceScoreLogo()
24
+ {
25
+ $helper = Mage::helper('ddg');
26
+ $url = 'http://www.feefo.com/feefo/feefologo.jsp?logon=';
27
+ $logon = $helper->getFeefoLogon();
28
+ $template = '';
29
+ if($helper->getFeefoLogoTemplate())
30
+ $template = '&template=' . $helper->getFeefoLogoTemplate();
31
+ $fullUrl = $url . $logon . $template;
32
+ $vendorUrl = 'http://www.feefo.com/feefo/viewvendor.jsp?logon=' . $logon;
33
+
34
+ return
35
+ "<a href=$vendorUrl target='_blank'>
36
+ <img alt='Feefo logo' border='0' src=$fullUrl title='See what our customers say about us'>
37
+ </a>";
38
+ }
39
+
40
+ /**
41
+ * get quote products to show feefo reviews
42
+ *
43
+ * @return array
44
+ */
45
+ public function getQuoteProducts()
46
+ {
47
+ $products = array();
48
+ $quoteId = Mage::app()->getRequest()->getParam('quote_id');
49
+ $quoteModel = Mage::getModel('sales/quote')->load($quoteId);
50
+ if(!$quoteModel->getId())
51
+ die;
52
+
53
+ $quoteItems = $quoteModel->getAllItems();
54
+
55
+ if(count($quoteItems) == 0)
56
+ return array();
57
+
58
+ foreach($quoteItems as $item)
59
+ {
60
+ $productId = $item->getProductId();
61
+ $productModel = Mage::getModel('catalog/product')->load($productId);
62
+ if ($productModel->getId())
63
+ $products[$productModel->getSku()] = $productModel->getName();
64
+ }
65
+ return $products;
66
+ }
67
+
68
+ /**
69
+ * get product reviews from feefo
70
+ *
71
+ * @return array
72
+ */
73
+ public function getProductsReview()
74
+ {
75
+ $check = true;
76
+ $reviews = array();
77
+ $feefo_dir = Mage::getModel('core/config_options')->getLibDir().DS.'connector'.DS.'feefo';
78
+ $helper = Mage::helper('ddg');
79
+ $logon = $helper->getFeefoLogon();
80
+ $limit = $helper->getFeefoReviewsPerProduct();
81
+ $products = $this->getQuoteProducts();
82
+
83
+ foreach($products as $sku => $name)
84
+ {
85
+ $url = "http://www.feefo.com/feefo/xmlfeed.jsp?logon=" . $logon . "&limit=".$limit . "&vendorref=" . $sku . "&mode=productonly" ;
86
+ $doc = new DOMDocument();
87
+ $xsl = new XSLTProcessor();
88
+ if($check)
89
+ $doc->load($feefo_dir. DS ."feedback.xsl");
90
+ else
91
+ $doc->load($feefo_dir. DS ."feedback-no-th.xsl");
92
+ $xsl->importStyleSheet($doc);
93
+ $doc->load($url);
94
+ $productReview = $xsl->transformToXML($doc);
95
+ if(strpos($productReview, '<td'))
96
+ $reviews[$name] = $xsl->transformToXML($doc);
97
+ $check = false;
98
+ }
99
+ return $reviews;
100
+ }
101
+ }
app/code/community/Dotdigitalgroup/Email/Block/Order.php ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ if(!$orderId)
33
+ return false;
34
+ Mage::unregister('order_id'); // additional measure
35
+ Mage::register('order_id', $orderId);
36
+ }
37
+ if (! $order) {
38
+ if(!$orderId)
39
+ return false;
40
+ $order = Mage::getModel('sales/order')->load($orderId);
41
+ Mage::unregister('current_order'); // additional measure
42
+ Mage::register('current_order', $order);
43
+ }
44
+
45
+ return $order;
46
+ }
47
+
48
+ /**
49
+ * Filter items for review. If a customer has already placed a review for a product then exclude the product.
50
+ *
51
+ * @param array $items
52
+ * @param int $websiteId
53
+ * @return mixed
54
+ */
55
+ public function filterItemsForReview($items, $websiteId)
56
+ {
57
+ if (!count($items))
58
+ return;
59
+
60
+ $order = $this->getOrder();
61
+
62
+ //if customer is guest then no need to filter any items
63
+ if($order->getCustomerIsGuest())
64
+ return $items;
65
+
66
+ if(!Mage::helper('ddg/review')->isNewProductOnly($websiteId))
67
+ return $items;
68
+
69
+ $customerId = $order->getCustomerId();
70
+
71
+ foreach($items as $key => $item)
72
+ {
73
+ $productId = $item->getProduct()->getId();
74
+
75
+ $collection = Mage::getModel('review/review')->getCollection();
76
+ $collection->addCustomerFilter($customerId)
77
+ ->addStoreFilter($order->getStoreId())
78
+ ->addFieldToFilter('main_table.entity_pk_value', $productId);
79
+
80
+ //remove item if customer has already placed review on this item
81
+ if($collection->getSize())
82
+ unset($items[$key]);
83
+ }
84
+
85
+ return $items;
86
+ }
87
+ }
app/code/community/Dotdigitalgroup/Email/Block/Order/Creditmemo.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Sales_Model_Order
19
+ * @throws Exception
20
+ */
21
+ public function getOrder()
22
+ {
23
+ $orderId = Mage::registry('order_id');
24
+ $order = Mage::registry('current_order');
25
+ if (! $orderId) {
26
+ $orderId = Mage::app()->getRequest()->getParam('order_id');
27
+ Mage::register('order_id', $orderId);
28
+ }
29
+ if (! $order) {
30
+ $order = Mage::getModel('sales/order')->load($orderId);
31
+ Mage::register('current_order', $order);
32
+ }
33
+ if (! $order->hasCreditmemos()) {
34
+ //throw new Exception('TE - no creditmemo for order : '. $orderId);
35
+ Mage::helper('ddg')->log('TE - no creditmemo for order : '. $orderId);
36
+ return false;
37
+ }
38
+
39
+ return $order;
40
+ }
41
+
42
+ /**
43
+ * Order items.
44
+ * @return mixed
45
+ */
46
+ public function getCreditmemoItems()
47
+ {
48
+ return Mage::registry('current_order')->getItemsCollection();
49
+ }
50
+ }
app/code/community/Dotdigitalgroup/Email/Block/Order/Invoice.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Sales_Model_Order
18
+ * @throws Exception
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
+ if(!$orderId)
27
+ return false;
28
+ Mage::register('order_id', $orderId);
29
+ }
30
+ if (! $order) {
31
+ if(!$orderId)
32
+ return false;
33
+ $order = Mage::getModel('sales/order')->load($orderId);
34
+ Mage::register('current_order', $order);
35
+ }
36
+ if (! $order->hasInvoices()) {
37
+ //throw new Exception('TE - no invoice for order : '. $orderId);
38
+ Mage::helper('ddg')->log('TE - no invoice for order : '. $orderId);
39
+ return false;
40
+ }
41
+
42
+ return $order;
43
+ }
44
+
45
+ }
app/code/community/Dotdigitalgroup/Email/Block/Order/Shipping.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * @return Mage_Sales_Model_Order
17
+ * @throws Exception
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
+ if(!$orderId)
26
+ return false;
27
+ Mage::register('order_id', $orderId);
28
+ }
29
+ if (! $order) {
30
+ if(!$orderId)
31
+ return false;
32
+ $order = Mage::getModel('sales/order')->load($orderId);
33
+ Mage::register('current_order', $order);
34
+ }
35
+ if (! $order->hasShipments()) {
36
+ //throw new Exception('TE - no shipments for order : '. $orderId);
37
+ Mage::helper('ddg')->log('TE - no shipments for order : '. $orderId);
38
+ return false;
39
+ }
40
+
41
+ return $order;
42
+
43
+ }
44
+
45
+ }
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('ddg_automation/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('ddg/recommended')->getDisplayType();
65
+
66
+ }
67
+ }
app/code/community/Dotdigitalgroup/Email/Block/Recommended/Bestsellers.php ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $mode = $this->getRequest()->getActionName();
25
+ $limit = Mage::helper('ddg/recommended')->getDisplayLimitByMode($mode);
26
+ $from = Mage::helper('ddg/recommended')->getTimeFromConfig($mode);
27
+ $to = Zend_Date::now()->toString(Zend_Date::ISO_8601);
28
+
29
+ $productCollection = Mage::getResourceModel('reports/product_collection')
30
+ ->addAttributeToSelect('*')
31
+ ->addOrderedQty($from, $to)
32
+ ->setOrder('ordered_qty', 'desc')
33
+ ->setPageSize($limit);
34
+
35
+ Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($productCollection);
36
+ $productCollection->addAttributeToFilter('is_saleable', TRUE);
37
+
38
+ //filter collection by category by category_id
39
+ if($cat_id = Mage::app()->getRequest()->getParam('category_id')){
40
+ $category = Mage::getModel('catalog/category')->load($cat_id);
41
+ if($category->getId()){
42
+ $productCollection->getSelect()
43
+ ->joinLeft(
44
+ array("ccpi" => 'catalog_category_product_index'),
45
+ "e.entity_id = ccpi.product_id",
46
+ array("category_id")
47
+ )
48
+ ->where('ccpi.category_id =?', $cat_id);
49
+ }else{
50
+ Mage::helper('ddg')->log('Best seller. Category id '. $cat_id . ' is invalid. It does not exist.');
51
+ }
52
+ }
53
+
54
+ //filter collection by category by category_name
55
+ if($cat_name = Mage::app()->getRequest()->getParam('category_name')){
56
+ $category = Mage::getModel('catalog/category')->loadByAttribute('name', $cat_name);
57
+ if($category){
58
+ $productCollection->getSelect()
59
+ ->joinLeft(
60
+ array("ccpi" => 'catalog_category_product_index'),
61
+ "e.entity_id = ccpi.product_id",
62
+ array("category_id")
63
+ )
64
+ ->where('ccpi.category_id =?', $category->getId());
65
+ }else{
66
+ Mage::helper('ddg')->log('Best seller. Category name '. $cat_name .' is invalid. It does not exist.');
67
+ }
68
+ }
69
+ return $productCollection;
70
+ }
71
+
72
+ /**
73
+ * Display type mode.
74
+ *
75
+ * @return mixed|string
76
+ */
77
+ public function getMode()
78
+ {
79
+ return Mage::helper('ddg/recommended')->getDisplayType();
80
+
81
+ }
82
+
83
+ /**
84
+ * Price html.
85
+ * @param $product
86
+ *
87
+ * @return string
88
+ */
89
+ public function getPriceHtml($product)
90
+ {
91
+ $this->setTemplate('connector/product/price.phtml');
92
+ $this->setProduct($product);
93
+ return $this->toHtml();
94
+ }
95
+
96
+ }
app/code/community/Dotdigitalgroup/Email/Block/Recommended/Mostviewed.php ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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('ddg/recommended')->getDisplayLimitByMode($mode);
27
+ $from = Mage::helper('ddg/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
+ //filter collection by category by category_id
36
+ if($cat_id = Mage::app()->getRequest()->getParam('category_id')){
37
+ $category = Mage::getModel('catalog/category')->load($cat_id);
38
+ if($category->getId()){
39
+ $productCollection->getSelect()
40
+ ->joinLeft(
41
+ array("ccpi" => 'catalog_category_product_index'),
42
+ "e.entity_id = ccpi.product_id",
43
+ array("category_id")
44
+ )
45
+ ->where('ccpi.category_id =?', $cat_id);
46
+ }else{
47
+ Mage::helper('ddg')->log('Most viewed. Category id '. $cat_id . ' is invalid. It does not exist.');
48
+ }
49
+ }
50
+
51
+ //filter collection by category by category_name
52
+ if($cat_name = Mage::app()->getRequest()->getParam('category_name')){
53
+ $category = Mage::getModel('catalog/category')->loadByAttribute('name', $cat_name);
54
+ if($category){
55
+ $productCollection->getSelect()
56
+ ->joinLeft(
57
+ array("ccpi" => 'catalog_category_product_index'),
58
+ "e.entity_id = ccpi.product_id",
59
+ array("category_id")
60
+ )
61
+ ->where('ccpi.category_id =?', $category->getId());
62
+ }else{
63
+ Mage::helper('ddg')->log('Most viewed. Category name '. $cat_name .' is invalid. It does not exist.');
64
+ }
65
+ }
66
+
67
+ foreach ($productCollection as $_product) {
68
+ $productId = $_product->getId();
69
+ $product = Mage::getModel('catalog/product')->load($productId);
70
+ if($product->isSalable())
71
+ $productsToDisplay[] = $product;
72
+ }
73
+
74
+ return $productsToDisplay;
75
+ }
76
+
77
+
78
+ /**
79
+ * Display mode type.
80
+ * @return mixed|string
81
+ */
82
+ public function getMode()
83
+ {
84
+ return Mage::helper('ddg/recommended')->getDisplayType();
85
+ }
86
+
87
+ /**
88
+ * @param $product
89
+ *
90
+ * @return string
91
+ */
92
+ public function getPriceHtml($product)
93
+ {
94
+ $this->setTemplate('connector/product/price.phtml');
95
+ $this->setProduct($product);
96
+ return $this->toHtml();
97
+ }
98
+ }
app/code/community/Dotdigitalgroup/Email/Block/Recommended/Products.php ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Recommended_Products extends Mage_Core_Block_Template
4
+ {
5
+ /**
6
+ * Slot div name.
7
+ * @var string
8
+ */
9
+ public $slot;
10
+
11
+ /**
12
+ * Prepare layout, set the template.
13
+ * @return Mage_Core_Block_Abstract|void
14
+ */
15
+ protected function _prepareLayout()
16
+ {
17
+ if ($root = $this->getLayout()->getBlock('root')) {
18
+ $root->setTemplate('page/blank.phtml');
19
+ }
20
+ }
21
+
22
+ /**
23
+ * get the products to display for table
24
+ */
25
+ public function getLoadedProductCollection()
26
+ {
27
+ //products to be diplayd for recommended pages
28
+ $productsToDisplay = array();
29
+ $orderId = $this->getRequest()->getParam('order_id');
30
+ //display mode based on the action name
31
+ $mode = $this->getRequest()->getActionName();
32
+ $orderModel = Mage::getModel('sales/order')->load($orderId);
33
+ //number of product items to be displayed
34
+ $limit = Mage::helper('ddg/recommended')->getDisplayLimitByMode($mode);
35
+ $orderItems = $orderModel->getAllItems();
36
+ $numItems = count($orderItems);
37
+
38
+ //no product found to display
39
+ if ($numItems == 0 || ! $limit) {
40
+ return array();
41
+ }elseif (count($orderItems) > $limit) {
42
+ $maxPerChild = 1;
43
+ } else {
44
+ $maxPerChild = number_format($limit / count($orderItems));
45
+ }
46
+
47
+ Mage::helper('ddg')->log('DYNAMIC PRODUCTS : limit ' . $limit . ' products : ' . $numItems . ', max per child : '. $maxPerChild);
48
+
49
+ foreach ($orderItems as $item) {
50
+ $i = 0;
51
+ $productId = $item->getProductId();
52
+ //parent product
53
+ $productModel = Mage::getModel('catalog/product')->load($productId);
54
+ //check for product exists
55
+ if ($productModel->getId()) {
56
+ //get single product for current mode
57
+ $recommendedProducts = $this->_getRecommendedProduct($productModel, $mode);
58
+ foreach ($recommendedProducts as $product) {
59
+ //load child product
60
+ $product = Mage::getModel('catalog/product')->load($product->getId());
61
+ //check if still exists
62
+ if ($product->getId() && count($productsToDisplay) < $limit && $i <= $maxPerChild && $product->isSaleable() && !$product->getParentId()) {
63
+ //we have a product to display
64
+ $productsToDisplay[$product->getId()] = $product;
65
+ $i++;
66
+ }
67
+ }
68
+ }
69
+ //have reached the limit don't loop for more
70
+ if (count($productsToDisplay) == $limit) {
71
+ break;
72
+ }
73
+ }
74
+
75
+ //check for more space to fill up the table with fallback products
76
+ if (count($productsToDisplay) < $limit) {
77
+ $fallbackIds = Mage::helper('ddg/recommended')->getFallbackIds();
78
+
79
+ foreach ($fallbackIds as $productId) {
80
+ $product = Mage::getModel('catalog/product')->load($productId);
81
+ if($product->isSaleable())
82
+ $productsToDisplay[$product->getId()] = $product;
83
+ //stop the limit was reached
84
+ if (count($productsToDisplay) == $limit) {
85
+ break;
86
+ }
87
+ }
88
+ }
89
+
90
+ Mage::helper('ddg')->log('loaded product to display ' . count($productsToDisplay));
91
+ return $productsToDisplay;
92
+ }
93
+
94
+ /**
95
+ * Product related items.
96
+ *
97
+ * @param Mage_Catalog_Model_Product $productModel
98
+ * @param $mode
99
+ *
100
+ * @return array
101
+ */
102
+ private function _getRecommendedProduct(Mage_Catalog_Model_Product $productModel, $mode)
103
+ {
104
+ //array of products to display
105
+ $products = array();
106
+ switch($mode){
107
+ case 'related':
108
+ $products = $productModel->getRelatedProducts();
109
+ break;
110
+ case 'upsell':
111
+ $products = $productModel->getUpSellProducts();
112
+ break;
113
+ case 'crosssell':
114
+ $products = $productModel->getCrossSellProducts();
115
+ break;
116
+
117
+ }
118
+
119
+ return $products;
120
+ }
121
+
122
+ /**
123
+ * Diplay mode type.
124
+ *
125
+ * @return mixed|string
126
+ */
127
+ public function getMode()
128
+ {
129
+ return Mage::helper('ddg/recommended')->getDisplayType();
130
+
131
+ }
132
+
133
+ /**
134
+ * Number of the colums.
135
+ * @return int|mixed
136
+ * @throws Exception
137
+ */
138
+ public function getColumnCount()
139
+ {
140
+ return Mage::helper('ddg/recommended')->getDisplayLimitByMode($this->getRequest()->getActionName());
141
+ }
142
+
143
+ /**
144
+ * Price html.
145
+ * @param $product
146
+ *
147
+ * @return string
148
+ */
149
+ public function getPriceHtml($product)
150
+ {
151
+ $this->setTemplate('connector/product/price.phtml');
152
+ $this->setProduct($product);
153
+ return $this->toHtml();
154
+ }
155
+
156
+
157
+ /**
158
+ * Nosto products data.
159
+ * @return object
160
+ */
161
+ public function getNostoProducts()
162
+ {
163
+ $client = Mage::getModel('ddg_automation/apiconnector_client');
164
+ //slot name, div id
165
+ $slot = Mage::app()->getRequest()->getParam('slot', false);
166
+
167
+ //email recommendation
168
+ $email = Mage::app()->getRequest()->getParam('email', false);
169
+
170
+ //no valid data for nosto recommendation
171
+ if (!$slot || ! $email)
172
+ return false;
173
+ else
174
+ $this->slot = $slot;
175
+
176
+ //html data from nosto
177
+ $data = $client->getNostoProducts($slot, $email);
178
+
179
+ //check for valid response
180
+ if (! isset($data->$email) && !isset($data->$email->$slot))
181
+ return false;
182
+ return $data->$email->$slot;
183
+ }
184
+
185
+ /**
186
+ * Slot name.
187
+ * Should be called after getNostoProducts.
188
+ * @return string
189
+ */
190
+ public function getSlotName()
191
+ {
192
+ return $this->slot;
193
+ }
194
+ }
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('ddg/recommended')->getDisplayLimitByMode($mode);
24
+
25
+ $productIds = Mage::helper('ddg/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('ddg/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/Quoteproducts.php ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Recommended_Quoteproducts 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
+ $quoteId = $this->getRequest()->getParam('quote_id');
24
+ //display mode based on the action name
25
+ $mode = $this->getRequest()->getActionName();
26
+ $quoteModel = Mage::getModel('sales/quote')->load($quoteId);
27
+ //number of product items to be displayed
28
+ $limit = Mage::helper('ddg/recommended')->getDisplayLimitByMode($mode);
29
+ $quoteItems = $quoteModel->getAllItems();
30
+ $numItems = count($quoteItems);
31
+
32
+ //no product found to display
33
+ if ($numItems == 0 || ! $limit) {
34
+ return array();
35
+ }elseif (count($quoteItems) > $limit) {
36
+ $maxPerChild = 1;
37
+ } else {
38
+ $maxPerChild = number_format($limit / count($quoteItems));
39
+ }
40
+
41
+ Mage::helper('ddg')->log('DYNAMIC QUOTE PRODUCTS : limit ' . $limit . ' products : ' . $numItems . ', max per child : '. $maxPerChild);
42
+
43
+ foreach ($quoteItems 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('ddg/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('ddg')->log('quote - 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('ddg/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('ddg/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/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('ddg/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('ddg')->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('ddg/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/Block/Recommended/Wishlistproducts.php ADDED
@@ -0,0 +1,176 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Recommended_Wishlistproducts 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
+ protected function _getWishlistItems()
17
+ {
18
+ $wishlist = $this->_getWishlist();
19
+ if($wishlist && count($wishlist->getItemCollection()))
20
+ return $wishlist->getItemCollection();
21
+ else
22
+ return array();
23
+ }
24
+
25
+ protected function _getWishlist()
26
+ {
27
+ $customerId = Mage::app()->getRequest()->getParam('customer_id');
28
+ if(!$customerId)
29
+ return array();
30
+
31
+ $customer = Mage::getModel('customer/customer')->load($customerId);
32
+ if(!$customer->getId())
33
+ return array();
34
+
35
+ $collection = Mage::getModel('wishlist/wishlist')->getCollection();
36
+ $collection->addFieldToFilter('customer_id', $customerId)
37
+ ->setOrder('updated_at', 'DESC');
38
+
39
+ if ($collection->count())
40
+ return $collection->getFirstItem();
41
+ else
42
+ return array();
43
+
44
+ }
45
+
46
+ /**
47
+ * get the products to display for table
48
+ */
49
+ public function getLoadedProductCollection()
50
+ {
51
+ //products to be display for recommended pages
52
+ $productsToDisplay = array();
53
+ //display mode based on the action name
54
+ $mode = $this->getRequest()->getActionName();
55
+ //number of product items to be displayed
56
+ $limit = Mage::helper('ddg/recommended')->getDisplayLimitByMode($mode);
57
+ $items = $this->_getWishlistItems();
58
+ $numItems = count($items);
59
+
60
+ //no product found to display
61
+ if ($numItems == 0 || ! $limit) {
62
+ return array();
63
+ }elseif (count($items) > $limit) {
64
+ $maxPerChild = 1;
65
+ } else {
66
+ $maxPerChild = number_format($limit / count($items));
67
+ }
68
+
69
+ Mage::helper('ddg')->log('DYNAMIC WISHLIST PRODUCTS : limit ' . $limit . ' products : ' . $numItems . ', max per child : '. $maxPerChild);
70
+
71
+ foreach ($items as $item) {
72
+ $i = 0;
73
+ //parent product
74
+ $product = $item->getProduct();
75
+ //check for product exists
76
+ if ($product->getId()) {
77
+ //get single product for current mode
78
+ $recommendedProducts = $this->_getRecommendedProduct($product, $mode);
79
+ foreach ($recommendedProducts as $product) {
80
+ //load child product
81
+ $product = Mage::getModel('catalog/product')->load($product->getId());
82
+ //check if still exists
83
+ if ($product->getId() && count($productsToDisplay) < $limit && $i <= $maxPerChild && $product->isSaleable() && !$product->getParentId()) {
84
+ //we have a product to display
85
+ $productsToDisplay[$product->getId()] = $product;
86
+ $i++;
87
+ }
88
+ }
89
+ }
90
+ //have reached the limit don't loop for more
91
+ if (count($productsToDisplay) == $limit) {
92
+ break;
93
+ }
94
+ }
95
+
96
+ //check for more space to fill up the table with fallback products
97
+ if (count($productsToDisplay) < $limit) {
98
+ $fallbackIds = Mage::helper('ddg/recommended')->getFallbackIds();
99
+
100
+ foreach ($fallbackIds as $productId) {
101
+ $product = Mage::getModel('catalog/product')->load($productId);
102
+ if($product->isSaleable())
103
+ $productsToDisplay[$product->getId()] = $product;
104
+ //stop the limit was reached
105
+ if (count($productsToDisplay) == $limit) {
106
+ break;
107
+ }
108
+ }
109
+ }
110
+
111
+ Mage::helper('ddg')->log('wishlist - loaded product to display ' . count($productsToDisplay));
112
+ return $productsToDisplay;
113
+ }
114
+
115
+ /**
116
+ * Product related items.
117
+ *
118
+ * @param Mage_Catalog_Model_Product $productModel
119
+ * @param $mode
120
+ *
121
+ * @return array
122
+ */
123
+ private function _getRecommendedProduct(Mage_Catalog_Model_Product $productModel, $mode)
124
+ {
125
+ //array of products to display
126
+ $products = array();
127
+ switch($mode){
128
+ case 'related':
129
+ $products = $productModel->getRelatedProducts();
130
+ break;
131
+ case 'upsell':
132
+ $products = $productModel->getUpSellProducts();
133
+ break;
134
+ case 'crosssell':
135
+ $products = $productModel->getCrossSellProducts();
136
+ break;
137
+
138
+ }
139
+
140
+ return $products;
141
+ }
142
+
143
+ /**
144
+ * Diplay mode type.
145
+ *
146
+ * @return mixed|string
147
+ */
148
+ public function getMode()
149
+ {
150
+ return Mage::helper('ddg/recommended')->getDisplayType();
151
+
152
+ }
153
+
154
+ /**
155
+ * Number of the colums.
156
+ * @return int|mixed
157
+ * @throws Exception
158
+ */
159
+ public function getColumnCount()
160
+ {
161
+ return Mage::helper('ddg/recommended')->getDisplayLimitByMode($this->getRequest()->getActionName());
162
+ }
163
+
164
+ /**
165
+ * Price html.
166
+ * @param $product
167
+ *
168
+ * @return string
169
+ */
170
+ public function getPriceHtml($product)
171
+ {
172
+ $this->setTemplate('ddg/product/price.phtml');
173
+ $this->setProduct($product);
174
+ return $this->toHtml();
175
+ }
176
+ }
app/code/community/Dotdigitalgroup/Email/Block/System/Email/Template/Edit.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_System_Email_Template_Edit extends Mage_Adminhtml_Block_System_Email_Template_Edit
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+ $this->setTemplate('connector/system/email/template/edit.phtml');
9
+ }
10
+
11
+ public function getConnectorTemplates()
12
+ {
13
+ return Mage::helper('ddg')->getTemplateList();
14
+ }
15
+ }
app/code/community/Dotdigitalgroup/Email/Block/Wishlist.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Wishlist extends Mage_Core_Block_Template
4
+ {
5
+ protected $_website;
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
+
17
+ public function getWishlistItems()
18
+ {
19
+ $wishlist = $this->_getWishlist();
20
+ if($wishlist && count($wishlist->getItemCollection()))
21
+ return $wishlist->getItemCollection();
22
+ else
23
+ return false;
24
+ }
25
+
26
+ protected function _getWishlist()
27
+ {
28
+ $customerId = Mage::app()->getRequest()->getParam('customer_id');
29
+ if(!$customerId)
30
+ return false;
31
+
32
+ $customer = Mage::getModel('customer/customer')->load($customerId);
33
+ if(!$customer->getId())
34
+ return false;
35
+
36
+ $collection = Mage::getModel('wishlist/wishlist')->getCollection();
37
+ $collection->addFieldToFilter('customer_id', $customerId)
38
+ ->setOrder('updated_at', 'DESC');
39
+
40
+ if ($collection->count())
41
+ return $collection->getFirstItem();
42
+ else
43
+ return false;
44
+
45
+ }
46
+
47
+ public function getMode()
48
+ {
49
+ return Mage::helper('ddg')->getWebsiteConfig(
50
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DYNAMIC_CONTENT_WIHSLIST_DISPLAY
51
+ );
52
+ }
53
+ }
app/code/community/Dotdigitalgroup/Email/Helper/Config.php ADDED
@@ -0,0 +1,323 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
15
+ /**
16
+ * SMS SECTION.
17
+ */
18
+ //enabled
19
+ const XML_PATH_CONNECTOR_SMS_ENABLED_1 = 'connector_sms/sms_one/enabled';
20
+ const XML_PATH_CONNECTOR_SMS_ENABLED_2 = 'connector_sms/sms_two/enabled';
21
+ const XML_PATH_CONNECTOR_SMS_ENABLED_3 = 'connector_sms/sms_three/enabled';
22
+ const XML_PATH_CONNECTOR_SMS_ENABLED_4 = 'connector_sms/sms_four/enabled';
23
+ //status
24
+ const XML_PATH_CONNECTOR_SMS_STATUS_1 = 'connector_sms/sms_one/status';
25
+ const XML_PATH_CONNECTOR_SMS_STATUS_2 = 'connector_sms/sms_two/status';
26
+ const XML_PATH_CONNECTOR_SMS_STATUS_3 = 'connector_sms/sms_three/status';
27
+ const XML_PATH_CONNECTOR_SMS_STATUS_4 = 'connector_sms/sms_four/status';
28
+ //message
29
+ const XML_PATH_CONNECTOR_SMS_MESSAGE_1 = 'connector_sms/sms_one/message';
30
+ const XML_PATH_CONNECTOR_SMS_MESSAGE_2 = 'connector_sms/sms_two/message';
31
+ const XML_PATH_CONNECTOR_SMS_MESSAGE_3 = 'connector_sms/sms_three/message';
32
+ const XML_PATH_CONNECTOR_SMS_MESSAGE_4 = 'connector_sms/sms_four/message';
33
+
34
+ /**
35
+ * SYNC SECTION.
36
+ */
37
+ const XML_PATH_CONNECTOR_SYNC_CONTACT_ENABLED = 'connector_sync_settings/sync/contact_enabled';
38
+ const XML_PATH_CONNECTOR_SYNC_SUBSCRIBER_ENABLED = 'connector_sync_settings/sync/subscriber_enabled';
39
+ const XML_PATH_CONNECTOR_SYNC_ORDER_ENABLED = 'connector_sync_settings/sync/order_enabled';
40
+ const XML_PATH_CONNECTOR_SYNC_WISHLIST_ENABLED = 'connector_sync_settings/sync/wishlist_enabled';
41
+ const XML_PATH_CONNECTOR_SYNC_REVIEW_ENABLED = 'connector_sync_settings/sync/review_enabled';
42
+ const XML_PATH_CONNECTOR_SYNC_QUOTE_ENABLED = 'connector_sync_settings/sync/quote_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_LAST_QUOTE_ID = 'connector_data_mapping/customer_data/last_quote_id';
50
+ const XML_PATH_CONNECTOR_MAPPING_CUSTOMER_ID = 'connector_data_mapping/customer_data/customer_id';
51
+ const XML_PATH_CONNECTOR_MAPPING_CUSTOM_DATAFIELDS = 'connector_data_mapping/customer_data/custom_attributes';
52
+ const XML_PATH_CONNECTOR_MAPPING_CUSTOMER_STORENAME = 'connector_data_mapping/customer_data/store_name';
53
+ const XML_PATH_CONNECTOR_MAPPING_CUSTOMER_TOTALREFUND = 'connector_data_mapping/customer_data/total_refund';
54
+ const XML_PATH_CONNECTOR_MAPPING_SWEETTOOTH_ACTIVE = 'connector_data_mapping/sweet_tooth/active';
55
+
56
+ // Address Book Pref
57
+ const XML_PATH_CONNECTOR_ADDRESSBOOK_PREF_CAN_CHANGE_BOOKS = 'connector_sync_settings/address_book_pref/can_change';
58
+ const XML_PATH_CONNECTOR_ADDRESSBOOK_PREF_SHOW_BOOKS = 'connector_sync_settings/address_book_pref/show_books';
59
+ const XML_PATH_CONNECTOR_ADDRESSBOOK_PREF_CAN_SHOW_FIELDS = 'connector_sync_settings/address_book_pref/can_show_fields';
60
+ const XML_PATH_CONNECTOR_ADDRESSBOOK_PREF_SHOW_FIELDS = 'connector_sync_settings/address_book_pref/fields_to_show';
61
+
62
+ /**
63
+ * Abandoned Carts.
64
+ */
65
+ const XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CARTS_ENABLED_1 = 'connector_lost_baskets/customers/enabled_1';
66
+ const XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CAMPAIGN_1 = 'connector_lost_baskets/customers/campaign_1';
67
+ const XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CARTS_ENABLED_2 = 'connector_lost_baskets/customers/enabled_2';
68
+ const XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CAMPAIGN_2 = 'connector_lost_baskets/customers/campaign_2';
69
+ const XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CARTS_ENABLED_3 = 'connector_lost_baskets/customers/enabled_3';
70
+ const XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CAMPAIGN_3 = 'connector_lost_baskets/customers/campaign_3';
71
+ const XML_PATH_CONNECTOR_GUEST_ABANDONED_CARTS_ENABLED_1 = 'connector_lost_baskets/guests/enabled_1';
72
+ const XML_PATH_CONNECTOR_GUEST_ABANDONED_CAMPAIGN_1 = 'connector_lost_baskets/guests/campaign_1';
73
+ const XML_PATH_CONNECTOR_GUEST_ABANDONED_CARTS_ENABLED_2 = 'connector_lost_baskets/guests/enabled_2';
74
+ const XML_PATH_CONNECTOR_GUEST_ABANDONED_CAMPAIGN_2 = 'connector_lost_baskets/guests/campaign_2';
75
+ const XML_PATH_CONNECTOR_GUEST_ABANDONED_CARTS_ENABLED_3 = 'connector_lost_baskets/guests/enabled_3';
76
+ const XML_PATH_CONNECTOR_GUEST_ABANDONED_CAMPAIGN_3 = 'connector_lost_baskets/guests/campaign_3';
77
+
78
+ /**
79
+ * Datafields Mapping.
80
+ */
81
+ const XML_PATH_CONNECTOR_CUSTOMER_ID = 'connector_data_mapping/customer_data/customer_id';
82
+ const XML_PATH_CONNECTOR_CUSTOMER_FIRSTNAME = 'connector_data_mapping/customer_data/firstname';
83
+ const XML_PATH_CONNECTOR_CUSTOMER_LASTNAME = 'connector_data_mapping/customer_data/lastname';
84
+ const XML_PATH_CONNECTOR_CUSTOMER_DOB = 'connector_data_mapping/customer_data/dob';
85
+ const XML_PATH_CONNECTOR_CUSTOMER_GENDER = 'connector_data_mapping/customer_data/gender';
86
+ const XML_PATH_CONNECTOR_CUSTOMER_WEBSITE_NAME = 'connector_data_mapping/customer_data/website_name';
87
+ const XML_PATH_CONNECTOR_CUSTOMER_STORE_NAME = 'connector_data_mapping/customer_data/store_name';
88
+ const XML_PATH_CONNECTOR_CUSTOMER_CREATED_AT = 'connector_data_mapping/customer_data/created_at';
89
+ const XML_PATH_CONNECTOR_CUSTOMER_LAST_LOGGED_DATE = 'connector_data_mapping/customer_data/last_logged_date';
90
+ const XML_PATH_CONNECTOR_CUSTOMER_CUSTOMER_GROUP = 'connector_data_mapping/customer_data/customer_group';
91
+ const XML_PATH_CONNECTOR_CUSTOMER_REVIEW_COUNT = 'connector_data_mapping/customer_data/review_count';
92
+ const XML_PATH_CONNECTOR_CUSTOMER_LAST_REVIEW_DATE = 'connector_data_mapping/customer_data/last_review_date';
93
+ const XML_PATH_CONNECTOR_CUSTOMER_BILLING_ADDRESS_1 = 'connector_data_mapping/customer_data/billing_address_1';
94
+ const XML_PATH_CONNECTOR_CUSTOMER_BILLING_ADDRESS_2 = 'connector_data_mapping/customer_data/billing_address_2';
95
+ const XML_PATH_CONNECTOR_CUSTOMER_BILLING_CITY = 'connector_data_mapping/customer_data/billing_city';
96
+ const XML_PATH_CONNECTOR_CUSTOMER_BILLING_STATE = 'connector_data_mapping/customer_data/billing_state';
97
+ const XML_PATH_CONNECTOR_CUSTOMER_BILLING_COUNTRY = 'connector_data_mapping/customer_data/billing_country';
98
+ const XML_PATH_CONNECTOR_CUSTOMER_BILLING_POSTCODE = 'connector_data_mapping/customer_data/billing_postcode';
99
+ const XML_PATH_CONNECTOR_CUSTOMER_BILLING_TELEPHONE = 'connector_data_mapping/customer_data/billing_telephone';
100
+ const XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_ADDRESS_1 = 'connector_data_mapping/customer_data/delivery_address_1';
101
+ const XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_ADDRESS_2 = 'connector_data_mapping/customer_data/delivery_address_2';
102
+ const XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_CITY = 'connector_data_mapping/customer_data/delivery_city';
103
+ const XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_STATE = 'connector_data_mapping/customer_data/delivery_state';
104
+ const XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_COUNTRY = 'connector_data_mapping/customer_data/delivery_country';
105
+ const XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_POSTCODE = 'connector_data_mapping/customer_data/delivery_postcode';
106
+ const XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_TELEPHONE = 'connector_data_mapping/customer_data/delivery_telephone';
107
+ const XML_PATH_CONNECTOR_CUSTOMER_TOTAL_NUMBER_ORDER = 'connector_data_mapping/customer_data/number_of_orders';
108
+ const XML_PATH_CONNECTOR_CUSTOMER_AOV = 'connector_data_mapping/customer_data/average_order_value';
109
+ const XML_PATH_CONNECTOR_CUSTOMER_TOTAL_SPEND = 'connector_data_mapping/customer_data/total_spend';
110
+ const XML_PATH_CONNECTOR_CUSTOMER_LAST_ORDER_DATE = 'connector_data_mapping/customer_data/last_order_date';
111
+ const XML_PATH_CONNECTOR_CUSTOMER_LAST_ORDER_ID = 'connector_data_mapping/customer_data/last_order_id';
112
+ const XML_PATH_CONNECTOR_CUSTOMER_TOTAL_REFUND = 'connector_data_mapping/customer_data/total_refund';
113
+ const XML_PATH_CONNECTOR_CUSTOMER_LAST_ORDER_INCREMENT_ID = 'connector_data_mapping/customer_data/last_increment_id';
114
+ const XML_PATH_CONNECTOR_CUSTOMER_MOST_PURCHASED_CATEGORY = 'connector_data_mapping/customer_data/most_pur_category';
115
+ const XML_PATH_CONNECTOR_CUSTOMER_MOST_PURCHASED_BRAND = 'connector_data_mapping/customer_data/most_pur_brand';
116
+ const XML_PATH_CONNECTOR_CUSTOMER_MOST_FREQUENT_PURCHASE_DAY = 'connector_data_mapping/customer_data/most_freq_pur_day';
117
+ const XML_PATH_CONNECTOR_CUSTOMER_MOST_FREQUENT_PURCHASE_MONTH = 'connector_data_mapping/customer_data/most_freq_pur_mon';
118
+ const XML_PATH_CONNECTOR_CUSTOMER_FIRST_CATEGORY_PURCHASED = 'connector_data_mapping/customer_data/first_category_pur';
119
+ const XML_PATH_CONNECTOR_CUSTOMER_LAST_CATEGORY_PURCHASED = 'connector_data_mapping/customer_data/last_category_pur';
120
+ const XML_PATH_CONNECTOR_CUSTOMER_FIRST_BRAND_PURCHASED = 'connector_data_mapping/customer_data/first_brand_pur';
121
+ const XML_PATH_CONNECTOR_CUSTOMER_LAST_BRAND_PURCHASED = 'connector_data_mapping/customer_data/last_brand_pur';
122
+ const XML_PATH_CONNECTOR_CUSTOMER_SUBSCRIBER_STATUS = 'connector_data_mapping/customer_data/subscriber_status';
123
+
124
+ const XML_PATH_CONNECTOR_ENTERPRISE_CURRENT_BALANCE = 'connector_data_mapping/enterprise_data/reward_points';
125
+ const XML_PATH_CONNECTOR_ENTERPRISE_REWARD_AMOUNT = 'connector_data_mapping/enterprise_data/reward_amount';
126
+ const XML_PATH_CONNECTOR_ENTERPRISE_CREATED_DATE = 'connector_data_mapping/enterprise_data/created_date';
127
+ const XML_PATH_CONNECTOR_ENTERPRISE_EXPIRATION_DATE = 'connector_data_mapping/enterprise_data/expiration_date';
128
+ const XML_PATH_CONNECTOR_ENTERPIRSE_LAST_USED_DATE = 'connector_data_mapping/enterprise_data/last_used_date';
129
+ const XML_PATH_CONNECTOR_ENTERPRISE_CUSTOMER_SEGMENTS = 'connector_data_mapping/enterprise_data/customer_segment';
130
+
131
+
132
+ /**
133
+ * Dynamic Content
134
+ */
135
+ const XML_PATH_CONNECTOR_DYNAMIC_CONTENT_PASSCODE = 'connector_dynamic_content/external_dynamic_content_urls/passcode';
136
+ const XML_PATH_CONNECTOR_DYNAMIC_CONTENT_NOSTO = 'connector_dynamic_content/nosto_recommendation/api';
137
+ const XML_PATH_CONNECTOR_DYNAMIC_CONTENT_WIHSLIST_DISPLAY = 'connector_dynamic_content/products/wishlist_display_type';
138
+
139
+ /**
140
+ * CONFIGURATION SECTION.
141
+ */
142
+ const XML_PATH_CONNECTOR_SYNC_ORDER_STATUS = 'connector_configuration/transactional_data/order_statuses';
143
+ const XML_PATH_CONNECTOR_CUSTOM_ORDER_ATTRIBUTES = 'connector_configuration/transactional_data/order_custom_attributes';
144
+ const XML_PATH_CONNECTOR_CUSTOM_QUOTE_ATTRIBUTES = 'connector_configuration/transactional_data/quote_custom_attributes';
145
+ const XML_PATH_CONNECTOR_EMAIL_CAPTURE = 'connector_configuration/abandoned_carts/email_capture';
146
+ const XML_PATH_CONNECTOR_ABANDONED_CART_LIMIT = 'connector_configuration/abandoned_carts/limits';
147
+ const XML_PATH_CONNECTOR_DISABLE_NEWSLETTER_SUCCESS = 'connector_configuration/admin/disable_newsletter_success';
148
+ const XML_PATH_CONNECTOR_DISABLE_CUSTOMER_SUCCESS = 'connector_configuration/admin/disable_customer_success';
149
+ const XML_PATH_CONNECTOR_DYNAMIC_STYLING = 'connector_configuration/dynamic_content_style/dynamic_syling';
150
+ const XML_PATH_CONNECTOR_DYNAMIC_NAME_COLOR = 'connector_configuration/dynamic_content_style/name_color';
151
+ const XML_PATH_CONNECTOR_DYNAMIC_NAME_FONT_SIZE = 'connector_configuration/dynamic_content_style/name_font_size';
152
+ const XML_PATH_CONNECTOR_DYNAMIC_NAME_STYLE = 'connector_configuration/dynamic_content_style/name_style';
153
+ const XML_PATH_CONNECTOR_DYNAMIC_PRICE_COLOR = 'connector_configuration/dynamic_content_style/price_color';
154
+ const XML_PATH_CONNECTOR_DYNAMIC_PRICE_FONT_SIZE = 'connector_configuration/dynamic_content_style/price_font_size';
155
+ const XML_PATH_CONNECTOR_DYNAMIC_PRICE_STYLE = 'connector_configuration/dynamic_content_style/price_style';
156
+ const XML_PATH_CONNECTOR_DYNAMIC_LINK_COLOR = 'connector_configuration/dynamic_content_style/link_color';
157
+ const XML_PATH_CONNECTOR_DYNAMIC_LINK_FONT_SIZE = 'connector_configuration/dynamic_content_style/link_font_size';
158
+ const XML_PATH_CONNECTOR_DYNAMIC_LINK_STYLE = 'connector_configuration/dynamic_content_style/link_style';
159
+ const XML_PATH_CONNECTOR_DYNAMIC_DOC_FONT = 'connector_configuration/dynamic_content_style/font_picker';
160
+ const XML_PATH_CONNECTOR_DYNAMIC_DOC_BG_COLOR = 'connector_configuration/dynamic_content_style/doc_color';
161
+ const XML_PATH_CONNECTOR_DYNAMIC_OTHER_COLOR = 'connector_configuration/dynamic_content_style/other_color';
162
+ const XML_PATH_CONNECTOR_DYNAMIC_OTHER_FONT_SIZE = 'connector_configuration/dynamic_content_style/other_font_size';
163
+ const XML_PATH_CONNECTOR_DYNAMIC_OTHER_STYLE = 'connector_configuration/dynamic_content_style/other_style';
164
+ const XML_PATH_CONNECTOR_RESOURCE_ALLOCATION = 'connector_developer_settings/import_settings/memory_limit';
165
+ const XML_PATH_CONNECTOR_SYNC_LIMIT = 'connector_developer_settings/import_settings/batch_size';
166
+ const XML_PATH_CONNECTOR_TRANSACTIONAL_DATA_SYNC_LIMIT = 'connector_developer_settings/import_settings/orders';
167
+ const XML_PATH_CONNECTOR_ABANDONED_CART_SHELL = 'connector_developer_settings/abandoned_cart/shell';
168
+ const XML_PATH_CONNECTOR_SETUP_DATAFIELDS = 'connector_developer_settings/sync_settings/setup_data_fields';
169
+ const XML_PATH_CONNECTOR_ADVANCED_DEBUG_ENABLED = 'connector_developer_settings/debug/debug_enabled';
170
+ const XML_PATH_CONNECTOR_DEBUG_API_CALLS = 'connector_developer_settings/debug/debug_api_calls';
171
+ const XML_PATH_RAYGUN_APPLICATION_CODE = 'connector_developer_settings/debug/raygun_code';
172
+ const XML_PATH_CONNECTOR_FEED_ENABLED = 'connector_developer_settings/feed_configuration/feed_enabled';
173
+ const XML_PATH_CONNECTOR_FEED_URL = 'connector_developer_settings/feed_configuration/feed_url';
174
+ const XML_PATH_CONNECTOR_FEED_FREQUENCY = 'connector_developer_settings/feed_configuration/frequency';
175
+ const XML_PATH_CONNECTOR_FEED_USE_HTTPS = 'connector_developer_settings/feed_configuration/use_https';
176
+
177
+
178
+ /**
179
+ * Automation studio.
180
+ */
181
+ const XML_PATH_CONNECTOR_AUTOMATION_STUDIO_CUSTOMER = 'connector_automation_studio/automation/customer_automation';
182
+ const XML_PATH_CONNECTOR_AUTOMATION_STUDIO_SUBSCRIBER = 'connector_automation_studio/automation/subscriber_automation';
183
+ const XML_PATH_CONNECTOR_AUTOMATION_STUDIO_ORDER = 'connector_automation_studio/automation/order_automation';
184
+ const XML_PATH_CONNECTOR_AUTOMATION_STUDIO_GUEST_ORDER = 'connector_automation_studio/automation/guest_order_automation';
185
+ const XML_PATH_CONNECTOR_AUTOMATION_STUDIO_REVIEW = 'connector_automation_studio/automation/review_automation';
186
+ CONST XML_PATH_CONNECTOR_AUTOMATION_STUDIO_WISHLIST = 'connector_automation_studio/automation/wishlist_automation';
187
+
188
+
189
+ /**
190
+ * ROI SECTION.
191
+ */
192
+ const XML_PATH_CONNECTOR_ROI_TRACKING_ENABLED = 'connector_roi_tracking/roi_tracking/enabled';
193
+ const XML_PATH_CONNECTOR_PAGE_TRACKING_ENABLED = 'connector_roi_tracking/page_tracking/enabled';
194
+
195
+ /**
196
+ * OAUTH
197
+ */
198
+ const API_CONNECTOR_OAUTH_URL = 'https://my.dotmailer.com/';
199
+ const API_CONNECTOR_OAUTH_URL_AUTHORISE = 'OAuth2/authorise.aspx?';
200
+ const API_CONNECTOR_OAUTH_URL_TOKEN = 'OAuth2/Tokens.ashx';
201
+ const API_CONNECTOR_OAUTH_URL_LOG_USER = '?oauthtoken=';
202
+
203
+ /**
204
+ * Email Config.
205
+ */
206
+ const CONNECTOR_EMAIL_CONFIG_LAST_RUN = 'connector_api_last_call';
207
+ const CONNECTOR_EMAIL_CONFIG_HOUR_TRIGGER = 'connector_api_hour_trigger';
208
+ const CONNECTOR_FEED_LAST_CHECK_TIME = 'connector_feed_last_check_time';
209
+
210
+ /**
211
+ * Reviews SECTION
212
+ */
213
+ const XML_PATH_REVIEWS_ENABLED = 'connector_reviews/settings/enabled';
214
+ const XML_PATH_REVIEWS_FEEFO_LOGON = 'connector_reviews/feefo_feedback_engine/logon';
215
+ const XML_PATH_REVIEWS_FEEFO_REVIEWS = 'connector_reviews/feefo_feedback_engine/reviews_per_product';
216
+ const XML_PATH_REVIEWS_FEEFO_TEMPLATE = 'connector_reviews/feefo_feedback_engine/template';
217
+
218
+
219
+ /**
220
+ * Developer SECTION.
221
+ */
222
+ const XML_PATH_CONNECTOR_CLIENT_ID = 'connector_developer_settings/oauth/client_id';
223
+ const XML_PATH_CONNECTOR_CLIENT_SECRET_ID = 'connector_developer_settings/oauth/client_key';
224
+ const XML_PATH_CONNECTOR_CUSTOM_DOMAIN = 'connector_developer_settings/oauth/custom_domain';
225
+ const XML_PATH_CONNECTOR_CUSTOM_AUTHORIZATION = 'connector_developer_settings/oauth/custom_authorization';
226
+
227
+ /**
228
+ * Nosto
229
+ */
230
+ const API_ENDPOINT = 'https://api.nosto.com';
231
+ const API_ENDPOINT_TEST = 'https://test.api.nosto.com';
232
+
233
+ const RAYGUN_API_CODE_URL = 'https://dotmailerformagento.co.uk/magento/raygun.xml';
234
+
235
+
236
+ /**
237
+ * @param int $website
238
+ *
239
+ * @return bool
240
+ * @throws Mage_Core_Exception
241
+ */
242
+ public function getAuthorizeLinkFlag($website = 0)
243
+ {
244
+ $website = Mage::app()->getWebsite($website);
245
+
246
+ $customDomain = $website->getConfig(self::XML_PATH_CONNECTOR_CUSTOM_DOMAIN);
247
+
248
+ return (bool)$customDomain;
249
+ }
250
+
251
+ /**
252
+ * @param int $website
253
+ *
254
+ * @return string
255
+ * @throws Mage_Core_Exception
256
+ */
257
+ public function getAuthorizeLink($website = 0)
258
+ {
259
+ //base url, check for custom oauth domain
260
+ if ($this->getAuthorizeLinkFlag($website)){
261
+ $website = Mage::app()->getWebsite($website);
262
+
263
+ $baseUrl = $website->getConfig(self::XML_PATH_CONNECTOR_CUSTOM_DOMAIN) . self::API_CONNECTOR_OAUTH_URL_AUTHORISE;
264
+
265
+ } else {
266
+ $baseUrl = self::API_CONNECTOR_OAUTH_URL . self::API_CONNECTOR_OAUTH_URL_AUTHORISE;
267
+ }
268
+
269
+ return $baseUrl;
270
+ }
271
+
272
+ /**
273
+ * Callback authorization url.
274
+ * @return mixed|string
275
+ */
276
+ public function getCallbackUrl()
277
+ {
278
+ if ($callback = Mage::getStoreConfig(self::XML_PATH_CONNECTOR_CUSTOM_AUTHORIZATION)){
279
+ return $callback;
280
+ }
281
+
282
+ return $redirectUri = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB, true);
283
+ }
284
+
285
+ /**
286
+ * @param int $website
287
+ *
288
+ * @return string
289
+ */
290
+ public function getTokenUrl($website = 0)
291
+ {
292
+ if ($this->getAuthorizeLinkFlag($website)) {
293
+ $website = Mage::app()->getWebsite($website);
294
+
295
+ $tokenUrl = $website->getConfig(self::XML_PATH_CONNECTOR_CUSTOM_DOMAIN) . self::API_CONNECTOR_OAUTH_URL_TOKEN;
296
+ } else {
297
+
298
+ $tokenUrl = self::API_CONNECTOR_OAUTH_URL . self::API_CONNECTOR_OAUTH_URL_TOKEN;
299
+ }
300
+
301
+ return $tokenUrl;
302
+ }
303
+
304
+
305
+ /**
306
+ * @param int $website
307
+ *
308
+ * @return string
309
+ */
310
+ public function getLogUserUrl( $website = 0 )
311
+ {
312
+ if ($this->getAuthorizeLinkFlag($website)) {
313
+ $website = Mage::app()->getWebsite($website);
314
+
315
+ $logUserUrl = $website->getConfig(self::XML_PATH_CONNECTOR_CUSTOM_DOMAIN) . self::API_CONNECTOR_OAUTH_URL_LOG_USER;
316
+ } else {
317
+
318
+ $logUserUrl = self::API_CONNECTOR_OAUTH_URL . self::API_CONNECTOR_OAUTH_URL_LOG_USER;
319
+ }
320
+ return $logUserUrl;
321
+ }
322
+
323
+ }
app/code/community/Dotdigitalgroup/Email/Helper/Dashboard.php ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Helper_Dashboard extends Mage_Core_Helper_Abstract
4
+ {
5
+ protected $_rewriteTypes = array(
6
+ 'blocks',
7
+ 'helpers',
8
+ 'models',
9
+ );
10
+
11
+ public function getRewrites()
12
+ {
13
+ $rewrites = array(
14
+ 'blocks',
15
+ 'models',
16
+ 'helpers',
17
+ );
18
+
19
+ /* @var $_magentoConfig Mage_Core_Model_Config */
20
+ $_magentoConfig = Mage::getConfig();
21
+
22
+ // Load config of each module because modules can overwrite config each other. Global config is already merged
23
+ $modules = $_magentoConfig->getNode('modules')->children();
24
+ foreach ($modules as $moduleName => $moduleData) {
25
+ // Check only active modules
26
+ if (!$moduleData->is('active')) {
27
+ continue;
28
+ }
29
+
30
+ // Load config of module
31
+ $configXmlFile = $_magentoConfig->getModuleDir('etc', $moduleName) . DIRECTORY_SEPARATOR . 'config.xml';
32
+ if (!file_exists($configXmlFile)) {
33
+ continue;
34
+ }
35
+
36
+ $xml = simplexml_load_file($configXmlFile);
37
+ if ($xml) {
38
+ $rewriteElements = $xml->xpath('//rewrite');
39
+ foreach ($rewriteElements as $element) {
40
+ foreach ($element->children() as $child) {
41
+ $type = simplexml_import_dom(dom_import_simplexml($element)->parentNode->parentNode)->getName();
42
+ if (!in_array($type, $this->_rewriteTypes)) {
43
+ continue;
44
+ }
45
+ $groupClassName = simplexml_import_dom(dom_import_simplexml($element)->parentNode)->getName();
46
+ if (!isset($rewrites[$type][$groupClassName . '/' . $child->getName()])) {
47
+ $rewrites[$type][$groupClassName . '/' . $child->getName()] = array();
48
+ }
49
+ $rewrites[$type][$groupClassName . '/' . $child->getName()]['classes'][] = (string) $child;
50
+ }
51
+ }
52
+ }
53
+ }
54
+
55
+ foreach ($rewrites as $type => $data) {
56
+ if (count($data) > 0 && is_array($data)) {
57
+ foreach ($data as $node => $rewriteInfo) {
58
+ if (count($rewriteInfo['classes']) > 1) {
59
+ if ($this->_isInheritanceConflict($rewriteInfo['classes'])) {
60
+ $rewrites[$type][$node]['conflicts'][] = array(
61
+ 'node' => $node,
62
+ 'loaded_class' => $this->_getLoadedClass($type, $node)
63
+ );
64
+ }
65
+ }
66
+ }
67
+ }
68
+ }
69
+
70
+ $rewrites = array_merge($rewrites, $this->_loadLocalAutoloaderRewrites());
71
+
72
+ if (empty($rewrites['blocks']) && empty($rewrites['models'])
73
+ && empty($rewrites['helpers']) && empty($rewrites['autoload'])
74
+ ) {
75
+ return false;
76
+ }
77
+
78
+ return $rewrites;
79
+ }
80
+
81
+
82
+ /**
83
+ * Check if rewritten class has inherited the parent class.
84
+ * If yes we have no conflict. The top class can extend every core class.
85
+ * So we cannot check this.
86
+ *
87
+ * @var array $classes
88
+ * @return bool
89
+ */
90
+ protected function _isInheritanceConflict($classes)
91
+ {
92
+ $classes = array_reverse($classes);
93
+ for ($i = 0; $i < count($classes) - 1; $i++) {
94
+ try {
95
+ if (class_exists($classes[$i]) && class_exists($classes[$i + 1])) {
96
+ if (!is_a($classes[$i], $classes[$i + 1], true)) {
97
+ return true;
98
+ }
99
+ }
100
+ } catch (Exception $e) {
101
+ return true;
102
+ }
103
+ }
104
+
105
+ return false;
106
+ }
107
+
108
+ /**
109
+ * Returns loaded class by type like models or blocks
110
+ *
111
+ * @param string $type Class Type
112
+ * @param string $classGroup Class Group Name
113
+ *
114
+ * @return string
115
+ */
116
+ protected function _getLoadedClass($type, $classGroup)
117
+ {
118
+ switch ($type) {
119
+ case 'blocks':
120
+ return Mage::getConfig()->getBlockClassName($classGroup);
121
+
122
+ case 'helpers':
123
+ return Mage::getConfig()->getHelperClassName($classGroup);
124
+
125
+ default:
126
+ case 'models':
127
+ return Mage::getConfig()->getModelClassName($classGroup);
128
+ break;
129
+ }
130
+ }
131
+
132
+
133
+ /**
134
+ * Searches for all rewrites over autoloader in "app/code/local" of
135
+ * Mage, Enterprise Zend, Varien namespaces.
136
+ *
137
+ * @return array
138
+ */
139
+ protected function _loadLocalAutoloaderRewrites()
140
+ {
141
+ $return = array();
142
+ $localCodeFolder = Mage::getBaseDir('code') . '/local';
143
+
144
+ $folders = array(
145
+ 'Mage' => $localCodeFolder . '/Mage',
146
+ 'Enterprise' => $localCodeFolder . '/Enterprise',
147
+ 'Varien' => $localCodeFolder . '/Varien',
148
+ 'Zend' => $localCodeFolder . '/Zend',
149
+ );
150
+
151
+ foreach ($folders as $vendorPrefix => $folder) {
152
+ if (is_dir($folder)) {
153
+ $directory = new RecursiveDirectoryIterator($folder);
154
+ $iterator = new RecursiveIteratorIterator($directory);
155
+ $files = new RegexIterator($iterator, '/^.+\.php$/i', RecursiveRegexIterator::GET_MATCH);
156
+
157
+ foreach ($files as $file) {
158
+ $classFile = trim(str_replace($folder, '', realpath($file[0])), '/');
159
+ $className = $vendorPrefix
160
+ . '_'
161
+ . str_replace(DIRECTORY_SEPARATOR, '_', $classFile);
162
+ $className = substr($className, 0, -4); // replace .php extension
163
+ $return['autoload'][$className]['classes'][] = $className;
164
+ }
165
+ }
166
+ }
167
+ return $return;
168
+ }
169
+
170
+
171
+ }
app/code/community/Dotdigitalgroup/Email/Helper/Data.php ADDED
@@ -0,0 +1,726 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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->getRaygunClient()->Send('Authentication failed with code :' . $authRequest);
34
+ //throw new Exception('Authentication failed : ' . $authRequest);
35
+ return false;
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 getLastQuoteId()
62
+ {
63
+ return Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_LAST_QUOTE_ID);
64
+
65
+ }
66
+
67
+ public function log($data, $level = Zend_Log::DEBUG, $filename = 'api.log')
68
+ {
69
+ if ($this->getDebugEnabled()) {
70
+ $filename = 'connector_' . $filename;
71
+
72
+ Mage::log($data, $level, $filename, $force = true);
73
+ }
74
+ }
75
+
76
+ public function getDebugEnabled()
77
+ {
78
+ return (bool) Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_ADVANCED_DEBUG_ENABLED);
79
+ }
80
+
81
+ public function getConnectorVersion()
82
+ {
83
+ $modules = (array) Mage::getConfig()->getNode('modules')->children();
84
+ if (isset($modules['Dotdigitalgroup_Email'])) {
85
+ $moduleName = $modules['Dotdigitalgroup_Email'];
86
+ return $moduleName->version;
87
+ }
88
+ return '';
89
+ }
90
+
91
+
92
+ public function getPageTrackingEnabled()
93
+ {
94
+ return (bool)Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_PAGE_TRACKING_ENABLED);
95
+ }
96
+
97
+ public function getRoiTrackingEnabled()
98
+ {
99
+ return (bool)Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_ROI_TRACKING_ENABLED);
100
+ }
101
+
102
+ public function getResourceAllocationEnabled()
103
+ {
104
+ return (bool)Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_RESOURCE_ALLOCATION);
105
+ }
106
+
107
+ public function getMappedStoreName($website)
108
+ {
109
+ $mapped = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_CUSTOMER_STORENAME);
110
+ $storeName = ($mapped)? $mapped : '';
111
+ return $storeName;
112
+ }
113
+
114
+ /**
115
+ * Get the contact id for the custoemer based on website id.
116
+ * @param $email
117
+ * @param $websiteId
118
+ *
119
+ * @return bool
120
+ */
121
+ public function getContactId($email, $websiteId)
122
+ {
123
+ $contact = Mage::getModel('ddg_automation/contact')->loadByCustomerEmail($email, $websiteId);
124
+ if ($contactId = $contact->getContactId()) {
125
+ return $contactId;
126
+ }
127
+
128
+ $client = $this->getWebsiteApiClient($websiteId);
129
+ $response = $client->postContacts($email);
130
+
131
+ if (isset($response->message))
132
+ return false;
133
+ //save contact id
134
+ if (isset($response->id)){
135
+ $contact->setContactId($response->id)
136
+ ->save();
137
+ }
138
+ return $response->id;
139
+ }
140
+
141
+ public function getCustomerAddressBook($website)
142
+ {
143
+ $website = Mage::app()->getWebsite($website);
144
+ return $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMERS_ADDRESS_BOOK_ID);
145
+ }
146
+
147
+ public function getSubscriberAddressBook($website)
148
+ {
149
+ $website = Mage::app()->getWebsite($website);
150
+ return $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SUBSCRIBERS_ADDRESS_BOOK_ID);
151
+ }
152
+
153
+ public function getGuestAddressBook($website)
154
+ {
155
+ $website = Mage::app()->getWebsite($website);
156
+ return $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_GUEST_ADDRESS_BOOK_ID);
157
+ }
158
+
159
+ /**
160
+ * @return $this
161
+ */
162
+ public function allowResourceFullExecution()
163
+ {
164
+ if ($this->getResourceAllocationEnabled()) {
165
+
166
+ /* it may be needed to set maximum execution time of the script to longer,
167
+ * like 60 minutes than usual */
168
+ set_time_limit(7200);
169
+
170
+ /* and memory to 512 megabytes */
171
+ ini_set('memory_limit', '512M');
172
+ }
173
+ return $this;
174
+ }
175
+ public function convert($size)
176
+ {
177
+ $unit=array('b','kb','mb','gb','tb','pb');
178
+ return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i];
179
+ }
180
+
181
+ /**
182
+ * @return string
183
+ */
184
+ public function getStringWebsiteApiAccounts()
185
+ {
186
+ $accounts = array();
187
+ foreach (Mage::app()->getWebsites() as $website) {
188
+ $websiteId = $website->getId();
189
+ $apiUsername = $this->getApiUsername($website);
190
+ $accounts[$apiUsername] = $apiUsername . ', websiteId: ' . $websiteId . ' name ' . $website->getName();
191
+ }
192
+ return implode('</br>', $accounts);
193
+ }
194
+
195
+ /**
196
+ * @param int $website
197
+ *
198
+ * @return array|mixed
199
+ * @throws Mage_Core_Exception
200
+ */
201
+ public function getCustomAttributes($website = 0)
202
+ {
203
+ $website = Mage::app()->getWebsite($website);
204
+ $attr = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_CUSTOM_DATAFIELDS);
205
+
206
+ if (!$attr)
207
+ return array();
208
+
209
+ return unserialize($attr);
210
+ }
211
+
212
+
213
+ /**
214
+ * Enterprise custom datafields attributes.
215
+ * @param int $website
216
+ *
217
+ * @return array
218
+ * @throws Mage_Core_Exception
219
+ */
220
+ public function getEnterpriseAttributes( $website = 0) {
221
+ $website = Mage::app()->getWebsite($website);
222
+ $result = array();
223
+ $attrs = $website->getConfig('connector_data_mapping/enterprise_data');
224
+ //get individual mapped keys
225
+ foreach ( $attrs as $key => $one ) {
226
+ $config = $website->getConfig('connector_data_mapping/enterprise_data/' . $key);
227
+ //check for the mapped field
228
+ if ($config)
229
+ $result[$key] = $config;
230
+ }
231
+
232
+ if (empty($result))
233
+ return false;
234
+ return $result;
235
+ }
236
+
237
+ /**
238
+ * @param $path
239
+ * @param null|string|bool|int|Mage_Core_Model_Website $websiteId
240
+ * @return mixed
241
+ */
242
+ public function getWebsiteConfig($path, $websiteId = 0)
243
+ {
244
+ $website = Mage::app()->getWebsite($websiteId);
245
+ return $website->getConfig($path);
246
+ }
247
+
248
+ /**
249
+ * Api client by website.
250
+ *
251
+ * @param mixed $website
252
+ *
253
+ * @return bool|Dotdigitalgroup_Email_Model_Apiconnector_Client
254
+ */
255
+ public function getWebsiteApiClient($website = 0)
256
+ {
257
+ if (! $apiUsername = $this->getApiUsername($website) || ! $apiPassword = $this->getApiPassword($website))
258
+ return false;
259
+
260
+ $client = Mage::getModel('ddg_automation/apiconnector_client');
261
+ $client->setApiUsername($this->getApiUsername($website))
262
+ ->setApiPassword($this->getApiPassword($website));
263
+
264
+ return $client;
265
+ }
266
+
267
+ /**
268
+ * Retrieve authorisation code.
269
+ */
270
+ public function getCode()
271
+ {
272
+ $adminUser = Mage::getSingleton('admin/session')->getUser();
273
+ $code = $adminUser->getEmailCode();
274
+
275
+ return $code;
276
+ }
277
+
278
+ /**
279
+ * Autorisation url for OAUTH.
280
+ * @return string
281
+ */
282
+ public function getAuthoriseUrl()
283
+ {
284
+ $clientId = Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CLIENT_ID);
285
+
286
+ //callback uri if not set custom
287
+ $redirectUri = $this->getRedirectUri();
288
+ $redirectUri .= 'connector/email/callback';
289
+ $adminUser = Mage::getSingleton('admin/session')->getUser();
290
+ //query params
291
+ $params = array(
292
+ 'redirect_uri' => $redirectUri,
293
+ 'scope' => 'Account',
294
+ 'state' => $adminUser->getId(),
295
+ 'response_type' => 'code'
296
+ );
297
+
298
+ $authorizeBaseUrl = Mage::helper('ddg/config')->getAuthorizeLink();
299
+ $url = $authorizeBaseUrl . http_build_query($params) . '&client_id=' . $clientId;
300
+
301
+ return $url;
302
+ }
303
+
304
+ public function getRedirectUri()
305
+ {
306
+ $callback = Mage::helper('ddg/config')->getCallbackUrl();
307
+
308
+ return $callback;
309
+ }
310
+
311
+ /**
312
+ * order status config value
313
+ * @param int $website
314
+ * @return mixed order status
315
+ */
316
+ public function getConfigSelectedStatus($website = 0)
317
+ {
318
+ $status = $this->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_ORDER_STATUS, $website);
319
+ if($status)
320
+ return explode(',',$status);
321
+ else
322
+ return false;
323
+ }
324
+
325
+ public function getConfigSelectedCustomOrderAttributes($website = 0)
326
+ {
327
+ $customAttributes = $this->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOM_ORDER_ATTRIBUTES, $website);
328
+ if($customAttributes)
329
+ return explode(',',$customAttributes);
330
+ else
331
+ return false;
332
+ }
333
+
334
+ public function getConfigSelectedCustomQuoteAttributes($website = 0)
335
+ {
336
+ $customAttributes = $this->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOM_QUOTE_ATTRIBUTES, $website);
337
+ if($customAttributes)
338
+ return explode(',',$customAttributes);
339
+ else
340
+ return false;
341
+ }
342
+
343
+ /**
344
+ * check sweet tooth installed/active status
345
+ * @return boolean
346
+ */
347
+ public function isSweetToothEnabled()
348
+ {
349
+ return (bool)Mage::getConfig()->getModuleConfig('TBT_Rewards')->is('active', 'true');
350
+ }
351
+
352
+ /**
353
+ * check sweet tooth installed/active status and active status
354
+ * @param Mage_Core_Model_Website $website
355
+ * @return boolean
356
+ */
357
+ public function isSweetToothToGo($website)
358
+ {
359
+ $stMappingStatus = $this->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_SWEETTOOTH_ACTIVE, $website);
360
+ if($stMappingStatus && $this->isSweetToothEnabled()) return true;
361
+ return false;
362
+ }
363
+
364
+ public function setConnectorContactToReImport($customerId)
365
+ {
366
+ $contactModel = Mage::getModel('ddg_automation/contact');
367
+ $contactModel
368
+ ->loadByCustomerId($customerId)
369
+ ->setEmailImported(Dotdigitalgroup_Email_Model_Contact::EMAIL_CONTACT_NOT_IMPORTED)
370
+ ->save();
371
+ }
372
+
373
+ /**
374
+ * Diff between to times;
375
+ *
376
+ * @param $time1
377
+ * @param $time2
378
+ * @return int
379
+ */
380
+ public function dateDiff($time1, $time2=NULL) {
381
+ if (is_null($time2)) {
382
+ $time2 = Mage::getModel('core/date')->date();
383
+ }
384
+ $time1 = strtotime($time1);
385
+ $time2 = strtotime($time2);
386
+ return $time2 - $time1;
387
+ }
388
+
389
+
390
+ /**
391
+ * Disable website config when the request is made admin area only!
392
+ * @param $path
393
+ *
394
+ * @throws Mage_Core_Exception
395
+ */
396
+ public function disableConfigForWebsite($path)
397
+ {
398
+ $scopeId = 0;
399
+ if ($website = Mage::app()->getRequest()->getParam('website')) {
400
+ $scope = 'websites';
401
+ $scopeId = Mage::app()->getWebsite($website)->getId();
402
+ } else {
403
+ $scope = "default";
404
+ }
405
+ $config = Mage::getConfig();
406
+ $config->saveConfig($path, 0, $scope, $scopeId);
407
+ $config->cleanCache();
408
+ }
409
+
410
+ /**
411
+ * number of customers with duplicate emails, emails as total number
412
+ * @return Mage_Customer_Model_Resource_Customer_Collection
413
+ */
414
+ public function getCustomersWithDuplicateEmails( ) {
415
+ $customers = Mage::getModel('customer/customer')->getCollection();
416
+
417
+ //duplicate emails
418
+ $customers->getSelect()
419
+ ->columns(array('emails' => 'COUNT(e.entity_id)'))
420
+ ->group('email')
421
+ ->having('emails > ?', 1);
422
+
423
+ return $customers;
424
+ }
425
+
426
+ /**
427
+ * Create new raygun client.
428
+ *
429
+ * @return bool|\Raygun4php\RaygunClient
430
+ */
431
+ public function getRaygunClient()
432
+ {
433
+ $code = Mage::getstoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_RAYGUN_APPLICATION_CODE);
434
+
435
+ if ($this->raygunEnabled()) {
436
+ require_once Mage::getBaseDir('lib') . DS . 'Raygun4php' . DS . 'RaygunClient.php';
437
+ return new Raygun4php\RaygunClient($code, false, true);
438
+ }
439
+
440
+ return false;
441
+ }
442
+
443
+ /**
444
+ * Raygun logs.
445
+ * @param int $errno
446
+ * @param $message
447
+ * @param string $filename
448
+ * @param int $line
449
+ * @param array $tags
450
+ *
451
+ * @return int|null
452
+ */
453
+ public function rayLog($errno = 100, $message, $filename = 'helper/data.php', $line = 1, $tags = array())
454
+ {
455
+ $client = $this->getRaygunClient();
456
+ if ($client) {
457
+ //use tags to log the client baseurl
458
+ if (empty($tags))
459
+ $tags = array(Mage::getBaseUrl('web'));
460
+ //send message
461
+ $code = $client->SendError( $errno, $message, $filename, $line, $tags );
462
+
463
+ return $code;
464
+ }
465
+
466
+ return false;
467
+ }
468
+
469
+
470
+ /**
471
+ * check for raygun application and if enabled.
472
+ * @param int $websiteId
473
+ *
474
+ * @return mixed
475
+ * @throws Mage_Core_Exception
476
+ */
477
+ public function raygunEnabled($websiteId = 0)
478
+ {
479
+ $website = Mage::app()->getWebsite($websiteId);
480
+
481
+ return (bool)$website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_RAYGUN_APPLICATION_CODE);
482
+
483
+ }
484
+
485
+ /**
486
+ * Generate the baseurl for the default store
487
+ * dynamic content will be displayed
488
+ * @return string
489
+ * @throws Mage_Core_Exception
490
+ */
491
+ public function generateDynamicUrl()
492
+ {
493
+ $website = Mage::app()->getRequest()->getParam('website', false);
494
+
495
+ //set website url for the default store id
496
+ $website = ($website)? Mage::app()->getWebsite( $website ) : 0;
497
+
498
+ $defaultGroup = Mage::app()->getWebsite($website)
499
+ ->getDefaultGroup();
500
+
501
+ if (! $defaultGroup)
502
+ return $mage = Mage::app()->getStore()->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
503
+
504
+ //base url
505
+ $baseUrl = Mage::app()->getStore($defaultGroup->getDefaultStore())->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
506
+
507
+ return $baseUrl;
508
+
509
+ }
510
+
511
+ /**
512
+ *
513
+ *
514
+ * @param int $store
515
+ * @return mixed
516
+ */
517
+ public function isNewsletterSuccessDisabled($store = 0)
518
+ {
519
+ return Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DISABLE_NEWSLETTER_SUCCESS, $store);
520
+ }
521
+
522
+ /**
523
+ * get sales_flat_order table description
524
+ *
525
+ * @return array
526
+ */
527
+ public function getOrderTableDescription()
528
+ {
529
+ $resource = Mage::getSingleton('core/resource');
530
+ $readConnection = $resource->getConnection('core_read');
531
+ $salesTable = $resource->getTableName('sales/order');
532
+
533
+ return $readConnection->describeTable($salesTable);
534
+ }
535
+
536
+ /**
537
+ * get sales_flat_quote table description
538
+ *
539
+ * @return array
540
+ */
541
+ public function getQuoteTableDescription()
542
+ {
543
+ $resource = Mage::getSingleton('core/resource');
544
+ $readConnection = $resource->getConnection('core_read');
545
+ $table = $resource->getTableName('sales/quote');
546
+ return $readConnection->describeTable($table);
547
+ }
548
+
549
+ /**
550
+ * @return bool
551
+ */
552
+ public function getEasyEmailCapture()
553
+ {
554
+ return Mage::getStoreConfigFlag(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_EMAIL_CAPTURE);
555
+ }
556
+
557
+ /**
558
+ * get feefo logon config value
559
+ *
560
+ * @return mixed
561
+ */
562
+ public function getFeefoLogon()
563
+ {
564
+ return $this->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_REVIEWS_FEEFO_LOGON);
565
+ }
566
+
567
+ /**
568
+ * get feefo reviews limit config value
569
+ *
570
+ * @return mixed
571
+ */
572
+ public function getFeefoReviewsPerProduct()
573
+ {
574
+ return $this->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_REVIEWS_FEEFO_REVIEWS);
575
+ }
576
+
577
+ /**
578
+ * get feefo logo template config value
579
+ *
580
+ * @return mixed
581
+ */
582
+ public function getFeefoLogoTemplate()
583
+ {
584
+ return $this->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_REVIEWS_FEEFO_TEMPLATE);
585
+ }
586
+
587
+ /**
588
+ * update data fields
589
+ *
590
+ * @param $email
591
+ * @param Mage_Core_Model_Website $website
592
+ * @param $storeName
593
+ */
594
+ public function updateDataFields($email, Mage_Core_Model_Website $website, $storeName)
595
+ {
596
+ $data = array();
597
+ if($store_name = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_STORE_NAME)){
598
+ $data[] = array(
599
+ 'Key' => $store_name,
600
+ 'Value' => $storeName
601
+ );
602
+ }
603
+ if($website_name = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_WEBSITE_NAME)){
604
+ $data[] = array(
605
+ 'Key' => $website_name,
606
+ 'Value' => $website->getName()
607
+ );
608
+ }
609
+ if(!empty($data)){
610
+ //update data fields
611
+ $client = $this->getWebsiteApiClient($website);
612
+ $client->updateContactDatafieldsByEmail($email, $data);
613
+ }
614
+ }
615
+
616
+ /**
617
+ * check connector SMTP installed/active status
618
+ * @return boolean
619
+ */
620
+ public function isSmtpEnabled()
621
+ {
622
+ return (bool)Mage::getConfig()->getModuleConfig('Ddg_Transactional')->is('active', 'true');
623
+ }
624
+
625
+ /**
626
+ * Is magento enterprise.
627
+ * @return bool
628
+ */
629
+ public function isEnterprise()
630
+ {
631
+ return Mage::getConfig ()->getModuleConfig ( 'Enterprise_Enterprise' ) && Mage::getConfig ()->getModuleConfig ( 'Enterprise_AdminGws' ) && Mage::getConfig ()->getModuleConfig ( 'Enterprise_Checkout' ) && Mage::getConfig ()->getModuleConfig ( 'Enterprise_Customer' );
632
+
633
+ }
634
+
635
+ public function getTemplateList()
636
+ {
637
+ $client = $this->getWebsiteApiClient(Mage::app()->getWebsite());
638
+ if(!$client)
639
+ return array();
640
+
641
+ $templates = $client->getApiTemplateList();
642
+ $fields[] = array('value' => '', 'label' => '');
643
+ foreach ( $templates as $one ) {
644
+ if ( isset( $one->id ) ) {
645
+ $fields[] = array(
646
+ 'value' => $one->id,
647
+ 'label' => $this->__( addslashes( $one->name ) )
648
+ );
649
+ }
650
+ }
651
+ return $fields;
652
+ }
653
+
654
+ /**
655
+ * Update last quote id datafield.
656
+ * @param $quoteId
657
+ * @param $email
658
+ * @param $websiteId
659
+ */
660
+ public function updateLastQuoteId($quoteId, $email, $websiteId)
661
+ {
662
+ $client = $this->getWebsiteApiClient($websiteId);
663
+ //last quote id config data mapped
664
+ $quoteIdField = $this->getLastQuoteId();
665
+
666
+ $data[] = array(
667
+ 'Key' => $quoteIdField,
668
+ 'Value' => $quoteId
669
+ );
670
+ //update datafields for conctact
671
+ $client->updateContactDatafieldsByEmail($email, $data);
672
+ }
673
+
674
+ /**
675
+ * Remove code and disable Raygun.
676
+ */
677
+ public function disableRaygun()
678
+ {
679
+ $config = new Mage_Core_Model_Config();
680
+ $config->saveConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_RAYGUN_APPLICATION_CODE, '');
681
+ Mage::getConfig()->cleanCache();
682
+ }
683
+
684
+ public function enableRaygunCode()
685
+ {
686
+ $curl = new Varien_Http_Adapter_Curl();
687
+ $curl->setConfig(array(
688
+ 'timeout' => 2
689
+ ));
690
+ $curl->write(Zend_Http_Client::GET, Dotdigitalgroup_Email_Helper_Config::RAYGUN_API_CODE_URL, '1.0');
691
+ $data = $curl->read();
692
+
693
+ if ($data === false) {
694
+ return false;
695
+ }
696
+ $data = preg_split('/^\r?$/m', $data, 2);
697
+ $data = trim($data[1]);
698
+ $curl->close();
699
+
700
+ $xml = new SimpleXMLElement($data);
701
+ $raygunCode = $xml->code;
702
+
703
+ //not found
704
+ if (!$raygunCode)
705
+ return;
706
+
707
+ $config = new Mage_Core_Model_Config();
708
+ $config->saveConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_RAYGUN_APPLICATION_CODE, $raygunCode);
709
+ }
710
+
711
+ /**
712
+ * Get the config id by the automation type.
713
+ * @param $automationType
714
+ * @param int $websiteId
715
+ *
716
+ * @return mixed
717
+ */
718
+ public function getAutomationIdByType($automationType, $websiteId = 0)
719
+ {
720
+ $path = constant('Dotdigitalgroup_Email_Helper_Config::' . $automationType);
721
+ $automationCampaignId = $this->getWebsiteConfig($path, $websiteId);
722
+
723
+ return $automationCampaignId;
724
+ }
725
+
726
+ }
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
 
@@ -107,11 +110,12 @@ class Dotdigitalgroup_Email_Helper_File extends Dotdigitalgroup_Email_Helper_Dat
107
 
108
  /**
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
 
117
  return;
@@ -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,58 @@ 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
 
110
 
111
  /**
112
  * If the path does not exist then create it
113
+ * @param string $pathz
114
  */
115
+ public function pathExists($path)
116
+ {
117
+ if (!is_dir($path)) {
118
+ mkdir($path, 0770, true);
119
  } // end
120
 
121
  return;
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
+ //enterprise datafields
170
+ if (Mage::helper('ddg')->isEnterprise()) {
171
+
172
+ $enterpriseMapping = Mage::helper( 'ddg' )->getEnterpriseAttributes( $website );
173
+ if ( $enterpriseMapping ) {
174
+ $mappedData = array_merge( $mappedData, $enterpriseMapping );
175
+ }
176
+ }
177
+
178
+ $mappedRewardData = $this->getWebsiteCustomerRewardMappingDatafields($website);
179
+ if($mappedRewardData) $mappedData = array_merge($mappedData, $mappedRewardData);
180
+
181
+ foreach ($mappedData as $key => $value) {
182
+ if (! $value)
183
+ unset($mappedData[$key]);
184
+ }
185
+
186
+ return $mappedData;
187
+ }
188
+
189
+ public function getWebsiteCustomerRewardMappingDatafields($website)
190
+ {
191
+ $helper = Mage::helper('ddg');
192
+ if($helper->isSweetToothToGo($website)) {
193
+ $store = $website->getDefaultStore();
194
+ $mappedData = Mage::getStoreConfig('connector_data_mapping/sweet_tooth', $store);
195
+ unset($mappedData['active']);
196
+ return $mappedData;
197
+ }
198
+ return false;
199
+ }
200
+
201
+ /**
202
+ * @param $path
203
+ *
204
+ * @return bool
205
+ */
206
+ public function getPathPermission($path) {
207
+
208
+ //check for directory created before looking into permission
209
+ if (is_dir($path)) {
210
+ clearstatcache( null, $path );
211
+
212
+ return decoct( fileperms( $path ) & 0777 );
213
+ }
214
+ //the file is not created and return the passing value
215
+ return 755;
216
+ }
217
  }
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/Review.php ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Helper_Review extends Mage_Core_Helper_Abstract
4
+ {
5
+ /**
6
+ * configs
7
+ */
8
+ const XML_PATH_REVIEW_STATUS = 'connector_reviews/settings/status';
9
+ const XML_PATH_REVIEW_DELAY = 'connector_reviews/settings/delay';
10
+ const XML_PATH_REVIEW_NEW_PRODUCT = 'connector_reviews/settings/new_product';
11
+ const XML_PATH_REVIEW_CAMPAIGN = 'connector_reviews/settings/campaign';
12
+ const XML_PATH_REVIEW_ANCHOR = 'connector_reviews/settings/anchor';
13
+ const XML_PATH_REVIEW_DISPLAY_TYPE = 'connector_dynamic_content/products/review_display_type';
14
+
15
+ /**
16
+ * get config value on website level
17
+ *
18
+ * @param $path
19
+ * @param $website
20
+ * @return mixed
21
+ */
22
+ public function getReviewWebsiteSettings($path, $website)
23
+ {
24
+ $helper = Mage::helper('ddg');
25
+ return $helper->getWebsiteConfig($path, $website);
26
+ }
27
+
28
+ /**
29
+ * @param $website
30
+ * @return boolean
31
+ */
32
+ public function isEnabled($website)
33
+ {
34
+ return $this->getReviewWebsiteSettings(Dotdigitalgroup_Email_Helper_Config::XML_PATH_REVIEWS_ENABLED, $website);
35
+ }
36
+
37
+ /**
38
+ * @param $website
39
+ * @return string
40
+ */
41
+ public function getOrderStatus($website)
42
+ {
43
+ return $this->getReviewWebsiteSettings(self::XML_PATH_REVIEW_STATUS, $website);
44
+ }
45
+
46
+ /**
47
+ * @param $website
48
+ * @return int
49
+ */
50
+ public function getDelay($website)
51
+ {
52
+ return $this->getReviewWebsiteSettings(self::XML_PATH_REVIEW_DELAY, $website);
53
+ }
54
+
55
+ /**
56
+ * @param $website
57
+ * @return boolean
58
+ */
59
+ public function isNewProductOnly($website)
60
+ {
61
+ return $this->getReviewWebsiteSettings(self::XML_PATH_REVIEW_NEW_PRODUCT, $website);
62
+ }
63
+
64
+ /**
65
+ * @param $website
66
+ * @return int
67
+ */
68
+ public function getCampaign($website)
69
+ {
70
+ return $this->getReviewWebsiteSettings(self::XML_PATH_REVIEW_CAMPAIGN, $website);
71
+ }
72
+
73
+ /**
74
+ * @param $website
75
+ * @return string
76
+ */
77
+ public function getAnchor($website)
78
+ {
79
+ return $this->getReviewWebsiteSettings(self::XML_PATH_REVIEW_ANCHOR, $website);
80
+ }
81
+
82
+ /**
83
+ * @param $website
84
+ * @return string
85
+ */
86
+ public function getDisplayType($website)
87
+ {
88
+ return $this->getReviewWebsiteSettings(self::XML_PATH_REVIEW_DISPLAY_TYPE, $website);
89
+ }
90
+ }
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('ddg')->getApiUsername($website);
22
+ $this->_apiPassword = (string)Mage::helper('ddg')->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,230 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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('ddg_automation/contact');
14
+ $numImported = $contactModel->getNumberOfImportedContacs();
15
+ $updated = $contactModel->resetAllContacts();
16
+ Mage::helper('ddg')->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
+ * Check if the transactional data feature is enabled
28
+ * To use the wishlist and order sync this needs to be enabled.
29
+ */
30
+ public function checkFeatureActive()
31
+ {
32
+ //scope to retrieve the website id
33
+ $scopeId = 0;
34
+ if ($website = Mage::app()->getRequest()->getParam('website')) {
35
+ //use webiste
36
+ $scope = 'websites';
37
+ $scopeId = Mage::app()->getWebsite($website)->getId();
38
+ } else {
39
+ //set to default
40
+ $scope = "default";
41
+ }
42
+ //webiste by id
43
+ $website = Mage::app()->getWebsite($scopeId);
44
+
45
+ //configuration saved for the wishlist and order sync
46
+ $wishlistEnabled = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_WISHLIST_ENABLED, $scope, $scopeId);
47
+ $orderEnabled = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_ORDER_ENABLED);
48
+
49
+ //only for modification for order and wishlist
50
+ if ($orderEnabled || $wishlistEnabled) {
51
+ //client by website id
52
+ $client = Mage::helper('ddg')->getWebsiteApiClient($scopeId);
53
+
54
+ //call request for account info
55
+ $response = $client->getAccountInfo();
56
+
57
+ //properties must be checked
58
+ if (isset($response->properties)) {
59
+ $accountInfo = $response->properties;
60
+ $result = $this->_checkForOption(Dotdigitalgroup_Email_Model_Apiconnector_Client::API_ERROR_TRANS_ALLOWANCE, $accountInfo);
61
+
62
+ //account is disabled to use transactional data
63
+ if (! $result) {
64
+ $message = 'Transactional Data For This Account Is Disabled. Call Support To Enable.';
65
+ //send admin message
66
+ Mage::getSingleton('adminhtml/session')->addError($message);
67
+
68
+ //send raygun message for trans data
69
+ Mage::helper('ddg')->rayLog('100', $message);
70
+ //disable the config for wishlist and order sync
71
+ $config = Mage::getConfig();
72
+ $config->saveConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_WISHLIST_ENABLED, 0, $scope, $scopeId);
73
+ $config->saveConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_ORDER_ENABLED, 0, $scope, $scopeId);
74
+ $config->cleanCache();
75
+ }
76
+ }
77
+ }
78
+
79
+ return $this;
80
+
81
+ }
82
+
83
+ /**
84
+ * API Credentials.
85
+ * Installation and validation confirmation.
86
+ * @return $this
87
+ */
88
+ public function actionConfigSaveApi()
89
+ {
90
+ $groups = Mage::app()->getRequest()->getPost('groups');
91
+ if (isset($groups['api']['fields']['username']['inherit']) || isset($groups['api']['fields']['password']['inherit']))
92
+ return $this;
93
+
94
+ $apiUsername = isset($groups['api']['fields']['username']['value'])? $groups['api']['fields']['username']['value'] : false;
95
+ $apiPassword = isset($groups['api']['fields']['password']['value'])? $groups['api']['fields']['password']['value'] : false;
96
+ //skip if the inherit option is selected
97
+ if ($apiUsername && $apiPassword) {
98
+ Mage::helper('ddg')->log('----VALIDATING ACCOUNT---');
99
+ $testModel = Mage::getModel('ddg_automation/apiconnector_test');
100
+ $isValid = $testModel->validate($apiUsername, $apiPassword);
101
+ if (! $isValid) {
102
+ /**
103
+ * Disable invalid Api credentials
104
+ */
105
+ $scopeId = 0;
106
+ if ($website = Mage::app()->getRequest()->getParam('website')) {
107
+ $scope = 'websites';
108
+ $scopeId = Mage::app()->getWebsite($website)->getId();
109
+ } else {
110
+ $scope = "default";
111
+ }
112
+ $config = Mage::getConfig();
113
+ $config->saveConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED, 0, $scope, $scopeId);
114
+ $config->cleanCache();
115
+ }
116
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('ddg')->__('API Credentials Valid.'));
117
+ }
118
+ return $this;
119
+ }
120
+
121
+ private function _checkAddressBookMapping( $website ) {
122
+
123
+ $helper = Mage::helper('ddg');
124
+ $customerAddressBook = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMERS_ADDRESS_BOOK_ID, $website);
125
+ $subscriberAddressBook = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SUBSCRIBERS_ADDRESS_BOOK_ID, $website);
126
+
127
+ if (! $customerAddressBook && $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_CONTACT_ENABLED, $website)){
128
+
129
+ $helper->disableConfigForWebsite(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_CONTACT_ENABLED);
130
+ Mage::getSingleton('adminhtml/session')->addNotice('The Contact Sync Disabled - No Addressbook Selected !');
131
+ }
132
+ if (! $subscriberAddressBook && $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_SUBSCRIBER_ENABLED, $website)) {
133
+ $helper->disableConfigForWebsite( Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_SUBSCRIBER_ENABLED );
134
+ Mage::getSingleton('adminhtml/session')->addNotice('The Subscriber Sync Disabled - No Addressbook Selected !');
135
+ }
136
+
137
+ }
138
+
139
+ /**
140
+ * Check for name option in array.
141
+ *
142
+ * @param $name
143
+ * @param $data
144
+ *
145
+ * @return bool
146
+ */
147
+ private function _checkForOption($name, $data) {
148
+ //loop for all options
149
+ foreach ( $data as $one ) {
150
+
151
+ if ($one->name == $name) {
152
+ return true;
153
+ }
154
+ }
155
+
156
+ return false;
157
+ }
158
+
159
+ /**
160
+ * Update Feed for latest releases.
161
+ *
162
+ */
163
+ public function updateFeed()
164
+ {
165
+ Mage::getModel('ddg_automation/feed')->checkForUpgrade();
166
+ }
167
+
168
+
169
+ /**
170
+ * Add modified segment for contact.
171
+ * @param $observer
172
+ *
173
+ * @return $this
174
+ */
175
+ public function connectorCustomerSegmentChanged($observer)
176
+ {
177
+ $segmentsIds = $observer->getEvent()->getSegmentIds();
178
+ $customerId = Mage::getSingleton('customer/session')->getCustomerId();
179
+
180
+ $websiteId = Mage::app()->getStore()->getWebsiteId();
181
+
182
+ if (!empty($segmentsIds)) {
183
+ $this->addContactsFromWebsiteSegments($customerId, $segmentsIds, $websiteId);
184
+ }
185
+
186
+ return $this;
187
+ }
188
+
189
+
190
+ /**
191
+ * Add segment ids.
192
+ * @param $customerId
193
+ * @param $segmentIds
194
+ * @param $websiteId
195
+ *
196
+ * @return $this
197
+ */
198
+ protected function addContactsFromWebsiteSegments($customerId, $segmentIds, $websiteId){
199
+
200
+ if (empty($segmentIds))
201
+ return;
202
+ $segmentIds = implode(',', $segmentIds);
203
+
204
+ $contact = Mage::getModel('ddg_automation/contact')->getCollection()
205
+ ->addFieldToFilter('customer_id', $customerId)
206
+ ->addFieldToFilter('website_id', $websiteId)
207
+ ->getFirstItem();
208
+ try {
209
+
210
+ $contact->setSegmentIds($segmentIds)
211
+ ->setEmailImported()
212
+ ->save();
213
+
214
+ }catch (Exception $e){
215
+ Mage::logException($e);
216
+ }
217
+
218
+ return $this;
219
+ }
220
+
221
+ protected function getCustomerSegmentIdsForWebsite($customerId, $websiteId){
222
+ $segmentIds = Mage::getModel('ddg_automation/contact')->getCollection()
223
+ ->addFieldToFilter('website_id', $websiteId)
224
+ ->addFieldToFilter('customer_id', $customerId)
225
+ ->getFirstItem()
226
+ ->getSegmentIds();
227
+
228
+ return $segmentIds;
229
+ }
230
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Addressbooks.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // Add a "Do Not Map" Option
14
+ $fields[] = array('value' => 0, 'label' => Mage::helper('ddg')->__('-- Please Select --'));
15
+ $website = Mage::app()->getRequest()->getParam('website');
16
+
17
+ $enabled = Mage::helper('ddg')->isEnabled($website);
18
+
19
+ //get address books options
20
+ if ($enabled) {
21
+ $client = Mage::getModel( 'ddg_automation/apiconnector_client' );
22
+ $client->setApiUsername( Mage::helper( 'ddg' )->getApiUsername( $website ) )
23
+ ->setApiPassword( Mage::helper( 'ddg' )->getApiPassword( $website ) );
24
+
25
+ $savedAddressBooks = Mage::registry( 'addressbooks' );
26
+ //get saved address books from registry
27
+ if ( $savedAddressBooks ) {
28
+ $addressBooks = $savedAddressBooks;
29
+ } else {
30
+ // api all address books
31
+ $addressBooks = $client->getAddressBooks();
32
+ Mage::register( 'addressbooks', $addressBooks );
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
+ }
42
+
43
+ return $fields;
44
+ }
45
+
46
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Addressbookspref.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Addressbookspref
4
+ {
5
+ private function getWebsite()
6
+ {
7
+ $website = Mage::app()->getWebsite();
8
+ $websiteParam = Mage::app()->getRequest()->getParam('website');
9
+ if($websiteParam)
10
+ $website = Mage::app()->getWebsite($websiteParam);
11
+ return $website;
12
+ }
13
+
14
+ /**
15
+ * get address books
16
+ *
17
+ * @return null
18
+ */
19
+ private function getAddressBooks()
20
+ {
21
+ $website = $this->getWebsite();
22
+ $client = Mage::getModel( 'ddg_automation/apiconnector_client' );
23
+ $client->setApiUsername( Mage::helper( 'ddg' )->getApiUsername( $website ) )
24
+ ->setApiPassword( Mage::helper( 'ddg' )->getApiPassword( $website ) );
25
+
26
+ $savedAddressBooks = Mage::registry( 'addressbooks' );
27
+ //get saved address books from registry
28
+ if ( $savedAddressBooks ) {
29
+ $addressBooks = $savedAddressBooks;
30
+ } else {
31
+ // api all address books
32
+ $addressBooks = $client->getAddressBooks();
33
+ Mage::register( 'addressbooks', $addressBooks );
34
+ }
35
+ return $addressBooks;
36
+ }
37
+
38
+ /**
39
+ * addressbook options
40
+ *
41
+ * @return array
42
+ * @throws Mage_Core_Exception
43
+ */
44
+ public function toOptionArray()
45
+ {
46
+ $fields = array();
47
+ $website = $this->getWebsite();
48
+
49
+ $enabled = Mage::helper('ddg')->isEnabled($website);
50
+
51
+ //get address books options
52
+ if ($enabled) {
53
+ $addressBooks = $this->getAddressBooks();
54
+ //set the error message to the select option
55
+ if ( isset( $addressBooks->message ) ) {
56
+ $fields[] = array( 'value' => 0, 'label' => Mage::helper( 'ddg' )->__( $addressBooks->message) );
57
+ }
58
+
59
+ $subscriberAddressBook = Mage::helper('ddg')->getSubscriberAddressBook(Mage::app()->getWebsite());
60
+
61
+ //set up fields with book id and label
62
+ foreach ( $addressBooks as $book ) {
63
+ if (isset($book->id) && $book->visibility == 'Public' && $book->id != $subscriberAddressBook) {
64
+ $fields[] = array( 'value' => $book->id, 'label' => $book->name );
65
+ }
66
+ }
67
+ }
68
+
69
+ return $fields;
70
+ }
71
+ }
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('ddg')->__('No Limit'));
26
+ elseif ($i == 1) {
27
+ $row = array(
28
+ 'value' => $one,
29
+ 'label' => Mage::helper( 'ddg' )->__( $one . ' Hour' )
30
+ );
31
+ } else {
32
+ $row = array(
33
+ 'value' => $one,
34
+ 'label' => Mage::helper( 'ddg' )->__( $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/Attributes.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Advanced_Attributes
4
+ {
5
+ /**
6
+ * Returns custom order attributes
7
+ * @return array
8
+ */
9
+ public function toOptionArray()
10
+ {
11
+ $fields = Mage::helper('ddg')->getOrderTableDescription();
12
+
13
+ $customFields = array();
14
+ foreach($fields as $key => $field){
15
+ $customFields[] = array(
16
+ 'value' => $field['COLUMN_NAME'],
17
+ 'label' => $field['COLUMN_NAME']
18
+ );
19
+ }
20
+ return $customFields;
21
+ }
22
+ }
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('ddg')->__('1 Hour')),
9
+ array('value' => '2', 'label' => Mage::helper('ddg')->__('2 Hours')),
10
+ array('value' => '6', 'label' => Mage::helper('ddg')->__('6 Hours')),
11
+ array('value' => '12', 'label' => Mage::helper('ddg')->__('12 Hours')),
12
+ array('value' => '24', 'label' => Mage::helper('ddg')->__('24 Hours'))
13
+ );
14
+ }
15
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Quoteattributes.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Advanced_Quoteattributes
4
+ {
5
+ /**
6
+ * @return array
7
+ */
8
+ public function toOptionArray()
9
+ {
10
+ $fields = Mage::helper('ddg')->getQuoteTableDescription();
11
+
12
+ $customFields = array();
13
+ foreach($fields as $key => $field){
14
+ $customFields[] = array(
15
+ 'value' => $field['COLUMN_NAME'],
16
+ 'label' => $field['COLUMN_NAME']
17
+ );
18
+ }
19
+ return $customFields;
20
+ }
21
+ }
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,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $fields[] = array('value' => '0', 'label' => Mage::helper('ddg')->__('-- Disabled --'));
13
+ if ($websiteName) {
14
+ $website = Mage::app()->getWebsite($websiteName);
15
+ }
16
+
17
+ if (Mage::helper('ddg')->isEnabled($website)) {
18
+
19
+ $client = Mage::helper( 'ddg' )->getWebsiteApiClient( $website );
20
+ $programmes = $client->getPrograms();
21
+
22
+ foreach ( $programmes as $one ) {
23
+ if ( isset( $one->id ) ) {
24
+ $fields[] = array( 'value' => $one->id, 'label' => Mage::helper( 'ddg' )->__( $one->name ) );
25
+ }
26
+ }
27
+ }
28
+
29
+ return $fields;
30
+ }
31
+
32
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Campaigns.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $fields[] = array('value' => '0', 'label' => Mage::helper('ddg')->__('-- Please Select --'));
19
+
20
+ if ($websiteName) {
21
+ $website = Mage::app()->getWebsite($websiteName);
22
+ }
23
+
24
+ $enabled = Mage::helper('ddg')->isEnabled($website);
25
+
26
+ //api enabled get campaigns
27
+ if ($enabled) {
28
+ $client = Mage::helper( 'ddg' )->getWebsiteApiClient( $website );
29
+
30
+ $savedCampaigns = Mage::registry( 'savedcampigns' );
31
+
32
+ //get campaigns from registry
33
+ if ( $savedCampaigns ) {
34
+ $campaigns = $savedCampaigns;
35
+ } else {
36
+ $campaigns = $client->getCampaigns();
37
+ Mage::unregister( 'savedcampigns' );
38
+ Mage::register( 'savedcampigns', $campaigns );
39
+ }
40
+
41
+ foreach ( $campaigns as $one ) {
42
+ if ( isset( $one->id ) ) {
43
+ $fields[] = array(
44
+ 'value' => $one->id,
45
+ 'label' => Mage::helper( 'ddg' )->__( addslashes( $one->name ) )
46
+ );
47
+ }
48
+ }
49
+ }
50
+
51
+ return $fields;
52
+ }
53
+
54
+ }
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('ddg')->__('Imported'),
14
+ 'null' => Mage::helper('ddg')->__('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,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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('ddg');
13
+ //default data option
14
+ $fields[] = array('value' => 0, 'label' => Mage::helper('ddg')->__('-- Please Select --'));
15
+
16
+ $website = Mage::app()->getRequest()->getParam('website', 0);
17
+ $client = $helper->getWebsiteApiClient($website);
18
+
19
+ //get datafields options
20
+ if ($helper->isEnabled($website)) {
21
+
22
+ $savedDatafields = Mage::registry( 'datafields' );
23
+
24
+ //get saved datafileds from registry
25
+ if ( $savedDatafields ) {
26
+ $datafields = $savedDatafields;
27
+ } else {
28
+ //grab the datafields request and save to register
29
+ $datafields = $client->getDataFields();
30
+ Mage::register( 'datafields', $datafields );
31
+ }
32
+
33
+ //set the api error message for the first option
34
+ if ( isset( $datafields->message ) ) {
35
+
36
+ //message
37
+ $fields[] = array( 'value' => 0, 'label' => Mage::helper( 'ddg' )->__( $datafields->message ) );
38
+
39
+ } else {
40
+
41
+ //loop for all datafields option
42
+ foreach ( $datafields as $datafield ) {
43
+ if ( isset( $datafield->name ) ) {
44
+ $fields[] = array(
45
+ 'value' => $datafield->name,
46
+ 'label' => Mage::helper( 'ddg' )->__( $datafield->name )
47
+ );
48
+ }
49
+ }
50
+ }
51
+ }
52
+
53
+ return $fields;
54
+ }
55
+ }
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' => 'Private', 'label' => Mage::helper('ddg')->__('Private')),
12
+ array('value' => 'Public', 'label' => Mage::helper('ddg')->__('Public')),
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('ddg')->__('String')),
14
+ array('value' => 'Numeric', 'label' => Mage::helper('ddg')->__('Numeric')),
15
+ array('value' => 'Date', 'label' => Mage::helper('ddg')->__('Date')),
16
+ array('value' => 'Boolean', 'label' => Mage::helper('ddg')->__('Yes/No'))
17
+ );
18
+
19
+ return $dataType;
20
+ }
21
+
22
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Dynamic/Displaytype.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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('ddg')->__('Grid')),
14
+ array('value' => 'list', 'label' => Mage::helper('ddg')->__('List'))
15
+ );
16
+
17
+ }
18
+ }
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/Fontpicker.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Fontpicker
4
+ {
5
+ /**
6
+ * Options getter. web safe fonts
7
+ *
8
+ * @return array
9
+ */
10
+ public function toOptionArray()
11
+ {
12
+ return array(
13
+ array('value' => "Arial, Helvetica, sans-serif",
14
+ 'label' => Mage::helper('ddg')->__("Arial, Helvetica")),
15
+ array('value' => "'Arial Black', Gadget, sans-serif",
16
+ 'label' => Mage::helper('ddg')->__("Arial Black, Gadget")),
17
+ array('value' => "'Courier New', Courier, monospace",
18
+ 'label' => Mage::helper('ddg')->__("Courier New, Courier")),
19
+ array('value' => "Georgia, serif",
20
+ 'label' => Mage::helper('ddg')->__("Georgia")),
21
+ array('value' => "'MS Sans Serif', Geneva, sans-serif",
22
+ 'label' => Mage::helper('ddg')->__("MS Sans Serif, Geneva")),
23
+ array('value' => "'Palatino Linotype', 'Book Antiqua', Palatino, serif",
24
+ 'label' => Mage::helper('ddg')->__("Palatino Linotype, Book Antiqua")),
25
+ array('value' => "Tahoma, Geneva, sans-serif",
26
+ 'label' => Mage::helper('ddg')->__("Tahoma, Geneva")),
27
+ array('value' => "'Times New Roman', Times, serif",
28
+ 'label' => Mage::helper('ddg')->__("Times New Roman, Times")),
29
+ array('value' => "'Trebuchet MS', Helvetica, sans-serif",
30
+ 'label' => Mage::helper('ddg')->__("Trebuchet MS, Helvetica")),
31
+ array('value' => "Verdana, Geneva, sans-serif",
32
+ 'label' => Mage::helper('ddg')->__("Verdana, Geneva")),
33
+ );
34
+ }
35
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Fontsize.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Fontsize
4
+ {
5
+ /**
6
+ * Options getter. Styling options
7
+ *
8
+ * @return array
9
+ */
10
+ public function toOptionArray()
11
+ {
12
+ return array(
13
+ array('value' => '8px', 'label' => '8px'),
14
+ array('value' => '9px', 'label' => '9px'),
15
+ array('value' => '10px', 'label' => '10px'),
16
+ array('value' => '11px', 'label' => '11px'),
17
+ array('value' => '12px', 'label' => '12px'),
18
+ array('value' => '13px', 'label' => '13px'),
19
+ array('value' => '14px', 'label' => '14px'),
20
+ array('value' => '15px', 'label' => '15px'),
21
+ array('value' => '16px', 'label' => '16px'),
22
+ array('value' => '17px', 'label' => '17px'),
23
+ array('value' => '18px', 'label' => '18px'),
24
+ array('value' => '19px', 'label' => '19px'),
25
+ array('value' => '20px', 'label' => '20px'),
26
+ array('value' => '21px', 'label' => '21px'),
27
+ array('value' => '22px', 'label' => '22px'),
28
+ );
29
+ }
30
+ }
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( 'ddg' )->__( $one . ' Hour' )
27
+ );
28
+ } else {
29
+ $row = array(
30
+ 'value' => $one,
31
+ 'label' => Mage::helper( 'ddg' )->__( $one . ' Hours' )
32
+ );
33
+ }
34
+ $result[] = $row;
35
+ $i++;
36
+ }
37
+
38
+ return $result;
39
+ }
40
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Lostbaskets/Intervalminute.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Lostbaskets_Intervalminute
4
+ {
5
+ /**
6
+ * lost basket hour options
7
+ * @return array
8
+ */
9
+ public function toOptionArray()
10
+ {
11
+ return array(
12
+ array('value' => "15", 'label' => Mage::helper('ddg')->__('15 Minutes')),
13
+ array('value' => "20", 'label' => Mage::helper('ddg')->__('20 Minutes')),
14
+ array('value' => "25", 'label' => Mage::helper('ddg')->__('25 Minutes')),
15
+ array('value' => "30", 'label' => Mage::helper('ddg')->__('30 Minutes')),
16
+ array('value' => "40", 'label' => Mage::helper('ddg')->__('40 Minutes')),
17
+ array('value' => "50", 'label' => Mage::helper('ddg')->__('50 Minutes')),
18
+ array('value' => "60", 'label' => Mage::helper('ddg')->__('60 Minutes')),
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/Publicdatafields.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Publicdatafields
4
+ {
5
+ private function getWebsite()
6
+ {
7
+ $website = Mage::app()->getWebsite();
8
+ $websiteParam = Mage::app()->getRequest()->getParam('website');
9
+ if($websiteParam)
10
+ $website = Mage::app()->getWebsite($websiteParam);
11
+ return $website;
12
+ }
13
+
14
+ /**
15
+ * get data fields
16
+ *
17
+ * @return mixed
18
+ */
19
+ private function getDataFields()
20
+ {
21
+ $helper = Mage::helper('ddg');
22
+ $website = $this->getWebsite();
23
+ $client = $helper->getWebsiteApiClient($website);
24
+
25
+ //grab the datafields request and save to register
26
+ $datafields = $client->getDataFields();
27
+
28
+ return $datafields;
29
+ }
30
+
31
+ /**
32
+ * Datafields option.
33
+ * @return array
34
+ */
35
+ public function toOptionArray()
36
+ {
37
+ $fields = array();
38
+ $helper = Mage::helper('ddg');
39
+ $website = $this->getWebsite();
40
+
41
+ //get datafields options
42
+ if ($helper->isEnabled($website)) {
43
+ $datafields = $this->getDataFields();
44
+
45
+ //set the api error message for the first option
46
+ if ( isset( $datafields->message ) ) {
47
+ //message
48
+ $fields[] = array( 'value' => 0, 'label' => Mage::helper( 'ddg' )->__( $datafields->message ) );
49
+ } else {
50
+ //loop for all datafields option
51
+ foreach ( $datafields as $datafield ) {
52
+ if ( isset( $datafield->name ) && $datafield->visibility == 'Public') {
53
+ $fields[] = array(
54
+ 'value' => $datafield->name,
55
+ 'label' => Mage::helper( 'ddg' )->__( $datafield->name )
56
+ );
57
+ }
58
+ }
59
+ }
60
+ }
61
+ return $fields;
62
+ }
63
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Reviews/Campaigns.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Reviews_Campaigns
4
+ {
5
+
6
+ /**
7
+ * Returns account's Campaigns.
8
+ *
9
+ * @return array
10
+ * @throws Mage_Core_Exception
11
+ */
12
+ public function toOptionArray()
13
+ {
14
+ $fields = array();
15
+ $client = Mage::getModel('ddg_automation/apiconnector_client');
16
+
17
+ $website = Mage::app()->getRequest()->getParam('website', false);
18
+ if ($website) {
19
+ $website = Mage::app()->getWebsite($website);
20
+ } else {
21
+ $website = 0;
22
+ }
23
+ $client->setApiUsername(Mage::helper('ddg')->getApiUsername($website));
24
+ $client->setApiPassword(Mage::helper('ddg')->getApiPassword($website));
25
+
26
+ $savedCampaigns = Mage::registry('savedcampignsforreview');
27
+
28
+ if ($savedCampaigns) {
29
+ $campaigns = $savedCampaigns;
30
+ } else {
31
+ $campaigns = $client->getCampaigns();
32
+ Mage::unregister('savedcampignsforreview');
33
+ Mage::register('savedcampignsforreview', $campaigns);
34
+ }
35
+
36
+ $fields[] = array('value' => '0', 'label' => Mage::helper('ddg')->__('-- Please Select --'));
37
+
38
+ if (is_array($fields)) {
39
+ foreach ( $campaigns as $one ) {
40
+ if ( isset( $one->id ) )
41
+ $fields[] = array( 'value' => $one->id, 'label' => Mage::helper( 'ddg' )->__( addslashes($one->name)) );
42
+ }
43
+ }
44
+
45
+ return $fields;
46
+ }
47
+
48
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Reviews/Delay.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Reviews_Delay
4
+ {
5
+ /**
6
+ * Returns the values for field delay
7
+ * @return array
8
+ */
9
+ public function toOptionArray()
10
+ {
11
+ return array(
12
+ array('value' => '', 'label' => Mage::helper('ddg')->__('-- Please Select --')),
13
+ array('value' => 1, 'label' => '1'),
14
+ array('value' => 2, 'label' => '2'),
15
+ array('value' => 3, 'label' => '3'),
16
+ array('value' => 4, 'label' => '4'),
17
+ array('value' => 5, 'label' => '5'),
18
+ array('value' => 6, 'label' => '6'),
19
+ array('value' => 7, 'label' => '7'),
20
+ array('value' => 14, 'label' => '14'),
21
+ array('value' => 30, 'label' => '30'),
22
+ array('value' => 60, 'label' => '60'),
23
+ array('value' => 90, 'label' => '90')
24
+ );
25
+ }
26
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Styling.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Styling
4
+ {
5
+ /**
6
+ * Options getter. Styling options
7
+ *
8
+ * @return array
9
+ */
10
+ public function toOptionArray()
11
+ {
12
+ return array(
13
+ array('value' => 'bold', 'label' => 'Bold'),
14
+ array('value' => 'italic', 'label' => 'Italic'),
15
+ array('value' => 'underline', 'label' => 'Underline')
16
+ );
17
+ }
18
+ }
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('ddg')->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/Yesno.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Transactional_Yesno
4
+ {
5
+
6
+ /**
7
+ * Options getter
8
+ *
9
+ * @return array
10
+ */
11
+ public function toOptionArray()
12
+ {
13
+ $status = Mage::helper('ddg')->isSmtpEnabled();
14
+ if (!$status) {
15
+ return array(
16
+ array('value' => 0, 'label'=> Mage::helper('adminhtml')->__('No')),
17
+ );
18
+ } else {
19
+ return array(
20
+ array('value' => 0, 'label' => Mage::helper('adminhtml')->__('No')),
21
+ array('value' => 1, 'label' => Mage::helper('adminhtml')->__('Yes'))
22
+ );
23
+ }
24
+ }
25
+
26
+ }
app/code/community/Dotdigitalgroup/Email/Model/Api2/Subscriber/Rest/Admin/V1.php ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Model_Api2_Subscriber_Rest_Admin_V1 extends Mage_Api2_Model_Resource
3
+ {
4
+
5
+ /**
6
+ * Create a subscriber
7
+ * @return array
8
+ */
9
+
10
+ public function _create() {
11
+ //Create Subscriber
12
+ $requestData = $this->getRequest()->getBodyParams();
13
+
14
+ $email = $requestData['subscriber_email'];
15
+ //email is set
16
+ if ($email) {
17
+ try {
18
+ $customerId = (isset($requestData['customer_id']))? $requestData['customer_id'] : 0;
19
+ $storeId = (isset($requestData['store_id']))? $requestData['store_id'] : 1;
20
+ //subscriber status 1- subscribed, 3 - unsubscribed
21
+ $status = (isset($requestData['status']))? $requestData['status'] : 3;
22
+ //additional data for subscriber
23
+ $data = array(
24
+ 'subscriber_email' => $email,
25
+ 'customer_id' => $customerId,
26
+ 'subscriber_status' => $status,
27
+ 'store_id' => $storeId
28
+ );
29
+
30
+ //save subscriber
31
+ Mage::getModel('newsletter/subscriber')->setData($data)
32
+ ->save();
33
+
34
+ }catch (Mage_Api2_Exception $e){
35
+ Mage::helper('ddg')->log($e->getMessage());
36
+ }catch (Exception $e){
37
+ Mage::logException($e);
38
+ }
39
+
40
+ $json = array('email' => $email);
41
+ echo json_encode($json);
42
+ }
43
+
44
+ }
45
+
46
+ /**
47
+ * Retrieve a subscriber name by email
48
+ * @return string
49
+ */
50
+
51
+ public function _retrieve()
52
+ {
53
+ $email = $this->getRequest()->getParam('email', false);
54
+ if (! $email) {
55
+ Mage::helper('ddg')->log('Subscriber id is not set');
56
+ return array();
57
+ }
58
+ try {
59
+
60
+ $data = Mage::getModel('newsletter/subscriber')->loadByEmail($email)->getData();
61
+ return json_encode($data);
62
+
63
+ }catch (Mage_Api2_Exception $e){
64
+ Mage::helper('ddg')->log($e->getMessage());
65
+ }catch (Exception $e){
66
+ Mage::logException($e);
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Update subscriber data.
72
+ * @throws Exception
73
+ */
74
+ public function _update()
75
+ {
76
+ //Update Subscriber
77
+ $requestData = $this->getRequest()->getBodyParams();
78
+
79
+ //check for scubscriber email
80
+ if ($email = $requestData['subscriber_email']) {
81
+ try {
82
+ $customerId = ( isset( $requestData['customer_id'] ) ) ? $requestData['customer_id'] : 0;
83
+ $storeId = ( isset( $requestData['store_id'] ) ) ? $requestData['store_id'] : 1;
84
+ //subscriber status 1- subscribed, 3 - unsubscribed
85
+ $status = ( isset( $requestData['status'] ) ) ? $requestData['status'] : 3;
86
+ //additional data for subscriber
87
+ $data = array(
88
+ 'customer_id' => $customerId,
89
+ 'subscriber_status' => $status,
90
+ 'store_id' => $storeId
91
+ );
92
+ //update subscriber
93
+ $subscriber = Mage::getModel( 'newsletter/subscriber' )->loadByEmail( $email );
94
+ if ( $subscriber->getId() ) {
95
+ $subscriber->setCustomerId( $customerId )
96
+ ->setSubscriberStatus( $status )
97
+ ->setStoreId( $storeId )
98
+ ->save();
99
+ } else {
100
+ Mage::helper( 'ddg' )->log( "REST Subscriber not found : " . $email);
101
+ }
102
+
103
+ echo json_encode( $data );
104
+ }catch (Mage_Api2_Exception $e){
105
+ Mage::helper('ddg')->log($e->getMessage());
106
+ }catch (Exception $e){
107
+ Mage::logException($e);
108
+ }
109
+ }
110
+ }
111
+ }
app/code/community/Dotdigitalgroup/Email/Model/Apiconnector/Client.php ADDED
@@ -0,0 +1,1291 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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://apiconnector.com/v2/programs/';
24
+ const REST_PROGRAM_ENROLMENTS = 'https://apiconnector.com/v2/programs/enrolments';
25
+ const REST_TEMPLATES = 'https://apiconnector.com/v2/templates';
26
+
27
+ //rest error responces
28
+ const API_ERROR_API_EXCEEDED = 'Your account has generated excess API activity and is being temporarily capped. Please contact support. ERROR_APIUSAGE_EXCEEDED';
29
+ const API_ERROR_TRANS_ALLOWANCE = 'TransactionalDataAllowanceInMegabytes';
30
+ const API_ERROR_EMAIL_NOT_VALID = 'Email is not a valid email address. ERROR_PARAMETER_INVALID';
31
+ const API_ERROR_FEATURENOTACTIVE = 'Error: ERROR_FEATURENOTACTIVE';
32
+ const API_ERROR_REPORT_NOT_FOUND = 'Import is not processed yet or completed with error. ERROR_IMPORT_REPORT_NOT_FOUND';
33
+ const API_ERROR_TRANS_NOT_EXISTS = 'Error: ERROR_TRANSACTIONAL_DATA_DOES_NOT_EXIST';
34
+ const API_ERROR_DATAFIELD_EXISTS = 'Field already exists. ERROR_NON_UNIQUE_DATAFIELD';
35
+ const API_ERROR_CONTACT_NOT_FOUND = 'Error: ERROR_CONTACT_NOT_FOUND';
36
+ const API_ERROR_PROGRAM_NOT_ACTIVE = 'Error: ERROR_PROGRAM_NOT_ACTIVE';
37
+ const API_ERROR_ENROLMENT_EXCEEDED = 'Error: ERROR_ENROLMENT_ALLOWANCE_EXCEEDED ';
38
+ const API_ERROR_SEND_NOT_PERMITTED = 'Send not permitted at this time. ERROR_CAMPAIGN_SENDNOTPERMITTED';
39
+ const API_ERROR_CONTACT_SUPPRESSED = 'Contact is suppressed. ERROR_CONTACT_SUPPRESSED';
40
+ const API_ERROR_AUTHORIZATION_DENIED = 'Authorization has been denied for this request.';
41
+ const API_ERROR_ADDRESSBOOK_NOT_FOUND = 'Error: ERROR_ADDRESSBOOK_NOT_FOUND';
42
+
43
+
44
+
45
+ protected $_limit = 10;
46
+ public $fileHelper;
47
+ protected $_filename;
48
+ protected $_api_helper;
49
+ protected $_address_book_id;
50
+ protected $_customers_filename;
51
+ protected $_subscribers_filename;
52
+ protected $_customers_address_book_id;
53
+ protected $_subscribers_address_book_id;
54
+ protected $_customers_file_slug = 'customer_sync';
55
+ protected $_subscribers_file_slug = 'subscriber_sync';
56
+ public $result = array('error' => false, 'message' => '');
57
+
58
+
59
+ public $apiCalls = array(
60
+ 'getContactById' => 'get_contact_by_id',
61
+ 'postAddressBookContactsImport' => 'post_address_book_contacts_import',
62
+ 'postAddressBookContacts' => 'post_address_book_contacts',
63
+ 'deleteAddressBookContact' => 'delete_address_book_contact',
64
+ 'getContactsImportReport' => 'get_contacts_import',
65
+ 'getContactByEmail' => 'get_contact_by_email',
66
+ 'getAddressBooks' => 'get_address_books',
67
+ 'postAddressBooks' => 'post_address_books',
68
+ 'getAddressBookById' => 'get_address_book_by_id',
69
+ 'getCampaigns' => 'get_campaigns',
70
+ 'postDataFields' => 'post_data_fields',
71
+ 'deleteDataField' => 'delete_data_field',
72
+ 'getDataFields' => 'get_data_fields',
73
+ 'updateContact' => 'update_contact',
74
+ 'deleteContact' => 'delete_contact',
75
+ 'updateContactDatafieldsByEmail' => 'update_contact_datafields_by_email',
76
+ 'postCampaignsSend' => 'post_campaigns_send',
77
+ 'postContacts' => 'post_contacts',
78
+ 'getContactsSuppressedSinceDate' => 'get_contacts_suppressed_sinse_date',
79
+ 'postContactsTransactionalDataImport' => 'post_contacts_transactional_data_import',
80
+ 'postContactsTransactionalData' => 'post_contacts_transactional_data',
81
+ 'getContactsTransactionalDataByKey' => 'get_contacts_transactional_data_by_key',
82
+ 'deleteContactTransactionalData' => 'delete_contact_transactional_data',
83
+ 'getAccountInfo' => 'get_account_info',
84
+ 'postSmsMessagesSendTo' => 'post_sms_message_send_to',
85
+ 'deleteAddressBookContactsInbulk' => 'delete_addess_book_contacts_in_bulk',
86
+ 'postContactsResubscribe' => 'post_contacts_resubscribe',
87
+ 'getCustomFromAddresses' => 'get_custom_fromaddresses',
88
+ 'postCampaign' => 'post_campaign',
89
+ 'getPrograms' => 'get_programs',
90
+ 'postProgramsEnrolments' => 'post_programs_enrolments',
91
+ 'getProgramById' => 'get_program_by_id',
92
+ 'getCampaignSummary' => 'get_campaign_summary',
93
+ 'deleteContactsTransactionalData' => 'delete_contacts_transactional_data',
94
+ 'getContactAddressBooks' => 'get_contact_addressBooks',
95
+ 'getApiTemplateList' => 'get_api_template_list',
96
+ 'getApiTemplate' => 'get_api_template',
97
+ 'postAccountTransactionalDataImport' => 'post_account_transactional_data_import',
98
+ 'getCampaignsWithActivitySinceDate' => 'get_campaigns_with_activity_since_date',
99
+ 'getCampaignActivityByContactId' => 'get_campaign_activity_by_contact_id',
100
+ 'getContactsImportByImportId' => 'get_contacts_import_by_import_id',
101
+ 'getContactsTransactionalDataImportByImportId' => 'get_contacts_transactional_data_import_by_import_id'
102
+ );
103
+
104
+
105
+
106
+ /**
107
+ * constructor.
108
+ */
109
+ public function __construct()
110
+ {
111
+ parent::__construct();
112
+ }
113
+
114
+ /**
115
+ * Excluded api response that we don't want to send.
116
+ * @var array
117
+ */
118
+ public $exludeMessages = array(
119
+ self::API_ERROR_FEATURENOTACTIVE,
120
+ self::API_ERROR_PROGRAM_NOT_ACTIVE,
121
+ self::API_ERROR_CONTACT_SUPPRESSED,
122
+ self::API_ERROR_DATAFIELD_EXISTS,
123
+ self::API_ERROR_AUTHORIZATION_DENIED,
124
+ self::API_ERROR_ENROLMENT_EXCEEDED,
125
+ self::API_ERROR_SEND_NOT_PERMITTED,
126
+ self::API_ERROR_TRANS_NOT_EXISTS,
127
+ self::API_ERROR_ADDRESSBOOK_NOT_FOUND
128
+ );
129
+
130
+ /**
131
+ * @param $apiUsername
132
+ * @param $apiPassword
133
+ * @return bool|mixed
134
+ */
135
+ public function validate($apiUsername, $apiPassword)
136
+ {
137
+ if ($apiUsername && $apiPassword) {
138
+ $this->setApiUsername($apiUsername)
139
+ ->setApiPassword($apiPassword);
140
+ $accountInfo = $this->getAccountInfo();
141
+
142
+ if (isset($accountInfo->message)) {
143
+ Mage::getSingleton('adminhtml/session')->addError($accountInfo->message);
144
+ $message = 'VALIDATION ERROR : ' . $accountInfo->message;
145
+ Mage::helper('ddg')->log($message);
146
+ return false;
147
+ }
148
+ return $accountInfo;
149
+ }
150
+ return false;
151
+ }
152
+ /**
153
+ * Gets a contact by ID. Unsubscribed or suppressed contacts will not be retrieved.
154
+ * @param $id
155
+ * @return null
156
+ */
157
+ public function getContactById($id)
158
+ {
159
+ $url = self::REST_CONTACTS . $id;
160
+ $this->setUrl($url)
161
+ ->setVerb('GET');
162
+ $response = $this->execute();
163
+
164
+ if(isset($response->message)) {
165
+ $message = 'GET CONTACT INFO ID ' . $url . ', ' . $response->message;
166
+ Mage::helper( 'ddg' )->log( $message );
167
+ }
168
+
169
+ return $response;
170
+ }
171
+
172
+ /**
173
+ * Bulk creates, or bulk updates, contacts. Import format can either be CSV or Excel.
174
+ * Must include one column called "Email". Any other columns will attempt to map to your custom data fields.
175
+ * The ID of returned object can be used to query import progress.
176
+ * @param $filename
177
+ * @param $addressBookId
178
+ * @return mixed
179
+ */
180
+
181
+ public function postAddressBookContactsImport($filename, $addressBookId)
182
+ {
183
+ $url = "https://apiconnector.com/v2/address-books/{$addressBookId}/contacts/import";
184
+ $helper = Mage::helper('ddg');
185
+
186
+ $ch = curl_init($url);
187
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
188
+ curl_setopt($ch, CURLOPT_USERPWD, $this->getApiUsername() . ':' . $this->getApiPassword());
189
+
190
+ //case the deprication of @filename for uploading
191
+ if (function_exists('curl_file_create')) {
192
+ curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
193
+ $args['file'] = curl_file_create(Mage::helper('ddg/file')->getFilePath($filename), 'text/csv');
194
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
195
+
196
+ } else {
197
+ //standart use of curl file
198
+ curl_setopt($ch, CURLOPT_POSTFIELDS, array (
199
+ 'file' => '@'.Mage::helper('ddg/file')->getFilePath($filename)
200
+ ));
201
+ }
202
+
203
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
204
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
205
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array(
206
+ 'Content-Type: multipart/form-data')
207
+ );
208
+
209
+ // send contacts to address book
210
+ $result = curl_exec($ch);
211
+ $result = json_decode($result);
212
+ if (isset($result->message)) {
213
+ $message = 'POST ADDRESS BOOK ' . $addressBookId . ', CONTACT IMPORT : ' . ' filename ' . $filename . ' Username ' . $this->getApiUsername() . $result->message;
214
+ $helper->log($message);
215
+ Mage::helper('ddg')->log($result);
216
+ Mage::helper('ddg')->rayLog('205', $message, __FILE__, __LINE__);
217
+ }
218
+ return $result;
219
+ }
220
+
221
+ /**
222
+ * Adds a contact to a given address book.
223
+ * @param $addressBookId
224
+ * @param $apiContact
225
+ * @return mixed|null
226
+ */
227
+ public function postAddressBookContacts($addressBookId, $apiContact)
228
+ {
229
+ $url = self::REST_ADDRESS_BOOKS . $addressBookId . '/contacts';
230
+ $this->setUrl($url)
231
+ ->setVerb("POST")
232
+ ->buildPostBody($apiContact);
233
+
234
+ $response = $this->execute();
235
+ if (isset($response->message)) {
236
+
237
+ $message = 'POST ADDRESS BOOK CONTACTS ' . $url . ', ' . $response->message;
238
+ Mage::helper('ddg')->log($message);
239
+ if (! in_array($response->message, $this->exludeMessages)) {
240
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
241
+
242
+
243
+ }
244
+ }
245
+
246
+ return $response;
247
+ }
248
+
249
+ /**
250
+ * Deletes all contacts from a given address book.
251
+ * @param $addressBookId
252
+ * @param $contactId
253
+ * @return null
254
+ */
255
+ public function deleteAddressBookContact($addressBookId, $contactId)
256
+ {
257
+
258
+ $url = self::REST_ADDRESS_BOOKS . $addressBookId . '/contacts/' . $contactId;
259
+ $this->setUrl($url)
260
+ ->setVerb('DELETE');
261
+ $response = $this->execute();
262
+
263
+ return $response;
264
+ }
265
+
266
+ /**
267
+ * Gets a report with statistics about what was successfully imported, and what was unable to be imported.
268
+ * @param $importId
269
+ * @return mixed
270
+ */
271
+ public function getContactsImportReport($importId)
272
+ {
273
+
274
+ $url = self::REST_CONTACTS_IMPORT . $importId . "/report";
275
+ $this->setUrl($url)
276
+ ->setVerb('GET');
277
+ $response = $this->execute();
278
+ if (isset($response->message)) {
279
+ $message = 'GET CONTACTS IMPORT REPORT . ' . $url . ' message : ' . $response->message;
280
+ Mage::helper( 'ddg' )->log( $message );
281
+ if (! in_array($response->message, $this->exludeMessages))
282
+ Mage::helper( 'ddg' )->rayLog( '100', $message, 'apiconnector/client.php', __LINE__);
283
+ }
284
+ return $response;
285
+ }
286
+
287
+ /**
288
+ * Gets a contact by email address.
289
+ * @param $email
290
+ * @return mixed
291
+ */
292
+ public function getContactByEmail($email)
293
+ {
294
+ $url = self::REST_CONTACTS . $email;
295
+ $this->setUrl($url)
296
+ ->setVerb('GET');
297
+
298
+ //should create new one if not exists?!?
299
+ $response = $this->execute();
300
+ if (isset($response->message)) {
301
+ $message = 'GET CONTACT BY email : ' . $email . ' ' . $response->message;
302
+ Mage::helper('ddg')->log($message);
303
+ if (! in_array($response->message, $this->exludeMessages))
304
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
305
+ }
306
+
307
+ return $response;
308
+ }
309
+
310
+ /**
311
+ * Get all address books.
312
+ * @return null
313
+ */
314
+ public function getAddressBooks()
315
+ {
316
+ $url = self::REST_ADDRESS_BOOKS;
317
+ $this->setUrl($url)
318
+ ->setVerb("GET");
319
+
320
+ $response = $this->execute();
321
+ if (isset($response->message)) {
322
+ $message = 'GET ALL ADDRESS BOOKS : ' . $url . ', ' . $response->message;
323
+ Mage::helper('ddg')->log($message);
324
+ if (! in_array($response->message, $this->exludeMessages))
325
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
326
+ }
327
+ return $response;
328
+ }
329
+
330
+ /**
331
+ * Gets an address book by ID.
332
+ * @param $id
333
+ *
334
+ * @return null
335
+ * @throws Exception
336
+ */
337
+ public function getAddressBookById($id)
338
+ {
339
+ $url = self::REST_ADDRESS_BOOKS . $id;
340
+
341
+ $this->setUrl($url)
342
+ ->setVerb('GET');
343
+
344
+ $response = $this->execute();
345
+
346
+ if (isset($response->message)) {
347
+ $message = 'GET ADDRESS BOOK BY ID '. $id . ', ' . $response->message;
348
+ Mage::helper('ddg')->log($message);
349
+ }
350
+
351
+ return $response;
352
+ }
353
+
354
+ /**
355
+ * Creates an address book.
356
+ * @param $name
357
+ * @return null
358
+ */
359
+ public function postAddressBooks($name, $visibility = 'Public')
360
+ {
361
+ $data = array(
362
+ 'Name' => $name,
363
+ 'Visibility' => $visibility
364
+ );
365
+ $url = self::REST_ADDRESS_BOOKS;
366
+ $this->setUrl($url)
367
+ ->setVerb('POST')
368
+ ->buildPostBody($data);
369
+
370
+ $response = $this->execute();
371
+ if (isset($response->message)) {
372
+ $message = 'Postaddressbooks ' . $response->message . ', url :' . $url ;
373
+ Mage::helper('ddg')->log($message);
374
+ if (! in_array($response->message, $this->exludeMessages))
375
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
376
+ }
377
+ return $response;
378
+ }
379
+
380
+ /**
381
+ * Get list of all campaigns.
382
+ * @return mixed
383
+ */
384
+ public function getCampaigns()
385
+ {
386
+ $url = self::REST_DATA_FIELDS_CAMPAIGNS;
387
+ $this->setUrl($url)
388
+ ->setVerb('GET');
389
+
390
+ $response = $this->execute();
391
+
392
+ if (isset($response->message)) {
393
+ $message = 'GET CAMPAIGNS ' . $response->message . ' api user : ' . $this->getApiUsername();
394
+ Mage::helper('ddg')->log($message);
395
+ if (! in_array($response->message, $this->exludeMessages))
396
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
397
+ }
398
+
399
+ return $response;
400
+ }
401
+
402
+ /**
403
+ * Creates a data field within the account.
404
+ * @param $data string/array
405
+ * @param string $type string, numeric, date, boolean
406
+ * @param string $visibility public, private
407
+ * @param bool $defaultValue
408
+ * @return mixed
409
+ */
410
+ public function postDataFields($data, $type = 'String', $visibility = 'public', $defaultValue = false)
411
+ {
412
+ $url = self::REST_DATA_FILEDS;
413
+ //set default value for the numeric datatype
414
+ if($type == 'numeric' && !$defaultValue)
415
+ $defaultValue = 0;
416
+ //set data for the string datatype
417
+ if (is_string($data)) {
418
+ $data = array(
419
+ 'Name' => $data,
420
+ 'Type' => $type,
421
+ 'Visibility' => $visibility
422
+ );
423
+ //default value
424
+ if($defaultValue)
425
+ $data['DefaultValue'] = $defaultValue;
426
+ }
427
+ $this->setUrl($url)
428
+ ->buildPostBody($data)
429
+ ->setVerb('POST');
430
+
431
+ $response = $this->execute();
432
+
433
+ if (isset($response->message)) {
434
+ $message = 'POST CREATE DATAFIELDS ' . $response->message;
435
+ Mage::helper('ddg')->log($message);
436
+ Mage::helper('ddg')->log($data);
437
+ if (! in_array($response->message, $this->exludeMessages))
438
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
439
+ }
440
+
441
+ return $response;
442
+ }
443
+
444
+ /**
445
+ * Deletes a data field within the account.
446
+ * @param $name
447
+ *
448
+ * @return mixed
449
+ */
450
+ public function deleteDataField($name)
451
+ {
452
+ $url = self::REST_DATA_FILEDS . '/' . $name;
453
+ $request = Mage::helper('ddg/api_restrequest');
454
+ $request->setUrl($url)
455
+ ->setVerb('DELETE');
456
+
457
+ $response = $request->execute();
458
+ if (isset($response->message)) {
459
+ $message = 'DELETE DATA FIELD :' . $name . ' ' . $response->message;
460
+ Mage::helper('ddg')->log($message);
461
+ if (! in_array($response->message, $this->exludeMessages))
462
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
463
+ }
464
+ return $request->execute();
465
+ }
466
+
467
+ /**
468
+ * Lists the data fields within the account.
469
+ * @return mixed
470
+ */
471
+ public function getDataFields()
472
+ {
473
+
474
+
475
+ $url = self::REST_DATA_FILEDS;
476
+ $this->setUrl($url)
477
+ ->setVerb('GET');
478
+
479
+ $response = $this->execute();
480
+ if (isset($response->message)) {
481
+ $message = 'GET ALL DATAFIELDS ' . $response->message;
482
+ Mage::helper('ddg')->log($message);
483
+ if (! in_array($response->message, $this->exludeMessages))
484
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
485
+ }
486
+
487
+ return $response;
488
+ }
489
+
490
+ /**
491
+ * Updates a contact.
492
+ * @param $contactId
493
+ * @param $data
494
+ * @return object
495
+ */
496
+ public function updateContact($contactId, $data)
497
+ {
498
+
499
+ $url = self::REST_CONTACTS . $contactId;
500
+ $this->setUrl($url)
501
+ ->setVerb('PUT')
502
+ ->buildPostBody($data);
503
+
504
+ $response = $this->execute();
505
+ if (isset($response->message)) {
506
+ $message = 'ERROR : UPDATE SINGLE CONTACT : ' . $url . ' message : ' . $response->message;
507
+ Mage::helper('ddg')->log($message);
508
+ Mage::helper('ddg')->log($data);
509
+ if (! in_array($response->message, $this->exludeMessages))
510
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
511
+ }
512
+
513
+ return $response;
514
+ }
515
+
516
+ /**
517
+ * Deletes a contact.
518
+ * @param $contactId
519
+ * @return null
520
+ */
521
+ public function deleteContact($contactId)
522
+ {
523
+
524
+
525
+ $url = self::REST_CONTACTS . $contactId;
526
+ $this->setUrl($url)
527
+ ->setVerb('DELETE');
528
+
529
+ $response = $this->execute();
530
+
531
+ if (isset($response->message)) {
532
+ $message = 'DELETE CONTACT : ' . $url . ', ' . $response->message;
533
+ Mage::helper('ddg')->log($message);
534
+ if (! in_array($response->message, $this->exludeMessages))
535
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
536
+ }
537
+ return $response;
538
+ }
539
+
540
+ /**
541
+ * Update contact datafields by email.
542
+ * @param $email
543
+ * @param $dataFields
544
+ *
545
+ * @return null
546
+ * @throws Exception
547
+ */
548
+ public function updateContactDatafieldsByEmail($email, $dataFields)
549
+ {
550
+
551
+
552
+ $apiContact = $this->postContacts($email);
553
+ //do not create for non contact id set
554
+ if (! isset($apiContact->id)) {
555
+ return $apiContact;
556
+ } else {
557
+ //get the contact id for this email
558
+ $contactId = $apiContact->id;
559
+ }
560
+ $data = array(
561
+ 'Email' => $email,
562
+ 'EmailType' => 'Html');
563
+ $data['DataFields'] = $dataFields;
564
+ $url = self::REST_CONTACTS . $contactId;
565
+ $this->setUrl($url)
566
+ ->setVerb('PUT')
567
+ ->buildPostBody($data);
568
+
569
+ $response = $this->execute();
570
+ if (isset($response->message)) {
571
+ $message = 'ERROR: UPDATE CONTACT DATAFIELD ' . $url . ' message : ' . $response->message;
572
+ Mage::helper('ddg')->log($message);
573
+ Mage::helper('ddg')->log($data);
574
+ if (! in_array($response->message, $this->exludeMessages))
575
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
576
+ }
577
+
578
+ return $response;
579
+ }
580
+
581
+ /**
582
+ * Sends a specified campaign to one or more address books, segments or contacts at a specified time.
583
+ * Leave the address book array empty to send to All Contacts.
584
+ * @param $campaignId
585
+ * @param $contacts
586
+ * @return mixed
587
+ */
588
+ public function postCampaignsSend($campaignId, $contacts)
589
+ {
590
+
591
+
592
+ $helper = Mage::helper('ddg');
593
+ $data = array(
594
+ 'username' => $this->getApiUsername(),
595
+ 'password' => $this->getApiPassword(),
596
+ "campaignId" => $campaignId,
597
+ "ContactIds" => $contacts
598
+ );
599
+ $this->setUrl(self::REST_CAMPAIGN_SEND)
600
+ ->setVerb('POST')
601
+ ->buildPostBody($data);
602
+
603
+ $response = $this->execute();
604
+ if (isset($response->message)) {
605
+ $message = 'SENDING CAMPAIGN ' . $response->message;
606
+ $helper->log($message);
607
+ $helper->log($data);
608
+ if (! in_array($response->message, $this->exludeMessages))
609
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
610
+ }
611
+
612
+ return $response;
613
+ }
614
+
615
+ /**
616
+ * Creates a contact.
617
+ * @param $email
618
+ * @return mixed
619
+ */
620
+ public function postContacts($email)
621
+ {
622
+
623
+
624
+ $url = self::REST_CONTACTS;
625
+ $data = array(
626
+ 'Email' => $email,
627
+ 'EmailType' => 'Html',
628
+ );
629
+ $this->setUrl($url)
630
+ ->setVerb('POST')
631
+ ->buildPostBody($data);
632
+
633
+ $response = $this->execute();
634
+ if (isset($response->message)) {
635
+ $message = 'CREATE A NEW CONTACT : ' . $email . ' , url ' . $url . ', ' . $response->message;
636
+ Mage::helper('ddg')->log($message);
637
+ if (! in_array($response->message, $this->exludeMessages))
638
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
639
+ }
640
+
641
+ return $response;
642
+ }
643
+
644
+
645
+ /**
646
+ * Gets a list of suppressed contacts after a given date along with the reason for suppression.
647
+ * @param $dateString
648
+ * @param $select
649
+ * @param $skip
650
+ * @return object
651
+ */
652
+ public function getContactsSuppressedSinceDate($dateString, $select = 1000, $skip = 0)
653
+ {
654
+
655
+
656
+ $url = self::REST_CONTACTS_SUPPRESSED_SINCE . $dateString . '?select=' . $select . '&skip=' . $skip;
657
+ $this->setUrl($url)
658
+ ->setVerb("GET");
659
+
660
+ $response = $this->execute();
661
+
662
+ if (isset($response->message)) {
663
+ $message = 'GET CONTACTS SUPPRESSED SINSE : ' . $dateString . ' select ' . $select . ' skip : ' . $skip . ' response : ' . $response->message;
664
+ Mage::helper('ddg')->log($message);
665
+ if (! in_array($response->message, $this->exludeMessages))
666
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
667
+ }
668
+
669
+ return $response;
670
+ }
671
+
672
+ /**
673
+ * Adds multiple pieces of transactional data to contacts asynchronously, returning an identifier that can be used to check for import progress.
674
+ * @param $collectionName
675
+ * @param $transactionalData
676
+ * @return object
677
+ */
678
+ public function postContactsTransactionalDataImport($transactionalData, $collectionName = 'Orders')
679
+ {
680
+ $orders = array();
681
+ foreach ($transactionalData as $one) {
682
+ if (isset($one->email)) {
683
+ $orders[] = array(
684
+ 'Key' => $one->id,
685
+ 'ContactIdentifier' => $one->email,
686
+ 'Json' => json_encode($one)
687
+ );
688
+ }
689
+ }
690
+ $url = self::REST_TRANSACTIONAL_DATA_IMPORT . $collectionName;
691
+ $this->setURl($url)
692
+ ->setVerb('POST')
693
+ ->buildPostBody($orders);
694
+
695
+ $response = $this->execute();
696
+
697
+ if (isset($response->message)) {
698
+ $message = ' SEND MULTI TRANSACTIONAL DATA ' . $response->message;
699
+ Mage::helper('ddg')->log($message);
700
+ if (! in_array($response->message, $this->exludeMessages))
701
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
702
+ }
703
+
704
+ return $response;
705
+ }
706
+
707
+ /**
708
+ * Adds a single piece of transactional data to a contact.
709
+ *
710
+ * @param $data
711
+ * @param string $collectionName
712
+ *
713
+ * @return null
714
+ * @throws Exception
715
+ */
716
+ public function postContactsTransactionalData($data, $collectionName = 'Orders')
717
+ {
718
+ $order = $this->getContactsTransactionalDataByKey($collectionName, $data->id);
719
+ if(isset($order->message) && $order->message == self::API_ERROR_TRANS_NOT_EXISTS){
720
+ $url = self::REST_TRANSACTIONAL_DATA . $collectionName;
721
+ }else{
722
+ $url = self::REST_TRANSACTIONAL_DATA . $collectionName . '/' . $order->key ;
723
+ }
724
+ $apiData = array(
725
+ 'Key' => $data->id,
726
+ 'Json' => json_encode($data->expose())
727
+ );
728
+
729
+ $this->setUrl($url)
730
+ ->setVerb('POST')
731
+ ->buildPostBody($apiData);
732
+ $response = $this->execute();
733
+
734
+ if (isset($response->message)) {
735
+ $message = 'POST CONTACTS TRANSACTIONAL DATA ' . $response->message;
736
+ Mage::helper('ddg')->log($message);
737
+ Mage::helper('ddg')->log($apiData);
738
+ if (! in_array($response->message, $this->exludeMessages))
739
+ Mage::helper('ddg')->rayLog('100', $message, __FILE__, __LINE__);
740
+ }
741
+
742
+ return $response;
743
+ }
744
+
745
+ /**
746
+ * Gets a piece of transactional data by key.
747
+ * @param $name
748
+ * @param $key
749
+ * @return null
750
+ */
751
+ public function getContactsTransactionalDataByKey($name, $key)
752
+ {
753
+ $url = self::REST_TRANSACTIONAL_DATA . $name . '/' . $key;
754
+ $this->setUrl($url)
755
+ ->setVerb('GET');
756
+
757
+ return $this->execute();
758
+ }
759
+
760
+ /**
761
+ * Deletes all transactional data for a contact.
762
+ * @param $email
763
+ * @param string $collectionName
764
+ * @return object
765
+ */
766
+ public function deleteContactTransactionalData($email, $collectionName = 'Orders')
767
+ {
768
+ $url = 'https://apiconnector.com/v2/contacts/' . $email . '/transactional-data/' . $collectionName ;
769
+ $this->setUrl($url)
770
+ ->setVerb('DELETE');
771
+
772
+ return $this->execute();
773
+ }
774
+
775
+ /**
776
+ * Gets a summary of information about the current status of the account.
777
+ * @return mixed
778
+ */
779
+ public function getAccountInfo()
780
+ {
781
+
782
+ $url = self::REST_ACCOUNT_INFO;
783
+ $this->setUrl($url)
784
+ ->setVerb('GET');
785
+
786
+ $response = $this->execute();
787
+ if (isset($response->message)) {
788
+ $message = 'GET ACCOUNT INFO for api user : ' . $this->getApiUsername() . ' ' . $response->message;
789
+ Mage::helper('ddg')->log($message);
790
+ if (! in_array($response->message, $this->exludeMessages))
791
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
792
+ }
793
+
794
+ return $response;
795
+ }
796
+
797
+ /**
798
+ * Send a single SMS message.
799
+ * @param $telephoneNumber
800
+ * @param $message
801
+ * @return object
802
+ */
803
+ public function postSmsMessagesSendTo($telephoneNumber, $message)
804
+ {
805
+
806
+
807
+ $data = array('Message' => $message);
808
+ $url = self::REST_SMS_MESSAGE_SEND_TO . $telephoneNumber;
809
+ $this->setUrl($url)
810
+ ->setVerb('POST')
811
+ ->buildPostBody($data);
812
+
813
+ $response = $this->execute();
814
+ if (isset($response->message)) {
815
+ $message = 'POST SMS MESSAGE SEND to ' . $telephoneNumber . ' message: ' . $message . ' error: ' . $response->message;
816
+ Mage::helper('ddg')->log($message);
817
+ if (! in_array($response->message, $this->exludeMessages))
818
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
819
+ }
820
+
821
+ return $response;
822
+ }
823
+
824
+
825
+ /**
826
+ * Deletes multiple contacts from an address book.
827
+ * @param $addressBookId
828
+ * @param $contactIds
829
+ * @return object
830
+ */
831
+ public function deleteAddressBookContactsInbulk($addressBookId, $contactIds)
832
+ {
833
+
834
+
835
+ $url = 'https://apiconnector.com/v2/address-books/' . $addressBookId . '/contacts/inbulk';
836
+ $data = array('ContactIds' => array($contactIds[0]));
837
+ $this->setUrl($url)
838
+ ->setVerb('DELETE')
839
+ ->buildPostBody($data);
840
+
841
+ $response = $this->execute();
842
+ if (isset($response->message)) {
843
+ $message = 'DELETE BULK ADDRESS BOOK CONTACTS ' . $response->message . ' address book ' . $addressBookId;
844
+ Mage::helper('ddg')->log($message);
845
+ if (! in_array($response->message, $this->exludeMessages))
846
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
847
+ }
848
+ return $response;
849
+ }
850
+
851
+ /**
852
+ * Resubscribes a previously unsubscribed contact.
853
+ *
854
+ * @param $apiContact
855
+ */
856
+ public function postContactsResubscribe($apiContact)
857
+ {
858
+
859
+
860
+ $url = self::REST_CONTACTS_RESUBSCRIBE;
861
+ $data = array(
862
+ 'UnsubscribedContact' => $apiContact
863
+ );
864
+ $this->setUrl($url)
865
+ ->setVerb("POST")
866
+ ->buildPostBody($data);
867
+
868
+ $response = $this->execute();
869
+ if (isset($response->message)) {
870
+ $message = 'Resubscribe : ' . $url . ', message :' . $response->message;
871
+ Mage::helper('ddg')->log($message);
872
+ Mage::helper('ddg')->log($data);
873
+ if (! in_array($response->message, $this->exludeMessages))
874
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
875
+ }
876
+ }
877
+
878
+ /**
879
+ * Gets all custom from addresses which can be used in a campaign.
880
+ *
881
+ * @return null
882
+ * @throws Exception
883
+ */
884
+
885
+ public function getCustomFromAddresses()
886
+ {
887
+
888
+
889
+ $url = self::REST_CAMPAIGN_FROM_ADDRESS_LIST;
890
+ $this->setUrl($url)
891
+ ->setVerb('GET');
892
+
893
+ $response = $this->execute();
894
+
895
+ if (isset($response->message)) {
896
+
897
+ $message = 'GET CampaignFromAddressList ' . $response->message . ' api user : ' . $this->getApiUsername();
898
+ Mage::helper('ddg')->log($message);
899
+ if (! in_array($response->message, $this->exludeMessages))
900
+ Mage::helper('ddg')->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
+
916
+
917
+ $url = self::REST_CREATE_CAMPAIGN;
918
+ $this->setURl($url)
919
+ ->setVerb('POST')
920
+ ->buildPostBody($data);
921
+
922
+ $response = $this->execute();
923
+
924
+ if (isset($response->message)) {
925
+ $message = ' CREATE CAMPAIGN ' . $response->message;
926
+ Mage::helper('ddg')->log($message);
927
+ if (! in_array($response->message, $this->exludeMessages))
928
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
929
+ }
930
+
931
+ return $response;
932
+ }
933
+
934
+ /**
935
+ * Gets all programs.
936
+ * https://apiconnector.com/v2/programs?select={select}&skip={skip}
937
+ */
938
+ public function getPrograms()
939
+ {
940
+
941
+
942
+ $url = self::REST_PROGRAM;
943
+
944
+ $this->setUrl($url)
945
+ ->setVerb('GET');
946
+
947
+ $response = $this->execute();
948
+
949
+ if (isset($response->message)) {
950
+ $message = 'Get programmes : ' . $response->message ;
951
+ Mage::helper( 'ddg' )->log($message);
952
+ if (! in_array($response->message, $this->exludeMessages))
953
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
954
+ }
955
+
956
+ return $response;
957
+ }
958
+
959
+ /**
960
+ * Creates an enrolment.
961
+ * @param $data
962
+ *
963
+ * @return null
964
+ * @throws Exception
965
+ */
966
+ public function postProgramsEnrolments($data)
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('ddg')->log($message);
977
+ Mage::helper('ddg')->log($data);
978
+ if (! in_array($response->message, $this->exludeMessages))
979
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
980
+ }
981
+
982
+ return $response;
983
+ }
984
+
985
+ /**
986
+ * Gets a program by id.
987
+ * @param $id
988
+ *
989
+ * @return null
990
+ * @throws Exception
991
+ */
992
+ public function getProgramById( $id )
993
+ {
994
+
995
+
996
+ $url = self::REST_PROGRAM . $id;
997
+ $this->setUrl($url)
998
+ ->setVerb('GET');
999
+
1000
+ $response = $this->execute();
1001
+ if (isset($response->message)) {
1002
+ $message = 'Get program by id ' . $id . ', ' . $response->message;
1003
+ Mage::helper('ddg')->log($message);
1004
+ if (! in_array($response->message, $this->exludeMessages))
1005
+ Mage::helper("ddg")->rayLog(100, $message, 'apiconnector/client.php', __LINE__);
1006
+
1007
+ }
1008
+
1009
+ return $response;
1010
+ }
1011
+
1012
+ /**
1013
+ * Gets a summary of reporting information for a specified campaign.
1014
+ * @param $campaignId
1015
+ *
1016
+ * @return null
1017
+ * @throws Exception
1018
+ */
1019
+ public function getCampaignSummary($campaignId)
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('ddg')->log( $message );
1030
+ if (! in_array($response->message, $this->exludeMessages))
1031
+ Mage::helper('ddg')->rayLog(100, $message, 'apiconnector/client.php', __LINE__);
1032
+ }
1033
+
1034
+ return $response;
1035
+ }
1036
+
1037
+ /**
1038
+ * Deletes a piece of transactional data by key.
1039
+ * @param $key
1040
+ * @param string $collectionName
1041
+ * @return object
1042
+ */
1043
+ public function deleteContactsTransactionalData($key, $collectionName = 'Orders')
1044
+ {
1045
+ $url = 'https://apiconnector.com/v2/contacts/transactional-data/' . $collectionName .'/' . $key ;
1046
+ $this->setUrl($url)
1047
+ ->setVerb('DELETE');
1048
+ $response = $this->execute();
1049
+ if (isset($response->message))
1050
+ Mage::helper('ddg')->log('DELETE CONTACTS TRANSACTIONAL DATA : ' . $url . ' ' . $response->message);
1051
+
1052
+ return $response;
1053
+ }
1054
+
1055
+ /**
1056
+ * Adds a document to a campaign as an attachment.
1057
+ * @param $campaignId
1058
+ * @param $data
1059
+ *
1060
+ * @return object
1061
+ * @throws Exception
1062
+ */
1063
+ public function postCampaignAttachments($campaignId, $data)
1064
+ {
1065
+ $url = self::REST_CREATE_CAMPAIGN . "/$campaignId/attachments";
1066
+ $this->setURl($url)
1067
+ ->setVerb('POST')
1068
+ ->buildPostBody($data);
1069
+ $result = $this->execute();
1070
+ if (isset($result->message)) {
1071
+ Mage::helper('ddg')->log(' CAMPAIGN ATTACHMENT ' . $result->message);
1072
+ }
1073
+ return $result;
1074
+ }
1075
+
1076
+
1077
+ public function getNostoProducts($slotName, $email)
1078
+ {
1079
+ $recommended = Dotdigitalgroup_Email_Helper_Config::API_ENDPOINT . '/recommendations/email';
1080
+ $token = Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DYNAMIC_CONTENT_NOSTO);
1081
+
1082
+ //check for strin length
1083
+ if (strlen($slotName) > 1 && strlen($email) > 1) {
1084
+
1085
+ $recommended .= '?elements=' . $slotName;
1086
+ $recommended .= '&emails=' . $email;
1087
+ }
1088
+
1089
+ $this->setApiUsername('')
1090
+ ->setApiPassword($token)
1091
+ ->setUrl($recommended)
1092
+ ->setVerb('GET');
1093
+
1094
+ $result = $this->execute();
1095
+
1096
+ if (isset($result->message)) {
1097
+ $message = $result->message;
1098
+ Mage::helper('ddg')->log($message);
1099
+ Mage::helper('ddg')->log("Nosto recommendation slot name : $slotName , email : $email");
1100
+ }
1101
+
1102
+ return $result;
1103
+ }
1104
+
1105
+ /**
1106
+ * get contact address books
1107
+ *
1108
+ * @param $contactId
1109
+ * @return object
1110
+ * @throws Exception
1111
+ */
1112
+ public function getContactAddressBooks($contactId)
1113
+ {
1114
+
1115
+
1116
+ $url = 'https://apiconnector.com/v2/contacts/' . $contactId . '/address-books' ;
1117
+ $this->setUrl($url)
1118
+ ->setVerb('GET');
1119
+ $response = $this->execute();
1120
+ if (isset($response->message)) {
1121
+ $message = 'GET CONTACTS ADDRESS BOOKS contact: ' . $contactId . $response->message;
1122
+ Mage::helper('ddg')->log($message);
1123
+ if (! in_array($response->message, $this->exludeMessages))
1124
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
1125
+ }
1126
+
1127
+ return $response;
1128
+ }
1129
+
1130
+ /**
1131
+ * Gets list of all templates.
1132
+ *
1133
+ * @return object
1134
+ * @throws Exception
1135
+ */
1136
+ public function getApiTemplateList()
1137
+ {
1138
+ $url = self::REST_TEMPLATES;
1139
+ $this->setUrl($url)
1140
+ ->setVerb('GET');
1141
+ $response = $this->execute();
1142
+
1143
+ if (isset($response->message)) {
1144
+ $message = 'GET API CONTACT LIST ' . $response->message;
1145
+ Mage::helper('ddg')->log($message);
1146
+
1147
+ if (! in_array($response->message, $this->exludeMessages))
1148
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
1149
+ }
1150
+ return $response;
1151
+ }
1152
+
1153
+ /**
1154
+ * Gets a template by ID.
1155
+ *
1156
+ * @param $templateId
1157
+ * @return object
1158
+ * @throws Exception
1159
+ */
1160
+ public function getApiTemplate($templateId)
1161
+ {
1162
+
1163
+
1164
+ $url = self::REST_TEMPLATES . '/' . $templateId;
1165
+ $this->setUrl($url)
1166
+ ->setVerb('GET');
1167
+ $response = $this->execute();
1168
+ if (isset($response->message)) {
1169
+ $message = 'GET API CONTACT LIST ' . $response->message;
1170
+ Mage::helper('ddg')->log($message);
1171
+ if (! in_array($response->message, $this->exludeMessages))
1172
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
1173
+ }
1174
+ return $response;
1175
+ }
1176
+
1177
+ /**
1178
+ * Adds multiple pieces of transactional data to account asynchronously, returning an identifier that can be used to check for import progress.
1179
+ * @param $collectionName
1180
+ * @param $transactionalData
1181
+ * @return object
1182
+ */
1183
+ public function postAccountTransactionalDataImport($transactionalData, $collectionName = 'Catalog_Default')
1184
+ {
1185
+
1186
+
1187
+ $orders = array();
1188
+ foreach ($transactionalData as $one) {
1189
+ if (isset($one->id)) {
1190
+ $orders[] = array(
1191
+ 'Key' => $one->id,
1192
+ 'ContactIdentifier' => 'account',
1193
+ 'Json' => json_encode($one->expose())
1194
+ );
1195
+ }
1196
+ }
1197
+ $url = self::REST_TRANSACTIONAL_DATA_IMPORT . $collectionName;
1198
+ $this->setURl($url)
1199
+ ->setVerb('POST')
1200
+ ->buildPostBody($orders);
1201
+
1202
+ $response = $this->execute();
1203
+
1204
+ if (isset($response->message)) {
1205
+ $message = ' SEND MULTI TRANSACTIONAL DATA TO ACCOUNT' . $response->message;
1206
+ Mage::helper('ddg')->log($message);
1207
+ if (! in_array($response->message, $this->exludeMessages))
1208
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
1209
+ }
1210
+
1211
+ return $response;
1212
+ }
1213
+
1214
+ public function getCampaignsWithActivitySinceDate($dateTime)
1215
+ {
1216
+
1217
+ $url = self::REST_DATA_FIELDS_CAMPAIGNS . '/with-activity-since/' . $dateTime;
1218
+
1219
+ $this->setUrl($url)
1220
+ ->setVerb('GET');
1221
+ $response = $this->execute();
1222
+ if (isset($response->message)) {
1223
+ $message = 'GET CAMPAIGNS WITH ACTIVITY SINCE DATE ' . $response->message;
1224
+ Mage::helper('ddg')->log($message);
1225
+ if (! in_array($response->message, $this->exludeMessages))
1226
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
1227
+ }
1228
+ return $response;
1229
+ }
1230
+
1231
+ public function getCampaignActivityByContactId($campaignId, $contactId)
1232
+ {
1233
+
1234
+ $url = self::REST_DATA_FIELDS_CAMPAIGNS . '/' . $campaignId . '/activities/' . $contactId;
1235
+
1236
+ $this->setUrl($url)
1237
+ ->setVerb('GET');
1238
+ $response = $this->execute();
1239
+ if (isset($response->message)) {
1240
+ $message = 'GET CAMPAIGN ACTIVITY BY CONTACT ID ' . $response->message;
1241
+ Mage::helper('ddg')->log($message);
1242
+ if (!in_array($response->message, $this->exludeMessages))
1243
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
1244
+ }
1245
+ return $response;
1246
+ }
1247
+
1248
+ /**
1249
+ * Gets the import status of a previously started contact import.
1250
+ *
1251
+ * @param $importId
1252
+ * @return object
1253
+ */
1254
+ public function getContactsImportByImportId($importId)
1255
+ {
1256
+ $url = self::REST_CONTACTS_IMPORT . $importId;
1257
+
1258
+ $this->setUrl($url)
1259
+ ->setVerb('GET');
1260
+ $response = $this->execute();
1261
+ if (isset($response->message)) {
1262
+ $message = 'GET CONTACTS IMPORT BY IMPORT ID ' . $response->message;
1263
+ Mage::helper('ddg')->log($message);
1264
+ if (!in_array($response->message, $this->exludeMessages))
1265
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
1266
+ }
1267
+ return $response;
1268
+ }
1269
+
1270
+ /**
1271
+ * Gets the import status of a previously started transactional import.
1272
+ *
1273
+ * @param $importId
1274
+ * @return object
1275
+ */
1276
+ public function getContactsTransactionalDataImportByImportId($importId)
1277
+ {
1278
+ $url = self::REST_TRANSACTIONAL_DATA_IMPORT . $importId;
1279
+
1280
+ $this->setUrl($url)
1281
+ ->setVerb('GET');
1282
+ $response = $this->execute();
1283
+ if (isset($response->message)) {
1284
+ $message = 'GET CONTACTS TRANSACTIONAL DATA IMPORT BY IMPORT ID ' . $response->message;
1285
+ Mage::helper('ddg')->log($message);
1286
+ if (! in_array($response->message, $this->exludeMessages))
1287
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
1288
+ }
1289
+ return $response;
1290
+ }
1291
+ }
app/code/community/Dotdigitalgroup/Email/Model/Apiconnector/Contact.php ADDED
@@ -0,0 +1,423 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Apiconnector_Contact
4
+ {
5
+ private $_start;
6
+ private $_countCustomers = 0;
7
+
8
+ /**
9
+ * Contact sync.
10
+ *
11
+ * @return array
12
+ */
13
+ public function sync()
14
+ {
15
+ $result = array('success' => true, 'message' => '');
16
+ /** @var Dotdigitalgroup_Email_Helper_Data $helper */
17
+ $helper = Mage::helper('ddg');
18
+ $this->_start = microtime(true);
19
+ //resourse allocation
20
+ $helper->allowResourceFullExecution();
21
+ foreach (Mage::app()->getWebsites(true) as $website) {
22
+ $enabled = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED, $website);
23
+ $sync = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_CONTACT_ENABLED, $website);
24
+ if ($enabled && $sync) {
25
+
26
+ if (!$this->_countCustomers)
27
+ $helper->log('---------- Start customer sync ----------');
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
+ //sync proccessed
35
+ if ($this->_countCustomers) {
36
+ $message = 'Total time for sync : ' . gmdate( "H:i:s", microtime( true ) - $this->_start ) . ', Total updated = ' . $this->_countCustomers;
37
+ $helper->log( $message );
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('ddg');
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 0;
61
+ $fileHelper = Mage::helper('ddg/file');
62
+ $contactModel = Mage::getModel('ddg_automation/contact');
63
+ $client = Mage::helper('ddg')->getWebsiteApiClient($website);
64
+ $contacts = $contactModel->getContactsToImportForWebsite($website->getId(), $pageSize);
65
+
66
+ // no contacts for this webiste
67
+ if (!count($contacts))
68
+ return 0;
69
+ //create customer filename
70
+ $customersFile = strtolower($website->getCode() . '_customers_' . date('d_m_Y_Hi') . '.csv');
71
+ $helper->log('Customers file : ' . $customersFile);
72
+
73
+ //get customer ids
74
+ $customerIds = array();
75
+ foreach ($contacts as $contact) {
76
+ $customerIds[] = $contact->getCustomerId();
77
+ //remove contact with customer id set and no customer
78
+ if ($contact->getCustomerId() && ! Mage::getModel('customer/customer')->load($contact->getCustomerId())->getId())
79
+ $contact->delete();
80
+ }
81
+
82
+ //customer collection
83
+ $customerCollection = $this->getCollection($customerIds, $website);
84
+
85
+ /**
86
+ * HEADERS.
87
+ */
88
+ $mappedHash = $fileHelper->getWebsiteCustomerMappingDatafields($website);
89
+ $headers = $mappedHash;
90
+ //custom customer attributes
91
+ $customAttributes = $helper->getCustomAttributes($website);
92
+ if ($customAttributes)
93
+ foreach ($customAttributes as $data) {
94
+ $headers[] = $data['datafield'];
95
+ $allMappedHash[$data['attribute']] = $data['datafield'];
96
+ }
97
+ $headers[] = 'Email';
98
+ $headers[] = 'EmailType';
99
+ $fileHelper->outputCSV($fileHelper->getFilePath($customersFile), $headers);
100
+ /**
101
+ * END HEADERS.
102
+ */
103
+
104
+
105
+ foreach ($customerCollection as $customer) {
106
+ $contactModel = Mage::getModel('ddg_automation/contact')->loadByCustomerEmail($customer->getEmail(), $website->getId());
107
+ //remove contact with customer id set and no customer
108
+ if(!$contactModel->getId()){
109
+ Mage::helper('ddg')->log('delete contact email :' . $customer->getEmail());
110
+ $contactModel->delete();
111
+ continue;
112
+ }
113
+ /**
114
+ * DATA.
115
+ */
116
+ $connectorCustomer = Mage::getModel('ddg_automation/apiconnector_customer', $mappedHash);
117
+ $connectorCustomer->setCustomerData($customer);
118
+ //count number of customers
119
+ $customers[] = $connectorCustomer;
120
+ if ($connectorCustomer)
121
+ foreach ($customAttributes as $data) {
122
+ $attribute = $data['attribute'];
123
+ $value = $customer->getData( $attribute );
124
+ $connectorCustomer->setData( $value );
125
+ }
126
+
127
+ //contact email and email type
128
+ $connectorCustomer->setData($customer->getEmail());
129
+ $connectorCustomer->setData('Html');
130
+ // save csv file data for customers
131
+ $fileHelper->outputCSV($fileHelper->getFilePath($customersFile), $connectorCustomer->toCSVArray());
132
+
133
+ /**
134
+ * END DATA.
135
+ */
136
+
137
+ //mark the contact as imported
138
+ $contactModel->setEmailImported(Dotdigitalgroup_Email_Model_Contact::EMAIL_CONTACT_IMPORTED);
139
+ $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($customer->getEmail());
140
+ if ($subscriber->isSubscribed()) {
141
+ $contactModel->setIsSubscriber(1)
142
+ ->setSubscriberStatus($subscriber->getSubscriberStatus());
143
+ }
144
+
145
+ $contactModel->save();
146
+ $updated++;
147
+ }
148
+ $customerNum = count($customers);
149
+ $helper->log('Website : ' . $website->getName() . ', customers = ' . $customerNum);
150
+ $helper->log('---------------------------- execution time :' . gmdate("H:i:s", microtime(true) - $this->_start));
151
+
152
+ if (is_file($fileHelper->getFilePath($customersFile))) {
153
+ //import contacts
154
+ if ($updated > 0)
155
+ $client->postAddressBookContactsImport($customersFile, $helper->getCustomerAddressBook($website));
156
+ //archive file on success
157
+ $fileHelper->archiveCSV($customersFile);
158
+ }
159
+ $this->_countCustomers += $updated;
160
+ return $customerNum;
161
+ }
162
+
163
+ /**
164
+ * Sync a single contact.
165
+ *
166
+ * @param null $contactId
167
+ *
168
+ * @return mixed
169
+ * @throws Mage_Core_Exception
170
+ */
171
+ public function syncContact($contactId = null)
172
+ {
173
+ if ($contactId)
174
+ $contact = Mage::getModel('ddg_automation/contact')->load($contactId);
175
+ else {
176
+ $contact = Mage::registry('current_contact');
177
+ }
178
+ if (! $contact->getId()) {
179
+ Mage::getSingleton('adminhtml/session')->addError('No contact found!');
180
+ return false;
181
+ }
182
+
183
+ $websiteId = $contact->getWebsiteId();
184
+ $website = Mage::app()->getWebsite($websiteId);
185
+ $updated = 0;
186
+ $customers = $headers = $allMappedHash = array();
187
+ $helper = Mage::helper('ddg');
188
+ $helper->log('---------- Start single customer sync ----------');
189
+ //skip if the mapping field is missing
190
+ if(!$helper->getCustomerAddressBook($website))
191
+ return false;
192
+ $fileHelper = Mage::helper('ddg/file');
193
+
194
+ $customerId = $contact->getCustomerId();
195
+ if (!$customerId) {
196
+ Mage::getSingleton('adminhtml/session')->addError('Cannot manually sync guests!');
197
+ return false;
198
+ }
199
+ $client = Mage::helper('ddg')->getWebsiteApiClient($website);
200
+
201
+ //create customer filename
202
+ $customersFile = strtolower($website->getCode() . '_customers_' . date('d_m_Y_Hi') . '.csv');
203
+ $helper->log('Customers file : ' . $customersFile);
204
+
205
+ /**
206
+ * HEADERS.
207
+ */
208
+ $mappedHash = $fileHelper->getWebsiteCustomerMappingDatafields($website);
209
+ $headers = $mappedHash;
210
+ //custom customer attributes
211
+ $customAttributes = $helper->getCustomAttributes($website);
212
+ foreach ($customAttributes as $data) {
213
+ $headers[] = $data['datafield'];
214
+ $allMappedHash[$data['attribute']] = $data['datafield'];
215
+ }
216
+
217
+ $headers[] = 'Email';
218
+ $headers[] = 'EmailType';
219
+ $fileHelper->outputCSV($fileHelper->getFilePath($customersFile), $headers);
220
+ /**
221
+ * END HEADERS.
222
+ */
223
+ $customerCollection = $this->getCollection(array($customerId));
224
+
225
+ foreach ($customerCollection as $customer) {
226
+ $contactModel = Mage::getModel('ddg_automation/contact')->loadByCustomerEmail($customer->getEmail(), $websiteId);
227
+ //skip contacts without customer id
228
+ if (!$contactModel->getId())
229
+ continue;
230
+ /**
231
+ * DATA.
232
+ */
233
+ $connectorCustomer = Mage::getModel('ddg_automation/apiconnector_customer', $mappedHash);
234
+ $connectorCustomer->setCustomerData($customer);
235
+ //count number of customers
236
+ $customers[] = $connectorCustomer;
237
+ foreach ($customAttributes as $data) {
238
+ $attribute = $data['attribute'];
239
+ $value = $customer->getData($attribute);
240
+ $connectorCustomer->setData($value);
241
+ }
242
+ //contact email and email type
243
+ $connectorCustomer->setData($customer->getEmail());
244
+ $connectorCustomer->setData('Html');
245
+ // save csv file data for customers
246
+ $fileHelper->outputCSV($fileHelper->getFilePath($customersFile), $connectorCustomer->toCSVArray());
247
+
248
+ /**
249
+ * END DATA.
250
+ */
251
+
252
+ //mark the contact as imported
253
+ $contactModel->setEmailImported(Dotdigitalgroup_Email_Model_Contact::EMAIL_CONTACT_IMPORTED);
254
+ $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($customer->getEmail());
255
+ if ($subscriber->isSubscribed()) {
256
+ $contactModel->setIsSubscriber('1')
257
+ ->setSubscriberStatus($subscriber->getSubscriberStatus());
258
+ }
259
+
260
+ $contactModel->save();
261
+ $updated++;
262
+ }
263
+
264
+ if (is_file($fileHelper->getFilePath($customersFile))) {
265
+ //import contacts
266
+ if ($updated > 0)
267
+ $client->postAddressBookContactsImport($customersFile, $helper->getCustomerAddressBook($website));
268
+ //archive file on success
269
+ $fileHelper->archiveCSV($customersFile);
270
+ }
271
+ return $contact->getEmail();
272
+ }
273
+
274
+
275
+ /**
276
+ * get customer collection
277
+ * @param $customerIds
278
+ * @return Mage_Eav_Model_Entity_Collection_Abstract
279
+ * @throws Mage_Core_Exception
280
+ */
281
+ public function getCollection($customerIds)
282
+ {
283
+ $customerCollection = Mage::getResourceModel('customer/customer_collection')
284
+ ->addNameToSelect()
285
+ ->addAttributeToSelect('*')
286
+ ->joinAttribute('billing_street', 'customer_address/street', 'default_billing', null, 'left')
287
+ ->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
288
+ ->joinAttribute('billing_country_code', 'customer_address/country_id', 'default_billing', null, 'left')
289
+ ->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
290
+ ->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')
291
+ ->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
292
+ ->joinAttribute('shipping_street', 'customer_address/street', 'default_shipping', null, 'left')
293
+ ->joinAttribute('shipping_city', 'customer_address/city', 'default_shipping', null, 'left')
294
+ ->joinAttribute('shipping_country_code','customer_address/country_id', 'default_shipping', null, 'left')
295
+ ->joinAttribute('shipping_postcode', 'customer_address/postcode', 'default_shipping', null, 'left')
296
+ ->joinAttribute('shipping_telephone', 'customer_address/telephone', 'default_shipping', null, 'left')
297
+ ->joinAttribute('shipping_region', 'customer_address/region', 'default_shipping', null, 'left')
298
+ ->addAttributeToFilter('entity_id', array('in' => $customerIds));
299
+ $customer_log = Mage::getSingleton('core/resource')->getTableName('log_customer');
300
+ $sales_flat_order_grid = Mage::getSingleton('core/resource')->getTableName('sales_flat_order_grid');
301
+ $sales_flat_quote = Mage::getSingleton('core/resource')->getTableName('sales_flat_quote');
302
+ $sales_flat_order = Mage::getSingleton('core/resource')->getTableName('sales_flat_order');
303
+ $sales_flat_order_item = Mage::getSingleton('core/resource')->getTableName('sales_flat_order_item');
304
+ $catalog_category_product_index = Mage::getSingleton('core/resource')->getTableName('catalog_category_product');
305
+ $eav_attribute_option_value = Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value');
306
+ $catalog_product_entity_int = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int');
307
+ $eav_attribute = Mage::getSingleton('core/resource')->getTableName('eav_attribute');
308
+
309
+
310
+ // get the last login date from the log_customer table
311
+ $customerCollection->getSelect()->columns(
312
+ 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)")));
313
+
314
+ // customer order information
315
+ $alias = 'subselect';
316
+ $subselect = Mage::getModel('Varien_Db_Select', Mage::getSingleton('core/resource')->getConnection('core_read'))
317
+ ->from($sales_flat_order_grid, array(
318
+ 'customer_id as s_customer_id',
319
+ 'sum(grand_total) as total_spend',
320
+ 'count(*) as number_of_orders',
321
+ 'avg(grand_total) as average_order_value',
322
+ )
323
+ )->group('customer_id')
324
+ ;
325
+ $customerCollection->getSelect()->columns(array(
326
+ '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)"),
327
+ '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)"),
328
+ 'last_increment_id' => new Zend_Db_Expr("(SELECT increment_id FROM $sales_flat_order_grid WHERE customer_id =e.entity_id ORDER BY created_at DESC LIMIT 1)"),
329
+ 'last_quote_id' => new Zend_Db_Expr("(SELECT entity_id FROM $sales_flat_quote WHERE customer_id = e.entity_id ORDER BY created_at DESC LIMIT 1)"),
330
+ 'first_category_id' => new Zend_Db_Expr(
331
+ "(
332
+ SELECT ccpi.category_id FROM $sales_flat_order as sfo
333
+ left join $sales_flat_order_item as sfoi on sfoi.order_id = sfo.entity_id
334
+ left join $catalog_category_product_index as ccpi on ccpi.product_id = sfoi.product_id
335
+ WHERE sfo.customer_id = e.entity_id
336
+ ORDER BY sfo.created_at ASC, sfoi.price DESC
337
+ LIMIT 1
338
+ )"
339
+ ),
340
+ 'last_category_id' => new Zend_Db_Expr(
341
+ "(
342
+ SELECT ccpi.category_id FROM $sales_flat_order as sfo
343
+ left join $sales_flat_order_item as sfoi on sfoi.order_id = sfo.entity_id
344
+ left join $catalog_category_product_index as ccpi on ccpi.product_id = sfoi.product_id
345
+ WHERE sfo.customer_id = e.entity_id
346
+ ORDER BY sfo.created_at DESC, sfoi.price DESC
347
+ LIMIT 1
348
+ )"
349
+ ),
350
+ 'product_id_for_first_brand' => new Zend_Db_Expr(
351
+ "(
352
+ SELECT sfoi.product_id FROM $sales_flat_order as sfo
353
+ left join $sales_flat_order_item as sfoi on sfoi.order_id = sfo.entity_id
354
+ WHERE sfo.customer_id = e.entity_id and sfoi.product_type = 'simple'
355
+ ORDER BY sfo.created_at ASC, sfoi.price DESC
356
+ LIMIT 1
357
+ )"
358
+ ),
359
+ 'product_id_for_last_brand' => new Zend_Db_Expr(
360
+ "(
361
+ SELECT sfoi.product_id FROM $sales_flat_order as sfo
362
+ left join $sales_flat_order_item as sfoi on sfoi.order_id = sfo.entity_id
363
+ WHERE sfo.customer_id = e.entity_id and sfoi.product_type = 'simple'
364
+ ORDER BY sfo.created_at DESC, sfoi.price DESC
365
+ LIMIT 1
366
+ )"
367
+ ),
368
+ 'week_day' => new Zend_Db_Expr(
369
+ "(
370
+ SELECT dayname(created_at) as week_day
371
+ FROM $sales_flat_order
372
+ WHERE customer_id = e.entity_id
373
+ GROUP BY week_day
374
+ HAVING COUNT(*) > 0
375
+ ORDER BY (COUNT(*)) DESC
376
+ LIMIT 1
377
+ )"
378
+ ),
379
+ 'month_day' => new Zend_Db_Expr(
380
+ "(
381
+ SELECT monthname(created_at) as month_day
382
+ FROM $sales_flat_order
383
+ WHERE customer_id = e.entity_id
384
+ GROUP BY month_day
385
+ HAVING COUNT(*) > 0
386
+ ORDER BY (COUNT(*)) DESC
387
+ LIMIT 1
388
+ )"
389
+ ),
390
+ 'most_category_id' => new Zend_Db_Expr(
391
+ "(
392
+ SELECT ccpi.category_id FROM $sales_flat_order as sfo
393
+ LEFT JOIN $sales_flat_order_item as sfoi on sfoi.order_id = sfo.entity_id
394
+ LEFT JOIN $catalog_category_product_index as ccpi on ccpi.product_id = sfoi.product_id
395
+ WHERE sfo.customer_id = e.entity_id AND ccpi.category_id is not null
396
+ GROUP BY category_id
397
+ HAVING COUNT(sfoi.product_id) > 0
398
+ ORDER BY COUNT(sfoi.product_id) DESC
399
+ LIMIT 1
400
+ )"
401
+ ),
402
+ 'most_brand' => new Zend_Db_Expr(
403
+ "(
404
+ SELECT eaov.value from $sales_flat_order sfo
405
+ LEFT JOIN $sales_flat_order_item as sfoi on sfoi.order_id = sfo.entity_id
406
+ LEFT JOIN $catalog_product_entity_int pei on pei.entity_id = sfoi.product_id
407
+ LEFT JOIN $eav_attribute ea ON pei.attribute_id = ea.attribute_id
408
+ LEFT JOIN $eav_attribute_option_value as eaov on pei.value = eaov.option_id
409
+ WHERE sfo.customer_id = e.entity_id AND ea.attribute_code = 'manufacturer' AND eaov.value is not null
410
+ GROUP BY eaov.value
411
+ HAVING count(*) > 0
412
+ ORDER BY count(*) DESC
413
+ LIMIT 1
414
+ )"
415
+ ),
416
+ )
417
+ );
418
+ $customerCollection->getSelect()
419
+ ->joinLeft(array($alias => $subselect), "{$alias}.s_customer_id = e.entity_id");
420
+
421
+ return $customerCollection;
422
+ }
423
+ }
app/code/community/Dotdigitalgroup/Email/Model/Apiconnector/Customer.php ADDED
@@ -0,0 +1,901 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Apiconnector_Customer
4
+ {
5
+
6
+ public $customer;
7
+ public $customerData;
8
+ public $reviewCollection;
9
+
10
+ //enterprise reward
11
+ public $reward;
12
+
13
+ public $rewardCustomer;
14
+ public $rewardLastSpent = "";
15
+ public $rewardLastEarned = "";
16
+ public $rewardExpiry = "";
17
+
18
+ protected $_mapping_hash;
19
+
20
+ private $subscriber_status = array(
21
+ Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED => 'Subscribed',
22
+ Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE => 'Not Active',
23
+ Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED => 'Unsubscribed',
24
+ Mage_Newsletter_Model_Subscriber::STATUS_UNCONFIRMED => 'Unconfirmed'
25
+ );
26
+
27
+ /**
28
+ * constructor, mapping hash to map.
29
+ *
30
+ * @param $mappingHash
31
+ */
32
+ public function __construct( $mappingHash)
33
+ {
34
+ $this->setMappigHash($mappingHash);
35
+ }
36
+
37
+ /**
38
+ * Set key value data.
39
+ *
40
+ * @param $data
41
+ */
42
+ public function setData($data)
43
+ {
44
+ $this->customerData[] = $data;
45
+ }
46
+
47
+ /**
48
+ * Set customer data.
49
+ *
50
+ * @param Mage_Customer_Model_Customer $customer
51
+ */
52
+ public function setCustomerData(Mage_Customer_Model_Customer $customer)
53
+ {
54
+ $this->customer = $customer;
55
+ $this->setReviewCollection();
56
+ $website = $customer->getStore()->getWebsite();
57
+
58
+ if ($website && Mage::helper('ddg')->isSweetToothToGo($website))
59
+ $this->setRewardCustomer($customer);
60
+
61
+ foreach ($this->getMappingHash() as $key => $field) {
62
+
63
+ /**
64
+ * call user function based on the attribute mapped.
65
+ */
66
+ $function = 'get';
67
+ $exploded = explode('_', $key);
68
+ foreach ($exploded as $one) {
69
+ $function .= ucfirst($one);
70
+ }
71
+ try{
72
+ $value = call_user_func(array('self', $function));
73
+ $this->customerData[$key] = $value;
74
+ }catch (Exception $e){
75
+ Mage::logException($e);
76
+ }
77
+ }
78
+ }
79
+
80
+ public function setReviewCollection()
81
+ {
82
+ $customer_id = $this->customer->getId();
83
+ $collection = Mage::getModel('review/review')->getCollection()
84
+ ->addCustomerFilter($customer_id)
85
+ ->setOrder('review_id','DESC');
86
+ $this->reviewCollection = $collection;
87
+ }
88
+
89
+ public function getReviewCount()
90
+ {
91
+ return count($this->reviewCollection);
92
+ }
93
+
94
+ public function getLastReviewDate(){
95
+ if(count($this->reviewCollection))
96
+ return $this->reviewCollection->getFirstItem()->getCreatedAt();
97
+ return '';
98
+ }
99
+
100
+ /**
101
+ * Set reward customer
102
+ *
103
+ * @param Mage_Customer_Model_Customer $customer
104
+ */
105
+ public function setRewardCustomer(Mage_Customer_Model_Customer $customer)
106
+ {
107
+ //get tbt reward customer
108
+ $tbt_reward = Mage::getModel('rewards/customer')->getRewardsCustomer($customer);
109
+ $this->rewardCustomer = $tbt_reward;
110
+
111
+ //get transfers collection from tbt reward. only active and order by last updated.
112
+ $lastTransfers = $tbt_reward->getTransfers()
113
+ ->selectOnlyActive()
114
+ ->addOrder('last_update_ts', Varien_Data_Collection::SORT_ORDER_DESC);
115
+
116
+ $spent = $earn = null;
117
+
118
+ foreach($lastTransfers as $transfer) {
119
+ // if transfer quantity is greater then 0 then this is last points earned date. keep checking until earn is not null
120
+ if(is_null($earn) && $transfer->getQuantity() > 0){
121
+ $earn = $transfer->getEffectiveStart();
122
+ }
123
+ // id transfer quantity is less then 0 then this is last points spent date. keep checking until spent is not null
124
+ else if(is_null($spent) && $transfer->getQuantity() < 0) {
125
+ $spent = $transfer->getEffectiveStart();
126
+ }
127
+ // break if both spent and earn are not null (a value has been assigned)
128
+ if(!is_null($spent) && !is_null($earn)) {
129
+ break;
130
+ }
131
+ }
132
+
133
+ // if earn is not null (has a value) then assign the value to property
134
+ if($earn)
135
+ $this->rewardLastEarned = $earn;
136
+ // if spent is not null (has a value) then assign the value to property
137
+ if($spent)
138
+ $this->rewardLastSpent = $spent;
139
+
140
+ $tbt_expiry = Mage::getSingleton('rewards/expiry')
141
+ ->getExpiryDate($tbt_reward);
142
+
143
+ // if there is an expiry (has a value) then assign the value to property
144
+ if($tbt_expiry)
145
+ $this->rewardExpiry = $tbt_expiry;
146
+ }
147
+
148
+ /**
149
+ * get customer id.
150
+ *
151
+ * @return mixed
152
+ */
153
+ public function getCustomerId()
154
+ {
155
+ return $this->customer->getId();
156
+ }
157
+
158
+ /**
159
+ * get first name.
160
+ *
161
+ * @return mixed
162
+ */
163
+ public function getFirstname(){
164
+ return $this->customer->getFirstname();
165
+ }
166
+
167
+ /**
168
+ * get last name.
169
+ *
170
+ * @return mixed
171
+ */
172
+ public function getLastname()
173
+ {
174
+ return $this->customer->getLastname();
175
+ }
176
+
177
+ /**
178
+ * get date of birth.
179
+ *
180
+ * @return mixed
181
+ */
182
+ public function getDob()
183
+ {
184
+ return $this->customer->getDob();
185
+ }
186
+
187
+ /**
188
+ * get customer gender.
189
+ *
190
+ * @return bool|string
191
+ */
192
+ public function getGender()
193
+ {
194
+ return $this->_getCustomerGender();
195
+ }
196
+
197
+ /**
198
+ * get customer prefix.
199
+ *
200
+ * @return mixed
201
+ */
202
+ public function getPrefix()
203
+ {
204
+ return $this->customer->getPrefix();
205
+ }
206
+
207
+ /**
208
+ * get customer suffix.
209
+ *
210
+ * @return mixed
211
+ */
212
+ public function getSuffix()
213
+ {
214
+ return $this->customer->getSuffix();
215
+ }
216
+
217
+ /**
218
+ * get website name.
219
+ *
220
+ * @return string
221
+ */
222
+ public function getWebsiteName()
223
+ {
224
+ return $this->_getWebsiteName();
225
+ }
226
+
227
+ /**
228
+ * get store name.
229
+ *
230
+ * @return null|string
231
+ */
232
+ public function getStoreName()
233
+ {
234
+ return $this->_getStoreName();
235
+ }
236
+
237
+ /**
238
+ * get customer created at date.
239
+ *
240
+ * @return mixed
241
+ */
242
+ public function getCreatedAt()
243
+ {
244
+ return $this->customer->getCreatedAt();
245
+ }
246
+
247
+ /**
248
+ * get customer last logged in date.
249
+ *
250
+ * @return mixed
251
+ */
252
+ public function getLastLoggedDate()
253
+ {
254
+ return $this->customer->getLastLoggedDate();
255
+ }
256
+
257
+ /**
258
+ * get cutomer group.
259
+ *
260
+ * @return string
261
+ */
262
+ public function getCustomerGroup()
263
+ {
264
+ return $this->_getCustomerGroup();
265
+ }
266
+
267
+ /**
268
+ * get billing address line 1.
269
+ *
270
+ * @return string
271
+ */
272
+ public function getBillingAddress1()
273
+ {
274
+ return $this->_getStreet($this->customer->getBillingStreet(), 1);
275
+ }
276
+
277
+ /**
278
+ * get billing address line 2.
279
+ *
280
+ * @return string
281
+ */
282
+ public function getBillingAddress2()
283
+ {
284
+ return $this->_getStreet($this->customer->getBillingStreet(), 2);
285
+ }
286
+
287
+ /**
288
+ * get billing city.
289
+ *
290
+ * @return mixed
291
+ */
292
+ public function getBillingCity()
293
+ {
294
+ return $this->customer->getBillingCity();
295
+ }
296
+
297
+ /**
298
+ * get billing country.
299
+ *
300
+ * @return mixed
301
+ */
302
+ public function getBillingCountry()
303
+ {
304
+ return $this->customer->getBillingCountryCode();
305
+ }
306
+
307
+ /**
308
+ * get billing state.
309
+ *
310
+ * @return mixed
311
+ */
312
+ public function getBillingState()
313
+ {
314
+ return $this->customer->getBillingRegion();
315
+ }
316
+
317
+ /**
318
+ * get billing postcode.
319
+ *
320
+ * @return mixed
321
+ */
322
+ public function getBillingPostcode()
323
+ {
324
+ return $this->customer->getBillingPostcode();
325
+ }
326
+
327
+ /**
328
+ * get billing phone.
329
+ *
330
+ * @return mixed
331
+ */
332
+ public function getBillingTelephone()
333
+ {
334
+ return $this->customer->getBillingTelephone();
335
+ }
336
+
337
+ /**
338
+ * get delivery address line 1.
339
+ *
340
+ * @return string
341
+ */
342
+ public function getDeliveryAddress1()
343
+ {
344
+ return $this->_getStreet($this->customer->getShippingStreet(), 1);
345
+ }
346
+
347
+ /**
348
+ * get delivery addrss line 2.
349
+ *
350
+ * @return string
351
+ */
352
+ public function getDeliveryAddress2()
353
+ {
354
+ return $this->_getStreet($this->customer->getShippingStreet(), 2);
355
+ }
356
+
357
+ /**
358
+ * get delivery city.
359
+ *
360
+ * @return mixed
361
+ */
362
+ public function getDeliveryCity()
363
+ {
364
+ return $this->customer->getShippingCity();
365
+ }
366
+
367
+ /**
368
+ * get delivery country.
369
+ *
370
+ * @return mixed
371
+ */
372
+ public function getDeliveryCountry(){
373
+ return $this->customer->getShippingCountryCode();
374
+ }
375
+
376
+ /**
377
+ * get delivery state.
378
+ *
379
+ * @return mixed
380
+ */
381
+ public function getDeliveryState()
382
+ {
383
+ return $this->customer->getShippingRegion();
384
+ }
385
+
386
+ /**
387
+ * get delivery postcode.
388
+ *
389
+ * @return mixed
390
+ */
391
+ public function getDeliveryPostcode()
392
+ {
393
+ return $this->customer->getShippingPostcode();
394
+ }
395
+
396
+ /**
397
+ * get delivery phone.
398
+ *
399
+ * @return mixed
400
+ */
401
+ public function getDeliveryTelephone(){
402
+ return $this->customer->getShippingTelephone();
403
+ }
404
+
405
+ /**
406
+ * get numbser of orders.
407
+ *
408
+ * @return mixed
409
+ */
410
+ public function getNumberOfOrders()
411
+ {
412
+ return $this->customer->getNumberOfOrders();
413
+ }
414
+
415
+ /**
416
+ * get average order value.
417
+ *
418
+ * @return mixed
419
+ */
420
+ public function getAverageOrderValue()
421
+ {
422
+ return $this->customer->getAverageOrderValue();
423
+ }
424
+
425
+ /**
426
+ * get total spend.
427
+ *
428
+ * @return mixed
429
+ */
430
+ public function getTotalSpend()
431
+ {
432
+ return $this->customer->getTotalSpend();
433
+ }
434
+
435
+ /**
436
+ * get last order date.
437
+ *
438
+ * @return mixed
439
+ */
440
+ public function getLastOrderDate()
441
+ {
442
+ return $this->customer->getLastOrderDate();
443
+ }
444
+
445
+ /**
446
+ * get last order id.
447
+ *
448
+ * @return mixed
449
+ */
450
+ public function getLastOrderId()
451
+ {
452
+ return $this->customer->getLastOrderId();
453
+ }
454
+
455
+ /**
456
+ * get last quote id.
457
+ *
458
+ * @return mixed
459
+ */
460
+ public function getLastQuoteId()
461
+ {
462
+ return $this->customer->getLastQuoteId();
463
+ }
464
+
465
+ /**
466
+ * get cutomer id.
467
+ *
468
+ * @return mixed
469
+ */
470
+ public function getId()
471
+ {
472
+ return $this->customer->getId();
473
+ }
474
+
475
+ /**
476
+ * get customer title.
477
+ *
478
+ * @return mixed
479
+ */
480
+ public function getTitle()
481
+ {
482
+ return $this->customer->getPrefix();
483
+ }
484
+
485
+ /**
486
+ * get total refund value.
487
+ *
488
+ * @return float|int
489
+ */
490
+ public function getTotalRefund()
491
+ {
492
+ $orders = Mage::getResourceModel('sales/order_collection')
493
+ ->addAttributeToFilter('customer_id', $this->customer->getId())
494
+ ;
495
+ $totalRefunded = 0;
496
+ foreach ($orders as $order) {
497
+ $refunded = $order->getTotalRefunded();
498
+ $totalRefunded += $refunded;
499
+ }
500
+
501
+ return $totalRefunded;
502
+ }
503
+
504
+ /**
505
+ * export to CSV.
506
+ *
507
+ * @return mixed
508
+ */
509
+ public function toCSVArray()
510
+ {
511
+ $result = $this->customerData;
512
+ return $result;
513
+ }
514
+
515
+ /**
516
+ * customer gender.
517
+ *
518
+ * @return bool|string
519
+ * @throws Mage_Core_Exception
520
+ */
521
+ private function _getCustomerGender()
522
+ {
523
+ $genderId = $this->customer->getGender();
524
+ if (is_numeric($genderId)) {
525
+ $gender = Mage::getResourceModel('customer/customer')
526
+ ->getAttribute('gender')
527
+ ->getSource()
528
+ ->getOptionText($genderId)
529
+ ;
530
+ return $gender;
531
+ }
532
+
533
+ return '';
534
+ }
535
+
536
+ private function _getStreet($street, $line){
537
+ $street = explode("\n", $street);
538
+ if(isset($street[$line - 1]))
539
+ return $street[$line - 1];
540
+ return '';
541
+ }
542
+
543
+ private function _getWebsiteName(){
544
+ $websiteId = $this->customer->getWebsiteId();
545
+ $website = Mage::app()->getWebsite($websiteId);
546
+ if($website)
547
+ return $website->getName();
548
+
549
+ return '';
550
+ }
551
+
552
+ private function _getStoreName()
553
+ {
554
+ $storeId = $this->customer->getStoreId();
555
+ $store = Mage::app()->getStore($storeId);
556
+ if($store)
557
+ return $store->getName();
558
+
559
+ return '';
560
+ }
561
+
562
+ /**
563
+ * @param mixed $mapping_hash
564
+ */
565
+ public function setMappingHash($mapping_hash)
566
+ {
567
+ $this->_mapping_hash = $mapping_hash;
568
+ }
569
+
570
+ /**
571
+ * @return mixed
572
+ */
573
+ public function getMappingHash()
574
+ {
575
+ return $this->_mapping_hash;
576
+ }
577
+
578
+ private function _getCustomerGroup(){
579
+ $groupId = $this->customer->getGroupId();
580
+ $group = Mage::getModel('customer/group')->load($groupId);
581
+ if($group){
582
+ return $group->getCode();
583
+ }
584
+ return '';
585
+ }
586
+
587
+ /**
588
+ * mapping hash value.
589
+ *
590
+ * @param $value
591
+ *
592
+ * @return $this
593
+ */
594
+ public function setMappigHash($value)
595
+ {
596
+ $this->_mapping_hash = $value;
597
+ return $this;
598
+ }
599
+
600
+ public function getRewardReferralUrl()
601
+ {
602
+ if(Mage::helper('ddg')->isSweetToothToGo($this->customer->getStore()->getWebsite()))
603
+ return (string) Mage::helper('rewardsref/url')->getUrl($this->customer);
604
+
605
+ return '';
606
+ }
607
+
608
+ public function getRewardPointBalance()
609
+ {
610
+ return $this->cleanString($this->rewardCustomer->getPointsSummary());
611
+ }
612
+
613
+ public function getRewardPointPending()
614
+ {
615
+ return $this->cleanString($this->rewardCustomer->getPendingPointsSummary());
616
+ }
617
+
618
+ public function getRewardPointPendingTime()
619
+ {
620
+ return $this->cleanString($this->rewardCustomer->getPendingTimePointsSummary());
621
+ }
622
+
623
+ public function getRewardPointOnHold()
624
+ {
625
+ return $this->cleanString($this->rewardCustomer->getOnHoldPointsSummary());
626
+ }
627
+
628
+ public function getRewardPointExpiration()
629
+ {
630
+ if($this->rewardExpiry != "")
631
+ return Mage::getModel('core/date')->date('Y/m/d', strtotime($this->rewardExpiry));
632
+ return $this->rewardExpiry;
633
+ }
634
+
635
+ public function getRewardPointLastSpent()
636
+ {
637
+ return $this->rewardLastSpent;
638
+ }
639
+
640
+ public function getRewardPointLastEarn()
641
+ {
642
+ return $this->rewardLastEarned;
643
+ }
644
+
645
+ public function cleanString($string)
646
+ {
647
+ $cleanedString = preg_replace("/[^0-9]/","",$string);
648
+ if($cleanedString != "")
649
+ return (int) number_format($cleanedString, 0, '.', '');
650
+ return 0;
651
+ }
652
+
653
+ public function getSubscriberStatus()
654
+ {
655
+ $subscriber = Mage::getModel('newsletter/subscriber')->loadByCustomer($this->customer);
656
+ if($subscriber->getCustomerId())
657
+ return $this->subscriber_status[$subscriber->getSubscriberStatus()];
658
+ }
659
+
660
+ /**
661
+ * Reward points balance.
662
+ * @return int
663
+ */
664
+ public function getRewardPoints() {
665
+ if (!$this->reward)
666
+ $this->_setReward();
667
+ $rewardPoints = $this->reward->getPointsBalance();
668
+
669
+ return $rewardPoints;
670
+ }
671
+
672
+ /**
673
+ * Currency amount points.
674
+ * @return mixed
675
+ */
676
+ public function getRewardAmount() {
677
+ if (!$this->reward)
678
+ $this->_setReward();
679
+
680
+ return $this->reward->getCurrencyAmount();
681
+ }
682
+
683
+ /**
684
+ * Expiration date to use the points.
685
+ * @return string
686
+ */
687
+ public function getExpirationDate()
688
+ {
689
+ //set reward for later use
690
+ if (!$this->reward)
691
+ $this->_setReward();
692
+
693
+
694
+ $expiredAt = $this->reward->getExpirationDate();
695
+
696
+ if ($expiredAt) {
697
+ $date = Mage::helper('core')->formatDate($expiredAt, 'short', true);
698
+ } else {
699
+ $date = '';
700
+ }
701
+
702
+ return $date;
703
+ }
704
+
705
+
706
+ private function _setReward() {
707
+ $collection = Mage::getModel('enterprise_reward/reward_history')->getCollection()
708
+ ->addCustomerFilter($this->customer->getId())
709
+ ->addWebsiteFilter($this->customer->getWebsiteId())
710
+ ->setExpiryConfig(Mage::helper('enterprise_reward')->getExpiryConfig())
711
+ ->addExpirationDate($this->customer->getWebsiteId())
712
+ ->skipExpiredDuplicates()
713
+ ->setDefaultOrder()
714
+ ->getFirstItem()
715
+ ;
716
+
717
+ $this->reward = $collection;
718
+ }
719
+
720
+
721
+ /**
722
+ * Customer segments id.
723
+ * @return string
724
+ */
725
+ public function getCustomerSegments()
726
+ {
727
+ $contactModel = Mage::getModel('ddg_automation/contact')->getCollection()
728
+ ->addFieldToFilter('customer_id', $this->getCustomerId())
729
+ ->addFieldToFilter('website_id', $this->customer->getWebsiteId())
730
+ ->getFirstItem();
731
+ if ($contactModel)
732
+ return $contactModel->getSegmentIds();
733
+
734
+ return '';
735
+ }
736
+
737
+
738
+
739
+ /**
740
+ * Last used reward points.
741
+ * @return mixed
742
+ */
743
+ public function getLastUsedDate()
744
+ {
745
+ //last used from the reward history based on the points delta used
746
+ $lastUsed = Mage::getModel('enterprise_reward/reward_history')->getCollection()
747
+ ->addCustomerFilter($this->customer->getId())
748
+ ->addWebsiteFilter($this->customer->getWebsiteId())
749
+ ->addFieldToFilter('points_delta', array('lt'=> 0))
750
+ ->setDefaultOrder()
751
+ ->getFirstItem()
752
+ ->getCreatedAt()
753
+ ;
754
+
755
+ //for any valid date
756
+ if ($lastUsed)
757
+ return $date = Mage::helper('core')->formatDate($lastUsed, 'short', true);
758
+
759
+ return '';
760
+ }
761
+
762
+
763
+
764
+ /**
765
+ * get most purchased category
766
+ *
767
+ * @return string
768
+ */
769
+ public function getMostPurCategory()
770
+ {
771
+ $id = $this->customer->getMostCategoryId();
772
+ if($id){
773
+ return Mage::getModel('catalog/category')
774
+ ->load($id)
775
+ ->setStoreId($this->customer->getStoreId())
776
+ ->getName();
777
+ }
778
+ return "";
779
+ }
780
+
781
+ /**
782
+ * get most purchased brand
783
+ *
784
+ * @return string
785
+ */
786
+ public function getMostPurBrand()
787
+ {
788
+ $brand = $this->customer->getMostBrand();
789
+ if($brand)
790
+ return $brand;
791
+ return "";
792
+ }
793
+
794
+ /**
795
+ * get most frequent day of purchase
796
+ *
797
+ * @return string
798
+ */
799
+ public function getMostFreqPurDay()
800
+ {
801
+ $day = $this->customer->getWeekDay();
802
+ if($day)
803
+ return $day;
804
+ return "";
805
+ }
806
+
807
+ /**
808
+ * get most frequent month of purchase
809
+ *
810
+ * @return string
811
+ */
812
+ public function getMostFreqPurMon()
813
+ {
814
+ $month = $this->customer->getMonthDay();
815
+ if($month)
816
+ return $month;
817
+ return "";
818
+ }
819
+
820
+ /**
821
+ * get first purchased category
822
+ *
823
+ * @return string
824
+ */
825
+ public function getFirstCategoryPur()
826
+ {
827
+ $id = $this->customer->getFirstCategoryId();
828
+ if($id){
829
+ return Mage::getModel('catalog/category')
830
+ ->load($id)
831
+ ->setStoreId($this->customer->getStoreId())
832
+ ->getName();
833
+ }
834
+ return "";
835
+ }
836
+
837
+ /**
838
+ * get last purchased category
839
+ *
840
+ * @return string
841
+ */
842
+ public function getLastCategoryPur()
843
+ {
844
+ $id = $this->customer->getLastCategoryId();
845
+ if($id){
846
+ return Mage::getModel('catalog/category')
847
+ ->setStoreId($this->customer->getStoreId())
848
+ ->load($id)
849
+ ->getName();
850
+ }
851
+ return "";
852
+ }
853
+
854
+ /**
855
+ * get first purchased brand
856
+ *
857
+ * @return string
858
+ */
859
+ public function getFirstBrandPur()
860
+ {
861
+ $id = $this->customer->getProductIdForFirstBrand();
862
+ if($id){
863
+ $brand = Mage::getModel('catalog/product')
864
+ ->setStoreId($this->customer->getStoreId())
865
+ ->load($id)
866
+ ->getAttributeText('manufacturer');
867
+ if($brand)
868
+ return $brand;
869
+ }
870
+ return "";
871
+ }
872
+
873
+ /**
874
+ * get last purchased brand
875
+ *
876
+ * @return string
877
+ */
878
+ public function getLastBrandPur()
879
+ {
880
+ $id = $this->customer->getProductIdForLastBrand();
881
+ if($id){
882
+ $brand = Mage::getModel('catalog/product')
883
+ ->setStoreId($this->customer->getStoreId())
884
+ ->load($id)
885
+ ->getAttributeText('manufacturer');
886
+ if($brand)
887
+ return $brand;
888
+ }
889
+ return "";
890
+ }
891
+
892
+ /**
893
+ * get last increment id
894
+ *
895
+ * @return mixed
896
+ */
897
+ public function getLastIncrementId()
898
+ {
899
+ return $this->customer->getLastIncrementId();
900
+ }
901
+ }
app/code/community/Dotdigitalgroup/Email/Model/Apiconnector/Test.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Apiconnector_Test extends Dotdigitalgroup_Email_Model_Apiconnector_Client
4
+ {
5
+
6
+ /**
7
+ * Validate apiuser on save.
8
+ *
9
+ * @param $apiUsername
10
+ * @param $apiPassword
11
+ *
12
+ * @return bool|mixed
13
+ */
14
+ public function validate($apiUsername, $apiPassword)
15
+ {
16
+ if ($apiUsername && $apiPassword) {
17
+ $this->setApiUsername($apiUsername)
18
+ ->setApiPassword($apiPassword);
19
+
20
+ $accountInfo = $this->getAccountInfo();
21
+ if (isset($accountInfo->message)) {
22
+ Mage::getSingleton('adminhtml/session')->addError($accountInfo->message);
23
+ Mage::helper('ddg')->log('VALIDATION ERROR : ' . $accountInfo->message);
24
+ return false;
25
+ }
26
+ return $accountInfo;
27
+ }
28
+ return false;
29
+ }
30
+
31
+ /**
32
+ * Ajax validate api user.
33
+ *
34
+ * @param $apiUsername
35
+ * @param $apiPassword
36
+ *
37
+ * @return bool|string
38
+ */
39
+ public function ajaxvalidate($apiUsername, $apiPassword)
40
+ {
41
+ if ($apiUsername && $apiPassword) {
42
+ $message = 'Credentials Valid.';
43
+ $this->setApiUsername($apiUsername)
44
+ ->setApiPassword($apiPassword);
45
+ $response = $this->getAccountInfo();
46
+ if (isset($response->message)) {
47
+ $message = 'API Username And Password Do Not Match!';
48
+ Mage::helper('ddg')->log($message);
49
+ }
50
+ return $message;
51
+ }
52
+ return false;
53
+ }
54
+ }
app/code/community/Dotdigitalgroup/Email/Model/Automation.php ADDED
@@ -0,0 +1,284 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Automation extends Mage_Core_Model_Abstract
4
+ {
5
+ const AUTOMATION_TYPE_NEW_CUSTOMER = 'customer_automation';
6
+ const AUTOMATION_TYPE_NEW_SUBSCRIBER = 'subscriber_automation';
7
+ const AUTOMATION_TYPE_NEW_ORDER = 'order_automation';
8
+ const AUTOMATION_TYPE_NEW_GUEST_ORDER = 'guest_order_automation';
9
+ const AUTOMATION_TYPE_NEW_REVIEW = 'review_automation';
10
+ const AUTOMATION_TYPE_NEW_WISHLIST = 'wishlist_automation';
11
+
12
+ const AUTOMATION_STATUS_PENDING = 'pending';
13
+
14
+ //automation enrolment limit
15
+ public $limit = 500;
16
+
17
+ public $email;
18
+
19
+ public $typeId;
20
+
21
+ public $websiteId;
22
+
23
+ public $storeName;
24
+
25
+ public $programId;
26
+
27
+ public $programStatus = 'Active';
28
+
29
+ public $programMessage;
30
+
31
+ public $automationType;
32
+ /**
33
+ * constructor
34
+ */
35
+ public function _construct()
36
+ {
37
+ parent::_construct();
38
+ $this->_init('ddg_automation/automation');
39
+ }
40
+
41
+
42
+ /**
43
+ * @return $this|Mage_Core_Model_Abstract
44
+ */
45
+ protected function _beforeSave()
46
+ {
47
+ parent::_beforeSave();
48
+ $now = Mage::getSingleton('core/date')->gmtDate();
49
+ if ($this->isObjectNew()) {
50
+ $this->setCreatedAt($now);
51
+ } else {
52
+ $this->setUpdatedAt($now);
53
+ }
54
+ return $this;
55
+ }
56
+
57
+
58
+ public function enrollment()
59
+ {
60
+
61
+ //automation statuses to filter
62
+ $automationCollection = $this->getCollection()
63
+ ->addFieldToSelect( 'automation_type' )
64
+ ->addFieldToFilter( 'enrolment_status', array('in' => array(self::AUTOMATION_STATUS_PENDING, '' )));
65
+ $automationCollection->getSelect()->group( 'automation_type' );
66
+ //active types
67
+ $automationTypes = $automationCollection->getColumnValues( 'automation_type' );
68
+
69
+ //send the campaign by each types
70
+ foreach ( $automationTypes as $type ) {
71
+
72
+ $contacts = array();
73
+ //reset the collection
74
+ $automationCollection->clear();
75
+ $automationCollection = $this->getCollection()
76
+ ->addFieldToFilter( 'enrolment_status', array('in' => array(self::AUTOMATION_STATUS_PENDING, '' )))
77
+ ->addFieldToFilter( 'automation_type', $type );
78
+ //limit because of the each contact request to get the id
79
+ $automationCollection->getSelect()->limit( $this->limit );
80
+
81
+ foreach ( $automationCollection as $automation ) {
82
+
83
+ $type = $automation->getAutomationType();
84
+ //customerid, subscriberid, wishlistid..
85
+ $email = $automation->getEmail();
86
+ $this->typeId = $automation->getTypeId();
87
+ $this->websiteId = $automation->getWebsiteId();
88
+ $this->programId = $automation->getProgramId();
89
+ $this->storeName = $automation->getStoreName();
90
+
91
+ $contactId = Mage::helper( 'ddg' )->getContactId( $email, $this->websiteId );
92
+ //contact id is valid, can update datafields
93
+ if ( $contactId ) {
94
+ //need to update datafields
95
+ $this->updateDatafieldsByType( $this->automationType, $email );
96
+ $contacts[ $automation->getId() ] = $contactId;
97
+ } else {
98
+ // the contact is suppressed or the request failed
99
+ $automation->setEnrolmentStatus('Suppressed')->save();
100
+ }
101
+ }
102
+
103
+ //only for subscribed contacts
104
+ if ( ! empty( $contacts ) && $type != '' && $this->_checkCampignEnrolmentActive( $this->programId ) ) {
105
+
106
+ $result = $this->sendContactsToAutomation( array_values( $contacts ) );
107
+
108
+ //check for error message
109
+ if ( isset( $result->message ) ) {
110
+ $this->programStatus = 'Failed';
111
+ $this->programMessage = $result->message;
112
+ }
113
+ //program is not active
114
+ } elseif ( $this->programMessage == 'Error: ERROR_PROGRAM_NOT_ACTIVE ' ) {
115
+ $this->programStatus = 'Deactivated';
116
+ }
117
+
118
+ //update contacts with the new status, and log the error message if failes
119
+ /** @var $coreResource Mage_Core_Model_Resource */
120
+ $coreResource = Mage::getSingleton( 'core/resource' );
121
+ /** @var $conn Varien_Db_Adapter_Pdo_Mysql */
122
+ $conn = $coreResource->getConnection( 'core_write' );
123
+
124
+ try {
125
+ $contactIds = array_keys($contacts);
126
+
127
+ $bind = array(
128
+ 'enrolment_status' => $this->programStatus,
129
+ 'message' => $this->programMessage,
130
+ 'updated_at' => Mage::getSingleton('core/date')->gmtDate()
131
+ );
132
+ $where = array('id IN(?)' => $contactIds);
133
+
134
+ $num = $conn->update( $coreResource->getTableName( 'ddg_automation/automation' ),
135
+ $bind,
136
+ $where
137
+ );
138
+ if ($num)
139
+ Mage::helper('ddg')->log('Automation type : ' . $type . ', updated no : ' . $num);
140
+
141
+
142
+ } catch ( Exception $e ) {
143
+ Mage::logException($e);
144
+ }
145
+ }
146
+ }
147
+
148
+ /**
149
+ * update single contact datafields for this automation type.
150
+ *
151
+ * @param $type
152
+ */
153
+ public function updateDatafieldsByType($type, $email )
154
+ {
155
+
156
+ switch($type) {
157
+ case self::AUTOMATION_TYPE_NEW_CUSTOMER :
158
+ $this->_updateDefaultDatafields($email);
159
+ break;
160
+ case self::AUTOMATION_TYPE_NEW_SUBSCRIBER :
161
+ $this->_updateDefaultDatafields($email);
162
+ break;
163
+ case self::AUTOMATION_TYPE_NEW_ORDER :
164
+ $this->_updateNewOrderDatafields($email);
165
+ break;
166
+ case self::AUTOMATION_TYPE_NEW_GUEST_ORDER:
167
+ $this->_updateNewOrderDatafields($email);
168
+ break;
169
+ case self::AUTOMATION_TYPE_NEW_REVIEW :
170
+ $this->_updateNewOrderDatafields($email);
171
+ break;
172
+ case self::AUTOMATION_TYPE_NEW_WISHLIST:
173
+ $this->_updateDefaultDatafields($email);
174
+ break;
175
+ default:
176
+ $this->_updateDefaultDatafields($email);
177
+ break;
178
+ }
179
+
180
+ }
181
+
182
+ private function _updateDefaultDatafields($email)
183
+ {
184
+ $website = Mage::app()->getWebsite($this->websiteId);
185
+ Mage::helper('ddg')->updateDataFields($email, $website, $this->storeName);
186
+ }
187
+
188
+ private function _updateNewOrderDatafields($email)
189
+ {
190
+ $website = Mage::app()->getWebsite($this->websiteId);
191
+ $order = Mage::getModel('sales/order')->load($this->typeId);
192
+
193
+
194
+ //data fields
195
+ if($last_order_id = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_LAST_ORDER_ID)){
196
+ $data[] = array(
197
+ 'Key' => $last_order_id,
198
+ 'Value' => $order->getId()
199
+ );
200
+ }
201
+ if($order_increment_id = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_LAST_ORDER_INCREMENT_ID)){
202
+ $data[] = array(
203
+ 'Key' => $order_increment_id,
204
+ 'Value' => $order->getIncrementId()
205
+ );
206
+ }
207
+ if($store_name = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_STORE_NAME)){
208
+ $data[] = array(
209
+ 'Key' => $store_name,
210
+ 'Value' => $this->storeName
211
+ );
212
+ }
213
+ if($website_name = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_WEBSITE_NAME)){
214
+ $data[] = array(
215
+ 'Key' => $website_name,
216
+ 'Value' => $website->getName()
217
+ );
218
+ }
219
+ if($last_order_date = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_LAST_ORDER_DATE)){
220
+ $data[] = array(
221
+ 'Key' => $last_order_date,
222
+ 'Value' => $order->getCreatedAt()
223
+ );
224
+ }
225
+ if(($customer_id = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_ID)) && $order->getCustomerId()){
226
+ $data[] = array(
227
+ 'Key' => $customer_id,
228
+ 'Value' => $order->getCustomerId()
229
+ );
230
+ }
231
+
232
+ if(! empty($data)){
233
+ //update data fields
234
+ $client = Mage::helper('ddg')->getWebsiteApiClient($website);
235
+ $client->updateContactDatafieldsByEmail($order->getCustomerEmail(), $data);
236
+ }
237
+
238
+ }
239
+
240
+ /**
241
+ * Program check if is valid and active.
242
+ * @param $programId
243
+ *
244
+ * @return bool
245
+ */
246
+ private function _checkCampignEnrolmentActive($programId)
247
+ {
248
+ //program is not set
249
+ if (!$programId)
250
+ return false;
251
+ $client = Mage::helper('ddg')->getWebsiteApiClient($this->websiteId);
252
+ $program = $client->getProgramById($programId);
253
+
254
+ //program status
255
+ if (isset($program->status))
256
+ $this->programStatus = $program->status;
257
+ if (isset($program->status) && $program->status == 'Active') {
258
+ return true;
259
+ }
260
+
261
+ return false;
262
+ }
263
+
264
+ /**
265
+ * Enrol contacts for a program.
266
+ * @param $contacts
267
+ *
268
+ * @return null
269
+ */
270
+ public function sendContactsToAutomation($contacts)
271
+ {
272
+ $client = Mage::helper('ddg')->getWebsiteApiClient($this->websiteId);
273
+ $data = array(
274
+ 'Contacts' => $contacts,
275
+ 'ProgramId' => $this->programId,
276
+ 'AddressBooks' => array()
277
+ );
278
+
279
+ //api add contact to automation enrolment
280
+ $result = $client->postProgramsEnrolments( $data );
281
+
282
+ return $result;
283
+ }
284
+ }
app/code/community/Dotdigitalgroup/Email/Model/Campaign.php ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ /**
35
+ * constructor
36
+ */
37
+ public function _construct()
38
+ {
39
+ parent::_construct();
40
+ $this->_init('ddg_automation/campaign');
41
+ }
42
+
43
+ /**
44
+ * @return $this|Mage_Core_Model_Abstract
45
+ */
46
+ protected function _beforeSave()
47
+ {
48
+ parent::_beforeSave();
49
+ $now = Mage::getSingleton('core/date')->gmtDate();
50
+ if ($this->isObjectNew()) {
51
+ $this->setCreatedAt($now);
52
+ }
53
+ $this->setUpdatedAt($now);
54
+ return $this;
55
+ }
56
+
57
+ /**
58
+ * @param $quoteId
59
+ * @param $storeId
60
+ * @return mixed
61
+ */
62
+ public function loadByQuoteId($quoteId, $storeId)
63
+ {
64
+ $collection = $this->getCollection()
65
+ ->addFieldToFilter('quote_id', $quoteId)
66
+ ->addFieldToFilter('store_id', $storeId);
67
+
68
+ if ($collection->getSize()) {
69
+ return $collection->getFirstItem();
70
+ } else {
71
+ $this->setQuoteId($quoteId)
72
+ ->setStoreId($storeId);
73
+ }
74
+
75
+ return $this;
76
+ }
77
+
78
+
79
+ /**
80
+ * Sending the campaigns.
81
+ */
82
+ public function sendCampaigns()
83
+ {
84
+ //grab the emails not send
85
+ $emailsToSend = $this->_getEmailCampaigns();
86
+
87
+ foreach ($emailsToSend as $campaign) {
88
+
89
+ $email = $campaign->getEmail();
90
+ $storeId = $campaign->getStoreId();
91
+ $campaignId = $campaign->getCampaignId();
92
+ $store = Mage::app()->getStore($storeId);
93
+ $websiteId = $store->getWebsiteId();
94
+
95
+
96
+ if (!$campaignId) {
97
+ $campaign->setMessage('Missing campaign id: ' . $campaignId)
98
+ ->setIsSent(1)
99
+ ->save();
100
+ continue;
101
+ } elseif (!$email) {
102
+ $campaign->setMessage('Missing email : ' . $email)
103
+ ->setIsSent(1)
104
+ ->save();
105
+ continue;
106
+ }
107
+ try{
108
+ $client = Mage::helper('ddg')->getWebsiteApiClient($websiteId);
109
+ $contactId = Mage::helper('ddg')->getContactId($campaign->getEmail(), $websiteId);
110
+ if(is_numeric($contactId)) {
111
+ $response = $client->postCampaignsSend($campaignId, array($contactId));
112
+ if (isset($response->message)) {
113
+ //update the failed to send email message
114
+ $campaign->setMessage($response->message)->setIsSent(1)->save();
115
+ }
116
+ $now = Mage::getSingleton('core/date')->gmtDate();
117
+ //record suscces
118
+ $campaign->setIsSent(1)
119
+ ->setMessage(NULL)
120
+ ->setSentAt($now)
121
+ ->save();
122
+ }else{
123
+ //update the failed to send email message- error message from post contact
124
+ $campaign->setContactMessage($contactId)->setIsSent(1)->save();
125
+ }
126
+ }catch(Exception $e){
127
+ Mage::logException($e);
128
+ }
129
+ }
130
+ return;
131
+ }
132
+
133
+ /**
134
+ * @return mixed
135
+ */
136
+ private function _getEmailCampaigns()
137
+ {
138
+ $emailCollection = $this->getCollection();
139
+ $emailCollection->addFieldToFilter('is_sent', array('null' => true))
140
+ ->addFieldToFilter('campaign_id', array('notnull' => true));
141
+ $emailCollection->getSelect()->order('campaign_id');
142
+ return $emailCollection;
143
+ }
144
+ }
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('ddg_automation/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->getSize()) {
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->getSize()) {
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,293 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * Contact default datafields.
29
+ *
30
+ * @var array
31
+ */
32
+ private $_contactDatafields = array(
33
+ 'customer_id' => array(
34
+ 'name' => 'CUSTOMER_ID',
35
+ 'type' => 'numeric',
36
+ 'visibility' => 'private',
37
+ ),
38
+ 'firstname' => array(
39
+ 'name' => 'FIRSTNAME',
40
+ 'type' => 'string',
41
+ 'visibility' => 'private',
42
+ ),
43
+ 'lastname' => array(
44
+ 'name' => 'LASTNAME',
45
+ 'type' => 'string',
46
+ 'visibility' => 'private',
47
+ ),
48
+ 'gender' => array(
49
+ 'name' => 'GENDER',
50
+ 'type' => 'string',
51
+ 'visibility' => 'private',
52
+ ),
53
+ 'dob' => array(
54
+ 'name' => 'DOB',
55
+ 'type' => 'date',
56
+ 'visibility' => 'private',
57
+ ),
58
+ 'title' => array(
59
+ 'name' => 'TITLE',
60
+ 'type' => 'string',
61
+ 'visibility' => 'private',
62
+ ),
63
+ 'website_name' => array(
64
+ 'name' => 'WEBSITE_NAME',
65
+ 'type' => 'string',
66
+ 'visibility' => 'private',
67
+ ),
68
+ 'store_name' => array(
69
+ 'name' => 'STORE_NAME',
70
+ 'type' => 'string',
71
+ 'visibility' => 'private',
72
+ ),
73
+ 'created_at' => array(
74
+ 'name' => 'ACCOUNT_CREATED_DATE',
75
+ 'type' => 'date',
76
+ 'visibility' => 'private',
77
+ ),
78
+ 'last_logged_date' => array(
79
+ 'name' => 'LAST_LOGGEDIN_DATE',
80
+ 'type' => 'date',
81
+ 'visibility' => 'private',
82
+ ),
83
+ 'customer_group' => array(
84
+ 'name' => 'CUSTOMER_GROUP',
85
+ 'type' => 'string',
86
+ 'visibility' => 'private',
87
+ ),
88
+ 'billing_address_1' => array(
89
+ 'name' => 'BILLING_ADDRESS_1',
90
+ 'type' => 'string',
91
+ 'visibility' => 'private',
92
+ 'defaultValue' => ''
93
+ ),
94
+ 'billing_address_2' => array(
95
+ 'name' => 'BILLING_ADDRESS_2',
96
+ 'type' => 'string',
97
+ 'visibility' => 'private',
98
+ ),
99
+ 'billing_state' => array(
100
+ 'name' => 'BILLING_STATE',
101
+ 'type' => 'string',
102
+ 'visibility' => 'private',
103
+ ),
104
+ 'billing_city' => array(
105
+ 'name' => 'BILLING_CITY',
106
+ 'type' => 'string',
107
+ 'visibility' => 'private',
108
+ ),
109
+ 'billing_country' => array(
110
+ 'name' => 'BILLING_COUNTRY',
111
+ 'type' => 'string',
112
+ 'visibility' => 'private',
113
+ ),
114
+ 'billing_postcode' => array(
115
+ 'name' => 'BILLING_POSTCODE',
116
+ 'type' => 'string',
117
+ 'visibility' => 'private',
118
+ ),
119
+ 'billing_telephone' => array(
120
+ 'name' => 'BILLING_TELEPHONE',
121
+ 'type' => 'string',
122
+ 'visibility' => 'private',
123
+ ),
124
+ 'delivery_address_1' => array(
125
+ 'name' => 'DELIVERY_ADDRESS_1',
126
+ 'type' => 'string',
127
+ 'visibility' => 'private',
128
+ ),
129
+ 'delivery_address_2' => array(
130
+ 'name' => 'DELIVERY_ADDRESS_2',
131
+ 'type' => 'string',
132
+ 'visibility' => 'private',
133
+ ),
134
+ 'delivery_state' => array(
135
+ 'name' => 'DELIVERY_STATE',
136
+ 'type' => 'string',
137
+ 'visibility' => 'private',
138
+ ),
139
+ 'delivery_city' => array(
140
+ 'name' => 'DELIVERY_CITY',
141
+ 'type' => 'string',
142
+ 'visibility' => 'private',
143
+ ),
144
+ 'delivery_country' => array(
145
+ 'name' => 'DELIVERY_COUNTRY',
146
+ 'type' => 'string',
147
+ 'visibility' => 'private',
148
+ ),
149
+ 'delivery_postcode' => array(
150
+ 'name' => 'DELIVERY_POSTCODE',
151
+ 'type' => 'string',
152
+ 'visibility' => 'private',
153
+ ),
154
+ 'delivery_telephone' => array(
155
+ 'name' => 'DELIVERY_TELEPHONE',
156
+ 'type' => 'string',
157
+ 'visibility' => 'private',
158
+ ),
159
+ 'number_of_orders' => array(
160
+ 'name' => 'NUMBER_OF_ORDERS',
161
+ 'type' => 'numeric',
162
+ 'visibility' => 'private',
163
+ ),
164
+ 'total_spend' => array(
165
+ 'name' => 'TOTAL_SPEND',
166
+ 'type' => 'numeric',
167
+ 'visibility' => 'private',
168
+ ),
169
+ 'average_order_value' => array(
170
+ 'name' => 'AVERAGE_ORDER_VALUE',
171
+ 'type' => 'numeric',
172
+ 'visibility' => 'private',
173
+ ),
174
+ 'last_order_date' => array(
175
+ 'name' => 'LAST_ORDER_DATE',
176
+ 'type' => 'date',
177
+ 'visibility' => 'private',
178
+ ),
179
+ 'last_order_id' => array(
180
+ 'name' => 'LAST_ORDER_ID',
181
+ 'type' => 'numeric',
182
+ 'visibility' => 'private',
183
+ ),
184
+ 'last_increment_id' => array(
185
+ 'name' => 'LAST_INCREMENT_ID',
186
+ 'type' => 'numeric',
187
+ 'visibility' => 'private',
188
+ ),
189
+ 'last_quote_id' => array(
190
+ 'name' => 'LAST_QUOTE_ID',
191
+ 'type' => 'numeric',
192
+ 'visibility' => 'private',
193
+ ),
194
+ 'total_refund' => array(
195
+ 'name' => 'TOTAL_REFUND',
196
+ 'type' => 'numeric',
197
+ 'visibility' => 'private',
198
+ ),
199
+ 'review_count' => array(
200
+ 'name' => 'REVIEW_COUNT',
201
+ 'type' => 'numeric',
202
+ 'visibility' => 'private',
203
+ ),
204
+ 'last_review_date' => array(
205
+ 'name' => 'LAST_REVIEW_DATE',
206
+ 'type' => 'date',
207
+ 'visibility' => 'private',
208
+ ),
209
+ 'subscriber_status' => array(
210
+ 'name' => 'SUBSCRIBER_STATUS',
211
+ 'type' => 'string',
212
+ 'visibility' => 'private',
213
+ ),
214
+ 'most_pur_category' => array(
215
+ 'name' => 'MOST_PUR_CATEGORY',
216
+ 'type' => 'string',
217
+ 'visibility' => 'private',
218
+ ),
219
+ 'most_pur_brand' => array(
220
+ 'name' => 'MOST_PUR_BRAND',
221
+ 'type' => 'string',
222
+ 'visibility' => 'private',
223
+ ),
224
+ 'most_freq_pur_day' => array(
225
+ 'name' => 'MOST_FREQ_PUR_DAY',
226
+ 'type' => 'string',
227
+ 'visibility' => 'private',
228
+ ),
229
+ 'most_freq_pur_mon' => array(
230
+ 'name' => 'MOST_FREQ_PUR_MON',
231
+ 'type' => 'string',
232
+ 'visibility' => 'private',
233
+ ),
234
+ 'first_category_pur' => array(
235
+ 'name' => 'FIRST_CATEGORY_PUR',
236
+ 'type' => 'string',
237
+ 'visibility' => 'private',
238
+ ),
239
+ 'last_category_pur' => array(
240
+ 'name' => 'LAST_CATEGORY_PUR',
241
+ 'type' => 'string',
242
+ 'visibility' => 'private',
243
+ ),
244
+ 'first_brand_pur' => array(
245
+ 'name' => 'FIRST_BRAND_PUR',
246
+ 'type' => 'string',
247
+ 'visibility' => 'private',
248
+ ),
249
+ 'last_brand_pur' => array(
250
+ 'name' => 'LAST_BRAND_PUR',
251
+ 'type' => 'string',
252
+ 'visibility' => 'private',
253
+ ),
254
+ );
255
+
256
+ /**
257
+ * @param array $contactDatafields
258
+ */
259
+ public function setContactDatafields($contactDatafields)
260
+ {
261
+ $this->_contactDatafields = $contactDatafields;
262
+ }
263
+
264
+ /**
265
+ * @return array
266
+ */
267
+ public function getContactDatafields()
268
+ {
269
+ return $this->_contactDatafields;
270
+ }
271
+
272
+ /**
273
+ * set a single datafield.
274
+ *
275
+ * @param $name
276
+ * @param $value
277
+ * @param string $type
278
+ * @param string $visibility
279
+ *
280
+ * @return array
281
+ */
282
+ public function setDatafield($name, $value, $type = 'string', $visibility = 'private')
283
+ {
284
+ $this->datafields[] = array(
285
+ 'name' => $name,
286
+ 'value' => $value,
287
+ 'type' => $type,
288
+ 'visibility' => $visibility
289
+ );
290
+ return $this->datafields;
291
+ }
292
+
293
+ }
app/code/community/Dotdigitalgroup/Email/Model/Connector/Order.php ADDED
@@ -0,0 +1,279 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * @var array
78
+ */
79
+ public $custom = array();
80
+
81
+ /**
82
+ * set the order information
83
+ * @param Mage_Sales_Model_Order $orderData
84
+ */
85
+ public function __construct(Mage_Sales_Model_Order $orderData)
86
+ {
87
+ $customerModel = Mage::getModel('customer/customer');
88
+ $customerModel->load($orderData->getCustomerId());
89
+
90
+ $this->id = $orderData->getIncrementId();
91
+ $this->quote_id = $orderData->getQuoteId();
92
+ $this->email = $orderData->getCustomerEmail();
93
+ $this->store_name = $orderData->getStoreName();
94
+
95
+ $created_at = new Zend_Date($orderData->getCreatedAt(), Zend_Date::ISO_8601);
96
+
97
+ $this->purchase_date = $created_at->toString(Zend_Date::ISO_8601);
98
+ $this->delivery_method = $orderData->getShippingDescription();
99
+ $this->delivery_total = $orderData->getShippingAmount();
100
+ $this->currency = $orderData->getStoreCurrencyCode();
101
+
102
+ if ($payment = $orderData->getPayment())
103
+ $this->payment = $payment->getMethodInstance()->getTitle();
104
+ $this->couponCode = $orderData->getCouponCode();
105
+
106
+ /**
107
+ * custom order attributes
108
+ */
109
+ $helper = Mage::helper('ddg');
110
+ $website = Mage::app()->getStore($orderData->getStore())->getWebsite();
111
+ $customAttributes = $helper->getConfigSelectedCustomOrderAttributes($website);
112
+ if($customAttributes){
113
+ $fields = $helper->getOrderTableDescription();
114
+ foreach($customAttributes as $customAttribute){
115
+ if(isset($fields[$customAttribute])){
116
+ $field = $fields[$customAttribute];
117
+ $value = $this->_getCustomAttributeValue($field, $orderData);
118
+ if($value)
119
+ $this->_assignCustom($field, $value);
120
+ }
121
+ }
122
+ }
123
+
124
+ /**
125
+ * Billing address.
126
+ */
127
+ if ($orderData->getBillingAddress()) {
128
+ $billingData = $orderData->getBillingAddress()->getData();
129
+ $this->billing_address = array(
130
+ 'billing_address_1' => $this->_getStreet($billingData['street'], 1),
131
+ 'billing_address_2' => $this->_getStreet($billingData['street'], 2),
132
+ 'billing_city' => $billingData['city'],
133
+ 'billing_region' => $billingData['region'],
134
+ 'billing_country' => $billingData['country_id'],
135
+ 'billing_postcode' => $billingData['postcode'],
136
+ );
137
+ }
138
+ /**
139
+ * Shipping address.
140
+ */
141
+ if ($orderData->getShippingAddress()) {
142
+ $shippingData = $orderData->getShippingAddress()->getData();
143
+
144
+ $this->delivery_address = array(
145
+ 'delivery_address_1' => $this->_getStreet($shippingData['street'], 1),
146
+ 'delivery_address_2' => $this->_getStreet($shippingData['street'], 2),
147
+ 'delivery_city' => $shippingData['city'],
148
+ 'delivery_region' => $shippingData['region'],
149
+ 'delivery_country' => $shippingData['country_id'],
150
+ 'delivery_postcode' => $shippingData['postcode']
151
+ );
152
+ }
153
+
154
+ /**
155
+ * Order items.
156
+ */
157
+ foreach ($orderData->getAllItems() as $productItem) {
158
+
159
+ //load product by product id, for compatibility
160
+ $product = Mage::getModel('catalog/product')->load($productItem->getProductId());
161
+
162
+ if ($product) {
163
+ // category names
164
+ $categoryCollection = $product->getCategoryCollection()
165
+ ->addAttributeToSelect( 'name' );
166
+
167
+ foreach ( $categoryCollection as $cat ) {
168
+ $categories = array();
169
+ $categories[] = $cat->getName();
170
+ $this->categories[]['Name'] = substr( implode( ', ', $categories ), 0, 244 );
171
+ }
172
+
173
+ $attributeSetModel = Mage::getModel( "eav/entity_attribute_set" );
174
+ $attributeSetModel->load( $product->getAttributeSetId() );
175
+ $attributeSetName = $attributeSetModel->getAttributeSetName();
176
+ $this->products[] = array(
177
+ 'name' => $productItem->getName(),
178
+ 'sku' => $productItem->getSku(),
179
+ 'qty' => (int) number_format( $productItem->getData( 'qty_ordered' ), 2 ),
180
+ 'price' => (float) number_format( $productItem->getPrice(), 2, '.', '' ),
181
+ 'attribute-set' => $attributeSetName
182
+ );
183
+ } else {
184
+ // when no product information is available limit to this data
185
+ $this->products[] = array(
186
+ 'name' => $productItem->getName(),
187
+ 'sku' => $productItem->getSku(),
188
+ 'qty' => (int) number_format( $productItem->getData( 'qty_ordered' ), 2 ),
189
+ 'price' => (float) number_format( $productItem->getPrice(), 2, '.', '' )
190
+ );
191
+ }
192
+ }
193
+
194
+ $this->order_subtotal = (float)number_format($orderData->getData('subtotal'), 2 , '.', '');
195
+ $this->discount_ammount = (float)number_format($orderData->getData('discount_amount'), 2 , '.', '');
196
+ $orderTotal = abs($orderData->getData('grand_total') - $orderData->getTotalRefunded());
197
+ $this->order_total = (float)number_format($orderTotal, 2 , '.', '');
198
+
199
+ return true;
200
+ }
201
+ /**
202
+ * get the street name by line number
203
+ * @param $street
204
+ * @param $line
205
+ * @return string
206
+ */
207
+ private function _getStreet($street, $line)
208
+ {
209
+ $street = explode("\n", $street);
210
+ if ($line == 1) {
211
+ return $street[0];
212
+ }
213
+ if (isset($street[$line -1])) {
214
+
215
+ return $street[$line - 1];
216
+ } else {
217
+
218
+ return '';
219
+ }
220
+ }
221
+
222
+ /**
223
+ * exposes the class as an array of objects.
224
+ * @return array
225
+ */
226
+ public function expose()
227
+ {
228
+ return get_object_vars($this);
229
+
230
+ }
231
+
232
+ private function _getCustomAttributeValue($field, $orderData)
233
+ {
234
+ $type = $field['DATA_TYPE'];
235
+
236
+ $function = 'get';
237
+ $exploded = explode('_', $field['COLUMN_NAME']);
238
+ foreach ($exploded as $one) {
239
+ $function .= ucfirst($one);
240
+ }
241
+
242
+ $value = null;
243
+ if($type == 'int' or $type == 'smallint'){
244
+ try{
245
+ $value = (int)$orderData->$function();
246
+ }catch (Exception $e){
247
+ Mage::logException($e);
248
+ }
249
+ }
250
+ if($type == 'decimal'){
251
+ try{
252
+ $value = (float)number_format($orderData->$function(), 2 , '.', '');
253
+ }catch (Exception $e){
254
+ Mage::logException($e);
255
+ }
256
+ }
257
+ if($type == 'timestamp' or $type == 'datetime'){
258
+ try{
259
+ $date = new Zend_Date($orderData->$function(), Zend_Date::ISO_8601);
260
+ $value = $date->toString(Zend_Date::ISO_8601);
261
+ }catch (Exception $e){
262
+ Mage::logException($e);
263
+ }
264
+ }
265
+
266
+ return $value;
267
+ }
268
+
269
+ /**
270
+ * create property on runtime
271
+ *
272
+ * @param $field
273
+ * @param $value
274
+ */
275
+ private function _assignCustom($field, $value)
276
+ {
277
+ $this->custom[$field['COLUMN_NAME']] = $value;
278
+ }
279
+ }
app/code/community/Dotdigitalgroup/Email/Model/Connector/Quote.php ADDED
@@ -0,0 +1,282 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Connector_Quote
4
+ {
5
+ /**
6
+ * @var int
7
+ */
8
+ public $id;
9
+ /**
10
+ * Email
11
+ * @var string
12
+ */
13
+ public $email;
14
+ /**
15
+ * @var string
16
+ */
17
+ public $store_name;
18
+ /**
19
+ * @var string
20
+ */
21
+ public $created_date;
22
+ /**
23
+ * @var string
24
+ */
25
+ public $delivery_address;
26
+ /**
27
+ * @var string
28
+ */
29
+ public $billing_address;
30
+ /**
31
+ * @var array
32
+ */
33
+ public $products = array();
34
+ /**
35
+ * @var float
36
+ */
37
+ public $quote_subtotal;
38
+ /**
39
+ * @var float
40
+ */
41
+ public $discount_amount;
42
+ /**
43
+ * @var float
44
+ */
45
+ public $quote_total;
46
+ /**
47
+ * @var array
48
+ */
49
+ public $categories;
50
+ /**
51
+ * Payment name
52
+ * @var string
53
+ */
54
+ public $payment;
55
+ /**
56
+ * @var string
57
+ */
58
+ public $delivery_method;
59
+ /**
60
+ * @var float
61
+ */
62
+ public $delivery_total;
63
+ /**
64
+ * @var string
65
+ */
66
+ public $currency;
67
+
68
+
69
+ public $couponCode;
70
+
71
+ /**
72
+ * @var array
73
+ */
74
+ public $custom = array();
75
+
76
+ /**
77
+ * set the quote information
78
+ * @param Mage_Sales_Model_Quote $quoteData
79
+ */
80
+ public function __construct(Mage_Sales_Model_Quote $quoteData)
81
+ {
82
+ $customerModel = Mage::getModel('customer/customer');
83
+ $customerModel->load($quoteData->getCustomerId());
84
+
85
+ $this->id = $quoteData->getId();
86
+ $this->email = $quoteData->getCustomerEmail();
87
+ $this->store_name = $quoteData->getStore()->getName();
88
+
89
+ $created_at = new Zend_Date($quoteData->getCreatedAt(), Zend_Date::ISO_8601);
90
+
91
+ $this->created_date = $created_at->toString(Zend_Date::ISO_8601);
92
+ if($quoteData->getShippingAddress()){
93
+ $this->delivery_method = $quoteData->getShippingAddress()->getShippingDescription();
94
+ $this->delivery_total = $quoteData->getShippingAddress()->getShippingAmount();
95
+ }
96
+ $this->currency = $quoteData->getStoreCurrencyCode();
97
+ if ($payment = $quoteData->getPayment())
98
+ $this->payment = $payment->getMethod();
99
+
100
+ $this->couponCode = $quoteData->getCouponCode();
101
+
102
+ /**
103
+ * custom quote attributes
104
+ */
105
+ $helper = Mage::helper('ddg');
106
+ $website = Mage::app()->getStore($quoteData->getStore())->getWebsite();
107
+ $customAttributes = $helper->getConfigSelectedCustomQuoteAttributes($website);
108
+ if($customAttributes){
109
+ $fields = $helper->getQuoteTableDescription();
110
+ foreach($customAttributes as $customAttribute){
111
+ if(isset($fields[$customAttribute])){
112
+ $field = $fields[$customAttribute];
113
+ $value = $this->_getCustomAttributeValue($field, $quoteData);
114
+ if($value)
115
+ $this->_assignCustom($field, $value);
116
+ }
117
+ }
118
+ }
119
+
120
+ /**
121
+ * Billing address.
122
+ */
123
+ if ($quoteData->getBillingAddress()) {
124
+ $billingData = $quoteData->getBillingAddress()->getData();
125
+ $this->billing_address = array(
126
+ 'billing_address_1' => $this->_getStreet($billingData['street'], 1),
127
+ 'billing_address_2' => $this->_getStreet($billingData['street'], 2),
128
+ 'billing_city' => $billingData['city'],
129
+ 'billing_region' => $billingData['region'],
130
+ 'billing_country' => $billingData['country_id'],
131
+ 'billing_postcode' => $billingData['postcode'],
132
+ );
133
+ }
134
+ /**
135
+ * Shipping address.
136
+ */
137
+ if ($quoteData->getShippingAddress()) {
138
+ $shippingData = $quoteData->getShippingAddress()->getData();
139
+
140
+ $this->delivery_address = array(
141
+ 'delivery_address_1' => $this->_getStreet($shippingData['street'], 1),
142
+ 'delivery_address_2' => $this->_getStreet($shippingData['street'], 2),
143
+ 'delivery_city' => $shippingData['city'],
144
+ 'delivery_region' => $shippingData['region'],
145
+ 'delivery_country' => $shippingData['country_id'],
146
+ 'delivery_postcode' => $shippingData['postcode']
147
+ );
148
+ }
149
+
150
+ /**
151
+ * Quote items.
152
+ */
153
+ foreach ($quoteData->getAllItems() as $productItem) {
154
+
155
+ //load product by product id, for compatibility
156
+ $product = Mage::getModel('catalog/product')->load($productItem->getProductId());
157
+
158
+ if ($product) {
159
+ // category names
160
+ $categoryCollection = $product->getCategoryCollection()
161
+ ->addAttributeToSelect( 'name' );
162
+
163
+ foreach ( $categoryCollection as $cat ) {
164
+ $categories = array();
165
+ $categories[] = $cat->getName();
166
+ $this->categories[]['Name'] = substr( implode( ', ', $categories ), 0, 244 );
167
+ }
168
+
169
+ $attributeSetModel = Mage::getModel( "eav/entity_attribute_set" );
170
+ $attributeSetModel->load( $product->getAttributeSetId() );
171
+ $attributeSetName = $attributeSetModel->getAttributeSetName();
172
+ $this->products[] = array(
173
+ 'name' => $productItem->getName(),
174
+ 'sku' => $productItem->getSku(),
175
+ 'qty' => (int) number_format( $productItem->getData( 'qty' ), 2 ),
176
+ 'price' => (float) number_format( $productItem->getPrice(), 2, '.', '' ),
177
+ 'attribute-set' => $attributeSetName
178
+ );
179
+ } else {
180
+ // when no product information is available limit to this data
181
+ $this->products[] = array(
182
+ 'name' => $productItem->getName(),
183
+ 'sku' => $productItem->getSku(),
184
+ 'qty' => (int) number_format( $productItem->getData( 'qty' ), 2 ),
185
+ 'price' => (float) number_format( $productItem->getPrice(), 2, '.', '' )
186
+ );
187
+ }
188
+ }
189
+
190
+ $this->quote_subtotal = (float)number_format($quoteData->getData('subtotal'), 2 , '.', '');
191
+ $discountAmount = $quoteData->getData('subtotal') - $quoteData->getData('subtotal_with_discount');
192
+ $this->discount_amount = (float)number_format($discountAmount, 2 , '.', '');
193
+ $this->quote_total = (float)number_format($quoteData->getData('grand_total'), 2 , '.', '');
194
+
195
+ return true;
196
+ }
197
+ /**
198
+ * get the street name by line number
199
+ * @param $street
200
+ * @param $line
201
+ * @return string
202
+ */
203
+ private function _getStreet($street, $line)
204
+ {
205
+ $street = explode("\n", $street);
206
+ if ($line == 1) {
207
+ return $street[0];
208
+ }
209
+ if (isset($street[$line -1])) {
210
+
211
+ return $street[$line - 1];
212
+ } else {
213
+
214
+ return '';
215
+ }
216
+ }
217
+
218
+ /**
219
+ * exposes the class as an array of objects.
220
+ * @return array
221
+ */
222
+ public function expose()
223
+ {
224
+ return get_object_vars($this);
225
+
226
+ }
227
+
228
+ /**
229
+ * get custom attribute value
230
+ *
231
+ * @param $field
232
+ * @param $quoteData
233
+ * @return float|int|null|string
234
+ */
235
+ private function _getCustomAttributeValue($field, $quoteData)
236
+ {
237
+ $type = $field['DATA_TYPE'];
238
+
239
+ $function = 'get';
240
+ $exploded = explode('_', $field['COLUMN_NAME']);
241
+ foreach ($exploded as $one) {
242
+ $function .= ucfirst($one);
243
+ }
244
+
245
+ $value = null;
246
+ if($type == 'int' or $type == 'smallint'){
247
+ try{
248
+ $value = (int)$quoteData->$function();
249
+ }catch (Exception $e){
250
+ Mage::logException($e);
251
+ }
252
+ }
253
+ if($type == 'decimal'){
254
+ try{
255
+ $value = (float)number_format($quoteData->$function(), 2 , '.', '');
256
+ }catch (Exception $e){
257
+ Mage::logException($e);
258
+ }
259
+ }
260
+ if($type == 'timestamp' or $type == 'datetime'){
261
+ try{
262
+ $date = new Zend_Date($quoteData->$function(), Zend_Date::ISO_8601);
263
+ $value = $date->toString(Zend_Date::ISO_8601);
264
+ }catch (Exception $e){
265
+ Mage::logException($e);
266
+ }
267
+ }
268
+
269
+ return $value;
270
+ }
271
+
272
+ /**
273
+ * create property on runtime
274
+ *
275
+ * @param $field
276
+ * @param $value
277
+ */
278
+ private function _assignCustom($field, $value)
279
+ {
280
+ $this->custom[$field['COLUMN_NAME']] = $value;
281
+ }
282
+ }
app/code/community/Dotdigitalgroup/Email/Model/Contact.php ADDED
@@ -0,0 +1,290 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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('ddg_automation/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('ddg_automation/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('ddg')->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->getSize()) {
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
+
145
+ $storeIds = $website->getStoreIds();
146
+ $collection = $this->getCollection()
147
+ ->addFieldToFilter('is_subscriber', array('notnull' => true))
148
+ ->addFieldToFilter('subscriber_imported', array('null' => true))
149
+ ->addFieldToFilter('store_id', array('in' => $storeIds));
150
+
151
+ $collection->getSelect()->limit($limit);
152
+
153
+ return $collection;
154
+ }
155
+
156
+ /**
157
+ * get all not imported guests for a website.
158
+ * @param $website
159
+ *
160
+ * @return Dotdigitalgroup_Email_Model_Resource_Contact_Collection
161
+ */
162
+ public function getGuests($website)
163
+ {
164
+ $guestCollection = $this->getCollection()
165
+ ->addFieldToFilter('is_guest', array('notnull' => true))
166
+ ->addFieldToFilter('email_imported', array('null' => true))
167
+ ->addFieldToFilter('website_id', $website->getId());
168
+ return $guestCollection->load();
169
+ }
170
+
171
+ public function getNumberOfImportedContacs()
172
+ {
173
+ $collection = $this->getCollection()
174
+ ->addFieldToFilter('email_imported', array('notnull' => true));
175
+
176
+ return $collection->getSize();
177
+ }
178
+
179
+
180
+ /**
181
+ * Set all imported subscribers for reimport.
182
+ *
183
+ * @return int
184
+ */
185
+ public function resetSubscribers() {
186
+
187
+ /** @var $coreResource Mage_Core_Model_Resource */
188
+ $coreResource = Mage::getSingleton( 'core/resource' );
189
+
190
+ /** @var $conn Varien_Db_Adapter_Pdo_Mysql */
191
+ $conn = $coreResource->getConnection( 'core_write' );
192
+
193
+ try {
194
+ $num = $conn->update(
195
+ $coreResource->getTableName( 'ddg_automation/contact' ),
196
+ array('subscriber_imported' => new Zend_Db_Expr( 'null' ) ),
197
+ $conn->quoteInto('subscriber_imported is ?', new Zend_Db_Expr('not null')));
198
+
199
+ } catch ( Exception $e ) {
200
+ Mage::logException($e);
201
+ Mage::helper('ddg')->getRaygunClient()->SendException($e, array(Mage::getBaseUrl('web')));
202
+ }
203
+
204
+ return $num;
205
+ }
206
+
207
+ /**
208
+ * Get the number of customers for a website.
209
+ * @param int $websiteId
210
+ *
211
+ * @return int
212
+ */
213
+ public function getNumberCustomerContacts($websiteId = 0)
214
+ {
215
+ $countContacts = Mage::getModel('ddg_automation/contact')->getCollection()
216
+ ->addFieldToFilter('customer_id', array('gt' => '0'))
217
+ ->addFieldToFilter('website_id', $websiteId)
218
+ ->getSize();
219
+ return $countContacts;
220
+ }
221
+
222
+ /**
223
+ *
224
+ * Get number of suppressed contacts as customer.
225
+ * @param int $websiteId
226
+ *
227
+ * @return int
228
+ */
229
+ public function getNumberCustomerSuppressed( $websiteId = 0 )
230
+ {
231
+ $countContacts = Mage::getModel('ddg_automation/contact')->getCollection()
232
+ ->addFieldToFilter('customer_id', array('gt' => 0))
233
+ ->addFieldToFilter('website_id', $websiteId)
234
+ ->addFieldToFilter('suppressed', '1')
235
+ ->getSize();
236
+
237
+ return $countContacts;
238
+ }
239
+
240
+ /**
241
+ * Get number of synced customers.
242
+ * @param int $websiteId
243
+ *
244
+ * @return int
245
+ */
246
+ public function getNumberCustomerSynced( $websiteId = 0 )
247
+ {
248
+ $countContacts = Mage::getModel('ddg_automation/contact')->getCollection()
249
+ ->addFieldToFilter('customer_id', array('gt' => 0))
250
+ ->addFieldToFilter('website_id', $websiteId)
251
+ ->addFieldToFilter('email_imported' , '1')
252
+ ->getSize();
253
+
254
+ return $countContacts;
255
+
256
+ }
257
+
258
+ /**
259
+ * Get number of subscribers synced.
260
+ * @param int $websiteId
261
+ *
262
+ * @return int
263
+ */
264
+ public function getNumberSubscribersSynced( $websiteId = 0 )
265
+ {
266
+ $countContacts = Mage::getModel('ddg_automation/contact')->getCollection()
267
+ ->addFieldToFilter('subscriber_status', Dotdigitalgroup_Email_Model_Newsletter_Subscriber::STATUS_SUBSCRIBED)
268
+ ->addFieldToFilter('subscriber_imported', '1')
269
+ ->addFieldToFilter('website_id', $websiteId)
270
+ ->getSize();
271
+
272
+ return $countContacts;
273
+ }
274
+
275
+ /**
276
+ * Get number of subscribers.
277
+ * @param int $websiteId
278
+ *
279
+ * @return int
280
+ */
281
+ public function getNumberSubscribers( $websiteId = 0 )
282
+ {
283
+
284
+ $countContacts = Mage::getModel('ddg_automation/contact')->getCollection()
285
+ ->addFieldToFilter('subscriber_status', Dotdigitalgroup_Email_Model_Newsletter_Subscriber::STATUS_SUBSCRIBED)
286
+ ->addFieldToFilter('website_id', $websiteId)
287
+ ->getSize();
288
+ return $countContacts;
289
+ }
290
+ }
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,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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('ddg_automation/apiconnector_contact')->sync();
12
+ return $result;
13
+ }
14
+
15
+ /**
16
+ * CRON FOR ABANDONED CARTS
17
+ */
18
+ public function abandonedCarts()
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( 'ddg_automation/sales_quote' )->proccessAbandonedCarts();
24
+ }
25
+ }
26
+
27
+ /**
28
+ * CRON FOR SYNC REVIEWS and REGISTER ORDER REVIEW CAMPAIGNS
29
+ */
30
+ public function reviewsAndWishlist()
31
+ {
32
+ //sync reviews
33
+ $this->reviewSync();
34
+ //sync wishlist
35
+ Mage::getModel('ddg_automation/wishlist')->sync();
36
+ }
37
+
38
+ /**
39
+ * review sync
40
+ */
41
+ public function reviewSync()
42
+ {
43
+ //find orders to review and register campaign
44
+ Mage::getModel('ddg_automation/sales_order')->createReviewCampaigns();
45
+ //sync reviews
46
+ $result = Mage::getModel('ddg_automation/review')->sync();
47
+ return $result;
48
+ }
49
+
50
+ /**
51
+ * order sync
52
+ *
53
+ * @return mixed
54
+ */
55
+ public function orderSync()
56
+ {
57
+ // send order
58
+ $orderResult = Mage::getModel('ddg_automation/sales_order')->sync();
59
+ return $orderResult;
60
+ }
61
+
62
+ /**
63
+ * quote sync
64
+ *
65
+ * @return mixed
66
+ */
67
+ public function quoteSync()
68
+ {
69
+ //send quote
70
+ $quoteResult = Mage::getModel('ddg_automation/quote')->sync();
71
+
72
+ return $quoteResult;
73
+ }
74
+
75
+ /**
76
+ * CRON FOR ORDER & QUOTE TRANSACTIONAL DATA
77
+ */
78
+ public function orderAndQuoteSync()
79
+ {
80
+ // send order
81
+ $orderResult = $this->orderSync();
82
+
83
+ //send quote
84
+ $quoteResult = $this->quoteSync();
85
+
86
+ return $orderResult['message'] . ' ' .$quoteResult['message'];
87
+ }
88
+
89
+ /**
90
+ * CRON FOR SUBSCRIBERS AND GUEST CONTACTS
91
+ */
92
+ public function subscribersAndGuestSync()
93
+ {
94
+ //sync subscribers
95
+ $subscriberModel = Mage::getModel('ddg_automation/newsletter_subscriber');
96
+ $result = $subscriberModel->sync();
97
+
98
+ //unsubscribe suppressed contacts
99
+ $subscriberModel->unsubscribe();
100
+
101
+ //sync guests
102
+ Mage::getModel('ddg_automation/customer_guest')->sync();
103
+ return $result;
104
+ }
105
+
106
+ /**
107
+ * CRON FOR EMAILS SENDING
108
+ */
109
+ public function sendEmails()
110
+ {
111
+ Mage::getModel('ddg_automation/campaign')->sendCampaigns();
112
+
113
+ return $this;
114
+ }
115
+
116
+ /**
117
+ * CLEAN ARHIVED FOLDERS
118
+ */
119
+ public function cleaning()
120
+ {
121
+ $helper = Mage::helper('ddg/file');
122
+ $archivedFolder = $helper->getArchiveFolder();
123
+ $result = $helper->deleteDir($archivedFolder);
124
+ $message = 'Cleaning cronjob result : ' . $result;
125
+ $helper->log($message);
126
+ Mage::helper('ddg')->rayLog('10', $message, 'model/cron.php');
127
+ return $result;
128
+ }
129
+
130
+
131
+ /**
132
+ * Last customer sync date.
133
+ * @return bool|string
134
+ */
135
+ public function getLastCustomerSync(){
136
+
137
+ $schedules = Mage::getModel('cron/schedule')->getCollection();
138
+ $schedules->getSelect()->limit(1)->order('executed_at DESC');
139
+ $schedules->addFieldToFilter('status', Mage_Cron_Model_Schedule::STATUS_SUCCESS);
140
+ $schedules->addFieldToFilter('job_code', 'connector_email_customer_sync');
141
+ $schedules->load();
142
+
143
+ if (count($schedules) == 0) {
144
+ return false;
145
+ }
146
+ $executedAt = $schedules->getFirstItem()->getExecutedAt();
147
+ return Mage::getModel('core/date')->date(NULL, $executedAt);
148
+ }
149
+
150
+ public function automationStatus()
151
+ {
152
+ Mage::getModel('ddg_automation/automation')->enrollment();
153
+
154
+ }
155
+ }
app/code/community/Dotdigitalgroup/Email/Model/Customer.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Customer extends Mage_Customer_Model_Customer
4
+ {
5
+ /**
6
+ * overwrites the default function
7
+ *
8
+ * @param string $type
9
+ * @param string $backUrl
10
+ * @param string $storeId
11
+ * @return Mage_Customer_Model_Customer|void
12
+ */
13
+ public function sendNewAccountEmail($type = 'registered', $backUrl = '', $storeId = '0')
14
+ {
15
+ if(Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DISABLE_CUSTOMER_SUCCESS, $storeId))
16
+ return;
17
+
18
+ parent::sendNewAccountEmail($type = 'registered', $backUrl = '', $storeId = '0');
19
+ }
20
+ }
app/code/community/Dotdigitalgroup/Email/Model/Customer/Guest.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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('ddg');
15
+ $this->_start = microtime(true);
16
+ foreach(Mage::app()->getWebsites() as $website) {
17
+
18
+ //check if the guest is mapped and enabled
19
+ $enabled = $helper->getGuestAddressBook($website);
20
+ $mapped = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_SUBSCRIBER_ENABLED);
21
+ if ($enabled && $mapped) {
22
+
23
+ //ready to start sync
24
+ if (!$this->_countGuests)
25
+ $helper->log('----------- Start guest sync ----------');
26
+
27
+ //sync guests for website
28
+ $this->exportGuestPerWebsite($website);
29
+ }
30
+ }
31
+ if ($this->_countGuests)
32
+ $helper->log('---- End Guest total time for guest sync : ' . gmdate("H:i:s", microtime(true) - $this->_start));
33
+ }
34
+
35
+ public function exportGuestPerWebsite(Mage_Core_Model_Website $website)
36
+ {
37
+ $helper = Mage::helper('ddg');
38
+ $fileHelper = Mage::helper('ddg/file');
39
+ $guests = Mage::getModel('ddg_automation/contact')->getGuests($website);
40
+ if ($guests->getSize()) {
41
+ $client = Mage::helper('ddg')->getWebsiteApiClient($website);
42
+ $guestFilename = strtolower($website->getCode() . '_guest_' . date('d_m_Y_Hi') . '.csv');
43
+ $helper->log('Guest file: ' . $guestFilename);
44
+ $storeName = $helper->getMappedStoreName($website);
45
+ $fileHelper->outputCSV($fileHelper->getFilePath($guestFilename), array('Email', 'emailType', $storeName));
46
+ foreach ($guests as $guest) {
47
+ $email = $guest->getEmail();
48
+ try{
49
+ $guest->setEmailImported(Dotdigitalgroup_Email_Model_Contact::EMAIL_CONTACT_IMPORTED)
50
+ ->save();
51
+ $storeName = $website->getName();
52
+ // save data for guests
53
+ $fileHelper->outputCSV($fileHelper->getFilePath($guestFilename), array($email, 'Html', $storeName));
54
+ $this->_countGuests++;
55
+ }catch (Exception $e){
56
+ Mage::logException($e);
57
+ }
58
+ }
59
+ if ($this->_countGuests) {
60
+ //Add to guest address book
61
+ $client->postAddressBookContactsImport($guestFilename, $helper->getGuestAddressBook($website));
62
+ }
63
+ //archive guest file
64
+ $fileHelper->archiveCSV($guestFilename);
65
+ }
66
+ }
67
+ }
app/code/community/Dotdigitalgroup/Email/Model/Customer/Observer.php ADDED
@@ -0,0 +1,358 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_after
8
+ * @param Varien_Event_Observer $observer
9
+ * @return $this
10
+ */
11
+ public function handleCustomerSaveAfter(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
+
19
+ try{
20
+ // fix for a multiple hit of the observer
21
+ $emailReg = Mage::registry($email . '_customer_save');
22
+
23
+ if ($emailReg){
24
+ return $this;
25
+ }
26
+
27
+ Mage::register($email . '_customer_save', $email);
28
+ $emailBefore = Mage::getModel('customer/customer')->load($customer->getId())->getEmail();
29
+ $contactModel = Mage::getModel('ddg_automation/contact')->loadByCustomerEmail($emailBefore, $websiteId);
30
+ //email change detection
31
+ if ($email != $emailBefore) {
32
+ Mage::helper('ddg')->log('email change detected : ' . $email . ', after : ' . $emailBefore . ', website id : ' . $websiteId);
33
+ $enabled = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED, $websiteId);
34
+
35
+ if ($enabled) {
36
+ $client = Mage::helper('ddg')->getWebsiteApiClient($websiteId);
37
+ $subscribersAddressBook = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SUBSCRIBERS_ADDRESS_BOOK_ID, $websiteId);
38
+ $response = $client->postContacts($emailBefore);
39
+ //check for matching email
40
+ if (isset($response->id)) {
41
+ if ($email != $response->email) {
42
+ $data = array(
43
+ 'Email' => $email,
44
+ 'EmailType' => 'Html'
45
+ );
46
+ //update the contact with same id - different email
47
+ $client->updateContact($response->id, $data);
48
+
49
+ }
50
+ if (!$isSubscribed && $response->status == 'Subscribed') {
51
+ $client->deleteAddressBookContact($subscribersAddressBook, $response->id);
52
+ }
53
+ } elseif (isset($response->message)) {
54
+ Mage::helper('ddg')->log('Email change error : ' . $response->message);
55
+ }
56
+ }
57
+ $contactModel->setEmail($email);
58
+ }
59
+
60
+ $contactModel->setEmailImported(Dotdigitalgroup_Email_Model_Contact::EMAIL_CONTACT_NOT_IMPORTED)
61
+ ->setCustomerId($customerId)
62
+ ->save();
63
+ }catch(Exception $e){
64
+ Mage::logException($e);
65
+ }
66
+ return $this;
67
+ }
68
+
69
+ /**
70
+ * Add new customers to the automation.
71
+ * @param Varien_Event_Observer $observer
72
+ *
73
+ * @return $this
74
+ */
75
+ public function handleCustomerRegiterSuccess(Varien_Event_Observer $observer)
76
+ {
77
+ /** @var $customer Mage_Customer_Model_Customer */
78
+ $customer = $observer->getEvent()->getCustomer();
79
+ $websiteId = $customer->getWebsiteId();
80
+ $website = Mage::app()->getWebsite($websiteId);
81
+ $storeName = $customer->getStore()->getName();
82
+
83
+
84
+ //if api is not enabled
85
+ if (!$website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED))
86
+ return $this;
87
+
88
+ try {
89
+ //program id must be map
90
+ $programId = Mage::helper( 'ddg' )->getAutomationIdByType( 'XML_PATH_CONNECTOR_AUTOMATION_STUDIO_CUSTOMER' );
91
+ if (!$programId)
92
+ return $this;
93
+ $email = $customer->getEmail();
94
+ $automation = Mage::getModel( 'ddg_automation/automation' );
95
+ $automation->setEmail( $email )
96
+ ->setAutomationType( Dotdigitalgroup_Email_Model_Automation::AUTOMATION_TYPE_NEW_CUSTOMER )
97
+ ->setEnrolmentStatus(Dotdigitalgroup_Email_Model_Automation::AUTOMATION_STATUS_PENDING)
98
+ ->setTypeId( $customer->getId() )
99
+ ->setWebsiteId($websiteId)
100
+ ->setStoreName($storeName)
101
+ ->setProgramId($programId)
102
+ ;
103
+
104
+ $automation->save();
105
+ }catch(Exception $e) {
106
+ Mage::logException($e);
107
+ }
108
+
109
+ return $this;
110
+ }
111
+
112
+ /**
113
+ * Remove the contact on customer delete.
114
+ *
115
+ * @param Varien_Event_Observer $observer
116
+ *
117
+ * @return $this
118
+ */
119
+ public function handleCustomerDeleteAfter(Varien_Event_Observer $observer)
120
+ {
121
+ $customer = $observer->getEvent()->getCustomer();
122
+ $email = $customer->getEmail();
123
+ $websiteId = $customer->getWebsiteId();
124
+ $helper = Mage::helper('ddg');
125
+
126
+ //api enabled
127
+ $enabled = $helper->getWebsiteConfig(
128
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED,
129
+ $websiteId
130
+ );
131
+ //sync enabled
132
+ $syncEnabled = $helper->getWebsiteConfig(
133
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_CONTACT_ENABLED,
134
+ $websiteId
135
+ );
136
+
137
+ /**
138
+ * Remove contact.
139
+ */
140
+ if ($enabled && $syncEnabled) {
141
+ try {
142
+ $contactModel = Mage::getModel( 'ddg_automation/contact' )->loadByCustomerEmail( $email, $websiteId );
143
+ if ( $contactModel->getId() ) {
144
+ //remove contact
145
+ $contactModel->delete();
146
+ }
147
+ //remove from account
148
+ $client = Mage::helper( 'ddg' )->getWebsiteApiClient( $websiteId );
149
+ $apiContact = $client->postContacts( $email );
150
+ if ( ! isset( $apiContact->message ) && isset( $apiContact->id ) ) {
151
+ $client->deleteContact( $apiContact->id );
152
+ }
153
+
154
+ } catch ( Exception $e ) {
155
+ Mage::logException( $e );
156
+ }
157
+ }
158
+ return $this;
159
+ }
160
+
161
+ /**
162
+ * Set contact to re-import if registered customer submitted a review. Save review in email_review table.
163
+ * @param Varien_Event_Observer $observer
164
+ * @return $this
165
+ */
166
+ public function reviewSaveAfter(Varien_Event_Observer $observer)
167
+ {
168
+ $dataObject = $observer->getEvent()->getDataObject();
169
+
170
+ if($dataObject->getCustomerId() && $dataObject->getStatusId() == Mage_Review_Model_Review::STATUS_PENDING){
171
+ $helper = Mage::helper('ddg');
172
+ $customerId = $dataObject->getCustomerId();
173
+ $helper->setConnectorContactToReImport($customerId);
174
+ //save review info in the table
175
+ $this->_registerReview($dataObject);
176
+ $store = Mage::app()->getStore($dataObject->getStoreId());
177
+ $storeName = $store->getName();
178
+ $website = Mage::app()->getStore($store)->getWebsite();
179
+ $customer = Mage::getModel('customer/customer')->load($customerId);
180
+
181
+
182
+ //if api is not enabled
183
+ if (!$website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED))
184
+ return $this;
185
+
186
+ $programId = Mage::helper( 'ddg' )->getAutomationIdByType('XML_PATH_CONNECTOR_AUTOMATION_STUDIO_REVIEW');
187
+ if ($programId) {
188
+ $automation = Mage::getModel( 'ddg_automation/automation' );
189
+ $automation->setEmail( $customer->getEmail() )
190
+ ->setAutomationType( Dotdigitalgroup_Email_Model_Automation::AUTOMATION_TYPE_NEW_REVIEW )
191
+ ->setEnrolmentStatus(Dotdigitalgroup_Email_Model_Automation::AUTOMATION_STATUS_PENDING)
192
+ ->setTypeId( $dataObject->getReviewId() )
193
+ ->setWebsiteId( $website->getId() )
194
+ ->setStoreName( $storeName )
195
+ ->setProgramId( $programId );
196
+ $automation->save();
197
+ }
198
+ }
199
+ return $this;
200
+ }
201
+
202
+ /**
203
+ * register review
204
+ *
205
+ * @param $review
206
+ */
207
+ private function _registerReview($review)
208
+ {
209
+ try{
210
+ $emailReview = Mage::getModel('ddg_automation/review');
211
+ $emailReview->setReviewId($review->getReviewId())
212
+ ->setCustomerId($review->getCustomerId())
213
+ ->setStoreId($review->getStoreId())
214
+ ->save();
215
+ }catch(Exception $e){
216
+ Mage::logException($e);
217
+ }
218
+ }
219
+
220
+ /**
221
+ * wishlist save after observer. save new wishlist in the email_wishlist table.
222
+ *
223
+ * @param Varien_Event_Observer $observer
224
+ * @return $this
225
+ */
226
+ public function wishlistSaveAfter(Varien_Event_Observer $observer)
227
+ {
228
+ if($observer->getEvent()->getObject() instanceof Mage_Wishlist_Model_Wishlist) {
229
+ $wishlist = $observer->getEvent()->getObject()->getData();
230
+ if (is_array($wishlist) && isset($wishlist['customer_id'])) {
231
+ //save wishlist info in the table
232
+ $this->_registerWishlist( $wishlist );
233
+ }
234
+ }
235
+ }
236
+
237
+ /**
238
+ * register wishlist
239
+ *
240
+ * @param $wishlist
241
+ * @return $this
242
+ */
243
+ private function _registerWishlist($wishlist)
244
+ {
245
+ try{
246
+ $emailWishlist = Mage::getModel('ddg_automation/wishlist');
247
+ $customer = Mage::getModel('customer/customer');
248
+
249
+ //if wishlist exist not to save again
250
+ if(!$emailWishlist->getWishlist($wishlist['wishlist_id'])){
251
+ $customer->load($wishlist['customer_id']);
252
+ $email = $customer->getEmail();
253
+ $wishlistId = $wishlist['wishlist_id'];
254
+ $websiteId = $customer->getWebsiteId();
255
+ $emailWishlist->setWishlistId($wishlistId)
256
+ ->setCustomerId($wishlist['customer_id'])
257
+ ->setStoreId($customer->getStoreId())
258
+ ->save();
259
+
260
+ $store = Mage::app()->getStore($customer->getStoreId());
261
+ $storeName = $store->getName();
262
+ $website = Mage::app()->getStore($store)->getWebsite();
263
+
264
+ //if api is not enabled
265
+ if (!$website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED))
266
+ return $this;
267
+
268
+ $automationType = 'XML_PATH_CONNECTOR_AUTOMATION_STUDIO_WISHLIST';
269
+ $programId = Mage::helper( 'ddg' )->getAutomationIdByType($automationType );
270
+ if ($programId) {
271
+ $automation = Mage::getModel( 'ddg_automation/automation' );
272
+ $automation->setEmail( $email )
273
+ ->setAutomationType( Dotdigitalgroup_Email_Model_Automation::AUTOMATION_TYPE_NEW_WISHLIST )
274
+ ->setEnrolmentStatus(Dotdigitalgroup_Email_Model_Automation::AUTOMATION_STATUS_PENDING)
275
+ ->setTypeId( $wishlistId )
276
+ ->setWebsiteId( $websiteId )
277
+ ->setStoreName( $storeName )
278
+ ->setProgramId( $programId );
279
+ $automation->save();
280
+ }
281
+
282
+ }
283
+ }catch(Exception $e){
284
+ Mage::logException($e);
285
+ }
286
+ }
287
+
288
+ /**
289
+ * wishlist item save after
290
+ *
291
+ * @param Varien_Event_Observer $observer
292
+ */
293
+ public function wishlistItemSaveAfter(Varien_Event_Observer $observer)
294
+ {
295
+ $object = $observer->getEvent()->getDataObject();
296
+ $wishlist = Mage::getModel( 'wishlist/wishlist' )->load( $object->getWishlistId() );
297
+ $emailWishlist = Mage::getModel( 'ddg_automation/wishlist' );
298
+ try {
299
+ if ( $object->getWishlistId() ) {
300
+ $itemCount = count( $wishlist->getItemCollection() );
301
+ $item = $emailWishlist->getWishlist( $object->getWishlistId() );
302
+
303
+ if ( $item && $item->getId() ) {
304
+ $preSaveItemCount = $item->getItemCount();
305
+
306
+ if ( $itemCount != $item->getItemCount() ) {
307
+ $item->setItemCount( $itemCount );
308
+ }
309
+
310
+ if ( $itemCount == 1 && $preSaveItemCount == 0 ) {
311
+ $item->setWishlistImported( null );
312
+ } elseif ( $item->getWishlistImported() ) {
313
+ $item->setWishlistModified( 1 );
314
+ }
315
+
316
+ $item->save();
317
+ }
318
+ }
319
+ } catch ( Exception $e ) {
320
+ Mage::logException( $e );
321
+ }
322
+
323
+ }
324
+
325
+ /**
326
+ * Wishlist delete.
327
+ *
328
+ * @param Varien_Event_Observer $observer
329
+ */
330
+ public function wishlistDeleteAfter(Varien_Event_Observer $observer)
331
+ {
332
+ $object = $observer->getEvent()->getDataObject();
333
+ $customer = Mage::getModel('customer/customer')->load($object->getCustomerId());
334
+ $website = Mage::app()->getStore($customer->getStoreId())->getWebsite();
335
+ $helper = Mage::helper('ddg');
336
+ $client = $helper->getWebsiteApiClient($website);
337
+
338
+ //sync enabled
339
+ $syncEnabled = $helper->getWebsiteConfig(
340
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_WISHLIST_ENABLED,
341
+ $website->getId()
342
+ );
343
+ if ($helper->isEnabled($website->getId()) && $syncEnabled) {
344
+ //Remove wishlist
345
+ try {
346
+ $item = Mage::getModel( 'ddg_automation/wishlist' )->getWishlist( $object->getWishlistId() );
347
+ if ( $item->getId() ) {
348
+ $result = $client->deleteContactsTransactionalData( $item->getId(), 'Wishlist' );
349
+ if ( ! isset( $result->message ) ) {
350
+ $item->delete();
351
+ }
352
+ }
353
+ } catch ( Exception $e ) {
354
+ Mage::logException( $e );
355
+ }
356
+ }
357
+ }
358
+ }
app/code/community/Dotdigitalgroup/Email/Model/Customer/Review.php ADDED
@@ -0,0 +1,240 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Customer_Review
4
+ {
5
+ /**
6
+ * @var int
7
+ */
8
+ public $id;
9
+
10
+ /**
11
+ * @var int
12
+ */
13
+ public $customer_id;
14
+
15
+ /**
16
+ * @var string
17
+ */
18
+ public $email;
19
+
20
+ /**
21
+ * @var string
22
+ */
23
+ public $product_name;
24
+
25
+ /**
26
+ * @var string
27
+ */
28
+ public $product_sku;
29
+
30
+ /**
31
+ * @var string
32
+ */
33
+ public $review_date;
34
+
35
+ /**
36
+ * @var string
37
+ */
38
+ public $website_name;
39
+
40
+ /**
41
+ * @var string
42
+ */
43
+ public $store_name;
44
+
45
+
46
+ /**
47
+ * constructor.
48
+ *
49
+ * @param Mage_Customer_Model_Customer $customer
50
+ */
51
+ public function __construct(Mage_Customer_Model_Customer $customer)
52
+ {
53
+
54
+ $this->setCustomerId($customer->getId());
55
+ $this->email = $customer->getEmail();
56
+ }
57
+
58
+ /**
59
+ * @param mixed $customer_id
60
+ */
61
+ public function setCustomerId($customer_id)
62
+ {
63
+ $this->customer_id = (int) $customer_id;
64
+ }
65
+
66
+ /**
67
+ * @return mixed
68
+ */
69
+ public function getCustomerId()
70
+ {
71
+ return (int) $this->customer_id;
72
+ }
73
+
74
+ /**
75
+ * @param $id
76
+ * @return $this
77
+ */
78
+ public function setId($id)
79
+ {
80
+ $this->id = (int) $id;
81
+ return $this;
82
+ }
83
+
84
+ /**
85
+ * @return mixed
86
+ */
87
+ public function getId()
88
+ {
89
+ return (int) $this->id;
90
+ }
91
+
92
+ /**
93
+ * create rating on runtime
94
+ *
95
+ * @param $rating_name
96
+ * @param $rating
97
+ */
98
+ public function createRating($rating_name, $rating)
99
+ {
100
+ $this->$rating_name = $rating->expose();
101
+ }
102
+
103
+ /**
104
+ * set review date.
105
+ *
106
+ * @param $date
107
+ * @return $this;
108
+ */
109
+ public function setReviewDate($date)
110
+ {
111
+ $created_at = new Zend_Date($date, Zend_Date::ISO_8601);
112
+
113
+ $this->review_date = $created_at->toString(Zend_Date::ISO_8601);;
114
+ return $this;
115
+ }
116
+
117
+ /**
118
+ * @return string
119
+ */
120
+ public function getReviewDate()
121
+ {
122
+ return $this->review_date;
123
+ }
124
+
125
+ /**
126
+ * set product
127
+ *
128
+ * @param Mage_Catalog_Model_Product $product
129
+ * @return $this
130
+ */
131
+ public function setProduct(Mage_Catalog_Model_Product $product)
132
+ {
133
+ $this->setProductName($product->getName());
134
+ $this->setProductSku($product->getSku());
135
+ return $this;
136
+ }
137
+
138
+ /**
139
+ * set review data
140
+ *
141
+ * @param Mage_Review_Model_Review $review $product
142
+ * @return $this
143
+ */
144
+ public function setReviewData(Mage_Review_Model_Review $review)
145
+ {
146
+ $store = Mage::app()->getStore($review->getStoreId());
147
+ $websiteName = $store->getWebsite()->getName();
148
+ $storeName = $store->getName();
149
+ $this->setId($review->getReviewId())
150
+ ->setWebsiteName($websiteName)
151
+ ->setStoreName($storeName)
152
+ ->setReviewDate($review->getCreatedAt());
153
+
154
+ return $this;
155
+ }
156
+
157
+ /**
158
+ * set product name
159
+ *
160
+ * @param $name
161
+ */
162
+ public function setProductName($name)
163
+ {
164
+ $this->product_name = $name;
165
+ }
166
+
167
+ /**
168
+ * @return string
169
+ */
170
+ public function getProductName()
171
+ {
172
+ return $this->product_name;
173
+ }
174
+
175
+ /**
176
+ * set product sku
177
+ *
178
+ * @param $sku
179
+ */
180
+ public function setProductSku($sku)
181
+ {
182
+ $this->product_sku = $sku;
183
+ }
184
+
185
+ /**
186
+ * @return string
187
+ */
188
+ public function getProductSku()
189
+ {
190
+ return $this->product_sku;
191
+ }
192
+
193
+ /**
194
+ * set website name
195
+ *
196
+ * @param $name
197
+ * @return $this
198
+ */
199
+ public function setWebsiteName($name)
200
+ {
201
+ $this->website_name = $name;
202
+ return $this;
203
+ }
204
+
205
+ /**
206
+ * @return string
207
+ */
208
+ public function getStoreName()
209
+ {
210
+ return $this->store_name;
211
+ }
212
+
213
+ /**
214
+ * set store name
215
+ *
216
+ * @param $name
217
+ * @return $this
218
+ */
219
+ public function setStoreName($name)
220
+ {
221
+ $this->store_name = $name;
222
+ return $this;
223
+ }
224
+
225
+ /**
226
+ * @return string
227
+ */
228
+ public function getWebsiteName()
229
+ {
230
+ return $this->website_name;
231
+ }
232
+
233
+ /**
234
+ * @return array
235
+ */
236
+ public function expose()
237
+ {
238
+ return get_object_vars($this);
239
+ }
240
+ }
app/code/community/Dotdigitalgroup/Email/Model/Customer/Review/Rating.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Customer_Review_Rating
4
+ {
5
+ /**
6
+ * @var int
7
+ */
8
+ public $rating_score;
9
+
10
+ /**
11
+ * constructor
12
+ *
13
+ * @param $rating
14
+ */
15
+ public function __construct($rating)
16
+ {
17
+ $this->setRatingScore($rating->getValue());
18
+ }
19
+
20
+ /**
21
+ * @param $score
22
+ *
23
+ * @return $this
24
+ */
25
+ public function setRatingScore($score)
26
+ {
27
+ $this->rating_score = (int)$score;
28
+ return $this;
29
+ }
30
+
31
+ /**
32
+ * @return int
33
+ */
34
+ public function getRatingScore()
35
+ {
36
+ return $this->rating_score;
37
+ }
38
+
39
+ /**
40
+ * @return array
41
+ */
42
+ public function expose()
43
+ {
44
+ return get_object_vars($this);
45
+ }
46
+ }
app/code/community/Dotdigitalgroup/Email/Model/Customer/Wishlist.php ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * @var string
31
+ */
32
+ public $updated_at;
33
+ /**
34
+ * constructor.
35
+ *
36
+ * @param Mage_Customer_Model_Customer $customer
37
+ */
38
+ public function __construct(Mage_Customer_Model_Customer $customer)
39
+ {
40
+
41
+ $this->setCustomerId($customer->getId());
42
+ $this->email = $customer->getEmail();
43
+ }
44
+
45
+ /**
46
+ * @param mixed $customer_id
47
+ */
48
+ public function setCustomerId($customer_id)
49
+ {
50
+ $this->customer_id = (int) $customer_id;
51
+ }
52
+
53
+ /**
54
+ * @return mixed
55
+ */
56
+ public function getCustomerId()
57
+ {
58
+ return (int) $this->customer_id;
59
+ }
60
+
61
+ /**
62
+ * @param $id
63
+ * @return $this
64
+ */
65
+ public function setId($id)
66
+ {
67
+ $this->id = (int) $id;
68
+ return $this;
69
+ }
70
+
71
+ /**
72
+ * @return mixed
73
+ */
74
+ public function getId()
75
+ {
76
+ return (int) $this->id;
77
+ }
78
+
79
+ /**
80
+ * set wishlist item.
81
+ *
82
+ * @param $item
83
+ */
84
+ public function setItem($item)
85
+ {
86
+ $this->items[] = $item->expose();
87
+
88
+ $this->total_wishlist_value += $item->getTotalValueOfProduct();
89
+ }
90
+
91
+ /**
92
+ * @return array
93
+ */
94
+ public function expose()
95
+ {
96
+ return get_object_vars($this);
97
+ }
98
+
99
+ /**
100
+ * set wishlist date.
101
+ *
102
+ * @param $date
103
+ * @return $this;
104
+ */
105
+ public function setUpdatedAt($date)
106
+ {
107
+ $date = new Zend_Date($date, Zend_Date::ISO_8601);
108
+
109
+ $this->updated_at = $date->toString(Zend_Date::ISO_8601);;
110
+ return $this;
111
+ }
112
+
113
+ /**
114
+ * @return string
115
+ */
116
+ public function getUpdatedAt()
117
+ {
118
+ return $this->updated_at;
119
+ }
120
+ }
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/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('ddg')->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,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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('ddg');
17
+ $subscriber = $observer->getEvent()->getSubscriber();
18
+ $email = $subscriber->getEmail();
19
+ $storeId = $subscriber->getStoreId();
20
+ $subscriberStatus = $subscriber->getSubscriberStatus();
21
+ $websiteId = Mage::app()->getStore($subscriber->getStoreId())->getWebsiteId();
22
+
23
+ //check if enabled
24
+ if ( ! Mage::helper('ddg')->isEnabled($websiteId))
25
+ return $this;
26
+ try{
27
+ // fix for a multiple hit of the observer
28
+ $emailReg = Mage::registry($email . '_subscriber_save');
29
+ if ($emailReg){
30
+ return $this;
31
+ }
32
+ Mage::register($email . '_subscriber_save', $email);
33
+
34
+ $contactEmail = Mage::getModel('ddg_automation/contact')->loadByCustomerEmail($email, $websiteId);
35
+
36
+ // only for subsribers
37
+ if ($subscriberStatus == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED) {
38
+ $client = Mage::helper('ddg')->getWebsiteApiClient($websiteId);
39
+ //check for website client
40
+ if ($client) {
41
+ //set contact as subscribed
42
+ $contactEmail->setSubscriberStatus( $subscriberStatus )
43
+ ->setIsSubscriber('1');
44
+ $apiContact = $client->postContacts( $email );
45
+
46
+ //resubscribe suppressed contacts
47
+ if (isset($apiContact->message) && $apiContact->message == Dotdigitalgroup_Email_Model_Apiconnector_Client::API_ERROR_CONTACT_SUPPRESSED) {
48
+ $client->postContactsResubscribe( $apiContact );
49
+ }
50
+ }
51
+ // reset the subscriber as suppressed
52
+ $contactEmail->setSuppressed(null);
53
+
54
+ //not subscribed
55
+ } else {
56
+ //skip if contact is suppressed
57
+ if ($contactEmail->getSuppressed())
58
+ return $this;
59
+ //update contact id for the subscriber
60
+ $client = Mage::helper('ddg')->getWebsiteApiClient($websiteId);
61
+ //check for website client
62
+ if ($client) {
63
+ $contactId = $contactEmail->getContactId();
64
+ //get the contact id
65
+ if ( !$contactId ) {
66
+ //if contact id is not set get the contact_id
67
+ $result = $client->postContacts( $email );
68
+ if ( isset( $result->id ) ) {
69
+ $contactId = $result->id;
70
+ } else {
71
+ //no contact id skip
72
+ $contactEmail->setSuppressed( '1' )
73
+ ->save();
74
+ return $this;
75
+ }
76
+ }
77
+ //remove contact from address book
78
+ $client->deleteAddressBookContact( $helper->getSubscriberAddressBook( $websiteId ), $contactId );
79
+ }
80
+ $contactEmail->setIsSubscriber(null)
81
+ ->setSubscriberStatus(Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED);
82
+ }
83
+ //add subscriber to automation
84
+ $this->_addSubscriberToAutomation($email, $subscriber, $websiteId);
85
+
86
+ //update the contact
87
+ $contactEmail->setStoreId($storeId);
88
+ if (isset($contactId))
89
+ $contactEmail->setContactId($contactId);
90
+ //update contact
91
+ $contactEmail->save();
92
+
93
+ }catch(Exception $e){
94
+ Mage::logException($e);
95
+ Mage::helper('ddg')->getRaygunClient()->SendException($e, array(Mage::getBaseUrl('web')));
96
+ }
97
+ return $this;
98
+ }
99
+
100
+ private function _addSubscriberToAutomation($email, $subscriber, $websiteId){
101
+
102
+ $storeId = $subscriber->getStoreId();
103
+ $store = Mage::app()->getStore($storeId);
104
+ $programId = Mage::helper( 'ddg' )->getAutomationIdByType( 'XML_PATH_CONNECTOR_AUTOMATION_STUDIO_SUBSCRIBER' );
105
+ //not mapped ignore
106
+ if (! $programId)
107
+ return;
108
+ try {
109
+ //save subscriber to the queue
110
+ $automation = Mage::getModel( 'ddg_automation/automation' );
111
+ $automation->setEmail( $email )
112
+ ->setAutomationType( Dotdigitalgroup_Email_Model_Automation::AUTOMATION_TYPE_NEW_SUBSCRIBER )
113
+ ->setEnrolmentStatus(Dotdigitalgroup_Email_Model_Automation::AUTOMATION_STATUS_PENDING)
114
+ ->setTypeId( $subscriber->getId() )
115
+ ->setWebsiteId( $websiteId )
116
+ ->setStoreName( $store->getName() )
117
+ ->setProgramId( $programId );
118
+ $automation->save();
119
+ }catch(Exception $e){
120
+ Mage::logException($e);
121
+ }
122
+ }
123
+
124
+ }
app/code/community/Dotdigitalgroup/Email/Model/Newsletter/Sub.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Newsletter_Sub extends Mage_Newsletter_Model_Subscriber
4
+ {
5
+ public function sendConfirmationSuccessEmail()
6
+ {
7
+ if (Mage::helper('ddg')->isNewsletterSuccessDisabled($this->getStoreId()))
8
+ return $this;
9
+ else
10
+ parent::sendConfirmationSuccessEmail();
11
+ }
12
+ }
app/code/community/Dotdigitalgroup/Email/Model/Newsletter/Subscriber.php ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 = 0;
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('ddg');
27
+
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
+ //enabled and mapped
36
+ if ( $enabled && $addressBook ) {
37
+
38
+ //ready to start sync
39
+ if (!$this->_countSubscriber)
40
+ $helper->log('---------------------- Start subscriber sync -------------------');
41
+
42
+ $numUpdated = $this->exportSubscribersPerWebsite($website);
43
+ // show message for any number of customers
44
+ if ($numUpdated)
45
+ $response['message'] .= '</br>' . $website->getName() . ', updated subscribers = ' . $numUpdated;
46
+
47
+ }
48
+ }
49
+
50
+ //global number of subscribers to set the message
51
+ if ($this->_countSubscriber) {
52
+ //reponse message
53
+ $message = 'Total time for sync : ' . gmdate("H:i:s", microtime(true) - $this->_start);
54
+
55
+ //put the message in front
56
+ $message .= $response['message'];
57
+ $result['message'] = $message;
58
+ }
59
+
60
+ return $response;
61
+ }
62
+
63
+ /**
64
+ * Export subscriber per website.
65
+ * @param Mage_Core_Model_Website $website
66
+ *
67
+ * @return int
68
+ */
69
+ public function exportSubscribersPerWebsite(Mage_Core_Model_Website $website)
70
+ {
71
+ $updated = 0;
72
+ $fileHelper = Mage::helper('ddg/file');
73
+ $limit = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_LIMIT);
74
+ $subscribers = Mage::getModel('ddg_automation/contact')->getSubscribersToImport($website, $limit);
75
+ if (count($subscribers)) {
76
+ $client = Mage::helper('ddg')->getWebsiteApiClient($website);
77
+ $subscribersFilename = strtolower($website->getCode() . '_subscribers_' . date('d_m_Y_Hi') . '.csv');
78
+ //get mapped storename
79
+ $subscriberStorename = Mage::helper('ddg')->getMappedStoreName($website);
80
+ //file headers
81
+ $fileHelper->outputCSV($fileHelper->getFilePath($subscribersFilename), array('Email', 'emailType', $subscriberStorename));
82
+ foreach ($subscribers as $subscriber) {
83
+ try{
84
+ $email = $subscriber->getEmail();
85
+ $subscriber->setSubscriberImported(1)->save();
86
+ $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
87
+ $storeName = Mage::app()->getStore($subscriber->getStoreId())->getName();
88
+ // save data for subscribers
89
+ $fileHelper->outputCSV($fileHelper->getFilePath($subscribersFilename), array($email, 'Html', $storeName));
90
+ $updated++;
91
+ }catch (Exception $e){
92
+ Mage::logException($e);
93
+ }
94
+ }
95
+ Mage::helper('ddg')->log('Subscriber filename: ' . $subscribersFilename);
96
+ //Add to subscriber address book
97
+ $client->postAddressBookContactsImport($subscribersFilename, $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SUBSCRIBERS_ADDRESS_BOOK_ID));
98
+ $fileHelper->archiveCSV($subscribersFilename);
99
+ }
100
+ //add updated number for the website
101
+ $this->_countSubscriber += $updated;
102
+ return $updated;
103
+ }
104
+
105
+ /**
106
+ * Unsubscribe suppressed contacts.
107
+ * @param bool $force set 10years old
108
+ * @return mixed
109
+ */
110
+ public function unsubscribe($force = false)
111
+ {
112
+ $limit = 5;
113
+ $max_to_select = 1000;
114
+ $result['customers'] = 0;
115
+ $helper = Mage::helper('ddg');
116
+ $date = Mage::app()->getLocale()->date()->subHour(1);
117
+ // force sync all customers
118
+ if($force)
119
+ $date = $date->subYear(10);
120
+ // datetime format string
121
+ $dateString = $date->toString(Zend_Date::W3C);
122
+ /**
123
+ * 1. Sync all suppressed for each store
124
+ */
125
+ foreach (Mage::app()->getWebsites(true) as $website) {
126
+
127
+ $enabled = (bool)$website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED);
128
+
129
+ //no enabled and valid credentials
130
+ if (! $enabled)
131
+ continue;
132
+
133
+ $skip = $i = 0;
134
+ $contacts = array();
135
+ $client = Mage::helper('ddg')->getWebsiteApiClient($website);
136
+
137
+
138
+ //there is a maximum of request we need to loop to get more suppressed contacts
139
+ for ($i=0; $i<= $limit;$i++) {
140
+ $apiContacts = $client->getContactsSuppressedSinceDate($dateString, $max_to_select , $skip);
141
+
142
+ // skip no more contacts or the api request failed
143
+ if(empty($apiContacts) || isset($apiContacts->message))
144
+ break;
145
+
146
+ $contacts = array_merge($contacts, $apiContacts);
147
+ $skip += 1000;
148
+ }
149
+
150
+ $subscriberBookId = $helper->getSubscriberAddressBook($website);
151
+
152
+ // suppressed contacts to unsubscibe
153
+ foreach ($contacts as $apiContact) {
154
+ if (isset($apiContact->suppressedContact)) {
155
+ $suppressedContact = $apiContact->suppressedContact;
156
+ $email = $suppressedContact->email;
157
+ $contactId = $suppressedContact->id;
158
+ try{
159
+ /**
160
+ * 2. Remove subscriber from the address book.
161
+ */
162
+ $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
163
+ if ($subscriber->getStatus() == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED) {
164
+ $subscriber->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED);
165
+ $subscriber->save();
166
+ // remove from subscriber address-book
167
+ $client->deleteAddressBookContact($subscriberBookId, $contactId);
168
+ }
169
+ //mark contact as suppressed and unsubscribe
170
+ $contactCollection = Mage::getModel('ddg_automation/contact')->getCollection()
171
+ ->addFieldToFilter('email', $email)
172
+ ->addFieldToFilter('website_id', $website->getId());
173
+ //unsubscribe from the email contact table.
174
+ foreach ($contactCollection as $contact) {
175
+ $contact->setIsSubscriber(null)
176
+ ->setSuppressed('1')->save();
177
+ }
178
+ }catch (Exception $e){
179
+ Mage::logException($e);
180
+ }
181
+ }
182
+ }
183
+ }
184
+ return $result;
185
+ }
186
+ }
app/code/community/Dotdigitalgroup/Email/Model/Order.php ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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('ddg_automation/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
+ *
87
+ * @return Dotdigitalgroup_Email_Model_Resource_Order_Collection
88
+ */
89
+ public function getOrdersToImport($storeIds, $limit, $orderStatuses)
90
+ {
91
+ $collection = $this->getCollection()
92
+ ->addFieldToFilter('email_imported', array('null' => true))
93
+ ->addFieldToFilter('store_id', array('in' => $storeIds))
94
+ ->addFieldToFilter('order_status', array('in' => $orderStatuses));
95
+
96
+ $collection->getSelect()->limit($limit);
97
+ return $collection->load();
98
+ }
99
+
100
+ /**
101
+ * Get all sent orders older then certain days.
102
+ *
103
+ * @param $storeIds
104
+ * @param $limit
105
+ *
106
+ * @return Dotdigitalgroup_Email_Model_Resource_Order_Collection
107
+ */
108
+ public function getAllSentOrders($storeIds, $limit)
109
+ {
110
+ $collection = $this->getCollection()
111
+ ->addFieldToFilter('email_imported', 1)
112
+ ->addFieldToFilter('store_id', array('in' => $storeIds));
113
+
114
+ $collection->getSelect()->limit($limit);
115
+ return $collection->load();
116
+ }
117
+
118
+ /**
119
+ * Reset the email order for reimport.
120
+ *
121
+ * @return int
122
+ */
123
+ public function resetOrders()
124
+ {
125
+ /** @var $coreResource Mage_Core_Model_Resource */
126
+ $coreResource = Mage::getSingleton('core/resource');
127
+
128
+ /** @var $conn Varien_Db_Adapter_Pdo_Mysql */
129
+ $conn = $coreResource->getConnection('core_write');
130
+ try{
131
+ $num = $conn->update($coreResource->getTableName('ddg_automation/order'),
132
+ array('email_imported' => new Zend_Db_Expr('null')),
133
+ $conn->quoteInto('email_imported is ?', new Zend_Db_Expr('not null'))
134
+ );
135
+ }catch (Exception $e){
136
+ Mage::logException($e);
137
+ }
138
+
139
+ return $num;
140
+ }
141
+
142
+ }
app/code/community/Dotdigitalgroup/Email/Model/Quote.php ADDED
@@ -0,0 +1,246 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Quote extends Mage_Core_Model_Abstract
4
+ {
5
+ private $_start;
6
+ private $_quotes;
7
+ private $_count = 0;
8
+
9
+ /**
10
+ * constructor
11
+ */
12
+ public function _construct()
13
+ {
14
+ parent::_construct();
15
+ $this->_init('ddg_automation/quote');
16
+ }
17
+
18
+ /**
19
+ * @return $this|Mage_Core_Model_Abstract
20
+ */
21
+ protected function _beforeSave()
22
+ {
23
+ parent::_beforeSave();
24
+ $now = Mage::getSingleton('core/date')->gmtDate();
25
+ if ($this->isObjectNew()) {
26
+ $this->setCreatedAt($now);
27
+ }else {
28
+ $this->setUpdatedAt($now);
29
+ }
30
+ return $this;
31
+ }
32
+
33
+ /**
34
+ * sync
35
+ *
36
+ * @return array
37
+ */
38
+ public function sync()
39
+ {
40
+ $response = array('success' => true, 'message' => '');
41
+ $helper = Mage::helper('ddg');
42
+ //resource allocation
43
+ $helper->allowResourceFullExecution();
44
+
45
+ foreach (Mage::app()->getWebsites(true) as $website) {
46
+ $enabled = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_QUOTE_ENABLED, $website);
47
+ if ($enabled) {
48
+ //using bulk api
49
+ $helper->log('---------- Start quote bulk sync ----------');
50
+ $this->_start = microtime(true);
51
+ $this->_exportQuoteForWebsite($website);
52
+ //send quote as transactional data
53
+ if (isset($this->_quotes[$website->getId()])) {
54
+ $client = Mage::helper('ddg')->getWebsiteApiClient($website);
55
+ $websiteQuotes = $this->_quotes[$website->getId()];
56
+ //import quote in bulk
57
+ $client->postContactsTransactionalDataImport($websiteQuotes, 'Quote');
58
+ }
59
+ $message = 'Total time for quote bulk sync : ' . gmdate("H:i:s", microtime(true) - $this->_start);
60
+ $helper->log($message);
61
+
62
+ //remove quotes
63
+ $this->_deleteQuoteForWebsite($website);
64
+
65
+ //update quotes
66
+ $this->_exportQuoteForWebsiteInSingle($website);
67
+ }
68
+ }
69
+ $response['message'] = "quote updated: ". $this->_count;
70
+ return $response;
71
+ }
72
+
73
+ /**
74
+ * export quotes to website
75
+ *
76
+ * @param Mage_Core_Model_Website $website
77
+ */
78
+ private function _exportQuoteForWebsite(Mage_Core_Model_Website $website)
79
+ {
80
+ try{
81
+ //reset quotes
82
+ $this->_quotes = array();
83
+ $limit = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_TRANSACTIONAL_DATA_SYNC_LIMIT, $website);
84
+ $collection = $this->_getQuoteToImport($website, $limit);
85
+ foreach($collection as $emailQuote){
86
+ $store = Mage::app()->getStore($emailQuote->getStoreId());
87
+ $quote = Mage::getModel('sales/quote')->setStore($store)->load($emailQuote->getQuoteId());
88
+ if($quote->getId())
89
+ {
90
+ $connectorQuote = Mage::getModel('ddg_automation/connector_quote', $quote);
91
+ $this->_quotes[$website->getId()][] = $connectorQuote;
92
+ }
93
+ $emailQuote->setImported(Dotdigitalgroup_Email_Model_Contact::EMAIL_CONTACT_IMPORTED)
94
+ ->setModified(null)
95
+ ->save();
96
+ $this->_count++;
97
+ }
98
+ }catch(Exception $e){
99
+ Mage::logException($e);
100
+ }
101
+ }
102
+
103
+ /**
104
+ * get quotes to import
105
+ *
106
+ * @param Mage_Core_Model_Website $website
107
+ * @param int $limit
108
+ * @param $modified
109
+ *
110
+ * @return mixed
111
+ */
112
+ private function _getQuoteToImport(Mage_Core_Model_Website $website, $limit = 100, $modified = false)
113
+ {
114
+ $collection = $this->getCollection()
115
+ ->addFieldToFilter('store_id', array('in' => $website->getStoreIds()))
116
+ ->addFieldToFilter('customer_id', array('notnull' => true));
117
+
118
+ if ($modified) {
119
+ $collection->addFieldToFilter('modified', 1)
120
+ ->addFieldToFilter('imported', 1);
121
+ } else {
122
+ $collection->addFieldToFilter('imported', array('null' => true));
123
+ }
124
+ $collection->getSelect()->limit($limit);
125
+ return $collection;
126
+ }
127
+
128
+ /**
129
+ * remove quotes for website
130
+ *
131
+ * @param Mage_Core_Model_Website $website
132
+ */
133
+ private function _deleteQuoteForWebsite(Mage_Core_Model_Website $website)
134
+ {
135
+ try{
136
+ $limit = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_TRANSACTIONAL_DATA_SYNC_LIMIT, $website);
137
+ $client = Mage::helper('ddg')->getWebsiteApiClient($website);
138
+ $collection = $this->_getQuoteToDelete($website, $limit);
139
+ foreach($collection as $emailQuote){
140
+ $result = $client->deleteContactsTransactionalData($emailQuote->getQuoteId(), 'Quote');
141
+ if (!isset($result->message)){
142
+ $emailQuote->delete();
143
+ $this->_count++;
144
+ }
145
+ }
146
+ }catch(Exception $e){
147
+ Mage::logException($e);
148
+ }
149
+ }
150
+
151
+ /**
152
+ * update quotes for website in single
153
+ *
154
+ * @param Mage_Core_Model_Website $website
155
+ */
156
+ private function _exportQuoteForWebsiteInSingle(Mage_Core_Model_Website $website)
157
+ {
158
+ try {
159
+ $limit = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_TRANSACTIONAL_DATA_SYNC_LIMIT, $website);
160
+ $client = Mage::helper('ddg')->getWebsiteApiClient($website);
161
+ $collection = $this->_getQuoteToImport($website, $limit, true);
162
+ foreach ($collection as $emailQuote) {
163
+ $store = Mage::app()->getStore($emailQuote->getStoreId());
164
+ $quote = Mage::getModel('sales/quote')->setStore($store)->load($emailQuote->getQuoteId());
165
+ if ($quote->getId()) {
166
+ $connectorQuote = Mage::getModel('ddg_automation/connector_quote', $quote);
167
+ //single api
168
+ $result = $client->postContactsTransactionalData($connectorQuote, 'Quote');
169
+ //if no error
170
+ if (!isset($result->message)) {
171
+ $message = 'Quote updated : ' . $emailQuote->getQuoteId();
172
+ Mage::helper('ddg')->log($message);
173
+ $emailQuote->setModified(null)->save();
174
+ $this->_count++;
175
+ }
176
+
177
+ }
178
+ }
179
+ } catch (Exception $e) {
180
+ Mage::logException($e);
181
+ }
182
+ }
183
+
184
+ /**
185
+ * get collection that will be used to remove quotes from connector
186
+ *
187
+ * @param Mage_Core_Model_Website $website
188
+ * @param int $limit
189
+ * @return mixed
190
+ */
191
+ private function _getQuoteToDelete(Mage_Core_Model_Website $website, $limit = 100)
192
+ {
193
+ $collection = $this->getCollection()
194
+ ->addFieldToFilter('imported', 1)
195
+ ->addFieldToFilter('converted_to_order', 1)
196
+ ->addFieldToFilter('store_id', array('in' => $website->getStoreIds()));
197
+ $collection->getSelect()->limit($limit);
198
+ return $collection;
199
+ }
200
+
201
+ /**
202
+ * load quote from connector table
203
+ *
204
+ * @param $quoteId
205
+ * @return bool
206
+ */
207
+ public function loadQuote($quoteId)
208
+ {
209
+ $collection = $this->getCollection();
210
+ $collection->addFieldToFilter('quote_id', $quoteId)
211
+ ->setPageSize(1);
212
+
213
+ if ($collection->count()) {
214
+ return $collection->getFirstItem();
215
+ }
216
+ return false;
217
+ }
218
+
219
+ /**
220
+ * Reset the email quote for reimport.
221
+ *
222
+ * @return int
223
+ */
224
+ public function resetQuotes()
225
+ {
226
+ /** @var $coreResource Mage_Core_Model_Resource */
227
+ $coreResource = Mage::getSingleton('core/resource');
228
+
229
+ /** @var $conn Varien_Db_Adapter_Pdo_Mysql */
230
+ $conn = $coreResource->getConnection('core_write');
231
+ try{
232
+ $num = $conn->update($coreResource->getTableName('ddg_automation/quote'),
233
+ array('imported' => new Zend_Db_Expr('null')),
234
+ array(
235
+ $conn->quoteInto('imported is ?', new Zend_Db_Expr('not null')),
236
+ $conn->quoteInto('converted_to_order is ?', new Zend_Db_Expr('null')),
237
+ $conn->quoteInto('modified is ?', new Zend_Db_Expr('null'))
238
+ )
239
+ );
240
+ }catch (Exception $e){
241
+ Mage::logException($e);
242
+ }
243
+
244
+ return $num;
245
+ }
246
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Automation.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Automation extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+
6
+ /**
7
+ * constructor.
8
+ */
9
+ protected function _construct()
10
+ {
11
+ $this->_init('ddg_automation/automation', 'id');
12
+
13
+ }
14
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Automation/Collection.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Automation_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('ddg_automation/automation');
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/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('ddg_automation/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('ddg_automation/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('ddg_automation/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('ddg_automation/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('ddg_automation/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('ddg_automation/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('ddg_automation/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('ddg_automation/order');
13
+ }
14
+
15
+
16
+
17
+
18
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Quote.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Quote extends Mage_Core_Model_Resource_Db_Abstract
4
+ {
5
+ /**
6
+ * constructor.
7
+ */
8
+ protected function _construct()
9
+ {
10
+ $this->_init('ddg_automation/quote', 'id');
11
+ }
12
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Quote/Collection.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Quote_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('ddg_automation/quote');
13
+ }
14
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Review.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Review extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+ /**
6
+ * constructor.
7
+ */
8
+ protected function _construct()
9
+ {
10
+ $this->_init('ddg_automation/review', 'id');
11
+
12
+ }
13
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Review/Collection.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Review_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('ddg_automation/review');
12
+ }
13
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Segment.php ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Model_Resource_Segment extends Enterprise_CustomerSegment_Model_Resource_Segment
3
+ {
4
+
5
+ public function saveCustomersFromSelect($segment, $websiteId, $select)
6
+ {
7
+ $customerTable = $this->getTable('enterprise_customersegment/customer');
8
+ $adapter = $this->_getWriteAdapter();
9
+ $segmentId = $segment->getId();
10
+ $now = $this->formatDate(time());
11
+
12
+ $data = array();
13
+ $count= 0;
14
+ $stmt = $adapter->query($select);
15
+ $adapter->beginTransaction();
16
+ try {
17
+ while ($row = $stmt->fetch()) {
18
+ $data[] = array(
19
+ 'segment_id' => $segmentId,
20
+ 'customer_id' => $row['entity_id'],
21
+ 'website_id' => $row['website_id'],
22
+ 'added_date' => $now,
23
+ 'updated_date' => $now,
24
+ );
25
+
26
+ /**
27
+ * trigger the contact segment ids to update
28
+ */
29
+ $this->updateContactSegmentIds($row['entity_id'], $segmentId, $websiteId);
30
+ $count++;
31
+ if (($count % 1000) == 0) {
32
+ $adapter->insertMultiple($customerTable, $data);
33
+ $data = array();
34
+ }
35
+ }
36
+ if (!empty($data)) {
37
+ $adapter->insertMultiple($customerTable, $data);
38
+ }
39
+ } catch (Exception $e) {
40
+ $adapter->rollBack();
41
+ throw $e;
42
+ }
43
+
44
+ $adapter->commit();
45
+
46
+ return $this;
47
+ }
48
+
49
+ //in case for old version that is still using this method
50
+ public function saveSegmentCustomersFromSelect($segment, $select)
51
+ {
52
+ $table = $this->getTable('enterprise_customersegment/customer');
53
+ $adapter = $this->_getWriteAdapter();
54
+ $segmentId = $segment->getId();
55
+ $now = $this->formatDate(time());
56
+
57
+ $adapter->delete($table, $adapter->quoteInto('segment_id=?', $segmentId));
58
+
59
+ $data = array();
60
+ $count= 0;
61
+ $stmt = $adapter->query($select);
62
+ while ($row = $stmt->fetch()) {
63
+
64
+ $data[] = array(
65
+ 'segment_id' => $segmentId,
66
+ 'customer_id' => $row['entity_id'],
67
+ 'added_date' => $now,
68
+ 'updated_date' => $now,
69
+ );
70
+ /**
71
+ * trigger the contact segment ids to update
72
+ */
73
+ $this->updateContactSegmentIds($row['entity_id'], $segmentId);
74
+ $count++;
75
+ if ($count>1000) {
76
+ $count = 0;
77
+ $adapter->insertMultiple($table, $data);
78
+ $data = array();
79
+ }
80
+ }
81
+ if ($count>0) {
82
+ $adapter->insertMultiple($table, $data);
83
+ }
84
+ return $this;
85
+ }
86
+
87
+ protected function updateContactSegmentIds($customerId, $segmentId, $websiteId = 0){
88
+ $collection = Mage::getModel('ddg_automation/contact')->getCollection()
89
+ ->addFieldToFilter('customer_id', $customerId);
90
+ if ($websiteId)
91
+ $collection->addFieldToFilter('website_id', $websiteId);
92
+ $contact = $collection->getFirstItem();
93
+ $existing = $contact->getSegmentIds();
94
+
95
+ $existing = explode(',', $existing);
96
+ //no segments found set current segment
97
+ if ( ! in_array( $segmentId, $existing ) ) {
98
+
99
+ //for the existing
100
+ if ( count( $existing ) == 1 ) {
101
+ $existing = $segmentId;
102
+ } else {
103
+ $existing[] = $segmentId;
104
+ $existing = implode( ',', $existing );
105
+ }
106
+ }
107
+
108
+ //update new segmets and mark for import
109
+ $contact->setSegmentIds($existing)
110
+ ->setEmailImported()
111
+ ->save();
112
+ }
113
+
114
+
115
+ public function deleteSegmentCustomers($segment)
116
+ {
117
+ $this->_getWriteAdapter()->delete(
118
+ $this->getTable('enterprise_customersegment/customer'),
119
+ array('segment_id=?' => $segment->getId())
120
+ );
121
+
122
+ /**
123
+ * Trigger the delete for contact segment ids.
124
+ */
125
+ $this->deleteSegmentContacts($segment->getId());
126
+ return $this;
127
+ }
128
+
129
+ protected function deleteSegmentContacts($segment){
130
+
131
+ $contacts = Mage::getModel('ddg_automation/contact')->getCollection()
132
+ ->addFieldToFilter('segment_ids', array('finset'=> array($segment)));
133
+ foreach ( $contacts as $contact ) {
134
+ //segments found for contact
135
+ $segments = explode(',', $contact->getSegmentIds());
136
+ foreach ( $segments as $key => $one ) {
137
+ if ($segment == $one)
138
+ unset($segments[$key]);
139
+ }
140
+
141
+ //save the comma separated values
142
+ if (count($segments) == 1)
143
+ $segments = $segments[0];
144
+ else
145
+ $segments = implode(',' , $segments);
146
+
147
+ //save updated segments for contact
148
+ $contact->setSegmentIds($segments)
149
+ ->setEmailImported()
150
+ ->save();
151
+ }
152
+ }
153
+
154
+ }
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/Resource/Wishlist.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Wishlist extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+ /**
6
+ * constructor.
7
+ */
8
+ protected function _construct()
9
+ {
10
+ $this->_init('ddg_automation/wishlist', 'id');
11
+
12
+ }
13
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Wishlist/Collection.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Wishlist_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('ddg_automation/wishlist');
12
+ }
13
+ }
app/code/community/Dotdigitalgroup/Email/Model/Review.php ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Review extends Mage_Core_Model_Abstract
4
+ {
5
+ private $_start;
6
+ private $_countReviews;
7
+ private $_reviews;
8
+
9
+ const EMAIL_REVIEW_IMPORTED = 1;
10
+
11
+ /**
12
+ * constructor
13
+ */
14
+ public function _construct()
15
+ {
16
+ parent::_construct();
17
+ $this->_init('ddg_automation/review');
18
+ }
19
+
20
+ /**
21
+ * @return $this|Mage_Core_Model_Abstract
22
+ */
23
+ protected function _beforeSave()
24
+ {
25
+ parent::_beforeSave();
26
+ $now = Mage::getSingleton('core/date')->gmtDate();
27
+ if ($this->isObjectNew()) {
28
+ $this->setCreatedAt($now);
29
+ }else {
30
+ $this->setUpdatedAt($now);
31
+ }
32
+ return $this;
33
+ }
34
+
35
+ public function sync()
36
+ {
37
+ $response = array('success' => true, 'message' => '');
38
+ $helper = Mage::helper('ddg');
39
+ $this->_countReviews = 0;
40
+ $this->_reviews = array();
41
+ $this->_start = microtime(true);
42
+ //resource allocation
43
+ $helper->allowResourceFullExecution();
44
+ foreach (Mage::app()->getWebsites(true) as $website) {
45
+
46
+ $enabled = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED, $website);
47
+ $sync = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_REVIEW_ENABLED, $website);
48
+
49
+ if ($enabled && $sync) {
50
+ //start the sync
51
+ if (! $this->_countReviews)
52
+ $helper->log('---------- Start reviews sync ----------');
53
+ $this->_exportReviewsForWebsite($website);
54
+ }
55
+
56
+ if (isset($this->_reviews[$website->getId()])) {
57
+ $reviews = $this->_reviews[$website->getId()];
58
+ //send reviews as transactional data
59
+ $client = Mage::helper('ddg')->getWebsiteApiClient($website);
60
+ $client->postContactsTransactionalDataImport($reviews, 'Reviews');
61
+ $this->_countReviews += count($reviews);
62
+ }
63
+ }
64
+
65
+ if ($this->_countReviews) {
66
+ $message = 'Total time for sync : ' . gmdate( "H:i:s", microtime( true ) - $this->_start ) . ', Total synced = ' . $this->_countReviews;
67
+ $helper->log( $message );
68
+ $response['message'] = $message;
69
+ }
70
+ return $response;
71
+ }
72
+
73
+ private function _exportReviewsForWebsite(Mage_Core_Model_Website $website)
74
+ {
75
+ $limit = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_TRANSACTIONAL_DATA_SYNC_LIMIT, $website);
76
+ $reviews = $this->_getReviewsToExport($website, $limit);
77
+
78
+ if($reviews->getSize()){
79
+ foreach($reviews as $review){
80
+ try {
81
+ $mageReview = Mage::getModel('review/review')->load($review->getReviewId());
82
+
83
+ $product = Mage::getModel('catalog/product')
84
+ ->setStoreId($mageReview->getStoreId())
85
+ ->load($mageReview->getEntityPkValue());
86
+
87
+ $customer = Mage::getModel('customer/customer')->load($mageReview->getCustomerId());
88
+
89
+ $connectorReview = Mage::getModel('ddg_automation/customer_review', $customer)
90
+ ->setReviewData($mageReview)
91
+ ->setProduct($product);
92
+
93
+ $votesCollection = Mage::getModel('rating/rating_option_vote')
94
+ ->getResourceCollection()
95
+ ->setReviewFilter($mageReview->getReviewId());
96
+ $votesCollection->getSelect()->join(
97
+ array('rating'=> 'rating'),
98
+ 'rating.rating_id = main_table.rating_id',
99
+ array('rating_code' => 'rating.rating_code')
100
+ );
101
+
102
+ foreach($votesCollection as $ratingItem){
103
+ $rating = Mage::getModel('ddg_automation/customer_review_rating', $ratingItem);
104
+ $connectorReview->createRating($ratingItem->getRatingCode(), $rating);
105
+ }
106
+ $this->_reviews[$website->getId()][] = $connectorReview;
107
+ $review->setReviewImported(self::EMAIL_REVIEW_IMPORTED)->save();
108
+ }catch(Exception $e){
109
+ Mage::logException($e);
110
+ }
111
+ }
112
+ }
113
+ }
114
+
115
+ private function _getReviewsToExport(Mage_Core_Model_Website $website, $limit = 100)
116
+ {
117
+ return $this->getCollection()
118
+ ->addFieldToFilter('review_imported', array('null' => 'true'))
119
+ ->addFieldToFilter('store_id', array('in' => $website->getStoreIds()))
120
+ ->setPageSize($limit)
121
+ ->load();
122
+ }
123
+
124
+ /**
125
+ * Reset the email reviews for reimport.
126
+ *
127
+ * @return int
128
+ */
129
+ public function reset()
130
+ {
131
+ /** @var $coreResource Mage_Core_Model_Resource */
132
+ $coreResource = Mage::getSingleton('core/resource');
133
+
134
+ /** @var $conn Varien_Db_Adapter_Pdo_Mysql */
135
+ $conn = $coreResource->getConnection('core_write');
136
+ try{
137
+ $num = $conn->update($coreResource->getTableName('ddg_automation/review'),
138
+ array('review_imported' => new Zend_Db_Expr('null')),
139
+ $conn->quoteInto('review_imported is ?', new Zend_Db_Expr('not null'))
140
+ );
141
+ }catch (Exception $e){
142
+ Mage::logException($e);
143
+ }
144
+
145
+ return $num;
146
+ }
147
+ }
app/code/community/Dotdigitalgroup/Email/Model/Sales/Observer.php ADDED
@@ -0,0 +1,283 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ if (! Mage::registry('sales_order_status_before'))
17
+ Mage::register('sales_order_status_before', $reloaded->getStatus());
18
+ return $this;
19
+ }
20
+ /**
21
+ * save/reset the order as transactional data.
22
+ *
23
+ * @param Varien_Event_Observer $observer
24
+ * @return $this
25
+ */
26
+ public function handleSalesOrderSaveAfter(Varien_Event_Observer $observer)
27
+ {
28
+ try{
29
+ /** @var $order Mage_Sales_Model_Order */
30
+ $order = $observer->getEvent()->getOrder();
31
+ $status = $order->getStatus();
32
+ $storeId = $order->getStoreId();
33
+ $store = Mage::app()->getStore($storeId);
34
+ // start app emulation
35
+ $appEmulation = Mage::getSingleton('core/app_emulation');
36
+ $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);
37
+ $emailOrder = Mage::getModel('ddg_automation/order')->loadByOrderId($order->getEntityId(), $order->getQuoteId());
38
+ //reimport email order
39
+ $emailOrder->setUpdatedAt($order->getUpdatedAt())
40
+ ->setStoreId($storeId)
41
+ ->setOrderStatus($status);
42
+ if($emailOrder->getEmailImported() != Dotdigitalgroup_Email_Model_Contact::EMAIL_CONTACT_IMPORTED) {
43
+ $emailOrder->setEmailImported(null);
44
+ }
45
+
46
+ //if api is not enabled
47
+ if (!$store->getWebsite()->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED))
48
+ return $this;
49
+
50
+ // check for order status change
51
+ $statusBefore = Mage::registry('sales_order_status_before');
52
+ if ( $status!= $statusBefore) {
53
+ //If order status has changed and order is already imported then set imported to null
54
+ if($emailOrder->getEmailImported() == Dotdigitalgroup_Email_Model_Contact::EMAIL_CONTACT_IMPORTED) {
55
+ $emailOrder->setEmailImported(Dotdigitalgroup_Email_Model_Contact::EMAIL_CONTACT_NOT_IMPORTED);
56
+ }
57
+ $smsCampaign = Mage::getModel('ddg_automation/sms_campaign', $order);
58
+ $smsCampaign->setStatus($status);
59
+ $smsCampaign->sendSms();
60
+ }
61
+ // set back the current store
62
+ $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
63
+ $emailOrder->save();
64
+
65
+ //admin oder when editing the first one is canceled
66
+ Mage::unregister('sales_order_status_before');
67
+ }catch(Exception $e){
68
+ Mage::logException($e);
69
+ }
70
+ return $this;
71
+ }
72
+
73
+
74
+ /**
75
+ * Create new order event.
76
+ * @param Varien_Event_Observer $observer
77
+ *
78
+ * @return $this
79
+ * @throws Mage_Core_Exception
80
+ */
81
+ public function handleSalesOrderPlaceAfter(Varien_Event_Observer $observer)
82
+ {
83
+ /** @var $order Mage_Sales_Model_Order */
84
+ $order = $observer->getEvent()->getOrder();
85
+ $email = $order->getCustomerEmail();
86
+ $website = Mage::app()->getWebsite($order->getWebsiteId());
87
+ $storeName = Mage::app()->getStore($order->getStoreId())->getName();
88
+
89
+ //if api is not enabled
90
+ if (!$website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED))
91
+ return $this;
92
+
93
+ //automation enrolment for order
94
+ if($order->getCustomerIsGuest()){
95
+ // guest to automation mapped
96
+ $programType = 'XML_PATH_CONNECTOR_AUTOMATION_STUDIO_GUEST_ORDER';
97
+ $automationType = Dotdigitalgroup_Email_Model_Automation::AUTOMATION_TYPE_NEW_GUEST_ORDER;
98
+ }else{
99
+ // customer to automation mapped
100
+ $programType = 'XML_PATH_CONNECTOR_AUTOMATION_STUDIO_ORDER';
101
+ $automationType = Dotdigitalgroup_Email_Model_Automation::AUTOMATION_TYPE_NEW_ORDER;
102
+ }
103
+
104
+ $programId = Mage::helper( 'ddg' )->getAutomationIdByType($programType );
105
+ //the program is not mappped
106
+ if (! $programId)
107
+ return $this;
108
+ try {
109
+ $automation = Mage::getModel( 'ddg_automation/automation' );
110
+ $automation->setEmail( $email )
111
+ ->setAutomationType( $automationType )
112
+ ->setEnrolmentStatus(Dotdigitalgroup_Email_Model_Automation::AUTOMATION_STATUS_PENDING)
113
+ ->setTypeId( $order->getId() )
114
+ ->setWebsiteId($website->getId())
115
+ ->setStoreName($storeName)
116
+ ->setProgramId($programId);
117
+ $automation->save();
118
+ }catch(Exception $e) {
119
+ Mage::logException( $e );
120
+ }
121
+
122
+ return $this;
123
+ }
124
+
125
+ /**
126
+ * Sales order refund event.
127
+ *
128
+ * @param Varien_Event_Observer $observer
129
+ *
130
+ * @return $this
131
+ */
132
+ public function handleSalesOrderRefund(Varien_Event_Observer $observer)
133
+ {
134
+ $creditmemo = $observer->getEvent()->getCreditmemo();
135
+ $storeId = $creditmemo->getStoreId();
136
+ $order = $creditmemo->getOrder();
137
+ $orderId = $order->getEntityId();
138
+ $quoteId = $order->getQuoteId();
139
+
140
+ try{
141
+ /**
142
+ * Reimport transactional data.
143
+ */
144
+ $emailOrder = Mage::getModel('ddg_automation/order')->loadByOrderId($orderId, $quoteId, $storeId);
145
+ if (!$emailOrder->getId()) {
146
+ Mage::helper('ddg')->log('ERROR Creditmemmo Order not found :' . $orderId . ', quote id : ' . $quoteId . ', store id ' . $storeId);
147
+ return $this;
148
+ }
149
+ $emailOrder->setEmailImported(Dotdigitalgroup_Email_Model_Contact::EMAIL_CONTACT_NOT_IMPORTED)->save();
150
+ }catch (Exception $e){
151
+ Mage::logException($e);
152
+ }
153
+
154
+ return $this;
155
+ }
156
+
157
+ /**
158
+ * Sales cancel order event, remove transactional data.
159
+ *
160
+ * @param Varien_Event_Observer $observer
161
+ *
162
+ * @return $this
163
+ */
164
+ public function hangleSalesOrderCancel(Varien_Event_Observer $observer)
165
+ {
166
+ $order = $observer->getEvent()->getOrder();
167
+ $storeId = $order->getStoreId();
168
+ $websiteId = Mage::app()->getStore($storeId)->getWebsiteId();
169
+ $customerEmail = $order->getCustomerEmail();
170
+ $helper = Mage::helper('ddg');
171
+ if ($helper->isEnabled($websiteId)) {
172
+ $client = Mage::getModel('ddg_automation/apiconnector_client');
173
+ $client->setApiUsername($helper->getApiUsername($websiteId));
174
+ $client->setApiPassword($helper->getApiPassword($websiteId));
175
+ // delete the order transactional data
176
+ $client->deleteContactTransactionalData($customerEmail, 'Orders');
177
+ }
178
+
179
+ return $this;
180
+ }
181
+
182
+ /**
183
+ * enrol single contact to automation
184
+ *
185
+ * @param $email
186
+ * @param $websiteId
187
+ * @param $automationType
188
+ */
189
+ private function _postCustomerToAutomation( $email, $websiteId, $automationType) {
190
+ /**
191
+ * Automation Programme
192
+ */
193
+ $path = constant('Dotdigitalgroup_Email_Helper_Config::' . $automationType);
194
+ $automationCampaignId = Mage::helper('ddg')->getWebsiteConfig($path, $websiteId);
195
+ $enabled = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED, $websiteId);
196
+
197
+ //add customer to automation
198
+ if ($enabled && $automationCampaignId) {
199
+ Mage::helper( 'ddg' )->log( 'AS - ' . $automationType . ' automation Campaign id : ' . $automationCampaignId );
200
+ $client = Mage::helper( 'ddg' )->getWebsiteApiClient( $websiteId );
201
+ $apiContact = $client->postContacts($email);
202
+
203
+ // get a program by id
204
+ $program = $client->getProgramById($automationCampaignId);
205
+ /**
206
+ * id
207
+ * name
208
+ * status
209
+ * dateCreated
210
+ */
211
+ Mage::helper( 'ddg' )->log( 'AS - get ' . $automationType . ' Program id : ' . $program->id);
212
+ //check for active program with status "Active"
213
+ if (isset($program->status) && $program->status == 'Active') {
214
+ $data = array(
215
+ 'Contacts' => array($apiContact->id),
216
+ 'ProgramId' => $program->id,
217
+ 'Status' => $program->status,
218
+ 'DateCreated' => $program->dateCreated,
219
+ 'AddressBooks' => array()
220
+ );
221
+ $client->postProgramsEnrolments($data);
222
+ }
223
+ }
224
+ }
225
+
226
+ /**
227
+ * convert_quote_to_order observer
228
+ *
229
+ * @param Varien_Event_Observer $observer
230
+ * @return $this
231
+ */
232
+ public function handleQuoteToOrder(Varien_Event_Observer $observer)
233
+ {
234
+ /* @var $order Mage_Sales_Model_Order */
235
+ $order = $observer->getOrder();
236
+ $quoteId = $order->getQuoteId();
237
+ $connectorQuote = Mage::getModel('ddg_automation/quote')->loadQuote($quoteId);
238
+ if($connectorQuote)
239
+ $connectorQuote->setModified(null)->setConvertedToOrder(1)->save();
240
+
241
+ return $this;
242
+ }
243
+
244
+ /**
245
+ * sales_quote_save_after event observer
246
+ *
247
+ * @param Varien_Event_Observer $observer
248
+ * @return $this
249
+ */
250
+ public function handleQuoteSaveAfter(Varien_Event_Observer $observer)
251
+ {
252
+ /* @var $quote Mage_Sales_Model_Quote */
253
+ $quote = $observer->getEvent()->getQuote();
254
+ if($quote->getCustomerId() && $quote->getAllItems() > 0) {
255
+ $connectorQuote = Mage::getModel('ddg_automation/quote')->loadQuote($quote->getId());
256
+ if($connectorQuote){
257
+ if($connectorQuote->getImported())
258
+ $connectorQuote->setModified(1)->save();
259
+ }
260
+ else
261
+ $this->_registerQuote($quote);
262
+ }
263
+ return $this;
264
+ }
265
+
266
+ /**
267
+ * register quote with connector
268
+ *
269
+ * @param Mage_Sales_Model_Quote $quote
270
+ */
271
+ private function _registerQuote(Mage_Sales_Model_Quote $quote)
272
+ {
273
+ try {
274
+ $connectorQuote = Mage::getModel('ddg_automation/quote');
275
+ $connectorQuote->setQuoteId($quote->getId())
276
+ ->setCustomerId($quote->getCustomerId())
277
+ ->setStoreId($quote->getStoreId())
278
+ ->save();
279
+ }catch (Exception $e){
280
+ Mage::logException($e);
281
+ }
282
+ }
283
+ }
app/code/community/Dotdigitalgroup/Email/Model/Sales/Order.php ADDED
@@ -0,0 +1,323 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ /**
19
+ * Global number of orders
20
+ * @var int
21
+ */
22
+ private $_countOrders = 0;
23
+
24
+ private $_reviewCollection = array();
25
+
26
+ /**
27
+ * initial sync the transactional data
28
+ * @return array
29
+ */
30
+ public function sync()
31
+ {
32
+ $response = array('success' => true, 'message' => '');
33
+ $client = Mage::getModel('ddg_automation/apiconnector_client');
34
+ // Initialise a return hash containing results of our sync attempt
35
+ $this->_searchAccounts();
36
+ foreach ($this->accounts as $account) {
37
+ $orders = $account->getOrders();
38
+ $numOrders = count($orders);
39
+ $this->_countOrders += $numOrders;
40
+ //send transactional for any number of orders set
41
+ if ($numOrders) {
42
+ $client->setApiUsername($account->getApiUsername())
43
+ ->setApiPassword($account->getApiPassword());
44
+ Mage::helper('ddg')->log('--------- Order sync ---------- : ' . count($orders));
45
+ $client->postContactsTransactionalDataImport($orders, 'Orders');
46
+ Mage::helper('ddg')->log('----------end order sync----------');
47
+ }
48
+ unset($this->accounts[$account->getApiUsername()]);
49
+ }
50
+
51
+ if ($this->_countOrders)
52
+ $response['message'] = 'Number of updated orders : ' . $this->_countOrders;
53
+ return $response;
54
+ }
55
+
56
+ /**
57
+ * Search the configuration data per website
58
+ */
59
+ private function _searchAccounts()
60
+ {
61
+ $helper = Mage::helper('ddg');
62
+ foreach (Mage::app()->getWebsites(true) as $website) {
63
+ if ($helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_ORDER_ENABLED, $website)) {
64
+
65
+ $this->_apiUsername = $helper->getApiUsername($website);
66
+ $this->_apiPassword = $helper->getApiPassword($website);
67
+
68
+ // limit for orders included to sync
69
+ $limit = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_TRANSACTIONAL_DATA_SYNC_LIMIT, $website);
70
+ if (!isset($this->accounts[$this->_apiUsername])) {
71
+ $account = Mage::getModel('ddg_automation/connector_account')
72
+ ->setApiUsername($this->_apiUsername)
73
+ ->setApiPassword($this->_apiPassword);
74
+ $this->accounts[$this->_apiUsername] = $account;
75
+ }
76
+ $this->accounts[$this->_apiUsername]->setOrders($this->getConnectorOrders($website, $limit));
77
+ }
78
+ }
79
+ }
80
+
81
+ /**
82
+ * get all order to import.
83
+ * @param $website
84
+ * @param int $limit
85
+ * @return array
86
+ */
87
+ public function getConnectorOrders($website, $limit = 100)
88
+ {
89
+ $orders = $customers = array();
90
+ $storeIds = $website->getStoreIds();
91
+ $orderModel = Mage::getModel('ddg_automation/order');
92
+ if(empty($storeIds))
93
+ return array();
94
+
95
+ $helper = Mage::helper('ddg');
96
+ $orderStatuses = $helper->getConfigSelectedStatus($website);
97
+
98
+ if($orderStatuses)
99
+ $orderCollection = $orderModel->getOrdersToImport($storeIds, $limit, $orderStatuses);
100
+ else
101
+ return array();
102
+
103
+ foreach ($orderCollection as $order) {
104
+ try {
105
+ $salesOrder = Mage::getModel('sales/order')->load($order->getOrderId());
106
+ $storeId = $order->getStoreId();
107
+ $websiteId = Mage::app()->getStore($storeId)->getWebsiteId();
108
+ /**
109
+ * Add guest to contacts table.
110
+ */
111
+ if ($salesOrder->getCustomerIsGuest()) {
112
+ $this->_createGuestContact($salesOrder->getCustomerEmail(), $websiteId, $storeId);
113
+ }
114
+ if ($salesOrder->getId()) {
115
+ $connectorOrder = Mage::getModel('ddg_automation/connector_order', $salesOrder);
116
+ $orders[] = $connectorOrder;
117
+ }
118
+ $order->setEmailImported(Dotdigitalgroup_Email_Model_Contact::EMAIL_CONTACT_IMPORTED)
119
+ ->save();
120
+ }catch(Exception $e){
121
+ Mage::logException($e);
122
+ }
123
+ }
124
+ return $orders;
125
+ }
126
+
127
+ /**
128
+ * Create a guest contact.
129
+ * @param $email
130
+ * @param $websiteId
131
+ * @param $storeId
132
+ *
133
+ * @return bool
134
+ */
135
+ private function _createGuestContact($email, $websiteId, $storeId){
136
+ try{
137
+ $client = Mage::helper('ddg')->getWebsiteApiClient($websiteId);
138
+
139
+ //no api credentials or the guest has no been mapped
140
+ if (! $client || ! $addressBookId = Mage::helper('ddg')->getGuestAddressBook($websiteId))
141
+ return false;
142
+ //check if contact exists, create if not
143
+ $contactApi = $client->postContacts($email);
144
+
145
+ //cannot continue error creating contact
146
+ if (isset($contactApi->message)) {
147
+ return false;
148
+ }
149
+
150
+ //add guest to address book
151
+ $response = $client->postAddressBookContacts($addressBookId, $contactApi);
152
+
153
+ //set contact as was found as guest and
154
+ $contactModel = Mage::getModel('ddg_automation/contact')->loadByCustomerEmail($email, $websiteId);
155
+ $contactModel->setIsGuest(1)
156
+ ->setStoreId($storeId)
157
+ ->setEmailImported(1);
158
+ //contact id
159
+ if (isset($contactApi->id))
160
+ $contactModel->setContactId();
161
+
162
+ //mark the contact as surpressed
163
+ if (isset($response->message) && $response->message == 'Contact is suppressed. ERROR_CONTACT_SUPPRESSED')
164
+ $contactModel->setSuppressed(1);
165
+
166
+ //save
167
+ $contactModel->save();
168
+
169
+ Mage::helper('ddg')->log('-- guest found : ' . $email . ' website : ' . $websiteId . ' ,store : ' . $storeId);
170
+ }catch(Exception $e){
171
+ Mage::helper('ddg')->getRaygunClient()->SendException($e, array(Mage::getBaseUrl('web')));
172
+ Mage::logException($e);
173
+ }
174
+
175
+ return true;
176
+ }
177
+
178
+ /**
179
+ * create review campaigns
180
+ *
181
+ * @return bool
182
+ */
183
+ public function createReviewCampaigns()
184
+ {
185
+ $this->searchOrdersForReview();
186
+
187
+ foreach($this->_reviewCollection as $websiteId => $collection){
188
+ $this->registerCampaign($collection, $websiteId);
189
+ }
190
+ }
191
+
192
+ /**
193
+ * register review campaign
194
+ *
195
+ * @param $collection
196
+ * @param $websiteId
197
+ *
198
+ * @throws Exception
199
+ */
200
+ private function registerCampaign($collection, $websiteId)
201
+ {
202
+ $helper = Mage::helper('ddg/review');
203
+ $campaignId = $helper->getCampaign($websiteId);
204
+
205
+ if($campaignId) {
206
+ foreach ($collection as $order) {
207
+ Mage::helper('ddg')->log('-- Order Review: ' . $order->getIncrementId() . ' Campaign Id: ' . $campaignId);
208
+
209
+ try {
210
+ $emailCampaign = Mage::getModel('ddg_automation/campaign');
211
+ $emailCampaign
212
+ ->setEmail($order->getCustomerEmail())
213
+ ->setStoreId($order->getStoreId())
214
+ ->setCampaignId($campaignId)
215
+ ->setEventName('Order Review')
216
+ ->setCreatedAt(Mage::getSingleton('core/date')->gmtDate())
217
+ ->setOrderIncrementId($order->getIncrementId())
218
+ ->setQuoteId($order->getQuoteId());
219
+
220
+ if($order->getCustomerId())
221
+ $emailCampaign->setCustomerId($order->getCustomerId());
222
+
223
+ $emailCampaign->save();
224
+ } catch (Exception $e) {
225
+ Mage::logException($e);
226
+ }
227
+ }
228
+ }
229
+ }
230
+
231
+ /**
232
+ * search for orders to review per website
233
+ */
234
+ private function searchOrdersForReview()
235
+ {
236
+ $helper = Mage::helper('ddg/review');
237
+
238
+ foreach (Mage::app()->getWebsites(true) as $website){
239
+ if($helper->isEnabled($website) &&
240
+ $helper->getOrderStatus($website) &&
241
+ $helper->getDelay($website)){
242
+
243
+ $storeIds = $website->getStoreIds();
244
+ if(empty($storeIds))
245
+ return;
246
+
247
+ $orderStatusFromConfig = $helper->getOrderStatus($website);
248
+ $delayInDays = $helper->getDelay($website);
249
+
250
+ $campaignCollection = Mage::getModel('ddg_automation/campaign')->getCollection();
251
+ $campaignCollection
252
+ ->addFieldToFilter('event_name', 'Order Review')
253
+ ->load();
254
+
255
+ $campaignOrderIds = $campaignCollection->getColumnValues('order_increment_id');
256
+
257
+ $to = Mage::app()->getLocale()->date()
258
+ ->subDay($delayInDays);
259
+ $from = clone $to;
260
+ $to = $to->toString('YYYY-MM-dd HH:mm:ss');
261
+ $from = $from->subHour(2)
262
+ ->toString('YYYY-MM-dd HH:mm:ss');
263
+
264
+ $created = array( 'from' => $from, 'to' => $to, 'date' => true);
265
+
266
+ $collection = Mage::getModel('sales/order')->getCollection();
267
+ $collection->addFieldToFilter('status', $orderStatusFromConfig)
268
+ ->addFieldToFilter('created_at', $created)
269
+ ->addFieldToFilter('store_id', array('in' => $storeIds));
270
+
271
+ if(!empty($campaignOrderIds))
272
+ $collection->addFieldToFilter('increment_id', array('nin' => $campaignOrderIds));
273
+
274
+ $collection->load();
275
+
276
+ if($collection->getSize())
277
+ $this->_reviewCollection[$website->getId()] = $collection;
278
+ }
279
+ }
280
+ }
281
+
282
+ /**
283
+ * get customer last order id
284
+ *
285
+ * @param Mage_Customer_Model_Customer $customer
286
+ * @return bool|Varien_Object
287
+ */
288
+ public function getCustomerLastOrderId(Mage_Customer_Model_Customer $customer)
289
+ {
290
+ $storeIds = Mage::app()->getWebsite($customer->getWebsiteId())->getStoreIds();
291
+ $collection = Mage::getModel('sales/order')->getCollection();
292
+ $collection->addFieldToFilter('customer_id', $customer->getId())
293
+ ->addFieldToFilter('store_id', array('in' => $storeIds))
294
+ ->setPageSize(1)
295
+ ->setOrder('entity_id');
296
+
297
+ if ($collection->count())
298
+ return $collection->getFirstItem();
299
+ else
300
+ return false;
301
+ }
302
+
303
+ /**
304
+ * get customer last quote id
305
+ *
306
+ * @param Mage_Customer_Model_Customer $customer
307
+ * @return bool|Varien_Object
308
+ */
309
+ public function getCustomerLastQuoteId(Mage_Customer_Model_Customer $customer)
310
+ {
311
+ $storeIds = Mage::app()->getWebsite($customer->getWebsiteId())->getStoreIds();
312
+ $collection = Mage::getModel('sales/quote')->getCollection();
313
+ $collection->addFieldToFilter('customer_id', $customer->getId())
314
+ ->addFieldToFilter('store_id', array('in' => $storeIds))
315
+ ->setPageSize(1)
316
+ ->setOrder('entity_id');
317
+
318
+ if ($collection->count())
319
+ return $collection->getFirstItem();
320
+ else
321
+ return false;
322
+ }
323
+ }
app/code/community/Dotdigitalgroup/Email/Model/Sales/Quote.php ADDED
@@ -0,0 +1,269 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 abandoned carts.
42
+ *
43
+ * @param string $mode
44
+ */
45
+ public function proccessAbandonedCarts($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
+
55
+ if ($mode == 'all' || $mode == 'customers') {
56
+ /**
57
+ * Customers campaings
58
+ */
59
+ foreach ( $this->lostBasketCustomers as $num ) {
60
+ //customer enabled
61
+ if ( $this->_getLostBasketCustomerEnabled( $num, $storeId ) ) {
62
+
63
+ //number of the campaign use minutes
64
+ if ( $num == 1 ) {
65
+ $from = Zend_Date::now( $locale )->subMinute( $this->_getLostBasketCustomerInterval( $num, $storeId ) );
66
+ //other use hours
67
+ } else {
68
+ $from = Zend_Date::now( $locale )->subHour( $this->_getLostBasketCustomerInterval( $num, $storeId ) );
69
+ }
70
+
71
+ $to = clone( $from );
72
+ $from->sub( '5', Zend_Date::MINUTE );
73
+
74
+ //active quotes
75
+ $quoteCollection = $this->_getStoreQuotes( $from->toString( 'YYYY-MM-dd HH:mm' ), $to->toString( 'YYYY-MM-dd HH:mm' ), $guest = false, $storeId );
76
+
77
+ if ( $quoteCollection->getSize() ) {
78
+ Mage::helper( 'ddg' )->log( 'Customer lost baskets : ' . $num . ', from : ' . $from->toString( 'YYYY-MM-dd HH:mm' ) . ':' . $to->toString( 'YYYY-MM-dd HH:mm' ) );
79
+ }
80
+
81
+ //campaign id for customers
82
+ $campaignId = $this->_getLostBasketCustomerCampaignId( $num, $storeId );
83
+ foreach ( $quoteCollection as $quote ) {
84
+
85
+ $email = $quote->getCustomerEmail();
86
+ $websiteId = $store->getWebsiteId();
87
+ // upate last quote id for the contact
88
+ Mage::helper('ddg')->updateLastQuoteId($quote->getId(), $email, $websiteId);
89
+
90
+ //send email only if the interval limit passed, no emails during this interval
91
+ $campignFound = $this->_checkCustomerCartLimit( $email, $storeId );
92
+
93
+ //no campign found for interval pass
94
+ if ( !$campignFound ) {
95
+
96
+ //save lost basket for sending
97
+ $sendModel = Mage::getModel('ddg_automation/campaign')
98
+ ->setEmail( $email )
99
+ ->setCustomerId( $quote->getCustomerId() )
100
+ ->setEventName( 'Lost Basket' )
101
+ ->setMessage('Abandoned Cart :' . $num)
102
+ ->setCampaignId( $campaignId )
103
+ ->setStoreId( $storeId )
104
+ ->setWebsiteId($websiteId)
105
+ ->setIsSent( null )->save();
106
+ }
107
+ }
108
+ }
109
+
110
+ }
111
+ }
112
+ if ($mode == 'all' || $mode == 'guests') {
113
+ /**
114
+ * Guests campaigns
115
+ */
116
+ foreach ( $this->lostBasketGuests as $num ) {
117
+ if ( $this->_getLostBasketGuestEnabled( $num, $storeId ) ) {
118
+ if ( $num == 1 ) {
119
+ $from = Zend_Date::now( $locale )->subMinute( $this->_getLostBasketGuestIterval( $num, $storeId ) );
120
+ } else {
121
+ $from = Zend_Date::now( $locale )->subHour( $this->_getLostBasketGuestIterval( $num, $storeId ) );
122
+ }
123
+ $to = clone( $from );
124
+ $from->sub( '5', Zend_Date::MINUTE );
125
+ $quoteCollection = $this->_getStoreQuotes( $from->toString( 'YYYY-MM-dd HH:mm' ), $to->toString( 'YYYY-MM-dd HH:mm' ), $guest = true, $storeId );
126
+
127
+ if ( $quoteCollection->getSize() ) {
128
+ Mage::helper( 'ddg' )->log( 'Guest lost baskets : ' . $num . ', from : ' . $from->toString( 'YYYY-MM-dd HH:mm' ) . ':' . $to->toString( 'YYYY-MM-dd HH:mm' ) );
129
+ }
130
+ $guestCampaignId = $this->_getLostBasketGuestCampaignId( $num, $storeId );
131
+ foreach ( $quoteCollection as $quote ) {
132
+
133
+ $email = $quote->getCustomerEmail();
134
+ $websiteId = $store->getWebsiteId();
135
+ // upate last quote id for the contact
136
+ Mage::helper('ddg')->updateLastQuoteId($quote->getId(), $email, $websiteId);
137
+ //send email only if the interval limit passed, no emails during this interval
138
+ $campignFound = $this->_checkCustomerCartLimit( $email, $storeId );
139
+
140
+ //no campign found for interval pass
141
+ if ( !$campignFound ) {
142
+ //save lost basket for sending
143
+ $sendModel = Mage::getModel('ddg_automation/campaign')
144
+ ->setEmail( $email )
145
+ ->setEventName( 'Lost Basket' )
146
+ ->setCheckoutMethod( 'Guest' )
147
+ ->setMessage('Guest Abandoned Cart : ' . $num)
148
+ ->setCampaignId( $guestCampaignId )
149
+ ->setStoreId( $storeId )
150
+ ->setWebsiteId($websiteId)
151
+ ->setIsSent( null )->save();
152
+ }
153
+ }
154
+ }
155
+ }
156
+ }
157
+ }
158
+ }
159
+
160
+ private function _getLostBasketCustomerCampaignId($num, $storeId)
161
+ {
162
+ $store = Mage::app()->getStore($storeId);
163
+ return $store->getConfig(constant('self::XML_PATH_LOSTBASKET_CUSTOMER_CAMPAIGN_' . $num));
164
+ }
165
+ private function _getLostBasketGuestCampaignId($num, $storeId)
166
+ {
167
+ $store = Mage::app()->getStore($storeId);
168
+ return $store->getConfig(constant('self::XML_PATH_LOSTBASKET_GUEST_CAMPAIGN_'. $num));
169
+ }
170
+
171
+ private function _getLostBasketCustomerInterval($num, $storeId)
172
+ {
173
+ $store = Mage::app()->getstore($storeId);
174
+ return $store->getConfig(constant('self::XML_PATH_LOSTBASKET_CUSTOMER_INTERVAL_' . $num));
175
+ }
176
+
177
+ private function _getLostBasketGuestIterval($num, $storeId)
178
+ {
179
+ $store = Mage::app()->getStore($storeId);
180
+ return $store->getConfig(constant('self::XML_PATH_LOSTBASKET_GUEST_INTERVAL_' . $num));
181
+ }
182
+
183
+ protected function _getLostBasketCustomerEnabled($num, $storeId)
184
+ {
185
+ $store = Mage::app()->getStore($storeId);
186
+ $enabled = $store->getConfig(constant('self::XML_PATH_LOSTBASKET_CUSTOMER_ENABLED_' . $num));
187
+ return $enabled;
188
+
189
+ }
190
+
191
+ protected function _getLostBasketGuestEnabled($num, $storeId)
192
+ {
193
+ $store = Mage::app()->getStore($storeId);
194
+ return $store->getConfig(constant('self::XML_PATH_LOSTBASKET_GUEST_ENABLED_' . $num));
195
+ }
196
+
197
+ /**
198
+ * @param string $from
199
+ * @param string $to
200
+ * @param bool $guest
201
+ * @param int $storeId
202
+ * @return Mage_Eav_Model_Entity_Collection_Abstract
203
+ */
204
+ private function _getStoreQuotes($from = null, $to = null, $guest = false, $storeId = 0)
205
+ {
206
+ $updated = array(
207
+ 'from' => $from,
208
+ 'to' => $to,
209
+ 'date' => true);
210
+
211
+ $salesCollection = Mage::getResourceModel('sales/quote_collection')
212
+ ->addFieldToFilter('is_active', 1)
213
+ ->addFieldToFilter('items_count', array('gt' => 0))
214
+ ->addFieldToFilter('customer_email', array('neq' => ''))
215
+ ->addFieldToFilter('store_id', $storeId)
216
+ ->addFieldToFilter('updated_at', $updated);
217
+ //guests
218
+ if ($guest) {
219
+ $salesCollection->addFieldToFilter( 'customer_id', array( 'null' => true ) );
220
+ } else {
221
+ //customers
222
+ $salesCollection->addFieldToFilter( 'customer_id', array( 'notnull' => true ) );
223
+ }
224
+
225
+ return $salesCollection;
226
+ }
227
+
228
+ /**
229
+ * Check customer campaign that was sent by a limit from config.
230
+ * Return false for any found for this period.
231
+ *
232
+ * @param $email
233
+ * @param $storeId
234
+ *
235
+ * @return bool
236
+ */
237
+ private function _checkCustomerCartLimit($email, $storeId) {
238
+
239
+ $cartLimit = Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_ABANDONED_CART_LIMIT, $storeId);
240
+ $locale = Mage::app()->getLocale()->getLocale();
241
+
242
+ //no limit is set skip
243
+ if (! $cartLimit)
244
+ return false;
245
+
246
+ //time diff
247
+ $to = Zend_Date::now($locale);
248
+ $from = Zend_Date::now($locale)->subHour($cartLimit);
249
+
250
+ $updated = array(
251
+ 'from' => $from,
252
+ 'to' => $to,
253
+ 'date' => true
254
+ );
255
+
256
+ //number of campigns during this time
257
+ $campaignLimit = Mage::getModel('ddg_automation/campaign')->getCollection()
258
+ ->addFieldToFilter('email', $email)
259
+ ->addFieldToFilter('event_name', 'Lost Basket')
260
+ ->addFieldToFilter('sent_at', $updated)
261
+ ->count()
262
+ ;
263
+
264
+ if ($campaignLimit)
265
+ return true;
266
+
267
+ return false;
268
+ }
269
+ }
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('ddg')->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('ddg')->log('sending sms message with status : ' . $status . ' and ' . $codePhone);
86
+ $client->postSmsMessagesSendTo($codePhone, $message);
87
+ }
88
+ } else {
89
+ Mage::helper('ddg')->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('ddg');
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/Model/Wishlist.php ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Wishlist extends Mage_Core_Model_Abstract
4
+ {
5
+ private $_start;
6
+ private $_wishlists;
7
+ private $_count = 0;
8
+
9
+ /**
10
+ * constructor
11
+ */
12
+ public function _construct()
13
+ {
14
+ parent::_construct();
15
+ $this->_init('ddg_automation/wishlist');
16
+ }
17
+
18
+ /**
19
+ * @return $this|Mage_Core_Model_Abstract
20
+ */
21
+ protected function _beforeSave()
22
+ {
23
+ parent::_beforeSave();
24
+ $now = Mage::getSingleton('core/date')->gmtDate();
25
+ if ($this->isObjectNew()) {
26
+ $this->setCreatedAt($now);
27
+ }else {
28
+ $this->setUpdatedAt($now);
29
+ }
30
+ return $this;
31
+ }
32
+
33
+ /**
34
+ * @param int $wishListId
35
+ * @return bool|Varien_Object
36
+ */
37
+ public function getWishlist($wishListId)
38
+ {
39
+ $collection = $this->getCollection()
40
+ ->addFieldToFilter('wishlist_id', $wishListId)
41
+ ->setPageSize(1);
42
+
43
+ if ($collection->count()) {
44
+ return $collection->getFirstItem();
45
+ }
46
+ return false;
47
+ }
48
+
49
+ public function sync()
50
+ {
51
+ $response = array('success' => true, 'message' => '');
52
+ $helper = Mage::helper('ddg');
53
+ //resource allocation
54
+ $helper->allowResourceFullExecution();
55
+
56
+ foreach (Mage::app()->getWebsites(true) as $website) {
57
+ $enabled = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_WISHLIST_ENABLED, $website);
58
+ if ($enabled) {
59
+ //using bulk api
60
+ $helper->log('---------- Start wishlist bulk sync ----------');
61
+ $this->_start = microtime(true);
62
+ $this->_exportWishlistForWebsite($website);
63
+ //send wishlist as transactional data
64
+ if (isset($this->_wishlists[$website->getId()])) {
65
+ $client = Mage::helper('ddg')->getWebsiteApiClient($website);
66
+ $websiteWishlists = $this->_wishlists[$website->getId()];
67
+ //import wishlists in bulk
68
+ $client->postContactsTransactionalDataImport($websiteWishlists, 'Wishlist');
69
+ }
70
+ $message = 'Total time for wishlist bulk sync : ' . gmdate("H:i:s", microtime(true) - $this->_start);
71
+ $helper->log($message);
72
+
73
+ //using single api
74
+ $this->_exportWishlistForWebsiteInSingle($website);
75
+ }
76
+ }
77
+ $response['message'] = "wishlist updated: ". $this->_count;
78
+ return $response;
79
+ }
80
+
81
+ private function _exportWishlistForWebsite(Mage_Core_Model_Website $website)
82
+ {
83
+ //reset wishlists
84
+ $this->_wishlists = array();
85
+ $limit = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_TRANSACTIONAL_DATA_SYNC_LIMIT, $website);
86
+ $collection = $this->_getWishlistToImport($website, $limit);
87
+ foreach($collection as $emailWishlist){
88
+ $customer = Mage::getModel('customer/customer')->load($emailWishlist->getCustomerId());
89
+ $wishlist = Mage::getModel('wishlist/wishlist')->load($emailWishlist->getWishlistId());
90
+ /** @var $connectorWishlist */
91
+ $connectorWishlist = Mage::getModel('ddg_automation/customer_wishlist', $customer);
92
+ $connectorWishlist->setId($wishlist->getId())
93
+ ->setUpdatedAt($wishlist->getUpdatedAt());
94
+ $wishListItemCollection = $wishlist->getItemCollection();
95
+ if (count($wishListItemCollection)) {
96
+ foreach ($wishListItemCollection as $item) {
97
+ /* @var $product Mage_Catalog_Model_Product */
98
+ $product = $item->getProduct();
99
+ $wishlistItem = Mage::getModel('ddg_automation/customer_wishlist_item', $product)
100
+ ->setQty($item->getQty())
101
+ ->setPrice($product);
102
+ //store for wishlists
103
+ $connectorWishlist->setItem($wishlistItem);
104
+ $this->_count++;
105
+ }
106
+ //set wishlists for later use
107
+ $this->_wishlists[$website->getId()][] = $connectorWishlist;
108
+ $emailWishlist->setWishlistImported(1)->save();
109
+ }
110
+ }
111
+ }
112
+
113
+ private function _getWishlistToImport(Mage_Core_Model_Website $website, $limit = 100)
114
+ {
115
+ $collection = $this->getCollection()
116
+ ->addFieldToFilter('wishlist_imported', array('null' => true))
117
+ ->addFieldToFilter('store_id', array('in' => $website->getStoreIds()))
118
+ ->addFieldToFilter('item_count', array('gt' => 0));
119
+
120
+ $collection->getSelect()->limit($limit);
121
+ return $collection->load();
122
+ }
123
+
124
+ private function _exportWishlistForWebsiteInSingle(Mage_Core_Model_Website $website)
125
+ {
126
+ $helper = Mage::helper('ddg');
127
+ $client = $helper->getWebsiteApiClient($website);
128
+ $limit = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_TRANSACTIONAL_DATA_SYNC_LIMIT, $website);
129
+ $collection = $this->_getModifiedWishlistToImport($website, $limit);
130
+ foreach($collection as $emailWishlist){
131
+ $customer = Mage::getModel('customer/customer')->load($emailWishlist->getCustomerId());
132
+ $wishlist = Mage::getModel('wishlist/wishlist')->load($emailWishlist->getWishlistId());
133
+ /** @var $connectorWishlist */
134
+ $connectorWishlist = Mage::getModel('ddg_automation/customer_wishlist', $customer);
135
+ $connectorWishlist->setId($wishlist->getId());
136
+ $wishListItemCollection = $wishlist->getItemCollection();
137
+ if (count($wishListItemCollection)) {
138
+ foreach ($wishListItemCollection as $item) {
139
+ /* @var $product Mage_Catalog_Model_Product */
140
+ $product = $item->getProduct();
141
+ $wishlistItem = Mage::getModel('ddg_automation/customer_wishlist_item', $product)
142
+ ->setQty($item->getQty())
143
+ ->setPrice($product);
144
+ //store for wishlists
145
+ $connectorWishlist->setItem($wishlistItem);
146
+ $this->_count++;
147
+ }
148
+ //send wishlist as transactional data
149
+ $helper->log('---------- Start wishlist single sync ----------');
150
+ $this->_start = microtime(true);
151
+ //import single piece of transactional data
152
+ $result = $client->postContactsTransactionalData($connectorWishlist, 'Wishlist');
153
+ if (!isset($result->message)){
154
+ $emailWishlist->setWishlistModified(null)->save();
155
+ }
156
+ $message = 'Total time for wishlist single sync : ' . gmdate("H:i:s", microtime(true) - $this->_start);
157
+ $helper->log($message);
158
+ }else{
159
+ $result = $client->deleteContactsTransactionalData($wishlist->getId(), 'Wishlist');
160
+ if (!isset($result->message)){
161
+ $emailWishlist->setWishlistModified(null)->save();
162
+ }
163
+ $message = 'Total time for wishlist single sync : ' . gmdate("H:i:s", microtime(true) - $this->_start);
164
+ $helper->log($message);
165
+ }
166
+ }
167
+ }
168
+
169
+ private function _getModifiedWishlistToImport(Mage_Core_Model_Website $website, $limit = 100)
170
+ {
171
+ $collection = $this->getCollection()
172
+ ->addFieldToFilter('wishlist_modified', 1)
173
+ ->addFieldToFilter('store_id', array('in' => $website->getStoreIds()));
174
+
175
+ $collection->getSelect()->limit($limit);
176
+ return $collection->load();
177
+ }
178
+
179
+ /**
180
+ * Reset the email reviews for reimport.
181
+ *
182
+ * @return int
183
+ */
184
+ public function reset()
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
+ try{
192
+ $num = $conn->update($coreResource->getTableName('ddg_automation/wishlist'),
193
+ array('wishlist_imported' => new Zend_Db_Expr('null')),
194
+ $conn->quoteInto('wishlist_imported is ?', new Zend_Db_Expr('not null'))
195
+ );
196
+ }catch (Exception $e){
197
+ Mage::logException($e);
198
+ }
199
+
200
+ return $num;
201
+ }
202
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/ConnectorController.php ADDED
@@ -0,0 +1,385 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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('ddg')->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('ddg_automation/connector_datafield')->getContactDatafields();
18
+ foreach ($datafields as $key => $datafield) {
19
+ $response = $apiModel->postDataFields($datafield, 'Private');
20
+
21
+ //ignore existing datafields message
22
+ if (isset($response->message) && $response->message != Dotdigitalgroup_Email_Model_Apiconnector_Client::API_ERROR_DATAFIELD_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('ddg')->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('ddg_automation/order')->resetOrders();
57
+ Mage::helper('ddg')->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('ddg_automation/contact')->resetAllContacts();
68
+
69
+ Mage::getSingleton('adminhtml/session')->addSuccess('Done.');
70
+
71
+ $this->_redirectReferer();
72
+ }
73
+
74
+ /**
75
+ * Refresh suppressed contacts.
76
+ */
77
+ public function suppresscontactsAction()
78
+ {
79
+ Mage::getModel('ddg_automation/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('ddg_automation/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('ddg_automation/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('ddg_automation/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('ddg_automation/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('ddg_automation/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', 0);
158
+ $access = $request->getParam('access', false);
159
+ $website = $request->getParam('website', 0);
160
+
161
+ //api client for this website
162
+ $client = Mage::helper('ddg')->getWebsiteApiClient($website);
163
+ //only if all data is available
164
+ if ($name && $type && $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('ddg')->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('ddg')->rayLog('100', $message);
180
+ }
181
+ }
182
+
183
+ /**
184
+ * Create new address book action.
185
+ */
186
+ public function createnewaddressbookAction()
187
+ {
188
+ $addressBookName = $this->getRequest()->getParam('name');
189
+ $visibility = $this->getRequest()->getParam('visibility');
190
+ $website = $this->getRequest()->getParam('website', 0);
191
+ $client = Mage::helper('ddg')->getWebsiteApiClient($website);
192
+ if (strlen($addressBookName)) {
193
+ $response = $client->postAddressBooks($addressBookName, $visibility);
194
+ if (isset($response->message))
195
+ Mage::getSingleton('adminhtml/session')->addError($response->message);
196
+ else
197
+ Mage::getSingleton('adminhtml/session')->addSuccess('Address book : '. $addressBookName . ' created.');
198
+ }
199
+
200
+ }
201
+
202
+ public function reimoprtsubscribersAction()
203
+ {
204
+ $updated = Mage::getModel('ddg_automation/contact')->resetSubscribers();
205
+ if ($updated) {
206
+ Mage::getSingleton('adminhtml/session')->addSuccess('Done.');
207
+ } else {
208
+ Mage::getSingleton('adminhtml/session')->addNotice('No subscribers imported!');
209
+ }
210
+ $this->_redirectReferer();
211
+ }
212
+
213
+ /**
214
+ * path constant for config helper sent as string.
215
+ */
216
+ public function enablewebsiteconfigurationAction()
217
+ {
218
+ $path = $this->getRequest()->getParam('path');
219
+ $value = $this->getRequest()->getParam('value');
220
+ $website = $this->getRequest()->getParam('website', 0);
221
+
222
+ $path = constant('Dotdigitalgroup_Email_Helper_Config::' . $path);
223
+ $scope = 'websites';
224
+ $scopeId = $website;
225
+
226
+ $config = Mage::getConfig();
227
+
228
+ //use value 1 if not set
229
+ if (isset($value))
230
+ $config->saveConfig($path, $value, $scope, $scopeId);
231
+ else
232
+ $config->saveConfig($path, 1, $scope, $scopeId);
233
+
234
+ //clean cache
235
+ $config->cleanCache();
236
+
237
+ $this->_redirectReferer();
238
+ }
239
+
240
+ /**
241
+ * Populate the tables (customer-email_contact, subscribers-email_contact) with missing ones.
242
+ */
243
+ public function populatecontactsAction()
244
+ {
245
+
246
+ //type of data to bring up-to-date
247
+ $type = $this->getRequest()->getParam('type', false);
248
+ $website = $this->getRequest()->getParam('website', false);
249
+ //required data not set
250
+ if (!$type && $website == false) {
251
+ return ;
252
+ }
253
+
254
+ $contactTable = Mage::getSingleton('core/resource')->getTableName('ddg_automation/contact');
255
+
256
+ $customerCollection = Mage::getModel('customer/customer')->getCollection()
257
+ ->addFieldToFilter('website_id', $website);
258
+
259
+ $customerCollection->getSelect()
260
+ ->joinLeft(array('ec' => $contactTable), 'e.entity_id = ec.customer_id', array('customer_id' => 'ec.customer_id'))
261
+ ->where('ec.customer_id IS NULL');
262
+
263
+ //found customers t
264
+ if ($count = $customerCollection->getSize()) {
265
+ //trigger the save to update the contact table
266
+ foreach ( $customerCollection as $customer ) {
267
+ $customer->save();
268
+ }
269
+
270
+ Mage::getSingleton( 'adminhtml/session' )->addSuccess( "Total contacts populated : " . $count );
271
+ }
272
+ $this->_redirectReferer();
273
+ }
274
+
275
+ /**
276
+ * Trigger to run the contact sync.
277
+ */
278
+ public function runcontactsyncAction()
279
+ {
280
+ $result = Mage::getModel('ddg_automation/cron')->contactSync();
281
+
282
+ if ($result['message'])
283
+ Mage::getSingleton('adminhtml/session')->addSuccess($result['message']);
284
+
285
+ $this->_redirectReferer();
286
+ }
287
+
288
+ /**
289
+ * Trigger to run the subscriber sync.
290
+ */
291
+ public function runsubscribersyncAction()
292
+ {
293
+ $result = Mage::getModel('ddg_automation/cron')->subscribersAndGuestSync();
294
+
295
+ if ($result['message'])
296
+ Mage::getSingleton('adminhtml/session')->addSuccess($result['message']);
297
+
298
+ $this->_redirectReferer();
299
+ }
300
+
301
+ /**
302
+ * Trigger to run the order sync.
303
+ */
304
+ public function runordersyncAction()
305
+ {
306
+
307
+ $result = Mage::getModel('ddg_automation/cron')->orderSync();
308
+ if ($result['message'])
309
+ Mage::getSingleton('adminhtml/session')->addSuccess($result['message']);
310
+
311
+ $this->_redirectReferer();
312
+ }
313
+
314
+ /**
315
+ * Trigger to run the review sync.
316
+ */
317
+ public function runreviewsyncAction()
318
+ {
319
+
320
+ $result = Mage::getModel('ddg_automation/cron')->reviewSync();
321
+ if ($result['message'])
322
+ Mage::getSingleton('adminhtml/session')->addSuccess($result['message']);
323
+
324
+ $this->_redirectReferer();
325
+ }
326
+
327
+ /**
328
+ * Trigger to run the reviw sync.
329
+ */
330
+ public function runwishlistsyncAction()
331
+ {
332
+
333
+ $result = Mage::getModel('ddg_automation/wishlist')->sync();
334
+ if ($result['message'])
335
+ Mage::getSingleton('adminhtml/session')->addSuccess($result['message']);
336
+
337
+ $this->_redirectReferer();
338
+ }
339
+
340
+ /**
341
+ * Trigger to run the quote sync.
342
+ */
343
+ public function runquotesyncAction()
344
+ {
345
+
346
+ $result = Mage::getModel('ddg_automation/cron')->quoteSync();
347
+ if ($result['message'])
348
+ Mage::getSingleton('adminhtml/session')->addSuccess($result['message']);
349
+
350
+ $this->_redirectReferer();
351
+ }
352
+
353
+ /**
354
+ * Reset quote for reimport.
355
+ */
356
+ public function resetquotesAction()
357
+ {
358
+ $num = Mage::getModel('ddg_automation/quote')->resetQuotes();
359
+ Mage::helper('ddg')->log('-- Reset Quotes for reimport : ' . $num);
360
+ Mage::getSingleton('adminhtml/session')->addSuccess('Done.');
361
+ $this->_redirectReferer();
362
+ }
363
+
364
+ /**
365
+ * Reset reviews for reimport.
366
+ */
367
+ public function resetreviewsAction()
368
+ {
369
+ $num = Mage::getModel('ddg_automation/review')->reset();
370
+ Mage::helper('ddg')->log('-- Reset Reviews for reimport : ' . $num);
371
+ Mage::getSingleton('adminhtml/session')->addSuccess('Done.');
372
+ $this->_redirectReferer();
373
+ }
374
+
375
+ /**
376
+ * Reset wishlist for reimport.
377
+ */
378
+ public function resetwishlistsAction()
379
+ {
380
+ $num = Mage::getModel('ddg_automation/wishlist')->reset();
381
+ Mage::helper('ddg')->log('-- Reset Wishlist for reimport : ' . $num);
382
+ Mage::getSingleton('adminhtml/session')->addSuccess('Done.');
383
+ $this->_redirectReferer();
384
+ }
385
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/AutomationController.php ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Adminhtml_Email_AutomationController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+
6
+ protected function _construct(){
7
+ $this->setUsedModuleName('Dotdigitalgroup_Email');
8
+ }
9
+
10
+ /**
11
+ * main page.
12
+ */
13
+ public function indexAction()
14
+ {
15
+ $this->_title($this->__('Automation'))
16
+ ->_title($this->__('Automation Status'));
17
+ $this->loadLayout();
18
+ $this->_setActiveMenu('email_connector');
19
+ $this->renderLayout();
20
+ }
21
+
22
+ public function editAction()
23
+ {
24
+ $this->_redirect('*/*');
25
+ }
26
+
27
+ /**
28
+ * main grid.
29
+ */
30
+ public function gridAction(){
31
+ $this->loadLayout();
32
+ $this->renderLayout();
33
+ }
34
+
35
+ /**
36
+ * Delete action.
37
+ */
38
+ public function massDeleteAction()
39
+ {
40
+ $automationIds = $this->getRequest()->getParam('automation');
41
+ if (!is_array($automationIds)) {
42
+ $this->_getSession()->addError($this->__('Please select .'));
43
+ }else {
44
+ try {
45
+ foreach ($automationIds as $id) {
46
+ $automation = Mage::getSingleton('ddg_automation/automation')->load($id);
47
+ Mage::dispatchEvent('connector_controller_automation_delete', array('automation' => $automation));
48
+ $automation->delete();
49
+ }
50
+ $this->_getSession()->addSuccess(
51
+ Mage::helper('ddg')->__('Total of %d record(s) have been deleted.', count($automationIds))
52
+ );
53
+ } catch (Exception $e) {
54
+ $this->_getSession()->addError($e->getMessage());
55
+ }
56
+ }
57
+ $this->_redirect('*/*/index');
58
+ }
59
+
60
+ /**
61
+ * Mark for resend.
62
+ */
63
+ public function massResendAction()
64
+ {
65
+ $automationIds = $this->getRequest()->getParam('automation');
66
+ if (!is_array($automationIds)) {
67
+ $this->_getSession()->addError($this->__('Please select .'));
68
+ }else {
69
+ try {
70
+
71
+ /** @var $coreResource Mage_Core_Model_Resource */
72
+ $coreResource = Mage::getSingleton('core/resource');
73
+
74
+ /** @var $conn Varien_Db_Adapter_Pdo_Mysql */
75
+ $conn = $coreResource->getConnection('core_write');
76
+
77
+ $num = $conn->update($coreResource->getTableName('ddg_automation/automation'),
78
+ array('enrolment_status' => new Zend_Db_Expr('null')),
79
+ array('id IN(?)' => $automationIds)
80
+ );
81
+
82
+ $this->_getSession()->addSuccess(
83
+ Mage::helper('ddg')->__('Total of %d record(s) have been deleted.', $num)
84
+ );
85
+ } catch (Exception $e) {
86
+ $this->_getSession()->addError($e->getMessage());
87
+ }
88
+ }
89
+ $this->_redirect('*/*/index');
90
+ }
91
+
92
+ protected function _isAllowed()
93
+ {
94
+ return Mage::getSingleton('admin/session')->isAllowed('email_connector/reports/email_connector_automation');
95
+ }
96
+
97
+ }
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('ddg')->__('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('ddg')->__('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('ddg')->__('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('ddg')->__('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('ddg_automation/campaign')->load($id);
111
+ try {
112
+ $campaign->delete();
113
+ $this->_getSession()->addSuccess(Mage::helper('ddg')->__('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('ddg_automation/campaign')->load($campaignId);
134
+ Mage::dispatchEvent('connector_controller_campaign_delete', array('campaign' => $campaign));
135
+ $campaign->delete();
136
+ }
137
+ $this->_getSession()->addSuccess(
138
+ Mage::helper('ddg')->__('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('ddg_automation/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('ddg')->__('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('ddg_automation/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('ddg')->__('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('ddg_automation/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('ddg_automation/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/ddg_automation_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('ddg')->__('This contact no longer exists.'));
33
+ $this->_redirect('*/*/');
34
+ return;
35
+ }
36
+ $contactEmail = Mage::getModel('ddg_automation/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('ddg')->__('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('ddg')->__('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('ddg_automation/contact')->load($id);
93
+ try {
94
+ $contact->delete();
95
+ $this->_getSession()->addSuccess(Mage::helper('ddg')->__('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('ddg_automation/contact')->load($contactId);
116
+ Mage::dispatchEvent('connector_controller_affiliate_delete', array('contact' => $contact));
117
+ $contact->delete();
118
+ }
119
+ $this->_getSession()->addSuccess(
120
+ Mage::helper('ddg')->__('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('ddg_automation/contact')->load($contactId);
142
+ $contact->setEmailImported(null)->save();
143
+ }
144
+ $this->_getSession()->addSuccess(
145
+ Mage::helper('ddg')->__('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('ddg_automation/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('ddg_automation/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/ddg_automation/ddg_automation_contact');
190
+ }
191
+
192
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/DashboardController.php ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Adminhtml_Email_DashboardController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+ /**
6
+ * post dispatch
7
+ */
8
+ public function postDispatch()
9
+ {
10
+ //check the api valid for any of the website
11
+ foreach ( Mage::app()->getWebsites( true ) as $website ) {
12
+
13
+ $passed = Mage::helper('ddg')->isEnabled($website);
14
+
15
+ if (! $passed)
16
+ $this->_redirect('*/system_config/edit', array('section' => 'connector_api_credentials'));
17
+ }
18
+
19
+ }
20
+ /**
21
+ * main page.
22
+ */
23
+ public function indexAction()
24
+ {
25
+ $this->_title($this->__('Dashboard'));
26
+
27
+ $this->loadLayout();
28
+ $this->_setActiveMenu('ddg_automation');
29
+ $this->_addContent($this->getLayout()->createBlock('adminhtml/widget_container'))
30
+ ->_addLeft($this->getLayout()->createBlock ('ddg_automation/adminhtml_dashboard_tabs'));
31
+ $this->renderLayout();
32
+ }
33
+
34
+ /**
35
+ * Load Status Grid as ajax requst.
36
+ */
37
+ public function statusGridAction() {
38
+
39
+ $block = $this->getLayout()->createBlock('ddg_automation/adminhtml_dashboard_tabs_status');
40
+ $this->getResponse()->setBody($block->toHtml());
41
+
42
+ }
43
+
44
+ /**
45
+ * Ajax tab for config data.
46
+ */
47
+ public function emailConfigAction() {
48
+ $block = $this->getLayout()->createBlock('ddg_automation/adminhtml_dashboard_tabs_config');
49
+
50
+ $this->getResponse()->setBody($block->toHtml());
51
+ }
52
+
53
+ protected function _isAllowed()
54
+ {
55
+ return Mage::getSingleton('admin/session')->isAllowed('newsletter/ddg_automation/ddg_automation_dashboard');
56
+ }
57
+
58
+
59
+ /**
60
+ * Ajax save the state of expandbles fieldsets.
61
+ */
62
+ public function stateAction()
63
+ {
64
+ $configState = array(
65
+ $this->getRequest()->getParam('container') => $this->getRequest()->getParam('value')
66
+ );
67
+ $this->_saveState($configState);
68
+ }
69
+
70
+ protected function _saveState($configState = array())
71
+ {
72
+ $adminUser = Mage::getSingleton('admin/session')->getUser();
73
+ if (is_array($configState)) {
74
+ $extra = $adminUser->getExtra();
75
+ if (!is_array($extra)) {
76
+ $extra = array();
77
+ }
78
+ if (!isset($extra['configState'])) {
79
+ $extra['configState'] = array();
80
+ }
81
+ foreach ($configState as $fieldset => $state) {
82
+ $extra['configState'][$fieldset] = $state;
83
+ }
84
+ $adminUser->saveExtra($extra);
85
+ }
86
+
87
+ return true;
88
+ }
89
+
90
+
91
+ }
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('ddg_automation');
12
+ $this->_addContent($this->getLayout()->createBlock('ddg_automation/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/ddg_automation/email_connector_order');
25
+ }
26
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/QuoteController.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Adminhtml_Email_QuoteController 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('ddg_automation/adminhtml_quote'));
13
+ $this->getLayout()->getBlock('head')->setTitle('Connector Quote(s)');
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/ddg_automation/email_connector_quote');
25
+ }
26
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/ReviewController.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Adminhtml_Email_ReviewController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+ /**
6
+ * main page.
7
+ */
8
+ public function indexAction()
9
+ {
10
+ $this->loadLayout();
11
+ $this->_setActiveMenu('ddg_automation');
12
+ $this->_addContent($this->getLayout()->createBlock('ddg_automation/adminhtml_review'));
13
+ $this->getLayout()->getBlock('head')->setTitle('Connector Reviews');
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/ddg_automation/email_connector_review');
25
+ }
26
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/StudioController.php ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Adminhtml_Email_StudioController 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
+ $baseUrl = Mage::helper('ddg/config')->getLogUserUrl();
18
+ $loginuserUrl = $baseUrl . $token . '&suppressfooter=true';
19
+
20
+ $block = $this->getLayout()
21
+ ->createBlock('core/text', 'connector_iframe')
22
+ ->setText(
23
+ "<iframe src=" . $loginuserUrl . " width=100% height=1650 frameborder='0' scrolling='no' style='margin:0;padding: 0;display:block;'></iframe>"
24
+ );
25
+
26
+ $this->_addContent($block);
27
+ $this->renderLayout();
28
+ }
29
+
30
+ protected function _isAllowed()
31
+ {
32
+ return Mage::getSingleton('admin/session')->isAllowed('ddg_automation/automation_studio');
33
+ }
34
+
35
+ /**
36
+ * Generate new token and connect from the admin.
37
+ *
38
+ * POST httpsː//my.dotmailer.com/OAuth2/Tokens.ashx HTTP/1.1
39
+ * Content-Type: application/x-www-form-urlencoded
40
+ * client_id=QVNY867m2DQozogTJfUmqA%253D%253D&
41
+ * redirect_uri=https%3a%2f%2flocalhost%3a10999%2fcallback.aspx
42
+ * &client_secret=SndpTndiSlhRawAAAAAAAA%253D%253D
43
+ * &grant_type=authorization_code
44
+ */
45
+ public function generatetokenAction()
46
+ {
47
+ //check for secure url
48
+ $adminUser = Mage::getSingleton('admin/session')->getUser();
49
+ $refreshToken = Mage::getSingleton('admin/user')->load($adminUser->getId())->getRefreshToken();
50
+
51
+ if ($refreshToken) {
52
+ $code = Mage::helper('ddg')->getCode();
53
+ $params = 'client_id=' . Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CLIENT_ID) .
54
+ '&client_secret=' . Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CLIENT_SECRET_ID) .
55
+ '&refresh_token=' . $refreshToken .
56
+ '&grant_type=refresh_token';
57
+
58
+ $url = Mage::helper('ddg/config')->getTokenUrl();
59
+
60
+ Mage::helper('ddg')->log('token code : ' . $code . ', params : ' . $params);
61
+
62
+ /**
63
+ * Refresh Token request.
64
+ */
65
+ $ch = curl_init();
66
+ curl_setopt($ch, CURLOPT_URL, $url);
67
+ curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
68
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
69
+ curl_setopt($ch, CURLOPT_TIMEOUT, 5);
70
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
71
+ curl_setopt($ch, CURLOPT_POST, count($params));
72
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
73
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
74
+
75
+ $response = json_decode(curl_exec($ch));
76
+
77
+ if (isset($response->error)) {
78
+ Mage::helper('ddg')->log("Token Error Num`ber:" . curl_errno($ch) . "Error String:" . curl_error($ch));
79
+ }
80
+ curl_close($ch);
81
+
82
+ $token = $response->access_token;
83
+ return $token;
84
+
85
+ } else {
86
+ Mage::getSingleton('adminhtml/session')->addNotice('Please Connect To Access The Page.');
87
+ }
88
+
89
+ $this->_redirect('*/system_config/edit', array('section' => 'connector_developer_settings'));
90
+ }
91
+
92
+ /**
93
+ * Disconnect and remote the refresh token.
94
+ */
95
+ public function disconnectAction()
96
+ {
97
+ try {
98
+ $adminUser = Mage::getSingleton('admin/session')->getUser();
99
+
100
+ if ($adminUser->getRefreshToken()) {
101
+ $adminUser->setRefreshToken()->save();
102
+ }
103
+ Mage::getSingleton('adminhtml/session')->addSuccess('Successfully disconnected');
104
+ }catch (Exception $e){
105
+ Mage::logException($e);
106
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
107
+ }
108
+
109
+ $this->_redirectReferer('*/*/*');
110
+ }
111
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/WishlistController.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Adminhtml_Email_WishlistController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+ /**
6
+ * main page.
7
+ */
8
+ public function indexAction()
9
+ {
10
+ $this->loadLayout();
11
+ $this->_setActiveMenu('ddg_automation');
12
+ $this->_addContent($this->getLayout()->createBlock('ddg_automation/adminhtml_wishlist'));
13
+ $this->getLayout()->getBlock('head')->setTitle('Connector Wishlist(s)');
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/ddg_automation/email_connector_wishlist');
25
+ }
26
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/System/Email/TemplateController.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once 'Mage/Adminhtml/controllers/System/Email/TemplateController.php';
4
+
5
+ class Dotdigitalgroup_Email_Adminhtml_System_Email_TemplateController extends Mage_Adminhtml_System_Email_TemplateController
6
+ {
7
+ /**
8
+ * Set template data to retrieve it in template info form
9
+ */
10
+ public function defaultTemplateAction()
11
+ {
12
+ if(!$this->getRequest()->getParam('connector') or $this->getRequest()->getParam('connector') == '')
13
+ parent::defaultTemplateAction();
14
+
15
+ $template = $this->_initTemplate('id');
16
+ $templateCode = $this->getRequest()->getParam('code');
17
+ $connectorTemplateId = $this->getRequest()->getParam('connector');
18
+
19
+ $template->loadDefault($templateCode, $this->getRequest()->getParam('locale'));
20
+ $template->setData('orig_template_code', $templateCode);
21
+ $template->setData('template_variables', Zend_Json::encode($template->getVariablesOptionArray(true)));
22
+
23
+ $templateBlock = $this->getLayout()->createBlock('adminhtml/system_email_template_edit');
24
+ $template->setData('orig_template_used_default_for', $templateBlock->getUsedDefaultForPaths(false));
25
+
26
+ if($connectorTemplateId){
27
+ $client = Mage::helper('ddg')->getWebsiteApiClient(Mage::app()->getWebsite());
28
+ $connectorTemplate = $client->getApiTemplate($connectorTemplateId);
29
+ if(isset($connectorTemplate->id))
30
+ $template->setTemplateText($connectorTemplate->htmlContent);
31
+ $template->setTemplateStyles('');
32
+ }
33
+
34
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($template->getData()));
35
+ }
36
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Widget/ChooserController.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Adminhtml_Widget_ChooserController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+ /**
6
+ * ajax handler for product chooser
7
+ */
8
+ public function productAction()
9
+ {
10
+ $block = $this->getLayout()->createBlock(
11
+ 'ddg_automation/adminhtml_widget_chooser_product', 'email_connector_chooser_product',
12
+ array('js_form_object' => $this->getRequest()->getParam('form'),
13
+ ));
14
+
15
+ if ($block) {
16
+ $this->getResponse()->setBody($block->toHtml());
17
+ }
18
+ }
19
+ }
app/code/community/Dotdigitalgroup/Email/controllers/AjaxController.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_AjaxController extends Mage_Core_Controller_Front_Action
4
+ {
5
+ public function emailcaptureAction()
6
+ {
7
+ if($this->getRequest()->getParam('email') && Mage::getSingleton('checkout/session')->getQuote()){
8
+ $email = $this->getRequest()->getParam('email');
9
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
10
+ if($quote->hasItems()){
11
+ try {
12
+ $quote->setCustomerEmail($email)->save();
13
+ Mage::helper('ddg')->log('ajax emailCapture email: '. $email);
14
+ }catch(Exception $e){
15
+ Mage::logException($e);
16
+ Mage::helper('ddg')->log('ajax emailCapture fail for email: '. $email);
17
+ }
18
+ }
19
+ }
20
+ }
21
+ }
app/code/community/Dotdigitalgroup/Email/controllers/CreditmemoController.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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('ddg_automation/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('ddg_automation/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
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
23
+ }
24
+
25
+ /**
26
+ * New guest action.
27
+ */
28
+ public function newguestAction()
29
+ {
30
+ $this->loadLayout();
31
+ $invoice = $this->getLayout()->createBlock('ddg_automation/order_invoice', 'connector_creditmemo_guest', array(
32
+ 'template' => 'connector/creditmemo/newguest.phtml'
33
+ ));
34
+ $this->getLayout()->getBlock('content')->append($invoice);
35
+ $items = $this->getLayout()->createBlock('ddg_automation/order_creditmemo', 'connector_creditmemo_items', array(
36
+ 'template' => 'connector/creditmemo/items.phtml'
37
+ ));
38
+ $this->getLayout()->getBlock('connector_creditmemo_guest')->append($items);
39
+ $this->renderLayout();
40
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
41
+ }
42
+
43
+ /**
44
+ * update creditmemo.
45
+ */
46
+ public function updateAction()
47
+ {
48
+ $this->loadLayout();
49
+ $newOrder = $this->getLayout()->createBlock('ddg_automation/order_creditmemo', 'connector_creditmemo_update', array(
50
+ 'template' => 'connector/creditmemo/update.phtml'
51
+ ));
52
+ $this->getLayout()->getBlock('content')->append($newOrder);
53
+ $this->renderLayout();
54
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
55
+ }
56
+
57
+ /**
58
+ * update guest.
59
+ */
60
+ public function updateguestAction()
61
+ {
62
+ $this->loadLayout();
63
+ $newOrder = $this->getLayout()->createBlock('ddg_automation/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
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
69
+ }
70
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Customer/NewsletterController.php ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Customer_NewsletterController extends Mage_Core_Controller_Front_Action
4
+ {
5
+
6
+ /**
7
+ * Check customer authentication
8
+ */
9
+ public function preDispatch()
10
+ {
11
+ parent::preDispatch();
12
+
13
+ if (!$this->getRequest()->isDispatched()) {
14
+ return;
15
+ }
16
+ if (!$this->_getCustomerSession()->authenticate($this)) {
17
+ $this->setFlag('', 'no-dispatch', true);
18
+ }
19
+ }
20
+
21
+ /**
22
+ * get customer session
23
+ *
24
+ * @return Mage_Customer_Model_Session
25
+ */
26
+ protected function _getCustomerSession()
27
+ {
28
+ return Mage::getSingleton('customer/session');
29
+ }
30
+
31
+ /**
32
+ * save action
33
+ *
34
+ * @return Mage_Core_Controller_Varien_Action
35
+ * @throws Mage_Core_Exception
36
+ */
37
+ public function saveAction()
38
+ {
39
+ if (!$this->_validateFormKey()) {
40
+ return $this->_redirect('customer/account/');
41
+ }
42
+ //params
43
+ $additional_subscriptions = Mage::app()->getRequest()->getParam('additional_subscriptions');
44
+ $data_fields = Mage::app()->getRequest()->getParam('data_fields');
45
+ $customer_id = Mage::app()->getRequest()->getParam('connector_customer_id');
46
+ $customer_email = Mage::app()->getRequest()->getParam('connector_customer_email');
47
+
48
+ //client
49
+ $website = Mage::getModel('customer/session')->getCustomer()->getStore()->getWebsite();
50
+ $client = Mage::getModel('ddg_automation/apiconnector_client');
51
+ $client->setApiUsername(Mage::helper('ddg')->getApiUsername($website))
52
+ ->setApiPassword(Mage::helper('ddg')->getApiPassword($website));
53
+
54
+ $contact = $client->getContactById($customer_id);
55
+ if(isset($contact->id)){
56
+ //contact data fields
57
+ $data = array();
58
+ $dataFields = $client->getDataFields();
59
+ $processedFields = array();
60
+ foreach($dataFields as $dataField){
61
+ $processedFields[$dataField->name] = $dataField->type;
62
+ }
63
+ foreach($data_fields as $key => $value){
64
+ if(isset($processedFields[$key]) && $value){
65
+ if($processedFields[$key] == 'Numeric'){
66
+ $data_fields[$key] = (int)$value;
67
+ }
68
+ if($processedFields[$key] == 'String'){
69
+ $data_fields[$key] = (string)$value;
70
+ }
71
+ if($processedFields[$key] == 'Date'){
72
+ $date = new Zend_Date($value, "Y/M/d");
73
+ $data_fields[$key] = $date->toString(Zend_Date::ISO_8601);
74
+ }
75
+ $data[] = array(
76
+ 'Key' => $key,
77
+ 'Value' => $data_fields[$key]
78
+ );
79
+ }
80
+ }
81
+ $contactResponse = $client->updateContactDatafieldsByEmail($customer_email, $data);
82
+
83
+ //contact address books
84
+ $bookError = false;
85
+ $addressBooks = $client->getContactAddressBooks($contact->id);
86
+ $subscriberAddressBook = Mage::helper('ddg')->getSubscriberAddressBook(Mage::app()->getWebsite());
87
+ $processedAddressBooks = array();
88
+ if(is_array($addressBooks)){
89
+ foreach($addressBooks as $addressBook){
90
+ if($subscriberAddressBook != $addressBook->id)
91
+ $processedAddressBooks[$addressBook->id] = $addressBook->name;
92
+ }
93
+ }
94
+ if(isset($additional_subscriptions)){
95
+ foreach($additional_subscriptions as $additional_subscription){
96
+ if(!isset($processedAddressBooks[$additional_subscription])){
97
+ $bookResponse = $client->postAddressBookContacts($additional_subscription, $contact);
98
+ if(isset($bookResponse->message))
99
+ $bookError = true;
100
+
101
+ }
102
+ }
103
+ foreach($processedAddressBooks as $bookId => $name){
104
+ if(!in_array($bookId, $additional_subscriptions)) {
105
+ $bookResponse = $client->deleteAddressBookContact($bookId, $contact->id);
106
+ if(isset($bookResponse->message))
107
+ $bookError = true;
108
+ }
109
+ }
110
+ }
111
+ else{
112
+ foreach($processedAddressBooks as $bookId => $name){
113
+ $bookResponse = $client->deleteAddressBookContact($bookId, $contact->id);
114
+ if(isset($bookResponse->message))
115
+ $bookError = true;
116
+ }
117
+ }
118
+
119
+ if(isset($contactResponse->message) && $bookError)
120
+ Mage::getSingleton('customer/session')->addError($this->__('An error occurred while saving your subscription preferences.'));
121
+ else
122
+ Mage::getSingleton('customer/session')->addSuccess($this->__('The subscription preferences has been saved.'));
123
+ }
124
+ else{
125
+ Mage::getSingleton('customer/session')->addError($this->__('An error occurred while saving your subscription preferences.'));
126
+ }
127
+ $this->_redirect('customer/account/');
128
+ }
129
+ }
app/code/community/Dotdigitalgroup/Email/controllers/DynamicContentController.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once 'Dotdigitalgroup' . DS . 'Email' . DS . 'controllers' . DS . 'ResponseController.php';
3
+
4
+ class Dotdigitalgroup_Email_DynamicContentController extends Dotdigitalgroup_Email_ResponseController
5
+ {
6
+ /**
7
+ * @return Mage_Core_Controller_Front_Action|void
8
+ * @throws Exception
9
+ */
10
+ public function preDispatch()
11
+ {
12
+ //authenticate
13
+ $this->authenticate();
14
+
15
+ $orderId = $this->getRequest()->getParam('order_id', false);
16
+ //check for order_id param
17
+ if ($orderId) {
18
+ $order = Mage::getModel('sales/order')->load($orderId);
19
+ //check if the order still exists
20
+ if ($order->getId()) {
21
+ $storeId = $order->getStoreId();
22
+ //start the emulation for order store
23
+ $appEmulation = Mage::getSingleton('core/app_emulation');
24
+ $appEmulation->startEnvironmentEmulation($storeId);
25
+ } else {
26
+ //throw new Exception('TE invoice : order not found: ' . $orderId);
27
+ Mage::helper('ddg')->log('TE invoice : order not found: ' . $orderId);
28
+ $this->sendResponse();
29
+ die;
30
+ }
31
+ } else {
32
+ //throw new Exception('TE invoice : order_id missing :' . $orderId);
33
+ Mage::helper('ddg')->log('TE invoice : order_id missing :' . $orderId);
34
+ $this->sendResponse();
35
+ die;
36
+ }
37
+ parent::preDispatch();
38
+ }
39
+ }
app/code/community/Dotdigitalgroup/Email/controllers/EmailController.php ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once 'Dotdigitalgroup' . DS . 'Email' . DS . 'controllers' . DS . 'ResponseController.php';
3
+
4
+ class Dotdigitalgroup_Email_EmailController extends Dotdigitalgroup_Email_ResponseController
5
+ {
6
+ /**
7
+ * wishlist
8
+ */
9
+ public function wishlistAction()
10
+ {
11
+ //authenticate
12
+ $this->authenticate();
13
+ $this->loadLayout();
14
+ $wishlist = $this->getLayout()->createBlock('ddg_automation/wishlist', 'connector_wishlist', array(
15
+ 'template' => 'connector/wishlist.phtml'
16
+ ));
17
+ $this->getLayout()->getBlock('content')->append($wishlist);
18
+ $this->renderLayout();
19
+ $this->checkContentNotEmpty($wishlist->toHtml(), false);
20
+ }
21
+
22
+ /**
23
+ * Generate coupon for a coupon code id.
24
+ */
25
+ public function couponAction()
26
+ {
27
+ $this->authenticate();
28
+ $this->loadLayout();
29
+ //page root template
30
+ if ($root = $this->getLayout()->getBlock('root')) {
31
+ $root->setTemplate('page/blank.phtml');
32
+ }
33
+ //content template
34
+ $coupon = $this->getLayout()->createBlock('ddg_automation/coupon', 'connector_coupon', array(
35
+ 'template' => 'connector/coupon.phtml'
36
+ ));
37
+ $this->checkContentNotEmpty($coupon->toHtml(), false);
38
+ $this->getLayout()->getBlock('content')->append($coupon);
39
+ $this->renderLayout();
40
+ }
41
+
42
+ /**
43
+ * Basket page to display the user items with specific email.
44
+ */
45
+ public function basketAction()
46
+ {
47
+ //authenticate
48
+ $this->authenticate();
49
+ $this->loadLayout();
50
+ if ($root = $this->getLayout()->getBlock('root')) {
51
+ $root->setTemplate('page/blank.phtml');
52
+ }
53
+ $basket = $this->getLayout()->createBlock('ddg_automation/basket', 'connector_basket', array(
54
+ 'template' => 'connector/basket.phtml'
55
+ ));
56
+ $this->getLayout()->getBlock('content')->append($basket);
57
+ $this->renderLayout();
58
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
59
+ }
60
+
61
+ public function reviewAction()
62
+ {
63
+ //authenticate
64
+ $this->authenticate();
65
+ $this->loadLayout();
66
+ $review = $this->getLayout()->createBlock('ddg_automation/order', 'connector_review', array(
67
+ 'template' => 'connector/review.phtml'
68
+ ));
69
+ $this->getLayout()->getBlock('content')->append($review);
70
+ $this->renderLayout();
71
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
72
+ }
73
+
74
+
75
+ /**
76
+ * Callback action for the automation studio.
77
+ */
78
+ public function callbackAction()
79
+ {
80
+ $code = $this->getRequest()->getParam('code', false);
81
+ $userId = $this->getRequest()->getParam('state');
82
+ $adminUser = Mage::getModel('admin/user')->load($userId);
83
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB, true);
84
+
85
+ //callback url
86
+ $callback = $baseUrl . 'connector/email/callback';
87
+
88
+ if ($code) {
89
+ $data = 'client_id=' . Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CLIENT_ID) .
90
+ '&client_secret=' . Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CLIENT_SECRET_ID) .
91
+ '&redirect_uri=' . $callback .
92
+ '&grant_type=authorization_code' .
93
+ '&code=' . $code;
94
+
95
+
96
+ $url = Mage::helper('ddg/config')->getTokenUrl();
97
+ $ch = curl_init();
98
+ curl_setopt($ch, CURLOPT_URL, $url);
99
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
100
+ curl_setopt($ch, CURLOPT_TIMEOUT, 10);
101
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
102
+ curl_setopt($ch, CURLOPT_POST, count($data));
103
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
104
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array ('Content-Type: application/x-www-form-urlencoded'));
105
+
106
+
107
+ $response = json_decode(curl_exec($ch));
108
+ if ($response === false) {
109
+ Mage::helper('ddg')->rayLog('100', 'Automaion studio number not found : ' . serialize($response));
110
+ Mage::helper('ddg')->log("Error Number: " . curl_errno($ch));
111
+ }
112
+
113
+ //save the refresh token to the admin user
114
+ $adminUser->setRefreshToken($response->refresh_token)->save();
115
+ }
116
+ //redirect to automation index page
117
+ $this->_redirectReferer(Mage::helper('adminhtml')->getUrl('adminhtml/email_automation/index'));
118
+ }
119
+ }
app/code/community/Dotdigitalgroup/Email/controllers/FeefoController.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once 'Dotdigitalgroup' . DS . 'Email' . DS . 'controllers' . DS . 'ResponseController.php';
3
+
4
+ class Dotdigitalgroup_Email_FeefoController extends Dotdigitalgroup_Email_ResponseController
5
+ {
6
+ /**
7
+ * @return Mage_Core_Controller_Front_Action|void
8
+ */
9
+ public function preDispatch()
10
+ {
11
+ $helper = Mage::helper('ddg');
12
+ //authenticate
13
+ $this->authenticate();
14
+
15
+ $actionName = $this->getRequest()->getActionName();
16
+ switch ($actionName) {
17
+ case 'score':
18
+ if(!$helper->getFeefoLogon()){
19
+ $this->sendResponse();
20
+ die;
21
+ }
22
+ break;
23
+ case 'reviews':
24
+ if(!$helper->getFeefoLogon() or !Mage::app()->getRequest()->getParam('quote_id')){
25
+ $this->sendResponse();
26
+ die;
27
+ }
28
+ break;
29
+ }
30
+
31
+ parent::preDispatch();
32
+ }
33
+
34
+ /**
35
+ * show customer's score logo
36
+ */
37
+ public function scoreAction()
38
+ {
39
+ $this->loadLayout();
40
+
41
+ $block = $this->getLayout()->createBlock('ddg_automation/feefo', 'connector_feefo_service_score', array(
42
+ 'template' => 'connector/feefo/score.phtml'
43
+ ));
44
+ $this->getLayout()->getBlock('content')->append($block);
45
+ $this->checkContentNotEmpty($block->toHtml(), false);
46
+ $this->renderLayout();
47
+ }
48
+
49
+ /**
50
+ * show product reviews
51
+ */
52
+ public function reviewsAction()
53
+ {
54
+ $this->loadLayout();
55
+
56
+ $block = $this->getLayout()->createBlock('ddg_automation/feefo', 'connector_feefo_product_reviews', array(
57
+ 'template' => 'connector/feefo/reviews.phtml'
58
+ ));
59
+ $this->getLayout()->getBlock('content')->append($block);
60
+ $this->renderLayout();
61
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
62
+ }
63
+ }
app/code/community/Dotdigitalgroup/Email/controllers/InvoiceController.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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('ddg_automation/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('ddg_automation/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
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
24
+ }
25
+
26
+ /**
27
+ * New guest invoice.
28
+ */
29
+ public function newguestAction()
30
+ {
31
+ $this->loadLayout();
32
+ $invoiceGuest = $this->getLayout()->createBlock('ddg_automation/order_invoice', 'connector_invoiceguest_new', array(
33
+ 'template' => 'connector/invoice/newguest.phtml'
34
+ ));
35
+
36
+ $this->getLayout()->getBlock('content')->append($invoiceGuest);
37
+ $items = $this->getLayout()->createBlock('ddg_automation/order_invoice', 'connector_order_items', array(
38
+ 'template' => 'connector/order/items.phtml'
39
+ ));
40
+ //set invoice items
41
+ $this->getLayout()->getBlock('connector_invoiceguest_new')->append($items);
42
+ $this->renderLayout();
43
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
44
+ }
45
+
46
+ /**
47
+ * Invoice update information.
48
+ */
49
+ public function updateAction()
50
+ {
51
+ $this->loadLayout();
52
+ $invoice = $this->getLayout()->createBlock('ddg_automation/order_invoice', 'connector_invoice_update', array(
53
+ 'template' => 'connector/invoice/update.phtml'
54
+ ));
55
+ //set invoice content
56
+ $this->getLayout()->getBlock('content')->append($invoice);
57
+ $this->renderLayout();
58
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
59
+ }
60
+
61
+ /**
62
+ * Invoice guest.
63
+ */
64
+ public function updateguestAction()
65
+ {
66
+ $this->loadLayout();
67
+ $invoice = $this->getLayout()->createBlock('ddg_automation/order_invoice', 'connector_invoice_updateguest', array(
68
+ 'template' => 'connector/invoice/updateguest.phtml'
69
+ ));
70
+ //set invoice content
71
+ $this->getLayout()->getBlock('content')->append($invoice);
72
+ $this->renderLayout();
73
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
74
+ }
75
+ }
app/code/community/Dotdigitalgroup/Email/controllers/OrderController.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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('ddg_automation/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('ddg_automation/order', 'connector_order_items', array(
19
+ 'template' => 'connector/order/items.phtml'
20
+ ));
21
+ $this->getLayout()->getBlock('connector_order')->append($items);
22
+ $this->renderLayout();
23
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
24
+ }
25
+
26
+ /**
27
+ * New order for guest.
28
+ */
29
+ public function newguestAction()
30
+ {
31
+ $this->loadLayout();
32
+ //set content template
33
+ $newGuestOrder = $this->getLayout()->createBlock('ddg_automation/order', 'connector_order_guest', array(
34
+ 'template' => 'connector/order/newguest.phtml'
35
+ ));
36
+ $this->getLayout()->getBlock('content')->append($newGuestOrder);
37
+ //set the items for this order
38
+ $items = $this->getLayout()->createBlock('ddg_automation/order', 'connector_order_items', array(
39
+ 'template' => 'connector/order/items.phtml'
40
+ ));
41
+ $this->getLayout()->getBlock('connector_order_guest')->append($items);
42
+ $this->renderLayout();
43
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
44
+ }
45
+
46
+ /**
47
+ * Show order update information.
48
+ */
49
+ public function updateAction()
50
+ {
51
+ $this->loadLayout();
52
+ //set content template
53
+ $newOrder = $this->getLayout()->createBlock('ddg_automation/order', 'connector_order_update', array(
54
+ 'template' => 'connector/order/update.phtml'
55
+ ));
56
+ $this->getLayout()->getBlock('content')->append($newOrder);
57
+ $this->renderLayout();
58
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
59
+ }
60
+
61
+ /**
62
+ * Show order update for guest.
63
+ */
64
+ public function updateguestAction()
65
+ {
66
+ $this->loadLayout();
67
+ //set the content template
68
+ $newOrder = $this->getLayout()->createBlock('ddg_automation/order', 'connector_order_update_guest', array(
69
+ 'template' => 'connector/order/updateguest.phtml'
70
+ ));
71
+ $this->getLayout()->getBlock('content')->append($newOrder);
72
+ $this->renderLayout();
73
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
74
+ }
75
+ }
app/code/community/Dotdigitalgroup/Email/controllers/ProductsController.php ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once 'Dotdigitalgroup' . DS . 'Email' . DS . 'controllers' . DS . 'ResponseController.php';
3
+
4
+ class Dotdigitalgroup_Email_ProductsController extends Dotdigitalgroup_Email_ResponseController
5
+ {
6
+ /**
7
+ * @return Mage_Core_Controller_Front_Action|void
8
+ */
9
+ public function preDispatch()
10
+ {
11
+ //authenticate
12
+ $this->authenticate();
13
+ //skip order_id check for this actions
14
+ $skip = array('push', 'nosto');
15
+ $actionName = $this->getRequest()->getActionName();
16
+ if (! in_array($actionName, $skip)) {
17
+ $orderId = $this->getRequest()->getParam('order_id', false);
18
+ //check for order id param
19
+ if ($orderId) {
20
+ //check if order still exists
21
+ $order = Mage::getModel('sales/order')->load($orderId);
22
+ if ($order->getId()) {
23
+ //start app emulation
24
+ $storeId = $order->getStoreId();
25
+ $appEmulation = Mage::getSingleton('core/app_emulation');
26
+ $appEmulation->startEnvironmentEmulation($storeId);
27
+ } else {
28
+ $message = 'Dynamic : order not found: ' . $orderId;
29
+ Mage::helper('ddg')->log($message);
30
+ Mage::helper('ddg')->rayLog('100', $message);
31
+ }
32
+ } else {
33
+ Mage::helper('ddg')->log('Dynamic : order_id missing :' . $orderId);
34
+ }
35
+ }
36
+
37
+ parent::preDispatch();
38
+ }
39
+
40
+ /**
41
+ * Related products.
42
+ */
43
+ public function relatedAction()
44
+ {
45
+ $this->loadLayout();
46
+ $products = $this->getLayout()->createBlock('ddg_automation/recommended_products', 'connector_recommended_related', array(
47
+ 'template' => 'connector/product/list.phtml'
48
+ ));
49
+ //append related products
50
+ $this->getLayout()->getBlock('content')->append($products);
51
+
52
+ $this->renderLayout();
53
+
54
+ }
55
+
56
+ /**
57
+ * Crosssell products.
58
+ */
59
+ public function crosssellAction()
60
+ {
61
+ $this->loadLayout();
62
+ $products = $this->getLayout()->createBlock('ddg_automation/recommended_products', 'connector_recommended_crosssell', array(
63
+ 'template' => 'connector/product/list.phtml'
64
+ ));
65
+ //append crosssell products.
66
+ $this->getLayout()->getBlock('content')->append($products);
67
+
68
+ $this->renderLayout();
69
+ }
70
+
71
+ /**
72
+ * Upsell products.
73
+ */
74
+ public function upsellAction()
75
+ {
76
+ $this->loadLayout();
77
+ $products = $this->getLayout()->createBlock('ddg_automation/recommended_products', 'connector_recommended_upsell', array(
78
+ 'template' => 'connector/product/list.phtml'
79
+ ));
80
+ //append upsell products
81
+ $this->getLayout()->getBlock('content')->append($products);
82
+
83
+ $this->renderLayout();
84
+ }
85
+
86
+ /**
87
+ * Products that are set to manually push as related.
88
+ */
89
+ public function pushAction()
90
+ {
91
+ $this->loadLayout();
92
+ $products = $this->getLayout()->createBlock('ddg_automation/recommended_push', 'connector_product_push', array(
93
+ 'template' => 'connector/product/list.phtml'
94
+ ));
95
+ //append push products
96
+ $this->getLayout()->getBlock('content')->append($products);
97
+ $this->renderLayout();
98
+ }
99
+
100
+ /**
101
+ * Nosto recommendation action.
102
+ */
103
+ public function nostoAction()
104
+ {
105
+ $this->loadLayout();
106
+
107
+ $products = $this->getLayout()->createBlock('ddg_automation/recommended_products', 'connector_nosto_recommended', array(
108
+ 'template' => 'connector/product/nosto.phtml'
109
+ ));
110
+ $this->getLayout()->getBlock('content')->append($products);
111
+ $this->renderLayout();
112
+ }
113
+
114
+ }
app/code/community/Dotdigitalgroup/Email/controllers/QuoteproductsController.php ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once 'Dotdigitalgroup' . DS . 'Email' . DS . 'controllers' . DS . 'ResponseController.php';
3
+
4
+ class Dotdigitalgroup_Email_QuoteproductsController extends Dotdigitalgroup_Email_ResponseController
5
+ {
6
+ /**
7
+ * @return Mage_Core_Controller_Front_Action|void
8
+ */
9
+ public function preDispatch()
10
+ {
11
+ //authenticate
12
+ $this->authenticate();
13
+ if ($this->getRequest()->getActionName() != 'push') {
14
+ $quoteId = $this->getRequest()->getParam('quote_id', false);
15
+ //check for quote id param
16
+ if ($quoteId) {
17
+ //check if quote exists
18
+ $quote = Mage::getModel('sales/quote')->load($quoteId);
19
+ if ($quote->getId()) {
20
+ //start app emulation
21
+ $storeId = $quote->getStoreId();
22
+ $appEmulation = Mage::getSingleton('core/app_emulation');
23
+ $appEmulation->startEnvironmentEmulation($storeId);
24
+ } else {
25
+ $message = 'Dynamic : Quote not found: ' . $quoteId;
26
+ Mage::helper('ddg')->log($message);
27
+ Mage::helper('ddg')->rayLog('100', $message);
28
+ }
29
+ } else {
30
+ Mage::helper('ddg')->log('Dynamic : order_id missing :' . $quoteId);
31
+ }
32
+ }
33
+
34
+ parent::preDispatch();
35
+ }
36
+
37
+ /**
38
+ * Related products.
39
+ */
40
+ public function relatedAction()
41
+ {
42
+ $this->loadLayout();
43
+ $products = $this->getLayout()->createBlock('ddg_automation/recommended_quoteproducts', 'connector_recommended_quote_related', array(
44
+ 'template' => 'connector/product/list.phtml'
45
+ ));
46
+ //append related products
47
+ $this->getLayout()->getBlock('content')->append($products);
48
+ $this->renderLayout();
49
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
50
+ }
51
+
52
+ /**
53
+ * Crosssell products.
54
+ */
55
+ public function crosssellAction()
56
+ {
57
+ $this->loadLayout();
58
+ $products = $this->getLayout()->createBlock('ddg_automation/recommended_quoteproducts', 'connector_recommended_quote_crosssell', array(
59
+ 'template' => 'connector/product/list.phtml'
60
+ ));
61
+ //append crosssell products.
62
+ $this->getLayout()->getBlock('content')->append($products);
63
+ $this->renderLayout();
64
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
65
+ }
66
+
67
+ /**
68
+ * Upsell products.
69
+ */
70
+ public function upsellAction()
71
+ {
72
+ $this->loadLayout();
73
+ $products = $this->getLayout()->createBlock('ddg_automation/recommended_quoteproducts', 'connector_recommended_quote_upsell', array(
74
+ 'template' => 'connector/product/list.phtml'
75
+ ));
76
+ //append upsell products
77
+ $this->getLayout()->getBlock('content')->append($products);
78
+ $this->renderLayout();
79
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
80
+ }
81
+
82
+ /**
83
+ * Products that are set to manually push as related.
84
+ */
85
+ public function pushAction()
86
+ {
87
+ $this->loadLayout();
88
+ $products = $this->getLayout()->createBlock('ddg_automation/recommended_push', 'connector_product_push', array(
89
+ 'template' => 'connector/product/list.phtml'
90
+ ));
91
+ //append push products
92
+ $this->getLayout()->getBlock('content')->append($products);
93
+ $this->renderLayout();
94
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
95
+ }
96
+ }
app/code/community/Dotdigitalgroup/Email/controllers/ReportController.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once 'Dotdigitalgroup' . DS . 'Email' . DS . 'controllers' . DS . 'ResponseController.php';
3
+
4
+
5
+ class Dotdigitalgroup_Email_ReportController extends Dotdigitalgroup_Email_ResponseController
6
+ {
7
+ /**
8
+ * @return Mage_Core_Controller_Front_Action|void
9
+ */
10
+ public function preDispatch()
11
+ {
12
+ //authenticate
13
+ $this->authenticate();
14
+ parent::preDispatch();
15
+ }
16
+
17
+ /**
18
+ * Bestsellers report.
19
+ */
20
+ public function bestsellersAction()
21
+ {
22
+ $this->loadLayout();
23
+ //set the content template
24
+ $products = $this->getLayout()->createBlock('ddg_automation/recommended_bestsellers', 'connector_customer', array(
25
+ 'template' => 'connector/product/list.phtml'
26
+ ));
27
+ $this->getLayout()->getBlock('content')->append($products);
28
+ $this->renderLayout();
29
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
30
+ }
31
+
32
+ /**
33
+ * Most viewed report.
34
+ */
35
+ public function mostviewedAction()
36
+ {
37
+ $this->loadLayout();
38
+ //set the content template
39
+ $products = $this->getLayout()->createBlock('ddg_automation/recommended_mostviewed', 'connector_customer', array(
40
+ 'template' => 'connector/product/list.phtml'
41
+ ));
42
+ $this->getLayout()->getBlock('content')->append($products);
43
+ $this->renderLayout();
44
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
45
+ }
46
+
47
+ /**
48
+ * Recently viewed products for customer.
49
+ */
50
+ public function recentlyviewedAction()
51
+ {
52
+ //customer id param
53
+ $customerId = $this->getRequest()->getParam('customer_id');
54
+ //no customer was found
55
+ if (! $customerId) {
56
+ //throw new Exception('Recentlyviewed : no customer id : ' . $customerId);
57
+ Mage::helper('ddg')->log('Recentlyviewed : no customer id : ' . $customerId);
58
+ $this->sendResponse();
59
+ die;
60
+ }
61
+ $this->loadLayout();
62
+ //set content template
63
+ $products = $this->getLayout()->createBlock('ddg_automation/recommended_recentlyviewed', 'connector_customer', array(
64
+ 'template' => 'connector/product/list.phtml'
65
+ ));
66
+ $this->getLayout()->getBlock('content')->append($products);
67
+ $this->renderLayout();
68
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
69
+ }
70
+ }
app/code/community/Dotdigitalgroup/Email/controllers/ResponseController.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_ResponseController extends Mage_Core_Controller_Front_Action
4
+ {
5
+ protected function authenticate()
6
+ {
7
+ //authenticate
8
+ $auth = Mage::helper('ddg')->auth($this->getRequest()->getParam('code'));
9
+ if(!$auth){
10
+ $this->sendResponse();
11
+ die;
12
+ }
13
+ }
14
+
15
+ protected function checkContentNotEmpty($output, $flag = true)
16
+ {
17
+ try{
18
+ if(strlen($output) < 3 && $flag == false)
19
+ $this->sendResponse();
20
+ elseif($flag && !strpos($output, '<table'))
21
+ $this->sendResponse();
22
+ } catch (Exception $e) {
23
+ Mage::logException($e);
24
+ throw new Exception($e->getMessage());
25
+ }
26
+ }
27
+
28
+ protected function sendResponse()
29
+ {
30
+ try{
31
+ $this->getResponse()
32
+ ->setHttpResponseCode(204)
33
+ ->setHeader('Pragma', 'public', true)
34
+ ->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true)
35
+ ->setHeader('Content-type', 'text/html; charset=UTF-8', true);
36
+ $this->getResponse()->sendHeaders();
37
+ } catch (Exception $e) {
38
+ Mage::logException($e);
39
+ throw new Exception($e->getMessage());
40
+ }
41
+ }
42
+ }
app/code/community/Dotdigitalgroup/Email/controllers/ShippingController.php ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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('ddg_automation/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('ddg_automation/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('ddg_automation/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
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
29
+ }
30
+
31
+ /**
32
+ * New shipping for guest.
33
+ */
34
+ public function newguestAction()
35
+ {
36
+ $this->loadLayout();
37
+ //set content template
38
+ $newOrder = $this->getLayout()->createBlock('ddg_automation/order_shipping', 'connector_shipping_newguest', array(
39
+ 'template' => 'connector/shipping/newguest.phtml'
40
+ ));
41
+ $this->getLayout()->getBlock('content')->append($newOrder);
42
+ //set content items
43
+ $items = $this->getLayout()->createBlock('ddg_automation/order', 'connector_shipping_items', array(
44
+ 'template' => 'connector/order/items.phtml'
45
+ ));
46
+ //new guest shipping items
47
+ $this->getLayout()->getBlock('connector_shipping_newguest')->append($items);
48
+ //rewrite the items to dislpay the shipped ones
49
+ $items = $this->getLayout()->createBlock('ddg_automation/order_shipping', 'connector_shipping_track', array(
50
+ 'template' => 'email/order/shipment/track.phtml'
51
+ ));
52
+ //items that was shipped
53
+ $this->getLayout()->getBlock('connector_shipping_newguest')->append($items);
54
+ $this->renderLayout();
55
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
56
+ }
57
+
58
+ /**
59
+ * Shipping update for this order.
60
+ */
61
+ public function updateAction()
62
+ {
63
+ $this->loadLayout();
64
+ //set the content template
65
+ $shippingUpdate = $this->getLayout()->createBlock('ddg_automation/order_shipping', 'connector_shipping_update', array(
66
+ 'template' => 'connector/shipping/update.phtml'
67
+ ));
68
+ //shipping update content
69
+ $this->getLayout()->getBlock('content')->append($shippingUpdate);
70
+ $this->renderLayout();
71
+ $this->checkContentNotEmpty($shippingUpdate->toHtml());
72
+ }
73
+
74
+ /**
75
+ * Shipping update for guests.
76
+ */
77
+ public function updateguestAction()
78
+ {
79
+ $this->loadLayout();
80
+ $shippingGuest = $this->getLayout()->createBlock('ddg_automation/order_shipping', 'connector_shipping_updateguest', array(
81
+ 'template' => 'connector/shipping/updateguest.phtml'
82
+ ));
83
+ //set shipping content
84
+ $this->getLayout()->getBlock('content')->append($shippingGuest);
85
+ $this->renderLayout();
86
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
87
+ }
88
+ }
app/code/community/Dotdigitalgroup/Email/controllers/WishlistController.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once 'Dotdigitalgroup' . DS . 'Email' . DS . 'controllers' . DS . 'ResponseController.php';
3
+
4
+ class Dotdigitalgroup_Email_WishlistController extends Dotdigitalgroup_Email_ResponseController
5
+ {
6
+ /**
7
+ * Related products.
8
+ */
9
+ public function relatedAction()
10
+ {
11
+ $this->loadLayout();
12
+ $products = $this->getLayout()->createBlock('ddg_automation/recommended_wishlistproducts', 'connector_recommended_wishlist_related', array(
13
+ 'template' => 'connector/product/list.phtml'
14
+ ));
15
+ //append related products
16
+ $this->getLayout()->getBlock('content')->append($products);
17
+ $this->renderLayout();
18
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
19
+ }
20
+
21
+ /**
22
+ * Crosssell products.
23
+ */
24
+ public function crosssellAction()
25
+ {
26
+ $this->loadLayout();
27
+ $products = $this->getLayout()->createBlock('ddg_automation/recommended_wishlistproducts', 'connector_recommended_wishlist_crosssell', array(
28
+ 'template' => 'connector/product/list.phtml'
29
+ ));
30
+ //append crosssell products.
31
+ $this->getLayout()->getBlock('content')->append($products);
32
+ $this->renderLayout();
33
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
34
+ }
35
+
36
+ /**
37
+ * Upsell products.
38
+ */
39
+ public function upsellAction()
40
+ {
41
+ $this->loadLayout();
42
+ $products = $this->getLayout()->createBlock('ddg_automation/recommended_wishlistproducts', 'connector_recommended_wishlist_upsell', array(
43
+ 'template' => 'connector/product/list.phtml'
44
+ ));
45
+ //append upsell products
46
+ $this->getLayout()->getBlock('content')->append($products);
47
+ $this->renderLayout();
48
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
49
+ }
50
+ }
app/code/community/Dotdigitalgroup/Email/etc/adminhtml.xml ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_studio</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>35</sort_order>
30
+ <action>adminhtml/email_campaign</action>
31
+ </email_connector_campaign>
32
+ <email_connector_contact translate="title">
33
+ <title>Contacts Sync</title>
34
+ <sort_order>10</sort_order>
35
+ <action>adminhtml/email_contact</action>
36
+ </email_connector_contact>
37
+ <email_connector_review translate="title">
38
+ <title>Review Sync</title>
39
+ <sort_order>25</sort_order>
40
+ <action>adminhtml/email_review</action>
41
+ </email_connector_review>
42
+ <email_connector_wishlist translate="title">
43
+ <title>Wishlist Sync</title>
44
+ <sort_order>30</sort_order>
45
+ <action>adminhtml/email_wishlist</action>
46
+ </email_connector_wishlist>
47
+ <email_connector_quote translate="title">
48
+ <title>Quote Sync</title>
49
+ <sort_order>22</sort_order>
50
+ <action>adminhtml/email_quote</action>
51
+ </email_connector_quote>
52
+ <email_connector_automation translate="title">
53
+ <title>Automation Status</title>
54
+ <sort_order>50</sort_order>
55
+ <action>adminhtml/email_automation</action>
56
+ </email_connector_automation>
57
+ </children>
58
+ </reports>
59
+ <email_configuration translate="title">
60
+ <title>Configuration</title>
61
+ <sort_order>40</sort_order>
62
+ <children>
63
+ <api_credentials translate="title">
64
+ <title>Api Credentials</title>
65
+ <sort_order>20</sort_order>
66
+ <action>adminhtml/system_config/edit/section/connector_api_credentials</action>
67
+ </api_credentials>
68
+ <data_mapping translate="title">
69
+ <title>Data Mapping</title>
70
+ <sort_order>30</sort_order>
71
+ <action>adminhtml/system_config/edit/section/connector_data_mapping</action>
72
+ </data_mapping>
73
+ <sync_settings translate="title">
74
+ <title>Sync Settings</title>
75
+ <sort_order>40</sort_order>
76
+ <action>adminhtml/system_config/edit/section/connector_sync_settings</action>
77
+ </sync_settings>
78
+ </children>
79
+ </email_configuration>
80
+ </children>
81
+ </email_connector>
82
+ </menu>
83
+ <acl>
84
+ <resources>
85
+ <admin>
86
+ <children>
87
+ <email_connector>
88
+ <title>DDG Automation</title>
89
+ <children>
90
+ <email_connector_dashboard translate="title">
91
+ <title>Dashboard</title>
92
+ </email_connector_dashboard>
93
+ <automation_studio translate="title">
94
+ <title>Automation Studio</title>
95
+ </automation_studio>
96
+ <reports>
97
+ <title>Reports</title>
98
+ <children>
99
+ <email_connector_order translate="title">
100
+ <title>Email Connector Orders</title>
101
+ </email_connector_order>
102
+ <email_connector_campaign translate="title">
103
+ <title>Email Connector Campaigns</title>
104
+ </email_connector_campaign>
105
+ <email_connector_contact translate="title">
106
+ <title>Email Connector Contacts</title>
107
+ </email_connector_contact>
108
+ <email_connector_review translate="title">
109
+ <title>Email Connector Reviews</title>
110
+ </email_connector_review>
111
+ <email_connector_wishlist translate="title">
112
+ <title>Email Connector Wishlist</title>
113
+ </email_connector_wishlist>
114
+ <email_connector_quote translate="title">
115
+ <title>Email Connector Quote</title>
116
+ </email_connector_quote>
117
+ <email_connector_automation translate="title">
118
+ <title>Email Automation Status</title>
119
+ </email_connector_automation>
120
+ </children>
121
+ </reports>
122
+ <email_configuration translate="title">
123
+ <title>Email Configuration</title>
124
+ <children>
125
+ <api_credentials translate="title">
126
+ <title>Api Credentials</title>
127
+ </api_credentials>
128
+ <data_mapping translate="title">
129
+ <title>Data Mapping</title>
130
+ </data_mapping>
131
+ <sync_settings translate="title">
132
+ <title>Sync Settings</title>
133
+ </sync_settings>
134
+ </children>
135
+ </email_configuration>
136
+ </children>
137
+ </email_connector>
138
+ <system>
139
+ <children>
140
+ <config>
141
+ <children>
142
+ <connector_api_credentials translate="title">
143
+ <title><![CDATA[Email API Credentials]]></title>
144
+ </connector_api_credentials>
145
+ <connector_sync_settings translate="title">
146
+ <title><![CDATA[Email Sync Settings]]></title>
147
+ </connector_sync_settings>
148
+ <connector_data_mapping translate="title">
149
+ <title><![CDATA[Email Data Field Mapping]]></title>
150
+ </connector_data_mapping>
151
+ <connector_roi_tracking translate="title">
152
+ <title><![CDATA[Email ROI & Tracking]]></title>
153
+ </connector_roi_tracking>
154
+ <connector_lost_baskets translate="title">
155
+ <title><![CDATA[Abandoned Carts]]></title>
156
+ </connector_lost_baskets>
157
+ <connector_reviews translate="title">
158
+ <title><![CDATA[Reviews]]></title>
159
+ </connector_reviews>
160
+ <connector_sms translate="title">
161
+ <title><![CDATA[Email SMS Section]]></title>
162
+ </connector_sms>
163
+ <connector_dynamic_content translate="title">
164
+ <title><![CDATA[Email Dynamic Content]]></title>
165
+ </connector_dynamic_content>
166
+ <connector_transactional_emails translate="title">
167
+ <title><![CDATA[Email Transactional Email]]></title>
168
+ </connector_transactional_emails>
169
+ <connector_automation_studio translate="title">
170
+ <title><![CDATA[Automation Studio]]></title>
171
+ </connector_automation_studio>
172
+ <connector_configuration translate="title">
173
+ <title><![CDATA[Configuration]]></title>
174
+ </connector_configuration>
175
+ <connector_developer_settings translate="title">
176
+ <title><![CDATA[Developer]]></title>
177
+ </connector_developer_settings>
178
+ </children>
179
+ </config>
180
+ </children>
181
+ </system>
182
+ </children>
183
+ </admin>
184
+ </resources>
185
+ </acl>
186
+ </config>
app/code/community/Dotdigitalgroup/Email/etc/api2.xml ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <api2>
4
+ <resource_groups>
5
+ <ddg_automation translate="title" module="api2">
6
+ <title>DDG Automation</title>
7
+ </ddg_automation>
8
+ </resource_groups>
9
+ <resources>
10
+ <ddg_create translate="title" module="api2">
11
+ <group>ddg_automation</group>
12
+ <model>ddg_automation/api2_subscriber</model>
13
+ <working_model>ddg_automation/api2_subscriber</working_model>
14
+ <title>Subscriber</title>
15
+ <sort_order>10</sort_order>
16
+ <privileges>
17
+ <admin>
18
+ <retrieve>1</retrieve>
19
+ <create>1</create>
20
+ <update>1</update>
21
+ </admin>
22
+ </privileges>
23
+ <attributes>
24
+ <customer_id>Customer Id</customer_id>
25
+ <store_id>Store Id</store_id>
26
+ <subscriber_email>Subscriber Email</subscriber_email>
27
+ <subscriber_status>Subscriber Status</subscriber_status>
28
+ </attributes>
29
+ <routes>
30
+ <route_entity>
31
+ <route>/ddg/subscriber/:email</route>
32
+ <action_type>entity</action_type>
33
+ </route_entity>
34
+ <route_collection>
35
+ <route>/ddg/subscriber/</route>
36
+ <action_type>collection</action_type>
37
+ </route_collection>
38
+ </routes>
39
+ <versions>1</versions>
40
+ </ddg_create>
41
+ </resources>
42
+ </api2>
43
+ </config>
app/code/community/Dotdigitalgroup/Email/etc/config.xml ADDED
@@ -0,0 +1,692 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Dotdigitalgroup_Email>
5
+ <version>4.1.3</version>
6
+ </Dotdigitalgroup_Email>
7
+ </modules>
8
+ <frontend>
9
+ <routers>
10
+ <ddg_automation>
11
+ <use>standard</use>
12
+ <args>
13
+ <module>Dotdigitalgroup_Email</module>
14
+ <frontName>connector</frontName>
15
+ </args>
16
+ </ddg_automation>
17
+ </routers>
18
+ <secure_url>
19
+ <connector_customer_newsletter_save>/ddg/customer_newsletter/save</connector_customer_newsletter_save>
20
+ </secure_url>
21
+ <layout>
22
+ <updates>
23
+ <ddg_automation>
24
+ <file>connector.xml</file>
25
+ </ddg_automation>
26
+ </updates>
27
+ </layout>
28
+ <events>
29
+             <controller_action_postdispatch>
30
+                 <observers>
31
+                     <ddg_switcher>
32
+                         <class>Dotdigitalgroup_Email_Model_Controller_Observer</class>
33
+                         <method>controllerActionPostdispatch</method>
34
+                     </ddg_switcher>
35
+                 </observers>
36
+             </controller_action_postdispatch>
37
+         </events>
38
+ </frontend>
39
+ <global>
40
+ <resources>
41
+ <email_connector_setup>
42
+ <setup>
43
+ <module>Dotdigitalgroup_Email</module>
44
+ <class>Dotdigitalgroup_Email_Model_Resource_Setup</class>
45
+ </setup>
46
+ </email_connector_setup>
47
+ </resources>
48
+ <events>
49
+ <enterprise_customersegment_ids_changed>
50
+ <observers>
51
+ <ddg_customersegment_changed>
52
+ <class>Dotdigitalgroup_Email_Model_Adminhtml_Observer</class>
53
+ <method>connectorCustomerSegmentChanged</method>
54
+ </ddg_customersegment_changed>
55
+ </observers>
56
+ </enterprise_customersegment_ids_changed>
57
+ </events>
58
+ <models>
59
+ <ddg_automation>
60
+ <class>Dotdigitalgroup_Email_Model</class>
61
+ <resourceModel>email_connector_resource</resourceModel>
62
+ </ddg_automation>
63
+ <email_connector_resource>
64
+ <class>Dotdigitalgroup_Email_Model_Resource</class>
65
+ <entities>
66
+ <order>
67
+ <table>email_order</table>
68
+ </order>
69
+ <contact>
70
+ <table>email_contact</table>
71
+ </contact>
72
+ <campaign>
73
+ <table>email_campaign</table>
74
+ </campaign>
75
+ <create>
76
+ <table>email_create</table>
77
+ </create>
78
+ <config>
79
+ <table>email_config</table>
80
+ </config>
81
+ <review>
82
+ <table>email_review</table>
83
+ </review>
84
+ <wishlist>
85
+ <table>email_wishlist</table>
86
+ </wishlist>
87
+ <quote>
88
+ <table>email_quote</table>
89
+ </quote>
90
+ <automation>
91
+ <table>email_automation</table>
92
+ </automation>
93
+ </entities>
94
+ </email_connector_resource>
95
+ <newsletter>
96
+ <rewrite>
97
+ <subscriber>Dotdigitalgroup_Email_Model_Newsletter_Sub</subscriber>
98
+ </rewrite>
99
+ </newsletter>
100
+ <customer>
101
+ <rewrite>
102
+ <customer>Dotdigitalgroup_Email_Model_Customer</customer>
103
+ </rewrite>
104
+ </customer>
105
+ <enterprise_customersegment_resource>
106
+ <rewrite>
107
+ <segment>Dotdigitalgroup_Email_Model_Resource_Segment</segment>
108
+ </rewrite>
109
+ </enterprise_customersegment_resource>
110
+ </models>
111
+ <helpers>
112
+ <ddg>
113
+ <class>Dotdigitalgroup_Email_Helper</class>
114
+ </ddg>
115
+ </helpers>
116
+ <blocks>
117
+ <ddg_automation>
118
+ <class>Dotdigitalgroup_Email_Block</class>
119
+ </ddg_automation>
120
+ <adminhtml>
121
+ <rewrite>
122
+ <system_email_template_edit>Dotdigitalgroup_Email_Block_System_Email_Template_Edit</system_email_template_edit>
123
+ </rewrite>
124
+ </adminhtml>
125
+ </blocks>
126
+ <events>
127
+ <admin_system_config_changed_section_connector_api_credentials>
128
+ <observers>
129
+ <ddg_api_save>
130
+ <class>Dotdigitalgroup_Email_Model_Adminhtml_Observer</class>
131
+ <method>actionConfigSaveApi</method>
132
+ </ddg_api_save>
133
+ </observers>
134
+ </admin_system_config_changed_section_connector_api_credentials>
135
+ <admin_system_config_changed_section_connector_data_mapping>
136
+ <observers>
137
+ <ddg_data_mapping_reset>
138
+ <class>Dotdigitalgroup_Email_Model_Adminhtml_Observer</class>
139
+ <method>actionConfigResetContacts</method>
140
+ </ddg_data_mapping_reset>
141
+ </observers>
142
+ </admin_system_config_changed_section_connector_data_mapping>
143
+ <admin_system_config_changed_section_connector_sync_settings>
144
+ <observers>
145
+ <ddg_sys_check_feature_active>
146
+ <class>Dotdigitalgroup_Email_Model_Adminhtml_Observer</class>
147
+ <method>checkFeatureActive</method>
148
+ </ddg_sys_check_feature_active>
149
+ </observers>
150
+ </admin_system_config_changed_section_connector_sync_settings>
151
+ <customer_save_after>
152
+ <observers>
153
+ <ddg_customer_save_after>
154
+ <class>Dotdigitalgroup_Email_Model_Customer_Observer</class>
155
+ <method>handleCustomerSaveAfter</method>
156
+ </ddg_customer_save_after>
157
+ </observers>
158
+ </customer_save_after>
159
+ <customer_register_success>
160
+ <observers>
161
+ <ddg_customer_register_success>
162
+ <type>singleton</type>
163
+ <class>Dotdigitalgroup_Email_Model_Customer_Observer</class>
164
+ <method>handleCustomerRegiterSuccess</method>
165
+ </ddg_customer_register_success>
166
+ </observers>
167
+ </customer_register_success>
168
+ <customer_delete_after>
169
+ <observers>
170
+ <ddg_customer_delete_after>
171
+ <class>Dotdigitalgroup_Email_Model_Customer_Observer</class>
172
+ <method>handleCustomerDeleteAfter</method>
173
+ </ddg_customer_delete_after>
174
+ </observers>
175
+ </customer_delete_after>
176
+ <newsletter_subscriber_save_before>
177
+ <observers>
178
+ <ddg_newsletter_subscriber_save_before>
179
+ <class>Dotdigitalgroup_Email_Model_Newsletter_Observer</class>
180
+ <method>handleNewsletterSubscriberSave</method>
181
+ </ddg_newsletter_subscriber_save_before>
182
+ </observers>
183
+ </newsletter_subscriber_save_before>
184
+ <sales_order_place_after>
185
+ <observers>
186
+ <ddg_record_sale>
187
+ <type>singleton</type>
188
+ <class>Dotdigitalgroup_Email_Model_Sales_Observer</class>
189
+ <method>handleSalesOrderPlaceAfter</method>
190
+ </ddg_record_sale>
191
+ </observers>
192
+ </sales_order_place_after>
193
+ <sales_order_save_before>
194
+ <observers>
195
+ <ddg_sales_save_before>
196
+ <class>Dotdigitalgroup_Email_Model_Sales_Observer</class>
197
+ <method>handleSalesOrderSaveBefore</method>
198
+ </ddg_sales_save_before>
199
+ </observers>
200
+ </sales_order_save_before>
201
+ <sales_order_save_after>
202
+ <observers>
203
+ <ddg_checkout_type_onepage_save_order_after>
204
+ <class>Dotdigitalgroup_Email_Model_Sales_Observer</class>
205
+ <method>handleSalesOrderSaveAfter</method>
206
+ </ddg_checkout_type_onepage_save_order_after>
207
+ </observers>
208
+ </sales_order_save_after>
209
+ <sales_order_creditmemo_save_after>
210
+ <observers>
211
+ <ddg_sales_order_payment_refund>
212
+ <class>Dotdigitalgroup_Email_Model_Sales_Observer</class>
213
+ <method>handleSalesOrderRefund</method>
214
+ </ddg_sales_order_payment_refund>
215
+ </observers>
216
+ </sales_order_creditmemo_save_after>
217
+ <order_cancel_after>
218
+ <observers>
219
+ <ddg_sales_order_cancel>
220
+ <class>Dotdigitalgroup_Email_Model_Sales_Observer</class>
221
+ <method>hangleSalesOrderCancel</method>
222
+ </ddg_sales_order_cancel>
223
+ </observers>
224
+ </order_cancel_after>
225
+ <rewards_points_indexer_update>
226
+ <observers>
227
+ <ddg_rewards_points_indexer_update>
228
+ <class>Dotdigitalgroup_Email_Model_Sweettooth_Observer</class>
229
+ <method>ConnectorRewardsPointsIndexerUpdate</method>
230
+ </ddg_rewards_points_indexer_update>
231
+ </observers>
232
+ </rewards_points_indexer_update>
233
+ <review_save_after>
234
+ <observers>
235
+ <ddg_review_save_after>
236
+ <class>Dotdigitalgroup_Email_Model_Customer_Observer</class>
237
+ <method>reviewSaveAfter</method>
238
+ </ddg_review_save_after>
239
+ </observers>
240
+ </review_save_after>
241
+ <model_save_after>
242
+ <observers>
243
+ <ddg_wishlist_save_after>
244
+ <class>Dotdigitalgroup_Email_Model_Customer_Observer</class>
245
+ <method>wishlistSaveAfter</method>
246
+ </ddg_wishlist_save_after>
247
+ </observers>
248
+ </model_save_after>
249
+ <wishlist_item_save_after>
250
+ <observers>
251
+ <ddg_wishlist_item_save_after>
252
+ <class>Dotdigitalgroup_Email_Model_Customer_Observer</class>
253
+ <method>wishlistItemSaveAfter</method>
254
+ </ddg_wishlist_item_save_after>
255
+ </observers>
256
+ </wishlist_item_save_after>
257
+ <wishlist_delete_after>
258
+ <observers>
259
+ <ddg_wishlist_delete_after>
260
+ <class>Dotdigitalgroup_Email_Model_Customer_Observer</class>
261
+ <method>wishlistDeleteAfter</method>
262
+ </ddg_wishlist_delete_after>
263
+ </observers>
264
+ </wishlist_delete_after>
265
+ <wishlist_item_delete_after>
266
+ <observers>
267
+ <ddg_wishlist_item_delete_after>
268
+ <class>Dotdigitalgroup_Email_Model_Customer_Observer</class>
269
+ <method>wishlistItemSaveAfter</method>
270
+ </ddg_wishlist_item_delete_after>
271
+ </observers>
272
+ </wishlist_item_delete_after>
273
+ <sales_convert_quote_to_order>
274
+ <observers>
275
+ <ddg_quote_to_order>
276
+ <class>Dotdigitalgroup_Email_Model_Sales_Observer</class>
277
+ <method>handleQuoteToOrder</method>
278
+ </ddg_quote_to_order>
279
+ </observers>
280
+ </sales_convert_quote_to_order>
281
+ <sales_quote_save_after>
282
+ <observers>
283
+ <ddg_sales_quote_save_after>
284
+ <class>Dotdigitalgroup_Email_Model_Sales_Observer</class>
285
+ <method>handleQuoteSaveAfter</method>
286
+ </ddg_sales_quote_save_after>
287
+ </observers>
288
+ </sales_quote_save_after>
289
+ </events>
290
+ </global>
291
+ <adminhtml>
292
+ <layout>
293
+ <updates>
294
+ <ddg_automation>
295
+ <file>connector/email.xml</file>
296
+ </ddg_automation>
297
+ </updates>
298
+ </layout>
299
+ <events>
300
+ <controller_action_predispatch>
301
+ <observers>
302
+ <ddg_feed>
303
+ <type>singleton</type>
304
+ <class>Dotdigitalgroup_Email_Model_Adminhtml_Observer</class>
305
+ <method>updateFeed</method>
306
+ </ddg_feed>
307
+ </observers>
308
+ </controller_action_predispatch>
309
+ </events>
310
+ <translate>
311
+ <modules>
312
+ <Dotdigitalgroup_Email>
313
+ <files>
314
+ <default>Dotdigitalgroup_Email.csv</default>
315
+ </files>
316
+ </Dotdigitalgroup_Email>
317
+ </modules>
318
+ </translate>
319
+ </adminhtml>
320
+ <admin>
321
+ <routers>
322
+ <adminhtml>
323
+ <args>
324
+ <modules>
325
+ <Dotdigitalgroup_Email before="Mage_Adminhtml">Dotdigitalgroup_Email_Adminhtml</Dotdigitalgroup_Email>
326
+ </modules>
327
+ </args>
328
+ </adminhtml>
329
+ </routers>
330
+ </admin>
331
+ <crontab>
332
+ <jobs>
333
+ <ddg_automation_customer_sync>
334
+ <run><model>ddg_automation/cron::contactSync</model></run>
335
+ <schedule>
336
+ <cron_expr>*/15 * * * *</cron_expr>
337
+ </schedule>
338
+ </ddg_automation_customer_sync>
339
+ <ddg_automation_status>
340
+ <run><model>ddg_automation/cron::automationStatus</model></run>
341
+ <schedule>
342
+ <cron_expr>*/15 * * * *</cron_expr>
343
+ </schedule>
344
+ </ddg_automation_status>
345
+ <ddg_automation_subscriber_and_guest_sync>
346
+ <run><model>ddg_automation/cron::subscribersAndGuestSync</model></run>
347
+ <schedule>
348
+ <cron_expr>*/15 * * * *</cron_expr>
349
+ </schedule>
350
+ </ddg_automation_subscriber_and_guest_sync>
351
+ <ddg_automation_abandonedcarts>
352
+ <run><model>ddg_automation/cron::abandonedCarts</model></run>
353
+ <schedule>
354
+ <cron_expr>*/5 * * * *</cron_expr>
355
+ </schedule>
356
+ </ddg_automation_abandonedcarts>
357
+ <ddg_automation_reviews_and_wishlist>
358
+ <run>
359
+ <model>ddg_automation/cron::reviewsAndWishlist</model>
360
+ </run>
361
+ <schedule>
362
+ <cron_expr>0 * * * *</cron_expr>
363
+ </schedule>
364
+ </ddg_automation_reviews_and_wishlist>
365
+ <ddg_automation_campaign>
366
+ <run>
367
+ <model>ddg_automation/cron::sendEmails</model>
368
+ </run>
369
+ <schedule>
370
+ <cron_expr>*/5 * * * *</cron_expr>
371
+ </schedule>
372
+ </ddg_automation_campaign>
373
+ <ddg_automation_order_sync>
374
+ <run><model>ddg_automation/cron::orderAndQuoteSync</model></run>
375
+ <schedule>
376
+ <cron_expr>*/15 * * * *</cron_expr>
377
+ </schedule>
378
+ </ddg_automation_order_sync>
379
+ <ddg_automation_cleaner>
380
+ <run><model>ddg_automation/cron::cleaning</model></run>
381
+ <schedule>
382
+ <cron_expr>0 0 1 * * </cron_expr>
383
+ </schedule>
384
+ </ddg_automation_cleaner>
385
+ </jobs>
386
+ </crontab>
387
+ <default>
388
+ <connector_api_credentials>
389
+ <api>
390
+ <enabled>0</enabled>
391
+ <username></username>
392
+ <password></password>
393
+ </api>
394
+ <oauth>
395
+ <client_id></client_id>
396
+ <client_key></client_key>
397
+ <test_connect></test_connect>
398
+ </oauth>
399
+ </connector_api_credentials>
400
+ <connector_sync_settings>
401
+ <address_book>
402
+ <customers>0</customers>
403
+ <subscribers>0</subscribers>
404
+ <guests>0</guests>
405
+ </address_book>
406
+ <address_book_pref>
407
+ <can_change>0</can_change>
408
+ <show_books></show_books>
409
+ <can_show_fields>0</can_show_fields>
410
+ <fields_to_show></fields_to_show>
411
+ </address_book_pref>
412
+ <sync>
413
+ <contact_enabled>0</contact_enabled>
414
+ <subscriber_enabled>0</subscriber_enabled>
415
+ <order_enabled>0</order_enabled>
416
+ <wishlist_enabled>0</wishlist_enabled>
417
+ <review_enabled>0</review_enabled>
418
+ <quote_enabled>0</quote_enabled>
419
+ </sync>
420
+ <dynamic_addressbook>
421
+ <addressbook_name></addressbook_name>
422
+ </dynamic_addressbook>
423
+ </connector_sync_settings>
424
+ <connector_data_mapping>
425
+ <customer_data>
426
+ <customer_id></customer_id>
427
+ <firstname></firstname>
428
+ <lastname></lastname>
429
+ <dob></dob>
430
+ <gender></gender>
431
+ <website_name></website_name>
432
+ <store_name></store_name>
433
+ <created_at></created_at>
434
+ <last_logged_date></last_logged_date>
435
+ <customer_group></customer_group>
436
+ <review_count></review_count>
437
+ <last_review_date></last_review_date>
438
+ <subscriber_status></subscriber_status>
439
+ <billing_address_1></billing_address_1>
440
+ <billing_address_2></billing_address_2>
441
+ <billing_city></billing_city>
442
+ <billing_state></billing_state>
443
+ <billing_country></billing_country>
444
+ <billing_postcode></billing_postcode>
445
+ <billing_telephone></billing_telephone>
446
+ <delivery_address_1></delivery_address_1>
447
+ <delivery_address_2></delivery_address_2>
448
+ <delivery_city></delivery_city>
449
+ <delivery_state></delivery_state>
450
+ <delivery_country></delivery_country>
451
+ <delivery_postcode></delivery_postcode>
452
+ <delivery_telephone></delivery_telephone>
453
+ <number_of_orders></number_of_orders>
454
+ <average_order_value></average_order_value>
455
+ <total_spend></total_spend>
456
+ <last_order_date></last_order_date>
457
+ <last_order_id></last_order_id>
458
+ <total_refund></total_refund>
459
+ <most_purchased_category></most_purchased_category>
460
+ <most_purchased_brand></most_purchased_brand>
461
+ <most_frequent_purchase_day></most_frequent_purchase_day>
462
+ <most_frequent_purchase_month></most_frequent_purchase_month>
463
+ <first_category_purchased></first_category_purchased>
464
+ <last_category_purchased></last_category_purchased>
465
+ <first_brand_purchased></first_brand_purchased>
466
+ <last_brand_purchased></last_brand_purchased>
467
+ <custom_attributes></custom_attributes>
468
+ <validator></validator>
469
+ <last_increment_id></last_increment_id>
470
+ </customer_data>
471
+ <dynamic_datafield>
472
+ <datafield_name></datafield_name>
473
+ <datafield_type></datafield_type>
474
+ <datafield_default></datafield_default>
475
+ <datafield_access></datafield_access>
476
+ </dynamic_datafield>
477
+ <sweet_tooth>
478
+ <active>0</active>
479
+ <reward_point_balance></reward_point_balance>
480
+ <reward_point_pending></reward_point_pending>
481
+ <reward_point_pending_time></reward_point_pending_time>
482
+ <reward_point_on_hold></reward_point_on_hold>
483
+ <reward_point_expiration></reward_point_expiration>
484
+ <reward_point_last_earn></reward_point_last_earn>
485
+ <reward_point_last_spent></reward_point_last_spent>
486
+ </sweet_tooth>
487
+ </connector_data_mapping>
488
+ <connector_roi_tracking>
489
+ <page_tracking>
490
+ <enabled>0</enabled>
491
+ </page_tracking>
492
+ <roi_tracking>
493
+ <enabled>0</enabled>
494
+ </roi_tracking>
495
+ </connector_roi_tracking>
496
+ <connector_lost_baskets>
497
+ <customers>
498
+ <enabled_1>0</enabled_1>
499
+ <send_after_1></send_after_1>
500
+ <campaign_1></campaign_1>
501
+ <enabled_2>0</enabled_2>
502
+ <send_after_2></send_after_2>
503
+ <campaign_2></campaign_2>
504
+ <enabled_3>0</enabled_3>
505
+ <send_after_3></send_after_3>
506
+ <campaign_3></campaign_3>
507
+ </customers>
508
+ <guests>
509
+ <enabled_1>0</enabled_1>
510
+ <send_after_1></send_after_1>
511
+ <campaign_1></campaign_1>
512
+ <enabled_2>0</enabled_2>
513
+ <send_after_2></send_after_2>
514
+ <campaign_2></campaign_2>
515
+ <enabled_3>0</enabled_3>
516
+ <send_after_3></send_after_3>
517
+ <campaign_3></campaign_3>
518
+ </guests>
519
+ </connector_lost_baskets>
520
+ <connector_sms>
521
+ <sms_one>
522
+ <enabled>0</enabled>
523
+ <status></status>
524
+ <message></message>
525
+ </sms_one>
526
+ <sms_two>
527
+ <enabled>0</enabled>
528
+ <status></status>
529
+ <message></message>
530
+ </sms_two>
531
+ <sms_three>
532
+ <enabled>0</enabled>
533
+ <status></status>
534
+ <message></message>
535
+ </sms_three>
536
+ <sms_four>
537
+ <enabled>0</enabled>
538
+ <status></status>
539
+ <message></message>
540
+ </sms_four>
541
+ </connector_sms>
542
+ <connector_dynamic_content>
543
+ <products>
544
+ <related_display_type>list</related_display_type>
545
+ <related_items_to_display>2</related_items_to_display>
546
+ <upsell_display_type>list</upsell_display_type>
547
+ <upsell_items_to_display>2</upsell_items_to_display>
548
+ <crosssell_display_type>list</crosssell_display_type>
549
+ <crosssell_items_to_display>2</crosssell_items_to_display>
550
+ <bestsellers_display_type>list</bestsellers_display_type>
551
+ <bestsellers_items_to_display>2</bestsellers_items_to_display>
552
+ <bestsellers_time_period></bestsellers_time_period>
553
+ <most_viewed_display_type>list</most_viewed_display_type>
554
+ <most_viewed_items_to_display>2</most_viewed_items_to_display>
555
+ <most_viewed_time_period></most_viewed_time_period>
556
+ <recently_viewed_display_type>list</recently_viewed_display_type>
557
+ <recently_viewed_items_to_display>2</recently_viewed_items_to_display>
558
+ <review_display_type>list</review_display_type>
559
+ <wishlist_display_type>list</wishlist_display_type>
560
+ </products>
561
+ <external_dynamic_content_urls>
562
+ <passcode>secret</passcode>
563
+ <lost_basket_url></lost_basket_url>
564
+ <review_url></review_url>
565
+ <coupon_code_url></coupon_code_url>
566
+ <dynamic_content_url></dynamic_content_url>
567
+ <related_products_url></related_products_url>
568
+ <upsell_products_url></upsell_products_url>
569
+ <crosssell_products_url></crosssell_products_url>
570
+ <best_sellers_url></best_sellers_url>
571
+ <most_viewed_url></most_viewed_url>
572
+ <product_push_url></product_push_url>
573
+ <recently_viewed_url></recently_viewed_url>
574
+ <new_order_url></new_order_url>
575
+ <new_order_guest_url></new_order_guest_url>
576
+ <order_update_url></order_update_url>
577
+ <order_update_guest_url></order_update_guest_url>
578
+ <new_invoice_url></new_invoice_url>
579
+ <new_invoice_guest_url></new_invoice_guest_url>
580
+ <invoice_update_url></invoice_update_url>
581
+ <invoice_update_guest_url></invoice_update_guest_url>
582
+ <new_creditmemo_url></new_creditmemo_url>
583
+ <new_creditmemo_guest_url></new_creditmemo_guest_url>
584
+ <creditmemo_update_url></creditmemo_update_url>
585
+ <creditmemo_update_guest_url></creditmemo_update_guest_url>
586
+ <new_shipment_url></new_shipment_url>
587
+ <new_shipment_guest_url></new_shipment_guest_url>
588
+ <shipment_update_url></shipment_update_url>
589
+ <shipment_update_guest_url></shipment_update_guest_url>
590
+ <wishlist_url></wishlist_url>
591
+ </external_dynamic_content_urls>
592
+ <manual_product_search>
593
+ <display_type>list</display_type>
594
+ <items_to_display>2</items_to_display>
595
+ <products_push_items></products_push_items>
596
+ </manual_product_search>
597
+ <fallback_products>
598
+ <product_list></product_list>
599
+ </fallback_products>
600
+ </connector_dynamic_content>
601
+ <connector_reviews>
602
+ <settings>
603
+ <enabled>0</enabled>
604
+ <status></status>
605
+ <delay></delay>
606
+ <new_product>0</new_product>
607
+ <campaign>0</campaign>
608
+ <anchor></anchor>
609
+ </settings>
610
+ <feefo_feedback_engine>
611
+ <logon></logon>
612
+ <reviews_per_product></reviews_per_product>
613
+ <template></template>
614
+ </feefo_feedback_engine>
615
+ </connector_reviews>
616
+ <connector_automation_studio>
617
+ <automation>
618
+ <customer_automation>0</customer_automation>
619
+ <subscriber_automation>0</subscriber_automation>
620
+ <order_automation>0</order_automation>
621
+ <guest_order_automation>0</guest_order_automation>
622
+ <review_automation>0</review_automation>
623
+ <wishlist_automation>0</wishlist_automation>
624
+ </automation>
625
+ </connector_automation_studio>
626
+ <connector_configuration>
627
+ <transactional_data>
628
+ <order_statuses></order_statuses>
629
+ <order_custom_attributes></order_custom_attributes>
630
+ <quote_custom_attributes></quote_custom_attributes>
631
+ </transactional_data>
632
+ <abandoned_carts>
633
+ <email_capture>0</email_capture>
634
+ <limits></limits>
635
+ </abandoned_carts>
636
+ <dynamic_content_style>
637
+ <dynamic_syling><![CDATA[table{font-family: Arial, Helvetica, sans-serif; font-size:12px;}]]></dynamic_syling>
638
+ <name_color><![CDATA[#000000]]></name_color>
639
+ <name_font_size><![CDATA[12px]]></name_font_size>
640
+ <name_style></name_style>
641
+ <price_color><![CDATA[#000000]]></price_color>
642
+ <price_font_size><![CDATA[12px]]></price_font_size>
643
+ <price_style></price_style>
644
+ <link_color><![CDATA[#000000]]></link_color>
645
+ <link_font_size><![CDATA[12px]]></link_font_size>
646
+ <link_style></link_style>
647
+ <other_color><![CDATA[#000000]]></other_color>
648
+ <other_font_size><![CDATA[14px]]></other_font_size>
649
+ <other_style></other_style>
650
+ <font_picker><![CDATA[Arial, Helvetica, sans-serif]]></font_picker>
651
+ <doc_color><![CDATA[#FFFFFF]]></doc_color>
652
+ </dynamic_content_style>
653
+ <admin>
654
+ <disable_newsletter_success>0</disable_newsletter_success>
655
+ <disable_customer_success>0</disable_customer_success>
656
+ </admin>
657
+ </connector_configuration>
658
+ <connector_developer_settings>
659
+ <import_settings>
660
+ <memory_limit>0</memory_limit>
661
+ <batch_size>5000</batch_size>
662
+ <orders>200</orders>
663
+ </import_settings>
664
+ <abandoned_cart>
665
+ <shell></shell>
666
+ </abandoned_cart>
667
+ <sync_settings>
668
+ <setup_data_fields></setup_data_fields>
669
+ <contact_sync></contact_sync>
670
+ <subscriber_sync></subscriber_sync>
671
+ <order_sync></order_sync>
672
+ <delete_contact></delete_contact>
673
+ <reimport_customers></reimport_customers>
674
+ <reimport_subscribers></reimport_subscribers>
675
+ <reimport_orders></reimport_orders>
676
+ <suppressed_contacts></suppressed_contacts>
677
+ </sync_settings>
678
+ <debug>
679
+ <debug_enabled>1</debug_enabled>
680
+ <debug_api_calls>0</debug_api_calls>
681
+ <raygun_code>JOWaQ4nf4Ox7eAFUvr+TAw==</raygun_code>
682
+ </debug>
683
+ <feed_configuration>
684
+ <feed_enabled>1</feed_enabled>
685
+ <feed_url>dotmailerformagento.co.uk/feed.xml</feed_url>
686
+ <use_https>0</use_https>
687
+ <frequency>1</frequency>
688
+ <last_update></last_update>
689
+ </feed_configuration>
690
+ </connector_developer_settings>
691
+ </default>
692
+ </config>
app/code/community/Dotdigitalgroup/Email/etc/files.yaml ADDED
@@ -0,0 +1,292 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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#Email#ReviewController.php
12
+ - Adminhtml#Email#WishlistController.php
13
+ - Adminhtml#Widget#ChooserController.php
14
+ - Adminhtml#ConnectorController.php
15
+ - CreditmemoController.php
16
+ - DynamicContentController.php
17
+ - EmailController.php
18
+ - InvoiceController.php
19
+ - OrderController.php
20
+ - ProductsController.php
21
+ - ReportController.php
22
+ - ShippingController.php
23
+ - AjaxController.php
24
+ - QuoteproductsController.php
25
+ sql:
26
+ - email_connector_setup#mysql4-install-0.1.0.php
27
+ - email_connector_setup#mysql4-install-3.0.0.php
28
+ - email_connector_setup#mysql4-upgrade-1.1.1-1.1.2.php
29
+ - email_connector_setup#mysql4-upgrade-1.1.2-1.5.0.php
30
+ - email_connector_setup#mysql4-upgrade-2.0.0-2.0.1.php
31
+ - email_connector_setup#mysql4-upgrade-2.0.1-2.0.2.php
32
+ - email_connector_setup#mysql4-upgrade-2.0.4-2.0.5.php
33
+ - email_connector_setup#mysql4-upgrade-2.0.5-2.0.6.php
34
+ - email_connector_setup#mysql4-upgrade-3.0.1-3.0.2.php
35
+ - email_connector_setup#mysql4-upgrade-3.0.3-3.0.4.php
36
+ - email_connector_setup#mysql4-upgrade-3.0.4-3.0.5.php
37
+ - email_connector_setup#mysql4-upgrade-3.1.2-3.1.3.php
38
+ - email_connector_setup#mysql4-upgrade-3.2.1-3.3.0.php
39
+ locale:
40
+ - en_US#Dotdigitalgroup_Email.csv
41
+ block:
42
+ - Adminhtml#Campaign#Edit#Form.php
43
+ - Adminhtml#Campaign#Edit.php
44
+ - Adminhtml#Campaign#Grid.php
45
+ - Adminhtml#Column#Renderer#Imported.php
46
+ - Adminhtml#Column#Renderer#Status.php
47
+ - Adminhtml#Column#Renderer#Sync.php
48
+ - Adminhtml#Config#Customdatafields.php
49
+ - Adminhtml#Config#Select.php
50
+ - Adminhtml#Contact#Edit#Form.php
51
+ - Adminhtml#Contact#Edit.php
52
+ - Adminhtml#Contact#Grid.php
53
+ - Adminhtml#Dashboard#Tabs#Analysis#Abandonedcarts.php
54
+ - Adminhtml#Dashboard#Tabs#Analysis#Customer.php
55
+ - Adminhtml#Dashboard#Tabs#Analysis#Rfm.php
56
+ - Adminhtml#Dashboard#Tabs#Analysis#Sales.php
57
+ - Adminhtml#Dashboard#Tabs#Analysis#Subscriber.php
58
+ - Adminhtml#Dashboard#Tabs#General#Data.php
59
+ - Adminhtml#Dashboard#Tabs#Analysis.php
60
+ - Adminhtml#Dashboard#Tabs#Config.php
61
+ - Adminhtml#Dashboard#Tabs#General.php
62
+ - Adminhtml#Dashboard#Tabs#Status.php
63
+ - Adminhtml#Dashboard#Switcher.php
64
+ - Adminhtml#Dashboard#Tabs.php
65
+ - Adminhtml#Order#Grid.php
66
+ - Adminhtml#Review#Grid.php
67
+ - Adminhtml#Sales#Order#Creditmemo#View.php
68
+ - Adminhtml#System#Advanced#Deletecontactids.php
69
+ - Adminhtml#System#Advanced#Notification.php
70
+ - Adminhtml#System#Advanced#Reimportorders.php
71
+ - Adminhtml#System#Advanced#Reimportsubscribers.php
72
+ - Adminhtml#System#Advanced#Resetcustomersimport.php
73
+ - Adminhtml#System#Advanced#Runcontactsync.php
74
+ - Adminhtml#System#Advanced#Runordersync.php
75
+ - Adminhtml#System#Advanced#Runreviewsync.php
76
+ - Adminhtml#System#Advanced#Runsubscribersync.php
77
+ - Adminhtml#System#Advanced#Runwishlistsync.php
78
+ - Adminhtml#System#Advanced#Setupdatafields.php
79
+ - Adminhtml#System#Advanced#Suppressedcontacts.php
80
+ - Adminhtml#System#Automation#Connect.php
81
+ - Adminhtml#System#Config#Addressbook.php
82
+ - Adminhtml#System#Config#Datafield.php
83
+ - Adminhtml#System#Config#Resetcontacts.php
84
+ - Adminhtml#System#Config#Resetguests.php
85
+ - Adminhtml#System#Config#Resetsubscribers.php
86
+ - Adminhtml#System#Config#Validator.php
87
+ - Adminhtml#System#Config#Waitingfield.php
88
+ - Adminhtml#System#Config#Wrapper.php
89
+ - Adminhtml#System#Dynamic#Basket#Crosssell.php
90
+ - Adminhtml#System#Dynamic#Basket#Related.php
91
+ - Adminhtml#System#Dynamic#Basket#Upsell.php
92
+ - Adminhtml#System#Dynamic#Addressbookbutton.php
93
+ - Adminhtml#System#Dynamic#Bestsellers.php
94
+ - Adminhtml#System#Dynamic#Couponinfo.php
95
+ - Adminhtml#System#Dynamic#Creditmemonew.php
96
+ - Adminhtml#System#Dynamic#Crosssell.php
97
+ - Adminhtml#System#Dynamic#Datafieldbutton.php
98
+ - Adminhtml#System#Dynamic#Fallbackchooser.php
99
+ - Adminhtml#System#Dynamic#Fallbackcontainer.php
100
+ - Adminhtml#System#Dynamic#Gridlist.php
101
+ - Adminhtml#System#Dynamic#Lostbasket.php
102
+ - Adminhtml#System#Dynamic#Manualchooser.php
103
+ - Adminhtml#System#Dynamic#Manualcontainer.php
104
+ - Adminhtml#System#Dynamic#Mostviewed.php
105
+ - Adminhtml#System#Dynamic#Nosto.php
106
+ - Adminhtml#System#Dynamic#Productpush.php
107
+ - Adminhtml#System#Dynamic#Recentlyviewed.php
108
+ - Adminhtml#System#Dynamic#Related.php
109
+ - Adminhtml#System#Dynamic#Review.php
110
+ - Adminhtml#System#Dynamic#Upsell.php
111
+ - Adminhtml#System#Sms#Smsmessagefour.php
112
+ - Adminhtml#System#Sms#Smsmessageone.php
113
+ - Adminhtml#System#Sms#Smsmessagethree.php
114
+ - Adminhtml#System#Sms#Smsmessagetwo.php
115
+ - Adminhtml#System#Url#Creditmemoupdate.php
116
+ - Adminhtml#System#Url#Creditmemoupdateguest.php
117
+ - Adminhtml#System#Url#Customerconfirmation.php
118
+ - Adminhtml#System#Url#Customerconfirmed.php
119
+ - Adminhtml#System#Url#Customernew.php
120
+ - Adminhtml#System#Url#Invoiceupdate.php
121
+ - Adminhtml#System#Url#Invoiceupdateguest.php
122
+ - Adminhtml#System#Url#Newcreditmemo.php
123
+ - Adminhtml#System#Url#Newcreditmemoguest.php
124
+ - Adminhtml#System#Url#Newinvoice.php
125
+ - Adminhtml#System#Url#Newinvoiceguest.php
126
+ - Adminhtml#System#Url#Neworder.php
127
+ - Adminhtml#System#Url#Neworderguest.php
128
+ - Adminhtml#System#Url#Newshipment.php
129
+ - Adminhtml#System#Url#Newshipmentguest.php
130
+ - Adminhtml#System#Url#Orderupdate.php
131
+ - Adminhtml#System#Url#Orderupdateguest.php
132
+ - Adminhtml#System#Url#Shipmentupdate.php
133
+ - Adminhtml#System#Url#Shipmentupdateguest.php
134
+ - Adminhtml#System#Ajaxvalidate.php
135
+ - Adminhtml#System#Emailapivalidate.php
136
+ - Adminhtml#Widget#Chooser#Product.php
137
+ - Adminhtml#Wishlist#Grid.php
138
+ - Adminhtml#Campaign.php
139
+ - Adminhtml#Config.php
140
+ - Adminhtml#Contact.php
141
+ - Adminhtml#Dashboard.php
142
+ - Adminhtml#Order.php
143
+ - Adminhtml#Review.php
144
+ - Adminhtml#Wishlist.php
145
+ - Order#Creditmemo.php
146
+ - Order#Invoice.php
147
+ - Order#Shipping.php
148
+ - Recommended#Bestsellers.php
149
+ - Recommended#Mostviewed.php
150
+ - Recommended#Products.php
151
+ - Recommended#Push.php
152
+ - Recommended#Quoteproducts.php
153
+ - Recommended#Recentlyviewed.php
154
+ - Basket.php
155
+ - Coupon.php
156
+ - Order.php
157
+ - Products.php
158
+ helper:
159
+ - Config.php
160
+ - Data.php
161
+ - File.php
162
+ - Recommended.php
163
+ - Review.php
164
+ model:
165
+ - Abstract#Rest.php
166
+ - Adminhtml#Dashboard#Tabs#Analysis#Abandoned.php
167
+ - Adminhtml#Dashboard#Tabs#Analysis#Customer.php
168
+ - Adminhtml#Dashboard#Tabs#Analysis#Orders.php
169
+ - Adminhtml#Dashboard#Tabs#Analysis#Rfm.php
170
+ - Adminhtml#Dashboard#Tabs#Analysis#Subscriber.php
171
+ - Adminhtml#Dashboard#Content.php
172
+ - Adminhtml#Source#Advanced#Abandonedlimit.php
173
+ - Adminhtml#Source#Advanced#Attributes.php
174
+ - Adminhtml#Source#Advanced#Frequency.php
175
+ - Adminhtml#Source#Advanced#Transdata.php
176
+ - Adminhtml#Source#Automation#Programme.php
177
+ - Adminhtml#Source#Contact#Imported.php
178
+ - Adminhtml#Source#Customer#Attributes#Select.php
179
+ - Adminhtml#Source#Datamapping#Datafieldtype.php
180
+ - Adminhtml#Source#Datamapping#Datafieldaccess.php
181
+ - Adminhtml#Source#Dynamic#Displaytype.php
182
+ - Adminhtml#Source#Dynamic#Gridview.php
183
+ - Adminhtml#Source#Lostbaskets#Interval.php
184
+ - Adminhtml#Source#Lostbaskets#Intervalminute.php
185
+ - Adminhtml#Source#Reviews#Campaigns.php
186
+ - Adminhtml#Source#Reviews#Delay.php
187
+ - Adminhtml#Source#Sweettooth#Yesno.php
188
+ - Adminhtml#Source#Addressbooks.php
189
+ - Adminhtml#Source#Campaigns.php
190
+ - Adminhtml#Source#Datafields.php
191
+ - Adminhtml#Source#Orderstatus.php
192
+ - Adminhtml#Observer.php
193
+ - Apiconnector#Client.php
194
+ - Apiconnector#Contact.php
195
+ - Apiconnector#Customer.php
196
+ - Apiconnector#Test.php
197
+ - Connector#Account.php
198
+ - Connector#Campaign.php
199
+ - Connector#Datafield.php
200
+ - Connector#Order.php
201
+ - Controller#Observer.php
202
+ - Customer#Review#Rating.php
203
+ - Customer#Wishlist#Item.php
204
+ - Customer#Guest.php
205
+ - Customer#Observer.php
206
+ - Customer#Review.php
207
+ - Customer#Wishlist.php
208
+ - Newsletter#Observer.php
209
+ - Newsletter#Sub.php
210
+ - Newsletter#Subscriber.php
211
+ - Resource#Campaign#Collection.php
212
+ - Resource#Config#Collection.php
213
+ - Resource#Contact#Collection.php
214
+ - Resource#Order#Collection.php
215
+ - Resource#Review#Collection.php
216
+ - Resource#Wishlist#Collection.php
217
+ - Resource#Campaign.php
218
+ - Resource#Config.php
219
+ - Resource#Contact.php
220
+ - Resource#Order.php
221
+ - Resource#Review.php
222
+ - Resource#Setup.php
223
+ - Resource#Wishlist.php
224
+ - Sales#Observer.php
225
+ - Sales#Order.php
226
+ - Sales#Quote.php
227
+ - Sms#Campaign.php
228
+ - Sweettooth#Observer.php
229
+ - Campaign.php
230
+ - Config.php
231
+ - Contact.php
232
+ - Cron.php
233
+ - Customer.php
234
+ - Feed.php
235
+ - Order.php
236
+ - Review.php
237
+ - Wishlist.php
238
+ design:
239
+ - adminhtml#default#default#layout#connector#email.xml
240
+ - adminhtml#default#default#template#connector#dashboard#tabs#analysis#index.phtml
241
+ - adminhtml#default#default#template#connector#dashboard#tabs#analysis#rfm.phtml
242
+ - adminhtml#default#default#template#connector#dashboard#tabs#general#index.phtml
243
+ - adminhtml#default#default#template#connector#dashboard#tabs#config.phtml
244
+ - adminhtml#default#default#template#connector#dashboard#tabs#data.phtml
245
+ - adminhtml#default#default#template#connector#dashboard#accountbar.phtml
246
+ - adminhtml#default#default#template#connector#dashboard#content.phtml
247
+ - adminhtml#default#default#template#connector#dashboard#status.phtml
248
+ - adminhtml#default#default#template#connector#dashboard#tabs.phtml
249
+ - adminhtml#default#default#template#connector#system#config#createdatafield.phtml
250
+ - frontend#base#default#layout#connector.xml
251
+ - frontend#base#default#layout#mailcheck.xml
252
+ - frontend#base#default#template#connector#creditmemo#items.phtml
253
+ - frontend#base#default#template#connector#creditmemo#new.phtml
254
+ - frontend#base#default#template#connector#creditmemo#newguest.phtml
255
+ - frontend#base#default#template#connector#creditmemo#update.phtml
256
+ - frontend#base#default#template#connector#creditmemo#updateguest.phtml
257
+ - frontend#base#default#template#connector#invoice#new.phtml
258
+ - frontend#base#default#template#connector#invoice#newguest.phtml
259
+ - frontend#base#default#template#connector#invoice#update.phtml
260
+ - frontend#base#default#template#connector#invoice#updateguest.phtml
261
+ - frontend#base#default#template#connector#order#items.phtml
262
+ - frontend#base#default#template#connector#order#new.phtml
263
+ - frontend#base#default#template#connector#order#newguest.phtml
264
+ - frontend#base#default#template#connector#order#update.phtml
265
+ - frontend#base#default#template#connector#order#updateguest.phtml
266
+ - frontend#base#default#template#connector#product#list.phtml
267
+ - frontend#base#default#template#connector#product#nosto.phtml
268
+ - frontend#base#default#template#connector#product#price.phtml
269
+ - frontend#base#default#template#connector#shipping#new.phtml
270
+ - frontend#base#default#template#connector#shipping#newguest.phtml
271
+ - frontend#base#default#template#connector#shipping#update.phtml
272
+ - frontend#base#default#template#connector#shipping#updateguest.phtml
273
+ - frontend#base#default#template#connector#basket.phtml
274
+ - frontend#base#default#template#connector#coupon.phtml
275
+ - frontend#base#default#template#connector#email_capture.phtml
276
+ - frontend#base#default#template#connector#email_capture_init.phtml
277
+ - frontend#base#default#template#connector#review.phtml
278
+ - frontend#base#default#template#connector#roi_code.phtml
279
+ - frontend#base#default#template#connector#tracking_code.phtml
280
+ - frontend#base#default#template#mailcheck#scripts.phtml
281
+ - frontend#base#default#template#page#blank.phtml
282
+ skin:
283
+ - adminhtml#default#default#connector#dashboard.css
284
+ - frontend#base#default#js#mailcheck#init.js
285
+ shell:
286
+ - connector.php
287
+ lib:
288
+ - Raygun4php#RaygunClient.php
289
+ js:
290
+ - connector#selector.js
291
+ - mailcheck#magentoMailcheck.js
292
+ - mailcheck#mailcheck.min.js
app/code/community/Dotdigitalgroup/Email/etc/system.xml ADDED
@@ -0,0 +1,2776 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <tabs>
4
+ <connector translate="label" module="ddg">
5
+ <label>DOTMAILER</label>
6
+ <sort_order>1000</sort_order>
7
+ </connector>
8
+ </tabs>
9
+ <sections>
10
+ <connector_api_credentials translate="label" module="ddg">
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="ddg">
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="ddg">
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="ddg">
38
+ <label>API Username</label>
39
+ <frontend_type>text</frontend_type>
40
+ <frontend_model>ddg_automation/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="ddg">
48
+ <label>API Password</label>
49
+ <frontend_type>password</frontend_type>
50
+ <frontend_model>ddg_automation/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 module="ddg">
58
+ <frontend_type>hidden</frontend_type>
59
+ <frontend_model>ddg_automation/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="ddg">
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="ddg">
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="ddg">
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 comment" module="ddg">
92
+ <label>Connection</label>
93
+ <frontend_model>ddg_automation/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="ddg">
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="ddg">
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="ddg">
121
+ <label>Add Customers To</label>
122
+ <frontend_type>select</frontend_type>
123
+ <frontend_model>ddg_automation/adminhtml_system_config_resetcontacts</frontend_model>
124
+ <source_model>ddg_automation/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="ddg">
131
+ <label>Add Subscribers To</label>
132
+ <frontend_type>select</frontend_type>
133
+ <frontend_model>ddg_automation/adminhtml_system_config_resetsubscribers</frontend_model>
134
+ <source_model>ddg_automation/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="ddg">
141
+ <label>Add Guests To</label>
142
+ <frontend_type>select</frontend_type>
143
+ <frontend_model>ddg_automation/adminhtml_system_config_resetguests</frontend_model>
144
+ <source_model>ddg_automation/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
+ <address_book_pref>
153
+ <label>Customer Address Book Preference</label>
154
+ <sort_order>15</sort_order>
155
+ <show_in_default>1</show_in_default>
156
+ <show_in_website>1</show_in_website>
157
+ <show_in_store>0</show_in_store>
158
+ <expanded>1</expanded>
159
+ <fields>
160
+ <can_change translate="label" module="ddg">
161
+ <label>Show Address Books To Customer?</label>
162
+ <frontend_type>select</frontend_type>
163
+ <source_model>adminhtml/system_config_source_yesno</source_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
+ </can_change>
169
+ <show_books>
170
+ <label>Address Books To Show</label>
171
+ <frontend_type>multiselect</frontend_type>
172
+ <source_model>ddg_automation/adminhtml_source_addressbookspref</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
+ <depends>
178
+ <can_change>1</can_change>
179
+ </depends>
180
+ <comment><![CDATA[ Choose additional address books to show in addition to the Magento General Subscription list.]]></comment>
181
+ </show_books>
182
+ <can_show_fields translate="label" module="ddg">
183
+ <label>Show Data Fields To Customer?</label>
184
+ <frontend_type>select</frontend_type>
185
+ <source_model>adminhtml/system_config_source_yesno</source_model>
186
+ <sort_order>30</sort_order>
187
+ <show_in_default>1</show_in_default>
188
+ <show_in_website>1</show_in_website>
189
+ <show_in_store>0</show_in_store>
190
+ </can_show_fields>
191
+ <fields_to_show>
192
+ <label>Data Fields To Show</label>
193
+ <frontend_type>multiselect</frontend_type>
194
+ <source_model>ddg_automation/adminhtml_source_publicdatafields</source_model>
195
+ <sort_order>40</sort_order>
196
+ <show_in_default>1</show_in_default>
197
+ <show_in_website>1</show_in_website>
198
+ <show_in_store>0</show_in_store>
199
+ <depends>
200
+ <can_show_fields>1</can_show_fields>
201
+ </depends>
202
+ <comment><![CDATA[Only data fields with visibility public can be shown to customers. You can create more data fields within the Data Mapping section.]]></comment>
203
+ </fields_to_show>
204
+ </fields>
205
+ </address_book_pref>
206
+ <sync translate="label" module="ddg">
207
+ <label>Sync</label>
208
+ <frontend_type>text</frontend_type>
209
+ <sort_order>20</sort_order>
210
+ <show_in_default>1</show_in_default>
211
+ <show_in_website>1</show_in_website>
212
+ <show_in_store>0</show_in_store>
213
+ <expanded>1</expanded>
214
+ <fields>
215
+ <contact_title translate="label" module="ddg">
216
+ <label>Contact Sync</label>
217
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
218
+ <sort_order>10</sort_order>
219
+ <show_in_default>1</show_in_default>
220
+ <show_in_website>1</show_in_website>
221
+ <show_in_store>0</show_in_store>
222
+ </contact_title>
223
+ <contact_enabled translate="label" module="ddg">
224
+ <label>Enabled</label>
225
+ <frontend_type>select</frontend_type>
226
+ <source_model>adminhtml/system_config_source_yesno</source_model>
227
+ <sort_order>20</sort_order>
228
+ <show_in_default>1</show_in_default>
229
+ <show_in_website>1</show_in_website>
230
+ <show_in_store>0</show_in_store>
231
+ </contact_enabled>
232
+ <subscriber_title translate="label" module="ddg">
233
+ <label>Subscriber Sync</label>
234
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
235
+ <sort_order>50</sort_order>
236
+ <show_in_default>1</show_in_default>
237
+ <show_in_website>1</show_in_website>
238
+ <show_in_store>0</show_in_store>
239
+ </subscriber_title>
240
+ <subscriber_enabled translate="label" module="ddg">
241
+ <label>Enabled</label>
242
+ <frontend_type>select</frontend_type>
243
+ <source_model>adminhtml/system_config_source_yesno</source_model>
244
+ <sort_order>60</sort_order>
245
+ <show_in_default>1</show_in_default>
246
+ <show_in_website>1</show_in_website>
247
+ <show_in_store>0</show_in_store>
248
+ </subscriber_enabled>
249
+ <order_title translate="label" module="ddg">
250
+ <label>Order Sync</label>
251
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
252
+ <sort_order>70</sort_order>
253
+ <show_in_default>1</show_in_default>
254
+ <show_in_website>1</show_in_website>
255
+ <show_in_store>0</show_in_store>
256
+ </order_title>
257
+ <order_enabled translate="label" module="ddg">
258
+ <label>Enabled</label>
259
+ <frontend_type>select</frontend_type>
260
+ <source_model>adminhtml/system_config_source_yesno</source_model>
261
+ <sort_order>80</sort_order>
262
+ <show_in_default>1</show_in_default>
263
+ <show_in_website>1</show_in_website>
264
+ <show_in_store>0</show_in_store>
265
+ </order_enabled>
266
+ <quote_title translate="label" module="ddg">
267
+ <label>Quote Sync</label>
268
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
269
+ <sort_order>83</sort_order>
270
+ <show_in_default>1</show_in_default>
271
+ <show_in_website>1</show_in_website>
272
+ <show_in_store>0</show_in_store>
273
+ </quote_title>
274
+ <quote_enabled translate="label" module="ddg">
275
+ <label>Enabled</label>
276
+ <frontend_type>select</frontend_type>
277
+ <source_model>adminhtml/system_config_source_yesno</source_model>
278
+ <sort_order>86</sort_order>
279
+ <show_in_default>1</show_in_default>
280
+ <show_in_website>1</show_in_website>
281
+ <show_in_store>0</show_in_store>
282
+ </quote_enabled>
283
+ <wishlist_title translate="label" module="ddg">
284
+ <label>Wishlist Sync</label>
285
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
286
+ <sort_order>90</sort_order>
287
+ <show_in_default>1</show_in_default>
288
+ <show_in_website>1</show_in_website>
289
+ <show_in_store>0</show_in_store>
290
+ </wishlist_title>
291
+ <wishlist_enabled translate="label" module="ddg">
292
+ <label>Enabled</label>
293
+ <frontend_type>select</frontend_type>
294
+ <source_model>adminhtml/system_config_source_yesno</source_model>
295
+ <sort_order>100</sort_order>
296
+ <show_in_default>1</show_in_default>
297
+ <show_in_website>1</show_in_website>
298
+ <show_in_store>0</show_in_store>
299
+ </wishlist_enabled>
300
+ <review_title translate="label" module="ddg">
301
+ <label>Review Sync</label>
302
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
303
+ <sort_order>103</sort_order>
304
+ <show_in_default>1</show_in_default>
305
+ <show_in_website>1</show_in_website>
306
+ <show_in_store>0</show_in_store>
307
+ </review_title>
308
+ <review_enabled translate="label" module="ddg">
309
+ <label>Enabled</label>
310
+ <frontend_type>select</frontend_type>
311
+ <source_model>adminhtml/system_config_source_yesno</source_model>
312
+ <sort_order>106</sort_order>
313
+ <show_in_default>1</show_in_default>
314
+ <show_in_website>1</show_in_website>
315
+ <show_in_store>0</show_in_store>
316
+ </review_enabled>
317
+ <validator>
318
+ <frontend_type>hidden</frontend_type>
319
+ <frontend_model>ddg_automation/adminhtml_system_config_waitingfield</frontend_model>
320
+ <sort_order>110</sort_order>
321
+ <show_in_default>1</show_in_default>
322
+ <show_in_website>1</show_in_website>
323
+ <show_in_store>0</show_in_store>
324
+ <can_be_empty>1</can_be_empty>
325
+ </validator>
326
+ </fields>
327
+ </sync>
328
+ <dynamic_addressbook translate="label" module="ddg">
329
+ <label>Create Address Book</label>
330
+ <sort_order>30</sort_order>
331
+ <show_in_default>1</show_in_default>
332
+ <show_in_website>1</show_in_website>
333
+ <show_in_store>0</show_in_store>
334
+ <fields>
335
+ <addressbook_name translate="label" module="ddg">
336
+ <label>Address Book Name</label>
337
+ <frontend_type>text</frontend_type>
338
+ <frontend_model>ddg_automation/adminhtml_system_config_addressbook</frontend_model>
339
+ <sort_order>10</sort_order>
340
+ <show_in_default>1</show_in_default>
341
+ <show_in_website>1</show_in_website>
342
+ <show_in_store>0</show_in_store>
343
+ </addressbook_name>
344
+ <visibility translate="label comment">
345
+ <label>Visibility</label>
346
+ <frontend_type>select</frontend_type>
347
+ <source_model>ddg_automation/adminhtml_source_datamapping_datafieldaccess</source_model>
348
+ <sort_order>20</sort_order>
349
+ <show_in_default>1</show_in_default>
350
+ <show_in_website>1</show_in_website>
351
+ <show_in_store>0</show_in_store>
352
+ <comment>Select if a contact can join/unsubscribe from the address book via the unsubscribe page</comment>
353
+ </visibility>
354
+ <addresbook_button translate="label button_label" module="ddg">
355
+ <label />
356
+ <button_label>Create New Address Book</button_label>
357
+ <frontend_model>ddg_automation/adminhtml_system_dynamic_addressbookbutton</frontend_model>
358
+ <sort_order>30</sort_order>
359
+ <show_in_default>1</show_in_default>
360
+ <show_in_website>1</show_in_website>
361
+ <show_in_store>0</show_in_store>
362
+ </addresbook_button>
363
+ </fields>
364
+ </dynamic_addressbook>
365
+ </groups>
366
+ </connector_sync_settings>
367
+ <connector_data_mapping translate="label" module="ddg">
368
+ <label><![CDATA[Data Mapping]]></label>
369
+ <tab>connector</tab>
370
+ <frontend_type>text</frontend_type>
371
+ <sort_order>2000</sort_order>
372
+ <show_in_default>1</show_in_default>
373
+ <show_in_website>1</show_in_website>
374
+ <show_in_store>0</show_in_store>
375
+ <groups>
376
+ <customer_data translate="label" module="ddg">
377
+ <label>Data Fields Mapping</label>
378
+ <frontend_type>text</frontend_type>
379
+ <sort_order>20</sort_order>
380
+ <show_in_default>1</show_in_default>
381
+ <show_in_website>1</show_in_website>
382
+ <show_in_store>0</show_in_store>
383
+ <expanded>1</expanded>
384
+ <comment><![CDATA[<p class="notice">AUTOMAP AVAILABLE IN DEVELOPER SECTION TO MAP ALL DATAFIELDS.</p>]]></comment>
385
+ <fields>
386
+ <customer_title translate="label" module="ddg">
387
+ <label>Customer Information</label>
388
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
389
+ <sort_order>10</sort_order>
390
+ <show_in_default>1</show_in_default>
391
+ <show_in_website>1</show_in_website>
392
+ <show_in_store>0</show_in_store>
393
+ </customer_title>
394
+ <title translate="label" module="ddg">
395
+ <label>Title</label>
396
+ <frontend_type>select</frontend_type>
397
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
398
+ <sort_order>20</sort_order>
399
+ <show_in_default>1</show_in_default>
400
+ <show_in_website>1</show_in_website>
401
+ <show_in_store>0</show_in_store>
402
+ </title>
403
+ <customer_id translate="label" module="ddg">
404
+ <label>Customer ID</label>
405
+ <frontend_type>select</frontend_type>
406
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
407
+ <sort_order>30</sort_order>
408
+ <show_in_default>1</show_in_default>
409
+ <show_in_website>1</show_in_website>
410
+ <show_in_store>0</show_in_store>
411
+ </customer_id>
412
+ <firstname translate="label" module="ddg">
413
+ <label>First Name</label>
414
+ <frontend_type>select</frontend_type>
415
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
416
+ <sort_order>40</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
+ </firstname>
421
+ <lastname translate="label" module="ddg">
422
+ <label>Last Name</label>
423
+ <frontend_type>select</frontend_type>
424
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
425
+ <sort_order>50</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
+ </lastname>
430
+ <dob translate="label" module="ddg">
431
+ <label>D.O.B.</label>
432
+ <frontend_type>select</frontend_type>
433
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
434
+ <sort_order>60</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
+ </dob>
439
+ <gender translate="label" module="ddg">
440
+ <label>Gender</label>
441
+ <frontend_type>select</frontend_type>
442
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
443
+ <sort_order>70</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
+ </gender>
448
+ <website_name translate="label" module="ddg">
449
+ <label>Website Created On</label>
450
+ <frontend_type>select</frontend_type>
451
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
452
+ <sort_order>80</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
+ </website_name>
457
+ <store_name translate="label" module="ddg">
458
+ <label>Store Created On</label>
459
+ <frontend_type>select</frontend_type>
460
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
461
+ <sort_order>90</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
+ </store_name>
466
+ <created_at translate="label" module="ddg">
467
+ <label>Account Created Date</label>
468
+ <frontend_type>select</frontend_type>
469
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
470
+ <sort_order>100</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
+ </created_at>
475
+ <last_logged_date translate="label" module="ddg">
476
+ <label>Last Logged In Date</label>
477
+ <frontend_type>select</frontend_type>
478
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
479
+ <sort_order>110</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
+ </last_logged_date>
484
+ <customer_group translate="label" module="ddg">
485
+ <label>Customer Group</label>
486
+ <frontend_type>select</frontend_type>
487
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
488
+ <sort_order>120</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
+ </customer_group>
493
+ <review_count translate="label" module="ddg">
494
+ <label>Customer Review Count</label>
495
+ <frontend_type>select</frontend_type>
496
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
497
+ <sort_order>121</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
+ </review_count>
502
+ <last_review_date translate="label" module="ddg">
503
+ <label>Last Review Date</label>
504
+ <frontend_type>select</frontend_type>
505
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
506
+ <sort_order>122</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
+ </last_review_date>
511
+ <subscriber_status translate="label" module="ddg">
512
+ <label>Subscriber Status</label>
513
+ <frontend_type>select</frontend_type>
514
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
515
+ <sort_order>123</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
+ </subscriber_status>
520
+ <address_title translate="label" module="ddg">
521
+ <label>Address</label>
522
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
523
+ <sort_order>130</sort_order>
524
+ <show_in_default>1</show_in_default>
525
+ <show_in_website>1</show_in_website>
526
+ <show_in_store>0</show_in_store>
527
+ </address_title>
528
+ <billing_address_1 translate="label" module="ddg">
529
+ <label>Billing Address Line 1</label>
530
+ <frontend_type>select</frontend_type>
531
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
532
+ <sort_order>140</sort_order>
533
+ <show_in_default>1</show_in_default>
534
+ <show_in_website>1</show_in_website>
535
+ <show_in_store>0</show_in_store>
536
+ </billing_address_1>
537
+ <billing_address_2 translate="label" module="ddg">
538
+ <label>Billing Address Line 2</label>
539
+ <frontend_type>select</frontend_type>
540
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
541
+ <sort_order>150</sort_order>
542
+ <show_in_default>1</show_in_default>
543
+ <show_in_website>1</show_in_website>
544
+ <show_in_store>0</show_in_store>
545
+ </billing_address_2>
546
+ <billing_city translate="label" module="ddg">
547
+ <label>Billing City</label>
548
+ <frontend_type>select</frontend_type>
549
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
550
+ <sort_order>160</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
+ </billing_city>
555
+ <billing_state translate="label" module="ddg">
556
+ <label>Billing State/Region</label>
557
+ <frontend_type>select</frontend_type>
558
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
559
+ <sort_order>155</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
+ </billing_state>
564
+ <billing_country translate="label" module="ddg">
565
+ <label>Billing Country</label>
566
+ <frontend_type>select</frontend_type>
567
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
568
+ <sort_order>170</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
+ </billing_country>
573
+ <billing_postcode translate="label" module="ddg">
574
+ <label>Billing Zip/Postcode</label>
575
+ <frontend_type>select</frontend_type>
576
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
577
+ <sort_order>180</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
+ </billing_postcode>
582
+ <billing_telephone translate="label" module="ddg">
583
+ <label>Billing Telephone</label>
584
+ <frontend_type>select</frontend_type>
585
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
586
+ <sort_order>190</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
+ </billing_telephone>
591
+ <delivery_address_1 translate="label" module="ddg">
592
+ <label>Delivery Address Line 1</label>
593
+ <frontend_type>select</frontend_type>
594
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
595
+ <sort_order>200</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
+ </delivery_address_1>
600
+ <delivery_address_2 translate="label" module="ddg">
601
+ <label>Delivery Address Line 2</label>
602
+ <frontend_type>select</frontend_type>
603
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
604
+ <sort_order>210</sort_order>
605
+ <show_in_default>1</show_in_default>
606
+ <show_in_website>1</show_in_website>
607
+ <show_in_store>0</show_in_store>
608
+ </delivery_address_2>
609
+ <delivery_city translate="label" module="ddg">
610
+ <label>Delivery City</label>
611
+ <frontend_type>select</frontend_type>
612
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
613
+ <sort_order>220</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
+ </delivery_city>
618
+ <delivery_state translate="label" module="ddg">
619
+ <label>Delivery State/Region</label>
620
+ <frontend_type>select</frontend_type>
621
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
622
+ <sort_order>215</sort_order>
623
+ <show_in_default>1</show_in_default>
624
+ <show_in_website>1</show_in_website>
625
+ <show_in_store>0</show_in_store>
626
+ </delivery_state>
627
+ <delivery_country translate="label" module="ddg">
628
+ <label>Delivery Country</label>
629
+ <frontend_type>select</frontend_type>
630
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
631
+ <sort_order>230</sort_order>
632
+ <show_in_default>1</show_in_default>
633
+ <show_in_website>1</show_in_website>
634
+ <show_in_store>0</show_in_store>
635
+ </delivery_country>
636
+ <delivery_postcode translate="label" module="ddg">
637
+ <label>Delivery Zip/Postcode</label>
638
+ <frontend_type>select</frontend_type>
639
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
640
+ <sort_order>240</sort_order>
641
+ <show_in_default>1</show_in_default>
642
+ <show_in_website>1</show_in_website>
643
+ <show_in_store>0</show_in_store>
644
+ </delivery_postcode>
645
+ <delivery_telephone translate="label" module="ddg">
646
+ <label>Delivery Telephone</label>
647
+ <frontend_type>select</frontend_type>
648
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
649
+ <sort_order>250</sort_order>
650
+ <show_in_default>1</show_in_default>
651
+ <show_in_website>1</show_in_website>
652
+ <show_in_store>0</show_in_store>
653
+ </delivery_telephone>
654
+ <sales_title translate="label" module="ddg">
655
+ <label>Sales</label>
656
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
657
+ <sort_order>260</sort_order>
658
+ <show_in_default>1</show_in_default>
659
+ <show_in_website>1</show_in_website>
660
+ <show_in_store>0</show_in_store>
661
+ </sales_title>
662
+ <number_of_orders translate="label" module="ddg">
663
+ <label>Total Number of Orders</label>
664
+ <frontend_type>select</frontend_type>
665
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
666
+ <sort_order>270</sort_order>
667
+ <show_in_default>1</show_in_default>
668
+ <show_in_website>1</show_in_website>
669
+ <show_in_store>0</show_in_store>
670
+ </number_of_orders>
671
+ <average_order_value translate="label" module="ddg">
672
+ <label>Average Order Value</label>
673
+ <frontend_type>select</frontend_type>
674
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
675
+ <sort_order>280</sort_order>
676
+ <show_in_default>1</show_in_default>
677
+ <show_in_website>1</show_in_website>
678
+ <show_in_store>0</show_in_store>
679
+ </average_order_value>
680
+ <total_spend translate="label" module="ddg">
681
+ <label>Total Spend</label>
682
+ <frontend_type>select</frontend_type>
683
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
684
+ <sort_order>290</sort_order>
685
+ <show_in_default>1</show_in_default>
686
+ <show_in_website>1</show_in_website>
687
+ <show_in_store>0</show_in_store>
688
+ </total_spend>
689
+ <last_order_date translate="label" module="ddg">
690
+ <label>Last Purchase Date</label>
691
+ <frontend_type>select</frontend_type>
692
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
693
+ <sort_order>300</sort_order>
694
+ <show_in_default>1</show_in_default>
695
+ <show_in_website>1</show_in_website>
696
+ <show_in_store>0</show_in_store>
697
+ </last_order_date>
698
+ <last_order_id translate="label" module="ddg">
699
+ <label>Last Order ID</label>
700
+ <frontend_type>select</frontend_type>
701
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
702
+ <sort_order>310</sort_order>
703
+ <show_in_default>1</show_in_default>
704
+ <show_in_website>1</show_in_website>
705
+ <show_in_store>0</show_in_store>
706
+ </last_order_id>
707
+ <last_quote_id translate="label" module="ddg">
708
+ <label>Last Quote ID</label>
709
+ <frontend_type>select</frontend_type>
710
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
711
+ <sort_order>315</sort_order>
712
+ <show_in_default>1</show_in_default>
713
+ <show_in_website>1</show_in_website>
714
+ <show_in_store>0</show_in_store>
715
+ </last_quote_id>
716
+ <total_refund translate="label">
717
+ <label>Total Refund</label>
718
+ <frontend_type>select</frontend_type>
719
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
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
+ <sort_order>320</sort_order>
724
+ </total_refund>
725
+ <custom_title translate="label" module="ddg">
726
+ <label>Custom Attributes</label>
727
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
728
+ <sort_order>330</sort_order>
729
+ <show_in_default>1</show_in_default>
730
+ <show_in_website>1</show_in_website>
731
+ <show_in_store>0</show_in_store>
732
+ </custom_title>
733
+ <custom_attributes translate="label" module="ddg">
734
+ <label>Customer</label>
735
+ <frontend_model>ddg_automation/adminhtml_config_customdatafields</frontend_model>
736
+ <backend_model>adminhtml/system_config_backend_serialized_array</backend_model>
737
+ <source_model>ddg_automation/adminhtml_source_customer_attributes_select</source_model>
738
+ <sort_order>340</sort_order>
739
+ <show_in_default>1</show_in_default>
740
+ <show_in_website>1</show_in_website>
741
+ <show_in_store>0</show_in_store>
742
+ </custom_attributes>
743
+ <validator translate="label" module="ddg">
744
+ <label>Validation Block</label>
745
+ <frontend_type>select</frontend_type>
746
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
747
+ <frontend_model>ddg_automation/adminhtml_system_config_validator</frontend_model>
748
+ <sort_order>920</sort_order>
749
+ <show_in_default>1</show_in_default>
750
+ <show_in_website>1</show_in_website>
751
+ <show_in_store>0</show_in_store>
752
+ <can_be_empty>1</can_be_empty>
753
+ <expanded>1</expanded>
754
+ </validator>
755
+ </fields>
756
+ </customer_data>
757
+ <dynamic_datafield translate="label" module="ddg">
758
+ <label>Create Data Field</label>
759
+ <sort_order>30</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
+ <fields>
764
+ <datafield_name translate="label comment" module="ddg">
765
+ <label>Data Field Name</label>
766
+ <frontend_type>text</frontend_type>
767
+ <frontend_model>ddg_automation/adminhtml_system_config_datafield</frontend_model>
768
+ <sort_order>10</sort_order>
769
+ <show_in_default>1</show_in_default>
770
+ <show_in_website>1</show_in_website>
771
+ <show_in_store>0</show_in_store>
772
+ <comment>(Maximum of 20 characters)</comment>
773
+ </datafield_name>
774
+ <datafield_type translate="label" module="ddg">
775
+ <label>Data Field Type</label>
776
+ <frontend_type>select</frontend_type>
777
+ <source_model>ddg_automation/adminhtml_source_datamapping_datafieldtype</source_model>
778
+ <sort_order>20</sort_order>
779
+ <show_in_default>1</show_in_default>
780
+ <show_in_website>1</show_in_website>
781
+ <show_in_store>0</show_in_store>
782
+ <expended>1</expended>
783
+ </datafield_type>
784
+ <datafield_default translate="label comment" module="ddg">
785
+ <label>Default Value</label>
786
+ <frontend_type>text</frontend_type>
787
+ <sort_order>30</sort_order>
788
+ <show_in_default>1</show_in_default>
789
+ <show_in_website>1</show_in_website>
790
+ <show_in_store>0</show_in_store>
791
+ <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>
792
+ </datafield_default>
793
+ <datafield_access translate="label comment" module="ddg">
794
+ <label>Visibility</label>
795
+ <frontend_type>select</frontend_type>
796
+ <source_model>ddg_automation/adminhtml_source_datamapping_datafieldaccess</source_model>
797
+ <sort_order>40</sort_order>
798
+ <show_in_default>1</show_in_default>
799
+ <show_in_website>1</show_in_website>
800
+ <show_in_store>0</show_in_store>
801
+ <comment>Make the field public if you want to allow your contacts to view and amend the data you hold on them in this field.</comment>
802
+ </datafield_access>
803
+ <datafield_button translate="label button_label" module="ddg">
804
+ <label />
805
+ <button_label>Create New Data Field</button_label>
806
+ <frontend_model>ddg_automation/adminhtml_system_dynamic_datafieldbutton</frontend_model>
807
+ <sort_order>50</sort_order>
808
+ <show_in_default>1</show_in_default>
809
+ <show_in_website>1</show_in_website>
810
+ <show_in_store>0</show_in_store>
811
+ </datafield_button>
812
+ </fields>
813
+ </dynamic_datafield>
814
+ <sweet_tooth>
815
+ <label>Sweet Tooth Rewards</label>
816
+ <sort_order>40</sort_order>
817
+ <show_in_default>1</show_in_default>
818
+ <show_in_website>1</show_in_website>
819
+ <show_in_store>0</show_in_store>
820
+ <fields>
821
+ <active translate="label comment" module="ddg">
822
+ <label>Enabled</label>
823
+ <frontend_type>select</frontend_type>
824
+ <source_model>ddg_automation/adminhtml_source_sweettooth_yesno</source_model>
825
+ <sort_order>0</sort_order>
826
+ <show_in_default>1</show_in_default>
827
+ <show_in_website>1</show_in_website>
828
+ <show_in_store>0</show_in_store>
829
+ <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>
830
+ </active>
831
+ <title translate="label" module="ddg">
832
+ <label>Data Fields Mapping</label>
833
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
834
+ <sort_order>10</sort_order>
835
+ <show_in_default>1</show_in_default>
836
+ <show_in_website>1</show_in_website>
837
+ <show_in_store>0</show_in_store>
838
+ <depends><active>1</active></depends>
839
+ </title>
840
+ <reward_point_balance translate="label" module="ddg">
841
+ <label>Current Point Balance</label>
842
+ <frontend_type>select</frontend_type>
843
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
844
+ <sort_order>20</sort_order>
845
+ <show_in_default>1</show_in_default>
846
+ <show_in_website>1</show_in_website>
847
+ <show_in_store>0</show_in_store>
848
+ <depends><active>1</active></depends>
849
+ </reward_point_balance>
850
+ <reward_point_pending translate="label" module="ddg">
851
+ <label>Points Pending An Event</label>
852
+ <frontend_type>select</frontend_type>
853
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
854
+ <sort_order>30</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
+ <depends><active>1</active></depends>
859
+ </reward_point_pending>
860
+ <reward_point_pending_time translate="label" module="ddg">
861
+ <label>Points Pending A Date</label>
862
+ <frontend_type>select</frontend_type>
863
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
864
+ <sort_order>40</sort_order>
865
+ <show_in_default>1</show_in_default>
866
+ <show_in_website>1</show_in_website>
867
+ <show_in_store>0</show_in_store>
868
+ <depends><active>1</active></depends>
869
+ </reward_point_pending_time>
870
+ <reward_point_on_hold translate="label" module="ddg">
871
+ <label>Current On Hold Points</label>
872
+ <frontend_type>select</frontend_type>
873
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
874
+ <sort_order>50</sort_order>
875
+ <show_in_default>1</show_in_default>
876
+ <show_in_website>1</show_in_website>
877
+ <show_in_store>0</show_in_store>
878
+ <depends><active>1</active></depends>
879
+ </reward_point_on_hold>
880
+ <reward_point_expiration translate="label" module="ddg">
881
+ <label>Points Expiry Date</label>
882
+ <frontend_type>select</frontend_type>
883
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
884
+ <sort_order>60</sort_order>
885
+ <show_in_default>1</show_in_default>
886
+ <show_in_website>1</show_in_website>
887
+ <show_in_store>0</show_in_store>
888
+ <depends><active>1</active></depends>
889
+ </reward_point_expiration>
890
+ <reward_point_last_earn translate="label" module="ddg">
891
+ <label>Last Date Points Earned</label>
892
+ <frontend_type>select</frontend_type>
893
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
894
+ <sort_order>70</sort_order>
895
+ <show_in_default>1</show_in_default>
896
+ <show_in_website>1</show_in_website>
897
+ <show_in_store>0</show_in_store>
898
+ <depends><active>1</active></depends>
899
+ </reward_point_last_earn>
900
+ <reward_point_last_spent translate="label" module="ddg">
901
+ <label>Last Date Points Spent</label>
902
+ <frontend_type>select</frontend_type>
903
+ <source_model>ddg_automation/adminhtml_source_datafields</source_model>
904
+ <sort_order>70</sort_order>
905
+ <show_in_default>1</show_in_default>
906
+ <show_in_website>1</show_in_website>
907
+ <show_in_store>0</show_in_store>
908
+ <depends><active>1</active></depends>
909
+ </reward_point_last_spent>
910
+ </fields>
911
+ </sweet_tooth>
912
+ </groups>
913
+ </connector_data_mapping>
914
+ <connector_roi_tracking translate="label" module="ddg">
915
+ <label><![CDATA[ROI & Tracking]]></label>
916
+ <tab>connector</tab>
917
+ <frontend_type>text</frontend_type>
918
+ <sort_order>5000</sort_order>
919
+ <show_in_default>1</show_in_default>
920
+ <show_in_website>1</show_in_website>
921
+ <show_in_store>0</show_in_store>
922
+ <groups>
923
+ <page_tracking translate="label" module="ddg">
924
+ <label>Page Tracking</label>
925
+ <frontend_type>text</frontend_type>
926
+ <sort_order>10</sort_order>
927
+ <show_in_default>1</show_in_default>
928
+ <show_in_website>1</show_in_website>
929
+ <show_in_store>0</show_in_store>
930
+ <expanded>1</expanded>
931
+ <fields>
932
+ <enabled translate="label" module="ddg">
933
+ <label>Enabled</label>
934
+ <frontend_type>select</frontend_type>
935
+ <source_model>adminhtml/system_config_source_yesno</source_model>
936
+ <sort_order>10</sort_order>
937
+ <show_in_default>1</show_in_default>
938
+ <show_in_website>1</show_in_website>
939
+ <show_in_store>0</show_in_store>
940
+ </enabled>
941
+ </fields>
942
+ </page_tracking>
943
+ <roi_tracking translate="label" module="ddg">
944
+ <label>ROI Tracking</label>
945
+ <frontend_type>text</frontend_type>
946
+ <sort_order>20</sort_order>
947
+ <show_in_default>1</show_in_default>
948
+ <show_in_website>1</show_in_website>
949
+ <show_in_store>0</show_in_store>
950
+ <expanded>1</expanded>
951
+ <fields>
952
+ <enabled translate="label" module="ddg">
953
+ <label>Enabled</label>
954
+ <frontend_type>select</frontend_type>
955
+ <source_model>adminhtml/system_config_source_yesno</source_model>
956
+ <sort_order>10</sort_order>
957
+ <show_in_default>1</show_in_default>
958
+ <show_in_website>1</show_in_website>
959
+ <show_in_store>0</show_in_store>
960
+ </enabled>
961
+ </fields>
962
+ </roi_tracking>
963
+ </groups>
964
+ </connector_roi_tracking>
965
+ <connector_lost_baskets translate="label" module="ddg">
966
+ <label><![CDATA[Abandoned Carts]]></label>
967
+ <tab>connector</tab>
968
+ <frontend_type>text</frontend_type>
969
+ <sort_order>6000</sort_order>
970
+ <show_in_default>1</show_in_default>
971
+ <show_in_website>1</show_in_website>
972
+ <show_in_store>0</show_in_store>
973
+ <groups>
974
+ <customers translate="label" module="ddg">
975
+ <label>Customers</label>
976
+ <frontend_type>text</frontend_type>
977
+ <sort_order>10</sort_order>
978
+ <show_in_default>1</show_in_default>
979
+ <show_in_website>1</show_in_website>
980
+ <show_in_store>1</show_in_store>
981
+ <expanded>1</expanded>
982
+ <fields>
983
+ <heading_1 translate="label" module="ddg">
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>1</show_in_store>
990
+ </heading_1>
991
+ <enabled_1 translate="label" module="ddg">
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>1</show_in_store>
999
+ </enabled_1>
1000
+ <send_after_1 translate="label" module="ddg">
1001
+ <label>Send After (min)</label>
1002
+ <frontend_type>select</frontend_type>
1003
+ <source_model>ddg_automation/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>1</show_in_store>
1008
+ </send_after_1>
1009
+ <campaign_1 translate="label" module="ddg">
1010
+ <label>Campaign To Send</label>
1011
+ <frontend_type>select</frontend_type>
1012
+ <source_model>ddg_automation/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>1</show_in_store>
1017
+ </campaign_1>
1018
+ <heading_2 translate="label" module="ddg">
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>1</show_in_store>
1025
+ </heading_2>
1026
+ <enabled_2 translate="label" module="ddg">
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>1</show_in_store>
1034
+ </enabled_2>
1035
+ <send_after_2 translate="label" module="ddg">
1036
+ <label>Send After (hrs)</label>
1037
+ <frontend_type>select</frontend_type>
1038
+ <source_model>ddg_automation/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>1</show_in_store>
1043
+ </send_after_2>
1044
+ <campaign_2 translate="label" module="ddg">
1045
+ <label>Campaign To Send</label>
1046
+ <frontend_type>select</frontend_type>
1047
+ <source_model>ddg_automation/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>1</show_in_store>
1052
+ </campaign_2>
1053
+ <heading_3 translate="label" module="ddg">
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>1</show_in_store>
1060
+ </heading_3>
1061
+ <enabled_3 translate="label" module="ddg">
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>1</show_in_store>
1069
+ </enabled_3>
1070
+ <send_after_3 translate="label" module="ddg">
1071
+ <label>Send After (hrs)</label>
1072
+ <frontend_type>select</frontend_type>
1073
+ <source_model>ddg_automation/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>1</show_in_store>
1078
+ </send_after_3>
1079
+ <campaign_3 translate="label" module="ddg">
1080
+ <label>Campaign To Send</label>
1081
+ <frontend_type>select</frontend_type>
1082
+ <source_model>ddg_automation/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>1</show_in_store>
1087
+ </campaign_3>
1088
+ </fields>
1089
+ </customers>
1090
+ <guests translate="label" module="ddg">
1091
+ <label>Guests</label>
1092
+ <frontend_type>text</frontend_type>
1093
+ <sort_order>20</sort_order>
1094
+ <show_in_default>1</show_in_default>
1095
+ <show_in_website>1</show_in_website>
1096
+ <show_in_store>0</show_in_store>
1097
+ <fields>
1098
+ <heading_1 translate="label" module="ddg">
1099
+ <label>Abandoned Cart 1</label>
1100
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
1101
+ <sort_order>10</sort_order>
1102
+ <show_in_default>1</show_in_default>
1103
+ <show_in_website>1</show_in_website>
1104
+ <show_in_store>0</show_in_store>
1105
+ </heading_1>
1106
+ <enabled_1 translate="label" module="ddg">
1107
+ <label>Enabled/Disabled</label>
1108
+ <frontend_type>select</frontend_type>
1109
+ <source_model>adminhtml/system_config_source_enabledisable</source_model>
1110
+ <sort_order>20</sort_order>
1111
+ <show_in_default>1</show_in_default>
1112
+ <show_in_website>1</show_in_website>
1113
+ <show_in_store>0</show_in_store>
1114
+ </enabled_1>
1115
+ <send_after_1 translate="label" module="ddg">
1116
+ <label>Send After (min)</label>
1117
+ <frontend_type>select</frontend_type>
1118
+ <source_model>ddg_automation/adminhtml_source_lostbaskets_intervalminute</source_model>
1119
+ <sort_order>30</sort_order>
1120
+ <show_in_default>1</show_in_default>
1121
+ <show_in_website>1</show_in_website>
1122
+ <show_in_store>0</show_in_store>
1123
+ </send_after_1>
1124
+ <campaign_1 translate="label" module="ddg">
1125
+ <label>Campaign To Send</label>
1126
+ <frontend_type>select</frontend_type>
1127
+ <source_model>ddg_automation/adminhtml_source_campaigns</source_model>
1128
+ <sort_order>40</sort_order>
1129
+ <show_in_default>1</show_in_default>
1130
+ <show_in_website>1</show_in_website>
1131
+ <show_in_store>0</show_in_store>
1132
+ </campaign_1>
1133
+ <heading_2 translate="label" module="ddg">
1134
+ <label>Abandoned Cart 2</label>
1135
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
1136
+ <sort_order>50</sort_order>
1137
+ <show_in_default>1</show_in_default>
1138
+ <show_in_website>1</show_in_website>
1139
+ <show_in_store>0</show_in_store>
1140
+ </heading_2>
1141
+ <enabled_2 translate="label" module="ddg">
1142
+ <label>Enabled/Disabled</label>
1143
+ <frontend_type>select</frontend_type>
1144
+ <source_model>adminhtml/system_config_source_enabledisable</source_model>
1145
+ <sort_order>60</sort_order>
1146
+ <show_in_default>1</show_in_default>
1147
+ <show_in_website>1</show_in_website>
1148
+ <show_in_store>0</show_in_store>
1149
+ </enabled_2>
1150
+ <send_after_2 translate="label" module="ddg">
1151
+ <label>Send After (hrs)</label>
1152
+ <frontend_type>select</frontend_type>
1153
+ <source_model>ddg_automation/adminhtml_source_lostbaskets_interval</source_model>
1154
+ <sort_order>70</sort_order>
1155
+ <show_in_default>1</show_in_default>
1156
+ <show_in_website>1</show_in_website>
1157
+ <show_in_store>0</show_in_store>
1158
+ </send_after_2>
1159
+ <campaign_2 translate="label" module="ddg">
1160
+ <label>Campaign To Send</label>
1161
+ <frontend_type>select</frontend_type>
1162
+ <source_model>ddg_automation/adminhtml_source_campaigns</source_model>
1163
+ <sort_order>80</sort_order>
1164
+ <show_in_default>1</show_in_default>
1165
+ <show_in_website>1</show_in_website>
1166
+ <show_in_store>0</show_in_store>
1167
+ </campaign_2>
1168
+ <heading_3 translate="label" module="ddg">
1169
+ <label>Abandoned Cart 3</label>
1170
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
1171
+ <sort_order>90</sort_order>
1172
+ <show_in_default>1</show_in_default>
1173
+ <show_in_website>1</show_in_website>
1174
+ <show_in_store>0</show_in_store>
1175
+ </heading_3>
1176
+ <enabled_3 translate="label" module="ddg">
1177
+ <label>Enabled/Disabled</label>
1178
+ <frontend_type>select</frontend_type>
1179
+ <source_model>adminhtml/system_config_source_enabledisable</source_model>
1180
+ <sort_order>100</sort_order>
1181
+ <show_in_default>1</show_in_default>
1182
+ <show_in_website>1</show_in_website>
1183
+ <show_in_store>0</show_in_store>
1184
+ </enabled_3>
1185
+ <send_after_3 translate="label" module="ddg">
1186
+ <label>Send After (hrs)</label>
1187
+ <frontend_type>select</frontend_type>
1188
+ <source_model>ddg_automation/adminhtml_source_lostbaskets_interval</source_model>
1189
+ <sort_order>110</sort_order>
1190
+ <show_in_default>1</show_in_default>
1191
+ <show_in_website>1</show_in_website>
1192
+ <show_in_store>0</show_in_store>
1193
+ </send_after_3>
1194
+ <campaign_3 translate="label" module="ddg">
1195
+ <label>Campaign To Send</label>
1196
+ <frontend_type>select</frontend_type>
1197
+ <source_model>ddg_automation/adminhtml_source_campaigns</source_model>
1198
+ <sort_order>120</sort_order>
1199
+ <show_in_default>1</show_in_default>
1200
+ <show_in_website>1</show_in_website>
1201
+ <show_in_store>0</show_in_store>
1202
+ </campaign_3>
1203
+ </fields>
1204
+ </guests>
1205
+ </groups>
1206
+ </connector_lost_baskets>
1207
+ <connector_reviews translate="label" module="ddg">
1208
+ <label><![CDATA[Reviews]]></label>
1209
+ <tab>connector</tab>
1210
+ <frontend_type>text</frontend_type>
1211
+ <sort_order>6500</sort_order>
1212
+ <show_in_default>1</show_in_default>
1213
+ <show_in_website>1</show_in_website>
1214
+ <show_in_store>1</show_in_store>
1215
+ <groups>
1216
+ <settings translate="label" module="ddg">
1217
+ <label>Settings</label>
1218
+ <frontend_type>text</frontend_type>
1219
+ <sort_order>10</sort_order>
1220
+ <show_in_default>1</show_in_default>
1221
+ <show_in_website>1</show_in_website>
1222
+ <show_in_store>1</show_in_store>
1223
+ <expanded>1</expanded>
1224
+ <fields>
1225
+ <enabled translate="label" module="ddg">
1226
+ <label>Enabled</label>
1227
+ <frontend_type>select</frontend_type>
1228
+ <source_model>adminhtml/system_config_source_yesno</source_model>
1229
+ <sort_order>10</sort_order>
1230
+ <show_in_default>1</show_in_default>
1231
+ <show_in_website>1</show_in_website>
1232
+ <show_in_store>0</show_in_store>
1233
+ </enabled>
1234
+ <status translate="label" module="ddg">
1235
+ <label>Order Status</label>
1236
+ <sort_order>20</sort_order>
1237
+ <frontend_type>select</frontend_type>
1238
+ <source_model>adminhtml/system_config_source_order_status</source_model>
1239
+ <show_in_default>1</show_in_default>
1240
+ <show_in_website>1</show_in_website>
1241
+ <show_in_store>0</show_in_store>
1242
+ </status>
1243
+ <delay>
1244
+ <label>Delay Period (Days)</label>
1245
+ <sort_order>30</sort_order>
1246
+ <frontend_type>select</frontend_type>
1247
+ <source_model>ddg_automation/adminhtml_source_reviews_delay</source_model>
1248
+ <show_in_default>1</show_in_default>
1249
+ <show_in_website>1</show_in_website>
1250
+ <show_in_store>0</show_in_store>
1251
+ <comment><![CDATA[The system will send the reminder after the above mentioned amount of days upon order status selected above.]]></comment>
1252
+ </delay>
1253
+ <new_product>
1254
+ <label>New Product Only</label>
1255
+ <sort_order>40</sort_order>
1256
+ <frontend_type>select</frontend_type>
1257
+ <source_model>adminhtml/system_config_source_yesno</source_model>
1258
+ <show_in_default>1</show_in_default>
1259
+ <show_in_website>1</show_in_website>
1260
+ <show_in_store>0</show_in_store>
1261
+ <comment><![CDATA[Only include not purchased before products only.]]></comment>
1262
+ </new_product>
1263
+ <campaign>
1264
+ <label>Campaign To Send</label>
1265
+ <sort_order>50</sort_order>
1266
+ <frontend_type>select</frontend_type>
1267
+ <source_model>ddg_automation/adminhtml_source_reviews_campaigns</source_model>
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
+ </campaign>
1272
+ <anchor>
1273
+ <label>Reviews Anchor</label>
1274
+ <sort_order>60</sort_order>
1275
+ <frontend_type>text</frontend_type>
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
+ <comment><![CDATA[Please provide the anchor used on product pages for reviews e.g. #reviews]]></comment>
1280
+ </anchor>
1281
+ </fields>
1282
+ </settings>
1283
+ </groups>
1284
+ </connector_reviews>
1285
+ <connector_sms translate="label" module="ddg">
1286
+ <label><![CDATA[SMS]]></label>
1287
+ <tab>connector</tab>
1288
+ <frontend_type>text</frontend_type>
1289
+ <sort_order>7000</sort_order>
1290
+ <show_in_default>1</show_in_default>
1291
+ <show_in_website>1</show_in_website>
1292
+ <show_in_store>1</show_in_store>
1293
+ <groups>
1294
+ <sms_one translate="label" module="ddg">
1295
+ <label>SMS Message 1</label>
1296
+ <frontend_type>text</frontend_type>
1297
+ <sort_order>10</sort_order>
1298
+ <show_in_default>1</show_in_default>
1299
+ <show_in_website>1</show_in_website>
1300
+ <show_in_store>1</show_in_store>
1301
+ <fields>
1302
+ <enabled translate="label" module="ddg">
1303
+ <label>Enabled</label>
1304
+ <frontend_type>select</frontend_type>
1305
+ <source_model>adminhtml/system_config_source_yesno</source_model>
1306
+ <sort_order>10</sort_order>
1307
+ <show_in_default>1</show_in_default>
1308
+ <show_in_website>1</show_in_website>
1309
+ <show_in_store>1</show_in_store>
1310
+ </enabled>
1311
+ <status translate="label" module="ddg">
1312
+ <label>Order Status</label>
1313
+ <sort_order>20</sort_order>
1314
+ <frontend_type>select</frontend_type>
1315
+ <source_model>adminhtml/system_config_source_order_status</source_model>
1316
+ <show_in_default>1</show_in_default>
1317
+ <show_in_website>1</show_in_website>
1318
+ <show_in_store>1</show_in_store>
1319
+ </status>
1320
+ <message translate="label" module="ddg">
1321
+ <label>Message</label>
1322
+ <frontend_type>textarea</frontend_type>
1323
+ <frontend_model>ddg_automation/adminhtml_system_sms_smsmessageone</frontend_model>
1324
+ <sort_order>30</sort_order>
1325
+ <show_in_default>1</show_in_default>
1326
+ <show_in_website>1</show_in_website>
1327
+ <show_in_store>1</show_in_store>
1328
+ <validate>validate-length maximum-length-160</validate>
1329
+ </message>
1330
+ </fields>
1331
+ </sms_one>
1332
+ <sms_two translate="label" module="ddg">
1333
+ <label>SMS Message 2</label>
1334
+ <frontend_type>text</frontend_type>
1335
+ <sort_order>20</sort_order>
1336
+ <show_in_default>1</show_in_default>
1337
+ <show_in_website>1</show_in_website>
1338
+ <show_in_store>1</show_in_store>
1339
+ <fields>
1340
+ <enabled translate="label" module="ddg">
1341
+ <label>Enabled</label>
1342
+ <frontend_type>select</frontend_type>
1343
+ <source_model>adminhtml/system_config_source_yesno</source_model>
1344
+ <sort_order>10</sort_order>
1345
+ <show_in_default>1</show_in_default>
1346
+ <show_in_website>1</show_in_website>
1347
+ <show_in_store>1</show_in_store>
1348
+ </enabled>
1349
+ <status translate="label" module="ddg">
1350
+ <label>Order Status</label>
1351
+ <sort_order>20</sort_order>
1352
+ <frontend_type>select</frontend_type>
1353
+ <source_model>adminhtml/system_config_source_order_status</source_model>
1354
+ <show_in_default>1</show_in_default>
1355
+ <show_in_website>1</show_in_website>
1356
+ <show_in_store>1</show_in_store>
1357
+ </status>
1358
+ <message translate="label" module="ddg">
1359
+ <label>Message</label>
1360
+ <frontend_type>textarea</frontend_type>
1361
+ <frontend_model>ddg_automation/adminhtml_system_sms_smsmessagetwo</frontend_model>
1362
+ <sort_order>30</sort_order>
1363
+ <show_in_default>1</show_in_default>
1364
+ <show_in_website>1</show_in_website>
1365
+ <show_in_store>1</show_in_store>
1366
+ <validate>validate-length maximum-length-160</validate>
1367
+ </message>
1368
+ </fields>
1369
+ </sms_two>
1370
+ <sms_three translate="label" module="ddg">
1371
+ <label>SMS Message 3</label>
1372
+ <frontend_type>text</frontend_type>
1373
+ <sort_order>30</sort_order>
1374
+ <show_in_default>1</show_in_default>
1375
+ <show_in_website>1</show_in_website>
1376
+ <show_in_store>1</show_in_store>
1377
+ <fields>
1378
+ <enabled translate="label" module="ddg">
1379
+ <label>Enabled</label>
1380
+ <frontend_type>select</frontend_type>
1381
+ <source_model>adminhtml/system_config_source_yesno</source_model>
1382
+ <sort_order>10</sort_order>
1383
+ <show_in_default>1</show_in_default>
1384
+ <show_in_website>1</show_in_website>
1385
+ <show_in_store>1</show_in_store>
1386
+ </enabled>
1387
+ <status translate="label" module="ddg">
1388
+ <label>Order Status</label>
1389
+ <sort_order>20</sort_order>
1390
+ <frontend_type>select</frontend_type>
1391
+ <source_model>adminhtml/system_config_source_order_status</source_model>
1392
+ <show_in_default>1</show_in_default>
1393
+ <show_in_website>1</show_in_website>
1394
+ <show_in_store>1</show_in_store>
1395
+ </status>
1396
+ <message translate="label" module="ddg">
1397
+ <label>Message</label>
1398
+ <frontend_type>textarea</frontend_type>
1399
+ <frontend_model>ddg_automation/adminhtml_system_sms_smsmessagethree</frontend_model>
1400
+ <sort_order>30</sort_order>
1401
+ <show_in_default>1</show_in_default>
1402
+ <show_in_website>1</show_in_website>
1403
+ <show_in_store>1</show_in_store>
1404
+ <validate>validate-length maximum-length-160</validate>
1405
+ </message>
1406
+ </fields>
1407
+ </sms_three>
1408
+ <sms_four translate="label" module="ddg">
1409
+ <label>SMS Message 4</label>
1410
+ <frontend_type>text</frontend_type>
1411
+ <sort_order>40</sort_order>
1412
+ <show_in_default>1</show_in_default>
1413
+ <show_in_website>1</show_in_website>
1414
+ <show_in_store>1</show_in_store>
1415
+ <fields>
1416
+ <enabled translate="label" module="ddg">
1417
+ <label>Enabled</label>
1418
+ <frontend_type>select</frontend_type>
1419
+ <source_model>adminhtml/system_config_source_yesno</source_model>
1420
+ <sort_order>10</sort_order>
1421
+ <show_in_default>1</show_in_default>
1422
+ <show_in_website>1</show_in_website>
1423
+ <show_in_store>1</show_in_store>
1424
+ </enabled>
1425
+ <status translate="label" module="ddg">
1426
+ <label>Order Status</label>
1427
+ <sort_order>20</sort_order>
1428
+ <frontend_type>select</frontend_type>
1429
+ <source_model>adminhtml/system_config_source_order_status</source_model>
1430
+ <show_in_default>1</show_in_default>
1431
+ <show_in_website>1</show_in_website>
1432
+ <show_in_store>1</show_in_store>
1433
+ </status>
1434
+ <message translate="label" module="ddg">
1435
+ <label>Message</label>
1436
+ <frontend_type>textarea</frontend_type>
1437
+ <frontend_model>ddg_automation/adminhtml_system_sms_smsmessagefour</frontend_model>
1438
+ <sort_order>30</sort_order>
1439
+ <show_in_default>1</show_in_default>
1440
+ <show_in_website>1</show_in_website>
1441
+ <show_in_store>1</show_in_store>
1442
+ <validate>validate-length maximum-length-160</validate>
1443
+ </message>
1444
+ </fields>
1445
+ </sms_four>
1446
+ </groups>
1447
+ </connector_sms>
1448
+ <connector_dynamic_content translate="label" module="ddg">
1449
+ <label><![CDATA[Dynamic Content]]></label>
1450
+ <tab>connector</tab>
1451
+ <frontend_type>text</frontend_type>
1452
+ <sort_order>8000</sort_order>
1453
+ <show_in_default>1</show_in_default>
1454
+ <show_in_website>1</show_in_website>
1455
+ <show_in_store>0</show_in_store>
1456
+ <groups>
1457
+ <products translate="label" module="ddg">
1458
+ <label>Dynamic Products</label>
1459
+ <frontend_type>text</frontend_type>
1460
+ <sort_order>20</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
+ <review translate="label" module="ddg">
1466
+ <label>Reviews</label>
1467
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
1468
+ <sort_order>3</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
+ </review>
1473
+ <review_display_type translate="label" module="ddg">
1474
+ <label>Display Type</label>
1475
+ <frontend_type>select</frontend_type>
1476
+ <source_model>ddg_automation/adminhtml_source_dynamic_displaytype</source_model>
1477
+ <sort_order>6</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
+ </review_display_type>
1482
+ <related translate="label" module="ddg">
1483
+ <label>Related Products</label>
1484
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
1485
+ <sort_order>10</sort_order>
1486
+ <show_in_default>1</show_in_default>
1487
+ <show_in_website>1</show_in_website>
1488
+ <show_in_store>0</show_in_store>
1489
+ </related>
1490
+ <related_display_type translate="label" module="ddg">
1491
+ <label>Display Type</label>
1492
+ <frontend_type>select</frontend_type>
1493
+ <source_model>ddg_automation/adminhtml_source_dynamic_displaytype</source_model>
1494
+ <sort_order>20</sort_order>
1495
+ <show_in_default>1</show_in_default>
1496
+ <show_in_website>1</show_in_website>
1497
+ <show_in_store>0</show_in_store>
1498
+ </related_display_type>
1499
+ <related_items_to_display translate="label" module="ddg">
1500
+ <label>Items To Display</label>
1501
+ <frontend_type>select</frontend_type>
1502
+ <source_model>ddg_automation/adminhtml_source_dynamic_gridview</source_model>
1503
+ <sort_order>30</sort_order>
1504
+ <show_in_website>1</show_in_website>
1505
+ <show_in_default>1</show_in_default>
1506
+ <show_in_store>0</show_in_store>
1507
+ </related_items_to_display>
1508
+ <upsell translate="label" module="ddg">
1509
+ <label>Up Sell Products</label>
1510
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
1511
+ <sort_order>40</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
+ </upsell>
1516
+ <upsell_display_type translate="label" module="ddg">
1517
+ <label>Display Type</label>
1518
+ <frontend_type>select</frontend_type>
1519
+ <source_model>ddg_automation/adminhtml_source_dynamic_displaytype</source_model>
1520
+ <sort_order>50</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
+ </upsell_display_type>
1525
+ <upsell_items_to_display translate="label" module="ddg">
1526
+ <label>Items To Display</label>
1527
+ <frontend_type>select</frontend_type>
1528
+ <source_model>ddg_automation/adminhtml_source_dynamic_gridview</source_model>
1529
+ <sort_order>60</sort_order>
1530
+ <show_in_website>1</show_in_website>
1531
+ <show_in_default>1</show_in_default>
1532
+ <show_in_store>0</show_in_store>
1533
+ </upsell_items_to_display>
1534
+ <crosssell translate="label" module="ddg">
1535
+ <label>Cross Sell Products</label>
1536
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
1537
+ <sort_order>70</sort_order>
1538
+ <show_in_default>1</show_in_default>
1539
+ <show_in_website>1</show_in_website>
1540
+ <show_in_store>0</show_in_store>
1541
+ </crosssell>
1542
+ <crosssell_display_type translate="label" module="ddg">
1543
+ <label>Display Type</label>
1544
+ <frontend_type>select</frontend_type>
1545
+ <source_model>ddg_automation/adminhtml_source_dynamic_displaytype</source_model>
1546
+ <sort_order>80</sort_order>
1547
+ <show_in_default>1</show_in_default>
1548
+ <show_in_website>1</show_in_website>
1549
+ <show_in_store>0</show_in_store>
1550
+ </crosssell_display_type>
1551
+ <crosssell_items_to_display translate="label" module="ddg">
1552
+ <label>Items To Display</label>
1553
+ <frontend_type>select</frontend_type>
1554
+ <source_model>ddg_automation/adminhtml_source_dynamic_gridview</source_model>
1555
+ <sort_order>90</sort_order>
1556
+ <show_in_website>1</show_in_website>
1557
+ <show_in_default>1</show_in_default>
1558
+ <show_in_store>0</show_in_store>
1559
+ </crosssell_items_to_display>
1560
+ <bestsellers translate="label" module="ddg">
1561
+ <label>Best Sellers</label>
1562
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
1563
+ <sort_order>100</sort_order>
1564
+ <show_in_default>1</show_in_default>
1565
+ <show_in_website>1</show_in_website>
1566
+ <show_in_store>0</show_in_store>
1567
+ </bestsellers>
1568
+ <bestsellers_display_type translate="label" module="ddg">
1569
+ <label>Display Type</label>
1570
+ <frontend_type>select</frontend_type>
1571
+ <source_model>ddg_automation/adminhtml_source_dynamic_displaytype</source_model>
1572
+ <sort_order>110</sort_order>
1573
+ <show_in_default>1</show_in_default>
1574
+ <show_in_website>1</show_in_website>
1575
+ <show_in_store>0</show_in_store>
1576
+ </bestsellers_display_type>
1577
+ <bestsellers_items_to_display translate="label" module="ddg">
1578
+ <label>Items To Display</label>
1579
+ <frontend_type>select</frontend_type>
1580
+ <source_model>ddg_automation/adminhtml_source_dynamic_gridview</source_model>
1581
+ <sort_order>120</sort_order>
1582
+ <show_in_website>1</show_in_website>
1583
+ <show_in_default>1</show_in_default>
1584
+ <show_in_store>0</show_in_store>
1585
+ </bestsellers_items_to_display>
1586
+ <bestsellers_time_period translate="label" module="ddg">
1587
+ <label>Time Period</label>
1588
+ <frontend_type>select</frontend_type>
1589
+ <source_model>adminhtml/system_config_source_cron_frequency</source_model>
1590
+ <sort_order>130</sort_order>
1591
+ <show_in_default>1</show_in_default>
1592
+ <show_in_website>1</show_in_website>
1593
+ <show_in_store>0</show_in_store>
1594
+ </bestsellers_time_period>
1595
+ <most_viewed translate="label" module="ddg">
1596
+ <label>Most Viewed</label>
1597
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
1598
+ <sort_order>140</sort_order>
1599
+ <show_in_default>1</show_in_default>
1600
+ <show_in_website>1</show_in_website>
1601
+ <show_in_store>0</show_in_store>
1602
+ </most_viewed>
1603
+ <most_viewed_display_type translate="label" module="ddg">
1604
+ <label>Display Type</label>
1605
+ <frontend_type>select</frontend_type>
1606
+ <source_model>ddg_automation/adminhtml_source_dynamic_displaytype</source_model>
1607
+ <sort_order>150</sort_order>
1608
+ <show_in_default>1</show_in_default>
1609
+ <show_in_website>1</show_in_website>
1610
+ <show_in_store>0</show_in_store>
1611
+ </most_viewed_display_type>
1612
+ <most_viewed_items_to_display translate="label" module="ddg">
1613
+ <label>Items To Display</label>
1614
+ <frontend_type>select</frontend_type>
1615
+ <source_model>ddg_automation/adminhtml_source_dynamic_gridview</source_model>
1616
+ <sort_order>160</sort_order>
1617
+ <show_in_website>1</show_in_website>
1618
+ <show_in_default>1</show_in_default>
1619
+ <show_in_store>0</show_in_store>
1620
+ </most_viewed_items_to_display>
1621
+ <most_viewed_time_period translate="label" module="ddg">
1622
+ <label>Time Period</label>
1623
+ <frontend_type>select</frontend_type>
1624
+ <source_model>adminhtml/system_config_source_cron_frequency</source_model>
1625
+ <sort_order>170</sort_order>
1626
+ <show_in_default>1</show_in_default>
1627
+ <show_in_website>1</show_in_website>
1628
+ <show_in_store>0</show_in_store>
1629
+ </most_viewed_time_period>
1630
+ <recently_viewed translate="label" module="ddg">
1631
+ <label>Recently Viewed</label>
1632
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
1633
+ <sort_order>180</sort_order>
1634
+ <show_in_default>1</show_in_default>
1635
+ <show_in_website>1</show_in_website>
1636
+ <show_in_store>0</show_in_store>
1637
+ </recently_viewed>
1638
+ <recently_viewed_display_type translate="label" module="ddg">
1639
+ <label>Display Type</label>
1640
+ <frontend_type>select</frontend_type>
1641
+ <source_model>ddg_automation/adminhtml_source_dynamic_displaytype</source_model>
1642
+ <sort_order>190</sort_order>
1643
+ <show_in_default>1</show_in_default>
1644
+ <show_in_website>1</show_in_website>
1645
+ <show_in_store>0</show_in_store>
1646
+ </recently_viewed_display_type>
1647
+ <recently_viewed_items_to_display translate="label" module="ddg">
1648
+ <label>items To Display</label>
1649
+ <frontend_type>select</frontend_type>
1650
+ <source_model>ddg_automation/adminhtml_source_dynamic_gridview</source_model>
1651
+ <sort_order>200</sort_order>
1652
+ <show_in_default>1</show_in_default>
1653
+ <show_in_website>1</show_in_website>
1654
+ <show_in_store>0</show_in_store>
1655
+ </recently_viewed_items_to_display>
1656
+ <validator module="ddg">
1657
+ <frontend_type>hidden</frontend_type>
1658
+ <frontend_model>ddg_automation/adminhtml_system_dynamic_gridlist</frontend_model>
1659
+ <sort_order>210</sort_order>
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
+ <can_be_empty>1</can_be_empty>
1664
+ </validator>
1665
+ </fields>
1666
+ </products>
1667
+ <external_dynamic_content_urls translate="label" module="ddg">
1668
+ <label><![CDATA[External Dynamic Content URL's]]></label>
1669
+ <frontend_type>text</frontend_type>
1670
+ <sort_order>10</sort_order>
1671
+ <show_in_default>1</show_in_default>
1672
+ <show_in_website>1</show_in_website>
1673
+ <show_in_store>0</show_in_store>
1674
+ <fields>
1675
+ <passcode translate="label comment" module="ddg">
1676
+ <label>Passcode</label>
1677
+ <frontend_type>text</frontend_type>
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
+ <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>
1683
+ </passcode>
1684
+ <lost_basket_title translate="label" module="ddg">
1685
+ <label>Abandoned Carts</label>
1686
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
1687
+ <sort_order>20</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
+ </lost_basket_title>
1692
+ <lost_basket_url translate="label" module="ddg">
1693
+ <label>Cart Content URL</label>
1694
+ <frontend_type>label</frontend_type>
1695
+ <frontend_model>ddg_automation/adminhtml_system_dynamic_lostbasket</frontend_model>
1696
+ <sort_order>30</sort_order>
1697
+ <show_in_default>1</show_in_default>
1698
+ <show_in_website>1</show_in_website>
1699
+ <show_in_store>0</show_in_store>
1700
+ </lost_basket_url>
1701
+ <review_title title="label" module="ddg">
1702
+ <label>Reviews</label>
1703
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
1704
+ <sort_order>33</sort_order>
1705
+ <show_in_website>1</show_in_website>
1706
+ <show_in_default>1</show_in_default>
1707
+ <show_in_store>0</show_in_store>
1708
+ </review_title>
1709
+ <review_url translate="label" module="ddg">
1710
+ <label>Order Contents</label>
1711
+ <frontend_type>label</frontend_type>
1712
+ <frontend_model>ddg_automation/adminhtml_system_dynamic_review</frontend_model>
1713
+ <sort_order>36</sort_order>
1714
+ <show_in_default>1</show_in_default>
1715
+ <show_in_website>1</show_in_website>
1716
+ <show_in_store>0</show_in_store>
1717
+ </review_url>
1718
+ <coupon_code_title title="label" module="ddg">
1719
+ <label>Coupon Codes</label>
1720
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
1721
+ <sort_order>40</sort_order>
1722
+ <show_in_website>1</show_in_website>
1723
+ <show_in_default>1</show_in_default>
1724
+ <show_in_store>0</show_in_store>
1725
+ </coupon_code_title>
1726
+ <coupon_code_url translate="label" module="ddg">
1727
+ <label>Coupon Codes URL</label>
1728
+ <frontend_type>label</frontend_type>
1729
+ <frontend_model>ddg_automation/adminhtml_system_dynamic_couponinfo</frontend_model>
1730
+ <sort_order>50</sort_order>
1731
+ <show_in_default>1</show_in_default>
1732
+ <show_in_website>1</show_in_website>
1733
+ <show_in_store>0</show_in_store>
1734
+ </coupon_code_url>
1735
+ <order_dynamic_content_url translate="label" module="ddg">
1736
+ <label>Order Recommendation</label>
1737
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
1738
+ <sort_order>60</sort_order>
1739
+ <show_in_default>1</show_in_default>
1740
+ <show_in_website>1</show_in_website>
1741
+ <show_in_store>0</show_in_store>
1742
+ </order_dynamic_content_url>
1743
+ <related_products_url translate="label" module="ddg">
1744
+ <label>Related Products URL</label>
1745
+ <frontend_type>label</frontend_type>
1746
+ <frontend_model>ddg_automation/adminhtml_system_dynamic_related</frontend_model>
1747
+ <sort_order>70</sort_order>
1748
+ <show_in_default>1</show_in_default>
1749
+ <show_in_website>1</show_in_website>
1750
+ <show_in_store>0</show_in_store>
1751
+ </related_products_url>
1752
+ <upsell_products_url translate="label" module="ddg">
1753
+ <label>Up-Sell Products URL</label>
1754
+ <frontend_type>label</frontend_type>
1755
+ <frontend_model>ddg_automation/adminhtml_system_dynamic_upsell</frontend_model>
1756
+ <sort_order>80</sort_order>
1757
+ <show_in_default>1</show_in_default>
1758
+ <show_in_website>1</show_in_website>
1759
+ <show_in_store>0</show_in_store>
1760
+ </upsell_products_url>
1761
+ <crosssell_products_url translate="label" module="ddg">
1762
+ <label>Cross-Sell Products URL</label>
1763
+ <frontend_type>label</frontend_type>
1764
+ <frontend_model>ddg_automation/adminhtml_system_dynamic_crosssell</frontend_model>
1765
+ <sort_order>90</sort_order>
1766
+ <show_in_default>1</show_in_default>
1767
+ <show_in_website>1</show_in_website>
1768
+ <show_in_store>0</show_in_store>
1769
+ </crosssell_products_url>
1770
+ <basket_dynamic_content_url translate="label" module="ddg">
1771
+ <label>Cart Recommendation</label>
1772
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
1773
+ <sort_order>91</sort_order>
1774
+ <show_in_default>1</show_in_default>
1775
+ <show_in_website>1</show_in_website>
1776
+ <show_in_store>0</show_in_store>
1777
+ </basket_dynamic_content_url>
1778
+ <basket_related_products_url translate="label" module="ddg">
1779
+ <label>Related Products URL</label>
1780
+ <frontend_type>label</frontend_type>
1781
+ <frontend_model>ddg_automation/adminhtml_system_dynamic_basket_related</frontend_model>
1782
+ <sort_order>92</sort_order>
1783
+ <show_in_default>1</show_in_default>
1784
+ <show_in_website>1</show_in_website>
1785
+ <show_in_store>0</show_in_store>
1786
+ </basket_related_products_url>
1787
+ <basket_upsell_products_url translate="label" module="ddg">
1788
+ <label>Up-Sell Products URL</label>
1789
+ <frontend_type>label</frontend_type>
1790
+ <frontend_model>ddg_automation/adminhtml_system_dynamic_basket_upsell</frontend_model>
1791
+ <sort_order>93</sort_order>
1792
+ <show_in_default>1</show_in_default>
1793
+ <show_in_website>1</show_in_website>
1794
+ <show_in_store>0</show_in_store>
1795
+ </basket_upsell_products_url>
1796
+ <basket_crosssell_products_url translate="label" module="ddg">
1797
+ <label>Cross-Sell Products URL</label>
1798
+ <frontend_type>label</frontend_type>
1799
+ <frontend_model>ddg_automation/adminhtml_system_dynamic_basket_crosssell</frontend_model>
1800
+ <sort_order>94</sort_order>
1801
+ <show_in_default>1</show_in_default>
1802
+ <show_in_website>1</show_in_website>
1803
+ <show_in_store>0</show_in_store>
1804
+ </basket_crosssell_products_url>
1805
+ <product_dynamic_content_url translate="label" module="ddg">
1806
+ <label>Product Recommendation</label>
1807
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
1808
+ <sort_order>100</sort_order>
1809
+ <show_in_default>1</show_in_default>
1810
+ <show_in_website>1</show_in_website>
1811
+ <show_in_store>0</show_in_store>
1812
+ </product_dynamic_content_url>
1813
+ <best_sellers_url translate="label" module="ddg">
1814
+ <label>Best Sellers URL</label>
1815
+ <frontend_type>label</frontend_type>
1816
+ <frontend_model>ddg_automation/adminhtml_system_dynamic_bestsellers</frontend_model>
1817
+ <sort_order>110</sort_order>
1818
+ <show_in_default>1</show_in_default>
1819
+ <show_in_website>1</show_in_website>
1820
+ <show_in_store>0</show_in_store>
1821
+ <comment><![CDATA[add category_id/@CATEGORY_ID@ at the end of url to filter best sellers by category]]></comment>
1822
+ </best_sellers_url>
1823
+ <most_viewed_url translate="label" module="ddg">
1824
+ <label>Most Viewed URL</label>
1825
+ <frontend_type>label</frontend_type>
1826
+ <frontend_model>ddg_automation/adminhtml_system_dynamic_mostviewed</frontend_model>
1827
+ <sort_order>120</sort_order>
1828
+ <show_in_default>1</show_in_default>
1829
+ <show_in_website>1</show_in_website>
1830
+ <show_in_store>0</show_in_store>
1831
+ <comment><![CDATA[add category_id/@CATEGORY_ID@ at the end of url to filter most viewed by category]]></comment>
1832
+ </most_viewed_url>
1833
+ <product_push_url translate="label" module="ddg">
1834
+ <label>Product Push URL</label>
1835
+ <frontend_type>label</frontend_type>
1836
+ <frontend_model>ddg_automation/adminhtml_system_dynamic_productpush</frontend_model>
1837
+ <sort_order>130</sort_order>
1838
+ <show_in_default>1</show_in_default>
1839
+ <show_in_website>1</show_in_website>
1840
+ <show_in_store>0</show_in_store>
1841
+ </product_push_url>
1842
+ <recently_viewed_url translate="label" module="ddg">
1843
+ <label>Recently Viewed</label>
1844
+ <frontend_type>label</frontend_type>
1845
+ <frontend_model>ddg_automation/adminhtml_system_dynamic_recentlyviewed</frontend_model>
1846
+ <sort_order>140</sort_order>
1847
+ <show_in_default>1</show_in_default>
1848
+ <show_in_website>1</show_in_website>
1849
+ <show_in_store>0</show_in_store>
1850
+ </recently_viewed_url>
1851
+ </fields>
1852
+ </external_dynamic_content_urls>
1853
+ <manual_product_search translate="label" module="ddg">
1854
+ <label>Manual Product Push</label>
1855
+ <frontend_type>text</frontend_type>
1856
+ <sort_order>30</sort_order>
1857
+ <show_in_default>1</show_in_default>
1858
+ <show_in_website>1</show_in_website>
1859
+ <show_in_store>0</show_in_store>
1860
+ <expanded>1</expanded>
1861
+ <fields>
1862
+ <settings_title tranlate="label" module="ddg">
1863
+ <label>Settings</label>
1864
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
1865
+ <sort_order>10</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
+ </settings_title>
1870
+ <display_type translate="label" module="ddg">
1871
+ <label>Display Type</label>
1872
+ <frontend_type>select</frontend_type>
1873
+ <source_model>ddg_automation/adminhtml_source_dynamic_displaytype</source_model>
1874
+ <sort_order>50</sort_order>
1875
+ <show_in_default>1</show_in_default>
1876
+ <show_in_website>1</show_in_website>
1877
+ <show_in_store>0</show_in_store>
1878
+ </display_type>
1879
+ <items_to_display translate="label" module="ddg">
1880
+ <label>Items To Display</label>
1881
+ <frontend_type>select</frontend_type>
1882
+ <source_model>ddg_automation/adminhtml_source_dynamic_gridview</source_model>
1883
+ <sort_order>60</sort_order>
1884
+ <show_in_website>1</show_in_website>
1885
+ <show_in_default>1</show_in_default>
1886
+ <show_in_store>0</show_in_store>
1887
+ </items_to_display>
1888
+ <products_push_title translate="label" module="ddg">
1889
+ <label>Products</label>
1890
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
1891
+ <sort_order>80</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
+ </products_push_title>
1896
+ <products_chooser_button translate="label comment" module="ddg">
1897
+ <frontend_model>ddg_automation/adminhtml_system_dynamic_manualchooser</frontend_model>
1898
+ <sort_order>85</sort_order>
1899
+ <show_in_default>1</show_in_default>
1900
+ <show_in_website>1</show_in_website>
1901
+ <show_in_store>0</show_in_store>
1902
+ <comment><![CDATA[Click To Open Product Chooser. After Choosing Products Save Config.]]></comment>
1903
+ </products_chooser_button>
1904
+ <products_push_items translate="label comment" module="ddg">
1905
+ <label>Products</label>
1906
+ <frontend_type>text</frontend_type>
1907
+ <sort_order>90</sort_order>
1908
+ <show_in_default>1</show_in_default>
1909
+ <show_in_website>1</show_in_website>
1910
+ <show_in_store>0</show_in_store>
1911
+ <comment><![CDATA[Comma Separated Product Id's]]></comment>
1912
+ </products_push_items>
1913
+ <products_chooser_container translate="label comment" module="ddg">
1914
+ <frontend_model>ddg_automation/adminhtml_system_dynamic_manualcontainer</frontend_model>
1915
+ <sort_order>95</sort_order>
1916
+ <show_in_default>1</show_in_default>
1917
+ <show_in_website>1</show_in_website>
1918
+ <show_in_store>0</show_in_store>
1919
+ </products_chooser_container>
1920
+ </fields>
1921
+ </manual_product_search>
1922
+ <fallback_products translate="label" module="ddg">
1923
+ <label>Fallback Products</label>
1924
+ <frontend_type>text</frontend_type>
1925
+ <sort_order>40</sort_order>
1926
+ <show_in_default>1</show_in_default>
1927
+ <show_in_website>1</show_in_website>
1928
+ <show_in_store>0</show_in_store>
1929
+ <fields>
1930
+ <products_chooser_button translate="label comment" module="ddg">
1931
+ <frontend_model>ddg_automation/adminhtml_system_dynamic_fallbackchooser</frontend_model>
1932
+ <sort_order>5</sort_order>
1933
+ <show_in_default>1</show_in_default>
1934
+ <show_in_website>1</show_in_website>
1935
+ <show_in_store>0</show_in_store>
1936
+ <comment><![CDATA[Click To Open Product Chooser. After Choosing Products Save Config.]]></comment>
1937
+ </products_chooser_button>
1938
+ <product_list translate="label comment" module="ddg">
1939
+ <label>Products</label>
1940
+ <frontend_type>text</frontend_type>
1941
+ <sort_order>10</sort_order>
1942
+ <show_in_default>1</show_in_default>
1943
+ <show_in_website>1</show_in_website>
1944
+ <show_in_store>0</show_in_store>
1945
+ <comment><![CDATA[Comma Separated Product Id's]]></comment>
1946
+ </product_list>
1947
+ <products_chooser_container translate="label comment" module="ddg">
1948
+ <frontend_model>ddg_automation/adminhtml_system_dynamic_fallbackcontainer</frontend_model>
1949
+ <sort_order>15</sort_order>
1950
+ <show_in_default>1</show_in_default>
1951
+ <show_in_website>1</show_in_website>
1952
+ <show_in_store>0</show_in_store>
1953
+ </products_chooser_container>
1954
+ </fields>
1955
+ </fallback_products>
1956
+ <nosto_recommendation translate="label" module="ddg">
1957
+ <label>Nosto Recommendations</label>
1958
+ <sort_order>50</sort_order>
1959
+ <show_in_default>1</show_in_default>
1960
+ <show_in_website>1</show_in_website>
1961
+ <show_in_store>0</show_in_store>
1962
+ <fields>
1963
+ <api translate="label" module="ddg">
1964
+ <label>API key</label>
1965
+ <sort_order>10</sort_order>
1966
+ <show_in_default>1</show_in_default>
1967
+ <show_in_website>1</show_in_website>
1968
+ <show_in_store>0</show_in_store>
1969
+ </api>
1970
+ <dynamic_url traslate="label" module="ddg">
1971
+ <label>Recommendation URL</label>
1972
+ <frontend_type>label</frontend_type>
1973
+ <frontend_model>ddg_automation/adminhtml_system_dynamic_nosto</frontend_model>
1974
+ <sort_order>20</sort_order>
1975
+ <show_in_default>1</show_in_default>
1976
+ <show_in_website>1</show_in_website>
1977
+ <show_in_store>0</show_in_store>
1978
+ <comment><![CDATA[Replace @SLOT_NAME@ with the slot name created in your Nosto account.]]></comment>
1979
+ </dynamic_url>
1980
+ </fields>
1981
+ </nosto_recommendation>
1982
+ <feefo_feedback_engine translate="label" module="ddg">
1983
+ <label>Feefo Feedback Engine</label>
1984
+ <sort_order>100</sort_order>
1985
+ <show_in_default>1</show_in_default>
1986
+ <show_in_website>1</show_in_website>
1987
+ <show_in_store>0</show_in_store>
1988
+ <fields>
1989
+ <logon translate="label" module="ddg">
1990
+ <label>Feefo Logon</label>
1991
+ <sort_order>10</sort_order>
1992
+ <show_in_default>1</show_in_default>
1993
+ <show_in_website>1</show_in_website>
1994
+ <show_in_store>0</show_in_store>
1995
+ <comment><![CDATA[This is what you provided Feefo during account setup and is usually your website domain name.]]></comment>
1996
+ </logon>
1997
+ <reviews_per_product>
1998
+ <label>Reviews Per Product</label>
1999
+ <sort_order>20</sort_order>
2000
+ <show_in_default>1</show_in_default>
2001
+ <show_in_website>1</show_in_website>
2002
+ <show_in_store>0</show_in_store>
2003
+ <comment><![CDATA[Number of reviews to display per product.]]></comment>
2004
+ </reviews_per_product>
2005
+ <template>
2006
+ <label>Logo Template (Optional)</label>
2007
+ <sort_order>25</sort_order>
2008
+ <show_in_default>1</show_in_default>
2009
+ <show_in_website>1</show_in_website>
2010
+ <show_in_store>0</show_in_store>
2011
+ <comment><![CDATA[Enter name of logo template. ]]></comment>
2012
+ </template>
2013
+ <service_score_url traslate="label" module="ddg">
2014
+ <label>Service Score URL</label>
2015
+ <frontend_type>label</frontend_type>
2016
+ <frontend_model>ddg_automation/adminhtml_system_dynamic_feefo_score</frontend_model>
2017
+ <sort_order>30</sort_order>
2018
+ <show_in_default>1</show_in_default>
2019
+ <show_in_website>1</show_in_website>
2020
+ <show_in_store>0</show_in_store>
2021
+ <comment><![CDATA[Enter Feefo logon above before using this URL.]]></comment>
2022
+ </service_score_url>
2023
+ <product_reviews_url traslate="label" module="ddg">
2024
+ <label>Product Reviews URL</label>
2025
+ <frontend_type>label</frontend_type>
2026
+ <frontend_model>ddg_automation/adminhtml_system_dynamic_feefo_reviews</frontend_model>
2027
+ <sort_order>40</sort_order>
2028
+ <show_in_default>1</show_in_default>
2029
+ <show_in_website>1</show_in_website>
2030
+ <show_in_store>0</show_in_store>
2031
+ <comment><![CDATA[Enter Feefo logon above before using this URL.]]></comment>
2032
+ </product_reviews_url>
2033
+ </fields>
2034
+ </feefo_feedback_engine>
2035
+ </groups>
2036
+ </connector_dynamic_content>
2037
+ <connector_transactional_emails translate="label" module="ddg">
2038
+ <label>Transactional Emails</label>
2039
+ <tab>connector</tab>
2040
+ <frontend_type>text</frontend_type>
2041
+ <show_in_default>1</show_in_default>
2042
+ <show_in_website>1</show_in_website>
2043
+ <show_in_store>0</show_in_store>
2044
+ <sort_order>7000</sort_order>
2045
+ <groups>
2046
+ <ddg_transactional translate="label" module="ddg">
2047
+ <label>DDG Transactional</label>
2048
+ <frontend_type>text</frontend_type>
2049
+ <sort_order>9000</sort_order>
2050
+ <show_in_default>1</show_in_default>
2051
+ <show_in_website>1</show_in_website>
2052
+ <show_in_store>0</show_in_store>
2053
+ <expanded>1</expanded>
2054
+ <fields>
2055
+ <enabled translate="label" module="ddg">
2056
+ <label>Enabled</label>
2057
+ <frontend_type>select</frontend_type>
2058
+ <source_model>ddg_automation/adminhtml_source_transactional_yesno</source_model>
2059
+ <sort_order>10</sort_order>
2060
+ <show_in_default>1</show_in_default>
2061
+ <show_in_website>1</show_in_website>
2062
+ <show_in_store>0</show_in_store>
2063
+ <comment><![CDATA[<p id="smtp-warning" style="display:none;" class="notice">DOTMAILER TRANSACTIONAL EMAIL EXTENSION HAS TO BE INSTALLED AND ENABLED IN ORDER TO USE THIS FEATURE.</p>]]></comment>
2064
+ </enabled>
2065
+ <validator module="ddg">
2066
+ <frontend_type>hidden</frontend_type>
2067
+ <frontend_model>ddg_automation/adminhtml_system_config_smtpvalidator</frontend_model>
2068
+ <sort_order>20</sort_order>
2069
+ <show_in_default>1</show_in_default>
2070
+ <show_in_website>1</show_in_website>
2071
+ <show_in_store>0</show_in_store>
2072
+ <can_be_empty>1</can_be_empty>
2073
+ </validator>
2074
+ </fields>
2075
+ </ddg_transactional>
2076
+ </groups>
2077
+ </connector_transactional_emails>
2078
+ <connector_automation_studio translate="label" module="ddg">
2079
+ <label>Automation</label>
2080
+ <tab>connector</tab>
2081
+ <frontend_type>text</frontend_type>
2082
+ <sort_order>4000</sort_order>
2083
+ <show_in_default>1</show_in_default>
2084
+ <show_in_website>1</show_in_website>
2085
+ <show_in_store>0</show_in_store>
2086
+ <groups>
2087
+ <automation translate="label" module="ddg">
2088
+ <label>Automation</label>
2089
+ <frontend_type>text</frontend_type>
2090
+ <show_in_default>1</show_in_default>
2091
+ <show_in_website>1</show_in_website>
2092
+ <show_in_store>0</show_in_store>
2093
+ <expanded>1</expanded>
2094
+ <fields>
2095
+ <customer_automation translate="label" module="ddg">
2096
+ <label>Customer Program</label>
2097
+ <frontend_type>select</frontend_type>
2098
+ <source_model>ddg_automation/adminhtml_source_automation_programme</source_model>
2099
+ <show_in_default>1</show_in_default>
2100
+ <show_in_website>1</show_in_website>
2101
+ <show_in_store>0</show_in_store>
2102
+ <sort_order>100</sort_order>
2103
+ </customer_automation>
2104
+ <subscriber_automation>
2105
+ <label>Subscriber Program</label>
2106
+ <frontend_type>select</frontend_type>
2107
+ <source_model>ddg_automation/adminhtml_source_automation_programme</source_model>
2108
+ <show_in_default>1</show_in_default>
2109
+ <show_in_website>1</show_in_website>
2110
+ <show_in_store>0</show_in_store>
2111
+ <sort_order>110</sort_order>
2112
+ </subscriber_automation>
2113
+ <order_automation>
2114
+ <label>Customer Order</label>
2115
+ <frontend_type>select</frontend_type>
2116
+ <source_model>ddg_automation/adminhtml_source_automation_programme</source_model>
2117
+ <show_in_default>1</show_in_default>
2118
+ <show_in_website>1</show_in_website>
2119
+ <show_in_store>0</show_in_store>
2120
+ <sort_order>120</sort_order>
2121
+ </order_automation>
2122
+ <guest_order_automation>
2123
+ <label>Guest Order</label>
2124
+ <frontend_type>select</frontend_type>
2125
+ <source_model>ddg_automation/adminhtml_source_automation_programme</source_model>
2126
+ <show_in_default>1</show_in_default>
2127
+ <show_in_website>1</show_in_website>
2128
+ <show_in_store>0</show_in_store>
2129
+ <sort_order>130</sort_order>
2130
+ </guest_order_automation>
2131
+ <review_automation>
2132
+ <label>Submitted Review</label>
2133
+ <frontend_type>select</frontend_type>
2134
+ <source_model>ddg_automation/adminhtml_source_automation_programme</source_model>
2135
+ <show_in_default>1</show_in_default>
2136
+ <show_in_website>1</show_in_website>
2137
+ <show_in_store>0</show_in_store>
2138
+ <sort_order>140</sort_order>
2139
+ </review_automation>
2140
+ <wishlist_automation>
2141
+ <label>Created Wishlist</label>
2142
+ <frontend_type>select</frontend_type>
2143
+ <source_model>ddg_automation/adminhtml_source_automation_programme</source_model>
2144
+ <show_in_default>1</show_in_default>
2145
+ <show_in_website>1</show_in_website>
2146
+ <show_in_store>0</show_in_store>
2147
+ <sort_order>150</sort_order>
2148
+ </wishlist_automation>
2149
+ </fields>
2150
+ </automation>
2151
+ </groups>
2152
+ </connector_automation_studio>
2153
+ <connector_configuration translate="label" module="ddg">
2154
+ <label>Configuration</label>
2155
+ <tab>connector</tab>
2156
+ <sort_order>10000</sort_order>
2157
+ <show_in_default>1</show_in_default>
2158
+ <show_in_website>1</show_in_website>
2159
+ <show_in_store>0</show_in_store>
2160
+ <groups>
2161
+ <transactional_data translate="label" module="ddg">
2162
+ <label>Transactional Data</label>
2163
+ <sort_order>1000</sort_order>
2164
+ <show_in_default>1</show_in_default>
2165
+ <show_in_website>1</show_in_website>
2166
+ <show_in_store>0</show_in_store>
2167
+ <fields>
2168
+ <order_statuses translate="label comment" module="ddg">
2169
+ <label>Import With Status</label>
2170
+ <frontend_type>multiselect</frontend_type>
2171
+ <source_model>ddg_automation/adminhtml_source_orderstatus</source_model>
2172
+ <sort_order>10</sort_order>
2173
+ <show_in_default>1</show_in_default>
2174
+ <show_in_website>1</show_in_website>
2175
+ <show_in_store>0</show_in_store>
2176
+ <comment><![CDATA[Select multiple statuses by pressing Ctrl button while selecting]]></comment>
2177
+ </order_statuses>
2178
+ <order_custom_attributes>
2179
+ <label>Order Custom Attributes</label>
2180
+ <frontend_type>multiselect</frontend_type>
2181
+ <source_model>ddg_automation/adminhtml_source_advanced_attributes</source_model>
2182
+ <sort_order>20</sort_order>
2183
+ <show_in_default>1</show_in_default>
2184
+ <show_in_website>1</show_in_website>
2185
+ <show_in_store>0</show_in_store>
2186
+ <comment><![CDATA[Select custom order attributes that you want to import with your order data. Select multiple by pressing Ctrl button while selecting.]]></comment>
2187
+ </order_custom_attributes>
2188
+ <quote_custom_attributes>
2189
+ <label>Quote Custom Attributes</label>
2190
+ <frontend_type>multiselect</frontend_type>
2191
+ <source_model>ddg_automation/adminhtml_source_advanced_quoteattributes</source_model>
2192
+ <sort_order>30</sort_order>
2193
+ <show_in_default>1</show_in_default>
2194
+ <show_in_website>1</show_in_website>
2195
+ <show_in_store>0</show_in_store>
2196
+ <comment><![CDATA[Select custom quote attributes that you want to import with your quote data. Select multiple by pressing Ctrl button while selecting.]]></comment>
2197
+ </quote_custom_attributes>
2198
+ </fields>
2199
+ </transactional_data>
2200
+ <abandoned_carts translate="label" module="ddg">
2201
+ <label>Abandoned Carts</label>
2202
+ <sort_order>2000</sort_order>
2203
+ <show_in_default>1</show_in_default>
2204
+ <show_in_website>1</show_in_website>
2205
+ <show_in_store>0</show_in_store>
2206
+ <fields>
2207
+ <email_capture translate="label comment" module="ddg">
2208
+ <label>Easy Email Capture</label>
2209
+ <frontend_type>select</frontend_type>
2210
+ <source_model>adminhtml/system_config_source_yesno</source_model>
2211
+ <sort_order>10</sort_order>
2212
+ <show_in_default>1</show_in_default>
2213
+ <show_in_website>1</show_in_website>
2214
+ <show_in_store>0</show_in_store>
2215
+ <comment><![CDATA[Enable this if you have a checkout process that allows the visitor to
2216
+ enter their email address during the checkout, but it does not update quote table instantly.]]></comment>
2217
+ </email_capture>
2218
+ <limits translate="label comment" module="ddg">
2219
+ <label>Abandoned Cart Limit</label>
2220
+ <frontend_type>select</frontend_type>
2221
+ <source_model>ddg_automation/adminhtml_source_advanced_abandonedlimit</source_model>
2222
+ <sort_order>20</sort_order>
2223
+ <show_in_default>1</show_in_default>
2224
+ <show_in_website>1</show_in_website>
2225
+ <show_in_store>0</show_in_store>
2226
+ <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>
2227
+ </limits>
2228
+ </fields>
2229
+ </abandoned_carts>
2230
+ <dynamic_content_style translate="label comment" module="ddg">
2231
+ <label>Dynamic Content Styling</label>
2232
+ <sort_order>2500</sort_order>
2233
+ <show_in_default>1</show_in_default>
2234
+ <show_in_website>1</show_in_website>
2235
+ <show_in_store>0</show_in_store>
2236
+ <fields>
2237
+ <dynamic_syling translate="label" module="ddg">
2238
+ <label>Dynamic Styling</label>
2239
+ <frontend_type>textarea</frontend_type>
2240
+ <sort_order>30</sort_order>
2241
+ <show_in_default>1</show_in_default>
2242
+ <show_in_website>1</show_in_website>
2243
+ <show_in_store>0</show_in_store>
2244
+ <comment><![CDATA[Styling entered here will apply to all dynamic content areas pulled from Magento. Classes References Used : 'product-table', 'product-name', 'product-price', 'product-url', 'other-text']]></comment>
2245
+ </dynamic_syling>
2246
+ <name_title title="label" module="ddg">
2247
+ <label>Product Name</label>
2248
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
2249
+ <sort_order>35</so