I added a custom JS validation rule for customer address tax_id field, following this instructions.

But the JS validations can be easely skiped, so how can I reproduce the frontend JS validation in my custom module PHP codes?

Thanks in advance.


M2 checkout uses web API to communicate with the backend. You can bind your custom plugins(http://devdocs.magento.com/guides/v2.2/extension-dev-guide/plugins.html) to any web API service.

For your case it should be \Magento\Checkout\Api\ShippingInformationManagementInterface::saveAddressInformation.

So, just create a plugin and put your validation there.

  • Hi, I've tried your solution, but aparently without success, I create the plugin in di.xml: <type name="\Magento\Checkout\Api\ShippingInformationManagementInterface"> <plugin sortOrder="100" name="cpfCnpjValidation" type="Experius\AddressLines\Plugin\CpfCnpjValidationPlugin"/></type>. And in plugin class, I add a logger, and nothing in logs, I think that is not entering in plugin method, beforeSaveAddressInformation, any ideia? Thanks
    – lpFranz
    Dec 26 '17 at 18:51
  • Did you clean the cache? Dec 27 '17 at 15:47

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.