2

There is any simple way in Magento2 to add custom field to Checkout? I have displayed my custom field in shipping address following by StackOverFlow tips and Magento docs. Unfortunally, Magento docs doesn't have info how to save this attribute to database.

I have moved my attributes from custom_attributes to extension_attributes, but values still is not saved in customer shipping address.

Can You give me tip how I should save my new field in custom attributes in shipping address in Customer details?

K. Maliszewski
  • 737
  • 5
  • 14

2 Answers2

2

I solved my problem. Extra field in Shipping Address is saved to Quote first. So if you want to save new field in custom attributes in Customer details you have to do follow steps:

  1. Extend Extension Attributes for Magento\Quote\Api\Data\AddressInterface (in Magento docs)
  2. Extend Quote table in DB about new field Create

  3. set-shipping-information-mixin.js and move attributes to extension attributes (in Magento docs)

  4. Create plugin in ShippingInformationManagement before SaveAddressInformation method. Read variable from extension attributes and save it to Quote

  5. Overwrite "populateCustomerInfo" method in "Magento\Quote\Model\CustomerManagment and read new value from Quote and save it to custom attributes in customer object.
K. Maliszewski
  • 737
  • 5
  • 14
0

@K.Maliszewski, can you share your code please? I am having trouble getting the custom attributes in the ShippingInformationManagement plugin. No matter what I do it's always empty. Thanks.

  • You can take a look at my instructions in this post https://magento.stackexchange.com/questions/363920/extension-attributes-not-storing-data – Tu Van Jan 29 '23 at 22:11