function _webform_submit_productfield in Commerce Webform 7
Same name and namespace in other branches
- 8 productfield.inc \_webform_submit_productfield()
- 7.2 productfield.inc \_webform_submit_productfield()
Implements _webform_submit_component(). This executes when the webform is submitted by the user. Convert FAPI 0/1 values into something saveable.
File
- ./
productfield.inc, line 392
Code
function _webform_submit_productfield($component, $value) {
$return = array();
$multiple = $component['extra']['multiple'];
$choose_quantity = !empty($component['extra']['choose_quantity']);
if ($multiple && $choose_quantity) {
foreach ($value as $product_id => $quantity) {
if ($quantity > 0) {
$details = array(
'product_id' => $product_id,
'quantity' => $quantity,
'order_id' => FALSE,
'line_item_id' => FALSE,
'paid' => FALSE,
);
$return[] = json_encode($details);
}
}
}
else {
if (is_array($value[0])) {
foreach ($value[0] as $id => $product_id) {
$details = array(
'product_id' => $product_id,
'quantity' => 1,
'order_id' => FALSE,
'line_item_id' => FALSE,
'paid' => FALSE,
);
$return[] = json_encode($details);
}
}
else {
$details = array(
'product_id' => $value[0],
'quantity' => empty($value[0]) ? '0' : $value[1],
'order_id' => FALSE,
'line_item_id' => FALSE,
'paid' => FALSE,
);
$return[] = json_encode($details);
}
}
return $return;
}