Wishlist.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. namespace Dotdigitalgroup\Email\Model\Customer;
  3. /**
  4. * Transactional data for customer wishlist.
  5. */
  6. class Wishlist
  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. * Wishlist items.
  22. *
  23. * @var array
  24. */
  25. public $items = [];
  26. /**
  27. * @var float
  28. */
  29. public $totalWishlistValue;
  30. /**
  31. * @var string
  32. */
  33. public $updatedAt;
  34. /**
  35. * @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface
  36. */
  37. private $localeDate;
  38. /**
  39. * Wishlist constructor.
  40. * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
  41. */
  42. public function __construct(
  43. \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
  44. ) {
  45. $this->localeDate = $localeDate;
  46. }
  47. /**
  48. * @param \Magento\Customer\Model\Customer $customer
  49. *
  50. * @return $this
  51. */
  52. public function setCustomer($customer)
  53. {
  54. $this->setCustomerId($customer->getId());
  55. $this->email = $customer->getEmail();
  56. return $this;
  57. }
  58. /**
  59. * @param int $customerId
  60. *
  61. * @return $this
  62. */
  63. public function setCustomerId($customerId)
  64. {
  65. $this->customerId = (int)$customerId;
  66. return $this;
  67. }
  68. /**
  69. * @return int
  70. */
  71. public function getCustomerId()
  72. {
  73. return (int)$this->customerId;
  74. }
  75. /**
  76. * @param int $id
  77. *
  78. * @return $this
  79. */
  80. public function setId($id)
  81. {
  82. $this->id = (int)$id;
  83. return $this;
  84. }
  85. /**
  86. * @return int
  87. */
  88. public function getId()
  89. {
  90. return (int)$this->id;
  91. }
  92. /**
  93. * Set wishlist item.
  94. *
  95. * @param \Dotdigitalgroup\Email\Model\Customer\Wishlist\Item $item
  96. *
  97. * @return null
  98. */
  99. public function setItem($item)
  100. {
  101. $this->items[] = $item->expose();
  102. $this->totalWishlistValue += $item->getTotalValueOfProduct();
  103. }
  104. /**
  105. * @return array
  106. */
  107. public function expose()
  108. {
  109. $properties = array_diff_key(
  110. get_object_vars($this),
  111. array_flip(['localeDate'])
  112. );
  113. //remove null/0/false values
  114. $properties = array_filter($properties);
  115. return $properties;
  116. }
  117. /**
  118. * Set wishlist date.
  119. *
  120. * @param string $date
  121. *
  122. * @return $this;
  123. */
  124. public function setUpdatedAt($date)
  125. {
  126. $date = $this->localeDate->date($date)
  127. ->format(\Zend_Date::ISO_8601);
  128. $this->updatedAt = $date;
  129. return $this;
  130. }
  131. /**
  132. * @return string
  133. */
  134. public function getUpdatedAt()
  135. {
  136. return $this->updatedAt;
  137. }
  138. /**
  139. * Set email
  140. *
  141. * @param string $email
  142. *
  143. * @return $this
  144. */
  145. public function setEmail($email)
  146. {
  147. $this->email = $email;
  148. return $this;
  149. }
  150. /**
  151. * @return array
  152. */
  153. public function getData()
  154. {
  155. return get_object_vars($this);
  156. }
  157. }