Search code examples
phpprestashopsmarty

Set free shipping depending total cart price | Prestashop 1.7.7.2


I'm coming to you because I'm actually developping a module to allow the possibility to set free shipping depending of the total amount of the cart, even if the carrier is set on a range weight model.

I've tried many solutions, first of them is doing a carrier Module :

  • Even if I used the functions set for CarrierModule to calculate shipping cost, it seems that the carrier not made through this module were not using the function to calculate the shippping through the module.

So I tried another way, modify shipping cost through the hook ActionCartSave:

  • It seems that is not possible to modify the shipping price of the cart directly from his module.

My actual plan is now to create a delivery option (table miib_delivery), it seems that this is use to calculate shipping cost, based on the range of price or weight set, I've been able to generate my range price and my delivery option, but for an obscur reason, my delivery option is not used when calculating the shipping.

So here are the solutions that I already though about but are impossible in my case :

  • Create a new carrier that will be free over € -> It won't be linked to the initial carrier Module, which is really important for setting the relay, and printing the shipping label

  • Modify the shipping price dinamically in the DB -> Surely the worst idea I had

Here are the worst solutions :

  • Override Cart or Carrier class -> Override is risky, moreover I'm using custom class made in my module to generate object of my free shipping carrier, so it might create conflicts between all (carrier module , ect).

I'm quiet lost on the best way to do this, the most efficient and the most scalable between PS versions, olders and newers.

If somebody has already faced the same issue, please help me, I know there is many way to do it, but I don't just wan't to do it, I wan't to do it properly.


Solution

  • Finally, I've made an override of Cart class, of the getPackageShippingCost function