Skip to main content
Tweeted twitter.com/#!/StackDrupal/status/498096822041448448
Notice removed Draw attention by Kojo
Bounty Ended with Andy's answer chosen by Kojo
edited body
Source Link
Kojo
  • 3.5k
  • 4
  • 33
  • 62
  1. Set up a custom pane with Commerce Fieldgroup Panes, disabled by default
  2. Add a rule with Commerce Rules Extra, which enables the pane if qty > 1 for specific product type
  3. Then with MYMODULE_form_commerce_checkout_form_checkout_alterMYMODULE_form_FORM_ID_alter, I tried 2 different ways to add the relevant fields :

At this pointThe pane is duplicated fine, but the fields of duplicated panepanes are not saved, nor displayed at next step. Maybe because I have to tell the system these ARE checkout panes, + subsequent callbacks (as per incheckout_pane_example module) ?

If so, I don't find how to declare these dynamicthe added panes are checkout paneones inside thethat loop  .

  1. Set up a custom pane with Commerce Fieldgroup Panes, disabled by default
  2. Add a rule with Commerce Rules Extra, which enables the pane if qty > 1 for specific product type
  3. Then with MYMODULE_form_commerce_checkout_form_checkout_alter, I tried 2 different ways to add the relevant fields :

At this point the fields of duplicated pane are not saved, nor displayed at next step. Maybe because I have to tell the system these ARE checkout panes, + subsequent callbacks (as per checkout_pane_example module) ?

If so, I don't find how to declare these dynamic checkout pane inside the loop  .

  1. Set up a custom pane with Commerce Fieldgroup Panes, disabled by default
  2. Add a rule with Commerce Rules Extra, which enables the pane if qty > 1 for specific product type
  3. Then with MYMODULE_form_FORM_ID_alter, I tried 2 different ways to add the relevant fields :

The pane is duplicated fine, but the fields of duplicated panes are not saved, nor displayed at next step. Maybe because I have to tell the system these ARE checkout panes, + subsequent callbacks (as incheckout_pane_example module) ?

If so, I don't find how to declare the added panes are checkout ones inside that loop.

deleted 109 characters in body
Source Link
Kojo
  • 3.5k
  • 4
  • 33
  • 62
  • Customers book travels
  • For the sake of argument, let’s say they2 couples of lovers book a week in Venice for two lovers : they will add 2 Venice weeks4 "Venice trip" to the cart
  • During checkout, I'll collectI collect usual customer data, plus additional information (name, passport, birthday…) for the 2ndeach other participant in a dynamic custom pane
  • Let’s say now 4 friends book a week in NY: during checkout, I’ll have to display the additional custom pane three times, once for each participant (except user).
  1. Set up a custom pane with Commerce Fieldgroup Panes, disabled by default
  2. Add a rule with Commerce Rules Extra, which enables the pane if qty > 1 for specific product type
  3. Then with MYMODULE_form_commerce_checkout_form_checkout_alter, I tried 2 different ways. to add the relevant fields :

First one, : duplicate the whole custom pane into the checkout page :

Another try is toSecond one : duplicate each field inof the custom pane inside the checkout pane itself :

  • Customers book travels
  • For the sake of argument, let’s say they book a week in Venice for two lovers : they will add 2 Venice weeks to the cart
  • During checkout, I'll collect usual customer data, plus additional information (name, passport, birthday…) for the 2nd participant in a custom pane
  • Let’s say now 4 friends book a week in NY: during checkout, I’ll have to display the additional custom pane three times, once for each participant (except user)
  1. Set up a custom pane with Commerce Fieldgroup Panes, disabled by default
  2. Add a rule with Commerce Rules Extra, which enables the pane if qty > 1 for specific product type
  3. Then with MYMODULE_form_commerce_checkout_form_checkout_alter, I tried 2 different ways.

First one, duplicate the whole pane into the checkout page :

Another try is to duplicate each field in the custom checkout pane :

  • Customers book travels
  • For the sake of argument, let’s say 2 couples of lovers book a week in Venice : they will add 4 "Venice trip" to the cart
  • During checkout, I collect usual customer data, plus additional information (name, passport, birthday…) for each other participant in a dynamic custom pane.
  1. Set up a custom pane with Commerce Fieldgroup Panes, disabled by default
  2. Add a rule with Commerce Rules Extra, which enables the pane if qty > 1 for specific product type
  3. Then with MYMODULE_form_commerce_checkout_form_checkout_alter, I tried 2 different ways to add the relevant fields :

First one: duplicate the whole custom pane into the checkout page :

Second one : duplicate each field of the custom pane inside the checkout pane itself :

Notice added Draw attention by Kojo
Bounty Started worth 50 reputation by Kojo
improved formatting and question clarity
Source Link
Kojo
  • 3.5k
  • 4
  • 33
  • 62

In thea checkout process, I need to collect additional data depending on the quantity in the cart.

  • The customersCustomers book travels
  • For the sake of argument, let’s say they book a week in Venice for two lovers : they will add 2 Venice weeks to the cart
  • InDuring checkout, II'll collect usual customer data ; I also have to collect, plus additional information (name, passport, birthday…) for the 2nd participant, in a custom pane
  • Let’s say now 4 friends book a week in NY: during checkout, I’ll have to display the additional custom pane three times, once for each participant (except user)
  1. Set up a custom pane with Commerce Fieldgroup Panes, disabled by default
  2. Add a rule with Commerce Rules Extra, which enables the pane if qty > 1 for specific product type
  3. I gave up with hook_commerce_checkout_page_info_alter(&$checkout_panes), never had even a dsm(1,2,3) returning sthing !
  4. Then with MYMODULE_form_commerce_checkout_form_checkout_alter:, I tried 2 different ways.
function vts_commerce_form_commerce_checkout_form_checkout_alter(&$form, &$form_state, $form_id) {
  
  //load line item$order from= $form_state$form_state['build_info']['args'][0];
  $order//load =line $form_state['build_info']['args'][0];item
  $line_item = commerce_line_item_load($order->commerce_line_items['und'][0]['line_item_id']);
  //get quantity
  $qty = round($line_item->quantity);
  
  //duplicate the pane for each participant (minus the customer user) 
  for($n=1; $n<$qty; $n++) {
    $form['commerce_fieldgroup_pane__group_pax_sup_'.$n] = array_merge(array(), $form['commerce_fieldgroup_pane__group_pax_sup']);
  }
}

At this point the fields of duplicated pane are not saved, nor displayed at next step. Maybe because I have to tell the system these ARE checkout panes, and write callbacks+ subsequent callbacks (as per checkout_pane_example module) ? 

If so, I'm blocking onI don't find how to declare these dynamic checkout pane inside athe loop .

function vts_commerce_form_commerce_checkout_form_checkout_alter(&$form, &$form_state, $form_id) {
 
  $order = $form_state['build_info']['args'][0];
  //load line item
  $line_item = commerce_line_item_load($order->commerce_line_items['und'][0]['line_item_id']);
  //get quantity
  $qty = round($line_item->quantity);

  //loopduplicate the pane for each participant (minus the customer user) 
  for($n = 0;1; $n<$qty-3;$n<$qty; $n++) {
    
    foreach ($form['commerce_fieldgroup_pane__group_pax_sup'] as $key => $value) {
    
      //searching fields into the fieldgroup array
      if(substr($key, 0, 5) == 'field') {
        
        //we duplicate the field
        $form['commerce_fieldgroup_pane__group_pax_sup'][$key.'_'.$n] = array_merge(array(), $form['commerce_fieldgroup_pane__group_pax_sup'][$key]);
        //rename field to have it unique
        $form['commerce_fieldgroup_pane__group_pax_sup'][$key.'_'.$n]['und'][0]['#field_name'] = $form['commerce_fieldgroup_pane__group_pax_sup'][$key.'_'.$n]['und'][0]['#field_name'].'_'.$n;
        //add it to the fieldgroup : NOT SURE WHICH IS THE RIGHT ONE OR IF I MUST LEAVE ALL
        $group_pax_sup = $form['commerce_fieldgroup_pane__group_pax_sup']['#groups']['group_pax_sup'];
        $group_pax_sup->children[] = $key.'_'.$n;  
        $form['commerce_fieldgroup_pane__group_pax_sup']['#group_children'][$key.'_'.$n] = 'group_pax_sup' ;
      }
    }
  }

This is adding the fields correctly (except order), but then same result : both tries don't saveagain nothing is saved or display anything after the checkout form page (review, etc...)displayed in next steps. Here it seems that I don't manage to add the fields to the fieldgroup correctly?

How could I achieve this ? Thank you so much!

In the checkout process, I need to collect additional data depending on the quantity in the cart.

  • The customers book travels
  • For the sake of argument, let’s say they book a week in Venice for two lovers : they will add 2 Venice weeks to the cart
  • In checkout, I collect usual customer data ; I also have to collect additional information (name, passport, birthday…) for the 2nd participant, in a custom pane
  • Let’s say now 4 friends book a week in NY: during checkout, I’ll have to display the additional custom pane three times, once for each participant (except user)
  1. Set up a custom pane with Commerce Fieldgroup Panes, disabled by default
  2. Add a rule with Commerce Rules Extra, which enables the pane if qty > 1 for specific product type
  3. I gave up with hook_commerce_checkout_page_info_alter(&$checkout_panes), never had even a dsm(1,2,3) returning sthing !
  4. Then with MYMODULE_form_commerce_checkout_form_checkout_alter: I tried 2 ways.
function vts_commerce_form_commerce_checkout_form_checkout_alter(&$form, &$form_state, $form_id) {
  
  //load line item from $form_state
  $order = $form_state['build_info']['args'][0];
  $line_item = commerce_line_item_load($order->commerce_line_items['und'][0]['line_item_id']);
  //get quantity
  $qty = round($line_item->quantity);
  
  //duplicate the pane for each participant (minus the customer user) 
  for($n=1; $n<$qty; $n++) {
    $form['commerce_fieldgroup_pane__group_pax_sup_'.$n] = array_merge(array(), $form['commerce_fieldgroup_pane__group_pax_sup']);
  }
}

At this point the fields of duplicated pane are not saved, nor displayed at next step. Maybe because I have to tell the system these ARE checkout panes, and write callbacks (as per checkout_pane_example module) ? If so, I'm blocking on how to declare these dynamic checkout pane inside a loop .

function vts_commerce_form_commerce_checkout_form_checkout_alter(&$form, &$form_state, $form_id) {
 
  $order = $form_state['build_info']['args'][0];
  //load line item
  $line_item = commerce_line_item_load($order->commerce_line_items['und'][0]['line_item_id']);
  //get quantity
  $qty = round($line_item->quantity);

  //loop for each participant
  for($n = 0; $n<$qty-3; $n++) {
    
    foreach ($form['commerce_fieldgroup_pane__group_pax_sup'] as $key => $value) {
    
      //searching fields into the fieldgroup array
      if(substr($key, 0, 5) == 'field') {
        
        //we duplicate the field
        $form['commerce_fieldgroup_pane__group_pax_sup'][$key.'_'.$n] = array_merge(array(), $form['commerce_fieldgroup_pane__group_pax_sup'][$key]);
        //rename field to have it unique
        $form['commerce_fieldgroup_pane__group_pax_sup'][$key.'_'.$n]['und'][0]['#field_name'] = $form['commerce_fieldgroup_pane__group_pax_sup'][$key.'_'.$n]['und'][0]['#field_name'].'_'.$n;
        //add it to the fieldgroup : NOT SURE WHICH IS THE RIGHT ONE OR IF I MUST LEAVE ALL
        $group_pax_sup = $form['commerce_fieldgroup_pane__group_pax_sup']['#groups']['group_pax_sup'];
        $group_pax_sup->children[] = $key.'_'.$n;  
        $form['commerce_fieldgroup_pane__group_pax_sup']['#group_children'][$key.'_'.$n] = 'group_pax_sup' ;
      }
    }
  }

This is adding the fields correctly (except order), but then same result : both tries don't save or display anything after the checkout form page (review, etc...).

How could I achieve this ? Thank you !

In a checkout process, I need to collect additional data depending on the quantity in the cart.

  • Customers book travels
  • For the sake of argument, let’s say they book a week in Venice for two lovers : they will add 2 Venice weeks to the cart
  • During checkout, I'll collect usual customer data, plus additional information (name, passport, birthday…) for the 2nd participant in a custom pane
  • Let’s say now 4 friends book a week in NY: during checkout, I’ll have to display the additional custom pane three times, once for each participant (except user)
  1. Set up a custom pane with Commerce Fieldgroup Panes, disabled by default
  2. Add a rule with Commerce Rules Extra, which enables the pane if qty > 1 for specific product type
  3. Then with MYMODULE_form_commerce_checkout_form_checkout_alter, I tried 2 different ways.
function vts_commerce_form_commerce_checkout_form_checkout_alter(&$form, &$form_state, $form_id) {
  
  $order = $form_state['build_info']['args'][0];
  //load line item
  $line_item = commerce_line_item_load($order->commerce_line_items['und'][0]['line_item_id']);
  //get quantity
  $qty = round($line_item->quantity);
  
  //duplicate the pane for each participant (minus the customer user) 
  for($n=1; $n<$qty; $n++) {
    $form['commerce_fieldgroup_pane__group_pax_sup_'.$n] = array_merge(array(), $form['commerce_fieldgroup_pane__group_pax_sup']);
  }
}

At this point the fields of duplicated pane are not saved, nor displayed at next step. Maybe because I have to tell the system these ARE checkout panes, + subsequent callbacks (as per checkout_pane_example module) ? 

If so, I don't find how to declare these dynamic checkout pane inside the loop .

function vts_commerce_form_commerce_checkout_form_checkout_alter(&$form, &$form_state, $form_id) {
 
  $order = $form_state['build_info']['args'][0];
  //load line item
  $line_item = commerce_line_item_load($order->commerce_line_items['und'][0]['line_item_id']);
  //get quantity
  $qty = round($line_item->quantity);

  //duplicate the pane for each participant (minus the customer user) 
  for($n = 1; $n<$qty; $n++) {
    
    foreach ($form['commerce_fieldgroup_pane__group_pax_sup'] as $key => $value) {
    
      //searching fields into the fieldgroup array
      if(substr($key, 0, 5) == 'field') {
        
        //we duplicate the field
        $form['commerce_fieldgroup_pane__group_pax_sup'][$key.'_'.$n] = array_merge(array(), $form['commerce_fieldgroup_pane__group_pax_sup'][$key]);
        //rename field to have it unique
        $form['commerce_fieldgroup_pane__group_pax_sup'][$key.'_'.$n]['und'][0]['#field_name'] = $form['commerce_fieldgroup_pane__group_pax_sup'][$key.'_'.$n]['und'][0]['#field_name'].'_'.$n;
        //add it to the fieldgroup : NOT SURE WHICH IS THE RIGHT ONE OR IF I MUST LEAVE ALL
        $group_pax_sup = $form['commerce_fieldgroup_pane__group_pax_sup']['#groups']['group_pax_sup'];
        $group_pax_sup->children[] = $key.'_'.$n;  
        $form['commerce_fieldgroup_pane__group_pax_sup']['#group_children'][$key.'_'.$n] = 'group_pax_sup' ;
      }
    }
  }

This is adding the fields correctly, but again nothing is saved or displayed in next steps. Here it seems that I don't manage to add the fields to the fieldgroup correctly?

How could I achieve this ? Thank you so much!

added 26 characters in body
Source Link
Kojo
  • 3.5k
  • 4
  • 33
  • 62
Loading
added code
Source Link
Kojo
  • 3.5k
  • 4
  • 33
  • 62
Loading
edit : added search progress
Source Link
Kojo
  • 3.5k
  • 4
  • 33
  • 62
Loading
edit : added search progress
Source Link
Kojo
  • 3.5k
  • 4
  • 33
  • 62
Loading
edit : added search progress
Source Link
Kojo
  • 3.5k
  • 4
  • 33
  • 62
Loading
Source Link
Kojo
  • 3.5k
  • 4
  • 33
  • 62
Loading