/**
  * @return void
  */
 public function testExecute()
 {
     $customerId = 7;
     $captchaValue = 'some-value';
     $email = '*****@*****.**';
     $redirectUrl = 'http://magento.com/customer/account/edit/';
     $captcha = $this->getMock('Magento\\Captcha\\Model\\DefaultModel', [], [], '', false);
     $captcha->expects($this->once())->method('isRequired')->willReturn(true);
     $captcha->expects($this->once())->method('isCorrect')->with($captchaValue)->willReturn(false);
     $this->helperMock->expects($this->once())->method('getCaptcha')->with(\Magento\Captcha\Observer\CheckUserEditObserver::FORM_ID)->willReturn($captcha);
     $response = $this->getMock('Magento\\Framework\\App\\Response\\Http', [], [], '', false);
     $request = $this->getMock('Magento\\Framework\\App\\Request\\Http', [], [], '', false);
     $request->expects($this->any())->method('getPost')->with(\Magento\Captcha\Helper\Data::INPUT_NAME_FIELD_VALUE, null)->willReturn([\Magento\Captcha\Observer\CheckUserEditObserver::FORM_ID => $captchaValue]);
     $controller = $this->getMock('Magento\\Framework\\App\\Action\\Action', [], [], '', false);
     $controller->expects($this->any())->method('getRequest')->will($this->returnValue($request));
     $controller->expects($this->any())->method('getResponse')->will($this->returnValue($response));
     $this->captchaStringResolverMock->expects($this->once())->method('resolve')->with($request, \Magento\Captcha\Observer\CheckUserEditObserver::FORM_ID)->willReturn($captchaValue);
     $customerDataMock = $this->getMock('\\Magento\\Customer\\Model\\Data\\Customer', [], [], '', false);
     $this->customerSessionMock->expects($this->once())->method('getCustomerId')->willReturn($customerId);
     $this->customerSessionMock->expects($this->atLeastOnce())->method('getCustomer')->willReturn($customerDataMock);
     $this->authenticationMock->expects($this->once())->method('processAuthenticationFailure')->with($customerId);
     $this->authenticationMock->expects($this->once())->method('isLocked')->with($customerId)->willReturn(true);
     $this->customerSessionMock->expects($this->once())->method('logout');
     $this->customerSessionMock->expects($this->once())->method('start');
     $this->scopeConfigMock->expects($this->once())->method('getValue')->with('contact/email/recipient_email')->willReturn($email);
     $message = __('The account is locked. Please wait and try again or contact %1.', $email);
     $this->messageManagerMock->expects($this->exactly(2))->method('addError')->withConsecutive([$message], [__('Incorrect CAPTCHA')]);
     $this->actionFlagMock->expects($this->once())->method('set')->with('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
     $this->redirectMock->expects($this->once())->method('redirect')->with($response, '*/*/edit')->willReturn($redirectUrl);
     $this->observer->execute(new \Magento\Framework\Event\Observer(['controller_action' => $controller]));
 }
Esempio n. 2
0
 public function testSetPath()
 {
     $path = 'test/path';
     $params = ['one' => 1, 'two' => 2];
     $this->redirectInterface->expects($this->once())->method('updatePathParams')->with($params)->will($this->returnValue($params));
     $this->assertInstanceOf('Magento\\Framework\\Controller\\Result\\Redirect', $this->redirect->setPath($path, $params));
 }
Esempio n. 3
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();
 }
Esempio n. 4
0
 public function setUp()
 {
     $this->request = $this->getMockBuilder('Magento\\Framework\\App\\RequestInterface')->disableOriginalConstructor()->getMock();
     $this->response = $this->getMock('Magento\\Framework\\App\\ResponseInterface', [], [], '', false);
     $this->redirect = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Redirect')->setMethods(['setRefererOrBaseUrl'])->disableOriginalConstructor()->getMock();
     $this->redirectFactory = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\RedirectFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $this->redirectFactory->expects($this->any())->method('create')->willReturn($this->redirect);
     $this->context = $this->getMockBuilder('Magento\\Framework\\App\\Action\\Context')->disableOriginalConstructor()->getMock();
     $this->context->expects($this->any())->method('getResultRedirectFactory')->willReturn($this->redirectFactory);
     $this->action = $this->getMockForAbstractClass('Magento\\Framework\\App\\Action\\AbstractAction', [$this->context]);
 }
Esempio n. 5
0
 /**
  * Perform customer authentication and wishlist feature state checks
  *
  * @param \Magento\Framework\App\ActionInterface $subject
  * @param RequestInterface $request
  * @return void
  * @throws \Magento\Framework\Exception\NotFoundException
  */
 public function beforeDispatch(\Magento\Framework\App\ActionInterface $subject, RequestInterface $request)
 {
     if ($this->authenticationState->isEnabled() && !$this->customerSession->authenticate($subject)) {
         $subject->getActionFlag()->set('', 'no-dispatch', true);
         if (!$this->customerSession->getBeforeWishlistUrl()) {
             $this->customerSession->setBeforeWishlistUrl($this->redirector->getRefererUrl());
         }
         $this->customerSession->setBeforeWishlistRequest($request->getParams());
     }
     if (!$this->config->isSetFlag('wishlist/general/active')) {
         throw new NotFoundException(__('Page not found.'));
     }
 }
 /**
  * Check CAPTCHA on Contact Us page
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $formId = 'contact_us';
     $captcha = $this->_helper->getCaptcha($formId);
     if ($captcha->isRequired()) {
         /** @var \Magento\Framework\App\Action\Action $controller */
         $controller = $observer->getControllerAction();
         if (!$captcha->isCorrect($this->captchaStringResolver->resolve($controller->getRequest(), $formId))) {
             $this->messageManager->addError(__('Incorrect CAPTCHA.'));
             $this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
             $this->redirect->redirect($controller->getResponse(), 'contact/index/index');
         }
     }
 }
Esempio n. 7
0
 public function testExecute()
 {
     $firstElement = 'firstElement';
     $symbolsDataArray = [$firstElement];
     $redirectUrl = 'redirectUrl';
     $this->requestMock->expects($this->once())->method('getParam')->with('custom_currency_symbol')->willReturn($symbolsDataArray);
     $this->helperMock->expects($this->once())->method('getUrl')->with('*');
     $this->redirectMock->expects($this->once())->method('getRedirectUrl')->willReturn($redirectUrl);
     $this->currencySymbolMock->expects($this->once())->method('setCurrencySymbolsData')->with($symbolsDataArray);
     $this->responseMock->expects($this->once())->method('setRedirect');
     $this->filterManagerMock->expects($this->once())->method('stripTags')->with($firstElement)->willReturn($firstElement);
     $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\CurrencySymbol\\Model\\System\\Currencysymbol')->willReturn($this->currencySymbolMock);
     $this->objectManagerMock->expects($this->once())->method('get')->with('Magento\\Framework\\Filter\\FilterManager')->willReturn($this->filterManagerMock);
     $this->messageManagerMock->expects($this->once())->method('addSuccess')->with(__('You applied the custom currency symbols.'));
     $this->action->execute();
 }
 /**
  * Check Captcha On Forgot Password Page
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $captchaModel = $this->helper->getCaptcha(self::FORM_ID);
     if ($captchaModel->isRequired()) {
         /** @var \Magento\Framework\App\Action\Action $controller */
         $controller = $observer->getControllerAction();
         if (!$captchaModel->isCorrect($this->captchaStringResolver->resolve($controller->getRequest(), self::FORM_ID))) {
             try {
                 $customer = $this->customerRepository->getById($this->customerSession->getCustomerId());
                 $this->accountManagementHelper->processCustomerLockoutData($customer->getId());
                 $this->customerRepository->save($customer);
             } catch (NoSuchEntityException $e) {
                 //do nothing as customer existance is validated later in authenticate method
             }
             $this->workWithLock();
             $this->messageManager->addError(__('Incorrect CAPTCHA'));
             $this->actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
             $this->redirect->redirect($controller->getResponse(), '*/*/edit');
         }
     }
     $customer = $this->customerSession->getCustomer();
     $login = $customer->getEmail();
     $captchaModel->logAttempt($login);
     return $this;
 }
 /**
  * Check Captcha On Forgot Password Page
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $captchaModel = $this->helper->getCaptcha(self::FORM_ID);
     if ($captchaModel->isRequired()) {
         /** @var \Magento\Framework\App\Action\Action $controller */
         $controller = $observer->getControllerAction();
         if (!$captchaModel->isCorrect($this->captchaStringResolver->resolve($controller->getRequest(), self::FORM_ID))) {
             $customerId = $this->customerSession->getCustomerId();
             $this->authentication->processAuthenticationFailure($customerId);
             if ($this->authentication->isLocked($customerId)) {
                 $this->customerSession->logout();
                 $this->customerSession->start();
                 $message = __('The account is locked. Please wait and try again or contact %1.', $this->scopeConfig->getValue('contact/email/recipient_email'));
                 $this->messageManager->addError($message);
             }
             $this->messageManager->addError(__('Incorrect CAPTCHA'));
             $this->actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
             $this->redirect->redirect($controller->getResponse(), '*/*/edit');
         }
     }
     $customer = $this->customerSession->getCustomer();
     $login = $customer->getEmail();
     $captchaModel->logAttempt($login);
     return $this;
 }
 public function testCheckContactUsFormRedirectsCustomerWithWarningMessageWhenCaptchaIsRequiredAndInvalid()
 {
     $formId = 'contact_us';
     $captchaValue = 'some-value';
     $warningMessage = 'Incorrect CAPTCHA.';
     $redirectRoutePath = 'contact/index/index';
     $redirectUrl = 'http://magento.com/contacts/';
     $postData = ['name' => 'Some Name'];
     $request = $this->getMock('Magento\\Framework\\App\\Request\\Http', [], [], '', false);
     $response = $this->getMock('Magento\\Framework\\App\\Response\\Http', [], [], '', false);
     $request->expects($this->any())->method('getPost')->with(\Magento\Captcha\Helper\Data::INPUT_NAME_FIELD_VALUE, null)->willReturn([$formId => $captchaValue]);
     $request->expects($this->once())->method('getPostValue')->willReturn($postData);
     $this->redirectMock->expects($this->once())->method('redirect')->with($response, $redirectRoutePath, [])->willReturn($redirectUrl);
     $controller = $this->getMock('Magento\\Framework\\App\\Action\\Action', [], [], '', false);
     $controller->expects($this->any())->method('getRequest')->willReturn($request);
     $controller->expects($this->any())->method('getResponse')->willReturn($response);
     $this->captchaMock->expects($this->any())->method('isRequired')->willReturn(true);
     $this->captchaMock->expects($this->once())->method('isCorrect')->with($captchaValue)->willReturn(false);
     $this->captchaStringResolverMock->expects($this->once())->method('resolve')->with($request, $formId)->willReturn($captchaValue);
     $this->helperMock->expects($this->any())->method('getCaptcha')->with($formId)->willReturn($this->captchaMock);
     $this->messageManagerMock->expects($this->once())->method('addError')->with($warningMessage);
     $this->actionFlagMock->expects($this->once())->method('set')->with('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
     $this->dataPersistorMock->expects($this->once())->method('set')->with($formId, $postData);
     $this->checkContactUsFormObserver->execute(new \Magento\Framework\Event\Observer(['controller_action' => $controller]));
 }
Esempio n. 11
0
 /**
  * @expectedException \Magento\Framework\Exception\NotFoundException
  */
 public function testBeforeDispatch()
 {
     $actionFlag = $this->getMock('Magento\\Framework\\App\\ActionFlag', [], [], '', false);
     $indexController = $this->getMock('Magento\\Wishlist\\Controller\\Index\\Index', [], [], '', false);
     $actionFlag->expects($this->once())->method('set')->with('', 'no-dispatch', true)->willReturn(true);
     $indexController->expects($this->once())->method('getActionFlag')->willReturn($actionFlag);
     $this->authenticationState->expects($this->once())->method('isEnabled')->willReturn(true);
     $this->customerSession->expects($this->once())->method('authenticate')->willReturn(false);
     $this->redirector->expects($this->once())->method('getRefererUrl')->willReturn('http://referer-url.com');
     $this->request->expects($this->once())->method('getParams')->willReturn(['product' => 1]);
     $this->customerSession->expects($this->at(1))->method('__call')->with('getBeforeWishlistUrl', [])->willReturn(false);
     $this->customerSession->expects($this->at(2))->method('__call')->with('setBeforeWishlistUrl', ['http://referer-url.com'])->willReturn(false);
     $this->customerSession->expects($this->at(3))->method('__call')->with('setBeforeWishlistRequest', [['product' => 1]])->willReturn(true);
     $this->config->expects($this->once())->method('isSetFlag')->with('wishlist/general/active')->willReturn(false);
     $this->getPlugin()->beforeDispatch($indexController, $this->request);
 }
Esempio n. 12
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testExecuteWithException()
 {
     $productId = 11;
     $categoryId = 5;
     $sender = 'sender';
     $recipients = 'recipients';
     $formData = ['sender' => $sender, 'recipients' => $recipients];
     $redirectUrl = 'redirect_url';
     /** @var \Magento\Framework\Controller\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject $redirectMock */
     $redirectMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Redirect')->disableOriginalConstructor()->getMock();
     $this->resultFactoryMock->expects($this->once())->method('create')->with(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT, [])->willReturn($redirectMock);
     $this->validatorMock->expects($this->once())->method('validate')->with($this->requestMock)->willReturn(true);
     $this->requestMock->expects($this->exactly(2))->method('getParam')->willReturnMap([['id', null, $productId], ['cat_id', null, $categoryId]]);
     /** @var \Magento\Catalog\Api\Data\ProductInterface|\PHPUnit_Framework_MockObject_MockObject $productMock */
     $productMock = $this->getMockBuilder('Magento\\Catalog\\Api\\Data\\ProductInterface')->setMethods(['isVisibleInCatalog', 'setCategory', 'getProductUrl'])->getMockForAbstractClass();
     $this->productRepositoryMock->expects($this->once())->method('getById')->with($productId, false, null, false)->willReturn($productMock);
     $productMock->expects($this->once())->method('isVisibleInCatalog')->willReturn(true);
     $this->categoryRepositoryMock->expects($this->once())->method('get')->with($categoryId, null)->willThrowException(new \Magento\Framework\Exception\NoSuchEntityException(__('No Category Exception.')));
     $productMock->expects($this->never())->method('setCategory');
     $this->registryMock->expects($this->once())->method('register')->willReturnMap([['product', $productMock, false, null]]);
     $this->requestMock->expects($this->once())->method('getPostValue')->willReturn($formData);
     $this->requestMock->expects($this->exactly(2))->method('getPost')->willReturnMap([['sender', $sender], ['recipients', $recipients]]);
     $this->sendFriendMock->expects($this->once())->method('setSender')->with($sender)->willReturnSelf();
     $this->sendFriendMock->expects($this->once())->method('setRecipients')->with($recipients)->willReturnSelf();
     $this->sendFriendMock->expects($this->once())->method('setProduct')->with($productMock)->willReturnSelf();
     $exception = new \Exception(__('Exception.'));
     $this->sendFriendMock->expects($this->once())->method('validate')->willThrowException($exception);
     $this->sendFriendMock->expects($this->never())->method('send');
     $this->messageManagerMock->expects($this->once())->method('addException')->with($exception, __('Some emails were not sent.'))->willReturnSelf();
     $this->catalogSessionMock->expects($this->once())->method('setSendfriendFormData')->with($formData);
     $this->urlBuilderMock->expects($this->once())->method('getUrl')->with('sendfriend/product/send', ['_current' => true])->willReturn($redirectUrl);
     $this->redirectMock->expects($this->once())->method('error')->with($redirectUrl)->willReturnArgument(0);
     $redirectMock->expects($this->once())->method('setUrl')->with($redirectUrl)->willReturnSelf();
     $this->assertEquals($redirectMock, $this->model->execute());
 }
Esempio n. 13
0
 public function testDispatchPostDispatch()
 {
     $this->_requestMock->expects($this->exactly(3))->method('getFullActionName')->will($this->returnValue(self::FULL_ACTION_NAME));
     $this->_requestMock->expects($this->exactly(2))->method('getRouteName')->will($this->returnValue(self::ROUTE_NAME));
     $expectedEventParameters = ['controller_action' => $this->action, 'request' => $this->_requestMock];
     $this->_eventManagerMock->expects($this->at(0))->method('dispatch')->with('controller_action_predispatch', $expectedEventParameters);
     $this->_eventManagerMock->expects($this->at(1))->method('dispatch')->with('controller_action_predispatch_' . self::ROUTE_NAME, $expectedEventParameters);
     $this->_eventManagerMock->expects($this->at(2))->method('dispatch')->with('controller_action_predispatch_' . self::FULL_ACTION_NAME, $expectedEventParameters);
     $this->_requestMock->expects($this->once())->method('isDispatched')->will($this->returnValue(true));
     $this->_actionFlagMock->expects($this->at(0))->method('get')->with('', Action::FLAG_NO_DISPATCH)->will($this->returnValue(false));
     // _forward expectations
     $this->_requestMock->expects($this->once())->method('initForward');
     $this->_requestMock->expects($this->once())->method('setParams')->with(self::$actionParams);
     $this->_requestMock->expects($this->once())->method('setControllerName')->with(self::CONTROLLER_NAME);
     $this->_requestMock->expects($this->once())->method('setModuleName')->with(self::MODULE_NAME);
     $this->_requestMock->expects($this->once())->method('setActionName')->with(self::ACTION_NAME);
     $this->_requestMock->expects($this->once())->method('setDispatched')->with(false);
     // _redirect expectations
     $this->_redirectMock->expects($this->once())->method('redirect')->with($this->_responseMock, self::FULL_ACTION_NAME, self::$actionParams);
     $this->_actionFlagMock->expects($this->at(1))->method('get')->with('', Action::FLAG_NO_POST_DISPATCH)->will($this->returnValue(false));
     $this->_eventManagerMock->expects($this->at(3))->method('dispatch')->with('controller_action_postdispatch_' . self::FULL_ACTION_NAME, $expectedEventParameters);
     $this->_eventManagerMock->expects($this->at(4))->method('dispatch')->with('controller_action_postdispatch_' . self::ROUTE_NAME, $expectedEventParameters);
     $this->_eventManagerMock->expects($this->at(5))->method('dispatch')->with('controller_action_postdispatch', $expectedEventParameters);
     $this->assertEquals($this->_responseMock, $this->action->dispatch($this->_requestMock));
 }
 /**
  * Check Captcha On User Login Page
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $formId = 'user_create';
     $captchaModel = $this->_helper->getCaptcha($formId);
     if ($captchaModel->isRequired()) {
         /** @var \Magento\Framework\App\Action\Action $controller */
         $controller = $observer->getControllerAction();
         if (!$captchaModel->isCorrect($this->captchaStringResolver->resolve($controller->getRequest(), $formId))) {
             $this->messageManager->addError(__('Incorrect CAPTCHA'));
             $this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
             $this->_session->setCustomerFormData($controller->getRequest()->getPostValue());
             $url = $this->_urlManager->getUrl('*/*/create', ['_nosecret' => true]);
             $controller->getResponse()->setRedirect($this->redirect->error($url));
         }
     }
     return $this;
 }
Esempio n. 15
0
 public function testExecute()
 {
     $customerId = 1;
     $refererUrl = 'http://referer.url';
     $this->sessionMock->expects($this->once())->method('getId')->willReturn($customerId);
     $this->sessionMock->expects($this->once())->method('logout')->willReturnSelf();
     $this->redirect->expects($this->once())->method('getRefererUrl')->willReturn($refererUrl);
     $this->sessionMock->expects($this->once())->method('setBeforeAuthUrl')->with($refererUrl)->willReturnSelf();
     $this->sessionMock->expects($this->once())->method('setLastCustomerId')->with($customerId);
     $this->cookieManager->expects($this->once())->method('getCookie')->with('mage-cache-sessid')->willReturn(true);
     $this->cookieMetadataFactory->expects($this->once())->method('createCookieMetadata')->willReturn($this->cookieMetadata);
     $this->cookieMetadata->expects($this->once())->method('setPath')->with('/');
     $this->cookieManager->expects($this->once())->method('deleteCookie')->with('mage-cache-sessid', $this->cookieMetadata);
     $this->redirectFactory->expects($this->once())->method('create')->willReturn($this->resultRedirect);
     $this->resultRedirect->expects($this->once())->method('setPath')->with('*/*/logoutSuccess');
     $this->assertSame($this->resultRedirect, $this->controller->execute());
 }
Esempio n. 16
0
    public function testExecuteInvalidArgument()
    {
        $themeId = 1;
        $fileParam = '/path/to/file.ext';
        $fileId = 'fileId';
        $refererUrl = 'referer/url';

        $this->request->expects($this->any())
            ->method('getParam')
            ->willReturnMap(
                [
                    ['theme_id', null, $themeId],
                    ['file', null, $fileParam],
                ]
            );
        $theme = $this->getMockBuilder('Magento\Framework\View\Design\ThemeInterface')
            ->setMethods(['getId', 'load'])
            ->getMockForAbstractClass();
        $urlDecoder = $this->getMockBuilder('Magento\Framework\Url\DecoderInterface')->getMock();
        $logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
        $this->objectManager->expects($this->any())
            ->method('get')
            ->willReturnMap(
                [
                    ['Magento\Framework\Url\DecoderInterface', $urlDecoder],
                    ['Psr\Log\LoggerInterface', $logger],
                ]
            );
        $this->objectManager->expects($this->any())
            ->method('create')
            ->with('Magento\Framework\View\Design\ThemeInterface')
            ->willReturn($theme);
        $urlDecoder->expects($this->once())
            ->method('decode')
            ->with($fileParam)
            ->willReturn($fileId);
        $theme->expects($this->once())
            ->method('load')
            ->with($themeId)
            ->willReturnSelf();
        $theme->expects($this->once())
            ->method('getId')
            ->willReturn(null);
        $this->messageManager->expects($this->once())
            ->method('addException');
        $logger->expects($this->once())
            ->method('critical');
        $this->redirect->expects($this->once())
            ->method('getRefererUrl')
            ->willReturn($refererUrl);
        $this->response->expects($this->once())
            ->method('setRedirect')
            ->with($refererUrl);

        $this->controller->executeInternal();
    }
Esempio n. 17
0
 /**
  * @param bool $isAjax
  * @return array
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function prepareExecuteWithQuantityArray($isAjax = false)
 {
     $itemId = 2;
     $wishlistId = 1;
     $qty = [$itemId => 3];
     $productId = 4;
     $productName = 'product_name';
     $indexUrl = 'index_url';
     $configureUrl = 'configure_url';
     $options = [5 => 'option'];
     $params = ['item' => $itemId, 'qty' => $qty];
     $refererUrl = 'referer_url';
     $itemMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\Item')->disableOriginalConstructor()->setMethods(['load', 'getId', 'getWishlistId', 'setQty', 'setOptions', 'getBuyRequest', 'mergeBuyRequest', 'addToCart', 'getProduct', 'getProductId'])->getMock();
     $this->requestMock->expects($this->at(0))->method('getParam')->with('item', null)->willReturn($itemId);
     $this->itemFactoryMock->expects($this->once())->method('create')->willReturn($itemMock);
     $itemMock->expects($this->once())->method('load')->with($itemId, null)->willReturnSelf();
     $itemMock->expects($this->exactly(2))->method('getId')->willReturn($itemId);
     $itemMock->expects($this->once())->method('getWishlistId')->willReturn($wishlistId);
     $wishlistMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\Wishlist')->disableOriginalConstructor()->getMock();
     $this->wishlistProviderMock->expects($this->once())->method('getWishlist')->with($wishlistId)->willReturn($wishlistMock);
     $this->requestMock->expects($this->at(1))->method('getParam')->with('qty', null)->willReturn($qty);
     $this->quantityProcessorMock->expects($this->once())->method('process')->with($qty[$itemId])->willReturnArgument(0);
     $itemMock->expects($this->once())->method('setQty')->with($qty[$itemId])->willReturnSelf();
     $this->urlMock->expects($this->at(0))->method('getUrl')->with('*/*', null)->willReturn($indexUrl);
     $itemMock->expects($this->once())->method('getProductId')->willReturn($productId);
     $this->urlMock->expects($this->at(1))->method('getUrl')->with('*/*/configure/', ['id' => $itemId, 'product_id' => $productId])->willReturn($configureUrl);
     $optionMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\Item\\Option')->disableOriginalConstructor()->getMock();
     $this->optionFactoryMock->expects($this->once())->method('create')->willReturn($optionMock);
     $optionsMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\Resource\\Item\\Option\\Collection')->disableOriginalConstructor()->getMock();
     $optionMock->expects($this->once())->method('getCollection')->willReturn($optionsMock);
     $optionsMock->expects($this->once())->method('addItemFilter')->with([$itemId])->willReturnSelf();
     $optionsMock->expects($this->once())->method('getOptionsByItem')->with($itemId)->willReturn($options);
     $itemMock->expects($this->once())->method('setOptions')->with($options)->willReturnSelf();
     $this->requestMock->expects($this->once())->method('getParams')->willReturn($params);
     $this->requestMock->expects($this->once())->method('isAjax')->willReturn($isAjax);
     $buyRequestMock = $this->getMockBuilder('Magento\\Framework\\Object')->disableOriginalConstructor()->getMock();
     $itemMock->expects($this->once())->method('getBuyRequest')->willReturn($buyRequestMock);
     $this->productHelperMock->expects($this->once())->method('addParamsToBuyRequest')->with($params, ['current_config' => $buyRequestMock])->willReturn($buyRequestMock);
     $itemMock->expects($this->once())->method('mergeBuyRequest')->with($buyRequestMock)->willReturnSelf();
     $itemMock->expects($this->once())->method('addToCart')->with($this->checkoutCartMock, true)->willReturn(true);
     $this->checkoutCartMock->expects($this->once())->method('save')->willReturnSelf();
     $quoteMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote')->disableOriginalConstructor()->setMethods(['getHasError', 'collectTotals'])->getMock();
     $this->checkoutCartMock->expects($this->exactly(2))->method('getQuote')->willReturn($quoteMock);
     $quoteMock->expects($this->once())->method('collectTotals')->willReturnSelf();
     $wishlistMock->expects($this->once())->method('save')->willReturnSelf();
     $quoteMock->expects($this->once())->method('getHasError')->willReturn(false);
     $productMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock();
     $itemMock->expects($this->once())->method('getProduct')->willReturn($productMock);
     $productMock->expects($this->once())->method('getName')->willReturn($productName);
     $this->escaperMock->expects($this->once())->method('escapeHtml')->with($productName, null)->willReturn($productName);
     $this->messageManagerMock->expects($this->once())->method('addSuccess')->with('You added ' . $productName . ' to your shopping cart.', null)->willReturnSelf();
     $this->cartHelperMock->expects($this->once())->method('getShouldRedirectToCart')->willReturn(false);
     $this->redirectMock->expects($this->once())->method('getRefererUrl')->willReturn($refererUrl);
     $this->helperMock->expects($this->once())->method('calculate')->willReturnSelf();
     return $refererUrl;
 }
 public function testExecuteAjaxException()
 {
     $redirectPath = 'path/to/redirect';
     $quoteMock = $this->getQuoteMock();
     $quoteMock->expects(self::once())->method('getItemsCount')->willReturn(0);
     $this->requestMock->expects(self::exactly(1))->method('getParam')->willReturnMap([['isAjax', null, false]]);
     $this->checkoutSessionMock->expects(self::once())->method('getQuote')->willReturn($quoteMock);
     $this->shippingMethodUpdaterMock->expects(self::never())->method('execute');
     $this->messageManagerMock->expects(self::once())->method('addExceptionMessage')->with(self::isInstanceOf('\\InvalidArgumentException'), 'We can\'t initialize checkout.');
     $this->urlMock->expects(self::once())->method('getUrl')->with('*/*/review', ['_secure' => true])->willReturn($redirectPath);
     $this->redirectMock->expects(self::once())->method('redirect')->with($this->responseMock, $redirectPath, []);
     $this->saveShippingMethod->execute();
 }
 public function testExecuteInvalidArgument()
 {
     $themeId = 1;
     $refererUrl = 'referer/url';
     $this->request->expects($this->any())->method('getParam')->with('theme_id')->willReturn($themeId);
     $themeFactory = $this->getMockBuilder('Magento\\Framework\\View\\Design\\Theme\\FlyweightFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $logger = $this->getMockBuilder('Psr\\Log\\LoggerInterface')->getMock();
     $this->objectManager->expects($this->any())->method('get')->with('Psr\\Log\\LoggerInterface')->willReturn($logger);
     $this->objectManager->expects($this->any())->method('create')->with('Magento\\Framework\\View\\Design\\Theme\\FlyweightFactory')->willReturn($themeFactory);
     $themeFactory->expects($this->once())->method('create')->with($themeId)->willReturn(null);
     $this->messageManager->expects($this->once())->method('addException');
     $logger->expects($this->once())->method('critical');
     $this->redirect->expects($this->once())->method('getRefererUrl')->willReturn($refererUrl);
     $this->response->expects($this->once())->method('setRedirect')->with($refererUrl);
     $this->controller->execute();
 }
Esempio n. 20
0
 /**
  * @param $customerId
  * @param $key
  * @param $backUrl
  * @param $successUrl
  * @param $resultUrl
  * @param $isSetFlag
  * @param $successMessage
  *
  * @dataProvider getSuccessRedirectDataProvider
  */
 public function testSuccessRedirect($customerId, $key, $backUrl, $successUrl, $resultUrl, $isSetFlag, $successMessage)
 {
     $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->will($this->returnValue(false));
     $this->requestMock->expects($this->any())->method('getParam')->willReturnMap([['id', false, $customerId], ['key', false, $key], ['back_url', false, $backUrl]]);
     $this->customerRepositoryMock->expects($this->any())->method('getById')->with($customerId)->will($this->returnValue($this->customerDataMock));
     $email = '*****@*****.**';
     $this->customerDataMock->expects($this->once())->method('getEmail')->will($this->returnValue($email));
     $this->customerAccountManagementMock->expects($this->once())->method('activate')->with($this->equalTo($email), $this->equalTo($key))->will($this->returnValue($this->customerDataMock));
     $this->customerSessionMock->expects($this->any())->method('setCustomerDataAsLoggedIn')->with($this->equalTo($this->customerDataMock))->willReturnSelf();
     $this->messageManagerMock->expects($this->any())->method('addSuccess')->with($this->stringContains($successMessage))->willReturnSelf();
     $this->storeMock->expects($this->any())->method('getFrontendName')->will($this->returnValue('frontend'));
     $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($this->storeMock));
     $this->urlMock->expects($this->any())->method('getUrl')->with($this->equalTo('*/*/index'), ['_secure' => true])->will($this->returnValue($successUrl));
     $this->redirectMock->expects($this->never())->method('success')->with($this->equalTo($resultUrl))->willReturn($resultUrl);
     $this->scopeConfigMock->expects($this->never())->method('isSetFlag')->with(Url::XML_PATH_CUSTOMER_STARTUP_REDIRECT_TO_DASHBOARD, ScopeInterface::SCOPE_STORE)->willReturn($isSetFlag);
     $this->model->execute();
 }
Esempio n. 21
0
 public function testExecuteLinkTypeFile()
 {
     $sampleMock = $this->getMockBuilder('Magento\\Downloadable\\Model\\Sample')->disableOriginalConstructor()->setMethods(['getId', 'load', 'getSampleType', 'getSampleUrl', 'getBaseSamplePath'])->getMock();
     $fileHelperMock = $this->getMockBuilder('Magento\\Downloadable\\Helper\\File')->disableOriginalConstructor()->setMethods(['getFilePath'])->getMock();
     $this->request->expects($this->once())->method('getParam')->with('sample_id', 0)->willReturn('some_sample_id');
     $this->objectManager->expects($this->at(0))->method('create')->with('Magento\\Downloadable\\Model\\Sample')->willReturn($sampleMock);
     $sampleMock->expects($this->once())->method('load')->with('some_sample_id')->willReturnSelf();
     $sampleMock->expects($this->once())->method('getId')->willReturn('some_sample_id');
     $sampleMock->expects($this->any())->method('getSampleType')->willReturn(\Magento\Downloadable\Helper\Download::LINK_TYPE_FILE);
     $this->objectManager->expects($this->at(1))->method('get')->with('Magento\\Downloadable\\Helper\\File')->willReturn($fileHelperMock);
     $fileHelperMock->expects($this->once())->method('getFilePath')->willReturn('file_path');
     $this->objectManager->expects($this->at(2))->method('get')->with('Magento\\Downloadable\\Helper\\Download')->willReturn($this->downloadHelper);
     $this->response->expects($this->once())->method('setHttpResponseCode')->with(200)->willReturnSelf();
     $this->response->expects($this->any())->method('setHeader')->willReturnSelf();
     $this->downloadHelper->expects($this->once())->method('output')->willThrowException(new \Exception());
     $this->messageManager->expects($this->once())->method('addError')->with('Sorry, there was an error getting requested content. Please contact the store owner.')->willReturnSelf();
     $this->redirect->expects($this->once())->method('getRedirectUrl')->willReturn('redirect_url');
     $this->response->expects($this->once())->method('setRedirect')->with('redirect_url')->willReturnSelf();
     $this->assertEquals($this->response, $this->sample->execute());
 }
Esempio n. 22
0
 public function testExceptionInUpdateLinkStatus()
 {
     $this->objectManager->expects($this->at(0))->method('get')->with('Magento\\Customer\\Model\\Session')->willReturn($this->session);
     $this->request->expects($this->once())->method('getParam')->with('id', 0)->willReturn('some_id');
     $this->objectManager->expects($this->at(1))->method('create')->with('Magento\\Downloadable\\Model\\Link\\Purchased\\Item')->willReturn($this->linkPurchasedItem);
     $this->linkPurchasedItem->expects($this->once())->method('load')->with('some_id', 'link_hash')->willReturnSelf();
     $this->linkPurchasedItem->expects($this->once())->method('getId')->willReturn(5);
     $this->objectManager->expects($this->at(2))->method('get')->with('Magento\\Downloadable\\Helper\\Data')->willReturn($this->helperData);
     $this->helperData->expects($this->once())->method('getIsShareable')->with($this->linkPurchasedItem)->willReturn(true);
     $this->linkPurchasedItem->expects($this->any())->method('getNumberOfDownloadsBought')->willReturn(10);
     $this->linkPurchasedItem->expects($this->any())->method('getNumberOfDownloadsUsed')->willReturn(9);
     $this->linkPurchasedItem->expects($this->once())->method('getStatus')->willReturn('available');
     $this->linkPurchasedItem->expects($this->once())->method('getLinkType')->willReturn('url');
     $this->linkPurchasedItem->expects($this->once())->method('getLinkUrl')->willReturn('link_url');
     $this->processDownload('link_url', 'url');
     $this->linkPurchasedItem->expects($this->any())->method('setNumberOfDownloadsUsed')->willReturnSelf();
     $this->linkPurchasedItem->expects($this->any())->method('setStatus')->with('expired')->willReturnSelf();
     $this->linkPurchasedItem->expects($this->any())->method('save')->willThrowException(new \Exception());
     $this->messageManager->expects($this->once())->method('addError')->with('Something went wrong while getting the requested content.')->willReturnSelf();
     $this->redirect->expects($this->once())->method('redirect')->with($this->response, '*/customer/products', []);
     $this->assertEquals($this->response, $this->link->execute());
 }
 /**
  * @param $customerId
  * @param $password
  * @param $confirmationStatus
  * @param $successUrl
  * @param $isSetFlag
  * @param $successMessage
  *
  * @dataProvider getSuccessRedirectDataProvider
  */
 public function testSuccessRedirect($customerId, $password, $confirmationStatus, $successUrl, $isSetFlag, $successMessage)
 {
     $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->will($this->returnValue(false));
     $this->registration->expects($this->once())->method('isAllowed')->will($this->returnValue(true));
     $this->customerSessionMock->expects($this->once())->method('regenerateId');
     $this->customerMock->expects($this->any())->method('getId')->will($this->returnValue($customerId));
     $this->customerExtractorMock->expects($this->any())->method('extract')->with($this->equalTo('customer_account_create'), $this->equalTo($this->requestMock))->will($this->returnValue($this->customerMock));
     $this->requestMock->expects($this->once())->method('isPost')->will($this->returnValue(true));
     $this->requestMock->expects($this->any())->method('getPost')->will($this->returnValue(false));
     $this->requestMock->expects($this->any())->method('getParam')->willReturnMap([['password', null, $password], ['password_confirmation', null, $password], ['is_subscribed', false, true]]);
     $this->customerMock->expects($this->once())->method('setAddresses')->with($this->equalTo([]))->will($this->returnSelf());
     $this->accountManagement->expects($this->once())->method('createAccount')->with($this->equalTo($this->customerDetailsMock), $this->equalTo($password), '')->will($this->returnValue($this->customerMock));
     $this->accountManagement->expects($this->once())->method('getConfirmationStatus')->with($this->equalTo($customerId))->will($this->returnValue($confirmationStatus));
     $this->subscriberMock->expects($this->once())->method('subscribeCustomerById')->with($this->equalTo($customerId));
     $this->messageManagerMock->expects($this->any())->method('addSuccess')->with($this->stringContains($successMessage))->will($this->returnSelf());
     $this->urlMock->expects($this->any())->method('getUrl')->willReturnMap([['*/*/index', ['_secure' => true], $successUrl], ['*/*/create', ['_secure' => true], $successUrl]]);
     $this->redirectMock->expects($this->once())->method('success')->with($this->equalTo($successUrl))->will($this->returnValue($successUrl));
     $this->scopeConfigMock->expects($this->once())->method('isSetFlag')->with($this->equalTo(Url::XML_PATH_CUSTOMER_STARTUP_REDIRECT_TO_DASHBOARD), $this->equalTo(ScopeInterface::SCOPE_STORE))->will($this->returnValue($isSetFlag));
     $this->storeMock->expects($this->any())->method('getFrontendName')->will($this->returnValue('frontend'));
     $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($this->storeMock));
     $this->model->execute();
 }
Esempio n. 24
0
 public function testExecuteSuccessWithUseStoreInUrl()
 {
     $currentActiveStoreCode = 'sv1';
     $storeToSwitchToCode = 'sv2';
     $defaultStoreViewCode = 'default';
     $originalRedirectUrl = "magento.com/{$currentActiveStoreCode}/test-page/test-sub-page";
     $expectedRedirectUrl = "magento.com/{$storeToSwitchToCode}/test-page/test-sub-page";
     $currentActiveStoreMock = $this->getMockBuilder('Magento\\Store\\Api\\Data\\StoreInterface')->disableOriginalConstructor()->setMethods(['isUseStoreInUrl', 'getBaseUrl'])->getMockForAbstractClass();
     $defaultStoreViewMock = $this->getMockBuilder('Magento\\Store\\Api\\Data\\StoreInterface')->getMock();
     $storeToSwitchToMock = $this->getMockBuilder('Magento\\Store\\Api\\Data\\StoreInterface')->disableOriginalConstructor()->setMethods(['isUseStoreInUrl', 'getBaseUrl'])->getMockForAbstractClass();
     $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($currentActiveStoreMock);
     $this->requestMock->expects($this->once())->method('getParam')->willReturn($storeToSwitchToCode);
     $this->storeRepositoryMock->expects($this->once())->method('getActiveStoreByCode')->willReturn($storeToSwitchToMock);
     $this->storeManagerMock->expects($this->once())->method('getDefaultStoreView')->willReturn($defaultStoreViewMock);
     $defaultStoreViewMock->expects($this->once())->method('getId')->willReturn($defaultStoreViewCode);
     $storeToSwitchToMock->expects($this->once())->method('getId')->willReturn($storeToSwitchToCode);
     $storeToSwitchToMock->expects($this->once())->method('isUseStoreInUrl')->willReturn(true);
     $this->redirectMock->expects($this->any())->method('getRedirectUrl')->willReturn($originalRedirectUrl);
     $currentActiveStoreMock->expects($this->any())->method('getBaseUrl')->willReturn("magento.com/{$currentActiveStoreCode}");
     $storeToSwitchToMock->expects($this->once())->method('getBaseUrl')->willReturn("magento.com/{$storeToSwitchToCode}");
     $this->responseMock->expects($this->once())->method('setRedirect')->with($expectedRedirectUrl);
     $this->model->execute();
 }
Esempio n. 25
0
 public function testExecuteEmptyPost()
 {
     $this->_request->expects($this->once())->method('getPost')->will($this->returnValue([]));
     $this->_redirect->expects($this->once())->method('redirect');
     $this->_controller->execute();
 }
Esempio n. 26
0
 /**
  * Set redirect into response
  *
  * @param   string $path
  * @param   array $arguments
  * @return  ResponseInterface
  */
 protected function _redirect($path, $arguments = [])
 {
     $this->_redirect->redirect($this->getResponse(), $path, $arguments);
     return $this->getResponse();
 }
Esempio n. 27
0
 /**
  * Set url by path
  *
  * @param string $path
  * @param array $params
  * @return $this
  */
 public function setPath($path, array $params = [])
 {
     $this->url = $this->urlBuilder->getUrl($path, $this->redirect->updatePathParams($params));
     return $this;
 }
Esempio n. 28
0
 public function testExecuteEmptyPost()
 {
     $this->requestMock->expects($this->once())->method('getPostValue')->willReturn([]);
     $this->redirectMock->expects($this->once())->method('redirect');
     $this->controller->execute();
 }
Esempio n. 29
0
 public function testSetRefererOrBaseUrl()
 {
     $this->urlBuilder->expects($this->once())->method('getUrl')->willReturn($this->url);
     $this->redirect->expects($this->once())->method('getRedirectUrl')->with($this->url)->willReturn('test string');
     $this->action->setRefererOrBaseUrl();
 }
Esempio n. 30
0
 /**
  * Move all wishlist item to cart
  *
  * @param Wishlist $wishlist
  * @param array $qtys
  * @return string
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function moveAllToCart(Wishlist $wishlist, $qtys)
 {
     $isOwner = $wishlist->isOwner($this->customerSession->getCustomerId());
     $messages = [];
     $addedItems = [];
     $notSalable = [];
     $hasOptions = [];
     $cart = $this->cart;
     $collection = $wishlist->getItemCollection()->setVisibilityFilter();
     foreach ($collection as $item) {
         /** @var \Magento\Wishlist\Model\Item */
         try {
             $disableAddToCart = $item->getProduct()->getDisableAddToCart();
             $item->unsProduct();
             // Set qty
             if (isset($qtys[$item->getId()])) {
                 $qty = $this->quantityProcessor->process($qtys[$item->getId()]);
                 if ($qty) {
                     $item->setQty($qty);
                 }
             }
             $item->getProduct()->setDisableAddToCart($disableAddToCart);
             // Add to cart
             if ($item->addToCart($cart, $isOwner)) {
                 $addedItems[] = $item->getProduct();
             }
         } catch (\Magento\Framework\Exception\LocalizedException $e) {
             if ($e->getCode() == \Magento\Wishlist\Model\Item::EXCEPTION_CODE_NOT_SALABLE) {
                 $notSalable[] = $item;
             } elseif ($e->getCode() == \Magento\Wishlist\Model\Item::EXCEPTION_CODE_HAS_REQUIRED_OPTIONS) {
                 $hasOptions[] = $item;
             } else {
                 $messages[] = __('%1 for "%2".', trim($e->getMessage(), '.'), $item->getProduct()->getName());
             }
             $cartItem = $cart->getQuote()->getItemByProduct($item->getProduct());
             if ($cartItem) {
                 $cart->getQuote()->deleteItem($cartItem);
             }
         } catch (\Exception $e) {
             $this->logger->critical($e);
             $messages[] = __('We cannot add this item to your shopping cart.');
         }
     }
     if ($isOwner) {
         $indexUrl = $this->helper->getListUrl($wishlist->getId());
     } else {
         $indexUrl = $this->urlBuilder->getUrl('wishlist/shared', ['code' => $wishlist->getSharingCode()]);
     }
     if ($this->cartHelper->getShouldRedirectToCart()) {
         $redirectUrl = $this->cartHelper->getCartUrl();
     } elseif ($this->redirector->getRefererUrl()) {
         $redirectUrl = $this->redirector->getRefererUrl();
     } else {
         $redirectUrl = $indexUrl;
     }
     if ($notSalable) {
         $products = [];
         foreach ($notSalable as $item) {
             $products[] = '"' . $item->getProduct()->getName() . '"';
         }
         $messages[] = __('We couldn\'t add the following product(s) to the shopping cart: %1.', join(', ', $products));
     }
     if ($hasOptions) {
         $products = [];
         foreach ($hasOptions as $item) {
             $products[] = '"' . $item->getProduct()->getName() . '"';
         }
         $messages[] = __('Product(s) %1 have required options. Each product can only be added individually.', join(', ', $products));
     }
     if ($messages) {
         $isMessageSole = count($messages) == 1;
         if ($isMessageSole && count($hasOptions) == 1) {
             $item = $hasOptions[0];
             if ($isOwner) {
                 $item->delete();
             }
             $redirectUrl = $item->getProductUrl();
         } else {
             foreach ($messages as $message) {
                 $this->messageManager->addError($message);
             }
             $redirectUrl = $indexUrl;
         }
     }
     if ($addedItems) {
         // save wishlist model for setting date of last update
         try {
             $wishlist->save();
         } catch (\Exception $e) {
             $this->messageManager->addError(__('We can\'t update wish list.'));
             $redirectUrl = $indexUrl;
         }
         $products = [];
         foreach ($addedItems as $product) {
             $products[] = '"' . $product->getName() . '"';
         }
         $this->messageManager->addSuccess(__('%1 product(s) have been added to shopping cart: %2.', count($addedItems), join(', ', $products)));
         // save cart and collect totals
         $cart->save()->getQuote()->collectTotals();
     }
     $this->helper->calculate();
     return $redirectUrl;
 }