Jump to content

Shipping cost with multi warehouses


Recommended Posts

I'm creating a shop with prestashop 1.6.0.8 and advanced warehouse enabled. I create three warehouses and some sample products to test it. The problem is that if I checkout from a cart containing two products of two diferrent warehouses the shipping costs are counted two times. Is there a way to not duplicate shipping if the products comes from different warehouses?

Link to comment
Share on other sites

right now its meant to be that way but the system should definatly let us choose if we want to make the client pay the cost of the second shipment or not

 

So it's not possible to count the shipping cost only once for now?

Link to comment
Share on other sites

  • 1 year later...
  • 8 months later...
  • 1 month later...

For me the same problem with PS 1.6.1.2 and Ps 1.6.1.3.

Nobody solved?

 

Hi Eugenata !

 

I bumped into this same issue recently, and when today, i was working on fixing it i found the code to modify.

So if you (if it's not too late) or anyone else find this post, here is where to modify:

 

The code is in the Class Cart.php in the function getDeliveryOptionList().

First, i would advice you to copy this function in your override file of Cart.php to prevent any issue and to keep the original code clean.

 

You need to look for "price_with_tax" and "price_without_tax".

 

Find:

$best_price_carrier[$id_carrier]['price_with_tax'] += $carriers_price[$id_address][$id_package][$id_carrier]['with_tax'];
$best_price_carrier[$id_carrier]['price_without_tax'] += $carriers_price[$id_address][$id_package][$id_carrier]['without_tax'];

and change the "+=" by "=" to remove the incrementation, like this:

$best_price_carrier[$id_carrier]['price_with_tax'] = $carriers_price[$id_address][$id_package][$id_carrier]['with_tax']; // count only 1 shipping fee whatever the number of packages.
$best_price_carrier[$id_carrier]['price_without_tax'] = $carriers_price[$id_address][$id_package][$id_carrier]['without_tax'];

Do the same for the 2 following pieces of code a few lines under by changing "+=" into "=" :

$best_grade_carrier[$id_carrier]['price_with_tax'] += $carriers_price[$id_address][$id_package][$id_carrier]['with_tax'];
$best_grade_carrier[$id_carrier]['price_without_tax'] += $carriers_price[$id_address][$id_package][$id_carrier]['without_tax'];
$price_with_tax += $carriers_price[$id_address][$id_package][$id_carrier]['with_tax'];
$price_without_tax += $carriers_price[$id_address][$id_package][$id_carrier]['without_tax'];

You will also need to do the same for the function getCarrierCost().

 

Finally, you will need to modify the class PaymentModule.

 

Look for the following code:

foreach ($package_list as $id_address => $packageByAddress) { 
    foreach ($packageByAddress as $id_package => $package) {

and insert, just outside the first loop, a flag that we will create to detect in which package we are.

$packageCount = 1;

Inside the second loop, look for the $order->total_shipping_tax_excl declaration and add a condition like this:

$order->total_shipping_tax_excl = ($packageCount === 1 ? (float)$this->context->cart->getPackageShippingCost((int)$id_carrier, false, null, $order->product_list) : 0.00);

So if it's not the 1st package, then the total_shipping_tax_excl is 0 (float).

Do the same for $order->total_shipping_tax_incl.

 

At the end of the second loop, don't forget to increment our new flag, so we know that we are on the next package.

$packageCount++;

That's it ! :)

 

I hope this will help ! Please comment if it worked well for you or not! For me it was perfect! :)

Cheers!

Edited by bbgun91 (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 4 months later...

Hi Eugenata !

 

I bumped into this same issue recently, and when today, i was working on fixing it i found the code to modify.

So if you (if it's not too late) or anyone else find this post, here is where to modify:

 

The code is in the Class Cart.php in the function getDeliveryOptionList().

First, i would advice you to copy this function in your override file of Cart.php to prevent any issue and to keep the original code clean.

 

You need to look for "price_with_tax" and "price_without_tax".

 

Find:

$best_price_carrier[$id_carrier]['price_with_tax'] += $carriers_price[$id_address][$id_package][$id_carrier]['with_tax'];
$best_price_carrier[$id_carrier]['price_without_tax'] += $carriers_price[$id_address][$id_package][$id_carrier]['without_tax'];

and change the "+=" by "=" to remove the incrementation, like this:

$best_price_carrier[$id_carrier]['price_with_tax'] = $carriers_price[$id_address][$id_package][$id_carrier]['with_tax']; // count only 1 shipping fee whatever the number of packages.
$best_price_carrier[$id_carrier]['price_without_tax'] = $carriers_price[$id_address][$id_package][$id_carrier]['without_tax'];

Do the same for the 2 following pieces of code a few lines under by changing "+=" into "=" :

$best_grade_carrier[$id_carrier]['price_with_tax'] += $carriers_price[$id_address][$id_package][$id_carrier]['with_tax'];
$best_grade_carrier[$id_carrier]['price_without_tax'] += $carriers_price[$id_address][$id_package][$id_carrier]['without_tax'];
$price_with_tax += $carriers_price[$id_address][$id_package][$id_carrier]['with_tax'];
$price_without_tax += $carriers_price[$id_address][$id_package][$id_carrier]['without_tax'];

You will also need to do the same for the function getCarrierCost().

 

Finally, you will need to modify the class PaymentModule.

 

Look for the following code:

foreach ($package_list as $id_address => $packageByAddress) { 
    foreach ($packageByAddress as $id_package => $package) {

and insert, just outside the first loop, a flag that we will create to detect in which package we are.

$packageCount = 1;

Inside the second loop, look for the $order->total_shipping_tax_excl declaration and add a condition like this:

$order->total_shipping_tax_excl = ($packageCount === 1 ? (float)$this->context->cart->getPackageShippingCost((int)$id_carrier, false, null, $order->product_list) : 0.00);

So if it's not the 1st package, then the total_shipping_tax_excl is 0 (float).

Do the same for $order->total_shipping_tax_incl.

 

At the end of the second loop, don't forget to increment our new flag, so we know that we are on the next package.

$packageCount++;

That's it ! :)

 

I hope this will help ! Please comment if it worked well for you or not! For me it was perfect! :)

Cheers!

 

A few months later....

 

bbgun91 YOU ROCKS !

It work for me, i made the two overrides and now, only one shipping cost for my customer :D

Link to comment
Share on other sites

  • 1 month later...

Hello,

I was looking for such long time for a solution regarding this issue.

Thank you for the hints.

 

Still I have a problem regarding the total order amount that is registered in backoffice and I really don't know how to solve it.

I mean that the solution works ok for the front office until the order is registered.

The cart shows the correct price and also in the back office inside the order details the shipping is applied only for one product.

 

But the TOTAL inside the order details and also inside the invoice, even the shipping is 0 for one of the orders, still show sum of the product + shipping price.

It should show only the products price.

 

Anyone can help me to fix this ?

Thank you,

Link to comment
Share on other sites

  • 4 weeks later...
  • 2 weeks later...
  • 2 months later...

Hi everybody,

 

this is a part of the final solution actually.

It could work as it is but if you have lot of warehouse and lot of different prices depending on range (weight or cart price), this solution will everytime take the last shipping price. And if you have a free shipping for a certain range, and different prices depending on range, the last price of the list (delivery_option_list) won't be the good one, maybe sometime but not always.

The solution has to be develop regarding ranges and prices.

Best regards.

Link to comment
Share on other sites

×
×
  • Create New...