Commerce Stock module, for Drupal Commerce.
This module provides stock management for Drupal Commerce stores.
Check out Randy Fay's Stock Screencast
What version of stock should you use?
A simple and robust approach to stock control. Not as configurable and extensible as 2 but easy to configure and works, and most importantly is on full release will not significantly change and will receive priority for maintenance and support.
- Stores stock along side other product information
- Allows for Enabling of stock control for specific product bundles
- Allows for turning off stock control for specific products.
- Will do all in its power to prevent users from purchasing out of stock items.
Designed to be more flexible and extensible and is likely to go through significant changes in the future. It does however provide a stable platform for stock management and if you need the extra flexibility it may be the one for you.
- Uses configurable rules for stock validation
- Uses a sub module system for stock storage – makes it easier to develop integration with external stock systems.
- The next stage of development plan is to refactor the code to be more api based
Commerce Stock - Version 1
To install and configure
- Install and enable the module.
- Visit admin/commerce/config/stock to enable stock tracking on your product type(s).
- Set the starting value of stock on each product.
The stock module does two main things
- Maintain stock levels
- Implement validation of stock to prevent users from ordering out of stock items
The module does the following stock validation checks
- Disable the add to cart button for out of stock products.
- Validates the add to cart quantity widget.
- 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)
- Checks that all products and quantities in the shopping cart (/cart) are in stock
- 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:
- 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
- Ability to disable stock checking for specific products
Commerce Stock - version 2
This version is a complete rewrite of the code and will need testing before use in a live environment, it is also likely to go through significant changes in the future.
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 one 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 (more documentation to follow)
I am hoping to have more sub modules available soon to handle features like Transactional stock Product Bundles.
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.
Advance configuration of the add to cart button
Installation and setup
1. Download commerce_stock
2. Enable the Commerce Stock API & Commerce Simple stock 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
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.
Commerce decimal quantities: http://drupal.org/project/commerce_decimal_quantities
Advanced configuration of the add to cart form
As of Alpha 4 we have a new action that will allow us to do much more then just disable the add to cart.
- 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
Expend functionality using rules Issues
- Increase stock when order is canceled
- Translating "Out of stock" and other messages set in Rules
- Out of stock Text or Link instead of a disabled button
- Backorder / Waitlist Capabilities see comment #17 for a good approach.
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