--- uc_recurring_order.module 2010-03-27 20:58:42.000000000 -0500 +++ NEWuc_recurring_order.module 2010-03-27 18:52:00.000000000 -0500 @@ -19,7 +19,7 @@ function uc_recurring_order_menu() { 'title' => 'Recurring orders', 'description' => 'Edit recurring order information.', 'page callback' => 'drupal_get_form', - 'page arguments' => array('uc_recurring_order_form'), + 'page arguments' => array('uc_recurring_order_settings_form'), 'access arguments' => array('administer store'), 'type' => MENU_LOCAL_TASK, 'weight' => 0, @@ -28,6 +28,64 @@ function uc_recurring_order_menu() { } /** + * Settings for recurring orders + */ + +function uc_recurring_order_settings_form($form_state) { + drupal_set_title(t('Recurring Order Settings')); + $intoptions = _uc_recurring_order_recurring_options(); + $form['pane_settings'] = array( + '#type' => 'fieldset', + '#title' => t('Pane Text Settings'), + '#collapsible' => TRUE, + ); + $form['pane_settings']['uc_recurring_order_pane_description'] = array( + '#type' => 'textarea', + '#title' => t('Checkout pane message'), + '#default_value' => t(variable_get('uc_recurring_pane_description', 'Select to have this order automatically.')), + ); + $form['pane_settings']['uc_recurring_order_pane_title'] = array( + '#type' => 'textfield', + '#title' => t('Checkout and Review Pane Title'), + '#default_value' => t(variable_get('uc_recurring_order_pane_title', 'Recurring Order')), + ); + $form['pane_settings']['uc_recurring_order_pane_empty'] = array( + '#type' => 'textarea', + '#title' => t('No Recurring Order Text'), + '#description' => t('Text to display on the order review page if customer has not signed up for a recurring order.'), + '#default_value' => t(variable_get('uc_recurring_order_pane_empty', 'This order will not repeat.')), + ); + $form['interval_options'] = array( + '#type' => 'select', + '#multiple' => TRUE, + '#options' => $intoptions, + '#default_value' => variable_get('uc_recurring_order_interval_options', $intoptions), + '#title' => t('Available Recurring Interval Options'), + ); + + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Save'), + ); + + return $form; +} + + + +function uc_recurring_order_settings_form_submit($form, &$form_state) { + $intervals = array(); + foreach ($form_state['values']['interval_options'] as $int => $option) { + $intervals[check_plain($option)] = check_plain($option); + } + variable_set('uc_recurring_order_interval_options', $intervals); + variable_set('uc_recurring_pane_description', check_plain($form_state['values']['uc_recurring_order_pane_description'])); + variable_set('uc_recurring_order_pane_title', check_plain($form_state['values']['uc_recurring_order_pane_title'])); + variable_set('uc_recurring_order_pane_empty', check_plain($form_state['values']['uc_recurring_order_pane_empty'])); +} + + +/** * Implementation of hook_cart_pane(). */ function uc_recurring_order_cart_pane($items) { @@ -46,11 +104,19 @@ function uc_recurring_order_cart_pane($i * Cart pane recurring form. */ function uc_recurring_order_pane_cart($form_state) { + $options = array(); + $intervals = variable_get('uc_recurring_order_interval_options', _uc_recurring_order_recurring_options()); + $values = _uc_recurring_order_recurring_options(); + foreach ($intervals as $int => $option) { + $options[$option] = $values[$option]; + } + $form['recurring_option'] = array( '#type' => 'select', - '#title' => t('Recurring order'), - '#description' => t('Select to have this order automatically.'), - '#options' => _uc_recurring_order_recurring_options(), + '#title' => t(variable_get('uc_recurring_order_pane_title', 'Recurring Order')), + '#description' => t(variable_get('uc_recurring_pane_description', 'Select to have this order automatically repeat,')), + '#options' => $options, + '#default_value' => $_SESSION['recurring_option'], ); $form['apply'] = array( '#type' => 'submit', @@ -62,11 +128,11 @@ function uc_recurring_order_pane_cart($f function uc_recurring_order_pane_cart_submit($form, &$form_state) { if ($form_state['values']['recurring_option']) { $recurring_options = _uc_recurring_order_recurring_options(); - $recurring = $form_state['values']['recurring_option']; - $next_renewal = strtotime('+'. $recurring); + $recurring_option = check_plain($form_state['values']['recurring_option']); + $next_renewal = strtotime('+'. $recurring_option); if ($next_renewal > 0) { $_SESSION['recurring_option'] = $recurring_option; - drupal_set_message(t('@recurring. Your next order after this will occur on @next.', array('@recurring' => $recurring_options[$recurring], '@next' => format_date($next_renewal, 'short')))); + drupal_set_message(t('Your next order after this will occur on @next.', array('@recurring' => $recurring_options[$recurring], '@next' => format_date($next_renewal, 'short')))); } else { unset($_SESSION['uc_recurring_order']); @@ -75,12 +141,15 @@ function uc_recurring_order_pane_cart_su } /** - * + * Default options */ function _uc_recurring_order_recurring_options() { return array( - '' => t('Single order (not recurring)'), + '0 months' => t('Single order (not recurring)'), '1 months' => t('Monthly order'), + '3 months' => t('Every Three Months'), + '6 months' => t('Every 6 Months'), + '12 months' => t('Once a year'), ); } @@ -111,9 +180,14 @@ function uc_recurring_order_checkout_pan function uc_recurring_order_pane_checkout($op, &$arg1, $arg2) { switch ($op) { case 'view': - drupal_add_js(drupal_get_path('module', 'uc_recurring_order') .'/uc_recurring_order.js'); - - // Use coupon code from cart pane if available. + $options = array(); + $intervals = variable_get('uc_recurring_order_interval_options', _uc_recurring_order_recurring_options()); + $values = _uc_recurring_order_recurring_options(); + foreach ($intervals as $int => $option) { + $options[$option] = $values[$option]; + } + + // Use recurring order info from cart pane if available. if ($_SESSION['recurring_option']) { $recurring = $_SESSION['recurring_option']; unset($_SESSION['recurring_option']); @@ -125,9 +199,9 @@ function uc_recurring_order_pane_checkou $description = t('Select to have this order automatically.'); $contents['recurring_option'] = array( '#type' => 'select', - '#title' => t('Recurring order'), + '#title' => t(variable_get('uc_recurring_order_pane_title', 'Recurring Order')), '#default_value' => $recurring, - '#options' => _uc_recurring_order_recurring_options(), + '#options' => $options, ); return array('description' => $description, 'contents' => $contents); @@ -136,30 +210,33 @@ function uc_recurring_order_pane_checkou if (($products = uc_recurring_get_recurring_products_in_order($order))) { unset($_SESSION['uc_recurring_order']); drupal_set_message(t('Unable to create recurring order when it contains recurring products'), 'warning'); - //return TRUE; + return FALSE; } if ($arg2['recurring_option']) { $recurring_options = _uc_recurring_order_recurring_options(); - $recuring = $arg2['recurring_option']; + $recurring = check_plain($arg2['recurring_option']); $next_renewal = strtotime('+'. $recurring); if ($next_renewal > 0) { - $_SESSION['recurring_option'] = $recurring_option; - drupal_set_message(t('@recurring. Your next order after this will occur on @next.', array('@recurring' => $recurring_options[$recurring], '@next' => format_date($next_renewal, 'short')))); + $arg1->data['recurring_option'] = $recurring; } else { - unset($_SESSION['uc_recurring_order']); + unset($_SESSION['recurring']); } } + dsm($arg1); return TRUE; - - case 'settings': - $form['uc_recurring_order_pane_description'] = array( - '#type' => 'textarea', - '#title' => t('Checkout pane message'), - '#default_value' => variable_get('uc_recurring_pane_description', 'Select to have this order automatically.'), - ); - return $form; + + + case 'review': + if ($arg1->data['recurring_option']) { + $next_renewal = strtotime('+'. $arg1->data['recurring_option']); + $review[] = array('title' =>t(variable_get('uc_recurring_order_pane_title', 'Recurring Order')), 'data' =>t('Your next order after this will occur on @next.', array('@recurring' => $arg1->data['recurring_option'], '@next' => format_date($next_renewal, 'short')))); + } + else { + $review[] = array('title' =>t(variable_get('uc_recurring_order_pane_title', 'Recurring Order')), 'data' => t(variable_get('uc_recurring_order_pane_empty', 'This order will not repeat.'))); + } + return $review; } } @@ -170,14 +247,20 @@ function uc_recurring_order_order($op, & switch ($op) { // TODO: Allow admin to create a recurring order from "create order" page. case 'submit': - $recurring = $_SESSION['recurring_option']; + $recurring = $arg1->data['recurring_option']; $next_renewal = strtotime('+'. $recurring); if ($next_renewal > 0 && variable_get('uc_recurring_checkout_process', TRUE)) { - if (uc_recurring_order_process_order($arg1) === FALSE) { + if (uc_recurring_order_process_order($arg1, $recurring) === FALSE) { return array(array('pass' => FALSE, 'message' => t('Your order cannot be completed, because we could not process your recurring payment. Please review your payment details and contact us to complete your order if the problem persists.'))); } } break; + case 'save': + db_query("UPDATE {uc_recurring_users} SET fee_amount = %f WHERE order_id = %d", uc_order_get_total($arg1), $arg1->order_id); + if (db_affected_rows !== 0) { + uc_order_comment_save($arg1->order_id, 0, t('The recurring order amount was updated.'), 'admin'); + } + break; } } @@ -250,6 +333,10 @@ function uc_recurring_order_recurring_re // recreate order if (!empty($fee->data['uc_recurring_order'])) { $order->products = $fee->data['uc_recurring_order']['products']; + $result = db_query("SELECT * FROM {uc_order_line_items} WHERE order_id = %d", $fee->order_id); + while ($line_item = db_fetch_array($result)) { + uc_order_line_item_add($order->order_id, $line_item['type'], $line_item['title'], $line_item['amount'], $line_item['weight'], $line_item['data']); + } } }