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

Contents of /contributions/modules/uc_node_checkout/uc_node_checkout.module

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


Revision 1.8 - (show annotations) (download) (as text)
Mon Jan 26 20:14:39 2009 UTC (10 months ago) by rszrama
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--2
Changes since 1.7: +309 -286 lines
File MIME type: text/x-php
Updating HEAD from latest work.
1 <?php
2 // $Id: uc_node_checkout.module,v 1.4.2.5 2009/01/20 22:28:19 rszrama Exp $
3
4 /**
5 * @file
6 * Associate node types with products on your site that customers can purchase.
7 */
8
9
10 /**
11 * Implementation of hook_menu().
12 */
13 function uc_node_checkout_menu() {
14 $items = array();
15
16 $items['admin/store/settings/node-checkout'] = array(
17 'title' => 'Node checkout settings',
18 'description' => 'Map products to node types and adjust node checkout behavior.',
19 'page callback' => 'uc_node_checkout_admin',
20 'access arguments' => array('administer node checkout'),
21 'type' => MENU_NORMAL_ITEM,
22 'file' => 'uc_node_checkout.admin.inc',
23 );
24 $items['admin/store/settings/node-checkout/overview'] = array(
25 'title' => 'Node types',
26 'type' => MENU_DEFAULT_LOCAL_TASK,
27 'weight' => -10,
28 'file' => 'uc_node_checkout.admin.inc',
29 );
30 $items['admin/store/settings/node-checkout/settings'] = array(
31 'title' => 'Settings',
32 'page callback' => 'drupal_get_form',
33 'page arguments' => array('uc_node_checkout_settings_form'),
34 'access arguments' => array('administer node checkout'),
35 'type' => MENU_LOCAL_TASK,
36 'file' => 'uc_node_checkout.admin.inc',
37 );
38 $items['uc_node_checkout/autocomplete'] = array(
39 'page callback' => 'uc_node_checkout_autocomplete',
40 'access arguments' => array('administer node checkout'),
41 'type' => MENU_CALLBACK,
42 'file' => 'uc_node_checkout.admin.inc',
43 );
44
45 $items['admin/store/settings/node-checkout/%uc_node_checkout_type'] = array(
46 'title callback' => 'uc_node_checkout_admin_settings_title',
47 'title arguments' => array(4),
48 'description' => 'Map a product to this node type.',
49 'page callback' => 'drupal_get_form',
50 'page arguments' => array('uc_node_checkout_type_form', 4),
51 'access arguments' => array('administer node checkout'),
52 'type' => MENU_CALLBACK,
53 'file' => 'uc_node_checkout.admin.inc',
54 );
55
56 return $items;
57 }
58
59 function uc_node_checkout_type_load($arg) {
60 $types = node_get_types('types');
61 foreach ($types as $type) {
62 if ($type->type == $arg) {
63 return $type;
64 }
65 }
66 return FALSE;
67 }
68
69 function uc_node_checkout_admin_settings_title($type) {
70 return t('@type product checkout', array('@type' => $type->name));
71 }
72
73 /**
74 * Implementation of hook_perm().
75 */
76 function uc_node_checkout_perm() {
77 return array('administer node checkout');
78 }
79
80 /**
81 * Implementation of hook_help().
82 */
83 function uc_node_checkout_help($path, $arg) {
84 switch ($path) {
85 case 'admin/store/settings/node-checkout':
86 return t('The table represents products associated with node types on your site. If you want a node type to be governed by UC Node Checkout, simply click its edit link and specify which product node on your site should be added to the cart when a node of that type gets created. Use the settings tab to adjust some extra behaviors and display settings of the module.');
87 }
88 }
89
90 /**
91 * Implementation of hook_theme().
92 */
93 function uc_node_checkout_theme() {
94 return array(
95 'uc_cart_click_to_edit' => array(
96 'arguments' => array(),
97 ),
98 'uc_node_cart_teaser' => array(
99 'arguments' => array('node' => NULL),
100 ),
101 'uc_node_checkout_node_attributes' => array(
102 'arguments' => array(),
103 ),
104 );
105 }
106
107 /**
108 * Implementation of hook_enable().
109 */
110 function uc_node_checkout_enable() {
111 // Get the weight of the cart module.
112 $weight = db_result(db_query("SELECT weight FROM {system} WHERE name = 'uc_cart' AND type = 'module'"));
113
114 // Set this module's weight to the cart module's + 100 to make sure its hooks
115 // are invoked in the right order.
116 db_query("UPDATE {system} SET weight = %d WHERE name = 'uc_node_checkout' AND type = 'module'", $weight + 100);
117 }
118
119 /**
120 * Implementation of hook_user().
121 */
122 function uc_node_checkout_user($op, &$edit, &$user, $category = NULL) {
123 switch ($op) {
124 case 'load':
125 // Fall through if this a new user load prior to checkout.
126 if (request_uri() != '/user/register?destination=cart/checkout' || $user->uid == 0) {
127 break;
128 }
129 case 'login':
130 $rebuild = FALSE;
131
132 // Update the author of node checkout nodes referenced in the cart.
133 foreach (uc_cart_get_contents($user->uid, 'rebuild') as $item) {
134 // If the item has a checkout node...
135 if ($node = $item->checkout_node) {
136 // Update the author and save the node.
137 $node->uid = $user->uid;
138 node_save($node);
139
140 // Make sure we rebuild the shopping cart with the updated info.
141 $rebuild = TRUE;
142 }
143 }
144
145 // Rebuild the cart contents so the checkout nodes are updated.
146 if ($rebuild) {
147 uc_cart_get_contents($user->uid, 'rebuild');
148 }
149 break;
150 }
151 }
152
153 /**
154 * Implementation of hook_form_alter().
155 */
156 function uc_node_checkout_form_alter(&$form, &$form_state, $form_id) {
157 global $user;
158
159 // Alters the product add to cart forms to redirect to the appropriate node
160 // add form if enabled.
161 if (strpos($form_id, 'add_to_cart_form') > 0 && variable_get('uc_node_checkout_add_to_cart_node_form', TRUE)) {
162 // Loop through the node checkout mappings.
163 foreach (uc_node_checkout_product_map() as $type => $value) {
164 // If the current product is mapped to a node type...
165 if ($form['nid']['#value'] == $value['nid']) {
166 // Store the node type in the form.
167 $form['node_type'] = array(
168 '#type' => 'value',
169 '#value' => $type,
170 );
171
172 // Change the submit handler to use the add to cart redirect handler.
173 $form['submit']['#submit'] = array('uc_node_checkout_add_to_cart_submit');
174 }
175 }
176 }
177
178 // Alter the cart view form to change node checkout product titles into edit
179 // links for the nodes they reference.
180 if ($form_id == 'uc_cart_view_form') {
181 $items = uc_cart_get_contents();
182 $i = 0;
183 foreach ($items as $item) {
184 if (isset($item->checkout_node)) {
185 $node = $item->checkout_node;
186
187 // Update the title if the based on user access.
188 if (variable_get('uc_node_checkout_cart_titles', TRUE)) {
189 if (node_access('update', $node)) {
190 $title = l($item->title, 'node/'. $node->nid .'/edit', array('query' => 'destination=cart'));
191
192 // Add the click to edit link to the title if necessary.
193 if (variable_get('uc_node_checkout_click_to_edit', TRUE)) {
194 $title .= ' '. theme('uc_cart_click_to_edit');
195 }
196 }
197 else {
198 $title = check_plain($item->title);
199 }
200
201 $form['items'][$i]['title']['#value'] = $title;
202 }
203
204 // Add the node cart teaser beneath the title if necessary.
205 if (variable_get('uc_node_cart_teaser', TRUE)) {
206 if (variable_get('uc_node_order_product_teaser_override', FALSE)) {
207 $list = array(
208 token_replace(variable_get('uc_node_order_product_attribute', 'ID'), 'node', $node) .': '
209 . token_replace(variable_get('uc_node_order_product_option', '[nid] - [title]'), 'node', $node),
210 );
211 $teaser = theme('item_list', $list, NULL, 'ul', array('class' => 'uc-node-cart-teaser'));
212 }
213 else {
214 $teaser = theme('uc_node_cart_teaser', $node);
215 }
216
217 $form['items'][$i]['description']['#value'] .= $teaser;
218 }
219
220 // Rebuild the description from the title and options.
221 $form['items'][$i]['desc']['#value'] = $form['items'][$i]['title']['#value'] . $form['items'][$i]['description']['#value'];
222 }
223 $i++;
224 }
225
226 // Add a submit handler to check for removed products.
227 $form['update']['#submit'][] = 'uc_node_checkout_cart_view_submit';
228 $form['#submit'][] = 'uc_node_checkout_cart_view_submit';
229 }
230
231 // Check stock levels on the checkout form and prevent checkout if specified.
232 if ($form_id == 'uc_cart_checkout_form' && module_exists('uc_stock')) {
233 // Loop through the items in the cart.
234 foreach (uc_cart_get_contents() as $item) {
235 // If an item is governed by node checkout...
236 if (isset($item->checkout_node)) {
237 // Get the stock level for each model.
238 $stock = uc_stock_level($item->model);
239
240 // If the product has no stock...
241 if ($stock !== FALSE && $stock <= 0) {
242 // And we've set this to prevent checkout for node checkout nodes...
243 if (variable_get('uc_node_stock_prevent_checkout', TRUE)) {
244 drupal_set_message(t('Due to stock levels, you may not complete the purchase of %title at this time. Please contact us for more information.', array('%title' => $item->title)), 'error');
245 drupal_goto('cart');
246 }
247 }
248 }
249 }
250 }
251
252 // Alter the node forms for UC Node Checkout governed node types.
253 foreach (uc_node_checkout_product_map() as $type => $value) {
254 if ($form_id == $type .'_node_form') {
255 // If enabled, add attributes form to the top of the node form if the node
256 // has not already been checked out.
257 if (module_exists('uc_attribute') && empty($form['#node']->uc_order_product_id)) {
258 // Load up any attribute elements for this node's form.
259 $attributes = _uc_attribute_alter_form(node_load($value['nid']));
260
261 // If we got a result...
262 if (!empty($attributes)) {
263 // Put them in a tidy fieldset.
264 $form['attributes'] = array(
265 '#type' => 'fieldset',
266 '#title' => t('Product specifications'),
267 '#description' => t('Please specify your preferences from these options. Some may affect the final price of your purchase.'),
268 '#weight' => -10,
269 '#tree' => TRUE,
270 );
271 $form['attributes'] += $attributes;
272
273 // Set defaults based on a GET variable.
274 if (!empty($_GET['attr'])) {
275 foreach (explode('_', $_GET['attr']) as $attr) {
276 list($aid, $oid) = explode('-', $attr);
277 $form['attributes'][$aid]['#default_value'] = $oid;
278 }
279 }
280
281 // Override with any defaults found in the cart products table.
282 if ($item = uc_node_checkout_load_cart_item($form['nid']['#value'])) {
283 // Set the attribute options to those in the database.
284 foreach ($item->data['attributes'] as $aid => $oid) {
285 $form['attributes'][$aid]['#default_value'] = $oid;
286 }
287 }
288 }
289 }
290
291 // For node add forms...
292 if (empty($form['nid']['#value'])) {
293 $product_nid = $_GET['product_nid'];
294
295 $form['ucnc_product_nid'] = array(
296 '#type' => 'hidden',
297 '#value' => $product_nid,
298 );
299
300 // If specified, redirect anonymous customers to login.
301 if (variable_get('uc_node_checkout_node_access', TRUE) && !$user->uid) {
302 drupal_set_message(t('You must login or create a user account to continue.'));
303 $_SESSION['node_checkout_redirect'] = 'node/add/'. $type;
304 drupal_goto('user');
305 }
306 else {
307 unset($_SESSION['node_checkout_redirect']);
308 }
309
310 // If stock control is turned on, prevent adding an out of stock node.
311 if (module_exists('uc_stock')) {
312 $node = node_load($value['nid']);
313 $stock = uc_stock_level($node->model);
314
315 if ($stock !== FALSE && $stock <= 0) {
316 if (variable_get('uc_node_stock_prevent_add', FALSE)) {
317 drupal_set_message(t('Due to stock levels, this product is currently not available.'));
318 drupal_goto(variable_get('uc_node_stock_prevent_add_redirect', 'cart'));
319 }
320 elseif (variable_get('uc_node_stock_prevent_checkout', TRUE) && empty($form['#post'])) {
321 drupal_set_message(t('Due to stock levels, you will not be able to complete the purchase of this product. You may still create it and add it to your shopping cart until stock is available. Please contact us for more information.'));
322 }
323 }
324 }
325
326 // If enabled, alter the submit button to say "Add to cart".
327 if (variable_get('uc_node_checkout_alter_node_submit_button', TRUE)) {
328 $form['buttons']['submit']['#value'] = t('Add to cart');
329 }
330 }
331
332 // Remove restricted fields for users without access.
333 $fields = variable_get('uc_node_checkout_'. $type .'_restrictions', array());
334
335 if (!empty($fields) && !user_access('edit any '. $type .' content')) {
336 foreach ($fields as $field) {
337 $form[$field]['#access'] = FALSE;
338 }
339 }
340
341 // Redirect non-administrators to the shopping cart after edits.
342 if (variable_get('uc_node_checkout_submit_redirect', TRUE) && !user_access('edit any '. $type .' content')) {
343 $form['#redirect'] = variable_get('uc_add_item_redirect', 'cart');
344 }
345 }
346 }
347
348 // Redirect shopper back to node add form once they've logged in.
349 if (variable_get('uc_node_checkout_node_access', TRUE) && ($form_id == 'user_login' || $form_id == 'user_edit' || $form_id == 'user_register')) {
350 if (isset($_SESSION['node_checkout_redirect'])) {
351 $form['#redirect'] = $_SESSION['node_checkout_redirect'];
352 }
353 }
354 }
355
356 // Submit handler for add to cart buttons on node checkout associated products.
357 function uc_node_checkout_add_to_cart_submit(&$form, &$form_state) {
358 // Display a message so the customer isn't totally confused.
359 drupal_set_message(t('This product requires some additional information.'));
360
361 $get = array('product_nid='. $form_state['values']['nid']);
362
363 // Pass the attributes selections in the URL.
364 $attr = array();
365
366 foreach ((array) $form_state['values']['attributes'] as $aid => $oid) {
367 $attr[] = $aid .'-'. $oid;
368 }
369
370 if (!empty($attr)) {
371 $get[] = 'attr='. implode('_', $attr);
372 }
373
374 // Redirect to the node add form.
375 $form['#redirect'] = array('node/add/'. $form_state['values']['node_type'], implode('&', $get));
376 }
377
378 // Submit handler for cart view form that deletes nodes when necessary.
379 function uc_node_checkout_cart_view_submit($form, &$form_state) {
380 if (variable_get('uc_node_checkout_delete_nodes', TRUE)) {
381 foreach ($form_state['values']['items'] as $key => $item) {
382 $data = unserialize($item['data']);
383
384 if ($item['remove'] && isset($data['node_checkout_nid'])) {
385 node_delete($data['node_checkout_nid']);
386 }
387 }
388 }
389 }
390
391 /**
392 * Implementation of hook_nodeapi().
393 */
394 function uc_node_checkout_nodeapi(&$node, $op, $arg3 = NULL, $arg4 = NULL) {
395 switch ($op) {
396 // Add the associated product to the cart when a node is created that should
397 // be checked out.
398 case 'insert':
399 // If this node type is mapped to a product...
400 if (uc_node_checkout_node_associated($node)) {
401 // Load up the corresponding product so we can use the default add to
402 // cart quantity.
403 $product = node_load($node->ucnc_product_nid);
404
405 // Make sure we add at least 1 to the cart.
406 if (empty($product->default_qty)) {
407 $product->default_qty = 1;
408 }
409
410 // Build the preliminary add to cart data array.
411 $data = array('nid' => $product->nid, 'node_checkout_nid' => intval($node->nid));
412
413 // Setup the extra values that will be passed around.
414 $values = array(
415 'nid' => $product->nid,
416 'qty' => $product->default_qty,
417 );
418
419 // Add any attribute values if they exist.
420 if (isset($node->attributes)) {
421 $values['attributes'] = $node->attributes;
422 }
423
424 // Pass these values to modules for alteration.
425 $extra = module_invoke_all('add_to_cart_data', $values);
426
427 // Add to the add to cart data array based on the hook response.
428 foreach ($extra as $key => $value) {
429 if (!isset($data[$key])) {
430 $data[$key] = $value;
431 }
432 }
433
434 // Add the product to the cart!
435 uc_cart_add_item($product->nid, $product->default_qty, $data, NULL, FALSE, FALSE);
436 }
437 break;
438
439 // When a customer is updating a product in the cart with attributes, save
440 // any changed attribute options.
441 case 'update':
442 // Only save attributes if this node has not been checked out.
443 if (empty($node->uc_order_product_id)) {
444 $data = db_result(db_query("SELECT data FROM {uc_cart_products} WHERE data LIKE '%%\"node_checkout_nid\";i:%d;%%'", $node->nid));
445
446 $data = unserialize($data);
447 $data['attributes'] = $node->attributes;
448
449 db_query("UPDATE {uc_cart_products} SET data = '%s' WHERE data LIKE '%%\"node_checkout_nid\";i:%d;%%'", serialize($data), $node->nid);
450 }
451 break;
452
453 // Load any saved attributes output from the DB for display on the node.
454 case 'load':
455 $node->uc_order_product_id = db_result(db_query("SELECT order_product_id FROM {uc_node_checkout_order_products} WHERE nid = %d", $node->nid));
456 break;
457
458 // When enabled, deletes nodes from the site when their creators remove the
459 // associated products from their cart.
460 case 'delete':
461 // Skip this whole block of code if we're not supposed to delete orphans.
462 if (variable_get('uc_node_checkout_delete_orphans', TRUE)) {
463 if (uc_node_checkout_node_associated($node)) {
464 db_query("DELETE FROM {uc_cart_products} WHERE data LIKE '%%\"node_checkout_nid\";i:%d;%%'", $node->nid);
465 if (db_affected_rows()) {
466 // Display a message here if necessary.
467 }
468 }
469 }
470 break;
471
472 // When enabled, redirects users to their cart when they try to view a node
473 // governed by UC Node Checkout that hasn't been checked out yet.
474 case 'view':
475 // Skip this whole block of code if this setting isn't enabled.
476 if (variable_get('uc_node_checkout_view_redirect', TRUE) && $arg4 === TRUE) {
477 if (uc_node_checkout_node_associated($node) &&
478 !user_access('edit any '. $node->type .' content') &&
479 uc_node_checkout_load_cart_item($node->nid)) {
480 drupal_goto(variable_get('uc_add_item_redirect', 'cart'));
481 }
482 }
483
484 // Add any existing attribute text to the node on a full pageview.
485 if ($arg4 === TRUE && !empty($node->uc_order_product_id)) {
486 drupal_add_css(drupal_get_path('module', 'uc_node_checkout') .'/uc_node_checkout.css');
487
488 // Load the product from the order.
489 $product = uc_node_checkout_load_order_product($node->uc_order_product_id);
490
491 // If it has attributes on it, set them to display.
492 if (is_array($product->data['attributes']) && count($product->data['attributes']) > 0) {
493 $node->content['uc_attribute_text'] = array(
494 '#data' => $product->data['attributes'],
495 '#value' => theme('uc_node_checkout_node_attributes', $product),
496 '#weight' => -10,
497 );
498 }
499 }
500
501 break;
502 }
503 }
504
505 /**
506 * Implementation of UC hook_cart_item().
507 */
508 function uc_node_checkout_cart_item($op, &$item) {
509 switch ($op) {
510 case 'load':
511 // Load the entire related node into the item array for use in display.
512 if (isset($item->data['node_checkout_nid']) && $node = node_load($item->data['node_checkout_nid'])) {
513 $item->checkout_node = $node;
514 }
515 break;
516 }
517 }
518
519 /**
520 * Implementation of UC hook_order().
521 */
522 function uc_node_checkout_order($op, &$arg1, $arg2) {
523 switch ($op) {
524 // Save node to order product associations upon order submission.
525 case 'submit':
526 // Loop through each product on the order.
527 foreach ($arg1->products as $product) {
528 // If it has a node checkout nid...
529 if (!empty($product->data['node_checkout_nid'])) {
530 // Save the association.
531 uc_node_checkout_save_product_association($product->order_product_id, $product->data['node_checkout_nid']);
532 }
533 }
534 break;
535
536 // Add the node checkout teaser to products on order view screens.
537 case 'load':
538 // Skip the whole block of the teaser is not enabled.
539 if (variable_get('uc_node_order_product_display', TRUE) && module_exists('uc_attribute')) {
540 $attribute = variable_get('uc_node_order_product_attribute', 'ID');
541 $option = variable_get('uc_node_order_product_option', '[nid] - [title]');
542
543 for ($i = 0, $j = count($arg1->products); $i < $j; $i++) {
544 if (isset($arg1->products[$i]->data['node_checkout_nid'])) {
545 $node = node_load($arg1->products[$i]->data['node_checkout_nid']);
546
547 if ($node) {
548 $arg1->products[$i]->data['attributes'][token_replace($attribute, 'node', $node)] = token_replace($option, 'node', $node);
549 }
550 }
551 }
552 }
553 break;
554 }
555 }
556
557 // Themes a click to edit link by node checkout products in a customer's cart.
558 function theme_uc_cart_click_to_edit() {
559 return '<span class="node-checkout-edit">'. t('(click to edit)') .'</span>';
560 }
561
562 // Themes a cart teaser for a node checkout product in the shopping cart.
563 function theme_uc_node_cart_teaser($node) {
564 $output = '<div class="uc-node-cart-teaser" id="uc-node-cart-teaser-'
565 . $node->nid .'">'. check_plain($node->title) .'</div>';
566
567 return $output;
568 }
569
570 /**
571 * Themes the attributes selected for a product when the node was purchased on
572 * the node view page.
573 *
574 * @param $product
575 * The order product array for the node.
576 * @return
577 * An HTML string representing the attribute selections from the purchase of
578 * the node.
579 */
580 function theme_uc_node_checkout_node_attributes($product) {
581 foreach ($product->data['attributes'] as $attribute => $option) {
582 $option_rows[] = t('@attribute: @option', array('@attribute' => $attribute, '@option' => $option));
583 }
584
585 $output = '<div class="ucnc-attributes"><div class="ucnc-attributes-label">'. t('Original product attributes:')
586 .'</div>'. theme('item_list', $option_rows) .'</div>';
587
588 return $output;
589 }
590
591 /**
592 * Returns an array mapping node types to their associated products.
593 *
594 * @param $type
595 * Optional. Specify a node type and only return that type's product nid.
596 * @return
597 * Either an array containing all node type to product nid associations or a
598 * single nid for the specified node type.
599 */
600 function uc_node_checkout_product_map($type = '') {
601 static $nc_map = array();
602
603 // The only limitation here is that the static caching will have no effect
604 // when this module is enabled but no associations have been made.
605 if (empty($nc_map)) {
606 $result = db_query("SELECT type, product_nid, node_view FROM {uc_node_checkout_types}");
607
608 while ($nc_type = db_fetch_array($result)) {
609 $nc_map[$nc_type['type']] = array('nid' => $nc_type['product_nid'], 'view' => $nc_type['node_view']);
610 }
611 }
612
613 // If we passed in a node type, return that node type's product nid.
614 if (!empty($type)) {
615 return $nc_map[$type];
616 }
617
618 return $nc_map;
619 }
620
621 /**
622 * Determines whether or not a given node has any product associations.
623 *
624 * @param $node
625 * The node object to check.
626 * @return
627 * TRUE or FALSE indicating the given node is associated to a product.
628 */
629 function uc_node_checkout_node_associated($node) {
630 // Return TRUE if a product node has been associated to this node type.
631 if ($nc_map = uc_node_checkout_product_map($node->type)) {
632 if ($nc_map['nid'] || $nc_map['view']) {
633 return TRUE;
634 }
635 }
636
637 return FALSE;
638 }
639
640 // Saves a node to order product association when a node checkout product is
641 // purchased.
642 function uc_node_checkout_save_product_association($order_product_id, $nid) {
643 // First attempt to update any existing associations.
644 db_query("UPDATE {uc_node_checkout_order_products} SET order_product_id = %d WHERE nid = %d", $order_product_id, $nid);
645
646 // If none were found...
647 if (!db_affected_rows()) {
648 // Insert a new association.
649 db_query("INSERT INTO {uc_node_checkout_order_products} (nid, order_product_id) VALUES (%d, %d)", $nid, $order_product_id);
650 }
651 }
652
653 /**
654 * Loads the cart item data corresponding to a node for an unchecked out node
655 * checkout governed node.
656 *
657 * Note that this function does not do a full cart item load, meaning hooks
658 * aren't invoked and information is not filled in from the corresponding
659 * product node. This is due to a current limitation in the core cart API.
660 *
661 * @param $nid
662 * The nid of the node to look for in the shopping cart table.
663 * @return
664 * An object representing the cart item or FALSE if none was found.
665 */
666 function uc_node_checkout_load_cart_item($nid) {
667 static $items = array();
668
669 // If the item hasn't been searched before...
670 if (!isset($items[$nid])) {
671 // Load the data from the database.
672 $result = db_query("SELECT * FROM {uc_cart_products} WHERE data LIKE '%%\"node_checkout_nid\";i:%d;%%'", $nid);
673
674 // If a matching product was found in the DB for this node...
675 if ($item = db_fetch_object($result)) {
676 $item->data = unserialize($item->data);
677 $items[$nid] = $item;
678 }
679 else {
680 $items[$nid] = FALSE;
681 }
682 }
683
684 return $items[$nid];
685 }
686
687 /**
688 * Loads the order product data corresponding to a node for a node checkout
689 * governed node.
690 *
691 * @param $order_product_id
692 * The order product ID of the product to load from the database.
693 * @return
694 * An object representing the product or FALSE if none was found.
695 */
696 function uc_node_checkout_load_order_product($order_product_id) {
697 static $products = array();
698
699 // If the product hasn't been searched before...
700 if (!isset($items[$nid])) {
701 // Load the data from the database.
702 $result = db_query("SELECT * FROM {uc_order_products} WHERE order_product_id = %d", $order_product_id);
703
704 // If a matching product was found in the DB for this node...
705 if ($product = db_fetch_object($result)) {
706 $product->data = unserialize($product->data);
707 $products[$order_product_id] = $product;
708 }
709 else {
710 $products[$order_product_id] = FALSE;
711 }
712 }
713
714 return $products[$order_product_id];
715 }
716
717 // Allow the customer to select which associated product to use for the node.
718 function uc_node_checkout_product_selection_form() {
719
720 }
721

  ViewVC Help
Powered by ViewVC 1.1.2