Jump to content

Disable Carrier in FrontEnd from Shipping / Carrier Module


Recommended Posts

Hello.

 

I am developing a carrier module, used for calculating shipping costs for orders. The module creates a carrier, and gets the shipping costs depending on zipcode, weight and cost of the order. The external API returns a value for the cost, or false if there is no shipping available for that combination.

 

I would like to handle this by disabling or removing the carrier on the front end, so customers would not see that carrier in those specific options.

 

There is always a default option for picking up the order at the store, but I would like the other carrier to only be shown if the shipping is actually available. Is this possible, either by tapping into the cart object and setting some options, without messing with the Prestashop core code? Or would I have to edit the checkout templates and code? Can anyone point me to the correct way of doing this?

 

Thank you in advance.

 

<?php
if (!defined('_PS_VERSION_')) exit;

class ShippingCalculator extends CarrierModule {
  public function getOrderShippingCost($params, $shipping_cost) {

    $apiValue = getValueFromExternalAPI();
    // returns shipping cost for zipcode, weight and price, or false if shipping is no available

    return $apiValue;
  }
}

 

Link to comment
Share on other sites

consider Carrier.php function getAvailableCarrierList

 

this returns carriers based on carrier configuration.

 

at the end of class, it returns an array of avail carriers, you maybe able to squash return of your carrier as it pleases you.

 

But because you also use zip codes,  then you also need logged in or way for visitor to input their zip code...it's tricky business. :)

Link to comment
Share on other sites

Hello El Patron.

 

Thank you for the tip.

 

In the meanwhile I have been able to achieve what I needed without messing with Carrier.php, only through my class code, which was what I was after.

 

Oh good!  I just happen to be working in that area for another project, it takes a bit more 'drastic' solution.  Not having a dependency outside or your foot print makes for a much better module.  Happy day, el

Link to comment
Share on other sites

  • 2 years later...
On 10/5/2016 at 10:38 AM, alfasoft said:

Hello El Patron.

 

Thank you for the tip.

 

In the meanwhile I have been able to achieve what I needed without messing with Carrier.php, only through my class code, which was what I was after.

Hi there, 

I know this is an old post but if you still have that code somewhere, I'm doing something similar and it'd be very useful, so if you could send it, that'd be amazing.

Have a nice day, 

MD.

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