2

I’m building a drupal commerce store using product displays that reference multiple product variations. But i need the product display to show all of its product variations with all attributes one after another, not hiding the attributes by AJAX. And each product variation should have its own add-to-cart-button. So it’s a simple, flat design where a customer can see every variation and every attribute at a glance.

I know this could be easily accomplished using views, but for certain reasons views is not an option for me. I need a real node of the productdisplay with its variations. What’s the best and most performant way to achieve this?

EDIT According to @nvahalic it’s a mess to solve my issue without Views. So maybe i have to reconsider my decision not to use Views. To clarify, the products will be displayed like this:

+------------------------------------+
| Title Product 1                    |
| =====================              |
| General Text (for all variations)  |
| General Image (for all variations) |
|                                    |
|    Title Product Variation 1       |
|    =========================       |
|    Text                            |
|    Image                           |
|    *Add to Cart*                   |
|                                    |
|    Title Product Variation 2       |
|    =========================       |
|    Text                            |
|    Image                           |
|    *Add to Cart*                   |
+------------------------------------+
+------------------------------------+
| Title Product 2                    |
| =====================              |
| General Text (for all variations)  |
| General Image (for all variations) |
|                                    |
|    Title Product Variation 1       |
|    =========================       |
|    Text                            |
|    Image                           |
|    *Add to Cart*                   |
|                                    |
|    ...                             |
|    ...                             |
+------------------------------------+

As far as i know when using views to build this structure, i will need something like the module Views Field View to achieve the nested structure consisting of fields belonging to the product display as well as fields belonging to the variants. Since the shop will have very long lists of products, i’m concerned about performance issues coming along with this kind of modules. Or maybe i got it wrong and such module isn’t necessary at all?

EDIT 2 Finally i solved the problem by using the EVA module: i created a view showing the attributes of all products as fields and added am add-to-cart field. This view i attached to my product display – it seems to me this approach is way more performant than using the Views Field View module …

EDIT 3 It is a huge mess: using nested views is not a good idea, because commerce-add-to-cart buttons can not be cached, so caching views does not work as it is discussed here https://www.drupal.org/node/1926888 From my point of view it was a very, very bad choice to use views for this task. Now I can not use views for caching and the module commerce entity cache is not usable neither because the view does not rely on entities.

2
  • Take a look at demo.commerceguys.com and see how it works Oct 14, 2015 at 10:46
  • seems to me like they use views for the product catalog, so it's not the hint that i am looking for.
    – Madam Adam
    Oct 15, 2015 at 15:48

2 Answers 2

1
+50

If you're insistent on not using Views, you might pull it off like this:

  1. Create a new node type and then add an entity reference field that will reference the product displays for each of your products. Set the values to unlimited.
  2. For each of your individual products, create a product display.
  3. Set the renderer of the entity reference field on the new node you created to "rendered entity"
  4. Theme the product display nodes that are linked to the entity reference field accordingly
  +------+     +------------------+     +----------+
  | Node |1---M| Product Displays |1---1| Products |
  +------+     +------------------+     +----------+
            ^     ^ 
            |     | Theme this entity appropriately.
            |
            | Set this display rendered to "Rendered entities"

At that point, you should have a list of rendered node entities that would each have their own add to cart form. You could also add a new view mode (using Display Suite) and use that view mode specifically if you still wanted to use the other view modes.

But honestly, this is an extreme amount of work for something that you could accomplish in 30 minutes with Commerce Add to Cart Extras and Views. And regardless of what I said above, that's still my recommendation.

Edit: You're on the right track with Views Field View. If you're worried about performance (how many products do you have?) then you can also:

  1. Use Views cache. It's configurable under Advanced in the right-most column of the view configuration screen.
  2. Enable Views Content Cache.
  3. Implement Redis and perhaps Entity Cache.
1
  • thanks, probably you're right – it seems a bad way to go without views. Maybe i shouldn't be afraid of views, so I edited my question; i would be glad if you could say something to my concerns about views in the context of my requirements.
    – Madam Adam
    Oct 15, 2015 at 22:45
0

I've just done it in this simple way using views:

  1. Created a views block called "Product variation add to cart buttons"
  2. Added a "Content: Product reference" relationship (Products referenced...)
  3. Added a contextual NID filter (Provide default value, Content ID from URL)
  4. Added the Add to Cart fields
  5. Placed the block under admin/structure
  6. Configured to only display on product/* (which is the basic path pattern for my product displays)

Voila:)

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.