Drupal 7, Ubercart 3 Custom Checkout Pane $order not setting the variable

StackOverflow https://stackoverflow.com/questions/12917508

  •  07-07-2021
  •  | 
  •  

سؤال

//create anew schedule pane at checkout
function uc_pizza_uc_checkout_pane() {
  $panes[] = array(
    'id' => 'schedule',
    'callback' => 'uc_checkout_pane_schedule',
    'title' => t('Pickup/Delivery Date & Time'),
    'desc' => t("Show Pickup/Delivery Date & Time Pane"),
    'weight' => 1,
    'process' => TRUE,
    'collapsible' => FALSE,
  );
  return $panes;
}




function uc_checkout_pane_schedule($op, $order, $form = NULL, &$form_state = NULL) {
  require_once(drupal_get_path('module', 'uc_cart') . '/uc_cart_checkout_pane.inc');

  switch($op) {
    case 'view':  //create a date-popup field and a separate field for time.
        $format = 'Y-m-d';

        if(isset($_REQUEST['panes']['schedule']['date']['date'])) {
            $date = $_REQUEST['panes']['schedule']['date']['date'];
        } else {
            $date = date($format);
        }

        $descriptions = t("NOTE: You may schedule your pizza pickup or delivery below. The shop is only open from 5pm until 11pm, you may still place your order beyond store hours but it will be delivered the next working hour or your required schedule.");
        $contents ['sched_date'] = array(
           '#type' => 'date_popup', 
           '#title' => t('select a date'),
           '#default_value' => $date, 
           '#date_format' => $format,
           '#datepicker_options' => array('minDate' => 'today', 'maxDate' => variable_get("uc_pizza_max_days", '+6 days')),
           '#date_label_position' => 'within', 
           '#date_increment' => 15, 
           '#date_year_range' => '-0:+0', 
        );

        $base_hour= 5;  
        for($i=0; $i<25; $i++) {     
           $mins = str_pad((int) (($i % 4) * 15),2,"0",STR_PAD_LEFT);
           $hour = str_pad((int) $base_hour,2,"0",STR_PAD_LEFT);
           $options_time[$hour.$mins] =  t($hour . ":" . $mins . " PM"); 
           if($mins == 45) {
              $base_hour++;
           }
        }

       if(isset($_REQUEST['panes']['schedule']['time'])) {
          $default_option = $_REQUEST['panes']['schedule']['time'];
       } else {
          $default_option = 0000;
       }

       $contents['sched_time'] = array(
            '#type' => 'select',
            '#title' => 'Time',
            '#options' => $options_time,
            '#default_value' => $default_option,
        );
        return array('description' => $descriptions, 'contents' => $contents);
    break;

    case 'prepare':
    break;

    case 'review': //**/THIS IS WHERE THE PROBLEM IS** please check process
            dprint_r("order: ", $order); // only var with data
            dprint_r("form: ", $form);  //no data
            dprint_r("form_state: ", $form_state); //no data 
      //$sched_date = $arg1->schedule_date;
      //$sched_time = $arg1->schedule_time;
      //$review[] = '<div class="giftwrap">' . t('You want @type as gift wrap medium', array('@type' => $gift_wrap_type)) . '</div>';    
      //$review[] = array('title' => t('Schedule'), 'data' => check_plain("$sched_date @ $sched_time"));
      //return $review;
    break;

    case 'process': 
//here in process i put the var to $order->schedule_date but unable to see it in $order at view
      $order->schedule_date = $form_state['panes']['schedule']['sched_date']['#value']['date'];
      $order->schedule_time = $form_state['panes']['schedule']['sched_time']['#value'];
      return TRUE;
    break;

    case 'settings':
          $max_days = variable_get("uc_pizza_max_days", '+6 days');
          variable_set("uc_pizza_max_days", $max_days);
          $contents['max_days'] = array(
            '#type' => 'textfield',
            '#title' => t('Calendar Max Days Limit'),
            '#default_value' => $max_days,
            '#maxlength' => 60,
            '#size' => 32,
          );
        return $contents;
    break;

  }
}

I'm trying to add a pane to checkout process of ubercart, $op = view and settings works perfect.

I have problem with review i tried setting the variable at $op=process but i cannot find it in $op=review

tried this in process

  $order->schedule_date = $form_state['panes']['schedule']['sched_date']['#value']['date'];
  $order->schedule_time = $form_state['panes']['schedule']['sched_time']['#value'];

but

in review it seems $order->schedule_date and $order->schedule_time is not in $order;

Can anyone help out what im missing please... this is in D7

هل كانت مفيدة؟

المحلول

Use $order->data instead of trying to apply your custom settings directly to $order. Try this under 'process'

case 'process':
  // display arrays for devel testing
  dpm($form);
  dpm($order);

  // use $order->data to store your submission data
  $order->data['schedule_time'] = $form['panes']['schedule']['sched_time']['#value'];
  break;

Then use $order under 'review' to get the data you need.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top