Skip to content

Instantly share code, notes, and snippets.

Created May 30, 2014 01:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/86838c02028faabfb404 to your computer and use it in GitHub Desktop.
Save anonymous/86838c02028faabfb404 to your computer and use it in GitHub Desktop.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* ExpressionEngine - by EllisLab
*
* @package ExpressionEngine
* @author ExpressionEngine Dev Team
* @copyright Copyright (c) 2003 - 2011, EllisLab, Inc.
* @license http://expressionengine.com/user_guide/license.html
* @link http://expressionengine.com
* @since Version 2.0
* @filesource
*/
// ------------------------------------------------------------------------
/**
* Store Shipping Wine Extension
*
* @package ExpressionEngine
* @subpackage Addons
* @category Extension
* @author Francis Bond
* @link http://francisbond.com
*/
class Store_shipping_wine_ext {
public $settings = array();
public $description = 'Shipping per post code range.';
public $docs_url = '';
public $name = 'Store Shipping Wine';
public $settings_exist = 'n';
public $version = '1.0';
private $EE;
/**
* Constructor
*
* @param mixed Settings array or empty string if none exist.
*/
public function __construct($settings = '')
{
$this->EE =& get_instance();
$this->settings = $settings;
}// ----------------------------------------------------------------------
/**
* Activate Extension
*
* This function enters the extension into the exp_extensions table
*
* @see http://codeigniter.com/user_guide/database/index.html for
* more information on the db class.
*
* @return void
*/
public function activate_extension()
{
// Setup custom settings in this array.
$this->settings = array();
$data = array(
'class' => __CLASS__,
'method' => 'store_order_recalculate_start',
'hook' => 'store_order_recalculate_start',
'settings' => serialize($this->settings),
'version' => $this->version,
'enabled' => 'y'
);
$this->EE->db->insert('extensions', $data);
}
// ----------------------------------------------------------------------
/**
* store_order_recalculate_start
*
* @param
* @return
*/
public function store_order_recalculate_start($order)
{
/**
* Allow multiple extensions to use this hook
* http://ellislab.com/expressionengine/user-guide/development/extensions.html#multiple-extensions-same-hook
*/
if (ee()->extensions->last_call) {
$order = ee()->extensions->last_call;
}
$postcode = $order['shipping_postcode'];
$shipping = array(
'default' => 20.00,
'nsw-metro' => 15.00,
'nsw' => 20.00,
'vic-metro' => 10.00,
'vic' => 20.00,
'qld-metro' => 20.00,
'qld' => 25.00,
'sa-metro' => 20.00,
'sa' => 25.00,
'wa-metro' => 30.00,
'wa' => 45.00,
'tas' => 20.00,
'nt' => 40.00
);
if (
// NSW Metro
// 2600-2609, 2000-2234, 1100-1299
$postcode>=2600 && $postcode<=2609 ||
$postcode>=2000 && $postcode<=2234 ||
$postcode>=1100 && $postcode<=1299
){
$order['order_shipping'] = $shipping['nsw-metro'];
} elseif (
// NSW
// 2610-2620, 2235-2999
$postcode>=2610 && $postcode<=2620 ||
$postcode>=2235 && $postcode<=2999
){
$order['order_shipping'] = $shipping['nsw'];
} elseif (
// VIC Metro
// 3000-3207, 8000-8399
$postcode>=3000 && $postcode<=3207 ||
$postcode>=8000 && $postcode<=8399
){
$order['order_shipping'] = $shipping['vic-metro'];
} elseif (
// VIC
// 3208-3999
$postcode>=3208 && $postcode<=3999
){
$order['order_shipping'] = $shipping['vic'];
} elseif (
// QLD Metro
// 4000-4207, 4300-4305, 4500-4519, 9000-9015
$postcode>=4000 && $postcode<=4207 ||
$postcode>=4300 && $postcode<=4305 ||
$postcode>=4500 && $postcode<=4519 ||
$postcode>=9000 && $postcode<=9015
){
$order['order_shipping'] = $shipping['qld-metro'];
} elseif (
// QLD
// 4208-4299, 4306-4499, 4520-4999, 4550-4575
$postcode>=4208 && $postcode<=4299 ||
$postcode>=4306 && $postcode<=4499 ||
$postcode>=4520 && $postcode<=4999 ||
$postcode>=4550 && $postcode<=4575
){
$order['order_shipping'] = $shipping['qld'];
} elseif (
// SA Metro
// 5000-5199, 5880-5889, 5839, 5810
$postcode>=5000 && $postcode<=5199 ||
$postcode>=5880 && $postcode<=5889 ||
$postcode==5839 ||
$postcode==5810
){
$order['order_shipping'] = $shipping['sa-metro'];
} elseif (
// SA
// 5200-5749, 5825-5838, 5840-5854
$postcode>=5200 && $postcode<=5749 ||
$postcode>=5825 && $postcode<=5838 ||
$postcode>=5840 && $postcode<=5854
){
$order['order_shipping'] = $shipping['sa'];
} elseif (
// WA Metro
// 6000-6199, 6830-6832, 6837-6849
$postcode>=6000 && $postcode<=6199 ||
$postcode>=6830 && $postcode<=6832 ||
$postcode>=6837 && $postcode<=6849
){
$order['order_shipping'] = $shipping['wa-metro'];
} elseif (
// WA
// 6200-6999
$postcode>=6200 && $postcode<=6999
){
$order['order_shipping'] = $shipping['wa'];
} elseif (
// TAS
// 7000-7999
$postcode>=7000 && $postcode<=7999
){
$order['order_shipping'] = $shipping['tas'];
} elseif (
// NT
// 0800-0899
$postcode>=0800 && $postcode<=0899
){
$order['order_shipping'] = $shipping['nt'];
} else {
// Fallback
$order['order_shipping'] = $shipping['default'];
}
if (ee()->extensions->end_script) return $order;
}
// ----------------------------------------------------------------------
/**
* Disable Extension
*
* This method removes information from the exp_extensions table
*
* @return void
*/
function disable_extension()
{
$this->EE->db->where('class', __CLASS__);
$this->EE->db->delete('extensions');
}
// ----------------------------------------------------------------------
/**
* Update Extension
*
* This function performs any necessary db updates when the extension
* page is visited
*
* @return mixed void on update / false if none
*/
function update_extension($current = '')
{
if ($current == '' OR $current == $this->version)
{
return FALSE;
}
}
// ----------------------------------------------------------------------
}
/* End of file ext.store_shipping_wine.php */
/* Location: /system/expressionengine/third_party/store_shipping_wine/ext.store_shipping_wine.php */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment