-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[4.x]: getShippingMethod on Order can't find custom shipping options added by module #2986
Comments
Hi @hatyi Thank you for your message. Are you able to share your custom shipping method class? If you would rather not post it publicly you can send it over to support@craftcms.com where we can pick it up and take a look. Thanks! |
Hello @nfourtythree, thanks a lot for the quick response. Sure no problem, we use a base class we are extending by many others:
And this is an example of one we actually use:
|
Hi @hatyi Thank you for raising the issue. We have pushed fixes for both To get this early, change your "require": {
"craftcms/commerce": "dev-develop#a2b6413b41abd56cf61a6d8dc578488f2bbf61fc as 4.1.2",
"...": "..."
} Then run Thanks! |
What happened?
Description
Hello, I'm reaching out because I'm trying upgrade a Craft CMS + Commerce website from 3 to 4.
Specifically from Craft 3.5.19.1 and Commerce 3.2.7 to the latest available releases.
We have many custom shipping options added by our module using the EVENT_REGISTER_AVAILABLE_SHIPPING_METHODS event.
Everything works as expected until the point where I'm trying to save the selected custom shipping option on a cart using the standard
commerce/cart/update-cart
controller.I can query these options in twig by
cart.getAvailableShippingMethodOptions()
, and I can also see the selected option with the other available options in CP (if I check the cart, it shows up as a select input on the right panel with the "Shipping Method" label), the shippingMethodHandle attribute is also getting saved properly containing the selected options' handle.But it looks like that for some reason the cart itself can not resolve the shipping option by this saved handle. So it's actually not added to the cart, neither increases it's price.
I was trying to trace back the error in the
craftcms/commerce/src/elements/Order.php
class and I've found that inside thegetShippingMethod()
method thePlugin::getInstance()->getShippingMethods()
call returns an empty array and it looks like it runs before our module registers our custom shipping options.This is just absolutely a hunch from my side, maybe I'm doing something wrong here but since I couldn't find any related open issue or conversation about this I thought it's worth creating one to ask for help, report this.
Steps to reproduce
1.Try adding custom shipping options by a module, select it and save it to a cart.
Expected behavior
It's added to the cart, works as it would in Craft Commerce 3.
Actual behavior
Please see description.
Craft CMS version
4.2.2
Craft Commerce version
4.1.2
PHP version
8.1.9
Operating system and version
Ubuntu 20.04
Database type and version
MySQL 8.0.30
Image driver and version
No response
Installed plugins and versions
"ext-json": "*",
"aelvan/mailchimp-subscribe": "^4.0.0",
"algolia/algoliasearch-client-php": "^2.7",
"clubstudioltd/craft-asset-rev": "^7.0",
"craftcms/cms": "4.2.2",
"craftcms/commerce": "4.1.2",
"craftcms/commerce-omnipay": "^4.0",
"craftcms/redactor": "^3.0.0",
"dolphiq/redirect": "2.0.0",
"league/omnipay": "^3",
"mailchimp/marketing": "^3.0",
"mmikkel/incognito-field": "1.3.0",
"monolog/monolog": "^2.8",
"nystudio107/craft-seomatic": "^4.0.0",
"verbb/navigation": "^2.0.0",
"verbb/super-table": "^3.0.0",
"vlucas/phpdotenv": "^3.4.0"
The text was updated successfully, but these errors were encountered: