/** * * @param \Magento\Framework\Event\Observer $observer * @return $this */ public function execute(\Magento\Framework\Event\Observer $observer) { if ($observer->getStore()) { $scopeId = $observer->getStore(); $scopeType = \Magento\Store\Model\ScopeInterface::SCOPE_STORE; } elseif ($observer->getWebsite()) { $scopeId = $observer->getWebsite(); $scopeType = \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE; } else { $scopeId = \Magento\Store\Model\Store::DEFAULT_STORE_ID; $scopeType = \Magento\Store\Model\ScopeInterface::SCOPE_STORE; } foreach ($this->getErrors($scopeId, $scopeType) as $error) { $this->messageManager->addError($error); } foreach ($this->getNotices() as $notice) { $this->messageManager->addNotice($notice); } return $this; }