0

I have successfully added the custom line item fields in the cart through Views and modified the new total using a hook, but how do I do the same thing in Create an Order page (admin/commerce/orders/add)?

  • The custom line item field was added in admin/commerce/config/line-items/product/fields
  • I'm using inline entity form and I can see the custom field, but the custom field is not visible in line items table.
1

Sounds like you just need to alter the commerce_line_item_table View. Edit this view and add your fields so that they show up when it is embedded when the line item reference field formatter is used.

You'll want to take some extra steps, however, to save your customizations since that view is provided by the module. I would clone that view and update your field formatter's to use that view (it's customizable from the display options!)

Or, implement hook_views_default_views_alter and completely override the view with your own export.

EDIT: Some info on the line item manager widget

In order to get fields to show up in the line item manager widget table, you're going to need to override the widget's theme function. See commerce_line_item_field_widget_form and theme_commerce_line_item_manager.

Essentially you may need to invoke hook_field_widget_form_alter to added your field's value, and then override theme_commerce_line_item_manager to place it properly.

Snippet of a theme override that could be used, to add length

// Add each line item to the table.
foreach (element_children($form['line_items']) as $line_item_id) {
  $row = array(
    drupal_render($form['line_items'][$line_item_id]['remove']),
    drupal_render($form['line_items'][$line_item_id]['title']),
    drupal_render($form['line_items'][$line_item_id]['length']),
    drupal_render($form['line_items'][$line_item_id]['line_item_label']),
    drupal_render($form['line_items'][$line_item_id]['commerce_unit_price']),
    drupal_render($form['line_items'][$line_item_id]['quantity']),
    drupal_render($form['line_items'][$line_item_id]['commerce_total']),
  );

  $rows[] = $row;
}
  • Thanks. Looks like it works in the View page, but how do I get it working in the Edit page? i.imgur.com/DEnY6I0.png Also, how can I modify the line item total? – user173457 Feb 7 '16 at 16:25
  • I've updated my answer to reflect the line item manager widget. This should cover the total, too. – Matt Glaman Feb 7 '16 at 17:13
  • I regretfully have not been able to add the the length field into line item manager. I was able to do it with IEF but encountered problem with the line item total calculation. How do I add the field's value into the table by invoice hook_field_widget_form_alter? – user173457 Mar 6 '16 at 15:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.