Author Topic: UPSv2 Hack to have Additional Flatrate or handling fee per product  (Read 4373 times)

mowlman

  • Full Member
  • ***
  • Posts: 209
I almost have this working, but I am having a problem of properly setting and saving a switch within class.package.php and class.shipment.php.
Package logic where I am setting the fee and adding it to the final UPS rates
\administrator\components\com_virtuemart\classes\shipping\upsv2\class.Package.php
\administrator\components\com_virtuemart\classes\shipping\upsv2\class.Shipment.php

We have some products which need an extra flatrate / handling fee if their quantities are less than a certain number i.e. if prod A QTY is 1 to 3, then add a one time Additional fee of $10, once the QTy has reached 4 , then do not charge any additional fee.

I have added 3 fields to the product table
add_flatfee  -Y/N does product have an additional flatfee
add_flatfee_amount  - How much the additional fee is
add_flatfee_cutoff  - The quantity to cutoff and no longer charge a fee since the min QTY has been reached

Each product has its own cutoff, so I need to keep track of a switch for when their QTY cutoff has been met. There can be multiple products added to the cart, each with their own cutoff.

How can I save a switch that is set within class.package that is not reset with the next product?

Has this products cutoff_reached = 'N' {
  If product count < add_flatfee_cutoff {
     Add this products add_flatfee_amount to total_fee
     set flatfee_this_prod_already_added = 'Y'
  }
  Else{
       cutoff_reached = 'Y'   //no longer charge an additional fee for this product
       Subtract this products add_flatfee_amount from total_fee
  }
}

example:
prod A add_flatfee_amount=$10 , add_flatfee_cutoff=2
prod B add_flatfee_amount=$5 , add_flatfee_cutoff=3

Prod A added to cart  Total_fee = 10
Prod B added to cart  Total_fee= 15

Another Prod B added to cart (QTY now is 2)   Total fee remains $15
Now Another Prod B added to cart (QTY now is 3)  which is equal to the cuttoff amount for prod B, so remove the Prod B additional fee,   Total fee becomes $10


VM1.1.9, upsv2

lowmips

  • Global Moderator
  • Hero Member
  • *
  • Posts: 1464
    • lowmips.com
Re: UPSv2 Hack to have Additional Flatrate or handling fee per product
« Reply #1 on: May 17, 2012, 17:51:57 pm »
Hi Bill,
Use the class instance's "shipment" pointer to refer to the containing shipment, then iterate through each package, keeping track of how many item B there are.  If the minimum is met, again loop through each package and set the additional fee to zero.  Or, go at it from a different angle.. create an array of product id's with "extra" fees and minimum triggers in the containing Shipment instance, then each time a product is added update the array, check for extra fees.  The extra fee amount could be kept in the same array, something like:

Code: [Select]
pid => (
    min => 3,
    fee => 5.00
   count => 1
)

Then during final fee calculation either include or exclude that fee based on the total count of that product.
Visit my website at www.lowmips.com
View my newsletters Here (sign up for newsletters on the front page of my website)

makevalue

  • Beginner
  • *
  • Posts: 13
Re: UPSv2 Hack to have Additional Flatrate or handling fee per product
« Reply #2 on: June 08, 2012, 16:14:10 pm »
We don't code php in house.  I need to add a handling charge to VirtueMart 2.x.  Do you know anyone created a plug in to do this?