Jump to content

Help creating a carrier module


iambaz

Recommended Posts

I am creating a module which gets my shipping costs from an external API. I have ten carriers added to the system and I am using 'getPackageShippingCost()' hook to return a new shipping value. 

 

My problem is that when I use this hook, it returns the same value for all of the carriers listed. I want to be able to return a different value for each carrier but I don't know how to switch between them in the hook.

 

This is the code I have:

 

    public function getPackageShippingCost($cart, $shipping_cost, $products)
    {
        return 10;
    }
 
So this returns a shipping cost of £10 for every carrier. I want to be able to switch between them, so I imagined it would be something like:
 
    public function getPackageShippingCost($cart, $shipping_cost, $products)
    {
        if($this->current_carrier == "UPS"){
            return 15;
        } else {
            return 10;
        }
    }
 
So is there any way I can identify that 'current carrier'?
 
Thanks

 

Link to comment
Share on other sites

So the variable I was looking for was $this->id_carrier from within getPackageShippingCost()

 

You must make sure you have the parameter set in your module class:

 

class YourModName extends CarrierModule {
 
    public $id_carrier;
 
}
  • Like 1
Link to comment
Share on other sites

  • 4 weeks later...

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