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?

2 Answers 2

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.
4
  • 1
    will you please provide a coded example here, will help , thanks
    – amit_game
    Dec 27, 2017 at 9:48
  • please provide the code Apr 27, 2018 at 6:46
  • 1
    u guys can use this example https://github.com/saxsax1995/magento2-module-delivery-date/tree/master/SR/DeliveryDate
    – fudu
    Sep 21, 2018 at 4:08
  • @K. Maliszewski Can you please help me to save custom field in billing address on checkout page in Magento 2? Nov 20, 2018 at 13:17
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.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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