internal_name = "flatrate";
$this->name="Flat Rate";
$this->is_external=false;
return true;
}
function getId() {
// return $this->usps_id;
}
function setId($id) {
// $usps_id = $id;
// return true;
}
function getName() {
return $this->name;
}
function getInternalName() {
return $this->internal_name;
}
function getForm() {
$shipping = get_option('flat_rates');
$output = "
" . __('If you do not wish to ship to a particular region, leave the field blank. To offer free shipping to a region, enter 0.', 'wpsc') . " | ";
$output .= "
Base Local | ";
switch(get_option('base_country')) {
case 'NZ':
$output .= "
South Island | $ |
";
$output .= "North Island | $ |
";
break;
case 'US':
$output .= "Continental 48 States | $ |
";
$output .= "All 50 States | $ |
";
break;
default:
$output .= "$ | ";
break;
}
if (get_option('base_country')=='NZ') {
} else {
}
$output.= "Base International |
";
$output .= "North America | $ |
";
$output .= "South America | $ |
";
$output .= "Asia and Pacific | $ |
";
$output .= "Europe | $ |
";
$output .= "Africa | $ |
";
return $output;
}
function submit_form() {
if($_POST['shipping'] != null) {
$shipping = (array)get_option('flat_rates');
$submitted_shipping = (array)$_POST['shipping'];
update_option('flat_rates',array_merge($shipping, $submitted_shipping));
}
return true;
}
function getQuote($for_display = false) {
global $wpdb, $wpsc_cart;
if (isset($_POST['country'])) {
$country = $_POST['country'];
$_SESSION['wpsc_delivery_country'] = $country;
} else {
$country = $_SESSION['wpsc_delivery_country'];
}
if (get_option('base_country') != $country) {
$results = $wpdb->get_var("SELECT `continent` FROM `".WPSC_TABLE_CURRENCY_LIST."` WHERE `isocode` IN('{$country}') LIMIT 1");
$flatrates = get_option('flat_rates');
if ($flatrates != '') {
if($_SESSION['quote_shipping_method'] == $this->internal_name) {
if($_SESSION['quote_shipping_option'] != "Flat Rate") {
$_SESSION['quote_shipping_option'] = null;
}
}
if (strlen($flatrates[$results]) > 0) return array("Flat Rate"=>(float)$flatrates[$results]);
}
} else {
$flatrates = get_option('flat_rates');
$shipping_quotes = array();
switch($country) {
case 'NZ':
if (strlen($flatrates['northisland']) > 0) $shipping_quotes["North Island"] = (float)$flatrates['northisland'];
if (strlen($flatrates['southisland']) > 0) $shipping_quotes["South Island"] = (float)$flatrates['southisland'];
break;
case 'US':
if (strlen($flatrates['continental']) > 0) $shipping_quotes["Continental 48 States"] = (float)$flatrates['continental'];
if (strlen($flatrates['all']) > 0) $shipping_quotes["All 50 States"] = (float)$flatrates['all'];
break;
default:
if (strlen($flatrates['local']) > 0) $shipping_quotes["Local Shipping"] = (float)$flatrates['local']; break;
}
if($_SESSION['quote_shipping_method'] == $this->internal_name) {
$shipping_options = array_keys($shipping_quotes);
if(array_search($_SESSION['quote_shipping_option'], $shipping_options) === false) {
$_SESSION['quote_shipping_option'] = null;
}
}
return $shipping_quotes;
}
}
function get_item_shipping($unit_price, $quantity, $weight, $product_id) {
global $wpdb;
if(is_numeric($product_id) && (get_option('do_not_use_shipping') != 1)) {
$country_code = $_SESSION['wpsc_delivery_country'];
$product_list = $wpdb->get_row("SELECT * FROM `".WPSC_TABLE_PRODUCT_LIST."` WHERE `id`='{$product_id}' LIMIT 1",ARRAY_A);
if($product_list['no_shipping'] == 0) {
//if the item has shipping
//exit("".print_r($country_code,true)."
");
if($country_code == get_option('base_country')) {
$additional_shipping = $product_list['pnp'];
} else {
$additional_shipping = $product_list['international_pnp'];
}
$shipping = $quantity * $additional_shipping;
} else {
//if the item does not have shipping
$shipping = 0;
}
} else {
//if the item is invalid or all items do not have shipping
$shipping = 0;
}
return $shipping;
}
function get_cart_shipping($total_price, $weight) {
return $output;
}
}
$flatrate = new flatrate();
$wpsc_shipping_modules[$flatrate->getInternalName()] = $flatrate;