Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-29T12:45:28.097Z
Answers.LastActivityDate: 2016-03-29T12:45:28.097Z
Answers.UserDisplayName: Luke Holder
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-09T19:55:43.260Z
Answers.Text: 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.
Answers.UserDisplayName: moondawg
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-09T20:00:35.540Z
Answers.Text: @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.)
Answers.UserDisplayName: Matt Stein
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-09T20:47:12.830Z
Answers.Text: Thanks Matt, Craft via Twitter said they could help. Quite happy to pay then for this to be in the 'core'.
Answers.UserDisplayName: moondawg
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-10T08:41:24.660Z
Answers.Text: @moondawg Kudos to you. Appreciate it when the industry pays for new core features! Well done
Answers.UserDisplayName: Matt P
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-10T16:12:10.077Z
Answers.Text: In Norwegian "Matt stein" means dim rock :D
Answers.UserDisplayName: Wobee
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-10T17:18:53.347Z
Answers.Text: @Wobee Ha! I can work with low expectations. Thanks for the warning! ;)
Answers.UserDisplayName: Matt Stein
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-09T19:35:12.040Z
Answers.LastActivityDate: 2016-03-09T19:49:19.343Z
Answers.LastEditDate: 2016-03-09T19:49:19.343Z
Answers.UserDisplayName: Matt Stein
Body: <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>
  
Tags: <plugin-craftcommerce><ecommerce>
Title: How can I notify store owners when stock levels are getting low?
ThreadText: # 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](https://craftcommerce.com/docs/events-reference#commerce_orders.onordercomplete)) that evaluates the stock levels and probably uses Craft's [Email Service](https://craftcms.com/classreference/services/EmailService) to fire off notifications to the store owners.
  
  Here's some quick pseudocode:
  
  ```
  <?php
  
  namespace Craft;
  
  class StockNotificationPlugin extends BasePlugin
  {
      ...
  
      function init()
      {
          craft()->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 username_2, 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**: @username_0 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 username_2, Craft via Twitter said they could help. Quite happy to pay then for this to be in the 'core'.  
  > **username_3**: @username_0 Kudos to you. Appreciate it when the industry pays for new core features! Well done  
  > **username_4**: In Norwegian "username_2 username_2" means dim rock :D  
  > **username_2**: @username_4 Ha! I can work with low expectations. Thanks for the warning! ;)  
  
  ---
  
  