Why my custom line item won't show with the shipping line item in Drupal Commerce
I've been doing a lot of Drupal Commerce work recently, it's pretty much my full-time job. I created a custom discount line item a while back, which is used for bulk discounts on orders. I could not get the line item to appear on the order summary, no matter what I did. I wanted it to appear with the Shipping line item. Here is how.
At first the line item didn't appear anywhere. Looking into it I found that the line items for the view I was looking at were filtered so that only 'product' line item types were displayed. I removed this filter, and hurray, my line items displayed with all of the products.
I really wanted the bulk discount line item to display with the Shipping line item, between the Sub total and Total for the order. I looked through the Shipping module, I looked online, I could not find a way.
Looking the other day at the Price module, I found commerce_price_field_formatter_view(). This function is used to format the Price field. looking through the code it appears that the price is grouped by 'component'. Price components were scary when I researched this in the first place, so I stayed away. It turns out that modules can expose price components (the parts that go into a price, like tax, discount, base rate, etc.), using hook_commerce_price_component_type_info().
The long and short of it is that my custom discount line item was using the base rate as its price component, which is automatically grouped as the sub total. Shipping uses the shipping price component, which it exposes, which is why the price is itemized separately. Exposing, and using, a custom price component in my custom line item module will allow me to have more control over how the price is displayed.
I haven't looked into it, but the Commerce price by components module appears to give even more control over how prices with custom components are displayed.