You are here

function uc_line_item_subtotal in Ubercart 6.2

Same name and namespace in other branches
  1. 5 uc_order/uc_order_line_item.inc \uc_line_item_subtotal()
  2. 7.3 uc_order/uc_order.line_item.inc \uc_line_item_subtotal()

Handles the subtotal line item.

1 string reference to 'uc_line_item_subtotal'
uc_order_line_item in uc_order/uc_order.module
Implements hook_line_item().

File

uc_order/uc_order.line_item.inc, line 16
This file contains the callbacks for the default line items for orders and the various functions that make line items work.

Code

function uc_line_item_subtotal($op, $arg1) {
  switch ($op) {
    case 'load':
      $lines[] = array(
        'id' => 'subtotal',
        'title' => t('Subtotal'),
        'amount' => uc_order_get_total($arg1, TRUE),
      );
      return $lines;
    case 'cart-preview':
      if (module_exists('uc_payment') && variable_get('uc_pane_payment_enabled', TRUE)) {
        $context = array(
          'revision' => 'altered',
          'type' => 'cart_item',
        );
        $subtotal = 0;
        foreach ($arg1 as $item) {
          $price_info = array(
            'price' => $item->price,
            'qty' => $item->qty ? $item->qty : 1,
          );
          $context['subject'] = array(
            'cart_item' => $item,
            'node' => node_load($item->nid),
          );
          $total = uc_price($price_info, $context);
          $subtotal += $total;
        }
        $line_item = array(
          'type' => 'subtotal',
          'name' => t('Subtotal'),
          'amount' => $subtotal,
          'weight' => -10,
        );
        $order = new stdClass();
        $order->products = $arg1;
        $context = array(
          'revision' => 'altered',
          'type' => 'line_item',
          'subject' => array(
            'order' => $order,
            'line_item' => $line_item,
          ),
        );
        drupal_add_js("if (Drupal.jsEnabled) { \$(document).ready( function() { set_line_item('subtotal', '" . $line_item['name'] . "', " . uc_price($line_item['amount'], $context) . ", " . $line_item['weight'] . "); } )};", 'inline');
      }
      break;
  }
}