123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504 |
- <?php
- /**
- * @file
- * Install, update and uninstall functions for the uc_attribute module.
- */
- /**
- * Implements hook_schema().
- */
- function uc_attribute_schema() {
- $schema = array();
- $schema['uc_attributes'] = array(
- 'description' => 'Attributes: the decisions that need to be made about products.',
- 'fields' => array(
- 'aid' => array(
- 'description' => 'Primary key: attribute ID.',
- 'type' => 'serial',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- ),
- 'name' => array(
- 'description' => 'Name of the attribute.',
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => '',
- ),
- 'label' => array(
- 'description' => 'Label to use when attribute is displayed.',
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => '',
- ),
- 'ordering' => array(
- 'description' => 'Determines the list position of attributes.',
- 'type' => 'int',
- 'size' => 'tiny',
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'required' => array(
- 'description' => 'Flag that, if set, requires a user response for attributes (disables default options).',
- 'type' => 'int',
- 'size' => 'tiny',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'display' => array(
- 'description' => 'Display type of the attribute options: 0 => text fields, 1 => select box (default), 2 => radio buttons.',
- 'type' => 'int',
- 'size' => 'tiny',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 1,
- ),
- 'description' => array(
- 'description' => 'Description of the attribute.',
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => '',
- ),
- ),
- 'primary key' => array('aid'),
- );
- $schema['uc_attribute_options'] = array(
- 'description' => 'The available choices for each attribute.',
- 'fields' => array(
- 'aid' => array(
- 'description' => 'The {uc_attributes}.aid.',
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'oid' => array(
- 'description' => 'Primary key: the option ID.',
- 'type' => 'serial',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- ),
- 'name' => array(
- 'description' => 'The name of the option.',
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => '',
- ),
- 'cost' => array(
- 'description' => "The adjustment to a product's cost with the chosen option.",
- 'type' => 'numeric',
- 'precision' => 16,
- 'scale' => 5,
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'price' => array(
- 'description' => "The adjustment to a product's price with the chosen option.",
- 'type' => 'numeric',
- 'precision' => 16,
- 'scale' => 5,
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'weight' => array(
- 'description' => "The adjustment to a product's physical weight with the chosen option.",
- 'type' => 'float',
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'ordering' => array(
- 'description' => 'Affects the list position of the options.',
- 'type' => 'int',
- 'size' => 'tiny',
- 'not null' => TRUE,
- 'default' => 0,
- ),
- ),
- 'primary key' => array('oid'),
- 'indexes' => array(
- 'aid' => array('aid'),
- ),
- 'foreign keys' => array(
- 'uc_attributes' => array(
- 'table' => 'uc_attributes',
- 'columns' => array('aid' => 'aid'),
- ),
- ),
- );
- $schema['uc_class_attributes'] = array(
- 'description' => 'Attributes copied to a product of a certain class when it is created.',
- 'fields' => array(
- 'pcid' => array(
- 'description' => 'Primary key: the product {node}.type.',
- 'type' => 'varchar',
- 'length' => 32,
- 'not null' => TRUE,
- 'default' => '',
- ),
- 'aid' => array(
- 'description' => 'The {uc_attributes}.aid.',
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'label' => array(
- 'description' => 'Label to use when attribute is displayed.',
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => '',
- ),
- 'ordering' => array(
- 'description' => 'Determines the list position of attributes.',
- 'type' => 'int',
- 'size' => 'tiny',
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'default_option' => array(
- 'description' => 'The default value of the attribute field on the add to cart form.',
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'required' => array(
- 'description' => "A flag indicating that, if set, requires a user response for attributes (disables default options).",
- 'type' => 'int',
- 'size' => 'tiny',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'display' => array(
- 'description' => 'Display type of the attribute options: 0 => text fields, 1 => select box (default), 2 => radio buttons',
- 'type' => 'int',
- 'size' => 'tiny',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 1,
- ),
- ),
- 'primary key' => array('pcid', 'aid'),
- 'foreign keys' => array(
- 'uc_product_classes' => array(
- 'table' => 'uc_product_classes',
- 'columns' => array('pcid' => 'pcid'),
- ),
- 'uc_attributes' => array(
- 'table' => 'uc_attributes',
- 'columns' => array('aid' => 'aid'),
- ),
- ),
- );
- $schema['uc_class_attribute_options'] = array(
- 'description' => 'The available choices for each attribute.',
- 'fields' => array(
- 'pcid' => array(
- 'description' => 'Primary key: the product {node}.type.',
- 'type' => 'varchar',
- 'length' => 32,
- 'not null' => TRUE,
- 'default' => '',
- ),
- 'oid' => array(
- 'description' => 'The {uc_attribute_options}.oid.',
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'cost' => array(
- 'description' => "The adjustment to a product's cost with the chosen option.",
- 'type' => 'numeric',
- 'precision' => 16,
- 'scale' => 5,
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'price' => array(
- 'description' => "The adjustment to a product's price with the chosen option.",
- 'type' => 'numeric',
- 'precision' => 16,
- 'scale' => 5,
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'weight' => array(
- 'description' => "The adjustment to a product's physical weight with the chosen option.",
- 'type' => 'float',
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'ordering' => array(
- 'description' => 'Affects the list position of the options.',
- 'type' => 'int',
- 'size' => 'tiny',
- 'not null' => TRUE,
- 'default' => 0,
- ),
- ),
- 'primary key' => array('pcid', 'oid'),
- 'foreign keys' => array(
- 'uc_product_classes' => array(
- 'table' => 'uc_product_classes',
- 'columns' => array('pcid' => 'pcid'),
- ),
- 'uc_attribute_options' => array(
- 'table' => 'uc_attribute_options',
- 'columns' => array('oid' => 'oid'),
- ),
- ),
- );
- $schema['uc_product_attributes'] = array(
- 'description' => 'Attributes copied to a product.',
- 'fields' => array(
- 'nid' => array(
- 'description' => 'The product {node}.nid.',
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'aid' => array(
- 'description' => 'The {uc_attributes}.aid.',
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'label' => array(
- 'description' => 'Label to use when attribute is displayed',
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => '',
- ),
- 'ordering' => array(
- 'description' => 'Determines the list position of attributes.',
- 'type' => 'int',
- 'size' => 'tiny',
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'default_option' => array(
- 'description' => 'The default value of the attribute field on the add to cart form.',
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'required' => array(
- 'description' => "Flag that, if set, requires a user response for attributes (disables default options).",
- 'type' => 'int',
- 'size' => 'tiny',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'display' => array(
- 'description' => 'Display type of the attribute options: 0 -- text fields, 1 -- select box (default), 2 -- radio buttons',
- 'type' => 'int',
- 'size' => 'tiny',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 1,
- ),
- ),
- 'primary key' => array('nid', 'aid'),
- 'foreign keys' => array(
- 'uc_products' => array(
- 'table' => 'uc_products',
- 'columns' => array('nid' => 'nid'),
- ),
- 'uc_attributes' => array(
- 'table' => 'uc_attributes',
- 'columns' => array('aid' => 'aid'),
- ),
- ),
- );
- $schema['uc_product_options'] = array(
- 'description' => 'The available choices for each attribute.',
- 'fields' => array(
- 'nid' => array(
- 'description' => 'The product {node}.nid.',
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'oid' => array(
- 'description' => 'The {uc_attribute_options}.oid.',
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'cost' => array(
- 'description' => "The adjustment to a product's cost with the chosen option.",
- 'type' => 'numeric',
- 'precision' => 16,
- 'scale' => 5,
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'price' => array(
- 'description' => "The adjustment to a product's price with the chosen option.",
- 'type' => 'numeric',
- 'precision' => 16,
- 'scale' => 5,
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'weight' => array(
- 'description' => "The adjustment to a product's physical weight with the chosen option.",
- 'type' => 'float',
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'ordering' => array(
- 'description' => 'Affects the list position of the options.',
- 'type' => 'int',
- 'size' => 'tiny',
- 'not null' => TRUE,
- 'default' => 0,
- ),
- ),
- 'primary key' => array('nid', 'oid'),
- 'foreign keys' => array(
- 'uc_products' => array(
- 'table' => 'uc_products',
- 'columns' => array('nid' => 'nid'),
- ),
- 'uc_attribute_options' => array(
- 'table' => 'uc_attribute_options',
- 'columns' => array('oid' => 'oid'),
- ),
- ),
- );
- $schema['uc_product_adjustments'] = array(
- 'description' => "Changes to a product's SKU based on the possible combination of chosen options.",
- 'fields' => array(
- 'nid' => array(
- 'description' => 'The product {node}.nid.',
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'combination' => array(
- 'description' => 'A serialized array whose keys are attribute IDs and values are option IDs.',
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => '',
- 'serialize' => TRUE,
- ),
- 'model' => array(
- 'description' => 'The SKU representing the product with the combination of options.',
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => '',
- ),
- ),
- 'indexes' => array(
- 'nid' => array('nid'),
- ),
- 'foreign keys' => array(
- 'uc_products' => array(
- 'table' => 'uc_products',
- 'columns' => array('nid' => 'nid'),
- ),
- ),
- );
- return $schema;
- }
- /**
- * Implements hook_uninstall().
- */
- function uc_attribute_uninstall() {
- variable_del('uc_attribute_option_price_format');
- }
- /**
- * Implements hook_update_dependencies().
- */
- function uc_attribute_update_dependencies() {
- $dependencies['uc_attribute'][7000] = array(
- 'filter' => 7005,
- );
- return $dependencies;
- }
- /**
- * Implements hook_update_last_removed().
- */
- function uc_attribute_update_last_removed() {
- return 6005;
- }
- /**
- * Add description format for attributes.
- */
- function uc_attribute_update_7000() {
- db_add_field('uc_attributes', 'format', array(
- 'description' => 'Format of the attribute description.',
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- ));
- db_update('uc_attributes')
- ->fields(array('format' => 0))
- ->execute();
- }
- /**
- * Change default description format to NULL.
- */
- function uc_attribute_update_7001() {
- db_change_field('uc_attributes', 'format', 'format', array(
- 'description' => 'Format of the attribute description.',
- 'type' => 'int',
- 'not null' => FALSE,
- 'default' => NULL,
- ));
- db_update('uc_attributes')
- ->fields(array('format' => filter_fallback_format()))
- ->execute();
- }
- /**
- * Remove attribute description format..
- */
- function uc_attribute_update_7002() {
- db_drop_field('uc_attributes', 'format');
- }
- /**
- * Add index to attribute options table.
- */
- function uc_attribute_update_7003() {
- // Indexes may have been added in 6.x-2.x.
- if (!db_index_exists('uc_attribute_options', 'aid')) {
- db_add_index('uc_attribute_options', 'aid', array('aid'));
- }
- }
|