/** * Before delete process * * @throws \Magento\Framework\Model\Exception * @return $this */ protected function _beforeDelete() { if ($this->getResource()->isForbiddenToDelete($this->getId())) { throw new \Magento\Framework\Model\Exception("Can't delete root category."); } return parent::_beforeDelete(); }
/** * Clear cache related with product and protect delete from not admin * Register indexing event before delete product * * @return \Magento\Catalog\Model\Product */ protected function _beforeDelete() { $this->cleanCache(); $this->_indexIndexer->logEvent($this, self::ENTITY, \Magento\Index\Model\Event::TYPE_DELETE); return parent::_beforeDelete(); }