Projet

Général

Profil

Paste
Télécharger (2,22 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / commerce / modules / cart / commerce_cart.rules_defaults.inc @ 651307cd

1
<?php
2

    
3
/**
4
 * @file
5
 * Default rule configurations for Cart.
6
 */
7

    
8
/**
9
 * Implements hook_default_rules_configuration().
10
 */
11
function commerce_cart_default_rules_configuration() {
12
  $rules = array();
13

    
14
  // Add a reaction rule to display the default Add to Cart message.
15
  $rule = rules_reaction_rule();
16

    
17
  $rule->label = t('Display an Add to Cart message');
18
  $rule->tags = array('Commerce Cart');
19
  $rule->active = TRUE;
20

    
21
  $rule
22
    ->event('commerce_cart_product_add')
23
    ->action('commerce_cart_add_to_cart_message', array(
24
      'commerce_product:select' => 'commerce-product',
25
    ));
26

    
27
  $rules['commerce_cart_add_to_cart_message'] = $rule;
28

    
29
  // Add a reaction rule to update a shopping cart order's status to "Shopping
30
  // cart" when a product is added to or removed from the order.
31
  $rule = rules_reaction_rule();
32

    
33
  $rule->label = t('Reset the cart order status on product add or remove');
34
  $rule->tags = array('Commerce Cart');
35
  $rule->active = TRUE;
36

    
37
  $rule
38
    ->event('commerce_cart_product_add')
39
    ->event('commerce_cart_product_remove')
40
    ->action('commerce_order_update_status', array(
41
      'commerce_order:select' => 'commerce-order',
42
      'order_status' => 'cart',
43
    ));
44

    
45
  $rules['commerce_cart_order_status_reset'] = $rule;
46

    
47
  // Add a reaction rule to unset the price of disabled products in the cart
48
  // during price calculation, effectively removing them from the order.
49
  $rule = rules_reaction_rule();
50

    
51
  $rule->label = t('Unset the price of disabled products in the cart');
52
  $rule->tags = array('Commerce Cart');
53
  $rule->active = TRUE;
54
  $rule->weight = 10;
55

    
56
  $rule
57
    ->event('commerce_product_calculate_sell_price')
58
    ->condition(rules_condition('data_is_empty', array(
59
      'data:select' => 'commerce-line-item:line-item-id',
60
    ))->negate())
61
    ->condition('entity_has_field', array(
62
      'entity:select' => 'commerce-line-item',
63
      'field' => 'commerce_product',
64
    ))
65
    ->condition('data_is', array(
66
      'data:select' => 'commerce-line-item:commerce-product:status',
67
      'op' => '==',
68
      'value' => '0',
69
    ))
70
    ->action('data_set', array(
71
      'data:select' => 'commerce-line-item:commerce-unit-price:amount',
72
    ));
73

    
74
  $rules['commerce_cart_unset_disabled_products'] = $rule;
75

    
76
  return $rules;
77
}