The documentation for hook_order is half way toward UC 3.0 hook_uc_order but there are extra operations and the documentation does not tell you where the order fits in to the processing. hook_uc_order will add a temporary line item that is displayed in some places but not others.

hook_uc_line_item is supposed to add a line item to an order but it does not, at least not for the combinations of options I tried.

What is needed is an Ubercart 3.0 page on adding an item to the order showing a working combination of the order and line item functions. One example should show an item created once then saved in the database so the item remain in the order for subsequent display in invoices etc.

Comments

tr’s picture

Are you talking about the documentation in uc_order.api.php, or something else?

peterx’s picture

The documentation in the code is good but it does not tell you how the line item functions work together with the order functions. What is need is a page about how to add a line item to an order so it appears in the order and invoice.

I searched for hook_uc_order and found a documentation page at ubercart.org on hook_order. The next time I looked for the hook_order page, I found http://www.ubercart.org/docs/api/hook_order which looks different. I do not know if there is one for Ubercart 1 and another for Ubercart 2. I could not find one to match Ubercart 3.

http://www.ubercart.org/docs/api/hook_line_item appears to be the predecessor to hook_uc_line_item. The Ubercart.org documentation pages need a way to indicate the the release they are for and to select the equivalent for the release you want.

Using the documentation in the code and some searches through the code, I found ways to add line items in hook_uc_order but the line is not saved in the order. I expected hook_uc_line_item would add a line and I could add a value to the line but the line is not created anywhere.

The following setting is one combination I tested and the line item was not stored with the order. What does stored mean? Do I have to store it myself?

$items[] = array(
    'id' => 'generic',
    'title' => t('Example'),
    'weight' => 2,
    'default' => 99,
    'stored' => true,
    'add_list' => true,
    'calculated' => false,
    'callback' => 'example_line_item_99',
  );

I also looked in the database and the uc_order_line_item table stays empty.

The following line from uc_order.api.php needs expanding to list the interactions required to save the line item and to make it appear in the various screens and the invoice.

Once a line item has been defined in hook_line_item, Ubercart will begin interacting with it in various parts of the code. One of the primary ways this is done is through the callback function you specify for the line item.

tr’s picture

longwave’s picture

uc_order_line_item_add() will save a line item to an order. Unfortunately at present you have to look after adding, updating and deleting the line item yourself. See http://api.ubercart.me/api/drupal/ubercart--uc_order--uc_order.line_item... - examining how uc_quote and uc_taxes add line items to orders may also be useful.

peterx’s picture

Thank you TR. The UC 3 documentation is a good start. How do I contribute documentation changes if I find a question unanswered or an answer?

Thank you longwave. The taxes module does almost exactly what I want. The only difference, at this stage, is my line item is not added to the total. I wrote a module to add to the store admin page for settings and had most things working except for the save to the database. The taxes module does that and looks like simple code to copy.

After that I will work on the visibility of my line item. The tax line item appears in about the right places. I am tracking data from the product to the order. My line item could make use of an extra data field loaded per product. It does not have to appear in the cart. It does have to appear in the order and the value has to be locked in the order when the order is committed. The line item also has to appear in the invoice. The tax field does that.

There are lots of references to taxes in the payment modules. My line item has to reach the invoice but does not have to interact in any way with the payment system because it does not change the amount billed. That should make my code simpler than the tax code.

longwave’s picture

All API documentation at api.ubercart.me is built directly from Doxygen comments in the source code, you can submit documentation changes by editing the code comments and uploading a patch here in the same way as you would submit a code change.

You can also contribute user documentation by editing or adding pages at http://drupal.org/documentation/modules/ubercart

tr’s picture

Component: Orders » Documentation