Disable product when out of stock I would like to disable a product as soon as it's stock drops to 0 in Drupal commerce.

I think this might be possible by using rules, but then I don't know what will happen to the product display. I figure that when there are no more active products attached to a product display, the display will still appear in my views but without any product information attached to it. In this case I would also like the product display to be "unpublished".

I can't unpublish the product display immediately after a given product is out of stock because there could be more products added to a single display...

Can some one help me to achieve this through rules or is there some other method that I could use?

I'm using Drupal Commerce and the stock module for it.
Seems really odd that the maintainer would say that this was impossible and a fringe case. 

Seems to me like this is a very normal use case, in fact one that we use on every single Ubercart site we have in production. I actually thought this was a setting in the module config page and was surprised to see that it wasn't.

Anyway, here's what I did. I disabled the included rule because I despise rules and added this code to my module:

/**
 * Implements hook_commerce_checkout_complete().
 */
function MYMODULE_commerce_checkout_complete($order) {
  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
  $line_items = $order_wrapper-&gt;commerce_line_items-&gt;value();
  if (is_array($line_items)) {
    foreach ($line_items as $line_item) {
      if (in_array($line_item-&gt;type, commerce_product_line_item_types())) {
        $product = commerce_product_load_by_sku($line_item-&gt;line_item_label);

        // Subtract the sold amount from the available stock level.
        $qty = (int) $line_item-&gt;quantity;
        module_load_include('inc', 'commerce_stock', 'commerce_stock.rules');
        commerce_stock_adjust($product, -$qty);

        // Disable the product if we have no stock left
        $product_wrapper = entity_metadata_wrapper('commerce_product', $product);
        if ($product_wrapper-&gt;commerce_stock-&gt;value() &lt;= 0) {
          $product_wrapper-&gt;status-&gt;set(0);
          $result = $product_wrapper-&gt;save();

          if ($result) {
            watchdog('commerce_stock', 'Product %sku stock level reached 0, status set to 0.', array('%sku' =&gt; $product-&gt;sku));
          }
          else {
            watchdog('commerce_stock', 'Failed attempt to disable product %sku', array('%sku' =&gt; $product-&gt;sku), WATCHDOG_ERROR);
          }
        }
      }   
    }
  }
}


It's just a copy of the default rule that ships with the module with the extra code for disabling the product added in.

I guess you could leave the default rule active and remove the 3 lines that adjust the stock level in my example, but then I'm not sure what would be called first, the rule or my hook so you would have to test that yourself.