function uc_fedex_update_6201 in FedEx Shipping 7.2
Same name and namespace in other branches
- 6.2 uc_fedex.install \uc_fedex_update_6201()
Implements hook_update_N().
Refactor uc_fedex shipping method into three separate methods: Ground, Express, and Freight. Ensure that service selections are transferred from the old method to the new methods. If FedEx was enabled at admin/store/settings/quotes/methods, figure out which of the new methods should be enabled based on the service selections.
File
- ./
uc_fedex.install, line 134 - Install, update, and uninstall functions for the uc_fedex module.
Code
function uc_fedex_update_6201() {
$ret = array();
$services = variable_get('uc_fedex_services', NULL);
if (isset($services)) {
$ground_services = array();
$freight_services = array();
// Remove ground services from list of services.
if (isset($services['FEDEX_GROUND'])) {
$ground_services['FEDEX_GROUND'] = $services['FEDEX_GROUND'];
unset($services['FEDEX_GROUND']);
}
if (isset($services['GROUND_HOME_DELIVERY'])) {
$ground_services['GROUND_HOME_DELIVERY'] = $services['GROUND_HOME_DELIVERY'];
unset($services['GROUND_HOME_DELIVERY']);
}
// Remove freight services from list of services.
if (isset($services['FEDEX_1_DAY_FREIGHT'])) {
$freight_services['FEDEX_1_DAY_FREIGHT'] = $services['FEDEX_1_DAY_FREIGHT'];
unset($services['FEDEX_1_DAY_FREIGHT']);
}
if (isset($services['FEDEX_2_DAY_FREIGHT'])) {
$freight_services['FEDEX_2_DAY_FREIGHT'] = $services['FEDEX_2_DAY_FREIGHT'];
unset($services['FEDEX_2_DAY_FREIGHT']);
}
if (isset($services['FEDEX_3_DAY_FREIGHT'])) {
$freight_services['FEDEX_3_DAY_FREIGHT'] = $services['FEDEX_3_DAY_FREIGHT'];
unset($services['FEDEX_3_DAY_FREIGHT']);
}
if (isset($services['INTERNATIONAL_ECONOMY_FREIGHT'])) {
$freight_services['INTERNATIONAL_ECONOMY_FREIGHT'] = $services['INTERNATIONAL_ECONOMY_FREIGHT'];
unset($services['INTERNATIONAL_ECONOMY_FREIGHT']);
}
if (isset($services['INTERNATIONAL_PRIORITY_FREIGHT'])) {
$freight_services['INTERNATIONAL_PRIORITY_FREIGHT'] = $services['INTERNATIONAL_PRIORITY_FREIGHT'];
unset($services['INTERNATIONAL_PRIORITY_FREIGHT']);
}
if (isset($services['INTERNATIONAL_DISTRIBUTION_FREIGHT'])) {
$freight_services['INTERNATIONAL_DISTRIBUTION_FREIGHT'] = $services['INTERNATIONAL_DISTRIBUTION_FREIGHT'];
unset($services['INTERNATIONAL_DISTRIBUTUION_FREIGHT']);
}
// Create new variables with services separated out.
variable_set('uc_fedex_ground_services', $ground_services);
variable_set('uc_fedex_express_services', $services);
variable_set('uc_fedex_freight_services', $freight_services);
variable_del('uc_fedex_services', $services);
// If FedEx quotes are enabled, figure out which services are
// being used and make sure the correct new methods are enabled.
$enabled = variable_get('uc_quote_enabled', array());
if ($enabled['fedex']) {
if (count($ground_services)) {
$enabled['fedex_ground'] = TRUE;
}
if (count($services) == 0) {
$enabled['fedex'] = FALSE;
}
if (count($freight_services)) {
$enabled['fedex_freight'] = TRUE;
}
variable_set('uc_quote_enabled', $enabled);
}
}
return $ret;
}