Commerce Stock

Commerce Stock module, for Drupal Commerce.

This module provides stock management for Drupal Commerce stores.

Drupal 8/9/10

This implementation is significantly different from the Drupal 7 implementation. Below are some of the main differences:

  • Transaction-based inventory management - Improves performance, Provides Stock history and audit, and supports more use cases.
  • Multi store support
  • Multiple Stock location
  • Serviceses and OOP implementation for more structured custom development
  • Various stock entry methods
  • Stock aggregation modes and Transactions retention configuration for supporting both Enterprise and Small e-shops

Standard setup for Commerce stock

1. Enable the following modules

  • Commerce Stock API
  • Commerce Stock Field
  • Commerce Stock Local Storage
  • Commerce Stock UI
  • Commerce Stock Enforcement (optional)

2. Commerce >> Configuration >> Stock >> Stock configuration

  • Set Default service to "Local stock" (optionally select Local stock only for product variations that should be controlled by stock)

3. Commerce >> Configuration >> Products >> Product variation types assuming you
only have Default Product variation type

  • Manage fields
  • Add field
  • Select "Stock Level" under the "General" section and name the field "stock
  • level"
  • Save and continue
  • "Allowed number of values" is set to 1 - "Save field settings"
  • "Save settings" one last time
  • If you have more product variation types:
  • Reuse the field that was created for the Default Product variation type: "field_stock_level"

Other configuration

Using Widgets for updating stock

Commerce stock comes with three widgets for stock level editing.
To set the widget, go to the "Manage form display" of the product variation
type you want to set and use the Widget drop-down of the "Stock Level" field.

The following are the widgets and their functionality:

  • "Absolute stock level" - This is the equivalent to the Drupal 7 version and allows setting the current stock level. The list secure approach and not recommended for live sites as other stock transactions can occur from the point a stock count was made and the entering of the data. Can be handy for priming a new site and stock takes while in maintenance mode.
  • "Simple stock transaction" - A simple form for creating transactions. Allows for entering of positive (stock in) and negative (stock out) transactions. Targeted at simple sites that don't require much extra metadata about their transactions.
  • "Link to stock transaction form" - This provides a link to a transaction form providing full transaction details.

Both "Absolute stock level" and "Simple stock transaction" also have the options: "Allow custom note per transaction." and "Allow decimal quantities".
This and more are available on the "stock transaction form" so not needed as an options for the "Link to stock transaction form" widget.

Event handling
By default, the stock system reacts only on "order complete" events - creates a
negative transaction resulting with that stock no longer available.
You can enable 2 more events by going to:
Commerce >> Configuration >> Stock >> Stock configuration

  • Automatically return stock on cancel - Creates a positive stock transaction and makes the stock available again
  • Adjust stock on order updates (after the order was completed) - Allows to modify a placed order and any changes to quantities will get reflected in stock levels.

Stock enforcement
By default, the stock system allows stock to go into negative (i.e. a user can purchase 10 items if the product has only 5 in stock). To have the module enforce the stock levels you must enable Commerce Stock Enforcement module.

Support multiple stores
Each store will have a primary location for creating transactions against. Each store will have a list of locations available for fulfilment (this is for checking of stock not for creating transactions).
To support multiple stores you must add the following fields to relevant Store types (we may automate this later on):

  • Available stock locations (field_available_stock_locations) - Entity reference to stock location - unlimited
  • Stock allocation location (field_stock_allocation_location) - Entity reference to stock location - 1

How to add a stock locations reference field:

  1. Add a new field
  2. Select Reference: Other.
  3. Enter the label and make sure the machine name is correct.
  4. Set the "Type of item to reference" to "Stock Location" and the "Allowed number of values"
  5. Press Save Field settings
  6. Set the "Stock location type"
  7. Press Save Setting

You can then edit each of the stores and set the locations.

For up to date instructions see the readme file

Commerce Stock for Drupal 7 - version 2

This version should be used for Drupal 7 sites .

The module uses rules for implementation of the stock checking and allows for more flexibility, it also uses an API submodules architecture allowing the extension of the functionality.
The module currently implements a sub module 'simple stock' providing most of the features in version 1 out of the box.
To implement your own business logic: install the modules and configure the rules.

Key Features of V2

  • A rule and action for enabling and disabling the add to cart form.
  • A rule and action for validating stock for the add to cart button action.
  • A rule for checking the cart form submit, also used for checkout submit and review submit.
  • A new checkout pane placed in the first step of checkout: stops the user from accessing checkout if order contains out of stock items
  • Supports Decimal stock.
  • Works with Inline Entity Form module.
  • Advance configuration of the add to cart button action for even more control
  • Commerce Stock field formatter for converting stock levels into text messages.

Installation and setup
1. Download commerce_stock
2. Enable the Commerce Stock API, Commerce Simple Stock, and Commerce Simple Stock Rules modules.
3. Go to Home » Administration » Store » Configuration » Stock management
4. Select the “simple stock management” tab
5. Check the product types you want simple stock to manage and hit submit

Important: you may need to clear caches after installing and enabling stock for your products!

add to cart validation
The add to cart is now checked using rules: Event "Check if a product is in stock"
It passes in the Product, Requested Quantity, the Quantity already in the cart & the total requested (Requested+ already in cart)
The action "Set the result of a stock check" allows you to set the following
stock action:
block transaction - block adding to cart and display a message to the user
display message only - allows adding to cart and display a message to the user
Message: the message to display to the user
Approved Quantity: the quantity to add to the cart, allows you to approve 1 if 3 where asked for and two already in cart.

Advanced configuration of the add to cart form
This action will allow us to do much more then just disable the add to cart.
Options are:

  • Convert the add to cart button to a custom link
  • Replace the add to cart button with user defined HTML
  • Override the forms validation and submit functions
  • Disable the quantity box if active
  • Added Prefix and Suffix to the submit element

Related projects
Commerce decimal quantities: http://drupal.org/project/commerce_decimal_quantities

Expend functionality using rules Issues

Commerce Stock for Drupal 7 - Version 1

Check out Randy Fay's Stock V1 Screencast

No new features for version 1 so maintenance only.

To install and configure

  1. Install and enable the module.
  2. Visit admin/commerce/config/stock to enable stock tracking on your product type(s).
  3. Set the starting value of stock on each product.

The stock module does two main things

  1. Maintain stock levels
  2. Implement validation of stock to prevent users from ordering out of stock items

The module does the following stock validation checks

  1. Disable the add to cart button for out of stock products.
  2. Validates the add to cart quantity widget.
  3. Checks current Cart quantity when adding to your cart (so if stock is 10 and you got 6 in your cart you can only add 4)
  4. Checks that all products and quantities in the shopping cart (/cart) are in stock
  5. On Checkout if you attempt to enter, continue or complete with out of stock items you get redirected to the shopping cart.

If you are using multiple products per display and are not using attributes:

  1. Marks items as out of stock in the dropdown (version 1 only)

Management of stock

Each product type that is to be stock controlled is to be enabled using the admin interface.
Enabled product types will have a stock field added to them; this field will hold the current stock count.
A rule is created by the module to decrease the stock level when an order is complete.
The modules also provides some rule conditions and actions (increase / decrease stock) for you to create your own custom rules

Other features

  1. Ability to disable stock checking for specific products

Upgrade path from version 1:
I haven’t looked into this so any help will be great. For now just be aware that all rules have been rewritten.
If you have existing products with stock you will need to disable stock on all product types first, so the new decimal field gets created, you can probably backup and restore your stock using some SQL.
See also Issue 1800666

to keep up with development plans see the Roadmap

Project information

Releases