Console Commands
Commerce supplements Craft’s own console commands with a few utilities that can help you manage your storefront’s data.
# commerce/example-templates
Copies the example templates that Commerce ships with into your project’s template folder.
$ php craft commerce/example-templates
A folder will be copied to your templates directory.
Choose folder name: [shop] myshop
Copying ...
Done!
Pass the --overwrite
flag if you’d like to squash an existing folder of the same name.
# commerce/reset-data
Cleanses Commerce data without uninstalling the plugin or removing store configuration. This can be useful for removing test data after finishing initial project development.
Deletes all orders, subscriptions, payment sources, customers, addresses and resets discount usages.
$ php craft commerce/reset-data
# commerce/transfer-user-data
4.3.0+
Transfers customer data from one user to another. You will be prompted for the username or email of the source and destination users.
$ php craft commerce/transfer-user-data
Updates are performed via low-level database queries, so element events are not emitted and plugins are not given an opportunity to alter this behavior. This also serves to speed up the process of saving large amounts of data.
# commerce/upgrade
Support command for the Commerce 3 → Commerce 4 upgrade process; meant to be run after upgrading to Commerce 4.
$ php craft commerce/upgrade
It goes through several steps to ensure the best-possible migration:
- Checks that the standard migration has already been run.
- Prompts for any custom countries that should be swapped to valid two-letter country codes, which will be used to update all addresses and zones.
- Prompts to select an existing field handle or create a new custom field on the fly for any legacy address fields that were used with Commerce 3:
title
address3
businessId
phone
alternativePhone
custom1
custom2
custom3
custom4
notes
- Converts all legacy customers without user accounts into users.
- Converts all existing addresses to address elements.
- Links all user addresses to the appropriate address elements.
- Links all order addresses to the appropriate address elements.
- Maps each user’s primary billing and shipping IDs to the appropriate address elements.
- Creates tax and shipping zone conditions based on legacy country and state lists.
- Links the store location address to the appropriate address element.
- Links order history records to their appropriate user accounts.
- Migrates previously-enabled countries to the store’s Country List and creates an Order Address Condition as needed.