Wishlist.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace Dotdigitalgroup\Email\Model;
  3. class Wishlist extends \Magento\Framework\Model\AbstractModel
  4. {
  5. /**
  6. * @var \Magento\Framework\Stdlib\DateTime
  7. */
  8. private $dateTime;
  9. /**
  10. * Wishlist constructor.
  11. *
  12. * @param \Magento\Framework\Model\Context $context
  13. * @param \Magento\Framework\Registry $registry
  14. * @param \Magento\Framework\Stdlib\DateTime $dateTime
  15. * @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
  16. * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
  17. * @param array $data
  18. */
  19. public function __construct(
  20. \Magento\Framework\Model\Context $context,
  21. \Magento\Framework\Registry $registry,
  22. \Magento\Framework\Stdlib\DateTime $dateTime,
  23. \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
  24. \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
  25. array $data = []
  26. ) {
  27. $this->dateTime = $dateTime;
  28. parent::__construct(
  29. $context,
  30. $registry,
  31. $resource,
  32. $resourceCollection,
  33. $data
  34. );
  35. }
  36. /**
  37. * Constructor.
  38. *
  39. * @return null
  40. */
  41. public function _construct()
  42. {
  43. parent::_construct();
  44. $this->_init(\Dotdigitalgroup\Email\Model\ResourceModel\Wishlist::class);
  45. }
  46. /**
  47. * Prepare data to be saved to database.
  48. *
  49. * @return $this
  50. */
  51. public function beforeSave()
  52. {
  53. parent::beforeSave();
  54. if ($this->isObjectNew() && !$this->getCreatedAt()) {
  55. $this->setCreatedAt($this->dateTime->formatDate(true));
  56. }
  57. $this->setUpdatedAt($this->dateTime->formatDate(true));
  58. return $this;
  59. }
  60. }