/** * Make sure customer is valid, if logged in * * By default will add error messages and redirect to customer edit form * * @param bool $redirect - stop dispatch and redirect? * @param bool $addErrors - add error messages? * @return bool */ protected function _preDispatchValidateCustomer($redirect = true, $addErrors = true) { try { $customerId = $this->_customerSession->getCustomerId(); $customer = $this->_customerAccountService->getCustomer($customerId); } catch (NoSuchEntityException $e) { return true; } if (isset($customer)) { $validationResult = $this->_customerAccountService->validateCustomerData($customer, $this->_customerMetadataService->getAllCustomerAttributeMetadata()); if (!$validationResult->isValid()) { if ($addErrors) { foreach ($validationResult->getMessages() as $error) { $this->messageManager->addError($error); } } if ($redirect) { $this->_redirect('customer/account/edit'); $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true); } return false; } } return true; }
/** * @return void */ protected function _construct() { parent::_construct(); $orders = $this->_orderCollectionFactory->create()->addFieldToSelect('*')->addFieldToFilter('customer_id', $this->_customerSession->getCustomerId())->addFieldToFilter('status', array('in' => $this->_orderConfig->getVisibleOnFrontStatuses()))->setOrder('created_at', 'desc'); $this->setOrders($orders); $this->pageConfig->setTitle(__('My Orders')); }
/** * Check customer authentication for some actions * * @param \Magento\Framework\App\RequestInterface $request * @return \Magento\Framework\App\ResponseInterface */ public function dispatch(RequestInterface $request) { if (!$this->customerSession->authenticate()) { $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true); } return parent::dispatch($request); }
public function testExecute() { $event = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock(); /** @var $event \Magento\Framework\Event\Observer */ $this->customerSession->expects($this->once())->method('setWishlistItemCount')->with($this->equalTo(0)); $this->observer->execute($event); }
/** * Dispatch request * * @param RequestInterface $request * @return ResponseInterface * @throws NotFoundException */ public function dispatch(RequestInterface $request) { if (!$this->customerSession->authenticate()) { $this->_actionFlag->set('', 'no-dispatch', true); } return parent::dispatch($request); }
/** * @magentoConfigFixture current_store persistent/options/customer 1 * @magentoConfigFixture current_store persistent/options/enabled 1 * @magentoConfigFixture current_store persistent/options/remember_enabled 1 * @magentoConfigFixture current_store persistent/options/remember_default 1 * @magentoAppArea frontend * @magentoAppIsolation enabled */ public function testToHtml() { $this->_customerSession->loginById(1); $translation = __('Not you?'); $this->assertStringMatchesFormat('%A<span>%A<a%Ahref="' . $this->_block->getHref() . '"%A>' . $translation . '</a>%A</span>%A', $this->_block->toHtml()); $this->_customerSession->logout(); }
/** * @param Observer $observer * @return void * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function execute(Observer $observer) { if ($this->moduleManager->isEnabled('Magento_PageCache') && $this->cacheConfig->isEnabled() && $this->taxHelper->isCatalogPriceDisplayAffectedByTax()) { /** @var \Magento\Customer\Model\Data\Customer $customer */ $customer = $observer->getData('customer'); $customerGroupId = $customer->getGroupId(); $customerGroup = $this->groupRepository->getById($customerGroupId); $customerTaxClassId = $customerGroup->getTaxClassId(); $this->customerSession->setCustomerTaxClassId($customerTaxClassId); /** @var \Magento\Customer\Api\Data\AddressInterface[] $addresses */ $addresses = $customer->getAddresses(); if (isset($addresses)) { $defaultShippingFound = false; $defaultBillingFound = false; foreach ($addresses as $address) { if ($address->isDefaultBilling()) { $defaultBillingFound = true; $this->customerSession->setDefaultTaxBillingAddress(['country_id' => $address->getCountryId(), 'region_id' => $address->getRegion() ? $address->getRegion()->getRegionId() : null, 'postcode' => $address->getPostcode()]); } if ($address->isDefaultShipping()) { $defaultShippingFound = true; $this->customerSession->setDefaultTaxShippingAddress(['country_id' => $address->getCountryId(), 'region_id' => $address->getRegion() ? $address->getRegion()->getRegionId() : null, 'postcode' => $address->getPostcode()]); } if ($defaultShippingFound && $defaultBillingFound) { break; } } } } }
/** * Authenticate user * * @param \Magento\Framework\App\ActionInterface $subject * @param RequestInterface $request * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function beforeDispatch(\Magento\Framework\App\ActionInterface $subject, RequestInterface $request) { $loginUrl = $this->customerUrl->getLoginUrl(); if (!$this->customerSession->authenticate($loginUrl)) { $subject->getActionFlag()->set('', $subject::FLAG_NO_DISPATCH, true); } }
/** * Retrieve billing agreements collection * * @return \Magento\Paypal\Model\ResourceModel\Billing\Agreement\Collection */ public function getBillingAgreements() { if ($this->_billingAgreements === null) { $this->_billingAgreements = $this->_agreementCollection->create()->addFieldToFilter('customer_id', $this->_customerSession->getCustomerId())->setOrder('agreement_id', 'desc'); } return $this->_billingAgreements; }
protected function setUp() { $this->markTestIncomplete(); $this->messageManager = $this->getMockForAbstractClass('Magento\\Framework\\Message\\ManagerInterface'); $this->config = $this->getMock('Magento\\Paypal\\Model\\Config', [], [], '', false); $this->request = $this->getMock('Magento\\Framework\\App\\Request\\Http', [], [], '', false); $this->quote = $this->getMock('Magento\\Quote\\Model\\Quote', [], [], '', false); $this->quote->expects($this->any())->method('hasItems')->will($this->returnValue(true)); $this->redirect = $this->getMockForAbstractClass('Magento\\Framework\\App\\Response\\RedirectInterface'); $this->response = $this->getMock('Magento\\Framework\\App\\Response\\Http', [], [], '', false); $this->customerData = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false); $this->checkout = $this->getMock('Magento\\Paypal\\Model\\Express\\Checkout', [], [], '', false); $this->customerSession = $this->getMock('Magento\\Customer\\Model\\Session', [], [], '', false); $this->customerSession->expects($this->any())->method('getCustomerDataObject')->will($this->returnValue($this->customerData)); $this->checkoutSession = $this->getMock('Magento\\Checkout\\Model\\Session', [], [], '', false); $this->checkoutFactory = $this->getMock('Magento\\Paypal\\Model\\Express\\Checkout\\Factory', [], [], '', false); $this->checkoutFactory->expects($this->any())->method('create')->will($this->returnValue($this->checkout)); $this->checkoutSession->expects($this->any())->method('getQuote')->will($this->returnValue($this->quote)); $this->session = $this->getMock('Magento\\Framework\\Session\\Generic', [], [], '', false); $objectManager = $this->getMock('Magento\\Framework\\ObjectManagerInterface'); $this->objectManagerCallback = function ($className) { if ($className == 'Magento\\Paypal\\Model\\Config') { return $this->config; } return $this->getMock($className, [], [], '', false); }; $objectManager->expects($this->any())->method('get')->will($this->returnCallback(function ($className) { return call_user_func($this->objectManagerCallback, $className); })); $objectManager->expects($this->any())->method('create')->will($this->returnCallback(function ($className) { return call_user_func($this->objectManagerCallback, $className); })); $helper = new ObjectManagerHelper($this); $this->model = $helper->getObject('\\Magento\\\\Paypal\\Controller\\Express\\' . $this->name, ['messageManager' => $this->messageManager, 'response' => $this->response, 'redirect' => $this->redirect, 'request' => $this->request, 'customerSession' => $this->customerSession, 'checkoutSession' => $this->checkoutSession, 'checkoutFactory' => $this->checkoutFactory, 'paypalSession' => $this->session, 'objectManager' => $objectManager]); }
/** * {@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; }
/** * Reset forgotten password * * Used to handle data received from reset forgotten password form * * @return \Magento\Framework\Controller\Result\Redirect */ public function execute() { /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); $resetPasswordToken = (string) $this->getRequest()->getQuery('token'); $customerId = (int) $this->getRequest()->getQuery('id'); $password = (string) $this->getRequest()->getPost('password'); $passwordConfirmation = (string) $this->getRequest()->getPost('password_confirmation'); if ($password !== $passwordConfirmation) { $this->messageManager->addError(__("New Password and Confirm New Password values didn't match.")); $resultRedirect->setPath('*/*/createPassword', ['id' => $customerId, 'token' => $resetPasswordToken]); return $resultRedirect; } if (iconv_strlen($password) <= 0) { $this->messageManager->addError(__('Please enter a new password.')); $resultRedirect->setPath('*/*/createPassword', ['id' => $customerId, 'token' => $resetPasswordToken]); return $resultRedirect; } try { $customerEmail = $this->customerRepository->getById($customerId)->getEmail(); $this->accountManagement->resetPassword($customerEmail, $resetPasswordToken, $password); $this->session->unsRpToken(); $this->session->unsRpCustomerId(); $this->messageManager->addSuccess(__('You updated your password.')); $resultRedirect->setPath('*/*/login'); return $resultRedirect; } catch (\Exception $exception) { $this->messageManager->addError(__('Something went wrong while saving the new password.')); $resultRedirect->setPath('*/*/createPassword', ['id' => $customerId, 'token' => $resetPasswordToken]); return $resultRedirect; } }
public function testSubscribe() { $email = '*****@*****.**'; $this->resource->expects($this->any())->method('loadByEmail')->willReturn(['subscriber_status' => 3, 'subscriber_email' => $email, 'name' => 'subscriber_name']); $this->resource->expects($this->any())->method('getIdFieldName')->willReturn('id_field'); $this->scopeConfig->expects($this->any())->method('getValue')->willReturn(true); $this->customerSession->expects($this->any())->method('isLoggedIn')->willReturn(true); $customerDataModel = $this->getMock('\\Magento\\Customer\\Api\\Data\\CustomerInterface'); $this->customerSession->expects($this->any())->method('getCustomerDataObject')->willReturn($customerDataModel); $this->customerSession->expects($this->any())->method('getCustomerId')->willReturn(1); $customerDataModel->expects($this->any())->method('getEmail')->willReturn($email); $this->customerRepository->expects($this->any())->method('getById')->willReturn($customerDataModel); $customerDataModel->expects($this->any())->method('getStoreId')->willReturn(1); $customerDataModel->expects($this->any())->method('getId')->willReturn(1); $this->transportBuilder->expects($this->any())->method('setTemplateIdentifier')->willReturnSelf(); $this->transportBuilder->expects($this->any())->method('setTemplateOptions')->willReturnSelf(); $this->transportBuilder->expects($this->any())->method('setTemplateVars')->willReturnSelf(); $this->transportBuilder->expects($this->any())->method('setFrom')->willReturnSelf(); $this->transportBuilder->expects($this->any())->method('addTo')->willReturnSelf(); $storeModel = $this->getMock('\\Magento\\Store\\Model\\Store', ['getId'], [], '', false); $this->scopeConfig->expects($this->any())->method('getValue')->willReturn('*****@*****.**'); $this->storeManager->expects($this->any())->method('getStore')->willReturn($storeModel); $storeModel->expects($this->any())->method('getId')->willReturn(1); $transport = $this->getMock('\\Magento\\Framework\\Mail\\TransportInterface'); $this->transportBuilder->expects($this->any())->method('getTransport')->willReturn($transport); $transport->expects($this->any())->method('sendMessage')->willReturnSelf(); $inlineTranslation = $this->getMock('Magento\\Framework\\Translate\\Inline\\StateInterface'); $inlineTranslation->expects($this->any())->method('resume')->willReturnSelf(); $this->resource->expects($this->atLeastOnce())->method('save')->willReturnSelf(); $this->assertEquals(1, $this->subscriber->subscribe($email)); }
/** * Prepare the layout of the address edit block. * * @return $this */ protected function _prepareLayout() { parent::_prepareLayout(); // Init address object if ($addressId = $this->getRequest()->getParam('id')) { try { $this->_address = $this->_addressRepository->getById($addressId); if ($this->_address->getCustomerId() != $this->_customerSession->getCustomerId()) { $this->_address = null; } } catch (NoSuchEntityException $e) { $this->_address = null; } } if ($this->_address === null || !$this->_address->getId()) { $this->_address = $this->addressDataFactory->create(); $customer = $this->getCustomer(); $this->_address->setPrefix($customer->getPrefix()); $this->_address->setFirstname($customer->getFirstname()); $this->_address->setMiddlename($customer->getMiddlename()); $this->_address->setLastname($customer->getLastname()); $this->_address->setSuffix($customer->getSuffix()); } $this->pageConfig->getTitle()->set($this->getTitle()); if ($postedData = $this->_customerSession->getAddressFormData(true)) { if (!empty($postedData['region_id']) || !empty($postedData['region'])) { $postedData['region'] = ['region_id' => $postedData['region_id'], 'region' => $postedData['region']]; } $this->dataObjectHelper->populateWithArray($this->_address, $postedData, '\\Magento\\Customer\\Api\\Data\\AddressInterface'); } return $this; }
/** * Test aroundDispatch */ public function testAroundDispatch() { $this->customerSessionMock->expects($this->once())->method('getCustomerGroupId')->will($this->returnValue(1)); $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->will($this->returnValue(true)); $this->httpContextMock->expects($this->atLeastOnce())->method('setValue')->will($this->returnValueMap([[Context::CONTEXT_GROUP, 'UAH', $this->httpContextMock], [Context::CONTEXT_AUTH, 0, $this->httpContextMock]])); $this->assertEquals('ExpectedValue', $this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock)); }
/** * Resetting password handler * * @return \Magento\Framework\Controller\Result\Redirect|\Magento\Framework\View\Result\Page */ public function executeInternal() { $resetPasswordToken = (string) $this->getRequest()->getParam('token'); $customerId = (int) $this->getRequest()->getParam('id'); $isDirectLink = $resetPasswordToken != '' && $customerId != 0; if (!$isDirectLink) { $resetPasswordToken = (string) $this->session->getRpToken(); $customerId = (int) $this->session->getRpCustomerId(); } try { $this->accountManagement->validateResetPasswordLinkToken($customerId, $resetPasswordToken); if ($isDirectLink) { $this->session->setRpToken($resetPasswordToken); $this->session->setRpCustomerId($customerId); $resultRedirect = $this->resultRedirectFactory->create(); $resultRedirect->setPath('*/*/createpassword'); return $resultRedirect; } else { /** @var \Magento\Framework\View\Result\Page $resultPage */ $resultPage = $this->resultPageFactory->create(); $resultPage->getLayout()->getBlock('resetPassword')->setCustomerId($customerId)->setResetPasswordLinkToken($resetPasswordToken); return $resultPage; } } catch (\Exception $exception) { $this->messageManager->addError(__('Your password reset link has expired.')); /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); $resultRedirect->setPath('*/*/forgotpassword'); return $resultRedirect; } }
public function beforeSubscribeCustomerById($subscriber, $customerId) { $subscriber->loadByCustomerId($customerId); $storeId = $subscriber->getStoreId(); if ($this->_helper->isMonkeyEnabled($storeId)) { $customer = $this->_customer->load($customerId); $mergeVars = $this->_helper->getMergeVars($customer); $api = $this->_api; $isSubscribeOwnEmail = $this->_customerSession->isLoggedIn() && $this->_customerSession->getCustomerDataObject()->getEmail() == $subscriber->getSubscriberEmail(); if ($this->_helper->isDoubleOptInEnabled($storeId) && !$isSubscribeOwnEmail) { $status = 'pending'; } else { $status = 'subscribed'; } if ($mergeVars) { $data = array('list_id' => $this->_helper->getDefaultList(), 'email_address' => $customer->getEmail(), 'email_type' => 'html', 'status' => $status, 'merge_fields' => $mergeVars); } else { $data = array('list_id' => $this->_helper->getDefaultList(), 'email_address' => $customer->getEmail(), 'email_type' => 'html', 'status' => $status); } $return = $api->listCreateMember($this->_helper->getDefaultList(), json_encode($data)); if (isset($return->id)) { $subscriber->setMagemonkeyId($return->id); } } return [$customerId]; }
/** * Retrieve username for form field * * @return string */ public function getUsername() { if (-1 === $this->_username) { $this->_username = $this->_customerSession->getUsername(true); } return $this->_username; }
/** * Send confirmation link to specified email * * @return \Magento\Framework\Controller\Result\Redirect|\Magento\Framework\View\Result\Page */ public function execute() { if ($this->session->isLoggedIn()) { /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); $resultRedirect->setPath('*/*/'); return $resultRedirect; } // try to confirm by email $email = $this->getRequest()->getPost('email'); if ($email) { /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); try { $this->customerAccountManagement->resendConfirmation($email, $this->storeManager->getStore()->getWebsiteId()); $this->messageManager->addSuccess(__('Please check your email for confirmation key.')); } catch (InvalidTransitionException $e) { $this->messageManager->addSuccess(__('This email does not require confirmation.')); } catch (\Exception $e) { $this->messageManager->addException($e, __('Wrong email.')); $resultRedirect->setPath('*/*/*', ['email' => $email, '_secure' => true]); return $resultRedirect; } $this->session->setUsername($email); $resultRedirect->setPath('*/*/index', ['_secure' => true]); return $resultRedirect; } /** @var \Magento\Framework\View\Result\Page $resultPage */ $resultPage = $this->resultPageFactory->create(); $resultPage->getLayout()->getBlock('accountConfirmation')->setEmail($this->getRequest()->getParam('email', $email)); return $resultPage; }
/** * {@inheritdoc} */ public function toHtml() { if ($this->customerSession->isLoggedIn() || !$this->registration->isAllowed() || !$this->accountManagement->isEmailAvailable($this->getEmailAddress()) || !$this->validateAddresses()) { return ''; } return parent::toHtml(); }
/** * Validates the fields in a specified address data object. * * @param \Magento\Quote\Api\Data\AddressInterface $addressData The address data object. * @return bool * @throws \Magento\Framework\Exception\InputException The specified address belongs to another customer. * @throws \Magento\Framework\Exception\NoSuchEntityException The specified customer ID or address ID is not valid. */ public function validate(\Magento\Quote\Api\Data\AddressInterface $addressData) { //validate customer id if ($addressData->getCustomerId()) { $customer = $this->customerRepository->getById($addressData->getCustomerId()); if (!$customer->getId()) { throw new \Magento\Framework\Exception\NoSuchEntityException(__('Invalid customer id %1', $addressData->getCustomerId())); } } // validate address id if ($addressData->getId()) { try { $address = $this->addressRepository->getById($addressData->getId()); } catch (\Magento\Framework\Exception\NoSuchEntityException $e) { throw new \Magento\Framework\Exception\NoSuchEntityException(__('Invalid address id %1', $addressData->getId())); } // check correspondence between customer id and address id if ($addressData->getCustomerId()) { if ($address->getCustomerId() != $addressData->getCustomerId()) { throw new \Magento\Framework\Exception\NoSuchEntityException(__('Invalid address id %1', $addressData->getId())); } } } if ($addressData->getCustomerAddressId()) { $applicableAddressIds = array_map(function ($address) { /** @var \Magento\Customer\Api\Data\AddressInterface $address */ return $address->getId(); }, $this->customerSession->getCustomerDataObject()->getAddresses()); if (!in_array($addressData->getCustomerAddressId(), $applicableAddressIds)) { throw new \Magento\Framework\Exception\NoSuchEntityException(__('Invalid address id %1', $addressData->getCustomerAddressId())); } } return true; }
/** * Fetch the subscription object. Create the subscriber by loading using the customerId. * * @return Subscriber */ public function getSubscriptionObject() { if ($this->_subscription === null) { $this->_subscription = $this->_createSubscriber()->loadByCustomerId($this->_customerSession->getCustomerId()); } return $this->_subscription; }
/** * Forgot customer password action * * @return \Magento\Framework\Controller\Result\Redirect */ public function execute() { /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); $email = (string) $this->getRequest()->getPost('email'); if ($email) { if (!\Zend_Validate::is($email, 'EmailAddress')) { $this->session->setForgottenEmail($email); $this->messageManager->addErrorMessage(__('Please correct the email address.')); return $resultRedirect->setPath('*/*/forgotpassword'); } try { $this->customerAccountManagement->initiatePasswordReset($email, AccountManagement::EMAIL_RESET); } catch (NoSuchEntityException $exception) { // Do nothing, we don't want anyone to use this action to determine which email accounts are registered. } catch (SecurityViolationException $exception) { $this->messageManager->addErrorMessage($exception->getMessage()); return $resultRedirect->setPath('*/*/forgotpassword'); } catch (\Exception $exception) { $this->messageManager->addExceptionMessage($exception, __('We\'re unable to send the password reset email.')); return $resultRedirect->setPath('*/*/forgotpassword'); } $this->messageManager->addSuccessMessage($this->getSuccessMessage($email)); return $resultRedirect->setPath('*/*/'); } else { $this->messageManager->addErrorMessage(__('Please enter your email.')); return $resultRedirect->setPath('*/*/forgotpassword'); } }
/** * @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])); }
/** * Set configuration for AdyenHPP payemnt method * * @return array */ public function getConfig() { // set to active $config = ['payment' => [self::CODE => ['isActive' => true, 'redirectUrl' => $this->_urlBuilder->getUrl('adyen/process/redirect', ['_secure' => $this->_getRequest()->isSecure()])]]]; // get customer if ($this->_customerSession->isLoggedIn()) { $gender = \Adyen\Payment\Model\Gender::getAdyenGenderFromMagentoGender($this->_customerSession->getCustomerData()->getGender()); // format to calendar date $dob = $this->_customerSession->getCustomerData()->getDob(); $dob = strtotime($dob); $dob = date('m/d/Y', $dob); } else { $gender = ""; $dob = ""; } // add to config $config['payment']['adyenHpp']['gender'] = $gender; $config['payment']['adyenHpp']['dob'] = $dob; // gender types $config['payment']['adyenHpp']['genderTypes'] = \Adyen\Payment\Model\Gender::getGenderTypes(); $paymentMethodSelectionOnAdyen = $this->_adyenHelper->getAdyenHppConfigDataFlag('payment_selection_on_adyen'); $config['payment']['adyenHpp']['isPaymentMethodSelectionOnAdyen'] = $paymentMethodSelectionOnAdyen; $config['payment']['adyenHpp']['showGender'] = $this->_adyenHelper->getAdyenHppConfigDataFlag('show_gender'); $config['payment']['adyenHpp']['showDob'] = $this->_adyenHelper->getAdyenHppConfigDataFlag('show_dob'); $config['payment']['adyenHpp']['showTelephone'] = $this->_adyenHelper->getAdyenHppConfigDataFlag('show_telephone'); return $config; }
protected function _construct() { parent::_construct(); // CSRF protection $this->_customerSession->setFacebookCsrf($csrf = md5(uniqid(rand(), true))); $this->_clientFacebook->setState($csrf); }
/** * Init customer order for display on front * * @return void */ protected function initOrders() { $customerId = $this->_customerSession->getCustomerId(); $orders = $this->_orderCollectionFactory->create()->addAttributeToFilter('customer_id', $customerId)->addAttributeToFilter('status', ['in' => $this->_orderConfig->getVisibleOnFrontStatuses()])->addAttributeToSort('created_at', 'desc')->setPage(1, 1); //TODO: add filter by current website $this->orders = $orders; }
/** * @return void */ protected function _construct() { parent::_construct(); //TODO: add full name logic $orders = $this->_orderCollectionFactory->create()->addAttributeToSelect('*')->joinAttribute('shipping_firstname', 'order_address/firstname', 'shipping_address_id', null, 'left')->joinAttribute('shipping_lastname', 'order_address/lastname', 'shipping_address_id', null, 'left')->addAttributeToFilter('customer_id', $this->_customerSession->getCustomerId())->addAttributeToFilter('status', array('in' => $this->_orderConfig->getVisibleOnFrontStatuses()))->addAttributeToSort('created_at', 'desc')->setPageSize('5')->load(); $this->setOrders($orders); }
/** * @magentoDataFixture Magento/Customer/_files/customer.php */ public function testGetSubscriptionObject() { $this->customerSession->setCustomerId(1); $subscriber = $this->block->getSubscriptionObject(); $this->assertInstanceOf('Magento\\Newsletter\\Model\\Subscriber', $subscriber); $this->assertFalse($subscriber->isSubscribed()); }
/** * @return int */ protected function getCustomerGroupId() { if ($this->product->getCustomerGroupId()) { return (int) $this->product->getCustomerGroupId(); } return (int) $this->customerSession->getCustomerGroupId(); }