本文整理汇总了PHP中Magento\Customer\Model\Customer类的典型用法代码示例。如果您正苦于以下问题:PHP Customer类的具体用法?PHP Customer怎么用?PHP Customer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Customer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeSubscribeCustomerById
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: beforeSubscribeCustomerById
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: testGetButtonData
/**
* @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: beforeSave
/**
* 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: testUpdateDataOverrideExistingData
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());
}
示例6: testGetAccountLock
/**
* @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());
}
示例7: _prepareDataForUpdate
/**
* 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];
}
示例8: _setCustomerAddressAndSave
/**
* 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();
}
示例9: loadSelf
/**
* 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;
}
示例10: testIsConfirmationRequired
/**
* @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());
}
示例11: afterSubscribeCustomerById
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();
}
}
}
示例12: testDeleteById
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));
}
示例13: afterGenerateXml
/**
* 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;
}
示例14: beforeSubscribeCustomerById
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];
}
示例15: testExecute
/**
* @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);
}