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

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

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


Revision 1.6 - (show annotations) (download) (as text)
Thu Jul 10 12:41:06 2008 UTC (16 months, 2 weeks ago) by islandusurper
Branch: MAIN
CVS Tags: DRUPAL-5--1-1, DRUPAL-5--1-2, HEAD
Branch point for: DRUPAL-5, DRUPAL-6--2
Changes since 1.5: +0 -0 lines
File MIME type: text/x-php
Begin the Ubercart 6.x-2.x branch.
1 <?php
2 // $Id$
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 * Workflow-ng Hooks *
13 ******************************************************************************/
14
15 /**
16 * Implementation of hook_configuration().
17 */
18 function uc_stock_configuration() {
19 $configurations = array();
20 $configurations['uc_stock_decrement_on_order'] = array(
21 '#label' => t('Decrement stock upon order submission'),
22 '#event' => 'checkout_complete',
23 '#module' => 'uc_stock',
24 );
25 $action = workflow_ng_use_action('uc_stock_action_decrement_stock', array(
26 '#label' => t('Decrement stock of products in order'),
27 '#arguments' => array(
28 'order' => array('#entity' => 'order', '#label' => t('Order')),
29 ),
30 ));
31 $configurations['uc_stock_decrement_on_order'] = workflow_ng_configure($configurations['uc_stock_decrement_on_order'], $action);
32 return $configurations;
33 }
34
35 /**
36 * Implementation of hook_action_info().
37 */
38 function uc_stock_action_info() {
39 return array(
40 'uc_stock_action_decrement_stock' => array(
41 '#label' => t('Decrement stock of products on the order with tracking activated.'),
42 '#arguments' => array(
43 'order' => array('#entity' => 'order', '#label' => t('Order')),
44 ),
45 '#module' => t('Stock'),
46 ),
47 );
48 }
49
50 /*******************************************************************************
51 * Workflow-ng Action Callbacks and Forms *
52 ******************************************************************************/
53
54 function uc_stock_action_decrement_stock($order, $settings) {
55 if (is_array($order->products)) {
56 $stock_warnings = array();
57 foreach ($order->products as $product) {
58 if (($stock = uc_stock_level($product->model)) !== FALSE) {
59 $stock_level = db_fetch_object(db_query("SELECT * FROM {uc_product_stock} WHERE sku = '%s'", $product->model));
60 if ((($stock - $product->qty) <= $stock_level->threshold) && !in_array($product->model, array_keys($stock_warnings))) {
61 $stock_level->stock -= $product->qty;
62 $stock_warnings[$product->model] = $stock_level;
63 }
64 uc_stock_adjust($product->model, -$product->qty);
65 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))));
66 }
67 }
68 if (!empty($stock_warnings) && variable_get('uc_stock_threshold_notification', FALSE)) {
69 foreach ($stock_warnings as $model => $stock_level) {
70 _uc_stock_send_mail($order, $stock_level);
71 }
72 }
73 }
74 }

  ViewVC Help
Powered by ViewVC 1.1.2