Sort categories by nesting level to set correct value of the attribute if product assigned to parent and its child categories