I may be mistaken, but it looks like there's some missing code in the process behind registrering custom shipping methods. The event currently is only triggered on the getAvailableShippingMethods method; however, this doesn't allow us to define shipping methods that can be viewed within the native shipping methods list in the CP. If we look at ShippingMethods.php:66 getAllShippingMethods, which is used by the controller, it's only querying the database and forcing all shipping methods to be the default Craft Commerce type rather than creating them with the custom self-defined class.
public function getAllShippingMethods(): array
{
if (!$this->_fetchedAllShippingMethods) {
$results = $this->_createShippingMethodQuery()->all();
foreach ($results as $result) {
$shippingMethod = new ShippingMethod($result);
$this->_memoizeShippingMethod($shippingMethod);
}
$this->_fetchedAllShippingMethods = true;
}
return $this->_shippingMethodsById;
}
While the core functionality should still be there for pure-programmatic definition of shipping methods, it doesn't allow us to make use of the shipping method's full interface, such as "getCpEditUrl" where we might want to put settings for our shipping method.
Custom shipping methods no longer show up on the shipping method listing page, but they still can show up as available methods for an order.
Unlike the built in shipping method setup, plugin provided custom shipping methods can be dynamically generated depending on the order. In commerce 2 the RegisterAvailableShippingMethodsEvent contains the order parameter, so when plugins register their shipping methods an arbitrary number of shipping methods could be returned, making listing them in the control panel a little confusing.
Now that 2.1 is out we will introduce a new concept called a “shipping provider”, where plugins can register providers on the new main shipping screen in 2.1, and provide a link to edit their options.
Look for it in the next release.
Duplication of #29 - please discuss there.
Most helpful comment
Custom shipping methods no longer show up on the shipping method listing page, but they still can show up as available methods for an order.
Unlike the built in shipping method setup, plugin provided custom shipping methods can be dynamically generated depending on the order. In commerce 2 the
RegisterAvailableShippingMethodsEventcontains theorderparameter, so when plugins register their shipping methods an arbitrary number of shipping methods could be returned, making listing them in the control panel a little confusing.Now that 2.1 is out we will introduce a new concept called a “shipping provider”, where plugins can register providers on the new main shipping screen in 2.1, and provide a link to edit their options.
Look for it in the next release.