Configuring Commerce

Commerce supports a number of settings. Like Craft’s config settings, you can override their default values in a config/commerce.php file.

return [
    'purgeInactiveCartsDuration' => 'P1D',
];

# Aliases

Commerce adds these aliases on top of those provided by Craft.

Alias Description
@commerceLib The path to vendor/craftcms/commerce/lib/

# Environmental Configuration

Some Commerce settings should be defined on a per-environment basis.

  • System Settings
    • General Settings
      • Email
        • Status Email Address
        • From Name
      • Subscription Settings
        • Billing detail update URL

# PHP Constants

# COMMERCE_PAYMENT_CURRENCY

This constant can be used to lock a valid payment currency ISO code, which otherwise defaults to the primary currency.

# Project Config

Craft Commerce stores the following items in the Craft project config:

  • Commerce general settings
  • Email settings
  • PDF settings
  • Gateways settings
  • Order field layout
  • Order Statuses
  • Product types
  • Fields and field groups
  • Subscription field layout

Not everything should be stored in the project config. Some items are considered content, which will change in production—meaning they’re not stored in the project config:

  • Discount promotions
  • Sales promotions
  • Shipping categories
  • Shipping zones
  • Shipping methods and rules
  • Subscription plans
  • Subscriptions elements
  • Tax categories
  • Tax zones
  • Tax rates
  • Order elements
  • Products & Variant elements

# Config Settings

# System

# defaultView

Allowed types
string (opens new window)
Default value
'commerce/orders'
Defined by
Settings::$defaultView
Since
2.2

Commerce’s default control panel view. (Defaults to order index.)

# Cart

# activeCartDuration

Allowed types
mixed
Default value
3600 (1 hour)
Defined by
Settings::$activeCartDuration
Since
2.2

How long a cart should go without being updated before it’s considered inactive.

# cartVariable

Allowed types
string (opens new window)
Default value
'cart'
Defined by
Settings::$cartVariable

Key to be used when returning cart information in a response.

# loadCartRedirectUrl

Allowed types
string (opens new window), null (opens new window)
Default value
null
Defined by
Settings::$loadCartRedirectUrl
Since
3.1

Default URL to be loaded after using the load cart controller action.

# purgeInactiveCarts

Allowed types
boolean (opens new window)
Default value
true
Defined by
Settings::$purgeInactiveCarts

Whether inactive carts should automatically be deleted from the database during garbage collection.

# purgeInactiveCartsDuration

Allowed types
mixed
Default value
7776000 (90 days)
Defined by
Settings::$purgeInactiveCartsDuration

Default length of time before inactive carts are purged. (Defaults to 90 days.)

# updateCartSearchIndexes

Allowed types
boolean (opens new window)
Default value
true
Defined by
Settings::$updateCartSearchIndexes
Since
3.1.5

Whether the search index for a cart should be updated when saving the cart via commerce/cart/* controller actions.

# validateCartCustomFieldsOnSubmission

Allowed types
boolean (opens new window)
Default value
false
Defined by
Settings::$validateCartCustomFieldsOnSubmission
Since
3.0.12

Whether to validate custom fields when a cart is updated.

# Orders

# pdfAllowRemoteImages

Allowed types
boolean (opens new window)
Default value
false
Defined by
Settings::$pdfAllowRemoteImages

Whether to allow non-local images in generated order PDFs.

# updateBillingDetailsUrl

Allowed types
string (opens new window)
Default value
''
Defined by
Settings::$updateBillingDetailsUrl

URL for a user to resolve billing issues with their subscription.

# Payments

# gatewayPostRedirectTemplate

Allowed types
string (opens new window)
Default value
''
Defined by
Settings::$gatewayPostRedirectTemplate

The path to the template that should be used to perform POST requests to offsite payment gateways.

# paymentCurrency

ISO codes for supported payment currencies.

# Units

# dimensionUnits

Allowed types
string (opens new window)
Default value
'mm'
Defined by
Settings::$dimensionUnits

Unit type for dimension measurements.

# weightUnits

Allowed types
string (opens new window)
Default value
'g'
Defined by
Settings::$weightUnits

Units to be used for weight measurements.

# Advanced Configuration

Additional customization of Commerce components is possible via application configuration. These settings must be added to your project’s config/app.php file, within the pluginConfigs block.

Cart cookies expire after one year, by default. Change this with the carts.cartCookieDuration property:

return [
    'components' => [
        'plugins' => [
            'pluginConfigs' => [
                'commerce' => [
                    'components' => [
                        'carts' => [
                            'cartCookie' => [
                                // Add custom key-value cookie params
                            ],
                            // Set the cart expiry to one month
                            'cartCookieDuration' => 2629800,
                        ],
                    ],
                ],
            ],
        ],
    ],
];