top of page

Getting Started with Commerce 2.x


Drupal Commerce 2.x overview +rakesh.james@valuebound.com can we divide this post in multiple ones. Part 1, Part 2 ...

E-commerce in drupal 8 is a very interesting topic for many developers. This blog is the right place to start with E-commerce in drupal 8.

Drupal Commerce 2.x is the module for creating online stores of varying complexity. This blog provides an overview of the Commerce 2.x module for Drupal 8.

Installing Drupal Commerce 2.x

For installing Drupal Commerce, make sure that your server has a Composer dependency manager installed. In Drupal 8, Commerce requires the installation of libraries, which are now installed not manually but with the help of Composer. Make sure Composer installed globally.

You can install Drupal, as well as Commerce together with the dependent modules and libraries with this command:

“composer create-project drupalcommerce/project-base mystore --stability dev”

Everything will be installed to “mystore” folder

Installing Drupal Commerce 2.x on existing site

We need to do the following steps for Installing Commerce 2.x in existing Drupal8.x site.

Step 1: Add the Drupal packagist repository which allows Composer to find Commerce and the other Drupal modules. For that run the following command,

composer config repositories.drupal composer https://packages.drupal.org/8

Step 2: The following command will help us to download the required libraries and modules (Address, Entity, State Machine, Inline Entity Form, Profile).

“composer require "drupal/commerce 8.2.x-dev"

Step 3: Enable the all commerce related submodules like “commerce_product commerce_checkout, commerce_cart, commerce_tax” , Use drush or drupal console.

Settings in the admin interface in new Commerce 2.x

Go to the commerce settings (admin/commerce/config).

1. Currency :

It is very easy to use the currency inside and Outside the US.

First, you need to select your store currency (admin/commerce/config/currency). By default, the currency list is empty (you will see the message “there is no currency yet”). The list of currencies needs to be imported. Select the desired ones on the currency import page (admin/commerce/config/currency/import).

Now, at the Currency page, we see a list of currencies.

2. Store :

In the version for Drupal 8, you can create multiple stores, which may vary by products, currencies, tax settings, shipping countries and so on. In Commerce 1.x (Drupal 7) there was no such entity as "store".

You can create your own types of stores (on the admin/commerce/config/store-types page) and add a variety of fields. On the admin/commerce/stores page, click Add new store.

At this step, we configure the store: give it a name, specify its email, country, currency, and other settings.

Now, at the Store page, we see our new store.

3. Products :

Here we should note the main difference of Drupal Commerce 2.x (for Drupal 8) from Drupal Commerce 1.x (for Drupal 7). In Commerce 2.x, we now have such entities as Product and Product Variation. Product replaces product display of Commerce 1.x (node type, which has been linked to the products).

3.1 Product Attributes : In Commerce 2.x product attributes are its own entities, So it is easy to edit, delete, create new attribute from.

To create Products, first we need to create Product attributes.

On the Product Attributes page (admin/commerce/product-attributes) we add our attribute (eg, product size) and select a value that it can have.

For example, let’s add "size".

3.2 Product variations :

The Product variation types page (admin/commerce/config/product-variation-types) we choose the Default product variation (or create our own), and add this attribute to the variation.

A product variation can have several attributes.

All the attributes of the product variations can be found in the list of fields (admin/commerce/config/product-variation-types/default/edit/fields)

When creating a new type of product variations, you can use the already existing attributes.

In our example, the Default variation has one attribute — "size" . This is a field that can be changed just like other fields. By clicking the Edit button, we can go to the editing mode.

So for Size As an example, let’s set a default value.

A product variation may have various fields of different types (text, numeric, etc.), as well as other entities

3.3 Product Types :

The Product types page (admin/commerce/config/product-types) we choose the Default product type (or create our own), and here we can add fields which will be added with the product entity.

In manage fields in default product type (admin/commerce/config/product-types/default/edit/fields) we see Variations and Store are inherited in product and Body is a field added to it.

Let’s add an image field too

These fields will be seen when we add products, which is the next step.

3.4 Creating a Product :

Instead of nodes we hare having Product entity itself. To create a product, let’s go to the admin/commerce/products page.

we will have a product named “T-shirt” and the variations of this product in various sizes.

This is how our first product looks.

We have now done basic settings for an online store. The Drupal Commerce 2.x module supports a variety of options for implementing the desired features like shipping (commerce_shipping module), Promotions (commerce_promotions module). Recently Commerce guys are working on making these functionality stable.


bottom of page