function uc_order_pane_line_items in Ubercart 5
Same name and namespace in other branches
- 6.2 uc_order/uc_order.order_pane.inc \uc_order_pane_line_items()
- 7.3 uc_order/uc_order.order_pane.inc \uc_order_pane_line_items()
Handle the "Line Items" order pane.
1 call to uc_order_pane_line_items()
- uc_paypal_ec_submit in payment/
uc_paypal/ uc_paypal.module
1 string reference to 'uc_order_pane_line_items'
- uc_order_order_pane in uc_order/
uc_order.module - Implementation of hook_order_pane().
File
- uc_order/
uc_order_order_pane.inc, line 315 - This file contains the callbacks for the default order panes supplied with Ubercart and their corresponding helper functions.
Code
function uc_order_pane_line_items($op, $arg1) {
switch ($op) {
case 'view':
case 'customer':
$line_items = $arg1->line_items;
$items = _line_item_list();
foreach ($items as $item) {
if (isset($item['display_only']) && $item['display_only'] == TRUE) {
$result = $item['callback']('display', $arg1);
if (is_array($result)) {
foreach ($result as $line) {
$line_items[] = array(
'title' => $line['title'],
'amount' => $line['amount'],
'weight' => $item['weight'],
);
}
}
}
}
usort($line_items, 'uc_weight_sort');
$output = '<table class="line-item-table">';
foreach ($line_items as $item) {
$output .= '<tr><td class="li-title">' . check_plain($item['title']) . ':</td>' . '<td class="li-amount" nowrap="nowrap">' . uc_currency_format($item['amount']) . '</td></tr>';
}
$output .= '</table>';
return $output;
case 'show-title':
return FALSE;
case 'edit-form':
$options = array();
$items = _line_item_list();
$line_items = $arg1->line_items;
foreach ($items as $item) {
if ($item['add_list'] === TRUE) {
$options[$item['id']] = check_plain($item['title']);
}
if (isset($item['display_only']) && $item['display_only'] == TRUE) {
$result = $item['callback']('display', $arg1);
if (is_array($result)) {
foreach ($result as $line) {
$line_items[] = array(
'line_item_id' => $line['id'],
'title' => $line['title'],
'amount' => $line['amount'],
'weight' => $item['weight'],
);
}
}
}
}
usort($line_items, 'uc_weight_sort');
$form['add_line_item'] = array(
'#type' => 'fieldset',
'#title' => t('Add line item'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['add_line_item']['li_type_select'] = array(
'#type' => 'select',
'#title' => t('Select a type'),
'#options' => $options,
);
$form['add_line_item']['submit'] = array(
'#type' => 'submit',
'#value' => t('Add line'),
'#attributes' => array(
'class' => 'save-button',
),
'#disabled' => TRUE,
);
$form['li_delete_id'] = array(
'#type' => 'hidden',
);
$form['line_items'] = array(
'#type' => 'fieldset',
'#title' => t("Modify 'line items'"),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#tree' => TRUE,
);
foreach ($line_items as $item) {
$form['line_items'][$item['line_item_id']]['li_id'] = array(
'#type' => 'hidden',
'#value' => $item['line_item_id'],
);
if (_line_item_data($item['type'], 'stored') == TRUE) {
$form['line_items'][$item['line_item_id']]['title'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#default_value' => $item['title'],
'#size' => 40,
'#maxlength' => 128,
'#prefix' => '<img id="li-' . $item['line_item_id'] . '" src="' . base_path() . drupal_get_path('module', 'uc_store') . '/images/error.gif" alt="' . t('Remove line item.') . '" title="' . t('Remove line item.') . '" style="' . 'cursor: pointer; position: relative; top: 3px;" ' . 'onclick="confirm_line_item_delete(\'' . addslashes(t('Remove this line item?')) . '\', this.id);" />',
);
$form['line_items'][$item['line_item_id']]['amount'] = array(
'#type' => 'textfield',
'#title' => t('Amount'),
'#default_value' => $item['amount'],
'#size' => 6,
'#maxlength' => 13,
'#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', '$') : '',
);
}
else {
$form['line_items'][$item['line_item_id']]['title'] = array(
'#value' => check_plain($item['title']),
);
$form['line_items'][$item['line_item_id']]['amount'] = array(
'#value' => uc_currency_format($item['amount']),
);
}
}
return $form;
case 'edit-theme':
$arg1['add_line_item']['li_type_select']['#title'] = '';
$output = '<table class="full-width"><tr><td>';
$output .= '<table><tr><td colspan="2"><b>' . t('Add a line item') . ': </b></td></tr><tr><td>' . drupal_render($arg1['add_line_item']['li_type_select']) . ' </td><td>' . drupal_render($arg1['add_line_item']['submit']) . '</td></tr></table>';
$output .= '</td><td>' . drupal_render($arg1['li_delete_id']) . '<table class="line-item-table">';
foreach (element_children($arg1['line_items']) as $field) {
$arg1['line_items'][$field]['title']['#title'] = '';
$arg1['line_items'][$field]['amount']['#title'] = '';
$output .= '<tr><td class="li-title">' . drupal_render($arg1['line_items'][$field]['li_id']) . drupal_render($arg1['line_items'][$field]['title']) . ':</td><td class="li-amount" nowrap>' . drupal_render($arg1['line_items'][$field]['amount']) . '</td></tr>';
}
$output .= '</table></td></tr></table>';
return $output;
case 'edit-process':
if (is_array($arg1['line_items'])) {
foreach ($arg1['line_items'] as $line) {
if (is_numeric($line['li_id']) && intval($line['li_id']) > 0) {
uc_order_update_line_item($line['li_id'], $line['title'], $line['amount']);
}
}
}
if (intval($arg1['li_delete_id']) > 0) {
uc_order_delete_line_item($arg1['li_delete_id']);
drupal_set_message(t('Line item removed.'));
}
return;
case 'edit-ops':
return array(
t('Add line'),
);
case t('Add line'):
drupal_goto('admin/store/orders/' . $arg1['order_id'] . '/add_line_item/' . $arg1['li_type_select']);
}
}