Author Topic: Update of Standard Shipping Module  (Read 24502 times)

laurie_lewis

  • Jr. Member
  • **
  • Posts: 211
Update of Standard Shipping Module
« on: May 22, 2006, 13:16:55 pm »
This request is driven by my need but also could be incorporated into the standard shipping module giving it greater flexibility.  I put this in acknowledging that I am no code wizard just someone trying to understand how it goes.

At this time the standard shipping module does not give users the ability to cope with delivery systems where there is:-
1>   a minimum cost associated with the shipping
2>   a costing system that is structured on a base cost and then a costing per kg/lbs

Aarondwyer has created a module for an Australian Courier company that does this for one company.  It requires a modification to the shipping_rate table adding one more row and using other rows not for their original purpose.  This stops you being able to add your own packaging costs to the shipping price.  Aaron's module can be seen here.
http://websmartcentral.com/downloads/TollAustraliaShippingModule.zip

Aaron in his module adds one more row to the shipping rate table but I would suggest two, one for the base rate if it exists and one for the minimum cost if it exists
Code: [Select]
ALTER TABLE `jos_vm_shipping_rate` ADD `shipping_rate_minimum_cost` DECIMAL( 10, 2 ) DEFAULT '0.00' NOT NULL AFTER `shipping_rate_weight_end` ;
ALTER TABLE `jos_vm_shipping_rate` ADD `shipping_rate_base_rate` DECIMAL( 10, 2 ) DEFAULT '0.00' NOT NULL AFTER `shipping_rate_minimum_cost` ;

If there is no base rate or minimum cost they could just be left at their default "0" and the shipping module should work as it currently is.

He also indicates a number of other files that need to be changed that I am just not up to speed with.  I was hoping that someone with greater programming experience could take aarons original work and incorporate it into the standard module??

Any takers ----please.

Laurie

laurie_lewis

  • Jr. Member
  • **
  • Posts: 211
Re: Update of Standard Shipping Module
« Reply #1 on: May 22, 2006, 15:49:09 pm »
Message Updated by Laurie 31/5/2006


I think I have got this working now.  It is based on the standard shipping module and work done by Aaron Dwyer for the Toll Australia Courier. 

The module works this way:

Shipper has a minimum cost that they charge.  This will default to 0 if nothing entered.

Shipping costs are made up of ((base cost + (weight cost * weight) + packaging) ) + TAX

This can be altered in the code just by changing the order of a few things - explain further on.


The shipping module requires some alteration of other code used  -  BUT PLEASE TEST AS I AM NEW AT THIS.

I will explain what I have done but I have attached copies of all the files mentioned in one zip file.  The English language file has been australianised  ;D

Here goes

Step #1 - Analyzing requirements

This contribution requires:
•   VirtueMart v1.05

Step #2 - Backup files

Make a backup of the files that are going to be changed:
•   /administrator/components/com_virtuemart/classes/ps_shipping.php
•   /administrator/components/com_virtuemart/html/shipping.rate_form.php
•   /administrator/components/com_virtuemart/html/shipping.rate_list.php
•   /administrator/components/com_virtuemart/languages/english.php

and

        Don't forget to backup your database as well.

Step #3 - Start editing your files

The bits to add are wrapped in these tags

Code: [Select]
// ###### Begin Added To Standard Shipping Module ######
   code that is added
// ###### End Added To Standard Shipping Module ######

The code bits before and after the tags are there to help you locate where to put them.

Step #4 - Add extra columns into shipping rate table in the database

You will need to use phpMyAdmin or whatever you use to edit your database and insert this SQL to add the extra rows.  The rows hold data for the minimum cost associated with a shipped and their base charge.

Code: [Select]
ALTER TABLE `jos_vm_shipping_rate` ADD `shipping_rate_minimum_cost` DECIMAL( 10, 2 ) DEFAULT '0.00' NOT NULL AFTER `shipping_rate_weight_end` ;
ALTER TABLE `jos_vm_shipping_rate` ADD `shipping_rate_base_cost` DECIMAL( 10, 2 ) DEFAULT '0.00' NOT NULL AFTER `shipping_rate_minimum_cost` ;

Step #5 - In /administrator/components/com_virtuemart/html/shipping.rate_form.php

This code changes the form used to enter data in the shipping rates screen placing two additional fields asking for minimum cost and base cost figures.  These rows were added to the database in the previous step.

locate within the file and add the commented text

Code: [Select]
<input type="text" class="inputbox" name="shipping_rate_weight_end" size="32" maxlength="255" value="<?php $db->sp("shipping_rate_weight_end"?>">
</td>
</tr>

// ###### Begin Added To Standard Shipping Module ######
<tr>
<td width="21%" ><div align="right"><strong><?php echo $VM_LANG->_PHPSHOP_RATE_FORM_MIMIMUM_COST ?>:</strong></div></td>
<td width="79%" >
<input type="text" class="inputbox" name="shipping_rate_minimum_cost" size="32" maxlength="255" value="<?php $db->sp("shipping_rate_minimum_cost"?>">
</td>
</tr>
<tr>
<td width="21%" ><div align="right"><strong><?php echo $VM_LANG->_PHPSHOP_RATE_FORM_BASE_COST ?>:</strong></div></td>
<td width="79%" >
<input type="text" class="inputbox" name="shipping_rate_base_cost" size="32" maxlength="255" value="<?php $db->sp("shipping_rate_base_cost"?>">
</td>
</tr>
// ###### End Added To Standard Shipping Module ######

<tr>
<td width="21%" ><div align="right"><strong><?php echo $VM_LANG->_PHPSHOP_RATE_FORM_VALUE ?>:</strong></div></td>


Step #6 - In /administrator/components/com_virtuemart/languages/english.php


This adds the text for the two new fields created , (minimum cost and error costs).  I previously put in error messages but have removed these so they default to 0 if not entered.

locate within the file and add the commented text

Code: [Select]
var $_PHPSHOP_RATE_FORM_VALUE = 'Fee';
var $_PHPSHOP_RATE_FORM_PACKAGE_FEE = 'Your package fee';

// ###### Begin Added To Standardll Shipping ######
var $_PHPSHOP_RATE_FORM_MINIMUM_COST = 'Minimum shipping fee';
        var $_PHPSHOP_RATE_FORM_BASE_COST = 'Base shipping fee';
// ###### End Added To Standard Shipping #######

var $_PHPSHOP_RATE_FORM_CURRENCY = 'Currency';
var $_PHPSHOP_RATE_FORM_VAT_ID = 'VAT Id';
var $_PHPSHOP_RATE_FORM_LIST_ORDER = 'List Order';
var $_PHPSHOP_SHIPPING_RATE_LIST_CARRIER_LBL = 'Shipper';
var $_PHPSHOP_SHIPPING_RATE_LIST_RATE_NAME = 'Shipping Rate description';

// ####### Begin Added To Standard Shipping ###########
var $_PHPSHOP_SHIPPING_RATE_LIST_RATE_ZIP_START = 'Post Code Start';
var $_PHPSHOP_SHIPPING_RATE_LIST_RATE_ZIP_END = 'Post Code End';
// ######## End Added To Standard Shipping ########

var $_PHPSHOP_SHIPPING_RATE_LIST_RATE_WSTART = 'Weight from ...';
var $_PHPSHOP_SHIPPING_RATE_LIST_RATE_WEND = '... to';
var $_PHPSHOP_CARRIER_FORM_NAME = 'Shipper Company';
   
 
Step #7 - In /administrator/components/com_virtuemart/html/shipping.rate_list.php

This file changes how the data is displayed in the shipping rate list.  The first change - changes the titles displayed and the second the data that is displayed.  It is changing the list from being viewed by weights to postcodes. 

I believe that this will interfere with the standard shipping module but I am not sure how I can alter it so it does not.

locate within the file and add the commented text

Code: [Select]
$columns = Array(  "#" => "width=\"20\"",
"<input type=\"checkbox\" name=\"toggle\" value=\"\" onclick=\"checkAll(".$num_rows.")\" />" => "width=\"20\"",
$VM_LANG->_PHPSHOP_SHIPPING_RATE_LIST_CARRIER_LBL => '',
$VM_LANG->_PHPSHOP_SHIPPING_RATE_LIST_RATE_NAME => '',
// #################### Begin Added Toll Shipping ######################
$VM_LANG->_PHPSHOP_SHIPPING_RATE_LIST_RATE_ZIP_START => '',
$VM_LANG->_PHPSHOP_SHIPPING_RATE_LIST_RATE_ZIP_END => '',
// $VM_LANG->_PHPSHOP_SHIPPING_RATE_LIST_RATE_WSTART => '',
// $VM_LANG->_PHPSHOP_SHIPPING_RATE_LIST_RATE_WEND => '',
// #################### End Added Toll Shipping ######################
_E_REMOVE => "width=\"5%\""
);
$listObj->writeTableHeader( $columns );

$db->query($list);
$i = 0;
   
then

Code: [Select]
$url = $_SERVER['PHP_SELF'] . "?page=$modulename.rate_form&limitstart=$limitstart&keyword=$keyword&shipping_rate_id=". $db->f("shipping_rate_id");
$tmp_cell = "<a href=\"" . $sess->url($url) . "\">". $db->f("shipping_rate_name")."</a>";

$listObj->addCell( $tmp_cell );
// #################### Begin Added Toll Shipping ######################
$listObj->addCell( $db->f("shipping_rate_zip_start"));
$listObj->addCell( $db->f("shipping_rate_zip_end"));
// $listObj->addCell( $db->f("shipping_rate_weight_start"));
// $listObj->addCell( $db->f("shipping_rate_weight_end"));
// #################### End Added Toll Shipping ######################

$listObj->addCell( $ps_html->deleteButton( "shipping_rate_id", $db->f("shipping_rate_id"), "rateDelete", $keyword, $limitstart ) );

$i++;


Step #8 - In /administrator/components/com_virtuemart/classes/ps_shipping.php

Put in error mesages if minimum and base costs missing
locate within the file and add the commented text

Code: [Select]
if ($d["shipping_rate_value"] == "") {
      $d["error"] = $VM_LANG->_PHPSHOP_ERR_MSG_RATE_WEIGHT_VALUE_REQ;
      return False;
    }

// ####### Begin Added To Standard Shipping ########
     if ($d["shipping_rate_minimum_cost"] == "") {
       $d["shipping_rate_minimum_cost"] = '0';
    }
      if ($d["shipping_rate_base_cost"] == "") {
       $d["shipping_rate_base_cost"] = '0';
    }
// ####### End Added To Standard Shipping ########


    if ($d["shipping_rate_package_fee"] == "") {
      $d["shipping_rate_package_fee"] = '0';
    }

then in the same file replace the the rate_add() function with this one

Code: [Select]
/**************************************************************************
   * name: rate_add()
   * created by: Ekkehard Domning
   * description: creates a new rate entry
   * parameters:
   * returns:
   **************************************************************************/
  function rate_add(&$d) {
    $db = new ps_DB;
    $timestamp = time();

    if (!$this->validate_rate_add($d)) {
      return False;
    }

    $q = "INSERT INTO #__{vm}_shipping_rate ";
    $q .= "(shipping_rate_name,shipping_rate_carrier_id,shipping_rate_country,";
    $q .= "shipping_rate_zip_start,shipping_rate_zip_end,shipping_rate_weight_start,";
    $q .= "shipping_rate_weight_end,";
$q .= "shipping_rate_minimum_cost,shipping_rate_base_cost,";
    $q .= "shipping_rate_value,shipping_rate_package_fee,";
    $q .= "shipping_rate_currency_id,shipping_rate_vat_id,shipping_rate_list_order)";

    $q .= "VALUES ('";
    $q .= $d["shipping_rate_name"] . "','";
    $q .= $d["shipping_rate_carrier_id"] . "','";
    $src_str = "";
    if(!empty($d["shipping_rate_country"])) {
      for($i=0;$i<count($d["shipping_rate_country"]);$i++){
        if ($d["shipping_rate_country"][$i] != "") {
          $src_str .= $d["shipping_rate_country"][$i] . ";";
        }
      }
      chop($src_str,";");
    }
    $q .= "$src_str','";
    $q .= $d["shipping_rate_zip_start"] . "','";
    $q .= $d["shipping_rate_zip_end"] . "','";
    $q .= $d["shipping_rate_weight_start"] . "','";
    $q .= $d["shipping_rate_weight_end"] . "','";
//  Added for two new fields added
    $q .= $d["shipping_rate_minimum_cost"] . "','";
$q .= $d["shipping_rate_base_cost"] . "','";
//  End of additions
    $q .= $d["shipping_rate_value"] . "','";
    $q .= $d["shipping_rate_package_fee"] . "','";
    $q .= $d["shipping_rate_currency_id"] . "','";
    $q .= $d["shipping_rate_vat_id"] . "','";
    $q .= $d["shipping_rate_list_order"] . "')";
    $db->query($q);
    $db->next_record();
    return True;
  }


then add this code int the rate_update section

Code: [Select]
    $q .= "shipping_rate_weight_start='" . $d["shipping_rate_weight_start"] . "',";
    $q .= "shipping_rate_weight_end='" . $d["shipping_rate_weight_end"] . "',";
// #########  New lines added for new fields added
   $q .= "shipping_rate_minimum_cost='" . $d["shipping_rate_minimum_cost"] . "',";
   $q .= "shipping_rate_base_cost='" . $d["shipping_rate_base_cost"] . "',";
//  ######### End of additons
    $q .= "shipping_rate_value='" . $d["shipping_rate_value"] . "',";
    $q .= "shipping_rate_package_fee='" . $d["shipping_rate_package_fee"] . "',";


Step #9 - Copy new shipping files into /administrator/components/com_virtuemart/classes/shipping

Locate the files that were in the ZIP file:

    * Australian_Couriers.php
    * Australian_Couriers.ini

and copy them into the shipping directory.


Now in the aus_couriers.php file you will find the following code

Code: [Select]
// #################### Begin Added Toll Shipping ######################
$total_shipping_handling = ($d["weight"]*$dbr->f("shipping_rate_value")) + $dbr->f("shipping_rate_base_cost");

//Check for total shipping is more than the minimum, if not charge the minimum
if ( $total_shipping_handling < $dbr->f("shipping_rate_minimum_cost") ) {
$total_shipping_handling = $dbr->f("shipping_rate_minimum_cost");
}

$total_shipping_handling = $total_shipping_handling + $dbr->f("shipping_rate_package_fee");

// #################### End Added Toll Shipping ######################
$total_shipping_handling *= $taxrate;

You can see that you can rearrange or configure the total cost that is calculated by rearranging things so the packaging fee is added before tax or after tax, where your minimum cost for postage is confirmed - etc etc etc Just how you need it.

Hope this helps and if you find any problems let me know.

I have to repeat I am new at this so test test test before using on a production system
l
Laurie
Code: [Select]

[attachment cleanup by admin]

laurie_lewis

  • Jr. Member
  • **
  • Posts: 211
Re: Update of Standard Shipping Module
« Reply #2 on: June 01, 2006, 01:48:11 am »

If you just need to have a shipping rate that is based on (weight * weight per unit cost) then I think you could do the following

Remember to backup before doing anything else.

In the standard_shipping module find this code

Code: [Select]
$total_shipping_handling = $dbr->f("shipping_rate_value") + $dbr->f("shipping_rate_package_fee");
replace it with

Code: [Select]
$total_shipping_handling = ($d["weight"]*$dbr->f("shipping_rate_value")) + $dbr->f("shipping_rate_base_cost") + $dbr->f("shipping_rate_package_fee");
While there, you could also change whether the packaging fee is added at this time or after tax etc.

This will not require any database changes or other changes in the code.  If you wanted to use this variation and the original standard shipping rates then simply copy the standard_shipping   PHP and INI files to another name - edit them both with the new name you have given them and put them in the shipping directory and then you have both systems available to you.

I HAVE NOT TESTED this but believe it would work very simply.

Laurie

laurie_lewis

  • Jr. Member
  • **
  • Posts: 211
Re: Update of Standard Shipping Module
« Reply #3 on: June 04, 2006, 05:21:57 am »
These are the postcode areas for Australian air Express as used in the database configuration explained above.

Laurie

[attachment cleanup by admin]

hanhand

  • Beginner
  • *
  • Posts: 21
Re: Update of Standard Shipping Module
« Reply #4 on: June 05, 2006, 15:53:11 pm »
Hello laurie_lewi
It seems that you are a good coder and what you are doing. i have a question amybe you can help me in solving my problem.

Actually I am using 2 shipping methods Flex shipping module and the standard shipping module and I have 2 groups of shoppers, individuals and retailers so I want each shipping module to be accessible for each group, What I mean is that, when a shopper status is an individual then he will get the Flex shipping module, and if the shopper status is a retailer then the standard shipping module will be available for him.

I think that placing a code such as $my->id = 1 OR $my->id > 1 in the shipping modules files or maybe in the checkput.index.php will solve the problem but i cannot figure out how and where to do it.

Any help is appreciated

laurie_lewis

  • Jr. Member
  • **
  • Posts: 211
Re: Update of Standard Shipping Module
« Reply #5 on: June 06, 2006, 05:58:44 am »
I would love to be able to help but I am not a good coder.  I just was fortunate to find somebody's hack and able to modify it some more.

Sorry, I can't even point you in the right direction.  Best of luck

Laurie

fagan

  • Beginner
  • *
  • Posts: 14
Re: Update of Standard Shipping Module
« Reply #6 on: June 11, 2006, 02:57:58 am »
Hi laurie,

If you get this message, can you explain what each coloum represents for when you can input the aussie courier data straight into the database eg...


INSERT INTO `jos_vm_shipping_rate` VALUES (1, 'ABX', 3, 'AUS;', '3689', '3694', 0.000, 500.000, 0.55, 10.25, 16.50, 9, 3, 1);
INSERT INTO `jos_vm_shipping_rate` VALUES (2, 'ABX', 3, 'AUS;', '2640', '2641', 0.000, 500.000, 0.55, 10.25, 16.50, 9, 3, 2);
INSERT INTO `jos_vm_shipping_rate` VALUES (3, 'ABX', 3, 'AUS;', '2708', '2708', 0.000, 500.000, 0.55, 10.25, 16.50, 9, 3, 3);
INSERT INTO `jos_vm_shipping_rate` VALUES (4, 'ADL', 3, 'AUS;', '5000', '5115', 0.000, 500.000, 0.77, 12.20, 16.50, 9, 3, 4);
INSERT INTO `jos_vm_shipping_rate` VALUES (5, 'ADL', 3, 'AUS;', '5125', '5127', 0.000, 500.000, 0.77, 12.20, 16.50, 9, 3, 5);
INSERT INTO `jos_vm_shipping_rate` VALUES (6, 'ADL', 3, 'AUS;', '5158', '5169', 0.000, 500.000, 0.77, 12.20, 16.50, 9, 3, 6);
INSERT INTO `jos_vm_shipping_rate` VALUES (7, 'ADL', 3, 'AUS;', '5810', '5999', 0.000, 500.000, 0.77, 12.20, 16.50, 9, 3, 7);
INSERT INTO `jos_vm_shipping_rate` VALUES (8, 'ASP', 3, 'AUS;', '0870', '0871', 0.000, 500.000, 1.28, 19.10, 16.50, 9, 3, 8);
INSERT INTO `jos_vm_shipping_rate` VALUES (9, 'BNE', 3, 'AUS;', '4000', '4179', 0.000, 500.000, 0.29, 8.80, 16.50, 9, 3, 9);
INSERT INTO `jos_vm_shipping_rate` VALUES (10, 'BNE', 3, 'AUS;', '4205', '4207', 0.000, 500.000, 0.40, 8.80, 16.50, 9, 3, 10);
INSERT INTO `jos_vm_shipping_rate` VALUES (11, 'BNE', 3, 'AUS;', '4300', '4305', 0.000, 500.000, 0.28, 8.80, 16.50, 9, 3, 11);
INSERT INTO `jos_vm_shipping_rate` VALUES (12, 'BNE', 3, 'AUS;', '4500', '4503', 0.000, 500.000, 0.28, 8.80, 16.50, 9, 3, 12);
INSERT INTO `jos_vm_shipping_rate` VALUES (13, 'BRM', 3, 'AUS;', '6725', '6725', 0.000, 500.000, 3.88, 23.00, 16.50, 9, 3, 13);


etc,.............

Alan Woo

  • Beginner
  • *
  • Posts: 8
Re: Update of Standard Shipping Module
« Reply #7 on: August 30, 2007, 07:45:50 am »
many changes required to this to make it work with virtuemart 1.12?

laurie_lewis

  • Jr. Member
  • **
  • Posts: 211
Re: Update of Standard Shipping Module
« Reply #8 on: August 31, 2007, 08:50:35 am »
This is still working for me on the latest version of VM.  I have not tried it on VM1.1 but I have put in a request that it becomes part of the standard shipping module in 1.1  -  not sure if anyone will listen though.


radagast

  • Beginner
  • *
  • Posts: 12
Re: Update of Standard Shipping Module
« Reply #9 on: March 20, 2009, 01:53:04 am »
Working on a version of this for 1.1.3 (and maybe even 1.2)... if i get anywhere i'll start a new thread in the 1.1 forum and post here.

slakalot

  • Beginner
  • *
  • Posts: 27
Re: Update of Standard Shipping Module
« Reply #10 on: September 08, 2009, 13:52:51 pm »
This actually works great for 1.1.3 if you just change the code a little. It's pretty obvious when you go to paste in the code that things need slight changing. Also the language file has moved but the process is the same. It's in shipping I think.
I know it was a while back but thanks so much for providing this, it's saved me a heap of time :-)

porl66

  • Beginner
  • *
  • Posts: 26
Re: Update of Standard Shipping Module
« Reply #11 on: September 18, 2009, 03:03:59 am »
Hi

I've uploaded Laurie's auspost-oseas mod and it works great. However in the confirmation it pulls the file name (or maybe from somewhere else) so the customer is confirming postage with the name auspost-oseas. Can anyone explain how to change this to either just the old name auspost or to write Australia Post?

Thanks

radagast

  • Beginner
  • *
  • Posts: 12
Re: Update of Standard Shipping Module
« Reply #12 on: February 19, 2013, 13:35:13 pm »
I know this is old news, and maybe nobody has need any more...
but i've just installed this into VM 1.2.0
still works (thanks laurie). 
zip file attached.

[attachment cleanup by admin]