You are here

uc_varprice.install in UC Variable Price 6

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

Installs the necessary table for the Variable Price product features.

File

uc_varprice.install
View source
<?php

// $Id: uc_varprice.install,v 1.1 2009/05/15 21:40:04 rszrama Exp $

/**
 * @file
 * Installs the necessary table for the Variable Price product features.
 */
function uc_varprice_schema() {
  $schema = array();
  $schema['uc_varprice_products'] = array(
    'fields' => array(
      'vpid' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'pfid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'price_default' => array(
        'description' => t('Default product price.'),
        'type' => 'numeric',
        'precision' => 10,
        'scale' => 2,
        'not null' => TRUE,
        'default' => 0.0,
      ),
      'price_minimum' => array(
        'description' => t('Minimum product price.'),
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'price_maximum' => array(
        'description' => t('Maximum product price.'),
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'add_to_cart_title' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'amount_title' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'arbitrary' => array(
        'type' => 'int',
        'size' => 'tiny',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'selectable' => array(
        'type' => 'int',
        'size' => 'tiny',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'sel_widget' => array(
        'type' => 'varchar',
        'length' => 8,
        'not null' => TRUE,
        'default' => 'radios',
      ),
      'sel_options' => array(
        'type' => 'text',
        'not null' => TRUE,
        'default' => '',
      ),
    ),
    'indexes' => array(
      'pfid' => array(
        'pfid',
      ),
    ),
    'primary key' => array(
      'vpid',
    ),
  );
  return $schema;
}
function uc_varprice_install() {
  drupal_install_schema('uc_varprice');
}
function uc_varprice_uninstall() {
  drupal_uninstall_schema('uc_varprice');
  db_query("DELETE FROM {uc_product_features} WHERE fid = 'varprice'");
  variable_del('uc_varprice_global_default');
  global $conf;
  foreach (array_keys($conf) as $key) {
    if (strpos($key, 'ucvp_class_def_') === 0) {
      variable_del($key);
    }
  }
}
function uc_varprice_update_6001() {
  $added = array();
  $schema = uc_varprice_schema();

  // Add new fields
  foreach (array(
    'arbitrary',
    'selectable',
    'sel_widget',
    'sel_options',
  ) as $key) {
    db_add_field($added, 'uc_varprice_products', $key, $schema['uc_varprice_products']['fields'][$key]);
  }

  // Define all currently-existing varprice fields as arbitrary price only fields
  db_query('UPDATE {uc_varprice_products} SET arbitrary = 1');
  return $added;
}

Functions

Namesort descending Description
uc_varprice_install
uc_varprice_schema @file Installs the necessary table for the Variable Price product features.
uc_varprice_uninstall
uc_varprice_update_6001