function uc_stock_adjust_product_stock in Ubercart 7.3
Same name and namespace in other branches
- 8.4 uc_stock/uc_stock.module \uc_stock_adjust_product_stock()
- 6.2 uc_stock/uc_stock.module \uc_stock_adjust_product_stock()
Decrement 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_order_edit_form_submit in uc_order/
uc_order.admin.inc - Form submission handler for uc_order_edit_form().
- uc_order_edit_products_add in uc_order/
uc_order.order_pane.inc - Form submit callback: add a product to an order.
- uc_stock_increment_product_stock in uc_stock/
uc_stock.module - Increment a product's stock.
1 string reference to 'uc_stock_adjust_product_stock'
- uc_stock_action_decrement_stock in uc_stock/
uc_stock.rules.inc - Decreases the stock of ordered products.
File
- uc_stock/
uc_stock.module, line 262 - Allow ubercart products to have stock levels associated with their SKU
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_query("SELECT * FROM {uc_product_stock} WHERE sku = :sku", array(
':sku' => $product->model,
))
->fetchObject();
// 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'),
)));
}