本文整理汇总了PHP中Magento\Customer\Api\Data\CustomerInterface::getId方法的典型用法代码示例。如果您正苦于以下问题:PHP CustomerInterface::getId方法的具体用法?PHP CustomerInterface::getId怎么用?PHP CustomerInterface::getId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Customer\Api\Data\CustomerInterface
的用法示例。
在下文中一共展示了CustomerInterface::getId方法的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: createCustomerItem
/**
* Creates a collection item that represents a customer for the customer Grid.
*
* @param CustomerInterface $customer Input data for creating the item.
* @return \Magento\Framework\Object Collection item that represents a customer
*/
protected function createCustomerItem(CustomerInterface $customer)
{
$customerNameParts = [$customer->getPrefix(), $customer->getFirstname(), $customer->getMiddlename(), $customer->getLastname(), $customer->getSuffix()];
$customerItem = new \Magento\Framework\Object();
$customerItem->setId($customer->getId());
$customerItem->setEntityId($customer->getId());
// All parts of the customer name must be displayed in the name column of the grid
$customerItem->setName(implode(' ', array_filter($customerNameParts)));
$customerItem->setEmail($customer->getEmail());
$customerItem->setWebsiteId($customer->getWebsiteId());
$customerItem->setCreatedAt($customer->getCreatedAt());
$customerItem->setGroupId($customer->getGroupId());
$billingAddress = null;
foreach ($customer->getAddresses() as $address) {
if ($address->isDefaultBilling()) {
$billingAddress = $address;
break;
}
}
if ($billingAddress !== null) {
$customerItem->setBillingTelephone($billingAddress->getTelephone());
$customerItem->setBillingPostcode($billingAddress->getPostcode());
$customerItem->setBillingCountryId($billingAddress->getCountryId());
$region = $billingAddress->getRegion() === null ? '' : $billingAddress->getRegion()->getRegion();
$customerItem->setBillingRegion($region);
}
return $customerItem;
}
示例3: 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;
}
示例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: 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;
}
示例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: 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;
}
示例8: getFullCustomerObject
/**
* Create an object with data merged from Customer and CustomerSecure
*
* @param CustomerInterface $customer
* @return Data\CustomerSecure
*/
protected function getFullCustomerObject($customer)
{
// No need to flatten the custom attributes or nested objects since the only usage is for email templates and
// object passed for events
$mergedCustomerData = $this->customerRegistry->retrieveSecureData($customer->getId());
$customerData = $this->dataProcessor->buildOutputDataArray($customer, '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
$mergedCustomerData->addData($customerData);
$mergedCustomerData->setData('name', $this->customerViewHelper->getCustomerName($customer));
return $mergedCustomerData;
}
示例9: _prepareCustomerAddress
/**
* Create customer address and save it in the quote so that it can be used to persist later.
*
* @param \Magento\Customer\Api\Data\CustomerInterface $customer
* @param \Magento\Quote\Model\Quote\Address $quoteCustomerAddress
* @return void
* @throws \InvalidArgumentException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
protected function _prepareCustomerAddress($customer, $quoteCustomerAddress)
{
// Possible that customerId is null for new customers
$quoteCustomerAddress->setCustomerId($customer->getId());
$customerAddress = $quoteCustomerAddress->exportCustomerAddress();
$quoteAddressId = $quoteCustomerAddress->getCustomerAddressId();
$addressType = $quoteCustomerAddress->getAddressType();
if ($quoteAddressId) {
/** Update existing address */
$existingAddressDataObject = $this->addressRepository->getById($quoteAddressId);
/** Update customer address data */
$this->dataObjectHelper->mergeDataObjects(get_class($existingAddressDataObject), $existingAddressDataObject, $customerAddress);
$customerAddress = $existingAddressDataObject;
} elseif ($addressType == \Magento\Quote\Model\Quote\Address::ADDRESS_TYPE_SHIPPING) {
try {
$billingAddressDataObject = $this->accountManagement->getDefaultBillingAddress($customer->getId());
} catch (\Exception $e) {
/** Billing address does not exist. */
}
$isShippingAsBilling = $quoteCustomerAddress->getSameAsBilling();
if (isset($billingAddressDataObject) && $isShippingAsBilling) {
/** Set existing billing address as default shipping */
$customerAddress = $billingAddressDataObject;
$customerAddress->setIsDefaultShipping(true);
}
}
switch ($addressType) {
case \Magento\Quote\Model\Quote\Address::ADDRESS_TYPE_BILLING:
if (is_null($customer->getDefaultBilling())) {
$customerAddress->setIsDefaultBilling(true);
}
break;
case \Magento\Quote\Model\Quote\Address::ADDRESS_TYPE_SHIPPING:
if (is_null($customer->getDefaultShipping())) {
$customerAddress->setIsDefaultShipping(true);
}
break;
default:
throw new \InvalidArgumentException('Customer address type is invalid.');
}
$this->getQuote()->setCustomer($customer);
$this->getQuote()->addCustomerAddress($customerAddress);
}
示例10: setCustomer
/**
* Define customer object
*
* @param \Magento\Customer\Api\Data\CustomerInterface $customer
* @return $this
*/
public function setCustomer(\Magento\Customer\Api\Data\CustomerInterface $customer = null)
{
/* @TODO: Remove the method after all external usages are refactored in MAGETWO-19930 */
$this->_customer = $customer;
$this->setCustomerId($customer->getId());
$origAddresses = $customer->getAddresses();
$customer->setAddresses([]);
$customerDataFlatArray = $this->objectFactory->create($this->extensibleDataObjectConverter->toFlatArray($customer, [], '\\Magento\\Customer\\Api\\Data\\CustomerInterface'));
$customer->setAddresses($origAddresses);
$this->_objectCopyService->copyFieldsetToTarget('customer_account', 'to_quote', $customerDataFlatArray, $this);
return $this;
}
示例11: delete
/**
* {@inheritdoc}
*/
public function delete(\Magento\Customer\Api\Data\CustomerInterface $customer)
{
return $this->deleteById($customer->getId());
}
示例12: loadByCustomerData
/**
* Load subscriber by customer
*
* @param \Magento\Customer\Api\Data\CustomerInterface $customer
* @return array
*/
public function loadByCustomerData(\Magento\Customer\Api\Data\CustomerInterface $customer)
{
$select = $this->connection->select()->from($this->getMainTable())->where('customer_id=:customer_id');
$result = $this->connection->fetchRow($select, ['customer_id' => $customer->getId()]);
if ($result) {
return $result;
}
$select = $this->connection->select()->from($this->getMainTable())->where('subscriber_email=:subscriber_email');
$result = $this->connection->fetchRow($select, ['subscriber_email' => $customer->getEmail()]);
if ($result) {
return $result;
}
return [];
}
示例13: createQuote
/**
* Create a quote object with customer
*
* @param array $quoteData
* @param \Magento\Customer\Api\Data\CustomerInterface $customer
* @return \Magento\Quote\Model\Quote
*/
protected function createQuote($quoteData, $customer)
{
/** @var \Magento\Customer\Api\AddressRepositoryInterface $addressService */
$addressService = $this->objectManager->create('Magento\\Customer\\Api\\AddressRepositoryInterface');
/** @var array $shippingAddressOverride */
$shippingAddressOverride = empty($quoteData['shipping_address']) ? [] : $quoteData['shipping_address'];
/** @var \Magento\Customer\Model\Address $shippingAddress */
$shippingAddress = $this->createCustomerAddress($shippingAddressOverride, $customer->getId());
/** @var \Magento\Quote\Model\Quote\Address $quoteShippingAddress */
$quoteShippingAddress = $this->objectManager->create('Magento\\Quote\\Model\\Quote\\Address');
$quoteShippingAddress->importCustomerAddressData($addressService->getById($shippingAddress->getId()));
/** @var array $billingAddressOverride */
$billingAddressOverride = empty($quoteData['billing_address']) ? [] : $quoteData['billing_address'];
/** @var \Magento\Customer\Model\Address $billingAddress */
$billingAddress = $this->createCustomerAddress($billingAddressOverride, $customer->getId());
/** @var \Magento\Quote\Model\Quote\Address $quoteBillingAddress */
$quoteBillingAddress = $this->objectManager->create('Magento\\Quote\\Model\\Quote\\Address');
$quoteBillingAddress->importCustomerAddressData($addressService->getById($billingAddress->getId()));
/** @var \Magento\Quote\Model\Quote $quote */
$quote = $this->objectManager->create('Magento\\Quote\\Model\\Quote');
$quote->setStoreId(1)->setIsActive(true)->setIsMultiShipping(false)->assignCustomerWithAddressChange($customer, $quoteBillingAddress, $quoteShippingAddress)->setCheckoutMethod('register')->setPasswordHash($this->accountManagement->getPasswordHash(static::CUSTOMER_PASSWORD));
return $quote;
}
示例14: getQuote
/**
* Get checkout quote instance by current session
*
* @return Quote
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function getQuote()
{
$this->_eventManager->dispatch('custom_quote_process', ['checkout_session' => $this]);
if ($this->_quote === null) {
$quote = $this->quoteFactory->create();
if ($this->getQuoteId()) {
try {
if ($this->_loadInactive) {
$quote = $this->quoteRepository->get($this->getQuoteId());
} else {
$quote = $this->quoteRepository->getActive($this->getQuoteId());
}
/**
* If current currency code of quote is not equal current currency code of store,
* need recalculate totals of quote. It is possible if customer use currency switcher or
* store switcher.
*/
if ($quote->getQuoteCurrencyCode() != $this->_storeManager->getStore()->getCurrentCurrencyCode()) {
$quote->setStore($this->_storeManager->getStore());
$this->quoteRepository->save($quote->collectTotals());
/*
* We mast to create new quote object, because collectTotals()
* can to create links with other objects.
*/
$quote = $this->quoteRepository->get($this->getQuoteId());
}
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
$this->setQuoteId(null);
}
}
if (!$this->getQuoteId()) {
if ($this->_customerSession->isLoggedIn() || $this->_customer) {
$customerId = $this->_customer ? $this->_customer->getId() : $this->_customerSession->getCustomerId();
try {
$quote = $this->quoteRepository->getActiveForCustomer($customerId);
$this->setQuoteId($quote->getId());
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
}
} else {
$quote->setIsCheckoutCart(true);
$this->_eventManager->dispatch('checkout_quote_init', ['quote' => $quote]);
}
}
if ($this->_customer) {
$quote->setCustomer($this->_customer);
} elseif ($this->_customerSession->isLoggedIn()) {
$quote->setCustomer($this->customerRepository->getById($this->_customerSession->getCustomerId()));
}
$quote->setStore($this->_storeManager->getStore());
$this->_quote = $quote;
}
if (!$this->isQuoteMasked() && !$this->_customerSession->isLoggedIn() && $this->getQuoteId()) {
$quoteId = $this->getQuoteId();
/** @var $quoteIdMask \Magento\Quote\Model\QuoteIdMask */
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($quoteId, 'quote_id');
if ($quoteIdMask->getMaskedId() === null) {
$quoteIdMask->setQuoteId($quoteId)->save();
}
$this->setIsQuoteMasked(true);
}
$remoteAddress = $this->_remoteAddress->getRemoteAddress();
if ($remoteAddress) {
$this->_quote->setRemoteIp($remoteAddress);
$xForwardIp = $this->request->getServer('HTTP_X_FORWARDED_FOR');
$this->_quote->setXForwardedFor($xForwardIp);
}
return $this->_quote;
}
示例15: processChangeEmailRequest
/**
* Process change email request
*
* @param \Magento\Customer\Api\Data\CustomerInterface $currentCustomerDataObject
* @return void
* @throws InvalidEmailOrPasswordException
* @throws UserLockedException
*/
private function processChangeEmailRequest(\Magento\Customer\Api\Data\CustomerInterface $currentCustomerDataObject)
{
if ($this->getRequest()->getParam('change_email')) {
// authenticate user for changing email
try {
$this->getAuthentication()->authenticate($currentCustomerDataObject->getId(), $this->getRequest()->getPost('current_password'));
} catch (InvalidEmailOrPasswordException $e) {
throw new InvalidEmailOrPasswordException(__('The password doesn\'t match this account.'));
}
}
}