Jump to content

Proposed change in Carrier fees


rockraven

Recommended Posts

Hello,

I needed a core change for a client and i implemented it; it now works, i would like to share it with you and hear your oppinions.


Premise:

1.My carrier prices are calculated using a formula that depends on: 2 base prices, Weight factor, Fuel price.

2.Example formula: "BasePrice1 + (Weight - 1) * BasePrice2 * FuelPrice";

3.Using the formula to calculate the fees for each Zone/Weight-range would have resulted in a large table of fees; updating that table if BasePrice1 or BasePrice2 or FuelPrice changed would mean recalculating all the fees in the table and replacing them.

4.The client did not accept the work involved with recalculating/replacing all fees in the fees table for the carrier (on a weekly basis), he wanted an easy way of managing his transport fees.


Actions:

1.I changed the ps_delivery table; i converted the price column from a float type to a string type;

2.I found /classes/Carrier.php code that was reading/writing the price value from the database and converting it into an integer to be used in calculations later on;

3.i stoped the code from converting my strings into integers;

4.i added some string replacements in case the string %W was present in the string, it would be replaced by total weight of package;

5.i added an "eval('return '.$price)" on the price string so that it would calculate the final price based on the string it had;

6.i enlarged the inputs in /admin/tabs/AdminShipping.php, i changed them into textareas so that you could write down the formula there;


Worries:

1.Eval is not safe and breaking the database could imply running any php code present in the price column of that table, so a vulnerability is created;

2.possible simple solution would be to calculate the price string using SQL with something like mysql_query("SELECT ".((string) $price))

3.possible simple solution using the solution described here http://www.php.net/manual/en/language.types.string.php#91628

3.possible complex solution would be to create a rudimentary parser like a calculator function and process the result in php;

4.my code is not upgrade-able because i changed core features;

5.i can't make a module out of this because the module would have to RegEx-replace several lines of code in several files and it's an unelegant solution that i would have to maintain for each new release;


I am eagerly expecting your feedback.

Link to comment
Share on other sites

Can you please explain the background for the formula? My guess was that it's something like your client lives a long way from the post office and will have to use a lot of petrol to go there. But it still doesn't make sense for me.

/Kjeld

Link to comment
Share on other sites

To get our lingo synchronised I am a developer, my client is a shop owner, his clients are the customers.

My clients carriers & their respective formulas are the following:
1. Romanian Postal service:
WeightRange[0,10]: (1.25ron + 1.25ron * ceil(TotalWeight)) * 119/100
WeightRange[10,15]: (1.32ron + 1.32ron * ceil(TotalWeight)) * 119/100
WeightRange[15,+]: (1.32ron + 1.32ron * 15) * 119/100
For this carrier in a clean PrestaShop install i would have to configure 15 fees one for each extra kilogram of the total weight (and that only for one zone).
Imagine recalculating then replacing the value of 15 fee cells for each zone.
Now we only use 2 cells for this carrier.

2. Urgent Currier:
WeightRange[0,1]: 10.4ron * 119/100
WeightRange[1,+]: (10.4ron + 0.728 * round(TotalWeight)) * 119/100
For this carrier in a clean PrestaShop i would have to configure a number of fees (lets say 50) for each kilogram of the total weight in order to cover the larget possible delivery weight i could think of.

3. TNT Shipping International (this one is weird)
WeightRange[0,5]: (ZoneBasePrice/TotalWeight * FuelIndex) * 119/100
WeightRange[5,30]: ((ZoneBasePrice/5 + PricePerKG * (TotalWeight - 5)) * FuelIndex) * 119/100
WeightRange[30,30]: (ZoneBasePrice/TotalWeight * FuelIndex) * 119/100
WeightRange[30,70]: ((ZoneBasePrice/30 + PricePerKG * (TotalWeight - 30)) * FuelIndex) * 119/100
WeightRange[70,70]: (ZoneBasePrice/TotalWeight * FuelIndex) * 119/100
WeightRange[70,500]:((ZoneBasePrice/500 + PricePerKG * (TotalWeight - 70)) * FuelIndex) * 119/100
WeightRange[500,+]: (ZoneBasePrice/TotalWeight * FuelIndex) * 119/100

The 3rd carrier is international and shipments are made via plane, which means expensive kerosene and varying petrol prices, they have an international kerosene indices that they calculate in order to compensate for price fluctuations http://tonto.eia.doe.gov/dnav/pet/hist/LeafHandler.ashx?n=pet&s=rgoeara5&f=a

I am curios, how are carrier shipping fees calculated in other countries? Are there fixed fees for several weight ranges? That's the only way a PrestaShop default configuration could be used out of the box.

Before my client contacted me, he used nothing except cash on delivery and bank wires. So he displayed no shipping costs on site, he would call the customers and announce shipping costs over the phone.

The client contacted me to add a credit card payment module, and i alerted them that they would need to include shipping costs onsite in the final order before the credit card payment was made. And in turn he talked to the carriers and came up with these crazy formulas.

I just hacked what was needed to make things work, and to ease the workload of updating these fees monthly/weekly.

I imagined it would be usefull for others as well since the most complex formula is TNT's and as far as i know TNT is a big shipping corporation that must mean other people in other countries must be using TNT as a carrier too and having the same complex formulas for their fees.

Link to comment
Share on other sites

I recently noticed the "is_module" column in the carrier table.

I read up on it here and got the big picture, custom carrier modules will soon be available.

With this in mind i think my changes on the core carrier functionality become less relevant.

It's still a neat trick, it takes 10 minutes to apply but it probably won't be worth the trouble after custom carrier modules start popping up.

Link to comment
Share on other sites

  • 3 weeks later...

Hello, can either of you tell me what file I could find the word "free" in when the calculation comes back to have it post "free" in the checkout summary? I just want to change the actual word that comes back there........but I can't find the file its in. Thank you.

Link to comment
Share on other sites

Thank you.....I read through the order.php and figured out I needed to be in the order-carrier.tpl file --------- what I was looking to change is at line 80

{l s='Free!'}

I changed it to : {l s='Please Call for Delivery Pricing!'}


Thanks again because your post got me in the right direction.........

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...