Hi, thanks for the module!
I needed to be able to import multiple hierarchical paths of terms (within one taxonomy) so I reworked the module to support this.
It also wasn't working for me on Feeds 7.x-2.0-alpha8 (looks like others had trouble too https://drupal.org/node/2021519), so I fixed that.
I exposed configuration options in the Mapping UI so the separators can be configured, and because of the multiple hierarchy needs, I built in explosion so Feeds Tamper isn't necessary on the attached version.
There's a readme file in the zip with usage info regarding the differences.
| Comment | File | Size | Author |
|---|---|---|---|
| #33 | feeds_taxonomy_hierarchy.zip | 4.57 KB | lmeurs |
Comments
Comment #1
lmeurs commented@manarth: Thanks for a great module! I was working on a fork of a Feeds Tamper plugin with similar functionality (#1319278: Support automatic importing of the term hierarchy for nested taxonomy terms), but using your custom mapping is the way to go!
@anschultz: Great fork, but it seems you removed functionality to automatically create new terms,
is this on purposehadn't read the README file! Also I think it might be wise to not replicate Feeds Tamper's functionality to separate multiple field values from each other.Before I saw anschultz's module I also forked Feeds hierarchical taxonomy and combined it with original mapping from
feeds/mappers/taxonomy.inc, see attached. My fork:With help of Feeds Tamper's explode plugin to separate multiple field values, I successfully tested attached fork on an import file similar to:
Comment #2
lmeurs commentedI altered our module to:
Comment #3
lmeurs commentedAttached newer version with cleaner code and made automatic term creation optional.
Comment #4
Andrea Gobetti commentedHi, I've installed the #3 version, but I can't find the module's configuration form and I don't understand how to make this module work... I imported an XML file using XPath XML parser, using feeds tamper I obtained a string like "Category>>Subcategory" and now I'm trying to add these terms to my vocabulary but all I get is a single term which contains a string like "Category>>Subcategory".
Could someone explain me how can I make this module work? Thank you!
Comment #5
lmeurs commented@Andrea Gobetti: I have not used XML imports through Feeds yet, so do not know whether it works for non CSV imports.
The module does not have a settings page. At the mapping settings of your feed you should select the target field with a suffix like "Hierarchical", after that you can alter some settings at field level.
Comment #6
Andrea Gobetti commentedThank you lmeurs, all I can see in the mapping settings on my field is a select box called "Search taxonomy terms by" and a checkbox called "Auto create", I don't think this module works also for XPath XML parser, for now.
Comment #7
ethanLee commentedHi~ I installed feeds_taxonomy_hierarchy_3.zip. But when I try to start importing, It shown error in the report page:
Recoverable fatal error:Argument 4 passed to feeds_taxonomy_hierarchy_feeds_set_target() must be an array, string given, called in /www/sites/all/modules/feeds/plugins/FeedsProcessor.inc on line 509 and defined at feeds_taxonomy_hierarchy_feeds_set_target() (/www/sites/all/modules/feeds_taxonomy_hierarchy/feeds_taxonomy_hierarchy.module line 104 )。
please help~
Thank you.
Comment #8
lmeurs commented@ethanLee: Did you use the Feeds Tamper module to explode the bare string value first? Your feed probably provides a string value like
Parent term|Child term, but this string value needs to be turned into an array value likearray('Parent term', 'Child term')before it can be mapped correctly.Comment #9
ethanLee commentedDear Imeurs,
Thank you for your answer. But I still don't know how to set the feeds tamper and feeds_taxonomy_hierarchy module. Could you give me an example?
Thank you again.
My csv file :
id,title,brand
12,product1,brand>brandA>brand123
13,product2,brand>brandB>brand123
Comment #10
lmeurs commented@ethanLee: You already mapped the fields for your node processor and have the Feeds Tamper module enabled, right? Go to
admin/structure/feeds, look up your feed and click it's Tamper link. Search for the Brand field and click Add plugin. Now under The plugin to add select List > Explode and set the String separator in your case to>.Also see the Feeds Tamper documentation, it's a great versatile module!
Comment #11
ethanLee commentedThank you lmeurs~It works well~
Comment #12
sampaka commentedHi Imeurs, i have mapped several xpath expression to my fields. I have created one field (Location: hierarchical by term name -Hierarchy separator: >>) where with the tamper pluggin i make a rewrite to get a hierarchy path stiched together by other field values ([xpathparser:11]>>[xpathparser:7]>>[xpathparser:8]>>[xpathparser:9]) . Then I added another plugin to explode the stiched string with ">>" as separator.
When i do the feed import only the first expath expression is created in my taxonomy vocabulary ([xpathparser:11]). The rest is simply ignored.
Can you image why this is so? Thanks in advance.
Comment #13
lmeurs commented@sampaka: I am not familiar with the Feeds XPath Parser module, but since at least 1 term reference is created, something is working well.
Do you happen to use "Save term lineage"? If so, make sure the node's field that is referencing to this taxonomy vocabulary allows more than 1 value.
Comment #14
sampaka commented@Inmeurs - thanks a lot for your answer. Indeed the taxonomy vocabulary was limited to 1 value, so I changed it! Now every term is imported but without any hierarchy. Could this be a problem of my term reference field as it is set to Autocomplete term widget (tagging). Update: changing to a select list unfortunately did not change anything
Comment #15
lmeurs commented@sampaka: Your question puzzled me for a while, but I might have a solution. At #12 you say:
This causes Feeds tamper to flatten your hierarchy, while handling hierarchies is supposed to be done by Feeds hierarchical taxonomy.
Feeds tamper is only needed here to optionally explode multiple hierarchical terms that remain in a single value. Say your CSV looks like:
In this case a Feeds tamper plugin can be used to explode the hierarchies from each other using "|" as separator, Feeds hierarchical taxonomy is used to handle single hierarchies using ">>" as hierarchy separator.
Comment #16
sampaka commented@Imeurs - its working! so great - you made my day! You were absolutely right that feeds tamper with ">>" as separator flattened my hierarchy. But when I removed it i got the error: "An AJAX HTTP error occurred. HTTP Result Code: 500 Debugging information follows. ResponseText: Recoverable fatal error: Argument 4 passed to feeds_taxonomy_hierarchy_feeds_set_target() must be an array, string given, called in ".
So I simply added the Feed temper plugin to explode but instead of ">>" i established "|" as separator. Now the array gets created and I can pass the stitched xpath expression results into the taxonomy term with the corresponding hierarchies.
Thanks you so much for pointing out the things you noted that were wrong with my approach. I hope this can help people who try to map xpath expressions to taxonomy!
Comment #17
lmeurs commented@sampaka: I am happy to hear it's working for you! I understand where the confusion came from. Though the original module expects an array (as stated at the project page), it makes more sense to accept strings as well. I changed this in the forked module and attached it to this issue.
Best of luck!
Comment #18
agerard commentedI just want to say thanks! This module - especially with the last change - is just what I needed to create a lot of nodes with reams of hierarchical taxonomic terms from csv files. I'm not yet up to the level where I can contribute much back in the way of code, and offering to bake cookies doesn't seem appropriate, but you've saved me hours and days of head-banging.
Comment #19
vimokkhadipa commentedHello Imeurs, thank you very much for writing this module, Fixed my life. I could use your module to import 5000 products and their views on a new Drupal system and worked perfectly. thank you very much.
Comment #20
casper83 commentedI added this line after line:202 to remove empty values
$hierarchical_term_names = array_filter($hierarchical_term_names);
Comment #21
vivdrupal commented@Inmeurs Thanks for the module. It works perfectly.
Since I had not paid heed to your statement "Feeds tamper is only needed here to optionally explode multiple hierarchical terms that remain in a single value." and lost some hours, I am recording the steps required to import data like
Media>Graphics>Banner & Sign.
In Feeds setup for the field "Category: hierarchical by term name" it should be like
Hierarchy separator: >
Automatically create terms: No
Save term lineage: Yes
No other setup is required in Feeds Tamper for this field.
Comment #22
nir.arazi commented@Inmeurs First of all, thanks for the module!
I can't seem to get it to work the way I need it to, though.
My CSV file contains a taxonomy field named 'list', which has its values exported in the format "Parent Term>>Child Term".
This taxonomy has only 2 levels (if that makes any difference).
I installed the latest version of the module (4), and mapped the 'list' field from the CSV file to the 'field_category' taxonomy field I have in my data type. I've used '>>' as separator, checked the option to add new terms, and tried with and without term lineage.
Both options yielded the same result - only parent terms have been imported and set.
What I want to achieve is to have the taxonomy filled with parent and children terms, and the node field value to be set to the child term.
What am I doing wrong?
Thanks again,
Nir
Comment #23
lmeurs commented@nir.arazi: I have not worked with the module for a while now, but from the top of my head: do you happen to use Save term lineage and does the node's field allow just 1 value? If this is the case, the module iterates through all taxonomy terms, tries to create terms and stores term ID's as field values, but since only 1 field value is allowed the module stops after the first term (the parent). By turning off Save term lineage all terms are being created, but only the ID of the deepest term (child term) is being stored as the field's value.
Does this make any sense?
Comment #24
lmeurs commented@casper83: Thank you for your input, I added support for empty terms as in "Term A >> Term B >> >> ": The last terms have no name and will be ignored.
Comment #25
tadesign commentedHi,
Just wanted to say thank you so much for this patch, it worked perfectly for me and is essential for my current project which involves importing hundreds of terms that are listed in a hierachy and which are used to organise sections of the website and populate navigational menus.
Many Thanks
Richard
Comment #26
wesleymusgrove commentedI had a similar situation as @tadesign and agree 100%!
My CSV hierarchy looked like this:
Parent > Child > Grandchild
So being able to easily specify in the settings that my delimiter had a space on either side was a big help. After some careful setup, it worked flawlessly on the first try! Great job @lmeurs!
Comment #27
vivdrupal commentedFor me right now it is working for Commerce product but not for Product Displays.
Comment #28
lmeurs commented@vivdrupal: a Commerce product display is a node, so it should work. Did it suddenly stop working (maybe after you updated to Drupal 7.33 like you said before you edited your comment) or is this a new install you're talking about?
Today I successfully implemented a feed for product displays using this module, so could you tell me about your setup and settings?
Comment #29
JadH commentedHello,
Thank you for the module.
I used the version in #24, I am able to explode the terms with feed tamper, but the relationship between parent and child is not set.
Did I miss something? any ideas?
Comment #30
lmeurs commented@JadH: At the field mapping page, did you select "VOCABULARY_NAME: hierarchical by term name"?
If so, can you determine the following settings for this field:
What are the values of these settings and can you provide one line from your CSV file?
NB: You should only use Feeds Tamper for this field if a node can contain multiple hierarchies, see comment #15 for more info.
Comment #31
JadH commented@lmeurs it is working now, I was not using the field with "hierarchical by term name"
great module, thank you.
Comment #32
chris_cross commentedHaving issues with Drupal v. 7.34. Worked fine on 7.32. We are uploading a csv file to a node using feeds v. 7.x-2.0-alpha8. Now it only imports the parent term with v. #24. The other one does not import any terms.Figured out the issue. We had changed the input widget to simple hierarchy select on the content type. Once we changed it back to the regular hierarchy select, the import feeds worked.
Comment #33
lmeurs commentedI attached a new version of the module which fixes a bug that on entity update prevented possible existing values from being overwritten, instead new values were being appended.
Take for example updating an entity with a taxonomy term reference field with a cardinality of 1: only one value is allowed, the old value would not be overwritten and a new value could not be added, so nothing seemed to have happened after the update had finished.
Comment #34
ikeigenwijs commentedWould this module also work for entity reference to taxonomy ? instead of basic taxonomy term reference?
Comment #35
lmeurs commentedRight now it does not, but it might after a few small modifications.
The implementation of the
hook_feeds_processor_targets_alter()hook only adds a custom Feeds target for fields of typetaxonomy_term_reference, of course another field type could be easily added.Also, on import the module sets the entity's field value as an array with associative subarrays with solely term ID's, I do not know if this structure applies to entity reference fields as well. Example:
Comment #36
ikeigenwijs commentedhttps://www.drupal.org/project/entityreference_feeds
This module does feeds entity import
I m looking to merge your hierarchical solution with there entity solution.
Comment #37
ikeigenwijs commentedIn feeds_taxonomy_hierarchy_feeds_processor_targets_alter the folowing is needed to let it show up
I think i get close with the other code but
$shared->cache->{$field_name}->vocabulary_ids[0];
apears to never be filled in and gives Null so look up also gives nothing.
For lookup i also tried in
feeds_taxonomy_hierarchy_get_term_id
just to keep you posted
Comment #38
ikeigenwijs commentedi created a sepperate issue for the entity reference support
https://www.drupal.org/node/2484727#comment-9899953
It appears to be working for our use case
Comment #39
lmeurs commentedGreat, will try to take a look at your adaptions soon!
Comment #40
madelyncruz commentedI just have tried #33 and I was unable to make it work. It only saves the parent term and the child under that parent term is being ignored.
I've added Vocabulary name: hierarchical by term name (field_name_hierarchical) and set the settings below:
Hierarchy separator: |
Automatically create terms: Yes
Save term lineage: Yes
Here's my CSV's structure:
title,code,category
title 1,123,parent
title 2,345,parent|child1
title 3,678,parent|child1|child2
I've also added a tamper plugin, which is [Explode] and used vertical bar in string operator.
I noticed that only parent term is being created.
Is there something wrong with my setup? Please advice.
Comment #41
lmeurs commented@madelyncruz: Does the node's taxonomy reference field allow multiple values?
Comment #42
lmeurs commented@madelyncruz: BTW, you should only use Tamper Explode if the column contains multiple hierarchies as in:
(I prefer to use "|" to separate muliple values from each other and ">>" as a hierarchy separator)
Comment #43
madelyncruz commented@lmeurs No. I've set it to 1. Is it needed to be unlimited?
Comment #44
lmeurs commented@madelyncruz: Well, since you selected Save term lineage you want to save multiple terms, so the fields cardinality needs to be at least 2.
Comment #45
madelyncruz commented@lmeurs OK. I did not know that. Thank you for telling me that :)
Comment #46
madelyncruz commented@lmeurs Got it! I've set the values to unlimited and it's working OK now, but why it creates 2 separate terms
eg.
Term 1: best sellers
Term 2: best sellers > aus
What I only need is the Term 2 and I don't want a redundant terms.
Thank you so much for your quick response.
Comment #47
lmeurs commentedIf you provide
Parent > Child > Child's child, all terms will be created, hence the nameFeeds Taxonomy Hierarchy. If you only want the top level term, the easiest way is to only provide that term as inChild's child, but that can be done with Feeds out of the box.If you do not have control over the input feed, you might want to look for a Feeds Tamper way to explode your values and only pass the top level value to Feeds. But I do not know how to... Or you can alter the module to only process this top level value.
Turn:
into something like:
I have not tested it, so at your own risk! :-)
Comment #48
aus007 commented@lmeurs
Thanks for module. I am trying to use it as I am a bit new to drupal finding it hard to use .
Do you have any step by step doc anywhere ?
This module is different from other modules, once I download all I can see is .info and .module only ?
Thanks
Comment #49
aus007 commentedCan someone help me with the taxonomy hierarchy set up .
ON website I have category HOME & Garden > Sofas
In the XML the category structure is Root > Category> Sofas.
What setting do i have to change to get this imported.
I tried default setting none of products were uploaded to right category .
Thanks
Comment #50
lmeurs commented@aus007: If you have created feeds before, using this module is easy. When mapping a Feeds column to a taxonomy reference field you have to select a hierarchical by term name mapper and A) select whether you want to create new terms or only use existing ones and B) whether you want to save term lineage (also save the term's parents).
I have not tested the module with XML files yet and I am not sure whether it works, also see #4. So far it does work with CSV, if you can switch to CSV, please do so.
Comment #51
aus007 commented@lmeurs
Thanks for your reply.
Ok will try with CSV , got a small question . Inorder for this Module to work correctly, should the hierarchical structure be same in Source and destination.what's the work around if my source CSV has category hierarchy HOME& Garden > LIVINGROOM> Sofas
while destination has just HOME > Sofa .
How to work around with this specially when you dealing with many different suppliers with different hierarchical structure.
Thanks
Comment #52
lmeurs commented@aus007: That is beyond the scope of this module. You might want to take a look at Feeds Tamper to alter values before they are processed by any Feeds processor. If you create a custom tamper plugin you could easily define source + destinations pairs (maybe in a separate text file) and map source > destination accordingly.
To be honest, if things get complicated I often use a custom parser outside of Drupal which prepares a CSV file before importing it into Drupal: Feeds requests the CSV over HTTP through the custom PHP parser.
Comment #53
droddis commentedHi Imeurs,
First off thank you for such a great module. I had it working perfectly until we determined the client couldn't combine all possible Taxonomy terms on one line give Access DB export restrictions based on character counts.
We are creating individual products in Commerce, and using Brand+Model heirarchical taxonomy terms to associate the products with other products. In an effort to reduce the size of the combined taxonomy field in the DB export, I imported the entire Taxonomy tree, and then used the Term ID as part of my import CSV.
Having just read through the comments above I notice that you mention we can't use Term ID's in the import, only actual term names. I'm not sure I understood exactly the reason why, over my head I'm guessing, but is there anyway I can use the taxonomy term ID's in my import?
thanks in advance for your advice/support.
Regards
Comment #54
j0e commentedThanks for the module!
Comment #55
lmeurs commented@droddis: The main goal of this module is to link entities to hierarchical taxonomy terms when processing a feed, this comes with extra features like automatically creating non existing terms and saving term lineage.
In your case you want to link to already existing terms using their ID's, so as long as you do not need to save the term lineage, can't you use Feeds' default taxonomy term importer providing the ID of the highest term?
Comment #56
lexbritvin commentedModule works fine!
Please, contrib!
Comment #57
Anonymous (not verified) commentedDoes this module work with a taxonomy term import or does it need to be attached to a node import?
I just want to import this structure into an existing taxonomy:
town, county, country
taunton, somerset, england
oban, argyll scotland
where country is the top level term. I would like to retain the taxonomy terms that already exist as they are used in nodes.
Is this possible?
Comment #58
droddis commented@Imeurs
I'm not sure that I can't. I just tried creating the import csv using the taxonomy terms. didn't work as of yet but I'll continue to play with it.
Maybe I'm going about it all wrong, I'll take another look at the setup. thanks for your help and suggestions though!
Comment #59
mristau commentedThanks for that - please contribute.
Working with Feeds version: 7.x-2.0-beta1.
Comment #60
lmeurs commented@olomouc: The module can be used with any type of entity which has a taxonomy term reference field, so unfortunately it will not work in your case.
@mristau: You hid the latest version of this module, I think by mistake, so I unhid it.
Comment #61
mattia.cristalloI have Feeds v.7.x-2.0-beta1
and I want import my csv with hierarchial taxonomy mode.
Industry (root)
-Country (parent1)
--Email (term)
How I can I do?
Thanks
Example:
Industry|Country|Email
Ferrari|Italy|ferra@f.it
but this template import only last term... I want hierarchial term.
Comment #62
pradeepjha commentedHi @lmeurs - is this module supporting for X-path while importing xml feed? Because for me in xml feed import it's not working.
Comment #63
lmeurs commented@pradeepjha: As earlier discussed in this issue I have not tested this module with X-path and other users seem to be unsuccessful at it.
Comment #64
ikeigenwijs commentedBump for when using entity reference support
Patch and code here, aplies cleanly to latest version 6
https://www.drupal.org/node/2484727#comment-9900321
Comment #65
ikeigenwijs commentedImproved version when using entity reference support that also handels the case when a view handler is being used on the field.
Patch and code here, applies cleanly to latest version 6
https://www.drupal.org/node/2484727#comment-11536381
Comment #66
maxchock commentedFirst, thanks for the effort to have such wonderful module.
I'm using the #33 module. My setting are as follow:
using feeds_tamper: explode list - the result looks like "Bedding>mattress"
pre-process replace all the ">" to ";" - the result become "Bedding;mattress"
on the import site, I selected the mapping to Product Categories: hierarchical (field_taxonomy_terms_hierarchical)
Then I start to import, but it gave me so many warning/notice and error which I have simplified such as:
Any thought?
Thanks & best regards,
Max.
Comment #67
kumkum29 commented@lmeurs
I use this module with a xml file & Feeds Tamper. For me it's ok and the importation seems to work.
This module is very very useful. Do you think create a stable/official version for this module?
Thanks.
P.S. This module seems to work but I get 1 warning after the process of importation :
Comment #68
joro78 commentedI wonder if this would be the right thread to post comment but anyway it is a issue, partly related to the module.
It works fine and thanks very much, for providing it. Anyway I am using i18n and have multilingual - hierarchical, taxonomy. My taxonomy terms have same meaning but translated names, as per a few languages.
When importing hierarchy of terms (or even flat) in English, everything is just fine.
A problem occurs, when importing translated terms on any other language. I couldn't do it so far using Feeds and/or this module. I have tested many taxonomy field types (select, autocomplete, hierarchical). None of them seems to import data from Feeds import, when the latter is in a different from English (default for site btw).
Did someone had a similar issue? Any help or advice would be appreciated.
Comment #69
IamOnStage commentedHi @lmeurs,
Amazing contribution, thank you!
I just want to report an issue with the current module. It does not seam to like taxonomy terms with a " - "
It seams ok with a letter-letter i.e. "User-Interface" but not "User - Interface"
Comment #70
joro78 commentedIs it possible to import multiple values in one taxonomy field using this module?
When I am trying to do it, saving the category lineage, with two separate fields, the import takes the results from the second field.
Should I use one field for import, with a similar structure parent > child, parent > child 2 with FEED Tamper I didn't try this so far.
Comment #71
FireHawkX commented#33 worked great, however since it needs to be created as a patch, setting to Needs work. Thanks for everyone's work on this!