You are here

commerce_option.install in Commerce Product Option 7.2

Same filename and directory in other branches
  1. 7 commerce_option.install

File

commerce_option.install
View source
<?php

/**
 * Implements hook_schema().
 */
function commerce_option_schema() {
  $schema = array();
  $schema['commerce_option'] = array(
    'description' => 'The base table for option lines.',
    'fields' => array(
      'option_id' => array(
        'description' => 'The primary identifier for the option.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'set_id' => array(
        'description' => 'The {commerce_option_set}.set_id of this.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'product_id' => array(
        'description' => 'The {commerce_product}.product_id which is linked with this option.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'line_item_id' => array(
        'description' => 'The {commerce_line_item}.line_item_id that is linked with this option.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'created' => array(
        'description' => 'The Unix timestamp when the option was created.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'changed' => array(
        'description' => 'The Unix timestamp when the product was most recently saved.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'data' => array(
        'type' => 'blob',
        'not null' => FALSE,
        'size' => 'big',
        'serialize' => TRUE,
        'description' => 'A serialized array of additional data.',
      ),
    ),
    'primary key' => array(
      'option_id',
    ),
    'indexes' => array(
      'set_id' => array(
        'set_id',
      ),
      'line_item_id' => array(
        'line_item_id',
      ),
    ),
    'foreign keys' => array(
      'line_item' => array(
        'table' => 'commerce_line_item',
        'columns' => array(
          'line_item_id' => 'line_item_id',
        ),
      ),
    ),
  );
  $schema['commerce_option_set'] = array(
    'description' => 'Stores information about {commerce_option} sets.',
    'fields' => array(
      'option_set_id' => array(
        'description' => 'The primary identifier for the option set.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'set_id' => array(
        'description' => 'The machine-readable name of this set.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'name' => array(
        'description' => 'The human-readable name of this set.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'description' => array(
        'description' => 'A brief description of this set.',
        'type' => 'text',
        'not null' => TRUE,
        'size' => 'medium',
      ),
      'data' => array(
        'type' => 'text',
        'not null' => FALSE,
        'size' => 'big',
        'serialize' => TRUE,
        'description' => 'A serialized array of additional data related to this option set.',
      ),
      'status' => array(
        'type' => 'int',
        'not null' => TRUE,
        // Set the default to ENTITY_CUSTOM without using the constant as it is
        // not safe to use it at this point.
        'default' => 0x1,
        'size' => 'tiny',
        'description' => 'The exportable status of the entity.',
      ),
      'module' => array(
        'description' => 'The name of the providing module if the entity has been defined in code.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
      ),
    ),
    'primary key' => array(
      'option_set_id',
    ),
  );
  return $schema;
}

/**
 * Add new field, which are used to track the line item with the exact option
 * value on the view page.
 *
 */
function commerce_option_update_7100() {
  db_add_field('commerce_option', 'product_id', array(
    'description' => 'The {commerce_product}.product_id which is linked with this option.',
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
  ));
  db_add_field('commerce_option', 'field_name', array(
    'description' => 'The {commerce_product} field_name which is linked with this option.',
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
    'default' => '',
  ));
  db_add_field('commerce_option', 'field_delta', array(
    'description' => 'The {commerce_product} field delta which is linked with this option.',
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
  ));
  db_add_field('commerce_option_set', 'data', array(
    'type' => 'text',
    'not null' => FALSE,
    'size' => 'big',
    'serialize' => TRUE,
    'description' => 'A serialized array of additional data related to this option set.',
  ));
  return t('Add new fields to the product option entity.');
}

/**
 * Add new fields to option sets to make them exportable.
 */
function commerce_option_update_7101() {
  db_add_field('commerce_option_set', 'status', array(
    'type' => 'int',
    'not null' => TRUE,
    // Set the default to ENTITY_CUSTOM without using the constant as it is
    // not safe to use it at this point.
    'default' => 0x1,
    'size' => 'tiny',
    'description' => 'The exportable status of the entity.',
  ));
  db_add_field('commerce_option_set', 'module', array(
    'description' => 'The name of the providing module if the entity has been defined in code.',
    'type' => 'varchar',
    'length' => 255,
    'not null' => FALSE,
  ));
}

/**
 * Add new fields to option sets to make them work with entity reference.
 */
function commerce_option_update_7102() {
  db_drop_primary_key('commerce_option_set');

  // Add the new field
  db_add_field('commerce_option_set', 'option_set_id', array(
    'description' => 'The primary identifier for the option set.',
    'type' => 'serial',
    'unsigned' => TRUE,
    'not null' => TRUE,
  ), array(
    'primary key' => array(
      'option_set_id',
    ),
  ));
}

/**
 * Drop two columns in the commerce_option table as they contain useless data.
 */
function commerce_option_update_7103() {
  db_drop_field('commerce_option', 'field_name');
  db_drop_field('commerce_option', 'field_delta');
}

/**
 * Add index to table
 */
function commerce_option_update_7104() {
  db_add_index('commerce_option', 'line_item_id', array(
    'line_item_id',
  ));
}

Functions

Namesort descending Description
commerce_option_schema Implements hook_schema().
commerce_option_update_7100 Add new field, which are used to track the line item with the exact option value on the view page.
commerce_option_update_7101 Add new fields to option sets to make them exportable.
commerce_option_update_7102 Add new fields to option sets to make them work with entity reference.
commerce_option_update_7103 Drop two columns in the commerce_option table as they contain useless data.
commerce_option_update_7104 Add index to table