ONLINE STORE IN DRUPAL 8 - DRUPAL COMMERCE
When we talk about e-commerce or electronic commerce we refer to the purchase or sale of a product through an electronic medium such as a web or app.
E-commerce is consolidating as an alternative to traditional commerce due to its diffusion power that exceeds that of traditional methods. With fewer resources, we can reach more people.
Drupal Commerce is a set of Drupal modules that allow you to create e-commerce in Drupal in a professional way. It leverages the power and versatility of Drupal to create customized and flexible stores, very suitable for companies that need to create their own business rules.
In this article, I'm going to tell how to do a very very basic installation, and show what to expect from Drupal Commerce.
Configuration and requirements
According to the manual, it is recommended to install Drupal using Composer; the setup requires Drupal 8.5 or later. We had no problems with the installation process. To install the newer Drupal Commerce, we used the following command:
composer require "drupal/commerce"
Drupal Commerce requires several additional modules (Address, Entity, Inline Entity Form, Entity Reference Revisions, Profile, State Machine). When using Composer, you don't have to worry about installing them manually, as they will be added automatically. After successful configuration, the list of modules will grow by 12 new entries.
Functionality, modules and innovations.
We have activated all modules for testing purposes. The Commerce icon appeared in our main menu. At first glance, you can see several options that were not included in the standard version for Drupal 7. These include:
- Store types
- Product attributes
- Promotions
- Order types
- Order item types
- Payment flows
- Product variation types.
Keep in mind that Drupal Commerce is very modular, this allows for example just to activate the products/variations and disable the cart or the checkout. This is very useful if your website is not an E-commerce as such and you only want to have a "showcase of products" but without giving the option to buy them.
Store and store types
Allows you to define the store types of your website, "online" is added by default. Adding more store types can be useful if you have a network of physical stores or branches in different countries. These stores may have a country-specific offering, but they use the same database of all products that are kept in one place. You must remember that a product can belong to one or more stores; however, an order placed by the user is always assigned to one store.
Another interesting option is the possibility of creating stores by users on your website, which allows suppliers to open their online stores on your platform, as well as create and sell their products, just like ETSY. You can find more information about that functionality in the Drupal Commerce documentation.
Product attributes
Attributes can be added to your products. There are three display options available: Select List, Radio Button and Processed Attribute. These attributes can be assigned to types and used when adding new products.
Attributes are used to define things that are different within the same product. For example sizes, colours, sizes, ...
Promotions
Drupal Commerce provides you with a submodule that allows you to add promotions and discounts. The discount can be set for specific products or the whole order. The discount can be a fixed amount or a percentage and can be assigned to a role, a shipping address or an email address. You can also limit promotions and special offers to a maximum order value or currency. In addition, you have the option to add start and end dates, limit the number of uses, and decide whether a discount can be combined with other promotions. Admittedly, this is a great convenience. Compared to other e-commerce systems, these are things that should already be standard. In Drupal 7, it was not so obvious and could cause a big headache.
Order Types
Another new thing in Drupal Commerce is a new approach to orders. You can now create multiple order types with different checkout paths or even display a shopping cart differently. This is quite an interesting solution and will certainly be useful for more complex projects, where products require a different commerce approach. Each type can have its unique fields and rendering methods.
This is very useful if, for example, you sell physical products, virtual products, recurring memberships or a mix of the above. It allows you to specify that an order will be recurring, or that order will ask for the shipping address because physical products are to be shipped, but online products do not need these fields.
Payment flows
As mentioned above, in addition to order types, you can set up many different purchase paths. They may vary depending on the type of order placed. The entire ordering process is displayed via add-ons. By default, you can take advantage of Multistep, however, you can add your add-on and use it, for example, for one of several purchase paths. This is quite an interesting approach, thanks to which you will not have to alter the single default path. You can see how to create your flow add-in here: https://docs.drupalcommerce.org/commerce2/developer-guide/checkout/create-custom-checkout-flow
Order Item Types
You could say this is something like Drupal 7's "Order Line" : an item that stores order and product data, you can also define your fields to store other information.
Drupal Commerce 8 in action
Let's see how Drupal Commerce works in practice.
Adding a product
As you can see, you can use the attributes and variations of the products you have previously created. Let's add a product with several options to choose from.
To make the concepts clear:
- The product for example can be a t-shirt
- The variations are the different models of that same t-shirt (the options that would generate its possible attributes) and is where you specify the price. For example, different colours of the T-shirt can have different prices.
- The attributes would be the different sizes and colours in which the product is available.
Product page
For each product, a page is automatically created where the values of that product are shown.
In our example case, we have almost no fields, but normally this includes image fields, text fields, categories, related products, ..... etc.
It also displays a form where attributes can be selected and based on the user's selection the information of the corresponding variation (price, image, etc ...) is displayed.
Cart/Shopping Cart
The standard cart is a block with views, which can be configured easily and freely, as in Drupal 7.
You indeed have to use contributed modules to get the "Add to cart" to work by AJAX and not reload the whole page, but it is quite easy to use.
Payments
Drupal Commerce already comes with a few payment methods, but they are mostly intended for testing or bank transfers.
In almost all cases, you have to use contributed modules to install alternative payment methods such as:
- Paypal
- Tpay
- Redsys
- Stripe
- ...
Shipping
You can take advantage of a shipping module: Commerce Shipping
It is integrated with the physical model, thanks to which you can use automatic conversion of sizes and scales to the final shipping cost.
Overview
Drupal Commerce has several basic functions and many interesting operational and working innovations, which is, of course, a great advantage. In addition, the developers decided to provide users with more configuration options by default, compared to the Drupal 7 version. A typical site builder might have trouble building a store for a client, due to the lack of D7 modules and the fact that most of them are in alpha or beta version, which means they might be unstable. If you don't develop advanced modules for Drupal 8, it can be a big hurdle, otherwise, you may have to develop them yourself.
The good thing about Drupal Commerce was the fact that you can set up and reconfigure the basic functions of our store in no time without any problems. More and more modules are released, and a large number of them are already available in stable versions. That is why the combination of Drupal 8 and Drupal Commerce is a tool that offers many possibilities to implement interesting projects.
Whether Drupal Commerce is a viable option for your online store ... depends on each specific case. Drupal Commerce is one of the most flexible options currently available, but it is also a lot of work and this is reflected in the cost.
However, as of now, the project looks promising and we keep our fingers crossed for further development of Drupal Commerce.
If you need more information about Drupal Commerce, please feel free to visit https://docs.drupalcommerce.org/.
Have Any Project in Mind?
If you want to do something in Drupal maybe you can hire me.
Either for consulting, development or maintenance of Drupal websites.