Exemplo n.º 1
0
def add_to_basket(request, prod_name):
    current_user = userassert(request)

    try:
        c = Customer.objects.get(name=current_user)
    except ObjectDoesNotExist:
        c = Customer(name=current_user)
        c.save()

    try:
        basket = Basket.objects.get(current=True, customer=c)
    except ObjectDoesNotExist:
        basket = Basket(customer=c, totalbill=0, current=True)
        basket.save()

    try:
        item = basket.item_set.get(name=prod_name)
    except ObjectDoesNotExist:
        item = Item.objects.get(name=prod_name, listed=True)
        # Create an unlisted copy of item
        item.pk = None
        item.id = None
        item.wishlist_id = None
        item.listed = False
        item.save()
        basket.item_set.add(item)    

    item.purchase_quantity += int(request.POST['numofitems'])
    dis = (item.discount/100) * item.cost
    t = (item.purchase_quantity * item.cost) - dis
    item.save()
    basket.totalbill += t
    basket.save()

    return HttpResponseRedirect(reverse('osp:basket'))
Exemplo n.º 2
0
def basket(request):
    current_user = userassert(request)
    try:
        basket = Basket.objects.get(current=True, customer__name=current_user)
    except ObjectDoesNotExist:
        try:
            c = Customer.objects.get(name=current_user)
        except ObjectDoesNotExist:
            c = Customer(name=current_user)
            c.save()
        basket = Basket(customer=c, totalbill=0, current=True)
        basket.save()
    context = {'basket': basket}
    return render(request, 'osp/basket.html', context)
Exemplo n.º 3
0
def wishlist(request):
    current_user = userassert(request)
    try:
        wishlist = Wishlist.objects.get(customer__name=current_user)
    except ObjectDoesNotExist:
        try:
            c = Customer.objects.get(name=current_user)
        except ObjectDoesNotExist:
            c = Customer(name=current_user)
            c.save()
        wishlist = Wishlist(customer=c)
        wishlist.save()
    context = {'wishlist': wishlist}
    return render(request, 'osp/wishlist.html', context)
Exemplo n.º 4
0
def add_to_wishlist(request, prod_name):
    current_user = userassert(request)
    item = Item.objects.get(name=prod_name, listed=True)
    try:
        c = Customer.objects.get(name=current_user)
    except:
        c = Customer(name=current_user)
        c.save()

    try:
        wishlist = Wishlist.objects.get(customer__name=current_user)
    except ObjectDoesNotExist:
        wishlist = Wishlist(customer=c)
        wishlist.save()
    wishlist.item_set.add(item)
    return HttpResponseRedirect(reverse('osp:wishlist'))
Exemplo n.º 5
0
def add_to_basket(request, prod_name):
    #item = get_object_or_404(Item, pk=request.POST['item'])
    item = Item.objects.get(name=prod_name)
    try:
        c = Customer.objects.get(name='defaultguest')
    except:
        c = Customer(name='defaultguest')
        c.save()

    t = item.purchase_quantity * item.cost

    try:
        basket = Basket(customer=c, totalbill=t)
        basket.save()
    except IntegrityError:
        basket = Basket.objects.get(customer=c)
        basket.totalbill += t

    basket.item_set.add(item)
    return HttpResponseRedirect(reverse('osp:basket', args=(basket, )))
Exemplo n.º 6
0
def add_to_basket(request, prod_name):
    #item = get_object_or_404(Item, pk=request.POST['item'])
    item = Item.objects.get(name=prod_name)
    try:
        c = Customer.objects.get(name='defaultguest')
    except:
        c = Customer(name='defaultguest')
        c.save()

    t = item.purchase_quantity * item.cost
    
    try:
        basket = Basket(customer=c, totalbill=t)
        basket.save()
    except IntegrityError:
        basket = Basket.objects.get(customer=c)
        basket.totalbill += t

    basket.item_set.add(item)    
    return HttpResponseRedirect(reverse('osp:basket', args=(basket,)))