#NEWLINE# def get_current_category( self , request ) : #NEWLINE# #INDENT# '\n        Returns product category based on actual categories of the given product\n        and the last visited category.\n\n        This is needed if the category has more than one category to display\n        breadcrumbs, selected menu points, etc. appropriately.\n        ' #NEWLINE# last_category = None #NEWLINE# category = None #NEWLINE# product_categories = self . get_categories ( ) #NEWLINE# if ( len ( product_categories ) >= 1 ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# if ( len ( product_categories ) == 1 ) : #NEWLINE# #INDENT# category = product_categories [ 0 ] #NEWLINE# return category #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# last_category = request . session . get ( 'last_category' ) #NEWLINE# #UNINDENT# if ( last_category is None ) : #NEWLINE# #INDENT# return product_categories [ 0 ] #NEWLINE# #UNINDENT# category = None #NEWLINE# if ( last_category in product_categories ) : #NEWLINE# #INDENT# category = last_category #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# children = last_category . get_all_children ( ) #NEWLINE# for product_category in product_categories : #NEWLINE# #INDENT# if ( product_category in children ) : #NEWLINE# #INDENT# category = product_category #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( category is None ) : #NEWLINE# #INDENT# category = product_categories [ 0 ] #NEWLINE# #UNINDENT# #UNINDENT# except IndexError : #NEWLINE# #INDENT# category = None #NEWLINE# #UNINDENT# #UNINDENT# request . session [ 'last_category' ] = category #NEWLINE# return category