Review.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <?php
  2. namespace Dotdigitalgroup\Email\Model\Customer;
  3. /**
  4. * Transactional data for customer review.
  5. */
  6. class Review
  7. {
  8. /**
  9. * @var int
  10. */
  11. public $id;
  12. /**
  13. * @var int
  14. */
  15. public $customerId;
  16. /**
  17. * @var string
  18. */
  19. public $email;
  20. /**
  21. * @var string
  22. */
  23. public $productName;
  24. /**
  25. * @var string
  26. */
  27. public $productSku;
  28. /**
  29. * @var string
  30. */
  31. public $reviewDate;
  32. /**
  33. * @var string
  34. */
  35. public $websiteName;
  36. /**
  37. * @var string
  38. */
  39. public $storeName;
  40. /**
  41. * @var \Magento\Store\Model\StoreManagerInterface
  42. */
  43. public $storeManager;
  44. /**
  45. * @var \Dotdigitalgroup\Email\Helper\Data
  46. */
  47. public $helper;
  48. /**
  49. * Review constructor.
  50. *
  51. * @param \Dotdigitalgroup\Email\Helper\Data $data
  52. * @param \Magento\Store\Model\StoreManagerInterface $storeManagerInterface
  53. */
  54. public function __construct(
  55. \Dotdigitalgroup\Email\Helper\Data $data,
  56. \Magento\Store\Model\StoreManagerInterface $storeManagerInterface
  57. ) {
  58. $this->helper = $data;
  59. $this->storeManager = $storeManagerInterface;
  60. }
  61. /**
  62. * @param \Magento\Customer\Model\Customer $customer
  63. *
  64. * @return $this
  65. */
  66. public function setCustomer($customer)
  67. {
  68. $this->setCustomerId($customer->getId());
  69. $this->email = $customer->getEmail();
  70. return $this;
  71. }
  72. /**
  73. * @param int $customerId
  74. *
  75. * @return $this
  76. */
  77. public function setCustomerId($customerId)
  78. {
  79. $this->customerId = (int)$customerId;
  80. return $this;
  81. }
  82. /**
  83. * @return int
  84. */
  85. public function getCustomerId()
  86. {
  87. return (int)$this->customerId;
  88. }
  89. /**
  90. * @param int $id
  91. *
  92. * @return $this
  93. */
  94. public function setId($id)
  95. {
  96. $this->id = (int)$id;
  97. return $this;
  98. }
  99. /**
  100. * @return int
  101. */
  102. public function getId()
  103. {
  104. return (int)$this->id;
  105. }
  106. /**
  107. * Create rating on runtime.
  108. *
  109. * @param string $ratingName
  110. * @param \Dotdigitalgroup\Email\Model\Customer\Review\Rating $rating
  111. *
  112. * @return null
  113. */
  114. public function createRating($ratingName, $rating)
  115. {
  116. $this->$ratingName = $rating->expose();
  117. }
  118. /**
  119. * Set review date.
  120. *
  121. * @param string $date
  122. *
  123. * @return $this;
  124. */
  125. public function setReviewDate($date)
  126. {
  127. $this->reviewDate = $date;
  128. return $this;
  129. }
  130. /**
  131. * @return string
  132. */
  133. public function getReviewDate()
  134. {
  135. return $this->reviewDate;
  136. }
  137. /**
  138. * Set product.
  139. *
  140. * @param \Magento\Catalog\Model\Product $product
  141. * @return $this
  142. */
  143. public function setProduct(\Magento\Catalog\Model\Product $product)
  144. {
  145. $this->setProductName($product->getName());
  146. $this->setProductSku($product->getSku());
  147. return $this;
  148. }
  149. /**
  150. * Set review data.
  151. *
  152. * @param \Magento\Review\Model\Review $review
  153. * @return $this
  154. */
  155. public function setReviewData(\Magento\Review\Model\Review $review)
  156. {
  157. $store = $this->storeManager->getStore($review->getStoreId());
  158. $websiteName = $store->getWebsite()->getName();
  159. $storeName = $store->getName();
  160. $this->setId($review->getReviewId())
  161. ->setWebsiteName($websiteName)
  162. ->setStoreName($storeName)
  163. ->setReviewDate($review->getCreatedAt())
  164. ->setCustomerId($review->getCustomerId())
  165. ->setEmail($review->getEmail());
  166. return $this;
  167. }
  168. /**
  169. * Set product name.
  170. *
  171. * @param string $name
  172. *
  173. * @return null
  174. */
  175. public function setProductName($name)
  176. {
  177. $this->productName = $name;
  178. }
  179. /**
  180. * @return string
  181. */
  182. public function getProductName()
  183. {
  184. return $this->productName;
  185. }
  186. /**
  187. * Set product sku.
  188. *
  189. * @param string $sku
  190. *
  191. * @return null
  192. */
  193. public function setProductSku($sku)
  194. {
  195. $this->productSku = $sku;
  196. }
  197. /**
  198. * @return string
  199. */
  200. public function getProductSku()
  201. {
  202. return $this->productSku;
  203. }
  204. /**
  205. * Set website name.
  206. *
  207. * @param string $name
  208. *
  209. * @return $this
  210. */
  211. public function setWebsiteName($name)
  212. {
  213. $this->websiteName = $name;
  214. return $this;
  215. }
  216. /**
  217. * @return string
  218. */
  219. public function getStoreName()
  220. {
  221. return $this->storeName;
  222. }
  223. /**
  224. * Set store name.
  225. *
  226. * @param string $name
  227. *
  228. * @return $this
  229. */
  230. public function setStoreName($name)
  231. {
  232. $this->storeName = $name;
  233. return $this;
  234. }
  235. /**
  236. * @return string
  237. */
  238. public function getWebsiteName()
  239. {
  240. return $this->websiteName;
  241. }
  242. /**
  243. * Set email
  244. *
  245. * @param string $email
  246. *
  247. * @return $this
  248. */
  249. public function setEmail($email)
  250. {
  251. $this->email = $email;
  252. return $this;
  253. }
  254. /**
  255. * @return array
  256. */
  257. public function expose()
  258. {
  259. return array_diff_key(
  260. get_object_vars($this),
  261. array_flip(['storeManager', 'helper'])
  262. );
  263. }
  264. /**
  265. * @return array
  266. */
  267. public function __sleep()
  268. {
  269. $properties = array_keys(get_object_vars($this));
  270. $properties = array_diff($properties, ['storeManager', 'helper']);
  271. return $properties;
  272. }
  273. }