Thread: Major Additions - microCART: Shopping System for vB4
View Single Post
  #633  
Old 10-04-2011, 07:37 AM
JimL JimL is offline
 
Join Date: Sep 2011
Posts: 44
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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"], 3050);
    
print_input_row("Carrier""carrier"$zone["carrier"], 3050);
    
print_input_row("Delivery Time""delivery"$zone["delivery"], 3050);
    
print_input_row("Base Weight""baseweight"$zone["baseweight"], 3050);
    
print_input_row("Base Fare""basefare"$zone["basefare"], 3050);
    
print_input_row("Extra Weight""extraweight"$zone["extraweight"], 3050);
    
print_input_row("Extra Fare""extrafare"$zone["extrafare"], 3050);
    
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"""3050);
    
print_input_row("Carrier""carrier"""3050);
    
print_input_row("Delivery Time""delivery"""3050);
    
print_input_row("Base Weight""baseweight"""3050);
    
print_input_row("Base Fare""basefare"""3050);
    
print_input_row("Extra Weight""extraweight"""3050);
    
print_input_row("Extra Fare""extrafare"""3050);
    
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"], 3050);
    
print_input_row("Carrier""carrier"$zone["carrier"], 3050);
    
print_input_row("Delivery Time""delivery"$zone["delivery"], 3050);
    
print_input_row("Weight 1""weight1"$zone["weight1"], 3050);
    
print_input_row("Price 1""price1"$zone["price1"], 3050);
    
print_input_row("Weight 2""weight2"$zone["weight2"], 3050);
    
print_input_row("Price 2""price2"$zone["price2"], 3050);
    
print_input_row("Weight 3""weight3"$zone["weight3"], 3050);
    
print_input_row("Price 3""price3"$zone["price3"], 3050);
    
print_input_row("Weight 4""weight4"$zone["weight4"], 3050);
    
print_input_row("Price 4""price4"$zone["price4"], 3050);
    
print_input_row("Weight 5""weight5"$zone["weight5"], 3050);
    
print_input_row("Price 5""price5"$zone["price5"], 3050);
    
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"""3050);
    
print_input_row("Carrier""carrier"""3050);
    
print_input_row("Delivery Time""delivery"""3050);
    
print_input_row("Weight 1""weight1"""3050);
    
print_input_row("Price 1""price1"""3050);
    
print_input_row("Weight 2""weight2"""3050);
    
print_input_row("Price 2""price2"""3050);
    
print_input_row("Weight 3""weight3"""3050);
    
print_input_row("Price 3""price3"""3050);
    
print_input_row("Weight 4""weight4"""3050);
    
print_input_row("Price 4""price4"""3050);
    
print_input_row("Weight 5""weight5"""3050);
    
print_input_row("Price 5""price5"""3050);
    
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)
Attached Files
File Type: (21.4 KB, 212 views)
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01485 seconds
  • Memory Usage 2,161KB
  • Queries Executed 12 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code
  • (6)bbcode_php
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_attachment
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_attachment
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete