This if seems reverse, also, better use $parent in the next line instead of calling getParentCategory again