当前位置: 首页>>代码示例>>PHP>>正文


PHP Model\Customer类代码示例

本文整理汇总了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];
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:26,代码来源:Subscriber.php

示例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];
 }
开发者ID:sendpulse,项目名称:mageia,代码行数:35,代码来源:Plugin.php

示例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());
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:13,代码来源:UnlockButtonTest.php

示例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;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:14,代码来源:Boolean.php

示例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());
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:13,代码来源:CustomerTest.php

示例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());
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:13,代码来源:PersonalInfoTest.php

示例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];
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:67,代码来源:Customer.php

示例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();
 }
开发者ID:aiesh,项目名称:magento2,代码行数:13,代码来源:AddressTest.php

示例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;
 }
开发者ID:LavoWeb,项目名称:Magento2-Inchoo_SocialConnect,代码行数:24,代码来源:User.php

示例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());
 }
开发者ID:rafaelstz,项目名称:magento2,代码行数:17,代码来源:CustomerTest.php

示例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();
         }
     }
 }
开发者ID:andrewkett,项目名称:magento2-magemonkey,代码行数:20,代码来源:Subscriber.php

示例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));
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:14,代码来源:AddressRepositoryTest.php

示例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;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:21,代码来源:DepersonalizePlugin.php

示例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];
 }
开发者ID:ebizmarts,项目名称:magento2-magemonkey,代码行数:36,代码来源:Subscriber.php

示例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);
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:14,代码来源:CustomerLoginSuccessObserverTest.php


注:本文中的Magento\Customer\Model\Customer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。