Jump to content

[solved] PS 1.4.8.2. Free Shipping for one carrier only


jassy

Recommended Posts

dear All

actually this is a repeated discussion. but due to the original discussion took place 3yrs ago, the tips are no longer applicable to me.

here's the former forum link solution provided by Ion_cannon:

http://www.prestasho...e-carrier-only/

 

despite 3yrs already, i noticed prestashop still has not decided to include this feature, the present version im using (1.4.8.2) still has the free shipping feature (whether by weight or by price) implemented to all carriers.

 

here's the php code for my version:

 

classes/Cart.php find //Free fees:

 

// Free fees

$free_fees_price = 0;

if (isset($configuration['PS_SHIPPING_FREE_PRICE']))

$free_fees_price = Tools::convertPrice((float)($configuration['PS_SHIPPING_FREE_PRICE']), Currency::getCurrencyInstance((int)($this->id_currency)));

$orderTotalwithDiscounts = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING);

if ($orderTotalwithDiscounts >= (float)($free_fees_price) AND (float)($free_fees_price) > 0)

return $shipping_cost;

if (isset($configuration['PS_SHIPPING_FREE_WEIGHT']) AND $this->getTotalWeight() >= (float)($configuration['PS_SHIPPING_FREE_WEIGHT']) AND (float)($configuration['PS_SHIPPING_FREE_WEIGHT']) > 0)

return $shipping_cost;

 

 

i hv 2 carriers now, 1) carrier in local country (carrier ID: 37) & 2) carrier to my neighbour country (carrier ID: 36)

could anyone pls advise me how to configure free shipping for 1) carrier in local country (carrier ID: 37) & no free shipping applicable to 2) carrier to my neighbour country (carrier ID: 36).

 

then in the event i hv more carriers for countries that has no free shipping, what do i do as well?

 

highly appreciate some assistance here.

rgds

jassy

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

Hello,

 

I'm currently developing an module, that extends the freeshipping capabilities of prestashop. It will be able to provide the functionalities you want and many more.

 

http://www.prestasho...d-free-shipping

 

Keep looking into that thread, I will update as soon as it is releasable.

 

Till then, here a quick fix for your problem.

First get the carrier id for the carrier you want to deactivate freeshipping (I will refer to this ID as 'A-ID' in the code) for.

You can get this id by going to the admin panel -> carriers and clicking edit on the carrier, then look at the address on top and extract "id_carrier=xx", the "xx" is the carrier id.

 

Now look for the code:

$free_fees_price = 0;
 if (isset($configuration['PS_SHIPPING_FREE_PRICE']))
  $free_fees_price = Tools::convertPrice((float)($configuration['PS_SHIPPING_FREE_PRICE']), Currency::getCurrencyInstance((int)($this->id_currency)));
 $orderTotalwithDiscounts = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING);
 if ($orderTotalwithDiscounts >= (float)($free_fees_price) AND (float)($free_fees_price) > 0)
  return $shipping_cost;
 if (isset($configuration['PS_SHIPPING_FREE_WEIGHT']) AND $this->getTotalWeight() >= (float)($configuration['PS_SHIPPING_FREE_WEIGHT']) AND (float)($configuration['PS_SHIPPING_FREE_WEIGHT']) > 0)
  return $shipping_cost;

 

and replace it with this:

 

Replace A-ID with the corresponding carrier id.

 

$disable_freeshipping = array(A-ID);

$free_fees_price = 0;
 if (isset($configuration['PS_SHIPPING_FREE_PRICE']))
  $free_fees_price = Tools::convertPrice((float)($configuration['PS_SHIPPING_FREE_PRICE']), Currency::getCurrencyInstance((int)($this->id_currency)));
 $orderTotalwithDiscounts = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING);
 if ($orderTotalwithDiscounts >= (float)($free_fees_price) AND (float)($free_fees_price) > 0)
  return $shipping_cost;
 if (isset($configuration['PS_SHIPPING_FREE_WEIGHT']) AND !in_array($id_carrier, $disable_freeshipping) AND $this->getTotalWeight() >= (float)($configuration['PS_SHIPPING_FREE_WEIGHT']) AND (float)($configuration['PS_SHIPPING_FREE_WEIGHT']) > 0)
  return $shipping_cost;

 

Everytime you edit the carrier in the admin panel now, the ID of the carrier will change, so you will have to update the ID in the code above by changing the variable $disable_freeshipping accordingly.

 

By adding more carriers to $disable_freeshipping (so it'll look something like $disable_freeshipping = array(A-ID, 3, 32, 23)), each of these carrier's will be deactivated for freeshipping.

 

I hope it works.

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

Hello,

 

I'm currently developing an module, that extends the freeshipping capabilities of prestashop. It will be able to provide the functionalities you want and many more.

 

http://www.prestasho...d-free-shipping

 

Keep looking into that thread, I will update as soon as it is releasable.

 

Till then, here a quick fix for your problem.

First get the carrier id for the carrier you want to deactivate freeshipping (I will refer to this ID as 'A-ID' in the code) for.

You can get this id by going to the admin panel -> carriers and clicking edit on the carrier, then look at the address on top and extract "id_carrier=xx", the "xx" is the carrier id.

 

Now look for the code:

$free_fees_price = 0;
 if (isset($configuration['PS_SHIPPING_FREE_PRICE']))
  $free_fees_price = Tools::convertPrice((float)($configuration['PS_SHIPPING_FREE_PRICE']), Currency::getCurrencyInstance((int)($this->id_currency)));
 $orderTotalwithDiscounts = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING);
 if ($orderTotalwithDiscounts >= (float)($free_fees_price) AND (float)($free_fees_price) > 0)
  return $shipping_cost;
 if (isset($configuration['PS_SHIPPING_FREE_WEIGHT']) AND $this->getTotalWeight() >= (float)($configuration['PS_SHIPPING_FREE_WEIGHT']) AND (float)($configuration['PS_SHIPPING_FREE_WEIGHT']) > 0)
  return $shipping_cost;

 

and replace it with this:

 

Replace A-ID with the corresponding carrier id.

 

$disable_freeshipping = array(A-ID);

$free_fees_price = 0;
 if (isset($configuration['PS_SHIPPING_FREE_PRICE']))
  $free_fees_price = Tools::convertPrice((float)($configuration['PS_SHIPPING_FREE_PRICE']), Currency::getCurrencyInstance((int)($this->id_currency)));
 $orderTotalwithDiscounts = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING);
 if ($orderTotalwithDiscounts >= (float)($free_fees_price) AND (float)($free_fees_price) > 0)
  return $shipping_cost;
 if (isset($configuration['PS_SHIPPING_FREE_WEIGHT']) AND !in_array($id_carrier, $disable_freeshipping) AND $this->getTotalWeight() >= (float)($configuration['PS_SHIPPING_FREE_WEIGHT']) AND (float)($configuration['PS_SHIPPING_FREE_WEIGHT']) > 0)
  return $shipping_cost;

 

Everytime you edit the carrier in the admin panel now, the ID of the carrier will change, so you will have to update the ID in the code above by changing the variable $disable_freeshipping accordingly.

 

By adding more carriers to $disable_freeshipping (so it'll look something like $disable_freeshipping = array(A-ID, 3, 32, 23)), each of these carrier's will be deactivated for freeshipping.

 

I hope it works.

 

I hope you will have it prepared soon...

I´m looking forward having a tool like yours

 

Klaus

Link to comment
Share on other sites

hi genix,

good evening to you. so glad to see someone has actually revert to me on this & apologised for the late reply as i hv not been feeling well the last few days.

 

i hv gone thru your recommended thread i.e. the freeshipping.exe. however, this module is not applicable to me for the time being because i hv had fewer product range at the moment & thus need not have to hv too many different free shipping condition for different category or product.

 

nevertheless, i had like to try out your above html codes. im trying to locate the platform to change these codes, my guess is i should be looking thru the public_html/modules/ & look for the original prestashop shipping estimation module. but i hadnt found anything with that similar name other than the carriercompare folder & carriercompare.php file.

 

could you pls advise me the right platform to locate your stated codes.

 

highly appreciate that.

rgds

jassy

Link to comment
Share on other sites

dear genix

i hv tried replacing your codes, but it doesnt give any sort of difference to my website. the following is what i hv done:

1) using file manager to locate public_html/classes/cart.php

2) copy your fix to replace the original (starting from line approx. 1145)

3) change carrier id from A-ID to no. 40 (the carrier i didnt want to hv free shipping)

4) save changes

5) go to BO/Preferences/Performance/set force compile yes & cache no

6) view my shop, check, it's is still the same meaning the carrier i didnt want to hv free shipping is still providing free shipping like my default carrier.

 

appreciate your further advise on this matter.

Link to comment
Share on other sites

Hello,

 

Ok, I forgot something, didn't test the code, but this should work now:

 

$disable_freeshipping = array(A-ID);

$free_fees_price = 0;
 if (isset($configuration['PS_SHIPPING_FREE_PRICE']))
  $free_fees_price = Tools::convertPrice((float)($configuration['PS_SHIPPING_FREE_PRICE']), Currency::getCurrencyInstance((int)($this->id_currency)));
 $orderTotalwithDiscounts = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING);
 if ($orderTotalwithDiscounts >= (float)($free_fees_price) AND (float)($free_fees_price) > 0 AND !in_array($id_carrier, $disable_freeshipping))
  return $shipping_cost;
 if (isset($configuration['PS_SHIPPING_FREE_WEIGHT']) AND !in_array($id_carrier, $disable_freeshipping) AND $this->getTotalWeight() >= (float)($configuration['PS_SHIPPING_FREE_WEIGHT']) AND (float)($configuration['PS_SHIPPING_FREE_WEIGHT']) > 0)
  return $shipping_cost;

 

Just replace the previous code, with the above one.

 

Good luck.

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

Hi genix, your fix works fine for me, thanks a lot!

 

Just one thing: when the customer applys a free shipping voucher, he can still see all shipping options.... what can I do about that?

 

The same for me. I have free shipping expending 80 or more € and 3 carriers, and I want to offer free shipping with 1 or 2, not with all.

 

Transportistas.png

 

In this case I offer the 24 h for free. Obviously, the 72 h is also free, but it appears as free also the 14 h.

Link to comment
Share on other sites

hi,

 

i use 1.4.4 and the classes/Cart.php edit works perfect.

(one remark: when you edit a carrier in the backend, it saves the edit as a new iD! so make sure to edit the ID in the code when you edited the carrier in the backend - probably this is a bug and is fixed in newer versions...)

 

anyone has a solution for the 'free shipping voucher'? we use this kind of voucher a lot, but this should not be valid for 'express delivery option', which costs us much more...

 

thank you

Link to comment
Share on other sites

  • 4 months later...
  • 2 months later...
  • 6 months later...

thanks for this hack, with it being relatively easy to do i am suprised this has not been included in prestashop by default. It could just be a tick box next to the carrier saying 'disable from free shipping'

----

in ps 1.5 not work, someone can help me pls??

in ps 1.5 this is original code:

 

// Free fees
$free_fees_price = 0;
if (isset($configuration['PS_SHIPPING_FREE_PRICE']))
$free_fees_price = Tools::convertPrice((float)$configuration['PS_SHIPPING_FREE_PRICE'], Currency::getCurrencyInstance((int)$this->id_currency));
$orderTotalwithDiscounts = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING, null, null, false);
if ($orderTotalwithDiscounts >= (float)($free_fees_price) && (float)($free_fees_price) > 0)
{
Cache::store($cache_id, $shipping_cost);
return $shipping_cost;
}
Link to comment
Share on other sites

  • 1 month later...

1.5.6:

 

 

        // Free fees
        $disable_freeshipping = array('7');
        $free_fees_price = 0;
        if (isset($configuration['PS_SHIPPING_FREE_PRICE']))
            $free_fees_price = Tools::convertPrice((float)$configuration['PS_SHIPPING_FREE_PRICE'], Currency::getCurrencyInstance((int)$this->id_currency));
        $orderTotalwithDiscounts = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING, null, null, false);
        if ($orderTotalwithDiscounts >= (float)($free_fees_price) && (float)($free_fees_price) > 0 && !in_array($id_carrier, $disable_freeshipping))
        {
            Cache::store($cache_id, $shipping_cost);
            return $shipping_cost;
        }

        if (isset($configuration['PS_SHIPPING_FREE_WEIGHT'])
            && $this->getTotalWeight() >= (float)$configuration['PS_SHIPPING_FREE_WEIGHT']
            && (float)$configuration['PS_SHIPPING_FREE_WEIGHT'] > 0
            && !in_array($id_carrier, $disable_freeshipping))
        {
            Cache::store($cache_id, $shipping_cost);
            return $shipping_cost;
        }
  • Like 1
Link to comment
Share on other sites

  • 1 year later...

Husar changes works like a charm.

Just to explain exactly what you have to do:

 

Add this (change the number 7 with your carrier's id that you don't want to have free shipping)

$disable_freeshipping = array('7');

before this

$free_fees_price = 0;

and before this

&& (float)($free_fees_price) > 0)

add this

&& !in_array($id_carrier, $disable_freeshipping)

If you just want to have free shipping only on one carrier (the method above could be used for multiple carriers)

 

just add this (change the 1 with the id of the carrier you want to have free shipping)

AND $id_carrier==1

before this

&& (float)($free_fees_price) > 0)
Edited by AlexFL (see edit history)
Link to comment
Share on other sites

  • 1 year later...
Guest
This topic is now closed to further replies.
×
×
  • Create New...