Each time an order is added to cart, the admin/commerce/orders/11/view, for example, shows all product display nodes ever created on the site for that SKU.

I suspect that this is not the normal behaviour I should see because if it were, over time, these order views on the administrative pages would grow endlessly long.

However, the Cart Form shows only 1 item and that appears to be correct. I suspect there is something incorrect with my Line Items view. admin/structure/views/view/commerce_line_item_table/edit/default?destination=admin/commerce/orders/11/view

Please see my attached images. enter image description here enter image description here enter image description here

1 Answer 1


It's a result of your relationships: you're connecting each order item to the product it represents and then each product to each node that references it. Because of the way that database query works, it returns a unique result for every combination and renders them into your View.

Judging by your View's configuration, this was the simplest way for it to include the course type, teacher, etc. fields from the node. You're going to have to filter the result set somehow ... unfortunately, the data you need to be able to do that (the add to cart context from the $line_item->data array) isn't exposed to Views.

To see how that array gets built, check out commerce_cart_field_attach_view_alter(). You have two basic options for that data: create a custom Views filter that will allow you to filter the result set of your Views based on the values in the $line_item->data['context']['entity'] array or else remove the relationship from the View and switch to rendering the line item using a custom view mode, loading the data you need from the related entities manually.

(Note: I was going to suggest that if you only have one active node selling each product at any given point in time (unclear from your question), you could just add a filter to your View that checks to ensure the node referencing the product is published. That would get rid of the duplication but screw up your historical orders who now appear to show the wrong content.)

  • Thank you, Ryan. Taking away the relationship worked, but I also want my customer to see the title of the product display node. Additional info: when a user "books" (flag) a course the original course (product display node) created by the teacher (where the teacher is set via an entity reference field) is cloned and the booking user is then set as the author. So I can show a view to the user of all their booked courses and show the teacher as well. I don't understand "switch to rendering the line item using a custom view mode, loading the data you need from the related entities manually."
    – BassPlaya
    Mar 25, 2020 at 23:43
  • I think you were talking about "line item types" and take the one called "product" and in manage display add a view mode to show that "product" line item type differently so that it would include the teacher, the course title, etc. Correct? If so, that wouldn't work because my products are actually very simple products that have only the standard settings. There is no reference to the display node. There is a reference from the display node to the product type obviously.
    – BassPlaya
    Mar 26, 2020 at 1:50
  • Yeah, sorry I wasn't clear; I left out of there the idea that you would need to hook into the theme layer to load in the additional information you need when rendering the entity in that view mode. So, if you detect a line item is being rendered for the cart or order page view mode or whatever, preprocess it by loading the fields from the relevant node and then alter the render array or add a template that drops those fields into place. Mar 27, 2020 at 2:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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