Projet

Général

Profil

Paste
Télécharger (7,28 ko) Statistiques
| Branche: | Révision:

root / htmltest / sites / all / modules / commerce / commerce.api.php @ a5572547

1
<?php
2

    
3
/**
4
 * @file
5
 * This file contains no working PHP code; it exists to provide additional
6
 * documentation for doxygen as well as to document hooks in the standard
7
 * Drupal manner.
8
 */
9

    
10
/**
11
 * Defines currencies available to the Commerce currency formatting and price APIs.
12
 *
13
 * By default Drupal Commerce defines all actively traded currencies according
14
 * to ISO 4217. Additional currencies may be added by modules that depend on
15
 * alternate or pseudo-currency definitions.
16
 *
17
 * @return
18
 *   An array of currency data arrays keyed by three character currency codes.
19
 *   Currency data arrays should include:
20
 *   - code: The uppercase alphabetic currency code. For example USD.
21
 *   - numeric_code: The numeric currency code. According to ISO4217 this code
22
 *     consists of three digits and first digit can be a zero.
23
 *   - symbol: The currency symbol. For example $.
24
 *   - name: The name of the currency. Translatable.
25
 *   - symbol_placement: Defines where the currency symbol has to be placed for
26
 *      display. Allowed values: before, after, hidden.
27
 *   - symbol_spacer: The spacer to put between the price amount and a currency
28
 *     symbol that appears after the amount; defaults to ' '.
29
 *   - code_placement: Defines where the currency code has to be placed for
30
 *      display. Allowed values: before, after, hidden.
31
 *   - code_spacer: The spacer to put between the price amount and currency code
32
 *     whether the code is displayed before or after the amount; defaults to ' '.
33
 *   - minor_unit: Name of the minor unit of the currency. For example Cent.
34
 *     Translatable
35
 *   - major_unit: Name of the major unit of the currency. For example Dollar.
36
 *     Translatable
37
 *   - rounding_step: Defines which stepping has to is used for price rounding.
38
 *     For example Swiss Francs use a rounding_step of 0.05. This means a
39
 *     price like 10.93 is converted to 10.95. Currently only the steps
40
 *     0.5,0.05... and 0.2, 0.02 ... are supported. This value has to be
41
 *     defined as string, otherwise the rounding results can be unpredictable.
42
 *     Default: 0 (no special rounding)
43
 *   - decimals: The number of decimals to display.
44
 *     Default: 2
45
 *   - thousands_separator: The char to split the value in groups of thousand.
46
 *     Default: ,
47
 *   - decimal_separator: The char to split the integer from the decimal part.
48
 *     Default: .
49
 *   - format_callback: Custom callback function to format a price value.
50
 *   - conversion_callback: Custom callback function to convert a price amount
51
 *     from one currency into another.
52
 *   - conversion_rate: The conversion rate of this currency calculated against
53
 *     the base currency, expressed as a decimal value denoting the value of
54
 *     one major unit of this currency when converted to the base currency.
55
 *     Default: 1
56
 *
57
 * @see hook_commerce_currency_info_alter()
58
 */
59
function hook_commerce_currency_info() {
60
  return array (
61
    'CHF' => array(
62
      'code' => 'CHF',
63
      'numeric_code' => '756',
64
      'symbol' => 'Fr.',
65
      'name' => t('Swiss Franc'),
66
      'symbol_placement' => 'before',
67
      'code_placement' => 'before',
68
      'minor_unit' => t('Rappen'),
69
      'major_unit' => t('Franc'),
70
      'rounding_step' => '0.05',
71
    ),
72
  );
73
}
74

    
75
/**
76
 * Allows modules to alter Commerce currency definitions.
77
 *
78
 * By default Commerce provides all active currencies according to ISO 4217.
79
 * This hook allows you to change the formatting properties of existing
80
 * definitions.
81
 *
82
 * Additionally, because every currency's default conversion rate is 1, this
83
 * hook can be used to populate currency conversion rates with meaningful
84
 * values. Conversion rates can be calculated using any currency as the base
85
 * currency as long as the same base currency is used for every rate.
86
 *
87
 * @see hook_commerce_currency_info()
88
 */
89
function hook_commerce_currency_info_alter(&$currencies, $langcode) {
90
  $currencies['CHF']['code_placement'] = 'after';
91
}
92

    
93
/**
94
 * Allows modules to deny or provide access for a user to perform a non-view
95
 * operation on an entity before any other access check occurs.
96
 *
97
 * Modules implementing this hook can return FALSE to provide a blanket
98
 * prevention for the user to perform the requested operation on the specified
99
 * entity. If no modules implementing this hook return FALSE but at least one
100
 * returns TRUE, then the operation will be allowed, even for a user without
101
 * role based permission to perform the operation.
102
 *
103
 * If no modules return FALSE but none return TRUE either, normal permission
104
 * based checking will apply.
105
 *
106
 * @param $op
107
 *   The request operation: update, create, or delete.
108
 * @param $entity
109
 *   The entity to perform the operation on.
110
 * @param $account
111
 *   The user account whose access should be determined.
112
 * @param $entity_type
113
 *   The machine-name of the entity type of the given $entity.
114
 *
115
 * @return
116
 *   TRUE or FALSE indicating an explicit denial of permission or a grant in the
117
 *   presence of no other denials; NULL to not affect the access check at all.
118
 */
119
function hook_commerce_entity_access($op, $entity, $account, $entity_type) {
120
  // No example.
121
}
122

    
123
/**
124
 * Allows modules to alter the conditions used on the query to grant view access
125
 * to a Commerce entity of the specified ENTITY TYPE.
126
 *
127
 * The Commerce module defines a generic implementation of hook_query_alter() to
128
 * determine view access for its entities, commerce_entity_access_query_alter().
129
 * This function is called by modules defining Commerce entities from their
130
 * view access altering functions to apply a standard set of permission based
131
 * conditions for determining a user's access to view the given entity.
132
 *
133
 * @param $conditions
134
 *   The OR conditions group used for the view access query.
135
 * @param $context
136
 *   An array of contextual information including:
137
 *   - account: the account whose access to view the entity is being checked
138
 *   - entity_type: the type of entity in the query
139
 *   - base_table: the name of the table for the entity type
140
 *
141
 * @see commerce_entity_access_query_alter()
142
 * @see commerce_cart_commerce_entity_access_condition_commerce_order_alter()
143
 */
144
function hook_commerce_entity_access_condition_ENTITY_TYPE_alter() {
145
  // See the Cart implementation of the hook for an example, as the Cart module
146
  // alters the view query to grant view access of orders to anonymous users who
147
  // own them based on the order IDs stored in the anonymous session.
148
}
149

    
150
/**
151
 * Allows modules to alter the conditions used on the query to grant view access
152
 * to a Commerce entity.
153
 *
154
 * This hook uses the same parameters as the entity type specific hook but is
155
 * invoked after it.
156
 *
157
 * @see hook_commerce_entity_access_condition_ENTITY_TYPE_alter()
158
 */
159
function hook_commerce_entity_access_condition_alter() {
160
  // No example.
161
}
162

    
163
/**
164
 * Allows modules to alter newly created Commerce entities.
165
 *
166
 * Commerce's default entity controller, DrupalCommerceEntityController, invokes
167
 * this hook after creating a new entity object using either a class specified
168
 * by the entity type info or a stdClass. Using this hook, you can alter the
169
 * entity before it is returned to any of our entity "new" API functions such
170
 * as commerce_product_new().
171
 *
172
 * @param $entity_type
173
 *   The machine-name type of the entity.
174
 * @param $entity
175
 *   The entity object that was just created.
176
 */
177
function hook_commerce_entity_create_alter($entity_type, $entity) {
178
  // No example.
179
}