[5.x]: craft project-config/apply fails with Undefined array key "name" when updating gateway orderCondition
What happened?
Description
When updating Craft Commerce from 5.3.13 to 5.5.0 on a development environment using a production database, ./craft project-config/apply fails with:
error: Undefined array key "name"
The error happens while applying project config changes for one specific gateway, right after removing its orderCondition key. It looks related to the new orderCondition handling and the m251112_120000_fix_null_gateway_order_condition migration that was added in the commit fixing #4172.
Relevant log output:
Applying changes from your project config files ...
- removing commerce.gateways.ef65f7cc-2da0-4689-84da-9e3dd33f23ce.orderCondition ...
- updating commerce.gateways.ef65f7cc-2da0-4689-84da-9e3dd33f23ce ...
error: Undefined array key "name"
The gateway referenced here corresponds to the project config file:
config/project/commerce/gateways/ef65f7cc-2da0-4689-84da-9e3dd33f23ce.yaml
There are no manual edits to this file beyond what the Control Panel and project config normally generate.
Steps to reproduce
-
Start from a project running Craft Commerce
5.3.13with project config enabled and at least one payment gateway configured (the one with UIDef65f7cc-2da0-4689-84da-9e3dd33f23cein my case). -
Take a copy of the production database and restore it to a local/development environment.
-
Update
craftcms/commerceincomposer.jsonfrom5.3.13to5.5.0, then run:composer update craftcms/commerce ./craft migrate/all -
Run:
./craft project-config/apply -
Observe that the command stops with:
- removing commerce.gateways.ef65f7cc-2da0-4689-84da-9e3dd33f23ce.orderCondition ... - updating commerce.gateways.ef65f7cc-2da0-4689-84da-9e3dd33f23ce ... error: Undefined array key "name"
Expected behavior
-
./craft project-config/applyshould complete successfully after the Commerce update. - The gateway’s
orderConditionshould be migrated/normalized correctly (including the case where it was previouslynullor missing), without triggering PHP warnings or errors. - Existing gateways should continue to work and be editable in the Control Panel.
Actual behavior
-
./craft project-config/applyfails witherror: Undefined array key "name"while applying config for the gatewayef65f7cc-2da0-4689-84da-9e3dd33f23ce. - Project config changes can’t be fully applied, so the instance is effectively stuck until the error is resolved.
- The error message points to an internal assumption that a
namekey exists in the gateway config array during project-config handling / migration of theorderCondition.
Note: The stack trace does not provide any additional information.
Craft CMS version
5.8.20
Craft Commerce version
5.5.0
PHP version
No response
Operating system and version
No response
Database type and version
No response
Image driver and version
No response
Installed plugins and versions
@romainpoirier Just looking into this now. Hopefully i can reproduce.
Hi @romainpoirier
Thank you for reporting this, we have pushed up a fix which will be included in the next release of Commerce.
To get this early, change your craftcms/commerce requirement in your project's composer.json to:
"require": {
"craftcms/commerce": "5.x-dev as 5.5.0.1",
"...": "..."
}
Then run composer update.
Thanks!
After updating to "craftcms/commerce": "5.x-dev as 5.5.0.1" and running composer update, I am still encountering the following error:
./craft project-config/apply
Applying changes from your project config files ...
- removing commerce.gateways.ef65f7cc-2da0-4689-84da-9e3dd33f23ce.orderCondition ...
- updating commerce.gateways.ef65f7cc-2da0-4689-84da-9e3dd33f23ce ...
error: Undefined array key "name"
Failed to execute command `./craft project-config/apply`: exit status 1
Could you please investigate this issue? Also, do you have an estimated release date for the public fix?
Thank you!
Hi @romainpoirier
Commerce 5.5.1 has just been released, could you try updating to that version and let us know if the problem still exists.
Thanks!
With Commerce 5.5.1 and Craft CMS 5.8.20, I still get this error when applying the project config:
./craft project-config/apply
Applying changes from your project config files ...
- removing commerce.gateways.ef65f7cc-2da0-4689-84da-9e3dd33f23ce.orderCondition ...
- updating commerce.gateways.ef65f7cc-2da0-4689-84da-9e3dd33f23ce ...
error: Undefined array key "name"
Is there still no fix for this? It’s quite restrictive, as it prevents a clean project-config sync when deploying to production. As mentioned, the issue is still present in 5.5.1. It may be related to the default dummy gateway, since the error occurs even when that gateway is not used and another gateway is configured.
@romainpoirier Can you please send your 5.3.13 database backup, composer.lock and composer.json, and a copy of your config folder to [email protected] so we can take a look. It looks like something is broken in your installation. Thanks!
Here’s what I’m currently running:
dev / staging:
"craftcms/cms": "5.8.20"
"craftcms/commerce": "5.5.1"
production:
"craftcms/cms": "5.8.18"
"craftcms/commerce": "5.4.8"
Which database version would you like me to use?
You already have this project and its database from another ticket you handled recently in parallel to this one, sent under the subject: Commerce pricing catalog generation error – minimal reproducible case for GitHub issue #4175.
Have you already tested with these versions?
Thanks!
I dug a bit more into the gateway that was causing the issue (ef65f7cc-2da0-4689-84da-9e3dd33f23ce) and found that its project config file was effectively incomplete.
Under:
config/project/commerce/gateways/ef65f7cc-2da0-4689-84da-9e3dd33f23ce.yaml
the file only contained:
billingAddressCondition:
class: craft\commerce\elements\conditions\addresses\GatewayAddressCondition
shippingAddressCondition:
class: craft\commerce\elements\conditions\addresses\GatewayAddressCondition
So there was no name, handle, type, paymentType, or settings defined for this gateway. That explains why the migration / project-config handling was failing with an undefined name and later with SQL errors: Commerce was trying to work with a gateway whose core properties were missing from the project config.
As a workaround, manually correcting that file to include a minimal, valid gateway definition resolved the problem for me. For example:
handle: legacyDummy
name: 'Legacy dummy gateway'
type: craft\commerce\gateways\Dummy
paymentType: purchase
isFrontendEnabled: false
sortOrder: 98
settings: { }
billingAddressCondition:
class: craft\commerce\elements\conditions\addresses\GatewayAddressCondition
shippingAddressCondition:
class: craft\commerce\elements\conditions\addresses\GatewayAddressCondition
After adding those fields, running:
./craft project-config/apply
completed successfully again.
Is there a way to make this fix more robust and permanent in Commerce itself, so that this workaround (or an equivalent safeguard) is available to everyone—for example by validating gateway project config and handling incomplete definitions more gracefully?
@romainpoirier thanks, my co-worker supplied it to me.
I just took a look at your project config file and see this:
This means that in the entry for the Stripe gateway in the project/commerce/gateways/stripe--6f6a861f-5334-4a11-a280-c8426f107053.yaml config at some point was saved with a missing Stripe plugin installed. If you know that Stripe for commerce is now installed, you can fix that by changing the Type value back to craft\commerce\stripe\gateways\PaymentIntents and apply gain. Or try resaving the gateway in the UI in development to rebuild the config entry for the Stripe gateway.
I would do this in development and then deploy staging again.
Sorry about the confusion — the version I provided to your colleague is not the actual staging/production project, but a reduced test case where I had to uninstall all plugins so that the Commerce issue could be clearly identified.
Are you able to reproduce the issue with the following configuration (under config/project/commerce/gateways/ef65f7cc-2da0-4689-84da-9e3dd33f23ce.yaml), as mentioned earlier?
billingAddressCondition:
class: craft\commerce\elements\conditions\addresses\GatewayAddressCondition
shippingAddressCondition:
class: craft\commerce\elements\conditions\addresses\GatewayAddressCondition
If not, please let me know the minimum setup you would need in order to reproduce the issue.
Thanks!
If you only have
billingAddressCondition:
class: craft\commerce\elements\conditions\addresses\GatewayAddressCondition
shippingAddressCondition:
class: craft\commerce\elements\conditions\addresses\GatewayAddressCondition
in that file then it is invalid and I don't know how it could have got into that state.
Can you go to the gateway UI page for the Stripe gateway in development, save it in the UI and look at the file again?
After your suggestion, here is what I had before re-saving the gateway in the CP.
config/project/commerce/gateways/ef65f7cc-2da0-4689-84da-9e3dd33f23ce.yaml (before):
orderCondition:
class: craft\commerce\elements\conditions\orders\GatewayOrderCondition
config/project/commerce/gateways/stripe--6f6a861f-5334-4a11-a280-c8426f107053.yaml (before):
billingAddressCondition:
class: craft\commerce\elements\conditions\addresses\GatewayAddressCondition
handle: stripe
isFrontendEnabled: true
name: Stripe
paymentType: purchase
settings:
apiKey: $STRIPE_PRIVATE_KEY
publishableKey: $STRIPE_PUBLIC_KEY
sendReceiptEmail: false
signingSecret: $STRIPE_WEBHOOK_SIGNING_SECRET
shippingAddressCondition:
class: craft\commerce\elements\conditions\addresses\GatewayAddressCondition
sortOrder: 99
type: craft\commerce\stripe\gateways\PaymentIntents
Changes after re-saving the gateway
After opening the Stripe gateway in the CP (in development) and saving it once, the following changes were applied to the project config:
-
For
ef65f7cc-2da0-4689-84da-9e3dd33f23ce.yaml:-
billingAddressConditionandshippingAddressConditionwere added alongside the existingorderCondition.
-
-
For
stripe--6f6a861f-5334-4a11-a280-c8426f107053.yaml:-
An
orderConditionblock was added for the gateway. -
elementTypeandfieldContextwere added for:-
billingAddressCondition -
shippingAddressCondition -
orderCondition
-
-
isFrontendEnabledchanged fromtrue(boolean) to'1'(string), which appears to be how the UI now serializes that setting.
-
Here is the current state of the files after re-saving:
config/project/commerce/gateways/ef65f7cc-2da0-4689-84da-9e3dd33f23ce.yaml (after):
billingAddressCondition:
class: craft\commerce\elements\conditions\addresses\GatewayAddressCondition
orderCondition:
class: craft\commerce\elements\conditions\orders\GatewayOrderCondition
shippingAddressCondition:
class: craft\commerce\elements\conditions\addresses\GatewayAddressCondition
config/project/commerce/gateways/stripe--6f6a861f-5334-4a11-a280-c8426f107053.yaml (after):
billingAddressCondition:
class: craft\commerce\elements\conditions\addresses\GatewayAddressCondition
elementType: null
fieldContext: global
handle: stripe
isFrontendEnabled: '1'
name: Stripe
orderCondition:
class: craft\commerce\elements\conditions\orders\GatewayOrderCondition
elementType: craft\commerce\elements\Order
fieldContext: global
paymentType: purchase
settings:
apiKey: $STRIPE_PRIVATE_KEY
publishableKey: $STRIPE_PUBLIC_KEY
sendReceiptEmail: false
signingSecret: $STRIPE_WEBHOOK_SIGNING_SECRET
shippingAddressCondition:
class: craft\commerce\elements\conditions\addresses\GatewayAddressCondition
elementType: null
fieldContext: global
sortOrder: 99
type: craft\commerce\stripe\gateways\PaymentIntents
After these changes, running project-config/sync no longer throws any errors.
From what I can see, this looks like a valid gateway config again (especially now that the conditions have elementType and fieldContext, and the orderCondition is properly defined on the Stripe gateway), and it seems safe to commit and apply on production. If you see anything unexpected in this updated config, please let me know.
Could you send me your database backup to [email protected] The version that has this issue.
Sorry for the late reply — I’ve been very busy.
As mentioned in my last message, I believe everything is working on our side. That said, I ended with: “If you see anything unexpected in this updated config, please let me know.” Do you still notice anything that looks unusual or off?
I’m asking because our database anonymization process takes quite a while (there’s a large volume of records we can’t share).