You are here

function _commerce_reports_stock_get_stockenabled_products in Commerce Reporting 7.3

Get the stock enabled products

File

modules/stock/commerce_reports_stock.module, line 95
This module provides advanced stock reporting for Drupal Commerce.

Code

function _commerce_reports_stock_get_stockenabled_products() {
  $products = commerce_product_load_multiple(array(), array(
    'status' => 1,
  ));

  // Check which ones are stock enabled
  foreach (commerce_product_types() as $type => $product_type) {
    $instance[$type] = field_info_instance('commerce_product', 'commerce_stock', $type);
    $enabled[$type] = !empty($instance[$type]);
  }

  // Key by SKU
  $productlist = array();
  foreach ($products as $product) {
    if ($enabled[$product->type]) {
      $productlist[$product->sku] = $product;
    }
  }
  return $productlist;
}