Created
November 14, 2011 11:57
-
-
Save craigrodway/1363800 to your computer and use it in GitHub Desktop.
GoCart 'Local collection' shipping method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
class collection | |
{ | |
var $CI; | |
function __construct() | |
{ | |
$this->CI =& get_instance(); | |
$this->CI->load->model('Settings_model'); | |
} | |
function rates() | |
{ | |
//rates function should return an array of rates/prices | |
//this is so a UPS function could perhaps return multiple shipping rates | |
//setting up some sort of database setting for this is ok | |
$settings = $this->CI->Settings_model->get_settings('collection'); | |
if($settings['enabled'] && $settings['enabled'] > 0) | |
{ | |
return array('Collection' => 0); | |
} | |
else | |
{ | |
return array(); | |
} | |
} | |
function install() | |
{ | |
//set a default blank setting for collection | |
$this->CI->Settings_model->save_settings('collection', array('rate'=>'')); | |
$this->CI->Settings_model->save_settings('collection', array('enabled'=>'0')); | |
} | |
function uninstall() | |
{ | |
$this->CI->Settings_model->delete_settings('collection'); | |
} | |
function form($post = false) | |
{ | |
//this same function processes the form | |
if(!$post) | |
{ | |
$settings = $this->CI->Settings_model->get_settings('collection'); | |
$rate = 0; | |
$enabled = $settings['enabled']; | |
} | |
else | |
{ | |
$rate = 0; | |
$enabled = $post['enabled']; | |
} | |
$form = '<table> | |
<tr><td>Enabled: </td><td><select name="enabled">'; | |
if($enabled == 1) | |
{ | |
$enable = ' selected="selected"'; | |
$disable = ''; | |
} | |
else | |
{ | |
$enable = ''; | |
$disable = ' selected="selected"'; | |
} | |
$form .= '<option value="1"'.$enable.'>Enabled</option> | |
<option value="0"'.$disable.'>Disabled</option>'; | |
$form .= '</select></td></tr> | |
</table>'; | |
return $form; | |
} | |
function check() | |
{ | |
$error = false; | |
//we save the settings if it gets here | |
$this->CI->Settings_model->save_settings('collection', array( | |
'rate' =>0, | |
'enabled' => $_POST['enabled'] | |
)); | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment