コード例 #1
0
ファイル: Subscriber.php プロジェクト: Doability/magento2dev
 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];
 }
コード例 #2
0
ファイル: Plugin.php プロジェクト: sendpulse/mageia
 public function beforeSubscribeCustomerById($subscriber, $customerId)
 {
     $subscriber->loadByCustomerId($customerId);
     $storeId = $subscriber->getStoreId();
     if ($this->_helper->isMageiaEnabled($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';
         }
         */
         $email = ['email' => $customer->getEmail()];
         if ($mergeVars) {
             $email['variables'] = $mergeVars;
         }
         $data = ['emails' => json_encode([$email])];
         $listId = $this->_helper->getDefaultList();
         $return = $api->listCreateMember($listId, $data);
         if (isset($return->result) && $return->result) {
             $subscriber->setMageiaId($customer->getEmail());
             $subscriber->save();
         }
     }
     return [$customerId];
 }
コード例 #3
0
 /**
  * @param array $result
  * @param bool $expectedValue
  * @dataProvider getButtonDataProvider
  */
 public function testGetButtonData($result, $expectedValue)
 {
     $this->registryMock->expects($this->any())->method('registry')->willReturn(1);
     $this->customerRegistryMock->expects($this->once())->method('retrieve')->willReturn($this->customerModelMock);
     $this->customerModelMock->expects($this->once())->method('isCustomerLocked')->willReturn($expectedValue);
     $this->urlBuilderMock->expects($this->any())->method('getUrl')->willReturn('http://website.com/');
     $this->assertEquals($result, $this->block->getButtonData());
 }
コード例 #4
0
ファイル: Boolean.php プロジェクト: aiesh/magento2
 /**
  * Prepare data before attribute save
  *
  * @param \Magento\Customer\Model\Customer $customer
  * @return $this
  */
 public function beforeSave($customer)
 {
     $attributeName = $this->getAttribute()->getName();
     $inputValue = $customer->getData($attributeName);
     $sanitizedValue = !empty($inputValue) ? '1' : '0';
     $customer->setData($attributeName, $sanitizedValue);
     return $this;
 }
コード例 #5
0
 /**
  * @return void
  */
 public function testExecute()
 {
     $customerId = 1;
     $observerMock = $this->getMock('Magento\\Framework\\Event\\Observer', [], [], '', false);
     $eventMock = $this->getMock('Magento\\Framework\\Event', ['getData'], [], '', false);
     $observerMock->expects($this->once())->method('getEvent')->willReturn($eventMock);
     $eventMock->expects($this->once())->method('getData')->with('model')->willReturn($this->customerModelMock);
     $this->customerModelMock->expects($this->once())->method('getId')->willReturn($customerId);
     $this->authenticationMock->expects($this->once())->method('unlock')->with($customerId);
     $this->customerLoginSuccessObserver->execute($observerMock);
 }
コード例 #6
0
 public function testUpdateDataOverrideExistingData()
 {
     /** @var \Magento\Customer\Model\Data\Customer $customerData */
     $customerData = $this->customerFactory->create()->setId(2)->setFirstname('John')->setLastname('Doe')->setDefaultBilling(1);
     $this->customerModel->updateData($customerData);
     /** @var \Magento\Customer\Model\Data\Customer $updatedCustomerData */
     $updatedCustomerData = $this->customerFactory->create()->setId(3)->setFirstname('Jane')->setLastname('Smith')->setDefaultBilling(0);
     $updatedCustomerData = $this->customerModel->updateData($updatedCustomerData)->getDataModel();
     $this->assertEquals(3, $updatedCustomerData->getId());
     $this->assertEquals('Jane', $updatedCustomerData->getFirstname());
     $this->assertEquals('Smith', $updatedCustomerData->getLastname());
     $this->assertEquals(0, $updatedCustomerData->getDefaultBilling());
 }
 /**
  * @return void
  */
 public function testExecute()
 {
     $customerId = 1;
     $observerMock = $this->getMock('Magento\\Framework\\Event\\Observer', [], [], '', false);
     $eventMock = $this->getMock('Magento\\Framework\\Event', ['getData'], [], '', false);
     $observerMock->expects($this->once())->method('getEvent')->willReturn($eventMock);
     $eventMock->expects($this->once())->method('getData')->with('model')->willReturn($this->customerModelMock);
     $this->customerModelMock->expects($this->once())->method('getId')->willReturn($customerId);
     $this->customerRepositoryMock->expects($this->once())->method('getById')->willReturn($this->customerDataMock);
     $this->customerDataMock->expects($this->once())->method('getId')->willReturn($customerId);
     $this->accountManagementHelperMock->expects($this->once())->method('processUnlockData')->with($customerId);
     $this->customerRepositoryMock->expects($this->once())->method('save')->with($this->customerDataMock);
     $this->customerLoginSuccessObserver->execute($observerMock);
 }
コード例 #8
0
 /**
  * Get store id
  *
  * @return int
  */
 public function getStoreId()
 {
     if ($this->getWebsiteId() * 1) {
         return $this->_getWebsiteStoreId();
     }
     return parent::getStoreId();
 }
コード例 #9
0
 /**
  * return bool
  */
 public function testValidateResetPasswordToken()
 {
     $this->reInitModel();
     $this->customer->expects($this->once())->method('getResetPasswordLinkExpirationPeriod')->willReturn(100000);
     $this->customerRegistry->expects($this->atLeastOnce())->method('retrieveSecureData')->willReturn($this->customerSecure);
     $this->assertTrue($this->accountManagement->validateResetPasswordLinkToken(22, 'newStringToken'));
 }
コード例 #10
0
 /**
  * @param string $expectedResult
  * @param bool $value
  * @dataProvider getAccountLockDataProvider
  * @return void
  */
 public function testGetAccountLock($expectedResult, $value)
 {
     $this->customerRegistry->expects($this->once())->method('retrieve')->willReturn($this->customerModel);
     $this->customerModel->expects($this->once())->method('isCustomerLocked')->willReturn($value);
     $expectedResult = new \Magento\Framework\Phrase($expectedResult);
     $this->assertEquals($expectedResult, $this->block->getAccountLock());
 }
コード例 #11
0
ファイル: Customer.php プロジェクト: shabbirvividads/magento2
 /**
  * Prepare customer data for update
  *
  * @param array $rowData
  * @return array
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 protected function _prepareDataForUpdate(array $rowData)
 {
     /** @var $passwordAttribute \Magento\Customer\Model\Attribute */
     $passwordAttribute = $this->_customerModel->getAttribute('password_hash');
     $passwordAttributeId = $passwordAttribute->getId();
     $passwordStorageTable = $passwordAttribute->getBackend()->getTable();
     $entitiesToCreate = [];
     $entitiesToUpdate = [];
     $attributesToSave = [];
     // entity table data
     $now = new \DateTime();
     if (empty($rowData['created_at'])) {
         $createdAt = $now;
     } else {
         $createdAt = (new \DateTime())->setTimestamp(strtotime($rowData['created_at']));
     }
     $entityRow = ['group_id' => empty($rowData['group_id']) ? self::DEFAULT_GROUP_ID : $rowData['group_id'], 'store_id' => empty($rowData[self::COLUMN_STORE]) ? 0 : $this->_storeCodeToId[$rowData[self::COLUMN_STORE]], 'created_at' => $createdAt->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT), 'updated_at' => $now->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT)];
     $emailInLowercase = strtolower($rowData[self::COLUMN_EMAIL]);
     if ($entityId = $this->_getCustomerId($emailInLowercase, $rowData[self::COLUMN_WEBSITE])) {
         // edit
         $entityRow['entity_id'] = $entityId;
         $entitiesToUpdate[] = $entityRow;
     } else {
         // create
         $entityId = $this->_getNextEntityId();
         $entityRow['entity_id'] = $entityId;
         $entityRow['website_id'] = $this->_websiteCodeToId[$rowData[self::COLUMN_WEBSITE]];
         $entityRow['email'] = $emailInLowercase;
         $entityRow['is_active'] = 1;
         $entitiesToCreate[] = $entityRow;
         $this->_newCustomers[$emailInLowercase][$rowData[self::COLUMN_WEBSITE]] = $entityId;
     }
     // attribute values
     foreach (array_intersect_key($rowData, $this->_attributes) as $attributeCode => $value) {
         if (!$this->_attributes[$attributeCode]['is_static'] && strlen($value)) {
             /** @var $attribute \Magento\Customer\Model\Attribute */
             $attribute = $this->_customerModel->getAttribute($attributeCode);
             $backendModel = $attribute->getBackendModel();
             $attributeParameters = $this->_attributes[$attributeCode];
             if ('select' == $attributeParameters['type']) {
                 $value = $attributeParameters['options'][strtolower($value)];
             } elseif ('datetime' == $attributeParameters['type']) {
                 $value = (new \DateTime())->setTimestamp(strtotime($value));
                 $value = $value->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT);
             } elseif ($backendModel) {
                 $attribute->getBackend()->beforeSave($this->_customerModel->setData($attributeCode, $value));
                 $value = $this->_customerModel->getData($attributeCode);
             }
             $attributesToSave[$attribute->getBackend()->getTable()][$entityId][$attributeParameters['id']] = $value;
             // restore 'backend_model' to avoid default setting
             $attribute->setBackendModel($backendModel);
         }
     }
     // password change/set
     if (isset($rowData['password']) && strlen($rowData['password'])) {
         $attributesToSave[$passwordStorageTable][$entityId][$passwordAttributeId] = $this->_customerModel->hashPassword($rowData['password']);
     }
     return [self::ENTITIES_TO_CREATE_KEY => $entitiesToCreate, self::ENTITIES_TO_UPDATE_KEY => $entitiesToUpdate, self::ATTRIBUTES_TO_SAVE_KEY => $attributesToSave];
 }
コード例 #12
0
 /**
  * Send email with new account related information
  *
  * @param string $type
  * @param string $backUrl
  * @param string $storeId
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function sendNewAccountEmail($type = 'registered', $backUrl = '', $storeId = '0')
 {
     if ($this->_scopeConfig->getValue(\Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_DISABLE_CUSTOMER_SUCCESS, 'store', $storeId)) {
         return $this;
     } else {
         return parent::sendNewAccountEmail($type, $backUrl, $storeId);
     }
 }
コード例 #13
0
ファイル: AddressTest.php プロジェクト: aiesh/magento2
 /**
  * Assign customer address to quote address and save quote address
  *
  * @param bool $unsetId
  */
 protected function _setCustomerAddressAndSave($unsetId)
 {
     $shippingAddress = $this->_quote->getShippingAddress();
     if ($unsetId) {
         $shippingAddress->setId(null);
     }
     $shippingAddress->setSameAsBilling(0)->setCustomerAddressData($this->_customer->getDefaultBillingAddress())->save();
 }
コード例 #14
0
 /**
  * Load customer user info
  *
  * @throws \Magento\Framework\Exception
  * @return \Inchoo\SocialConnect\Model\Facebook\Info\User
  */
 public function loadSelf()
 {
     if (!$this->_customerSession->isLoggedIn()) {
         if (!$this->_customer->getId()) {
             throw new \Magento\Framework\Exception(__('Could not load self since customer isn\'t logged in'));
         }
     }
     $this->_customer = $this->_customerSession->getCustomer();
     if (!$this->_customer->getId()) {
         throw new \Magento\Framework\Exception(__('Could not load by customer id'));
     }
     if (!($socialconnectFid = $this->_customer->getInchooSocialconnectFid()) || !($socialconnectFtoken = $this->_customer->getInchooSocialconnectFtoken())) {
         throw new \Magento\Framework\Exception(__('Could not retrieve token by customer id'));
     }
     $this->setAccessToken($socialconnectFtoken);
     $this->_load();
     return $this;
 }
コード例 #15
0
ファイル: CustomerTest.php プロジェクト: rafaelstz/magento2
 /**
  * @param int $customerId
  * @param int $websiteId
  * @param string|null $skipConfirmationIfEmail
  * @param bool $expected
  * @dataProvider dataProviderIsConfirmationRequired
  */
 public function testIsConfirmationRequired($customerId, $websiteId, $skipConfirmationIfEmail, $expected)
 {
     $customerEmail = '*****@*****.**';
     $this->registryMock->expects($this->any())->method('registry')->with('skip_confirmation_if_email')->willReturn($skipConfirmationIfEmail);
     $this->_scopeConfigMock->expects($this->any())->method('getValue')->with(Customer::XML_PATH_IS_CONFIRM, ScopeInterface::SCOPE_WEBSITES, $websiteId)->willReturn($expected);
     $this->_model->setData('id', $customerId);
     $this->_model->setData('website_id', $websiteId);
     $this->_model->setData('email', $customerEmail);
     $this->assertEquals($expected, $this->_model->isConfirmationRequired());
 }
コード例 #16
0
 public function afterSubscribeCustomerById($subscriber)
 {
     $storeId = $subscriber->getStoreId();
     if ($this->_helper->isMonkeyEnabled($storeId)) {
         $customer = $this->_customer->load($subscriber->getCustomerId());
         $mergeVars = $this->_helper->getMergeVars($customer);
         $api = new \Ebizmarts\MageMonkey\Model\Api(array(), $this->_helper);
         $isSubscribeOwnEmail = $this->_customerSession->isLoggedIn() && $this->_customerSession->getCustomerDataObject()->getEmail() == $subscriber->getSubscriberEmail();
         if ($this->_helper->isDoubleOptInEnabled($storeId) && !$isSubscribeOwnEmail) {
             $status = 'pending';
         } else {
             $status = 'subscribed';
         }
         $data = array('list_id' => $this->_helper->getDefaultList(), 'email_address' => $subscriber->getEmail(), 'email_type' => 'html', 'status' => $status);
         $return = $api->listCreateMember($this->_helper->getDefaultList(), json_encode($data));
         if (isset($return->id)) {
             $subscriber->setMagemonkeyId($return->id)->save();
         }
     }
 }
コード例 #17
0
 public function testDeleteById()
 {
     $addressId = 12;
     $customerId = 43;
     $this->address->expects($this->once())->method('getCustomerId')->willReturn($customerId);
     $addressCollection = $this->getMock('Magento\\Customer\\Model\\ResourceModel\\Address\\Collection', [], [], '', false);
     $this->addressRegistry->expects($this->once())->method('retrieve')->with($addressId)->willReturn($this->address);
     $this->customerRegistry->expects($this->once())->method('retrieve')->with($customerId)->willReturn($this->customer);
     $this->customer->expects($this->once())->method('getAddressesCollection')->willReturn($addressCollection);
     $addressCollection->expects($this->once())->method('clear');
     $this->addressResourceModel->expects($this->once())->method('delete')->with($this->address);
     $this->addressRegistry->expects($this->once())->method('remove')->with($addressId);
     $this->assertTrue($this->repository->deleteById($addressId));
 }
コード例 #18
0
 /**
  * After generate Xml
  *
  * @param \Magento\Framework\View\LayoutInterface $subject
  * @param \Magento\Framework\View\LayoutInterface $result
  * @return \Magento\Framework\View\LayoutInterface
  */
 public function afterGenerateXml(\Magento\Framework\View\LayoutInterface $subject, $result)
 {
     if ($this->moduleManager->isEnabled('Magento_PageCache') && $this->cacheConfig->isEnabled() && !$this->request->isAjax() && $subject->isCacheable()) {
         $this->visitor->setSkipRequestLogging(true);
         $this->visitor->unsetData();
         $this->session->clearStorage();
         $this->customerSession->clearStorage();
         $this->session->setData(\Magento\Framework\Data\Form\FormKey::FORM_KEY, $this->formKey);
         $this->customerSession->setCustomerGroupId($this->customerGroupId);
         $this->customer->setGroupId($this->customerGroupId);
         $this->customerSession->setCustomer($this->customer);
     }
     return $result;
 }
コード例 #19
0
 public function testRemoveByEmail()
 {
     $this->customer->expects($this->exactly(2))->method('loadByEmail')->with(self::CUSTOMER_EMAIL)->will($this->returnValue($this->customer));
     $this->customer->expects($this->any())->method('getId')->will($this->returnValue(self::CUSTOMER_ID));
     $this->customer->expects($this->any())->method('getEmail')->will($this->returnValue(self::CUSTOMER_EMAIL));
     $this->customer->expects($this->any())->method('getWebsiteId')->will($this->returnValue(self::WEBSITE_ID));
     $this->customer->expects($this->any())->method('setEmail')->will($this->returnValue($this->customer));
     $this->customer->expects($this->any())->method('setWebsiteId')->will($this->returnValue($this->customer));
     $this->customerFactory->expects($this->exactly(2))->method('create')->will($this->returnValue($this->customer));
     $actual = $this->customerRegistry->retrieveByEmail(self::CUSTOMER_EMAIL, self::WEBSITE_ID);
     $this->assertEquals($this->customer, $actual);
     $this->customerRegistry->removeByEmail(self::CUSTOMER_EMAIL, self::WEBSITE_ID);
     $actual = $this->customerRegistry->retrieveByEmail(self::CUSTOMER_EMAIL, self::WEBSITE_ID);
     $this->assertEquals($this->customer, $actual);
 }
コード例 #20
0
 public function beforeSubscribeCustomerById($subscriber, $customerId)
 {
     $subscriber->loadByCustomerId($customerId);
     $subscriber->setImportMode(true);
     $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 = ['list_id' => $this->_helper->getDefaultList(), 'email_address' => $customer->getEmail(), 'email_type' => 'html', 'status' => $status, 'merge_fields' => $mergeVars];
         } else {
             $data = ['list_id' => $this->_helper->getDefaultList(), 'email_address' => $customer->getEmail(), 'email_type' => 'html', 'status' => $status, 'merge_fields' => ['EMAIL' => $customer->getEmail()]];
         }
         try {
             $emailHash = md5(strtolower($customer->getEmail()));
             $return = $api->getMember($this->_helper->getDefaultList(), $emailHash);
             if (!isset($return->id)) {
                 $return = $api->listCreateMember($this->_helper->getDefaultList(), json_encode($data));
                 if (isset($return->id)) {
                     $subscriber->setMagemonkeyId($return->id)->save();
                 }
             }
             $subscriber->setMagemonkeyId($emailHash)->save();
         } catch (\Exception $e) {
             $this->_helper->log($e->getMessage());
         }
     }
     return [$customerId];
 }
コード例 #21
0
 public function testAfterGenerateXmlNoDepersonalize()
 {
     $expectedResult = $this->getMock('Magento\\Framework\\View\\Layout', [], [], '', false);
     $this->depersonalizeCheckerMock->expects($this->once())->method('checkIfDepersonalize')->willReturn(false);
     $this->visitorMock->expects($this->never())->method('setSkipRequestLogging');
     $this->visitorMock->expects($this->never())->method('unsetData');
     $this->sessionMock->expects($this->never())->method('clearStorage');
     $this->customerSessionMock->expects($this->never())->method('clearStorage');
     $this->customerSessionMock->expects($this->never())->method('setCustomerGroupId');
     $this->customerMock->expects($this->never())->method('setGroupId');
     $this->sessionMock->expects($this->never())->method('setData');
     $this->customerSessionMock->expects($this->never())->method('setCustomer');
     $actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $expectedResult);
     $this->assertSame($expectedResult, $actualResult);
 }
コード例 #22
0
 /**
  * Test method afterGenerateXml with enabled module PageCache
  */
 public function testAfterGenerateXmlPageCacheEnabled()
 {
     $expectedResult = $this->getMock('Magento\\Framework\\View\\Layout', array(), array(), '', false);
     $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with('Magento_PageCache')->will($this->returnValue(true));
     $this->cacheConfigMock->expects($this->once())->method('isEnabled')->will($this->returnValue(true));
     $this->requestMock->expects($this->once())->method('isAjax')->will($this->returnValue(false));
     $this->layoutMock->expects($this->once())->method('isCacheable')->will($this->returnValue(true));
     $this->visitorMock->expects($this->once())->method('setSkipRequestLogging')->with($this->equalTo(true));
     $this->visitorMock->expects($this->once())->method('unsetData');
     $this->sessionMock->expects($this->once())->method('clearStorage');
     $this->customerSessionMock->expects($this->once())->method('clearStorage');
     $this->customerSessionMock->expects($this->once())->method('setCustomerGroupId')->with($this->equalTo(null));
     $this->customerMock->expects($this->once())->method('setGroupId')->with($this->equalTo(null));
     $this->sessionMock->expects($this->once())->method('setData')->with($this->equalTo(\Magento\Framework\Data\Form\FormKey::FORM_KEY), $this->equalTo(null));
     $this->customerSessionMock->expects($this->once())->method('setCustomer')->with($this->equalTo($this->customerMock));
     $actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $expectedResult);
     $this->assertSame($expectedResult, $actualResult);
 }
コード例 #23
0
 public function testSendNewAccountEmailWithoutStoreId()
 {
     $store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
     $website = $this->getMock('Magento\\Store\\Model\\Website', [], [], '', false);
     $website->expects($this->once())->method('getStoreIds')->will($this->returnValue([1, 2, 3, 4]));
     $this->_storeManager->expects($this->once())->method('getWebsite')->with(1)->will($this->returnValue($website));
     $this->_storeManager->expects($this->once())->method('getStore')->with(1)->will($this->returnValue($store));
     $this->_config->expects($this->exactly(3))->method('getAttribute')->will($this->returnValue($this->_attribute));
     $this->_attribute->expects($this->exactly(3))->method('getIsVisible')->will($this->returnValue(true));
     $methods = ['setTemplateIdentifier', 'setTemplateOptions', 'setTemplateVars', 'setFrom', 'addTo'];
     foreach ($methods as $method) {
         $this->_transportBuilderMock->expects($this->once())->method($method)->will($this->returnSelf());
     }
     $transportMock = $this->getMock('Magento\\Framework\\Mail\\TransportInterface', [], [], '', false);
     $transportMock->expects($this->once())->method('sendMessage')->will($this->returnSelf());
     $this->_transportBuilderMock->expects($this->once())->method('getTransport')->will($this->returnValue($transportMock));
     $this->_model->setData(['website_id' => 1, 'store_id' => 1, 'email' => '*****@*****.**', 'firstname' => 'FirstName', 'lastname' => 'LastName', 'middlename' => 'MiddleName', 'prefix' => 'Prefix']);
     $this->_model->sendNewAccountEmail('registered');
 }
コード例 #24
0
ファイル: Quote.php プロジェクト: Atlis/docker-magento2
 /**
  * Retrieve customer model object
  *
  * @return \Magento\Customer\Model\Customer
  */
 public function getCustomer()
 {
     /**
      * @TODO: Remove the method after all external usages are refactored in MAGETWO-19930
      * _customer and _customerFactory variables should be eliminated as well
      */
     if (null === $this->_customer) {
         $this->_customer = $this->_customerFactory->create();
         $customerId = $this->getCustomerId();
         if ($customerId) {
             $this->_customer->load($customerId);
             if (!$this->_customer->getId()) {
                 $this->_customer->setCustomerId(null);
             }
         }
     }
     return $this->_customer;
 }
コード例 #25
0
 /**
  * Check if rpToken is expired
  *
  * @param string $rpToken
  * @param string $rpTokenCreatedAt
  * @return bool
  */
 public function isResetPasswordLinkTokenExpired($rpToken, $rpTokenCreatedAt)
 {
     if (empty($rpToken) || empty($rpTokenCreatedAt)) {
         return true;
     }
     $expirationPeriod = $this->customerModel->getResetPasswordLinkExpirationPeriod();
     $currentTimestamp = (new \DateTime())->getTimestamp();
     $tokenTimestamp = (new \DateTime($rpTokenCreatedAt))->getTimestamp();
     if ($tokenTimestamp > $currentTimestamp) {
         return true;
     }
     $dayDifference = floor(($currentTimestamp - $tokenTimestamp) / (24 * 60 * 60));
     if ($dayDifference >= $expirationPeriod) {
         return true;
     }
     return false;
 }
コード例 #26
0
ファイル: Customer.php プロジェクト: shabbirvividads/magento2
 /**
  * Change reset password link token
  *
  * Stores new reset password link token and its creation time
  *
  * @param \Magento\Customer\Model\Customer $customer
  * @param string $passwordLinkToken
  * @return $this
  */
 public function changeResetPasswordLinkToken(\Magento\Customer\Model\Customer $customer, $passwordLinkToken)
 {
     if (is_string($passwordLinkToken) && !empty($passwordLinkToken)) {
         $customer->setRpToken($passwordLinkToken);
         $customer->setRpTokenCreatedAt((new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT));
         $this->saveAttribute($customer, 'rp_token');
         $this->saveAttribute($customer, 'rp_token_created_at');
     }
     return $this;
 }
コード例 #27
0
ファイル: Quote.php プロジェクト: niranjanssiet/magento2
 /**
  * Retrieve customer model object
  *
  * @return \Magento\Customer\Api\Data\CustomerInterface|\Magento\Framework\Api\ExtensibleDataInterface
  */
 public function getCustomer()
 {
     /**
      * @TODO: Remove the method after all external usages are refactored in MAGETWO-19930
      * _customer and _customerFactory variables should be eliminated as well
      */
     if (null === $this->_customer) {
         try {
             $this->_customer = $this->customerRepository->getById($this->getCustomerId());
         } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
             $this->_customer = $this->customerDataFactory->create();
             $this->_customer->setId(null);
         }
     }
     return $this->_customer;
 }
コード例 #28
0
ファイル: Session.php プロジェクト: pavelnovitsky/magento2
 /**
  * Set customer model and the customer id in session
  *
  * @param   Customer $customerModel
  * @return  $this
  * @deprecated use setCustomerId() instead
  */
 public function setCustomer(Customer $customerModel)
 {
     $this->_customerModel = $customerModel;
     $this->_httpContext->setValue(\Magento\Customer\Helper\Data::CONTEXT_GROUP, $customerModel->getGroupId(), \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID);
     $this->setCustomerId($customerModel->getId());
     if (!$customerModel->isConfirmationRequired() && $customerModel->getConfirmation()) {
         $customerModel->setConfirmation(null)->save();
     }
     /**
      * The next line is a workaround.
      * It is used to distinguish users that are logged in from user data set via methods similar to setCustomerId()
      */
     $this->unsIsCustomerEmulated();
     return $this;
 }
コード例 #29
0
 /**
  * Replace existing customer model with a new one.
  *
  * @param Customer $customer
  * @return $this
  */
 public function push(Customer $customer)
 {
     $this->customerRegistryById[$customer->getId()] = $customer;
     $emailKey = $this->getEmailKey($customer->getEmail(), $customer->getWebsiteId());
     $this->customerRegistryByEmail[$emailKey] = $customer;
     return $this;
 }
コード例 #30
0
ファイル: VaultTest.php プロジェクト: nja78/magento2
 /**
  * @param string $params
  * @dataProvider dataProcessNonce
  */
 public function testProcessNonceException($params = null, $exceptionMessage = null)
 {
     $this->customerSessionMock->expects($this->any())->method('getCustomerId')->willReturn($params['customerId']);
     $countryCollectionMock = $this->getMockBuilder('\\Magento\\Directory\\Model\\Resource\\Country\\Collection')->disableOriginalConstructor()->getMock();
     $countryCollectionMock->expects($this->any())->method('addCountryCodeFilter')->willReturn($countryCollectionMock);
     $this->countryFactoryMock->expects($this->any())->method('create')->willReturn($countryCollectionMock);
     $this->configMock->expects($this->any())->method('canUseForCountry')->willReturn($params['canUseForCountry']);
     $this->configMock->expects($this->any())->method('canUseCcTypeForCountry')->willReturn($params['canUseCcTypeForCountry']);
     $this->helperMock->expects($this->any())->method('generateCustomerId')->willReturn($params['customerId']);
     $this->customerMock->expects($this->any())->method('load')->willReturn($this->customerMock);
     $this->customerFactoryMock->expects($this->any())->method('create')->willReturn($this->customerMock);
     if (is_object($params['paymentMethodObj'])) {
         if (!$params['optionsArray']['update']) {
             $this->braintreePaymentMethodMock->expects($this->once())->method('create')->willReturn($params['paymentMethodObj']);
         } else {
             $this->braintreePaymentMethodMock->expects($this->once())->method('update')->willReturn($params['paymentMethodObj']);
         }
         if (!$params['paymentMethodObj']->success) {
             $this->errorHelperMock->expects($this->once())->method('parseBraintreeError')->willReturn(new \Magento\Framework\Phrase($exceptionMessage));
         } else {
             $this->errorHelperMock->expects($this->never())->method('parseBraintreeError');
         }
     }
     try {
         $this->model->processNonce($params['nonce'], $params['optionsArray'], $params['billingAddress']);
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $this->assertEquals($exceptionMessage, $e->getMessage());
     }
 }