Hi,
Are there any thorough tutorials out there on how to use line items in Übercart 2-6.x? I have found a few, but none of them really explain what is going on and what needs to happen for certain things to occur. For example, my issue is that I need to get a variable that is in my cart-preview case for the line item to also appear in the order pane and the invoice. The line item itself is there, but it doesn't show any cost. I'm sure I've just gone slightly off somewhere and if someone could help, that would be great. I tried to use:

    case 'load':
      $lines[] = array(
        'id' => 'fastpris',
        'title' => t('Fast pris'),
        'amount' => uc_fastpris_get_cost($arg1),
        );
        return $lines;

and then:

function uc_fastpris_get_cost($arg1){
  $fptotal = 0;
  foreach ($arg1->items as $item) {
    $arg1->type = node_load($item->nid)->type;
    if($item->type == 'fast_pris_items'){
      $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);
      $fptotal += $total;
    }
  }
  return $fptotal;

  $order = new stdClass();
  $order->products = $arg1;

  $context = array(
    'revision' => 'altered',
    'type' => 'line_item',
    'subject' => array(
      'order' => $order,
      'line_item' => $line_item,
    ),
  );
}

But there is no value in the order pane for the line item Fast Pris.

Comments

longwave’s picture

Title: Line item tutorial/Passing line item variable to order invoice & pane » Improve line item API documentation
Component: Code » Documentation
Category: support » task

You can look at the source of the uc_quote or uc_coupon modules, which both provide dynamic line items. Better documentation is needed, though, especially regarding the differences between "calculated", "stored" and "display only" line item types.

TR’s picture

Version: 6.x-2.6 » 6.x-2.x-dev
Issue tags: -$line_item +Novice
TR’s picture

Version: 6.x-2.x-dev » 7.x-3.x-dev

7.x-3.x comes first.

webchick’s picture

Issue summary: View changes

Correct formatting.

krh121791’s picture

Hello,

Does this tutorial satisfy your the needs of this request: http://www.jaypan.com/tutorial/ubercart-creating-line-items-tutorial?

I found the tutorial on the following thread: http://www.ubercart.org/forum/tutorials/16764/line_items_tutorial.

If this satisfies the needs, or is the correct direction, I will work on appending the information to the documentation. Does anyone have suggestions on where to add the new information on this page: https://drupal.org/documentation/modules/ubercart?

Thanks.

TR’s picture

Version: 7.x-3.x-dev » 8.x-4.x-dev