| '. $item->qty .'x | ' . ''. l($item->title, 'node/'. $item->nid) .' | ' . ''. uc_currency_format($item->price) .' |
| '. $display_item['options']['#value'] .' | ||
'. t('There are no products in your shopping cart.') .'
'; } $output .= ''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 .= '';
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 .= '
| '. $item->qty .'x | ' . ''. l($item->title, 'node/'. $item->nid) .' | ' . ''. uc_currency_format($item->price) .' |
| '. $display_item['options']['#value'] .' | ||
'. t('There are no products in your shopping cart.') .'
'; } $output .= '| ' . $item_text .' | ' .''. t('Total:') .' '. uc_currency_format($total) .' |
| '. $view . $checkout .' | |
'. 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 '
. 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. '. t('There are no products in your shopping cart.') . ' '. strtr($show_message, $variables) .' '. check_markup(variable_get('uc_msg_continue_shopping', uc_get_message('continue_shopping')),
variable_get('uc_msg_order_submit_format', 3),
FALSE) .'
Password: !new_password');
$messages['continue_shopping'] = l(t('Click to return to the front page.'), '
!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)))),
//
!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.') .'
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', '$') : '',
);
//
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', '
';
$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');
}
//';
foreach ($panes as $title => $data) {
$output .= '
';
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 .= ' ';
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 .= ''. $title
.' ';
}
else {
$output .= ''. $row['title'] .': '
. $row['data'] .' ';
}
}
}
else {
$output .= ''. $row .' ';
}
}
$output .= ''. $data .' '. $form
.'