コード例 #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'))
コード例 #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)
コード例 #3
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, )))
コード例 #4
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,)))