function uc_stock_adjust_product_stock in Ubercart 6.2
Same name and namespace in other branches
- 8.4 uc_stock/uc_stock.module \uc_stock_adjust_product_stock()
- 7.3 uc_stock/uc_stock.module \uc_stock_adjust_product_stock()
Adjusts a product's stock.
Parameters
$product: The product whose stock is being adjusted.
$key: Internal, so this function can be used as a callback of array_walk().
$order: Order object.
3 calls to uc_stock_adjust_product_stock()
- uc_stock_decrement_product_stock in uc_stock/
uc_stock.module - Deprecated. Wrapper function for uc_stock_adjust_product_stock().
- uc_stock_increment_product_stock in uc_stock/
uc_stock.module - Increment a product's stock.
- uc_stock_order in uc_stock/
uc_stock.module - Implementation of hook_order().
1 string reference to 'uc_stock_adjust_product_stock'
- uc_stock_action_decrement_stock in uc_stock/
uc_stock.ca.inc - Decreases the stock of ordered products.
File
- uc_stock/
uc_stock.module, line 403
Code
function uc_stock_adjust_product_stock($product, $key, $order) {
// Product has an active stock?
if (!uc_stock_is_active($product->model)) {
return;
}
// Do nothing if decrement quantity is 0
if ($product->qty == 0) {
return;
}
// Adjust the product's stock.
uc_stock_adjust($product->model, -$product->qty);
// Load the new stock record
$stock = db_fetch_object(db_query("SELECT * FROM {uc_product_stock} WHERE sku = '%s'", $product->model));
// Should we notify?
if (variable_get('uc_stock_threshold_notification', FALSE) && $stock->stock <= $stock->threshold) {
$node = node_load($product->nid);
_uc_stock_send_mail($order, $node, $stock);
}
// Save a comment about the stock level.
uc_order_comment_save($order->order_id, 0, t('The stock level for %model_name has been !action to !qty.', array(
'%model_name' => $product->model,
'!qty' => $stock->stock,
'!action' => -$product->qty <= 0 ? t('decreased') : t('increased'),
)));
}