question

global-imports7 avatar image
0 Likes"
global-imports7 asked

GetCategoryInfo namepaths

Here is the result of a category: stdClass Object ( [CategoryID] => 150009 [CategoryLevel] => 4 [CategoryName] => 1800-1934 [CategoryParentID] => 713 [CategoryNamePath] => Collectibles:Cultures & Ethnicities:Native American: US:1800-1934 [CategoryIDPath] => 1:3913:713:150009 [LeafCategory] => ) I would like to parse out the CategoryNamePath. Only problem is that some categories have ":" in the name.. like above! Is there a simpler way to do it (and using less calls) without resorting to using the CategoryIDPath and getting the CategoryName for each ID one by one and then rebuilding the name path?
getcategoryinfo
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

clickimusprime avatar image
0 Likes"
clickimusprime answered
It would be nice to have this reliable and have Path and ID added to Finding API. It's a very easy way to build breadcrumbs. Same info is returned by Shopping. You could scan all categories offline and flag the ones that have mismatches in the colon counts and put in exception code in your production system to correct these before processing. Otherwise, you have to walk the path. Start from the end and back up until you find a category with a colon in the name.
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

helios825 avatar image
0 Likes"
helios825 answered
The hack I use is to do a simple full string replace on the path and replace ": " (colon+space) with something else, like hyphen+space, or just a space. AFAIK, when colons are used in the category name, a space always follows. So I can search/replace based on that.
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

helios825 avatar image
0 Likes"
helios825 answered
... and that leaves just colons being the subcategory delimiters that we expect and can further parse on.
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

clickimusprime avatar image
0 Likes"
clickimusprime answered
**a space always follows.** Ahh good to know, thanks.
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

global-imports7 avatar image
0 Likes"
global-imports7 answered
Thanks helios.. I should have thought of that! I did the long way of walking the CategoryIDPath to get the CategoryName (only for categories with : in the name). Then I cached these calls... But this sounds a lot easier and faster!
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.