dotmailermagento - Version 5.0.4

Version Notes

Cron config change

Download this release

Release Info

Developer Adeel Qamar
Extension dotmailermagento
Version 5.0.4
Comparing to
See all releases


Code changes from version 1.5.1 to 5.0.4

Files changed (304) hide show
  1. app/code/community/Dotdigitalgroup/Email/.DS_Store +0 -0
  2. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Automation.php +17 -0
  3. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Automation/Edit.php +35 -0
  4. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Automation/Edit/Form.php +26 -0
  5. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Automation/Grid.php +158 -0
  6. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Campaign.php +17 -0
  7. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Campaign/Edit.php +39 -0
  8. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Campaign/Edit/Form.php +54 -0
  9. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Campaign/Grid.php +178 -0
  10. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Catalog.php +15 -0
  11. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Catalog/Grid.php +106 -0
  12. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Column/Renderer/Delete.php +17 -0
  13. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Column/Renderer/Imported.php +16 -0
  14. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Column/Renderer/Reset.php +17 -0
  15. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Column/Renderer/Script.php +21 -0
  16. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Column/Renderer/Status.php +18 -0
  17. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Column/Renderer/Sync.php +16 -0
  18. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Column/Renderer/Website.php +15 -0
  19. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Config/Automation/Customdatafields.php +104 -0
  20. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Config/Customdatafields.php +112 -0
  21. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Config/Rules/Customdatafields.php +266 -0
  22. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Config/Select.php +14 -0
  23. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Contact.php +17 -0
  24. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Contact/Edit.php +36 -0
  25. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Contact/Edit/Form.php +26 -0
  26. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Contact/Grid.php +219 -0
  27. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Customer/Tab.php +41 -0
  28. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Customer/Tab/Stats.php +41 -0
  29. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard.php +52 -0
  30. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Switcher.php +92 -0
  31. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs.php +50 -0
  32. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Analysis.php +61 -0
  33. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Analysis/Abandonedcarts.php +57 -0
  34. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Analysis/Customer.php +55 -0
  35. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Analysis/Rfm.php +91 -0
  36. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Analysis/Sales.php +54 -0
  37. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Analysis/Subscriber.php +56 -0
  38. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/General.php +106 -0
  39. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/General/Data.php +43 -0
  40. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Status.php +1752 -0
  41. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Importer.php +15 -0
  42. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Importer/Grid.php +163 -0
  43. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Order.php +15 -0
  44. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Order/Grid.php +123 -0
  45. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Quote.php +15 -0
  46. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Quote/Grid.php +120 -0
  47. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Review.php +15 -0
  48. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Review/Grid.php +109 -0
  49. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Rules.php +15 -0
  50. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Rules/Edit.php +46 -0
  51. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Rules/Edit/Form.php +22 -0
  52. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Rules/Edit/Tab/Conditions.php +85 -0
  53. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Rules/Edit/Tab/Main.php +121 -0
  54. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Rules/Edit/Tabs.php +12 -0
  55. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Rules/Grid.php +116 -0
  56. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Sales/Order/Creditmemo/View.php +196 -0
  57. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/.DS_Store +0 -0
  58. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Deletecontactids.php +22 -0
  59. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Notification.php +11 -0
  60. app/code/{local/Dotdigitalgroup/Email/Block/Debug/Initialsync.php → community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Reimportcatalog.php} +9 -7
  61. app/code/{local/Dotdigitalgroup/Email/Block/Debug/Countcontacts.php → community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Reimportorders.php} +7 -6
  62. app/code/{local/Dotdigitalgroup/Email/Block/Debug/Deletecontacts.php → community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Reimportquotes.php} +7 -6
  63. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Reimportreviews.php +22 -0
  64. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Reimportsubscribers.php +22 -0
  65. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Reimportwishlists.php +22 -0
  66. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Reset.php +22 -0
  67. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Resetcustomersimport.php +22 -0
  68. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Runcatalogsync.php +22 -0
  69. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Runcontactsync.php +22 -0
  70. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Runordersync.php +22 -0
  71. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Runquotesync.php +22 -0
  72. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Runreviewsync.php +22 -0
  73. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Runsubscribersync.php +22 -0
  74. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Runwishlistsync.php +22 -0
  75. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Setupdatafields.php +24 -0
  76. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Suppressedcontacts.php +23 -0
  77. app/code/{local/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Password.php → community/Dotdigitalgroup/Email/Block/Adminhtml/System/Ajaxvalidate.php} +1 -1
  78. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Automation/Connect.php +41 -0
  79. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Addressbook.php +39 -0
  80. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Colorpicker.php +66 -0
  81. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Datafield.php +41 -0
  82. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Enterprisevalidator.php +30 -0
  83. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Resetcontacts.php +28 -0
  84. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Resetguests.php +28 -0
  85. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Resetsubscribers.php +28 -0
  86. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Smtpvalidator.php +36 -0
  87. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Validator.php +87 -0
  88. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Waitingfield.php +65 -0
  89. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Wrapper.php +59 -0
  90. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Addressbookbutton.php +22 -0
  91. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Basket/Crosssell.php +26 -0
  92. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Basket/Related.php +27 -0
  93. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Basket/Upsell.php +25 -0
  94. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Bestsellers.php +24 -0
  95. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Couponinfo.php +26 -0
  96. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Creditmemonew.php +25 -0
  97. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Crosssell.php +26 -0
  98. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Datafieldbutton.php +21 -0
  99. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Fallbackchooser.php +25 -0
  100. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Fallbackcontainer.php +27 -0
  101. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Feefo/Reviews.php +22 -0
  102. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Feefo/Score.php +22 -0
  103. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Gridlist.php +106 -0
  104. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Lostbasket.php +31 -0
  105. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Manualchooser.php +25 -0
  106. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Manualcontainer.php +27 -0
  107. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Mostviewed.php +21 -0
  108. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Nosto.php +22 -0
  109. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Productpush.php +21 -0
  110. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Recentlyviewed.php +24 -0
  111. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Related.php +26 -0
  112. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Review.php +29 -0
  113. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Upsell.php +24 -0
  114. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Wishlist.php +33 -0
  115. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Wishlist/Crosssell.php +32 -0
  116. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Wishlist/Related.php +32 -0
  117. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Wishlist/Upsell.php +31 -0
  118. app/code/{local/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Wrapper.php → community/Dotdigitalgroup/Email/Block/Adminhtml/System/Emailapivalidate.php} +9 -8
  119. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Installation.php +161 -0
  120. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Sms/Smsmessagefour.php +24 -0
  121. app/code/{local/Dotdigitalgroup/Email/Block/Adminhtml/System/Config → community/Dotdigitalgroup/Email/Block/Adminhtml/System/Sms}/Smsmessageone.php +13 -8
  122. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Sms/Smsmessagethree.php +26 -0
  123. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Sms/Smsmessagetwo.php +25 -0
  124. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Creditmemoupdate.php +32 -0
  125. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Creditmemoupdateguest.php +30 -0
  126. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Customerconfirmation.php +36 -0
  127. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Customerconfirmed.php +36 -0
  128. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Customernew.php +36 -0
  129. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Invoiceupdate.php +33 -0
  130. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Invoiceupdateguest.php +33 -0
  131. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Newcreditmemo.php +36 -0
  132. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Newcreditmemoguest.php +35 -0
  133. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Newinvoice.php +34 -0
  134. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Newinvoiceguest.php +34 -0
  135. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Neworder.php +33 -0
  136. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Neworderguest.php +32 -0
  137. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Newshipment.php +34 -0
  138. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Newshipmentguest.php +33 -0
  139. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Orderupdate.php +31 -0
  140. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Orderupdateguest.php +31 -0
  141. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Shipmentupdate.php +33 -0
  142. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Shipmentupdateguest.php +32 -0
  143. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Widget/Chooser/Product.php +163 -0
  144. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Wishlist.php +15 -0
  145. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Wishlist/Grid.php +120 -0
  146. app/code/community/Dotdigitalgroup/Email/Block/Basket.php +87 -0
  147. app/code/{local → community}/Dotdigitalgroup/Email/Block/Coupon.php +16 -16
  148. app/code/community/Dotdigitalgroup/Email/Block/Customer/Account/Books.php +214 -0
  149. app/code/community/Dotdigitalgroup/Email/Block/Edc.php +393 -0
  150. app/code/community/Dotdigitalgroup/Email/Block/Feefo.php +101 -0
  151. app/code/community/Dotdigitalgroup/Email/Block/Order.php +75 -0
  152. app/code/community/Dotdigitalgroup/Email/Block/Order/Creditmemo.php +45 -0
  153. app/code/community/Dotdigitalgroup/Email/Block/Order/Invoice.php +36 -0
  154. app/code/community/Dotdigitalgroup/Email/Block/Order/Shipping.php +36 -0
  155. app/code/community/Dotdigitalgroup/Email/Block/Products.php +67 -0
  156. app/code/community/Dotdigitalgroup/Email/Block/Recommended/Products.php +68 -0
  157. app/code/community/Dotdigitalgroup/Email/Block/Recommended/Wishlistproducts.php +51 -0
  158. app/code/community/Dotdigitalgroup/Email/Block/System/Email/Template/Edit.php +13 -0
  159. app/code/community/Dotdigitalgroup/Email/Block/Wishlist.php +43 -0
  160. app/code/community/Dotdigitalgroup/Email/Helper/Config.php +346 -0
  161. app/code/community/Dotdigitalgroup/Email/Helper/Dashboard.php +171 -0
  162. app/code/community/Dotdigitalgroup/Email/Helper/Data.php +900 -0
  163. app/code/{local → community}/Dotdigitalgroup/Email/Helper/File.php +88 -30
  164. app/code/community/Dotdigitalgroup/Email/Helper/Recommended.php +178 -0
  165. app/code/community/Dotdigitalgroup/Email/Helper/Review.php +90 -0
  166. app/code/community/Dotdigitalgroup/Email/Model/Abstract/Rest.php +457 -0
  167. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Content.php +121 -0
  168. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Abandoned.php +59 -0
  169. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Customer.php +48 -0
  170. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Orders.php +93 -0
  171. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Rfm.php +160 -0
  172. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Subscriber.php +91 -0
  173. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Observer.php +229 -0
  174. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Addressbooks.php +46 -0
  175. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Addressbookspref.php +71 -0
  176. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Abandonedlimit.php +43 -0
  177. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Attributes.php +22 -0
  178. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Frequency.php +15 -0
  179. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Quoteattributes.php +21 -0
  180. app/code/{local/Dotdigitalgroup/Email/Model/System/Config/Source/Orderlimit.php → community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Transdata.php} +1 -1
  181. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Automation/Programme.php +39 -0
  182. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Campaigns.php +58 -0
  183. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Contact/Imported.php +17 -0
  184. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Contact/Modified.php +17 -0
  185. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Customer/Attributes/Select.php +36 -0
  186. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Datafields.php +55 -0
  187. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Datamapping/Datafieldaccess.php +17 -0
  188. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Datamapping/Datafieldtype.php +22 -0
  189. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Dynamic/Displaytype.php +18 -0
  190. app/code/{local/Dotdigitalgroup/Email/Model/System/Config/Source → community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Dynamic}/Gridview.php +6 -1
  191. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Fontpicker.php +35 -0
  192. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Fontsize.php +30 -0
  193. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Importer/Mode.php +19 -0
  194. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Importer/Status.php +19 -0
  195. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Lostbaskets/Interval.php +40 -0
  196. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Lostbaskets/Intervalminute.php +21 -0
  197. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Orderstatus.php +28 -0
  198. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Publicdatafields.php +63 -0
  199. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Reviews/Delay.php +26 -0
  200. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Rules/Condition.php +67 -0
  201. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Rules/Type.php +72 -0
  202. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Rules/Value.php +89 -0
  203. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Styling.php +18 -0
  204. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Sweettooth/Yesno.php +26 -0
  205. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Sync/Catalog/Attributes.php +28 -0
  206. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Sync/Catalog/Type.php +16 -0
  207. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Sync/Catalog/Values.php +23 -0
  208. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Sync/Catalog/Visibility.php +16 -0
  209. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Transactional/Yesno.php +26 -0
  210. app/code/community/Dotdigitalgroup/Email/Model/Api2/Subscriber/Rest/Admin/V1.php +111 -0
  211. app/code/community/Dotdigitalgroup/Email/Model/Apiconnector/Client.php +1243 -0
  212. app/code/community/Dotdigitalgroup/Email/Model/Apiconnector/Contact.php +430 -0
  213. app/code/community/Dotdigitalgroup/Email/Model/Apiconnector/Customer.php +935 -0
  214. app/code/community/Dotdigitalgroup/Email/Model/Apiconnector/Test.php +50 -0
  215. app/code/community/Dotdigitalgroup/Email/Model/Automation.php +221 -0
  216. app/code/community/Dotdigitalgroup/Email/Model/Campaign.php +144 -0
  217. app/code/community/Dotdigitalgroup/Email/Model/Catalog.php +420 -0
  218. app/code/{local → community}/Dotdigitalgroup/Email/Model/Connector/Account.php +61 -7
  219. app/code/community/Dotdigitalgroup/Email/Model/Connector/Campaign.php +100 -0
  220. app/code/community/Dotdigitalgroup/Email/Model/Connector/Datafield.php +298 -0
  221. app/code/community/Dotdigitalgroup/Email/Model/Connector/Order.php +446 -0
  222. app/code/community/Dotdigitalgroup/Email/Model/Connector/Product.php +162 -0
  223. app/code/community/Dotdigitalgroup/Email/Model/Connector/Quote.php +327 -0
  224. app/code/community/Dotdigitalgroup/Email/Model/Contact.php +238 -0
  225. app/code/community/Dotdigitalgroup/Email/Model/Controller/Observer.php +43 -0
  226. app/code/community/Dotdigitalgroup/Email/Model/Cron.php +175 -0
  227. app/code/community/Dotdigitalgroup/Email/Model/Customer.php +20 -0
  228. app/code/community/Dotdigitalgroup/Email/Model/Customer/Guest.php +71 -0
  229. app/code/community/Dotdigitalgroup/Email/Model/Customer/Observer.php +362 -0
  230. app/code/community/Dotdigitalgroup/Email/Model/Customer/Review.php +241 -0
  231. app/code/community/Dotdigitalgroup/Email/Model/Customer/Review/Rating.php +46 -0
  232. app/code/community/Dotdigitalgroup/Email/Model/Customer/Wishlist.php +121 -0
  233. app/code/{local → community}/Dotdigitalgroup/Email/Model/Customer/Wishlist/Item.php +29 -16
  234. app/code/community/Dotdigitalgroup/Email/Model/Feed.php +88 -0
  235. app/code/community/Dotdigitalgroup/Email/Model/Importer.php +270 -0
  236. app/code/community/Dotdigitalgroup/Email/Model/Newsletter/Observer.php +136 -0
  237. app/code/community/Dotdigitalgroup/Email/Model/Newsletter/Sub.php +12 -0
  238. app/code/community/Dotdigitalgroup/Email/Model/Newsletter/Subscriber.php +192 -0
  239. app/code/community/Dotdigitalgroup/Email/Model/Order.php +126 -0
  240. app/code/community/Dotdigitalgroup/Email/Model/Quote.php +189 -0
  241. app/code/community/Dotdigitalgroup/Email/Model/Resource/Automation.php +75 -0
  242. app/code/community/Dotdigitalgroup/Email/Model/Resource/Automation/Collection.php +25 -0
  243. app/code/community/Dotdigitalgroup/Email/Model/Resource/Campaign.php +54 -0
  244. app/code/community/Dotdigitalgroup/Email/Model/Resource/Campaign/Collection.php +13 -0
  245. app/code/community/Dotdigitalgroup/Email/Model/Resource/Catalog.php +53 -0
  246. app/code/community/Dotdigitalgroup/Email/Model/Resource/Catalog/Collection.php +13 -0
  247. app/code/community/Dotdigitalgroup/Email/Model/Resource/Contact.php +324 -0
  248. app/code/community/Dotdigitalgroup/Email/Model/Resource/Contact/Collection.php +25 -0
  249. app/code/community/Dotdigitalgroup/Email/Model/Resource/Importer.php +51 -0
  250. app/code/community/Dotdigitalgroup/Email/Model/Resource/Importer/Collection.php +13 -0
  251. app/code/community/Dotdigitalgroup/Email/Model/Resource/Order.php +41 -0
  252. app/code/community/Dotdigitalgroup/Email/Model/Resource/Order/Collection.php +18 -0
  253. app/code/community/Dotdigitalgroup/Email/Model/Resource/Quote.php +59 -0
  254. app/code/community/Dotdigitalgroup/Email/Model/Resource/Quote/Collection.php +14 -0
  255. app/code/community/Dotdigitalgroup/Email/Model/Resource/Review.php +50 -0
  256. app/code/community/Dotdigitalgroup/Email/Model/Resource/Review/Collection.php +13 -0
  257. app/code/community/Dotdigitalgroup/Email/Model/Resource/Rules.php +13 -0
  258. app/code/community/Dotdigitalgroup/Email/Model/Resource/Rules/Collection.php +13 -0
  259. app/code/community/Dotdigitalgroup/Email/Model/Resource/Segment.php +154 -0
  260. app/code/community/Dotdigitalgroup/Email/Model/Resource/Setup.php +26 -0
  261. app/code/community/Dotdigitalgroup/Email/Model/Resource/Wishlist.php +53 -0
  262. app/code/community/Dotdigitalgroup/Email/Model/Resource/Wishlist/Collection.php +13 -0
  263. app/code/community/Dotdigitalgroup/Email/Model/Review.php +146 -0
  264. app/code/community/Dotdigitalgroup/Email/Model/Rules.php +436 -0
  265. app/code/community/Dotdigitalgroup/Email/Model/Sales/Observer.php +319 -0
  266. app/code/community/Dotdigitalgroup/Email/Model/Sales/Order.php +414 -0
  267. app/code/community/Dotdigitalgroup/Email/Model/Sales/Quote.php +306 -0
  268. app/code/community/Dotdigitalgroup/Email/Model/Sms/Campaign.php +112 -0
  269. app/code/community/Dotdigitalgroup/Email/Model/Sweettooth/Observer.php +21 -0
  270. app/code/community/Dotdigitalgroup/Email/Model/Wishlist.php +220 -0
  271. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/ConnectorController.php +393 -0
  272. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/CustomerController.php +10 -0
  273. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/AutomationController.php +80 -0
  274. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/CampaignController.php +207 -0
  275. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/CatalogController.php +26 -0
  276. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/ContactController.php +183 -0
  277. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/DashboardController.php +90 -0
  278. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/ImporterController.php +67 -0
  279. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/OrderController.php +26 -0
  280. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/QuoteController.php +26 -0
  281. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/ReviewController.php +26 -0
  282. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/RulesController.php +207 -0
  283. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/StudioController.php +111 -0
  284. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/WishlistController.php +26 -0
  285. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/System/Email/TemplateController.php +36 -0
  286. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Widget/ChooserController.php +24 -0
  287. app/code/community/Dotdigitalgroup/Email/controllers/AjaxController.php +21 -0
  288. app/code/community/Dotdigitalgroup/Email/controllers/CreditmemoController.php +70 -0
  289. app/code/community/Dotdigitalgroup/Email/controllers/Customer/AccountController.php +27 -0
  290. app/code/community/Dotdigitalgroup/Email/controllers/Customer/NewsletterController.php +129 -0
  291. app/code/community/Dotdigitalgroup/Email/controllers/DynamicContentController.php +40 -0
  292. app/code/community/Dotdigitalgroup/Email/controllers/EmailController.php +278 -0
  293. app/code/community/Dotdigitalgroup/Email/controllers/FeefoController.php +63 -0
  294. app/code/community/Dotdigitalgroup/Email/controllers/InvoiceController.php +75 -0
  295. app/code/community/Dotdigitalgroup/Email/controllers/OrderController.php +75 -0
  296. app/code/community/Dotdigitalgroup/Email/controllers/ProductsController.php +123 -0
  297. app/code/community/Dotdigitalgroup/Email/controllers/QuoteproductsController.php +82 -0
  298. app/code/community/Dotdigitalgroup/Email/controllers/ReportController.php +70 -0
  299. app/code/community/Dotdigitalgroup/Email/controllers/ResponseController.php +50 -0
  300. app/code/community/Dotdigitalgroup/Email/controllers/RulesController.php +123 -0
  301. app/code/community/Dotdigitalgroup/Email/controllers/ShippingController.php +88 -0
  302. app/code/community/Dotdigitalgroup/Email/controllers/WishlistController.php +50 -0
  303. app/code/community/Dotdigitalgroup/Email/etc/adminhtml.xml +210 -0
  304. app/code/community/Dotdigitalgroup/Email/etc/api2.xml +29 -0
app/code/community/Dotdigitalgroup/Email/.DS_Store ADDED
Binary file
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,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ ),
58
+ 'escape' => true
59
+ ))->addColumn('email', array(
60
+ 'header' => Mage::helper('ddg')->__('Email'),
61
+ 'align' => 'right',
62
+ 'index' => 'email',
63
+ 'type' => 'text',
64
+ 'escape' => true,
65
+ ))->addColumn('type_id', array(
66
+ 'header' => Mage::helper('ddg')->__('Type ID'),
67
+ 'align' => 'center',
68
+ 'index' => 'type_id',
69
+ 'type' => 'number',
70
+ 'escape' => true,
71
+ ))->addColumn('message', array(
72
+ 'header' => Mage::helper('ddg')->__('Message'),
73
+ 'align' => 'right',
74
+ 'index' => 'message',
75
+ 'type' => 'text',
76
+ 'escape' => true
77
+ ))->addColumn('created_at', array(
78
+ 'header' => Mage::helper('ddg')->__('Created at'),
79
+ 'align' => 'center',
80
+ 'index' => 'created_at',
81
+ 'escape' => true,
82
+ 'type' => 'datetime'
83
+
84
+ ))->addColumn('updated_at', array(
85
+ 'header' => Mage::helper('ddg')->__('Updated at'),
86
+ 'align' => 'center',
87
+ 'index' => 'updated_at',
88
+ 'escape' => true,
89
+ 'type' => 'datetime'
90
+ ));
91
+ if (!Mage::app()->isSingleStoreMode()) {
92
+ $this->addColumn('website_id', array(
93
+ 'header' => Mage::helper('customer')->__('Website'),
94
+ 'align' => 'center',
95
+ 'type' => 'options',
96
+ 'options' => Mage::getSingleton('adminhtml/system_store')->getWebsiteOptionHash(true),
97
+ 'index' => 'website_id',
98
+ ));
99
+ }
100
+
101
+ $this->addExportType('*/*/exportCsv', Mage::helper('ddg')->__('CSV'));
102
+ return parent::_prepareColumns();
103
+ }
104
+
105
+ /**
106
+ * Get the store.
107
+ *
108
+ * @return Mage_Core_Model_Store
109
+ * @throws Exception
110
+ */
111
+ protected function _getStore()
112
+ {
113
+ $storeId = (int) $this->getRequest()->getParam('store', 0);
114
+ return Mage::app()->getStore($storeId);
115
+ }
116
+
117
+ /**
118
+ * Prepare the grid massaction.
119
+ * @return $this|Mage_Adminhtml_Block_Widget_Grid
120
+ */
121
+ protected function _prepareMassaction()
122
+ {
123
+ $this->setMassactionIdField('id');
124
+ $this->getMassactionBlock()->setFormFieldName('automation');
125
+ $this->getMassactionBlock()->addItem('resend', array(
126
+ 'label' => Mage::helper('ddg')->__('Resend'),
127
+ 'url' => $this->getUrl('*/*/massResend'),
128
+
129
+ ));
130
+ $this->getMassactionBlock()->addItem('delete', array(
131
+ 'label'=> Mage::helper('ddg')->__('Delete'),
132
+ 'url' => $this->getUrl('*/*/massDelete'),
133
+ 'confirm' => Mage::helper('ddg')->__('Are you sure?')));
134
+
135
+ return $this;
136
+ }
137
+
138
+ /**
139
+ * Edit the row.
140
+ * @param $row
141
+ *
142
+ * @return string
143
+ */
144
+ public function getRowUrl($row)
145
+ {
146
+ return $this->getUrl('*/*/edit', array('id' => $row->getEmailContactId()));
147
+ }
148
+
149
+ /**
150
+ * Grid url.
151
+ * @return string
152
+ */
153
+ public function getGridUrl()
154
+ {
155
+ return $this->getUrl('*/*/grid', array('_current'=>true));
156
+ }
157
+
158
+ }
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,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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('customer_id', array(
38
+ 'header' => Mage::helper('ddg')->__('Customer ID'),
39
+ 'align' => 'left',
40
+ 'width' => '50px',
41
+ 'index' => 'customer_id',
42
+ 'type' => 'number',
43
+ 'escape' => true
44
+ ))->addColumn('email', array(
45
+ 'header' => Mage::helper('ddg')->__('Email'),
46
+ 'align' => 'left',
47
+ 'width' => '50px',
48
+ 'index' => 'email',
49
+ 'type' => 'text',
50
+ 'escape' => true
51
+ ))->addColumn('is_sent', array(
52
+ 'header' => Mage::helper('ddg')->__('Is Sent'),
53
+ 'align' => 'center',
54
+ 'width' => '20px',
55
+ 'index' => 'is_sent',
56
+ 'escape' => true,
57
+ 'type' => 'options',
58
+ 'renderer' => 'ddg_automation/adminhtml_column_renderer_imported',
59
+ 'options' => array(
60
+ '1' => 'Is Send',
61
+ 'null' => 'Not Send'
62
+ ),
63
+ 'filter_condition_callback' => array($this, 'filterCallbackContact')
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')->__('Event Name'),
73
+ 'align' => 'left',
74
+ 'index' => 'event_name',
75
+ 'width' => '100px',
76
+ 'type' => 'string',
77
+ 'escape' => true
78
+ ))->addColumn('quote_id', array(
79
+ 'header' => Mage::helper('ddg')->__('Quote Id'),
80
+ 'align' => 'left',
81
+ 'width' => '50px',
82
+ 'index' => 'quote_id',
83
+ 'type' => 'number',
84
+ 'escape' => true
85
+ ))->addColumn('sent_at', array(
86
+ 'header' => Mage::helper('ddg')->__('Sent At'),
87
+ 'align' => 'center',
88
+ 'width' => '100px',
89
+ 'index' => 'sent_at',
90
+ 'type' => 'datetime',
91
+ 'escape' => true
92
+ ))->addColumn('created_at', array(
93
+ 'header' => Mage::helper('ddg')->__('Created At'),
94
+ 'align' => 'center',
95
+ 'width' => '100px',
96
+ 'index' => 'created_at',
97
+ 'type' => 'datetime',
98
+ 'escape' => true
99
+ ))->addColumn('updated_at', array(
100
+ 'header' => Mage::helper('ddg')->__('Updated At'),
101
+ 'align' => 'center',
102
+ 'width' => '100px',
103
+ 'index' => 'updated_at',
104
+ 'type' => 'datetime',
105
+ 'escape' => true
106
+ ));
107
+ if (!Mage::app()->isSingleStoreMode()) {
108
+ $this->addColumn('store_id', array(
109
+ 'header' => Mage::helper('customer')->__('Store'),
110
+ 'align' => 'center',
111
+ 'width' => '80px',
112
+ 'type' => 'options',
113
+ 'options' => Mage::getSingleton('adminhtml/system_store')->getStoreOptionHash(true),
114
+ 'index' => 'store_id'
115
+ ));
116
+ }
117
+
118
+ $this->addExportType('*/*/exportCsv', Mage::helper('ddg')->__('CSV'));
119
+ return parent::_prepareColumns();
120
+ }
121
+
122
+ /**
123
+ * Get the store selected.
124
+ * @return Mage_Core_Model_Store
125
+ * @throws Exception
126
+ */
127
+ protected function _getStore()
128
+ {
129
+ $storeId = (int) $this->getRequest()->getParam('store', 0);
130
+ return Mage::app()->getStore($storeId);
131
+ }
132
+
133
+
134
+ /**
135
+ * @return $this|Mage_Adminhtml_Block_Widget_Grid
136
+ */
137
+ protected function _prepareMassaction()
138
+ {
139
+ $this->setMassactionIdField('id');
140
+ $this->getMassactionBlock()->setFormFieldName('campaign');
141
+ $this->getMassactionBlock()->addItem('delete', array (
142
+ 'label'=> Mage::helper('ddg')->__('Delete'),
143
+ 'url' => $this->getUrl('*/*/massDelete'),
144
+ 'confirm' => Mage::helper('ddg')->__('Are you sure?')
145
+ )
146
+ );
147
+
148
+ $this->getMassactionBlock()->addItem('resend', array('label'=>Mage::helper('ddg')->__('Resend'),'url'=>$this->getUrl('*/*/massResend')));
149
+ return $this;
150
+ }
151
+
152
+ /**
153
+ * Grid selected url.
154
+ * @return string
155
+ */
156
+ public function getGridUrl()
157
+ {
158
+ return $this->getUrl('*/*/grid', array('_current'=>true));
159
+ }
160
+ /**
161
+ * Custom callback action for the campaign.
162
+ *
163
+ * @param $collection
164
+ * @param $column
165
+ */
166
+ public function filterCallbackContact($collection, $column)
167
+ {
168
+ $field = $column->getFilterIndex() ? $column->getFilterIndex() : $column->getIndex();
169
+ $value = $column->getFilter()->getValue();
170
+
171
+ if ($value == 'null') {
172
+ $collection->addFieldToFilter($field, array('null' => true) );
173
+ } else {
174
+ $collection->addFieldToFilter($field, array('notnull' => true));
175
+ }
176
+ }
177
+
178
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Catalog.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Catalog extends Mage_Adminhtml_Block_Widget_Grid_Container
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+
9
+ $this->_controller = 'adminhtml_catalog';
10
+ $this->_blockGroup = 'ddg_automation';
11
+ $this->_headerText = Mage::helper('ddg')->__('Email Catalog');
12
+
13
+ $this->_removeButton('add');
14
+ }
15
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Catalog/Grid.php ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Catalog_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/catalog_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('product_id', array(
45
+ 'header' => Mage::helper('ddg')->__('Product ID'),
46
+ 'align' => 'left',
47
+ 'width' => '50px',
48
+ 'index' => 'product_id',
49
+ 'type' => 'number',
50
+ 'escape' => true
51
+ ))->addColumn('imported', array(
52
+ 'header' => Mage::helper('ddg')->__('Imported'),
53
+ 'align' => 'center',
54
+ 'width' => '50px',
55
+ 'index' => 'imported',
56
+ 'type' => 'options',
57
+ 'escape' => true,
58
+ 'renderer' => 'ddg_automation/adminhtml_column_renderer_imported',
59
+ 'options' => Mage::getModel('ddg_automation/adminhtml_source_contact_imported')->getOptions(),
60
+ 'filter_condition_callback' => array($this, 'filterCallbackContact')
61
+ ))->addColumn('modified', array(
62
+ 'header' => Mage::helper('ddg')->__('Modified'),
63
+ 'align' => 'center',
64
+ 'width' => '50px',
65
+ 'index' => 'modified',
66
+ 'type' => 'options',
67
+ 'escape' => true,
68
+ 'renderer' => 'ddg_automation/adminhtml_column_renderer_imported',
69
+ 'options' => Mage::getModel('ddg_automation/adminhtml_source_contact_modified')->getOptions(),
70
+ 'filter_condition_callback' => array($this, 'filterCallbackContact')
71
+ ))->addColumn('created_at', array(
72
+ 'header' => Mage::helper('ddg')->__('Created At'),
73
+ 'width' => '50px',
74
+ 'align' => 'center',
75
+ 'index' => 'created_at',
76
+ 'type' => 'datetime',
77
+ 'escape' => true,
78
+ ))->addColumn('updated_at', array(
79
+ 'header' => Mage::helper('ddg')->__('Updated At'),
80
+ 'width' => '50px',
81
+ 'align' => 'center',
82
+ 'index' => 'updated_at',
83
+ 'type' => 'datetime',
84
+ 'escape' => true,
85
+ ));
86
+
87
+ return parent::_prepareColumns();
88
+ }
89
+
90
+ /**
91
+ * Callback action for the imported subscribers/contacts.
92
+ *
93
+ * @param $collection
94
+ * @param $column
95
+ */
96
+ public function filterCallbackContact($collection, $column)
97
+ {
98
+ $field = $column->getFilterIndex() ? $column->getFilterIndex() : $column->getIndex();
99
+ $value = $column->getFilter()->getValue();
100
+ if ($value == 'null') {
101
+ $collection->addFieldToFilter($field, array('null' => true));
102
+ } else {
103
+ $collection->addFieldToFilter($field, array('notnull' => true));
104
+ }
105
+ }
106
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Column/Renderer/Delete.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Column_Renderer_Delete 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
+ $url = HtmlSpecialChars(json_encode(Mage::helper('adminhtml')->getUrl('*/*/delete', array('id' => $row->getId()))));
14
+ return '<button title="Delete" onclick="visitPage(' . $url . ')" type="button" style=""><span><span><span>Delete</span></span></span></button>';
15
+ }
16
+
17
+ }
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/Reset.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Column_Renderer_Reset 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
+ $url = HtmlSpecialChars(json_encode(Mage::helper('adminhtml')->getUrl('*/*/reset', array('id' => $row->getId()))));
14
+ return '<button title="Reset" onclick="visitPage(' . $url . '); return false" type="button" style=""><span><span><span>Reset</span></span></span></button>';
15
+ }
16
+
17
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Column/Renderer/Script.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Column_Renderer_Script 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
+ $html = "<script type='application/javascript'>
14
+ function visitPage(url){
15
+ document.location.href = url;
16
+ }
17
+ </script>";
18
+ return $html;
19
+ }
20
+
21
+ }
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/Automation/Customdatafields.php ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Config_Automation_Customdatafields extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
4
+ {
5
+ protected $_getStatusRenderer;
6
+ protected $_getAutomationRenderer;
7
+
8
+
9
+ /**
10
+ * Construct.
11
+ */
12
+ public function __construct()
13
+ {
14
+ $this->_addAfter = false;
15
+ $this->_addButtonLabel = Mage::helper('adminhtml')->__('Add New Enrolment');
16
+ parent::__construct();
17
+
18
+ }
19
+
20
+ protected function _prepareToRender()
21
+ {
22
+ $this->_getStatusRenderer = null;
23
+ $this->_getAutomationRenderer = null;
24
+ $this->addColumn('status',
25
+ array(
26
+ 'label' => Mage::helper('adminhtml')->__('Order Status'),
27
+ 'style' => 'width:120px',
28
+ )
29
+ );
30
+ $this->addColumn('automation', array(
31
+ 'label' => Mage::helper('adminhtml')->__('Automation Programme'),
32
+ 'style' => 'width:120px',
33
+ )
34
+ );
35
+ }
36
+
37
+ protected function _renderCellTemplate($columnName)
38
+ {
39
+ $inputName = $this->getElement()->getName() . '[#{_id}][' . $columnName . ']';
40
+ if ($columnName=="status") {
41
+ return $this->_getStatusRenderer()
42
+ ->setName($inputName)
43
+ ->setTitle($columnName)
44
+ ->setExtraParams('style="width:160px"')
45
+ ->setOptions(
46
+ $this->getElement()->getValues()
47
+ )
48
+ ->toHtml();
49
+ } elseif ($columnName == "automation") {
50
+ return $this->_getAutomationRenderer()
51
+ ->setName($inputName)
52
+ ->setTitle($columnName)
53
+ ->setExtraParams('style="width:160px"')
54
+ ->setOptions(Mage::getModel('ddg_automation/adminhtml_source_automation_programme')->toOptionArray())
55
+ ->toHtml();
56
+ }
57
+ return parent::_renderCellTemplate($columnName);
58
+ }
59
+
60
+ /**
61
+ * Assign extra parameters to row
62
+ *
63
+ * @param Varien_Object $row
64
+ */
65
+ protected function _prepareArrayRow(Varien_Object $row)
66
+ {
67
+
68
+ $row->setData(
69
+ 'option_extra_attr_' . $this->_getStatusRenderer()->calcOptionHash($row->getData('status')),
70
+ 'selected="selected"'
71
+ );
72
+
73
+ $row->setData(
74
+ 'option_extra_attr_' . $this->_getAutomationRenderer()->calcOptionHash($row->getData('automation')),
75
+ 'selected="selected"'
76
+ );
77
+ }
78
+ protected function _getStatusRenderer()
79
+ {
80
+ if (!$this->_getStatusRenderer) {
81
+ $this->_getStatusRenderer = $this->getLayout()
82
+ ->createBlock('ddg_automation/adminhtml_config_select')
83
+ ->setIsRenderToJsTemplate(true);
84
+ }
85
+ return $this->_getStatusRenderer;
86
+ }
87
+
88
+ protected function _getAutomationRenderer()
89
+ {
90
+ if (!$this->_getAutomationRenderer) {
91
+ $this->_getAutomationRenderer = $this->getLayout()
92
+ ->createBlock('ddg_automation/adminhtml_config_select')
93
+ ->setIsRenderToJsTemplate(true);
94
+ }
95
+ return $this->_getAutomationRenderer;
96
+ }
97
+
98
+ public function _toHtml()
99
+ {
100
+ return '<input type="hidden" id="'.$this->getElement()->getHtmlId().'"/>'.parent::_toHtml();
101
+
102
+ }
103
+
104
+ }
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/Rules/Customdatafields.php ADDED
@@ -0,0 +1,266 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Config_Rules_Customdatafields extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
4
+ {
5
+ protected $_getAttributeRenderer;
6
+ protected $_getConditionsRenderer;
7
+ protected $_getValueRenderer;
8
+
9
+
10
+ /**
11
+ * Construct.
12
+ */
13
+ public function __construct()
14
+ {
15
+ $this->_addAfter = false;
16
+ $this->_addButtonLabel = Mage::helper('adminhtml')->__('Add New Condition');
17
+ parent::__construct();
18
+
19
+ }
20
+
21
+ /**
22
+ * prepare render
23
+ */
24
+ protected function _prepareToRender()
25
+ {
26
+ $this->_getConditionsRenderer = null;
27
+ $this->_getAttributeRenderer = null;
28
+ $this->_getValueRenderer = null;
29
+ $this->addColumn('attribute',
30
+ array(
31
+ 'label' => Mage::helper('adminhtml')->__('Attribute'),
32
+ 'style' => 'width:120px',
33
+ )
34
+ );
35
+ $this->addColumn('conditions',
36
+ array(
37
+ 'label' => Mage::helper('adminhtml')->__('Condition'),
38
+ 'style' => 'width:120px',
39
+ )
40
+ );
41
+ $this->addColumn('cvalue',
42
+ array(
43
+ 'label' => Mage::helper('adminhtml')->__('Value'),
44
+ 'style' => 'width:120px',
45
+ )
46
+ );
47
+ }
48
+
49
+ /**
50
+ * render cell template
51
+ *
52
+ * @param string $columnName
53
+ * @return string
54
+ * @throws Exception
55
+ */
56
+ protected function _renderCellTemplate($columnName)
57
+ {
58
+ $inputName = $this->getElement()->getName() . '[#{_id}][' . $columnName . ']';
59
+ if ($columnName=="attribute") {
60
+ return $this->_getAttributeRenderer()
61
+ ->setName($inputName)
62
+ ->setTitle($columnName)
63
+ ->setExtraParams('style="width:160px"')
64
+ ->setOptions(
65
+ $this->getElement()->getValues()
66
+ )
67
+ ->toHtml();
68
+ }elseif ($columnName == "conditions") {
69
+ return $this->_getConditionsRenderer()
70
+ ->setName($inputName)
71
+ ->setTitle($columnName)
72
+ ->setExtraParams('style="width:160px"')
73
+ ->setOptions(Mage::getModel('ddg_automation/adminhtml_source_rules_condition')->toOptionArray())
74
+ ->toHtml();
75
+ }elseif ($columnName == "cvalue") {
76
+ return $this->_getValueRenderer()
77
+ ->setName($inputName)
78
+ ->setTitle($columnName)
79
+ ->setExtraParams('style="width:160px"')
80
+ ->setOptions(Mage::getModel('ddg_automation/adminhtml_source_rules_value')->toOptionArray())
81
+ ->toHtml();
82
+ }
83
+ return parent::_renderCellTemplate($columnName);
84
+ }
85
+
86
+ /**
87
+ * Assign extra parameters to row
88
+ *
89
+ * @param Varien_Object $row
90
+ */
91
+ protected function _prepareArrayRow(Varien_Object $row)
92
+ {
93
+ $row->setData(
94
+ 'option_extra_attr_' . $this->_getAttributeRenderer()->calcOptionHash($row->getData('attribute')),
95
+ 'selected="selected"'
96
+ );
97
+ }
98
+
99
+ /**
100
+ * get rendered for attribute field
101
+ *
102
+ * @return mixed
103
+ */
104
+ protected function _getAttributeRenderer()
105
+ {
106
+ if (!$this->_getAttributeRenderer) {
107
+ $this->_getAttributeRenderer = $this->getLayout()
108
+ ->createBlock('ddg_automation/adminhtml_config_select')
109
+ ->setIsRenderToJsTemplate(true);
110
+ }
111
+ return $this->_getAttributeRenderer;
112
+ }
113
+
114
+ /**
115
+ * get renderer for conditions field
116
+ *
117
+ * @return mixed
118
+ */
119
+ protected function _getConditionsRenderer()
120
+ {
121
+ if (!$this->_getConditionsRenderer) {
122
+ $this->_getConditionsRenderer = $this->getLayout()
123
+ ->createBlock('ddg_automation/adminhtml_config_select')
124
+ ->setIsRenderToJsTemplate(true);
125
+ }
126
+ return $this->_getConditionsRenderer;
127
+ }
128
+
129
+ /**
130
+ * get renderer for value field
131
+ *
132
+ * @return mixed
133
+ */
134
+ protected function _getValueRenderer()
135
+ {
136
+ if (!$this->_getValueRenderer) {
137
+ $this->_getValueRenderer = $this->getLayout()
138
+ ->createBlock('ddg_automation/adminhtml_config_select')
139
+ ->setIsRenderToJsTemplate(true);
140
+ }
141
+ return $this->_getValueRenderer;
142
+ }
143
+
144
+ public function _toHtml()
145
+ {
146
+ $script =
147
+ "<script type=\"text/javascript\">
148
+ document.observe('dom:loaded', function() {
149
+ $$('tr#row_rule_condition tr td:first-child select').each(function(item) {
150
+ doUpdateWithValues(item);
151
+ });
152
+
153
+ $$('tr#row_rule_condition tr td:first-child select').each(function(item) {
154
+ Event.observe(item,'change', function(){
155
+ doUpdate(item);
156
+ });
157
+ });
158
+
159
+ $$('tr#row_rule_condition button.add').each(function(item) {
160
+ Event.observe(item,'click', function(){
161
+ $$('tr#row_rule_condition tr td:first-child select').each(function(item) {
162
+ Event.observe(item,'change', function(){
163
+ doUpdate(item);
164
+ });
165
+ });
166
+ $$('tr#row_rule_condition tr td select').each(function(item) {
167
+ Event.observe(item,'change', function(){
168
+ if(item.readAttribute('title') == 'conditions'){
169
+ doUpdateForCondition(item);
170
+ }
171
+ });
172
+ });
173
+ });
174
+ });
175
+
176
+ function doUpdate(item){
177
+ var url = '". Mage::getUrl('connector/rules/ajax')."';
178
+ var cond = item.up(1).down().next();
179
+ var condName = cond.down().readAttribute('name');
180
+ var value = item.up(1).down().next(1);
181
+ var valueName = value.down().readAttribute('name');
182
+ var attribute = item.value;
183
+ new Ajax.Request(url, {
184
+ method: 'post',
185
+ parameters: {
186
+ attribute: attribute,
187
+ condition: condName,
188
+ value: valueName
189
+ },
190
+ onSuccess: function(transport){
191
+ var json = transport.responseJSON;
192
+ cond.update(json.condition);
193
+ value.update(json.cvalue);
194
+
195
+ $$('tr#row_rule_condition tr td select').each(function(item) {
196
+ Event.observe(item,'change', function(){
197
+ if(item.readAttribute('title') == 'conditions'){
198
+ doUpdateForCondition(item);
199
+ }
200
+ });
201
+ });
202
+ }
203
+ });
204
+ }
205
+
206
+ function doUpdateWithValues(item){
207
+ var url = '". Mage::getUrl('connector/rules/selected')."';
208
+ var arrayKey = item.up(1).readAttribute('id');
209
+ var cond = item.up(1).down().next();
210
+ var condName = cond.down().readAttribute('name');
211
+ var value = item.up(1).down().next(1);
212
+ var valueName = value.down().readAttribute('name');
213
+ var attribute = item.value;
214
+ var ruleId = $('rule_id').value;
215
+ new Ajax.Request(url, {
216
+ method: 'post',
217
+ parameters: {
218
+ attribute: attribute,
219
+ condition: condName,
220
+ value: valueName,
221
+ arraykey: arrayKey,
222
+ ruleid: ruleId
223
+ },
224
+ onSuccess: function(transport){
225
+ var json = transport.responseJSON;
226
+ cond.update(json.condition);
227
+ value.update(json.cvalue);
228
+
229
+ $$('tr#row_rule_condition tr td select').each(function(item) {
230
+ Event.observe(item,'change', function(){
231
+ if(item.readAttribute('title') == 'conditions'){
232
+ doUpdateForCondition(item);
233
+ }
234
+ });
235
+ });
236
+ }
237
+ });
238
+ }
239
+
240
+ function doUpdateForCondition(item){
241
+ var url = '". Mage::getUrl('connector/rules/value')."';
242
+ var attribute = item.up(1).down();
243
+ var attributeValue = attribute.down().value;
244
+ var value = item.up().next();
245
+ var valueName = value.down().readAttribute('name');
246
+ var condValue = item.value;
247
+ new Ajax.Request(url, {
248
+ method: 'post',
249
+ parameters: {
250
+ attributeValue: attributeValue,
251
+ value: valueName,
252
+ condValue: condValue
253
+ },
254
+ onSuccess: function(transport){
255
+ var json = transport.responseJSON;
256
+ value.update(json.cvalue);
257
+ }
258
+ });
259
+ }
260
+ });
261
+ </script>";
262
+ return '<input type="hidden" id="'.$this->getElement()->getHtmlId().'"/>'.parent::_toHtml().$script;
263
+
264
+ }
265
+
266
+ }
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('customer_id', array(
40
+ 'header' => Mage::helper('ddg')->__('Customer ID'),
41
+ 'align' => 'left',
42
+ 'width' => '20px',
43
+ 'index' => 'customer_id',
44
+ 'type' => 'number',
45
+ 'escape' => true
46
+ ))->addColumn('is_guest', array(
47
+ 'header' => Mage::helper('ddg')->__('Is Guest'),
48
+ 'align' => 'right',
49
+ 'width' => '50px',
50
+ 'index' => 'is_guest',
51
+ 'type' => 'options',
52
+ 'options' => array(
53
+ '1' => 'Guest',
54
+ 'null' => 'Not Guest'
55
+ ),
56
+ 'escape' => true,
57
+ 'filter_condition_callback' => array($this, 'filterCallbackContact')
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/Customer/Tab.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Customer_Tab
4
+ extends Mage_Adminhtml_Block_Widget
5
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface {
6
+
7
+ public function getTabLabel()
8
+ {
9
+ return $this->__('Email Activity');
10
+ }
11
+
12
+ public function getTabTitle()
13
+ {
14
+ return $this->__('Email Activity');
15
+ }
16
+
17
+ public function canShowTab()
18
+ {
19
+ return true;
20
+ }
21
+
22
+ public function isHidden()
23
+ {
24
+ return false;
25
+ }
26
+
27
+ public function getTabUrl()
28
+ {
29
+ return $this->getUrl('*/customer/stat', array('_current' => true));
30
+ }
31
+
32
+ public function getTabClass()
33
+ {
34
+ return 'ajax';
35
+ }
36
+
37
+ public function getAfter()
38
+ {
39
+ return 'tags';
40
+ }
41
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Customer/Tab/Stats.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Customer_Tab_Stats extends Mage_Adminhtml_Block_Template
4
+ {
5
+ private $_stat = array();
6
+
7
+ public function _construct()
8
+ {
9
+ $this->setTemplate('connector/customer/stats.phtml');
10
+ }
11
+
12
+ private function _getCampaignStatsForCustomer()
13
+ {
14
+ $id = Mage::app()->getRequest()->getParam('id');
15
+ $customer = Mage::getModel('customer/customer')->load($id);
16
+ $email = $customer->getEmail();
17
+ $website = $customer->getStore()->getWebsite();
18
+
19
+ $client = Mage::helper('ddg')->getWebsiteApiClient($website);
20
+ $contact = $client->postContacts($email);
21
+ if(!isset($contact->message)){
22
+ $locale = Mage::app()->getLocale()->getLocale();
23
+ $date = Zend_Date::now($locale)->subDay(30);
24
+ $response = $client->getCampaignsWithActivitySinceDate($date->toString(Zend_Date::ISO_8601));
25
+ if(!isset($response->message) && is_array($response)){
26
+ foreach($response as $one){
27
+ $result = $client->getCampaignActivityByContactId($one->id, $contact->id);
28
+ if(!empty($result) && !isset($result->message) && !is_null($result)){
29
+ $this->_stat[$one->name] = $result;
30
+ }
31
+ }
32
+ }
33
+ }
34
+ }
35
+
36
+ public function getStats()
37
+ {
38
+ $this->_getCampaignStatsForCustomer();
39
+ return $this->_stat;
40
+ }
41
+ }
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,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ return parent::_beforeToHtml();
49
+ }
50
+ }
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/General.php ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ 'ApiCallsRemaining' => $this->__('Not Available')
84
+ );
85
+ }
86
+
87
+ /**
88
+ * get Tab content title
89
+ *
90
+ * @return string
91
+ */
92
+ public function getTitle()
93
+ {
94
+ return "Connector Account Information";
95
+ }
96
+
97
+ /**
98
+ * get column width
99
+ *
100
+ * @return string
101
+ */
102
+ public function getColumnWidth()
103
+ {
104
+ return "400px;";
105
+ }
106
+ }
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,1752 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ 'valid_api_credentials' => 'API Credentials',
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
+ 'order_enabled' => 'Order Sync Enabled',
27
+ 'order_syncing' => 'Orders Syncing',
28
+ 'custom_order_attributes' => 'Custom Order Attributes',
29
+ 'quote_enabled' => 'Quote Sync Enabled',
30
+ 'quote_syncing' => 'Quote Syncing',
31
+ 'custom_quote_attributes' => 'Custom Quote Attributes',
32
+ 'last_abandoned_cart_sent_day' => 'Last Abandoned Cart Sent Day',
33
+ 'easy_email_capture_enabled' => 'Easy Email Capture Enabled',
34
+ 'disable_newsletter_success_enabled' => 'Disable Newsletter Success Enabled',
35
+ 'system_information' => 'System Information'
36
+
37
+ );
38
+ /**
39
+ * Set the template.
40
+ */
41
+ public function __construct()
42
+ {
43
+ parent::_construct();
44
+
45
+ $this->setTemplate('connector/dashboard/status.phtml');
46
+ }
47
+
48
+ /**
49
+ * Prepare the layout.
50
+ *
51
+ * @return Mage_Core_Block_Abstract|void
52
+ * @throws Exception
53
+ */
54
+ protected function _prepareLayout()
55
+ {
56
+ }
57
+
58
+ public function canShowTab()
59
+ {
60
+ return true;
61
+ }
62
+ public function isHidden()
63
+ {
64
+ return true;
65
+ }
66
+
67
+ public function getTabLabel()
68
+ {
69
+ return Mage::helper('ddg')->__('Marketing Automation System Status');
70
+ }
71
+
72
+ public function getTabTitle()
73
+ {
74
+ return Mage::helper('ddg')->__('Marketing Automation System Status');
75
+ }
76
+
77
+ /**
78
+ * Collapse key for the fieldset state.
79
+ * @param $key
80
+ *
81
+ * @return bool
82
+ */
83
+ protected function _getCollapseState($key)
84
+ {
85
+ $extra = Mage::getSingleton('admin/session')->getUser()->getExtra();
86
+ if (isset($extra['configState'][$key])) {
87
+ return $extra['configState'][$key];
88
+ }
89
+
90
+ return false;
91
+ }
92
+
93
+ public function getCheckpoints() {
94
+ return $this->_checkpoints;
95
+ }
96
+
97
+
98
+ public function addCheckpoint($checkpoint)
99
+ {
100
+ $this->_checkpoints[$checkpoint->getName()] = $checkpoint;
101
+ }
102
+
103
+
104
+
105
+ /**
106
+ * Check cron for the customer sync.
107
+ * @return array
108
+ */
109
+ public function cronRunning()
110
+ {
111
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
112
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
113
+ ->setTitle('Cron Status : ')
114
+ ->setMessage('Cron is running.');
115
+ $message = 'No cronjob task found. Check if cron is configured correctly.';
116
+ $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>';
117
+ $lastCustomerSync = Mage::getModel('ddg_automation/cron')->getLastCustomerSync();
118
+
119
+ if ($lastCustomerSync === false) {
120
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
121
+ ->setHowto($howToSetupCron);
122
+ } else {
123
+ $timespan = Mage::helper('ddg')->dateDiff($lastCustomerSync);
124
+ //last cron was less then 5min
125
+ if ($timespan <= 5 * 60) {
126
+ $resultContent->setTitle('Cronjob is working : ');
127
+ $message = sprintf('(Last execution: %s minute(s) ago) ', round($timespan/60));
128
+ } elseif ($timespan > 5 * 60 && $timespan <= 60 * 60 ) {
129
+ //last cron execution was between 15min and 60min
130
+ $resultContent->setTitle('Last customer sync : ' )
131
+ ->setStyle(self::CONNECTOR_DASHBOARD_FAILED);
132
+ $message = sprintf(' %s minutes. ', round($timespan/60));
133
+ } else {
134
+ //last cron was more then an hour
135
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
136
+ ->setHowto('Last customer sync is older than one hour.')
137
+ ->setHowto($howToSetupCron);
138
+ }
139
+ }
140
+
141
+ $resultContent->setMessage($message);
142
+ return $resultContent;
143
+ }
144
+
145
+ /**
146
+ * Address Book Mapping.
147
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
148
+ */
149
+ public function addressBookMapped()
150
+ {
151
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
152
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
153
+ ->setTitle('Configuration For Address Book Status : ')
154
+ ->setMessage('Looks Great.');
155
+
156
+ foreach (Mage::app()->getWebsites() as $website ) {
157
+
158
+ $websiteName = $website->getName();
159
+ $link = Mage::helper('adminhtml')->getUrl('*/system_config/edit/section/connector_sync_settings/website/' . $website->getCode());
160
+
161
+ $customerMapped = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMERS_ADDRESS_BOOK_ID))? true :
162
+ 'Not mapped!';
163
+ $subscriberMapped = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SUBSCRIBERS_ADDRESS_BOOK_ID))? true :
164
+ 'Not mapped!';
165
+ $guestMapped = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_GUEST_ADDRESS_BOOK_ID))? true :
166
+ 'Not mapped!';
167
+
168
+ if ($customerMapped !== true || $subscriberMapped !== true || $guestMapped !== true) {
169
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
170
+ ->setMessage('')
171
+ ->setTable(array(
172
+ 'Website' => $websiteName,
173
+ 'Customers' => ($customerMapped !== true)? $customerMapped . ' <a href="' . $link . '">configuration</a>' : 'Mapped.',
174
+ 'Subscribers' => ($subscriberMapped !== true)? $subscriberMapped . ' <a href="' . $link . '">configuration</a>' : 'Mapped.',
175
+ 'Guests' => ($guestMapped !== true)? $guestMapped . ' <a href="' . $link . '">configuration</a>' : 'Mapped.'
176
+ ));
177
+ }
178
+ }
179
+
180
+ return $resultContent;
181
+ }
182
+
183
+ /**
184
+ * ROI Tracking.
185
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
186
+ */
187
+ public function roiTrackingEnabled()
188
+ {
189
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
190
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
191
+ ->setTitle('ROI Tracking Status : ')
192
+ ->setMessage('Looks Great.');
193
+
194
+ $valid = true;
195
+ foreach ( Mage::app()->getWebsites() as $website ) {
196
+ $websiteName = $website->getName();
197
+
198
+ $roiConfig = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_ROI_TRACKING_ENABLED))? true : 'Not Mapped! ';
199
+ $pageTracking = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_PAGE_TRACKING_ENABLED))? true : 'Not Mapped! ';
200
+ //not mapped show options
201
+ if ($roiConfig !== true || $pageTracking !== true) {
202
+
203
+ //links to enable and get redirected back
204
+ $roiUrl = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_ROI_TRACKING_ENABLED', 'website' => $website->getId()));
205
+ $pageUrl = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_PAGE_TRACKING_ENABLED', 'website' => $website->getId()));
206
+
207
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
208
+ ->setMessage('')
209
+ ->setTable(array(
210
+ 'Website' => $websiteName,
211
+ 'ROI' => ($roiConfig !== true)? $roiConfig . ' <a href="' . $roiUrl . '">enable</a>' : 'Mapped.',
212
+ 'PAGE' => ($pageTracking !== true)? $pageTracking . ' <a href="' . $pageUrl . '">enable</a>' : 'Mapped.'
213
+ ));
214
+ $valid = false;
215
+ }
216
+ }
217
+ //validation failed
218
+ if (! $valid) {
219
+ $resultContent->setHowto(self::FAST_FIX_MESSAGE);
220
+ }
221
+
222
+ return $resultContent;
223
+ }
224
+
225
+ /**
226
+ * File Permissions.
227
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
228
+ */
229
+ public function filePermissionSetttings()
230
+ {
231
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
232
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
233
+ ->setTitle('Files/Folders Permission Settings : ')
234
+ ->setMessage('Looks Great.');
235
+
236
+ /**
237
+ * Arhive and email export directories.
238
+ */
239
+ $emailDir = Mage::getBaseDir('var') . DIRECTORY_SEPARATOR . 'export' . DIRECTORY_SEPARATOR . 'email';
240
+ $archiveDir = Mage::getBaseDir('var') . DIRECTORY_SEPARATOR . 'export' . DIRECTORY_SEPARATOR . 'email' . DIRECTORY_SEPARATOR . 'archive';
241
+
242
+ $checkEmail = Mage::helper('ddg/file')->getPathPermission($emailDir);
243
+ $checkArchive = Mage::helper('ddg/file')->getPathPermission($archiveDir);
244
+
245
+ //file persmission failed
246
+ if ($checkEmail != 755 && $checkEmail != 777 || $checkArchive != 755 && $checkArchive != 777) {
247
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
248
+ ->setMessage('Wrong Permission For Directory : 777 or 755');
249
+
250
+ //list of directory permission checked
251
+ if ($checkEmail != 755 || $checkEmail != 777)
252
+ $resultContent->setHowto( $emailDir . ' is set to : ' . $checkEmail);
253
+ if ($checkArchive != 755 || $checkArchive != 777)
254
+ $resultContent->setHowto( $archiveDir . ' is set to : ' . $checkArchive);
255
+ }
256
+
257
+ return $resultContent;
258
+ }
259
+
260
+ /**
261
+ * Check for missing files.
262
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
263
+ */
264
+ public function missingFiles()
265
+ {
266
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
267
+
268
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
269
+ ->setTitle('Missing Files : ')
270
+ ->setMessage('Looks Great.');
271
+
272
+ $filePath = Mage::getModuleDir('etc', Dotdigitalgroup_Email_Helper_Config::MODULE_NAME).DS.'files.yaml';
273
+ $config = Zend_Config_Yaml::decode(file_get_contents($filePath));
274
+
275
+ /**
276
+ * Code dirs.
277
+ */
278
+ $etcDir = Mage::getModuleDir('etc', Dotdigitalgroup_Email_Helper_Config::MODULE_NAME);
279
+ $controllerDir = Mage::getModuleDir('controllers', Dotdigitalgroup_Email_Helper_Config::MODULE_NAME);
280
+ $sqlDir = Mage::getModuleDir('sql', Dotdigitalgroup_Email_Helper_Config::MODULE_NAME);
281
+ $localeDir = Mage::getBaseDir('locale');
282
+ $rootDir = Mage::getModuleDir('', Dotdigitalgroup_Email_Helper_Config::MODULE_NAME);
283
+ $blockDir = $rootDir .DS. 'Block';
284
+ $helperDir = $rootDir .DS. 'Helper';
285
+ $modelDir = $rootDir .DS. 'Model';
286
+
287
+ /**
288
+ * Design dir.
289
+ */
290
+ $designDir = Mage::getBaseDir('design');
291
+
292
+ /**
293
+ * Skin dir.
294
+ */
295
+ $skinDir = Mage::getBaseDir('skin');
296
+
297
+ /**
298
+ * Js dir
299
+ */
300
+ $jsDir = Mage::getBaseDir('base') . DS . 'js';
301
+
302
+ /**
303
+ * lib dir
304
+ */
305
+ $libDir = Mage::getBaseDir('lib');
306
+
307
+ $filesToCheck = array($config['etc'], $config['controllers'], $config['sql'], $config['locale'], $config['block'],
308
+ $config['helper'], $config['model'], $config['design'], $config['skin'], $config['lib'], $config['js']);
309
+ $pathToCheck = array($etcDir, $controllerDir, $sqlDir, $localeDir, $blockDir, $helperDir,
310
+ $modelDir, $designDir, $skinDir, $libDir, $jsDir);
311
+ foreach ( $filesToCheck as $subdir ) {
312
+ foreach ( $subdir as $path ) {
313
+ $file = $pathToCheck[0] . DS . str_replace( '#', DS, $path );
314
+
315
+ if ( !file_exists( $file ) ) {
316
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED )
317
+ ->setMessage('')
318
+ ->setHowto('File not found : ' . $file );
319
+ }
320
+ }
321
+ array_shift($pathToCheck);
322
+ }
323
+
324
+ return $resultContent;
325
+ }
326
+
327
+ /**
328
+ * Contact Sync Status.
329
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
330
+ */
331
+ public function contactSyncEnabled()
332
+ {
333
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
334
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
335
+ ->setTitle('Contacts Sync Status : ')
336
+ ->setMessage('Looks Great.');
337
+
338
+ $valid = true;
339
+ foreach ( Mage::app()->getWebsites() as $website ) {
340
+ $websiteName = $website->getName();
341
+ $contact = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_CONTACT_ENABLED))? true : 'Disabled!';
342
+ //disabled show data table
343
+ if ($contact !== true){
344
+ //redirection url to enable website config
345
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_SYNC_CONTACT_ENABLED', 'website' => $website->getId()));
346
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
347
+ ->setMessage('')
348
+ ->setTable(array(
349
+ 'Website' => $websiteName,
350
+ 'Status' => ($contact)? $contact . ' <a href="' . $url . '">enable</a>' : 'Enabled.'
351
+ ))
352
+ ;
353
+ $valid = false;
354
+ }
355
+ }
356
+ //validation failed
357
+ if (! $valid) {
358
+ $resultContent->setHowto(self::FAST_FIX_MESSAGE);
359
+ }
360
+
361
+ return $resultContent;
362
+ }
363
+
364
+ /**
365
+ * Check if contact is syncing by counting the number of contacts imported.
366
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
367
+ */
368
+ public function contactSyncing()
369
+ {
370
+ //content to render
371
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
372
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
373
+ ->setTitle('Contacts Sync : ')
374
+ ->setMessage('Looks Great.');
375
+ $contactModel = Mage::getModel('ddg_automation/contact');
376
+
377
+ //global email duplicates
378
+ if (Mage::getResourceModel('customer/customer')->findEmailDuplicates()) {
379
+
380
+ //duplicate email customers
381
+ $customers = Mage::helper('ddg')->getCustomersWithDuplicateEmails();
382
+ $customerEmails = implode(', ', $customers->getColumnValues('email'));
383
+ //render the email duplicates
384
+ $resultContent->setHowto('Found Duplicate Customers Emails :')
385
+ ->setHowto($customerEmails);
386
+ }
387
+
388
+ foreach ( Mage::app()->getWebsites() as $website ) {
389
+
390
+ $websiteId = $website->getId();
391
+ //total customers for website
392
+ $countCustomers = Mage::getModel('customer/customer')->getCollection()
393
+ ->addAttributeToFilter('website_id', $websiteId)
394
+ ->getSize();
395
+
396
+ //skip if no customers
397
+ if (! $countCustomers)
398
+ continue;
399
+
400
+ //total contacts from customer address book
401
+ $customerAddressBook = $this->_getAddressBookContacts($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMERS_ADDRESS_BOOK_ID), $website);
402
+ $countAddressbookContacts = ($customerAddressBook)? $customerAddressBook->contacts : 0;
403
+ //total contacts as customers
404
+ $countCustomerContacts = $contactModel->getNumberCustomerContacts($websiteId);
405
+
406
+ //suppressed contacts
407
+ $suppressed = $contactModel->getNumberCustomerSuppressed($websiteId);
408
+
409
+ //table data
410
+ $tableData = array(
411
+ 'Website' => $website->getName(),
412
+ 'Total Customers/Contacts' => $countCustomers . '/ ' . $countCustomerContacts,
413
+ 'Customer AddressBook Contacts' => ($customerAddressBook)? $customerAddressBook->name . ' : ' . $countAddressbookContacts : 'Not Mapped.',
414
+ 'Suppressed' => $suppressed,
415
+ 'Synced' => $contactModel->getNumberCustomerSynced($websiteId)
416
+ );
417
+
418
+ //number of customers not match, try to update
419
+ if ($countCustomers != $countCustomerContacts) {
420
+
421
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/populatecontacts', array('type' => 'customers', 'website' => $website->getId()));
422
+ $link = ' <a href="' . $url . '"> populate</a>';
423
+ $tableData['Status'] = 'Customers not matching the contact table. ' . $link;
424
+ //customers not synced yet
425
+ } elseif ($countCustomers > $countCustomerContacts + $suppressed){
426
+ $tableData['Status'] = 'Syncing..';
427
+ //all customers syned.
428
+ } else {
429
+ $tableData['Status'] = 'Synced';
430
+ }
431
+
432
+ //not valid response remove status
433
+ if (!$countAddressbookContacts)
434
+ unset($tableData['Status']);
435
+
436
+ //no contacts
437
+ if (! $countCustomers) {
438
+
439
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
440
+ ->setTitle('Contacts Sync (ignore if you have reset contacts for reimport) : ')
441
+ ->setMessage('');
442
+ $tableData['Status'] = 'No Imported Contacts Found!';
443
+ unset($tableData['Imported Contacts']);
444
+ }
445
+
446
+ $resultContent->setTable($tableData);
447
+ }
448
+
449
+ return $resultContent;
450
+ }
451
+
452
+ /**
453
+ * Check for subscribers sync status.
454
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
455
+ */
456
+ public function subscriberSyncEnabled()
457
+ {
458
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
459
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
460
+ ->setTitle('Subscribers Sync Status : ')
461
+ ->setMessage('Looks Great.');
462
+
463
+ $passed = true;
464
+ foreach ( Mage::app()->getWebsites() as $website ) {
465
+ $websiteName = $website->getName();
466
+ $contact = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_SUBSCRIBER_ENABLED))? true :
467
+ 'Disabled!';
468
+ //disabled show data table
469
+ if ($contact !== true){
470
+ //redirection url to enable website config
471
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_SYNC_SUBSCRIBER_ENABLED', 'website' => $website->getId()));
472
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
473
+ ->setMessage('')
474
+ ->setTable(array(
475
+ 'Website' => $websiteName,
476
+ 'Status' => ($contact)? $contact . ' <a href="' . $url . '">enable</a>' : 'Enabled.'
477
+ ));
478
+ $passed = false;
479
+ }
480
+ }
481
+ //if validation not passed
482
+ if (! $passed)
483
+ $resultContent->setHowto(self::FAST_FIX_MESSAGE);
484
+
485
+ return $resultContent;
486
+ }
487
+
488
+ /**
489
+ * Subscribers syncing status.
490
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
491
+ */
492
+ public function subscribersSyncing()
493
+ {
494
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
495
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
496
+ ->setTitle('Subscribers Sync : ')
497
+ ->setMessage('Looks Great.');
498
+ $contactModel = Mage::getModel('ddg_automation/contact');
499
+
500
+ foreach ( Mage::app()->getWebsites() as $website ) {
501
+ $websiteId = $website->getId();
502
+ $websiteName = $website->getName();
503
+ $storeIds = $website->getStoreIds();
504
+ //total subscribers
505
+ $countSubscribers = Mage::getModel('newsletter/subscriber')->getCollection()
506
+ ->useOnlySubscribed()
507
+ ->addStoreFilter($storeIds)
508
+ ->getSize();
509
+ //skip if no subscriber
510
+ if (! $countSubscribers)
511
+ continue;
512
+
513
+ //total contacts subscribed
514
+ $countSubscribedContacts = $contactModel->getNumberSubscribers($websiteId);
515
+ //total contacts subscribed imported
516
+ $countSubscribersImported = $contactModel->getNumberSubscribersSynced($websiteId);
517
+
518
+ //number of address
519
+ $countAddressbookContacts = $this->_getAddressBookContacts($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SUBSCRIBERS_ADDRESS_BOOK_ID), $website);
520
+
521
+ $tableData = array(
522
+ 'Website' => $websiteName,
523
+ 'Total Subscribers/Contacts' => $countSubscribers . '/ ' . $countSubscribedContacts,
524
+ 'Subscriber AddressBook Contacts' => ($countAddressbookContacts)? $countAddressbookContacts->name . ' : ' . $countAddressbookContacts->contacts : 'Not Mapped.',
525
+ 'Imported' => $countSubscribersImported
526
+ );
527
+
528
+ $tableData['Status'] = '';
529
+
530
+ //no imported contacts
531
+ if (! $countSubscribersImported) {
532
+
533
+ $tableData['Status'] = 'No Imported Subscribers Found.';
534
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
535
+ ->setTitle('Subscriber Sync (ignore if you have reset subscribers for reimport) : ')
536
+ ->setMessage('');
537
+ }
538
+ $resultContent->setTable($tableData);
539
+ }
540
+
541
+ return $resultContent;
542
+ }
543
+ //check the mapped programs are active
544
+ public function automationActive()
545
+ {
546
+ $disableCustomer = $disableSubscriber = $disableOrder = $disableGuestOrder = $disableReviews = $disableWishlist = '';
547
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
548
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
549
+ ->setTitle('Automation Program Status :')
550
+ ->setMessage('');
551
+
552
+ foreach ( Mage::app()->getWebsites() as $website ) {
553
+ $customerProgram = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_AUTOMATION_STUDIO_CUSTOMER);
554
+ $subscriberProgram = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_AUTOMATION_STUDIO_SUBSCRIBER);
555
+ $orderProgram = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_AUTOMATION_STUDIO_ORDER);
556
+ $guestOrderProgram = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_AUTOMATION_STUDIO_GUEST_ORDER);
557
+ $reviewsProgram = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_AUTOMATION_STUDIO_REVIEW);
558
+ $wishlistProgram = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_AUTOMATION_STUDIO_WISHLIST);
559
+
560
+ //programs
561
+ $cusProgram = $this->_getWebisteProgram($customerProgram, $website);
562
+ $subProgram = $this->_getWebisteProgram($subscriberProgram, $website);
563
+ $orderProgram = $this->_getWebisteProgram($orderProgram, $website);
564
+ $guestOrderProgram = $this->_getWebisteProgram($guestOrderProgram, $website);
565
+ $reviewsProgram = $this->_getWebisteProgram($reviewsProgram, $website);
566
+ $wishlistProgram = $this->_getWebisteProgram($wishlistProgram, $website);
567
+
568
+ //check for wishlist program
569
+ if ($wishlistProgram) {
570
+
571
+ if ($wishlistProgram->status != 'Active') {
572
+
573
+ //set the status as failed
574
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
575
+ ->setMessage(' Consider to disable not active programs');
576
+
577
+ $disableWishlist = Mage::helper( 'adminhtml' )->getUrl( '*/connector/enablewebsiteconfiguration', array(
578
+ 'path' => 'XML_PATH_CONNECTOR_AUTOMATION_STUDIO_WISHLIST',
579
+ 'value' => '0',
580
+ 'website' => $website->getId()
581
+ )
582
+ );
583
+ $disableWishlist = 'Deactivated! <a href="' . $disableWishlist . '">click</a> to disable';
584
+
585
+ } else {
586
+
587
+ $disableWishlist = $wishlistProgram->status;
588
+ }
589
+ }
590
+
591
+ //check for order program
592
+ if ($orderProgram) {
593
+
594
+ if ($orderProgram->status != 'Active') {
595
+
596
+ //set the status as failed
597
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
598
+ ->setMessage(' Consider to disable not active programs');
599
+
600
+ $disableOrder = Mage::helper( 'adminhtml' )->getUrl( '*/connector/enablewebsiteconfiguration', array(
601
+ 'path' => 'XML_PATH_CONNECTOR_AUTOMATION_STUDIO_ORDER',
602
+ 'value' => '0',
603
+ 'website' => $website->getId()
604
+ )
605
+ );
606
+ $disableOrder = 'Deactivated! <a href="' . $disableOrder . '">click</a> to disable';
607
+
608
+ } else {
609
+
610
+ $disableOrder = $orderProgram->status;
611
+ }
612
+ }
613
+
614
+ //check for review program
615
+ if ($reviewsProgram) {
616
+
617
+ if ($reviewsProgram->status != 'Active') {
618
+
619
+ //set the status as failed
620
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
621
+ ->setMessage(' Consider to disable not active programs');
622
+
623
+ $disableReviews = Mage::helper( 'adminhtml' )->getUrl( '*/connector/enablewebsiteconfiguration', array(
624
+ 'path' => 'XML_PATH_CONNECTOR_AUTOMATION_STUDIO_REVIEW',
625
+ 'value' => '0',
626
+ 'website' => $website->getId()
627
+ )
628
+ );
629
+ $disableReviews = 'Deactivated! <a href="' . $disableReviews . '">click</a> to disable';
630
+
631
+ } else {
632
+
633
+ $disableReviews = $reviewsProgram->status;
634
+ }
635
+ }
636
+
637
+ //check for guest order program
638
+ if ($guestOrderProgram) {
639
+
640
+ if ($guestOrderProgram->status != 'Active') {
641
+
642
+ //set the status as failed
643
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
644
+ ->setMessage(' Consider to disable not active programs');
645
+
646
+ $disableGuestOrder = Mage::helper( 'adminhtml' )->getUrl( '*/connector/enablewebsiteconfiguration', array(
647
+ 'path' => 'XML_PATH_CONNECTOR_AUTOMATION_STUDIO_GUEST_ORDER',
648
+ 'value' => '0',
649
+ 'website' => $website->getId()
650
+ )
651
+ );
652
+ $disableGuestOrder = 'Deactivated! <a href="' . $disableGuestOrder . '">click</a> to disable';
653
+
654
+ } else {
655
+
656
+ $disableGuestOrder = $guestOrderProgram->status;
657
+ }
658
+ }
659
+
660
+ //check for customer program
661
+ if ($cusProgram) {
662
+
663
+ if ($cusProgram->status != 'Active') {
664
+
665
+ //set the status as failed
666
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
667
+ ->setMessage(' Consider to disable not active programs');
668
+
669
+ $disableCustomer = Mage::helper( 'adminhtml' )->getUrl( '*/connector/enablewebsiteconfiguration', array(
670
+ 'path' => 'XML_PATH_CONNECTOR_AUTOMATION_STUDIO_CUSTOMER',
671
+ 'value' => '0',
672
+ 'website' => $website->getId()
673
+ )
674
+ );
675
+ $disableCustomer = 'Deactivated! <a href="' . $disableCustomer . '">click</a> to disable';
676
+
677
+ } else {
678
+
679
+ $disableCustomer = $cusProgram->status;
680
+ }
681
+ }
682
+
683
+ //check for subscriber program
684
+ if ($subProgram) {
685
+
686
+ if ($subProgram->status != 'Active') {
687
+ // set the status failed
688
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
689
+ ->setMessage(' Consider to disable not active programs');
690
+
691
+ //link to disbale config
692
+ $disableSubscriber = Mage::helper( 'adminhtml' )->getUrl( '*/connector/enablewebsiteconfiguration', array(
693
+ 'path' => 'XML_PATH_CONNECTOR_AUTOMATION_STUDIO_SUBSCRIBER',
694
+ 'value' => '0',
695
+ 'website' => $website->getId()
696
+ )
697
+ );
698
+ $disableSubscriber = 'Deactivated <a href="' . $disableSubscriber . '">click</a> to disable';
699
+
700
+ } else {
701
+ $disableSubscriber = $subProgram->status;
702
+ }
703
+ }
704
+
705
+ $tableData = array(
706
+ 'Website' => $website->getName(),
707
+ 'Customer Program' => (isset($cusProgram->name))? $cusProgram->name : 'Disabled',
708
+ 'Customer Status' => (isset($cusProgram->status))? $disableCustomer : '',
709
+ 'Subscriber Program' => (isset($subProgram->name))? $subProgram->name : 'Disabled',
710
+ 'Subscriber Status' => (isset($subProgram->status))? $disableSubscriber : '',
711
+ 'Order Program' => (isset($orderProgram->name))? $orderProgram->name : 'Disabled',
712
+ 'Order Status' => (isset($orderProgram->status))? $disableOrder : '',
713
+ 'Guest Order Program' => (isset($guestOrderProgram->name))? $guestOrderProgram->name : 'Disabled',
714
+ 'Guest Order Status' => (isset($guestOrderProgram->status))? $disableGuestOrder : '',
715
+ 'Review Program' => (isset($reviewsProgram->name))? $reviewsProgram->name : 'Disabled',
716
+ 'Review Status' => (isset($reviewsProgram->status))? $disableReviews : '',
717
+ 'Wishlist Program' => (isset($wishlistProgram->name))? $wishlistProgram->name : 'Disabled',
718
+ 'Wishlist Status' => (isset($wishlistProgram->status))? $disableWishlist : '',
719
+ );
720
+
721
+ //set the content with table data
722
+ $resultContent->setTable($tableData);
723
+
724
+ }
725
+
726
+ return $resultContent;
727
+ }
728
+
729
+ /**
730
+ * Abandoned carts status.
731
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
732
+ */
733
+ public function abandonedCartsEnabled()
734
+ {
735
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
736
+
737
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
738
+ ->setTitle('Abandoned Carts Status : ')
739
+ ->setMessage('Looks Great.');
740
+
741
+ foreach ( Mage::app()->getWebsites() as $website ) {
742
+ $websiteName = $website->getName();
743
+ $abandonedCusomer_1 = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CARTS_ENABLED_1))? true :
744
+ 'Disabled!';
745
+ $abandonedCusomer_2 = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CARTS_ENABLED_2))? true :
746
+ 'Disabled!';
747
+ $abandonedCusomer_3 = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CARTS_ENABLED_3))? true :
748
+ 'Disabled!';
749
+ $abandonedGuest_1 = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_GUEST_ABANDONED_CARTS_ENABLED_1))? true :
750
+ 'Disabled!';
751
+ $abandonedGuest_2 = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_GUEST_ABANDONED_CARTS_ENABLED_2))? true :
752
+ 'Disabled!';
753
+ $abandonedGuest_3 = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_GUEST_ABANDONED_CARTS_ENABLED_3))? true :
754
+ 'Disabled!';
755
+
756
+ if ($abandonedCusomer_1 !== true || $abandonedCusomer_2 !== true || $abandonedCusomer_3 !== true || $abandonedGuest_1 !== true || $abandonedGuest_2 !== true || $abandonedGuest_3 !== true){
757
+ //customer abandoned links to enable
758
+ $customer1 = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CARTS_ENABLED_1', 'website' => $website->getId()));
759
+ $customer2 = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CARTS_ENABLED_2', 'website' => $website->getId()));
760
+ $customer3 = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CARTS_ENABLED_3', 'website' => $website->getId()));
761
+ //guests abandoned links to enable
762
+ $guest1 = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_GUEST_ABANDONED_CARTS_ENABLED_1', 'website' => $website->getId()));
763
+ $guest2 = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_GUEST_ABANDONED_CARTS_ENABLED_2', 'website' => $website->getId()));
764
+ $guest3 = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_GUEST_ABANDONED_CARTS_ENABLED_3', 'website' => $website->getId()));
765
+
766
+
767
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
768
+ ->setMessage('Don\'t forget to map')
769
+ ->setTable(array(
770
+ 'Website' => $websiteName,
771
+ 'Customer Abandoned 1' => ($abandonedCusomer_1 !== true)? $abandonedCusomer_1 . ' <a href="' . $customer1 . '">enable</a>' : 'Enabled',
772
+ 'Customer Abandoned 2' => ($abandonedCusomer_2 !== true)? $abandonedCusomer_2 . ' <a href="' . $customer2 . '">enable</a>' : 'Enabled',
773
+ 'Customer Abandoned 3' => ($abandonedCusomer_3 !== true)? $abandonedCusomer_3 . ' <a href="' . $customer3 . '">enable</a>' : 'Enabled',
774
+ 'Guest Abandoned 1' => ($abandonedGuest_1 !== true)? $abandonedGuest_1 . ' <a href="' . $guest1 . '">enable</a>' : 'Enabled',
775
+ 'Guest Abandoned 2' => ($abandonedGuest_2 !== true)? $abandonedGuest_2 . ' <a href="' . $guest2 . '">enable</a>' : 'Enabled',
776
+ 'Guest Abandoned 3' => ($abandonedGuest_3 !== true)? $abandonedGuest_3 . ' <a href="' . $guest3 . '">enable</a>' : 'Enabled',
777
+ ));
778
+ }
779
+ }
780
+
781
+ return $resultContent;
782
+ }
783
+
784
+ /**
785
+ * Crazy mapping checking.
786
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
787
+ */
788
+ public function dataFieldMapped()
789
+ {
790
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
791
+
792
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
793
+ ->setTitle('Default Datafields Mapped Status : ')
794
+ ->setMessage('All Datafields Are Mapped.');
795
+
796
+ foreach ( Mage::app()->getWebsites() as $website ) {
797
+ $passed = true;
798
+ $mapped = 0;
799
+ $tableData = array();
800
+ //website name for table data
801
+ $websiteName = $website->getName();
802
+ $tableData['Website'] = $websiteName;
803
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_ID)) {
804
+ $passed = false;
805
+ $mapped++;
806
+ }
807
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_FIRSTNAME)) {
808
+ $passed = false;
809
+ $mapped++;
810
+ }
811
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_LASTNAME)) {
812
+ $passed = false;
813
+ $mapped++;
814
+ }
815
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_DOB)) {
816
+ $passed = false;
817
+ $mapped++;
818
+ }
819
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_GENDER)) {
820
+ $passed = false;
821
+ $mapped++;
822
+ }
823
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_WEBSITE_NAME)) {
824
+ $passed = false;
825
+ $mapped++;
826
+ }
827
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_STORE_NAME)) {
828
+ $passed = false;
829
+ $mapped++;
830
+ }
831
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_CREATED_AT)) {
832
+ $passed = false;
833
+ $mapped++;
834
+ }
835
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_LAST_LOGGED_DATE)) {
836
+ $passed = false;
837
+ $mapped++;
838
+ }
839
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_CUSTOMER_GROUP)) {
840
+ $passed = false;
841
+ $mapped++;
842
+ }
843
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_REVIEW_COUNT)) {
844
+ $passed = false;
845
+ $mapped++;
846
+ }
847
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_LAST_REVIEW_DATE)) {
848
+ $passed = false;
849
+ $mapped++;
850
+ }
851
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_BILLING_ADDRESS_1)) {
852
+ $passed = false;
853
+ $mapped++;
854
+ }
855
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_BILLING_ADDRESS_2)) {
856
+ $passed = false;
857
+ $mapped++;
858
+ }
859
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_BILLING_CITY)) {
860
+ $passed = false;
861
+ $mapped++;
862
+ }
863
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_BILLING_STATE)) {
864
+ $passed = false;
865
+ $mapped++;
866
+ }
867
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_BILLING_COUNTRY)) {
868
+ $passed = false;
869
+ $mapped++;
870
+ }
871
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_BILLING_POSTCODE)) {
872
+ $passed = false;
873
+ $mapped++;
874
+ }
875
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_BILLING_TELEPHONE)) {
876
+ $passed = false;
877
+ $mapped++;
878
+ }
879
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_ADDRESS_1)) {
880
+ $passed = false;
881
+ $mapped++;
882
+ }
883
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_ADDRESS_2)) {
884
+ $passed = false;
885
+ $mapped++;
886
+ }
887
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_CITY)) {
888
+ $passed = false;
889
+ $mapped++;
890
+ }
891
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_STATE)) {
892
+ $passed = false;
893
+ $mapped++;
894
+ }
895
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_COUNTRY)) {
896
+ $passed = false;
897
+ $mapped++;
898
+ }
899
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_POSTCODE)) {
900
+ $passed = false;
901
+ $mapped++;
902
+ }
903
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_TELEPHONE)) {
904
+ $passed = false;
905
+ $mapped++;
906
+ }
907
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_TOTAL_NUMBER_ORDER)) {
908
+ $passed = false;
909
+ $mapped++;
910
+ }
911
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_AOV)) {
912
+ $passed = false;
913
+ $mapped++;
914
+ }
915
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_TOTAL_SPEND)) {
916
+ $passed = false;
917
+ $mapped++;
918
+ }
919
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_LAST_ORDER_DATE)) {
920
+ $passed = false;
921
+ $mapped++;
922
+ }
923
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_LAST_ORDER_ID)) {
924
+ $passed = false;
925
+ $mapped++;
926
+ }
927
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_CUSTOMER_TOTALREFUND)) {
928
+ $passed = false;
929
+ $mapped++;
930
+ }
931
+ if (! $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_SUBSCRIBER_STATUS)) {
932
+ $passed = false;
933
+ $mapped++;
934
+ }
935
+ $tableData['Mapped Percentage'] = number_format((1 - $mapped / 32) * 100, 2) . ' %';
936
+ //mapping not complete.
937
+ if (! $passed ){
938
+ $url = Mage::helper('adminhtml')->getUrl('*/system_config/edit/section/connector_data_mapping/website/' . $website->getCode());
939
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
940
+ ->setMessage('Click <a href="' . $url . '">here</a> to change mapping configuration.')
941
+ ;
942
+ }
943
+ $resultContent->setTable($tableData);
944
+ }
945
+
946
+ return $resultContent;
947
+ }
948
+
949
+
950
+ /**
951
+ * Validate API Credentials.
952
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
953
+ */
954
+ public function validApiCredentials()
955
+ {
956
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
957
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
958
+ ->setTitle('API Credentials Status : ')
959
+ ->setMessage('Valid.');
960
+ $helper = Mage::helper('ddg');
961
+ foreach ( Mage::app()->getWebsites() as $website ) {
962
+ $websiteName = $website->getName();
963
+ $websiteId = $website->getId();
964
+
965
+ $apiUsername = $helper->getApiUsername($websiteId);
966
+ $apiPassword = $helper->getApiPassword($websiteId);
967
+
968
+ $api = Mage::getModel('ddg_automation/apiconnector_test')->ajaxvalidate($apiUsername, $apiPassword);
969
+
970
+ if ($api != 'Credentials Valid.') {
971
+ $url = Mage::helper('adminhtml')->getUrl('*/system_config/edit/section/connector_api_credentials/website/' . $website->getCode());
972
+
973
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
974
+ ->setMessage('')
975
+ ->setTable(array(
976
+ 'Website' => $websiteName,
977
+ 'Status' => $api,
978
+ 'Fast Fix' => 'Click <a href="' . $url . '">here</a> to enter new api credentials.'
979
+ ));
980
+ }
981
+ }
982
+
983
+ return $resultContent;
984
+ }
985
+
986
+ /**
987
+ * Order sync enabled.
988
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
989
+ */
990
+ public function orderEnabled()
991
+ {
992
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
993
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
994
+ ->setTitle('Order Sync : ')
995
+ ->setMessage('Enabled.');
996
+
997
+ $passed = true;
998
+ foreach ( Mage::app()->getWebsites() as $website ) {
999
+ $websiteName = $website->getName();
1000
+ $order = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_ORDER_ENABLED))? true :
1001
+ 'Disabled!';
1002
+
1003
+ if ($order !== true){
1004
+
1005
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_SYNC_ORDER_ENABLED', 'website' => $website->getId()));
1006
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
1007
+ ->setMessage('')
1008
+ ->setTable(array(
1009
+ 'Website' => $websiteName,
1010
+ 'Status' => $order . ' <a href="' . $url . '">enable</a>'
1011
+ ));
1012
+ $passed = false;
1013
+ }
1014
+ }
1015
+ //validation failed
1016
+ if (! $passed) {
1017
+ $resultContent->setHowto(self::FAST_FIX_MESSAGE);
1018
+ }
1019
+
1020
+ return $resultContent;
1021
+ }
1022
+
1023
+ /**
1024
+ * check if any custom order attribute selected
1025
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1026
+ */
1027
+ public function customOrderAttributes()
1028
+ {
1029
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1030
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1031
+ ->setTitle('Custom Order Attributes : ')
1032
+ ->setMessage('Selected.');
1033
+
1034
+ foreach ( Mage::app()->getWebsites() as $website ) {
1035
+ $websiteName = $website->getName();
1036
+ $customOrderAttibute = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOM_ORDER_ATTRIBUTES))? true : false;
1037
+
1038
+ if ($customOrderAttibute !== true){
1039
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
1040
+ ->setTitle('Custom order attribute not selected (ignore if you do not want to import custom order attributes) :')
1041
+ ->setMessage('')
1042
+ ->setTable(array(
1043
+ 'Website' => $websiteName,
1044
+ 'Status' => 'No Custom Order Attribute Selected'
1045
+ ));
1046
+ }
1047
+ }
1048
+
1049
+ return $resultContent;
1050
+ }
1051
+
1052
+ /**
1053
+ * Check if any orders are imported.
1054
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1055
+ */
1056
+ public function orderSyncing()
1057
+ {
1058
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1059
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1060
+ ->setTitle('Order Syncing : ')
1061
+ ->setMessage('Looks Great.');
1062
+
1063
+ foreach ( Mage::app()->getWebsites() as $website ) {
1064
+ $websiteName = $website->getName();
1065
+ $storeIds = $website->getStoreIds();
1066
+
1067
+ //numbser of orders marked as imported
1068
+ $numOrders = Mage::getModel('ddg_automation/order')->getCollection()
1069
+ ->addFieldToFilter('email_imported', 1)
1070
+ ->addFieldToFilter('store_id', array('in', $storeIds))->getSize();
1071
+
1072
+ if (! $numOrders) {
1073
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
1074
+ ->setTitle('Order Syncing (ignore if you have reset orders for reimport) :')
1075
+ ->setMessage('')
1076
+ ->setTable(array(
1077
+ 'Website' => $websiteName,
1078
+ 'Status' => 'No Imported Orders Found'
1079
+ ));
1080
+ }
1081
+ }
1082
+
1083
+ return $resultContent;
1084
+
1085
+ }
1086
+
1087
+ /**
1088
+ * Quote sync enabled.
1089
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1090
+ */
1091
+ public function quoteEnabled()
1092
+ {
1093
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1094
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1095
+ ->setTitle('Quote Sync : ')
1096
+ ->setMessage('Enabled.');
1097
+
1098
+ $passed = true;
1099
+ foreach ( Mage::app()->getWebsites() as $website ) {
1100
+ $websiteName = $website->getName();
1101
+ $quote = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_QUOTE_ENABLED))? true :
1102
+ 'Disabled!';
1103
+
1104
+ if ($quote !== true){
1105
+
1106
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_SYNC_QUOTE_ENABLED', 'website' => $website->getId()));
1107
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
1108
+ ->setMessage('')
1109
+ ->setTable(array(
1110
+ 'Website' => $websiteName,
1111
+ 'Status' => $quote . ' <a href="' . $url . '">enable</a>'
1112
+ ));
1113
+ $passed = false;
1114
+ }
1115
+ }
1116
+ //validation failed
1117
+ if (! $passed) {
1118
+ $resultContent->setHowto(self::FAST_FIX_MESSAGE);
1119
+ }
1120
+
1121
+ return $resultContent;
1122
+ }
1123
+
1124
+ /**
1125
+ * check if any custom quote attribute selected
1126
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1127
+ */
1128
+ public function customQuoteAttributes()
1129
+ {
1130
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1131
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1132
+ ->setTitle('Custom Quote Attributes : ')
1133
+ ->setMessage('Selected.');
1134
+
1135
+ foreach ( Mage::app()->getWebsites() as $website ) {
1136
+ $websiteName = $website->getName();
1137
+ $customQuoteAttribute = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOM_QUOTE_ATTRIBUTES))? true : false;
1138
+
1139
+ if ($customQuoteAttribute !== true){
1140
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
1141
+ ->setTitle('Custom quote attribute not selected (ignore if you do not want to import custom quote attributes) :')
1142
+ ->setMessage('')
1143
+ ->setTable(array(
1144
+ 'Website' => $websiteName,
1145
+ 'Status' => 'No Custom Quote Attribute Selected'
1146
+ ));
1147
+ }
1148
+ }
1149
+
1150
+ return $resultContent;
1151
+ }
1152
+
1153
+ /**
1154
+ * Check if any quote are imported.
1155
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1156
+ */
1157
+ public function quoteSyncing()
1158
+ {
1159
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1160
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1161
+ ->setTitle('Quote Syncing : ')
1162
+ ->setMessage('Looks Great.');
1163
+
1164
+ foreach ( Mage::app()->getWebsites() as $website ) {
1165
+ $websiteName = $website->getName();
1166
+ $storeIds = $website->getStoreIds();
1167
+
1168
+ //number of quote marked as imported
1169
+ $numQuotes = Mage::getModel('ddg_automation/quote')->getCollection()
1170
+ ->addFieldToFilter('imported', 1)
1171
+ ->addFieldToFilter('store_id', array('in', $storeIds))->getSize();
1172
+
1173
+ if (! $numQuotes) {
1174
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
1175
+ ->setTitle('Quote Syncing (ignore if you have reset quote for re-import) :')
1176
+ ->setMessage('')
1177
+ ->setTable(array(
1178
+ 'Website' => $websiteName,
1179
+ 'Status' => 'No Imported Quotes Found'
1180
+ ));
1181
+ }
1182
+ }
1183
+
1184
+ return $resultContent;
1185
+
1186
+ }
1187
+
1188
+ /**
1189
+ * review sync enabled.
1190
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1191
+ * Display the transactional data for orders to be removed.
1192
+ */
1193
+ public function reviewEnabled()
1194
+ {
1195
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1196
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1197
+ ->setTitle('Review Sync : ')
1198
+ ->setMessage('Enabled.');
1199
+
1200
+ foreach ( Mage::app()->getWebsites() as $website ) {
1201
+ $websiteName = $website->getName();
1202
+ $review = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_REVIEW_ENABLED))? true :
1203
+ 'Disabled';
1204
+
1205
+ if ($review !== true){
1206
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_SYNC_REVIEW_ENABLED', 'website' => $website->getId()));
1207
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
1208
+ ->setMessage('Don\'t forget to enable if you want to sync reviews.' )
1209
+ ->setTable(array(
1210
+ 'Website' => $websiteName,
1211
+ 'Status' => $review,
1212
+ 'Fast Fix' => 'Click <a href="' . $url . '">here </a>to enable.'
1213
+ ));
1214
+ }
1215
+ }
1216
+ return $resultContent;
1217
+ }
1218
+
1219
+ /**
1220
+ * Check if any reviews are imported.
1221
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1222
+ */
1223
+ public function reviewSyncing()
1224
+ {
1225
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1226
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1227
+ ->setTitle('Review Syncing : ')
1228
+ ->setMessage('Looks Great.');
1229
+
1230
+ foreach ( Mage::app()->getWebsites() as $website ) {
1231
+ $websiteName = $website->getName();
1232
+ $storeIds = $website->getStoreIds();
1233
+
1234
+ //number of reviews marked as imported
1235
+ $numReview = Mage::getModel('ddg_automation/review')->getCollection()
1236
+ ->addFieldToFilter('review_imported', 1)
1237
+ ->addFieldToFilter('store_id', array('in', $storeIds))
1238
+ ->getSize();
1239
+
1240
+ //total reviews
1241
+ $totalReview = Mage::getModel('ddg_automation/review')->getCollection()
1242
+ ->addFieldToFilter('store_id', array('in', $storeIds))
1243
+ ->getSize();
1244
+
1245
+ $tableData = array(
1246
+ 'Website' => $websiteName,
1247
+ 'Total Reviews' => $totalReview,
1248
+ 'Imported' => $numReview
1249
+ );
1250
+
1251
+ $tableData['Status'] = 'Importing';
1252
+
1253
+ if (! $numReview) {
1254
+ $tableData['Status'] = 'No Imported Review Found.';
1255
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
1256
+ ->setTitle('Review Sync (ignore if you have reset wishlist) : ')
1257
+ ->setMessage('');
1258
+ }
1259
+ $resultContent->setTable($tableData);
1260
+ }
1261
+ return $resultContent;
1262
+ }
1263
+
1264
+ /**
1265
+ * review campaign enabled.
1266
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1267
+ */
1268
+ public function reviewCampaignStatus()
1269
+ {
1270
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1271
+
1272
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1273
+ ->setTitle('Review Status : ')
1274
+ ->setMessage('Looks Great.');
1275
+
1276
+ foreach ( Mage::app()->getWebsites() as $website ) {
1277
+ $websiteName = $website->getName();
1278
+ $enabled = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_REVIEWS_ENABLED))? true :
1279
+ 'Disabled ';
1280
+ $orderStatus = ($website->getConfig(Dotdigitalgroup_Email_Helper_Review::XML_PATH_REVIEW_STATUS))? true :
1281
+ 'Disabled ';
1282
+ $delayPeriod = ($website->getConfig(Dotdigitalgroup_Email_Helper_Review::XML_PATH_REVIEW_DELAY))? true :
1283
+ 'Disabled ';
1284
+ $newProduct = ($website->getConfig(Dotdigitalgroup_Email_Helper_Review::XML_PATH_REVIEW_NEW_PRODUCT))? true :
1285
+ 'Disabled ';
1286
+ $campaign = ($website->getConfig(Dotdigitalgroup_Email_Helper_Review::XML_PATH_REVIEW_CAMPAIGN))? true :
1287
+ 'Disabled ';
1288
+
1289
+ if ($enabled !== true || $orderStatus !== true || $delayPeriod !== true || $newProduct !== true || $campaign !== true){
1290
+ $enabledUrl = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_REVIEWS_ENABLED', 'website' => $website->getId()));
1291
+
1292
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
1293
+ ->setMessage('Don\'t forget to map')
1294
+ ->setTable(array(
1295
+ 'Website' => $websiteName,
1296
+ 'Enabled' => ($enabled !== true)? $enabled . '<a href="' . $enabledUrl . '">Click to enable</a>' : 'Enabled',
1297
+ 'Order Status' => ($orderStatus !== true)? 'Not Set' : 'Enabled',
1298
+ 'Delay Period' => ($delayPeriod !== true)? 'Not Set' : 'Enabled',
1299
+ 'New Product Only' => ($newProduct !== true)? 'Not Set' : 'Enabled',
1300
+ 'Campaign To Select' => ($campaign !== true)? 'Not Set' : 'Enabled',
1301
+ ));
1302
+ }
1303
+ }
1304
+ return $resultContent;
1305
+ }
1306
+
1307
+ /**
1308
+ * Get the last date for abandaned carts.
1309
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1310
+ */
1311
+ public function lastAbandonedCartSentDay()
1312
+ {
1313
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1314
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1315
+ ->setTitle('Last Abandoned Summary : ');
1316
+
1317
+ foreach ( Mage::app()->getWebsites() as $website ) {
1318
+
1319
+ $websiteName = $website->getName();
1320
+ $client = Mage::helper('ddg')->getWebsiteApiClient($website);
1321
+
1322
+ //customer carts
1323
+ $customerCampaign1 = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CAMPAIGN_1);
1324
+ $customerCampaign2 = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CAMPAIGN_2);
1325
+ $customerCampaign3 = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CAMPAIGN_3);
1326
+
1327
+ //guests carts
1328
+ $guestCampaign1 = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_GUEST_ABANDONED_CAMPAIGN_1);
1329
+ $guestCampaign2 = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_GUEST_ABANDONED_CAMPAIGN_2);
1330
+ $guestCampaign3 = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_GUEST_ABANDONED_CAMPAIGN_3);
1331
+
1332
+
1333
+ //date customer carts
1334
+
1335
+ $cusDateSent1 = ($customerCampaign1)? $client->getCampaignSummary($customerCampaign1) : '';
1336
+ $cusDateSent2 = ($customerCampaign2)? $client->getCampaignSummary($customerCampaign2) : '';
1337
+ $cusDateSent3 = ($customerCampaign3)? $client->getCampaignSummary($customerCampaign3) : '';
1338
+
1339
+ //date guest carts
1340
+ $resGuest1 = ($guestCampaign1)? $client->getCampaignSummary($guestCampaign1) : '';
1341
+ $resGuest2 = ($guestCampaign2)? $client->getCampaignSummary($guestCampaign2) : '';
1342
+ $resGuest3 = ($guestCampaign3)? $client->getCampaignSummary($guestCampaign3) : '';
1343
+
1344
+ /**
1345
+ * Customers.
1346
+ */
1347
+ $customerCampaign1 = (isset($cusDateSent1->dateSent)? $cusDateSent1->dateSent : 'Not Sent/Selected');
1348
+ $customerCampaign2 = (isset($cusDateSent2->dateSent)? $cusDateSent2->dateSent : 'Not Sent/Selected');
1349
+ $customerCampaign3 = (isset($cusDateSent3->dateSent)? $cusDateSent3->dateSent : 'Not Sent/Selected');
1350
+
1351
+ /**
1352
+ * Guests.
1353
+ */
1354
+ $guestCampaign1 = (isset($resGuest1->dateSent)? $resGuest1->dateSent : 'Not Sent/Selected');
1355
+ $guestCampaign2 = (isset($resGuest2->dateSent)? $resGuest2->dateSent : 'Not Sent/Selected');
1356
+ $guestCampaign3 = (isset($resGuest3->dateSent)? $resGuest3->dateSent : 'Not Sent/Selected');
1357
+
1358
+
1359
+ $resultContent->setTable(array(
1360
+ 'Website' => $websiteName,
1361
+ 'Customer Campaign 1' => $customerCampaign1,
1362
+ 'Customer Campaign 2' => $customerCampaign2,
1363
+ 'Customer Campaign 3' => $customerCampaign3,
1364
+ 'Guest Campaign 1' => $guestCampaign1,
1365
+ 'Guest Campaign 2' => $guestCampaign2,
1366
+ 'Guest Campaign 3' => $guestCampaign3
1367
+ ));
1368
+ }
1369
+
1370
+ return $resultContent;
1371
+ }
1372
+
1373
+ /**
1374
+ * Conflict checker.
1375
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1376
+ */
1377
+ public function conflictCheck()
1378
+ {
1379
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1380
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1381
+ ->setTitle('Conflict Status : ')
1382
+ ->setMessage('Looks Great.');
1383
+
1384
+ //check the module override and conflict
1385
+ $rewrites = Mage::helper('ddg/dashboard')->getRewrites();
1386
+
1387
+
1388
+ if ($rewrites === false) {
1389
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1390
+ ->setMessage('No Conflict Rewrites Found.');
1391
+ } else {
1392
+
1393
+ $types = array('blocks', 'models', 'helpers');
1394
+ foreach ($types as $t) {
1395
+
1396
+ if (!empty($rewrites[$t])) {
1397
+
1398
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
1399
+ ->setMessage('Conflicting Rewrite Found : ');
1400
+
1401
+ foreach ($rewrites[$t] as $node => $rewriteInfo) {
1402
+
1403
+ $resultContent->setTable(array(
1404
+ 'Type' => $t,
1405
+ 'Class' => implode(', ', array_values($rewriteInfo['classes'])),
1406
+ 'Rewrites' => '',
1407
+ 'Loaded Class' => ''
1408
+ ));
1409
+ }
1410
+ }
1411
+ }
1412
+
1413
+ $conflictCounter = 0;
1414
+ $tableData = array();
1415
+ foreach ($rewrites as $type => $data) {
1416
+ if (count($data) > 0 && is_array($data)) {
1417
+
1418
+ foreach ($data as $class => $rewriteClass) {
1419
+
1420
+ if (count($rewriteClass) > 1) {
1421
+ if ($this->_isInheritanceConflict($rewriteClass)) {
1422
+
1423
+ $resultContent->setTable(array(
1424
+ 'Type' => $type,
1425
+ 'Class' => $class,
1426
+ 'Rewrites' => implode(', ', $rewriteClass['classes']),
1427
+ 'Loaded Class' => $this->_getLoadedClass($type, $class),
1428
+ ));
1429
+
1430
+ $conflictCounter++;
1431
+ }
1432
+ }
1433
+ }
1434
+ }
1435
+ }
1436
+ if (! empty($tableData))
1437
+ $resultContent->setTable($tableData);
1438
+
1439
+ }
1440
+
1441
+ return $resultContent;
1442
+ }
1443
+
1444
+ /**
1445
+ * Returns loaded class by type like models or blocks
1446
+ *
1447
+ * @param string $type
1448
+ * @param string $class
1449
+ * @return string
1450
+ */
1451
+ protected function _getLoadedClass($type, $class)
1452
+ {
1453
+ switch ($type) {
1454
+ case 'blocks':
1455
+ return Mage::getConfig()->getBlockClassName($class);
1456
+
1457
+ case 'helpers':
1458
+ return Mage::getConfig()->getHelperClassName($class);
1459
+
1460
+ default:
1461
+ case 'models':
1462
+ return Mage::getConfig()->getModelClassName($class);
1463
+ break;
1464
+ }
1465
+ }
1466
+
1467
+ /**
1468
+ * Check if rewritten class has inherited the parent class.
1469
+ * If yes we have no conflict. The top class can extend every core class.
1470
+ * So we cannot check this.
1471
+ *
1472
+ * @var array $classes
1473
+ * @return bool
1474
+ */
1475
+ protected function _isInheritanceConflict($classes)
1476
+ {
1477
+ $classes = array_reverse($classes);
1478
+ for ($i = 0; $i < count($classes) - 1; $i++) {
1479
+ try {
1480
+ if (class_exists($classes[$i])
1481
+ && class_exists($classes[$i + 1])
1482
+ ) {
1483
+ if (! is_a($classes[$i], $classes[$i + 1], true)) {
1484
+ return true;
1485
+ }
1486
+ }
1487
+ } catch (\Exception $e) {
1488
+ return true;
1489
+ }
1490
+ }
1491
+
1492
+ return false;
1493
+ }
1494
+
1495
+ /**
1496
+ * System information about the version used and the memory limits.
1497
+ *
1498
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1499
+ */
1500
+ public function systemInformation()
1501
+ {
1502
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1503
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED);
1504
+
1505
+ //compatibility with the old versions
1506
+ if (version_compare(Mage::getVersion(), '1.6.2.0', '>')) {
1507
+ $version = 'Magento ' . Mage::getEdition() . ' ' . Mage::getVersion() . 'V';
1508
+ } else {
1509
+ $version = 'Magento version : ' . Mage::getVersion() . 'V';
1510
+ }
1511
+
1512
+ $fh = @fopen('/proc/meminfo', 'r');
1513
+ $mem = 0;
1514
+ if ($fh) {
1515
+ while ($line = fgets($fh)) {
1516
+ $pieces = array();
1517
+ if (preg_match('^MemTotal:\s+(\d+)\skB$^', $line, $pieces)) {
1518
+ $mem = $pieces[1];
1519
+ break;
1520
+ }
1521
+ }
1522
+ fclose($fh);
1523
+ }
1524
+ if ($mem > 0) {
1525
+ $mem = $mem / 1024 . 'M';
1526
+ } else {
1527
+ $mem = $this->_getTopMemoryInfo();
1528
+ }
1529
+
1530
+ //check for php version
1531
+ $resultContent->setHowTo('PHP version : V' . PHP_VERSION)
1532
+ ->setHowto('PHP Memory : ' . $mem)
1533
+ ->setHowto('PHP Max Execution Time : ' . ini_get('max_execution_time') . ' sec')
1534
+ ->setHowto($version)
1535
+ ->setHowto('Connector version : V' . Mage::helper('ddg')->getConnectorVersion());
1536
+
1537
+ return $resultContent;
1538
+ }
1539
+
1540
+
1541
+ /**
1542
+ * Returns memory size. Alternative way
1543
+ *
1544
+ * @return string|null
1545
+ */
1546
+ public function _getTopMemoryInfo()
1547
+ {
1548
+ $memInfo = exec('top -l 1 | head -n 10 | grep PhysMem');
1549
+ $memInfo = str_ireplace('PhysMem: ', '', $memInfo);
1550
+
1551
+ if (!empty($memInfo)) {
1552
+ return $memInfo;
1553
+ } else {
1554
+ return null;
1555
+ }
1556
+ }
1557
+
1558
+ /**
1559
+ * Check if the mapped program is active.
1560
+
1561
+ */
1562
+ protected function _getWebisteProgram($program, $website) {
1563
+ $client = Mage::helper('ddg')->getWebsiteApiClient($website);
1564
+
1565
+ if (! $client || !$program){
1566
+ return false;
1567
+ }
1568
+
1569
+ $data = $client->getProgramById($program);
1570
+
1571
+ if (isset($data->message))
1572
+ return false;
1573
+
1574
+
1575
+ return $data;
1576
+ }
1577
+
1578
+ /**
1579
+ * Get the contacts address book.
1580
+ * @param $addressBook
1581
+ * @param $webiste
1582
+ *
1583
+ * @return bool|null
1584
+ */
1585
+ protected function _getAddressBookContacts($addressBook, $webiste) {
1586
+ $client = Mage::helper('ddg')->getWebsiteApiClient($webiste);
1587
+
1588
+ if (! $client && $addressBook)
1589
+ return false;
1590
+
1591
+ $response = $client->getAddressBookById($addressBook);
1592
+
1593
+ if (isset($response->message))
1594
+ return false;
1595
+ return $response;
1596
+ }
1597
+
1598
+ /**
1599
+ * Get the method name
1600
+ * @param $name
1601
+ *
1602
+ * @return string
1603
+ */
1604
+ public function getFormatedMethodName($name)
1605
+ {
1606
+ //version that not support the lcfirst method
1607
+ if(function_exists('lcfirst') === false) {
1608
+
1609
+ $method = strtolower(substr(uc_words($name, '') ,0,1)).substr(uc_words($name, ''), 1);
1610
+
1611
+ } else {
1612
+ $method = lcfirst(uc_words($name, ''));
1613
+ }
1614
+
1615
+ return $method;
1616
+ }
1617
+
1618
+ /**
1619
+ * easy email capture enabled
1620
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1621
+ */
1622
+ public function easyEmailCaptureEnabled()
1623
+ {
1624
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1625
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1626
+ ->setTitle('Easy Email Capture : ')
1627
+ ->setMessage('Enabled.');
1628
+
1629
+ foreach ( Mage::app()->getWebsites() as $website ) {
1630
+ $websiteName = $website->getName();
1631
+ $enabled = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_EMAIL_CAPTURE))? true :
1632
+ 'Disabled';
1633
+
1634
+ if ($enabled !== true){
1635
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_EMAIL_CAPTURE', 'website' => $website->getId()));
1636
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
1637
+ ->setMessage('Don\'t forget to enable if you want to enable easy email capture.' )
1638
+ ->setTable(array(
1639
+ 'Website' => $websiteName,
1640
+ 'Status' => $enabled,
1641
+ 'Fast Fix' => 'Click <a href="' . $url . '">here </a>to enable.'
1642
+ ));
1643
+ }
1644
+ }
1645
+ return $resultContent;
1646
+ }
1647
+
1648
+ /**
1649
+ * disabled newsletter success enabled
1650
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1651
+ */
1652
+ public function disableNewsletterSuccessEnabled()
1653
+ {
1654
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1655
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1656
+ ->setTitle('Disable Newsletter Success : ')
1657
+ ->setMessage('Enabled.');
1658
+
1659
+ foreach ( Mage::app()->getWebsites() as $website ) {
1660
+ $websiteName = $website->getName();
1661
+ $enabled = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DISABLE_NEWSLETTER_SUCCESS))? true :
1662
+ 'Disabled';
1663
+
1664
+ if ($enabled !== true){
1665
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_DISABLE_NEWSLETTER_SUCCESS', 'website' => $website->getId()));
1666
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
1667
+ ->setMessage('Don\'t forget to enable if you want to disable Magento newsletter success email.' )
1668
+ ->setTable(array(
1669
+ 'Website' => $websiteName,
1670
+ 'Status' => $enabled,
1671
+ 'Fast Fix' => 'Click <a href="' . $url . '">here </a>to enable.'
1672
+ ));
1673
+ }
1674
+ }
1675
+ return $resultContent;
1676
+ }
1677
+
1678
+ /**
1679
+ * wishlist sync enabled.
1680
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1681
+ */
1682
+ public function wishlistEnabled()
1683
+ {
1684
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1685
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1686
+ ->setTitle('Wishlist Sync : ')
1687
+ ->setMessage('Enabled.');
1688
+
1689
+ foreach ( Mage::app()->getWebsites() as $website ) {
1690
+ $websiteName = $website->getName();
1691
+ $wishlist = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_WISHLIST_ENABLED))? true :
1692
+ 'Disabled';
1693
+
1694
+ if ($wishlist !== true){
1695
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_SYNC_WISHLIST_ENABLED', 'website' => $website->getId()));
1696
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
1697
+ ->setMessage('Don\'t forget to enable if you want to sync wishlist.' )
1698
+ ->setTable(array(
1699
+ 'Website' => $websiteName,
1700
+ 'Status' => $wishlist,
1701
+ 'Fast Fix' => 'Click <a href="' . $url . '">here </a>to enable.'
1702
+ ));
1703
+ }
1704
+ }
1705
+ return $resultContent;
1706
+ }
1707
+
1708
+ /**
1709
+ * Check if any wishlist are imported.
1710
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1711
+ */
1712
+ public function wishlistSyncing()
1713
+ {
1714
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1715
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1716
+ ->setTitle('Wishlist Syncing : ')
1717
+ ->setMessage('Looks Great.');
1718
+
1719
+ foreach ( Mage::app()->getWebsites() as $website ) {
1720
+ $websiteName = $website->getName();
1721
+ $storeIds = $website->getStoreIds();
1722
+
1723
+ //number of wishlist marked as imported
1724
+ $numWishlist = Mage::getModel('ddg_automation/wishlist')->getCollection()
1725
+ ->addFieldToFilter('wishlist_imported', 1)
1726
+ ->addFieldToFilter('store_id', array('in', $storeIds))
1727
+ ->getSize();
1728
+
1729
+ //total wishlist
1730
+ $totalWishlist = Mage::getModel('ddg_automation/wishlist')->getCollection()
1731
+ ->addFieldToFilter('store_id', array('in', $storeIds))
1732
+ ->getSize();
1733
+
1734
+ $tableData = array(
1735
+ 'Website' => $websiteName,
1736
+ 'Total Wishlist' => $totalWishlist,
1737
+ 'Imported' => $numWishlist
1738
+ );
1739
+
1740
+ $tableData['Status'] = 'Importing';
1741
+
1742
+ if (! $numWishlist) {
1743
+ $tableData['Status'] = 'No Imported Wishlist Found.';
1744
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
1745
+ ->setTitle('Wishlist Sync (ignore if you have reset wishlist) : ')
1746
+ ->setMessage('');
1747
+ }
1748
+ $resultContent->setTable($tableData);
1749
+ }
1750
+ return $resultContent;
1751
+ }
1752
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Importer.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Importer extends Mage_Adminhtml_Block_Widget_Grid_Container
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+
9
+ $this->_controller = 'adminhtml_importer';
10
+ $this->_blockGroup = 'ddg_automation';
11
+ $this->_headerText = Mage::helper('ddg')->__('Importer Status');
12
+
13
+ $this->_removeButton('add');
14
+ }
15
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Importer/Grid.php ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Importer_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/importer_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('id', array(
45
+ 'header' => Mage::helper('ddg')->__('ID'),
46
+ 'align' => 'left',
47
+ 'index' => 'id',
48
+ 'type' => 'number',
49
+ 'escape' => true
50
+ ))->addColumn('import_type', array(
51
+ 'header' => Mage::helper('ddg')->__('Import Type'),
52
+ 'width' => '50px',
53
+ 'index' => 'import_type',
54
+ 'type' => 'text',
55
+ 'escape' => true
56
+ ))->addColumn('import_status', array(
57
+ 'header' => Mage::helper('ddg')->__('Import Status'),
58
+ 'width' => '50px',
59
+ 'index' => 'import_status',
60
+ 'type' => 'options',
61
+ 'escape' => true,
62
+ 'options' => Mage::getModel('ddg_automation/adminhtml_source_importer_status')->getOptions(),
63
+ ))->addColumn('message', array(
64
+ 'header' => Mage::helper('ddg')->__('Error Message'),
65
+ 'index' => 'message',
66
+ 'type' => 'text',
67
+ 'escape' => true
68
+ ))->addColumn('import_mode', array(
69
+ 'header' => Mage::helper('ddg')->__('Import Mode'),
70
+ 'width' => '50px',
71
+ 'index' => 'import_mode',
72
+ 'type' => 'options',
73
+ 'escape' => true,
74
+ 'options' => Mage::getModel('ddg_automation/adminhtml_source_importer_mode')->getOptions(),
75
+ ))->addColumn('import_id', array(
76
+ 'header' => Mage::helper('ddg')->__('Import ID'),
77
+ 'width' => '50px',
78
+ 'index' => 'import_id',
79
+ 'type' => 'text',
80
+ 'escape' => true
81
+ ))->addColumn('import_started', array(
82
+ 'header' => Mage::helper('ddg')->__('Imported Started At'),
83
+ 'width' => '50px',
84
+ 'align' => 'center',
85
+ 'index' => 'import_started',
86
+ 'type' => 'datetime',
87
+ 'escape' => true
88
+ ))->addColumn('import_finished', array(
89
+ 'header' => Mage::helper('ddg')->__('Last Import Check Time'),
90
+ 'width' => '50px',
91
+ 'align' => 'center',
92
+ 'index' => 'import_finished',
93
+ 'type' => 'datetime',
94
+ 'escape' => true
95
+ ))->addColumn('script', array(
96
+ 'header' => Mage::helper('ddg')->__('Script'),
97
+ 'renderer' => 'ddg_automation/adminhtml_column_renderer_script',
98
+ 'column_css_class' => 'no-display',
99
+ 'header_css_class' => 'no-display'
100
+ ))->addColumn('created_at', array(
101
+ 'header' => Mage::helper('ddg')->__('Created At'),
102
+ 'width' => '50px',
103
+ 'align' => 'center',
104
+ 'index' => 'created_at',
105
+ 'type' => 'datetime',
106
+ 'escape' => true
107
+ ))->addColumn('updated_at', array(
108
+ 'header' => Mage::helper('ddg')->__('Updated At'),
109
+ 'width' => '50px',
110
+ 'align' => 'center',
111
+ 'index' => 'updated_at',
112
+ 'type' => 'datetime',
113
+ 'escape' => true
114
+
115
+ ));
116
+ if (!Mage::app()->isSingleStoreMode()) {
117
+ $this->addColumn('website_id', array(
118
+ 'header' => Mage::helper('customer')->__('Website'),
119
+ 'align' => 'center',
120
+ 'width' => '80px',
121
+ 'type' => 'options',
122
+ 'options' => Mage::getSingleton('adminhtml/system_store')->getWebsiteOptionHash(true),
123
+ 'index' => 'website_id',
124
+ ));
125
+ }
126
+
127
+
128
+ return parent::_prepareColumns();
129
+ }
130
+
131
+ /**
132
+ * Get the store.
133
+ *
134
+ * @return Mage_Core_Model_Store
135
+ * @throws Exception
136
+ */
137
+ protected function _getStore()
138
+ {
139
+ $storeId = (int)$this->getRequest()->getParam('store', 0);
140
+ return Mage::app()->getStore($storeId);
141
+ }
142
+
143
+ /**
144
+ * Prepare the grid massaction.
145
+ * @return $this|Mage_Adminhtml_Block_Widget_Grid
146
+ */
147
+ protected function _prepareMassaction()
148
+ {
149
+ $this->setMassactionIdField('id');
150
+ $this->getMassactionBlock()->setFormFieldName('importer');
151
+ $this->getMassactionBlock()->addItem('resend', array(
152
+ 'label' => Mage::helper('ddg')->__('Reset'),
153
+ 'url' => $this->getUrl('*/*/massResend'),
154
+
155
+ ));
156
+ $this->getMassactionBlock()->addItem('delete', array(
157
+ 'label'=> Mage::helper('ddg')->__('Delete'),
158
+ 'url' => $this->getUrl('*/*/massDelete'),
159
+ 'confirm' => Mage::helper('ddg')->__('Are you sure?')));
160
+
161
+ return $this;
162
+ }
163
+ }
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,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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('store_id', array(
52
+ 'header' => Mage::helper('ddg')->__('Store ID'),
53
+ 'width' => '50px',
54
+ 'index' => 'store_id',
55
+ 'type' => 'number',
56
+ 'escape' => true,
57
+ ))->addColumn('order_status', array(
58
+ 'header' => Mage::helper('ddg')->__('Order Status'),
59
+ 'align' => 'right',
60
+ 'width' => '50px',
61
+ 'index' => 'order_status',
62
+ 'type' => 'options',
63
+ 'escape' => true,
64
+ 'options' => Mage::getSingleton('sales/order_config')->getStatuses(),
65
+ ))->addColumn('email_imported', array(
66
+ 'header' => Mage::helper('ddg')->__('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('modified', array(
76
+ 'header' => Mage::helper('ddg')->__('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' => array(
84
+ 1 => 'Modified',
85
+ null => 'Not Modified',
86
+ ),
87
+ 'filter_condition_callback' => array($this, 'filterCallbackContact')
88
+ ))->addColumn('created_at', array(
89
+ 'header' => Mage::helper('ddg')->__('Created At'),
90
+ 'width' => '50px',
91
+ 'align' => 'center',
92
+ 'index' => 'created_at',
93
+ 'type' => 'datetime',
94
+ 'escape' => true,
95
+ ))->addColumn('updated_at', array(
96
+ 'header' => Mage::helper('ddg')->__('Updated At'),
97
+ 'width' => '50px',
98
+ 'align' => 'center',
99
+ 'index' => 'updated_at',
100
+ 'type' => 'datetime',
101
+ 'escape' => true,
102
+ ));
103
+
104
+ return parent::_prepareColumns();
105
+ }
106
+
107
+ /**
108
+ * Callback action for the imported subscribers/contacts.
109
+ *
110
+ * @param $collection
111
+ * @param $column
112
+ */
113
+ public function filterCallbackContact($collection, $column)
114
+ {
115
+ $field = $column->getFilterIndex() ? $column->getFilterIndex() : $column->getIndex();
116
+ $value = $column->getFilter()->getValue();
117
+ if ($value == 'null') {
118
+ $collection->addFieldToFilter($field, array('null' => true));
119
+ } else {
120
+ $collection->addFieldToFilter($field, array('notnull' => true));
121
+ }
122
+ }
123
+ }
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,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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('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/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/Rules.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Rules extends Mage_Adminhtml_Block_Widget_Grid_Container
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+
9
+ $this->_controller = 'adminhtml_rules';
10
+ $this->_blockGroup = 'ddg_automation';
11
+ $this->_headerText = Mage::helper('ddg')->__('Email Exclusion Rule(s)');
12
+ $this->_addButtonLabel = Mage::helper('ddg')->__('Add New Rule');
13
+ parent::__construct();
14
+ }
15
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Rules/Edit.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Shopping cart rule edit form block
5
+ */
6
+
7
+ class Dotdigitalgroup_Email_Block_Adminhtml_Rules_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
8
+ {
9
+
10
+ /**
11
+ * Initialize form
12
+ * Add standard buttons
13
+ * Add "Save and Continue" button
14
+ */
15
+ public function __construct()
16
+ {
17
+ $this->_objectId = 'id';
18
+ $this->_blockGroup = 'ddg_automation';
19
+ $this->_controller = 'adminhtml_rules';
20
+
21
+ parent::__construct();
22
+
23
+ $this->_addButton('save_and_continue_edit', array(
24
+ 'class' => 'save',
25
+ 'label' => Mage::helper('ddg')->__('Save and Continue Edit'),
26
+ 'onclick' => 'editForm.submit($(\'edit_form\').action + \'back/edit/\')',
27
+ ), 10);
28
+ }
29
+
30
+ /**
31
+ * Getter for form header text
32
+ *
33
+ * @return string
34
+ */
35
+ public function getHeaderText()
36
+ {
37
+ $rule = Mage::registry('current_ddg_rule');
38
+ if ($rule->getId()) {
39
+ return Mage::helper('ddg')->__("Edit Rule '%s'", $this->escapeHtml($rule->getName()));
40
+ }
41
+ else {
42
+ return Mage::helper('ddg')->__('New Rule');
43
+ }
44
+ }
45
+
46
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Rules/Edit/Form.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Rules_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
4
+ {
5
+
6
+ public function __construct()
7
+ {
8
+ parent::__construct();
9
+ $this->setId('edit_form');
10
+ $this->setTitle(Mage::helper('salesrule')->__('Rule Information'));
11
+ }
12
+
13
+ protected function _prepareForm()
14
+ {
15
+ $form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getUrl('adminhtml/email_rules/save'), 'method' => 'post'));
16
+ $form->setUseContainer(true);
17
+ $this->setForm($form);
18
+ return parent::_prepareForm();
19
+ }
20
+
21
+
22
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Rules/Edit/Tab/Conditions.php ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Rules_Edit_Tab_Conditions
4
+ extends Mage_Adminhtml_Block_Widget_Form
5
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
6
+ {
7
+ /**
8
+ * Prepare content for tab
9
+ *
10
+ * @return string
11
+ */
12
+ public function getTabLabel()
13
+ {
14
+ return Mage::helper('ddg')->__('Conditions');
15
+ }
16
+
17
+ /**
18
+ * Prepare title for tab
19
+ *
20
+ * @return string
21
+ */
22
+ public function getTabTitle()
23
+ {
24
+ return Mage::helper('ddg')->__('Conditions');
25
+ }
26
+
27
+ /**
28
+ * Returns status flag about this tab can be showen or not
29
+ *
30
+ * @return true
31
+ */
32
+ public function canShowTab()
33
+ {
34
+ return true;
35
+ }
36
+
37
+ /**
38
+ * Returns status flag about this tab hidden or not
39
+ *
40
+ * @return true
41
+ */
42
+ public function isHidden()
43
+ {
44
+ return false;
45
+ }
46
+
47
+ protected function _prepareForm()
48
+ {
49
+ $model = Mage::registry('current_ddg_rule');
50
+ $form = new Varien_Data_Form();
51
+ $form->setHtmlIdPrefix('rule_');
52
+
53
+ $fieldset = $form->addFieldset('base_fieldset',
54
+ array('legend' => Mage::helper('ddg')->__('Exclusion Rule Conditions'))
55
+ );
56
+
57
+ $fieldset->addField('combination', 'select', array(
58
+ 'label' => Mage::helper('ddg')->__('Conditions Combination Match'),
59
+ 'title' => Mage::helper('ddg')->__('Conditions Combination Match'),
60
+ 'name' => 'combination',
61
+ 'required' => true,
62
+ 'options' => array(
63
+ '1' => Mage::helper('ddg')->__('ALL'),
64
+ '2' => Mage::helper('ddg')->__('ANY'),
65
+ ),
66
+ 'after_element_html' => '<small>Choose ANY if using multi line conditions for same attribute.
67
+ If multi line conditions for same attribute is used and ALL is chosen then multiple lines for same attribute will be ignored.</small>',
68
+ ));
69
+
70
+ $field = $fieldset->addField('condition', 'select', array(
71
+ 'name' => 'condition',
72
+ 'label' => Mage::helper('ddg')->__('Condition'),
73
+ 'title' => Mage::helper('ddg')->__('Condition'),
74
+ 'required' => true,
75
+ 'options' => Mage::getModel('ddg_automation/adminhtml_source_rules_type')->toOptionArray(),
76
+ ));
77
+ $renderer = $this->getLayout()->createBlock('ddg_automation/adminhtml_config_rules_customdatafields');
78
+ $field->setRenderer($renderer);
79
+
80
+ $form->setValues($model->getData());
81
+ $this->setForm($form);
82
+
83
+ return parent::_prepareForm();
84
+ }
85
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Rules/Edit/Tab/Main.php ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Rules_Edit_Tab_Main
4
+ extends Mage_Adminhtml_Block_Widget_Form
5
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
6
+ {
7
+ /**
8
+ * Prepare content for tab
9
+ *
10
+ * @return string
11
+ */
12
+ public function getTabLabel()
13
+ {
14
+ return Mage::helper('salesrule')->__('Rule Information');
15
+ }
16
+
17
+ /**
18
+ * Prepare title for tab
19
+ *
20
+ * @return string
21
+ */
22
+ public function getTabTitle()
23
+ {
24
+ return Mage::helper('salesrule')->__('Rule Information');
25
+ }
26
+
27
+ /**
28
+ * Returns status flag about this tab can be showed or not
29
+ *
30
+ * @return true
31
+ */
32
+ public function canShowTab()
33
+ {
34
+ return true;
35
+ }
36
+
37
+ /**
38
+ * Returns status flag about this tab hidden or not
39
+ *
40
+ * @return true
41
+ */
42
+ public function isHidden()
43
+ {
44
+ return false;
45
+ }
46
+
47
+ protected function _prepareForm()
48
+ {
49
+ $model = Mage::registry('current_ddg_rule');
50
+
51
+ $form = new Varien_Data_Form();
52
+ $form->setHtmlIdPrefix('rule_');
53
+
54
+ $fieldset = $form->addFieldset('base_fieldset',
55
+ array('legend' => Mage::helper('ddg')->__('Rule Information'))
56
+ );
57
+
58
+ if ($model->getId()) {
59
+ $fieldset->addField('id', 'hidden', array(
60
+ 'name' => 'id',
61
+ ));
62
+ }
63
+
64
+ $fieldset->addField('name', 'text', array(
65
+ 'name' => 'name',
66
+ 'label' => Mage::helper('ddg')->__('Rule Name'),
67
+ 'title' => Mage::helper('ddg')->__('Rule Name'),
68
+ 'required' => true,
69
+ ));
70
+
71
+ $fieldset->addField('type', 'select', array(
72
+ 'label' => Mage::helper('ddg')->__('Rule Type'),
73
+ 'title' => Mage::helper('ddg')->__('Rule Type'),
74
+ 'name' => 'type',
75
+ 'required' => true,
76
+ 'options' => array(
77
+ Dotdigitalgroup_Email_Model_Rules::ABANDONED => 'Abandoned Cart Exclusion Rule',
78
+ Dotdigitalgroup_Email_Model_Rules::REVIEW => 'Review Email Exclusion Rule',
79
+ ),
80
+ ));
81
+
82
+ $fieldset->addField('status', 'select', array(
83
+ 'label' => Mage::helper('ddg')->__('Status'),
84
+ 'title' => Mage::helper('ddg')->__('Status'),
85
+ 'name' => 'status',
86
+ 'required' => true,
87
+ 'options' => array(
88
+ '1' => Mage::helper('ddg')->__('Active'),
89
+ '0' => Mage::helper('ddg')->__('Inactive'),
90
+ ),
91
+ ));
92
+
93
+ if (!$model->getId()) {
94
+ $model->setData('status', '0');
95
+ }
96
+
97
+ if (Mage::app()->isSingleStoreMode()) {
98
+ $websiteId = Mage::app()->getStore(true)->getWebsiteId();
99
+ $fieldset->addField('website_ids', 'hidden', array(
100
+ 'name' => 'website_ids[]',
101
+ 'value' => $websiteId
102
+ ));
103
+ $model->setWebsiteIds($websiteId);
104
+ } else {
105
+ $field = $fieldset->addField('website_ids', 'multiselect', array(
106
+ 'name' => 'website_ids[]',
107
+ 'label' => Mage::helper('ddg')->__('Websites'),
108
+ 'title' => Mage::helper('ddg')->__('Websites'),
109
+ 'required' => true,
110
+ 'values' => Mage::getSingleton('adminhtml/system_store')->getWebsiteValuesForForm()
111
+ ));
112
+ $renderer = $this->getLayout()->createBlock('adminhtml/store_switcher_form_renderer_fieldset_element');
113
+ $field->setRenderer($renderer);
114
+ }
115
+
116
+ $form->setValues($model->getData());
117
+ $this->setForm($form);
118
+
119
+ return parent::_prepareForm();
120
+ }
121
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Rules/Edit/Tabs.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Rules_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+ $this->setId('ddg_rules_tabs');
9
+ $this->setDestElementId('edit_form');
10
+ $this->setTitle(Mage::helper('ddg')->__('Exclusion Rule'));
11
+ }
12
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Rules/Grid.php ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Rules_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('ddg_rules_grid');
12
+ $this->setDefaultDir('asc');
13
+ $this->setSaveParametersInSession(true);
14
+ }
15
+
16
+ /**
17
+ * Prepare the grid collection.
18
+ * @return Mage_Adminhtml_Block_Widget_Grid
19
+ */
20
+ protected function _prepareCollection()
21
+ {
22
+ $collection = Mage::getModel('ddg_automation/rules')->getResourceCollection();
23
+ $this->setCollection($collection);
24
+ parent::_prepareCollection();
25
+ return $this;
26
+ }
27
+
28
+ /**
29
+ * Add columns to grid
30
+ *
31
+ * @return $this
32
+ * @throws Exception
33
+ */
34
+ protected function _prepareColumns()
35
+ {
36
+ $this->addColumn('rule_id', array(
37
+ 'header' => Mage::helper('ddg')->__('ID'),
38
+ 'align' =>'right',
39
+ 'width' => '50px',
40
+ 'index' => 'id',
41
+ ));
42
+
43
+ $this->addColumn('name', array(
44
+ 'header' => Mage::helper('ddg')->__('Rule Name'),
45
+ 'align' =>'left',
46
+ 'width' => '150px',
47
+ 'index' => 'name',
48
+ ));
49
+
50
+ $this->addColumn('type', array(
51
+ 'header' => Mage::helper('ddg')->__('Rule Type'),
52
+ 'align' => 'left',
53
+ 'width' => '150px',
54
+ 'index' => 'type',
55
+ 'type' => 'options',
56
+ 'options' => array(
57
+ 1 => 'Abandoned Cart Exclusion Rule',
58
+ 2 => 'Review Email Exclusion Rule',
59
+ ),
60
+ ));
61
+
62
+ $this->addColumn('status', array(
63
+ 'header' => Mage::helper('ddg')->__('Status'),
64
+ 'align' => 'left',
65
+ 'width' => '80px',
66
+ 'index' => 'status',
67
+ 'type' => 'options',
68
+ 'options' => array(
69
+ 1 => 'Active',
70
+ 0 => 'Inactive',
71
+ ),
72
+ ));
73
+
74
+ $this->addColumn('created_at', array(
75
+ 'header' => Mage::helper('ddg')->__('Created At'),
76
+ 'align' => 'left',
77
+ 'width' => '120px',
78
+ 'type' => 'datetime',
79
+ 'index' => 'created_at',
80
+ ));
81
+
82
+ $this->addColumn('updated_at', array(
83
+ 'header' => Mage::helper('ddg')->__('Updated At'),
84
+ 'align' => 'left',
85
+ 'width' => '120px',
86
+ 'type' => 'datetime',
87
+ 'index' => 'updated_at',
88
+ ));
89
+
90
+ if (!Mage::app()->isSingleStoreMode()) {
91
+ $this->addColumn('rule_website', array(
92
+ 'header' => Mage::helper('salesrule')->__('Website'),
93
+ 'align' =>'left',
94
+ 'index' => 'website_ids',
95
+ 'type' => 'options',
96
+ 'sortable' => false,
97
+ 'options' => Mage::getSingleton('adminhtml/system_store')->getWebsiteOptionHash(),
98
+ 'width' => 150,
99
+ ));
100
+ }
101
+ parent::_prepareColumns();
102
+ return $this;
103
+ }
104
+
105
+ /**
106
+ * Retrieve row click URL
107
+ *
108
+ * @param Varien_Object $row
109
+ *
110
+ * @return string
111
+ */
112
+ public function getRowUrl($row)
113
+ {
114
+ return $this->getUrl('*/*/edit', array('id' => $row->getId()));
115
+ }
116
+ }
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/Initialsync.php → community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Reimportcatalog.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_Reimportcatalog 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/resetcatalog");
14
 
15
  return $this->getLayout()->createBlock('adminhtml/widget_button')
16
  ->setType('button')
19
  ->toHtml();
20
  }
21
 
22
+ }
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/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Reimportreviews.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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')
17
+ ->setLabel($this->__($title))
18
+ ->setOnClick("window.location.href='" . $url . "'")
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/Reset.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Advanced_Reset 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/reset");
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/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/Runcatalogsync.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Advanced_Runcatalogsync 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/runcatalogsync");
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/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_studio/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/Installation.php ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Installation extends Mage_Core_Block_Template
4
+ {
5
+ public $sections = array(
6
+ 'connector_api_credentials',
7
+ 'connector_data_mapping',
8
+ 'connector_sync_settings',
9
+ 'connector_roi_tracking',
10
+ 'connector_lost_baskets',
11
+ 'connector_reviews',
12
+ 'connector_dynamic_content',
13
+ 'connector_transactional_emails',
14
+ 'connector_configuration',
15
+ 'connector_developer_settings'
16
+ );
17
+
18
+ /**
19
+ * get the website domain.
20
+ *
21
+ * @return string
22
+ */
23
+ public function getDomain()
24
+ {
25
+ return Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
26
+ }
27
+
28
+ /**
29
+ * api username.
30
+ * @return string
31
+ */
32
+ public function getApiUsername()
33
+ {
34
+ return Mage::helper('ddg')->getApiUsername();
35
+ }
36
+
37
+ /**
38
+ * check if the cron is running.
39
+ * @return bool
40
+ */
41
+ public function getCronInstalled()
42
+ {
43
+ return (Mage::helper('ddg')->getCronInstalled())? '1' : '0';
44
+ }
45
+
46
+ /*
47
+ * Features enabled to use.
48
+ */
49
+ public function getFeatures()
50
+ {
51
+ $section = $this->getRequest()->getParam('section');
52
+
53
+ // not not track other sections
54
+ if (!in_array($section, $this->sections))
55
+ return;
56
+
57
+ $features = array(
58
+ 'customer_sync' => $this->getCustomerSync(),
59
+ 'guest_sync' => $this->getGuestSync(),
60
+ 'subscriber_sync' => $this->getSubscriberSync(),
61
+ 'order_sync' => $this->getOrderSync(),
62
+ 'catalog_sync' => $this->getCatalogSync(),
63
+ 'dotmailer_smtp' => $this->getDotmailerSmtp(),
64
+ 'roi' => $this->getRoi()
65
+ );
66
+
67
+ return json_encode($features);
68
+ }
69
+
70
+
71
+ public function getCatalogSync()
72
+ {
73
+ return Mage::helper('ddg')->getCatalogSyncEnabled();
74
+ }
75
+
76
+ public function getOrderSync()
77
+ {
78
+ return Mage::helper('ddg')->getOrderSyncEnabled();
79
+ }
80
+
81
+ public function getSubscriberSync()
82
+ {
83
+ return Mage::helper('ddg')->getSubscriberSyncEnabled();
84
+ }
85
+
86
+ public function getGuestSync()
87
+ {
88
+ return Mage::helper('ddg')->getGuestSyncEnabled();
89
+ }
90
+
91
+ public function getCustomerSync()
92
+ {
93
+ return Mage::helper('ddg')->getContactSyncEnabled();
94
+ }
95
+
96
+ public function getRoi()
97
+ {
98
+ return Mage::helper('ddg')->getRoiTrackingEnabled();
99
+ }
100
+
101
+ public function getDotmailerSmtp()
102
+ {
103
+ return Mage::helper('ddg')->isSmtpEnabled();
104
+ }
105
+
106
+ /**
107
+ * magento version.
108
+ * @return string
109
+ */
110
+ public function getMageVersion()
111
+ {
112
+ return Mage::getVersion();
113
+ }
114
+
115
+ /**
116
+ * connector version.
117
+ * @return string
118
+ */
119
+ public function getConnectorVersion()
120
+ {
121
+ return Mage::helper('ddg')->getConnectorVersion();
122
+ }
123
+
124
+ /**
125
+ * Get the api and website names.
126
+ * @return mixed|string
127
+ */
128
+ public function getWebsiteNames()
129
+ {
130
+
131
+ $data = Mage::helper('ddg')->getStringWebsiteApiAccounts();
132
+
133
+ return $data;
134
+ }
135
+
136
+ /**
137
+ * Get the account email.
138
+ *
139
+ * @return mixed
140
+ */
141
+ public function getAccountEmail()
142
+ {
143
+ return Mage::helper('ddg')->getAccountEmail();
144
+ }
145
+
146
+
147
+ /**
148
+ * Use the beacon only on the api connector section.
149
+ * @return string
150
+ */
151
+ protected function _toHtml()
152
+ {
153
+ $section = $this->getAction()->getRequest()->getParam('section', false);
154
+
155
+ if ($section == 'connector_api_credentials') {
156
+ return parent::_toHtml();
157
+ } else {
158
+ return '';
159
+ }
160
+ }
161
+ }
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_automation_studio_sms_sms_four_message', '{{var order_number}}');return false;\">Insert Order Number</a>
18
+ <a href='#' onclick=\"injectText('connector_automation_studio_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_automation_studio_sms_sms_one_message', '{{var order_number}}');return false;\">Insert Order Number</a>
20
+ <a href='#' onclick=\"injectText('connector_automation_studio_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_automation_studio_sms_sms_three_message', '{{var order_number}}');return false;\">Insert Order Number</a>
20
+ <a href='#' onclick=\"injectText('connector_automation_studio_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_automation_studio_sms_sms_two_message', '{{var order_number}}');return false;\">Insert Order Number</a>
19
+ <a href='#' onclick=\"injectText('connector_automation_studio_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('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('item_count', array(
59
+ 'header' => Mage::helper('ddg')->__('Item Count'),
60
+ 'align' => 'left',
61
+ 'width' => '50px',
62
+ 'index' => 'item_count',
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,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 '. $quoteId);
29
+ return false;
30
+ }
31
+ if (! $quoteModel->getIsActive()) {
32
+ Mage::helper('ddg')->log('Cart is not active : '. $quoteId);
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
+ /**
57
+ * url for "take me to basket" link
58
+ *
59
+ * @return string
60
+ */
61
+ public function getUrlForLink()
62
+ {
63
+ return $this->_quote->getStore()->getUrl(
64
+ 'connector/email/getbasket',
65
+ array('quote_id' => $this->_quote->getId())
66
+ );
67
+ }
68
+
69
+ /**
70
+ * can show go to basket url
71
+ *
72
+ * @return bool
73
+ */
74
+ public function canShowUrl()
75
+ {
76
+ return (boolean) $this->_quote->getStore()->getWebsite()->getConfig(
77
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CONTENT_LINK_ENABLED
78
+ );
79
+ }
80
+
81
+ public function takeMeToCartTextForUrl()
82
+ {
83
+ return $this->_quote->getStore()->getWebsite()->getConfig(
84
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CONTENT_LINK_TEXT
85
+ );
86
+ }
87
+ }
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,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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->_getCustomerSession()->setConnectorContactId($contact->id);
199
+ $this->contact_id = $contact->id;
200
+ }else{
201
+ $contact = $this->_getApiClient()->postContacts($this->getCustomer()->getEmail());
202
+ if($contact->id){
203
+ $this->_getCustomerSession()->setConnectorContactId($contact->id);
204
+ $this->contact_id = $contact->id;
205
+ }
206
+ }
207
+ return $contact;
208
+ }
209
+
210
+ private function _getCustomerSession()
211
+ {
212
+ return Mage::getSingleton('customer/session');
213
+ }
214
+ }
app/code/community/Dotdigitalgroup/Email/Block/Edc.php ADDED
@@ -0,0 +1,393 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Edc extends Mage_Core_Block_Template
4
+ {
5
+ protected $_edc_type;
6
+
7
+ protected function _construct()
8
+ {
9
+ parent::_construct();
10
+
11
+ if ($this->hasData('edc_type')) {
12
+ $this->_edc_type = $this->getData('edc_type');
13
+ }
14
+ }
15
+
16
+ /**
17
+ * Prepare layout, set the template.
18
+ * @return Mage_Core_Block_Abstract|void
19
+ */
20
+ protected function _prepareLayout()
21
+ {
22
+ if ($root = $this->getLayout()->getBlock('root')) {
23
+ $root->setTemplate('page/blank.phtml');
24
+ }
25
+ }
26
+
27
+ /**
28
+ * Product related items.
29
+ *
30
+ * @param Mage_Catalog_Model_Product $productModel
31
+ * @param $mode
32
+ *
33
+ * @return array
34
+ */
35
+ protected function _getRecommendedProduct(Mage_Catalog_Model_Product $productModel, $mode)
36
+ {
37
+ //array of products to display
38
+ $products = array();
39
+ switch($mode){
40
+ case 'related':
41
+ $products = $productModel->getRelatedProducts();
42
+ break;
43
+ case 'upsell':
44
+ $products = $productModel->getUpSellProducts();
45
+ break;
46
+ case 'crosssell':
47
+ $products = $productModel->getCrossSellProducts();
48
+ break;
49
+
50
+ }
51
+ $productIds = array();
52
+ foreach($products as $product){
53
+ $productIds[] = $product->getId();
54
+ }
55
+ return $productIds;
56
+ }
57
+
58
+ public function getTextForUrl($store)
59
+ {
60
+ $store = Mage::app()->getStore($store);
61
+ return $store->getConfig(
62
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DYNAMIC_CONTENT_LINK_TEXT
63
+ );
64
+ }
65
+
66
+ /**
67
+ * Diplay mode type.
68
+ *
69
+ * @return mixed|string
70
+ */
71
+ public function getMode()
72
+ {
73
+ return Mage::helper('ddg/recommended')->getDisplayType();
74
+
75
+ }
76
+
77
+ /**
78
+ * Number of the colums.
79
+ * @return int|mixed
80
+ * @throws Exception
81
+ */
82
+ public function getColumnCount()
83
+ {
84
+ return Mage::helper('ddg/recommended')->getDisplayLimitByMode($this->getRequest()->getActionName());
85
+ }
86
+
87
+ /**
88
+ * Price html.
89
+ * @param $product
90
+ *
91
+ * @return string
92
+ */
93
+ public function getPriceHtml($product)
94
+ {
95
+ $this->setTemplate('connector/product/price.phtml');
96
+ $this->setProduct($product);
97
+ return $this->toHtml();
98
+ }
99
+
100
+ /**
101
+ * get collection to EDC type
102
+ *
103
+ * @return array
104
+ * @throws Exception
105
+ */
106
+ public function getLoadedProductCollection()
107
+ {
108
+ $mode = $this->getRequest()->getActionName();
109
+ $limit = Mage::helper('ddg/recommended')->getDisplayLimitByMode($mode);
110
+
111
+ switch ($this->_edc_type) {
112
+ case 'recently_viewed':
113
+ return $this->_getRecentlyViewedCollection($limit);
114
+ break;
115
+ case 'product_push':
116
+ return $this->_getProductPushCollection($limit);
117
+ break;
118
+ case 'bestsellers':
119
+ return $this->_getBestSellersCollection($mode, $limit);
120
+ break;
121
+ case 'most_viewed':
122
+ return $this->_getMostViewedCollection($mode, $limit);
123
+ break;
124
+ case 'quote_products':
125
+ return $this->_getQuoteProductCollection($mode, $limit);
126
+ break;
127
+ }
128
+ }
129
+
130
+ /**
131
+ * get collection for recently viewed products
132
+ *
133
+ * @param $limit
134
+ * @return array
135
+ * @throws Exception
136
+ */
137
+ private function _getRecentlyViewedCollection($limit)
138
+ {
139
+ $productsToDisplay = array();
140
+ $customerId = $this->getRequest()->getParam('customer_id');
141
+
142
+ //login customer to receive the recent products
143
+ $session = Mage::getSingleton('customer/session');
144
+ $isLoggedIn = $session->loginById($customerId);
145
+
146
+ /** @var Mage_Reports_Block_Product_Viewed $collection */
147
+ $collection = Mage::getSingleton('Mage_Reports_Block_Product_Viewed');
148
+ $items = $collection->getItemsCollection()
149
+ ->setPageSize($limit);
150
+ Mage::helper('ddg')->log('Recentlyviewed customer : ' . $customerId . ', mode ' . $mode . ', limit : ' . $limit .
151
+ ', items found : ' . count($items) . ', is customer logged in : ' . $isLoggedIn . ', products :' . count($productsToDisplay));
152
+ foreach ($items as $product) {
153
+ $product = Mage::getModel('catalog/product')->load($product->getId());
154
+ if($product->isSalable())
155
+ $productsToDisplay[$product->getId()] = $product;
156
+
157
+ }
158
+ $session->logout();
159
+
160
+ return $productsToDisplay;
161
+ }
162
+
163
+ /**
164
+ * get collection for push items
165
+ *
166
+ * @param $limit
167
+ * @return array
168
+ */
169
+ private function _getProductPushCollection($limit)
170
+ {
171
+ $productsToDisplay = array();
172
+ $productIds = Mage::helper('ddg/recommended')->getProductPushIds();
173
+
174
+ $productCollection = Mage::getResourceModel('catalog/product_collection')
175
+ ->addAttributeToFilter('entity_id', array('in' => $productIds))
176
+ ->addAttributeToSelect(array('product_url', 'name', 'store_id', 'small_image', 'price'))
177
+ ->setPageSize($limit);
178
+
179
+ foreach ($productCollection as $product) {
180
+ if($product->isSaleable())
181
+ $productsToDisplay[] = $product;
182
+ }
183
+
184
+ return $productsToDisplay;
185
+ }
186
+
187
+ /**
188
+ * get collection for best sellers
189
+ *
190
+ * @param $mode
191
+ * @param $limit
192
+ * @return Varien_Data_Collection
193
+ */
194
+ private function _getBestSellersCollection($mode, $limit)
195
+ {
196
+ $from = Mage::helper('ddg/recommended')->getTimeFromConfig($mode);
197
+ $locale = Mage::app()->getLocale()->getLocale();
198
+ $to = Zend_Date::now($locale)->toString(Zend_Date::ISO_8601);
199
+
200
+ $productCollection = Mage::getResourceModel('reports/product_collection')
201
+ ->addAttributeToSelect(array('product_url', 'name', 'store_id', 'small_image', 'price'))
202
+ ->addOrderedQty($from, $to)
203
+ ->setOrder('ordered_qty', 'desc')
204
+ ->setPageSize($limit);
205
+
206
+ Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($productCollection);
207
+ $productCollection->addAttributeToFilter('is_saleable', TRUE);
208
+
209
+ $cat_id = Mage::app()->getRequest()->getParam('category_id');
210
+ $cat_name = Mage::app()->getRequest()->getParam('category_name');
211
+ if($cat_id or $cat_name){
212
+ if($cat_id)
213
+ $category = Mage::getModel('catalog/category')->load($cat_id);
214
+
215
+ if($cat_name)
216
+ $category = Mage::getModel('catalog/category')->loadByAttribute('name', $cat_name);
217
+
218
+ $productCollection = $this->_joinCategoryOnCollection($productCollection, $category);
219
+ }
220
+ return $productCollection;
221
+ }
222
+
223
+ /**
224
+ * get collection for most viewed items
225
+ *
226
+ * @param $mode
227
+ * @param $limit
228
+ * @return array
229
+ */
230
+ private function _getMostViewedCollection($mode, $limit)
231
+ {
232
+ $productsToDisplay = array();
233
+ $from = Mage::helper('ddg/recommended')->getTimeFromConfig($mode);
234
+ $locale = Mage::app()->getLocale()->getLocale();
235
+
236
+ $to = Zend_Date::now($locale)->toString(Zend_Date::ISO_8601);
237
+ $productCollection = Mage::getResourceModel('reports/product_collection')
238
+ ->addViewsCount($from, $to)
239
+ ->setPageSize($limit);
240
+
241
+ $cat_id = Mage::app()->getRequest()->getParam('category_id');
242
+ $cat_name = Mage::app()->getRequest()->getParam('category_name');
243
+ if($cat_id or $cat_name){
244
+ if($cat_id)
245
+ $category = Mage::getModel('catalog/category')->load($cat_id);
246
+
247
+ if($cat_name)
248
+ $category = Mage::getModel('catalog/category')->loadByAttribute('name', $cat_name);
249
+
250
+ $productCollection = $this->_joinCategoryOnCollection($productCollection, $category);
251
+ }
252
+
253
+ $productIds = $productCollection->getColumnValues('entity_id');
254
+ $productCollection->clear();
255
+ $productCollection = Mage::getModel('catalog/product')
256
+ ->getCollection()
257
+ ->addIdFilter($productIds)
258
+ ->addAttributeToSelect(array('product_url', 'name', 'store_id', 'small_image', 'price'));
259
+
260
+ foreach ($productCollection as $_product) {
261
+ $productId = $_product->getId();
262
+ $product = Mage::getModel('catalog/product')->load($productId);
263
+ if($product->isSalable())
264
+ $productsToDisplay[] = $product;
265
+ }
266
+
267
+ return $productsToDisplay;
268
+ }
269
+
270
+ /**
271
+ * join categories on product collection
272
+ *
273
+ * @param $productCollection
274
+ * @param $category
275
+ * @return mixed
276
+ */
277
+ private function _joinCategoryOnCollection($productCollection, $category)
278
+ {
279
+ if($category->getId()){
280
+ $productCollection->getSelect()
281
+ ->joinLeft(
282
+ array("ccpi" => 'catalog_category_product_index'),
283
+ "e.entity_id = ccpi.product_id",
284
+ array("category_id")
285
+ )
286
+ ->where('ccpi.category_id =?', $category->getId());
287
+ }else{
288
+ Mage::helper('ddg')->log('Most viewed. Category id/name is invalid. It does not exist.');
289
+ }
290
+
291
+ return $productCollection;
292
+ }
293
+
294
+ /**
295
+ * get collection for quote products
296
+ *
297
+ * @param $mode
298
+ * @param $limit
299
+ * @return array
300
+ * @throws Exception
301
+ */
302
+ private function _getQuoteProductCollection($mode, $limit)
303
+ {
304
+ $quoteModel = Mage::registry('current_quote');
305
+ if (! $quoteModel) {
306
+ Mage::throwException('no current_quote found for EDC');
307
+ }
308
+
309
+ $quoteItems = $quoteModel->getAllItems();
310
+ $productsToDisplay = $this->getProductsToDisplay($quoteItems, $limit, $mode, 'QUOTE');
311
+
312
+ return $productsToDisplay;
313
+ }
314
+
315
+ /**
316
+ * get products to display for order, wishlist and quote EDC
317
+ *
318
+ * @param $items
319
+ * @param $limit
320
+ * @param $mode
321
+ * @param $type
322
+ * @return array
323
+ */
324
+ protected function getProductsToDisplay($items, $limit, $mode, $type)
325
+ {
326
+ //products to be display for recommended pages
327
+ $productsToDisplay = array();
328
+ $productsToDisplayCounter = 0;
329
+
330
+ $numItems = count($items);
331
+
332
+ //no product found to display
333
+ if ($numItems == 0 || ! $limit) {
334
+ return array();
335
+ }elseif (count($items) > $limit) {
336
+ $maxPerChild = 1;
337
+ } else {
338
+ $maxPerChild = number_format($limit / count($items));
339
+ }
340
+
341
+ Mage::helper('ddg')->log('DYNAMIC ' .$type. ' PRODUCTS : limit ' . $limit . ' products : ' . $numItems . ', max per child : '. $maxPerChild);
342
+
343
+ foreach ($items as $item) {
344
+ $i = 0;
345
+ //parent product
346
+ $product = $item->getProduct();
347
+ //check for product exists
348
+ if ($product->getId()) {
349
+ //get single product for current mode
350
+ $recommendedProducts = $this->_getRecommendedProduct($product, $mode);
351
+ if(!empty($recommendedProducts)){
352
+ $recommendedProducts = Mage::getModel('catalog/product')
353
+ ->getCollection()
354
+ ->addIdFilter($recommendedProducts)
355
+ ->addAttributeToSelect(array('product_url', 'name', 'store_id', 'small_image', 'price'));
356
+
357
+ foreach ($recommendedProducts as $product) {
358
+ //check if still exists
359
+ if ($product->getId() && $productsToDisplayCounter < $limit && $i <= $maxPerChild && $product->isSaleable() && !$product->getParentId()) {
360
+ //we have a product to display
361
+ $productsToDisplay[$product->getId()] = $product;
362
+ $i++;
363
+ $productsToDisplayCounter++;
364
+ }
365
+ }
366
+ }
367
+ }
368
+ //have reached the limit don't loop for more
369
+ if ($productsToDisplayCounter == $limit) {
370
+ break;
371
+ }
372
+ }
373
+
374
+ //check for more space to fill up the table with fallback products
375
+ if ($productsToDisplayCounter < $limit) {
376
+ $fallbackIds = Mage::helper('ddg/recommended')->getFallbackIds();
377
+ $productCollection = Mage::getModel('catalog/product')
378
+ ->getCollection()
379
+ ->addIdFilter($fallbackIds)
380
+ ->addAttributeToSelect(array('product_url', 'name', 'store_id', 'small_image', 'price'));
381
+
382
+ foreach ($productCollection as $product) {
383
+ if($product->isSaleable())
384
+ $productsToDisplay[$product->getId()] = $product;
385
+ //stop the limit was reached
386
+ if (count($productsToDisplay) == $limit) {
387
+ break;
388
+ }
389
+ }
390
+ }
391
+ return $productsToDisplay;
392
+ }
393
+ }
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
+ /** @var Mage_Sales_Model_Quote_Item $item */
59
+ foreach($quoteItems as $item)
60
+ {
61
+ $productModel = $item->getProduct();
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,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Order extends Dotdigitalgroup_Email_Block_Edc
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
+ $order = Mage::registry('current_order');
29
+ if (! $order) {
30
+ Mage::throwException('no current_order found for EDC');
31
+ }
32
+
33
+ return $order;
34
+ }
35
+
36
+ /**
37
+ * Filter items for review. If a customer has already placed a review for a product then exclude the product.
38
+ *
39
+ * @param array $items
40
+ * @param int $websiteId
41
+ * @return mixed
42
+ */
43
+ public function filterItemsForReview($items, $websiteId)
44
+ {
45
+ if (!count($items))
46
+ return;
47
+
48
+ $order = $this->getOrder();
49
+
50
+ //if customer is guest then no need to filter any items
51
+ if($order->getCustomerIsGuest())
52
+ return $items;
53
+
54
+ if(!Mage::helper('ddg/review')->isNewProductOnly($websiteId))
55
+ return $items;
56
+
57
+ $customerId = $order->getCustomerId();
58
+
59
+ foreach($items as $key => $item)
60
+ {
61
+ $productId = $item->getProduct()->getId();
62
+
63
+ $collection = Mage::getModel('review/review')->getCollection();
64
+ $collection->addCustomerFilter($customerId)
65
+ ->addStoreFilter($order->getStoreId())
66
+ ->addFieldToFilter('main_table.entity_pk_value', $productId);
67
+
68
+ //remove item if customer has already placed review on this item
69
+ if($collection->getSize())
70
+ unset($items[$key]);
71
+ }
72
+
73
+ return $items;
74
+ }
75
+ }
app/code/community/Dotdigitalgroup/Email/Block/Order/Creditmemo.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $order = Mage::registry('current_order');
24
+ if (! $order) {
25
+ Mage::throwException('no current_order found for EDC');
26
+ }
27
+
28
+ if (! $order->hasCreditmemos()) {
29
+ //throw new Exception('TE - no creditmemo for order : '. $orderId);
30
+ Mage::helper('ddg')->log('TE - no creditmemo for order : '. $order->getId());
31
+ return false;
32
+ }
33
+
34
+ return $order;
35
+ }
36
+
37
+ /**
38
+ * Order items.
39
+ * @return mixed
40
+ */
41
+ public function getCreditmemoItems()
42
+ {
43
+ return Mage::registry('current_order')->getItemsCollection();
44
+ }
45
+ }
app/code/community/Dotdigitalgroup/Email/Block/Order/Invoice.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $order = Mage::registry('current_order');
23
+ if (! $order) {
24
+ Mage::throwException('no current_order found for EDC');
25
+ }
26
+
27
+ if (! $order->hasInvoices()) {
28
+ //throw new Exception('TE - no invoice for order : '. $orderId);
29
+ Mage::helper('ddg')->log('TE - no invoice for order : '. $order->getId());
30
+ return false;
31
+ }
32
+
33
+ return $order;
34
+ }
35
+
36
+ }
app/code/community/Dotdigitalgroup/Email/Block/Order/Shipping.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $order = Mage::registry('current_order');
22
+ if (! $order) {
23
+ Mage::throwException('no current_order found for EDC');
24
+ }
25
+
26
+ if (! $order->hasShipments()) {
27
+ //throw new Exception('TE - no shipments for order : '. $orderId);
28
+ Mage::helper('ddg')->log('TE - no shipments for order : '. $order->getId());
29
+ return false;
30
+ }
31
+
32
+ return $order;
33
+
34
+ }
35
+
36
+ }
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/Products.php ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Recommended_Products extends Dotdigitalgroup_Email_Block_Edc
4
+ {
5
+ /**
6
+ * Slot div name.
7
+ * @var string
8
+ */
9
+ public $slot;
10
+
11
+ /**
12
+ * get the products to display for table
13
+ */
14
+ public function getLoadedProductCollection()
15
+ {
16
+ $orderModel = Mage::registry('current_order');
17
+ if (! $orderModel) {
18
+ Mage::throwException('no current_order found for EDC');
19
+ }
20
+
21
+ //display mode based on the action name
22
+ $mode = $this->getRequest()->getActionName();
23
+ //number of product items to be displayed
24
+ $limit = Mage::helper('ddg/recommended')->getDisplayLimitByMode($mode);
25
+ $orderItems = $orderModel->getAllItems();
26
+
27
+ $productsToDisplay = $this->getProductsToDisplay($orderItems, $limit, $mode, 'PRODUCT');
28
+ return $productsToDisplay;
29
+ }
30
+
31
+ /**
32
+ * Nosto products data.
33
+ * @return object
34
+ */
35
+ public function getNostoProducts()
36
+ {
37
+ $client = Mage::getModel('ddg_automation/apiconnector_client');
38
+ //slot name, div id
39
+ $slot = Mage::app()->getRequest()->getParam('slot', false);
40
+
41
+ //email recommendation
42
+ $email = Mage::app()->getRequest()->getParam('email', false);
43
+
44
+ //no valid data for nosto recommendation
45
+ if (!$slot || ! $email)
46
+ return false;
47
+ else
48
+ $this->slot = $slot;
49
+
50
+ //html data from nosto
51
+ $data = $client->getNostoProducts($slot, $email);
52
+
53
+ //check for valid response
54
+ if (! isset($data->$email) && !isset($data->$email->$slot))
55
+ return false;
56
+ return $data->$email->$slot;
57
+ }
58
+
59
+ /**
60
+ * Slot name.
61
+ * Should be called after getNostoProducts.
62
+ * @return string
63
+ */
64
+ public function getSlotName()
65
+ {
66
+ return $this->slot;
67
+ }
68
+ }
app/code/community/Dotdigitalgroup/Email/Block/Recommended/Wishlistproducts.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Recommended_Wishlistproducts extends Dotdigitalgroup_Email_Block_Edc
4
+ {
5
+
6
+ protected function _getWishlistItems()
7
+ {
8
+ $wishlist = $this->_getWishlist();
9
+ if($wishlist && count($wishlist->getItemCollection()))
10
+ return $wishlist->getItemCollection();
11
+ else
12
+ return array();
13
+ }
14
+
15
+ protected function _getWishlist()
16
+ {
17
+ $customerId = Mage::app()->getRequest()->getParam('customer_id');
18
+ if(!$customerId)
19
+ return array();
20
+
21
+ $customer = Mage::getModel('customer/customer')->load($customerId);
22
+ if(!$customer->getId())
23
+ return array();
24
+
25
+ $collection = Mage::getModel('wishlist/wishlist')->getCollection();
26
+ $collection->addFieldToFilter('customer_id', $customerId)
27
+ ->setOrder('updated_at', 'DESC');
28
+
29
+ if ($collection->count())
30
+ return $collection->getFirstItem();
31
+ else
32
+ return array();
33
+
34
+ }
35
+
36
+ /**
37
+ * get the products to display for table
38
+ */
39
+ public function getLoadedProductCollection()
40
+ {
41
+ //display mode based on the action name
42
+ $mode = $this->getRequest()->getActionName();
43
+ //number of product items to be displayed
44
+ $limit = Mage::helper('ddg/recommended')->getDisplayLimitByMode($mode);
45
+
46
+ $items = $this->_getWishlistItems();
47
+ $productsToDisplay = $this->getProductsToDisplay($items, $limit, $mode, 'WISHLIST');
48
+
49
+ return $productsToDisplay;
50
+ }
51
+ }
app/code/community/Dotdigitalgroup/Email/Block/System/Email/Template/Edit.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Block_System_Email_Template_Edit extends Mage_Adminhtml_Block_System_Email_Template_Edit
3
+ {
4
+ public function __construct()
5
+ {
6
+ parent::__construct();
7
+ $this->setTemplate('connector/system/email/template/edit.phtml');
8
+ }
9
+ public function getConnectorTemplates()
10
+ {
11
+ return Mage::helper('ddg')->getTemplateList();
12
+ }
13
+ }
app/code/community/Dotdigitalgroup/Email/Block/Wishlist.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Wishlist extends Dotdigitalgroup_Email_Block_Edc
4
+ {
5
+ protected $_website;
6
+
7
+ public function getWishlistItems()
8
+ {
9
+ $wishlist = $this->_getWishlist();
10
+ if($wishlist && count($wishlist->getItemCollection()))
11
+ return $wishlist->getItemCollection();
12
+ else
13
+ return false;
14
+ }
15
+
16
+ protected function _getWishlist()
17
+ {
18
+ $customerId = Mage::app()->getRequest()->getParam('customer_id');
19
+ if(!$customerId)
20
+ return false;
21
+
22
+ $customer = Mage::getModel('customer/customer')->load($customerId);
23
+ if(!$customer->getId())
24
+ return false;
25
+
26
+ $collection = Mage::getModel('wishlist/wishlist')->getCollection();
27
+ $collection->addFieldToFilter('customer_id', $customerId)
28
+ ->setOrder('updated_at', 'DESC');
29
+
30
+ if ($collection->count())
31
+ return $collection->setPageSize(1)->setCurPage(1)->getFirstItem();
32
+ else
33
+ return false;
34
+
35
+ }
36
+
37
+ public function getMode()
38
+ {
39
+ return Mage::helper('ddg')->getWebsiteConfig(
40
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DYNAMIC_CONTENT_WIHSLIST_DISPLAY
41
+ );
42
+ }
43
+ }
app/code/community/Dotdigitalgroup/Email/Helper/Config.php ADDED
@@ -0,0 +1,346 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Helper_Config
4
+ {
5
+ const MODULE_NAME = 'Dotdigitalgroup_Email';
6
+
7
+ /**
8
+ * API SECTION.
9
+ */
10
+ const XML_PATH_CONNECTOR_API_ENABLED = 'connector_api_credentials/api/enabled';
11
+ const XML_PATH_CONNECTOR_API_USERNAME = 'connector_api_credentials/api/username';
12
+ const XML_PATH_CONNECTOR_API_PASSWORD = 'connector_api_credentials/api/password';
13
+
14
+ /**
15
+ * SMS SECTION.
16
+ */
17
+ //enabled
18
+ const XML_PATH_CONNECTOR_SMS_ENABLED_1 = 'connector_automation_studio/sms/sms_one_enabled';
19
+ const XML_PATH_CONNECTOR_SMS_ENABLED_2 = 'connector_automation_studio/sms/sms_two_enabled';
20
+ const XML_PATH_CONNECTOR_SMS_ENABLED_3 = 'connector_automation_studio/sms/sms_three_enabled';
21
+ const XML_PATH_CONNECTOR_SMS_ENABLED_4 = 'connector_automation_studio/sms/sms_four_enabled';
22
+ //status
23
+ const XML_PATH_CONNECTOR_SMS_STATUS_1 = 'connector_automation_studio/sms/sms_one_status';
24
+ const XML_PATH_CONNECTOR_SMS_STATUS_2 = 'connector_automation_studio/sms/sms_two_status';
25
+ const XML_PATH_CONNECTOR_SMS_STATUS_3 = 'connector_automation_studio/sms/sms_three_status';
26
+ const XML_PATH_CONNECTOR_SMS_STATUS_4 = 'connector_automation_studio/sms/sms_four_status';
27
+ //message
28
+ const XML_PATH_CONNECTOR_SMS_MESSAGE_1 = 'connector_automation_studio/sms/sms_one_message';
29
+ const XML_PATH_CONNECTOR_SMS_MESSAGE_2 = 'connector_automation_studio/sms/sms_two_message';
30
+ const XML_PATH_CONNECTOR_SMS_MESSAGE_3 = 'connector_automation_studio/sms/sms_three_message';
31
+ const XML_PATH_CONNECTOR_SMS_MESSAGE_4 = 'connector_automation_studio/sms/sms_four_message';
32
+
33
+ /**
34
+ * SYNC SECTION.
35
+ */
36
+ const XML_PATH_CONNECTOR_SYNC_CONTACT_ENABLED = 'connector_sync_settings/sync/contact_enabled';
37
+ const XML_PATH_CONNECTOR_SYNC_GUEST_ENABLED = 'connector_sync_settings/sync/guest_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
+ const XML_PATH_CONNECTOR_SYNC_CATALOG_ENABLED = 'connector_sync_settings/sync/catalog_enabled';
44
+
45
+ const XML_PATH_CONNECTOR_CUSTOMERS_ADDRESS_BOOK_ID = 'connector_sync_settings/address_book/customers';
46
+ const XML_PATH_CONNECTOR_SUBSCRIBERS_ADDRESS_BOOK_ID = 'connector_sync_settings/address_book/subscribers';
47
+ const XML_PATH_CONNECTOR_GUEST_ADDRESS_BOOK_ID = 'connector_sync_settings/address_book/guests';
48
+ // Mapping
49
+ const XML_PATH_CONNECTOR_MAPPING_LAST_ORDER_ID = 'connector_data_mapping/customer_data/last_order_id';
50
+ const XML_PATH_CONNECTOR_MAPPING_LAST_QUOTE_ID = 'connector_data_mapping/customer_data/last_quote_id';
51
+ const XML_PATH_CONNECTOR_MAPPING_CUSTOMER_ID = 'connector_data_mapping/customer_data/customer_id';
52
+ const XML_PATH_CONNECTOR_MAPPING_CUSTOM_DATAFIELDS = 'connector_data_mapping/customer_data/custom_attributes';
53
+ const XML_PATH_CONNECTOR_MAPPING_CUSTOMER_STORENAME = 'connector_data_mapping/customer_data/store_name';
54
+ const XML_PATH_CONNECTOR_MAPPING_CUSTOMER_TOTALREFUND = 'connector_data_mapping/customer_data/total_refund';
55
+ const XML_PATH_CONNECTOR_MAPPING_SWEETTOOTH_ACTIVE = 'connector_data_mapping/sweet_tooth/active';
56
+
57
+ /**
58
+ * Abandoned Carts.
59
+ */
60
+ const XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CARTS_ENABLED_1 = 'connector_lost_baskets/customers/enabled_1';
61
+ const XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CAMPAIGN_1 = 'connector_lost_baskets/customers/campaign_1';
62
+ const XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CARTS_ENABLED_2 = 'connector_lost_baskets/customers/enabled_2';
63
+ const XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CAMPAIGN_2 = 'connector_lost_baskets/customers/campaign_2';
64
+ const XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CARTS_ENABLED_3 = 'connector_lost_baskets/customers/enabled_3';
65
+ const XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CAMPAIGN_3 = 'connector_lost_baskets/customers/campaign_3';
66
+ const XML_PATH_CONNECTOR_GUEST_ABANDONED_CARTS_ENABLED_1 = 'connector_lost_baskets/guests/enabled_1';
67
+ const XML_PATH_CONNECTOR_GUEST_ABANDONED_CAMPAIGN_1 = 'connector_lost_baskets/guests/campaign_1';
68
+ const XML_PATH_CONNECTOR_GUEST_ABANDONED_CARTS_ENABLED_2 = 'connector_lost_baskets/guests/enabled_2';
69
+ const XML_PATH_CONNECTOR_GUEST_ABANDONED_CAMPAIGN_2 = 'connector_lost_baskets/guests/campaign_2';
70
+ const XML_PATH_CONNECTOR_GUEST_ABANDONED_CARTS_ENABLED_3 = 'connector_lost_baskets/guests/enabled_3';
71
+ const XML_PATH_CONNECTOR_GUEST_ABANDONED_CAMPAIGN_3 = 'connector_lost_baskets/guests/campaign_3';
72
+
73
+ /**
74
+ * Datafields Mapping.
75
+ */
76
+ const XML_PATH_CONNECTOR_CUSTOMER_ID = 'connector_data_mapping/customer_data/customer_id';
77
+ const XML_PATH_CONNECTOR_CUSTOMER_FIRSTNAME = 'connector_data_mapping/customer_data/firstname';
78
+ const XML_PATH_CONNECTOR_CUSTOMER_LASTNAME = 'connector_data_mapping/customer_data/lastname';
79
+ const XML_PATH_CONNECTOR_CUSTOMER_DOB = 'connector_data_mapping/customer_data/dob';
80
+ const XML_PATH_CONNECTOR_CUSTOMER_GENDER = 'connector_data_mapping/customer_data/gender';
81
+ const XML_PATH_CONNECTOR_CUSTOMER_WEBSITE_NAME = 'connector_data_mapping/customer_data/website_name';
82
+ const XML_PATH_CONNECTOR_CUSTOMER_STORE_NAME = 'connector_data_mapping/customer_data/store_name';
83
+ const XML_PATH_CONNECTOR_CUSTOMER_CREATED_AT = 'connector_data_mapping/customer_data/created_at';
84
+ const XML_PATH_CONNECTOR_CUSTOMER_LAST_LOGGED_DATE = 'connector_data_mapping/customer_data/last_logged_date';
85
+ const XML_PATH_CONNECTOR_CUSTOMER_CUSTOMER_GROUP = 'connector_data_mapping/customer_data/customer_group';
86
+ const XML_PATH_CONNECTOR_CUSTOMER_REVIEW_COUNT = 'connector_data_mapping/customer_data/review_count';
87
+ const XML_PATH_CONNECTOR_CUSTOMER_LAST_REVIEW_DATE = 'connector_data_mapping/customer_data/last_review_date';
88
+ const XML_PATH_CONNECTOR_CUSTOMER_BILLING_ADDRESS_1 = 'connector_data_mapping/customer_data/billing_address_1';
89
+ const XML_PATH_CONNECTOR_CUSTOMER_BILLING_ADDRESS_2 = 'connector_data_mapping/customer_data/billing_address_2';
90
+ const XML_PATH_CONNECTOR_CUSTOMER_BILLING_CITY = 'connector_data_mapping/customer_data/billing_city';
91
+ const XML_PATH_CONNECTOR_CUSTOMER_BILLING_STATE = 'connector_data_mapping/customer_data/billing_state';
92
+ const XML_PATH_CONNECTOR_CUSTOMER_BILLING_COUNTRY = 'connector_data_mapping/customer_data/billing_country';
93
+ const XML_PATH_CONNECTOR_CUSTOMER_BILLING_POSTCODE = 'connector_data_mapping/customer_data/billing_postcode';
94
+ const XML_PATH_CONNECTOR_CUSTOMER_BILLING_TELEPHONE = 'connector_data_mapping/customer_data/billing_telephone';
95
+ const XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_ADDRESS_1 = 'connector_data_mapping/customer_data/delivery_address_1';
96
+ const XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_ADDRESS_2 = 'connector_data_mapping/customer_data/delivery_address_2';
97
+ const XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_CITY = 'connector_data_mapping/customer_data/delivery_city';
98
+ const XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_STATE = 'connector_data_mapping/customer_data/delivery_state';
99
+ const XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_COUNTRY = 'connector_data_mapping/customer_data/delivery_country';
100
+ const XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_POSTCODE = 'connector_data_mapping/customer_data/delivery_postcode';
101
+ const XML_PATH_CONNECTOR_CUSTOMER_DELIVERY_TELEPHONE = 'connector_data_mapping/customer_data/delivery_telephone';
102
+ const XML_PATH_CONNECTOR_CUSTOMER_TOTAL_NUMBER_ORDER = 'connector_data_mapping/customer_data/number_of_orders';
103
+ const XML_PATH_CONNECTOR_CUSTOMER_AOV = 'connector_data_mapping/customer_data/average_order_value';
104
+ const XML_PATH_CONNECTOR_CUSTOMER_TOTAL_SPEND = 'connector_data_mapping/customer_data/total_spend';
105
+ const XML_PATH_CONNECTOR_CUSTOMER_LAST_ORDER_DATE = 'connector_data_mapping/customer_data/last_order_date';
106
+ const XML_PATH_CONNECTOR_CUSTOMER_LAST_ORDER_ID = 'connector_data_mapping/customer_data/last_order_id';
107
+ const XML_PATH_CONNECTOR_CUSTOMER_TOTAL_REFUND = 'connector_data_mapping/customer_data/total_refund';
108
+ const XML_PATH_CONNECTOR_CUSTOMER_LAST_ORDER_INCREMENT_ID = 'connector_data_mapping/customer_data/last_increment_id';
109
+ const XML_PATH_CONNECTOR_CUSTOMER_MOST_PURCHASED_CATEGORY = 'connector_data_mapping/customer_data/most_pur_category';
110
+ const XML_PATH_CONNECTOR_CUSTOMER_MOST_PURCHASED_BRAND = 'connector_data_mapping/customer_data/most_pur_brand';
111
+ const XML_PATH_CONNECTOR_CUSTOMER_MOST_FREQUENT_PURCHASE_DAY = 'connector_data_mapping/customer_data/most_freq_pur_day';
112
+ const XML_PATH_CONNECTOR_CUSTOMER_MOST_FREQUENT_PURCHASE_MONTH = 'connector_data_mapping/customer_data/most_freq_pur_mon';
113
+ const XML_PATH_CONNECTOR_CUSTOMER_FIRST_CATEGORY_PURCHASED = 'connector_data_mapping/customer_data/first_category_pur';
114
+ const XML_PATH_CONNECTOR_CUSTOMER_LAST_CATEGORY_PURCHASED = 'connector_data_mapping/customer_data/last_category_pur';
115
+ const XML_PATH_CONNECTOR_CUSTOMER_FIRST_BRAND_PURCHASED = 'connector_data_mapping/customer_data/first_brand_pur';
116
+ const XML_PATH_CONNECTOR_CUSTOMER_LAST_BRAND_PURCHASED = 'connector_data_mapping/customer_data/last_brand_pur';
117
+ const XML_PATH_CONNECTOR_CUSTOMER_SUBSCRIBER_STATUS = 'connector_data_mapping/customer_data/subscriber_status';
118
+ const XML_PATH_CONNECTOR_ABANDONED_PRODUCT_NAME = 'connector_data_mapping/customer_data/abandoned_prod_name';
119
+
120
+ const XML_PATH_CONNECTOR_ENTERPRISE_CURRENT_BALANCE = 'connector_data_mapping/enterprise_data/reward_points';
121
+ const XML_PATH_CONNECTOR_ENTERPRISE_REWARD_AMOUNT = 'connector_data_mapping/enterprise_data/reward_amount';
122
+ const XML_PATH_CONNECTOR_ENTERPRISE_CREATED_DATE = 'connector_data_mapping/enterprise_data/created_date';
123
+ const XML_PATH_CONNECTOR_ENTERPRISE_EXPIRATION_DATE = 'connector_data_mapping/enterprise_data/expiration_date';
124
+ const XML_PATH_CONNECTOR_ENTERPIRSE_LAST_USED_DATE = 'connector_data_mapping/enterprise_data/last_used_date';
125
+ const XML_PATH_CONNECTOR_ENTERPRISE_CUSTOMER_SEGMENTS = 'connector_data_mapping/enterprise_data/customer_segment';
126
+
127
+
128
+ /**
129
+ * Dynamic Content
130
+ */
131
+ const XML_PATH_CONNECTOR_DYNAMIC_CONTENT_PASSCODE = 'connector_dynamic_content/external_dynamic_content_urls/passcode';
132
+ const XML_PATH_CONNECTOR_DYNAMIC_CONTENT_NOSTO = 'connector_dynamic_content/nosto_recommendation/api';
133
+ const XML_PATH_CONNECTOR_DYNAMIC_CONTENT_WIHSLIST_DISPLAY = 'connector_dynamic_content/products/wishlist_display_type';
134
+
135
+ /**
136
+ * CONFIGURATION SECTION.
137
+ */
138
+ //Data Fields
139
+ const XML_PATH_CONNECTOR_SYNC_DATA_FIELDS_STATUS = 'connector_configuration/data_fields/order_statuses';
140
+
141
+ //Transactional Data
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_SYNC_ORDER_PRODUCT_ATTRIBUTES = 'connector_configuration/transactional_data/order_product_attributes';
146
+ const XML_PATH_CONNECTOR_SYNC_ORDER_PRODUCT_CUSTOM_OPTIONS = 'connector_configuration/transactional_data/order_product_custom_options';
147
+ //Admin
148
+ const XML_PATH_CONNECTOR_DISABLE_NEWSLETTER_SUCCESS = 'connector_configuration/admin/disable_newsletter_success';
149
+ const XML_PATH_CONNECTOR_DISABLE_CUSTOMER_SUCCESS = 'connector_configuration/admin/disable_customer_success';
150
+ //Dynamic Content Styling
151
+ const XML_PATH_CONNECTOR_DYNAMIC_STYLING = 'connector_configuration/dynamic_content_style/dynamic_syling';
152
+ const XML_PATH_CONNECTOR_DYNAMIC_NAME_COLOR = 'connector_configuration/dynamic_content_style/name_color';
153
+ const XML_PATH_CONNECTOR_DYNAMIC_NAME_FONT_SIZE = 'connector_configuration/dynamic_content_style/name_font_size';
154
+ const XML_PATH_CONNECTOR_DYNAMIC_NAME_STYLE = 'connector_configuration/dynamic_content_style/name_style';
155
+ const XML_PATH_CONNECTOR_DYNAMIC_PRICE_COLOR = 'connector_configuration/dynamic_content_style/price_color';
156
+ const XML_PATH_CONNECTOR_DYNAMIC_PRICE_FONT_SIZE = 'connector_configuration/dynamic_content_style/price_font_size';
157
+ const XML_PATH_CONNECTOR_DYNAMIC_PRICE_STYLE = 'connector_configuration/dynamic_content_style/price_style';
158
+ const XML_PATH_CONNECTOR_DYNAMIC_LINK_COLOR = 'connector_configuration/dynamic_content_style/link_color';
159
+ const XML_PATH_CONNECTOR_DYNAMIC_LINK_FONT_SIZE = 'connector_configuration/dynamic_content_style/link_font_size';
160
+ const XML_PATH_CONNECTOR_DYNAMIC_LINK_STYLE = 'connector_configuration/dynamic_content_style/link_style';
161
+ const XML_PATH_CONNECTOR_DYNAMIC_DOC_FONT = 'connector_configuration/dynamic_content_style/font_picker';
162
+ const XML_PATH_CONNECTOR_DYNAMIC_DOC_BG_COLOR = 'connector_configuration/dynamic_content_style/doc_color';
163
+ const XML_PATH_CONNECTOR_DYNAMIC_OTHER_COLOR = 'connector_configuration/dynamic_content_style/other_color';
164
+ const XML_PATH_CONNECTOR_DYNAMIC_OTHER_FONT_SIZE = 'connector_configuration/dynamic_content_style/other_font_size';
165
+ const XML_PATH_CONNECTOR_DYNAMIC_OTHER_STYLE = 'connector_configuration/dynamic_content_style/other_style';
166
+ const XML_PATH_CONNECTOR_DYNAMIC_COUPON_COLOR = 'connector_configuration/dynamic_content_style/coupon_color';
167
+ const XML_PATH_CONNECTOR_DYNAMIC_COUPON_FONT_SIZE = 'connector_configuration/dynamic_content_style/coupon_font_size';
168
+ const XML_PATH_CONNECTOR_DYNAMIC_COUPON_STYLE = 'connector_configuration/dynamic_content_style/coupon_style';
169
+ const XML_PATH_CONNECTOR_DYNAMIC_COUPON_FONT = 'connector_configuration/dynamic_content_style/coupon_font_picker';
170
+ const XML_PATH_CONNECTOR_DYNAMIC_COUPON_BG_COLOR = 'connector_configuration/dynamic_content_style/coupon_doc_color';
171
+
172
+ //Catalog
173
+ const XML_PATH_CONNECTOR_SYNC_CATALOG_VALUES = 'connector_configuration/catalog_sync/catalog_values';
174
+ const XML_PATH_CONNECTOR_SYNC_CATALOG_VISIBILITY = 'connector_configuration/catalog_sync/catalog_visibility';
175
+ const XML_PATH_CONNECTOR_SYNC_CATALOG_TYPE = 'connector_configuration/catalog_sync/catalog_type';
176
+ //Abandoned Cart
177
+ const XML_PATH_CONNECTOR_EMAIL_CAPTURE = 'connector_configuration/abandoned_carts/email_capture';
178
+ const XML_PATH_CONNECTOR_ABANDONED_CART_LIMIT = 'connector_configuration/abandoned_carts/limits';
179
+ const XML_PATH_CONNECTOR_EMAIL_CAPTURE_NEWSLETTER = 'connector_configuration/abandoned_carts/email_capture_newsletter';
180
+ const XML_PATH_CONNECTOR_CONTENT_LINK_ENABLED = 'connector_configuration/abandoned_carts/link_enabled';
181
+ const XML_PATH_CONNECTOR_CONTENT_LINK_TEXT = 'connector_configuration/abandoned_carts/link_text';
182
+ const XML_PATH_CONNECTOR_CONTENT_CART_URL = 'connector_configuration/abandoned_carts/cart_url';
183
+ const XML_PATH_CONNECTOR_CONTENT_LOGIN_URL = 'connector_configuration/abandoned_carts/login_url';
184
+ // Address Book Pref
185
+ const XML_PATH_CONNECTOR_ADDRESSBOOK_PREF_CAN_CHANGE_BOOKS = 'connector_configuration/address_book_pref/can_change';
186
+ const XML_PATH_CONNECTOR_ADDRESSBOOK_PREF_SHOW_BOOKS = 'connector_configuration/address_book_pref/show_books';
187
+ const XML_PATH_CONNECTOR_ADDRESSBOOK_PREF_CAN_SHOW_FIELDS = 'connector_configuration/address_book_pref/can_show_fields';
188
+ const XML_PATH_CONNECTOR_ADDRESSBOOK_PREF_SHOW_FIELDS = 'connector_configuration/address_book_pref/fields_to_show';
189
+ //Dynamic Content
190
+ const XML_PATH_CONNECTOR_DYNAMIC_CONTENT_LINK_TEXT = 'connector_configuration/dynamic_content_style/link_text';
191
+
192
+ /**
193
+ * Automation studio.
194
+ */
195
+ const XML_PATH_CONNECTOR_AUTOMATION_STUDIO_CUSTOMER = 'connector_automation_studio/visitor_automation/customer_automation';
196
+ const XML_PATH_CONNECTOR_AUTOMATION_STUDIO_SUBSCRIBER = 'connector_automation_studio/visitor_automation/subscriber_automation';
197
+ const XML_PATH_CONNECTOR_AUTOMATION_STUDIO_ORDER = 'connector_automation_studio/visitor_automation/order_automation';
198
+ const XML_PATH_CONNECTOR_AUTOMATION_STUDIO_GUEST_ORDER = 'connector_automation_studio/visitor_automation/guest_order_automation';
199
+ const XML_PATH_CONNECTOR_AUTOMATION_STUDIO_REVIEW = 'connector_automation_studio/visitor_automation/review_automation';
200
+ const XML_PATH_CONNECTOR_AUTOMATION_STUDIO_WISHLIST = 'connector_automation_studio/visitor_automation/wishlist_automation';
201
+ const XML_PATH_CONNECTOR_AUTOMATION_STUDIO_ORDER_STATUS = 'connector_automation_studio/order_status_automation/status_to_automation';
202
+
203
+
204
+ /**
205
+ * ROI SECTION.
206
+ */
207
+ const XML_PATH_CONNECTOR_ROI_TRACKING_ENABLED = 'connector_configuration/tracking/roi_enabled';
208
+ const XML_PATH_CONNECTOR_PAGE_TRACKING_ENABLED = 'connector_configuration/tracking/page_enabled';
209
+
210
+ /**
211
+ * OAUTH
212
+ */
213
+ const API_CONNECTOR_OAUTH_URL = 'https://my.dotmailer.com/';
214
+ const API_CONNECTOR_OAUTH_URL_AUTHORISE = 'OAuth2/authorise.aspx?';
215
+ const API_CONNECTOR_OAUTH_URL_TOKEN = 'OAuth2/Tokens.ashx';
216
+ const API_CONNECTOR_OAUTH_URL_LOG_USER = '?oauthtoken=';
217
+
218
+ const CONNECTOR_FEED_LAST_CHECK_TIME = 'connector_feed_last_check_time';
219
+
220
+ /**
221
+ * Reviews SECTION
222
+ */
223
+ const XML_PATH_REVIEWS_ENABLED = 'connector_automation_studio/review_settings/enabled';
224
+ const XML_PATH_REVIEWS_FEEFO_LOGON = 'connector_automation_studio/feefo_feedback_engine/logon';
225
+ const XML_PATH_REVIEWS_FEEFO_REVIEWS = 'connector_automation_studio/feefo_feedback_engine/reviews_per_product';
226
+ const XML_PATH_REVIEWS_FEEFO_TEMPLATE = 'connector_automation_studio/feefo_feedback_engine/template';
227
+
228
+
229
+ /**
230
+ * Developer SECTION.
231
+ */
232
+ const XML_PATH_CONNECTOR_FEED_URL = 'connector_developer_settings/feed_configuration/feed_url';
233
+ const XML_PATH_CONNECTOR_CLIENT_ID = 'connector_developer_settings/oauth/client_id';
234
+ const XML_PATH_CONNECTOR_SYNC_LIMIT = 'connector_developer_settings/import_settings/batch_size';
235
+ const XML_PATH_CONNECTOR_FEED_ENABLED = 'connector_developer_settings/feed_configuration/feed_enabled';
236
+ const XML_PATH_RAYGUN_APPLICATION_CODE = 'connector_developer_settings/debug/raygun_code';
237
+ const XML_PATH_CONNECTOR_CUSTOM_DOMAIN = 'connector_developer_settings/oauth/custom_domain';
238
+ const XML_PATH_CONNECTOR_FEED_FREQUENCY = 'connector_developer_settings/feed_configuration/frequency';
239
+ const XML_PATH_RAYGUN_APPLICATION_ASYNC = 'connector_developer_settings/debug/raygun_async';
240
+ const XML_PATH_CONNECTOR_FEED_USE_HTTPS = 'connector_developer_settings/feed_configuration/use_https';
241
+ const XML_PATH_CONNECTOR_SETUP_DATAFIELDS = 'connector_developer_settings/sync_settings/setup_data_fields';
242
+ const XML_PATH_CONNECTOR_CLIENT_SECRET_ID = 'connector_developer_settings/oauth/client_key';
243
+ const XML_PATH_CONNECTOR_CUSTOM_AUTHORIZATION = 'connector_developer_settings/oauth/custom_authorization';
244
+ const XML_PATH_CONNECTOR_RESOURCE_ALLOCATION = 'connector_developer_settings/import_settings/memory_limit';
245
+ const XML_PATH_CONNECTOR_ADVANCED_DEBUG_ENABLED = 'connector_developer_settings/debug/debug_enabled';
246
+ const XML_PATH_CONNECTOR_DEBUG_API_REQUEST_LIMIT = 'connector_developer_settings/debug/api_request_time_limit';
247
+ const XML_PATH_CONNECTOR_TRANSACTIONAL_DATA_SYNC_LIMIT = 'connector_developer_settings/import_settings/orders';
248
+ const XML_PATH_CONNECTOR_IP_RESTRICTION_ADDRESSES = 'connector_developer_settings/ip_restriction/ip_addresses';
249
+
250
+ /**
251
+ * Nosto
252
+ */
253
+ const API_ENDPOINT = 'https://api.nosto.com';
254
+ const API_ENDPOINT_TEST = 'https://test.api.nosto.com';
255
+
256
+ const RAYGUN_API_CODE_URL = 'https://dotmailerformagento.co.uk/magento/raygun.xml';
257
+
258
+
259
+ /**
260
+ * @param int $website
261
+ *
262
+ * @return bool
263
+ * @throws Mage_Core_Exception
264
+ */
265
+ public function getAuthorizeLinkFlag($website = 0)
266
+ {
267
+ $website = Mage::app()->getWebsite($website);
268
+
269
+ $customDomain = $website->getConfig(self::XML_PATH_CONNECTOR_CUSTOM_DOMAIN);
270
+
271
+ return (bool)$customDomain;
272
+ }
273
+
274
+ /**
275
+ * @param int $website
276
+ *
277
+ * @return string
278
+ * @throws Mage_Core_Exception
279
+ */
280
+ public function getAuthorizeLink($website = 0)
281
+ {
282
+ //base url, check for custom oauth domain
283
+ if ($this->getAuthorizeLinkFlag($website)){
284
+ $website = Mage::app()->getWebsite($website);
285
+
286
+ $baseUrl = $website->getConfig(self::XML_PATH_CONNECTOR_CUSTOM_DOMAIN) . self::API_CONNECTOR_OAUTH_URL_AUTHORISE;
287
+
288
+ } else {
289
+ $baseUrl = self::API_CONNECTOR_OAUTH_URL . self::API_CONNECTOR_OAUTH_URL_AUTHORISE;
290
+ }
291
+
292
+ return $baseUrl;
293
+ }
294
+
295
+ /**
296
+ * Callback authorization url.
297
+ * @return mixed|string
298
+ */
299
+ public function getCallbackUrl()
300
+ {
301
+ if ($callback = Mage::getStoreConfig(self::XML_PATH_CONNECTOR_CUSTOM_AUTHORIZATION)){
302
+ return $callback;
303
+ }
304
+
305
+ return $redirectUri = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB, true);
306
+ }
307
+
308
+ /**
309
+ * @param int $website
310
+ *
311
+ * @return string
312
+ */
313
+ public function getTokenUrl($website = 0)
314
+ {
315
+ if ($this->getAuthorizeLinkFlag($website)) {
316
+ $website = Mage::app()->getWebsite($website);
317
+
318
+ $tokenUrl = $website->getConfig(self::XML_PATH_CONNECTOR_CUSTOM_DOMAIN) . self::API_CONNECTOR_OAUTH_URL_TOKEN;
319
+ } else {
320
+
321
+ $tokenUrl = self::API_CONNECTOR_OAUTH_URL . self::API_CONNECTOR_OAUTH_URL_TOKEN;
322
+ }
323
+
324
+ return $tokenUrl;
325
+ }
326
+
327
+
328
+ /**
329
+ * @param int $website
330
+ *
331
+ * @return string
332
+ */
333
+ public function getLogUserUrl( $website = 0 )
334
+ {
335
+ if ($this->getAuthorizeLinkFlag($website)) {
336
+ $website = Mage::app()->getWebsite($website);
337
+
338
+ $logUserUrl = $website->getConfig(self::XML_PATH_CONNECTOR_CUSTOM_DOMAIN) . self::API_CONNECTOR_OAUTH_URL_LOG_USER;
339
+ } else {
340
+
341
+ $logUserUrl = self::API_CONNECTOR_OAUTH_URL . self::API_CONNECTOR_OAUTH_URL_LOG_USER;
342
+ }
343
+ return $logUserUrl;
344
+ }
345
+
346
+ }
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,900 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ /**
82
+ * Extension version number.
83
+ * @return string
84
+ */
85
+ public function getConnectorVersion()
86
+ {
87
+ $modules = (array) Mage::getConfig()->getNode('modules')->children();
88
+ if (isset($modules['Dotdigitalgroup_Email'])) {
89
+ $moduleName = $modules['Dotdigitalgroup_Email'];
90
+ return (string) $moduleName->version;
91
+ }
92
+ return '';
93
+ }
94
+
95
+
96
+ public function getPageTrackingEnabled()
97
+ {
98
+ return (bool)Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_PAGE_TRACKING_ENABLED);
99
+ }
100
+
101
+ public function getRoiTrackingEnabled()
102
+ {
103
+ return (bool)Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_ROI_TRACKING_ENABLED);
104
+ }
105
+
106
+ public function getResourceAllocationEnabled()
107
+ {
108
+ return (bool)Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_RESOURCE_ALLOCATION);
109
+ }
110
+
111
+ public function getMappedStoreName($website)
112
+ {
113
+ $mapped = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_CUSTOMER_STORENAME);
114
+ $storeName = ($mapped)? $mapped : '';
115
+ return $storeName;
116
+ }
117
+
118
+ /**
119
+ * Get the contact id for the custoemer based on website id.
120
+ * @param $email
121
+ * @param $websiteId
122
+ *
123
+ * @return bool
124
+ */
125
+ public function getContactId($email, $websiteId)
126
+ {
127
+ $contact = Mage::getModel('ddg_automation/contact')->loadByCustomerEmail($email, $websiteId);
128
+ if ($contactId = $contact->getContactId()) {
129
+ return $contactId;
130
+ }
131
+
132
+ $client = $this->getWebsiteApiClient($websiteId);
133
+ $response = $client->postContacts($email);
134
+
135
+ if (isset($response->message))
136
+ return false;
137
+ //save contact id
138
+ if (isset($response->id)){
139
+ $contact->setContactId($response->id)
140
+ ->save();
141
+ }
142
+ return $response->id;
143
+ }
144
+
145
+ public function getCustomerAddressBook($website)
146
+ {
147
+ $website = Mage::app()->getWebsite($website);
148
+ return $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMERS_ADDRESS_BOOK_ID);
149
+ }
150
+
151
+ public function getSubscriberAddressBook($website)
152
+ {
153
+ $website = Mage::app()->getWebsite($website);
154
+ return $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SUBSCRIBERS_ADDRESS_BOOK_ID);
155
+ }
156
+
157
+ public function getGuestAddressBook($website)
158
+ {
159
+ $website = Mage::app()->getWebsite($website);
160
+ return $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_GUEST_ADDRESS_BOOK_ID);
161
+ }
162
+
163
+ /**
164
+ * @return $this
165
+ */
166
+ public function allowResourceFullExecution()
167
+ {
168
+ if ($this->getResourceAllocationEnabled()) {
169
+
170
+ /* it may be needed to set maximum execution time of the script to longer,
171
+ * like 60 minutes than usual */
172
+ set_time_limit(7200);
173
+
174
+ /* and memory to 512 megabytes */
175
+ ini_set('memory_limit', '512M');
176
+ }
177
+ return $this;
178
+ }
179
+ public function convert($size)
180
+ {
181
+ $unit=array('b','kb','mb','gb','tb','pb');
182
+ return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i];
183
+ }
184
+
185
+ /**
186
+ * @return string
187
+ */
188
+ public function getStringWebsiteApiAccounts()
189
+ {
190
+ $accounts = array();
191
+ foreach (Mage::app()->getWebsites() as $website) {
192
+ $websiteId = $website->getId();
193
+ $apiUsername = $this->getApiUsername($website);
194
+ $accounts[$apiUsername] = $apiUsername . ', websiteId: ' . $websiteId . ' name ' . $website->getName();
195
+ }
196
+ return implode('</br>', $accounts);
197
+ }
198
+
199
+ /**
200
+ * @param int $website
201
+ *
202
+ * @return array|mixed
203
+ * @throws Mage_Core_Exception
204
+ */
205
+ public function getCustomAttributes($website = 0)
206
+ {
207
+ $website = Mage::app()->getWebsite($website);
208
+ $attr = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_CUSTOM_DATAFIELDS);
209
+
210
+ if (!$attr)
211
+ return array();
212
+
213
+ return unserialize($attr);
214
+ }
215
+
216
+
217
+ /**
218
+ * Enterprise custom datafields attributes.
219
+ * @param int $website
220
+ *
221
+ * @return array
222
+ * @throws Mage_Core_Exception
223
+ */
224
+ public function getEnterpriseAttributes( $website = 0) {
225
+ $website = Mage::app()->getWebsite($website);
226
+ $result = array();
227
+ $attrs = $website->getConfig('connector_data_mapping/enterprise_data');
228
+ //get individual mapped keys
229
+ foreach ( $attrs as $key => $one ) {
230
+ $config = $website->getConfig('connector_data_mapping/enterprise_data/' . $key);
231
+ //check for the mapped field
232
+ if ($config)
233
+ $result[$key] = $config;
234
+ }
235
+
236
+ if (empty($result))
237
+ return false;
238
+ return $result;
239
+ }
240
+
241
+ /**
242
+ * @param $path
243
+ * @param null|string|bool|int|Mage_Core_Model_Website $websiteId
244
+ * @return mixed
245
+ */
246
+ public function getWebsiteConfig($path, $websiteId = 0)
247
+ {
248
+ $website = Mage::app()->getWebsite($websiteId);
249
+ return $website->getConfig($path);
250
+ }
251
+
252
+ /**
253
+ * Api client by website.
254
+ *
255
+ * @param mixed $website
256
+ *
257
+ * @return bool|Dotdigitalgroup_Email_Model_Apiconnector_Client
258
+ */
259
+ public function getWebsiteApiClient($website = 0)
260
+ {
261
+ if(!$this->isEnabled($website))
262
+ return false;
263
+
264
+ if (! $apiUsername = $this->getApiUsername($website) || ! $apiPassword = $this->getApiPassword($website))
265
+ return false;
266
+
267
+ $client = Mage::getModel('ddg_automation/apiconnector_client');
268
+ $client->setApiUsername($this->getApiUsername($website))
269
+ ->setApiPassword($this->getApiPassword($website));
270
+
271
+ return $client;
272
+ }
273
+
274
+ /**
275
+ * Retrieve authorisation code.
276
+ */
277
+ public function getCode()
278
+ {
279
+ $adminUser = Mage::getSingleton('admin/session')->getUser();
280
+ $code = $adminUser->getEmailCode();
281
+
282
+ return $code;
283
+ }
284
+
285
+ /**
286
+ * Autorisation url for OAUTH.
287
+ * @return string
288
+ */
289
+ public function getAuthoriseUrl()
290
+ {
291
+ $clientId = Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CLIENT_ID);
292
+
293
+ //callback uri if not set custom
294
+ $redirectUri = $this->getRedirectUri();
295
+ $redirectUri .= 'connector/email/callback';
296
+ $adminUser = Mage::getSingleton('admin/session')->getUser();
297
+ //query params
298
+ $params = array(
299
+ 'redirect_uri' => $redirectUri,
300
+ 'scope' => 'Account',
301
+ 'state' => $adminUser->getId(),
302
+ 'response_type' => 'code'
303
+ );
304
+
305
+ $authorizeBaseUrl = Mage::helper('ddg/config')->getAuthorizeLink();
306
+ $url = $authorizeBaseUrl . http_build_query($params) . '&client_id=' . $clientId;
307
+
308
+ return $url;
309
+ }
310
+
311
+ public function getRedirectUri()
312
+ {
313
+ $callback = Mage::helper('ddg/config')->getCallbackUrl();
314
+
315
+ return $callback;
316
+ }
317
+
318
+ /**
319
+ * order status config value
320
+ * @param int $website
321
+ * @return mixed order status
322
+ */
323
+ public function getConfigSelectedStatus($website = 0)
324
+ {
325
+ $status = $this->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_ORDER_STATUS, $website);
326
+ if($status)
327
+ return explode(',',$status);
328
+ else
329
+ return false;
330
+ }
331
+
332
+ public function getConfigSelectedCustomOrderAttributes($website = 0)
333
+ {
334
+ $customAttributes = $this->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOM_ORDER_ATTRIBUTES, $website);
335
+ if($customAttributes)
336
+ return explode(',',$customAttributes);
337
+ else
338
+ return false;
339
+ }
340
+
341
+ public function getConfigSelectedCustomQuoteAttributes($website = 0)
342
+ {
343
+ $customAttributes = $this->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOM_QUOTE_ATTRIBUTES, $website);
344
+ if($customAttributes)
345
+ return explode(',',$customAttributes);
346
+ else
347
+ return false;
348
+ }
349
+
350
+ /**
351
+ * check sweet tooth installed/active status
352
+ * @return boolean
353
+ */
354
+ public function isSweetToothEnabled()
355
+ {
356
+ return (bool)Mage::getConfig()->getModuleConfig('TBT_Rewards')->is('active', 'true');
357
+ }
358
+
359
+ /**
360
+ * check sweet tooth installed/active status and active status
361
+ * @param Mage_Core_Model_Website $website
362
+ * @return boolean
363
+ */
364
+ public function isSweetToothToGo($website)
365
+ {
366
+ $stMappingStatus = $this->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_SWEETTOOTH_ACTIVE, $website);
367
+ if($stMappingStatus && $this->isSweetToothEnabled()) return true;
368
+ return false;
369
+ }
370
+
371
+ public function setConnectorContactToReImport($customerId)
372
+ {
373
+ try {
374
+ $coreResource = Mage::getSingleton('core/resource');
375
+ $con = $coreResource->getConnection('core_write');
376
+ $con->update(
377
+ $coreResource->getTableName('ddg_automation/contact'),
378
+ array('email_imported' => new Zend_Db_Expr('null')),
379
+ array("customer_id = ?" => $customerId)
380
+ );
381
+ } catch (Exception $e) {
382
+ Mage::logException($e);
383
+ }
384
+ }
385
+
386
+ /**
387
+ * Diff between to times;
388
+ *
389
+ * @param $time1
390
+ * @param $time2
391
+ * @return int
392
+ */
393
+ public function dateDiff($time1, $time2=NULL) {
394
+ if (is_null($time2)) {
395
+ $time2 = Mage::getModel('core/date')->date();
396
+ }
397
+ $time1 = strtotime($time1);
398
+ $time2 = strtotime($time2);
399
+ return $time2 - $time1;
400
+ }
401
+
402
+
403
+ /**
404
+ * Disable website config when the request is made admin area only!
405
+ * @param $path
406
+ *
407
+ * @throws Mage_Core_Exception
408
+ */
409
+ public function disableConfigForWebsite($path)
410
+ {
411
+ $scopeId = 0;
412
+ if ($website = Mage::app()->getRequest()->getParam('website')) {
413
+ $scope = 'websites';
414
+ $scopeId = Mage::app()->getWebsite($website)->getId();
415
+ } else {
416
+ $scope = "default";
417
+ }
418
+ $config = Mage::getConfig();
419
+ $config->saveConfig($path, 0, $scope, $scopeId);
420
+ $config->cleanCache();
421
+ }
422
+
423
+ /**
424
+ * number of customers with duplicate emails, emails as total number
425
+ * @return Mage_Customer_Model_Resource_Customer_Collection
426
+ */
427
+ public function getCustomersWithDuplicateEmails( ) {
428
+ $customers = Mage::getModel('customer/customer')->getCollection();
429
+
430
+ //duplicate emails
431
+ $customers->getSelect()
432
+ ->columns(array('emails' => 'COUNT(e.entity_id)'))
433
+ ->group('email')
434
+ ->having('emails > ?', 1);
435
+
436
+ return $customers;
437
+ }
438
+
439
+ /**
440
+ * Create new raygun client.
441
+ *
442
+ * @return bool|\Raygun4php\RaygunClient
443
+ */
444
+ public function getRaygunClient()
445
+ {
446
+ $code = Mage::getstoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_RAYGUN_APPLICATION_CODE);
447
+
448
+ if ($this->raygunEnabled()) {
449
+ //use async mode for sending.
450
+ $async = Mage::getStoreConfigFlag(Dotdigitalgroup_Email_Helper_Config::XML_PATH_RAYGUN_APPLICATION_ASYNC);
451
+ require_once Mage::getBaseDir('lib') . DS . 'Raygun4php' . DS . 'RaygunClient.php';
452
+ return new Raygun4php\RaygunClient($code, $async);
453
+ }
454
+
455
+ return false;
456
+ }
457
+
458
+ /**
459
+ * Raygun logs.
460
+ * @param int $errno
461
+ * @param $message
462
+ * @param string $filename
463
+ * @param int $line
464
+ * @param array $tags
465
+ *
466
+ * @return int|null
467
+ */
468
+ public function rayLog($errno = 100, $message, $filename = 'helper/data.php', $line = 1, $tags = array())
469
+ {
470
+ if (!$this->raygunEnabled())
471
+ return;
472
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
473
+ if (empty($tags)) {
474
+ $tags = array(
475
+ $baseUrl,
476
+ Mage::getVersion()
477
+ );
478
+ }
479
+
480
+ $client = $this->getRaygunClient();
481
+ //user, firstname, lastname, email, annonim, uuid
482
+ $client->SetUser($baseUrl, null, null, $this->getApiUsername());
483
+ $client->SetVersion($this->getConnectorVersion());
484
+ $client->SendError($errno, $message, $filename,$line, $tags);
485
+ }
486
+
487
+
488
+ /**
489
+ * check for raygun application and if enabled.
490
+ * @param int $websiteId
491
+ *
492
+ * @return mixed
493
+ * @throws Mage_Core_Exception
494
+ */
495
+ public function raygunEnabled($websiteId = 0)
496
+ {
497
+ $website = Mage::app()->getWebsite($websiteId);
498
+
499
+ return (bool)$website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_RAYGUN_APPLICATION_CODE);
500
+
501
+ }
502
+
503
+ /**
504
+ * Generate the baseurl for the default store
505
+ * dynamic content will be displayed
506
+ * @return string
507
+ * @throws Mage_Core_Exception
508
+ */
509
+ public function generateDynamicUrl()
510
+ {
511
+ $website = Mage::app()->getRequest()->getParam('website', false);
512
+
513
+ //set website url for the default store id
514
+ $website = ($website)? Mage::app()->getWebsite( $website ) : 0;
515
+
516
+ $defaultGroup = Mage::app()->getWebsite($website)
517
+ ->getDefaultGroup();
518
+
519
+ if (! $defaultGroup)
520
+ return $mage = Mage::app()->getStore()->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
521
+
522
+ //base url
523
+ $baseUrl = Mage::app()->getStore($defaultGroup->getDefaultStore())->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
524
+
525
+ return $baseUrl;
526
+
527
+ }
528
+
529
+ /**
530
+ *
531
+ *
532
+ * @param int $store
533
+ * @return mixed
534
+ */
535
+ public function isNewsletterSuccessDisabled($store = 0)
536
+ {
537
+ return Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DISABLE_NEWSLETTER_SUCCESS, $store);
538
+ }
539
+
540
+ /**
541
+ * @return bool
542
+ */
543
+ public function getEasyEmailCapture()
544
+ {
545
+ return Mage::getStoreConfigFlag(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_EMAIL_CAPTURE);
546
+ }
547
+
548
+ /**
549
+ * @return bool
550
+ */
551
+ public function getEasyEmailCaptureForNewsletter()
552
+ {
553
+ return Mage::getStoreConfigFlag(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_EMAIL_CAPTURE_NEWSLETTER);
554
+ }
555
+ /**
556
+ * get feefo logon config value
557
+ *
558
+ * @return mixed
559
+ */
560
+ public function getFeefoLogon()
561
+ {
562
+ return $this->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_REVIEWS_FEEFO_LOGON);
563
+ }
564
+
565
+ /**
566
+ * get feefo reviews limit config value
567
+ *
568
+ * @return mixed
569
+ */
570
+ public function getFeefoReviewsPerProduct()
571
+ {
572
+ return $this->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_REVIEWS_FEEFO_REVIEWS);
573
+ }
574
+
575
+ /**
576
+ * get feefo logo template config value
577
+ *
578
+ * @return mixed
579
+ */
580
+ public function getFeefoLogoTemplate()
581
+ {
582
+ return $this->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_REVIEWS_FEEFO_TEMPLATE);
583
+ }
584
+
585
+ /**
586
+ * update data fields
587
+ *
588
+ * @param $email
589
+ * @param Mage_Core_Model_Website $website
590
+ * @param $storeName
591
+ */
592
+ public function updateDataFields($email, Mage_Core_Model_Website $website, $storeName)
593
+ {
594
+ $data = array();
595
+ if($store_name = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_STORE_NAME)){
596
+ $data[] = array(
597
+ 'Key' => $store_name,
598
+ 'Value' => $storeName
599
+ );
600
+ }
601
+ if($website_name = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_WEBSITE_NAME)){
602
+ $data[] = array(
603
+ 'Key' => $website_name,
604
+ 'Value' => $website->getName()
605
+ );
606
+ }
607
+ if(!empty($data)){
608
+ //update data fields
609
+ $client = $this->getWebsiteApiClient($website);
610
+ $client->updateContactDatafieldsByEmail($email, $data);
611
+ }
612
+ }
613
+
614
+ /**
615
+ * check connector SMTP installed/active status
616
+ * @return boolean
617
+ */
618
+ public function isSmtpEnabled()
619
+ {
620
+ return (bool)Mage::getConfig()->getModuleConfig('Ddg_Transactional')->is('active', 'true');
621
+ }
622
+
623
+ /**
624
+ * Is magento enterprise.
625
+ * @return bool
626
+ */
627
+ public function isEnterprise()
628
+ {
629
+ return Mage::getConfig ()->getModuleConfig ( 'Enterprise_Enterprise' ) && Mage::getConfig ()->getModuleConfig ( 'Enterprise_AdminGws' ) && Mage::getConfig ()->getModuleConfig ( 'Enterprise_Checkout' ) && Mage::getConfig ()->getModuleConfig ( 'Enterprise_Customer' );
630
+
631
+ }
632
+
633
+ public function getTemplateList()
634
+ {
635
+ $client = $this->getWebsiteApiClient(Mage::app()->getWebsite());
636
+ if(!$client)
637
+ return array();
638
+
639
+ $templates = $client->getApiTemplateList();
640
+ $fields[] = array('value' => '', 'label' => '');
641
+ foreach ( $templates as $one ) {
642
+ if ( isset( $one->id ) ) {
643
+ $fields[] = array(
644
+ 'value' => $one->id,
645
+ 'label' => $this->__( addslashes( $one->name ) )
646
+ );
647
+ }
648
+ }
649
+ return $fields;
650
+ }
651
+
652
+ /**
653
+ * Update last quote id datafield.
654
+ * @param $quoteId
655
+ * @param $email
656
+ * @param $websiteId
657
+ */
658
+ public function updateLastQuoteId($quoteId, $email, $websiteId)
659
+ {
660
+ $client = $this->getWebsiteApiClient($websiteId);
661
+ //last quote id config data mapped
662
+ $quoteIdField = $this->getLastQuoteId();
663
+
664
+ $data[] = array(
665
+ 'Key' => $quoteIdField,
666
+ 'Value' => $quoteId
667
+ );
668
+ //update datafields for conctact
669
+ $client->updateContactDatafieldsByEmail($email, $data);
670
+ }
671
+
672
+ /**
673
+ * Remove code and disable Raygun.
674
+ */
675
+ public function disableRaygun()
676
+ {
677
+ $config = new Mage_Core_Model_Config();
678
+ $config->saveConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_RAYGUN_APPLICATION_CODE, '');
679
+ Mage::getConfig()->cleanCache();
680
+ }
681
+
682
+ public function enableRaygunCode()
683
+ {
684
+ $curl = new Varien_Http_Adapter_Curl();
685
+ $curl->setConfig(array(
686
+ 'timeout' => 2
687
+ ));
688
+ $curl->write(Zend_Http_Client::GET, Dotdigitalgroup_Email_Helper_Config::RAYGUN_API_CODE_URL, '1.0');
689
+ $data = $curl->read();
690
+
691
+ if ($data === false) {
692
+ return false;
693
+ }
694
+ $data = preg_split('/^\r?$/m', $data, 2);
695
+ $data = trim($data[1]);
696
+ $curl->close();
697
+
698
+ $xml = new SimpleXMLElement($data);
699
+ $raygunCode = $xml->code;
700
+
701
+ //not found
702
+ if (!$raygunCode)
703
+ return;
704
+
705
+ $config = new Mage_Core_Model_Config();
706
+ $config->saveConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_RAYGUN_APPLICATION_CODE, $raygunCode);
707
+ }
708
+
709
+ /**
710
+ * Send the exception to raygun.
711
+ *
712
+ * @param $e Exception
713
+ */
714
+ public function sendRaygunException( $e )
715
+ {
716
+ if (!$this->raygunEnabled())
717
+ return;
718
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
719
+ $tags = array(
720
+ $baseUrl,
721
+ Mage::getVersion()
722
+ );
723
+
724
+ $client = $this->getRaygunClient();
725
+ //user, firstname, lastname, email, annonim, uuid
726
+ $client->SetUser($baseUrl, null, null, $this->getApiUsername());
727
+ $client->SetVersion($this->getConnectorVersion());
728
+ $client->SendException($e, $tags);
729
+ }
730
+
731
+ /**
732
+ * @param int $websiteId
733
+ *
734
+ * @return bool
735
+ */
736
+ public function getOrderSyncEnabled($websiteId = 0)
737
+ {
738
+ return Mage::getStoreConfigFlag(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_ORDER_ENABLED, $websiteId);
739
+ }
740
+ /**
741
+ * @param int $websiteId
742
+ *
743
+ * @return bool
744
+ */
745
+ public function getCatalogSyncEnabled($websiteId = 0)
746
+ {
747
+ return Mage::getStoreConfigFlag(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_CATALOG_ENABLED, $websiteId);
748
+ }
749
+
750
+ /**
751
+ * @param int $websiteId
752
+ *
753
+ * @return bool
754
+ */
755
+ public function getContactSyncEnabled($websiteId = 0)
756
+ {
757
+ return Mage::getStoreConfigFlag(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_CONTACT_ENABLED, $websiteId);
758
+ }
759
+
760
+ /**
761
+ * @param int $websiteId
762
+ *
763
+ * @return bool
764
+ */
765
+ public function getGuestSyncEnabled($websiteId = 0)
766
+ {
767
+ return Mage::getStoreConfigFlag(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_GUEST_ENABLED, $websiteId);
768
+ }
769
+
770
+ /**
771
+ * @param int $websiteId
772
+ *
773
+ * @return bool
774
+ */
775
+ public function getSubscriberSyncEnabled($websiteId = 0)
776
+ {
777
+ return Mage::getStoreConfigFlag(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_SUBSCRIBER_ENABLED, $websiteId);
778
+ }
779
+
780
+ /**
781
+ * @return bool
782
+ */
783
+ public function getCronInstalled()
784
+ {
785
+ $lastCustomerSync = Mage::getModel('ddg_automation/cron')->getLastCustomerSync();
786
+ $timespan = Mage::helper('ddg')->dateDiff($lastCustomerSync);
787
+
788
+ //last customer cron was less then 15 min
789
+ if ($timespan <= 15 * 60) {
790
+ return true;
791
+ }
792
+ return false;
793
+ }
794
+ /**
795
+ * Get the config id by the automation type.
796
+ * @param $automationType
797
+ * @param int $websiteId
798
+ *
799
+ * @return mixed
800
+ */
801
+ public function getAutomationIdByType($automationType, $websiteId = 0)
802
+ {
803
+ $path = constant('Dotdigitalgroup_Email_Helper_Config::' . $automationType);
804
+ $automationCampaignId = $this->getWebsiteConfig($path, $websiteId);
805
+
806
+ return $automationCampaignId;
807
+ }
808
+
809
+ public function getAbandonedProductName()
810
+ {
811
+ return Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_ABANDONED_PRODUCT_NAME);
812
+
813
+ }
814
+
815
+ /**
816
+ * Update last quote id datafield.
817
+ * @param $name
818
+ * @param $email
819
+ * @param $websiteId
820
+ */
821
+ public function updateAbandonedProductName($name, $email, $websiteId)
822
+ {
823
+ $client = $this->getWebsiteApiClient($websiteId);
824
+ // id config data mapped
825
+ $field = $this->getAbandonedProductName();
826
+
827
+ if ($field) {
828
+ $data[] = array(
829
+ 'Key' => $field,
830
+ 'Value' => $name
831
+ );
832
+ //update data field for contact
833
+ $client->updateContactDatafieldsByEmail($email, $data);
834
+ }
835
+ }
836
+
837
+
838
+ /**
839
+ * Api request response time limit that should be logged.
840
+ *
841
+ * @param int $websiteId
842
+ *
843
+ * @return mixed
844
+ * @throws Mage_Core_Exception
845
+ */
846
+ public function getApiResponseTimeLimit($websiteId = 0)
847
+ {
848
+ $website = Mage::app()->getWebsite($websiteId);
849
+ $limit = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DEBUG_API_REQUEST_LIMIT);
850
+
851
+ return $limit;
852
+ }
853
+
854
+ /**
855
+ * Main email for an account.
856
+ *
857
+ * @param int $website
858
+ *
859
+ * @return string
860
+ */
861
+ public function getAccountEmail( $website = 0)
862
+ {
863
+ $client = $this->getWebsiteApiClient($website);
864
+ $info = $client->getAccountInfo();
865
+ $email = '';
866
+
867
+ if(isset($info->properties)){
868
+ $properties = $info->properties;
869
+
870
+ foreach ( $properties as $property ) {
871
+
872
+ if ($property->name == 'MainEmail')
873
+ $email = $property->value;
874
+ }
875
+ }
876
+ return $email;
877
+ }
878
+
879
+ public function authIpAddress()
880
+ {
881
+ if ($ipString = Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_IP_RESTRICTION_ADDRESSES)) {
882
+ //string to array
883
+ $ipArray = explode(',', $ipString);
884
+ //remove white spaces
885
+ foreach($ipArray as $key => $ip){
886
+ $ipArray[$key] = preg_replace('/\s+/', '', $ip);
887
+ }
888
+ //ip address
889
+ $ipAddress = Mage::helper('core/http')->getRemoteAddr();
890
+
891
+ if(in_array($ipAddress, $ipArray)) {
892
+ return true;
893
+ }
894
+
895
+ $this->getRaygunClient()->Send('Ip address auth failed with ip address :' . $ipAddress);
896
+ return false;
897
+ }
898
+ return false;
899
+ }
900
+ }
app/code/{local → community}/Dotdigitalgroup/Email/Helper/File.php RENAMED
@@ -1,10 +1,10 @@
1
  <?php
2
- /*
3
- empty helper to keep admin from breaking
4
- */
5
  class Dotdigitalgroup_Email_Helper_File extends Dotdigitalgroup_Email_Helper_Data
6
  {
7
 
 
 
8
  /**
9
  * Location of files we are building
10
  */
@@ -15,8 +15,8 @@ class Dotdigitalgroup_Email_Helper_File extends Dotdigitalgroup_Email_Helper_Dat
15
  private $delimiter; // set in _construct
16
  private $enclosure; // set in _construct
17
 
18
- public function __construct() {
19
-
20
  $this->_output_folder = Mage::getBaseDir('var') . DS . 'export' . DS . 'email';
21
  $this->_output_archive_folder = $this->_output_folder . DS . 'archive';
22
 
@@ -25,34 +25,37 @@ class Dotdigitalgroup_Email_Helper_File extends Dotdigitalgroup_Email_Helper_Dat
25
  } // end
26
 
27
 
28
- public function getOutputFolder() {
 
29
  $this->pathExists($this->_output_folder);
30
  return $this->_output_folder;
31
  } // end
32
 
33
- public function getArchiveFolder() {
 
34
  $this->pathExists($this->_output_archive_folder);
35
  return $this->_output_archive_folder;
36
  } // end
37
 
38
  /* Return the full filepath */
39
- public function getFilePath($filename) {
 
40
  return $this->getOutputFolder() . DS . $filename;
41
  }
42
 
43
- public function archiveCSV($filename) {
44
-
45
  $this->moveFile($this->getOutputFolder(), $this->getArchiveFolder(), $filename);
46
  }
47
 
48
  /**
49
  * Moves the output file from one folder to the next
50
- *
51
- * @param string $source_folder
52
- * @param string $dest_folder
53
  */
54
- public function moveFile($source_folder, $dest_folder, $filename ){
55
-
56
  // generate the full file paths
57
  $source_filepath = $source_folder . DS . $filename;
58
  $dest_filepath = $dest_folder . DS . $filename;
@@ -68,15 +71,15 @@ class Dotdigitalgroup_Email_Helper_File extends Dotdigitalgroup_Email_Helper_Dat
68
  * @param $filepath
69
  * @param $csv
70
  */
71
- public function outputForceQuotesCSV($filepath, $csv) {
72
-
73
  $fqCsv = $this->arrayToCsv($csv,chr(9),'"',true,false);
74
  // Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it.
75
  $fp = fopen($filepath, "a");
76
 
77
  // for some reason passing the preset delimiter/enclosure variables results in error
78
- if (fwrite($fp, $fqCsv) == 0 ) //$this->delimiter $this->enclosure
79
- {
80
  Mage::throwException('Problem writing CSV file');
81
  }
82
  fclose($fp);
@@ -89,14 +92,14 @@ class Dotdigitalgroup_Email_Helper_File extends Dotdigitalgroup_Email_Helper_Dat
89
  * @param $filepath
90
  * @param $csv
91
  */
92
- public function outputCSV($filepath, $csv) {
93
-
94
  // Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it.
95
  $handle = fopen($filepath, "a");
96
 
97
  // for some reason passing the preset delimiter/enclosure variables results in error
98
- if (fputcsv($handle, $csv, ',', '"') == 0 ) //$this->delimiter $this->enclosure
99
- {
100
  Mage::throwException('Problem writing CSV file');
101
  }
102
 
@@ -109,9 +112,10 @@ class Dotdigitalgroup_Email_Helper_File extends Dotdigitalgroup_Email_Helper_Dat
109
  * If the path does not exist then create it
110
  * @param string $path
111
  */
112
- public function pathExists($path) {
113
- if (!is_dir( $path ) ) {
114
- mkdir($path, 0777, true);
 
115
  } // end
116
 
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
 
112
  * If the path does not exist then create it
113
  * @param string $path
114
  */
115
+ public function pathExists($path)
116
+ {
117
+ if (!is_dir($path)) {
118
+ mkdir($path, 0660, 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_automation_studio/review_settings/status';
9
+ const XML_PATH_REVIEW_DELAY = 'connector_automation_studio/review_settings/delay';
10
+ const XML_PATH_REVIEW_NEW_PRODUCT = 'connector_automation_studio/review_settings/new_product';
11
+ const XML_PATH_REVIEW_CAMPAIGN = 'connector_automation_studio/review_settings/campaign';
12
+ const XML_PATH_REVIEW_ANCHOR = 'connector_automation_studio/review_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,457 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ /**
170
+ * check and debug api request total time
171
+ */
172
+ if (Mage::helper('ddg')->getDebugEnabled()){
173
+ $info = $this->getResponseInfo();
174
+ //the response info data is set
175
+ if (isset($info['url']) && isset($info['total_time'])){
176
+ $url = $info['url'];
177
+ $time = $info['total_time'];
178
+ $totalTime = sprintf(' time : %g sec', $time);
179
+ $check = Mage::helper('ddg')->getApiResponseTimeLimit();
180
+ $limit = ($check)? $check : '2';
181
+ $message = $this->verb . ', ' . $url. $totalTime;
182
+ //check for slow queries
183
+ if ( $time > $limit) {
184
+ //log the slow queries
185
+ Mage::helper('ddg')->rayLog('100', $message);
186
+ Mage::helper( 'ddg' )->log( $message );
187
+ }
188
+ }
189
+ }
190
+
191
+ return $this->responseBody;
192
+ }
193
+
194
+ /**
195
+ * Post data.
196
+ *
197
+ * @param null $data
198
+ *
199
+ * @return $this
200
+ */
201
+ public function buildPostBody($data = null)
202
+ {
203
+ $this->requestBody = json_encode($data);
204
+ return $this;
205
+ }
206
+
207
+ /**
208
+ * Execute curl get request.
209
+ *
210
+ * @param $ch
211
+ */
212
+ protected function executeGet($ch)
213
+ {
214
+ $this->doExecute($ch);
215
+ }
216
+
217
+ /**
218
+ * Execute post request.
219
+ *
220
+ * @param $ch
221
+ */
222
+ protected function executePost($ch)
223
+ {
224
+ if (!is_string($this->requestBody)) {
225
+ $this->buildPostBody();
226
+ }
227
+
228
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $this->requestBody);
229
+ curl_setopt($ch, CURLOPT_POST, true);
230
+
231
+ $this->doExecute($ch);
232
+ }
233
+
234
+ /**
235
+ * Post from the file.
236
+ *
237
+ * @param $filename
238
+ */
239
+ protected function buildPostBodyFromFile($filename)
240
+ {
241
+ $this->requestBody = array (
242
+ 'file' => '@'.$filename
243
+ );
244
+ }
245
+
246
+ /**
247
+ * Execute put.
248
+ *
249
+ * @param $ch
250
+ */
251
+ protected function executePut($ch)
252
+ {
253
+ if (!is_string($this->requestBody)) {
254
+ $this->buildPostBody();
255
+ }
256
+
257
+ $this->requestLength = strlen($this->requestBody);
258
+
259
+ $fh = fopen('php://memory', 'rw');
260
+ fwrite($fh, $this->requestBody);
261
+ rewind($fh);
262
+
263
+ curl_setopt($ch, CURLOPT_INFILE, $fh);
264
+ curl_setopt($ch, CURLOPT_INFILESIZE, $this->requestLength);
265
+ curl_setopt($ch, CURLOPT_PUT, true);
266
+
267
+ $this->doExecute($ch);
268
+
269
+ fclose($fh);
270
+ }
271
+
272
+ /**
273
+ * Ececute delete.
274
+ *
275
+ * @param $ch
276
+ */
277
+ protected function executeDelete($ch)
278
+ {
279
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
280
+
281
+ $this->doExecute($ch);
282
+ }
283
+
284
+ /**
285
+ * Execute request.
286
+ *
287
+ * @param $ch
288
+ */
289
+ protected function doExecute(&$ch)
290
+ {
291
+ $this->setCurlOpts($ch);
292
+ $this->responseBody = json_decode(curl_exec($ch));
293
+ $this->responseInfo = curl_getinfo($ch);
294
+
295
+ curl_close($ch);
296
+ }
297
+
298
+ /**
299
+ * curl options.
300
+ *
301
+ * @param $ch
302
+ */
303
+ protected function setCurlOpts(&$ch)
304
+ {
305
+ curl_setopt($ch, CURLOPT_TIMEOUT, 10);
306
+ curl_setopt($ch, CURLOPT_URL, $this->url);
307
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
308
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
309
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
310
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array ('Accept: ' . $this->acceptType ,'Content-Type: application/json'));
311
+ }
312
+
313
+ /**
314
+ * basic auth.
315
+ *
316
+ * @param $ch
317
+ */
318
+ protected function setAuth(&$ch)
319
+ {
320
+ if ($this->_apiUsername !== null && $this->_apiPassword !== null)
321
+ {
322
+ curl_setopt($ch, CURLAUTH_BASIC, CURLAUTH_DIGEST);
323
+ curl_setopt($ch, CURLOPT_USERPWD, $this->_apiUsername . ':' . $this->_apiPassword);
324
+ }
325
+ }
326
+
327
+ /**
328
+ * Get accept type.
329
+ *
330
+ * @return string
331
+ */
332
+ public function getAcceptType()
333
+ {
334
+ return $this->acceptType;
335
+ }
336
+
337
+ /**
338
+ * set accept type.
339
+ *
340
+ * @param $acceptType
341
+ */
342
+ public function setAcceptType($acceptType)
343
+ {
344
+ $this->acceptType = $acceptType;
345
+ }
346
+
347
+
348
+ /**
349
+ * get api username.
350
+ *
351
+ * @return string
352
+ */
353
+ public function getApiUsername()
354
+ {
355
+ return $this->_apiUsername;
356
+ }
357
+
358
+ /**
359
+ * set api username.
360
+ *
361
+ * @param $apiUsername
362
+ *
363
+ * @return $this
364
+ */
365
+ public function setApiUsername($apiUsername)
366
+ {
367
+ $this->_apiUsername = $apiUsername;
368
+ return $this;
369
+ }
370
+ /**
371
+ * Get api password.
372
+ *
373
+ * @return string
374
+ */
375
+ public function getApiPassword()
376
+ {
377
+ return $this->_apiPassword;
378
+ }
379
+
380
+ /**
381
+ * set api password.
382
+ * @param $apiPassword
383
+ *
384
+ * @return $this
385
+ */
386
+ public function setApiPassword($apiPassword)
387
+ {
388
+ $this->_apiPassword = $apiPassword;
389
+ return $this;
390
+ }
391
+
392
+ /**
393
+ * get response body.
394
+ *
395
+ * @return string/object
396
+ */
397
+ public function getResponseBody()
398
+ {
399
+ return $this->responseBody;
400
+ }
401
+
402
+ /**
403
+ * get response info.
404
+ *
405
+ * @return null
406
+ */
407
+ public function getResponseInfo()
408
+ {
409
+ return $this->responseInfo;
410
+ }
411
+
412
+ /**
413
+ * get url.
414
+ *
415
+ * @return string
416
+ */
417
+ public function getUrl()
418
+ {
419
+ return $this->url;
420
+ }
421
+
422
+ /**
423
+ * set url.
424
+ *
425
+ * @param $url
426
+ *
427
+ * @return $this
428
+ */
429
+ public function setUrl($url)
430
+ {
431
+ $this->url = $url;
432
+ return $this;
433
+ }
434
+
435
+ /**
436
+ * get the verb.
437
+ *
438
+ * @return string
439
+ */
440
+ public function getVerb ()
441
+ {
442
+ return $this->verb;
443
+ }
444
+
445
+ /**
446
+ * set the verb.
447
+ *
448
+ * @param $verb
449
+ *
450
+ * @return $this
451
+ */
452
+ public function setVerb ($verb)
453
+ {
454
+ $this->verb = $verb;
455
+ return $this;
456
+ }
457
+ }
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()->setPageSize(1)->setCurPage(1)->getFirstItem();
47
+ }
48
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Orders.php ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 = Mage::getResourceModel('ddg_automation/contact')->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
+ * @param int $store
71
+ * @param int $website
72
+ * @param int $group
73
+ * @return Varien_Object
74
+ * @throws Mage_Core_Exception
75
+ */
76
+ public function getLifetimeSales($store = 0, $website = 0, $group =0)
77
+ {
78
+ $isFilter = $store || $website || $group;
79
+ $collection = $this->calculateSales($isFilter);
80
+
81
+ if ($store) {
82
+ $collection->addFieldToFilter('store_id', $store);
83
+ } else if ($website){
84
+ $storeIds = Mage::app()->getWebsite($website)->getStoreIds();
85
+ $collection->addFieldToFilter('store_id', array('in' => $storeIds));
86
+ } else if ($group){
87
+ $storeIds = Mage::app()->getGroup($group)->getStoreIds();
88
+ $collection->addFieldToFilter('store_id', array('in' => $storeIds));
89
+ }
90
+
91
+ return $collection->setPageSize(1)->setCurPage(1)->getFirstItem();
92
+ }
93
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Rfm.php ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ protected $_resultCount;
11
+
12
+ const RECENCY = 'Recency';
13
+ const FREQUENCY = 'Frequency';
14
+ const MONETARY = 'Monetary';
15
+
16
+ /**
17
+ * prepare collection and needed columns
18
+ *
19
+ * @return Mage_Sales_Model_Resource_Order_Collection
20
+ * @throws Mage_Core_Exception
21
+ */
22
+ protected function getPreparedCollection()
23
+ {
24
+ $statuses = Mage::getSingleton('sales/config')
25
+ ->getOrderStatusesForState(Mage_Sales_Model_Order::STATE_CANCELED);
26
+ if (empty($statuses)) {
27
+ $statuses = array(0);
28
+ }
29
+
30
+ $collection = Mage::getResourceModel('sales/order_collection');
31
+ $collection
32
+ ->addFieldToFilter('status', array('nin' => $statuses))
33
+ ->addFieldToFilter('state',
34
+ array('nin' => array(
35
+ Mage_Sales_Model_Order::STATE_NEW,
36
+ Mage_Sales_Model_Order::STATE_PENDING_PAYMENT)
37
+ )
38
+ )
39
+ ->addFieldToFilter('customer_id', array('neq' => 'null'))
40
+ ->addOrder('created_at');
41
+
42
+ if ($this->_store) {
43
+ $collection->addFieldToFilter('store_id', $this->_store);
44
+ } else if ($this->_website){
45
+ $storeIds = Mage::app()->getWebsite($this->_website)->getStoreIds();
46
+ $collection->addFieldToFilter('store_id', array('in' => $storeIds));
47
+ } else if ($this->_group){
48
+ $storeIds = Mage::app()->getGroup($this->_group)->getStoreIds();
49
+ $collection->addFieldToFilter('store_id', array('in' => $storeIds));
50
+ }
51
+
52
+ $expr = Mage::getResourceModel('ddg_automation/contact')->getSalesAmountExpression($collection);
53
+ $isFilter = $this->_store || $this->_website || $this->_group;
54
+ if ($isFilter == 0) {
55
+ $expr = '(' . $expr . ') * main_table.base_to_global_rate';
56
+ }
57
+
58
+ $collection->getSelect()
59
+ ->reset(Zend_Db_Select::COLUMNS)
60
+ ->columns(array(
61
+ 'customer_total_orders' => "count(*)",
62
+ 'customer_average_order_value' => "SUM({$expr})/count(*)",
63
+ 'last_order_days_ago' => "DATEDIFF(date(NOW()) , date(MAX(created_at)))"
64
+ ))
65
+ ->group('customer_id');
66
+
67
+ return $collection;
68
+ }
69
+
70
+ /**
71
+ * calculate quartiles
72
+ *
73
+ * @param $array
74
+ * @return array
75
+ */
76
+ protected function calculateQuartile($array)
77
+ {
78
+ $count = $this->_resultCount;
79
+ if ($count == 0)
80
+ return array(
81
+ "Low" => 0,
82
+ "Medium" => 0,
83
+ "High" => 0
84
+ );
85
+
86
+ $first = intval(round(.25 * ($count + 1)));
87
+ $second = intval(round(.50 * ($count + 1)));
88
+ $third = intval(round(.75 * ($count + 1)));
89
+
90
+ if (!array_key_exists($first, $array))
91
+ $first = $this->getClosest($first, $array);
92
+
93
+ if (!array_key_exists($second, $array))
94
+ $second = $this->getClosest($second, $array);
95
+
96
+ if (!array_key_exists($third, $array))
97
+ $third = $this->getClosest($third, $array);
98
+
99
+ return array(
100
+ "Low" => $array[$first],
101
+ "Medium" => $array[$second],
102
+ "High" => $array[$third]
103
+ );
104
+ }
105
+
106
+ /**
107
+ * find closest index key from array
108
+ *
109
+ * @param $search
110
+ * @param $arr
111
+ * @return mix
112
+ */
113
+ protected function getClosest($search, $arr) {
114
+ $closest = null;
115
+ foreach($arr as $key => $value) {
116
+ if($search == $key)
117
+ return $search;
118
+ if($closest == null || abs($search - $closest) > abs($key - $search)) {
119
+ $closest = $key;
120
+ }
121
+ }
122
+ return $closest;
123
+ }
124
+
125
+ /**
126
+ * prepare rfm data
127
+ */
128
+ protected function prepareRfm()
129
+ {
130
+ $collection = $this->getPreparedCollection();
131
+ $contactResource = Mage::getResourceModel('ddg_automation/contact');
132
+
133
+ $values = $contactResource->prepareFrequency($collection);
134
+ $this->_resultCount = count($values);
135
+ $this->rfm[self::FREQUENCY] = $this->calculateQuartile($values);
136
+
137
+
138
+ $values = $contactResource->prepareRecency($collection);
139
+ $this->rfm[self::RECENCY] = $this->calculateQuartile($values);
140
+
141
+ $values = $contactResource->prepareMonetary($collection);
142
+ $this->rfm[self::MONETARY] = $this->calculateQuartile($values);
143
+ }
144
+
145
+ /**
146
+ * @param int $store
147
+ * @param int $website
148
+ * @param int $group
149
+ * @return array
150
+ */
151
+ public function getPreparedRfm($store = 0, $website = 0, $group =0)
152
+ {
153
+ $this->_store = $store;
154
+ $this->_group = $group;
155
+ $this->_website = $website;
156
+
157
+ $this->prepareRfm();
158
+ return $this->rfm;
159
+ }
160
+ }
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->setPageSize(1)->setCurPage(1)->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->getSize();
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,229 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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->getResource()->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
+ $websiteId = Mage::app()->getStore()->getWebsiteId();
180
+
181
+ if (!empty($segmentsIds) && $customerId) {
182
+ $this->addContactsFromWebsiteSegments($customerId, $segmentsIds, $websiteId);
183
+ }
184
+
185
+ return $this;
186
+ }
187
+
188
+
189
+ /**
190
+ * Add segment ids.
191
+ * @param $customerId
192
+ * @param $segmentIds
193
+ * @param $websiteId
194
+ *
195
+ * @return $this
196
+ */
197
+ protected function addContactsFromWebsiteSegments($customerId, $segmentIds, $websiteId){
198
+
199
+ if (empty($segmentIds) || ! $customerId)
200
+ return;
201
+ $segmentIds = implode(',', $segmentIds);
202
+
203
+ $contact = Mage::getModel('ddg_automation/contact')->getCollection()
204
+ ->addFieldToFilter('customer_id', $customerId)
205
+ ->addFieldToFilter('website_id', $websiteId)
206
+ ->getFirstItem();
207
+ try {
208
+
209
+ $contact->setSegmentIds($segmentIds)
210
+ ->setEmailImported()
211
+ ->save();
212
+
213
+ }catch (Exception $e){
214
+ Mage::logException($e);
215
+ }
216
+
217
+ return $this;
218
+ }
219
+
220
+ protected function getCustomerSegmentIdsForWebsite($customerId, $websiteId){
221
+ $segmentIds = Mage::getModel('ddg_automation/contact')->getCollection()
222
+ ->addFieldToFilter('website_id', $websiteId)
223
+ ->addFieldToFilter('customer_id', $customerId)
224
+ ->getFirstItem()
225
+ ->getSegmentIds();
226
+
227
+ return $segmentIds;
228
+ }
229
+ }
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::getResourceModel('ddg_automation/order')->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::getResourceModel('ddg_automation/quote')->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,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
11
+ $website = Mage::app()->getRequest()->getParam('website', false);
12
+ if ($website)
13
+ $website = Mage::app()->getWebsite($website);
14
+ else
15
+ $website = 0;
16
+
17
+ $fields[] = array('value' => '0', 'label' => Mage::helper('ddg')->__('-- Disabled --'));
18
+ if ($websiteName) {
19
+ $website = Mage::app()->getWebsite($websiteName);
20
+ }
21
+
22
+ if (Mage::helper('ddg')->isEnabled($website)) {
23
+
24
+ $client = Mage::helper( 'ddg' )->getWebsiteApiClient( $website );
25
+ $programmes = $client->getPrograms();
26
+
27
+ foreach ( $programmes as $one ) {
28
+ if ( isset( $one->id ) ) {
29
+ if($one->status == 'Active'){
30
+ $fields[] = array( 'value' => $one->id, 'label' => Mage::helper( 'ddg' )->__( $one->name ) );
31
+ }
32
+ }
33
+ }
34
+ }
35
+
36
+ return $fields;
37
+ }
38
+
39
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Campaigns.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ $website = Mage::app()->getRequest()->getParam('website', false);
18
+ if ($website)
19
+ $website = Mage::app()->getWebsite($website);
20
+ else
21
+ $website = 0;
22
+ $fields[] = array('value' => '0', 'label' => Mage::helper('ddg')->__('-- Please Select --'));
23
+
24
+ if ($websiteName) {
25
+ $website = Mage::app()->getWebsite($websiteName);
26
+ }
27
+
28
+ $enabled = Mage::helper('ddg')->isEnabled($website);
29
+
30
+ //api enabled get campaigns
31
+ if ($enabled) {
32
+ $client = Mage::helper( 'ddg' )->getWebsiteApiClient( $website );
33
+
34
+ $savedCampaigns = Mage::registry( 'savedcampigns' );
35
+
36
+ //get campaigns from registry
37
+ if ( $savedCampaigns ) {
38
+ $campaigns = $savedCampaigns;
39
+ } else {
40
+ $campaigns = $client->getCampaigns();
41
+ Mage::unregister( 'savedcampigns' );
42
+ Mage::register( 'savedcampigns', $campaigns );
43
+ }
44
+
45
+ foreach ( $campaigns as $one ) {
46
+ if ( isset( $one->id ) ) {
47
+ $fields[] = array(
48
+ 'value' => $one->id,
49
+ 'label' => Mage::helper('ddg')->__(addslashes($one->name))
50
+ );
51
+ }
52
+ }
53
+ }
54
+
55
+ return $fields;
56
+ }
57
+
58
+ }
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/Contact/Modified.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Contact_Modified
4
+ {
5
+ /**
6
+ * Contact imported options.
7
+ *
8
+ * @return array
9
+ */
10
+ public function getOptions()
11
+ {
12
+ return array(
13
+ '1' => Mage::helper('ddg')->__('Modified'),
14
+ 'null' => Mage::helper('ddg')->__('Not Modified'),
15
+ );
16
+ }
17
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Customer/Attributes/Select.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ //escape the label in case of quotes
25
+ $label = addslashes($attribute->getFrontendLabel());
26
+ if(!in_array($code, $excluded))
27
+ $options[] = array(
28
+ 'value' => $attribute->getAttributeCode(),
29
+ 'label' => $label
30
+ );
31
+ }
32
+ }
33
+
34
+ return $options;
35
+ }
36
+ }
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
+ } elseif(is_array($datafields)) {
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/Importer/Mode.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Importer_Mode
4
+ {
5
+ /**
6
+ * Contact imported options.
7
+ *
8
+ * @return array
9
+ */
10
+ public function getOptions()
11
+ {
12
+ return array(
13
+ Dotdigitalgroup_Email_Model_Importer::MODE_BULK => Mage::helper('ddg')->__(Dotdigitalgroup_Email_Model_Importer::MODE_BULK),
14
+ Dotdigitalgroup_Email_Model_Importer::MODE_SINGLE => Mage::helper('ddg')->__(Dotdigitalgroup_Email_Model_Importer::MODE_SINGLE),
15
+ Dotdigitalgroup_Email_Model_Importer::MODE_SINGLE_DELETE => Mage::helper('ddg')->__(Dotdigitalgroup_Email_Model_Importer::MODE_SINGLE_DELETE),
16
+ Dotdigitalgroup_Email_Model_Importer::MODE_CONTACT_DELETE => Mage::helper('ddg')->__(Dotdigitalgroup_Email_Model_Importer::MODE_CONTACT_DELETE)
17
+ );
18
+ }
19
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Importer/Status.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Importer_Status
4
+ {
5
+ /**
6
+ * Contact imported options.
7
+ *
8
+ * @return array
9
+ */
10
+ public function getOptions()
11
+ {
12
+ return array(
13
+ Dotdigitalgroup_Email_Model_Importer::NOT_IMPORTED => Mage::helper('ddg')->__('Not Imported'),
14
+ Dotdigitalgroup_Email_Model_Importer::IMPORTING => Mage::helper('ddg')->__('Importing'),
15
+ Dotdigitalgroup_Email_Model_Importer::IMPORTED => Mage::helper('ddg')->__('Imported'),
16
+ Dotdigitalgroup_Email_Model_Importer::FAILED => Mage::helper('ddg')->__('Failed'),
17
+ );
18
+ }
19
+ }
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/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/Rules/Condition.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Rules_Condition
4
+ {
5
+ /**
6
+ * options array
7
+ *
8
+ * @return array
9
+ */
10
+ public function toOptionArray()
11
+ {
12
+ $options = array(
13
+ array('value' => 'eq', 'label' => Mage::helper('ddg')->__('is')),
14
+ array('value' => 'neq', 'label' => Mage::helper('ddg')->__('is not')),
15
+ array('value' => 'null', 'label' => Mage::helper('ddg')->__('is empty')),
16
+ );
17
+ return $options;
18
+ }
19
+
20
+ /**
21
+ * get condition options according to type
22
+ *
23
+ * @param $type
24
+ * @return array
25
+ */
26
+ public function getInputTypeOptions($type)
27
+ {
28
+ switch ($type) {
29
+ case 'numeric':
30
+ return $this->optionsForNumericType();
31
+
32
+ case 'select':
33
+ return $this->toOptionArray();
34
+
35
+ case 'string':
36
+ return $this->optionsForStringType();
37
+ }
38
+ }
39
+
40
+ /**
41
+ * condition options for numeric type
42
+ *
43
+ * @return array
44
+ */
45
+ public function optionsForNumericType()
46
+ {
47
+ $options = $this->toOptionArray();
48
+ $options[] = array('value' => 'gteq', 'label' => Mage::helper('ddg')->__('equals or greater than'));
49
+ $options[] = array('value' => 'lteq', 'label' => Mage::helper('ddg')->__('equals or less then'));
50
+ $options[] = array('value' => 'gt', 'label' => Mage::helper('ddg')->__('greater than'));
51
+ $options[] = array('value' => 'lt', 'label' => Mage::helper('ddg')->__('less than'));
52
+ return $options;
53
+ }
54
+
55
+ /**
56
+ * condition options for string type
57
+ *
58
+ * @return array
59
+ */
60
+ public function optionsForStringType()
61
+ {
62
+ $options = $this->toOptionArray();
63
+ $options[] = array('value' => 'like', 'label' => Mage::helper('ddg')->__('contains'));
64
+ $options[] = array('value' => 'nlike', 'label' => Mage::helper('ddg')->__('does not contains'));
65
+ return $options;
66
+ }
67
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Rules/Type.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Rules_Type
4
+ {
5
+
6
+ /**
7
+ * get input type
8
+ *
9
+ * @param $attribute
10
+ * @return string
11
+ */
12
+ public function getInputType($attribute)
13
+ {
14
+ switch ($attribute) {
15
+ case 'subtotal': case 'grand_total': case 'items_qty':
16
+ return 'numeric';
17
+
18
+ case 'method': case 'shipping_method': case 'country_id': case 'region_id': case 'customer_group_id':
19
+ return 'select';
20
+
21
+ default:
22
+ $attribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', $attribute);
23
+ if($attribute->getFrontend()->getInputType() == 'price')
24
+ return 'numeric';
25
+ if ($attribute->usesSource())
26
+ return 'select';
27
+ }
28
+ return 'string';
29
+ }
30
+
31
+ /**
32
+ * default options
33
+ *
34
+ * @return array
35
+ */
36
+ public function defaultOptions()
37
+ {
38
+ return array(
39
+ 'method' => Mage::helper('adminhtml')->__('Payment Method'),
40
+ 'shipping_method' => Mage::helper('adminhtml')->__('Shipping Method'),
41
+ 'country_id' => Mage::helper('adminhtml')->__('Shipping Country'),
42
+ 'city' => Mage::helper('adminhtml')->__('Shipping Town'),
43
+ 'region_id' =>Mage::helper('adminhtml')->__( 'Shipping State/Province'),
44
+ 'customer_group_id' =>Mage::helper('adminhtml')->__( 'Customer Group'),
45
+ 'coupon_code' =>Mage::helper('adminhtml')->__( 'Coupon'),
46
+ 'subtotal' =>Mage::helper('adminhtml')->__( 'Subtotal'),
47
+ 'grand_total' =>Mage::helper('adminhtml')->__( 'Grand Total'),
48
+ 'items_qty' =>Mage::helper('adminhtml')->__( 'Total Qty'),
49
+ 'customer_email' => Mage::helper('adminhtml')->__('Email'),
50
+ );
51
+ }
52
+
53
+ /**
54
+ * attribute options array
55
+ *
56
+ * @return array
57
+ */
58
+ public function toOptionArray()
59
+ {
60
+ $defaultOptions = $this->defaultOptions();
61
+ $productCondition = Mage::getModel('salesrule/rule_condition_product');
62
+ $productAttributes = $productCondition->loadAttributeOptions()->getAttributeOption();
63
+ $pAttributes = array();
64
+ foreach ($productAttributes as $code=>$label) {
65
+ if (strpos($code, 'quote_item_') === false) {
66
+ $pAttributes[$code] = Mage::helper('adminhtml')->__($label);
67
+ }
68
+ }
69
+ $options = array_merge($defaultOptions, $pAttributes);
70
+ return $options;
71
+ }
72
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Rules/Value.php ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Rules_Value
4
+ {
5
+ /**
6
+ * get element type
7
+ *
8
+ * @param $attribute
9
+ * @return string
10
+ */
11
+ public function getValueElementType($attribute)
12
+ {
13
+ switch ($attribute) {
14
+ case 'method': case 'shipping_method': case 'country_id': case 'region_id': case 'customer_group_id':
15
+ return 'select';
16
+ default:
17
+ $attribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', $attribute);
18
+ if ($attribute->usesSource()) {
19
+ return 'select';
20
+ }
21
+ }
22
+ return 'text';
23
+ }
24
+
25
+ /**
26
+ * get options array
27
+ *
28
+ * @param $attribute
29
+ * @param bool $is_empty
30
+ * @return array
31
+ * @throws Mage_Core_Exception
32
+ */
33
+ public function getValueSelectOptions($attribute, $is_empty = false)
34
+ {
35
+ $options = array();
36
+ if($is_empty){
37
+ $options = Mage::getModel('adminhtml/system_config_source_yesno')
38
+ ->toOptionArray();
39
+ return $options;
40
+ }
41
+
42
+ switch ($attribute) {
43
+ case 'country_id':
44
+ $options = Mage::getModel('adminhtml/system_config_source_country')
45
+ ->toOptionArray();
46
+ break;
47
+
48
+ case 'region_id':
49
+ $options = Mage::getModel('adminhtml/system_config_source_allregion')
50
+ ->toOptionArray();
51
+ break;
52
+
53
+ case 'shipping_method':
54
+ $options = Mage::getModel('adminhtml/system_config_source_shipping_allmethods')
55
+ ->toOptionArray();
56
+ break;
57
+
58
+ case 'method':
59
+ $options = Mage::getModel('adminhtml/system_config_source_payment_allmethods')
60
+ ->toOptionArray();
61
+ break;
62
+
63
+ case 'customer_group_id':
64
+ $options = Mage::getModel('adminhtml/system_config_source_customer_group')
65
+ ->toOptionArray();
66
+ break;
67
+
68
+ default:
69
+ $attribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', $attribute);
70
+ if ($attribute->usesSource()) {
71
+ $options = $attribute->getSource()->getAllOptions(false);
72
+ }
73
+ }
74
+ return $options;
75
+ }
76
+
77
+ /**
78
+ * options array
79
+ *
80
+ * @return array
81
+ */
82
+ public function toOptionArray()
83
+ {
84
+ $options = Mage::getModel('adminhtml/system_config_source_payment_allmethods')
85
+ ->toOptionArray();
86
+
87
+ return $options;
88
+ }
89
+ }
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/Sync/Catalog/Attributes.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Sync_Catalog_Attributes
4
+ {
5
+ /**
6
+ * all attributes type catalog
7
+ *
8
+ * @return array
9
+ */
10
+ public function toOptionArray()
11
+ {
12
+ $attributes = Mage::getResourceModel('catalog/product_attribute_collection')->addVisibleFilter();
13
+ $attributeArray = array();
14
+
15
+ //exclude these from showing in the options
16
+ $exclude = array('gallery', 'image', 'media_gallery', 'small_image', 'thumbnail');
17
+
18
+ foreach ($attributes as $attribute) {
19
+ if (!in_array($attribute->getData('attribute_code'), $exclude)) {
20
+ $attributeArray[] = array(
21
+ 'label' => $attribute->getData('frontend_label'),
22
+ 'value' => $attribute->getData('attribute_code')
23
+ );
24
+ }
25
+ }
26
+ return $attributeArray;
27
+ }
28
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Sync/Catalog/Type.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Sync_Catalog_Type
4
+ {
5
+ /**
6
+ * Options getter. Styling options
7
+ *
8
+ * @return array
9
+ */
10
+ public function toOptionArray()
11
+ {
12
+ $options = Mage::getModel('catalog/product_type')->getAllOptions();
13
+ array_shift($options);
14
+ return $options;
15
+ }
16
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Sync/Catalog/Values.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Sync_Catalog_Values
4
+ {
5
+ /**
6
+ * Options getter. Styling options
7
+ *
8
+ * @return array
9
+ */
10
+ public function toOptionArray()
11
+ {
12
+ return array(
13
+ array(
14
+ 'value' => '1',
15
+ 'label' => 'Default Level'
16
+ ),
17
+ array(
18
+ 'value' => '2',
19
+ 'label' => 'Store Level'
20
+ )
21
+ );
22
+ }
23
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Sync/Catalog/Visibility.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Sync_Catalog_Visibility
4
+ {
5
+ /**
6
+ * Options getter. Styling options
7
+ *
8
+ * @return array
9
+ */
10
+ public function toOptionArray()
11
+ {
12
+ $options = Mage::getModel('catalog/product_visibility')->getAllOptions();
13
+ array_shift($options);
14
+ return $options;
15
+ }
16
+ }
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,1243 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ protected $_limit = 10;
45
+ public $fileHelper;
46
+ protected $_filename;
47
+ protected $_api_helper;
48
+ protected $_address_book_id;
49
+ protected $_customers_filename;
50
+ protected $_subscribers_filename;
51
+ protected $_customers_address_book_id;
52
+ protected $_subscribers_address_book_id;
53
+ protected $_customers_file_slug = 'customer_sync';
54
+ protected $_subscribers_file_slug = 'subscriber_sync';
55
+ public $result = array('error' => false, 'message' => '');
56
+
57
+
58
+ /**
59
+ * constructor.
60
+ */
61
+ public function __construct()
62
+ {
63
+ parent::__construct();
64
+ }
65
+
66
+ /**
67
+ * Excluded api response that we don't want to send.
68
+ * @var array
69
+ */
70
+ public $exludeMessages = array(
71
+ self::API_ERROR_FEATURENOTACTIVE,
72
+ self::API_ERROR_PROGRAM_NOT_ACTIVE,
73
+ self::API_ERROR_CONTACT_SUPPRESSED,
74
+ self::API_ERROR_DATAFIELD_EXISTS,
75
+ self::API_ERROR_AUTHORIZATION_DENIED,
76
+ self::API_ERROR_ENROLMENT_EXCEEDED,
77
+ self::API_ERROR_SEND_NOT_PERMITTED,
78
+ self::API_ERROR_TRANS_NOT_EXISTS,
79
+ self::API_ERROR_ADDRESSBOOK_NOT_FOUND
80
+ );
81
+
82
+ /**
83
+ * @param $apiUsername
84
+ * @param $apiPassword
85
+ * @return bool|mixed
86
+ */
87
+ public function validate($apiUsername, $apiPassword)
88
+ {
89
+ if ($apiUsername && $apiPassword) {
90
+ $this->setApiUsername($apiUsername)
91
+ ->setApiPassword($apiPassword);
92
+ $accountInfo = $this->getAccountInfo();
93
+
94
+ if (isset($accountInfo->message)) {
95
+ Mage::getSingleton('adminhtml/session')->addError($accountInfo->message);
96
+ $message = 'VALIDATION ERROR : ' . $accountInfo->message;
97
+ Mage::helper('ddg')->log($message);
98
+ return false;
99
+ }
100
+ return $accountInfo;
101
+ }
102
+ return false;
103
+ }
104
+ /**
105
+ * Gets a contact by ID. Unsubscribed or suppressed contacts will not be retrieved.
106
+ * @param $id
107
+ * @return null
108
+ */
109
+ public function getContactById($id)
110
+ {
111
+ $url = self::REST_CONTACTS . $id;
112
+ $this->setUrl($url)
113
+ ->setVerb('GET');
114
+ $response = $this->execute();
115
+
116
+ if(isset($response->message)) {
117
+ $message = 'GET CONTACT INFO ID ' . $url . ', ' . $response->message;
118
+ Mage::helper( 'ddg' )->log( $message );
119
+ }
120
+
121
+ return $response;
122
+ }
123
+
124
+ /**
125
+ * Bulk creates, or bulk updates, contacts. Import format can either be CSV or Excel.
126
+ * Must include one column called "Email". Any other columns will attempt to map to your custom data fields.
127
+ * The ID of returned object can be used to query import progress.
128
+ * @param $filename
129
+ * @param $addressBookId
130
+ * @return mixed
131
+ */
132
+
133
+ public function postAddressBookContactsImport($filename, $addressBookId)
134
+ {
135
+ $url = "https://apiconnector.com/v2/address-books/{$addressBookId}/contacts/import";
136
+ $helper = Mage::helper('ddg');
137
+
138
+ $ch = curl_init($url);
139
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
140
+ curl_setopt($ch, CURLOPT_USERPWD, $this->getApiUsername() . ':' . $this->getApiPassword());
141
+
142
+ //case the deprication of @filename for uploading
143
+ if (function_exists('curl_file_create')) {
144
+ curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
145
+ $args['file'] = curl_file_create(Mage::helper('ddg/file')->getFilePath($filename), 'text/csv');
146
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
147
+
148
+ } else {
149
+ //standart use of curl file
150
+ curl_setopt($ch, CURLOPT_POSTFIELDS, array (
151
+ 'file' => '@'.Mage::helper('ddg/file')->getFilePath($filename)
152
+ ));
153
+ }
154
+
155
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
156
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
157
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array(
158
+ 'Content-Type: multipart/form-data')
159
+ );
160
+
161
+ // send contacts to address book
162
+ $result = curl_exec($ch);
163
+ $result = json_decode($result);
164
+ if (isset($result->message)) {
165
+ $message = 'POST ADDRESS BOOK ' . $addressBookId . ', CONTACT IMPORT : ' . ' filename ' . $filename . ' Username ' . $this->getApiUsername() . $result->message;
166
+ $helper->log($message);
167
+ Mage::helper('ddg')->log($result);
168
+ Mage::helper('ddg')->rayLog('205', $message, __FILE__, __LINE__);
169
+ }
170
+ return $result;
171
+ }
172
+
173
+ /**
174
+ * Adds a contact to a given address book.
175
+ * @param $addressBookId
176
+ * @param $apiContact
177
+ * @return mixed|null
178
+ */
179
+ public function postAddressBookContacts($addressBookId, $apiContact)
180
+ {
181
+ $url = self::REST_ADDRESS_BOOKS . $addressBookId . '/contacts';
182
+ $this->setUrl($url)
183
+ ->setVerb("POST")
184
+ ->buildPostBody($apiContact);
185
+
186
+ $response = $this->execute();
187
+ if (isset($response->message)) {
188
+
189
+ $message = 'POST ADDRESS BOOK CONTACTS ' . $url . ', ' . $response->message;
190
+ Mage::helper('ddg')->log($message);
191
+ if (! in_array($response->message, $this->exludeMessages)) {
192
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
193
+
194
+
195
+ }
196
+ }
197
+
198
+ return $response;
199
+ }
200
+
201
+ /**
202
+ * Deletes all contacts from a given address book.
203
+ * @param $addressBookId
204
+ * @param $contactId
205
+ * @return null
206
+ */
207
+ public function deleteAddressBookContact($addressBookId, $contactId)
208
+ {
209
+
210
+ $url = self::REST_ADDRESS_BOOKS . $addressBookId . '/contacts/' . $contactId;
211
+ $this->setUrl($url)
212
+ ->setVerb('DELETE');
213
+ $response = $this->execute();
214
+
215
+ return $response;
216
+ }
217
+
218
+ /**
219
+ * Gets a report with statistics about what was successfully imported, and what was unable to be imported.
220
+ * @param $importId
221
+ * @return mixed
222
+ */
223
+ public function getContactsImportReport($importId)
224
+ {
225
+
226
+ $url = self::REST_CONTACTS_IMPORT . $importId . "/report";
227
+ $this->setUrl($url)
228
+ ->setVerb('GET');
229
+ $response = $this->execute();
230
+ if (isset($response->message)) {
231
+ $message = 'GET CONTACTS IMPORT REPORT . ' . $url . ' message : ' . $response->message;
232
+ Mage::helper( 'ddg' )->log( $message );
233
+ if (! in_array($response->message, $this->exludeMessages))
234
+ Mage::helper( 'ddg' )->rayLog( '100', $message, 'apiconnector/client.php', __LINE__);
235
+ }
236
+ return $response;
237
+ }
238
+
239
+ /**
240
+ * Gets a contact by email address.
241
+ * @param $email
242
+ * @return mixed
243
+ */
244
+ public function getContactByEmail($email)
245
+ {
246
+ $url = self::REST_CONTACTS . $email;
247
+ $this->setUrl($url)
248
+ ->setVerb('GET');
249
+
250
+ //should create new one if not exists?!?
251
+ $response = $this->execute();
252
+ if (isset($response->message)) {
253
+ $message = 'GET CONTACT BY email : ' . $email . ' ' . $response->message;
254
+ Mage::helper('ddg')->log($message);
255
+ if (! in_array($response->message, $this->exludeMessages))
256
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
257
+ }
258
+
259
+ return $response;
260
+ }
261
+
262
+ /**
263
+ * Get all address books.
264
+ * @return null
265
+ */
266
+ public function getAddressBooks()
267
+ {
268
+ $url = self::REST_ADDRESS_BOOKS;
269
+ $this->setUrl($url)
270
+ ->setVerb("GET");
271
+
272
+ $response = $this->execute();
273
+ if (isset($response->message)) {
274
+ $message = 'GET ALL ADDRESS BOOKS : ' . $url . ', ' . $response->message;
275
+ Mage::helper('ddg')->log($message);
276
+ if (! in_array($response->message, $this->exludeMessages))
277
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
278
+ }
279
+ return $response;
280
+ }
281
+
282
+ /**
283
+ * Gets an address book by ID.
284
+ * @param $id
285
+ *
286
+ * @return null
287
+ * @throws Exception
288
+ */
289
+ public function getAddressBookById($id)
290
+ {
291
+ $url = self::REST_ADDRESS_BOOKS . $id;
292
+
293
+ $this->setUrl($url)
294
+ ->setVerb('GET');
295
+
296
+ $response = $this->execute();
297
+
298
+ if (isset($response->message)) {
299
+ $message = 'GET ADDRESS BOOK BY ID '. $id . ', ' . $response->message;
300
+ Mage::helper('ddg')->log($message);
301
+ }
302
+
303
+ return $response;
304
+ }
305
+
306
+ /**
307
+ * Creates an address book.
308
+ * @param $name
309
+ * @return null
310
+ */
311
+ public function postAddressBooks($name, $visibility = 'Public')
312
+ {
313
+ $data = array(
314
+ 'Name' => $name,
315
+ 'Visibility' => $visibility
316
+ );
317
+ $url = self::REST_ADDRESS_BOOKS;
318
+ $this->setUrl($url)
319
+ ->setVerb('POST')
320
+ ->buildPostBody($data);
321
+
322
+ $response = $this->execute();
323
+ if (isset($response->message)) {
324
+ $message = 'Postaddressbooks ' . $response->message . ', url :' . $url ;
325
+ Mage::helper('ddg')->log($message);
326
+ if (! in_array($response->message, $this->exludeMessages))
327
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
328
+ }
329
+ return $response;
330
+ }
331
+
332
+ /**
333
+ * Get list of all campaigns.
334
+ * @return mixed
335
+ */
336
+ public function getCampaigns()
337
+ {
338
+ $url = self::REST_DATA_FIELDS_CAMPAIGNS;
339
+ $this->setUrl($url)
340
+ ->setVerb('GET');
341
+
342
+ $response = $this->execute();
343
+
344
+ if (isset($response->message)) {
345
+ $message = 'GET CAMPAIGNS ' . $response->message . ' api user : ' . $this->getApiUsername();
346
+ Mage::helper('ddg')->log($message);
347
+ if (! in_array($response->message, $this->exludeMessages))
348
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
349
+ }
350
+
351
+ return $response;
352
+ }
353
+
354
+ /**
355
+ * Creates a data field within the account.
356
+ * @param $data string/array
357
+ * @param string $type string, numeric, date, boolean
358
+ * @param string $visibility public, private
359
+ * @param bool $defaultValue
360
+ * @return mixed
361
+ */
362
+ public function postDataFields($data, $type = 'String', $visibility = 'public', $defaultValue = false)
363
+ {
364
+ $url = self::REST_DATA_FILEDS;
365
+ //set default value for the numeric datatype
366
+ if($type == 'numeric' && !$defaultValue)
367
+ $defaultValue = 0;
368
+ //set data for the string datatype
369
+ if (is_string($data)) {
370
+ $data = array(
371
+ 'Name' => $data,
372
+ 'Type' => $type,
373
+ 'Visibility' => $visibility
374
+ );
375
+ //default value
376
+ if($defaultValue)
377
+ $data['DefaultValue'] = $defaultValue;
378
+ }
379
+ $this->setUrl($url)
380
+ ->buildPostBody($data)
381
+ ->setVerb('POST');
382
+
383
+ $response = $this->execute();
384
+
385
+ if (isset($response->message)) {
386
+ $message = 'POST CREATE DATAFIELDS ' . $response->message;
387
+ Mage::helper('ddg')->log($message);
388
+ Mage::helper('ddg')->log($data);
389
+ if (! in_array($response->message, $this->exludeMessages))
390
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
391
+ }
392
+
393
+ return $response;
394
+ }
395
+
396
+ /**
397
+ * Deletes a data field within the account.
398
+ * @param $name
399
+ *
400
+ * @return mixed
401
+ */
402
+ public function deleteDataField($name)
403
+ {
404
+ $url = self::REST_DATA_FILEDS . '/' . $name;
405
+ $request = Mage::helper('ddg/api_restrequest');
406
+ $request->setUrl($url)
407
+ ->setVerb('DELETE');
408
+
409
+ $response = $request->execute();
410
+ if (isset($response->message)) {
411
+ $message = 'DELETE DATA FIELD :' . $name . ' ' . $response->message;
412
+ Mage::helper('ddg')->log($message);
413
+ if (! in_array($response->message, $this->exludeMessages))
414
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
415
+ }
416
+ return $request->execute();
417
+ }
418
+
419
+ /**
420
+ * Lists the data fields within the account.
421
+ * @return mixed
422
+ */
423
+ public function getDataFields()
424
+ {
425
+
426
+
427
+ $url = self::REST_DATA_FILEDS;
428
+ $this->setUrl($url)
429
+ ->setVerb('GET');
430
+
431
+ $response = $this->execute();
432
+ if (isset($response->message)) {
433
+ $message = 'GET ALL DATAFIELDS ' . $response->message;
434
+ Mage::helper('ddg')->log($message);
435
+ if (! in_array($response->message, $this->exludeMessages))
436
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
437
+ }
438
+
439
+ return $response;
440
+ }
441
+
442
+ /**
443
+ * Updates a contact.
444
+ * @param $contactId
445
+ * @param $data
446
+ * @return object
447
+ */
448
+ public function updateContact($contactId, $data)
449
+ {
450
+
451
+ $url = self::REST_CONTACTS . $contactId;
452
+ $this->setUrl($url)
453
+ ->setVerb('PUT')
454
+ ->buildPostBody($data);
455
+
456
+ $response = $this->execute();
457
+ if (isset($response->message)) {
458
+ $message = 'ERROR : UPDATE SINGLE CONTACT : ' . $url . ' message : ' . $response->message;
459
+ Mage::helper('ddg')->log($message);
460
+ Mage::helper('ddg')->log($data);
461
+ if (! in_array($response->message, $this->exludeMessages))
462
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
463
+ }
464
+
465
+ return $response;
466
+ }
467
+
468
+ /**
469
+ * Deletes a contact.
470
+ * @param $contactId
471
+ * @return null
472
+ */
473
+ public function deleteContact($contactId)
474
+ {
475
+
476
+
477
+ $url = self::REST_CONTACTS . $contactId;
478
+ $this->setUrl($url)
479
+ ->setVerb('DELETE');
480
+
481
+ $response = $this->execute();
482
+
483
+ if (isset($response->message)) {
484
+ $message = 'DELETE CONTACT : ' . $url . ', ' . $response->message;
485
+ Mage::helper('ddg')->log($message);
486
+ if (! in_array($response->message, $this->exludeMessages))
487
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
488
+ }
489
+ return $response;
490
+ }
491
+
492
+ /**
493
+ * Update contact datafields by email.
494
+ * @param $email
495
+ * @param $dataFields
496
+ *
497
+ * @return null
498
+ * @throws Exception
499
+ */
500
+ public function updateContactDatafieldsByEmail($email, $dataFields)
501
+ {
502
+
503
+
504
+ $apiContact = $this->postContacts($email);
505
+ //do not create for non contact id set
506
+ if (! isset($apiContact->id)) {
507
+ return $apiContact;
508
+ } else {
509
+ //get the contact id for this email
510
+ $contactId = $apiContact->id;
511
+ }
512
+ $data = array(
513
+ 'Email' => $email,
514
+ 'EmailType' => 'Html');
515
+ $data['DataFields'] = $dataFields;
516
+ $url = self::REST_CONTACTS . $contactId;
517
+ $this->setUrl($url)
518
+ ->setVerb('PUT')
519
+ ->buildPostBody($data);
520
+
521
+ $response = $this->execute();
522
+ if (isset($response->message)) {
523
+ $message = 'ERROR: UPDATE CONTACT DATAFIELD ' . $url . ' message : ' . $response->message;
524
+ Mage::helper('ddg')->log($message);
525
+ Mage::helper('ddg')->log($data);
526
+ if (! in_array($response->message, $this->exludeMessages))
527
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
528
+ }
529
+
530
+ return $response;
531
+ }
532
+
533
+ /**
534
+ * Sends a specified campaign to one or more address books, segments or contacts at a specified time.
535
+ * Leave the address book array empty to send to All Contacts.
536
+ * @param $campaignId
537
+ * @param $contacts
538
+ * @return mixed
539
+ */
540
+ public function postCampaignsSend($campaignId, $contacts)
541
+ {
542
+
543
+
544
+ $helper = Mage::helper('ddg');
545
+ $data = array(
546
+ 'username' => $this->getApiUsername(),
547
+ 'password' => $this->getApiPassword(),
548
+ "campaignId" => $campaignId,
549
+ "ContactIds" => $contacts
550
+ );
551
+ $this->setUrl(self::REST_CAMPAIGN_SEND)
552
+ ->setVerb('POST')
553
+ ->buildPostBody($data);
554
+
555
+ $response = $this->execute();
556
+ if (isset($response->message)) {
557
+ $message = 'SENDING CAMPAIGN ' . $response->message;
558
+ $helper->log($message);
559
+ $helper->log($data);
560
+ if (! in_array($response->message, $this->exludeMessages))
561
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
562
+ }
563
+
564
+ return $response;
565
+ }
566
+
567
+ /**
568
+ * Creates a contact.
569
+ * @param $email
570
+ * @return mixed
571
+ */
572
+ public function postContacts($email)
573
+ {
574
+
575
+
576
+ $url = self::REST_CONTACTS;
577
+ $data = array(
578
+ 'Email' => $email,
579
+ 'EmailType' => 'Html',
580
+ );
581
+ $this->setUrl($url)
582
+ ->setVerb('POST')
583
+ ->buildPostBody($data);
584
+
585
+ $response = $this->execute();
586
+ if (isset($response->message)) {
587
+ $message = 'CREATE A NEW CONTACT : ' . $email . ' , url ' . $url . ', ' . $response->message;
588
+ Mage::helper('ddg')->log($message);
589
+ if (! in_array($response->message, $this->exludeMessages))
590
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
591
+ }
592
+
593
+ return $response;
594
+ }
595
+
596
+
597
+ /**
598
+ * Gets a list of suppressed contacts after a given date along with the reason for suppression.
599
+ * @param $dateString
600
+ * @param $select
601
+ * @param $skip
602
+ * @return object
603
+ */
604
+ public function getContactsSuppressedSinceDate($dateString, $select = 1000, $skip = 0)
605
+ {
606
+
607
+
608
+ $url = self::REST_CONTACTS_SUPPRESSED_SINCE . $dateString . '?select=' . $select . '&skip=' . $skip;
609
+ $this->setUrl($url)
610
+ ->setVerb("GET");
611
+
612
+ $response = $this->execute();
613
+
614
+ if (isset($response->message)) {
615
+ $message = 'GET CONTACTS SUPPRESSED SINSE : ' . $dateString . ' select ' . $select . ' skip : ' . $skip . ' response : ' . $response->message;
616
+ Mage::helper('ddg')->log($message);
617
+ if (! in_array($response->message, $this->exludeMessages))
618
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
619
+ }
620
+
621
+ return $response;
622
+ }
623
+
624
+ /**
625
+ * Adds multiple pieces of transactional data to contacts asynchronously, returning an identifier that can be used to check for import progress.
626
+ * @param $collectionName
627
+ * @param $transactionalData
628
+ * @return object
629
+ */
630
+ public function postContactsTransactionalDataImport($transactionalData, $collectionName = 'Orders')
631
+ {
632
+ $orders = array();
633
+ foreach ($transactionalData as $one) {
634
+ if (isset($one->email)) {
635
+ $orders[] = array(
636
+ 'Key' => $one->id,
637
+ 'ContactIdentifier' => $one->email,
638
+ 'Json' => json_encode($one)
639
+ );
640
+ }
641
+ }
642
+ $url = self::REST_TRANSACTIONAL_DATA_IMPORT . $collectionName;
643
+ $this->setURl($url)
644
+ ->setVerb('POST')
645
+ ->buildPostBody($orders);
646
+
647
+ $response = $this->execute();
648
+
649
+ if (isset($response->message)) {
650
+ $message = ' SEND MULTI TRANSACTIONAL DATA ' . $response->message;
651
+ Mage::helper('ddg')->log($message);
652
+ if (! in_array($response->message, $this->exludeMessages))
653
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
654
+ }
655
+
656
+ return $response;
657
+ }
658
+
659
+ /**
660
+ * Adds a single piece of transactional data to a contact.
661
+ *
662
+ * @param $data
663
+ * @param string $collectionName
664
+ *
665
+ * @return null
666
+ * @throws Exception
667
+ */
668
+ public function postContactsTransactionalData($data, $collectionName = 'Orders')
669
+ {
670
+ $order = $this->getContactsTransactionalDataByKey($collectionName, $data->id);
671
+ if(isset($order->message) && $order->message == self::API_ERROR_TRANS_NOT_EXISTS){
672
+ $url = self::REST_TRANSACTIONAL_DATA . $collectionName;
673
+ }else{
674
+ $url = self::REST_TRANSACTIONAL_DATA . $collectionName . '/' . $order->key ;
675
+ }
676
+ $apiData = array(
677
+ 'Key' => $data->id,
678
+ 'Json' => json_encode($data->expose())
679
+ );
680
+
681
+ $this->setUrl($url)
682
+ ->setVerb('POST')
683
+ ->buildPostBody($apiData);
684
+ $response = $this->execute();
685
+
686
+ if (isset($response->message)) {
687
+ $message = 'POST CONTACTS TRANSACTIONAL DATA ' . $response->message;
688
+ Mage::helper('ddg')->log($message);
689
+ Mage::helper('ddg')->log($apiData);
690
+ if (! in_array($response->message, $this->exludeMessages))
691
+ Mage::helper('ddg')->rayLog('100', $message, __FILE__, __LINE__);
692
+ }
693
+
694
+ return $response;
695
+ }
696
+
697
+ /**
698
+ * Gets a piece of transactional data by key.
699
+ * @param $name
700
+ * @param $key
701
+ * @return null
702
+ */
703
+ public function getContactsTransactionalDataByKey($name, $key)
704
+ {
705
+ $url = self::REST_TRANSACTIONAL_DATA . $name . '/' . $key;
706
+ $this->setUrl($url)
707
+ ->setVerb('GET');
708
+
709
+ return $this->execute();
710
+ }
711
+
712
+ /**
713
+ * Deletes all transactional data for a contact.
714
+ * @param $email
715
+ * @param string $collectionName
716
+ * @return object
717
+ */
718
+ public function deleteContactTransactionalData($email, $collectionName = 'Orders')
719
+ {
720
+ $url = 'https://apiconnector.com/v2/contacts/' . $email . '/transactional-data/' . $collectionName ;
721
+ $this->setUrl($url)
722
+ ->setVerb('DELETE');
723
+
724
+ return $this->execute();
725
+ }
726
+
727
+ /**
728
+ * Gets a summary of information about the current status of the account.
729
+ * @return mixed
730
+ */
731
+ public function getAccountInfo()
732
+ {
733
+
734
+ $url = self::REST_ACCOUNT_INFO;
735
+ $this->setUrl($url)
736
+ ->setVerb('GET');
737
+
738
+ $response = $this->execute();
739
+ if (isset($response->message)) {
740
+ $message = 'GET ACCOUNT INFO for api user : ' . $this->getApiUsername() . ' ' . $response->message;
741
+ Mage::helper('ddg')->log($message);
742
+ if (! in_array($response->message, $this->exludeMessages))
743
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
744
+ }
745
+
746
+ return $response;
747
+ }
748
+
749
+ /**
750
+ * Send a single SMS message.
751
+ * @param $telephoneNumber
752
+ * @param $message
753
+ * @return object
754
+ */
755
+ public function postSmsMessagesSendTo($telephoneNumber, $message)
756
+ {
757
+
758
+
759
+ $data = array('Message' => $message);
760
+ $url = self::REST_SMS_MESSAGE_SEND_TO . $telephoneNumber;
761
+ $this->setUrl($url)
762
+ ->setVerb('POST')
763
+ ->buildPostBody($data);
764
+
765
+ $response = $this->execute();
766
+ if (isset($response->message)) {
767
+ $message = 'POST SMS MESSAGE SEND to ' . $telephoneNumber . ' message: ' . $message . ' error: ' . $response->message;
768
+ Mage::helper('ddg')->log($message);
769
+ if (! in_array($response->message, $this->exludeMessages))
770
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
771
+ }
772
+
773
+ return $response;
774
+ }
775
+
776
+
777
+ /**
778
+ * Deletes multiple contacts from an address book.
779
+ * @param $addressBookId
780
+ * @param $contactIds
781
+ * @return object
782
+ */
783
+ public function deleteAddressBookContactsInbulk($addressBookId, $contactIds)
784
+ {
785
+
786
+
787
+ $url = 'https://apiconnector.com/v2/address-books/' . $addressBookId . '/contacts/inbulk';
788
+ $data = array('ContactIds' => array($contactIds[0]));
789
+ $this->setUrl($url)
790
+ ->setVerb('DELETE')
791
+ ->buildPostBody($data);
792
+
793
+ $response = $this->execute();
794
+ if (isset($response->message)) {
795
+ $message = 'DELETE BULK ADDRESS BOOK CONTACTS ' . $response->message . ' address book ' . $addressBookId;
796
+ Mage::helper('ddg')->log($message);
797
+ if (! in_array($response->message, $this->exludeMessages))
798
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
799
+ }
800
+ return $response;
801
+ }
802
+
803
+ /**
804
+ * Resubscribes a previously unsubscribed contact.
805
+ *
806
+ * @param $apiContact
807
+ */
808
+ public function postContactsResubscribe($apiContact)
809
+ {
810
+
811
+
812
+ $url = self::REST_CONTACTS_RESUBSCRIBE;
813
+ $data = array(
814
+ 'UnsubscribedContact' => $apiContact
815
+ );
816
+ $this->setUrl($url)
817
+ ->setVerb("POST")
818
+ ->buildPostBody($data);
819
+
820
+ $response = $this->execute();
821
+ if (isset($response->message)) {
822
+ $message = 'Resubscribe : ' . $url . ', message :' . $response->message;
823
+ Mage::helper('ddg')->log($message);
824
+ Mage::helper('ddg')->log($data);
825
+ if (! in_array($response->message, $this->exludeMessages))
826
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
827
+ }
828
+ }
829
+
830
+ /**
831
+ * Gets all custom from addresses which can be used in a campaign.
832
+ *
833
+ * @return null
834
+ * @throws Exception
835
+ */
836
+
837
+ public function getCustomFromAddresses()
838
+ {
839
+
840
+
841
+ $url = self::REST_CAMPAIGN_FROM_ADDRESS_LIST;
842
+ $this->setUrl($url)
843
+ ->setVerb('GET');
844
+
845
+ $response = $this->execute();
846
+
847
+ if (isset($response->message)) {
848
+
849
+ $message = 'GET CampaignFromAddressList ' . $response->message . ' api user : ' . $this->getApiUsername();
850
+ Mage::helper('ddg')->log($message);
851
+ if (! in_array($response->message, $this->exludeMessages))
852
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
853
+ }
854
+
855
+ return $response;
856
+ }
857
+
858
+ /**
859
+ * Creates a campaign.
860
+ * @param $data
861
+ *
862
+ * @return null
863
+ * @throws Exception
864
+ */
865
+ public function postCampaign($data)
866
+ {
867
+
868
+
869
+ $url = self::REST_CREATE_CAMPAIGN;
870
+ $this->setURl($url)
871
+ ->setVerb('POST')
872
+ ->buildPostBody($data);
873
+
874
+ $response = $this->execute();
875
+
876
+ if (isset($response->message)) {
877
+ $message = ' CREATE CAMPAIGN ' . $response->message;
878
+ Mage::helper('ddg')->log($message);
879
+ if (! in_array($response->message, $this->exludeMessages))
880
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
881
+ }
882
+
883
+ return $response;
884
+ }
885
+
886
+ /**
887
+ * Gets all programs.
888
+ * https://apiconnector.com/v2/programs?select={select}&skip={skip}
889
+ */
890
+ public function getPrograms()
891
+ {
892
+
893
+
894
+ $url = self::REST_PROGRAM;
895
+
896
+ $this->setUrl($url)
897
+ ->setVerb('GET');
898
+
899
+ $response = $this->execute();
900
+
901
+ if (isset($response->message)) {
902
+ $message = 'Get programmes : ' . $response->message ;
903
+ Mage::helper( 'ddg' )->log($message);
904
+ if (! in_array($response->message, $this->exludeMessages))
905
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
906
+ }
907
+
908
+ return $response;
909
+ }
910
+
911
+ /**
912
+ * Creates an enrolment.
913
+ * @param $data
914
+ *
915
+ * @return null
916
+ * @throws Exception
917
+ */
918
+ public function postProgramsEnrolments($data)
919
+ {
920
+ $url = self::REST_PROGRAM_ENROLMENTS;
921
+ $this->setUrl($url)
922
+ ->setVerb('POST')
923
+ ->buildPostBody($data);
924
+
925
+ $response = $this->execute();
926
+ if (isset($response->message)) {
927
+ $message = 'Post programs enrolments : ' . $response->message;
928
+ Mage::helper('ddg')->log($message);
929
+ Mage::helper('ddg')->log($data);
930
+ if (! in_array($response->message, $this->exludeMessages))
931
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
932
+ }
933
+
934
+ return $response;
935
+ }
936
+
937
+ /**
938
+ * Gets a program by id.
939
+ * @param $id
940
+ *
941
+ * @return null
942
+ * @throws Exception
943
+ */
944
+ public function getProgramById( $id )
945
+ {
946
+
947
+
948
+ $url = self::REST_PROGRAM . $id;
949
+ $this->setUrl($url)
950
+ ->setVerb('GET');
951
+
952
+ $response = $this->execute();
953
+ if (isset($response->message)) {
954
+ $message = 'Get program by id ' . $id . ', ' . $response->message;
955
+ Mage::helper('ddg')->log($message);
956
+ if (! in_array($response->message, $this->exludeMessages))
957
+ Mage::helper("ddg")->rayLog(100, $message, 'apiconnector/client.php', __LINE__);
958
+
959
+ }
960
+
961
+ return $response;
962
+ }
963
+
964
+ /**
965
+ * Gets a summary of reporting information for a specified campaign.
966
+ * @param $campaignId
967
+ *
968
+ * @return null
969
+ * @throws Exception
970
+ */
971
+ public function getCampaignSummary($campaignId)
972
+ {
973
+ $url = 'https://apiconnector.com/v2/campaigns/' . $campaignId . '/summary';
974
+
975
+ $this->setUrl($url)
976
+ ->setVerb('GET');
977
+ $response = $this->execute();
978
+
979
+ if (isset($response->message)) {
980
+ $message = 'Get Campaign Summary ' . $response->message . ' ,url : ' . $url;
981
+ Mage::helper('ddg')->log( $message );
982
+ if (! in_array($response->message, $this->exludeMessages))
983
+ Mage::helper('ddg')->rayLog(100, $message, 'apiconnector/client.php', __LINE__);
984
+ }
985
+
986
+ return $response;
987
+ }
988
+
989
+ /**
990
+ * Deletes a piece of transactional data by key.
991
+ * @param $key
992
+ * @param string $collectionName
993
+ * @return object
994
+ */
995
+ public function deleteContactsTransactionalData($key, $collectionName = 'Orders')
996
+ {
997
+ $url = 'https://apiconnector.com/v2/contacts/transactional-data/' . $collectionName .'/' . $key ;
998
+ $this->setUrl($url)
999
+ ->setVerb('DELETE');
1000
+ $response = $this->execute();
1001
+ if (isset($response->message))
1002
+ Mage::helper('ddg')->log('DELETE CONTACTS TRANSACTIONAL DATA : ' . $url . ' ' . $response->message);
1003
+
1004
+ return $response;
1005
+ }
1006
+
1007
+ /**
1008
+ * Adds a document to a campaign as an attachment.
1009
+ * @param $campaignId
1010
+ * @param $data
1011
+ *
1012
+ * @return object
1013
+ * @throws Exception
1014
+ */
1015
+ public function postCampaignAttachments($campaignId, $data)
1016
+ {
1017
+ $url = self::REST_CREATE_CAMPAIGN . "/$campaignId/attachments";
1018
+ $this->setURl($url)
1019
+ ->setVerb('POST')
1020
+ ->buildPostBody($data);
1021
+ $result = $this->execute();
1022
+ if (isset($result->message)) {
1023
+ Mage::helper('ddg')->log(' CAMPAIGN ATTACHMENT ' . $result->message);
1024
+ }
1025
+ return $result;
1026
+ }
1027
+
1028
+
1029
+ public function getNostoProducts($slotName, $email)
1030
+ {
1031
+ $recommended = Dotdigitalgroup_Email_Helper_Config::API_ENDPOINT . '/recommendations/email';
1032
+ $token = Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DYNAMIC_CONTENT_NOSTO);
1033
+
1034
+ //check for strin length
1035
+ if (strlen($slotName) > 1 && strlen($email) > 1) {
1036
+
1037
+ $recommended .= '?elements=' . $slotName;
1038
+ $recommended .= '&emails=' . $email;
1039
+ }
1040
+
1041
+ $this->setApiUsername('')
1042
+ ->setApiPassword($token)
1043
+ ->setUrl($recommended)
1044
+ ->setVerb('GET');
1045
+
1046
+ $result = $this->execute();
1047
+
1048
+ if (isset($result->message)) {
1049
+ $message = $result->message;
1050
+ Mage::helper('ddg')->log($message);
1051
+ Mage::helper('ddg')->log("Nosto recommendation slot name : $slotName , email : $email");
1052
+ }
1053
+
1054
+ return $result;
1055
+ }
1056
+
1057
+ /**
1058
+ * get contact address books
1059
+ *
1060
+ * @param $contactId
1061
+ * @return object
1062
+ * @throws Exception
1063
+ */
1064
+ public function getContactAddressBooks($contactId)
1065
+ {
1066
+
1067
+
1068
+ $url = 'https://apiconnector.com/v2/contacts/' . $contactId . '/address-books' ;
1069
+ $this->setUrl($url)
1070
+ ->setVerb('GET');
1071
+ $response = $this->execute();
1072
+ if (isset($response->message)) {
1073
+ $message = 'GET CONTACTS ADDRESS BOOKS contact: ' . $contactId . $response->message;
1074
+ Mage::helper('ddg')->log($message);
1075
+ if (! in_array($response->message, $this->exludeMessages))
1076
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
1077
+ }
1078
+
1079
+ return $response;
1080
+ }
1081
+
1082
+ /**
1083
+ * Gets list of all templates.
1084
+ *
1085
+ * @return object
1086
+ * @throws Exception
1087
+ */
1088
+ public function getApiTemplateList()
1089
+ {
1090
+ $url = self::REST_TEMPLATES;
1091
+ $this->setUrl($url)
1092
+ ->setVerb('GET');
1093
+ $response = $this->execute();
1094
+
1095
+ if (isset($response->message)) {
1096
+ $message = 'GET API CONTACT LIST ' . $response->message;
1097
+ Mage::helper('ddg')->log($message);
1098
+
1099
+ if (! in_array($response->message, $this->exludeMessages))
1100
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
1101
+ }
1102
+ return $response;
1103
+ }
1104
+
1105
+ /**
1106
+ * Gets a template by ID.
1107
+ *
1108
+ * @param $templateId
1109
+ * @return object
1110
+ * @throws Exception
1111
+ */
1112
+ public function getApiTemplate($templateId)
1113
+ {
1114
+
1115
+
1116
+ $url = self::REST_TEMPLATES . '/' . $templateId;
1117
+ $this->setUrl($url)
1118
+ ->setVerb('GET');
1119
+ $response = $this->execute();
1120
+ if (isset($response->message)) {
1121
+ $message = 'GET API CONTACT LIST ' . $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
+ return $response;
1127
+ }
1128
+
1129
+ /**
1130
+ * Adds multiple pieces of transactional data to account asynchronously, returning an identifier that can be used to check for import progress.
1131
+ * @param $collectionName
1132
+ * @param $transactionalData
1133
+ * @return object
1134
+ */
1135
+ public function postAccountTransactionalDataImport($transactionalData, $collectionName = 'Catalog_Default')
1136
+ {
1137
+
1138
+
1139
+ $orders = array();
1140
+ foreach ($transactionalData as $one) {
1141
+ if (isset($one->id)) {
1142
+ $orders[] = array(
1143
+ 'Key' => $one->id,
1144
+ 'ContactIdentifier' => 'account',
1145
+ 'Json' => json_encode($one->expose())
1146
+ );
1147
+ }
1148
+ }
1149
+ $url = self::REST_TRANSACTIONAL_DATA_IMPORT . $collectionName;
1150
+ $this->setURl($url)
1151
+ ->setVerb('POST')
1152
+ ->buildPostBody($orders);
1153
+
1154
+ $response = $this->execute();
1155
+
1156
+ if (isset($response->message)) {
1157
+ $message = ' SEND MULTI TRANSACTIONAL DATA TO ACCOUNT' . $response->message;
1158
+ Mage::helper('ddg')->log($message);
1159
+ if (! in_array($response->message, $this->exludeMessages))
1160
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
1161
+ }
1162
+
1163
+ return $response;
1164
+ }
1165
+
1166
+ public function getCampaignsWithActivitySinceDate($dateTime)
1167
+ {
1168
+
1169
+ $url = self::REST_DATA_FIELDS_CAMPAIGNS . '/with-activity-since/' . $dateTime;
1170
+
1171
+ $this->setUrl($url)
1172
+ ->setVerb('GET');
1173
+ $response = $this->execute();
1174
+ if (isset($response->message)) {
1175
+ $message = 'GET CAMPAIGNS WITH ACTIVITY SINCE DATE ' . $response->message;
1176
+ Mage::helper('ddg')->log($message);
1177
+ if (! in_array($response->message, $this->exludeMessages))
1178
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
1179
+ }
1180
+ return $response;
1181
+ }
1182
+
1183
+ public function getCampaignActivityByContactId($campaignId, $contactId)
1184
+ {
1185
+
1186
+ $url = self::REST_DATA_FIELDS_CAMPAIGNS . '/' . $campaignId . '/activities/' . $contactId;
1187
+
1188
+ $this->setUrl($url)
1189
+ ->setVerb('GET');
1190
+ $response = $this->execute();
1191
+ if (isset($response->message)) {
1192
+ $message = 'GET CAMPAIGN ACTIVITY BY CONTACT ID ' . $response->message;
1193
+ Mage::helper('ddg')->log($message);
1194
+ if (!in_array($response->message, $this->exludeMessages))
1195
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
1196
+ }
1197
+ return $response;
1198
+ }
1199
+
1200
+ /**
1201
+ * Gets the import status of a previously started contact import.
1202
+ *
1203
+ * @param $importId
1204
+ * @return object
1205
+ */
1206
+ public function getContactsImportByImportId($importId)
1207
+ {
1208
+ $url = self::REST_CONTACTS_IMPORT . $importId;
1209
+
1210
+ $this->setUrl($url)
1211
+ ->setVerb('GET');
1212
+ $response = $this->execute();
1213
+ if (isset($response->message)) {
1214
+ $message = 'GET CONTACTS IMPORT BY IMPORT ID ' . $response->message;
1215
+ Mage::helper('ddg')->log($message);
1216
+ if (!in_array($response->message, $this->exludeMessages))
1217
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
1218
+ }
1219
+ return $response;
1220
+ }
1221
+
1222
+ /**
1223
+ * Gets the import status of a previously started transactional import.
1224
+ *
1225
+ * @param $importId
1226
+ * @return object
1227
+ */
1228
+ public function getContactsTransactionalDataImportByImportId($importId)
1229
+ {
1230
+ $url = self::REST_TRANSACTIONAL_DATA_IMPORT . $importId;
1231
+
1232
+ $this->setUrl($url)
1233
+ ->setVerb('GET');
1234
+ $response = $this->execute();
1235
+ if (isset($response->message)) {
1236
+ $message = 'GET CONTACTS TRANSACTIONAL DATA IMPORT BY IMPORT ID ' . $response->message;
1237
+ Mage::helper('ddg')->log($message);
1238
+ if (! in_array($response->message, $this->exludeMessages))
1239
+ Mage::helper('ddg')->rayLog('100', $message, 'apiconnector/client.php', __LINE__);
1240
+ }
1241
+ return $response;
1242
+ }
1243
+ }
app/code/community/Dotdigitalgroup/Email/Model/Apiconnector/Contact.php ADDED
@@ -0,0 +1,430 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Apiconnector_Contact
4
+ {
5
+ private $_start;
6
+ private $_countCustomers = 0;
7
+ private $_sqlExecuted = false;
8
+
9
+ /**
10
+ * Contact sync.
11
+ *
12
+ * @return array
13
+ */
14
+ public function sync()
15
+ {
16
+ $result = array('success' => true, 'message' => '');
17
+ /** @var Dotdigitalgroup_Email_Helper_Data $helper */
18
+ $helper = Mage::helper('ddg');
19
+ $this->_start = microtime(true);
20
+ //resourse allocation
21
+ $helper->allowResourceFullExecution();
22
+ foreach (Mage::app()->getWebsites(true) as $website) {
23
+ $enabled = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED, $website);
24
+ $sync = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_CONTACT_ENABLED, $website);
25
+ if ($enabled && $sync) {
26
+
27
+ if (!$this->_countCustomers)
28
+ $helper->log('---------- Start customer sync ----------');
29
+ $numUpdated = $this->exportCustomersForWebsite($website);
30
+ // show message for any number of customers
31
+ if ($numUpdated)
32
+ $result['message'] .= '</br>' . $website->getName() . ', updated customers = ' . $numUpdated;
33
+ }
34
+ }
35
+ //sync proccessed
36
+ if ($this->_countCustomers) {
37
+ $message = 'Total time for sync : ' . gmdate( "H:i:s", microtime( true ) - $this->_start ) . ', Total updated = ' . $this->_countCustomers;
38
+ $helper->log( $message );
39
+ $message .= $result['message'];
40
+ $result['message'] = $message;
41
+ }
42
+
43
+ return $result;
44
+ }
45
+
46
+ /**
47
+ * Execute the contact sync for the website
48
+ * number of customer synced.
49
+ * @param Mage_Core_Model_Website $website
50
+ *
51
+ * @return int|void
52
+ */
53
+ public function exportCustomersForWebsite(Mage_Core_Model_Website $website)
54
+ {
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
+
59
+ //skip if the mapping field is missing
60
+ if ( !$helper->getCustomerAddressBook($website))
61
+ return 0;
62
+
63
+ $fileHelper = Mage::helper('ddg/file');
64
+ $contactModel = Mage::getModel('ddg_automation/contact');
65
+ $contacts = $contactModel->getContactsToImportForWebsite($website->getId(), $pageSize);
66
+
67
+ // no contacts for this website
68
+ if (!$contacts->getSize())
69
+ return 0;
70
+
71
+ //create customer filename
72
+ $customersFile = strtolower($website->getCode() . '_customers_' . date('d_m_Y_Hi') . '.csv');
73
+ $helper->log('Customers file : ' . $customersFile);
74
+
75
+ //get customer ids
76
+ $customerIds = $contacts->getColumnValues('customer_id');
77
+
78
+ //customer collection
79
+ $customerCollection = $this->getCollection($customerIds, $website->getId());
80
+
81
+ /**
82
+ * HEADERS.
83
+ */
84
+ $mappedHash = $fileHelper->getWebsiteCustomerMappingDatafields($website);
85
+ $headers = $mappedHash;
86
+
87
+ //custom customer attributes
88
+ $customAttributes = $helper->getCustomAttributes($website);
89
+ if ($customAttributes){
90
+ foreach ($customAttributes as $data) {
91
+ $headers[] = $data['datafield'];
92
+ $allMappedHash[$data['attribute']] = $data['datafield'];
93
+ }
94
+ }
95
+ $headers[] = 'Email';
96
+ $headers[] = 'EmailType';
97
+ $fileHelper->outputCSV($fileHelper->getFilePath($customersFile), $headers);
98
+ /**
99
+ * END HEADERS.
100
+ */
101
+
102
+ //only execute once despite number of websites
103
+ if(!$this->_sqlExecuted){
104
+ Mage::getResourceModel('ddg_automation/contact')->populateAndCleanupRecords();
105
+ //set flag
106
+ $this->_sqlExecuted = true;
107
+ }
108
+
109
+ //customer data
110
+ foreach ($customerCollection as $customer) {
111
+ $connectorCustomer = Mage::getModel('ddg_automation/apiconnector_customer', $mappedHash);
112
+ $connectorCustomer->setCustomerData($customer);
113
+ //count number of customers
114
+ $customers[] = $customer->getId();
115
+
116
+ if ($connectorCustomer) {
117
+ foreach ($customAttributes as $data) {
118
+ $attribute = $data['attribute'];
119
+ $value = $customer->getData($attribute);
120
+ $connectorCustomer->setData($value);
121
+ }
122
+ }
123
+
124
+ //contact email and email type
125
+ $connectorCustomer->setData($customer->getEmail());
126
+ $connectorCustomer->setData('Html');
127
+ // save csv file data for customers
128
+ $fileHelper->outputCSV($fileHelper->getFilePath($customersFile), $connectorCustomer->toCSVArray());
129
+ //clear collection and free memory
130
+ $customer->clearInstance();
131
+ }
132
+
133
+ $customerNum = count($customers);
134
+ $helper->log('Website : ' . $website->getName() . ', customers = ' . $customerNum);
135
+ $helper->log('---------------------------- execution time :' . gmdate("H:i:s", microtime(true) - $this->_start));
136
+
137
+ if (is_file($fileHelper->getFilePath($customersFile))) {
138
+ if ($customerNum > 0) {
139
+ //register in queue with importer
140
+ $check = Mage::getModel('ddg_automation/importer')->registerQueue(
141
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_CONTACT,
142
+ '',
143
+ Dotdigitalgroup_Email_Model_Importer::MODE_BULK,
144
+ $website->getId(),
145
+ $customersFile
146
+ );
147
+
148
+ //set imported
149
+ if ($check) {
150
+ Mage::getResourceModel('ddg_automation/contact')->update($customers);
151
+ }
152
+ }
153
+ }
154
+ $this->_countCustomers += $customerNum;
155
+ return $customerNum;
156
+ }
157
+
158
+ /**
159
+ * Sync a single contact.
160
+ *
161
+ * @param null $contactId
162
+ *
163
+ * @return mixed
164
+ * @throws Mage_Core_Exception
165
+ */
166
+ public function syncContact($contactId = null)
167
+ {
168
+ if ($contactId)
169
+ $contact = Mage::getModel('ddg_automation/contact')->load($contactId);
170
+ else {
171
+ $contact = Mage::registry('current_contact');
172
+ }
173
+ if (! $contact->getId()) {
174
+ Mage::getSingleton('adminhtml/session')->addError('No contact found!');
175
+ return false;
176
+ }
177
+
178
+ $websiteId = $contact->getWebsiteId();
179
+ $website = Mage::app()->getWebsite($websiteId);
180
+ $updated = 0;
181
+ $customers = $headers = $allMappedHash = array();
182
+ $helper = Mage::helper('ddg');
183
+ $helper->log('---------- Start single customer sync ----------');
184
+ //skip if the mapping field is missing
185
+ if(!$helper->getCustomerAddressBook($website))
186
+ return false;
187
+ $fileHelper = Mage::helper('ddg/file');
188
+
189
+ $customerId = $contact->getCustomerId();
190
+ if (!$customerId) {
191
+ Mage::getSingleton('adminhtml/session')->addError('Cannot manually sync guests!');
192
+ return false;
193
+ }
194
+
195
+ //create customer filename
196
+ $customersFile = strtolower($website->getCode() . '_customers_' . date('d_m_Y_Hi') . '.csv');
197
+ $helper->log('Customers file : ' . $customersFile);
198
+
199
+ /**
200
+ * HEADERS.
201
+ */
202
+ $mappedHash = $fileHelper->getWebsiteCustomerMappingDatafields($website);
203
+ $headers = $mappedHash;
204
+ //custom customer attributes
205
+ $customAttributes = $helper->getCustomAttributes($website);
206
+ foreach ($customAttributes as $data) {
207
+ $headers[] = $data['datafield'];
208
+ $allMappedHash[$data['attribute']] = $data['datafield'];
209
+ }
210
+
211
+ $headers[] = 'Email';
212
+ $headers[] = 'EmailType';
213
+ $fileHelper->outputCSV($fileHelper->getFilePath($customersFile), $headers);
214
+ /**
215
+ * END HEADERS.
216
+ */
217
+
218
+ //only execute once despite number of websites
219
+ if(!$this->_sqlExecuted){
220
+ Mage::getResourceModel('ddg_automation/contact')->populateAndCleanupRecords();
221
+ //set flag
222
+ $this->_sqlExecuted = true;
223
+ }
224
+
225
+
226
+ $customerCollection = $this->getCollection(array($customerId), $website->getId());
227
+
228
+ foreach ($customerCollection as $customer) {
229
+ /**
230
+ * DATA.
231
+ */
232
+ $connectorCustomer = Mage::getModel('ddg_automation/apiconnector_customer', $mappedHash);
233
+ $connectorCustomer->setCustomerData($customer);
234
+ //count number of customers
235
+ $customers[] = $connectorCustomer;
236
+ foreach ($customAttributes as $data) {
237
+ $attribute = $data['attribute'];
238
+ $value = $customer->getData($attribute);
239
+ $connectorCustomer->setData($value);
240
+ }
241
+ //contact email and email type
242
+ $connectorCustomer->setData($customer->getEmail());
243
+ $connectorCustomer->setData('Html');
244
+ // save csv file data for customers
245
+ $fileHelper->outputCSV($fileHelper->getFilePath($customersFile), $connectorCustomer->toCSVArray());
246
+
247
+ /**
248
+ * END DATA.
249
+ */
250
+
251
+ $updated++;
252
+ }
253
+
254
+ if (is_file($fileHelper->getFilePath($customersFile))) {
255
+ //import contacts
256
+ if ($updated > 0) {
257
+ //register in queue with importer
258
+ $check = Mage::getModel('ddg_automation/importer')->registerQueue(
259
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_CONTACT,
260
+ '',
261
+ Dotdigitalgroup_Email_Model_Importer::MODE_BULK,
262
+ $website->getId(),
263
+ $customersFile
264
+ );
265
+
266
+ //set imported
267
+ if ($check) {
268
+ Mage::getResourceModel('ddg_automation/contact')->update($customerId);
269
+ }
270
+ }
271
+ }
272
+ return $contact->getEmail();
273
+ }
274
+
275
+
276
+ /**
277
+ * get customer collection
278
+ * @param $customerIds
279
+ * @param $websiteId
280
+ * @return Mage_Eav_Model_Entity_Collection_Abstract
281
+ * @throws Mage_Core_Exception
282
+ */
283
+ public function getCollection($customerIds, $websiteId = 0)
284
+ {
285
+ $customerCollection = Mage::getResourceModel('customer/customer_collection')
286
+ ->addNameToSelect()
287
+ ->addAttributeToSelect('*')
288
+ ->joinAttribute('billing_street', 'customer_address/street', 'default_billing', null, 'left')
289
+ ->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
290
+ ->joinAttribute('billing_country_code', 'customer_address/country_id', 'default_billing', null, 'left')
291
+ ->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
292
+ ->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')
293
+ ->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
294
+ ->joinAttribute('shipping_street', 'customer_address/street', 'default_shipping', null, 'left')
295
+ ->joinAttribute('shipping_city', 'customer_address/city', 'default_shipping', null, 'left')
296
+ ->joinAttribute('shipping_country_code','customer_address/country_id', 'default_shipping', null, 'left')
297
+ ->joinAttribute('shipping_postcode', 'customer_address/postcode', 'default_shipping', null, 'left')
298
+ ->joinAttribute('shipping_telephone', 'customer_address/telephone', 'default_shipping', null, 'left')
299
+ ->joinAttribute('shipping_region', 'customer_address/region', 'default_shipping', null, 'left')
300
+ ->addAttributeToFilter('entity_id', array('in' => $customerIds));
301
+ $customer_log = Mage::getSingleton('core/resource')->getTableName('log_customer');
302
+ $sales_flat_order_grid = Mage::getSingleton('core/resource')->getTableName('sales_flat_order_grid');
303
+ $sales_flat_quote = Mage::getSingleton('core/resource')->getTableName('sales_flat_quote');
304
+ $sales_flat_order = Mage::getSingleton('core/resource')->getTableName('sales_flat_order');
305
+ $sales_flat_order_item = Mage::getSingleton('core/resource')->getTableName('sales_flat_order_item');
306
+ $catalog_category_product_index = Mage::getSingleton('core/resource')->getTableName('catalog_category_product');
307
+ $eav_attribute_option_value = Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value');
308
+ $catalog_product_entity_int = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int');
309
+ $eav_attribute = Mage::getSingleton('core/resource')->getTableName('eav_attribute');
310
+
311
+
312
+ // get the last login date from the log_customer table
313
+ $customerCollection->getSelect()->columns(
314
+ 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)")));
315
+
316
+ // customer order information
317
+ $alias = 'subselect';
318
+ $statuses = Mage::helper('ddg')->getWebsiteConfig(
319
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_DATA_FIELDS_STATUS, $websiteId
320
+ );
321
+ $statuses = explode(',', $statuses);
322
+ $subselect = Mage::getModel('Varien_Db_Select', Mage::getSingleton('core/resource')->getConnection('core_read'))
323
+ ->from($sales_flat_order_grid, array(
324
+ 'customer_id as s_customer_id',
325
+ 'sum(grand_total) as total_spend',
326
+ 'count(*) as number_of_orders',
327
+ 'avg(grand_total) as average_order_value',
328
+ )
329
+ )
330
+ ->where("status in (?)", $statuses)
331
+ ->group('customer_id')
332
+ ;
333
+ $customerCollection->getSelect()->columns(array(
334
+ '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)"),
335
+ '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)"),
336
+ '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)"),
337
+ '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)"),
338
+ 'first_category_id' => new Zend_Db_Expr(
339
+ "(
340
+ SELECT ccpi.category_id FROM $sales_flat_order as sfo
341
+ left join $sales_flat_order_item as sfoi on sfoi.order_id = sfo.entity_id
342
+ left join $catalog_category_product_index as ccpi on ccpi.product_id = sfoi.product_id
343
+ WHERE sfo.customer_id = e.entity_id
344
+ ORDER BY sfo.created_at ASC, sfoi.price DESC
345
+ LIMIT 1
346
+ )"
347
+ ),
348
+ 'last_category_id' => new Zend_Db_Expr(
349
+ "(
350
+ SELECT ccpi.category_id FROM $sales_flat_order as sfo
351
+ left join $sales_flat_order_item as sfoi on sfoi.order_id = sfo.entity_id
352
+ left join $catalog_category_product_index as ccpi on ccpi.product_id = sfoi.product_id
353
+ WHERE sfo.customer_id = e.entity_id
354
+ ORDER BY sfo.created_at DESC, sfoi.price DESC
355
+ LIMIT 1
356
+ )"
357
+ ),
358
+ 'product_id_for_first_brand' => new Zend_Db_Expr(
359
+ "(
360
+ SELECT sfoi.product_id FROM $sales_flat_order as sfo
361
+ left join $sales_flat_order_item as sfoi on sfoi.order_id = sfo.entity_id
362
+ WHERE sfo.customer_id = e.entity_id and sfoi.product_type = 'simple'
363
+ ORDER BY sfo.created_at ASC, sfoi.price DESC
364
+ LIMIT 1
365
+ )"
366
+ ),
367
+ 'product_id_for_last_brand' => new Zend_Db_Expr(
368
+ "(
369
+ SELECT sfoi.product_id FROM $sales_flat_order as sfo
370
+ left join $sales_flat_order_item as sfoi on sfoi.order_id = sfo.entity_id
371
+ WHERE sfo.customer_id = e.entity_id and sfoi.product_type = 'simple'
372
+ ORDER BY sfo.created_at DESC, sfoi.price DESC
373
+ LIMIT 1
374
+ )"
375
+ ),
376
+ 'week_day' => new Zend_Db_Expr(
377
+ "(
378
+ SELECT dayname(created_at) as week_day
379
+ FROM $sales_flat_order
380
+ WHERE customer_id = e.entity_id
381
+ GROUP BY week_day
382
+ HAVING COUNT(*) > 0
383
+ ORDER BY (COUNT(*)) DESC
384
+ LIMIT 1
385
+ )"
386
+ ),
387
+ 'month_day' => new Zend_Db_Expr(
388
+ "(
389
+ SELECT monthname(created_at) as month_day
390
+ FROM $sales_flat_order
391
+ WHERE customer_id = e.entity_id
392
+ GROUP BY month_day
393
+ HAVING COUNT(*) > 0
394
+ ORDER BY (COUNT(*)) DESC
395
+ LIMIT 1
396
+ )"
397
+ ),
398
+ 'most_category_id' => new Zend_Db_Expr(
399
+ "(
400
+ SELECT ccpi.category_id FROM $sales_flat_order as sfo
401
+ LEFT JOIN $sales_flat_order_item as sfoi on sfoi.order_id = sfo.entity_id
402
+ LEFT JOIN $catalog_category_product_index as ccpi on ccpi.product_id = sfoi.product_id
403
+ WHERE sfo.customer_id = e.entity_id AND ccpi.category_id is not null
404
+ GROUP BY category_id
405
+ HAVING COUNT(sfoi.product_id) > 0
406
+ ORDER BY COUNT(sfoi.product_id) DESC
407
+ LIMIT 1
408
+ )"
409
+ ),
410
+ 'most_brand' => new Zend_Db_Expr(
411
+ "(
412
+ SELECT eaov.value from $sales_flat_order sfo
413
+ LEFT JOIN $sales_flat_order_item as sfoi on sfoi.order_id = sfo.entity_id
414
+ LEFT JOIN $catalog_product_entity_int pei on pei.entity_id = sfoi.product_id
415
+ LEFT JOIN $eav_attribute ea ON pei.attribute_id = ea.attribute_id
416
+ LEFT JOIN $eav_attribute_option_value as eaov on pei.value = eaov.option_id
417
+ WHERE sfo.customer_id = e.entity_id AND ea.attribute_code = 'manufacturer' AND eaov.value is not null
418
+ GROUP BY eaov.value
419
+ HAVING count(*) > 0
420
+ ORDER BY count(*) DESC
421
+ LIMIT 1
422
+ )"
423
+ ),
424
+ )
425
+ );
426
+ $customerCollection->getSelect()
427
+ ->joinLeft(array($alias => $subselect), "{$alias}.s_customer_id = e.entity_id");
428
+ return $customerCollection;
429
+ }
430
+ }
app/code/community/Dotdigitalgroup/Email/Model/Apiconnector/Customer.php ADDED
@@ -0,0 +1,935 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ private $attribute_check = false;
28
+
29
+ /**
30
+ * constructor, mapping hash to map.
31
+ *
32
+ * @param $mappingHash
33
+ */
34
+ public function __construct( $mappingHash)
35
+ {
36
+ $this->setMappigHash($mappingHash);
37
+ }
38
+
39
+ /**
40
+ * Set key value data.
41
+ *
42
+ * @param $data
43
+ */
44
+ public function setData($data)
45
+ {
46
+ $this->customerData[] = $data;
47
+ }
48
+
49
+ /**
50
+ * Set customer data.
51
+ *
52
+ * @param Mage_Customer_Model_Customer $customer
53
+ */
54
+ public function setCustomerData(Mage_Customer_Model_Customer $customer)
55
+ {
56
+ $this->customer = $customer;
57
+ $this->setReviewCollection();
58
+ $website = $customer->getStore()->getWebsite();
59
+
60
+ if ($website && Mage::helper('ddg')->isSweetToothToGo($website))
61
+ $this->setRewardCustomer($customer);
62
+
63
+ foreach ($this->getMappingHash() as $key => $field) {
64
+
65
+ /**
66
+ * call user function based on the attribute mapped.
67
+ */
68
+ $function = 'get';
69
+ $exploded = explode('_', $key);
70
+ foreach ($exploded as $one) {
71
+ $function .= ucfirst($one);
72
+ }
73
+ try{
74
+ $value = call_user_func(array('self', $function));
75
+ $this->customerData[$key] = $value;
76
+ }catch (Exception $e){
77
+ Mage::logException($e);
78
+ }
79
+ }
80
+ }
81
+
82
+ public function setReviewCollection()
83
+ {
84
+ $customer_id = $this->customer->getId();
85
+ $collection = Mage::getModel('review/review')->getCollection()
86
+ ->addCustomerFilter($customer_id)
87
+ ->setOrder('review_id','DESC');
88
+ $this->reviewCollection = $collection;
89
+ }
90
+
91
+ public function getReviewCount()
92
+ {
93
+ return count($this->reviewCollection);
94
+ }
95
+
96
+ public function getLastReviewDate(){
97
+ if(count($this->reviewCollection))
98
+ return $this->reviewCollection->getFirstItem()->getCreatedAt();
99
+ return '';
100
+ }
101
+
102
+ /**
103
+ * Set reward customer
104
+ *
105
+ * @param Mage_Customer_Model_Customer $customer
106
+ */
107
+ public function setRewardCustomer(Mage_Customer_Model_Customer $customer)
108
+ {
109
+ //get tbt reward customer
110
+ $tbt_reward = Mage::getModel('rewards/customer')->getRewardsCustomer($customer);
111
+ $this->rewardCustomer = $tbt_reward;
112
+
113
+ //get transfers collection from tbt reward. only active and order by last updated.
114
+ $lastTransfers = $tbt_reward->getTransfers()
115
+ ->selectOnlyActive()
116
+ ->addOrder('last_update_ts', Varien_Data_Collection::SORT_ORDER_DESC);
117
+
118
+ $spent = $earn = null;
119
+
120
+ foreach($lastTransfers as $transfer) {
121
+ // if transfer quantity is greater then 0 then this is last points earned date. keep checking until earn is not null
122
+ if(is_null($earn) && $transfer->getQuantity() > 0){
123
+ $earn = $transfer->getEffectiveStart();
124
+ }
125
+ // id transfer quantity is less then 0 then this is last points spent date. keep checking until spent is not null
126
+ else if(is_null($spent) && $transfer->getQuantity() < 0) {
127
+ $spent = $transfer->getEffectiveStart();
128
+ }
129
+ // break if both spent and earn are not null (a value has been assigned)
130
+ if(!is_null($spent) && !is_null($earn)) {
131
+ break;
132
+ }
133
+ }
134
+
135
+ // if earn is not null (has a value) then assign the value to property
136
+ if($earn)
137
+ $this->rewardLastEarned = $earn;
138
+ // if spent is not null (has a value) then assign the value to property
139
+ if($spent)
140
+ $this->rewardLastSpent = $spent;
141
+
142
+ $tbt_expiry = Mage::getSingleton('rewards/expiry')
143
+ ->getExpiryDate($tbt_reward);
144
+
145
+ // if there is an expiry (has a value) then assign the value to property
146
+ if($tbt_expiry)
147
+ $this->rewardExpiry = $tbt_expiry;
148
+ }
149
+
150
+ /**
151
+ * get customer id.
152
+ *
153
+ * @return mixed
154
+ */
155
+ public function getCustomerId()
156
+ {
157
+ return $this->customer->getId();
158
+ }
159
+
160
+ /**
161
+ * get first name.
162
+ *
163
+ * @return mixed
164
+ */
165
+ public function getFirstname(){
166
+ return $this->customer->getFirstname();
167
+ }
168
+
169
+ /**
170
+ * get last name.
171
+ *
172
+ * @return mixed
173
+ */
174
+ public function getLastname()
175
+ {
176
+ return $this->customer->getLastname();
177
+ }
178
+
179
+ /**
180
+ * get date of birth.
181
+ *
182
+ * @return mixed
183
+ */
184
+ public function getDob()
185
+ {
186
+ return $this->customer->getDob();
187
+ }
188
+
189
+ /**
190
+ * get customer gender.
191
+ *
192
+ * @return bool|string
193
+ */
194
+ public function getGender()
195
+ {
196
+ return $this->_getCustomerGender();
197
+ }
198
+
199
+ /**
200
+ * get customer prefix.
201
+ *
202
+ * @return mixed
203
+ */
204
+ public function getPrefix()
205
+ {
206
+ return $this->customer->getPrefix();
207
+ }
208
+
209
+ /**
210
+ * get customer suffix.
211
+ *
212
+ * @return mixed
213
+ */
214
+ public function getSuffix()
215
+ {
216
+ return $this->customer->getSuffix();
217
+ }
218
+
219
+ /**
220
+ * get website name.
221
+ *
222
+ * @return string
223
+ */
224
+ public function getWebsiteName()
225
+ {
226
+ return $this->_getWebsiteName();
227
+ }
228
+
229
+ /**
230
+ * get store name.
231
+ *
232
+ * @return null|string
233
+ */
234
+ public function getStoreName()
235
+ {
236
+ return $this->_getStoreName();
237
+ }
238
+
239
+ /**
240
+ * get customer created at date.
241
+ *
242
+ * @return mixed
243
+ */
244
+ public function getCreatedAt()
245
+ {
246
+ return $this->customer->getCreatedAt();
247
+ }
248
+
249
+ /**
250
+ * get customer last logged in date.
251
+ *
252
+ * @return mixed
253
+ */
254
+ public function getLastLoggedDate()
255
+ {
256
+ return $this->customer->getLastLoggedDate();
257
+ }
258
+
259
+ /**
260
+ * get cutomer group.
261
+ *
262
+ * @return string
263
+ */
264
+ public function getCustomerGroup()
265
+ {
266
+ return $this->_getCustomerGroup();
267
+ }
268
+
269
+ /**
270
+ * get billing address line 1.
271
+ *
272
+ * @return string
273
+ */
274
+ public function getBillingAddress1()
275
+ {
276
+ return $this->_getStreet($this->customer->getBillingStreet(), 1);
277
+ }
278
+
279
+ /**
280
+ * get billing address line 2.
281
+ *
282
+ * @return string
283
+ */
284
+ public function getBillingAddress2()
285
+ {
286
+ return $this->_getStreet($this->customer->getBillingStreet(), 2);
287
+ }
288
+
289
+ /**
290
+ * get billing city.
291
+ *
292
+ * @return mixed
293
+ */
294
+ public function getBillingCity()
295
+ {
296
+ return $this->customer->getBillingCity();
297
+ }
298
+
299
+ /**
300
+ * get billing country.
301
+ *
302
+ * @return mixed
303
+ */
304
+ public function getBillingCountry()
305
+ {
306
+ return $this->customer->getBillingCountryCode();
307
+ }
308
+
309
+ /**
310
+ * get billing state.
311
+ *
312
+ * @return mixed
313
+ */
314
+ public function getBillingState()
315
+ {
316
+ return $this->customer->getBillingRegion();
317
+ }
318
+
319
+ /**
320
+ * get billing postcode.
321
+ *
322
+ * @return mixed
323
+ */
324
+ public function getBillingPostcode()
325
+ {
326
+ return $this->customer->getBillingPostcode();
327
+ }
328
+
329
+ /**
330
+ * get billing phone.
331
+ *
332
+ * @return mixed
333
+ */
334
+ public function getBillingTelephone()
335
+ {
336
+ return $this->customer->getBillingTelephone();
337
+ }
338
+
339
+ /**
340
+ * get delivery address line 1.
341
+ *
342
+ * @return string
343
+ */
344
+ public function getDeliveryAddress1()
345
+ {
346
+ return $this->_getStreet($this->customer->getShippingStreet(), 1);
347
+ }
348
+
349
+ /**
350
+ * get delivery addrss line 2.
351
+ *
352
+ * @return string
353
+ */
354
+ public function getDeliveryAddress2()
355
+ {
356
+ return $this->_getStreet($this->customer->getShippingStreet(), 2);
357
+ }
358
+
359
+ /**
360
+ * get delivery city.
361
+ *
362
+ * @return mixed
363
+ */
364
+ public function getDeliveryCity()
365
+ {
366
+ return $this->customer->getShippingCity();
367
+ }
368
+
369
+ /**
370
+ * get delivery country.
371
+ *
372
+ * @return mixed
373
+ */
374
+ public function getDeliveryCountry(){
375
+ return $this->customer->getShippingCountryCode();
376
+ }
377
+
378
+ /**
379
+ * get delivery state.
380
+ *
381
+ * @return mixed
382
+ */
383
+ public function getDeliveryState()
384
+ {
385
+ return $this->customer->getShippingRegion();
386
+ }
387
+
388
+ /**
389
+ * get delivery postcode.
390
+ *
391
+ * @return mixed
392
+ */
393
+ public function getDeliveryPostcode()
394
+ {
395
+ return $this->customer->getShippingPostcode();
396
+ }
397
+
398
+ /**
399
+ * get delivery phone.
400
+ *
401
+ * @return mixed
402
+ */
403
+ public function getDeliveryTelephone(){
404
+ return $this->customer->getShippingTelephone();
405
+ }
406
+
407
+ /**
408
+ * get numbser of orders.
409
+ *
410
+ * @return mixed
411
+ */
412
+ public function getNumberOfOrders()
413
+ {
414
+ return $this->customer->getNumberOfOrders();
415
+ }
416
+
417
+ /**
418
+ * get average order value.
419
+ *
420
+ * @return mixed
421
+ */
422
+ public function getAverageOrderValue()
423
+ {
424
+ return $this->customer->getAverageOrderValue();
425
+ }
426
+
427
+ /**
428
+ * get total spend.
429
+ *
430
+ * @return mixed
431
+ */
432
+ public function getTotalSpend()
433
+ {
434
+ return $this->customer->getTotalSpend();
435
+ }
436
+
437
+ /**
438
+ * get last order date.
439
+ *
440
+ * @return mixed
441
+ */
442
+ public function getLastOrderDate()
443
+ {
444
+ return $this->customer->getLastOrderDate();
445
+ }
446
+
447
+ /**
448
+ * get last order id.
449
+ *
450
+ * @return mixed
451
+ */
452
+ public function getLastOrderId()
453
+ {
454
+ return $this->customer->getLastOrderId();
455
+ }
456
+
457
+ /**
458
+ * get last quote id.
459
+ *
460
+ * @return mixed
461
+ */
462
+ public function getLastQuoteId()
463
+ {
464
+ return $this->customer->getLastQuoteId();
465
+ }
466
+
467
+ /**
468
+ * get cutomer id.
469
+ *
470
+ * @return mixed
471
+ */
472
+ public function getId()
473
+ {
474
+ return $this->customer->getId();
475
+ }
476
+
477
+ /**
478
+ * get customer title.
479
+ *
480
+ * @return mixed
481
+ */
482
+ public function getTitle()
483
+ {
484
+ return $this->customer->getPrefix();
485
+ }
486
+
487
+ /**
488
+ * get total refund value.
489
+ *
490
+ * @return float|int
491
+ */
492
+ public function getTotalRefund()
493
+ {
494
+ $orders = Mage::getResourceModel('sales/order_collection')
495
+ ->addAttributeToFilter('customer_id', $this->customer->getId())
496
+ ;
497
+ $totalRefunded = 0;
498
+ foreach ($orders as $order) {
499
+ $refunded = $order->getTotalRefunded();
500
+ $totalRefunded += $refunded;
501
+ }
502
+
503
+ return $totalRefunded;
504
+ }
505
+
506
+ /**
507
+ * export to CSV.
508
+ *
509
+ * @return mixed
510
+ */
511
+ public function toCSVArray()
512
+ {
513
+ $result = $this->customerData;
514
+ return $result;
515
+ }
516
+
517
+ /**
518
+ * customer gender.
519
+ *
520
+ * @return bool|string
521
+ * @throws Mage_Core_Exception
522
+ */
523
+ private function _getCustomerGender()
524
+ {
525
+ $genderId = $this->customer->getGender();
526
+ if (is_numeric($genderId)) {
527
+ $gender = Mage::getResourceModel('customer/customer')
528
+ ->getAttribute('gender')
529
+ ->getSource()
530
+ ->getOptionText($genderId)
531
+ ;
532
+ return $gender;
533
+ }
534
+
535
+ return '';
536
+ }
537
+
538
+ private function _getStreet($street, $line){
539
+ $street = explode("\n", $street);
540
+ if(isset($street[$line - 1]))
541
+ return $street[$line - 1];
542
+ return '';
543
+ }
544
+
545
+ private function _getWebsiteName(){
546
+ $websiteId = $this->customer->getWebsiteId();
547
+ $website = Mage::app()->getWebsite($websiteId);
548
+ if($website)
549
+ return $website->getName();
550
+
551
+ return '';
552
+ }
553
+
554
+ private function _getStoreName()
555
+ {
556
+ $storeId = $this->customer->getStoreId();
557
+ $store = Mage::app()->getStore($storeId);
558
+ if($store)
559
+ return $store->getName();
560
+
561
+ return '';
562
+ }
563
+
564
+ /**
565
+ * @param mixed $mapping_hash
566
+ */
567
+ public function setMappingHash($mapping_hash)
568
+ {
569
+ $this->_mapping_hash = $mapping_hash;
570
+ }
571
+
572
+ /**
573
+ * @return mixed
574
+ */
575
+ public function getMappingHash()
576
+ {
577
+ return $this->_mapping_hash;
578
+ }
579
+
580
+ private function _getCustomerGroup(){
581
+ $groupId = $this->customer->getGroupId();
582
+ $group = Mage::getModel('customer/group')->load($groupId);
583
+ if($group){
584
+ return $group->getCode();
585
+ }
586
+ return '';
587
+ }
588
+
589
+ /**
590
+ * mapping hash value.
591
+ *
592
+ * @param $value
593
+ *
594
+ * @return $this
595
+ */
596
+ public function setMappigHash($value)
597
+ {
598
+ $this->_mapping_hash = $value;
599
+ return $this;
600
+ }
601
+
602
+ public function getRewardReferralUrl()
603
+ {
604
+ if(Mage::helper('ddg')->isSweetToothToGo($this->customer->getStore()->getWebsite()))
605
+ return (string) Mage::helper('rewardsref/url')->getUrl($this->customer);
606
+
607
+ return '';
608
+ }
609
+
610
+ public function getRewardPointBalance()
611
+ {
612
+ return $this->cleanString($this->rewardCustomer->getPointsSummary());
613
+ }
614
+
615
+ public function getRewardPointPending()
616
+ {
617
+ return $this->cleanString($this->rewardCustomer->getPendingPointsSummary());
618
+ }
619
+
620
+ public function getRewardPointPendingTime()
621
+ {
622
+ return $this->cleanString($this->rewardCustomer->getPendingTimePointsSummary());
623
+ }
624
+
625
+ public function getRewardPointOnHold()
626
+ {
627
+ return $this->cleanString($this->rewardCustomer->getOnHoldPointsSummary());
628
+ }
629
+
630
+ public function getRewardPointExpiration()
631
+ {
632
+ if($this->rewardExpiry != "")
633
+ return Mage::getModel('core/date')->date('Y/m/d', strtotime($this->rewardExpiry));
634
+ return $this->rewardExpiry;
635
+ }
636
+
637
+ public function getRewardPointLastSpent()
638
+ {
639
+ return $this->rewardLastSpent;
640
+ }
641
+
642
+ public function getRewardPointLastEarn()
643
+ {
644
+ return $this->rewardLastEarned;
645
+ }
646
+
647
+ public function cleanString($string)
648
+ {
649
+ $cleanedString = preg_replace("/[^0-9]/","",$string);
650
+ if($cleanedString != "")
651
+ return (int) number_format($cleanedString, 0, '.', '');
652
+ return 0;
653
+ }
654
+
655
+ public function getSubscriberStatus()
656
+ {
657
+ $subscriber = Mage::getModel('newsletter/subscriber')->loadByCustomer($this->customer);
658
+ if($subscriber->getCustomerId())
659
+ return $this->subscriber_status[$subscriber->getSubscriberStatus()];
660
+ }
661
+
662
+ /**
663
+ * Reward points balance.
664
+ * @return int
665
+ */
666
+ public function getRewardPoints() {
667
+ if (!$this->reward)
668
+ $this->_setReward();
669
+
670
+ if($this->reward !== true){
671
+ return $this->reward->getPointsBalance();
672
+ }
673
+ return '';
674
+ }
675
+
676
+ /**
677
+ * Currency amount points.
678
+ * @return mixed
679
+ */
680
+ public function getRewardAmount() {
681
+ if (!$this->reward)
682
+ $this->_setReward();
683
+
684
+ if($this->reward !== true){
685
+ return $this->reward->getCurrencyAmount();
686
+ }
687
+ return '';
688
+ }
689
+
690
+ /**
691
+ * Expiration date to use the points.
692
+ * @return string
693
+ */
694
+ public function getExpirationDate()
695
+ {
696
+ //set reward for later use
697
+ if (!$this->reward)
698
+ $this->_setReward();
699
+
700
+ if($this->reward !== true){
701
+ $expiredAt = $this->reward->getExpirationDate();
702
+
703
+ if ($expiredAt) {
704
+ $date = Mage::helper('core')->formatDate($expiredAt, 'short', true);
705
+ } else {
706
+ $date = '';
707
+ }
708
+ return $date;
709
+ }
710
+
711
+ return '';
712
+ }
713
+
714
+
715
+ private function _setReward() {
716
+ if (Mage::getModel('enterprise_reward/reward_history')){
717
+ $collection = Mage::getModel('enterprise_reward/reward_history')->getCollection()
718
+ ->addCustomerFilter($this->customer->getId())
719
+ ->addWebsiteFilter($this->customer->getWebsiteId())
720
+ ->setExpiryConfig(Mage::helper('enterprise_reward')->getExpiryConfig())
721
+ ->addExpirationDate($this->customer->getWebsiteId())
722
+ ->skipExpiredDuplicates()
723
+ ->setDefaultOrder();
724
+
725
+ $item = $collection->setPageSize(1)->setCurPage(1)->getFirstItem();
726
+
727
+ $this->reward = $item;
728
+ }
729
+ else
730
+ $this->reward = true;
731
+ }
732
+
733
+
734
+ /**
735
+ * Customer segments id.
736
+ * @return string
737
+ */
738
+ public function getCustomerSegments()
739
+ {
740
+ $collection = Mage::getModel('ddg_automation/contact')->getCollection()
741
+ ->addFieldToFilter('customer_id', $this->getCustomerId())
742
+ ->addFieldToFilter('website_id', $this->customer->getWebsiteId());
743
+
744
+ $item = $collection->setPageSize(1)->setCurPage(1)->getFirstItem();
745
+
746
+ if ($item)
747
+ return $item->getSegmentIds();
748
+
749
+ return '';
750
+ }
751
+
752
+
753
+
754
+ /**
755
+ * Last used reward points.
756
+ * @return mixed
757
+ */
758
+ public function getLastUsedDate()
759
+ {
760
+ if (Mage::getModel('enterprise_reward/reward_history')) {
761
+ //last used from the reward history based on the points delta used
762
+ $collection = Mage::getModel('enterprise_reward/reward_history')->getCollection()
763
+ ->addCustomerFilter($this->customer->getId())
764
+ ->addWebsiteFilter($this->customer->getWebsiteId())
765
+ ->addFieldToFilter('points_delta', array('lt' => 0))
766
+ ->setDefaultOrder();
767
+
768
+ $item = $collection->setPageSize(1)->setCurPage(1)->getFirstItem();
769
+ $lastUsed = $item->getCreatedAt();
770
+
771
+ //for any valid date
772
+ if ($lastUsed)
773
+ return $date = Mage::helper('core')->formatDate($lastUsed, 'short', true);
774
+ }
775
+ return '';
776
+ }
777
+
778
+
779
+
780
+ /**
781
+ * get most purchased category
782
+ *
783
+ * @return string
784
+ */
785
+ public function getMostPurCategory()
786
+ {
787
+ $id = $this->customer->getMostCategoryId();
788
+ if($id){
789
+ return Mage::getModel('catalog/category')
790
+ ->load($id)
791
+ ->setStoreId($this->customer->getStoreId())
792
+ ->getName();
793
+ }
794
+ return "";
795
+ }
796
+
797
+ /**
798
+ * get most purchased brand
799
+ *
800
+ * @return string
801
+ */
802
+ public function getMostPurBrand()
803
+ {
804
+ $brand = $this->customer->getMostBrand();
805
+ if($brand)
806
+ return $brand;
807
+ return "";
808
+ }
809
+
810
+ /**
811
+ * get most frequent day of purchase
812
+ *
813
+ * @return string
814
+ */
815
+ public function getMostFreqPurDay()
816
+ {
817
+ $day = $this->customer->getWeekDay();
818
+ if($day)
819
+ return $day;
820
+ return "";
821
+ }
822
+
823
+ /**
824
+ * get most frequent month of purchase
825
+ *
826
+ * @return string
827
+ */
828
+ public function getMostFreqPurMon()
829
+ {
830
+ $month = $this->customer->getMonthDay();
831
+ if($month)
832
+ return $month;
833
+ return "";
834
+ }
835
+
836
+ /**
837
+ * get first purchased category
838
+ *
839
+ * @return string
840
+ */
841
+ public function getFirstCategoryPur()
842
+ {
843
+ $id = $this->customer->getFirstCategoryId();
844
+ if($id){
845
+ return Mage::getModel('catalog/category')
846
+ ->load($id)
847
+ ->setStoreId($this->customer->getStoreId())
848
+ ->getName();
849
+ }
850
+ return "";
851
+ }
852
+
853
+ /**
854
+ * get last purchased category
855
+ *
856
+ * @return string
857
+ */
858
+ public function getLastCategoryPur()
859
+ {
860
+ $id = $this->customer->getLastCategoryId();
861
+ if($id){
862
+ return Mage::getModel('catalog/category')
863
+ ->setStoreId($this->customer->getStoreId())
864
+ ->load($id)
865
+ ->getName();
866
+ }
867
+ return "";
868
+ }
869
+
870
+ /**
871
+ * get first purchased brand
872
+ *
873
+ * @return string
874
+ */
875
+ public function getFirstBrandPur()
876
+ {
877
+ if(!$this->attribute_check){
878
+ $attribute = Mage::getModel('catalog/resource_eav_attribute')
879
+ ->loadByCode('catalog_product', 'manufacturer');
880
+ if($attribute->getId())
881
+ $this->attribute_check = true;
882
+ }
883
+
884
+ if($this->attribute_check){
885
+ $id = $this->customer->getProductIdForFirstBrand();
886
+ if($id){
887
+ $brand = Mage::getModel('catalog/product')
888
+ ->setStoreId($this->customer->getStoreId())
889
+ ->load($id)
890
+ ->getAttributeText('manufacturer');
891
+ if($brand)
892
+ return $brand;
893
+ }
894
+ }
895
+ return "";
896
+ }
897
+
898
+ /**
899
+ * get last purchased brand
900
+ *
901
+ * @return string
902
+ */
903
+ public function getLastBrandPur()
904
+ {
905
+ if(!$this->attribute_check){
906
+ $attribute = Mage::getModel('catalog/resource_eav_attribute')
907
+ ->loadByCode('catalog_product', 'manufacturer');
908
+ if($attribute->getId())
909
+ $this->attribute_check = true;
910
+ }
911
+
912
+ if($this->attribute_check){
913
+ $id = $this->customer->getProductIdForLastBrand();
914
+ if($id){
915
+ $brand = Mage::getModel('catalog/product')
916
+ ->setStoreId($this->customer->getStoreId())
917
+ ->load($id)
918
+ ->getAttributeText('manufacturer');
919
+ if($brand)
920
+ return $brand;
921
+ }
922
+ return "";
923
+ }
924
+ }
925
+
926
+ /**
927
+ * get last increment id
928
+ *
929
+ * @return mixed
930
+ */
931
+ public function getLastIncrementId()
932
+ {
933
+ return $this->customer->getLastIncrementId();
934
+ }
935
+ }
app/code/community/Dotdigitalgroup/Email/Model/Apiconnector/Test.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Model_Apiconnector_Test extends Dotdigitalgroup_Email_Model_Apiconnector_Client
3
+ {
4
+ /**
5
+ * Validate apiuser on save.
6
+ *
7
+ * @param $apiUsername
8
+ * @param $apiPassword
9
+ *
10
+ * @return bool|mixed
11
+ */
12
+ public function validate($apiUsername, $apiPassword)
13
+ {
14
+ if ($apiUsername && $apiPassword) {
15
+ $this->setApiUsername($apiUsername)
16
+ ->setApiPassword($apiPassword);
17
+ $accountInfo = $this->getAccountInfo();
18
+ if (isset($accountInfo->message)) {
19
+ Mage::getSingleton('adminhtml/session')->addError($accountInfo->message);
20
+ Mage::helper('ddg')->log('VALIDATION ERROR : ' . $accountInfo->message);
21
+ return false;
22
+ }
23
+ return $accountInfo;
24
+ }
25
+ return false;
26
+ }
27
+ /**
28
+ * Ajax validate api user.
29
+ *
30
+ * @param $apiUsername
31
+ * @param $apiPassword
32
+ *
33
+ * @return bool|string
34
+ */
35
+ public function ajaxvalidate($apiUsername, $apiPassword)
36
+ {
37
+ if ($apiUsername && $apiPassword) {
38
+ $message = 'Credentials Valid.';
39
+ $this->setApiUsername($apiUsername)
40
+ ->setApiPassword($apiPassword);
41
+ $response = $this->getAccountInfo();
42
+ if (isset($response->message)) {
43
+ $message = 'API Username And Password Do Not Match!';
44
+ Mage::helper('ddg')->log($message);
45
+ }
46
+ return $message;
47
+ }
48
+ return false;
49
+ }
50
+ }
app/code/community/Dotdigitalgroup/Email/Model/Automation.php ADDED
@@ -0,0 +1,221 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Model_Automation extends Mage_Core_Model_Abstract
3
+ {
4
+ const AUTOMATION_TYPE_NEW_CUSTOMER = 'customer_automation';
5
+ const AUTOMATION_TYPE_NEW_SUBSCRIBER = 'subscriber_automation';
6
+ const AUTOMATION_TYPE_NEW_ORDER = 'order_automation';
7
+ const AUTOMATION_TYPE_NEW_GUEST_ORDER = 'guest_order_automation';
8
+ const AUTOMATION_TYPE_NEW_REVIEW = 'review_automation';
9
+ const AUTOMATION_TYPE_NEW_WISHLIST = 'wishlist_automation';
10
+ const AUTOMATION_STATUS_PENDING = 'pending';
11
+ //automation enrolment limit
12
+ public $limit = 100;
13
+ public $email;
14
+ public $typeId;
15
+ public $websiteId;
16
+ public $storeName;
17
+ public $programId;
18
+ public $programStatus = 'Active';
19
+ public $programMessage;
20
+ public $automationType;
21
+ /**
22
+ * constructor
23
+ */
24
+ public function _construct()
25
+ {
26
+ parent::_construct();
27
+ $this->_init('ddg_automation/automation');
28
+ }
29
+ /**
30
+ * @return $this|Mage_Core_Model_Abstract
31
+ */
32
+ protected function _beforeSave()
33
+ {
34
+ parent::_beforeSave();
35
+ $now = Mage::getSingleton('core/date')->gmtDate();
36
+ if ($this->isObjectNew()) {
37
+ $this->setCreatedAt($now);
38
+ } else {
39
+ $this->setUpdatedAt($now);
40
+ }
41
+ return $this;
42
+ }
43
+ public function enrollment()
44
+ {
45
+ //automation statuses to filter
46
+ $automationCollection = $this->getCollection()
47
+ ->addFieldToSelect( 'automation_type' )
48
+ ->addFieldToFilter( 'enrolment_status', self::AUTOMATION_STATUS_PENDING );
49
+ $automationCollection->getSelect()->group( 'automation_type' );
50
+ //active types
51
+ $automationTypes = $automationCollection->getColumnValues( 'automation_type' );
52
+ //send the campaign by each types
53
+ foreach ( $automationTypes as $type ) {
54
+ $contacts = array();
55
+ //reset the collection
56
+ $automationCollection->clear();
57
+ $automationCollection = $this->getCollection()
58
+ ->addFieldToFilter( 'enrolment_status', self::AUTOMATION_STATUS_PENDING )
59
+ ->addFieldToFilter( 'automation_type', $type );
60
+ //limit because of the each contact request to get the id
61
+ $automationCollection->getSelect()->limit( $this->limit );
62
+ foreach ( $automationCollection as $automation ) {
63
+ $type = $automation->getAutomationType();
64
+ //customerid, subscriberid, wishlistid..
65
+ $email = $automation->getEmail();
66
+ $this->typeId = $automation->getTypeId();
67
+ $this->websiteId = $automation->getWebsiteId();
68
+ $this->programId = $automation->getProgramId();
69
+ $this->storeName = $automation->getStoreName();
70
+ $contactId = Mage::helper( 'ddg' )->getContactId( $email, $this->websiteId );
71
+ //contact id is valid, can update datafields
72
+ if ( $contactId ) {
73
+ //need to update datafields
74
+ $this->updateDatafieldsByType( $this->automationType, $email );
75
+ $contacts[ $automation->getId() ] = $contactId;
76
+ } else {
77
+ // the contact is suppressed or the request failed
78
+ $automation->setStatus('Suppressed')->save();
79
+ }
80
+ }
81
+ //only for subscribed contacts
82
+ if ( ! empty( $contacts ) && $type != '' && $this->_checkCampignEnrolmentActive( $this->programId ) ) {
83
+ $result = $this->sendContactsToAutomation( array_values( $contacts ) );
84
+ //check for error message
85
+ if ( isset( $result->message ) ) {
86
+ $this->programStatus = 'Failed';
87
+ $this->programMessage = $result->message;
88
+ }
89
+ //program is not active
90
+ } elseif ( $this->programMessage == 'Error: ERROR_PROGRAM_NOT_ACTIVE ' ) {
91
+ $this->programStatus = 'Deactivated';
92
+ }
93
+ //update contacts with the new status, and log the error message if failes
94
+ $num = $this->getResource()->updateContacts($contacts, $this->programStatus, $this->programMessage);
95
+ if ($num)
96
+ Mage::helper('ddg')->log('Automation type : ' . $type . ', updated no : ' . $num);
97
+ }
98
+ }
99
+ /**
100
+ * update single contact datafields for this automation type.
101
+ *
102
+ * @param $type
103
+ */
104
+ public function updateDatafieldsByType($type, $email )
105
+ {
106
+ switch($type) {
107
+ case self::AUTOMATION_TYPE_NEW_CUSTOMER :
108
+ $this->_updateDefaultDatafields($email);
109
+ break;
110
+ case self::AUTOMATION_TYPE_NEW_SUBSCRIBER :
111
+ $this->_updateDefaultDatafields($email);
112
+ break;
113
+ case self::AUTOMATION_TYPE_NEW_ORDER :
114
+ $this->_updateNewOrderDatafields($email);
115
+ break;
116
+ case self::AUTOMATION_TYPE_NEW_GUEST_ORDER:
117
+ $this->_updateNewOrderDatafields($email);
118
+ break;
119
+ case self::AUTOMATION_TYPE_NEW_REVIEW :
120
+ $this->_updateNewOrderDatafields($email);
121
+ break;
122
+ case self::AUTOMATION_TYPE_NEW_WISHLIST:
123
+ $this->_updateDefaultDatafields($email);
124
+ break;
125
+ default:
126
+ $this->_updateDefaultDatafields($email);
127
+ break;
128
+ }
129
+ }
130
+ private function _updateDefaultDatafields($email)
131
+ {
132
+ $website = Mage::app()->getWebsite($this->websiteId);
133
+ Mage::helper('ddg')->updateDataFields($email, $website, $this->storeName);
134
+ }
135
+ private function _updateNewOrderDatafields($email)
136
+ {
137
+ $website = Mage::app()->getWebsite($this->websiteId);
138
+ $order = Mage::getModel('sales/order')->load($this->typeId);
139
+ //data fields
140
+ if($last_order_id = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_LAST_ORDER_ID)){
141
+ $data[] = array(
142
+ 'Key' => $last_order_id,
143
+ 'Value' => $order->getId()
144
+ );
145
+ }
146
+ if($order_increment_id = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_LAST_ORDER_INCREMENT_ID)){
147
+ $data[] = array(
148
+ 'Key' => $order_increment_id,
149
+ 'Value' => $order->getIncrementId()
150
+ );
151
+ }
152
+ if($store_name = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_STORE_NAME)){
153
+ $data[] = array(
154
+ 'Key' => $store_name,
155
+ 'Value' => $this->storeName
156
+ );
157
+ }
158
+ if($website_name = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_WEBSITE_NAME)){
159
+ $data[] = array(
160
+ 'Key' => $website_name,
161
+ 'Value' => $website->getName()
162
+ );
163
+ }
164
+ if($last_order_date = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_LAST_ORDER_DATE)){
165
+ $data[] = array(
166
+ 'Key' => $last_order_date,
167
+ 'Value' => $order->getCreatedAt()
168
+ );
169
+ }
170
+ if(($customer_id = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_ID)) && $order->getCustomerId()){
171
+ $data[] = array(
172
+ 'Key' => $customer_id,
173
+ 'Value' => $order->getCustomerId()
174
+ );
175
+ }
176
+ if(! empty($data)){
177
+ //update data fields
178
+ $client = Mage::helper('ddg')->getWebsiteApiClient($website);
179
+ $client->updateContactDatafieldsByEmail($order->getCustomerEmail(), $data);
180
+ }
181
+ }
182
+ /**
183
+ * Program check if is valid and active.
184
+ * @param $programId
185
+ *
186
+ * @return bool
187
+ */
188
+ private function _checkCampignEnrolmentActive($programId)
189
+ {
190
+ //program is not set
191
+ if (!$programId)
192
+ return false;
193
+ $client = Mage::helper('ddg')->getWebsiteApiClient($this->websiteId);
194
+ $program = $client->getProgramById($programId);
195
+ //program status
196
+ if (isset($program->status))
197
+ $this->programStatus = $program->status;
198
+ if (isset($program->status) && $program->status == 'Active') {
199
+ return true;
200
+ }
201
+ return false;
202
+ }
203
+ /**
204
+ * Enrol contacts for a program.
205
+ * @param $contacts
206
+ *
207
+ * @return null
208
+ */
209
+ public function sendContactsToAutomation($contacts)
210
+ {
211
+ $client = Mage::helper('ddg')->getWebsiteApiClient($this->websiteId);
212
+ $data = array(
213
+ 'Contacts' => $contacts,
214
+ 'ProgramId' => $this->programId,
215
+ 'AddressBooks' => array()
216
+ );
217
+ //api add contact to automation enrolment
218
+ $result = $client->postProgramsEnrolments( $data );
219
+ return $result;
220
+ }
221
+ }
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/Catalog.php ADDED
@@ -0,0 +1,420 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Catalog extends Mage_Core_Model_Abstract
4
+ {
5
+ private $_start;
6
+ private $_countProducts = 0;
7
+ private $_productIds;
8
+
9
+ /**
10
+ * constructor
11
+ */
12
+ public function _construct()
13
+ {
14
+ parent::_construct();
15
+ $this->_init('ddg_automation/catalog');
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
+ * catalog sync
35
+ *
36
+ * @return array
37
+ */
38
+ public function sync()
39
+ {
40
+ $response = array('success' => true, 'message' => '');
41
+ $helper = Mage::helper('ddg');
42
+ $this->_start = microtime(true);
43
+ $importer = Mage::getModel('ddg_automation/importer');
44
+
45
+ //resource allocation
46
+ $helper->allowResourceFullExecution();
47
+ $enabled = Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED);
48
+ $sync = Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_CATALOG_ENABLED);
49
+
50
+ if ($enabled && $sync) {
51
+ $helper->log('---------- Start catalog sync ----------');
52
+
53
+ //remove product with product id set and no product
54
+ $coreResource = Mage::getSingleton('core/resource');
55
+ $write = $coreResource->getConnection('core_write');
56
+ $catalogTable = $coreResource->getTableName('ddg_automation/catalog');
57
+ $select = $write->select();
58
+ $select->reset()
59
+ ->from(
60
+ array('c' => $catalogTable),
61
+ array('c.product_id')
62
+ )
63
+ ->joinLeft(
64
+ array('e' => $coreResource->getTableName('catalog_product_entity')),
65
+ "c.product_id = e.entity_id"
66
+ )
67
+ ->where('e.entity_id is NULL');
68
+ //delete sql statement
69
+ $deleteSql = $select->deleteFromSelect('c');
70
+ //run query
71
+ $write->query($deleteSql);
72
+
73
+ $scope = Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_CATALOG_VALUES);
74
+
75
+ //if only to pull default value
76
+ if($scope == 1){
77
+ $products = $this->_exportCatalog(Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID);
78
+ if ($products) {
79
+ //register in queue with importer
80
+ $check = $importer->registerQueue(
81
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_CATALOG,
82
+ $products,
83
+ Dotdigitalgroup_Email_Model_Importer::MODE_BULK,
84
+ Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID
85
+ );
86
+
87
+ //set imported
88
+ if ($check)
89
+ $this->getResource()->setImported($this->_productIds);
90
+
91
+ //set number of product imported
92
+ $this->_countProducts += count($products);
93
+ }
94
+ //using single api
95
+ $this->_exportInSingle(Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID, 'Catalog_Default', Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID);
96
+ //if to pull store values. will be pulled for each store
97
+ }elseif($scope == 2){
98
+ /** @var $store Mage_Core_Model_Store */
99
+ $stores = Mage::app()->getStores();
100
+ foreach($stores as $store){
101
+ $websiteCode = $store->getWebsite()->getCode();
102
+ $storeCode = $store->getCode();
103
+ $products = $this->_exportCatalog($store);
104
+ if($products){
105
+ $importer = Mage::getModel('ddg_automation/importer');
106
+ //register in queue with importer
107
+ $check = $importer->registerQueue(
108
+ 'Catalog_' . $websiteCode . '_' . $storeCode,
109
+ $products,
110
+ Dotdigitalgroup_Email_Model_Importer::MODE_BULK,
111
+ $store->getWebsite()->getId()
112
+ );
113
+ //set imported
114
+ if ($check)
115
+ $this->getResource()->setImported($this->_productIds);
116
+
117
+ //set number of product imported
118
+ $this->_countProducts += count($products);
119
+ }
120
+ //using single api
121
+ $this->_exportInSingle($store, 'Catalog_' . $websiteCode . '_' . $storeCode, $store->getWebsite()->getId());
122
+ }
123
+ }
124
+ }
125
+
126
+ if ($this->_countProducts) {
127
+ $message = 'Total time for sync : ' . gmdate( "H:i:s", microtime( true ) - $this->_start ) . ', Total synced = ' . $this->_countProducts;
128
+ $helper->log( $message );
129
+ $response['message'] = $message;
130
+ }
131
+ return $response;
132
+ }
133
+
134
+ /**
135
+ * export catalog
136
+ *
137
+ * @param $store
138
+ * @return array|bool
139
+ */
140
+ private function _exportCatalog($store)
141
+ {
142
+ $products = $this->_getProductsToExport($store);
143
+ if($products){
144
+ $this->_productIds = $products->getColumnValues('entity_id');
145
+ $connectorProducts = array();
146
+ foreach($products as $product){
147
+ $connectorProduct = Mage::getModel('ddg_automation/connector_product', $product);
148
+ $connectorProducts[] = $connectorProduct;
149
+ }
150
+ return $connectorProducts;
151
+ }
152
+ return false;
153
+ }
154
+
155
+ /**
156
+ * export in single
157
+ *
158
+ * @param $store
159
+ * @param $collectionName
160
+ * @param $websiteId
161
+ */
162
+ private function _exportInSingle($store, $collectionName, $websiteId)
163
+ {
164
+ $helper = Mage::helper('ddg');
165
+ $this->_productIds = array();
166
+
167
+ $products = $this->_getProductsToExport($store, true);
168
+ if($products){
169
+ foreach($products as $product){
170
+ $connectorProduct = Mage::getModel('ddg_automation/connector_product', $product);
171
+ $helper->log('---------- Start catalog single sync ----------');
172
+
173
+ //register in queue with importer
174
+ $check = Mage::getModel('ddg_automation/importer')->registerQueue(
175
+ $collectionName,
176
+ $connectorProduct,
177
+ Dotdigitalgroup_Email_Model_Importer::MODE_SINGLE,
178
+ $websiteId
179
+ );
180
+
181
+ if ($check) {
182
+ $this->_productIds[] = $product->getId();
183
+ }
184
+ }
185
+
186
+ if(!empty($this->_productIds)){
187
+ $this->getResource()->setImported($this->_productIds, true);
188
+ $this->_countProducts += count($this->_productIds);
189
+ }
190
+ }
191
+ }
192
+
193
+ /**
194
+ * get product collection
195
+ *
196
+ * @param $store
197
+ * @param $modified
198
+ * @return bool|Mage_Catalog_Model_Resource_Product_Collection
199
+ */
200
+ private function _getProductsToExport($store, $modified = false)
201
+ {
202
+ $limit = Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_TRANSACTIONAL_DATA_SYNC_LIMIT);
203
+ $connectorCollection = $this->getCollection();
204
+
205
+ if($modified)
206
+ $connectorCollection->addFieldToFilter('modified', array('eq' => '1'));
207
+ else
208
+ $connectorCollection->addFieldToFilter('imported', array('null' => 'true'));
209
+
210
+ $connectorCollection->setPageSize($limit);
211
+
212
+ if($connectorCollection->getSize()) {
213
+ $product_ids = $connectorCollection->getColumnValues('product_id');
214
+ $productCollection = Mage::getModel('catalog/product')->getCollection();
215
+ $productCollection
216
+ ->addAttributeToSelect('*')
217
+ ->addStoreFilter($store)
218
+ ->addAttributeToFilter('entity_id', array('in' => $product_ids));
219
+
220
+ //visibility filter
221
+ if($visibility = Mage::getStoreConfig(
222
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_CATALOG_VISIBILITY)){
223
+ $visibility = explode(',', $visibility);
224
+ $productCollection->addAttributeToFilter('visibility', array('in' => $visibility));
225
+ }
226
+
227
+ //type filter
228
+ if($type = Mage::getStoreConfig(
229
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_CATALOG_TYPE)){
230
+ $type = explode(',', $type);
231
+ $productCollection->addAttributeToFilter('type_id', array('in' => $type));
232
+ }
233
+
234
+ $productCollection
235
+ ->addWebsiteNamesToResult()
236
+ ->addFinalPrice()
237
+ ->addCategoryIds()
238
+ ->addOptionsToResult();
239
+
240
+ return $productCollection;
241
+ }
242
+ return false;
243
+ }
244
+
245
+ /**
246
+ * product save after event processor
247
+ *
248
+ * @param Varien_Event_Observer $observer
249
+ */
250
+ public function handleProductSaveAfter(Varien_Event_Observer $observer)
251
+ {
252
+ try{
253
+ $object = $observer->getEvent()->getDataObject();
254
+ $productId = $object->getId();
255
+ if($item = $this->_loadProduct($productId)){
256
+ if($item->getImported())
257
+ $item->setModified(1)->save();
258
+ }
259
+ }catch (Exception $e){
260
+ Mage::logException($e);
261
+ }
262
+ }
263
+
264
+ /**
265
+ * product delete after event processor
266
+ *
267
+ * @param Varien_Event_Observer $observer
268
+ */
269
+ public function handleProductDeleteAfter(Varien_Event_Observer $observer)
270
+ {
271
+ try{
272
+ /** @var $object Mage_Catalog_Model_Product */
273
+ $object = $observer->getEvent()->getDataObject();
274
+ $productId = $object->getId();
275
+ if($item = $this->_loadProduct($productId)){
276
+ //if imported delete from account
277
+ if($item->getImported()){
278
+ $this->_deleteFromAccount($productId);
279
+ }
280
+ //delete from table
281
+ $item->delete();
282
+
283
+ }
284
+ }catch (Exception $e){
285
+ Mage::logException($e);
286
+ }
287
+ }
288
+
289
+ /**
290
+ * delete piece of transactional data by key
291
+ *
292
+ * @param $key
293
+ */
294
+ private function _deleteFromAccount($key)
295
+ {
296
+ $enabled = Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED);
297
+ $sync = Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_CATALOG_ENABLED);
298
+ if($enabled && $sync){
299
+ $scope = Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_CATALOG_VALUES);
300
+ if($scope == 1){
301
+ //register in queue with importer
302
+ Mage::getModel('ddg_automation/importer')->registerQueue(
303
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_CATALOG,
304
+ array($key),
305
+ Dotdigitalgroup_Email_Model_Importer::MODE_SINGLE_DELETE,
306
+ Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID
307
+ );
308
+ }
309
+ if($scope == 2){
310
+ $stores = Mage::app()->getStores();
311
+ /** @var $store Mage_Core_Model_Store */
312
+ foreach($stores as $store){
313
+ $websiteCode = $store->getWebsite()->getCode();
314
+ $storeCode = $store->getCode();
315
+
316
+ //register in queue with importer
317
+ Mage::getModel('ddg_automation/importer')->registerQueue(
318
+ 'Catalog_' . $websiteCode . '_' . $storeCode,
319
+ array($key),
320
+ Dotdigitalgroup_Email_Model_Importer::MODE_SINGLE_DELETE,
321
+ $store->getWebsite()->getId()
322
+ );
323
+ }
324
+ }
325
+ }
326
+ }
327
+
328
+ /**
329
+ * load product. return item otherwise create item
330
+ *
331
+ * @param $productId
332
+ * @return bool|Varien_Object
333
+ */
334
+ private function _loadProduct($productId)
335
+ {
336
+ $collection = $this->getCollection()
337
+ ->addFieldToFilter('product_id', $productId)
338
+ ->setPageSize(1);
339
+
340
+ if ($collection->getSize()) {
341
+ return $collection->getFirstItem();
342
+ } else {
343
+ $this->setProductId($productId)->save();
344
+ }
345
+ return false;
346
+ }
347
+
348
+ /**
349
+ * core config data save before event
350
+ *
351
+ * @param Varien_Event_Observer $observer
352
+ * @return $this
353
+ */
354
+ public function handleConfigSaveBefore(Varien_Event_Observer $observer)
355
+ {
356
+ if (!Mage::registry('core_config_data_save_before')){
357
+ if($groups = $observer->getEvent()->getConfigData()->getGroups()){
358
+ if(isset($groups['catalog_sync']['fields']['catalog_values']['value'])){
359
+ $value = $groups['catalog_sync']['fields']['catalog_values']['value'];
360
+ Mage::register('core_config_data_save_before', $value);
361
+ }
362
+ }
363
+ }
364
+
365
+
366
+ if (!Mage::registry('core_config_data_save_before_status')) {
367
+ if ($groups = $observer->getEvent()->getConfigData()->getGroups()) {
368
+ if (isset($groups['data_fields']['fields']['order_statuses']['value'])) {
369
+ $value = $groups['data_fields']['fields']['order_statuses']['value'];
370
+ Mage::register('core_config_data_save_before_status', $value);
371
+ }
372
+ }
373
+ }
374
+
375
+
376
+ return $this;
377
+ }
378
+
379
+ /**
380
+ * core config data save after event
381
+ *
382
+ * @param Varien_Event_Observer $observer
383
+ * @return $this
384
+ */
385
+ public function handleConfigSaveAfter(Varien_Event_Observer $observer)
386
+ {
387
+ try{
388
+ if(!Mage::registry('core_config_data_save_after_done')){
389
+ if($groups = $observer->getEvent()->getConfigData()->getGroups()){
390
+ if(isset($groups['catalog_sync']['fields']['catalog_values']['value'])){
391
+ $configAfter = $groups['catalog_sync']['fields']['catalog_values']['value'];
392
+ $configBefore = Mage::registry('core_config_data_save_before');
393
+ if($configAfter != $configBefore){
394
+ //reset catalog to re-import
395
+ $this->getResource()->reset();
396
+ }
397
+ Mage::register('core_config_data_save_after_done', true);
398
+ }
399
+ }
400
+ }
401
+
402
+ if (!Mage::registry('core_config_data_save_after_done_status')) {
403
+ if ($groups = $observer->getEvent()->getConfigData()->getGroups()) {
404
+ if (isset($groups['data_fields']['fields']['order_statuses']['value'])) {
405
+ $configAfter = $groups['data_fields']['fields']['order_statuses']['value'];
406
+ $configBefore = Mage::registry('core_config_data_save_before_status');
407
+ if ($configAfter != $configBefore) {
408
+ //reset all contacts
409
+ Mage::getResourceModel('ddg_automation/contact')->resetAllContacts();
410
+ }
411
+ Mage::register('core_config_data_save_after_done_status', true);
412
+ }
413
+ }
414
+ }
415
+ }catch (Exception $e){
416
+ Mage::logException($e);
417
+ }
418
+ return $this;
419
+ }
420
+ }
app/code/{local → community}/Dotdigitalgroup/Email/Model/Connector/Account.php RENAMED
@@ -14,13 +14,18 @@ class Dotdigitalgroup_Email_Model_Connector_Account
14
  private $_mapping_hash;
15
  private $_contacts = array();
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 +37,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 +75,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 +220,53 @@ class Dotdigitalgroup_Email_Model_Connector_Account
214
  return $this->_websites;
215
  }
216
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
217
 
 
 
 
 
 
 
 
218
  }
14
  private $_mapping_hash;
15
  private $_contacts = array();
16
  private $_orders = array();
17
+ private $_orderIds = array();
18
+ private $_ordersForSingleSync = array();
19
+ private $_orderIdsForSingleSync = array();
20
 
21
  /**
22
+ * @param $api_password
23
+ * @return $this
24
  */
25
  public function setApiPassword($api_password)
26
  {
27
  $this->_api_password = $api_password;
28
+ return $this;
29
  }
30
 
31
  /**
37
  }
38
 
39
  /**
40
+ * @param $api_username
41
+ * @return $this
42
  */
43
  public function setApiUsername($api_username)
44
  {
45
  $this->_api_username = $api_username;
46
+ return $this;
47
  }
48
 
49
  /**
75
  */
76
  public function setContacts($contacts)
77
  {
78
+ if (!empty($this->_contacts)) {
79
+ $this->_contacts += $contacts;
80
+ } else {
 
81
  $this->_contacts[] = $contacts;
82
+ }
83
  }
84
 
85
  /**
220
  return $this->_websites;
221
  }
222
 
223
+ /**
224
+ * @param array $orderIds
225
+ */
226
+ public function setOrderIds($orderIds)
227
+ {
228
+ $this->_orderIds = $orderIds;
229
+ }
230
+
231
+ /**
232
+ * @return array
233
+ */
234
+ public function getOrderIds()
235
+ {
236
+ return $this->_orderIds;
237
+ }
238
+
239
+ /**
240
+ * @param array $orders
241
+ */
242
+ public function setOrdersForSingleSync($orders)
243
+ {
244
+ foreach ($orders as $order) {
245
+ $this->_ordersForSingleSync[$order->id] = $order;
246
+ }
247
+ }
248
+
249
+ /**
250
+ * @return array
251
+ */
252
+ public function getOrdersForSingleSync()
253
+ {
254
+ return $this->_ordersForSingleSync;
255
+ }
256
+
257
+ /**
258
+ * @param array $orderIds
259
+ */
260
+ public function setOrderIdsForSingleSync($orderIds)
261
+ {
262
+ $this->_orderIdsForSingleSync = $orderIds;
263
+ }
264
 
265
+ /**
266
+ * @return array
267
+ */
268
+ public function getOrderIdsForSingleSync()
269
+ {
270
+ return $this->_orderIdsForSingleSync;
271
+ }
272
  }
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,298 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ 'abandoned_prod_name' => array(
255
+ 'name' => 'ABANDONED_PROD_NAME',
256
+ 'type' => 'string',
257
+ 'visibility' => 'private',
258
+ ),
259
+ );
260
+
261
+ /**
262
+ * @param array $contactDatafields
263
+ */
264
+ public function setContactDatafields($contactDatafields)
265
+ {
266
+ $this->_contactDatafields = $contactDatafields;
267
+ }
268
+
269
+ /**
270
+ * @return array
271
+ */
272
+ public function getContactDatafields()
273
+ {
274
+ return $this->_contactDatafields;
275
+ }
276
+
277
+ /**
278
+ * set a single datafield.
279
+ *
280
+ * @param $name
281
+ * @param $value
282
+ * @param string $type
283
+ * @param string $visibility
284
+ *
285
+ * @return array
286
+ */
287
+ public function setDatafield($name, $value, $type = 'string', $visibility = 'private')
288
+ {
289
+ $this->datafields[] = array(
290
+ 'name' => $name,
291
+ 'value' => $value,
292
+ 'type' => $type,
293
+ 'visibility' => $visibility
294
+ );
295
+ return $this->datafields;
296
+ }
297
+
298
+ }
app/code/community/Dotdigitalgroup/Email/Model/Connector/Order.php ADDED
@@ -0,0 +1,446 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * Payment name
53
+ * @var string
54
+ */
55
+ public $payment;
56
+ /**
57
+ * @var string
58
+ */
59
+ public $delivery_method;
60
+ /**
61
+ * @var float
62
+ */
63
+ public $delivery_total;
64
+ /**
65
+ * @var string
66
+ */
67
+ public $currency;
68
+
69
+
70
+ public $couponCode;
71
+
72
+ /**
73
+ * @var array
74
+ */
75
+ public $custom = array();
76
+
77
+ /**
78
+ * @var string
79
+ */
80
+ public $order_status;
81
+
82
+ private $_attributeSet;
83
+
84
+ /**
85
+ * set the order information
86
+ * @param Mage_Sales_Model_Order $orderData
87
+ */
88
+ public function __construct(Mage_Sales_Model_Order $orderData)
89
+ {
90
+ $customerModel = Mage::getModel('customer/customer');
91
+ $customerModel->load($orderData->getCustomerId());
92
+
93
+ $this->id = $orderData->getIncrementId();
94
+ $this->quote_id = $orderData->getQuoteId();
95
+ $this->email = $orderData->getCustomerEmail();
96
+ $this->store_name = $orderData->getStoreName();
97
+
98
+ $created_at = new Zend_Date($orderData->getCreatedAt(), Zend_Date::ISO_8601);
99
+
100
+ $this->purchase_date = $created_at->toString(Zend_Date::ISO_8601);
101
+ $this->delivery_method = $orderData->getShippingDescription();
102
+ $this->delivery_total = $orderData->getShippingAmount();
103
+ $this->currency = $orderData->getStoreCurrencyCode();
104
+
105
+ if ($payment = $orderData->getPayment())
106
+ $this->payment = $payment->getMethodInstance()->getTitle();
107
+ $this->couponCode = $orderData->getCouponCode();
108
+
109
+ /**
110
+ * custom order attributes
111
+ */
112
+ $helper = Mage::helper('ddg');
113
+ $website = Mage::app()->getStore($orderData->getStore())->getWebsite();
114
+ $customAttributes = $helper->getConfigSelectedCustomOrderAttributes($website);
115
+ if($customAttributes){
116
+ $fields = Mage::getResourceModel('ddg_automation/order')->getOrderTableDescription();
117
+ foreach($customAttributes as $customAttribute){
118
+ if(isset($fields[$customAttribute])){
119
+ $field = $fields[$customAttribute];
120
+ $value = $this->_getCustomAttributeValue($field, $orderData);
121
+ if($value)
122
+ $this->_assignCustom($field, $value);
123
+ }
124
+ }
125
+ }
126
+
127
+ /**
128
+ * Billing address.
129
+ */
130
+ if ($orderData->getBillingAddress()) {
131
+ $billingData = $orderData->getBillingAddress()->getData();
132
+ $this->billing_address = array(
133
+ 'billing_address_1' => $this->_getStreet($billingData['street'], 1),
134
+ 'billing_address_2' => $this->_getStreet($billingData['street'], 2),
135
+ 'billing_city' => $billingData['city'],
136
+ 'billing_region' => $billingData['region'],
137
+ 'billing_country' => $billingData['country_id'],
138
+ 'billing_postcode' => $billingData['postcode'],
139
+ );
140
+ }
141
+ /**
142
+ * Shipping address.
143
+ */
144
+ if ($orderData->getShippingAddress()) {
145
+ $shippingData = $orderData->getShippingAddress()->getData();
146
+
147
+ $this->delivery_address = array(
148
+ 'delivery_address_1' => $this->_getStreet($shippingData['street'], 1),
149
+ 'delivery_address_2' => $this->_getStreet($shippingData['street'], 2),
150
+ 'delivery_city' => $shippingData['city'],
151
+ 'delivery_region' => $shippingData['region'],
152
+ 'delivery_country' => $shippingData['country_id'],
153
+ 'delivery_postcode' => $shippingData['postcode']
154
+ );
155
+ }
156
+
157
+ $syncCustomOption = $helper->getWebsiteConfig(
158
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_ORDER_PRODUCT_CUSTOM_OPTIONS,
159
+ $website
160
+ );
161
+
162
+ /**
163
+ * Order items.
164
+ * @var Mage_Sales_Model_Order_Item $productItem
165
+ */
166
+ foreach ($orderData->getAllItems() as $productItem) {
167
+ //product custom options
168
+ $customOptions = array();
169
+ if ($syncCustomOption)
170
+ $customOptions = $this->_getOrderItemOptions($productItem);
171
+
172
+ $product = $productItem->getProduct();
173
+
174
+ if ($product) {
175
+ // category names
176
+ $categoryCollection = $product->getCategoryCollection()
177
+ ->addAttributeToSelect( 'name' );
178
+ $productCat = array();
179
+ foreach ( $categoryCollection as $cat ) {
180
+ $categories = array();
181
+ $categories[] = $cat->getName();
182
+ $productCat[]['Name'] = substr(implode(', ', $categories), 0, 244);
183
+ }
184
+
185
+ $attributes = array();
186
+ //selected attributes from config
187
+ $configAttributes = Mage::helper('ddg')->getWebsiteConfig(
188
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_ORDER_PRODUCT_ATTRIBUTES,
189
+ $orderData->getStore()->getWebsite()
190
+ );
191
+ if ($configAttributes) {
192
+ $configAttributes = explode(',', $configAttributes);
193
+ //attributes from attribute set
194
+ $attributesFromAttributeSet = $this->_getAttributesArray($product->getAttributeSetId());
195
+
196
+ foreach ($configAttributes as $attribute_code) {
197
+ //if config attribute is in attribute set
198
+ if (in_array($attribute_code, $attributesFromAttributeSet)) {
199
+ //attribute input type
200
+ $inputType = $product->getResource()
201
+ ->getAttribute($attribute_code)
202
+ ->getFrontend()
203
+ ->getInputType();
204
+
205
+ //fetch attribute value from product depending on input type
206
+ switch ($inputType) {
207
+ case 'multiselect':
208
+ case 'select':
209
+ case 'dropdown':
210
+ $value = $product->getAttributeText($attribute_code);
211
+ break;
212
+ default:
213
+ $value = $product->getData($attribute_code);
214
+ break;
215
+ }
216
+
217
+ if ($value) // check limit on text and assign value to array
218
+ $attributes[][$attribute_code] = $this->_limitLength($value);
219
+ }
220
+ }
221
+ }
222
+
223
+ $attributeSetName = $this->_getAttributeSetName($product);
224
+ $this->products[] = array(
225
+ 'name' => $productItem->getName(),
226
+ 'sku' => $productItem->getSku(),
227
+ 'qty' => (int) number_format( $productItem->getData( 'qty_ordered' ), 2 ),
228
+ 'price' => (float) number_format( $productItem->getPrice(), 2, '.', '' ),
229
+ 'attribute-set' => $attributeSetName,
230
+ 'categories' => $productCat,
231
+ 'attributes' => $attributes,
232
+ 'custom-options' => $customOptions
233
+ );
234
+ } else {
235
+ // when no product information is available limit to this data
236
+ $this->products[] = array(
237
+ 'name' => $productItem->getName(),
238
+ 'sku' => $productItem->getSku(),
239
+ 'qty' => (int) number_format( $productItem->getData( 'qty_ordered' ), 2 ),
240
+ 'price' => (float)number_format($productItem->getPrice(), 2, '.', ''),
241
+ 'attribute-set' => '',
242
+ 'categories' => array(),
243
+ 'attributes' => array(),
244
+ 'custom-options' => $customOptions
245
+ );
246
+ }
247
+ }
248
+
249
+ $this->order_subtotal = (float)number_format($orderData->getData('subtotal'), 2 , '.', '');
250
+ $this->discount_ammount = (float)number_format($orderData->getData('discount_amount'), 2 , '.', '');
251
+ $orderTotal = abs($orderData->getData('grand_total') - $orderData->getTotalRefunded());
252
+ $this->order_total = (float)number_format($orderTotal, 2 , '.', '');
253
+ $this->order_status = $orderData->getStatus();
254
+
255
+ return true;
256
+ }
257
+ /**
258
+ * get the street name by line number
259
+ * @param $street
260
+ * @param $line
261
+ * @return string
262
+ */
263
+ private function _getStreet($street, $line)
264
+ {
265
+ $street = explode("\n", $street);
266
+ if ($line == 1) {
267
+ return $street[0];
268
+ }
269
+ if (isset($street[$line -1])) {
270
+
271
+ return $street[$line - 1];
272
+ } else {
273
+
274
+ return '';
275
+ }
276
+ }
277
+
278
+ /**
279
+ * exposes the class as an array of objects.
280
+ * @return array
281
+ */
282
+ public function expose()
283
+ {
284
+ return get_object_vars($this);
285
+
286
+ }
287
+
288
+ private function _getCustomAttributeValue($field, $orderData)
289
+ {
290
+ $type = $field['DATA_TYPE'];
291
+
292
+ $function = 'get';
293
+ $exploded = explode('_', $field['COLUMN_NAME']);
294
+ foreach ($exploded as $one) {
295
+ $function .= ucfirst($one);
296
+ }
297
+
298
+ $value = null;
299
+ try{
300
+ switch ($type) {
301
+ case 'int':
302
+ case 'smallint':
303
+ $value = (int)$orderData->$function();
304
+ break;
305
+
306
+ case 'decimal':
307
+ $value = (float)number_format($orderData->$function(), 2 , '.', '');
308
+ break;
309
+
310
+ case 'timestamp':
311
+ case 'datetime':
312
+ case 'date':
313
+ $date = new Zend_Date($orderData->$function(), Zend_Date::ISO_8601);
314
+ $value = $date->toString(Zend_Date::ISO_8601);
315
+ break;
316
+
317
+ default:
318
+ $value = $orderData->$function();
319
+ }
320
+ }catch (Exception $e){
321
+ Mage::logException($e);
322
+ }
323
+
324
+ return $value;
325
+ }
326
+
327
+ /**
328
+ * create property on runtime
329
+ *
330
+ * @param $field
331
+ * @param $value
332
+ */
333
+ private function _assignCustom($field, $value)
334
+ {
335
+ $this->custom[$field['COLUMN_NAME']] = $value;
336
+ }
337
+
338
+ /**
339
+ * get attributes from attribute set
340
+ *
341
+ * @param $attributeSetId
342
+ * @return array
343
+ */
344
+ private function _getAttributesArray($attributeSetId)
345
+ {
346
+ $result = array();
347
+ $attributes = Mage::getResourceModel('catalog/product_attribute_collection')
348
+ ->setAttributeSetFilter($attributeSetId)
349
+ ->getItems();
350
+
351
+ foreach ($attributes as $attribute) {
352
+ $result[] = $attribute->getAttributeCode();
353
+ }
354
+
355
+ return $result;
356
+ }
357
+
358
+ /**
359
+ * check string length and limit to 250
360
+ *
361
+ * @param $value
362
+ * @return string
363
+ */
364
+ private function _limitLength($value)
365
+ {
366
+ if (strlen($value) > 250)
367
+ $value = substr($value, 0, 250);
368
+
369
+ return $value;
370
+ }
371
+
372
+ /**
373
+ * @param Mage_Sales_Model_Order_Item $orderItem
374
+ * @return array
375
+ */
376
+ private function _getOrderItemOptions($orderItem)
377
+ {
378
+ $orderItemOptions = $orderItem->getProductOptions();
379
+
380
+ //if product doesn't have options
381
+ if (!array_key_exists('options', $orderItemOptions)) {
382
+ return array();
383
+ }
384
+
385
+ $orderItemOptions = $orderItemOptions['options'];
386
+
387
+ //if product options isn't array
388
+ if (!is_array($orderItemOptions)) {
389
+ return array();
390
+ }
391
+
392
+ $options = array();
393
+
394
+ foreach ($orderItemOptions as $orderItemOption) {
395
+ if (array_key_exists('value', $orderItemOption) && array_key_exists('label', $orderItemOption)) {
396
+ $label = str_replace(' ', '-', $orderItemOption['label']);
397
+ $options[][$label] = $orderItemOption['value'];
398
+ }
399
+ }
400
+
401
+ return $options;
402
+
403
+ }
404
+
405
+ /**
406
+ * get attribute set name
407
+ *
408
+ * @param Mage_Catalog_Model_Product $product
409
+ * @return string
410
+ */
411
+ private function _getAttributeSetName(Mage_Catalog_Model_Product $product)
412
+ {
413
+ //check if empty. on true load model and cache result
414
+ if(empty($this->_attributeSet)){
415
+ $this->_loadAttributeModel($product);
416
+ if(empty($this->_attributeSet))
417
+ return '';
418
+ else
419
+ return $this->_attributeSet->getAttributeSetName();
420
+ }
421
+
422
+ //if cached attribute set id equals product's attribute set id
423
+ if($this->_attributeSet->getId() == $product->getAttributeSetId())
424
+ return $this->_attributeSet->getAttributeSetName();
425
+
426
+ //if both above false. load model and cache result
427
+ $this->_loadAttributeModel($product);
428
+ if(empty($this->_attributeSet))
429
+ return '';
430
+ else
431
+ return $this->_attributeSet->getAttributeSetName();
432
+ }
433
+
434
+ /**
435
+ * load attribute model
436
+ *
437
+ * @param Mage_Catalog_Model_Product $product
438
+ */
439
+ private function _loadAttributeModel(Mage_Catalog_Model_Product $product)
440
+ {
441
+ $attributeSetModel = Mage::getModel( "eav/entity_attribute_set" );
442
+ $attributeSetModel->load( $product->getAttributeSetId() );
443
+ if($attributeSetModel->getId())
444
+ $this->_attributeSet = $attributeSetModel;
445
+ }
446
+ }
app/code/community/Dotdigitalgroup/Email/Model/Connector/Product.php ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Connector_Product
4
+ {
5
+ /**
6
+ * @var string
7
+ */
8
+ public $id;
9
+
10
+ /**
11
+ * @var string
12
+ */
13
+ public $name = '';
14
+
15
+ /**
16
+ * @var string
17
+ */
18
+ public $sku = '';
19
+
20
+ /**
21
+ * @var string
22
+ */
23
+ public $status = '';
24
+
25
+ /**
26
+ * @var string
27
+ */
28
+ public $visibility = '';
29
+
30
+ /**
31
+ * @var float
32
+ */
33
+ public $price = 0;
34
+
35
+ /**
36
+ * @var float
37
+ */
38
+ public $special_price = 0;
39
+
40
+ /**
41
+ * @var array
42
+ */
43
+ public $categories = array();
44
+
45
+ /**
46
+ * @var string
47
+ */
48
+ public $url = '';
49
+
50
+ /**
51
+ * @var string
52
+ */
53
+ public $image_path = '';
54
+
55
+ /**
56
+ * @var string
57
+ */
58
+ public $short_description = '';
59
+
60
+ /**
61
+ * @var float
62
+ */
63
+ public $stock = 0;
64
+
65
+ /**
66
+ * @var array
67
+ */
68
+ public $websites = array();
69
+
70
+ public function __construct(Mage_Catalog_Model_Product $product)
71
+ {
72
+ $this->id = $product->getId();
73
+ $this->sku = $product->getSku();
74
+ $this->name = $product->getName();
75
+ $statuses = Mage::getModel('catalog/product_status')->getOptionArray();
76
+ $this->status = $statuses[$product->getStatus()];
77
+ $options = Mage::getModel('catalog/product_visibility')->getOptionArray();
78
+ $this->visibility = $options[$product->getVisibility()];
79
+ $this->price = (float) number_format($product->getPrice(), 2, '.', '' );
80
+ $this->special_price = (float) number_format($product->getSpecialPrice(), 2, '.', '' );
81
+ $this->url = $product->getProductUrl();
82
+ $this->image_path = Mage::getModel('catalog/product_media_config')->getMediaUrl( $product->getSmallImage());
83
+ $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product);
84
+ $this->stock = (float) number_format($stock->getQty(), 2, '.', '' );
85
+
86
+ $short_description = $product->getShortDescription();
87
+ //limit short description
88
+ if(strlen($short_description) > 250)
89
+ $short_description = substr($short_description, 0 , 250);
90
+
91
+ $this->short_description = $short_description;
92
+
93
+ //category data
94
+ $count = 0;
95
+ $categoryCollection = $product->getCategoryCollection()->addNameToResult();
96
+ foreach ($categoryCollection as $cat) {
97
+ $this->categories[$count]['Id'] = $cat->getId();
98
+ $this->categories[$count]['Name'] = $cat->getName();
99
+ $count++;
100
+ }
101
+
102
+ //website data
103
+ $count = 0;
104
+ $websiteIds = $product->getWebsiteIds();
105
+ foreach ($websiteIds as $websiteId) {
106
+ $website = Mage::app()->getWebsite($websiteId);
107
+ $this->websites[$count]['Id'] = $website->getId();
108
+ $this->websites[$count]['Name'] = $website->getName();
109
+ $count++;
110
+ }
111
+
112
+ //bundle product options
113
+ if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE){
114
+ $optionCollection = $product->getTypeInstance()->getOptionsCollection();
115
+ $selectionCollection = $product->getTypeInstance()->getSelectionsCollection($product->getTypeInstance()->getOptionsIds());
116
+ $options = $optionCollection->appendSelections($selectionCollection);
117
+ foreach($options as $option)
118
+ {
119
+ $count = 0;
120
+ $title = str_replace(' ', '', $option->getDefaultTitle());
121
+ $selections = $option->getSelections();
122
+ $sOptions = array();
123
+ foreach($selections as $selection)
124
+ {
125
+ $sOptions[$count]['name'] = $selection->getName();
126
+ $sOptions[$count]['sku'] = $selection->getSku();
127
+ $sOptions[$count]['id'] = $selection->getProductId();
128
+ $sOptions[$count]['price'] = (float) number_format($selection->getPrice(), 2, '.', '' );
129
+ $count++;
130
+ }
131
+ $this->$title = $sOptions;
132
+ }
133
+ }
134
+
135
+ //configurable product options
136
+ if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE){
137
+ $productAttributeOptions = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
138
+ foreach ($productAttributeOptions as $productAttribute) {
139
+ $count = 0;
140
+ $label = strtolower(str_replace(' ', '', $productAttribute['label']));
141
+ $options = array();
142
+ foreach ($productAttribute['values'] as $attribute) {
143
+ $options[$count]['option'] = $attribute['default_label'];
144
+ $options[$count]['price'] = (float) number_format($attribute['pricing_value'], 2, '.', '' );
145
+ $count++;
146
+ }
147
+ $this->$label = $options;
148
+ }
149
+ }
150
+ return true;
151
+ }
152
+
153
+ /**
154
+ * exposes the class as an array of objects.
155
+ * @return array
156
+ */
157
+ public function expose()
158
+ {
159
+ return get_object_vars($this);
160
+ }
161
+
162
+ }
app/code/community/Dotdigitalgroup/Email/Model/Connector/Quote.php ADDED
@@ -0,0 +1,327 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ private $_attributeSet;
77
+
78
+ /**
79
+ * set the quote information
80
+ * @param Mage_Sales_Model_Quote $quoteData
81
+ */
82
+ public function __construct(Mage_Sales_Model_Quote $quoteData)
83
+ {
84
+ $customerModel = Mage::getModel('customer/customer');
85
+ $customerModel->load($quoteData->getCustomerId());
86
+
87
+ $this->id = $quoteData->getId();
88
+ $this->email = $quoteData->getCustomerEmail();
89
+ $this->store_name = $quoteData->getStore()->getName();
90
+
91
+ $created_at = new Zend_Date($quoteData->getCreatedAt(), Zend_Date::ISO_8601);
92
+
93
+ $this->created_date = $created_at->toString(Zend_Date::ISO_8601);
94
+ if($quoteData->getShippingAddress()){
95
+ $this->delivery_method = $quoteData->getShippingAddress()->getShippingDescription();
96
+ $this->delivery_total = $quoteData->getShippingAddress()->getShippingAmount();
97
+ }
98
+ $this->currency = $quoteData->getStoreCurrencyCode();
99
+ if ($payment = $quoteData->getPayment())
100
+ $this->payment = $payment->getMethod();
101
+
102
+ $this->couponCode = $quoteData->getCouponCode();
103
+
104
+ /**
105
+ * custom quote attributes
106
+ */
107
+ $helper = Mage::helper('ddg');
108
+ $website = Mage::app()->getStore($quoteData->getStore())->getWebsite();
109
+ $customAttributes = $helper->getConfigSelectedCustomQuoteAttributes($website);
110
+ if($customAttributes){
111
+ $fields = Mage::getResourceModel('ddg_automation/quote')->getQuoteTableDescription();
112
+ foreach($customAttributes as $customAttribute){
113
+ if(isset($fields[$customAttribute])){
114
+ $field = $fields[$customAttribute];
115
+ $value = $this->_getCustomAttributeValue($field, $quoteData);
116
+ if($value)
117
+ $this->_assignCustom($field, $value);
118
+ }
119
+ }
120
+ }
121
+
122
+ /**
123
+ * Billing address.
124
+ */
125
+ if ($quoteData->getBillingAddress()) {
126
+ $billingData = $quoteData->getBillingAddress()->getData();
127
+ $this->billing_address = array(
128
+ 'billing_address_1' => $this->_getStreet($billingData['street'], 1),
129
+ 'billing_address_2' => $this->_getStreet($billingData['street'], 2),
130
+ 'billing_city' => $billingData['city'],
131
+ 'billing_region' => $billingData['region'],
132
+ 'billing_country' => $billingData['country_id'],
133
+ 'billing_postcode' => $billingData['postcode'],
134
+ );
135
+ }
136
+ /**
137
+ * Shipping address.
138
+ */
139
+ if ($quoteData->getShippingAddress()) {
140
+ $shippingData = $quoteData->getShippingAddress()->getData();
141
+
142
+ $this->delivery_address = array(
143
+ 'delivery_address_1' => $this->_getStreet($shippingData['street'], 1),
144
+ 'delivery_address_2' => $this->_getStreet($shippingData['street'], 2),
145
+ 'delivery_city' => $shippingData['city'],
146
+ 'delivery_region' => $shippingData['region'],
147
+ 'delivery_country' => $shippingData['country_id'],
148
+ 'delivery_postcode' => $shippingData['postcode']
149
+ );
150
+ }
151
+
152
+ /**
153
+ * Quote items.
154
+ * @var Mage_Sales_Model_Quote_Item $productItem
155
+ */
156
+ foreach ($quoteData->getAllItems() as $productItem) {
157
+
158
+ $product = $productItem->getProduct();
159
+
160
+ if ($product) {
161
+ // category names
162
+ $categoryCollection = $product->getCategoryCollection()
163
+ ->addAttributeToSelect( 'name' );
164
+
165
+ foreach ( $categoryCollection as $cat ) {
166
+ $categories = array();
167
+ $categories[] = $cat->getName();
168
+ $this->categories[]['Name'] = substr( implode( ', ', $categories ), 0, 244 );
169
+ }
170
+
171
+ //get attribute set name
172
+ $attributeSetName = $this->_getAttributeSetName($product);
173
+ $this->products[] = array(
174
+ 'name' => $productItem->getName(),
175
+ 'sku' => $productItem->getSku(),
176
+ 'qty' => (int) number_format( $productItem->getData( 'qty' ), 2 ),
177
+ 'price' => (float) number_format( $productItem->getPrice(), 2, '.', '' ),
178
+ 'attribute-set' => $attributeSetName
179
+ );
180
+ } else {
181
+ // when no product information is available limit to this data
182
+ $this->products[] = array(
183
+ 'name' => $productItem->getName(),
184
+ 'sku' => $productItem->getSku(),
185
+ 'qty' => (int) number_format( $productItem->getData( 'qty' ), 2 ),
186
+ 'price' => (float) number_format( $productItem->getPrice(), 2, '.', '' )
187
+ );
188
+ }
189
+ }
190
+
191
+ $this->quote_subtotal = (float)number_format($quoteData->getData('subtotal'), 2 , '.', '');
192
+ $discountAmount = $quoteData->getData('subtotal') - $quoteData->getData('subtotal_with_discount');
193
+ $this->discount_amount = (float)number_format($discountAmount, 2 , '.', '');
194
+ $this->quote_total = (float)number_format($quoteData->getData('grand_total'), 2 , '.', '');
195
+
196
+ return true;
197
+ }
198
+ /**
199
+ * get the street name by line number
200
+ * @param $street
201
+ * @param $line
202
+ * @return string
203
+ */
204
+ private function _getStreet($street, $line)
205
+ {
206
+ $street = explode("\n", $street);
207
+ if ($line == 1) {
208
+ return $street[0];
209
+ }
210
+ if (isset($street[$line -1])) {
211
+
212
+ return $street[$line - 1];
213
+ } else {
214
+
215
+ return '';
216
+ }
217
+ }
218
+
219
+ /**
220
+ * exposes the class as an array of objects.
221
+ * @return array
222
+ */
223
+ public function expose()
224
+ {
225
+ return get_object_vars($this);
226
+
227
+ }
228
+
229
+ /**
230
+ * get custom attribute value
231
+ *
232
+ * @param $field
233
+ * @param $quoteData
234
+ * @return float|int|null|string
235
+ */
236
+ private function _getCustomAttributeValue($field, $quoteData)
237
+ {
238
+ $type = $field['DATA_TYPE'];
239
+
240
+ $function = 'get';
241
+ $exploded = explode('_', $field['COLUMN_NAME']);
242
+ foreach ($exploded as $one) {
243
+ $function .= ucfirst($one);
244
+ }
245
+
246
+ $value = null;
247
+ try{
248
+ switch ($type) {
249
+ case 'int':
250
+ case 'smallint':
251
+ $value = (int)$quoteData->$function();
252
+ break;
253
+
254
+ case 'decimal':
255
+ $value = (float)number_format($quoteData->$function(), 2 , '.', '');
256
+ break;
257
+
258
+ case 'timestamp':
259
+ case 'datetime':
260
+ case 'date':
261
+ $date = new Zend_Date($quoteData->$function(), Zend_Date::ISO_8601);
262
+ $value = $date->toString(Zend_Date::ISO_8601);
263
+ break;
264
+
265
+ default:
266
+ $value = $quoteData->$function();
267
+ }
268
+ }catch (Exception $e){
269
+ Mage::logException($e);
270
+ }
271
+
272
+ return $value;
273
+ }
274
+
275
+ /**
276
+ * create property on runtime
277
+ *
278
+ * @param $field
279
+ * @param $value
280
+ */
281
+ private function _assignCustom($field, $value)
282
+ {
283
+ $this->custom[$field['COLUMN_NAME']] = $value;
284
+ }
285
+
286
+ /**
287
+ * get attribute set name
288
+ *
289
+ * @param Mage_Catalog_Model_Product $product
290
+ * @return string
291
+ */
292
+ private function _getAttributeSetName(Mage_Catalog_Model_Product $product)
293
+ {
294
+ //check if empty. on true load model and cache result
295
+ if(empty($this->_attributeSet)){
296
+ $this->_loadAttributeModel($product);
297
+ if(empty($this->_attributeSet))
298
+ return '';
299
+ else
300
+ return $this->_attributeSet->getAttributeSetName();
301
+ }
302
+
303
+ //if cached attribute set id equals product's attribute set id
304
+ if($this->_attributeSet->getId() == $product->getAttributeSetId())
305
+ return $this->_attributeSet->getAttributeSetName();
306
+
307
+ //if both above false. load model and cache result
308
+ $this->_loadAttributeModel($product);
309
+ if(empty($this->_attributeSet))
310
+ return '';
311
+ else
312
+ return $this->_attributeSet->getAttributeSetName();
313
+ }
314
+
315
+ /**
316
+ * load attribute model
317
+ *
318
+ * @param Mage_Catalog_Model_Product $product
319
+ */
320
+ private function _loadAttributeModel(Mage_Catalog_Model_Product $product)
321
+ {
322
+ $attributeSetModel = Mage::getModel( "eav/entity_attribute_set" );
323
+ $attributeSetModel->load( $product->getAttributeSetId() );
324
+ if($attributeSetModel->getId())
325
+ $this->_attributeSet = $attributeSetModel;
326
+ }
327
+ }
app/code/community/Dotdigitalgroup/Email/Model/Contact.php ADDED
@@ -0,0 +1,238 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * Load contact by customer id
34
+ * @param $customerId
35
+ * @return mixed
36
+ */
37
+ public function loadByCustomerId($customerId)
38
+ {
39
+ $collection = $this->getCollection()
40
+ ->addFieldToFilter('customer_id', $customerId)
41
+ ->setPageSize(1);
42
+
43
+ if($collection->count())
44
+ return $collection->getFirstItem();
45
+
46
+ return $this;
47
+ }
48
+
49
+ /**
50
+ * get all customer contacts not imported for a website.
51
+ *
52
+ * @param $websiteId
53
+ * @param int $pageSize
54
+ *
55
+ * @return Dotdigitalgroup_Email_Model_Resource_Contact_Collection
56
+ */
57
+ public function getContactsToImportForWebsite($websiteId, $pageSize = 100)
58
+ {
59
+ $collection = $this->getCollection()
60
+ ->addFieldToFilter('website_id', $websiteId)
61
+ ->addFieldToFilter('email_imported', array('null' => true))
62
+ ->addFieldToFilter('customer_id', array('neq' => '0'));
63
+
64
+
65
+ $collection->getSelect()->limit($pageSize);
66
+
67
+ return $collection;
68
+ }
69
+
70
+ /**
71
+ * Get missing contacts.
72
+ * @param $websiteId
73
+ * @param int $pageSize
74
+ * @return mixed
75
+ */
76
+ public function getMissingContacts($websiteId, $pageSize = 100)
77
+ {
78
+ $collection = $this->getCollection()
79
+ ->addFieldToFilter('contact_id', array('null' => true))
80
+ ->addFieldToFilter('suppressed', array('null' => true))
81
+ ->addFieldToFilter('website_id', $websiteId);
82
+
83
+ $collection->getSelect()->limit($pageSize);
84
+
85
+ return $collection->load();
86
+ }
87
+
88
+ /**
89
+ * Load Contact by Email.
90
+ * @param $email
91
+ * @param $websiteId
92
+ * @return $this
93
+ */
94
+ public function loadByCustomerEmail($email, $websiteId)
95
+ {
96
+ $collection = $this->getCollection()
97
+ ->addFieldToFilter('email', $email)
98
+ ->addFieldToFilter('website_id', $websiteId)
99
+ ->setPageSize(1);
100
+
101
+ if ($collection->getSize()) {
102
+ return $collection->getFirstItem();
103
+ } else {
104
+ $this->setEmail($email)
105
+ ->setWebsiteId($websiteId);
106
+ }
107
+ return $this;
108
+ }
109
+
110
+ /**
111
+ * batch non imported subscribers for a website.
112
+ * @param $website
113
+ * @param int $limit
114
+ *
115
+ * @return Dotdigitalgroup_Email_Model_Resource_Contact_Collection
116
+ */
117
+ public function getSubscribersToImport($website, $limit = 1000)
118
+ {
119
+
120
+ $storeIds = $website->getStoreIds();
121
+ $collection = $this->getCollection()
122
+ ->addFieldToFilter('is_subscriber', array('notnull' => true))
123
+ ->addFieldToFilter('subscriber_imported', array('null' => true))
124
+ ->addFieldToFilter('store_id', array('in' => $storeIds));
125
+
126
+ $collection->getSelect()->limit($limit);
127
+
128
+ return $collection;
129
+ }
130
+
131
+ /**
132
+ * get all not imported guests for a website.
133
+ * @param $website
134
+ *
135
+ * @return Dotdigitalgroup_Email_Model_Resource_Contact_Collection
136
+ */
137
+ public function getGuests($website)
138
+ {
139
+ $guestCollection = $this->getCollection()
140
+ ->addFieldToFilter('is_guest', array('notnull' => true))
141
+ ->addFieldToFilter('email_imported', array('null' => true))
142
+ ->addFieldToFilter('website_id', $website->getId());
143
+ return $guestCollection->load();
144
+ }
145
+
146
+ public function getNumberOfImportedContacs()
147
+ {
148
+ $collection = $this->getCollection()
149
+ ->addFieldToFilter('email_imported', array('notnull' => true));
150
+
151
+ return $collection->getSize();
152
+ }
153
+
154
+ /**
155
+ * Get the number of customers for a website.
156
+ * @param int $websiteId
157
+ *
158
+ * @return int
159
+ */
160
+ public function getNumberCustomerContacts($websiteId = 0)
161
+ {
162
+ $countContacts = Mage::getModel('ddg_automation/contact')->getCollection()
163
+ ->addFieldToFilter('customer_id', array('gt' => '0'))
164
+ ->addFieldToFilter('website_id', $websiteId)
165
+ ->getSize();
166
+ return $countContacts;
167
+ }
168
+
169
+ /**
170
+ *
171
+ * Get number of suppressed contacts as customer.
172
+ * @param int $websiteId
173
+ *
174
+ * @return int
175
+ */
176
+ public function getNumberCustomerSuppressed( $websiteId = 0 )
177
+ {
178
+ $countContacts = Mage::getModel('ddg_automation/contact')->getCollection()
179
+ ->addFieldToFilter('customer_id', array('gt' => 0))
180
+ ->addFieldToFilter('website_id', $websiteId)
181
+ ->addFieldToFilter('suppressed', '1')
182
+ ->getSize();
183
+
184
+ return $countContacts;
185
+ }
186
+
187
+ /**
188
+ * Get number of synced customers.
189
+ * @param int $websiteId
190
+ *
191
+ * @return int
192
+ */
193
+ public function getNumberCustomerSynced( $websiteId = 0 )
194
+ {
195
+ $countContacts = Mage::getModel('ddg_automation/contact')->getCollection()
196
+ ->addFieldToFilter('customer_id', array('gt' => 0))
197
+ ->addFieldToFilter('website_id', $websiteId)
198
+ ->addFieldToFilter('email_imported' , '1')
199
+ ->getSize();
200
+
201
+ return $countContacts;
202
+
203
+ }
204
+
205
+ /**
206
+ * Get number of subscribers synced.
207
+ * @param int $websiteId
208
+ *
209
+ * @return int
210
+ */
211
+ public function getNumberSubscribersSynced( $websiteId = 0 )
212
+ {
213
+ $countContacts = Mage::getModel('ddg_automation/contact')->getCollection()
214
+ ->addFieldToFilter('subscriber_status', Dotdigitalgroup_Email_Model_Newsletter_Subscriber::STATUS_SUBSCRIBED)
215
+ ->addFieldToFilter('subscriber_imported', '1')
216
+ ->addFieldToFilter('website_id', $websiteId)
217
+ ->getSize();
218
+
219
+ return $countContacts;
220
+ }
221
+
222
+ /**
223
+ * Get number of subscribers.
224
+ * @param int $websiteId
225
+ *
226
+ * @return int
227
+ */
228
+ public function getNumberSubscribers( $websiteId = 0 )
229
+ {
230
+
231
+ $countContacts = Mage::getModel('ddg_automation/contact')->getCollection()
232
+ ->addFieldToFilter('subscriber_status', Dotdigitalgroup_Email_Model_Newsletter_Subscriber::STATUS_SUBSCRIBED)
233
+ ->addFieldToFilter('website_id', $websiteId)
234
+ ->getSize();
235
+ return $countContacts;
236
+ }
237
+
238
+ }
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,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Cron
4
+ {
5
+ /**
6
+ * CRON FOR EMAIL IMPORTER PROCESSOR
7
+ */
8
+ public function emailImporter()
9
+ {
10
+ return Mage::getModel('ddg_automation/importer')->processQueue();
11
+ }
12
+
13
+ /**
14
+ * CRON FOR CATALOG SYNC
15
+ */
16
+ public function catalogSync()
17
+ {
18
+ // send customers
19
+ $result = Mage::getModel('ddg_automation/catalog')->sync();
20
+ return $result;
21
+ }
22
+
23
+ /**
24
+ * CRON FOR CONTACTS SYNC
25
+ */
26
+ public function contactSync()
27
+ {
28
+ // send customers
29
+ $result = Mage::getModel('ddg_automation/apiconnector_contact')->sync();
30
+ $subscriberResult = $this->subscribersAndGuestSync();
31
+ if(isset($subscriberResult['message']) && isset($result['message']))
32
+ $result['message'] = $result['message'] . ' - ' . $subscriberResult['message'];
33
+ return $result;
34
+ }
35
+
36
+ /**
37
+ * CRON FOR ABANDONED CARTS
38
+ */
39
+ public function abandonedCarts()
40
+ {
41
+
42
+ Mage::getModel( 'ddg_automation/sales_quote' )->proccessAbandonedCarts();
43
+
44
+ }
45
+
46
+ /**
47
+ * CRON FOR SYNC REVIEWS and REGISTER ORDER REVIEW CAMPAIGNS
48
+ */
49
+ public function reviewsAndWishlist()
50
+ {
51
+ //sync reviews
52
+ $this->reviewSync();
53
+ //sync wishlist
54
+ Mage::getModel('ddg_automation/wishlist')->sync();
55
+ }
56
+
57
+ /**
58
+ * review sync
59
+ */
60
+ public function reviewSync()
61
+ {
62
+ //find orders to review and register campaign
63
+ Mage::getModel('ddg_automation/sales_order')->createReviewCampaigns();
64
+ //sync reviews
65
+ $result = Mage::getModel('ddg_automation/review')->sync();
66
+ return $result;
67
+ }
68
+
69
+ /**
70
+ * order sync
71
+ *
72
+ * @return mixed
73
+ */
74
+ public function orderSync()
75
+ {
76
+ // send order
77
+ $orderResult = Mage::getModel('ddg_automation/sales_order')->sync();
78
+ return $orderResult;
79
+ }
80
+
81
+ /**
82
+ * quote sync
83
+ *
84
+ * @return mixed
85
+ */
86
+ public function quoteSync()
87
+ {
88
+ //send quote
89
+ $quoteResult = Mage::getModel('ddg_automation/quote')->sync();
90
+
91
+ return $quoteResult;
92
+ }
93
+
94
+ /**
95
+ * CRON FOR ORDER & QUOTE TRANSACTIONAL DATA
96
+ */
97
+ public function orderAndQuoteSync()
98
+ {
99
+ // send order
100
+ $orderResult = $this->orderSync();
101
+
102
+ //send quote
103
+ $quoteResult = $this->quoteSync();
104
+
105
+ return $orderResult['message'] . ' ' .$quoteResult['message'];
106
+ }
107
+
108
+ /**
109
+ * CRON FOR SUBSCRIBERS AND GUEST CONTACTS
110
+ */
111
+ public function subscribersAndGuestSync()
112
+ {
113
+ //sync subscribers
114
+ $subscriberModel = Mage::getModel('ddg_automation/newsletter_subscriber');
115
+ $result = $subscriberModel->sync();
116
+
117
+ //unsubscribe suppressed contacts
118
+ $subscriberModel->unsubscribe();
119
+
120
+ //sync guests
121
+ Mage::getModel('ddg_automation/customer_guest')->sync();
122
+ return $result;
123
+ }
124
+
125
+ /**
126
+ * CRON FOR EMAILS SENDING
127
+ */
128
+ public function sendEmails()
129
+ {
130
+ Mage::getModel('ddg_automation/campaign')->sendCampaigns();
131
+
132
+ return $this;
133
+ }
134
+
135
+ /**
136
+ * CLEAN ARHIVED FOLDERS
137
+ */
138
+ public function cleaning()
139
+ {
140
+ $helper = Mage::helper('ddg/file');
141
+ $archivedFolder = $helper->getArchiveFolder();
142
+ $result = $helper->deleteDir($archivedFolder);
143
+ $message = 'Cleaning cronjob result : ' . $result;
144
+ $helper->log($message);
145
+ Mage::helper('ddg')->rayLog('10', $message, 'model/cron.php');
146
+ return $result;
147
+ }
148
+
149
+
150
+ /**
151
+ * Last customer sync date.
152
+ * @return bool|string
153
+ */
154
+ public function getLastCustomerSync(){
155
+
156
+ $schedules = Mage::getModel('cron/schedule')->getCollection();
157
+ $schedules->getSelect()->limit(1)->order('executed_at DESC');
158
+ $schedules->addFieldToFilter('status', Mage_Cron_Model_Schedule::STATUS_SUCCESS)
159
+ ->addFieldToFilter('job_code', 'ddg_automation_customer_subscriber_guest_sync')
160
+ ->getSize();
161
+
162
+
163
+ if ($schedules->getSize() == 0) {
164
+ return false;
165
+ }
166
+ $executedAt = $schedules->getFirstItem()->getExecutedAt();
167
+ return Mage::getModel('core/date')->date(NULL, $executedAt);
168
+ }
169
+
170
+ public function automationStatus()
171
+ {
172
+ Mage::getModel('ddg_automation/automation')->enrollment();
173
+
174
+ }
175
+ }
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, $backUrl, $storeId);
19
+ }
20
+ }
app/code/community/Dotdigitalgroup/Email/Model/Customer/Guest.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $syncEnabled = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_GUEST_ENABLED);
21
+ $apiEnabled = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED, $website);
22
+ if ($enabled && $syncEnabled && $apiEnabled) {
23
+
24
+ //ready to start sync
25
+ if (!$this->_countGuests)
26
+ $helper->log('----------- Start guest sync ----------');
27
+
28
+ //sync guests for website
29
+ $this->exportGuestPerWebsite($website);
30
+ }
31
+ }
32
+ if ($this->_countGuests)
33
+ $helper->log('---- End Guest total time for guest sync : ' . gmdate("H:i:s", microtime(true) - $this->_start));
34
+ }
35
+
36
+ public function exportGuestPerWebsite(Mage_Core_Model_Website $website)
37
+ {
38
+ $helper = Mage::helper('ddg');
39
+ $fileHelper = Mage::helper('ddg/file');
40
+ $guests = Mage::getModel('ddg_automation/contact')->getGuests($website);
41
+ if ($guests->getSize()) {
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
+ //register in queue with importer
61
+ Mage::getModel('ddg_automation/importer')->registerQueue(
62
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_GUEST,
63
+ '',
64
+ Dotdigitalgroup_Email_Model_Importer::MODE_BULK,
65
+ $website->getId(),
66
+ $guestFilename
67
+ );
68
+ }
69
+ }
70
+ }
71
+ }
app/code/community/Dotdigitalgroup/Email/Model/Customer/Observer.php ADDED
@@ -0,0 +1,362 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ if ($emailReg){
23
+ return $this;
24
+ }
25
+
26
+ Mage::register($email . '_customer_save', $email);
27
+ $emailBefore = Mage::getModel('customer/customer')->load($customer->getId())->getEmail();
28
+ $contactModel = Mage::getModel('ddg_automation/contact')->loadByCustomerEmail($emailBefore, $websiteId);
29
+ //email change detection
30
+ if ($email != $emailBefore) {
31
+ Mage::helper('ddg')->log('email change detected : ' . $email . ', after : ' . $emailBefore . ', website id : ' . $websiteId);
32
+ $enabled = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED, $websiteId);
33
+
34
+ if ($enabled) {
35
+ $client = Mage::helper('ddg')->getWebsiteApiClient($websiteId);
36
+ $subscribersAddressBook = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SUBSCRIBERS_ADDRESS_BOOK_ID, $websiteId);
37
+ $response = $client->postContacts($emailBefore);
38
+ //check for matching email
39
+ if (isset($response->id)) {
40
+ if ($email != $response->email) {
41
+ $data = array(
42
+ 'Email' => $email,
43
+ 'EmailType' => 'Html'
44
+ );
45
+ //update the contact with same id - different email
46
+ $client->updateContact($response->id, $data);
47
+
48
+ }
49
+ if (!$isSubscribed && $response->status == 'Subscribed') {
50
+ $client->deleteAddressBookContact($subscribersAddressBook, $response->id);
51
+ }
52
+ } elseif (isset($response->message)) {
53
+ Mage::helper('ddg')->log('Email change error : ' . $response->message);
54
+ }
55
+ }
56
+ $contactModel->setEmail($email);
57
+ }
58
+
59
+ $contactModel->setEmailImported(Dotdigitalgroup_Email_Model_Contact::EMAIL_CONTACT_NOT_IMPORTED)
60
+ ->setCustomerId($customerId)
61
+ ->save();
62
+ }catch(Exception $e){
63
+ Mage::logException($e);
64
+ }
65
+ return $this;
66
+ }
67
+
68
+ /**
69
+ * Add new customers to the automation.
70
+ * @param Varien_Event_Observer $observer
71
+ *
72
+ * @return $this
73
+ */
74
+ public function handleCustomerRegiterSuccess(Varien_Event_Observer $observer)
75
+ {
76
+ /** @var $customer Mage_Customer_Model_Customer */
77
+ $customer = $observer->getEvent()->getCustomer();
78
+ $websiteId = $customer->getWebsiteId();
79
+ $website = Mage::app()->getWebsite($websiteId);
80
+ $storeName = $customer->getStore()->getName();
81
+
82
+
83
+ //if api is not enabled
84
+ if (!$website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED))
85
+ return $this;
86
+
87
+ try {
88
+ //program id must be map
89
+ $programId = Mage::helper( 'ddg' )->getAutomationIdByType( 'XML_PATH_CONNECTOR_AUTOMATION_STUDIO_CUSTOMER', $websiteId);
90
+ if (!$programId)
91
+ return $this;
92
+ $email = $customer->getEmail();
93
+ $automation = Mage::getModel( 'ddg_automation/automation' );
94
+ $automation->setEmail( $email )
95
+ ->setAutomationType( Dotdigitalgroup_Email_Model_Automation::AUTOMATION_TYPE_NEW_CUSTOMER )
96
+ ->setEnrolmentStatus(Dotdigitalgroup_Email_Model_Automation::AUTOMATION_STATUS_PENDING)
97
+ ->setTypeId( $customer->getId() )
98
+ ->setWebsiteId($websiteId)
99
+ ->setStoreName($storeName)
100
+ ->setProgramId($programId)
101
+ ;
102
+
103
+ $automation->save();
104
+ }catch(Exception $e) {
105
+ Mage::logException($e);
106
+ }
107
+
108
+ return $this;
109
+ }
110
+
111
+ /**
112
+ * Remove the contact on customer delete.
113
+ *
114
+ * @param Varien_Event_Observer $observer
115
+ *
116
+ * @return $this
117
+ */
118
+ public function handleCustomerDeleteAfter(Varien_Event_Observer $observer)
119
+ {
120
+ $customer = $observer->getEvent()->getCustomer();
121
+ $email = $customer->getEmail();
122
+ $websiteId = $customer->getWebsiteId();
123
+ $helper = Mage::helper('ddg');
124
+
125
+ //api enabled
126
+ $enabled = $helper->getWebsiteConfig(
127
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED,
128
+ $websiteId
129
+ );
130
+ //sync enabled
131
+ $syncEnabled = $helper->getWebsiteConfig(
132
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_CONTACT_ENABLED,
133
+ $websiteId
134
+ );
135
+
136
+ /**
137
+ * Remove contact.
138
+ */
139
+ if ($enabled && $syncEnabled) {
140
+ try {
141
+ //register in queue with importer
142
+ $check = Mage::getModel('ddg_automation/importer')->registerQueue(
143
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_CONTACT,
144
+ $email,
145
+ Dotdigitalgroup_Email_Model_Importer::MODE_CONTACT_DELETE,
146
+ $websiteId
147
+ );
148
+ $contactModel = Mage::getModel('ddg_automation/contact')->loadByCustomerEmail($email, $websiteId);
149
+ if ($contactModel->getId() && $check) {
150
+ //remove contact
151
+ $contactModel->delete();
152
+ }
153
+ } catch (Exception $e) {
154
+ Mage::logException($e);
155
+ }
156
+ }
157
+ return $this;
158
+ }
159
+
160
+ /**
161
+ * Set contact to re-import if registered customer submitted a review. Save review in email_review table.
162
+ * @param Varien_Event_Observer $observer
163
+ * @return $this
164
+ */
165
+ public function reviewSaveAfter(Varien_Event_Observer $observer)
166
+ {
167
+ $dataObject = $observer->getEvent()->getDataObject();
168
+
169
+ if($dataObject->getCustomerId() && $dataObject->getStatusId() == Mage_Review_Model_Review::STATUS_APPROVED){
170
+ $helper = Mage::helper('ddg');
171
+ $customerId = $dataObject->getCustomerId();
172
+ $helper->setConnectorContactToReImport($customerId);
173
+ //save review info in the table
174
+ $this->_registerReview($dataObject);
175
+ $store = Mage::app()->getStore($dataObject->getStoreId());
176
+ $storeName = $store->getName();
177
+ $website = Mage::app()->getStore($store)->getWebsite();
178
+ $customer = Mage::getModel('customer/customer')->load($customerId);
179
+
180
+
181
+ //if api is not enabled
182
+ if (!$website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED))
183
+ return $this;
184
+
185
+ $programId = Mage::helper( 'ddg' )->getAutomationIdByType('XML_PATH_CONNECTOR_AUTOMATION_STUDIO_REVIEW', $website->getId());
186
+ if ($programId) {
187
+ $automation = Mage::getModel( 'ddg_automation/automation' );
188
+ $automation->setEmail( $customer->getEmail() )
189
+ ->setAutomationType( Dotdigitalgroup_Email_Model_Automation::AUTOMATION_TYPE_NEW_REVIEW )
190
+ ->setEnrolmentStatus(Dotdigitalgroup_Email_Model_Automation::AUTOMATION_STATUS_PENDING)
191
+ ->setTypeId( $dataObject->getReviewId() )
192
+ ->setWebsiteId( $website->getId() )
193
+ ->setStoreName( $storeName )
194
+ ->setProgramId( $programId );
195
+ $automation->save();
196
+ }
197
+ }
198
+ return $this;
199
+ }
200
+
201
+ /**
202
+ * register review
203
+ *
204
+ * @param $review
205
+ */
206
+ private function _registerReview($review)
207
+ {
208
+ try{
209
+ $emailReview = Mage::getModel('ddg_automation/review');
210
+ $emailReview->setReviewId($review->getReviewId())
211
+ ->setCustomerId($review->getCustomerId())
212
+ ->setStoreId($review->getStoreId())
213
+ ->save();
214
+ }catch(Exception $e){
215
+ Mage::logException($e);
216
+ }
217
+ }
218
+
219
+ /**
220
+ * wishlist save after observer. save new wishlist in the email_wishlist table.
221
+ *
222
+ * @param Varien_Event_Observer $observer
223
+ * @return $this
224
+ */
225
+ public function wishlistSaveAfter(Varien_Event_Observer $observer)
226
+ {
227
+ if($observer->getEvent()->getObject() instanceof Mage_Wishlist_Model_Wishlist) {
228
+ $wishlist = $observer->getEvent()->getObject()->getData();
229
+ if (is_array($wishlist) && isset($wishlist['customer_id'])) {
230
+ //save wishlist info in the table
231
+ $this->_registerWishlist( $wishlist );
232
+ }
233
+ }
234
+ }
235
+
236
+ /**
237
+ * register wishlist
238
+ *
239
+ * @param $wishlist
240
+ * @return $this
241
+ */
242
+ private function _registerWishlist($wishlist)
243
+ {
244
+ try{
245
+ $emailWishlist = Mage::getModel('ddg_automation/wishlist');
246
+ $customer = Mage::getModel('customer/customer');
247
+
248
+ //if wishlist exist not to save again
249
+ if(!$emailWishlist->getWishlist($wishlist['wishlist_id'])){
250
+ $customer->load($wishlist['customer_id']);
251
+ $email = $customer->getEmail();
252
+ $wishlistId = $wishlist['wishlist_id'];
253
+ $websiteId = $customer->getWebsiteId();
254
+ $emailWishlist->setWishlistId($wishlistId)
255
+ ->setCustomerId($wishlist['customer_id'])
256
+ ->setStoreId($customer->getStoreId())
257
+ ->save();
258
+
259
+ $store = Mage::app()->getStore($customer->getStoreId());
260
+ $storeName = $store->getName();
261
+ $website = Mage::app()->getStore($store)->getWebsite();
262
+
263
+ //if api is not enabled
264
+ if (!$website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED))
265
+ return $this;
266
+
267
+ $automationType = 'XML_PATH_CONNECTOR_AUTOMATION_STUDIO_WISHLIST';
268
+ $programId = Mage::helper( 'ddg' )->getAutomationIdByType($automationType, $websiteId);
269
+ if ($programId) {
270
+ $automation = Mage::getModel( 'ddg_automation/automation' );
271
+ $automation->setEmail( $email )
272
+ ->setAutomationType( Dotdigitalgroup_Email_Model_Automation::AUTOMATION_TYPE_NEW_WISHLIST )
273
+ ->setEnrolmentStatus(Dotdigitalgroup_Email_Model_Automation::AUTOMATION_STATUS_PENDING)
274
+ ->setTypeId( $wishlistId )
275
+ ->setWebsiteId( $websiteId )
276
+ ->setStoreName( $storeName )
277
+ ->setProgramId( $programId );
278
+ $automation->save();
279
+ }
280
+
281
+ }
282
+ }catch(Exception $e){
283
+ Mage::logException($e);
284
+ }
285
+ }
286
+
287
+ /**
288
+ * wishlist item save after
289
+ *
290
+ * @param Varien_Event_Observer $observer
291
+ */
292
+ public function wishlistItemSaveAfter(Varien_Event_Observer $observer)
293
+ {
294
+ $object = $observer->getEvent()->getDataObject();
295
+ $wishlist = Mage::getModel( 'wishlist/wishlist' )->load( $object->getWishlistId() );
296
+ $emailWishlist = Mage::getModel( 'ddg_automation/wishlist' );
297
+ try {
298
+ if ( $object->getWishlistId() ) {
299
+ $itemCount = count( $wishlist->getItemCollection() );
300
+ $item = $emailWishlist->getWishlist( $object->getWishlistId() );
301
+
302
+ if ( $item && $item->getId() ) {
303
+ $preSaveItemCount = $item->getItemCount();
304
+
305
+ if ( $itemCount != $item->getItemCount() ) {
306
+ $item->setItemCount( $itemCount );
307
+ }
308
+
309
+ if ( $itemCount == 1 && $preSaveItemCount == 0 ) {
310
+ $item->setWishlistImported( null );
311
+ } elseif ( $item->getWishlistImported() ) {
312
+ $item->setWishlistModified( 1 );
313
+ }
314
+
315
+ $item->save();
316
+ }
317
+ }
318
+ } catch ( Exception $e ) {
319
+ Mage::logException( $e );
320
+ }
321
+
322
+ }
323
+
324
+ /**
325
+ * wishlist delete observer
326
+ *
327
+ * @param Varien_Event_Observer $observer
328
+ */
329
+ public function wishlistDeleteAfter(Varien_Event_Observer $observer)
330
+ {
331
+ $object = $observer->getEvent()->getDataObject();
332
+ $customer = Mage::getModel('customer/customer')->load($object->getCustomerId());
333
+ $website = Mage::app()->getStore($customer->getStoreId())->getWebsite();
334
+ $helper = Mage::helper('ddg');
335
+
336
+ //sync enabled
337
+ $syncEnabled = $helper->getWebsiteConfig(
338
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_WISHLIST_ENABLED,
339
+ $website->getId()
340
+ );
341
+ if ($helper->isEnabled($website->getId()) && $syncEnabled) {
342
+ //Remove wishlist
343
+ try {
344
+ $item = Mage::getModel('ddg_automation/wishlist')->getWishlist($object->getWishlistId());
345
+ if ($item->getId()) {
346
+ //register in queue with importer
347
+ $check = Mage::getModel('ddg_automation/importer')->registerQueue(
348
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_WISHLIST,
349
+ array($item->getId()),
350
+ Dotdigitalgroup_Email_Model_Importer::MODE_SINGLE_DELETE,
351
+ $website->getId()
352
+ );
353
+ if ($check) {
354
+ $item->delete();
355
+ }
356
+ }
357
+ } catch (Exception $e) {
358
+ Mage::logException($e);
359
+ }
360
+ }
361
+ }
362
+ }
app/code/community/Dotdigitalgroup/Email/Model/Customer/Review.php ADDED
@@ -0,0 +1,241 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * @param $email
47
+ * @return $this
48
+ */
49
+ public function setEmail($email)
50
+ {
51
+ $this->email = $email;
52
+ return $this;
53
+ }
54
+
55
+ /**
56
+ * @param $customer_id
57
+ * @return $this
58
+ */
59
+ public function setCustomerId($customer_id)
60
+ {
61
+ $this->customer_id = (int) $customer_id;
62
+ return $this;
63
+ }
64
+
65
+ /**
66
+ * @return mixed
67
+ */
68
+ public function getCustomerId()
69
+ {
70
+ return (int) $this->customer_id;
71
+ }
72
+
73
+ /**
74
+ * @param $id
75
+ * @return $this
76
+ */
77
+ public function setId($id)
78
+ {
79
+ $this->id = (int) $id;
80
+ return $this;
81
+ }
82
+
83
+ /**
84
+ * @return mixed
85
+ */
86
+ public function getId()
87
+ {
88
+ return (int) $this->id;
89
+ }
90
+
91
+ /**
92
+ * create rating on runtime
93
+ *
94
+ * @param $rating_name
95
+ * @param $rating
96
+ */
97
+ public function createRating($rating_name, $rating)
98
+ {
99
+ $this->$rating_name = $rating->expose();
100
+ }
101
+
102
+ /**
103
+ * set review date.
104
+ *
105
+ * @param $date
106
+ * @return $this;
107
+ */
108
+ public function setReviewDate($date)
109
+ {
110
+ $created_at = new Zend_Date($date, Zend_Date::ISO_8601);
111
+
112
+ $this->review_date = $created_at->toString(Zend_Date::ISO_8601);;
113
+ return $this;
114
+ }
115
+
116
+ /**
117
+ * @return string
118
+ */
119
+ public function getReviewDate()
120
+ {
121
+ return $this->review_date;
122
+ }
123
+
124
+ /**
125
+ * set product
126
+ *
127
+ * @param Mage_Catalog_Model_Product $product
128
+ * @return $this
129
+ */
130
+ public function setProduct(Mage_Catalog_Model_Product $product)
131
+ {
132
+ $this->setProductName($product->getName());
133
+ $this->setProductSku($product->getSku());
134
+ return $this;
135
+ }
136
+
137
+ /**
138
+ * set review data
139
+ *
140
+ * @param Mage_Review_Model_Review $review $product
141
+ * @return $this
142
+ */
143
+ public function setReviewData(Mage_Review_Model_Review $review)
144
+ {
145
+ $store = Mage::app()->getStore($review->getStoreId());
146
+ $websiteName = $store->getWebsite()->getName();
147
+ $storeName = $store->getName();
148
+ $this->setId($review->getReviewId())
149
+ ->setWebsiteName($websiteName)
150
+ ->setStoreName($storeName)
151
+ ->setReviewDate($review->getCreatedAt())
152
+ ->setCustomerId($review->getCustomerId())
153
+ ->setEmail($review->getEmail());
154
+
155
+ return $this;
156
+ }
157
+
158
+ /**
159
+ * set product name
160
+ *
161
+ * @param $name
162
+ */
163
+ public function setProductName($name)
164
+ {
165
+ $this->product_name = $name;
166
+ }
167
+
168
+ /**
169
+ * @return string
170
+ */
171
+ public function getProductName()
172
+ {
173
+ return $this->product_name;
174
+ }
175
+
176
+ /**
177
+ * set product sku
178
+ *
179
+ * @param $sku
180
+ */
181
+ public function setProductSku($sku)
182
+ {
183
+ $this->product_sku = $sku;
184
+ }
185
+
186
+ /**
187
+ * @return string
188
+ */
189
+ public function getProductSku()
190
+ {
191
+ return $this->product_sku;
192
+ }
193
+
194
+ /**
195
+ * set website name
196
+ *
197
+ * @param $name
198
+ * @return $this
199
+ */
200
+ public function setWebsiteName($name)
201
+ {
202
+ $this->website_name = $name;
203
+ return $this;
204
+ }
205
+
206
+ /**
207
+ * @return string
208
+ */
209
+ public function getStoreName()
210
+ {
211
+ return $this->store_name;
212
+ }
213
+
214
+ /**
215
+ * set store name
216
+ *
217
+ * @param $name
218
+ * @return $this
219
+ */
220
+ public function setStoreName($name)
221
+ {
222
+ $this->store_name = $name;
223
+ return $this;
224
+ }
225
+
226
+ /**
227
+ * @return string
228
+ */
229
+ public function getWebsiteName()
230
+ {
231
+ return $this->website_name;
232
+ }
233
+
234
+ /**
235
+ * @return array
236
+ */
237
+ public function expose()
238
+ {
239
+ return get_object_vars($this);
240
+ }
241
+ }
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,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ /**
35
+ * @param $email
36
+ * @return $this
37
+ */
38
+ public function setEmail($email)
39
+ {
40
+ $this->email = $email;
41
+ return $this;
42
+ }
43
+
44
+ /**
45
+ * @param $customer_id
46
+ * @return $this
47
+ */
48
+ public function setCustomerId($customer_id)
49
+ {
50
+ $this->customer_id = (int) $customer_id;
51
+ return $this;
52
+ }
53
+
54
+ /**
55
+ * @return mixed
56
+ */
57
+ public function getCustomerId()
58
+ {
59
+ return (int) $this->customer_id;
60
+ }
61
+
62
+ /**
63
+ * @param $id
64
+ * @return $this
65
+ */
66
+ public function setId($id)
67
+ {
68
+ $this->id = (int) $id;
69
+ return $this;
70
+ }
71
+
72
+ /**
73
+ * @return mixed
74
+ */
75
+ public function getId()
76
+ {
77
+ return (int) $this->id;
78
+ }
79
+
80
+ /**
81
+ * set wishlist item.
82
+ *
83
+ * @param $item
84
+ */
85
+ public function setItem($item)
86
+ {
87
+ $this->items[] = $item->expose();
88
+
89
+ $this->total_wishlist_value += $item->getTotalValueOfProduct();
90
+ }
91
+
92
+ /**
93
+ * @return array
94
+ */
95
+ public function expose()
96
+ {
97
+ return get_object_vars($this);
98
+ }
99
+
100
+ /**
101
+ * set wishlist date.
102
+ *
103
+ * @param $date
104
+ * @return $this;
105
+ */
106
+ public function setUpdatedAt($date)
107
+ {
108
+ $date = new Zend_Date($date, Zend_Date::ISO_8601);
109
+
110
+ $this->updated_at = $date->toString(Zend_Date::ISO_8601);;
111
+ return $this;
112
+ }
113
+
114
+ /**
115
+ * @return string
116
+ */
117
+ public function getUpdatedAt()
118
+ {
119
+ return $this->updated_at;
120
+ }
121
+ }
app/code/{local → community}/Dotdigitalgroup/Email/Model/Customer/Wishlist/Item.php RENAMED
@@ -2,24 +2,32 @@
2
 
3
  class Dotdigitalgroup_Email_Model_Customer_Wishlist_Item
4
  {
5
- protected $name;
6
- protected $sku;
7
- protected $price;
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
  }
2
 
3
  class Dotdigitalgroup_Email_Model_Customer_Wishlist_Item
4
  {
5
+ protected $sku;
6
+ protected $qty;
7
+ protected $name;
8
+ protected $price;
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/Importer.php ADDED
@@ -0,0 +1,270 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Importer extends Mage_Core_Model_Abstract
4
+ {
5
+ //import statuses
6
+ const NOT_IMPORTED = 0;
7
+ const IMPORTING = 1;
8
+ const IMPORTED = 2;
9
+ const FAILED = 3;
10
+
11
+ //import mode
12
+ const MODE_BULK = 'Bulk';
13
+ const MODE_SINGLE = 'Single';
14
+ const MODE_SINGLE_DELETE = 'Single_Delete';
15
+ const MODE_CONTACT_DELETE = 'Contact_Delete';
16
+
17
+ //import type
18
+ const IMPORT_TYPE_CONTACT = 'Contact';
19
+ const IMPORT_TYPE_ORDERS = 'Orders';
20
+ const IMPORT_TYPE_WISHLIST = 'Wishlist';
21
+ const IMPORT_TYPE_REVIEWS = 'Reviews';
22
+ const IMPORT_TYPE_CATALOG = 'Catalog_Default';
23
+ const IMPORT_TYPE_QUOTE = 'Quote';
24
+ const IMPORT_TYPE_SUBSCRIBERS = 'Subscriber';
25
+ const IMPORT_TYPE_GUEST = 'Guest';
26
+
27
+ private $import_statuses = array(
28
+ 'RejectedByWatchdog', 'InvalidFileFormat', 'Unknown',
29
+ 'Failed', 'ExceedsAllowedContactLimit', 'NotAvailableInThisVersion'
30
+ );
31
+
32
+ /**
33
+ * constructor
34
+ */
35
+ public function _construct()
36
+ {
37
+ parent::_construct();
38
+ $this->_init('ddg_automation/importer');
39
+ }
40
+
41
+ /**
42
+ * @return $this|Mage_Core_Model_Abstract
43
+ */
44
+ protected function _beforeSave()
45
+ {
46
+ parent::_beforeSave();
47
+ $now = Mage::getSingleton('core/date')->gmtDate();
48
+ if ($this->isObjectNew()) {
49
+ $this->setCreatedAt($now);
50
+ } else {
51
+ $this->setUpdatedAt($now);
52
+ }
53
+ return $this;
54
+ }
55
+
56
+ /**
57
+ * register import in queue
58
+ *
59
+ * @param $importType
60
+ * @param $importData
61
+ * @param $importMode
62
+ * @param $websiteId
63
+ * @param bool $file
64
+ * @return bool
65
+ */
66
+ public function registerQueue($importType, $importData, $importMode, $websiteId, $file = false)
67
+ {
68
+ try {
69
+ if (!empty($importData))
70
+ $importData = serialize($importData);
71
+
72
+ if ($file)
73
+ $this->setImportFile($file);
74
+
75
+ $this->setImportType($importType)
76
+ ->setImportData($importData)
77
+ ->setWebsiteId($websiteId)
78
+ ->setImportMode($importMode)
79
+ ->save();
80
+
81
+ return true;
82
+ } catch (Exception $e) {
83
+ Mage::logException($e);
84
+ }
85
+ }
86
+
87
+ /**
88
+ * start point. importer queue processor. check if un-finished import exist.
89
+ *
90
+ * @return bool
91
+ */
92
+ public function processQueue()
93
+ {
94
+ $helper = Mage::helper('ddg');
95
+ $helper->allowResourceFullExecution();
96
+ if ($item = $this->_getQueue(true)) {
97
+ $websiteId = $item->getWebsiteId();
98
+ $enabled = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED, $websiteId);
99
+ if ($enabled) {
100
+ $client = Mage::helper('ddg')->getWebsiteApiClient($websiteId);
101
+ if (
102
+ $item->getImportType() == self::IMPORT_TYPE_CONTACT or
103
+ $item->getImportType() == self::IMPORT_TYPE_SUBSCRIBERS or
104
+ $item->getImportType() == self::IMPORT_TYPE_GUEST
105
+
106
+ ) {
107
+ $response = $client->getContactsImportByImportId($item->getImportId());
108
+ } else {
109
+ $response = $client->getContactsTransactionalDataImportByImportId($item->getImportId());
110
+ }
111
+ if ($response && !isset($response->message)) {
112
+ if ($response->status == 'Finished') {
113
+ $now = Mage::getSingleton('core/date')->gmtDate();
114
+ $item->setImportStatus(self::IMPORTED)
115
+ ->setImportFinished($now)
116
+ ->setMessage('')
117
+ ->save();
118
+
119
+ $this->_processQueue();
120
+ } elseif (in_array($response->status, $this->import_statuses)) {
121
+ $item->setImportStatus(self::FAILED)
122
+ ->setMessage($response->message)
123
+ ->save();
124
+
125
+ $this->_processQueue();
126
+ }
127
+ }
128
+ if ($response && isset($response->message)) {
129
+ $item->setImportStatus(self::FAILED)
130
+ ->setMessage($response->message)
131
+ ->save();
132
+
133
+ $this->_processQueue();
134
+ }
135
+ }
136
+ } else {
137
+ $this->_processQueue();
138
+ }
139
+ return true;
140
+ }
141
+
142
+ /**
143
+ * actual importer queue processor
144
+ */
145
+ private function _processQueue()
146
+ {
147
+ if ($item = $this->_getQueue()) {
148
+ $helper = Mage::helper('ddg');
149
+ $websiteId = $item->getWebsiteId();
150
+ $client = $helper->getWebsiteApiClient($websiteId);
151
+ $now = Mage::getSingleton('core/date')->gmtDate();
152
+ $error = false;
153
+
154
+ if ( //import requires file
155
+ $item->getImportType() == self::IMPORT_TYPE_CONTACT or
156
+ $item->getImportType() == self::IMPORT_TYPE_SUBSCRIBERS or
157
+ $item->getImportType() == self::IMPORT_TYPE_GUEST
158
+ ) {
159
+ if ($item->getImportMode() == self::MODE_CONTACT_DELETE) {
160
+ //remove from account
161
+ $client = Mage::helper('ddg')->getWebsiteApiClient($websiteId);
162
+ $email = unserialize($item->getImportData());
163
+ $apiContact = $client->postContacts($email);
164
+ if (!isset($apiContact->message) && isset($apiContact->id)) {
165
+ $result = $client->deleteContact($apiContact->id);
166
+ if (isset($result->message)) {
167
+ $error = true;
168
+ }
169
+ } elseif (isset($apiContact->message) && !isset($apiContact->id)) {
170
+ $error = true;
171
+ $result = $apiContact;
172
+ }
173
+ } else {
174
+ //address book
175
+ $addressbook = '';
176
+ if ($item->getImportType() == self::IMPORT_TYPE_CONTACT)
177
+ $addressbook = $helper->getCustomerAddressBook($websiteId);
178
+ if ($item->getImportType() == self::IMPORT_TYPE_SUBSCRIBERS)
179
+ $addressbook = $helper->getSubscriberAddressBook($websiteId);
180
+ if ($item->getImportType() == self::IMPORT_TYPE_GUEST)
181
+ $addressbook = $helper->getGuestAddressBook($websiteId);
182
+
183
+ $file = $item->getImportFile();
184
+ if (!empty($file) && !empty($addressbook)) {
185
+ $result = $client->postAddressBookContactsImport($file, $addressbook);
186
+ $fileHelper = Mage::helper('ddg/file');
187
+ if (isset($result->message) && !isset($result->id)) {
188
+ $error = true;
189
+ } else
190
+ $fileHelper->archiveCSV($file);
191
+ }
192
+ }
193
+ } elseif ($item->getImportMode() == self::MODE_SINGLE_DELETE) { //import to single delete
194
+ $importData = unserialize($item->getImportData());
195
+ $result = $client->deleteContactsTransactionalData($importData[0], $item->getImportType());
196
+ if (isset($result->message)) {
197
+ $error = true;
198
+ }
199
+ } else {
200
+ $importData = unserialize($item->getImportData());
201
+ //catalog type and bulk mode
202
+ if (strpos($item->getImportType(), 'Catalog_') !== false && $item->getImportMode() == self::MODE_BULK) {
203
+ $result = $client->postAccountTransactionalDataImport($importData, $item->getImportType());
204
+ if (isset($result->message) && !isset($result->id)) {
205
+ $error = true;
206
+ }
207
+ } elseif ($item->getImportMode() == self::MODE_SINGLE) { // single contact import
208
+ $result = $client->postContactsTransactionalData($importData, $item->getImportType());
209
+ if (isset($result->message)) {
210
+ $error = true;
211
+ }
212
+ } else { //bulk import transactional data
213
+ $result = $client->postContactsTransactionalDataImport($importData, $item->getImportType());
214
+ if (isset($result->message) && !isset($result->id)) {
215
+ $error = true;
216
+ }
217
+ }
218
+ }
219
+ if (!$error) {
220
+ if ($item->getImportMode() == self::MODE_SINGLE_DELETE or
221
+ $item->getImportMode() == self::MODE_SINGLE or
222
+ $item->getImportMode() == self::MODE_CONTACT_DELETE
223
+ ) {
224
+ $item->setImportStatus(self::IMPORTED)
225
+ ->setImportFinished($now)
226
+ ->setImportStarted($now)
227
+ ->save();
228
+ }
229
+ elseif(isset($result->id)){
230
+ $item->setImportStatus(self::IMPORTING)
231
+ ->setImportId($result->id)
232
+ ->setImportStarted($now)
233
+ ->save();
234
+ }
235
+ else{
236
+ $item->setImportStatus(self::FAILED)
237
+ ->setMessage($result->message)
238
+ ->save();
239
+ }
240
+ } elseif ($error) {
241
+ $item->setImportStatus(self::FAILED)
242
+ ->setMessage($result->message)
243
+ ->save();
244
+ }
245
+ }
246
+ }
247
+
248
+ /**
249
+ * get queue items from importer
250
+ *
251
+ * @param bool $importing
252
+ * @return bool|Varien_Object
253
+ */
254
+ private function _getQueue($importing = false)
255
+ {
256
+ $collection = $this->getCollection();
257
+
258
+ //if true then return item with importing status
259
+ if ($importing)
260
+ $collection->addFieldToFilter('import_status', array('eq' => self::IMPORTING));
261
+ else
262
+ $collection->addFieldToFilter('import_status', array('eq' => self::NOT_IMPORTED));
263
+
264
+ $collection->setPageSize(1);
265
+ if ($collection->count()) {
266
+ return $collection->getFirstItem();
267
+ }
268
+ return false;
269
+ }
270
+ }
app/code/community/Dotdigitalgroup/Email/Model/Newsletter/Observer.php ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
28
+ // fix for a multiple hit of the observer
29
+ $emailReg = Mage::registry($email . '_subscriber_save');
30
+ if ($emailReg){
31
+ return $this;
32
+ }
33
+ Mage::register($email . '_subscriber_save', $email);
34
+
35
+ $contactEmail = Mage::getModel('ddg_automation/contact')->loadByCustomerEmail($email, $websiteId);
36
+
37
+ // only for subsribers
38
+ if ($subscriberStatus == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED) {
39
+ $client = Mage::helper('ddg')->getWebsiteApiClient($websiteId);
40
+ //check for website client
41
+ if ($client) {
42
+ //set contact as subscribed
43
+ $contactEmail->setSubscriberStatus( $subscriberStatus )
44
+ ->setIsSubscriber('1');
45
+ $apiContact = $client->postContacts( $email );
46
+
47
+ //resubscribe suppressed contacts
48
+ if (isset($apiContact->message) && $apiContact->message == Dotdigitalgroup_Email_Model_Apiconnector_Client::API_ERROR_CONTACT_SUPPRESSED) {
49
+ $client->postContactsResubscribe( $apiContact );
50
+ }
51
+ }
52
+ // reset the subscriber as suppressed
53
+ $contactEmail->setSuppressed(null);
54
+
55
+ //not subscribed
56
+ } else {
57
+ //skip if contact is suppressed
58
+ if ($contactEmail->getSuppressed())
59
+ return $this;
60
+ //update contact id for the subscriber
61
+ $client = Mage::helper('ddg')->getWebsiteApiClient($websiteId);
62
+ //check for website client
63
+ if ($client) {
64
+ $contactId = $contactEmail->getContactId();
65
+ //get the contact id
66
+ if ( !$contactId ) {
67
+ //if contact id is not set get the contact_id
68
+ $result = $client->postContacts( $email );
69
+ if ( isset( $result->id ) ) {
70
+ $contactId = $result->id;
71
+ } else {
72
+ //no contact id skip
73
+ $contactEmail->setSuppressed( '1' )
74
+ ->save();
75
+ return $this;
76
+ }
77
+ }
78
+ //remove contact from address book
79
+ $client->deleteAddressBookContact( $helper->getSubscriberAddressBook( $websiteId ), $contactId );
80
+ }
81
+ $contactEmail->setIsSubscriber(null)
82
+ ->setSubscriberStatus(Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED);
83
+ }
84
+
85
+ //add subscriber to automation
86
+ $this->_addSubscriberToAutomation($email, $subscriber, $websiteId);
87
+
88
+ //update the contact
89
+ $contactEmail->setStoreId($storeId);
90
+ if (isset($contactId))
91
+ $contactEmail->setContactId($contactId);
92
+ //update contact
93
+ $contactEmail->save();
94
+
95
+ }catch(Exception $e){
96
+ Mage::logException($e);
97
+ Mage::helper('ddg')->getRaygunClient()->SendException($e, array(Mage::getBaseUrl('web')));
98
+ }
99
+ return $this;
100
+ }
101
+
102
+ private function _addSubscriberToAutomation($email, $subscriber, $websiteId){
103
+
104
+ $storeId = $subscriber->getStoreId();
105
+ $store = Mage::app()->getStore($storeId);
106
+ $programId = Mage::helper( 'ddg' )->getAutomationIdByType( 'XML_PATH_CONNECTOR_AUTOMATION_STUDIO_SUBSCRIBER', $websiteId );
107
+ //not mapped ignore
108
+ if (! $programId)
109
+ return;
110
+ try {
111
+ //check the subscriber alredy exists
112
+ $enrolment = Mage::getModel('ddg_automation/automation')->getCollection()
113
+ ->addFieldToFilter('email', $email)
114
+ ->addFieldToFilter('automation_type', Dotdigitalgroup_Email_Model_Automation::AUTOMATION_TYPE_NEW_SUBSCRIBER)
115
+ ->addFieldToFilter('website_id', $websiteId)
116
+ ->getFirstItem();
117
+
118
+ //add new subscriber to automation
119
+ if (! $enrolment->getId()) {
120
+ //save subscriber to the queue
121
+ $automation = Mage::getModel( 'ddg_automation/automation' );
122
+ $automation->setEmail( $email )
123
+ ->setAutomationType( Dotdigitalgroup_Email_Model_Automation::AUTOMATION_TYPE_NEW_SUBSCRIBER )
124
+ ->setEnrolmentStatus( Dotdigitalgroup_Email_Model_Automation::AUTOMATION_STATUS_PENDING )
125
+ ->setTypeId( $subscriber->getId() )
126
+ ->setWebsiteId( $websiteId )
127
+ ->setStoreName( $store->getName() )
128
+ ->setProgramId( $programId );
129
+ $automation->save();
130
+ }
131
+ }catch(Exception $e){
132
+ Mage::logException($e);
133
+ }
134
+ }
135
+
136
+ }
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,192 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $apiEnabled = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED, $website);
33
+ $enabled = (bool)$website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_SUBSCRIBER_ENABLED);
34
+ $addressBook = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SUBSCRIBERS_ADDRESS_BOOK_ID);
35
+
36
+ //enabled and mapped
37
+ if ($enabled && $addressBook && $apiEnabled) {
38
+
39
+ //ready to start sync
40
+ if (!$this->_countSubscriber)
41
+ $helper->log('---------------------- Start subscriber sync -------------------');
42
+
43
+ $numUpdated = $this->exportSubscribersPerWebsite($website);
44
+ // show message for any number of customers
45
+ if ($numUpdated)
46
+ $response['message'] .= '</br>' . $website->getName() . ', updated subscribers = ' . $numUpdated;
47
+
48
+ }
49
+ }
50
+
51
+ //global number of subscribers to set the message
52
+ if ($this->_countSubscriber) {
53
+ //reponse message
54
+ $message = 'Total time for sync : ' . gmdate("H:i:s", microtime(true) - $this->_start);
55
+
56
+ //put the message in front
57
+ $message .= $response['message'];
58
+ $result['message'] = $message;
59
+ }
60
+
61
+ return $response;
62
+ }
63
+
64
+ /**
65
+ * Export subscriber per website.
66
+ * @param Mage_Core_Model_Website $website
67
+ *
68
+ * @return int
69
+ */
70
+ public function exportSubscribersPerWebsite(Mage_Core_Model_Website $website)
71
+ {
72
+ $updated = 0;
73
+ $fileHelper = Mage::helper('ddg/file');
74
+ $limit = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_LIMIT);
75
+ $subscribers = Mage::getModel('ddg_automation/contact')->getSubscribersToImport($website, $limit);
76
+ if (count($subscribers)) {
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
+ //register in queue with importer
97
+ Mage::getModel('ddg_automation/importer')->registerQueue(
98
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_SUBSCRIBERS,
99
+ '',
100
+ Dotdigitalgroup_Email_Model_Importer::MODE_BULK,
101
+ $website->getId(),
102
+ $subscribersFilename
103
+ );
104
+ }
105
+ //add updated number for the website
106
+ $this->_countSubscriber += $updated;
107
+ return $updated;
108
+ }
109
+
110
+ /**
111
+ * Unsubscribe suppressed contacts.
112
+ * @param bool $force set 10years old
113
+ * @return mixed
114
+ */
115
+ public function unsubscribe($force = false)
116
+ {
117
+ $limit = 5;
118
+ $max_to_select = 1000;
119
+ $result['customers'] = 0;
120
+ $helper = Mage::helper('ddg');
121
+ $date = Mage::app()->getLocale()->date()->subHour(24);
122
+ // force sync all customers
123
+ if($force)
124
+ $date = $date->subYear(10);
125
+ // datetime format string
126
+ $dateString = $date->toString(Zend_Date::W3C);
127
+ /**
128
+ * 1. Sync all suppressed for each store
129
+ */
130
+ foreach (Mage::app()->getWebsites(true) as $website) {
131
+
132
+ $enabled = (bool)$website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED);
133
+
134
+ //no enabled and valid credentials
135
+ if (! $enabled)
136
+ continue;
137
+
138
+ $skip = $i = 0;
139
+ $contacts = array();
140
+ $client = Mage::helper('ddg')->getWebsiteApiClient($website);
141
+
142
+
143
+ //there is a maximum of request we need to loop to get more suppressed contacts
144
+ for ($i=0; $i<= $limit;$i++) {
145
+ $apiContacts = $client->getContactsSuppressedSinceDate($dateString, $max_to_select , $skip);
146
+
147
+ // skip no more contacts or the api request failed
148
+ if(empty($apiContacts) || isset($apiContacts->message))
149
+ break;
150
+
151
+ $contacts = array_merge($contacts, $apiContacts);
152
+ $skip += 1000;
153
+ }
154
+
155
+ $subscriberBookId = $helper->getSubscriberAddressBook($website);
156
+
157
+ // suppressed contacts to unsubscibe
158
+ foreach ($contacts as $apiContact) {
159
+ if (isset($apiContact->suppressedContact)) {
160
+ $suppressedContact = $apiContact->suppressedContact;
161
+ $email = $suppressedContact->email;
162
+ $contactId = $suppressedContact->id;
163
+ try{
164
+ /**
165
+ * 2. Remove subscriber from the address book.
166
+ */
167
+ $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
168
+ if ($subscriber->getStatus() == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED) {
169
+ $subscriber->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED);
170
+ $subscriber->save();
171
+ // remove from subscriber address-book
172
+ $client->deleteAddressBookContact($subscriberBookId, $contactId);
173
+ }
174
+ //mark contact as suppressed and unsubscribe
175
+ $contactCollection = Mage::getModel('ddg_automation/contact')->getCollection()
176
+ ->addFieldToFilter('email', $email)
177
+ ->addFieldToFilter('website_id', $website->getId());
178
+
179
+ //unsubscribe from the email contact table.
180
+ foreach ($contactCollection as $contact) {
181
+ $contact->setIsSubscriber(null)
182
+ ->setSuppressed('1')->save();
183
+ }
184
+ }catch (Exception $e){
185
+ Mage::logException($e);
186
+ }
187
+ }
188
+ }
189
+ }
190
+ return $result;
191
+ }
192
+ }
app/code/community/Dotdigitalgroup/Email/Model/Order.php ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * @param $modified
87
+ *
88
+ * @return Dotdigitalgroup_Email_Model_Resource_Order_Collection
89
+ */
90
+ public function getOrdersToImport($storeIds, $limit, $orderStatuses, $modified = false)
91
+ {
92
+ $collection = $this->getCollection()
93
+ ->addFieldToFilter('store_id', array('in' => $storeIds))
94
+ ->addFieldToFilter('order_status', array('in' => $orderStatuses));
95
+
96
+ if ($modified) {
97
+ $collection
98
+ ->addFieldToFilter('email_imported', 1)
99
+ ->addFieldToFilter('modified', 1);
100
+ } else
101
+ $collection->addFieldToFilter('email_imported', array('null' => true));
102
+
103
+
104
+ $collection->getSelect()->limit($limit);
105
+ return $collection;
106
+ }
107
+
108
+ /**
109
+ * Get all sent orders older then certain days.
110
+ *
111
+ * @param $storeIds
112
+ * @param $limit
113
+ *
114
+ * @return Dotdigitalgroup_Email_Model_Resource_Order_Collection
115
+ */
116
+ public function getAllSentOrders($storeIds, $limit)
117
+ {
118
+ $collection = $this->getCollection()
119
+ ->addFieldToFilter('email_imported', 1)
120
+ ->addFieldToFilter('store_id', array('in' => $storeIds));
121
+
122
+ $collection->getSelect()->limit($limit);
123
+ return $collection->load();
124
+ }
125
+
126
+ }
app/code/community/Dotdigitalgroup/Email/Model/Quote.php ADDED
@@ -0,0 +1,189 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ private $_quoteIds;
9
+
10
+ /**
11
+ * constructor
12
+ */
13
+ public function _construct()
14
+ {
15
+ parent::_construct();
16
+ $this->_init('ddg_automation/quote');
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
+ }else {
29
+ $this->setUpdatedAt($now);
30
+ }
31
+ return $this;
32
+ }
33
+
34
+ /**
35
+ * sync
36
+ *
37
+ * @return array
38
+ */
39
+ public function sync()
40
+ {
41
+ $response = array('success' => true, 'message' => '');
42
+ $helper = Mage::helper('ddg');
43
+ //resource allocation
44
+ $helper->allowResourceFullExecution();
45
+
46
+ foreach (Mage::app()->getWebsites(true) as $website) {
47
+ $apiEnabled = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED, $website);
48
+ $enabled = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_QUOTE_ENABLED, $website);
49
+ if ($enabled && $apiEnabled) {
50
+ //using bulk api
51
+ $helper->log('---------- Start quote bulk sync ----------');
52
+ $this->_start = microtime(true);
53
+ $this->_exportQuoteForWebsite($website);
54
+ //send quote as transactional data
55
+ if (isset($this->_quotes[$website->getId()])) {
56
+ $websiteQuotes = $this->_quotes[$website->getId()];
57
+ //register in queue with importer
58
+ $check = Mage::getModel('ddg_automation/importer')->registerQueue(
59
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_QUOTE,
60
+ $websiteQuotes,
61
+ Dotdigitalgroup_Email_Model_Importer::MODE_BULK,
62
+ $website->getId()
63
+ );
64
+ //set imported
65
+ if ($check) {
66
+ $this->getResource()->setImported($this->_quoteIds);
67
+ }
68
+ }
69
+ $message = 'Total time for quote bulk sync : ' . gmdate("H:i:s", microtime(true) - $this->_start);
70
+ $helper->log($message);
71
+
72
+ //update quotes
73
+ $this->_exportQuoteForWebsiteInSingle($website);
74
+
75
+ }
76
+ }
77
+ $response['message'] = "quote updated: ". $this->_count;
78
+ return $response;
79
+ }
80
+
81
+ /**
82
+ * export quotes to website
83
+ *
84
+ * @param Mage_Core_Model_Website $website
85
+ */
86
+ private function _exportQuoteForWebsite(Mage_Core_Model_Website $website)
87
+ {
88
+ try{
89
+ //reset quotes
90
+ $this->_quotes = array();
91
+ $this->_quoteIds = array();
92
+ $limit = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_TRANSACTIONAL_DATA_SYNC_LIMIT, $website);
93
+ $collection = $this->_getQuoteToImport($website, $limit);
94
+ foreach($collection as $emailQuote){
95
+ $store = Mage::app()->getStore($emailQuote->getStoreId());
96
+ $quote = Mage::getModel('sales/quote')->setStore($store)->load($emailQuote->getQuoteId());
97
+ if($quote->getId())
98
+ {
99
+ $connectorQuote = Mage::getModel('ddg_automation/connector_quote', $quote);
100
+ $this->_quotes[$website->getId()][] = $connectorQuote;
101
+ }
102
+ $this->_quoteIds[] = $emailQuote->getQuoteId();
103
+ $this->_count++;
104
+ }
105
+ }catch(Exception $e){
106
+ Mage::logException($e);
107
+ }
108
+ }
109
+
110
+ /**
111
+ * get quotes to import
112
+ *
113
+ * @param Mage_Core_Model_Website $website
114
+ * @param int $limit
115
+ * @param $modified
116
+ *
117
+ * @return mixed
118
+ */
119
+ private function _getQuoteToImport(Mage_Core_Model_Website $website, $limit = 100, $modified = false)
120
+ {
121
+ $collection = $this->getCollection()
122
+ ->addFieldToFilter('store_id', array('in' => $website->getStoreIds()))
123
+ ->addFieldToFilter('customer_id', array('notnull' => true));
124
+
125
+ if ($modified) {
126
+ $collection->addFieldToFilter('modified', 1)
127
+ ->addFieldToFilter('imported', 1);
128
+ } else {
129
+ $collection->addFieldToFilter('imported', array('null' => true));
130
+ }
131
+
132
+ $collection->getSelect()->limit($limit);
133
+ return $collection;
134
+ }
135
+
136
+ /**
137
+ * update quotes for website in single
138
+ *
139
+ * @param Mage_Core_Model_Website $website
140
+ */
141
+ private function _exportQuoteForWebsiteInSingle(Mage_Core_Model_Website $website)
142
+ {
143
+ try {
144
+ $limit = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_TRANSACTIONAL_DATA_SYNC_LIMIT, $website);
145
+ $collection = $this->_getQuoteToImport($website, $limit, true);
146
+ foreach ($collection as $emailQuote) {
147
+ $store = Mage::app()->getStore($emailQuote->getStoreId());
148
+ $quote = Mage::getModel('sales/quote')->setStore($store)->load($emailQuote->getQuoteId());
149
+ if($quote->getId())
150
+ {
151
+ $connectorQuote = Mage::getModel('ddg_automation/connector_quote', $quote);
152
+ //register in queue with importer
153
+ $check = Mage::getModel('ddg_automation/importer')->registerQueue(
154
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_QUOTE,
155
+ $connectorQuote,
156
+ Dotdigitalgroup_Email_Model_Importer::MODE_SINGLE,
157
+ $website->getId()
158
+ );
159
+ if ($check) {
160
+ $message = 'Quote updated : ' . $emailQuote->getQuoteId();
161
+ Mage::helper('ddg')->log($message);
162
+ $emailQuote->setModified(null)->save();
163
+ $this->_count++;
164
+ }
165
+ }
166
+ }
167
+ } catch (Exception $e) {
168
+ Mage::logException($e);
169
+ }
170
+ }
171
+
172
+ /**
173
+ * load quote from connector table
174
+ *
175
+ * @param $quoteId
176
+ * @return bool
177
+ */
178
+ public function loadQuote($quoteId)
179
+ {
180
+ $collection = $this->getCollection();
181
+ $collection->addFieldToFilter('quote_id', $quoteId)
182
+ ->setPageSize(1);
183
+
184
+ if ($collection->count()) {
185
+ return $collection->getFirstItem();
186
+ }
187
+ return false;
188
+ }
189
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Automation.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
15
+ public function updateContacts($contacts, $programStatus, $programMessage)
16
+ {
17
+ $conn = $this->_getWriteAdapter();
18
+ try {
19
+ $contactIds = array_keys($contacts);
20
+ $bind = array(
21
+ 'enrolment_status' => $programStatus,
22
+ 'message' => $programMessage,
23
+ 'updated_at' => Mage::getSingleton('core/date')->gmtDate()
24
+ );
25
+ $where = array('id IN(?)' => $contactIds);
26
+ $num = $conn->update( $this->getMainTable(),
27
+ $bind,
28
+ $where
29
+ );
30
+ return $num;
31
+ } catch ( Exception $e ) {
32
+ Mage::logException($e);
33
+ }
34
+ }
35
+
36
+ /**
37
+ * mass delete
38
+ *
39
+ * @param $automationIds
40
+ * @return Exception|int
41
+ */
42
+ public function massDelete($automationIds)
43
+ {
44
+ try {
45
+ $conn = $this->_getWriteAdapter();
46
+ $num = $conn->delete(
47
+ $this->getMainTable(),
48
+ array('id IN(?)' => $automationIds)
49
+ );
50
+ return $num;
51
+ } catch (Exception $e) {
52
+ return $e;
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Mark for resend.
58
+ *
59
+ * @param $automationIds
60
+ * @return int
61
+ */
62
+ public function massResend($automationIds)
63
+ {
64
+ try {
65
+ $conn = $this->_getWriteAdapter();
66
+ $num = $conn->update($this->getMainTable(),
67
+ array('enrolment_status' => Dotdigitalgroup_Email_Model_Automation::AUTOMATION_STATUS_PENDING),
68
+ array('id IN(?)' => $automationIds)
69
+ );
70
+ return $num;
71
+ } catch (Exception $e) {
72
+ return $e;
73
+ }
74
+ }
75
+ }
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,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
14
+ /**
15
+ * Delete mass campaigns.
16
+ *
17
+ * @param $campaignIds
18
+ * @return Exception|int
19
+ */
20
+ public function massDelete($campaignIds)
21
+ {
22
+ try {
23
+ $conn =$this->_getWriteAdapter();
24
+ $num = $conn->delete(
25
+ $this->getMainTable(),
26
+ array('id IN(?)' => $campaignIds)
27
+ );
28
+ return $num;
29
+ } catch (Exception $e) {
30
+ return $e;
31
+ }
32
+ }
33
+
34
+ /**
35
+ * Mass mark for resend campaigns.
36
+ *
37
+ * @param $campaignIds
38
+ * @return Exception|int
39
+ */
40
+ public function massResend($campaignIds)
41
+ {
42
+ try {
43
+ $conn = $this->_getWriteAdapter();
44
+ $num = $conn->update(
45
+ $this->getMainTable(),
46
+ array('is_sent' => new Zend_Db_Expr('null')),
47
+ array('id IN(?)' => $campaignIds)
48
+ );
49
+ return $num;
50
+ } catch (Exception $e) {
51
+ return $e;
52
+ }
53
+ }
54
+ }
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/Catalog.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Catalog extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+ /**
6
+ * constructor.
7
+ */
8
+ protected function _construct()
9
+ {
10
+ $this->_init('ddg_automation/catalog', 'id');
11
+
12
+ }
13
+
14
+ /**
15
+ * Reset for re-import.
16
+ *
17
+ * @return int
18
+ */
19
+ public function reset()
20
+ {
21
+ $conn = $this->_getWriteAdapter();
22
+ try{
23
+ $num = $conn->update($this->getMainTable(),
24
+ array('imported' => new Zend_Db_Expr('null'), 'modified' => new Zend_Db_Expr('null'))
25
+ );
26
+ return $num;
27
+ }catch (Exception $e){
28
+ Mage::logException($e);
29
+ }
30
+ }
31
+
32
+ /**
33
+ * set imported in bulk query. if modified true then set modified to null in bulk query.
34
+ *
35
+ * @param $ids
36
+ * @param $modified
37
+ */
38
+ public function setImported($ids, $modified = false)
39
+ {
40
+ try{
41
+ $write = $this->_getWriteAdapter();
42
+ $tableName = $this->getMainTable();
43
+ $ids = implode(', ', $ids);
44
+ $now = Mage::getSingleton('core/date')->gmtDate();
45
+ if($modified)
46
+ $write->update($tableName, array('modified' => new Zend_Db_Expr('null'), 'updated_at' => $now), "product_id IN ($ids)");
47
+ else
48
+ $write->update($tableName, array('imported' => 1, 'updated_at' => $now), "product_id IN ($ids)");
49
+ }catch (Exception $e){
50
+ Mage::logException($e);
51
+ }
52
+ }
53
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Catalog/Collection.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Catalog_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/catalog');
12
+ }
13
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Contact.php ADDED
@@ -0,0 +1,324 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
15
+ /**
16
+ * Remove contact id's.
17
+ *
18
+ * @return int
19
+ */
20
+ public function deleteContactIds()
21
+ {
22
+ try{
23
+ $conn = $this->getReadConnection();
24
+ $num = $conn->update($this->getMainTable(),
25
+ array('contact_id' => new Zend_Db_Expr('null')),
26
+ $conn->quoteInto('contact_id is ?', new Zend_Db_Expr('not null'))
27
+ );
28
+ return $num;
29
+ }catch (Exception $e){
30
+ Mage::logException($e);
31
+ Mage::helper('ddg')->rayLog('300', $e);
32
+ }
33
+ }
34
+
35
+ /**
36
+ * Reset the imported contacts
37
+ * @return int
38
+ */
39
+ public function resetAllContacts()
40
+ {
41
+ try{
42
+ $conn = $this->_getWriteAdapter();
43
+ $num = $conn->update($this->getMainTable(),
44
+ array('email_imported' => new Zend_Db_Expr('null')),
45
+ $conn->quoteInto('email_imported is ?', new Zend_Db_Expr('not null'))
46
+ );
47
+ return $num;
48
+ }catch (Exception $e){
49
+ Mage::logException($e);
50
+ Mage::helper('ddg')->rayLog('300', $e);
51
+ }
52
+ }
53
+
54
+ /**
55
+ * Set all imported subscribers for re-import.
56
+ *
57
+ * @return int
58
+ */
59
+ public function resetSubscribers()
60
+ {
61
+ try {
62
+ $conn = $this->_getWriteAdapter();
63
+ $num = $conn->update(
64
+ $this->getMainTable(),
65
+ array('subscriber_imported' => new Zend_Db_Expr( 'null' ) ),
66
+ $conn->quoteInto('subscriber_imported is ?', new Zend_Db_Expr('not null')));
67
+ return $num;
68
+ } catch ( Exception $e ) {
69
+ Mage::logException($e);
70
+ Mage::helper('ddg')->sendRaygunException($e);
71
+ }
72
+ }
73
+
74
+ /**
75
+ * Reset the imported contacts as guest
76
+ * @return int
77
+ */
78
+ public function resetAllGuestContacts()
79
+ {
80
+ try {
81
+ $conn = $this->_getWriteAdapter();
82
+ $where = array();
83
+ $where[] = $conn->quoteInto('email_imported is ?', new Zend_Db_Expr('not null'));
84
+ $where[] = $conn->quoteInto('is_guest is ?', new Zend_Db_Expr('not null'));
85
+
86
+ $num = $conn->update($this->getMainTable(),
87
+ array('email_imported' => new Zend_Db_Expr('null')),
88
+ $where
89
+ );
90
+ return $num;
91
+ } catch (Exception $e) {
92
+ Mage::logException($e);
93
+ Mage::helper('ddg')->rayLog('300', $e);
94
+ }
95
+ }
96
+
97
+ /**
98
+ * populate and cleanup
99
+ */
100
+ public function populateAndCleanup()
101
+ {
102
+ $write = $this->_getWriteAdapter();
103
+ $contactTable = $this->getMainTable();
104
+ $select = $write->select();
105
+
106
+ //populate customers to email_contact
107
+ $emailContacts = Mage::getModel('ddg_automation/contact')
108
+ ->getCollection()
109
+ ->getColumnValues('customer_id');
110
+ $emailContacts = implode(',', $emailContacts);
111
+
112
+ $select
113
+ ->from(
114
+ array('customer' => $this->getReadConnection()->getTableName('customer_entity')),
115
+ array('customer_id' => 'entity_id','email','website_id','store_id')
116
+ )
117
+ ->where("entity_id not in ($emailContacts)");
118
+
119
+ $insertArray = array('customer_id','email','website_id','store_id');
120
+ $sqlQuery = $select->insertFromSelect($contactTable, $insertArray, false);
121
+ $write->query($sqlQuery);
122
+
123
+ //remove contact with customer id set and no customer
124
+ $select->reset()
125
+ ->from(
126
+ array('c' => $contactTable),
127
+ array('c.customer_id')
128
+ )
129
+ ->joinLeft(
130
+ array('e' => $this->getReadConnection()->getTableName('customer_entity')),
131
+ "c.customer_id = e.entity_id"
132
+ )
133
+ ->where('e.entity_id is NULL');
134
+ $deleteSql = $select->deleteFromSelect('c');
135
+ $write->query($deleteSql);
136
+ }
137
+
138
+ /**
139
+ * Re-set all tables
140
+ */
141
+ public function resetAllTables()
142
+ {
143
+ $conn = $this->_getWriteAdapter();
144
+ try{
145
+ //remove dotmailer code from core_resource table
146
+ $cond = $conn->quoteInto('code = ?', 'email_connector_setup');
147
+ $conn->delete($this->getReadConnection()->getTableName('core_resource'), $cond);
148
+
149
+ //clean cache
150
+ Mage::app()->getCacheInstance()->flush();
151
+
152
+ }catch (Exception $e){
153
+ Mage::logException($e);
154
+ }
155
+ }
156
+
157
+ public function update($customer)
158
+ {
159
+ $write = $this->_getWriteAdapter();
160
+ if(is_array($customer)){
161
+ $ids = implode(', ', $customer);
162
+ $write->update($this->getMainTable(), array('email_imported' => 1), "customer_id IN ($ids)");
163
+ }
164
+ else
165
+ $write->update($this->getMainTable(), array('email_imported' => 1), "customer_id = $customer");
166
+ }
167
+
168
+ public function populateAndCleanupRecords()
169
+ {
170
+ $write = $this->_getWriteAdapter();
171
+ $contactTable = $this->getMainTable();
172
+ $select = $write->select();
173
+
174
+ //check subscriber and update in one query
175
+ $select->joinLeft(
176
+ array('s' => $this->getReadConnection()->getTableName('newsletter_subscriber')),
177
+ "c.customer_id = s.customer_id",
178
+ array('subscriber_status' => 's.subscriber_status')
179
+ );
180
+ //update sql statement
181
+ $updateSql = $select->crossUpdateFromSelect(array('c' => $contactTable));
182
+ //run query and update subscriber_status column
183
+ $write->query($updateSql);
184
+ //update is_subscriber column if subscriber_status is not null
185
+ $write->update($contactTable, array('is_subscriber' => 1), "subscriber_status is not null");
186
+
187
+
188
+ //remove contact with customer id set and no customer
189
+ $select->reset()
190
+ ->from(
191
+ array('c' => $contactTable),
192
+ array('c.customer_id')
193
+ )
194
+ ->joinLeft(
195
+ array('e' => $this->getReadConnection()->getTableName('customer_entity')),
196
+ "c.customer_id = e.entity_id"
197
+ )
198
+ ->where('e.entity_id is NULL');
199
+ //delete sql statement
200
+ $deleteSql = $select->deleteFromSelect('c');
201
+ //run query
202
+ $write->query($deleteSql);
203
+ }
204
+
205
+ /**
206
+ * Mass delete contacts.
207
+ *
208
+ * @param $contactIds
209
+ * @return Exception|int
210
+ */
211
+ public function massDelete($contactIds)
212
+ {
213
+ try {
214
+ $conn = $this->_getWriteAdapter();
215
+ $num = $conn->delete(
216
+ $this->getMainTable(),
217
+ array('email_contact_id IN(?)' => $contactIds)
218
+ );
219
+ return $num;
220
+ } catch (Exception $e) {
221
+ return $e;
222
+ }
223
+ }
224
+
225
+ /**
226
+ * Mark a contact to be resend.
227
+ *
228
+ * @param $contactIds
229
+ * @return Exception|int
230
+ */
231
+ public function massResend($contactIds)
232
+ {
233
+ try {
234
+ $conn = $this->_getWriteAdapter();
235
+ $num = $conn->update(
236
+ $this->getMainTable(),
237
+ array('email_imported' => new Zend_Db_Expr('null')),
238
+ array('email_contact_id IN(?)' => $contactIds)
239
+ );
240
+ return $num;
241
+ } catch (Exception $e) {
242
+ return $e;
243
+ }
244
+ }
245
+
246
+ /**
247
+ * prepare recency part of RFM
248
+ *
249
+ * @param $collection
250
+ * @return array
251
+ */
252
+ public function prepareRecency($collection)
253
+ {
254
+ $select = $collection->getSelect()
255
+ ->reset(Zend_Db_Select::COLUMNS)
256
+ ->reset(Zend_Db_Select::ORDER)
257
+ ->columns(array(
258
+ 'last_order_days_ago' => "DATEDIFF(date(NOW()) , date(MAX(created_at)))"
259
+ ))->order('last_order_days_ago');
260
+ return $this->getReadConnection()->fetchCol($select);
261
+ }
262
+
263
+ /**
264
+ * prepare frequency part of RFM
265
+ *
266
+ * @param $collection
267
+ * @return array
268
+ */
269
+ public function prepareFrequency($collection)
270
+ {
271
+ $select = $collection->getSelect()
272
+ ->reset(Zend_Db_Select::COLUMNS)
273
+ ->columns(array(
274
+ 'customer_total_orders' => "count(*)",
275
+ ))->order('customer_total_orders');
276
+ return $this->getReadConnection()->fetchCol($select);
277
+ }
278
+
279
+ /**
280
+ * prepare monetary part of RFM
281
+ *
282
+ * @param $collection
283
+ * @return array
284
+ */
285
+ public function prepareMonetary($collection)
286
+ {
287
+ $expr = $this->getSalesAmountExpression($collection);
288
+ $select = $collection->getSelect()
289
+ ->reset(Zend_Db_Select::COLUMNS)
290
+ ->reset(Zend_Db_Select::ORDER)
291
+ ->columns(array(
292
+ 'customer_average_order_value' => "SUM({$expr})/count(*)",
293
+ ))->order('customer_average_order_value');
294
+ return $this->getReadConnection()->fetchCol($select);
295
+ }
296
+
297
+ /**
298
+ * get sales amount expression
299
+ *
300
+ * @param $collection
301
+ * @return string
302
+ */
303
+ public function getSalesAmountExpression($collection)
304
+ {
305
+ $adapter = $collection->getConnection();
306
+ $expressionTransferObject = new Varien_Object(array(
307
+ 'expression' => '%s - %s - %s - (%s - %s - %s)',
308
+ 'arguments' => array(
309
+ $adapter->getIfNullSql('main_table.base_total_invoiced', 0),
310
+ $adapter->getIfNullSql('main_table.base_tax_invoiced', 0),
311
+ $adapter->getIfNullSql('main_table.base_shipping_invoiced', 0),
312
+ $adapter->getIfNullSql('main_table.base_total_refunded', 0),
313
+ $adapter->getIfNullSql('main_table.base_tax_refunded', 0),
314
+ $adapter->getIfNullSql('main_table.base_shipping_refunded', 0),
315
+ )
316
+ ));
317
+
318
+ return vsprintf(
319
+ $expressionTransferObject->getExpression(),
320
+ $expressionTransferObject->getArguments()
321
+ );
322
+
323
+ }
324
+ }
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/Importer.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Importer extends Mage_Core_Model_Resource_Db_Abstract
4
+ {
5
+ /**
6
+ * cosntructor.
7
+ */
8
+ protected function _construct()
9
+ {
10
+ $this->_init('ddg_automation/importer', 'id');
11
+ }
12
+
13
+ /**
14
+ * Mark a contact to be resend.
15
+ *
16
+ * @param $ids
17
+ * @return Exception|int
18
+ */
19
+ public function massResend($ids)
20
+ {
21
+ try {
22
+ $conn = $this->_getWriteAdapter();
23
+ $num = $conn->update($this->getMainTable(),
24
+ array('import_status' => 0),
25
+ array('id IN(?)' => $ids)
26
+ );
27
+ return $num;
28
+ } catch (Exception $e) {
29
+ return $e;
30
+ }
31
+ }
32
+
33
+ /**
34
+ * Mass delete contacts.
35
+ *
36
+ * @param $ids
37
+ * @return Exception|int
38
+ */
39
+ public function massDelete($ids)
40
+ {
41
+ try {
42
+ $conn = $this->_getWriteAdapter();
43
+ $num = $conn->delete($this->getMainTable(),
44
+ array('id IN(?)' => $ids)
45
+ );
46
+ return $num;
47
+ } catch (Exception $e) {
48
+ return $e;
49
+ }
50
+ }
51
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Importer/Collection.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Importer_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/importer');
12
+ }
13
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Order.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
13
+ /**
14
+ * get sales_flat_order table description
15
+ *
16
+ * @return array
17
+ */
18
+ public function getOrderTableDescription()
19
+ {
20
+ return $this->getReadConnection()->describeTable($this->getTable('sales/order'));
21
+ }
22
+
23
+ /**
24
+ * Reset the email order for reimport.
25
+ *
26
+ * @return int
27
+ */
28
+ public function resetOrders()
29
+ {
30
+ try{
31
+ $conn = $this->_getWriteAdapter();
32
+ $num = $conn->update($this->getMainTable(),
33
+ array('email_imported' => new Zend_Db_Expr('null'), 'modified' => new Zend_Db_Expr('null')),
34
+ $conn->quoteInto('email_imported is ?', new Zend_Db_Expr('not null'))
35
+ );
36
+ return $num;
37
+ }catch (Exception $e){
38
+ Mage::logException($e);
39
+ }
40
+ }
41
+ }
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,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
13
+ /**
14
+ * get sales_flat_quote table description
15
+ *
16
+ * @return array
17
+ */
18
+ public function getQuoteTableDescription()
19
+ {
20
+ return $this->getReadConnection()->describeTable($this->getTable('sales/quote'));
21
+ }
22
+
23
+ /**
24
+ * Reset the email quote for re-import.
25
+ *
26
+ * @return int
27
+ */
28
+ public function resetQuotes()
29
+ {
30
+ $conn = $this->_getWriteAdapter();
31
+ try{
32
+ $num = $conn->update(
33
+ $this->getMainTable(),
34
+ array('imported' => new Zend_Db_Expr('null'), 'modified' => new Zend_Db_Expr('null'))
35
+ );
36
+ return $num;
37
+ }catch (Exception $e){
38
+ Mage::logException($e);
39
+ }
40
+ }
41
+
42
+ /**
43
+ * set imported in bulk query
44
+ *
45
+ * @param $ids
46
+ */
47
+ public function setImported($ids)
48
+ {
49
+ try{
50
+ $write = $this->_getWriteAdapter();
51
+ $tableName = $this->getMainTable();
52
+ $ids = implode(', ', $ids);
53
+ $now = Mage::getSingleton('core/date')->gmtDate();
54
+ $write->update($tableName, array('imported' => 1, 'updated_at' => $now, 'modified' => new Zend_Db_Expr('null')), "quote_id IN ($ids)");
55
+ }catch (Exception $e){
56
+ Mage::logException($e);
57
+ }
58
+ }
59
+ }
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,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
14
+ /**
15
+ * Reset the email reviews for reimport.
16
+ *
17
+ * @return int
18
+ */
19
+ public function reset()
20
+ {
21
+ $conn = $this->_getWriteAdapter();
22
+ try{
23
+ $num = $conn->update($this->getMainTable(),
24
+ array('review_imported' => new Zend_Db_Expr('null')),
25
+ $conn->quoteInto('review_imported is ?', new Zend_Db_Expr('not null'))
26
+ );
27
+ return $num;
28
+ }catch (Exception $e){
29
+ Mage::logException($e);
30
+ }
31
+ }
32
+
33
+ /**
34
+ * set imported in bulk query
35
+ *
36
+ * @param $ids
37
+ */
38
+ public function setImported($ids)
39
+ {
40
+ try{
41
+ $write = $this->_getWriteAdapter();
42
+ $tableName = $this->getMainTable();
43
+ $ids = implode(', ', $ids);
44
+ $now = Mage::getSingleton('core/date')->gmtDate();
45
+ $write->update($tableName, array('review_imported' => 1, 'updated_at' => $now), "review_id IN ($ids)");
46
+ }catch (Exception $e){
47
+ Mage::logException($e);
48
+ }
49
+ }
50
+ }
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/Rules.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Rules extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+ /**
6
+ * constructor.
7
+ */
8
+ protected function _construct()
9
+ {
10
+ $this->_init('ddg_automation/rules', 'id');
11
+
12
+ }
13
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Rules/Collection.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Rules_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/rules');
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,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
14
+ /**
15
+ * Reset the email reviews for re-import.
16
+ *
17
+ * @return int
18
+ */
19
+ public function reset()
20
+ {
21
+ $conn = $this->_getWriteAdapter();
22
+ try{
23
+ $num = $conn->update($this->getMainTable(),
24
+ array('wishlist_imported' => new Zend_Db_Expr('null'), 'wishlist_modified' => new Zend_Db_Expr('null'))
25
+ );
26
+ return $num;
27
+ }catch (Exception $e){
28
+ Mage::logException($e);
29
+ }
30
+ }
31
+
32
+ /**
33
+ * set imported in bulk query
34
+ *
35
+ * @param $ids
36
+ * @param $modified
37
+ */
38
+ public function setImported($ids, $modified = false)
39
+ {
40
+ try{
41
+ $write = $this->_getWriteAdapter();
42
+ $tableName = $this->getMainTable();
43
+ $ids = implode(', ', $ids);
44
+ $now = Mage::getSingleton('core/date')->gmtDate();
45
+ if($modified)
46
+ $write->update($tableName, array('wishlist_modified' => new Zend_Db_Expr('null'), 'updated_at' => $now), "wishlist_id IN ($ids)");
47
+ else
48
+ $write->update($tableName, array('wishlist_imported' => 1, 'updated_at' => $now), "wishlist_id IN ($ids)");
49
+ }catch (Exception $e){
50
+ Mage::logException($e);
51
+ }
52
+ }
53
+ }
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,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ private $_reviewIds;
9
+
10
+ const EMAIL_REVIEW_IMPORTED = 1;
11
+
12
+ /**
13
+ * constructor
14
+ */
15
+ public function _construct()
16
+ {
17
+ parent::_construct();
18
+ $this->_init('ddg_automation/review');
19
+ }
20
+
21
+ /**
22
+ * @return $this|Mage_Core_Model_Abstract
23
+ */
24
+ protected function _beforeSave()
25
+ {
26
+ parent::_beforeSave();
27
+ $now = Mage::getSingleton('core/date')->gmtDate();
28
+ if ($this->isObjectNew()) {
29
+ $this->setCreatedAt($now);
30
+ }else {
31
+ $this->setUpdatedAt($now);
32
+ }
33
+ return $this;
34
+ }
35
+
36
+ public function sync()
37
+ {
38
+ $response = array('success' => true, 'message' => '');
39
+ $helper = Mage::helper('ddg');
40
+ $this->_countReviews = 0;
41
+ $this->_reviews = array();
42
+ $this->_start = microtime(true);
43
+ //resource allocation
44
+ $helper->allowResourceFullExecution();
45
+ foreach (Mage::app()->getWebsites(true) as $website) {
46
+
47
+ $enabled = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED, $website);
48
+ $sync = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_REVIEW_ENABLED, $website);
49
+
50
+ if ($enabled && $sync) {
51
+ //start the sync
52
+ if (! $this->_countReviews)
53
+ $helper->log('---------- Start reviews sync ----------');
54
+ $this->_exportReviewsForWebsite($website);
55
+ }
56
+
57
+ if (isset($this->_reviews[$website->getId()])) {
58
+ $reviews = $this->_reviews[$website->getId()];
59
+ //send reviews as transactional data
60
+ //register in queue with importer
61
+ $check = Mage::getModel('ddg_automation/importer')->registerQueue(
62
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_REVIEWS,
63
+ $reviews,
64
+ Dotdigitalgroup_Email_Model_Importer::MODE_BULK,
65
+ $website->getId()
66
+ );
67
+ //if no error then set imported
68
+ if ($check) {
69
+ $this->getResource()->setImported($this->_reviewIds);
70
+ }
71
+ $this->_countReviews += count($reviews);
72
+ }
73
+ }
74
+
75
+ if ($this->_countReviews) {
76
+ $message = 'Total time for sync : ' . gmdate( "H:i:s", microtime( true ) - $this->_start ) . ', Total synced = ' . $this->_countReviews;
77
+ $helper->log( $message );
78
+ $response['message'] = $message;
79
+ }
80
+ return $response;
81
+ }
82
+
83
+ private function _exportReviewsForWebsite(Mage_Core_Model_Website $website)
84
+ {
85
+ $limit = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_TRANSACTIONAL_DATA_SYNC_LIMIT, $website);
86
+ $emailReviews = $this->_getReviewsToExport($website, $limit);
87
+ $this->_reviewIds = $emailReviews->getColumnValues('review_id');
88
+
89
+ if(!empty($this->_reviewIds)){
90
+ $reviews = Mage::getModel('review/review')
91
+ ->getCollection()
92
+ ->addFieldToFilter('main_table.review_id', array('in' => $this->_reviewIds))
93
+ ->addFieldToFilter('customer_id', array('notnull' => 'true'));
94
+
95
+ $reviews->getSelect()
96
+ ->joinLeft(
97
+ array('c' => 'customer_entity'),
98
+ 'c.entity_id = customer_id',
99
+ array('email','store_id')
100
+ );
101
+
102
+ if($reviews->getSize()){
103
+ foreach($reviews as $mageReview){
104
+ try {
105
+ $product = Mage::getModel('catalog/product')
106
+ ->getCollection()
107
+ ->addIdFilter($mageReview->getEntityPkValue())
108
+ ->setStoreId($mageReview->getStoreId())
109
+ ->addAttributeToSelect(array('product_url', 'name', 'store_id', 'small_image'))
110
+ ->setPage(1,1)
111
+ ->getFirstItem();
112
+
113
+ $connectorReview = Mage::getModel('ddg_automation/customer_review')
114
+ ->setReviewData($mageReview)
115
+ ->setProduct($product);
116
+
117
+ $votesCollection = Mage::getModel('rating/rating_option_vote')
118
+ ->getResourceCollection()
119
+ ->setReviewFilter($mageReview->getReviewId());
120
+ $votesCollection->getSelect()->join(
121
+ array('rating'=> 'rating'),
122
+ 'rating.rating_id = main_table.rating_id',
123
+ array('rating_code' => 'rating.rating_code')
124
+ );
125
+
126
+ foreach($votesCollection as $ratingItem){
127
+ $rating = Mage::getModel('ddg_automation/customer_review_rating', $ratingItem);
128
+ $connectorReview->createRating($ratingItem->getRatingCode(), $rating);
129
+ }
130
+ $this->_reviews[$website->getId()][] = $connectorReview;
131
+ }catch(Exception $e){
132
+ Mage::logException($e);
133
+ }
134
+ }
135
+ }
136
+ }
137
+ }
138
+
139
+ private function _getReviewsToExport(Mage_Core_Model_Website $website, $limit = 100)
140
+ {
141
+ return $this->getCollection()
142
+ ->addFieldToFilter('review_imported', array('null' => 'true'))
143
+ ->addFieldToFilter('store_id', array('in' => $website->getStoreIds()))
144
+ ->setPageSize($limit);
145
+ }
146
+ }
app/code/community/Dotdigitalgroup/Email/Model/Rules.php ADDED
@@ -0,0 +1,436 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Rules extends Mage_Core_Model_Abstract
4
+ {
5
+ const ABANDONED = 1;
6
+ const REVIEW = 2;
7
+
8
+ private $_defaultOptions;
9
+ private $_conditionMap;
10
+ private $_attributeMapForQuote;
11
+ private $_attributeMapForOrder;
12
+ private $_productAttribute;
13
+ private $_used = array();
14
+
15
+ /**
16
+ * constructor
17
+ */
18
+ public function _construct()
19
+ {
20
+ $this->_defaultOptions = Mage::getModel('ddg_automation/adminhtml_source_rules_type')->defaultOptions();
21
+ $this->_conditionMap =
22
+ array(
23
+ 'eq' => 'neq',
24
+ 'neq' => 'eq',
25
+ 'gteq' => 'lteq',
26
+ 'lteq' => 'gteq',
27
+ 'gt' => 'lt',
28
+ 'lt' => 'gt',
29
+ 'like' => 'nlike',
30
+ 'nlike' => 'like'
31
+ );
32
+ $this->_attributeMapForQuote =
33
+ array(
34
+ 'method' => 'method',
35
+ 'shipping_method' => 'shipping_method',
36
+ 'country_id' => 'country_id',
37
+ 'city' => 'city',
38
+ 'region_id' => 'region_id',
39
+ 'customer_group_id' => 'main_table.customer_group_id',
40
+ 'coupon_code' => 'main_table.coupon_code',
41
+ 'subtotal' => 'main_table.subtotal',
42
+ 'grand_total' => 'main_table.grand_total',
43
+ 'items_qty' => 'main_table.items_qty',
44
+ 'customer_email' => 'main_table.customer_email',
45
+ );
46
+ $this->_attributeMapForOrder =
47
+ array(
48
+ 'method' => 'method',
49
+ 'shipping_method' => 'main_table.shipping_method',
50
+ 'country_id' => 'country_id',
51
+ 'city' => 'city',
52
+ 'region_id' => 'region_id',
53
+ 'customer_group_id' => 'main_table.customer_group_id',
54
+ 'coupon_code' => 'main_table.coupon_code',
55
+ 'subtotal' => 'main_table.subtotal',
56
+ 'grand_total' => 'main_table.grand_total',
57
+ 'items_qty' => 'items_qty',
58
+ 'customer_email' => 'main_table.customer_email',
59
+ );
60
+ parent::_construct();
61
+ $this->_init('ddg_automation/rules');
62
+ }
63
+
64
+ /**
65
+ * before save
66
+ *
67
+ * @return $this|Mage_Core_Model_Abstract
68
+ */
69
+ protected function _beforeSave()
70
+ {
71
+ parent::_beforeSave();
72
+ $now = Mage::getSingleton('core/date')->gmtDate();
73
+ if ($this->isObjectNew()) {
74
+ $this->setCreatedAt($now);
75
+ }else {
76
+ $this->setUpdatedAt($now);
77
+ }
78
+ $this->setCondition(serialize($this->getCondition()));
79
+ $this->setWebsiteIds(implode(',', $this->getWebsiteIds()));
80
+ return $this;
81
+ }
82
+
83
+ /**
84
+ * after load
85
+ *
86
+ * @return $this
87
+ */
88
+ protected function _afterLoad()
89
+ {
90
+ parent::_afterLoad();
91
+ $this->setCondition(unserialize($this->getCondition()));
92
+ return $this;
93
+ }
94
+
95
+ /**
96
+ * check if rule already exist for website
97
+ *
98
+ * @param $websiteId
99
+ * @param $type
100
+ * @param bool $ruleId
101
+ * @return bool
102
+ */
103
+ public function checkWebsiteBeforeSave($websiteId, $type, $ruleId = false)
104
+ {
105
+ $collection = $this->getCollection();
106
+ $collection
107
+ ->addFieldToFilter('type', array('eq' => $type))
108
+ ->addFieldToFilter('website_ids', array('finset' => $websiteId));
109
+ if($ruleId)
110
+ $collection->addFieldToFilter('id', array('neq' => $ruleId));
111
+ $collection->setPageSize(1);
112
+
113
+ if ($collection->getSize()) {
114
+ return false;
115
+ }
116
+ return true;
117
+ }
118
+
119
+ /**
120
+ * get website active rule
121
+ *
122
+ * @param $type
123
+ * @param $websiteId
124
+ * @return array|Varien_Object
125
+ */
126
+ public function getActiveRuleForWebsite($type, $websiteId)
127
+ {
128
+ $collection = $this->getCollection();
129
+ $collection
130
+ ->addFieldToFilter('type', array('eq' => $type))
131
+ ->addFieldToFilter('status', array('eq' => 1))
132
+ ->addFieldToFilter('website_ids', array('finset' => $websiteId))
133
+ ->setPageSize(1);
134
+ if ($collection->getSize()) {
135
+ return $collection->getFirstItem();
136
+ }
137
+ return array();
138
+ }
139
+
140
+ /**
141
+ * process rule on collection
142
+ *
143
+ * @param $collection
144
+ * @param $type
145
+ * @param $websiteId
146
+ * @return mixed
147
+ */
148
+ public function process($collection, $type, $websiteId)
149
+ {
150
+ $rule = $this->getActiveRuleForWebsite($type, $websiteId);
151
+ //if no rule then return the collection untouched
152
+ if(empty($rule))
153
+ return $collection;
154
+
155
+ //if rule has no conditions then return the collection untouched
156
+ $condition = unserialize($rule->getCondition());
157
+ if(empty($condition))
158
+ return $collection;
159
+
160
+ //join tables to collection according to type
161
+ if($type == self::ABANDONED){
162
+ $collection->getSelect()
163
+ ->joinLeft(
164
+ array('quote_address' => 'sales_flat_quote_address'),
165
+ "main_table.entity_id = quote_address.quote_id",
166
+ array('shipping_method', 'country_id', 'city', 'region_id')
167
+ )->joinLeft(
168
+ array('quote_payment' => 'sales_flat_quote_payment'),
169
+ "main_table.entity_id = quote_payment.quote_id",
170
+ array('method')
171
+ )->where('address_type = ?', 'shipping');
172
+ }elseif($type == self::REVIEW){
173
+ $collection->getSelect()
174
+ ->join(
175
+ array('order_address' => 'sales_flat_order_address'),
176
+ "main_table.entity_id = order_address.parent_id",
177
+ array('country_id', 'city', 'region_id')
178
+ )->join(
179
+ array('order_payment' => 'sales_flat_order_payment'),
180
+ "main_table.entity_id = order_payment.parent_id",
181
+ array('method')
182
+ )->join(
183
+ array('quote' => 'sales_flat_quote'),
184
+ "main_table.quote_id = quote.entity_id",
185
+ array('items_qty')
186
+ )->where('order_address.address_type = ?', 'shipping');
187
+ }
188
+
189
+ //process rule on collection according to combination
190
+ $combination = $rule->getCombination();
191
+
192
+ // ALL TRUE
193
+ if($combination == 1)
194
+ return $this->_processAndCombination($collection, $condition, $type);
195
+ //ANY TRUE
196
+ if($combination == 2)
197
+ return $this->_processOrCombination($collection, $condition, $type);
198
+
199
+ }
200
+
201
+ /**
202
+ * process And combination on collection
203
+ *
204
+ * @param $collection
205
+ * @param $conditions
206
+ * @param $type
207
+ * @return mixed
208
+ */
209
+ private function _processAndCombination($collection, $conditions, $type)
210
+ {
211
+ foreach($conditions as $condition){
212
+ $attribute = $condition['attribute'];
213
+ $cond = $condition['conditions'];
214
+ $value = $condition['cvalue'];
215
+
216
+ //ignore condition if value is null or empty
217
+ if($value == '' or $value == null)
218
+ continue;
219
+
220
+ //ignore conditions for already used attribute
221
+ if(in_array($attribute, $this->_used))
222
+ continue;
223
+ //set used to check later
224
+ $this->_used[] = $attribute;
225
+
226
+ if($type == self::REVIEW && isset($this->_attributeMapForQuote[$attribute])){
227
+ $attribute = $this->_attributeMapForOrder[$attribute];
228
+ }elseif($type == self::ABANDONED && isset($this->_attributeMapForOrder[$attribute])){
229
+ $attribute = $this->_attributeMapForQuote[$attribute];
230
+ }else{
231
+ $this->_productAttribute[] = $condition;
232
+ continue;
233
+ }
234
+
235
+ if($cond == 'null'){
236
+ if($value == '1')
237
+ $collection->addFieldToFilter($attribute, array('notnull' => true));
238
+ elseif($value == '0')
239
+ $collection->addFieldToFilter($attribute, array($cond => true));
240
+ }else{
241
+ if($cond == 'like' or $cond == 'nlike')
242
+ $value = '%' . $value . '%';
243
+ $collection->addFieldToFilter($attribute, array($this->_conditionMap[$cond] => $value));
244
+ }
245
+ }
246
+ return $this->_processProductAttributes($collection);
247
+ }
248
+
249
+ /**
250
+ * process Or combination on collection
251
+ *
252
+ * @param $collection
253
+ * @param $conditions
254
+ * @param $type
255
+ * @return mixed
256
+ */
257
+ private function _processOrCombination($collection, $conditions, $type)
258
+ {
259
+ $fieldsConditions = array();
260
+ $multiFieldsConditions = array();
261
+ foreach($conditions as $condition){
262
+ $attribute = $condition['attribute'];
263
+ $cond = $condition['conditions'];
264
+ $value = $condition['cvalue'];
265
+
266
+ //ignore condition if value is null or empty
267
+ if($value == '' or $value == null)
268
+ continue;
269
+
270
+ if($type == self::REVIEW && isset($this->_attributeMapForQuote[$attribute])){
271
+ $attribute = $this->_attributeMapForOrder[$attribute];
272
+ }elseif($type == self::ABANDONED && isset($this->_attributeMapForOrder[$attribute])){
273
+ $attribute = $this->_attributeMapForQuote[$attribute];
274
+ }else{
275
+ $this->_productAttribute[] = $condition;
276
+ continue;
277
+ }
278
+
279
+ if($cond == 'null'){
280
+ if($value == '1'){
281
+ if(isset($fieldsConditions[$attribute])){
282
+ $multiFieldsConditions[$attribute] = array('notnull' => true);
283
+ continue;
284
+ }
285
+ $fieldsConditions[$attribute] = array('notnull' => true);
286
+ }
287
+ elseif($value == '0'){
288
+ if(isset($fieldsConditions[$attribute])){
289
+ $multiFieldsConditions[$attribute] = array($cond => true);;
290
+ continue;
291
+ }
292
+ $fieldsConditions[$attribute] = array($cond => true);
293
+ }
294
+ }else{
295
+ if($cond == 'like' or $cond == 'nlike')
296
+ $value = '%' . $value . '%';
297
+ if(isset($fieldsConditions[$attribute])){
298
+ $multiFieldsConditions[$attribute] = array($this->_conditionMap[$cond] => $value);
299
+ continue;
300
+ }
301
+ $fieldsConditions[$attribute] = array($this->_conditionMap[$cond] => $value);
302
+ }
303
+ }
304
+ //all rules condition will be with or combination
305
+ if(!empty($fieldsConditions)){
306
+ $column = array();
307
+ $cond = array();
308
+ foreach($fieldsConditions as $key => $fieldsCondition){
309
+ $column[] = $key;
310
+ $cond[] = $fieldsCondition;
311
+ }
312
+ if(!empty($multiFieldsConditions)){
313
+ foreach($multiFieldsConditions as $key => $multiFieldsCondition){
314
+ if(in_array($key, $column)){
315
+ $column[] = $key;
316
+ $cond[] = $multiFieldsCondition;
317
+ continue;
318
+ }
319
+ }
320
+ }
321
+ $collection->addFieldToFilter(
322
+ $column,
323
+ $cond
324
+ );
325
+ }
326
+ return $this->_processProductAttributes($collection);
327
+ }
328
+
329
+ /**
330
+ * process product attributes on collection
331
+ *
332
+ * @param $collection
333
+ * @return mixed
334
+ */
335
+ private function _processProductAttributes($collection)
336
+ {
337
+ //if no product attribute or collection empty return collection
338
+ if(empty($this->_productAttribute) or !$collection->getSize())
339
+ return $collection;
340
+
341
+ foreach($collection as $collectionItem){
342
+ $items = $collectionItem->getAllItems();
343
+ foreach($items as $item){
344
+ //loaded product
345
+ $product = $item->getProduct();
346
+
347
+ //attributes array from loaded product
348
+ $attributes = Mage::getModel('eav/config')->getEntityAttributeCodes(
349
+ Mage_Catalog_Model_Product::ENTITY,
350
+ $product
351
+ );
352
+
353
+ foreach($this->_productAttribute as $productAttribute){
354
+ $attribute = $productAttribute['attribute'];
355
+ $cond = $productAttribute['conditions'];
356
+ $value = $productAttribute['cvalue'];
357
+
358
+ if($cond == 'null'){
359
+ if($value == '0')
360
+ $cond = 'neq';
361
+ elseif($value == '1')
362
+ $cond = 'eq';
363
+ $value = '';
364
+ }
365
+
366
+ //if attribute is in product's attributes array
367
+ if(in_array($attribute,$attributes)){
368
+ $attr = Mage::getSingleton('eav/config')->getAttribute('catalog_product', $attribute);
369
+ //frontend type
370
+ $frontType = $attr->getFrontend()->getInputType();
371
+ //if type is select
372
+ if($frontType == 'select' or $frontType == 'multiselect'){
373
+ $attributeValue = $product->getAttributeText($attribute);
374
+ //evaluate conditions on values. if true then unset item from collection
375
+ if($this->_evaluate($value, $cond, $attributeValue)){
376
+ $collection->removeItemByKey($collectionItem->getId());
377
+ continue 3;
378
+ }
379
+ }else{
380
+ $getter = 'get';
381
+ $exploded = explode('_', $attribute);
382
+ foreach ($exploded as $one) {
383
+ $getter .= ucfirst($one);
384
+ }
385
+ $attributeValue = call_user_func(array($product, $getter));
386
+ //if retrieved value is an array then loop through all array values. example can be categories
387
+ if(is_array($attributeValue)){
388
+ foreach($attributeValue as $attrValue){
389
+ //evaluate conditions on values. if true then unset item from collection
390
+ if($this->_evaluate($value, $cond, $attrValue)){
391
+ $collection->removeItemByKey($collectionItem->getId());
392
+ continue 3;
393
+ }
394
+ }
395
+ }
396
+ else{
397
+ //evaluate conditions on values. if true then unset item from collection
398
+ if($this->_evaluate($value, $cond, $attributeValue)){
399
+ $collection->removeItemByKey($collectionItem->getId());
400
+ continue 3;
401
+ }
402
+ }
403
+ }
404
+ }
405
+ }
406
+ }
407
+ }
408
+ return $collection;
409
+ }
410
+
411
+ /**
412
+ * evaluate two values against condition
413
+ *
414
+ * @param $var1
415
+ * @param $op
416
+ * @param $var2
417
+ * @return bool
418
+ */
419
+ private function _evaluate($var1, $op, $var2)
420
+ {
421
+ switch ($op) {
422
+ case "eq":
423
+ return $var1 == $var2;
424
+ case "neq":
425
+ return $var1 != $var2;
426
+ case "gteq":
427
+ return $var1 >= $var2;
428
+ case "lteq":
429
+ return $var1 <= $var2;
430
+ case "gt":
431
+ return $var1 > $var2;
432
+ case "lt":
433
+ return $var1 < $var2;
434
+ }
435
+ }
436
+ }
app/code/community/Dotdigitalgroup/Email/Model/Sales/Observer.php ADDED
@@ -0,0 +1,319 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $storeName = $store->getName();
35
+ $websiteId = $store->getWebsiteId();
36
+ $customerEmail = $order->getCustomerEmail();
37
+ // start app emulation
38
+ $appEmulation = Mage::getSingleton('core/app_emulation');
39
+ $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);
40
+ $emailOrder = Mage::getModel('ddg_automation/order')->loadByOrderId($order->getEntityId(), $order->getQuoteId());
41
+ //reimport email order
42
+ $emailOrder->setUpdatedAt($order->getUpdatedAt())
43
+ ->setStoreId($storeId)
44
+ ->setOrderStatus($status);
45
+ if($emailOrder->getEmailImported() != Dotdigitalgroup_Email_Model_Contact::EMAIL_CONTACT_IMPORTED) {
46
+ $emailOrder->setEmailImported(null);
47
+ }
48
+
49
+ //if api is not enabled
50
+ if (!$store->getWebsite()->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED))
51
+ return $this;
52
+
53
+ // check for order status change
54
+ $statusBefore = Mage::registry('sales_order_status_before');
55
+ if ( $status!= $statusBefore) {
56
+ //If order status has changed and order is already imported then set modified to 1
57
+ if($emailOrder->getEmailImported() == Dotdigitalgroup_Email_Model_Contact::EMAIL_CONTACT_IMPORTED) {
58
+ $emailOrder->setModified(Dotdigitalgroup_Email_Model_Contact::EMAIL_CONTACT_IMPORTED);
59
+ }
60
+ $smsCampaign = Mage::getModel('ddg_automation/sms_campaign', $order);
61
+ $smsCampaign->setStatus($status);
62
+ $smsCampaign->sendSms();
63
+ }
64
+ // set back the current store
65
+ $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
66
+ $emailOrder->save();
67
+
68
+ //Status check automation enrolment
69
+ $configStatusAutomationMap = unserialize(Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_AUTOMATION_STUDIO_ORDER_STATUS, $order->getStore()));
70
+ if(!empty($configStatusAutomationMap)){
71
+ foreach($configStatusAutomationMap as $configMap){
72
+ if($configMap['status'] == $status) {
73
+ try {
74
+ $programId = $configMap['automation'];
75
+ $automation = Mage::getModel( 'ddg_automation/automation' );
76
+ $automation->setEmail( $customerEmail )
77
+ ->setAutomationType( 'order_automation_' . $status )
78
+ ->setEnrolmentStatus( Dotdigitalgroup_Email_Model_Automation::AUTOMATION_STATUS_PENDING )
79
+ ->setTypeId( $order->getId() )
80
+ ->setWebsiteId( $websiteId )
81
+ ->setStoreName( $storeName )
82
+ ->setProgramId( $programId );
83
+ $automation->save();
84
+ }catch(Exception $e){
85
+ Mage::logException($e);
86
+ }
87
+ }
88
+ }
89
+ }
90
+
91
+ //admin oder when editing the first one is canceled
92
+ Mage::unregister('sales_order_status_before');
93
+
94
+ }catch(Exception $e){
95
+ Mage::logException($e);
96
+ }
97
+ return $this;
98
+ }
99
+
100
+
101
+ /**
102
+ * Create new order event.
103
+ * @param Varien_Event_Observer $observer
104
+ *
105
+ * @return $this
106
+ * @throws Mage_Core_Exception
107
+ */
108
+ public function handleSalesOrderPlaceAfter(Varien_Event_Observer $observer)
109
+ {
110
+ /** @var $order Mage_Sales_Model_Order */
111
+ $order = $observer->getEvent()->getOrder();
112
+ $email = $order->getCustomerEmail();
113
+ $website = Mage::app()->getWebsite($order->getWebsiteId());
114
+ $storeName = Mage::app()->getStore($order->getStoreId())->getName();
115
+
116
+ //if api is not enabled
117
+ if (!$website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED))
118
+ return $this;
119
+
120
+ //automation enrolment for order
121
+ if($order->getCustomerIsGuest()){
122
+ // guest to automation mapped
123
+ $programType = 'XML_PATH_CONNECTOR_AUTOMATION_STUDIO_GUEST_ORDER';
124
+ $automationType = Dotdigitalgroup_Email_Model_Automation::AUTOMATION_TYPE_NEW_GUEST_ORDER;
125
+ }else{
126
+ // customer to automation mapped
127
+ $programType = 'XML_PATH_CONNECTOR_AUTOMATION_STUDIO_ORDER';
128
+ $automationType = Dotdigitalgroup_Email_Model_Automation::AUTOMATION_TYPE_NEW_ORDER;
129
+ }
130
+
131
+ $programId = Mage::helper( 'ddg' )->getAutomationIdByType($programType, $order->getWebsiteId());
132
+
133
+ //the program is not mappped
134
+ if (! $programId){
135
+
136
+ Mage::log('automation type : ' . $automationType. ' program id not found');
137
+ return $this;
138
+ }
139
+ try {
140
+ $automation = Mage::getModel( 'ddg_automation/automation' );
141
+ $automation->setEmail( $email )
142
+ ->setAutomationType( $automationType )
143
+ ->setEnrolmentStatus( Dotdigitalgroup_Email_Model_Automation::AUTOMATION_STATUS_PENDING )
144
+ ->setTypeId( $order->getId() )
145
+ ->setWebsiteId( $website->getId() )
146
+ ->setStoreName( $storeName )
147
+ ->setProgramId( $programId )
148
+ ->save();
149
+ }catch(Exception $e){
150
+ Mage::logException($e);
151
+ }
152
+
153
+ return $this;
154
+ }
155
+
156
+ /**
157
+ * Sales order refund event.
158
+ *
159
+ * @param Varien_Event_Observer $observer
160
+ *
161
+ * @return $this
162
+ */
163
+ public function handleSalesOrderRefund(Varien_Event_Observer $observer)
164
+ {
165
+ $creditmemo = $observer->getEvent()->getCreditmemo();
166
+ $storeId = $creditmemo->getStoreId();
167
+ $order = $creditmemo->getOrder();
168
+ $orderId = $order->getEntityId();
169
+ $quoteId = $order->getQuoteId();
170
+
171
+ try{
172
+ /**
173
+ * Reimport transactional data.
174
+ */
175
+ $emailOrder = Mage::getModel('ddg_automation/order')->loadByOrderId($orderId, $quoteId, $storeId);
176
+ if (!$emailOrder->getId()) {
177
+ Mage::helper('ddg')->log('ERROR Creditmemmo Order not found :' . $orderId . ', quote id : ' . $quoteId . ', store id ' . $storeId);
178
+ return $this;
179
+ }
180
+ $emailOrder->setEmailImported(Dotdigitalgroup_Email_Model_Contact::EMAIL_CONTACT_NOT_IMPORTED)->save();
181
+ }catch (Exception $e){
182
+ Mage::logException($e);
183
+ }
184
+
185
+ return $this;
186
+ }
187
+
188
+ /**
189
+ * Sales cancel order event, remove transactional data.
190
+ *
191
+ * @param Varien_Event_Observer $observer
192
+ *
193
+ * @return $this
194
+ */
195
+ public function hangleSalesOrderCancel(Varien_Event_Observer $observer)
196
+ {
197
+ $helper = Mage::helper('ddg');
198
+ $order = $observer->getEvent()->getOrder();
199
+ $incrementId = $order->getIncrementId();
200
+ $websiteId = Mage::app()->getStore($order->getStoreId())->getWebsiteId();
201
+
202
+ //sync enabled
203
+ $syncEnabled = $helper->getWebsiteConfig(
204
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_ORDER_ENABLED,
205
+ $websiteId
206
+ );
207
+
208
+ if ($helper->isEnabled($websiteId) && $syncEnabled) {
209
+ //register in queue with importer
210
+ Mage::getModel('ddg_automation/importer')->registerQueue(
211
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_ORDERS,
212
+ array($incrementId),
213
+ Dotdigitalgroup_Email_Model_Importer::MODE_SINGLE_DELETE,
214
+ $websiteId
215
+ );
216
+ }
217
+
218
+ return $this;
219
+ }
220
+
221
+ /**
222
+ * convert_quote_to_order observer
223
+ *
224
+ * @param Varien_Event_Observer $observer
225
+ * @return $this
226
+ */
227
+ public function handleQuoteToOrder(Varien_Event_Observer $observer)
228
+ {
229
+ /* @var $order Mage_Sales_Model_Order */
230
+ $order = $observer->getOrder();
231
+ $helper = Mage::helper('ddg');
232
+ $enabled = $helper->getWebsiteConfig(
233
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED,
234
+ $order->getStore()->getWebsiteId()
235
+ );
236
+ $syncEnabled = $helper->getWebsiteConfig(
237
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_QUOTE_ENABLED,
238
+ $order->getStore()->getWebsiteId()
239
+ );
240
+ if ($enabled && $syncEnabled) {
241
+ $quoteId = $order->getQuoteId();
242
+ $connectorQuote = Mage::getModel('ddg_automation/quote')->loadQuote($quoteId);
243
+ if ($connectorQuote) {
244
+ //register in queue with importer for single delete
245
+ Mage::getModel('ddg_automation/importer')->registerQueue(
246
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_QUOTE,
247
+ array($connectorQuote->getQuoteId()),
248
+ Dotdigitalgroup_Email_Model_Importer::MODE_SINGLE_DELETE,
249
+ $order->getStore()->getWebsiteId()
250
+ );
251
+ //delete from table
252
+ $connectorQuote->delete();
253
+ }
254
+ }
255
+ return $this;
256
+ }
257
+
258
+ /**
259
+ * sales_quote_save_after event observer
260
+ *
261
+ * @param Varien_Event_Observer $observer
262
+ * @return $this
263
+ */
264
+ public function handleQuoteSaveAfter(Varien_Event_Observer $observer)
265
+ {
266
+ /* @var $quote Mage_Sales_Model_Quote */
267
+ $quote = $observer->getEvent()->getQuote();
268
+ $helper = Mage::helper('ddg');
269
+ $enabled = $helper->getWebsiteConfig(
270
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED,
271
+ $quote->getStore()->getWebsiteId()
272
+ );
273
+ $syncEnabled = $helper->getWebsiteConfig(
274
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_QUOTE_ENABLED,
275
+ $quote->getStore()->getWebsiteId()
276
+ );
277
+ if ($enabled && $syncEnabled) {
278
+ if ($quote->getCustomerId()) {
279
+ $connectorQuote = Mage::getModel('ddg_automation/quote')->loadQuote($quote->getId());
280
+ $count = count($quote->getAllItems());
281
+ if ($connectorQuote) {
282
+ if ($connectorQuote->getImported() && $count > 0)
283
+ $connectorQuote->setModified(1)->save();
284
+ elseif ($connectorQuote->getImported() && $count == 0) {
285
+ //register in queue with importer for single delete
286
+ Mage::getModel('ddg_automation/importer')->registerQueue(
287
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_QUOTE,
288
+ array($connectorQuote->getQuoteId()),
289
+ Dotdigitalgroup_Email_Model_Importer::MODE_SINGLE_DELETE,
290
+ $quote->getStore()->getWebsiteId()
291
+ );
292
+ //delete from table
293
+ $connectorQuote->delete();
294
+ }
295
+ } elseif ($count > 0)
296
+ $this->_registerQuote($quote);
297
+ }
298
+ }
299
+ return $this;
300
+ }
301
+
302
+ /**
303
+ * register quote with connector
304
+ *
305
+ * @param Mage_Sales_Model_Quote $quote
306
+ */
307
+ private function _registerQuote(Mage_Sales_Model_Quote $quote)
308
+ {
309
+ try {
310
+ $connectorQuote = Mage::getModel('ddg_automation/quote');
311
+ $connectorQuote->setQuoteId($quote->getId())
312
+ ->setCustomerId($quote->getCustomerId())
313
+ ->setStoreId($quote->getStoreId())
314
+ ->save();
315
+ }catch (Exception $e){
316
+ Mage::logException($e);
317
+ }
318
+ }
319
+ }
app/code/community/Dotdigitalgroup/Email/Model/Sales/Order.php ADDED
@@ -0,0 +1,414 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ private $_orderIds;
26
+ private $_orderIdsForSingleSync;
27
+
28
+ /**
29
+ * initial sync the transactional data
30
+ * @return array
31
+ */
32
+ public function sync()
33
+ {
34
+ $response = array('success' => true, 'message' => '');
35
+ // Initialise a return hash containing results of our sync attempt
36
+ $this->_searchAccounts();
37
+ foreach ($this->accounts as $account) {
38
+ $orders = $account->getOrders();
39
+ $orderIds = $account->getOrderIds();
40
+ $ordersForSingleSync = $account->getOrdersForSingleSync();
41
+ $orderIdsForSingleSync = $account->getOrderIdsForSingleSync();
42
+ $numOrdersForSingleSync = count($ordersForSingleSync);
43
+ $website = $account->getWebsites();
44
+ $numOrders = count($orders);
45
+ $this->_countOrders += $numOrders;
46
+ $this->_countOrders += $numOrdersForSingleSync;
47
+ //send transactional for any number of orders set
48
+ if ($numOrders) {
49
+ Mage::helper('ddg')->log('--------- register Order sync with importer ---------- : ' . count($orders));
50
+ //register in queue with importer
51
+ $check = Mage::getModel('ddg_automation/importer')->registerQueue(
52
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_ORDERS,
53
+ $orders,
54
+ Dotdigitalgroup_Email_Model_Importer::MODE_BULK,
55
+ $website[0]
56
+ );
57
+ //if no error then set imported
58
+ if ($check) {
59
+ $this->_setImported($orderIds);
60
+ }
61
+ Mage::helper('ddg')->log('----------end order sync----------');
62
+ }
63
+
64
+ if ($numOrdersForSingleSync) {
65
+ $error = false;
66
+ foreach ($ordersForSingleSync as $order) {
67
+ Mage::helper('ddg')->log('--------- register Order sync in single with importer ---------- : ' . $order->id);
68
+ //register in queue with importer
69
+ $check = Mage::getModel('ddg_automation/importer')->registerQueue(
70
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_ORDERS,
71
+ $order,
72
+ Dotdigitalgroup_Email_Model_Importer::MODE_SINGLE,
73
+ $website[0]
74
+ );
75
+ if (!$check) {
76
+ $error = true;
77
+ }
78
+ Mage::helper('ddg')->log('----------end order sync in single----------');
79
+ }
80
+ //if no error then set imported
81
+ if (!$error) {
82
+ $this->_setImported($orderIdsForSingleSync, true);
83
+ }
84
+ }
85
+ unset($this->accounts[$account->getApiUsername()]);
86
+ }
87
+
88
+ if ($this->_countOrders)
89
+ $response['message'] = 'Number of updated orders : ' . $this->_countOrders;
90
+ return $response;
91
+ }
92
+
93
+ /**
94
+ * Search the configuration data per website
95
+ */
96
+ private function _searchAccounts()
97
+ {
98
+ $helper = Mage::helper('ddg');
99
+ foreach (Mage::app()->getWebsites(true) as $website) {
100
+ $this->_orderIds = array();
101
+ $this->_orderIdsForSingleSync = array();
102
+ $apiEnabled = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED, $website);
103
+ if ($apiEnabled && $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_ORDER_ENABLED, $website)) {
104
+
105
+ $this->_apiUsername = $helper->getApiUsername($website);
106
+ $this->_apiPassword = $helper->getApiPassword($website);
107
+
108
+ // limit for orders included to sync
109
+ $limit = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_TRANSACTIONAL_DATA_SYNC_LIMIT, $website);
110
+ if (!isset($this->accounts[$this->_apiUsername])) {
111
+ $account = Mage::getModel('ddg_automation/connector_account')
112
+ ->setApiUsername($this->_apiUsername)
113
+ ->setApiPassword($this->_apiPassword);
114
+ $this->accounts[$this->_apiUsername] = $account;
115
+ }
116
+
117
+ $this->accounts[$this->_apiUsername]->setOrders($this->getConnectorOrders($website, $limit));
118
+ $orderIds = array_merge($this->accounts[$this->_apiUsername]->getOrderIds(), $this->_orderIds);
119
+ $this->accounts[$this->_apiUsername]->setOrderIds($orderIds);
120
+ $this->accounts[$this->_apiUsername]->setWebsites($website->getId());
121
+ $this->accounts[$this->_apiUsername]->setOrdersForSingleSync($this->getConnectorOrders($website, $limit, true));
122
+ $orderIdsForSingleSync = array_merge(
123
+ $this->accounts[$this->_apiUsername]->getOrderIdsForSingleSync(),
124
+ $this->_orderIdsForSingleSync
125
+ );
126
+ $this->accounts[$this->_apiUsername]->setOrderIdsForSingleSync($orderIdsForSingleSync);
127
+ }
128
+ }
129
+ }
130
+
131
+ /**
132
+ * get all order to import.
133
+ * @param $website
134
+ * @param int $limit
135
+ * @param $modified
136
+ *
137
+ * @return array
138
+ */
139
+ public function getConnectorOrders($website, $limit = 100, $modified = false)
140
+ {
141
+ $orders = $customers = array();
142
+ $storeIds = $website->getStoreIds();
143
+ $orderModel = Mage::getModel('ddg_automation/order');
144
+ if(empty($storeIds))
145
+ return array();
146
+
147
+ $helper = Mage::helper('ddg');
148
+ $orderStatuses = $helper->getConfigSelectedStatus($website);
149
+
150
+ if ($orderStatuses) {
151
+ if ($modified)
152
+ $orderCollection = $orderModel->getOrdersToImport($storeIds, $limit, $orderStatuses, true);
153
+ else
154
+ $orderCollection = $orderModel->getOrdersToImport($storeIds, $limit, $orderStatuses);
155
+ }
156
+ else
157
+ return array();
158
+
159
+ foreach ($orderCollection as $order) {
160
+ try {
161
+ $salesOrder = Mage::getModel('sales/order')->load($order->getOrderId());
162
+ $storeId = $order->getStoreId();
163
+ $websiteId = Mage::app()->getStore($storeId)->getWebsiteId();
164
+ /**
165
+ * Add guest to contacts table.
166
+ */
167
+ if ($salesOrder->getCustomerIsGuest()) {
168
+ $this->_createGuestContact($salesOrder->getCustomerEmail(), $websiteId, $storeId);
169
+ }
170
+ if ($salesOrder->getId()) {
171
+ $connectorOrder = Mage::getModel('ddg_automation/connector_order', $salesOrder);
172
+ $orders[] = $connectorOrder;
173
+ }
174
+ if ($modified)
175
+ $this->_orderIdsForSingleSync[] = $order->getOrderId();
176
+ else
177
+ $this->_orderIds[] = $order->getOrderId();
178
+ }catch(Exception $e){
179
+ Mage::logException($e);
180
+ }
181
+ }
182
+ return $orders;
183
+ }
184
+
185
+ /**
186
+ * Create a guest contact.
187
+ * @param $email
188
+ * @param $websiteId
189
+ * @param $storeId
190
+ *
191
+ * @return bool
192
+ */
193
+ private function _createGuestContact($email, $websiteId, $storeId){
194
+ try{
195
+ $client = Mage::helper('ddg')->getWebsiteApiClient($websiteId);
196
+
197
+ //no api credentials or the guest has no been mapped
198
+ if (! $client || ! $addressBookId = Mage::helper('ddg')->getGuestAddressBook($websiteId))
199
+ return false;
200
+
201
+ $contactModel = Mage::getModel('ddg_automation/contact')->loadByCustomerEmail($email, $websiteId);
202
+
203
+ //check if contact exists, create if not
204
+ $contactApi = $client->postContacts($email);
205
+
206
+ //contact is suppressed cannot add to address book, mark as suppressed.
207
+ if (isset($contactApi->message) && $contactApi->message == 'Contact is suppressed. ERROR_CONTACT_SUPPRESSED'){
208
+ //mark new contacts as guest.
209
+ if ($contactModel->isObjectNew())
210
+ $contactModel->setIsGuest(1);
211
+ $contactModel->setSuppressed(1);
212
+ $contactModel->save();
213
+ return;
214
+ }
215
+
216
+ //add guest to address book
217
+ $response = $client->postAddressBookContacts($addressBookId, $contactApi);
218
+ //set contact as was found as guest and
219
+ $contactModel->setIsGuest(1)
220
+ ->setStoreId($storeId)
221
+ ->setEmailImported(1);
222
+ //contact id
223
+ if (isset($contactApi->id))
224
+ $contactModel->setContactId();
225
+ //mark the contact as surpressed
226
+ if (isset($response->message) && $response->message == 'Contact is suppressed. ERROR_CONTACT_SUPPRESSED')
227
+ $contactModel->setSuppressed(1);
228
+ //save
229
+ $contactModel->save();
230
+
231
+ Mage::helper('ddg')->log('-- guest found : ' . $email . ' website : ' . $websiteId . ' ,store : ' . $storeId);
232
+ }catch(Exception $e){
233
+ Mage::logException($e);
234
+ }
235
+
236
+ return true;
237
+ }
238
+
239
+
240
+ /**
241
+ * create review campaigns
242
+ *
243
+ * @return bool
244
+ */
245
+ public function createReviewCampaigns()
246
+ {
247
+ $this->searchOrdersForReview();
248
+
249
+ foreach($this->_reviewCollection as $websiteId => $collection){
250
+ $this->registerCampaign($collection, $websiteId);
251
+ }
252
+ }
253
+
254
+ /**
255
+ * register review campaign
256
+ *
257
+ * @param $collection
258
+ * @param $websiteId
259
+ *
260
+ * @throws Exception
261
+ */
262
+ private function registerCampaign($collection, $websiteId)
263
+ {
264
+ $helper = Mage::helper('ddg/review');
265
+ $campaignId = $helper->getCampaign($websiteId);
266
+
267
+ if($campaignId) {
268
+ foreach ($collection as $order) {
269
+ Mage::helper('ddg')->log('-- Order Review: ' . $order->getIncrementId() . ' Campaign Id: ' . $campaignId);
270
+
271
+ try {
272
+ $emailCampaign = Mage::getModel('ddg_automation/campaign');
273
+ $emailCampaign
274
+ ->setEmail($order->getCustomerEmail())
275
+ ->setStoreId($order->getStoreId())
276
+ ->setCampaignId($campaignId)
277
+ ->setEventName('Order Review')
278
+ ->setCreatedAt(Mage::getSingleton('core/date')->gmtDate())
279
+ ->setOrderIncrementId($order->getIncrementId())
280
+ ->setQuoteId($order->getQuoteId());
281
+
282
+ if($order->getCustomerId())
283
+ $emailCampaign->setCustomerId($order->getCustomerId());
284
+
285
+ $emailCampaign->save();
286
+ } catch (Exception $e) {
287
+ Mage::logException($e);
288
+ }
289
+ }
290
+ }
291
+ }
292
+
293
+ /**
294
+ * search for orders to review per website
295
+ */
296
+ private function searchOrdersForReview()
297
+ {
298
+ $helper = Mage::helper('ddg/review');
299
+
300
+ foreach (Mage::app()->getWebsites(true) as $website){
301
+ $apiEnabled = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED, $website);
302
+ if($apiEnabled && $helper->isEnabled($website) &&
303
+ $helper->getOrderStatus($website) &&
304
+ $helper->getDelay($website)){
305
+
306
+ $storeIds = $website->getStoreIds();
307
+ if(empty($storeIds))
308
+ return;
309
+
310
+ $orderStatusFromConfig = $helper->getOrderStatus($website);
311
+ $delayInDays = $helper->getDelay($website);
312
+
313
+ $campaignCollection = Mage::getModel('ddg_automation/campaign')->getCollection();
314
+ $campaignCollection
315
+ ->addFieldToFilter('event_name', 'Order Review')
316
+ ->load();
317
+
318
+ $campaignOrderIds = $campaignCollection->getColumnValues('order_increment_id');
319
+
320
+ $to = Mage::app()->getLocale()->date()
321
+ ->subDay($delayInDays);
322
+ $from = clone $to;
323
+ $to = $to->toString('YYYY-MM-dd HH:mm:ss');
324
+ $from = $from->subHour(2)
325
+ ->toString('YYYY-MM-dd HH:mm:ss');
326
+
327
+ $created = array( 'from' => $from, 'to' => $to, 'date' => true);
328
+
329
+ $collection = Mage::getModel('sales/order')->getCollection();
330
+ $collection->addFieldToFilter('main_table.status', $orderStatusFromConfig)
331
+ ->addFieldToFilter('main_table.created_at', $created)
332
+ ->addFieldToFilter('main_table.store_id', array('in' => $storeIds));
333
+
334
+ if(!empty($campaignOrderIds))
335
+ $collection->addFieldToFilter('main_table.increment_id', array('nin' => $campaignOrderIds));
336
+
337
+ //process rules on collection
338
+ $ruleModel = Mage::getModel('ddg_automation/rules');
339
+ $collection = $ruleModel->process(
340
+ $collection, Dotdigitalgroup_Email_Model_Rules::REVIEW, $website->getId()
341
+ );
342
+
343
+ if($collection->getSize())
344
+ $this->_reviewCollection[$website->getId()] = $collection;
345
+ }
346
+ }
347
+ }
348
+
349
+ /**
350
+ * get customer last order id
351
+ *
352
+ * @param Mage_Customer_Model_Customer $customer
353
+ * @return bool|Varien_Object
354
+ */
355
+ public function getCustomerLastOrderId(Mage_Customer_Model_Customer $customer)
356
+ {
357
+ $storeIds = Mage::app()->getWebsite($customer->getWebsiteId())->getStoreIds();
358
+ $collection = Mage::getModel('sales/order')->getCollection();
359
+ $collection->addFieldToFilter('customer_id', $customer->getId())
360
+ ->addFieldToFilter('store_id', array('in' => $storeIds))
361
+ ->setPageSize(1)
362
+ ->setOrder('entity_id');
363
+
364
+ if ($collection->count())
365
+ return $collection->getFirstItem();
366
+ else
367
+ return false;
368
+ }
369
+
370
+ /**
371
+ * get customer last quote id
372
+ *
373
+ * @param Mage_Customer_Model_Customer $customer
374
+ * @return bool|Varien_Object
375
+ */
376
+ public function getCustomerLastQuoteId(Mage_Customer_Model_Customer $customer)
377
+ {
378
+ $storeIds = Mage::app()->getWebsite($customer->getWebsiteId())->getStoreIds();
379
+ $collection = Mage::getModel('sales/quote')->getCollection();
380
+ $collection->addFieldToFilter('customer_id', $customer->getId())
381
+ ->addFieldToFilter('store_id', array('in' => $storeIds))
382
+ ->setPageSize(1)
383
+ ->setOrder('entity_id');
384
+
385
+ if ($collection->count())
386
+ return $collection->getFirstItem();
387
+ else
388
+ return false;
389
+ }
390
+
391
+ /**
392
+ * set imported in bulk query
393
+ *
394
+ * @param $ids
395
+ * @param $modified
396
+ */
397
+ private function _setImported($ids, $modified = false)
398
+ {
399
+ try{
400
+ $coreResource = Mage::getSingleton('core/resource');
401
+ $write = $coreResource->getConnection('core_write');
402
+ $tableName = $coreResource->getTableName('email_order');
403
+ $ids = implode(', ', $ids);
404
+ $now = Mage::getSingleton('core/date')->gmtDate();
405
+
406
+ if ($modified)
407
+ $write->update($tableName, array('modified' => new Zend_Db_Expr('null'), 'updated_at' => $now), "order_id IN ($ids)");
408
+ else
409
+ $write->update($tableName, array('email_imported' => 1, 'updated_at' => $now), "order_id IN ($ids)");
410
+ }catch (Exception $e){
411
+ Mage::logException($e);
412
+ }
413
+ }
414
+ }
app/code/community/Dotdigitalgroup/Email/Model/Sales/Quote.php ADDED
@@ -0,0 +1,306 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $quoteId = $quote->getId();
88
+ // upate last quote id for the contact
89
+ Mage::helper('ddg')->updateLastQuoteId($quoteId, $email, $websiteId);
90
+
91
+ // update abandoned product name for contact
92
+ $items = $quote->getAllItems();
93
+ $mostExpensiveItem = false;
94
+ foreach ($items as $item) {
95
+ /** @var $item Mage_Sales_Model_Quote_Item */
96
+ if ($mostExpensiveItem == false)
97
+ $mostExpensiveItem = $item;
98
+ elseif ($item->getPrice() > $mostExpensiveItem->getPrice())
99
+ $mostExpensiveItem = $item;
100
+ }
101
+ if ($mostExpensiveItem)
102
+ Mage::helper('ddg')->updateAbandonedProductName($mostExpensiveItem->getName(), $email, $websiteId);
103
+
104
+ //send email only if the interval limit passed, no emails during this interval
105
+ $campignFound = $this->_checkCustomerCartLimit( $email, $storeId );
106
+
107
+ //no campign found for interval pass
108
+ if (!$campignFound) {
109
+
110
+ //save lost basket for sending
111
+ $sendModel = Mage::getModel('ddg_automation/campaign')
112
+ ->setEmail( $email )
113
+ ->setCustomerId( $quote->getCustomerId() )
114
+ ->setEventName( 'Lost Basket' )
115
+ ->setQuoteId($quoteId)
116
+ ->setMessage('Abandoned Cart :' . $num)
117
+ ->setCampaignId( $campaignId )
118
+ ->setStoreId( $storeId )
119
+ ->setWebsiteId($websiteId)
120
+ ->setIsSent( null )->save();
121
+ }
122
+ }
123
+ }
124
+
125
+ }
126
+ }
127
+ if ($mode == 'all' || $mode == 'guests') {
128
+ /**
129
+ * Guests campaigns
130
+ */
131
+ foreach ( $this->lostBasketGuests as $num ) {
132
+ if ( $this->_getLostBasketGuestEnabled( $num, $storeId ) ) {
133
+ if ( $num == 1 ) {
134
+ $from = Zend_Date::now( $locale )->subMinute( $this->_getLostBasketGuestIterval( $num, $storeId ) );
135
+ } else {
136
+ $from = Zend_Date::now( $locale )->subHour( $this->_getLostBasketGuestIterval( $num, $storeId ) );
137
+ }
138
+ $to = clone($from);
139
+ $from->sub('5', Zend_Date::MINUTE);
140
+ $quoteCollection = $this->_getStoreQuotes( $from->toString( 'YYYY-MM-dd HH:mm' ), $to->toString( 'YYYY-MM-dd HH:mm' ), $guest = true, $storeId );
141
+
142
+ if ( $quoteCollection->getSize() ) {
143
+ Mage::helper( 'ddg' )->log( 'Guest lost baskets : ' . $num . ', from : ' . $from->toString( 'YYYY-MM-dd HH:mm' ) . ':' . $to->toString( 'YYYY-MM-dd HH:mm' ) );
144
+ }
145
+ $guestCampaignId = $this->_getLostBasketGuestCampaignId( $num, $storeId );
146
+ foreach ( $quoteCollection as $quote ) {
147
+
148
+ $email = $quote->getCustomerEmail();
149
+ $websiteId = $store->getWebsiteId();
150
+ $quoteId = $quote->getId();
151
+ // upate last quote id for the contact
152
+ Mage::helper('ddg')->updateLastQuoteId($quoteId, $email, $websiteId);
153
+
154
+ // update abandoned product name for contact
155
+ $items = $quote->getAllItems();
156
+ $mostExpensiveItem = false;
157
+ foreach ($items as $item) {
158
+ /** @var $item Mage_Sales_Model_Quote_Item */
159
+ if ($mostExpensiveItem == false)
160
+ $mostExpensiveItem = $item;
161
+ elseif ($item->getPrice() > $mostExpensiveItem->getPrice())
162
+ $mostExpensiveItem = $item;
163
+ }
164
+ if ($mostExpensiveItem)
165
+ Mage::helper('ddg')->updateAbandonedProductName($mostExpensiveItem->getName(), $email, $websiteId);
166
+
167
+ //send email only if the interval limit passed, no emails during this interval
168
+ $campignFound = $this->_checkCustomerCartLimit( $email, $storeId );
169
+
170
+ //no campign found for interval pass
171
+ if (!$campignFound) {
172
+ //save lost basket for sending
173
+ $sendModel = Mage::getModel('ddg_automation/campaign')
174
+ ->setEmail( $email )
175
+ ->setEventName( 'Lost Basket' )
176
+ ->setQuoteId($quoteId)
177
+ ->setCheckoutMethod( 'Guest' )
178
+ ->setMessage('Guest Abandoned Cart : ' . $num)
179
+ ->setCampaignId( $guestCampaignId )
180
+ ->setStoreId( $storeId )
181
+ ->setWebsiteId($websiteId)
182
+ ->setIsSent( null )->save();
183
+ }
184
+ }
185
+ }
186
+ }
187
+ }
188
+ }
189
+ }
190
+
191
+ private function _getLostBasketCustomerCampaignId($num, $storeId)
192
+ {
193
+ $store = Mage::app()->getStore($storeId);
194
+ return $store->getConfig(constant('self::XML_PATH_LOSTBASKET_CUSTOMER_CAMPAIGN_' . $num));
195
+ }
196
+ private function _getLostBasketGuestCampaignId($num, $storeId)
197
+ {
198
+ $store = Mage::app()->getStore($storeId);
199
+ return $store->getConfig(constant('self::XML_PATH_LOSTBASKET_GUEST_CAMPAIGN_'. $num));
200
+ }
201
+
202
+ private function _getLostBasketCustomerInterval($num, $storeId)
203
+ {
204
+ $store = Mage::app()->getstore($storeId);
205
+ return $store->getConfig(constant('self::XML_PATH_LOSTBASKET_CUSTOMER_INTERVAL_' . $num));
206
+ }
207
+
208
+ private function _getLostBasketGuestIterval($num, $storeId)
209
+ {
210
+ $store = Mage::app()->getStore($storeId);
211
+ return $store->getConfig(constant('self::XML_PATH_LOSTBASKET_GUEST_INTERVAL_' . $num));
212
+ }
213
+
214
+ protected function _getLostBasketCustomerEnabled($num, $storeId)
215
+ {
216
+ $store = Mage::app()->getStore($storeId);
217
+ $enabled = $store->getConfig(constant('self::XML_PATH_LOSTBASKET_CUSTOMER_ENABLED_' . $num));
218
+ return $enabled;
219
+
220
+ }
221
+
222
+ protected function _getLostBasketGuestEnabled($num, $storeId)
223
+ {
224
+ $store = Mage::app()->getStore($storeId);
225
+ return $store->getConfig(constant('self::XML_PATH_LOSTBASKET_GUEST_ENABLED_' . $num));
226
+ }
227
+
228
+ /**
229
+ * @param string $from
230
+ * @param string $to
231
+ * @param bool $guest
232
+ * @param int $storeId
233
+ * @return Mage_Eav_Model_Entity_Collection_Abstract
234
+ */
235
+ private function _getStoreQuotes($from = null, $to = null, $guest = false, $storeId = 0)
236
+ {
237
+ $updated = array(
238
+ 'from' => $from,
239
+ 'to' => $to,
240
+ 'date' => true);
241
+
242
+ $salesCollection = Mage::getResourceModel('sales/quote_collection')
243
+ ->addFieldToFilter('is_active', 1)
244
+ ->addFieldToFilter('items_count', array('gt' => 0))
245
+ ->addFieldToFilter('customer_email', array('neq' => ''))
246
+ ->addFieldToFilter('store_id', $storeId)
247
+ ->addFieldToFilter('updated_at', $updated);
248
+ //guests
249
+ if ($guest) {
250
+ $salesCollection->addFieldToFilter( 'main_table.customer_id', array( 'null' => true ) );
251
+ } else {
252
+ //customers
253
+ $salesCollection->addFieldToFilter( 'main_table.customer_id', array( 'notnull' => true ) );
254
+ }
255
+
256
+ //process rules on collection
257
+ $ruleModel = Mage::getModel('ddg_automation/rules');
258
+ $salesCollection = $ruleModel->process(
259
+ $salesCollection, Dotdigitalgroup_Email_Model_Rules::ABANDONED, Mage::app()->getStore($storeId)->getWebsiteId()
260
+ );
261
+
262
+ return $salesCollection;
263
+ }
264
+
265
+ /**
266
+ * Check customer campaign that was sent by a limit from config.
267
+ * Return false for any found for this period.
268
+ *
269
+ * @param $email
270
+ * @param $storeId
271
+ *
272
+ * @return bool
273
+ */
274
+ private function _checkCustomerCartLimit($email, $storeId) {
275
+
276
+ $cartLimit = Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_ABANDONED_CART_LIMIT, $storeId);
277
+ $locale = Mage::app()->getLocale()->getLocale();
278
+
279
+ //no limit is set skip
280
+ if (! $cartLimit)
281
+ return false;
282
+
283
+ //time diff
284
+ $to = Zend_Date::now($locale);
285
+ $from = Zend_Date::now($locale)->subHour($cartLimit);
286
+
287
+ $updated = array(
288
+ 'from' => $from,
289
+ 'to' => $to,
290
+ 'date' => true
291
+ );
292
+
293
+ //number of campigns during this time
294
+ $campaignLimit = Mage::getModel('ddg_automation/campaign')->getCollection()
295
+ ->addFieldToFilter('email', $email)
296
+ ->addFieldToFilter('event_name', 'Lost Basket')
297
+ ->addFieldToFilter('sent_at', $updated)
298
+ ->count()
299
+ ;
300
+
301
+ if ($campaignLimit)
302
+ return true;
303
+
304
+ return false;
305
+ }
306
+ }
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,220 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ private $_wishlistIds;
9
+
10
+ /**
11
+ * constructor
12
+ */
13
+ public function _construct()
14
+ {
15
+ parent::_construct();
16
+ $this->_init('ddg_automation/wishlist');
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
+ }else {
29
+ $this->setUpdatedAt($now);
30
+ }
31
+ return $this;
32
+ }
33
+
34
+ /**
35
+ * @param int $wishListId
36
+ * @return bool|Varien_Object
37
+ */
38
+ public function getWishlist($wishListId)
39
+ {
40
+ $collection = $this->getCollection()
41
+ ->addFieldToFilter('wishlist_id', $wishListId)
42
+ ->setPageSize(1);
43
+
44
+ if ($collection->count()) {
45
+ return $collection->getFirstItem();
46
+ }
47
+ return false;
48
+ }
49
+
50
+ public function sync()
51
+ {
52
+ $response = array('success' => true, 'message' => '');
53
+ $helper = Mage::helper('ddg');
54
+ //resource allocation
55
+ $helper->allowResourceFullExecution();
56
+
57
+ foreach (Mage::app()->getWebsites(true) as $website) {
58
+ $enabled = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_WISHLIST_ENABLED, $website);
59
+ $apiEnabled = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED, $website);
60
+ if ($enabled && $apiEnabled) {
61
+ //using bulk api
62
+ $helper->log('---------- Start wishlist bulk sync ----------');
63
+ $this->_start = microtime(true);
64
+ $this->_exportWishlistForWebsite($website);
65
+ //send wishlist as transactional data
66
+ if (isset($this->_wishlists[$website->getId()])) {
67
+ $websiteWishlists = $this->_wishlists[$website->getId()];
68
+
69
+ //register in queue with importer
70
+ $check = Mage::getModel('ddg_automation/importer')->registerQueue(
71
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_WISHLIST,
72
+ $websiteWishlists,
73
+ Dotdigitalgroup_Email_Model_Importer::MODE_BULK,
74
+ $website->getId()
75
+ );
76
+
77
+ //set imported
78
+ if ($check) {
79
+ $this->getResource()->setImported($this->_wishlistIds);
80
+ }
81
+ }
82
+ $message = 'Total time for wishlist bulk sync : ' . gmdate("H:i:s", microtime(true) - $this->_start);
83
+ $helper->log($message);
84
+
85
+ //using single api
86
+ $this->_exportWishlistForWebsiteInSingle($website);
87
+ }
88
+ }
89
+ $response['message'] = "wishlist updated: ". $this->_count;
90
+ return $response;
91
+ }
92
+
93
+ private function _exportWishlistForWebsite(Mage_Core_Model_Website $website)
94
+ {
95
+ //reset wishlists
96
+ $this->_wishlists = array();
97
+ $this->_wishlistIds = array();
98
+ $limit = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_TRANSACTIONAL_DATA_SYNC_LIMIT, $website);
99
+ $emailWishlist = $this->_getWishlistToImport($website, $limit);
100
+ $this->_wishlistIds = $emailWishlist->getColumnValues('wishlist_id');
101
+
102
+ if(!empty($this->_wishlistIds)){
103
+ $collection = Mage::getModel('wishlist/wishlist')
104
+ ->getCollection()
105
+ ->addFieldToFilter('main_table.wishlist_id', array('in' => $this->_wishlistIds))
106
+ ->addFieldToFilter('customer_id', array('notnull' => 'true'));
107
+
108
+ $collection->getSelect()
109
+ ->joinLeft(
110
+ array('c' => 'customer_entity'),
111
+ 'c.entity_id = customer_id',
112
+ array('email','store_id')
113
+ );
114
+
115
+ foreach($collection as $wishlist){
116
+ $connectorWishlist = Mage::getModel('ddg_automation/customer_wishlist');
117
+ $connectorWishlist
118
+ ->setId($wishlist->getId())
119
+ ->setUpdatedAt($wishlist->getUpdatedAt())
120
+ ->setCustomerId($wishlist->getCustomerId())
121
+ ->setEmail($wishlist->getEmail());
122
+ $wishListItemCollection = $wishlist->getItemCollection();
123
+ if ($wishListItemCollection->getSize()) {
124
+ foreach ($wishListItemCollection as $item) {
125
+ /* @var $product Mage_Catalog_Model_Product */
126
+ $product = $item->getProduct();
127
+ $wishlistItem = Mage::getModel('ddg_automation/customer_wishlist_item', $product)
128
+ ->setQty($item->getQty())
129
+ ->setPrice($product);
130
+ //store for wishlists
131
+ $connectorWishlist->setItem($wishlistItem);
132
+ $this->_count++;
133
+ }
134
+ //set wishlists for later use
135
+ $this->_wishlists[$website->getId()][] = $connectorWishlist;
136
+ }
137
+ }
138
+ }
139
+ }
140
+
141
+ private function _getWishlistToImport(Mage_Core_Model_Website $website, $limit = 100)
142
+ {
143
+ $collection = $this->getCollection()
144
+ ->addFieldToFilter('wishlist_imported', array('null' => true))
145
+ ->addFieldToFilter('store_id', array('in' => $website->getStoreIds()))
146
+ ->addFieldToFilter('item_count', array('gt' => 0));
147
+
148
+ $collection->getSelect()->limit($limit);
149
+ return $collection;
150
+ }
151
+
152
+ private function _exportWishlistForWebsiteInSingle(Mage_Core_Model_Website $website)
153
+ {
154
+ $helper = Mage::helper('ddg');
155
+ $client = $helper->getWebsiteApiClient($website);
156
+ $limit = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_TRANSACTIONAL_DATA_SYNC_LIMIT, $website);
157
+ $collection = $this->_getModifiedWishlistToImport($website, $limit);
158
+ $this->_wishlistIds = array();
159
+ foreach($collection as $emailWishlist){
160
+ $customer = Mage::getModel('customer/customer')->load($emailWishlist->getCustomerId());
161
+ $wishlist = Mage::getModel('wishlist/wishlist')->load($emailWishlist->getWishlistId());
162
+ /** @var $connectorWishlist */
163
+ $connectorWishlist = Mage::getModel('ddg_automation/customer_wishlist', $customer);
164
+ $connectorWishlist->setId($wishlist->getId());
165
+ $wishListItemCollection = $wishlist->getItemCollection();
166
+ if ($wishListItemCollection->getSize()) {
167
+ foreach ($wishListItemCollection as $item) {
168
+ /* @var $product Mage_Catalog_Model_Product */
169
+ $product = $item->getProduct();
170
+ $wishlistItem = Mage::getModel('ddg_automation/customer_wishlist_item', $product)
171
+ ->setQty($item->getQty())
172
+ ->setPrice($product);
173
+ //store for wishlists
174
+ $connectorWishlist->setItem($wishlistItem);
175
+ $this->_count++;
176
+ }
177
+ //send wishlist as transactional data
178
+ $helper->log('---------- Start wishlist single sync ----------');
179
+ $this->_start = microtime(true);
180
+ //register in queue with importer
181
+ $check = Mage::getModel('ddg_automation/importer')->registerQueue(
182
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_WISHLIST,
183
+ $connectorWishlist,
184
+ Dotdigitalgroup_Email_Model_Importer::MODE_SINGLE,
185
+ $website->getId()
186
+ );
187
+ if ($check) {
188
+ $this->_wishlistIds[] = $emailWishlist->getWishlistId();
189
+ }
190
+ $message = 'Total time for wishlist single sync : ' . gmdate("H:i:s", microtime(true) - $this->_start);
191
+ $helper->log($message);
192
+ }else{
193
+ //register in queue with importer
194
+ $check = Mage::getModel('ddg_automation/importer')->registerQueue(
195
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_WISHLIST,
196
+ array($wishlist->getId()),
197
+ Dotdigitalgroup_Email_Model_Importer::MODE_SINGLE_DELETE,
198
+ $website->getId()
199
+ );
200
+ if ($check) {
201
+ $this->_wishlistIds[] = $emailWishlist->getWishlistId();
202
+ }
203
+ $message = 'Total time for wishlist single sync : ' . gmdate("H:i:s", microtime(true) - $this->_start);
204
+ $helper->log($message);
205
+ }
206
+ }
207
+ if(!empty($this->_wishlistIds))
208
+ $this->getResource()->setImported($this->_wishlistIds, true);
209
+ }
210
+
211
+ private function _getModifiedWishlistToImport(Mage_Core_Model_Website $website, $limit = 100)
212
+ {
213
+ $collection = $this->getCollection()
214
+ ->addFieldToFilter('wishlist_modified', 1)
215
+ ->addFieldToFilter('store_id', array('in' => $website->getStoreIds()));
216
+
217
+ $collection->getSelect()->limit($limit);
218
+ return $collection;
219
+ }
220
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/ConnectorController.php ADDED
@@ -0,0 +1,393 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ if(!$apiModel){
17
+ Mage::getSingleton('adminhtml/session')->addNotice('Please enable api first.');
18
+ }else{
19
+ // get all possible datatifileds
20
+ $datafields = Mage::getModel('ddg_automation/connector_datafield')->getContactDatafields();
21
+ foreach ($datafields as $key => $datafield) {
22
+ $response = $apiModel->postDataFields($datafield);
23
+
24
+ //ignore existing datafields message
25
+ if (isset($response->message) && $response->message != Dotdigitalgroup_Email_Model_Apiconnector_Client::API_ERROR_DATAFIELD_EXISTS) {
26
+ $result['errors'] = true;
27
+ $result['message'] .= ' Datafield ' . $datafield['name'] . ' - '. $response->message . '</br>';
28
+ } else {
29
+ if ($websiteParam) {
30
+ $scope = 'websites';
31
+ $scopeId = $website->getId();
32
+ } else {
33
+ $scope = 'default';
34
+ $scopeId = '0';
35
+ }
36
+ /**
37
+ * map the succesful created datafield
38
+ */
39
+ $config = new Mage_Core_Model_Config();
40
+ $config->saveConfig('connector_data_mapping/customer_data/' . $key, strtoupper($datafield['name']), $scope, $scopeId);
41
+ Mage::helper('ddg')->log('successfully connected : ' . $datafield['name']);
42
+ }
43
+ }
44
+ if ($result['errors']) {
45
+ Mage::getSingleton('adminhtml/session')->addNotice($result['message']);
46
+ } else {
47
+ Mage::getConfig()->cleanCache();
48
+ Mage::getSingleton('adminhtml/session')->addSuccess('All Datafields Created And Mapped.');
49
+ }
50
+ }
51
+
52
+ $this->_redirectUrl($redirectUrl);
53
+ }
54
+
55
+ /**
56
+ * Reset order for reimport.
57
+ */
58
+ public function resetordersAction()
59
+ {
60
+ $num = Mage::getResourceModel('ddg_automation/order')->resetOrders();
61
+ Mage::helper('ddg')->log('-- Reset Orders for re-import : ' . $num);
62
+ Mage::getSingleton('adminhtml/session')->addSuccess('Done. Refreshed '.$num);
63
+ $this->_redirectReferer();
64
+ }
65
+
66
+ /**
67
+ * Reset customers import.
68
+ */
69
+ public function resetcustomersimportAction()
70
+ {
71
+ $num = Mage::getResourceModel('ddg_automation/contact')->resetAllContacts();
72
+ Mage::helper('ddg')->log('-- Reset Contacts for re-import : ' . $num);
73
+ Mage::getSingleton('adminhtml/session')->addSuccess('Done. Refreshed '.$num);
74
+
75
+ $this->_redirectReferer();
76
+ }
77
+
78
+ /**
79
+ * Refresh suppressed contacts.
80
+ */
81
+ public function suppresscontactsAction()
82
+ {
83
+ Mage::getModel('ddg_automation/newsletter_subscriber')
84
+ ->unsubscribe(true);
85
+ Mage::getSingleton('adminhtml/session')->addSuccess('Done.');
86
+ $this->_redirectReferer();
87
+
88
+ }
89
+ /**
90
+ * Remove contact id's.
91
+ */
92
+ public function deletecontactidsAction()
93
+ {
94
+ $num = Mage::getResourceModel('ddg_automation/contact')->deleteContactIds();
95
+ Mage::getSingleton('adminhtml/session')->addSuccess('Number Of Contacts Id Removed: '. $num);
96
+ $this->_redirectReferer();
97
+ }
98
+
99
+ /**
100
+ * Ajax API validation.
101
+ */
102
+ public function ajaxvalidationAction()
103
+ {
104
+ $params = $this->getRequest()->getParams();
105
+ $apiUsername = $params['api_username'];
106
+ // use javascript btoa function to encode the password
107
+
108
+ $apiPassword = base64_decode($params['api_password']);
109
+ $message = Mage::getModel('ddg_automation/apiconnector_test')->ajaxvalidate($apiUsername, $apiPassword);
110
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($message));
111
+ }
112
+
113
+ /**
114
+ * Ajax request to reset the import for contacts.
115
+ */
116
+ public function resetcontactsajaxAction()
117
+ {
118
+ $numReseted = Mage::getResourceModel('ddg_automation/contact')->resetAllContacts();
119
+ $message = array('reseted' => $numReseted);
120
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($message));
121
+ }
122
+
123
+ /**
124
+ * Ajax requets to reset susbcribers for reimport.
125
+ */
126
+ public function ajaxresetsubscribersAction()
127
+ {
128
+ $num = Mage::getResourceModel('ddg_automation/contact')->resetSubscribers();
129
+ $message = array('reseted' => $num);
130
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($message));
131
+ }
132
+
133
+ /**
134
+ * Ajax request to reset orders for reimoport.
135
+ */
136
+ public function ajaxresetguestsAction()
137
+ {
138
+ $num = Mage::getResourceModel('ddg_automation/contact')->resetAllGuestContacts();
139
+ $message = array('reseted' => $num);
140
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($message));
141
+ }
142
+
143
+ public function createnewdatafieldAction()
144
+ {
145
+ //get params required for datafield
146
+ $request = $this->getRequest();
147
+ $name = $request->getParam('name', false);
148
+ $type = $request->getParam('type', false);
149
+ $default = $request->getParam('default', 0);
150
+ $access = $request->getParam('access', false);
151
+ $website = $request->getParam('website', 0);
152
+
153
+ //api client for this website
154
+ $client = Mage::helper('ddg')->getWebsiteApiClient($website);
155
+ //only if all data is available
156
+ if ($name && $type && $access) {
157
+ //create datafield
158
+ $response = $client->postDataFields($name, $type, $access, $default);
159
+ //error creating datafield message
160
+ if (isset($response->message)) {
161
+ //send error message to backend
162
+ Mage::getSingleton('adminhtml/session')->addError($response->message);
163
+ Mage::helper('ddg')->log($response->message);
164
+ } else {
165
+ //success message
166
+ Mage::getSingleton('adminhtml/session')->addSuccess('Datafield created : ' . $name);
167
+ }
168
+ } else {
169
+ $message = 'Name ' . $name . ', type ' . $type . ' default ' . $default . 'access ' . $access;
170
+ Mage::getSingleton('adminhtml/session')->addError('Datafield cannot be empty.');
171
+ Mage::helper('ddg')->rayLog('100', $message);
172
+ }
173
+ }
174
+
175
+ /**
176
+ * Create new address book action.
177
+ */
178
+ public function createnewaddressbookAction()
179
+ {
180
+ $addressBookName = $this->getRequest()->getParam('name');
181
+ $visibility = $this->getRequest()->getParam('visibility');
182
+ $website = $this->getRequest()->getParam('website', 0);
183
+ $client = Mage::helper('ddg')->getWebsiteApiClient($website);
184
+ if (strlen($addressBookName)) {
185
+ $response = $client->postAddressBooks($addressBookName, $visibility);
186
+ if (isset($response->message))
187
+ Mage::getSingleton('adminhtml/session')->addError($response->message);
188
+ else
189
+ Mage::getSingleton('adminhtml/session')->addSuccess('Address book : '. $addressBookName . ' created.');
190
+ }
191
+
192
+ }
193
+
194
+ public function reimoprtsubscribersAction()
195
+ {
196
+ $updated = Mage::getResourceModel('ddg_automation/contact')->resetSubscribers();
197
+ if ($updated) {
198
+ Mage::getSingleton('adminhtml/session')->addSuccess('Done.');
199
+ } else {
200
+ Mage::getSingleton('adminhtml/session')->addNotice('No subscribers imported!');
201
+ }
202
+ $this->_redirectReferer();
203
+ }
204
+
205
+ /**
206
+ * path constant for config helper sent as string.
207
+ */
208
+ public function enablewebsiteconfigurationAction()
209
+ {
210
+ $path = $this->getRequest()->getParam('path');
211
+ $value = $this->getRequest()->getParam('value');
212
+ $website = $this->getRequest()->getParam('website', 0);
213
+
214
+ $path = constant('Dotdigitalgroup_Email_Helper_Config::' . $path);
215
+ $scope = 'websites';
216
+ $scopeId = $website;
217
+
218
+ $config = Mage::getConfig();
219
+
220
+ //use value 1 if not set
221
+ if (isset($value))
222
+ $config->saveConfig($path, $value, $scope, $scopeId);
223
+ else
224
+ $config->saveConfig($path, 1, $scope, $scopeId);
225
+
226
+ //clean cache
227
+ $config->cleanCache();
228
+
229
+ $this->_redirectReferer();
230
+ }
231
+
232
+ /**
233
+ * Populate the tables (customer-email_contact, subscribers-email_contact) with missing ones.
234
+ */
235
+ public function populatecontactsAction()
236
+ {
237
+ Mage::getResourceModel('ddg_automation/contact')->populateAndCleanup();
238
+
239
+ Mage::getSingleton( 'adminhtml/session' )->addSuccess( "Contacts populated");
240
+
241
+ $this->_redirectReferer();
242
+ }
243
+
244
+ /**
245
+ * Trigger to run the contact sync.
246
+ */
247
+ public function runcontactsyncAction()
248
+ {
249
+ $result = Mage::getModel('ddg_automation/cron')->contactSync();
250
+
251
+ if ($result['message'])
252
+ Mage::getSingleton('adminhtml/session')->addSuccess($result['message']);
253
+
254
+ $this->_redirectReferer();
255
+ }
256
+
257
+ /**
258
+ * Trigger to run the subscriber sync.
259
+ */
260
+ public function runsubscribersyncAction()
261
+ {
262
+ $result = Mage::getModel('ddg_automation/cron')->subscribersAndGuestSync();
263
+
264
+ if ($result['message'])
265
+ Mage::getSingleton('adminhtml/session')->addSuccess($result['message']);
266
+
267
+ $this->_redirectReferer();
268
+ }
269
+
270
+ /**
271
+ * Trigger to run the order sync.
272
+ */
273
+ public function runordersyncAction()
274
+ {
275
+
276
+ $result = Mage::getModel('ddg_automation/cron')->orderSync();
277
+ if ($result['message'])
278
+ Mage::getSingleton('adminhtml/session')->addSuccess($result['message']);
279
+
280
+ $this->_redirectReferer();
281
+ }
282
+
283
+ /**
284
+ * Trigger to run the review sync.
285
+ */
286
+ public function runreviewsyncAction()
287
+ {
288
+
289
+ $result = Mage::getModel('ddg_automation/cron')->reviewSync();
290
+ if ($result['message'])
291
+ Mage::getSingleton('adminhtml/session')->addSuccess($result['message']);
292
+
293
+ $this->_redirectReferer();
294
+ }
295
+
296
+ /**
297
+ * Trigger to run the reviw sync.
298
+ */
299
+ public function runwishlistsyncAction()
300
+ {
301
+
302
+ $result = Mage::getModel('ddg_automation/wishlist')->sync();
303
+ if ($result['message'])
304
+ Mage::getSingleton('adminhtml/session')->addSuccess($result['message']);
305
+
306
+ $this->_redirectReferer();
307
+ }
308
+
309
+ /**
310
+ * Trigger to run the quote sync.
311
+ */
312
+ public function runquotesyncAction()
313
+ {
314
+
315
+ $result = Mage::getModel('ddg_automation/cron')->quoteSync();
316
+ if ($result['message'])
317
+ Mage::getSingleton('adminhtml/session')->addSuccess($result['message']);
318
+
319
+ $this->_redirectReferer();
320
+ }
321
+
322
+ /**
323
+ * Reset quote for reimport.
324
+ */
325
+ public function resetquotesAction()
326
+ {
327
+ $num = Mage::getResourceModel('ddg_automation/quote')->resetQuotes();
328
+ Mage::helper('ddg')->log('-- Reset Quotes for reimport : ' . $num);
329
+ Mage::getSingleton('adminhtml/session')->addSuccess('Done.');
330
+ $this->_redirectReferer();
331
+ }
332
+
333
+ /**
334
+ * Reset reviews for reimport.
335
+ */
336
+ public function resetreviewsAction()
337
+ {
338
+ $num = Mage::getResourceModel('ddg_automation/review')->reset();
339
+ Mage::helper('ddg')->log('-- Reset Reviews for reimport : ' . $num);
340
+ Mage::getSingleton('adminhtml/session')->addSuccess('Done.');
341
+ $this->_redirectReferer();
342
+ }
343
+
344
+ /**
345
+ * Reset wishlist for reimport.
346
+ */
347
+ public function resetwishlistsAction()
348
+ {
349
+ $num = Mage::getResourceModel('ddg_automation/wishlist')->reset();
350
+ Mage::helper('ddg')->log('-- Reset Wishlist for reimport : ' . $num);
351
+ Mage::getSingleton('adminhtml/session')->addSuccess('Done.');
352
+ $this->_redirectReferer();
353
+ }
354
+
355
+ /**
356
+ * Re-set all tables
357
+ */
358
+ public function resetAction()
359
+ {
360
+ Mage::getResourceModel('ddg_automation/contact')->resetAllTables();
361
+ Mage::getSingleton('adminhtml/session')->addSuccess('All tables successfully reset.');
362
+ $this->_redirectReferer();
363
+ }
364
+
365
+ /**
366
+ * Reset catalog for reimport.
367
+ */
368
+ public function resetcatalogAction()
369
+ {
370
+ $num = Mage::getResourceModel('ddg_automation/catalog')->reset();
371
+ Mage::helper('ddg')->log('-- Reset Catalog for reimport : ' . $num);
372
+ Mage::getSingleton('adminhtml/session')->addSuccess('Done.');
373
+ $this->_redirectReferer();
374
+ }
375
+
376
+ /**
377
+ * Trigger to run the catalog sync.
378
+ */
379
+ public function runcatalogsyncAction()
380
+ {
381
+
382
+ $result = Mage::getModel('ddg_automation/cron')->catalogSync();
383
+ if ($result['message'])
384
+ Mage::getSingleton('adminhtml/session')->addSuccess($result['message']);
385
+
386
+ $this->_redirectReferer();
387
+ }
388
+
389
+ protected function _isAllowed()
390
+ {
391
+ return Mage::getSingleton('admin/session')->isAllowed('system/config/connector_developer_settings');
392
+ }
393
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/CustomerController.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Adminhtml_CustomerController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+ public function statAction()
6
+ {
7
+ $block = $this->getLayout()->createBlock('ddg_automation/adminhtml_customer_tab_stats');
8
+ echo $block->toHtml();
9
+ }
10
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/AutomationController.php ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $num = Mage::getResourceModel('ddg_automation/automation')->massDelete($automationIds);
45
+ if(is_int($num)){
46
+ $this->_getSession()->addSuccess(
47
+ Mage::helper('ddg')->__('Total of %d record(s) have been deleted.', $num)
48
+ );
49
+ }else
50
+ $this->_getSession()->addError($num->getMessage());
51
+ }
52
+ $this->_redirect('*/*/index');
53
+ }
54
+
55
+ /**
56
+ * Mark for resend.
57
+ */
58
+ public function massResendAction()
59
+ {
60
+ $automationIds = $this->getRequest()->getParam('automation');
61
+ if (!is_array($automationIds)) {
62
+ $this->_getSession()->addError($this->__('Please select .'));
63
+ }else {
64
+ $num = Mage::getResourceModel('ddg_automation/automation')->massResend($automationIds);
65
+ if(is_int($num)){
66
+ $this->_getSession()->addSuccess(
67
+ Mage::helper('ddg')->__('Total of %d record(s) have been deleted.', $num)
68
+ );
69
+ }else
70
+ $this->_getSession()->addError($num->getMessage());
71
+ }
72
+ $this->_redirect('*/*/index');
73
+ }
74
+
75
+ protected function _isAllowed()
76
+ {
77
+ return Mage::getSingleton('admin/session')->isAllowed('email_connector/reports/email_connector_automation');
78
+ }
79
+
80
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/CampaignController.php ADDED
@@ -0,0 +1,207 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $num = Mage::getResourceModel('ddg_automation/campaign')->massDelete($campaignIds);
132
+ if(is_int($num)){
133
+ $this->_getSession()->addSuccess(
134
+ Mage::helper('ddg')->__('Total of %d record(s) have been deleted.', $num));
135
+ }
136
+ else
137
+ $this->_getSession()->addError($num->getMessage());
138
+ }
139
+ $this->_redirect('*/*/index');
140
+ }
141
+
142
+ /**
143
+ * Mass mark for resend campaings.
144
+ */
145
+ public function massResendAction()
146
+ {
147
+ $campaignIds = $this->getRequest()->getParam('campaign');
148
+ if (!is_array($campaignIds)) {
149
+ $this->_getSession()->addError($this->__('Please select campaigns.'));
150
+ } else {
151
+ $num = Mage::getResourceModel('ddg_automation/campaign')->massResend($campaignIds);
152
+ if(is_int($num)){
153
+ $this->_getSession()->addSuccess(
154
+ Mage::helper('ddg')->__('Total of %d record(s) have resend .', $num)
155
+ );
156
+ }else
157
+ $this->_getSession()->addError($num->getMessage());
158
+ }
159
+ $this->_redirect('*/*/index');
160
+ }
161
+
162
+ /**
163
+ * main page.
164
+ */
165
+ public function gridAction()
166
+ {
167
+ $this->loadLayout();
168
+ $this->renderLayout();
169
+ }
170
+
171
+ /**
172
+ * manage the campaigns.
173
+ *
174
+ * @return Dotdigitalgroup_Email_Model_Campaign
175
+ */
176
+ protected function _initAction()
177
+ {
178
+ $this->_title($this->__('Newsletter'))
179
+ ->_title($this->__('Manage Campaigns'));
180
+
181
+ $campaignId = (int) $this->getRequest()->getParam('id');
182
+ $campaign = Mage::getModel('ddg_automation/campaign');
183
+
184
+ if ($campaignId) {
185
+ $campaign->load($campaignId);
186
+ }
187
+ Mage::register('email_campaign', $campaign);
188
+ return $campaign;
189
+ }
190
+
191
+ /**
192
+ * Export campaigns to CSV file.
193
+ */
194
+ public function exportCsvAction()
195
+ {
196
+ $fileName = 'campaign.csv';
197
+ $content = $this->getLayout()->createBlock('ddg_automation/adminhtml_campaign_grid')
198
+ ->getCsvFile();
199
+ $this->_prepareDownloadResponse($fileName, $content);
200
+ }
201
+
202
+ protected function _isAllowed()
203
+ {
204
+ return Mage::getSingleton('admin/session')->isAllowed('email_connector/reports/email_connector_campaign');
205
+ }
206
+
207
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/CatalogController.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Adminhtml_Email_CatalogController 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_catalog'));
13
+ $this->getLayout()->getBlock('head')->setTitle('Connector Catalog');
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('email_connector/reports/email_connector_catalog');
25
+ }
26
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/ContactController.php ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $num = Mage::getResourceModel('ddg_automation/contact')->massDelete($contactIds);
114
+ if(is_int($num)){
115
+ $this->_getSession()->addSuccess(
116
+ Mage::helper('ddg')->__('Total of %d record(s) have been deleted.', $num)
117
+ );
118
+ }else
119
+ $this->_getSession()->addError($num->getMessage());
120
+ }
121
+ $this->_redirect('*/*/index');
122
+ }
123
+
124
+ /**
125
+ * Mark a contact to be resend.
126
+ */
127
+ public function massResendAction()
128
+ {
129
+ $contactIds = $this->getRequest()->getParam('contact');
130
+
131
+ if (!is_array($contactIds)) {
132
+ $this->_getSession()->addError($this->__('Please select contacts.'));
133
+ }else {
134
+ $num = Mage::getResourceModel('ddg_automation/contact')->massResend($contactIds);
135
+ if(is_int($num)){
136
+ $this->_getSession()->addSuccess(
137
+ Mage::helper('ddg')->__('Total of %d record(s) set for resend.', $num)
138
+ );
139
+ }else
140
+ $this->_getSession()->addError($num->getMessage());
141
+ }
142
+ $this->_redirect('*/*/index');
143
+ }
144
+
145
+
146
+ /**
147
+ * main grid.
148
+ */
149
+ public function gridAction(){
150
+ $this->loadLayout();
151
+ $this->renderLayout();
152
+ }
153
+
154
+ protected function _initAction()
155
+ {
156
+ $this->_title($this->__('Newsletter'))
157
+ ->_title($this->__('Manage Contacts'));
158
+
159
+ $contactId = (int) $this->getRequest()->getParam('id');
160
+ $contact = Mage::getModel('ddg_automation/contact')
161
+ ->setStoreId($this->getRequest()->getParam('store', 0));
162
+
163
+ if ($contactId) {
164
+ $contact->load($contactId);
165
+ }
166
+ Mage::register('current_contact', $contact);
167
+ return $contact;
168
+ }
169
+
170
+ public function exportCsvAction()
171
+ {
172
+ $fileName = 'contacts.csv';
173
+ $content = $this->getLayout()->createBlock('ddg_automation/adminhtml_contact_grid')
174
+ ->getCsvFile();
175
+ $this->_prepareDownloadResponse($fileName, $content);
176
+ }
177
+
178
+ protected function _isAllowed()
179
+ {
180
+ return Mage::getSingleton('admin/session')->isAllowed('email_connector/reports/email_connector_contact');
181
+ }
182
+
183
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/DashboardController.php ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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('email_connector');
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
+ $this->getResponse()->setBody($block->toHtml());
50
+ }
51
+
52
+ protected function _isAllowed()
53
+ {
54
+ return Mage::getSingleton('admin/session')->isAllowed('email_connector/email_connector_dashboard');
55
+ }
56
+
57
+
58
+ /**
59
+ * Ajax save the state of expandbles fieldsets.
60
+ */
61
+ public function stateAction()
62
+ {
63
+ $configState = array(
64
+ $this->getRequest()->getParam('container') => $this->getRequest()->getParam('value')
65
+ );
66
+ $this->_saveState($configState);
67
+ }
68
+
69
+ protected function _saveState($configState = array())
70
+ {
71
+ $adminUser = Mage::getSingleton('admin/session')->getUser();
72
+ if (is_array($configState)) {
73
+ $extra = $adminUser->getExtra();
74
+ if (!is_array($extra)) {
75
+ $extra = array();
76
+ }
77
+ if (!isset($extra['configState'])) {
78
+ $extra['configState'] = array();
79
+ }
80
+ foreach ($configState as $fieldset => $state) {
81
+ $extra['configState'][$fieldset] = $state;
82
+ }
83
+ $adminUser->saveExtra($extra);
84
+ }
85
+
86
+ return true;
87
+ }
88
+
89
+
90
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/ImporterController.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Adminhtml_Email_ImporterController 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_importer'));
13
+ $this->getLayout()->getBlock('head')->setTitle('Importer Status');
14
+ $this->renderLayout();
15
+ }
16
+
17
+ /**
18
+ * Mark a contact to be resend.
19
+ */
20
+ public function massResendAction()
21
+ {
22
+ $ids = $this->getRequest()->getParam('importer');
23
+ if (!is_array($ids)) {
24
+ $this->_getSession()->addError($this->__('Please select import.'));
25
+ }else {
26
+ $num = Mage::getResourceModel('ddg_automation/importer')->massResend($ids);
27
+ if(is_int($num)) {
28
+ $this->_getSession()->addSuccess(
29
+ Mage::helper('ddg')->__('Total of %d record(s) set for reset.', $num)
30
+ );
31
+ }else
32
+ $this->_getSession()->addError($num->getMessage());
33
+ }
34
+ $this->_redirect('*/*/index');
35
+ }
36
+
37
+
38
+ /**
39
+ * Mass delete contacts.
40
+ */
41
+ public function massDeleteAction()
42
+ {
43
+ $ids = $this->getRequest()->getParam('importer');
44
+ if (!is_array($ids)) {
45
+ $this->_getSession()->addError($this->__('Please select import.'));
46
+ }else {
47
+ $num = Mage::getResourceModel('ddg_automation/importer')->massDelete($ids);
48
+ if (is_int($num)){
49
+ $this->_getSession()->addSuccess(
50
+ Mage::helper('ddg')->__('Total of %d record(s) have been deleted.', $num)
51
+ );
52
+ }else
53
+ $this->_getSession()->addError($num->getMessage());
54
+ }
55
+ $this->_redirect('*/*/index');
56
+ }
57
+
58
+ /**
59
+ * Check currently called action by permissions for current user
60
+ *
61
+ * @return bool
62
+ */
63
+ protected function _isAllowed()
64
+ {
65
+ return Mage::getSingleton('admin/session')->isAllowed('email_connector/reports/email_connector_importer');
66
+ }
67
+ }
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('email_connector/reports/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('email_connector/reports/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('email_connector/reports/email_connector_review');
25
+ }
26
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/RulesController.php ADDED
@@ -0,0 +1,207 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Adminhtml_Email_RulesController 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
+ * init action
15
+ *
16
+ * @return $this
17
+ */
18
+ protected function _initAction()
19
+ {
20
+ $this->loadLayout()
21
+ ->_setActiveMenu('email_connector')
22
+ ->_addBreadcrumb(Mage::helper('ddg')->__('Exclusion Rules'), Mage::helper('ddg')->__('Exclusion Rules'))
23
+ ;
24
+ return $this;
25
+ }
26
+
27
+ /**
28
+ * index action
29
+ */
30
+ public function indexAction()
31
+ {
32
+ $this->loadLayout();
33
+ $this->_setActiveMenu('email_connector');
34
+ $this->getLayout()->getBlock('head')->setTitle('Connector Exclusion Rule(s)');
35
+ $this->_addBreadcrumb(Mage::helper('ddg')->__('Exclusion Rules'), Mage::helper('ddg')->__('Exclusion Rules'));
36
+ $this->renderLayout();
37
+ }
38
+
39
+ /**
40
+ * action for new rule page
41
+ */
42
+ public function newAction()
43
+ {
44
+ $this->_forward('edit');
45
+ }
46
+
47
+ /**
48
+ * action for edit rule page
49
+ */
50
+ public function editAction()
51
+ {
52
+ $id = $this->getRequest()->getParam('id');
53
+ $model = Mage::getModel('ddg_automation/rules');
54
+
55
+ if ($id) {
56
+ $model->load($id);
57
+ if (!$model->getId()) {
58
+ Mage::getSingleton('adminhtml/session')->addError(
59
+ Mage::helper('adminhtml')->__('This rule no longer exists.'));
60
+ $this->_redirect('*/*');
61
+ return;
62
+ }
63
+ //$model->setCondition(unserialize($model->getCondition()));
64
+ }
65
+ $this->_title($model->getId() ? $model->getName() : $this->__('New Rule'));
66
+
67
+ // set entered data if was error when we do save
68
+ $data = Mage::getSingleton('adminhtml/session')->getPageData(true);
69
+ if (!empty($data)) {
70
+ $model->addData($data);
71
+ }
72
+
73
+ Mage::register('current_ddg_rule', $model);
74
+
75
+ $this->_initAction()->getLayout()->getBlock('ddg_rule_edit')
76
+ ->setData('action', $this->getUrl('*/*/save'));
77
+
78
+ $this->_addBreadcrumb(
79
+ $id ? Mage::helper('ddg')->__('Edit Rule')
80
+ : Mage::helper('ddg')->__('New Rule'),
81
+ $id ? Mage::helper('ddg')->__('Edit Rule')
82
+ : Mage::helper('ddg')->__('New Rule'))
83
+ ->renderLayout();
84
+
85
+ }
86
+
87
+ /**
88
+ * action for save rule data
89
+ */
90
+ public function saveAction()
91
+ {
92
+ if ($this->getRequest()->getPost()) {
93
+ try {
94
+ $model = Mage::getModel('ddg_automation/rules');
95
+ $data = $this->getRequest()->getPost();
96
+ $id = $this->getRequest()->getParam('id');
97
+
98
+ if($data['website_ids']){
99
+ foreach($data['website_ids'] as $websiteId){
100
+ $result = $model->checkWebsiteBeforeSave($websiteId, $data['type'], $id);
101
+ if(!$result){
102
+ $websiteName = Mage::app()->getWebsite($websiteId)->getName();
103
+ $this->_getSession()->addError(
104
+ Mage::helper('adminhtml')->__('Rule already exist for website '. $websiteName . '. You can only have one rule per website.'));
105
+ $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
106
+ return;
107
+ }
108
+ }
109
+ }
110
+
111
+ if ($id) {
112
+ $model->load($id);
113
+ if ($id != $model->getId()) {
114
+ Mage::throwException(Mage::helper('ddg')->__('Wrong rule specified.'));
115
+ }
116
+ }
117
+
118
+ foreach($data as $key => $value){
119
+ if($key != 'form_key'){
120
+ if($key == 'condition'){
121
+ if (is_array($value))
122
+ unset($value['__empty']);
123
+ }
124
+ $model->setData($key, $value);
125
+ }
126
+ }
127
+
128
+ $this->_getSession()->setPageData($model->getData());
129
+
130
+ $model->save();
131
+ $this->_getSession()->addSuccess(Mage::helper('adminhtml')->__('The rule has been saved.'));
132
+ $this->_getSession()->setPageData(false);
133
+ if ($this->getRequest()->getParam('back')) {
134
+ $this->_redirect('*/*/edit', array('id' => $model->getId()));
135
+ return;
136
+ }
137
+ $this->_redirect('*/*/');
138
+ return;
139
+ } catch (Mage_Core_Exception $e) {
140
+ $this->_getSession()->addError($e->getMessage());
141
+ $id = (int)$this->getRequest()->getParam('id');
142
+ if (!empty($id)) {
143
+ $this->_redirect('*/*/edit', array('id' => $id));
144
+ } else {
145
+ $this->_redirect('*/*/new');
146
+ }
147
+ return;
148
+
149
+ } catch (Exception $e) {
150
+ $this->_getSession()->addError(
151
+ Mage::helper('adminhtml')->__('An error occurred while saving the rule data. Please review the log and try again.'));
152
+ Mage::logException($e);
153
+ Mage::getSingleton('adminhtml/session')->setPageData($data);
154
+ $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
155
+ return;
156
+ }
157
+ }
158
+ $this->_redirect('*/*/');
159
+ }
160
+
161
+ /**
162
+ * action for delete button
163
+ */
164
+ public function deleteAction()
165
+ {
166
+ if ($id = $this->getRequest()->getParam('id')) {
167
+ try {
168
+ $model = Mage::getModel('ddg_automation/rules');
169
+ $model->setId($id);
170
+ $model->delete();
171
+ Mage::getSingleton('adminhtml/session')->addSuccess(
172
+ Mage::helper('adminhtml')->__('The rule has been deleted.'));
173
+ $this->_redirect('*/*/');
174
+ return;
175
+ } catch (Mage_Core_Exception $e) {
176
+ $this->_getSession()->addError($e->getMessage());
177
+ } catch (Exception $e) {
178
+ $this->_getSession()->addError(
179
+ Mage::helper('adminhtml')->__('An error occurred while deleting the rule. Please review the log and try again.'));
180
+ Mage::logException($e);
181
+ $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
182
+ return;
183
+ }
184
+ }
185
+ Mage::getSingleton('adminhtml/session')->addError(
186
+ Mage::helper('adminhtml')->__('Unable to find a rule to delete.'));
187
+ $this->_redirect('*/*/');
188
+ }
189
+
190
+ /**
191
+ * main page/grid.
192
+ */
193
+ public function gridAction()
194
+ {
195
+ $this->loadLayout();
196
+ $this->renderLayout();
197
+ }
198
+
199
+ /**
200
+ * @return bool
201
+ */
202
+ protected function _isAllowed()
203
+ {
204
+ return Mage::getSingleton('admin/session')->isAllowed('email_connector/automation_rules');
205
+ }
206
+
207
+ }
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('email_connector/reports/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,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
20
+ protected function _isAllowed()
21
+ {
22
+ return Mage::getSingleton('admin/session')->isAllowed('system/config/connector_dynamic_content');
23
+ }
24
+ }
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/AccountController.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Customer_AccountController extends Mage_Core_Controller_Front_Action
4
+ {
5
+ /**
6
+ * Checking if user is logged in. If not logged in then redirect to customer login
7
+ */
8
+ public function preDispatch()
9
+ {
10
+ parent::preDispatch();
11
+
12
+ if (!Mage::getSingleton('customer/session')->authenticate($this)) {
13
+ $this->setFlag('', 'no-dispatch', true);
14
+
15
+ // adding message in customer login page
16
+ Mage::getSingleton('core/session')
17
+ ->addNotice(Mage::helper('ddg')->__('Please sign in or create a new account'));
18
+ }
19
+ }
20
+
21
+ public function statsAction()
22
+ {
23
+ $this->loadLayout();
24
+ $this->getLayout()->getBlock('head')->setTitle($this->__('Email Activity'));
25
+ $this->renderLayout();
26
+ }
27
+ }
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() or !$this->_getCustomerSession()->getConnectorContactId()) {
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 = $this->_getCustomerSession()->getConnectorContactId();
46
+ $customer_email = $this->_getCustomerSession()->getCustomer()->getEmail();
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 address books
57
+ $bookError = false;
58
+ $addressBooks = $client->getContactAddressBooks($contact->id);
59
+ $subscriberAddressBook = Mage::helper('ddg')->getSubscriberAddressBook(Mage::app()->getWebsite());
60
+ $processedAddressBooks = array();
61
+ if(is_array($addressBooks)){
62
+ foreach($addressBooks as $addressBook){
63
+ if($subscriberAddressBook != $addressBook->id)
64
+ $processedAddressBooks[$addressBook->id] = $addressBook->name;
65
+ }
66
+ }
67
+ if(isset($additional_subscriptions)){
68
+ foreach($additional_subscriptions as $additional_subscription){
69
+ if(!isset($processedAddressBooks[$additional_subscription])){
70
+ $bookResponse = $client->postAddressBookContacts($additional_subscription, $contact);
71
+ if(isset($bookResponse->message))
72
+ $bookError = true;
73
+
74
+ }
75
+ }
76
+ foreach($processedAddressBooks as $bookId => $name){
77
+ if(!in_array($bookId, $additional_subscriptions)) {
78
+ $bookResponse = $client->deleteAddressBookContact($bookId, $contact->id);
79
+ if(isset($bookResponse->message))
80
+ $bookError = true;
81
+ }
82
+ }
83
+ }
84
+ else{
85
+ foreach($processedAddressBooks as $bookId => $name){
86
+ $bookResponse = $client->deleteAddressBookContact($bookId, $contact->id);
87
+ if(isset($bookResponse->message))
88
+ $bookError = true;
89
+ }
90
+ }
91
+
92
+ //contact data fields
93
+ $data = array();
94
+ $dataFields = $client->getDataFields();
95
+ $processedFields = array();
96
+ foreach($dataFields as $dataField){
97
+ $processedFields[$dataField->name] = $dataField->type;
98
+ }
99
+ foreach($data_fields as $key => $value){
100
+ if(isset($processedFields[$key]) && $value){
101
+ if($processedFields[$key] == 'Numeric'){
102
+ $data_fields[$key] = (int)$value;
103
+ }
104
+ if($processedFields[$key] == 'String'){
105
+ $data_fields[$key] = (string)$value;
106
+ }
107
+ if($processedFields[$key] == 'Date'){
108
+ $date = new Zend_Date($value, "Y/M/d");
109
+ $data_fields[$key] = $date->toString(Zend_Date::ISO_8601);
110
+ }
111
+ $data[] = array(
112
+ 'Key' => $key,
113
+ 'Value' => $data_fields[$key]
114
+ );
115
+ }
116
+ }
117
+ $contactResponse = $client->updateContactDatafieldsByEmail($customer_email, $data);
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,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ Mage::register('current_order', $order);
22
+ $storeId = $order->getStoreId();
23
+ //start the emulation for order store
24
+ $appEmulation = Mage::getSingleton('core/app_emulation');
25
+ $appEmulation->startEnvironmentEmulation($storeId);
26
+ } else {
27
+ //throw new Exception('TE invoice : order not found: ' . $orderId);
28
+ Mage::helper('ddg')->log('order not found: ' . $orderId);
29
+ $this->sendResponse();
30
+ die;
31
+ }
32
+ } else {
33
+ //throw new Exception('TE invoice : order_id missing :' . $orderId);
34
+ Mage::helper('ddg')->log('order_id missing :' . $orderId);
35
+ $this->sendResponse();
36
+ die;
37
+ }
38
+ parent::preDispatch();
39
+ }
40
+ }
app/code/community/Dotdigitalgroup/Email/controllers/EmailController.php ADDED
@@ -0,0 +1,278 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * @var $_quote Mage_Sales_Model_Quote
8
+ */
9
+ protected $_quote;
10
+
11
+ /**
12
+ * wishlist
13
+ */
14
+ public function wishlistAction()
15
+ {
16
+ //authenticate
17
+ $this->authenticate();
18
+ $this->loadLayout();
19
+ $wishlist = $this->getLayout()->createBlock('ddg_automation/wishlist', 'connector_wishlist', array(
20
+ 'template' => 'connector/wishlist.phtml'
21
+ ));
22
+ $this->getLayout()->getBlock('content')->append($wishlist);
23
+ $this->renderLayout();
24
+ $this->checkContentNotEmpty($wishlist->toHtml(), false);
25
+ }
26
+
27
+ /**
28
+ * Generate coupon for a coupon code id.
29
+ */
30
+ public function couponAction()
31
+ {
32
+ $this->authenticate();
33
+ $this->loadLayout();
34
+ //page root template
35
+ if ($root = $this->getLayout()->getBlock('root')) {
36
+ $root->setTemplate('page/blank.phtml');
37
+ }
38
+ //content template
39
+ $coupon = $this->getLayout()->createBlock('ddg_automation/coupon', 'connector_coupon', array(
40
+ 'template' => 'connector/coupon.phtml'
41
+ ));
42
+ $this->checkContentNotEmpty($coupon->toHtml(), false);
43
+ $this->getLayout()->getBlock('content')->append($coupon);
44
+ $this->renderLayout();
45
+ }
46
+
47
+ /**
48
+ * Basket page to display the user items with specific email.
49
+ */
50
+ public function basketAction()
51
+ {
52
+ //authenticate
53
+ $this->authenticate();
54
+ $this->loadLayout();
55
+ if ($root = $this->getLayout()->getBlock('root')) {
56
+ $root->setTemplate('page/blank.phtml');
57
+ }
58
+ $basket = $this->getLayout()->createBlock('ddg_automation/basket', 'connector_basket', array(
59
+ 'template' => 'connector/basket.phtml'
60
+ ));
61
+ $this->getLayout()->getBlock('content')->append($basket);
62
+ $this->renderLayout();
63
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
64
+ }
65
+
66
+ public function reviewAction()
67
+ {
68
+ //authenticate
69
+ $this->authenticate();
70
+
71
+ $orderId = $this->getRequest()->getParam('order_id', false);
72
+ //check for order_id param
73
+ if ($orderId) {
74
+ $order = Mage::getModel('sales/order')->load($orderId);
75
+ //check if the order still exists
76
+ if ($order->getId()) {
77
+ Mage::register('current_order', $order);
78
+ } else {
79
+ Mage::helper('ddg')->log('order not found: ' . $orderId);
80
+ $this->sendResponse();
81
+ die;
82
+ }
83
+ } else {
84
+ Mage::helper('ddg')->log('order_id missing :' . $orderId);
85
+ $this->sendResponse();
86
+ die;
87
+ }
88
+
89
+
90
+ $this->loadLayout();
91
+ $review = $this->getLayout()->createBlock('ddg_automation/order', 'connector_review', array(
92
+ 'template' => 'connector/review.phtml'
93
+ ));
94
+ $this->getLayout()->getBlock('content')->append($review);
95
+ $this->renderLayout();
96
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
97
+ }
98
+
99
+ /**
100
+ * Callback action for the automation studio.
101
+ */
102
+ public function callbackAction()
103
+ {
104
+ $code = $this->getRequest()->getParam('code', false);
105
+ $userId = $this->getRequest()->getParam('state');
106
+ $adminUser = Mage::getModel('admin/user')->load($userId);
107
+
108
+
109
+ if ($code && $adminUser->getId()) {
110
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB, true);
111
+ //callback url
112
+ $callback = $baseUrl . 'connector/email/callback';
113
+ $data = 'client_id=' . Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CLIENT_ID) .
114
+ '&client_secret=' . Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CLIENT_SECRET_ID) .
115
+ '&redirect_uri=' . $callback .
116
+ '&grant_type=authorization_code' .
117
+ '&code=' . $code;
118
+
119
+
120
+ $url = Mage::helper('ddg/config')->getTokenUrl();
121
+ $ch = curl_init();
122
+ curl_setopt($ch, CURLOPT_URL, $url);
123
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
124
+ curl_setopt($ch, CURLOPT_TIMEOUT, 10);
125
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
126
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
127
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
128
+ curl_setopt($ch, CURLOPT_POST, count($data));
129
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
130
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array ('Content-Type: application/x-www-form-urlencoded'));
131
+
132
+
133
+ $response = json_decode(curl_exec($ch));
134
+ if ($response === false) {
135
+ Mage::helper('ddg')->rayLog('100', 'Automaion studio number not found : ' . serialize($response));
136
+ Mage::helper('ddg')->log("Error Number: " . curl_errno($ch));
137
+ }
138
+
139
+ //save the refresh token to the admin user
140
+ $adminUser->setRefreshToken($response->refresh_token)->save();
141
+ }
142
+ //redirect to automation index page
143
+ $this->_redirectReferer(Mage::helper('adminhtml')->getUrl('adminhtml/email_automation/index'));
144
+ }
145
+
146
+ /**
147
+ * quote process action
148
+ */
149
+ public function getbasketAction()
150
+ {
151
+ $quote_id = $this->getRequest()->getParam('quote_id');
152
+ //no quote id redirect to base url
153
+ if(!$quote_id)
154
+ $this->_redirectUrl(Mage::getBaseUrl());
155
+
156
+ $quoteModel = Mage::getModel('sales/quote')->load($quote_id);
157
+
158
+ //no quote id redirect to base url
159
+ if (!$quoteModel->getId())
160
+ $this->_redirectUrl(Mage::getBaseUrl());
161
+
162
+ //set quoteModel to _quote property for later use
163
+ $this->_quote = $quoteModel;
164
+
165
+ if($quoteModel->getCustomerId())
166
+ $this->_handleCustomerBasket();
167
+ else
168
+ $this->_handleGuestBasket();
169
+ }
170
+
171
+ /**
172
+ * process customer basket
173
+ */
174
+ private function _handleCustomerBasket()
175
+ {
176
+ $customerSession = Mage::getSingleton('customer/session');
177
+ $configCartUrl = $this->_quote->getStore()->getWebsite()->getConfig(
178
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CONTENT_CART_URL
179
+ );
180
+
181
+ //if customer is logged in then redirect to cart
182
+ if($customerSession->isLoggedIn()){
183
+ $checkoutSession = Mage::getSingleton('checkout/session');
184
+ if($checkoutSession->getQuote() && $checkoutSession->getQuote()->hasItems()){
185
+ $quote = $checkoutSession->getQuote();
186
+ if($this->_quote->getId() != $quote->getId())
187
+ $this->_checkMissingAndAdd();
188
+ }
189
+ else{
190
+ $this->_loadAndReplace();
191
+ }
192
+
193
+ if($configCartUrl)
194
+ $url = $configCartUrl;
195
+ else
196
+ $url = $customerSession->getCustomer()->getStore()->getUrl('checkout/cart');
197
+
198
+ $this->_redirectUrl($url);
199
+ }
200
+ else{
201
+ //set after auth url. customer will be redirected to cart after successful login
202
+ if($configCartUrl)
203
+ $cartUrl = $configCartUrl;
204
+ else
205
+ $cartUrl = 'checkout/cart';
206
+ $customerSession->setAfterAuthUrl($this->_quote->getStore()->getUrl($cartUrl));
207
+
208
+ //send customer to login page
209
+ $configLoginUrl = $this->_quote->getStore()->getWebsite()->getConfig(
210
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CONTENT_LOGIN_URL
211
+ );
212
+ if($configLoginUrl)
213
+ $loginUrl = $configLoginUrl;
214
+ else
215
+ $loginUrl = 'customer/account/login';
216
+ $this->_redirectUrl($this->_quote->getStore()->getUrl($loginUrl));
217
+ }
218
+ }
219
+
220
+ /**
221
+ * process guest basket
222
+ */
223
+ private function _handleGuestBasket()
224
+ {
225
+ $checkoutSession = Mage::getSingleton('checkout/session');
226
+ if($checkoutSession->getQuote() && $checkoutSession->getQuote()->hasItems()){
227
+ $this->_checkMissingAndAdd();
228
+ }
229
+ else{
230
+ $this->_loadAndReplace();
231
+ }
232
+
233
+ $configCartUrl = $this->_quote->getStore()->getWebsite()->getConfig(
234
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CONTENT_CART_URL
235
+ );
236
+
237
+ if($configCartUrl)
238
+ $url = $configCartUrl;
239
+ else
240
+ $url = 'checkout/cart';
241
+ $this->_redirectUrl($this->_quote->getStore()->getUrl($url));
242
+ }
243
+
244
+ /**
245
+ * check missing items from current quote and add
246
+ */
247
+ private function _checkMissingAndAdd()
248
+ {
249
+ $checkoutSession = Mage::getSingleton('checkout/session');
250
+ $currentQuote = $checkoutSession->getQuote();
251
+ if($currentQuote->hasItems()){
252
+ $currentSessionItems = $currentQuote->getAllItems();
253
+ $currentItemIds = array();
254
+ foreach($currentSessionItems as $currentSessionItem){
255
+ $currentItemIds[] = $currentSessionItem->getId();
256
+ }
257
+ foreach($this->_quote->getAllItems() as $item){
258
+ if(!in_array($item->getId(), $currentItemIds)){
259
+ $currentQuote->addItem($item);
260
+ }
261
+ }
262
+ $currentQuote->collectTotals()->save();
263
+ }else{
264
+ $this->_loadAndReplace();
265
+ }
266
+ }
267
+
268
+ /**
269
+ * load quote and replace in session#1114
270
+ */
271
+ private function _loadAndReplace()
272
+ {
273
+ $checkoutSession = Mage::getSingleton('checkout/session');
274
+ $quote = Mage::getSingleton('sales/quote')->load($this->_quote->getId());
275
+ $quote->setIsActive(true)->save();
276
+ $checkoutSession->replaceQuote($quote);
277
+ }
278
+ }
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,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ Mage::register('current_order', $order);
24
+ //start app emulation
25
+ $storeId = $order->getStoreId();
26
+ $appEmulation = Mage::getSingleton('core/app_emulation');
27
+ $appEmulation->startEnvironmentEmulation($storeId);
28
+ } else {
29
+ $message = 'Dynamic : order not found: ' . $orderId;
30
+ Mage::helper('ddg')->log($message);
31
+ Mage::helper('ddg')->rayLog('100', $message);
32
+ }
33
+ } else {
34
+ Mage::helper('ddg')->log('Dynamic : order_id missing :' . $orderId);
35
+ }
36
+ }
37
+
38
+ parent::preDispatch();
39
+ }
40
+
41
+ /**
42
+ * Related products.
43
+ */
44
+ public function relatedAction()
45
+ {
46
+ $this->loadLayout();
47
+ $products = $this->getLayout()->createBlock('ddg_automation/recommended_products', 'connector_recommended_related', array(
48
+ 'template' => 'connector/product/list.phtml'
49
+ ));
50
+ //append related products
51
+ $this->getLayout()->getBlock('content')->append($products);
52
+
53
+ $this->renderLayout();
54
+
55
+ }
56
+
57
+ /**
58
+ * Crosssell products.
59
+ */
60
+ public function crosssellAction()
61
+ {
62
+ $this->loadLayout();
63
+ $products = $this->getLayout()->createBlock('ddg_automation/recommended_products', 'connector_recommended_crosssell', array(
64
+ 'template' => 'connector/product/list.phtml'
65
+ ));
66
+ //append crosssell products.
67
+ $this->getLayout()->getBlock('content')->append($products);
68
+
69
+ $this->renderLayout();
70
+ }
71
+
72
+ /**
73
+ * Upsell products.
74
+ */
75
+ public function upsellAction()
76
+ {
77
+ $this->loadLayout();
78
+ $products = $this->getLayout()->createBlock('ddg_automation/recommended_products', 'connector_recommended_upsell', array(
79
+ 'template' => 'connector/product/list.phtml'
80
+ ));
81
+ //append upsell products
82
+ $this->getLayout()->getBlock('content')->append($products);
83
+
84
+ $this->renderLayout();
85
+ }
86
+
87
+ /**
88
+ * Products that are set to manually push as related.
89
+ */
90
+ public function pushAction()
91
+ {
92
+ $this->loadLayout();
93
+ $products = $this->getLayout()->createBlock('ddg_automation/edc', 'connector_product_push', array(
94
+ 'template' => 'connector/product/list.phtml', 'edc_type' => 'product_push'
95
+ ));
96
+ //append push products
97
+ $this->getLayout()->getBlock('content')->append($products);
98
+ $this->renderLayout();
99
+ }
100
+
101
+ /**
102
+ * Nosto recommendation action.
103
+ */
104
+ public function nostoAction()
105
+ {
106
+ $this->loadLayout();
107
+
108
+ $products = $this->getLayout()->createBlock('ddg_automation/recommended_products', 'connector_nosto_recommended', array(
109
+ 'template' => 'connector/product/nosto.phtml'
110
+ ));
111
+ $html = $products->toHtml();
112
+
113
+ //if empty than display our fallback products instead.
114
+ if (empty($html)) {
115
+ Mage::app()->getRequest()->setActionName('push');
116
+ $this->pushAction();
117
+ } else {
118
+ $this->getLayout()->getBlock('content')->append($products);
119
+ $this->renderLayout();
120
+ }
121
+ }
122
+
123
+ }
app/code/community/Dotdigitalgroup/Email/controllers/QuoteproductsController.php ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ Mage::register('current_quote', $quote);
21
+ //start app emulation
22
+ $storeId = $quote->getStoreId();
23
+ $appEmulation = Mage::getSingleton('core/app_emulation');
24
+ $appEmulation->startEnvironmentEmulation($storeId);
25
+ } else {
26
+ $message = 'Dynamic : Quote not found: ' . $quoteId;
27
+ Mage::helper('ddg')->log($message);
28
+ Mage::helper('ddg')->rayLog('100', $message);
29
+ }
30
+ } else {
31
+ Mage::helper('ddg')->log('Dynamic : order_id missing :' . $quoteId);
32
+ }
33
+ }
34
+
35
+ parent::preDispatch();
36
+ }
37
+
38
+ /**
39
+ * Related products.
40
+ */
41
+ public function relatedAction()
42
+ {
43
+ $this->loadLayout();
44
+ $products = $this->getLayout()->createBlock('ddg_automation/edc', 'connector_recommended_quote_related', array(
45
+ 'template' => 'connector/product/list.phtml' , 'edc_type' => 'quote_products'
46
+ ));
47
+ //append related products
48
+ $this->getLayout()->getBlock('content')->append($products);
49
+ $this->renderLayout();
50
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
51
+ }
52
+
53
+ /**
54
+ * Crosssell products.
55
+ */
56
+ public function crosssellAction()
57
+ {
58
+ $this->loadLayout();
59
+ $products = $this->getLayout()->createBlock('ddg_automation/edc', 'connector_recommended_quote_crosssell', array(
60
+ 'template' => 'connector/product/list.phtml' , 'edc_type' => 'quote_products'
61
+ ));
62
+ //append crosssell products.
63
+ $this->getLayout()->getBlock('content')->append($products);
64
+ $this->renderLayout();
65
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
66
+ }
67
+
68
+ /**
69
+ * Upsell products.
70
+ */
71
+ public function upsellAction()
72
+ {
73
+ $this->loadLayout();
74
+ $products = $this->getLayout()->createBlock('ddg_automation/edc', 'connector_recommended_quote_upsell', array(
75
+ 'template' => 'connector/product/list.phtml' , 'edc_type' => 'quote_products'
76
+ ));
77
+ //append upsell products
78
+ $this->getLayout()->getBlock('content')->append($products);
79
+ $this->renderLayout();
80
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
81
+ }
82
+ }
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/edc', 'connector_customer', array(
25
+ 'template' => 'connector/product/list.phtml', 'edc_type' => 'bestsellers'
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/edc', 'connector_customer', array(
40
+ 'template' => 'connector/product/list.phtml', 'edc_type' => 'most_viewed'
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/edc', 'connector_customer', array(
64
+ 'template' => 'connector/product/list.phtml', 'edc_type' => 'recently_viewed'
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,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_ResponseController extends Mage_Core_Controller_Front_Action
4
+ {
5
+ protected function authenticate()
6
+ {
7
+ //authenticate ip address
8
+ $authIp = Mage::helper('ddg')->authIpAddress();
9
+ if(!$authIp){
10
+ $e = new Exception('You are not authorised to view content of this page.');
11
+ Mage::logException($e);
12
+ throw new Exception($e->getMessage());
13
+ }
14
+
15
+ //authenticate
16
+ $auth = Mage::helper('ddg')->auth($this->getRequest()->getParam('code'));
17
+ if(!$auth){
18
+ $this->sendResponse();
19
+ die;
20
+ }
21
+ }
22
+
23
+ protected function checkContentNotEmpty($output, $flag = true)
24
+ {
25
+ try{
26
+ if(strlen($output) < 3 && $flag == false)
27
+ $this->sendResponse();
28
+ elseif($flag && !strpos($output, '<table'))
29
+ $this->sendResponse();
30
+ } catch (Exception $e) {
31
+ Mage::logException($e);
32
+ throw new Exception($e->getMessage());
33
+ }
34
+ }
35
+
36
+ protected function sendResponse()
37
+ {
38
+ try{
39
+ $this->getResponse()
40
+ ->setHttpResponseCode(204)
41
+ ->setHeader('Pragma', 'public', true)
42
+ ->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true)
43
+ ->setHeader('Content-type', 'text/html; charset=UTF-8', true);
44
+ $this->getResponse()->sendHeaders();
45
+ } catch (Exception $e) {
46
+ Mage::logException($e);
47
+ throw new Exception($e->getMessage());
48
+ }
49
+ }
50
+ }
app/code/community/Dotdigitalgroup/Email/controllers/RulesController.php ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_RulesController extends Mage_Core_Controller_Front_Action
4
+ {
5
+ /**
6
+ * ajax action for actions and value update without selection
7
+ */
8
+ public function ajaxAction()
9
+ {
10
+ $attribute = $this->getRequest()->getParam('attribute');
11
+ $conditionName = $this->getRequest()->getParam('condition');
12
+ $valueName = $this->getRequest()->getParam('value');
13
+ if($attribute && $conditionName && $valueName){
14
+ $type = Mage::getModel('ddg_automation/adminhtml_source_rules_type')->getInputType($attribute);
15
+ $conditionOptions = Mage::getModel('ddg_automation/adminhtml_source_rules_condition')->getInputTypeOptions($type);
16
+ $response['condition'] = $this->_getOptionHtml('conditions', $conditionName, $conditionOptions);
17
+
18
+ $elmType = Mage::getModel('ddg_automation/adminhtml_source_rules_value')->getValueElementType($attribute);
19
+ if($elmType == 'select'){
20
+ $valueOptions = Mage::getModel('ddg_automation/adminhtml_source_rules_value')->getValueSelectOptions($attribute);
21
+ $response['cvalue'] = $this->_getOptionHtml('cvalue', $valueName, $valueOptions);
22
+ }elseif($elmType == 'text'){
23
+ $html = "<input style='width:160px' title='cvalue' class='' id='' name=$valueName />";
24
+ $response['cvalue'] = $html;
25
+ }
26
+ $this->getResponse()->clearHeaders()->setHeader('Content-Type', 'application/json')->setBody(Mage::helper('core')->jsonEncode($response));
27
+ }
28
+ }
29
+
30
+ /**
31
+ * create options array from block
32
+ *
33
+ * @param $title
34
+ * @param $name
35
+ * @param $options
36
+ * @return string
37
+ */
38
+ private function _getOptionHtml($title, $name, $options)
39
+ {
40
+ $block = $this->getLayout()->createBlock('core/html_select');
41
+ $block->setOptions($options)
42
+ ->setId('')
43
+ ->setClass('')
44
+ ->setTitle($title)
45
+ ->setName($name)
46
+ ->setExtraParams('style="width:160px"');
47
+ return $block->toHtml();
48
+ }
49
+
50
+ /**
51
+ * ajax action for actions and value update with selection
52
+ */
53
+ public function selectedAction()
54
+ {
55
+ $id = $this->getRequest()->getParam('ruleid');
56
+ $attribute = $this->getRequest()->getParam('attribute');
57
+ $arrayKey = $this->getRequest()->getParam('arraykey');
58
+ $conditionName = $this->getRequest()->getParam('condition');
59
+ $valueName = $this->getRequest()->getParam('value');
60
+ if($arrayKey && $id && $attribute && $conditionName && $valueName){
61
+ $rule = Mage::getModel('ddg_automation/rules')->load($id);
62
+ $conditions = $rule->getCondition();
63
+ $condition = $conditions[$arrayKey];
64
+ $selectedConditions = $condition['conditions'];
65
+ $selectedValues = $condition['cvalue'];
66
+ $type = Mage::getModel('ddg_automation/adminhtml_source_rules_type')->getInputType($attribute);
67
+ $conditionOptions = Mage::getModel('ddg_automation/adminhtml_source_rules_condition')->getInputTypeOptions($type);
68
+
69
+ $response['condition'] =
70
+ str_replace(
71
+ 'value="'.$selectedConditions.'"',
72
+ 'value="'.$selectedConditions.'"'.'selected="selected"',
73
+ $this->_getOptionHtml('conditions', $conditionName, $conditionOptions)
74
+ );
75
+
76
+ $elmType = Mage::getModel('ddg_automation/adminhtml_source_rules_value')->getValueElementType($attribute);
77
+ if($elmType == 'select' or $selectedConditions == 'null'){
78
+ $is_empty = false;
79
+ if($selectedConditions == 'null')
80
+ $is_empty = true;
81
+ $valueOptions = Mage::getModel('ddg_automation/adminhtml_source_rules_value')->getValueSelectOptions($attribute, $is_empty);
82
+ $response['cvalue'] =
83
+ str_replace(
84
+ 'value="'.$selectedValues.'"',
85
+ 'value="'.$selectedValues.'"'.'selected="selected"',
86
+ $this->_getOptionHtml('cvalue', $valueName, $valueOptions)
87
+ );
88
+ }elseif($elmType == 'text'){
89
+ $html = "<input style='width:160px' title='cvalue' class='' id='' name='$valueName' value='$selectedValues' />";
90
+ $response['cvalue'] = $html;
91
+ }
92
+ $this->getResponse()->clearHeaders()->setHeader('Content-Type', 'application/json')->setBody(Mage::helper('core')->jsonEncode($response));
93
+ }
94
+ }
95
+
96
+ /**
97
+ * ajax action for value update without selection
98
+ */
99
+ public function valueAction()
100
+ {
101
+ $valueName = $this->getRequest()->getParam('value');
102
+ $conditionValue = $this->getRequest()->getParam('condValue');;
103
+ $attributeValue = $this->getRequest()->getParam('attributeValue');
104
+
105
+ if($valueName && $attributeValue && $conditionValue){
106
+ if($conditionValue == 'null'){
107
+ $valueOptions = Mage::getModel('ddg_automation/adminhtml_source_rules_value')->getValueSelectOptions($attributeValue, true);
108
+ $response['cvalue'] = $this->_getOptionHtml('cvalue', $valueName, $valueOptions);
109
+ }
110
+ else{
111
+ $elmType = Mage::getModel('ddg_automation/adminhtml_source_rules_value')->getValueElementType($attributeValue);
112
+ if($elmType == 'select'){
113
+ $valueOptions = Mage::getModel('ddg_automation/adminhtml_source_rules_value')->getValueSelectOptions($attributeValue);
114
+ $response['cvalue'] = $this->_getOptionHtml('cvalue', $valueName, $valueOptions);
115
+ }elseif($elmType == 'text'){
116
+ $html = "<input style='width:160px' title='cvalue' class='' id='' name=$valueName />";
117
+ $response['cvalue'] = $html;
118
+ }
119
+ }
120
+ $this->getResponse()->clearHeaders()->setHeader('Content-Type', 'application/json')->setBody(Mage::helper('core')->jsonEncode($response));
121
+ }
122
+ }
123
+ }
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,210 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ <automation_rules translate="title">
19
+ <title>Exclusion Rules</title>
20
+ <sort_order>25</sort_order>
21
+ <action>adminhtml/email_rules</action>
22
+ </automation_rules>
23
+ <reports translate="title">
24
+ <title>Reports</title>
25
+ <sort_order>30</sort_order>
26
+ <children>
27
+ <email_connector_contact translate="title">
28
+ <title>Contacts Sync</title>
29
+ <sort_order>10</sort_order>
30
+ <action>adminhtml/email_contact</action>
31
+ </email_connector_contact>
32
+ <email_connector_order translate="title">
33
+ <title>Orders Sync</title>
34
+ <sort_order>20</sort_order>
35
+ <action>adminhtml/email_order</action>
36
+ </email_connector_order>
37
+ <email_connector_quote translate="title">
38
+ <title>Quote Sync</title>
39
+ <sort_order>30</sort_order>
40
+ <action>adminhtml/email_quote</action>
41
+ </email_connector_quote>
42
+ <email_connector_review translate="title">
43
+ <title>Review Sync</title>
44
+ <sort_order>40</sort_order>
45
+ <action>adminhtml/email_review</action>
46
+ </email_connector_review>
47
+ <email_connector_wishlist translate="title">
48
+ <title>Wishlist Sync</title>
49
+ <sort_order>50</sort_order>
50
+ <action>adminhtml/email_wishlist</action>
51
+ </email_connector_wishlist>
52
+ <email_connector_catalog translate="title">
53
+ <title>Catalog Sync</title>
54
+ <sort_order>60</sort_order>
55
+ <action>adminhtml/email_catalog</action>
56
+ </email_connector_catalog>
57
+ <email_connector_importer>
58
+ <title>Importer Status</title>
59
+ <sort_order>70</sort_order>
60
+ <action>adminhtml/email_importer</action>
61
+ </email_connector_importer>
62
+ <email_connector_campaign translate="title">
63
+ <title>Email Send Status</title>
64
+ <sort_order>80</sort_order>
65
+ <action>adminhtml/email_campaign</action>
66
+ </email_connector_campaign>
67
+ <email_connector_automation translate="title">
68
+ <title>Automation Status</title>
69
+ <sort_order>90</sort_order>
70
+ <action>adminhtml/email_automation</action>
71
+ </email_connector_automation>
72
+ </children>
73
+ </reports>
74
+ <email_configuration translate="title">
75
+ <title>Configuration</title>
76
+ <sort_order>40</sort_order>
77
+ <children>
78
+ <api_credentials translate="title">
79
+ <title>Api Credentials</title>
80
+ <sort_order>20</sort_order>
81
+ <action>adminhtml/system_config/edit/section/connector_api_credentials</action>
82
+ </api_credentials>
83
+ <data_mapping translate="title">
84
+ <title>Data Mapping</title>
85
+ <sort_order>30</sort_order>
86
+ <action>adminhtml/system_config/edit/section/connector_data_mapping</action>
87
+ </data_mapping>
88
+ <sync_settings translate="title">
89
+ <title>Sync Settings</title>
90
+ <sort_order>40</sort_order>
91
+ <action>adminhtml/system_config/edit/section/connector_sync_settings</action>
92
+ </sync_settings>
93
+ </children>
94
+ </email_configuration>
95
+ </children>
96
+ </email_connector>
97
+ </menu>
98
+ <acl>
99
+ <resources>
100
+ <admin>
101
+ <children>
102
+ <email_connector>
103
+ <title>DDG Automation</title>
104
+ <children>
105
+ <email_connector_dashboard translate="title">
106
+ <title>Dashboard</title>
107
+ </email_connector_dashboard>
108
+ <automation_studio translate="title">
109
+ <title>Automation Studio</title>
110
+ </automation_studio>
111
+ <automation_rules translate="title">
112
+ <title>Exclusion Rules</title>
113
+ </automation_rules>
114
+ <reports>
115
+ <title>Reports</title>
116
+ <children>
117
+ <email_connector_order translate="title">
118
+ <title>Email Connector Orders</title>
119
+ </email_connector_order>
120
+ <email_connector_campaign translate="title">
121
+ <title>Email Connector Campaigns</title>
122
+ </email_connector_campaign>
123
+ <email_connector_contact translate="title">
124
+ <title>Email Connector Contacts</title>
125
+ </email_connector_contact>
126
+ <email_connector_review translate="title">
127
+ <title>Email Connector Reviews</title>
128
+ </email_connector_review>
129
+ <email_connector_wishlist translate="title">
130
+ <title>Email Connector Wishlist</title>
131
+ </email_connector_wishlist>
132
+ <email_connector_quote translate="title">
133
+ <title>Email Connector Quote</title>
134
+ </email_connector_quote>
135
+ <email_connector_catalog translate="title">
136
+ <title>Email Connector Catalog</title>
137
+ </email_connector_catalog>
138
+ <email_connector_importer translate="title">
139
+ <title>Email Connector Importer</title>
140
+ </email_connector_importer>
141
+ <email_connector_automation translate="title">
142
+ <title>Email Automation Status</title>
143
+ </email_connector_automation>
144
+ </children>
145
+ </reports>
146
+ <email_configuration translate="title">
147
+ <title>Email Configuration</title>
148
+ <children>
149
+ <api_credentials translate="title">
150
+ <title>Api Credentials</title>
151
+ </api_credentials>
152
+ <data_mapping translate="title">
153
+ <title>Data Mapping</title>
154
+ </data_mapping>
155
+ <sync_settings translate="title">
156
+ <title>Sync Settings</title>
157
+ </sync_settings>
158
+ </children>
159
+ </email_configuration>
160
+ </children>
161
+ </email_connector>
162
+ <system>
163
+ <children>
164
+ <config>
165
+ <children>
166
+ <connector_api_credentials translate="title">
167
+ <title><![CDATA[Email API Credentials]]></title>
168
+ </connector_api_credentials>
169
+ <connector_sync_settings translate="title">
170
+ <title><![CDATA[Email Sync Settings]]></title>
171
+ </connector_sync_settings>
172
+ <connector_data_mapping translate="title">
173
+ <title><![CDATA[Email Data Field Mapping]]></title>
174
+ </connector_data_mapping>
175
+ <connector_roi_tracking translate="title">
176
+ <title><![CDATA[Email ROI & Tracking]]></title>
177
+ </connector_roi_tracking>
178
+ <connector_lost_baskets translate="title">
179
+ <title><![CDATA[Email Abandoned Carts]]></title>
180
+ </connector_lost_baskets>
181
+ <connector_reviews translate="title">
182
+ <title><![CDATA[Reviews]]></title>
183
+ </connector_reviews>
184
+ <connector_sms translate="title">
185
+ <title><![CDATA[Email SMS Section]]></title>
186
+ </connector_sms>
187
+ <connector_dynamic_content translate="title">
188
+ <title><![CDATA[Email Dynamic Content]]></title>
189
+ </connector_dynamic_content>
190
+ <connector_transactional_emails translate="title">
191
+ <title><![CDATA[Email Transactional Email]]></title>
192
+ </connector_transactional_emails>
193
+ <connector_automation_studio translate="title">
194
+ <title><![CDATA[Email Automation Studio]]></title>
195
+ </connector_automation_studio>
196
+ <connector_configuration translate="title">
197
+ <title><![CDATA[Email Configuration]]></title>
198
+ </connector_configuration>
199
+ <connector_developer_settings translate="title">
200
+ <title><![CDATA[Email Developer]]></title>
201
+ </connector_developer_settings>
202
+ </children>
203
+ </config>
204
+ </children>
205
+ </system>
206
+ </children>
207
+ </admin>
208
+ </resources>
209
+ </acl>
210
+ </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
+