Author Topic: Standard Shipping module (add value variable)  (Read 16795 times)

Patrick@M4

  • Beginner
  • *
  • Posts: 24
Standard Shipping module (add value variable)
« on: July 18, 2008, 04:11:07 AM »
The standard shipping module is excellent but missing one feature that would be really useful.

Adding two fields for order value from -> to.

That way shipping can be applied per country but also based on the order value.
JM 1.0.15 / VM 1.0.15

Patrick@M4

  • Beginner
  • *
  • Posts: 24
Re: Standard Shipping module (add value variable)
« Reply #1 on: July 18, 2008, 07:30:15 AM »
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.0

Changes mades (on VirtueMart 1.0.15):

Run this SQL statment on your database, update the table names to match yours!

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_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:
Code: [Select]
<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:
Code: [Select]
<!-- // 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
Code: [Select]
/**************************************************************************
   * 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:

Code: [Select]
/**************************************************************************
   * 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:
 
Code: [Select]
/**************************************************************************
* 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:

Code: [Select]
//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:

Code: [Select]
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


JM 1.0.15 / VM 1.0.15

Tetz

  • Beginner
  • *
  • Posts: 1
Re: Standard Shipping module (add value variable)
« Reply #2 on: September 03, 2008, 19:58:26 PM »
This seems perfect for what I am trying to do for a client but I can't get it to work. I have been reviewing it and I think the problem is the actual "standard_shipping.php" file.

It seems like this file has had an update to it compared to what is posted here and maybe that's the problem. I looked through the other files and didn't see anything that jumped out at me but I am by no means an expert.

The problems I am running in to are...

I can update existing shipping rates with order ranges, but I can not create new shipping options. Every time I try I hit save, and it goes back to the shipping screen and nothing new changes, nor is anything added on the back end.

Secondly, on the front end the shipping is not showing up. Right now the only shipping range I have is 0.00 to $25.00 but even at that price it does not show anything to the customer.


I tried to use shipvalue.php and it works great for one country, but my client ships to many countries, each with shipping rates. The standard shipping module is perfect for this if it would let me do order totals.

Has anyone else tried to get this to work and if so do you have any tips or changes to this code that may allow it to work?

Zavu

  • Beginner
  • *
  • Posts: 2
Re: Standard Shipping module (add value variable)
« Reply #3 on: October 01, 2008, 05:13:17 AM »
Here are the modifications to be done for activating this feature on VirtueMart 1.1.2 (based on Patrick@M4 steps). In Bold are the lines to be added to the corresponding files

1. Update DB (adapt the names of the tables to your needs)

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` ;


2. /administrator/components/com_virtuemart/languages/shipping/english.php (or other language according to your needs)

   'PHPSHOP_RATE_FORM_WEIGHT_START' => 'Lowest Weight',
   'PHPSHOP_RATE_FORM_WEIGHT_END' => 'Highest Weight',
   'PHPSHOP_RATE_FORM_MINIMUM_COST' => 'Minimum shipping fee',
   'PHPSHOP_RATE_FORM_MAXIMUM_COST' => 'Maximum shipping fee',


3. /administrator/components/com_virtuemart/html/shipping.rate_list.php

   "<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') => '',
   $VM_LANG->_('PHPSHOP_SHIPPING_RATE_LIST_RATE_WSTART') => '',
   $VM_LANG->_('PHPSHOP_SHIPPING_RATE_LIST_RATE_WEND') => '',
   $VM_LANG->_('PHPSHOP_RATE_FORM_MINIMUM_COST') => '',
   $VM_LANG->_('PHPSHOP_RATE_FORM_MAXIMUM_COST') => '',

   $VM_LANG->_('E_REMOVE') => "width=\"5%\""

...


   $tmp_cell = "<a href=\"" . $sess->url($url) . "\">". $db->f("shipping_rate_name")."</a>";
   $listObj->addCell( $tmp_cell );
   $listObj->addCell( $db->f("shipping_rate_weight_start"));
   $listObj->addCell( $db->f("shipping_rate_weight_end"));
   $listObj->addCell( $db->f("shipping_rate_minimum_cost"));    
   $listObj->addCell( $db->f("shipping_rate_maximum_cost"));



4. /administrator/components/com_virtuemart/html/shipping.rate_form.php

   <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>
   <!-- // 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 ######-->

5. /administrator/components/com_virtuemart/classes/ps_shipping.php


   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,shipping_rate_minimum_cost,shipping_rate_maximum_cost,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"] . "','";
      $q .= $d["shipping_rate_minimum_cost"] . "','";
      $q .= $d["shipping_rate_maximum_cost"] . "','";



…………………………………………………………………………………………………………


      $q .= "shipping_rate_weight_start='" . $d["shipping_rate_weight_start"] . "',";
      $q .= "shipping_rate_weight_end='" . $d["shipping_rate_weight_end"] . "',";
      $q .= "shipping_rate_minimum_cost='" . $d["shipping_rate_minimum_cost"] . "',";
      $q .= "shipping_rate_maximum_cost='" . $d["shipping_rate_maximum_cost"] . "',";



6. /administrator/components/com_virtuemart/classes/shipping/standard_shipping.php

   function list_rates( &$d ) {
      global $total, $tax_total, $VM_LANG, $CURRENCY_DISPLAY, $vmLogger ;

      
      $auth = $_SESSION["auth"] ;
      
      //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


………………………………………………………………………..

      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 " ;
      }
      $q .= "shipping_rate_minimum_cost <= '" . $order_total . "'AND ";
      $q .= "shipping_rate_maximum_cost >= '" . $order_total . "'AND ";
      $q .= "shipping_rate_weight_start <= '" . $d["weight"] . "'AND ";


That's it! Hope I didn’t forgot anything

002media

  • Beginner
  • *
  • Posts: 3
Re: Standard Shipping module (add value variable)
« Reply #4 on: October 15, 2008, 21:33:16 PM »
ive had the same problems as tetz

here are the problems
i can not add new shipping rates
does not show up in shipping options

this is using zavu's instructions using virtuemart 1.1.2

has anybody found a solution, or alternative route

all i want is fixed rates based on order totals and countries

002media

  • Beginner
  • *
  • Posts: 3
Re: Standard Shipping module (add value variable)
« Reply #5 on: October 16, 2008, 07:34:53 AM »
OMG just found a extra comma in one of them, so my mistake :)
works perfectly, now i can add rates and they show up when needed
thanks for posting this guys, i'm sure many will appreciate this, I DO !!!!!

llema

  • Beginner
  • *
  • Posts: 14
Re: Standard Shipping module (add value variable)
« Reply #6 on: February 24, 2009, 13:40:18 PM »
Will this work with 1.1.3 if I make all the changes noted in ZAVU's post above??? Really need this functionality for shipping rates!

bobinfrance

  • Beginner
  • *
  • Posts: 5
Re: Standard Shipping module (add value variable)
« Reply #7 on: March 28, 2009, 10:04:23 AM »
Very nearly the same for 1.1.3

But for /administrator/components/com_virtuemart/classes/ps_shipping.php


function rate_add(&$d) and function rate_update(&$d) add the bold

'shipping_rate_weight_start' => vmGet($d, 'shipping_rate_weight_start'),
'shipping_rate_weight_end' => vmGet($d, 'shipping_rate_weight_end'),
'shipping_rate_minimum_cost' => vmGet($d, 'shipping_rate_minimum_cost'),
'shipping_rate_maximum_cost' => vmGet($d, 'shipping_rate_maximum_cost'),

'shipping_rate_value' => vmGet($d, 'shipping_rate_value'),





SnakeDragon

  • Jr. Member
  • **
  • Posts: 59
Re: Standard Shipping module (add value variable)
« Reply #8 on: June 20, 2009, 11:18:42 AM »
Works perfectly with VM 1.1.2

Thank you very, very much! :D

active8

  • Jr. Member
  • **
  • Posts: 56
Re: Standard Shipping module (add value variable)
« Reply #9 on: September 03, 2009, 18:07:57 PM »
does anyone care to explain on how to use this as I would be very grateful if someone could guide me on how to set this up in the admin back-end.

thanks

bobinfrance

  • Beginner
  • *
  • Posts: 5
Re: Standard Shipping module (add value variable)
« Reply #10 on: September 04, 2009, 04:42:11 AM »
active8 -

Set up a shipping rate for each of your bands for each county you're delivering to:

So for Canada:
Weight from 0 to 99999999
Order value from $0.00 to $29.99 = $11.99
Zip from 0000 to 99999

Weight from 0 to 99999999
Order value from 30.00 to 49.99 = 13.99
Zip from 0000 to 99999
etc.

Weight from 0 to 99999999
Order value from 100.00 to 999999.99 = 0
Zip from 0000 to 99999


Does that make sense?

Melmoi

  • Beginner
  • *
  • Posts: 4
Re: Standard Shipping module (add value variable)
« Reply #11 on: February 08, 2010, 07:20:46 AM »
Hello !

It does'nt work with virtuemart 1.1.4, do you know what piece of we need to change to make it work ?

Thanks

Atti

  • Beginner
  • *
  • Posts: 43
Re: Standard Shipping module (add value variable)
« Reply #12 on: June 15, 2010, 06:55:56 AM »
any body have the fix for 1.1.4? Would really need this...THNX

Template Designer

  • Beginner
  • *
  • Posts: 37
    • Virtuemart Templates
Re: Standard Shipping module (add value variable)
« Reply #13 on: June 15, 2010, 19:15:41 PM »
I want this function on 1.1.4
VirtueMart Templates gear up your sales...

mzdesign

  • Beginner
  • *
  • Posts: 2
Re: Standard Shipping module (add value variable)
« Reply #14 on: December 16, 2010, 00:14:19 AM »
Hi !

Does anybody have this solution for VM 1.1.5 ?

Thanks in advance

VirtueMart Forum

Re: Standard Shipping module (add value variable)
« Reply #14 on: December 16, 2010, 00:14:19 AM »