function uc_flatrate_update_2 in Ubercart 5
File
- shipping/
uc_flatrate/ uc_flatrate.install, line 75
Code
function uc_flatrate_update_2() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {uc_flatrate_products} CHANGE rate rate decimal(10,2) NOT NULL default 0.00");
$ret[] = update_sql("ALTER TABLE {uc_flatrate_products} ADD COLUMN mid mediumint(9) unsigned NOT NULL default 0 AFTER nid");
$ret[] = update_sql("CREATE TABLE {uc_flatrate_methods} (\n `mid` mediumint(9) unsigned NOT NULL default 0,\n `title` varchar(255) NOT NULL default '',\n `label` varchar(255) NOT NULL default '',\n `base_rate` decimal(10,2) NOT NULL default 0.00,\n `product_rate` decimal(10,2) NOT NULL default 0.00,\n PRIMARY KEY (`mid`)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ;");
break;
case 'pgsql':
db_change_column($ret, 'uc_flatrate_products', 'rate', 'rate', 'decimal(10,2)', array(
'not null' => true,
'default' => 0,
));
db_add_column($ret, 'uc_flatrate_products', 'mid', 'mediumint(9) unsigned', array(
'not null' => true,
'default' => 0,
));
$ret[] = update_sql("CREATE TABLE {uc_flatrate_methods} (\n mid mediumint(9) unsigned NOT NULL default 0,\n title varchar(255) NOT NULL default '',\n label varchar(255) NOT NULL default '',\n base_rate decimal(10,2) NOT NULL default 0.00,\n product_rate decimal(10,2) NOT NULL default 0.00,\n PRIMARY KEY (mid)\n );");
$ret[] = update_sql("CREATE INDEX {uc_flatrate_methods}_mid_idx ON {uc_flatrate_methods}(mid)");
break;
}
$set_var = false;
$enabled = variable_get('uc_quote_enabled', array());
$weight = variable_get('uc_quote_method_weight', array(
'flatrate' => 0,
'order_rate' => 1,
));
$base_rate = variable_get('uc_flatrate_product_base_rate', 0);
$product_rate = variable_get('uc_flatrate_product_default', 0);
$changes = db_num_rows(db_query("SELECT * FROM {uc_flatrate_products}"));
$mid = db_next_id('{uc_flatrate_methods}_mid');
$ret[] = update_sql("INSERT INTO {uc_flatrate_methods} (mid, title, label, base_rate, product_rate) VALUES (" . $mid . ", '" . t('Flat rate per product') . "', '" . t('Shipping rate') . "', " . $base_rate . ", " . $product_rate . ")");
$ret[] = update_sql("UPDATE {uc_flatrate_products} SET mid = " . $mid);
$enabled['flatrate_' . $mid] = $enabled['flatrate'];
$weight['flatrate_' . $mid] = $weight['flatrate'];
unset($enabled['flatrate'], $weight['flatrate']);
if (db_table_exists('workflow_ng_cfgs') && ($configuration = db_fetch_object(db_query("SELECT data FROM {workflow_ng_cfgs} WHERE name = '%s'", 'uc_flatrate_get_quote')))) {
$configuration->name = 'uc_flatrate_get_quote_' . $mid;
$configuration->data = unserialize($configuration->data);
$configuration->data['#event'] = 'get_quote_from_flatrate_' . $mid;
$result = db_query("UPDATE {workflow_ng_cfgs} SET name = '" . $configuration->name . "', data = '" . serialize($configuration->data) . "' WHERE name = 'uc_flatrate_get_quote'");
$ret[] = array(
'success' => $result !== FALSE,
'query' => check_plain("UPDATE {workflow_ng_cfgs} SET name = '" . $configuration->name . "', data = '" . serialize($configuration->data) . "' WHERE name = 'uc_flatrate_get_quote'"),
);
}
else {
$ret[] = array(
'success' => FALSE,
'query' => check_plain("UPDATE {workflow_ng_cfgs} SET name = '" . $configuration->name . "', data = '" . serialize($configuration->data) . "' WHERE name = 'uc_flatrate_get_quote'"),
);
}
$order_rate = variable_get('uc_flatrate_order_rate', 0);
$mid = db_next_id('{uc_flatrate_methods}_mid');
$ret[] = update_sql("INSERT INTO {uc_flatrate_methods} (mid, title, label, base_rate) VALUES (" . $mid . ", '" . t('Flat rate per order') . "', '" . t('Shipping rate') . "', " . $order_rate . ")");
$enabled['flatrate_' . $mid] = $enabled['order_rate'];
$weight['flatrate_' . $mid] = $weight['order_rate'];
unset($enabled['order_rate'], $weight['order_rate']);
if (db_table_exists('workflow_ng_cfgs') && ($configuration = db_fetch_object(db_query("SELECT data FROM {workflow_ng_cfgs} WHERE name = '%s'", 'uc_flatrate_get_quote_by_order')))) {
$configuration->name = 'uc_flatrate_get_quote_' . $mid;
$configuration->data = unserialize($configuration->data);
$configuration->data['#event'] = 'get_quote_from_flatrate_' . $mid;
$result = db_query("UPDATE {workflow_ng_cfgs} SET name = '" . $configuration->name . "', data = '" . serialize($configuration->data) . "' WHERE name = 'uc_flatrate_get_quote_by_order'");
$ret[] = array(
'success' => $result !== FALSE,
'query' => check_plain("UPDATE {workflow_ng_cfgs} SET name = '" . $configuration->name . "', data = '" . serialize($configuration->data) . "' WHERE name = 'uc_flatrate_get_quote_by_order'"),
);
}
else {
$ret[] = array(
'success' => FALSE,
'query' => check_plain("UPDATE {workflow_ng_cfgs} SET name = '" . $configuration->name . "', data = '" . serialize($configuration->data) . "' WHERE name = 'uc_flatrate_get_quote_by_order'"),
);
}
variable_set('uc_quote_enabled', $enabled);
variable_set('uc_quote_method_weight', $weight);
if (module_exists('workflow_ng')) {
workflow_ng_clear_cache();
}
variable_del('uc_flatrate_product_base_rate');
variable_del('uc_flatrate_product_default');
variable_del('uc_flatrate_order_rate');
return $ret;
}