<?php

class ShippingAreaHelper { 
	public static function get_shipping_area_by_country_id($country_id,$customer_group_id = false) {
		$db = Registry::get('base')->db;

		$sql = "SELECT shipping_area_id 
				FROM countries
				WHERE id=".$db->real_escape_string($country_id);

		$result = $db->query($sql);

		$shipping_area_id = false;
		if ($result->num_rows > 0) {
			$shipping_area_id = $result->fetch_object()->shipping_area_id;
		}

		if ($customer_group_id) {
			$sql = "SELECT * FROM country_customergroup_shippingarea
				WHERE country_id = $country_id AND customer_group_id = $customer_group_id";
			$result = $db->query($sql);
			if ($result->num_rows > 0) {
				$shipping_area_id = $result->fetch_object()->shipping_area_id;
			}
		}

		return $shipping_area_id;

	}
}