本文整理汇总了PHP中Magento\Customer\Api\Data\CustomerInterface类的典型用法代码示例。如果您正苦于以下问题:PHP CustomerInterface类的具体用法?PHP CustomerInterface怎么用?PHP CustomerInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CustomerInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* @param CustomerInterface $entity
* @param array $arguments
* @return CustomerInterface
* @throws \Exception
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function execute($entity, $arguments = [])
{
$extensionAttribute = $entity->getExtensionAttributes()->getExtensionAttribute();
$extensionAttribute->setCustomerId($entity->getId());
$extensionAttribute = $this->entityManager->save($extensionAttribute);
$entity->getExtensionAttributes()->setExtensionAttribute($extensionAttribute);
return $entity;
}
示例2: setUp
public function setUp()
{
if (!function_exists('libxml_set_external_entity_loader')) {
$this->markTestSkipped('Skipped on HHVM. Will be fixed in MAGETWO-45033');
}
$this->customer = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\CustomerInterface', [], '', false, true, true);
$this->customer->expects($this->once())->method('getWebsiteId')->willReturn(2);
$this->customerDataFactory = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterfaceFactory', ['create'], [], '', false);
$this->customerDataFactory->expects($this->once())->method('create')->willReturn($this->customer);
$this->form = $this->getMock('Magento\\Customer\\Model\\Metadata\\Form', [], [], '', false);
$this->request = $this->getMockForAbstractClass('Magento\\Framework\\App\\RequestInterface', [], '', false, true, true, ['getPost']);
$this->response = $this->getMockForAbstractClass('Magento\\Framework\\App\\ResponseInterface', [], '', false);
$this->formFactory = $this->getMock('Magento\\Customer\\Model\\Metadata\\FormFactory', ['create'], [], '', false);
$this->formFactory->expects($this->atLeastOnce())->method('create')->willReturn($this->form);
$this->extensibleDataObjectConverter = $this->getMock('Magento\\Framework\\Api\\ExtensibleDataObjectConverter', [], [], '', false);
$this->dataObjectHelper = $this->getMock('Magento\\Framework\\Api\\DataObjectHelper', [], [], '', false);
$this->dataObjectHelper->expects($this->once())->method('populateWithArray');
$this->customerAccountManagement = $this->getMockForAbstractClass('Magento\\Customer\\Api\\AccountManagementInterface', [], '', false, true, true);
$this->resultJson = $this->getMock('Magento\\Framework\\Controller\\Result\\Json', [], [], '', false);
$this->resultJson->expects($this->once())->method('setData');
$this->resultJsonFactory = $this->getMock('Magento\\Framework\\Controller\\Result\\JsonFactory', ['create'], [], '', false);
$this->resultJsonFactory->expects($this->once())->method('create')->willReturn($this->resultJson);
$objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->controller = $objectHelper->getObject('Magento\\Customer\\Controller\\Adminhtml\\Index\\Validate', ['request' => $this->request, 'response' => $this->response, 'customerDataFactory' => $this->customerDataFactory, 'formFactory' => $this->formFactory, 'extensibleDataObjectConverter' => $this->extensibleDataObjectConverter, 'customerAccountManagement' => $this->customerAccountManagement, 'resultJsonFactory' => $this->resultJsonFactory, 'dataObjectHelper' => $this->dataObjectHelper]);
}
示例3: save
/**
* @param CustomerInterface $customer
* @return \Openpay\Client\Type\OpenpayCustomerType
* @throws LocalizedException
*/
public function save(CustomerInterface $customer)
{
$params = ['name' => $customer->getFirstname(), 'last_name' => $customer->getLastname(), 'email' => $customer->getEmail(), 'requires_account' => self::CUSTOMER_REQUIRES_ACCOUNT, 'external_id' => $customer->getId()];
try {
$openpayCustomer = $this->customerAdapter->store($params);
} catch (OpenpayException $e) {
throw new LocalizedException(__($e->getDescription()), $e);
}
return $openpayCustomer;
}
示例4: execute
/**
* @param CustomerInterface $entity
* @param array $arguments
* @return CustomerInterface
* @throws \Exception
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function execute($entity, $arguments = [])
{
$newAddresses = [];
foreach ($entity->getAddresses() as $address) {
$address->setCustomerId($entity->getId());
$newAddresses[] = $this->entityManager->save($address);
}
$entity->setAddresses($newAddresses);
return $entity;
}
示例5: getBusCodeForCustomerGroup
/** @inheritdoc */
public function getBusCodeForCustomerGroup(\Magento\Customer\Api\Data\CustomerInterface $customer)
{
$result = self::B_CUST_GROUP_RETAIL;
$groupId = $customer->getGroupId();
if ($groupId == self::M_CUST_GROUP_DISTRIBUTOR) {
$result = self::B_CUST_GROUP_DISTRIBUTOR;
} elseif ($groupId == self::M_CUST_GROUP_WHOLESALE) {
$result = self::B_CUST_GROUP_WHOLESALE;
}
return $result;
}
示例6: execute
/**
* @param CustomerInterface $entity
* @param array $arguments
* @return CustomerInterface
* @throws \Exception
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function execute($entity, $arguments = [])
{
$metadata = $this->metadataPool->getMetadata(ExtensionAttributeInterface::class);
$connection = $this->resourceConnection->getConnectionByName($metadata->getEntityConnectionName());
$id = $connection->fetchOne($connection->select()->from($metadata->getEntityTable(), [$metadata->getIdentifierField()])->where('customer_id = ?', $entity->getId())->limit(1));
$extensionAttribute = $this->extensionAttributeFactory->create();
$extensionAttribute = $this->entityManager->load($extensionAttribute, $id);
$customerExtension = $this->customerExtensionFactory->create(['data' => ['extension_attribute' => $extensionAttribute]]);
$entity->setExtensionAttributes($customerExtension);
return $entity;
}
示例7: testEditPostActionWithoutErrors
/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testEditPostActionWithoutErrors()
{
$customerId = 24;
$address = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\AddressInterface', [], '', false);
$loadedCustomer = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\CustomerInterface', [], 'loadedCustomer', false);
$loadedCustomer->expects($this->once())->method('getAddresses')->willReturn([$address, $address]);
$this->resultRedirectFactory->expects($this->once())->method('create')->willReturn($this->redirectResultMock);
$this->formKeyValidator->expects($this->once())->method('validate')->willReturn(true);
$this->request->expects($this->once())->method('isPost')->willReturn(true);
$this->customerSession->expects($this->once())->method('getCustomerId')->willReturn($customerId);
$this->customerExtractor->expects($this->once())->method('extract')->willReturn($this->customer);
$this->customer->expects($this->once())->method('setId')->with($customerId);
$this->customer->expects($this->once())->method('getAddresses')->willReturn(null);
$this->customerRepository->expects($this->exactly(2))->method('getById')->with($customerId)->willReturn($loadedCustomer);
$this->customer->expects($this->once())->method('setAddresses')->with([$address, $address]);
$this->request->expects($this->once())->method('getParam')->with('change_password')->willReturn(true);
$this->request->expects($this->at(2))->method('getPost')->with('current_password', null)->willReturn(123);
$this->request->expects($this->at(3))->method('getPost')->with('password', null)->willReturn(321);
$this->request->expects($this->at(4))->method('getPost')->with('password_confirmation', null)->willReturn(321);
$this->customerAccountManagement->expects($this->once())->method('changePassword');
$this->customerRepository->expects($this->once())->method('save');
$messageCollection = $this->getMock('Magento\\Framework\\Message\\Collection', [], [], '', false);
$messageCollection->expects($this->once())->method('getCount')->willReturn(0);
$this->messageManager->expects($this->once())->method('getMessages')->willReturn($messageCollection);
$this->messageManager->expects($this->once())->method('addSuccess')->with('You saved the account information.');
$this->redirectResultMock->expects($this->once())->method('setPath')->with('customer/account')->willReturn('http://test.com/customer/account/edit');
$this->assertSame($this->redirectResultMock, $this->getController()->execute());
}
示例8: _populateQuoteAddrShipping
public function _populateQuoteAddrShipping(\Magento\Quote\Model\Quote $quote, \Magento\Customer\Api\Data\CustomerInterface $customerDo)
{
/** @var \Magento\Quote\Model\Quote\Address $addr */
$addr = $this->_manObj->create(\Magento\Quote\Model\Quote\Address::class);
$addr->setFirstname($customerDo->getFirstname());
$addr->setLastname($customerDo->getLastname());
$addr->setEmail($customerDo->getEmail());
$addr->setTelephone('23344556');
$addr->setStreet('Liela iela');
$addr->setCity('Riga');
$addr->setRegionId(362);
// Riga region
$addr->setPostcode('1010');
$addr->setCountryId('LV');
$quote->setShippingAddress($addr);
return $quote;
}
示例9: testExtract
public function testExtract()
{
$customerData = ['firstname' => 'firstname', 'lastname' => 'firstname', 'email' => 'email.example.com'];
$this->formFactory->expects($this->once())->method('create')->with('customer', 'form-code')->willReturn($this->customerForm);
$this->customerForm->expects($this->once())->method('extractData')->with($this->request)->willReturn($customerData);
$this->customerForm->expects($this->once())->method('getAllowedAttributes')->willReturn(['group_id' => 'attribute object']);
$this->customerFactory->expects($this->once())->method('create')->willReturn($this->customerData);
$this->dataObjectHelper->expects($this->once())->method('populateWithArray')->with($this->customerData, $customerData, '\\Magento\\Customer\\Api\\Data\\CustomerInterface')->willReturn($this->customerData);
$this->storeManager->expects($this->once())->method('getStore')->willReturn($this->store);
$this->store->expects($this->exactly(2))->method('getId')->willReturn(1);
$this->customerGroupManagement->expects($this->once())->method('getDefaultGroup')->with(1)->willReturn($this->customerGroup);
$this->customerGroup->expects($this->once())->method('getId')->willReturn(1);
$this->customerData->expects($this->once())->method('setGroupId')->with(1);
$this->store->expects($this->once())->method('getWebsiteId')->willReturn(1);
$this->customerData->expects($this->once())->method('setWebsiteId')->with(1);
$this->customerData->expects($this->once())->method('setStoreId')->with(1);
$this->assertSame($this->customerData, $this->customerExtractor->extract('form-code', $this->request));
}
示例10: getCustomerName
/**
* Concatenate all customer name parts into full customer name.
*
* @param CustomerInterface $customerData
* @return string
*/
public function getCustomerName(CustomerInterface $customerData)
{
$name = '';
$prefixMetadata = $this->_customerMetadataService->getAttributeMetadata('prefix');
if ($prefixMetadata->isVisible() && $customerData->getPrefix()) {
$name .= $customerData->getPrefix() . ' ';
}
$name .= $customerData->getFirstname();
$middleNameMetadata = $this->_customerMetadataService->getAttributeMetadata('middlename');
if ($middleNameMetadata->isVisible() && $customerData->getMiddlename()) {
$name .= ' ' . $customerData->getMiddlename();
}
$name .= ' ' . $customerData->getLastname();
$suffixMetadata = $this->_customerMetadataService->getAttributeMetadata('suffix');
if ($suffixMetadata->isVisible() && $customerData->getSuffix()) {
$name .= ' ' . $customerData->getSuffix();
}
return $name;
}
示例11: createOrUpdateAndLogin
/**
* Create or update user by using data from facebook and login to store
*
* @param GraphUser $facebookUser
* @param AccessToken $accessToken
*
* @return CustomerInterface
*/
private function createOrUpdateAndLogin(GraphUser $facebookUser, AccessToken $accessToken)
{
if (!$this->customer->getId()) {
$this->customer->setEmail($facebookUser->getEmail());
$this->customer->setFirstname($facebookUser->getFirstName());
$this->customer->setLastname($facebookUser->getLastName());
$this->customer->setMiddlename($facebookUser->getMiddleName());
$this->customer->setGender((int) ($facebookUser->getGender() == 'male'));
}
$this->customer->setCustomAttribute('sf_id', $facebookUser->getId());
$this->customer->setCustomAttribute('sf_access_token', serialize($accessToken));
if ($this->customer->getId()) {
$customer = $this->customerRepository->save($this->customer);
} else {
$customer = $this->accountManagement->createAccount($this->customer);
}
$this->login($customer->getId());
return $customer;
}
示例12: testGetCustomerDepersonalizeCustomerData
/**
* test getCustomer method, method returns depersonalized customer Data
*/
public function testGetCustomerDepersonalizeCustomerData()
{
$this->requestMock->expects($this->once())->method('isAjax')->will($this->returnValue(false));
$this->layoutMock->expects($this->once())->method('isCacheable')->will($this->returnValue(true));
$this->viewMock->expects($this->once())->method('isLayoutLoaded')->will($this->returnValue(true));
$this->moduleManagerMock->expects($this->once())->method('isEnabled')->with($this->equalTo('Magento_PageCache'))->will($this->returnValue(true));
$this->customerSessionMock->expects($this->once())->method('getCustomerGroupId')->will($this->returnValue($this->customerGroupId));
$this->customerInterfaceFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->customerDataMock));
$this->customerDataMock->expects($this->once())->method('setGroupId')->with($this->equalTo($this->customerGroupId))->will($this->returnSelf());
$this->assertEquals($this->customerDataMock, $this->currentCustomer->getCustomer());
}
示例13: testPopulateCustomerInfo
public function testPopulateCustomerInfo()
{
$this->quoteMock->expects($this->once())->method('getCustomer')->willReturn($this->customerMock);
$this->customerMock->expects($this->atLeastOnce())->method('getId')->willReturn(null);
$this->customerMock->expects($this->atLeastOnce())->method('getDefaultBilling')->willReturn(100500);
$this->quoteMock->expects($this->atLeastOnce())->method('getBillingAddress')->willReturn($this->quoteAddressMock);
$this->quoteMock->expects($this->atLeastOnce())->method('getShippingAddress')->willReturn($this->quoteAddressMock);
$this->quoteMock->expects($this->atLeastOnce())->method('setCustomer')->with($this->customerMock)->willReturnSelf();
$this->quoteMock->expects($this->once())->method('getPasswordHash')->willReturn('password hash');
$this->quoteAddressMock->expects($this->atLeastOnce())->method('getId')->willReturn(null);
$this->customerAddressRepositoryMock->expects($this->atLeastOnce())->method('getById')->with(100500)->willReturn($this->customerAddressMock);
$this->quoteAddressMock->expects($this->atLeastOnce())->method('importCustomerAddressData')->willReturnSelf();
$this->accountManagementMock->expects($this->once())->method('createAccountWithPasswordHash')->with($this->customerMock, 'password hash')->willReturn($this->customerMock);
$this->customerManagement->populateCustomerInfo($this->quoteMock);
}
示例14: iHaveANewAddressWith
/**
* @Given I have a new address with :street :city :region :zip :country
*/
public function iHaveANewAddressWith($street, $city, $region, $zip, $country)
{
$countryId = $this->getCountryId($country);
$region = $this->loadRegionByName($region, $countryId);
$address = $this->addressFactory->create()->setStreet((array) $street)->setCity($city)->setPostcode($zip)->setCountryId($countryId)->setRegion($region)->setRegionId($region->getRegionId())->setFirstname($this->customer->getFirstname())->setLastname($this->customer->getLastname())->setTelephone('555-555-5555')->setCustomerId($this->customer->getId());
$this->customerAddress = $address;
}
示例15: _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);
}
/** @var \Magento\Customer\Api\AddressRepositoryInterface $addressRepository */
$addressRepository = Bootstrap::getObjectManager()->create('Magento\\Customer\\Api\\AddressRepositoryInterface');
$shippingAddress->setSameAsBilling(0)->setCustomerAddressData($addressRepository->getById($this->_customer->getDefaultBilling()))->save();
}