How to build a Drupal Commerce development environment

Developer Desk

Every day we find ourselves in need of a clean development environment to work with Drupal Commerce. We use them for sales demos, testing new modules, and reviewing patches in the issue queue. Fortunately, modern development tools make it easy to build a clean local development environment for any of the above!

My preferred approach is to work with a site that resembles our demo store. This includes an attractive theme, a common store layout, and sample content that makes it easy to work in an environment that resembles a live online store.

However, while our demo project specifies packaged releases of Drupal Commerce and various contributed modules, when I'm working locally I want to have the latest commits from the development branch of any project I might be touching. This means using Composer to build a codebase with the following chain of commands:

composer create-project drupal/recommended-project:^8.9 d8dev
cd d8dev
composer require drupal/commerce:2.x-dev
composer require drupal/commerce_demo:1.x-dev
composer require drupal/belgrade:1.x-dev
composer require drupal/commerce_shipping:2.x-dev
composer require drupal/commerce_cart_flyout:1.x-dev
composer require drupal/commerce_cart_api:1.x-dev
composer require drupal/swiftmailer:^2.0
composer require drupal/admin_toolbar:^2.0
git clone https://github.com/drupalcommerce/demo_commerce.git web/profiles/demo_commerce
cd web/profiles/demo_commerce
git checkout eec3cc9485a585412bf003e2030d387f39a8c136
cd ../../../
ddev config
ddev start

I built my codebase in a folder called d8dev. I use it to differentiate my local Drupal 8 development environment from my Drupal 7 environment, since I still also maintain Commerce 1.x. Replace that with whatever you want.

I also prefer working with ddev locally. It has a standard configuration for running Drupal 8 sites that I use, and it's easy to add new services if a site requires them - e.g. Solr, Redis, etc. The team behind ddev make it easy to install, update, and use through their wonderful documentation.

To update the site, you just run two commands from your site's folder:

composer update
ddev exec drush updb

Last, I love that ddev makes phpMyAdmin available on port 8036 for simple database management. I've used it to inspect changes after testing updates and to drop all tables in order to re-install the site and demo content from scratch. Very handy!

Add new comment