I had a bash at this myself thought I post the changes which actually were not overly drastic!
First off thanks to this thread for getting me started with adding the new fields items to the shipping rates!:
http://forum.virtuemart.net/index.php?topic=18592.0Changes mades (on VirtueMart 1.0.15):
Run this SQL statment on your database, update the table names to match yours!
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_maximum_cost` DECIMAL( 10, 2 ) DEFAULT '0.00' NOT NULL AFTER `shipping_rate_minimum_cost` ;
com_virtuemart\languages\english.php
This add the two bits of new text to the language file:
Add these two lines to the end of the the list:
var $_PHPSHOP_RATE_FORM_MINIMUM_COST = 'Minimum shipping fee';
var $_PHPSHOP_RATE_FORM_MAXIMUM_COST = 'Maximum shipping fee';
BEFORE: }
class phpShopLanguage extends vmLanguage { }
-------------------------------------
com_virtuemart\html\shipping.rate_list.php
This add the from/to amounts to the shipping rate lists page:
After the line $VM_LANG->_PHPSHOP_SHIPPING_RATE_LIST_RATE_WEND => '',
Add:
$VM_LANG->_PHPSHOP_RATE_FORM_MINIMUM_COST => '',//added
$VM_LANG->_PHPSHOP_RATE_FORM_MAXIMUM_COST => '',//added
Further down after:
$listObj->addCell( $db->f("shipping_rate_weight_start"));
$listObj->addCell( $db->f("shipping_rate_weight_end"));
Add:
$listObj->addCell( $db->f("shipping_rate_minimum_cost")); //weight OUT cost IN
$listObj->addCell( $db->f("shipping_rate_maximum_cost")); //weight OUT cost IN
-------------------------------------
com_virtuemart\html\shipping.rate_form.php
This added the input text boxes when you add or edit a shipping rate
After:
<tr>
<td width="21%" ><div align="right"><strong><?php echo $VM_LANG->_PHPSHOP_RATE_FORM_PACKAGE_FEE ?>:</strong></div></td>
<td width="79%" >
<input type="text" class="inputbox" name="shipping_rate_package_fee" size="32" maxlength="255" value="<?php $db->sp("shipping_rate_package_fee") ?>">
</td>
</tr>
Add:
<!-- // Added To Standard Shipping Module ######--->
<tr>
<td width="21%" ><div align="right"><strong><?php echo $VM_LANG->_PHPSHOP_RATE_FORM_MINIMUM_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_MAXIMUM_COST ?>:</strong></div></td>
<td width="79%" >
<input type="text" class="inputbox" name="shipping_rate_maximum_cost" size="32" maxlength="255" value="<?php $db->sp("shipping_rate_maximum_cost") ?>">
</td>
</tr>
<!--// Added To Standard Shipping Module ######-->
-------------------------------------
com_virtuemart\classes\ps_shipping.php
This set of changes means that it saves the value when you create a new rate or edit an existing rate
In the
/**************************************************************************
* name: rate_add()
* created by: Ekkehard Domning
* description: creates a new rate entry
* parameters:
* returns:
**************************************************************************/
Section after:
$q .= $d["shipping_rate_weight_end"] . "','";
Add:
$q .= $d["shipping_rate_minimum_cost"] . "','"; //added
$q .= $d["shipping_rate_maximum_cost"] . "','"; //added
Secondly in the:
/**************************************************************************
* name: rate_update()
* created by: Ekkehard Domning
* description: updates a rate entry
* parameters:
* returns:
**************************************************************************/
Section after:
$q .= "shipping_rate_weight_end='" . $d["shipping_rate_weight_end"] . "',";
Add:
$q .= "shipping_rate_minimum_cost='" . $d["shipping_rate_minimum_cost"] . "',"; //added
$q .= "shipping_rate_maximum_cost='" . $d["shipping_rate_maximum_cost"] . "',"; //added
-------------------------------------
All we've done with the above is add 2 extra fields to the database and let you store values in them. Now we have to edit the standard shipping module:
com_virtuemart\classes\shipping\standard_shipping.php
In the section:
/**************************************************************************
* name: list_rates()
* created by: Ekkehard Domning, Soeren Eberhardt
* description: returns a html list with selectable rates
* parameters: $d[]: Array with search criteria
* "country", "zip", "weight"
* returns:
**************************************************************************/ After:
$auth = $_SESSION["auth"];
Add:
//GET PRICE
if ( $_SESSION['auth']['show_price_including_tax'] != 1 ) {
$taxrate = 1;
$order_total = $total + $tax_total;
}
else {
$taxrate = $this->get_tax_rate() + 1;
$order_total = $total;
}
//END GET PRICE
This was borrowed from com_virtuemart\classes\shipping\shipvalue.php
About 20 lines down from there after:
if (is_numeric($zip)) {
$q .= "(shipping_rate_zip_start <= '" . $zip . "' OR LENGTH(shipping_rate_zip_start) = 0 ) AND ";
$q .= "(shipping_rate_zip_end >= '" . $zip . "' OR LENGTH(shipping_rate_zip_end) = 0 ) AND ";
}Add - all your doing here is modifying the SQL statement that gets the available shipping rates from the data base and saying, get one that fits in between the min and max order values :
$q .= "shipping_rate_minimum_cost <= '" . $order_total . "'AND ";
$q .= "shipping_rate_maximum_cost >= '" . $order_total . "'";
Also edit the next line to read (you'll be adding the extra AND to it):
$q .= " AND shipping_rate_weight_start <= '" . $d["weight"] . "'AND ";
-------------------------------------
That's it! Not perfect as there are some things you need to consider when using it:
This shop is based in the UK so I will use royal mail standard as the example:
If you want to have a shipping rate of £2.50 on orders below £20 you will need to setup two rates:
UK Standard Below £20 Order value from 0.00 to 20.00 rate £2.50
UK Standard Order Over £20 value from 20.01 to 999999.00 rate £0.00
You can build in as many bands / countries as you need.
For example I have:
Europe Standard Rate from 0.00 to 999999.00 rate £10