Commerce Stock Notifications
Allows users to subscribe for email notifications when out-of-stock products become available again.
commerce_stock_notifications
Overview
Commerce Stock Notifications enhances Drupal Commerce stores by providing a back-in-stock notification system. When a product is out of stock, the module automatically replaces the "Add to Cart" button with a notification subscription form where customers can enter their email address.
When products come back in stock, the module automatically sends email notifications to subscribed users via a cron-based queue system. The module includes full administrative controls for managing subscriptions, customizing notification messages with token support, and automatic cleanup of old notification records.
Each notification subscription is stored as a content entity, providing Views integration and allowing administrators to track and manage all subscriptions from a central location.
Features
- Automatically modifies the Add to Cart form on out-of-stock products to display a notification subscription form
- Stores notification subscriptions as content entities with full metadata (user, email, product variation, timestamps)
- Queue-based email notification system that processes subscriptions during cron runs when products return to stock
- Fully customizable email subject and body with Token module support for user and product variation tokens
- Configurable user-facing messages for out-of-stock, success, and duplicate subscription scenarios
- Automatic purge of sent notification records after a configurable number of days
- Built-in Views display showing users their active notification subscriptions on their profile
- Unsubscribe functionality allowing users to remove their notification subscriptions
- Views integration enabling custom reports and administrative views of all subscriptions
- Support for Commerce Product Limits module to respect minimum order quantities when determining stock availability
Use Cases
E-commerce Store Stock Alerts
For online stores using Drupal Commerce with inventory management, this module allows customers to sign up for notifications on sold-out products. When inventory is replenished, customers receive automatic email alerts encouraging them to return and complete their purchase.
Pre-order Interest Collection
When launching new products that aren't yet in stock, stores can use this module to collect customer interest. The notification system will automatically alert interested customers once inventory arrives.
High-Demand Product Management
For products that frequently sell out, the notification system helps retain customer interest and provides valuable data about demand levels through the subscription list.
Guest Customer Engagement
By granting anonymous users the create permission, stores can collect notification subscriptions from non-registered visitors, potentially converting them to customers when products return to stock.
Tips
- Use tokens like [commerce_product_variation:title] and [commerce_product_variation:url] in email templates to personalize notifications
- Set up a reasonable purge interval (default 30 days) to keep the notification table clean while retaining useful data
- Consider the Views provided for user subscription management and extend them for administrative reporting
- Test email delivery by subscribing to a test product, then manually setting stock to trigger the notification queue
Technical Details
Admin Pages 2
/admin/commerce/config/stock/stock-notifications
Configure the email templates and user-facing messages for stock notifications. This page allows administrators to customize all text displayed to users and sent via email when products return to stock.
/admin/structure/commerce_stock_notification
Administrative listing of all stock notification subscriptions. Displays subscription details including user email, product, submission date, sent date, and provides unsubscribe links for manual management.
Permissions 2
Hooks 5
hook_form_alter
Modifies add-to-cart forms for out-of-stock products by replacing the submit button with a notification subscription inline form.
hook_cron
Manages two queues during cron: (1) Creates notification send queue items for subscriptions where the product is back in stock, (2) Creates cleanup queue items for sent notifications older than the purge interval.
hook_mail
Prepares email messages for stock notifications with HTML format support.
hook_theme
Defines the commerce_stock_notifications_message theme hook for rendering email notification content.
hook_module_implements_alter
Ensures the module's form_alter runs last to properly modify add-to-cart forms after other modules.
Troubleshooting 4
Ensure cron is running regularly. The module processes notifications during cron runs. Check that the commerce_stock_notifications queue has items and that products are actually back in stock.
Grant the 'Create commerce stock notifications' permission to the anonymous user role. Note that anonymous users cannot unsubscribe themselves.
Consider installing Swift Mailer or another HTML mail module. The module sets HTML headers but your mail system must support HTML rendering.
Verify that Commerce Stock is properly configured and stock levels are correctly set. The module checks stock through the Commerce Stock service manager.
Security Notes 3
- Anonymous user subscriptions cannot be unsubscribed by the user themselves - administrators must manage these manually
- Email addresses are stored in plain text in the database for notification delivery
- The unsubscribe URL contains the notification ID which could theoretically allow enumeration, though access is controlled by entity permissions