Projet

Général

Profil

Paste
Télécharger (5,66 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / commerce / modules / product_pricing / commerce_product_pricing_ui.module @ 13755f8d

1
<?php
2

    
3
/**
4
 * @file
5
 * Exposes a UI for managing product pricing rules and pre-calculation settings.
6
 */
7

    
8

    
9
/**
10
 * Implements hook_menu().
11
 */
12
function commerce_product_pricing_ui_menu() {
13
  $items = array();
14

    
15
  // Product price calculation Rules admin overview.
16
  $items['admin/commerce/config/product-pricing'] = array(
17
    'title' => 'Product pricing rules',
18
    'description' => 'Enable and configure product pricing rules and pre-calculation.',
19
    'page callback' => 'commerce_product_pricing_ui_sell_price_rules',
20
    'access arguments' => array('administer product pricing'),
21
    'file' => 'includes/commerce_product_pricing_ui.admin.inc',
22
  );
23

    
24
  $items['admin/commerce/config/product-pricing/rules'] = array(
25
    'title' => 'List',
26
    'description' => 'Administer the rules used for calculating product sell prices.',
27
    'weight' => 0,
28
    'type' => MENU_DEFAULT_LOCAL_TASK,
29
  );
30

    
31
  // Add the menu items for the various Rules forms.
32
  $controller = new RulesUIController();
33
  $items += $controller->config_menu('admin/commerce/config/product-pricing/rules');
34

    
35
  $items['admin/commerce/config/product-pricing/rules/add'] = array(
36
    'title' => 'Add a pricing rule',
37
    'description' => 'Adds an additional sell price calculation rule configuration.',
38
    'page callback' => 'drupal_get_form',
39
    'page arguments' => array('commerce_product_pricing_ui_add_pricing_rule_form', 'admin/commerce/config/product-pricing/rules'),
40
    'access arguments' => array('administer product pricing'),
41
    'file path' => drupal_get_path('module', 'rules_admin'),
42
    'file' => 'rules_admin.inc',
43
  );
44

    
45
  // Provide a configuration menu item for adjusting the product sell price
46
  // pre-calculation settings.
47
  $items['admin/commerce/config/product-pricing/pre-calculation'] = array(
48
    'title' => 'Pre-calculation',
49
    'description' => 'Configure the price pre-calculation settings.',
50
    'page callback' => 'drupal_get_form',
51
    'page arguments' => array('commerce_product_pre_calculation_settings_form'),
52
    'access arguments' => array('administer product pricing'),
53
    'weight' => 5,
54
    'type' => MENU_LOCAL_TASK,
55
    'file' => 'includes/commerce_product_pricing_ui.admin.inc',
56
  );
57

    
58
  return $items;
59
}
60

    
61
/**
62
 * Implements hook_permission().
63
 */
64
function commerce_product_pricing_ui_permission() {
65
  return array(
66
    'administer product pricing' => array(
67
      'title' => t('Administer product pricing'),
68
      'description' => t('Grants access to the sell price calculation user interface and settings form.'),
69
      'restrict access' => TRUE,
70
    ),
71
  );
72
}
73

    
74
/**
75
 * Implements hook_menu_local_tasks_alter().
76
 */
77
function commerce_product_pricing_ui_menu_local_tasks_alter(&$data, $router_item, $root_path) {
78
  // Add action link 'admin/commerce/config/product-pricing/rules/add' on
79
  // 'admin/commerce/config/product-pricing'.
80
  if ($root_path == 'admin/commerce/config/product-pricing') {
81
    $item = menu_get_item('admin/commerce/config/product-pricing/rules/add');
82
    if ($item['access']) {
83
      $data['actions']['output'][] = array(
84
        '#theme' => 'menu_local_action',
85
        '#link' => $item,
86
      );
87
    }
88
  }
89
}
90

    
91
/**
92
 * Implements hook_help().
93
 */
94
function commerce_product_pricing_ui_help($path, $arg) {
95
  switch ($path) {
96
    case 'admin/commerce/config/product-pricing':
97
      // TODO: Add a note regarding the restrictions that apply for price pre-
98
      // calculation based on the current pre-calculation method setting.
99
      return t('Prior to purchase, product sell prices are calculated using the rule configurations listed below. Pricing rules can be used for things like discounts, price lists, currency conversions, and tax application depending on the Rules elements defined by your enabled modules. To apply the enabled pricing rules on product display, you must ensure the display formatter settings for your product price fields are configured to display the <em>Calculated sell price for the current user</em>.');
100

    
101
    case 'admin/commerce/config/product-pricing/rules/add':
102
      return t('After setting the label for this rule configuration, you will be redirected to its empty edit page. There you should add the conditions that must be met for the pricing rule to apply. You can then use actions that alter the unit price of the product line item passed to the rule to affect the sell price customers will see prior to purchase.');
103
  }
104
}
105

    
106
/**
107
 * Implements hook_commerce_product_valid_pre_calculation_rule().
108
 */
109
function commerce_product_pricing_ui_commerce_product_valid_pre_calculation_rule($rule) {
110
  // If the given rule has been marked to be bypassed, return FALSE.
111
  $bypass = variable_get('commerce_product_sell_price_pre_calculation_rules_bypass', array());
112

    
113
  if (!empty($bypass[$rule->name]) && $bypass[$rule->name] == $rule->name) {
114
    return FALSE;
115
  }
116
}
117

    
118
/**
119
 * Implements hook_forms().
120
 */
121
function commerce_product_pricing_ui_forms($form_id, $args) {
122
  $forms = array();
123

    
124
  $forms['commerce_product_pricing_ui_add_pricing_rule_form'] = array(
125
    'callback' => 'rules_admin_add_reaction_rule',
126
  );
127

    
128
  return $forms;
129
}
130

    
131
/**
132
 * Implements hook_form_FORM_ID_alter().
133
 *
134
 * The Product Pricing UI module instantiates the Rules Admin rule configuration
135
 * add form at a particular path in the Commerce IA. It uses its own form ID to
136
 * do so and alters the form here to select the necessary Rules event.
137
 *
138
 * @see rules_admin_add_reaction_rule()
139
 */
140
function commerce_product_pricing_ui_form_commerce_product_pricing_ui_add_pricing_rule_form_alter(&$form, &$form_state) {
141
  unset($form['settings']['help']);
142
  $form['settings']['event']['#type'] = 'value';
143
  $form['settings']['event']['#value'] = 'commerce_product_calculate_sell_price';
144
  $form['submit']['#suffix'] = l(t('Cancel'), 'admin/commerce/config/product-pricing');
145
}