0

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

0

You can use the method toArray().

\Magento\Customer\Model\Customer $customer;
$customer->toArray();
0

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);

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.