iambaz Posted October 14, 2015 Share Posted October 14, 2015 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 More sharing options...
iambaz Posted October 14, 2015 Author Share Posted October 14, 2015 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; } 1 Link to comment Share on other sites More sharing options...
presta911 Posted November 10, 2015 Share Posted November 10, 2015 (edited) Thanks Iambaz! Your post helped me out a lot. Have you hardcoded the $this->id_carrier==123 into the getPackageShippingCost function? Or have you figured a way to make that configurable? Edited November 10, 2015 by presta911 (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now