0

I used to work with Drupal 7 Commerce and now I need help to work on D8 Commerce.

I have nodes on my D8 website and I need to sell them through Drupal Commerce. Each node can be sold in the same conditioning with four variations, based on customer types.

I have created a store, a product variation type, an attribute, a product type and one product with four variations, considering that one product would be enough.

Each node needs to be available as an order item. For that, I have added an entity reference field, linked to the product type. I have thus filled the default value with the product created.

Now on each node page, I have my add to cart button (through Commerce block or custom Views block, it works).

My problem :

Viewing the node A, I choose the variation and add the product in the cart and everything is fine.

Viewing the node B, I choose the exact same variation and add the product and there I need a second order item line with the node title (added through Views with relation to the entity reference field, not the issue here).

Unfortunately I get one order line item with quantity 2 (if I add the node title, I get two order line items with quantity 2 for each).

It may look obvious but I need to know if I really have to create one product with four variations for each node (2000+)?

Or is there a way to achieve this with D8 Commerce with only one product?

My concern here is to use properly Drupal Commerce and of course avoid the long multiple creation of products, especially in the future for my end user.

Related threads:

Automatically generate product variations

  • 1
    Are you asking how to reuse the same product on nodes? And are you using a content type as a "wrapper" to display for the product and variation? Commerce 2 was designed with the intent on no longer being dependent upon "nodes". The product entity is now the display entity by design, but the downside is that it doesn't allow you to reuse the same variation for different product displays. I for example am going off road, and using a simple 1:1 product/variation, and referencing that through the node. I don't believe you can reuse the same variation any other way. – TonyTheFerg Apr 6 at 20:21
  • drupal.org/sandbox/taggartj/3104497. this may get you in the right direction – taggartJ Apr 6 at 23:23
  • Thanks for comments. @TonyTheFerg Yes I have a content type "wrapper" and the product and variations are the same for each node. Your answer is what I suspected, I should probably build the site around products and not nodes (but my nodes have multiple fields and entity references). Or I will have to create as much product+variations as existing nodes... TaggartJensen, for products bulk generation, I thought maybe using Feeds since it was possible in D7 (need investigation here) – Toki Apr 7 at 8:29
  • @TaggartJensen If I am correct the module is more a Variation bulk generate tool? So in my case, I would have to bulk generate 4 variations 2000+ times? Am I correct? – Toki Apr 7 at 9:15
  • If you have a view displaying nodes with the 2 of the same product, and you add to cart, you will get 2 items in the cart. Also, you will need to uncheck "combine like items in the cart" – TonyTheFerg Apr 7 at 20:48
0

Drupal 8 Commerce does not need product display nodes anymore. When we create a product, we get a page automatically for this product.

But if you need, like me, to keep a "node environment" on your website then you will have to create as much products as nodes and link them through an entity reference field (Type : Reference > Other...)

To create products, variations and links between nodes and products, I use Feeds, Commerce Feeds and Feeds Tamper. In my case, each feed type is based on upload file technique with CSV file created from Excel.

First, you build a Variations Feed type to create product variations with simple data (sku (unique), price, your_attribute). In my case, customer type was the attribute.

Second, you build a Products Feed type to create products using variations imported before (title (unique), variations (skus), store (required, ID=1 if you have only one). Here goes Feeds Tamper with List explode to get multiple variations for one product.

Third, you build a Nodes feed type to link nodes and products with two data (node title (unique), product title (in entity reference field)).

Finally, you get display nodes with specific products and variations and when you add to cart, products are well separated.

Hope this helps.

| improve this answer | |

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.