1

I'm looking to add additional shipping methods through a plugin, using the documentation here: https://craftcommerce.com/docs/shipping-methods

I'm a little bit lost about how to hook things up, according to the docs I'm supposed to do:

public function commerce_registerShippingMethods()
{
    return [new CustomShipper_CourierDeliveryMethod()];
}

The docs don't really cover where and how to do this, other than to include it in the base plugin file. That part I can follow. Could someone help me understand what file to create, the basics of what it should include and how to connect it (referring to new CustomShipper_CourierDeliveryMethod())?

This is new to me for Craft Plugin development - I'm used to connecting to files using something like:

return [craft()->pluginHandle_serviceName->function_name()];

Which obviously is very differently than the above. Any help would be HUGELY appreciated.. thanks!

3

Ok, so what you're doing is returning a new instance of a shipping method class - this class must meet the Shipping Method interface - documented here: https://craftcommerce.com/docs/shipping-methods#shipping-method-interface

That is, you must implement each of those functions as defined by the interface in your shipping method class.

You'd define this class in a file of it's own named after the class, and in your base plugin file you require this class definition to bring it in to scope.

The same goes for your shipping rules - you again create a class that meets the interface and then require that in your main plugin file (or wherever you need to access the rule).

  • Am I supposed to extend or implements my custom shipping method class to a specific class? I run into this error: "Argument 2 passed to Craft\Commerce_ShippingMethodsService::getMatchingShippingRule() must implement interface Commerce\Interfaces\ShippingMethod, instance of Craft\MyShippingMethod given" – taylor Sep 29 '16 at 16:07
  • I figured it out. The shipping method class needed to 'implements \Commerce\Interfaces\ShippingMethod '. Thanks for the help in figuring out how to hook this all up! – taylor Sep 29 '16 at 18:46
  • Good stuff, glad you're off an running. The hardest part is the structure - once you have that the actual calculator is usually relatively simple ( - and sorry I am in Aus so hard to respond promptly!) – Jeremy Daalder Sep 29 '16 at 23:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.