2

I have created a custom attribute of type customer_address and I would like to have the API to return me the value as an attribute when I call the API to receive an order.

Attribute:

private function upgradeExternalKeyAddressCustomer($customerSetup)
{
 $attributesInfo = [
 'mod_external_key' => [
 'label' => __('External Key'),
 'type' => 'varchar',
 'input' => 'text',
 'position' => 200,
 'visible' => 1,
 'required' => 0,
 'system' => 0,
 ],
 ];
 foreach ($attributesInfo as $attributeCode => $attributeParams) {
 $customerSetup->addAttribute('customer_address', $attributeCode, $attributeParams);
 }
 foreach ($attributesInfo as $attributeCode => $attributeParams) {
 $attribute = $customerSetup->getEavConfig()->getAttribute('customer_address', $attributeCode);
 $attribute->setData(
 'used_in_forms',
 ['adminhtml_customer_address', 'customer_address_edit', 'customer_register_address']
 );
 $attribute->save();
 }
}

How to do this?

asked Nov 12, 2018 at 12:01

1 Answer 1

1

try this blog it will return your custom attribute in order api response https://www.atwix.com/development/adding-custom-attribute-to-api-response-in-magento-2/

answered Nov 12, 2018 at 12:08
1
  • 1
    This tutorial is about extension attributes. How can I do that for an attribute outside of extension attributes ? Commented Jul 6, 2020 at 15:07

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.