Jump to content

[CONTRIB(?)] Recalculate shipping cost in AdminOrders when removing products


DenisDT

Recommended Posts

Hi all,

Has anyone noticed this (PS 1.2.5.0):

Let's say I have a carrier that has the following price ranges:
€0 -> €30 : shipping = €6
€30 -> €50 : shipping = €3
€50 -> €75 : shipping = €2
€75 -> €100 : shipping = €1
+€100: shipping = free

And let's say we open an order in Backoffice that is €79.
Shipping cost is, according to price ranges €1 (which is correct).

Now I remove soms products so the total order is €43 (due to customers wish or end-of-life products or whatever).
Shipping cost should be recalculated to €3, but that doesn't happen!

My solution (AdminOrders.php tab):

Add the following after line 592 (give or take, it's right below the "Display summary order" comment and before the echo):

       $result = Db::getInstance()->getRow('
       SELECT d.`price`
       FROM `'._DB_PREFIX_.'delivery` d
       LEFT JOIN `'._DB_PREFIX_.'range_price` r ON d.`id_range_price` = r.`id_range_price`
       WHERE d.`id_zone` = '.intval("1").'
       AND '.floatval($order->total_paid).' <= r.`delimiter2`
       AND d.`id_carrier` = '.intval($carrier->id).'
       ORDER BY r.`delimiter1` ASC');
       $result = floatval($result['price']);

       Db::getInstance()->Execute('
           UPDATE `'._DB_PREFIX_.'orders`
           SET `total_shipping` = '.$result.'
           WHERE `id_order` = '.$order->id);

       $order->total_shipping = $result;



This recalculates the shipping cost for the selected order based on actual total price, and displays the correct amounts in the order page.

Useful for anyone?

D.

Link to comment
Share on other sites

  • 1 month later...

No, i only adapted it to fit the needs of my client in this case.
But it can be extended to take weight in account too.
Remember, it's still a quick & dirty hack by replacing data in the database upon page loading...
I didn't have time for an elegant solution back then.

Good luck!
D.

Link to comment
Share on other sites

This is a bad hack. If you recalculate the shipping costs everytime the page loads you will not only slow down the page but also cause problems with old orders after changing the shipping costs. If you change the shipping costs and go to the order details in the backend, the shipping costs will change even if the order is already processed.

You should put this code somewhere after the comment "/* Cancel product from order */".

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...