If we have commerce checkout enable for anonymous (New Customers), after submitting registration form, legal module force redirect to /legal_accept and breaks checkout process. Below are the details
1. We should add legal field for commerce checkout registration forms as well. We should alter the this form in legal.module the way we are doing registration form. As interim solution I am using hook_form_alter in custom module to add field in form with $form_id = commerce_checkout_flow_multistep_default

legal_display_fields($form['email_registration_login']['register'], $conditions, 'registration');

2. Since commerce forms follow field-set/panes, we are getting \Drupal::request()->request->get('legal_accept'); as empty in legal_user_insert and instead. As interim solution I am using below solution in custom module ( example_user_insert)

function my_module_user_insert(EntityInterface $entity) {
  $language = \Drupal::languageManager()->getCurrentLanguage();
  $post = \Drupal::request()->request->get('email_registration_login');
  $accepted = $post['register']['legal']['legal_accept'] ? TRUE : FALSE;
  if ($accepted) {
    module_load_include('module', 'legal');
    $conditions = legal_get_conditions($language->getId());
    if (empty($conditions['conditions'])) {
      return;
    }
    legal_save_accept($conditions['version'], $conditions['revision'], $conditions['language'], $entity->get('uid')
      ->getString());
  }
}

Comments

rsingh27 created an issue. See original summary.

rsingh27’s picture

Issue summary: View changes
introfini’s picture

Great workaround. Thanks!

tiburi’s picture

Hello, I'm happy to found this post.
Can you explain easier how can I fix this issue?
Is there any patch to solve this?
Thank you so much!

mrweiner’s picture

Status: Active » Needs review
StatusFileSize
new2.3 KB

Attaching a patch that brings in the workaround from the initial issue description. Initial issue report had the right idea, but instead of legal_display_fields($form['email_registration_login']['register'], $conditions, 'registration'); I needed to use legal_display_fields($form['login']['register'], $conditions, 'registration');. Patch adds a function to grab the pane ids in case additional cases exist that need to be checked.

mrweiner’s picture

Version: 8.x-1.0-rc1 » 8.x-1.x-dev
savage1974’s picture

The patch works OK! Thanks a lot!

But there is one problem with form validation - when T&C is not checked - there is no any message that the checkbox is not checked. The same goes for Additional Checkboxes.
Perhaps someone has already found a solution to this problem?

best regards,

Savage

anybody’s picture

Assigned: rsingh27 » Unassigned

Is this issue still existing with 3.x? Then the version should be changed to 3.0.x please.

anybody’s picture

Version: 8.x-1.x-dev » 3.0.x-dev
Status: Needs review » Postponed (maintainer needs more info)

Development happens in 3.x - can this still be reproduced there?