and my view content



from django.shortcuts import render
from django.http import JsonResponse
import json
from .models import *



def store(request):
    if request.user.is_authenticated:
        customer = request.user.customer
        order, created =
Order.objects.get_or_create(customer=customer, complete=False)
        items = order.orderitem_set.all()
        cartItems = order.get_cart_items
    else:
        items = []
        order = {'get_cart_total': 0, 'get_cart_items': 0, 'shipping': False}
        cartItems = order['get_cart_items']

    products = Product.objects.all()
    context = {'products': products, 'cartItems': cartItems}
    return render(request, 'store/store.html', context)


def cart(request):
    if request.user.is_authenticated:
        customer = request.user.customer
        order, created =
Order.objects.get_or_create(customer=customer, complete=False)
        items = order.orderitem_set.all()
        cartItems = order.get_cart_items
    else:
        items = []
        order = {'get_cart_total': 0, 'get_cart_items': 0}
        cartItems = order['get_cart_items']
    context = {'items': items, 'order': order, 'cartItems': cartItems}
    return render(request, 'store/cart.html', context)


def checkout(request):
    if request.user.is_authenticated:
        customer = request.user.customer
        order, created =
Order.objects.get_or_create(customer=customer, complete=False)
        items = order.orderitem_set.all()
        cartItems = order.get_cart_items
    else:
        items = []
        order = {'get_cart_total': 0, 'get_cart_items': 0}
        cartItems = order['get_cart_items']
    context = {'items': items, 'order': order, 'cartItems': cartItems}
    return render(request, 'store/checkout.html', context)

def updateItem(request):
    data = json.loads(request.body)
    productId = data['productId']
    action = data['action']

    print('action:', action)
    print('productId:', productId)


    customer = request.user.customer
    product = Product.objects.get(id=productId)
    order, created = Order.objects.get_or_create(customer=customer,
complete=False)
    orderItem, created = OrderItem.objects.get_or_create(order=order,
product=product)

    if action == 'add':
        orderItem.quantity = (orderItem.quantity + 1)
    elif action == 'remove':
        orderItem.quantity = (orderItem.quantity - 1)

    orderItem.save()

    if orderItem.quantity <= 0:
        orderItem.delete()


    return JsonResponse('Item was added', safe=False)


Le sam. 8 août 2020 à 20:24, Agoua David <cdavidag...@gmail.com> a écrit :

> Can you send a screenshot of the view file
>
> Le sam. 8 août 2020 à 20:21, traore arouna <taroun...@gmail.com> a écrit :
>
>> Hello
>> I am here because I am developing an e-commerce application.
>> But at a certain level of my code when I run my server with the command
>> python manage runserver
>> I have an error message
>> Uncaught ReferenceError: info is not defined
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/2fdbf0c6-5f2e-4120-a524-6f3171c50389o%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/2fdbf0c6-5f2e-4120-a524-6f3171c50389o%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAByCr6gT6SJ1EHyDMTGKb6Q73rbRJXWnd7XbgOeq7WE%2BLU3sAg%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAByCr6gT6SJ1EHyDMTGKb6Q73rbRJXWnd7XbgOeq7WE%2BLU3sAg%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADjT8DY5pjin5-RGk0xUW2A%3DQVpry2NC%2BCBi8epKQtbvOV8v2w%40mail.gmail.com.

Reply via email to