_init('olegnax_carousel_carousel', 'carousel_id'); } protected function _beforeSave(AbstractModel $object) { $data = $object->getData('identifier'); if (empty($data)) { $data = $object->getData('Title'); } $data = str_replace(' ', '_', strtolower($data)); $object->setData('identifier', $data); if (!$this->getIsUniqueCarousel($object)) { throw new LocalizedException( __('A Carousel identifier with the same properties already exists.') ); } return parent::_beforeSave($object); } private function getIsUniqueCarousel(AbstractModel $object) { $select = $this->getConnection()->select() ->from(['cb' => $this->getMainTable()]) ->where('cb.identifier = ? ', $object->getData('identifier')); if ($this->getConnection()->fetchRow($select)) { return false; } return true; } }