Example #1
1
 /**
  * Update items stock status and low stock date.
  *
  * @param Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(Observer $observer)
 {
     if ($this->config->isNewRelicEnabled()) {
         if (!$this->newRelicWrapper->isExtensionInstalled()) {
             $this->config->disableModule();
             $this->messageManager->addError(__('The New Relic integration requires the newrelic-php5 agent, which is not installed. More 
                     information on installing the agent is available <a target="_blank" href="%1">here</a>.', 'https://docs.newrelic.com/docs/agents/php-agent/installation/php-agent-installation-overview'), $this->messageManager->getDefaultGroup());
         }
     }
 }
 /**
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     try {
         $this->checkoutSession->loadCustomerQuote();
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $this->messageManager->addError($e->getMessage());
     } catch (\Exception $e) {
         $this->messageManager->addException($e, __('Load customer quote error'));
     }
 }
 /**
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function execute()
 {
     $redirectUrl = $this->getUrl('adminhtml/system_config/edit', ['section' => 'connector_developer_settings']);
     $result = $this->contactFactory->create()->deleteContactIds();
     $this->messageManager->addSuccessMessage('Contact id\'s reseted ' . $result);
     $this->_redirect($redirectUrl);
 }
Example #4
0
 public function testLoadCustomerQuoteThrowingException()
 {
     $exception = new \Exception('Message');
     $this->checkoutSession->expects($this->once())->method('loadCustomerQuote')->will($this->throwException($exception));
     $this->messageManager->expects($this->once())->method('addException')->with($exception, 'Load customer quote error');
     $this->object->loadCustomerQuote();
 }
 /**
  * Execute method.
  *
  * @param \Magento\Framework\Event\Observer $observer
  *
  * @return $this
  * @codingStandardsIgnoreStart
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     //@codingStandardsIgnoreEnd
     $groups = $this->context->getRequest()->getPost('groups');
     if (isset($groups['api']['fields']['username']['inherit']) || isset($groups['api']['fields']['password']['inherit'])) {
         return $this;
     }
     $apiUsername = isset($groups['api']['fields']['username']['value']) ? $groups['api']['fields']['username']['value'] : false;
     $apiPassword = isset($groups['api']['fields']['password']['value']) ? $groups['api']['fields']['password']['value'] : false;
     //skip if the inherit option is selected
     if ($apiUsername && $apiPassword) {
         $this->helper->log('----VALIDATING ACCOUNT---');
         $isValid = $this->test->validate($apiUsername, $apiPassword);
         if ($isValid) {
             //save endpoint for account
             foreach ($isValid->properties as $property) {
                 if ($property->name == 'ApiEndpoint' && !empty($property->value)) {
                     $this->saveApiEndpoint($property->value);
                     break;
                 }
             }
             $this->messageManager->addSuccessMessage(__('API Credentials Valid.'));
         } else {
             $this->messageManager->addWarningMessage(__('Authorization has been denied for this request.'));
         }
     }
     return $this;
 }
Example #6
0
 public function testTryToSaveInvalidDataShouldFailWithErrors()
 {
     $validatorClass = 'Magento\\MediaStorage\\Model\\File\\Validator\\AvailablePath';
     $helperClass = 'Magento\\Sitemap\\Helper\\Data';
     $validPaths = [];
     $messages = ['message1', 'message2'];
     $sessionClass = 'Magento\\Backend\\Model\\Session';
     $data = ['sitemap_filename' => 'sitemap_filename', 'sitemap_path' => '/sitemap_path'];
     $siteMapId = 1;
     $this->requestMock->expects($this->once())->method('getPostValue')->willReturn($data);
     $this->requestMock->expects($this->once())->method('getParam')->with('sitemap_id')->willReturn($siteMapId);
     $validator = $this->getMock($validatorClass, [], [], '', false);
     $validator->expects($this->once())->method('setPaths')->with($validPaths)->willReturnSelf();
     $validator->expects($this->once())->method('isValid')->with('/sitemap_path/sitemap_filename')->willReturn(false);
     $validator->expects($this->once())->method('getMessages')->willReturn($messages);
     $helper = $this->getMock($helperClass, [], [], '', false);
     $helper->expects($this->once())->method('getValidPaths')->willReturn($validPaths);
     $session = $this->getMock($sessionClass, ['setFormData'], [], '', false);
     $session->expects($this->once())->method('setFormData')->with($data)->willReturnSelf();
     $this->objectManagerMock->expects($this->once())->method('create')->with($validatorClass)->willReturn($validator);
     $this->objectManagerMock->expects($this->any())->method('get')->willReturnMap([[$helperClass, $helper], [$sessionClass, $session]]);
     $this->messageManagerMock->expects($this->at(0))->method('addError')->withConsecutive([$messages[0]], [$messages[1]])->willReturnSelf();
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('adminhtml/*/edit', ['sitemap_id' => $siteMapId])->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->saveController->execute());
 }
Example #7
0
 /**
  * @param \Magento\Backend\Model\Auth $authModel
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterLogin(\Magento\Backend\Model\Auth $authModel)
 {
     $this->sessionsManager->processLogin();
     if ($this->sessionsManager->getCurrentSession()->isOtherSessionsTerminated()) {
         $this->messageManager->addWarning(__('All other open sessions for this account were terminated.'));
     }
 }
 /**
  * Refresh suppressed contacts.
  */
 public function execute()
 {
     $result = $this->cronFactory->create()->orderSync();
     $this->messageManager->addSuccessMessage($result['message']);
     $redirectUrl = $this->getUrl('adminhtml/system_config/edit', ['section' => 'connector_developer_settings']);
     $this->_redirect($redirectUrl);
 }
Example #9
0
 /**
  * Handle exception
  *
  * @param \Exception $e
  * @return void
  */
 protected function handleException($e)
 {
     $needToMaskDisplayMessage = !$e instanceof \Magento\Framework\Exception\LocalizedException && $this->appState->getMode() != State::MODE_DEVELOPER;
     $displayMessage = $needToMaskDisplayMessage ? (string) new \Magento\Framework\Phrase('An error occurred while processing your request') : $e->getMessage();
     $this->messageManager->addError($displayMessage);
     $this->logger->critical($e->getMessage());
 }
 /**
  * Refresh suppressed contacts.
  */
 public function execute()
 {
     $result = $this->importerFactory->create()->processQueue();
     $this->messageManager->addSuccessMessage($result['message']);
     $redirectBack = $this->_redirect->getRefererUrl();
     $this->_redirect($redirectBack);
 }
 /**
  * {@inheritdoc}
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function getWishlist($wishlistId = null)
 {
     if ($this->wishlist) {
         return $this->wishlist;
     }
     try {
         if (!$wishlistId) {
             $wishlistId = $this->request->getParam('wishlist_id');
         }
         $customerId = $this->customerSession->getCustomerId();
         $wishlist = $this->wishlistFactory->create();
         if (!$wishlistId && !$customerId) {
             return $wishlist;
         }
         if ($wishlistId) {
             $wishlist->load($wishlistId);
         } elseif ($customerId) {
             $wishlist->loadByCustomerId($customerId, true);
         }
         if (!$wishlist->getId() || $wishlist->getCustomerId() != $customerId) {
             throw new \Magento\Framework\Exception\NoSuchEntityException(__('The requested Wish List doesn\'t exist.'));
         }
     } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
         $this->messageManager->addError($e->getMessage());
         return false;
     } catch (\Exception $e) {
         $this->messageManager->addException($e, __('We can\'t create the Wish List right now.'));
         return false;
     }
     $this->wishlist = $wishlist;
     return $wishlist;
 }
Example #12
0
 /**
  * Add success message
  *
  * @return void
  */
 private function addSuccessMessage()
 {
     $params = $this->getParams();
     if (isset($params['redirect_parent'])) {
         $this->messageManager->addSuccess(__('You created the order.'));
     }
 }
 /**
  * Refresh suppressed contacts.
  */
 public function execute()
 {
     $this->catalogFactory->create()->resetCatalog();
     $this->messageManager->addSuccessMessage(__('Done.'));
     $redirectUrl = $this->getUrl('adminhtml/system_config/edit', ['section' => 'connector_developer_settings']);
     $this->_redirect($redirectUrl);
 }
 /**
  * Refresh suppressed contacts.
  */
 public function execute()
 {
     $result = $this->cronFactory->create()->contactSync();
     $this->messageManager->addSuccessMessage($result['message']);
     $redirectBack = $this->_redirect->getRefererUrl();
     $this->_redirect($redirectBack);
 }
 /**
  * @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();
 }
 public function testBeforeSaveFail()
 {
     $wrongValue = '/^mozillai';
     $this->regexp->setValue($wrongValue);
     $this->messageManager->expects($this->once())->method('addNotice')->with(__('Invalid regular expression: %value', ['value' => $wrongValue]));
     $this->regexp->beforeSave();
     $this->assertNull($this->regexp->getValue());
 }
Example #17
0
 /**
  * {@inheritdoc}
  */
 public function getSectionData()
 {
     $messages = $this->messageManager->getMessages(true);
     return ['messages' => array_reduce($messages->getItems(), function (array $result, MessageInterface $message) {
         $result[] = ['type' => $message->getType(), 'text' => $message->getText()];
         return $result;
     }, [])];
 }
 public function testLoadCustomerQuoteThrowingException()
 {
     $exception = new \Exception('Message');
     $this->checkoutSession->expects($this->once())->method('loadCustomerQuote')->will($this->throwException($exception));
     $this->messageManager->expects($this->once())->method('addException')->with($exception, 'Load customer quote error');
     $observerMock = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $this->object->execute($observerMock);
 }
Example #19
0
 public function testDeleteActionNoId()
 {
     $this->requestMock->expects($this->once())->method('getParam')->willReturn(null);
     $this->messageManagerMock->expects($this->once())->method('addError')->with(__('We can\'t find a synonym group to delete.'));
     $this->messageManagerMock->expects($this->never())->method('addSuccess');
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('*/*/')->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->deleteController->execute());
 }
 /**
  * Checks if 'synonyms' feature is supported by configured search engine. If not supported displays a notice
  *
  * @return void
  */
 protected function checkSearchEngineSupport()
 {
     // Display a notice if search engine configuration does not support synonyms
     $searchEngine = $this->engineResolver->getCurrentSearchEngine();
     if (!$this->searchFeatureConfig->isFeatureSupported(\Magento\Framework\Search\SearchEngine\ConfigInterface::SEARCH_ENGINE_FEATURE_SYNONYMS, $searchEngine)) {
         $this->messageManager->addNoticeMessage(__('Search synonyms are not supported by the %1 search engine. ' . 'Any synonyms you enter won\'t be used.', $searchEngine));
     }
 }
 /**
  * Before execute login
  *
  * @param Login $login
  * @return void
  */
 public function beforeExecute(Login $login)
 {
     $logoutReasonCode = $this->securityCookieHelper->getLogoutReasonCookie();
     if ($this->isLoginForm($login) && $logoutReasonCode >= 0) {
         $this->messageManager->addError($this->sessionsManager->getLogoutReasonMessageByStatus($logoutReasonCode));
         $this->securityCookieHelper->deleteLogoutReasonCookie();
     }
 }
 /**
  * @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'));
         }
     }
 }
Example #23
0
 /**
  * @return void
  */
 public function testAfterLogin()
 {
     $warningMessage = __('All other open sessions for this account were terminated.');
     $this->sessionsManager->expects($this->once())->method('processLogin');
     $this->sessionsManager->expects($this->once())->method('getCurrentSession')->willReturn($this->currentSession);
     $this->currentSession->expects($this->once())->method('isOtherSessionsTerminated')->willReturn(true);
     $this->messageManager->expects($this->once())->method('addWarning')->with($warningMessage);
     $this->model->afterLogin($this->authMock);
 }
Example #24
0
 /**
  * Return messages array and clean message manager messages
  *
  * @return array
  */
 protected function getMessages()
 {
     $messages = $this->getCookiesMessages();
     /** @var MessageInterface $message */
     foreach ($this->messageManager->getMessages(true)->getItems() as $message) {
         $messages[] = ['type' => $message->getType(), 'text' => $this->interpretationStrategy->interpret($message)];
     }
     return $messages;
 }
 /**
  * Add user logout notification
  *
  * @return $this
  */
 protected function addUserLogoutNotification()
 {
     if ($this->isAjaxRequest()) {
         $this->securityCookieHelper->setLogoutReasonCookie($this->sessionsManager->getCurrentSession()->getStatus());
     } else {
         $this->messageManager->addError($this->sessionsManager->getLogoutReasonMessage());
     }
     return $this;
 }
Example #26
0
 /**
  * @dataProvider testPostDataProvider
  */
 public function testExecutePostValidation($postData, $exceptionExpected)
 {
     $this->_request->expects($this->any())->method('getPost')->will($this->returnValue($postData));
     if ($exceptionExpected) {
         $this->_messageManager->expects($this->once())->method('addError');
     }
     $this->_inlineTranslation->expects($this->once())->method('resume');
     $this->_inlineTranslation->expects($this->once())->method('suspend');
     $this->_controller->execute();
 }
Example #27
0
 public function testSaveActionWithException()
 {
     $this->formKeyValidatorMock->expects($this->once())->method('validate')->will($this->returnValue(true));
     $this->customerSessionMock->expects($this->any())->method('getCustomerId')->will($this->returnValue(1));
     $this->customerRepositoryMock->expects($this->any())->method('getById')->will($this->throwException(new NoSuchEntityException(__(NoSuchEntityException::MESSAGE_SINGLE_FIELD, ['fieldName' => 'customerId', 'value' => 'value']))));
     $this->redirectMock->expects($this->once())->method('redirect')->with($this->responseMock, 'customer/account/', []);
     $this->messageManagerMock->expects($this->never())->method('addSuccess');
     $this->messageManagerMock->expects($this->once())->method('addError')->with('Something went wrong while saving your subscription.');
     $this->action->execute();
 }
Example #28
0
 /**
  * Test case when module is enabled in config and php extension is installed
  *
  * @return void
  */
 public function testCheckConfig()
 {
     /** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserver */
     $eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $this->config->expects($this->once())->method('isNewRelicEnabled')->willReturn(true);
     $this->newRelicWrapper->expects($this->once())->method('isExtensionInstalled')->willReturn(false);
     $this->config->expects($this->once())->method('disableModule');
     $this->messageManager->expects($this->once())->method('addError');
     $this->model->execute($eventObserver);
 }
Example #29
0
 /**
  * @return void
  */
 public function loadCustomerQuote()
 {
     try {
         $this->_checkoutSession->loadCustomerQuote();
     } catch (\Magento\Framework\Model\Exception $e) {
         $this->messageManager->addError($e->getMessage());
     } catch (\Exception $e) {
         $this->messageManager->addException($e, __('Load customer quote error'));
     }
 }
 public function testExecute()
 {
     $ids = [1, 2];
     $this->request->expects($this->once())->method('getParam')->with('search')->will($this->returnValue($ids));
     $this->createQuery(0, 1);
     $this->createQuery(1, 2);
     $this->messageManager->expects($this->once())->method('addSuccess')->will($this->returnSelf());
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('search/*/')->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->controller->execute());
 }