You are here

function commerce_stock_admin_init in Commerce Stock 7

This functions parses all the product of the specified bundle, and initialize its stock field (commerce_stock) to a value

Parameters

String $bundle: Commerce product bundle type to initialize

int $init_stock_value: Stock value to initialize to

Return value

void

1 call to commerce_stock_admin_init()
commerce_stock_admin_form_submit in includes/commerce_stock.admin.inc
Add or remove the Stock field from product types.

File

includes/commerce_stock.admin.inc, line 106
Administrative callbacks and form builder functions for Commerce Stock.

Code

function commerce_stock_admin_init($bundle, $init_stock_value) {

  //Load every product of $bundle type
  $products = commerce_product_load_multiple(array(), array(
    'type' => $bundle,
  ));

  //Parses each product to initialize its stock value
  foreach ($products as $product) {
    $wrapper = entity_metadata_wrapper('commerce_product', $product);

    //dpm($wrapper->getPropertyInfo());
    $wrapper->commerce_stock = $init_stock_value;
    $wrapper
      ->save();
  }
}