commerce icon indicating copy to clipboard operation
commerce copied to clipboard

[5.x]: craft project-config/apply fails with Undefined array key "name" when updating gateway orderCondition

Open romainpoirier opened this issue 3 months ago • 15 comments

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

  1. Start from a project running Craft Commerce 5.3.13 with project config enabled and at least one payment gateway configured (the one with UID ef65f7cc-2da0-4689-84da-9e3dd33f23ce in my case).

  2. Take a copy of the production database and restore it to a local/development environment.

  3. Update craftcms/commerce in composer.json from 5.3.13 to 5.5.0, then run:

    composer update craftcms/commerce
    ./craft migrate/all
    
  4. Run:

    ./craft project-config/apply
    
  5. 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/apply should complete successfully after the Commerce update.
  • The gateway’s orderCondition should be migrated/normalized correctly (including the case where it was previously null or 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/apply fails with error: Undefined array key "name" while applying config for the gateway ef65f7cc-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 name key exists in the gateway config array during project-config handling / migration of the orderCondition.

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 avatar Nov 24 '25 16:11 romainpoirier

COM-504

linear[bot] avatar Nov 24 '25 16:11 linear[bot]

@romainpoirier Just looking into this now. Hopefully i can reproduce.

lukeholder avatar Nov 26 '25 08:11 lukeholder

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!

nfourtythree avatar Nov 28 '25 13:11 nfourtythree

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!

romainpoirier avatar Dec 02 '25 13:12 romainpoirier

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!

nfourtythree avatar Dec 04 '25 14:12 nfourtythree

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"

romainpoirier avatar Dec 04 '25 14:12 romainpoirier

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 avatar Dec 09 '25 08:12 romainpoirier

@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!

lukeholder avatar Dec 09 '25 08:12 lukeholder

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!

romainpoirier avatar Dec 09 '25 08:12 romainpoirier

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 avatar Dec 09 '25 09:12 romainpoirier

@romainpoirier thanks, my co-worker supplied it to me.

I just took a look at your project config file and see this:

Image

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.

lukeholder avatar Dec 09 '25 09:12 lukeholder

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!

romainpoirier avatar Dec 09 '25 09:12 romainpoirier

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?

lukeholder avatar Dec 09 '25 12:12 lukeholder

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:

    • billingAddressCondition and shippingAddressCondition were added alongside the existing orderCondition.
  • For stripe--6f6a861f-5334-4a11-a280-c8426f107053.yaml:

    • An orderCondition block was added for the gateway.

    • elementType and fieldContext were added for:

      • billingAddressCondition
      • shippingAddressCondition
      • orderCondition
    • isFrontendEnabled changed from true (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.

romainpoirier avatar Dec 10 '25 15:12 romainpoirier

Could you send me your database backup to [email protected] The version that has this issue.

lukeholder avatar Dec 12 '25 08:12 lukeholder

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).

romainpoirier avatar Dec 30 '25 09:12 romainpoirier