Ive been through several answers before succumbing to ask a question. I will list what i tried and why i think this is a bit of a special case, and not a duplicate.
Am reading a .csv file from my customer. Each product has 3 fields for the category (among other fields, sku, name, weight etc).
[ParentCategoryType] => CLOTHING [ParentCategory] => SHIRTS [Category] => SHIRTS CASUAL [Gender] => MEN
What I want is to create the category if it does not exist, in the tree. I.e. The current item's tree is
but there is also a similar category starting with Women/Clothing/Shirts/Shirts Casual
I would like to check if given the current tree, there is such a category and if not add it. I realize maybe this will need to be recursive, so it can add the categories in between. For example maybe Men/Clothing/Shirts doesn't exist, and needs to add Shirts, and then Shirts Casual
- This answer here , which causes error 500
- This answer here, which kinda works (it adds a category so if i recurse my list maybe ill manage) BUT this seems messy and maybe does stuff it doesn't need.
- and many other similar, others being very vague and others outdated.
Given the string
I want to create the tree accordingly, so when given Men/Clothing/Pants, only pants should be created, and when given
Women/Clothing/Shirts/Shirts Casual, another tree with root Women is created