Exemplo n.º 1
0
    def get(self, request):

        # request.session.clear()

        cart_exists = request.session.get('shoppingCart', None)
        if not cart_exists:
            shoppingCart = ShoppingCart()
            request.session['shoppingCart'] = shoppingCart.to_dictionary()

        return JsonResponse(request.session['shoppingCart'])
Exemplo n.º 2
0
    def post(self, request):
        cart = json.loads(request.body)

        cart['unsavedChanges'] = False
        cart['checkoutStatus']['review'] = False

        if cart['totalItems'] == 0:
            shoppingCart = ShoppingCart()
            request.session['shoppingCart'] = shoppingCart.to_dictionary()
            return JsonResponse(
                {'shoppingCart': request.session['shoppingCart']})
        else:
            request.session['shoppingCart'] = cart

        return JsonResponse({'status': True})