1
Answers
Vote up!
0
Vote down!

Auto select product type based on taxonomy term (category)

Let's say we have a Commerce webshop with two product types: Default and Wine. There are many categories(bread, water, wine, nuts, ....) in which the products are defined, and all categories but Wine can use the default product type.

To illustrate the problem along with the text below:
http://puu.sh/2FBzH.png

What I want to do is allow my client to select which category he wants to create a product in, and have Drupal automatically create a creation form for the appropiate product type. So if the client chooses the Wine category, the Wine product type is selected. If the client chooses the Nuts or Bread category it selects the Default product type.

It would be possible to manually solve this problem by creating tons of duplicates of the "Default" product type with the exact same fields but a default taxonomy term chosen, but because of the large scale of this webshop it would take tons of work if a new field would have to be added to the default product type later.

The Inline Entity form module has provided me with the option of creating a new node("add content") of the Product node type and also generate a Commerce product with that, but I want to make it even simpler for the client by having the Inline Entity Form automatically choose the correct product type depending on the taxonomy term("category") chosen. Any idea how this can be done?

Suggestions of taking a completely different approach to this problem are also welcome.

Thanks!

Asked by: dinnesch
on April 23, 2013

1 Answer

Vote up!
1
Vote down!

If I understand your situation, I think it's similar to mine. I think this is the hang-up and to my research there is no good workaround.

It would be possible to manually solve this problem by creating tons of duplicates of the "Default" product type with the exact same fields but a default taxonomy term chosen, but because of the large scale of this webshop it would take tons of work if a new field would have to be added to the default product type later.

Problem is you have to customize each Product Variation Type so granularly including the Content Type, adding fields, etc. this becomes impractical for most clients. As far as I can tell Commerce doesn't handle maintainers well if you want to add categories/Types. I would like to be wrong.

To get around this I did as you said and created a bunch more Product Variation Types ( I fear calling them Variations or Types since those terms get re-used for variations of products). Yes, the inability to clone a Product Variation Type is, to me, very crippling. To get around some of this I created a Content Type vocab list that includes all my Product Variation Types (and it gave me some additional flexibility to group some products in a way otherwise impossible with just PVTs) In my case, I have branded shirts, cups, and hats. Each has its own PVT, but I want to be able to see them under a single heading called "Swag". (My site is for a company whose primary product is far from these items. However, since they have such different attributes I could not make one PVT called "Swag"). I added a Term Reference Field to the Content Type. Now I can select both Swag and, for instance, Shirts so I can group, filter, sort them on either term.

I hope I understood your needs well enough that this was helpful. If not, sorry to have wasted both our time :-)

Do look into Feeds and Feeds Tamper to see if they can be of any help. In my use case I was totally unsuccessful at getting them to work due to the complexity of what I have and the lack of documentation/examples related to my use case and/or my ineptitude. I hope you fair better.

Answer by: abiconsulting
Posted: Apr 26, 2013

Comments

Your solution is definitely a good way to be able to group products of multiple PVTs. For my needs it's not so suitable because the store needs to be quickly adapted to change. I don't like having to choose PVTs to show products in a specific category, I just want to list all nodes associated to a taxonomy(category) term.

I've found a solution that's better suited to my needs, I'll explain it below. My solutions allows the client to use this procedure to add a product:

  • Go to "add content", and click the "add product" tab to only show node types("content types") that are product displays
  • Choose a PVT(and at the same time, product display(node) type). Default product(no extra fields, suitable for most categories), wine(which has a red/white term reference), etc.. My client just has to choose the most specific one.
  • Create both the node and Commerce product at once thanks to Inline Entity Form
  • Select the node's category at the bottom of the screen, this is shown in a tab thanks to Commerce Backoffice

To make it a little more visual

So here's what you need:

  • Commerce Backoffice to automatically generate a new product display type(node type) when adding a PVT, and to automatically set the correct inline entity form when adding a product node
  • Inline Entity Form to show both the node creation and product creation forms on one tidy page

Both solutions have their pros and cons. abiconsulting, for your multiple-PVT grouping needs, if you decide to use my solution (in the future) you can just show the nodes associated to multiple taxonomy terms using Views.

Thanks for the help! And by the way, "my solution" is mostly taken from Commerce Kickstart if anyone wants to see it in action.

- dinnesch on April 29, 2013