'admin/store/settings/cart', 'title' => t('Cart settings'), 'callback' => 'uc_cart_cart_settings_overview', 'access' => user_access('administer store'), 'description' => t('Configure the cart settings.'), ); $items[] = array( 'path' => 'admin/store/settings/cart/overview', 'title' => t('Overview'), 'access' => user_access('administer store'), 'description' => t('View the cart settings.'), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10, ); $items[] = array( 'path' => 'admin/store/settings/cart/edit', 'title' => t('Edit'), 'callback' => 'drupal_get_form', 'callback arguments' => array('uc_cart_cart_settings_form'), 'access' => user_access('administer store'), 'description' => t('Edit the cart settings.'), 'type' => MENU_LOCAL_TASK, 'weight' => -5, ); $items[] = array( 'path' => 'admin/store/settings/cart/edit/basic', 'title' => t('Cart settings'), 'access' => user_access('administer store'), 'description' => t('Edit the basic cart settings.'), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10, ); $items[] = array( 'path' => 'admin/store/settings/cart/edit/panes', 'title' => t('Cart panes'), 'access' => user_access('administer store'), 'callback' => 'drupal_get_form', 'callback arguments' => array('uc_cart_cart_panes_form'), 'description' => t('Edit the pane settings for the cart view page.'), 'type' => MENU_LOCAL_TASK, 'weight' => -5, ); $items[] = array( 'path' => 'admin/store/settings/cart/edit/block', 'title' => t('Cart block'), 'access' => user_access('administer store'), 'callback' => 'uc_cart_block_edit_info', 'description' => t('Edit the settings for the shopping cart block.'), 'type' => MENU_LOCAL_TASK, 'weight' => 0, ); $items[] = array( 'path' => 'admin/store/settings/checkout', 'title' => t('Checkout settings'), 'callback' => 'uc_cart_checkout_settings_overview', 'access' => user_access('administer store'), 'description' => t('Configure the checkout settings.'), ); $items[] = array( 'path' => 'admin/store/settings/checkout/overview', 'title' => t('Overview'), 'access' => user_access('administer store'), 'description' => t('View the checkout settings.'), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10, ); $items[] = array( 'path' => 'admin/store/settings/checkout/edit', 'title' => t('Edit'), 'callback' => 'drupal_get_form', 'callback arguments' => array('uc_cart_checkout_settings_form'), 'access' => user_access('administer store'), 'description' => t('Edit the cart settings.'), 'type' => MENU_LOCAL_TASK, 'weight' => -5, ); $items[] = array( 'path' => 'admin/store/settings/checkout/edit/basic', 'title' => t('Checkout settings'), 'access' => user_access('administer store'), 'description' => t('Edit the basic checkout settings.'), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10, ); $items[] = array( 'path' => 'admin/store/settings/checkout/edit/panes', 'title' => t('Checkout panes'), 'access' => user_access('administer store'), 'callback' => 'drupal_get_form', 'callback arguments' => array('uc_cart_checkout_panes_form'), 'description' => t('Edit the pane settings for the checkout page.'), 'type' => MENU_LOCAL_TASK, 'weight' => -5, ); $items[] = array( 'path' => 'admin/store/settings/checkout/edit/messages', 'title' => t('Checkout messages'), 'access' => user_access('administer store'), 'callback' => 'drupal_get_form', 'callback arguments' => array('uc_cart_checkout_messages_form'), 'description' => t('Edit the messages for the checkout completion page.'), 'type' => MENU_LOCAL_TASK, 'weight' => 0, ); $items[] = array( 'path' => 'admin/store/settings/checkout/edit/fields', 'title' => t('Address fields'), 'access' => user_access('administer store'), 'callback' => 'drupal_get_form', 'callback arguments' => array('uc_store_address_fields_form'), 'description' => t('Edit the address field settings.'), 'type' => MENU_LOCAL_TASK, 'weight' => 5, ); $items[] = array( 'path' => 'cart', 'title' => t('Shopping cart'), 'description' => t('View/modify the contents of your shopping cart or proceed to checkout.'), 'callback' => 'uc_cart_view', 'access' => user_access('access content'), 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'cart/checkout', 'title' => t('Checkout'), 'description' => t('Purchase the items in your shopping cart.'), 'callback' => 'uc_cart_checkout', 'access' => user_access('access content'), 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'cart/checkout/review', 'title' => t('Review order'), 'description' => t('Review an order before final submission.'), 'callback' => 'uc_cart_checkout_review', 'access' => user_access('access content'), 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'cart/checkout/complete', 'title' => t('Order complete'), 'description' => t('Display information upon completion of an order.'), 'callback' => 'uc_cart_checkout_complete', 'access' => user_access('access content'), 'type' => MENU_CALLBACK, ); } return $items; } function uc_cart_enable(){ if (module_exists('imagecache')){ $result = db_query("SELECT presetid FROM {imagecache_preset} WHERE presetname = 'cart'"); if (!db_fetch_object($result)){ $id = db_next_id('{imagecache_preset}_presetid'); db_query("INSERT INTO {imagecache_preset} (presetid, presetname) VALUES (%d, 'cart')", $id); db_query("INSERT INTO {imagecache_action} (actionid, presetid, weight, data) VALUES (%d, %d, 0, '%s')", db_next_id('{imagecache_action}_actionid'), $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";}'); cache_clear_all('imagecache:presets', 'cache'); } } } /** * Implementation of hook_cron(). */ function uc_cart_cron() { // Empty anonymous carts. $time = strtotime(variable_get('uc_cart_anon_duration', '4') .' ' . variable_get('uc_cart_anon_unit', 'hours') .' ago'); db_query("DELETE FROM {uc_cart_products} WHERE changed <= %d AND " ."CHAR_LENGTH(cart_id) > 8", $time); // Empty authenticated carts. $time = strtotime(variable_get('uc_cart_auth_duration', '1') .' ' . variable_get('uc_cart_auth_unit', 'years') .' ago'); db_query("DELETE FROM {uc_cart_products} WHERE changed <= %d AND " ."CHAR_LENGTH(cart_id) <= 8", $time); } /** * Implementation of hook_block(). */ function uc_cart_block($op = 'list', $delta = 0, $edit = array()) { if ($op == 'list') { $blocks[0]['info'] = t('Shopping cart'); return $blocks; } elseif ($op == 'view') { $uc_cart_path = base_path() . drupal_get_path('module', 'uc_cart'); if (variable_get('uc_cart_block_collapsible', TRUE)) { $val = variable_get('uc_cart_block_collapsed', TRUE) ? 'true' : 'false'; drupal_add_js('var collapsed_block = '. $val .';', 'inline'); drupal_add_js("var uc_cart_path = '". $uc_cart_path ."';", 'inline'); drupal_add_js(drupal_get_path('module', 'uc_cart') .'/uc_cart_block.js'); } drupal_add_css(drupal_get_path('module', 'uc_cart') .'/uc_cart_block.css'); $item_count = count(uc_cart_get_contents()); if ($item_count == 0 && variable_get('uc_cart_block_empty_hide', FALSE)) { return; } $cart_image = $uc_cart_path; $cart_image .= ($item_count) ? '/images/cart_full.gif' : '/images/cart_empty.gif'; $arrow_down_image = $uc_cart_path .'/images/bullet-arrow-down.gif'; $arrow_up_image = $uc_cart_path .'/images/bullet-arrow-up.gif'; $block['subject'] = theme('uc_cart_block_title', $cart_image, $arrow_up_image); $block['content'] = theme('uc_cart_block_content'); return $block; } elseif ($op == 'configure') { $form['uc_cart_block_empty_hide'] = array( '#type' => 'checkbox', '#title' => t('Hide block if cart is empty.'), '#default_value' => variable_get('uc_cart_block_empty_hide', FALSE), ); $form['uc_cart_block_image'] = array( '#type' => 'checkbox', '#title' => t('Display the shopping cart icon in the block title.'), '#default_value' => variable_get('uc_cart_block_image', TRUE), ); $form['uc_cart_block_title'] = array( '#type' => 'textfield', '#title' => t('Cart name'), '#description' => t('This name will be displayed when using the default block title.
Leaving this blank defaults to the translatable name "Shopping Cart."'), '#default_value' => variable_get('uc_cart_block_title', ''), ); $form['uc_cart_block_collapsible'] = array( '#type' => 'checkbox', '#title' => t('Make the shopping cart block collapsible by clicking the name or arrow.'), '#default_value' => variable_get('uc_cart_block_collapsible', TRUE), ); $form['uc_cart_block_collapsed'] = array( '#type' => 'checkbox', '#title' => t('Display the shopping cart block collapsed by default.'), '#default_value' => variable_get('uc_cart_block_collapsed', TRUE), ); $form['uc_cart_show_help_text'] = array( '#type' => 'checkbox', '#title' => t('Display small help text in the shopping cart block.'), '#default_value' => variable_get('uc_cart_show_help_text', FALSE), ); $form['uc_cart_help_text'] = array( '#type' => 'textfield', '#title' => t('Cart help text'), '#description' => t('Displayed if the above box is checked.'), '#size' => 32, '#default_value' => variable_get('uc_cart_help_text', t('Click title to display cart contents.')), ); return $form; } elseif ($op == 'save' && isset($edit['uc_cart_block_empty_hide'])) { variable_set('uc_cart_block_empty_hide', $edit['uc_cart_block_empty_hide']); variable_set('uc_cart_block_image', $edit['uc_cart_block_image']); variable_set('uc_cart_block_title', $edit['uc_cart_block_title']); variable_set('uc_cart_block_collapsible', $edit['uc_cart_block_collapsible']); variable_set('uc_cart_block_collapsed', $edit['uc_cart_block_collapsed']); variable_set('uc_cart_show_help_text', $edit['uc_cart_show_help_text']); variable_set('uc_cart_help_text', check_plain($edit['uc_cart_help_text'])); } } /** * Theme the shopping cart block title */ function theme_uc_cart_block_title($cart_image, $arrow_up_image) { if (variable_get('uc_cart_block_image', TRUE)) { $output = l('', 'cart', NULL, NULL, NULL, FALSE, TRUE); } $title = trim(variable_get('uc_cart_block_title', '')); if (empty($title)) { $title = t('Shopping cart'); } if (variable_get('uc_cart_block_collapsible', TRUE)) { $class = ' cart-block-toggle'; } $output .= '' .''. check_plain($title) .''; if (variable_get('uc_cart_block_collapsible', TRUE)) { $output .= '' .'[]'; } return $output; } /** * Theme the shopping cart block content. */ function theme_uc_cart_block_content() { global $user; // Disabled until we figure out if this is actually screwing up caching. -RS //if (!$user->uid && variable_get('cache', 0) !== 0) { // return t('View your shopping cart.', array('!url' => url('cart'))); //} if (variable_get('uc_cart_show_help_text', FALSE)) { $output = '' . variable_get('uc_cart_help_text', t('Click title to display cart contents.')) .''; } $output .= '
'; $items = uc_cart_get_contents(); $item_count = 0; if (!empty($items)) { $output .= '' .''; foreach ($items as $item) { $output .= '' . '' . ''; if (is_array($item->data['attributes']) && !empty($item->data['attributes'])) { $display_item = module_invoke($item->module, 'cart_display', $item); $output .= ''; } $total += ($item->price) * $item->qty; $item_count += $item->qty; } $output .= '
'. $item->qty .'x'. l($item->title, 'node/'. $item->nid) .''. uc_currency_format($item->price) .'
'. $display_item['options']['#value'] .'
'; } else { $output .= '

'. t('There are no products in your shopping cart.') .'

'; } $output .= '
'; $item_text = format_plural($item_count, '1 Item', '@count Items'); $view = '('. l(t('View cart'), 'cart', array('rel' => 'nofollow')) .')'; if (variable_get('uc_checkout_enabled', TRUE)) { $checkout = ' ('. l(t('Checkout'), 'cart/checkout', array('rel' => 'nofollow')) .')'; } $output .= '' .''; if ($item_count > 0) { $output .= ''; } $output .= '
' . $item_text .'' .''. t('Total:') .' '. uc_currency_format($total) .'
'. $view . $checkout .'
'; return $output; } /** * Implementation of hook_exit(). * * Code from CacheExclude - http://drupal.org/project/cacheexclude */ function uc_cart_exit() { global $base_root; $pages = array('cart', 'cart/checkout', 'cart/checkout/review', 'cart/checkout/complete'); $this_page = request_uri(); foreach ($pages as $page) { if ($page && strstr($this_page, $page) !== FALSE) { cache_clear_all($base_root . $this_page, 'cache_page'); return; } } } function uc_cart_nodeapi(&$node, $op, $arg3, $arg4){ if (in_array($node->type, array_keys(uc_product_node_info()))){ switch ($op){ case 'delete': db_query("DELETE FROM {uc_cart_products} WHERE nid = %d", $node->nid); break; } } } /** * Implementation of hook_user(). */ function uc_cart_user($op, &$edit, &$user, $category = NULL) { switch ($op) { case 'load': // Fall through if this a new user load prior to checkout. if (request_uri() != '/user/register?destination=cart/checkout' || $user->uid == 0) { break; } case 'login': // Add items from an anonymous cart to a user's permanent cart on login. $items = uc_cart_get_contents($user->uid); db_query("UPDATE {uc_cart_products} SET cart_id = %d WHERE cart_id = '%s'", $user->uid, session_id()); if (count($items) > 0) { $items = uc_cart_get_contents($user->uid, 'rebuild'); db_query("DELETE FROM {uc_cart_products} WHERE cart_id = %d", $user->uid); foreach ($items as $key => $item) { uc_cart_add_item($item->nid, $item->qty, $item->data, $user->uid, FALSE, FALSE); } } break; } } /** * Implementation of hook_form_alter(). * * Redirect shopper back to checkout page if they go to login from there. */ function uc_cart_form_alter($form_id, &$form) { if ($form_id == 'user_login' || $form_id == 'user_edit' || $form_id == 'user_register') { if ($_SESSION['checkout-redirect'] == TRUE) { $form['#action'] = url($_GET['q'], "destination=cart/checkout"); return; } $referer = referer_uri(); if (substr($referer, -13, 13) == 'cart/checkout') { $form['#action'] = url($_GET['q'], "destination=cart/checkout"); } elseif (substr($referer, -22, 22) == 'cart/checkout/complete') { $form['#action'] = url($_GET['q'], "destination=user"); } } } /******************************************************************************* * Hook Functions (TAPIr) ******************************************************************************/ /** * Implementation of hook_table_settings(). */ function uc_cart_table_settings() { $tables[] = array( 'id' => 'uc_cart_view_table', 'description' => t("Display information on products in a customer's cart."), 'path' => 'admin/store/settings/tables', 'access' => 'administer store', 'preview' => FALSE, ); return $tables; } /******************************************************************************* * Hook Functions (Ubercart) ******************************************************************************/ /** * Implementation of hook_uc_message(). */ function uc_cart_uc_message() { global $user; $messages['checkout_instructions'] = ''; $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')))); $messages['completion_message'] = t('Your order is complete! Your order number is [order-id].'); $messages['completion_logged_in'] = t('Thank you for shopping at [store-name]. While logged in, you may continue shopping or click here to view your current order status and order history.', array('!url' => url('user/'. $user->uid .'/orders', NULL, NULL, TRUE))); $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.') .'

'. t('Click here 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', NULL, NULL, TRUE))); $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('

Click here to login to your new account using the following information:', array('!url' => url('user', NULL, NULL, TRUE))) . t('

Username: !new_username
Password: !new_password'); $messages['continue_shopping'] = l(t('Click to return to the front page.'), '', array(), NULL, NULL, TRUE); return $messages; } /** * Implementation of hook_cart_pane(). */ function uc_cart_cart_pane($items) { $panes[] = array( 'id' => 'cart_form', 'title' => t('Default cart form'), 'enabled' => TRUE, 'weight' => 0, 'body' => !is_null($items) ? '

'. drupal_get_form('uc_cart_view_form', $items) .'
': '', ); return $panes; } /** * Implementation of hook_checkout_pane(). */ function uc_cart_checkout_pane() { $panes[] = array( 'id' => 'cart', 'callback' => 'uc_checkout_pane_cart', 'title' => t('Cart contents'), 'desc' => t("Display the contents of a customer's shopping cart."), 'weight' => 1, 'process' => FALSE, 'collapsible' => FALSE, ); $panes[] = array( 'id' => 'customer', 'callback' => 'uc_checkout_pane_customer', 'title' => t('Customer information'), 'desc' => t('Get the necessary information to create a customer on the site.'), 'weight' => 2, ); $panes[] = array( 'id' => 'delivery', 'callback' => 'uc_checkout_pane_delivery', 'title' => t('Delivery information'), 'desc' => t('Get the information for where the order needs to ship.'), 'weight' => 3, 'shippable' => TRUE, ); $panes[] = array( 'id' => 'billing', 'callback' => 'uc_checkout_pane_billing', 'title' => t('Billing information'), 'desc' => t('Get basic information needed to collect payment.'), 'weight' => 4, ); $panes[] = array( 'id' => 'comments', 'callback' => 'uc_checkout_pane_comments', 'title' => t('Order comments'), 'desc' => t('Allow a customer to put comments on an order.'), 'weight' => 7, ); return $panes; } /******************************************************************************* * Callback Functions, Forms, and Tables ******************************************************************************/ function uc_cart_cart_settings_overview() { $sections[] = array( 'edit' => 'admin/store/settings/cart/edit', 'title' => t('Cart settings'), 'items' => array( t('Add item URL redirect is:
!url', array('!url' => url(variable_get('uc_add_item_redirect', 'cart'), NULL, NULL, TRUE))), t('Minimum order subtotal is !min.', array('!min' => uc_currency_format(variable_get('uc_minimum_subtotal', 0)))), // t('Minimum number of cart items allowed during checkout is !min.', array('!min' => variable_get('uc_minimum_item_count', 0) ? variable_get('uc_minimum_item_count', 0) : 'unlimited')), t('Maximum number of cart items allowed during checkout is !max.', array('!max' => variable_get('uc_maximum_item_count', 0) ? variable_get('uc_maximum_item_count', 0) : 'unlimited')), // t('Anonymous cart duration is !duration.', array('!duration' => variable_get('uc_cart_anon_duration', '4') .' ' . variable_get('uc_cart_anon_unit', 'hours'))), t('Authenticated cart duration is !duration.', array('!duration' => variable_get('uc_cart_auth_duration', '1') .' ' . variable_get('uc_cart_auth_unit', 'years'))), 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', '')))), t('Default cart breadcrumb is:
!link', array('!link' => l(variable_get('uc_cart_breadcrumb_text', t('Home')), variable_get('uc_cart_breadcrumb_url', '')))), ), ); $panes = uc_cart_cart_pane_list(NULL); foreach ($panes as $pane) { $items[] = t('!title is !enabled.', array('!title' => $pane['title'], '!enabled' => $pane['enabled'] ? t('enabled') : t('disabled'))); } $sections[] = array( 'edit' => 'admin/store/settings/cart/edit/panes', 'title' => t('Cart panes (in display order)'), 'items' => $items, ); if (variable_get('uc_cart_show_help_text', FALSE)) { $help_text = t('Help text is shown in block:') .'
' . variable_get('uc_cart_help_text', t('Click title to display cart contents.')) .''; } else { $help_text = t('Help text is not shown in block.'); } $sections[] = array( 'edit' => 'admin/store/settings/cart/edit/block', 'title' => t('Cart block'), 'items' => array( t('Cart block is !option when empty.', array('!option' => variable_get('uc_cart_empty_hide', FALSE) ? t('hidden') : t('shown'))), t('Cart block is !option by default.', array('!option' => variable_get('uc_cart_expanded', FALSE) ? t('expanded') : t('collapsed'))), $help_text, ), ); $output = theme('uc_settings_overview', $sections); return $output; } function uc_cart_block_edit_info() { $output = t('Drupal handles all the block settings forms automatically.') .'

' . t('Click here to goto the shopping cart block configuration page.', array('!url' => url('admin/build/block/configure/uc_cart/0'))); return $output; } function uc_cart_cart_settings_form() { $form['general'] = array( '#type' => 'fieldset', '#title' => t('General cart settings'), '#collapsible' => FALSE, '#collapsed' => FALSE, ); $form['general']['uc_add_item_redirect'] = array( '#type' => 'textfield', '#title' => t('Add to cart redirect'), '#description' => t('Enter the Drupal page to redirect to when a customer adds an item to their cart.
Enter <none> for no redirect.'), '#default_value' => variable_get('uc_add_item_redirect', 'cart'), '#size' => 32, '#field_prefix' => url(NULL, NULL, NULL, TRUE) . (variable_get('clean_url', 0) ? '' : '?q='), ); $form['general']['uc_minimum_subtotal'] = array( '#type' => 'textfield', '#title' => t('Minimum order subtotal'), '#description' => t('Optionally specify a minimum allowed subtotal for a cart to proceed to checkout.'), '#default_value' => variable_get('uc_minimum_subtotal', 0), '#size' => 16, '#field_prefix' => variable_get('uc_sign_after_amount', FALSE) ? '' : variable_get('uc_currency_sign', '$'), '#field_suffix' => variable_get('uc_sign_after_amount', FALSE) ? variable_get('uc_currency_sign', '$') : '', ); // $form['general']['uc_minimum_item_count'] = array( '#type' => 'textfield', '#title' => t('Minimum number of cart items'), '#description' => t('Optionally specify the minimum number of cart items required to proceed to checkout. Use 0 for no minimum'), '#default_value' => variable_get('uc_minimum_item_count', 0), '#size' => 16, ); $form['general']['uc_maximum_item_count'] = array( '#type' => 'textfield', '#title' => t('Maximum number of cart items'), '#description' => t('Optionally specify the maximum number of cart items allowed before proceeding to checkout. Use 0 for no limit.'), '#default_value' => variable_get('uc_maximum_item_count', 0), '#size' => 16, ); // $form['anonymous'] = array( '#type' => 'fieldset', '#title' => t('Anonymous cart duration'), '#description' => t('Set the length of time products remain in the cart for customers who have not logged in.'), '#collapsible' => FALSE, ); $form['anonymous']['uc_cart_anon_duration'] = array( '#type' => 'select', '#title' => t('Duration'), '#options' => drupal_map_assoc(uc_range(1, 60)), '#default_value' => variable_get('uc_cart_anon_duration', '4'), '#prefix' => '

', '#suffix' => '
', ); $form['anonymous']['uc_cart_anon_unit'] = array( '#type' => 'select', '#title' => t('Unit of time'), '#options' => array( 'minutes' => t('Minute(s)'), 'hours' => t('Hour(s)'), 'days' => t('Day(s)'), 'weeks' => t('Week(s)'), 'years' => t('Year(s)'), ), '#default_value' => variable_get('uc_cart_anon_unit', 'hours'), '#prefix' => '
', '#suffix' => '
', ); $form['authenticated'] = array( '#type' => 'fieldset', '#title' => t('Authenticated cart duration'), '#description' => t('Set the length of time products remain in the cart for customers who have logged in.'), '#collapsible' => FALSE, ); $form['authenticated']['uc_cart_auth_duration'] = array( '#type' => 'select', '#title' => t('Duration'), '#options' => drupal_map_assoc(uc_range(1, 24)), '#default_value' => variable_get('uc_cart_auth_duration', '1'), '#prefix' => '
', '#suffix' => '
', ); $form['authenticated']['uc_cart_auth_unit'] = array( '#type' => 'select', '#title' => t('Unit of time'), '#options' => array( 'hours' => t('Hour(s)'), 'days' => t('Day(s)'), 'weeks' => t('Week(s)'), 'years' => t('Year(s)'), ), '#default_value' => variable_get('uc_cart_auth_unit', 'years'), '#prefix' => '
', '#suffix' => '
', ); $form['continue_shopping'] = array( '#type' => 'fieldset', '#title' => t('Continue shopping link'), '#collapsed' => FALSE, '#collapsible' => FALSE, ); $form['continue_shopping']['uc_continue_shopping_type'] = array( '#type' => 'radios', '#title' => t('Display the continue shopping link as'), '#options' => array( 'link' => t('A text link'), 'button' => t('A button link'), ), '#default_value' => variable_get('uc_continue_shopping_type', 'link'), ); $form['continue_shopping']['uc_continue_shopping_url'] = array( '#type' => 'textfield', '#title' => t('Continue shopping link URL'), '#description' => t('Enter the Drupal page for the link to continue shopping from the cart view page.
Enter <none> for no link to appear.'), '#default_value' => variable_get('uc_continue_shopping_url', ''), '#size' => 32, '#field_prefix' => url(NULL, NULL, NULL, TRUE) . (variable_get('clean_url', 0) ? '' : '?q='), ); $form['continue_shopping']['uc_continue_shopping_text'] = array( '#type' => 'textfield', '#title' => t('Continue shopping link text'), '#description' => t('Enter the text for the continue shopping link.'), '#default_value' => variable_get('uc_continue_shopping_text', t('Continue shopping')), ); $form['breadcrumb'] = array( '#type' => 'fieldset', '#title' => t('Cart breadcrumb'), '#collapsed' => FALSE, '#collapsible' => FALSE, ); $form['breadcrumb']['uc_cart_breadcrumb_url'] = array( '#type' => 'textfield', '#title' => t('Default cart breadcrumb URL'), '#description' => t('Enter the Drupal page linked to in the default breadcrumb on the cart view page.'), '#default_value' => variable_get('uc_cart_breadcrumb_url', ''), '#size' => 32, '#field_prefix' => url(NULL, NULL, NULL, TRUE) . (variable_get('clean_url', 0) ? '' : '?q='), ); $form['breadcrumb']['uc_cart_breadcrumb_text'] = array( '#type' => 'textfield', '#title' => t('Default cart breadcrumb text'), '#description' => t('Enter the text for the default breadcrumb on the cart page.'), '#default_value' => variable_get('uc_cart_breadcrumb_text', t('Home')), ); return system_settings_form($form); } function uc_cart_cart_settings_form_validate($form_id, $form_values) { if (!is_numeric($form_values['uc_minimum_subtotal']) || $form_values['uc_minimum_subtotal'] < 0 || $form_values['uc_minimum_subtotal'] === '-0') { form_set_error('uc_minimum_subtotal', t('Minimum order subtotal should be a non-negative number.')); } } function uc_cart_cart_panes_form() { $panes = uc_cart_cart_pane_list(NULL); $form['panes'] = array( '#theme' => 'uc_pane_sort_table', '#pane_prefix' => 'uc_cap', ); foreach($panes as $pane) { $form['panes'][$pane['id']]['uc_cap_'. $pane['id'] .'_enabled'] = array( '#type' => 'checkbox', '#default_value' => $pane['enabled'], ); $form['panes'][$pane['id']]['title'] = array( '#value' => $pane['title'], ); $form['panes'][$pane['id']]['uc_cap_'. $pane['id'] .'_weight'] = array( '#type' => 'weight', '#delta' => 10, '#default_value' => $pane['weight'], ); } return system_settings_form($form); } function uc_cart_checkout_settings_overview() { $sections[] = array( 'edit' => 'admin/store/settings/checkout/edit', 'title' => t('Checkout settings'), 'items' => array( t('Checkout is !status.', array('!status' => variable_get('uc_checkout_enabled', TRUE) ? t('enabled') : t('disabled'))), t('Anonymous checkout is !status.', array('!status' => variable_get('uc_checkout_anonymous', TRUE) ? t('enabled') : t('disabled'))), t('Review order button on checkout page says %text.', array('%text' => variable_get('uc_checkout_review_button', t('Review order')))), t('Submit order button on review page says %text.', array('%text' => variable_get('uc_checkout_submit_button', t('Submit order')))), t('Shipping fields are !option.', array('!option' => variable_get('uc_cart_delivery_not_shippable', TRUE) ? t('hidden when applicable') : t('always shown'))), t('Checkout panes are !option.', array('!option' => variable_get('uc_use_next_buttons', FALSE) ? t('collapsed with next buttons') : t('expanded by default'))), 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'))), t('Next buttons on checkout panes say %text.', array('%text' => variable_get('uc_checkout_next_button', t('Next')))), 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.'))), t('New customer account status will be !status.', array('!status' => variable_get('uc_new_customer_status_active', TRUE) ? t('active') : t('blocked'))), 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', ''))))), ), ); $panes = _checkout_pane_list(); $items = array(); foreach ($panes as $pane) { $items[] = t('!title is !enabled.', array('!title' => $pane['title'], '!enabled' => $pane['enabled'] ? t('enabled') : t('disabled'))); } $sections[] = array( 'edit' => 'admin/store/settings/checkout/edit/panes', 'title' => t('Checkout panes (in display order)'), 'items' => $items, ); $items = array(); $messages = array( 'checkout_instructions' => array( 'title' => t('Checkout instructions are'), 'variable' => 'uc_checkout_instructions', ), 'review_instructions' => array( 'title' => t('Review instructions are'), 'variable' => 'uc_checkout_review_instructions', ), 'completion_message' => array( 'title' => t('Completion message is'), 'variable' => 'uc_msg_order_submit', ), 'completion_logged_in' => array( 'title' => t('Completion text for logged in users is'), 'variable' => 'uc_msg_order_logged_in', ), 'completion_existing_user' => array( 'title' => t('Completion text for not logged in users is'), 'variable' => 'uc_msg_order_existing_user', ), 'completion_new_user' => array( 'title' => t('Completion text for totally new users is'), 'variable' => 'uc_msg_order_new_user', ), 'continue_shopping' => array( 'title' => t('Continue shopping text is'), 'variable' => 'uc_msg_continue_shopping', ), ); foreach ($messages as $message_id => $data) { $current = variable_get($data['variable'], uc_get_message($message_id)); if (empty($current)) { $items[] = t('!title not set.', array('!title' => $data['title'])); } else { $items[] = t('!title set.', array('!title' => $data['title'])); } } $sections[] = array( 'edit' => 'admin/store/settings/checkout/edit/messages', 'title' => t('Checkout messages'), 'items' => $items, ); $items = array(); $fields = array( 'first_name' => uc_get_field_name('first_name'), 'last_name' => uc_get_field_name('last_name'), 'phone' => uc_get_field_name('phone'), 'company' => uc_get_field_name('company'), 'street1' => uc_get_field_name('street1'), 'street2' => uc_get_field_name('street2'), 'city' => uc_get_field_name('city'), 'zone' => uc_get_field_name('zone'), 'country' => uc_get_field_name('country'), 'postal_code' => uc_get_field_name('postal_code'), ); $current = variable_get('uc_address_fields', drupal_map_assoc(array('first_name', 'last_name', 'phone', 'company', 'street1', 'street2', 'city', 'zone', 'postal_code', 'country'))); foreach ($fields as $field => $title) { $items[] = t('!field is !status.', array('!field' => $title, '!status' => isset($current[$field]) ? t('enabled') : t('disabled'))); } $sections[] = array( 'edit' => 'admin/store/settings/checkout/edit/fields', 'title' => t('Address fields'), 'items' => $items, ); $output = theme('uc_settings_overview', $sections); return $output; } function uc_cart_checkout_settings_form() { $form['general'] = array( '#type' => 'fieldset', '#title' => t('General checkout settings'), '#collapsible' => FALSE, '#collapsed' => FALSE, ); $form['general']['uc_checkout_enabled'] = array( '#type' => 'checkbox', '#title' => t('Enable checkout (disable to only use third party checkout service like PayPal Express Checkout).'), '#default_value' => variable_get('uc_checkout_enabled', TRUE), ); $form['general']['uc_checkout_anonymous'] = array( '#type' => 'checkbox', '#title' => t('Enable anonymous checkout (users can checkout without logging in).'), '#default_value' => variable_get('uc_checkout_anonymous', TRUE), ); $form['general']['uc_checkout_review_button'] = array( '#type' => 'textfield', '#title' => t('Review order button text'), '#description' => t('Change the text on the review order button at the bottom of the checkout screen.'), '#default_value' => variable_get('uc_checkout_review_button', t('Review order')), ); $form['general']['uc_checkout_submit_button'] = array( '#type' => 'textfield', '#title' => t('Submit order button text'), '#description' => t('Change the text on the submit order button at the bottom of the review screen.'), '#default_value' => variable_get('uc_checkout_submit_button', t('Submit order')), ); $form['general']['uc_cart_delivery_not_shippable'] = array( '#type' => 'checkbox', '#title' => t('Hide shipping information when possible for carts with no shippable items.'), '#default_value' => variable_get('uc_cart_delivery_not_shippable', TRUE), ); $form['pane_settings'] = array( '#type' => 'fieldset', '#title' => t('Checkout pane display options'), '#collapsible' => FALSE, '#collapsed' => FALSE, ); $form['pane_settings']['uc_use_next_buttons'] = array( '#type' => 'checkbox', '#title' => t('Use collapsing checkout panes with next buttons during checkout.'), '#default_value' => variable_get('uc_use_next_buttons', TRUE), ); $form['pane_settings']['uc_collapse_current_pane'] = array( '#type' => 'checkbox', '#title' => t('Collapse a pane when its next button is clicked.'), '#default_value' => variable_get('uc_collapse_current_pane', TRUE), ); $form['pane_settings']['uc_checkout_next_button'] = array( '#type' => 'textfield', '#title' => t('Next pane button text'), '#description' => t('Change the text on the checkout pane buttons to expand the next pane.'), '#default_value' => variable_get('uc_checkout_next_button', t('Next')), ); $form['completion'] = array( '#type' => 'fieldset', '#title' => t('Checkout completion settings'), '#collapsible' => FALSE, '#collapsed' => FALSE, ); $form['completion']['uc_new_customer_email'] = array( '#type' => 'checkbox', '#title' => t('Send new customers a separate e-mail with their account details.'), '#default_value' => variable_get('uc_new_customer_email', TRUE), ); $form['completion']['uc_new_customer_status_active'] = array( '#type' => 'checkbox', '#title' => t('New customer accounts will be set to active.'), '#description' => t('Uncheck to create new accounts but make them blocked.'), '#default_value' => variable_get('uc_new_customer_status_active', TRUE), ); $form['completion']['uc_cart_checkout_complete_page'] = array( '#type' => 'textfield', '#title' => t('Alternate checkout completion page'), '#description' => t('Leave blank to use the default completion page (recommended).'), '#default_value' => variable_get('uc_cart_checkout_complete_page', ''), '#field_prefix' => url(NULL, NULL, NULL, TRUE) . (variable_get('clean_url', 0) ? '' : '?q='), '#size' => 16, ); return system_settings_form($form); } function uc_cart_checkout_panes_form() { $panes = _checkout_pane_list(); $form['panes'] = array( '#theme' => 'uc_pane_sort_table', '#pane_prefix' => 'uc_pane', ); foreach ($panes as $pane) { $form['panes'][$pane['id']]['uc_pane_'. $pane['id'] .'_enabled'] = array( '#type' => 'checkbox', '#default_value' => $pane['enabled'], ); $form['panes'][$pane['id']]['title'] = array( '#value' => $pane['title'], ); $form['panes'][$pane['id']]['uc_pane_'. $pane['id'] .'_weight'] = array( '#type' => 'weight', '#default_value' => $pane['weight'], ); $pane_settings = $pane['callback']('settings', $null, NULL); if (is_array($pane_settings)) { $form['pane_'. $pane['id']] = array( '#type' => 'fieldset', '#title' => t('!pane settings', array('!pane' => $pane['title'])), '#collapsible' => TRUE, '#collapsed' => TRUE, ); $form['pane_'. $pane['id']] = array_merge($form['pane_'. $pane['id']], $pane_settings); } } return system_settings_form($form); } function uc_cart_checkout_messages_form() { $form['uc_checkout_instructions'] = array( '#type' => 'textarea', '#title' => t('Checkout instructions'), '#description' => t('Provide instructions for customers at the top of the checkout screen.'), '#default_value' => variable_get('uc_checkout_instructions', ''), '#rows' => 3, ); $form['uc_checkout_instructions_format'] = filter_form(variable_get('uc_checkout_instructions_format', 3), NULL, array('uc_checkout_instructions_format')); $form['uc_checkout_review_instructions'] = array( '#type' => 'textarea', '#title' => t('Checkout review instructions'), '#description' => t('Provide instructions for customers at the top of the checkout review screen.'), '#default_value' => variable_get('uc_checkout_review_instructions', uc_get_message('review_instructions')), '#rows' => 3, ); $form['uc_checkout_review_instructions_format'] = filter_form(variable_get('uc_checkout_review_instructions_format', 3), NULL, array('uc_checkout_review_instructions_format')); $form['uc_msg_order_submit'] = array( '#type' => 'textarea', '#title' => t('Checkout completion message header'), '#description' => t('Header for message displayed after a user checks out. Uses order and global tokens.', array('!url' => 'admin/store/help/tokens')), '#default_value' => variable_get('uc_msg_order_submit', uc_get_message('completion_message')), '#rows' => 3, ); $form['uc_msg_order_submit_format'] = filter_form(variable_get('uc_msg_order_submit_format', 3), NULL, array('uc_msg_order_submit_format')); $form['checkout_messages'] = array( '#type' => 'fieldset', '#title' => t('Checkout completion message body'), '#description' => t("In the following three boxes, you may use the special tokens !new_username for the username of a newly created account and !new_password for that account's password."), '#collapsible' => FALSE, ); $form['checkout_messages']['uc_msg_order_logged_in'] = array( '#type' => 'textarea', '#title' => t('Checkout completion for logged-in users'), '#description' => t('Message displayed upon checkout for a user who has logged in. Uses order and global tokens.', array('!url' => 'admin/store/help/tokens')), '#default_value' => variable_get('uc_msg_order_logged_in', uc_get_message('completion_logged_in')), '#rows' => 3, ); $form['checkout_messages']['uc_msg_order_logged_in_format'] = filter_form(variable_get('uc_msg_order_logged_in_format', 3), NULL, array('uc_msg_order_logged_in_format')); $form['checkout_messages']['uc_msg_order_existing_user'] = array( '#type' => 'textarea', '#title' => t('Checkout completion for existing users'), '#description' => t("Message displayed upon checkout for a user who has an account but wasn't logged in. Uses order and global tokens.", array('!url' => 'admin/store/help/tokens')), '#default_value' => variable_get('uc_msg_order_existing_user', uc_get_message('completion_existing_user')), '#rows' => 3, ); $form['checkout_messages']['uc_msg_order_existing_user_format'] = filter_form(variable_get('uc_msg_order_existing_user_format', 3), NULL, array('uc_msg_order_existing_user_format')); $form['checkout_messages']['uc_msg_order_new_user'] = array( '#type' => 'textarea', '#title' => t('Checkout completion for new users'), '#description' => t('Message displayed upon checkout for a new user whose account was just created. Uses order and global tokens.', array('!url' => 'admin/store/help/tokens')), '#default_value' => variable_get('uc_msg_order_new_user', uc_get_message('completion_new_user')), '#rows' => 3, ); $form['checkout_messages']['uc_msg_order_new_user_format'] = filter_form(variable_get('uc_msg_order_new_user_format', 3), NULL, array('uc_msg_order_new_user_format')); $form['uc_msg_continue_shopping'] = array( '#type' => 'textarea', '#title' => t('Continue shopping message'), '#description' => t('Message displayed upon checkout to direct customers to another part of your site. Uses order and global tokens.', array('!url' => 'admin/store/help/tokens')), '#default_value' => variable_get('uc_msg_continue_shopping', uc_get_message('continue_shopping')), '#rows' => 3, ); $form['uc_msg_continue_shopping_format'] = filter_form(variable_get('uc_msg_continue_shopping_format', 3), NULL, array('uc_msg_continue_shopping_format')); return system_settings_form($form); } // Displays cart view page with form to adjust cart contents or go to checkout. function uc_cart_view() { if (!empty($_SESSION['cart_order'])) { unset($_SESSION['cart_order']); } $items = uc_cart_get_contents(); if (empty($items)) { return theme('uc_empty_cart'); } $panes = uc_cart_cart_pane_list($items); foreach ($panes as $pane) { if ($pane['enabled']) { $output .= $pane['body']; } } if (isset($_SESSION['last_url'])) { drupal_set_breadcrumb(array(l(t('Back'), check_plain($_SESSION['last_url'])))); unset($_SESSION['last_url']); } else { if (($text = variable_get('uc_cart_breadcrumb_text', t('Home'))) !== '') { $link = l($text, variable_get('uc_cart_breadcrumb_url', '')); drupal_set_breadcrumb(array($link)); } } return $output; } // Returns the text displayed for an empty shopping cart. function theme_uc_empty_cart() { return '

'. t('There are no products in your shopping cart.') . '

'; } /** * Display a page allowing the customer to view the contents of his or her cart. * * Handles simple or complex objects. Some cart items may have a list of products * that they represent. These are displayed but are not able to be changed by the * customer. */ function uc_cart_view_form($items = NULL) { $form['items'] = array('#tree' => TRUE); $i = 0; foreach ($items as $item) { $display_item = module_invoke($item->module, 'cart_display', $item); if (!empty($display_item)){ $form['items'][$i] = $display_item; $form['items'][$i]['image']['#value'] = uc_product_get_picture($item->nid, 'cart'); $i++; } } if (($page = variable_get('uc_continue_shopping_url', '')) != '' && variable_get('uc_continue_shopping_type', 'link') == 'button') { $form['continue_shopping'] = array( '#type' => 'submit', '#value' => variable_get('uc_continue_shopping_text', t('Continue shopping')), ); } $form['update'] = array( '#type' => 'submit', '#value' => t('Update cart'), ); if (variable_get('uc_checkout_enabled', TRUE)) { $form['checkout'] = array( '#type' => 'submit', '#value' => t('Checkout'), ); } return $form; } function theme_uc_cart_view_form($form) { drupal_add_css(drupal_get_path('module', 'uc_cart') .'/uc_cart.css'); $output = '
' . tapir_get_table('uc_cart_view_table', $form) .'
'; if (($page = variable_get('uc_continue_shopping_url', '')) != '') { if (variable_get('uc_continue_shopping_type', 'link') == 'link') { $continue_shopping_link = l(variable_get('uc_continue_shopping_text', t('Continue shopping')), $page); } else { $continue_shopping_link = drupal_render($form['continue_shopping']); } } $output .= '
' . $continue_shopping_link .'
' /*. drupal_render($form['order_id']) . drupal_render($form['form_id']) . drupal_render($form['form_token']) . drupal_render($form['update']) . drupal_render($form['checkout']) .'
';*/ . drupal_render($form) .''; return $output; } function uc_cart_view_table($op, &$form) { switch ($op) { case 'fields': $fields[] = array('name' => 'remove', 'title' => t('Remove'), 'weight' => 0, 'enabled' => TRUE, 'locked' => TRUE); $fields[] = array('name' => 'image', 'title' => t('Products'), 'weight' => 1, 'enabled' => TRUE); $fields[] = array('name' => 'desc', 'title' => '', 'weight' => 2, 'enabled' => TRUE); $fields[] = array('name' => 'qty', 'title' => t('Qty.'), 'weight' => 3, 'enabled' => TRUE); $fields[] = array('name' => 'total', 'title' => t('Total'), 'weight' => 4, 'enabled' => TRUE); return $fields; case 'data': foreach (element_children($form['items']) as $i){ $nid = $form['items'][$i]['nid']['#value']; $subtotal += $form['items'][$i]['#total']; $desc = drupal_render($form['items'][$i]['title']) .'
'; $desc .= drupal_render($form['items'][$i]['options']); $data['remove'][] = array('data' => drupal_render($form['items'][$i]['remove']), 'align' => 'center', 'class' => 'remove'); $data['image'][] = array('data' => drupal_render($form['items'][$i]['image']), 'class' => 'image'); $data['desc'][] = array('data' => $desc, 'width' => '100%', 'class' => 'desc'); $data['qty'][] = array('data' => $form['items'][$i]['qty'] ? drupal_render($form['items'][$i]['qty']) : '', 'class' => 'qty'); $data['total'][] = array('data' => uc_currency_format($form['items'][$i]['#total']), 'nowrap' => 'nowrap', 'class' => 'price'); $data['#attributes'][] = array('valign' => 'top'); } $data['#footer'] = array( array('data' => ''. t('Subtotal:') .' '. uc_currency_format($subtotal), 'colspan' => 5, 'align' => 'right', 'nowrap' => 'nowrap', 'class' => 'subtotal') ); return $data; case 'attributes': $attributes = array('width' => '100%'); return $attributes; } } function uc_cart_view_form_submit($form_id, $form_values) { if (isset($_SESSION['cart_order'])) { unset($_SESSION['cart_order']); } switch ($form_values['op']) { case variable_get('uc_continue_shopping_text', t('Continue shopping')): return variable_get('uc_continue_shopping_url', ''); case t('Update cart'): cache_clear_all(); uc_cart_update_item_object((object)$form_values); drupal_set_message(t('Your cart has been updated.')); return 'cart'; case t('Checkout'): cache_clear_all(); if (!variable_get('uc_checkout_enabled', TRUE)) { return 'cart'; } uc_cart_update_item_object((object)$form_values); return 'cart/checkout'; } } /** * Display the cart checkout page built of checkout panes from enabled modules. */ function uc_cart_checkout() { global $user; $items = uc_cart_get_contents(); if (count($items) == 0 || !variable_get('uc_checkout_enabled', TRUE)) { drupal_goto('cart'); } // $iMinItems = variable_get('uc_minimum_item_count', 0); $iMaxItems = variable_get('uc_maximum_item_count', 0); if(count($items) < $iMinItems) { drupal_set_message('You must purchase at least '.format_plural($iMinItems,'1 item', '@count different items').' to complete your checkout.'); drupal_goto('cart'); } if(count($items) > $iMaxItems && $iMaxItems) { drupal_set_message('You can not purchase more than '.format_plural($iMaxItems,'1 item', '@count different items'). ' at a time.'); drupal_goto('cart'); } // if (($min = variable_get('uc_minimum_subtotal', 0)) > 0) { $subtotal = 0; $items = uc_cart_get_contents(); if (is_array($items) && count($items) > 0) { foreach ($items as $item) { $data = module_invoke($item->module, 'cart_display', $item); if (!empty($data)){ $subtotal += $data['#total']; } } } if ($subtotal < $min) { drupal_set_message(variable_get('uc_minimum_subtotal_text', t('The minimum order subtotal for checkout is !min.', array('!min' => uc_currency_format($min)))), 'error'); drupal_goto('cart'); } } // Send anonymous users to login page when anonymous checkout is disabled. if(!$user->uid && !variable_get('uc_checkout_anonymous', TRUE)) { drupal_set_message(t('You must login before you can proceed to checkout.')); drupal_set_message(t('If you do not have an account, you can !click_here to create one.', array('!click_here' => l(t('click here'), 'user/register')))); $_SESSION['checkout-redirect'] = TRUE; drupal_goto('user'); } $list = _line_item_list(); foreach ($list as $line_item) { if (function_exists($line_item['callback'])) { $line_item['callback']('cart-preview', $items); } } drupal_add_js(drupal_get_path('module', 'uc_cart') .'/uc_cart.js'); $output = drupal_get_form('uc_cart_checkout_form'); return $output; } function uc_cart_checkout_form() { global $user; // Cancel an order when a customer clicks the 'Cancel' button. if ($_POST['op'] == t('Cancel')) { if (intval($_SESSION['cart_order']) > 0) { uc_order_comment_save($_SESSION['cart_order'], 0, t('Customer cancelled this order from the checkout form.')); unset($_SESSION['cart_order']); } drupal_goto('cart'); } // Check the referer URI to clear the order details and prevent identity theft. $referer = referer_uri(); if (substr($referer, -20, 20) == 'cart/checkout/review' || substr($referer, -13, 13) == 'cart/checkout') { if (!($order = uc_order_load($_SESSION['cart_order'])) || uc_order_status_data($order->order_status, 'state') != 'in_checkout') { unset($_SESSION['cart_order']); $order = NULL; } if (uc_order_status_data($order->order_status, 'state') != 'in_checkout' || ($user->uid && $user->uid != $order->uid)) { $order = NULL; } } else { unset($_SESSION['cart_order']); } $form['panes'] = array('#tree' => TRUE); $panes = _checkout_pane_list(); // If the cart isn't shippable, remove panes with shippable == TRUE. if (!uc_cart_is_shippable() && variable_get('uc_cart_delivery_not_shippable', TRUE)) { $panes = uc_cart_filter_checkout_panes($panes, array('shippable' => TRUE)); } foreach ($panes as $pane) { if (variable_get('uc_pane_'. $pane['id'] .'_enabled', TRUE)) { $pane['prev'] = _uc_cart_checkout_prev_pane($panes, $pane['id']); $pane['next'] = _uc_cart_checkout_next_pane($panes, $pane['id']); if (is_null($pane['collapsed'])) { $collapsed = ($pane['prev'] === FALSE || empty($displayed[$pane['prev']])) ? FALSE : TRUE; } if (isset($_SESSION['expanded_panes'])) { if (is_array($_SESSION['expanded_panes']) && in_array($pane['id'], $_SESSION['expanded_panes'])) { $collapsed = FALSE; } } $return = $pane['callback']('view', $order, NULL); // Add the pane if any display data is returned from the callback. if (is_array($return) && (!empty($return['description']) || !empty($return['contents']))) { // Create the fieldset for the pane. $form['panes'][$pane['id']] = array( '#type' => 'fieldset', '#title' => $pane['title'], '#description' => !empty($return['description']) ? $return['description'] : NULL, '#collapsible' => $pane['collapsible'], '#collapsed' => variable_get('uc_use_next_buttons', FALSE) ? $collapsed : FALSE, '#attributes' => array('id' => $pane['id'] .'-pane'), '#theme' => $return['theme'], ); // Add the contents of the fieldset if any were returned. if (!empty($return['contents'])) { $form['panes'][$pane['id']] = array_merge($form['panes'][$pane['id']], $return['contents']); } // Add the 'Next' button if necessary. if ($return['next-button'] !== FALSE && $pane['next'] !== FALSE && variable_get('uc_use_next_buttons', FALSE) != FALSE) { $opt = variable_get('uc_collapse_current_pane', FALSE) ? $pane['id'] : 'false'; $form['panes'][$pane['id']]['next'] = array( '#type' => 'button', '#value' => variable_get('uc_checkout_next_button', t('Next')), '#weight' => variable_get("uc_pane_{$pane_id}_field_button_weight", 20), '#attributes' => array('onclick' => "return uc_cart_next_button_click(this, '". $pane['next'] ."', '". $opt ."');"), '#prefix' => '
', '#suffix' => '
', ); } // Log that this pane was actually displayed. $displayed[$pane['id']] = TRUE; } } } unset($_SESSION['expanded_panes']); $form['cart_contents'] = array('#type' => 'hidden', '#value' => serialize(uc_cart_get_contents())); $form['cancel'] = array('#type' => 'submit', '#submit' => FALSE, '#value' => t('Cancel')); $form['continue'] = array('#type' => 'submit', '#value' => variable_get('uc_checkout_review_button', t('Review order'))); return $form; } function theme_uc_cart_checkout_form($form) { drupal_add_css(drupal_get_path('module', 'uc_cart') .'/uc_cart.css'); $output = '
'. check_markup(variable_get('uc_checkout_instructions', ''), variable_get('uc_checkout_instructions_format', 3), FALSE) . '
'; if (arg(1) == 'checkout2') { foreach (element_children($form['panes']) as $pane_id) { $output .= drupal_render($form['panes'][$pane_id]); } } else { foreach (element_children($form['panes']) as $pane_id) { if (function_exists(($func = _checkout_pane_data($pane_id, 'callback')))) { $result = $func('theme', $form['panes'][$pane_id], NULL); if (!empty($result)) { $output .= $result; $form['panes'][$pane_id] = array(); } else { $output .= drupal_render($form['panes'][$pane_id]); } } else { $output .= drupal_render($form['panes'][$pane_id]); } } } $output .= '
'. drupal_render($form) .'
'; return $output; } function uc_cart_checkout_form_submit($form_id, $form_values) { global $user; if (empty($_SESSION['cart_order'])) { $order = uc_order_new($user->uid); $_SESSION['cart_order'] = $order->order_id; } else { $order = new stdClass(); $order->uid = $user->uid; $order->order_id = $_SESSION['cart_order']; $order->order_status = uc_order_state_default('in_checkout'); } $order->products = unserialize($form_values['cart_contents']); $valid = TRUE; foreach(element_children($form_values['panes']) as $pane_id) { $func = _checkout_pane_data($pane_id, 'callback'); $isvalid = $func('process', $order, $form_values['panes'][$pane_id]); if ($isvalid === FALSE) { $_SESSION['expanded_panes'][] = $pane_id; $valid = FALSE; } } $order->line_items = uc_order_load_line_items($order->order_id, true); uc_order_save($order); if ($valid === FALSE) { return 'cart/checkout'; } $_SESSION['do_review'] = TRUE; return 'cart/checkout/review'; } /** * Allow a customer to review their order before finally submitting it. */ function uc_cart_checkout_review() { $form = drupal_get_form('uc_cart_checkout_review_form'); if ($_SESSION['do_review'] !== TRUE) { drupal_goto('cart'); } $_SESSION['do_review'] = FALSE; unset($_SESSION['do_review']); $order_id = intval($_SESSION['cart_order']); $order = uc_order_load($order_id); if ($order === FALSE || uc_order_status_data($order->order_status, 'state') != 'in_checkout') { $_SESSION['cart_order'] = NULL; unset($_SESSION['cart_order']); drupal_goto('cart'); } $panes = _checkout_pane_list(); // If the cart isn't shippable, bypass panes with shippable == TRUE. if (!uc_cart_is_shippable() && variable_get('uc_cart_delivery_not_shippable', TRUE)) { $panes = uc_cart_filter_checkout_panes($panes, array('shippable' => TRUE)); } foreach ($panes as $pane) { if (variable_get('uc_pane_'. $pane['id'] .'_enabled', TRUE)) { $func = $pane['callback']; if (function_exists($func)) { $return = $func('review', $order, NULL); if (!is_null($return)) { $data[$pane['title']] = $return; } } } } $output = theme('uc_cart_checkout_review', $help, $data, $form); return $output; } /** * Theme the checkout review order page. * * @param $help * A string containing the review order page help message. * @param $panes * An associative array for each checkout pane that has information to add to * the review page. The key is the pane's title and the value is either the * data returned for that pane or an array of returned data. * @param $form * The HTML version of the form that by default includes the 'Back' and * 'Submit order' buttons at the bottom of the review page. * @return * A string of HTML for the page contents. * @ingroup themeable */ function theme_uc_cart_checkout_review($help, $panes, $form) { drupal_add_css(drupal_get_path('module', 'uc_cart') .'/uc_cart.css'); $output = '
'. check_markup(variable_get('uc_checkout_review_instructions', uc_get_message('review_instructions')), variable_get('uc_checkout_review_instructions_format', 3), FALSE) . '
'; foreach ($panes as $title => $data) { $output .= ''; if (is_array($data)) { foreach ($data as $row) { if (is_array($row)) { if (isset($row['border'])) { $border = ' class="row-border-'. $row['border'] .'"'; } else { $border = ''; } $output .= ''; } else { $output .= ''; } } } else { $output .= ''; } } $output .= '
'. $title .'
'. $row['title'] .':' . $row['data'] .'
'. $row .'
'. $data .'
'. $form .'
'; return $output; } function uc_cart_checkout_review_form() { if ($_POST['op'] == t('Back')) { cache_clear_all(); drupal_goto('cart/checkout'); } $form['back'] = array('#type' => 'button', '#value' => t('Back')); $form['submit'] = array('#type' => 'submit', '#value' => variable_get('uc_checkout_submit_button', t('Submit order'))); return $form; } function uc_cart_checkout_review_form_submit($form_id, $form_values) { switch ($form_values['op']) { case variable_get('uc_checkout_submit_button', t('Submit order')): // Invoke hook_order($op = 'submit') to test to make sure the order can // be completed... used for auto payment in uc_credit.module. $order = uc_order_load($_SESSION['cart_order']); $pass = module_invoke_all('order', 'submit', $order, NULL); foreach ($pass as $result) { $msg_type = 'status'; if ($result['pass'] === FALSE) { $error = TRUE; $msg_type = 'error'; } if (!empty($result['message'])) { drupal_set_message($result['message'], $msg_type); } } if ($error === TRUE) { $_SESSION['do_review'] = TRUE; return 'cart/checkout/review'; } else { $_SESSION['do_complete'] = TRUE; return 'cart/checkout/complete'; } } } function uc_cart_checkout_complete() { if (!$_SESSION['do_complete']) { drupal_goto('cart'); } $order = uc_order_load(intval($_SESSION['cart_order'])); $output = uc_cart_complete_sale($order); // Add a comment to let sales team know this came in through the site. uc_order_comment_save($order->order_id, 0, t('Order created through website.'), 'admin'); $page = variable_get('uc_cart_checkout_complete_page', ''); if (!empty($page)) { drupal_goto(variable_get('uc_cart_checkout_complete_page', '')); } return $output; } /******************************************************************************* * Module and Helper Functions ******************************************************************************/ /** * Completes a sale, including adjusting order status and creating user account. * * @param $order * The order object that has just been completed. * @return * The HTML text of the default order completion page. */ function uc_cart_complete_sale($order) { // Logic to create new user if necessary: if ($order->uid == 0) { $result = db_query("SELECT uid FROM {users} WHERE mail = '%s'", $order->primary_email); if ($user = db_fetch_object($result)) { $order->uid = $user->uid; db_query("UPDATE {uc_orders} SET uid = %d WHERE order_id = %d", $order->uid, $order->order_id); $message_type = 'existing_user'; } else { $fields = array( 'name' => empty($order->data['new_user']['name']) ? $order->primary_email : $order->data['new_user']['name'], 'mail' => $order->primary_email, 'init' => $order->primary_email, 'pass' => empty($order->data['new_user']['pass']) ? user_password(variable_get('uc_pwd_length', 6)) : $order->data['new_user']['pass'], 'roles' => array(), 'status' => variable_get('uc_new_customer_status_active', TRUE) ? 1 : 0, ); $account = user_save('', $fields); if (variable_get('uc_new_customer_email', TRUE)) { $variables = array('!username' => $fields['name'], '!site' => variable_get('site_name', 'Drupal'), '!password' => $fields['pass'], '!uri' => $base_url, '!uri_brief' => substr($base_url, strlen('http://')), '!mailto' => $fields['mail'], '!date' => format_date(time()), '!login_uri' => url('user', NULL, NULL, TRUE), '!edit_uri' => url('user/'. $account->uid .'/edit', NULL, NULL, TRUE), '!login_url' => user_pass_reset_url($account)); $from = variable_get('uc_store_email_from', ini_get('sendmail_from')); $subject = _user_mail_text('welcome_subject', $variables); $body = _user_mail_text('welcome_body', $variables); drupal_mail('user-register-welcome', $order->primary_email, $subject, $body, $from); } $order->uid = $account->uid; $_SESSION['new_user'] = array('name' => $fields['name'], 'pass' => $fields['pass']); db_query("UPDATE {uc_orders} SET uid = %d WHERE order_id = %d", $order->uid, $order->order_id); $message_type = 'new_user'; } } else { $message_type = 'logged_in'; } $output = check_markup(variable_get('uc_msg_order_submit', uc_get_message('completion_message')), variable_get('uc_msg_order_submit_format', 3), FALSE); $show_message = check_markup(variable_get('uc_msg_order_'. $message_type, uc_get_message('completion_'. $message_type)), variable_get('uc_msg_order_'. $message_type .'_format', 3), FALSE); if ($show_message != '') { $variables['!new_username'] = check_plain($_SESSION['new_user']['name']); $variables['!new_password'] = check_plain($_SESSION['new_user']['pass']); $output .= '

'. strtr($show_message, $variables) .'

'; } $output .= '

'. check_markup(variable_get('uc_msg_continue_shopping', uc_get_message('continue_shopping')), variable_get('uc_msg_order_submit_format', 3), FALSE) .'

'; $output = token_replace_multiple($output, array('global' => NULL, 'order' => $order)); // Move an order's status from "In Checkout" to "Pending" $status = db_result(db_query("SELECT order_status FROM {uc_orders} WHERE order_id = %d", $order->order_id)); if (uc_order_status_data($status, 'state') == 'in_checkout') { uc_order_update_status($order->order_id, uc_order_state_default('post_checkout')); } // Empty that cart... uc_cart_empty(uc_cart_get_id()); // Clear our the session variables used to force the cart workflow. unset($_SESSION['cart_order'], $_SESSION['do_complete'], $_SESSION['new_user']); global $user; workflow_ng_invoke_event('checkout_complete', $order, $user); return $output; } /** * Return the unique cart_id of the user, sid for anonymous and uid for logged in users. */ function uc_cart_get_id() { global $user; if ($user->uid) { return $user->uid; } elseif ($sid = session_id()) { return $sid; } // What to do if neither of these work? -RS } /** * Grab the items in a shopping cart for a user. * * If $cid is not passed in, this function uses the uid of the person currently * accessing this function. */ function uc_cart_get_contents($cid = NULL, $action = NULL) { static $items = array(); $cid = $cid ? $cid : uc_cart_get_id(); if ($action == 'rebuild') { $items = array(); } if (!isset($items[$cid])) { $items[$cid] = array(); $result = db_query("SELECT c.*, n.title, n.vid FROM {node} n INNER JOIN {uc_cart_products} c ON n.nid = c.nid WHERE c.cart_id = '%s'", $cid); while ($item = db_fetch_object($result)) { for ($i = 0; $i < count($items[$cid]); $i++) { if ($items[$cid][$i]->nid == $item->nid && $items[$cid][$i]->data == $item->data) { $items[$cid][$i]->qty += $item->qty; continue 2; } } $product = node_load($item->nid); $item->cost = $product->cost; $item->price = $product->sell_price; $item->weight = $product->weight; $item->data = unserialize($item->data); $item->module = $item->data['module']; $item->options = array(); $item->model = $product->model; // Invoke hook_cart_item() with $op = 'load' in enabled modules. foreach (module_implements('cart_item') as $module) { $func = $module .'_cart_item'; $func('load', $item); } $items[$cid][] = $item; } } return $items[$cid]; } /** * Adds an item to a user's cart. */ function uc_cart_add_item($nid, $qty = 1, $data = NULL, $cid = NULL, $msg = TRUE, $check_redirect = TRUE) { if (isset($_SESSION['cart_order'])) { unset($_SESSION['cart_order']); } $cid = $cid ? $cid : uc_cart_get_id(); $node = node_load($nid); if (is_null($data)) { $data = array('module' => 'uc_product'); } if (!in_array($node->type, array_keys(uc_product_node_info()))) { drupal_set_message(t('!title is not a product. Unable to add to cart.', array('!title' => $node->title)), 'error'); return; } $result = module_invoke_all('add_to_cart', $nid, $qty, $data); if (is_array($result) && !empty($result)) { foreach ($result as $row) { if ($row['success'] === FALSE) { if (isset($row['message']) && !empty($row['message'])) { $message = $row['message']; } else { $message = t('Sorry, that item is not available for purchase at this time.'); } if ($row['silent'] === TRUE) { if ($check_redirect) { if (isset($_GET['destination'])) { drupal_goto(); } $redirect = variable_get('uc_add_item_redirect', 'cart'); if ($redirect != '') { $_SESSION['last_url'] = referer_uri(); return $redirect; } else { return referer_uri(); } } } else{ drupal_set_message($message, 'error'); } return; } } } $item = db_fetch_object(db_query("SELECT * FROM {uc_cart_products} WHERE cart_id = '%s' AND nid = %d AND data = '%s'", $cid, $node->nid, serialize($data))); // If the item isn't in the cart yet, add it. if (is_null($item) || $item === FALSE) { db_query("INSERT INTO {uc_cart_products} (cart_id, nid, qty, changed, data) VALUES ('%s', %d, %d, %d, '%s')", $cid, $node->nid, $qty, time(), serialize($data)); if ($msg) { drupal_set_message(t('!product-title added to your shopping cart.', array('!product-title' => $node->title, '!url' => url('cart')))); } } else { // Update the item instead. if ($msg) { drupal_set_message(t('Your item(s) have been updated.')); } $qty += $item->qty; module_invoke($data['module'], 'update_cart_item', $node->nid, $data, min($qty, 999999), $cid); } cache_clear_all(); if ($check_redirect) { if (isset($_GET['destination'])) { drupal_goto(); } $redirect = variable_get('uc_add_item_redirect', 'cart'); if ($redirect != '') { $_SESSION['last_url'] = referer_uri(); return $redirect; } else { return referer_uri(); } } } /** * Remove an item from the cart */ function uc_cart_remove_item($nid, $cid = NULL, $data = array()) { if (empty($nid)) { return; } $cart_id = !(is_null($cid) || empty($cid)) ? $cid : uc_cart_get_id(); db_query("DELETE FROM {uc_cart_products} WHERE cart_id = '%s' AND nid = %d AND data = '%s'", $cart_id, $nid, serialize($data)); cache_clear_all(); } /** * Updates the quantity of all the items in a cart object */ function uc_cart_update_item_object($cart) { if (is_object($cart)) { foreach ($cart->items as $item){ if ($item['remove']) { module_invoke($item['module'], 'update_cart_item', $item['nid'], unserialize($item['data']), 0); } else { module_invoke($item['module'], 'update_cart_item', $item['nid'], unserialize($item['data']), $item['qty']); } } } } /** * Empties a cart of its contents. */ function uc_cart_empty($cart_id) { if (is_null($cart_id) || empty($cart_id)) { return; } db_query("DELETE FROM {uc_cart_products} WHERE cart_id = '%s'", $cart_id); } function uc_cart_cart_pane_list($items, $action = NULL) { static $panes; if (count($panes) > 0 && $action !== 'rebuild') { return $panes; } $panes = module_invoke_all('cart_pane', $items); if (!is_array($panes) || count($panes) == 0) { return array(); } for ($i = 0; $i < count($panes); $i++) { $panes[$i]['enabled'] = variable_get('uc_cap_'. $panes[$i]['id'] .'_enabled', (!isset($panes[$i]['enabled']) ? TRUE : $panes[$i]['enabled'])); $panes[$i]['weight'] = variable_get('uc_cap_'. $panes[$i]['id'] .'_weight', (!isset($panes[$i]['weight']) ? 0 : $panes[$i]['weight'])); } usort($panes, 'uc_weight_sort'); return $panes; } // Returns TRUE or FALSE for whether a cart contains shippable items or not. function uc_cart_is_shippable($cart_id = NULL, $action = '') { static $shippable; if ($action != 'refresh' && ($shippable === FALSE || $shippable === TRUE)) { return $shippable; } $shippable = FALSE; $items = uc_cart_get_contents($cart_id); // Return FALSE if the cart is empty! if (empty($items)) { return FALSE; } foreach ($items as $item) { $result[] = uc_cart_product_is_shippable($item); } // Return TRUE if any product in the cart is shippable. if (in_array(TRUE, $result)) { $shippable = TRUE; return TRUE; } return FALSE; } // Return TRUE or FALSE for whether a product is shippable or not. function uc_cart_product_is_shippable($product) { // Return FALSE if the product form specifies this as not shippable. if ($product->data['shippable'] == FALSE) { return FALSE; } // See if any other modules have a say in the matter... $result = module_invoke_all('cart_item', 'can_ship', $product); // Return TRUE by default. if (empty($result) || in_array(TRUE, $result)) { return TRUE; } return FALSE; } // Returns a checkout pane array with panes filtered out that have key values // matching the combinations in the $remove array. function uc_cart_filter_checkout_panes($panes, $remove = NULL) { if (is_array($remove)) { for ($i = 0; $i < count($panes); $i++) { foreach ($remove as $key => $value) { if ($panes[$i][$key] == $value) { unset($panes[$i]); } } } } return $panes; }