Closed (works as designed)
Project:
Feeds
Version:
7.x-2.x-dev
Component:
User interface
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
17 May 2011 at 00:19 UTC
Updated:
28 Aug 2017 at 13:38 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
rickmanelius commentedIt appears that some work was done for the Drupal 6 branch.
#1004668: Add support for mapping taxonomy term parents
I'm placing this ticket here as a reference, as well as subscribing because I'm also interested in this functionality.
Comment #2
rickmanelius commentedIt appears this is a duplicate as an initial patch is posted here #1152940: Feeds term import with hierarchy and weight. I'm leaving this open because the instruction part could still be relevant to this ticket.
Comment #3
johnbarclay commentedComment #4
timhsieh commentedI believe that the issues in #1 and #2 are actually referring to a different issue -- that of importing terms into n-level taxonomies -- rather than what the OP was asking: importing nodes and tagging the nodes with terms from an existing n-level taxonomy.
I think this can be accomplished with already existing tools. First, install Feeds Tamper and configure a comma-delimited exploder plugin on the desired mapper field (Category in this case). Next, put your terms in the same column in your csv:
I was able to successfully import nodes and tag them with terms in a 2-level hierarchical select field using this.
Comment #5
vaccinemedia commentedThat solution worked perfectly for me on one project where the products all belonged to one category / subcategory i.e. "dresses,oriental".
However, I'm about to run an import from another source where the products belong to multiple categories / subcategories like:
"Kids,Fleece" and "Kids Sports,Fleece" or
"T-shirts,Fashion" "T-shirts,Women" "Women's Fashion,T-shirts"
How would this be achievable?
Comment #6
OldAccount commentedThanks for the Feeds Tamper module suggestion, using the Exploder plugin I was able to import my feed with multiple terms attached to one node. Being able to specify the string separator was also very helpful since some of my terms have commas so they're separated by semicolons instead.
Comment #7
pindaman commentedi tried to add feeds tamper for this:
GUID,Item,Category
1,Item 1,"Tools,Hammer"
2,Item 2,"Tools,Drill"
etc
in Category i am looking to create:
Tools
+ Hammer (child of tools)
+ Drill (child of tools)
Now it is just a list of terms like:
Tools
Hammer
Drill
Comment #8
dark_underground commentedsubscribe
Comment #9
GuGuss commented@dark_underground : no need to subscribe since there is the big "follow" green button that'll do the trick ! So Stop subscribing, start following...
Comment #10
pindaman commentedhttp://drupal.org/sandbox/manarth/1540722
will select multiple terms in a hierarchie with the explode option.
Comment #11
Tab10id commentedI have csv with structure GUID,Item,Category1,Category2,Category3 and I can import taxonomy structure and nodes with four importers
1) taxonomy structure 1:
import for first level of terms
2) taxonomy structure 2:
import for second level of terms with setting parent term (first level terms)
3) taxonomy structure 3:
import for second level of terms with setting parent term (second level terms)
4) nodes:
simple node importer and connect them to the last term (I use Feeds Tamper for getting last term in row)
---
Sorry for my English
Comment #12
rleroux commented@ Tab10id Thanks for the info. Could you elaborate on your 4th importer: what Feeds tamper plugin do you use?
Comment #13
PeggyOCO commentedI am also interested in the 4th step. What filter do you use in Feeds tamper to get the previous last term?
Comment #14
Tab10id commentedI use "rewrite" ([v_categories_name_1];[v_categories_name_2];[v_categories_name_3]) and then two cuting with "Find replace REGEX" (/;[\s;]*$/ and /^.*;/) I have not found a better way.
Comment #15
siliconvalet commentedHow to import a taxonomy hierarchy with feeds...
For my example, I'll import vehicles in this fashion - Make, Model, Year. Model being a child of Make, Year being a child of Model.
You need to add an "ID" field to your taxonomy. Found here: "admin/structure/taxonomy/taxonomy_name/fields". This can be deleted after your imports are complete.
Your data should look similar to this:
Note: the last level in the hierarchy doesn't need an ID. Only parents of terms need an ID.
Importer settings - http://www.diigo.com/item/image/32b8r/e5vj
Step 1 - Import your first level - Importer #1
Step 2 - Import your second level - Importer #2
Step 3 - Import your third level - Importer #3 - Repeat step 2... and if you had any more than 3 levels, you'd just keep repeating step 2.
If you're having a bit of trouble, remember the concept behind it is to have a unique ID (that you set in your import) and then reference that on your next level import.
Hope this helps.
Comment #16
gboggs commentedSiliconValet,
Great post. However, you've left out two steps.
1. Where you add the ID fields to your data. I assume you wrote a script to do this or used excel functions?
2. The last step once you have the terms, how did you import nodes and assign them to the correct taxonomy?
Comment #17
siliconvalet commentedRegarding creating the ID's, yes, I did do this in excel prior to importing.
Comment #18
molnitza commentedI want to import a lot of nodes with the node processor. The nodes have three different categories like "Hardware/Notebooks/CID", "Germany/Hamburg/Headquater" and "Brand/Type". If I import the .cvs the terms are all on the 1st level of their vocabulary without parents. Is it possible to import the nodes directly with their categories without using the taxonomy processor?
Comment #19
siliconvalet commentedWith Feeds? Short answer, No. Reason being, there is no way to reference the correct term (that I know of) through the GUI. I imagine if every term name from every level were unique, you can map it and it would just work. Duplicate term names would probably cause unexpected results.
I'm just getting my feet wet with migrate module. Have you tried it? Promising?
Comment #20
nitvirus commentedI am unable to import the sub-taxonomy terms after selecting terms of the taxonomy.
For example I have a taxonomy is subject-topic where maths(term) is the main term and algebra(sub term) and logic are to be choosen.
these sub terms are connected to the node by heirarchical select.
I have used the method as described in #4 but the sub-term is coming blank.
thanks,
Nitish
Comment #21
partyzan commentedGreat example, thank you, but how then to import nodes using taxonomy IDs.
I mean you'll get the same Taxonomy items "Civic/1994" and "Integra/1994".
Then if youll import nodes and taxanomy reference will be "1994" , and node will be added to the first taxonomy list item "1994".
Comment #22
nitvirus commentedI was able to import the sub-terms by giving the sub term name algebra so maths was getting pre selected.
Comment #23
no_angel commentedComment #24
crystaldawn commentedSo I needed to import hierarchy and I have no idea how to do this with feeds UI and I was not satisfied with having 50+ imports (one for each possible hierarchy level, WTF really? hehe). So I created a custom module that utilizes Tamper module instead that does this WITHOUT the need to have a zillion imports. It's NOT pretty code in the least but I've done my best to comment it so that others could improve upon it and maybe make it a contrib module at some point. It utilizes the already existing drupal 7 taxonomy_term_hierarchy table for looking up the terms.
Here is what it does for the following hierarchical example:
Parent 1 > Child 1 (Parent 2) > Child 2 (Parent of nothing)
NOTE: The > character IS REQUIRED. So your actual CSV data should look like:
Shirts > t-shirts > big shirts
You can change the delimiter if you want, but make sure to update the explode() function with the new delimiter if you do so. You can have whitespace between the > character if you like to make the CSV a little more human readable as everything is trimmed in the below code anyway.
It will look at the 1st level (Parent 1) first and check to see if that term exists or not, if it does not, it autocreates it (this may or may not be what you want, but you can change it's behavior if you dont want that to happen, for my use case I needed every missing level to be autocreated). It also does NOT mark the item as being in every parent taxonomy (something that others may need, but I did not for this particular case). This type of functionality would require a new return value of type ARRAY rather than type TID (int) which is currently not supported by the feeds module.
Then it passes the new parent TID to the 2nd level and repeats the step from above. This process continues all the way through ALL the levels. Then once the last level is reached, it returns the very last child's TID back to feeds and then feeds tags your new content with that taxonomy term. So now you have a term on the content that is tagged with a true hierarchical structure. Pretty snazzy right :) All without having to create 500 imports. God what a nightmare that would have been. UGH.
Requirement modules for this to work:
feeds
feeds_tamper
feeds_tamper_php
Steps to get this functioning (I am putting this here for my own reference, I am sure I'll need this crap again someday and I'd like it here for reference):
1. Create a new field mapping using "Taxonomy" and set it to use "TID" and NOT "TermName"
2. Create a Tamper rule on the taxonomy field using PHP (you get this functionality from the feeds_tamper_php module)
3. Now we create a custom module (I realize the naming convention may not be perfect, but none of the function names are currently in use anyway) and put the following code in it:
Comment #25
rikki_iki commented@crystaldawn thanks so much for your code! I had this exact issue with an XML feed that I couldn't alter at all, which listed it's categories as Parent > Child. You're code was perfect.
For anyone else, it doesn't require commerce_feeds at all...
And where it says
$vocab_name = 'YourVocabNameGoesHere'it's the machine name it's after.Comment #26
Costa-USSR commentedPerfect! Thanx!
Comment #27
crystaldawn commentedHmm yea, the requirements were a copy/paste from my own notes. Commerce_feeds is not needed. I updated #24 to reflect that as well as making the vocab name more obvious that it needs the machine name.
Comment #28
BATDesign-dupe commentedThis looks to be exactly what i need, but with all the stuff in my head at the moment, I am at a loss on how to exactly implement it. Can i please have some help :)
Comment #29
rikki_iki commentedHey @BATDesign, what specifically is confusing you?
Comment #30
BATDesign-dupe commentedHey @rikki_iki, the steps to get this to work - Do i have to create an actual module to get this to work from the php here or do i add it somewhere else, i think i missed something. Also is this to work as a separate feed importer just for taxonomy or can i use it in the node feeds importer...
Comment #31
BATDesign-dupe commentedOOOOOh, the fog may have lifted... I think i worked it out - Yes Module needs to be made and yes it works in node. I have also got it taking the categories from different fields with the rewrite function in tamper. Then I have them exploded again by this script - Working fantasticly - thankyou
Comment #32
BATDesign-dupe commentedDo you think it could be extended to add a url alias for each of the taxonomy values it puts in?
Comment #33
rikki_iki commentedIf you've got pathauto installed you can setup an alias pattern, which will automatically be applied to imported taxonomy terms.
Comment #34
zach harkey commentedI followed the instructions and adapted the code in comment #24 and was finally able to successfully import thousands of products into hierarchical categories.
Thank you, @crystaldawn!
Comment #35
drew29 commentedthanks a lot that works for me.
One question I have the find replace tamper plugin does work with this code is this right?
I need to replace one category name with another.
can you explain me how can i solve it?
kinde regards
drew
Comment #36
masterperoo commentedthis query fails for term names with single quote - basically quote breaks sql statement.
replacing line with the below fixes it.
Comment #37
mr4711 commentedSolution #24 does not work for me. Sometimes the title is missing (but the tax name and hierarchy is ok, guess when there are entries not on the deepest level) and it is not possible to have same category names in different hierarchies. And - don't know why - #36 leads to duplicate entries. Better change the "'" into "& #8217;" and choose "HTML entity decode" as first plugin. WTF
Better use: https://www.drupal.org/node/2212587
Comment #38
tadesign commentedThanks so much for pointing me in the direction of https://www.drupal.org/node/2212587 mr4711, it worked perfectly for me and much less messing about.
Thanks
Richard
Comment #39
aus007 commented@crystaldawn
Hi , Can someone please guide as which files to edit inorder to crystaldawn fix working .
I am new to drupal development .
Thanks
Comment #40
aus007 commentedFound the Module .Thanks anyways @mr4711
Comment #41
lexbritvin commentedThe module works fine!
Please, contrib.
Comment #42
aaronelborg commentedRE: #24.
I swear I've dealt with this before so perhaps someone could help me remember...
Why do I not have "TID" as an option in the "select a target" dropdown? I have "Term name", however.
Thanks.
Comment #43
alireza.13 commentedthank you for code.
If taxonomy term like bellow that code select wrong parent term with "asd>bb>asd".
asd2
-asd
--bb
---asd
asd
-bb
--asd
I modify the code to fix it.
Comment #44
jedihe commentedI'm attaching the code from #24 (with minor code formatting improvements) put into a plugin for Feeds Tamper. Using it should be as easy as dropping inside sites/all/modules/feeds_tamper/plugins (remove .txt extension, only .inc at the end), clearing caches and then looking for "Taxonomy hierarchy" plugin in the Feeds Tamper UI.
Didn't yet look into the improvements mentioned in #43, so this file includes none of those.
Comment #45
ikeigenwijs commentedFor other visitors. We use https://www.drupal.org/sandbox/manarth/1540722