Get Customer information from order Magento 2
I want to retrieve customer information from sales order view observer in adminhtml section, currently i only know how to retrieve order in that observer like this:
namespace NamespaceModuleBlockAdminhtmlOrderView;
class Custom extends MagentoBackendBlockTemplate
{
public function getCustomAttribute(){
$order = $this->getParentBlock()->getOrder();
return $order->getId();
}
}
i need to retrieve the customer information from that order, if the order is from logged in customer
magento2 sales-order customer-attribute
add a comment |
I want to retrieve customer information from sales order view observer in adminhtml section, currently i only know how to retrieve order in that observer like this:
namespace NamespaceModuleBlockAdminhtmlOrderView;
class Custom extends MagentoBackendBlockTemplate
{
public function getCustomAttribute(){
$order = $this->getParentBlock()->getOrder();
return $order->getId();
}
}
i need to retrieve the customer information from that order, if the order is from logged in customer
magento2 sales-order customer-attribute
Did you try$order->getCustomer()
?
– Khoa TruongDinh
Jul 4 '17 at 10:06
You can directly access customer details like firstname,lastname,email from the order object . eg. $order->getCustomerEmail(),$order->getCustomerFirstname()
– Emipro Technologies Pvt. Ltd.
Jul 4 '17 at 10:07
@EmiproTechnologiesPvt.Ltd. thanks it works
– Idham Choudry
Jul 4 '17 at 10:17
@Idham Most welcome
– Emipro Technologies Pvt. Ltd.
Jul 4 '17 at 10:35
add a comment |
I want to retrieve customer information from sales order view observer in adminhtml section, currently i only know how to retrieve order in that observer like this:
namespace NamespaceModuleBlockAdminhtmlOrderView;
class Custom extends MagentoBackendBlockTemplate
{
public function getCustomAttribute(){
$order = $this->getParentBlock()->getOrder();
return $order->getId();
}
}
i need to retrieve the customer information from that order, if the order is from logged in customer
magento2 sales-order customer-attribute
I want to retrieve customer information from sales order view observer in adminhtml section, currently i only know how to retrieve order in that observer like this:
namespace NamespaceModuleBlockAdminhtmlOrderView;
class Custom extends MagentoBackendBlockTemplate
{
public function getCustomAttribute(){
$order = $this->getParentBlock()->getOrder();
return $order->getId();
}
}
i need to retrieve the customer information from that order, if the order is from logged in customer
magento2 sales-order customer-attribute
magento2 sales-order customer-attribute
asked Jul 4 '17 at 9:46
Idham ChoudryIdham Choudry
1,2461736
1,2461736
Did you try$order->getCustomer()
?
– Khoa TruongDinh
Jul 4 '17 at 10:06
You can directly access customer details like firstname,lastname,email from the order object . eg. $order->getCustomerEmail(),$order->getCustomerFirstname()
– Emipro Technologies Pvt. Ltd.
Jul 4 '17 at 10:07
@EmiproTechnologiesPvt.Ltd. thanks it works
– Idham Choudry
Jul 4 '17 at 10:17
@Idham Most welcome
– Emipro Technologies Pvt. Ltd.
Jul 4 '17 at 10:35
add a comment |
Did you try$order->getCustomer()
?
– Khoa TruongDinh
Jul 4 '17 at 10:06
You can directly access customer details like firstname,lastname,email from the order object . eg. $order->getCustomerEmail(),$order->getCustomerFirstname()
– Emipro Technologies Pvt. Ltd.
Jul 4 '17 at 10:07
@EmiproTechnologiesPvt.Ltd. thanks it works
– Idham Choudry
Jul 4 '17 at 10:17
@Idham Most welcome
– Emipro Technologies Pvt. Ltd.
Jul 4 '17 at 10:35
Did you try
$order->getCustomer()
?– Khoa TruongDinh
Jul 4 '17 at 10:06
Did you try
$order->getCustomer()
?– Khoa TruongDinh
Jul 4 '17 at 10:06
You can directly access customer details like firstname,lastname,email from the order object . eg. $order->getCustomerEmail(),$order->getCustomerFirstname()
– Emipro Technologies Pvt. Ltd.
Jul 4 '17 at 10:07
You can directly access customer details like firstname,lastname,email from the order object . eg. $order->getCustomerEmail(),$order->getCustomerFirstname()
– Emipro Technologies Pvt. Ltd.
Jul 4 '17 at 10:07
@EmiproTechnologiesPvt.Ltd. thanks it works
– Idham Choudry
Jul 4 '17 at 10:17
@EmiproTechnologiesPvt.Ltd. thanks it works
– Idham Choudry
Jul 4 '17 at 10:17
@Idham Most welcome
– Emipro Technologies Pvt. Ltd.
Jul 4 '17 at 10:35
@Idham Most welcome
– Emipro Technologies Pvt. Ltd.
Jul 4 '17 at 10:35
add a comment |
4 Answers
4
active
oldest
votes
Inside observer,
$order = $observer->getEvent()->getOrder();
$orderFromFront = $order->getRemoteIp();
$guestCustomer = $order->getCustomerIsGuest();
groupId = $order->getCustomerGroupId();
$firstname = $order->getCustomerFirstname();
$lastname = $order->getCustomerMiddlename();
$lastname = $order->getCustomerLastname();
$prefix = $order->getCustomerPrefix();
$suffix = $order->getCustomerSuffix();
$dob = $order->getCustomerDob();
$taxvat = $order->getCustomerTaxvat();
$gender = $order->getCustomerGender();
For shipping address,
$order->getShippingAddress()->getData()
And for billing,
$order->getBillingAddress()->getData()
You can get all type of customer data using observer.
is$order->getCustomerIsGuest()
to check if the order from customer logged in or not?
– Idham Choudry
Jul 4 '17 at 10:19
if customer is guest at that time its return 1 otherwise null
– Rakesh Jesadiya
Jul 4 '17 at 10:19
How do I get custom attribute of customer from order?
– Manish
Jul 25 '18 at 11:06
the guest placed an order, after that they have registered, then how do i map that guest order to them
– Jaisa
Aug 23 '18 at 5:06
add a comment |
As per as,magento2 standard,you can inject Sales Collection Factory class,Then Filter that collection by Customer id.
protected $order;
public function __construct(
MagentoSalesModelOrder $order,
) {
$this->_order = $order;
parent::__construct($context, $data);
}
public function getCustomAttribute(){
$order = $this->getParentBlock()->getOrder();
$orderdetails = $this->order->load( $order->getId());
return $orderdetails ->getCustomerId();
}
or
$order = $this->_objectManager->create('MagentoSalesModelOrder')->load($id);
$email = $order->getCustomerId();
But this is not recomended.
add a comment |
@Idham choudry,
you can add below code in to your observer to get customer information.
use MagentoCustomerApiCustomerRepositoryInterface;
use MagentoCustomerModelSession;
use MagentoSalesModelOrder;
class yourobserver implements ObserverInterface
{
protected $customerSession;
protected $customerrepository;
protected $order;
public function __construct(
Session $customerSession,
CustomerRepositoryInterface $customerrepository,
Order $order
)
{
$this->customerSession = $customerSession;
$this->customerrepository = $customerrepository;
$this->order = $order;
}
public function execute(MagentoFrameworkEventObserver $observer)
{
$event = $observer->getEvent();
$orderIds = $event->getOrderIds();
$order = $observer->getEvent()->getOrder();
$ordercoll = $this->order->loadByAttribute("entity_id",$orderIds[0]);
$shippingdetails = $ordercoll->getShippingAddress()->getData();
$magento_address_id = $ordercoll->getShippingAddress()->getId();
$billingdetails = $ordercoll->getBillingAddress()->getData();
$paymentdetails = $ordercoll->getPayment()->getData();
$shipmentdetails = $ordercoll->getShippingmethod();
$customerinfo = $this->customerSession->getData();
$shipping_amount = $ordercoll->getShippingAmount();
$discount_amount = $ordercoll->getDiscountAmount();
$discount_description = $ordercoll->getDiscountDescription();
$applied_rule_ids = $ordercoll->getAppliedRuleIds();
}
}
1
i want to retrieve customer information from order data not from session
– Idham Choudry
Jul 4 '17 at 10:02
Is the data you want on the order table or order_address table?
– LM_Fielding
Jul 4 '17 at 10:14
I have updated my coding to get order billing and shipping address information. you can get customer information.
– Iyappan Perumal
Jul 4 '17 at 10:17
add a comment |
Use repository. With $order
you can do
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$customer = $objectManager->create('MagentoCustomerApiCustomerRepositoryInterface')
->getById($order->getCustomerId());
$customer
is an instance of MagentoCustomerModelDataCustomer
, just call its get() methods to access customer properties.
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');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
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%2f181939%2fget-customer-information-from-order-magento-2%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
Inside observer,
$order = $observer->getEvent()->getOrder();
$orderFromFront = $order->getRemoteIp();
$guestCustomer = $order->getCustomerIsGuest();
groupId = $order->getCustomerGroupId();
$firstname = $order->getCustomerFirstname();
$lastname = $order->getCustomerMiddlename();
$lastname = $order->getCustomerLastname();
$prefix = $order->getCustomerPrefix();
$suffix = $order->getCustomerSuffix();
$dob = $order->getCustomerDob();
$taxvat = $order->getCustomerTaxvat();
$gender = $order->getCustomerGender();
For shipping address,
$order->getShippingAddress()->getData()
And for billing,
$order->getBillingAddress()->getData()
You can get all type of customer data using observer.
is$order->getCustomerIsGuest()
to check if the order from customer logged in or not?
– Idham Choudry
Jul 4 '17 at 10:19
if customer is guest at that time its return 1 otherwise null
– Rakesh Jesadiya
Jul 4 '17 at 10:19
How do I get custom attribute of customer from order?
– Manish
Jul 25 '18 at 11:06
the guest placed an order, after that they have registered, then how do i map that guest order to them
– Jaisa
Aug 23 '18 at 5:06
add a comment |
Inside observer,
$order = $observer->getEvent()->getOrder();
$orderFromFront = $order->getRemoteIp();
$guestCustomer = $order->getCustomerIsGuest();
groupId = $order->getCustomerGroupId();
$firstname = $order->getCustomerFirstname();
$lastname = $order->getCustomerMiddlename();
$lastname = $order->getCustomerLastname();
$prefix = $order->getCustomerPrefix();
$suffix = $order->getCustomerSuffix();
$dob = $order->getCustomerDob();
$taxvat = $order->getCustomerTaxvat();
$gender = $order->getCustomerGender();
For shipping address,
$order->getShippingAddress()->getData()
And for billing,
$order->getBillingAddress()->getData()
You can get all type of customer data using observer.
is$order->getCustomerIsGuest()
to check if the order from customer logged in or not?
– Idham Choudry
Jul 4 '17 at 10:19
if customer is guest at that time its return 1 otherwise null
– Rakesh Jesadiya
Jul 4 '17 at 10:19
How do I get custom attribute of customer from order?
– Manish
Jul 25 '18 at 11:06
the guest placed an order, after that they have registered, then how do i map that guest order to them
– Jaisa
Aug 23 '18 at 5:06
add a comment |
Inside observer,
$order = $observer->getEvent()->getOrder();
$orderFromFront = $order->getRemoteIp();
$guestCustomer = $order->getCustomerIsGuest();
groupId = $order->getCustomerGroupId();
$firstname = $order->getCustomerFirstname();
$lastname = $order->getCustomerMiddlename();
$lastname = $order->getCustomerLastname();
$prefix = $order->getCustomerPrefix();
$suffix = $order->getCustomerSuffix();
$dob = $order->getCustomerDob();
$taxvat = $order->getCustomerTaxvat();
$gender = $order->getCustomerGender();
For shipping address,
$order->getShippingAddress()->getData()
And for billing,
$order->getBillingAddress()->getData()
You can get all type of customer data using observer.
Inside observer,
$order = $observer->getEvent()->getOrder();
$orderFromFront = $order->getRemoteIp();
$guestCustomer = $order->getCustomerIsGuest();
groupId = $order->getCustomerGroupId();
$firstname = $order->getCustomerFirstname();
$lastname = $order->getCustomerMiddlename();
$lastname = $order->getCustomerLastname();
$prefix = $order->getCustomerPrefix();
$suffix = $order->getCustomerSuffix();
$dob = $order->getCustomerDob();
$taxvat = $order->getCustomerTaxvat();
$gender = $order->getCustomerGender();
For shipping address,
$order->getShippingAddress()->getData()
And for billing,
$order->getBillingAddress()->getData()
You can get all type of customer data using observer.
edited 10 mins ago
magefms
571216
571216
answered Jul 4 '17 at 10:15
Rakesh JesadiyaRakesh Jesadiya
29k1572120
29k1572120
is$order->getCustomerIsGuest()
to check if the order from customer logged in or not?
– Idham Choudry
Jul 4 '17 at 10:19
if customer is guest at that time its return 1 otherwise null
– Rakesh Jesadiya
Jul 4 '17 at 10:19
How do I get custom attribute of customer from order?
– Manish
Jul 25 '18 at 11:06
the guest placed an order, after that they have registered, then how do i map that guest order to them
– Jaisa
Aug 23 '18 at 5:06
add a comment |
is$order->getCustomerIsGuest()
to check if the order from customer logged in or not?
– Idham Choudry
Jul 4 '17 at 10:19
if customer is guest at that time its return 1 otherwise null
– Rakesh Jesadiya
Jul 4 '17 at 10:19
How do I get custom attribute of customer from order?
– Manish
Jul 25 '18 at 11:06
the guest placed an order, after that they have registered, then how do i map that guest order to them
– Jaisa
Aug 23 '18 at 5:06
is
$order->getCustomerIsGuest()
to check if the order from customer logged in or not?– Idham Choudry
Jul 4 '17 at 10:19
is
$order->getCustomerIsGuest()
to check if the order from customer logged in or not?– Idham Choudry
Jul 4 '17 at 10:19
if customer is guest at that time its return 1 otherwise null
– Rakesh Jesadiya
Jul 4 '17 at 10:19
if customer is guest at that time its return 1 otherwise null
– Rakesh Jesadiya
Jul 4 '17 at 10:19
How do I get custom attribute of customer from order?
– Manish
Jul 25 '18 at 11:06
How do I get custom attribute of customer from order?
– Manish
Jul 25 '18 at 11:06
the guest placed an order, after that they have registered, then how do i map that guest order to them
– Jaisa
Aug 23 '18 at 5:06
the guest placed an order, after that they have registered, then how do i map that guest order to them
– Jaisa
Aug 23 '18 at 5:06
add a comment |
As per as,magento2 standard,you can inject Sales Collection Factory class,Then Filter that collection by Customer id.
protected $order;
public function __construct(
MagentoSalesModelOrder $order,
) {
$this->_order = $order;
parent::__construct($context, $data);
}
public function getCustomAttribute(){
$order = $this->getParentBlock()->getOrder();
$orderdetails = $this->order->load( $order->getId());
return $orderdetails ->getCustomerId();
}
or
$order = $this->_objectManager->create('MagentoSalesModelOrder')->load($id);
$email = $order->getCustomerId();
But this is not recomended.
add a comment |
As per as,magento2 standard,you can inject Sales Collection Factory class,Then Filter that collection by Customer id.
protected $order;
public function __construct(
MagentoSalesModelOrder $order,
) {
$this->_order = $order;
parent::__construct($context, $data);
}
public function getCustomAttribute(){
$order = $this->getParentBlock()->getOrder();
$orderdetails = $this->order->load( $order->getId());
return $orderdetails ->getCustomerId();
}
or
$order = $this->_objectManager->create('MagentoSalesModelOrder')->load($id);
$email = $order->getCustomerId();
But this is not recomended.
add a comment |
As per as,magento2 standard,you can inject Sales Collection Factory class,Then Filter that collection by Customer id.
protected $order;
public function __construct(
MagentoSalesModelOrder $order,
) {
$this->_order = $order;
parent::__construct($context, $data);
}
public function getCustomAttribute(){
$order = $this->getParentBlock()->getOrder();
$orderdetails = $this->order->load( $order->getId());
return $orderdetails ->getCustomerId();
}
or
$order = $this->_objectManager->create('MagentoSalesModelOrder')->load($id);
$email = $order->getCustomerId();
But this is not recomended.
As per as,magento2 standard,you can inject Sales Collection Factory class,Then Filter that collection by Customer id.
protected $order;
public function __construct(
MagentoSalesModelOrder $order,
) {
$this->_order = $order;
parent::__construct($context, $data);
}
public function getCustomAttribute(){
$order = $this->getParentBlock()->getOrder();
$orderdetails = $this->order->load( $order->getId());
return $orderdetails ->getCustomerId();
}
or
$order = $this->_objectManager->create('MagentoSalesModelOrder')->load($id);
$email = $order->getCustomerId();
But this is not recomended.
edited Jul 4 '17 at 10:24
Jjo
795114
795114
answered Jul 4 '17 at 10:18
Jeya KiruthikaJeya Kiruthika
30819
30819
add a comment |
add a comment |
@Idham choudry,
you can add below code in to your observer to get customer information.
use MagentoCustomerApiCustomerRepositoryInterface;
use MagentoCustomerModelSession;
use MagentoSalesModelOrder;
class yourobserver implements ObserverInterface
{
protected $customerSession;
protected $customerrepository;
protected $order;
public function __construct(
Session $customerSession,
CustomerRepositoryInterface $customerrepository,
Order $order
)
{
$this->customerSession = $customerSession;
$this->customerrepository = $customerrepository;
$this->order = $order;
}
public function execute(MagentoFrameworkEventObserver $observer)
{
$event = $observer->getEvent();
$orderIds = $event->getOrderIds();
$order = $observer->getEvent()->getOrder();
$ordercoll = $this->order->loadByAttribute("entity_id",$orderIds[0]);
$shippingdetails = $ordercoll->getShippingAddress()->getData();
$magento_address_id = $ordercoll->getShippingAddress()->getId();
$billingdetails = $ordercoll->getBillingAddress()->getData();
$paymentdetails = $ordercoll->getPayment()->getData();
$shipmentdetails = $ordercoll->getShippingmethod();
$customerinfo = $this->customerSession->getData();
$shipping_amount = $ordercoll->getShippingAmount();
$discount_amount = $ordercoll->getDiscountAmount();
$discount_description = $ordercoll->getDiscountDescription();
$applied_rule_ids = $ordercoll->getAppliedRuleIds();
}
}
1
i want to retrieve customer information from order data not from session
– Idham Choudry
Jul 4 '17 at 10:02
Is the data you want on the order table or order_address table?
– LM_Fielding
Jul 4 '17 at 10:14
I have updated my coding to get order billing and shipping address information. you can get customer information.
– Iyappan Perumal
Jul 4 '17 at 10:17
add a comment |
@Idham choudry,
you can add below code in to your observer to get customer information.
use MagentoCustomerApiCustomerRepositoryInterface;
use MagentoCustomerModelSession;
use MagentoSalesModelOrder;
class yourobserver implements ObserverInterface
{
protected $customerSession;
protected $customerrepository;
protected $order;
public function __construct(
Session $customerSession,
CustomerRepositoryInterface $customerrepository,
Order $order
)
{
$this->customerSession = $customerSession;
$this->customerrepository = $customerrepository;
$this->order = $order;
}
public function execute(MagentoFrameworkEventObserver $observer)
{
$event = $observer->getEvent();
$orderIds = $event->getOrderIds();
$order = $observer->getEvent()->getOrder();
$ordercoll = $this->order->loadByAttribute("entity_id",$orderIds[0]);
$shippingdetails = $ordercoll->getShippingAddress()->getData();
$magento_address_id = $ordercoll->getShippingAddress()->getId();
$billingdetails = $ordercoll->getBillingAddress()->getData();
$paymentdetails = $ordercoll->getPayment()->getData();
$shipmentdetails = $ordercoll->getShippingmethod();
$customerinfo = $this->customerSession->getData();
$shipping_amount = $ordercoll->getShippingAmount();
$discount_amount = $ordercoll->getDiscountAmount();
$discount_description = $ordercoll->getDiscountDescription();
$applied_rule_ids = $ordercoll->getAppliedRuleIds();
}
}
1
i want to retrieve customer information from order data not from session
– Idham Choudry
Jul 4 '17 at 10:02
Is the data you want on the order table or order_address table?
– LM_Fielding
Jul 4 '17 at 10:14
I have updated my coding to get order billing and shipping address information. you can get customer information.
– Iyappan Perumal
Jul 4 '17 at 10:17
add a comment |
@Idham choudry,
you can add below code in to your observer to get customer information.
use MagentoCustomerApiCustomerRepositoryInterface;
use MagentoCustomerModelSession;
use MagentoSalesModelOrder;
class yourobserver implements ObserverInterface
{
protected $customerSession;
protected $customerrepository;
protected $order;
public function __construct(
Session $customerSession,
CustomerRepositoryInterface $customerrepository,
Order $order
)
{
$this->customerSession = $customerSession;
$this->customerrepository = $customerrepository;
$this->order = $order;
}
public function execute(MagentoFrameworkEventObserver $observer)
{
$event = $observer->getEvent();
$orderIds = $event->getOrderIds();
$order = $observer->getEvent()->getOrder();
$ordercoll = $this->order->loadByAttribute("entity_id",$orderIds[0]);
$shippingdetails = $ordercoll->getShippingAddress()->getData();
$magento_address_id = $ordercoll->getShippingAddress()->getId();
$billingdetails = $ordercoll->getBillingAddress()->getData();
$paymentdetails = $ordercoll->getPayment()->getData();
$shipmentdetails = $ordercoll->getShippingmethod();
$customerinfo = $this->customerSession->getData();
$shipping_amount = $ordercoll->getShippingAmount();
$discount_amount = $ordercoll->getDiscountAmount();
$discount_description = $ordercoll->getDiscountDescription();
$applied_rule_ids = $ordercoll->getAppliedRuleIds();
}
}
@Idham choudry,
you can add below code in to your observer to get customer information.
use MagentoCustomerApiCustomerRepositoryInterface;
use MagentoCustomerModelSession;
use MagentoSalesModelOrder;
class yourobserver implements ObserverInterface
{
protected $customerSession;
protected $customerrepository;
protected $order;
public function __construct(
Session $customerSession,
CustomerRepositoryInterface $customerrepository,
Order $order
)
{
$this->customerSession = $customerSession;
$this->customerrepository = $customerrepository;
$this->order = $order;
}
public function execute(MagentoFrameworkEventObserver $observer)
{
$event = $observer->getEvent();
$orderIds = $event->getOrderIds();
$order = $observer->getEvent()->getOrder();
$ordercoll = $this->order->loadByAttribute("entity_id",$orderIds[0]);
$shippingdetails = $ordercoll->getShippingAddress()->getData();
$magento_address_id = $ordercoll->getShippingAddress()->getId();
$billingdetails = $ordercoll->getBillingAddress()->getData();
$paymentdetails = $ordercoll->getPayment()->getData();
$shipmentdetails = $ordercoll->getShippingmethod();
$customerinfo = $this->customerSession->getData();
$shipping_amount = $ordercoll->getShippingAmount();
$discount_amount = $ordercoll->getDiscountAmount();
$discount_description = $ordercoll->getDiscountDescription();
$applied_rule_ids = $ordercoll->getAppliedRuleIds();
}
}
edited Jul 4 '17 at 10:15
answered Jul 4 '17 at 10:01
Iyappan PerumalIyappan Perumal
33118
33118
1
i want to retrieve customer information from order data not from session
– Idham Choudry
Jul 4 '17 at 10:02
Is the data you want on the order table or order_address table?
– LM_Fielding
Jul 4 '17 at 10:14
I have updated my coding to get order billing and shipping address information. you can get customer information.
– Iyappan Perumal
Jul 4 '17 at 10:17
add a comment |
1
i want to retrieve customer information from order data not from session
– Idham Choudry
Jul 4 '17 at 10:02
Is the data you want on the order table or order_address table?
– LM_Fielding
Jul 4 '17 at 10:14
I have updated my coding to get order billing and shipping address information. you can get customer information.
– Iyappan Perumal
Jul 4 '17 at 10:17
1
1
i want to retrieve customer information from order data not from session
– Idham Choudry
Jul 4 '17 at 10:02
i want to retrieve customer information from order data not from session
– Idham Choudry
Jul 4 '17 at 10:02
Is the data you want on the order table or order_address table?
– LM_Fielding
Jul 4 '17 at 10:14
Is the data you want on the order table or order_address table?
– LM_Fielding
Jul 4 '17 at 10:14
I have updated my coding to get order billing and shipping address information. you can get customer information.
– Iyappan Perumal
Jul 4 '17 at 10:17
I have updated my coding to get order billing and shipping address information. you can get customer information.
– Iyappan Perumal
Jul 4 '17 at 10:17
add a comment |
Use repository. With $order
you can do
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$customer = $objectManager->create('MagentoCustomerApiCustomerRepositoryInterface')
->getById($order->getCustomerId());
$customer
is an instance of MagentoCustomerModelDataCustomer
, just call its get() methods to access customer properties.
add a comment |
Use repository. With $order
you can do
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$customer = $objectManager->create('MagentoCustomerApiCustomerRepositoryInterface')
->getById($order->getCustomerId());
$customer
is an instance of MagentoCustomerModelDataCustomer
, just call its get() methods to access customer properties.
add a comment |
Use repository. With $order
you can do
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$customer = $objectManager->create('MagentoCustomerApiCustomerRepositoryInterface')
->getById($order->getCustomerId());
$customer
is an instance of MagentoCustomerModelDataCustomer
, just call its get() methods to access customer properties.
Use repository. With $order
you can do
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$customer = $objectManager->create('MagentoCustomerApiCustomerRepositoryInterface')
->getById($order->getCustomerId());
$customer
is an instance of MagentoCustomerModelDataCustomer
, just call its get() methods to access customer properties.
edited Nov 10 '17 at 11:08
answered Sep 29 '17 at 8:38
LucScuLucScu
1,207929
1,207929
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');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
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%2f181939%2fget-customer-information-from-order-magento-2%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');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
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');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
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');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
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
Did you try
$order->getCustomer()
?– Khoa TruongDinh
Jul 4 '17 at 10:06
You can directly access customer details like firstname,lastname,email from the order object . eg. $order->getCustomerEmail(),$order->getCustomerFirstname()
– Emipro Technologies Pvt. Ltd.
Jul 4 '17 at 10:07
@EmiproTechnologiesPvt.Ltd. thanks it works
– Idham Choudry
Jul 4 '17 at 10:17
@Idham Most welcome
– Emipro Technologies Pvt. Ltd.
Jul 4 '17 at 10:35