I have this Data Object value.
Magento\Customer\Model\Data\AttributeMetadata Object
(
[_data:protected] => Array
(
[frontend_input] => boolean
[input_filter] =>
[store_label] => Verified Buyer
[validation_rules] => Array
(
)
[multiline_count] => 0
[visible] => 1
[required] =>
[data_model] =>
[options] => Array
(
)
[frontend_class] =>
[user_defined] => 1
[sort_order] => 90
[frontend_label] => Verified Buyer
[note] =>
[system] =>
[backend_type] => int
[is_used_in_grid] =>
[is_visible_in_grid] =>
[is_filterable_in_grid] =>
[is_searchable_in_grid] =>
[attribute_code] => verified_buyer
)
)
I converted this to
$array = (array) $customAttr;
But still I am reciving the object
Array
(
[*_data] => Array
(
[frontend_input] => boolean
[input_filter] =>
[store_label] => Verified Buyer
[validation_rules] => Array
(
)
[multiline_count] => 0
[visible] => 1
[required] =>
[data_model] =>
[options] => Array
(
)
[frontend_class] =>
[user_defined] => 1
[sort_order] => 90
[frontend_label] => Verified Buyer
[note] =>
[system] =>
[backend_type] => int
[is_used_in_grid] =>
[is_visible_in_grid] =>
[is_filterable_in_grid] =>
[is_searchable_in_grid] =>
[attribute_code] => verified_buyer
)
)
I am expecting output like
Array
(
[frontend_input] => boolean
[input_filter] =>
[store_label] => Verified Buyer
[validation_rules] => Array
(
)
[multiline_count] => 0
[visible] => 1
[required] =>
[data_model] =>
[options] => Array
(
)
[frontend_class] =>
[user_defined] => 1
[sort_order] => 90
[frontend_label] => Verified Buyer
[note] =>
[system] =>
[backend_type] => int
[is_used_in_grid] =>
[is_visible_in_grid] =>
[is_filterable_in_grid] =>
[is_searchable_in_grid] =>
[attribute_code] => verified_buyer
)
Above all is Magento Customer custom attributes data.
Note : I am using REST API
asked Jan 11, 2019 at 10:02
Aditya Shah
7,6813 gold badges41 silver badges79 bronze badges
3 Answers 3
You can use the method toArray().
\Magento\Customer\Model\Customer $customer;
$customer->toArray();
answered Jan 11, 2019 at 11:01
Gabriel Fernandes
1822 silver badges11 bronze badges
-
Nope, Not working.Aditya Shah– Aditya Shah2019年01月11日 11:52:12 +00:00Commented Jan 11, 2019 at 11:52
-
Have an error log?Gabriel Fernandes– Gabriel Fernandes2019年01月11日 12:41:11 +00:00Commented Jan 11, 2019 at 12:41
-
Thanks for the efforts +1Aditya Shah– Aditya Shah2019年03月15日 10:44:28 +00:00Commented Mar 15, 2019 at 10:44
The simple way you can do it via php function json_encode and json_decode.
$object = 'your_object_variable'
$myArray = json_decode(json_encode($object), true);
print_r($myarray);
-
Does it works ?Franck Garnier– Franck Garnier2019年01月14日 11:22:42 +00:00Commented Jan 14, 2019 at 11:22
Try like this one:
$data = $this->dataObjectConverter->toFlatArray($Customer, [], \Magento\Customer\Model\Customer::class);
answered Jul 19, 2019 at 12:57
Chirag Parmar
7298 silver badges20 bronze badges
Explore related questions
See similar questions with these tags.
default