Introduction to Drupal Commerce

  • 6 minute read

Drupal Commerce is a powerful Commerce framework build on the Drupal 7 API, core and contrib. It puts the distributions on the map once again through the Commerce Kickstart package, a ready to go e-commerce store.

It is important to clarify the difference between Drupal Commerce and Commerce Kickstart: Drupal Commerce (DC) on its own is nothing more (and less) than a powerful framework that implements various commerce related APIs (checkouts, products, payments and so on) on top of, or extending the already powerful Drupal 7 API, while Commerce Kickstart (Kickstart) is a distribution package containing Drupal core, Commerce, various contributed modules and configurations.

Find out more on how to install Kickstart here: http://drupal.org/node/1291122

Drupal Commerce vs Ubercart

Ubercart predates DC, it was virtually the only viable choice for building a commerce site with Drupal 5 and 6. It has been ported to Drupal 7, but due to a lot of legacy compatibility and lack of rewrites it keeps the flaws stemming from the fact that the architecture was designed for older Drupal versions in mind.

For the Drupal commerce veterans: do you remember the pain of setting up tax rules in Europe? Creating a product with various options (attributes in Ubercart lingo, for instance t-shirts with various sizes), and the pain of managing their stock levels, or prices? Or when trying to theme the cart form, only to find the ugly theme hacks preventing you from implementing the visuals your designer came up with?

Drupal Commerce was written from scratch, designed from the ground up by people who learned from the flaws of Ubercart, with years of ecommerce experience under their belt. It uses the new APIs of Drupal 7, which results in a significantly greater compatibility with contrib modules. This in turn results less custom code required for a new site, both theme and modules.

It employs the following architectural principles:

  • Build APIs and re-use from applications
  • Separate user interface from the applications
  • Interface with contrib modules such as Views, Rules that follow these principles

Now that Drupal 7 has an underlying API of handling data entities this can be done. Contributed module compatibility happens on the entity level, which means that once the handlers are implemented for Views, shopping carts can be built in Views, orders and line items can be re-used and customised without the hurdle of PHP development and code deployment workflow.

A good example of how this enhances the uses for Commerce: the selling of digital goods can be implemented with ease. Membership, or access to certain files on the site can be done through granting a role or a permission for a user upon purchase, which in turn grants him or her the access. Since Commerce core itself does not contain shipping modules, one less module has to be installed.

Nodes, entities

Admittedly, some of this flexibility comes at the price of having rough edges initially, until contributed modules come along to smoothen them and bridge the gaps. For instance Drupal Commerce defines a new entity for products as opposed to the content type of Ubercart. By going down the entity road an actual store item one will end up with two data entries in the system: a product entity representing the physical (or digital) item being sold, e.g. an M sized, red t-shirt, and a node that serves as the shop window, selling "t-shirts".

Albeit this separation seems to overcomplicate the problem at first (and simpler stores may not need it as they have a 1:1 relation between items to sell and their display on the site) it is necessary in order to be able to handle variations of a given product (t-shirts with various sizes). Contributed modules can help overcome this complexity, for instance it is possible to create and handle both the product entities and their display nodes together using the Inline Entity Form (http://drupal.org/project/inline_entity_form).

Theme

Kickstart comes with a responsive theme that is built on the popular responsive base theme, Omega (http://drupal.org/project/omega), so basically mobile friendly from the get-go. Commerce Kickstart comes with a responsive theme built on Omega using omega_kickstart (http://drupal.org/project/omega_kickstart), built by the creator of Omega himself.

The fact that Commerce reuses Views on so many places make it very easily template-able and re-themeable too. Following Drupal development patterns closely means that virtually every output can be overwritten using theme overwrites.

A few good examples of beautiful Drupal Commerce sites:

Modules

Following Drupal development principles not Commerce specific functionality was placed into generic contributed modules, giving birth to the generic address field module (http://drupal.org/project/addressfield),

Commerce modules are not part of the main package (unlike Ubercart), instead they are separate projects:

There are already tons of extensions adding functionality such as reusing addresses for customers (http://drupal.org/project/commerce_addressbook), integrating with Feeds, or creating products and their displays together (http://drupal.org/project/commerce_product_display_manager). For a complete list check out this page: http://www.drupalcommerce.org/contrib/all

Resources