|
|
Drupal example source code file (uc_shipping.install)
The uc_shipping.install Drupal example source code<?php // $Id: uc_shipping.install,v 1.4.2.12 2010/07/12 01:57:35 tr Exp $ /** * @file * Install hooks for uc_shipping.module. */ /** * Implementation of hook_schema(). */ function uc_shipping_schema() { $schema = array(); $schema['uc_shipments'] = array( 'description' => 'Stores shipment information.', 'fields' => array( 'sid' => array( 'description' => 'Primary key: the shipment ID.', 'type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, ), 'order_id' => array( 'description' => 'The {uc_orders}.order_id of the order associated with the shipment.', 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, ), 'o_first_name' => array( 'description' => 'Origin address: First name.', 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', ), 'o_last_name' => array( 'description' => 'Origin address: Last name.', 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', ), 'o_company' => array( 'description' => 'Origin address: Company name.', 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', ), 'o_street1' => array( 'description' => 'Origin address: Street line 1.', 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', ), 'o_street2' => array( 'description' => 'Origin address: Street line 2.', 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', ), 'o_city' => array( 'description' => 'Origin address: City.', 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', ), 'o_zone' => array( 'description' => 'Origin address: State/province, from {uc_zones}.zone_id.', 'type' => 'int', 'size' => 'medium', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, ), 'o_postal_code' => array( 'description' => 'Origin address: Postal code.', 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', ), 'o_country' => array( 'description' => 'Origin address: Country, from {uc_countries}.country_id.', 'type' => 'int', 'size' => 'medium', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, ), 'd_first_name' => array( 'description' => 'Destination address: First name.', 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', ), 'd_last_name' => array( 'description' => 'Destination address: Last name.', 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', ), 'd_company' => array( 'description' => 'Destination address: Company name.', 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', ), 'd_street1' => array( 'description' => 'Destination address: Street line 1.', 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', ), 'd_street2' => array( 'description' => 'Destination address: Street line 2.', 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', ), 'd_city' => array( 'description' => 'Destination address: City.', 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', ), 'd_zone' => array( 'description' => 'Destination address: State/province, from {uc_zones}.zone_id.', 'type' => 'int', 'size' => 'medium', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, ), 'd_postal_code' => array( 'description' => 'Destination address: Postal code.', 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', ), 'd_country' => array( 'description' => 'Destination address: Country, from {uc_countries}.country_id.', 'type' => 'int', 'size' => 'medium', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, ), 'shipping_method' => array( 'description' => 'The shipping method.', 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', ), 'accessorials' => array( 'description' => 'Shipping options and special instructions.', 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', ), 'carrier' => array( 'description' => 'The company making the delivery.', 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', ), 'transaction_id' => array( 'description' => "The carrier's shipment identifier.", 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', ), 'tracking_number' => array( 'description' => 'The number used by the carrier to locate the shipment while it is in transit.', 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', ), 'ship_date' => array( 'description' => 'The Unix timestamp indicating when the shipment left the origin address.', 'type' => 'int', 'not null' => TRUE, 'default' => 0, ), 'expected_delivery' => array( 'description' => 'The Unix timestamp indicating the expected date of delivery.', 'type' => 'int', 'not null' => TRUE, 'default' => 0, ), 'cost' => array( 'description' => 'The cost of the shipment.', 'type' => 'numeric', 'precision' => 16, 'scale' => 5, 'not null' => TRUE, 'default' => 0.0, ), ), 'primary key' => array('sid'), ); $schema['uc_packages'] = array( 'description' => 'Stores shipment package information.', 'fields' => array( 'package_id' => array( 'description' => 'Primary key: the package ID.', 'type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, ), 'order_id' => array( 'description' => 'The {uc_orders}.order_id.', 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, ), 'shipping_type' => array( 'description' => 'The basic type of shipment, e.g.: small package, freight, etc.', 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', ), 'pkg_type' => array( 'description' => 'The type of packaging.', 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', ), 'length' => array( 'description' => 'The package length.', 'type' => 'float', 'not null' => FALSE, ), 'width' => array( 'description' => 'The pacakge width.', 'type' => 'float', 'not null' => FALSE, ), 'height' => array( 'description' => 'The package height.', 'type' => 'float', 'not null' => FALSE, ), 'length_units' => array( 'description' => 'The physical units of the length, width, and height.', 'type' => 'varchar', 'length' => 255, 'not null' => FALSE, ), 'value' => array( 'description' => 'The monetary value of the package contents.', 'type' => 'numeric', 'precision' => 16, 'scale' => 5, 'not null' => FALSE, 'default' => 0.0, ), 'sid' => array( 'description' => 'The {uc_shimpents}.sid, if the package has been shipped.', 'type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, ), 'tracking_number' => array( 'description' => 'The package-specific tracking number, if available.', 'type' => 'varchar', 'length' => 255, 'not null' => FALSE, ), 'label_image' => array( 'description' => 'The {file}.fid that refers to an image of the shipping label of the package.', 'type' => 'varchar', 'length' => 255, 'not null' => FALSE, ), ), 'primary key' => array('package_id'), ); $schema['uc_packaged_products'] = array( 'description' => 'Stores packaged product information.', 'fields' => array( 'package_id' => array( 'description' => 'The {uc_packages}.package_id in which the product is shipped.', 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, ), 'order_product_id' => array( 'description' => 'The {uc_order_products}.order_product_id of the ordered product.', 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, ), 'qty' => array( 'description' => 'The number of this product in this package.', 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, ), ), 'primary key' => array('package_id', 'order_product_id'), ); return $schema; } /** * Implementation of hook_install(). */ function uc_shipping_install() { drupal_install_schema('uc_shipping'); } /** * Implementation of hook_uninstall(). */ function uc_shipping_uninstall() { drupal_uninstall_schema('uc_shipping'); } function uc_shipping_update_1() { $ret = array(); switch ($GLOBALS['db_type']) { case 'mysql': case 'mysqli': $ret[] = update_sql("ALTER TABLE {uc_packages} CHANGE units length_units varchar(255) NULL"); break; case 'pgsql': db_change_column($ret, 'uc_packages', 'units', 'length_units', 'varchar(255)', array('not null' => FALSE)); break; } return $ret; } //function uc_shipping_update_2() { // Abortive attempt at rearranging package_ids and order_product_ids. // Leaving this here as a reminder to start the next update at "3". //} function uc_shipping_update_6000() { $ret = array(); db_drop_primary_key($ret, 'uc_shipments'); db_change_field($ret, 'uc_shipments', 'sid', 'sid', array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), array('primary key' => array('sid'))); db_change_field($ret, 'uc_shipments', 'order_id', 'order_id', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0)); db_drop_primary_key($ret, 'uc_packages'); db_change_field($ret, 'uc_packages', 'package_id', 'package_id', array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), array('primary key' => array('package_id'))); db_change_field($ret, 'uc_packages', 'order_id', 'order_id', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0)); db_change_field($ret, 'uc_packages', 'value', 'value', array('type' => 'numeric', 'precision' => 10, 'scale' => 2, 'unsigned' => TRUE, 'not null' => FALSE)); db_change_field($ret, 'uc_packages', 'sid', 'sid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE)); db_drop_primary_key($ret, 'uc_packaged_products'); db_change_field($ret, 'uc_packaged_products', 'package_id', 'package_id', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0)); db_change_field($ret, 'uc_packaged_products', 'order_product_id', 'order_product_id', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0)); db_add_primary_key($ret, 'uc_packaged_products', array('package_id', 'order_product_id')); return $ret; } function uc_shipping_update_6001() { $ret = array(); if (db_column_exists('uc_packages', 'values')) { if ($GLOBALS['db_type'] == 'mysql' || $GLOBALS['db_type'] == 'mysqli') { $field = '`values`'; } else { $field = 'values'; } db_change_field($ret, 'uc_packages', $field, 'value', array('type' => 'numeric', 'precision' => 10, 'scale' => 2, 'unsigned' => TRUE, 'not null' => FALSE)); } return $ret; } function uc_shipping_update_6002() { $ret = array(); db_change_field($ret, 'uc_packages', 'value', 'value', array('type' => 'numeric', 'precision' => 10, 'scale' => 2, 'not null' => FALSE)); return $ret; } function uc_shipping_update_6003() { $ret = array(); db_change_field($ret, 'uc_shipments', 'cost', 'cost', array('type' => 'numeric', 'precision' => 15, 'scale' => 3, 'not null' => TRUE, 'default' => 0)); db_change_field($ret, 'uc_packages', 'value', 'value', array('type' => 'numeric', 'precision' => 15, 'scale' => 3, 'not null' => FALSE)); return $ret; } /** * Change to signed floats for package dimensions. */ function uc_shipping_update_6004() { $ret = array(); $schema = array( 'float_spec' => array( 'type' => 'float', 'not null' => TRUE, 'default' => 0.0, ), ); db_change_field($ret, 'uc_packages', 'length', 'length', $schema['float_spec'] + array('description' => t('Physical length of the packaging.'))); db_change_field($ret, 'uc_packages', 'width', 'width', $schema['float_spec'] + array('description' => t('Physical width of the packaging.'))); db_change_field($ret, 'uc_packages', 'height', 'height', $schema['float_spec'] + array('description' => t('Physical height of the packaging.'))); return $ret; } /** * Change currency fields to numeric(16,5). */ function uc_shipping_update_6005() { $ret = array(); db_change_field($ret, 'uc_shipments', 'cost', 'cost', array('type' => 'numeric', 'precision' => 16, 'scale' => 5, 'not null' => TRUE, 'default' => 0)); db_change_field($ret, 'uc_packages', 'value', 'value', array('type' => 'numeric', 'precision' => 16, 'scale' => 5, 'not null' => FALSE)); return $ret; } Other Drupal examples (source code examples)Here is a short list of links related to this Drupal uc_shipping.install source code file: |
"Drupal" is a registered trademark of Dries Buytaert.
my drupal tutorials and examples
Copyright
1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.
Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.