作者:Doabilit
项目:magento2de
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];
}
作者:sendpuls
项目:magei
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];
}
作者:BlackIkeEagl
项目:magento2-continuousph
/**
* @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());
}
作者:aies
项目:magento
/**
* 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;
}
作者:pradeep-wagent
项目:magento
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());
}
作者:BlackIkeEagl
项目:magento2-continuousph
/**
* @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());
}
作者:shabbirvividad
项目:magento
/**
* 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];
}
作者:aies
项目:magento
/**
* 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();
}
作者:LavoWe
项目:Magento2-Inchoo_SocialConnec
/**
* 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;
}
作者:rafaelst
项目:magento
/**
* @param int $customerId
* @param int $websiteId
* @param string|null $skipConfirmationIfEmail
* @param bool $expected
* @dataProvider dataProviderIsConfirmationRequired
*/
public function testIsConfirmationRequired($customerId, $websiteId, $skipConfirmationIfEmail, $expected)
{
$customerEmail = 'test1@example.com';
$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());
}
作者:andrewket
项目:magento2-magemonke
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();
}
}
}
作者:kidaa3
项目:magento2-platforms
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));
}
作者:aies
项目:magento
/**
* 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;
}
作者:ebizmart
项目:magento2-magemonke
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];
}
作者:Doabilit
项目:magento2de
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);
}
作者:
项目:
/**
* 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);
}
作者:Atli
项目:docker-magento
/**
* 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;
}
作者:shabbirvividad
项目:magento
/**
* 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;
}
作者:niranjanssie
项目:magento
/**
* 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;
}
作者:pavelnovitsk
项目:magento
/**
* 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;
}