cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Attribute for Shipping/Billing Address on place order fail validation

Custom Attribute for Shipping/Billing Address on place order fail validation

Added custom attribute for billing/shipping address (county) and set as required in setup.

User logged in, no default billing / shipping addresses configured, product in cart.  Proceed to checkout displays form with custom attribute (county) is displayed.  Form completed and validated including custom attribute.  Click next.  Order screen displays shipping information that was completed in previous screen, including attribute.  Pressing "Place Order"  stops with an error that "County is a required field".  

 

If user not logged in and checks out as guest, forms are completed and place order is a success.  Also works if user is logged in and configures a default shipping/billing address.

 

Stumbling over files in module checkout searching for a place where custom attributes are  validated, have not yet been successful.  Following is a dump of the payload where it does show the custom attributes.

 

console.dir(JSON.stringify(payload));

{"cartId":"6683","billingAddress":{"countryId":"US","regionId":"44","regionCode":"NC","region":"North Carolina","street":["4086 gray rock road"],"company":"SouthernWoodcraft","telephone":"9196933389","postcode":"27544","city":"kittrell","firstname":"virgil","lastname":"long","customAttributes":[{"attribute_code":"county","value":"Granville"}],"save_in_address_book":1,"saveInAddressBook":null,"extension_attributes":{"county":"Granville"}},"paymentMethod":{"method":"purchaseorder","po_number":"11111","additional_data":null}}

2 REPLIES 2

Re: Custom Attribute for Shipping/Billing Address on place order fail validation

Hi @virgil_long 

 

You need to create custom validation for new field on checkout. You can customise restriction of field by js on checkout.
Kindly refer below link for your reference:
https://www.mageplaza.com/devdocs/add-custom-validations-before-placing-order-magento-2.html

It may help you!
Problem Solved? Please click on 'Kudos' & Accept as Solution!

Problem solved? Click Accept as Solution!

Re: Custom Attribute for Shipping/Billing Address on place order fail validation

Thanks Bhanu,

I tried your suggestion, it did not work.  Im assuming I didnt need to register js with requirejs config.  I will continue experimenting with your suggestion.

 

I am able to checkout as a guest (not signed in).  I complete the form, click next the click place order with a successful conclusion. Im also able to checkout if Im logged in and configure a default address.  The unsuccessful case is logged in and checking out as a guest with no default addresses assigned.  It apparently is doing some type of validation, it states the name of my custom field and tells me its required.

I can go back to setup and define the field as not required and it will allow me to check out. 

 

I did notice another case that if Im logged in as user, check out and ask for a new shipping address, I complete the form successfully, but when it displays,  the value of my custom field is [Object object].  I know this is using a different mechanism, the shipping popup renderer, but it is not endering the custom attribute.  I believe this is a different case but thought I would mention it.