/[drupal]/contributions/modules/ubercart/uc_stock/uc_stock.ca.inc
ViewVC logotype

Contents of /contributions/modules/ubercart/uc_stock/uc_stock.ca.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Mon Jul 21 13:18:37 2008 UTC (16 months ago) by islandusurper
Branch: MAIN
CVS Tags: DRUPAL-5--1-2, DRUPAL-5--1-1, HEAD
Branch point for: DRUPAL-6--2
File MIME type: text/x-php
Add ca.css and uc_stock.ca.inc to the repository.
1 <?php
2 // $Id: uc_stock_workflow.inc,v 1.5 2008/06/04 20:33:22 rszrama Exp $
3
4 /**
5 * @file
6 * This file contains all the Workflow-NG hooks that are neccesary for Workflow
7 * integeration with the uc_stock module
8 */
9
10
11 /******************************************************************************
12 * Conditional Action Hooks *
13 ******************************************************************************/
14
15 /**
16 * Implementation of hook_configuration().
17 */
18 function uc_stock_ca_predicate() {
19 $predicates['uc_stock_decrement_on_order'] = array(
20 '#title' => t('Decrement stock upon order submission'),
21 '#trigger' => 'checkout_complete',
22 '#class' => 'uc_stock',
23 '#actions' => array(
24 array(
25 '#name' => 'uc_stock_action_decrement_stock',
26 '#title' => t('Decrement stock of products in order'),
27 '#arguments' => array(
28 'order' => array(
29 '#entity' => 'order',
30 '#title' => t('Order'),
31 ),
32 ),
33 ),
34 ),
35 );
36
37 return $predicates;
38 }
39
40 /**
41 * Implementation of hook_action_info().
42 */
43 function uc_stock_ca_action() {
44 $actions['uc_stock_action_decrement_stock'] = array(
45 '#title' => t('Decrement stock of products on the order with tracking activated.'),
46 '#callback' => 'uc_stock_action_decrement_stock',
47 '#arguments' => array(
48 'order' => array('#entity' => 'order', '#title' => t('Order')),
49 ),
50 '#category' => t('Stock'),
51 );
52
53 return $actions;
54 }
55
56 /******************************************************************************
57 * Conditional Action Callbacks and Forms *
58 ******************************************************************************/
59
60 function uc_stock_action_decrement_stock($order, $settings) {
61 if (is_array($order->products)) {
62 $stock_warnings = array();
63 foreach ($order->products as $product) {
64 if (($stock = uc_stock_level($product->model)) !== FALSE) {
65 $stock_level = db_fetch_object(db_query("SELECT * FROM {uc_product_stock} WHERE sku = '%s'", $product->model));
66 if ((($stock - $product->qty) <= $stock_level->threshold) && !in_array($product->model, array_keys($stock_warnings))) {
67 $stock_level->stock -= $product->qty;
68 $stock_warnings[$product->model] = $stock_level;
69 }
70 uc_stock_adjust($product->model, -$product->qty);
71 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))));
72 }
73 }
74 if (!empty($stock_warnings) && variable_get('uc_stock_threshold_notification', FALSE)) {
75 foreach ($stock_warnings as $model => $stock_level) {
76 _uc_stock_send_mail($order, $stock_level);
77 }
78 }
79 }
80 }

  ViewVC Help
Powered by ViewVC 1.1.2