123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- <?php
- /**
- * @file
- * Install, update and uninstall functions for the uc_taxes module.
- */
- /**
- * Implements hook_schema().
- */
- function uc_taxes_schema() {
- $schema = array();
- $schema['uc_taxes'] = array(
- 'description' => 'Stores tax information.',
- 'fields' => array(
- 'id' => array(
- 'description' => 'Primary key: Unique tax rate id.',
- 'type' => 'serial',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- ),
- 'name' => array(
- 'description' => 'The tax rate name.',
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => '',
- ),
- 'rate' => array(
- 'description' => 'The tax rate multiplier.',
- 'type' => 'float',
- 'not null' => TRUE,
- 'default' => 0.0,
- ),
- 'shippable' => array(
- 'description' => 'Flag that describes how this rate applies to shippable and non-shippable products. 0 => Disregard shipability. 1 => Apply tax to shippable products only.',
- 'type' => 'int',
- 'size' => 'tiny',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'taxed_product_types' => array(
- 'description' => 'Serialized array of node types to be taxed.',
- 'type' => 'text',
- 'serialize' => TRUE,
- ),
- 'taxed_line_items' => array(
- 'description' => 'Serialized array of line item types to be taxed.',
- 'type' => 'text',
- 'serialize' => TRUE,
- ),
- 'weight' => array(
- 'description' => 'The weight of this tax rate in relation to other rates.',
- 'type' => 'int',
- 'size' => 'tiny',
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'display_include' => array(
- 'description' => 'Boolean flag indicating that product prices should be displayed including the tax.',
- 'type' => 'int',
- 'size' => 'tiny',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'inclusion_text' => array(
- 'description' => 'Text to be shown near a product price that includes tax.',
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => '',
- ),
- ),
- 'primary key' => array('id'),
- );
- $schema['uc_taxed_product_types'] = array(
- 'fields' => array(
- 'tax_id' => array(
- 'description' => 'Tax rate id',
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'type' => array(
- 'description' => 'Node type',
- 'type' => 'varchar',
- 'length' => 32,
- 'not null' => TRUE,
- 'default' => '',
- ),
- ),
- 'primary key' => array('tax_id', 'type'),
- 'indexes' => array(
- 'type' => array('type'),
- ),
- );
- $schema['uc_taxed_line_items'] = $schema['uc_taxed_product_types'];
- $schema['uc_taxed_line_items']['fields']['type']['description'] = 'Line item type';
- return $schema;
- }
- /**
- * Implements hook_update_last_removed().
- */
- function uc_taxes_update_last_removed() {
- return 6003;
- }
- /**
- * Add "price including tax" columns.
- */
- function uc_taxes_update_7000() {
- db_add_field('uc_taxes', 'include', array(
- 'description' => 'Boolean flag indicating that product prices should be displayed including the tax.',
- 'type' => 'int',
- 'size' => 'tiny',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- ));
- db_add_field('uc_taxes', 'inclusion_text', array(
- 'description' => 'Text to be shown near a product price that includes tax.',
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => '',
- ));
- return t('Added "price including tax" columns.');
- }
- /**
- * Separate taxed product types and line items to joined tables.
- */
- function uc_taxes_update_7001() {
- $table = array(
- 'fields' => array(
- 'tax_id' => array(
- 'description' => 'Tax rate id',
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'type' => array(
- 'description' => 'Node type',
- 'type' => 'varchar',
- 'length' => 32,
- 'not null' => TRUE,
- 'default' => '',
- ),
- ),
- 'primary key' => array('tax_id', 'type'),
- 'indexes' => array(
- 'type' => array('type'),
- ),
- );
- db_create_table('uc_taxed_product_types', $table);
- $table['fields']['type']['description'] = 'Line item type';
- db_create_table('uc_taxed_line_items', $table);
- $p_insert = db_insert('uc_taxed_product_types')->fields(array('tax_id', 'type'));
- $l_insert = db_insert('uc_taxed_line_items')->fields(array('tax_id', 'type'));
- $result = db_query("SELECT id, taxed_product_types, taxed_line_items FROM {uc_taxes}");
- foreach ($result as $tax) {
- $tax->taxed_product_types = unserialize($tax->taxed_product_types);
- $tax->taxed_line_items = unserialize($tax->taxed_line_items);
- foreach ($tax->taxed_product_types as $type) {
- $p_insert->values(array(
- 'tax_id' => $tax->id,
- 'type' => $type,
- ));
- }
- foreach ($tax->taxed_line_items as $type) {
- $l_insert->values(array(
- 'tax_id' => $tax->id,
- 'type' => $type,
- ));
- }
- $p_insert->execute();
- $l_insert->execute();
- }
- }
- /**
- * Fix schema mismatch in update 7000.
- */
- function uc_taxes_update_7002() {
- if (db_field_exists('uc_taxes', 'include')) {
- db_change_field('uc_taxes', 'include', 'display_include', array(
- 'description' => 'Boolean flag indicating that product prices should be displayed including the tax.',
- 'type' => 'int',
- 'size' => 'tiny',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- ));
- }
- db_change_field('uc_taxes', 'inclusion_text', 'inclusion_text', array(
- 'description' => 'Text to be shown near a product price that includes tax.',
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => '',
- ));
- }
- /**
- * Make sure orders have stored tax data.
- */
- function uc_taxes_update_7003(&$sandbox) {
- if (!isset($sandbox['progress'])) {
- $taxes = db_query("SELECT id FROM {uc_taxes}")->fetchField();
- if (!$taxes) {
- return;
- }
- $sandbox['current'] = 0;
- $sandbox['progress'] = 0;
- $sandbox['max'] = db_query("SELECT COUNT(order_id) FROM {uc_orders}")->fetchField();
- }
- $t = get_t();
- $limit = 100;
- $orders = db_query_range("SELECT order_id FROM {uc_orders} WHERE order_id > :current ORDER BY order_id", 0, $limit, array(':current' => $sandbox['current']))->fetchCol();
- foreach ($orders as $order_id) {
- $order = uc_order_load($order_id);
- uc_order_save($order);
- $sandbox['current'] = $order_id;
- $sandbox['progress']++;
- }
- if ($sandbox['progress'] < $sandbox['max']) {
- $sandbox['#finished'] = min(0.99, $sandbox['progress'] / $sandbox['max']);
- }
- else {
- $sandbox['#finished'] = 1;
- }
- }
|