function commerce_flat_rate_service_save in Commerce Flat Rate 7
Saves a flat rate service to the database.
Parameters
$shipping_service: The flat rate shipping service to save. If the service array includes the base_rate array, its amount and currency_code values will be moved up a level to be saved to the database via drupal_write_record().
$skip_reset: Boolean indicating whether or not this save should result in shipping services being reset and the menu being rebuilt; defaults to FALSE. This is useful when you intend to perform many saves at once, as menu rebuilding is very costly in terms of performance.
Return value
The return value of the call to drupal_write_record() to save the flat rate service; either FALSE on failure or SAVED_NEW or SAVED_UPDATED indicating the type of query performed to save the flat rate service.
1 call to commerce_flat_rate_service_save()
- commerce_flat_rate_service_form_submit in includes/
commerce_flat_rate.admin.inc - Submit handler: saves the new or updated flat rate service.
File
- ./
commerce_flat_rate.module, line 275 - Allows you to define any number of flat rate shipping services for customers to choose during checkout.
Code
function commerce_flat_rate_service_save($shipping_service, $skip_reset = FALSE) {
// Move the amount and currency code up a level in the service array.
if (!empty($shipping_service['base_rate'])) {
$shipping_service['amount'] = $shipping_service['base_rate']['amount'];
$shipping_service['currency_code'] = $shipping_service['base_rate']['currency_code'];
}
$op = drupal_write_record('commerce_flat_rate_service', $shipping_service, empty($shipping_service['is_new']) ? 'name' : array());
// If this is a new flat rate service and the insert did not fail...
if (!empty($shipping_service['is_new']) && $op !== FALSE) {
// Notify other modules that a new tax flat rate service has been created.
module_invoke_all('commerce_flat_rate_service_insert', $shipping_service, $skip_reset);
}
elseif ($op !== FALSE) {
// Notify other modules that an existing flat rate service has been updated.
module_invoke_all('commerce_flat_rate_service_update', $shipping_service, $skip_reset);
}
// Clear the necessary caches and rebuild the menu items.
if (!$skip_reset) {
commerce_shipping_services_reset();
entity_defaults_rebuild();
rules_clear_cache(TRUE);
menu_rebuild();
}
return $op;
}