Table Shipping Rates
WARNING:
This will replace the default shipping system, not supplement it!
(it is also a quick and dirty hack, and is to be considered an internal release)
if total weight is less than or equal to 0 then shipping cost is 0 (good for subscriptions, memberships, etc).
if total weight is less than or equal to Weight 1 then shipping cost is Price 1.
if total weight is less than or equal to Weight 2 then shipping cost is Price 2.
etc...
Tested on:
vBulletin 4.1.4 & 4.1.6
MICROCART_114
WARNING:
This will replace the default shipping system, not supplement it!
(it is also a quick and dirty hack, and is to be considered an internal release)
Backup the following before you start!
/admincp/microcart_admin.php
/microcart/functions.php
microcart_zones (SQL table)
open /admincp/microcart_admin.php
find
PHP Code:
////////////////////////////////////////////////////////////////////////////////
//////////////////////////// SHIPPING ZONES & FARES ////////////////////////////
////////////////////////////////////////////////////////////////////////////////
if ($_REQUEST['do'] == 'zones')
{
$zoneid = isset($_REQUEST['zoneid']) ? intval($_REQUEST['zoneid']) : -1;
if($_REQUEST['action'] == "newzone")
{
$zoneid = newZone();
}
if($_REQUEST['action'] == "editzone")
{
editZone($zoneid);
}
if($_REQUEST['action'] == "deletezone")
{
deleteZone($zoneid);
$zoneid = -1;
}
if($_REQUEST['action'] == "save")
{
saveZoneOrder();
}
print_form_header('microcart_admin', 'zones', true);
print_table_header("Shipping Zones", 7);
print_cells_row(array("Zone Name", "B-Weight", "B-Fare", "E-Weight", "E-Fare", "Display", "Actions"), 1, 'tcat');
$zones = $db->query_read("SELECT * FROM ". TABLE_PREFIX ."microcart_zones ORDER BY displayorder ASC");
while($zone = $db->fetch_array($zones)) {
$cell[0] = $zone["name"];
$cell[1] = $zone["baseweight"];
$cell[2] = getFormatPrice($zone["basefare"]);
$cell[3] = $zone["extraweight"];
$cell[4] = getFormatPrice($zone["extrafare"]);
$cell[5] = '<input type="text" class="bginput" size="3" name="display['.$zone["id"].']" value="'.$zone["displayorder"].'">';
$cell[6] = '<select class="bginput" name="action" onChange="ZoneAction(this, '.$zone["id"].')">
<option value="0">Select Action</option>
<option value="1">Edit</option>
<option value="2">Delete</option>
</select>';
print_cells_row($cell);
}
echo '<input type="hidden" name="action" value="save" />';
print_table_footer(7, "<input type=\"submit\" class=\"button\" tabindex=\"1\" value=\" Save Display Order \" accesskey=\"s\" />" . construct_button_code(" Add New Zone ", "microcart_admin.php?do=newzone"));
}
if ($_REQUEST['do'] == 'editzone') {
$zoneid = isset($_REQUEST['zoneid']) ? intval($_REQUEST['zoneid']) : -1;
print_form_header('microcart_admin', 'zones', true);
print_table_header("Edit Zone", 2);
$zones = $db->query_read("SELECT * FROM ". TABLE_PREFIX ."microcart_zones WHERE id=$zoneid");
$zone = $db->fetch_array($zones);
echo '<input type="hidden" name="action" value="editzone" />';
echo '<input type="hidden" name="zoneid" value="'.$zoneid.'" />';
print_input_row("Zone Name", "name", $zone["name"], 30, 50);
print_input_row("Carrier", "carrier", $zone["carrier"], 30, 50);
print_input_row("Delivery Time", "delivery", $zone["delivery"], 30, 50);
print_input_row("Base Weight", "baseweight", $zone["baseweight"], 30, 50);
print_input_row("Base Fare", "basefare", $zone["basefare"], 30, 50);
print_input_row("Extra Weight", "extraweight", $zone["extraweight"], 30, 50);
print_input_row("Extra Fare", "extrafare", $zone["extrafare"], 30, 50);
print_submit_row();
print_table_footer();
}
if ($_REQUEST['do'] == 'newzone') {
print_form_header('microcart_admin', 'zones', true);
print_table_header("New Shipping Zone", 2);
echo '<input type="hidden" name="action" value="newzone" />';
print_input_row("Zone Name", "name", "", 30, 50);
print_input_row("Carrier", "carrier", "", 30, 50);
print_input_row("Delivery Time", "delivery", "", 30, 50);
print_input_row("Base Weight", "baseweight", "", 30, 50);
print_input_row("Base Fare", "basefare", "", 30, 50);
print_input_row("Extra Weight", "extraweight", "", 30, 50);
print_input_row("Extra Fare", "extrafare", "", 30, 50);
print_submit_row();
print_table_footer();
}
///// END OF SHIPPING ZONES & FARES
replace with
PHP Code:
////////////////////////////////////////////////////////////////////////////////
//////////////////////////// SHIPPING ZONES & FARES ////////////////////////////
////////////////////////////////////////////////////////////////////////////////
if ($_REQUEST['do'] == 'zones')
{
$zoneid = isset($_REQUEST['zoneid']) ? intval($_REQUEST['zoneid']) : -1;
if($_REQUEST['action'] == "newzone")
{
$zoneid = newZone();
}
if($_REQUEST['action'] == "editzone")
{
editZone($zoneid);
}
if($_REQUEST['action'] == "deletezone")
{
deleteZone($zoneid);
$zoneid = -1;
}
if($_REQUEST['action'] == "save")
{
saveZoneOrder();
}
print_form_header('microcart_admin', 'zones', true);
print_table_header("Shipping Zones", 13);
print_cells_row(array("Name", "Weight 1", "Price 1", "Weight 2", "Price 2", "Weight 3", "Price 3", "Weight 4", "Price 4", "Weight 5", "Price 5", "Order", "Action"), 1, 'tcat');
$zones = $db->query_read("SELECT * FROM ". TABLE_PREFIX ."microcart_zones ORDER BY displayorder ASC");
while($zone = $db->fetch_array($zones)) {
$cell[0] = $zone["name"];
$cell[1] = $zone["weight1"];
$cell[2] = getFormatPrice($zone["price1"]);
$cell[3] = $zone["weight2"];
$cell[4] = getFormatPrice($zone["price2"]);
$cell[5] = $zone["weight3"];
$cell[6] = getFormatPrice($zone["price3"]);
$cell[7] = $zone["weight4"];
$cell[8] = getFormatPrice($zone["price4"]);
$cell[9] = $zone["weight5"];
$cell[10] = getFormatPrice($zone["price5"]);
$cell[11] = '<input type="text" class="bginput" size="3" name="display['.$zone["id"].']" value="'.$zone["displayorder"].'">';
$cell[12] = '<select class="bginput" name="action" onChange="ZoneAction(this, '.$zone["id"].')">
<option value="0">Choose</option>
<option value="1">Edit</option>
<option value="2">Delete</option>
</select>';
print_cells_row($cell);
}
echo '<input type="hidden" name="action" value="save" />';
print_table_footer(13, "<input type=\"submit\" class=\"button\" tabindex=\"1\" value=\" Save Display Order \" accesskey=\"s\" />" . construct_button_code(" Add New Zone ", "microcart_admin.php?do=newzone"));
}
if ($_REQUEST['do'] == 'editzone') {
$zoneid = isset($_REQUEST['zoneid']) ? intval($_REQUEST['zoneid']) : -1;
print_form_header('microcart_admin', 'zones', true);
print_table_header("Edit Zone", 2);
$zones = $db->query_read("SELECT * FROM ". TABLE_PREFIX ."microcart_zones WHERE id=$zoneid");
$zone = $db->fetch_array($zones);
echo '<input type="hidden" name="action" value="editzone" />';
echo '<input type="hidden" name="zoneid" value="'.$zoneid.'" />';
print_input_row("Name", "name", $zone["name"], 30, 50);
print_input_row("Carrier", "carrier", $zone["carrier"], 30, 50);
print_input_row("Delivery Time", "delivery", $zone["delivery"], 30, 50);
print_input_row("Weight 1", "weight1", $zone["weight1"], 30, 50);
print_input_row("Price 1", "price1", $zone["price1"], 30, 50);
print_input_row("Weight 2", "weight2", $zone["weight2"], 30, 50);
print_input_row("Price 2", "price2", $zone["price2"], 30, 50);
print_input_row("Weight 3", "weight3", $zone["weight3"], 30, 50);
print_input_row("Price 3", "price3", $zone["price3"], 30, 50);
print_input_row("Weight 4", "weight4", $zone["weight4"], 30, 50);
print_input_row("Price 4", "price4", $zone["price4"], 30, 50);
print_input_row("Weight 5", "weight5", $zone["weight5"], 30, 50);
print_input_row("Price 5", "price5", $zone["price5"], 30, 50);
print_submit_row();
print_table_footer();
}
if ($_REQUEST['do'] == 'newzone') {
print_form_header('microcart_admin', 'zones', true);
print_table_header("New Shipping Zone", 2);
echo '<input type="hidden" name="action" value="newzone" />';
print_input_row("Name", "name", "", 30, 50);
print_input_row("Carrier", "carrier", "", 30, 50);
print_input_row("Delivery Time", "delivery", "", 30, 50);
print_input_row("Weight 1", "weight1", "", 30, 50);
print_input_row("Price 1", "price1", "", 30, 50);
print_input_row("Weight 2", "weight2", "", 30, 50);
print_input_row("Price 2", "price2", "", 30, 50);
print_input_row("Weight 3", "weight3", "", 30, 50);
print_input_row("Price 3", "price3", "", 30, 50);
print_input_row("Weight 4", "weight4", "", 30, 50);
print_input_row("Price 4", "price4", "", 30, 50);
print_input_row("Weight 5", "weight5", "", 30, 50);
print_input_row("Price 5", "price5", "", 30, 50);
print_submit_row();
print_table_footer();
}
///// END OF SHIPPING ZONES & FARES
open /microcart/functions.php
find
PHP Code:
function newZone()
{
global $db, $vbulletin;
$vbulletin->input->clean_array_gpc('p', array(
'name' => TYPE_STR,
'carrier' => TYPE_STR,
'delivery' => TYPE_STR,
'baseweight' => TYPE_INT,
'basefare' => TYPE_NUM,
'extraweight' => TYPE_INT,
'extrafare' => TYPE_NUM
));
$name = $db->escape_string($vbulletin->GPC['name']);
$carrier = $db->escape_string($vbulletin->GPC['carrier']);
$delivery = $db->escape_string($vbulletin->GPC['delivery']);
$baseweight = $vbulletin->GPC['baseweight'];
$basefare = $vbulletin->GPC['basefare'];
$extraweight = $vbulletin->GPC['extraweight'];
$extrafare = $vbulletin->GPC['extrafare'];
$displayorder = 0;
$vbulletin->db->query_write("INSERT INTO ". TABLE_PREFIX ."microcart_zones
SET name='$name',
carrier = '$carrier',
delivery = '$delivery',
baseweight = '$baseweight',
basefare = '$basefare',
extraweight = '$extraweight',
extrafare = '$extrafare',
displayorder='$displayorder'");
$vbulletin->db->insert_id();
return;
}
replace with
PHP Code:
function newZone()
{
global $db, $vbulletin;
$vbulletin->input->clean_array_gpc('p', array(
'name' => TYPE_STR,
'carrier' => TYPE_STR,
'delivery' => TYPE_STR,
'weight1' => TYPE_INT,
'price1' => TYPE_NUM,
'weight2' => TYPE_INT,
'price2' => TYPE_NUM,
'weight3' => TYPE_INT,
'price3' => TYPE_NUM,
'weight4' => TYPE_INT,
'price4' => TYPE_NUM,
'weight5' => TYPE_INT,
'price5' => TYPE_NUM
));
$name = $db->escape_string($vbulletin->GPC['name']);
$carrier = $db->escape_string($vbulletin->GPC['carrier']);
$delivery = $db->escape_string($vbulletin->GPC['delivery']);
$weight1 = $vbulletin->GPC['weight1'];
$price1 = $vbulletin->GPC['price1'];
$weight2 = $vbulletin->GPC['weight2'];
$price2 = $vbulletin->GPC['price2'];
$weight3 = $vbulletin->GPC['weight3'];
$price3 = $vbulletin->GPC['price3'];
$weight4 = $vbulletin->GPC['weight4'];
$price4 = $vbulletin->GPC['price4'];
$weight5 = $vbulletin->GPC['weight5'];
$price5 = $vbulletin->GPC['price5'];
$displayorder = 0;
$vbulletin->db->query_write("INSERT INTO ". TABLE_PREFIX ."microcart_zones
SET name='$name',
carrier = '$carrier',
delivery = '$delivery',
weight1 = '$weight1',
price1 = '$price1',
weight2 = '$weight2',
price2 = '$price2',
weight3 = '$weight3',
price3 = '$price3',
weight4 = '$weight4',
price4 = '$price4',
weight5 = '$weight5',
price5 = '$price5',
displayorder='$displayorder'");
$vbulletin->db->insert_id();
return;
}
find
PHP Code:
function editZone($zoneid)
{
global $db, $vbulletin;
$vbulletin->input->clean_array_gpc('p', array(
'name' => TYPE_STR,
'carrier' => TYPE_STR,
'delivery' => TYPE_STR,
'baseweight' => TYPE_INT,
'basefare' => TYPE_NUM,
'extraweight' => TYPE_INT,
'extrafare' => TYPE_NUM
));
$name = $db->escape_string($vbulletin->GPC['name']);
$carrier = $db->escape_string($vbulletin->GPC['carrier']);
$delivery = $db->escape_string($vbulletin->GPC['delivery']);
$baseweight = $vbulletin->GPC['baseweight'];
$basefare = $vbulletin->GPC['basefare'];
$extraweight = $vbulletin->GPC['extraweight'];
$extrafare = $vbulletin->GPC['extrafare'];
$vbulletin->db->query_write("UPDATE ". TABLE_PREFIX ."microcart_zones
SET name='$name',
carrier = '$carrier',
delivery = '$delivery',
baseweight = '$baseweight',
basefare = '$basefare',
extraweight = '$extraweight',
extrafare = '$extrafare' WHERE id=$zoneid");
return;
}
replace with
PHP Code:
function editZone($zoneid)
{
global $db, $vbulletin;
$vbulletin->input->clean_array_gpc('p', array(
'name' => TYPE_STR,
'carrier' => TYPE_STR,
'delivery' => TYPE_STR,
'weight1' => TYPE_INT,
'price1' => TYPE_NUM,
'weight2' => TYPE_INT,
'price2' => TYPE_NUM,
'weight3' => TYPE_INT,
'price3' => TYPE_NUM,
'weight4' => TYPE_INT,
'price4' => TYPE_NUM,
'weight5' => TYPE_INT,
'price5' => TYPE_NUM
));
$name = $db->escape_string($vbulletin->GPC['name']);
$carrier = $db->escape_string($vbulletin->GPC['carrier']);
$delivery = $db->escape_string($vbulletin->GPC['delivery']);
$weight1 = $vbulletin->GPC['weight1'];
$price1 = $vbulletin->GPC['price1'];
$weight2 = $vbulletin->GPC['weight2'];
$price2 = $vbulletin->GPC['price2'];
$weight3 = $vbulletin->GPC['weight3'];
$price3 = $vbulletin->GPC['price3'];
$weight4 = $vbulletin->GPC['weight4'];
$price4 = $vbulletin->GPC['price4'];
$weight5 = $vbulletin->GPC['weight5'];
$price5 = $vbulletin->GPC['price5'];
$vbulletin->db->query_write("UPDATE ". TABLE_PREFIX ."microcart_zones
SET name='$name',
carrier = '$carrier',
delivery = '$delivery',
weight1 = '$weight1',
price1 = '$price1',
weight2 = '$weight2',
price2 = '$price2',
weight3 = '$weight3',
price3 = '$price3',
weight4 = '$weight4',
price4 = '$price4',
weight5 = '$weight5',
price5 = '$price5' WHERE id=$zoneid");
return;
}
Run SQL query (remember to put prefix in front of the table names)
Code:
DROP TABLE IF EXISTS `microcart_zones`;
CREATE TABLE IF NOT EXISTS `microcart_zones` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`name` varchar(250) NOT NULL DEFAULT '',
`displayorder` int(10) NOT NULL DEFAULT '0',
`carrier` varchar(100) DEFAULT '',
`delivery` varchar(100) DEFAULT '',
`weight1` int(10) NOT NULL DEFAULT '0',
`price1` decimal(10,2) NOT NULL DEFAULT '0.00',
`weight2` int(10) NOT NULL DEFAULT '0',
`price2` decimal(10,2) NOT NULL DEFAULT '0.00',
`weight3` int(10) NOT NULL DEFAULT '0',
`price3` decimal(10,2) NOT NULL DEFAULT '0.00',
`weight4` int(10) NOT NULL DEFAULT '0',
`price4` decimal(10,2) NOT NULL DEFAULT '0.00',
`weight5` int(10) NOT NULL DEFAULT '0',
`price5` decimal(10,2) NOT NULL DEFAULT '0.00',
PRIMARY KEY (`id`),
KEY `displayorder` (`displayorder`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;
INSERT INTO `microcart_zones` (`id`, `name`, `displayorder`, `carrier`, `delivery`, `weight1`, `price1`, `weight2`, `price2`, `weight3`, `price3`, `weight4`, `price4`, `weight5`, `price5`) VALUES
(1, 'Zone Name', 0, 'Carrier', 'Delivery Time', 5, 1.00, 10, 2.00, 20, 4, 40, 8.00, 80, 16.00);
WARNING:
This will replace the default shipping system, not supplement it!
(it is also a quick and dirty hack, and is to be considered an internal release)
|