Parent Directory
|
Revision Log
|
Revision Graph
Begin the Ubercart 6.x-2.x branch.
| 1 | <?php |
| 2 | // $Id$ |
| 3 | |
| 4 | /** |
| 5 | * @file |
| 6 | * Handles all things concerning Ubercart's shopping cart. |
| 7 | * |
| 8 | * The Ubercart cart system functions much like the e-commerce cart at its base |
| 9 | * level... in fact, most carts do. This module handles the cart display, |
| 10 | * adding items to a cart, and checking out. The module enables the cart, |
| 11 | * products, and checkout to be extensible. |
| 12 | */ |
| 13 | |
| 14 | require_once('uc_cart_checkout_pane.inc'); |
| 15 | require_once('uc_cart.ca.inc'); |
| 16 | |
| 17 | /******************************************************************************* |
| 18 | * Hook Functions (Drupal) |
| 19 | ******************************************************************************/ |
| 20 | |
| 21 | /** |
| 22 | * Implementation of hook_menu(). |
| 23 | */ |
| 24 | function uc_cart_menu() { |
| 25 | $items = array(); |
| 26 | |
| 27 | $items['admin/store/settings/cart'] = array( |
| 28 | 'title' => 'Cart settings', |
| 29 | 'description' => 'Configure the cart settings.', |
| 30 | 'page callback' => 'uc_cart_cart_settings_overview', |
| 31 | 'access arguments' => array('administer store'), |
| 32 | ); |
| 33 | $items['admin/store/settings/cart/overview'] = array( |
| 34 | 'title' => 'Overview', |
| 35 | 'description' => 'View the cart settings.', |
| 36 | 'access arguments' => array('administer store'), |
| 37 | 'type' => MENU_DEFAULT_LOCAL_TASK, |
| 38 | 'weight' => -10, |
| 39 | ); |
| 40 | $items['admin/store/settings/cart/edit'] = array( |
| 41 | 'title' => 'Edit', |
| 42 | 'description' => 'Edit the cart settings.', |
| 43 | 'page callback' => 'drupal_get_form', |
| 44 | 'page arguments' => array('uc_cart_cart_settings_form'), |
| 45 | 'access arguments' => array('administer store'), |
| 46 | 'type' => MENU_LOCAL_TASK, |
| 47 | 'weight' => -5, |
| 48 | ); |
| 49 | $items['admin/store/settings/cart/edit/basic'] = array( |
| 50 | 'title' => 'Cart settings', |
| 51 | 'description' => 'Edit the basic cart settings.', |
| 52 | 'access arguments' => array('administer store'), |
| 53 | 'type' => MENU_DEFAULT_LOCAL_TASK, |
| 54 | 'weight' => -10, |
| 55 | ); |
| 56 | $items['admin/store/settings/cart/edit/panes'] = array( |
| 57 | 'title' => 'Cart panes', |
| 58 | 'description' => 'Edit the pane settings for the cart view page.', |
| 59 | 'page callback' => 'drupal_get_form', |
| 60 | 'page arguments' => array('uc_cart_cart_panes_form'), |
| 61 | 'access arguments' => array('administer store'), |
| 62 | 'type' => MENU_LOCAL_TASK, |
| 63 | 'weight' => -5, |
| 64 | ); |
| 65 | $items['admin/store/settings/cart/edit/block'] = array( |
| 66 | 'title' => 'Cart block', |
| 67 | 'description' => t('Edit the settings for the shopping cart block.'), |
| 68 | 'page callback' => 'uc_cart_block_edit_info', |
| 69 | 'access arguments' => array('administer store'), |
| 70 | 'type' => MENU_LOCAL_TASK, |
| 71 | 'weight' => 0, |
| 72 | ); |
| 73 | |
| 74 | $items['admin/store/settings/checkout'] = array( |
| 75 | 'title' => 'Checkout settings', |
| 76 | 'description' => 'Configure the checkout settings.', |
| 77 | 'page callback' => 'uc_cart_checkout_settings_overview', |
| 78 | 'access arguments' => array('administer store'), |
| 79 | ); |
| 80 | $items['admin/store/settings/checkout/overview'] = array( |
| 81 | 'title' => 'Overview', |
| 82 | 'description' => 'View the checkout settings.', |
| 83 | 'access arguments' => array('administer store'), |
| 84 | 'type' => MENU_DEFAULT_LOCAL_TASK, |
| 85 | 'weight' => -10, |
| 86 | ); |
| 87 | $items['admin/store/settings/checkout/edit'] = array( |
| 88 | 'title' => 'Edit', |
| 89 | 'description' => 'Edit the cart settings.', |
| 90 | 'page callback' => 'drupal_get_form', |
| 91 | 'page arguments' => array('uc_cart_checkout_settings_form'), |
| 92 | 'access arguments' => array('administer store'), |
| 93 | 'type' => MENU_LOCAL_TASK, |
| 94 | 'weight' => -5, |
| 95 | ); |
| 96 | $items['admin/store/settings/checkout/edit/basic'] = array( |
| 97 | 'title' => 'Checkout settings', |
| 98 | 'description' => 'Edit the basic checkout settings.', |
| 99 | 'access arguments' => array('administer store'), |
| 100 | 'type' => MENU_DEFAULT_LOCAL_TASK, |
| 101 | 'weight' => -10, |
| 102 | ); |
| 103 | $items['admin/store/settings/checkout/edit/panes'] = array( |
| 104 | 'title' => 'Checkout panes', |
| 105 | 'description' => 'Edit the pane settings for the checkout page.', |
| 106 | 'page callback' => 'drupal_get_form', |
| 107 | 'page arguments' => array('uc_cart_checkout_panes_form'), |
| 108 | 'access arguments' => array('administer store'), |
| 109 | 'type' => MENU_LOCAL_TASK, |
| 110 | 'weight' => -5, |
| 111 | ); |
| 112 | $items['admin/store/settings/checkout/edit/messages'] = array( |
| 113 | 'title' => 'Checkout messages', |
| 114 | 'description' => 'Edit the messages for the checkout completion page.', |
| 115 | 'page callback' => 'drupal_get_form', |
| 116 | 'page arguments' => array('uc_cart_checkout_messages_form'), |
| 117 | 'access arguments' => array('administer store'), |
| 118 | 'type' => MENU_LOCAL_TASK, |
| 119 | 'weight' => 0, |
| 120 | ); |
| 121 | $items['admin/store/settings/checkout/edit/fields'] = array( |
| 122 | 'title' => 'Address fields', |
| 123 | 'description' => 'Edit the address field settings.', |
| 124 | 'page callback' => 'drupal_get_form', |
| 125 | 'page arguments' => array('uc_store_address_fields_form'), |
| 126 | 'access arguments' => array('administer store'), |
| 127 | 'type' => MENU_LOCAL_TASK, |
| 128 | 'weight' => 5, |
| 129 | ); |
| 130 | |
| 131 | $items['cart'] = array( |
| 132 | 'title' => 'Shopping cart', |
| 133 | 'description' => 'View/modify the contents of your shopping cart or proceed to checkout.', |
| 134 | 'page callback' => 'uc_cart_view', |
| 135 | 'access arguments' => array('access content'), |
| 136 | 'type' => MENU_CALLBACK, |
| 137 | ); |
| 138 | $items['cart/checkout'] = array( |
| 139 | 'title' => 'Checkout', |
| 140 | 'description' => 'Purchase the items in your shopping cart.', |
| 141 | 'page callback' => 'uc_cart_checkout', |
| 142 | 'access arguments' => array('access content'), |
| 143 | 'type' => MENU_CALLBACK, |
| 144 | ); |
| 145 | $items['cart/checkout/review'] = array( |
| 146 | 'title' => 'Review order', |
| 147 | 'description' => 'Review an order before final submission.', |
| 148 | 'page callback' => 'uc_cart_checkout_review', |
| 149 | 'access arguments' => array('access content'), |
| 150 | 'type' => MENU_CALLBACK, |
| 151 | ); |
| 152 | $items['cart/checkout/complete'] = array( |
| 153 | 'title' => 'Order complete', |
| 154 | 'description' => 'Display information upon completion of an order.', |
| 155 | 'page callback' => 'uc_cart_checkout_complete', |
| 156 | 'access arguments' => array('access content'), |
| 157 | 'type' => MENU_CALLBACK, |
| 158 | ); |
| 159 | |
| 160 | return $items; |
| 161 | } |
| 162 | |
| 163 | function uc_cart_enable() { |
| 164 | if (module_exists('imagecache')) { |
| 165 | $result = db_query("SELECT presetid FROM {imagecache_preset} WHERE presetname = 'cart'"); |
| 166 | if (!db_fetch_object($result)) { |
| 167 | db_query("INSERT INTO {imagecache_preset} (presetname) VALUES ('cart')"); |
| 168 | $id = db_last_insert_id('imagecache_preset', 'presetid'); |
| 169 | db_query("INSERT INTO {imagecache_action} (presetid, weight, data) VALUES (%d, 0, '%s')", $id, 'a:4:{s:8:"function";s:5:"scale";s:3:"fit";s:6:"inside";s:5:"width";s:2:"50";s:6:"height";s:2:"50";}'); |
| 170 | cache_clear_all('imagecache:presets', 'cache'); |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Implementation of hook_theme(). |
| 177 | */ |
| 178 | function uc_cart_theme() { |
| 179 | return array( |
| 180 | 'uc_cart_block_title' => array( |
| 181 | 'arguments' => array('cart_image' => NULL, 'arrow_up_image' => NULL), |
| 182 | ), |
| 183 | 'uc_cart_block_content' => array( |
| 184 | 'arguments' => array(), |
| 185 | ), |
| 186 | 'uc_empty_cart' => array( |
| 187 | 'arguments' => array(), |
| 188 | ), |
| 189 | 'uc_cart_view_form' => array( |
| 190 | 'arguments' => array('items' => NULL), |
| 191 | ), |
| 192 | 'address_pane' => array( |
| 193 | 'arguments' => array('form' => NULL), |
| 194 | ), |
| 195 | 'cart_review_table' => array( |
| 196 | 'arguments' => array('show_subtotal' => TRUE), |
| 197 | ), |
| 198 | 'uc_cart_checkout_form' => array( |
| 199 | 'arguments' => array('form' => NULL), |
| 200 | ), |
| 201 | 'uc_cart_checkout_review' => array( |
| 202 | 'arguments' => array('help' => NULL, 'panes' => NULL, 'form' => NULL), |
| 203 | ), |
| 204 | ); |
| 205 | } |
| 206 | |
| 207 | /** |
| 208 | * Implementation of hook_cron(). |
| 209 | */ |
| 210 | function uc_cart_cron() { |
| 211 | // Empty anonymous carts. |
| 212 | $time = strtotime(variable_get('uc_cart_anon_duration', '4') .' '. variable_get('uc_cart_anon_unit', 'hours') .' ago'); |
| 213 | db_query("DELETE FROM {uc_cart_products} WHERE changed <= %d AND CHAR_LENGTH(cart_id) > 8", $time); |
| 214 | |
| 215 | // Empty authenticated carts. |
| 216 | $time = strtotime(variable_get('uc_cart_auth_duration', '1') .' '. variable_get('uc_cart_auth_unit', 'years') .' ago'); |
| 217 | db_query("DELETE FROM {uc_cart_products} WHERE changed <= %d AND CHAR_LENGTH(cart_id) <= 8", $time); |
| 218 | } |
| 219 | |
| 220 | /** |
| 221 | * Implementation of hook_block(). |
| 222 | */ |
| 223 | function uc_cart_block($op = 'list', $delta = 0, $edit = array()) { |
| 224 | if ($op == 'list') { |
| 225 | $blocks[0]['info'] = t('Shopping cart'); |
| 226 | $blocks[0]['cache'] = BLOCK_NO_CACHE; |
| 227 | return $blocks; |
| 228 | } |
| 229 | elseif ($op == 'view') { |
| 230 | $uc_cart_path = base_path() . drupal_get_path('module', 'uc_cart'); |
| 231 | |
| 232 | if (variable_get('uc_cart_block_collapsible', TRUE)) { |
| 233 | $val = variable_get('uc_cart_block_collapsed', TRUE) ? 'true' : 'false'; |
| 234 | uc_add_js('var collapsed_block = '. $val .';', 'inline'); |
| 235 | uc_add_js("var uc_cart_path = '". $uc_cart_path ."';", 'inline'); |
| 236 | uc_add_js(drupal_get_path('module', 'uc_cart') .'/uc_cart_block.js'); |
| 237 | } |
| 238 | |
| 239 | drupal_add_css(drupal_get_path('module', 'uc_cart') .'/uc_cart_block.css'); |
| 240 | |
| 241 | $item_count = count(uc_cart_get_contents()); |
| 242 | if ($item_count == 0 && variable_get('uc_cart_block_empty_hide', FALSE)) { |
| 243 | return; |
| 244 | } |
| 245 | |
| 246 | $cart_image = $uc_cart_path; |
| 247 | $cart_image .= ($item_count) ? '/images/cart_full.gif' : '/images/cart_empty.gif'; |
| 248 | $arrow_down_image = $uc_cart_path .'/images/bullet-arrow-down.gif'; |
| 249 | $arrow_up_image = $uc_cart_path .'/images/bullet-arrow-up.gif'; |
| 250 | |
| 251 | $block['subject'] = theme('uc_cart_block_title', $cart_image, $arrow_up_image); |
| 252 | $block['content'] = theme('uc_cart_block_content'); |
| 253 | |
| 254 | return $block; |
| 255 | } |
| 256 | elseif ($op == 'configure') { |
| 257 | $form['uc_cart_block_empty_hide'] = array( |
| 258 | '#type' => 'checkbox', |
| 259 | '#title' => t('Hide block if cart is empty.'), |
| 260 | '#default_value' => variable_get('uc_cart_block_empty_hide', FALSE), |
| 261 | ); |
| 262 | $form['uc_cart_block_image'] = array( |
| 263 | '#type' => 'checkbox', |
| 264 | '#title' => t('Display the shopping cart icon in the block title.'), |
| 265 | '#default_value' => variable_get('uc_cart_block_image', TRUE), |
| 266 | ); |
| 267 | $form['uc_cart_block_title'] = array( |
| 268 | '#type' => 'textfield', |
| 269 | '#title' => t('Cart name'), |
| 270 | '#description' => t('This name will be displayed when using the default block title.<br />Leaving this blank defaults to the translatable name "Shopping Cart."'), |
| 271 | '#default_value' => variable_get('uc_cart_block_title', ''), |
| 272 | ); |
| 273 | $form['uc_cart_block_collapsible'] = array( |
| 274 | '#type' => 'checkbox', |
| 275 | '#title' => t('Make the shopping cart block collapsible by clicking the name or arrow.'), |
| 276 | '#default_value' => variable_get('uc_cart_block_collapsible', TRUE), |
| 277 | ); |
| 278 | $form['uc_cart_block_collapsed'] = array( |
| 279 | '#type' => 'checkbox', |
| 280 | '#title' => t('Display the shopping cart block collapsed by default.'), |
| 281 | '#default_value' => variable_get('uc_cart_block_collapsed', TRUE), |
| 282 | ); |
| 283 | $form['uc_cart_show_help_text'] = array( |
| 284 | '#type' => 'checkbox', |
| 285 | '#title' => t('Display small help text in the shopping cart block.'), |
| 286 | '#default_value' => variable_get('uc_cart_show_help_text', FALSE), |
| 287 | ); |
| 288 | $form['uc_cart_help_text'] = array( |
| 289 | '#type' => 'textfield', |
| 290 | '#title' => t('Cart help text'), |
| 291 | '#description' => t('Displayed if the above box is checked.'), |
| 292 | '#size' => 32, |
| 293 | '#default_value' => variable_get('uc_cart_help_text', t('Click title to display cart contents.')), |
| 294 | ); |
| 295 | |
| 296 | return $form; |
| 297 | } |
| 298 | elseif ($op == 'save' && isset($edit['uc_cart_block_empty_hide'])) { |
| 299 | variable_set('uc_cart_block_empty_hide', $edit['uc_cart_block_empty_hide']); |
| 300 | variable_set('uc_cart_block_image', $edit['uc_cart_block_image']); |
| 301 | variable_set('uc_cart_block_title', $edit['uc_cart_block_title']); |
| 302 | variable_set('uc_cart_block_collapsible', $edit['uc_cart_block_collapsible']); |
| 303 | variable_set('uc_cart_block_collapsed', $edit['uc_cart_block_collapsed']); |
| 304 | variable_set('uc_cart_show_help_text', $edit['uc_cart_show_help_text']); |
| 305 | variable_set('uc_cart_help_text', check_plain($edit['uc_cart_help_text'])); |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | /** |
| 310 | * Theme the shopping cart block title |
| 311 | */ |
| 312 | function theme_uc_cart_block_title($cart_image, $arrow_up_image) { |
| 313 | if (variable_get('uc_cart_block_image', TRUE)) { |
| 314 | $output = l('<img src="'. $cart_image .'" id="block-cart-title-image" alt="" />', 'cart', array('html' => TRUE)); |
| 315 | } |
| 316 | |
| 317 | $title = trim(variable_get('uc_cart_block_title', '')); |
| 318 | if (empty($title)) { |
| 319 | $title = t('Shopping cart'); |
| 320 | } |
| 321 | |
| 322 | if (variable_get('uc_cart_block_collapsible', TRUE)) { |
| 323 | $class = ' cart-block-toggle'; |
| 324 | } |
| 325 | |
| 326 | $output .= '<span class="block-cart-title-bar'. $class .'" id="block-cart-title-bar-text">' |
| 327 | .'<span id="block-cart-title">'. check_plain($title) .'</span></span>'; |
| 328 | |
| 329 | if (variable_get('uc_cart_block_collapsible', TRUE)) { |
| 330 | $output .= '<span class="block-cart-title-bar cart-block-toggle" id="block-cart-title-bar-arrow">' |
| 331 | .'<img id="block-cart-title-arrow" src="'. $arrow_up_image .'" alt="[]" title="'. t('Expand cart block.') .'" /></span>'; |
| 332 | } |
| 333 | |
| 334 | return $output; |
| 335 | } |
| 336 | |
| 337 | /** |
| 338 | * Theme the shopping cart block content. |
| 339 | */ |
| 340 | function theme_uc_cart_block_content() { |
| 341 | global $user; |
| 342 | |
| 343 | // Disabled until we figure out if this is actually screwing up caching. -RS |
| 344 | //if (!$user->uid && variable_get('cache', 0) !== 0) { |
| 345 | // return t('<a href="!url">View</a> your shopping cart.', array('!url' => url('cart'))); |
| 346 | //} |
| 347 | |
| 348 | if (variable_get('uc_cart_show_help_text', FALSE)) { |
| 349 | $output = '<span class="cart-help-text">' |
| 350 | . variable_get('uc_cart_help_text', t('Click title to display cart contents.')) |
| 351 | .'</span>'; |
| 352 | } |
| 353 | |
| 354 | $output .= '<div id="block-cart-contents">'; |
| 355 | |
| 356 | $items = uc_cart_get_contents(); |
| 357 | |
| 358 | $item_count = 0; |
| 359 | if (!empty($items)) { |
| 360 | $output .= '<table class="cart-block-table">' |
| 361 | .'<tbody class="cart-block-tbody">'; |
| 362 | foreach ($items as $item) { |
| 363 | $display_item = module_invoke($item->module, 'cart_display', $item); |
| 364 | if (!empty($display_item)) { |
| 365 | $output .= '<tr class="cart-block-item"><td class="cart-block-item-qty">'. $display_item['qty']['#default_value'] .'x</td>' |
| 366 | .'<td class="cart-block-item-title">'. $display_item['title']['#value'] .'</td>' |
| 367 | .'<td class="cart-block-item-price">'. uc_currency_format($display_item['#total']) .'</td></tr>'; |
| 368 | if ($display_item['options']['#value']) { |
| 369 | $output .= '<tr><td colspan="3">'. $display_item['options']['#value'] .'</td></tr>'; |
| 370 | } |
| 371 | } |
| 372 | $total += ($item->price) * $item->qty; |
| 373 | $item_count += $item->qty; |
| 374 | } |
| 375 | |
| 376 | $output .= '</tbody></table>'; |
| 377 | } |
| 378 | else { |
| 379 | $output .= '<p>'. t('There are no products in your shopping cart.') .'</p>'; |
| 380 | } |
| 381 | |
| 382 | $output .= '</div>'; |
| 383 | |
| 384 | $item_text = format_plural($item_count, '@count Item', '@count Items'); |
| 385 | $view = '('. l(t('View cart'), 'cart', array('attributes' => array('rel' => 'nofollow'))) .')'; |
| 386 | if (variable_get('uc_checkout_enabled', TRUE)) { |
| 387 | $checkout = ' ('. l(t('Checkout'), 'cart/checkout', array('attributes' => array('rel' => 'nofollow'))) .')'; |
| 388 | } |
| 389 | $output .= '<table class="cart-block-summary-table"><tbody class="cart-block-summary-tbody">' |
| 390 | .'<tr class="cart-block-summary-tr"><td class="cart-block-summary-items">' |
| 391 | . $item_text .'</td><td class="cart-block-summary-total">' |
| 392 | .'<strong>'. t('Total:') .'</strong> '. uc_currency_format($total) .'</td></tr>'; |
| 393 | if ($item_count > 0) { |
| 394 | $output .= '<tr><td colspan="2" class="cart-block-summary-checkout">'. $view . $checkout .'</td></tr>'; |
| 395 | } |
| 396 | $output .= '</tbody></table>'; |
| 397 | |
| 398 | return $output; |
| 399 | } |
| 400 | |
| 401 | /** |
| 402 | * Implementation of hook_exit(). |
| 403 | * |
| 404 | * Code from CacheExclude - http://drupal.org/project/cacheexclude |
| 405 | */ |
| 406 | function uc_cart_exit() { |
| 407 | global $base_root; |
| 408 | |
| 409 | $pages = array('cart', 'cart/checkout', 'cart/checkout/review', 'cart/checkout/complete'); |
| 410 | $this_page = request_uri(); |
| 411 | foreach ($pages as $page) { |
| 412 | if ($page && strstr($this_page, $page) !== FALSE) { |
| 413 | cache_clear_all($base_root . $this_page, 'cache_page'); |
| 414 | return; |
| 415 | } |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | function uc_cart_nodeapi(&$node, $op, $arg3, $arg4) { |
| 420 | if (in_array($node->type, module_invoke_all('product_types'))) { |
| 421 | switch ($op) { |
| 422 | case 'delete': |
| 423 | db_query("DELETE FROM {uc_cart_products} WHERE nid = %d", $node->nid); |
| 424 | break; |
| 425 | } |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | /** |
| 430 | * Implementation of hook_user(). |
| 431 | */ |
| 432 | function uc_cart_user($op, &$edit, &$user, $category = NULL) { |
| 433 | switch ($op) { |
| 434 | case 'load': |
| 435 | // Fall through if this a new user load prior to checkout. |
| 436 | if (request_uri() != '/user/register?destination=cart/checkout' || $user->uid == 0) { |
| 437 | break; |
| 438 | } |
| 439 | case 'login': |
| 440 | // Add items from an anonymous cart to a user's permanent cart on login. |
| 441 | |
| 442 | // Get the current contents of the cart. |
| 443 | $items = uc_cart_get_contents($user->uid); |
| 444 | |
| 445 | // Update the cart so the ID is switched from the session to user ID. |
| 446 | db_query("UPDATE {uc_cart_products} SET cart_id = %d WHERE cart_id = '%s'", $user->uid, session_id()); |
| 447 | |
| 448 | // If there were items before the update, we need to re-add them all to |
| 449 | // take care of item consolidation. |
| 450 | if (count($items) > 0) { |
| 451 | // Store again what items these are. |
| 452 | $items = uc_cart_get_contents($user->uid, 'rebuild'); |
| 453 | |
| 454 | // Remove from the table all the items in the cart. |
| 455 | // Should be a function call instead of a single query. -RS |
| 456 | db_query("DELETE FROM {uc_cart_products} WHERE cart_id = %d", $user->uid); |
| 457 | |
| 458 | // Reset the cart item cache. |
| 459 | uc_cart_get_contents($user->uid, 'rebuild'); |
| 460 | |
| 461 | // Loop through what the items should be and re-add them to the cart. |
| 462 | foreach ($items as $key => $item) { |
| 463 | uc_cart_add_item($item->nid, $item->qty, $item->data, $user->uid, FALSE, FALSE); |
| 464 | } |
| 465 | } |
| 466 | break; |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | /** |
| 471 | * Implementation of hook_form_alter(). |
| 472 | */ |
| 473 | function uc_cart_form_alter(&$form, $form_state, $form_id) { |
| 474 | // Redirect shopper back to checkout page if they go to login from there. |
| 475 | if ($form_id == 'user_login' || $form_id == 'user_edit' || $form_id == 'user_register') { |
| 476 | if ($_SESSION['checkout-redirect'] == TRUE) { |
| 477 | $form['#action'] = url($_GET['q'], array('query' => "destination=cart/checkout")); |
| 478 | return; |
| 479 | } |
| 480 | |
| 481 | // Grab the referer if possible. |
| 482 | $referer = referer_uri(); |
| 483 | |
| 484 | // Compare it for checkout page URLs. |
| 485 | if (substr($referer, -13, 13) == 'cart/checkout') { |
| 486 | $form['#action'] = url($_GET['q'], "destination=cart/checkout"); |
| 487 | } |
| 488 | elseif (substr($referer, -22, 22) == 'cart/checkout/complete') { |
| 489 | $form['#action'] = url($_GET['q'], "destination=user"); |
| 490 | } |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | |
| 495 | /******************************************************************************* |
| 496 | * Hook Functions (TAPIr) |
| 497 | ******************************************************************************/ |
| 498 | |
| 499 | /** |
| 500 | * Implementation of hook_table_settings(). |
| 501 | */ |
| 502 | function uc_cart_table_settings() { |
| 503 | $tables[] = array( |
| 504 | 'id' => 'uc_cart_view_table', |
| 505 | 'description' => t("Display information on products in a customer's cart."), |
| 506 | 'path' => 'admin/store/settings/tables', |
| 507 | 'access' => 'administer store', |
| 508 | 'preview' => FALSE, |
| 509 | ); |
| 510 | |
| 511 | return $tables; |
| 512 | } |
| 513 | |
| 514 | |
| 515 | /******************************************************************************* |
| 516 | * Hook Functions (Ubercart) |
| 517 | ******************************************************************************/ |
| 518 | |
| 519 | /** |
| 520 | * Implementation of hook_uc_message(). |
| 521 | */ |
| 522 | function uc_cart_uc_message() { |
| 523 | global $user; |
| 524 | |
| 525 | $messages['checkout_instructions'] = ''; |
| 526 | $messages['review_instructions'] = t('Your order is not complete. Please review the details of your order and click !submit if all the information is correct. You may use the Back button to make changes to your order if necessary.', array('!submit' => variable_get('uc_checkout_submit_button', t('Submit order')))); |
| 527 | $messages['completion_message'] = t('Your order is complete! Your order number is [order-id].'); |
| 528 | $messages['completion_logged_in'] = t('Thank you for shopping at [store-name]. While logged in, you may continue shopping or <a href="!url">click here</a> to view your current order status and order history.', array('!url' => url('user/'. $user->uid .'/orders', array('absolute' => TRUE)))); |
| 529 | $messages['completion_existing_user'] = t('Thank you for shopping at [store-name]. Your current order has been attached to the account we found matching your e-mail address.') .'<p>'. t('<a href="!url">Click here</a> to login and view your current order status and order history. Remember to login when you make your next purchase for a faster checkout experience!', array('!url' => url('user', array('absolute' => TRUE)))); |
| 530 | $messages['completion_new_user'] = t('Thank you for shopping at [store-name]. A new account has been created for you here that you may use to view your current order status.') . t('<p><a href="!url">Click here</a> to login to your new account using the following information:', array('!url' => url('user', array('absolute' => TRUE)))) . t('<p><strong>Username:</strong> !new_username<br /><strong>Password:</strong> !new_password'); |
| 531 | $messages['continue_shopping'] = l(t('Click to return to the front page.'), '<front>', array('absolute' => TRUE)); |
| 532 | |
| 533 | return $messages; |
| 534 | } |
| 535 | |
| 536 | /** |
| 537 | * Implementation of hook_cart_pane(). |
| 538 | */ |
| 539 | function uc_cart_cart_pane($items) { |
| 540 | $panes[] = array( |
| 541 | 'id' => 'cart_form', |
| 542 | 'title' => t('Default cart form'), |
| 543 | 'enabled' => TRUE, |
| 544 | 'weight' => 0, |
| 545 | 'body' => !is_null($items) ? '<div id="cart-form-pane">'. drupal_get_form('uc_cart_view_form', $items) .'</div>': '', |
| 546 | ); |
| 547 | |
| 548 | return $panes; |
| 549 | } |
| 550 | |
| 551 | /** |
| 552 | * Implementation of hook_checkout_pane(). |
| 553 | */ |
| 554 | function uc_cart_checkout_pane() { |
| 555 | $panes[] = array( |
| 556 | 'id' => 'cart', |
| 557 | 'callback' => 'uc_checkout_pane_cart', |
| 558 | 'title' => t('Cart contents'), |
| 559 | 'desc' => t("Display the contents of a customer's shopping cart."), |
| 560 | 'weight' => 1, |
| 561 | 'process' => FALSE, |
| 562 | 'collapsible' => FALSE, |
| 563 | ); |
| 564 | $panes[] = array( |
| 565 | 'id' => 'customer', |
| 566 | 'callback' => 'uc_checkout_pane_customer', |
| 567 | 'title' => t('Customer information'), |
| 568 | 'desc' => t('Get the necessary information to create a customer on the site.'), |
| 569 | 'weight' => 2, |
| 570 | ); |
| 571 | $panes[] = array( |
| 572 | 'id' => 'delivery', |
| 573 | 'callback' => 'uc_checkout_pane_delivery', |
| 574 | 'title' => t('Delivery information'), |
| 575 | 'desc' => t('Get the information for where the order needs to ship.'), |
| 576 | 'weight' => 3, |
| 577 | 'shippable' => TRUE, |
| 578 | ); |
| 579 | $panes[] = array( |
| 580 | 'id' => 'billing', |
| 581 | 'callback' => 'uc_checkout_pane_billing', |
| 582 | 'title' => t('Billing information'), |
| 583 | 'desc' => t('Get basic information needed to collect payment.'), |
| 584 | 'weight' => 4, |
| 585 | ); |
| 586 | $panes[] = array( |
| 587 | 'id' => 'comments', |
| 588 | 'callback' => 'uc_checkout_pane_comments', |
| 589 | 'title' => t('Order comments'), |
| 590 | 'desc' => t('Allow a customer to put comments on an order.'), |
| 591 | 'weight' => 7, |
| 592 | ); |
| 593 | |
| 594 | return $panes; |
| 595 | } |
| 596 | |
| 597 | /******************************************************************************* |
| 598 | * Callback Functions, Forms, and Tables |
| 599 | ******************************************************************************/ |
| 600 | |
| 601 | // Displays the cart settings overview page. |
| 602 | function uc_cart_cart_settings_overview() { |
| 603 | // Load the form summaries for pages beneath this path. |
| 604 | $summaries = summarize_child_form_pages('admin/store/settings/cart/edit'); |
| 605 | |
| 606 | // Build the block summary since it comes from another form. |
| 607 | if (variable_get('uc_cart_show_help_text', FALSE)) { |
| 608 | $help_text = t('Help text is shown in block:') .'<br /><i>' |
| 609 | . variable_get('uc_cart_help_text', t('Click title to display cart contents.')) .'</i>'; |
| 610 | } |
| 611 | else { |
| 612 | $help_text = t('Help text is not shown in block.'); |
| 613 | } |
| 614 | $summaries[] = array( |
| 615 | 'path' => 'admin/store/settings/cart/edit/block', |
| 616 | 'href' => 'admin/store/settings/cart/edit/block', |
| 617 | 'title' => t('Cart block'), |
| 618 | 'items' => array( |
| 619 | t('Cart block is !option when empty.', array('!option' => variable_get('uc_cart_empty_hide', FALSE) ? t('hidden') : t('shown'))), |
| 620 | t('Cart block is !option by default.', array('!option' => variable_get('uc_cart_expanded', FALSE) ? t('expanded') : t('collapsed'))), |
| 621 | $help_text, |
| 622 | ), |
| 623 | ); |
| 624 | |
| 625 | // Theme it all up in a summaries overview. |
| 626 | return theme('summary_overview', $summaries); |
| 627 | } |
| 628 | |
| 629 | function uc_cart_block_edit_info() { |
| 630 | $output = t('Drupal handles all the block settings forms automatically.') .'<p>' |
| 631 | . t('<a href="!url">Click here</a> to goto the shopping cart block configuration page.', |
| 632 | array('!url' => url('admin/build/block/configure/uc_cart/0'))); |
| 633 | |
| 634 | return $output; |
| 635 | } |
| 636 | |
| 637 | function uc_cart_cart_settings_form() { |
| 638 | $form['general'] = array( |
| 639 | '#type' => 'fieldset', |
| 640 | '#title' => t('General cart settings'), |
| 641 | '#summary callback' => 'summarize_form', |
| 642 | ); |
| 643 | $form['general']['uc_add_item_redirect'] = array( |
| 644 | '#type' => 'textfield', |
| 645 | '#title' => t('Add to cart redirect'), |
| 646 | '#description' => t('Enter the Drupal page to redirect to when a customer adds an item to their cart.<br />Enter <none> for no redirect.'), |
| 647 | '#summary' => url(variable_get('uc_add_item_redirect', 'cart'), array('absolute' => TRUE)), |
| 648 | '#default_value' => variable_get('uc_add_item_redirect', 'cart'), |
| 649 | '#size' => 32, |
| 650 | '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='), |
| 651 | ); |
| 652 | $form['general']['uc_minimum_subtotal'] = array( |
| 653 | '#type' => 'textfield', |
| 654 | '#title' => t('Minimum order subtotal'), |
| 655 | '#description' => t('Optionally specify a minimum allowed subtotal for a cart to proceed to checkout.'), |
| 656 | '#summary' => uc_currency_format(variable_get('uc_minimum_subtotal', 0)), |
| 657 | '#default_value' => variable_get('uc_minimum_subtotal', 0), |
| 658 | '#size' => 16, |
| 659 | '#field_prefix' => variable_get('uc_sign_after_amount', FALSE) ? '' : variable_get('uc_currency_sign', '$'), |
| 660 | '#field_suffix' => variable_get('uc_sign_after_amount', FALSE) ? variable_get('uc_currency_sign', '$') : '', |
| 661 | ); |
| 662 | |
| 663 | $form['anonymous'] = array( |
| 664 | '#type' => 'fieldset', |
| 665 | '#title' => t('Anonymous cart duration'), |
| 666 | '#description' => t('Set the length of time products remain in the cart for customers who <strong>have not</strong> logged in.'), |
| 667 | '#summary' => variable_get('uc_cart_anon_duration', '4') .' '. variable_get('uc_cart_anon_unit', 'hours'), |
| 668 | ); |
| 669 | $form['anonymous']['uc_cart_anon_duration'] = array( |
| 670 | '#type' => 'select', |
| 671 | '#title' => t('Duration'), |
| 672 | '#options' => drupal_map_assoc(uc_range(1, 60)), |
| 673 | '#default_value' => variable_get('uc_cart_anon_duration', '4'), |
| 674 | '#prefix' => '<div style="float: left; margin-right: 1em;">', |
| 675 | '#suffix' => '</div>', |
| 676 | ); |
| 677 | $form['anonymous']['uc_cart_anon_unit'] = array( |
| 678 | '#type' => 'select', |
| 679 | '#title' => t('Unit of time'), |
| 680 | '#options' => array( |
| 681 | 'minutes' => t('Minute(s)'), |
| 682 | 'hours' => t('Hour(s)'), |
| 683 | 'days' => t('Day(s)'), |
| 684 | 'weeks' => t('Week(s)'), |
| 685 | 'years' => t('Year(s)'), |
| 686 | ), |
| 687 | '#default_value' => variable_get('uc_cart_anon_unit', 'hours'), |
| 688 | '#prefix' => '<div style="float: left; margin-right: 1em;">', |
| 689 | '#suffix' => '</div>', |
| 690 | ); |
| 691 | |
| 692 | $form['authenticated'] = array( |
| 693 | '#type' => 'fieldset', |
| 694 | '#title' => t('Authenticated cart duration'), |
| 695 | '#description' => t('Set the length of time products remain in the cart for customers who <strong>have</strong> logged in.'), |
| 696 | '#summary' => variable_get('uc_cart_auth_duration', '1') .' '. variable_get('uc_cart_anon_unit', 'years'), |
| 697 | ); |
| 698 | $form['authenticated']['uc_cart_auth_duration'] = array( |
| 699 | '#type' => 'select', |
| 700 | '#title' => t('Duration'), |
| 701 | '#options' => drupal_map_assoc(uc_range(1, 24)), |
| 702 | '#default_value' => variable_get('uc_cart_auth_duration', '1'), |
| 703 | '#prefix' => '<div style="float: left; margin-right: 1em;">', |
| 704 | '#suffix' => '</div>', |
| 705 | ); |
| 706 | $form['authenticated']['uc_cart_auth_unit'] = array( |
| 707 | '#type' => 'select', |
| 708 | '#title' => t('Unit of time'), |
| 709 | '#options' => array( |
| 710 | 'hours' => t('Hour(s)'), |
| 711 | 'days' => t('Day(s)'), |
| 712 | 'weeks' => t('Week(s)'), |
| 713 | 'years' => t('Year(s)'), |
| 714 | ), |
| 715 | '#default_value' => variable_get('uc_cart_auth_unit', 'years'), |
| 716 | '#prefix' => '<div style="float: left; margin-right: 1em;">', |
| 717 | '#suffix' => '</div>', |
| 718 | ); |
| 719 | |
| 720 | $form['continue_shopping'] = array( |
| 721 | '#type' => 'fieldset', |
| 722 | '#title' => t('Continue shopping link'), |
| 723 | '#summary' => t('Continue shopping !type is: !link', array('!type' => variable_get('uc_continue_shopping_type', 'link') == 'link' ? t('link') : t('button'), '!link' => l(variable_get('uc_continue_shopping_text', t('Continue shopping')), variable_get('uc_cart_continue_shopping', '')))), |
| 724 | '#summary arguments' => array(FALSE), |
| 725 | ); |
| 726 | $form['continue_shopping']['uc_continue_shopping_type'] = array( |
| 727 | '#type' => 'radios', |
| 728 | '#title' => t('Display the continue shopping link as'), |
| 729 | '#options' => array( |
| 730 | 'link' => t('A text link'), |
| 731 | 'button' => t('A button link'), |
| 732 | ), |
| 733 | '#default_value' => variable_get('uc_continue_shopping_type', 'link'), |
| 734 | ); |
| 735 | $form['continue_shopping']['uc_continue_shopping_url'] = array( |
| 736 | '#type' => 'textfield', |
| 737 | '#title' => t('Continue shopping link URL'), |
| 738 | '#description' => t('Enter the Drupal page for the link to continue shopping from the cart view page.<br />Enter <none> for no link to appear.'), |
| 739 | '#default_value' => variable_get('uc_continue_shopping_url', ''), |
| 740 | '#size' => 32, |
| 741 | '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='), |
| 742 | ); |
| 743 | $form['continue_shopping']['uc_continue_shopping_text'] = array( |
| 744 | '#type' => 'textfield', |
| 745 | '#title' => t('Continue shopping link text'), |
| 746 | '#description' => t('Enter the text for the continue shopping link.'), |
| 747 | '#default_value' => variable_get('uc_continue_shopping_text', t('Continue shopping')), |
| 748 | ); |
| 749 | |
| 750 | $form['breadcrumb'] = array( |
| 751 | '#type' => 'fieldset', |
| 752 | '#title' => t('Cart breadcrumb'), |
| 753 | '#summary' => l(variable_get('uc_cart_breadcrumb_text', t('Home')), variable_get('uc_cart_breadcrumb_url', '')), |
| 754 | ); |
| 755 | $form['breadcrumb']['uc_cart_breadcrumb_url'] = array( |
| 756 | '#type' => 'textfield', |
| 757 | '#title' => t('Default cart breadcrumb URL'), |
| 758 | '#description' => t('Enter the Drupal page linked to in the default breadcrumb on the cart view page.'), |
| 759 | '#default_value' => variable_get('uc_cart_breadcrumb_url', ''), |
| 760 | '#size' => 32, |
| 761 | '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='), |
| 762 | ); |
| 763 | $form['breadcrumb']['uc_cart_breadcrumb_text'] = array( |
| 764 | '#type' => 'textfield', |
| 765 | '#title' => t('Default cart breadcrumb text'), |
| 766 | '#description' => t('Enter the text for the default breadcrumb on the cart page.'), |
| 767 | '#default_value' => variable_get('uc_cart_breadcrumb_text', t('Home')), |
| 768 | ); |
| 769 | |
| 770 | return system_settings_form($form); |
| 771 | } |
| 772 | |
| 773 | function uc_cart_cart_settings_form_validate($form, &$form_state) { |
| 774 | if (!is_numeric($form_state['values']['uc_minimum_subtotal']) || $form_state['values']['uc_minimum_subtotal'] < 0 || $form_state['values']['uc_minimum_subtotal'] === '-0') { |
| 775 | form_set_error('uc_minimum_subtotal', t('Minimum order subtotal should be a non-negative number.')); |
| 776 | } |
| 777 | } |
| 778 | |
| 779 | function uc_cart_cart_panes_form() { |
| 780 | $panes = uc_cart_cart_pane_list(NULL); |
| 781 | |
| 782 | $form['panes'] = array( |
| 783 | '#theme' => 'uc_pane_sort_table', |
| 784 | '#pane_prefix' => 'uc_cap', |
| 785 | '#summary callback' => 'summarize_uc_cart_panes' |
| 786 | ); |
| 787 | foreach ($panes as $pane) { |
| 788 | $form['panes'][$pane['id']]['uc_cap_'. $pane['id'] .'_enabled'] = array( |
| 789 | '#type' => 'checkbox', |
| 790 | '#default_value' => $pane['enabled'], |
| 791 | ); |
| 792 | $form['panes'][$pane['id']]['title'] = array( |
| 793 | '#value' => $pane['title'], |
| 794 | ); |
| 795 | $form['panes'][$pane['id']]['uc_cap_'. $pane['id'] .'_weight'] = array( |
| 796 | '#type' => 'weight', |
| 797 | '#delta' => 10, |
| 798 | '#default_value' => $pane['weight'], |
| 799 | ); |
| 800 | } |
| 801 | |
| 802 | return system_settings_form($form); |
| 803 | } |
| 804 | |
| 805 | function summarize_uc_cart_panes() { |
| 806 | $items = array(); |
| 807 | |
| 808 | $panes = uc_cart_cart_pane_list(NULL); |
| 809 | |
| 810 | foreach ($panes as $pane) { |
| 811 | $items[] = t('!title is !enabled.', array('!title' => $pane['title'], '!enabled' => $pane['enabled'] ? t('enabled') : t('disabled'))); |
| 812 | } |
| 813 | |
| 814 | return $items; |
| 815 | } |
| 816 | |
| 817 | function uc_cart_checkout_settings_overview() { |
| 818 | $sections[] = array( |
| 819 | 'edit' => 'admin/store/settings/checkout/edit', |
| 820 | 'title' => t('Checkout settings'), |
| 821 | 'items' => array( |
| 822 | t('Checkout is !status.', array('!status' => variable_get('uc_checkout_enabled', TRUE) ? t('enabled') : t('disabled'))), |
| 823 | t('Anonymous checkout is !status.', array('!status' => variable_get('uc_checkout_anonymous', TRUE) ? t('enabled') : t('disabled'))), |
| 824 | t('Review order button on checkout page says %text.', array('%text' => variable_get('uc_checkout_review_button', t('Review order')))), |
| 825 | t('Submit order button on review page says %text.', array('%text' => variable_get('uc_checkout_submit_button', t('Submit order')))), |
| 826 | t('Shipping fields are !option.', array('!option' => variable_get('uc_cart_delivery_not_shippable', TRUE) ? t('hidden when applicable') : t('always shown'))), |
| 827 | t('Checkout panes are !option.', array('!option' => variable_get('uc_use_next_buttons', FALSE) ? t('collapsed with next buttons') : t('expanded by default'))), |
| 828 | t('Collapsible panes will !text when their next buttons are clicked.', array('!text' => variable_get('uc_collapse_current_pane', FALSE) ? t('collapse') : t('not collapse'))), |
| 829 | t('Next buttons on checkout panes say %text.', array('%text' => variable_get('uc_checkout_next_button', t('Next')))), |
| 830 | t('New customers !option.', array('!option' => variable_get('uc_new_customer_email', TRUE) ? t('receive an e-mail with their account details') : t('will only see their details in their initial order e-mail.'))), |
| 831 | t('New customer account status will be !status.', array('!status' => variable_get('uc_new_customer_status_active', TRUE) ? t('active') : t('blocked'))), |
| 832 | t('Checkout completion page !text.', array('!text' => variable_get('uc_cart_checkout_complete_page', '') == '' ? t('will be the default page.') : t('has been set to !url', array('!url' => variable_get('uc_cart_checkout_complete_page', ''))))), |
| 833 | ), |
| 834 | ); |
| 835 | |
| 836 | $panes = _checkout_pane_list(); |
| 837 | $items = array(); |
| 838 | foreach ($panes as $pane) { |
| 839 | $items[] = t('!title is !enabled.', array('!title' => $pane['title'], '!enabled' => $pane['enabled'] ? t('enabled') : t('disabled'))); |
| 840 | } |
| 841 | $sections[] = array( |
| 842 | 'edit' => 'admin/store/settings/checkout/edit/panes', |
| 843 | 'title' => t('Checkout panes (in display order)'), |
| 844 | 'items' => $items, |
| 845 | ); |
| 846 | |
| 847 | $items = array(); |
| 848 | $messages = array( |
| 849 | 'checkout_instructions' => array( |
| 850 | 'title' => t('Checkout instructions are'), |
| 851 | 'variable' => 'uc_checkout_instructions', |
| 852 | ), |
| 853 | 'review_instructions' => array( |
| 854 | 'title' => t('Review instructions are'), |
| 855 | 'variable' => 'uc_checkout_review_instructions', |
| 856 | ), |
| 857 | 'completion_message' => array( |
| 858 | 'title' => t('Completion message is'), |
| 859 | 'variable' => 'uc_msg_order_submit', |
| 860 | ), |
| 861 | 'completion_logged_in' => array( |
| 862 | 'title' => t('Completion text for logged in users is'), |
| 863 | 'variable' => 'uc_msg_order_logged_in', |
| 864 | ), |
| 865 | 'completion_existing_user' => array( |
| 866 | 'title' => t('Completion text for not logged in users is'), |
| 867 | 'variable' => 'uc_msg_order_existing_user', |
| 868 | ), |
| 869 | 'completion_new_user' => array( |
| 870 | 'title' => t('Completion text for totally new users is'), |
| 871 | 'variable' => 'uc_msg_order_new_user', |
| 872 | ), |
| 873 | 'continue_shopping' => array( |
| 874 | 'title' => t('Continue shopping text is'), |
| 875 | 'variable' => 'uc_msg_continue_shopping', |
| 876 | ), |
| 877 | ); |
| 878 | foreach ($messages as $message_id => $data) { |
| 879 | $current = variable_get($data['variable'], uc_get_message($message_id)); |
| 880 | if (empty($current)) { |
| 881 | $items[] = t('!title not set.', array('!title' => $data['title'])); |
| 882 | } |
| 883 | else { |
| 884 | $items[] = t('!title set.', array('!title' => $data['title'])); |
| 885 | } |
| 886 | } |
| 887 | $sections[] = array( |
| 888 | 'edit' => 'admin/store/settings/checkout/edit/messages', |
| 889 | 'title' => t('Checkout messages'), |
| 890 | 'items' => $items, |
| 891 | ); |
| 892 | |
| 893 | $items = array(); |
| 894 | $fields = array( |
| 895 | 'first_name' => uc_get_field_name('first_name'), |
| 896 | 'last_name' => uc_get_field_name('last_name'), |
| 897 | 'phone' => uc_get_field_name('phone'), |
| 898 | 'company' => uc_get_field_name('company'), |
| 899 | 'street1' => uc_get_field_name('street1'), |
| 900 | 'street2' => uc_get_field_name('street2'), |
| 901 | 'city' => uc_get_field_name('city'), |
| 902 | 'zone' => uc_get_field_name('zone'), |
| 903 | 'country' => uc_get_field_name('country'), |
| 904 | 'postal_code' => uc_get_field_name('postal_code'), |
| 905 | ); |
| 906 | $current = variable_get('uc_address_fields', drupal_map_assoc(array('first_name', 'last_name', 'phone', 'company', 'street1', 'street2', 'city', 'zone', 'postal_code', 'country'))); |
| 907 | foreach ($fields as $field => $title) { |
| 908 | $items[] = t('!field is !status.', array('!field' => $title, '!status' => isset($current[$field]) ? t('enabled') : t('disabled'))); |
| 909 | } |
| 910 | $sections[] = array( |
| 911 | 'edit' => 'admin/store/settings/checkout/edit/fields', |
| 912 | 'title' => t('Address fields'), |
| 913 | 'items' => $items, |
| 914 | ); |
| 915 | |
| 916 | $output = theme('uc_settings_overview', $sections); |
| 917 | |
| 918 | return $output; |
| 919 | } |
| 920 | |
| 921 | function uc_cart_checkout_settings_form() { |
| 922 | $form['general'] = array( |
| 923 | '#type' => 'fieldset', |
| 924 | '#title' => t('General checkout settings'), |
| 925 | //'#summary' => array(FALSE), |
| 926 | '#summary callback' => 'summarize_form', |
| 927 | ); |
| 928 | $form['general']['uc_checkout_enabled'] = array( |
| 929 | '#type' => 'checkbox', |
| 930 | '#title' => t('Enable checkout (disable to only use third party checkout service like PayPal Express Checkout).'), |
| 931 | '#summary' => t('Ubercart checkout is @status.', array('@status' => variable_get('uc_checkout_enabled', TRUE) ? t('enabled') : t('disabled'))), |
| 932 | '#summary arguments' => array(FALSE), |
| 933 | '#default_value' => variable_get('uc_checkout_enabled', TRUE), |
| 934 | ); |
| 935 | $form['general']['uc_checkout_anonymous'] = array( |
| 936 | '#type' => 'checkbox', |
| 937 | '#title' => t('Enable anonymous checkout (users can checkout without logging in).'), |
| 938 | '#summary' => t('Anonymous checkout is @status.', array('@status' => variable_get('uc_checkout_anonymous', TRUE) ? t('enabled') : t('disabled'))), |
| 939 | '#summary arguments' => array(FALSE), |
| 940 | '#default_value' => variable_get('uc_checkout_anonymous', TRUE), |
| 941 | ); |
| 942 | $form['general']['uc_checkout_review_button'] = array( |
| 943 | '#type' => 'textfield', |
| 944 | '#title' => t('Review order button text'), |
| 945 | '#description' => t('Change the text on the review order button at the bottom of the checkout screen.'), |
| 946 | '#default_value' => variable_get('uc_checkout_review_button', t('Review order')), |
| 947 | ); |
| 948 | $form['general']['uc_checkout_submit_button'] = array( |
| 949 | '#type' => 'textfield', |
| 950 | '#title' => t('Submit order button text'), |
| 951 | '#description' => t('Change the text on the submit order button at the bottom of the review screen.'), |
| 952 | '#default_value' => variable_get('uc_checkout_submit_button', t('Submit order')), |
| 953 | ); |
| 954 | $form['general']['uc_cart_delivery_not_shippable'] = array( |
| 955 | '#type' => 'checkbox', |
| 956 | '#title' => t('Hide shipping information when possible for carts with no shippable items.'), |
| 957 | '#default_value' => variable_get('uc_cart_delivery_not_shippable', TRUE), |
| 958 | ); |
| 959 | |
| 960 | $form['pane_settings'] = array( |
| 961 | '#type' => 'fieldset', |
| 962 | '#title' => t('Checkout pane display options'), |
| 963 | ); |
| 964 | $form['pane_settings']['uc_use_next_buttons'] = array( |
| 965 | '#type' => 'checkbox', |
| 966 | '#title' => t('Use collapsing checkout panes with next buttons during checkout.'), |
| 967 | '#default_value' => variable_get('uc_use_next_buttons', FALSE), |
| 968 | ); |
| 969 | $form['pane_settings']['uc_collapse_current_pane'] = array( |
| 970 | '#type' => 'checkbox', |
| 971 | '#title' => t('Collapse a pane when its next button is clicked.'), |
| 972 | '#default_value' => variable_get('uc_collapse_current_pane', TRUE), |
| 973 | ); |
| 974 | $form['pane_settings']['uc_checkout_next_button'] = array( |
| 975 | '#type' => 'textfield', |
| 976 | '#title' => t('Next pane button text'), |
| 977 | '#description' => t('Change the text on the checkout pane buttons to expand the next pane.'), |
| 978 | '#default_value' => variable_get('uc_checkout_next_button', t('Next')), |
| 979 | ); |
| 980 | |
| 981 | $form['completion'] = array( |
| 982 | '#type' => 'fieldset', |
| 983 | '#title' => t('Checkout completion settings'), |
| 984 | ); |
| 985 | $form['completion']['uc_new_customer_email'] = array( |
| 986 | '#type' => 'checkbox', |
| 987 | '#title' => t('Send new customers a separate e-mail with their account details.'), |
| 988 | '#summary callback' => 'summarize_checkbox', |
| 989 | '#summary arguments' => array( |
| 990 | t('Anonymous customers are e-mailed user details.'), |
| 991 | t('Anonymous customers are not e-mailed user details.') |
| 992 | ), |
| 993 | '#default_value' => variable_get('uc_new_customer_email', TRUE), |
| 994 | ); |
| 995 | $form['completion']['uc_new_customer_login'] = array( |
| 996 | '#type' => 'checkbox', |
| 997 | '#title' => t('Login users when new customer accounts are created at checkout.'), |
| 998 | '#default_value' => variable_get('uc_new_customer_login', FALSE), |
| 999 | ); |
| 1000 | $form['completion']['uc_new_customer_status_active'] = array( |
| 1001 | '#type' => 'checkbox', |
| 1002 | '#title' => t('New customer accounts will be set to active.'), |
| 1003 | '#description' => t('Uncheck to create new accounts but make them blocked.'), |
| 1004 | '#default_value' => variable_get('uc_new_customer_status_active', TRUE), |
| 1005 | ); |
| 1006 | |
| 1007 | $form['completion']['uc_cart_checkout_complete_page'] = array( |
| 1008 | '#type' => 'textfield', |
| 1009 | '#title' => t('Alternate checkout completion page'), |
| 1010 | '#description' => t('Leave blank to use the default completion page (recommended).'), |
| 1011 | '#default_value' => variable_get('uc_cart_checkout_complete_page', ''), |
| 1012 | '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='), |
| 1013 | '#size' => 16, |
| 1014 | ); |
| 1015 | |