You are here

function commerce_product_ui_product_type_save in Commerce Core 7

Saves a product type.

This function will either insert a new product type if $product_type['is_new'] is set or attempt to update an existing product type if it is not. It does not currently support changing the machine-readable name of the product type, nor is this possible through the form supplied by the Product UI module.

Parameters

$product_type: The product type array containing the basic properties as initialized in commerce_product_ui_product_type_new().

$configure: Boolean indicating whether or not product type configuration should be performed in the event of a new product type being saved.

$skip_reset: Boolean indicating whether or not this save should result in product types 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 product type, either FALSE on failure or SAVED_NEW or SAVED_UPDATED indicating the type of query performed to save the product type.

4 calls to commerce_product_ui_product_type_save()
CommerceBaseTestCase::createDummyProductType in tests/commerce_base.test
Creates a dummy product type for use with other tests.
CommerceProductCRUDTestCase::testCommerceProductTypeCrud in modules/product/tests/commerce_product.test
Test the product type CRUD functions.
commerce_product_ui_install in modules/product/commerce_product_ui.install
Implements hook_install().
commerce_product_ui_product_type_form_submit in modules/product/includes/commerce_product_ui.forms.inc
Form submit handler: save a product type.

File

modules/product/commerce_product_ui.module, line 345

Code

function commerce_product_ui_product_type_save($product_type, $configure = TRUE, $skip_reset = FALSE) {
  $op = drupal_write_record('commerce_product_type', $product_type, empty($product_type['is_new']) ? 'type' : array());

  // If this is a new product type and the insert did not fail...
  if (!empty($product_type['is_new']) && $op !== FALSE) {

    // Notify the field API that a new bundle has been created.
    field_attach_create_bundle('commerce_product', $product_type['type']);

    // Add the default price field to the product type.
    if ($configure) {
      commerce_product_configure_product_type($product_type['type']);
    }

    // Notify other modules that a new product type has been created.
    module_invoke_all('commerce_product_type_insert', $product_type, $skip_reset);
  }
  elseif ($op !== FALSE) {

    // Notify other modules that an existing product type has been updated.
    module_invoke_all('commerce_product_type_update', $product_type, $skip_reset);
  }

  // Rebuild the menu to add this product type's menu items.
  if (!$skip_reset) {
    commerce_product_types_reset();
    variable_set('menu_rebuild_needed', TRUE);
  }
  return $op;
}