/** * Before delete process * * @throws \Magento\Framework\Exception\LocalizedException * @return $this */ public function beforeDelete() { if ($this->getResource()->isForbiddenToDelete($this->getId())) { throw new \Magento\Framework\Exception\LocalizedException(__('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 */ public function beforeDelete() { $this->cleanCache(); return parent::beforeDelete(); }