Score:0

How to achieve this? (because I think it's not possible to reference a vocabulary)

fi flag

I'm trying to implement a (i think it's not that complex) functionality but I'm stuck at this moment.

I'm using Drupal 7 and I have my own custom module so, if necessary I would code, but for now I was defining the content types.

I want the user to be able to create two types of content:

1. Stock This content has the following fields:

a. name
b. item
c. quantity
d. value

2. Items (this content is the one that I reference in the Stock content). This content has the following fields:

a. name
b. attributes (unlimited)

And the last part of the puzzle is the attributes field that initially I wanted to use a Vocabulary.

An example is easier to understand:

I have 2 attributes (vocabularies):

color (with terms yellow, blue and green)
weight (with terms 200, 1000 and 5000)

I then create an Item like this:

name = "Item Nº1"
attribues = [color, weight] (this field is unlimited so I want to reference the 2 vocabularies. From what I see, it's not possible to reference vocabularies, only terms)

Finally, when the user creates a Stock, I want something like this:

name = "my First Stock"
item = "Item Nº1" (referenced)
quantity = 3
value = 34

The goal I need to achieve is that, in this last step of creating a Stock content, I need to choose the terms of the "Item Nº1". In this case it would show up the color and weight and the user would choose one or multiple terms of each one.

I think I'm overthinking this and there is a clean solution so, if someone can help me and suggest a better way to do this, I would really appreciate it.

Thank you

EDIT:

I've managed to create the "Items" content type that as an Entity Reference field where I can choose which vocabularies I can reference:

enter image description here

adding a new Item:

enter image description here

So, at this moment I can add another entity reference to the Stock content type BUT that will only allows the user to choose the Item type. What I need at this point is to also be able to choose the terms of the vocabularies that Item type has available (as I'm writing this, I'm getting more certain that is not possible without any coding at all)

Score:0
cn flag

To track inventory, take a look at how Drupal Commerce does it.

The Commerce setup may be a little more complex than you need, but it is quite flexible and well supported. If you choose this approach, it will also make it easier to add new features later.

To start, you can make some products, and then create what Commerce calls product variations for your "attributes".

To handle inventory, there's the Commerce Stock module. (Disclaimer: Have not used this particular module.)

Even though it's called "Drupal Commerce", all the features are split up into separate modules, so if you only need to handle inventory and do not want a web store, you can just disable the store related modules (Payment, Checkout, etc.)

zephirus avatar
fi flag
Thanks Patrick, I'm aware of Commerce Stock but because I need something so simple, I was thinking that there would be a better solution. I will take a look nevertheless.
Score:0
in flag

Vocabularies are configuration entities, but you can still reference them with entity reference fields.

Add a new field and choose Reference > Other... for the field type.

On the next screen you'll be able to select the type of item to reference via a select list with many more options, including configuration entities. On this screen, set "Type of item to reference" to Configuration > Taxonomy vocabulary.

By default this will allow an editor to reference any taxonomy vocabulary. If you need to limit which vocabularies can be referenced, create an entity reference view and configure your field to use if by setting the Reference method on your field's edit page (Manage Fields > My Field > Edit). For details, see How to Use Entity Reference Views in Drupal 8

sonfd avatar
in flag
Oh darn, this answer for Drupal 8+, no idea if it applies to Drupal 7. :(
zephirus avatar
fi flag
I think that doesn't apply to Drupal 7. I was thinking about changing to Drupal 7 but the differences in code are massive so I'm not yet prepared to do it. But I think that would solve it, yes.
zephirus avatar
fi flag
I edited my initial question. I can reference a vocabulary name in my "Items" content type. I just can't show the terms available when creating a "Stock" node :(
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.