You are here

function uc_order_pane_products in Ubercart 7.3

Same name and namespace in other branches
  1. 5 uc_order/uc_order_order_pane.inc \uc_order_pane_products()
  2. 6.2 uc_order/uc_order.order_pane.inc \uc_order_pane_products()

Handles the "Products" order pane.

1 string reference to 'uc_order_pane_products'
uc_order_uc_order_pane in uc_order/uc_order.module
Implements hook_uc_order_pane().

File

uc_order/uc_order.order_pane.inc, line 184
This file contains the callbacks for the default order panes supplied with Ubercart and their corresponding helper functions.

Code

function uc_order_pane_products($op, $order, &$form = NULL, &$form_state = NULL) {
  switch ($op) {
    case 'view':
      return tapir_get_table('uc_op_products_view_table', $order);
    case 'customer':
      return tapir_get_table('uc_op_products_customer_table', $order);
    case 'edit-form':
      $form['add_product_button'] = array(
        '#type' => 'submit',
        '#value' => t('Add product'),
        '#submit' => array(
          'uc_order_pane_products_select',
        ),
        '#ajax' => array(
          'callback' => 'uc_order_pane_products_ajax_callback',
          'wrapper' => 'product-controls',
        ),
      );
      $form['add_blank_line_button'] = array(
        '#type' => 'submit',
        '#value' => t('Add blank line'),
        '#submit' => array(
          'uc_order_edit_products_add_blank',
        ),
        '#ajax' => array(
          'callback' => 'uc_order_pane_products_ajax_callback',
          'wrapper' => 'product-controls',
        ),
      );
      $form['product_controls'] = array(
        '#tree' => TRUE,
        '#prefix' => '<div id="product-controls">',
        '#suffix' => '</div>',
      );
      $controls = array();
      if (isset($form_state['products_action'])) {
        switch ($form_state['products_action']) {
          case 'select':
            $controls = uc_order_product_select_form($form['product_controls'], $form_state, $order);
            break;
          case 'add_product':
            $controls = uc_order_add_product_form($form['product_controls'], $form_state, $order, $form_state['node']);
            break;
        }
      }
      $form['product_controls'] += $controls;
      $form += uc_order_edit_products_form($form, $form_state, $order->products);
      return $form;
    case 'edit-theme':
      $output = drupal_render($form['add_product_button']);
      $output .= drupal_render($form['add_blank_line_button']);
      $output .= drupal_render($form['product_controls']);
      $output .= drupal_render($form['products']);
      return $output;
    case 'edit-process':
      if (isset($form_state['values']['products'])) {
        foreach ($form_state['values']['products'] as $key => $product) {
          $product['data'] = unserialize($product['data']);
          uc_order_product_save($order->order_id, (object) $product);
        }
      }
      break;
  }
}