Ejemplo n.º 1
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 testEmulateWelcomeBlock()
 {
     $this->_customerSession->loginById(1);
     $httpContext = new \Magento\Framework\App\Http\Context();
     $httpContext->setValue(Context::CONTEXT_AUTH, 1, 1);
     $block = $this->_objectManager->create('Magento\\Sales\\Block\\Reorder\\Sidebar', ['httpContext' => $httpContext]);
     $this->_observer->emulateWelcomeBlock($block);
     $customerName = $this->_escaper->escapeHtml($this->_customerViewHelper->getCustomerName($this->customerRepository->getById($this->_persistentSessionHelper->getSession()->getCustomerId())));
     $translation = __('Welcome, %1!', $customerName);
     $this->assertStringMatchesFormat('%A' . $translation . '%A', $block->getWelcome());
     $this->_customerSession->logout();
 }
Ejemplo n.º 2
0
 /**
  * Set persistent data to customer session
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  *
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if (!$this->_persistentData->canProcess($observer) || !$this->_persistentData->isShoppingCartPersist()) {
         return $this;
     }
     if ($this->_persistentSession->isPersistent() && !$this->_customerSession->isLoggedIn()) {
         /** @var  \Magento\Customer\Api\Data\CustomerInterface $customer */
         $customer = $this->customerRepository->getById($this->_persistentSession->getSession()->getCustomerId());
         if ($defaultShipping = $customer->getDefaultShipping()) {
             /** @var  \Magento\Customer\Model\Data\Address $address */
             $address = $this->addressRepository->getById($defaultShipping);
             if ($address) {
                 $this->_customerSession->setDefaultTaxShippingAddress(['country_id' => $address->getCountryId(), 'region_id' => $address->getRegion() ? $address->getRegionId() : null, 'postcode' => $address->getPostcode()]);
             }
         }
         if ($defaultBilling = $customer->getDefaultBilling()) {
             $address = $this->addressRepository->getById($defaultBilling);
             if ($address) {
                 $this->_customerSession->setDefaultTaxBillingAddress(['country_id' => $address->getCountryId(), 'region_id' => $address->getRegion() ? $address->getRegionId() : null, 'postcode' => $address->getPostcode()]);
             }
         }
         $this->_customerSession->setCustomerId($customer->getId())->setCustomerGroupId($customer->getGroupId());
     }
     return $this;
 }
Ejemplo n.º 3
0
 /**
  * Confirm customer account by id and confirmation key
  *
  * @return \Magento\Framework\Controller\Result\Redirect
  */
 public function execute()
 {
     /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultRedirectFactory->create();
     if ($this->_getSession()->isLoggedIn()) {
         $resultRedirect->setPath('*/*/');
         return $resultRedirect;
     }
     try {
         $customerId = $this->getRequest()->getParam('id', false);
         $key = $this->getRequest()->getParam('key', false);
         if (empty($customerId) || empty($key)) {
             throw new \Exception(__('Bad request.'));
         }
         // log in and send greeting email
         $customerEmail = $this->customerRepository->getById($customerId)->getEmail();
         $customer = $this->customerAccountManagement->activate($customerEmail, $key);
         $this->_getSession()->setCustomerDataAsLoggedIn($customer);
         $this->messageManager->addSuccess($this->getSuccessMessage());
         $resultRedirect->setUrl($this->getSuccessRedirect());
         return $resultRedirect;
     } catch (StateException $e) {
         $this->messageManager->addException($e, __('This confirmation key is invalid or has expired.'));
     } catch (\Exception $e) {
         $this->messageManager->addException($e, __('There was an error confirming the account'));
     }
     // die unhappy
     $url = $this->urlModel->getUrl('*/*/index', ['_secure' => true]);
     $resultRedirect->setUrl($this->_redirect->error($url));
     return $resultRedirect;
 }
Ejemplo n.º 4
0
 /**
  * Save newsletter subscription preference action
  *
  * @return void|null
  */
 public function executeInternal()
 {
     if (!$this->formKeyValidator->validate($this->getRequest())) {
         return $this->_redirect('customer/account/');
     }
     $customerId = $this->_customerSession->getCustomerId();
     if ($customerId === null) {
         $this->messageManager->addError(__('Something went wrong while saving your subscription.'));
     } else {
         try {
             $customer = $this->customerRepository->getById($customerId);
             $storeId = $this->storeManager->getStore()->getId();
             $customer->setStoreId($storeId);
             $this->customerRepository->save($customer);
             if ((bool) $this->getRequest()->getParam('is_subscribed', false)) {
                 $this->subscriberFactory->create()->subscribeCustomerById($customerId);
                 $this->messageManager->addSuccess(__('We saved the subscription.'));
             } else {
                 $this->subscriberFactory->create()->unsubscribeCustomerById($customerId);
                 $this->messageManager->addSuccess(__('We removed the subscription.'));
             }
         } catch (\Exception $e) {
             $this->messageManager->addError(__('Something went wrong while saving your subscription.'));
         }
     }
     $this->_redirect('customer/account/');
 }
 /**
  * @param InfoInterface $payment
  * @param float $amount
  * @return $this
  * @throws LocalizedException
  */
 public function capture(InfoInterface $payment, $amount)
 {
     parent::capture($payment, $amount);
     $customerId = $payment->getOrder()->getCustomerId();
     $customer = $this->customerRepository->getById($customerId);
     $openpayCustomerId = $customer->getCustomAttribute('openpay_customer_id')->getValue();
     $cardId = $payment->getAdditionalInformation('customer_card_id');
     $deviceSessionId = $payment->getAdditionalInformation('device_session_id');
     $order = $payment->getOrder();
     $currency = $order->getOrderCurrencyCode();
     $useOrderId = $this->getConfigData('useOrderId');
     $paymentLeyend = $this->getConfigData('paymentLeyend');
     $orderId = $order->getIncrementId();
     $params = ['source_id' => $cardId, 'method' => self::OPENPAY_PAYMENT_METHOD_CARD, 'amount' => $amount, 'currency' => $currency, 'description' => __($paymentLeyend)->getText(), 'order_id' => $useOrderId ? $orderId : null, 'device_session_id' => $deviceSessionId];
     try {
         $transaction = $this->chargeAdapter->chargeCustomerCard($openpayCustomerId, $params);
         $payment->setTransactionId($transaction->getId())->setIsTransactionClosed(0);
         $this->openpayCustomerRepository->clearCustomerCache($openpayCustomerId);
     } catch (OpenpayException $e) {
         $this->debugData(['request' => $params, 'exception' => $e->getMessage()]);
         $this->_logger->error(__('Payment capturing error.'));
         throw new LocalizedException(new Phrase('[' . $e->getErrorCode() . ']' . $e->getMessage()));
     }
     return $this;
 }
Ejemplo n.º 6
0
 /**
  * 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(__('New password field cannot be empty.'));
         $resultRedirect->setPath('*/*/createPassword', ['id' => $customerId, 'token' => $resetPasswordToken]);
         return $resultRedirect;
     }
     try {
         $customerEmail = $this->customerRepository->getById($customerId)->getEmail();
         $this->accountManagement->resetPassword($customerEmail, $resetPasswordToken, $password);
         $this->messageManager->addSuccess(__('Your password has been updated.'));
         $resultRedirect->setPath('*/*/login');
         return $resultRedirect;
     } catch (\Exception $exception) {
         $this->messageManager->addError(__('There was an error saving the new password.'));
         $resultRedirect->setPath('*/*/createPassword', ['id' => $customerId, 'token' => $resetPasswordToken]);
         return $resultRedirect;
     }
 }
Ejemplo n.º 7
0
 /**
  * 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()));
         }
     }
     if ($addressData->getCustomerAddressId()) {
         try {
             $this->addressRepository->getById($addressData->getCustomerAddressId());
         } catch (NoSuchEntityException $e) {
             throw new \Magento\Framework\Exception\NoSuchEntityException(__('Invalid address id %1', $addressData->getId()));
         }
         $applicableAddressIds = array_map(function ($address) {
             /** @var \Magento\Customer\Api\Data\AddressInterface $address */
             return $address->getId();
         }, $this->customerRepository->getById($addressData->getCustomerId())->getAddresses());
         if (!in_array($addressData->getCustomerAddressId(), $applicableAddressIds)) {
             throw new \Magento\Framework\Exception\NoSuchEntityException(__('Invalid address id %1', $addressData->getCustomerAddressId()));
         }
     }
     return true;
 }
Ejemplo n.º 8
0
 /**
  * Retrieve Shared Wishlist Customer instance
  *
  * @return \Magento\Customer\Api\Data\CustomerInterface
  */
 public function getWishlistCustomer()
 {
     if ($this->_customer === null) {
         $this->_customer = $this->customerRepository->getById($this->_getWishlist()->getCustomerId());
     }
     return $this->_customer;
 }
Ejemplo n.º 9
0
 /**
  * @magentoDataFixture Magento/Customer/_files/customer.php
  */
 public function testGetCustomerAttributeMetadata()
 {
     // Expect these attributes to exist but do not check the value
     $expectAttrsWOutVals = ['created_at', 'updated_at'];
     // Expect these attributes to exist and check the value - values come from _files/customer.php
     $expectAttrsWithVals = ['id' => 1, 'website_id' => 1, 'store_id' => 1, 'group_id' => 1, 'prefix' => 'Mr.', 'firstname' => 'John', 'middlename' => 'A', 'lastname' => 'Smith', 'suffix' => 'Esq.', 'email' => '*****@*****.**', 'default_billing' => '1', 'default_shipping' => '1', 'disable_auto_group_change' => 0, 'taxvat' => '12', 'gender' => 0];
     $customer = $this->customerRepository->getById(1);
     $this->assertNotNull($customer);
     $attributes = $this->_extensibleDataObjectConverter->toFlatArray($customer, [], '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     $this->assertNotEmpty($attributes);
     foreach ($attributes as $attributeCode => $attributeValue) {
         $this->assertNotNull($attributeCode);
         $this->assertNotNull($attributeValue);
         $attributeMetadata = $this->_service->getAttributeMetadata($attributeCode);
         $attrMetadataCode = $attributeMetadata->getAttributeCode();
         $this->assertSame($attributeCode, $attrMetadataCode);
         if (($key = array_search($attrMetadataCode, $expectAttrsWOutVals)) !== false) {
             unset($expectAttrsWOutVals[$key]);
         } else {
             $this->assertArrayHasKey($attrMetadataCode, $expectAttrsWithVals);
             $this->assertSame($expectAttrsWithVals[$attrMetadataCode], $attributeValue, "Failed for {$attrMetadataCode}");
             unset($expectAttrsWithVals[$attrMetadataCode]);
         }
     }
     $this->assertEmpty($expectAttrsWOutVals);
     $this->assertEmpty($expectAttrsWithVals);
 }
Ejemplo n.º 10
0
 /**
  * Emulate 'welcome' block with persistent data
  *
  * @param \Magento\Framework\View\Element\AbstractBlock $block
  * @return $this
  */
 public function emulateWelcomeBlock($block)
 {
     $escapedName = $this->_escaper->escapeHtml($this->_customerViewHelper->getCustomerName($this->customerRepository->getById($this->_persistentSession->getSession()->getCustomerId())), null);
     $this->_applyAccountLinksPersistentData();
     $welcomeMessage = __('Welcome, %1!', $escapedName) . ' ' . $this->_layout->getBlock('header.additional')->toHtml();
     $block->setWelcome($welcomeMessage);
     return $this;
 }
 /**
  * Unlock customer on success login attempt.
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     /** @var \Magento\Customer\Model\Customer $model */
     $customerModel = $observer->getEvent()->getData('model');
     $customer = $this->customerRepository->getById($customerModel->getId());
     $this->accountManagementHelper->processUnlockData($customer->getId());
     $this->customerRepository->save($customer);
     return $this;
 }
Ejemplo n.º 12
0
 /**
  * Return the full name of the customer currently logged in
  *
  * @return string|null
  */
 public function getCustomerName()
 {
     try {
         $customer = $this->customerRepository->getById($this->currentCustomer->getCustomerId());
         return $this->escapeHtml($this->_viewHelper->getCustomerName($customer));
     } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
         return null;
     }
 }
Ejemplo n.º 13
0
 /**
  * Change customer password action
  *
  * @return \Magento\Framework\Controller\Result\Redirect
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function execute()
 {
     /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultRedirectFactory->create();
     if (!$this->formKeyValidator->validate($this->getRequest())) {
         $resultRedirect->setPath('*/*/edit');
         return $resultRedirect;
     }
     if ($this->getRequest()->isPost()) {
         $customerId = $this->_getSession()->getCustomerId();
         $customer = $this->customerExtractor->extract('customer_account_edit', $this->_request);
         $customer->setId($customerId);
         if ($customer->getAddresses() == null) {
             $customer->setAddresses($this->customerRepository->getById($customerId)->getAddresses());
         }
         if ($this->getRequest()->getParam('change_password')) {
             $currPass = $this->getRequest()->getPost('current_password');
             $newPass = $this->getRequest()->getPost('password');
             $confPass = $this->getRequest()->getPost('password_confirmation');
             if (strlen($newPass)) {
                 if ($newPass == $confPass) {
                     try {
                         $customerEmail = $this->customerRepository->getById($customerId)->getEmail();
                         $this->customerAccountManagement->changePassword($customerEmail, $currPass, $newPass);
                     } catch (AuthenticationException $e) {
                         $this->messageManager->addError($e->getMessage());
                     } catch (\Exception $e) {
                         $this->messageManager->addException($e, __('Something went wrong while changing the password.'));
                     }
                 } else {
                     $this->messageManager->addError(__('Confirm your new password.'));
                 }
             } else {
                 $this->messageManager->addError(__('Please enter new password.'));
             }
         }
         try {
             $this->customerRepository->save($customer);
         } catch (AuthenticationException $e) {
             $this->messageManager->addError($e->getMessage());
         } catch (InputException $e) {
             $this->messageManager->addException($e, __('Invalid input'));
         } catch (\Exception $e) {
             $this->messageManager->addException($e, __('We can\'t save the customer.') . $e->getMessage() . '<pre>' . $e->getTraceAsString() . '</pre>');
         }
         if ($this->messageManager->getMessages()->getCount() > 0) {
             $this->_getSession()->setCustomerFormData($this->getRequest()->getPostValue());
             $resultRedirect->setPath('*/*/edit');
             return $resultRedirect;
         }
         $this->messageManager->addSuccess(__('You saved the account information.'));
         $resultRedirect->setPath('customer/account');
         return $resultRedirect;
     }
     $resultRedirect->setPath('*/*/edit');
     return $resultRedirect;
 }
 /**
  * @return \Magento\Customer\Api\Data\CustomerInterface
  */
 protected function loadSource()
 {
     if ($this->isBackendOrder()) {
         // For backend orders
         $customerId = $this->objectManager->get('Magento\\Backend\\Model\\Session\\Quote')->getQuote()->getCustomerId();
     } else {
         $customerId = $this->objectManager->get('Magento\\Customer\\Model\\Session')->getCustomerId();
     }
     return $this->customerRepository->getById($customerId);
 }
Ejemplo n.º 15
0
 /**
  * @param AbstractAction $subject
  * @param RequestInterface $request
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function beforeDispatch(AbstractAction $subject, RequestInterface $request)
 {
     if ($this->state->getAreaCode() == Area::AREA_FRONTEND && $request->isPost() && $this->notificationStorage->isExists(NotificationStorage::UPDATE_CUSTOMER_SESSION, $this->session->getCustomerId())) {
         $customer = $this->customerRepository->getById($this->session->getCustomerId());
         $this->session->setCustomerData($customer);
         $this->session->setCustomerGroupId($customer->getGroupId());
         $this->session->regenerateId();
         $this->notificationStorage->remove(NotificationStorage::UPDATE_CUSTOMER_SESSION, $customer->getId());
     }
 }
Ejemplo n.º 16
0
 /**
  * Verify that the specified customer has the same default billing and shipping address.
  *
  * @magentoDataFixture Magento/Customer/_files/customer.php
  * @magentoDataFixture Magento/Customer/_files/customer_address.php
  */
 public function testGetPrimaryAddressesBillingShippingSame()
 {
     $customer = $this->customerRepository->getById(1);
     $this->customerSession->setCustomerId(1);
     $addresses = $this->block->getPrimaryAddresses();
     $this->assertCount(1, $addresses);
     $address = $addresses[0];
     $this->assertInstanceOf('Magento\\Customer\\Api\\Data\\AddressInterface', $address);
     $this->assertEquals((int) $customer->getDefaultBilling(), $address->getId());
     $this->assertEquals((int) $customer->getDefaultShipping(), $address->getId());
 }
 /**
  * Set persistent data to customer session
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if (!$this->_persistentData->canProcess($observer) || !$this->_persistentData->isShoppingCartPersist()) {
         return $this;
     }
     if ($this->_persistentSession->isPersistent() && !$this->_customerSession->isLoggedIn()) {
         $customer = $this->customerRepository->getById($this->_persistentSession->getSession()->getCustomerId());
         $this->_customerSession->setCustomerId($customer->getId())->setCustomerGroupId($customer->getGroupId());
     }
     return $this;
 }
Ejemplo n.º 18
0
 /**
  * @magentoDataFixture Magento/Customer/_files/customer.php
  */
 public function testMassAssignGroupAction()
 {
     $customer = $this->customerRepository->getById(1);
     $this->assertEquals(1, $customer->getGroupId());
     $this->getRequest()->setParam('group', 0)->setPostValue('namespace', 'customer_listing')->setPostValue('selected', [1]);
     $this->dispatch('backend/customer/index/massAssignGroup');
     $this->assertSessionMessages($this->equalTo(['A total of 1 record(s) were updated.']), \Magento\Framework\Message\MessageInterface::TYPE_SUCCESS);
     $this->assertRedirect($this->stringStartsWith($this->baseControllerUrl));
     $customer = $this->customerRepository->getById(1);
     $this->assertEquals(0, $customer->getGroupId());
 }
Ejemplo n.º 19
0
 /**
  * @magentoDataFixture Magento/Customer/_files/customer.php
  */
 public function testGetHtml()
 {
     $customer = $this->_customerRepository->getById(1);
     $data = ['account' => $customer->__toArray()];
     $this->_context->getBackendSession()->setCustomerData($data);
     $this->_block = $this->_objectManager->get('Magento\\Framework\\View\\LayoutInterface')->createBlock('Magento\\Customer\\Block\\Adminhtml\\Edit\\Tab\\Carts', '', ['context' => $this->_context]);
     $html = $this->_block->toHtml();
     $this->assertContains("<div id=\"customer_cart_grid1\"", $html);
     $this->assertRegExp('/<div class=".*admin__data-grid-toolbar"/', $html);
     $this->assertContains("customer_cart_grid1JsObject = new varienGrid('customer_cart_grid1',", $html);
     $this->assertContains("backend/customer/cart_product_composite_cart/configure/website_id/1", $html);
 }
Ejemplo n.º 20
0
 public function testGetDefaultRateRequest()
 {
     $customerDataSet = $this->customerRepository->getById(self::FIXTURE_CUSTOMER_ID);
     $address = $this->addressRepository->getById(self::FIXTURE_ADDRESS_ID);
     $rateRequest = $this->_model->getRateRequest(null, null, null, null, $customerDataSet->getId());
     $this->assertNotNull($rateRequest);
     $this->assertEquals($address->getCountryId(), $rateRequest->getCountryId());
     $this->assertEquals($address->getRegion()->getRegionId(), $rateRequest->getRegionId());
     $this->assertEquals($address->getPostcode(), $rateRequest->getPostcode());
     $customerTaxClassId = $this->groupRepository->getById($customerDataSet->getGroupId())->getTaxClassId();
     $this->assertEquals($customerTaxClassId, $rateRequest->getCustomerClassId());
 }
 /**
  * Upgrade customer password hash when customer has logged in
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $password = $observer->getEvent()->getData('password');
     /** @var \Magento\Customer\Model\Customer $model */
     $model = $observer->getEvent()->getData('model');
     $customer = $this->customerRepository->getById($model->getId());
     $customerSecure = $this->customerRegistry->retrieveSecureData($model->getId());
     if (!$this->encryptor->validateHashVersion($customerSecure->getPasswordHash(), true)) {
         $customerSecure->setPasswordHash($this->encryptor->getHash($password, true));
         $this->customerRepository->save($customer);
     }
 }
 /**
  * Update customer id and customer group id if user is in persistent session
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if (!$this->_persistentSession->isPersistent()) {
         return;
     }
     $customerCookies = $observer->getEvent()->getCustomerCookies();
     if ($customerCookies instanceof \Magento\Framework\DataObject) {
         $persistentCustomer = $this->customerRepository->getById($this->_persistentSession->getSession()->getCustomerId());
         $customerCookies->setCustomerId($persistentCustomer->getId());
         $customerCookies->setCustomerGroupId($persistentCustomer->getGroupId());
     }
 }
 /**
  * Adds New Relic custom parameters per request for store, website, and logged in user if applicable
  *
  * @param Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(Observer $observer)
 {
     if ($this->config->isNewRelicEnabled()) {
         $this->newRelicWrapper->addCustomParameter(Config::STORE, $this->storeManager->getStore()->getName());
         $this->newRelicWrapper->addCustomParameter(Config::WEBSITE, $this->storeManager->getWebsite()->getName());
         if ($this->customerSession->isLoggedIn()) {
             $customer = $this->customerRepository->getById($this->customerSession->getCustomerId());
             $this->newRelicWrapper->addCustomParameter(Config::CUSTOMER_ID, $customer->getId());
             $this->newRelicWrapper->addCustomParameter(Config::CUSTOMER_NAME, $customer->getFirstname() . ' ' . $customer->getLastname());
         }
     }
 }
 /**
  * @magentoAppArea frontend
  * @magentoConfigFixture current_store persistent/options/shopping_cart 1
  * @magentoConfigFixture current_store persistent/options/logout_clear 0
  * @magentoConfigFixture current_store persistent/options/enabled 1
  */
 public function testEmulateCustomer()
 {
     $observer = new \Magento\Framework\Event\Observer();
     $this->_customerSession->loginById(1);
     $this->_customerSession->logout();
     $this->assertNull($this->_customerSession->getCustomerId());
     $this->assertEquals(\Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID, $this->_customerSession->getCustomerGroupId());
     $this->_observer->execute($observer);
     $customer = $this->customerRepository->getById($this->_persistentSessionHelper->getSession()->getCustomerId());
     $this->assertEquals($customer->getId(), $this->_customerSession->getCustomerId());
     $this->assertEquals($customer->getGroupId(), $this->_customerSession->getCustomerGroupId());
 }
Ejemplo n.º 25
0
 /**
  * @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
  * @magentoConfigFixture current_store persistent/options/shopping_cart 1
  * @magentoConfigFixture current_store persistent/options/logout_clear 0
  */
 public function testEmulateQuote()
 {
     $requestMock = $this->getMockBuilder('Magento\\Framework\\App\\Request\\Http')->disableOriginalConstructor()->setMethods([])->getMock();
     $requestMock->expects($this->once())->method('getFullActionName')->will($this->returnValue('valid_action'));
     $event = new \Magento\Framework\Event(['request' => $requestMock]);
     $observer = new \Magento\Framework\Event\Observer();
     $observer->setEvent($event);
     $this->_customerSession->loginById(1);
     $customer = $this->customerRepository->getById($this->_persistentSessionHelper->getSession()->getCustomerId());
     $this->_checkoutSession->expects($this->once())->method('setCustomerData')->with($customer);
     $this->_customerSession->logout();
     $this->_observer->execute($observer);
 }
Ejemplo n.º 26
0
 /**
  * Prepare the form.
  *
  * @return $this
  */
 protected function _prepareForm()
 {
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->_formFactory->create(['data' => ['id' => 'edit_form', 'action' => $this->getUrl('customer/*/save'), 'method' => 'post', 'enctype' => 'multipart/form-data']]);
     $customerId = $this->_coreRegistry->registry(RegistryConstants::CURRENT_CUSTOMER_ID);
     if ($customerId) {
         $form->addField('id', 'hidden', ['name' => 'customer_id']);
         $customer = $this->_customerRepository->getById($customerId);
         $form->setValues($this->_extensibleDataObjectConverter->toFlatArray($customer, [], '\\Magento\\Customer\\Api\\Data\\CustomerInterface'))->addValues(['customer_id' => $customerId]);
     }
     $form->setUseContainer(true);
     $this->setForm($form);
     return parent::_prepareForm();
 }
 /**
  * Reports concurrent users to the database reporting_users table
  *
  * @param Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(Observer $observer)
 {
     if ($this->config->isNewRelicEnabled()) {
         if ($this->customerSession->isLoggedIn()) {
             $customer = $this->customerRepository->getById($this->customerSession->getCustomerId());
             $jsonData = ['id' => $customer->getId(), 'name' => $customer->getFirstname() . ' ' . $customer->getLastname(), 'store' => $this->storeManager->getStore()->getName(), 'website' => $this->storeManager->getWebsite()->getName()];
             $modelData = ['type' => 'user_action', 'action' => $this->jsonEncoder->encode($jsonData), 'updated_at' => $this->dateTime->formatDate(true)];
             /** @var \Magento\NewRelicReporting\Model\Users $usersModel */
             $usersModel = $this->usersFactory->create();
             $usersModel->setData($modelData);
             $usersModel->save();
         }
     }
 }
Ejemplo n.º 28
0
 /**
  * Retrieve Customer instance
  *
  * @return \Magento\Customer\Api\Data\CustomerInterface
  */
 public function getCustomer()
 {
     if ($this->_customer === null) {
         $params = $this->urlDecoder->decode($this->_getRequest()->getParam('data'));
         $data = explode(',', $params);
         $customerId = abs(intval($data[0]));
         if ($customerId && $customerId == $this->_customerSession->getCustomerId()) {
             $this->_customer = $this->_customerRepository->getById($customerId);
         } else {
             $this->_customer = $this->_customerFactory->create();
         }
     }
     return $this->_customer;
 }
Ejemplo n.º 29
0
 /**
  * Customer addresses list
  *
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function executeInternal()
 {
     $addresses = $this->customerRepository->getById($this->_getSession()->getCustomerId())->getAddresses();
     if (count($addresses)) {
         /** @var \Magento\Framework\View\Result\Page $resultPage */
         $resultPage = $this->resultPageFactory->create();
         $block = $resultPage->getLayout()->getBlock('address_book');
         if ($block) {
             $block->setRefererUrl($this->_redirect->getRefererUrl());
         }
         return $resultPage;
     } else {
         return $this->resultRedirectFactory->create()->setPath('*/*/new');
     }
 }
Ejemplo n.º 30
0
 /**
  * Get logged in customer
  *
  * @return \Magento\Customer\Api\Data\CustomerInterface
  */
 protected function _getCustomer()
 {
     if (empty($this->_customer)) {
         $this->_customer = $this->customerRepository->getById($this->_customerSession->getCustomerId());
     }
     return $this->_customer;
 }