8

I have created one "Customer address" type of attribute name "Suburb", It successfully created.

It shows on Checkout, Customer create(admin) and Create New Order address(Admin) section, While It works fine with checkout as well as create customer but not working with Create new order.

Here install script:

$customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
 $customerSetup->addAttribute('customer_address', 'suburb', [
 'label' => 'Suburb',
 'input' => 'text',
 'type' => 'varchar',
 'source' => '',
 'required' => true,
 'position' => 70,
 'visible' => true,
 'system' => false,
 'is_used_in_grid' => false,
 'is_visible_in_grid' => false,
 'is_filterable_in_grid' => false,
 'is_searchable_in_grid' => false,
 'backend' => ''
 ]);
 $attribute = $customerSetup->getEavConfig()->getAttribute('customer_address', 'suburb')
 ->addData(['used_in_forms' => [
 'adminhtml_customer_address',
 'customer_address_edit',
 'customer_register_address'
 ]]);
 $attribute->save();

I tried to create new Order and fill all required data including Suburb. enter image description here

But when I tried to Submit Order It shows me error 'Suburb` is a required value. It's shown that filled value of suburb is not being saved too.

enter image description here Please help, Any suggestions would be appreciated. Thank you.

asked Sep 5, 2017 at 9:21

1 Answer 1

0

Have you applied your custom attribute to the appropriate node inside the fieldset.xml configuration? See the following file:

vendor/magento/module-sales/etc/fieldset.xml

Looking at your screenshots it seems you have added your attribute to the address object. See the 'sales_copy_order_billing_address' and 'sales_copy_order_shipping_address' fieldset nodes.

Update

I recently had to save a custom order attribute to the database when creating the order via the admin area. I found that adding the attribute to the fieldset.xml didn't work when creating an order in the admin. To save the attribute I created a plugin and an observer. See details below:

Plugin

Class: Magento\Sales\Model\AdminOrder\Create

Method: importPostData()

This saved the custom attribute to the quote object used to create the order in the quote management class.


Observer

Event: sales_model_service_quote_submit_before

This is used to add the custom attribute to the older model just before the model is saved to the DB.

Hope the above is useful for you.

Msquare
9,4627 gold badges30 silver badges71 bronze badges
answered Oct 1, 2018 at 7:25

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.