function uc_weightquote_update_6001 in Ubercart 6.2
File
- shipping/
uc_weightquote/ uc_weightquote.install, line 159 - Install modules for uc_weightquote.module.
Code
function uc_weightquote_update_6001() {
$ret = array();
db_change_field($ret, 'uc_weightquote_products', 'rate', 'rate', array(
'type' => 'numeric',
'precision' => 15,
'scale' => 3,
'not null' => FALSE,
));
db_drop_primary_key($ret, 'uc_weightquote_products');
db_add_field($ret, 'uc_weightquote_products', 'mid', array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
), array(
'primary key' => array(
'vid',
'mid',
),
));
db_create_table($ret, 'uc_weightquote_methods', array(
'fields' => array(
'mid' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'title' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'label' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'base_rate' => array(
'type' => 'numeric',
'precision' => 15,
'scale' => 3,
'not null' => TRUE,
'default' => 0.0,
),
'product_rate' => array(
'type' => 'numeric',
'precision' => 15,
'scale' => 3,
'not null' => TRUE,
'default' => 0.0,
),
),
'primary key' => array(
'mid',
),
));
$enabled = variable_get('uc_quote_enabled', array());
$weight = variable_get('uc_quote_method_weight', array());
$base_rate = variable_get('uc_weightquote_base_rate', 0);
$product_rate = variable_get('uc_weightquote_product_default', 0);
$ret[] = update_sql("INSERT INTO {uc_weightquote_methods} (title, label, base_rate, product_rate) VALUES ('" . t('Weight rate per product') . "', '" . t('Shipping') . "', " . $base_rate . ", " . $product_rate . ")");
$mid = db_last_insert_id('uc_weightquote_methods', 'mid');
$ret[] = update_sql("UPDATE {uc_weightquote_products} SET mid = " . $mid);
if (isset($enabled['weightquote'])) {
$enabled['weightquote_' . $mid] = $enabled['weightquote'];
}
if (isset($weight['weightquote'])) {
$weight['weightquote_' . $mid] = $weight['weightquote'];
}
unset($enabled['weightquote'], $weight['weightquote']);
variable_set('uc_quote_enabled', $enabled);
variable_set('uc_quote_method_weight', $weight);
variable_del('uc_weightquote_base_rate');
variable_del('uc_weightquote_product_default');
if (db_table_exists('ca_predicates') && ($predicate = db_fetch_object(db_query("SELECT ca_trigger, actions FROM {ca_predicates} WHERE pid = '%s'", 'uc_weightquote_get_quote')))) {
$predicate->pid = 'uc_weightquote_get_quote_' . $mid;
$predicate->actions = unserialize($predicate->actions);
$predicate->ca_trigger = 'get_quote_from_weightquote_' . $mid;
$result = db_query("UPDATE {ca_predicates} SET pid = '%s', ca_trigger = '%s', actions = '%s' WHERE pid = 'uc_weightquote_get_quote'", $predicate->pid, $predicate->ca_trigger, serialize($predicate->actions));
$ret[] = array(
'success' => TRUE,
'query' => check_plain("UPDATE {ca_predicates} SET pid = '" . $predicate->pid . "', ca_trigger = '" . $predicate->ca_trigger . "', actions = '" . serialize($predicate->actions) . "' WHERE pid = 'uc_weightquote_get_quote'"),
);
}
return $ret;
}