/[drupal]/contributions/modules/ec_inventory/ec_inventory.module
ViewVC logotype

Contents of /contributions/modules/ec_inventory/ec_inventory.module

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


Revision 1.1 - (show annotations) (download) (as text)
Fri May 4 23:11:24 2007 UTC (2 years, 6 months ago) by darrenoh
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-5
File MIME type: text/x-php
Allow inventory management for any product type.
1 <?php
2 // $Id$
3
4 /**
5 * Implementation of hook_help().
6 */
7 function ec_inventory_help($section) {
8 switch ($section) {
9 case 'admin/help#ec_inventory':
10 $output = '<p>'. t('The EC inventory module enables inventory control for any product type. To enable inventory control for a product type, go to !link and check the box for that product type. An inventory control section will then appear when you edit products of that type.', array('!link' => l('Inventory product types', 'admin/ecsettings/ec_inventory'))) .'</p>';
11 return $output;
12 }
13 }
14
15 /**
16 * Implementation of hook_menu().
17 */
18 function ec_inventory_menu($may_cache) {
19 global $user;
20 $items = array();
21 if ($may_cache) {
22 $items[] = array(
23 'path' => 'admin/ecsettings/ec_inventory',
24 'title' => t('Inventory product types'),
25 'description' => t('Enable inventory management for non-shippable product types.'),
26 'access' => user_access('administer store'),
27 'callback' => 'drupal_get_form',
28 'callback arguments' => array('ec_inventory_admin_products'),
29 );
30 }
31 return $items;
32 }
33
34 /**
35 * Menu callback; configure ec_inventory settings.
36 */
37 function ec_inventory_admin_products() {
38 $form[] = array(
39 '#value' => '<p>'. t('Enable inventory control for product types. Remember that inventory control is built in to some product types.') .'</p>',
40 );
41 foreach (product_get_ptypes() as $ptype => $name) {
42 $form[$ptype] = array(
43 '#type' => 'checkbox',
44 '#title' => $name,
45 '#default_value' => db_result(db_query("SELECT inventory_enabled FROM {ec_inventory_types} WHERE ptype = '%s'", $ptype)),
46 );
47 }
48 return system_settings_form($form);
49 }
50
51 /**
52 * Submit ec_inventory settings.
53 */
54 function ec_inventory_admin_products_submit($form_id, $form_values) {
55 foreach ($form_values as $ptype => $value) {
56 if (db_num_rows(db_query("SELECT * FROM {ec_inventory_types} WHERE ptype = '%s'", $ptype)) == 0) {
57 db_query("INSERT INTO {ec_inventory_types} (ptype, inventory_enabled) VALUES ('%s', %d)", $ptype, $value);
58 }
59 else {
60 db_query("UPDATE {ec_inventory_types} SET inventory_enabled = %d WHERE ptype = '%s'", $value, $ptype);
61 }
62 }
63 drupal_set_message(t('Inventory settings have been saved.'));
64 }
65
66 /**
67 * Implementation of hook_form_alter().
68 */
69 function ec_inventory_form_alter($form_id, &$form) {
70 switch ($form_id) {
71 case 'product_node_form':
72 $ptype = $form['product']['ptype']['#value'];
73 if (db_result(db_query("SELECT inventory_enabled FROM {ec_inventory_types} WHERE ptype = '%s'", $ptype))) {
74 $form = module_invoke('tangible', 'productapi', $form['#node'], 'form');
75 unset($form['availability']);
76 return $form;
77 }
78 break;
79 }
80 }
81
82 /**
83 * Implementation of hook_nodeapi().
84 */
85 function ec_inventory_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
86 if (!empty($node->type)) {
87 if (db_result(db_query("SELECT inventory_enabled FROM {ec_inventory_types} WHERE ptype = '%s'", $node->ptype))) {
88 switch ($op) {
89 case 'validate':
90 case 'insert':
91 case 'load':
92 case 'update':
93 case 'delete':
94 module_invoke('tangible', 'productapi', $node, $op);
95 break;
96 }
97 }
98 }
99 }
100

  ViewVC Help
Powered by ViewVC 1.1.2