function uc_stock_action_decrement_stock in Ubercart 5
Same name and namespace in other branches
- 6.2 uc_stock/uc_stock.ca.inc \uc_stock_action_decrement_stock()
- 7.3 uc_stock/uc_stock.rules.inc \uc_stock_action_decrement_stock()
1 string reference to 'uc_stock_action_decrement_stock'
- uc_stock_configuration in uc_stock/
uc_stock_workflow.inc - Implementation of hook_configuration().
File
- uc_stock/
uc_stock_workflow.inc, line 53 - This file contains all the Workflow-NG hooks that are neccesary for Workflow integeration with the uc_stock module
Code
function uc_stock_action_decrement_stock($order, $settings) {
if (is_array($order->products)) {
$stock_warnings = array();
foreach ($order->products as $product) {
if (($stock = uc_stock_level($product->model)) !== FALSE) {
$stock_level = db_fetch_object(db_query("SELECT * FROM {uc_product_stock} WHERE sku = '%s'", $product->model));
if ($stock - $product->qty <= $stock_level->threshold && !in_array($product->model, array_keys($stock_warnings))) {
$stock_level->stock -= $product->qty;
$stock_warnings[$product->model] = $stock_level;
}
uc_stock_adjust($product->model, -$product->qty);
uc_order_comment_save($order->order_id, 0, t('The stock level for %model_name has been decreased to !qty.', array(
'%model_name' => $product->model,
'!qty' => $stock - $product->qty,
)));
}
}
if (!empty($stock_warnings) && variable_get('uc_stock_threshold_notification', FALSE)) {
foreach ($stock_warnings as $model => $stock_level) {
_uc_stock_send_mail($order, $stock_level);
}
}
}
}