Projet

Général

Profil

Paste
Télécharger (10,1 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / commerce / modules / cart / commerce_cart.api.php @ 0f8e34f8

1
<?php
2

    
3
/**
4
 * @file
5
 * Hooks provided by the Cart module.
6
 */
7

    
8

    
9
/**
10
 * Allows modules to return a shopping cart order ID for a user before the Cart
11
 * module determines it using its default queries.
12
 *
13
 * Implementations of this hook are executed one at a time, meaning the first
14
 * implementation to return a non-NULL value will determine the current cart
15
 * order ID for the given user. Acceptable values will be either FALSE to
16
 * indicate that the user should not be considered to have a valid cart order or
17
 * an order ID to use besides the ID that would be returned by the default
18
 * queries in the Cart module.
19
 *
20
 * @param $uid
21
 *   The uid of the user whose shopping cart order ID should be returned.
22
 *
23
 * @return
24
 * The order ID (if a valid cart was found), FALSE (if the user should have no
25
 * current cart), or NULL (if the implementation cannot tell if the user has a
26
 * cart or not).
27
 */
28
function hook_commerce_cart_order_id($uid) {
29
  // No example.
30
}
31

    
32
/**
33
 * Determines whether or not the given order is a shopping cart order.
34
 *
35
 * When determining if an order should be considered a shopping cart order, the
36
 * Cart module provides a simple order status comparison but allows other
37
 * modules to make the decision based on some other criteria. Any module can
38
 * invalidate the cart status of an order by returning FALSE from this hook, but
39
 * a module can also opt to treat an order in a non-cart status as a cart by
40
 * receiving the second argument by reference and setting it to TRUE. It should
41
 * just be noted that this value could be returned to FALSE by some other
42
 * module implementing the same hook.
43
 *
44
 * @param $order
45
 *   The order whose cart status is being determined.
46
 * @param $is_cart
47
 *   Boolean indicating whether or not the order should be considered a cart
48
 *   order; initialized based on the order status.
49
 *
50
 * @return
51
 *   FALSE to indicate that an order should not be treated as a cart.
52
 *
53
 * @deprecated since 7.x-1.2, use hook_commerce_cart_order_is_cart_alter() instead.
54
 * @see commerce_cart_order_is_cart()
55
 * @see hook_commerce_cart_order_is_cart_alter()
56
 */
57
function hook_commerce_cart_order_is_cart($order, &$is_cart) {
58
  // No example.
59
}
60

    
61
/**
62
 * Alter the cart status of an order.
63
 *
64
 * When determining if an order should be considered a shopping cart order, the
65
 * Cart module provides a simple order status comparison but allows other
66
 * modules to make the decision based on some other criteria.
67
 *
68
 * @param $is_cart
69
 *   Boolean indicating whether or not the order should be considered a cart
70
 *   order; initialized based on the order status.
71
 * @param $order
72
 *   The order whose cart status is being determined.
73
 */
74
function hook_commerce_cart_order_is_cart_alter(&$is_cart, $order) {
75
  // No example.
76
}
77

    
78
/**
79
 * Allows modules to perform additional processing to convert an anonymous
80
 * shopping cart order to an authenticated cart.
81
 *
82
 * When anonymous users login to the site, if they have shopping cart orders,
83
 * those are converted to authenticated shopping carts. This means their uid and
84
 * mail properties are updated along with the uid of any referenced customer
85
 * profiles. Additional modules can implement their own logic via this hook,
86
 * such as canceling any existing shopping cart orders the user might already
87
 * have prior to conversion of the anonymous cart.
88
 *
89
 * Modules that implement this hook do not need to save changes to the order, as
90
 * the Cart module will save the order after invoking the hook.
91
 *
92
 * @param $order_wrapper
93
 *   The entity metadata wrapper for the order being refreshed.
94
 * @param $account
95
 *   The user account the order will belong to.
96
 *
97
 * @see commerce_cart_order_convert()
98
 */
99
function hook_commerce_cart_order_convert($order_wrapper, $account) {
100
  // No example.
101
}
102

    
103
/**
104
 * Allows modules to perform processing on a shopping cart order prior to the
105
 * logic in commerce_cart_order_refresh() taking place.
106
 *
107
 * @param $order_wrapper
108
 *   The entity metadata wrapper for the order about to be refreshed.
109
 *
110
 * @see commerce_cart_order_refresh()
111
 * @see entity_metadata_wrapper()
112
 */
113
function hook_commerce_cart_order_pre_refresh($order_wrapper) {
114
  // No example.
115
}
116

    
117
/**
118
 * Allows modules to perform additional processing to refresh an individual line
119
 * item on a shopping cart order.
120
 *
121
 * Prior to this hook being invoked, product line items will have already had
122
 * their sell prices refreshed via the creation of a new line item for the same
123
 * product being passed through Rules for calculation.
124
 *
125
 * @param $line_item
126
 *   A line item object that should be updated as necessary for the refresh.
127
 * @param $order_wrapper
128
 *   An EntityMetadataWrapper for the order the line item is attached to.
129
 *
130
 * @see commerce_cart_order_refresh()
131
 */
132
function hook_commerce_cart_line_item_refresh($line_item, $order_wrapper) {
133
  // No example.
134
}
135

    
136
/**
137
 * Allows modules to perform additional processing to refresh a shopping cart
138
 * order's contents.
139
 *
140
 * When an order is loaded, if it is in a shopping cart order status, its
141
 * contents are refreshed to get the current product prices. This prevents users
142
 * from checking out orders with stale contents. The API function
143
 * commerce_cart_order_refresh() takes care of product line item updates, but
144
 * this hook can be used for any additional updates.
145
 *
146
 * Modules that implement this hook do not need to save changes to the order, as
147
 * the Cart module will save the order after invoking the hook.
148
 *
149
 * @param $order_wrapper
150
 *   The entity metadata wrapper for the order being refreshed.
151
 *
152
 * @see commerce_cart_order_refresh()
153
 * @see entity_metadata_wrapper()
154
 */
155
function hook_commerce_cart_order_refresh($order_wrapper) {
156
  // No example.
157
}
158

    
159
/**
160
 * Allows modules to perform additional processing when emptying a shopping cart
161
 * order.
162
 *
163
 * Modules that implement this hook do not need to save changes to the order, as
164
 * the Cart module will save the order after invoking the hook.
165
 *
166
 * @param $order
167
 *   The order being emptied.
168
 *
169
 * @see commerce_cart_order_empty()
170
 */
171
function hook_commerce_cart_order_empty($order) {
172
  // No example.
173
}
174

    
175
/**
176
 * Allows modules to add arbitrary AJAX commands to the array returned from the
177
 * Add to Cart form attributes refresh.
178
 *
179
 * When a product selection widget's value is changed, whether it is a product
180
 * select list or a product attribute field widget, the Add to Cart form gets
181
 * an AJAX refresh. The form will be rebuilt using the new form state and the
182
 * AJAX callback of the element that was changed will be called. For this form
183
 * it is commerce_cart_add_to_cart_form_attributes_refresh().
184
 *
185
 * The cart form's particular AJAX refresh function returns an array of AJAX
186
 * commands that perform HTML replacement on the page. However, other modules
187
 * may want to interact with the refreshed form. They can use this hook to
188
 * add additional items to the commands array, which is passed to the hook by
189
 * reference. Note that the form array and form state cannot be altered, just
190
 * the array of commands.
191
 *
192
 * @param &$commands
193
 *   The array of AJAX commands used to refresh the cart form with updated form
194
 *   elements and to replace product fields rendered on the page to match the
195
 *   currently selected product.
196
 * @param $form
197
 *   The rebuilt form array.
198
 * @param $form_state
199
 *   The form state array from the form.
200
 *
201
 * @see commerce_cart_add_to_cart_form_attributes_refresh()
202
 */
203
function hook_commerce_cart_attributes_refresh_alter(&$commands, $form, $form_state) {
204
  // Display an alert message showing the new default product ID.
205
  $commands[] = ajax_command_alert(t('Now defaulted to product @product_id.', array('@product_id' => $form['product_id']['#value'])));
206
}
207

    
208
/**
209
 * Allows modules to add additional property names to an array of comparison
210
 * properties used to determine whether or not a product line item can be
211
 * combined into an existing line item when added to the cart.
212
 *
213
 * @param &$comparison_properties
214
 *   The array of property names (including field names) that map to properties
215
 *   on the line item wrappers being compared to check for combination.
216
 * @param $line_item
217
 *   A clone of the line item being added to the cart. Since this is a clone,
218
 *   changes made to it will not propagate up to the Add to Cart process.
219
 */
220
function hook_commerce_cart_product_comparison_properties_alter(&$comparison_properties, $line_item) {
221
  // Force separate line items when the same product is added to the cart from
222
  // different display paths.
223
  $comparison_properties[] = 'commerce_display_path';
224
}
225

    
226
/**
227
 * Rules event hook: allows modules to operate prior to adding a product to the
228
 * cart but does not actually allow you to interrupt the process.
229
 *
230
 * Invoking this Rules event / hook does not result in the processing of any
231
 * return value, so it is not useful for interrupting a cart product add
232
 * operation outside of a redirect.
233
 *
234
 * @param $order
235
 *   The cart order object the product will be added to.
236
 * @param $product
237
 *   The product being added to the cart.
238
 * @param $quantity
239
 *   The quantity of the product to add to the cart.
240
 */
241
function hook_commerce_cart_product_prepare($order, $product, $quantity) {
242
  // No example.
243
}
244

    
245
/**
246
 * Rules event hook: allows modules to react to the addition of a product to a
247
 * shopping cart order.
248
 *
249
 * @param $order
250
 *   The cart order object the product was added to.
251
 * @param $product
252
 *   The product that was added to the cart.
253
 * @param $quantity
254
 *   The quantity of the product added to the cart.
255
 * @param $line_item
256
 *   The new or updated line item representing that product on the given order.
257
 */
258
function hook_commerce_cart_product_add($order, $product, $quantity, $line_item) {
259
  // No example.
260
}
261

    
262
/**
263
 * Rules event hook: allows modules to react to the removal of a product from a
264
 * shopping cart order.
265
 *
266
 * @param $order
267
 *   The cart order object the product was removed from.
268
 * @param $product
269
 *   The product that was removed from the cart.
270
 * @param $quantity
271
 *   The quantity of the product line item removed from the cart.
272
 * @param $line_item
273
 *   The product line item that was deleted to remove the product from the cart.
274
 */
275
function hook_commerce_cart_product_remove($order, $product, $quantity, $line_item) {
276
  // No example.
277
}