VirtueMart Forum

VirtueMart 1.1.x [ Old version - no longer supported ] => Shipping VM 1.1 => Topic started by: bochenek on June 26, 2009, 20:17:09 pm

Title: Solution! - Flat rate + fixed cost for each additional item
Post by: bochenek on June 26, 2009, 20:17:09 pm
Success,

Here is a work around solution that will allow you to offer a flat rate shipping charge for the first item plus a fixed cost for each additional item. This solution allows you to create different pricing rules for individual carriers. Different pricing rules by shipping method. Different pricing rules for specific locations. It can used to create simple flat rate policies. And it can be used to offer free shipping to specific locations.

Say you wanted to charge the following shipping fees:
UPS Ground            $5.95 1st item + $2.00 ea. add'l item (USA only)
UPS Flate Rate       $14.95 (International only)
USPS Priority Mail   $5.00 1st item + $1.20 ea. add'l item (USA + International)
USPS Book Rate     $3.50 1st item + $ .75 ea. add'l item (USA + International)
Free Shipping to customers in your city

Summary:
This solution uses VM's Standard Shipping Module. You only need to add "one" additional line of code to standard_shipping.php then use the standard VM "Shipping / Create a Shipping Rate" to create multiple "flat rate + additional cost" or multiple flat rate shipping policies or multiple location based free shipping.

Edit the file:
/your_site_root/administrator/components/com_virtuemart/classes/shipping/standard_shipping.php

Locate the following section:
$total_shipping_handling = $dbr->f( "shipping_rate_value" ) + $dbr->f( "shipping_rate_package_fee" ) ;
$total_shipping_handling = $GLOBALS['CURRENCY']->convert( $total_shipping_handling ) ;
$total_shipping_handling *= $taxrate ;
$show_shipping_handling = $CURRENCY_DISPLAY->getFullValue( $total_shipping_handling ) ;

Add/Insert the following line indicated in red:
$total_shipping_handling = $dbr->f( "shipping_rate_value" ) + $dbr->f( "shipping_rate_package_fee" ) ;
$total_shipping_handling = $GLOBALS['CURRENCY']->convert( $total_shipping_handling ) ;
$total_shipping_handling *= $taxrate ;
$total_shipping_handling = $d["zone_qty"] * $dbr->f( "shipping_rate_value" ) + $dbr->f( "shipping_rate_package_fee" ) ;
$show_shipping_handling = $CURRENCY_DISPLAY->getFullValue( $total_shipping_handling ) ;


How this new line of code works:
This work around solution uses the number of items in the shopping cart as the "cost for each additional item" and adds a fixed base amount. The fixed base amount is added to the total to create the "cost for the first item".

So if you wanted to charge $5.95 for the 1st item + $2.00 ea. add'l item. the math is ((quantity of items in cart * 2.00) + $3.95)

Say you only have one item in the cart, the math is: ((1*2.00)+3.95)= $5.95, or, the cost for your first item.

Now lets say that you have three items in your cart, the math is: ((3*2.00)+3.95)= $9.95, or, $5.95 for the 1st item plus $2.00 ea. for the 2 additional items.

If you wanted to charge a flat rate of $14.95, the math is ((quantity of items in cart * 0) + $14.95)
If you wanted to offer free shipping for a location, the math is ((quantity of items in cart * 0) + 0)
If you wanted to charge $5.00 for the 1st item + $ 1.20 ea. add'l item. the math is ((quantity of items in cart * 1.20) + $3.80)
If you wanted to charge $3.50 for the 1st item + $ .75 ea. add'l item. the math is ((quantity of items in cart * 0.75) + $2.75)


How you configure it in VM:
1) Enable Standard Shipping under "Admin / Configuration / Shipping" make sure that the Standard Shipping Module is checked.

2) Create a shipping rate under "Shipping / Create a Shipping Rate"

This work around solution changes the definition or purpose of the fields "Fee:" and "Your package fee:". "Fee:" is now the multiplier to "items in cart" and "Your package fee:" is now the added fixed base amount.

The above formula is now: ((items in cart * Fee:) + Your package fee:)

As in the above examples, if you wanted to charge $5.95 for the 1st item + $2.00 ea. add'l item. Enter the following:
Fee: 2.00
Your package fee: 3.95

If you wanted to charge a single Flat Rate fee of $14.95, enter:
Fee: 0.00
Your package fee: 14.95
 - This works because "items in cart" * 0 = 0, then the "Your package fee:" is added. Providing you with a fixed amount flat rate.

As in the above examples, if you wanted to charge $5.00 for the 1st item + $1.20 ea. add'l item. Enter the following:
Fee: 1.20
Your package fee: 3.80

If you wanted to offer free shipping to a specific zone, zip, city, state or country. Specify the zip code range of a zone, city, or state. To specify a country, select it from the country list. Then enter the following:
Fee: 0.00
Your package fee: 0.00


You can create multiple combinations of the above shipping rates with this solution. Just give each shipping rate the appropriate "Shipping rate description:". e.g. UPS Ground or USPS Priority Mail. Then select the appropriate zip code range and/or country(s) that the shipping rate applies to.  

This solution also works with the automatic order confirmation email. The order confirmations will display the ship method that you entered into the rule's "Shipping rate description:".  

I haven't needed it yet but I believe that it would be fairly easy to offer free shipping over a specific dollar amount (i.e. $50.00) by using the following logic:
  if cart total > 50.00
      $total_shipping_handling = 0 ;
  else
      $total_shipping_handling = $d["zone_qty"] * $dbr->f( "shipping_rate_value" ) + $dbr->f( "shipping_rate_package_fee" ) ;

If you want flat rate shipping only and do not need an additional cost per item. Then enter the following code:
$total_shipping_handling = $dbr->f( "shipping_rate_value" ) + $dbr->f( "shipping_rate_package_fee" ) ;
In this scenario, use the "Fee:" field to enter the amount of your flat rate. This scenario also allows you to use the "Your package fee:" as normal.

Drawbacks to this approach are:
- It breaks the Standard Shipping module. Because it changes the meaning or function of the fields "Fee:" and "Your package fee:" all rules created using Standard Shipping module will be calculated in this way.
- During version upgrades it will be lost when the PHP file is replaced and therefore it will need to be manually coded again.


Note: I am a consultant and I am posting this solution to hopefully generate some business. I can be contacted at dbochenek@compitsol.com for services or consultation.

I hope that this solution is of some use to you.
David
Title: Re: Solution! - Flat rate + fixed cost for each additional item
Post by: Mike Horsten on July 07, 2009, 14:20:04 pm
Thanks just what i needed :)
Title: Re: Solution! - Flat rate + fixed cost for each additional item
Post by: bonaventure on August 03, 2009, 23:50:06 pm
Thank you for this solution. It works great in my shop. Anyone who deals with wholesalers will be grateful for this hack.

And thanks for the contact info. We've already hired others from this forum with great success. We'll keep you in mind.
Title: Re: Solution! - Flat rate + fixed cost for each additional item
Post by: sextoytopmart on August 04, 2009, 01:10:52 am
Oh my! Thank you so much, this is the perfect interim fix for my site.
Title: Re: Solution! - Flat rate + fixed cost for each additional item
Post by: bengsan on August 04, 2009, 08:44:13 am
thanks you so much.
Title: Re: Solution! - Flat rate + fixed cost for each additional item
Post by: enquirerUK on September 28, 2009, 02:15:24 am
Hi everyone,

This is indeed a great hack but I noticed that, unfortunately, it doesn't work if you have activated another hack which enables the creation of a shipping fee based on the number of items being purchased as per http://forum.virtuemart.net/index.php?topic=57350.0

Can anyone help?

Thanks in advance. :-\
Title: Re: Solution! - Flat rate + fixed cost for each additional item
Post by: bonaventure on October 19, 2009, 14:59:48 pm
Would it be difficult to tweak this hack so that the flat fee also includes a percentage of the total sale.

For example, according to the hack above, if the flat rate shipping was $5 + .50 for each additional item (let's assume there are 10 items), the total shipping would be $10.

But I would like to add 5% charge to the flat fee. Thus if the total order was $100 for 10 items the formula would look like this: ($5 + ($100 X 5%) + ($0.50 X 10)) = $15.

Any thoughts?
Title: Re: Solution! - Flat rate + fixed cost for each additional item
Post by: waller99 on November 11, 2009, 18:35:23 pm
For some reason it is not working for me. It is just charging the Package fee no matter how many the quantity is.

This is what I changed it to:
Quote
$total_shipping_handling = $dbr->f( "shipping_rate_value" ) + $dbr->f( "shipping_rate_package_fee" ) ;
            $total_shipping_handling = $GLOBALS['CURRENCY']->convert( $total_shipping_handling ) ;
            $total_shipping_handling *= $taxrate ;
            $total_shipping_handling = $d["zone_qty"] * $dbr->f( "shipping_rate_value" ) + $dbr->f( "shipping_rate_package_fee" ) ;
            $show_shipping_handling = $CURRENCY_DISPLAY->getFullValue( $total_shipping_handling ) ;
Title: Re: Solution! - Flat rate + fixed cost for each additional item
Post by: PRO on January 05, 2010, 16:36:57 pm
tested and working
Title: Re: Solution! - Flat rate + fixed cost for each additional item
Post by: PRO on January 06, 2010, 18:25:59 pm
Does anyone know how to change  zone_qty   TO "ORDER WEIGHT"

$total_shipping_handling = $d["zone_qty"] * $dbr->f( "shipping_rate_value" ) + $dbr->f( "shipping_rate_package_fee" ) ;
Title: Re: Solution! - Flat rate + fixed cost for each additional item
Post by: thanoss43 on January 07, 2010, 10:19:20 am
Hi,

Thanks a lot for this.

I can't set a free shipping for order totals over 50.
I used the code you wrote above and added the lines you gave for free shipping. I get a parse error. I don't know much about php coding i guess my syntax is totally wrong!
 

$total_shipping_handling = $dbr->f( "shipping_rate_value" ) + $dbr->f( "shipping_rate_package_fee" ) ;
$total_shipping_handling = $GLOBALS['CURRENCY']->convert( $total_shipping_handling, $shipping_rate_currency_code, $GLOBALS['product_currency'] ) ;
$total_shipping_handling *= $taxrate ;
if cart total > 50.00
$total_shipping_handling = 0 ;
else
$total_shipping_handling = $d["zone_qty"] * $dbr->f( "shipping_rate_value" ) + $dbr->f( "shipping_rate_package_fee" ) ;
$show_shipping_handling = $CURRENCY_DISPLAY->getFullValue( $total_shipping_handling ) ;


UPDATE: SOLVED: I had to import variable $total and then write if ($total > 50.00)
Title: Re: Solution! - Flat rate + fixed cost for each additional item
Post by: laurieudy on January 07, 2010, 21:51:31 pm
Thanks!!  I follwed the instructions but for some reason when i try and place an order it says the wrong price but i have put 5.95 for first item and then package fee 2.00 but then it shows for 4 items.  %5.97.  Can you please help. 
thanks!!!
Title: Re: Solution! - Flat rate + fixed cost for each additional item
Post by: laurieudy on January 09, 2010, 06:23:04 am
Please help me with the previous posts.  thanks!!!!
Title: Re: Solution! - Flat rate + fixed cost for each additional item
Post by: PRO on January 09, 2010, 16:37:51 pm
do you have discounts OR taxes interfering with your total/

Title: Re: Solution! - Flat rate + fixed cost for each additional item
Post by: laurieudy on January 09, 2010, 21:00:02 pm
i have taxes but the prices are wrong when it shows up when to choose shipping.  it always has different amounts even when it is for one item which i have set up as 5.95
Title: Re: Solution! - Flat rate + fixed cost for each additional item
Post by: laurieudy on January 09, 2010, 21:10:22 pm
Here is what my screen looks like on my screen.  I am not sure where the standard shipping method is coming from. 

Please select a Shipping Method!
 Standard Shipping: $12.78

  Shipper Shipping Rate Price
 USPS USPS $5.95
 USPS Priority Mail USPS Priority $11.95
 UPS Ground UPS Ground $6.50

Title: Re: Solution! - Flat rate + fixed cost for each additional item
Post by: johk on January 12, 2010, 12:48:50 pm
Thanks Mate,
This is a great solution.But it doens't seem to matter what atx rate I choose - it doesn't take it in to account.

J
Title: Re: Solution! - Flat rate + fixed cost for each additional item
Post by: mike68 on February 09, 2010, 18:56:08 pm
Awesome! This worked like a charm! Thank you so much!
Title: Re: Solution! - Flat rate + fixed cost for each additional item
Post by: Trackerpls on March 31, 2010, 03:53:27 am
 ;D THANK YOU THANK YOU!!!

This worked perfectly...however, I just received and email from a buyer in Mexico which I have set up in my First Class USPS overSEAS shipping rate. For some reason when this buyer goes to choose a shipping rate there is nothing available to choose. Does this have something to do with the ZONE area. I have US and Canada as one shipping rate and all other locations set up as another rate. Should I create another shipping rate just for Mexico? Haven't had any other problems with overseas shipping expect Mexico. Anni thoughs or suggestion would be helpful.
Title: Re: Solution! - Flat rate + fixed cost for each additional item
Post by: thanoss43 on June 08, 2010, 16:49:03 pm
Hello,

Thanks again for your work.

I need one more tweek please if possible:

I 'm using your method and the following code to achieve free shipping for over 80Euros orders.

if ($total > 80.00)
         {   $total_shipping_handling = 0 ;  }
                else
      {       $total_shipping_handling = $d["zone_qty"] * $dbr->f( "shipping_rate_value" ) + $dbr->f( "shipping_rate_package_fee" ) ; }
            $show_shipping_handling = $CURRENCY_DISPLAY->getFullValue( $total_shipping_handling ) ;

I want now to use free shipping only to orders within Europe.

I 'm using standard shipping and i have 3 rates, one for the UK, one for European Union and one for the rest of the world.
I want to exclude free shipping in the "rest of the world" option and maybe use a flat rate. Something like

if ($total > 80.00) AND shipping rate IS NOT "rest of the world"
    {   $total_shipping_handling = 0 ;  }

Can someone please translate the above expresion into code?  :D

Thanks a lot!
Title: Re: Solution! - Flat rate + fixed cost for each additional item
Post by: digitalrain on June 10, 2010, 12:20:08 pm
I needed my shipping to be $6.95 for the first item and $0.50 for each
additional item.

I implemented your fix and although it *mostly* works, it adds the $0.50
to the first item as well as all of the others.

Any ideas?

Many thanks,

Cynthia
Title: Re: Solution! - Flat rate + fixed cost for each additional item
Post by: jboulton on June 17, 2010, 19:46:49 pm
I've changed the code and created a shipper and two shipping rates 1) pick up the tickets ($0) and mail the tickets ($1.00). Both are flat rates - doesn't matter on quantity.

When I get to the shipping method I get: Please select a Shipping Method!

Neither Pickup or Mail is an option.  This is the first time I've setup shipping.

I would really appreciate any suggestions.  Thanks.

Title: Re: Solution! - Flat rate + fixed cost for each additional item
Post by: yash_dhan on September 28, 2010, 17:51:53 pm
can anybody help. I want custom rates for shipping. At shipping module i want to have 3 radio buttons and at payment module i want to add the selectes rate from previous module. which files should be edited and wat code plz help my email id is 19.yash@gmail.com
Title: Re: Solution! - Flat rate + fixed cost for each additional item
Post by: davidodtralee on November 18, 2010, 00:32:13 am
Hi all,

Would this be terribly hard to implement in relation to products? It basically does what I need it to...but I'm new at this.

My problem is as follows:

Product costs: 15 euro to buy one.  Each subsequent product will cost 5 euro.  So 2 products will cost 20 euro.

Maybe I'm just confusing myself, but how would I do this?

Thanks for any help (its greatly appreciated at 11.33pm on a Wednesday night!)

David
Title: Re: Solution! - Flat rate + fixed cost for each additional item
Post by: Rochelle on April 18, 2011, 15:03:22 pm
how do I access the standard_shipping.php file ?? If I paste the address it does not allow direct access.
Title: Re: Solution! - Flat rate + fixed cost for each additional item
Post by: Acceleral on June 30, 2011, 00:59:08 am
This works really well but one consideration with the math is if the per-item additional charge is greater than the initial item charge.

In that case in your VM configuration for the Shipping Rate you need to make the "Your package fee:" a negative amount so it is subtracted from the total.
Title: Re: Solution! - Flat rate + fixed cost for each additional item
Post by: DW1972 on October 18, 2011, 10:19:38 am
Guys

 i added this code and all looked good..set up the fees and so on and looks good but when i choose the shipping type and press next in the shopping cart checkout...an error comes up saying

"Error: Please select another Shipping Method.
 Error: Please select another Shipping Method."

Any ideas how to fix this

Title: Re: Solution! - Flat rate + fixed cost for each additional item
Post by: bouss on April 12, 2012, 08:16:25 am
GOOOOOOOOOOOOOODD GOD BLESS YOU !!!!!!!!!!!!! it works perfect even whit the Virtuemart Shipping by State
Title: Re: Solution! - Flat rate + fixed cost for each additional item
Post by: jinanissa on June 26, 2012, 11:46:32 am
Thanks a lot for this post
Title: Re: Solution! - Flat rate + fixed cost for each additional item
Post by: camppos on September 04, 2013, 00:32:17 am
Does anybody know how can I calculate the shipping by quantity for instance.
-1 to 6 items (Small Flat Rate Box) $6.00 dlls
-6 to 12 items (Medium Flat Rate Box) $13.00 dlls


Thank you,

Jesus
Title: Re: Solution! - Flat rate + fixed cost for each additional item
Post by: rdharma on November 02, 2015, 18:45:27 pm
HI,
Could you tell the file in VirtueMart 2.6.10?
Thanks