How to programmatically add a product variation to the cart in Drupal commerce 2.x (Drupal 8)

Playing a bit with Drupal commerce in Drupal 8, we notice that several functions that we used to use in the past with D7 are gone in D8, or they've had several changes, dued to the new API.

Drupal commerce has lots of changes. The new concept give us more flexibility and features (for example, we don't need a content type to display our products, because they have now their own display page, the product variations are now in commerce core, or the Store concept.).

Two steps login

Two steps login module helps users to login to their drupal website in a better way.
Two steps login module converts the user login experience to a whole new level. This module is inspired by google login functionality and user experience. By enabling this module all the users can quickly access their accounts by just one click and entering their password.

Two steps login

Two steps login module helps users to login to their drupal website in a better way.
Two steps login module converts the user login experience to a whole new level. This module is inspired by google login functionality and user experience. By enabling this module all the users can quickly access their accounts by just one click and entering their password.

You can download this module here

TableField

The TableField module provides a simple, generic form/widget to input tabular data. The form allows the user to select the number of rows/columns in the table, then enter the data via text fields. Since this is a field it is revision capable,multi-value capable and has integration with Views.

An user pays credits for publishing a post

Paying credits for doing actions on a site makes it necessary to check user credits before performing the action. So I use an "Before saving content" event and a "Entity has credits" action to do so.

To avoid publishing the post we send the user back to the add content form using a custom "Execute custom PHP code" action. In order to allow PHP snippets you have to activate core module "PHP filter".

The first rule looks like that:

An user earns credits for publishing a post

After creating Credit Types at admin/commerce/credits/types (see README.txt for details) you are ready to use credits account. They are linked to users, so adding and removing credits must be related to an user entity.

Here a simple rule which adds 1 credit to users who write a blog post:

Pages

Subscribe with RSS Subscribe to RSS - Site administrators