You are here

uc_shipping_zones.module in Ubercart Global Quote 6

Same filename and directory in other branches
  1. 7 uc_shipping_zones/uc_shipping_zones.module

Provides zone definitions for uc_global_quote

File

uc_shipping_zones/uc_shipping_zones.module
View source
<?php

/**
 * @file
 * Provides zone definitions for uc_global_quote
 */

/**
 * Implementation of hook_menu().
 */
function uc_shipping_zones_menu() {
  $items = array();
  $items['admin/store/settings/quotes/methods/zones'] = array(
    'title' => 'Shipping zones',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'uc_shipping_zones_admin',
      6,
    ),
    'access arguments' => array(
      'configure quotes',
    ),
    'type' => MENU_LOCAL_TASK,
    'file' => 'uc_shipping_zones_admin.inc',
  );
  return $items;
}

/**
 * Implementation of hook_theme().
 */
function uc_shipping_zones_theme($form) {
  return array(
    'uc_shipping_zones_admin' => array(
      'arguments' => array(
        'form' => NULL,
        'zid' => NULL,
      ),
      'file' => 'uc_shipping_zones_admin.inc',
    ),
  );
}

/**
 * Get shipping zones
 *
 * @param $country
 * country name or code (optional)
 *
 * @return
 * an array containing the shipping zones.
 */
function uc_shipping_zones_get($country = NULL, $region = NULL) {
  if (!$country) {
    $r = db_query("SELECT * FROM {uc_shipping_zones} ORDER BY name");
  }
  else {
    if (is_int($country)) {
      $c->name = uc_country_get_by_id($country);
      $c->id = $country;
    }
    else {
      $c->name = $country;
      $c->id = db_result(db_query("SELECT country_name FROM {uc_countries} WHERE country_name = '%s'", $country));
    }
    if (is_int($region)) {
      $r->name = uc_zone_get_by_id($region);
      $r->id = $region;
    }
    else {
      $r->name = $region;
      $r->id = db_result(db_query("SELECT zone_name FROM {uc_zones} WHERE zone_name = '%s'", $region));
    }

    // Willcard countries without regions
    if ($region < 1 && !db_result(db_query("SELECT zone_id FROM {uc_zones} WHERE zone_country_id = %d", $c->id))) {
      $row = db_query("SELECT * FROM {uc_shipping_zones} WHERE countries LIKE '%%%s%%'", $c->name . ',' . $c->id);
    }
    else {
      $row = db_query("SELECT * FROM {uc_shipping_zones} WHERE countries LIKE '%%%s%%' AND (regions LIKE '%%%s%%' OR (regions IS NULL OR regions = '')) ORDER BY name", $c->name . ',' . $c->id, $r->name . ',' . $r->id);
    }
    return db_fetch_object($row);
  }
  $rows = array();
  while ($row = db_fetch_object($r)) {
    $rows[] = $row;
  }
  return $rows;
}

/**
 * Returns shipping zones ready to feed a selectbox
 */
function uc_shipping_zones_get_select() {
  $rows = array();
  $r = db_query("SELECT zid,name FROM {uc_shipping_zones} ORDER BY name");
  while ($row = db_fetch_object($r)) {
    $rows[$row->zid] = $row->name;
  }
  return $rows;
}

Functions

Namesort descending Description
uc_shipping_zones_get Get shipping zones
uc_shipping_zones_get_select Returns shipping zones ready to feed a selectbox
uc_shipping_zones_menu Implementation of hook_menu().
uc_shipping_zones_theme Implementation of hook_theme().