Magento2 print customer full data array
How to print customer array full data.
public function __construct(
MagentoCustomerModelCustomer $customermodel,
MagentoCustomerModelAddress $addressmodel,
MagentoCustomerApiCustomerRepositoryInterface $customer
)
{
$this->_customer = $customer;
$this->_address = $addressmodel;
$this->_customermodel = $customermodel;
}
$customerData = $this->_customer->getById($customerId);
How to print this $customerData
?
magento2 customer
bumped to the homepage by Community♦ 5 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
|
show 5 more comments
How to print customer array full data.
public function __construct(
MagentoCustomerModelCustomer $customermodel,
MagentoCustomerModelAddress $addressmodel,
MagentoCustomerApiCustomerRepositoryInterface $customer
)
{
$this->_customer = $customer;
$this->_address = $addressmodel;
$this->_customermodel = $customermodel;
}
$customerData = $this->_customer->getById($customerId);
How to print this $customerData
?
magento2 customer
bumped to the homepage by Community♦ 5 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
check like that print_r($customerData->getData());
– Emipro Technologies Pvt. Ltd.
Jul 10 '17 at 13:32
Did you try with $customerData->getData()?
– Rakesh Jesadiya
Jul 10 '17 at 13:34
Hi Emipro , now i am getting follwing error: "code": 500, "message": "Fatal Error: 'Call to undefined method Magento\Customer\Model\Data\Customer::getData()'
– user3374995
Jul 10 '17 at 13:34
$customerData = $this->_customer->getById($customerId); foreach($customerData as $customer){ print_r($customer->getData()); } try with this
– Rakesh Jesadiya
Jul 10 '17 at 13:35
Hi Rakesh, it displaying Blank. if we print $customerData ->getEmail()..we are getting emailid.
– user3374995
Jul 10 '17 at 13:38
|
show 5 more comments
How to print customer array full data.
public function __construct(
MagentoCustomerModelCustomer $customermodel,
MagentoCustomerModelAddress $addressmodel,
MagentoCustomerApiCustomerRepositoryInterface $customer
)
{
$this->_customer = $customer;
$this->_address = $addressmodel;
$this->_customermodel = $customermodel;
}
$customerData = $this->_customer->getById($customerId);
How to print this $customerData
?
magento2 customer
How to print customer array full data.
public function __construct(
MagentoCustomerModelCustomer $customermodel,
MagentoCustomerModelAddress $addressmodel,
MagentoCustomerApiCustomerRepositoryInterface $customer
)
{
$this->_customer = $customer;
$this->_address = $addressmodel;
$this->_customermodel = $customermodel;
}
$customerData = $this->_customer->getById($customerId);
How to print this $customerData
?
magento2 customer
magento2 customer
edited Jul 10 '17 at 14:47
Kishan Patadia
3,5781923
3,5781923
asked Jul 10 '17 at 13:28
user3374995user3374995
668
668
bumped to the homepage by Community♦ 5 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 5 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
check like that print_r($customerData->getData());
– Emipro Technologies Pvt. Ltd.
Jul 10 '17 at 13:32
Did you try with $customerData->getData()?
– Rakesh Jesadiya
Jul 10 '17 at 13:34
Hi Emipro , now i am getting follwing error: "code": 500, "message": "Fatal Error: 'Call to undefined method Magento\Customer\Model\Data\Customer::getData()'
– user3374995
Jul 10 '17 at 13:34
$customerData = $this->_customer->getById($customerId); foreach($customerData as $customer){ print_r($customer->getData()); } try with this
– Rakesh Jesadiya
Jul 10 '17 at 13:35
Hi Rakesh, it displaying Blank. if we print $customerData ->getEmail()..we are getting emailid.
– user3374995
Jul 10 '17 at 13:38
|
show 5 more comments
check like that print_r($customerData->getData());
– Emipro Technologies Pvt. Ltd.
Jul 10 '17 at 13:32
Did you try with $customerData->getData()?
– Rakesh Jesadiya
Jul 10 '17 at 13:34
Hi Emipro , now i am getting follwing error: "code": 500, "message": "Fatal Error: 'Call to undefined method Magento\Customer\Model\Data\Customer::getData()'
– user3374995
Jul 10 '17 at 13:34
$customerData = $this->_customer->getById($customerId); foreach($customerData as $customer){ print_r($customer->getData()); } try with this
– Rakesh Jesadiya
Jul 10 '17 at 13:35
Hi Rakesh, it displaying Blank. if we print $customerData ->getEmail()..we are getting emailid.
– user3374995
Jul 10 '17 at 13:38
check like that print_r($customerData->getData());
– Emipro Technologies Pvt. Ltd.
Jul 10 '17 at 13:32
check like that print_r($customerData->getData());
– Emipro Technologies Pvt. Ltd.
Jul 10 '17 at 13:32
Did you try with $customerData->getData()?
– Rakesh Jesadiya
Jul 10 '17 at 13:34
Did you try with $customerData->getData()?
– Rakesh Jesadiya
Jul 10 '17 at 13:34
Hi Emipro , now i am getting follwing error: "code": 500, "message": "Fatal Error: 'Call to undefined method Magento\Customer\Model\Data\Customer::getData()'
– user3374995
Jul 10 '17 at 13:34
Hi Emipro , now i am getting follwing error: "code": 500, "message": "Fatal Error: 'Call to undefined method Magento\Customer\Model\Data\Customer::getData()'
– user3374995
Jul 10 '17 at 13:34
$customerData = $this->_customer->getById($customerId); foreach($customerData as $customer){ print_r($customer->getData()); } try with this
– Rakesh Jesadiya
Jul 10 '17 at 13:35
$customerData = $this->_customer->getById($customerId); foreach($customerData as $customer){ print_r($customer->getData()); } try with this
– Rakesh Jesadiya
Jul 10 '17 at 13:35
Hi Rakesh, it displaying Blank. if we print $customerData ->getEmail()..we are getting emailid.
– user3374995
Jul 10 '17 at 13:38
Hi Rakesh, it displaying Blank. if we print $customerData ->getEmail()..we are getting emailid.
– user3374995
Jul 10 '17 at 13:38
|
show 5 more comments
1 Answer
1
active
oldest
votes
In Magento 1, any class which extended from Varien_Object
had access to a method getData
which would return the data property of the class as an array.
In Magento 2, there is no Varien_Object
and no getData
method. Data Models still have a data property, however, but it is of protected visibility and there is no accessor method for the whole array.
The only way to get at this property, then is to use the __toArray
method, in order to tell Magento to create an array representation of the data property.
This method is defined in MagentoFrameworkApiAbstractSimpleObject
, so you will only be able to use it if your model extends from that class.
<?php
// Inject your customer dependency in the usual way
/** @var $customer MagentoCustomerApiDataCustomerInterface */
$customerData = $customer->__toArray();
var_dump($customerData);
// Outputs something like:
array(22) {
'website_id' =>
string(1) "1"
'email' =>
string(34) "me@example.com"
'group_id' =>
string(2) "17"
'store_id' =>
string(1) "1"
'created_at' =>
string(19) "2018-04-06 15:52:34"
'updated_at' =>
string(19) "2018-06-26 13:42:09"
'disable_auto_group_change' =>
string(1) "0"
'created_in' =>
string(18) "Default Store View"
...Output truncated
A word of warning before copy-pasting the above, however: The code snippet above depends on whether your Customer Data Model also extends from MagentoFrameworkApiAbstractSimpleObject
.
The default, as defined in vendor/magento/module-customer/etc/di.xml
specifies MagentoCustomerModelDataCustomer
as the concrete implementation, which does include MagentoFrameworkApiAbstractSimpleObject
in it's dependency chain, which is why the code snippet above works.
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%2f182938%2fmagento2-print-customer-full-data-array%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
In Magento 1, any class which extended from Varien_Object
had access to a method getData
which would return the data property of the class as an array.
In Magento 2, there is no Varien_Object
and no getData
method. Data Models still have a data property, however, but it is of protected visibility and there is no accessor method for the whole array.
The only way to get at this property, then is to use the __toArray
method, in order to tell Magento to create an array representation of the data property.
This method is defined in MagentoFrameworkApiAbstractSimpleObject
, so you will only be able to use it if your model extends from that class.
<?php
// Inject your customer dependency in the usual way
/** @var $customer MagentoCustomerApiDataCustomerInterface */
$customerData = $customer->__toArray();
var_dump($customerData);
// Outputs something like:
array(22) {
'website_id' =>
string(1) "1"
'email' =>
string(34) "me@example.com"
'group_id' =>
string(2) "17"
'store_id' =>
string(1) "1"
'created_at' =>
string(19) "2018-04-06 15:52:34"
'updated_at' =>
string(19) "2018-06-26 13:42:09"
'disable_auto_group_change' =>
string(1) "0"
'created_in' =>
string(18) "Default Store View"
...Output truncated
A word of warning before copy-pasting the above, however: The code snippet above depends on whether your Customer Data Model also extends from MagentoFrameworkApiAbstractSimpleObject
.
The default, as defined in vendor/magento/module-customer/etc/di.xml
specifies MagentoCustomerModelDataCustomer
as the concrete implementation, which does include MagentoFrameworkApiAbstractSimpleObject
in it's dependency chain, which is why the code snippet above works.
add a comment |
In Magento 1, any class which extended from Varien_Object
had access to a method getData
which would return the data property of the class as an array.
In Magento 2, there is no Varien_Object
and no getData
method. Data Models still have a data property, however, but it is of protected visibility and there is no accessor method for the whole array.
The only way to get at this property, then is to use the __toArray
method, in order to tell Magento to create an array representation of the data property.
This method is defined in MagentoFrameworkApiAbstractSimpleObject
, so you will only be able to use it if your model extends from that class.
<?php
// Inject your customer dependency in the usual way
/** @var $customer MagentoCustomerApiDataCustomerInterface */
$customerData = $customer->__toArray();
var_dump($customerData);
// Outputs something like:
array(22) {
'website_id' =>
string(1) "1"
'email' =>
string(34) "me@example.com"
'group_id' =>
string(2) "17"
'store_id' =>
string(1) "1"
'created_at' =>
string(19) "2018-04-06 15:52:34"
'updated_at' =>
string(19) "2018-06-26 13:42:09"
'disable_auto_group_change' =>
string(1) "0"
'created_in' =>
string(18) "Default Store View"
...Output truncated
A word of warning before copy-pasting the above, however: The code snippet above depends on whether your Customer Data Model also extends from MagentoFrameworkApiAbstractSimpleObject
.
The default, as defined in vendor/magento/module-customer/etc/di.xml
specifies MagentoCustomerModelDataCustomer
as the concrete implementation, which does include MagentoFrameworkApiAbstractSimpleObject
in it's dependency chain, which is why the code snippet above works.
add a comment |
In Magento 1, any class which extended from Varien_Object
had access to a method getData
which would return the data property of the class as an array.
In Magento 2, there is no Varien_Object
and no getData
method. Data Models still have a data property, however, but it is of protected visibility and there is no accessor method for the whole array.
The only way to get at this property, then is to use the __toArray
method, in order to tell Magento to create an array representation of the data property.
This method is defined in MagentoFrameworkApiAbstractSimpleObject
, so you will only be able to use it if your model extends from that class.
<?php
// Inject your customer dependency in the usual way
/** @var $customer MagentoCustomerApiDataCustomerInterface */
$customerData = $customer->__toArray();
var_dump($customerData);
// Outputs something like:
array(22) {
'website_id' =>
string(1) "1"
'email' =>
string(34) "me@example.com"
'group_id' =>
string(2) "17"
'store_id' =>
string(1) "1"
'created_at' =>
string(19) "2018-04-06 15:52:34"
'updated_at' =>
string(19) "2018-06-26 13:42:09"
'disable_auto_group_change' =>
string(1) "0"
'created_in' =>
string(18) "Default Store View"
...Output truncated
A word of warning before copy-pasting the above, however: The code snippet above depends on whether your Customer Data Model also extends from MagentoFrameworkApiAbstractSimpleObject
.
The default, as defined in vendor/magento/module-customer/etc/di.xml
specifies MagentoCustomerModelDataCustomer
as the concrete implementation, which does include MagentoFrameworkApiAbstractSimpleObject
in it's dependency chain, which is why the code snippet above works.
In Magento 1, any class which extended from Varien_Object
had access to a method getData
which would return the data property of the class as an array.
In Magento 2, there is no Varien_Object
and no getData
method. Data Models still have a data property, however, but it is of protected visibility and there is no accessor method for the whole array.
The only way to get at this property, then is to use the __toArray
method, in order to tell Magento to create an array representation of the data property.
This method is defined in MagentoFrameworkApiAbstractSimpleObject
, so you will only be able to use it if your model extends from that class.
<?php
// Inject your customer dependency in the usual way
/** @var $customer MagentoCustomerApiDataCustomerInterface */
$customerData = $customer->__toArray();
var_dump($customerData);
// Outputs something like:
array(22) {
'website_id' =>
string(1) "1"
'email' =>
string(34) "me@example.com"
'group_id' =>
string(2) "17"
'store_id' =>
string(1) "1"
'created_at' =>
string(19) "2018-04-06 15:52:34"
'updated_at' =>
string(19) "2018-06-26 13:42:09"
'disable_auto_group_change' =>
string(1) "0"
'created_in' =>
string(18) "Default Store View"
...Output truncated
A word of warning before copy-pasting the above, however: The code snippet above depends on whether your Customer Data Model also extends from MagentoFrameworkApiAbstractSimpleObject
.
The default, as defined in vendor/magento/module-customer/etc/di.xml
specifies MagentoCustomerModelDataCustomer
as the concrete implementation, which does include MagentoFrameworkApiAbstractSimpleObject
in it's dependency chain, which is why the code snippet above works.
answered Jun 28 '18 at 8:39
ProcessEightProcessEight
6711416
6711416
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%2f182938%2fmagento2-print-customer-full-data-array%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
check like that print_r($customerData->getData());
– Emipro Technologies Pvt. Ltd.
Jul 10 '17 at 13:32
Did you try with $customerData->getData()?
– Rakesh Jesadiya
Jul 10 '17 at 13:34
Hi Emipro , now i am getting follwing error: "code": 500, "message": "Fatal Error: 'Call to undefined method Magento\Customer\Model\Data\Customer::getData()'
– user3374995
Jul 10 '17 at 13:34
$customerData = $this->_customer->getById($customerId); foreach($customerData as $customer){ print_r($customer->getData()); } try with this
– Rakesh Jesadiya
Jul 10 '17 at 13:35
Hi Rakesh, it displaying Blank. if we print $customerData ->getEmail()..we are getting emailid.
– user3374995
Jul 10 '17 at 13:38