/**
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function beforeSave()
 {
     if (!empty($this->getValue()) && !$this->_isRegexp($this->getValue())) {
         $this->messageManager->addNotice(__('Invalid regular expression: %value', ['value' => $this->getValue()]));
         $this->setValue(null);
     }
     return parent::beforeSave();
 }
 /**
  * @param Observer $observer
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $dirtyRules = $observer->getData('dirty_rules');
     if (!empty($dirtyRules)) {
         if ($dirtyRules->getState()) {
             $this->messageManager->addNotice($observer->getData('message'));
         }
     }
 }
 /**
  * Prevent express checkout
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if (!($this->_persistentSession->isPersistent() && !$this->_customerSession->isLoggedIn())) {
         return;
     }
     /** @var $controllerAction \Magento\Checkout\Controller\Express\RedirectLoginInterface*/
     $controllerAction = $observer->getEvent()->getControllerAction();
     if (!$controllerAction || !$controllerAction instanceof \Magento\Checkout\Controller\Express\RedirectLoginInterface || $controllerAction->getRedirectActionName() != $controllerAction->getRequest()->getActionName()) {
         return;
     }
     $this->messageManager->addNotice(__('To check out, please sign in using your email address.'));
     $customerBeforeAuthUrl = $this->_url->getUrl('persistent/index/expressCheckout');
     $this->_expressRedirectHelper->redirectLogin($controllerAction, $customerBeforeAuthUrl);
 }
 /**
  * @param Observer $observer
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $webhook = $this->storeManager->getStore()->getBaseUrl() . "cpwebhook/";
     try {
         $client = new Client($this->model->getPublicKey(), $this->model->getPrivateKey(), $this->model->getLiveMode());
         Validations::validateGateway($client);
         $client->api->createWebhook($webhook);
         $response = $client->api->hookRetro($this->model->getConfigData('active') == 1);
         if ($response[0]) {
             $this->messageManager->addNotice("ComproPago: {$response[1]}");
         }
     } catch (\Exception $e) {
         $this->messageManager->addError("ComproPago: {$e->getMessage()}");
     }
 }
Example #5
0
 /**
  * Update cart items information
  *
  * @param  array $data
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function updateItems($data)
 {
     $infoDataObject = new \Magento\Framework\Object($data);
     $this->_eventManager->dispatch('checkout_cart_update_items_before', ['cart' => $this, 'info' => $infoDataObject]);
     $qtyRecalculatedFlag = false;
     foreach ($data as $itemId => $itemInfo) {
         $item = $this->getQuote()->getItemById($itemId);
         if (!$item) {
             continue;
         }
         if (!empty($itemInfo['remove']) || isset($itemInfo['qty']) && $itemInfo['qty'] == '0') {
             $this->removeItem($itemId);
             continue;
         }
         $qty = isset($itemInfo['qty']) ? (double) $itemInfo['qty'] : false;
         if ($qty > 0) {
             $item->setQty($qty);
             $itemInQuote = $this->getQuote()->getItemById($item->getId());
             if (!$itemInQuote && $item->getHasError()) {
                 throw new \Magento\Framework\Exception\LocalizedException(__($item->getMessage()));
             }
             if (isset($itemInfo['before_suggest_qty']) && $itemInfo['before_suggest_qty'] != $qty) {
                 $qtyRecalculatedFlag = true;
                 $this->messageManager->addNotice(__('Quantity was recalculated from %1 to %2', $itemInfo['before_suggest_qty'], $qty), 'quote_item' . $item->getId());
             }
         }
     }
     if ($qtyRecalculatedFlag) {
         $this->messageManager->addNotice(__('Some products quantities were recalculated because of quantity increment mismatch.'));
     }
     $this->_eventManager->dispatch('checkout_cart_update_items_after', ['cart' => $this, 'info' => $infoDataObject]);
     return $this;
 }
Example #6
0
 /**
  * Update all attribute-dependant index
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return \Magento\CatalogSearch\Model\Fulltext\Observer
  */
 public function eavAttributeChange(\Magento\Framework\Event\Observer $observer)
 {
     $attribute = $observer->getEvent()->getAttribute();
     /* @var $attribute \Magento\Eav\Model\Entity\Attribute */
     $entityType = $this->_eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY);
     /* @var $entityType \Magento\Eav\Model\Entity\Type */
     if ($attribute->getEntityTypeId() != $entityType->getId()) {
         return $this;
     }
     $delete = $observer->getEventName() == 'eav_entity_attribute_delete_after';
     if (!$delete && !$attribute->dataHasChangedFor('is_searchable')) {
         return $this;
     }
     $showNotice = false;
     if ($delete) {
         if ($attribute->getIsSearchable()) {
             $showNotice = true;
         }
     } elseif ($attribute->dataHasChangedFor('is_searchable')) {
         $showNotice = true;
     }
     if ($showNotice) {
         $url = $this->_backendUrl->getUrl('adminhtml/system_cache');
         $this->messageManager->addNotice(__('Attribute setting change related with Search Index. Please run <a href="%1">Rebuild Search Index</a> process.', $url));
     }
     return $this;
 }
 /**
  *
  * @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;
 }
Example #8
0
 /**
  * Validate ip addresses before save
  *
  * @return $this
  */
 public function beforeSave()
 {
     $allowedIpsRaw = $this->getValue();
     $noticeMsgArray = [];
     $allowedIpsArray = [];
     if (empty($allowedIpsRaw)) {
         return parent::beforeSave();
     }
     $dataArray = explode(',', $allowedIpsRaw);
     foreach ($dataArray as $data) {
         if (filter_var(trim($data), FILTER_VALIDATE_IP)) {
             $allowedIpsArray[] = $data;
         } else {
             $noticeMsgArray[] = $data;
         }
     }
     $noticeMsg = implode(',', $noticeMsgArray);
     if (!empty($noticeMsgArray)) {
         $this->messageManager->addNotice(__(__('The following invalid values cannot be saved: %values', ['values' => $noticeMsg])));
     }
     $this->setValue(implode(',', $allowedIpsArray));
     return parent::beforeSave();
 }
 /**
  * {@inheritdoc}
  * @param Observer $observer
  * @return bool
  */
 public function execute(Observer $observer)
 {
     if ($this->config->isNorouteToSearchEnabled()) {
         /** @var \Magento\Framework\App\Request\Http $request */
         $request = $observer->getEvent()->getData('request');
         /** @var \Magento\Framework\App\Response\Http\Interceptor $response */
         $response = $observer->getEvent()->getData('response');
         $extension = pathinfo($request->getRequestString(), PATHINFO_EXTENSION);
         if ($response->getStatusCode() != 404 || !$request->isGet() || in_array($extension, $this->mediaTypes)) {
             return false;
         } else {
             $searchQuery = $this->getSearchQuery($request);
             if (!$searchQuery) {
                 return false;
             }
             $message = __('The page you requested was not found, but we have searched for relevant content.');
             $this->messageManager->addNotice($message);
             $url = $this->urlFactory->create()->addQueryParams(['q' => $searchQuery])->getUrl('catalogsearch/result');
             $response->setRedirect($url)->setStatusCode(301)->sendResponse();
         }
     }
     return true;
 }
 /**
  * @return \Magento\Framework\Controller\Result\Redirect|\Magento\Framework\Controller\ResultInterface
  */
 public function execute()
 {
     $email = $this->getRequest()->getParam('email', false);
     $list = $this->getRequest()->getParam('list', false);
     $store = $this->getRequest()->getParam('store', false);
     if ($email && $list && $store) {
         $collection = $this->_objectManager->create('\\Ebizmarts\\Mandrill\\Model\\Unsubscribe')->getCollection();
         $collection->addFieldToFilter('main_table.email', array('eq' => $email))->addFieldToFilter('main_table.list', array('eq' => $list))->addFieldToFilter('main_table.store_id', array('eq' => $store))->limit(1);
         if ($collection->getSize() == 0) {
             $unsubscribe = $this->_objectManager->create('\\Ebizmarts\\Mandrill\\Model\\Unsubscribe');
             $unsubscribe->setEmail($email)->setList($list)->setStoreId($store)->setUnsubscribedAt(date('Y-m-d H:i:s'));
             $unsubscribe->save();
             $this->messageManager->addNotice("You are unsubcribed from {$list}");
         } else {
             $this->messageManager->addNotice("You are already unsubcribed from {$list}");
         }
     } else {
         $this->messageManager->addNotice("Invalid url format");
     }
     $resultRedirect = $this->_resultRedirectFactory->create();
     $resultRedirect->setPath('/');
     return $resultRedirect;
 }
Example #11
0
 public function addNotice($message, $popupText = null, $popupTitle = null)
 {
     $popupId = $this->addPopup($popupText, $popupTitle);
     $this->messageManager->addNotice($this->getMessageText($message, $popupId));
 }