Datafield.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. <?php
  2. namespace Dotdigitalgroup\Email\Model\Connector;
  3. /**
  4. * Contact datafields information.
  5. *
  6. */
  7. class Datafield
  8. {
  9. /**
  10. * @var string
  11. */
  12. public $name;
  13. /**
  14. * @var string
  15. */
  16. public $type;
  17. /**
  18. * @var string
  19. */
  20. public $visibility;
  21. /**
  22. * @var string
  23. */
  24. public $defaultValue;
  25. /**
  26. * Contact datafields.
  27. *
  28. * @var array
  29. */
  30. public $datafields = [];
  31. /**
  32. * Contact default datafields.
  33. *
  34. * @var array
  35. */
  36. public $contactDatafields
  37. = [
  38. 'customer_id' => [
  39. 'name' => 'CUSTOMER_ID',
  40. 'type' => 'numeric',
  41. 'visibility' => 'private',
  42. ],
  43. 'firstname' => [
  44. 'name' => 'FIRSTNAME',
  45. 'type' => 'string',
  46. 'visibility' => 'private',
  47. ],
  48. 'lastname' => [
  49. 'name' => 'LASTNAME',
  50. 'type' => 'string',
  51. 'visibility' => 'private',
  52. ],
  53. 'gender' => [
  54. 'name' => 'GENDER',
  55. 'type' => 'string',
  56. 'visibility' => 'private',
  57. ],
  58. 'dob' => [
  59. 'name' => 'DOB',
  60. 'type' => 'date',
  61. 'visibility' => 'private',
  62. ],
  63. 'title' => [
  64. 'name' => 'TITLE',
  65. 'type' => 'string',
  66. 'visibility' => 'private',
  67. ],
  68. 'website_name' => [
  69. 'name' => 'WEBSITE_NAME',
  70. 'type' => 'string',
  71. 'visibility' => 'private',
  72. ],
  73. 'store_name' => [
  74. 'name' => 'STORE_NAME',
  75. 'type' => 'string',
  76. 'visibility' => 'private',
  77. ],
  78. 'created_at' => [
  79. 'name' => 'ACCOUNT_CREATED_DATE',
  80. 'type' => 'date',
  81. 'visibility' => 'private',
  82. ],
  83. 'last_logged_date' => [
  84. 'name' => 'LAST_LOGGEDIN_DATE',
  85. 'type' => 'date',
  86. 'visibility' => 'private',
  87. ],
  88. 'customer_group' => [
  89. 'name' => 'CUSTOMER_GROUP',
  90. 'type' => 'string',
  91. 'visibility' => 'private',
  92. ],
  93. 'billing_address_1' => [
  94. 'name' => 'BILLING_ADDRESS_1',
  95. 'type' => 'string',
  96. 'visibility' => 'private',
  97. 'defaultValue' => '',
  98. ],
  99. 'billing_address_2' => [
  100. 'name' => 'BILLING_ADDRESS_2',
  101. 'type' => 'string',
  102. 'visibility' => 'private',
  103. ],
  104. 'billing_state' => [
  105. 'name' => 'BILLING_STATE',
  106. 'type' => 'string',
  107. 'visibility' => 'private',
  108. ],
  109. 'billing_city' => [
  110. 'name' => 'BILLING_CITY',
  111. 'type' => 'string',
  112. 'visibility' => 'private',
  113. ],
  114. 'billing_country' => [
  115. 'name' => 'BILLING_COUNTRY',
  116. 'type' => 'string',
  117. 'visibility' => 'private',
  118. ],
  119. 'billing_postcode' => [
  120. 'name' => 'BILLING_POSTCODE',
  121. 'type' => 'string',
  122. 'visibility' => 'private',
  123. ],
  124. 'billing_telephone' => [
  125. 'name' => 'BILLING_TELEPHONE',
  126. 'type' => 'string',
  127. 'visibility' => 'private',
  128. ],
  129. 'delivery_address_1' => [
  130. 'name' => 'DELIVERY_ADDRESS_1',
  131. 'type' => 'string',
  132. 'visibility' => 'private',
  133. ],
  134. 'delivery_address_2' => [
  135. 'name' => 'DELIVERY_ADDRESS_2',
  136. 'type' => 'string',
  137. 'visibility' => 'private',
  138. ],
  139. 'delivery_state' => [
  140. 'name' => 'DELIVERY_STATE',
  141. 'type' => 'string',
  142. 'visibility' => 'private',
  143. ],
  144. 'delivery_city' => [
  145. 'name' => 'DELIVERY_CITY',
  146. 'type' => 'string',
  147. 'visibility' => 'private',
  148. ],
  149. 'delivery_country' => [
  150. 'name' => 'DELIVERY_COUNTRY',
  151. 'type' => 'string',
  152. 'visibility' => 'private',
  153. ],
  154. 'delivery_postcode' => [
  155. 'name' => 'DELIVERY_POSTCODE',
  156. 'type' => 'string',
  157. 'visibility' => 'private',
  158. ],
  159. 'delivery_telephone' => [
  160. 'name' => 'DELIVERY_TELEPHONE',
  161. 'type' => 'string',
  162. 'visibility' => 'private',
  163. ],
  164. 'number_of_orders' => [
  165. 'name' => 'NUMBER_OF_ORDERS',
  166. 'type' => 'numeric',
  167. 'visibility' => 'private',
  168. ],
  169. 'total_spend' => [
  170. 'name' => 'TOTAL_SPEND',
  171. 'type' => 'numeric',
  172. 'visibility' => 'private',
  173. ],
  174. 'average_order_value' => [
  175. 'name' => 'AVERAGE_ORDER_VALUE',
  176. 'type' => 'numeric',
  177. 'visibility' => 'private',
  178. ],
  179. 'last_order_date' => [
  180. 'name' => 'LAST_ORDER_DATE',
  181. 'type' => 'date',
  182. 'visibility' => 'private',
  183. ],
  184. 'last_order_id' => [
  185. 'name' => 'LAST_ORDER_ID',
  186. 'type' => 'numeric',
  187. 'visibility' => 'private',
  188. ],
  189. 'last_increment_id' => [
  190. 'name' => 'LAST_INCREMENT_ID',
  191. 'type' => 'numeric',
  192. 'visibility' => 'private',
  193. ],
  194. 'last_quote_id' => [
  195. 'name' => 'LAST_QUOTE_ID',
  196. 'type' => 'numeric',
  197. 'visibility' => 'private',
  198. ],
  199. 'total_refund' => [
  200. 'name' => 'TOTAL_REFUND',
  201. 'type' => 'numeric',
  202. 'visibility' => 'private',
  203. ],
  204. 'review_count' => [
  205. 'name' => 'REVIEW_COUNT',
  206. 'type' => 'numeric',
  207. 'visibility' => 'private',
  208. ],
  209. 'last_review_date' => [
  210. 'name' => 'LAST_REVIEW_DATE',
  211. 'type' => 'date',
  212. 'visibility' => 'private',
  213. ],
  214. 'subscriber_status' => [
  215. 'name' => 'SUBSCRIBER_STATUS',
  216. 'type' => 'string',
  217. 'visibility' => 'private',
  218. ],
  219. 'most_pur_category' => [
  220. 'name' => 'MOST_PUR_CATEGORY',
  221. 'type' => 'string',
  222. 'visibility' => 'private',
  223. ],
  224. 'most_pur_brand' => [
  225. 'name' => 'MOST_PUR_BRAND',
  226. 'type' => 'string',
  227. 'visibility' => 'private',
  228. ],
  229. 'most_freq_pur_day' => [
  230. 'name' => 'MOST_FREQ_PUR_DAY',
  231. 'type' => 'string',
  232. 'visibility' => 'private',
  233. ],
  234. 'most_freq_pur_mon' => [
  235. 'name' => 'MOST_FREQ_PUR_MON',
  236. 'type' => 'string',
  237. 'visibility' => 'private',
  238. ],
  239. 'first_category_pur' => [
  240. 'name' => 'FIRST_CATEGORY_PUR',
  241. 'type' => 'string',
  242. 'visibility' => 'private',
  243. ],
  244. 'last_category_pur' => [
  245. 'name' => 'LAST_CATEGORY_PUR',
  246. 'type' => 'string',
  247. 'visibility' => 'private',
  248. ],
  249. 'first_brand_pur' => [
  250. 'name' => 'FIRST_BRAND_PUR',
  251. 'type' => 'string',
  252. 'visibility' => 'private',
  253. ],
  254. 'last_brand_pur' => [
  255. 'name' => 'LAST_BRAND_PUR',
  256. 'type' => 'string',
  257. 'visibility' => 'private',
  258. ],
  259. 'abandoned_prod_name' => [
  260. 'name' => 'ABANDONED_PROD_NAME',
  261. 'type' => 'string',
  262. 'visibility' => 'private',
  263. ],
  264. 'billing_company' => [
  265. 'name' => 'BILLING_COMPANY',
  266. 'type' => 'string',
  267. 'visibility' => 'private',
  268. ],
  269. 'delivery_company' => [
  270. 'name' => 'DELIVERY_COMPANY',
  271. 'type' => 'string',
  272. 'visibility' => 'private',
  273. ],
  274. ];
  275. /**
  276. * @var \Dotdigitalgroup\Email\Helper\Data
  277. */
  278. private $helper;
  279. /**
  280. * Datafield constructor.
  281. *
  282. * @param \Dotdigitalgroup\Email\Helper\Data $helper
  283. */
  284. public function __construct(
  285. \Dotdigitalgroup\Email\Helper\Data $helper
  286. ) {
  287. $this->helper = $helper;
  288. }
  289. /**
  290. * Set contact datafields.
  291. *
  292. * @param array $contactDatafields
  293. *
  294. * @return null
  295. */
  296. public function setContactDatafields($contactDatafields)
  297. {
  298. $this->contactDatafields = $contactDatafields;
  299. }
  300. /**
  301. * Get contact datafields.
  302. *
  303. * @return array
  304. */
  305. public function getContactDatafields()
  306. {
  307. $contactDataFields = $this->contactDatafields;
  308. $extraDataFields = $this->getExtraDataFields();
  309. if (! empty($extraDataFields)) {
  310. $contactDataFields = array_merge($extraDataFields, $contactDataFields);
  311. }
  312. return $contactDataFields;
  313. }
  314. /**
  315. * Set a single datafield.
  316. *
  317. * @param string $name
  318. * @param string|int|boolean $value
  319. * @param string $type
  320. * @param string $visibility
  321. *
  322. * @return array
  323. */
  324. public function setDatafield(
  325. $name,
  326. $value,
  327. $type = 'string',
  328. $visibility = 'private'
  329. ) {
  330. $this->datafields[] = [
  331. 'name' => $name,
  332. 'value' => $value,
  333. 'type' => $type,
  334. 'visibility' => $visibility,
  335. ];
  336. return $this->datafields;
  337. }
  338. /**
  339. * @return array
  340. */
  341. public function getExtraDataFields()
  342. {
  343. return [];
  344. }
  345. }