Magento 2: How to get first and last name of customer?How to make last name optional in Magento 1.8Added last name and search functionality in Customer Gridmagento make last name optionalWhy Magento ask First Name and Last Name?How to reverse first name and last name globallyImport Customers to Magento - Customer Name is Whole Name, Not First and LastHow to Make First and Last Name Optional for addresses?Get customer name from customer id using object managerHow to fetch First Name Last Name using Magento 2customer first name and last name separately (Magento 2)
Efficiently merge lists chronologically without duplicates?
Smooth switching between 12v batteries, with toggle switch
Who operates delivery flights for commercial airlines?
Is there any word or phrase for negative bearing?
Why is the relationship between frequency and pitch exponential?
How to pass a regex when finding a directory path in bash?
Payment instructions from HomeAway look fishy to me
Word for a small burst of laughter that can't be held back
Avoiding cliches when writing gods
Implement Homestuck's Catenative Doomsday Dice Cascader
Accidentally renamed tar.gz file to a non tar.gz file, will my file be messed up
Why don't B747s start takeoffs with full throttle?
How to make a setting relevant?
Did Darth Vader wear the same suit for 20+ years?
Function to extract float from different price patterns
How can I instantiate a lambda closure type in C++11/14?
Sharing one invocation list between multiple events on the same object in C#
Bent spoke design wheels — feasible?
Do adult Russians normally hand-write Cyrillic as cursive or as block letters?
What do we gain with higher order logics?
Bash difference or preferred negation statement
Does the "6 seconds per round" rule apply to speaking/roleplaying during combat situations?
How bad would a partial hash leak be, realistically?
What is in `tex.print` or `tex.sprint`?
Magento 2: How to get first and last name of customer?
How to make last name optional in Magento 1.8Added last name and search functionality in Customer Gridmagento make last name optionalWhy Magento ask First Name and Last Name?How to reverse first name and last name globallyImport Customers to Magento - Customer Name is Whole Name, Not First and LastHow to Make First and Last Name Optional for addresses?Get customer name from customer id using object managerHow to fetch First Name Last Name using Magento 2customer first name and last name separately (Magento 2)
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have a customer ID and I want to get first name and last name of that customer. Any solution?
magento2 customer customer-account customer-attribute
add a comment |
I have a customer ID and I want to get first name and last name of that customer. Any solution?
magento2 customer customer-account customer-attribute
add a comment |
I have a customer ID and I want to get first name and last name of that customer. Any solution?
magento2 customer customer-account customer-attribute
I have a customer ID and I want to get first name and last name of that customer. Any solution?
magento2 customer customer-account customer-attribute
magento2 customer customer-account customer-attribute
asked Jan 3 '18 at 16:15
umair ayubumair ayub
515829
515829
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
The Best idea to use repository interface for getting customer data Magento 2.2..
MagentoCustomerApiCustomerRepositoryInterface
Use function getById($customerId)
Inject that class on __construct function then use this class of getting customer object
public function __construct(
MagentoCustomerApiCustomerRepositoryInterface $customerRepository
)
$this->customerRepository = $customerRepository;
public function getCustomerDetails()
$customer = $this->customerRepository->getById($customerId);
if($customer->getId())
echo $customer->getFirstname();
echo $customer->getLastname();
You want to use Object Manager then this
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$customerRepository = $objectManager->create(MagentoCustomerApiCustomerRepositoryInterface::class);
$customer = $customerRepository->getById(CUSTOMER_ID);
if($customer->getId())
echo $customer->getFirstname();
echo $customer->getLastname();
add a comment |
Use below code
$customerID = 10; // your customer-id
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$customerObj = $objectManager->create('MagentoCustomerModelCustomer')
->load($customerID);
$customerFirstName = $customerObj->getFirstName();
$customerLastName = $customerObj->getLastName();
By factory method:
protected $_customers;
public function __construct(
...
MagentoCustomerModelCustomer $customers
...
)
...
$this->_customers = $customers;
...
public function getCustomer($customerId)
//Get customer by customerID
$customer = $this->_customers->load($customerId);
echo $customer->getFirstName(); //Print Customer First Name
echo $customer->getLastName(); //Print Customer Last Name
public function getCollection()
//Get customer collection
return $this->_customers->getCollection();
Note: It is not recommended to use objectManager directly.
add a comment |
You can achieve like this also:
<?php
namespace MasteringItdesireBlockIndex;
class Index extends MagentoFrameworkViewElementTemplate
protected $_customer;
public function __construct(
MagentoCustomerModelCustomer $customer,
MagentoBackendBlockTemplateContext $context
)
$this->_customer = $customer;
parent::__construct($context);
public function getCustomer()
$customerId = '189'; //You customer ID
$customer = $this->_customer->getCollection()->addAttributeToFilter('entity_id', array('eq' => $customerId));
echo "Customer Name:".$customer->getFirstName();
echo "Customer Name:".$customer->getLastName();
Hope, This will help you some extend.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f207966%2fmagento-2-how-to-get-first-and-last-name-of-customer%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
The Best idea to use repository interface for getting customer data Magento 2.2..
MagentoCustomerApiCustomerRepositoryInterface
Use function getById($customerId)
Inject that class on __construct function then use this class of getting customer object
public function __construct(
MagentoCustomerApiCustomerRepositoryInterface $customerRepository
)
$this->customerRepository = $customerRepository;
public function getCustomerDetails()
$customer = $this->customerRepository->getById($customerId);
if($customer->getId())
echo $customer->getFirstname();
echo $customer->getLastname();
You want to use Object Manager then this
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$customerRepository = $objectManager->create(MagentoCustomerApiCustomerRepositoryInterface::class);
$customer = $customerRepository->getById(CUSTOMER_ID);
if($customer->getId())
echo $customer->getFirstname();
echo $customer->getLastname();
add a comment |
The Best idea to use repository interface for getting customer data Magento 2.2..
MagentoCustomerApiCustomerRepositoryInterface
Use function getById($customerId)
Inject that class on __construct function then use this class of getting customer object
public function __construct(
MagentoCustomerApiCustomerRepositoryInterface $customerRepository
)
$this->customerRepository = $customerRepository;
public function getCustomerDetails()
$customer = $this->customerRepository->getById($customerId);
if($customer->getId())
echo $customer->getFirstname();
echo $customer->getLastname();
You want to use Object Manager then this
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$customerRepository = $objectManager->create(MagentoCustomerApiCustomerRepositoryInterface::class);
$customer = $customerRepository->getById(CUSTOMER_ID);
if($customer->getId())
echo $customer->getFirstname();
echo $customer->getLastname();
add a comment |
The Best idea to use repository interface for getting customer data Magento 2.2..
MagentoCustomerApiCustomerRepositoryInterface
Use function getById($customerId)
Inject that class on __construct function then use this class of getting customer object
public function __construct(
MagentoCustomerApiCustomerRepositoryInterface $customerRepository
)
$this->customerRepository = $customerRepository;
public function getCustomerDetails()
$customer = $this->customerRepository->getById($customerId);
if($customer->getId())
echo $customer->getFirstname();
echo $customer->getLastname();
You want to use Object Manager then this
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$customerRepository = $objectManager->create(MagentoCustomerApiCustomerRepositoryInterface::class);
$customer = $customerRepository->getById(CUSTOMER_ID);
if($customer->getId())
echo $customer->getFirstname();
echo $customer->getLastname();
The Best idea to use repository interface for getting customer data Magento 2.2..
MagentoCustomerApiCustomerRepositoryInterface
Use function getById($customerId)
Inject that class on __construct function then use this class of getting customer object
public function __construct(
MagentoCustomerApiCustomerRepositoryInterface $customerRepository
)
$this->customerRepository = $customerRepository;
public function getCustomerDetails()
$customer = $this->customerRepository->getById($customerId);
if($customer->getId())
echo $customer->getFirstname();
echo $customer->getLastname();
You want to use Object Manager then this
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$customerRepository = $objectManager->create(MagentoCustomerApiCustomerRepositoryInterface::class);
$customer = $customerRepository->getById(CUSTOMER_ID);
if($customer->getId())
echo $customer->getFirstname();
echo $customer->getLastname();
edited May 27 at 14:23
answered Jan 3 '18 at 17:27
Amit Bera♦Amit Bera
60.7k1682181
60.7k1682181
add a comment |
add a comment |
Use below code
$customerID = 10; // your customer-id
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$customerObj = $objectManager->create('MagentoCustomerModelCustomer')
->load($customerID);
$customerFirstName = $customerObj->getFirstName();
$customerLastName = $customerObj->getLastName();
By factory method:
protected $_customers;
public function __construct(
...
MagentoCustomerModelCustomer $customers
...
)
...
$this->_customers = $customers;
...
public function getCustomer($customerId)
//Get customer by customerID
$customer = $this->_customers->load($customerId);
echo $customer->getFirstName(); //Print Customer First Name
echo $customer->getLastName(); //Print Customer Last Name
public function getCollection()
//Get customer collection
return $this->_customers->getCollection();
Note: It is not recommended to use objectManager directly.
add a comment |
Use below code
$customerID = 10; // your customer-id
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$customerObj = $objectManager->create('MagentoCustomerModelCustomer')
->load($customerID);
$customerFirstName = $customerObj->getFirstName();
$customerLastName = $customerObj->getLastName();
By factory method:
protected $_customers;
public function __construct(
...
MagentoCustomerModelCustomer $customers
...
)
...
$this->_customers = $customers;
...
public function getCustomer($customerId)
//Get customer by customerID
$customer = $this->_customers->load($customerId);
echo $customer->getFirstName(); //Print Customer First Name
echo $customer->getLastName(); //Print Customer Last Name
public function getCollection()
//Get customer collection
return $this->_customers->getCollection();
Note: It is not recommended to use objectManager directly.
add a comment |
Use below code
$customerID = 10; // your customer-id
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$customerObj = $objectManager->create('MagentoCustomerModelCustomer')
->load($customerID);
$customerFirstName = $customerObj->getFirstName();
$customerLastName = $customerObj->getLastName();
By factory method:
protected $_customers;
public function __construct(
...
MagentoCustomerModelCustomer $customers
...
)
...
$this->_customers = $customers;
...
public function getCustomer($customerId)
//Get customer by customerID
$customer = $this->_customers->load($customerId);
echo $customer->getFirstName(); //Print Customer First Name
echo $customer->getLastName(); //Print Customer Last Name
public function getCollection()
//Get customer collection
return $this->_customers->getCollection();
Note: It is not recommended to use objectManager directly.
Use below code
$customerID = 10; // your customer-id
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$customerObj = $objectManager->create('MagentoCustomerModelCustomer')
->load($customerID);
$customerFirstName = $customerObj->getFirstName();
$customerLastName = $customerObj->getLastName();
By factory method:
protected $_customers;
public function __construct(
...
MagentoCustomerModelCustomer $customers
...
)
...
$this->_customers = $customers;
...
public function getCustomer($customerId)
//Get customer by customerID
$customer = $this->_customers->load($customerId);
echo $customer->getFirstName(); //Print Customer First Name
echo $customer->getLastName(); //Print Customer Last Name
public function getCollection()
//Get customer collection
return $this->_customers->getCollection();
Note: It is not recommended to use objectManager directly.
answered Jan 3 '18 at 16:20
Kishan PatadiaKishan Patadia
3,93211025
3,93211025
add a comment |
add a comment |
You can achieve like this also:
<?php
namespace MasteringItdesireBlockIndex;
class Index extends MagentoFrameworkViewElementTemplate
protected $_customer;
public function __construct(
MagentoCustomerModelCustomer $customer,
MagentoBackendBlockTemplateContext $context
)
$this->_customer = $customer;
parent::__construct($context);
public function getCustomer()
$customerId = '189'; //You customer ID
$customer = $this->_customer->getCollection()->addAttributeToFilter('entity_id', array('eq' => $customerId));
echo "Customer Name:".$customer->getFirstName();
echo "Customer Name:".$customer->getLastName();
Hope, This will help you some extend.
add a comment |
You can achieve like this also:
<?php
namespace MasteringItdesireBlockIndex;
class Index extends MagentoFrameworkViewElementTemplate
protected $_customer;
public function __construct(
MagentoCustomerModelCustomer $customer,
MagentoBackendBlockTemplateContext $context
)
$this->_customer = $customer;
parent::__construct($context);
public function getCustomer()
$customerId = '189'; //You customer ID
$customer = $this->_customer->getCollection()->addAttributeToFilter('entity_id', array('eq' => $customerId));
echo "Customer Name:".$customer->getFirstName();
echo "Customer Name:".$customer->getLastName();
Hope, This will help you some extend.
add a comment |
You can achieve like this also:
<?php
namespace MasteringItdesireBlockIndex;
class Index extends MagentoFrameworkViewElementTemplate
protected $_customer;
public function __construct(
MagentoCustomerModelCustomer $customer,
MagentoBackendBlockTemplateContext $context
)
$this->_customer = $customer;
parent::__construct($context);
public function getCustomer()
$customerId = '189'; //You customer ID
$customer = $this->_customer->getCollection()->addAttributeToFilter('entity_id', array('eq' => $customerId));
echo "Customer Name:".$customer->getFirstName();
echo "Customer Name:".$customer->getLastName();
Hope, This will help you some extend.
You can achieve like this also:
<?php
namespace MasteringItdesireBlockIndex;
class Index extends MagentoFrameworkViewElementTemplate
protected $_customer;
public function __construct(
MagentoCustomerModelCustomer $customer,
MagentoBackendBlockTemplateContext $context
)
$this->_customer = $customer;
parent::__construct($context);
public function getCustomer()
$customerId = '189'; //You customer ID
$customer = $this->_customer->getCollection()->addAttributeToFilter('entity_id', array('eq' => $customerId));
echo "Customer Name:".$customer->getFirstName();
echo "Customer Name:".$customer->getLastName();
Hope, This will help you some extend.
answered Jan 4 '18 at 2:51
Pramod KharadePramod Kharade
1,8221329
1,8221329
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f207966%2fmagento-2-how-to-get-first-and-last-name-of-customer%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown