def recommendation_pack(request): """Returns all recommendations types in JSON format""" customer = get_customer_from_request(request) if customer is not None: product_data = recommend_based_on_orders(customer) recommended = product_list_serializer(product_data) else: recommended = [] product_data = bestseller_products() bestseller = product_list_serializer(product_data) product_data = top_rated_products() top_rated = product_list_serializer(product_data) product_data = newest_arrival_products() newest_arrival = product_list_serializer(product_data) recommendation = { 'recommended': recommended, 'bestseller': bestseller, 'top_rated': top_rated, 'newest_arrival': newest_arrival } return JsonResponse(recommendation, safe=False)
def recommended_products(request): """Returns personally recommended products in JSON format""" customer = get_customer_from_request(request) if customer is not None: product_data = recommend_based_on_orders(customer) recommended = product_list_serializer(product_data) else: recommended = [] return JsonResponse(recommended, safe=False)
def newest_arrival(request): """Returns newest products in JSON format""" product_data = newest_arrival_products() products = product_list_serializer(product_data) return JsonResponse(products, safe=False)
def top_rated(request): """Returns top rated products in JSON format""" product_data = top_rated_products() products = product_list_serializer(product_data) return JsonResponse(products, safe=False)
def bestseller(request): """Returns bestseller products in JSON format""" product_data = bestseller_products() products = product_list_serializer(product_data) return JsonResponse(products, safe=False)