<p>We have created an working example plugin that can notify users by email when the stock of a variant drops below a defined threshold.</p>

<p><a href="https://github.com/pixelandtonic/CommerceStockNotifier" rel="nofollow">https://github.com/pixelandtonic/CommerceStockNotifier</a></p>

CC BY-SA 3.0
2016-03-29T12:45:28.097Z
2016-03-29T12:45:28.097Z
Luke Holder
<p>Just like Craft itself, Craft Commerce has lots of events you can have a plugin respond to. In this case, you'd want to write a plugin that waits for <code>commerce_orders.onOrderComplete</code> (<a href="https://craftcommerce.com/docs/events-reference#commerce_orders.onordercomplete" rel="nofollow">per documentation</a>) that evaluates the stock levels and probably uses Craft's <a href="https://craftcms.com/classreference/services/EmailService" rel="nofollow">Email Service</a> to fire off notifications to the store owners.</p>

<p>Here's some quick pseudocode:</p>

<pre><code>&lt;?php

namespace Craft;

class StockNotificationPlugin extends BasePlugin
{
    ...

    function init()
    {
        craft()-&gt;on('commerce_orders.onOrderComplete', function($event) 
        {
            // loop through the items in the order ($order-&gt;lineItems), 
            // checking the remaining stock ($item-&gt;purchasable-&gt;stock)
            // against your desired threshold, firing off notifications
            // if applicable
        }
    }

    ...
}
</code></pre>

CC BY-SA 3.0
2016-03-09T19:55:43.260Z
Thanks very much Matt, one is not a developer anymore though, front end is my bread and butter now. This needs a Control Panel interface, where you can set who gets the email notifications via the plugin, as set by the store owner - as it could be a few people that get the notifications - a stock warehouse as well for example and of course input fields for the actual stock level control per product. Yes, you could do that via a custom field/s, but it would be nice to have a configured plugin I feel.
moondawg
CC BY-SA 3.0
2016-03-09T20:00:35.540Z
@moondawg You might consider [posting a feature request](http://feedback.craftcms.com/forums/285221-feature-requests) for this, or see if you could hire a developer to build the plugin for you. (The Craft Slack account is crawling with friendly developers.)
Matt Stein
CC BY-SA 3.0
2016-03-09T20:47:12.830Z
Thanks Matt, Craft via Twitter said they could help. Quite happy to pay then for this to be in the 'core'.
moondawg
CC BY-SA 3.0
2016-03-10T08:41:24.660Z
@moondawg Kudos to you. Appreciate it when the industry pays for new core features! Well done
Matt P
CC BY-SA 3.0
2016-03-10T16:12:10.077Z
In Norwegian "Matt stein" means dim rock :D
Wobee
CC BY-SA 3.0
2016-03-10T17:18:53.347Z
@Wobee Ha! I can work with low expectations. Thanks for the warning! ;)
Matt Stein
CC BY-SA 3.0
2016-03-09T19:35:12.040Z
2016-03-09T19:49:19.343Z
2016-03-09T19:49:19.343Z
Matt Stein
<p>For a Craft Commerce site, the store owners wish to be notified automatically when a stock is starting to get low. Can this be achieved with a plugin, and if so, how?</p>

<plugin-craftcommerce><ecommerce>
How can I notify store owners when stock levels are getting low?
# How can I notify store owners when stock levels are getting low?

(Asked by: username_0 on 2016-03-09)

For a Craft Commerce site, the store owners wish to be notified automatically when a stock is starting to get low. Can this be achieved with a plugin, and if so, how?

**Tags:** plugin-craftcommerce, ecommerce

---

## 2 answers

### Answer by username_1 on 2016-03-29. Score: 3

We have created an working example plugin that can notify users by email when the stock of a variant drops below a defined threshold.

<https://github.com/pixelandtonic/CommerceStockNotifier>


---

### Answer by username_2 on 2016-03-09. Score: 3

Just like Craft itself, Craft Commerce has lots of events you can have a plugin respond to. In this case, you'd want to write a plugin that waits for commerce_orders.onOrderComplete (per documentation) that evaluates the stock levels and probably uses Craft's Email Service to fire off notifications to the store owners.
Here's some quick pseudocode:
on('commerce_orders.onOrderComplete', function($event) 
        {
            // loop through the items in the order ($order->lineItems), 
            // checking the remaining stock ($item->purchasable->stock)
            // against your desired threshold, firing off notifications
            // if applicable
        }
    }

    ...
}

> **Comments:**
> **username_0**: Thanks very much Matt, one is not a developer anymore though, front end is my bread and butter now. This needs a Control Panel interface, where you can set who gets the email notifications via the plugin, as set by the store owner - as it could be a few people that get the notifications - a stock warehouse as well for example and of course input fields for the actual stock level control per product. Yes, you could do that via a custom field/s, but it would be nice to have a configured plugin I feel.  
> **username_2**: @moondawg You might consider [posting a feature request](http://feedback.craftcms.com/forums/285221-feature-requests) for this, or see if you could hire a developer to build the plugin for you. (The Craft Slack account is crawling with friendly developers.)  
> **username_0**: Thanks Matt, Craft via Twitter said they could help. Quite happy to pay then for this to be in the 'core'.  
> **username_3**: @moondawg Kudos to you. Appreciate it when the industry pays for new core features! Well done  
> **username_4**: In Norwegian "Matt stein" means dim rock :D  
> **username_2**: @Wobee Ha! I can work with low expectations. Thanks for the warning! ;)  

---

