dotmailermagento - Version 5.1.0

Version Notes

New Automation improvements.

Transactional Emails, Custom Customer Attributes, Reports & More

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

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

Release Highlights:

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

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

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

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

Download this release

Release Info

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


Code changes from version 1.5.1 to 5.1.0

Files changed (306) hide show
  1. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Automation.php +17 -0
  2. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Automation/Edit.php +35 -0
  3. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Automation/Edit/Form.php +26 -0
  4. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Automation/Grid.php +158 -0
  5. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Campaign.php +17 -0
  6. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Campaign/Grid.php +178 -0
  7. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Catalog.php +15 -0
  8. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Catalog/Grid.php +106 -0
  9. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Column/Renderer/Delete.php +17 -0
  10. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Column/Renderer/Imported.php +16 -0
  11. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Column/Renderer/Reset.php +17 -0
  12. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Column/Renderer/Script.php +21 -0
  13. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Column/Renderer/Status.php +18 -0
  14. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Column/Renderer/Sync.php +16 -0
  15. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Column/Renderer/Website.php +15 -0
  16. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Config/Automation/Customdatafields.php +104 -0
  17. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Config/Customdatafields.php +112 -0
  18. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Config/Rules/Customdatafields.php +266 -0
  19. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Config/Select.php +14 -0
  20. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Contact.php +17 -0
  21. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Contact/Edit.php +36 -0
  22. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Contact/Edit/Form.php +26 -0
  23. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Contact/Grid.php +219 -0
  24. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Customer/Tab.php +41 -0
  25. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Customer/Tab/Stats.php +41 -0
  26. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard.php +52 -0
  27. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Switcher.php +92 -0
  28. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs.php +59 -0
  29. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Analysis.php +61 -0
  30. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Analysis/Abandonedcarts.php +57 -0
  31. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Analysis/Customer.php +55 -0
  32. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Analysis/Rfm.php +91 -0
  33. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Analysis/Sales.php +54 -0
  34. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Analysis/Subscriber.php +56 -0
  35. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/General.php +106 -0
  36. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/General/Data.php +43 -0
  37. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Logs.php +35 -0
  38. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Status.php +1749 -0
  39. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Importer.php +15 -0
  40. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Importer/Grid.php +163 -0
  41. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Order.php +15 -0
  42. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Order/Grid.php +123 -0
  43. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Quote.php +15 -0
  44. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Quote/Grid.php +120 -0
  45. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Review.php +15 -0
  46. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Review/Grid.php +109 -0
  47. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Rules.php +14 -0
  48. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Rules/Edit.php +46 -0
  49. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Rules/Edit/Form.php +22 -0
  50. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Rules/Edit/Tab/Conditions.php +85 -0
  51. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Rules/Edit/Tab/Main.php +121 -0
  52. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Rules/Edit/Tabs.php +12 -0
  53. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Rules/Grid.php +116 -0
  54. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Sales/Order/Creditmemo/View.php +196 -0
  55. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/.DS_Store +0 -0
  56. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Deletecontactids.php +22 -0
  57. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Notification.php +11 -0
  58. app/code/{local/Dotdigitalgroup/Email/Block/Debug/Initialsync.php → community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Reimportcatalog.php} +9 -7
  59. app/code/{local/Dotdigitalgroup/Email/Block/Debug/Countcontacts.php → community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Reimportorders.php} +7 -6
  60. app/code/{local/Dotdigitalgroup/Email/Block/Debug/Deletecontacts.php → community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Reimportquotes.php} +7 -6
  61. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Reimportreviews.php +22 -0
  62. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Reimportsubscribers.php +22 -0
  63. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Reimportwishlists.php +22 -0
  64. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Reset.php +22 -0
  65. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Resetcustomersimport.php +22 -0
  66. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Runcatalogsync.php +22 -0
  67. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Runcontactsync.php +22 -0
  68. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Runordersync.php +22 -0
  69. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Runquotesync.php +22 -0
  70. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Runreviewsync.php +22 -0
  71. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Runsubscribersync.php +22 -0
  72. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Runwishlistsync.php +22 -0
  73. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Advanced/Setupdatafields.php +24 -0
  74. app/code/{local/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Password.php → community/Dotdigitalgroup/Email/Block/Adminhtml/System/Ajaxvalidate.php} +1 -1
  75. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Automation/Connect.php +41 -0
  76. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Addressbook.php +39 -0
  77. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Colorpicker.php +66 -0
  78. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Datafield.php +41 -0
  79. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Enterprisevalidator.php +30 -0
  80. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Resetcontacts.php +28 -0
  81. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Resetguests.php +28 -0
  82. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Resetsubscribers.php +28 -0
  83. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Validator.php +87 -0
  84. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Waitingfield.php +65 -0
  85. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Wrapper.php +59 -0
  86. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Addressbookbutton.php +22 -0
  87. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Basket/Crosssell.php +26 -0
  88. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Basket/Related.php +27 -0
  89. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Basket/Upsell.php +25 -0
  90. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Bestsellers.php +24 -0
  91. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Couponinfo.php +26 -0
  92. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Creditmemonew.php +25 -0
  93. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Crosssell.php +26 -0
  94. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Datafieldbutton.php +21 -0
  95. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Fallbackchooser.php +25 -0
  96. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Fallbackcontainer.php +27 -0
  97. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Feefo/Reviews.php +22 -0
  98. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Feefo/Score.php +22 -0
  99. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Gridlist.php +106 -0
  100. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Lostbasket.php +31 -0
  101. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Manualchooser.php +25 -0
  102. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Manualcontainer.php +27 -0
  103. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Mostviewed.php +21 -0
  104. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Nosto.php +22 -0
  105. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Productpush.php +21 -0
  106. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Recentlyviewed.php +24 -0
  107. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Related.php +26 -0
  108. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Review.php +29 -0
  109. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Upsell.php +24 -0
  110. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Wishlist.php +33 -0
  111. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Wishlist/Crosssell.php +32 -0
  112. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Wishlist/Related.php +32 -0
  113. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Dynamic/Wishlist/Upsell.php +31 -0
  114. app/code/{local/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Wrapper.php → community/Dotdigitalgroup/Email/Block/Adminhtml/System/Emailapivalidate.php} +9 -8
  115. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Installation.php +161 -0
  116. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Sms/Smsmessagefour.php +24 -0
  117. app/code/{local/Dotdigitalgroup/Email/Block/Adminhtml/System/Config → community/Dotdigitalgroup/Email/Block/Adminhtml/System/Sms}/Smsmessageone.php +13 -8
  118. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Sms/Smsmessagethree.php +26 -0
  119. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Sms/Smsmessagetwo.php +25 -0
  120. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Creditmemoupdate.php +32 -0
  121. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Creditmemoupdateguest.php +30 -0
  122. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Customerconfirmation.php +36 -0
  123. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Customerconfirmed.php +36 -0
  124. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Customernew.php +36 -0
  125. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Invoiceupdate.php +33 -0
  126. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Invoiceupdateguest.php +33 -0
  127. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Newcreditmemo.php +36 -0
  128. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Newcreditmemoguest.php +35 -0
  129. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Newinvoice.php +34 -0
  130. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Newinvoiceguest.php +34 -0
  131. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Neworder.php +33 -0
  132. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Neworderguest.php +32 -0
  133. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Newshipment.php +34 -0
  134. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Newshipmentguest.php +33 -0
  135. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Orderupdate.php +31 -0
  136. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Orderupdateguest.php +31 -0
  137. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Shipmentupdate.php +33 -0
  138. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Url/Shipmentupdateguest.php +32 -0
  139. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Widget/Chooser/Product.php +163 -0
  140. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Wishlist.php +15 -0
  141. app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Wishlist/Grid.php +120 -0
  142. app/code/community/Dotdigitalgroup/Email/Block/Basket.php +87 -0
  143. app/code/{local → community}/Dotdigitalgroup/Email/Block/Coupon.php +21 -16
  144. app/code/community/Dotdigitalgroup/Email/Block/Customer/Account/Books.php +214 -0
  145. app/code/community/Dotdigitalgroup/Email/Block/Edc.php +410 -0
  146. app/code/community/Dotdigitalgroup/Email/Block/Feefo.php +102 -0
  147. app/code/community/Dotdigitalgroup/Email/Block/Order.php +75 -0
  148. app/code/community/Dotdigitalgroup/Email/Block/Order/Creditmemo.php +45 -0
  149. app/code/community/Dotdigitalgroup/Email/Block/Order/Invoice.php +36 -0
  150. app/code/community/Dotdigitalgroup/Email/Block/Order/Shipping.php +36 -0
  151. app/code/community/Dotdigitalgroup/Email/Block/Products.php +67 -0
  152. app/code/community/Dotdigitalgroup/Email/Block/Recommended/Products.php +68 -0
  153. app/code/community/Dotdigitalgroup/Email/Block/Recommended/Wishlistproducts.php +52 -0
  154. app/code/community/Dotdigitalgroup/Email/Block/System/Email/Template/Edit.php +13 -0
  155. app/code/community/Dotdigitalgroup/Email/Block/Wishlist.php +43 -0
  156. app/code/community/Dotdigitalgroup/Email/Helper/Config.php +347 -0
  157. app/code/community/Dotdigitalgroup/Email/Helper/Dashboard.php +171 -0
  158. app/code/community/Dotdigitalgroup/Email/Helper/Data.php +937 -0
  159. app/code/{local → community}/Dotdigitalgroup/Email/Helper/File.php +89 -30
  160. app/code/community/Dotdigitalgroup/Email/Helper/Recommended.php +178 -0
  161. app/code/community/Dotdigitalgroup/Email/Helper/Review.php +90 -0
  162. app/code/community/Dotdigitalgroup/Email/Helper/Transactional.php +65 -0
  163. app/code/community/Dotdigitalgroup/Email/Model/Abstract/Rest.php +492 -0
  164. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Content.php +121 -0
  165. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Abandoned.php +59 -0
  166. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Customer.php +48 -0
  167. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Orders.php +93 -0
  168. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Rfm.php +160 -0
  169. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Subscriber.php +90 -0
  170. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Observer.php +229 -0
  171. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Addressbooks.php +47 -0
  172. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Addressbookspref.php +71 -0
  173. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Abandonedlimit.php +43 -0
  174. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Attributes.php +22 -0
  175. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Cronexpressionsone.php +13 -0
  176. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Cronexpressionstwo.php +13 -0
  177. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Frequency.php +15 -0
  178. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Quoteattributes.php +21 -0
  179. app/code/{local/Dotdigitalgroup/Email/Model/System/Config/Source/Orderlimit.php → community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Transdata.php} +1 -1
  180. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Attributes.php +25 -0
  181. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Automation/Programme.php +39 -0
  182. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Campaigns.php +58 -0
  183. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Contact/Imported.php +17 -0
  184. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Contact/Modified.php +17 -0
  185. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Customer/Attributes/Select.php +36 -0
  186. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Datafields.php +55 -0
  187. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Datamapping/Datafieldaccess.php +17 -0
  188. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Datamapping/Datafieldtype.php +22 -0
  189. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Dynamic/Displaytype.php +18 -0
  190. app/code/{local/Dotdigitalgroup/Email/Model/System/Config/Source → community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Dynamic}/Gridview.php +6 -1
  191. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Fontpicker.php +35 -0
  192. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Fontsize.php +30 -0
  193. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Importer/Mode.php +19 -0
  194. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Importer/Status.php +19 -0
  195. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Lostbaskets/Interval.php +40 -0
  196. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Lostbaskets/Intervalminute.php +21 -0
  197. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Orderstatus.php +22 -0
  198. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Publicdatafields.php +63 -0
  199. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Reviews/Delay.php +26 -0
  200. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Rules/Condition.php +67 -0
  201. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Rules/Type.php +72 -0
  202. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Rules/Value.php +89 -0
  203. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Styling.php +18 -0
  204. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Sweettooth/Yesno.php +26 -0
  205. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Sync/Catalog/Attributes.php +28 -0
  206. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Sync/Catalog/Type.php +16 -0
  207. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Sync/Catalog/Values.php +23 -0
  208. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Sync/Catalog/Visibility.php +16 -0
  209. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Sync/Yesno.php +61 -0
  210. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Transactional/Mode.php +12 -0
  211. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Transactional/Port.php +15 -0
  212. app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Transactional/Ssl.php +12 -0
  213. app/code/community/Dotdigitalgroup/Email/Model/Api2/Subscriber/Rest/Admin/V1.php +111 -0
  214. app/code/community/Dotdigitalgroup/Email/Model/Apiconnector/Client.php +1254 -0
  215. app/code/community/Dotdigitalgroup/Email/Model/Apiconnector/Contact.php +427 -0
  216. app/code/community/Dotdigitalgroup/Email/Model/Apiconnector/Customer.php +924 -0
  217. app/code/community/Dotdigitalgroup/Email/Model/Apiconnector/Test.php +50 -0
  218. app/code/community/Dotdigitalgroup/Email/Model/Automation.php +213 -0
  219. app/code/community/Dotdigitalgroup/Email/Model/Campaign.php +145 -0
  220. app/code/community/Dotdigitalgroup/Email/Model/Catalog.php +420 -0
  221. app/code/{local → community}/Dotdigitalgroup/Email/Model/Connector/Account.php +61 -7
  222. app/code/community/Dotdigitalgroup/Email/Model/Connector/Campaign.php +100 -0
  223. app/code/community/Dotdigitalgroup/Email/Model/Connector/Datafield.php +298 -0
  224. app/code/community/Dotdigitalgroup/Email/Model/Connector/Order.php +467 -0
  225. app/code/community/Dotdigitalgroup/Email/Model/Connector/Product.php +161 -0
  226. app/code/community/Dotdigitalgroup/Email/Model/Connector/Quote.php +323 -0
  227. app/code/community/Dotdigitalgroup/Email/Model/Contact.php +238 -0
  228. app/code/community/Dotdigitalgroup/Email/Model/Controller/Observer.php +43 -0
  229. app/code/community/Dotdigitalgroup/Email/Model/Cron.php +172 -0
  230. app/code/community/Dotdigitalgroup/Email/Model/Customer.php +20 -0
  231. app/code/community/Dotdigitalgroup/Email/Model/Customer/Guest.php +71 -0
  232. app/code/community/Dotdigitalgroup/Email/Model/Customer/Observer.php +374 -0
  233. app/code/community/Dotdigitalgroup/Email/Model/Customer/Review.php +241 -0
  234. app/code/community/Dotdigitalgroup/Email/Model/Customer/Review/Rating.php +46 -0
  235. app/code/community/Dotdigitalgroup/Email/Model/Customer/Wishlist.php +121 -0
  236. app/code/{local → community}/Dotdigitalgroup/Email/Model/Customer/Wishlist/Item.php +29 -16
  237. app/code/community/Dotdigitalgroup/Email/Model/Email.php +36 -0
  238. app/code/community/Dotdigitalgroup/Email/Model/Email/Template.php +93 -0
  239. app/code/community/Dotdigitalgroup/Email/Model/Feed.php +88 -0
  240. app/code/community/Dotdigitalgroup/Email/Model/Importer.php +377 -0
  241. app/code/community/Dotdigitalgroup/Email/Model/Newsletter/Observer.php +138 -0
  242. app/code/community/Dotdigitalgroup/Email/Model/Newsletter/Sub.php +12 -0
  243. app/code/community/Dotdigitalgroup/Email/Model/Newsletter/Subscriber.php +110 -0
  244. app/code/community/Dotdigitalgroup/Email/Model/Order.php +126 -0
  245. app/code/community/Dotdigitalgroup/Email/Model/Quote.php +193 -0
  246. app/code/community/Dotdigitalgroup/Email/Model/Resource/Automation.php +75 -0
  247. app/code/community/Dotdigitalgroup/Email/Model/Resource/Automation/Collection.php +25 -0
  248. app/code/community/Dotdigitalgroup/Email/Model/Resource/Campaign.php +54 -0
  249. app/code/community/Dotdigitalgroup/Email/Model/Resource/Campaign/Collection.php +13 -0
  250. app/code/community/Dotdigitalgroup/Email/Model/Resource/Catalog.php +53 -0
  251. app/code/community/Dotdigitalgroup/Email/Model/Resource/Catalog/Collection.php +13 -0
  252. app/code/community/Dotdigitalgroup/Email/Model/Resource/Contact.php +315 -0
  253. app/code/community/Dotdigitalgroup/Email/Model/Resource/Contact/Collection.php +25 -0
  254. app/code/community/Dotdigitalgroup/Email/Model/Resource/Importer.php +51 -0
  255. app/code/community/Dotdigitalgroup/Email/Model/Resource/Importer/Collection.php +13 -0
  256. app/code/community/Dotdigitalgroup/Email/Model/Resource/Order.php +41 -0
  257. app/code/community/Dotdigitalgroup/Email/Model/Resource/Order/Collection.php +18 -0
  258. app/code/community/Dotdigitalgroup/Email/Model/Resource/Quote.php +59 -0
  259. app/code/community/Dotdigitalgroup/Email/Model/Resource/Quote/Collection.php +14 -0
  260. app/code/community/Dotdigitalgroup/Email/Model/Resource/Review.php +50 -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 +156 -0
  265. app/code/community/Dotdigitalgroup/Email/Model/Resource/Setup.php +26 -0
  266. app/code/community/Dotdigitalgroup/Email/Model/Resource/Wishlist.php +53 -0
  267. app/code/community/Dotdigitalgroup/Email/Model/Resource/Wishlist/Collection.php +13 -0
  268. app/code/community/Dotdigitalgroup/Email/Model/Review.php +146 -0
  269. app/code/community/Dotdigitalgroup/Email/Model/Rules.php +436 -0
  270. app/code/community/Dotdigitalgroup/Email/Model/Sales/Observer.php +302 -0
  271. app/code/community/Dotdigitalgroup/Email/Model/Sales/Order.php +435 -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 +221 -0
  276. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/ConnectorController.php +391 -0
  277. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/CustomerController.php +12 -0
  278. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/AutomationController.php +85 -0
  279. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/CampaignController.php +99 -0
  280. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/CatalogController.php +25 -0
  281. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/ContactController.php +138 -0
  282. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/DashboardController.php +95 -0
  283. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/ImporterController.php +66 -0
  284. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/OrderController.php +25 -0
  285. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/QuoteController.php +25 -0
  286. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/ReviewController.php +25 -0
  287. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/RulesController.php +208 -0
  288. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/StudioController.php +110 -0
  289. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/WishlistController.php +25 -0
  290. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/RulesController.php +130 -0
  291. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/System/Email/TemplateController.php +36 -0
  292. app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Widget/ChooserController.php +24 -0
  293. app/code/community/Dotdigitalgroup/Email/controllers/AjaxController.php +21 -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 +40 -0
  297. app/code/community/Dotdigitalgroup/Email/controllers/EmailController.php +278 -0
  298. app/code/community/Dotdigitalgroup/Email/controllers/FeefoController.php +54 -0
  299. app/code/community/Dotdigitalgroup/Email/controllers/ProductsController.php +99 -0
  300. app/code/community/Dotdigitalgroup/Email/controllers/QuoteproductsController.php +69 -0
  301. app/code/community/Dotdigitalgroup/Email/controllers/ReportController.php +55 -0
  302. app/code/community/Dotdigitalgroup/Email/controllers/ResponseController.php +50 -0
  303. app/code/community/Dotdigitalgroup/Email/controllers/WishlistController.php +35 -0
  304. app/code/community/Dotdigitalgroup/Email/etc/adminhtml.xml +210 -0
  305. app/code/community/Dotdigitalgroup/Email/etc/api2.xml +43 -0
  306. app/code/community/Dotdigitalgroup/Email/etc/config.xml +484 -0
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Automation.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Automation extends Mage_Adminhtml_Block_Widget_Grid_Container
4
+ {
5
+ /**
6
+ * Set the template.
7
+ */
8
+ public function __construct()
9
+ {
10
+ $this->_controller = 'adminhtml_automation';
11
+ $this->_blockGroup = 'ddg_automation';
12
+ parent::__construct();
13
+ $this->_headerText = Mage::helper('ddg')->__('Automation Status');
14
+ $this->_removeButton('add');
15
+
16
+ }
17
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Automation/Edit.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Automation_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+ $this->_blockGroup = 'ddg_automation';
9
+ $this->_controller = 'adminhtml_automation';
10
+ $this->_updateButton('delete', 'label', Mage::helper('ddg')->__('Delete Contact'));
11
+ $this->_addButton('saveandcontinue', array(
12
+ 'label' => Mage::helper('ddg')->__('Save And Continue Edit'),
13
+ 'onclick' => 'saveAndContinueEdit()',
14
+ 'class' => 'save',
15
+ ), -100);
16
+ $this->_formScripts[] = "
17
+ function saveAndContinueEdit(){
18
+ editForm.submit($('edit_form').action+'back/edit/');
19
+ }
20
+ ";
21
+ }
22
+
23
+ /**
24
+ * HEader text.
25
+ * @return string
26
+ */
27
+ public function getHeaderText()
28
+ {
29
+ if ( Mage::registry('automation_data') && Mage::registry('contact_data')->getId() ) {
30
+ return Mage::helper('ddg')->__("Edit Automation '%s'", $this->htmlEscape(Mage::registry('contact_data')->getContact()));
31
+ } else {
32
+ return Mage::helper('ddg')->__('Add Automation');
33
+ }
34
+ }
35
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Automation/Edit/Form.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Automation_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
4
+ {
5
+
6
+ /**
7
+ * Contact Form.
8
+ * @return Mage_Adminhtml_Block_Widget_Form
9
+ * @throws Exception
10
+ */
11
+ protected function _prepareForm()
12
+ {
13
+ $form = new Varien_Data_Form(array(
14
+ 'id' => 'edit_form',
15
+ 'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'), 'store' => $this->getRequest()->getParam('store'))),
16
+ 'method' => 'post',
17
+ 'enctype' => 'multipart/form-data'
18
+ )
19
+ );
20
+ $form->setUseContainer(true);
21
+
22
+ $this->setForm($form);
23
+ return parent::_prepareForm();
24
+ }
25
+
26
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Automation/Grid.php ADDED
@@ -0,0 +1,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/Grid.php ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Campaign_Grid extends Mage_Adminhtml_Block_Widget_Grid
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+ $this->setId('id');
9
+ $this->setDefaultSort('entity_id');
10
+ $this->setDefaultDir('ASC');
11
+ $this->setSaveParametersInSession(true);
12
+ $this->setUseAjax(true);
13
+ }
14
+
15
+ /**
16
+ * Prepare grid collection object.
17
+ * @return Mage_Adminhtml_Block_Widget_Grid
18
+ */
19
+ protected function _prepareCollection()
20
+ {
21
+ $collection = Mage::getModel('ddg_automation/campaign')->getCollection();
22
+ $this->setCollection($collection);
23
+ $this->setDefaultSort('created_at');
24
+ $this->setDefaultDir('DESC');
25
+ return parent::_prepareCollection();
26
+ }
27
+
28
+ protected function _prepareColumns()
29
+ {
30
+ $this->addColumn('id', array(
31
+ 'header' => Mage::helper('ddg')->__('Campaign ID'),
32
+ 'width' => '20px',
33
+ 'index' => 'campaign_id',
34
+ 'type' => 'number',
35
+ 'truncate' => 50,
36
+ 'escape' => true
37
+ ))->addColumn('customer_id', array(
38
+ 'header' => Mage::helper('ddg')->__('Customer ID'),
39
+ 'align' => 'left',
40
+ 'width' => '50px',
41
+ 'index' => 'customer_id',
42
+ 'type' => 'number',
43
+ 'escape' => true
44
+ ))->addColumn('email', array(
45
+ 'header' => Mage::helper('ddg')->__('Email'),
46
+ 'align' => 'left',
47
+ 'width' => '50px',
48
+ 'index' => 'email',
49
+ 'type' => 'text',
50
+ 'escape' => true
51
+ ))->addColumn('is_sent', array(
52
+ 'header' => Mage::helper('ddg')->__('Is Sent'),
53
+ 'align' => 'center',
54
+ 'width' => '20px',
55
+ 'index' => 'is_sent',
56
+ 'escape' => true,
57
+ 'type' => 'options',
58
+ 'renderer' => 'ddg_automation/adminhtml_column_renderer_imported',
59
+ 'options' => array(
60
+ '1' => 'Is Send',
61
+ 'null' => 'Not Send'
62
+ ),
63
+ 'filter_condition_callback' => array($this, 'filterCallbackContact')
64
+ ))->addColumn('message', array(
65
+ 'header' => Mage::helper('ddg')->__('Send Message'),
66
+ 'align' => 'left',
67
+ 'width' => '300px',
68
+ 'index' => 'message',
69
+ 'type' => 'text',
70
+ 'escape' => true
71
+ ))->addColumn('event_name', array(
72
+ 'header' => Mage::helper('ddg')->__('Event Name'),
73
+ 'align' => 'left',
74
+ 'index' => 'event_name',
75
+ 'width' => '100px',
76
+ 'type' => 'string',
77
+ 'escape' => true
78
+ ))->addColumn('quote_id', array(
79
+ 'header' => Mage::helper('ddg')->__('Quote Id'),
80
+ 'align' => 'left',
81
+ 'width' => '50px',
82
+ 'index' => 'quote_id',
83
+ 'type' => 'number',
84
+ 'escape' => true
85
+ ))->addColumn('sent_at', array(
86
+ 'header' => Mage::helper('ddg')->__('Sent At'),
87
+ 'align' => 'center',
88
+ 'width' => '100px',
89
+ 'index' => 'sent_at',
90
+ 'type' => 'datetime',
91
+ 'escape' => true
92
+ ))->addColumn('created_at', array(
93
+ 'header' => Mage::helper('ddg')->__('Created At'),
94
+ 'align' => 'center',
95
+ 'width' => '100px',
96
+ 'index' => 'created_at',
97
+ 'type' => 'datetime',
98
+ 'escape' => true
99
+ ))->addColumn('updated_at', array(
100
+ 'header' => Mage::helper('ddg')->__('Updated At'),
101
+ 'align' => 'center',
102
+ 'width' => '100px',
103
+ 'index' => 'updated_at',
104
+ 'type' => 'datetime',
105
+ 'escape' => true
106
+ ));
107
+ if (!Mage::app()->isSingleStoreMode()) {
108
+ $this->addColumn('store_id', array(
109
+ 'header' => Mage::helper('customer')->__('Store'),
110
+ 'align' => 'center',
111
+ 'width' => '80px',
112
+ 'type' => 'options',
113
+ 'options' => Mage::getSingleton('adminhtml/system_store')->getStoreOptionHash(true),
114
+ 'index' => 'store_id'
115
+ ));
116
+ }
117
+
118
+ $this->addExportType('*/*/exportCsv', Mage::helper('ddg')->__('CSV'));
119
+ return parent::_prepareColumns();
120
+ }
121
+
122
+ /**
123
+ * Get the store selected.
124
+ * @return Mage_Core_Model_Store
125
+ * @throws Exception
126
+ */
127
+ protected function _getStore()
128
+ {
129
+ $storeId = (int) $this->getRequest()->getParam('store', 0);
130
+ return Mage::app()->getStore($storeId);
131
+ }
132
+
133
+
134
+ /**
135
+ * @return $this|Mage_Adminhtml_Block_Widget_Grid
136
+ */
137
+ protected function _prepareMassaction()
138
+ {
139
+ $this->setMassactionIdField('id');
140
+ $this->getMassactionBlock()->setFormFieldName('campaign');
141
+ $this->getMassactionBlock()->addItem('delete', array (
142
+ 'label'=> Mage::helper('ddg')->__('Delete'),
143
+ 'url' => $this->getUrl('*/*/massDelete'),
144
+ 'confirm' => Mage::helper('ddg')->__('Are you sure?')
145
+ )
146
+ );
147
+
148
+ $this->getMassactionBlock()->addItem('resend', array('label'=>Mage::helper('ddg')->__('Resend'),'url'=>$this->getUrl('*/*/massResend')));
149
+ return $this;
150
+ }
151
+
152
+ /**
153
+ * Grid selected url.
154
+ * @return string
155
+ */
156
+ public function getGridUrl()
157
+ {
158
+ return $this->getUrl('*/*/grid', array('_current'=>true));
159
+ }
160
+ /**
161
+ * Custom callback action for the campaign.
162
+ *
163
+ * @param $collection
164
+ * @param $column
165
+ */
166
+ public function filterCallbackContact($collection, $column)
167
+ {
168
+ $field = $column->getFilterIndex() ? $column->getFilterIndex() : $column->getIndex();
169
+ $value = $column->getFilter()->getValue();
170
+
171
+ if ($value == 'null') {
172
+ $collection->addFieldToFilter($field, array('null' => true) );
173
+ } else {
174
+ $collection->addFieldToFilter($field, array('notnull' => true));
175
+ }
176
+ }
177
+
178
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Catalog.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Catalog extends Mage_Adminhtml_Block_Widget_Grid_Container
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+
9
+ $this->_controller = 'adminhtml_catalog';
10
+ $this->_blockGroup = 'ddg_automation';
11
+ $this->_headerText = Mage::helper('ddg')->__('Email Catalog');
12
+
13
+ $this->_removeButton('add');
14
+ }
15
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Catalog/Grid.php ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Catalog_Grid extends Mage_Adminhtml_Block_Widget_Grid
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+
9
+ // Set some defaults for our grid
10
+ $this->setDefaultSort('id');
11
+ $this->setId('id');
12
+ $this->setDefaultDir('asc');
13
+ }
14
+
15
+ /**
16
+ * Collection class;
17
+ * @return string
18
+ */
19
+ protected function _getCollectionClass()
20
+ {
21
+ // This is the model we are using for the grid
22
+ return 'ddg_automation/catalog_collection';
23
+ }
24
+
25
+ /**
26
+ * Prepare the grid collection.
27
+ * @return Mage_Adminhtml_Block_Widget_Grid
28
+ */
29
+ protected function _prepareCollection()
30
+ {
31
+ // Get and set our collection for the grid
32
+ $collection = Mage::getResourceModel($this->_getCollectionClass());
33
+ $this->setCollection($collection);
34
+ return parent::_prepareCollection();
35
+ }
36
+
37
+ /**
38
+ * Prepare the grid collumns.
39
+ * @return $this
40
+ * @throws Exception
41
+ */
42
+ protected function _prepareColumns()
43
+ {
44
+ $this->addColumn('product_id', array(
45
+ 'header' => Mage::helper('ddg')->__('Product ID'),
46
+ 'align' => 'left',
47
+ 'width' => '50px',
48
+ 'index' => 'product_id',
49
+ 'type' => 'number',
50
+ 'escape' => true
51
+ ))->addColumn('imported', array(
52
+ 'header' => Mage::helper('ddg')->__('Imported'),
53
+ 'align' => 'center',
54
+ 'width' => '50px',
55
+ 'index' => 'imported',
56
+ 'type' => 'options',
57
+ 'escape' => true,
58
+ 'renderer' => 'ddg_automation/adminhtml_column_renderer_imported',
59
+ 'options' => Mage::getModel('ddg_automation/adminhtml_source_contact_imported')->getOptions(),
60
+ 'filter_condition_callback' => array($this, 'filterCallbackContact')
61
+ ))->addColumn('modified', array(
62
+ 'header' => Mage::helper('ddg')->__('Modified'),
63
+ 'align' => 'center',
64
+ 'width' => '50px',
65
+ 'index' => 'modified',
66
+ 'type' => 'options',
67
+ 'escape' => true,
68
+ 'renderer' => 'ddg_automation/adminhtml_column_renderer_imported',
69
+ 'options' => Mage::getModel('ddg_automation/adminhtml_source_contact_modified')->getOptions(),
70
+ 'filter_condition_callback' => array($this, 'filterCallbackContact')
71
+ ))->addColumn('created_at', array(
72
+ 'header' => Mage::helper('ddg')->__('Created At'),
73
+ 'width' => '50px',
74
+ 'align' => 'center',
75
+ 'index' => 'created_at',
76
+ 'type' => 'datetime',
77
+ 'escape' => true,
78
+ ))->addColumn('updated_at', array(
79
+ 'header' => Mage::helper('ddg')->__('Updated At'),
80
+ 'width' => '50px',
81
+ 'align' => 'center',
82
+ 'index' => 'updated_at',
83
+ 'type' => 'datetime',
84
+ 'escape' => true,
85
+ ));
86
+
87
+ return parent::_prepareColumns();
88
+ }
89
+
90
+ /**
91
+ * Callback action for the imported subscribers/contacts.
92
+ *
93
+ * @param $collection
94
+ * @param $column
95
+ */
96
+ public function filterCallbackContact($collection, $column)
97
+ {
98
+ $field = $column->getFilterIndex() ? $column->getFilterIndex() : $column->getIndex();
99
+ $value = $column->getFilter()->getValue();
100
+ if ($value == 'null') {
101
+ $collection->addFieldToFilter($field, array('null' => true));
102
+ } else {
103
+ $collection->addFieldToFilter($field, array('notnull' => true));
104
+ }
105
+ }
106
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Column/Renderer/Delete.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Column_Renderer_Delete extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
4
+ {
5
+ /**
6
+ * Render the grid columns.
7
+ *
8
+ * @param Varien_Object $row
9
+ * @return string
10
+ */
11
+ public function render(Varien_Object $row)
12
+ {
13
+ $url = HtmlSpecialChars(json_encode(Mage::helper('adminhtml')->getUrl('*/*/delete', array('id' => $row->getId()))));
14
+ return '<button title="Delete" onclick="visitPage(' . $url . ')" type="button" style=""><span><span><span>Delete</span></span></span></button>';
15
+ }
16
+
17
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Column/Renderer/Imported.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Column_Renderer_Imported extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
4
+ {
5
+ /**
6
+ * Render grid columns.
7
+ * @param Varien_Object $row
8
+ *
9
+ * @return string
10
+ */
11
+ public function render(Varien_Object $row)
12
+ {
13
+ return '<img style="padding-top:2px" '.(($this->_getValue($row)=='1' || $this->_getValue($row)==true) ? 'src="'.$this->getSkinUrl('images/success_msg_icon.gif').'" alt="YES" ' : 'src="'.
14
+ $this->getSkinUrl('images/error_msg_icon.gif').'" alt="NO" ').'>';
15
+ }
16
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Column/Renderer/Reset.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Column_Renderer_Reset extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
4
+ {
5
+ /**
6
+ * Render the grid columns.
7
+ *
8
+ * @param Varien_Object $row
9
+ * @return string
10
+ */
11
+ public function render(Varien_Object $row)
12
+ {
13
+ $url = HtmlSpecialChars(json_encode(Mage::helper('adminhtml')->getUrl('*/*/reset', array('id' => $row->getId()))));
14
+ return '<button title="Reset" onclick="visitPage(' . $url . '); return false" type="button" style=""><span><span><span>Reset</span></span></span></button>';
15
+ }
16
+
17
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Column/Renderer/Script.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Column_Renderer_Script extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
4
+ {
5
+ /**
6
+ * Render the grid columns.
7
+ *
8
+ * @param Varien_Object $row
9
+ * @return string
10
+ */
11
+ public function render(Varien_Object $row)
12
+ {
13
+ $html = "<script type='application/javascript'>
14
+ function visitPage(url){
15
+ document.location.href = url;
16
+ }
17
+ </script>";
18
+ return $html;
19
+ }
20
+
21
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Column/Renderer/Status.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Column_Renderer_Status extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
4
+ {
5
+ /**
6
+ * Render the grid columns.
7
+ *
8
+ * @param Varien_Object $row
9
+ * @return string
10
+ */
11
+ public function render(Varien_Object $row)
12
+ {
13
+ if($this->getValue($row) == '1')
14
+ return 'Subscribed';
15
+ return 'Unsubscribed';
16
+ }
17
+
18
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Column/Renderer/Sync.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Column_Renderer_Sync extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
4
+ {
5
+ /**
6
+ * Render the grid columns.
7
+ *
8
+ * @param Varien_Object $row
9
+ * @return string
10
+ */
11
+ public function render(Varien_Object $row)
12
+ {
13
+ return '<button title="Connect" type="button" style=""><span><span><span>Sync Now</span></span></span></button>';
14
+ }
15
+
16
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Column/Renderer/Website.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Column_Renderer_Website extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
4
+ {
5
+ /**
6
+ * Render grid columns.
7
+ * @param Varien_Object $row
8
+ *
9
+ * @return string
10
+ */
11
+ public function render(Varien_Object $row)
12
+ {
13
+ return Mage::app()->getStore($this->_getValue($row))->getWebsiteId();
14
+ }
15
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Config/Automation/Customdatafields.php ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Config_Automation_Customdatafields extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
4
+ {
5
+ protected $_getStatusRenderer;
6
+ protected $_getAutomationRenderer;
7
+
8
+
9
+ /**
10
+ * Construct.
11
+ */
12
+ public function __construct()
13
+ {
14
+ $this->_addAfter = false;
15
+ $this->_addButtonLabel = Mage::helper('adminhtml')->__('Add New Enrolment');
16
+ parent::__construct();
17
+
18
+ }
19
+
20
+ protected function _prepareToRender()
21
+ {
22
+ $this->_getStatusRenderer = null;
23
+ $this->_getAutomationRenderer = null;
24
+ $this->addColumn('status',
25
+ array(
26
+ 'label' => Mage::helper('adminhtml')->__('Order Status'),
27
+ 'style' => 'width:120px',
28
+ )
29
+ );
30
+ $this->addColumn('automation', array(
31
+ 'label' => Mage::helper('adminhtml')->__('Automation Programme'),
32
+ 'style' => 'width:120px',
33
+ )
34
+ );
35
+ }
36
+
37
+ protected function _renderCellTemplate($columnName)
38
+ {
39
+ $inputName = $this->getElement()->getName() . '[#{_id}][' . $columnName . ']';
40
+ if ($columnName=="status") {
41
+ return $this->_getStatusRenderer()
42
+ ->setName($inputName)
43
+ ->setTitle($columnName)
44
+ ->setExtraParams('style="width:160px"')
45
+ ->setOptions(
46
+ $this->getElement()->getValues()
47
+ )
48
+ ->toHtml();
49
+ } elseif ($columnName == "automation") {
50
+ return $this->_getAutomationRenderer()
51
+ ->setName($inputName)
52
+ ->setTitle($columnName)
53
+ ->setExtraParams('style="width:160px"')
54
+ ->setOptions(Mage::getModel('ddg_automation/adminhtml_source_automation_programme')->toOptionArray())
55
+ ->toHtml();
56
+ }
57
+ return parent::_renderCellTemplate($columnName);
58
+ }
59
+
60
+ /**
61
+ * Assign extra parameters to row
62
+ *
63
+ * @param Varien_Object $row
64
+ */
65
+ protected function _prepareArrayRow(Varien_Object $row)
66
+ {
67
+
68
+ $row->setData(
69
+ 'option_extra_attr_' . $this->_getStatusRenderer()->calcOptionHash($row->getData('status')),
70
+ 'selected="selected"'
71
+ );
72
+
73
+ $row->setData(
74
+ 'option_extra_attr_' . $this->_getAutomationRenderer()->calcOptionHash($row->getData('automation')),
75
+ 'selected="selected"'
76
+ );
77
+ }
78
+ protected function _getStatusRenderer()
79
+ {
80
+ if (!$this->_getStatusRenderer) {
81
+ $this->_getStatusRenderer = $this->getLayout()
82
+ ->createBlock('ddg_automation/adminhtml_config_select')
83
+ ->setIsRenderToJsTemplate(true);
84
+ }
85
+ return $this->_getStatusRenderer;
86
+ }
87
+
88
+ protected function _getAutomationRenderer()
89
+ {
90
+ if (!$this->_getAutomationRenderer) {
91
+ $this->_getAutomationRenderer = $this->getLayout()
92
+ ->createBlock('ddg_automation/adminhtml_config_select')
93
+ ->setIsRenderToJsTemplate(true);
94
+ }
95
+ return $this->_getAutomationRenderer;
96
+ }
97
+
98
+ public function _toHtml()
99
+ {
100
+ return '<input type="hidden" id="'.$this->getElement()->getHtmlId().'"/>'.parent::_toHtml();
101
+
102
+ }
103
+
104
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Config/Customdatafields.php ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Config_Customdatafields extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
4
+ {
5
+ /**
6
+ * Customer attribute
7
+ *
8
+ */
9
+ protected $_getAttributeRenderer;
10
+
11
+ /**
12
+ * Datafields
13
+ */
14
+ protected $_getDatafieldRenderer;
15
+
16
+
17
+ /**
18
+ * Construct.
19
+ */
20
+ public function __construct()
21
+ {
22
+ $this->_addAfter = false;
23
+ $this->_addButtonLabel = Mage::helper('adminhtml')->__('Add New Attribute');
24
+ parent::__construct();
25
+
26
+ }
27
+
28
+ protected function _prepareToRender()
29
+ {
30
+ $this->_getDatafieldRenderer = null;
31
+ $this->_getAttributeRenderer = null;
32
+ $this->addColumn('attribute',
33
+ array(
34
+ 'label' => Mage::helper('adminhtml')->__('Attribute'),
35
+ 'style' => 'width:120px',
36
+ )
37
+ );
38
+ $this->addColumn('datafield', array(
39
+ 'label' => Mage::helper('adminhtml')->__('DataField'),
40
+ 'style' => 'width:120px',
41
+ )
42
+ );
43
+ }
44
+
45
+ protected function _renderCellTemplate($columnName)
46
+ {
47
+ $inputName = $this->getElement()->getName() . '[#{_id}][' . $columnName . ']';
48
+ if ($columnName=="attribute") {
49
+ return $this->_getAttributeRenderer()
50
+ ->setName($inputName)
51
+ ->setTitle($columnName)
52
+ ->setExtraParams('style="width:160px"')
53
+ ->setOptions(
54
+ $this->getElement()->getValues()
55
+ )
56
+ ->toHtml();
57
+ } elseif ($columnName == "datafield") {
58
+ return $this->_getDatafieldRenderer()
59
+ ->setName($inputName)
60
+ ->setTitle($columnName)
61
+ ->setExtraParams('style="width:160px"')
62
+ ->setOptions(Mage::getModel('ddg_automation/adminhtml_source_datafields')->toOptionArray())
63
+ ->toHtml();
64
+ }
65
+ return parent::_renderCellTemplate($columnName);
66
+ }
67
+
68
+ /**
69
+ * Assign extra parameters to row
70
+ *
71
+ * @param Varien_Object $row
72
+ */
73
+ protected function _prepareArrayRow(Varien_Object $row)
74
+ {
75
+
76
+ $row->setData(
77
+ 'option_extra_attr_' . $this->_getAttributeRenderer()->calcOptionHash($row->getData('attribute')),
78
+ 'selected="selected"'
79
+ );
80
+
81
+ $row->setData(
82
+ 'option_extra_attr_' . $this->_getDatafieldRenderer()->calcOptionHash($row->getData('datafield')),
83
+ 'selected="selected"'
84
+ );
85
+ }
86
+ protected function _getAttributeRenderer()
87
+ {
88
+ if (!$this->_getAttributeRenderer) {
89
+ $this->_getAttributeRenderer = $this->getLayout()
90
+ ->createBlock('ddg_automation/adminhtml_config_select')
91
+ ->setIsRenderToJsTemplate(true);
92
+ }
93
+ return $this->_getAttributeRenderer;
94
+ }
95
+
96
+ protected function _getDatafieldRenderer()
97
+ {
98
+ if (!$this->_getDatafieldRenderer) {
99
+ $this->_getDatafieldRenderer = $this->getLayout()
100
+ ->createBlock('ddg_automation/adminhtml_config_select')
101
+ ->setIsRenderToJsTemplate(true);
102
+ }
103
+ return $this->_getDatafieldRenderer;
104
+ }
105
+
106
+ public function _toHtml()
107
+ {
108
+ return '<input type="hidden" id="'.$this->getElement()->getHtmlId().'"/>'.parent::_toHtml();
109
+
110
+ }
111
+
112
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Config/Rules/Customdatafields.php ADDED
@@ -0,0 +1,266 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Config_Rules_Customdatafields extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
4
+ {
5
+ protected $_getAttributeRenderer;
6
+ protected $_getConditionsRenderer;
7
+ protected $_getValueRenderer;
8
+
9
+
10
+ /**
11
+ * Construct.
12
+ */
13
+ public function __construct()
14
+ {
15
+ $this->_addAfter = false;
16
+ $this->_addButtonLabel = Mage::helper('adminhtml')->__('Add New Condition');
17
+ parent::__construct();
18
+
19
+ }
20
+
21
+ /**
22
+ * prepare render
23
+ */
24
+ protected function _prepareToRender()
25
+ {
26
+ $this->_getConditionsRenderer = null;
27
+ $this->_getAttributeRenderer = null;
28
+ $this->_getValueRenderer = null;
29
+ $this->addColumn('attribute',
30
+ array(
31
+ 'label' => Mage::helper('adminhtml')->__('Attribute'),
32
+ 'style' => 'width:120px',
33
+ )
34
+ );
35
+ $this->addColumn('conditions',
36
+ array(
37
+ 'label' => Mage::helper('adminhtml')->__('Condition'),
38
+ 'style' => 'width:120px',
39
+ )
40
+ );
41
+ $this->addColumn('cvalue',
42
+ array(
43
+ 'label' => Mage::helper('adminhtml')->__('Value'),
44
+ 'style' => 'width:120px',
45
+ )
46
+ );
47
+ }
48
+
49
+ /**
50
+ * render cell template
51
+ *
52
+ * @param string $columnName
53
+ * @return string
54
+ * @throws Exception
55
+ */
56
+ protected function _renderCellTemplate($columnName)
57
+ {
58
+ $inputName = $this->getElement()->getName() . '[#{_id}][' . $columnName . ']';
59
+ if ($columnName=="attribute") {
60
+ return $this->_getAttributeRenderer()
61
+ ->setName($inputName)
62
+ ->setTitle($columnName)
63
+ ->setExtraParams('style="width:160px"')
64
+ ->setOptions(
65
+ $this->getElement()->getValues()
66
+ )
67
+ ->toHtml();
68
+ }elseif ($columnName == "conditions") {
69
+ return $this->_getConditionsRenderer()
70
+ ->setName($inputName)
71
+ ->setTitle($columnName)
72
+ ->setExtraParams('style="width:160px"')
73
+ ->setOptions(Mage::getModel('ddg_automation/adminhtml_source_rules_condition')->toOptionArray())
74
+ ->toHtml();
75
+ }elseif ($columnName == "cvalue") {
76
+ return $this->_getValueRenderer()
77
+ ->setName($inputName)
78
+ ->setTitle($columnName)
79
+ ->setExtraParams('style="width:160px"')
80
+ ->setOptions(Mage::getModel('ddg_automation/adminhtml_source_rules_value')->toOptionArray())
81
+ ->toHtml();
82
+ }
83
+ return parent::_renderCellTemplate($columnName);
84
+ }
85
+
86
+ /**
87
+ * Assign extra parameters to row
88
+ *
89
+ * @param Varien_Object $row
90
+ */
91
+ protected function _prepareArrayRow(Varien_Object $row)
92
+ {
93
+ $row->setData(
94
+ 'option_extra_attr_' . $this->_getAttributeRenderer()->calcOptionHash($row->getData('attribute')),
95
+ 'selected="selected"'
96
+ );
97
+ }
98
+
99
+ /**
100
+ * get rendered for attribute field
101
+ *
102
+ * @return mixed
103
+ */
104
+ protected function _getAttributeRenderer()
105
+ {
106
+ if (!$this->_getAttributeRenderer) {
107
+ $this->_getAttributeRenderer = $this->getLayout()
108
+ ->createBlock('ddg_automation/adminhtml_config_select')
109
+ ->setIsRenderToJsTemplate(true);
110
+ }
111
+ return $this->_getAttributeRenderer;
112
+ }
113
+
114
+ /**
115
+ * get renderer for conditions field
116
+ *
117
+ * @return mixed
118
+ */
119
+ protected function _getConditionsRenderer()
120
+ {
121
+ if (!$this->_getConditionsRenderer) {
122
+ $this->_getConditionsRenderer = $this->getLayout()
123
+ ->createBlock('ddg_automation/adminhtml_config_select')
124
+ ->setIsRenderToJsTemplate(true);
125
+ }
126
+ return $this->_getConditionsRenderer;
127
+ }
128
+
129
+ /**
130
+ * get renderer for value field
131
+ *
132
+ * @return mixed
133
+ */
134
+ protected function _getValueRenderer()
135
+ {
136
+ if (!$this->_getValueRenderer) {
137
+ $this->_getValueRenderer = $this->getLayout()
138
+ ->createBlock('ddg_automation/adminhtml_config_select')
139
+ ->setIsRenderToJsTemplate(true);
140
+ }
141
+ return $this->_getValueRenderer;
142
+ }
143
+
144
+ public function _toHtml()
145
+ {
146
+ $script =
147
+ "<script type=\"text/javascript\">
148
+ document.observe('dom:loaded', function() {
149
+ $$('tr#row_rule_condition tr td:first-child select').each(function(item) {
150
+ doUpdateWithValues(item);
151
+ });
152
+
153
+ $$('tr#row_rule_condition tr td:first-child select').each(function(item) {
154
+ Event.observe(item,'change', function(){
155
+ doUpdate(item);
156
+ });
157
+ });
158
+
159
+ $$('tr#row_rule_condition button.add').each(function(item) {
160
+ Event.observe(item,'click', function(){
161
+ $$('tr#row_rule_condition tr td:first-child select').each(function(item) {
162
+ Event.observe(item,'change', function(){
163
+ doUpdate(item);
164
+ });
165
+ });
166
+ $$('tr#row_rule_condition tr td select').each(function(item) {
167
+ Event.observe(item,'change', function(){
168
+ if(item.readAttribute('title') == 'conditions'){
169
+ doUpdateForCondition(item);
170
+ }
171
+ });
172
+ });
173
+ });
174
+ });
175
+
176
+ function doUpdate(item){
177
+ var url = '". Mage::helper('adminhtml')->getUrl('adminhtml/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::helper('adminhtml')->getUrl('adminhtml/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::helper('adminhtml')->getUrl('adminhtml/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,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ 'active' => true
29
+ )
30
+ );
31
+ $this->addTab(
32
+ 'status',
33
+ array (
34
+ 'label' => $this->__('Connector Status'),
35
+ 'title' => $this->__('Connector Status'),
36
+ 'url' => $this->getUrl('*/*/statusGrid'),
37
+ 'class' => 'ajax',
38
+ )
39
+ );
40
+ $this->addTab(
41
+ 'analysis',
42
+ array (
43
+ 'label' => $this->__('Data Analysis'),
44
+ 'title' => $this->__('Data Analysis'),
45
+ 'content' => $this->getLayout()->createBlock('ddg_automation/adminhtml_dashboard_tabs_analysis')->toHtml()
46
+ )
47
+ );
48
+ $this->addTab(
49
+ 'logs',
50
+ array (
51
+ 'label' => $this->__('Connector Logs'),
52
+ 'title' => $this->__('Connector Logs'),
53
+ 'url' => $this->getUrl('*/*/logs'),
54
+ 'class' => 'ajax',
55
+ )
56
+ );
57
+ return parent::_beforeToHtml();
58
+ }
59
+ }
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/Logs.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_Dashboard_Tabs_Logs
4
+ extends Mage_Adminhtml_Block_Widget
5
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
6
+ {
7
+ /**
8
+ * Set the template.
9
+ */
10
+ public function _construct()
11
+ {
12
+ parent::_construct();
13
+
14
+ $this->setTemplate('connector/dashboard/logs.phtml');
15
+ }
16
+
17
+ public function canShowTab()
18
+ {
19
+ return true;
20
+ }
21
+ public function isHidden()
22
+ {
23
+ return true;
24
+ }
25
+
26
+ public function getTabLabel()
27
+ {
28
+ return Mage::helper('ddg')->__('Marketing Automation Logs');
29
+ }
30
+
31
+ public function getTabTitle()
32
+ {
33
+ return Mage::helper('ddg')->__('Marketing Automation Logs');
34
+ }
35
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/Dashboard/Tabs/Status.php ADDED
@@ -0,0 +1,1749 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ if(empty($storeIds))
1068
+ continue;
1069
+
1070
+ //numbser of orders marked as imported
1071
+ $numOrders = Mage::getModel('ddg_automation/order')->getCollection()
1072
+ ->addFieldToFilter('email_imported', 1)
1073
+ ->addFieldToFilter('store_id', array('in', $storeIds))->getSize();
1074
+
1075
+ if (! $numOrders) {
1076
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
1077
+ ->setTitle('Order Syncing (ignore if you have reset orders for reimport) :')
1078
+ ->setMessage('')
1079
+ ->setTable(array(
1080
+ 'Website' => $websiteName,
1081
+ 'Status' => 'No Imported Orders Found'
1082
+ ));
1083
+ }
1084
+ }
1085
+
1086
+ return $resultContent;
1087
+
1088
+ }
1089
+
1090
+ /**
1091
+ * Quote sync enabled.
1092
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1093
+ */
1094
+ public function quoteEnabled()
1095
+ {
1096
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1097
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1098
+ ->setTitle('Quote Sync : ')
1099
+ ->setMessage('Enabled.');
1100
+
1101
+ $passed = true;
1102
+ foreach ( Mage::app()->getWebsites() as $website ) {
1103
+ $websiteName = $website->getName();
1104
+ $quote = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_QUOTE_ENABLED))? true :
1105
+ 'Disabled!';
1106
+
1107
+ if ($quote !== true){
1108
+
1109
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_SYNC_QUOTE_ENABLED', 'website' => $website->getId()));
1110
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
1111
+ ->setMessage('')
1112
+ ->setTable(array(
1113
+ 'Website' => $websiteName,
1114
+ 'Status' => $quote . ' <a href="' . $url . '">enable</a>'
1115
+ ));
1116
+ $passed = false;
1117
+ }
1118
+ }
1119
+ //validation failed
1120
+ if (! $passed) {
1121
+ $resultContent->setHowto(self::FAST_FIX_MESSAGE);
1122
+ }
1123
+
1124
+ return $resultContent;
1125
+ }
1126
+
1127
+ /**
1128
+ * check if any custom quote attribute selected
1129
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1130
+ */
1131
+ public function customQuoteAttributes()
1132
+ {
1133
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1134
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1135
+ ->setTitle('Custom Quote Attributes : ')
1136
+ ->setMessage('Selected.');
1137
+
1138
+ foreach ( Mage::app()->getWebsites() as $website ) {
1139
+ $websiteName = $website->getName();
1140
+ $customQuoteAttribute = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOM_QUOTE_ATTRIBUTES))? true : false;
1141
+
1142
+ if ($customQuoteAttribute !== true){
1143
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
1144
+ ->setTitle('Custom quote attribute not selected (ignore if you do not want to import custom quote attributes) :')
1145
+ ->setMessage('')
1146
+ ->setTable(array(
1147
+ 'Website' => $websiteName,
1148
+ 'Status' => 'No Custom Quote Attribute Selected'
1149
+ ));
1150
+ }
1151
+ }
1152
+
1153
+ return $resultContent;
1154
+ }
1155
+
1156
+ /**
1157
+ * Check if any quote are imported.
1158
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1159
+ */
1160
+ public function quoteSyncing()
1161
+ {
1162
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1163
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1164
+ ->setTitle('Quote Syncing : ')
1165
+ ->setMessage('Looks Great.');
1166
+
1167
+ foreach ( Mage::app()->getWebsites() as $website ) {
1168
+ $websiteName = $website->getName();
1169
+ $storeIds = $website->getStoreIds();
1170
+
1171
+ if(empty($storeIds))
1172
+ continue;
1173
+
1174
+ //number of quote marked as imported
1175
+ $numQuotes = Mage::getModel('ddg_automation/quote')->getCollection()
1176
+ ->addFieldToFilter('imported', 1)
1177
+ ->addFieldToFilter('store_id', array('in', $storeIds))->getSize();
1178
+
1179
+ if (! $numQuotes) {
1180
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
1181
+ ->setTitle('Quote Syncing (ignore if you have reset quote for re-import) :')
1182
+ ->setMessage('')
1183
+ ->setTable(array(
1184
+ 'Website' => $websiteName,
1185
+ 'Status' => 'No Imported Quotes Found'
1186
+ ));
1187
+ }
1188
+ }
1189
+
1190
+ return $resultContent;
1191
+
1192
+ }
1193
+
1194
+ /**
1195
+ * review sync enabled.
1196
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1197
+ * Display the transactional data for orders to be removed.
1198
+ */
1199
+ public function reviewEnabled()
1200
+ {
1201
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1202
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1203
+ ->setTitle('Review Sync : ')
1204
+ ->setMessage('Enabled.');
1205
+
1206
+ foreach ( Mage::app()->getWebsites() as $website ) {
1207
+ $websiteName = $website->getName();
1208
+ $review = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_REVIEW_ENABLED))? true :
1209
+ 'Disabled';
1210
+
1211
+ if ($review !== true){
1212
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_SYNC_REVIEW_ENABLED', 'website' => $website->getId()));
1213
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
1214
+ ->setMessage('Don\'t forget to enable if you want to sync reviews.' )
1215
+ ->setTable(array(
1216
+ 'Website' => $websiteName,
1217
+ 'Status' => $review,
1218
+ 'Fast Fix' => 'Click <a href="' . $url . '">here </a>to enable.'
1219
+ ));
1220
+ }
1221
+ }
1222
+ return $resultContent;
1223
+ }
1224
+
1225
+ /**
1226
+ * Check if any reviews are imported.
1227
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1228
+ */
1229
+ public function reviewSyncing()
1230
+ {
1231
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1232
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1233
+ ->setTitle('Review Syncing : ')
1234
+ ->setMessage('Looks Great.');
1235
+
1236
+ foreach ( Mage::app()->getWebsites() as $website ) {
1237
+ $websiteName = $website->getName();
1238
+ $storeIds = $website->getStoreIds();
1239
+
1240
+ if(empty($storeIds))
1241
+ continue;
1242
+
1243
+ //number of reviews marked as imported
1244
+ $numReview = Mage::getModel('ddg_automation/review')->getCollection()
1245
+ ->addFieldToFilter('review_imported', 1)
1246
+ ->addFieldToFilter('store_id', array('in', $storeIds))
1247
+ ->getSize();
1248
+
1249
+ //total reviews
1250
+ $totalReview = Mage::getModel('ddg_automation/review')->getCollection()
1251
+ ->addFieldToFilter('store_id', array('in', $storeIds))
1252
+ ->getSize();
1253
+
1254
+ $tableData = array(
1255
+ 'Website' => $websiteName,
1256
+ 'Total Reviews' => $totalReview,
1257
+ 'Imported' => $numReview
1258
+ );
1259
+
1260
+ $tableData['Status'] = 'Importing';
1261
+
1262
+ if (! $numReview) {
1263
+ $tableData['Status'] = 'No Imported Review Found.';
1264
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
1265
+ ->setTitle('Review Sync (ignore if you have reset wishlist) : ')
1266
+ ->setMessage('');
1267
+ }
1268
+ $resultContent->setTable($tableData);
1269
+ }
1270
+ return $resultContent;
1271
+ }
1272
+
1273
+ /**
1274
+ * review campaign enabled.
1275
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1276
+ */
1277
+ public function reviewCampaignStatus()
1278
+ {
1279
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1280
+
1281
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1282
+ ->setTitle('Review Status : ')
1283
+ ->setMessage('Looks Great.');
1284
+
1285
+ foreach ( Mage::app()->getWebsites() as $website ) {
1286
+ $websiteName = $website->getName();
1287
+ $enabled = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_REVIEWS_ENABLED))? true :
1288
+ 'Disabled ';
1289
+ $orderStatus = ($website->getConfig(Dotdigitalgroup_Email_Helper_Review::XML_PATH_REVIEW_STATUS))? true :
1290
+ 'Disabled ';
1291
+ $delayPeriod = ($website->getConfig(Dotdigitalgroup_Email_Helper_Review::XML_PATH_REVIEW_DELAY))? true :
1292
+ 'Disabled ';
1293
+ $newProduct = ($website->getConfig(Dotdigitalgroup_Email_Helper_Review::XML_PATH_REVIEW_NEW_PRODUCT))? true :
1294
+ 'Disabled ';
1295
+ $campaign = ($website->getConfig(Dotdigitalgroup_Email_Helper_Review::XML_PATH_REVIEW_CAMPAIGN))? true :
1296
+ 'Disabled ';
1297
+
1298
+ if ($enabled !== true || $orderStatus !== true || $delayPeriod !== true || $newProduct !== true || $campaign !== true){
1299
+ $enabledUrl = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_REVIEWS_ENABLED', 'website' => $website->getId()));
1300
+
1301
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
1302
+ ->setMessage('Don\'t forget to map')
1303
+ ->setTable(array(
1304
+ 'Website' => $websiteName,
1305
+ 'Enabled' => ($enabled !== true)? $enabled . '<a href="' . $enabledUrl . '">Click to enable</a>' : 'Enabled',
1306
+ 'Order Status' => ($orderStatus !== true)? 'Not Set' : 'Enabled',
1307
+ 'Delay Period' => ($delayPeriod !== true)? 'Not Set' : 'Enabled',
1308
+ 'New Product Only' => ($newProduct !== true)? 'Not Set' : 'Enabled',
1309
+ 'Campaign To Select' => ($campaign !== true)? 'Not Set' : 'Enabled',
1310
+ ));
1311
+ }
1312
+ }
1313
+ return $resultContent;
1314
+ }
1315
+
1316
+ /**
1317
+ * Get the last date for abandaned carts.
1318
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1319
+ */
1320
+ public function lastAbandonedCartSentDay()
1321
+ {
1322
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1323
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1324
+ ->setTitle('Last Abandoned Summary : ');
1325
+
1326
+ foreach ( Mage::app()->getWebsites() as $website ) {
1327
+
1328
+ $websiteName = $website->getName();
1329
+ $client = Mage::helper('ddg')->getWebsiteApiClient($website);
1330
+
1331
+ //customer carts
1332
+ $customerCampaign1 = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CAMPAIGN_1);
1333
+ $customerCampaign2 = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CAMPAIGN_2);
1334
+ $customerCampaign3 = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_ABANDONED_CAMPAIGN_3);
1335
+
1336
+ //guests carts
1337
+ $guestCampaign1 = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_GUEST_ABANDONED_CAMPAIGN_1);
1338
+ $guestCampaign2 = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_GUEST_ABANDONED_CAMPAIGN_2);
1339
+ $guestCampaign3 = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_GUEST_ABANDONED_CAMPAIGN_3);
1340
+
1341
+
1342
+ //date customer carts
1343
+
1344
+ $cusDateSent1 = ($customerCampaign1)? $client->getCampaignSummary($customerCampaign1) : '';
1345
+ $cusDateSent2 = ($customerCampaign2)? $client->getCampaignSummary($customerCampaign2) : '';
1346
+ $cusDateSent3 = ($customerCampaign3)? $client->getCampaignSummary($customerCampaign3) : '';
1347
+
1348
+ //date guest carts
1349
+ $resGuest1 = ($guestCampaign1)? $client->getCampaignSummary($guestCampaign1) : '';
1350
+ $resGuest2 = ($guestCampaign2)? $client->getCampaignSummary($guestCampaign2) : '';
1351
+ $resGuest3 = ($guestCampaign3)? $client->getCampaignSummary($guestCampaign3) : '';
1352
+
1353
+ /**
1354
+ * Customers.
1355
+ */
1356
+ $customerCampaign1 = (isset($cusDateSent1->dateSent)? $cusDateSent1->dateSent : 'Not Sent/Selected');
1357
+ $customerCampaign2 = (isset($cusDateSent2->dateSent)? $cusDateSent2->dateSent : 'Not Sent/Selected');
1358
+ $customerCampaign3 = (isset($cusDateSent3->dateSent)? $cusDateSent3->dateSent : 'Not Sent/Selected');
1359
+
1360
+ /**
1361
+ * Guests.
1362
+ */
1363
+ $guestCampaign1 = (isset($resGuest1->dateSent)? $resGuest1->dateSent : 'Not Sent/Selected');
1364
+ $guestCampaign2 = (isset($resGuest2->dateSent)? $resGuest2->dateSent : 'Not Sent/Selected');
1365
+ $guestCampaign3 = (isset($resGuest3->dateSent)? $resGuest3->dateSent : 'Not Sent/Selected');
1366
+
1367
+
1368
+ $resultContent->setTable(array(
1369
+ 'Website' => $websiteName,
1370
+ 'Customer Campaign 1' => $customerCampaign1,
1371
+ 'Customer Campaign 2' => $customerCampaign2,
1372
+ 'Customer Campaign 3' => $customerCampaign3,
1373
+ 'Guest Campaign 1' => $guestCampaign1,
1374
+ 'Guest Campaign 2' => $guestCampaign2,
1375
+ 'Guest Campaign 3' => $guestCampaign3
1376
+ ));
1377
+ }
1378
+
1379
+ return $resultContent;
1380
+ }
1381
+
1382
+ /**
1383
+ * Conflict checker.
1384
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1385
+ */
1386
+ public function conflictCheck()
1387
+ {
1388
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1389
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1390
+ ->setTitle('Conflict Status : ')
1391
+ ->setMessage('Looks Great.');
1392
+
1393
+ //check the module override and conflict
1394
+ $rewrites = Mage::helper('ddg/dashboard')->getRewrites();
1395
+
1396
+
1397
+ if ($rewrites === false) {
1398
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1399
+ ->setMessage('No Conflict Rewrites Found.');
1400
+ } else {
1401
+
1402
+ $types = array('blocks', 'models', 'helpers');
1403
+ foreach ($types as $t) {
1404
+
1405
+ if (!empty($rewrites[$t])) {
1406
+
1407
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
1408
+ ->setMessage('Conflicting Rewrite Found : ');
1409
+
1410
+ foreach ($rewrites[$t] as $node => $rewriteInfo) {
1411
+
1412
+ $resultContent->setTable(array(
1413
+ 'Type' => $t,
1414
+ 'Class' => implode(', ', array_values($rewriteInfo['classes'])),
1415
+ 'Rewrites' => '',
1416
+ 'Loaded Class' => ''
1417
+ ));
1418
+ }
1419
+ }
1420
+ }
1421
+
1422
+ $conflictCounter = 0;
1423
+ $tableData = array();
1424
+ foreach ($rewrites as $type => $data) {
1425
+ if (count($data) > 0 && is_array($data)) {
1426
+
1427
+ foreach ($data as $class => $rewriteClass) {
1428
+
1429
+ if (count($rewriteClass) > 1) {
1430
+ if ($this->_isInheritanceConflict($rewriteClass)) {
1431
+
1432
+ $resultContent->setTable(array(
1433
+ 'Type' => $type,
1434
+ 'Class' => $class,
1435
+ 'Rewrites' => implode(', ', $rewriteClass['classes']),
1436
+ 'Loaded Class' => $this->_getLoadedClass($type, $class),
1437
+ ));
1438
+
1439
+ $conflictCounter++;
1440
+ }
1441
+ }
1442
+ }
1443
+ }
1444
+ }
1445
+ if (! empty($tableData))
1446
+ $resultContent->setTable($tableData);
1447
+
1448
+ }
1449
+
1450
+ return $resultContent;
1451
+ }
1452
+
1453
+ /**
1454
+ * Returns loaded class by type like models or blocks
1455
+ *
1456
+ * @param string $type
1457
+ * @param string $class
1458
+ * @return string
1459
+ */
1460
+ protected function _getLoadedClass($type, $class)
1461
+ {
1462
+ switch ($type) {
1463
+ case 'blocks':
1464
+ return Mage::getConfig()->getBlockClassName($class);
1465
+
1466
+ case 'helpers':
1467
+ return Mage::getConfig()->getHelperClassName($class);
1468
+
1469
+ default:
1470
+ case 'models':
1471
+ return Mage::getConfig()->getModelClassName($class);
1472
+ break;
1473
+ }
1474
+ }
1475
+
1476
+ /**
1477
+ * Check if rewritten class has inherited the parent class.
1478
+ * If yes we have no conflict. The top class can extend every core class.
1479
+ * So we cannot check this.
1480
+ *
1481
+ * @var array $classes
1482
+ * @return bool
1483
+ */
1484
+ protected function _isInheritanceConflict($classes)
1485
+ {
1486
+ $classes = array_reverse($classes);
1487
+ $numClases = count($classes);
1488
+
1489
+ for ($i = 0; $i < $numClases - 1; $i++) {
1490
+ try {
1491
+ if (class_exists($classes[$i])
1492
+ && class_exists($classes[$i + 1])
1493
+ ) {
1494
+ if (! is_a($classes[$i], $classes[$i + 1], true)) {
1495
+ return true;
1496
+ }
1497
+ }
1498
+ } catch (\Exception $e) {
1499
+ return true;
1500
+ }
1501
+ }
1502
+
1503
+ return false;
1504
+ }
1505
+
1506
+ /**
1507
+ * System information about the version used and the memory limits.
1508
+ *
1509
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1510
+ */
1511
+ public function systemInformation()
1512
+ {
1513
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1514
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED);
1515
+
1516
+ //compatibility with the old versions
1517
+ if (version_compare(Mage::getVersion(), '1.6.2.0', '>')) {
1518
+ $version = 'Magento ' . Mage::getEdition() . ' ' . Mage::getVersion() . 'V';
1519
+ } else {
1520
+ $version = 'Magento version : ' . Mage::getVersion() . 'V';
1521
+ }
1522
+
1523
+ $fh = @fopen('/proc/meminfo', 'r');
1524
+ $mem = 0;
1525
+ if ($fh) {
1526
+ while ($line = fgets($fh)) {
1527
+ $pieces = array();
1528
+ if (preg_match('^MemTotal:\s+(\d+)\skB$^', $line, $pieces)) {
1529
+ $mem = $pieces[1];
1530
+ break;
1531
+ }
1532
+ }
1533
+ fclose($fh);
1534
+ }
1535
+ if ($mem > 0) {
1536
+ $mem = $mem / 1024 . 'M';
1537
+ } else {
1538
+ $mem = 'Not available';
1539
+ }
1540
+
1541
+ //check for php version
1542
+ $resultContent->setHowTo('PHP version : V' . PHP_VERSION)
1543
+ ->setHowto('PHP Memory : ' . $mem)
1544
+ ->setHowto('PHP Max Execution Time : ' . ini_get('max_execution_time') . ' sec')
1545
+ ->setHowto($version)
1546
+ ->setHowto('Connector version : V' . Mage::helper('ddg')->getConnectorVersion());
1547
+
1548
+ return $resultContent;
1549
+ }
1550
+
1551
+
1552
+ /**
1553
+ * Check if the mapped program is active.
1554
+
1555
+ */
1556
+ protected function _getWebisteProgram($program, $website) {
1557
+ $client = Mage::helper('ddg')->getWebsiteApiClient($website);
1558
+
1559
+ if (! $client || !$program){
1560
+ return false;
1561
+ }
1562
+
1563
+ $data = $client->getProgramById($program);
1564
+
1565
+ if (isset($data->message))
1566
+ return false;
1567
+
1568
+
1569
+ return $data;
1570
+ }
1571
+
1572
+ /**
1573
+ * Get the contacts address book.
1574
+ * @param $addressBook
1575
+ * @param $webiste
1576
+ *
1577
+ * @return bool|null
1578
+ */
1579
+ protected function _getAddressBookContacts($addressBook, $webiste) {
1580
+ $client = Mage::helper('ddg')->getWebsiteApiClient($webiste);
1581
+
1582
+ if (! $client && $addressBook)
1583
+ return false;
1584
+
1585
+ $response = $client->getAddressBookById($addressBook);
1586
+
1587
+ if (isset($response->message))
1588
+ return false;
1589
+ return $response;
1590
+ }
1591
+
1592
+ /**
1593
+ * Get the method name
1594
+ * @param $name
1595
+ *
1596
+ * @return string
1597
+ */
1598
+ public function getFormatedMethodName($name)
1599
+ {
1600
+ //version that not support the lcfirst method
1601
+ if(function_exists('lcfirst') === false) {
1602
+
1603
+ $method = strtolower(substr(uc_words($name, '') ,0,1)).substr(uc_words($name, ''), 1);
1604
+
1605
+ } else {
1606
+ $method = lcfirst(uc_words($name, ''));
1607
+ }
1608
+
1609
+ return $method;
1610
+ }
1611
+
1612
+ /**
1613
+ * easy email capture enabled
1614
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1615
+ */
1616
+ public function easyEmailCaptureEnabled()
1617
+ {
1618
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1619
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1620
+ ->setTitle('Easy Email Capture : ')
1621
+ ->setMessage('Enabled.');
1622
+
1623
+ foreach ( Mage::app()->getWebsites() as $website ) {
1624
+ $websiteName = $website->getName();
1625
+ $enabled = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_EMAIL_CAPTURE))? true :
1626
+ 'Disabled';
1627
+
1628
+ if ($enabled !== true){
1629
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_EMAIL_CAPTURE', 'website' => $website->getId()));
1630
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
1631
+ ->setMessage('Don\'t forget to enable if you want to enable easy email capture.' )
1632
+ ->setTable(array(
1633
+ 'Website' => $websiteName,
1634
+ 'Status' => $enabled,
1635
+ 'Fast Fix' => 'Click <a href="' . $url . '">here </a>to enable.'
1636
+ ));
1637
+ }
1638
+ }
1639
+ return $resultContent;
1640
+ }
1641
+
1642
+ /**
1643
+ * disabled newsletter success enabled
1644
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1645
+ */
1646
+ public function disableNewsletterSuccessEnabled()
1647
+ {
1648
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1649
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1650
+ ->setTitle('Disable Newsletter Success : ')
1651
+ ->setMessage('Enabled.');
1652
+
1653
+ foreach ( Mage::app()->getWebsites() as $website ) {
1654
+ $websiteName = $website->getName();
1655
+ $enabled = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DISABLE_NEWSLETTER_SUCCESS))? true :
1656
+ 'Disabled';
1657
+
1658
+ if ($enabled !== true){
1659
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_DISABLE_NEWSLETTER_SUCCESS', 'website' => $website->getId()));
1660
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
1661
+ ->setMessage('Don\'t forget to enable if you want to disable Magento newsletter success email.' )
1662
+ ->setTable(array(
1663
+ 'Website' => $websiteName,
1664
+ 'Status' => $enabled,
1665
+ 'Fast Fix' => 'Click <a href="' . $url . '">here </a>to enable.'
1666
+ ));
1667
+ }
1668
+ }
1669
+ return $resultContent;
1670
+ }
1671
+
1672
+ /**
1673
+ * wishlist sync enabled.
1674
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1675
+ */
1676
+ public function wishlistEnabled()
1677
+ {
1678
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1679
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1680
+ ->setTitle('Wishlist Sync : ')
1681
+ ->setMessage('Enabled.');
1682
+
1683
+ foreach ( Mage::app()->getWebsites() as $website ) {
1684
+ $websiteName = $website->getName();
1685
+ $wishlist = ($website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_WISHLIST_ENABLED))? true :
1686
+ 'Disabled';
1687
+
1688
+ if ($wishlist !== true){
1689
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/enablewebsiteconfiguration', array('path' => 'XML_PATH_CONNECTOR_SYNC_WISHLIST_ENABLED', 'website' => $website->getId()));
1690
+ $resultContent->setStyle( self::CONNECTOR_DASHBOARD_FAILED)
1691
+ ->setMessage('Don\'t forget to enable if you want to sync wishlist.' )
1692
+ ->setTable(array(
1693
+ 'Website' => $websiteName,
1694
+ 'Status' => $wishlist,
1695
+ 'Fast Fix' => 'Click <a href="' . $url . '">here </a>to enable.'
1696
+ ));
1697
+ }
1698
+ }
1699
+ return $resultContent;
1700
+ }
1701
+
1702
+ /**
1703
+ * Check if any wishlist are imported.
1704
+ * @return Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
1705
+ */
1706
+ public function wishlistSyncing()
1707
+ {
1708
+ $resultContent = Mage::getModel('ddg_automation/adminhtml_dashboard_content');
1709
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_PASSED)
1710
+ ->setTitle('Wishlist Syncing : ')
1711
+ ->setMessage('Looks Great.');
1712
+
1713
+ foreach ( Mage::app()->getWebsites() as $website ) {
1714
+ $websiteName = $website->getName();
1715
+ $storeIds = $website->getStoreIds();
1716
+
1717
+ if(empty($storeIds))
1718
+ continue;
1719
+
1720
+ //number of wishlist marked as imported
1721
+ $numWishlist = Mage::getModel('ddg_automation/wishlist')->getCollection()
1722
+ ->addFieldToFilter('wishlist_imported', 1)
1723
+ ->addFieldToFilter('store_id', array('in', $storeIds))
1724
+ ->getSize();
1725
+
1726
+ //total wishlist
1727
+ $totalWishlist = Mage::getModel('ddg_automation/wishlist')->getCollection()
1728
+ ->addFieldToFilter('store_id', array('in', $storeIds))
1729
+ ->getSize();
1730
+
1731
+ $tableData = array(
1732
+ 'Website' => $websiteName,
1733
+ 'Total Wishlist' => $totalWishlist,
1734
+ 'Imported' => $numWishlist
1735
+ );
1736
+
1737
+ $tableData['Status'] = 'Importing';
1738
+
1739
+ if (! $numWishlist) {
1740
+ $tableData['Status'] = 'No Imported Wishlist Found.';
1741
+ $resultContent->setStyle(self::CONNECTOR_DASHBOARD_FAILED)
1742
+ ->setTitle('Wishlist Sync (ignore if you have reset wishlist) : ')
1743
+ ->setMessage('');
1744
+ }
1745
+ $resultContent->setTable($tableData);
1746
+ }
1747
+ return $resultContent;
1748
+ }
1749
+ }
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('desc');
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,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $this->_controller = 'adminhtml_rules';
9
+ $this->_blockGroup = 'ddg_automation';
10
+ $this->_headerText = Mage::helper('ddg')->__('Email Exclusion Rule(s)');
11
+ $this->_addButtonLabel = Mage::helper('ddg')->__('Add New Rule');
12
+
13
+ }
14
+ }
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/{local/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Password.php → community/Dotdigitalgroup/Email/Block/Adminhtml/System/Ajaxvalidate.php} RENAMED
@@ -1,6 +1,6 @@
1
  <?php
2
 
3
- class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Password extends Mage_Adminhtml_Block_System_Config_Form_Field
4
  {
5
  public function _getElementHtml(Varien_Data_Form_Element_Abstract$element){
6
 
1
  <?php
2
 
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Ajaxvalidate extends Mage_Adminhtml_Block_System_Config_Form_Field
4
  {
5
  public function _getElementHtml(Varien_Data_Form_Element_Abstract$element){
6
 
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Automation/Connect.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Automation_Connect extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
6
+ {
7
+ $this->setElement($element);
8
+ return $this->_getAddRowButtonHtml();
9
+ }
10
+
11
+ protected function _getAddRowButtonHtml()
12
+ {
13
+ $url = Mage::helper('ddg')->getAuthoriseUrl();
14
+ $ssl = $this->_checkForSecureUrl();
15
+ $disabled = false;
16
+ //disable for ssl missing
17
+ if (!$ssl) {
18
+ $disabled = true;
19
+ }
20
+
21
+ $adminUser = Mage::getSingleton('admin/session')->getUser();
22
+ $refreshToken = $adminUser->getRefreshToken();
23
+ $title = ($refreshToken)? $this->__('Disconnect') : $this->__('Connect');
24
+ $url = ($refreshToken)? $this->getUrl('*/email_studio/disconnect') : $url;
25
+
26
+ return $this->getLayout()->createBlock('adminhtml/widget_button')
27
+ ->setType('button')
28
+ ->setLabel($this->__($title))
29
+ ->setDisabled($disabled)
30
+ ->setOnClick("window.location.href='" . $url . "'")
31
+ ->toHtml();
32
+ }
33
+
34
+ private function _checkForSecureUrl() {
35
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB, true);
36
+ if (!preg_match('/https/',$baseUrl)) {
37
+ return false;
38
+ }
39
+ return $this;
40
+ }
41
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Addressbook.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Addressbook extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+
6
+ /**
7
+ * Ajax Create the addressbooks.
8
+ * @param Varien_Data_Form_Element_Abstract $element
9
+ *
10
+ * @return string
11
+ */
12
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
13
+ {
14
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/createnewaddressbook');
15
+ $website = Mage::app()->getRequest()->getParam('website', 0);
16
+
17
+ $element->setData('after_element_html',
18
+ "<script>
19
+ function createAddressbook(form, element) {
20
+ var name = $('connector_sync_settings_dynamic_addressbook_addressbook_name').value;
21
+ var visibility = $('connector_sync_settings_dynamic_addressbook_visibility').value;
22
+ var reloadurl = '{$url}';
23
+ if(name && visibility){
24
+ new Ajax.Request(reloadurl, {
25
+ method: 'post',
26
+ parameters: {'name' : name, 'visibility' : visibility, 'website': '$website'},
27
+ onComplete: function(transport) {
28
+ window.location.reload();
29
+ }
30
+ });
31
+ }
32
+ return false;
33
+ }
34
+ </script>"
35
+ );
36
+
37
+ return parent::_getElementHtml($element);
38
+ }
39
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Colorpicker.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Colorpicker extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ /**
6
+ * Generate HTML code for color picker
7
+ *
8
+ * @param Varien_Data_Form_Element_Abstract $element
9
+ * @return string
10
+ */
11
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
12
+ {
13
+ // Include Procolor library JS file
14
+ $html = '<script type="text/javascript" src="' . Mage::getBaseUrl('js') . 'connector/procolor-1.0/procolor.compressed.js' .'"></script>';
15
+
16
+ // Use Varien text element as a basis
17
+ $input = new Varien_Data_Form_Element_Text();
18
+
19
+ // Set data from config element on Varien text element
20
+ $input->setForm($element->getForm())
21
+ ->setElement($element)
22
+ ->setValue($element->getValue())
23
+ ->setHtmlId($element->getHtmlId())
24
+ ->setName($element->getName())
25
+ ->setStyle('width: 60px') // Update style in order to shrink width
26
+ ->addClass('validate-hex'); // Add some Prototype validation to make sure color code is correct
27
+
28
+ // Inject updated Varien text element HTML in our current HTML
29
+ $html .= $input->getHtml();
30
+
31
+ // Inject Procolor JS code to display color picker
32
+ $html .= $this->_getProcolorJs($element->getHtmlId());
33
+
34
+ // Inject Prototype validation
35
+ $html .= $this->_addHexValidator();
36
+
37
+ return $html;
38
+ }
39
+
40
+ /**
41
+ * Procolor JS code to display color picker
42
+ *
43
+ * @see http://procolor.sourceforge.net/examples.php
44
+ * @param string $htmlId
45
+ * @return string
46
+ */
47
+ protected function _getProcolorJs($htmlId)
48
+ {
49
+ return '<script type="text/javascript">ProColor.prototype.attachButton(\'' . $htmlId . '\', { imgPath:\'' . Mage::getBaseUrl('js') . 'connector/procolor-1.0/' . 'img/procolor_win_\', showInField: true });</script>';
50
+ }
51
+
52
+ /**
53
+ * Prototype validation
54
+ *
55
+ * @return string
56
+ */
57
+ protected function _addHexValidator()
58
+ {
59
+ return
60
+ '<script type="text/javascript">
61
+ Validation.add(\'validate-hex\', \'' . Mage::helper('ddg')->__('Please enter a valid hex color code') . '\', function(v) {
62
+ return /^#(?:[0-9a-fA-F]{3}){1,2}$/.test(v);
63
+ });
64
+ </script>';
65
+ }
66
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Datafield.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Datafield extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+
6
+ /**
7
+ * Ajax Create the datafields.
8
+ * @param Varien_Data_Form_Element_Abstract $element
9
+ *
10
+ * @return string
11
+ */
12
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
13
+ {
14
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/createnewdatafield');
15
+ $website = Mage::app()->getRequest()->getParam('website', 0);
16
+
17
+ $element->setData('after_element_html',
18
+ "<script>
19
+ function createDatafield(form, element) {
20
+ var datafield_name = $('connector_data_mapping_dynamic_datafield_datafield_name').value;
21
+ var datafield_type = $('connector_data_mapping_dynamic_datafield_datafield_type').value;
22
+ var datafield_default = $('connector_data_mapping_dynamic_datafield_datafield_default').value;
23
+ var datafield_access = $('connector_data_mapping_dynamic_datafield_datafield_access').value;
24
+
25
+ var reloadurl = '{$url}';
26
+
27
+ if(datafield_name && datafield_type && datafield_access){
28
+ new Ajax.Request(reloadurl, {
29
+ method: 'post',
30
+ parameters: {'name' : datafield_name, 'type' : datafield_type, 'default' : datafield_default, 'access' : datafield_access, 'website': '$website'},
31
+ onComplete: function(transport) {
32
+ window.location.reload();
33
+ }
34
+ });
35
+ }
36
+ return false;}</script>"
37
+ );
38
+
39
+ return parent::_getElementHtml($element);
40
+ }
41
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Enterprisevalidator.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Enterprisevalidator extends Mage_Adminhtml_Block_System_Config_Form_Field
5
+ {
6
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
7
+ {
8
+ // Get the default HTML for this option
9
+ $html = parent::_getElementHtml($element);
10
+
11
+ // Set up additional JavaScript for our validation using jQuery.
12
+
13
+ $jquery = '<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>';
14
+
15
+ if (! Mage::helper('ddg')->isEnterprise()) {
16
+ $html .=$jquery;
17
+ $javaScript = "<script type=\"text/javascript\">
18
+ jQuery.noConflict();
19
+ jQuery(document).ready(function() {
20
+ jQuery('#connector_data_mapping_enterprise_data-head').parent().hide();
21
+
22
+ });
23
+ </script>";
24
+ $html .= $javaScript;
25
+ }
26
+
27
+
28
+ return $html;
29
+ }
30
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Resetcontacts.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Resetcontacts extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ public function _getElementHtml(Varien_Data_Form_Element_Abstract$element){
6
+
7
+ $element->setData('onchange', "resetContacts();");
8
+ //url to reset the contacs
9
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/resetcontactsajax');
10
+
11
+ $element->setData('after_element_html', "
12
+ <script>
13
+ function resetContacts(){
14
+ new Ajax.Request('{$url}', {
15
+ method: 'get',
16
+ onComplete: function(transport) {
17
+ }
18
+ });
19
+ return false;
20
+ }
21
+ </script>
22
+ ");
23
+
24
+ return parent::_getElementHtml($element);
25
+
26
+
27
+ }
28
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Resetguests.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Resetguests extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ public function _getElementHtml(Varien_Data_Form_Element_Abstract$element){
6
+
7
+ $element->setData('onchange', "resetGuests();");
8
+ //url to reset the guests
9
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/ajaxresetguests');
10
+
11
+ $element->setData('after_element_html', "
12
+ <script>
13
+ function resetGuests(){
14
+ new Ajax.Request('{$url}', {
15
+ method: 'get',
16
+ onComplete: function(transport) {
17
+ }
18
+ });
19
+ return false;
20
+ }
21
+ </script>
22
+ ");
23
+
24
+ return parent::_getElementHtml($element);
25
+
26
+
27
+ }
28
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/Resetsubscribers.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Adminhtml_System_Config_Resetsubscribers extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ public function _getElementHtml(Varien_Data_Form_Element_Abstract$element){
6
+
7
+ $element->setData('onchange', "resetSubscribers();");
8
+ //url to reset the subscribers
9
+ $url = Mage::helper('adminhtml')->getUrl('*/connector/ajaxresetsubscribers');
10
+
11
+ $element->setData('after_element_html', "
12
+ <script>
13
+ function resetSubscribers(){
14
+ new Ajax.Request('{$url}', {
15
+ method: 'get',
16
+ onComplete: function(transport) {
17
+ }
18
+ });
19
+ return false;
20
+ }
21
+ </script>
22
+ ");
23
+
24
+ return parent::_getElementHtml($element);
25
+
26
+
27
+ }
28
+ }
app/code/community/Dotdigitalgroup/Email/Block/Adminhtml/System/Config/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,44 @@
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
+ //coupon code id not found
25
+ if (! $rule->getId()) {
26
+ Mage::helper('ddg')->log('Rule with couponId model not found : ' . $couponCodeId);
27
+ return false;
28
+ }
29
  $generator = Mage::getModel('salesrule/coupon_massgenerator');
 
30
  $generator->setFormat( Mage_SalesRule_Helper_Coupon::COUPON_FORMAT_ALPHANUMERIC );
31
  $generator->setRuleId($couponCodeId);
32
  $generator->setUsesPerCoupon(1);
33
+ $generator->setDash(3);
34
+ $generator->setLength(9);
35
+ $generator->setPrefix('');
36
+ $generator->setSuffix('');
 
37
  //set the generation settings
38
  $rule->setCouponCodeGenerator($generator);
39
+ $rule->setCouponType(Mage_SalesRule_Model_Rule::COUPON_TYPE_AUTO);
 
40
  //generate the coupon
41
  $coupon = $rule->acquireCoupon();
42
  $couponCode = $coupon->getCode();
 
43
  //save the type of coupon
44
  $couponModel = Mage::getModel('salesrule/coupon')->loadByCode($couponCode);
45
  $couponModel->setType(Mage_SalesRule_Model_Rule::COUPON_TYPE_NO_COUPON);
app/code/community/Dotdigitalgroup/Email/Block/Customer/Account/Books.php ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Customer_Account_Books extends Mage_Customer_Block_Account_Dashboard
4
+ {
5
+ private $_client;
6
+ private $contact_id;
7
+
8
+ /**
9
+ * subscription pref save url
10
+ *
11
+ * @return string
12
+ */
13
+ public function getSaveUrl()
14
+ {
15
+ return $this->getUrl('connector/customer_newsletter/save');
16
+ }
17
+
18
+ /**
19
+ * get config values
20
+ *
21
+ * @param $path
22
+ * @param $website
23
+ * @return mixed
24
+ */
25
+ private function _getWebsiteConfigFromHelper($path, $website)
26
+ {
27
+ return Mage::helper('ddg')->getWebsiteConfig($path, $website);
28
+ }
29
+
30
+ /**
31
+ * get api client
32
+ *
33
+ * @return Dotdigitalgroup_Email_Model_Apiconnector_Client
34
+ */
35
+ private function _getApiClient()
36
+ {
37
+ if(empty($this->_client)) {
38
+ $website = $this->getCustomer()->getStore()->getWebsite();
39
+ $client = Mage::getModel('ddg_automation/apiconnector_client');
40
+ $client->setApiUsername(Mage::helper('ddg')->getApiUsername($website))
41
+ ->setApiPassword(Mage::helper('ddg')->getApiPassword($website));
42
+ $this->_client = $client;
43
+ }
44
+ return $this->_client;
45
+ }
46
+
47
+ /**
48
+ * can show additional books?
49
+ *
50
+ * @return mixed
51
+ */
52
+ public function getCanShowAdditionalBooks()
53
+ {
54
+ return $this->_getWebsiteConfigFromHelper(
55
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_ADDRESSBOOK_PREF_CAN_CHANGE_BOOKS,
56
+ $this->getCustomer()->getStore()->getWebsite()
57
+ );
58
+ }
59
+
60
+ /**
61
+ * getter for additional books. Fully processed.
62
+ *
63
+ * @return array
64
+ */
65
+ public function getAdditionalBooksToShow()
66
+ {
67
+ $additionalBooksToShow = array();
68
+ $additionalFromConfig = $this->_getWebsiteConfigFromHelper(
69
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_ADDRESSBOOK_PREF_SHOW_BOOKS,
70
+ $this->getCustomer()->getStore()->getWebsite()
71
+ );
72
+
73
+ if(strlen($additionalFromConfig))
74
+ {
75
+ $additionalFromConfig = explode(',', $additionalFromConfig);
76
+ $this->getConnectorContact();
77
+ if($this->contact_id){
78
+ $addressBooks = $this->_getApiClient()->getContactAddressBooks($this->contact_id);
79
+ $processedAddressBooks = array();
80
+ if(is_array($addressBooks)){
81
+ foreach($addressBooks as $addressBook){
82
+ $processedAddressBooks[$addressBook->id] = $addressBook->name;
83
+ }
84
+ }
85
+ foreach($additionalFromConfig as $bookId){
86
+ $connectorBook = $this->_getApiClient()->getAddressBookById($bookId);
87
+ if(isset($connectorBook->id))
88
+ {
89
+ $subscribed = 0;
90
+ if(isset($processedAddressBooks[$bookId]))
91
+ $subscribed = 1;
92
+ $additionalBooksToShow[] = array(
93
+ "name" => $connectorBook->name,
94
+ "value" => $connectorBook->id,
95
+ "subscribed" => $subscribed
96
+ );
97
+ }
98
+ }
99
+ }
100
+ }
101
+ return $additionalBooksToShow;
102
+ }
103
+
104
+ /**
105
+ * can show data fields?
106
+ *
107
+ * @return mixed
108
+ */
109
+ public function getCanShowDataFields()
110
+ {
111
+ return $this->_getWebsiteConfigFromHelper(
112
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_ADDRESSBOOK_PREF_CAN_SHOW_FIELDS,
113
+ $this->getCustomer()->getStore()->getWebsite()
114
+ );
115
+ }
116
+
117
+ /**
118
+ * getter for data fields to show. Fully processed.
119
+ *
120
+ * @return array
121
+ */
122
+ public function getDataFieldsToShow()
123
+ {
124
+ $datafieldsToShow = array();
125
+ $dataFieldsFromConfig = $this->_getWebsiteConfigFromHelper(
126
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_ADDRESSBOOK_PREF_SHOW_FIELDS,
127
+ $this->getCustomer()->getStore()->getWebsite()
128
+ );
129
+ if(strlen($dataFieldsFromConfig))
130
+ {
131
+ $dataFieldsFromConfig = explode(',', $dataFieldsFromConfig);
132
+ $contact = $this->getConnectorContact();
133
+ if($this->contact_id)
134
+ {
135
+ $contactDataFields = $contact->dataFields;
136
+ $processedContactDataFields = array();
137
+ foreach($contactDataFields as $contactDataField){
138
+ $processedContactDataFields[$contactDataField->key] = $contactDataField->value;
139
+ }
140
+
141
+ $connectorDataFields = $this->_getApiClient()->getDataFields();
142
+ $processedConnectorDataFields = array();
143
+ foreach($connectorDataFields as $connectorDataField){
144
+ $processedConnectorDataFields[$connectorDataField->name] = $connectorDataField;
145
+ }
146
+ foreach($dataFieldsFromConfig as $dataFieldFromConfig){
147
+ if(isset($processedConnectorDataFields[$dataFieldFromConfig])){
148
+ $value = "";
149
+ $type = "";
150
+ if(isset($processedContactDataFields[$processedConnectorDataFields[$dataFieldFromConfig]->name])){
151
+ if($processedConnectorDataFields[$dataFieldFromConfig]->type == "Date"){
152
+ $type = "Date";
153
+ $value = $processedContactDataFields[$processedConnectorDataFields[$dataFieldFromConfig]->name];
154
+ $value = Mage::app()->getLocale()->date($value)->toString("Y/M/d");
155
+ }
156
+ else
157
+ $value = $processedContactDataFields[$processedConnectorDataFields[$dataFieldFromConfig]->name];
158
+ }
159
+
160
+ $datafieldsToShow[] = array(
161
+ 'name' => $processedConnectorDataFields[$dataFieldFromConfig]->name,
162
+ 'type' => $processedConnectorDataFields[$dataFieldFromConfig]->type,
163
+ 'value' => $value
164
+ );
165
+ }
166
+ }
167
+
168
+ }
169
+ }
170
+ return $datafieldsToShow;
171
+ }
172
+
173
+ /**
174
+ * find out if anything is true
175
+ *
176
+ * @return bool
177
+ */
178
+ public function canShowAnything()
179
+ {
180
+ if($this->getCanShowDataFields() or $this->getCanShowAdditionalBooks()){
181
+ $books = $this->getAdditionalBooksToShow();
182
+ $fields = $this->getDataFieldsToShow();
183
+ if(!empty($books) or !empty($fields))
184
+ return true;
185
+ }
186
+ return false;
187
+ }
188
+
189
+ /**
190
+ * get connector contact
191
+ *
192
+ * @return mixed
193
+ */
194
+ public function getConnectorContact()
195
+ {
196
+ $contact = $this->_getApiClient()->getContactByEmail($this->getCustomer()->getEmail());
197
+ if($contact->id){
198
+ $this->_getCustomerSession()->setConnectorContactId($contact->id);
199
+ $this->contact_id = $contact->id;
200
+ }else{
201
+ $contact = $this->_getApiClient()->postContacts($this->getCustomer()->getEmail());
202
+ if($contact->id){
203
+ $this->_getCustomerSession()->setConnectorContactId($contact->id);
204
+ $this->contact_id = $contact->id;
205
+ }
206
+ }
207
+ return $contact;
208
+ }
209
+
210
+ private function _getCustomerSession()
211
+ {
212
+ return Mage::getSingleton('customer/session');
213
+ }
214
+ }
app/code/community/Dotdigitalgroup/Email/Block/Edc.php ADDED
@@ -0,0 +1,410 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Edc extends Mage_Core_Block_Template
4
+ {
5
+ protected $_edc_type;
6
+
7
+ protected function _construct()
8
+ {
9
+
10
+ parent::_construct();
11
+
12
+ if ($this->getRequest()->getControllerName() == 'quoteproducts') {
13
+ $this->_edc_type = 'quote_products';
14
+ }
15
+ }
16
+
17
+ /**
18
+ * Prepare layout, set the template.
19
+ * @return Mage_Core_Block_Abstract|void
20
+ */
21
+ protected function _prepareLayout()
22
+ {
23
+ if ($root = $this->getLayout()->getBlock('root')) {
24
+ $root->setTemplate('page/blank.phtml');
25
+ }
26
+ }
27
+
28
+ /**
29
+ * Product related items.
30
+ *
31
+ * @param Mage_Catalog_Model_Product $productModel
32
+ * @param $mode
33
+ *
34
+ * @return array
35
+ */
36
+ private function _getRecommendedProduct(Mage_Catalog_Model_Product $productModel, $mode)
37
+ {
38
+ //array of products to display
39
+ $products = array();
40
+ switch($mode){
41
+ case 'related':
42
+ $products = $productModel->getRelatedProducts();
43
+ break;
44
+ case 'upsell':
45
+ $products = $productModel->getUpSellProducts();
46
+ break;
47
+ case 'crosssell':
48
+ $products = $productModel->getCrossSellProducts();
49
+ break;
50
+
51
+ }
52
+ $productIds = array();
53
+ foreach($products as $product){
54
+ $productIds[] = $product->getId();
55
+ }
56
+ return $productIds;
57
+ }
58
+
59
+ public function getTextForUrl($store)
60
+ {
61
+ $store = Mage::app()->getStore($store);
62
+ return $store->getConfig(
63
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DYNAMIC_CONTENT_LINK_TEXT
64
+ );
65
+ }
66
+
67
+ /**
68
+ * Diplay mode type.
69
+ *
70
+ * @return mixed|string
71
+ */
72
+ public function getMode()
73
+ {
74
+ return Mage::helper('ddg/recommended')->getDisplayType();
75
+
76
+ }
77
+
78
+ /**
79
+ * Number of the colums.
80
+ * @return int|mixed
81
+ * @throws Exception
82
+ */
83
+ public function getColumnCount()
84
+ {
85
+ return Mage::helper('ddg/recommended')->getDisplayLimitByMode($this->getRequest()->getActionName());
86
+ }
87
+
88
+ /**
89
+ * Price html.
90
+ * @param $product
91
+ *
92
+ * @return string
93
+ */
94
+ public function getPriceHtml($product)
95
+ {
96
+ $this->setTemplate('connector/product/price.phtml');
97
+ $this->setProduct($product);
98
+ return $this->toHtml();
99
+ }
100
+
101
+ /**
102
+ * get collection to EDC type
103
+ *
104
+ * @return array
105
+ * @throws Exception
106
+ */
107
+ public function getLoadedProductCollection()
108
+ {
109
+ $mode = $this->getRequest()->getActionName();
110
+ $limit = Mage::helper('ddg/recommended')->getDisplayLimitByMode($mode);
111
+ if (! $this->_edc_type)
112
+ $this->_edc_type = $mode;
113
+
114
+ switch ($this->_edc_type) {
115
+ case 'recentlyviewed':
116
+ return $this->_getRecentlyViewedCollection($limit);
117
+ break;
118
+ case 'push':
119
+ return $this->_getProductPushCollection($limit);
120
+ break;
121
+ case 'bestsellers':
122
+ return $this->_getBestSellersCollection($mode, $limit);
123
+ break;
124
+ case 'mostviewed':
125
+ return $this->_getMostViewedCollection($mode, $limit);
126
+ break;
127
+ case 'quote_products':
128
+ return $this->_getQuoteProductCollection($mode, $limit);
129
+ break;
130
+ }
131
+ }
132
+
133
+ /**
134
+ * get collection for recently viewed products
135
+ *
136
+ * @param $limit
137
+ * @return array
138
+ * @throws Exception
139
+ */
140
+ private function _getRecentlyViewedCollection($limit)
141
+ {
142
+ $productsToDisplay = array();
143
+ $customerId = $this->getRequest()->getParam('customer_id');
144
+
145
+ //login customer to receive the recent products
146
+ $session = Mage::getSingleton('customer/session');
147
+ $isLoggedIn = $session->loginById($customerId);
148
+
149
+ /** @var Mage_Reports_Block_Product_Viewed $collection */
150
+ $collection = Mage::getSingleton('Mage_Reports_Block_Product_Viewed');
151
+ $productItems = $collection->getItemsCollection()
152
+ ->setPageSize($limit);
153
+
154
+ Mage::helper('ddg')->log('Recentlyviewed customer : ' . $customerId . ', limit : ' . $limit .
155
+ ', items found : ' . count($productItems) . ', is customer logged in : ' . $isLoggedIn . ', products :' . count($productsToDisplay));
156
+ //get the product ids from items collection
157
+ $productIds = $productItems->getColumnValues('product_id');
158
+ //get product collection to check for salable
159
+ $productCollection = Mage::getModel('catalog/product')->getCollection()
160
+ ->addFieldToFilter('entity_id', array('in' => $productIds))
161
+ ;
162
+ //show products only if is salable
163
+ foreach ($productCollection as $product) {
164
+ if($product->isSalable())
165
+ $productsToDisplay[$product->getId()] = $product;
166
+
167
+ }
168
+ $session->logout();
169
+
170
+ return $productsToDisplay;
171
+ }
172
+
173
+ /**
174
+ * get collection for push items
175
+ *
176
+ * @param $limit
177
+ * @return array
178
+ */
179
+ private function _getProductPushCollection($limit)
180
+ {
181
+ $productsToDisplay = array();
182
+ $productIds = Mage::helper('ddg/recommended')->getProductPushIds();
183
+
184
+ $productCollection = Mage::getResourceModel('catalog/product_collection')
185
+ ->addAttributeToFilter('entity_id', array('in' => $productIds))
186
+ ->addAttributeToSelect(array('product_url', 'name', 'store_id', 'small_image', 'price'))
187
+ ->setPageSize($limit);
188
+
189
+ foreach ($productCollection as $product) {
190
+ //add only salable products
191
+ if($product->isSaleable())
192
+ $productsToDisplay[] = $product;
193
+ }
194
+
195
+ return $productsToDisplay;
196
+ }
197
+
198
+ /**
199
+ * get collection for best sellers
200
+ *
201
+ * @param $mode
202
+ * @param $limit
203
+ * @return Varien_Data_Collection
204
+ */
205
+ private function _getBestSellersCollection($mode, $limit)
206
+ {
207
+ $from = Mage::helper('ddg/recommended')->getTimeFromConfig($mode);
208
+ $locale = Mage::app()->getLocale()->getLocale();
209
+ $to = Zend_Date::now($locale)->toString(Zend_Date::ISO_8601);
210
+
211
+ $productCollection = Mage::getResourceModel('reports/product_collection')
212
+ ->addAttributeToSelect(array('product_url', 'name', 'store_id', 'small_image', 'price'))
213
+ ->addOrderedQty($from, $to)
214
+ ->setOrder('ordered_qty', 'desc')
215
+ ->setPageSize($limit);
216
+
217
+ Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($productCollection);
218
+ $productCollection->addAttributeToFilter('is_saleable', TRUE);
219
+
220
+ $cat_id = Mage::app()->getRequest()->getParam('category_id', false);
221
+ $cat_name = Mage::app()->getRequest()->getParam('category_name', false);
222
+
223
+ //check for params
224
+ if ($cat_id or $cat_name){
225
+ $category = Mage::getModel('catalog/category');
226
+ //load by category id
227
+ if($cat_id)
228
+ $category->load($cat_id);
229
+ //load by the category name
230
+ if($cat_name)
231
+ $category->loadByAttribute('name', $cat_name);
232
+
233
+ $productCollection = $this->_joinCategoryOnCollection($productCollection, $category);
234
+ }
235
+ return $productCollection;
236
+ }
237
+
238
+ /**
239
+ * get collection for most viewed items
240
+ *
241
+ * @param $mode
242
+ * @param $limit
243
+ * @return array
244
+ */
245
+ private function _getMostViewedCollection($mode, $limit)
246
+ {
247
+ $productsToDisplay = array();
248
+ $from = Mage::helper('ddg/recommended')->getTimeFromConfig($mode);
249
+ $locale = Mage::app()->getLocale()->getLocale();
250
+
251
+ $to = Zend_Date::now($locale)->toString(Zend_Date::ISO_8601);
252
+ $productCollection = Mage::getResourceModel('reports/product_collection')
253
+ ->addViewsCount($from, $to)
254
+ ->setPageSize($limit);
255
+
256
+ $cat_id = Mage::app()->getRequest()->getParam('category_id');
257
+ $cat_name = Mage::app()->getRequest()->getParam('category_name');
258
+ if($cat_id or $cat_name){
259
+ $category = Mage::getModel('catalog/category');
260
+
261
+ if($cat_id)
262
+ $category->load($cat_id);
263
+
264
+ if($cat_name)
265
+ $category->loadByAttribute('name', $cat_name);
266
+
267
+ $productCollection = $this->_joinCategoryOnCollection($productCollection, $category);
268
+ }
269
+
270
+ $productIds = $productCollection->getColumnValues('entity_id');
271
+ $productCollection->clear();
272
+ $productCollection = Mage::getResourceModel('catalog/product_collection')
273
+ ->addIdFilter($productIds)
274
+ ->addAttributeToSelect(array('product_url', 'name', 'store_id', 'small_image', 'price'));
275
+
276
+ foreach ($productCollection as $_product) {
277
+ //add only salable products
278
+ if($_product->isSalable())
279
+ $productsToDisplay[] = $_product;
280
+ }
281
+
282
+ return $productsToDisplay;
283
+ }
284
+
285
+ /**
286
+ * join categories on product collection
287
+ *
288
+ * @param $productCollection
289
+ * @param $category
290
+ * @return mixed
291
+ */
292
+ private function _joinCategoryOnCollection($productCollection, $category)
293
+ {
294
+ if ($category->getId()){
295
+ $productCollection->getSelect()
296
+ ->joinLeft(
297
+ array("ccpi" => 'catalog_category_product_index'),
298
+ "e.entity_id = ccpi.product_id",
299
+ array("category_id")
300
+ )
301
+ ->where('ccpi.category_id =?', $category->getId());
302
+ }else{
303
+ Mage::helper('ddg')->log('Most viewed. Category id/name is invalid. It does not exist.');
304
+ }
305
+
306
+ return $productCollection;
307
+ }
308
+
309
+ /**
310
+ * get collection for quote products
311
+ *
312
+ * @param $mode
313
+ * @param $limit
314
+ * @return array
315
+ * @throws Exception
316
+ */
317
+ private function _getQuoteProductCollection($mode, $limit)
318
+ {
319
+ $quoteModel = Mage::registry('current_quote');
320
+
321
+ if (! $quoteModel) {
322
+ Mage::throwException('no current_quote found for EDC');
323
+ }
324
+ $quoteItems = $quoteModel->getAllItems();
325
+
326
+ $productsToDisplay = $this->getProductsToDisplay($quoteItems, $limit, $mode, 'QUOTE');
327
+
328
+ return $productsToDisplay;
329
+ }
330
+
331
+ /**
332
+ * get products to display for order, wishlist and quote EDC
333
+ *
334
+ * @param $items
335
+ * @param $limit
336
+ * @param $mode
337
+ * @param $type
338
+ * @return array
339
+ */
340
+ protected function getProductsToDisplay($items, $limit, $mode, $type)
341
+ {
342
+ //products to be display for recommended pages
343
+ $productsToDisplay = array();
344
+ $productsToDisplayCounter = 0;
345
+
346
+ $numItems = count($items);
347
+
348
+ //no product found to display
349
+ if ($numItems == 0 || ! $limit) {
350
+ return array();
351
+ }elseif (count($items) > $limit) {
352
+ $maxPerChild = 1;
353
+ } else {
354
+ $maxPerChild = number_format($limit / count($items));
355
+ }
356
+
357
+ Mage::helper('ddg')->log('DYNAMIC ' .$type. ' PRODUCTS : limit ' . $limit . ' products : ' . $numItems . ', max per child : '. $maxPerChild);
358
+
359
+ foreach ($items as $item) {
360
+ $i = 0;
361
+ //parent product
362
+ $product = $item->getProduct();
363
+ //check for product exists
364
+
365
+ //get single product for current mode
366
+ $recommendedProducts = $this->_getRecommendedProduct($product, $mode);
367
+ if (! empty($recommendedProducts)) {
368
+
369
+ $recommendedProducts = Mage::getModel('catalog/product')
370
+ ->getCollection()
371
+ ->addIdFilter($recommendedProducts)
372
+ ->addAttributeToSelect(array('product_url', 'name', 'store_id', 'small_image', 'price'));
373
+
374
+ foreach ($recommendedProducts as $product) {
375
+ //check if still exists
376
+ if ($product->getId() && $productsToDisplayCounter < $limit && $i <= $maxPerChild && $product->isSaleable() && !$product->getParentId()) {
377
+ //we have a product to display
378
+ $productsToDisplay[$product->getId()] = $product;
379
+ $i++;
380
+ $productsToDisplayCounter++;
381
+ }
382
+ }
383
+ }
384
+
385
+ //have reached the limit don't loop for more
386
+ if ($productsToDisplayCounter == $limit) {
387
+ break;
388
+ }
389
+ }
390
+
391
+ //check for more space to fill up the table with fallback products
392
+ if ($productsToDisplayCounter < $limit) {
393
+ $fallbackIds = Mage::helper('ddg/recommended')->getFallbackIds();
394
+ $productCollection = Mage::getModel('catalog/product')
395
+ ->getCollection()
396
+ ->addIdFilter($fallbackIds)
397
+ ->addAttributeToSelect(array('product_url', 'name', 'store_id', 'small_image', 'price'));
398
+
399
+ foreach ($productCollection as $product) {
400
+ if($product->isSaleable())
401
+ $productsToDisplay[$product->getId()] = $product;
402
+ //stop the limit was reached
403
+ if (count($productsToDisplay) == $limit) {
404
+ break;
405
+ }
406
+ }
407
+ }
408
+ return $productsToDisplay;
409
+ }
410
+ }
app/code/community/Dotdigitalgroup/Email/Block/Feefo.php ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ //quote
51
+ if (! $quoteModel->getId())
52
+ Mage::throwException('die');
53
+
54
+ $quoteItems = $quoteModel->getAllItems();
55
+
56
+ if(count($quoteItems) == 0)
57
+ return array();
58
+
59
+ /** @var Mage_Sales_Model_Quote_Item $item */
60
+ foreach($quoteItems as $item)
61
+ {
62
+ $productModel = $item->getProduct();
63
+ if ($productModel->getId())
64
+ $products[$productModel->getSku()] = $productModel->getName();
65
+ }
66
+ return $products;
67
+ }
68
+
69
+ /**
70
+ * get product reviews from feefo
71
+ *
72
+ * @return array
73
+ */
74
+ public function getProductsReview()
75
+ {
76
+ $check = true;
77
+ $reviews = array();
78
+ $feefo_dir = Mage::getModel('core/config_options')->getLibDir().DS.'connector'.DS.'feefo';
79
+ $helper = Mage::helper('ddg');
80
+ $logon = $helper->getFeefoLogon();
81
+ $limit = $helper->getFeefoReviewsPerProduct();
82
+ $products = $this->getQuoteProducts();
83
+
84
+ foreach($products as $sku => $name)
85
+ {
86
+ $url = "http://www.feefo.com/feefo/xmlfeed.jsp?logon=" . $logon . "&limit=".$limit . "&vendorref=" . $sku . "&mode=productonly" ;
87
+ $doc = new DOMDocument();
88
+ $xsl = new XSLTProcessor();
89
+ if($check)
90
+ $doc->load($feefo_dir. DS ."feedback.xsl");
91
+ else
92
+ $doc->load($feefo_dir. DS ."feedback-no-th.xsl");
93
+ $xsl->importStyleSheet($doc);
94
+ $doc->load($url);
95
+ $productReview = $xsl->transformToXML($doc);
96
+ if (strpos($productReview, '<td') !== false)
97
+ $reviews[$name] = $xsl->transformToXML($doc);
98
+ $check = false;
99
+ }
100
+ return $reviews;
101
+ }
102
+ }
app/code/community/Dotdigitalgroup/Email/Block/Order.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Order extends Dotdigitalgroup_Email_Block_Edc
4
+ {
5
+
6
+ /**
7
+ * Prepare layout, set template and title.
8
+ *
9
+ * @return Mage_Core_Block_Abstract|void
10
+ */
11
+ protected function _prepareLayout()
12
+ {
13
+ if ($root = $this->getLayout()->getBlock('root')) {
14
+ $root->setTemplate('page/blank.phtml');
15
+ }
16
+ if ($headBlock = $this->getLayout()->getBlock('head')) {
17
+ $headBlock->setTitle($this->__('Order # %s', $this->getOrder()->getRealOrderId()));
18
+ }
19
+ }
20
+
21
+ /**
22
+ * Current Order.
23
+ *
24
+ * @return Mage_Core_Model_Abstract|mixed
25
+ */
26
+ public function getOrder()
27
+ {
28
+ $order = Mage::registry('current_order');
29
+ if (! $order) {
30
+ Mage::throwException('no current_order found for EDC');
31
+ }
32
+
33
+ return $order;
34
+ }
35
+
36
+ /**
37
+ * Filter items for review. If a customer has already placed a review for a product then exclude the product.
38
+ *
39
+ * @param array $items
40
+ * @param int $websiteId
41
+ * @return mixed
42
+ */
43
+ public function filterItemsForReview($items, $websiteId)
44
+ {
45
+ if (!count($items))
46
+ return;
47
+
48
+ $order = $this->getOrder();
49
+
50
+ //if customer is guest then no need to filter any items
51
+ if($order->getCustomerIsGuest())
52
+ return $items;
53
+
54
+ if(!Mage::helper('ddg/review')->isNewProductOnly($websiteId))
55
+ return $items;
56
+
57
+ $customerId = $order->getCustomerId();
58
+
59
+ foreach($items as $key => $item)
60
+ {
61
+ $productId = $item->getProduct()->getId();
62
+
63
+ $collection = Mage::getModel('review/review')->getCollection();
64
+ $collection->addCustomerFilter($customerId)
65
+ ->addStoreFilter($order->getStoreId())
66
+ ->addFieldToFilter('main_table.entity_pk_value', $productId);
67
+
68
+ //remove item if customer has already placed review on this item
69
+ if($collection->getSize())
70
+ unset($items[$key]);
71
+ }
72
+
73
+ return $items;
74
+ }
75
+ }
app/code/community/Dotdigitalgroup/Email/Block/Order/Creditmemo.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Block_Order_Creditmemo extends Mage_Sales_Block_Order_Creditmemo_Items
3
+ {
4
+ /**
5
+ * Prepare layout.
6
+ *
7
+ * @return Mage_Core_Block_Abstract|void
8
+ */
9
+ protected function _prepareLayout()
10
+ {
11
+ if ($root = $this->getLayout()->getBlock('root')) {
12
+ $root->setTemplate('page/blank.phtml');
13
+ }
14
+ }
15
+
16
+ /**
17
+ * Get current Order.
18
+ * @return Mage_Sales_Model_Order
19
+ * @throws Exception
20
+ */
21
+ public function getOrder()
22
+ {
23
+ $order = Mage::registry('current_order');
24
+ if (! $order) {
25
+ Mage::throwException('no current_order found for EDC');
26
+ }
27
+
28
+ if (! $order->hasCreditmemos()) {
29
+ //throw new Exception('TE - no creditmemo for order : '. $orderId);
30
+ Mage::helper('ddg')->log('TE - no creditmemo for order : '. $order->getId());
31
+ return false;
32
+ }
33
+
34
+ return $order;
35
+ }
36
+
37
+ /**
38
+ * Order items.
39
+ * @return mixed
40
+ */
41
+ public function getCreditmemoItems()
42
+ {
43
+ return Mage::registry('current_order')->getItemsCollection();
44
+ }
45
+ }
app/code/community/Dotdigitalgroup/Email/Block/Order/Invoice.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Block_Order_Invoice extends Mage_Sales_Block_Order_Invoice_Items
3
+ {
4
+ /**
5
+ * Prepare layout.
6
+ * @return Mage_Core_Block_Abstract|void
7
+ */
8
+ protected function _prepareLayout()
9
+ {
10
+ if ($root = $this->getLayout()->getBlock('root')) {
11
+ $root->setTemplate('page/blank.phtml');
12
+ }
13
+ }
14
+
15
+ /**
16
+ * Get current order.
17
+ * @return Mage_Sales_Model_Order
18
+ * @throws Exception
19
+ */
20
+ public function getOrder()
21
+ {
22
+ $order = Mage::registry('current_order');
23
+ if (! $order) {
24
+ Mage::throwException('no current_order found for EDC');
25
+ }
26
+
27
+ if (! $order->hasInvoices()) {
28
+ //throw new Exception('TE - no invoice for order : '. $orderId);
29
+ Mage::helper('ddg')->log('TE - no invoice for order : '. $order->getId());
30
+ return false;
31
+ }
32
+
33
+ return $order;
34
+ }
35
+
36
+ }
app/code/community/Dotdigitalgroup/Email/Block/Order/Shipping.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Block_Order_Shipping extends Mage_Sales_Block_Order_Creditmemo_Items
3
+ {
4
+ /**
5
+ * Prepare layout.
6
+ * @return Mage_Core_Block_Abstract|void
7
+ */
8
+ protected function _prepareLayout()
9
+ {
10
+ if ($root = $this->getLayout()->getBlock('root')) {
11
+ $root->setTemplate('page/blank.phtml');
12
+ }
13
+ }
14
+
15
+ /**
16
+ * @return Mage_Sales_Model_Order
17
+ * @throws Exception
18
+ */
19
+ public function getOrder()
20
+ {
21
+ $order = Mage::registry('current_order');
22
+ if (! $order) {
23
+ Mage::throwException('no current_order found for EDC');
24
+ }
25
+
26
+ if (! $order->hasShipments()) {
27
+ //throw new Exception('TE - no shipments for order : '. $orderId);
28
+ Mage::helper('ddg')->log('TE - no shipments for order : '. $order->getId());
29
+ return false;
30
+ }
31
+
32
+ return $order;
33
+
34
+ }
35
+
36
+ }
app/code/community/Dotdigitalgroup/Email/Block/Products.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Products extends Mage_Core_Block_Template
4
+ {
5
+ /**
6
+ * Prepare layout, set template.
7
+ *
8
+ * @return Mage_Core_Block_Abstract|void
9
+ */
10
+ protected function _prepareLayout()
11
+ {
12
+ if ($root = $this->getLayout()->getBlock('root')) {
13
+ $root->setTemplate('page/blank.phtml');
14
+ }
15
+ }
16
+
17
+ /**
18
+ * get the products to display for table
19
+ */
20
+ public function getRecommendedProducts()
21
+ {
22
+ $productsToDisplay = array();
23
+ $orderId = $this->getRequest()->getParam('order', false);
24
+ $mode = $this->getRequest()->getParam('mode', false);
25
+ if ($orderId && $mode) {
26
+ $orderModel = Mage::getModel('sales/order')->load($orderId);
27
+ if ($orderModel->getId()) {
28
+ $storeId = $orderModel->getStoreId();
29
+ $appEmulation = Mage::getSingleton('core/app_emulation');
30
+ $appEmulation->startEnvironmentEmulation($storeId);
31
+ //order products
32
+ $productRecommended = Mage::getModel('ddg_automation/dynamic_recommended', $orderModel);
33
+ $productRecommended->setMode($mode);
34
+
35
+ //get the order items recommendations
36
+ $productsToDisplay = $productRecommended->getProducts();
37
+ }
38
+ }
39
+
40
+ return $productsToDisplay;
41
+ }
42
+
43
+
44
+ /**
45
+ * Price html block.
46
+ *
47
+ * @param $product
48
+ *
49
+ * @return string
50
+ */
51
+ public function getPriceHtml($product)
52
+ {
53
+ $this->setTemplate('connector/price.phtml');
54
+ $this->setProduct($product);
55
+ return $this->toHtml();
56
+ }
57
+
58
+ /**
59
+ * Display type mode.
60
+ * @return mixed|string
61
+ */
62
+ public function getDisplayType()
63
+ {
64
+ return Mage::helper('ddg/recommended')->getDisplayType();
65
+
66
+ }
67
+ }
app/code/community/Dotdigitalgroup/Email/Block/Recommended/Products.php ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Recommended_Products extends Dotdigitalgroup_Email_Block_Edc
4
+ {
5
+ /**
6
+ * Slot div name.
7
+ * @var string
8
+ */
9
+ public $slot;
10
+
11
+ /**
12
+ * get the products to display for table
13
+ */
14
+ public function getLoadedProductCollection()
15
+ {
16
+ $orderModel = Mage::registry('current_order');
17
+ if (! $orderModel) {
18
+ Mage::throwException('no current_order found for EDC');
19
+ }
20
+
21
+ //display mode based on the action name
22
+ $mode = $this->getRequest()->getActionName();
23
+ //number of product items to be displayed
24
+ $limit = Mage::helper('ddg/recommended')->getDisplayLimitByMode($mode);
25
+ $orderItems = $orderModel->getAllItems();
26
+
27
+ $productsToDisplay = $this->getProductsToDisplay($orderItems, $limit, $mode, 'PRODUCT');
28
+ return $productsToDisplay;
29
+ }
30
+
31
+ /**
32
+ * Nosto products data.
33
+ * @return object
34
+ */
35
+ public function getNostoProducts()
36
+ {
37
+ $client = Mage::getModel('ddg_automation/apiconnector_client');
38
+ //slot name, div id
39
+ $slot = Mage::app()->getRequest()->getParam('slot', false);
40
+
41
+ //email recommendation
42
+ $email = Mage::app()->getRequest()->getParam('email', false);
43
+
44
+ //no valid data for nosto recommendation
45
+ if (!$slot || ! $email)
46
+ return false;
47
+ else
48
+ $this->slot = $slot;
49
+
50
+ //html data from nosto
51
+ $data = $client->getNostoProducts($slot, $email);
52
+
53
+ //check for valid response
54
+ if (! isset($data->$email) && !isset($data->$email->$slot))
55
+ return false;
56
+ return $data->$email->$slot;
57
+ }
58
+
59
+ /**
60
+ * Slot name.
61
+ * Should be called after getNostoProducts.
62
+ * @return string
63
+ */
64
+ public function getSlotName()
65
+ {
66
+ return $this->slot;
67
+ }
68
+ }
app/code/community/Dotdigitalgroup/Email/Block/Recommended/Wishlistproducts.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Recommended_Wishlistproducts extends Dotdigitalgroup_Email_Block_Edc
4
+ {
5
+
6
+ protected function _getWishlistItems()
7
+ {
8
+ $wishlist = $this->_getWishlist();
9
+ if($wishlist && count($wishlist->getItemCollection()))
10
+ return $wishlist->getItemCollection();
11
+ else
12
+ return array();
13
+ }
14
+
15
+ protected function _getWishlist()
16
+ {
17
+ $customerId = Mage::app()->getRequest()->getParam('customer_id');
18
+ if(!$customerId)
19
+ return array();
20
+
21
+ $customer = Mage::getModel('customer/customer')->load($customerId);
22
+ if(!$customer->getId())
23
+ return array();
24
+
25
+ $collection = Mage::getModel('wishlist/wishlist')->getCollection();
26
+ $collection->addFieldToFilter('customer_id', $customerId)
27
+ ->setOrder('updated_at', 'DESC')
28
+ ->getSelect()->limit(1);
29
+
30
+ if ($collection->count())
31
+ return $collection->getFirstItem();
32
+ else
33
+ return array();
34
+
35
+ }
36
+
37
+ /**
38
+ * get the products to display for table
39
+ */
40
+ public function getLoadedProductCollection()
41
+ {
42
+ //display mode based on the action name
43
+ $mode = $this->getRequest()->getActionName();
44
+ //number of product items to be displayed
45
+ $limit = Mage::helper('ddg/recommended')->getDisplayLimitByMode($mode);
46
+
47
+ $items = $this->_getWishlistItems();
48
+ $productsToDisplay = $this->getProductsToDisplay($items, $limit, $mode, 'WISHLIST');
49
+
50
+ return $productsToDisplay;
51
+ }
52
+ }
app/code/community/Dotdigitalgroup/Email/Block/System/Email/Template/Edit.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Block_System_Email_Template_Edit extends Mage_Adminhtml_Block_System_Email_Template_Edit
3
+ {
4
+ public function __construct()
5
+ {
6
+ parent::__construct();
7
+ $this->setTemplate('connector/system/email/template/edit.phtml');
8
+ }
9
+ public function getConnectorTemplates()
10
+ {
11
+ return Mage::helper('ddg')->getTemplateList();
12
+ }
13
+ }
app/code/community/Dotdigitalgroup/Email/Block/Wishlist.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Block_Wishlist extends Dotdigitalgroup_Email_Block_Edc
4
+ {
5
+ protected $_website;
6
+
7
+ public function getWishlistItems()
8
+ {
9
+ $wishlist = $this->_getWishlist();
10
+ if($wishlist && count($wishlist->getItemCollection()))
11
+ return $wishlist->getItemCollection();
12
+ else
13
+ return false;
14
+ }
15
+
16
+ protected function _getWishlist()
17
+ {
18
+ $customerId = Mage::app()->getRequest()->getParam('customer_id');
19
+ if(!$customerId)
20
+ return false;
21
+
22
+ $customer = Mage::getModel('customer/customer')->load($customerId);
23
+ if(!$customer->getId())
24
+ return false;
25
+
26
+ $collection = Mage::getModel('wishlist/wishlist')->getCollection();
27
+ $collection->addFieldToFilter('customer_id', $customerId)
28
+ ->setOrder('updated_at', 'DESC');
29
+
30
+ if ($collection->count())
31
+ return $collection->setPageSize(1)->setCurPage(1)->getFirstItem();
32
+ else
33
+ return false;
34
+
35
+ }
36
+
37
+ public function getMode()
38
+ {
39
+ return Mage::helper('ddg')->getWebsiteConfig(
40
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DYNAMIC_CONTENT_WIHSLIST_DISPLAY
41
+ );
42
+ }
43
+ }
app/code/community/Dotdigitalgroup/Email/Helper/Config.php ADDED
@@ -0,0 +1,347 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ const XML_PATH_CONNECTOR_SYNC_DATA_FIELDS_BRAND_ATTRIBUTE = 'connector_configuration/data_fields/brand_attribute';
141
+
142
+ //Transactional Data
143
+ const XML_PATH_CONNECTOR_SYNC_ORDER_STATUS = 'connector_configuration/transactional_data/order_statuses';
144
+ const XML_PATH_CONNECTOR_CUSTOM_ORDER_ATTRIBUTES = 'connector_configuration/transactional_data/order_custom_attributes';
145
+ const XML_PATH_CONNECTOR_CUSTOM_QUOTE_ATTRIBUTES = 'connector_configuration/transactional_data/quote_custom_attributes';
146
+ const XML_PATH_CONNECTOR_SYNC_ORDER_PRODUCT_ATTRIBUTES = 'connector_configuration/transactional_data/order_product_attributes';
147
+ const XML_PATH_CONNECTOR_SYNC_ORDER_PRODUCT_CUSTOM_OPTIONS = 'connector_configuration/transactional_data/order_product_custom_options';
148
+ //Admin
149
+ const XML_PATH_CONNECTOR_DISABLE_NEWSLETTER_SUCCESS = 'connector_configuration/admin/disable_newsletter_success';
150
+ const XML_PATH_CONNECTOR_DISABLE_CUSTOMER_SUCCESS = 'connector_configuration/admin/disable_customer_success';
151
+ //Dynamic Content Styling
152
+ const XML_PATH_CONNECTOR_DYNAMIC_STYLING = 'connector_configuration/dynamic_content_style/dynamic_syling';
153
+ const XML_PATH_CONNECTOR_DYNAMIC_NAME_COLOR = 'connector_configuration/dynamic_content_style/name_color';
154
+ const XML_PATH_CONNECTOR_DYNAMIC_NAME_FONT_SIZE = 'connector_configuration/dynamic_content_style/name_font_size';
155
+ const XML_PATH_CONNECTOR_DYNAMIC_NAME_STYLE = 'connector_configuration/dynamic_content_style/name_style';
156
+ const XML_PATH_CONNECTOR_DYNAMIC_PRICE_COLOR = 'connector_configuration/dynamic_content_style/price_color';
157
+ const XML_PATH_CONNECTOR_DYNAMIC_PRICE_FONT_SIZE = 'connector_configuration/dynamic_content_style/price_font_size';
158
+ const XML_PATH_CONNECTOR_DYNAMIC_PRICE_STYLE = 'connector_configuration/dynamic_content_style/price_style';
159
+ const XML_PATH_CONNECTOR_DYNAMIC_LINK_COLOR = 'connector_configuration/dynamic_content_style/link_color';
160
+ const XML_PATH_CONNECTOR_DYNAMIC_LINK_FONT_SIZE = 'connector_configuration/dynamic_content_style/link_font_size';
161
+ const XML_PATH_CONNECTOR_DYNAMIC_LINK_STYLE = 'connector_configuration/dynamic_content_style/link_style';
162
+ const XML_PATH_CONNECTOR_DYNAMIC_DOC_FONT = 'connector_configuration/dynamic_content_style/font_picker';
163
+ const XML_PATH_CONNECTOR_DYNAMIC_DOC_BG_COLOR = 'connector_configuration/dynamic_content_style/doc_color';
164
+ const XML_PATH_CONNECTOR_DYNAMIC_OTHER_COLOR = 'connector_configuration/dynamic_content_style/other_color';
165
+ const XML_PATH_CONNECTOR_DYNAMIC_OTHER_FONT_SIZE = 'connector_configuration/dynamic_content_style/other_font_size';
166
+ const XML_PATH_CONNECTOR_DYNAMIC_OTHER_STYLE = 'connector_configuration/dynamic_content_style/other_style';
167
+ const XML_PATH_CONNECTOR_DYNAMIC_COUPON_COLOR = 'connector_configuration/dynamic_content_style/coupon_color';
168
+ const XML_PATH_CONNECTOR_DYNAMIC_COUPON_FONT_SIZE = 'connector_configuration/dynamic_content_style/coupon_font_size';
169
+ const XML_PATH_CONNECTOR_DYNAMIC_COUPON_STYLE = 'connector_configuration/dynamic_content_style/coupon_style';
170
+ const XML_PATH_CONNECTOR_DYNAMIC_COUPON_FONT = 'connector_configuration/dynamic_content_style/coupon_font_picker';
171
+ const XML_PATH_CONNECTOR_DYNAMIC_COUPON_BG_COLOR = 'connector_configuration/dynamic_content_style/coupon_doc_color';
172
+
173
+ //Catalog
174
+ const XML_PATH_CONNECTOR_SYNC_CATALOG_VALUES = 'connector_configuration/catalog_sync/catalog_values';
175
+ const XML_PATH_CONNECTOR_SYNC_CATALOG_VISIBILITY = 'connector_configuration/catalog_sync/catalog_visibility';
176
+ const XML_PATH_CONNECTOR_SYNC_CATALOG_TYPE = 'connector_configuration/catalog_sync/catalog_type';
177
+ //Abandoned Cart
178
+ const XML_PATH_CONNECTOR_EMAIL_CAPTURE = 'connector_configuration/abandoned_carts/email_capture';
179
+ const XML_PATH_CONNECTOR_ABANDONED_CART_LIMIT = 'connector_configuration/abandoned_carts/limits';
180
+ const XML_PATH_CONNECTOR_EMAIL_CAPTURE_NEWSLETTER = 'connector_configuration/abandoned_carts/email_capture_newsletter';
181
+ const XML_PATH_CONNECTOR_CONTENT_LINK_ENABLED = 'connector_configuration/abandoned_carts/link_enabled';
182
+ const XML_PATH_CONNECTOR_CONTENT_LINK_TEXT = 'connector_configuration/abandoned_carts/link_text';
183
+ const XML_PATH_CONNECTOR_CONTENT_CART_URL = 'connector_configuration/abandoned_carts/cart_url';
184
+ const XML_PATH_CONNECTOR_CONTENT_LOGIN_URL = 'connector_configuration/abandoned_carts/login_url';
185
+ // Address Book Pref
186
+ const XML_PATH_CONNECTOR_ADDRESSBOOK_PREF_CAN_CHANGE_BOOKS = 'connector_configuration/address_book_pref/can_change';
187
+ const XML_PATH_CONNECTOR_ADDRESSBOOK_PREF_SHOW_BOOKS = 'connector_configuration/address_book_pref/show_books';
188
+ const XML_PATH_CONNECTOR_ADDRESSBOOK_PREF_CAN_SHOW_FIELDS = 'connector_configuration/address_book_pref/can_show_fields';
189
+ const XML_PATH_CONNECTOR_ADDRESSBOOK_PREF_SHOW_FIELDS = 'connector_configuration/address_book_pref/fields_to_show';
190
+ //Dynamic Content
191
+ const XML_PATH_CONNECTOR_DYNAMIC_CONTENT_LINK_TEXT = 'connector_configuration/dynamic_content_style/link_text';
192
+
193
+ /**
194
+ * Automation studio.
195
+ */
196
+ const XML_PATH_CONNECTOR_AUTOMATION_STUDIO_CUSTOMER = 'connector_automation_studio/visitor_automation/customer_automation';
197
+ const XML_PATH_CONNECTOR_AUTOMATION_STUDIO_SUBSCRIBER = 'connector_automation_studio/visitor_automation/subscriber_automation';
198
+ const XML_PATH_CONNECTOR_AUTOMATION_STUDIO_ORDER = 'connector_automation_studio/visitor_automation/order_automation';
199
+ const XML_PATH_CONNECTOR_AUTOMATION_STUDIO_GUEST_ORDER = 'connector_automation_studio/visitor_automation/guest_order_automation';
200
+ const XML_PATH_CONNECTOR_AUTOMATION_STUDIO_REVIEW = 'connector_automation_studio/visitor_automation/review_automation';
201
+ const XML_PATH_CONNECTOR_AUTOMATION_STUDIO_WISHLIST = 'connector_automation_studio/visitor_automation/wishlist_automation';
202
+ const XML_PATH_CONNECTOR_AUTOMATION_STUDIO_ORDER_STATUS = 'connector_automation_studio/order_status_automation/status_to_automation';
203
+
204
+
205
+ /**
206
+ * ROI SECTION.
207
+ */
208
+ const XML_PATH_CONNECTOR_ROI_TRACKING_ENABLED = 'connector_configuration/tracking/roi_enabled';
209
+ const XML_PATH_CONNECTOR_PAGE_TRACKING_ENABLED = 'connector_configuration/tracking/page_enabled';
210
+
211
+ /**
212
+ * OAUTH
213
+ */
214
+ const API_CONNECTOR_OAUTH_URL = 'https://my.dotmailer.com/';
215
+ const API_CONNECTOR_OAUTH_URL_AUTHORISE = 'OAuth2/authorise.aspx?';
216
+ const API_CONNECTOR_OAUTH_URL_TOKEN = 'OAuth2/Tokens.ashx';
217
+ const API_CONNECTOR_OAUTH_URL_LOG_USER = '?oauthtoken=';
218
+
219
+ const CONNECTOR_FEED_LAST_CHECK_TIME = 'connector_feed_last_check_time';
220
+
221
+ /**
222
+ * Reviews SECTION
223
+ */
224
+ const XML_PATH_REVIEWS_ENABLED = 'connector_automation_studio/review_settings/enabled';
225
+ const XML_PATH_REVIEWS_FEEFO_LOGON = 'connector_automation_studio/feefo_feedback_engine/logon';
226
+ const XML_PATH_REVIEWS_FEEFO_REVIEWS = 'connector_automation_studio/feefo_feedback_engine/reviews_per_product';
227
+ const XML_PATH_REVIEWS_FEEFO_TEMPLATE = 'connector_automation_studio/feefo_feedback_engine/template';
228
+
229
+
230
+ /**
231
+ * Developer SECTION.
232
+ */
233
+ const XML_PATH_CONNECTOR_FEED_URL = 'connector_developer_settings/feed_configuration/feed_url';
234
+ const XML_PATH_CONNECTOR_CLIENT_ID = 'connector_developer_settings/oauth/client_id';
235
+ const XML_PATH_CONNECTOR_SYNC_LIMIT = 'connector_developer_settings/import_settings/batch_size';
236
+ const XML_PATH_CONNECTOR_FEED_ENABLED = 'connector_developer_settings/feed_configuration/feed_enabled';
237
+ const XML_PATH_RAYGUN_APPLICATION_CODE = 'connector_developer_settings/debug/raygun_code';
238
+ const XML_PATH_CONNECTOR_CUSTOM_DOMAIN = 'connector_developer_settings/oauth/custom_domain';
239
+ const XML_PATH_CONNECTOR_FEED_FREQUENCY = 'connector_developer_settings/feed_configuration/frequency';
240
+ const XML_PATH_RAYGUN_APPLICATION_ASYNC = 'connector_developer_settings/debug/raygun_async';
241
+ const XML_PATH_CONNECTOR_FEED_USE_HTTPS = 'connector_developer_settings/feed_configuration/use_https';
242
+ const XML_PATH_CONNECTOR_SETUP_DATAFIELDS = 'connector_developer_settings/sync_settings/setup_data_fields';
243
+ const XML_PATH_CONNECTOR_CLIENT_SECRET_ID = 'connector_developer_settings/oauth/client_key';
244
+ const XML_PATH_CONNECTOR_CUSTOM_AUTHORIZATION = 'connector_developer_settings/oauth/custom_authorization';
245
+ const XML_PATH_CONNECTOR_RESOURCE_ALLOCATION = 'connector_developer_settings/import_settings/memory_limit';
246
+ const XML_PATH_CONNECTOR_ADVANCED_DEBUG_ENABLED = 'connector_developer_settings/debug/debug_enabled';
247
+ const XML_PATH_CONNECTOR_DEBUG_API_REQUEST_LIMIT = 'connector_developer_settings/debug/api_request_time_limit';
248
+ const XML_PATH_CONNECTOR_TRANSACTIONAL_DATA_SYNC_LIMIT = 'connector_developer_settings/import_settings/orders';
249
+ const XML_PATH_CONNECTOR_IP_RESTRICTION_ADDRESSES = 'connector_developer_settings/ip_restriction/ip_addresses';
250
+
251
+ /**
252
+ * Nosto
253
+ */
254
+ const API_ENDPOINT = 'https://api.nosto.com';
255
+ const API_ENDPOINT_TEST = 'https://test.api.nosto.com';
256
+
257
+ const RAYGUN_API_CODE_URL = 'https://dotmailerformagento.co.uk/magento/raygun.xml';
258
+
259
+
260
+ /**
261
+ * @param int $website
262
+ *
263
+ * @return bool
264
+ * @throws Mage_Core_Exception
265
+ */
266
+ public function getAuthorizeLinkFlag($website = 0)
267
+ {
268
+ $website = Mage::app()->getWebsite($website);
269
+
270
+ $customDomain = $website->getConfig(self::XML_PATH_CONNECTOR_CUSTOM_DOMAIN);
271
+
272
+ return (bool)$customDomain;
273
+ }
274
+
275
+ /**
276
+ * @param int $website
277
+ *
278
+ * @return string
279
+ * @throws Mage_Core_Exception
280
+ */
281
+ public function getAuthorizeLink($website = 0)
282
+ {
283
+ //base url, check for custom oauth domain
284
+ if ($this->getAuthorizeLinkFlag($website)){
285
+ $website = Mage::app()->getWebsite($website);
286
+
287
+ $baseUrl = $website->getConfig(self::XML_PATH_CONNECTOR_CUSTOM_DOMAIN) . self::API_CONNECTOR_OAUTH_URL_AUTHORISE;
288
+
289
+ } else {
290
+ $baseUrl = self::API_CONNECTOR_OAUTH_URL . self::API_CONNECTOR_OAUTH_URL_AUTHORISE;
291
+ }
292
+
293
+ return $baseUrl;
294
+ }
295
+
296
+ /**
297
+ * Callback authorization url.
298
+ * @return mixed|string
299
+ */
300
+ public function getCallbackUrl()
301
+ {
302
+ if ($callback = Mage::getStoreConfig(self::XML_PATH_CONNECTOR_CUSTOM_AUTHORIZATION)){
303
+ return $callback;
304
+ }
305
+
306
+ return $redirectUri = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB, true);
307
+ }
308
+
309
+ /**
310
+ * @param int $website
311
+ *
312
+ * @return string
313
+ */
314
+ public function getTokenUrl($website = 0)
315
+ {
316
+ if ($this->getAuthorizeLinkFlag($website)) {
317
+ $website = Mage::app()->getWebsite($website);
318
+
319
+ $tokenUrl = $website->getConfig(self::XML_PATH_CONNECTOR_CUSTOM_DOMAIN) . self::API_CONNECTOR_OAUTH_URL_TOKEN;
320
+ } else {
321
+
322
+ $tokenUrl = self::API_CONNECTOR_OAUTH_URL . self::API_CONNECTOR_OAUTH_URL_TOKEN;
323
+ }
324
+
325
+ return $tokenUrl;
326
+ }
327
+
328
+
329
+ /**
330
+ * @param int $website
331
+ *
332
+ * @return string
333
+ */
334
+ public function getLogUserUrl( $website = 0 )
335
+ {
336
+ if ($this->getAuthorizeLinkFlag($website)) {
337
+ $website = Mage::app()->getWebsite($website);
338
+
339
+ $logUserUrl = $website->getConfig(self::XML_PATH_CONNECTOR_CUSTOM_DOMAIN) . self::API_CONNECTOR_OAUTH_URL_LOG_USER;
340
+ } else {
341
+
342
+ $logUserUrl = self::API_CONNECTOR_OAUTH_URL . self::API_CONNECTOR_OAUTH_URL_LOG_USER;
343
+ }
344
+ return $logUserUrl;
345
+ }
346
+
347
+ }
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,937 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ return $this;
76
+ }
77
+
78
+ public function getDebugEnabled()
79
+ {
80
+ return (bool) Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_ADVANCED_DEBUG_ENABLED);
81
+ }
82
+
83
+ /**
84
+ * Extension version number.
85
+ * @return string
86
+ */
87
+ public function getConnectorVersion()
88
+ {
89
+ $modules = (array) Mage::getConfig()->getNode('modules')->children();
90
+ if (isset($modules['Dotdigitalgroup_Email'])) {
91
+ $moduleName = $modules['Dotdigitalgroup_Email'];
92
+ return (string) $moduleName->version;
93
+ }
94
+ return '';
95
+ }
96
+
97
+
98
+ public function getPageTrackingEnabled()
99
+ {
100
+ return (bool)Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_PAGE_TRACKING_ENABLED);
101
+ }
102
+
103
+ public function getRoiTrackingEnabled()
104
+ {
105
+ return (bool)Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_ROI_TRACKING_ENABLED);
106
+ }
107
+
108
+ public function getResourceAllocationEnabled()
109
+ {
110
+ return (bool)Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_RESOURCE_ALLOCATION);
111
+ }
112
+
113
+ public function getMappedStoreName($website)
114
+ {
115
+ $mapped = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_CUSTOMER_STORENAME);
116
+ $storeName = ($mapped)? $mapped : '';
117
+ return $storeName;
118
+ }
119
+
120
+ /**
121
+ * Get the contact id for the custoemer based on website id.
122
+ * @param $email
123
+ * @param $websiteId
124
+ *
125
+ * @return bool
126
+ */
127
+ public function getContactId($email, $websiteId)
128
+ {
129
+ $contact = Mage::getModel('ddg_automation/contact')->loadByCustomerEmail($email, $websiteId);
130
+ if ($contactId = $contact->getContactId()) {
131
+ return $contactId;
132
+ }
133
+
134
+ $client = $this->getWebsiteApiClient($websiteId);
135
+ $response = $client->postContacts($email);
136
+
137
+ if (isset($response->message))
138
+ return false;
139
+ //save contact id
140
+ if (isset($response->id)){
141
+ $contact->setContactId($response->id)
142
+ ->save();
143
+ }
144
+ return $response->id;
145
+ }
146
+
147
+ public function getCustomerAddressBook($website)
148
+ {
149
+ $website = Mage::app()->getWebsite($website);
150
+ return $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMERS_ADDRESS_BOOK_ID);
151
+ }
152
+
153
+ public function getSubscriberAddressBook($website)
154
+ {
155
+ $website = Mage::app()->getWebsite($website);
156
+ return $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SUBSCRIBERS_ADDRESS_BOOK_ID);
157
+ }
158
+
159
+ public function getGuestAddressBook($website)
160
+ {
161
+ $website = Mage::app()->getWebsite($website);
162
+ return $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_GUEST_ADDRESS_BOOK_ID);
163
+ }
164
+
165
+ /**
166
+ * @return $this
167
+ */
168
+ public function allowResourceFullExecution()
169
+ {
170
+ if ($this->getResourceAllocationEnabled()) {
171
+
172
+ /* it may be needed to set maximum execution time of the script to longer,
173
+ * like 60 minutes than usual */
174
+ set_time_limit(7200);
175
+
176
+ /* and memory to 512 megabytes */
177
+ ini_set('memory_limit', '512M');
178
+ }
179
+ return $this;
180
+ }
181
+ public function convert($size)
182
+ {
183
+ $unit=array('b','kb','mb','gb','tb','pb');
184
+ return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i];
185
+ }
186
+
187
+ /**
188
+ * @return string
189
+ */
190
+ public function getStringWebsiteApiAccounts()
191
+ {
192
+ $accounts = array();
193
+ foreach (Mage::app()->getWebsites() as $website) {
194
+ $websiteId = $website->getId();
195
+ $apiUsername = $this->getApiUsername($website);
196
+ $accounts[$apiUsername] = $apiUsername . ', websiteId: ' . $websiteId . ' name ' . $website->getName();
197
+ }
198
+ return implode('</br>', $accounts);
199
+ }
200
+
201
+ /**
202
+ * @param int $website
203
+ *
204
+ * @return array|mixed
205
+ * @throws Mage_Core_Exception
206
+ */
207
+ public function getCustomAttributes($website = 0)
208
+ {
209
+ $website = Mage::app()->getWebsite($website);
210
+ $attr = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_CUSTOM_DATAFIELDS);
211
+
212
+ if (!$attr)
213
+ return array();
214
+
215
+ return unserialize($attr);
216
+ }
217
+
218
+
219
+ /**
220
+ * Enterprise custom datafields attributes.
221
+ * @param int $website
222
+ *
223
+ * @return array
224
+ * @throws Mage_Core_Exception
225
+ */
226
+ public function getEnterpriseAttributes( $website = 0) {
227
+ $website = Mage::app()->getWebsite($website);
228
+ $result = array();
229
+ $attrs = $website->getConfig('connector_data_mapping/enterprise_data');
230
+
231
+ if(is_array($attrs)){
232
+ //get individual mapped keys
233
+ foreach ( $attrs as $key => $one ) {
234
+ $config = $website->getConfig('connector_data_mapping/enterprise_data/' . $key);
235
+ //check for the mapped field
236
+ if ($config)
237
+ $result[$key] = $config;
238
+ }
239
+ }
240
+
241
+ if (empty($result))
242
+ return false;
243
+ return $result;
244
+ }
245
+
246
+ /**
247
+ * @param $path
248
+ * @param null|string|bool|int|Mage_Core_Model_Website $websiteId
249
+ * @return mixed
250
+ */
251
+ public function getWebsiteConfig($path, $websiteId = 0)
252
+ {
253
+ $website = Mage::app()->getWebsite($websiteId);
254
+ return $website->getConfig($path);
255
+ }
256
+
257
+ /**
258
+ * Api client by website.
259
+ *
260
+ * @param mixed $website
261
+ *
262
+ * @return bool|Dotdigitalgroup_Email_Model_Apiconnector_Client
263
+ */
264
+ public function getWebsiteApiClient($website = 0)
265
+ {
266
+ if(!$this->isEnabled($website))
267
+ return false;
268
+
269
+ if (! $apiUsername = $this->getApiUsername($website) || ! $apiPassword = $this->getApiPassword($website))
270
+ return false;
271
+
272
+ $client = Mage::getModel('ddg_automation/apiconnector_client');
273
+ $client->setApiUsername($this->getApiUsername($website))
274
+ ->setApiPassword($this->getApiPassword($website));
275
+
276
+ return $client;
277
+ }
278
+
279
+ /**
280
+ * Retrieve authorisation code.
281
+ */
282
+ public function getCode()
283
+ {
284
+ $adminUser = Mage::getSingleton('admin/session')->getUser();
285
+ $code = $adminUser->getEmailCode();
286
+
287
+ return $code;
288
+ }
289
+
290
+ /**
291
+ * Autorisation url for OAUTH.
292
+ * @return string
293
+ */
294
+ public function getAuthoriseUrl()
295
+ {
296
+ $clientId = Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CLIENT_ID);
297
+
298
+ //callback uri if not set custom
299
+ $redirectUri = $this->getRedirectUri();
300
+ $redirectUri .= 'connector/email/callback';
301
+ $adminUser = Mage::getSingleton('admin/session')->getUser();
302
+ //query params
303
+ $params = array(
304
+ 'redirect_uri' => $redirectUri,
305
+ 'scope' => 'Account',
306
+ 'state' => $adminUser->getId(),
307
+ 'response_type' => 'code'
308
+ );
309
+
310
+ $authorizeBaseUrl = Mage::helper('ddg/config')->getAuthorizeLink();
311
+ $url = $authorizeBaseUrl . http_build_query($params) . '&client_id=' . $clientId;
312
+
313
+ return $url;
314
+ }
315
+
316
+ public function getRedirectUri()
317
+ {
318
+ $callback = Mage::helper('ddg/config')->getCallbackUrl();
319
+
320
+ return $callback;
321
+ }
322
+
323
+ /**
324
+ * order status config value
325
+ * @param int $website
326
+ * @return mixed order status
327
+ */
328
+ public function getConfigSelectedStatus($website = 0)
329
+ {
330
+ $status = $this->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_ORDER_STATUS, $website);
331
+ if($status)
332
+ return explode(',',$status);
333
+ else
334
+ return false;
335
+ }
336
+
337
+ public function getConfigSelectedCustomOrderAttributes($website = 0)
338
+ {
339
+ $customAttributes = $this->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOM_ORDER_ATTRIBUTES, $website);
340
+ if($customAttributes)
341
+ return explode(',',$customAttributes);
342
+ else
343
+ return false;
344
+ }
345
+
346
+ public function getConfigSelectedCustomQuoteAttributes($website = 0)
347
+ {
348
+ $customAttributes = $this->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOM_QUOTE_ATTRIBUTES, $website);
349
+ if($customAttributes)
350
+ return explode(',',$customAttributes);
351
+ else
352
+ return false;
353
+ }
354
+
355
+ /**
356
+ * check sweet tooth installed/active status
357
+ * @return boolean
358
+ */
359
+ public function isSweetToothEnabled()
360
+ {
361
+ return (bool)Mage::getConfig()->getModuleConfig('TBT_Rewards')->is('active', 'true');
362
+ }
363
+
364
+ /**
365
+ * check sweet tooth installed/active status and active status
366
+ * @param Mage_Core_Model_Website $website
367
+ * @return boolean
368
+ */
369
+ public function isSweetToothToGo($website)
370
+ {
371
+ $stMappingStatus = $this->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_MAPPING_SWEETTOOTH_ACTIVE, $website);
372
+ if($stMappingStatus && $this->isSweetToothEnabled()) return true;
373
+ return false;
374
+ }
375
+
376
+ public function setConnectorContactToReImport($customerId)
377
+ {
378
+ try {
379
+ $coreResource = Mage::getSingleton('core/resource');
380
+ $con = $coreResource->getConnection('core_write');
381
+ $con->update(
382
+ $coreResource->getTableName('ddg_automation/contact'),
383
+ array('email_imported' => new Zend_Db_Expr('null')),
384
+ array("customer_id = ?" => $customerId)
385
+ );
386
+ } catch (Exception $e) {
387
+ Mage::logException($e);
388
+ }
389
+ }
390
+
391
+ /**
392
+ * Diff between to times;
393
+ *
394
+ * @param $time1
395
+ * @param $time2
396
+ * @return int
397
+ */
398
+ public function dateDiff($time1, $time2=NULL) {
399
+ if (is_null($time2)) {
400
+ $time2 = Mage::getModel('core/date')->date();
401
+ }
402
+ $time1 = strtotime($time1);
403
+ $time2 = strtotime($time2);
404
+ return $time2 - $time1;
405
+ }
406
+
407
+
408
+ /**
409
+ * Disable website config when the request is made admin area only!
410
+ * @param $path
411
+ *
412
+ * @throws Mage_Core_Exception
413
+ */
414
+ public function disableConfigForWebsite($path)
415
+ {
416
+ $scopeId = 0;
417
+ if ($website = Mage::app()->getRequest()->getParam('website')) {
418
+ $scope = 'websites';
419
+ $scopeId = Mage::app()->getWebsite($website)->getId();
420
+ } else {
421
+ $scope = "default";
422
+ }
423
+ $config = Mage::getConfig();
424
+ $config->saveConfig($path, 0, $scope, $scopeId);
425
+ $config->cleanCache();
426
+ }
427
+
428
+ /**
429
+ * number of customers with duplicate emails, emails as total number
430
+ * @return Mage_Customer_Model_Resource_Customer_Collection
431
+ */
432
+ public function getCustomersWithDuplicateEmails( ) {
433
+ $customers = Mage::getModel('customer/customer')->getCollection();
434
+
435
+ //duplicate emails
436
+ $customers->getSelect()
437
+ ->columns(array('emails' => 'COUNT(e.entity_id)'))
438
+ ->group('email')
439
+ ->having('emails > ?', 1);
440
+
441
+ return $customers;
442
+ }
443
+
444
+ /**
445
+ * Create new raygun client.
446
+ *
447
+ * @return bool|\Raygun4php\RaygunClient
448
+ */
449
+ public function getRaygunClient()
450
+ {
451
+ $code = Mage::getstoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_RAYGUN_APPLICATION_CODE);
452
+
453
+ if ($this->raygunEnabled()) {
454
+ //use async mode for sending.
455
+ $async = Mage::getStoreConfigFlag(Dotdigitalgroup_Email_Helper_Config::XML_PATH_RAYGUN_APPLICATION_ASYNC);
456
+ require_once Mage::getBaseDir('lib') . DS . 'Raygun4php' . DS . 'RaygunClient.php';
457
+ return new Raygun4php\RaygunClient($code, $async);
458
+ }
459
+
460
+ return false;
461
+ }
462
+
463
+ /**
464
+ * Raygun logs.
465
+ * @param $message
466
+ * @param string $filename
467
+ * @param int $line
468
+ * @param array $tags
469
+ *
470
+ * @return int|null
471
+ */
472
+ public function rayLog($message, $filename = 'apiconnector/client.php', $line = 1, $tags = array())
473
+ {
474
+ //check if raygun has code enabled
475
+ if (!$this->raygunEnabled())
476
+ return;
477
+
478
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
479
+
480
+ if (empty($tags)) {
481
+ $tags = array(
482
+ $baseUrl,
483
+ Mage::getVersion()
484
+ );
485
+ }
486
+
487
+ $client = $this->getRaygunClient();
488
+ //user, firstname, lastname, email, annonim, uuid
489
+ $client->SetUser($baseUrl, null, null, $this->getApiUsername());
490
+ $client->SetVersion($this->getConnectorVersion());
491
+ $client->SendError(100, $message, $filename,$line, $tags);
492
+ }
493
+
494
+
495
+ /**
496
+ * check for raygun application and if enabled.
497
+ * @param int $websiteId
498
+ *
499
+ * @return mixed
500
+ * @throws Mage_Core_Exception
501
+ */
502
+ public function raygunEnabled($websiteId = 0)
503
+ {
504
+ $website = Mage::app()->getWebsite($websiteId);
505
+
506
+ return (bool)$website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_RAYGUN_APPLICATION_CODE);
507
+
508
+ }
509
+
510
+ /**
511
+ * Generate the baseurl for the default store
512
+ * dynamic content will be displayed
513
+ * @return string
514
+ * @throws Mage_Core_Exception
515
+ */
516
+ public function generateDynamicUrl()
517
+ {
518
+ $website = Mage::app()->getRequest()->getParam('website', false);
519
+
520
+ //set website url for the default store id
521
+ $website = ($website)? Mage::app()->getWebsite( $website ) : 0;
522
+
523
+ $defaultGroup = Mage::app()->getWebsite($website)
524
+ ->getDefaultGroup();
525
+
526
+ if (! $defaultGroup)
527
+ return $mage = Mage::app()->getStore()->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
528
+
529
+ //base url
530
+ $baseUrl = Mage::app()->getStore($defaultGroup->getDefaultStore())->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
531
+
532
+ return $baseUrl;
533
+
534
+ }
535
+
536
+ /**
537
+ *
538
+ *
539
+ * @param int $store
540
+ * @return mixed
541
+ */
542
+ public function isNewsletterSuccessDisabled($store = 0)
543
+ {
544
+ return Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DISABLE_NEWSLETTER_SUCCESS, $store);
545
+ }
546
+
547
+ /**
548
+ * @return bool
549
+ */
550
+ public function getEasyEmailCapture()
551
+ {
552
+ return Mage::getStoreConfigFlag(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_EMAIL_CAPTURE);
553
+ }
554
+
555
+ /**
556
+ * @return bool
557
+ */
558
+ public function getEasyEmailCaptureForNewsletter()
559
+ {
560
+ return Mage::getStoreConfigFlag(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_EMAIL_CAPTURE_NEWSLETTER);
561
+ }
562
+ /**
563
+ * get feefo logon config value
564
+ *
565
+ * @return mixed
566
+ */
567
+ public function getFeefoLogon()
568
+ {
569
+ return $this->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_REVIEWS_FEEFO_LOGON);
570
+ }
571
+
572
+ /**
573
+ * get feefo reviews limit config value
574
+ *
575
+ * @return mixed
576
+ */
577
+ public function getFeefoReviewsPerProduct()
578
+ {
579
+ return $this->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_REVIEWS_FEEFO_REVIEWS);
580
+ }
581
+
582
+ /**
583
+ * get feefo logo template config value
584
+ *
585
+ * @return mixed
586
+ */
587
+ public function getFeefoLogoTemplate()
588
+ {
589
+ return $this->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_REVIEWS_FEEFO_TEMPLATE);
590
+ }
591
+
592
+ /**
593
+ * update data fields
594
+ *
595
+ * @param $email
596
+ * @param Mage_Core_Model_Website $website
597
+ * @param $storeName
598
+ */
599
+ public function updateDataFields($email, Mage_Core_Model_Website $website, $storeName)
600
+ {
601
+ $data = array();
602
+ if($store_name = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_STORE_NAME)){
603
+ $data[] = array(
604
+ 'Key' => $store_name,
605
+ 'Value' => $storeName
606
+ );
607
+ }
608
+ if($website_name = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_WEBSITE_NAME)){
609
+ $data[] = array(
610
+ 'Key' => $website_name,
611
+ 'Value' => $website->getName()
612
+ );
613
+ }
614
+ if(!empty($data)){
615
+ //update data fields
616
+ $client = $this->getWebsiteApiClient($website);
617
+ $client->updateContactDatafieldsByEmail($email, $data);
618
+ }
619
+ }
620
+
621
+ /**
622
+ * check connector SMTP installed/active status
623
+ * @return boolean
624
+ */
625
+ public function isSmtpEnabled()
626
+ {
627
+ return (bool)Mage::getConfig()->getModuleConfig('Ddg_Transactional')->is('active', 'true');
628
+ }
629
+
630
+ /**
631
+ * Is magento enterprise.
632
+ * @return bool
633
+ */
634
+ public function isEnterprise()
635
+ {
636
+ return Mage::getConfig ()->getModuleConfig ( 'Enterprise_Enterprise' ) && Mage::getConfig ()->getModuleConfig ( 'Enterprise_AdminGws' ) && Mage::getConfig ()->getModuleConfig ( 'Enterprise_Checkout' ) && Mage::getConfig ()->getModuleConfig ( 'Enterprise_Customer' );
637
+
638
+ }
639
+
640
+ public function getTemplateList()
641
+ {
642
+ $client = $this->getWebsiteApiClient(Mage::app()->getWebsite());
643
+ if(!$client)
644
+ return array();
645
+
646
+ $templates = $client->getApiTemplateList();
647
+ $fields[] = array('value' => '', 'label' => '');
648
+ foreach ( $templates as $one ) {
649
+ if ( isset( $one->id ) ) {
650
+ $fields[] = array(
651
+ 'value' => $one->id,
652
+ 'label' => $this->__( addslashes( $one->name ) )
653
+ );
654
+ }
655
+ }
656
+ return $fields;
657
+ }
658
+
659
+ /**
660
+ * Update last quote id datafield.
661
+ * @param $quoteId
662
+ * @param $email
663
+ * @param $websiteId
664
+ */
665
+ public function updateLastQuoteId($quoteId, $email, $websiteId)
666
+ {
667
+ $client = $this->getWebsiteApiClient($websiteId);
668
+ //last quote id config data mapped
669
+ $quoteIdField = $this->getLastQuoteId();
670
+
671
+ $data[] = array(
672
+ 'Key' => $quoteIdField,
673
+ 'Value' => $quoteId
674
+ );
675
+ //update datafields for conctact
676
+ $client->updateContactDatafieldsByEmail($email, $data);
677
+ }
678
+
679
+ /**
680
+ * Remove code and disable Raygun.
681
+ */
682
+ public function disableRaygun()
683
+ {
684
+ $config = Mage::getModel('core/config');
685
+ $config->saveConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_RAYGUN_APPLICATION_CODE, '');
686
+ Mage::getConfig()->cleanCache();
687
+ }
688
+
689
+ public function enableRaygunCode()
690
+ {
691
+ $curl = new Varien_Http_Adapter_Curl();
692
+ $curl->setConfig(array(
693
+ 'timeout' => 2
694
+ ));
695
+ $curl->write(Zend_Http_Client::GET, Dotdigitalgroup_Email_Helper_Config::RAYGUN_API_CODE_URL, '1.0');
696
+ $data = $curl->read();
697
+
698
+ if ($data === false) {
699
+ return false;
700
+ }
701
+ $data = preg_split('/^\r?$/m', $data, 2);
702
+ $data = trim($data[1]);
703
+ $curl->close();
704
+
705
+ $xml = new SimpleXMLElement($data);
706
+ $raygunCode = $xml->code;
707
+
708
+ //not found
709
+ if (!$raygunCode)
710
+ return;
711
+
712
+ $config = Mage::getModel('core/config');
713
+ $config->saveConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_RAYGUN_APPLICATION_CODE, $raygunCode);
714
+ }
715
+
716
+ /**
717
+ * Send the exception to raygun.
718
+ *
719
+ * @param $e Exception
720
+ */
721
+ public function sendRaygunException( $e )
722
+ {
723
+ if (!$this->raygunEnabled())
724
+ return;
725
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
726
+ $tags = array(
727
+ $baseUrl,
728
+ Mage::getVersion()
729
+ );
730
+
731
+ $client = $this->getRaygunClient();
732
+ //user, firstname, lastname, email, annonim, uuid
733
+ $client->SetUser($baseUrl, null, null, $this->getApiUsername());
734
+ $client->SetVersion($this->getConnectorVersion());
735
+ $client->SendException($e, $tags);
736
+ }
737
+
738
+ /**
739
+ * @param int $websiteId
740
+ *
741
+ * @return bool
742
+ */
743
+ public function getOrderSyncEnabled($websiteId = 0)
744
+ {
745
+ return Mage::getStoreConfigFlag(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_ORDER_ENABLED, $websiteId);
746
+ }
747
+ /**
748
+ * @param int $websiteId
749
+ *
750
+ * @return bool
751
+ */
752
+ public function getCatalogSyncEnabled($websiteId = 0)
753
+ {
754
+ return Mage::getStoreConfigFlag(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_CATALOG_ENABLED, $websiteId);
755
+ }
756
+
757
+ /**
758
+ * @param int $websiteId
759
+ *
760
+ * @return bool
761
+ */
762
+ public function getContactSyncEnabled($websiteId = 0)
763
+ {
764
+ return Mage::getStoreConfigFlag(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_CONTACT_ENABLED, $websiteId);
765
+ }
766
+
767
+ /**
768
+ * @param int $websiteId
769
+ *
770
+ * @return bool
771
+ */
772
+ public function getGuestSyncEnabled($websiteId = 0)
773
+ {
774
+ return Mage::getStoreConfigFlag(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_GUEST_ENABLED, $websiteId);
775
+ }
776
+
777
+ /**
778
+ * @param int $websiteId
779
+ *
780
+ * @return bool
781
+ */
782
+ public function getSubscriberSyncEnabled($websiteId = 0)
783
+ {
784
+ return Mage::getStoreConfigFlag(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_SUBSCRIBER_ENABLED, $websiteId);
785
+ }
786
+
787
+ /**
788
+ * @return bool
789
+ */
790
+ public function getCronInstalled()
791
+ {
792
+ $lastCustomerSync = Mage::getModel('ddg_automation/cron')->getLastCustomerSync();
793
+ $timespan = Mage::helper('ddg')->dateDiff($lastCustomerSync);
794
+
795
+ //last customer cron was less then 15 min
796
+ if ($timespan <= 15 * 60) {
797
+ return true;
798
+ }
799
+ return false;
800
+ }
801
+ /**
802
+ * Get the config id by the automation type.
803
+ * @param $automationType
804
+ * @param int $websiteId
805
+ *
806
+ * @return mixed
807
+ */
808
+ public function getAutomationIdByType($automationType, $websiteId = 0)
809
+ {
810
+ $path = constant('Dotdigitalgroup_Email_Helper_Config::' . $automationType);
811
+ $automationCampaignId = $this->getWebsiteConfig($path, $websiteId);
812
+
813
+ return $automationCampaignId;
814
+ }
815
+
816
+ public function getAbandonedProductName()
817
+ {
818
+ return Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_ABANDONED_PRODUCT_NAME);
819
+
820
+ }
821
+
822
+ /**
823
+ * Update last quote id datafield.
824
+ * @param $name
825
+ * @param $email
826
+ * @param $websiteId
827
+ */
828
+ public function updateAbandonedProductName($name, $email, $websiteId)
829
+ {
830
+ $client = $this->getWebsiteApiClient($websiteId);
831
+ // id config data mapped
832
+ $field = $this->getAbandonedProductName();
833
+
834
+ if ($field) {
835
+ $data[] = array(
836
+ 'Key' => $field,
837
+ 'Value' => $name
838
+ );
839
+ //update data field for contact
840
+ $client->updateContactDatafieldsByEmail($email, $data);
841
+ }
842
+ }
843
+
844
+
845
+ /**
846
+ * Api request response time limit that should be logged.
847
+ *
848
+ * @param int $websiteId
849
+ *
850
+ * @return mixed
851
+ * @throws Mage_Core_Exception
852
+ */
853
+ public function getApiResponseTimeLimit($websiteId = 0)
854
+ {
855
+ $website = Mage::app()->getWebsite($websiteId);
856
+ $limit = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DEBUG_API_REQUEST_LIMIT);
857
+
858
+ return $limit;
859
+ }
860
+
861
+ /**
862
+ * Main email for an account.
863
+ *
864
+ * @param int $website
865
+ *
866
+ * @return string
867
+ */
868
+ public function getAccountEmail( $website = 0)
869
+ {
870
+ $client = $this->getWebsiteApiClient($website);
871
+ $info = $client->getAccountInfo();
872
+ $email = '';
873
+
874
+ if(isset($info->properties)){
875
+ $properties = $info->properties;
876
+
877
+ foreach ( $properties as $property ) {
878
+
879
+ if ($property->name == 'MainEmail')
880
+ $email = $property->value;
881
+ }
882
+ }
883
+ return $email;
884
+ }
885
+
886
+ public function authIpAddress()
887
+ {
888
+ if ($ipString = Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_IP_RESTRICTION_ADDRESSES)) {
889
+ //string to array
890
+ $ipArray = explode(',', $ipString);
891
+ //remove white spaces
892
+ foreach($ipArray as $key => $ip){
893
+ $ipArray[$key] = preg_replace('/\s+/', '', $ip);
894
+ }
895
+ //ip address
896
+ $ipAddress = Mage::helper('core/http')->getRemoteAddr();
897
+
898
+ if(in_array($ipAddress, $ipArray)) {
899
+ return true;
900
+ }
901
+
902
+ $this->getRaygunClient()->Send('Ip address auth failed with ip address :' . $ipAddress);
903
+ return false;
904
+ }
905
+ return false;
906
+ }
907
+
908
+ /**
909
+ * get log file content.
910
+ *
911
+ * @param string $filename
912
+ *
913
+ * @return string
914
+ */
915
+ public function getLogFileContent($filename = 'connector_api.log')
916
+ {
917
+ $path_to_log_file = Mage::getBaseDir('var') . DS . 'log' . DS . $filename;;
918
+ //tail the length file content
919
+ $lengthBefore = 500000;
920
+
921
+ $handle = fopen($path_to_log_file, 'r');
922
+ fseek($handle, -$lengthBefore, SEEK_END);
923
+
924
+ if (!$handle) {
925
+ return "Log file is not readable or does not exist at this moment. File path is ".$path_to_log_file;
926
+ }
927
+
928
+ $contents = fread($handle, filesize($path_to_log_file));
929
+
930
+ if (!$contents) {
931
+ return "Log file is not readable or does not exist at this moment. File path is ".$path_to_log_file;
932
+ }
933
+ fclose($handle);
934
+
935
+ return $contents;
936
+ }
937
+ }
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,59 @@ 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, 0775, 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
+ unset($mappedData['abandoned_prod_name']);
169
+
170
+ //enterprise datafields
171
+ if (Mage::helper('ddg')->isEnterprise()) {
172
+
173
+ $enterpriseMapping = Mage::helper( 'ddg' )->getEnterpriseAttributes( $website );
174
+ if ( $enterpriseMapping ) {
175
+ $mappedData = array_merge( $mappedData, $enterpriseMapping );
176
+ }
177
+ }
178
+
179
+ $mappedRewardData = $this->getWebsiteCustomerRewardMappingDatafields($website);
180
+ if($mappedRewardData) $mappedData = array_merge($mappedData, $mappedRewardData);
181
+
182
+ foreach ($mappedData as $key => $value) {
183
+ if (! $value)
184
+ unset($mappedData[$key]);
185
+ }
186
+
187
+ return $mappedData;
188
+ }
189
+
190
+ public function getWebsiteCustomerRewardMappingDatafields($website)
191
+ {
192
+ $helper = Mage::helper('ddg');
193
+ if($helper->isSweetToothToGo($website)) {
194
+ $store = $website->getDefaultStore();
195
+ $mappedData = Mage::getStoreConfig('connector_data_mapping/sweet_tooth', $store);
196
+ unset($mappedData['active']);
197
+ return $mappedData;
198
+ }
199
+ return false;
200
+ }
201
+
202
+ /**
203
+ * @param $path
204
+ *
205
+ * @return bool
206
+ */
207
+ public function getPathPermission($path) {
208
+
209
+ //check for directory created before looking into permission
210
+ if (is_dir($path)) {
211
+ clearstatcache( null, $path );
212
+
213
+ return decoct( fileperms( $path ) & 0777 );
214
+ }
215
+ //the file is not created and return the passing value
216
+ return 755;
217
+ }
218
  }
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/Helper/Transactional.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Helper_Transactional extends Mage_Core_Helper_Abstract
3
+ {
4
+
5
+ const XML_PATH_DDG_TRANSACTIONAL_ENABLED = 'connector_transactional_emails/ddg_transactional/enabled';
6
+ const XML_PATH_DDG_TRANSACTIONAL_HOST = 'connector_transactional_emails/ddg_transactional/host';
7
+ const XML_PATH_DDG_TRANSACTIONAL_USERNAME = 'connector_transactional_emails/ddg_transactional/username';
8
+ const XML_PATH_DDG_TRANSACTIONAL_PASSWORD = 'connector_transactional_emails/ddg_transactional/password';
9
+ const XML_PATH_DDG_TRANSACTIONAL_PORT = 'connector_transactional_emails/ddg_transactional/port';
10
+ const XML_PATH_DDG_TRANSACTIONAL_DEBUG = 'connector_transactional_emails/ddg_transactional/debug';
11
+
12
+
13
+ public function isEnabled()
14
+ {
15
+ return Mage::getStoreConfigFlag(self::XML_PATH_DDG_TRANSACTIONAL_ENABLED);
16
+
17
+ }
18
+ public function getSmtpHost()
19
+ {
20
+
21
+ return Mage::getStoreConfig(self::XML_PATH_DDG_TRANSACTIONAL_HOST);
22
+
23
+ }
24
+
25
+ public function getSmtpUsername()
26
+ {
27
+ return Mage::getStoreConfig(self::XML_PATH_DDG_TRANSACTIONAL_USERNAME);
28
+
29
+ }
30
+
31
+ public function getSmtpPassword()
32
+ {
33
+ return Mage::getStoreConfig(self::XML_PATH_DDG_TRANSACTIONAL_PASSWORD);
34
+
35
+ }
36
+
37
+ public function getSmtpPort()
38
+ {
39
+ return Mage::getStoreConfig(self::XML_PATH_DDG_TRANSACTIONAL_PORT);
40
+
41
+ }
42
+
43
+ public function isDebugEnabled()
44
+ {
45
+ return Mage::getStoreConfigFlag(self::XML_PATH_DDG_TRANSACTIONAL_DEBUG);
46
+ }
47
+
48
+
49
+ public function getTransport()
50
+ {
51
+ $config = array(
52
+ 'port' =>$this->getSmtpPort(),
53
+ 'auth' => 'login',
54
+ 'username' => $this->getSmtpUsername(),
55
+ 'password' => $this->getSmtpPassword(),
56
+ 'ssl' => 'tls'
57
+ );
58
+
59
+ if ($this->isDebugEnabled())
60
+ Mage::log('Mail transport config : '. implode(',', $config));
61
+
62
+ $transport = new Zend_Mail_Transport_Smtp($this->getSmtpHost(), $config);
63
+ return $transport;
64
+ }
65
+ }
app/code/community/Dotdigitalgroup/Email/Model/Abstract/Rest.php ADDED
@@ -0,0 +1,492 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ protected $curlError;
15
+ protected $isNotJson = false;
16
+
17
+ public function __construct($website = 0) // ($url = null, $verb = 'GET', $requestBody = null)
18
+ {
19
+ $this->url = null; //$url;
20
+ $this->verb = 'GET'; //$verb;
21
+ $this->requestBody = null; //$requestBody;
22
+ $this->requestLength = 0;
23
+ $this->_apiUsername = (string)Mage::helper('ddg')->getApiUsername($website);
24
+ $this->_apiPassword = (string)Mage::helper('ddg')->getApiPassword($website);
25
+ $this->acceptType = 'application/json';
26
+ $this->responseBody = null;
27
+ $this->responseInfo = null;
28
+
29
+ if ($this->requestBody !== null) {
30
+ $this->buildPostBody();
31
+ }
32
+ }
33
+
34
+ private function prettyPrint($json)
35
+ {
36
+ $result = '';
37
+ $level = 0;
38
+ $prev_char = '';
39
+ $in_quotes = false;
40
+ $ends_line_level = NULL;
41
+ $json_length = strlen( $json );
42
+
43
+ for ($i = 0; $i < $json_length; $i++) {
44
+ $char = $json[$i];
45
+ $new_line_level = NULL;
46
+ $post = "";
47
+ if ($ends_line_level !== NULL) {
48
+ $new_line_level = $ends_line_level;
49
+ $ends_line_level = NULL;
50
+ }
51
+ if ($char === '"' && $prev_char != '\\') {
52
+ $in_quotes = !$in_quotes;
53
+ } elseif (! $in_quotes) {
54
+ switch ($char) {
55
+ case '}': case ']':
56
+ $level--;
57
+ $ends_line_level = NULL;
58
+ $new_line_level = $level;
59
+ break;
60
+
61
+ case '{': case '[':
62
+ $level++;
63
+ case ',':
64
+ $ends_line_level = $level;
65
+ break;
66
+
67
+ case ':':
68
+ $post = " ";
69
+ break;
70
+
71
+ case " ": case "\t": case "\n": case "\r":
72
+ $char = "";
73
+ $ends_line_level = $new_line_level;
74
+ $new_line_level = NULL;
75
+ break;
76
+ }
77
+ }
78
+ if ($new_line_level !== NULL) {
79
+ $result .= "\n".str_repeat( "\t", $new_line_level );
80
+ }
81
+ $result .= $char.$post;
82
+ $prev_char = $char;
83
+ }
84
+
85
+ return $result;
86
+ }
87
+
88
+ /**
89
+ * returns the object as JSON.
90
+ *
91
+ * @param bool $pretty
92
+ *
93
+ * @return string
94
+ */
95
+ public function toJSON($pretty=false)
96
+ {
97
+
98
+ if (!$pretty) {
99
+ return json_encode($this->expose());
100
+ } else {
101
+ return $this->prettyPrint(json_encode($this->expose()));
102
+ }
103
+ }
104
+
105
+ /**
106
+ * exposes the class as an array of objects
107
+ * @return array
108
+ */
109
+ public function expose()
110
+ {
111
+
112
+ return get_object_vars($this);
113
+
114
+ }
115
+
116
+
117
+ /**
118
+ * Reset the client.
119
+ *
120
+ * @return $this
121
+ */
122
+ public function flush ()
123
+ {
124
+ $this->_apiUsername = '';
125
+ $this->_apiPassword = '';
126
+ $this->requestBody = null;
127
+ $this->requestLength = 0;
128
+ $this->verb = 'GET';
129
+ $this->responseBody = null;
130
+ $this->responseInfo = null;
131
+ return $this;
132
+ }
133
+
134
+ /**
135
+ * Execute the curl request.
136
+ *
137
+ * @return null
138
+ * @throws Exception
139
+ */
140
+ public function execute()
141
+ {
142
+ $ch = curl_init();
143
+ $this->setAuth($ch);
144
+ try
145
+ {
146
+ switch (strtoupper($this->verb))
147
+ {
148
+ case 'GET':
149
+ $this->executeGet($ch);
150
+ break;
151
+ case 'POST':
152
+ $this->executePost($ch);
153
+ break;
154
+ case 'PUT':
155
+ $this->executePut($ch);
156
+ break;
157
+ case 'DELETE':
158
+ $this->executeDelete($ch);
159
+ break;
160
+ default:
161
+ throw new InvalidArgumentException('Current verb (' . $this->verb . ') is an invalid REST verb.');
162
+ }
163
+ }catch (InvalidArgumentException $e){
164
+ curl_close($ch);
165
+ throw $e;
166
+ }catch (Exception $e){
167
+ curl_close($ch);
168
+ throw $e;
169
+ }
170
+
171
+ /**
172
+ * check and debug api request total time
173
+ */
174
+ if (Mage::helper('ddg')->getDebugEnabled()){
175
+ $info = $this->getResponseInfo();
176
+ //the response info data is set
177
+ if (isset($info['url']) && isset($info['total_time'])){
178
+ $url = $info['url'];
179
+ $time = $info['total_time'];
180
+ $totalTime = sprintf(' time : %g sec', $time);
181
+ $check = Mage::helper('ddg')->getApiResponseTimeLimit();
182
+ $limit = ($check)? $check : '2';
183
+ $message = $this->verb . ', ' . $url. $totalTime;
184
+ //check for slow queries
185
+ if ( $time > $limit) {
186
+ //log the slow queries
187
+ Mage::helper( 'ddg' )->log( $message )
188
+ ->rayLog($message);
189
+ }
190
+ }
191
+ }
192
+
193
+ return $this->responseBody;
194
+ }
195
+
196
+ /**
197
+ * Post data.
198
+ *
199
+ * @param null $data
200
+ *
201
+ * @return $this
202
+ */
203
+ public function buildPostBody($data = null)
204
+ {
205
+ $this->requestBody = json_encode($data);
206
+ return $this;
207
+ }
208
+
209
+ /**
210
+ * Execute curl get request.
211
+ *
212
+ * @param $ch
213
+ */
214
+ protected function executeGet($ch)
215
+ {
216
+ $this->doExecute($ch);
217
+ }
218
+
219
+ /**
220
+ * Execute post request.
221
+ *
222
+ * @param $ch
223
+ */
224
+ protected function executePost($ch)
225
+ {
226
+ if (!is_string($this->requestBody)) {
227
+ $this->buildPostBody();
228
+ }
229
+
230
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $this->requestBody);
231
+ curl_setopt($ch, CURLOPT_POST, true);
232
+
233
+ $this->doExecute($ch);
234
+ }
235
+
236
+ /**
237
+ * Post from the file.
238
+ *
239
+ * @param $filename
240
+ */
241
+ protected function buildPostBodyFromFile($filename)
242
+ {
243
+ $this->requestBody = array (
244
+ 'file' => '@'.$filename
245
+ );
246
+ }
247
+
248
+ /**
249
+ * Execute put.
250
+ *
251
+ * @param $ch
252
+ */
253
+ protected function executePut($ch)
254
+ {
255
+ if (!is_string($this->requestBody)) {
256
+ $this->buildPostBody();
257
+ }
258
+
259
+ $this->requestLength = strlen($this->requestBody);
260
+
261
+ $fh = fopen('php://memory', 'rw');
262
+ fwrite($fh, $this->requestBody);
263
+ rewind($fh);
264
+
265
+ curl_setopt($ch, CURLOPT_INFILE, $fh);
266
+ curl_setopt($ch, CURLOPT_INFILESIZE, $this->requestLength);
267
+ curl_setopt($ch, CURLOPT_PUT, true);
268
+
269
+ $this->doExecute($ch);
270
+
271
+ fclose($fh);
272
+ }
273
+
274
+ /**
275
+ * Ececute delete.
276
+ *
277
+ * @param $ch
278
+ */
279
+ protected function executeDelete($ch)
280
+ {
281
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
282
+
283
+ $this->doExecute($ch);
284
+ }
285
+
286
+ /**
287
+ * Execute request.
288
+ *
289
+ * @param $ch
290
+ */
291
+ protected function doExecute(&$ch)
292
+ {
293
+ $this->setCurlOpts($ch);
294
+
295
+ if($this->isNotJson)
296
+ $this->responseBody = curl_exec($ch);
297
+ else
298
+ $this->responseBody = json_decode(curl_exec($ch));
299
+
300
+ $this->responseInfo = curl_getinfo($ch);
301
+
302
+ //if curl error found
303
+ if(curl_errno($ch))
304
+ {
305
+ //save the error
306
+ $this->curlError = curl_error($ch);
307
+ }
308
+
309
+ curl_close($ch);
310
+ }
311
+
312
+ /**
313
+ * curl options.
314
+ *
315
+ * @param $ch
316
+ */
317
+ protected function setCurlOpts(&$ch)
318
+ {
319
+ curl_setopt($ch, CURLOPT_TIMEOUT, 10);
320
+ curl_setopt($ch, CURLOPT_URL, $this->url);
321
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
322
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
323
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
324
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array ('Accept: ' . $this->acceptType ,'Content-Type: application/json'));
325
+ }
326
+
327
+ /**
328
+ * basic auth.
329
+ *
330
+ * @param $ch
331
+ */
332
+ protected function setAuth(&$ch)
333
+ {
334
+ if ($this->_apiUsername !== null && $this->_apiPassword !== null)
335
+ {
336
+ curl_setopt($ch, CURLAUTH_BASIC, CURLAUTH_DIGEST);
337
+ curl_setopt($ch, CURLOPT_USERPWD, $this->_apiUsername . ':' . $this->_apiPassword);
338
+ }
339
+ }
340
+
341
+ /**
342
+ * Get accept type.
343
+ *
344
+ * @return string
345
+ */
346
+ public function getAcceptType()
347
+ {
348
+ return $this->acceptType;
349
+ }
350
+
351
+ /**
352
+ * set accept type.
353
+ *
354
+ * @param $acceptType
355
+ */
356
+ public function setAcceptType($acceptType)
357
+ {
358
+ $this->acceptType = $acceptType;
359
+ }
360
+
361
+
362
+ /**
363
+ * get api username.
364
+ *
365
+ * @return string
366
+ */
367
+ public function getApiUsername()
368
+ {
369
+ return $this->_apiUsername;
370
+ }
371
+
372
+ /**
373
+ * set api username.
374
+ *
375
+ * @param $apiUsername
376
+ *
377
+ * @return $this
378
+ */
379
+ public function setApiUsername($apiUsername)
380
+ {
381
+ $this->_apiUsername = $apiUsername;
382
+ return $this;
383
+ }
384
+ /**
385
+ * Get api password.
386
+ *
387
+ * @return string
388
+ */
389
+ public function getApiPassword()
390
+ {
391
+ return $this->_apiPassword;
392
+ }
393
+
394
+ /**
395
+ * set api password.
396
+ * @param $apiPassword
397
+ *
398
+ * @return $this
399
+ */
400
+ public function setApiPassword($apiPassword)
401
+ {
402
+ $this->_apiPassword = $apiPassword;
403
+ return $this;
404
+ }
405
+
406
+ /**
407
+ * get response body.
408
+ *
409
+ * @return string/object
410
+ */
411
+ public function getResponseBody()
412
+ {
413
+ return $this->responseBody;
414
+ }
415
+
416
+ /**
417
+ * get response info.
418
+ *
419
+ * @return null
420
+ */
421
+ public function getResponseInfo()
422
+ {
423
+ return $this->responseInfo;
424
+ }
425
+
426
+ /**
427
+ * get url.
428
+ *
429
+ * @return string
430
+ */
431
+ public function getUrl()
432
+ {
433
+ return $this->url;
434
+ }
435
+
436
+ /**
437
+ * set url.
438
+ *
439
+ * @param $url
440
+ *
441
+ * @return $this
442
+ */
443
+ public function setUrl($url)
444
+ {
445
+ $this->url = $url;
446
+ return $this;
447
+ }
448
+
449
+ /**
450
+ * get the verb.
451
+ *
452
+ * @return string
453
+ */
454
+ public function getVerb ()
455
+ {
456
+ return $this->verb;
457
+ }
458
+
459
+ /**
460
+ * set the verb.
461
+ *
462
+ * @param $verb
463
+ *
464
+ * @return $this
465
+ */
466
+ public function setVerb ($verb)
467
+ {
468
+ $this->verb = $verb;
469
+ return $this;
470
+ }
471
+
472
+ public function getCurlError()
473
+ {
474
+ //if curl error
475
+ if(!empty($this->curlError)){
476
+ //log curl error
477
+ $message = 'CURL ERROR '. $this->curlError;
478
+ Mage::helper('ddg')->log($message)
479
+ ->rayLog($message, 'apiconnector/rest.php', __LINE__);
480
+
481
+ return $this->curlError;
482
+ }
483
+
484
+ return false;
485
+ }
486
+
487
+ public function setIsNotJsonTrue()
488
+ {
489
+ $this->isNotJson = true;
490
+ return $this;
491
+ }
492
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Content.php ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
5
+ */
6
+ class Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Content
7
+ {
8
+
9
+ /**
10
+ * css style that can be used to alert based on result
11
+ * @var
12
+ */
13
+ public $style;
14
+
15
+ /**
16
+ * @return mixed
17
+ */
18
+ public function getTitle() {
19
+ return $this->title;
20
+ }
21
+
22
+ /**
23
+ * @param $title
24
+ *
25
+ * @return $this
26
+ */
27
+ public function setTitle( $title ) {
28
+ $this->title = $title;
29
+ return $this;
30
+ }
31
+
32
+ /**
33
+ * title to be displayed as a key for the status
34
+ * @var
35
+ */
36
+ public $title;
37
+
38
+ /**
39
+ * message to be displayd in the body
40
+ * @var
41
+ */
42
+ public $message;
43
+
44
+ /**
45
+ * how to fix message
46
+ * @var
47
+ */
48
+ public $howto = array();
49
+
50
+ /**
51
+ * @return mixed
52
+ */
53
+
54
+ /**
55
+ * table data
56
+ * @var
57
+ */
58
+ public $table = array();
59
+
60
+ public function getHowto() {
61
+ return $this->howto;
62
+ }
63
+
64
+ /**
65
+ * @param $howto
66
+ *
67
+ * @return $this
68
+ */
69
+ public function setHowto( $howto ) {
70
+ $this->howto[] = $howto;
71
+ return $this;
72
+ }
73
+
74
+ /**
75
+ * @return mixed
76
+ */
77
+ public function getMessage() {
78
+ return $this->message;
79
+ }
80
+
81
+ /**
82
+ * @param $message
83
+ *
84
+ * @return $this
85
+ */
86
+ public function setMessage( $message ) {
87
+ $this->message = $message;
88
+ return $this;
89
+ }
90
+
91
+ /**
92
+ * @return mixed
93
+ */
94
+ public function getStyle() {
95
+ return $this->style;
96
+ }
97
+
98
+ /**
99
+ * @param $style
100
+ *
101
+ * @return $this
102
+ */
103
+ public function setStyle( $style ) {
104
+ $this->style = $style;
105
+ return $this;
106
+ }
107
+
108
+ public function setTable($table)
109
+ {
110
+ $this->table[] = $table;
111
+ return $this;
112
+ }
113
+
114
+ public function getTable() {
115
+ return $this->table;
116
+ }
117
+
118
+
119
+
120
+
121
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Abandoned.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Tabs_Analysis_Abandoned extends Mage_Core_Model_Abstract
4
+ {
5
+ protected $storeIds;
6
+
7
+ /**
8
+ * prepare collection and needed columns
9
+ *
10
+ * @return Mage_Sales_Model_Resource_Quote_Collection
11
+ */
12
+ protected function getPreparedCollection()
13
+ {
14
+ $collection = Mage::getResourceModel('sales/quote_collection');
15
+ $collection
16
+ ->addFieldToFilter('items_count', array('neq' => '0'))
17
+ ->addFieldToFilter('main_table.is_active', '1')
18
+ ->setOrder('updated_at');
19
+
20
+ if (is_array($this->storeIds) && !empty($this->storeIds)) {
21
+ $collection->addFieldToFilter('store_id', array('in' => $this->storeIds));
22
+ }
23
+
24
+ $adapter = $collection->getConnection();
25
+ $averageExpr = $adapter->getCheckSql(
26
+ 'COUNT(main_table.entity_id) > 0',
27
+ 'SUM(main_table.subtotal)/COUNT(main_table.entity_id)',
28
+ 0);
29
+
30
+ $collection->getSelect()->columns(array(
31
+ 'lifetime' => 'SUM(main_table.subtotal)',
32
+ 'average' => $averageExpr,
33
+ 'total_count' => "COUNT(main_table.entity_id)",
34
+ 'day_count' => "ROUND(COUNT(main_table.entity_id) / DATEDIFF(date(MAX(main_table.updated_at)) , date(MIN(main_table.updated_at))), 2)"
35
+ ));
36
+ return $collection;
37
+ }
38
+
39
+ /**
40
+ * @param int $store
41
+ * @param int $website
42
+ * @param int $group
43
+ * @return Varien_Object
44
+ * @throws Mage_Core_Exception
45
+ */
46
+ public function getLifeTimeAbandoned($store = 0, $website = 0, $group =0)
47
+ {
48
+ if ($store) {
49
+ $this->storeIds = array($store => $store);
50
+ } else if ($website){
51
+ $storeIds = Mage::app()->getWebsite($website)->getStoreIds();
52
+ $this->storeIds = $storeIds;
53
+ } else if ($group){
54
+ $storeIds = Mage::app()->getGroup($group)->getStoreIds();
55
+ $this->storeIds = $storeIds;
56
+ }
57
+ return $this->getPreparedCollection()->getFirstItem();
58
+ }
59
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Customer.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Tabs_Analysis_Customer extends Mage_Core_Model_Abstract
4
+ {
5
+ protected $storeIds;
6
+
7
+ /**
8
+ * prepare collection and needed columns
9
+ *
10
+ * @return Mage_Customer_Model_Resource_Customer_Collection
11
+ */
12
+ protected function getPreparedCollection()
13
+ {
14
+ $collection = Mage::getResourceModel('customer/customer_collection');
15
+
16
+ if (is_array($this->storeIds) && !empty($this->storeIds)) {
17
+ $collection->addAttributeToFilter('store_id', array('in' => $this->storeIds));
18
+ }
19
+
20
+ $collection->getSelect()->columns(array(
21
+ 'total_count' => "COUNT(*)",
22
+ 'day_count' => "ROUND(COUNT(*) / DATEDIFF(date(MAX(created_at)) , date(MIN(created_at))), 2)"
23
+ ));
24
+
25
+ return $collection;
26
+ }
27
+
28
+ /**
29
+ * @param int $store
30
+ * @param int $website
31
+ * @param int $group
32
+ * @return Varien_Object
33
+ * @throws Mage_Core_Exception
34
+ */
35
+ public function getLifeTimeTimeCustomer($store = 0, $website = 0, $group =0)
36
+ {
37
+ if ($store) {
38
+ $this->storeIds = array($store => $store);
39
+ } else if ($website){
40
+ $storeIds = Mage::app()->getWebsite($website)->getStoreIds();
41
+ $this->storeIds = $storeIds;
42
+ } else if ($group){
43
+ $storeIds = Mage::app()->getGroup($group)->getStoreIds();
44
+ $this->storeIds = $storeIds;
45
+ }
46
+ return $this->getPreparedCollection()->setPageSize(1)->setCurPage(1)->getFirstItem();
47
+ }
48
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Orders.php ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Tabs_Analysis_Orders extends Mage_Core_Model_Abstract
4
+ {
5
+ /**
6
+ * calculate sales and prepare columns
7
+ *
8
+ * @param int $isFilter
9
+ * @return Mage_Reports_Model_Resource_Order_Collection
10
+ */
11
+ protected function calculateSales($isFilter = 0)
12
+ {
13
+ $collection = Mage::getResourceModel('reports/order_collection');
14
+
15
+ $statuses = Mage::getSingleton('sales/config')
16
+ ->getOrderStatusesForState(Mage_Sales_Model_Order::STATE_CANCELED);
17
+
18
+ if (empty($statuses)) {
19
+ $statuses = array(0);
20
+ }
21
+ $adapter = $collection->getConnection();
22
+
23
+ if (Mage::getStoreConfig('sales/dashboard/use_aggregated_data')) {
24
+ $collection->setMainTable('sales/order_aggregated_created');
25
+ $collection->removeAllFieldsFromSelect();
26
+ $averageExpr = $adapter->getCheckSql(
27
+ 'SUM(main_table.orders_count) > 0',
28
+ 'SUM(main_table.total_revenue_amount)/SUM(main_table.orders_count)',
29
+ 0);
30
+ $collection->getSelect()->columns(array(
31
+ 'lifetime' => 'SUM(main_table.total_revenue_amount)',
32
+ 'average' => $averageExpr,
33
+ 'total_count' => "SUM(main_table.orders_count)",
34
+ 'day_count' => "ROUND(SUM(main_table.orders_count) / DATEDIFF(date(MAX(period)) , date(MIN(period))), 2)"
35
+ ));
36
+
37
+ if (!$isFilter) {
38
+ $collection->addFieldToFilter('store_id',
39
+ array('eq' => Mage::app()->getStore(Mage_Core_Model_Store::ADMIN_CODE)->getId())
40
+ );
41
+ }
42
+ $collection->getSelect()->where('main_table.order_status NOT IN(?)', $statuses);
43
+ } else {
44
+ $collection->setMainTable('sales/order');
45
+ $collection->removeAllFieldsFromSelect();
46
+
47
+ $expr = Mage::getResourceModel('ddg_automation/contact')->getSalesAmountExpression($collection);
48
+
49
+ if ($isFilter == 0) {
50
+ $expr = '(' . $expr . ') * main_table.base_to_global_rate';
51
+ }
52
+
53
+ $collection->getSelect()
54
+ ->columns(array(
55
+ 'lifetime' => "SUM({$expr})",
56
+ 'average' => "AVG({$expr})",
57
+ 'total_count' => "COUNT({$expr})",
58
+ 'day_count' => "ROUND(COUNT({$expr}) / DATEDIFF(date(MAX(created_at)) , date(MIN(created_at))), 2)"
59
+ ))
60
+ ->where('main_table.status NOT IN(?)', $statuses)
61
+ ->where('main_table.state NOT IN(?)', array(
62
+ Mage_Sales_Model_Order::STATE_NEW,
63
+ Mage_Sales_Model_Order::STATE_PENDING_PAYMENT)
64
+ );
65
+ }
66
+ return $collection;
67
+ }
68
+
69
+ /**
70
+ * @param int $store
71
+ * @param int $website
72
+ * @param int $group
73
+ * @return Varien_Object
74
+ * @throws Mage_Core_Exception
75
+ */
76
+ public function getLifetimeSales($store = 0, $website = 0, $group =0)
77
+ {
78
+ $isFilter = $store || $website || $group;
79
+ $collection = $this->calculateSales($isFilter);
80
+
81
+ if ($store) {
82
+ $collection->addFieldToFilter('store_id', $store);
83
+ } else if ($website){
84
+ $storeIds = Mage::app()->getWebsite($website)->getStoreIds();
85
+ $collection->addFieldToFilter('store_id', array('in' => $storeIds));
86
+ } else if ($group){
87
+ $storeIds = Mage::app()->getGroup($group)->getStoreIds();
88
+ $collection->addFieldToFilter('store_id', array('in' => $storeIds));
89
+ }
90
+
91
+ return $collection->setPageSize(1)->setCurPage(1)->getFirstItem();
92
+ }
93
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Rfm.php ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Tabs_Analysis_Rfm extends Mage_Core_Model_Abstract
4
+ {
5
+ protected $rfm = array();
6
+ protected $_store = 0;
7
+ protected $_group = 0;
8
+ protected $_website = 0;
9
+
10
+ protected $_resultCount;
11
+
12
+ const RECENCY = 'Recency';
13
+ const FREQUENCY = 'Frequency';
14
+ const MONETARY = 'Monetary';
15
+
16
+ /**
17
+ * prepare collection and needed columns
18
+ *
19
+ * @return Mage_Sales_Model_Resource_Order_Collection
20
+ * @throws Mage_Core_Exception
21
+ */
22
+ protected function getPreparedCollection()
23
+ {
24
+ $statuses = Mage::getSingleton('sales/config')
25
+ ->getOrderStatusesForState(Mage_Sales_Model_Order::STATE_CANCELED);
26
+ if (empty($statuses)) {
27
+ $statuses = array(0);
28
+ }
29
+
30
+ $collection = Mage::getResourceModel('sales/order_collection');
31
+ $collection
32
+ ->addFieldToFilter('status', array('nin' => $statuses))
33
+ ->addFieldToFilter('state',
34
+ array('nin' => array(
35
+ Mage_Sales_Model_Order::STATE_NEW,
36
+ Mage_Sales_Model_Order::STATE_PENDING_PAYMENT)
37
+ )
38
+ )
39
+ ->addFieldToFilter('customer_id', array('neq' => 'null'))
40
+ ->addOrder('created_at');
41
+
42
+ if ($this->_store) {
43
+ $collection->addFieldToFilter('store_id', $this->_store);
44
+ } else if ($this->_website){
45
+ $storeIds = Mage::app()->getWebsite($this->_website)->getStoreIds();
46
+ $collection->addFieldToFilter('store_id', array('in' => $storeIds));
47
+ } else if ($this->_group){
48
+ $storeIds = Mage::app()->getGroup($this->_group)->getStoreIds();
49
+ $collection->addFieldToFilter('store_id', array('in' => $storeIds));
50
+ }
51
+
52
+ $expr = Mage::getResourceModel('ddg_automation/contact')->getSalesAmountExpression($collection);
53
+ $isFilter = $this->_store || $this->_website || $this->_group;
54
+ if ($isFilter == 0) {
55
+ $expr = '(' . $expr . ') * main_table.base_to_global_rate';
56
+ }
57
+
58
+ $collection->getSelect()
59
+ ->reset(Zend_Db_Select::COLUMNS)
60
+ ->columns(array(
61
+ 'customer_total_orders' => "count(*)",
62
+ 'customer_average_order_value' => "SUM({$expr})/count(*)",
63
+ 'last_order_days_ago' => "DATEDIFF(date(NOW()) , date(MAX(created_at)))"
64
+ ))
65
+ ->group('customer_id');
66
+
67
+ return $collection;
68
+ }
69
+
70
+ /**
71
+ * calculate quartiles
72
+ *
73
+ * @param $array
74
+ * @return array
75
+ */
76
+ protected function calculateQuartile($array)
77
+ {
78
+ $count = $this->_resultCount;
79
+ if ($count == 0)
80
+ return array(
81
+ "Low" => 0,
82
+ "Medium" => 0,
83
+ "High" => 0
84
+ );
85
+
86
+ $first = intval(round(.25 * ($count + 1)));
87
+ $second = intval(round(.50 * ($count + 1)));
88
+ $third = intval(round(.75 * ($count + 1)));
89
+
90
+ if (!array_key_exists($first, $array))
91
+ $first = $this->getClosest($first, $array);
92
+
93
+ if (!array_key_exists($second, $array))
94
+ $second = $this->getClosest($second, $array);
95
+
96
+ if (!array_key_exists($third, $array))
97
+ $third = $this->getClosest($third, $array);
98
+
99
+ return array(
100
+ "Low" => $array[$first],
101
+ "Medium" => $array[$second],
102
+ "High" => $array[$third]
103
+ );
104
+ }
105
+
106
+ /**
107
+ * find closest index key from array
108
+ *
109
+ * @param $search
110
+ * @param $arr
111
+ * @return mix
112
+ */
113
+ protected function getClosest($search, $arr) {
114
+ $closest = null;
115
+ foreach($arr as $key => $value) {
116
+ if($search == $key)
117
+ return $search;
118
+ if($closest == null || abs($search - $closest) > abs($key - $search)) {
119
+ $closest = $key;
120
+ }
121
+ }
122
+ return $closest;
123
+ }
124
+
125
+ /**
126
+ * prepare rfm data
127
+ */
128
+ protected function prepareRfm()
129
+ {
130
+ $collection = $this->getPreparedCollection();
131
+ $contactResource = Mage::getResourceModel('ddg_automation/contact');
132
+
133
+ $values = $contactResource->prepareFrequency($collection);
134
+ $this->_resultCount = count($values);
135
+ $this->rfm[self::FREQUENCY] = $this->calculateQuartile($values);
136
+
137
+
138
+ $values = $contactResource->prepareRecency($collection);
139
+ $this->rfm[self::RECENCY] = $this->calculateQuartile($values);
140
+
141
+ $values = $contactResource->prepareMonetary($collection);
142
+ $this->rfm[self::MONETARY] = $this->calculateQuartile($values);
143
+ }
144
+
145
+ /**
146
+ * @param int $store
147
+ * @param int $website
148
+ * @param int $group
149
+ * @return array
150
+ */
151
+ public function getPreparedRfm($store = 0, $website = 0, $group =0)
152
+ {
153
+ $this->_store = $store;
154
+ $this->_group = $group;
155
+ $this->_website = $website;
156
+
157
+ $this->prepareRfm();
158
+ return $this->rfm;
159
+ }
160
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Dashboard/Tabs/Analysis/Subscriber.php ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Dashboard_Tabs_Analysis_Subscriber extends Mage_Core_Model_Abstract
4
+ {
5
+ protected $storeIds;
6
+
7
+ protected function calculateOperationalDaysFromOrder()
8
+ {
9
+ $collection = Mage::getResourceModel('sales/order_collection');
10
+ $collection->addFieldToSelect('created_at');
11
+
12
+ if (is_array($this->storeIds) && !empty($this->storeIds)) {
13
+ $collection->addFieldToFilter('store_id', array('in' => $this->storeIds));
14
+ }
15
+
16
+ $collection->getSelect()->columns(array(
17
+ 'days' => "DATEDIFF(date(NOW()) , date(MIN(created_at)))"
18
+ ));
19
+ return $collection->setPageSize(1)->setCurPage(1)->getFirstItem()->getDays();
20
+ }
21
+
22
+ protected function _getCollection(){
23
+ $collection = Mage::getResourceModel('newsletter/subscriber_collection');
24
+ $collection->addFieldToFilter('subscriber_status', array('neq' => '3'));
25
+
26
+ if (is_array($this->storeIds) && !empty($this->storeIds)) {
27
+ $collection->addFieldToFilter('store_id', array('in' => $this->storeIds));
28
+ }
29
+ return $collection;
30
+ }
31
+
32
+ /**
33
+ * prepare collection
34
+ *
35
+ * @return Varien_Object
36
+ */
37
+ protected function getPreparedCollection()
38
+ {
39
+ //all active subscribers
40
+ $collection = $this->_getCollection();
41
+ $totalSubscribers = $collection->getSize();
42
+
43
+ //all active subscribers who are also customers
44
+ $customerSubscribers = $collection->addFieldToFilter('customer_id', array('neq' => '0'));
45
+ $customerSubscriberCount = $customerSubscribers->getSize();
46
+
47
+ $days = $this->calculateOperationalDaysFromOrder();
48
+ if($days)
49
+ $subscribersPerDay = number_format($totalSubscribers/$days, 2);
50
+ else
51
+ $subscribersPerDay = $totalSubscribers;
52
+
53
+ $resultObject = new Varien_Object;
54
+ $resultObject
55
+ ->setTotalSubscriber($totalSubscribers)
56
+ ->setTotalSubscriberCustomer($customerSubscriberCount)
57
+ ->setSubscribersPerDay($subscribersPerDay);
58
+
59
+ return $resultObject;
60
+ }
61
+
62
+ /**
63
+ * @param int $store
64
+ * @param int $website
65
+ * @param int $group
66
+ * @return Varien_Object
67
+ * @throws Mage_Core_Exception
68
+ */
69
+ public function getLifetimeSubscribers($store = 0, $website = 0, $group =0)
70
+ {
71
+ if ($store) {
72
+ $this->storeIds = array($store => $store);
73
+ } else if ($website){
74
+ $storeIds = Mage::app()->getWebsite($website)->getStoreIds();
75
+ $this->storeIds = $storeIds;
76
+ } else if ($group){
77
+ $storeIds = Mage::app()->getGroup($group)->getStoreIds();
78
+ $this->storeIds = $storeIds;
79
+ }
80
+ return $this->getPreparedCollection();
81
+ }
82
+
83
+ /**
84
+ * @return string
85
+ */
86
+ public function getTitle()
87
+ {
88
+ return "Subscribers Analytical Data";
89
+ }
90
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Observer.php ADDED
@@ -0,0 +1,229 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Observer
4
+ {
5
+
6
+ /**
7
+ * API Sync and Data Mapping.
8
+ * Reset contacts for reimport.
9
+ * @return $this
10
+ */
11
+ public function actionConfigResetContacts()
12
+ {
13
+ $contactModel = Mage::getModel('ddg_automation/contact');
14
+ $numImported = $contactModel->getNumberOfImportedContacs();
15
+ $updated = $contactModel->getResource()->resetAllContacts();
16
+ Mage::helper('ddg')->log('-- Imported contacts: ' . $numImported . ' reseted : ' . $updated . ' --');
17
+
18
+ /**
19
+ * check for addressbook mapping and disable if no address selected.
20
+ */
21
+ $this->_checkAddressBookMapping(Mage::app()->getRequest()->getParam('website'));
22
+
23
+ return $this;
24
+ }
25
+
26
+ /**
27
+ * Check if the transactional data feature is enabled
28
+ * To use the wishlist and order sync this needs to be enabled.
29
+ */
30
+ public function checkFeatureActive()
31
+ {
32
+ //scope to retrieve the website id
33
+ $scopeId = 0;
34
+ if ($website = Mage::app()->getRequest()->getParam('website')) {
35
+ //use webiste
36
+ $scope = 'websites';
37
+ $scopeId = Mage::app()->getWebsite($website)->getId();
38
+ } else {
39
+ //set to default
40
+ $scope = "default";
41
+ }
42
+ //webiste by id
43
+ $website = Mage::app()->getWebsite($scopeId);
44
+
45
+ //configuration saved for the wishlist and order sync
46
+ $wishlistEnabled = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_WISHLIST_ENABLED, $scope, $scopeId);
47
+ $orderEnabled = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_ORDER_ENABLED);
48
+
49
+ //only for modification for order and wishlist
50
+ if ($orderEnabled || $wishlistEnabled) {
51
+ //client by website id
52
+ $client = Mage::helper('ddg')->getWebsiteApiClient($scopeId);
53
+
54
+ //call request for account info
55
+ $response = $client->getAccountInfo();
56
+
57
+ //properties must be checked
58
+ if (isset($response->properties)) {
59
+ $accountInfo = $response->properties;
60
+ $result = $this->_checkForOption(Dotdigitalgroup_Email_Model_Apiconnector_Client::API_ERROR_TRANS_ALLOWANCE, $accountInfo);
61
+
62
+ //account is disabled to use transactional data
63
+ if (! $result) {
64
+ $message = 'Transactional Data For This Account Is Disabled. Call Support To Enable.';
65
+ //send admin message
66
+ Mage::getSingleton('adminhtml/session')->addError($message);
67
+
68
+ //send raygun message for trans data
69
+ Mage::helper('ddg')->rayLog($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,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ //check for address book id before displaying, IMPORTANT :Test address book cannot be used through api
38
+ if ( isset( $book->id ) && $book->name != 'Test') {
39
+ $fields[] = array( 'value' => $book->id, 'label' => $book->name );
40
+ }
41
+ }
42
+ }
43
+
44
+ return $fields;
45
+ }
46
+
47
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Addressbookspref.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Addressbookspref
4
+ {
5
+ private function getWebsite()
6
+ {
7
+ $website = Mage::app()->getWebsite();
8
+ $websiteParam = Mage::app()->getRequest()->getParam('website');
9
+ if($websiteParam)
10
+ $website = Mage::app()->getWebsite($websiteParam);
11
+ return $website;
12
+ }
13
+
14
+ /**
15
+ * get address books
16
+ *
17
+ * @return null
18
+ */
19
+ private function getAddressBooks()
20
+ {
21
+ $website = $this->getWebsite();
22
+ $client = Mage::getModel( 'ddg_automation/apiconnector_client' );
23
+ $client->setApiUsername( Mage::helper( 'ddg' )->getApiUsername( $website ) )
24
+ ->setApiPassword( Mage::helper( 'ddg' )->getApiPassword( $website ) );
25
+
26
+ $savedAddressBooks = Mage::registry( 'addressbooks' );
27
+ //get saved address books from registry
28
+ if ( $savedAddressBooks ) {
29
+ $addressBooks = $savedAddressBooks;
30
+ } else {
31
+ // api all address books
32
+ $addressBooks = $client->getAddressBooks();
33
+ Mage::register( 'addressbooks', $addressBooks );
34
+ }
35
+ return $addressBooks;
36
+ }
37
+
38
+ /**
39
+ * addressbook options
40
+ *
41
+ * @return array
42
+ * @throws Mage_Core_Exception
43
+ */
44
+ public function toOptionArray()
45
+ {
46
+ $fields = array();
47
+ $website = $this->getWebsite();
48
+
49
+ $enabled = Mage::helper('ddg')->isEnabled($website);
50
+
51
+ //get address books options
52
+ if ($enabled) {
53
+ $addressBooks = $this->getAddressBooks();
54
+ //set the error message to the select option
55
+ if ( isset( $addressBooks->message ) ) {
56
+ $fields[] = array( 'value' => 0, 'label' => Mage::helper( 'ddg' )->__( $addressBooks->message) );
57
+ }
58
+
59
+ $subscriberAddressBook = Mage::helper('ddg')->getSubscriberAddressBook(Mage::app()->getWebsite());
60
+
61
+ //set up fields with book id and label
62
+ foreach ( $addressBooks as $book ) {
63
+ if (isset($book->id) && $book->visibility == 'Public' && $book->id != $subscriberAddressBook) {
64
+ $fields[] = array( 'value' => $book->id, 'label' => $book->name );
65
+ }
66
+ }
67
+ }
68
+
69
+ return $fields;
70
+ }
71
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Abandonedlimit.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Advanced_Abandonedlimit
4
+ {
5
+
6
+ /**
7
+ * available times
8
+ * @var array
9
+ */
10
+ protected $_times = array(0,1,2,3,4,5,6,12,24,36,48,60,72,84,96,108,120, 240);
11
+
12
+
13
+ /**
14
+ * send to campain options hours
15
+ * @return array
16
+ */
17
+ public function toOptionArray()
18
+ {
19
+ $result = $row = array();
20
+ $i = 0;
21
+ foreach ($this->_times as $one) {
22
+
23
+
24
+ if ($i == 0)
25
+ $row = array('value' => $one, 'label' => Mage::helper('ddg')->__('No Limit'));
26
+ elseif ($i == 1) {
27
+ $row = array(
28
+ 'value' => $one,
29
+ 'label' => Mage::helper( 'ddg' )->__( $one . ' Hour' )
30
+ );
31
+ } else {
32
+ $row = array(
33
+ 'value' => $one,
34
+ 'label' => Mage::helper( 'ddg' )->__( $one . ' Hours' )
35
+ );
36
+ }
37
+ $result[] = $row;
38
+ $i++;
39
+ }
40
+
41
+ return $result;
42
+ }
43
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Attributes.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Advanced_Attributes
4
+ {
5
+ /**
6
+ * Returns custom order attributes
7
+ * @return array
8
+ */
9
+ public function toOptionArray()
10
+ {
11
+ $fields = Mage::getResourceModel('ddg_automation/order')->getOrderTableDescription();
12
+
13
+ $customFields = array();
14
+ foreach($fields as $key => $field){
15
+ $customFields[] = array(
16
+ 'value' => $field['COLUMN_NAME'],
17
+ 'label' => $field['COLUMN_NAME']
18
+ );
19
+ }
20
+ return $customFields;
21
+ }
22
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Cronexpressionsone.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Advanced_Cronexpressionsone
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ return array(
8
+ array('value' => '*/5 * * * *', 'label' => Mage::helper('ddg')->__('Every 5 Minutes')),
9
+ array('value' => '*/10 * * * *', 'label' => Mage::helper('ddg')->__('Every 10 Minutes')),
10
+ array('value' => '*/15 * * * *', 'label' => Mage::helper('ddg')->__('Every 15 Minutes')),
11
+ );
12
+ }
13
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Cronexpressionstwo.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Advanced_Cronexpressionstwo
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ return array(
8
+ array('value' => '*/15 * * * *', 'label' => Mage::helper('ddg')->__('Every 15 Minutes')),
9
+ array('value' => '*/30 * * * *', 'label' => Mage::helper('ddg')->__('Every 30 Minutes')),
10
+ array('value' => '00 * * * *', 'label' => Mage::helper('ddg')->__('Every 60 Minutes')),
11
+ );
12
+ }
13
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Frequency.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Advanced_Frequency
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ return array(
8
+ array('value' => '1', 'label' => Mage::helper('ddg')->__('1 Hour')),
9
+ array('value' => '2', 'label' => Mage::helper('ddg')->__('2 Hours')),
10
+ array('value' => '6', 'label' => Mage::helper('ddg')->__('6 Hours')),
11
+ array('value' => '12', 'label' => Mage::helper('ddg')->__('12 Hours')),
12
+ array('value' => '24', 'label' => Mage::helper('ddg')->__('24 Hours'))
13
+ );
14
+ }
15
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Quoteattributes.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Advanced_Quoteattributes
4
+ {
5
+ /**
6
+ * @return array
7
+ */
8
+ public function toOptionArray()
9
+ {
10
+ $fields = Mage::getResourceModel('ddg_automation/quote')->getQuoteTableDescription();
11
+
12
+ $customFields = array();
13
+ foreach($fields as $key => $field){
14
+ $customFields[] = array(
15
+ 'value' => $field['COLUMN_NAME'],
16
+ 'label' => $field['COLUMN_NAME']
17
+ );
18
+ }
19
+ return $customFields;
20
+ }
21
+ }
app/code/{local/Dotdigitalgroup/Email/Model/System/Config/Source/Orderlimit.php → community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Advanced/Transdata.php} RENAMED
@@ -1,6 +1,6 @@
1
  <?php
2
 
3
- class Dotdigitalgroup_Email_Model_System_Config_Source_Orderlimit
4
  {
5
  /**
6
  * @return array
1
  <?php
2
 
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Advanced_Transdata
4
  {
5
  /**
6
  * @return array
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Attributes.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Attributes
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ $attributes = Mage::getResourceModel('catalog/product_attribute_collection')
8
+ ->addVisibleFilter();
9
+
10
+ $attributeArray = array(
11
+ array(
12
+ 'label' => Mage::helper('ddg')->__('Select Attribute....'),
13
+ 'value' => ''
14
+ )
15
+ );
16
+
17
+ foreach($attributes as $attribute){
18
+ $attributeArray[] = array(
19
+ 'label' => $attribute->getFrontendLabel(),
20
+ 'value' => $attribute->getAttributeCode()
21
+ );
22
+ }
23
+ return $attributeArray;
24
+ }
25
+ }
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,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Orderstatus
4
+ {
5
+ /**
6
+ * Returns the order statuses
7
+ * @return array
8
+ */
9
+ public function toOptionArray()
10
+ {
11
+ $statuses = Mage::getSingleton('sales/order_config')->getStatuses();
12
+ $options = array();
13
+
14
+ foreach ($statuses as $code=>$label) {
15
+ $options[] = array(
16
+ 'value' => $code,
17
+ 'label' => $label
18
+ );
19
+ }
20
+ return $options;
21
+ }
22
+ }
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/Sync/Yesno.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Sync_Yesno
4
+ {
5
+ /**
6
+ * Options getter
7
+ *
8
+ * @return array
9
+ */
10
+ public function toOptionArray()
11
+ {
12
+ //get current scope website code
13
+ $websiteCode = Mage::getSingleton('adminhtml/config_data')->getWebsite();
14
+
15
+ //for current scope website check if entry exist in registry. if not than
16
+ //than get account data and store it in registry to re-use
17
+ if(!Mage::registry('ddg-account-info-'.$websiteCode)){
18
+ //load website by code
19
+ $website = Mage::getModel('core/website')->load($websiteCode, 'code');
20
+
21
+ //if scope is empty or no id than load default
22
+ if(empty($website) or !$website->getId())
23
+ $website = 0;
24
+
25
+ $apiUsername = Mage::helper('ddg')->getApiUsername($website);
26
+ $apiPassword = Mage::helper('ddg')->getApiPassword($website);
27
+ $data = Mage::getModel('ddg_automation/apiconnector_client')
28
+ ->setApiUsername($apiUsername)
29
+ ->setApiPassword($apiPassword)
30
+ ->getAccountInfo();
31
+
32
+ //save entry in registry for current website scope
33
+ Mage::register('ddg-account-info-'.$websiteCode, $data);
34
+ }
35
+
36
+ //get from registry
37
+ $data = Mage::registry('ddg-account-info-'.$websiteCode);
38
+ //if properties property exist
39
+ if(isset($data->properties)){
40
+ $propertyNames = array();
41
+ //loop all and save property names
42
+ foreach ($data->properties as $one) {
43
+ $propertyNames[] = $one->name;
44
+ }
45
+
46
+ //only return Yes/No option if data allowance properties exist
47
+ if(in_array('TransactionalDataAllowanceInMegabytes', $propertyNames) &&
48
+ in_array('TransactionalDataUsageInMegabytes', $propertyNames)){
49
+ return array(
50
+ array('value' => 1, 'label'=>Mage::helper('adminhtml')->__('Yes')),
51
+ array('value' => 0, 'label'=>Mage::helper('adminhtml')->__('No')),
52
+ );
53
+ }
54
+ }
55
+
56
+ //return default message if above is scenarios are failed.
57
+ return array(
58
+ array('value' => 0, 'label'=>Mage::helper('adminhtml')->__('Not enabled on account'))
59
+ );
60
+ }
61
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Transactional/Mode.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Transactional_Mode
3
+ {
4
+ public function toOptionArray()
5
+ {
6
+ return array(
7
+ 'smtp' => Mage::helper('ddg')->__('SMTP')
8
+ //'api' => Mage::helper('ddg')->__('API')
9
+ );
10
+
11
+ }
12
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Transactional/Port.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Transactional_Port
3
+ {
4
+
5
+ public function toOptionArray()
6
+ {
7
+ return array(
8
+ '25' => Mage::helper('ddg')->__("25"),
9
+ '2525' => Mage::helper('ddg')->__("2525"),
10
+ '587' => Mage::helper('ddg')->__("587")
11
+ );
12
+
13
+
14
+ }
15
+ }
app/code/community/Dotdigitalgroup/Email/Model/Adminhtml/Source/Transactional/Ssl.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Dotdigitalgroup_Email_Model_Adminhtml_Source_Transactional_Ssl
3
+ {
4
+ public function toOptionArray()
5
+ {
6
+ return array(
7
+ 'no' => Mage::helper('ddg')->__('No SSL'),
8
+ 'tls' => Mage::helper('ddg')->__('TLS')
9
+ );
10
+
11
+ }
12
+ }
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,1254 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
164
+ //if curl error found
165
+ if(curl_errno($ch))
166
+ {
167
+ //save the error
168
+ $this->curlError = curl_error($ch);
169
+ }
170
+
171
+ $result = json_decode($result);
172
+ if (isset($result->message)) {
173
+ $message = 'POST ADDRESS BOOK ' . $addressBookId . ', CONTACT IMPORT : ' . ' filename ' . $filename . ' Username ' . $this->getApiUsername() . $result->message;
174
+ $helper->log($message);
175
+ Mage::helper('ddg')->log($result)
176
+ ->rayLog($result->message);
177
+ }
178
+ return $result;
179
+ }
180
+
181
+ /**
182
+ * Adds a contact to a given address book.
183
+ * @param $addressBookId
184
+ * @param $apiContact
185
+ * @return mixed|null
186
+ */
187
+ public function postAddressBookContacts($addressBookId, $apiContact)
188
+ {
189
+ $url = self::REST_ADDRESS_BOOKS . $addressBookId . '/contacts';
190
+ $this->setUrl($url)
191
+ ->setVerb("POST")
192
+ ->buildPostBody($apiContact);
193
+
194
+ $response = $this->execute();
195
+
196
+ //log the error
197
+ if (isset($response->message) && ! in_array($response->message, $this->exludeMessages)) {
198
+ $message = 'POST ADDRESS BOOK CONTACTS ' . $url . ', ' . $response->message;
199
+ Mage::helper('ddg')->log($message)
200
+ ->rayLog($response->message);
201
+ }
202
+
203
+ return $response;
204
+ }
205
+
206
+ /**
207
+ * Deletes all contacts from a given address book.
208
+ * @param $addressBookId
209
+ * @param $contactId
210
+ * @return null
211
+ */
212
+ public function deleteAddressBookContact($addressBookId, $contactId)
213
+ {
214
+
215
+ $url = self::REST_ADDRESS_BOOKS . $addressBookId . '/contacts/' . $contactId;
216
+ $this->setUrl($url)
217
+ ->setVerb('DELETE');
218
+
219
+ return $this->execute();
220
+ }
221
+
222
+ /**
223
+ * Gets a report with statistics about what was successfully imported, and what was unable to be imported.
224
+ * @param $importId
225
+ * @return mixed
226
+ */
227
+ public function getContactsImportReport($importId)
228
+ {
229
+ $url = self::REST_CONTACTS_IMPORT . $importId . "/report";
230
+ $this->setUrl($url)
231
+ ->setVerb('GET');
232
+ $response = $this->execute();
233
+ //log error
234
+ if (isset($response->message) && ! in_array($response->message, $this->exludeMessages)) {
235
+ $message = 'GET CONTACTS IMPORT REPORT . ' . $url . ' message : ' . $response->message;
236
+ Mage::helper( 'ddg' )->log( $message )
237
+ ->rayLog( $response->message);
238
+ }
239
+ return $response;
240
+ }
241
+
242
+ /**
243
+ * Gets a contact by email address.
244
+ * @param $email
245
+ * @return mixed
246
+ */
247
+ public function getContactByEmail($email)
248
+ {
249
+ $url = self::REST_CONTACTS . $email;
250
+ $this->setUrl($url)
251
+ ->setVerb('GET');
252
+
253
+ $response = $this->execute();
254
+
255
+ //log error
256
+ if (isset($response->message) && ! in_array($response->message, $this->exludeMessages)) {
257
+ $message = 'GET CONTACT BY email : ' . $email . ' ' . $response->message;
258
+ Mage::helper('ddg')->log($message)
259
+ ->rayLog($response->message);
260
+ }
261
+
262
+ return $response;
263
+ }
264
+
265
+ /**
266
+ * Get all address books.
267
+ * @return null
268
+ */
269
+ public function getAddressBooks()
270
+ {
271
+ $url = self::REST_ADDRESS_BOOKS;
272
+ $this->setUrl($url)
273
+ ->setVerb("GET");
274
+
275
+ $response = $this->execute();
276
+ //log error
277
+ if (isset($response->message) && ! in_array($response->message, $this->exludeMessages)) {
278
+ $message = 'GET ALL ADDRESS BOOKS : ' . $url . ', ' . $response->message;
279
+ Mage::helper('ddg')->log($message)
280
+ ->rayLog($response->message);
281
+ }
282
+
283
+ return $response;
284
+ }
285
+
286
+ /**
287
+ * Gets an address book by ID.
288
+ * @param $id
289
+ *
290
+ * @return null
291
+ * @throws Exception
292
+ */
293
+ public function getAddressBookById($id)
294
+ {
295
+ $url = self::REST_ADDRESS_BOOKS . $id;
296
+
297
+ $this->setUrl($url)
298
+ ->setVerb('GET');
299
+
300
+ $response = $this->execute();
301
+
302
+ if (isset($response->message)) {
303
+ Mage::helper('ddg')->log('GET ADDRESS BOOK BY ID '. $id . ', ' . $response->message);
304
+ }
305
+
306
+ return $response;
307
+ }
308
+
309
+ /**
310
+ * Creates an address book.
311
+ * @param $name
312
+ * @return null
313
+ */
314
+ public function postAddressBooks($name, $visibility = 'Public')
315
+ {
316
+ $data = array(
317
+ 'Name' => $name,
318
+ 'Visibility' => $visibility
319
+ );
320
+ $url = self::REST_ADDRESS_BOOKS;
321
+ $this->setUrl($url)
322
+ ->setVerb('POST')
323
+ ->buildPostBody($data);
324
+
325
+ $response = $this->execute();
326
+ //log error
327
+ if (isset($response->message) && ! in_array($response->message, $this->exludeMessages)) {
328
+ $message = 'Postaddressbooks ' . $response->message . ', url :' . $url ;
329
+ Mage::helper('ddg')->log($message)
330
+ ->rayLog($response->message);
331
+ }
332
+
333
+ return $response;
334
+ }
335
+
336
+ /**
337
+ * Get list of all campaigns.
338
+ * @return mixed
339
+ */
340
+ public function getCampaigns()
341
+ {
342
+ $url = self::REST_DATA_FIELDS_CAMPAIGNS;
343
+ $this->setUrl($url)
344
+ ->setVerb('GET');
345
+
346
+ $response = $this->execute();
347
+ //log error
348
+ if (isset($response->message) && ! in_array($response->message, $this->exludeMessages)) {
349
+ $message = 'GET CAMPAIGNS ' . $response->message . ' api user : ' . $this->getApiUsername();
350
+ Mage::helper('ddg')->log($message)
351
+ ->rayLog($response->message);
352
+ }
353
+
354
+ return $response;
355
+ }
356
+
357
+ /**
358
+ * Creates a data field within the account.
359
+ * @param $data string/array
360
+ * @param string $type string, numeric, date, boolean
361
+ * @param string $visibility public, private
362
+ * @param bool $defaultValue
363
+ * @return mixed
364
+ */
365
+ public function postDataFields($data, $type = 'String', $visibility = 'public', $defaultValue = false)
366
+ {
367
+ $url = self::REST_DATA_FILEDS;
368
+ //set default value for the numeric datatype
369
+ if($type == 'numeric' && !$defaultValue)
370
+ $defaultValue = 0;
371
+ //set data for the string datatype
372
+ if (is_string($data)) {
373
+ $data = array(
374
+ 'Name' => $data,
375
+ 'Type' => $type,
376
+ 'Visibility' => $visibility
377
+ );
378
+ //default value
379
+ if($defaultValue)
380
+ $data['DefaultValue'] = $defaultValue;
381
+ }
382
+ $this->setUrl($url)
383
+ ->buildPostBody($data)
384
+ ->setVerb('POST');
385
+
386
+ $response = $this->execute();
387
+ //log error
388
+ if (isset($response->message) && ! in_array($response->message, $this->exludeMessages)) {
389
+ $message = 'POST CREATE DATAFIELDS ' . $response->message;
390
+ Mage::helper('ddg')->log($message)
391
+ ->log($data)
392
+ ->rayLog($response->message);
393
+ }
394
+
395
+ return $response;
396
+ }
397
+
398
+ /**
399
+ * Deletes a data field within the account.
400
+ * @param $name
401
+ *
402
+ * @return mixed
403
+ */
404
+ public function deleteDataField($name)
405
+ {
406
+ $url = self::REST_DATA_FILEDS . '/' . $name;
407
+ $this->setUrl($url)
408
+ ->setVerb('DELETE');
409
+
410
+ $response = $this->execute();
411
+ //log error
412
+ if (isset($response->message) && ! in_array($response->message, $this->exludeMessages)) {
413
+ $message = 'DELETE DATA FIELD :' . $name . ' ' . $response->message;
414
+ Mage::helper('ddg')->log($message)
415
+ ->rayLog($response->message);
416
+ }
417
+
418
+ return $response;
419
+ }
420
+
421
+ /**
422
+ * Lists the data fields within the account.
423
+ * @return mixed
424
+ */
425
+ public function getDataFields()
426
+ {
427
+ $url = self::REST_DATA_FILEDS;
428
+ $this->setUrl($url)
429
+ ->setVerb('GET');
430
+
431
+ $response = $this->execute();
432
+ //log error
433
+ if (isset($response->message) && ! in_array($response->message, $this->exludeMessages)) {
434
+ $message = 'GET ALL DATAFIELDS ' . $response->message;
435
+ Mage::helper('ddg')->log($message)
436
+ ->rayLog($response->message);
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
+ $url = self::REST_CONTACTS . $contactId;
451
+ $this->setUrl($url)
452
+ ->setVerb('PUT')
453
+ ->buildPostBody($data);
454
+
455
+ $response = $this->execute();
456
+ //log error
457
+ if (isset($response->message) && ! in_array($response->message, $this->exludeMessages)) {
458
+ $message = 'ERROR : UPDATE SINGLE CONTACT : ' . $url . ' message : ' . $response->message;
459
+ Mage::helper('ddg')->log($message)
460
+ ->log($data)
461
+ ->rayLog($response->message);
462
+ }
463
+
464
+ return $response;
465
+ }
466
+
467
+ /**
468
+ * Deletes a contact.
469
+ * @param $contactId
470
+ * @return null
471
+ */
472
+ public function deleteContact($contactId)
473
+ {
474
+ $url = self::REST_CONTACTS . $contactId;
475
+ $this->setUrl($url)
476
+ ->setVerb('DELETE');
477
+
478
+ $response = $this->execute();
479
+ //log error
480
+ if (isset($response->message) && ! in_array($response->message, $this->exludeMessages)) {
481
+ $message = 'DELETE CONTACT : ' . $url . ', ' . $response->message;
482
+ Mage::helper('ddg')->log($message)
483
+ ->rayLog($response->message);
484
+ }
485
+ return $response;
486
+ }
487
+
488
+ /**
489
+ * Update contact datafields by email.
490
+ * @param $email
491
+ * @param $dataFields
492
+ *
493
+ * @return null
494
+ * @throws Exception
495
+ */
496
+ public function updateContactDatafieldsByEmail($email, $dataFields)
497
+ {
498
+ $apiContact = $this->postContacts($email);
499
+ //do not create for non contact id set
500
+ if (! isset($apiContact->id)) {
501
+ return $apiContact;
502
+ } else {
503
+ //get the contact id for this email
504
+ $contactId = $apiContact->id;
505
+ }
506
+ $data = array(
507
+ 'Email' => $email,
508
+ 'EmailType' => 'Html');
509
+ $data['DataFields'] = $dataFields;
510
+ $url = self::REST_CONTACTS . $contactId;
511
+ $this->setUrl($url)
512
+ ->setVerb('PUT')
513
+ ->buildPostBody($data);
514
+
515
+ $response = $this->execute();
516
+ //log error
517
+ if (isset($response->message) && ! in_array($response->message, $this->exludeMessages)) {
518
+ $message = 'ERROR: UPDATE CONTACT DATAFIELD ' . $url . ' message : ' . $response->message;
519
+ Mage::helper('ddg')->log($message)
520
+ ->log($data)
521
+ ->rayLog($response->message);
522
+ }
523
+
524
+ return $response;
525
+ }
526
+
527
+ /**
528
+ * Sends a specified campaign to one or more address books, segments or contacts at a specified time.
529
+ * Leave the address book array empty to send to All Contacts.
530
+ * @param $campaignId
531
+ * @param $contacts
532
+ * @return mixed
533
+ */
534
+ public function postCampaignsSend($campaignId, $contacts)
535
+ {
536
+ $data = array(
537
+ 'username' => $this->getApiUsername(),
538
+ 'password' => $this->getApiPassword(),
539
+ "campaignId" => $campaignId,
540
+ "ContactIds" => $contacts
541
+ );
542
+ $this->setUrl(self::REST_CAMPAIGN_SEND)
543
+ ->setVerb('POST')
544
+ ->buildPostBody($data);
545
+
546
+ $response = $this->execute();
547
+ //log error
548
+ if (isset($response->message) && ! in_array($response->message, $this->exludeMessages)) {
549
+ $message = 'SENDING CAMPAIGN ' . $response->message;
550
+ Mage::helper('ddg')->log($message)
551
+ ->log($data)
552
+ ->rayLog($response->message);
553
+ }
554
+
555
+ return $response;
556
+ }
557
+
558
+ /**
559
+ * Creates a contact.
560
+ * @param $email
561
+ * @return mixed
562
+ */
563
+ public function postContacts($email)
564
+ {
565
+ //validate email before creating a contact
566
+ $valid = preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $email);
567
+ if (! $valid) {
568
+ $object = new stdClass();
569
+ return $object->message = 'Not valid email :' . $email;
570
+ }
571
+
572
+ $url = self::REST_CONTACTS;
573
+ $data = array(
574
+ 'Email' => $email,
575
+ 'EmailType' => 'Html',
576
+ );
577
+ $this->setUrl($url)
578
+ ->setVerb('POST')
579
+ ->buildPostBody($data);
580
+
581
+ $response = $this->execute();
582
+ //log error
583
+ if (isset($response->message) && ! in_array($response->message, $this->exludeMessages)) {
584
+ $message = 'CREATE A NEW CONTACT : ' . $response->message;
585
+ Mage::helper('ddg')->log($message)
586
+ ->rayLog($response->message);
587
+ }
588
+
589
+ return $response;
590
+ }
591
+
592
+
593
+ /**
594
+ * Gets a list of suppressed contacts after a given date along with the reason for suppression.
595
+ * @param $dateString
596
+ * @param $select
597
+ * @param $skip
598
+ * @return object
599
+ */
600
+ public function getContactsSuppressedSinceDate($dateString, $select = 1000, $skip = 0)
601
+ {
602
+ $url = self::REST_CONTACTS_SUPPRESSED_SINCE . $dateString . '?select=' . $select . '&skip=' . $skip;
603
+ $this->setUrl($url)
604
+ ->setVerb("GET");
605
+
606
+ $response = $this->execute();
607
+ //log error
608
+ if (isset($response->message) && ! in_array($response->message, $this->exludeMessages)) {
609
+ $message = 'GET CONTACTS SUPPRESSED SINSE : ' . $dateString . ' select ' . $select . ' skip : ' . $skip . ' response : ' . $response->message;
610
+ Mage::helper('ddg')->log($message)
611
+ ->rayLog($response->message);
612
+ }
613
+
614
+ return $response;
615
+ }
616
+
617
+ /**
618
+ * Adds multiple pieces of transactional data to contacts asynchronously, returning an identifier that can be used to check for import progress.
619
+ * @param $collectionName
620
+ * @param $transactionalData
621
+ * @return object
622
+ */
623
+ public function postContactsTransactionalDataImport($transactionalData, $collectionName = 'Orders')
624
+ {
625
+ $orders = array();
626
+ foreach ($transactionalData as $one) {
627
+ if (isset($one->email)) {
628
+ $orders[] = array(
629
+ 'Key' => $one->id,
630
+ 'ContactIdentifier' => $one->email,
631
+ 'Json' => json_encode($one)
632
+ );
633
+ }
634
+ }
635
+ $url = self::REST_TRANSACTIONAL_DATA_IMPORT . $collectionName;
636
+ $this->setURl($url)
637
+ ->setVerb('POST')
638
+ ->buildPostBody($orders);
639
+
640
+ $response = $this->execute();
641
+ // log error
642
+ if (isset($response->message) && ! in_array($response->message, $this->exludeMessages)) {
643
+ $message = ' SEND MULTI TRANSACTIONAL DATA ' . $response->message;
644
+ Mage::helper('ddg')->log($message)
645
+ ->rayLog($response->message);
646
+ }
647
+
648
+ return $response;
649
+ }
650
+
651
+ /**
652
+ * Adds a single piece of transactional data to a contact.
653
+ *
654
+ * @param $data
655
+ * @param string $collectionName
656
+ *
657
+ * @return null
658
+ * @throws Exception
659
+ */
660
+ public function postContactsTransactionalData($data, $collectionName = 'Orders')
661
+ {
662
+ $order = $this->getContactsTransactionalDataByKey($collectionName, $data->id);
663
+ if(isset($order->message) && $order->message == self::API_ERROR_TRANS_NOT_EXISTS){
664
+ $url = self::REST_TRANSACTIONAL_DATA . $collectionName;
665
+ }else{
666
+ $url = self::REST_TRANSACTIONAL_DATA . $collectionName . '/' . $order->key ;
667
+ }
668
+ $apiData = array(
669
+ 'Key' => $data->id,
670
+ 'ContactIdentifier' => $data->connector_id,
671
+ 'Json' => json_encode($data->expose())
672
+ );
673
+
674
+ $this->setUrl($url)
675
+ ->setVerb('POST')
676
+ ->buildPostBody($apiData);
677
+ $response = $this->execute();
678
+ //log error
679
+ if (isset($response->message) && ! in_array($response->message, $this->exludeMessages)) {
680
+ $message = 'POST CONTACTS TRANSACTIONAL DATA ' . $response->message;
681
+ Mage::helper('ddg')->log($message)
682
+ ->log($apiData)
683
+ ->rayLog($response->message);
684
+ }
685
+
686
+ return $response;
687
+ }
688
+
689
+ /**
690
+ * Gets a piece of transactional data by key.
691
+ * @param $name
692
+ * @param $key
693
+ * @return null
694
+ */
695
+ public function getContactsTransactionalDataByKey($name, $key)
696
+ {
697
+ $url = self::REST_TRANSACTIONAL_DATA . $name . '/' . $key;
698
+ $this->setUrl($url)
699
+ ->setVerb('GET');
700
+
701
+ return $this->execute();
702
+ }
703
+
704
+ /**
705
+ * Deletes all transactional data for a contact.
706
+ * @param $email
707
+ * @param string $collectionName
708
+ * @return object
709
+ */
710
+ public function deleteContactTransactionalData($email, $collectionName = 'Orders')
711
+ {
712
+ $url = 'https://apiconnector.com/v2/contacts/' . $email . '/transactional-data/' . $collectionName ;
713
+ $this->setUrl($url)
714
+ ->setVerb('DELETE');
715
+
716
+ return $this->execute();
717
+ }
718
+
719
+ /**
720
+ * Gets a summary of information about the current status of the account.
721
+ * @return mixed
722
+ */
723
+ public function getAccountInfo()
724
+ {
725
+ $url = self::REST_ACCOUNT_INFO;
726
+ $this->setUrl($url)
727
+ ->setVerb('GET');
728
+
729
+ $response = $this->execute();
730
+ //log error
731
+ if (isset($response->message) && ! in_array($response->message, $this->exludeMessages)) {
732
+ $message = 'GET ACCOUNT INFO for api user : ' . $this->getApiUsername() . ' ' . $response->message;
733
+ Mage::helper('ddg')->log($message)
734
+ ->rayLog($response->message);
735
+ }
736
+
737
+ return $response;
738
+ }
739
+
740
+ /**
741
+ * Send a single SMS message.
742
+ * @param $telephoneNumber
743
+ * @param $message
744
+ * @return object
745
+ */
746
+ public function postSmsMessagesSendTo($telephoneNumber, $message)
747
+ {
748
+ $data = array('Message' => $message);
749
+ $url = self::REST_SMS_MESSAGE_SEND_TO . $telephoneNumber;
750
+ $this->setUrl($url)
751
+ ->setVerb('POST')
752
+ ->buildPostBody($data);
753
+
754
+ $response = $this->execute();
755
+ //log error
756
+ if (isset($response->message) && ! in_array($response->message, $this->exludeMessages)) {
757
+ $message = 'POST SMS MESSAGE SEND to ' . $telephoneNumber . ' message: ' . $message . ' error: ' . $response->message;
758
+ Mage::helper('ddg')->log($message)
759
+ ->rayLog($response->message);
760
+ }
761
+
762
+ return $response;
763
+ }
764
+
765
+
766
+ /**
767
+ * Deletes multiple contacts from an address book.
768
+ * @param $addressBookId
769
+ * @param $contactIds
770
+ * @return object
771
+ */
772
+ public function deleteAddressBookContactsInbulk($addressBookId, $contactIds)
773
+ {
774
+ $url = 'https://apiconnector.com/v2/address-books/' . $addressBookId . '/contacts/inbulk';
775
+ $data = array('ContactIds' => array($contactIds[0]));
776
+ $this->setUrl($url)
777
+ ->setVerb('DELETE')
778
+ ->buildPostBody($data);
779
+
780
+ $response = $this->execute();
781
+ //log error
782
+ if (isset($response->message) && ! in_array($response->message, $this->exludeMessages)) {
783
+ $message = 'DELETE BULK ADDRESS BOOK CONTACTS ' . $response->message . ' address book ' . $addressBookId;
784
+ Mage::helper('ddg')->log($message)
785
+ ->rayLog($response->message);
786
+ }
787
+
788
+ return $response;
789
+ }
790
+
791
+ /**
792
+ * Resubscribes a previously unsubscribed contact.
793
+ *
794
+ * @param $apiContact
795
+ *
796
+ * @return null
797
+ * @throws Exception
798
+ */
799
+ public function postContactsResubscribe($apiContact)
800
+ {
801
+ $url = self::REST_CONTACTS_RESUBSCRIBE;
802
+ $data = array(
803
+ 'UnsubscribedContact' => $apiContact
804
+ );
805
+ $this->setUrl($url)
806
+ ->setVerb("POST")
807
+ ->buildPostBody($data);
808
+
809
+ $response = $this->execute();
810
+ //log error
811
+ if (isset($response->message) && ! in_array($response->message, $this->exludeMessages)) {
812
+ $message = 'Resubscribe : ' . $url . ', message :' . $response->message;
813
+ Mage::helper('ddg')->log($message)
814
+ ->log($data)
815
+ ->rayLog($response->message);
816
+ }
817
+ return $response;
818
+ }
819
+
820
+ /**
821
+ * Gets all custom from addresses which can be used in a campaign.
822
+ *
823
+ * @return null
824
+ * @throws Exception
825
+ */
826
+
827
+ public function getCustomFromAddresses()
828
+ {
829
+ $url = self::REST_CAMPAIGN_FROM_ADDRESS_LIST;
830
+ $this->setUrl($url)
831
+ ->setVerb('GET');
832
+
833
+ $response = $this->execute();
834
+ //log error
835
+ if (isset($response->message) && ! in_array($response->message, $this->exludeMessages)) {
836
+ $message = 'GET CampaignFromAddressList ' . $response->message . ' api user : ' . $this->getApiUsername();
837
+ Mage::helper('ddg')->log($message)
838
+ ->rayLog($response->message);
839
+ }
840
+
841
+ return $response;
842
+ }
843
+
844
+ /**
845
+ * Creates a campaign.
846
+ *
847
+ * @param $data
848
+ *
849
+ * @return null
850
+ * @throws Exception
851
+ */
852
+ public function postCampaign($data)
853
+ {
854
+ $url = self::REST_CREATE_CAMPAIGN;
855
+ $this->setURl($url)
856
+ ->setVerb('POST')
857
+ ->buildPostBody($data);
858
+
859
+ $response = $this->execute();
860
+ //log error
861
+ if (isset($response->message) && ! in_array($response->message, $this->exludeMessages)) {
862
+ $message = ' CREATE CAMPAIGN ' . $response->message;
863
+ Mage::helper('ddg')->log($message)
864
+ ->rayLog($response->message);
865
+ }
866
+
867
+ return $response;
868
+ }
869
+
870
+ /**
871
+ * Gets all programs.
872
+ * https://apiconnector.com/v2/programs?select={select}&skip={skip}
873
+ */
874
+ public function getPrograms()
875
+ {
876
+ $url = self::REST_PROGRAM;
877
+
878
+ $this->setUrl($url)
879
+ ->setVerb('GET');
880
+
881
+ $response = $this->execute();
882
+ //log error
883
+ if (isset($response->message) && ! in_array($response->message, $this->exludeMessages)) {
884
+ $message = 'Get programmes : ' . $response->message ;
885
+ Mage::helper( 'ddg' )->log($message)
886
+ ->rayLog($response->message);
887
+ }
888
+
889
+ return $response;
890
+ }
891
+
892
+ /**
893
+ * Creates an enrolment.
894
+ * @param $data
895
+ *
896
+ * @return null
897
+ * @throws Exception
898
+ */
899
+ public function postProgramsEnrolments($data)
900
+ {
901
+ $url = self::REST_PROGRAM_ENROLMENTS;
902
+ $this->setUrl($url)
903
+ ->setVerb('POST')
904
+ ->buildPostBody($data);
905
+
906
+ $response = $this->execute();
907
+ //log error
908
+ if (isset($response->message) && ! in_array($response->message, $this->exludeMessages)) {
909
+ $message = 'Post programs enrolments : ' . $response->message;
910
+ Mage::helper('ddg')->log($message)
911
+ ->log($data)
912
+ ->rayLog($response->message);
913
+ }
914
+
915
+ return $response;
916
+ }
917
+
918
+ /**
919
+ * Gets a program by id.
920
+ * @param $id
921
+ *
922
+ * @return null
923
+ * @throws Exception
924
+ */
925
+ public function getProgramById( $id )
926
+ {
927
+ $url = self::REST_PROGRAM . $id;
928
+ $this->setUrl($url)
929
+ ->setVerb('GET');
930
+
931
+ $response = $this->execute();
932
+ //log error
933
+ if (isset($response->message) && ! in_array($response->message, $this->exludeMessages)) {
934
+ $message = 'Get program by id ' . $id . ', ' . $response->message;
935
+ Mage::helper('ddg')->log($message)
936
+ ->rayLog($response->message);
937
+ }
938
+
939
+ return $response;
940
+ }
941
+
942
+ /**
943
+ * Gets a summary of reporting information for a specified campaign.
944
+ * @param $campaignId
945
+ *
946
+ * @return null
947
+ * @throws Exception
948
+ */
949
+ public function getCampaignSummary($campaignId)
950
+ {
951
+ $url = 'https://apiconnector.com/v2/campaigns/' . $campaignId . '/summary';
952
+
953
+ $this->setUrl($url)
954
+ ->setVerb('GET');
955
+ $response = $this->execute();
956
+ //log error
957
+ if (isset($response->message) && ! in_array($response->message, $this->exludeMessages)) {
958
+ $message = 'Get Campaign Summary ' . $response->message . ' ,url : ' . $url;
959
+ Mage::helper('ddg')->log( $message )
960
+ ->rayLog($response->message);
961
+ }
962
+
963
+ return $response;
964
+ }
965
+
966
+ /**
967
+ * Deletes a piece of transactional data by key.
968
+ * @param $key
969
+ * @param string $collectionName
970
+ * @return object
971
+ */
972
+ public function deleteContactsTransactionalData($key, $collectionName = 'Orders')
973
+ {
974
+ $url = 'https://apiconnector.com/v2/contacts/transactional-data/' . $collectionName .'/' . $key ;
975
+ $this->setUrl($url)
976
+ ->setVerb('DELETE');
977
+ $response = $this->execute();
978
+
979
+ if (isset($response->message))
980
+ Mage::helper('ddg')->log('DELETE CONTACTS TRANSACTIONAL DATA : ' . $url . ' ' . $response->message);
981
+
982
+ return $response;
983
+ }
984
+
985
+ /**
986
+ * Adds a document to a campaign as an attachment.
987
+ * @param $campaignId
988
+ * @param $data
989
+ *
990
+ * @return object
991
+ * @throws Exception
992
+ */
993
+ public function postCampaignAttachments($campaignId, $data)
994
+ {
995
+ $url = self::REST_CREATE_CAMPAIGN . "/$campaignId/attachments";
996
+ $this->setURl($url)
997
+ ->setVerb('POST')
998
+ ->buildPostBody($data);
999
+ $result = $this->execute();
1000
+
1001
+ if (isset($result->message)) {
1002
+ Mage::helper('ddg')->log(' CAMPAIGN ATTACHMENT ' . $result->message);
1003
+ }
1004
+ return $result;
1005
+ }
1006
+
1007
+
1008
+ public function getNostoProducts($slotName, $email)
1009
+ {
1010
+ $recommended = Dotdigitalgroup_Email_Helper_Config::API_ENDPOINT . '/recommendations/email';
1011
+ $token = Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DYNAMIC_CONTENT_NOSTO);
1012
+
1013
+ //check for strin length
1014
+ if (strlen($slotName) > 1 && strlen($email) > 1) {
1015
+
1016
+ $recommended .= '?elements=' . $slotName;
1017
+ $recommended .= '&emails=' . $email;
1018
+ }
1019
+
1020
+ $this->setApiUsername('')
1021
+ ->setApiPassword($token)
1022
+ ->setUrl($recommended)
1023
+ ->setVerb('GET');
1024
+
1025
+ $result = $this->execute();
1026
+
1027
+ if (isset($result->message)) {
1028
+ $message = $result->message;
1029
+ Mage::helper('ddg')->log($message);
1030
+ Mage::helper('ddg')->log("Nosto recommendation slot name : $slotName , email : $email");
1031
+ }
1032
+
1033
+ return $result;
1034
+ }
1035
+
1036
+ /**
1037
+ * get contact address books
1038
+ *
1039
+ * @param $contactId
1040
+ * @return object
1041
+ * @throws Exception
1042
+ */
1043
+ public function getContactAddressBooks($contactId)
1044
+ {
1045
+ $url = 'https://apiconnector.com/v2/contacts/' . $contactId . '/address-books' ;
1046
+ $this->setUrl($url)
1047
+ ->setVerb('GET');
1048
+ $response = $this->execute();
1049
+ //log error
1050
+ if (isset($response->message) && ! in_array($response->message, $this->exludeMessages)) {
1051
+ $message = 'GET CONTACTS ADDRESS BOOKS contact: ' . $contactId . $response->message;
1052
+ Mage::helper('ddg')->log($message)
1053
+ ->rayLog($response->message);
1054
+ }
1055
+
1056
+ return $response;
1057
+ }
1058
+
1059
+ /**
1060
+ * Gets list of all templates.
1061
+ *
1062
+ * @return object
1063
+ * @throws Exception
1064
+ */
1065
+ public function getApiTemplateList()
1066
+ {
1067
+ $url = self::REST_TEMPLATES;
1068
+ $this->setUrl($url)
1069
+ ->setVerb('GET');
1070
+
1071
+ $response = $this->execute();
1072
+
1073
+ //log error
1074
+ if (isset($response->message) && ! in_array($response->message, $this->exludeMessages)) {
1075
+ $message = 'GET API CONTACT LIST ' . $response->message;
1076
+ Mage::helper('ddg')->log($message)
1077
+ ->rayLog($response->message);
1078
+ }
1079
+
1080
+ return $response;
1081
+ }
1082
+
1083
+ /**
1084
+ * Gets a template by ID.
1085
+ *
1086
+ * @param $templateId
1087
+ * @return object
1088
+ * @throws Exception
1089
+ */
1090
+ public function getApiTemplate($templateId)
1091
+ {
1092
+ $url = self::REST_TEMPLATES . '/' . $templateId;
1093
+ $this->setUrl($url)
1094
+ ->setVerb('GET');
1095
+
1096
+ $response = $this->execute();
1097
+ //log error
1098
+ if (isset($response->message) && ! in_array($response->message, $this->exludeMessages)) {
1099
+ $message = 'GET API CONTACT LIST ' . $response->message;
1100
+ Mage::helper('ddg')->log($message)
1101
+ ->rayLog($response->message);
1102
+ }
1103
+
1104
+ return $response;
1105
+ }
1106
+
1107
+ /**
1108
+ * Adds multiple pieces of transactional data to account asynchronously, returning an identifier that can be used to check for import progress.
1109
+ * @param $collectionName
1110
+ * @param $transactionalData
1111
+ * @return object
1112
+ */
1113
+ public function postAccountTransactionalDataImport($transactionalData, $collectionName = 'Catalog_Default')
1114
+ {
1115
+ $orders = array();
1116
+ foreach ($transactionalData as $one) {
1117
+ if (isset($one->id)) {
1118
+ $orders[] = array(
1119
+ 'Key' => $one->id,
1120
+ 'ContactIdentifier' => 'account',
1121
+ 'Json' => json_encode($one->expose())
1122
+ );
1123
+ }
1124
+ }
1125
+ $url = self::REST_TRANSACTIONAL_DATA_IMPORT . $collectionName;
1126
+ $this->setURl($url)
1127
+ ->setVerb('POST')
1128
+ ->buildPostBody($orders);
1129
+
1130
+ $response = $this->execute();
1131
+ //log error
1132
+ if (isset($response->message) && ! in_array($response->message, $this->exludeMessages)) {
1133
+ $message = ' SEND MULTI TRANSACTIONAL DATA TO ACCOUNT' . $response->message;
1134
+ Mage::helper('ddg')->log($message)
1135
+ ->rayLog($response->message);
1136
+ }
1137
+
1138
+ return $response;
1139
+ }
1140
+
1141
+ public function getCampaignsWithActivitySinceDate($dateTime)
1142
+ {
1143
+ $url = self::REST_DATA_FIELDS_CAMPAIGNS . '/with-activity-since/' . $dateTime;
1144
+
1145
+ $this->setUrl($url)
1146
+ ->setVerb('GET');
1147
+
1148
+ $response = $this->execute();
1149
+ //log error
1150
+ if (isset($response->message) && ! in_array($response->message, $this->exludeMessages)) {
1151
+ $message = 'GET CAMPAIGNS WITH ACTIVITY SINCE DATE ' . $response->message;
1152
+ Mage::helper('ddg')->log($message)
1153
+ ->rayLog($response->message);
1154
+ }
1155
+
1156
+ return $response;
1157
+ }
1158
+
1159
+ public function getCampaignActivityByContactId($campaignId, $contactId)
1160
+ {
1161
+ $url = self::REST_DATA_FIELDS_CAMPAIGNS . '/' . $campaignId . '/activities/' . $contactId;
1162
+
1163
+ $this->setUrl($url)
1164
+ ->setVerb('GET');
1165
+
1166
+ $response = $this->execute();
1167
+ //log error
1168
+ if (isset($response->message) && ! in_array($response->message, $this->exludeMessages)) {
1169
+ $message = 'GET CAMPAIGN ACTIVITY BY CONTACT ID ' . $response->message;
1170
+ Mage::helper('ddg')->log($message)
1171
+ ->rayLog($response->message);
1172
+ }
1173
+
1174
+ return $response;
1175
+ }
1176
+
1177
+ /**
1178
+ * Gets the import status of a previously started contact import.
1179
+ *
1180
+ * @param $importId
1181
+ * @return object
1182
+ */
1183
+ public function getContactsImportByImportId($importId)
1184
+ {
1185
+ $url = self::REST_CONTACTS_IMPORT . $importId;
1186
+
1187
+ $this->setUrl($url)
1188
+ ->setVerb('GET');
1189
+
1190
+ $response = $this->execute();
1191
+ //log error
1192
+ if (isset($response->message) && ! in_array($response->message, $this->exludeMessages)) {
1193
+ $message = 'GET CONTACTS IMPORT BY IMPORT ID ' . $response->message;
1194
+ Mage::helper('ddg')->log($message)
1195
+ ->rayLog($response->message);
1196
+ }
1197
+
1198
+ return $response;
1199
+ }
1200
+
1201
+ /**
1202
+ * Gets the import status of a previously started transactional import.
1203
+ *
1204
+ * @param $importId
1205
+ * @return object
1206
+ */
1207
+ public function getContactsTransactionalDataImportByImportId($importId)
1208
+ {
1209
+ $url = self::REST_TRANSACTIONAL_DATA_IMPORT . $importId;
1210
+
1211
+ $this->setUrl($url)
1212
+ ->setVerb('GET');
1213
+
1214
+ $response = $this->execute();
1215
+ //log error
1216
+ if (isset($response->message) && ! in_array($response->message, $this->exludeMessages)) {
1217
+ $message = 'GET CONTACTS TRANSACTIONAL DATA IMPORT BY IMPORT ID ' . $response->message;
1218
+ Mage::helper('ddg')->log($message)
1219
+ ->rayLog($response->message);
1220
+ }
1221
+
1222
+ return $response;
1223
+ }
1224
+
1225
+ /**
1226
+ * get contact import report faults
1227
+ *
1228
+ * @param $id
1229
+ * @return bool|null
1230
+ * @throws Exception
1231
+ */
1232
+ public function getContactImportReportFaults($id)
1233
+ {
1234
+ $url = self::REST_CONTACTS_IMPORT . $id . '/report-faults';
1235
+ $this->setUrl($url)
1236
+ ->setVerb('GET');
1237
+
1238
+ $this->setIsNotJsonTrue();
1239
+ $response = $this->execute();
1240
+
1241
+ //if string is JSON than there is a error message
1242
+ if(json_decode($response)){
1243
+ //log error
1244
+ if (isset($response->message) && ! in_array($response->message, $this->exludeMessages)) {
1245
+ $message = 'GET CONTACT IMPORT REPORT FAULTS: ' . $response->message;
1246
+ Mage::helper('ddg')->log($message)
1247
+ ->rayLog($response->message);
1248
+ }
1249
+ return false;
1250
+ }
1251
+
1252
+ return $response;
1253
+ }
1254
+ }
app/code/community/Dotdigitalgroup/Email/Model/Apiconnector/Contact.php ADDED
@@ -0,0 +1,427 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Apiconnector_Contact
4
+ {
5
+ private $_start;
6
+ private $_countCustomers = 0;
7
+
8
+ /**
9
+ * Contact sync.
10
+ *
11
+ * @return array
12
+ */
13
+ public function sync()
14
+ {
15
+ $result = array('success' => true, 'message' => '');
16
+ /** @var Dotdigitalgroup_Email_Helper_Data $helper */
17
+ $helper = Mage::helper('ddg');
18
+ $this->_start = microtime(true);
19
+ //resourse allocation
20
+ $helper->allowResourceFullExecution();
21
+ foreach (Mage::app()->getWebsites(true) as $website) {
22
+ $enabled = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED, $website);
23
+ $sync = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_CONTACT_ENABLED, $website);
24
+ if ($enabled && $sync) {
25
+
26
+ if (!$this->_countCustomers)
27
+ $helper->log('---------- Start customer sync ----------');
28
+ $numUpdated = $this->exportCustomersForWebsite($website);
29
+ // show message for any number of customers
30
+ if ($numUpdated)
31
+ $result['message'] .= '</br>' . $website->getName() . ', updated customers = ' . $numUpdated;
32
+ }
33
+ }
34
+ //sync proccessed
35
+ if ($this->_countCustomers) {
36
+ $message = 'Total time for sync : ' . gmdate( "H:i:s", microtime( true ) - $this->_start ) . ', Total updated = ' . $this->_countCustomers;
37
+ $helper->log( $message );
38
+ $message .= $result['message'];
39
+ $result['message'] = $message;
40
+ }
41
+
42
+ return $result;
43
+ }
44
+
45
+ /**
46
+ * Execute the contact sync for the website
47
+ * number of customer synced.
48
+ * @param Mage_Core_Model_Website $website
49
+ *
50
+ * @return int|void
51
+ */
52
+ public function exportCustomersForWebsite(Mage_Core_Model_Website $website)
53
+ {
54
+ $customers = $headers = $allMappedHash = array();
55
+ $helper = Mage::helper('ddg');
56
+ $pageSize = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_LIMIT, $website);
57
+
58
+ //skip if the mapping field is missing
59
+ if ( !$helper->getCustomerAddressBook($website))
60
+ return 0;
61
+
62
+ $fileHelper = Mage::helper('ddg/file');
63
+ $contactModel = Mage::getModel('ddg_automation/contact');
64
+ $contacts = $contactModel->getContactsToImportForWebsite($website->getId(), $pageSize);
65
+
66
+ // no contacts for this website
67
+ if (!$contacts->getSize())
68
+ return 0;
69
+
70
+ //create customer filename
71
+ $customersFile = strtolower($website->getCode() . '_customers_' . date('d_m_Y_Hi') . '.csv');
72
+ $helper->log('Customers file : ' . $customersFile);
73
+
74
+ //get customer ids
75
+ $customerIds = $contacts->getColumnValues('customer_id');
76
+
77
+ //customer collection
78
+ $customerCollection = $this->getCollection($customerIds, $website->getId());
79
+
80
+ /**
81
+ * HEADERS.
82
+ */
83
+ $mappedHash = $fileHelper->getWebsiteCustomerMappingDatafields($website);
84
+ $headers = $mappedHash;
85
+
86
+ //custom customer attributes
87
+ $customAttributes = $helper->getCustomAttributes($website);
88
+ if ($customAttributes){
89
+ foreach ($customAttributes as $data) {
90
+ $headers[] = $data['datafield'];
91
+ $allMappedHash[$data['attribute']] = $data['datafield'];
92
+ }
93
+ }
94
+ $headers[] = 'Email';
95
+ $headers[] = 'EmailType';
96
+ $fileHelper->outputCSV($fileHelper->getFilePath($customersFile), $headers);
97
+ /**
98
+ * END HEADERS.
99
+ */
100
+
101
+ //customer data
102
+ foreach ($customerCollection as $customer) {
103
+ $connectorCustomer = Mage::getModel('ddg_automation/apiconnector_customer', $mappedHash);
104
+ $connectorCustomer->setCustomerData($customer);
105
+ //count number of customers
106
+ $customers[] = $customer->getId();
107
+
108
+ if ($connectorCustomer) {
109
+ foreach ($customAttributes as $data) {
110
+ $attribute = $data['attribute'];
111
+ $value = $customer->getData($attribute);
112
+ $connectorCustomer->setData($value);
113
+ }
114
+ }
115
+
116
+ //contact email and email type
117
+ $connectorCustomer->setData($customer->getEmail());
118
+ $connectorCustomer->setData('Html');
119
+ // save csv file data for customers
120
+ $fileHelper->outputCSV($fileHelper->getFilePath($customersFile), $connectorCustomer->toCSVArray());
121
+ //clear collection and free memory
122
+ $customer->clearInstance();
123
+ }
124
+
125
+ $customerNum = count($customers);
126
+ $helper->log('Website : ' . $website->getName() . ', customers = ' . $customerNum);
127
+ $helper->log('---------------------------- execution time :' . gmdate("H:i:s", microtime(true) - $this->_start));
128
+
129
+ if (is_file($fileHelper->getFilePath($customersFile))) {
130
+ if ($customerNum > 0) {
131
+ //register in queue with importer
132
+ $check = Mage::getModel('ddg_automation/importer')->registerQueue(
133
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_CONTACT,
134
+ '',
135
+ Dotdigitalgroup_Email_Model_Importer::MODE_BULK,
136
+ $website->getId(),
137
+ $customersFile
138
+ );
139
+
140
+ //set imported
141
+ if ($check) {
142
+ Mage::getResourceModel('ddg_automation/contact')->update($customers);
143
+ }
144
+ }
145
+ }
146
+ $this->_countCustomers += $customerNum;
147
+ return $customerNum;
148
+ }
149
+
150
+ /**
151
+ * Sync a single contact.
152
+ *
153
+ * @param null $contactId
154
+ *
155
+ * @return mixed
156
+ * @throws Mage_Core_Exception
157
+ */
158
+ public function syncContact($contactId = null)
159
+ {
160
+ if ($contactId)
161
+ $contact = Mage::getModel('ddg_automation/contact')->load($contactId);
162
+ else {
163
+ $contact = Mage::registry('current_contact');
164
+ }
165
+ if (! $contact->getId()) {
166
+ Mage::getSingleton('adminhtml/session')->addError('No contact found!');
167
+ return false;
168
+ }
169
+
170
+ $websiteId = $contact->getWebsiteId();
171
+ $website = Mage::app()->getWebsite($websiteId);
172
+ $updated = 0;
173
+ $customers = $headers = $allMappedHash = array();
174
+ $helper = Mage::helper('ddg');
175
+ $helper->log('---------- Start single customer sync ----------');
176
+ //skip if the mapping field is missing
177
+ if(!$helper->getCustomerAddressBook($website))
178
+ return false;
179
+ $fileHelper = Mage::helper('ddg/file');
180
+
181
+ $customerId = $contact->getCustomerId();
182
+ if (!$customerId) {
183
+ Mage::getSingleton('adminhtml/session')->addError('Cannot manually sync guests!');
184
+ return false;
185
+ }
186
+
187
+ //create customer filename
188
+ $customersFile = strtolower($website->getCode() . '_customers_' . date('d_m_Y_Hi') . '.csv');
189
+ $helper->log('Customers file : ' . $customersFile);
190
+
191
+ /**
192
+ * HEADERS.
193
+ */
194
+ $mappedHash = $fileHelper->getWebsiteCustomerMappingDatafields($website);
195
+ $headers = $mappedHash;
196
+ //custom customer attributes
197
+ $customAttributes = $helper->getCustomAttributes($website);
198
+ foreach ($customAttributes as $data) {
199
+ $headers[] = $data['datafield'];
200
+ $allMappedHash[$data['attribute']] = $data['datafield'];
201
+ }
202
+
203
+ $headers[] = 'Email';
204
+ $headers[] = 'EmailType';
205
+ $fileHelper->outputCSV($fileHelper->getFilePath($customersFile), $headers);
206
+ /**
207
+ * END HEADERS.
208
+ */
209
+
210
+ $customerCollection = $this->getCollection(array($customerId), $website->getId());
211
+
212
+ foreach ($customerCollection as $customer) {
213
+ /**
214
+ * DATA.
215
+ */
216
+ $connectorCustomer = Mage::getModel('ddg_automation/apiconnector_customer', $mappedHash);
217
+ $connectorCustomer->setCustomerData($customer);
218
+ //count number of customers
219
+ $customers[] = $connectorCustomer;
220
+ foreach ($customAttributes as $data) {
221
+ $attribute = $data['attribute'];
222
+ $value = $customer->getData($attribute);
223
+ $connectorCustomer->setData($value);
224
+ }
225
+ //contact email and email type
226
+ $connectorCustomer->setData($customer->getEmail());
227
+ $connectorCustomer->setData('Html');
228
+ // save csv file data for customers
229
+ $fileHelper->outputCSV($fileHelper->getFilePath($customersFile), $connectorCustomer->toCSVArray());
230
+
231
+ /**
232
+ * END DATA.
233
+ */
234
+
235
+ $updated++;
236
+ }
237
+
238
+ if (is_file($fileHelper->getFilePath($customersFile))) {
239
+ //import contacts
240
+ if ($updated > 0) {
241
+ //register in queue with importer
242
+ $check = Mage::getModel('ddg_automation/importer')->registerQueue(
243
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_CONTACT,
244
+ '',
245
+ Dotdigitalgroup_Email_Model_Importer::MODE_BULK,
246
+ $website->getId(),
247
+ $customersFile
248
+ );
249
+
250
+ //set imported
251
+ if ($check) {
252
+ Mage::getResourceModel('ddg_automation/contact')->update($customerId);
253
+ }
254
+ }
255
+ }
256
+ return $contact->getEmail();
257
+ }
258
+
259
+
260
+ /**
261
+ * get customer collection
262
+ * @param $customerIds
263
+ * @param $websiteId
264
+ * @return Mage_Eav_Model_Entity_Collection_Abstract
265
+ * @throws Mage_Core_Exception
266
+ */
267
+ public function getCollection($customerIds, $websiteId = 0)
268
+ {
269
+ $customerCollection = Mage::getResourceModel('customer/customer_collection')
270
+ ->addNameToSelect()
271
+ ->addAttributeToSelect('*')
272
+ ->joinAttribute('billing_street', 'customer_address/street', 'default_billing', null, 'left')
273
+ ->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
274
+ ->joinAttribute('billing_country_code', 'customer_address/country_id', 'default_billing', null, 'left')
275
+ ->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
276
+ ->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')
277
+ ->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
278
+ ->joinAttribute('shipping_street', 'customer_address/street', 'default_shipping', null, 'left')
279
+ ->joinAttribute('shipping_city', 'customer_address/city', 'default_shipping', null, 'left')
280
+ ->joinAttribute('shipping_country_code','customer_address/country_id', 'default_shipping', null, 'left')
281
+ ->joinAttribute('shipping_postcode', 'customer_address/postcode', 'default_shipping', null, 'left')
282
+ ->joinAttribute('shipping_telephone', 'customer_address/telephone', 'default_shipping', null, 'left')
283
+ ->joinAttribute('shipping_region', 'customer_address/region', 'default_shipping', null, 'left')
284
+ ->addAttributeToFilter('entity_id', array('in' => $customerIds));
285
+ $customer_log = Mage::getSingleton('core/resource')->getTableName('log_customer');
286
+ $sales_flat_order_grid = Mage::getSingleton('core/resource')->getTableName('sales_flat_order_grid');
287
+ $sales_flat_quote = Mage::getSingleton('core/resource')->getTableName('sales_flat_quote');
288
+ $sales_flat_order = Mage::getSingleton('core/resource')->getTableName('sales_flat_order');
289
+ $sales_flat_order_item = Mage::getSingleton('core/resource')->getTableName('sales_flat_order_item');
290
+ $catalog_category_product_index = Mage::getSingleton('core/resource')->getTableName('catalog_category_product');
291
+ $eav_attribute_option_value = Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value');
292
+ $catalog_product_entity_int = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_int');
293
+ $eav_attribute = Mage::getSingleton('core/resource')->getTableName('eav_attribute');
294
+
295
+
296
+ // get the last login date from the log_customer table
297
+ $customerCollection->getSelect()->columns(
298
+ 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)")));
299
+
300
+ // customer order information
301
+ $alias = 'subselect';
302
+ $statuses = Mage::helper('ddg')->getWebsiteConfig(
303
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_DATA_FIELDS_STATUS, $websiteId
304
+ );
305
+ $statuses = explode(',', $statuses);
306
+ $subselect = Mage::getModel('Varien_Db_Select', Mage::getSingleton('core/resource')->getConnection('core_read'))
307
+ ->from($sales_flat_order_grid, array(
308
+ 'customer_id as s_customer_id',
309
+ 'sum(grand_total) as total_spend',
310
+ 'count(*) as number_of_orders',
311
+ 'avg(grand_total) as average_order_value',
312
+ )
313
+ )
314
+ ->where("status in (?)", $statuses)
315
+ ->group('customer_id')
316
+ ;
317
+
318
+ $columns = array(
319
+ '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)"),
320
+ '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)"),
321
+ '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)"),
322
+ '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)"),
323
+ 'first_category_id' => new Zend_Db_Expr(
324
+ "(
325
+ SELECT ccpi.category_id FROM $sales_flat_order as sfo
326
+ left join $sales_flat_order_item as sfoi on sfoi.order_id = sfo.entity_id
327
+ left join $catalog_category_product_index as ccpi on ccpi.product_id = sfoi.product_id
328
+ WHERE sfo.customer_id = e.entity_id
329
+ ORDER BY sfo.created_at ASC, sfoi.price DESC
330
+ LIMIT 1
331
+ )"
332
+ ),
333
+ 'last_category_id' => new Zend_Db_Expr(
334
+ "(
335
+ SELECT ccpi.category_id FROM $sales_flat_order as sfo
336
+ left join $sales_flat_order_item as sfoi on sfoi.order_id = sfo.entity_id
337
+ left join $catalog_category_product_index as ccpi on ccpi.product_id = sfoi.product_id
338
+ WHERE sfo.customer_id = e.entity_id
339
+ ORDER BY sfo.created_at DESC, sfoi.price DESC
340
+ LIMIT 1
341
+ )"
342
+ ),
343
+ 'product_id_for_first_brand' => new Zend_Db_Expr(
344
+ "(
345
+ SELECT sfoi.product_id FROM $sales_flat_order as sfo
346
+ left join $sales_flat_order_item as sfoi on sfoi.order_id = sfo.entity_id
347
+ WHERE sfo.customer_id = e.entity_id and sfoi.product_type = 'simple'
348
+ ORDER BY sfo.created_at ASC, sfoi.price DESC
349
+ LIMIT 1
350
+ )"
351
+ ),
352
+ 'product_id_for_last_brand' => new Zend_Db_Expr(
353
+ "(
354
+ SELECT sfoi.product_id FROM $sales_flat_order as sfo
355
+ left join $sales_flat_order_item as sfoi on sfoi.order_id = sfo.entity_id
356
+ WHERE sfo.customer_id = e.entity_id and sfoi.product_type = 'simple'
357
+ ORDER BY sfo.created_at DESC, sfoi.price DESC
358
+ LIMIT 1
359
+ )"
360
+ ),
361
+ 'week_day' => new Zend_Db_Expr(
362
+ "(
363
+ SELECT dayname(created_at) as week_day
364
+ FROM $sales_flat_order
365
+ WHERE customer_id = e.entity_id
366
+ GROUP BY week_day
367
+ HAVING COUNT(*) > 0
368
+ ORDER BY (COUNT(*)) DESC
369
+ LIMIT 1
370
+ )"
371
+ ),
372
+ 'month_day' => new Zend_Db_Expr(
373
+ "(
374
+ SELECT monthname(created_at) as month_day
375
+ FROM $sales_flat_order
376
+ WHERE customer_id = e.entity_id
377
+ GROUP BY month_day
378
+ HAVING COUNT(*) > 0
379
+ ORDER BY (COUNT(*)) DESC
380
+ LIMIT 1
381
+ )"
382
+ ),
383
+ 'most_category_id' => new Zend_Db_Expr(
384
+ "(
385
+ SELECT ccpi.category_id FROM $sales_flat_order as sfo
386
+ LEFT JOIN $sales_flat_order_item as sfoi on sfoi.order_id = sfo.entity_id
387
+ LEFT JOIN $catalog_category_product_index as ccpi on ccpi.product_id = sfoi.product_id
388
+ WHERE sfo.customer_id = e.entity_id AND ccpi.category_id is not null
389
+ GROUP BY category_id
390
+ HAVING COUNT(sfoi.product_id) > 0
391
+ ORDER BY COUNT(sfoi.product_id) DESC
392
+ LIMIT 1
393
+ )"
394
+ ),
395
+
396
+ 'most_brand' => new Zend_Db_Expr('NULL')
397
+ );
398
+
399
+ $brand = Mage::helper('ddg')->getWebsiteConfig(
400
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_DATA_FIELDS_BRAND_ATTRIBUTE, $websiteId
401
+ );
402
+
403
+ if($brand){
404
+ $columns['most_brand'] = new Zend_Db_Expr(
405
+ "(
406
+ SELECT eaov.value from $sales_flat_order sfo
407
+ LEFT JOIN $sales_flat_order_item as sfoi on sfoi.order_id = sfo.entity_id
408
+ LEFT JOIN $catalog_product_entity_int pei on pei.entity_id = sfoi.product_id
409
+ LEFT JOIN $eav_attribute ea ON pei.attribute_id = ea.attribute_id
410
+ LEFT JOIN $eav_attribute_option_value as eaov on pei.value = eaov.option_id
411
+ WHERE sfo.customer_id = e.entity_id AND ea.attribute_code = '$brand' AND eaov.value is not null
412
+ GROUP BY eaov.value
413
+ HAVING count(*) > 0
414
+ ORDER BY count(*) DESC
415
+ LIMIT 1
416
+ )"
417
+ );
418
+ }
419
+
420
+ $customerCollection->getSelect()->columns($columns);
421
+
422
+ $customerCollection->getSelect()
423
+ ->joinLeft(array($alias => $subselect), "{$alias}.s_customer_id = e.entity_id");
424
+
425
+ return $customerCollection;
426
+ }
427
+ }
app/code/community/Dotdigitalgroup/Email/Model/Apiconnector/Customer.php ADDED
@@ -0,0 +1,924 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Apiconnector_Customer
4
+ {
5
+
6
+ public $customer;
7
+ public $customerData;
8
+ public $reviewCollection;
9
+
10
+ //enterprise reward
11
+ public $reward;
12
+
13
+ public $rewardCustomer;
14
+ public $rewardLastSpent = "";
15
+ public $rewardLastEarned = "";
16
+ public $rewardExpiry = "";
17
+
18
+ protected $_mapping_hash;
19
+
20
+ private $subscriber_status = array(
21
+ Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED => 'Subscribed',
22
+ Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE => 'Not Active',
23
+ Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED => 'Unsubscribed',
24
+ Mage_Newsletter_Model_Subscriber::STATUS_UNCONFIRMED => 'Unconfirmed'
25
+ );
26
+
27
+ private $attribute_check = false;
28
+
29
+ /**
30
+ * constructor, mapping hash to map.
31
+ *
32
+ * @param $mappingHash
33
+ */
34
+ public function __construct( $mappingHash)
35
+ {
36
+ $this->setMappigHash($mappingHash);
37
+ }
38
+
39
+ /**
40
+ * Set key value data.
41
+ *
42
+ * @param $data
43
+ */
44
+ public function setData($data)
45
+ {
46
+ $this->customerData[] = $data;
47
+ }
48
+
49
+ /**
50
+ * Set customer data.
51
+ *
52
+ * @param Mage_Customer_Model_Customer $customer
53
+ */
54
+ public function setCustomerData(Mage_Customer_Model_Customer $customer)
55
+ {
56
+ $this->customer = $customer;
57
+ $this->setReviewCollection();
58
+ $website = $customer->getStore()->getWebsite();
59
+
60
+ if ($website && Mage::helper('ddg')->isSweetToothToGo($website))
61
+ $this->setRewardCustomer($customer);
62
+
63
+ foreach ($this->getMappingHash() as $key => $field) {
64
+
65
+ /**
66
+ * call user function based on the attribute mapped.
67
+ */
68
+ $function = 'get';
69
+ $exploded = explode('_', $key);
70
+ foreach ($exploded as $one) {
71
+ $function .= ucfirst($one);
72
+ }
73
+ try{
74
+ $value = call_user_func(array('self', $function));
75
+ $this->customerData[$key] = $value;
76
+ }catch (Exception $e){
77
+ Mage::logException($e);
78
+ }
79
+ }
80
+ }
81
+
82
+ public function setReviewCollection()
83
+ {
84
+ $customer_id = $this->customer->getId();
85
+ $collection = Mage::getModel('review/review')->getCollection()
86
+ ->addCustomerFilter($customer_id)
87
+ ->setOrder('review_id','DESC');
88
+
89
+ $this->reviewCollection = $collection;
90
+ }
91
+
92
+ public function getReviewCount()
93
+ {
94
+ return count($this->reviewCollection);
95
+ }
96
+
97
+ public function getLastReviewDate(){
98
+
99
+ if(count($this->reviewCollection)){
100
+ $this->reviewCollection->getSelect()->limit(1);
101
+ return $this->reviewCollection->getFirstItem()->getCreatedAt();
102
+ }
103
+ return '';
104
+ }
105
+
106
+ /**
107
+ * Set reward customer
108
+ *
109
+ * @param Mage_Customer_Model_Customer $customer
110
+ */
111
+ public function setRewardCustomer(Mage_Customer_Model_Customer $customer)
112
+ {
113
+ //get tbt reward customer
114
+ $tbt_reward = Mage::getModel('rewards/customer')->getRewardsCustomer($customer);
115
+ $this->rewardCustomer = $tbt_reward;
116
+
117
+ //get transfers collection from tbt reward. only active and order by last updated.
118
+ $lastTransfers = $tbt_reward->getTransfers()
119
+ ->selectOnlyActive()
120
+ ->addOrder('last_update_ts', Varien_Data_Collection::SORT_ORDER_DESC);
121
+
122
+ $spent = $earn = null;
123
+
124
+ foreach($lastTransfers as $transfer) {
125
+ // if transfer quantity is greater then 0 then this is last points earned date. keep checking until earn is not null
126
+ if(is_null($earn) && $transfer->getQuantity() > 0){
127
+ $earn = $transfer->getEffectiveStart();
128
+ }
129
+ // id transfer quantity is less then 0 then this is last points spent date. keep checking until spent is not null
130
+ else if(is_null($spent) && $transfer->getQuantity() < 0) {
131
+ $spent = $transfer->getEffectiveStart();
132
+ }
133
+ // break if both spent and earn are not null (a value has been assigned)
134
+ if(!is_null($spent) && !is_null($earn)) {
135
+ break;
136
+ }
137
+ }
138
+
139
+ // if earn is not null (has a value) then assign the value to property
140
+ if($earn)
141
+ $this->rewardLastEarned = $earn;
142
+ // if spent is not null (has a value) then assign the value to property
143
+ if($spent)
144
+ $this->rewardLastSpent = $spent;
145
+
146
+ $tbt_expiry = Mage::getSingleton('rewards/expiry')
147
+ ->getExpiryDate($tbt_reward);
148
+
149
+ // if there is an expiry (has a value) then assign the value to property
150
+ if($tbt_expiry)
151
+ $this->rewardExpiry = $tbt_expiry;
152
+ }
153
+
154
+ /**
155
+ * get customer id.
156
+ *
157
+ * @return mixed
158
+ */
159
+ public function getCustomerId()
160
+ {
161
+ return $this->customer->getId();
162
+ }
163
+
164
+ /**
165
+ * get first name.
166
+ *
167
+ * @return mixed
168
+ */
169
+ public function getFirstname(){
170
+ return $this->customer->getFirstname();
171
+ }
172
+
173
+ /**
174
+ * get last name.
175
+ *
176
+ * @return mixed
177
+ */
178
+ public function getLastname()
179
+ {
180
+ return $this->customer->getLastname();
181
+ }
182
+
183
+ /**
184
+ * get date of birth.
185
+ *
186
+ * @return mixed
187
+ */
188
+ public function getDob()
189
+ {
190
+ return $this->customer->getDob();
191
+ }
192
+
193
+ /**
194
+ * get customer gender.
195
+ *
196
+ * @return bool|string
197
+ */
198
+ public function getGender()
199
+ {
200
+ return $this->_getCustomerGender();
201
+ }
202
+
203
+ /**
204
+ * get customer prefix.
205
+ *
206
+ * @return mixed
207
+ */
208
+ public function getPrefix()
209
+ {
210
+ return $this->customer->getPrefix();
211
+ }
212
+
213
+ /**
214
+ * get customer suffix.
215
+ *
216
+ * @return mixed
217
+ */
218
+ public function getSuffix()
219
+ {
220
+ return $this->customer->getSuffix();
221
+ }
222
+
223
+ /**
224
+ * get website name.
225
+ *
226
+ * @return string
227
+ */
228
+ public function getWebsiteName()
229
+ {
230
+ return $this->_getWebsiteName();
231
+ }
232
+
233
+ /**
234
+ * get store name.
235
+ *
236
+ * @return null|string
237
+ */
238
+ public function getStoreName()
239
+ {
240
+ return $this->_getStoreName();
241
+ }
242
+
243
+ /**
244
+ * get customer created at date.
245
+ *
246
+ * @return mixed
247
+ */
248
+ public function getCreatedAt()
249
+ {
250
+ return $this->customer->getCreatedAt();
251
+ }
252
+
253
+ /**
254
+ * get customer last logged in date.
255
+ *
256
+ * @return mixed
257
+ */
258
+ public function getLastLoggedDate()
259
+ {
260
+ return $this->customer->getLastLoggedDate();
261
+ }
262
+
263
+ /**
264
+ * get cutomer group.
265
+ *
266
+ * @return string
267
+ */
268
+ public function getCustomerGroup()
269
+ {
270
+ return $this->_getCustomerGroup();
271
+ }
272
+
273
+ /**
274
+ * get billing address line 1.
275
+ *
276
+ * @return string
277
+ */
278
+ public function getBillingAddress1()
279
+ {
280
+ return $this->_getStreet($this->customer->getBillingStreet(), 1);
281
+ }
282
+
283
+ /**
284
+ * get billing address line 2.
285
+ *
286
+ * @return string
287
+ */
288
+ public function getBillingAddress2()
289
+ {
290
+ return $this->_getStreet($this->customer->getBillingStreet(), 2);
291
+ }
292
+
293
+ /**
294
+ * get billing city.
295
+ *
296
+ * @return mixed
297
+ */
298
+ public function getBillingCity()
299
+ {
300
+ return $this->customer->getBillingCity();
301
+ }
302
+
303
+ /**
304
+ * get billing country.
305
+ *
306
+ * @return mixed
307
+ */
308
+ public function getBillingCountry()
309
+ {
310
+ return $this->customer->getBillingCountryCode();
311
+ }
312
+
313
+ /**
314
+ * get billing state.
315
+ *
316
+ * @return mixed
317
+ */
318
+ public function getBillingState()
319
+ {
320
+ return $this->customer->getBillingRegion();
321
+ }
322
+
323
+ /**
324
+ * get billing postcode.
325
+ *
326
+ * @return mixed
327
+ */
328
+ public function getBillingPostcode()
329
+ {
330
+ return $this->customer->getBillingPostcode();
331
+ }
332
+
333
+ /**
334
+ * get billing phone.
335
+ *
336
+ * @return mixed
337
+ */
338
+ public function getBillingTelephone()
339
+ {
340
+ return $this->customer->getBillingTelephone();
341
+ }
342
+
343
+ /**
344
+ * get delivery address line 1.
345
+ *
346
+ * @return string
347
+ */
348
+ public function getDeliveryAddress1()
349
+ {
350
+ return $this->_getStreet($this->customer->getShippingStreet(), 1);
351
+ }
352
+
353
+ /**
354
+ * get delivery addrss line 2.
355
+ *
356
+ * @return string
357
+ */
358
+ public function getDeliveryAddress2()
359
+ {
360
+ return $this->_getStreet($this->customer->getShippingStreet(), 2);
361
+ }
362
+
363
+ /**
364
+ * get delivery city.
365
+ *
366
+ * @return mixed
367
+ */
368
+ public function getDeliveryCity()
369
+ {
370
+ return $this->customer->getShippingCity();
371
+ }
372
+
373
+ /**
374
+ * get delivery country.
375
+ *
376
+ * @return mixed
377
+ */
378
+ public function getDeliveryCountry(){
379
+ return $this->customer->getShippingCountryCode();
380
+ }
381
+
382
+ /**
383
+ * get delivery state.
384
+ *
385
+ * @return mixed
386
+ */
387
+ public function getDeliveryState()
388
+ {
389
+ return $this->customer->getShippingRegion();
390
+ }
391
+
392
+ /**
393
+ * get delivery postcode.
394
+ *
395
+ * @return mixed
396
+ */
397
+ public function getDeliveryPostcode()
398
+ {
399
+ return $this->customer->getShippingPostcode();
400
+ }
401
+
402
+ /**
403
+ * get delivery phone.
404
+ *
405
+ * @return mixed
406
+ */
407
+ public function getDeliveryTelephone(){
408
+ return $this->customer->getShippingTelephone();
409
+ }
410
+
411
+ /**
412
+ * get numbser of orders.
413
+ *
414
+ * @return mixed
415
+ */
416
+ public function getNumberOfOrders()
417
+ {
418
+ return $this->customer->getNumberOfOrders();
419
+ }
420
+
421
+ /**
422
+ * get average order value.
423
+ *
424
+ * @return mixed
425
+ */
426
+ public function getAverageOrderValue()
427
+ {
428
+ return $this->customer->getAverageOrderValue();
429
+ }
430
+
431
+ /**
432
+ * get total spend.
433
+ *
434
+ * @return mixed
435
+ */
436
+ public function getTotalSpend()
437
+ {
438
+ return $this->customer->getTotalSpend();
439
+ }
440
+
441
+ /**
442
+ * get last order date.
443
+ *
444
+ * @return mixed
445
+ */
446
+ public function getLastOrderDate()
447
+ {
448
+ return $this->customer->getLastOrderDate();
449
+ }
450
+
451
+ /**
452
+ * get last order id.
453
+ *
454
+ * @return mixed
455
+ */
456
+ public function getLastOrderId()
457
+ {
458
+ return $this->customer->getLastOrderId();
459
+ }
460
+
461
+ /**
462
+ * get last quote id.
463
+ *
464
+ * @return mixed
465
+ */
466
+ public function getLastQuoteId()
467
+ {
468
+ return $this->customer->getLastQuoteId();
469
+ }
470
+
471
+ /**
472
+ * get cutomer id.
473
+ *
474
+ * @return mixed
475
+ */
476
+ public function getId()
477
+ {
478
+ return $this->customer->getId();
479
+ }
480
+
481
+ /**
482
+ * get customer title.
483
+ *
484
+ * @return mixed
485
+ */
486
+ public function getTitle()
487
+ {
488
+ return $this->customer->getPrefix();
489
+ }
490
+
491
+ /**
492
+ * get total refund value.
493
+ *
494
+ * @return float|int
495
+ */
496
+ public function getTotalRefund()
497
+ {
498
+ $orders = Mage::getResourceModel('sales/order_collection')
499
+ ->addAttributeToFilter('customer_id', $this->customer->getId())
500
+ ;
501
+ $totalRefunded = 0;
502
+ foreach ($orders as $order) {
503
+ $refunded = $order->getTotalRefunded();
504
+ $totalRefunded += $refunded;
505
+ }
506
+
507
+ return $totalRefunded;
508
+ }
509
+
510
+ /**
511
+ * export to CSV.
512
+ *
513
+ * @return mixed
514
+ */
515
+ public function toCSVArray()
516
+ {
517
+ $result = $this->customerData;
518
+ return $result;
519
+ }
520
+
521
+ /**
522
+ * customer gender.
523
+ *
524
+ * @return bool|string
525
+ * @throws Mage_Core_Exception
526
+ */
527
+ private function _getCustomerGender()
528
+ {
529
+ $genderId = $this->customer->getGender();
530
+ if (is_numeric($genderId)) {
531
+ $gender = Mage::getResourceModel('customer/customer')
532
+ ->getAttribute('gender')
533
+ ->getSource()
534
+ ->getOptionText($genderId)
535
+ ;
536
+ return $gender;
537
+ }
538
+
539
+ return '';
540
+ }
541
+
542
+ private function _getStreet($street, $line){
543
+ $street = explode("\n", $street);
544
+ if(isset($street[$line - 1]))
545
+ return $street[$line - 1];
546
+ return '';
547
+ }
548
+
549
+ private function _getWebsiteName(){
550
+ $websiteId = $this->customer->getWebsiteId();
551
+ $website = Mage::app()->getWebsite($websiteId);
552
+ if($website)
553
+ return $website->getName();
554
+
555
+ return '';
556
+ }
557
+
558
+ private function _getStoreName()
559
+ {
560
+ $storeId = $this->customer->getStoreId();
561
+ $store = Mage::app()->getStore($storeId);
562
+ if($store)
563
+ return $store->getName();
564
+
565
+ return '';
566
+ }
567
+
568
+ /**
569
+ * @param mixed $mapping_hash
570
+ */
571
+ public function setMappingHash($mapping_hash)
572
+ {
573
+ $this->_mapping_hash = $mapping_hash;
574
+ }
575
+
576
+ /**
577
+ * @return mixed
578
+ */
579
+ public function getMappingHash()
580
+ {
581
+ return $this->_mapping_hash;
582
+ }
583
+
584
+ private function _getCustomerGroup(){
585
+
586
+ $groupId = $this->customer->getGroupId();
587
+ $group = Mage::getModel('customer/group')->load($groupId);
588
+
589
+ if ($group->getId()) {
590
+ return $group->getCode();
591
+ }
592
+ return '';
593
+ }
594
+
595
+ /**
596
+ * mapping hash value.
597
+ *
598
+ * @param $value
599
+ *
600
+ * @return $this
601
+ */
602
+ public function setMappigHash($value)
603
+ {
604
+ $this->_mapping_hash = $value;
605
+ return $this;
606
+ }
607
+
608
+ public function getRewardReferralUrl()
609
+ {
610
+ if(Mage::helper('ddg')->isSweetToothToGo($this->customer->getStore()->getWebsite()))
611
+ return (string) Mage::helper('rewardsref/url')->getUrl($this->customer);
612
+
613
+ return '';
614
+ }
615
+
616
+ public function getRewardPointBalance()
617
+ {
618
+ return $this->cleanString($this->rewardCustomer->getPointsSummary());
619
+ }
620
+
621
+ public function getRewardPointPending()
622
+ {
623
+ return $this->cleanString($this->rewardCustomer->getPendingPointsSummary());
624
+ }
625
+
626
+ public function getRewardPointPendingTime()
627
+ {
628
+ return $this->cleanString($this->rewardCustomer->getPendingTimePointsSummary());
629
+ }
630
+
631
+ public function getRewardPointOnHold()
632
+ {
633
+ return $this->cleanString($this->rewardCustomer->getOnHoldPointsSummary());
634
+ }
635
+
636
+ public function getRewardPointExpiration()
637
+ {
638
+ if($this->rewardExpiry != "")
639
+ return Mage::getModel('core/date')->date('Y/m/d', strtotime($this->rewardExpiry));
640
+ return $this->rewardExpiry;
641
+ }
642
+
643
+ public function getRewardPointLastSpent()
644
+ {
645
+ return $this->rewardLastSpent;
646
+ }
647
+
648
+ public function getRewardPointLastEarn()
649
+ {
650
+ return $this->rewardLastEarned;
651
+ }
652
+
653
+ public function cleanString($string)
654
+ {
655
+ $cleanedString = preg_replace("/[^0-9]/","",$string);
656
+ if($cleanedString != "")
657
+ return (int) number_format($cleanedString, 0, '.', '');
658
+ return 0;
659
+ }
660
+
661
+ public function getSubscriberStatus()
662
+ {
663
+ $subscriber = Mage::getModel('newsletter/subscriber')->loadByCustomer($this->customer);
664
+ if($subscriber->getCustomerId())
665
+ return $this->subscriber_status[$subscriber->getSubscriberStatus()];
666
+ }
667
+
668
+ /**
669
+ * Reward points balance.
670
+ * @return int
671
+ */
672
+ public function getRewardPoints() {
673
+ if (!$this->reward)
674
+ $this->_setReward();
675
+
676
+ if($this->reward !== true){
677
+ return $this->reward->getPointsBalance();
678
+ }
679
+ return '';
680
+ }
681
+
682
+ /**
683
+ * Currency amount points.
684
+ * @return mixed
685
+ */
686
+ public function getRewardAmount() {
687
+ if (!$this->reward)
688
+ $this->_setReward();
689
+
690
+ if($this->reward !== true){
691
+ return $this->reward->getCurrencyAmount();
692
+ }
693
+ return '';
694
+ }
695
+
696
+ /**
697
+ * Expiration date to use the points.
698
+ * @return string
699
+ */
700
+ public function getExpirationDate()
701
+ {
702
+ //set reward for later use
703
+ if (!$this->reward)
704
+ $this->_setReward();
705
+
706
+ if($this->reward !== true){
707
+ $expiredAt = $this->reward->getExpirationDate();
708
+
709
+ if ($expiredAt) {
710
+ $date = Mage::helper('core')->formatDate($expiredAt, 'short', true);
711
+ } else {
712
+ $date = '';
713
+ }
714
+ return $date;
715
+ }
716
+
717
+ return '';
718
+ }
719
+
720
+
721
+ private function _setReward() {
722
+ if (Mage::getModel('enterprise_reward/reward_history')){
723
+ $collection = Mage::getModel('enterprise_reward/reward_history')->getCollection()
724
+ ->addCustomerFilter($this->customer->getId())
725
+ ->addWebsiteFilter($this->customer->getWebsiteId())
726
+ ->setExpiryConfig(Mage::helper('enterprise_reward')->getExpiryConfig())
727
+ ->addExpirationDate($this->customer->getWebsiteId())
728
+ ->skipExpiredDuplicates()
729
+ ->setDefaultOrder();
730
+
731
+ $item = $collection->setPageSize(1)->setCurPage(1)->getFirstItem();
732
+
733
+ $this->reward = $item;
734
+ }
735
+ else
736
+ $this->reward = true;
737
+ }
738
+
739
+
740
+ /**
741
+ * Customer segments id.
742
+ * @return string
743
+ */
744
+ public function getCustomerSegments()
745
+ {
746
+ $collection = Mage::getModel('ddg_automation/contact')->getCollection()
747
+ ->addFieldToFilter('customer_id', $this->getCustomerId())
748
+ ->addFieldToFilter('website_id', $this->customer->getWebsiteId());
749
+
750
+ $item = $collection->setPageSize(1)->setCurPage(1)->getFirstItem();
751
+
752
+ if ($item)
753
+ return $item->getSegmentIds();
754
+
755
+ return '';
756
+ }
757
+
758
+
759
+
760
+ /**
761
+ * Last used reward points.
762
+ * @return mixed
763
+ */
764
+ public function getLastUsedDate()
765
+ {
766
+ if (Mage::getModel('enterprise_reward/reward_history')) {
767
+ //last used from the reward history based on the points delta used
768
+ $collection = Mage::getModel('enterprise_reward/reward_history')->getCollection()
769
+ ->addCustomerFilter($this->customer->getId())
770
+ ->addWebsiteFilter($this->customer->getWebsiteId())
771
+ ->addFieldToFilter('points_delta', array('lt' => 0))
772
+ ->setDefaultOrder();
773
+
774
+ $item = $collection->setPageSize(1)->setCurPage(1)->getFirstItem();
775
+ $lastUsed = $item->getCreatedAt();
776
+
777
+ //for any valid date
778
+ if ($lastUsed)
779
+ return $date = Mage::helper('core')->formatDate($lastUsed, 'short', true);
780
+ }
781
+ return '';
782
+ }
783
+
784
+
785
+
786
+ /**
787
+ * get most purchased category
788
+ *
789
+ * @return string
790
+ */
791
+ public function getMostPurCategory()
792
+ {
793
+ $id = $this->customer->getMostCategoryId();
794
+ if($id){
795
+ return Mage::getModel('catalog/category')
796
+ ->load($id)
797
+ ->setStoreId($this->customer->getStoreId())
798
+ ->getName();
799
+ }
800
+ return "";
801
+ }
802
+
803
+ /**
804
+ * get most purchased brand
805
+ *
806
+ * @return string
807
+ */
808
+ public function getMostPurBrand()
809
+ {
810
+ $brand = $this->customer->getMostBrand();
811
+ if($brand)
812
+ return $brand;
813
+ return "";
814
+ }
815
+
816
+ /**
817
+ * get most frequent day of purchase
818
+ *
819
+ * @return string
820
+ */
821
+ public function getMostFreqPurDay()
822
+ {
823
+ $day = $this->customer->getWeekDay();
824
+ if($day)
825
+ return $day;
826
+ return "";
827
+ }
828
+
829
+ /**
830
+ * get most frequent month of purchase
831
+ *
832
+ * @return string
833
+ */
834
+ public function getMostFreqPurMon()
835
+ {
836
+ $month = $this->customer->getMonthDay();
837
+ if($month)
838
+ return $month;
839
+ return "";
840
+ }
841
+
842
+ /**
843
+ * get first purchased category
844
+ *
845
+ * @return string
846
+ */
847
+ public function getFirstCategoryPur()
848
+ {
849
+ $id = $this->customer->getFirstCategoryId();
850
+ if($id){
851
+ return Mage::getModel('catalog/category')
852
+ ->load($id)
853
+ ->setStoreId($this->customer->getStoreId())
854
+ ->getName();
855
+ }
856
+ return "";
857
+ }
858
+
859
+ /**
860
+ * get last purchased category
861
+ *
862
+ * @return string
863
+ */
864
+ public function getLastCategoryPur()
865
+ {
866
+ $id = $this->customer->getLastCategoryId();
867
+ if($id){
868
+ return Mage::getModel('catalog/category')
869
+ ->setStoreId($this->customer->getStoreId())
870
+ ->load($id)
871
+ ->getName();
872
+ }
873
+ return "";
874
+ }
875
+
876
+ /**
877
+ * get first purchased brand
878
+ *
879
+ * @return string
880
+ */
881
+ public function getFirstBrandPur()
882
+ {
883
+ $id = $this->customer->getProductIdForFirstBrand();
884
+ return $this->_getBrandValue($id);
885
+ }
886
+
887
+ /**
888
+ * get last purchased brand
889
+ *
890
+ * @return string
891
+ */
892
+ public function getLastBrandPur()
893
+ {
894
+ $id = $this->customer->getProductIdForLastBrand();
895
+ return $this->_getBrandValue($id);
896
+ }
897
+
898
+ private function _getBrandValue($id)
899
+ {
900
+ $attribute = Mage::helper('ddg')->getWebsiteConfig(
901
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_DATA_FIELDS_BRAND_ATTRIBUTE,
902
+ $this->customer->getWebsiteId()
903
+ );
904
+ if($id && $attribute){
905
+ $brand = Mage::getModel('catalog/product')
906
+ ->setStoreId($this->customer->getStoreId())
907
+ ->load($id)
908
+ ->getAttributeText($attribute);
909
+ if($brand)
910
+ return $brand;
911
+ }
912
+ return "";
913
+ }
914
+
915
+ /**
916
+ * get last increment id
917
+ *
918
+ * @return mixed
919
+ */
920
+ public function getLastIncrementId()
921
+ {
922
+ return $this->customer->getLastIncrementId();
923
+ }
924
+ }
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,213 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
44
+ public function enrollment()
45
+ {
46
+ $automationCollection = $this->getCollection()
47
+ ->addFieldToFilter( 'enrolment_status', self::AUTOMATION_STATUS_PENDING )
48
+ ;
49
+ $automationCollection->getSelect()->group( 'automation_type' );
50
+ //limit because of the each contact request to get the id
51
+ $automationCollection->getSelect()->limit( $this->limit );
52
+
53
+ $contacts = array();
54
+
55
+ foreach ( $automationCollection as $automation ) {
56
+ $type = $automation->getAutomationType();
57
+ //customerid, subscriberid, wishlistid..
58
+ $email = $automation->getEmail();
59
+ $this->typeId = $automation->getTypeId();
60
+ $this->websiteId = $automation->getWebsiteId();
61
+ $this->programId = $automation->getProgramId();
62
+ $this->storeName = $automation->getStoreName();
63
+ $contactId = Mage::helper( 'ddg' )->getContactId( $email, $this->websiteId );
64
+ //contact id is valid, can update datafields
65
+ if ( $contactId ) {
66
+ //need to update datafields
67
+ $this->updateDatafieldsByType( $this->automationType, $email );
68
+ $contacts[ $automation->getId() ] = $contactId;
69
+ } else {
70
+ // the contact is suppressed or the request failed
71
+ $automation->setEnrolmentStatus('Suppressed')->save();
72
+ }
73
+ //only for subscribed contacts
74
+ if ( ! empty( $contacts ) && $type != '' && $this->_checkCampignEnrolmentActive( $this->programId ) ) {
75
+ $result = $this->sendContactsToAutomation( array_values( $contacts ) );
76
+ //check for error message
77
+ if ( isset( $result->message ) ) {
78
+ $this->programStatus = 'Failed';
79
+ $this->programMessage = $result->message;
80
+ }
81
+ //program is not active
82
+ } elseif ( $this->programMessage == 'Error: ERROR_PROGRAM_NOT_ACTIVE ' ) {
83
+ $this->programStatus = 'Deactivated';
84
+ }
85
+ }
86
+
87
+ //update contacts with the new status, and log the error message if failes
88
+ $this->getResource()->updateContacts($contacts, $this->programStatus, $this->programMessage);
89
+
90
+ }
91
+ /**
92
+ * update single contact datafields for this automation type.
93
+ *
94
+ * @param $type
95
+ */
96
+ public function updateDatafieldsByType($type, $email )
97
+ {
98
+ switch($type) {
99
+ case self::AUTOMATION_TYPE_NEW_CUSTOMER :
100
+ $this->_updateDefaultDatafields($email);
101
+ break;
102
+ case self::AUTOMATION_TYPE_NEW_SUBSCRIBER :
103
+ $this->_updateDefaultDatafields($email);
104
+ break;
105
+ case self::AUTOMATION_TYPE_NEW_ORDER :
106
+ $this->_updateNewOrderDatafields($email);
107
+ break;
108
+ case self::AUTOMATION_TYPE_NEW_GUEST_ORDER:
109
+ $this->_updateNewOrderDatafields($email);
110
+ break;
111
+ case self::AUTOMATION_TYPE_NEW_REVIEW :
112
+ $this->_updateNewOrderDatafields($email);
113
+ break;
114
+ case self::AUTOMATION_TYPE_NEW_WISHLIST:
115
+ $this->_updateDefaultDatafields($email);
116
+ break;
117
+ default:
118
+ $this->_updateDefaultDatafields($email);
119
+ break;
120
+ }
121
+ }
122
+ private function _updateDefaultDatafields($email)
123
+ {
124
+ $website = Mage::app()->getWebsite($this->websiteId);
125
+ Mage::helper('ddg')->updateDataFields($email, $website, $this->storeName);
126
+ }
127
+ private function _updateNewOrderDatafields($email)
128
+ {
129
+ $website = Mage::app()->getWebsite($this->websiteId);
130
+ $order = Mage::getModel('sales/order')->load($this->typeId);
131
+ //data fields
132
+ if($last_order_id = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_LAST_ORDER_ID)){
133
+ $data[] = array(
134
+ 'Key' => $last_order_id,
135
+ 'Value' => $order->getId()
136
+ );
137
+ }
138
+ if($order_increment_id = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_LAST_ORDER_INCREMENT_ID)){
139
+ $data[] = array(
140
+ 'Key' => $order_increment_id,
141
+ 'Value' => $order->getIncrementId()
142
+ );
143
+ }
144
+ if($store_name = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_STORE_NAME)){
145
+ $data[] = array(
146
+ 'Key' => $store_name,
147
+ 'Value' => $this->storeName
148
+ );
149
+ }
150
+ if($website_name = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_WEBSITE_NAME)){
151
+ $data[] = array(
152
+ 'Key' => $website_name,
153
+ 'Value' => $website->getName()
154
+ );
155
+ }
156
+ if($last_order_date = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_LAST_ORDER_DATE)){
157
+ $data[] = array(
158
+ 'Key' => $last_order_date,
159
+ 'Value' => $order->getCreatedAt()
160
+ );
161
+ }
162
+ if(($customer_id = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CUSTOMER_ID)) && $order->getCustomerId()){
163
+ $data[] = array(
164
+ 'Key' => $customer_id,
165
+ 'Value' => $order->getCustomerId()
166
+ );
167
+ }
168
+ if(! empty($data)){
169
+ //update data fields
170
+ $client = Mage::helper('ddg')->getWebsiteApiClient($website);
171
+ $client->updateContactDatafieldsByEmail($order->getCustomerEmail(), $data);
172
+ }
173
+ }
174
+ /**
175
+ * Program check if is valid and active.
176
+ * @param $programId
177
+ *
178
+ * @return bool
179
+ */
180
+ private function _checkCampignEnrolmentActive($programId)
181
+ {
182
+ //program is not set
183
+ if (!$programId)
184
+ return false;
185
+ $client = Mage::helper('ddg')->getWebsiteApiClient($this->websiteId);
186
+ $program = $client->getProgramById($programId);
187
+ //program status
188
+ if (isset($program->status))
189
+ $this->programStatus = $program->status;
190
+ if (isset($program->status) && $program->status == 'Active') {
191
+ return true;
192
+ }
193
+ return false;
194
+ }
195
+ /**
196
+ * Enrol contacts for a program.
197
+ * @param $contacts
198
+ *
199
+ * @return null
200
+ */
201
+ public function sendContactsToAutomation($contacts)
202
+ {
203
+ $client = Mage::helper('ddg')->getWebsiteApiClient($this->websiteId);
204
+ $data = array(
205
+ 'Contacts' => $contacts,
206
+ 'ProgramId' => $this->programId,
207
+ 'AddressBooks' => array()
208
+ );
209
+ //api add contact to automation enrolment
210
+ $result = $client->postProgramsEnrolments( $data );
211
+ return $result;
212
+ }
213
+ }
app/code/community/Dotdigitalgroup/Email/Model/Campaign.php ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $collection->getSelect()->limit(1);
68
+
69
+ if ($collection->getSize()) {
70
+ return $collection->getFirstItem();
71
+ } else {
72
+ $this->setQuoteId($quoteId)
73
+ ->setStoreId($storeId);
74
+ }
75
+
76
+ return $this;
77
+ }
78
+
79
+
80
+ /**
81
+ * Sending the campaigns.
82
+ */
83
+ public function sendCampaigns()
84
+ {
85
+ //grab the emails not send
86
+ $emailsToSend = $this->_getEmailCampaigns();
87
+
88
+ foreach ($emailsToSend as $campaign) {
89
+
90
+ $email = $campaign->getEmail();
91
+ $storeId = $campaign->getStoreId();
92
+ $campaignId = $campaign->getCampaignId();
93
+ $store = Mage::app()->getStore($storeId);
94
+ $websiteId = $store->getWebsiteId();
95
+
96
+
97
+ if (!$campaignId) {
98
+ $campaign->setMessage('Missing campaign id: ' . $campaignId)
99
+ ->setIsSent(1)
100
+ ->save();
101
+ continue;
102
+ } elseif (!$email) {
103
+ $campaign->setMessage('Missing email : ' . $email)
104
+ ->setIsSent(1)
105
+ ->save();
106
+ continue;
107
+ }
108
+ try{
109
+ $client = Mage::helper('ddg')->getWebsiteApiClient($websiteId);
110
+ $contactId = Mage::helper('ddg')->getContactId($campaign->getEmail(), $websiteId);
111
+ if(is_numeric($contactId)) {
112
+ $response = $client->postCampaignsSend($campaignId, array($contactId));
113
+ if (isset($response->message)) {
114
+ //update the failed to send email message
115
+ $campaign->setMessage($response->message)->setIsSent(1)->save();
116
+ }
117
+ $now = Mage::getSingleton('core/date')->gmtDate();
118
+ //record suscces
119
+ $campaign->setIsSent(1)
120
+ ->setMessage(NULL)
121
+ ->setSentAt($now)
122
+ ->save();
123
+ }else{
124
+ //update the failed to send email message- error message from post contact
125
+ $campaign->setContactMessage($contactId)->setIsSent(1)->save();
126
+ }
127
+ }catch(Exception $e){
128
+ Mage::logException($e);
129
+ }
130
+ }
131
+ return;
132
+ }
133
+
134
+ /**
135
+ * @return mixed
136
+ */
137
+ private function _getEmailCampaigns()
138
+ {
139
+ $emailCollection = $this->getCollection();
140
+ $emailCollection->addFieldToFilter('is_sent', array('null' => true))
141
+ ->addFieldToFilter('campaign_id', array('notnull' => true));
142
+ $emailCollection->getSelect()->order('campaign_id');
143
+ return $emailCollection;
144
+ }
145
+ }
app/code/community/Dotdigitalgroup/Email/Model/Catalog.php ADDED
@@ -0,0 +1,420 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Catalog extends Mage_Core_Model_Abstract
4
+ {
5
+ private $_start;
6
+ private $_countProducts = 0;
7
+ private $_productIds;
8
+
9
+ /**
10
+ * constructor
11
+ */
12
+ public function _construct()
13
+ {
14
+ parent::_construct();
15
+ $this->_init('ddg_automation/catalog');
16
+ }
17
+
18
+ /**
19
+ * @return $this|Mage_Core_Model_Abstract
20
+ */
21
+ protected function _beforeSave()
22
+ {
23
+ parent::_beforeSave();
24
+ $now = Mage::getSingleton('core/date')->gmtDate();
25
+ if ($this->isObjectNew()) {
26
+ $this->setCreatedAt($now);
27
+ }else {
28
+ $this->setUpdatedAt($now);
29
+ }
30
+ return $this;
31
+ }
32
+
33
+ /**
34
+ * catalog sync
35
+ *
36
+ * @return array
37
+ */
38
+ public function sync()
39
+ {
40
+ $response = array('success' => true, 'message' => '');
41
+ $helper = Mage::helper('ddg');
42
+ $this->_start = microtime(true);
43
+ $importer = Mage::getModel('ddg_automation/importer');
44
+
45
+ //resource allocation
46
+ $helper->allowResourceFullExecution();
47
+ $enabled = Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED);
48
+ $sync = Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_CATALOG_ENABLED);
49
+
50
+ if ($enabled && $sync) {
51
+ $helper->log('---------- Start catalog sync ----------');
52
+
53
+ //remove product with product id set and no product
54
+ $coreResource = Mage::getSingleton('core/resource');
55
+ $write = $coreResource->getConnection('core_write');
56
+ $catalogTable = $coreResource->getTableName('ddg_automation/catalog');
57
+ $select = $write->select();
58
+ $select->reset()
59
+ ->from(
60
+ array('c' => $catalogTable),
61
+ array('c.product_id')
62
+ )
63
+ ->joinLeft(
64
+ array('e' => $coreResource->getTableName('catalog/product')),
65
+ "c.product_id = e.entity_id"
66
+ )
67
+ ->where('e.entity_id is NULL');
68
+ //delete sql statement
69
+ $deleteSql = $select->deleteFromSelect('c');
70
+ //run query
71
+ $write->query($deleteSql);
72
+
73
+ $scope = Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_CATALOG_VALUES);
74
+
75
+ //if only to pull default value
76
+ if($scope == 1){
77
+ $products = $this->_exportCatalog(Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID);
78
+ if ($products) {
79
+ //register in queue with importer
80
+ $check = $importer->registerQueue(
81
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_CATALOG,
82
+ $products,
83
+ Dotdigitalgroup_Email_Model_Importer::MODE_BULK,
84
+ Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID
85
+ );
86
+
87
+ //set imported
88
+ if ($check)
89
+ $this->getResource()->setImported($this->_productIds);
90
+
91
+ //set number of product imported
92
+ $this->_countProducts += count($products);
93
+ }
94
+ //using single api
95
+ $this->_exportInSingle(Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID, 'Catalog_Default', Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID);
96
+ //if to pull store values. will be pulled for each store
97
+ }elseif($scope == 2){
98
+ /** @var $store Mage_Core_Model_Store */
99
+ $stores = Mage::app()->getStores();
100
+ foreach($stores as $store){
101
+ $websiteCode = $store->getWebsite()->getCode();
102
+ $storeCode = $store->getCode();
103
+ $products = $this->_exportCatalog($store);
104
+ if($products){
105
+ $importer = Mage::getModel('ddg_automation/importer');
106
+ //register in queue with importer
107
+ $check = $importer->registerQueue(
108
+ 'Catalog_' . $websiteCode . '_' . $storeCode,
109
+ $products,
110
+ Dotdigitalgroup_Email_Model_Importer::MODE_BULK,
111
+ $store->getWebsite()->getId()
112
+ );
113
+ //set imported
114
+ if ($check)
115
+ $this->getResource()->setImported($this->_productIds);
116
+
117
+ //set number of product imported
118
+ $this->_countProducts += count($products);
119
+ }
120
+ //using single api
121
+ $this->_exportInSingle($store, 'Catalog_' . $websiteCode . '_' . $storeCode, $store->getWebsite()->getId());
122
+ }
123
+ }
124
+ }
125
+
126
+ if ($this->_countProducts) {
127
+ $message = 'Total time for sync : ' . gmdate( "H:i:s", microtime( true ) - $this->_start ) . ', Total synced = ' . $this->_countProducts;
128
+ $helper->log( $message );
129
+ $response['message'] = $message;
130
+ }
131
+ return $response;
132
+ }
133
+
134
+ /**
135
+ * export catalog
136
+ *
137
+ * @param $store
138
+ * @return array|bool
139
+ */
140
+ private function _exportCatalog($store)
141
+ {
142
+ $products = $this->_getProductsToExport($store);
143
+ if($products){
144
+ $this->_productIds = $products->getColumnValues('entity_id');
145
+ $connectorProducts = array();
146
+ foreach($products as $product){
147
+ $connectorProduct = Mage::getModel('ddg_automation/connector_product', $product);
148
+ $connectorProducts[] = $connectorProduct;
149
+ }
150
+ return $connectorProducts;
151
+ }
152
+ return false;
153
+ }
154
+
155
+ /**
156
+ * export in single
157
+ *
158
+ * @param $store
159
+ * @param $collectionName
160
+ * @param $websiteId
161
+ */
162
+ private function _exportInSingle($store, $collectionName, $websiteId)
163
+ {
164
+ $helper = Mage::helper('ddg');
165
+ $this->_productIds = array();
166
+
167
+ $products = $this->_getProductsToExport($store, true);
168
+ if($products){
169
+ foreach($products as $product){
170
+ $connectorProduct = Mage::getModel('ddg_automation/connector_product', $product);
171
+ $helper->log('---------- Start catalog single sync ----------');
172
+
173
+ //register in queue with importer
174
+ $check = Mage::getModel('ddg_automation/importer')->registerQueue(
175
+ $collectionName,
176
+ $connectorProduct,
177
+ Dotdigitalgroup_Email_Model_Importer::MODE_SINGLE,
178
+ $websiteId
179
+ );
180
+
181
+ if ($check) {
182
+ $this->_productIds[] = $product->getId();
183
+ }
184
+ }
185
+
186
+ if(!empty($this->_productIds)){
187
+ $this->getResource()->setImported($this->_productIds, true);
188
+ $this->_countProducts += count($this->_productIds);
189
+ }
190
+ }
191
+ }
192
+
193
+ /**
194
+ * get product collection
195
+ *
196
+ * @param $store
197
+ * @param $modified
198
+ * @return bool|Mage_Catalog_Model_Resource_Product_Collection
199
+ */
200
+ private function _getProductsToExport($store, $modified = false)
201
+ {
202
+ $limit = Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_TRANSACTIONAL_DATA_SYNC_LIMIT);
203
+ $connectorCollection = $this->getCollection();
204
+
205
+ if($modified)
206
+ $connectorCollection->addFieldToFilter('modified', array('eq' => '1'));
207
+ else
208
+ $connectorCollection->addFieldToFilter('imported', array('null' => 'true'));
209
+
210
+ $connectorCollection->setPageSize($limit);
211
+
212
+ if($connectorCollection->getSize()) {
213
+ $product_ids = $connectorCollection->getColumnValues('product_id');
214
+ $productCollection = Mage::getModel('catalog/product')->getCollection();
215
+ $productCollection
216
+ ->addAttributeToSelect('*')
217
+ ->addStoreFilter($store)
218
+ ->addAttributeToFilter('entity_id', array('in' => $product_ids));
219
+
220
+ //visibility filter
221
+ if($visibility = Mage::getStoreConfig(
222
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_CATALOG_VISIBILITY)){
223
+ $visibility = explode(',', $visibility);
224
+ $productCollection->addAttributeToFilter('visibility', array('in' => $visibility));
225
+ }
226
+
227
+ //type filter
228
+ if($type = Mage::getStoreConfig(
229
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_CATALOG_TYPE)){
230
+ $type = explode(',', $type);
231
+ $productCollection->addAttributeToFilter('type_id', array('in' => $type));
232
+ }
233
+
234
+ $productCollection
235
+ ->addWebsiteNamesToResult()
236
+ ->addFinalPrice()
237
+ ->addCategoryIds()
238
+ ->addOptionsToResult();
239
+
240
+ return $productCollection;
241
+ }
242
+ return false;
243
+ }
244
+
245
+ /**
246
+ * product save after event processor
247
+ *
248
+ * @param Varien_Event_Observer $observer
249
+ */
250
+ public function handleProductSaveAfter(Varien_Event_Observer $observer)
251
+ {
252
+ try{
253
+ $object = $observer->getEvent()->getDataObject();
254
+ $productId = $object->getId();
255
+ if($item = $this->_loadProduct($productId)){
256
+ if($item->getImported())
257
+ $item->setModified(1)->save();
258
+ }
259
+ }catch (Exception $e){
260
+ Mage::logException($e);
261
+ }
262
+ }
263
+
264
+ /**
265
+ * product delete after event processor
266
+ *
267
+ * @param Varien_Event_Observer $observer
268
+ */
269
+ public function handleProductDeleteAfter(Varien_Event_Observer $observer)
270
+ {
271
+ try{
272
+ /** @var $object Mage_Catalog_Model_Product */
273
+ $object = $observer->getEvent()->getDataObject();
274
+ $productId = $object->getId();
275
+ if($item = $this->_loadProduct($productId)){
276
+ //if imported delete from account
277
+ if($item->getImported()){
278
+ $this->_deleteFromAccount($productId);
279
+ }
280
+ //delete from table
281
+ $item->delete();
282
+
283
+ }
284
+ }catch (Exception $e){
285
+ Mage::logException($e);
286
+ }
287
+ }
288
+
289
+ /**
290
+ * delete piece of transactional data by key
291
+ *
292
+ * @param $key
293
+ */
294
+ private function _deleteFromAccount($key)
295
+ {
296
+ $enabled = Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED);
297
+ $sync = Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_CATALOG_ENABLED);
298
+ if($enabled && $sync){
299
+ $scope = Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_CATALOG_VALUES);
300
+ if($scope == 1){
301
+ //register in queue with importer
302
+ Mage::getModel('ddg_automation/importer')->registerQueue(
303
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_CATALOG,
304
+ array($key),
305
+ Dotdigitalgroup_Email_Model_Importer::MODE_SINGLE_DELETE,
306
+ Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID
307
+ );
308
+ }
309
+ if($scope == 2){
310
+ $stores = Mage::app()->getStores();
311
+ /** @var $store Mage_Core_Model_Store */
312
+ foreach($stores as $store){
313
+ $websiteCode = $store->getWebsite()->getCode();
314
+ $storeCode = $store->getCode();
315
+
316
+ //register in queue with importer
317
+ Mage::getModel('ddg_automation/importer')->registerQueue(
318
+ 'Catalog_' . $websiteCode . '_' . $storeCode,
319
+ array($key),
320
+ Dotdigitalgroup_Email_Model_Importer::MODE_SINGLE_DELETE,
321
+ $store->getWebsite()->getId()
322
+ );
323
+ }
324
+ }
325
+ }
326
+ }
327
+
328
+ /**
329
+ * load product. return item otherwise create item
330
+ *
331
+ * @param $productId
332
+ * @return bool|Varien_Object
333
+ */
334
+ private function _loadProduct($productId)
335
+ {
336
+ $collection = $this->getCollection()
337
+ ->addFieldToFilter('product_id', $productId)
338
+ ->setPageSize(1);
339
+
340
+ if ($collection->getSize()) {
341
+ return $collection->getFirstItem();
342
+ } else {
343
+ $this->setProductId($productId)->save();
344
+ }
345
+ return false;
346
+ }
347
+
348
+ /**
349
+ * core config data save before event
350
+ *
351
+ * @param Varien_Event_Observer $observer
352
+ * @return $this
353
+ */
354
+ public function handleConfigSaveBefore(Varien_Event_Observer $observer)
355
+ {
356
+ if (!Mage::registry('core_config_data_save_before')){
357
+ if($groups = $observer->getEvent()->getConfigData()->getGroups()){
358
+ if(isset($groups['catalog_sync']['fields']['catalog_values']['value'])){
359
+ $value = $groups['catalog_sync']['fields']['catalog_values']['value'];
360
+ Mage::register('core_config_data_save_before', $value);
361
+ }
362
+ }
363
+ }
364
+
365
+
366
+ if (!Mage::registry('core_config_data_save_before_status')) {
367
+ if ($groups = $observer->getEvent()->getConfigData()->getGroups()) {
368
+ if (isset($groups['data_fields']['fields']['order_statuses']['value'])) {
369
+ $value = $groups['data_fields']['fields']['order_statuses']['value'];
370
+ Mage::register('core_config_data_save_before_status', $value);
371
+ }
372
+ }
373
+ }
374
+
375
+
376
+ return $this;
377
+ }
378
+
379
+ /**
380
+ * core config data save after event
381
+ *
382
+ * @param Varien_Event_Observer $observer
383
+ * @return $this
384
+ */
385
+ public function handleConfigSaveAfter(Varien_Event_Observer $observer)
386
+ {
387
+ try{
388
+ if(!Mage::registry('core_config_data_save_after_done')){
389
+ if($groups = $observer->getEvent()->getConfigData()->getGroups()){
390
+ if(isset($groups['catalog_sync']['fields']['catalog_values']['value'])){
391
+ $configAfter = $groups['catalog_sync']['fields']['catalog_values']['value'];
392
+ $configBefore = Mage::registry('core_config_data_save_before');
393
+ if($configAfter != $configBefore){
394
+ //reset catalog to re-import
395
+ $this->getResource()->reset();
396
+ }
397
+ Mage::register('core_config_data_save_after_done', true);
398
+ }
399
+ }
400
+ }
401
+
402
+ if (!Mage::registry('core_config_data_save_after_done_status')) {
403
+ if ($groups = $observer->getEvent()->getConfigData()->getGroups()) {
404
+ if (isset($groups['data_fields']['fields']['order_statuses']['value'])) {
405
+ $configAfter = $groups['data_fields']['fields']['order_statuses']['value'];
406
+ $configBefore = Mage::registry('core_config_data_save_before_status');
407
+ if ($configAfter != $configBefore) {
408
+ //reset all contacts
409
+ Mage::getResourceModel('ddg_automation/contact')->resetAllContacts();
410
+ }
411
+ Mage::register('core_config_data_save_after_done_status', true);
412
+ }
413
+ }
414
+ }
415
+ }catch (Exception $e){
416
+ Mage::logException($e);
417
+ }
418
+ return $this;
419
+ }
420
+ }
app/code/{local → community}/Dotdigitalgroup/Email/Model/Connector/Account.php RENAMED
@@ -14,13 +14,18 @@ class Dotdigitalgroup_Email_Model_Connector_Account
14
  private $_mapping_hash;
15
  private $_contacts = array();
16
  private $_orders = array();
 
 
 
17
 
18
  /**
19
- * @param mixed $api_password
 
20
  */
21
  public function setApiPassword($api_password)
22
  {
23
  $this->_api_password = $api_password;
 
24
  }
25
 
26
  /**
@@ -32,11 +37,13 @@ class Dotdigitalgroup_Email_Model_Connector_Account
32
  }
33
 
34
  /**
35
- * @param mixed $api_username
 
36
  */
37
  public function setApiUsername($api_username)
38
  {
39
  $this->_api_username = $api_username;
 
40
  }
41
 
42
  /**
@@ -68,12 +75,11 @@ class Dotdigitalgroup_Email_Model_Connector_Account
68
  */
69
  public function setContacts($contacts)
70
  {
71
- // if(!empty($this->_contacts)){
72
- // $this->_contacts += $contacts;
73
- // }else{
74
-
75
  $this->_contacts[] = $contacts;
76
- //}
77
  }
78
 
79
  /**
@@ -214,5 +220,53 @@ class Dotdigitalgroup_Email_Model_Connector_Account
214
  return $this->_websites;
215
  }
216
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
217
 
 
 
 
 
 
 
 
218
  }
14
  private $_mapping_hash;
15
  private $_contacts = array();
16
  private $_orders = array();
17
+ private $_orderIds = array();
18
+ private $_ordersForSingleSync = array();
19
+ private $_orderIdsForSingleSync = array();
20
 
21
  /**
22
+ * @param $api_password
23
+ * @return $this
24
  */
25
  public function setApiPassword($api_password)
26
  {
27
  $this->_api_password = $api_password;
28
+ return $this;
29
  }
30
 
31
  /**
37
  }
38
 
39
  /**
40
+ * @param $api_username
41
+ * @return $this
42
  */
43
  public function setApiUsername($api_username)
44
  {
45
  $this->_api_username = $api_username;
46
+ return $this;
47
  }
48
 
49
  /**
75
  */
76
  public function setContacts($contacts)
77
  {
78
+ if (!empty($this->_contacts)) {
79
+ $this->_contacts += $contacts;
80
+ } else {
 
81
  $this->_contacts[] = $contacts;
82
+ }
83
  }
84
 
85
  /**
220
  return $this->_websites;
221
  }
222
 
223
+ /**
224
+ * @param array $orderIds
225
+ */
226
+ public function setOrderIds($orderIds)
227
+ {
228
+ $this->_orderIds = $orderIds;
229
+ }
230
+
231
+ /**
232
+ * @return array
233
+ */
234
+ public function getOrderIds()
235
+ {
236
+ return $this->_orderIds;
237
+ }
238
+
239
+ /**
240
+ * @param array $orders
241
+ */
242
+ public function setOrdersForSingleSync($orders)
243
+ {
244
+ foreach ($orders as $order) {
245
+ $this->_ordersForSingleSync[$order->id] = $order;
246
+ }
247
+ }
248
+
249
+ /**
250
+ * @return array
251
+ */
252
+ public function getOrdersForSingleSync()
253
+ {
254
+ return $this->_ordersForSingleSync;
255
+ }
256
+
257
+ /**
258
+ * @param array $orderIds
259
+ */
260
+ public function setOrderIdsForSingleSync($orderIds)
261
+ {
262
+ $this->_orderIdsForSingleSync = $orderIds;
263
+ }
264
 
265
+ /**
266
+ * @return array
267
+ */
268
+ public function getOrderIdsForSingleSync()
269
+ {
270
+ return $this->_orderIdsForSingleSync;
271
+ }
272
  }
app/code/community/Dotdigitalgroup/Email/Model/Connector/Campaign.php ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Connector_Campaign
4
+ {
5
+
6
+ public $id;
7
+ public $contacts = array();
8
+ public $emails = array();
9
+ public $emailSendId = array();
10
+ private $_storeId;
11
+
12
+ /**
13
+ * @param mixed $storeId
14
+ */
15
+ public function setStoreId($storeId)
16
+ {
17
+ $this->_storeId = $storeId;
18
+ }
19
+
20
+ /**
21
+ * @return mixed
22
+ */
23
+ public function getStoreId()
24
+ {
25
+ return $this->_storeId;
26
+ }
27
+
28
+ /**
29
+ * @param $emailSendId
30
+ * @return $this
31
+ */
32
+ public function setEmailSendId($emailSendId)
33
+ {
34
+ $this->emailSendId[] = $emailSendId;
35
+ return $this;
36
+ }
37
+
38
+ /**
39
+ * @return array
40
+ */
41
+ public function getEmailSendId()
42
+ {
43
+ return $this->emailSendId;
44
+ }
45
+
46
+ /**
47
+ * @param $contact
48
+ * @return $this
49
+ */
50
+ public function setContactId($contact)
51
+ {
52
+ $this->contacts[] = $contact;
53
+ return $this;
54
+ }
55
+
56
+ /**
57
+ * @return array
58
+ */
59
+ public function getContacts()
60
+ {
61
+ return $this->contacts;
62
+ }
63
+
64
+ /**
65
+ * @param $emails
66
+ * @return $this
67
+ */
68
+ public function setEmails($emails)
69
+ {
70
+ $this->emails = $emails;
71
+ return $this;
72
+ }
73
+
74
+ /**
75
+ * @return array
76
+ */
77
+ public function getEmails()
78
+ {
79
+ return $this->emails;
80
+ }
81
+
82
+ /**
83
+ * @param $id
84
+ * @return $this
85
+ */
86
+ public function setId($id)
87
+ {
88
+ $this->id = $id;
89
+ return $this;
90
+ }
91
+
92
+ /**
93
+ * @return mixed
94
+ */
95
+ public function getId()
96
+ {
97
+ return $this->id;
98
+ }
99
+
100
+ }
app/code/community/Dotdigitalgroup/Email/Model/Connector/Datafield.php ADDED
@@ -0,0 +1,298 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Connector_Datafield
4
+ {
5
+ /**
6
+ * @var string
7
+ */
8
+ public $name;
9
+ /**
10
+ * @var string
11
+ */
12
+ public $type;
13
+ /**
14
+ * @var string
15
+ */
16
+ public $visibility;
17
+ /**
18
+ * @var string
19
+ */
20
+ public $defaultValue;
21
+ /**
22
+ * Contact datafields.
23
+ * @var array
24
+ */
25
+ public $datafields = array();
26
+
27
+ /**
28
+ * Contact default datafields.
29
+ *
30
+ * @var array
31
+ */
32
+ private $_contactDatafields = array(
33
+ 'customer_id' => array(
34
+ 'name' => 'CUSTOMER_ID',
35
+ 'type' => 'numeric',
36
+ 'visibility' => 'private',
37
+ ),
38
+ 'firstname' => array(
39
+ 'name' => 'FIRSTNAME',
40
+ 'type' => 'string',
41
+ 'visibility' => 'private',
42
+ ),
43
+ 'lastname' => array(
44
+ 'name' => 'LASTNAME',
45
+ 'type' => 'string',
46
+ 'visibility' => 'private',
47
+ ),
48
+ 'gender' => array(
49
+ 'name' => 'GENDER',
50
+ 'type' => 'string',
51
+ 'visibility' => 'private',
52
+ ),
53
+ 'dob' => array(
54
+ 'name' => 'DOB',
55
+ 'type' => 'date',
56
+ 'visibility' => 'private',
57
+ ),
58
+ 'title' => array(
59
+ 'name' => 'TITLE',
60
+ 'type' => 'string',
61
+ 'visibility' => 'private',
62
+ ),
63
+ 'website_name' => array(
64
+ 'name' => 'WEBSITE_NAME',
65
+ 'type' => 'string',
66
+ 'visibility' => 'private',
67
+ ),
68
+ 'store_name' => array(
69
+ 'name' => 'STORE_NAME',
70
+ 'type' => 'string',
71
+ 'visibility' => 'private',
72
+ ),
73
+ 'created_at' => array(
74
+ 'name' => 'ACCOUNT_CREATED_DATE',
75
+ 'type' => 'date',
76
+ 'visibility' => 'private',
77
+ ),
78
+ 'last_logged_date' => array(
79
+ 'name' => 'LAST_LOGGEDIN_DATE',
80
+ 'type' => 'date',
81
+ 'visibility' => 'private',
82
+ ),
83
+ 'customer_group' => array(
84
+ 'name' => 'CUSTOMER_GROUP',
85
+ 'type' => 'string',
86
+ 'visibility' => 'private',
87
+ ),
88
+ 'billing_address_1' => array(
89
+ 'name' => 'BILLING_ADDRESS_1',
90
+ 'type' => 'string',
91
+ 'visibility' => 'private',
92
+ 'defaultValue' => ''
93
+ ),
94
+ 'billing_address_2' => array(
95
+ 'name' => 'BILLING_ADDRESS_2',
96
+ 'type' => 'string',
97
+ 'visibility' => 'private',
98
+ ),
99
+ 'billing_state' => array(
100
+ 'name' => 'BILLING_STATE',
101
+ 'type' => 'string',
102
+ 'visibility' => 'private',
103
+ ),
104
+ 'billing_city' => array(
105
+ 'name' => 'BILLING_CITY',
106
+ 'type' => 'string',
107
+ 'visibility' => 'private',
108
+ ),
109
+ 'billing_country' => array(
110
+ 'name' => 'BILLING_COUNTRY',
111
+ 'type' => 'string',
112
+ 'visibility' => 'private',
113
+ ),
114
+ 'billing_postcode' => array(
115
+ 'name' => 'BILLING_POSTCODE',
116
+ 'type' => 'string',
117
+ 'visibility' => 'private',
118
+ ),
119
+ 'billing_telephone' => array(
120
+ 'name' => 'BILLING_TELEPHONE',
121
+ 'type' => 'string',
122
+ 'visibility' => 'private',
123
+ ),
124
+ 'delivery_address_1' => array(
125
+ 'name' => 'DELIVERY_ADDRESS_1',
126
+ 'type' => 'string',
127
+ 'visibility' => 'private',
128
+ ),
129
+ 'delivery_address_2' => array(
130
+ 'name' => 'DELIVERY_ADDRESS_2',
131
+ 'type' => 'string',
132
+ 'visibility' => 'private',
133
+ ),
134
+ 'delivery_state' => array(
135
+ 'name' => 'DELIVERY_STATE',
136
+ 'type' => 'string',
137
+ 'visibility' => 'private',
138
+ ),
139
+ 'delivery_city' => array(
140
+ 'name' => 'DELIVERY_CITY',
141
+ 'type' => 'string',
142
+ 'visibility' => 'private',
143
+ ),
144
+ 'delivery_country' => array(
145
+ 'name' => 'DELIVERY_COUNTRY',
146
+ 'type' => 'string',
147
+ 'visibility' => 'private',
148
+ ),
149
+ 'delivery_postcode' => array(
150
+ 'name' => 'DELIVERY_POSTCODE',
151
+ 'type' => 'string',
152
+ 'visibility' => 'private',
153
+ ),
154
+ 'delivery_telephone' => array(
155
+ 'name' => 'DELIVERY_TELEPHONE',
156
+ 'type' => 'string',
157
+ 'visibility' => 'private',
158
+ ),
159
+ 'number_of_orders' => array(
160
+ 'name' => 'NUMBER_OF_ORDERS',
161
+ 'type' => 'numeric',
162
+ 'visibility' => 'private',
163
+ ),
164
+ 'total_spend' => array(
165
+ 'name' => 'TOTAL_SPEND',
166
+ 'type' => 'numeric',
167
+ 'visibility' => 'private',
168
+ ),
169
+ 'average_order_value' => array(
170
+ 'name' => 'AVERAGE_ORDER_VALUE',
171
+ 'type' => 'numeric',
172
+ 'visibility' => 'private',
173
+ ),
174
+ 'last_order_date' => array(
175
+ 'name' => 'LAST_ORDER_DATE',
176
+ 'type' => 'date',
177
+ 'visibility' => 'private',
178
+ ),
179
+ 'last_order_id' => array(
180
+ 'name' => 'LAST_ORDER_ID',
181
+ 'type' => 'numeric',
182
+ 'visibility' => 'private',
183
+ ),
184
+ 'last_increment_id' => array(
185
+ 'name' => 'LAST_INCREMENT_ID',
186
+ 'type' => 'numeric',
187
+ 'visibility' => 'private',
188
+ ),
189
+ 'last_quote_id' => array(
190
+ 'name' => 'LAST_QUOTE_ID',
191
+ 'type' => 'numeric',
192
+ 'visibility' => 'private',
193
+ ),
194
+ 'total_refund' => array(
195
+ 'name' => 'TOTAL_REFUND',
196
+ 'type' => 'numeric',
197
+ 'visibility' => 'private',
198
+ ),
199
+ 'review_count' => array(
200
+ 'name' => 'REVIEW_COUNT',
201
+ 'type' => 'numeric',
202
+ 'visibility' => 'private',
203
+ ),
204
+ 'last_review_date' => array(
205
+ 'name' => 'LAST_REVIEW_DATE',
206
+ 'type' => 'date',
207
+ 'visibility' => 'private',
208
+ ),
209
+ 'subscriber_status' => array(
210
+ 'name' => 'SUBSCRIBER_STATUS',
211
+ 'type' => 'string',
212
+ 'visibility' => 'private',
213
+ ),
214
+ 'most_pur_category' => array(
215
+ 'name' => 'MOST_PUR_CATEGORY',
216
+ 'type' => 'string',
217
+ 'visibility' => 'private',
218
+ ),
219
+ 'most_pur_brand' => array(
220
+ 'name' => 'MOST_PUR_BRAND',
221
+ 'type' => 'string',
222
+ 'visibility' => 'private',
223
+ ),
224
+ 'most_freq_pur_day' => array(
225
+ 'name' => 'MOST_FREQ_PUR_DAY',
226
+ 'type' => 'string',
227
+ 'visibility' => 'private',
228
+ ),
229
+ 'most_freq_pur_mon' => array(
230
+ 'name' => 'MOST_FREQ_PUR_MON',
231
+ 'type' => 'string',
232
+ 'visibility' => 'private',
233
+ ),
234
+ 'first_category_pur' => array(
235
+ 'name' => 'FIRST_CATEGORY_PUR',
236
+ 'type' => 'string',
237
+ 'visibility' => 'private',
238
+ ),
239
+ 'last_category_pur' => array(
240
+ 'name' => 'LAST_CATEGORY_PUR',
241
+ 'type' => 'string',
242
+ 'visibility' => 'private',
243
+ ),
244
+ 'first_brand_pur' => array(
245
+ 'name' => 'FIRST_BRAND_PUR',
246
+ 'type' => 'string',
247
+ 'visibility' => 'private',
248
+ ),
249
+ 'last_brand_pur' => array(
250
+ 'name' => 'LAST_BRAND_PUR',
251
+ 'type' => 'string',
252
+ 'visibility' => 'private',
253
+ ),
254
+ 'abandoned_prod_name' => array(
255
+ 'name' => 'ABANDONED_PROD_NAME',
256
+ 'type' => 'string',
257
+ 'visibility' => 'private',
258
+ ),
259
+ );
260
+
261
+ /**
262
+ * @param array $contactDatafields
263
+ */
264
+ public function setContactDatafields($contactDatafields)
265
+ {
266
+ $this->_contactDatafields = $contactDatafields;
267
+ }
268
+
269
+ /**
270
+ * @return array
271
+ */
272
+ public function getContactDatafields()
273
+ {
274
+ return $this->_contactDatafields;
275
+ }
276
+
277
+ /**
278
+ * set a single datafield.
279
+ *
280
+ * @param $name
281
+ * @param $value
282
+ * @param string $type
283
+ * @param string $visibility
284
+ *
285
+ * @return array
286
+ */
287
+ public function setDatafield($name, $value, $type = 'string', $visibility = 'private')
288
+ {
289
+ $this->datafields[] = array(
290
+ 'name' => $name,
291
+ 'value' => $value,
292
+ 'type' => $type,
293
+ 'visibility' => $visibility
294
+ );
295
+ return $this->datafields;
296
+ }
297
+
298
+ }
app/code/community/Dotdigitalgroup/Email/Model/Connector/Order.php ADDED
@@ -0,0 +1,467 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Connector_Order
4
+ {
5
+ /**
6
+ * Order Increment ID
7
+ * @var string
8
+ */
9
+ public $id;
10
+ /**
11
+ * Email
12
+ * @var string
13
+ */
14
+ public $email;
15
+ /**
16
+ * @var int
17
+ */
18
+ public $quote_id;
19
+ /**
20
+ * @var string
21
+ */
22
+ public $store_name;
23
+ /**
24
+ * @var string
25
+ */
26
+ public $purchase_date;
27
+ /**
28
+ * @var string
29
+ */
30
+ public $delivery_address;
31
+ /**
32
+ * @var string
33
+ */
34
+ public $billing_address;
35
+ /**
36
+ * @var array
37
+ */
38
+ public $products = array();
39
+ /**
40
+ * @var float
41
+ */
42
+ public $order_subtotal;
43
+ /**
44
+ * @var float
45
+ */
46
+ public $discount_ammount;
47
+ /**
48
+ * @var float
49
+ */
50
+ public $order_total;
51
+ /**
52
+ * Payment name
53
+ * @var string
54
+ */
55
+ public $payment;
56
+ /**
57
+ * @var string
58
+ */
59
+ public $delivery_method;
60
+ /**
61
+ * @var float
62
+ */
63
+ public $delivery_total;
64
+ /**
65
+ * @var string
66
+ */
67
+ public $currency;
68
+
69
+
70
+ public $couponCode;
71
+
72
+ /**
73
+ * @var array
74
+ */
75
+ public $custom = array();
76
+
77
+ /**
78
+ * @var string
79
+ */
80
+ public $order_status;
81
+
82
+ private $_attributeSet;
83
+
84
+ /**
85
+ * set the order information
86
+ * @param Mage_Sales_Model_Order $orderData
87
+ */
88
+ public function setOrderData(Mage_Sales_Model_Order $orderData)
89
+ {
90
+ $this->id = $orderData->getIncrementId();
91
+ $this->quote_id = $orderData->getQuoteId();
92
+ $this->email = $orderData->getCustomerEmail();
93
+ $this->store_name = $orderData->getStoreName();
94
+
95
+ $created_at = new Zend_Date($orderData->getCreatedAt(), Zend_Date::ISO_8601);
96
+
97
+ $this->purchase_date = $created_at->toString(Zend_Date::ISO_8601);
98
+ $this->delivery_method = $orderData->getShippingDescription();
99
+ $this->delivery_total = $orderData->getShippingAmount();
100
+ $this->currency = $orderData->getStoreCurrencyCode();
101
+
102
+ if ($payment = $orderData->getPayment())
103
+ $this->payment = $payment->getMethodInstance()->getTitle();
104
+ $this->couponCode = $orderData->getCouponCode();
105
+
106
+ //set order custom attributes
107
+ $this->_setOrderCustomAttributes($orderData);
108
+ //billing
109
+ $this->_setBillingData($orderData);
110
+ //shipping
111
+ $this->_setShippingData($orderData);
112
+ //order items
113
+ $this->_setOrderItems($orderData);
114
+ //sales data
115
+ $this->order_subtotal = (float)number_format($orderData->getData('subtotal'), 2 , '.', '');
116
+ $this->discount_ammount = (float)number_format($orderData->getData('discount_amount'), 2 , '.', '');
117
+ $orderTotal = abs($orderData->getData('grand_total') - $orderData->getTotalRefunded());
118
+ $this->order_total = (float)number_format($orderTotal, 2 , '.', '');
119
+ $this->order_status = $orderData->getStatus();
120
+ }
121
+
122
+ /**
123
+ * Shipping address.
124
+ */
125
+ private function _setShippingData( $orderData ) {
126
+
127
+ if ($orderData->getShippingAddress()) {
128
+ $shippingData = $orderData->getShippingAddress()->getData();
129
+
130
+ $this->delivery_address = array(
131
+ 'delivery_address_1' => $this->_getStreet($shippingData['street'], 1),
132
+ 'delivery_address_2' => $this->_getStreet($shippingData['street'], 2),
133
+ 'delivery_city' => $shippingData['city'],
134
+ 'delivery_region' => $shippingData['region'],
135
+ 'delivery_country' => $shippingData['country_id'],
136
+ 'delivery_postcode' => $shippingData['postcode']
137
+ );
138
+ }
139
+ }
140
+ /**
141
+ * Billing address.
142
+ */
143
+ private function _setBillingData($orderData) {
144
+
145
+ if ($orderData->getBillingAddress()) {
146
+ $billingData = $orderData->getBillingAddress()->getData();
147
+ $this->billing_address = array(
148
+ 'billing_address_1' => $this->_getStreet($billingData['street'], 1),
149
+ 'billing_address_2' => $this->_getStreet($billingData['street'], 2),
150
+ 'billing_city' => $billingData['city'],
151
+ 'billing_region' => $billingData['region'],
152
+ 'billing_country' => $billingData['country_id'],
153
+ 'billing_postcode' => $billingData['postcode'],
154
+ );
155
+ }
156
+ }
157
+
158
+ /**
159
+ * custom order attributes
160
+ */
161
+ private function _setOrderCustomAttributes( $orderData ) {
162
+
163
+ $helper = Mage::helper('ddg');
164
+ $website = Mage::app()->getStore($orderData->getStore())->getWebsite();
165
+ $customAttributes = $helper->getConfigSelectedCustomOrderAttributes($website);
166
+ if($customAttributes) {
167
+ $fields = Mage::getResourceModel( 'ddg_automation/order' )->getOrderTableDescription();
168
+ foreach ( $customAttributes as $customAttribute ) {
169
+ if ( isset( $fields[ $customAttribute ] ) ) {
170
+ $field = $fields[ $customAttribute ];
171
+ $value = $this->_getCustomAttributeValue( $field, $orderData );
172
+ if ( $value ) {
173
+ $this->_assignCustom( $field, $value );
174
+ }
175
+ }
176
+ }
177
+ }
178
+ }
179
+ /**
180
+ * get the street name by line number
181
+ * @param $street
182
+ * @param $line
183
+ * @return string
184
+ */
185
+ private function _getStreet($street, $line)
186
+ {
187
+ $street = explode("\n", $street);
188
+ if ($line == 1) {
189
+ return $street[0];
190
+ }
191
+ if (isset($street[$line -1])) {
192
+
193
+ return $street[$line - 1];
194
+ } else {
195
+
196
+ return '';
197
+ }
198
+ }
199
+
200
+ /**
201
+ * exposes the class as an array of objects.
202
+ * @return array
203
+ */
204
+ public function expose()
205
+ {
206
+ return get_object_vars($this);
207
+
208
+ }
209
+
210
+ private function _getCustomAttributeValue($field, $orderData)
211
+ {
212
+ $type = $field['DATA_TYPE'];
213
+
214
+ $function = 'get';
215
+ $exploded = explode('_', $field['COLUMN_NAME']);
216
+ foreach ($exploded as $one) {
217
+ $function .= ucfirst($one);
218
+ }
219
+
220
+ $value = null;
221
+ try{
222
+ switch ($type) {
223
+ case 'int':
224
+ case 'smallint':
225
+ $value = (int)$orderData->$function();
226
+ break;
227
+
228
+ case 'decimal':
229
+ $value = (float)number_format($orderData->$function(), 2 , '.', '');
230
+ break;
231
+
232
+ case 'timestamp':
233
+ case 'datetime':
234
+ case 'date':
235
+ $date = new Zend_Date($orderData->$function(), Zend_Date::ISO_8601);
236
+ $value = $date->toString(Zend_Date::ISO_8601);
237
+ break;
238
+
239
+ default:
240
+ $value = $orderData->$function();
241
+ }
242
+ }catch (Exception $e){
243
+ Mage::logException($e);
244
+ }
245
+
246
+ return $value;
247
+ }
248
+
249
+ /**
250
+ * create property on runtime
251
+ *
252
+ * @param $field
253
+ * @param $value
254
+ */
255
+ private function _assignCustom($field, $value)
256
+ {
257
+ $this->custom[$field['COLUMN_NAME']] = $value;
258
+ }
259
+
260
+ /**
261
+ * get attributes from attribute set
262
+ *
263
+ * @param $attributeSetId
264
+ * @return array
265
+ */
266
+ private function _getAttributesArray($attributeSetId)
267
+ {
268
+ $result = array();
269
+ $attributes = Mage::getResourceModel('catalog/product_attribute_collection')
270
+ ->setAttributeSetFilter($attributeSetId)
271
+ ->getItems();
272
+
273
+ foreach ($attributes as $attribute) {
274
+ $result[] = $attribute->getAttributeCode();
275
+ }
276
+
277
+ return $result;
278
+ }
279
+
280
+ /**
281
+ * check string length and limit to 250
282
+ *
283
+ * @param $value
284
+ * @return string
285
+ */
286
+ private function _limitLength($value)
287
+ {
288
+ if (strlen($value) > 250)
289
+ $value = substr($value, 0, 250);
290
+
291
+ return $value;
292
+ }
293
+
294
+ /**
295
+ * @param Mage_Sales_Model_Order_Item $orderItem
296
+ * @return array
297
+ */
298
+ private function _getOrderItemOptions($orderItem)
299
+ {
300
+ $orderItemOptions = $orderItem->getProductOptions();
301
+
302
+ //if product doesn't have options
303
+ if (!array_key_exists('options', $orderItemOptions)) {
304
+ return array();
305
+ }
306
+
307
+ $orderItemOptions = $orderItemOptions['options'];
308
+
309
+ //if product options isn't array
310
+ if (!is_array($orderItemOptions)) {
311
+ return array();
312
+ }
313
+
314
+ $options = array();
315
+
316
+ foreach ($orderItemOptions as $orderItemOption) {
317
+ if (array_key_exists('value', $orderItemOption) && array_key_exists('label', $orderItemOption)) {
318
+ $label = str_replace(' ', '-', $orderItemOption['label']);
319
+ $options[][$label] = $orderItemOption['value'];
320
+ }
321
+ }
322
+
323
+ return $options;
324
+
325
+ }
326
+
327
+ /**
328
+ * get attribute set name
329
+ *
330
+ * @param Mage_Catalog_Model_Product $product
331
+ * @return string
332
+ */
333
+ private function _getAttributeSetName(Mage_Catalog_Model_Product $product)
334
+ {
335
+ //check if empty. on true load model and cache result
336
+ if(empty($this->_attributeSet)){
337
+ $this->_loadAttributeModel($product);
338
+ if(empty($this->_attributeSet))
339
+ return '';
340
+ else
341
+ return $this->_attributeSet->getAttributeSetName();
342
+ }
343
+
344
+ //if cached attribute set id equals product's attribute set id
345
+ if($this->_attributeSet->getId() == $product->getAttributeSetId())
346
+ return $this->_attributeSet->getAttributeSetName();
347
+
348
+ //if both above false. load model and cache result
349
+ $this->_loadAttributeModel($product);
350
+ if(empty($this->_attributeSet))
351
+ return '';
352
+ else
353
+ return $this->_attributeSet->getAttributeSetName();
354
+ }
355
+
356
+ /**
357
+ * load attribute model
358
+ *
359
+ * @param Mage_Catalog_Model_Product $product
360
+ */
361
+ private function _loadAttributeModel(Mage_Catalog_Model_Product $product)
362
+ {
363
+ $attributeSetModel = Mage::getModel( "eav/entity_attribute_set" );
364
+ $attributeSetModel->load( $product->getAttributeSetId() );
365
+ if($attributeSetModel->getId())
366
+ $this->_attributeSet = $attributeSetModel;
367
+ }
368
+
369
+ private function _setOrderItems( $orderData ) {
370
+
371
+ $website = Mage::app()->getStore($orderData->getStore())->getWebsite();
372
+
373
+ $syncCustomOption = Mage::helper('ddg')->getWebsiteConfig(
374
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_ORDER_PRODUCT_CUSTOM_OPTIONS,
375
+ $website
376
+ );
377
+
378
+ /**
379
+ * Order items.
380
+ * @var Mage_Sales_Model_Order_Item $productItem
381
+ */
382
+ foreach ($orderData->getAllItems() as $productItem) {
383
+ //product custom options
384
+ $customOptions = array();
385
+ if ($syncCustomOption)
386
+ $customOptions = $this->_getOrderItemOptions($productItem);
387
+
388
+ $product = $productItem->getProduct();
389
+
390
+ if ($product) {
391
+ // category names
392
+ $categoryCollection = $product->getCategoryCollection()
393
+ ->addAttributeToSelect( 'name' );
394
+ $productCat = array();
395
+ foreach ( $categoryCollection as $cat ) {
396
+ $categories = array();
397
+ $categories[] = $cat->getName();
398
+ $productCat[]['Name'] = substr(implode(', ', $categories), 0, 244);
399
+ }
400
+
401
+ $attributes = array();
402
+ //selected attributes from config
403
+ $configAttributes = Mage::helper('ddg')->getWebsiteConfig(
404
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_ORDER_PRODUCT_ATTRIBUTES,
405
+ $orderData->getStore()->getWebsite()
406
+ );
407
+ if ($configAttributes) {
408
+ $configAttributes = explode(',', $configAttributes);
409
+ //attributes from attribute set
410
+ $attributesFromAttributeSet = $this->_getAttributesArray($product->getAttributeSetId());
411
+
412
+ foreach ($configAttributes as $attribute_code) {
413
+ //if config attribute is in attribute set
414
+ if (in_array($attribute_code, $attributesFromAttributeSet)) {
415
+
416
+ //attribute input type
417
+ $inputType = $product->getResource()
418
+ ->getAttribute($attribute_code)
419
+ ->getFrontend()
420
+ ->getInputType();
421
+
422
+ //fetch attribute value from product depending on input type
423
+ switch ($inputType) {
424
+ case 'multiselect':
425
+ case 'select':
426
+ case 'dropdown':
427
+ $value = $product->getAttributeText($attribute_code);
428
+ break;
429
+ default:
430
+ $value = $product->getData($attribute_code);
431
+ break;
432
+ }
433
+
434
+
435
+ if ($value) // check limit on text and assign value to array
436
+ $attributes[][$attribute_code] = $this->_limitLength($value);
437
+ }
438
+ }
439
+ }
440
+
441
+ $attributeSetName = $this->_getAttributeSetName($product);
442
+ $this->products[] = array(
443
+ 'name' => $productItem->getName(),
444
+ 'sku' => $productItem->getSku(),
445
+ 'qty' => (int) number_format( $productItem->getData( 'qty_ordered' ), 2 ),
446
+ 'price' => (float) number_format( $productItem->getPrice(), 2, '.', '' ),
447
+ 'attribute-set' => $attributeSetName,
448
+ 'categories' => $productCat,
449
+ 'attributes' => $attributes,
450
+ 'custom-options' => $customOptions
451
+ );
452
+ } else {
453
+ // when no product information is available limit to this data
454
+ $this->products[] = array(
455
+ 'name' => $productItem->getName(),
456
+ 'sku' => $productItem->getSku(),
457
+ 'qty' => (int) number_format( $productItem->getData( 'qty_ordered' ), 2 ),
458
+ 'price' => (float)number_format($productItem->getPrice(), 2, '.', ''),
459
+ 'attribute-set' => '',
460
+ 'categories' => array(),
461
+ 'attributes' => array(),
462
+ 'custom-options' => $customOptions
463
+ );
464
+ }
465
+ }
466
+ }
467
+ }
app/code/community/Dotdigitalgroup/Email/Model/Connector/Product.php ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ }
151
+
152
+ /**
153
+ * exposes the class as an array of objects.
154
+ * @return array
155
+ */
156
+ public function expose()
157
+ {
158
+ return get_object_vars($this);
159
+ }
160
+
161
+ }
app/code/community/Dotdigitalgroup/Email/Model/Connector/Quote.php ADDED
@@ -0,0 +1,323 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Connector_Quote
4
+ {
5
+ /**
6
+ * @var int
7
+ */
8
+ public $id;
9
+ /**
10
+ * Email
11
+ * @var string
12
+ */
13
+ public $email;
14
+ /**
15
+ * @var string
16
+ */
17
+ public $store_name;
18
+ /**
19
+ * @var string
20
+ */
21
+ public $created_date;
22
+ /**
23
+ * @var string
24
+ */
25
+ public $delivery_address;
26
+ /**
27
+ * @var string
28
+ */
29
+ public $billing_address;
30
+ /**
31
+ * @var array
32
+ */
33
+ public $products = array();
34
+ /**
35
+ * @var float
36
+ */
37
+ public $quote_subtotal;
38
+ /**
39
+ * @var float
40
+ */
41
+ public $discount_amount;
42
+ /**
43
+ * @var float
44
+ */
45
+ public $quote_total;
46
+ /**
47
+ * @var array
48
+ */
49
+ public $categories;
50
+ /**
51
+ * Payment name
52
+ * @var string
53
+ */
54
+ public $payment;
55
+ /**
56
+ * @var string
57
+ */
58
+ public $delivery_method;
59
+ /**
60
+ * @var float
61
+ */
62
+ public $delivery_total;
63
+ /**
64
+ * @var string
65
+ */
66
+ public $currency;
67
+
68
+
69
+ public $couponCode;
70
+
71
+ /**
72
+ * @var array
73
+ */
74
+ public $custom = array();
75
+
76
+ private $_attributeSet;
77
+
78
+ /**
79
+ * set the quote information
80
+ * @param Mage_Sales_Model_Quote $quoteData
81
+ */
82
+ public function __construct(Mage_Sales_Model_Quote $quoteData)
83
+ {
84
+ $this->id = $quoteData->getId();
85
+ $this->email = $quoteData->getCustomerEmail();
86
+ $this->store_name = $quoteData->getStore()->getName();
87
+
88
+ $created_at = new Zend_Date($quoteData->getCreatedAt(), Zend_Date::ISO_8601);
89
+
90
+ $this->created_date = $created_at->toString(Zend_Date::ISO_8601);
91
+ if($quoteData->getShippingAddress()){
92
+ $this->delivery_method = $quoteData->getShippingAddress()->getShippingDescription();
93
+ $this->delivery_total = $quoteData->getShippingAddress()->getShippingAmount();
94
+ }
95
+ $this->currency = $quoteData->getStoreCurrencyCode();
96
+ if ($payment = $quoteData->getPayment())
97
+ $this->payment = $payment->getMethod();
98
+
99
+ $this->couponCode = $quoteData->getCouponCode();
100
+
101
+ /**
102
+ * custom quote attributes
103
+ */
104
+ $helper = Mage::helper('ddg');
105
+ $website = Mage::app()->getStore($quoteData->getStore())->getWebsite();
106
+ $customAttributes = $helper->getConfigSelectedCustomQuoteAttributes($website);
107
+ if($customAttributes){
108
+ $fields = Mage::getResourceModel('ddg_automation/quote')->getQuoteTableDescription();
109
+ foreach($customAttributes as $customAttribute){
110
+ if(isset($fields[$customAttribute])){
111
+ $field = $fields[$customAttribute];
112
+ $value = $this->_getCustomAttributeValue($field, $quoteData);
113
+ if($value)
114
+ $this->_assignCustom($field, $value);
115
+ }
116
+ }
117
+ }
118
+
119
+ /**
120
+ * Billing address.
121
+ */
122
+ if ($quoteData->getBillingAddress()) {
123
+ $billingData = $quoteData->getBillingAddress()->getData();
124
+ $this->billing_address = array(
125
+ 'billing_address_1' => $this->_getStreet($billingData['street'], 1),
126
+ 'billing_address_2' => $this->_getStreet($billingData['street'], 2),
127
+ 'billing_city' => $billingData['city'],
128
+ 'billing_region' => $billingData['region'],
129
+ 'billing_country' => $billingData['country_id'],
130
+ 'billing_postcode' => $billingData['postcode'],
131
+ );
132
+ }
133
+ /**
134
+ * Shipping address.
135
+ */
136
+ if ($quoteData->getShippingAddress()) {
137
+ $shippingData = $quoteData->getShippingAddress()->getData();
138
+
139
+ $this->delivery_address = array(
140
+ 'delivery_address_1' => $this->_getStreet($shippingData['street'], 1),
141
+ 'delivery_address_2' => $this->_getStreet($shippingData['street'], 2),
142
+ 'delivery_city' => $shippingData['city'],
143
+ 'delivery_region' => $shippingData['region'],
144
+ 'delivery_country' => $shippingData['country_id'],
145
+ 'delivery_postcode' => $shippingData['postcode']
146
+ );
147
+ }
148
+
149
+ /**
150
+ * Quote items.
151
+ * @var Mage_Sales_Model_Quote_Item $productItem
152
+ */
153
+ foreach ($quoteData->getAllItems() as $productItem) {
154
+
155
+ $product = $productItem->getProduct();
156
+
157
+ if ($product) {
158
+ // category names
159
+ $categoryCollection = $product->getCategoryCollection()
160
+ ->addAttributeToSelect( 'name' );
161
+
162
+ foreach ( $categoryCollection as $cat ) {
163
+ $categories = array();
164
+ $categories[] = $cat->getName();
165
+ $this->categories[]['Name'] = substr( implode( ', ', $categories ), 0, 244 );
166
+ }
167
+
168
+ //get attribute set name
169
+ $attributeSetName = $this->_getAttributeSetName($product);
170
+ $this->products[] = array(
171
+ 'name' => $productItem->getName(),
172
+ 'sku' => $productItem->getSku(),
173
+ 'qty' => (int) number_format( $productItem->getData( 'qty' ), 2 ),
174
+ 'price' => (float) number_format( $productItem->getPrice(), 2, '.', '' ),
175
+ 'attribute-set' => $attributeSetName
176
+ );
177
+ } else {
178
+ // when no product information is available limit to this data
179
+ $this->products[] = array(
180
+ 'name' => $productItem->getName(),
181
+ 'sku' => $productItem->getSku(),
182
+ 'qty' => (int) number_format( $productItem->getData( 'qty' ), 2 ),
183
+ 'price' => (float) number_format( $productItem->getPrice(), 2, '.', '' )
184
+ );
185
+ }
186
+ }
187
+
188
+ $this->quote_subtotal = (float)number_format($quoteData->getData('subtotal'), 2 , '.', '');
189
+ $discountAmount = $quoteData->getData('subtotal') - $quoteData->getData('subtotal_with_discount');
190
+ $this->discount_amount = (float)number_format($discountAmount, 2 , '.', '');
191
+ $this->quote_total = (float)number_format($quoteData->getData('grand_total'), 2 , '.', '');
192
+
193
+ }
194
+ /**
195
+ * get the street name by line number
196
+ * @param $street
197
+ * @param $line
198
+ * @return string
199
+ */
200
+ private function _getStreet($street, $line)
201
+ {
202
+ $street = explode("\n", $street);
203
+ if ($line == 1) {
204
+ return $street[0];
205
+ }
206
+ if (isset($street[$line -1])) {
207
+
208
+ return $street[$line - 1];
209
+ } else {
210
+
211
+ return '';
212
+ }
213
+ }
214
+
215
+ /**
216
+ * exposes the class as an array of objects.
217
+ * @return array
218
+ */
219
+ public function expose()
220
+ {
221
+ return get_object_vars($this);
222
+
223
+ }
224
+
225
+ /**
226
+ * get custom attribute value
227
+ *
228
+ * @param $field
229
+ * @param $quoteData
230
+ * @return float|int|null|string
231
+ */
232
+ private function _getCustomAttributeValue($field, $quoteData)
233
+ {
234
+ $type = $field['DATA_TYPE'];
235
+
236
+ $function = 'get';
237
+ $exploded = explode('_', $field['COLUMN_NAME']);
238
+ foreach ($exploded as $one) {
239
+ $function .= ucfirst($one);
240
+ }
241
+
242
+ $value = null;
243
+ try{
244
+ switch ($type) {
245
+ case 'int':
246
+ case 'smallint':
247
+ $value = (int)$quoteData->$function();
248
+ break;
249
+
250
+ case 'decimal':
251
+ $value = (float)number_format($quoteData->$function(), 2 , '.', '');
252
+ break;
253
+
254
+ case 'timestamp':
255
+ case 'datetime':
256
+ case 'date':
257
+ $date = new Zend_Date($quoteData->$function(), Zend_Date::ISO_8601);
258
+ $value = $date->toString(Zend_Date::ISO_8601);
259
+ break;
260
+
261
+ default:
262
+ $value = $quoteData->$function();
263
+ }
264
+ }catch (Exception $e){
265
+ Mage::logException($e);
266
+ }
267
+
268
+ return $value;
269
+ }
270
+
271
+ /**
272
+ * create property on runtime
273
+ *
274
+ * @param $field
275
+ * @param $value
276
+ */
277
+ private function _assignCustom($field, $value)
278
+ {
279
+ $this->custom[$field['COLUMN_NAME']] = $value;
280
+ }
281
+
282
+ /**
283
+ * get attribute set name
284
+ *
285
+ * @param Mage_Catalog_Model_Product $product
286
+ * @return string
287
+ */
288
+ private function _getAttributeSetName(Mage_Catalog_Model_Product $product)
289
+ {
290
+ //check if empty. on true load model and cache result
291
+ if(empty($this->_attributeSet)){
292
+ $this->_loadAttributeModel($product);
293
+ if(empty($this->_attributeSet))
294
+ return '';
295
+ else
296
+ return $this->_attributeSet->getAttributeSetName();
297
+ }
298
+
299
+ //if cached attribute set id equals product's attribute set id
300
+ if($this->_attributeSet->getId() == $product->getAttributeSetId())
301
+ return $this->_attributeSet->getAttributeSetName();
302
+
303
+ //if both above false. load model and cache result
304
+ $this->_loadAttributeModel($product);
305
+ if(empty($this->_attributeSet))
306
+ return '';
307
+ else
308
+ return $this->_attributeSet->getAttributeSetName();
309
+ }
310
+
311
+ /**
312
+ * load attribute model
313
+ *
314
+ * @param Mage_Catalog_Model_Product $product
315
+ */
316
+ private function _loadAttributeModel(Mage_Catalog_Model_Product $product)
317
+ {
318
+ $attributeSetModel = Mage::getModel( "eav/entity_attribute_set" );
319
+ $attributeSetModel->load( $product->getAttributeSetId() );
320
+ if($attributeSetModel->getId())
321
+ $this->_attributeSet = $attributeSetModel;
322
+ }
323
+ }
app/code/community/Dotdigitalgroup/Email/Model/Contact.php ADDED
@@ -0,0 +1,238 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Contact extends Mage_Core_Model_Abstract
4
+ {
5
+
6
+ const EMAIL_CONTACT_IMPORTED = 1;
7
+ const EMAIL_CONTACT_NOT_IMPORTED = null;
8
+ const EMAIL_SUBSCRIBER_NOT_IMPORTED = null;
9
+ /**
10
+ * constructor
11
+ */
12
+ public function _construct()
13
+ {
14
+ parent::_construct();
15
+ $this->_init('ddg_automation/contact');
16
+ }
17
+
18
+
19
+ /**
20
+ * @return $this|Mage_Core_Model_Abstract
21
+ */
22
+ protected function _beforeSave()
23
+ {
24
+ parent::_beforeSave();
25
+ $now = Mage::getSingleton('core/date')->gmtDate();
26
+ if ($this->isObjectNew()) {
27
+ $this->setCreatedAt($now);
28
+ }
29
+ return $this;
30
+ }
31
+
32
+ /**
33
+ * Load contact by customer id
34
+ * @param $customerId
35
+ * @return mixed
36
+ */
37
+ public function loadByCustomerId($customerId)
38
+ {
39
+ $collection = $this->getCollection()
40
+ ->addFieldToFilter('customer_id', $customerId)
41
+ ->setPageSize(1);
42
+
43
+ if($collection->count())
44
+ return $collection->getFirstItem();
45
+
46
+ return $this;
47
+ }
48
+
49
+ /**
50
+ * get all customer contacts not imported for a website.
51
+ *
52
+ * @param $websiteId
53
+ * @param int $pageSize
54
+ *
55
+ * @return Dotdigitalgroup_Email_Model_Resource_Contact_Collection
56
+ */
57
+ public function getContactsToImportForWebsite($websiteId, $pageSize = 100)
58
+ {
59
+ $collection = $this->getCollection()
60
+ ->addFieldToFilter('website_id', $websiteId)
61
+ ->addFieldToFilter('email_imported', array('null' => true))
62
+ ->addFieldToFilter('customer_id', array('neq' => '0'));
63
+
64
+
65
+ $collection->getSelect()->limit($pageSize);
66
+
67
+ return $collection;
68
+ }
69
+
70
+ /**
71
+ * Get missing contacts.
72
+ * @param $websiteId
73
+ * @param int $pageSize
74
+ * @return mixed
75
+ */
76
+ public function getMissingContacts($websiteId, $pageSize = 100)
77
+ {
78
+ $collection = $this->getCollection()
79
+ ->addFieldToFilter('contact_id', array('null' => true))
80
+ ->addFieldToFilter('suppressed', array('null' => true))
81
+ ->addFieldToFilter('website_id', $websiteId);
82
+
83
+ $collection->getSelect()->limit($pageSize);
84
+
85
+ return $collection->load();
86
+ }
87
+
88
+ /**
89
+ * Load Contact by Email.
90
+ * @param $email
91
+ * @param $websiteId
92
+ * @return $this
93
+ */
94
+ public function loadByCustomerEmail($email, $websiteId)
95
+ {
96
+ $collection = $this->getCollection()
97
+ ->addFieldToFilter('email', $email)
98
+ ->addFieldToFilter('website_id', $websiteId)
99
+ ->setPageSize(1);
100
+
101
+ if ($collection->getSize()) {
102
+ return $collection->getFirstItem();
103
+ } else {
104
+ $this->setEmail($email)
105
+ ->setWebsiteId($websiteId);
106
+ }
107
+ return $this;
108
+ }
109
+
110
+ /**
111
+ * batch non imported subscribers for a website.
112
+ * @param $website
113
+ * @param int $limit
114
+ *
115
+ * @return Dotdigitalgroup_Email_Model_Resource_Contact_Collection
116
+ */
117
+ public function getSubscribersToImport($website, $limit = 1000)
118
+ {
119
+
120
+ $storeIds = $website->getStoreIds();
121
+ $collection = $this->getCollection()
122
+ ->addFieldToFilter('is_subscriber', array('notnull' => true))
123
+ ->addFieldToFilter('subscriber_imported', array('null' => true))
124
+ ->addFieldToFilter('store_id', array('in' => $storeIds));
125
+
126
+ $collection->getSelect()->limit($limit);
127
+
128
+ return $collection;
129
+ }
130
+
131
+ /**
132
+ * get all not imported guests for a website.
133
+ * @param $website
134
+ *
135
+ * @return Dotdigitalgroup_Email_Model_Resource_Contact_Collection
136
+ */
137
+ public function getGuests($website)
138
+ {
139
+ $guestCollection = $this->getCollection()
140
+ ->addFieldToFilter('is_guest', array('notnull' => true))
141
+ ->addFieldToFilter('email_imported', array('null' => true))
142
+ ->addFieldToFilter('website_id', $website->getId());
143
+ return $guestCollection->load();
144
+ }
145
+
146
+ public function getNumberOfImportedContacs()
147
+ {
148
+ $collection = $this->getCollection()
149
+ ->addFieldToFilter('email_imported', array('notnull' => true));
150
+
151
+ return $collection->getSize();
152
+ }
153
+
154
+ /**
155
+ * Get the number of customers for a website.
156
+ * @param int $websiteId
157
+ *
158
+ * @return int
159
+ */
160
+ public function getNumberCustomerContacts($websiteId = 0)
161
+ {
162
+ $countContacts = Mage::getModel('ddg_automation/contact')->getCollection()
163
+ ->addFieldToFilter('customer_id', array('gt' => '0'))
164
+ ->addFieldToFilter('website_id', $websiteId)
165
+ ->getSize();
166
+ return $countContacts;
167
+ }
168
+
169
+ /**
170
+ *
171
+ * Get number of suppressed contacts as customer.
172
+ * @param int $websiteId
173
+ *
174
+ * @return int
175
+ */
176
+ public function getNumberCustomerSuppressed( $websiteId = 0 )
177
+ {
178
+ $countContacts = Mage::getModel('ddg_automation/contact')->getCollection()
179
+ ->addFieldToFilter('customer_id', array('gt' => 0))
180
+ ->addFieldToFilter('website_id', $websiteId)
181
+ ->addFieldToFilter('suppressed', '1')
182
+ ->getSize();
183
+
184
+ return $countContacts;
185
+ }
186
+
187
+ /**
188
+ * Get number of synced customers.
189
+ * @param int $websiteId
190
+ *
191
+ * @return int
192
+ */
193
+ public function getNumberCustomerSynced( $websiteId = 0 )
194
+ {
195
+ $countContacts = Mage::getModel('ddg_automation/contact')->getCollection()
196
+ ->addFieldToFilter('customer_id', array('gt' => 0))
197
+ ->addFieldToFilter('website_id', $websiteId)
198
+ ->addFieldToFilter('email_imported' , '1')
199
+ ->getSize();
200
+
201
+ return $countContacts;
202
+
203
+ }
204
+
205
+ /**
206
+ * Get number of subscribers synced.
207
+ * @param int $websiteId
208
+ *
209
+ * @return int
210
+ */
211
+ public function getNumberSubscribersSynced( $websiteId = 0 )
212
+ {
213
+ $countContacts = Mage::getModel('ddg_automation/contact')->getCollection()
214
+ ->addFieldToFilter('subscriber_status', Dotdigitalgroup_Email_Model_Newsletter_Subscriber::STATUS_SUBSCRIBED)
215
+ ->addFieldToFilter('subscriber_imported', '1')
216
+ ->addFieldToFilter('website_id', $websiteId)
217
+ ->getSize();
218
+
219
+ return $countContacts;
220
+ }
221
+
222
+ /**
223
+ * Get number of subscribers.
224
+ * @param int $websiteId
225
+ *
226
+ * @return int
227
+ */
228
+ public function getNumberSubscribers( $websiteId = 0 )
229
+ {
230
+
231
+ $countContacts = Mage::getModel('ddg_automation/contact')->getCollection()
232
+ ->addFieldToFilter('subscriber_status', Dotdigitalgroup_Email_Model_Newsletter_Subscriber::STATUS_SUBSCRIBED)
233
+ ->addFieldToFilter('website_id', $websiteId)
234
+ ->getSize();
235
+ return $countContacts;
236
+ }
237
+
238
+ }
app/code/community/Dotdigitalgroup/Email/Model/Controller/Observer.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Controller_Observer
4
+ {
5
+ /**
6
+ * @param $observer
7
+ *
8
+ * @return $this
9
+ */
10
+ public function controllerActionPostdispatch( $observer )
11
+ {
12
+ //event data
13
+ $event = $observer->getEvent();
14
+
15
+ //check for module name is a match for current request
16
+ if ($event->getControllerAction()->getRequest()->getModuleName() == 'connector') {
17
+
18
+ //check if the geoip module is installed
19
+ $modules = Mage::getConfig()->getNode('modules')->children();
20
+ $modulesArray = (array)$modules;
21
+
22
+ //module installed make sure don't redirect
23
+ if (isset($modulesArray['Sandfox_GeoIP'])) {
24
+
25
+ //order id param
26
+ $orderId = $event->getControllerAction()->getRequest()->getParam( 'order_id', false );
27
+
28
+ //order id param is set
29
+ if ( $orderId ) {
30
+ $order = Mage::getModel( 'sales/order' )->load( $orderId );
31
+ $store = Mage::app()->getStore( $order->getStore() );
32
+ //order still exits and store name is different than the order
33
+ if ( $order->getId() && $store->getName() != Mage::app()->getStore()->getName()) {
34
+
35
+ //redirect to original store
36
+ $event->getControllerAction()->getResponse()->setRedirect( $store->getCurrentUrl( false ) );
37
+ }
38
+ }
39
+ }
40
+ }
41
+ return $this;
42
+ }
43
+ }
app/code/community/Dotdigitalgroup/Email/Model/Cron.php ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ //sync guests
118
+ Mage::getModel('ddg_automation/customer_guest')->sync();
119
+ return $result;
120
+ }
121
+
122
+ /**
123
+ * CRON FOR EMAILS SENDING
124
+ */
125
+ public function sendEmails()
126
+ {
127
+ Mage::getModel('ddg_automation/campaign')->sendCampaigns();
128
+
129
+ return $this;
130
+ }
131
+
132
+ /**
133
+ * CLEAN ARHIVED FOLDERS
134
+ */
135
+ public function cleaning()
136
+ {
137
+ $helper = Mage::helper('ddg/file');
138
+ $archivedFolder = $helper->getArchiveFolder();
139
+ $result = $helper->deleteDir($archivedFolder);
140
+ $message = 'Cleaning cronjob result : ' . $result;
141
+ $helper->log($message);
142
+ Mage::helper('ddg')->rayLog($message, 'model/cron.php');
143
+ return $result;
144
+ }
145
+
146
+
147
+ /**
148
+ * Last customer sync date.
149
+ * @return bool|string
150
+ */
151
+ public function getLastCustomerSync(){
152
+
153
+ $schedules = Mage::getModel('cron/schedule')->getCollection();
154
+ $schedules->getSelect()->limit(1)->order('executed_at DESC');
155
+ $schedules->addFieldToFilter('status', Mage_Cron_Model_Schedule::STATUS_SUCCESS)
156
+ ->addFieldToFilter('job_code', 'ddg_automation_customer_subscriber_guest_sync');
157
+
158
+
159
+ if ($schedules->getSize() == 0) {
160
+ return false;
161
+ }
162
+ $executedAt = $schedules->getFirstItem()->getExecutedAt();
163
+
164
+ return Mage::getModel('core/date')->date(NULL, $executedAt);
165
+ }
166
+
167
+ public function automationStatus()
168
+ {
169
+ Mage::getModel('ddg_automation/automation')->enrollment();
170
+
171
+ }
172
+ }
app/code/community/Dotdigitalgroup/Email/Model/Customer.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Customer extends Mage_Customer_Model_Customer
4
+ {
5
+ /**
6
+ * overwrites the default function
7
+ *
8
+ * @param string $type
9
+ * @param string $backUrl
10
+ * @param string $storeId
11
+ * @return Mage_Customer_Model_Customer|void
12
+ */
13
+ public function sendNewAccountEmail($type = 'registered', $backUrl = '', $storeId = '0')
14
+ {
15
+ if(Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_DISABLE_CUSTOMER_SUCCESS, $storeId))
16
+ return;
17
+
18
+ parent::sendNewAccountEmail($type, $backUrl, $storeId);
19
+ }
20
+ }
app/code/community/Dotdigitalgroup/Email/Model/Customer/Guest.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Customer_Guest
4
+ {
5
+ protected $_countGuests = 0;
6
+ protected $_start;
7
+
8
+ /**
9
+ * GUEST SYNC.
10
+ */
11
+ public function sync()
12
+ {
13
+ /** @var Dotdigitalgroup_Email_Helper_Data $helper */
14
+ $helper = Mage::helper('ddg');
15
+ $this->_start = microtime(true);
16
+ foreach(Mage::app()->getWebsites() as $website) {
17
+
18
+ //check if the guest is mapped and enabled
19
+ $enabled = $helper->getGuestAddressBook($website);
20
+ $syncEnabled = $website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_GUEST_ENABLED);
21
+ $apiEnabled = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED, $website);
22
+ if ($enabled && $syncEnabled && $apiEnabled) {
23
+
24
+ //ready to start sync
25
+ if (!$this->_countGuests)
26
+ $helper->log('----------- Start guest sync ----------');
27
+
28
+ //sync guests for website
29
+ $this->exportGuestPerWebsite($website);
30
+ }
31
+ }
32
+ if ($this->_countGuests)
33
+ $helper->log('---- End Guest total time for guest sync : ' . gmdate("H:i:s", microtime(true) - $this->_start));
34
+ }
35
+
36
+ public function exportGuestPerWebsite(Mage_Core_Model_Website $website)
37
+ {
38
+ $helper = Mage::helper('ddg');
39
+ $fileHelper = Mage::helper('ddg/file');
40
+ $guests = Mage::getModel('ddg_automation/contact')->getGuests($website);
41
+ if ($guests->getSize()) {
42
+ $guestFilename = strtolower($website->getCode() . '_guest_' . date('d_m_Y_Hi') . '.csv');
43
+ $helper->log('Guest file: ' . $guestFilename);
44
+ $storeName = $helper->getMappedStoreName($website);
45
+ $fileHelper->outputCSV($fileHelper->getFilePath($guestFilename), array('Email', 'emailType', $storeName));
46
+ foreach ($guests as $guest) {
47
+ $email = $guest->getEmail();
48
+ try{
49
+ $guest->setEmailImported(Dotdigitalgroup_Email_Model_Contact::EMAIL_CONTACT_IMPORTED)
50
+ ->save();
51
+ $storeName = $website->getName();
52
+ // save data for guests
53
+ $fileHelper->outputCSV($fileHelper->getFilePath($guestFilename), array($email, 'Html', $storeName));
54
+ $this->_countGuests++;
55
+ }catch (Exception $e){
56
+ Mage::logException($e);
57
+ }
58
+ }
59
+ if ($this->_countGuests) {
60
+ //register in queue with importer
61
+ Mage::getModel('ddg_automation/importer')->registerQueue(
62
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_GUEST,
63
+ '',
64
+ Dotdigitalgroup_Email_Model_Importer::MODE_BULK,
65
+ $website->getId(),
66
+ $guestFilename
67
+ );
68
+ }
69
+ }
70
+ }
71
+ }
app/code/community/Dotdigitalgroup/Email/Model/Customer/Observer.php ADDED
@@ -0,0 +1,374 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
28
+ $emailBefore = $customer->getOrigData('email');
29
+
30
+ $contactModel = Mage::getModel('ddg_automation/contact')->loadByCustomerEmail($emailBefore, $websiteId);
31
+
32
+ //email change detection
33
+ if ($emailBefore && $email != $emailBefore) {
34
+ Mage::helper('ddg')->log('email change detected : ' . $email . ', after : ' . $emailBefore . ', website id : ' . $websiteId);
35
+ $enabled = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED, $websiteId);
36
+
37
+ if ($enabled) {
38
+ $client = Mage::helper('ddg')->getWebsiteApiClient($websiteId);
39
+ $subscribersAddressBook = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SUBSCRIBERS_ADDRESS_BOOK_ID, $websiteId);
40
+ $response = $client->postContacts($emailBefore);
41
+ //check for matching email
42
+ if (isset($response->id)) {
43
+ if ($email != $response->email) {
44
+ $data = array(
45
+ 'Email' => $email,
46
+ 'EmailType' => 'Html'
47
+ );
48
+ //update the contact with same id - different email
49
+ $client->updateContact($response->id, $data);
50
+
51
+ }
52
+ if (!$isSubscribed && $response->status == 'Subscribed') {
53
+ $client->deleteAddressBookContact($subscribersAddressBook, $response->id);
54
+ }
55
+ } elseif (isset($response->message)) {
56
+ Mage::helper('ddg')->log('Email change error : ' . $response->message);
57
+ }
58
+ }
59
+
60
+ } elseif (!$emailBefore) {
61
+ //for new contacts update email
62
+ $contactModel->setEmail( $email );
63
+ }
64
+ $contactModel->setEmailImported(Dotdigitalgroup_Email_Model_Contact::EMAIL_CONTACT_NOT_IMPORTED)
65
+ ->setCustomerId($customerId)
66
+ ->save();
67
+ }catch(Exception $e){
68
+ Mage::logException($e);
69
+ }
70
+ return $this;
71
+ }
72
+
73
+ /**
74
+ * Add new customers to the automation.
75
+ * @param Varien_Event_Observer $observer
76
+ *
77
+ * @return $this
78
+ */
79
+ public function handleCustomerRegiterSuccess(Varien_Event_Observer $observer)
80
+ {
81
+ /** @var $customer Mage_Customer_Model_Customer */
82
+ $customer = $observer->getEvent()->getCustomer();
83
+ $websiteId = $customer->getWebsiteId();
84
+ $website = Mage::app()->getWebsite($websiteId);
85
+ $storeName = $customer->getStore()->getName();
86
+
87
+
88
+ //if api is not enabled
89
+ if (!$website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED))
90
+ return $this;
91
+
92
+ try {
93
+ //program id must be map
94
+ $programId = Mage::helper( 'ddg' )->getAutomationIdByType( 'XML_PATH_CONNECTOR_AUTOMATION_STUDIO_CUSTOMER', $websiteId);
95
+ if (!$programId)
96
+ return $this;
97
+ $email = $customer->getEmail();
98
+ $automation = Mage::getModel( 'ddg_automation/automation' );
99
+ $automation->setEmail( $email )
100
+ ->setAutomationType( Dotdigitalgroup_Email_Model_Automation::AUTOMATION_TYPE_NEW_CUSTOMER )
101
+ ->setEnrolmentStatus(Dotdigitalgroup_Email_Model_Automation::AUTOMATION_STATUS_PENDING)
102
+ ->setTypeId( $customer->getId() )
103
+ ->setWebsiteId($websiteId)
104
+ ->setStoreName($storeName)
105
+ ->setProgramId($programId)
106
+ ;
107
+
108
+ $automation->save();
109
+ }catch(Exception $e) {
110
+ Mage::logException($e);
111
+ }
112
+
113
+ return $this;
114
+ }
115
+
116
+ /**
117
+ * Remove the contact on customer delete.
118
+ *
119
+ * @param Varien_Event_Observer $observer
120
+ *
121
+ * @return $this
122
+ */
123
+ public function handleCustomerDeleteAfter(Varien_Event_Observer $observer)
124
+ {
125
+ $customer = $observer->getEvent()->getCustomer();
126
+ $email = $customer->getEmail();
127
+ $websiteId = $customer->getWebsiteId();
128
+ $helper = Mage::helper('ddg');
129
+
130
+ //api enabled
131
+ $enabled = $helper->getWebsiteConfig(
132
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED,
133
+ $websiteId
134
+ );
135
+ //sync enabled
136
+ $syncEnabled = $helper->getWebsiteConfig(
137
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_CONTACT_ENABLED,
138
+ $websiteId
139
+ );
140
+
141
+ /**
142
+ * Remove contact.
143
+ */
144
+ if ($enabled && $syncEnabled) {
145
+ try {
146
+ //register in queue with importer
147
+ $check = Mage::getModel('ddg_automation/importer')->registerQueue(
148
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_CONTACT,
149
+ $email,
150
+ Dotdigitalgroup_Email_Model_Importer::MODE_CONTACT_DELETE,
151
+ $websiteId
152
+ );
153
+ $contactModel = Mage::getModel('ddg_automation/contact')->loadByCustomerEmail($email, $websiteId);
154
+ if ($contactModel->getId() && $check) {
155
+ //remove contact
156
+ $contactModel->delete();
157
+ }
158
+ } catch (Exception $e) {
159
+ Mage::logException($e);
160
+ }
161
+ }
162
+ return $this;
163
+ }
164
+
165
+ /**
166
+ * Set contact to re-import if registered customer submitted a review. Save review in email_review table.
167
+ * @param Varien_Event_Observer $observer
168
+ * @return $this
169
+ */
170
+ public function reviewSaveAfter(Varien_Event_Observer $observer)
171
+ {
172
+ $dataObject = $observer->getEvent()->getDataObject();
173
+
174
+ if($dataObject->getCustomerId() && $dataObject->getStatusId() == Mage_Review_Model_Review::STATUS_APPROVED){
175
+ $helper = Mage::helper('ddg');
176
+ $customerId = $dataObject->getCustomerId();
177
+ $helper->setConnectorContactToReImport($customerId);
178
+ //save review info in the table
179
+ $this->_registerReview($dataObject);
180
+ $store = Mage::app()->getStore($dataObject->getStoreId());
181
+ $storeName = $store->getName();
182
+ $website = Mage::app()->getStore($store)->getWebsite();
183
+ $customer = Mage::getModel('customer/customer')->getCollection()
184
+ ->addAttributeToSelect('email')
185
+ ->addAttributeToFilter('entity_id', $customerId)
186
+ ->getFirstItem();
187
+
188
+ //if api is not enabled
189
+ if (!$website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED))
190
+ return $this;
191
+
192
+ $programId = Mage::helper( 'ddg' )->getAutomationIdByType('XML_PATH_CONNECTOR_AUTOMATION_STUDIO_REVIEW', $website->getId());
193
+ if ($programId) {
194
+ $automation = Mage::getModel( 'ddg_automation/automation' );
195
+ $automation->setEmail( $customer->getEmail() )
196
+ ->setAutomationType( Dotdigitalgroup_Email_Model_Automation::AUTOMATION_TYPE_NEW_REVIEW )
197
+ ->setEnrolmentStatus(Dotdigitalgroup_Email_Model_Automation::AUTOMATION_STATUS_PENDING)
198
+ ->setTypeId( $dataObject->getReviewId() )
199
+ ->setWebsiteId( $website->getId() )
200
+ ->setStoreName( $storeName )
201
+ ->setProgramId( $programId );
202
+ $automation->save();
203
+ }
204
+ }
205
+ return $this;
206
+ }
207
+
208
+ /**
209
+ * register review
210
+ *
211
+ * @param $review
212
+ */
213
+ private function _registerReview($review)
214
+ {
215
+ try{
216
+ $emailReview = Mage::getModel('ddg_automation/review');
217
+ $emailReview->setReviewId($review->getReviewId())
218
+ ->setCustomerId($review->getCustomerId())
219
+ ->setStoreId($review->getStoreId())
220
+ ->save();
221
+ }catch(Exception $e){
222
+ Mage::logException($e);
223
+ }
224
+ }
225
+
226
+ /**
227
+ * wishlist save after observer. save new wishlist in the email_wishlist table.
228
+ *
229
+ * @param Varien_Event_Observer $observer
230
+ * @return $this
231
+ */
232
+ public function wishlistSaveAfter(Varien_Event_Observer $observer)
233
+ {
234
+ if($observer->getEvent()->getObject() instanceof Mage_Wishlist_Model_Wishlist) {
235
+ $wishlist = $observer->getEvent()->getObject()->getData();
236
+ if (is_array($wishlist) && isset($wishlist['customer_id'])) {
237
+ //save wishlist info in the table
238
+ $this->_registerWishlist( $wishlist );
239
+ }
240
+ }
241
+ }
242
+
243
+ /**
244
+ * register wishlist
245
+ *
246
+ * @param $wishlist
247
+ * @return $this
248
+ */
249
+ private function _registerWishlist($wishlist)
250
+ {
251
+ try{
252
+ $emailWishlist = Mage::getModel('ddg_automation/wishlist');
253
+ $customer = Mage::getModel('customer/customer');
254
+
255
+ //if wishlist exist not to save again
256
+ if (!$emailWishlist->getWishlist($wishlist['wishlist_id'])) {
257
+
258
+ $customer->load($wishlist['customer_id']);
259
+ //customer not found
260
+ if (! $customer->getId()) {
261
+ return false;
262
+ }
263
+ $email = $customer->getEmail();
264
+ $wishlistId = $wishlist['wishlist_id'];
265
+ $websiteId = $customer->getWebsiteId();
266
+ $emailWishlist->setWishlistId($wishlistId)
267
+ ->setCustomerId($wishlist['customer_id'])
268
+ ->setStoreId($customer->getStoreId())
269
+ ->save();
270
+
271
+ $store = Mage::app()->getStore($customer->getStoreId());
272
+ $storeName = $store->getName();
273
+ $website = Mage::app()->getStore($store)->getWebsite();
274
+
275
+ //if api is not enabled
276
+ if (!$website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED))
277
+ return $this;
278
+
279
+ $automationType = 'XML_PATH_CONNECTOR_AUTOMATION_STUDIO_WISHLIST';
280
+ $programId = Mage::helper( 'ddg' )->getAutomationIdByType($automationType, $websiteId);
281
+ if ($programId) {
282
+ $automation = Mage::getModel( 'ddg_automation/automation' );
283
+ $automation->setEmail( $email )
284
+ ->setAutomationType( Dotdigitalgroup_Email_Model_Automation::AUTOMATION_TYPE_NEW_WISHLIST )
285
+ ->setEnrolmentStatus(Dotdigitalgroup_Email_Model_Automation::AUTOMATION_STATUS_PENDING)
286
+ ->setTypeId( $wishlistId )
287
+ ->setWebsiteId( $websiteId )
288
+ ->setStoreName( $storeName )
289
+ ->setProgramId( $programId );
290
+ $automation->save();
291
+ }
292
+
293
+ }
294
+ }catch(Exception $e){
295
+ Mage::logException($e);
296
+ }
297
+ }
298
+
299
+ /**
300
+ * wishlist item save after
301
+ *
302
+ * @param Varien_Event_Observer $observer
303
+ */
304
+ public function wishlistItemSaveAfter(Varien_Event_Observer $observer)
305
+ {
306
+ $object = $observer->getEvent()->getDataObject();
307
+ $wishlist = Mage::getModel( 'wishlist/wishlist' )->load( $object->getWishlistId() );
308
+ $emailWishlist = Mage::getModel( 'ddg_automation/wishlist' );
309
+ try {
310
+ if ( $object->getWishlistId() ) {
311
+ $itemCount = $wishlist->getItemsCount();
312
+ $item = $emailWishlist->getWishlist( $object->getWishlistId() );
313
+
314
+ if ( $item && $item->getId() ) {
315
+ $preSaveItemCount = $item->getItemCount();
316
+
317
+ if ( $itemCount != $item->getItemCount() ) {
318
+ $item->setItemCount( $itemCount );
319
+ }
320
+
321
+ if ( $itemCount == 1 && $preSaveItemCount == 0 ) {
322
+ $item->setWishlistImported( null );
323
+ } elseif ( $item->getWishlistImported() ) {
324
+ $item->setWishlistModified( 1 );
325
+ }
326
+
327
+ $item->save();
328
+ }
329
+ }
330
+ } catch ( Exception $e ) {
331
+ Mage::logException( $e );
332
+ }
333
+
334
+ }
335
+
336
+ /**
337
+ * wishlist delete observer
338
+ *
339
+ * @param Varien_Event_Observer $observer
340
+ */
341
+ public function wishlistDeleteAfter(Varien_Event_Observer $observer)
342
+ {
343
+ $object = $observer->getEvent()->getDataObject();
344
+ $customer = Mage::getModel('customer/customer')->load($object->getCustomerId());
345
+ $website = Mage::app()->getStore($customer->getStoreId())->getWebsite();
346
+ $helper = Mage::helper('ddg');
347
+
348
+ //sync enabled
349
+ $syncEnabled = $helper->getWebsiteConfig(
350
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_WISHLIST_ENABLED,
351
+ $website->getId()
352
+ );
353
+ if ($helper->isEnabled($website->getId()) && $syncEnabled) {
354
+ //Remove wishlist
355
+ try {
356
+ $item = Mage::getModel('ddg_automation/wishlist')->getWishlist($object->getWishlistId());
357
+ if ($item->getId()) {
358
+ //register in queue with importer
359
+ $check = Mage::getModel('ddg_automation/importer')->registerQueue(
360
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_WISHLIST,
361
+ array($item->getId()),
362
+ Dotdigitalgroup_Email_Model_Importer::MODE_SINGLE_DELETE,
363
+ $website->getId()
364
+ );
365
+ if ($check) {
366
+ $item->delete();
367
+ }
368
+ }
369
+ } catch (Exception $e) {
370
+ Mage::logException($e);
371
+ }
372
+ }
373
+ }
374
+ }
app/code/community/Dotdigitalgroup/Email/Model/Customer/Review.php ADDED
@@ -0,0 +1,241 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Customer_Review
4
+ {
5
+ /**
6
+ * @var int
7
+ */
8
+ public $id;
9
+
10
+ /**
11
+ * @var int
12
+ */
13
+ public $customer_id;
14
+
15
+ /**
16
+ * @var string
17
+ */
18
+ public $email;
19
+
20
+ /**
21
+ * @var string
22
+ */
23
+ public $product_name;
24
+
25
+ /**
26
+ * @var string
27
+ */
28
+ public $product_sku;
29
+
30
+ /**
31
+ * @var string
32
+ */
33
+ public $review_date;
34
+
35
+ /**
36
+ * @var string
37
+ */
38
+ public $website_name;
39
+
40
+ /**
41
+ * @var string
42
+ */
43
+ public $store_name;
44
+
45
+ /**
46
+ * @param $email
47
+ * @return $this
48
+ */
49
+ public function setEmail($email)
50
+ {
51
+ $this->email = $email;
52
+ return $this;
53
+ }
54
+
55
+ /**
56
+ * @param $customer_id
57
+ * @return $this
58
+ */
59
+ public function setCustomerId($customer_id)
60
+ {
61
+ $this->customer_id = (int) $customer_id;
62
+ return $this;
63
+ }
64
+
65
+ /**
66
+ * @return mixed
67
+ */
68
+ public function getCustomerId()
69
+ {
70
+ return (int) $this->customer_id;
71
+ }
72
+
73
+ /**
74
+ * @param $id
75
+ * @return $this
76
+ */
77
+ public function setId($id)
78
+ {
79
+ $this->id = (int) $id;
80
+ return $this;
81
+ }
82
+
83
+ /**
84
+ * @return mixed
85
+ */
86
+ public function getId()
87
+ {
88
+ return (int) $this->id;
89
+ }
90
+
91
+ /**
92
+ * create rating on runtime
93
+ *
94
+ * @param $rating_name
95
+ * @param $rating
96
+ */
97
+ public function createRating($rating_name, $rating)
98
+ {
99
+ $this->$rating_name = $rating->expose();
100
+ }
101
+
102
+ /**
103
+ * set review date.
104
+ *
105
+ * @param $date
106
+ * @return $this;
107
+ */
108
+ public function setReviewDate($date)
109
+ {
110
+ $created_at = new Zend_Date($date, Zend_Date::ISO_8601);
111
+
112
+ $this->review_date = $created_at->toString(Zend_Date::ISO_8601);;
113
+ return $this;
114
+ }
115
+
116
+ /**
117
+ * @return string
118
+ */
119
+ public function getReviewDate()
120
+ {
121
+ return $this->review_date;
122
+ }
123
+
124
+ /**
125
+ * set product
126
+ *
127
+ * @param Mage_Catalog_Model_Product $product
128
+ * @return $this
129
+ */
130
+ public function setProduct(Mage_Catalog_Model_Product $product)
131
+ {
132
+ $this->setProductName($product->getName());
133
+ $this->setProductSku($product->getSku());
134
+ return $this;
135
+ }
136
+
137
+ /**
138
+ * set review data
139
+ *
140
+ * @param Mage_Review_Model_Review $review $product
141
+ * @return $this
142
+ */
143
+ public function setReviewData(Mage_Review_Model_Review $review)
144
+ {
145
+ $store = Mage::app()->getStore($review->getStoreId());
146
+ $websiteName = $store->getWebsite()->getName();
147
+ $storeName = $store->getName();
148
+ $this->setId($review->getReviewId())
149
+ ->setWebsiteName($websiteName)
150
+ ->setStoreName($storeName)
151
+ ->setReviewDate($review->getCreatedAt())
152
+ ->setCustomerId($review->getCustomerId())
153
+ ->setEmail($review->getEmail());
154
+
155
+ return $this;
156
+ }
157
+
158
+ /**
159
+ * set product name
160
+ *
161
+ * @param $name
162
+ */
163
+ public function setProductName($name)
164
+ {
165
+ $this->product_name = $name;
166
+ }
167
+
168
+ /**
169
+ * @return string
170
+ */
171
+ public function getProductName()
172
+ {
173
+ return $this->product_name;
174
+ }
175
+
176
+ /**
177
+ * set product sku
178
+ *
179
+ * @param $sku
180
+ */
181
+ public function setProductSku($sku)
182
+ {
183
+ $this->product_sku = $sku;
184
+ }
185
+
186
+ /**
187
+ * @return string
188
+ */
189
+ public function getProductSku()
190
+ {
191
+ return $this->product_sku;
192
+ }
193
+
194
+ /**
195
+ * set website name
196
+ *
197
+ * @param $name
198
+ * @return $this
199
+ */
200
+ public function setWebsiteName($name)
201
+ {
202
+ $this->website_name = $name;
203
+ return $this;
204
+ }
205
+
206
+ /**
207
+ * @return string
208
+ */
209
+ public function getStoreName()
210
+ {
211
+ return $this->store_name;
212
+ }
213
+
214
+ /**
215
+ * set store name
216
+ *
217
+ * @param $name
218
+ * @return $this
219
+ */
220
+ public function setStoreName($name)
221
+ {
222
+ $this->store_name = $name;
223
+ return $this;
224
+ }
225
+
226
+ /**
227
+ * @return string
228
+ */
229
+ public function getWebsiteName()
230
+ {
231
+ return $this->website_name;
232
+ }
233
+
234
+ /**
235
+ * @return array
236
+ */
237
+ public function expose()
238
+ {
239
+ return get_object_vars($this);
240
+ }
241
+ }
app/code/community/Dotdigitalgroup/Email/Model/Customer/Review/Rating.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Customer_Review_Rating
4
+ {
5
+ /**
6
+ * @var int
7
+ */
8
+ public $rating_score;
9
+
10
+ /**
11
+ * constructor
12
+ *
13
+ * @param $rating
14
+ */
15
+ public function __construct($rating)
16
+ {
17
+ $this->setRatingScore($rating->getValue());
18
+ }
19
+
20
+ /**
21
+ * @param $score
22
+ *
23
+ * @return $this
24
+ */
25
+ public function setRatingScore($score)
26
+ {
27
+ $this->rating_score = (int)$score;
28
+ return $this;
29
+ }
30
+
31
+ /**
32
+ * @return int
33
+ */
34
+ public function getRatingScore()
35
+ {
36
+ return $this->rating_score;
37
+ }
38
+
39
+ /**
40
+ * @return array
41
+ */
42
+ public function expose()
43
+ {
44
+ return get_object_vars($this);
45
+ }
46
+ }
app/code/community/Dotdigitalgroup/Email/Model/Customer/Wishlist.php ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Customer_Wishlist
4
+ {
5
+ /**
6
+ * @var int
7
+ */
8
+ public $id;
9
+ /**
10
+ * @var int
11
+ */
12
+ public $customer_id;
13
+ /**
14
+ * @var string
15
+ */
16
+ public $email;
17
+
18
+ /**
19
+ * wishlist items.
20
+ * @var array
21
+ */
22
+ public $items = array();
23
+
24
+ /**
25
+ * @var float
26
+ */
27
+ protected $total_wishlist_value;
28
+
29
+ /**
30
+ * @var string
31
+ */
32
+ public $updated_at;
33
+
34
+ /**
35
+ * @param $email
36
+ * @return $this
37
+ */
38
+ public function setEmail($email)
39
+ {
40
+ $this->email = $email;
41
+ return $this;
42
+ }
43
+
44
+ /**
45
+ * @param $customer_id
46
+ * @return $this
47
+ */
48
+ public function setCustomerId($customer_id)
49
+ {
50
+ $this->customer_id = (int) $customer_id;
51
+ return $this;
52
+ }
53
+
54
+ /**
55
+ * @return mixed
56
+ */
57
+ public function getCustomerId()
58
+ {
59
+ return (int) $this->customer_id;
60
+ }
61
+
62
+ /**
63
+ * @param $id
64
+ * @return $this
65
+ */
66
+ public function setId($id)
67
+ {
68
+ $this->id = (int) $id;
69
+ return $this;
70
+ }
71
+
72
+ /**
73
+ * @return mixed
74
+ */
75
+ public function getId()
76
+ {
77
+ return (int) $this->id;
78
+ }
79
+
80
+ /**
81
+ * set wishlist item.
82
+ *
83
+ * @param $item
84
+ */
85
+ public function setItem($item)
86
+ {
87
+ $this->items[] = $item->expose();
88
+
89
+ $this->total_wishlist_value += $item->getTotalValueOfProduct();
90
+ }
91
+
92
+ /**
93
+ * @return array
94
+ */
95
+ public function expose()
96
+ {
97
+ return get_object_vars($this);
98
+ }
99
+
100
+ /**
101
+ * set wishlist date.
102
+ *
103
+ * @param $date
104
+ * @return $this;
105
+ */
106
+ public function setUpdatedAt($date)
107
+ {
108
+ $date = new Zend_Date($date, Zend_Date::ISO_8601);
109
+
110
+ $this->updated_at = $date->toString(Zend_Date::ISO_8601);;
111
+ return $this;
112
+ }
113
+
114
+ /**
115
+ * @return string
116
+ */
117
+ public function getUpdatedAt()
118
+ {
119
+ return $this->updated_at;
120
+ }
121
+ }
app/code/{local → community}/Dotdigitalgroup/Email/Model/Customer/Wishlist/Item.php RENAMED
@@ -2,24 +2,32 @@
2
 
3
  class Dotdigitalgroup_Email_Model_Customer_Wishlist_Item
4
  {
5
- protected $name;
6
- protected $sku;
7
- protected $price;
8
- protected $qty;
9
  protected $total_value_of_product;
10
 
11
- public function __construct($product)
 
 
 
 
 
 
12
  {
13
  $this->setSku($product->getSku());
14
  $this->setName($product->getName());
15
  }
16
 
17
  /**
18
- * @param mixed $name
 
19
  */
20
  public function setName($name)
21
  {
22
  $this->name = $name;
 
23
  }
24
 
25
  /**
@@ -31,11 +39,13 @@ class Dotdigitalgroup_Email_Model_Customer_Wishlist_Item
31
  }
32
 
33
  /**
34
- * @param mixed $qty
 
35
  */
36
  public function setQty($qty)
37
  {
38
  $this->qty = (int)$qty;
 
39
  }
40
 
41
  /**
@@ -55,14 +65,16 @@ class Dotdigitalgroup_Email_Model_Customer_Wishlist_Item
55
  }
56
 
57
  /**
58
- * @param mixed $price
 
59
  */
60
  public function setPrice($product)
61
  {
62
  $this->price = $product->getFinalPrice();
63
  $total = $this->price * $this->qty;
64
 
65
- $this->total_value_of_product = number_format($total, 2);
 
66
  }
67
 
68
  /**
@@ -74,11 +86,13 @@ class Dotdigitalgroup_Email_Model_Customer_Wishlist_Item
74
  }
75
 
76
  /**
77
- * @param mixed $sku
 
78
  */
79
  public function setSku($sku)
80
  {
81
  $this->sku = $sku;
 
82
  }
83
 
84
  /**
@@ -88,13 +102,12 @@ class Dotdigitalgroup_Email_Model_Customer_Wishlist_Item
88
  {
89
  return $this->sku;
90
  }
91
- public function expose() {
92
 
 
 
 
 
 
93
  return get_object_vars($this);
94
-
95
  }
96
-
97
-
98
-
99
-
100
  }
2
 
3
  class Dotdigitalgroup_Email_Model_Customer_Wishlist_Item
4
  {
5
+ protected $sku;
6
+ protected $qty;
7
+ protected $name;
8
+ protected $price;
9
  protected $total_value_of_product;
10
 
11
+
12
+ /**
13
+ * construnctor.
14
+ *
15
+ * @param $product
16
+ */
17
+ public function __construct($product)
18
  {
19
  $this->setSku($product->getSku());
20
  $this->setName($product->getName());
21
  }
22
 
23
  /**
24
+ * @param $name
25
+ * @return $this
26
  */
27
  public function setName($name)
28
  {
29
  $this->name = $name;
30
+ return $this;
31
  }
32
 
33
  /**
39
  }
40
 
41
  /**
42
+ * @param $qty
43
+ * @return $this
44
  */
45
  public function setQty($qty)
46
  {
47
  $this->qty = (int)$qty;
48
+ return $this;
49
  }
50
 
51
  /**
65
  }
66
 
67
  /**
68
+ * @param $product
69
+ * @return $this
70
  */
71
  public function setPrice($product)
72
  {
73
  $this->price = $product->getFinalPrice();
74
  $total = $this->price * $this->qty;
75
 
76
+ $this->total_value_of_product = number_format($total, 2, '.', ',');
77
+ return $this;
78
  }
79
 
80
  /**
86
  }
87
 
88
  /**
89
+ * @param $sku
90
+ * @return $this
91
  */
92
  public function setSku($sku)
93
  {
94
  $this->sku = $sku;
95
+ return $this;
96
  }
97
 
98
  /**
102
  {
103
  return $this->sku;
104
  }
 
105
 
106
+ /**
107
+ * @return array
108
+ */
109
+ public function expose()
110
+ {
111
  return get_object_vars($this);
 
112
  }
 
 
 
 
113
  }
app/code/community/Dotdigitalgroup/Email/Model/Email.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Email extends Mage_Core_Model_Email
4
+ {
5
+
6
+ public function send() {
7
+
8
+
9
+ if ( ! Mage::helper('ddg/transactional')->isEnabled() ) {
10
+ return parent::send();
11
+ }
12
+
13
+ if (Mage::getStoreConfigFlag('system/smtp/disable')) {
14
+ return $this;
15
+ }
16
+
17
+ $mail = new Zend_Mail();
18
+
19
+ if (strtolower($this->getType()) == 'html') {
20
+ $mail->setBodyHtml($this->getBody());
21
+ } else {
22
+ $mail->setBodyText($this->getBody());
23
+ }
24
+
25
+ $mail->setFrom($this->getFromEmail(), $this->getFromName())
26
+ ->addTo($this->getToEmail(), $this->getToName())
27
+ ->setSubject($this->getSubject());
28
+
29
+ $transport = Mage::helper('ddg/transactional')->getTransport();
30
+
31
+ $mail->send($transport);
32
+
33
+
34
+ return $this;
35
+ }
36
+ }
app/code/community/Dotdigitalgroup/Email/Model/Email/Template.php ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Email_Template extends Mage_Core_Model_Email_Template
4
+ {
5
+
6
+ public function send($email, $name = null, array $variables = array())
7
+ {
8
+
9
+ $_helper = Mage::helper('ddg/transactional');
10
+ // If it's not enabled, just return the parent result.
11
+ if (!$_helper->isEnabled()) {
12
+ Mage::log('DDG Transactional is not enabled, fall back to parent class');
13
+ return parent::send($email, $name, $variables);
14
+ }
15
+
16
+
17
+ // As per parent class - except addition of before and after send events
18
+
19
+ if (!$this->isValidForSend()) {
20
+ Mage::log('Email is not valid for sending, this is a core error that often means there\'s a problem with your email templates.');
21
+ Mage::logException(new Exception('This letter cannot be sent.')); // translation is intentionally omitted
22
+ return false;
23
+ }
24
+
25
+ $emails = array_values((array)$email);
26
+ $names = is_array($name) ? $name : (array)$name;
27
+ $names = array_values($names);
28
+ foreach ($emails as $key => $email) {
29
+ if (!isset($names[$key])) {
30
+ $names[$key] = substr($email, 0, strpos($email, '@'));
31
+ }
32
+ }
33
+
34
+ $variables['email'] = reset($emails);
35
+ $variables['name'] = reset($names);
36
+
37
+ ini_set('SMTP', Mage::getStoreConfig('system/smtp/host'));
38
+ ini_set('smtp_port', Mage::getStoreConfig('system/smtp/port'));
39
+
40
+ $mail = $this->getMail();
41
+
42
+
43
+ $setReturnPath = Mage::getStoreConfig(self::XML_PATH_SENDING_SET_RETURN_PATH);
44
+ switch ($setReturnPath) {
45
+ case 1:
46
+ $returnPathEmail = $this->getSenderEmail();
47
+ break;
48
+ case 2:
49
+ $returnPathEmail = Mage::getStoreConfig(self::XML_PATH_SENDING_RETURN_PATH_EMAIL);
50
+ break;
51
+ default:
52
+ $returnPathEmail = null;
53
+ break;
54
+ }
55
+
56
+ if ($returnPathEmail !== null) {
57
+ $mailTransport = new Zend_Mail_Transport_Sendmail("-f".$returnPathEmail);
58
+ Zend_Mail::setDefaultTransport($mailTransport);
59
+ }
60
+
61
+ foreach ($emails as $key => $email) {
62
+ $mail->addTo($email, '=?utf-8?B?' . base64_encode($names[$key]) . '?=');
63
+ }
64
+
65
+ $this->setUseAbsoluteLinks(true);
66
+ $text = $this->getProcessedTemplate($variables, true);
67
+
68
+ if($this->isPlain()) {
69
+ $mail->setBodyText($text);
70
+ } else {
71
+ $mail->setBodyHTML($text);
72
+ }
73
+
74
+ $mail->setSubject('=?utf-8?B?' . base64_encode($this->getProcessedTemplateSubject($variables)) . '?=');
75
+ $mail->setFrom($this->getSenderEmail(), $this->getSenderName());
76
+
77
+ try {
78
+
79
+ $transport = $_helper->getTransport();
80
+
81
+ $mail->send($transport);
82
+
83
+ $this->_mail = null;
84
+ } catch (Exception $e) {
85
+ $this->_mail = null;
86
+ Mage::logException($e);
87
+ return false;
88
+ }
89
+
90
+ return true;
91
+ }
92
+
93
+ }
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,377 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 $_reasons = array(
28
+ 'Globally Suppressed',
29
+ 'Blocked',
30
+ 'Unsubscribed',
31
+ 'Hard Bounced',
32
+ 'Isp Complaints',
33
+ 'Domain Suppressed',
34
+ 'Failures',
35
+ 'Invalid Entries',
36
+ 'Mail Blocked'
37
+ );
38
+
39
+ private $import_statuses = array(
40
+ 'RejectedByWatchdog', 'InvalidFileFormat', 'Unknown',
41
+ 'Failed', 'ExceedsAllowedContactLimit', 'NotAvailableInThisVersion'
42
+ );
43
+
44
+ /**
45
+ * constructor
46
+ */
47
+ public function _construct()
48
+ {
49
+ parent::_construct();
50
+ $this->_init('ddg_automation/importer');
51
+ }
52
+
53
+ /**
54
+ * @return $this|Mage_Core_Model_Abstract
55
+ */
56
+ protected function _beforeSave()
57
+ {
58
+ parent::_beforeSave();
59
+ $now = Mage::getSingleton('core/date')->gmtDate();
60
+ if ($this->isObjectNew()) {
61
+ $this->setCreatedAt($now);
62
+ } else {
63
+ $this->setUpdatedAt($now);
64
+ }
65
+ return $this;
66
+ }
67
+
68
+ /**
69
+ * register import in queue
70
+ *
71
+ * @param $importType
72
+ * @param $importData
73
+ * @param $importMode
74
+ * @param $websiteId
75
+ * @param bool $file
76
+ * @return bool
77
+ */
78
+ public function registerQueue($importType, $importData, $importMode, $websiteId, $file = false)
79
+ {
80
+ try {
81
+ if (!empty($importData))
82
+ $importData = serialize($importData);
83
+
84
+ if ($file)
85
+ $this->setImportFile($file);
86
+
87
+ $this->setImportType($importType)
88
+ ->setImportData($importData)
89
+ ->setWebsiteId($websiteId)
90
+ ->setImportMode($importMode)
91
+ ->save();
92
+
93
+ return true;
94
+ } catch (Exception $e) {
95
+ Mage::logException($e);
96
+ }
97
+ }
98
+
99
+ /**
100
+ * start point. importer queue processor. check if un-finished import exist.
101
+ *
102
+ * @return bool
103
+ */
104
+ public function processQueue()
105
+ {
106
+ $helper = Mage::helper('ddg');
107
+ $helper->allowResourceFullExecution();
108
+ if ($item = $this->_getQueue(true)) {
109
+ $websiteId = $item->getWebsiteId();
110
+ $enabled = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED, $websiteId);
111
+ if ($enabled) {
112
+ $client = Mage::helper('ddg')->getWebsiteApiClient($websiteId);
113
+ if (
114
+ $item->getImportType() == self::IMPORT_TYPE_CONTACT or
115
+ $item->getImportType() == self::IMPORT_TYPE_SUBSCRIBERS or
116
+ $item->getImportType() == self::IMPORT_TYPE_GUEST
117
+
118
+ ) {
119
+ $response = $client->getContactsImportByImportId($item->getImportId());
120
+ } else {
121
+ $response = $client->getContactsTransactionalDataImportByImportId($item->getImportId());
122
+ }
123
+ //if curl error 28
124
+ $curlError = $client->getCurlError();
125
+ if($curlError) {
126
+ $item->setMessage($curlError)
127
+ ->save();
128
+ }
129
+ else{
130
+ if ($response && !isset($response->message)) {
131
+ if ($response->status == 'Finished') {
132
+ $now = Mage::getSingleton('core/date')->gmtDate();
133
+ $item->setImportStatus(self::IMPORTED)
134
+ ->setImportFinished($now)
135
+ ->setMessage('')
136
+ ->save();
137
+
138
+ if (
139
+ $item->getImportType() == self::IMPORT_TYPE_CONTACT or
140
+ $item->getImportType() == self::IMPORT_TYPE_SUBSCRIBERS or
141
+ $item->getImportType() == self::IMPORT_TYPE_GUEST
142
+
143
+ ){
144
+ if($item->getImportId())
145
+ $this->_processContactImportReportFaults($item->getImportId(), $websiteId);
146
+ }
147
+
148
+ $this->_processQueue();
149
+ } elseif (in_array($response->status, $this->import_statuses)) {
150
+ $item->setImportStatus(self::FAILED)
151
+ ->setMessage('Import failed with status '.$response->status)
152
+ ->save();
153
+
154
+ $this->_processQueue();
155
+ }
156
+ }
157
+ if ($response && isset($response->message)) {
158
+ $item->setImportStatus(self::FAILED)
159
+ ->setMessage($response->message)
160
+ ->save();
161
+
162
+ $this->_processQueue();
163
+ }
164
+ }
165
+ }
166
+ } else {
167
+ $this->_processQueue();
168
+ }
169
+ return true;
170
+ }
171
+
172
+ private function _processContactImportReportFaults($id, $websiteId)
173
+ {
174
+ $helper = Mage::helper('ddg');
175
+ $client = $helper->getWebsiteApiClient($websiteId);
176
+ $data = $client->getContactImportReportFaults($id);
177
+
178
+ if($data){
179
+ $data = $this->_remove_utf8_bom($data);
180
+ $fileName = Mage::getBaseDir('var') . DS . 'DmTempCsvFromApi.csv';
181
+ $io = new Varien_Io_File();
182
+ $check = $io->write($fileName, $data);
183
+ if($check){
184
+ $csvArray = $this->_csv_to_array($fileName);
185
+ $io->rm($fileName);
186
+ Mage::getResourceModel('ddg_automation/contact')->unsubscribe($csvArray);
187
+ }else{
188
+ $helper->log('_processContactImportReportFaults: cannot save data to CSV file.');
189
+ }
190
+ }
191
+ }
192
+
193
+ /**
194
+ * actual importer queue processor
195
+ */
196
+ private function _processQueue()
197
+ {
198
+ if ($item = $this->_getQueue()) {
199
+ $helper = Mage::helper('ddg');
200
+ $websiteId = $item->getWebsiteId();
201
+ $client = $helper->getWebsiteApiClient($websiteId);
202
+ $now = Mage::getSingleton('core/date')->gmtDate();
203
+ $error = false;
204
+
205
+ if ( //import requires file
206
+ $item->getImportType() == self::IMPORT_TYPE_CONTACT or
207
+ $item->getImportType() == self::IMPORT_TYPE_SUBSCRIBERS or
208
+ $item->getImportType() == self::IMPORT_TYPE_GUEST
209
+ ) {
210
+ if ($item->getImportMode() == self::MODE_CONTACT_DELETE) {
211
+ //remove from account
212
+ $client = Mage::helper('ddg')->getWebsiteApiClient($websiteId);
213
+ $email = unserialize($item->getImportData());
214
+ $apiContact = $client->postContacts($email);
215
+ if (!isset($apiContact->message) && isset($apiContact->id)) {
216
+ $result = $client->deleteContact($apiContact->id);
217
+ if (isset($result->message)) {
218
+ $error = true;
219
+ }
220
+ } elseif (isset($apiContact->message) && !isset($apiContact->id)) {
221
+ $error = true;
222
+ $result = $apiContact;
223
+ }
224
+ } else {
225
+ //address book
226
+ $addressbook = '';
227
+ if ($item->getImportType() == self::IMPORT_TYPE_CONTACT)
228
+ $addressbook = $helper->getCustomerAddressBook($websiteId);
229
+ if ($item->getImportType() == self::IMPORT_TYPE_SUBSCRIBERS)
230
+ $addressbook = $helper->getSubscriberAddressBook($websiteId);
231
+ if ($item->getImportType() == self::IMPORT_TYPE_GUEST)
232
+ $addressbook = $helper->getGuestAddressBook($websiteId);
233
+
234
+ $file = $item->getImportFile();
235
+ if (!empty($file) && !empty($addressbook)) {
236
+ $result = $client->postAddressBookContactsImport($file, $addressbook);
237
+ $fileHelper = Mage::helper('ddg/file');
238
+ if (isset($result->message) && !isset($result->id))
239
+ $error = true;
240
+ elseif(isset($result->id))
241
+ $fileHelper->archiveCSV($file);
242
+ }
243
+ }
244
+ } elseif ($item->getImportMode() == self::MODE_SINGLE_DELETE) { //import to single delete
245
+ $importData = unserialize($item->getImportData());
246
+ $result = $client->deleteContactsTransactionalData($importData[0], $item->getImportType());
247
+ if (isset($result->message)) {
248
+ $error = true;
249
+ }
250
+ } else {
251
+ $importData = unserialize($item->getImportData());
252
+ //catalog type and bulk mode
253
+ if (strpos($item->getImportType(), 'Catalog_') !== false && $item->getImportMode() == self::MODE_BULK) {
254
+ $result = $client->postAccountTransactionalDataImport($importData, $item->getImportType());
255
+ if (isset($result->message) && !isset($result->id)) {
256
+ $error = true;
257
+ }
258
+ } elseif ($item->getImportMode() == self::MODE_SINGLE) { // single contact import
259
+ $result = $client->postContactsTransactionalData($importData, $item->getImportType());
260
+ if (isset($result->message)) {
261
+ $error = true;
262
+ }
263
+ } else { //bulk import transactional data
264
+ $result = $client->postContactsTransactionalDataImport($importData, $item->getImportType());
265
+ if (isset($result->message) && !isset($result->id)) {
266
+ $error = true;
267
+ }
268
+ }
269
+ }
270
+ //if curl error 28
271
+ $curlError = $client->getCurlError();
272
+ if($curlError) {
273
+ $item->setMessage($curlError)
274
+ ->setImportStatus(self::FAILED)
275
+ ->save();
276
+ } else{
277
+ if (!$error) {
278
+ if ($item->getImportMode() == self::MODE_SINGLE_DELETE or
279
+ $item->getImportMode() == self::MODE_SINGLE or
280
+ $item->getImportMode() == self::MODE_CONTACT_DELETE
281
+ ) {
282
+ $item->setImportStatus(self::IMPORTED)
283
+ ->setImportFinished($now)
284
+ ->setImportStarted($now)
285
+ ->setMessage('')
286
+ ->save();
287
+
288
+ //process again next item in queue
289
+ $this->_processQueue();
290
+ }
291
+ elseif(isset($result->id) && !isset($result->message)){
292
+ $item->setImportStatus(self::IMPORTING)
293
+ ->setImportId($result->id)
294
+ ->setImportStarted($now)
295
+ ->setMessage('')
296
+ ->save();
297
+ }
298
+ else{
299
+ $item->setImportStatus(self::FAILED)
300
+ ->setMessage($result->message);
301
+
302
+ if(isset($result->id))
303
+ $item->setImportId($result->id);
304
+
305
+ $item->save();
306
+ }
307
+ } elseif ($error) {
308
+ $item->setImportStatus(self::FAILED)
309
+ ->setMessage($result->message);
310
+
311
+ if(isset($result->id))
312
+ $item->setImportId($result->id);
313
+
314
+ $item->save();
315
+ }
316
+ }
317
+ }
318
+ }
319
+
320
+ /**
321
+ * get queue items from importer
322
+ *
323
+ * @param bool $importing
324
+ * @return bool|Varien_Object
325
+ */
326
+ private function _getQueue($importing = false)
327
+ {
328
+ $collection = $this->getCollection();
329
+
330
+ //if true then return item with importing status
331
+ if ($importing)
332
+ $collection->addFieldToFilter('import_status', array('eq' => self::IMPORTING));
333
+ else
334
+ $collection->addFieldToFilter('import_status', array('eq' => self::NOT_IMPORTED));
335
+
336
+ $collection->setPageSize(1);
337
+ if ($collection->count()) {
338
+ return $collection->getFirstItem();
339
+ }
340
+ return false;
341
+ }
342
+
343
+ private function _csv_to_array($filename)
344
+ {
345
+ if(!file_exists($filename) || !is_readable($filename))
346
+ return FALSE;
347
+
348
+ $header = NULL;
349
+ $data = array();
350
+ if (($handle = fopen($filename, 'r')) !== FALSE)
351
+ {
352
+ while (($row = fgetcsv($handle)) !== FALSE)
353
+ {
354
+ if(!$header)
355
+ $header = $row;
356
+ else
357
+ $data[] = array_combine($header, $row);
358
+ }
359
+ fclose($handle);
360
+ }
361
+
362
+ $contacts = array();
363
+ foreach($data as $item){
364
+ if(in_array($item['Reason'], $this->_reasons))
365
+ $contacts[] = $item['email'];
366
+ }
367
+
368
+ return $contacts;
369
+ }
370
+
371
+ private function _remove_utf8_bom($text)
372
+ {
373
+ $bom = pack('H*','EFBBBF');
374
+ $text = preg_replace("/^$bom/", '', $text);
375
+ return $text;
376
+ }
377
+ }
app/code/community/Dotdigitalgroup/Email/Model/Newsletter/Observer.php ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $contactEmail = Mage::getModel('ddg_automation/contact')->loadByCustomerEmail($email, $websiteId);
29
+
30
+ // only for subsribers
31
+ if ($subscriberStatus == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED) {
32
+ $client = Mage::helper('ddg')->getWebsiteApiClient($websiteId);
33
+ //check for website client
34
+ if ($client) {
35
+ //set contact as subscribed
36
+ $contactEmail->setSubscriberStatus( $subscriberStatus )
37
+ ->setIsSubscriber('1');
38
+ $apiContact = $client->postContacts( $email );
39
+
40
+ //resubscribe suppressed contacts
41
+ if (isset($apiContact->message) && $apiContact->message == Dotdigitalgroup_Email_Model_Apiconnector_Client::API_ERROR_CONTACT_SUPPRESSED) {
42
+ $apiContact = $client->getContactByEmail($email);
43
+ $client->postContactsResubscribe( $apiContact );
44
+ }
45
+ }
46
+ // reset the subscriber as suppressed
47
+ $contactEmail->setSuppressed(null);
48
+
49
+ //not subscribed
50
+ } else {
51
+ //skip if contact is suppressed
52
+ if ($contactEmail->getSuppressed())
53
+ return $this;
54
+ //update contact id for the subscriber
55
+ $client = Mage::helper('ddg')->getWebsiteApiClient($websiteId);
56
+ //check for website client
57
+ if ($client) {
58
+ $contactId = $contactEmail->getContactId();
59
+ //get the contact id
60
+ if ( !$contactId ) {
61
+ //if contact id is not set get the contact_id
62
+ $result = $client->postContacts( $email );
63
+ if ( isset( $result->id ) ) {
64
+ $contactId = $result->id;
65
+ } else {
66
+ //no contact id skip
67
+ $contactEmail->setSuppressed( '1' )
68
+ ->save();
69
+ return $this;
70
+ }
71
+ }
72
+ //remove contact from address book
73
+ $client->deleteAddressBookContact( $helper->getSubscriberAddressBook( $websiteId ), $contactId );
74
+ }
75
+ $contactEmail->setIsSubscriber(null)
76
+ ->setSubscriberStatus(Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED);
77
+ }
78
+
79
+ // fix for a multiple hit of the observer
80
+ $emailReg = Mage::registry($email . '_subscriber_save');
81
+ if ($emailReg){
82
+ return $this;
83
+ }
84
+ Mage::register($email . '_subscriber_save', $email);
85
+
86
+ //add subscriber to automation
87
+ $this->_addSubscriberToAutomation($email, $subscriber, $websiteId);
88
+
89
+ //update the contact
90
+ $contactEmail->setStoreId($storeId);
91
+ if (isset($contactId))
92
+ $contactEmail->setContactId($contactId);
93
+ //update contact
94
+ $contactEmail->save();
95
+
96
+ }catch(Exception $e){
97
+ Mage::logException($e);
98
+ Mage::helper('ddg')->getRaygunClient()->SendException($e, array(Mage::getBaseUrl('web')));
99
+ }
100
+ return $this;
101
+ }
102
+
103
+ private function _addSubscriberToAutomation($email, $subscriber, $websiteId){
104
+
105
+ $storeId = $subscriber->getStoreId();
106
+ $store = Mage::app()->getStore($storeId);
107
+ $programId = Mage::helper( 'ddg' )->getAutomationIdByType( 'XML_PATH_CONNECTOR_AUTOMATION_STUDIO_SUBSCRIBER', $websiteId );
108
+ //not mapped ignore
109
+ if (! $programId)
110
+ return;
111
+ try {
112
+ //check the subscriber alredy exists
113
+ $enrolmentCollection = Mage::getModel('ddg_automation/automation')->getCollection()
114
+ ->addFieldToFilter('email', $email)
115
+ ->addFieldToFilter('automation_type', Dotdigitalgroup_Email_Model_Automation::AUTOMATION_TYPE_NEW_SUBSCRIBER)
116
+ ->addFieldToFilter('website_id', $websiteId);
117
+ $enrolmentCollection->getSelect()->limit(1);
118
+ $enrolment = $enrolmentCollection->getFirstItem();
119
+
120
+ //add new subscriber to automation
121
+ if (! $enrolment->getId()) {
122
+ //save subscriber to the queue
123
+ $automation = Mage::getModel( 'ddg_automation/automation' );
124
+ $automation->setEmail( $email )
125
+ ->setAutomationType( Dotdigitalgroup_Email_Model_Automation::AUTOMATION_TYPE_NEW_SUBSCRIBER )
126
+ ->setEnrolmentStatus( Dotdigitalgroup_Email_Model_Automation::AUTOMATION_STATUS_PENDING )
127
+ ->setTypeId( $subscriber->getId() )
128
+ ->setWebsiteId( $websiteId )
129
+ ->setStoreName( $store->getName() )
130
+ ->setProgramId( $programId );
131
+ $automation->save();
132
+ }
133
+ }catch(Exception $e){
134
+ Mage::logException($e);
135
+ }
136
+ }
137
+
138
+ }
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,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ }
app/code/community/Dotdigitalgroup/Email/Model/Order.php ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Order extends Mage_Core_Model_Abstract
4
+ {
5
+ const EMAIL_ORDER_NOT_IMPORTED = null;
6
+ /**
7
+ * constructor
8
+ */
9
+ public function _construct()
10
+ {
11
+ parent::_construct();
12
+ $this->_init('ddg_automation/order');
13
+ }
14
+
15
+ /**
16
+ * @return $this|Mage_Core_Model_Abstract
17
+ */
18
+ protected function _beforeSave()
19
+ {
20
+ parent::_beforeSave();
21
+ $now = Mage::getSingleton('core/date')->gmtDate();
22
+ if ($this->isObjectNew()) {
23
+ $this->setCreatedAt($now);
24
+ }
25
+ return $this;
26
+ }
27
+
28
+
29
+ /**
30
+ * Load the email order by quote id.
31
+ * @param $orderId
32
+ * @param $quoteId
33
+ * @return $this|Varien_Object
34
+ */
35
+ public function loadByOrderId($orderId, $quoteId)
36
+ {
37
+ $collection = $this->getCollection()
38
+ ->addFieldToFilter('order_id', $orderId)
39
+ ->addFieldToFilter('quote_id', $quoteId)
40
+ ->setPageSize(1);
41
+
42
+ if ($collection->count()) {
43
+ return $collection->getFirstItem();
44
+ } else {
45
+ $this->setOrderId($orderId)
46
+ ->setQuoteId($quoteId);
47
+ }
48
+ return $this;
49
+ }
50
+
51
+
52
+ /**
53
+ * @param $orderId
54
+ * @param $quoteId
55
+ * @param $storeId
56
+ *
57
+ * @return $this|Varien_Object
58
+ */
59
+ public function getEmailOrderRow($orderId, $quoteId, $storeId)
60
+ {
61
+ $collection = $this->getCollection()
62
+ ->addFieldToFilter('order_id', $orderId)
63
+ ->addFieldToFilter('quote_id', $quoteId)
64
+ ->addFieldToFilter('store_id', $storeId);
65
+
66
+ if ($collection->count()) {
67
+ return $collection->getFirstItem();
68
+ } else {
69
+ $now = Mage::getSingleton('core/date')->gmtDate();
70
+
71
+ $this->setOrderId($orderId)
72
+ ->setQuoteId($quoteId)
73
+ ->setStoreId($storeId)
74
+ ->setCreatedAt($now);
75
+ }
76
+ return $this;
77
+
78
+ }
79
+
80
+ /**
81
+ * Get all orders with particular status within certain days.
82
+ *
83
+ * @param $storeIds
84
+ * @param $limit
85
+ * @param $orderStatuses
86
+ * @param $modified
87
+ *
88
+ * @return Dotdigitalgroup_Email_Model_Resource_Order_Collection
89
+ */
90
+ public function getOrdersToImport($storeIds, $limit, $orderStatuses, $modified = false)
91
+ {
92
+ $collection = $this->getCollection()
93
+ ->addFieldToFilter('store_id', array('in' => $storeIds))
94
+ ->addFieldToFilter('order_status', array('in' => $orderStatuses));
95
+
96
+ if ($modified) {
97
+ $collection
98
+ ->addFieldToFilter('email_imported', 1)
99
+ ->addFieldToFilter('modified', 1);
100
+ } else
101
+ $collection->addFieldToFilter('email_imported', array('null' => true));
102
+
103
+
104
+ $collection->getSelect()->limit($limit);
105
+ return $collection;
106
+ }
107
+
108
+ /**
109
+ * Get all sent orders older then certain days.
110
+ *
111
+ * @param $storeIds
112
+ * @param $limit
113
+ *
114
+ * @return Dotdigitalgroup_Email_Model_Resource_Order_Collection
115
+ */
116
+ public function getAllSentOrders($storeIds, $limit)
117
+ {
118
+ $collection = $this->getCollection()
119
+ ->addFieldToFilter('email_imported', 1)
120
+ ->addFieldToFilter('store_id', array('in' => $storeIds));
121
+
122
+ $collection->getSelect()->limit($limit);
123
+ return $collection->load();
124
+ }
125
+
126
+ }
app/code/community/Dotdigitalgroup/Email/Model/Quote.php ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
48
+ $apiEnabled = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED, $website);
49
+ $enabled = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_QUOTE_ENABLED, $website);
50
+ $storeIds = $website->getStoreIds();
51
+ if ($enabled && $apiEnabled && !empty($storeIds)) {
52
+ //using bulk api
53
+ $helper->log('---------- Start quote bulk sync ----------');
54
+ $this->_start = microtime(true);
55
+ $this->_exportQuoteForWebsite($website);
56
+ //send quote as transactional data
57
+ if (isset($this->_quotes[$website->getId()])) {
58
+ $websiteQuotes = $this->_quotes[$website->getId()];
59
+ //register in queue with importer
60
+ $check = Mage::getModel('ddg_automation/importer')->registerQueue(
61
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_QUOTE,
62
+ $websiteQuotes,
63
+ Dotdigitalgroup_Email_Model_Importer::MODE_BULK,
64
+ $website->getId()
65
+ );
66
+ //set imported
67
+ if ($check) {
68
+ $this->getResource()->setImported($this->_quoteIds);
69
+ }
70
+ }
71
+ $message = 'Total time for quote bulk sync : ' . gmdate("H:i:s", microtime(true) - $this->_start);
72
+ $helper->log($message);
73
+
74
+ //update quotes
75
+ $this->_exportQuoteForWebsiteInSingle($website);
76
+
77
+ }
78
+ }
79
+ $response['message'] = "quote updated: ". $this->_count;
80
+ return $response;
81
+ }
82
+
83
+ /**
84
+ * export quotes to website
85
+ *
86
+ * @param Mage_Core_Model_Website $website
87
+ */
88
+ private function _exportQuoteForWebsite(Mage_Core_Model_Website $website)
89
+ {
90
+ try{
91
+ //reset quotes
92
+ $this->_quotes = array();
93
+ $this->_quoteIds = array();
94
+ $limit = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_TRANSACTIONAL_DATA_SYNC_LIMIT, $website);
95
+ $collection = $this->_getQuoteToImport($website, $limit);
96
+
97
+ foreach ($collection as $emailQuote) {
98
+
99
+ $quote = Mage::getModel('sales/quote')->load($emailQuote->getQuoteId());
100
+
101
+ if ($quote->getId()) {
102
+
103
+ $connectorQuote = Mage::getModel('ddg_automation/connector_quote', $quote);
104
+ $this->_quotes[$website->getId()][] = $connectorQuote;
105
+ }
106
+ $this->_quoteIds[] = $emailQuote->getQuoteId();
107
+ $this->_count++;
108
+ }
109
+ }catch(Exception $e){
110
+ Mage::logException($e);
111
+ }
112
+ }
113
+
114
+ /**
115
+ * get quotes to import
116
+ *
117
+ * @param Mage_Core_Model_Website $website
118
+ * @param int $limit
119
+ * @param $modified
120
+ *
121
+ * @return mixed
122
+ */
123
+ private function _getQuoteToImport(Mage_Core_Model_Website $website, $limit = 100, $modified = false)
124
+ {
125
+ $collection = $this->getCollection()
126
+ ->addFieldToFilter('store_id', array('in' => $website->getStoreIds()))
127
+ ->addFieldToFilter('customer_id', array('notnull' => true));
128
+
129
+ if ($modified) {
130
+ $collection->addFieldToFilter('modified', 1)
131
+ ->addFieldToFilter('imported', 1);
132
+ } else {
133
+ $collection->addFieldToFilter('imported', array('null' => true));
134
+ }
135
+
136
+ $collection->getSelect()->limit($limit);
137
+ return $collection;
138
+ }
139
+
140
+ /**
141
+ * update quotes for website in single
142
+ *
143
+ * @param Mage_Core_Model_Website $website
144
+ */
145
+ private function _exportQuoteForWebsiteInSingle(Mage_Core_Model_Website $website)
146
+ {
147
+ try {
148
+ $limit = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_TRANSACTIONAL_DATA_SYNC_LIMIT, $website);
149
+ $collection = $this->_getQuoteToImport($website, $limit, true);
150
+
151
+ foreach ($collection as $emailQuote) {
152
+ $quote = Mage::getModel('sales/quote')->load($emailQuote->getQuoteId());
153
+ if($quote->getId()) {
154
+
155
+ $connectorQuote = Mage::getModel('ddg_automation/connector_quote', $quote);
156
+ //register in queue with importer
157
+ $check = Mage::getModel('ddg_automation/importer')->registerQueue(
158
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_QUOTE,
159
+ $connectorQuote,
160
+ Dotdigitalgroup_Email_Model_Importer::MODE_SINGLE,
161
+ $website->getId()
162
+ );
163
+ if ($check) {
164
+ $message = 'Quote updated : ' . $emailQuote->getQuoteId();
165
+ Mage::helper('ddg')->log($message);
166
+ $emailQuote->setModified(null)->save();
167
+ $this->_count++;
168
+ }
169
+ }
170
+ }
171
+ } catch (Exception $e) {
172
+ Mage::logException($e);
173
+ }
174
+ }
175
+
176
+ /**
177
+ * load quote from connector table
178
+ *
179
+ * @param $quoteId
180
+ * @return bool
181
+ */
182
+ public function loadQuote($quoteId)
183
+ {
184
+ $collection = $this->getCollection();
185
+ $collection->addFieldToFilter('quote_id', $quoteId)
186
+ ->setPageSize(1);
187
+
188
+ if ($collection->count()) {
189
+ return $collection->getFirstItem();
190
+ }
191
+ return false;
192
+ }
193
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Automation.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Automation extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+
6
+ /**
7
+ * constructor.
8
+ */
9
+ protected function _construct()
10
+ {
11
+ $this->_init('ddg_automation/automation', 'id');
12
+
13
+ }
14
+
15
+ public function updateContacts($contacts, $programStatus, $programMessage)
16
+ {
17
+ $conn = $this->_getWriteAdapter();
18
+ try {
19
+ $contactIds = array_keys($contacts);
20
+ $bind = array(
21
+ 'enrolment_status' => $programStatus,
22
+ 'message' => $programMessage,
23
+ 'updated_at' => Mage::getSingleton('core/date')->gmtDate()
24
+ );
25
+ $where = array('id IN(?)' => $contactIds);
26
+ $num = $conn->update( $this->getMainTable(),
27
+ $bind,
28
+ $where
29
+ );
30
+ return $num;
31
+ } catch ( Exception $e ) {
32
+ Mage::logException($e);
33
+ }
34
+ }
35
+
36
+ /**
37
+ * mass delete
38
+ *
39
+ * @param $automationIds
40
+ * @return Exception|int
41
+ */
42
+ public function massDelete($automationIds)
43
+ {
44
+ try {
45
+ $conn = $this->_getWriteAdapter();
46
+ $num = $conn->delete(
47
+ $this->getMainTable(),
48
+ array('id IN(?)' => $automationIds)
49
+ );
50
+ return $num;
51
+ } catch (Exception $e) {
52
+ return $e;
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Mark for resend.
58
+ *
59
+ * @param $automationIds
60
+ * @return int
61
+ */
62
+ public function massResend($automationIds)
63
+ {
64
+ try {
65
+ $conn = $this->_getWriteAdapter();
66
+ $num = $conn->update($this->getMainTable(),
67
+ array('enrolment_status' => Dotdigitalgroup_Email_Model_Automation::AUTOMATION_STATUS_PENDING),
68
+ array('id IN(?)' => $automationIds)
69
+ );
70
+ return $num;
71
+ } catch (Exception $e) {
72
+ return $e;
73
+ }
74
+ }
75
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Automation/Collection.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Automation_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
4
+ {
5
+ /**
6
+ * constructor.
7
+ */
8
+ protected function _construct()
9
+ {
10
+ parent::_construct();
11
+ $this->_init('ddg_automation/automation');
12
+ }
13
+
14
+
15
+ /**
16
+ * @param $website
17
+ * @return $this
18
+ */
19
+ public function addWebsiteFilter($website)
20
+ {
21
+ $this->addFilter('website_id', $website);
22
+ return $this;
23
+ }
24
+
25
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Campaign.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Campaign extends Mage_Core_Model_Resource_Db_Abstract
4
+ {
5
+ /**
6
+ * constructor.
7
+ */
8
+ protected function _construct()
9
+ {
10
+ $this->_init('ddg_automation/campaign', 'id');
11
+
12
+ }
13
+
14
+ /**
15
+ * Delete mass campaigns.
16
+ *
17
+ * @param $campaignIds
18
+ * @return Exception|int
19
+ */
20
+ public function massDelete($campaignIds)
21
+ {
22
+ try {
23
+ $conn =$this->_getWriteAdapter();
24
+ $num = $conn->delete(
25
+ $this->getMainTable(),
26
+ array('id IN(?)' => $campaignIds)
27
+ );
28
+ return $num;
29
+ } catch (Exception $e) {
30
+ return $e;
31
+ }
32
+ }
33
+
34
+ /**
35
+ * Mass mark for resend campaigns.
36
+ *
37
+ * @param $campaignIds
38
+ * @return Exception|int
39
+ */
40
+ public function massResend($campaignIds)
41
+ {
42
+ try {
43
+ $conn = $this->_getWriteAdapter();
44
+ $num = $conn->update(
45
+ $this->getMainTable(),
46
+ array('is_sent' => new Zend_Db_Expr('null')),
47
+ array('id IN(?)' => $campaignIds)
48
+ );
49
+ return $num;
50
+ } catch (Exception $e) {
51
+ return $e;
52
+ }
53
+ }
54
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Campaign/Collection.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Campaign_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
4
+ {
5
+ /**
6
+ * constructor.
7
+ */
8
+ public function _construct()
9
+ {
10
+ parent::_construct();
11
+ $this->_init('ddg_automation/campaign');
12
+ }
13
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Catalog.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Catalog extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+ /**
6
+ * constructor.
7
+ */
8
+ protected function _construct()
9
+ {
10
+ $this->_init('ddg_automation/catalog', 'id');
11
+
12
+ }
13
+
14
+ /**
15
+ * Reset for re-import.
16
+ *
17
+ * @return int
18
+ */
19
+ public function reset()
20
+ {
21
+ $conn = $this->_getWriteAdapter();
22
+ try{
23
+ $num = $conn->update($this->getMainTable(),
24
+ array('imported' => new Zend_Db_Expr('null'), 'modified' => new Zend_Db_Expr('null'))
25
+ );
26
+ return $num;
27
+ }catch (Exception $e){
28
+ Mage::logException($e);
29
+ }
30
+ }
31
+
32
+ /**
33
+ * set imported in bulk query. if modified true then set modified to null in bulk query.
34
+ *
35
+ * @param $ids
36
+ * @param $modified
37
+ */
38
+ public function setImported($ids, $modified = false)
39
+ {
40
+ try{
41
+ $write = $this->_getWriteAdapter();
42
+ $tableName = $this->getMainTable();
43
+ $ids = implode(', ', $ids);
44
+ $now = Mage::getSingleton('core/date')->gmtDate();
45
+ if($modified)
46
+ $write->update($tableName, array('modified' => new Zend_Db_Expr('null'), 'updated_at' => $now), "product_id IN ($ids)");
47
+ else
48
+ $write->update($tableName, array('imported' => 1, 'updated_at' => $now), "product_id IN ($ids)");
49
+ }catch (Exception $e){
50
+ Mage::logException($e);
51
+ }
52
+ }
53
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Catalog/Collection.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Catalog_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
4
+ {
5
+ /**
6
+ * constructor.
7
+ */
8
+ public function _construct()
9
+ {
10
+ parent::_construct();
11
+ $this->_init('ddg_automation/catalog');
12
+ }
13
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Contact.php ADDED
@@ -0,0 +1,315 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Contact extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+
6
+ /**
7
+ * constructor.
8
+ */
9
+ protected function _construct()
10
+ {
11
+ $this->_init('ddg_automation/contact', 'email_contact_id');
12
+
13
+ }
14
+
15
+ /**
16
+ * Remove contact id's.
17
+ *
18
+ * @return int
19
+ */
20
+ public function deleteContactIds()
21
+ {
22
+ try{
23
+ $conn = $this->getReadConnection();
24
+ $num = $conn->update($this->getMainTable(),
25
+ array('contact_id' => new Zend_Db_Expr('null')),
26
+ $conn->quoteInto('contact_id is ?', new Zend_Db_Expr('not null'))
27
+ );
28
+ return $num;
29
+ }catch (Exception $e){
30
+ Mage::logException($e);
31
+ Mage::helper('ddg')->rayLog($e);
32
+ }
33
+ }
34
+
35
+ /**
36
+ * Reset the imported contacts
37
+ * @return int
38
+ */
39
+ public function resetAllContacts()
40
+ {
41
+ try{
42
+ $conn = $this->_getWriteAdapter();
43
+ $num = $conn->update($this->getMainTable(),
44
+ array('email_imported' => new Zend_Db_Expr('null')),
45
+ $conn->quoteInto('email_imported is ?', new Zend_Db_Expr('not null'))
46
+ );
47
+ return $num;
48
+ }catch (Exception $e){
49
+ Mage::logException($e);
50
+ Mage::helper('ddg')->rayLog($e);
51
+ }
52
+ }
53
+
54
+ /**
55
+ * Set all imported subscribers for re-import.
56
+ *
57
+ * @return int
58
+ */
59
+ public function resetSubscribers()
60
+ {
61
+ try {
62
+ $conn = $this->_getWriteAdapter();
63
+ $num = $conn->update(
64
+ $this->getMainTable(),
65
+ array('subscriber_imported' => new Zend_Db_Expr( 'null' ) ),
66
+ $conn->quoteInto('subscriber_imported is ?', new Zend_Db_Expr('not null')));
67
+ return $num;
68
+ } catch ( Exception $e ) {
69
+ Mage::logException($e);
70
+ Mage::helper('ddg')->sendRaygunException($e);
71
+ }
72
+ }
73
+
74
+ /**
75
+ * Reset the imported contacts as guest
76
+ * @return int
77
+ */
78
+ public function resetAllGuestContacts()
79
+ {
80
+ try {
81
+ $conn = $this->_getWriteAdapter();
82
+ $where = array();
83
+ $where[] = $conn->quoteInto('email_imported is ?', new Zend_Db_Expr('not null'));
84
+ $where[] = $conn->quoteInto('is_guest is ?', new Zend_Db_Expr('not null'));
85
+
86
+ $num = $conn->update($this->getMainTable(),
87
+ array('email_imported' => new Zend_Db_Expr('null')),
88
+ $where
89
+ );
90
+ return $num;
91
+ } catch (Exception $e) {
92
+ Mage::logException($e);
93
+ Mage::helper('ddg')->rayLog($e);
94
+ }
95
+ }
96
+
97
+ /**
98
+ * populate and cleanup
99
+ */
100
+ public function populateAndCleanup()
101
+ {
102
+ $write = $this->_getWriteAdapter();
103
+ $contactTable = $this->getMainTable();
104
+ $select = $write->select();
105
+
106
+ //populate customers to email_contact
107
+ $emailContacts = Mage::getModel('ddg_automation/contact')
108
+ ->getCollection()
109
+ ->getColumnValues('customer_id');
110
+ $emailContacts = implode(',', $emailContacts);
111
+
112
+ $select
113
+ ->from(
114
+ array('customer' => $this->getReadConnection()->getTableName('customer/customer')),
115
+ array('customer_id' => 'entity_id','email','website_id','store_id')
116
+ )
117
+ ->where("entity_id not in ($emailContacts)");
118
+
119
+ $insertArray = array('customer_id','email','website_id','store_id');
120
+ $sqlQuery = $select->insertFromSelect($contactTable, $insertArray, false);
121
+ $write->query($sqlQuery);
122
+
123
+ //remove contact with customer id set and no customer
124
+ $select->reset()
125
+ ->from(
126
+ array('c' => $contactTable),
127
+ array('c.customer_id')
128
+ )
129
+ ->joinLeft(
130
+ array('e' => $this->getReadConnection()->getTableName('customer/customer')),
131
+ "c.customer_id = e.entity_id"
132
+ )
133
+ ->where('e.entity_id is NULL');
134
+ $deleteSql = $select->deleteFromSelect('c');
135
+ $write->query($deleteSql);
136
+ }
137
+
138
+ /**
139
+ * Re-set all tables
140
+ */
141
+ public function resetAllTables()
142
+ {
143
+ $conn = $this->_getWriteAdapter();
144
+ try{
145
+ //remove dotmailer code from core_resource table
146
+ $cond = $conn->quoteInto('code = ?', 'email_connector_setup');
147
+ $conn->delete($this->getReadConnection()->getTableName('core_resource'), $cond);
148
+
149
+ //clean cache
150
+ Mage::app()->getCacheInstance()->flush();
151
+
152
+ }catch (Exception $e){
153
+ Mage::logException($e);
154
+ }
155
+ }
156
+
157
+ public function update($customer)
158
+ {
159
+ $write = $this->_getWriteAdapter();
160
+ if(is_array($customer)){
161
+ $ids = implode(', ', $customer);
162
+ $write->update($this->getMainTable(), array('email_imported' => 1), "customer_id IN ($ids)");
163
+ }
164
+ else
165
+ $write->update($this->getMainTable(), array('email_imported' => 1), "customer_id = $customer");
166
+ }
167
+
168
+ /**
169
+ * Mass delete contacts.
170
+ *
171
+ * @param $contactIds
172
+ * @return Exception|int
173
+ */
174
+ public function massDelete($contactIds)
175
+ {
176
+ try {
177
+ $conn = $this->_getWriteAdapter();
178
+ $num = $conn->delete(
179
+ $this->getMainTable(),
180
+ array('email_contact_id IN(?)' => $contactIds)
181
+ );
182
+ return $num;
183
+ } catch (Exception $e) {
184
+ return $e;
185
+ }
186
+ }
187
+
188
+ /**
189
+ * Mark a contact to be resend.
190
+ *
191
+ * @param $contactIds
192
+ * @return Exception|int
193
+ */
194
+ public function massResend($contactIds)
195
+ {
196
+ try {
197
+ $conn = $this->_getWriteAdapter();
198
+ $num = $conn->update(
199
+ $this->getMainTable(),
200
+ array('email_imported' => new Zend_Db_Expr('null')),
201
+ array('email_contact_id IN(?)' => $contactIds)
202
+ );
203
+ return $num;
204
+ } catch (Exception $e) {
205
+ return $e;
206
+ }
207
+ }
208
+
209
+ /**
210
+ * prepare recency part of RFM
211
+ *
212
+ * @param $collection
213
+ * @return array
214
+ */
215
+ public function prepareRecency($collection)
216
+ {
217
+ $select = $collection->getSelect()
218
+ ->reset(Zend_Db_Select::COLUMNS)
219
+ ->reset(Zend_Db_Select::ORDER)
220
+ ->columns(array(
221
+ 'last_order_days_ago' => "DATEDIFF(date(NOW()) , date(MAX(created_at)))"
222
+ ))->order('last_order_days_ago');
223
+ return $this->getReadConnection()->fetchCol($select);
224
+ }
225
+
226
+ /**
227
+ * prepare frequency part of RFM
228
+ *
229
+ * @param $collection
230
+ * @return array
231
+ */
232
+ public function prepareFrequency($collection)
233
+ {
234
+ $select = $collection->getSelect()
235
+ ->reset(Zend_Db_Select::COLUMNS)
236
+ ->columns(array(
237
+ 'customer_total_orders' => "count(*)",
238
+ ))->order('customer_total_orders');
239
+ return $this->getReadConnection()->fetchCol($select);
240
+ }
241
+
242
+ /**
243
+ * prepare monetary part of RFM
244
+ *
245
+ * @param $collection
246
+ * @return array
247
+ */
248
+ public function prepareMonetary($collection)
249
+ {
250
+ $expr = $this->getSalesAmountExpression($collection);
251
+ $select = $collection->getSelect()
252
+ ->reset(Zend_Db_Select::COLUMNS)
253
+ ->reset(Zend_Db_Select::ORDER)
254
+ ->columns(array(
255
+ 'customer_average_order_value' => "SUM({$expr})/count(*)",
256
+ ))->order('customer_average_order_value');
257
+ return $this->getReadConnection()->fetchCol($select);
258
+ }
259
+
260
+ /**
261
+ * get sales amount expression
262
+ *
263
+ * @param $collection
264
+ * @return string
265
+ */
266
+ public function getSalesAmountExpression($collection)
267
+ {
268
+ $adapter = $collection->getConnection();
269
+ $expressionTransferObject = new Varien_Object(array(
270
+ 'expression' => '%s - %s - %s - (%s - %s - %s)',
271
+ 'arguments' => array(
272
+ $adapter->getIfNullSql('main_table.base_total_invoiced', 0),
273
+ $adapter->getIfNullSql('main_table.base_tax_invoiced', 0),
274
+ $adapter->getIfNullSql('main_table.base_shipping_invoiced', 0),
275
+ $adapter->getIfNullSql('main_table.base_total_refunded', 0),
276
+ $adapter->getIfNullSql('main_table.base_tax_refunded', 0),
277
+ $adapter->getIfNullSql('main_table.base_shipping_refunded', 0),
278
+ )
279
+ ));
280
+
281
+ return vsprintf(
282
+ $expressionTransferObject->getExpression(),
283
+ $expressionTransferObject->getArguments()
284
+ );
285
+
286
+ }
287
+
288
+ public function unsubscribe($data)
289
+ {
290
+ $write = $this->_getWriteAdapter();
291
+ $emails = '"' . implode('","', $data) . '"';
292
+
293
+ try{
294
+ //un-subscribe from the email contact table.
295
+ $write->update(
296
+ $this->getMainTable(),
297
+ array(
298
+ 'is_subscriber' => new Zend_Db_Expr('null'),
299
+ 'suppressed' => '1'
300
+ ),
301
+ "email IN ($emails)"
302
+ );
303
+
304
+ // un-subscribe newsletter subscribers
305
+ $write->update(
306
+ $this->getTable('newsletter/subscriber'),
307
+ array('subscriber_status' => Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED),
308
+ "subscriber_email IN ($emails)"
309
+ );
310
+ }catch (Exception $e){
311
+ Mage::throwException($e->getMessage());
312
+ Mage::logException($e);
313
+ }
314
+ }
315
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Contact/Collection.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Contact_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
4
+ {
5
+ /**
6
+ * constructor.
7
+ */
8
+ protected function _construct()
9
+ {
10
+ parent::_construct();
11
+ $this->_init('ddg_automation/contact');
12
+ }
13
+
14
+
15
+ /**
16
+ * @param $website
17
+ * @return $this
18
+ */
19
+ public function addWebsiteFilter($website)
20
+ {
21
+ $this->addFilter('website_id', $website);
22
+ return $this;
23
+ }
24
+
25
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Importer.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Importer extends Mage_Core_Model_Resource_Db_Abstract
4
+ {
5
+ /**
6
+ * cosntructor.
7
+ */
8
+ protected function _construct()
9
+ {
10
+ $this->_init('ddg_automation/importer', 'id');
11
+ }
12
+
13
+ /**
14
+ * Mark a contact to be resend.
15
+ *
16
+ * @param $ids
17
+ * @return Exception|int
18
+ */
19
+ public function massResend($ids)
20
+ {
21
+ try {
22
+ $conn = $this->_getWriteAdapter();
23
+ $num = $conn->update($this->getMainTable(),
24
+ array('import_status' => 0),
25
+ array('id IN(?)' => $ids)
26
+ );
27
+ return $num;
28
+ } catch (Exception $e) {
29
+ return $e;
30
+ }
31
+ }
32
+
33
+ /**
34
+ * Mass delete contacts.
35
+ *
36
+ * @param $ids
37
+ * @return Exception|int
38
+ */
39
+ public function massDelete($ids)
40
+ {
41
+ try {
42
+ $conn = $this->_getWriteAdapter();
43
+ $num = $conn->delete($this->getMainTable(),
44
+ array('id IN(?)' => $ids)
45
+ );
46
+ return $num;
47
+ } catch (Exception $e) {
48
+ return $e;
49
+ }
50
+ }
51
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Importer/Collection.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Importer_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
4
+ {
5
+ /**
6
+ * constructor.
7
+ */
8
+ protected function _construct()
9
+ {
10
+ parent::_construct();
11
+ $this->_init('ddg_automation/importer');
12
+ }
13
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Order.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Order extends Mage_Core_Model_Resource_Db_Abstract
4
+ {
5
+ /**
6
+ * cosntructor.
7
+ */
8
+ protected function _construct()
9
+ {
10
+ $this->_init('ddg_automation/order', 'email_order_id');
11
+ }
12
+
13
+ /**
14
+ * get sales_flat_order table description
15
+ *
16
+ * @return array
17
+ */
18
+ public function getOrderTableDescription()
19
+ {
20
+ return $this->getReadConnection()->describeTable($this->getTable('sales/order'));
21
+ }
22
+
23
+ /**
24
+ * Reset the email order for reimport.
25
+ *
26
+ * @return int
27
+ */
28
+ public function resetOrders()
29
+ {
30
+ try{
31
+ $conn = $this->_getWriteAdapter();
32
+ $num = $conn->update($this->getMainTable(),
33
+ array('email_imported' => new Zend_Db_Expr('null'), 'modified' => new Zend_Db_Expr('null')),
34
+ $conn->quoteInto('email_imported is ?', new Zend_Db_Expr('not null'))
35
+ );
36
+ return $num;
37
+ }catch (Exception $e){
38
+ Mage::logException($e);
39
+ }
40
+ }
41
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Order/Collection.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Order_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
4
+ {
5
+
6
+ /**
7
+ * constructor.
8
+ */
9
+ public function _construct()
10
+ {
11
+ parent::_construct();
12
+ $this->_init('ddg_automation/order');
13
+ }
14
+
15
+
16
+
17
+
18
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Quote.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Quote extends Mage_Core_Model_Resource_Db_Abstract
4
+ {
5
+ /**
6
+ * constructor.
7
+ */
8
+ protected function _construct()
9
+ {
10
+ $this->_init('ddg_automation/quote', 'id');
11
+ }
12
+
13
+ /**
14
+ * get sales_flat_quote table description
15
+ *
16
+ * @return array
17
+ */
18
+ public function getQuoteTableDescription()
19
+ {
20
+ return $this->getReadConnection()->describeTable($this->getTable('sales/quote'));
21
+ }
22
+
23
+ /**
24
+ * Reset the email quote for re-import.
25
+ *
26
+ * @return int
27
+ */
28
+ public function resetQuotes()
29
+ {
30
+ $conn = $this->_getWriteAdapter();
31
+ try{
32
+ $num = $conn->update(
33
+ $this->getMainTable(),
34
+ array('imported' => new Zend_Db_Expr('null'), 'modified' => new Zend_Db_Expr('null'))
35
+ );
36
+ return $num;
37
+ }catch (Exception $e){
38
+ Mage::logException($e);
39
+ }
40
+ }
41
+
42
+ /**
43
+ * set imported in bulk query
44
+ *
45
+ * @param $ids
46
+ */
47
+ public function setImported($ids)
48
+ {
49
+ try{
50
+ $write = $this->_getWriteAdapter();
51
+ $tableName = $this->getMainTable();
52
+ $ids = implode(', ', $ids);
53
+ $now = Mage::getSingleton('core/date')->gmtDate();
54
+ $write->update($tableName, array('imported' => 1, 'updated_at' => $now, 'modified' => new Zend_Db_Expr('null')), "quote_id IN ($ids)");
55
+ }catch (Exception $e){
56
+ Mage::logException($e);
57
+ }
58
+ }
59
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Quote/Collection.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Quote_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
4
+ {
5
+
6
+ /**
7
+ * constructor.
8
+ */
9
+ public function _construct()
10
+ {
11
+ parent::_construct();
12
+ $this->_init('ddg_automation/quote');
13
+ }
14
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Review.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Review extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+ /**
6
+ * constructor.
7
+ */
8
+ protected function _construct()
9
+ {
10
+ $this->_init('ddg_automation/review', 'id');
11
+
12
+ }
13
+
14
+ /**
15
+ * Reset the email reviews for reimport.
16
+ *
17
+ * @return int
18
+ */
19
+ public function reset()
20
+ {
21
+ $conn = $this->_getWriteAdapter();
22
+ try{
23
+ $num = $conn->update($this->getMainTable(),
24
+ array('review_imported' => new Zend_Db_Expr('null')),
25
+ $conn->quoteInto('review_imported is ?', new Zend_Db_Expr('not null'))
26
+ );
27
+ return $num;
28
+ }catch (Exception $e){
29
+ Mage::logException($e);
30
+ }
31
+ }
32
+
33
+ /**
34
+ * set imported in bulk query
35
+ *
36
+ * @param $ids
37
+ */
38
+ public function setImported($ids)
39
+ {
40
+ try{
41
+ $write = $this->_getWriteAdapter();
42
+ $tableName = $this->getMainTable();
43
+ $ids = implode(', ', $ids);
44
+ $now = Mage::getSingleton('core/date')->gmtDate();
45
+ $write->update($tableName, array('review_imported' => 1, 'updated_at' => $now), "review_id IN ($ids)");
46
+ }catch (Exception $e){
47
+ Mage::logException($e);
48
+ }
49
+ }
50
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Review/Collection.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Review_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
4
+ {
5
+ /**
6
+ * constructor.
7
+ */
8
+ public function _construct()
9
+ {
10
+ parent::_construct();
11
+ $this->_init('ddg_automation/review');
12
+ }
13
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Rules.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Rules extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+ /**
6
+ * constructor.
7
+ */
8
+ protected function _construct()
9
+ {
10
+ $this->_init('ddg_automation/rules', 'id');
11
+
12
+ }
13
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Rules/Collection.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Rules_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
4
+ {
5
+ /**
6
+ * constructor.
7
+ */
8
+ public function _construct()
9
+ {
10
+ parent::_construct();
11
+ $this->_init('ddg_automation/rules');
12
+ }
13
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Segment.php ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $collection->getSelect()->limit(1);
93
+
94
+ $contact = $collection->getFirstItem();
95
+ $existing = $contact->getSegmentIds();
96
+
97
+ $existing = explode(',', $existing);
98
+ //no segments found set current segment
99
+ if ( ! in_array( $segmentId, $existing ) ) {
100
+
101
+ //for the existing
102
+ if ( count( $existing ) == 1 ) {
103
+ $existing = $segmentId;
104
+ } else {
105
+ $existing[] = $segmentId;
106
+ $existing = implode( ',', $existing );
107
+ }
108
+ }
109
+
110
+ //update new segmets and mark for import
111
+ $contact->setSegmentIds($existing)
112
+ ->setEmailImported()
113
+ ->save();
114
+ }
115
+
116
+
117
+ public function deleteSegmentCustomers($segment)
118
+ {
119
+ $this->_getWriteAdapter()->delete(
120
+ $this->getTable('enterprise_customersegment/customer'),
121
+ array('segment_id=?' => $segment->getId())
122
+ );
123
+
124
+ /**
125
+ * Trigger the delete for contact segment ids.
126
+ */
127
+ $this->deleteSegmentContacts($segment->getId());
128
+ return $this;
129
+ }
130
+
131
+ protected function deleteSegmentContacts($segment){
132
+
133
+ $contacts = Mage::getModel('ddg_automation/contact')->getCollection()
134
+ ->addFieldToFilter('segment_ids', array('finset'=> array($segment)));
135
+ foreach ( $contacts as $contact ) {
136
+ //segments found for contact
137
+ $segments = explode(',', $contact->getSegmentIds());
138
+ foreach ( $segments as $key => $one ) {
139
+ if ($segment == $one)
140
+ unset($segments[$key]);
141
+ }
142
+
143
+ //save the comma separated values
144
+ if (count($segments) == 1)
145
+ $segments = $segments[0];
146
+ else
147
+ $segments = implode(',' , $segments);
148
+
149
+ //save updated segments for contact
150
+ $contact->setSegmentIds($segments)
151
+ ->setEmailImported()
152
+ ->save();
153
+ }
154
+ }
155
+
156
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Setup.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Setup extends Mage_Eav_Model_Entity_Setup
4
+ {
5
+ /**
6
+ * This method returns true if the attribute exists.
7
+ *
8
+ * @param string|int $entityTypeId
9
+ * @param string|int $attributeId
10
+ * @return bool
11
+ */
12
+ public function attributeExists($entityTypeId, $attributeId)
13
+ {
14
+ try
15
+ {
16
+ $entityTypeId = $this->getEntityTypeId($entityTypeId);
17
+ $attributeId = $this->getAttributeId($entityTypeId, $attributeId);
18
+ return !empty($attributeId);
19
+ }
20
+ catch(Exception $e)
21
+ {
22
+ return FALSE;
23
+ }
24
+ }
25
+
26
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Wishlist.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Wishlist extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+ /**
6
+ * constructor.
7
+ */
8
+ protected function _construct()
9
+ {
10
+ $this->_init('ddg_automation/wishlist', 'id');
11
+
12
+ }
13
+
14
+ /**
15
+ * Reset the email reviews for re-import.
16
+ *
17
+ * @return int
18
+ */
19
+ public function reset()
20
+ {
21
+ $conn = $this->_getWriteAdapter();
22
+ try{
23
+ $num = $conn->update($this->getMainTable(),
24
+ array('wishlist_imported' => new Zend_Db_Expr('null'), 'wishlist_modified' => new Zend_Db_Expr('null'))
25
+ );
26
+ return $num;
27
+ }catch (Exception $e){
28
+ Mage::logException($e);
29
+ }
30
+ }
31
+
32
+ /**
33
+ * set imported in bulk query
34
+ *
35
+ * @param $ids
36
+ * @param $modified
37
+ */
38
+ public function setImported($ids, $modified = false)
39
+ {
40
+ try{
41
+ $write = $this->_getWriteAdapter();
42
+ $tableName = $this->getMainTable();
43
+ $ids = implode(', ', $ids);
44
+ $now = Mage::getSingleton('core/date')->gmtDate();
45
+ if($modified)
46
+ $write->update($tableName, array('wishlist_modified' => new Zend_Db_Expr('null'), 'updated_at' => $now), "wishlist_id IN ($ids)");
47
+ else
48
+ $write->update($tableName, array('wishlist_imported' => 1, 'updated_at' => $now), "wishlist_id IN ($ids)");
49
+ }catch (Exception $e){
50
+ Mage::logException($e);
51
+ }
52
+ }
53
+ }
app/code/community/Dotdigitalgroup/Email/Model/Resource/Wishlist/Collection.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Resource_Wishlist_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
4
+ {
5
+ /**
6
+ * constructor.
7
+ */
8
+ public function _construct()
9
+ {
10
+ parent::_construct();
11
+ $this->_init('ddg_automation/wishlist');
12
+ }
13
+ }
app/code/community/Dotdigitalgroup/Email/Model/Review.php ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Review extends Mage_Core_Model_Abstract
4
+ {
5
+ private $_start;
6
+ private $_countReviews;
7
+ private $_reviews;
8
+ private $_reviewIds;
9
+
10
+ const EMAIL_REVIEW_IMPORTED = 1;
11
+
12
+ /**
13
+ * constructor
14
+ */
15
+ public function _construct()
16
+ {
17
+ parent::_construct();
18
+ $this->_init('ddg_automation/review');
19
+ }
20
+
21
+ /**
22
+ * @return $this|Mage_Core_Model_Abstract
23
+ */
24
+ protected function _beforeSave()
25
+ {
26
+ parent::_beforeSave();
27
+ $now = Mage::getSingleton('core/date')->gmtDate();
28
+ if ($this->isObjectNew()) {
29
+ $this->setCreatedAt($now);
30
+ }else {
31
+ $this->setUpdatedAt($now);
32
+ }
33
+ return $this;
34
+ }
35
+
36
+ public function sync()
37
+ {
38
+ $response = array('success' => true, 'message' => '');
39
+ $helper = Mage::helper('ddg');
40
+ $this->_countReviews = 0;
41
+ $this->_reviews = array();
42
+ $this->_start = microtime(true);
43
+ //resource allocation
44
+ $helper->allowResourceFullExecution();
45
+ foreach (Mage::app()->getWebsites(true) as $website) {
46
+
47
+ $enabled = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED, $website);
48
+ $sync = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_REVIEW_ENABLED, $website);
49
+ $storeIds = $website->getStoreIds();
50
+ if ($enabled && $sync && !empty($storeIds)) {
51
+ //start the sync
52
+ if (! $this->_countReviews)
53
+ $helper->log('---------- Start reviews sync ----------');
54
+ $this->_exportReviewsForWebsite($website);
55
+ }
56
+
57
+ if (isset($this->_reviews[$website->getId()])) {
58
+ $reviews = $this->_reviews[$website->getId()];
59
+ //send reviews as transactional data
60
+ //register in queue with importer
61
+ $check = Mage::getModel('ddg_automation/importer')->registerQueue(
62
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_REVIEWS,
63
+ $reviews,
64
+ Dotdigitalgroup_Email_Model_Importer::MODE_BULK,
65
+ $website->getId()
66
+ );
67
+ //if no error then set imported
68
+ if ($check) {
69
+ $this->getResource()->setImported($this->_reviewIds);
70
+ }
71
+ $this->_countReviews += count($reviews);
72
+ }
73
+ }
74
+
75
+ if ($this->_countReviews) {
76
+ $message = 'Total time for sync : ' . gmdate( "H:i:s", microtime( true ) - $this->_start ) . ', Total synced = ' . $this->_countReviews;
77
+ $helper->log( $message );
78
+ $response['message'] = $message;
79
+ }
80
+ return $response;
81
+ }
82
+
83
+ private function _exportReviewsForWebsite(Mage_Core_Model_Website $website)
84
+ {
85
+ $limit = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_TRANSACTIONAL_DATA_SYNC_LIMIT, $website);
86
+ $emailReviews = $this->_getReviewsToExport($website, $limit);
87
+ $this->_reviewIds = $emailReviews->getColumnValues('review_id');
88
+
89
+ if(!empty($this->_reviewIds)){
90
+ $reviews = Mage::getModel('review/review')
91
+ ->getCollection()
92
+ ->addFieldToFilter('main_table.review_id', array('in' => $this->_reviewIds))
93
+ ->addFieldToFilter('customer_id', array('notnull' => 'true'));
94
+
95
+ $reviews->getSelect()
96
+ ->joinLeft(
97
+ array('c' => 'customer_entity'),
98
+ 'c.entity_id = customer_id',
99
+ array('email','store_id')
100
+ );
101
+
102
+ if($reviews->getSize()){
103
+ foreach($reviews as $mageReview){
104
+ try {
105
+ $product = Mage::getModel('catalog/product')
106
+ ->getCollection()
107
+ ->addIdFilter($mageReview->getEntityPkValue())
108
+ ->setStoreId($mageReview->getStoreId())
109
+ ->addAttributeToSelect(array('product_url', 'name', 'store_id', 'small_image'))
110
+ ->setPage(1,1)
111
+ ->getFirstItem();
112
+
113
+ $connectorReview = Mage::getModel('ddg_automation/customer_review')
114
+ ->setReviewData($mageReview)
115
+ ->setProduct($product);
116
+
117
+ $votesCollection = Mage::getModel('rating/rating_option_vote')
118
+ ->getResourceCollection()
119
+ ->setReviewFilter($mageReview->getReviewId());
120
+ $votesCollection->getSelect()->join(
121
+ array('rating'=> 'rating'),
122
+ 'rating.rating_id = main_table.rating_id',
123
+ array('rating_code' => 'rating.rating_code')
124
+ );
125
+
126
+ foreach($votesCollection as $ratingItem){
127
+ $rating = Mage::getModel('ddg_automation/customer_review_rating', $ratingItem);
128
+ $connectorReview->createRating($ratingItem->getRatingCode(), $rating);
129
+ }
130
+ $this->_reviews[$website->getId()][] = $connectorReview;
131
+ }catch(Exception $e){
132
+ Mage::logException($e);
133
+ }
134
+ }
135
+ }
136
+ }
137
+ }
138
+
139
+ private function _getReviewsToExport(Mage_Core_Model_Website $website, $limit = 100)
140
+ {
141
+ return $this->getCollection()
142
+ ->addFieldToFilter('review_imported', array('null' => 'true'))
143
+ ->addFieldToFilter('store_id', array('in' => $website->getStoreIds()))
144
+ ->setPageSize($limit);
145
+ }
146
+ }
app/code/community/Dotdigitalgroup/Email/Model/Rules.php ADDED
@@ -0,0 +1,436 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Rules extends Mage_Core_Model_Abstract
4
+ {
5
+ const ABANDONED = 1;
6
+ const REVIEW = 2;
7
+
8
+ private $_defaultOptions;
9
+ private $_conditionMap;
10
+ private $_attributeMapForQuote;
11
+ private $_attributeMapForOrder;
12
+ private $_productAttribute;
13
+ private $_used = array();
14
+
15
+ /**
16
+ * constructor
17
+ */
18
+ public function _construct()
19
+ {
20
+ $this->_defaultOptions = Mage::getModel('ddg_automation/adminhtml_source_rules_type')->defaultOptions();
21
+ $this->_conditionMap =
22
+ array(
23
+ 'eq' => 'neq',
24
+ 'neq' => 'eq',
25
+ 'gteq' => 'lteq',
26
+ 'lteq' => 'gteq',
27
+ 'gt' => 'lt',
28
+ 'lt' => 'gt',
29
+ 'like' => 'nlike',
30
+ 'nlike' => 'like'
31
+ );
32
+ $this->_attributeMapForQuote =
33
+ array(
34
+ 'method' => 'method',
35
+ 'shipping_method' => 'shipping_method',
36
+ 'country_id' => 'country_id',
37
+ 'city' => 'city',
38
+ 'region_id' => 'region_id',
39
+ 'customer_group_id' => 'main_table.customer_group_id',
40
+ 'coupon_code' => 'main_table.coupon_code',
41
+ 'subtotal' => 'main_table.subtotal',
42
+ 'grand_total' => 'main_table.grand_total',
43
+ 'items_qty' => 'main_table.items_qty',
44
+ 'customer_email' => 'main_table.customer_email',
45
+ );
46
+ $this->_attributeMapForOrder =
47
+ array(
48
+ 'method' => 'method',
49
+ 'shipping_method' => 'main_table.shipping_method',
50
+ 'country_id' => 'country_id',
51
+ 'city' => 'city',
52
+ 'region_id' => 'region_id',
53
+ 'customer_group_id' => 'main_table.customer_group_id',
54
+ 'coupon_code' => 'main_table.coupon_code',
55
+ 'subtotal' => 'main_table.subtotal',
56
+ 'grand_total' => 'main_table.grand_total',
57
+ 'items_qty' => 'items_qty',
58
+ 'customer_email' => 'main_table.customer_email',
59
+ );
60
+ parent::_construct();
61
+ $this->_init('ddg_automation/rules');
62
+ }
63
+
64
+ /**
65
+ * before save
66
+ *
67
+ * @return $this|Mage_Core_Model_Abstract
68
+ */
69
+ protected function _beforeSave()
70
+ {
71
+ parent::_beforeSave();
72
+ $now = Mage::getSingleton('core/date')->gmtDate();
73
+ if ($this->isObjectNew()) {
74
+ $this->setCreatedAt($now);
75
+ }else {
76
+ $this->setUpdatedAt($now);
77
+ }
78
+ $this->setCondition(serialize($this->getCondition()));
79
+ $this->setWebsiteIds(implode(',', $this->getWebsiteIds()));
80
+ return $this;
81
+ }
82
+
83
+ /**
84
+ * after load
85
+ *
86
+ * @return $this
87
+ */
88
+ protected function _afterLoad()
89
+ {
90
+ parent::_afterLoad();
91
+ $this->setCondition(unserialize($this->getCondition()));
92
+ return $this;
93
+ }
94
+
95
+ /**
96
+ * check if rule already exist for website
97
+ *
98
+ * @param $websiteId
99
+ * @param $type
100
+ * @param bool $ruleId
101
+ * @return bool
102
+ */
103
+ public function checkWebsiteBeforeSave($websiteId, $type, $ruleId = false)
104
+ {
105
+ $collection = $this->getCollection();
106
+ $collection
107
+ ->addFieldToFilter('type', array('eq' => $type))
108
+ ->addFieldToFilter('website_ids', array('finset' => $websiteId));
109
+ if($ruleId)
110
+ $collection->addFieldToFilter('id', array('neq' => $ruleId));
111
+ $collection->setPageSize(1);
112
+
113
+ if ($collection->getSize()) {
114
+ return false;
115
+ }
116
+ return true;
117
+ }
118
+
119
+ /**
120
+ * get website active rule
121
+ *
122
+ * @param $type
123
+ * @param $websiteId
124
+ * @return array|Varien_Object
125
+ */
126
+ public function getActiveRuleForWebsite($type, $websiteId)
127
+ {
128
+ $collection = $this->getCollection();
129
+ $collection
130
+ ->addFieldToFilter('type', array('eq' => $type))
131
+ ->addFieldToFilter('status', array('eq' => 1))
132
+ ->addFieldToFilter('website_ids', array('finset' => $websiteId))
133
+ ->setPageSize(1);
134
+ if ($collection->getSize()) {
135
+ return $collection->getFirstItem();
136
+ }
137
+ return array();
138
+ }
139
+
140
+ /**
141
+ * process rule on collection
142
+ *
143
+ * @param $collection
144
+ * @param $type
145
+ * @param $websiteId
146
+ * @return mixed
147
+ */
148
+ public function process($collection, $type, $websiteId)
149
+ {
150
+ $rule = $this->getActiveRuleForWebsite($type, $websiteId);
151
+ //if no rule then return the collection untouched
152
+ if(empty($rule))
153
+ return $collection;
154
+
155
+ //if rule has no conditions then return the collection untouched
156
+ $condition = unserialize($rule->getCondition());
157
+ if(empty($condition))
158
+ return $collection;
159
+
160
+ //join tables to collection according to type
161
+ if($type == self::ABANDONED){
162
+ $collection->getSelect()
163
+ ->joinLeft(
164
+ array('quote_address' => 'sales_flat_quote_address'),
165
+ "main_table.entity_id = quote_address.quote_id",
166
+ array('shipping_method', 'country_id', 'city', 'region_id')
167
+ )->joinLeft(
168
+ array('quote_payment' => 'sales_flat_quote_payment'),
169
+ "main_table.entity_id = quote_payment.quote_id",
170
+ array('method')
171
+ )->where('address_type = ?', 'shipping');
172
+ }elseif($type == self::REVIEW){
173
+ $collection->getSelect()
174
+ ->join(
175
+ array('order_address' => 'sales_flat_order_address'),
176
+ "main_table.entity_id = order_address.parent_id",
177
+ array('country_id', 'city', 'region_id')
178
+ )->join(
179
+ array('order_payment' => 'sales_flat_order_payment'),
180
+ "main_table.entity_id = order_payment.parent_id",
181
+ array('method')
182
+ )->join(
183
+ array('quote' => 'sales_flat_quote'),
184
+ "main_table.quote_id = quote.entity_id",
185
+ array('items_qty')
186
+ )->where('order_address.address_type = ?', 'shipping');
187
+ }
188
+
189
+ //process rule on collection according to combination
190
+ $combination = $rule->getCombination();
191
+
192
+ // ALL TRUE
193
+ if($combination == 1)
194
+ return $this->_processAndCombination($collection, $condition, $type);
195
+ //ANY TRUE
196
+ if($combination == 2)
197
+ return $this->_processOrCombination($collection, $condition, $type);
198
+
199
+ }
200
+
201
+ /**
202
+ * process And combination on collection
203
+ *
204
+ * @param $collection
205
+ * @param $conditions
206
+ * @param $type
207
+ * @return mixed
208
+ */
209
+ private function _processAndCombination($collection, $conditions, $type)
210
+ {
211
+ foreach($conditions as $condition){
212
+ $attribute = $condition['attribute'];
213
+ $cond = $condition['conditions'];
214
+ $value = $condition['cvalue'];
215
+
216
+ //ignore condition if value is null or empty
217
+ if($value == '' or $value == null)
218
+ continue;
219
+
220
+ //ignore conditions for already used attribute
221
+ if(in_array($attribute, $this->_used))
222
+ continue;
223
+ //set used to check later
224
+ $this->_used[] = $attribute;
225
+
226
+ if($type == self::REVIEW && isset($this->_attributeMapForQuote[$attribute])){
227
+ $attribute = $this->_attributeMapForOrder[$attribute];
228
+ }elseif($type == self::ABANDONED && isset($this->_attributeMapForOrder[$attribute])){
229
+ $attribute = $this->_attributeMapForQuote[$attribute];
230
+ }else{
231
+ $this->_productAttribute[] = $condition;
232
+ continue;
233
+ }
234
+
235
+ if($cond == 'null'){
236
+ if($value == '1')
237
+ $collection->addFieldToFilter($attribute, array('notnull' => true));
238
+ elseif($value == '0')
239
+ $collection->addFieldToFilter($attribute, array($cond => true));
240
+ }else{
241
+ if($cond == 'like' or $cond == 'nlike')
242
+ $value = '%' . $value . '%';
243
+ $collection->addFieldToFilter($attribute, array($this->_conditionMap[$cond] => $value));
244
+ }
245
+ }
246
+ return $this->_processProductAttributes($collection);
247
+ }
248
+
249
+ /**
250
+ * process Or combination on collection
251
+ *
252
+ * @param $collection
253
+ * @param $conditions
254
+ * @param $type
255
+ * @return mixed
256
+ */
257
+ private function _processOrCombination($collection, $conditions, $type)
258
+ {
259
+ $fieldsConditions = array();
260
+ $multiFieldsConditions = array();
261
+ foreach($conditions as $condition){
262
+ $attribute = $condition['attribute'];
263
+ $cond = $condition['conditions'];
264
+ $value = $condition['cvalue'];
265
+
266
+ //ignore condition if value is null or empty
267
+ if($value == '' or $value == null)
268
+ continue;
269
+
270
+ if($type == self::REVIEW && isset($this->_attributeMapForQuote[$attribute])){
271
+ $attribute = $this->_attributeMapForOrder[$attribute];
272
+ }elseif($type == self::ABANDONED && isset($this->_attributeMapForOrder[$attribute])){
273
+ $attribute = $this->_attributeMapForQuote[$attribute];
274
+ }else{
275
+ $this->_productAttribute[] = $condition;
276
+ continue;
277
+ }
278
+
279
+ if($cond == 'null'){
280
+ if($value == '1'){
281
+ if(isset($fieldsConditions[$attribute])){
282
+ $multiFieldsConditions[$attribute] = array('notnull' => true);
283
+ continue;
284
+ }
285
+ $fieldsConditions[$attribute] = array('notnull' => true);
286
+ }
287
+ elseif($value == '0'){
288
+ if(isset($fieldsConditions[$attribute])){
289
+ $multiFieldsConditions[$attribute] = array($cond => true);;
290
+ continue;
291
+ }
292
+ $fieldsConditions[$attribute] = array($cond => true);
293
+ }
294
+ }else{
295
+ if($cond == 'like' or $cond == 'nlike')
296
+ $value = '%' . $value . '%';
297
+ if(isset($fieldsConditions[$attribute])){
298
+ $multiFieldsConditions[$attribute] = array($this->_conditionMap[$cond] => $value);
299
+ continue;
300
+ }
301
+ $fieldsConditions[$attribute] = array($this->_conditionMap[$cond] => $value);
302
+ }
303
+ }
304
+ //all rules condition will be with or combination
305
+ if(!empty($fieldsConditions)){
306
+ $column = array();
307
+ $cond = array();
308
+ foreach($fieldsConditions as $key => $fieldsCondition){
309
+ $column[] = $key;
310
+ $cond[] = $fieldsCondition;
311
+ }
312
+ if(!empty($multiFieldsConditions)){
313
+ foreach($multiFieldsConditions as $key => $multiFieldsCondition){
314
+ if(in_array($key, $column)){
315
+ $column[] = $key;
316
+ $cond[] = $multiFieldsCondition;
317
+ continue;
318
+ }
319
+ }
320
+ }
321
+ $collection->addFieldToFilter(
322
+ $column,
323
+ $cond
324
+ );
325
+ }
326
+ return $this->_processProductAttributes($collection);
327
+ }
328
+
329
+ /**
330
+ * process product attributes on collection
331
+ *
332
+ * @param $collection
333
+ * @return mixed
334
+ */
335
+ private function _processProductAttributes($collection)
336
+ {
337
+ //if no product attribute or collection empty return collection
338
+ if(empty($this->_productAttribute) or !$collection->getSize())
339
+ return $collection;
340
+
341
+ foreach($collection as $collectionItem){
342
+ $items = $collectionItem->getAllItems();
343
+ foreach($items as $item){
344
+ //loaded product
345
+ $product = $item->getProduct();
346
+
347
+ //attributes array from loaded product
348
+ $attributes = Mage::getModel('eav/config')->getEntityAttributeCodes(
349
+ Mage_Catalog_Model_Product::ENTITY,
350
+ $product
351
+ );
352
+
353
+ foreach($this->_productAttribute as $productAttribute){
354
+ $attribute = $productAttribute['attribute'];
355
+ $cond = $productAttribute['conditions'];
356
+ $value = $productAttribute['cvalue'];
357
+
358
+ if($cond == 'null'){
359
+ if($value == '0')
360
+ $cond = 'neq';
361
+ elseif($value == '1')
362
+ $cond = 'eq';
363
+ $value = '';
364
+ }
365
+
366
+ //if attribute is in product's attributes array
367
+ if(in_array($attribute,$attributes)){
368
+ $attr = Mage::getSingleton('eav/config')->getAttribute('catalog_product', $attribute);
369
+ //frontend type
370
+ $frontType = $attr->getFrontend()->getInputType();
371
+ //if type is select
372
+ if($frontType == 'select' or $frontType == 'multiselect'){
373
+ $attributeValue = $product->getAttributeText($attribute);
374
+ //evaluate conditions on values. if true then unset item from collection
375
+ if($this->_evaluate($value, $cond, $attributeValue)){
376
+ $collection->removeItemByKey($collectionItem->getId());
377
+ continue 3;
378
+ }
379
+ }else{
380
+ $getter = 'get';
381
+ $exploded = explode('_', $attribute);
382
+ foreach ($exploded as $one) {
383
+ $getter .= ucfirst($one);
384
+ }
385
+ $attributeValue = call_user_func(array($product, $getter));
386
+ //if retrieved value is an array then loop through all array values. example can be categories
387
+ if(is_array($attributeValue)){
388
+ foreach($attributeValue as $attrValue){
389
+ //evaluate conditions on values. if true then unset item from collection
390
+ if($this->_evaluate($value, $cond, $attrValue)){
391
+ $collection->removeItemByKey($collectionItem->getId());
392
+ continue 3;
393
+ }
394
+ }
395
+ }
396
+ else{
397
+ //evaluate conditions on values. if true then unset item from collection
398
+ if($this->_evaluate($value, $cond, $attributeValue)){
399
+ $collection->removeItemByKey($collectionItem->getId());
400
+ continue 3;
401
+ }
402
+ }
403
+ }
404
+ }
405
+ }
406
+ }
407
+ }
408
+ return $collection;
409
+ }
410
+
411
+ /**
412
+ * evaluate two values against condition
413
+ *
414
+ * @param $var1
415
+ * @param $op
416
+ * @param $var2
417
+ * @return bool
418
+ */
419
+ private function _evaluate($var1, $op, $var2)
420
+ {
421
+ switch ($op) {
422
+ case "eq":
423
+ return $var1 == $var2;
424
+ case "neq":
425
+ return $var1 != $var2;
426
+ case "gteq":
427
+ return $var1 >= $var2;
428
+ case "lteq":
429
+ return $var1 <= $var2;
430
+ case "gt":
431
+ return $var1 > $var2;
432
+ case "lt":
433
+ return $var1 < $var2;
434
+ }
435
+ }
436
+ }
app/code/community/Dotdigitalgroup/Email/Model/Sales/Observer.php ADDED
@@ -0,0 +1,302 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Sales_Observer
4
+ {
5
+ /**
6
+ * save/reset the order as transactional data.
7
+ *
8
+ * @param Varien_Event_Observer $observer
9
+ * @return $this
10
+ */
11
+ public function handleSalesOrderSaveAfter(Varien_Event_Observer $observer)
12
+ {
13
+ try{
14
+ /** @var $order Mage_Sales_Model_Order */
15
+ $order = $observer->getEvent()->getOrder();
16
+ $status = $order->getStatus();
17
+ $storeId = $order->getStoreId();
18
+ $store = Mage::app()->getStore($storeId);
19
+ $storeName = $store->getName();
20
+ $websiteId = $store->getWebsiteId();
21
+ $customerEmail = $order->getCustomerEmail();
22
+ // start app emulation
23
+ $appEmulation = Mage::getSingleton('core/app_emulation');
24
+ $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);
25
+ $emailOrder = Mage::getModel('ddg_automation/order')->loadByOrderId($order->getEntityId(), $order->getQuoteId());
26
+ //reimport email order
27
+ $emailOrder->setUpdatedAt($order->getUpdatedAt())
28
+ ->setStoreId($storeId)
29
+ ->setOrderStatus($status);
30
+ if($emailOrder->getEmailImported() != Dotdigitalgroup_Email_Model_Contact::EMAIL_CONTACT_IMPORTED) {
31
+ $emailOrder->setEmailImported(null);
32
+ }
33
+
34
+ //if api is not enabled
35
+ if (!$store->getWebsite()->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED))
36
+ return $this;
37
+
38
+ // check for order status change
39
+ $statusBefore = $order->getOrigData('status');
40
+ //check if order status changed
41
+ if ( $status!= $statusBefore) {
42
+ //If order status has changed and order is already imported then set modified to 1
43
+ if($emailOrder->getEmailImported() == Dotdigitalgroup_Email_Model_Contact::EMAIL_CONTACT_IMPORTED) {
44
+ $emailOrder->setModified(Dotdigitalgroup_Email_Model_Contact::EMAIL_CONTACT_IMPORTED);
45
+ }
46
+ $smsCampaign = Mage::getModel('ddg_automation/sms_campaign', $order);
47
+ $smsCampaign->setStatus($status);
48
+ $smsCampaign->sendSms();
49
+ }
50
+ // set back the current store
51
+ $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
52
+ $emailOrder->save();
53
+
54
+ //Status check automation enrolment
55
+ $configStatusAutomationMap = unserialize(Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_AUTOMATION_STUDIO_ORDER_STATUS, $order->getStore()));
56
+ if(!empty($configStatusAutomationMap)){
57
+ foreach($configStatusAutomationMap as $configMap){
58
+ if($configMap['status'] == $status) {
59
+ try {
60
+ $programId = $configMap['automation'];
61
+ $automation = Mage::getModel( 'ddg_automation/automation' );
62
+ $automation->setEmail( $customerEmail )
63
+ ->setAutomationType( 'order_automation_' . $status )
64
+ ->setEnrolmentStatus( Dotdigitalgroup_Email_Model_Automation::AUTOMATION_STATUS_PENDING )
65
+ ->setTypeId( $order->getId() )
66
+ ->setWebsiteId( $websiteId )
67
+ ->setStoreName( $storeName )
68
+ ->setProgramId( $programId );
69
+ $automation->save();
70
+ }catch(Exception $e){
71
+ Mage::logException($e);
72
+ }
73
+ }
74
+ }
75
+ }
76
+
77
+ }catch(Exception $e){
78
+ Mage::logException($e);
79
+ }
80
+ return $this;
81
+ }
82
+
83
+
84
+ /**
85
+ * Create new order event.
86
+ * @param Varien_Event_Observer $observer
87
+ *
88
+ * @return $this
89
+ * @throws Mage_Core_Exception
90
+ */
91
+ public function handleSalesOrderPlaceAfter(Varien_Event_Observer $observer)
92
+ {
93
+ /** @var $order Mage_Sales_Model_Order */
94
+ $order = $observer->getEvent()->getOrder();
95
+ $email = $order->getCustomerEmail();
96
+ $website = Mage::app()->getWebsite($order->getWebsiteId());
97
+ $storeName = Mage::app()->getStore($order->getStoreId())->getName();
98
+
99
+ //if api is not enabled
100
+ if (!$website->getConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED))
101
+ return $this;
102
+
103
+ //automation enrolment for order
104
+ if($order->getCustomerIsGuest()){
105
+ // guest to automation mapped
106
+ $programType = 'XML_PATH_CONNECTOR_AUTOMATION_STUDIO_GUEST_ORDER';
107
+ $automationType = Dotdigitalgroup_Email_Model_Automation::AUTOMATION_TYPE_NEW_GUEST_ORDER;
108
+ }else{
109
+ // customer to automation mapped
110
+ $programType = 'XML_PATH_CONNECTOR_AUTOMATION_STUDIO_ORDER';
111
+ $automationType = Dotdigitalgroup_Email_Model_Automation::AUTOMATION_TYPE_NEW_ORDER;
112
+ }
113
+
114
+ $programId = Mage::helper( 'ddg' )->getAutomationIdByType($programType, $order->getWebsiteId());
115
+
116
+ //the program is not mappped
117
+ if (! $programId){
118
+
119
+ Mage::log('automation type : ' . $automationType. ' program id not found');
120
+ return $this;
121
+ }
122
+ try {
123
+ $automation = Mage::getModel( 'ddg_automation/automation' );
124
+ $automation->setEmail( $email )
125
+ ->setAutomationType( $automationType )
126
+ ->setEnrolmentStatus( Dotdigitalgroup_Email_Model_Automation::AUTOMATION_STATUS_PENDING )
127
+ ->setTypeId( $order->getId() )
128
+ ->setWebsiteId( $website->getId() )
129
+ ->setStoreName( $storeName )
130
+ ->setProgramId( $programId )
131
+ ->save();
132
+ }catch(Exception $e){
133
+ Mage::logException($e);
134
+ }
135
+
136
+ return $this;
137
+ }
138
+
139
+ /**
140
+ * Sales order refund event.
141
+ *
142
+ * @param Varien_Event_Observer $observer
143
+ *
144
+ * @return $this
145
+ */
146
+ public function handleSalesOrderRefund(Varien_Event_Observer $observer)
147
+ {
148
+ $creditmemo = $observer->getEvent()->getCreditmemo();
149
+ $storeId = $creditmemo->getStoreId();
150
+ $order = $creditmemo->getOrder();
151
+ $orderId = $order->getEntityId();
152
+ $quoteId = $order->getQuoteId();
153
+
154
+ try{
155
+ /**
156
+ * Reimport transactional data.
157
+ */
158
+ $emailOrder = Mage::getModel('ddg_automation/order')->loadByOrderId($orderId, $quoteId, $storeId);
159
+ if (!$emailOrder->getId()) {
160
+ Mage::helper('ddg')->log('ERROR Creditmemmo Order not found :' . $orderId . ', quote id : ' . $quoteId . ', store id ' . $storeId);
161
+ return $this;
162
+ }
163
+ $emailOrder->setEmailImported(Dotdigitalgroup_Email_Model_Contact::EMAIL_CONTACT_NOT_IMPORTED)->save();
164
+ }catch (Exception $e){
165
+ Mage::logException($e);
166
+ }
167
+
168
+ return $this;
169
+ }
170
+
171
+ /**
172
+ * Sales cancel order event, remove transactional data.
173
+ *
174
+ * @param Varien_Event_Observer $observer
175
+ *
176
+ * @return $this
177
+ */
178
+ public function hangleSalesOrderCancel(Varien_Event_Observer $observer)
179
+ {
180
+ $helper = Mage::helper('ddg');
181
+ $order = $observer->getEvent()->getOrder();
182
+ $incrementId = $order->getIncrementId();
183
+ $websiteId = Mage::app()->getStore($order->getStoreId())->getWebsiteId();
184
+
185
+ //sync enabled
186
+ $syncEnabled = $helper->getWebsiteConfig(
187
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_ORDER_ENABLED,
188
+ $websiteId
189
+ );
190
+
191
+ if ($helper->isEnabled($websiteId) && $syncEnabled) {
192
+ //register in queue with importer
193
+ Mage::getModel('ddg_automation/importer')->registerQueue(
194
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_ORDERS,
195
+ array($incrementId),
196
+ Dotdigitalgroup_Email_Model_Importer::MODE_SINGLE_DELETE,
197
+ $websiteId
198
+ );
199
+ }
200
+
201
+ return $this;
202
+ }
203
+
204
+ /**
205
+ * convert_quote_to_order observer
206
+ *
207
+ * @param Varien_Event_Observer $observer
208
+ * @return $this
209
+ */
210
+ public function handleQuoteToOrder(Varien_Event_Observer $observer)
211
+ {
212
+ /* @var $order Mage_Sales_Model_Order */
213
+ $order = $observer->getOrder();
214
+ $helper = Mage::helper('ddg');
215
+ $enabled = $helper->getWebsiteConfig(
216
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED,
217
+ $order->getStore()->getWebsiteId()
218
+ );
219
+ $syncEnabled = $helper->getWebsiteConfig(
220
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_QUOTE_ENABLED,
221
+ $order->getStore()->getWebsiteId()
222
+ );
223
+ if ($enabled && $syncEnabled) {
224
+ $quoteId = $order->getQuoteId();
225
+ $connectorQuote = Mage::getModel('ddg_automation/quote')->loadQuote($quoteId);
226
+ if ($connectorQuote) {
227
+ //register in queue with importer for single delete
228
+ Mage::getModel('ddg_automation/importer')->registerQueue(
229
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_QUOTE,
230
+ array($connectorQuote->getQuoteId()),
231
+ Dotdigitalgroup_Email_Model_Importer::MODE_SINGLE_DELETE,
232
+ $order->getStore()->getWebsiteId()
233
+ );
234
+ //delete from table
235
+ $connectorQuote->delete();
236
+ }
237
+ }
238
+ return $this;
239
+ }
240
+
241
+ /**
242
+ * sales_quote_save_after event observer
243
+ *
244
+ * @param Varien_Event_Observer $observer
245
+ * @return $this
246
+ */
247
+ public function handleQuoteSaveAfter(Varien_Event_Observer $observer)
248
+ {
249
+ /* @var $quote Mage_Sales_Model_Quote */
250
+ $quote = $observer->getEvent()->getQuote();
251
+ $helper = Mage::helper('ddg');
252
+ $enabled = $helper->getWebsiteConfig(
253
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED,
254
+ $quote->getStore()->getWebsiteId()
255
+ );
256
+ $syncEnabled = $helper->getWebsiteConfig(
257
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_QUOTE_ENABLED,
258
+ $quote->getStore()->getWebsiteId()
259
+ );
260
+ if ($enabled && $syncEnabled) {
261
+ if ($quote->getCustomerId()) {
262
+ $connectorQuote = Mage::getModel('ddg_automation/quote')->loadQuote($quote->getId());
263
+ $count = count($quote->getAllItems());
264
+ if ($connectorQuote) {
265
+ if ($connectorQuote->getImported() && $count > 0)
266
+ $connectorQuote->setModified(1)->save();
267
+ elseif ($connectorQuote->getImported() && $count == 0) {
268
+ //register in queue with importer for single delete
269
+ Mage::getModel('ddg_automation/importer')->registerQueue(
270
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_QUOTE,
271
+ array($connectorQuote->getQuoteId()),
272
+ Dotdigitalgroup_Email_Model_Importer::MODE_SINGLE_DELETE,
273
+ $quote->getStore()->getWebsiteId()
274
+ );
275
+ //delete from table
276
+ $connectorQuote->delete();
277
+ }
278
+ } elseif ($count > 0)
279
+ $this->_registerQuote($quote);
280
+ }
281
+ }
282
+ return $this;
283
+ }
284
+
285
+ /**
286
+ * register quote with connector
287
+ *
288
+ * @param Mage_Sales_Model_Quote $quote
289
+ */
290
+ private function _registerQuote(Mage_Sales_Model_Quote $quote)
291
+ {
292
+ try {
293
+ $connectorQuote = Mage::getModel('ddg_automation/quote');
294
+ $connectorQuote->setQuoteId($quote->getId())
295
+ ->setCustomerId($quote->getCustomerId())
296
+ ->setStoreId($quote->getStoreId())
297
+ ->save();
298
+ }catch (Exception $e){
299
+ Mage::logException($e);
300
+ }
301
+ }
302
+ }
app/code/community/Dotdigitalgroup/Email/Model/Sales/Order.php ADDED
@@ -0,0 +1,435 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Model_Sales_Order
4
+ {
5
+ /**
6
+ * @var array
7
+ */
8
+ protected $accounts = array();
9
+ /**
10
+ * @var string
11
+ */
12
+ private $_apiUsername;
13
+ /**
14
+ * @var string
15
+ */
16
+ private $_apiPassword;
17
+
18
+ /**
19
+ * Global number of orders
20
+ * @var int
21
+ */
22
+ private $_countOrders = 0;
23
+
24
+ private $_reviewCollection = array();
25
+ private $_orderIds;
26
+ private $_orderIdsForSingleSync;
27
+
28
+ /**
29
+ * initial sync the transactional data
30
+ * @return array
31
+ */
32
+ public function sync()
33
+ {
34
+ $response = array('success' => true, 'message' => '');
35
+ // Initialise a return hash containing results of our sync attempt
36
+ $this->_searchAccounts();
37
+
38
+ foreach ($this->accounts as $account) {
39
+
40
+ $orders = $account->getOrders();
41
+ $orderIds = $account->getOrderIds();
42
+ $ordersForSingleSync = $account->getOrdersForSingleSync();
43
+ $orderIdsForSingleSync = $account->getOrderIdsForSingleSync();
44
+ $numOrdersForSingleSync = count($ordersForSingleSync);
45
+ $website = $account->getWebsites();
46
+ $numOrders = count($orders);
47
+ $this->_countOrders += $numOrders;
48
+ $this->_countOrders += $numOrdersForSingleSync;
49
+ //send transactional for any number of orders set
50
+ if ($numOrders) {
51
+ Mage::helper('ddg')->log('--------- register Order sync with importer ---------- : ' . count($orders));
52
+ //register in queue with importer
53
+ $check = Mage::getModel('ddg_automation/importer')->registerQueue(
54
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_ORDERS,
55
+ $orders,
56
+ Dotdigitalgroup_Email_Model_Importer::MODE_BULK,
57
+ $website[0]
58
+ );
59
+ //if no error then set imported
60
+ if ($check) {
61
+ $this->_setImported($orderIds);
62
+ }
63
+ Mage::helper('ddg')->log('----------end order sync----------');
64
+ }
65
+
66
+ if ($numOrdersForSingleSync) {
67
+ $error = false;
68
+ foreach ($ordersForSingleSync as $order) {
69
+ Mage::helper('ddg')->log('--------- register Order sync in single with importer ---------- : ' . $order->id);
70
+ //register in queue with importer
71
+ $check = Mage::getModel('ddg_automation/importer')->registerQueue(
72
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_ORDERS,
73
+ $order,
74
+ Dotdigitalgroup_Email_Model_Importer::MODE_SINGLE,
75
+ $website[0]
76
+ );
77
+ if (!$check) {
78
+ $error = true;
79
+ }
80
+ Mage::helper('ddg')->log('----------end order sync in single----------');
81
+ }
82
+ //if no error then set imported
83
+ if (!$error) {
84
+ $this->_setImported($orderIdsForSingleSync, true);
85
+ }
86
+ }
87
+ unset($this->accounts[$account->getApiUsername()]);
88
+ }
89
+
90
+ if ($this->_countOrders)
91
+ $response['message'] = 'Number of updated orders : ' . $this->_countOrders;
92
+ return $response;
93
+ }
94
+
95
+ /**
96
+ * Search the configuration data per website
97
+ */
98
+ private function _searchAccounts() {
99
+
100
+ $helper = Mage::helper('ddg');
101
+
102
+ foreach (Mage::app()->getWebsites(true) as $website) {
103
+
104
+ $this->_orderIds = array();
105
+ $this->_orderIdsForSingleSync = array();
106
+ $apiEnabled = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED, $website);
107
+ $storeIds = $website->getStoreIds();
108
+ if ($apiEnabled &&
109
+ $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_SYNC_ORDER_ENABLED, $website) &&
110
+ !empty($storeIds)) {
111
+
112
+ $this->_apiUsername = $helper->getApiUsername($website);
113
+ $this->_apiPassword = $helper->getApiPassword($website);
114
+
115
+ // limit for orders included to sync
116
+ $limit = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_TRANSACTIONAL_DATA_SYNC_LIMIT, $website);
117
+ if (!isset($this->accounts[$this->_apiUsername])) {
118
+ $account = Mage::getModel('ddg_automation/connector_account')
119
+ ->setApiUsername($this->_apiUsername)
120
+ ->setApiPassword($this->_apiPassword);
121
+ $this->accounts[$this->_apiUsername] = $account;
122
+ }
123
+
124
+ $this->accounts[$this->_apiUsername]->setOrders($this->getConnectorOrders($website, $limit));
125
+ $orderIds = array_merge($this->accounts[$this->_apiUsername]->getOrderIds(), $this->_orderIds);
126
+ $this->accounts[$this->_apiUsername]->setOrderIds($orderIds);
127
+ $this->accounts[$this->_apiUsername]->setWebsites($website->getId());
128
+ $this->accounts[$this->_apiUsername]->setOrdersForSingleSync($this->getConnectorOrders($website, $limit, true));
129
+ $orderIdsForSingleSync = array_merge(
130
+ $this->accounts[$this->_apiUsername]->getOrderIdsForSingleSync(),
131
+ $this->_orderIdsForSingleSync
132
+ );
133
+ $this->accounts[$this->_apiUsername]->setOrderIdsForSingleSync($orderIdsForSingleSync);
134
+ }
135
+ }
136
+ }
137
+
138
+ /**
139
+ * get all order to import.
140
+ * @param $website
141
+ * @param int $limit
142
+ * @param $modified
143
+ *
144
+ * @return array
145
+ */
146
+ public function getConnectorOrders($website, $limit = 100, $modified = false)
147
+ {
148
+ $orders = $customers = array();
149
+ $storeIds = $website->getStoreIds();
150
+ $orderModel = Mage::getModel('ddg_automation/order');
151
+
152
+ if (empty($storeIds))
153
+ return array();
154
+
155
+ $helper = Mage::helper('ddg');
156
+ $orderStatuses = $helper->getConfigSelectedStatus($website);
157
+
158
+ if ($orderStatuses) {
159
+ if ($modified)
160
+ $orderCollection = $orderModel->getOrdersToImport($storeIds, $limit, $orderStatuses, true);
161
+ else
162
+ $orderCollection = $orderModel->getOrdersToImport($storeIds, $limit, $orderStatuses);
163
+ } else {
164
+ return array();
165
+ }
166
+
167
+ //email_order order ids
168
+ $orderIds = $orderCollection->getColumnValues('order_id');
169
+ //get the order collection
170
+ $salesOrderCollection = Mage::getResourceModel('sales/order_collection')
171
+ ->addFieldToFilter('entity_id', array('in' => $orderIds));
172
+ try {
173
+ foreach ($salesOrderCollection as $order) {
174
+
175
+ $storeId = $order->getStoreId();
176
+ $websiteId = Mage::app()->getStore( $storeId )->getWebsiteId();
177
+ /**
178
+ * Add guest to contacts table.
179
+ */
180
+ if ( $order->getCustomerIsGuest() ) {
181
+ $this->_createGuestContact( $order->getCustomerEmail(), $websiteId, $storeId );
182
+ }
183
+ if ( $order->getId() ) {
184
+ $connectorOrder = Mage::getModel( 'ddg_automation/connector_order' );
185
+ $connectorOrder->setOrderData( $order );
186
+ $orders[] = $connectorOrder;
187
+ }
188
+ if ( $modified ) {
189
+ $this->_orderIdsForSingleSync[] = $order->getId();
190
+ } else {
191
+ $this->_orderIds[] = $order->getId();
192
+ }
193
+ }
194
+ }catch(Exception $e){
195
+ Mage::logException($e);
196
+ }
197
+ return $orders;
198
+ }
199
+
200
+ /**
201
+ * Create a guest contact.
202
+ * @param $email
203
+ * @param $websiteId
204
+ * @param $storeId
205
+ *
206
+ * @return bool
207
+ */
208
+ private function _createGuestContact($email, $websiteId, $storeId) {
209
+
210
+ try{
211
+ $client = Mage::helper('ddg')->getWebsiteApiClient($websiteId);
212
+ //no api credentials or the guest has no been mapped
213
+ if (! $client || ! $addressBookId = Mage::helper('ddg')->getGuestAddressBook($websiteId))
214
+ return false;
215
+
216
+ $contactModel = Mage::getModel('ddg_automation/contact')->loadByCustomerEmail($email, $websiteId);
217
+
218
+ //check if contact is not suppressed
219
+ if (! $contactModel->getSuppressed()) {
220
+ //check if contact exists, create if not
221
+ $contactApi = $client->postContacts( $email );
222
+
223
+ //contact is suppressed cannot add to address book, mark as suppressed.
224
+ if ( isset( $contactApi->message ) && $contactApi->message == 'Contact is suppressed. ERROR_CONTACT_SUPPRESSED' ) {
225
+ //mark new contacts as guest.
226
+ if ( $contactModel->isObjectNew() ) {
227
+ $contactModel->setIsGuest( 1 );
228
+ }
229
+ $contactModel->setSuppressed( 1 );
230
+ $contactModel->save();
231
+
232
+ return false;
233
+ }
234
+ //add guest to address book
235
+ $response = $client->postAddressBookContacts( $addressBookId, $contactApi );
236
+ //set contact as was found as guest and
237
+ $contactModel->setIsGuest(1)
238
+ ->setStoreId($storeId)
239
+ ->setEmailImported(1);
240
+ //contact id
241
+ if (isset($contactApi->id))
242
+ $contactModel->setContactId();
243
+ //mark the contact as surpressed
244
+ if (isset($response->message) && $response->message == 'Contact is suppressed. ERROR_CONTACT_SUPPRESSED')
245
+ $contactModel->setSuppressed(1);
246
+ //save
247
+ $contactModel->save();
248
+ }
249
+
250
+ Mage::helper('ddg')->log('-- guest found : ' . $email . ' website : ' . $websiteId . ' ,store : ' . $storeId);
251
+ }catch(Exception $e){
252
+ Mage::logException($e);
253
+ }
254
+
255
+ return true;
256
+ }
257
+
258
+
259
+ /**
260
+ * create review campaigns
261
+ *
262
+ * @return bool
263
+ */
264
+ public function createReviewCampaigns()
265
+ {
266
+ $this->searchOrdersForReview();
267
+
268
+ foreach($this->_reviewCollection as $websiteId => $collection){
269
+ $this->registerCampaign($collection, $websiteId);
270
+ }
271
+ }
272
+
273
+ /**
274
+ * register review campaign
275
+ *
276
+ * @param $collection
277
+ * @param $websiteId
278
+ *
279
+ * @throws Exception
280
+ */
281
+ private function registerCampaign($collection, $websiteId) {
282
+
283
+ $helper = Mage::helper('ddg/review');
284
+ $campaignId = $helper->getCampaign($websiteId);
285
+
286
+ if ($campaignId) {
287
+ foreach ($collection as $order) {
288
+ Mage::helper('ddg')->log('-- Order Review: ' . $order->getIncrementId() . ' Campaign Id: ' . $campaignId);
289
+
290
+ try {
291
+ $emailCampaign = Mage::getModel('ddg_automation/campaign');
292
+ $emailCampaign
293
+ ->setEmail($order->getCustomerEmail())
294
+ ->setStoreId($order->getStoreId())
295
+ ->setCampaignId($campaignId)
296
+ ->setEventName('Order Review')
297
+ ->setCreatedAt(Mage::getSingleton('core/date')->gmtDate())
298
+ ->setOrderIncrementId($order->getIncrementId())
299
+ ->setQuoteId($order->getQuoteId());
300
+
301
+ if($order->getCustomerId())
302
+ $emailCampaign->setCustomerId($order->getCustomerId());
303
+
304
+ $emailCampaign->save();
305
+ } catch (Exception $e) {
306
+ Mage::logException($e);
307
+ }
308
+ }
309
+ }
310
+ }
311
+
312
+ /**
313
+ * search for orders to review per website
314
+ */
315
+ private function searchOrdersForReview() {
316
+
317
+ $helper = Mage::helper('ddg/review');
318
+
319
+ foreach (Mage::app()->getWebsites(true) as $website){
320
+
321
+ $apiEnabled = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_API_ENABLED, $website);
322
+
323
+ if($apiEnabled && $helper->isEnabled($website) &&
324
+ $helper->getOrderStatus($website) &&
325
+ $helper->getDelay($website)){
326
+
327
+ $storeIds = $website->getStoreIds();
328
+ if(empty($storeIds))
329
+ continue;
330
+
331
+ $orderStatusFromConfig = $helper->getOrderStatus($website);
332
+ $delayInDays = $helper->getDelay($website);
333
+
334
+ $campaignCollection = Mage::getModel('ddg_automation/campaign')->getCollection();
335
+ $campaignCollection
336
+ ->addFieldToFilter('event_name', 'Order Review')
337
+ ->load();
338
+
339
+ $campaignOrderIds = $campaignCollection->getColumnValues('order_increment_id');
340
+
341
+ $to = Mage::app()->getLocale()->date()
342
+ ->subDay($delayInDays);
343
+ $from = clone $to;
344
+ $to = $to->toString('YYYY-MM-dd HH:mm:ss');
345
+ $from = $from->subHour(2)
346
+ ->toString('YYYY-MM-dd HH:mm:ss');
347
+
348
+ $created = array( 'from' => $from, 'to' => $to, 'date' => true);
349
+
350
+ $collection = Mage::getModel('sales/order')->getCollection();
351
+ $collection->addFieldToFilter('main_table.status', $orderStatusFromConfig)
352
+ ->addFieldToFilter('main_table.created_at', $created)
353
+ ->addFieldToFilter('main_table.store_id', array('in' => $storeIds));
354
+
355
+ if (! empty($campaignOrderIds))
356
+ $collection->addFieldToFilter('main_table.increment_id', array('nin' => $campaignOrderIds));
357
+
358
+ //process rules on collection
359
+ $ruleModel = Mage::getModel('ddg_automation/rules');
360
+ $collection = $ruleModel->process(
361
+ $collection, Dotdigitalgroup_Email_Model_Rules::REVIEW, $website->getId()
362
+ );
363
+
364
+ if ($collection->getSize())
365
+ $this->_reviewCollection[$website->getId()] = $collection;
366
+ }
367
+ }
368
+ }
369
+
370
+ /**
371
+ * get customer last order id
372
+ *
373
+ * @param Mage_Customer_Model_Customer $customer
374
+ * @return bool|Varien_Object
375
+ */
376
+ public function getCustomerLastOrderId(Mage_Customer_Model_Customer $customer)
377
+ {
378
+ $storeIds = Mage::app()->getWebsite($customer->getWebsiteId())->getStoreIds();
379
+ $collection = Mage::getModel('sales/order')->getCollection();
380
+ $collection->addFieldToFilter('customer_id', $customer->getId())
381
+ ->addFieldToFilter('store_id', array('in' => $storeIds))
382
+ ->setPageSize(1)
383
+ ->setOrder('entity_id');
384
+
385
+ if ($collection->count())
386
+ return $collection->getFirstItem();
387
+ else
388
+ return false;
389
+ }
390
+
391
+ /**
392
+ * get customer last quote id
393
+ *
394
+ * @param Mage_Customer_Model_Customer $customer
395
+ * @return bool|Varien_Object
396
+ */
397
+ public function getCustomerLastQuoteId(Mage_Customer_Model_Customer $customer)
398
+ {
399
+ $storeIds = Mage::app()->getWebsite($customer->getWebsiteId())->getStoreIds();
400
+ $collection = Mage::getModel('sales/quote')->getCollection();
401
+ $collection->addFieldToFilter('customer_id', $customer->getId())
402
+ ->addFieldToFilter('store_id', array('in' => $storeIds))
403
+ ->setPageSize(1)
404
+ ->setOrder('entity_id');
405
+
406
+ if ($collection->count())
407
+ return $collection->getFirstItem();
408
+ else
409
+ return false;
410
+ }
411
+
412
+ /**
413
+ * set imported in bulk query
414
+ *
415
+ * @param $ids
416
+ * @param $modified
417
+ */
418
+ private function _setImported($ids, $modified = false) {
419
+
420
+ try{
421
+ $coreResource = Mage::getSingleton('core/resource');
422
+ $write = $coreResource->getConnection('core_write');
423
+ $tableName = $coreResource->getTableName('ddg_automation/order');
424
+ $ids = implode(', ', $ids);
425
+ $now = Mage::getSingleton('core/date')->gmtDate();
426
+
427
+ if ($modified)
428
+ $write->update($tableName, array('modified' => new Zend_Db_Expr('null'), 'updated_at' => $now), "order_id IN ($ids)");
429
+ else
430
+ $write->update($tableName, array('email_imported' => 1, 'updated_at' => $now), "order_id IN ($ids)");
431
+ }catch (Exception $e){
432
+ Mage::logException($e);
433
+ }
434
+ }
435
+ }
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,221 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $storeIds = $website->getStoreIds();
61
+ if ($enabled && $apiEnabled && !empty($storeIds)) {
62
+ //using bulk api
63
+ $helper->log('---------- Start wishlist bulk sync ----------');
64
+ $this->_start = microtime(true);
65
+ $this->_exportWishlistForWebsite($website);
66
+ //send wishlist as transactional data
67
+ if (isset($this->_wishlists[$website->getId()])) {
68
+ $websiteWishlists = $this->_wishlists[$website->getId()];
69
+
70
+ //register in queue with importer
71
+ $check = Mage::getModel('ddg_automation/importer')->registerQueue(
72
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_WISHLIST,
73
+ $websiteWishlists,
74
+ Dotdigitalgroup_Email_Model_Importer::MODE_BULK,
75
+ $website->getId()
76
+ );
77
+
78
+ //set imported
79
+ if ($check) {
80
+ $this->getResource()->setImported($this->_wishlistIds);
81
+ }
82
+ }
83
+ $message = 'Total time for wishlist bulk sync : ' . gmdate("H:i:s", microtime(true) - $this->_start);
84
+ $helper->log($message);
85
+
86
+ //using single api
87
+ $this->_exportWishlistForWebsiteInSingle($website);
88
+ }
89
+ }
90
+ $response['message'] = "wishlist updated: ". $this->_count;
91
+ return $response;
92
+ }
93
+
94
+ private function _exportWishlistForWebsite(Mage_Core_Model_Website $website)
95
+ {
96
+ //reset wishlists
97
+ $this->_wishlists = array();
98
+ $this->_wishlistIds = array();
99
+ $limit = Mage::helper('ddg')->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_TRANSACTIONAL_DATA_SYNC_LIMIT, $website);
100
+ $emailWishlist = $this->_getWishlistToImport($website, $limit);
101
+ $this->_wishlistIds = $emailWishlist->getColumnValues('wishlist_id');
102
+
103
+ if(!empty($this->_wishlistIds)){
104
+ $collection = Mage::getModel('wishlist/wishlist')
105
+ ->getCollection()
106
+ ->addFieldToFilter('main_table.wishlist_id', array('in' => $this->_wishlistIds))
107
+ ->addFieldToFilter('customer_id', array('notnull' => 'true'));
108
+
109
+ $collection->getSelect()
110
+ ->joinLeft(
111
+ array('c' => 'customer_entity'),
112
+ 'c.entity_id = customer_id',
113
+ array('email','store_id')
114
+ );
115
+
116
+ foreach($collection as $wishlist){
117
+ $connectorWishlist = Mage::getModel('ddg_automation/customer_wishlist');
118
+ $connectorWishlist
119
+ ->setId($wishlist->getId())
120
+ ->setUpdatedAt($wishlist->getUpdatedAt())
121
+ ->setCustomerId($wishlist->getCustomerId())
122
+ ->setEmail($wishlist->getEmail());
123
+ $wishListItemCollection = $wishlist->getItemCollection();
124
+ if ($wishListItemCollection->getSize()) {
125
+ foreach ($wishListItemCollection as $item) {
126
+ /* @var $product Mage_Catalog_Model_Product */
127
+ $product = $item->getProduct();
128
+ $wishlistItem = Mage::getModel('ddg_automation/customer_wishlist_item', $product)
129
+ ->setQty($item->getQty())
130
+ ->setPrice($product);
131
+ //store for wishlists
132
+ $connectorWishlist->setItem($wishlistItem);
133
+ $this->_count++;
134
+ }
135
+ //set wishlists for later use
136
+ $this->_wishlists[$website->getId()][] = $connectorWishlist;
137
+ }
138
+ }
139
+ }
140
+ }
141
+
142
+ private function _getWishlistToImport(Mage_Core_Model_Website $website, $limit = 100)
143
+ {
144
+ $collection = $this->getCollection()
145
+ ->addFieldToFilter('wishlist_imported', array('null' => true))
146
+ ->addFieldToFilter('store_id', array('in' => $website->getStoreIds()))
147
+ ->addFieldToFilter('item_count', array('gt' => 0));
148
+
149
+ $collection->getSelect()->limit($limit);
150
+ return $collection;
151
+ }
152
+
153
+ private function _exportWishlistForWebsiteInSingle(Mage_Core_Model_Website $website)
154
+ {
155
+ $helper = Mage::helper('ddg');
156
+ $client = $helper->getWebsiteApiClient($website);
157
+ $limit = $helper->getWebsiteConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_TRANSACTIONAL_DATA_SYNC_LIMIT, $website);
158
+ $collection = $this->_getModifiedWishlistToImport($website, $limit);
159
+ $this->_wishlistIds = array();
160
+ foreach($collection as $emailWishlist){
161
+ $customer = Mage::getModel('customer/customer')->load($emailWishlist->getCustomerId());
162
+ $wishlist = Mage::getModel('wishlist/wishlist')->load($emailWishlist->getWishlistId());
163
+ /** @var $connectorWishlist */
164
+ $connectorWishlist = Mage::getModel('ddg_automation/customer_wishlist', $customer);
165
+ $connectorWishlist->setId($wishlist->getId());
166
+ $wishListItemCollection = $wishlist->getItemCollection();
167
+ if ($wishListItemCollection->getSize()) {
168
+ foreach ($wishListItemCollection as $item) {
169
+ /* @var $product Mage_Catalog_Model_Product */
170
+ $product = $item->getProduct();
171
+ $wishlistItem = Mage::getModel('ddg_automation/customer_wishlist_item', $product)
172
+ ->setQty($item->getQty())
173
+ ->setPrice($product);
174
+ //store for wishlists
175
+ $connectorWishlist->setItem($wishlistItem);
176
+ $this->_count++;
177
+ }
178
+ //send wishlist as transactional data
179
+ $helper->log('---------- Start wishlist single sync ----------');
180
+ $this->_start = microtime(true);
181
+ //register in queue with importer
182
+ $check = Mage::getModel('ddg_automation/importer')->registerQueue(
183
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_WISHLIST,
184
+ $connectorWishlist,
185
+ Dotdigitalgroup_Email_Model_Importer::MODE_SINGLE,
186
+ $website->getId()
187
+ );
188
+ if ($check) {
189
+ $this->_wishlistIds[] = $emailWishlist->getWishlistId();
190
+ }
191
+ $message = 'Total time for wishlist single sync : ' . gmdate("H:i:s", microtime(true) - $this->_start);
192
+ $helper->log($message);
193
+ }else{
194
+ //register in queue with importer
195
+ $check = Mage::getModel('ddg_automation/importer')->registerQueue(
196
+ Dotdigitalgroup_Email_Model_Importer::IMPORT_TYPE_WISHLIST,
197
+ array($wishlist->getId()),
198
+ Dotdigitalgroup_Email_Model_Importer::MODE_SINGLE_DELETE,
199
+ $website->getId()
200
+ );
201
+ if ($check) {
202
+ $this->_wishlistIds[] = $emailWishlist->getWishlistId();
203
+ }
204
+ $message = 'Total time for wishlist single sync : ' . gmdate("H:i:s", microtime(true) - $this->_start);
205
+ $helper->log($message);
206
+ }
207
+ }
208
+ if(!empty($this->_wishlistIds))
209
+ $this->getResource()->setImported($this->_wishlistIds, true);
210
+ }
211
+
212
+ private function _getModifiedWishlistToImport(Mage_Core_Model_Website $website, $limit = 100)
213
+ {
214
+ $collection = $this->getCollection()
215
+ ->addFieldToFilter('wishlist_modified', 1)
216
+ ->addFieldToFilter('store_id', array('in' => $website->getStoreIds()));
217
+
218
+ $collection->getSelect()->limit($limit);
219
+ return $collection;
220
+ }
221
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/ConnectorController.php ADDED
@@ -0,0 +1,391 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 = Mage::getModel('core/config');
40
+ $config->saveConfig('connector_data_mapping/customer_data/' . $key, strtoupper($datafield['name']), $scope, $scopeId);
41
+ Mage::helper('ddg')->log('successfully connected : ' . $datafield['name']);
42
+ }
43
+ }
44
+ if ($result['errors']) {
45
+ Mage::getSingleton('adminhtml/session')->addNotice($result['message']);
46
+ } else {
47
+ Mage::getConfig()->cleanCache();
48
+ Mage::getSingleton('adminhtml/session')->addSuccess('All Datafields Created And Mapped.');
49
+ }
50
+ }
51
+
52
+ $this->_redirectUrl($redirectUrl);
53
+ }
54
+
55
+ /**
56
+ * Reset order for reimport.
57
+ */
58
+ public function resetordersAction()
59
+ {
60
+ $num = Mage::getResourceModel('ddg_automation/order')->resetOrders();
61
+ $message = '-- Reset Orders for Reimport : ' . $num;
62
+ Mage::helper('ddg')->log($message);
63
+ if (!$num)
64
+ $message = 'Done.';
65
+ Mage::getSingleton('adminhtml/session')->addSuccess($message);
66
+
67
+ $this->_redirectReferer();
68
+ }
69
+
70
+ /**
71
+ * Reset customers import.
72
+ */
73
+ public function resetcustomersimportAction()
74
+ {
75
+ $num = Mage::getResourceModel('ddg_automation/contact')->resetAllContacts();
76
+ $message = '-- Reset Contacts for re-import : ' . $num;
77
+ Mage::helper('ddg')->log($message);
78
+ if (!$num)
79
+ $message = 'Done.';
80
+ Mage::getSingleton('adminhtml/session')->addSuccess($message);
81
+ $this->_redirectReferer();
82
+ }
83
+
84
+ /**
85
+ * Remove contact id's.
86
+ */
87
+ public function deletecontactidsAction()
88
+ {
89
+ $num = Mage::getResourceModel('ddg_automation/contact')->deleteContactIds();
90
+ $message = 'Number of Contacts Id\'s Removed: '. $num;
91
+ if (!$num)
92
+ $message = 'Done.';
93
+ Mage::getSingleton('adminhtml/session')->addSuccess($message);
94
+ $this->_redirectReferer();
95
+ }
96
+
97
+ /**
98
+ * Ajax API validation.
99
+ */
100
+ public function ajaxvalidationAction()
101
+ {
102
+ $params = $this->getRequest()->getParams();
103
+ $apiUsername = $params['api_username'];
104
+ // use javascript btoa function to encode the password
105
+
106
+ $apiPassword = base64_decode($params['api_password']);
107
+ $message = Mage::getModel('ddg_automation/apiconnector_test')->ajaxvalidate($apiUsername, $apiPassword);
108
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($message));
109
+ }
110
+
111
+ /**
112
+ * Ajax request to reset the import for contacts.
113
+ */
114
+ public function resetcontactsajaxAction()
115
+ {
116
+ $numReseted = Mage::getResourceModel('ddg_automation/contact')->resetAllContacts();
117
+ $message = array('reseted' => $numReseted);
118
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($message));
119
+ }
120
+
121
+ /**
122
+ * Ajax requets to reset susbcribers for reimport.
123
+ */
124
+ public function ajaxresetsubscribersAction()
125
+ {
126
+ $num = Mage::getResourceModel('ddg_automation/contact')->resetSubscribers();
127
+ $message = array('reseted' => $num);
128
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($message));
129
+ }
130
+
131
+ /**
132
+ * Ajax request to reset orders for reimoport.
133
+ */
134
+ public function ajaxresetguestsAction()
135
+ {
136
+ $num = Mage::getResourceModel('ddg_automation/contact')->resetAllGuestContacts();
137
+ $message = array('reseted' => $num);
138
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($message));
139
+ }
140
+
141
+ public function createnewdatafieldAction()
142
+ {
143
+ //get params required for datafield
144
+ $request = $this->getRequest();
145
+ $name = $request->getParam('name', false);
146
+ $type = $request->getParam('type', false);
147
+ $default = $request->getParam('default', 0);
148
+ $access = $request->getParam('access', false);
149
+ $website = $request->getParam('website', 0);
150
+
151
+ //api client for this website
152
+ $client = Mage::helper('ddg')->getWebsiteApiClient($website);
153
+ //only if all data is available
154
+ if ($name && $type && $access) {
155
+ //create datafield
156
+ $response = $client->postDataFields($name, $type, $access, $default);
157
+ //error creating datafield message
158
+ if (isset($response->message)) {
159
+ //send error message to backend
160
+ Mage::getSingleton('adminhtml/session')->addError($response->message);
161
+ Mage::helper('ddg')->log($response->message);
162
+ } else {
163
+ //success message
164
+ Mage::getSingleton('adminhtml/session')->addSuccess('Datafield created : ' . $name);
165
+ }
166
+ } else {
167
+ $message = 'Name ' . $name . ', type ' . $type . ' default ' . $default . 'access ' . $access;
168
+ Mage::getSingleton('adminhtml/session')->addError('Datafield cannot be empty.');
169
+ Mage::helper('ddg')->rayLog($message);
170
+ }
171
+ }
172
+
173
+ /**
174
+ * Create new address book action.
175
+ */
176
+ public function createnewaddressbookAction()
177
+ {
178
+ $addressBookName = $this->getRequest()->getParam('name');
179
+ $visibility = $this->getRequest()->getParam('visibility');
180
+ $website = $this->getRequest()->getParam('website', 0);
181
+ $client = Mage::helper('ddg')->getWebsiteApiClient($website);
182
+ if (strlen($addressBookName)) {
183
+ $response = $client->postAddressBooks($addressBookName, $visibility);
184
+ if (isset($response->message))
185
+ Mage::getSingleton('adminhtml/session')->addError($response->message);
186
+ else
187
+ Mage::getSingleton('adminhtml/session')->addSuccess('Address book : '. $addressBookName . ' created.');
188
+ }
189
+
190
+ }
191
+
192
+ public function reimoprtsubscribersAction()
193
+ {
194
+ $updated = Mage::getResourceModel('ddg_automation/contact')->resetSubscribers();
195
+ if ($updated) {
196
+ Mage::getSingleton('adminhtml/session')->addSuccess('Done.');
197
+ } else {
198
+ Mage::getSingleton('adminhtml/session')->addNotice('No subscribers imported!');
199
+ }
200
+ $this->_redirectReferer();
201
+ }
202
+
203
+ /**
204
+ * path constant for config helper sent as string.
205
+ */
206
+ public function enablewebsiteconfigurationAction()
207
+ {
208
+ $path = $this->getRequest()->getParam('path');
209
+ $value = $this->getRequest()->getParam('value');
210
+ $website = $this->getRequest()->getParam('website', 0);
211
+
212
+ $path = constant('Dotdigitalgroup_Email_Helper_Config::' . $path);
213
+ $scope = 'websites';
214
+ $scopeId = $website;
215
+
216
+ $config = Mage::getConfig();
217
+
218
+ //use value 1 if not set
219
+ if (isset($value))
220
+ $config->saveConfig($path, $value, $scope, $scopeId);
221
+ else
222
+ $config->saveConfig($path, 1, $scope, $scopeId);
223
+
224
+ //clean cache
225
+ $config->cleanCache();
226
+
227
+ $this->_redirectReferer();
228
+ }
229
+
230
+ /**
231
+ * Populate the tables (customer-email_contact, subscribers-email_contact) with missing ones.
232
+ */
233
+ public function populatecontactsAction()
234
+ {
235
+ Mage::getResourceModel('ddg_automation/contact')->populateAndCleanup();
236
+
237
+ Mage::getSingleton( 'adminhtml/session' )->addSuccess( "Contacts populated");
238
+
239
+ $this->_redirectReferer();
240
+ }
241
+
242
+ /**
243
+ * Trigger to run the contact sync.
244
+ */
245
+ public function runcontactsyncAction()
246
+ {
247
+ $result = Mage::getModel('ddg_automation/cron')->contactSync();
248
+
249
+ if ($result['message'])
250
+ Mage::getSingleton('adminhtml/session')->addSuccess($result['message']);
251
+
252
+ $this->_redirectReferer();
253
+ }
254
+
255
+ /**
256
+ * Trigger to run the subscriber sync.
257
+ */
258
+ public function runsubscribersyncAction()
259
+ {
260
+ $result = Mage::getModel('ddg_automation/cron')->subscribersAndGuestSync();
261
+
262
+ if ($result['message'])
263
+ Mage::getSingleton('adminhtml/session')->addSuccess($result['message']);
264
+
265
+ $this->_redirectReferer();
266
+ }
267
+
268
+ /**
269
+ * Trigger to run the order sync.
270
+ */
271
+ public function runordersyncAction()
272
+ {
273
+
274
+ $result = Mage::getModel('ddg_automation/cron')->orderSync();
275
+ if ($result['message'])
276
+ Mage::getSingleton('adminhtml/session')->addSuccess($result['message']);
277
+
278
+ $this->_redirectReferer();
279
+ }
280
+
281
+ /**
282
+ * Trigger to run the review sync.
283
+ */
284
+ public function runreviewsyncAction()
285
+ {
286
+
287
+ $result = Mage::getModel('ddg_automation/cron')->reviewSync();
288
+ if ($result['message'])
289
+ Mage::getSingleton('adminhtml/session')->addSuccess($result['message']);
290
+
291
+ $this->_redirectReferer();
292
+ }
293
+
294
+ /**
295
+ * Trigger to run the reviw sync.
296
+ */
297
+ public function runwishlistsyncAction()
298
+ {
299
+
300
+ $result = Mage::getModel('ddg_automation/wishlist')->sync();
301
+ if ($result['message'])
302
+ Mage::getSingleton('adminhtml/session')->addSuccess($result['message']);
303
+
304
+ $this->_redirectReferer();
305
+ }
306
+
307
+ /**
308
+ * Trigger to run the quote sync.
309
+ */
310
+ public function runquotesyncAction()
311
+ {
312
+
313
+ $result = Mage::getModel('ddg_automation/cron')->quoteSync();
314
+ if ($result['message'])
315
+ Mage::getSingleton('adminhtml/session')->addSuccess($result['message']);
316
+
317
+ $this->_redirectReferer();
318
+ }
319
+
320
+ /**
321
+ * Reset quote for reimport.
322
+ */
323
+ public function resetquotesAction()
324
+ {
325
+ $num = Mage::getResourceModel('ddg_automation/quote')->resetQuotes();
326
+ Mage::helper('ddg')->log('-- Reset Quotes for reimport : ' . $num);
327
+ Mage::getSingleton('adminhtml/session')->addSuccess('Done.');
328
+ $this->_redirectReferer();
329
+ }
330
+
331
+ /**
332
+ * Reset reviews for reimport.
333
+ */
334
+ public function resetreviewsAction()
335
+ {
336
+ $num = Mage::getResourceModel('ddg_automation/review')->reset();
337
+ Mage::helper('ddg')->log('-- Reset Reviews for reimport : ' . $num);
338
+ Mage::getSingleton('adminhtml/session')->addSuccess('Done.');
339
+ $this->_redirectReferer();
340
+ }
341
+
342
+ /**
343
+ * Reset wishlist for reimport.
344
+ */
345
+ public function resetwishlistsAction()
346
+ {
347
+ $num = Mage::getResourceModel('ddg_automation/wishlist')->reset();
348
+ Mage::helper('ddg')->log('-- Reset Wishlist for reimport : ' . $num);
349
+ Mage::getSingleton('adminhtml/session')->addSuccess('Done.');
350
+ $this->_redirectReferer();
351
+ }
352
+
353
+ /**
354
+ * Re-set all tables
355
+ */
356
+ public function resetAction()
357
+ {
358
+ Mage::getResourceModel('ddg_automation/contact')->resetAllTables();
359
+ Mage::getSingleton('adminhtml/session')->addSuccess('All tables successfully reset.');
360
+ $this->_redirectReferer();
361
+ }
362
+
363
+ /**
364
+ * Reset catalog for reimport.
365
+ */
366
+ public function resetcatalogAction()
367
+ {
368
+ $num = Mage::getResourceModel('ddg_automation/catalog')->reset();
369
+ Mage::helper('ddg')->log('-- Reset Catalog for reimport : ' . $num);
370
+ Mage::getSingleton('adminhtml/session')->addSuccess('Done.');
371
+ $this->_redirectReferer();
372
+ }
373
+
374
+ /**
375
+ * Trigger to run the catalog sync.
376
+ */
377
+ public function runcatalogsyncAction()
378
+ {
379
+
380
+ $result = Mage::getModel('ddg_automation/cron')->catalogSync();
381
+ if ($result['message'])
382
+ Mage::getSingleton('adminhtml/session')->addSuccess($result['message']);
383
+
384
+ $this->_redirectReferer();
385
+ }
386
+
387
+ protected function _isAllowed()
388
+ {
389
+ return Mage::getSingleton('admin/session')->isAllowed('system/config/connector_developer_settings');
390
+ }
391
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/CustomerController.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Adminhtml_CustomerController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+ public function statAction()
6
+ {
7
+ // $this->getLayout();
8
+ // $this->renderLayout();
9
+ // $block = $this->getLayout()->createBlock('ddg_automation/adminhtml_customer_tab_stats');
10
+ // echo $block->toHtml();
11
+ }
12
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/AutomationController.php ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Adminhtml_Email_AutomationController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+
6
+ protected function _construct(){
7
+ $this->setUsedModuleName('Dotdigitalgroup_Email');
8
+ }
9
+
10
+ /**
11
+ * main page.
12
+ */
13
+ public function indexAction()
14
+ {
15
+ $this->_title($this->__('Automation'))
16
+ ->_title($this->__('Automation Status'));
17
+ $this->loadLayout();
18
+ $this->_setActiveMenu('email_connector');
19
+ $this->renderLayout();
20
+ }
21
+
22
+ public function editAction()
23
+ {
24
+ $this->_redirect('*/*');
25
+ }
26
+
27
+ /**
28
+ * main grid.
29
+ */
30
+ public function gridAction(){
31
+ $this->loadLayout();
32
+ $this->renderLayout();
33
+ }
34
+
35
+ /**
36
+ * Delete action.
37
+ */
38
+ public function massDeleteAction()
39
+ {
40
+ $automationIds = $this->getRequest()->getParam('automation');
41
+ if (!is_array($automationIds)) {
42
+ $this->_getSession()->addError($this->__('Please select .'));
43
+ } else {
44
+ $num = Mage::getResourceModel('ddg_automation/automation')->massDelete($automationIds);
45
+
46
+ if (is_int($num)){
47
+ $this->_getSession()->addSuccess(
48
+ Mage::helper('ddg')->__('Total of %d record(s) have been deleted.', $num)
49
+ );
50
+ } else {
51
+ $this->_getSession()->addError( $num->getMessage() );
52
+ }
53
+ }
54
+ $this->_redirect('*/*/index');
55
+ }
56
+
57
+ /**
58
+ * Mark for resend.
59
+ */
60
+ public function massResendAction()
61
+ {
62
+ $automationIds = $this->getRequest()->getParam('automation');
63
+
64
+ if (!is_array($automationIds)) {
65
+ $this->_getSession()->addError($this->__('Please select .'));
66
+ } else {
67
+ $num = Mage::getResourceModel('ddg_automation/automation')->massResend($automationIds);
68
+
69
+ if (is_int($num)) {
70
+ $this->_getSession()->addSuccess(
71
+ Mage::helper('ddg')->__('Total of %d record(s) have been deleted.', $num)
72
+ );
73
+ } else {
74
+ $this->_getSession()->addError( $num->getMessage() );
75
+ }
76
+ }
77
+ $this->_redirect('*/*/index');
78
+ }
79
+
80
+ protected function _isAllowed()
81
+ {
82
+ return Mage::getSingleton('admin/session')->isAllowed('email_connector/reports/email_connector_automation');
83
+ }
84
+
85
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/CampaignController.php ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * Delete campaign.
27
+ */
28
+ public function deleteAction()
29
+ {
30
+ if ($id = $this->getRequest()->getParam('id')) {
31
+ $campaign = Mage::getModel('ddg_automation/campaign')->load($id);
32
+ try {
33
+ $campaign->delete();
34
+ $this->_getSession()->addSuccess(Mage::helper('ddg')->__('The campaign has been deleted.'));
35
+ }
36
+ catch (Exception $e) {
37
+ $this->_getSession()->addError($e->getMessage());
38
+ }
39
+ }
40
+ $this->getResponse()->setRedirect($this->getUrl('*/*/', array('store'=>$this->getRequest()->getParam('store'))));
41
+ }
42
+
43
+ /**
44
+ * Delete mass campaigns.
45
+ */
46
+ public function massDeleteAction()
47
+ {
48
+ $campaignIds = $this->getRequest()->getParam('campaign');
49
+ if (!is_array($campaignIds)) {
50
+ $this->_getSession()->addError($this->__('Please select campaigns.'));
51
+ } else {
52
+ $num = Mage::getResourceModel('ddg_automation/campaign')->massDelete($campaignIds);
53
+ if(is_int($num)){
54
+ $this->_getSession()->addSuccess(
55
+ Mage::helper('ddg')->__('Total of %d record(s) have been deleted.', $num));
56
+ }
57
+ else
58
+ $this->_getSession()->addError($num->getMessage());
59
+ }
60
+ $this->_redirect('*/*/index');
61
+ }
62
+
63
+ /**
64
+ * Mass mark for resend campaings.
65
+ */
66
+ public function massResendAction()
67
+ {
68
+ $campaignIds = $this->getRequest()->getParam('campaign');
69
+ if (!is_array($campaignIds)) {
70
+ $this->_getSession()->addError($this->__('Please select campaigns.'));
71
+ } else {
72
+ $num = Mage::getResourceModel('ddg_automation/campaign')->massResend($campaignIds);
73
+
74
+ if(is_int($num)){
75
+ $this->_getSession()->addSuccess(
76
+ Mage::helper('ddg')->__('Total of %d record(s) have resend .', $num)
77
+ );
78
+ }else
79
+ $this->_getSession()->addError($num->getMessage());
80
+ }
81
+ $this->_redirect('*/*/index');
82
+ }
83
+
84
+ /**
85
+ * main page.
86
+ */
87
+ public function gridAction()
88
+ {
89
+ $this->loadLayout();
90
+ $this->renderLayout();
91
+ }
92
+
93
+
94
+ protected function _isAllowed()
95
+ {
96
+ return Mage::getSingleton('admin/session')->isAllowed('email_connector/reports/email_connector_campaign');
97
+ }
98
+
99
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/CatalogController.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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->getLayout()->getBlock('head')->setTitle('Connector Catalog');
13
+ $this->renderLayout();
14
+ }
15
+
16
+ /**
17
+ * Check currently called action by permissions for current user
18
+ *
19
+ * @return bool
20
+ */
21
+ protected function _isAllowed()
22
+ {
23
+ return Mage::getSingleton('admin/session')->isAllowed('email_connector/reports/email_connector_catalog');
24
+ }
25
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/ContactController.php ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * Edit action. Sync contact and redirect back.
25
+ */
26
+ public function editAction()
27
+ {
28
+ $contactId = (int) $this->getRequest()->getParam('id');
29
+ $contact = $this->_initAction();
30
+ if ($contactId && !$contact->getId()) {
31
+ $this->_getSession()->addError(Mage::helper('ddg')->__('This contact no longer exists.'));
32
+ $this->_redirect('*/*/');
33
+ return;
34
+ }
35
+ $contactEmail = Mage::getModel('ddg_automation/apiconnector_contact')->syncContact();
36
+ if ($contactEmail)
37
+ Mage::getSingleton('adminhtml/session')->addSuccess('Successfully synced : ' . $contactEmail);
38
+
39
+ Mage::dispatchEvent('email_contact_controller_edit_action', array('contact' => $contact));
40
+
41
+ $this->_redirect('*/*');
42
+ }
43
+
44
+ /**
45
+ * Delete a contact.
46
+ */
47
+ public function deleteAction()
48
+ {
49
+ if ($id = $this->getRequest()->getParam('id')) {
50
+ $contact = Mage::getModel('ddg_automation/contact')->load($id);
51
+ try {
52
+ $contact->delete();
53
+ $this->_getSession()->addSuccess(Mage::helper('ddg')->__('The contact has been deleted.'));
54
+ }
55
+ catch (Exception $e) {
56
+ $this->_getSession()->addError($e->getMessage());
57
+ }
58
+ }
59
+ $this->getResponse()->setRedirect($this->getUrl('*/*/', array('store'=>$this->getRequest()->getParam('store'))));
60
+ }
61
+
62
+ /**
63
+ * Mass delete contacts.
64
+ */
65
+ public function massDeleteAction()
66
+ {
67
+ $contactIds = $this->getRequest()->getParam('contact');
68
+ if (!is_array($contactIds)) {
69
+ $this->_getSession()->addError($this->__('Please select contacts.'));
70
+ }else {
71
+ $num = Mage::getResourceModel('ddg_automation/contact')->massDelete($contactIds);
72
+ if(is_int($num)){
73
+ $this->_getSession()->addSuccess(
74
+ Mage::helper('ddg')->__('Total of %d record(s) have been deleted.', $num)
75
+ );
76
+ }else
77
+ $this->_getSession()->addError($num->getMessage());
78
+ }
79
+ $this->_redirect('*/*/index');
80
+ }
81
+
82
+ /**
83
+ * Mark a contact to be resend.
84
+ */
85
+ public function massResendAction()
86
+ {
87
+ $contactIds = $this->getRequest()->getParam('contact');
88
+
89
+ if (!is_array($contactIds)) {
90
+ $this->_getSession()->addError($this->__('Please select contacts.'));
91
+ }else {
92
+ $num = Mage::getResourceModel('ddg_automation/contact')->massResend($contactIds);
93
+ if(is_int($num)){
94
+ $this->_getSession()->addSuccess(
95
+ Mage::helper('ddg')->__('Total of %d record(s) set for resend.', $num)
96
+ );
97
+ }else
98
+ $this->_getSession()->addError($num->getMessage());
99
+ }
100
+ $this->_redirect('*/*/index');
101
+ }
102
+
103
+
104
+ /**
105
+ * main grid.
106
+ */
107
+ public function gridAction(){
108
+ $this->loadLayout();
109
+ $this->renderLayout();
110
+ }
111
+
112
+
113
+ public function exportCsvAction()
114
+ {
115
+ $fileName = 'contacts.csv';
116
+ $content = $this->getLayout()->createBlock('ddg_automation/adminhtml_contact_grid')
117
+ ->getCsvFile();
118
+ $this->_prepareDownloadResponse($fileName, $content);
119
+ }
120
+
121
+ protected function _isAllowed()
122
+ {
123
+ return Mage::getSingleton('admin/session')->isAllowed('email_connector/reports/email_connector_contact');
124
+ }
125
+
126
+ protected function _initAction()
127
+ {
128
+ $contactId = (int) $this->getRequest()->getParam('id');
129
+ $contact = Mage::getModel('ddg_automation/contact')
130
+ ->setStoreId($this->getRequest()->getParam('store', 0));
131
+
132
+ if ($contactId) {
133
+ $contact->load($contactId);
134
+ }
135
+ Mage::register('current_contact', $contact);
136
+ return $contact;
137
+ }
138
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/DashboardController.php ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
30
+ $this->renderLayout();
31
+ }
32
+
33
+ /**
34
+ * Load Status Grid as ajax requst.
35
+ */
36
+ public function statusGridAction() {
37
+
38
+ $block = $this->getLayout()->createBlock('ddg_automation/adminhtml_dashboard_tabs_status');
39
+ $this->getResponse()->setBody($block->toHtml());
40
+ }
41
+
42
+ /**
43
+ * Ajax tab for config data.
44
+ */
45
+ public function emailConfigAction() {
46
+ $block = $this->getLayout()->createBlock('ddg_automation/adminhtml_dashboard_tabs_config');
47
+ $this->getResponse()->setBody($block->toHtml());
48
+ }
49
+
50
+ protected function _isAllowed()
51
+ {
52
+ return Mage::getSingleton('admin/session')->isAllowed('email_connector/email_connector_dashboard');
53
+ }
54
+
55
+
56
+ /**
57
+ * Ajax save the state of expandbles fieldsets.
58
+ */
59
+ public function stateAction()
60
+ {
61
+ $configState = array(
62
+ $this->getRequest()->getParam('container') => $this->getRequest()->getParam('value')
63
+ );
64
+ $this->_saveState($configState);
65
+ }
66
+
67
+ protected function _saveState($configState = array())
68
+ {
69
+ $adminUser = Mage::getSingleton('admin/session')->getUser();
70
+ if (is_array($configState)) {
71
+ $extra = $adminUser->getExtra();
72
+ if (!is_array($extra)) {
73
+ $extra = array();
74
+ }
75
+ if (!isset($extra['configState'])) {
76
+ $extra['configState'] = array();
77
+ }
78
+ foreach ($configState as $fieldset => $state) {
79
+ $extra['configState'][$fieldset] = $state;
80
+ }
81
+ $adminUser->saveExtra($extra);
82
+ }
83
+
84
+ return true;
85
+ }
86
+
87
+ /**
88
+ * ajax tab for view connector logs
89
+ */
90
+ public function logsAction()
91
+ {
92
+ $block = $this->getLayout()->createBlock('ddg_automation/adminhtml_dashboard_tabs_logs');
93
+ $this->getResponse()->setBody($block->toHtml());
94
+ }
95
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/ImporterController.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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->getLayout()->getBlock('head')->setTitle('Importer Status');
13
+ $this->renderLayout();
14
+ }
15
+
16
+ /**
17
+ * Mark a contact to be resend.
18
+ */
19
+ public function massResendAction()
20
+ {
21
+ $ids = $this->getRequest()->getParam('importer');
22
+ if (!is_array($ids)) {
23
+ $this->_getSession()->addError($this->__('Please select import.'));
24
+ }else {
25
+ $num = Mage::getResourceModel('ddg_automation/importer')->massResend($ids);
26
+ if(is_int($num)) {
27
+ $this->_getSession()->addSuccess(
28
+ Mage::helper('ddg')->__('Total of %d record(s) set for reset.', $num)
29
+ );
30
+ }else
31
+ $this->_getSession()->addError($num->getMessage());
32
+ }
33
+ $this->_redirect('*/*/index');
34
+ }
35
+
36
+
37
+ /**
38
+ * Mass delete contacts.
39
+ */
40
+ public function massDeleteAction()
41
+ {
42
+ $ids = $this->getRequest()->getParam('importer');
43
+ if (!is_array($ids)) {
44
+ $this->_getSession()->addError($this->__('Please select import.'));
45
+ }else {
46
+ $num = Mage::getResourceModel('ddg_automation/importer')->massDelete($ids);
47
+ if (is_int($num)){
48
+ $this->_getSession()->addSuccess(
49
+ Mage::helper('ddg')->__('Total of %d record(s) have been deleted.', $num)
50
+ );
51
+ }else
52
+ $this->_getSession()->addError($num->getMessage());
53
+ }
54
+ $this->_redirect('*/*/index');
55
+ }
56
+
57
+ /**
58
+ * Check currently called action by permissions for current user
59
+ *
60
+ * @return bool
61
+ */
62
+ protected function _isAllowed()
63
+ {
64
+ return Mage::getSingleton('admin/session')->isAllowed('email_connector/reports/email_connector_importer');
65
+ }
66
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/OrderController.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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->getLayout()->getBlock('head')->setTitle('Connector Orders');
13
+ $this->renderLayout();
14
+ }
15
+
16
+ /**
17
+ * Check currently called action by permissions for current user
18
+ *
19
+ * @return bool
20
+ */
21
+ protected function _isAllowed()
22
+ {
23
+ return Mage::getSingleton('admin/session')->isAllowed('email_connector/reports/email_connector_order');
24
+ }
25
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/QuoteController.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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->getLayout()->getBlock('head')->setTitle('Connector Quote(s)');
13
+ $this->renderLayout();
14
+ }
15
+
16
+ /**
17
+ * Check currently called action by permissions for current user
18
+ *
19
+ * @return bool
20
+ */
21
+ protected function _isAllowed()
22
+ {
23
+ return Mage::getSingleton('admin/session')->isAllowed('email_connector/reports/email_connector_quote');
24
+ }
25
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/ReviewController.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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->getLayout()->getBlock('head')->setTitle('Connector Reviews');
13
+ $this->renderLayout();
14
+ }
15
+
16
+ /**
17
+ * Check currently called action by permissions for current user
18
+ *
19
+ * @return bool
20
+ */
21
+ protected function _isAllowed()
22
+ {
23
+ return Mage::getSingleton('admin/session')->isAllowed('email_connector/reports/email_connector_review');
24
+ }
25
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/RulesController.php ADDED
@@ -0,0 +1,208 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $emailRules = Mage::getModel('ddg_automation/rules');
54
+
55
+ if ($id) {
56
+ $emailRules->load( $id );
57
+
58
+ if ( ! $emailRules->getId() ) {
59
+ Mage::getSingleton( 'adminhtml/session' )->addError(
60
+ Mage::helper( 'adminhtml' )->__( 'This rule no longer exists.' ) );
61
+ $this->_redirect( '*/*' );
62
+ return;
63
+ }
64
+ //$emailRules->setCondition(unserialize($model->getCondition()));
65
+ }
66
+ $this->_title($emailRules->getId() ? $emailRules->getName() : $this->__('New Rule'));
67
+
68
+ // set entered data if was error when we do save
69
+ $data = Mage::getSingleton('adminhtml/session')->getPageData(true);
70
+ if (! empty($data)) {
71
+ $emailRules->addData($data);
72
+ }
73
+
74
+
75
+ Mage::register('current_ddg_rule', $emailRules);
76
+
77
+ $this->_initAction()->getLayout()->getBlock('ddg_rule_edit')
78
+ ->setData('action', $this->getUrl('*/*/save'));
79
+
80
+ $this->_addBreadcrumb(
81
+ $id ? Mage::helper('ddg')->__('Edit Rule')
82
+ : Mage::helper('ddg')->__('New Rule'),
83
+ $id ? Mage::helper('ddg')->__('Edit Rule')
84
+ : Mage::helper('ddg')->__('New Rule'))
85
+ ->renderLayout();
86
+
87
+ }
88
+
89
+ /**
90
+ * action for save rule data
91
+ */
92
+ public function saveAction()
93
+ {
94
+ if ($this->getRequest()->getPost()) {
95
+ try {
96
+ $model = Mage::getModel('ddg_automation/rules');
97
+ $data = $this->getRequest()->getPost();
98
+ $id = $this->getRequest()->getParam('id');
99
+
100
+ if($data['website_ids']){
101
+ foreach($data['website_ids'] as $websiteId){
102
+ $result = $model->checkWebsiteBeforeSave($websiteId, $data['type'], $id);
103
+ if(!$result){
104
+ $websiteName = Mage::app()->getWebsite($websiteId)->getName();
105
+ $this->_getSession()->addError(
106
+ Mage::helper('adminhtml')->__('Rule already exist for website '. $websiteName . '. You can only have one rule per website.'));
107
+ $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
108
+ return;
109
+ }
110
+ }
111
+ }
112
+
113
+ $model->load($id);
114
+ if ($id != $model->getId()) {
115
+ Mage::throwException(Mage::helper('ddg')->__('Wrong rule specified.'));
116
+ }
117
+
118
+
119
+ foreach($data as $key => $value){
120
+ if($key != 'form_key'){
121
+ if($key == 'condition'){
122
+ if (is_array($value))
123
+ unset($value['__empty']);
124
+ }
125
+ $model->setData($key, $value);
126
+ }
127
+ }
128
+
129
+ $this->_getSession()->setPageData($model->getData());
130
+
131
+ $model->save();
132
+ $this->_getSession()->addSuccess(Mage::helper('adminhtml')->__('The rule has been saved.'));
133
+ $this->_getSession()->setPageData(false);
134
+ if ($this->getRequest()->getParam('back')) {
135
+ $this->_redirect('*/*/edit', array('id' => $model->getId()));
136
+ return;
137
+ }
138
+ $this->_redirect('*/*/');
139
+ return;
140
+ } catch (Mage_Core_Exception $e) {
141
+ $this->_getSession()->addError($e->getMessage());
142
+ $id = (int)$this->getRequest()->getParam('id');
143
+ if (!empty($id)) {
144
+ $this->_redirect('*/*/edit', array('id' => $id));
145
+ } else {
146
+ $this->_redirect('*/*/new');
147
+ }
148
+ return;
149
+
150
+ } catch (Exception $e) {
151
+ $this->_getSession()->addError(
152
+ Mage::helper('adminhtml')->__('An error occurred while saving the rule data. Please review the log and try again.'));
153
+ Mage::logException($e);
154
+ Mage::getSingleton('adminhtml/session')->setPageData($data);
155
+ $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
156
+ return;
157
+ }
158
+ }
159
+ $this->_redirect('*/*/');
160
+ }
161
+
162
+ /**
163
+ * action for delete button
164
+ */
165
+ public function deleteAction()
166
+ {
167
+ if ($id = $this->getRequest()->getParam('id')) {
168
+ try {
169
+ $model = Mage::getModel('ddg_automation/rules');
170
+ $model->setId($id);
171
+ $model->delete();
172
+ Mage::getSingleton('adminhtml/session')->addSuccess(
173
+ Mage::helper('adminhtml')->__('The rule has been deleted.'));
174
+ $this->_redirect('*/*/');
175
+ return;
176
+ } catch (Mage_Core_Exception $e) {
177
+ $this->_getSession()->addError($e->getMessage());
178
+ } catch (Exception $e) {
179
+ $this->_getSession()->addError(
180
+ Mage::helper('adminhtml')->__('An error occurred while deleting the rule. Please review the log and try again.'));
181
+ Mage::logException($e);
182
+ $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
183
+ return;
184
+ }
185
+ }
186
+ Mage::getSingleton('adminhtml/session')->addError(
187
+ Mage::helper('adminhtml')->__('Unable to find a rule to delete.'));
188
+ $this->_redirect('*/*/');
189
+ }
190
+
191
+ /**
192
+ * main page/grid.
193
+ */
194
+ public function gridAction()
195
+ {
196
+ $this->loadLayout();
197
+ $this->renderLayout();
198
+ }
199
+
200
+ /**
201
+ * @return bool
202
+ */
203
+ protected function _isAllowed()
204
+ {
205
+ return Mage::getSingleton('admin/session')->isAllowed('email_connector/automation_rules');
206
+ }
207
+
208
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/StudioController.php ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $this->getLayout()->getBlock('connector_iframe')
21
+ ->setText(
22
+ "<iframe src=" . $loginuserUrl . " width=100% height=1650 frameborder='0' scrolling='no' style='margin:0;padding: 0;display:block;'></iframe>"
23
+ );
24
+
25
+
26
+ $this->renderLayout();
27
+ }
28
+
29
+ protected function _isAllowed()
30
+ {
31
+ return Mage::getSingleton('admin/session')->isAllowed('ddg_automation/automation_studio');
32
+ }
33
+
34
+ /**
35
+ * Generate new token and connect from the admin.
36
+ *
37
+ * POST httpsː//my.dotmailer.com/OAuth2/Tokens.ashx HTTP/1.1
38
+ * Content-Type: application/x-www-form-urlencoded
39
+ * client_id=QVNY867m2DQozogTJfUmqA%253D%253D&
40
+ * redirect_uri=https%3a%2f%2flocalhost%3a10999%2fcallback.aspx
41
+ * &client_secret=SndpTndiSlhRawAAAAAAAA%253D%253D
42
+ * &grant_type=authorization_code
43
+ */
44
+ public function generatetokenAction()
45
+ {
46
+ //check for secure url
47
+ $adminUser = Mage::getSingleton('admin/session')->getUser();
48
+ $refreshToken = Mage::getSingleton('admin/user')->load($adminUser->getId())->getRefreshToken();
49
+
50
+ if ($refreshToken) {
51
+ $code = Mage::helper('ddg')->getCode();
52
+ $params = 'client_id=' . Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CLIENT_ID) .
53
+ '&client_secret=' . Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CLIENT_SECRET_ID) .
54
+ '&refresh_token=' . $refreshToken .
55
+ '&grant_type=refresh_token';
56
+
57
+ $url = Mage::helper('ddg/config')->getTokenUrl();
58
+
59
+ Mage::helper('ddg')->log('token code : ' . $code . ', params : ' . $params);
60
+
61
+ /**
62
+ * Refresh Token request.
63
+ */
64
+ $ch = curl_init();
65
+ curl_setopt($ch, CURLOPT_URL, $url);
66
+ curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
67
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
68
+ curl_setopt($ch, CURLOPT_TIMEOUT, 5);
69
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
70
+ curl_setopt($ch, CURLOPT_POST, count($params));
71
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
72
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
73
+
74
+ $response = json_decode(curl_exec($ch));
75
+
76
+ if (isset($response->error)) {
77
+ Mage::helper('ddg')->log("Token Error Num`ber:" . curl_errno($ch) . "Error String:" . curl_error($ch));
78
+ }
79
+ curl_close($ch);
80
+
81
+ $token = $response->access_token;
82
+ return $token;
83
+
84
+ } else {
85
+ Mage::getSingleton('adminhtml/session')->addNotice('Please Connect To Access The Page.');
86
+ }
87
+
88
+ $this->_redirect('*/system_config/edit', array('section' => 'connector_developer_settings'));
89
+ }
90
+
91
+ /**
92
+ * Disconnect and remote the refresh token.
93
+ */
94
+ public function disconnectAction()
95
+ {
96
+ try {
97
+ $adminUser = Mage::getSingleton('admin/session')->getUser();
98
+
99
+ if ($adminUser->getRefreshToken()) {
100
+ $adminUser->setRefreshToken()->save();
101
+ }
102
+ Mage::getSingleton('adminhtml/session')->addSuccess('Successfully disconnected');
103
+ }catch (Exception $e){
104
+ Mage::logException($e);
105
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
106
+ }
107
+
108
+ $this->_redirectReferer('*/*/*');
109
+ }
110
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Email/WishlistController.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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->getLayout()->getBlock('head')->setTitle('Connector Wishlist(s)');
13
+ $this->renderLayout();
14
+ }
15
+
16
+ /**
17
+ * Check currently called action by permissions for current user
18
+ *
19
+ * @return bool
20
+ */
21
+ protected function _isAllowed()
22
+ {
23
+ return Mage::getSingleton('admin/session')->isAllowed('email_connector/reports/email_connector_wishlist');
24
+ }
25
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/RulesController.php ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Adminhtml_RulesController extends Mage_Adminhtml_Controller_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
+
61
+ if ($arrayKey && $id && $attribute && $conditionName && $valueName) {
62
+
63
+ $rule = Mage::getModel('ddg_automation/rules')->load($id);
64
+ //rule not found
65
+ if (! $rule->getId()) {
66
+ return $this->getResponse()->clearHeaders()->setHeader('Content-Type', 'application/json')->setBody('Rule not found!');
67
+ }
68
+ $conditions = $rule->getCondition();
69
+ $condition = $conditions[$arrayKey];
70
+ $selectedConditions = $condition['conditions'];
71
+ $selectedValues = $condition['cvalue'];
72
+ $type = Mage::getModel('ddg_automation/adminhtml_source_rules_type')->getInputType($attribute);
73
+ $conditionOptions = Mage::getModel('ddg_automation/adminhtml_source_rules_condition')->getInputTypeOptions($type);
74
+
75
+ $response['condition'] =
76
+ str_replace(
77
+ 'value="'.$selectedConditions.'"',
78
+ 'value="'.$selectedConditions.'"'.'selected="selected"',
79
+ $this->_getOptionHtml('conditions', $conditionName, $conditionOptions)
80
+ );
81
+
82
+ $elmType = Mage::getModel('ddg_automation/adminhtml_source_rules_value')->getValueElementType($attribute);
83
+ if ($elmType == 'select' or $selectedConditions == 'null') {
84
+ $is_empty = false;
85
+
86
+ if ($selectedConditions == 'null')
87
+ $is_empty = true;
88
+ $valueOptions = Mage::getModel('ddg_automation/adminhtml_source_rules_value')->getValueSelectOptions($attribute, $is_empty);
89
+ $response['cvalue'] =
90
+ str_replace(
91
+ 'value="'.$selectedValues.'"',
92
+ 'value="'.$selectedValues.'"'.'selected="selected"',
93
+ $this->_getOptionHtml('cvalue', $valueName, $valueOptions)
94
+ );
95
+ } elseif ($elmType == 'text') {
96
+ $html = "<input style='width:160px' title='cvalue' class='' id='' name='$valueName' value='$selectedValues' />";
97
+ $response['cvalue'] = $html;
98
+ }
99
+ $this->getResponse()->clearHeaders()->setHeader('Content-Type', 'application/json')->setBody(Mage::helper('core')->jsonEncode($response));
100
+ }
101
+ }
102
+
103
+ /**
104
+ * ajax action for value update without selection
105
+ */
106
+ public function valueAction()
107
+ {
108
+ $valueName = $this->getRequest()->getParam('value');
109
+ $conditionValue = $this->getRequest()->getParam('condValue');;
110
+ $attributeValue = $this->getRequest()->getParam('attributeValue');
111
+
112
+ if($valueName && $attributeValue && $conditionValue){
113
+ if($conditionValue == 'null'){
114
+ $valueOptions = Mage::getModel('ddg_automation/adminhtml_source_rules_value')->getValueSelectOptions($attributeValue, true);
115
+ $response['cvalue'] = $this->_getOptionHtml('cvalue', $valueName, $valueOptions);
116
+ }
117
+ else{
118
+ $elmType = Mage::getModel('ddg_automation/adminhtml_source_rules_value')->getValueElementType($attributeValue);
119
+ if($elmType == 'select'){
120
+ $valueOptions = Mage::getModel('ddg_automation/adminhtml_source_rules_value')->getValueSelectOptions($attributeValue);
121
+ $response['cvalue'] = $this->_getOptionHtml('cvalue', $valueName, $valueOptions);
122
+ }elseif($elmType == 'text'){
123
+ $html = "<input style='width:160px' title='cvalue' class='' id='' name=$valueName />";
124
+ $response['cvalue'] = $html;
125
+ }
126
+ }
127
+ $this->getResponse()->clearHeaders()->setHeader('Content-Type', 'application/json')->setBody(Mage::helper('core')->jsonEncode($response));
128
+ }
129
+ }
130
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/System/Email/TemplateController.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once 'Mage/Adminhtml/controllers/System/Email/TemplateController.php';
4
+
5
+ class Dotdigitalgroup_Email_Adminhtml_System_Email_TemplateController extends Mage_Adminhtml_System_Email_TemplateController
6
+ {
7
+ /**
8
+ * Set template data to retrieve it in template info form
9
+ */
10
+ public function defaultTemplateAction()
11
+ {
12
+ if(!$this->getRequest()->getParam('connector') or $this->getRequest()->getParam('connector') == '')
13
+ parent::defaultTemplateAction();
14
+
15
+ $template = $this->_initTemplate('id');
16
+ $templateCode = $this->getRequest()->getParam('code');
17
+ $connectorTemplateId = $this->getRequest()->getParam('connector');
18
+
19
+ $template->loadDefault($templateCode, $this->getRequest()->getParam('locale'));
20
+ $template->setData('orig_template_code', $templateCode);
21
+ $template->setData('template_variables', Zend_Json::encode($template->getVariablesOptionArray(true)));
22
+
23
+ $templateBlock = $this->getLayout()->createBlock('adminhtml/system_email_template_edit');
24
+ $template->setData('orig_template_used_default_for', $templateBlock->getUsedDefaultForPaths(false));
25
+
26
+ if($connectorTemplateId){
27
+ $client = Mage::helper('ddg')->getWebsiteApiClient(Mage::app()->getWebsite());
28
+ $connectorTemplate = $client->getApiTemplate($connectorTemplateId);
29
+ if(isset($connectorTemplate->id))
30
+ $template->setTemplateText($connectorTemplate->htmlContent);
31
+ $template->setTemplateStyles('');
32
+ }
33
+
34
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($template->getData()));
35
+ }
36
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Adminhtml/Widget/ChooserController.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Adminhtml_Widget_ChooserController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+ /**
6
+ * ajax handler for product chooser
7
+ */
8
+ public function productAction()
9
+ {
10
+ $block = $this->getLayout()->createBlock(
11
+ 'ddg_automation/adminhtml_widget_chooser_product', 'email_connector_chooser_product',
12
+ array('js_form_object' => $this->getRequest()->getParam('form'),
13
+ ));
14
+
15
+ if ($block) {
16
+ $this->getResponse()->setBody($block->toHtml());
17
+ }
18
+ }
19
+
20
+ protected function _isAllowed()
21
+ {
22
+ return Mage::getSingleton('admin/session')->isAllowed('system/config/connector_dynamic_content');
23
+ }
24
+ }
app/code/community/Dotdigitalgroup/Email/controllers/AjaxController.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_AjaxController extends Mage_Core_Controller_Front_Action
4
+ {
5
+ public function emailcaptureAction()
6
+ {
7
+ if($this->getRequest()->getParam('email') && Mage::getSingleton('checkout/session')->getQuote()){
8
+ $email = $this->getRequest()->getParam('email');
9
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
10
+ if($quote->hasItems()){
11
+ try {
12
+ $quote->setCustomerEmail($email)->save();
13
+ Mage::helper('ddg')->log('ajax emailCapture email: '. $email);
14
+ }catch(Exception $e){
15
+ Mage::logException($e);
16
+ Mage::helper('ddg')->log('ajax emailCapture fail for email: '. $email);
17
+ }
18
+ }
19
+ }
20
+ }
21
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Customer/AccountController.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Customer_AccountController extends Mage_Core_Controller_Front_Action
4
+ {
5
+ /**
6
+ * Checking if user is logged in. If not logged in then redirect to customer login
7
+ */
8
+ public function preDispatch()
9
+ {
10
+ parent::preDispatch();
11
+
12
+ if (!Mage::getSingleton('customer/session')->authenticate($this)) {
13
+ $this->setFlag('', 'no-dispatch', true);
14
+
15
+ // adding message in customer login page
16
+ Mage::getSingleton('core/session')
17
+ ->addNotice(Mage::helper('ddg')->__('Please sign in or create a new account'));
18
+ }
19
+ }
20
+
21
+ public function statsAction()
22
+ {
23
+ $this->loadLayout();
24
+ $this->getLayout()->getBlock('head')->setTitle($this->__('Email Activity'));
25
+ $this->renderLayout();
26
+ }
27
+ }
app/code/community/Dotdigitalgroup/Email/controllers/Customer/NewsletterController.php ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Dotdigitalgroup_Email_Customer_NewsletterController extends Mage_Core_Controller_Front_Action
4
+ {
5
+
6
+ /**
7
+ * Check customer authentication
8
+ */
9
+ public function preDispatch()
10
+ {
11
+ parent::preDispatch();
12
+
13
+ if (!$this->getRequest()->isDispatched()) {
14
+ return;
15
+ }
16
+ if (!$this->_getCustomerSession()->authenticate($this)) {
17
+ $this->setFlag('', 'no-dispatch', true);
18
+ }
19
+ }
20
+
21
+ /**
22
+ * get customer session
23
+ *
24
+ * @return Mage_Customer_Model_Session
25
+ */
26
+ protected function _getCustomerSession()
27
+ {
28
+ return Mage::getSingleton('customer/session');
29
+ }
30
+
31
+ /**
32
+ * save action
33
+ *
34
+ * @return Mage_Core_Controller_Varien_Action
35
+ * @throws Mage_Core_Exception
36
+ */
37
+ public function saveAction()
38
+ {
39
+ if (!$this->_validateFormKey() or !$this->_getCustomerSession()->getConnectorContactId()) {
40
+ return $this->_redirect('customer/account/');
41
+ }
42
+ //params
43
+ $additional_subscriptions = Mage::app()->getRequest()->getParam('additional_subscriptions');
44
+ $data_fields = Mage::app()->getRequest()->getParam('data_fields');
45
+ $customer_id = $this->_getCustomerSession()->getConnectorContactId();
46
+ $customer_email = $this->_getCustomerSession()->getCustomer()->getEmail();
47
+
48
+ //client
49
+ $website = Mage::getModel('customer/session')->getCustomer()->getStore()->getWebsite();
50
+ $client = Mage::getModel('ddg_automation/apiconnector_client');
51
+ $client->setApiUsername(Mage::helper('ddg')->getApiUsername($website))
52
+ ->setApiPassword(Mage::helper('ddg')->getApiPassword($website));
53
+
54
+ $contact = $client->getContactById($customer_id);
55
+ if(isset($contact->id)){
56
+ //contact address books
57
+ $bookError = false;
58
+ $addressBooks = $client->getContactAddressBooks($contact->id);
59
+ $subscriberAddressBook = Mage::helper('ddg')->getSubscriberAddressBook(Mage::app()->getWebsite());
60
+ $processedAddressBooks = array();
61
+ if(is_array($addressBooks)){
62
+ foreach($addressBooks as $addressBook){
63
+ if($subscriberAddressBook != $addressBook->id)
64
+ $processedAddressBooks[$addressBook->id] = $addressBook->name;
65
+ }
66
+ }
67
+ if(isset($additional_subscriptions)){
68
+ foreach($additional_subscriptions as $additional_subscription){
69
+ if(!isset($processedAddressBooks[$additional_subscription])){
70
+ $bookResponse = $client->postAddressBookContacts($additional_subscription, $contact);
71
+ if(isset($bookResponse->message))
72
+ $bookError = true;
73
+
74
+ }
75
+ }
76
+ foreach($processedAddressBooks as $bookId => $name){
77
+ if(!in_array($bookId, $additional_subscriptions)) {
78
+ $bookResponse = $client->deleteAddressBookContact($bookId, $contact->id);
79
+ if(isset($bookResponse->message))
80
+ $bookError = true;
81
+ }
82
+ }
83
+ }
84
+ else{
85
+ foreach($processedAddressBooks as $bookId => $name){
86
+ $bookResponse = $client->deleteAddressBookContact($bookId, $contact->id);
87
+ if(isset($bookResponse->message))
88
+ $bookError = true;
89
+ }
90
+ }
91
+
92
+ //contact data fields
93
+ $data = array();
94
+ $dataFields = $client->getDataFields();
95
+ $processedFields = array();
96
+ foreach($dataFields as $dataField){
97
+ $processedFields[$dataField->name] = $dataField->type;
98
+ }
99
+ foreach($data_fields as $key => $value){
100
+ if(isset($processedFields[$key]) && $value){
101
+ if($processedFields[$key] == 'Numeric'){
102
+ $data_fields[$key] = (int)$value;
103
+ }
104
+ if($processedFields[$key] == 'String'){
105
+ $data_fields[$key] = (string)$value;
106
+ }
107
+ if($processedFields[$key] == 'Date'){
108
+ $date = new Zend_Date($value, "Y/M/d");
109
+ $data_fields[$key] = $date->toString(Zend_Date::ISO_8601);
110
+ }
111
+ $data[] = array(
112
+ 'Key' => $key,
113
+ 'Value' => $data_fields[$key]
114
+ );
115
+ }
116
+ }
117
+ $contactResponse = $client->updateContactDatafieldsByEmail($customer_email, $data);
118
+
119
+ if(isset($contactResponse->message) && $bookError)
120
+ Mage::getSingleton('customer/session')->addError($this->__('An error occurred while saving your subscription preferences.'));
121
+ else
122
+ Mage::getSingleton('customer/session')->addSuccess($this->__('The subscription preferences has been saved.'));
123
+ }
124
+ else{
125
+ Mage::getSingleton('customer/session')->addError($this->__('An error occurred while saving your subscription preferences.'));
126
+ }
127
+ $this->_redirect('customer/account/');
128
+ }
129
+ }
app/code/community/Dotdigitalgroup/Email/controllers/DynamicContentController.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once 'Dotdigitalgroup' . DS . 'Email' . DS . 'controllers' . DS . 'ResponseController.php';
3
+
4
+ class Dotdigitalgroup_Email_DynamicContentController extends Dotdigitalgroup_Email_ResponseController
5
+ {
6
+ /**
7
+ * @return Mage_Core_Controller_Front_Action|void
8
+ * @throws Exception
9
+ */
10
+ public function preDispatch()
11
+ {
12
+ //authenticate
13
+ $this->authenticate();
14
+
15
+ $orderId = $this->getRequest()->getParam('order_id', false);
16
+ //check for order_id param
17
+ if ($orderId) {
18
+ $order = Mage::getModel('sales/order')->load($orderId);
19
+ //check if the order still exists
20
+ if ($order->getId()) {
21
+ Mage::register('current_order', $order);
22
+ $storeId = $order->getStoreId();
23
+ //start the emulation for order store
24
+ $appEmulation = Mage::getSingleton('core/app_emulation');
25
+ $appEmulation->startEnvironmentEmulation($storeId);
26
+ } else {
27
+ //throw new Exception('TE invoice : order not found: ' . $orderId);
28
+ Mage::helper('ddg')->log('order not found: ' . $orderId);
29
+ $this->sendResponse();
30
+ Mage::throwException('Order not found');
31
+ }
32
+ } else {
33
+ //throw new Exception('TE invoice : order_id missing :' . $orderId);
34
+ Mage::helper('ddg')->log('order_id missing :' . $orderId);
35
+ $this->sendResponse();
36
+ Mage::throwException('Order id is missing');
37
+ }
38
+ parent::preDispatch();
39
+ }
40
+ }
app/code/community/Dotdigitalgroup/Email/controllers/EmailController.php ADDED
@@ -0,0 +1,278 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once 'Dotdigitalgroup' . DS . 'Email' . DS . 'controllers' . DS . 'ResponseController.php';
3
+
4
+ class Dotdigitalgroup_Email_EmailController extends Dotdigitalgroup_Email_ResponseController
5
+ {
6
+ /**
7
+ * @var $_quote Mage_Sales_Model_Quote
8
+ */
9
+ protected $_quote;
10
+
11
+ /**
12
+ * wishlist
13
+ */
14
+ public function wishlistAction()
15
+ {
16
+ //authenticate
17
+ $this->authenticate();
18
+ $this->loadLayout();
19
+ $wishlist = $this->getLayout()->createBlock('ddg_automation/wishlist', 'connector_wishlist', array(
20
+ 'template' => 'connector/wishlist.phtml'
21
+ ));
22
+ $this->getLayout()->getBlock('content')->append($wishlist);
23
+ $this->renderLayout();
24
+ $this->checkContentNotEmpty($wishlist->toHtml(), false);
25
+ }
26
+
27
+ /**
28
+ * Generate coupon for a coupon code id.
29
+ */
30
+ public function couponAction()
31
+ {
32
+ $this->authenticate();
33
+ $this->loadLayout();
34
+ //page root template
35
+ if ($root = $this->getLayout()->getBlock('root')) {
36
+ $root->setTemplate('page/blank.phtml');
37
+ }
38
+ //content template
39
+ $coupon = $this->getLayout()->createBlock('ddg_automation/coupon', 'connector_coupon', array(
40
+ 'template' => 'connector/coupon.phtml'
41
+ ));
42
+ $this->checkContentNotEmpty($coupon->toHtml(), false);
43
+ $this->getLayout()->getBlock('content')->append($coupon);
44
+ $this->renderLayout();
45
+ }
46
+
47
+ /**
48
+ * Basket page to display the user items with specific email.
49
+ */
50
+ public function basketAction()
51
+ {
52
+ //authenticate
53
+ $this->authenticate();
54
+ $this->loadLayout();
55
+ if ($root = $this->getLayout()->getBlock('root')) {
56
+ $root->setTemplate('page/blank.phtml');
57
+ }
58
+ $basket = $this->getLayout()->createBlock('ddg_automation/basket', 'connector_basket', array(
59
+ 'template' => 'connector/basket.phtml'
60
+ ));
61
+ $this->getLayout()->getBlock('content')->append($basket);
62
+ $this->renderLayout();
63
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
64
+ }
65
+
66
+ public function reviewAction()
67
+ {
68
+ //authenticate
69
+ $this->authenticate();
70
+
71
+ $orderId = $this->getRequest()->getParam('order_id', false);
72
+ //check for order_id param
73
+ if ($orderId) {
74
+ $order = Mage::getModel('sales/order')->load($orderId);
75
+ //check if the order still exists
76
+ if ($order->getId()) {
77
+ Mage::register('current_order', $order);
78
+ } else {
79
+ Mage::helper('ddg')->log('order not found: ' . $orderId);
80
+ $this->sendResponse();
81
+ Mage::throwException('Order not found');
82
+ }
83
+ } else {
84
+ Mage::helper('ddg')->log('order_id missing :' . $orderId);
85
+ $this->sendResponse();
86
+ Mage::throwException('Order id is missing');
87
+ }
88
+
89
+
90
+ $this->loadLayout();
91
+ $review = $this->getLayout()->createBlock('ddg_automation/order', 'connector_review', array(
92
+ 'template' => 'connector/review.phtml'
93
+ ));
94
+ $this->getLayout()->getBlock('content')->append($review);
95
+ $this->renderLayout();
96
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
97
+ }
98
+
99
+ /**
100
+ * Callback action for the automation studio.
101
+ */
102
+ public function callbackAction()
103
+ {
104
+ $code = $this->getRequest()->getParam('code', false);
105
+ $userId = $this->getRequest()->getParam('state');
106
+ $adminUser = Mage::getModel('admin/user')->load($userId);
107
+
108
+
109
+ if ($code && $adminUser->getId()) {
110
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB, true);
111
+ //callback url
112
+ $callback = $baseUrl . 'connector/email/callback';
113
+ $data = 'client_id=' . Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CLIENT_ID) .
114
+ '&client_secret=' . Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CLIENT_SECRET_ID) .
115
+ '&redirect_uri=' . $callback .
116
+ '&grant_type=authorization_code' .
117
+ '&code=' . $code;
118
+
119
+
120
+ $url = Mage::helper('ddg/config')->getTokenUrl();
121
+ $ch = curl_init();
122
+ curl_setopt($ch, CURLOPT_URL, $url);
123
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
124
+ curl_setopt($ch, CURLOPT_TIMEOUT, 10);
125
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
126
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
127
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
128
+ curl_setopt($ch, CURLOPT_POST, count($data));
129
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
130
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array ('Content-Type: application/x-www-form-urlencoded'));
131
+
132
+
133
+ $response = json_decode(curl_exec($ch));
134
+ if ($response === false) {
135
+ Mage::helper('ddg')->log("Error Number: " . curl_errno($ch))
136
+ ->rayLog('Automaion studio number not found : ' . serialize($response));
137
+ }
138
+
139
+ //save the refresh token to the admin user
140
+ $adminUser->setRefreshToken($response->refresh_token)->save();
141
+ }
142
+ //redirect to automation index page
143
+ $this->_redirectReferer(Mage::helper('adminhtml')->getUrl('adminhtml/email_studio/index'));
144
+ }
145
+
146
+ /**
147
+ * quote process action
148
+ */
149
+ public function getbasketAction()
150
+ {
151
+ $quote_id = $this->getRequest()->getParam('quote_id');
152
+ //no quote id redirect to base url
153
+ if(!$quote_id)
154
+ $this->_redirectUrl(Mage::getBaseUrl());
155
+
156
+ $quoteModel = Mage::getModel('sales/quote')->load($quote_id);
157
+
158
+ //no quote id redirect to base url
159
+ if (!$quoteModel->getId())
160
+ $this->_redirectUrl(Mage::getBaseUrl());
161
+
162
+ //set quoteModel to _quote property for later use
163
+ $this->_quote = $quoteModel;
164
+
165
+ if($quoteModel->getCustomerId())
166
+ $this->_handleCustomerBasket();
167
+ else
168
+ $this->_handleGuestBasket();
169
+ }
170
+
171
+ /**
172
+ * process customer basket
173
+ */
174
+ private function _handleCustomerBasket()
175
+ {
176
+ $customerSession = Mage::getSingleton('customer/session');
177
+ $configCartUrl = $this->_quote->getStore()->getWebsite()->getConfig(
178
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CONTENT_CART_URL
179
+ );
180
+
181
+ //if customer is logged in then redirect to cart
182
+ if($customerSession->isLoggedIn()){
183
+ $checkoutSession = Mage::getSingleton('checkout/session');
184
+ if($checkoutSession->getQuote() && $checkoutSession->getQuote()->hasItems()){
185
+ $quote = $checkoutSession->getQuote();
186
+ if($this->_quote->getId() != $quote->getId())
187
+ $this->_checkMissingAndAdd();
188
+ }
189
+ else{
190
+ $this->_loadAndReplace();
191
+ }
192
+
193
+ if($configCartUrl)
194
+ $url = $configCartUrl;
195
+ else
196
+ $url = $customerSession->getCustomer()->getStore()->getUrl('checkout/cart');
197
+
198
+ $this->_redirectUrl($url);
199
+ }
200
+ else{
201
+ //set after auth url. customer will be redirected to cart after successful login
202
+ if($configCartUrl)
203
+ $cartUrl = $configCartUrl;
204
+ else
205
+ $cartUrl = 'checkout/cart';
206
+ $customerSession->setAfterAuthUrl($this->_quote->getStore()->getUrl($cartUrl));
207
+
208
+ //send customer to login page
209
+ $configLoginUrl = $this->_quote->getStore()->getWebsite()->getConfig(
210
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CONTENT_LOGIN_URL
211
+ );
212
+ if($configLoginUrl)
213
+ $loginUrl = $configLoginUrl;
214
+ else
215
+ $loginUrl = 'customer/account/login';
216
+ $this->_redirectUrl($this->_quote->getStore()->getUrl($loginUrl));
217
+ }
218
+ }
219
+
220
+ /**
221
+ * process guest basket
222
+ */
223
+ private function _handleGuestBasket()
224
+ {
225
+ $checkoutSession = Mage::getSingleton('checkout/session');
226
+ if($checkoutSession->getQuote() && $checkoutSession->getQuote()->hasItems()){
227
+ $this->_checkMissingAndAdd();
228
+ }
229
+ else{
230
+ $this->_loadAndReplace();
231
+ }
232
+
233
+ $configCartUrl = $this->_quote->getStore()->getWebsite()->getConfig(
234
+ Dotdigitalgroup_Email_Helper_Config::XML_PATH_CONNECTOR_CONTENT_CART_URL
235
+ );
236
+
237
+ if($configCartUrl)
238
+ $url = $configCartUrl;
239
+ else
240
+ $url = 'checkout/cart';
241
+ $this->_redirectUrl($this->_quote->getStore()->getUrl($url));
242
+ }
243
+
244
+ /**
245
+ * check missing items from current quote and add
246
+ */
247
+ private function _checkMissingAndAdd()
248
+ {
249
+ $checkoutSession = Mage::getSingleton('checkout/session');
250
+ $currentQuote = $checkoutSession->getQuote();
251
+ if($currentQuote->hasItems()){
252
+ $currentSessionItems = $currentQuote->getAllItems();
253
+ $currentItemIds = array();
254
+ foreach($currentSessionItems as $currentSessionItem){
255
+ $currentItemIds[] = $currentSessionItem->getId();
256
+ }
257
+ foreach($this->_quote->getAllItems() as $item){
258
+ if(!in_array($item->getId(), $currentItemIds)){
259
+ $currentQuote->addItem($item);
260
+ }
261
+ }
262
+ $currentQuote->collectTotals()->save();
263
+ }else{
264
+ $this->_loadAndReplace();
265
+ }
266
+ }
267
+
268
+ /**
269
+ * load quote and replace in session#1114
270
+ */
271
+ private function _loadAndReplace()
272
+ {
273
+ $checkoutSession = Mage::getSingleton('checkout/session');
274
+ $quote = Mage::getSingleton('sales/quote')->load($this->_quote->getId());
275
+ $quote->setIsActive(true)->save();
276
+ $checkoutSession->replaceQuote($quote);
277
+ }
278
+ }
app/code/community/Dotdigitalgroup/Email/controllers/FeefoController.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ return;
21
+ }
22
+ break;
23
+ case 'reviews':
24
+ if (!$helper->getFeefoLogon() or !Mage::app()->getRequest()->getParam('quote_id')){
25
+ $this->sendResponse();
26
+ return;
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
+ $block = $this->getLayout()->getBlock('connector_feefo_service_score');
41
+ $this->checkContentNotEmpty($block->toHtml(), false);
42
+ $this->renderLayout();
43
+ }
44
+
45
+ /**
46
+ * show product reviews
47
+ */
48
+ public function reviewsAction()
49
+ {
50
+ $this->loadLayout();
51
+ $this->renderLayout();
52
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
53
+ }
54
+ }
app/code/community/Dotdigitalgroup/Email/controllers/ProductsController.php ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once 'Dotdigitalgroup' . DS . 'Email' . DS . 'controllers' . DS . 'ResponseController.php';
3
+
4
+ class Dotdigitalgroup_Email_ProductsController extends Dotdigitalgroup_Email_ResponseController
5
+ {
6
+ /**
7
+ * @return Mage_Core_Controller_Front_Action|void
8
+ */
9
+ public function preDispatch()
10
+ {
11
+ //authenticate
12
+ $this->authenticate();
13
+ //skip order_id check for this actions
14
+ $skip = array('push', 'nosto');
15
+ $actionName = $this->getRequest()->getActionName();
16
+ if (! in_array($actionName, $skip)) {
17
+ $orderId = $this->getRequest()->getParam('order_id', false);
18
+ //check for order id param
19
+ if ($orderId) {
20
+ //check if order still exists
21
+ $order = Mage::getModel('sales/order')->load($orderId);
22
+ if ($order->getId()) {
23
+ Mage::register('current_order', $order);
24
+ //start app emulation
25
+ $storeId = $order->getStoreId();
26
+ $appEmulation = Mage::getSingleton('core/app_emulation');
27
+ $appEmulation->startEnvironmentEmulation($storeId);
28
+ } else {
29
+ $message = 'Dynamic : order not found: ' . $orderId;
30
+ Mage::helper('ddg')->log($message)
31
+ ->rayLog($message);
32
+ }
33
+ } else {
34
+ Mage::helper('ddg')->log('Dynamic : order_id missing :' . $orderId);
35
+ }
36
+ }
37
+
38
+ parent::preDispatch();
39
+ }
40
+
41
+ /**
42
+ * Related products.
43
+ */
44
+ public function relatedAction()
45
+ {
46
+ $this->loadLayout();
47
+
48
+ $this->renderLayout();
49
+ }
50
+
51
+ /**
52
+ * Crosssell products.
53
+ */
54
+ public function crosssellAction()
55
+ {
56
+ $this->loadLayout();
57
+
58
+ $this->renderLayout();
59
+ }
60
+
61
+ /**
62
+ * Upsell products.
63
+ */
64
+ public function upsellAction()
65
+ {
66
+ $this->loadLayout();
67
+
68
+ $this->renderLayout();
69
+ }
70
+
71
+ /**
72
+ * Products that are set to manually push as related.
73
+ */
74
+ public function pushAction()
75
+ {
76
+ $this->loadLayout();
77
+
78
+ $this->renderLayout();
79
+ }
80
+
81
+ /**
82
+ * Nosto recommendation action.
83
+ */
84
+ public function nostoAction()
85
+ {
86
+ $this->loadLayout();
87
+
88
+ $html = $this->getLayout()->getBlock('connector_nosto_recommended')->toHtml();
89
+
90
+ //if empty than display our fallback products instead.
91
+ if (empty($html)) {
92
+ Mage::app()->getRequest()->setActionName('push');
93
+ $this->pushAction();
94
+ } else {
95
+ $this->renderLayout();
96
+ }
97
+ }
98
+
99
+ }
app/code/community/Dotdigitalgroup/Email/controllers/QuoteproductsController.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once 'Dotdigitalgroup' . DS . 'Email' . DS . 'controllers' . DS . 'ResponseController.php';
3
+
4
+ class Dotdigitalgroup_Email_QuoteproductsController extends Dotdigitalgroup_Email_ResponseController
5
+ {
6
+ /**
7
+ * @return Mage_Core_Controller_Front_Action|void
8
+ */
9
+ public function preDispatch()
10
+ {
11
+ //authenticate
12
+ $this->authenticate();
13
+ if ($this->getRequest()->getActionName() != 'push') {
14
+ $quoteId = $this->getRequest()->getParam('quote_id', false);
15
+ //check for quote id param
16
+ if ($quoteId) {
17
+ //check if quote exists
18
+ $quote = Mage::getModel('sales/quote')->load($quoteId);
19
+ if ($quote->getId()) {
20
+ Mage::register('current_quote', $quote);
21
+ //start app emulation
22
+ $storeId = $quote->getStoreId();
23
+ $appEmulation = Mage::getSingleton('core/app_emulation');
24
+ $appEmulation->startEnvironmentEmulation($storeId);
25
+ } else {
26
+ $message = 'Dynamic : Quote not found: ' . $quoteId;
27
+ Mage::helper('ddg')->log($message)
28
+ ->rayLog($message);
29
+ }
30
+ } else {
31
+ Mage::helper('ddg')->log('Dynamic : order_id missing :' . $quoteId);
32
+ }
33
+ }
34
+
35
+ parent::preDispatch();
36
+ }
37
+
38
+ /**
39
+ * Related products.
40
+ */
41
+ public function relatedAction()
42
+ {
43
+ $this->loadLayout();
44
+
45
+ $this->renderLayout();
46
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
47
+ }
48
+
49
+ /**
50
+ * Crosssell products.
51
+ */
52
+ public function crosssellAction()
53
+ {
54
+ $this->loadLayout();
55
+
56
+ $this->renderLayout();
57
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
58
+ }
59
+
60
+ /**
61
+ * Upsell products.
62
+ */
63
+ public function upsellAction()
64
+ {
65
+ $this->loadLayout();
66
+ $this->renderLayout();
67
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
68
+ }
69
+ }
app/code/community/Dotdigitalgroup/Email/controllers/ReportController.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $this->renderLayout();
24
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
25
+ }
26
+
27
+ /**
28
+ * Most viewed report.
29
+ */
30
+ public function mostviewedAction()
31
+ {
32
+ $this->loadLayout();
33
+ $this->renderLayout();
34
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
35
+ }
36
+
37
+ /**
38
+ * Recently viewed products for customer.
39
+ */
40
+ public function recentlyviewedAction()
41
+ {
42
+ //customer id param
43
+ $customerId = $this->getRequest()->getParam('customer_id', false);
44
+ //no customer was found
45
+ if (! $customerId) {
46
+
47
+ Mage::helper('ddg')->log('Recentlyviewed : no customer id : ' . $customerId);
48
+ $this->sendResponse();
49
+ Mage::throwException('Recentlyviewed, customer not set');
50
+ }
51
+ $this->loadLayout();
52
+ $this->renderLayout();
53
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
54
+ }
55
+ }
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
+ Mage::throwException('Authentication failed!');
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/WishlistController.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $this->renderLayout();
13
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
14
+ }
15
+
16
+ /**
17
+ * Crosssell products.
18
+ */
19
+ public function crosssellAction()
20
+ {
21
+ $this->loadLayout();
22
+ $this->renderLayout();
23
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
24
+ }
25
+
26
+ /**
27
+ * Upsell products.
28
+ */
29
+ public function upsellAction()
30
+ {
31
+ $this->loadLayout();
32
+ $this->renderLayout();
33
+ $this->checkContentNotEmpty($this->getLayout()->getOutput());
34
+ }
35
+ }
app/code/community/Dotdigitalgroup/Email/etc/adminhtml.xml ADDED
@@ -0,0 +1,210 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <menu>
4
+ <email_connector translate="title">
5
+ <title>Marketing Automation</title>
6
+ <sort_order>70</sort_order>
7
+ <children>
8
+ <email_connector_dashboard translate="title">
9
+ <title>Dashboard</title>
10
+ <sort_order>10</sort_order>
11
+ <action>adminhtml/email_dashboard</action>
12
+ </email_connector_dashboard>
13
+ <automation_studio translate="title">
14
+ <title>Automation Studio</title>
15
+ <sort_order>20</sort_order>
16
+ <action>adminhtml/email_studio</action>
17
+ </automation_studio>
18
+ <automation_rules translate="title">
19
+ <title>Exclusion Rules</title>
20
+ <sort_order>25</sort_order>
21
+ <action>adminhtml/email_rules</action>
22
+ </automation_rules>
23
+ <reports translate="title">
24
+ <title>Reports</title>
25
+ <sort_order>30</sort_order>
26
+ <children>
27
+ <email_connector_contact translate="title">
28
+ <title>Contacts Sync</title>
29
+ <sort_order>10</sort_order>
30
+ <action>adminhtml/email_contact</action>
31
+ </email_connector_contact>
32
+ <email_connector_order translate="title">
33
+ <title>Orders Sync</title>
34
+ <sort_order>20</sort_order>
35
+ <action>adminhtml/email_order</action>
36
+ </email_connector_order>
37
+ <email_connector_quote translate="title">
38
+ <title>Quote Sync</title>
39
+ <sort_order>30</sort_order>
40
+ <action>adminhtml/email_quote</action>
41
+ </email_connector_quote>
42
+ <email_connector_review translate="title">
43
+ <title>Review Sync</title>
44
+ <sort_order>40</sort_order>
45
+ <action>adminhtml/email_review</action>
46
+ </email_connector_review>
47
+ <email_connector_wishlist translate="title">
48
+ <title>Wishlist Sync</title>
49
+ <sort_order>50</sort_order>
50
+ <action>adminhtml/email_wishlist</action>
51
+ </email_connector_wishlist>
52
+ <email_connector_catalog translate="title">
53
+ <title>Catalog Sync</title>
54
+ <sort_order>60</sort_order>
55
+ <action>adminhtml/email_catalog</action>
56
+ </email_connector_catalog>
57
+ <email_connector_importer>
58
+ <title>Importer Status</title>
59
+ <sort_order>70</sort_order>
60
+ <action>adminhtml/email_importer</action>
61
+ </email_connector_importer>
62
+ <email_connector_campaign translate="title">
63
+ <title>Email Send Status</title>
64
+ <sort_order>80</sort_order>
65
+ <action>adminhtml/email_campaign</action>
66
+ </email_connector_campaign>
67
+ <email_connector_automation translate="title">
68
+ <title>Automation Status</title>
69
+ <sort_order>90</sort_order>
70
+ <action>adminhtml/email_automation</action>
71
+ </email_connector_automation>
72
+ </children>
73
+ </reports>
74
+ <email_configuration translate="title">
75
+ <title>Configuration</title>
76
+ <sort_order>40</sort_order>
77
+ <children>
78
+ <api_credentials translate="title">
79
+ <title>Api Credentials</title>
80
+ <sort_order>20</sort_order>
81
+ <action>adminhtml/system_config/edit/section/connector_api_credentials</action>
82
+ </api_credentials>
83
+ <data_mapping translate="title">
84
+ <title>Data Mapping</title>
85
+ <sort_order>30</sort_order>
86
+ <action>adminhtml/system_config/edit/section/connector_data_mapping</action>
87
+ </data_mapping>
88
+ <sync_settings translate="title">
89
+ <title>Sync Settings</title>
90
+ <sort_order>40</sort_order>
91
+ <action>adminhtml/system_config/edit/section/connector_sync_settings</action>
92
+ </sync_settings>
93
+ </children>
94
+ </email_configuration>
95
+ </children>
96
+ </email_connector>
97
+ </menu>
98
+ <acl>
99
+ <resources>
100
+ <admin>
101
+ <children>
102
+ <email_connector>
103
+ <title>DDG Automation</title>
104
+ <children>
105
+ <email_connector_dashboard translate="title">
106
+ <title>Dashboard</title>
107
+ </email_connector_dashboard>
108
+ <automation_studio translate="title">
109
+ <title>Automation Studio</title>
110
+ </automation_studio>
111
+ <automation_rules translate="title">
112
+ <title>Exclusion Rules</title>
113
+ </automation_rules>
114
+ <reports>
115
+ <title>Reports</title>
116
+ <children>
117
+ <email_connector_order translate="title">
118
+ <title>Email Connector Orders</title>
119
+ </email_connector_order>
120
+ <email_connector_campaign translate="title">
121
+ <title>Email Connector Campaigns</title>
122
+ </email_connector_campaign>
123
+ <email_connector_contact translate="title">
124
+ <title>Email Connector Contacts</title>
125
+ </email_connector_contact>
126
+ <email_connector_review translate="title">
127
+ <title>Email Connector Reviews</title>
128
+ </email_connector_review>
129
+ <email_connector_wishlist translate="title">
130
+ <title>Email Connector Wishlist</title>
131
+ </email_connector_wishlist>
132
+ <email_connector_quote translate="title">
133
+ <title>Email Connector Quote</title>
134
+ </email_connector_quote>
135
+ <email_connector_catalog translate="title">
136
+ <title>Email Connector Catalog</title>
137
+ </email_connector_catalog>
138
+ <email_connector_importer translate="title">
139
+ <title>Email Connector Importer</title>
140
+ </email_connector_importer>
141
+ <email_connector_automation translate="title">
142
+ <title>Email Automation Status</title>
143
+ </email_connector_automation>
144
+ </children>
145
+ </reports>
146
+ <email_configuration translate="title">
147
+ <title>Email Configuration</title>
148
+ <children>
149
+ <api_credentials translate="title">
150
+ <title>Api Credentials</title>
151
+ </api_credentials>
152
+ <data_mapping translate="title">
153
+ <title>Data Mapping</title>
154
+ </data_mapping>
155
+ <sync_settings translate="title">
156
+ <title>Sync Settings</title>
157
+ </sync_settings>
158
+ </children>
159
+ </email_configuration>
160
+ </children>
161
+ </email_connector>
162
+ <system>
163
+ <children>
164
+ <config>
165
+ <children>
166
+ <connector_api_credentials translate="title">
167
+ <title><![CDATA[Email API Credentials]]></title>
168
+ </connector_api_credentials>
169
+ <connector_sync_settings translate="title">
170
+ <title><![CDATA[Email Sync Settings]]></title>
171
+ </connector_sync_settings>
172
+ <connector_data_mapping translate="title">
173
+ <title><![CDATA[Email Data Field Mapping]]></title>
174
+ </connector_data_mapping>
175
+ <connector_roi_tracking translate="title">
176
+ <title><![CDATA[Email ROI & Tracking]]></title>
177
+ </connector_roi_tracking>
178
+ <connector_lost_baskets translate="title">
179
+ <title><![CDATA[Email Abandoned Carts]]></title>
180
+ </connector_lost_baskets>
181
+ <connector_reviews translate="title">
182
+ <title><![CDATA[Reviews]]></title>
183
+ </connector_reviews>
184
+ <connector_sms translate="title">
185
+ <title><![CDATA[Email SMS Section]]></title>
186
+ </connector_sms>
187
+ <connector_dynamic_content translate="title">
188
+ <title><![CDATA[Email Dynamic Content]]></title>
189
+ </connector_dynamic_content>
190
+ <connector_transactional_emails translate="title">
191
+ <title><![CDATA[Email Transactional Email]]></title>
192
+ </connector_transactional_emails>
193
+ <connector_automation_studio translate="title">
194
+ <title><![CDATA[Email Automation Studio]]></title>
195
+ </connector_automation_studio>
196
+ <connector_configuration translate="title">
197
+ <title><![CDATA[Email Configuration]]></title>
198
+ </connector_configuration>
199
+ <connector_developer_settings translate="title">
200
+ <title><![CDATA[Email Developer]]></title>
201
+ </connector_developer_settings>
202
+ </children>
203
+ </config>
204
+ </children>
205
+ </system>
206
+ </children>
207
+ </admin>
208
+ </resources>
209
+ </acl>
210
+ </config>
app/code/community/Dotdigitalgroup/Email/etc/api2.xml ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <api2>
4
+ <resource_groups>
5
+ <ddg_automation translate="title" module="api2">
6
+ <title>DDG Automation</title>
7
+ </ddg_automation>
8
+ </resource_groups>
9
+ <resources>
10
+ <ddg_create translate="title" module="api2">
11
+ <group>ddg_automation</group>
12
+ <model>ddg_automation/api2_subscriber</model>
13
+ <working_model>ddg_automation/api2_subscriber</working_model>
14
+ <title>Subscriber</title>
15
+ <sort_order>10</sort_order>
16
+ <privileges>
17
+ <admin>
18
+ <retrieve>1</retrieve>
19
+ <create>1</create>
20
+ <update>1</update>
21
+ </admin>
22
+ </privileges>
23
+ <attributes>
24
+ <customer_id>Customer Id</customer_id>
25
+ <store_id>Store Id</store_id>
26
+ <subscriber_email>Subscriber Email</subscriber_email>
27
+ <subscriber_status>Subscriber Status</subscriber_status>
28
+ </attributes>
29
+ <routes>
30
+ <route_entity>
31
+ <route>/ddg/subscriber/:email</route>
32
+ <action_type>entity</action_type>
33
+ </route_entity>
34
+ <route_collection>
35
+ <route>/ddg/subscriber/</route>
36
+ <action_type>collection</action_type>
37
+ </route_collection>
38
+ </routes>
39
+ <versions>1</versions>
40
+ </ddg_create>
41
+ </resources>
42
+ </api2>
43
+ </config>
app/code/community/Dotdigitalgroup/Email/etc/config.xml ADDED
@@ -0,0 +1,781 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Dotdigitalgroup_Email>
5
+ <version>5.1.0</version>
6
+ </Dotdigitalgroup_Email>
7
+ </modules>
8
+ <frontend>
9
+ <routers>
10
+ <ddg_automation>
11
+ <use>standard</use>
12
+ <args>
13
+ <module>Dotdigitalgroup_Email</module>
14
+ <frontName>connector</frontName>
15
+ </args>
16
+ </ddg_automation>
17
+ </routers>
18
+ <secure_url>
19
+ <connector_customer_newsletter_save>/connector/customer_newsletter/save</connector_customer_newsletter_save>
20
+ </secure_url>
21
+ <layout>
22
+ <updates>
23
+ <ddg_automation>
24
+ <file>connector.xml</file>
25
+ </ddg_automation>
26
+ </updates>
27
+ </layout>
28
+ <events>
29
+             <controller_action_postdispatch>
30
+                 <observers>
31
+                     <ddg_switcher>
32
+                         <class>ddg_automation/controller_observer</class>
33
+                         <method>controllerActionPostdispatch</method>
34
+                     </ddg_switcher>
35
+                 </observers>
36
+             </controller_action_postdispatch>
37
+         </events>
38
+ </frontend>
39
+ <global>
40
+ <resources>
41
+ <email_connector_setup>
42
+ <setup>
43
+ <module>Dotdigitalgroup_Email</module>
44
+ <class>ddg_automation/resource_setup</class>
45
+ </setup>
46
+ </email_connector_setup>
47
+ </resources>
48
+ <events>
49
+ <enterprise_customersegment_ids_changed>
50
+ <observers>
51
+ <ddg_customersegment_changed>
52
+ <class>ddg_automation/adminhtml_observer</class>
53
+ <method>connectorCustomerSegmentChanged</method>
54
+ </ddg_customersegment_changed>
55
+ </observers>
56
+ </enterprise_customersegment_ids_changed>
57
+ </events>
58
+ <models>
59
+ <ddg_automation>
60
+ <class>Dotdigitalgroup_Email_Model</class>
61
+ <resourceModel>email_connector_resource</resourceModel>
62
+ </ddg_automation>
63
+ <email_connector_resource>
64
+ <class>Dotdigitalgroup_Email_Model_Resource</class>
65
+ <entities>
66
+ <order>
67
+ <table>email_order</table>
68
+ </order>
69
+ <contact>
70
+ <table>email_contact</table>
71
+ </contact>
72
+ <campaign>
73
+ <table>email_campaign</table>
74
+ </campaign>
75
+ <create>
76
+ <table>email_create</table>
77
+ </create>
78
+ <config>
79
+ <table>email_config</table>
80
+ </config>
81
+ <review>
82
+ <table>email_review</table>
83
+ </review>
84
+ <wishlist>
85
+ <table>email_wishlist</table>
86
+ </wishlist>
87
+ <quote>
88
+ <table>email_quote</table>
89
+ </quote>
90
+ <automation>
91
+ <table>email_automation</table>
92
+ </automation>
93
+ <catalog>
94
+ <table>email_catalog</table>
95
+ </catalog>
96
+ <rules>
97
+ <table>email_rules</table>
98
+ </rules>
99
+ <importer>
100
+ <table>email_importer</table>
101
+ </importer>
102
+ </entities>
103
+ </email_connector_resource>
104
+ <newsletter>
105
+ <rewrite>
106
+ <subscriber>Dotdigitalgroup_Email_Model_Newsletter_Sub</subscriber>
107
+ </rewrite>
108
+ </newsletter>
109
+ <customer>
110
+ <rewrite>
111
+ <customer>Dotdigitalgroup_Email_Model_Customer</customer>
112
+ </rewrite>
113
+ </customer>
114
+ <enterprise_customersegment_resource>
115
+ <rewrite>
116
+ <segment>Dotdigitalgroup_Email_Model_Resource_Segment</segment>
117
+ </rewrite>
118
+ </enterprise_customersegment_resource>
119
+ <core>
120
+ <rewrite>
121
+ <email_template>Dotdigitalgroup_Email_Model_Email_Template</email_template>
122
+ <email>Dotdigitalgroup_Email_Model_Email</email>
123
+ </rewrite>
124
+ </core>
125
+ </models>
126
+ <helpers>
127
+ <ddg>
128
+ <class>Dotdigitalgroup_Email_Helper</class>
129
+ </ddg>
130
+ </helpers>
131
+ <blocks>
132
+ <ddg_automation>
133
+ <class>Dotdigitalgroup_Email_Block</class>
134
+ </ddg_automation>
135
+ <adminhtml>
136
+ <rewrite>
137
+ <system_email_template_edit>ddg_automation/system_email_template_edit</system_email_template_edit>
138
+ </rewrite>
139
+ </adminhtml>
140
+ </blocks>
141
+ <events>
142
+ <admin_system_config_changed_section_connector_api_credentials>
143
+ <observers>
144
+ <ddg_api_save>
145
+ <class>ddg_automation/adminhtml_observer</class>
146
+ <method>actionConfigSaveApi</method>
147
+ </ddg_api_save>
148
+ </observers>
149
+ </admin_system_config_changed_section_connector_api_credentials>
150
+ <admin_system_config_changed_section_connector_data_mapping>
151
+ <observers>
152
+ <ddg_data_mapping_reset>
153
+ <class>ddg_automation/adminhtml_observer</class>
154
+ <method>actionConfigResetContacts</method>
155
+ </ddg_data_mapping_reset>
156
+ </observers>
157
+ </admin_system_config_changed_section_connector_data_mapping>
158
+ <admin_system_config_changed_section_connector_sync_settings>
159
+ <observers>
160
+ <ddg_sys_check_feature_active>
161
+ <class>ddg_automation/adminhtml_observer</class>
162
+ <method>checkFeatureActive</method>
163
+ </ddg_sys_check_feature_active>
164
+ </observers>
165
+ </admin_system_config_changed_section_connector_sync_settings>
166
+ <customer_save_after>
167
+ <observers>
168
+ <ddg_customer_save_after>
169
+ <class>ddg_automation/customer_observer</class>
170
+ <method>handleCustomerSaveAfter</method>
171
+ </ddg_customer_save_after>
172
+ </observers>
173
+ </customer_save_after>
174
+ <customer_register_success>
175
+ <observers>
176
+ <ddg_customer_register_success>
177
+ <type>singleton</type>
178
+ <class>ddg_automation/customer_observer</class>
179
+ <method>handleCustomerRegiterSuccess</method>
180
+ </ddg_customer_register_success>
181
+ </observers>
182
+ </customer_register_success>
183
+ <customer_delete_after>
184
+ <observers>
185
+ <ddg_customer_delete_after>
186
+ <class>ddg_automation/customer_observer</class>
187
+ <method>handleCustomerDeleteAfter</method>
188
+ </ddg_customer_delete_after>
189
+ </observers>
190
+ </customer_delete_after>
191
+ <newsletter_subscriber_save_before>
192
+ <observers>
193
+ <ddg_newsletter_subscriber_save_before>
194
+ <class>ddg_automation/newsletter_observer</class>
195
+ <method>handleNewsletterSubscriberSave</method>
196
+ </ddg_newsletter_subscriber_save_before>
197
+ </observers>
198
+ </newsletter_subscriber_save_before>
199
+ <sales_order_place_after>
200
+ <observers>
201
+ <ddg_record_sale>
202
+ <type>singleton</type>
203
+ <class>ddg_automation/sales_observer</class>
204
+ <method>handleSalesOrderPlaceAfter</method>
205
+ </ddg_record_sale>
206
+ </observers>
207
+ </sales_order_place_after>
208
+ <sales_order_save_after>
209
+ <observers>
210
+ <ddg_checkout_type_onepage_save_order_after>
211
+ <class>ddg_automation/sales_observer</class>
212
+ <method>handleSalesOrderSaveAfter</method>
213
+ </ddg_checkout_type_onepage_save_order_after>
214
+ </observers>
215
+ </sales_order_save_after>
216
+ <sales_order_creditmemo_save_after>
217
+ <observers>
218
+ <ddg_sales_order_payment_refund>
219
+ <class>ddg_automation/sales_observer</class>
220
+ <method>handleSalesOrderRefund</method>
221
+ </ddg_sales_order_payment_refund>
222
+ </observers>
223
+ </sales_order_creditmemo_save_after>
224
+ <order_cancel_after>
225
+ <observers>
226
+ <ddg_sales_order_cancel>
227
+ <class>ddg_automation/sales_observer</class>
228
+ <method>hangleSalesOrderCancel</method>
229
+ </ddg_sales_order_cancel>
230
+ </observers>
231
+ </order_cancel_after>
232
+ <rewards_points_indexer_update>
233
+ <observers>
234
+ <ddg_rewards_points_indexer_update>
235
+ <class>ddg_automation/sweettooth_observer</class>
236
+ <method>ConnectorRewardsPointsIndexerUpdate</method>
237
+ </ddg_rewards_points_indexer_update>
238
+ </observers>
239
+ </rewards_points_indexer_update>
240
+ <review_save_after>
241
+ <observers>
242
+ <ddg_review_save_after>
243
+ <class>ddg_automation/customer_observer</class>
244
+ <method>reviewSaveAfter</method>
245
+ </ddg_review_save_after>
246
+ </observers>
247
+ </review_save_after>
248
+ <model_save_after>
249
+ <observers>
250
+ <ddg_wishlist_save_after>
251
+ <class>ddg_automation/customer_observer</class>
252
+ <method>wishlistSaveAfter</method>
253
+ </ddg_wishlist_save_after>
254
+ </observers>
255
+ </model_save_after>
256
+ <wishlist_item_save_after>
257
+ <observers>
258
+ <ddg_wishlist_item_save_after>
259
+ <class>ddg_automation/customer_observer</class>
260
+ <method>wishlistItemSaveAfter</method>
261
+ </ddg_wishlist_item_save_after>
262
+ </observers>
263
+ </wishlist_item_save_after>
264
+ <wishlist_delete_after>
265
+ <observers>
266
+ <ddg_wishlist_delete_after>
267
+ <class>ddg_automation/customer_observer</class>
268
+ <method>wishlistDeleteAfter</method>
269
+ </ddg_wishlist_delete_after>
270
+ </observers>
271
+ </wishlist_delete_after>
272
+ <wishlist_item_delete_after>
273
+ <observers>
274
+ <ddg_wishlist_item_delete_after>
275
+ <class>ddg_automation/customer_observer</class>
276
+ <method>wishlistItemSaveAfter</method>
277
+ </ddg_wishlist_item_delete_after>
278
+ </observers>
279
+ </wishlist_item_delete_after>
280
+ <sales_convert_quote_to_order>
281
+ <observers>
282
+ <ddg_quote_to_order>
283
+ <class>ddg_automation/sales_observer</class>
284
+ <method>handleQuoteToOrder</method>
285
+ </ddg_quote_to_order>
286
+ </observers>
287
+ </sales_convert_quote_to_order>
288
+ <sales_quote_save_after>
289
+ <observers>
290
+ <ddg_sales_quote_save_after>
291
+ <class>ddg_automation/sales_observer</class>
292
+ <method>handleQuoteSaveAfter</method>
293
+ </ddg_sales_quote_save_after>
294
+ </observers>
295
+ </sales_quote_save_after>
296
+ <catalog_product_save_after>
297
+ <observers>
298
+ <ddg_catalog_product_save_after>
299
+ <class>ddg_automation/catalog</class>
300
+ <method>handleProductSaveAfter</method>
301
+ </ddg_catalog_product_save_after>
302
+ </observers>
303
+ </catalog_product_save_after>
304
+ <catalog_product_delete_after>
305
+ <observers>
306
+ <ddg_catalog_product_delete_after>
307
+ <class>ddg_automation/catalog</class>
308
+ <method>handleProductDeleteAfter</method>
309
+ </ddg_catalog_product_delete_after>
310
+ </observers>
311
+ </catalog_product_delete_after>
312
+ <core_config_data_save_before>
313
+ <observers>
314
+ <ddg_core_config_data_save_before>
315
+ <class>ddg_automation/catalog</class>
316
+ <method>handleConfigSaveBefore</method>
317
+ </ddg_core_config_data_save_before>
318
+ </observers>
319
+ </core_config_data_save_before>
320
+ <core_config_data_save_after>
321
+ <observers>
322
+ <ddg_core_config_data_save_after>
323
+ <class>ddg_automation/catalog</class>
324
+ <method>handleConfigSaveAfter</method>
325
+ </ddg_core_config_data_save_after>
326
+ </observers>
327
+ </core_config_data_save_after>
328
+ </events>
329
+ </global>
330
+ <adminhtml>
331
+ <layout>
332
+ <updates>
333
+ <ddg_automation>
334
+ <file>connector/email.xml</file>
335
+ </ddg_automation>
336
+ </updates>
337
+ </layout>
338
+ <events>
339
+ <controller_action_predispatch>
340
+ <observers>
341
+ <ddg_feed>
342
+ <type>singleton</type>
343
+ <class>ddg_automation/adminhtml_observer</class>
344
+ <method>updateFeed</method>
345
+ </ddg_feed>
346
+ </observers>
347
+ </controller_action_predispatch>
348
+ </events>
349
+ <translate>
350
+ <modules>
351
+ <Dotdigitalgroup_Email>
352
+ <files>
353
+ <default>Dotdigitalgroup_Email.csv</default>
354
+ </files>
355
+ </Dotdigitalgroup_Email>
356
+ </modules>
357
+ </translate>
358
+ </adminhtml>
359
+ <admin>
360
+ <routers>
361
+ <adminhtml>
362
+ <args>
363
+ <modules>
364
+ <Dotdigitalgroup_Email before="Mage_Adminhtml">Dotdigitalgroup_Email_Adminhtml</Dotdigitalgroup_Email>
365
+ </modules>
366
+ </args>
367
+ </adminhtml>
368
+ </routers>
369
+ </admin>
370
+ <crontab>
371
+ <jobs>
372
+ <ddg_automation_customer_subscriber_guest_sync>
373
+ <run><model>ddg_automation/cron::contactSync</model></run>
374
+ <schedule>
375
+ <config_path>connector_developer_settings/cron_schedules/contact</config_path>
376
+ </schedule>
377
+ </ddg_automation_customer_subscriber_guest_sync>
378
+ <ddg_automation_status>
379
+ <run><model>ddg_automation/cron::automationStatus</model></run>
380
+ <schedule>
381
+ <cron_expr>*/15 * * * *</cron_expr>
382
+ </schedule>
383
+ </ddg_automation_status>
384
+ <ddg_automation_abandonedcarts>
385
+ <run><model>ddg_automation/cron::abandonedCarts</model></run>
386
+ <schedule>
387
+ <cron_expr>*/5 * * * *</cron_expr>
388
+ </schedule>
389
+ </ddg_automation_abandonedcarts>
390
+ <ddg_automation_reviews_and_wishlist>
391
+ <run>
392
+ <model>ddg_automation/cron::reviewsAndWishlist</model>
393
+ </run>
394
+ <schedule>
395
+ <config_path>connector_developer_settings/cron_schedules/review_wishlist</config_path>
396
+ </schedule>
397
+ </ddg_automation_reviews_and_wishlist>
398
+ <ddg_automation_campaign>
399
+ <run>
400
+ <model>ddg_automation/cron::sendEmails</model>
401
+ </run>
402
+ <schedule>
403
+ <cron_expr>*/5 * * * *</cron_expr>
404
+ </schedule>
405
+ </ddg_automation_campaign>
406
+ <ddg_automation_order_and_quote_sync>
407
+ <run><model>ddg_automation/cron::orderAndQuoteSync</model></run>
408
+ <schedule>
409
+ <config_path>connector_developer_settings/cron_schedules/order_quote</config_path>
410
+ </schedule>
411
+ </ddg_automation_order_and_quote_sync>
412
+ <ddg_automation_cleaner>
413
+ <run><model>ddg_automation/cron::cleaning</model></run>
414
+ <schedule>
415
+ <cron_expr>0 0 1 * * </cron_expr>
416
+ </schedule>
417
+ </ddg_automation_cleaner>
418
+ <ddg_automation_catalog_sync>
419
+ <run><model>ddg_automation/cron::catalogSync</model></run>
420
+ <schedule>
421
+ <config_path>connector_developer_settings/cron_schedules/catalog</config_path>
422
+ </schedule>
423
+ </ddg_automation_catalog_sync>
424
+ <ddg_automation_importer>
425
+ <run>
426
+ <model>ddg_automation/cron::emailImporter</model>
427
+ </run>
428
+ <schedule>
429
+ <config_path>connector_developer_settings/cron_schedules/importer</config_path>
430
+ </schedule>
431
+ </ddg_automation_importer>
432
+ </jobs>
433
+ </crontab>
434
+ <default>
435
+ <connector_api_credentials>
436
+ <api>
437
+ <enabled>0</enabled>
438
+ <username></username>
439
+ <password></password>
440
+ </api>
441
+ </connector_api_credentials>
442
+ <connector_sync_settings>
443
+ <address_book>
444
+ <customers>0</customers>
445
+ <subscribers>0</subscribers>
446
+ <guests>0</guests>
447
+ </address_book>
448
+ <sync>
449
+ <contact_enabled>0</contact_enabled>
450
+ <guest_enabled>0</guest_enabled>
451
+ <subscriber_enabled>0</subscriber_enabled>
452
+ <order_enabled>0</order_enabled>
453
+ <wishlist_enabled>0</wishlist_enabled>
454
+ <review_enabled>0</review_enabled>
455
+ <quote_enabled>0</quote_enabled>
456
+ <catalog_enabled>0</catalog_enabled>
457
+ </sync>
458
+ <dynamic_addressbook>
459
+ <addressbook_name></addressbook_name>
460
+ <visibility></visibility>
461
+ </dynamic_addressbook>
462
+ </connector_sync_settings>
463
+ <connector_lost_baskets>
464
+ <customers>
465
+ <enabled_1>0</enabled_1>
466
+ <send_after_1></send_after_1>
467
+ <campaign_1></campaign_1>
468
+ <enabled_2>0</enabled_2>
469
+ <send_after_2></send_after_2>
470
+ <campaign_2></campaign_2>
471
+ <enabled_3>0</enabled_3>
472
+ <send_after_3></send_after_3>
473
+ <campaign_3></campaign_3>
474
+ </customers>
475
+ <guests>
476
+ <enabled_1>0</enabled_1>
477
+ <send_after_1></send_after_1>
478
+ <campaign_1></campaign_1>
479
+ <enabled_2>0</enabled_2>
480
+ <send_after_2></send_after_2>
481
+ <campaign_2></campaign_2>
482
+ <enabled_3>0</enabled_3>
483
+ <send_after_3></send_after_3>
484
+ <