I've got a matrix of 12 products, which can be added to the cart by users after selecting different term reference fields, which then select the appropriate product. This is shown on a product display.

However, I'd like to have multiple add-to-cart forms, each with a different line item selected on the product display field.

Basically, I've got a field collection, and I'd like to iterate through each of the field collection entities and display an add to cart form, with my full 12-product matrix of options, for each of these field collection items.

It would seem that I could get the add to cart field, all formatted, using

field_default_view($entity_type, $entity, $field, $instance, $langcode, $items, $display)

But I am currently on the node.tpl.php file, and I can't quite work out which entity objects are which to pass to this function. Nothing really resembles what I'm seeing passed to commerce_cart_field_formatter_view.

Am I thinking about this wrong? Is there a better way to accomplish this?

1 Answer 1


I implemented this through patching Commerce Add to Cart Extras. My patch can be found here: https://www.drupal.org/node/1836200

In brief, the line item type contains a reference to an entity, a field collection item, actually.

I used views to generate a list of products with an add to cart form using Commerce Add to Cart Extras, joining (by a views relationship) on my field tables that provide the reference which must be attached to the line item.

Next, I had to alter Commerce Add to Cart extras so that the views result containing my entity id which must be added to the line item will copy that id over to the line item when the line item is created.

In the end, I have a list of multiple instances of the same product with a quantity field and a single add to cart button. Each product has the entity which must be added to the line item. When one of those products is added to the cart, the entity id gets copied over to the line item.

Your Answer

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

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