You are here

function uc_stock_adjust in Ubercart 6.2

Same name and namespace in other branches
  1. 8.4 uc_stock/uc_stock.module \uc_stock_adjust()
  2. 5 uc_stock/uc_stock.module \uc_stock_adjust()
  3. 7.3 uc_stock/uc_stock.module \uc_stock_adjust()

Adjusts the product stock level by a set amount.

Parameters

$sku: The product SKU of the stock level to adjust.

$qty: The amount to add to or subtract from the stock level.

1 call to uc_stock_adjust()
uc_stock_adjust_product_stock in uc_stock/uc_stock.module
Adjusts a product's stock.

File

uc_stock/uc_stock.module, line 270

Code

function uc_stock_adjust($sku, $qty, $check_active = TRUE) {
  $stock = db_fetch_object(db_query("SELECT active, stock FROM {uc_product_stock} WHERE sku = '%s'", $sku));
  if ($check_active) {
    if (!$stock->active) {
      return;
    }
  }
  db_query("UPDATE {uc_product_stock} SET stock = stock + %d WHERE sku = '%s'", $qty, $sku);
  module_invoke_all('uc_stock_adjusted', $sku, $stock->stock, $qty);
}