Drupal Commerce on Drupal 8
Use Composer to Install Drupal Commerce with Drupal 8, on Pantheon
Contributors: Alex Fornuto, Steve Persch.
Discuss in our Forum Discuss in SlackThis guide covers installing Drupal Commerce, an e-commerce implementation designed specifically for Drupal. At the end of this guide you will have a Drupal Commerce site, GitHub repository, and Circle CI configuration for testing.
Before You Begin
This process uses Composer to manage modules and dependencies. Before proceeding, you may wish to consult the following docs:
Note
As packages pulled by Composer are updated (along with their dependencies), version compatibility issues can pop up. Sometimes you may need to manually alter the version constraints on a given package within the require or require-dev section of composer.json in order to update packages. See the updating dependencies section of Composer's documentation for more information.
As a first troubleshooting step, try running composer update to bring composer.lock up to date with the latest available packages (as constrained by the version requirements in composer.json).
In addition to Pantheon, you will need accounts at:
Follow the Before You Begin section of the Build Tools guide to install Composer, Terminus, and the Terminus Build Tools plugin on your local computer, and create machine tokens for GitHub and CircleCI. Export the tokens to your current terminal session, as described below.
This guide uses several variables in example Terminus commands. This lets you copy and paste without needing to change the variable. For this to work, you must first export the variables in your local terminal session:
export SITENAME=yoursitenamehere export GITHUB_TOKEN=yourgithubtokenhere export CIRCLE_TOKEN=yourcirclecitokenhereSITENAMEwill be used as the machine names of the Pantheon site and the GitHub repo created in this processGITHUB_TOKENlets Terminus interact with your GitHub account to create the repositoryCIRCLE_TOKENis used to configure CircleCI to push to Pantheon any time a push is made to the GitHub repo
Create a New Drupal 8 Site
Using the Terminus Build Tools plugin, create a new Drupal 8 site from the Pantheon Example Drops 8 Composer repository on GitHub:
terminus build:project:create pantheon-systems/example-drops-8-composer $SITENAMEAt this point do not go to the web interface to continue installation.
You now have a repository on GitHub containing your new site. Clone a local copy to your
projectsfolder:cd ~/projects git clone git@github.com:username/$SITENAME.gitRemember to replace
usernamewith your GitHub username.
Install Drupal Commerce
Move into the local repository for your site:
cd $SITENAMEUse Composer to install the Commerce Installation Profile:
composer config repositories.commerce_base vcs https://github.com/drupalcommerce/commerce_base composer require "drupalcommerce/commerce_base dev-8.x-1.x"Running
git statusshould show that thecomposer.jsonandcomposer.lockfiles have changed:
Commit the new files and push them to GitHub:
git commit -am "add commerce_base to project" git push origin masterFrom your CircleCI Dashboard you can see that tests are already being run on your new commit. Once they pass, CircleCI will push the changes to your Site Dashboard.
Go to your newly created Site Dashboard. Under the Dev tab, click on Code, then install later. You should now see your commit history. Once CircleCI completes the automated tests built into our repository, it will commit the build assets and push them to Dev:
Reinstall Drupal
The Build Tools Plugin command we used earlier automatically installed Drupal's standard profile in the Dev environment for us. Now that we've installed the Commerce profile, we want that installed instead. Using Terminus, we can run the Drush command
site-installwhich will first clear the database of the Standard profile before installing Commerce. This Drush command requires that the system be in writable (SFTP) mode:terminus connection:set $SITENAME.dev sftp terminus drush $SITENAME.dev -- site-install commerceReview the last two lines of output to identify the username and password created:
Installation complete. User name: admin User password: jTHD8hd85U [ok] Congratulations, you installed Drupal! [status]Log in to your Drupal site in the Dev environment. The presence of the Commerce button on the toolbar indicates a successful install:
Conclusion
What you do next is up to you and your needs. Remember that you're now using Composer to manage core, modules, and dependencies for your site. Consider reading our Composer Fundamentals and Workflows doc for more information.