_type)) { $this->setType(\Plumrocket\CookieConsent\Model\Cookie::ENTITY); } return parent::getEntityType(); } /** * Retrieve customer entity default attributes * * @return string[] */ protected function _getDefaultAttributes(): array { return [ 'created_at', 'updated_at', ]; } /** * Perform operations before object save * * @param DataObject|CookieInterface $object * @return \Plumrocket\CookieConsent\Model\ResourceModel\Cookie * @throws LocalizedException */ protected function _beforeSave(DataObject $object): Cookie { if (! $this->isUniqueCookieName($object)) { throw new LocalizedException( __('A cookie with the same name already exists. Please update old cookie or delete it.') ); } return $this; } /** * @param \Plumrocket\CookieConsent\Api\Data\CookieInterface $cookie * @return bool */ private function isUniqueCookieName(CookieInterface $cookie): bool { $select = $this->getConnection()->select() ->from($this->getTable(self::MAIN_TABLE_NAME)) ->where('name = ? ', $cookie->getName()); if ($cookie->getId()) { $select->where(self::ID_FIELD_NAME . ' <> ?', $cookie->getId()); } if ($this->getConnection()->fetchRow($select)) { return false; } return true; } }