function commerce_webform_update_webform_submission_productfield in Commerce Webform 7
Same name and namespace in other branches
- 8 commerce_webform.module \commerce_webform_update_webform_submission_productfield()
- 7.2 commerce_webform.module \commerce_webform_update_webform_submission_productfield()
Update the details stored on a webform submission product field.
Parameters
obj $webform_submission: The webform submission
int $order_id: The order id which paid for the order.
int $line_item_id: The line item id the product was purchased on
int $product_id: The product id which has been paid for.
int $quantity: The number purchased.
boolean $paid: TRUE if the item has now been paid for, FALSE if not yet.
3 calls to commerce_webform_update_webform_submission_productfield()
- commerce_webform_mark_paid in ./
commerce_webform.rules.inc - Rules action. Mark commerce webform submission as paid.
- commerce_webform_order_update in ./
commerce_webform.rules.inc - Rules actions. Update an order from a commerce webform update.
- _commerce_webform_create_order_line_items in ./
commerce_webform.rules.inc - Helper function to create new line items from the webform submission. Used by webform creation and webform update rules.
File
- ./
commerce_webform.module, line 328 - Commerce Webform module file
Code
function commerce_webform_update_webform_submission_productfield($webform_submission, $order_id, $line_item_id, $product_id, $quantity, $paid) {
$node = node_load($webform_submission->nid);
$components = $node->webform['components'];
// Loop through all possible webform fields looking for
// productfields.
foreach ($components as $key => $component) {
if ($component['type'] == 'productfield') {
// Loop through the product options on the product field
// looking for the purchased product.
foreach ($component['extra']['items'] as $product_id_option => $details) {
if ($product_id_option == $product_id) {
// Loop through the submission values looking for the product
// which was just purchased.
foreach ($webform_submission->data[$key]['value'] as $value_key => $value) {
$value = json_decode($value);
if (!empty($value->product_id) && $value->product_id == $product_id) {
$value->order_id = $order_id;
$value->line_item_id = $line_item_id;
$value->paid = $paid;
$webform_submission->data[$key]['value'][$value_key] = json_encode($value);
// The following is the same as running
// webform_submission_update() except that
// it does not invoke the update hooks.
// Update the main submission info.
drupal_write_record('webform_submissions', $webform_submission, 'sid');
// Delete all old submission component data.
db_delete('webform_submitted_data')
->condition('sid', $webform_submission->sid)
->execute();
// Read submission component data.
$webform_submission->is_new = FALSE;
webform_submission_insert($node, $webform_submission);
// Do NOT return - but loop through all
// We need to find all items with this $product_id
// and give it the $line_item_id so that when Rule
// "Mark commerce webform as paid" is executed
// it will also be marked as paid.
}
}
}
}
}
}
}