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)
- Set up a custom pane with Commerce Fieldgroup Panes, disabled by default
- Add a rule with Commerce Rules Extra, which enables the pane if qty > 1 for specific product type
- I gave up with
hook_commerce_checkout_page_info_alter(&$checkout_panes)
, never had even a dsm(1,2,3) returning sthing !
- 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!