1

I am creating an online store, for which I am using the Views module (grid) for product displays.

I want a 'Add to cart'-button to appear for every product displayed. How can I do so?

Note: I can display the product, but without the 'Add to cart'-button.

1
  • Does anyone have a Drupal 8 answer for this?
    – Christia
    Apr 28, 2019 at 10:55

3 Answers 3

1

Surely your issue was solved a long time ago, but this could be useful for other people, so in short :

  • in advanced settings of the view, add a relationship Commerce Product: Referencing Node (Relate a product to the Node referencing it through field_product) with your product type
  • then add a Contextual filter (Node referencing products from field_product) Content: Nid How to display an add to cart button for each product
  • then you're be able to pick up Add to cart form from Add fields menu

Enjoy ;)

1
  • This doesn't work in Drupal 8 FYI.
    – Christia
    Apr 28, 2019 at 10:55
0

In case you are using Drupal Commerce, you might be able to solve your issue (question) as described in this issue, i.e:

The problem is the "Add to Cart form" Views field that you're using doesn't have the node context. As far as the node and the View are concerned, that View is the sole place you're displaying that Add to Cart form. What you'd really need to do is to have the actual Product Reference field from the node rendered. When that happens, Views will load the full node and its field will be rendered individually - and it's during that process that it adds the node context to the Add to Cart form for use in the display_path field.

0

Along with the other fields, add the product variations field and choose the add to cart form from the formatter dropdown. That will add add to cart button to all the products listed in the view.

configure field product variations

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.