Author Topic: Solution! - Flat rate + fixed cost for each additional item  (Read 117188 times)

bochenek

  • Beginner
  • *
  • Posts: 10
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

Mike Horsten

  • Beginner
  • *
  • Posts: 24
Re: Solution! - Flat rate + fixed cost for each additional item
« Reply #1 on: July 07, 2009, 14:20:04 pm »
Thanks just what i needed :)

bonaventure

  • Beginner
  • *
  • Posts: 17
Re: Solution! - Flat rate + fixed cost for each additional item
« Reply #2 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.

sextoytopmart

  • Beginner
  • *
  • Posts: 2
Re: Solution! - Flat rate + fixed cost for each additional item
« Reply #3 on: August 04, 2009, 01:10:52 am »
Oh my! Thank you so much, this is the perfect interim fix for my site.

bengsan

  • Beginner
  • *
  • Posts: 5
Re: Solution! - Flat rate + fixed cost for each additional item
« Reply #4 on: August 04, 2009, 08:44:13 am »
thanks you so much.

enquirerUK

  • Beginner
  • *
  • Posts: 4
Re: Solution! - Flat rate + fixed cost for each additional item
« Reply #5 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. :-\

bonaventure

  • Beginner
  • *
  • Posts: 17
Re: Solution! - Flat rate + fixed cost for each additional item
« Reply #6 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?

waller99

  • Beginner
  • *
  • Posts: 1
Re: Solution! - Flat rate + fixed cost for each additional item
« Reply #7 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 ) ;

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10439
  • VirtueMart Version: 3+
Re: Solution! - Flat rate + fixed cost for each additional item
« Reply #8 on: January 05, 2010, 16:36:57 pm »
tested and working

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10439
  • VirtueMart Version: 3+
Re: Solution! - Flat rate + fixed cost for each additional item
« Reply #9 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" ) ;

thanoss43

  • Beginner
  • *
  • Posts: 44
Re: Solution! - Flat rate + fixed cost for each additional item
« Reply #10 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)

laurieudy

  • Beginner
  • *
  • Posts: 38
Re: Solution! - Flat rate + fixed cost for each additional item
« Reply #11 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!!!

laurieudy

  • Beginner
  • *
  • Posts: 38
Re: Solution! - Flat rate + fixed cost for each additional item
« Reply #12 on: January 09, 2010, 06:23:04 am »
Please help me with the previous posts.  thanks!!!!

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10439
  • VirtueMart Version: 3+
Re: Solution! - Flat rate + fixed cost for each additional item
« Reply #13 on: January 09, 2010, 16:37:51 pm »
do you have discounts OR taxes interfering with your total/


laurieudy

  • Beginner
  • *
  • Posts: 38
Re: Solution! - Flat rate + fixed cost for each additional item
« Reply #14 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