dotmailermagento - Version 5.0.0

Version Notes

New Data Importer
Abandoned cart exclusion rules
Review request exclusion rules
Include product attributes in order sync
Include product custom options in order sync
Update transactional data for modified orders
Configure order status used in customer calculations
Automation Queue Enrolment
Easy Email capture on newsletter signup
Campaign stats for customers in admin
Seperate customer and guest syncs
Add to cart button for abandoned carts
Coupon code styling
Editable "view now" text for EDC pages
Nosto fallback products
Queued customer deletion
Log long API response
Catalog importer
Automation enrollment based on order status
Reset Tables button
IP restrictions on EDC pages

Download this release

Release Info

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


Code changes from version 1.5.1 to 5.0.0

Files changed (308) 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 +179 -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 +217 -0
  149. app/code/community/Dotdigitalgroup/Email/Block/Edc.php +12 -0
  150. app/code/community/Dotdigitalgroup/Email/Block/Feefo.php +101 -0
  151. app/code/community/Dotdigitalgroup/Email/Block/Order.php +87 -0
  152. app/code/community/Dotdigitalgroup/Email/Block/Order/Creditmemo.php +50 -0
  153. app/code/community/Dotdigitalgroup/Email/Block/Order/Invoice.php +45 -0
  154. app/code/community/Dotdigitalgroup/Email/Block/Order/Shipping.php +45 -0
  155. app/code/community/Dotdigitalgroup/Email/Block/Products.php +67 -0
  156. app/code/community/Dotdigitalgroup/Email/Block/Recommended/Bestsellers.php +97 -0
  157. app/code/community/Dotdigitalgroup/Email/Block/Recommended/Mostviewed.php +98 -0
  158. app/code/community/Dotdigitalgroup/Email/Block/Recommended/Products.php +194 -0
  159. app/code/community/Dotdigitalgroup/Email/Block/Recommended/Push.php +66 -0
  160. app/code/community/Dotdigitalgroup/Email/Block/Recommended/Quoteproducts.php +149 -0
  161. app/code/community/Dotdigitalgroup/Email/Block/Recommended/Recentlyviewed.php +73 -0
  162. app/code/community/Dotdigitalgroup/Email/Block/Recommended/Wishlistproducts.php +176 -0
  163. app/code/community/Dotdigitalgroup/Email/Block/System/Email/Template/Edit.php +13 -0
  164. app/code/community/Dotdigitalgroup/Email/Block/Wishlist.php +53 -0
  165. app/code/community/Dotdigitalgroup/Email/Helper/Config.php +346 -0
  166. app/code/community/Dotdigitalgroup/Email/Helper/Dashboard.php +171 -0
  167. app/code/community/Dotdigitalgroup/Email/Helper/Data.php +921 -0
  168. app/code/{local → community}/Dotdigitalgroup/Email/Helper/File.php +88 -30
  169. app/code/community/Dotdigitalgroup/Email/Helper/Recommended.php +178 -0
  170. app/code/community/Dotdigitalgroup/Email/Helper/Review.php +90 -0
  171. app/code/community/Dotdigitalgroup/Email/Model/Abstract/Rest.php +457 -0
  172. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Content.php +121 -0
  173. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Abandoned.php +59 -0
  174. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Customer.php +48 -0
  175. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Orders.php +122 -0
  176. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Rfm.php +200 -0
  177. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Subscriber.php +91 -0
  178. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Observer.php +229 -0
  179. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Addressbooks.php +46 -0
  180. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Addressbookspref.php +71 -0
  181. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Abandonedlimit.php +43 -0
  182. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Attributes.php +22 -0
  183. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Frequency.php +15 -0
  184. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Quoteattributes.php +21 -0
  185. app/code/{local/Dotdigitalgroup/Email/Model/System/Config/Source/Orderlimit.php → community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Transdata.php} +1 -1
  186. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Automation/Programme.php +39 -0
  187. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Campaigns.php +58 -0
  188. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Contact/Imported.php +17 -0
  189. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Contact/Modified.php +17 -0
  190. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Customer/Attributes/Select.php +36 -0
  191. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Datafields.php +55 -0
  192. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Datamapping/Datafieldaccess.php +17 -0
  193. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Datamapping/Datafieldtype.php +22 -0
  194. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Dynamic/Displaytype.php +18 -0
  195. app/code/{local/Dotdigitalgroup/Email/Model/System/Config/Source → community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Dynamic}/Gridview.php +6 -1
  196. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Fontpicker.php +35 -0
  197. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Fontsize.php +30 -0
  198. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Importer/Mode.php +19 -0
  199. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Importer/Status.php +19 -0
  200. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Lostbaskets/Interval.php +40 -0
  201. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Lostbaskets/Intervalminute.php +21 -0
  202. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Orderstatus.php +28 -0
  203. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Publicdatafields.php +63 -0
  204. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Reviews/Delay.php +26 -0
  205. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Rules/Condition.php +67 -0
  206. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Rules/Type.php +72 -0
  207. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Rules/Value.php +89 -0
  208. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Styling.php +18 -0
  209. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Sweettooth/Yesno.php +26 -0
  210. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Sync/Catalog/Attributes.php +28 -0
  211. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Sync/Catalog/Type.php +16 -0
  212. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Sync/Catalog/Values.php +23 -0
  213. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Sync/Catalog/Visibility.php +16 -0
  214. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Transactional/Yesno.php +26 -0
  215. app/code/community/Dotdigitalgroup/Email/Model/Api2/Subscriber/Rest/Admin/V1.php +111 -0
  216. app/code/community/Dotdigitalgroup/Email/Model/Apiconnector/Client.php +1243 -0
  217. app/code/community/Dotdigitalgroup/Email/Model/Apiconnector/Contact.php +466 -0
  218. app/code/community/Dotdigitalgroup/Email/Model/Apiconnector/Customer.php +901 -0
  219. app/code/community/Dotdigitalgroup/Email/Model/Apiconnector/Test.php +50 -0
  220. app/code/community/Dotdigitalgroup/Email/Model/Automation.php +239 -0
  221. app/code/community/Dotdigitalgroup/Email/Model/Campaign.php +144 -0
  222. app/code/community/Dotdigitalgroup/Email/Model/Catalog.php +465 -0
  223. app/code/{local → community}/Dotdigitalgroup/Email/Model/Connector/Account.php +61 -7
  224. app/code/community/Dotdigitalgroup/Email/Model/Connector/Campaign.php +100 -0
  225. app/code/community/Dotdigitalgroup/Email/Model/Connector/Datafield.php +298 -0
  226. app/code/community/Dotdigitalgroup/Email/Model/Connector/Order.php +404 -0
  227. app/code/community/Dotdigitalgroup/Email/Model/Connector/Product.php +162 -0
  228. app/code/community/Dotdigitalgroup/Email/Model/Connector/Quote.php +284 -0
  229. app/code/community/Dotdigitalgroup/Email/Model/Contact.php +321 -0
  230. app/code/community/Dotdigitalgroup/Email/Model/Controller/Observer.php +43 -0
  231. app/code/community/Dotdigitalgroup/Email/Model/Cron.php +175 -0
  232. app/code/community/Dotdigitalgroup/Email/Model/Customer.php +20 -0
  233. app/code/community/Dotdigitalgroup/Email/Model/Customer/Guest.php +71 -0
  234. app/code/community/Dotdigitalgroup/Email/Model/Customer/Observer.php +362 -0
  235. app/code/community/Dotdigitalgroup/Email/Model/Customer/Review.php +240 -0
  236. app/code/community/Dotdigitalgroup/Email/Model/Customer/Review/Rating.php +46 -0
  237. app/code/community/Dotdigitalgroup/Email/Model/Customer/Wishlist.php +120 -0
  238. app/code/{local → community}/Dotdigitalgroup/Email/Model/Customer/Wishlist/Item.php +29 -16
  239. app/code/community/Dotdigitalgroup/Email/Model/Feed.php +88 -0
  240. app/code/community/Dotdigitalgroup/Email/Model/Importer.php +270 -0
  241. app/code/community/Dotdigitalgroup/Email/Model/Newsletter/Observer.php +136 -0
  242. app/code/community/Dotdigitalgroup/Email/Model/Newsletter/Sub.php +12 -0
  243. app/code/community/Dotdigitalgroup/Email/Model/Newsletter/Subscriber.php +192 -0
  244. app/code/community/Dotdigitalgroup/Email/Model/Order.php +150 -0
  245. app/code/community/Dotdigitalgroup/Email/Model/Quote.php +225 -0
  246. app/code/community/Dotdigitalgroup/Email/Model/Resource/Automation.php +14 -0
  247. app/code/community/Dotdigitalgroup/Email/Model/Resource/Automation/Collection.php +25 -0
  248. app/code/community/Dotdigitalgroup/Email/Model/Resource/Campaign.php +13 -0
  249. app/code/community/Dotdigitalgroup/Email/Model/Resource/Campaign/Collection.php +13 -0
  250. app/code/community/Dotdigitalgroup/Email/Model/Resource/Catalog.php +13 -0
  251. app/code/community/Dotdigitalgroup/Email/Model/Resource/Catalog/Collection.php +13 -0
  252. app/code/community/Dotdigitalgroup/Email/Model/Resource/Contact.php +14 -0
  253. app/code/community/Dotdigitalgroup/Email/Model/Resource/Contact/Collection.php +25 -0
  254. app/code/community/Dotdigitalgroup/Email/Model/Resource/Importer.php +12 -0
  255. app/code/community/Dotdigitalgroup/Email/Model/Resource/Importer/Collection.php +13 -0
  256. app/code/community/Dotdigitalgroup/Email/Model/Resource/Order.php +12 -0
  257. app/code/community/Dotdigitalgroup/Email/Model/Resource/Order/Collection.php +18 -0
  258. app/code/community/Dotdigitalgroup/Email/Model/Resource/Quote.php +12 -0
  259. app/code/community/Dotdigitalgroup/Email/Model/Resource/Quote/Collection.php +14 -0
  260. app/code/community/Dotdigitalgroup/Email/Model/Resource/Review.php +13 -0
  261. app/code/community/Dotdigitalgroup/Email/Model/Resource/Review/Collection.php +13 -0
  262. app/code/community/Dotdigitalgroup/Email/Model/Resource/Rules.php +13 -0
  263. app/code/community/Dotdigitalgroup/Email/Model/Resource/Rules/Collection.php +13 -0
  264. app/code/community/Dotdigitalgroup/Email/Model/Resource/Segment.php +154 -0
  265. app/code/community/Dotdigitalgroup/Email/Model/Resource/Setup.php +26 -0
  266. app/code/community/Dotdigitalgroup/Email/Model/Resource/Wishlist.php +13 -0
  267. app/code/community/Dotdigitalgroup/Email/Model/Resource/Wishlist/Collection.php +13 -0
  268. app/code/community/Dotdigitalgroup/Email/Model/Review.php +176 -0
  269. app/code/community/Dotdigitalgroup/Email/Model/Rules.php +440 -0
  270. app/code/community/Dotdigitalgroup/Email/Model/Sales/Observer.php +319 -0
  271. app/code/community/Dotdigitalgroup/Email/Model/Sales/Order.php +408 -0
  272. app/code/community/Dotdigitalgroup/Email/Model/Sales/Quote.php +306 -0
  273. app/code/community/Dotdigitalgroup/Email/Model/Sms/Campaign.php +112 -0
  274. app/code/community/Dotdigitalgroup/Email/Model/Sweettooth/Observer.php +21 -0
  275. app/code/community/Dotdigitalgroup/Email/Model/Wishlist.php +251 -0
  276. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/ConnectorController.php +438 -0
  277. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/CustomerController.php +10 -0
  278. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/AutomationController.php +97 -0
  279. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/CampaignController.php +252 -0
  280. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/CatalogController.php +26 -0
  281. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/ContactController.php +192 -0
  282. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/DashboardController.php +90 -0
  283. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/ImporterController.php +76 -0
  284. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/OrderController.php +26 -0
  285. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/QuoteController.php +26 -0
  286. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/ReviewController.php +26 -0
  287. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/RulesController.php +207 -0
  288. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/StudioController.php +111 -0
  289. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/WishlistController.php +26 -0
  290. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/System/Email/TemplateController.php +36 -0
  291. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Widget/ChooserController.php +19 -0
  292. app/code/community/Dotdigitalgroup/Email/controllers/AjaxController.php +21 -0
  293. app/code/community/Dotdigitalgroup/Email/controllers/CreditmemoController.php +70 -0
  294. app/code/community/Dotdigitalgroup/Email/controllers/Customer/AccountController.php +27 -0
  295. app/code/community/Dotdigitalgroup/Email/controllers/Customer/NewsletterController.php +129 -0
  296. app/code/community/Dotdigitalgroup/Email/controllers/DynamicContentController.php +39 -0
  297. app/code/community/Dotdigitalgroup/Email/controllers/EmailController.php +258 -0
  298. app/code/community/Dotdigitalgroup/Email/controllers/FeefoController.php +63 -0
  299. app/code/community/Dotdigitalgroup/Email/controllers/InvoiceController.php +75 -0
  300. app/code/community/Dotdigitalgroup/Email/controllers/OrderController.php +75 -0
  301. app/code/community/Dotdigitalgroup/Email/controllers/ProductsController.php +122 -0
  302. app/code/community/Dotdigitalgroup/Email/controllers/QuoteproductsController.php +96 -0
  303. app/code/community/Dotdigitalgroup/Email/controllers/ReportController.php +70 -0
  304. app/code/community/Dotdigitalgroup/Email/controllers/ResponseController.php +50 -0
  305. app/code/community/Dotdigitalgroup/Email/controllers/RulesController.php +123 -0
  306. app/code/community/Dotdigitalgroup/Email/controllers/ShippingController.php +88 -0
  307. app/code/community/Dotdigitalgroup/Email/controllers/WishlistController.php +50 -0
  308. app/code/community/Dotdigitalgroup/Email/etc/adminhtml.xml +111 -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,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $this->getMassactionBlock()->addItem('re-create', array('label'=>Mage::helper('ddg')->__('Recreate'),'url'=>$this->getUrl('*/*/massRecreate')));
150
+ return $this;
151
+ }
152
+
153
+ /**
154
+ * Grid selected url.
155
+ * @return string
156
+ */
157
+ public function getGridUrl()
158
+ {
159
+ return $this->getUrl('*/*/grid', array('_current'=>true));
160
+ }
161
+ /**
162
+ * Custom callback action for the campaign.
163
+ *
164
+ * @param $collection
165
+ * @param $column
166
+ */
167
+ public function filterCallbackContact($collection, $column)
168
+ {
169
+ $field = $column->getFilterIndex() ? $column->getFilterIndex() : $column->getIndex();
170
+ $value = $column->getFilter()->getValue();
171
+
172
+ if ($value == 'null') {
173
+ $collection->addFieldToFilter($field, array('null' => true) );
174
+ } else {
175
+ $collection->addFieldToFilter($field, array('notnull' => true));
176
+ }
177
+ }
178
+
179
+ }
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_automation/disconnect') : $url;
25
+
26
+ return $this->getLayout()->createBlock('adminhtml/widget_button')
27
+ ->setType('button')
28
+ ->setLabel($this->__($title))
29
+ ->setDisabled($disabled)
30
+ ->setOnClick("window.location.href='" . $url . "'")
31
+ ->toHtml();
32
+ }
33
+
34
+ private function _checkForSecureUrl() {
35
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB, true);
36
+ if (!preg_match('/https/',$baseUrl)) {
37
+ return false;
38
+ }
39
+ return $this;
40
+ }
41
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Addressbook.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Addressbook extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+
6
+ /**
7
+ * Ajax Create the addressbooks.
8
+ * @param Varien_Data_Form_Element_Abstract $element
9
+ *
10
+ * @return string
11
+ */
12
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
13
+ {
14
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/createnewaddressbook');
15
+ $website = Mage::app()->getRequest()->getParam('website', 0);
16
+
17
+ $element->setData('after_element_html',
18
+ "<script>
19
+ function createAddressbook(form, element) {
20
+ var name = $('connector_sync_settings_dynamic_addressbook_addressbook_name').value;
21
+ var visibility = $('connector_sync_settings_dynamic_addressbook_visibility').value;
22
+ var reloadurl = '{$url}';
23
+ if(name && visibility){
24
+ new Ajax.Request(reloadurl, {
25
+ method: 'post',
26
+ parameters: {'name' : name, 'visibility' : visibility, 'website': '$website'},
27
+ onComplete: function(transport) {
28
+ window.location.reload();
29
+ }
30
+ });
31
+ }
32
+ return false;
33
+ }
34
+ </script>"
35
+ );
36
+
37
+ return parent::_getElementHtml($element);
38
+ }
39
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Colorpicker.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Colorpicker extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ /**
6
+ * Generate HTML code for color picker
7
+ *
8
+ * @param Varien_Data_Form_Element_Abstract $element
9
+ * @return string
10
+ */
11
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
12
+ {
13
+ // Include Procolor library JS file
14
+ $html = '<script type="text/javascript" src="' . Mage::getBaseUrl('js') . 'connector/procolor-1.0/procolor.compressed.js' .'"></script>';
15
+
16
+ // Use Varien text element as a basis
17
+ $input = new Varien_Data_Form_Element_Text();
18
+
19
+ // Set data from config element on Varien text element
20
+ $input->setForm($element->getForm())
21
+ ->setElement($element)
22
+ ->setValue($element->getValue())
23
+ ->setHtmlId($element->getHtmlId())
24
+ ->setName($element->getName())
25
+ ->setStyle('width: 60px') // Update style in order to shrink width
26
+ ->addClass('validate-hex'); // Add some Prototype validation to make sure color code is correct
27
+
28
+ // Inject updated Varien text element HTML in our current HTML
29
+ $html .= $input->getHtml();
30
+
31
+ // Inject Procolor JS code to display color picker
32
+ $html .= $this->_getProcolorJs($element->getHtmlId());
33
+
34
+ // Inject Prototype validation
35
+ $html .= $this->_addHexValidator();
36
+
37
+ return $html;
38
+ }
39
+
40
+ /**
41
+ * Procolor JS code to display color picker
42
+ *
43
+ * @see http://procolor.sourceforge.net/examples.php
44
+ * @param string $htmlId
45
+ * @return string
46
+ */
47
+ protected function _getProcolorJs($htmlId)
48
+ {
49
+ return '<script type="text/javascript">ProColor.prototype.attachButton(\'' . $htmlId . '\', { imgPath:\'' . Mage::getBaseUrl('js') . 'connector/procolor-1.0/' . 'img/procolor_win_\', showInField: true });</script>';
50
+ }
51
+
52
+ /**
53
+ * Prototype validation
54
+ *
55
+ * @return string
56
+ */
57
+ protected function _addHexValidator()
58
+ {
59
+ return
60
+ '<script type="text/javascript">
61
+ Validation.add(\'validate-hex\', \'' . Mage::helper('ddg')->__('Please enter a valid hex color code') . '\', function(v) {
62
+ return /^#(?:[0-9a-fA-F]{3}){1,2}$/.test(v);
63
+ });
64
+ </script>';
65
+ }
66
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Datafield.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Datafield extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+
6
+ /**
7
+ * Ajax Create the datafields.
8
+ * @param Varien_Data_Form_Element_Abstract $element
9
+ *
10
+ * @return string
11
+ */
12
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
13
+ {
14
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/createnewdatafield');
15
+ $website = Mage::app()->getRequest()->getParam('website', 0);
16
+
17
+ $element->setData('after_element_html',
18
+ "<script>
19
+ function createDatafield(form, element) {
20
+ var datafield_name = $('connector_data_mapping_dynamic_datafield_datafield_name').value;
21
+ var datafield_type = $('connector_data_mapping_dynamic_datafield_datafield_type').value;
22
+ var datafield_default = $('connector_data_mapping_dynamic_datafield_datafield_default').value;
23
+ var datafield_access = $('connector_data_mapping_dynamic_datafield_datafield_access').value;
24
+
25
+ var reloadurl = '{$url}';
26
+
27
+ if(datafield_name && datafield_type && datafield_access){
28
+ new Ajax.Request(reloadurl, {
29
+ method: 'post',
30
+ parameters: {'name' : datafield_name, 'type' : datafield_type, 'default' : datafield_default, 'access' : datafield_access, 'website': '$website'},
31
+ onComplete: function(transport) {
32
+ window.location.reload();
33
+ }
34
+ });
35
+ }
36
+ return false;}</script>"
37
+ );
38
+
39
+ return parent::_getElementHtml($element);
40
+ }
41
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Enterprisevalidator.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Enterprisevalidator extends Mage_Adminhtml_Block_System_Config_Form_Field
5
+ {
6
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
7
+ {
8
+ // Get the default HTML for this option
9
+ $html = parent::_getElementHtml($element);
10
+
11
+ // Set up additional JavaScript for our validation using jQuery.
12
+
13
+ $jquery = '<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>';
14
+
15
+ if (! Mage::helper('ddg')->isEnterprise()) {
16
+ $html .=$jquery;
17
+ $javaScript = "<script type=\"text/javascript\">
18
+ jQuery.noConflict();
19
+ jQuery(document).ready(function() {
20
+ jQuery('#connector_data_mapping_enterprise_data-head').parent().hide();
21
+
22
+ });
23
+ </script>";
24
+ $html .= $javaScript;
25
+ }
26
+
27
+
28
+ return $html;
29
+ }
30
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Resetcontacts.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Resetcontacts extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ public function _getElementHtml(Varien_Data_Form_Element_Abstract$element){
6
+
7
+ $element->setData('onchange', "resetContacts();");
8
+ //url to reset the contacs
9
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/resetcontactsajax');
10
+
11
+ $element->setData('after_element_html', "
12
+ <script>
13
+ function resetContacts(){
14
+ new Ajax.Request('{$url}', {
15
+ method: 'get',
16
+ onComplete: function(transport) {
17
+ }
18
+ });
19
+ return false;
20
+ }
21
+ </script>
22
+ ");
23
+
24
+ return parent::_getElementHtml($element);
25
+
26
+
27
+ }
28
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Resetguests.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Resetguests extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ public function _getElementHtml(Varien_Data_Form_Element_Abstract$element){
6
+
7
+ $element->setData('onchange', "resetGuests();");
8
+ //url to reset the guests
9
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/ajaxresetguests');
10
+
11
+ $element->setData('after_element_html', "
12
+ <script>
13
+ function resetGuests(){
14
+ new Ajax.Request('{$url}', {
15
+ method: 'get',
16
+ onComplete: function(transport) {
17
+ }
18
+ });
19
+ return false;
20
+ }
21
+ </script>
22
+ ");
23
+
24
+ return parent::_getElementHtml($element);
25
+
26
+
27
+ }
28
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Resetsubscribers.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Resetsubscribers extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ public function _getElementHtml(Varien_Data_Form_Element_Abstract$element){
6
+
7
+ $element->setData('onchange', "resetSubscribers();");
8
+ //url to reset the subscribers
9
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/ajaxresetsubscribers');
10
+
11
+ $element->setData('after_element_html', "
12
+ <script>
13
+ function resetSubscribers(){
14
+ new Ajax.Request('{$url}', {
15
+ method: 'get',
16
+ onComplete: function(transport) {
17
+ }
18
+ });
19
+ return false;
20
+ }
21
+ </script>
22
+ ");
23
+
24
+ return parent::_getElementHtml($element);
25
+
26
+
27
+ }
28
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Smtpvalidator.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Smtpvalidator extends Mage_Adminhtml_Block_System_Config_Form_Field
5
+ {
6
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
7
+ {
8
+ // Get the default HTML for this option
9
+ $html = parent::_getElementHtml($element);
10
+
11
+ // Set up additional JavaScript for our validation using jQuery.
12
+
13
+ $jquery = '<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>';
14
+
15
+ $html .=$jquery;
16
+ $javaScript = "<script type=\"text/javascript\"> var show_warning = 0;";
17
+
18
+ if(!Mage::helper('ddg')->isSmtpEnabled()){
19
+ $javaScript .= "show_warning = 1;";
20
+ }
21
+
22
+ $javaScript .=
23
+ "jQuery.noConflict();
24
+
25
+ jQuery(document).ready(function() {
26
+ // Handler for .ready() called.
27
+
28
+ //Show sweet tooth notice
29
+ if(show_warning == 1) jQuery('#smtp-warning').show();
30
+ });
31
+ </script>";
32
+
33
+ $html .= $javaScript;
34
+ return $html;
35
+ }
36
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Validator.php ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Validator extends Mage_Adminhtml_Block_System_Config_Form_Field
5
+ {
6
+
7
+ /**
8
+ * Ajax Validate the duplicate selection.
9
+ * @param Varien_Data_Form_Element_Abstract $element
10
+ *
11
+ * @return string
12
+ */
13
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
14
+ {
15
+ // Get the default HTML for this option
16
+ $html = parent::_getElementHtml($element);
17
+
18
+ // Set up additional JavaScript for our validation using jQuery.
19
+
20
+ $jquery = '<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>';
21
+
22
+ $html .=$jquery;
23
+ $javaScript = "<script type=\"text/javascript\"> var show_warning = 0;";
24
+
25
+ if(!Mage::helper('ddg')->isSweetToothEnabled()){
26
+ $javaScript .= "show_warning = 1;";
27
+ }
28
+
29
+ $javaScript .=
30
+ "jQuery.noConflict();
31
+
32
+ jQuery(document).ready(function() {
33
+ // Handler for .ready() called.
34
+
35
+ //Show sweet tooth notice
36
+ if(show_warning == 1) jQuery('#sweet-tooth-warning').show();
37
+
38
+ // Hide our validation block
39
+ jQuery('#row_connector_data_mapping_customer_data_validator').hide();
40
+
41
+ // Add listener for changing select box
42
+
43
+ jQuery('#connector_data_mapping_customer_data select').on('change', function() {
44
+ var currentSelection = jQuery(this).val();
45
+ var currentDropdownId = jQuery(this).attr('id');
46
+ check(currentSelection, currentDropdownId);
47
+ });
48
+
49
+ jQuery('#connector_data_mapping_sweet_tooth select').on('change', function() {
50
+ var currentSelection = jQuery(this).val();
51
+ var currentDropdownId = jQuery(this).attr('id');
52
+ check(currentSelection, currentDropdownId);
53
+ });
54
+
55
+ function check(currentSelection, currentDropdownId){
56
+ // foreach of the select fields on our mapping page:
57
+ jQuery('select').each(function(){
58
+ var thisId = jQuery(this).attr('id');
59
+ if (thisId != currentDropdownId) {
60
+
61
+ var currentLabel = jQuery('label[for=\\'' + thisId + '\\']').text();
62
+ var thisVal = jQuery(this).val();
63
+
64
+ switch (thisVal) {
65
+ case '0':
66
+ // ignore DO NOT MAP fields
67
+ break;
68
+ case currentSelection:
69
+ // warning, that field is already mapped somewhere else - reset that value to 'Do not map''
70
+ alert('Warning! You have overwritten: '+currentLabel);
71
+ jQuery(this).val(0);
72
+ break;
73
+ default:
74
+ break;
75
+ break;
76
+ }
77
+ }
78
+ });
79
+ }
80
+ });
81
+ </script>";
82
+
83
+ $html .= $javaScript;
84
+ return $html;
85
+ }
86
+
87
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Waitingfield.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Waitingfield extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ /**
6
+ * Unscope the website level.
7
+ * @param Varien_Data_Form_Element_Abstract $element
8
+ *
9
+ * @return string
10
+ */
11
+ public function render(Varien_Data_Form_Element_Abstract $element)
12
+ {
13
+
14
+ $element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
15
+ return parent::render($element);
16
+
17
+ }
18
+
19
+ /**
20
+ * Loading background on save.
21
+ * @param Varien_Data_Form_Element_Abstract $element
22
+ *
23
+ * @return string
24
+ */
25
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
26
+ {
27
+ // Get the default HTML for this option
28
+ $html = parent::_getElementHtml($element);
29
+
30
+
31
+ $html .= sprintf('<div id="loadingmask" style="position: fixed;">
32
+ <div class="loader" id="loading-mask-loader">
33
+ <img src="%sskin/adminhtml/default/default/images/ajax-loader-tr.gif" alt="%s"/>%s', preg_replace('/index.php\//', '', $this->getBaseUrl()), $this->__('Loading...'), $this->__('Loading...'))
34
+ . '<div id="loading-mask"></div></div>';
35
+
36
+ $jQuery = '<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>';
37
+
38
+ $jQuery .=
39
+ '<script type="text/javascript">
40
+ jQuery.noConflict();
41
+ jQuery(document).ready(function() {
42
+ //hide the load image field
43
+ jQuery("#row_connector_api_credentials_api_credentials_validator").hide();
44
+ jQuery("#row_connector_sync_settings_sync_customer_schedule_validator").hide();
45
+ var loadingmask = jQuery("#loadingmask");
46
+ loadingmask.hide();
47
+ loadingmask.css({top : "50\%", left: "50\%"});
48
+ //var thisButton = jQuery("button");
49
+ //console.log(thisButton);
50
+ //jQuery("button").click(function(){
51
+ // jQuery("body").css({"background-color": "black", "opacity": "0.4"});
52
+ // jQuery("#row_connector_api_settings_api_credentials_validator").show();
53
+ // jQuery("#row_connector_sync_settings_sync_customer_schedule_validator").show();
54
+ // loadingmask.show();
55
+ // loadingmask.css({"display": "block", "opacity" : "1"});
56
+ //})
57
+ });
58
+ </script>';
59
+
60
+ $html .= $jQuery;
61
+
62
+ return $html;
63
+ }
64
+
65
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Wrapper.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Wrapper extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+
6
+ /**
7
+ * Ajax Validate the api credentials.
8
+ *
9
+ * @param Varien_Data_Form_Element_Abstract $element
10
+ *
11
+ * @return string
12
+ */
13
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
14
+ {
15
+ $element->setData('onchange', "apiValidation(this.form, this);");
16
+
17
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/ajaxvalidation');
18
+
19
+ $element->setData('after_element_html', "
20
+ <script>
21
+ document.observe('dom:loaded', function(){
22
+ apiValidation();
23
+ });
24
+ function apiValidation(form, element) {
25
+ var api_username = $('connector_api_credentials_api_username');
26
+ var api_password = $('connector_api_credentials_api_password');
27
+ var reloadurl = '{$url}';
28
+ var encoded = btoa(api_password.value);
29
+ if(api_username.value && api_password.value){
30
+ new Ajax.Request(reloadurl, {
31
+ method: 'post',
32
+ parameters: {'api_username' : api_username.value, 'api_password' : encoded},
33
+ onComplete: function(transport) {
34
+ Element.hide('loadingmask');
35
+ if(transport.responseText == '\"Credentials Valid.\"'){
36
+ api_username.setStyle({
37
+ fontWeight: 'bold',
38
+ color: 'green' ,
39
+ background: 'transparent url(\"" . $this->getSkinUrl('images/success_msg_icon.gif') . "\") no-repeat right center'
40
+ })
41
+ }else{
42
+ api_username.setStyle({
43
+ fontWeight: 'bold',
44
+ color: 'red',
45
+ background: 'transparent url(\"" . $this->getSkinUrl('images/error_msg_icon.gif') . "\") no-repeat right center'
46
+ });
47
+ }
48
+ }
49
+ });
50
+ }
51
+ return false;
52
+ }
53
+ </script>
54
+ ");
55
+
56
+ return parent::_getElementHtml($element);
57
+
58
+ }
59
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Addressbookbutton.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Addressbookbutton extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+
6
+ protected function _getAddRowButtonHtml($title)
7
+ {
8
+ return $this->getLayout()->createBlock('adminhtml/widget_button')
9
+ ->setType('button')
10
+ ->setLabel($this->__($title))
11
+ ->setOnClick("createAddressbook(this.form, this);")
12
+ ->toHtml();
13
+ }
14
+
15
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
16
+ {
17
+ $this->setElement($element);
18
+ $originalData = $element->getOriginalData();
19
+
20
+ return $this->_getAddRowButtonHtml($this->__($originalData['button_label']));
21
+ }
22
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Basket/Crosssell.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Basket_Crosssell extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
6
+ {
7
+ //base url
8
+ $baseUrl = Mage::helper('ddg')->generateDynamicUrl();
9
+ //config passcode
10
+ $passcode = Mage::helper('ddg')->getPasscode();
11
+ //last quote id for dynamic page
12
+ $lastQuoteId = Mage::helper('ddg')->getLastQuoteId();
13
+
14
+ if (!strlen($passcode))
15
+ $passcode = '[PLEASE SET UP A PASSCODE]';
16
+ //alert message for last order id is not mapped
17
+ if (!$lastQuoteId)
18
+ $lastQuoteId = '[PLEASE MAP THE LAST QUOTE ID]';
19
+
20
+ //full url for dynamic content
21
+ $text = sprintf('%sconnector/quoteproducts/crosssell/code/%s/quote_id/@%s@', $baseUrl, $passcode, $lastQuoteId);
22
+ $element->setData('value', $text);
23
+
24
+ return parent::_getElementHtml($element);
25
+ }
26
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Basket/Related.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Basket_Related extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
6
+ {
7
+ //passcode to append for url
8
+ $passcode = Mage::helper('ddg')->getPasscode();
9
+ //last quote id for dynamic page
10
+ $lastQuoteId = Mage::helper('ddg')->getLastQuoteId();
11
+
12
+ if (!strlen($passcode))
13
+ $passcode = '[PLEASE SET UP A PASSCODE]';
14
+ //alert message for last order id is not mapped
15
+ if (!$lastQuoteId)
16
+ $lastQuoteId = '[PLEASE MAP THE LAST QUOTE ID]';
17
+
18
+ //generate the base url and display for default store id
19
+ $baseUrl = Mage::helper('ddg')->generateDynamicUrl();
20
+
21
+ //display the full url
22
+ $text = sprintf('%sconnector/quoteproducts/related/code/%s/quote_id/@%s@', $baseUrl, $passcode, $lastQuoteId);
23
+ $element->setData('value', $text);
24
+
25
+ return parent::_getElementHtml($element);
26
+ }
27
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Basket/Upsell.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Basket_Upsell extends Mage_Adminhtml_Block_System_Config_Form_Field
3
+ {
4
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
5
+ {
6
+ //passcode to append for url
7
+ $passcode = Mage::helper('ddg')->getPasscode();
8
+ //last quote id for dynamic page
9
+ $lastQuoteId = Mage::helper('ddg')->getLastQuoteId();
10
+
11
+ if (!strlen($passcode))
12
+ $passcode = '[PLEASE SET UP A PASSCODE]';
13
+ //alert message for last order id is not mapped
14
+ if (!$lastQuoteId)
15
+ $lastQuoteId = '[PLEASE MAP THE LAST QUOTE ID]';
16
+
17
+ //generate the base url and display for default store id
18
+ $baseUrl = Mage::helper('ddg')->generateDynamicUrl();
19
+
20
+ $text = sprintf('%sconnector/quoteproducts/upsell/code/%s/quote_id/@%s@', $baseUrl, $passcode, $lastQuoteId);
21
+ $element->setData('value', $text);
22
+
23
+ return parent::_getElementHtml($element);
24
+ }
25
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Bestsellers.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Bestsellers extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ /** label */
6
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) {
7
+
8
+ //base url
9
+ $baseUrl = Mage::helper('ddg')->generateDynamicUrl();
10
+
11
+ //config passcode
12
+ $passcode = Mage::helper('ddg')->getPasscode();
13
+
14
+ if (!strlen($passcode))
15
+ $passcode = '[PLEASE SET UP A PASSCODE]';
16
+
17
+ //full url
18
+ $text = sprintf('%sconnector/report/bestsellers/code/%s', $baseUrl, $passcode);
19
+ $element->setData('value', $text);
20
+ $element->setData('disabled', 'disabled');
21
+
22
+ return parent::_getElementHtml($element);
23
+ }
24
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Couponinfo.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Couponinfo extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ /** label */
6
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
7
+ {
8
+ //base url
9
+ $baseUrl = Mage::helper('ddg')->generateDynamicUrl();
10
+
11
+
12
+ //config code
13
+ $code = Mage::helper('ddg')->getPasscode();
14
+
15
+ if (!strlen($code))
16
+ $code = '[PLEASE SET UP A PASSCODE]';
17
+
18
+ //full url
19
+ $text = $baseUrl . 'connector/email/coupon/id/[INSERT ID HERE]/code/'. $code . '/@EMAIL@';
20
+
21
+ $element->setData('value', $text);
22
+ $element->setData('disabled', 'disabled');
23
+ return parent::_getElementHtml($element);
24
+ }
25
+
26
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Creditmemonew.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Creditmemonew extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) {
6
+
7
+ //base url
8
+ $baseUrl = Mage::helper('ddg')->generateDynamicUrl();
9
+
10
+ //config code
11
+ $code = Mage::helper('ddg')->getPasscode();
12
+ $orderId = Mage::helper('ddg')->getMappedOrderId();
13
+
14
+ //message to set up the passcode
15
+ if (!strlen($code))
16
+ $code = '[PLEASE SET UP A PASSCODE]';
17
+ //full url for dynamic content
18
+ $text = sprintf('%s/connector/creditmemo/new/code/%s/id/@%s@', $baseUrl, $code, $orderId);
19
+
20
+ $element->setData('value', $text);
21
+
22
+ return parent::_getElementHtml($element);
23
+ }
24
+
25
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Crosssell.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Crosssell extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
6
+ {
7
+ //base url
8
+ $baseUrl = Mage::helper('ddg')->generateDynamicUrl();
9
+ //config passcode
10
+ $passcode = Mage::helper('ddg')->getPasscode();
11
+ //last order id for dynamic page
12
+ $lastOrderId = Mage::helper('ddg')->getLastOrderId();
13
+
14
+ if (!strlen($passcode))
15
+ $passcode = '[PLEASE SET UP A PASSCODE]';
16
+ //alert message for last order id is not mapped
17
+ if (!$lastOrderId)
18
+ $lastOrderId = '[PLEASE MAP THE LAST ORDER ID]';
19
+
20
+ //full url for dynamic content
21
+ $text = sprintf('%sconnector/products/crosssell/code/%s/order_id/@%s@', $baseUrl, $passcode, $lastOrderId);
22
+ $element->setData('value', $text);
23
+
24
+ return parent::_getElementHtml($element);
25
+ }
26
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Datafieldbutton.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Datafieldbutton extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ protected function _getAddRowButtonHtml($title)
6
+ {
7
+ return $this->getLayout()->createBlock('adminhtml/widget_button')
8
+ ->setType('button')
9
+ ->setLabel($this->__($title))
10
+ ->setOnClick("createDatafield(this.form, this);")
11
+ ->toHtml();
12
+ }
13
+
14
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
15
+ {
16
+ $this->setElement($element);
17
+ $originalData = $element->getOriginalData();
18
+
19
+ return $this->_getAddRowButtonHtml($this->__($originalData['button_label']));
20
+ }
21
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Fallbackchooser.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Fallbackchooser extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+
6
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
7
+ {
8
+ $this->setElement($element);
9
+ return $this->_getAddRowButtonHtml($this->__("Choose Products"));
10
+ }
11
+
12
+ protected function _getAddRowButtonHtml($title)
13
+ {
14
+ $action = 'getFallbackProductChooser(\'' . Mage::getUrl(
15
+ '*/widget_chooser/product/form/fallback_product_selector',
16
+ array('_secure' => Mage::app()->getStore()->isAdminUrlSecure())
17
+ ) . '?isAjax=true\'); return false;';
18
+
19
+ return $this->getLayout()->createBlock('adminhtml/widget_button')
20
+ ->setType('button')
21
+ ->setLabel($this->__($title))
22
+ ->setOnClick($action)
23
+ ->toHtml();
24
+ }
25
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Fallbackcontainer.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Fallbackcontainer extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+
6
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
7
+ {
8
+ $this->setElement($element);
9
+ return
10
+ "<script type='text/javascript'>
11
+ var fallback_product_selector = new ConnectorProductSelectorForm('connector_dynamic_content_fallback_products_product_list');
12
+ //ajax call and handler
13
+ getFallbackProductChooser = function (url) {
14
+ new Ajax.Request(
15
+ url, {
16
+ method: 'post',
17
+ onSuccess: function (b) {
18
+ var a = $('connector-fallback-product-chooser-container');
19
+ a.update(b.responseText);
20
+ a.scrollTo()
21
+ }
22
+ })
23
+ };
24
+ </script>
25
+ <div id = 'connector-fallback-product-chooser-container'></div>";
26
+ }
27
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Feefo/Reviews.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Feefo_Reviews extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
6
+ {
7
+ //passcode to append for url
8
+ $passcode = Mage::helper('ddg')->getPasscode();
9
+
10
+ if(!strlen($passcode))
11
+ $passcode = '[PLEASE SET UP A PASSCODE]';
12
+
13
+ //generate the base url and display for default store id
14
+ $baseUrl = Mage::helper('ddg')->generateDynamicUrl();
15
+
16
+ //display the full url
17
+ $text = sprintf('%sconnector/feefo/reviews/code/%s/quote_id/@QUOTE_ID@', $baseUrl, $passcode);
18
+ $element->setData('value', $text);
19
+
20
+ return parent::_getElementHtml($element);
21
+ }
22
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Feefo/Score.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Feefo_Score extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
6
+ {
7
+ //passcode to append for url
8
+ $passcode = Mage::helper('ddg')->getPasscode();
9
+
10
+ if(!strlen($passcode))
11
+ $passcode = '[PLEASE SET UP A PASSCODE]';
12
+
13
+ //generate the base url and display for default store id
14
+ $baseUrl = Mage::helper('ddg')->generateDynamicUrl();
15
+
16
+ //display the full url
17
+ $text = sprintf('%sconnector/feefo/score/code/%s', $baseUrl, $passcode);
18
+ $element->setData('value', $text);
19
+
20
+ return parent::_getElementHtml($element);
21
+ }
22
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Gridlist.php ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Gridlist extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ /**
6
+ * Dynamic contaent dysplay type.
7
+ *
8
+ * @param Varien_Data_Form_Element_Abstract $element
9
+ *
10
+ * @return string
11
+ */
12
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
13
+ {
14
+ // Get the default HTML for this option
15
+ $html = parent::_getElementHtml($element);
16
+
17
+
18
+ $jQuery = '<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>';
19
+
20
+ $jQuery .=
21
+ '<script type="text/javascript">
22
+ jQuery.noConflict();
23
+ jQuery(document).ready(function() {
24
+ var gridOptions = {
25
+ "4" : "4",
26
+ "8" : "8",
27
+ "12" : "12",
28
+ "16" : "16",
29
+ "20" : "20",
30
+ "24" : "24",
31
+ "28" : "28",
32
+ "32" : "32"
33
+
34
+ };
35
+ var listOptions = {
36
+ "2" : "2",
37
+ "4" : "4",
38
+ "6" : "6",
39
+ "8" : "8"
40
+ }
41
+
42
+ jQuery("#connector_dynamic_content_products_related_display_type").change(function(){
43
+ var display_type = jQuery(this).closest("tr").next().find("select");
44
+ var display_mode = jQuery(this).val();
45
+ changeOptions(display_type, display_mode);
46
+ });
47
+
48
+ jQuery("#connector_dynamic_content_products_upsell_display_type").change(function(){
49
+ var display_type = jQuery(this).closest("tr").next().find("select");
50
+ var display_mode = jQuery(this).val();
51
+ changeOptions(display_type, display_mode);
52
+
53
+ });
54
+ jQuery("#connector_dynamic_content_products_crosssell_display_type").change(function(){
55
+ var display_type = jQuery(this).closest("tr").next().find("select");
56
+ var display_mode = jQuery(this).val();
57
+ changeOptions(display_type, display_mode);
58
+ });
59
+ jQuery("#connector_dynamic_content_products_bestsellers_display_type").change(function(){
60
+ var display_type = jQuery(this).closest("tr").next().find("select");
61
+ var display_mode = jQuery(this).val();
62
+ changeOptions(display_type, display_mode);
63
+ });
64
+ jQuery("#connector_dynamic_content_products_most_viewed_display_type").change(function(){
65
+ var display_type = jQuery(this).closest("tr").next().find("select");
66
+ var display_mode = jQuery(this).val();
67
+ changeOptions(display_type, display_mode);
68
+ });
69
+ jQuery("#connector_dynamic_content_products_recently_viewed_display_type").change(function(){
70
+ var display_type = jQuery(this).closest("tr").next().find("select");
71
+ var display_mode = jQuery(this).val();
72
+ changeOptions(display_type, display_mode);
73
+ });
74
+ jQuery("#connector_dynamic_content_manual_product_search_display_type").change(function(){
75
+ var display_type = jQuery(this).closest("tr").next().find("select");
76
+ var display_mode = jQuery(this).val();
77
+ changeOptions(display_type, display_mode);
78
+ });
79
+ function changeOptions(display_type, display_mode){
80
+ if(display_mode == "list"){
81
+ display_type.empty();
82
+
83
+ jQuery.each(listOptions, function(key, value) {
84
+ display_type.append(jQuery("<option></option>")
85
+ .attr("value", value).text(key));
86
+ });
87
+
88
+ }
89
+ if(display_mode == "grid"){
90
+ display_type.empty();
91
+ jQuery.each(gridOptions, function(key, value) {
92
+ display_type.append(jQuery("<option></option>")
93
+ .attr("value", value).text(key));
94
+ });
95
+ }
96
+ }
97
+ });
98
+ </script>';
99
+
100
+ $html .= $jQuery;
101
+
102
+ return $html;
103
+ }
104
+
105
+
106
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Lostbasket.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Lostbasket extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+
6
+ /** label */
7
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
8
+ {
9
+ //base url for dynamic content
10
+ $baseUrl = Mage::helper('ddg')->generateDynamicUrl();
11
+ $passcode = Mage::helper('ddg')->getPasscode();
12
+
13
+ //last quote id for dynamic page
14
+ $lastQuoteId = Mage::helper('ddg')->getLastQuoteId();
15
+
16
+ //config passcode
17
+ if(!strlen($passcode))
18
+ $passcode = '[PLEASE SET UP A PASSCODE]';
19
+ //alert message for last order id is not mapped
20
+ if (!$lastQuoteId)
21
+ $lastQuoteId = '[PLEASE MAP THE LAST QUOTE ID]';
22
+
23
+ // full url
24
+
25
+ $text = sprintf("%sconnector/email/basket/code/%s/quote_id/@%s@", $baseUrl, $passcode, $lastQuoteId);
26
+
27
+ $element->setData('value', $text);
28
+ return parent::_getElementHtml($element);
29
+ }
30
+
31
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Manualchooser.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Manualchooser extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+
6
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
7
+ {
8
+ $this->setElement($element);
9
+ return $this->_getAddRowButtonHtml($this->__("Choose Products"));
10
+ }
11
+
12
+ protected function _getAddRowButtonHtml($title)
13
+ {
14
+ $action = 'getManualProductChooser(\'' . Mage::getUrl(
15
+ '*/widget_chooser/product/form/manual_product_selector',
16
+ array('_secure' => Mage::app()->getStore()->isAdminUrlSecure())
17
+ ) . '?isAjax=true\'); return false;';
18
+
19
+ return $this->getLayout()->createBlock('adminhtml/widget_button')
20
+ ->setType('button')
21
+ ->setLabel($this->__($title))
22
+ ->setOnClick($action)
23
+ ->toHtml();
24
+ }
25
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Manualcontainer.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Manualcontainer extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+
6
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
7
+ {
8
+ $this->setElement($element);
9
+ return
10
+ "<script type='text/javascript'>
11
+ var manual_product_selector = new ConnectorProductSelectorForm('connector_dynamic_content_manual_product_search_products_push_items');
12
+ //ajax call and handler
13
+ getManualProductChooser = function (url) {
14
+ new Ajax.Request(
15
+ url, {
16
+ method: 'post',
17
+ onSuccess: function (b) {
18
+ var a = $('connector-product-chooser-container');
19
+ a.update(b.responseText);
20
+ a.scrollTo()
21
+ }
22
+ })
23
+ };
24
+ </script>
25
+ <div id = 'connector-product-chooser-container'></div>";
26
+ }
27
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Mostviewed.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Mostviewed extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ /** label */
6
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
7
+ {
8
+ //base url for dynamic content
9
+ $baseUrl = Mage::helper('ddg')->generateDynamicUrl();
10
+ $passcode = Mage::helper('ddg')->getPasscode();
11
+
12
+ if (!strlen($passcode))
13
+ $passcode = '[PLEASE SET UP A PASSCODE]';
14
+
15
+ //full url for dynamic content
16
+ $text = sprintf('%sconnector/report/mostviewed/code/%s', $baseUrl, $passcode);
17
+ $element->setData('value', $text);
18
+
19
+ return parent::_getElementHtml($element);
20
+ }
21
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Nosto.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Nosto extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
6
+ {
7
+ //passcode to append for url
8
+ $passcode = Mage::helper('ddg')->getPasscode();
9
+
10
+ if(!strlen($passcode))
11
+ $passcode = '[PLEASE SET UP A PASSCODE]';
12
+
13
+ //generate the base url and display for default store id
14
+ $baseUrl = Mage::helper('ddg')->generateDynamicUrl();
15
+
16
+ //display the full url
17
+ $text = sprintf('%sconnector/products/nosto/code/%s/slot/@SLOT_NAME@/email/@EMAIL@', $baseUrl, $passcode);
18
+ $element->setData('value', $text);
19
+
20
+ return parent::_getElementHtml($element);
21
+ }
22
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Productpush.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Productpush extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ /** label */
6
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
7
+ {
8
+ //generate base url
9
+ $baseUrl = Mage::helper('ddg')->generateDynamicUrl();
10
+ $passcode = Mage::helper('ddg')->getPasscode();
11
+
12
+ if (!strlen($passcode))
13
+ $passcode = '[PLEASE SET UP A PASSCODE]';
14
+
15
+ //full url for dynamic content
16
+ $text = sprintf('%sconnector/products/push/code/%s', $baseUrl, $passcode);
17
+ $element->setData('value', $text);
18
+
19
+ return parent::_getElementHtml($element);
20
+ }
21
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Recentlyviewed.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Recentlyviewed extends Mage_Adminhtml_Block_System_Config_Form_Field
3
+ {
4
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
5
+ {
6
+ //generate base url for dynamic content
7
+ $baseUrl = Mage::helper('ddg')->generateDynamicUrl();
8
+
9
+ //config passcode
10
+ $passcode = Mage::helper('ddg')->getPasscode();
11
+ $customerId = Mage::helper('ddg')->getMappedCustomerId();
12
+
13
+ if (!strlen($passcode))
14
+ $passcode = '[PLEASE SET UP A PASSCODE]';
15
+ if (!$customerId)
16
+ $customerId = '[PLEASE MAP THE CUSTOMER ID]';
17
+ //dynamic content url
18
+ $text = sprintf('%sconnector/report/recentlyviewed/code/%s/customer_id/@%s@', $baseUrl, $passcode, $customerId);
19
+ $element->setData('value', $text);
20
+
21
+ return parent::_getElementHtml($element);
22
+
23
+ }
24
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Related.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Related extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
6
+ {
7
+ //passcode to append for url
8
+ $passcode = Mage::helper('ddg')->getPasscode();
9
+ //last order id witch information will be generated
10
+ $lastOrderId = Mage::helper('ddg')->getLastOrderId();
11
+
12
+ if(!strlen($passcode))
13
+ $passcode = '[PLEASE SET UP A PASSCODE]';
14
+ if(!$lastOrderId)
15
+ $lastOrderId = '[PLEASE MAP THE LAST ORDER ID]';
16
+
17
+ //generate the base url and display for default store id
18
+ $baseUrl = Mage::helper('ddg')->generateDynamicUrl();
19
+
20
+ //display the full url
21
+ $text = sprintf('%sconnector/products/related/code/%s/order_id/@%s@', $baseUrl, $passcode, $lastOrderId);
22
+ $element->setData('value', $text);
23
+
24
+ return parent::_getElementHtml($element);
25
+ }
26
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Review.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Review extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+
6
+ /** label */
7
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
8
+ {
9
+ //passcode to append for url
10
+ $passcode = Mage::helper('ddg')->getPasscode();
11
+ //last order id witch information will be generated
12
+ $lastOrderId = Mage::helper('ddg')->getLastOrderId();
13
+
14
+ if(!strlen($passcode))
15
+ $passcode = '[PLEASE SET UP A PASSCODE]';
16
+ if(!$lastOrderId)
17
+ $lastOrderId = '[PLEASE MAP THE LAST ORDER ID]';
18
+
19
+ //generate the base url and display for default store id
20
+ $baseUrl = Mage::helper('ddg')->generateDynamicUrl();
21
+
22
+ //display the full url
23
+ $text = sprintf('%sconnector/email/review/code/%s/order_id/@%s@', $baseUrl, $passcode, $lastOrderId);
24
+ $element->setData('value', $text);
25
+
26
+ return parent::_getElementHtml($element);
27
+ }
28
+
29
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Upsell.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Upsell extends Mage_Adminhtml_Block_System_Config_Form_Field
3
+ {
4
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
5
+ {
6
+ //passcode to append for url
7
+ $passcode = Mage::helper('ddg')->getPasscode();
8
+ //last order id witch information will be generated
9
+ $lastOrderid = Mage::helper('ddg')->getLastOrderId();
10
+
11
+ if(!strlen($passcode))
12
+ $passcode = '[PLEASE SET UP A PASSCODE]';
13
+ if(!$lastOrderid)
14
+ $lastOrderid = '[PLEASE MAP THE LAST ORDER ID]';
15
+
16
+ //generate the base url and display for default store id
17
+ $baseUrl = Mage::helper('ddg')->generateDynamicUrl();
18
+
19
+ $text = sprintf('%sconnector/products/upsell/code/%s/order_id/@%s@', $baseUrl, $passcode, $lastOrderid);
20
+ $element->setData('value', $text);
21
+
22
+ return parent::_getElementHtml($element);
23
+ }
24
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Wishlist.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Wishlist extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ /**
6
+ * label
7
+ *
8
+ * @param Varien_Data_Form_Element_Abstract $element
9
+ * @return string
10
+ */
11
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
12
+ {
13
+ //passcode to append for url
14
+ $passcode = Mage::helper('ddg')->getPasscode();
15
+ //last order id witch information will be generated
16
+ $customerId = Mage::helper('ddg')->getMappedCustomerId();
17
+
18
+ if(!strlen($passcode))
19
+ $passcode = '[PLEASE SET UP A PASSCODE]';
20
+ if(!$customerId)
21
+ $customerId = '[PLEASE MAP THE CUSTOMER ID]';
22
+
23
+ //generate the base url and display for default store id
24
+ $baseUrl = Mage::helper('ddg')->generateDynamicUrl();
25
+
26
+ //display the full url
27
+ $text = sprintf('%sconnector/email/wishlist/code/%s/customer_id/@%s@', $baseUrl, $passcode, $customerId);
28
+ $element->setData('value', $text);
29
+
30
+ return parent::_getElementHtml($element);
31
+ }
32
+
33
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Wishlist/Crosssell.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Wishlist_Crosssell extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ /**
6
+ * label
7
+ *
8
+ * @param Varien_Data_Form_Element_Abstract $element
9
+ * @return string
10
+ */
11
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
12
+ {
13
+ //passcode to append for url
14
+ $passcode = Mage::helper('ddg')->getPasscode();
15
+ //last order id witch information will be generated
16
+ $customerId = Mage::helper('ddg')->getMappedCustomerId();
17
+
18
+ if(!strlen($passcode))
19
+ $passcode = '[PLEASE SET UP A PASSCODE]';
20
+ if(!$customerId)
21
+ $customerId = '[PLEASE MAP THE CUSTOMER ID]';
22
+
23
+ //generate the base url and display for default store id
24
+ $baseUrl = Mage::helper('ddg')->generateDynamicUrl();
25
+
26
+ //display the full url
27
+ $text = sprintf('%sconnector/wishlist/crosssell/code/%s/customer_id/@%s@', $baseUrl, $passcode, $customerId);
28
+ $element->setData('value', $text);
29
+
30
+ return parent::_getElementHtml($element);
31
+ }
32
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Wishlist/Related.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Wishlist_Related extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ /**
6
+ * label
7
+ *
8
+ * @param Varien_Data_Form_Element_Abstract $element
9
+ * @return string
10
+ */
11
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
12
+ {
13
+ //passcode to append for url
14
+ $passcode = Mage::helper('ddg')->getPasscode();
15
+ //last order id witch information will be generated
16
+ $customerId = Mage::helper('ddg')->getMappedCustomerId();
17
+
18
+ if(!strlen($passcode))
19
+ $passcode = '[PLEASE SET UP A PASSCODE]';
20
+ if(!$customerId)
21
+ $customerId = '[PLEASE MAP THE CUSTOMER ID]';
22
+
23
+ //generate the base url and display for default store id
24
+ $baseUrl = Mage::helper('ddg')->generateDynamicUrl();
25
+
26
+ //display the full url
27
+ $text = sprintf('%sconnector/wishlist/related/code/%s/customer_id/@%s@', $baseUrl, $passcode, $customerId);
28
+ $element->setData('value', $text);
29
+
30
+ return parent::_getElementHtml($element);
31
+ }
32
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Wishlist/Upsell.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Dynamic_Wishlist_Upsell extends Mage_Adminhtml_Block_System_Config_Form_Field
3
+ {
4
+ /**
5
+ * label
6
+ *
7
+ * @param Varien_Data_Form_Element_Abstract $element
8
+ * @return string
9
+ */
10
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
11
+ {
12
+ //passcode to append for url
13
+ $passcode = Mage::helper('ddg')->getPasscode();
14
+ //last order id witch information will be generated
15
+ $customerId = Mage::helper('ddg')->getMappedCustomerId();
16
+
17
+ if(!strlen($passcode))
18
+ $passcode = '[PLEASE SET UP A PASSCODE]';
19
+ if(!$customerId)
20
+ $customerId = '[PLEASE MAP THE CUSTOMER ID]';
21
+
22
+ //generate the base url and display for default store id
23
+ $baseUrl = Mage::helper('ddg')->generateDynamicUrl();
24
+
25
+ //display the full url
26
+ $text = sprintf('%sconnector/wishlist/upsell/code/%s/customer_id/@%s@', $baseUrl, $passcode, $customerId);
27
+ $element->setData('value', $text);
28
+
29
+ return parent::_getElementHtml($element);
30
+ }
31
+ }
app/code/{local/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Wrapper.php → community/Dotdigitalgroup/Email/Block/Adminhtml/System/Emailapivalidate.php} RENAMED
@@ -1,12 +1,14 @@
1
  <?php
2
 
3
- class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Wrapper extends Mage_Adminhtml_Block_System_Config_Form_Field
4
  {
5
 
6
  protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
7
  {
8
  $element->setData('onchange', "apiValidation(this.form, this);");
9
 
 
 
10
  $element->setData('after_element_html', "
11
  <script>
12
  document.observe('dom:loaded', function(){
@@ -14,17 +16,16 @@ class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Wrapper extends Mage_A
14
 
15
  });
16
  function apiValidation(form, element) {
17
- var api_user = $('connector_api_settings_api_credentials_username');
18
- var api_password = $('connector_api_settings_api_credentials_password');
19
-
20
- var reloadurl = '{$this->getUrl('connector/debug/ajaxvalidation')}';
21
-
22
  new Ajax.Request(reloadurl, {
23
  method: 'post',
24
- parameters: {'api_user' : api_user.value, 'api_password' : api_password.value},
25
  onComplete: function(transport) {
26
  Element.hide('loadingmask');
27
- if(transport.responseText == '\"Valid\"'){
28
  api_user.setStyle({
29
  fontWeight: 'bold',
30
  color: 'green' ,
1
  <?php
2
 
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Emailapivalidate extends Mage_Adminhtml_Block_System_Config_Form_Field
4
  {
5
 
6
  protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
7
  {
8
  $element->setData('onchange', "apiValidation(this.form, this);");
9
 
10
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/ajaxvalidation');
11
+
12
  $element->setData('after_element_html', "
13
  <script>
14
  document.observe('dom:loaded', function(){
16
 
17
  });
18
  function apiValidation(form, element) {
19
+ var api_user = $('connector_transactional_emails_credentials_api_username');
20
+ var api_password = $('connector_transactional_emails_credentials_api_password');
21
+ var reloadurl = '{$url}';
22
+ var encoded = btoa(api_password.value);
 
23
  new Ajax.Request(reloadurl, {
24
  method: 'post',
25
+ parameters: {'api_username' : api_user.value, 'api_password' : encoded},
26
  onComplete: function(transport) {
27
  Element.hide('loadingmask');
28
+ if(transport.responseText == '\"Credentials Valid.\"'){
29
  api_user.setStyle({
30
  fontWeight: 'bold',
31
  color: 'green' ,
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/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,217 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Customer_Account_Books extends Mage_Customer_Block_Account_Dashboard
4
+ {
5
+ private $_client;
6
+ private $contact_id;
7
+
8
+ /**
9
+ * subscription pref save url
10
+ *
11
+ * @return string
12
+ */
13
+ public function getSaveUrl()
14
+ {
15
+ return $this->getUrl('connector/customer_newsletter/save');
16
+ }
17
+
18
+ /**
19
+ * get config values
20
+ *
21
+ * @param $path
22
+ * @param $website
23
+ * @return mixed
24
+ */
25
+ private function _getWebsiteConfigFromHelper($path, $website)
26
+ {
27
+ return Mage::helper('ddg')->getWebsiteConfig($path, $website);
28
+ }
29
+
30
+ /**
31
+ * get api client
32
+ *
33
+ * @return Dotdigitalgroup_Email_Model_Apiconnector_Client
34
+ */
35
+ private function _getApiClient()
36
+ {
37
+ if(empty($this->_client)) {
38
+ $website = $this->getCustomer()->getStore()->getWebsite();
39
+ $client = Mage::getModel('ddg_automation/apiconnector_client');
40
+ $client->setApiUsername(Mage::helper('ddg')->getApiUsername($website))
41
+ ->setApiPassword(Mage::helper('ddg')->getApiPassword($website));
42
+ $this->_client = $client;
43
+ }
44
+ return $this->_client;
45
+ }
46
+
47
+ /**
48
+ * can show additional books?
49
+ *
50
+ * @return mixed
51
+ */
52
+ public function getCanShowAdditionalBooks()
53
+ {
54
+ return $this->_getWebsiteConfigFromHelper(
55
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_ADDRESSBOOK_PREF_CAN_CHANGE_BOOKS,
56
+ $this->getCustomer()->getStore()->getWebsite()
57
+ );
58
+ }
59
+
60
+ /**
61
+ * getter for additional books. Fully processed.
62
+ *
63
+ * @return array
64
+ */
65
+ public function getAdditionalBooksToShow()
66
+ {
67
+ $additionalBooksToShow = array();
68
+ $additionalFromConfig = $this->_getWebsiteConfigFromHelper(
69
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_ADDRESSBOOK_PREF_SHOW_BOOKS,
70
+ $this->getCustomer()->getStore()->getWebsite()
71
+ );
72
+
73
+ if(strlen($additionalFromConfig))
74
+ {
75
+ $additionalFromConfig = explode(',', $additionalFromConfig);
76
+ $this->getConnectorContact();
77
+ if($this->contact_id){
78
+ $addressBooks = $this->_getApiClient()->getContactAddressBooks($this->contact_id);
79
+ $processedAddressBooks = array();
80
+ if(is_array($addressBooks)){
81
+ foreach($addressBooks as $addressBook){
82
+ $processedAddressBooks[$addressBook->id] = $addressBook->name;
83
+ }
84
+ }
85
+ foreach($additionalFromConfig as $bookId){
86
+ $connectorBook = $this->_getApiClient()->getAddressBookById($bookId);
87
+ if(isset($connectorBook->id))
88
+ {
89
+ $subscribed = 0;
90
+ if(isset($processedAddressBooks[$bookId]))
91
+ $subscribed = 1;
92
+ $additionalBooksToShow[] = array(
93
+ "name" => $connectorBook->name,
94
+ "value" => $connectorBook->id,
95
+ "subscribed" => $subscribed
96
+ );
97
+ }
98
+ }
99
+ }
100
+ }
101
+ return $additionalBooksToShow;
102
+ }
103
+
104
+ /**
105
+ * can show data fields?
106
+ *
107
+ * @return mixed
108
+ */
109
+ public function getCanShowDataFields()
110
+ {
111
+ return $this->_getWebsiteConfigFromHelper(
112
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_ADDRESSBOOK_PREF_CAN_SHOW_FIELDS,
113
+ $this->getCustomer()->getStore()->getWebsite()
114
+ );
115
+ }
116
+
117
+ /**
118
+ * getter for data fields to show. Fully processed.
119
+ *
120
+ * @return array
121
+ */
122
+ public function getDataFieldsToShow()
123
+ {
124
+ $datafieldsToShow = array();
125
+ $dataFieldsFromConfig = $this->_getWebsiteConfigFromHelper(
126
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_ADDRESSBOOK_PREF_SHOW_FIELDS,
127
+ $this->getCustomer()->getStore()->getWebsite()
128
+ );
129
+ if(strlen($dataFieldsFromConfig))
130
+ {
131
+ $dataFieldsFromConfig = explode(',', $dataFieldsFromConfig);
132
+ $contact = $this->getConnectorContact();
133
+ if($this->contact_id)
134
+ {
135
+ $contactDataFields = $contact->dataFields;
136
+ $processedContactDataFields = array();
137
+ foreach($contactDataFields as $contactDataField){
138
+ $processedContactDataFields[$contactDataField->key] = $contactDataField->value;
139
+ }
140
+
141
+ $connectorDataFields = $this->_getApiClient()->getDataFields();
142
+ $processedConnectorDataFields = array();
143
+ foreach($connectorDataFields as $connectorDataField){
144
+ $processedConnectorDataFields[$connectorDataField->name] = $connectorDataField;
145
+ }
146
+ foreach($dataFieldsFromConfig as $dataFieldFromConfig){
147
+ if(isset($processedConnectorDataFields[$dataFieldFromConfig])){
148
+ $value = "";
149
+ $type = "";
150
+ if(isset($processedContactDataFields[$processedConnectorDataFields[$dataFieldFromConfig]->name])){
151
+ if($processedConnectorDataFields[$dataFieldFromConfig]->type == "Date"){
152
+ $type = "Date";
153
+ $value = $processedContactDataFields[$processedConnectorDataFields[$dataFieldFromConfig]->name];
154
+ $value = Mage::app()->getLocale()->date($value)->toString("Y/M/d");
155
+ }
156
+ else
157
+ $value = $processedContactDataFields[$processedConnectorDataFields[$dataFieldFromConfig]->name];
158
+ }
159
+
160
+ $datafieldsToShow[] = array(
161
+ 'name' => $processedConnectorDataFields[$dataFieldFromConfig]->name,
162
+ 'type' => $processedConnectorDataFields[$dataFieldFromConfig]->type,
163
+ 'value' => $value
164
+ );
165
+ }
166
+ }
167
+
168
+ }
169
+ }
170
+ return $datafieldsToShow;
171
+ }
172
+
173
+ /**
174
+ * find out if anything is true
175
+ *
176
+ * @return bool
177
+ */
178
+ public function canShowAnything()
179
+ {
180
+ if($this->getCanShowDataFields() or $this->getCanShowAdditionalBooks()){
181
+ $books = $this->getAdditionalBooksToShow();
182
+ $fields = $this->getDataFieldsToShow();
183
+ if(!empty($books) or !empty($fields))
184
+ return true;
185
+ }
186
+ return false;
187
+ }
188
+
189
+ /**
190
+ * get connector contact
191
+ *
192
+ * @return mixed
193
+ */
194
+ public function getConnectorContact()
195
+ {
196
+ $contact = $this->_getApiClient()->getContactByEmail($this->getCustomer()->getEmail());
197
+ if($contact->id){
198
+ $this->contact_id = $contact->id;
199
+ }else{
200
+ $contact = $this->_getApiClient()->postContacts($this->getCustomer()->getEmail());
201
+ if($contact->id){
202
+ $this->contact_id = $contact->id;
203
+ }
204
+ }
205
+ return $contact;
206
+ }
207
+
208
+ /**
209
+ * getter for contact id
210
+ *
211
+ * @return mixed
212
+ */
213
+ public function getConnectorContactId()
214
+ {
215
+ return $this->contact_id;
216
+ }
217
+ }
app/code/community/Dotdigitalgroup/Email/Block/Edc.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Edc extends Mage_Core_Block_Template
4
+ {
5
+ public function getTextForUrl($store)
6
+ {
7
+ $store = Mage::app()->getStore($store);
8
+ return $store->getConfig(
9
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DYNAMIC_CONTENT_LINK_TEXT
10
+ );
11
+ }
12
+ }
app/code/community/Dotdigitalgroup/Email/Block/Feefo.php ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ const FEEFO_URL = 'http://www.feefo.com/feefo/xmlfeed.jsp?';
4
+
5
+ class Dotdigitalgroup_Email_Block_Feefo extends Mage_Core_Block_Template
6
+ {
7
+ /**
8
+ * Prepare layout, set the template.
9
+ * @return Mage_Core_Block_Abstract|void
10
+ */
11
+ protected function _prepareLayout()
12
+ {
13
+ if ($root = $this->getLayout()->getBlock('root')) {
14
+ $root->setTemplate('page/blank.phtml');
15
+ }
16
+ }
17
+
18
+ /**
19
+ * get customer's service score logo and output it
20
+ *
21
+ * @return string
22
+ */
23
+ public function getServiceScoreLogo()
24
+ {
25
+ $helper = Mage::helper('ddg');
26
+ $url = 'http://www.feefo.com/feefo/feefologo.jsp?logon=';
27
+ $logon = $helper->getFeefoLogon();
28
+ $template = '';
29
+ if($helper->getFeefoLogoTemplate())
30
+ $template = '&template=' . $helper->getFeefoLogoTemplate();
31
+ $fullUrl = $url . $logon . $template;
32
+ $vendorUrl = 'http://www.feefo.com/feefo/viewvendor.jsp?logon=' . $logon;
33
+
34
+ return
35
+ "<a href=$vendorUrl target='_blank'>
36
+ <img alt='Feefo logo' border='0' src=$fullUrl title='See what our customers say about us'>
37
+ </a>";
38
+ }
39
+
40
+ /**
41
+ * get quote products to show feefo reviews
42
+ *
43
+ * @return array
44
+ */
45
+ public function getQuoteProducts()
46
+ {
47
+ $products = array();
48
+ $quoteId = Mage::app()->getRequest()->getParam('quote_id');
49
+ $quoteModel = Mage::getModel('sales/quote')->load($quoteId);
50
+ if(!$quoteModel->getId())
51
+ die;
52
+
53
+ $quoteItems = $quoteModel->getAllItems();
54
+
55
+ if(count($quoteItems) == 0)
56
+ return array();
57
+
58
+ foreach($quoteItems as $item)
59
+ {
60
+ $productId = $item->getProductId();
61
+ $productModel = Mage::getModel('catalog/product')->load($productId);
62
+ if ($productModel->getId())
63
+ $products[$productModel->getSku()] = $productModel->getName();
64
+ }
65
+ return $products;
66
+ }
67
+
68
+ /**
69
+ * get product reviews from feefo
70
+ *
71
+ * @return array
72
+ */
73
+ public function getProductsReview()
74
+ {
75
+ $check = true;
76
+ $reviews = array();
77
+ $feefo_dir = Mage::getModel('core/config_options')->getLibDir().DS.'connector'.DS.'feefo';
78
+ $helper = Mage::helper('ddg');
79
+ $logon = $helper->getFeefoLogon();
80
+ $limit = $helper->getFeefoReviewsPerProduct();
81
+ $products = $this->getQuoteProducts();
82
+
83
+ foreach($products as $sku => $name)
84
+ {
85
+ $url = "http://www.feefo.com/feefo/xmlfeed.jsp?logon=" . $logon . "&limit=".$limit . "&vendorref=" . $sku . "&mode=productonly" ;
86
+ $doc = new DOMDocument();
87
+ $xsl = new XSLTProcessor();
88
+ if($check)
89
+ $doc->load($feefo_dir. DS ."feedback.xsl");
90
+ else
91
+ $doc->load($feefo_dir. DS ."feedback-no-th.xsl");
92
+ $xsl->importStyleSheet($doc);
93
+ $doc->load($url);
94
+ $productReview = $xsl->transformToXML($doc);
95
+ if(strpos($productReview, '<td'))
96
+ $reviews[$name] = $xsl->transformToXML($doc);
97
+ $check = false;
98
+ }
99
+ return $reviews;
100
+ }
101
+ }
app/code/community/Dotdigitalgroup/Email/Block/Order.php ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Order extends 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
+ $orderId = Mage::registry('order_id');
29
+ $order = Mage::registry('current_order');
30
+ if (! $orderId) {
31
+ $orderId = Mage::app()->getRequest()->getParam('order_id');
32
+ if(!$orderId)
33
+ return false;
34
+ Mage::unregister('order_id'); // additional measure
35
+ Mage::register('order_id', $orderId);
36
+ }
37
+ if (! $order) {
38
+ if(!$orderId)
39
+ return false;
40
+ $order = Mage::getModel('sales/order')->load($orderId);
41
+ Mage::unregister('current_order'); // additional measure
42
+ Mage::register('current_order', $order);
43
+ }
44
+
45
+ return $order;
46
+ }
47
+
48
+ /**
49
+ * Filter items for review. If a customer has already placed a review for a product then exclude the product.
50
+ *
51
+ * @param array $items
52
+ * @param int $websiteId
53
+ * @return mixed
54
+ */
55
+ public function filterItemsForReview($items, $websiteId)
56
+ {
57
+ if (!count($items))
58
+ return;
59
+
60
+ $order = $this->getOrder();
61
+
62
+ //if customer is guest then no need to filter any items
63
+ if($order->getCustomerIsGuest())
64
+ return $items;
65
+
66
+ if(!Mage::helper('ddg/review')->isNewProductOnly($websiteId))
67
+ return $items;
68
+
69
+ $customerId = $order->getCustomerId();
70
+
71
+ foreach($items as $key => $item)
72
+ {
73
+ $productId = $item->getProduct()->getId();
74
+
75
+ $collection = Mage::getModel('review/review')->getCollection();
76
+ $collection->addCustomerFilter($customerId)
77
+ ->addStoreFilter($order->getStoreId())
78
+ ->addFieldToFilter('main_table.entity_pk_value', $productId);
79
+
80
+ //remove item if customer has already placed review on this item
81
+ if($collection->getSize())
82
+ unset($items[$key]);
83
+ }
84
+
85
+ return $items;
86
+ }
87
+ }
app/code/community/Dotdigitalgroup/Email/Block/Order/Creditmemo.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Block_Order_Creditmemo extends Mage_Sales_Block_Order_Creditmemo_Items
3
+ {
4
+ /**
5
+ * Prepare layout.
6
+ *
7
+ * @return Mage_Core_Block_Abstract|void
8
+ */
9
+ protected function _prepareLayout()
10
+ {
11
+ if ($root = $this->getLayout()->getBlock('root')) {
12
+ $root->setTemplate('page/blank.phtml');
13
+ }
14
+ }
15
+
16
+ /**
17
+ * Get current Order.
18
+ * @return Mage_Sales_Model_Order
19
+ * @throws Exception
20
+ */
21
+ public function getOrder()
22
+ {
23
+ $orderId = Mage::registry('order_id');
24
+ $order = Mage::registry('current_order');
25
+ if (! $orderId) {
26
+ $orderId = Mage::app()->getRequest()->getParam('order_id');
27
+ Mage::register('order_id', $orderId);
28
+ }
29
+ if (! $order) {
30
+ $order = Mage::getModel('sales/order')->load($orderId);
31
+ Mage::register('current_order', $order);
32
+ }
33
+ if (! $order->hasCreditmemos()) {
34
+ //throw new Exception('TE - no creditmemo for order : '. $orderId);
35
+ Mage::helper('ddg')->log('TE - no creditmemo for order : '. $orderId);
36
+ return false;
37
+ }
38
+
39
+ return $order;
40
+ }
41
+
42
+ /**
43
+ * Order items.
44
+ * @return mixed
45
+ */
46
+ public function getCreditmemoItems()
47
+ {
48
+ return Mage::registry('current_order')->getItemsCollection();
49
+ }
50
+ }
app/code/community/Dotdigitalgroup/Email/Block/Order/Invoice.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Block_Order_Invoice extends Mage_Sales_Block_Order_Invoice_Items
3
+ {
4
+ /**
5
+ * Prepare layout.
6
+ * @return Mage_Core_Block_Abstract|void
7
+ */
8
+ protected function _prepareLayout()
9
+ {
10
+ if ($root = $this->getLayout()->getBlock('root')) {
11
+ $root->setTemplate('page/blank.phtml');
12
+ }
13
+ }
14
+
15
+ /**
16
+ * Get current order.
17
+ * @return Mage_Sales_Model_Order
18
+ * @throws Exception
19
+ */
20
+ public function getOrder()
21
+ {
22
+ $orderId = Mage::registry('order_id');
23
+ $order = Mage::registry('current_order');
24
+ if (! $orderId) {
25
+ $orderId = Mage::app()->getRequest()->getParam('order_id');
26
+ if(!$orderId)
27
+ return false;
28
+ Mage::register('order_id', $orderId);
29
+ }
30
+ if (! $order) {
31
+ if(!$orderId)
32
+ return false;
33
+ $order = Mage::getModel('sales/order')->load($orderId);
34
+ Mage::register('current_order', $order);
35
+ }
36
+ if (! $order->hasInvoices()) {
37
+ //throw new Exception('TE - no invoice for order : '. $orderId);
38
+ Mage::helper('ddg')->log('TE - no invoice for order : '. $orderId);
39
+ return false;
40
+ }
41
+
42
+ return $order;
43
+ }
44
+
45
+ }
app/code/community/Dotdigitalgroup/Email/Block/Order/Shipping.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Block_Order_Shipping extends Mage_Sales_Block_Order_Creditmemo_Items
3
+ {
4
+ /**
5
+ * Prepare layout.
6
+ * @return Mage_Core_Block_Abstract|void
7
+ */
8
+ protected function _prepareLayout()
9
+ {
10
+ if ($root = $this->getLayout()->getBlock('root')) {
11
+ $root->setTemplate('page/blank.phtml');
12
+ }
13
+ }
14
+
15
+ /**
16
+ * @return Mage_Sales_Model_Order
17
+ * @throws Exception
18
+ */
19
+ public function getOrder()
20
+ {
21
+ $orderId = Mage::registry('order_id');
22
+ $order = Mage::registry('current_order');
23
+ if (! $orderId) {
24
+ $orderId = Mage::app()->getRequest()->getParam('order_id');
25
+ if(!$orderId)
26
+ return false;
27
+ Mage::register('order_id', $orderId);
28
+ }
29
+ if (! $order) {
30
+ if(!$orderId)
31
+ return false;
32
+ $order = Mage::getModel('sales/order')->load($orderId);
33
+ Mage::register('current_order', $order);
34
+ }
35
+ if (! $order->hasShipments()) {
36
+ //throw new Exception('TE - no shipments for order : '. $orderId);
37
+ Mage::helper('ddg')->log('TE - no shipments for order : '. $orderId);
38
+ return false;
39
+ }
40
+
41
+ return $order;
42
+
43
+ }
44
+
45
+ }
app/code/community/Dotdigitalgroup/Email/Block/Products.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Products extends Mage_Core_Block_Template
4
+ {
5
+ /**
6
+ * Prepare layout, set template.
7
+ *
8
+ * @return Mage_Core_Block_Abstract|void
9
+ */
10
+ protected function _prepareLayout()
11
+ {
12
+ if ($root = $this->getLayout()->getBlock('root')) {
13
+ $root->setTemplate('page/blank.phtml');
14
+ }
15
+ }
16
+
17
+ /**
18
+ * get the products to display for table
19
+ */
20
+ public function getRecommendedProducts()
21
+ {
22
+ $productsToDisplay = array();
23
+ $orderId = $this->getRequest()->getParam('order', false);
24
+ $mode = $this->getRequest()->getParam('mode', false);
25
+ if ($orderId && $mode) {
26
+ $orderModel = Mage::getModel('sales/order')->load($orderId);
27
+ if ($orderModel->getId()) {
28
+ $storeId = $orderModel->getStoreId();
29
+ $appEmulation = Mage::getSingleton('core/app_emulation');
30
+ $appEmulation->startEnvironmentEmulation($storeId);
31
+ //order products
32
+ $productRecommended = Mage::getModel('ddg_automation/dynamic_recommended', $orderModel);
33
+ $productRecommended->setMode($mode);
34
+
35
+ //get the order items recommendations
36
+ $productsToDisplay = $productRecommended->getProducts();
37
+ }
38
+ }
39
+
40
+ return $productsToDisplay;
41
+ }
42
+
43
+
44
+ /**
45
+ * Price html block.
46
+ *
47
+ * @param $product
48
+ *
49
+ * @return string
50
+ */
51
+ public function getPriceHtml($product)
52
+ {
53
+ $this->setTemplate('connector/price.phtml');
54
+ $this->setProduct($product);
55
+ return $this->toHtml();
56
+ }
57
+
58
+ /**
59
+ * Display type mode.
60
+ * @return mixed|string
61
+ */
62
+ public function getDisplayType()
63
+ {
64
+ return Mage::helper('ddg/recommended')->getDisplayType();
65
+
66
+ }
67
+ }
app/code/community/Dotdigitalgroup/Email/Block/Recommended/Bestsellers.php ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Recommended_Bestsellers extends Dotdigitalgroup_Email_Block_Edc
4
+ {
5
+
6
+ /**
7
+ * Prepare layout.
8
+ * @return Mage_Core_Block_Abstract|void
9
+ */
10
+ protected function _prepareLayout()
11
+ {
12
+ if ($root = $this->getLayout()->getBlock('root')) {
13
+ $root->setTemplate('page/blank.phtml');
14
+ }
15
+ }
16
+
17
+ /**
18
+ * Get product collection.
19
+ * @return array
20
+ * @throws Exception
21
+ */
22
+ public function getLoadedProductCollection()
23
+ {
24
+ $mode = $this->getRequest()->getActionName();
25
+ $limit = Mage::helper('ddg/recommended')->getDisplayLimitByMode($mode);
26
+ $from = Mage::helper('ddg/recommended')->getTimeFromConfig($mode);
27
+ $locale = Mage::app()->getLocale()->getLocale();
28
+ $to = Zend_Date::now($locale)->toString(Zend_Date::ISO_8601);
29
+
30
+ $productCollection = Mage::getResourceModel('reports/product_collection')
31
+ ->addAttributeToSelect('*')
32
+ ->addOrderedQty($from, $to)
33
+ ->setOrder('ordered_qty', 'desc')
34
+ ->setPageSize($limit);
35
+
36
+ Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($productCollection);
37
+ $productCollection->addAttributeToFilter('is_saleable', TRUE);
38
+
39
+ //filter collection by category by category_id
40
+ if($cat_id = Mage::app()->getRequest()->getParam('category_id')){
41
+ $category = Mage::getModel('catalog/category')->load($cat_id);
42
+ if($category->getId()){
43
+ $productCollection->getSelect()
44
+ ->joinLeft(
45
+ array("ccpi" => 'catalog_category_product_index'),
46
+ "e.entity_id = ccpi.product_id",
47
+ array("category_id")
48
+ )
49
+ ->where('ccpi.category_id =?', $cat_id);
50
+ }else{
51
+ Mage::helper('ddg')->log('Best seller. Category id '. $cat_id . ' is invalid. It does not exist.');
52
+ }
53
+ }
54
+
55
+ //filter collection by category by category_name
56
+ if($cat_name = Mage::app()->getRequest()->getParam('category_name')){
57
+ $category = Mage::getModel('catalog/category')->loadByAttribute('name', $cat_name);
58
+ if($category){
59
+ $productCollection->getSelect()
60
+ ->joinLeft(
61
+ array("ccpi" => 'catalog_category_product_index'),
62
+ "e.entity_id = ccpi.product_id",
63
+ array("category_id")
64
+ )
65
+ ->where('ccpi.category_id =?', $category->getId());
66
+ }else{
67
+ Mage::helper('ddg')->log('Best seller. Category name '. $cat_name .' is invalid. It does not exist.');
68
+ }
69
+ }
70
+ return $productCollection;
71
+ }
72
+
73
+ /**
74
+ * Display type mode.
75
+ *
76
+ * @return mixed|string
77
+ */
78
+ public function getMode()
79
+ {
80
+ return Mage::helper('ddg/recommended')->getDisplayType();
81
+
82
+ }
83
+
84
+ /**
85
+ * Price html.
86
+ * @param $product
87
+ *
88
+ * @return string
89
+ */
90
+ public function getPriceHtml($product)
91
+ {
92
+ $this->setTemplate('connector/product/price.phtml');
93
+ $this->setProduct($product);
94
+ return $this->toHtml();
95
+ }
96
+
97
+ }
app/code/community/Dotdigitalgroup/Email/Block/Recommended/Mostviewed.php ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Recommended_Mostviewed extends Dotdigitalgroup_Email_Block_Edc
4
+ {
5
+
6
+ /**
7
+ * Prepare layout.
8
+ * @return Mage_Core_Block_Abstract|void
9
+ */
10
+ protected function _prepareLayout()
11
+ {
12
+ if ($root = $this->getLayout()->getBlock('root')) {
13
+ $root->setTemplate('page/blank.phtml');
14
+ }
15
+ }
16
+
17
+ /**
18
+ * Get product collection.
19
+ * @return array
20
+ * @throws Exception
21
+ */
22
+ public function getLoadedProductCollection()
23
+ {
24
+ $productsToDisplay = array();
25
+ $mode = $this->getRequest()->getActionName();
26
+ $limit = Mage::helper('ddg/recommended')->getDisplayLimitByMode($mode);
27
+ $from = Mage::helper('ddg/recommended')->getTimeFromConfig($mode);
28
+ $locale = Mage::app()->getLocale()->getLocale();
29
+
30
+ $to = Zend_Date::now($locale)->toString(Zend_Date::ISO_8601);
31
+ $productCollection = Mage::getResourceModel('reports/product_collection')
32
+ ->addViewsCount($from, $to)
33
+ ->setPageSize($limit);
34
+
35
+ //filter collection by category by category_id
36
+ if($cat_id = Mage::app()->getRequest()->getParam('category_id')){
37
+ $category = Mage::getModel('catalog/category')->load($cat_id);
38
+ if($category->getId()){
39
+ $productCollection->getSelect()
40
+ ->joinLeft(
41
+ array("ccpi" => 'catalog_category_product_index'),
42
+ "e.entity_id = ccpi.product_id",
43
+ array("category_id")
44
+ )
45
+ ->where('ccpi.category_id =?', $cat_id);
46
+ }else{
47
+ Mage::helper('ddg')->log('Most viewed. Category id '. $cat_id . ' is invalid. It does not exist.');
48
+ }
49
+ }
50
+
51
+ //filter collection by category by category_name
52
+ if($cat_name = Mage::app()->getRequest()->getParam('category_name')){
53
+ $category = Mage::getModel('catalog/category')->loadByAttribute('name', $cat_name);
54
+ if($category){
55
+ $productCollection->getSelect()
56
+ ->joinLeft(
57
+ array("ccpi" => 'catalog_category_product_index'),
58
+ "e.entity_id = ccpi.product_id",
59
+ array("category_id")
60
+ )
61
+ ->where('ccpi.category_id =?', $category->getId());
62
+ }else{
63
+ Mage::helper('ddg')->log('Most viewed. Category name '. $cat_name .' is invalid. It does not exist.');
64
+ }
65
+ }
66
+
67
+ foreach ($productCollection as $_product) {
68
+ $productId = $_product->getId();
69
+ $product = Mage::getModel('catalog/product')->load($productId);
70
+ if($product->isSalable())
71
+ $productsToDisplay[] = $product;
72
+ }
73
+
74
+ return $productsToDisplay;
75
+ }
76
+
77
+
78
+ /**
79
+ * Display mode type.
80
+ * @return mixed|string
81
+ */
82
+ public function getMode()
83
+ {
84
+ return Mage::helper('ddg/recommended')->getDisplayType();
85
+ }
86
+
87
+ /**
88
+ * @param $product
89
+ *
90
+ * @return string
91
+ */
92
+ public function getPriceHtml($product)
93
+ {
94
+ $this->setTemplate('connector/product/price.phtml');
95
+ $this->setProduct($product);
96
+ return $this->toHtml();
97
+ }
98
+ }
app/code/community/Dotdigitalgroup/Email/Block/Recommended/Products.php ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Recommended_Products extends Dotdigitalgroup_Email_Block_Edc
4
+ {
5
+ /**
6
+ * Slot div name.
7
+ * @var string
8
+ */
9
+ public $slot;
10
+
11
+ /**
12
+ * Prepare layout, set the template.
13
+ * @return Mage_Core_Block_Abstract|void
14
+ */
15
+ protected function _prepareLayout()
16
+ {
17
+ if ($root = $this->getLayout()->getBlock('root')) {
18
+ $root->setTemplate('page/blank.phtml');
19
+ }
20
+ }
21
+
22
+ /**
23
+ * get the products to display for table
24
+ */
25
+ public function getLoadedProductCollection()
26
+ {
27
+ //products to be diplayd for recommended pages
28
+ $productsToDisplay = array();
29
+ $orderId = $this->getRequest()->getParam('order_id');
30
+ //display mode based on the action name
31
+ $mode = $this->getRequest()->getActionName();
32
+ $orderModel = Mage::getModel('sales/order')->load($orderId);
33
+ //number of product items to be displayed
34
+ $limit = Mage::helper('ddg/recommended')->getDisplayLimitByMode($mode);
35
+ $orderItems = $orderModel->getAllItems();
36
+ $numItems = count($orderItems);
37
+
38
+ //no product found to display
39
+ if ($numItems == 0 || ! $limit) {
40
+ return array();
41
+ }elseif (count($orderItems) > $limit) {
42
+ $maxPerChild = 1;
43
+ } else {
44
+ $maxPerChild = number_format($limit / count($orderItems));
45
+ }
46
+
47
+ Mage::helper('ddg')->log('DYNAMIC PRODUCTS : limit ' . $limit . ' products : ' . $numItems . ', max per child : '. $maxPerChild);
48
+
49
+ foreach ($orderItems as $item) {
50
+ $i = 1;
51
+ $productId = $item->getProductId();
52
+ //parent product
53
+ $productModel = Mage::getModel('catalog/product')->load($productId);
54
+ //check for product exists
55
+ if ($productModel->getId()) {
56
+ //get single product for current mode
57
+ $recommendedProducts = $this->_getRecommendedProduct($productModel, $mode);
58
+ foreach ($recommendedProducts as $product) {
59
+ //load child product
60
+ $product = Mage::getModel('catalog/product')->load($product->getId());
61
+ //check if still exists
62
+ if ($product->getId() && count($productsToDisplay) < $limit && $i <= $maxPerChild && $product->isSaleable() && !$product->getParentId()) {
63
+ //we have a product to display
64
+ $productsToDisplay[$product->getId()] = $product;
65
+ $i++;
66
+ }
67
+ }
68
+ }
69
+ //have reached the limit don't loop for more
70
+ if (count($productsToDisplay) == $limit) {
71
+ break;
72
+ }
73
+ }
74
+
75
+ //check for more space to fill up the table with fallback products
76
+ if (count($productsToDisplay) < $limit) {
77
+ $fallbackIds = Mage::helper('ddg/recommended')->getFallbackIds();
78
+
79
+ foreach ($fallbackIds as $productId) {
80
+ $product = Mage::getModel('catalog/product')->load($productId);
81
+ if($product->isSaleable())
82
+ $productsToDisplay[$product->getId()] = $product;
83
+ //stop the limit was reached
84
+ if (count($productsToDisplay) == $limit) {
85
+ break;
86
+ }
87
+ }
88
+ }
89
+
90
+ Mage::helper('ddg')->log('loaded product to display ' . count($productsToDisplay));
91
+ return $productsToDisplay;
92
+ }
93
+
94
+ /**
95
+ * Product related items.
96
+ *
97
+ * @param Mage_Catalog_Model_Product $productModel
98
+ * @param $mode
99
+ *
100
+ * @return array
101
+ */
102
+ private function _getRecommendedProduct(Mage_Catalog_Model_Product $productModel, $mode)
103
+ {
104
+ //array of products to display
105
+ $products = array();
106
+ switch($mode){
107
+ case 'related':
108
+ $products = $productModel->getRelatedProducts();
109
+ break;
110
+ case 'upsell':
111
+ $products = $productModel->getUpSellProducts();
112
+ break;
113
+ case 'crosssell':
114
+ $products = $productModel->getCrossSellProducts();
115
+ break;
116
+
117
+ }
118
+
119
+ return $products;
120
+ }
121
+
122
+ /**
123
+ * Diplay mode type.
124
+ *
125
+ * @return mixed|string
126
+ */
127
+ public function getMode()
128
+ {
129
+ return Mage::helper('ddg/recommended')->getDisplayType();
130
+
131
+ }
132
+
133
+ /**
134
+ * Number of the colums.
135
+ * @return int|mixed
136
+ * @throws Exception
137
+ */
138
+ public function getColumnCount()
139
+ {
140
+ return Mage::helper('ddg/recommended')->getDisplayLimitByMode($this->getRequest()->getActionName());
141
+ }
142
+
143
+ /**
144
+ * Price html.
145
+ * @param $product
146
+ *
147
+ * @return string
148
+ */
149
+ public function getPriceHtml($product)
150
+ {
151
+ $this->setTemplate('connector/product/price.phtml');
152
+ $this->setProduct($product);
153
+ return $this->toHtml();
154
+ }
155
+
156
+
157
+ /**
158
+ * Nosto products data.
159
+ * @return object
160
+ */
161
+ public function getNostoProducts()
162
+ {
163
+ $client = Mage::getModel('ddg_automation/apiconnector_client');
164
+ //slot name, div id
165
+ $slot = Mage::app()->getRequest()->getParam('slot', false);
166
+
167
+ //email recommendation
168
+ $email = Mage::app()->getRequest()->getParam('email', false);
169
+
170
+ //no valid data for nosto recommendation
171
+ if (!$slot || ! $email)
172
+ return false;
173
+ else
174
+ $this->slot = $slot;
175
+
176
+ //html data from nosto
177
+ $data = $client->getNostoProducts($slot, $email);
178
+
179
+ //check for valid response
180
+ if (! isset($data->$email) && !isset($data->$email->$slot))
181
+ return false;
182
+ return $data->$email->$slot;
183
+ }
184
+
185
+ /**
186
+ * Slot name.
187
+ * Should be called after getNostoProducts.
188
+ * @return string
189
+ */
190
+ public function getSlotName()
191
+ {
192
+ return $this->slot;
193
+ }
194
+ }
app/code/community/Dotdigitalgroup/Email/Block/Recommended/Push.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Recommended_Push extends Dotdigitalgroup_Email_Block_Edc
4
+ {
5
+ /**
6
+ * Prepare layout, set template.
7
+ * @return Mage_Core_Block_Abstract|void
8
+ */
9
+ protected function _prepareLayout()
10
+ {
11
+ if ($root = $this->getLayout()->getBlock('root')) {
12
+ $root->setTemplate('page/blank.phtml');
13
+ }
14
+ }
15
+
16
+ /**
17
+ * get the products to display for table
18
+ */
19
+ public function getLoadedProductCollection()
20
+ {
21
+ $productsToDisplay = array();
22
+ $mode = $this->getRequest()->getActionName();
23
+ $limit = Mage::helper('ddg/recommended')->getDisplayLimitByMode($mode);
24
+
25
+ $productIds = Mage::helper('ddg/recommended')->getProductPushIds();
26
+
27
+ $productCollection = Mage::getResourceModel('catalog/product_collection')
28
+ ->addAttributeToFilter('entity_id', array('in' => $productIds))
29
+ ->setPageSize($limit)
30
+ ;
31
+ foreach ($productCollection as $_product) {
32
+ $productId = $_product->getId();
33
+ $product = Mage::getModel('catalog/product')->load($productId);
34
+ if($product->isSaleable())
35
+ $productsToDisplay[] = $product;
36
+
37
+ }
38
+
39
+ return $productsToDisplay;
40
+
41
+ }
42
+
43
+ /**
44
+ * Display type mode.
45
+ *
46
+ * @return mixed|string
47
+ */
48
+ public function getMode()
49
+ {
50
+ return Mage::helper('ddg/recommended')->getDisplayType();
51
+
52
+ }
53
+
54
+ /**
55
+ * Price html.
56
+ * @param $product
57
+ *
58
+ * @return string
59
+ */
60
+ public function getPriceHtml($product)
61
+ {
62
+ $this->setTemplate('connector/product/price.phtml');
63
+ $this->setProduct($product);
64
+ return $this->toHtml();
65
+ }
66
+ }
app/code/community/Dotdigitalgroup/Email/Block/Recommended/Quoteproducts.php ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Recommended_Quoteproducts extends Dotdigitalgroup_Email_Block_Edc
4
+ {
5
+ /**
6
+ * Prepare layout, set the template.
7
+ * @return Mage_Core_Block_Abstract|void
8
+ */
9
+ protected function _prepareLayout()
10
+ {
11
+ if ($root = $this->getLayout()->getBlock('root')) {
12
+ $root->setTemplate('page/blank.phtml');
13
+ }
14
+ }
15
+
16
+ /**
17
+ * get the products to display for table
18
+ */
19
+ public function getLoadedProductCollection()
20
+ {
21
+ //products to be diplayd for recommended pages
22
+ $productsToDisplay = array();
23
+ $quoteId = $this->getRequest()->getParam('quote_id');
24
+ //display mode based on the action name
25
+ $mode = $this->getRequest()->getActionName();
26
+ $quoteModel = Mage::getModel('sales/quote')->load($quoteId);
27
+ //number of product items to be displayed
28
+ $limit = Mage::helper('ddg/recommended')->getDisplayLimitByMode($mode);
29
+ $quoteItems = $quoteModel->getAllItems();
30
+ $numItems = count($quoteItems);
31
+
32
+ //no product found to display
33
+ if ($numItems == 0 || ! $limit) {
34
+ return array();
35
+ }elseif (count($quoteItems) > $limit) {
36
+ $maxPerChild = 1;
37
+ } else {
38
+ $maxPerChild = number_format($limit / count($quoteItems));
39
+ }
40
+
41
+ Mage::helper('ddg')->log('DYNAMIC QUOTE PRODUCTS : limit ' . $limit . ' products : ' . $numItems . ', max per child : '. $maxPerChild);
42
+
43
+ foreach ($quoteItems as $item) {
44
+ $i = 1;
45
+ $productId = $item->getProductId();
46
+ //parent product
47
+ $productModel = Mage::getModel('catalog/product')->load($productId);
48
+ //check for product exists
49
+ if ($productModel->getId()) {
50
+ //get single product for current mode
51
+ $recommendedProducts = $this->_getRecommendedProduct($productModel, $mode);
52
+ foreach ($recommendedProducts as $product) {
53
+ //load child product
54
+ $product = Mage::getModel('catalog/product')->load($product->getId());
55
+ //check if still exists
56
+ if ($product->getId() && count($productsToDisplay) < $limit && $i <= $maxPerChild && $product->isSaleable() && !$product->getParentId()) {
57
+ //we have a product to display
58
+ $productsToDisplay[$product->getId()] = $product;
59
+ $i++;
60
+ }
61
+ }
62
+ }
63
+ //have reached the limit don't loop for more
64
+ if (count($productsToDisplay) == $limit) {
65
+ break;
66
+ }
67
+ }
68
+
69
+ //check for more space to fill up the table with fallback products
70
+ if (count($productsToDisplay) < $limit) {
71
+ $fallbackIds = Mage::helper('ddg/recommended')->getFallbackIds();
72
+
73
+ foreach ($fallbackIds as $productId) {
74
+ $product = Mage::getModel('catalog/product')->load($productId);
75
+ if($product->isSaleable())
76
+ $productsToDisplay[$product->getId()] = $product;
77
+ //stop the limit was reached
78
+ if (count($productsToDisplay) == $limit) {
79
+ break;
80
+ }
81
+ }
82
+ }
83
+
84
+ Mage::helper('ddg')->log('quote - loaded product to display ' . count($productsToDisplay));
85
+ return $productsToDisplay;
86
+ }
87
+
88
+ /**
89
+ * Product related items.
90
+ *
91
+ * @param Mage_Catalog_Model_Product $productModel
92
+ * @param $mode
93
+ *
94
+ * @return array
95
+ */
96
+ private function _getRecommendedProduct(Mage_Catalog_Model_Product $productModel, $mode)
97
+ {
98
+ //array of products to display
99
+ $products = array();
100
+ switch($mode){
101
+ case 'related':
102
+ $products = $productModel->getRelatedProducts();
103
+ break;
104
+ case 'upsell':
105
+ $products = $productModel->getUpSellProducts();
106
+ break;
107
+ case 'crosssell':
108
+ $products = $productModel->getCrossSellProducts();
109
+ break;
110
+
111
+ }
112
+
113
+ return $products;
114
+ }
115
+
116
+ /**
117
+ * Diplay mode type.
118
+ *
119
+ * @return mixed|string
120
+ */
121
+ public function getMode()
122
+ {
123
+ return Mage::helper('ddg/recommended')->getDisplayType();
124
+
125
+ }
126
+
127
+ /**
128
+ * Number of the colums.
129
+ * @return int|mixed
130
+ * @throws Exception
131
+ */
132
+ public function getColumnCount()
133
+ {
134
+ return Mage::helper('ddg/recommended')->getDisplayLimitByMode($this->getRequest()->getActionName());
135
+ }
136
+
137
+ /**
138
+ * Price html.
139
+ * @param $product
140
+ *
141
+ * @return string
142
+ */
143
+ public function getPriceHtml($product)
144
+ {
145
+ $this->setTemplate('connector/product/price.phtml');
146
+ $this->setProduct($product);
147
+ return $this->toHtml();
148
+ }
149
+ }
app/code/community/Dotdigitalgroup/Email/Block/Recommended/Recentlyviewed.php ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Recommended_Recentlyviewed extends Dotdigitalgroup_Email_Block_Edc
4
+ {
5
+
6
+ /**
7
+ * Prepare layout, set template.
8
+ * @return Mage_Core_Block_Abstract|void
9
+ */
10
+ protected function _prepareLayout()
11
+ {
12
+ if ($root = $this->getLayout()->getBlock('root')) {
13
+ $root->setTemplate('page/blank.phtml');
14
+ }
15
+ }
16
+
17
+ /**
18
+ * Products collection.
19
+ *
20
+ * @return array
21
+ * @throws Exception
22
+ */
23
+ public function getLoadedProductCollection()
24
+ {
25
+ $productsToDisplay = array();
26
+ $mode = $this->getRequest()->getActionName();
27
+ $customerId = $this->getRequest()->getParam('customer_id');
28
+ $limit = Mage::helper('ddg/recommended')->getDisplayLimitByMode($mode);
29
+ //login customer to receive the recent products
30
+ $session = Mage::getSingleton('customer/session');
31
+ $isLoggedIn = $session->loginById($customerId);
32
+ /** @var Mage_Reports_Block_Product_Viewed $collection */
33
+ $collection = Mage::getSingleton('Mage_Reports_Block_Product_Viewed');
34
+ $items = $collection->getItemsCollection()
35
+ ->setPageSize($limit);
36
+ Mage::helper('ddg')->log('Recentlyviewed customer : ' . $customerId . ', mode ' . $mode . ', limit : ' . $limit .
37
+ ', items found : ' . count($items) . ', is customer logged in : ' . $isLoggedIn . ', products :' . count($productsToDisplay));
38
+ foreach ($items as $product) {
39
+ $product = Mage::getModel('catalog/product')->load($product->getId());
40
+ if($product->isSalable())
41
+ $productsToDisplay[$product->getId()] = $product;
42
+
43
+ }
44
+ $session->logout();
45
+
46
+ return $productsToDisplay;
47
+ }
48
+
49
+
50
+ /**
51
+ * Display mode type.
52
+ *
53
+ * @return mixed|string
54
+ */
55
+ public function getMode()
56
+ {
57
+ return Mage::helper('ddg/recommended')->getDisplayType();
58
+
59
+ }
60
+
61
+ /**
62
+ * Price html.
63
+ * @param $product
64
+ *
65
+ * @return string
66
+ */
67
+ public function getPriceHtml($product)
68
+ {
69
+ $this->setTemplate('connector/product/price.phtml');
70
+ $this->setProduct($product);
71
+ return $this->toHtml();
72
+ }
73
+ }
app/code/community/Dotdigitalgroup/Email/Block/Recommended/Wishlistproducts.php ADDED
@@ -0,0 +1,176 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Recommended_Wishlistproducts extends Dotdigitalgroup_Email_Block_Edc
4
+ {
5
+ /**
6
+ * Prepare layout, set the template.
7
+ * @return Mage_Core_Block_Abstract|void
8
+ */
9
+ protected function _prepareLayout()
10
+ {
11
+ if ($root = $this->getLayout()->getBlock('root')) {
12
+ $root->setTemplate('page/blank.phtml');
13
+ }
14
+ }
15
+
16
+ protected function _getWishlistItems()
17
+ {
18
+ $wishlist = $this->_getWishlist();
19
+ if($wishlist && count($wishlist->getItemCollection()))
20
+ return $wishlist->getItemCollection();
21
+ else
22
+ return array();
23
+ }
24
+
25
+ protected function _getWishlist()
26
+ {
27
+ $customerId = Mage::app()->getRequest()->getParam('customer_id');
28
+ if(!$customerId)
29
+ return array();
30
+
31
+ $customer = Mage::getModel('customer/customer')->load($customerId);
32
+ if(!$customer->getId())
33
+ return array();
34
+
35
+ $collection = Mage::getModel('wishlist/wishlist')->getCollection();
36
+ $collection->addFieldToFilter('customer_id', $customerId)
37
+ ->setOrder('updated_at', 'DESC');
38
+
39
+ if ($collection->count())
40
+ return $collection->getFirstItem();
41
+ else
42
+ return array();
43
+
44
+ }
45
+
46
+ /**
47
+ * get the products to display for table
48
+ */
49
+ public function getLoadedProductCollection()
50
+ {
51
+ //products to be display for recommended pages
52
+ $productsToDisplay = array();
53
+ //display mode based on the action name
54
+ $mode = $this->getRequest()->getActionName();
55
+ //number of product items to be displayed
56
+ $limit = Mage::helper('ddg/recommended')->getDisplayLimitByMode($mode);
57
+ $items = $this->_getWishlistItems();
58
+ $numItems = count($items);
59
+
60
+ //no product found to display
61
+ if ($numItems == 0 || ! $limit) {
62
+ return array();
63
+ }elseif (count($items) > $limit) {
64
+ $maxPerChild = 1;
65
+ } else {
66
+ $maxPerChild = number_format($limit / count($items));
67
+ }
68
+
69
+ Mage::helper('ddg')->log('DYNAMIC WISHLIST PRODUCTS : limit ' . $limit . ' products : ' . $numItems . ', max per child : '. $maxPerChild);
70
+
71
+ foreach ($items as $item) {
72
+ $i = 1;
73
+ //parent product
74
+ $product = $item->getProduct();
75
+ //check for product exists
76
+ if ($product->getId()) {
77
+ //get single product for current mode
78
+ $recommendedProducts = $this->_getRecommendedProduct($product, $mode);
79
+ foreach ($recommendedProducts as $product) {
80
+ //load child product
81
+ $product = Mage::getModel('catalog/product')->load($product->getId());
82
+ //check if still exists
83
+ if ($product->getId() && count($productsToDisplay) < $limit && $i <= $maxPerChild && $product->isSaleable() && !$product->getParentId()) {
84
+ //we have a product to display
85
+ $productsToDisplay[$product->getId()] = $product;
86
+ $i++;
87
+ }
88
+ }
89
+ }
90
+ //have reached the limit don't loop for more
91
+ if (count($productsToDisplay) == $limit) {
92
+ break;
93
+ }
94
+ }
95
+
96
+ //check for more space to fill up the table with fallback products
97
+ if (count($productsToDisplay) < $limit) {
98
+ $fallbackIds = Mage::helper('ddg/recommended')->getFallbackIds();
99
+
100
+ foreach ($fallbackIds as $productId) {
101
+ $product = Mage::getModel('catalog/product')->load($productId);
102
+ if($product->isSaleable())
103
+ $productsToDisplay[$product->getId()] = $product;
104
+ //stop the limit was reached
105
+ if (count($productsToDisplay) == $limit) {
106
+ break;
107
+ }
108
+ }
109
+ }
110
+
111
+ Mage::helper('ddg')->log('wishlist - loaded product to display ' . count($productsToDisplay));
112
+ return $productsToDisplay;
113
+ }
114
+
115
+ /**
116
+ * Product related items.
117
+ *
118
+ * @param Mage_Catalog_Model_Product $productModel
119
+ * @param $mode
120
+ *
121
+ * @return array
122
+ */
123
+ private function _getRecommendedProduct(Mage_Catalog_Model_Product $productModel, $mode)
124
+ {
125
+ //array of products to display
126
+ $products = array();
127
+ switch($mode){
128
+ case 'related':
129
+ $products = $productModel->getRelatedProducts();
130
+ break;
131
+ case 'upsell':
132
+ $products = $productModel->getUpSellProducts();
133
+ break;
134
+ case 'crosssell':
135
+ $products = $productModel->getCrossSellProducts();
136
+ break;
137
+
138
+ }
139
+
140
+ return $products;
141
+ }
142
+
143
+ /**
144
+ * Diplay mode type.
145
+ *
146
+ * @return mixed|string
147
+ */
148
+ public function getMode()
149
+ {
150
+ return Mage::helper('ddg/recommended')->getDisplayType();
151
+
152
+ }
153
+
154
+ /**
155
+ * Number of the colums.
156
+ * @return int|mixed
157
+ * @throws Exception
158
+ */
159
+ public function getColumnCount()
160
+ {
161
+ return Mage::helper('ddg/recommended')->getDisplayLimitByMode($this->getRequest()->getActionName());
162
+ }
163
+
164
+ /**
165
+ * Price html.
166
+ * @param $product
167
+ *
168
+ * @return string
169
+ */
170
+ public function getPriceHtml($product)
171
+ {
172
+ $this->setTemplate('ddg/product/price.phtml');
173
+ $this->setProduct($product);
174
+ return $this->toHtml();
175
+ }
176
+ }
app/code/community/Dotdigitalgroup/Email/Block/System/Email/Template/Edit.php ADDED
@@ -0,0 +1,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,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Wishlist extends Dotdigitalgroup_Email_Block_Edc
4
+ {
5
+ protected $_website;
6
+ /**
7
+ * Prepare layout, set template and title.
8
+ *
9
+ * @return Mage_Core_Block_Abstract|void
10
+ */
11
+ protected function _prepareLayout()
12
+ {
13
+ if ($root = $this->getLayout()->getBlock('root'))
14
+ $root->setTemplate('page/blank.phtml');
15
+ }
16
+
17
+ public function getWishlistItems()
18
+ {
19
+ $wishlist = $this->_getWishlist();
20
+ if($wishlist && count($wishlist->getItemCollection()))
21
+ return $wishlist->getItemCollection();
22
+ else
23
+ return false;
24
+ }
25
+
26
+ protected function _getWishlist()
27
+ {
28
+ $customerId = Mage::app()->getRequest()->getParam('customer_id');
29
+ if(!$customerId)
30
+ return false;
31
+
32
+ $customer = Mage::getModel('customer/customer')->load($customerId);
33
+ if(!$customer->getId())
34
+ return false;
35
+
36
+ $collection = Mage::getModel('wishlist/wishlist')->getCollection();
37
+ $collection->addFieldToFilter('customer_id', $customerId)
38
+ ->setOrder('updated_at', 'DESC');
39
+
40
+ if ($collection->count())
41
+ return $collection->getFirstItem();
42
+ else
43
+ return false;
44
+
45
+ }
46
+
47
+ public function getMode()
48
+ {
49
+ return Mage::helper('ddg')->getWebsiteConfig(
50
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DYNAMIC_CONTENT_WIHSLIST_DISPLAY
51
+ );
52
+ }
53
+ }
app/code/community/Dotdigitalgroup/Email/Helper/Config.php ADDED
@@ -0,0 +1,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_styles';
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_roi_tracking/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,921 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $contactModel = Mage::getModel('ddg_automation/contact');
374
+ $contactModel
375
+ ->loadByCustomerId($customerId)
376
+ ->setEmailImported(Dotdigitalgroup_Email_Model_Contact::EMAIL_CONTACT_NOT_IMPORTED)
377
+ ->save();
378
+ }
379
+
380
+ /**
381
+ * Diff between to times;
382
+ *
383
+ * @param $time1
384
+ * @param $time2
385
+ * @return int
386
+ */
387
+ public function dateDiff($time1, $time2=NULL) {
388
+ if (is_null($time2)) {
389
+ $time2 = Mage::getModel('core/date')->date();
390
+ }
391
+ $time1 = strtotime($time1);
392
+ $time2 = strtotime($time2);
393
+ return $time2 - $time1;
394
+ }
395
+
396
+
397
+ /**
398
+ * Disable website config when the request is made admin area only!
399
+ * @param $path
400
+ *
401
+ * @throws Mage_Core_Exception
402
+ */
403
+ public function disableConfigForWebsite($path)
404
+ {
405
+ $scopeId = 0;
406
+ if ($website = Mage::app()->getRequest()->getParam('website')) {
407
+ $scope = 'websites';
408
+ $scopeId = Mage::app()->getWebsite($website)->getId();
409
+ } else {
410
+ $scope = "default";
411
+ }
412
+ $config = Mage::getConfig();
413
+ $config->saveConfig($path, 0, $scope, $scopeId);
414
+ $config->cleanCache();
415
+ }
416
+
417
+ /**
418
+ * number of customers with duplicate emails, emails as total number
419
+ * @return Mage_Customer_Model_Resource_Customer_Collection
420
+ */
421
+ public function getCustomersWithDuplicateEmails( ) {
422
+ $customers = Mage::getModel('customer/customer')->getCollection();
423
+
424
+ //duplicate emails
425
+ $customers->getSelect()
426
+ ->columns(array('emails' => 'COUNT(e.entity_id)'))
427
+ ->group('email')
428
+ ->having('emails > ?', 1);
429
+
430
+ return $customers;
431
+ }
432
+
433
+ /**
434
+ * Create new raygun client.
435
+ *
436
+ * @return bool|\Raygun4php\RaygunClient
437
+ */
438
+ public function getRaygunClient()
439
+ {
440
+ $code = Mage::getstoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_RAYGUN_APPLICATION_CODE);
441
+
442
+ if ($this->raygunEnabled()) {
443
+ //use async mode for sending.
444
+ $async = Mage::getStoreConfigFlag(Dotdigitalgroup_Email_Helper_Config::XML_PATH_RAYGUN_APPLICATION_ASYNC);
445
+ require_once Mage::getBaseDir('lib') . DS . 'Raygun4php' . DS . 'RaygunClient.php';
446
+ return new Raygun4php\RaygunClient($code, $async);
447
+ }
448
+
449
+ return false;
450
+ }
451
+
452
+ /**
453
+ * Raygun logs.
454
+ * @param int $errno
455
+ * @param $message
456
+ * @param string $filename
457
+ * @param int $line
458
+ * @param array $tags
459
+ *
460
+ * @return int|null
461
+ */
462
+ public function rayLog($errno = 100, $message, $filename = 'helper/data.php', $line = 1, $tags = array())
463
+ {
464
+ if (!$this->raygunEnabled())
465
+ return;
466
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
467
+ if (empty($tags)) {
468
+ $tags = array(
469
+ $baseUrl,
470
+ Mage::getVersion()
471
+ );
472
+ }
473
+
474
+ $client = $this->getRaygunClient();
475
+ //user, firstname, lastname, email, annonim, uuid
476
+ $client->SetUser($baseUrl, null, null, $this->getApiUsername());
477
+ $client->SetVersion($this->getConnectorVersion());
478
+ $client->SendError($errno, $message, $filename,$line, $tags);
479
+ }
480
+
481
+
482
+ /**
483
+ * check for raygun application and if enabled.
484
+ * @param int $websiteId
485
+ *
486
+ * @return mixed
487
+ * @throws Mage_Core_Exception
488
+ */
489
+ public function raygunEnabled($websiteId = 0)
490
+ {
491
+ $website = Mage::app()->getWebsite($websiteId);
492
+
493
+ return (bool)$website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_RAYGUN_APPLICATION_CODE);
494
+
495
+ }
496
+
497
+ /**
498
+ * Generate the baseurl for the default store
499
+ * dynamic content will be displayed
500
+ * @return string
501
+ * @throws Mage_Core_Exception
502
+ */
503
+ public function generateDynamicUrl()
504
+ {
505
+ $website = Mage::app()->getRequest()->getParam('website', false);
506
+
507
+ //set website url for the default store id
508
+ $website = ($website)? Mage::app()->getWebsite( $website ) : 0;
509
+
510
+ $defaultGroup = Mage::app()->getWebsite($website)
511
+ ->getDefaultGroup();
512
+
513
+ if (! $defaultGroup)
514
+ return $mage = Mage::app()->getStore()->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
515
+
516
+ //base url
517
+ $baseUrl = Mage::app()->getStore($defaultGroup->getDefaultStore())->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
518
+
519
+ return $baseUrl;
520
+
521
+ }
522
+
523
+ /**
524
+ *
525
+ *
526
+ * @param int $store
527
+ * @return mixed
528
+ */
529
+ public function isNewsletterSuccessDisabled($store = 0)
530
+ {
531
+ return Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DISABLE_NEWSLETTER_SUCCESS, $store);
532
+ }
533
+
534
+ /**
535
+ * get sales_flat_order table description
536
+ *
537
+ * @return array
538
+ */
539
+ public function getOrderTableDescription()
540
+ {
541
+ $resource = Mage::getSingleton('core/resource');
542
+ $readConnection = $resource->getConnection('core_read');
543
+ $salesTable = $resource->getTableName('sales/order');
544
+
545
+ return $readConnection->describeTable($salesTable);
546
+ }
547
+
548
+ /**
549
+ * get sales_flat_quote table description
550
+ *
551
+ * @return array
552
+ */
553
+ public function getQuoteTableDescription()
554
+ {
555
+ $resource = Mage::getSingleton('core/resource');
556
+ $readConnection = $resource->getConnection('core_read');
557
+ $table = $resource->getTableName('sales/quote');
558
+ return $readConnection->describeTable($table);
559
+ }
560
+
561
+ /**
562
+ * @return bool
563
+ */
564
+ public function getEasyEmailCapture()
565
+ {
566
+ return Mage::getStoreConfigFlag(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_EMAIL_CAPTURE);
567
+ }
568
+
569
+ /**
570
+ * @return bool
571
+ */
572
+ public function getEasyEmailCaptureForNewsletter()
573
+ {
574
+ return Mage::getStoreConfigFlag(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_EMAIL_CAPTURE_NEWSLETTER);
575
+ }
576
+ /**
577
+ * get feefo logon config value
578
+ *
579
+ * @return mixed
580
+ */
581
+ public function getFeefoLogon()
582
+ {
583
+ return $this->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_REVIEWS_FEEFO_LOGON);
584
+ }
585
+
586
+ /**
587
+ * get feefo reviews limit config value
588
+ *
589
+ * @return mixed
590
+ */
591
+ public function getFeefoReviewsPerProduct()
592
+ {
593
+ return $this->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_REVIEWS_FEEFO_REVIEWS);
594
+ }
595
+
596
+ /**
597
+ * get feefo logo template config value
598
+ *
599
+ * @return mixed
600
+ */
601
+ public function getFeefoLogoTemplate()
602
+ {
603
+ return $this->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_REVIEWS_FEEFO_TEMPLATE);
604
+ }
605
+
606
+ /**
607
+ * update data fields
608
+ *
609
+ * @param $email
610
+ * @param Mage_Core_Model_Website $website
611
+ * @param $storeName
612
+ */
613
+ public function updateDataFields($email, Mage_Core_Model_Website $website, $storeName)
614
+ {
615
+ $data = array();
616
+ if($store_name = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_STORE_NAME)){
617
+ $data[] = array(
618
+ 'Key' => $store_name,
619
+ 'Value' => $storeName
620
+ );
621
+ }
622
+ if($website_name = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_WEBSITE_NAME)){
623
+ $data[] = array(
624
+ 'Key' => $website_name,
625
+ 'Value' => $website->getName()
626
+ );
627
+ }
628
+ if(!empty($data)){
629
+ //update data fields
630
+ $client = $this->getWebsiteApiClient($website);
631
+ $client->updateContactDatafieldsByEmail($email, $data);
632
+ }
633
+ }
634
+
635
+ /**
636
+ * check connector SMTP installed/active status
637
+ * @return boolean
638
+ */
639
+ public function isSmtpEnabled()
640
+ {
641
+ return (bool)Mage::getConfig()->getModuleConfig('Ddg_Transactional')->is('active', 'true');
642
+ }
643
+
644
+ /**
645
+ * Is magento enterprise.
646
+ * @return bool
647
+ */
648
+ public function isEnterprise()
649
+ {
650
+ return Mage::getConfig ()->getModuleConfig ( 'Enterprise_Enterprise' ) && Mage::getConfig ()->getModuleConfig ( 'Enterprise_AdminGws' ) && Mage::getConfig ()->getModuleConfig ( 'Enterprise_Checkout' ) && Mage::getConfig ()->getModuleConfig ( 'Enterprise_Customer' );
651
+
652
+ }
653
+
654
+ public function getTemplateList()
655
+ {
656
+ $client = $this->getWebsiteApiClient(Mage::app()->getWebsite());
657
+ if(!$client)
658
+ return array();
659
+
660
+ $templates = $client->getApiTemplateList();
661
+ $fields[] = array('value' => '', 'label' => '');
662
+ foreach ( $templates as $one ) {
663
+ if ( isset( $one->id ) ) {
664
+ $fields[] = array(
665
+ 'value' => $one->id,
666
+ 'label' => $this->__( addslashes( $one->name ) )
667
+ );
668
+ }
669
+ }
670
+ return $fields;
671
+ }
672
+
673
+ /**
674
+ * Update last quote id datafield.
675
+ * @param $quoteId
676
+ * @param $email
677
+ * @param $websiteId
678
+ */
679
+ public function updateLastQuoteId($quoteId, $email, $websiteId)
680
+ {
681
+ $client = $this->getWebsiteApiClient($websiteId);
682
+ //last quote id config data mapped
683
+ $quoteIdField = $this->getLastQuoteId();
684
+
685
+ $data[] = array(
686
+ 'Key' => $quoteIdField,
687
+ 'Value' => $quoteId
688
+ );
689
+ //update datafields for conctact
690
+ $client->updateContactDatafieldsByEmail($email, $data);
691
+ }
692
+
693
+ /**
694
+ * Remove code and disable Raygun.
695
+ */
696
+ public function disableRaygun()
697
+ {
698
+ $config = new Mage_Core_Model_Config();
699
+ $config->saveConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_RAYGUN_APPLICATION_CODE, '');
700
+ Mage::getConfig()->cleanCache();
701
+ }
702
+
703
+ public function enableRaygunCode()
704
+ {
705
+ $curl = new Varien_Http_Adapter_Curl();
706
+ $curl->setConfig(array(
707
+ 'timeout' => 2
708
+ ));
709
+ $curl->write(Zend_Http_Client::GET, Dotdigitalgroup_Email_Helper_Config::RAYGUN_API_CODE_URL, '1.0');
710
+ $data = $curl->read();
711
+
712
+ if ($data === false) {
713
+ return false;
714
+ }
715
+ $data = preg_split('/^\r?$/m', $data, 2);
716
+ $data = trim($data[1]);
717
+ $curl->close();
718
+
719
+ $xml = new SimpleXMLElement($data);
720
+ $raygunCode = $xml->code;
721
+
722
+ //not found
723
+ if (!$raygunCode)
724
+ return;
725
+
726
+ $config = new Mage_Core_Model_Config();
727
+ $config->saveConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_RAYGUN_APPLICATION_CODE, $raygunCode);
728
+ }
729
+
730
+ /**
731
+ * Send the exception to raygun.
732
+ *
733
+ * @param $e Exception
734
+ */
735
+ public function sendRaygunException( $e )
736
+ {
737
+ if (!$this->raygunEnabled())
738
+ return;
739
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
740
+ $tags = array(
741
+ $baseUrl,
742
+ Mage::getVersion()
743
+ );
744
+
745
+ $client = $this->getRaygunClient();
746
+ //user, firstname, lastname, email, annonim, uuid
747
+ $client->SetUser($baseUrl, null, null, $this->getApiUsername());
748
+ $client->SetVersion($this->getConnectorVersion());
749
+ $client->SendException($e, $tags);
750
+ }
751
+
752
+ /**
753
+ * @param int $websiteId
754
+ *
755
+ * @return bool
756
+ */
757
+ public function getOrderSyncEnabled($websiteId = 0)
758
+ {
759
+ return Mage::getStoreConfigFlag(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_ORDER_ENABLED, $websiteId);
760
+ }
761
+ /**
762
+ * @param int $websiteId
763
+ *
764
+ * @return bool
765
+ */
766
+ public function getCatalogSyncEnabled($websiteId = 0)
767
+ {
768
+ return Mage::getStoreConfigFlag(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_CATALOG_ENABLED, $websiteId);
769
+ }
770
+
771
+ /**
772
+ * @param int $websiteId
773
+ *
774
+ * @return bool
775
+ */
776
+ public function getContactSyncEnabled($websiteId = 0)
777
+ {
778
+ return Mage::getStoreConfigFlag(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_CONTACT_ENABLED, $websiteId);
779
+ }
780
+
781
+ /**
782
+ * @param int $websiteId
783
+ *
784
+ * @return bool
785
+ */
786
+ public function getGuestSyncEnabled($websiteId = 0)
787
+ {
788
+ return Mage::getStoreConfigFlag(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_GUEST_ENABLED, $websiteId);
789
+ }
790
+
791
+ /**
792
+ * @param int $websiteId
793
+ *
794
+ * @return bool
795
+ */
796
+ public function getSubscriberSyncEnabled($websiteId = 0)
797
+ {
798
+ return Mage::getStoreConfigFlag(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_SUBSCRIBER_ENABLED, $websiteId);
799
+ }
800
+
801
+ /**
802
+ * @return bool
803
+ */
804
+ public function getCronInstalled()
805
+ {
806
+ $lastCustomerSync = Mage::getModel('ddg_automation/cron')->getLastCustomerSync();
807
+ $timespan = Mage::helper('ddg')->dateDiff($lastCustomerSync);
808
+
809
+ //last customer cron was less then 15 min
810
+ if ($timespan <= 15 * 60) {
811
+ return true;
812
+ }
813
+ return false;
814
+ }
815
+ /**
816
+ * Get the config id by the automation type.
817
+ * @param $automationType
818
+ * @param int $websiteId
819
+ *
820
+ * @return mixed
821
+ */
822
+ public function getAutomationIdByType($automationType, $websiteId = 0)
823
+ {
824
+ $path = constant('Dotdigitalgroup_Email_Helper_Config::' . $automationType);
825
+ $automationCampaignId = $this->getWebsiteConfig($path, $websiteId);
826
+
827
+ return $automationCampaignId;
828
+ }
829
+
830
+ public function getAbandonedProductName()
831
+ {
832
+ return Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_ABANDONED_PRODUCT_NAME);
833
+
834
+ }
835
+
836
+ /**
837
+ * Update last quote id datafield.
838
+ * @param $name
839
+ * @param $email
840
+ * @param $websiteId
841
+ */
842
+ public function updateAbandonedProductName($name, $email, $websiteId)
843
+ {
844
+ $client = $this->getWebsiteApiClient($websiteId);
845
+ // id config data mapped
846
+ $field = $this->getAbandonedProductName();
847
+
848
+ if ($field) {
849
+ $data[] = array(
850
+ 'Key' => $field,
851
+ 'Value' => $name
852
+ );
853
+ //update data field for contact
854
+ $client->updateContactDatafieldsByEmail($email, $data);
855
+ }
856
+ }
857
+
858
+
859
+ /**
860
+ * Api request response time limit that should be logged.
861
+ *
862
+ * @param int $websiteId
863
+ *
864
+ * @return mixed
865
+ * @throws Mage_Core_Exception
866
+ */
867
+ public function getApiResponseTimeLimit($websiteId = 0)
868
+ {
869
+ $website = Mage::app()->getWebsite($websiteId);
870
+ $limit = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DEBUG_API_REQUEST_LIMIT);
871
+
872
+ return $limit;
873
+ }
874
+
875
+ /**
876
+ * Main email for an account.
877
+ *
878
+ * @param int $website
879
+ *
880
+ * @return string
881
+ */
882
+ public function getAccountEmail( $website = 0)
883
+ {
884
+ $client = $this->getWebsiteApiClient($website);
885
+ $info = $client->getAccountInfo();
886
+ $email = '';
887
+
888
+ if(isset($info->properties)){
889
+ $properties = $info->properties;
890
+
891
+ foreach ( $properties as $property ) {
892
+
893
+ if ($property->name == 'MainEmail')
894
+ $email = $property->value;
895
+ }
896
+ }
897
+ return $email;
898
+ }
899
+
900
+ public function authIpAddress()
901
+ {
902
+ if ($ipString = Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_IP_RESTRICTION_ADDRESSES)) {
903
+ //string to array
904
+ $ipArray = explode(',', $ipString);
905
+ //remove white spaces
906
+ foreach($ipArray as $key => $ip){
907
+ $ipArray[$key] = preg_replace('/\s+/', '', $ip);
908
+ }
909
+ //ip address
910
+ $ipAddress = Mage::helper('core/http')->getRemoteAddr();
911
+
912
+ if(in_array($ipAddress, $ipArray)) {
913
+ return true;
914
+ }
915
+
916
+ $this->getRaygunClient()->Send('Ip address auth failed with ip address :' . $ipAddress);
917
+ return false;
918
+ }
919
+ return false;
920
+ }
921
+ }
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()->getFirstItem();
47
+ }
48
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Orders.php ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Tabs_Analysis_Orders extends Mage_Core_Model_Abstract
4
+ {
5
+ /**
6
+ * calculate sales and prepare columns
7
+ *
8
+ * @param int $isFilter
9
+ * @return Mage_Reports_Model_Resource_Order_Collection
10
+ */
11
+ protected function calculateSales($isFilter = 0)
12
+ {
13
+ $collection = Mage::getResourceModel('reports/order_collection');
14
+
15
+ $statuses = Mage::getSingleton('sales/config')
16
+ ->getOrderStatusesForState(Mage_Sales_Model_Order::STATE_CANCELED);
17
+
18
+ if (empty($statuses)) {
19
+ $statuses = array(0);
20
+ }
21
+ $adapter = $collection->getConnection();
22
+
23
+ if (Mage::getStoreConfig('sales/dashboard/use_aggregated_data')) {
24
+ $collection->setMainTable('sales/order_aggregated_created');
25
+ $collection->removeAllFieldsFromSelect();
26
+ $averageExpr = $adapter->getCheckSql(
27
+ 'SUM(main_table.orders_count) > 0',
28
+ 'SUM(main_table.total_revenue_amount)/SUM(main_table.orders_count)',
29
+ 0);
30
+ $collection->getSelect()->columns(array(
31
+ 'lifetime' => 'SUM(main_table.total_revenue_amount)',
32
+ 'average' => $averageExpr,
33
+ 'total_count' => "SUM(main_table.orders_count)",
34
+ 'day_count' => "ROUND(SUM(main_table.orders_count) / DATEDIFF(date(MAX(period)) , date(MIN(period))), 2)"
35
+ ));
36
+
37
+ if (!$isFilter) {
38
+ $collection->addFieldToFilter('store_id',
39
+ array('eq' => Mage::app()->getStore(Mage_Core_Model_Store::ADMIN_CODE)->getId())
40
+ );
41
+ }
42
+ $collection->getSelect()->where('main_table.order_status NOT IN(?)', $statuses);
43
+ } else {
44
+ $collection->setMainTable('sales/order');
45
+ $collection->removeAllFieldsFromSelect();
46
+
47
+ $expr = $this->_getSalesAmountExpression($collection);
48
+
49
+ if ($isFilter == 0) {
50
+ $expr = '(' . $expr . ') * main_table.base_to_global_rate';
51
+ }
52
+
53
+ $collection->getSelect()
54
+ ->columns(array(
55
+ 'lifetime' => "SUM({$expr})",
56
+ 'average' => "AVG({$expr})",
57
+ 'total_count' => "COUNT({$expr})",
58
+ 'day_count' => "ROUND(COUNT({$expr}) / DATEDIFF(date(MAX(created_at)) , date(MIN(created_at))), 2)"
59
+ ))
60
+ ->where('main_table.status NOT IN(?)', $statuses)
61
+ ->where('main_table.state NOT IN(?)', array(
62
+ Mage_Sales_Model_Order::STATE_NEW,
63
+ Mage_Sales_Model_Order::STATE_PENDING_PAYMENT)
64
+ );
65
+ }
66
+ return $collection;
67
+ }
68
+
69
+ /**
70
+ * get sales amount expression
71
+ *
72
+ * @param $collection
73
+ * @return string
74
+ */
75
+ protected function _getSalesAmountExpression($collection)
76
+ {
77
+ $adapter = $collection->getConnection();
78
+ $expressionTransferObject = new Varien_Object(array(
79
+ 'expression' => '%s - %s - %s - (%s - %s - %s)',
80
+ 'arguments' => array(
81
+ $adapter->getIfNullSql('main_table.base_total_invoiced', 0),
82
+ $adapter->getIfNullSql('main_table.base_tax_invoiced', 0),
83
+ $adapter->getIfNullSql('main_table.base_shipping_invoiced', 0),
84
+ $adapter->getIfNullSql('main_table.base_total_refunded', 0),
85
+ $adapter->getIfNullSql('main_table.base_tax_refunded', 0),
86
+ $adapter->getIfNullSql('main_table.base_shipping_refunded', 0),
87
+ )
88
+ ));
89
+
90
+ return vsprintf(
91
+ $expressionTransferObject->getExpression(),
92
+ $expressionTransferObject->getArguments()
93
+ );
94
+
95
+ }
96
+
97
+ /**
98
+ * @param int $store
99
+ * @param int $website
100
+ * @param int $group
101
+ * @return Varien_Object
102
+ * @throws Mage_Core_Exception
103
+ */
104
+ public function getLifetimeSales($store = 0, $website = 0, $group =0)
105
+ {
106
+ $isFilter = $store || $website || $group;
107
+ $collection = $this->calculateSales($isFilter);
108
+
109
+ if ($store) {
110
+ $collection->addFieldToFilter('store_id', $store);
111
+ } else if ($website){
112
+ $storeIds = Mage::app()->getWebsite($website)->getStoreIds();
113
+ $collection->addFieldToFilter('store_id', array('in' => $storeIds));
114
+ } else if ($group){
115
+ $storeIds = Mage::app()->getGroup($group)->getStoreIds();
116
+ $collection->addFieldToFilter('store_id', array('in' => $storeIds));
117
+ }
118
+
119
+ $collection->load();
120
+ return $collection->getFirstItem();
121
+ }
122
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Rfm.php ADDED
@@ -0,0 +1,200 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 = $this->_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
+ $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
132
+
133
+ $select = $collection->getSelect()
134
+ ->reset(Zend_Db_Select::COLUMNS)
135
+ ->columns(array(
136
+ 'customer_total_orders' => "count(*)",
137
+ ))->order('customer_total_orders');
138
+ $values = $conn->fetchCol($select);
139
+ $this->_resultCount = count($values);
140
+ $this->rfm[self::FREQUENCY] = $this->calculateQuartile($values);
141
+
142
+ $select = $collection->getSelect()
143
+ ->reset(Zend_Db_Select::COLUMNS)
144
+ ->reset(Zend_Db_Select::ORDER)
145
+ ->columns(array(
146
+ 'last_order_days_ago' => "DATEDIFF(date(NOW()) , date(MAX(created_at)))"
147
+ ))->order('last_order_days_ago');
148
+ $values = $conn->fetchCol($select);
149
+ $this->rfm[self::RECENCY] = $this->calculateQuartile($values);
150
+
151
+ $expr = $this->_getSalesAmountExpression($collection);
152
+ $select = $collection->getSelect()
153
+ ->reset(Zend_Db_Select::COLUMNS)
154
+ ->reset(Zend_Db_Select::ORDER)
155
+ ->columns(array(
156
+ 'customer_average_order_value' => "SUM({$expr})/count(*)",
157
+ ))->order('customer_average_order_value');
158
+ $values = $conn->fetchCol($select);
159
+ $this->rfm[self::MONETARY] = $this->calculateQuartile($values);
160
+ }
161
+
162
+
163
+ protected function _getSalesAmountExpression($collection)
164
+ {
165
+ $adapter = $collection->getConnection();
166
+ $expressionTransferObject = new Varien_Object(array(
167
+ 'expression' => '%s - %s - %s - (%s - %s - %s)',
168
+ 'arguments' => array(
169
+ $adapter->getIfNullSql('main_table.base_total_invoiced', 0),
170
+ $adapter->getIfNullSql('main_table.base_tax_invoiced', 0),
171
+ $adapter->getIfNullSql('main_table.base_shipping_invoiced', 0),
172
+ $adapter->getIfNullSql('main_table.base_total_refunded', 0),
173
+ $adapter->getIfNullSql('main_table.base_tax_refunded', 0),
174
+ $adapter->getIfNullSql('main_table.base_shipping_refunded', 0),
175
+ )
176
+ ));
177
+
178
+ return vsprintf(
179
+ $expressionTransferObject->getExpression(),
180
+ $expressionTransferObject->getArguments()
181
+ );
182
+
183
+ }
184
+
185
+ /**
186
+ * @param int $store
187
+ * @param int $website
188
+ * @param int $group
189
+ * @return array
190
+ */
191
+ public function getPreparedRfm($store = 0, $website = 0, $group =0)
192
+ {
193
+ $this->_store = $store;
194
+ $this->_group = $group;
195
+ $this->_website = $website;
196
+
197
+ $this->prepareRfm();
198
+ return $this->rfm;
199
+ }
200
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Subscriber.php ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Tabs_Analysis_Subscriber extends Mage_Core_Model_Abstract
4
+ {
5
+ protected $storeIds;
6
+
7
+ protected function calculateOperationalDaysFromOrder()
8
+ {
9
+ $collection = Mage::getResourceModel('sales/order_collection');
10
+ $collection->addFieldToSelect('created_at');
11
+
12
+ if (is_array($this->storeIds) && !empty($this->storeIds)) {
13
+ $collection->addFieldToFilter('store_id', array('in' => $this->storeIds));
14
+ }
15
+
16
+ $collection->getSelect()->columns(array(
17
+ 'days' => "DATEDIFF(date(NOW()) , date(MIN(created_at)))"
18
+ ));
19
+ return $collection->getFirstItem()->getDays();
20
+ }
21
+
22
+ protected function _getCollection(){
23
+ $collection = Mage::getResourceModel('newsletter/subscriber_collection');
24
+ $collection->addFieldToFilter('subscriber_status', array('neq' => '3'));
25
+
26
+ if (is_array($this->storeIds) && !empty($this->storeIds)) {
27
+ $collection->addFieldToFilter('store_id', array('in' => $this->storeIds));
28
+ }
29
+ return $collection;
30
+ }
31
+
32
+ /**
33
+ * prepare collection
34
+ *
35
+ * @return Varien_Object
36
+ */
37
+ protected function getPreparedCollection()
38
+ {
39
+ //all active subscribers
40
+ $collection = $this->_getCollection();
41
+ $totalSubscribers = $collection->count();
42
+
43
+ //all active subscribers who are also customers
44
+ $customerSubscribers = $this->_getCollection();
45
+ $customerSubscribers->addFieldToFilter('customer_id', array('neq' => '0'));
46
+ $customerSubscriberCount = $customerSubscribers->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->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::helper('ddg')->getOrderTableDescription();
12
+
13
+ $customFields = array();
14
+ foreach($fields as $key => $field){
15
+ $customFields[] = array(
16
+ 'value' => $field['COLUMN_NAME'],
17
+ 'label' => $field['COLUMN_NAME']
18
+ );
19
+ }
20
+ return $customFields;
21
+ }
22
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Frequency.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Advanced_Frequency
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ return array(
8
+ array('value' => '1', 'label' => Mage::helper('ddg')->__('1 Hour')),
9
+ array('value' => '2', 'label' => Mage::helper('ddg')->__('2 Hours')),
10
+ array('value' => '6', 'label' => Mage::helper('ddg')->__('6 Hours')),
11
+ array('value' => '12', 'label' => Mage::helper('ddg')->__('12 Hours')),
12
+ array('value' => '24', 'label' => Mage::helper('ddg')->__('24 Hours'))
13
+ );
14
+ }
15
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Quoteattributes.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Advanced_Quoteattributes
4
+ {
5
+ /**
6
+ * @return array
7
+ */
8
+ public function toOptionArray()
9
+ {
10
+ $fields = Mage::helper('ddg')->getQuoteTableDescription();
11
+
12
+ $customFields = array();
13
+ foreach($fields as $key => $field){
14
+ $customFields[] = array(
15
+ 'value' => $field['COLUMN_NAME'],
16
+ 'label' => $field['COLUMN_NAME']
17
+ );
18
+ }
19
+ return $customFields;
20
+ }
21
+ }
app/code/{local/Dotdigitalgroup/Email/Model/System/Config/Source/Orderlimit.php → community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Transdata.php} RENAMED
@@ -1,6 +1,6 @@
1
  <?php
2
 
3
- class Dotdigitalgroup_Email_Model_System_Config_Source_Orderlimit
4
  {
5
  /**
6
  * @return array
1
  <?php
2
 
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Advanced_Transdata
4
  {
5
  /**
6
  * @return array
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Automation/Programme.php ADDED
@@ -0,0 +1,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,466 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $coreResource = Mage::getSingleton('core/resource');
59
+ $write = $coreResource->getConnection('core_write');
60
+ $contactTable = $coreResource->getTableName('ddg_automation/contact');
61
+ $select = $write->select();
62
+
63
+
64
+ //skip if the mapping field is missing
65
+ if ( !$helper->getCustomerAddressBook($website))
66
+ return 0;
67
+
68
+ $fileHelper = Mage::helper('ddg/file');
69
+ $contactModel = Mage::getModel('ddg_automation/contact');
70
+ $contacts = $contactModel->getContactsToImportForWebsite($website->getId(), $pageSize);
71
+
72
+ // no contacts for this website
73
+ if (!$contacts->getSize())
74
+ return 0;
75
+
76
+ //create customer filename
77
+ $customersFile = strtolower($website->getCode() . '_customers_' . date('d_m_Y_Hi') . '.csv');
78
+ $helper->log('Customers file : ' . $customersFile);
79
+
80
+ //get customer ids
81
+ $customerIds = $contacts->getColumnValues('customer_id');
82
+
83
+ //customer collection
84
+ $customerCollection = $this->getCollection($customerIds, $website->getId());
85
+
86
+ /**
87
+ * HEADERS.
88
+ */
89
+ $mappedHash = $fileHelper->getWebsiteCustomerMappingDatafields($website);
90
+ $headers = $mappedHash;
91
+
92
+ //custom customer attributes
93
+ $customAttributes = $helper->getCustomAttributes($website);
94
+ if ($customAttributes){
95
+ foreach ($customAttributes as $data) {
96
+ $headers[] = $data['datafield'];
97
+ $allMappedHash[$data['attribute']] = $data['datafield'];
98
+ }
99
+ }
100
+ $headers[] = 'Email';
101
+ $headers[] = 'EmailType';
102
+ $fileHelper->outputCSV($fileHelper->getFilePath($customersFile), $headers);
103
+ /**
104
+ * END HEADERS.
105
+ */
106
+
107
+ //only execute once despite number of websites
108
+ if(!$this->_sqlExecuted){
109
+ //check subscriber and update in one query
110
+ $select->joinLeft(
111
+ array('s' => $coreResource->getTableName('newsletter/subscriber')),
112
+ "c.customer_id = s.customer_id",
113
+ array('subscriber_status' => 's.subscriber_status')
114
+ );
115
+ //update sql statement
116
+ $updateSql = $select->crossUpdateFromSelect(array('c' => $contactTable));
117
+ //run query and update subscriber_status column
118
+ $write->query($updateSql);
119
+ //update is_subscriber column if subscriber_status is not null
120
+ $write->update($contactTable, array('is_subscriber' => 1), "subscriber_status is not null");
121
+
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' => $coreResource->getTableName('customer_entity')),
131
+ "c.customer_id = e.entity_id"
132
+ )
133
+ ->where('e.entity_id is NULL');
134
+ //delete sql statement
135
+ $deleteSql = $select->deleteFromSelect('c');
136
+ //run query
137
+ $write->query($deleteSql);
138
+
139
+ //set flag
140
+ $this->_sqlExecuted = true;
141
+ }
142
+
143
+ //customer data
144
+ foreach ($customerCollection as $customer) {
145
+ $connectorCustomer = Mage::getModel('ddg_automation/apiconnector_customer', $mappedHash);
146
+ $connectorCustomer->setCustomerData($customer);
147
+ //count number of customers
148
+ $customers[] = $customer->getId();
149
+
150
+ if ($connectorCustomer) {
151
+ foreach ($customAttributes as $data) {
152
+ $attribute = $data['attribute'];
153
+ $value = $customer->getData($attribute);
154
+ $connectorCustomer->setData($value);
155
+ }
156
+ }
157
+
158
+ //contact email and email type
159
+ $connectorCustomer->setData($customer->getEmail());
160
+ $connectorCustomer->setData('Html');
161
+ // save csv file data for customers
162
+ $fileHelper->outputCSV($fileHelper->getFilePath($customersFile), $connectorCustomer->toCSVArray());
163
+ //clear collection and free memory
164
+ $customer->clearInstance();
165
+ }
166
+
167
+ $customerNum = count($customers);
168
+ $helper->log('Website : ' . $website->getName() . ', customers = ' . $customerNum);
169
+ $helper->log('---------------------------- execution time :' . gmdate("H:i:s", microtime(true) - $this->_start));
170
+
171
+ if (is_file($fileHelper->getFilePath($customersFile))) {
172
+ if ($customerNum > 0) {
173
+ //register in queue with importer
174
+ $check = Mage::getModel('ddg_automation/importer')->registerQueue(
175
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_CONTACT,
176
+ '',
177
+ Dotdigitalgroup_Email_Model_Importer::MODE_BULK,
178
+ $website->getId(),
179
+ $customersFile
180
+ );
181
+
182
+ //set imported
183
+ if ($check) {
184
+ $tableName = Mage::getSingleton('core/resource')->getTableName('email_contact');
185
+ $ids = implode(', ', $customers);
186
+ $write->update($tableName, array('email_imported' => 1), "customer_id IN ($ids)");
187
+ }
188
+ }
189
+ }
190
+ $this->_countCustomers += $customerNum;
191
+ return $customerNum;
192
+ }
193
+
194
+ /**
195
+ * Sync a single contact.
196
+ *
197
+ * @param null $contactId
198
+ *
199
+ * @return mixed
200
+ * @throws Mage_Core_Exception
201
+ */
202
+ public function syncContact($contactId = null)
203
+ {
204
+ if ($contactId)
205
+ $contact = Mage::getModel('ddg_automation/contact')->load($contactId);
206
+ else {
207
+ $contact = Mage::registry('current_contact');
208
+ }
209
+ if (! $contact->getId()) {
210
+ Mage::getSingleton('adminhtml/session')->addError('No contact found!');
211
+ return false;
212
+ }
213
+
214
+ $websiteId = $contact->getWebsiteId();
215
+ $website = Mage::app()->getWebsite($websiteId);
216
+ $updated = 0;
217
+ $customers = $headers = $allMappedHash = array();
218
+ $helper = Mage::helper('ddg');
219
+ $helper->log('---------- Start single customer sync ----------');
220
+ //skip if the mapping field is missing
221
+ if(!$helper->getCustomerAddressBook($website))
222
+ return false;
223
+ $fileHelper = Mage::helper('ddg/file');
224
+
225
+ $customerId = $contact->getCustomerId();
226
+ if (!$customerId) {
227
+ Mage::getSingleton('adminhtml/session')->addError('Cannot manually sync guests!');
228
+ return false;
229
+ }
230
+ $client = Mage::helper('ddg')->getWebsiteApiClient($website);
231
+
232
+ //create customer filename
233
+ $customersFile = strtolower($website->getCode() . '_customers_' . date('d_m_Y_Hi') . '.csv');
234
+ $helper->log('Customers file : ' . $customersFile);
235
+
236
+ /**
237
+ * HEADERS.
238
+ */
239
+ $mappedHash = $fileHelper->getWebsiteCustomerMappingDatafields($website);
240
+ $headers = $mappedHash;
241
+ //custom customer attributes
242
+ $customAttributes = $helper->getCustomAttributes($website);
243
+ foreach ($customAttributes as $data) {
244
+ $headers[] = $data['datafield'];
245
+ $allMappedHash[$data['attribute']] = $data['datafield'];
246
+ }
247
+
248
+ $headers[] = 'Email';
249
+ $headers[] = 'EmailType';
250
+ $fileHelper->outputCSV($fileHelper->getFilePath($customersFile), $headers);
251
+ /**
252
+ * END HEADERS.
253
+ */
254
+ $customerCollection = $this->getCollection(array($customerId), $website->getId());
255
+
256
+ foreach ($customerCollection as $customer) {
257
+ $contactModel = Mage::getModel('ddg_automation/contact')->loadByCustomerEmail($customer->getEmail(), $websiteId);
258
+ //skip contacts without customer id
259
+ if (!$contactModel->getId())
260
+ continue;
261
+ /**
262
+ * DATA.
263
+ */
264
+ $connectorCustomer = Mage::getModel('ddg_automation/apiconnector_customer', $mappedHash);
265
+ $connectorCustomer->setCustomerData($customer);
266
+ //count number of customers
267
+ $customers[] = $connectorCustomer;
268
+ foreach ($customAttributes as $data) {
269
+ $attribute = $data['attribute'];
270
+ $value = $customer->getData($attribute);
271
+ $connectorCustomer->setData($value);
272
+ }
273
+ //contact email and email type
274
+ $connectorCustomer->setData($customer->getEmail());
275
+ $connectorCustomer->setData('Html');
276
+ // save csv file data for customers
277
+ $fileHelper->outputCSV($fileHelper->getFilePath($customersFile), $connectorCustomer->toCSVArray());
278
+
279
+ /**
280
+ * END DATA.
281
+ */
282
+
283
+ //mark the contact as imported
284
+ $contactModel->setEmailImported(Dotdigitalgroup_Email_Model_Contact::EMAIL_CONTACT_IMPORTED);
285
+ $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($customer->getEmail());
286
+ if ($subscriber->isSubscribed()) {
287
+ $contactModel->setIsSubscriber('1')
288
+ ->setSubscriberStatus($subscriber->getSubscriberStatus());
289
+ }
290
+
291
+ $contactModel->save();
292
+ $updated++;
293
+ }
294
+
295
+ if (is_file($fileHelper->getFilePath($customersFile))) {
296
+ //import contacts
297
+ if ($updated > 0) {
298
+ //register in queue with importer
299
+ Mage::getModel('ddg_automation/importer')->registerQueue(
300
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_CONTACT,
301
+ '',
302
+ Dotdigitalgroup_Email_Model_Importer::MODE_BULK,
303
+ $website->getId(),
304
+ $customersFile
305
+ );
306
+ $client->postAddressBookContactsImport($customersFile, $helper->getCustomerAddressBook($website));
307
+ }
308
+ }
309
+ return $contact->getEmail();
310
+ }
311
+
312
+
313
+ /**
314
+ * get customer collection
315
+ * @param $customerIds
316
+ * @param $websiteId
317
+ * @return Mage_Eav_Model_Entity_Collection_Abstract
318
+ * @throws Mage_Core_Exception
319
+ */
320
+ public function getCollection($customerIds, $websiteId = 0)
321
+ {
322
+ $customerCollection = Mage::getResourceModel('customer/customer_collection')
323
+ ->addNameToSelect()
324
+ ->addAttributeToSelect('*')
325
+ ->joinAttribute('billing_street', 'customer_address/street', 'default_billing', null, 'left')
326
+ ->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
327
+ ->joinAttribute('billing_country_code', 'customer_address/country_id', 'default_billing', null, 'left')
328
+ ->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
329
+ ->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')
330
+ ->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
331
+ ->joinAttribute('shipping_street', 'customer_address/street', 'default_shipping', null, 'left')
332
+ ->joinAttribute('shipping_city', 'customer_address/city', 'default_shipping', null, 'left')
333
+ ->joinAttribute('shipping_country_code','customer_address/country_id', 'default_shipping', null, 'left')
334
+ ->joinAttribute('shipping_postcode', 'customer_address/postcode', 'default_shipping', null, 'left')
335
+ ->joinAttribute('shipping_telephone', 'customer_address/telephone', 'default_shipping', null, 'left')
336
+ ->joinAttribute('shipping_region', 'customer_address/region', 'default_shipping', null, 'left')
337
+ ->addAttributeToFilter('entity_id', array('in' => $customerIds));
338
+ $customer_log = Mage::getSingleton('core/resource')->getTableName('log_customer');
339
+ $sales_flat_order_grid = Mage::getSingleton('core/resource')->getTableName('sales_flat_order_grid');
340
+ $sales_flat_quote = Mage::getSingleton('core/resource')->getTableName('sales_flat_quote');
341
+ $sales_flat_order = Mage::getSingleton('core/resource')->getTableName('sales_flat_order');
342
+ $sales_flat_order_item = Mage::getSingleton('core/resource')->getTableName('sales_flat_order_item');
343
+ $catalog_category_product_index = Mage::getSingleton('core/resource')->getTableName('catalog_category_product');
344
+ $eav_attribute_option_value = Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value');
345
+ $catalog_product_entity_int = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int');
346
+ $eav_attribute = Mage::getSingleton('core/resource')->getTableName('eav_attribute');
347
+
348
+
349
+ // get the last login date from the log_customer table
350
+ $customerCollection->getSelect()->columns(
351
+ 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)")));
352
+
353
+ // customer order information
354
+ $alias = 'subselect';
355
+ $statuses = Mage::helper('ddg')->getWebsiteConfig(
356
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_DATA_FIELDS_STATUS, $websiteId
357
+ );
358
+ $subselect = Mage::getModel('Varien_Db_Select', Mage::getSingleton('core/resource')->getConnection('core_read'))
359
+ ->from($sales_flat_order_grid, array(
360
+ 'customer_id as s_customer_id',
361
+ 'sum(grand_total) as total_spend',
362
+ 'count(*) as number_of_orders',
363
+ 'avg(grand_total) as average_order_value',
364
+ )
365
+ )
366
+ ->where("status in (?)", $statuses)
367
+ ->group('customer_id')
368
+ ;
369
+ $customerCollection->getSelect()->columns(array(
370
+ '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)"),
371
+ '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)"),
372
+ '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)"),
373
+ '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)"),
374
+ 'first_category_id' => new Zend_Db_Expr(
375
+ "(
376
+ SELECT ccpi.category_id FROM $sales_flat_order as sfo
377
+ left join $sales_flat_order_item as sfoi on sfoi.order_id = sfo.entity_id
378
+ left join $catalog_category_product_index as ccpi on ccpi.product_id = sfoi.product_id
379
+ WHERE sfo.customer_id = e.entity_id
380
+ ORDER BY sfo.created_at ASC, sfoi.price DESC
381
+ LIMIT 1
382
+ )"
383
+ ),
384
+ 'last_category_id' => new Zend_Db_Expr(
385
+ "(
386
+ SELECT ccpi.category_id FROM $sales_flat_order as sfo
387
+ left join $sales_flat_order_item as sfoi on sfoi.order_id = sfo.entity_id
388
+ left join $catalog_category_product_index as ccpi on ccpi.product_id = sfoi.product_id
389
+ WHERE sfo.customer_id = e.entity_id
390
+ ORDER BY sfo.created_at DESC, sfoi.price DESC
391
+ LIMIT 1
392
+ )"
393
+ ),
394
+ 'product_id_for_first_brand' => new Zend_Db_Expr(
395
+ "(
396
+ SELECT sfoi.product_id FROM $sales_flat_order as sfo
397
+ left join $sales_flat_order_item as sfoi on sfoi.order_id = sfo.entity_id
398
+ WHERE sfo.customer_id = e.entity_id and sfoi.product_type = 'simple'
399
+ ORDER BY sfo.created_at ASC, sfoi.price DESC
400
+ LIMIT 1
401
+ )"
402
+ ),
403
+ 'product_id_for_last_brand' => new Zend_Db_Expr(
404
+ "(
405
+ SELECT sfoi.product_id FROM $sales_flat_order as sfo
406
+ left join $sales_flat_order_item as sfoi on sfoi.order_id = sfo.entity_id
407
+ WHERE sfo.customer_id = e.entity_id and sfoi.product_type = 'simple'
408
+ ORDER BY sfo.created_at DESC, sfoi.price DESC
409
+ LIMIT 1
410
+ )"
411
+ ),
412
+ 'week_day' => new Zend_Db_Expr(
413
+ "(
414
+ SELECT dayname(created_at) as week_day
415
+ FROM $sales_flat_order
416
+ WHERE customer_id = e.entity_id
417
+ GROUP BY week_day
418
+ HAVING COUNT(*) > 0
419
+ ORDER BY (COUNT(*)) DESC
420
+ LIMIT 1
421
+ )"
422
+ ),
423
+ 'month_day' => new Zend_Db_Expr(
424
+ "(
425
+ SELECT monthname(created_at) as month_day
426
+ FROM $sales_flat_order
427
+ WHERE customer_id = e.entity_id
428
+ GROUP BY month_day
429
+ HAVING COUNT(*) > 0
430
+ ORDER BY (COUNT(*)) DESC
431
+ LIMIT 1
432
+ )"
433
+ ),
434
+ 'most_category_id' => new Zend_Db_Expr(
435
+ "(
436
+ SELECT ccpi.category_id FROM $sales_flat_order as sfo
437
+ LEFT JOIN $sales_flat_order_item as sfoi on sfoi.order_id = sfo.entity_id
438
+ LEFT JOIN $catalog_category_product_index as ccpi on ccpi.product_id = sfoi.product_id
439
+ WHERE sfo.customer_id = e.entity_id AND ccpi.category_id is not null
440
+ GROUP BY category_id
441
+ HAVING COUNT(sfoi.product_id) > 0
442
+ ORDER BY COUNT(sfoi.product_id) DESC
443
+ LIMIT 1
444
+ )"
445
+ ),
446
+ 'most_brand' => new Zend_Db_Expr(
447
+ "(
448
+ SELECT eaov.value from $sales_flat_order sfo
449
+ LEFT JOIN $sales_flat_order_item as sfoi on sfoi.order_id = sfo.entity_id
450
+ LEFT JOIN $catalog_product_entity_int pei on pei.entity_id = sfoi.product_id
451
+ LEFT JOIN $eav_attribute ea ON pei.attribute_id = ea.attribute_id
452
+ LEFT JOIN $eav_attribute_option_value as eaov on pei.value = eaov.option_id
453
+ WHERE sfo.customer_id = e.entity_id AND ea.attribute_code = 'manufacturer' AND eaov.value is not null
454
+ GROUP BY eaov.value
455
+ HAVING count(*) > 0
456
+ ORDER BY count(*) DESC
457
+ LIMIT 1
458
+ )"
459
+ ),
460
+ )
461
+ );
462
+ $customerCollection->getSelect()
463
+ ->joinLeft(array($alias => $subselect), "{$alias}.s_customer_id = e.entity_id");
464
+ return $customerCollection;
465
+ }
466
+ }
app/code/community/Dotdigitalgroup/Email/Model/Apiconnector/Customer.php ADDED
@@ -0,0 +1,901 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Apiconnector_Customer
4
+ {
5
+
6
+ public $customer;
7
+ public $customerData;
8
+ public $reviewCollection;
9
+
10
+ //enterprise reward
11
+ public $reward;
12
+
13
+ public $rewardCustomer;
14
+ public $rewardLastSpent = "";
15
+ public $rewardLastEarned = "";
16
+ public $rewardExpiry = "";
17
+
18
+ protected $_mapping_hash;
19
+
20
+ private $subscriber_status = array(
21
+ Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED => 'Subscribed',
22
+ Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE => 'Not Active',
23
+ Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED => 'Unsubscribed',
24
+ Mage_Newsletter_Model_Subscriber::STATUS_UNCONFIRMED => 'Unconfirmed'
25
+ );
26
+
27
+ /**
28
+ * constructor, mapping hash to map.
29
+ *
30
+ * @param $mappingHash
31
+ */
32
+ public function __construct( $mappingHash)
33
+ {
34
+ $this->setMappigHash($mappingHash);
35
+ }
36
+
37
+ /**
38
+ * Set key value data.
39
+ *
40
+ * @param $data
41
+ */
42
+ public function setData($data)
43
+ {
44
+ $this->customerData[] = $data;
45
+ }
46
+
47
+ /**
48
+ * Set customer data.
49
+ *
50
+ * @param Mage_Customer_Model_Customer $customer
51
+ */
52
+ public function setCustomerData(Mage_Customer_Model_Customer $customer)
53
+ {
54
+ $this->customer = $customer;
55
+ $this->setReviewCollection();
56
+ $website = $customer->getStore()->getWebsite();
57
+
58
+ if ($website && Mage::helper('ddg')->isSweetToothToGo($website))
59
+ $this->setRewardCustomer($customer);
60
+
61
+ foreach ($this->getMappingHash() as $key => $field) {
62
+
63
+ /**
64
+ * call user function based on the attribute mapped.
65
+ */
66
+ $function = 'get';
67
+ $exploded = explode('_', $key);
68
+ foreach ($exploded as $one) {
69
+ $function .= ucfirst($one);
70
+ }
71
+ try{
72
+ $value = call_user_func(array('self', $function));
73
+ $this->customerData[$key] = $value;
74
+ }catch (Exception $e){
75
+ Mage::logException($e);
76
+ }
77
+ }
78
+ }
79
+
80
+ public function setReviewCollection()
81
+ {
82
+ $customer_id = $this->customer->getId();
83
+ $collection = Mage::getModel('review/review')->getCollection()
84
+ ->addCustomerFilter($customer_id)
85
+ ->setOrder('review_id','DESC');
86
+ $this->reviewCollection = $collection;
87
+ }
88
+
89
+ public function getReviewCount()
90
+ {
91
+ return count($this->reviewCollection);
92
+ }
93
+
94
+ public function getLastReviewDate(){
95
+ if(count($this->reviewCollection))
96
+ return $this->reviewCollection->getFirstItem()->getCreatedAt();
97
+ return '';
98
+ }
99
+
100
+ /**
101
+ * Set reward customer
102
+ *
103
+ * @param Mage_Customer_Model_Customer $customer
104
+ */
105
+ public function setRewardCustomer(Mage_Customer_Model_Customer $customer)
106
+ {
107
+ //get tbt reward customer
108
+ $tbt_reward = Mage::getModel('rewards/customer')->getRewardsCustomer($customer);
109
+ $this->rewardCustomer = $tbt_reward;
110
+
111
+ //get transfers collection from tbt reward. only active and order by last updated.
112
+ $lastTransfers = $tbt_reward->getTransfers()
113
+ ->selectOnlyActive()
114
+ ->addOrder('last_update_ts', Varien_Data_Collection::SORT_ORDER_DESC);
115
+
116
+ $spent = $earn = null;
117
+
118
+ foreach($lastTransfers as $transfer) {
119
+ // if transfer quantity is greater then 0 then this is last points earned date. keep checking until earn is not null
120
+ if(is_null($earn) && $transfer->getQuantity() > 0){
121
+ $earn = $transfer->getEffectiveStart();
122
+ }
123
+ // id transfer quantity is less then 0 then this is last points spent date. keep checking until spent is not null
124
+ else if(is_null($spent) && $transfer->getQuantity() < 0) {
125
+ $spent = $transfer->getEffectiveStart();
126
+ }
127
+ // break if both spent and earn are not null (a value has been assigned)
128
+ if(!is_null($spent) && !is_null($earn)) {
129
+ break;
130
+ }
131
+ }
132
+
133
+ // if earn is not null (has a value) then assign the value to property
134
+ if($earn)
135
+ $this->rewardLastEarned = $earn;
136
+ // if spent is not null (has a value) then assign the value to property
137
+ if($spent)
138
+ $this->rewardLastSpent = $spent;
139
+
140
+ $tbt_expiry = Mage::getSingleton('rewards/expiry')
141
+ ->getExpiryDate($tbt_reward);
142
+
143
+ // if there is an expiry (has a value) then assign the value to property
144
+ if($tbt_expiry)
145
+ $this->rewardExpiry = $tbt_expiry;
146
+ }
147
+
148
+ /**
149
+ * get customer id.
150
+ *
151
+ * @return mixed
152
+ */
153
+ public function getCustomerId()
154
+ {
155
+ return $this->customer->getId();
156
+ }
157
+
158
+ /**
159
+ * get first name.
160
+ *
161
+ * @return mixed
162
+ */
163
+ public function getFirstname(){
164
+ return $this->customer->getFirstname();
165
+ }
166
+
167
+ /**
168
+ * get last name.
169
+ *
170
+ * @return mixed
171
+ */
172
+ public function getLastname()
173
+ {
174
+ return $this->customer->getLastname();
175
+ }
176
+
177
+ /**
178
+ * get date of birth.
179
+ *
180
+ * @return mixed
181
+ */
182
+ public function getDob()
183
+ {
184
+ return $this->customer->getDob();
185
+ }
186
+
187
+ /**
188
+ * get customer gender.
189
+ *
190
+ * @return bool|string
191
+ */
192
+ public function getGender()
193
+ {
194
+ return $this->_getCustomerGender();
195
+ }
196
+
197
+ /**
198
+ * get customer prefix.
199
+ *
200
+ * @return mixed
201
+ */
202
+ public function getPrefix()
203
+ {
204
+ return $this->customer->getPrefix();
205
+ }
206
+
207
+ /**
208
+ * get customer suffix.
209
+ *
210
+ * @return mixed
211
+ */
212
+ public function getSuffix()
213
+ {
214
+ return $this->customer->getSuffix();
215
+ }
216
+
217
+ /**
218
+ * get website name.
219
+ *
220
+ * @return string
221
+ */
222
+ public function getWebsiteName()
223
+ {
224
+ return $this->_getWebsiteName();
225
+ }
226
+
227
+ /**
228
+ * get store name.
229
+ *
230
+ * @return null|string
231
+ */
232
+ public function getStoreName()
233
+ {
234
+ return $this->_getStoreName();
235
+ }
236
+
237
+ /**
238
+ * get customer created at date.
239
+ *
240
+ * @return mixed
241
+ */
242
+ public function getCreatedAt()
243
+ {
244
+ return $this->customer->getCreatedAt();
245
+ }
246
+
247
+ /**
248
+ * get customer last logged in date.
249
+ *
250
+ * @return mixed
251
+ */
252
+ public function getLastLoggedDate()
253
+ {
254
+ return $this->customer->getLastLoggedDate();
255
+ }
256
+
257
+ /**
258
+ * get cutomer group.
259
+ *
260
+ * @return string
261
+ */
262
+ public function getCustomerGroup()
263
+ {
264
+ return $this->_getCustomerGroup();
265
+ }
266
+
267
+ /**
268
+ * get billing address line 1.
269
+ *
270
+ * @return string
271
+ */
272
+ public function getBillingAddress1()
273
+ {
274
+ return $this->_getStreet($this->customer->getBillingStreet(), 1);
275
+ }
276
+
277
+ /**
278
+ * get billing address line 2.
279
+ *
280
+ * @return string
281
+ */
282
+ public function getBillingAddress2()
283
+ {
284
+ return $this->_getStreet($this->customer->getBillingStreet(), 2);
285
+ }
286
+
287
+ /**
288
+ * get billing city.
289
+ *
290
+ * @return mixed
291
+ */
292
+ public function getBillingCity()
293
+ {
294
+ return $this->customer->getBillingCity();
295
+ }
296
+
297
+ /**
298
+ * get billing country.
299
+ *
300
+ * @return mixed
301
+ */
302
+ public function getBillingCountry()
303
+ {
304
+ return $this->customer->getBillingCountryCode();
305
+ }
306
+
307
+ /**
308
+ * get billing state.
309
+ *
310
+ * @return mixed
311
+ */
312
+ public function getBillingState()
313
+ {
314
+ return $this->customer->getBillingRegion();
315
+ }
316
+
317
+ /**
318
+ * get billing postcode.
319
+ *
320
+ * @return mixed
321
+ */
322
+ public function getBillingPostcode()
323
+ {
324
+ return $this->customer->getBillingPostcode();
325
+ }
326
+
327
+ /**
328
+ * get billing phone.
329
+ *
330
+ * @return mixed
331
+ */
332
+ public function getBillingTelephone()
333
+ {
334
+ return $this->customer->getBillingTelephone();
335
+ }
336
+
337
+ /**
338
+ * get delivery address line 1.
339
+ *
340
+ * @return string
341
+ */
342
+ public function getDeliveryAddress1()
343
+ {
344
+ return $this->_getStreet($this->customer->getShippingStreet(), 1);
345
+ }
346
+
347
+ /**
348
+ * get delivery addrss line 2.
349
+ *
350
+ * @return string
351
+ */
352
+ public function getDeliveryAddress2()
353
+ {
354
+ return $this->_getStreet($this->customer->getShippingStreet(), 2);
355
+ }
356
+
357
+ /**
358
+ * get delivery city.
359
+ *
360
+ * @return mixed
361
+ */
362
+ public function getDeliveryCity()
363
+ {
364
+ return $this->customer->getShippingCity();
365
+ }
366
+
367
+ /**
368
+ * get delivery country.
369
+ *
370
+ * @return mixed
371
+ */
372
+ public function getDeliveryCountry(){
373
+ return $this->customer->getShippingCountryCode();
374
+ }
375
+
376
+ /**
377
+ * get delivery state.
378
+ *
379
+ * @return mixed
380
+ */
381
+ public function getDeliveryState()
382
+ {
383
+ return $this->customer->getShippingRegion();
384
+ }
385
+
386
+ /**
387
+ * get delivery postcode.
388
+ *
389
+ * @return mixed
390
+ */
391
+ public function getDeliveryPostcode()
392
+ {
393
+ return $this->customer->getShippingPostcode();
394
+ }
395
+
396
+ /**
397
+ * get delivery phone.
398
+ *
399
+ * @return mixed
400
+ */
401
+ public function getDeliveryTelephone(){
402
+ return $this->customer->getShippingTelephone();
403
+ }
404
+
405
+ /**
406
+ * get numbser of orders.
407
+ *
408
+ * @return mixed
409
+ */
410
+ public function getNumberOfOrders()
411
+ {
412
+ return $this->customer->getNumberOfOrders();
413
+ }
414
+
415
+ /**
416
+ * get average order value.
417
+ *
418
+ * @return mixed
419
+ */
420
+ public function getAverageOrderValue()
421
+ {
422
+ return $this->customer->getAverageOrderValue();
423
+ }
424
+
425
+ /**
426
+ * get total spend.
427
+ *
428
+ * @return mixed
429
+ */
430
+ public function getTotalSpend()
431
+ {
432
+ return $this->customer->getTotalSpend();
433
+ }
434
+
435
+ /**
436
+ * get last order date.
437
+ *
438
+ * @return mixed
439
+ */
440
+ public function getLastOrderDate()
441
+ {
442
+ return $this->customer->getLastOrderDate();
443
+ }
444
+
445
+ /**
446
+ * get last order id.
447
+ *
448
+ * @return mixed
449
+ */
450
+ public function getLastOrderId()
451
+ {
452
+ return $this->customer->getLastOrderId();
453
+ }
454
+
455
+ /**
456
+ * get last quote id.
457
+ *
458
+ * @return mixed
459
+ */
460
+ public function getLastQuoteId()
461
+ {
462
+ return $this->customer->getLastQuoteId();
463
+ }
464
+
465
+ /**
466
+ * get cutomer id.
467
+ *
468
+ * @return mixed
469
+ */
470
+ public function getId()
471
+ {
472
+ return $this->customer->getId();
473
+ }
474
+
475
+ /**
476
+ * get customer title.
477
+ *
478
+ * @return mixed
479
+ */
480
+ public function getTitle()
481
+ {
482
+ return $this->customer->getPrefix();
483
+ }
484
+
485
+ /**
486
+ * get total refund value.
487
+ *
488
+ * @return float|int
489
+ */
490
+ public function getTotalRefund()
491
+ {
492
+ $orders = Mage::getResourceModel('sales/order_collection')
493
+ ->addAttributeToFilter('customer_id', $this->customer->getId())
494
+ ;
495
+ $totalRefunded = 0;
496
+ foreach ($orders as $order) {
497
+ $refunded = $order->getTotalRefunded();
498
+ $totalRefunded += $refunded;
499
+ }
500
+
501
+ return $totalRefunded;
502
+ }
503
+
504
+ /**
505
+ * export to CSV.
506
+ *
507
+ * @return mixed
508
+ */
509
+ public function toCSVArray()
510
+ {
511
+ $result = $this->customerData;
512
+ return $result;
513
+ }
514
+
515
+ /**
516
+ * customer gender.
517
+ *
518
+ * @return bool|string
519
+ * @throws Mage_Core_Exception
520
+ */
521
+ private function _getCustomerGender()
522
+ {
523
+ $genderId = $this->customer->getGender();
524
+ if (is_numeric($genderId)) {
525
+ $gender = Mage::getResourceModel('customer/customer')
526
+ ->getAttribute('gender')
527
+ ->getSource()
528
+ ->getOptionText($genderId)
529
+ ;
530
+ return $gender;
531
+ }
532
+
533
+ return '';
534
+ }
535
+
536
+ private function _getStreet($street, $line){
537
+ $street = explode("\n", $street);
538
+ if(isset($street[$line - 1]))
539
+ return $street[$line - 1];
540
+ return '';
541
+ }
542
+
543
+ private function _getWebsiteName(){
544
+ $websiteId = $this->customer->getWebsiteId();
545
+ $website = Mage::app()->getWebsite($websiteId);
546
+ if($website)
547
+ return $website->getName();
548
+
549
+ return '';
550
+ }
551
+
552
+ private function _getStoreName()
553
+ {
554
+ $storeId = $this->customer->getStoreId();
555
+ $store = Mage::app()->getStore($storeId);
556
+ if($store)
557
+ return $store->getName();
558
+
559
+ return '';
560
+ }
561
+
562
+ /**
563
+ * @param mixed $mapping_hash
564
+ */
565
+ public function setMappingHash($mapping_hash)
566
+ {
567
+ $this->_mapping_hash = $mapping_hash;
568
+ }
569
+
570
+ /**
571
+ * @return mixed
572
+ */
573
+ public function getMappingHash()
574
+ {
575
+ return $this->_mapping_hash;
576
+ }
577
+
578
+ private function _getCustomerGroup(){
579
+ $groupId = $this->customer->getGroupId();
580
+ $group = Mage::getModel('customer/group')->load($groupId);
581
+ if($group){
582
+ return $group->getCode();
583
+ }
584
+ return '';
585
+ }
586
+
587
+ /**
588
+ * mapping hash value.
589
+ *
590
+ * @param $value
591
+ *
592
+ * @return $this
593
+ */
594
+ public function setMappigHash($value)
595
+ {
596
+ $this->_mapping_hash = $value;
597
+ return $this;
598
+ }
599
+
600
+ public function getRewardReferralUrl()
601
+ {
602
+ if(Mage::helper('ddg')->isSweetToothToGo($this->customer->getStore()->getWebsite()))
603
+ return (string) Mage::helper('rewardsref/url')->getUrl($this->customer);
604
+
605
+ return '';
606
+ }
607
+
608
+ public function getRewardPointBalance()
609
+ {
610
+ return $this->cleanString($this->rewardCustomer->getPointsSummary());
611
+ }
612
+
613
+ public function getRewardPointPending()
614
+ {
615
+ return $this->cleanString($this->rewardCustomer->getPendingPointsSummary());
616
+ }
617
+
618
+ public function getRewardPointPendingTime()
619
+ {
620
+ return $this->cleanString($this->rewardCustomer->getPendingTimePointsSummary());
621
+ }
622
+
623
+ public function getRewardPointOnHold()
624
+ {
625
+ return $this->cleanString($this->rewardCustomer->getOnHoldPointsSummary());
626
+ }
627
+
628
+ public function getRewardPointExpiration()
629
+ {
630
+ if($this->rewardExpiry != "")
631
+ return Mage::getModel('core/date')->date('Y/m/d', strtotime($this->rewardExpiry));
632
+ return $this->rewardExpiry;
633
+ }
634
+
635
+ public function getRewardPointLastSpent()
636
+ {
637
+ return $this->rewardLastSpent;
638
+ }
639
+
640
+ public function getRewardPointLastEarn()
641
+ {
642
+ return $this->rewardLastEarned;
643
+ }
644
+
645
+ public function cleanString($string)
646
+ {
647
+ $cleanedString = preg_replace("/[^0-9]/","",$string);
648
+ if($cleanedString != "")
649
+ return (int) number_format($cleanedString, 0, '.', '');
650
+ return 0;
651
+ }
652
+
653
+ public function getSubscriberStatus()
654
+ {
655
+ $subscriber = Mage::getModel('newsletter/subscriber')->loadByCustomer($this->customer);
656
+ if($subscriber->getCustomerId())
657
+ return $this->subscriber_status[$subscriber->getSubscriberStatus()];
658
+ }
659
+
660
+ /**
661
+ * Reward points balance.
662
+ * @return int
663
+ */
664
+ public function getRewardPoints() {
665
+ if (!$this->reward)
666
+ $this->_setReward();
667
+ $rewardPoints = $this->reward->getPointsBalance();
668
+
669
+ return $rewardPoints;
670
+ }
671
+
672
+ /**
673
+ * Currency amount points.
674
+ * @return mixed
675
+ */
676
+ public function getRewardAmount() {
677
+ if (!$this->reward)
678
+ $this->_setReward();
679
+
680
+ return $this->reward->getCurrencyAmount();
681
+ }
682
+
683
+ /**
684
+ * Expiration date to use the points.
685
+ * @return string
686
+ */
687
+ public function getExpirationDate()
688
+ {
689
+ //set reward for later use
690
+ if (!$this->reward)
691
+ $this->_setReward();
692
+
693
+
694
+ $expiredAt = $this->reward->getExpirationDate();
695
+
696
+ if ($expiredAt) {
697
+ $date = Mage::helper('core')->formatDate($expiredAt, 'short', true);
698
+ } else {
699
+ $date = '';
700
+ }
701
+
702
+ return $date;
703
+ }
704
+
705
+
706
+ private function _setReward() {
707
+ $collection = Mage::getModel('enterprise_reward/reward_history')->getCollection()
708
+ ->addCustomerFilter($this->customer->getId())
709
+ ->addWebsiteFilter($this->customer->getWebsiteId())
710
+ ->setExpiryConfig(Mage::helper('enterprise_reward')->getExpiryConfig())
711
+ ->addExpirationDate($this->customer->getWebsiteId())
712
+ ->skipExpiredDuplicates()
713
+ ->setDefaultOrder()
714
+ ->getFirstItem()
715
+ ;
716
+
717
+ $this->reward = $collection;
718
+ }
719
+
720
+
721
+ /**
722
+ * Customer segments id.
723
+ * @return string
724
+ */
725
+ public function getCustomerSegments()
726
+ {
727
+ $contactModel = Mage::getModel('ddg_automation/contact')->getCollection()
728
+ ->addFieldToFilter('customer_id', $this->getCustomerId())
729
+ ->addFieldToFilter('website_id', $this->customer->getWebsiteId())
730
+ ->getFirstItem();
731
+ if ($contactModel)
732
+ return $contactModel->getSegmentIds();
733
+
734
+ return '';
735
+ }
736
+
737
+
738
+
739
+ /**
740
+ * Last used reward points.
741
+ * @return mixed
742
+ */
743
+ public function getLastUsedDate()
744
+ {
745
+ //last used from the reward history based on the points delta used
746
+ $lastUsed = Mage::getModel('enterprise_reward/reward_history')->getCollection()
747
+ ->addCustomerFilter($this->customer->getId())
748
+ ->addWebsiteFilter($this->customer->getWebsiteId())
749
+ ->addFieldToFilter('points_delta', array('lt'=> 0))
750
+ ->setDefaultOrder()
751
+ ->getFirstItem()
752
+ ->getCreatedAt()
753
+ ;
754
+
755
+ //for any valid date
756
+ if ($lastUsed)
757
+ return $date = Mage::helper('core')->formatDate($lastUsed, 'short', true);
758
+
759
+ return '';
760
+ }
761
+
762
+
763
+
764
+ /**
765
+ * get most purchased category
766
+ *
767
+ * @return string
768
+ */
769
+ public function getMostPurCategory()
770
+ {
771
+ $id = $this->customer->getMostCategoryId();
772
+ if($id){
773
+ return Mage::getModel('catalog/category')
774
+ ->load($id)
775
+ ->setStoreId($this->customer->getStoreId())
776
+ ->getName();
777
+ }
778
+ return "";
779
+ }
780
+
781
+ /**
782
+ * get most purchased brand
783
+ *
784
+ * @return string
785
+ */
786
+ public function getMostPurBrand()
787
+ {
788
+ $brand = $this->customer->getMostBrand();
789
+ if($brand)
790
+ return $brand;
791
+ return "";
792
+ }
793
+
794
+ /**
795
+ * get most frequent day of purchase
796
+ *
797
+ * @return string
798
+ */
799
+ public function getMostFreqPurDay()
800
+ {
801
+ $day = $this->customer->getWeekDay();
802
+ if($day)
803
+ return $day;
804
+ return "";
805
+ }
806
+
807
+ /**
808
+ * get most frequent month of purchase
809
+ *
810
+ * @return string
811
+ */
812
+ public function getMostFreqPurMon()
813
+ {
814
+ $month = $this->customer->getMonthDay();
815
+ if($month)
816
+ return $month;
817
+ return "";
818
+ }
819
+
820
+ /**
821
+ * get first purchased category
822
+ *
823
+ * @return string
824
+ */
825
+ public function getFirstCategoryPur()
826
+ {
827
+ $id = $this->customer->getFirstCategoryId();
828
+ if($id){
829
+ return Mage::getModel('catalog/category')
830
+ ->load($id)
831
+ ->setStoreId($this->customer->getStoreId())
832
+ ->getName();
833
+ }
834
+ return "";
835
+ }
836
+
837
+ /**
838
+ * get last purchased category
839
+ *
840
+ * @return string
841
+ */
842
+ public function getLastCategoryPur()
843
+ {
844
+ $id = $this->customer->getLastCategoryId();
845
+ if($id){
846
+ return Mage::getModel('catalog/category')
847
+ ->setStoreId($this->customer->getStoreId())
848
+ ->load($id)
849
+ ->getName();
850
+ }
851
+ return "";
852
+ }
853
+
854
+ /**
855
+ * get first purchased brand
856
+ *
857
+ * @return string
858
+ */
859
+ public function getFirstBrandPur()
860
+ {
861
+ $id = $this->customer->getProductIdForFirstBrand();
862
+ if($id){
863
+ $brand = Mage::getModel('catalog/product')
864
+ ->setStoreId($this->customer->getStoreId())
865
+ ->load($id)
866
+ ->getAttributeText('manufacturer');
867
+ if($brand)
868
+ return $brand;
869
+ }
870
+ return "";
871
+ }
872
+
873
+ /**
874
+ * get last purchased brand
875
+ *
876
+ * @return string
877
+ */
878
+ public function getLastBrandPur()
879
+ {
880
+ $id = $this->customer->getProductIdForLastBrand();
881
+ if($id){
882
+ $brand = Mage::getModel('catalog/product')
883
+ ->setStoreId($this->customer->getStoreId())
884
+ ->load($id)
885
+ ->getAttributeText('manufacturer');
886
+ if($brand)
887
+ return $brand;
888
+ }
889
+ return "";
890
+ }
891
+
892
+ /**
893
+ * get last increment id
894
+ *
895
+ * @return mixed
896
+ */
897
+ public function getLastIncrementId()
898
+ {
899
+ return $this->customer->getLastIncrementId();
900
+ }
901
+ }
app/code/community/Dotdigitalgroup/Email/Model/Apiconnector/Test.php ADDED
@@ -0,0 +1,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,239 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ /** @var $coreResource Mage_Core_Model_Resource */
95
+ $coreResource = Mage::getSingleton( 'core/resource' );
96
+ /** @var $conn Varien_Db_Adapter_Pdo_Mysql */
97
+ $conn = $coreResource->getConnection( 'core_write' );
98
+ try {
99
+ $contactIds = array_keys($contacts);
100
+ $bind = array(
101
+ 'enrolment_status' => $this->programStatus,
102
+ 'message' => $this->programMessage,
103
+ 'updated_at' => Mage::getSingleton('core/date')->gmtDate()
104
+ );
105
+ $where = array('id IN(?)' => $contactIds);
106
+ $num = $conn->update( $coreResource->getTableName( 'ddg_automation/automation' ),
107
+ $bind,
108
+ $where
109
+ );
110
+ if ($num)
111
+ Mage::helper('ddg')->log('Automation type : ' . $type . ', updated no : ' . $num);
112
+ } catch ( Exception $e ) {
113
+ Mage::logException($e);
114
+ }
115
+ }
116
+ }
117
+ /**
118
+ * update single contact datafields for this automation type.
119
+ *
120
+ * @param $type
121
+ */
122
+ public function updateDatafieldsByType($type, $email )
123
+ {
124
+ switch($type) {
125
+ case self::AUTOMATION_TYPE_NEW_CUSTOMER :
126
+ $this->_updateDefaultDatafields($email);
127
+ break;
128
+ case self::AUTOMATION_TYPE_NEW_SUBSCRIBER :
129
+ $this->_updateDefaultDatafields($email);
130
+ break;
131
+ case self::AUTOMATION_TYPE_NEW_ORDER :
132
+ $this->_updateNewOrderDatafields($email);
133
+ break;
134
+ case self::AUTOMATION_TYPE_NEW_GUEST_ORDER:
135
+ $this->_updateNewOrderDatafields($email);
136
+ break;
137
+ case self::AUTOMATION_TYPE_NEW_REVIEW :
138
+ $this->_updateNewOrderDatafields($email);
139
+ break;
140
+ case self::AUTOMATION_TYPE_NEW_WISHLIST:
141
+ $this->_updateDefaultDatafields($email);
142
+ break;
143
+ default:
144
+ $this->_updateDefaultDatafields($email);
145
+ break;
146
+ }
147
+ }
148
+ private function _updateDefaultDatafields($email)
149
+ {
150
+ $website = Mage::app()->getWebsite($this->websiteId);
151
+ Mage::helper('ddg')->updateDataFields($email, $website, $this->storeName);
152
+ }
153
+ private function _updateNewOrderDatafields($email)
154
+ {
155
+ $website = Mage::app()->getWebsite($this->websiteId);
156
+ $order = Mage::getModel('sales/order')->load($this->typeId);
157
+ //data fields
158
+ if($last_order_id = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_LAST_ORDER_ID)){
159
+ $data[] = array(
160
+ 'Key' => $last_order_id,
161
+ 'Value' => $order->getId()
162
+ );
163
+ }
164
+ if($order_increment_id = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_LAST_ORDER_INCREMENT_ID)){
165
+ $data[] = array(
166
+ 'Key' => $order_increment_id,
167
+ 'Value' => $order->getIncrementId()
168
+ );
169
+ }
170
+ if($store_name = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_STORE_NAME)){
171
+ $data[] = array(
172
+ 'Key' => $store_name,
173
+ 'Value' => $this->storeName
174
+ );
175
+ }
176
+ if($website_name = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_WEBSITE_NAME)){
177
+ $data[] = array(
178
+ 'Key' => $website_name,
179
+ 'Value' => $website->getName()
180
+ );
181
+ }
182
+ if($last_order_date = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_LAST_ORDER_DATE)){
183
+ $data[] = array(
184
+ 'Key' => $last_order_date,
185
+ 'Value' => $order->getCreatedAt()
186
+ );
187
+ }
188
+ if(($customer_id = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_ID)) && $order->getCustomerId()){
189
+ $data[] = array(
190
+ 'Key' => $customer_id,
191
+ 'Value' => $order->getCustomerId()
192
+ );
193
+ }
194
+ if(! empty($data)){
195
+ //update data fields
196
+ $client = Mage::helper('ddg')->getWebsiteApiClient($website);
197
+ $client->updateContactDatafieldsByEmail($order->getCustomerEmail(), $data);
198
+ }
199
+ }
200
+ /**
201
+ * Program check if is valid and active.
202
+ * @param $programId
203
+ *
204
+ * @return bool
205
+ */
206
+ private function _checkCampignEnrolmentActive($programId)
207
+ {
208
+ //program is not set
209
+ if (!$programId)
210
+ return false;
211
+ $client = Mage::helper('ddg')->getWebsiteApiClient($this->websiteId);
212
+ $program = $client->getProgramById($programId);
213
+ //program status
214
+ if (isset($program->status))
215
+ $this->programStatus = $program->status;
216
+ if (isset($program->status) && $program->status == 'Active') {
217
+ return true;
218
+ }
219
+ return false;
220
+ }
221
+ /**
222
+ * Enrol contacts for a program.
223
+ * @param $contacts
224
+ *
225
+ * @return null
226
+ */
227
+ public function sendContactsToAutomation($contacts)
228
+ {
229
+ $client = Mage::helper('ddg')->getWebsiteApiClient($this->websiteId);
230
+ $data = array(
231
+ 'Contacts' => $contacts,
232
+ 'ProgramId' => $this->programId,
233
+ 'AddressBooks' => array()
234
+ );
235
+ //api add contact to automation enrolment
236
+ $result = $client->postProgramsEnrolments( $data );
237
+ return $result;
238
+ }
239
+ }
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,465 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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->_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->_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->_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
+ * Reset for re-import.
247
+ *
248
+ * @return int
249
+ */
250
+ public function reset()
251
+ {
252
+ /** @var $coreResource Mage_Core_Model_Resource */
253
+ $coreResource = Mage::getSingleton('core/resource');
254
+
255
+ /** @var $conn Varien_Db_Adapter_Pdo_Mysql */
256
+ $conn = $coreResource->getConnection('core_write');
257
+ try{
258
+ $num = $conn->update($coreResource->getTableName('ddg_automation/catalog'),
259
+ array('imported' => new Zend_Db_Expr('null'), 'modified' => new Zend_Db_Expr('null'))
260
+ );
261
+ }catch (Exception $e){
262
+ Mage::logException($e);
263
+ }
264
+ return $num;
265
+ }
266
+
267
+ /**
268
+ * product save after event processor
269
+ *
270
+ * @param Varien_Event_Observer $observer
271
+ */
272
+ public function handleProductSaveAfter(Varien_Event_Observer $observer)
273
+ {
274
+ try{
275
+ $object = $observer->getEvent()->getDataObject();
276
+ $productId = $object->getId();
277
+ if($item = $this->_loadProduct($productId)){
278
+ if($item->getImported())
279
+ $item->setModified(1)->save();
280
+ }
281
+ }catch (Exception $e){
282
+ Mage::logException($e);
283
+ }
284
+ }
285
+
286
+ /**
287
+ * product delete after event processor
288
+ *
289
+ * @param Varien_Event_Observer $observer
290
+ */
291
+ public function handleProductDeleteAfter(Varien_Event_Observer $observer)
292
+ {
293
+ try{
294
+ /** @var $object Mage_Catalog_Model_Product */
295
+ $object = $observer->getEvent()->getDataObject();
296
+ $productId = $object->getId();
297
+ if($item = $this->_loadProduct($productId)){
298
+ //if imported delete from account
299
+ if($item->getImported()){
300
+ $this->_deleteFromAccount($productId);
301
+ }
302
+ //delete from table
303
+ $item->delete();
304
+
305
+ }
306
+ }catch (Exception $e){
307
+ Mage::logException($e);
308
+ }
309
+ }
310
+
311
+ /**
312
+ * delete piece of transactional data by key
313
+ *
314
+ * @param $key
315
+ */
316
+ private function _deleteFromAccount($key)
317
+ {
318
+ $enabled = Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED);
319
+ $sync = Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_CATALOG_ENABLED);
320
+ if($enabled && $sync){
321
+ $scope = Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_CATALOG_VALUES);
322
+ if($scope == 1){
323
+ //register in queue with importer
324
+ Mage::getModel('ddg_automation/importer')->registerQueue(
325
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_CATALOG,
326
+ array($key),
327
+ Dotdigitalgroup_Email_Model_Importer::MODE_SINGLE_DELETE,
328
+ Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID
329
+ );
330
+ }
331
+ if($scope == 2){
332
+ $stores = Mage::app()->getStores();
333
+ /** @var $store Mage_Core_Model_Store */
334
+ foreach($stores as $store){
335
+ $websiteCode = $store->getWebsite()->getCode();
336
+ $storeCode = $store->getCode();
337
+
338
+ //register in queue with importer
339
+ Mage::getModel('ddg_automation/importer')->registerQueue(
340
+ 'Catalog_' . $websiteCode . '_' . $storeCode,
341
+ array($key),
342
+ Dotdigitalgroup_Email_Model_Importer::MODE_SINGLE_DELETE,
343
+ $store->getWebsite()->getId()
344
+ );
345
+ }
346
+ }
347
+ }
348
+ }
349
+
350
+ /**
351
+ * load product. return item otherwise create item
352
+ *
353
+ * @param $productId
354
+ * @return bool|Varien_Object
355
+ */
356
+ private function _loadProduct($productId)
357
+ {
358
+ $collection = $this->getCollection()
359
+ ->addFieldToFilter('product_id', $productId)
360
+ ->setPageSize(1);
361
+
362
+ if ($collection->getSize()) {
363
+ return $collection->getFirstItem();
364
+ } else {
365
+ $this->setProductId($productId)->save();
366
+ }
367
+ return false;
368
+ }
369
+
370
+ /**
371
+ * set imported in bulk query. if modified true then set modified to null in bulk query.
372
+ *
373
+ * @param $ids
374
+ * @param $modified
375
+ */
376
+ private function _setImported($ids, $modified = false)
377
+ {
378
+ try{
379
+ $coreResource = Mage::getSingleton('core/resource');
380
+ $write = $coreResource->getConnection('core_write');
381
+ $tableName = $coreResource->getTableName('email_catalog');
382
+ $ids = implode(', ', $ids);
383
+ $now = Mage::getSingleton('core/date')->gmtDate();
384
+ if($modified)
385
+ $write->update($tableName, array('modified' => new Zend_Db_Expr('null'), 'updated_at' => $now), "product_id IN ($ids)");
386
+ else
387
+ $write->update($tableName, array('imported' => 1, 'updated_at' => $now), "product_id IN ($ids)");
388
+ }catch (Exception $e){
389
+ Mage::logException($e);
390
+ }
391
+ }
392
+
393
+ /**
394
+ * core config data save before event
395
+ *
396
+ * @param Varien_Event_Observer $observer
397
+ * @return $this
398
+ */
399
+ public function handleConfigSaveBefore(Varien_Event_Observer $observer)
400
+ {
401
+ if (!Mage::registry('core_config_data_save_before')){
402
+ if($groups = $observer->getEvent()->getConfigData()->getGroups()){
403
+ if(isset($groups['catalog_sync']['fields']['catalog_values']['value'])){
404
+ $value = $groups['catalog_sync']['fields']['catalog_values']['value'];
405
+ Mage::register('core_config_data_save_before', $value);
406
+ }
407
+ }
408
+ }
409
+
410
+
411
+ if (!Mage::registry('core_config_data_save_before_status')) {
412
+ if ($groups = $observer->getEvent()->getConfigData()->getGroups()) {
413
+ if (isset($groups['data_fields']['fields']['order_statuses']['value'])) {
414
+ $value = $groups['data_fields']['fields']['order_statuses']['value'];
415
+ Mage::register('core_config_data_save_before_status', $value);
416
+ }
417
+ }
418
+ }
419
+
420
+
421
+ return $this;
422
+ }
423
+
424
+ /**
425
+ * core config data save after event
426
+ *
427
+ * @param Varien_Event_Observer $observer
428
+ * @return $this
429
+ */
430
+ public function handleConfigSaveAfter(Varien_Event_Observer $observer)
431
+ {
432
+ try{
433
+ if(!Mage::registry('core_config_data_save_after_done')){
434
+ if($groups = $observer->getEvent()->getConfigData()->getGroups()){
435
+ if(isset($groups['catalog_sync']['fields']['catalog_values']['value'])){
436
+ $configAfter = $groups['catalog_sync']['fields']['catalog_values']['value'];
437
+ $configBefore = Mage::registry('core_config_data_save_before');
438
+ if($configAfter != $configBefore){
439
+ //reset catalog to re-import
440
+ $this->reset();
441
+ }
442
+ Mage::register('core_config_data_save_after_done', true);
443
+ }
444
+ }
445
+ }
446
+
447
+ if (!Mage::registry('core_config_data_save_after_done_status')) {
448
+ if ($groups = $observer->getEvent()->getConfigData()->getGroups()) {
449
+ if (isset($groups['data_fields']['fields']['order_statuses']['value'])) {
450
+ $configAfter = $groups['data_fields']['fields']['order_statuses']['value'];
451
+ $configBefore = Mage::registry('core_config_data_save_before_status');
452
+ if ($configAfter != $configBefore) {
453
+ //reset all contacts
454
+ Mage::getModel('ddg_automation/contact')->resetAllContacts();
455
+ }
456
+ Mage::register('core_config_data_save_after_done_status', true);
457
+ }
458
+ }
459
+ }
460
+ }catch (Exception $e){
461
+ Mage::logException($e);
462
+ }
463
+ return $this;
464
+ }
465
+ }
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;
18
+ private $_ordersForSingleSync = array();
19
+ private $_orderIdsForSingleSync;
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,404 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ /**
83
+ * set the order information
84
+ * @param Mage_Sales_Model_Order $orderData
85
+ */
86
+ public function __construct(Mage_Sales_Model_Order $orderData)
87
+ {
88
+ $customerModel = Mage::getModel('customer/customer');
89
+ $customerModel->load($orderData->getCustomerId());
90
+
91
+ $this->id = $orderData->getIncrementId();
92
+ $this->quote_id = $orderData->getQuoteId();
93
+ $this->email = $orderData->getCustomerEmail();
94
+ $this->store_name = $orderData->getStoreName();
95
+
96
+ $created_at = new Zend_Date($orderData->getCreatedAt(), Zend_Date::ISO_8601);
97
+
98
+ $this->purchase_date = $created_at->toString(Zend_Date::ISO_8601);
99
+ $this->delivery_method = $orderData->getShippingDescription();
100
+ $this->delivery_total = $orderData->getShippingAmount();
101
+ $this->currency = $orderData->getStoreCurrencyCode();
102
+
103
+ if ($payment = $orderData->getPayment())
104
+ $this->payment = $payment->getMethodInstance()->getTitle();
105
+ $this->couponCode = $orderData->getCouponCode();
106
+
107
+ /**
108
+ * custom order attributes
109
+ */
110
+ $helper = Mage::helper('ddg');
111
+ $website = Mage::app()->getStore($orderData->getStore())->getWebsite();
112
+ $customAttributes = $helper->getConfigSelectedCustomOrderAttributes($website);
113
+ if($customAttributes){
114
+ $fields = $helper->getOrderTableDescription();
115
+ foreach($customAttributes as $customAttribute){
116
+ if(isset($fields[$customAttribute])){
117
+ $field = $fields[$customAttribute];
118
+ $value = $this->_getCustomAttributeValue($field, $orderData);
119
+ if($value)
120
+ $this->_assignCustom($field, $value);
121
+ }
122
+ }
123
+ }
124
+
125
+ /**
126
+ * Billing address.
127
+ */
128
+ if ($orderData->getBillingAddress()) {
129
+ $billingData = $orderData->getBillingAddress()->getData();
130
+ $this->billing_address = array(
131
+ 'billing_address_1' => $this->_getStreet($billingData['street'], 1),
132
+ 'billing_address_2' => $this->_getStreet($billingData['street'], 2),
133
+ 'billing_city' => $billingData['city'],
134
+ 'billing_region' => $billingData['region'],
135
+ 'billing_country' => $billingData['country_id'],
136
+ 'billing_postcode' => $billingData['postcode'],
137
+ );
138
+ }
139
+ /**
140
+ * Shipping address.
141
+ */
142
+ if ($orderData->getShippingAddress()) {
143
+ $shippingData = $orderData->getShippingAddress()->getData();
144
+
145
+ $this->delivery_address = array(
146
+ 'delivery_address_1' => $this->_getStreet($shippingData['street'], 1),
147
+ 'delivery_address_2' => $this->_getStreet($shippingData['street'], 2),
148
+ 'delivery_city' => $shippingData['city'],
149
+ 'delivery_region' => $shippingData['region'],
150
+ 'delivery_country' => $shippingData['country_id'],
151
+ 'delivery_postcode' => $shippingData['postcode']
152
+ );
153
+ }
154
+
155
+ $syncCustomOption = $helper->getWebsiteConfig(
156
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_ORDER_PRODUCT_CUSTOM_OPTIONS,
157
+ $website
158
+ );
159
+
160
+ /**
161
+ * Order items.
162
+ */
163
+ foreach ($orderData->getAllItems() as $productItem) {
164
+ //product custom options
165
+ $customOptions = array();
166
+ if ($syncCustomOption)
167
+ $customOptions = $this->_getOrderItemOptions($productItem);
168
+
169
+ //load product by product id, for compatibility
170
+ $product = Mage::getModel('catalog/product')->load($productItem->getProductId());
171
+
172
+ if ($product) {
173
+ // category names
174
+ $categoryCollection = $product->getCategoryCollection()
175
+ ->addAttributeToSelect( 'name' );
176
+ $productCat = array();
177
+ foreach ( $categoryCollection as $cat ) {
178
+ $categories = array();
179
+ $categories[] = $cat->getName();
180
+ $productCat[]['Name'] = substr(implode(', ', $categories), 0, 244);
181
+ }
182
+
183
+ $attributes = array();
184
+ //selected attributes from config
185
+ $configAttributes = Mage::helper('ddg')->getWebsiteConfig(
186
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_ORDER_PRODUCT_ATTRIBUTES,
187
+ $orderData->getStore()->getWebsite()
188
+ );
189
+ if ($configAttributes) {
190
+ $configAttributes = explode(',', $configAttributes);
191
+ //attributes from attribute set
192
+ $attributesFromAttributeSet = $this->_getAttributesArray($product->getAttributeSetId());
193
+
194
+ foreach ($configAttributes as $attribute_code) {
195
+ //if config attribute is in attribute set
196
+ if (in_array($attribute_code, $attributesFromAttributeSet)) {
197
+ //attribute input type
198
+ $inputType = $product->getResource()
199
+ ->getAttribute($attribute_code)
200
+ ->getFrontend()
201
+ ->getInputType();
202
+
203
+ //fetch attribute value from product depending on input type
204
+ switch ($inputType) {
205
+ case 'multiselect':
206
+ case 'select':
207
+ case 'dropdown':
208
+ $value = $product->getAttributeText($attribute_code);
209
+ break;
210
+ default:
211
+ $value = $product->getData($attribute_code);
212
+ break;
213
+ }
214
+
215
+ if ($value) // check limit on text and assign value to array
216
+ $attributes[][$attribute_code] = $this->_limitLength($value);
217
+ }
218
+ }
219
+ }
220
+
221
+ $attributeSetModel = Mage::getModel( "eav/entity_attribute_set" );
222
+ $attributeSetModel->load( $product->getAttributeSetId() );
223
+ $attributeSetName = $attributeSetModel->getAttributeSetName();
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
+ }
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,284 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Connector_Quote
4
+ {
5
+ /**
6
+ * @var int
7
+ */
8
+ public $id;
9
+ /**
10
+ * Email
11
+ * @var string
12
+ */
13
+ public $email;
14
+ /**
15
+ * @var string
16
+ */
17
+ public $store_name;
18
+ /**
19
+ * @var string
20
+ */
21
+ public $created_date;
22
+ /**
23
+ * @var string
24
+ */
25
+ public $delivery_address;
26
+ /**
27
+ * @var string
28
+ */
29
+ public $billing_address;
30
+ /**
31
+ * @var array
32
+ */
33
+ public $products = array();
34
+ /**
35
+ * @var float
36
+ */
37
+ public $quote_subtotal;
38
+ /**
39
+ * @var float
40
+ */
41
+ public $discount_amount;
42
+ /**
43
+ * @var float
44
+ */
45
+ public $quote_total;
46
+ /**
47
+ * @var array
48
+ */
49
+ public $categories;
50
+ /**
51
+ * Payment name
52
+ * @var string
53
+ */
54
+ public $payment;
55
+ /**
56
+ * @var string
57
+ */
58
+ public $delivery_method;
59
+ /**
60
+ * @var float
61
+ */
62
+ public $delivery_total;
63
+ /**
64
+ * @var string
65
+ */
66
+ public $currency;
67
+
68
+
69
+ public $couponCode;
70
+
71
+ /**
72
+ * @var array
73
+ */
74
+ public $custom = array();
75
+
76
+ /**
77
+ * set the quote information
78
+ * @param Mage_Sales_Model_Quote $quoteData
79
+ */
80
+ public function __construct(Mage_Sales_Model_Quote $quoteData)
81
+ {
82
+ $customerModel = Mage::getModel('customer/customer');
83
+ $customerModel->load($quoteData->getCustomerId());
84
+
85
+ $this->id = $quoteData->getId();
86
+ $this->email = $quoteData->getCustomerEmail();
87
+ $this->store_name = $quoteData->getStore()->getName();
88
+
89
+ $created_at = new Zend_Date($quoteData->getCreatedAt(), Zend_Date::ISO_8601);
90
+
91
+ $this->created_date = $created_at->toString(Zend_Date::ISO_8601);
92
+ if($quoteData->getShippingAddress()){
93
+ $this->delivery_method = $quoteData->getShippingAddress()->getShippingDescription();
94
+ $this->delivery_total = $quoteData->getShippingAddress()->getShippingAmount();
95
+ }
96
+ $this->currency = $quoteData->getStoreCurrencyCode();
97
+ if ($payment = $quoteData->getPayment())
98
+ $this->payment = $payment->getMethod();
99
+
100
+ $this->couponCode = $quoteData->getCouponCode();
101
+
102
+ /**
103
+ * custom quote attributes
104
+ */
105
+ $helper = Mage::helper('ddg');
106
+ $website = Mage::app()->getStore($quoteData->getStore())->getWebsite();
107
+ $customAttributes = $helper->getConfigSelectedCustomQuoteAttributes($website);
108
+ if($customAttributes){
109
+ $fields = $helper->getQuoteTableDescription();
110
+ foreach($customAttributes as $customAttribute){
111
+ if(isset($fields[$customAttribute])){
112
+ $field = $fields[$customAttribute];
113
+ $value = $this->_getCustomAttributeValue($field, $quoteData);
114
+ if($value)
115
+ $this->_assignCustom($field, $value);
116
+ }
117
+ }
118
+ }
119
+
120
+ /**
121
+ * Billing address.
122
+ */
123
+ if ($quoteData->getBillingAddress()) {
124
+ $billingData = $quoteData->getBillingAddress()->getData();
125
+ $this->billing_address = array(
126
+ 'billing_address_1' => $this->_getStreet($billingData['street'], 1),
127
+ 'billing_address_2' => $this->_getStreet($billingData['street'], 2),
128
+ 'billing_city' => $billingData['city'],
129
+ 'billing_region' => $billingData['region'],
130
+ 'billing_country' => $billingData['country_id'],
131
+ 'billing_postcode' => $billingData['postcode'],
132
+ );
133
+ }
134
+ /**
135
+ * Shipping address.
136
+ */
137
+ if ($quoteData->getShippingAddress()) {
138
+ $shippingData = $quoteData->getShippingAddress()->getData();
139
+
140
+ $this->delivery_address = array(
141
+ 'delivery_address_1' => $this->_getStreet($shippingData['street'], 1),
142
+ 'delivery_address_2' => $this->_getStreet($shippingData['street'], 2),
143
+ 'delivery_city' => $shippingData['city'],
144
+ 'delivery_region' => $shippingData['region'],
145
+ 'delivery_country' => $shippingData['country_id'],
146
+ 'delivery_postcode' => $shippingData['postcode']
147
+ );
148
+ }
149
+
150
+ /**
151
+ * Quote items.
152
+ */
153
+ foreach ($quoteData->getAllItems() as $productItem) {
154
+
155
+ //load product by product id, for compatibility
156
+ $product = Mage::getModel('catalog/product')->load($productItem->getProductId());
157
+
158
+ if ($product) {
159
+ // category names
160
+ $categoryCollection = $product->getCategoryCollection()
161
+ ->addAttributeToSelect( 'name' );
162
+
163
+ foreach ( $categoryCollection as $cat ) {
164
+ $categories = array();
165
+ $categories[] = $cat->getName();
166
+ $this->categories[]['Name'] = substr( implode( ', ', $categories ), 0, 244 );
167
+ }
168
+
169
+ $attributeSetModel = Mage::getModel( "eav/entity_attribute_set" );
170
+ $attributeSetModel->load( $product->getAttributeSetId() );
171
+ $attributeSetName = $attributeSetModel->getAttributeSetName();
172
+ $this->products[] = array(
173
+ 'name' => $productItem->getName(),
174
+ 'sku' => $productItem->getSku(),
175
+ 'qty' => (int) number_format( $productItem->getData( 'qty' ), 2 ),
176
+ 'price' => (float) number_format( $productItem->getPrice(), 2, '.', '' ),
177
+ 'attribute-set' => $attributeSetName
178
+ );
179
+ } else {
180
+ // when no product information is available limit to this data
181
+ $this->products[] = array(
182
+ 'name' => $productItem->getName(),
183
+ 'sku' => $productItem->getSku(),
184
+ 'qty' => (int) number_format( $productItem->getData( 'qty' ), 2 ),
185
+ 'price' => (float) number_format( $productItem->getPrice(), 2, '.', '' )
186
+ );
187
+ }
188
+ }
189
+
190
+ $this->quote_subtotal = (float)number_format($quoteData->getData('subtotal'), 2 , '.', '');
191
+ $discountAmount = $quoteData->getData('subtotal') - $quoteData->getData('subtotal_with_discount');
192
+ $this->discount_amount = (float)number_format($discountAmount, 2 , '.', '');
193
+ $this->quote_total = (float)number_format($quoteData->getData('grand_total'), 2 , '.', '');
194
+
195
+ return true;
196
+ }
197
+ /**
198
+ * get the street name by line number
199
+ * @param $street
200
+ * @param $line
201
+ * @return string
202
+ */
203
+ private function _getStreet($street, $line)
204
+ {
205
+ $street = explode("\n", $street);
206
+ if ($line == 1) {
207
+ return $street[0];
208
+ }
209
+ if (isset($street[$line -1])) {
210
+
211
+ return $street[$line - 1];
212
+ } else {
213
+
214
+ return '';
215
+ }
216
+ }
217
+
218
+ /**
219
+ * exposes the class as an array of objects.
220
+ * @return array
221
+ */
222
+ public function expose()
223
+ {
224
+ return get_object_vars($this);
225
+
226
+ }
227
+
228
+ /**
229
+ * get custom attribute value
230
+ *
231
+ * @param $field
232
+ * @param $quoteData
233
+ * @return float|int|null|string
234
+ */
235
+ private function _getCustomAttributeValue($field, $quoteData)
236
+ {
237
+ $type = $field['DATA_TYPE'];
238
+
239
+ $function = 'get';
240
+ $exploded = explode('_', $field['COLUMN_NAME']);
241
+ foreach ($exploded as $one) {
242
+ $function .= ucfirst($one);
243
+ }
244
+
245
+ $value = null;
246
+ try{
247
+ switch ($type) {
248
+ case 'int':
249
+ case 'smallint':
250
+ $value = (int)$quoteData->$function();
251
+ break;
252
+
253
+ case 'decimal':
254
+ $value = (float)number_format($quoteData->$function(), 2 , '.', '');
255
+ break;
256
+
257
+ case 'timestamp':
258
+ case 'datetime':
259
+ case 'date':
260
+ $date = new Zend_Date($quoteData->$function(), Zend_Date::ISO_8601);
261
+ $value = $date->toString(Zend_Date::ISO_8601);
262
+ break;
263
+
264
+ default:
265
+ $value = $quoteData->$function();
266
+ }
267
+ }catch (Exception $e){
268
+ Mage::logException($e);
269
+ }
270
+
271
+ return $value;
272
+ }
273
+
274
+ /**
275
+ * create property on runtime
276
+ *
277
+ * @param $field
278
+ * @param $value
279
+ */
280
+ private function _assignCustom($field, $value)
281
+ {
282
+ $this->custom[$field['COLUMN_NAME']] = $value;
283
+ }
284
+ }
app/code/community/Dotdigitalgroup/Email/Model/Contact.php ADDED
@@ -0,0 +1,321 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Contact extends Mage_Core_Model_Abstract
4
+ {
5
+
6
+ const EMAIL_CONTACT_IMPORTED = 1;
7
+ const EMAIL_CONTACT_NOT_IMPORTED = null;
8
+ const EMAIL_SUBSCRIBER_NOT_IMPORTED = null;
9
+ /**
10
+ * constructor
11
+ */
12
+ public function _construct()
13
+ {
14
+ parent::_construct();
15
+ $this->_init('ddg_automation/contact');
16
+ }
17
+
18
+
19
+ /**
20
+ * @return $this|Mage_Core_Model_Abstract
21
+ */
22
+ protected function _beforeSave()
23
+ {
24
+ parent::_beforeSave();
25
+ $now = Mage::getSingleton('core/date')->gmtDate();
26
+ if ($this->isObjectNew()) {
27
+ $this->setCreatedAt($now);
28
+ }
29
+ return $this;
30
+ }
31
+
32
+ /**
33
+ * Reset the imported contacts
34
+ * @return int
35
+ */
36
+ public function resetAllContacts()
37
+ {
38
+
39
+ /** @var $coreResource Mage_Core_Model_Resource */
40
+ $coreResource = Mage::getSingleton('core/resource');
41
+
42
+ /** @var $conn Varien_Db_Adapter_Pdo_Mysql */
43
+ $conn = $coreResource->getConnection('core_write');
44
+
45
+ try{
46
+ $num = $conn->update($coreResource->getTableName('ddg_automation/contact'),
47
+ array('email_imported' => new Zend_Db_Expr('null')),
48
+ $conn->quoteInto('email_imported is ?', new Zend_Db_Expr('not null'))
49
+ );
50
+ }catch (Exception $e){
51
+ Mage::logException($e);
52
+ Mage::helper('ddg')->rayLog('300', $e);
53
+ }
54
+ return $num;
55
+ }
56
+
57
+
58
+ /**
59
+ * Load contact by customer id
60
+ * @param $customerId
61
+ * @return mixed
62
+ */
63
+ public function loadByCustomerId($customerId)
64
+ {
65
+ $collection = $this->getCollection()
66
+ ->addFieldToFilter('customer_id', $customerId)
67
+ ->setPageSize(1);
68
+
69
+ if($collection->count())
70
+ return $collection->getFirstItem();
71
+
72
+ return $this;
73
+ }
74
+
75
+ /**
76
+ * get all customer contacts not imported for a website.
77
+ *
78
+ * @param $websiteId
79
+ * @param int $pageSize
80
+ *
81
+ * @return Dotdigitalgroup_Email_Model_Resource_Contact_Collection
82
+ */
83
+ public function getContactsToImportForWebsite($websiteId, $pageSize = 100)
84
+ {
85
+ $collection = $this->getCollection()
86
+ ->addFieldToFilter('website_id', $websiteId)
87
+ ->addFieldToFilter('email_imported', array('null' => true))
88
+ ->addFieldToFilter('customer_id', array('neq' => '0'));
89
+
90
+
91
+ $collection->getSelect()->limit($pageSize);
92
+
93
+ return $collection;
94
+ }
95
+
96
+ /**
97
+ * Get missing contacts.
98
+ * @param $websiteId
99
+ * @param int $pageSize
100
+ * @return mixed
101
+ */
102
+ public function getMissingContacts($websiteId, $pageSize = 100)
103
+ {
104
+ $collection = $this->getCollection()
105
+ ->addFieldToFilter('contact_id', array('null' => true))
106
+ ->addFieldToFilter('suppressed', array('null' => true))
107
+ ->addFieldToFilter('website_id', $websiteId);
108
+
109
+ $collection->getSelect()->limit($pageSize);
110
+
111
+ return $collection->load();
112
+ }
113
+
114
+ /**
115
+ * Load Contact by Email.
116
+ * @param $email
117
+ * @param $websiteId
118
+ * @return $this
119
+ */
120
+ public function loadByCustomerEmail($email, $websiteId)
121
+ {
122
+ $collection = $this->getCollection()
123
+ ->addFieldToFilter('email', $email)
124
+ ->addFieldToFilter('website_id', $websiteId)
125
+ ->setPageSize(1);
126
+
127
+ if ($collection->getSize()) {
128
+ return $collection->getFirstItem();
129
+ } else {
130
+ $this->setEmail($email)
131
+ ->setWebsiteId($websiteId);
132
+ }
133
+ return $this;
134
+ }
135
+
136
+ /**
137
+ * batch non imported subscribers for a website.
138
+ * @param $website
139
+ * @param int $limit
140
+ *
141
+ * @return Dotdigitalgroup_Email_Model_Resource_Contact_Collection
142
+ */
143
+ public function getSubscribersToImport($website, $limit = 1000)
144
+ {
145
+
146
+ $storeIds = $website->getStoreIds();
147
+ $collection = $this->getCollection()
148
+ ->addFieldToFilter('is_subscriber', array('notnull' => true))
149
+ ->addFieldToFilter('subscriber_imported', array('null' => true))
150
+ ->addFieldToFilter('store_id', array('in' => $storeIds));
151
+
152
+ $collection->getSelect()->limit($limit);
153
+
154
+ return $collection;
155
+ }
156
+
157
+ /**
158
+ * get all not imported guests for a website.
159
+ * @param $website
160
+ *
161
+ * @return Dotdigitalgroup_Email_Model_Resource_Contact_Collection
162
+ */
163
+ public function getGuests($website)
164
+ {
165
+ $guestCollection = $this->getCollection()
166
+ ->addFieldToFilter('is_guest', array('notnull' => true))
167
+ ->addFieldToFilter('email_imported', array('null' => true))
168
+ ->addFieldToFilter('website_id', $website->getId());
169
+ return $guestCollection->load();
170
+ }
171
+
172
+ public function getNumberOfImportedContacs()
173
+ {
174
+ $collection = $this->getCollection()
175
+ ->addFieldToFilter('email_imported', array('notnull' => true));
176
+
177
+ return $collection->getSize();
178
+ }
179
+
180
+
181
+ /**
182
+ * Set all imported subscribers for reimport.
183
+ *
184
+ * @return int
185
+ */
186
+ public function resetSubscribers() {
187
+
188
+ /** @var $coreResource Mage_Core_Model_Resource */
189
+ $coreResource = Mage::getSingleton( 'core/resource' );
190
+
191
+ /** @var $conn Varien_Db_Adapter_Pdo_Mysql */
192
+ $conn = $coreResource->getConnection( 'core_write' );
193
+
194
+ try {
195
+ $num = $conn->update(
196
+ $coreResource->getTableName( 'ddg_automation/contact' ),
197
+ array('subscriber_imported' => new Zend_Db_Expr( 'null' ) ),
198
+ $conn->quoteInto('subscriber_imported is ?', new Zend_Db_Expr('not null')));
199
+
200
+ } catch ( Exception $e ) {
201
+ Mage::logException($e);
202
+ Mage::helper('ddg')->sendRaygunException($e);
203
+ }
204
+
205
+ return $num;
206
+ }
207
+
208
+ /**
209
+ * Get the number of customers for a website.
210
+ * @param int $websiteId
211
+ *
212
+ * @return int
213
+ */
214
+ public function getNumberCustomerContacts($websiteId = 0)
215
+ {
216
+ $countContacts = Mage::getModel('ddg_automation/contact')->getCollection()
217
+ ->addFieldToFilter('customer_id', array('gt' => '0'))
218
+ ->addFieldToFilter('website_id', $websiteId)
219
+ ->getSize();
220
+ return $countContacts;
221
+ }
222
+
223
+ /**
224
+ *
225
+ * Get number of suppressed contacts as customer.
226
+ * @param int $websiteId
227
+ *
228
+ * @return int
229
+ */
230
+ public function getNumberCustomerSuppressed( $websiteId = 0 )
231
+ {
232
+ $countContacts = Mage::getModel('ddg_automation/contact')->getCollection()
233
+ ->addFieldToFilter('customer_id', array('gt' => 0))
234
+ ->addFieldToFilter('website_id', $websiteId)
235
+ ->addFieldToFilter('suppressed', '1')
236
+ ->getSize();
237
+
238
+ return $countContacts;
239
+ }
240
+
241
+ /**
242
+ * Get number of synced customers.
243
+ * @param int $websiteId
244
+ *
245
+ * @return int
246
+ */
247
+ public function getNumberCustomerSynced( $websiteId = 0 )
248
+ {
249
+ $countContacts = Mage::getModel('ddg_automation/contact')->getCollection()
250
+ ->addFieldToFilter('customer_id', array('gt' => 0))
251
+ ->addFieldToFilter('website_id', $websiteId)
252
+ ->addFieldToFilter('email_imported' , '1')
253
+ ->getSize();
254
+
255
+ return $countContacts;
256
+
257
+ }
258
+
259
+ /**
260
+ * Get number of subscribers synced.
261
+ * @param int $websiteId
262
+ *
263
+ * @return int
264
+ */
265
+ public function getNumberSubscribersSynced( $websiteId = 0 )
266
+ {
267
+ $countContacts = Mage::getModel('ddg_automation/contact')->getCollection()
268
+ ->addFieldToFilter('subscriber_status', Dotdigitalgroup_Email_Model_Newsletter_Subscriber::STATUS_SUBSCRIBED)
269
+ ->addFieldToFilter('subscriber_imported', '1')
270
+ ->addFieldToFilter('website_id', $websiteId)
271
+ ->getSize();
272
+
273
+ return $countContacts;
274
+ }
275
+
276
+ /**
277
+ * Get number of subscribers.
278
+ * @param int $websiteId
279
+ *
280
+ * @return int
281
+ */
282
+ public function getNumberSubscribers( $websiteId = 0 )
283
+ {
284
+
285
+ $countContacts = Mage::getModel('ddg_automation/contact')->getCollection()
286
+ ->addFieldToFilter('subscriber_status', Dotdigitalgroup_Email_Model_Newsletter_Subscriber::STATUS_SUBSCRIBED)
287
+ ->addFieldToFilter('website_id', $websiteId)
288
+ ->getSize();
289
+ return $countContacts;
290
+ }
291
+
292
+ /**
293
+ * Reset the imported contacts as guest
294
+ * @return int
295
+ */
296
+ public function resetAllGuestContacts()
297
+ {
298
+
299
+ /** @var $coreResource Mage_Core_Model_Resource */
300
+ $coreResource = Mage::getSingleton('core/resource');
301
+
302
+ /** @var $conn Varien_Db_Adapter_Pdo_Mysql */
303
+ $conn = $coreResource->getConnection('core_write');
304
+
305
+ try {
306
+ $where = array();
307
+ $where[] = $conn->quoteInto('email_imported is ?', new Zend_Db_Expr('not null'));
308
+ $where[] = $conn->quoteInto('is_guest is ?', new Zend_Db_Expr('not null'));
309
+
310
+ $num = $conn->update($coreResource->getTableName('ddg_automation/contact'),
311
+ array('email_imported' => new Zend_Db_Expr('null')),
312
+ $where
313
+ );
314
+ } catch (Exception $e) {
315
+ Mage::logException($e);
316
+ Mage::helper('ddg')->rayLog('300', $e);
317
+ }
318
+ return $num;
319
+ }
320
+
321
+ }
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 = 'registered', $backUrl = '', $storeId = '0');
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_PENDING){
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,240 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Customer_Review
4
+ {
5
+ /**
6
+ * @var int
7
+ */
8
+ public $id;
9
+
10
+ /**
11
+ * @var int
12
+ */
13
+ public $customer_id;
14
+
15
+ /**
16
+ * @var string
17
+ */
18
+ public $email;
19
+
20
+ /**
21
+ * @var string
22
+ */
23
+ public $product_name;
24
+
25
+ /**
26
+ * @var string
27
+ */
28
+ public $product_sku;
29
+
30
+ /**
31
+ * @var string
32
+ */
33
+ public $review_date;
34
+
35
+ /**
36
+ * @var string
37
+ */
38
+ public $website_name;
39
+
40
+ /**
41
+ * @var string
42
+ */
43
+ public $store_name;
44
+
45
+
46
+ /**
47
+ * constructor.
48
+ *
49
+ * @param Mage_Customer_Model_Customer $customer
50
+ */
51
+ public function __construct(Mage_Customer_Model_Customer $customer)
52
+ {
53
+
54
+ $this->setCustomerId($customer->getId());
55
+ $this->email = $customer->getEmail();
56
+ }
57
+
58
+ /**
59
+ * @param mixed $customer_id
60
+ */
61
+ public function setCustomerId($customer_id)
62
+ {
63
+ $this->customer_id = (int) $customer_id;
64
+ }
65
+
66
+ /**
67
+ * @return mixed
68
+ */
69
+ public function getCustomerId()
70
+ {
71
+ return (int) $this->customer_id;
72
+ }
73
+
74
+ /**
75
+ * @param $id
76
+ * @return $this
77
+ */
78
+ public function setId($id)
79
+ {
80
+ $this->id = (int) $id;
81
+ return $this;
82
+ }
83
+
84
+ /**
85
+ * @return mixed
86
+ */
87
+ public function getId()
88
+ {
89
+ return (int) $this->id;
90
+ }
91
+
92
+ /**
93
+ * create rating on runtime
94
+ *
95
+ * @param $rating_name
96
+ * @param $rating
97
+ */
98
+ public function createRating($rating_name, $rating)
99
+ {
100
+ $this->$rating_name = $rating->expose();
101
+ }
102
+
103
+ /**
104
+ * set review date.
105
+ *
106
+ * @param $date
107
+ * @return $this;
108
+ */
109
+ public function setReviewDate($date)
110
+ {
111
+ $created_at = new Zend_Date($date, Zend_Date::ISO_8601);
112
+
113
+ $this->review_date = $created_at->toString(Zend_Date::ISO_8601);;
114
+ return $this;
115
+ }
116
+
117
+ /**
118
+ * @return string
119
+ */
120
+ public function getReviewDate()
121
+ {
122
+ return $this->review_date;
123
+ }
124
+
125
+ /**
126
+ * set product
127
+ *
128
+ * @param Mage_Catalog_Model_Product $product
129
+ * @return $this
130
+ */
131
+ public function setProduct(Mage_Catalog_Model_Product $product)
132
+ {
133
+ $this->setProductName($product->getName());
134
+ $this->setProductSku($product->getSku());
135
+ return $this;
136
+ }
137
+
138
+ /**
139
+ * set review data
140
+ *
141
+ * @param Mage_Review_Model_Review $review $product
142
+ * @return $this
143
+ */
144
+ public function setReviewData(Mage_Review_Model_Review $review)
145
+ {
146
+ $store = Mage::app()->getStore($review->getStoreId());
147
+ $websiteName = $store->getWebsite()->getName();
148
+ $storeName = $store->getName();
149
+ $this->setId($review->getReviewId())
150
+ ->setWebsiteName($websiteName)
151
+ ->setStoreName($storeName)
152
+ ->setReviewDate($review->getCreatedAt());
153
+
154
+ return $this;
155
+ }
156
+
157
+ /**
158
+ * set product name
159
+ *
160
+ * @param $name
161
+ */
162
+ public function setProductName($name)
163
+ {
164
+ $this->product_name = $name;
165
+ }
166
+
167
+ /**
168
+ * @return string
169
+ */
170
+ public function getProductName()
171
+ {
172
+ return $this->product_name;
173
+ }
174
+
175
+ /**
176
+ * set product sku
177
+ *
178
+ * @param $sku
179
+ */
180
+ public function setProductSku($sku)
181
+ {
182
+ $this->product_sku = $sku;
183
+ }
184
+
185
+ /**
186
+ * @return string
187
+ */
188
+ public function getProductSku()
189
+ {
190
+ return $this->product_sku;
191
+ }
192
+
193
+ /**
194
+ * set website name
195
+ *
196
+ * @param $name
197
+ * @return $this
198
+ */
199
+ public function setWebsiteName($name)
200
+ {
201
+ $this->website_name = $name;
202
+ return $this;
203
+ }
204
+
205
+ /**
206
+ * @return string
207
+ */
208
+ public function getStoreName()
209
+ {
210
+ return $this->store_name;
211
+ }
212
+
213
+ /**
214
+ * set store name
215
+ *
216
+ * @param $name
217
+ * @return $this
218
+ */
219
+ public function setStoreName($name)
220
+ {
221
+ $this->store_name = $name;
222
+ return $this;
223
+ }
224
+
225
+ /**
226
+ * @return string
227
+ */
228
+ public function getWebsiteName()
229
+ {
230
+ return $this->website_name;
231
+ }
232
+
233
+ /**
234
+ * @return array
235
+ */
236
+ public function expose()
237
+ {
238
+ return get_object_vars($this);
239
+ }
240
+ }
app/code/community/Dotdigitalgroup/Email/Model/Customer/Review/Rating.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Customer_Review_Rating
4
+ {
5
+ /**
6
+ * @var int
7
+ */
8
+ public $rating_score;
9
+
10
+ /**
11
+ * constructor
12
+ *
13
+ * @param $rating
14
+ */
15
+ public function __construct($rating)
16
+ {
17
+ $this->setRatingScore($rating->getValue());
18
+ }
19
+
20
+ /**
21
+ * @param $score
22
+ *
23
+ * @return $this
24
+ */
25
+ public function setRatingScore($score)
26
+ {
27
+ $this->rating_score = (int)$score;
28
+ return $this;
29
+ }
30
+
31
+ /**
32
+ * @return int
33
+ */
34
+ public function getRatingScore()
35
+ {
36
+ return $this->rating_score;
37
+ }
38
+
39
+ /**
40
+ * @return array
41
+ */
42
+ public function expose()
43
+ {
44
+ return get_object_vars($this);
45
+ }
46
+ }
app/code/community/Dotdigitalgroup/Email/Model/Customer/Wishlist.php ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Customer_Wishlist
4
+ {
5
+ /**
6
+ * @var int
7
+ */
8
+ public $id;
9
+ /**
10
+ * @var int
11
+ */
12
+ public $customer_id;
13
+ /**
14
+ * @var string
15
+ */
16
+ public $email;
17
+
18
+ /**
19
+ * wishlist items.
20
+ * @var array
21
+ */
22
+ public $items = array();
23
+
24
+ /**
25
+ * @var float
26
+ */
27
+ protected $total_wishlist_value;
28
+
29
+ /**
30
+ * @var string
31
+ */
32
+ public $updated_at;
33
+ /**
34
+ * constructor.
35
+ *
36
+ * @param Mage_Customer_Model_Customer $customer
37
+ */
38
+ public function __construct(Mage_Customer_Model_Customer $customer)
39
+ {
40
+
41
+ $this->setCustomerId($customer->getId());
42
+ $this->email = $customer->getEmail();
43
+ }
44
+
45
+ /**
46
+ * @param mixed $customer_id
47
+ */
48
+ public function setCustomerId($customer_id)
49
+ {
50
+ $this->customer_id = (int) $customer_id;
51
+ }
52
+
53
+ /**
54
+ * @return mixed
55
+ */
56
+ public function getCustomerId()
57
+ {
58
+ return (int) $this->customer_id;
59
+ }
60
+
61
+ /**
62
+ * @param $id
63
+ * @return $this
64
+ */
65
+ public function setId($id)
66
+ {
67
+ $this->id = (int) $id;
68
+ return $this;
69
+ }
70
+
71
+ /**
72
+ * @return mixed
73
+ */
74
+ public function getId()
75
+ {
76
+ return (int) $this->id;
77
+ }
78
+
79
+ /**
80
+ * set wishlist item.
81
+ *
82
+ * @param $item
83
+ */
84
+ public function setItem($item)
85
+ {
86
+ $this->items[] = $item->expose();
87
+
88
+ $this->total_wishlist_value += $item->getTotalValueOfProduct();
89
+ }
90
+
91
+ /**
92
+ * @return array
93
+ */
94
+ public function expose()
95
+ {
96
+ return get_object_vars($this);
97
+ }
98
+
99
+ /**
100
+ * set wishlist date.
101
+ *
102
+ * @param $date
103
+ * @return $this;
104
+ */
105
+ public function setUpdatedAt($date)
106
+ {
107
+ $date = new Zend_Date($date, Zend_Date::ISO_8601);
108
+
109
+ $this->updated_at = $date->toString(Zend_Date::ISO_8601);;
110
+ return $this;
111
+ }
112
+
113
+ /**
114
+ * @return string
115
+ */
116
+ public function getUpdatedAt()
117
+ {
118
+ return $this->updated_at;
119
+ }
120
+ }
app/code/{local → community}/Dotdigitalgroup/Email/Model/Customer/Wishlist/Item.php RENAMED
@@ -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,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ /**
127
+ * Reset the email order for reimport.
128
+ *
129
+ * @return int
130
+ */
131
+ public function resetOrders()
132
+ {
133
+ /** @var $coreResource Mage_Core_Model_Resource */
134
+ $coreResource = Mage::getSingleton('core/resource');
135
+
136
+ /** @var $conn Varien_Db_Adapter_Pdo_Mysql */
137
+ $conn = $coreResource->getConnection('core_write');
138
+ try{
139
+ $num = $conn->update($coreResource->getTableName('ddg_automation/order'),
140
+ array('email_imported' => new Zend_Db_Expr('null'), 'modified' => new Zend_Db_Expr('null')),
141
+ $conn->quoteInto('email_imported is ?', new Zend_Db_Expr('not null'))
142
+ );
143
+ }catch (Exception $e){
144
+ Mage::logException($e);
145
+ }
146
+
147
+ return $num;
148
+ }
149
+
150
+ }
app/code/community/Dotdigitalgroup/Email/Model/Quote.php ADDED
@@ -0,0 +1,225 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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->_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
+ //register in queue with importer
148
+ $check = Mage::getModel('ddg_automation/importer')->registerQueue(
149
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_QUOTE,
150
+ array($emailQuote->getQuoteId()),
151
+ Dotdigitalgroup_Email_Model_Importer::MODE_SINGLE,
152
+ $website->getId()
153
+ );
154
+ if ($check) {
155
+ $message = 'Quote updated : ' . $emailQuote->getQuoteId();
156
+ Mage::helper('ddg')->log($message);
157
+ $emailQuote->setModified(null)->save();
158
+ $this->_count++;
159
+ }
160
+ }
161
+ } catch (Exception $e) {
162
+ Mage::logException($e);
163
+ }
164
+ }
165
+
166
+ /**
167
+ * load quote from connector table
168
+ *
169
+ * @param $quoteId
170
+ * @return bool
171
+ */
172
+ public function loadQuote($quoteId)
173
+ {
174
+ $collection = $this->getCollection();
175
+ $collection->addFieldToFilter('quote_id', $quoteId)
176
+ ->setPageSize(1);
177
+
178
+ if ($collection->count()) {
179
+ return $collection->getFirstItem();
180
+ }
181
+ return false;
182
+ }
183
+
184
+ /**
185
+ * Reset the email quote for reimport.
186
+ *
187
+ * @return int
188
+ */
189
+ public function resetQuotes()
190
+ {
191
+ /** @var $coreResource Mage_Core_Model_Resource */
192
+ $coreResource = Mage::getSingleton('core/resource');
193
+
194
+ /** @var $conn Varien_Db_Adapter_Pdo_Mysql */
195
+ $conn = $coreResource->getConnection('core_write');
196
+ try{
197
+ $num = $conn->update($coreResource->getTableName('ddg_automation/quote'),
198
+ array('imported' => new Zend_Db_Expr('null'), 'modified' => new Zend_Db_Expr('null'))
199
+ );
200
+ }catch (Exception $e){
201
+ Mage::logException($e);
202
+ }
203
+
204
+ return $num;
205
+ }
206
+
207
+ /**
208
+ * set imported in bulk query
209
+ *
210
+ * @param $ids
211
+ */
212
+ private function _setImported($ids)
213
+ {
214
+ try{
215
+ $coreResource = Mage::getSingleton('core/resource');
216
+ $write = $coreResource->getConnection('core_write');
217
+ $tableName = $coreResource->getTableName('email_quote');
218
+ $ids = implode(', ', $ids);
219
+ $now = Mage::getSingleton('core/date')->gmtDate();
220
+ $write->update($tableName, array('imported' => 1, 'updated_at' => $now, 'modified' => new Zend_Db_Expr('null')), "quote_id IN ($ids)");
221
+ }catch (Exception $e){
222
+ Mage::logException($e);
223
+ }
224
+ }
225
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Automation.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Automation extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+
6
+ /**
7
+ * constructor.
8
+ */
9
+ protected function _construct()
10
+ {
11
+ $this->_init('ddg_automation/automation', 'id');
12
+
13
+ }
14
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Automation/Collection.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Automation_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
4
+ {
5
+ /**
6
+ * constructor.
7
+ */
8
+ protected function _construct()
9
+ {
10
+ parent::_construct();
11
+ $this->_init('ddg_automation/automation');
12
+ }
13
+
14
+
15
+ /**
16
+ * @param $website
17
+ * @return $this
18
+ */
19
+ public function addWebsiteFilter($website)
20
+ {
21
+ $this->addFilter('website_id', $website);
22
+ return $this;
23
+ }
24
+
25
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Campaign.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Campaign extends Mage_Core_Model_Resource_Db_Abstract
4
+ {
5
+ /**
6
+ * constructor.
7
+ */
8
+ protected function _construct()
9
+ {
10
+ $this->_init('ddg_automation/campaign', 'id');
11
+
12
+ }
13
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Campaign/Collection.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Campaign_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
4
+ {
5
+ /**
6
+ * constructor.
7
+ */
8
+ public function _construct()
9
+ {
10
+ parent::_construct();
11
+ $this->_init('ddg_automation/campaign');
12
+ }
13
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Catalog.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ }
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,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Contact extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+
6
+ /**
7
+ * constructor.
8
+ */
9
+ protected function _construct()
10
+ {
11
+ $this->_init('ddg_automation/contact', 'email_contact_id');
12
+
13
+ }
14
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Contact/Collection.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Contact_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
4
+ {
5
+ /**
6
+ * constructor.
7
+ */
8
+ protected function _construct()
9
+ {
10
+ parent::_construct();
11
+ $this->_init('ddg_automation/contact');
12
+ }
13
+
14
+
15
+ /**
16
+ * @param $website
17
+ * @return $this
18
+ */
19
+ public function addWebsiteFilter($website)
20
+ {
21
+ $this->addFilter('website_id', $website);
22
+ return $this;
23
+ }
24
+
25
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Importer.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
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
+ }
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,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Order extends Mage_Core_Model_Resource_Db_Abstract
4
+ {
5
+ /**
6
+ * cosntructor.
7
+ */
8
+ protected function _construct()
9
+ {
10
+ $this->_init('ddg_automation/order', 'email_order_id');
11
+ }
12
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Order/Collection.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Order_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
4
+ {
5
+
6
+ /**
7
+ * constructor.
8
+ */
9
+ public function _construct()
10
+ {
11
+ parent::_construct();
12
+ $this->_init('ddg_automation/order');
13
+ }
14
+
15
+
16
+
17
+
18
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Quote.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Quote extends Mage_Core_Model_Resource_Db_Abstract
4
+ {
5
+ /**
6
+ * constructor.
7
+ */
8
+ protected function _construct()
9
+ {
10
+ $this->_init('ddg_automation/quote', 'id');
11
+ }
12
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Quote/Collection.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Quote_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
4
+ {
5
+
6
+ /**
7
+ * constructor.
8
+ */
9
+ public function _construct()
10
+ {
11
+ parent::_construct();
12
+ $this->_init('ddg_automation/quote');
13
+ }
14
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Review.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Review extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+ /**
6
+ * constructor.
7
+ */
8
+ protected function _construct()
9
+ {
10
+ $this->_init('ddg_automation/review', 'id');
11
+
12
+ }
13
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Review/Collection.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Review_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
4
+ {
5
+ /**
6
+ * constructor.
7
+ */
8
+ public function _construct()
9
+ {
10
+ parent::_construct();
11
+ $this->_init('ddg_automation/review');
12
+ }
13
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/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,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Wishlist extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+ /**
6
+ * constructor.
7
+ */
8
+ protected function _construct()
9
+ {
10
+ $this->_init('ddg_automation/wishlist', 'id');
11
+
12
+ }
13
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Wishlist/Collection.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Wishlist_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
4
+ {
5
+ /**
6
+ * constructor.
7
+ */
8
+ public function _construct()
9
+ {
10
+ parent::_construct();
11
+ $this->_init('ddg_automation/wishlist');
12
+ }
13
+ }
app/code/community/Dotdigitalgroup/Email/Model/Review.php ADDED
@@ -0,0 +1,176 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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->_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
+ $reviews = $this->_getReviewsToExport($website, $limit);
87
+ $this->_reviewIds = array();
88
+
89
+ if($reviews->getSize()){
90
+ foreach($reviews as $review){
91
+ try {
92
+ $mageReview = Mage::getModel('review/review')->load($review->getReviewId());
93
+
94
+ $product = Mage::getModel('catalog/product')
95
+ ->setStoreId($mageReview->getStoreId())
96
+ ->load($mageReview->getEntityPkValue());
97
+
98
+ $customer = Mage::getModel('customer/customer')->load($mageReview->getCustomerId());
99
+
100
+ $connectorReview = Mage::getModel('ddg_automation/customer_review', $customer)
101
+ ->setReviewData($mageReview)
102
+ ->setProduct($product);
103
+
104
+ $votesCollection = Mage::getModel('rating/rating_option_vote')
105
+ ->getResourceCollection()
106
+ ->setReviewFilter($mageReview->getReviewId());
107
+ $votesCollection->getSelect()->join(
108
+ array('rating'=> 'rating'),
109
+ 'rating.rating_id = main_table.rating_id',
110
+ array('rating_code' => 'rating.rating_code')
111
+ );
112
+
113
+ foreach($votesCollection as $ratingItem){
114
+ $rating = Mage::getModel('ddg_automation/customer_review_rating', $ratingItem);
115
+ $connectorReview->createRating($ratingItem->getRatingCode(), $rating);
116
+ }
117
+ $this->_reviews[$website->getId()][] = $connectorReview;
118
+ $this->_reviewIds[] = $review->getReviewId();
119
+ }catch(Exception $e){
120
+ Mage::logException($e);
121
+ }
122
+ }
123
+ }
124
+ }
125
+
126
+ private function _getReviewsToExport(Mage_Core_Model_Website $website, $limit = 100)
127
+ {
128
+ return $this->getCollection()
129
+ ->addFieldToFilter('review_imported', array('null' => 'true'))
130
+ ->addFieldToFilter('store_id', array('in' => $website->getStoreIds()))
131
+ ->setPageSize($limit);
132
+ }
133
+
134
+ /**
135
+ * Reset the email reviews for reimport.
136
+ *
137
+ * @return int
138
+ */
139
+ public function reset()
140
+ {
141
+ /** @var $coreResource Mage_Core_Model_Resource */
142
+ $coreResource = Mage::getSingleton('core/resource');
143
+
144
+ /** @var $conn Varien_Db_Adapter_Pdo_Mysql */
145
+ $conn = $coreResource->getConnection('core_write');
146
+ try{
147
+ $num = $conn->update($coreResource->getTableName('ddg_automation/review'),
148
+ array('review_imported' => new Zend_Db_Expr('null')),
149
+ $conn->quoteInto('review_imported is ?', new Zend_Db_Expr('not null'))
150
+ );
151
+ }catch (Exception $e){
152
+ Mage::logException($e);
153
+ }
154
+
155
+ return $num;
156
+ }
157
+
158
+ /**
159
+ * set imported in bulk query
160
+ *
161
+ * @param $ids
162
+ */
163
+ private function _setImported($ids)
164
+ {
165
+ try{
166
+ $coreResource = Mage::getSingleton('core/resource');
167
+ $write = $coreResource->getConnection('core_write');
168
+ $tableName = $coreResource->getTableName('email_review');
169
+ $ids = implode(', ', $ids);
170
+ $now = Mage::getSingleton('core/date')->gmtDate();
171
+ $write->update($tableName, array('review_imported' => 1, 'updated_at' => $now), "review_id IN ($ids)");
172
+ }catch (Exception $e){
173
+ Mage::logException($e);
174
+ }
175
+ }
176
+ }
app/code/community/Dotdigitalgroup/Email/Model/Rules.php ADDED
@@ -0,0 +1,440 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $productModel = Mage::getModel('catalog/product');
342
+ foreach($collection as $collectionItem){
343
+ $items = $collectionItem->getAllItems();
344
+ foreach($items as $item){
345
+ $productId = $item->getProductId();
346
+ //loaded product
347
+ $product = $productModel
348
+ ->setStoreId($item->getStoreId())
349
+ ->load($productId);
350
+
351
+ //attributes array from loaded product
352
+ $attributes = Mage::getModel('eav/config')->getEntityAttributeCodes(
353
+ Mage_Catalog_Model_Product::ENTITY,
354
+ $product
355
+ );
356
+
357
+ foreach($this->_productAttribute as $productAttribute){
358
+ $attribute = $productAttribute['attribute'];
359
+ $cond = $productAttribute['conditions'];
360
+ $value = $productAttribute['cvalue'];
361
+
362
+ if($cond == 'null'){
363
+ if($value == '0')
364
+ $cond = 'neq';
365
+ elseif($value == '1')
366
+ $cond = 'eq';
367
+ $value = '';
368
+ }
369
+
370
+ //if attribute is in product's attributes array
371
+ if(in_array($attribute,$attributes)){
372
+ $attr = Mage::getSingleton('eav/config')->getAttribute('catalog_product', $attribute);
373
+ //frontend type
374
+ $frontType = $attr->getFrontend()->getInputType();
375
+ //if type is select
376
+ if($frontType == 'select' or $frontType == 'multiselect'){
377
+ $attributeValue = $product->getAttributeText($attribute);
378
+ //evaluate conditions on values. if true then unset item from collection
379
+ if($this->_evaluate($value, $cond, $attributeValue)){
380
+ $collection->removeItemByKey($collectionItem->getId());
381
+ continue 3;
382
+ }
383
+ }else{
384
+ $getter = 'get';
385
+ $exploded = explode('_', $attribute);
386
+ foreach ($exploded as $one) {
387
+ $getter .= ucfirst($one);
388
+ }
389
+ $attributeValue = call_user_func(array($product, $getter));
390
+ //if retrieved value is an array then loop through all array values. example can be categories
391
+ if(is_array($attributeValue)){
392
+ foreach($attributeValue as $attrValue){
393
+ //evaluate conditions on values. if true then unset item from collection
394
+ if($this->_evaluate($value, $cond, $attrValue)){
395
+ $collection->removeItemByKey($collectionItem->getId());
396
+ continue 3;
397
+ }
398
+ }
399
+ }
400
+ else{
401
+ //evaluate conditions on values. if true then unset item from collection
402
+ if($this->_evaluate($value, $cond, $attributeValue)){
403
+ $collection->removeItemByKey($collectionItem->getId());
404
+ continue 3;
405
+ }
406
+ }
407
+ }
408
+ }
409
+ }
410
+ }
411
+ }
412
+ return $collection;
413
+ }
414
+
415
+ /**
416
+ * evaluate two values against condition
417
+ *
418
+ * @param $var1
419
+ * @param $op
420
+ * @param $var2
421
+ * @return bool
422
+ */
423
+ private function _evaluate($var1, $op, $var2)
424
+ {
425
+ switch ($op) {
426
+ case "eq":
427
+ return $var1 == $var2;
428
+ case "neq":
429
+ return $var1 != $var2;
430
+ case "gteq":
431
+ return $var1 >= $var2;
432
+ case "lteq":
433
+ return $var1 <= $var2;
434
+ case "gt":
435
+ return $var1 > $var2;
436
+ case "lt":
437
+ return $var1 < $var2;
438
+ }
439
+ }
440
+ }
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,408 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $client = Mage::getModel('ddg_automation/apiconnector_client');
36
+ // Initialise a return hash containing results of our sync attempt
37
+ $this->_searchAccounts();
38
+ foreach ($this->accounts as $account) {
39
+ $orders = $account->getOrders();
40
+ $orderIds = $account->getOrderIds();
41
+ $ordersForSingleSync = $account->getOrdersForSingleSync();
42
+ $orderIdsForSingleSync = $account->getOrderIdsForSingleSync();
43
+ $numOrdersForSingleSync = count($ordersForSingleSync);
44
+ $website = $account->getWebsites();
45
+ $numOrders = count($orders);
46
+ $this->_countOrders += $numOrders;
47
+ $this->_countOrders += $numOrdersForSingleSync;
48
+ //send transactional for any number of orders set
49
+ if ($numOrders) {
50
+ Mage::helper('ddg')->log('--------- register Order sync with importer ---------- : ' . count($orders));
51
+ //register in queue with importer
52
+ $check = Mage::getModel('ddg_automation/importer')->registerQueue(
53
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_ORDERS,
54
+ $orders,
55
+ Dotdigitalgroup_Email_Model_Importer::MODE_BULK,
56
+ $website[0]
57
+ );
58
+ //if no error then set imported
59
+ if ($check) {
60
+ $this->_setImported($orderIds);
61
+ }
62
+ Mage::helper('ddg')->log('----------end order sync----------');
63
+ }
64
+
65
+ if ($numOrdersForSingleSync) {
66
+ $error = false;
67
+ foreach ($ordersForSingleSync as $order) {
68
+ Mage::helper('ddg')->log('--------- register Order sync in single with importer ---------- : ' . $order->id);
69
+ //register in queue with importer
70
+ $check = Mage::getModel('ddg_automation/importer')->registerQueue(
71
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_ORDERS,
72
+ $order,
73
+ Dotdigitalgroup_Email_Model_Importer::MODE_SINGLE,
74
+ $website[0]
75
+ );
76
+ if (!$check) {
77
+ $error = true;
78
+ }
79
+ Mage::helper('ddg')->log('----------end order sync in single----------');
80
+ }
81
+ //if no error then set imported
82
+ if (!$error) {
83
+ $this->_setImported($orderIdsForSingleSync, true);
84
+ }
85
+ }
86
+ unset($this->accounts[$account->getApiUsername()]);
87
+ }
88
+
89
+ if ($this->_countOrders)
90
+ $response['message'] = 'Number of updated orders : ' . $this->_countOrders;
91
+ return $response;
92
+ }
93
+
94
+ /**
95
+ * Search the configuration data per website
96
+ */
97
+ private function _searchAccounts()
98
+ {
99
+ $helper = Mage::helper('ddg');
100
+ $this->_orderIds = array();
101
+ foreach (Mage::app()->getWebsites(true) as $website) {
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
+ $this->accounts[$this->_apiUsername]->setOrders($this->getConnectorOrders($website, $limit));
117
+ $this->accounts[$this->_apiUsername]->setOrderIds($this->_orderIds);
118
+ $this->accounts[$this->_apiUsername]->setWebsites($website->getId());
119
+ $this->accounts[$this->_apiUsername]->setOrdersForSingleSync($this->getConnectorOrders($website, $limit, true));
120
+ $this->accounts[$this->_apiUsername]->setOrderIdsForSingleSync($this->_orderIdsForSingleSync);
121
+ }
122
+ }
123
+ }
124
+
125
+ /**
126
+ * get all order to import.
127
+ * @param $website
128
+ * @param int $limit
129
+ * @param $modified
130
+ *
131
+ * @return array
132
+ */
133
+ public function getConnectorOrders($website, $limit = 100, $modified = false)
134
+ {
135
+ $orders = $customers = array();
136
+ $storeIds = $website->getStoreIds();
137
+ $orderModel = Mage::getModel('ddg_automation/order');
138
+ if(empty($storeIds))
139
+ return array();
140
+
141
+ $helper = Mage::helper('ddg');
142
+ $orderStatuses = $helper->getConfigSelectedStatus($website);
143
+
144
+ if ($orderStatuses) {
145
+ if ($modified)
146
+ $orderCollection = $orderModel->getOrdersToImport($storeIds, $limit, $orderStatuses, true);
147
+ else
148
+ $orderCollection = $orderModel->getOrdersToImport($storeIds, $limit, $orderStatuses);
149
+ }
150
+ else
151
+ return array();
152
+
153
+ foreach ($orderCollection as $order) {
154
+ try {
155
+ $salesOrder = Mage::getModel('sales/order')->load($order->getOrderId());
156
+ $storeId = $order->getStoreId();
157
+ $websiteId = Mage::app()->getStore($storeId)->getWebsiteId();
158
+ /**
159
+ * Add guest to contacts table.
160
+ */
161
+ if ($salesOrder->getCustomerIsGuest()) {
162
+ $this->_createGuestContact($salesOrder->getCustomerEmail(), $websiteId, $storeId);
163
+ }
164
+ if ($salesOrder->getId()) {
165
+ $connectorOrder = Mage::getModel('ddg_automation/connector_order', $salesOrder);
166
+ $orders[] = $connectorOrder;
167
+ }
168
+ if ($modified)
169
+ $this->_orderIdsForSingleSync[] = $order->getOrderId();
170
+ else
171
+ $this->_orderIds[] = $order->getOrderId();
172
+ }catch(Exception $e){
173
+ Mage::logException($e);
174
+ }
175
+ }
176
+ return $orders;
177
+ }
178
+
179
+ /**
180
+ * Create a guest contact.
181
+ * @param $email
182
+ * @param $websiteId
183
+ * @param $storeId
184
+ *
185
+ * @return bool
186
+ */
187
+ private function _createGuestContact($email, $websiteId, $storeId){
188
+ try{
189
+ $client = Mage::helper('ddg')->getWebsiteApiClient($websiteId);
190
+
191
+ //no api credentials or the guest has no been mapped
192
+ if (! $client || ! $addressBookId = Mage::helper('ddg')->getGuestAddressBook($websiteId))
193
+ return false;
194
+
195
+ $contactModel = Mage::getModel('ddg_automation/contact')->loadByCustomerEmail($email, $websiteId);
196
+
197
+ //check if contact exists, create if not
198
+ $contactApi = $client->postContacts($email);
199
+
200
+ //contact is suppressed cannot add to address book, mark as suppressed.
201
+ if (isset($contactApi->message) && $contactApi->message == 'Contact is suppressed. ERROR_CONTACT_SUPPRESSED'){
202
+ //mark new contacts as guest.
203
+ if ($contactModel->isObjectNew())
204
+ $contactModel->setIsGuest(1);
205
+ $contactModel->setSuppressed(1);
206
+ $contactModel->save();
207
+ return;
208
+ }
209
+
210
+ //add guest to address book
211
+ $response = $client->postAddressBookContacts($addressBookId, $contactApi);
212
+ //set contact as was found as guest and
213
+ $contactModel->setIsGuest(1)
214
+ ->setStoreId($storeId)
215
+ ->setEmailImported(1);
216
+ //contact id
217
+ if (isset($contactApi->id))
218
+ $contactModel->setContactId();
219
+ //mark the contact as surpressed
220
+ if (isset($response->message) && $response->message == 'Contact is suppressed. ERROR_CONTACT_SUPPRESSED')
221
+ $contactModel->setSuppressed(1);
222
+ //save
223
+ $contactModel->save();
224
+
225
+ Mage::helper('ddg')->log('-- guest found : ' . $email . ' website : ' . $websiteId . ' ,store : ' . $storeId);
226
+ }catch(Exception $e){
227
+ Mage::logException($e);
228
+ }
229
+
230
+ return true;
231
+ }
232
+
233
+
234
+ /**
235
+ * create review campaigns
236
+ *
237
+ * @return bool
238
+ */
239
+ public function createReviewCampaigns()
240
+ {
241
+ $this->searchOrdersForReview();
242
+
243
+ foreach($this->_reviewCollection as $websiteId => $collection){
244
+ $this->registerCampaign($collection, $websiteId);
245
+ }
246
+ }
247
+
248
+ /**
249
+ * register review campaign
250
+ *
251
+ * @param $collection
252
+ * @param $websiteId
253
+ *
254
+ * @throws Exception
255
+ */
256
+ private function registerCampaign($collection, $websiteId)
257
+ {
258
+ $helper = Mage::helper('ddg/review');
259
+ $campaignId = $helper->getCampaign($websiteId);
260
+
261
+ if($campaignId) {
262
+ foreach ($collection as $order) {
263
+ Mage::helper('ddg')->log('-- Order Review: ' . $order->getIncrementId() . ' Campaign Id: ' . $campaignId);
264
+
265
+ try {
266
+ $emailCampaign = Mage::getModel('ddg_automation/campaign');
267
+ $emailCampaign
268
+ ->setEmail($order->getCustomerEmail())
269
+ ->setStoreId($order->getStoreId())
270
+ ->setCampaignId($campaignId)
271
+ ->setEventName('Order Review')
272
+ ->setCreatedAt(Mage::getSingleton('core/date')->gmtDate())
273
+ ->setOrderIncrementId($order->getIncrementId())
274
+ ->setQuoteId($order->getQuoteId());
275
+
276
+ if($order->getCustomerId())
277
+ $emailCampaign->setCustomerId($order->getCustomerId());
278
+
279
+ $emailCampaign->save();
280
+ } catch (Exception $e) {
281
+ Mage::logException($e);
282
+ }
283
+ }
284
+ }
285
+ }
286
+
287
+ /**
288
+ * search for orders to review per website
289
+ */
290
+ private function searchOrdersForReview()
291
+ {
292
+ $helper = Mage::helper('ddg/review');
293
+
294
+ foreach (Mage::app()->getWebsites(true) as $website){
295
+ $apiEnabled = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED, $website);
296
+ if($apiEnabled && $helper->isEnabled($website) &&
297
+ $helper->getOrderStatus($website) &&
298
+ $helper->getDelay($website)){
299
+
300
+ $storeIds = $website->getStoreIds();
301
+ if(empty($storeIds))
302
+ return;
303
+
304
+ $orderStatusFromConfig = $helper->getOrderStatus($website);
305
+ $delayInDays = $helper->getDelay($website);
306
+
307
+ $campaignCollection = Mage::getModel('ddg_automation/campaign')->getCollection();
308
+ $campaignCollection
309
+ ->addFieldToFilter('event_name', 'Order Review')
310
+ ->load();
311
+
312
+ $campaignOrderIds = $campaignCollection->getColumnValues('order_increment_id');
313
+
314
+ $to = Mage::app()->getLocale()->date()
315
+ ->subDay($delayInDays);
316
+ $from = clone $to;
317
+ $to = $to->toString('YYYY-MM-dd HH:mm:ss');
318
+ $from = $from->subHour(2)
319
+ ->toString('YYYY-MM-dd HH:mm:ss');
320
+
321
+ $created = array( 'from' => $from, 'to' => $to, 'date' => true);
322
+
323
+ $collection = Mage::getModel('sales/order')->getCollection();
324
+ $collection->addFieldToFilter('main_table.status', $orderStatusFromConfig)
325
+ ->addFieldToFilter('main_table.created_at', $created)
326
+ ->addFieldToFilter('main_table.store_id', array('in' => $storeIds));
327
+
328
+ if(!empty($campaignOrderIds))
329
+ $collection->addFieldToFilter('main_table.increment_id', array('nin' => $campaignOrderIds));
330
+
331
+ //process rules on collection
332
+ $ruleModel = Mage::getModel('ddg_automation/rules');
333
+ $collection = $ruleModel->process(
334
+ $collection, Dotdigitalgroup_Email_Model_Rules::REVIEW, $website->getId()
335
+ );
336
+
337
+ if($collection->getSize())
338
+ $this->_reviewCollection[$website->getId()] = $collection;
339
+ }
340
+ }
341
+ }
342
+
343
+ /**
344
+ * get customer last order id
345
+ *
346
+ * @param Mage_Customer_Model_Customer $customer
347
+ * @return bool|Varien_Object
348
+ */
349
+ public function getCustomerLastOrderId(Mage_Customer_Model_Customer $customer)
350
+ {
351
+ $storeIds = Mage::app()->getWebsite($customer->getWebsiteId())->getStoreIds();
352
+ $collection = Mage::getModel('sales/order')->getCollection();
353
+ $collection->addFieldToFilter('customer_id', $customer->getId())
354
+ ->addFieldToFilter('store_id', array('in' => $storeIds))
355
+ ->setPageSize(1)
356
+ ->setOrder('entity_id');
357
+
358
+ if ($collection->count())
359
+ return $collection->getFirstItem();
360
+ else
361
+ return false;
362
+ }
363
+
364
+ /**
365
+ * get customer last quote id
366
+ *
367
+ * @param Mage_Customer_Model_Customer $customer
368
+ * @return bool|Varien_Object
369
+ */
370
+ public function getCustomerLastQuoteId(Mage_Customer_Model_Customer $customer)
371
+ {
372
+ $storeIds = Mage::app()->getWebsite($customer->getWebsiteId())->getStoreIds();
373
+ $collection = Mage::getModel('sales/quote')->getCollection();
374
+ $collection->addFieldToFilter('customer_id', $customer->getId())
375
+ ->addFieldToFilter('store_id', array('in' => $storeIds))
376
+ ->setPageSize(1)
377
+ ->setOrder('entity_id');
378
+
379
+ if ($collection->count())
380
+ return $collection->getFirstItem();
381
+ else
382
+ return false;
383
+ }
384
+
385
+ /**
386
+ * set imported in bulk query
387
+ *
388
+ * @param $ids
389
+ * @param $modified
390
+ */
391
+ private function _setImported($ids, $modified = false)
392
+ {
393
+ try{
394
+ $coreResource = Mage::getSingleton('core/resource');
395
+ $write = $coreResource->getConnection('core_write');
396
+ $tableName = $coreResource->getTableName('email_order');
397
+ $ids = implode(', ', $ids);
398
+ $now = Mage::getSingleton('core/date')->gmtDate();
399
+
400
+ if ($modified)
401
+ $write->update($tableName, array('modified' => new Zend_Db_Expr('null'), 'updated_at' => $now), "order_id IN ($ids)");
402
+ else
403
+ $write->update($tableName, array('email_imported' => 1, 'updated_at' => $now), "order_id IN ($ids)");
404
+ }catch (Exception $e){
405
+ Mage::logException($e);
406
+ }
407
+ }
408
+ }
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,251 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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->_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
+ $collection = $this->_getWishlistToImport($website, $limit);
100
+ foreach($collection as $emailWishlist){
101
+ $customer = Mage::getModel('customer/customer')->load($emailWishlist->getCustomerId());
102
+ $wishlist = Mage::getModel('wishlist/wishlist')->load($emailWishlist->getWishlistId());
103
+ /** @var $connectorWishlist */
104
+ $connectorWishlist = Mage::getModel('ddg_automation/customer_wishlist', $customer);
105
+ $connectorWishlist->setId($wishlist->getId())
106
+ ->setUpdatedAt($wishlist->getUpdatedAt());
107
+ $wishListItemCollection = $wishlist->getItemCollection();
108
+ if ($wishListItemCollection->getSize()) {
109
+ foreach ($wishListItemCollection as $item) {
110
+ /* @var $product Mage_Catalog_Model_Product */
111
+ $product = $item->getProduct();
112
+ $wishlistItem = Mage::getModel('ddg_automation/customer_wishlist_item', $product)
113
+ ->setQty($item->getQty())
114
+ ->setPrice($product);
115
+ //store for wishlists
116
+ $connectorWishlist->setItem($wishlistItem);
117
+ $this->_count++;
118
+ }
119
+ //set wishlists for later use
120
+ $this->_wishlists[$website->getId()][] = $connectorWishlist;
121
+ $this->_wishlistIds[] = $emailWishlist->getWishlistId();
122
+ }
123
+ }
124
+ }
125
+
126
+ private function _getWishlistToImport(Mage_Core_Model_Website $website, $limit = 100)
127
+ {
128
+ $collection = $this->getCollection()
129
+ ->addFieldToFilter('wishlist_imported', array('null' => true))
130
+ ->addFieldToFilter('store_id', array('in' => $website->getStoreIds()))
131
+ ->addFieldToFilter('item_count', array('gt' => 0));
132
+
133
+ $collection->getSelect()->limit($limit);
134
+ return $collection;
135
+ }
136
+
137
+ private function _exportWishlistForWebsiteInSingle(Mage_Core_Model_Website $website)
138
+ {
139
+ $helper = Mage::helper('ddg');
140
+ $client = $helper->getWebsiteApiClient($website);
141
+ $limit = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_TRANSACTIONAL_DATA_SYNC_LIMIT, $website);
142
+ $collection = $this->_getModifiedWishlistToImport($website, $limit);
143
+ $this->_wishlistIds = array();
144
+ foreach($collection as $emailWishlist){
145
+ $customer = Mage::getModel('customer/customer')->load($emailWishlist->getCustomerId());
146
+ $wishlist = Mage::getModel('wishlist/wishlist')->load($emailWishlist->getWishlistId());
147
+ /** @var $connectorWishlist */
148
+ $connectorWishlist = Mage::getModel('ddg_automation/customer_wishlist', $customer);
149
+ $connectorWishlist->setId($wishlist->getId());
150
+ $wishListItemCollection = $wishlist->getItemCollection();
151
+ if ($wishListItemCollection->getSize()) {
152
+ foreach ($wishListItemCollection as $item) {
153
+ /* @var $product Mage_Catalog_Model_Product */
154
+ $product = $item->getProduct();
155
+ $wishlistItem = Mage::getModel('ddg_automation/customer_wishlist_item', $product)
156
+ ->setQty($item->getQty())
157
+ ->setPrice($product);
158
+ //store for wishlists
159
+ $connectorWishlist->setItem($wishlistItem);
160
+ $this->_count++;
161
+ }
162
+ //send wishlist as transactional data
163
+ $helper->log('---------- Start wishlist single sync ----------');
164
+ $this->_start = microtime(true);
165
+ //register in queue with importer
166
+ $check = Mage::getModel('ddg_automation/importer')->registerQueue(
167
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_WISHLIST,
168
+ $connectorWishlist,
169
+ Dotdigitalgroup_Email_Model_Importer::MODE_SINGLE,
170
+ $website->getId()
171
+ );
172
+ if ($check) {
173
+ $this->_wishlistIds[] = $emailWishlist->getWishlistId();
174
+ }
175
+ $message = 'Total time for wishlist single sync : ' . gmdate("H:i:s", microtime(true) - $this->_start);
176
+ $helper->log($message);
177
+ }else{
178
+ //register in queue with importer
179
+ $check = Mage::getModel('ddg_automation/importer')->registerQueue(
180
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_WISHLIST,
181
+ array($wishlist->getId()),
182
+ Dotdigitalgroup_Email_Model_Importer::MODE_SINGLE_DELETE,
183
+ $website->getId()
184
+ );
185
+ if ($check) {
186
+ $this->_wishlistIds[] = $emailWishlist->getWishlistId();
187
+ }
188
+ $message = 'Total time for wishlist single sync : ' . gmdate("H:i:s", microtime(true) - $this->_start);
189
+ $helper->log($message);
190
+ }
191
+ }
192
+ if(!empty($this->_wishlistIds))
193
+ $this->_setImported($this->_wishlistIds, true);
194
+ }
195
+
196
+ private function _getModifiedWishlistToImport(Mage_Core_Model_Website $website, $limit = 100)
197
+ {
198
+ $collection = $this->getCollection()
199
+ ->addFieldToFilter('wishlist_modified', 1)
200
+ ->addFieldToFilter('store_id', array('in' => $website->getStoreIds()));
201
+
202
+ $collection->getSelect()->limit($limit);
203
+ return $collection;
204
+ }
205
+
206
+ /**
207
+ * Reset the email reviews for reimport.
208
+ *
209
+ * @return int
210
+ */
211
+ public function reset()
212
+ {
213
+ /** @var $coreResource Mage_Core_Model_Resource */
214
+ $coreResource = Mage::getSingleton('core/resource');
215
+
216
+ /** @var $conn Varien_Db_Adapter_Pdo_Mysql */
217
+ $conn = $coreResource->getConnection('core_write');
218
+ try{
219
+ $num = $conn->update($coreResource->getTableName('ddg_automation/wishlist'),
220
+ array('wishlist_imported' => new Zend_Db_Expr('null'), 'wishlist_modified' => new Zend_Db_Expr('null'))
221
+ );
222
+ }catch (Exception $e){
223
+ Mage::logException($e);
224
+ }
225
+
226
+ return $num;
227
+ }
228
+
229
+ /**
230
+ * set imported in bulk query
231
+ *
232
+ * @param $ids
233
+ * @param $modified
234
+ */
235
+ private function _setImported($ids, $modified = false)
236
+ {
237
+ try{
238
+ $coreResource = Mage::getSingleton('core/resource');
239
+ $write = $coreResource->getConnection('core_write');
240
+ $tableName = $coreResource->getTableName('email_wishlist');
241
+ $ids = implode(', ', $ids);
242
+ $now = Mage::getSingleton('core/date')->gmtDate();
243
+ if($modified)
244
+ $write->update($tableName, array('wishlist_modified' => new Zend_Db_Expr('null'), 'updated_at' => $now), "wishlist_id IN ($ids)");
245
+ else
246
+ $write->update($tableName, array('wishlist_imported' => 1, 'updated_at' => $now), "wishlist_id IN ($ids)");
247
+ }catch (Exception $e){
248
+ Mage::logException($e);
249
+ }
250
+ }
251
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/ConnectorController.php ADDED
@@ -0,0 +1,438 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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::getModel('ddg_automation/order')->resetOrders();
61
+ Mage::helper('ddg')->log('-- Reset Orders for reimport : ' . $num);
62
+ Mage::getSingleton('adminhtml/session')->addSuccess('Done.');
63
+ $this->_redirectReferer();
64
+ }
65
+
66
+ /**
67
+ * Reset customers import.
68
+ */
69
+ public function resetcustomersimportAction()
70
+ {
71
+ Mage::getModel('ddg_automation/contact')->resetAllContacts();
72
+
73
+ Mage::getSingleton('adminhtml/session')->addSuccess('Done.');
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
+ /** @var $coreResource Mage_Core_Model_Resource */
95
+ $coreResource = Mage::getSingleton('core/resource');
96
+
97
+ /** @var $conn Varien_Db_Adapter_Pdo_Mysql */
98
+ $conn = $coreResource->getConnection('core_write');
99
+ try{
100
+ $num = $conn->update($coreResource->getTableName('ddg_automation/contact'),
101
+ array('contact_id' => new Zend_Db_Expr('null')),
102
+ $conn->quoteInto('contact_id is ?', new Zend_Db_Expr('not null'))
103
+ );
104
+ }catch (Exception $e){
105
+ Mage::logException($e);
106
+ }
107
+ Mage::getSingleton('adminhtml/session')->addSuccess('Number Of Contacts Id Removed: '. $num);
108
+ $this->_redirectReferer();
109
+ }
110
+
111
+ /**
112
+ * Ajax API validation.
113
+ */
114
+ public function ajaxvalidationAction()
115
+ {
116
+ $params = $this->getRequest()->getParams();
117
+ $apiUsername = $params['api_username'];
118
+ // use javascript btoa function to encode the password
119
+
120
+ $apiPassword = base64_decode($params['api_password']);
121
+ $message = Mage::getModel('ddg_automation/apiconnector_test')->ajaxvalidate($apiUsername, $apiPassword);
122
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($message));
123
+ }
124
+
125
+ /**
126
+ * Ajax request to reset the import for contacts.
127
+ */
128
+ public function resetcontactsajaxAction()
129
+ {
130
+ $numReseted = Mage::getModel('ddg_automation/contact')->resetAllContacts();
131
+ $message = array('reseted' => $numReseted);
132
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($message));
133
+ }
134
+
135
+ /**
136
+ * Ajax requets to reset susbcribers for reimport.
137
+ */
138
+ public function ajaxresetsubscribersAction()
139
+ {
140
+ $num = Mage::getModel('ddg_automation/contact')->resetSubscribers();
141
+ $message = array('reseted' => $num);
142
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($message));
143
+ }
144
+
145
+ /**
146
+ * Ajax request to reset orders for reimoport.
147
+ */
148
+ public function ajaxresetguestsAction()
149
+ {
150
+ $num = Mage::getModel('ddg_automation/contact')->resetAllGuestContacts();
151
+ $message = array('reseted' => $num);
152
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($message));
153
+ }
154
+
155
+ public function createnewdatafieldAction()
156
+ {
157
+ //get params required for datafield
158
+ $request = $this->getRequest();
159
+ $name = $request->getParam('name', false);
160
+ $type = $request->getParam('type', false);
161
+ $default = $request->getParam('default', 0);
162
+ $access = $request->getParam('access', false);
163
+ $website = $request->getParam('website', 0);
164
+
165
+ //api client for this website
166
+ $client = Mage::helper('ddg')->getWebsiteApiClient($website);
167
+ //only if all data is available
168
+ if ($name && $type && $access) {
169
+ //create datafield
170
+ $response = $client->postDataFields($name, $type, $access, $default);
171
+ //error creating datafield message
172
+ if (isset($response->message)) {
173
+ //send error message to backend
174
+ Mage::getSingleton('adminhtml/session')->addError($response->message);
175
+ Mage::helper('ddg')->log($response->message);
176
+ } else {
177
+ //success message
178
+ Mage::getSingleton('adminhtml/session')->addSuccess('Datafield created : ' . $name);
179
+ }
180
+ } else {
181
+ $message = 'Name ' . $name . ', type ' . $type . ' default ' . $default . 'access ' . $access;
182
+ Mage::getSingleton('adminhtml/session')->addError('Datafield cannot be empty.');
183
+ Mage::helper('ddg')->rayLog('100', $message);
184
+ }
185
+ }
186
+
187
+ /**
188
+ * Create new address book action.
189
+ */
190
+ public function createnewaddressbookAction()
191
+ {
192
+ $addressBookName = $this->getRequest()->getParam('name');
193
+ $visibility = $this->getRequest()->getParam('visibility');
194
+ $website = $this->getRequest()->getParam('website', 0);
195
+ $client = Mage::helper('ddg')->getWebsiteApiClient($website);
196
+ if (strlen($addressBookName)) {
197
+ $response = $client->postAddressBooks($addressBookName, $visibility);
198
+ if (isset($response->message))
199
+ Mage::getSingleton('adminhtml/session')->addError($response->message);
200
+ else
201
+ Mage::getSingleton('adminhtml/session')->addSuccess('Address book : '. $addressBookName . ' created.');
202
+ }
203
+
204
+ }
205
+
206
+ public function reimoprtsubscribersAction()
207
+ {
208
+ $updated = Mage::getModel('ddg_automation/contact')->resetSubscribers();
209
+ if ($updated) {
210
+ Mage::getSingleton('adminhtml/session')->addSuccess('Done.');
211
+ } else {
212
+ Mage::getSingleton('adminhtml/session')->addNotice('No subscribers imported!');
213
+ }
214
+ $this->_redirectReferer();
215
+ }
216
+
217
+ /**
218
+ * path constant for config helper sent as string.
219
+ */
220
+ public function enablewebsiteconfigurationAction()
221
+ {
222
+ $path = $this->getRequest()->getParam('path');
223
+ $value = $this->getRequest()->getParam('value');
224
+ $website = $this->getRequest()->getParam('website', 0);
225
+
226
+ $path = constant('Dotdigitalgroup_Email_Helper_Config::' . $path);
227
+ $scope = 'websites';
228
+ $scopeId = $website;
229
+
230
+ $config = Mage::getConfig();
231
+
232
+ //use value 1 if not set
233
+ if (isset($value))
234
+ $config->saveConfig($path, $value, $scope, $scopeId);
235
+ else
236
+ $config->saveConfig($path, 1, $scope, $scopeId);
237
+
238
+ //clean cache
239
+ $config->cleanCache();
240
+
241
+ $this->_redirectReferer();
242
+ }
243
+
244
+ /**
245
+ * Populate the tables (customer-email_contact, subscribers-email_contact) with missing ones.
246
+ */
247
+ public function populatecontactsAction()
248
+ {
249
+
250
+ //type of data to bring up-to-date
251
+ $type = $this->getRequest()->getParam('type', false);
252
+ $website = $this->getRequest()->getParam('website', false);
253
+ //required data not set
254
+ if (!$type && $website == false) {
255
+ return ;
256
+ }
257
+
258
+ $contactTable = Mage::getSingleton('core/resource')->getTableName('ddg_automation/contact');
259
+
260
+ $customerCollection = Mage::getModel('customer/customer')->getCollection()
261
+ ->addFieldToFilter('website_id', $website);
262
+
263
+ $customerCollection->getSelect()
264
+ ->joinLeft(array('ec' => $contactTable), 'e.entity_id = ec.customer_id', array('customer_id' => 'ec.customer_id'))
265
+ ->where('ec.customer_id IS NULL');
266
+
267
+ //found customers t
268
+ if ($count = $customerCollection->getSize()) {
269
+ //trigger the save to update the contact table
270
+ foreach ( $customerCollection as $customer ) {
271
+ $customer->save();
272
+ }
273
+
274
+ Mage::getSingleton( 'adminhtml/session' )->addSuccess( "Total contacts populated : " . $count );
275
+ }
276
+ $this->_redirectReferer();
277
+ }
278
+
279
+ /**
280
+ * Trigger to run the contact sync.
281
+ */
282
+ public function runcontactsyncAction()
283
+ {
284
+ $result = Mage::getModel('ddg_automation/cron')->contactSync();
285
+
286
+ if ($result['message'])
287
+ Mage::getSingleton('adminhtml/session')->addSuccess($result['message']);
288
+
289
+ $this->_redirectReferer();
290
+ }
291
+
292
+ /**
293
+ * Trigger to run the subscriber sync.
294
+ */
295
+ public function runsubscribersyncAction()
296
+ {
297
+ $result = Mage::getModel('ddg_automation/cron')->subscribersAndGuestSync();
298
+
299
+ if ($result['message'])
300
+ Mage::getSingleton('adminhtml/session')->addSuccess($result['message']);
301
+
302
+ $this->_redirectReferer();
303
+ }
304
+
305
+ /**
306
+ * Trigger to run the order sync.
307
+ */
308
+ public function runordersyncAction()
309
+ {
310
+
311
+ $result = Mage::getModel('ddg_automation/cron')->orderSync();
312
+ if ($result['message'])
313
+ Mage::getSingleton('adminhtml/session')->addSuccess($result['message']);
314
+
315
+ $this->_redirectReferer();
316
+ }
317
+
318
+ /**
319
+ * Trigger to run the review sync.
320
+ */
321
+ public function runreviewsyncAction()
322
+ {
323
+
324
+ $result = Mage::getModel('ddg_automation/cron')->reviewSync();
325
+ if ($result['message'])
326
+ Mage::getSingleton('adminhtml/session')->addSuccess($result['message']);
327
+
328
+ $this->_redirectReferer();
329
+ }
330
+
331
+ /**
332
+ * Trigger to run the reviw sync.
333
+ */
334
+ public function runwishlistsyncAction()
335
+ {
336
+
337
+ $result = Mage::getModel('ddg_automation/wishlist')->sync();
338
+ if ($result['message'])
339
+ Mage::getSingleton('adminhtml/session')->addSuccess($result['message']);
340
+
341
+ $this->_redirectReferer();
342
+ }
343
+
344
+ /**
345
+ * Trigger to run the quote sync.
346
+ */
347
+ public function runquotesyncAction()
348
+ {
349
+
350
+ $result = Mage::getModel('ddg_automation/cron')->quoteSync();
351
+ if ($result['message'])
352
+ Mage::getSingleton('adminhtml/session')->addSuccess($result['message']);
353
+
354
+ $this->_redirectReferer();
355
+ }
356
+
357
+ /**
358
+ * Reset quote for reimport.
359
+ */
360
+ public function resetquotesAction()
361
+ {
362
+ $num = Mage::getModel('ddg_automation/quote')->resetQuotes();
363
+ Mage::helper('ddg')->log('-- Reset Quotes for reimport : ' . $num);
364
+ Mage::getSingleton('adminhtml/session')->addSuccess('Done.');
365
+ $this->_redirectReferer();
366
+ }
367
+
368
+ /**
369
+ * Reset reviews for reimport.
370
+ */
371
+ public function resetreviewsAction()
372
+ {
373
+ $num = Mage::getModel('ddg_automation/review')->reset();
374
+ Mage::helper('ddg')->log('-- Reset Reviews for reimport : ' . $num);
375
+ Mage::getSingleton('adminhtml/session')->addSuccess('Done.');
376
+ $this->_redirectReferer();
377
+ }
378
+
379
+ /**
380
+ * Reset wishlist for reimport.
381
+ */
382
+ public function resetwishlistsAction()
383
+ {
384
+ $num = Mage::getModel('ddg_automation/wishlist')->reset();
385
+ Mage::helper('ddg')->log('-- Reset Wishlist for reimport : ' . $num);
386
+ Mage::getSingleton('adminhtml/session')->addSuccess('Done.');
387
+ $this->_redirectReferer();
388
+ }
389
+
390
+ /**
391
+ * Re-set all tables
392
+ */
393
+ public function resetAction()
394
+ {
395
+ /** @var $coreResource Mage_Core_Model_Resource */
396
+ $coreResource = Mage::getSingleton('core/resource');
397
+
398
+ /** @var $conn Varien_Db_Adapter_Pdo_Mysql */
399
+ $conn = $coreResource->getConnection('core_write');
400
+ try{
401
+ //remove dotmailer code from core_resource table
402
+ $cond = $conn->quoteInto('code = ?', 'email_connector_setup');
403
+ $conn->delete($coreResource->getTableName('core_resource'), $cond);
404
+
405
+ //clean cache
406
+ Mage::app()->getCacheInstance()->flush();
407
+
408
+ }catch (Exception $e){
409
+ Mage::logException($e);
410
+ }
411
+ Mage::getSingleton('adminhtml/session')->addSuccess('All tables successfully reset.');
412
+ $this->_redirectReferer();
413
+ }
414
+
415
+ /**
416
+ * Reset catalog for reimport.
417
+ */
418
+ public function resetcatalogAction()
419
+ {
420
+ $num = Mage::getModel('ddg_automation/catalog')->reset();
421
+ Mage::helper('ddg')->log('-- Reset Catalog for reimport : ' . $num);
422
+ Mage::getSingleton('adminhtml/session')->addSuccess('Done.');
423
+ $this->_redirectReferer();
424
+ }
425
+
426
+ /**
427
+ * Trigger to run the catalog sync.
428
+ */
429
+ public function runcatalogsyncAction()
430
+ {
431
+
432
+ $result = Mage::getModel('ddg_automation/cron')->catalogSync();
433
+ if ($result['message'])
434
+ Mage::getSingleton('adminhtml/session')->addSuccess($result['message']);
435
+
436
+ $this->_redirectReferer();
437
+ }
438
+ }
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,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Adminhtml_Email_AutomationController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+
6
+ protected function _construct(){
7
+ $this->setUsedModuleName('Dotdigitalgroup_Email');
8
+ }
9
+
10
+ /**
11
+ * main page.
12
+ */
13
+ public function indexAction()
14
+ {
15
+ $this->_title($this->__('Automation'))
16
+ ->_title($this->__('Automation Status'));
17
+ $this->loadLayout();
18
+ $this->_setActiveMenu('email_connector');
19
+ $this->renderLayout();
20
+ }
21
+
22
+ public function editAction()
23
+ {
24
+ $this->_redirect('*/*');
25
+ }
26
+
27
+ /**
28
+ * main grid.
29
+ */
30
+ public function gridAction(){
31
+ $this->loadLayout();
32
+ $this->renderLayout();
33
+ }
34
+
35
+ /**
36
+ * Delete action.
37
+ */
38
+ public function massDeleteAction()
39
+ {
40
+ $automationIds = $this->getRequest()->getParam('automation');
41
+ if (!is_array($automationIds)) {
42
+ $this->_getSession()->addError($this->__('Please select .'));
43
+ }else {
44
+ try {
45
+ foreach ($automationIds as $id) {
46
+ $automation = Mage::getSingleton('ddg_automation/automation')->load($id);
47
+ Mage::dispatchEvent('connector_controller_automation_delete', array('automation' => $automation));
48
+ $automation->delete();
49
+ }
50
+ $this->_getSession()->addSuccess(
51
+ Mage::helper('ddg')->__('Total of %d record(s) have been deleted.', count($automationIds))
52
+ );
53
+ } catch (Exception $e) {
54
+ $this->_getSession()->addError($e->getMessage());
55
+ }
56
+ }
57
+ $this->_redirect('*/*/index');
58
+ }
59
+
60
+ /**
61
+ * Mark for resend.
62
+ */
63
+ public function massResendAction()
64
+ {
65
+ $automationIds = $this->getRequest()->getParam('automation');
66
+ if (!is_array($automationIds)) {
67
+ $this->_getSession()->addError($this->__('Please select .'));
68
+ }else {
69
+ try {
70
+
71
+ /** @var $coreResource Mage_Core_Model_Resource */
72
+ $coreResource = Mage::getSingleton('core/resource');
73
+
74
+ /** @var $conn Varien_Db_Adapter_Pdo_Mysql */
75
+ $conn = $coreResource->getConnection('core_write');
76
+
77
+ $num = $conn->update($coreResource->getTableName('ddg_automation/automation'),
78
+ array('enrolment_status' => new Zend_Db_Expr('null')),
79
+ array('id IN(?)' => $automationIds)
80
+ );
81
+
82
+ $this->_getSession()->addSuccess(
83
+ Mage::helper('ddg')->__('Total of %d record(s) have been deleted.', $num)
84
+ );
85
+ } catch (Exception $e) {
86
+ $this->_getSession()->addError($e->getMessage());
87
+ }
88
+ }
89
+ $this->_redirect('*/*/index');
90
+ }
91
+
92
+ protected function _isAllowed()
93
+ {
94
+ return Mage::getSingleton('admin/session')->isAllowed('email_connector/reports/email_connector_automation');
95
+ }
96
+
97
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/CampaignController.php ADDED
@@ -0,0 +1,252 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Adminhtml_Email_CampaignController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+ /**
6
+ * constructor - set the used module name
7
+ */
8
+ protected function _construct()
9
+ {
10
+ $this->setUsedModuleName('Dotdigitalgroup_Email');
11
+ }
12
+
13
+ /**
14
+ * Email campaigns.
15
+ */
16
+ public function indexAction()
17
+ {
18
+ $this->_title($this->__('Email'))
19
+ ->_title($this->__('Manage Campaigns'));
20
+ $this->loadLayout();
21
+ $this->_setActiveMenu('email_connector');
22
+ $this->renderLayout();
23
+ }
24
+
25
+ /**
26
+ * New campaings.
27
+ */
28
+ public function newAction()
29
+ {
30
+ // We just forward the new action to a blank edit form
31
+ $this->_forward('edit');
32
+ }
33
+
34
+
35
+ /**
36
+ * Edit campign.
37
+ */
38
+ public function editAction()
39
+ {
40
+ $contactId = (int) $this->getRequest()->getParam('id');
41
+ $contact = $this->_initAction();
42
+ if ($contactId && !$contact->getId()) {
43
+ $this->_getSession()->addError(Mage::helper('ddg')->__('This campaign no longer exists.'));
44
+ $this->_redirect('*/*/');
45
+ return;
46
+ }
47
+ if ($data = Mage::getSingleton('adminhtml/session')->getCampaignData(true)) {
48
+ $contact->setData($data);
49
+ }
50
+ Mage::dispatchEvent('email_campaign_controller_edit_action', array('contact' => $contact));
51
+ $this->loadLayout();
52
+ if ($contact->getId()) {
53
+ if (!Mage::app()->isSingleStoreMode() && ($switchBlock = $this->getLayout()->getBlock('store_switcher'))) {
54
+ $switchBlock->setDefaultStoreName(Mage::helper('ddg')->__('Default Values'))
55
+ ->setSwitchUrl($this->getUrl('*/*/*', array('_current'=>true, 'active_tab'=>null, 'tab' => null, 'store'=>null)));
56
+ }
57
+ } else {
58
+ $this->getLayout()->getBlock('left')->unsetChild('store_switcher');
59
+ }
60
+ $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
61
+ $this->renderLayout();
62
+ }
63
+
64
+ /**
65
+ * Save campaign.
66
+ */
67
+ public function saveAction()
68
+ {
69
+ $storeId = $this->getRequest()->getParam('store');
70
+ $redirectBack = $this->getRequest()->getParam('back', false);
71
+ $contactId = $this->getRequest()->getParam('id');
72
+ $data = $this->getRequest()->getPost();
73
+ if ($data) {
74
+ $campaign = $this->_initAction();
75
+
76
+ $campaignData = $this->getRequest()->getPost('campaign', array());
77
+ $campaign->addData($campaignData);
78
+
79
+ try {
80
+ $campaign->save();
81
+ $this->_getSession()->addSuccess(Mage::helper('ddg')->__('Campaign was saved.'));
82
+ }catch (Mage_Core_Exception $e) {
83
+ Mage::logException($e);
84
+ $this->_getSession()->addError($e->getMessage())
85
+ ->setContactData($campaignData);
86
+ $redirectBack = true;
87
+ }catch (Exception $e){
88
+ Mage::logException($e);
89
+ $this->_getSession()->addError(Mage::helper('ddg')->__('Error saving campaign'))
90
+ ->setContactData($campaignData);
91
+ $redirectBack = true;
92
+ }
93
+ }
94
+ if ($redirectBack) {
95
+ $this->_redirect('*/*/edit', array(
96
+ 'id' => $contactId,
97
+ '_current'=>true
98
+ ));
99
+ } else {
100
+ $this->_redirect('*/*/', array('store'=>$storeId));
101
+ }
102
+ }
103
+
104
+ /**
105
+ * Delete campaign.
106
+ */
107
+ public function deleteAction()
108
+ {
109
+ if ($id = $this->getRequest()->getParam('id')) {
110
+ $campaign = Mage::getModel('ddg_automation/campaign')->load($id);
111
+ try {
112
+ $campaign->delete();
113
+ $this->_getSession()->addSuccess(Mage::helper('ddg')->__('The campaign has been deleted.'));
114
+ }
115
+ catch (Exception $e) {
116
+ $this->_getSession()->addError($e->getMessage());
117
+ }
118
+ }
119
+ $this->getResponse()->setRedirect($this->getUrl('*/*/', array('store'=>$this->getRequest()->getParam('store'))));
120
+ }
121
+
122
+ /**
123
+ * Delete mass campaigns.
124
+ */
125
+ public function massDeleteAction()
126
+ {
127
+ $campaignIds = $this->getRequest()->getParam('campaign');
128
+ if (!is_array($campaignIds)) {
129
+ $this->_getSession()->addError($this->__('Please select campaigns.'));
130
+ } else {
131
+ try {
132
+ foreach ($campaignIds as $campaignId) {
133
+ $campaign = Mage::getSingleton('ddg_automation/campaign')->load($campaignId);
134
+ Mage::dispatchEvent('connector_controller_campaign_delete', array('campaign' => $campaign));
135
+ $campaign->delete();
136
+ }
137
+ $this->_getSession()->addSuccess(
138
+ Mage::helper('ddg')->__('Total of %d record(s) have been deleted.', count($campaignIds))
139
+ );
140
+ } catch (Exception $e) {
141
+ $this->_getSession()->addError($e->getMessage());
142
+ }
143
+ }
144
+ $this->_redirect('*/*/index');
145
+ }
146
+
147
+ /**
148
+ * Mass mark for resend campaings.
149
+ */
150
+ public function massResendAction()
151
+ {
152
+ $campaignIds = $this->getRequest()->getParam('campaign');
153
+ if (!is_array($campaignIds)) {
154
+ $this->_getSession()->addError($this->__('Please select campaigns.'));
155
+ } else {
156
+ try {
157
+ foreach ($campaignIds as $campaignId) {
158
+ $campaign = Mage::getSingleton('ddg_automation/campaign')->load($campaignId);
159
+ Mage::dispatchEvent('connector_controller_campaign_delete', array('campaign' => $campaign));
160
+ $campaign->setIsSent(null)->save();
161
+ }
162
+ $this->_getSession()->addSuccess(
163
+ Mage::helper('ddg')->__('Total of %d record(s) have resend .', count($campaignIds))
164
+ );
165
+ } catch (Exception $e) {
166
+ $this->_getSession()->addError($e->getMessage());
167
+ }
168
+ }
169
+ $this->_redirect('*/*/index');
170
+ }
171
+
172
+ /**
173
+ * Mass mark for recreate campaings.
174
+ */
175
+ public function massRecreateAction()
176
+ {
177
+ $campaignIds = $this->getRequest()->getParam('campaign');
178
+ $count = 0;
179
+ if (!is_array($campaignIds)) {
180
+ $this->_getSession()->addError($this->__('Please select campaigns.'));
181
+ } else {
182
+ try {
183
+ foreach ($campaignIds as $campaignId) {
184
+ $campaign = Mage::getSingleton('ddg_automation/campaign')->load($campaignId);
185
+ if($campaign->getSubject() && $campaign->getHtmlContent() && ($campaign->getIsSent() == NULL)){
186
+ $count++;
187
+ Mage::dispatchEvent('connector_controller_campaign_recreate', array('campaign' => $campaign));
188
+ $campaign->setIsCreated(null)->save();
189
+ }
190
+ elseif(($campaign->getIsSent() == NULL) && $campaign->getIsCopy() == 1){
191
+ $count++;
192
+ Mage::dispatchEvent('connector_controller_campaign_recreate', array('campaign' => $campaign));
193
+ $campaign->setIsCreated(null)->save();
194
+ }
195
+ }
196
+ $this->_getSession()->addSuccess(
197
+ Mage::helper('ddg')->__('Total of %d record(s) have recreate.', $count)
198
+ );
199
+ } catch (Exception $e) {
200
+ $this->_getSession()->addError($e->getMessage());
201
+ }
202
+ }
203
+ $this->_redirect('*/*/index');
204
+ }
205
+
206
+
207
+ /**
208
+ * main page.
209
+ */
210
+ public function gridAction()
211
+ {
212
+ $this->loadLayout();
213
+ $this->renderLayout();
214
+ }
215
+
216
+ /**
217
+ * manage the campaigns.
218
+ *
219
+ * @return Dotdigitalgroup_Email_Model_Campaign
220
+ */
221
+ protected function _initAction()
222
+ {
223
+ $this->_title($this->__('Newsletter'))
224
+ ->_title($this->__('Manage Campaigns'));
225
+
226
+ $campaignId = (int) $this->getRequest()->getParam('id');
227
+ $campaign = Mage::getModel('ddg_automation/campaign');
228
+
229
+ if ($campaignId) {
230
+ $campaign->load($campaignId);
231
+ }
232
+ Mage::register('email_campaign', $campaign);
233
+ return $campaign;
234
+ }
235
+
236
+ /**
237
+ * Export campaigns to CSV file.
238
+ */
239
+ public function exportCsvAction()
240
+ {
241
+ $fileName = 'campaign.csv';
242
+ $content = $this->getLayout()->createBlock('ddg_automation/adminhtml_campaign_grid')
243
+ ->getCsvFile();
244
+ $this->_prepareDownloadResponse($fileName, $content);
245
+ }
246
+
247
+ protected function _isAllowed()
248
+ {
249
+ return Mage::getSingleton('admin/session')->isAllowed('email_connector/reports/email_connector_campaign');
250
+ }
251
+
252
+ }
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,192 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Adminhtml_Email_ContactController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+ /**
6
+ * constructor - set the used module name
7
+ */
8
+ protected function _construct(){
9
+ $this->setUsedModuleName('Dotdigitalgroup_Email');
10
+ }
11
+
12
+ /**
13
+ * main page.
14
+ */
15
+ public function indexAction()
16
+ {
17
+ $this->_title($this->__('Email'))
18
+ ->_title($this->__('Manage Contacts'));
19
+ $this->loadLayout();
20
+ $this->_setActiveMenu('email_connector');
21
+ $this->renderLayout();
22
+ }
23
+
24
+ /**
25
+ * Edit contact.
26
+ */
27
+ public function editAction()
28
+ {
29
+ $contactId = (int) $this->getRequest()->getParam('id');
30
+ $contact = $this->_initAction();
31
+ if ($contactId && !$contact->getId()) {
32
+ $this->_getSession()->addError(Mage::helper('ddg')->__('This contact no longer exists.'));
33
+ $this->_redirect('*/*/');
34
+ return;
35
+ }
36
+ $contactEmail = Mage::getModel('ddg_automation/apiconnector_contact')->syncContact();
37
+ if ($contactEmail)
38
+ Mage::getSingleton('adminhtml/session')->addSuccess('Successfully synced : ' . $contactEmail);
39
+
40
+ Mage::dispatchEvent('email_contact_controller_edit_action', array('contact' => $contact));
41
+
42
+ $this->_redirect('*/*');
43
+ }
44
+
45
+ /**
46
+ * Save contact.
47
+ */
48
+ public function saveAction(){
49
+ $storeId = $this->getRequest()->getParam('store');
50
+ $redirectBack = $this->getRequest()->getParam('back', false);
51
+ $contactId = $this->getRequest()->getParam('id');
52
+
53
+ $data = $this->getRequest()->getPost();
54
+ if ($data) {
55
+ $contact = $this->_initAction();
56
+
57
+ $contactData = $this->getRequest()->getPost('contact', array());
58
+ $contact->addData($contactData);
59
+
60
+ try {
61
+ $contact->save();
62
+ $contactId = $contact->getId();
63
+ $this->_getSession()->addSuccess(Mage::helper('ddg')->__('Contact was saved.'));
64
+ }catch (Mage_Core_Exception $e) {
65
+ Mage::logException($e);
66
+ $this->_getSession()->addError($e->getMessage())
67
+ ->setContactData($contactData);
68
+ $redirectBack = true;
69
+ }catch (Exception $e){
70
+ Mage::logException($e);
71
+ $this->_getSession()->addError(Mage::helper('ddg')->__('Error saving contact'))
72
+ ->setContactData($contactData);
73
+ $redirectBack = true;
74
+ }
75
+ }
76
+ if ($redirectBack) {
77
+ $this->_redirect('*/*/edit', array(
78
+ 'id' => $contactId,
79
+ '_current'=>true
80
+ ));
81
+ } else {
82
+ $this->_redirect('*/*/', array('store'=>$storeId));
83
+ }
84
+ }
85
+
86
+ /**
87
+ * Delete a contact.
88
+ */
89
+ public function deleteAction()
90
+ {
91
+ if ($id = $this->getRequest()->getParam('id')) {
92
+ $contact = Mage::getModel('ddg_automation/contact')->load($id);
93
+ try {
94
+ $contact->delete();
95
+ $this->_getSession()->addSuccess(Mage::helper('ddg')->__('The contact has been deleted.'));
96
+ }
97
+ catch (Exception $e) {
98
+ $this->_getSession()->addError($e->getMessage());
99
+ }
100
+ }
101
+ $this->getResponse()->setRedirect($this->getUrl('*/*/', array('store'=>$this->getRequest()->getParam('store'))));
102
+ }
103
+
104
+ /**
105
+ * Mass delete contacts.
106
+ */
107
+ public function massDeleteAction()
108
+ {
109
+ $contactIds = $this->getRequest()->getParam('contact');
110
+ if (!is_array($contactIds)) {
111
+ $this->_getSession()->addError($this->__('Please select contacts.'));
112
+ }else {
113
+ try {
114
+ foreach ($contactIds as $contactId) {
115
+ $contact = Mage::getSingleton('ddg_automation/contact')->load($contactId);
116
+ Mage::dispatchEvent('connector_controller_affiliate_delete', array('contact' => $contact));
117
+ $contact->delete();
118
+ }
119
+ $this->_getSession()->addSuccess(
120
+ Mage::helper('ddg')->__('Total of %d record(s) have been deleted.', count($contactIds))
121
+ );
122
+ } catch (Exception $e) {
123
+ $this->_getSession()->addError($e->getMessage());
124
+ }
125
+ }
126
+ $this->_redirect('*/*/index');
127
+ }
128
+
129
+ /**
130
+ * Mark a contact to be resend.
131
+ */
132
+ public function massResendAction()
133
+ {
134
+ $contactIds = $this->getRequest()->getParam('contact');
135
+
136
+ if (!is_array($contactIds)) {
137
+ $this->_getSession()->addError($this->__('Please select contacts.'));
138
+ }else {
139
+ try {
140
+ foreach ($contactIds as $contactId) {
141
+ $contact = Mage::getSingleton('ddg_automation/contact')->load($contactId);
142
+ $contact->setEmailImported(null)->save();
143
+ }
144
+ $this->_getSession()->addSuccess(
145
+ Mage::helper('ddg')->__('Total of %d record(s) set for resend.', count($contactIds))
146
+ );
147
+ } catch (Exception $e) {
148
+ $this->_getSession()->addError($e->getMessage());
149
+ }
150
+ }
151
+ $this->_redirect('*/*/index');
152
+ }
153
+
154
+
155
+ /**
156
+ * main grid.
157
+ */
158
+ public function gridAction(){
159
+ $this->loadLayout();
160
+ $this->renderLayout();
161
+ }
162
+
163
+ protected function _initAction()
164
+ {
165
+ $this->_title($this->__('Newsletter'))
166
+ ->_title($this->__('Manage Contacts'));
167
+
168
+ $contactId = (int) $this->getRequest()->getParam('id');
169
+ $contact = Mage::getModel('ddg_automation/contact')
170
+ ->setStoreId($this->getRequest()->getParam('store', 0));
171
+
172
+ if ($contactId) {
173
+ $contact->load($contactId);
174
+ }
175
+ Mage::register('current_contact', $contact);
176
+ return $contact;
177
+ }
178
+
179
+ public function exportCsvAction()
180
+ {
181
+ $fileName = 'contacts.csv';
182
+ $content = $this->getLayout()->createBlock('ddg_automation/adminhtml_contact_grid')
183
+ ->getCsvFile();
184
+ $this->_prepareDownloadResponse($fileName, $content);
185
+ }
186
+
187
+ protected function _isAllowed()
188
+ {
189
+ return Mage::getSingleton('admin/session')->isAllowed('email_connector/reports/email_connector_contact');
190
+ }
191
+
192
+ }
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,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
24
+ if (!is_array($ids)) {
25
+ $this->_getSession()->addError($this->__('Please select import.'));
26
+ }else {
27
+ try {
28
+ foreach ($ids as $id) {
29
+ $import = Mage::getSingleton('ddg_automation/importer')->load($id);
30
+ $import->setImportStatus(Dotdigitalgroup_Email_Model_Importer::NOT_IMPORTED)->save();
31
+ }
32
+ $this->_getSession()->addSuccess(
33
+ Mage::helper('ddg')->__('Total of %d record(s) set for reset.', count($ids))
34
+ );
35
+ } catch (Exception $e) {
36
+ $this->_getSession()->addError($e->getMessage());
37
+ }
38
+ }
39
+ $this->_redirect('*/*/index');
40
+ }
41
+
42
+
43
+ /**
44
+ * Mass delete contacts.
45
+ */
46
+ public function massDeleteAction()
47
+ {
48
+ $ids = $this->getRequest()->getParam('importer');
49
+ if (!is_array($ids)) {
50
+ $this->_getSession()->addError($this->__('Please select import.'));
51
+ }else {
52
+ try {
53
+ foreach ($ids as $id) {
54
+ $import = Mage::getSingleton('ddg_automation/importer')->load($id);
55
+ $import->delete();
56
+ }
57
+ $this->_getSession()->addSuccess(
58
+ Mage::helper('ddg')->__('Total of %d record(s) have been deleted.', count($ids))
59
+ );
60
+ } catch (Exception $e) {
61
+ $this->_getSession()->addError($e->getMessage());
62
+ }
63
+ }
64
+ $this->_redirect('*/*/index');
65
+ }
66
+
67
+ /**
68
+ * Check currently called action by permissions for current user
69
+ *
70
+ * @return bool
71
+ */
72
+ protected function _isAllowed()
73
+ {
74
+ return Mage::getSingleton('admin/session')->isAllowed('email_connector/reports/email_connector_importer');
75
+ }
76
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/OrderController.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Adminhtml_Email_OrderController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+ /**
6
+ * main page.
7
+ */
8
+ public function indexAction()
9
+ {
10
+ $this->loadLayout();
11
+ $this->_setActiveMenu('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->load($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,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Adminhtml_Widget_ChooserController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+ /**
6
+ * ajax handler for product chooser
7
+ */
8
+ public function productAction()
9
+ {
10
+ $block = $this->getLayout()->createBlock(
11
+ 'ddg_automation/adminhtml_widget_chooser_product', 'email_connector_chooser_product',
12
+ array('js_form_object' => $this->getRequest()->getParam('form'),
13
+ ));
14
+
15
+ if ($block) {
16
+ $this->getResponse()->setBody($block->toHtml());
17
+ }
18
+ }
19
+ }
app/code/community/Dotdigitalgroup/Email/controllers/AjaxController.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_AjaxController extends Mage_Core_Controller_Front_Action
4
+ {
5
+ public function emailcaptureAction()
6
+ {
7
+ if($this->getRequest()->getParam('email') && Mage::getSingleton('checkout/session')->getQuote()){
8
+ $email = $this->getRequest()->getParam('email');
9
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
10
+ if($quote->hasItems()){
11
+ try {
12
+ $quote->setCustomerEmail($email)->save();
13
+ Mage::helper('ddg')->log('ajax emailCapture email: '. $email);
14
+ }catch(Exception $e){
15
+ Mage::logException($e);
16
+ Mage::helper('ddg')->log('ajax emailCapture fail for email: '. $email);
17
+ }
18
+ }
19
+ }
20
+ }
21
+ }
app/code/community/Dotdigitalgroup/Email/controllers/CreditmemoController.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once 'Dotdigitalgroup' . DS . 'Email' . DS . 'controllers' . DS . 'DynamicContentController.php';
3
+
4
+ class Dotdigitalgroup_Email_CreditmemoController extends Dotdigitalgroup_Email_DynamicContentController
5
+ {
6
+
7
+ /**
8
+ * New creditmemo.
9
+ */
10
+ public function newAction()
11
+ {
12
+ $this->loadLayout();
13
+ $newOrder = $this->getLayout()->createBlock('ddg_automation/order_creditmemo', 'connector_creditmemo_new', array(
14
+ 'template' => 'connector/creditmemo/new.phtml'
15
+ ));
16
+ $this->getLayout()->getBlock('content')->append($newOrder);
17
+ $items = $this->getLayout()->createBlock('ddg_automation/order_creditmemo', 'connector_creditmemo_items', array(
18
+ 'template' => 'connector/creditmemo/items.phtml'
19
+ ));
20
+ $this->getLayout()->getBlock('connector_creditmemo_new')->append($items);
21
+ $this->renderLayout();
22
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
23
+ }
24
+
25
+ /**
26
+ * New guest action.
27
+ */
28
+ public function newguestAction()
29
+ {
30
+ $this->loadLayout();
31
+ $invoice = $this->getLayout()->createBlock('ddg_automation/order_invoice', 'connector_creditmemo_guest', array(
32
+ 'template' => 'connector/creditmemo/newguest.phtml'
33
+ ));
34
+ $this->getLayout()->getBlock('content')->append($invoice);
35
+ $items = $this->getLayout()->createBlock('ddg_automation/order_creditmemo', 'connector_creditmemo_items', array(
36
+ 'template' => 'connector/creditmemo/items.phtml'
37
+ ));
38
+ $this->getLayout()->getBlock('connector_creditmemo_guest')->append($items);
39
+ $this->renderLayout();
40
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
41
+ }
42
+
43
+ /**
44
+ * update creditmemo.
45
+ */
46
+ public function updateAction()
47
+ {
48
+ $this->loadLayout();
49
+ $newOrder = $this->getLayout()->createBlock('ddg_automation/order_creditmemo', 'connector_creditmemo_update', array(
50
+ 'template' => 'connector/creditmemo/update.phtml'
51
+ ));
52
+ $this->getLayout()->getBlock('content')->append($newOrder);
53
+ $this->renderLayout();
54
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
55
+ }
56
+
57
+ /**
58
+ * update guest.
59
+ */
60
+ public function updateguestAction()
61
+ {
62
+ $this->loadLayout();
63
+ $newOrder = $this->getLayout()->createBlock('ddg_automation/order_creditmemo', 'connector_creditmemo_update_guest', array(
64
+ 'template' => 'connector/creditmemo/updateguest.phtml'
65
+ ));
66
+ $this->getLayout()->getBlock('content')->append($newOrder);
67
+ $this->renderLayout();
68
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
69
+ }
70
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Customer/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()) {
40
+ return $this->_redirect('customer/account/');
41
+ }
42
+ //params
43
+ $additional_subscriptions = Mage::app()->getRequest()->getParam('additional_subscriptions');
44
+ $data_fields = Mage::app()->getRequest()->getParam('data_fields');
45
+ $customer_id = Mage::app()->getRequest()->getParam('connector_customer_id');
46
+ $customer_email = Mage::app()->getRequest()->getParam('connector_customer_email');
47
+
48
+ //client
49
+ $website = Mage::getModel('customer/session')->getCustomer()->getStore()->getWebsite();
50
+ $client = Mage::getModel('ddg_automation/apiconnector_client');
51
+ $client->setApiUsername(Mage::helper('ddg')->getApiUsername($website))
52
+ ->setApiPassword(Mage::helper('ddg')->getApiPassword($website));
53
+
54
+ $contact = $client->getContactById($customer_id);
55
+ if(isset($contact->id)){
56
+ //contact 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,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once 'Dotdigitalgroup' . DS . 'Email' . DS . 'controllers' . DS . 'ResponseController.php';
3
+
4
+ class Dotdigitalgroup_Email_DynamicContentController extends Dotdigitalgroup_Email_ResponseController
5
+ {
6
+ /**
7
+ * @return Mage_Core_Controller_Front_Action|void
8
+ * @throws Exception
9
+ */
10
+ public function preDispatch()
11
+ {
12
+ //authenticate
13
+ $this->authenticate();
14
+
15
+ $orderId = $this->getRequest()->getParam('order_id', false);
16
+ //check for order_id param
17
+ if ($orderId) {
18
+ $order = Mage::getModel('sales/order')->load($orderId);
19
+ //check if the order still exists
20
+ if ($order->getId()) {
21
+ $storeId = $order->getStoreId();
22
+ //start the emulation for order store
23
+ $appEmulation = Mage::getSingleton('core/app_emulation');
24
+ $appEmulation->startEnvironmentEmulation($storeId);
25
+ } else {
26
+ //throw new Exception('TE invoice : order not found: ' . $orderId);
27
+ Mage::helper('ddg')->log('TE invoice : order not found: ' . $orderId);
28
+ $this->sendResponse();
29
+ die;
30
+ }
31
+ } else {
32
+ //throw new Exception('TE invoice : order_id missing :' . $orderId);
33
+ Mage::helper('ddg')->log('TE invoice : order_id missing :' . $orderId);
34
+ $this->sendResponse();
35
+ die;
36
+ }
37
+ parent::preDispatch();
38
+ }
39
+ }
app/code/community/Dotdigitalgroup/Email/controllers/EmailController.php ADDED
@@ -0,0 +1,258 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $this->loadLayout();
71
+ $review = $this->getLayout()->createBlock('ddg_automation/order', 'connector_review', array(
72
+ 'template' => 'connector/review.phtml'
73
+ ));
74
+ $this->getLayout()->getBlock('content')->append($review);
75
+ $this->renderLayout();
76
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
77
+ }
78
+
79
+ /**
80
+ * Callback action for the automation studio.
81
+ */
82
+ public function callbackAction()
83
+ {
84
+ $code = $this->getRequest()->getParam('code', false);
85
+ $userId = $this->getRequest()->getParam('state');
86
+ $adminUser = Mage::getModel('admin/user')->load($userId);
87
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB, true);
88
+
89
+ //callback url
90
+ $callback = $baseUrl . 'connector/email/callback';
91
+
92
+ if ($code) {
93
+ $data = 'client_id=' . Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CLIENT_ID) .
94
+ '&client_secret=' . Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CLIENT_SECRET_ID) .
95
+ '&redirect_uri=' . $callback .
96
+ '&grant_type=authorization_code' .
97
+ '&code=' . $code;
98
+
99
+
100
+ $url = Mage::helper('ddg/config')->getTokenUrl();
101
+ $ch = curl_init();
102
+ curl_setopt($ch, CURLOPT_URL, $url);
103
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
104
+ curl_setopt($ch, CURLOPT_TIMEOUT, 10);
105
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
106
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
107
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
108
+ curl_setopt($ch, CURLOPT_POST, count($data));
109
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
110
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array ('Content-Type: application/x-www-form-urlencoded'));
111
+
112
+
113
+ $response = json_decode(curl_exec($ch));
114
+ if ($response === false) {
115
+ Mage::helper('ddg')->rayLog('100', 'Automaion studio number not found : ' . serialize($response));
116
+ Mage::helper('ddg')->log("Error Number: " . curl_errno($ch));
117
+ }
118
+
119
+ //save the refresh token to the admin user
120
+ $adminUser->setRefreshToken($response->refresh_token)->save();
121
+ }
122
+ //redirect to automation index page
123
+ $this->_redirectReferer(Mage::helper('adminhtml')->getUrl('adminhtml/email_automation/index'));
124
+ }
125
+
126
+ /**
127
+ * quote process action
128
+ */
129
+ public function getbasketAction()
130
+ {
131
+ $quote_id = $this->getRequest()->getParam('quote_id');
132
+ //no quote id redirect to base url
133
+ if(!$quote_id)
134
+ $this->_redirectUrl(Mage::getBaseUrl());
135
+
136
+ $quoteModel = Mage::getModel('sales/quote')->load($quote_id);
137
+
138
+ //no quote id redirect to base url
139
+ if (!$quoteModel->getId())
140
+ $this->_redirectUrl(Mage::getBaseUrl());
141
+
142
+ //set quoteModel to _quote property for later use
143
+ $this->_quote = $quoteModel;
144
+
145
+ if($quoteModel->getCustomerId())
146
+ $this->_handleCustomerBasket();
147
+ else
148
+ $this->_handleGuestBasket();
149
+ }
150
+
151
+ /**
152
+ * process customer basket
153
+ */
154
+ private function _handleCustomerBasket()
155
+ {
156
+ $customerSession = Mage::getSingleton('customer/session');
157
+ $configCartUrl = $this->_quote->getStore()->getWebsite()->getConfig(
158
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CONTENT_CART_URL
159
+ );
160
+
161
+ //if customer is logged in then redirect to cart
162
+ if($customerSession->isLoggedIn()){
163
+ $checkoutSession = Mage::getSingleton('checkout/session');
164
+ if($checkoutSession->getQuote() && $checkoutSession->getQuote()->hasItems()){
165
+ $quote = $checkoutSession->getQuote();
166
+ if($this->_quote->getId() != $quote->getId())
167
+ $this->_checkMissingAndAdd();
168
+ }
169
+ else{
170
+ $this->_loadAndReplace();
171
+ }
172
+
173
+ if($configCartUrl)
174
+ $url = $configCartUrl;
175
+ else
176
+ $url = $customerSession->getCustomer()->getStore()->getUrl('checkout/cart');
177
+
178
+ $this->_redirectUrl($url);
179
+ }
180
+ else{
181
+ //set after auth url. customer will be redirected to cart after successful login
182
+ if($configCartUrl)
183
+ $cartUrl = $configCartUrl;
184
+ else
185
+ $cartUrl = 'checkout/cart';
186
+ $customerSession->setAfterAuthUrl($this->_quote->getStore()->getUrl($cartUrl));
187
+
188
+ //send customer to login page
189
+ $configLoginUrl = $this->_quote->getStore()->getWebsite()->getConfig(
190
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CONTENT_LOGIN_URL
191
+ );
192
+ if($configLoginUrl)
193
+ $loginUrl = $configLoginUrl;
194
+ else
195
+ $loginUrl = 'customer/account/login';
196
+ $this->_redirectUrl($this->_quote->getStore()->getUrl($loginUrl));
197
+ }
198
+ }
199
+
200
+ /**
201
+ * process guest basket
202
+ */
203
+ private function _handleGuestBasket()
204
+ {
205
+ $checkoutSession = Mage::getSingleton('checkout/session');
206
+ if($checkoutSession->getQuote() && $checkoutSession->getQuote()->hasItems()){
207
+ $this->_checkMissingAndAdd();
208
+ }
209
+ else{
210
+ $this->_loadAndReplace();
211
+ }
212
+
213
+ $configCartUrl = $this->_quote->getStore()->getWebsite()->getConfig(
214
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CONTENT_CART_URL
215
+ );
216
+
217
+ if($configCartUrl)
218
+ $url = $configCartUrl;
219
+ else
220
+ $url = 'checkout/cart';
221
+ $this->_redirectUrl($this->_quote->getStore()->getUrl($url));
222
+ }
223
+
224
+ /**
225
+ * check missing items from current quote and add
226
+ */
227
+ private function _checkMissingAndAdd()
228
+ {
229
+ $checkoutSession = Mage::getSingleton('checkout/session');
230
+ $currentQuote = $checkoutSession->getQuote();
231
+ if($currentQuote->hasItems()){
232
+ $currentSessionItems = $currentQuote->getAllItems();
233
+ $currentItemIds = array();
234
+ foreach($currentSessionItems as $currentSessionItem){
235
+ $currentItemIds[] = $currentSessionItem->getId();
236
+ }
237
+ foreach($this->_quote->getAllItems() as $item){
238
+ if(!in_array($item->getId(), $currentItemIds)){
239
+ $currentQuote->addItem($item);
240
+ }
241
+ }
242
+ $currentQuote->collectTotals()->save();
243
+ }else{
244
+ $this->_loadAndReplace();
245
+ }
246
+ }
247
+
248
+ /**
249
+ * load quote and replace in session#1114
250
+ */
251
+ private function _loadAndReplace()
252
+ {
253
+ $checkoutSession = Mage::getSingleton('checkout/session');
254
+ $quote = Mage::getSingleton('sales/quote')->load($this->_quote->getId());
255
+ $quote->setIsActive(true)->save();
256
+ $checkoutSession->replaceQuote($quote);
257
+ }
258
+ }
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,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once 'Dotdigitalgroup' . DS . 'Email' . DS . 'controllers' . DS . 'ResponseController.php';
3
+
4
+ class Dotdigitalgroup_Email_ProductsController extends Dotdigitalgroup_Email_ResponseController
5
+ {
6
+ /**
7
+ * @return Mage_Core_Controller_Front_Action|void
8
+ */
9
+ public function preDispatch()
10
+ {
11
+ //authenticate
12
+ $this->authenticate();
13
+ //skip order_id check for this actions
14
+ $skip = array('push', 'nosto');
15
+ $actionName = $this->getRequest()->getActionName();
16
+ if (! in_array($actionName, $skip)) {
17
+ $orderId = $this->getRequest()->getParam('order_id', false);
18
+ //check for order id param
19
+ if ($orderId) {
20
+ //check if order still exists
21
+ $order = Mage::getModel('sales/order')->load($orderId);
22
+ if ($order->getId()) {
23
+ //start app emulation
24
+ $storeId = $order->getStoreId();
25
+ $appEmulation = Mage::getSingleton('core/app_emulation');
26
+ $appEmulation->startEnvironmentEmulation($storeId);
27
+ } else {
28
+ $message = 'Dynamic : order not found: ' . $orderId;
29
+ Mage::helper('ddg')->log($message);
30
+ Mage::helper('ddg')->rayLog('100', $message);
31
+ }
32
+ } else {
33
+ Mage::helper('ddg')->log('Dynamic : order_id missing :' . $orderId);
34
+ }
35
+ }
36
+
37
+ parent::preDispatch();
38
+ }
39
+
40
+ /**
41
+ * Related products.
42
+ */
43
+ public function relatedAction()
44
+ {
45
+ $this->loadLayout();
46
+ $products = $this->getLayout()->createBlock('ddg_automation/recommended_products', 'connector_recommended_related', array(
47
+ 'template' => 'connector/product/list.phtml'
48
+ ));
49
+ //append related products
50
+ $this->getLayout()->getBlock('content')->append($products);
51
+
52
+ $this->renderLayout();
53
+
54
+ }
55
+
56
+ /**
57
+ * Crosssell products.
58
+ */
59
+ public function crosssellAction()
60
+ {
61
+ $this->loadLayout();
62
+ $products = $this->getLayout()->createBlock('ddg_automation/recommended_products', 'connector_recommended_crosssell', array(
63
+ 'template' => 'connector/product/list.phtml'
64
+ ));
65
+ //append crosssell products.
66
+ $this->getLayout()->getBlock('content')->append($products);
67
+
68
+ $this->renderLayout();
69
+ }
70
+
71
+ /**
72
+ * Upsell products.
73
+ */
74
+ public function upsellAction()
75
+ {
76
+ $this->loadLayout();
77
+ $products = $this->getLayout()->createBlock('ddg_automation/recommended_products', 'connector_recommended_upsell', array(
78
+ 'template' => 'connector/product/list.phtml'
79
+ ));
80
+ //append upsell products
81
+ $this->getLayout()->getBlock('content')->append($products);
82
+
83
+ $this->renderLayout();
84
+ }
85
+
86
+ /**
87
+ * Products that are set to manually push as related.
88
+ */
89
+ public function pushAction()
90
+ {
91
+ $this->loadLayout();
92
+ $products = $this->getLayout()->createBlock('ddg_automation/recommended_push', 'connector_product_push', array(
93
+ 'template' => 'connector/product/list.phtml'
94
+ ));
95
+ //append push products
96
+ $this->getLayout()->getBlock('content')->append($products);
97
+ $this->renderLayout();
98
+ }
99
+
100
+ /**
101
+ * Nosto recommendation action.
102
+ */
103
+ public function nostoAction()
104
+ {
105
+ $this->loadLayout();
106
+
107
+ $products = $this->getLayout()->createBlock('ddg_automation/recommended_products', 'connector_nosto_recommended', array(
108
+ 'template' => 'connector/product/nosto.phtml'
109
+ ));
110
+ $html = $products->toHtml();
111
+
112
+ //if empty than display our fallback products instead.
113
+ if (empty($html)) {
114
+ Mage::app()->getRequest()->setActionName('push');
115
+ $this->pushAction();
116
+ } else {
117
+ $this->getLayout()->getBlock('content')->append($products);
118
+ $this->renderLayout();
119
+ }
120
+ }
121
+
122
+ }
app/code/community/Dotdigitalgroup/Email/controllers/QuoteproductsController.php ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once 'Dotdigitalgroup' . DS . 'Email' . DS . 'controllers' . DS . 'ResponseController.php';
3
+
4
+ class Dotdigitalgroup_Email_QuoteproductsController extends Dotdigitalgroup_Email_ResponseController
5
+ {
6
+ /**
7
+ * @return Mage_Core_Controller_Front_Action|void
8
+ */
9
+ public function preDispatch()
10
+ {
11
+ //authenticate
12
+ $this->authenticate();
13
+ if ($this->getRequest()->getActionName() != 'push') {
14
+ $quoteId = $this->getRequest()->getParam('quote_id', false);
15
+ //check for quote id param
16
+ if ($quoteId) {
17
+ //check if quote exists
18
+ $quote = Mage::getModel('sales/quote')->load($quoteId);
19
+ if ($quote->getId()) {
20
+ //start app emulation
21
+ $storeId = $quote->getStoreId();
22
+ $appEmulation = Mage::getSingleton('core/app_emulation');
23
+ $appEmulation->startEnvironmentEmulation($storeId);
24
+ } else {
25
+ $message = 'Dynamic : Quote not found: ' . $quoteId;
26
+ Mage::helper('ddg')->log($message);
27
+ Mage::helper('ddg')->rayLog('100', $message);
28
+ }
29
+ } else {
30
+ Mage::helper('ddg')->log('Dynamic : order_id missing :' . $quoteId);
31
+ }
32
+ }
33
+
34
+ parent::preDispatch();
35
+ }
36
+
37
+ /**
38
+ * Related products.
39
+ */
40
+ public function relatedAction()
41
+ {
42
+ $this->loadLayout();
43
+ $products = $this->getLayout()->createBlock('ddg_automation/recommended_quoteproducts', 'connector_recommended_quote_related', array(
44
+ 'template' => 'connector/product/list.phtml'
45
+ ));
46
+ //append related products
47
+ $this->getLayout()->getBlock('content')->append($products);
48
+ $this->renderLayout();
49
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
50
+ }
51
+
52
+ /**
53
+ * Crosssell products.
54
+ */
55
+ public function crosssellAction()
56
+ {
57
+ $this->loadLayout();
58
+ $products = $this->getLayout()->createBlock('ddg_automation/recommended_quoteproducts', 'connector_recommended_quote_crosssell', array(
59
+ 'template' => 'connector/product/list.phtml'
60
+ ));
61
+ //append crosssell products.
62
+ $this->getLayout()->getBlock('content')->append($products);
63
+ $this->renderLayout();
64
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
65
+ }
66
+
67
+ /**
68
+ * Upsell products.
69
+ */
70
+ public function upsellAction()
71
+ {
72
+ $this->loadLayout();
73
+ $products = $this->getLayout()->createBlock('ddg_automation/recommended_quoteproducts', 'connector_recommended_quote_upsell', array(
74
+ 'template' => 'connector/product/list.phtml'
75
+ ));
76
+ //append upsell products
77
+ $this->getLayout()->getBlock('content')->append($products);
78
+ $this->renderLayout();
79
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
80
+ }
81
+
82
+ /**
83
+ * Products that are set to manually push as related.
84
+ */
85
+ public function pushAction()
86
+ {
87
+ $this->loadLayout();
88
+ $products = $this->getLayout()->createBlock('ddg_automation/recommended_push', 'connector_product_push', array(
89
+ 'template' => 'connector/product/list.phtml'
90
+ ));
91
+ //append push products
92
+ $this->getLayout()->getBlock('content')->append($products);
93
+ $this->renderLayout();
94
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
95
+ }
96
+ }
app/code/community/Dotdigitalgroup/Email/controllers/ReportController.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once 'Dotdigitalgroup' . DS . 'Email' . DS . 'controllers' . DS . 'ResponseController.php';
3
+
4
+
5
+ class Dotdigitalgroup_Email_ReportController extends Dotdigitalgroup_Email_ResponseController
6
+ {
7
+ /**
8
+ * @return Mage_Core_Controller_Front_Action|void
9
+ */
10
+ public function preDispatch()
11
+ {
12
+ //authenticate
13
+ $this->authenticate();
14
+ parent::preDispatch();
15
+ }
16
+
17
+ /**
18
+ * Bestsellers report.
19
+ */
20
+ public function bestsellersAction()
21
+ {
22
+ $this->loadLayout();
23
+ //set the content template
24
+ $products = $this->getLayout()->createBlock('ddg_automation/recommended_bestsellers', 'connector_customer', array(
25
+ 'template' => 'connector/product/list.phtml'
26
+ ));
27
+ $this->getLayout()->getBlock('content')->append($products);
28
+ $this->renderLayout();
29
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
30
+ }
31
+
32
+ /**
33
+ * Most viewed report.
34
+ */
35
+ public function mostviewedAction()
36
+ {
37
+ $this->loadLayout();
38
+ //set the content template
39
+ $products = $this->getLayout()->createBlock('ddg_automation/recommended_mostviewed', 'connector_customer', array(
40
+ 'template' => 'connector/product/list.phtml'
41
+ ));
42
+ $this->getLayout()->getBlock('content')->append($products);
43
+ $this->renderLayout();
44
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
45
+ }
46
+
47
+ /**
48
+ * Recently viewed products for customer.
49
+ */
50
+ public function recentlyviewedAction()
51
+ {
52
+ //customer id param
53
+ $customerId = $this->getRequest()->getParam('customer_id');
54
+ //no customer was found
55
+ if (! $customerId) {
56
+ //throw new Exception('Recentlyviewed : no customer id : ' . $customerId);
57
+ Mage::helper('ddg')->log('Recentlyviewed : no customer id : ' . $customerId);
58
+ $this->sendResponse();
59
+ die;
60
+ }
61
+ $this->loadLayout();
62
+ //set content template
63
+ $products = $this->getLayout()->createBlock('ddg_automation/recommended_recentlyviewed', 'connector_customer', array(
64
+ 'template' => 'connector/product/list.phtml'
65
+ ));
66
+ $this->getLayout()->getBlock('content')->append($products);
67
+ $this->renderLayout();
68
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
69
+ }
70
+ }
app/code/community/Dotdigitalgroup/Email/controllers/ResponseController.php ADDED
@@ -0,0 +1,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 tran