dateTime = $dateTime; $this->campaignCollection = $campaignCollection; parent::__construct( $context, $registry, $resource, $resourceCollection, $data ); } /** * Constructor. * * @return null */ public function _construct() { parent::_construct(); $this->_init(\Dotdigitalgroup\Email\Model\ResourceModel\Campaign::class); } /** * Get campaign by quote id. * * @param int $quoteId * @param int $storeId * * @return $this */ public function loadByQuoteId($quoteId, $storeId) { $item = $this->campaignCollection->create() ->loadByQuoteId($quoteId, $storeId); if ($item) { return $item; } else { return $this->setQuoteId($quoteId) ->setStoreId($storeId); } } /** * Prepare data to be saved to database. * * @return $this */ public function beforeSave() { parent::beforeSave(); if ($this->isObjectNew()) { $this->setCreatedAt($this->dateTime->formatDate(true)); } $this->setUpdatedAt($this->dateTime->formatDate(true)); return $this; } }