Esempio n. 1
0
def cartAddMix(request, mix_id):
    cart = requestCurCart(request)
    try:
        product = MixProduct.objects.get(id=mix_id)
        amount = 1
        if request.method == 'POST':
            form = CartAddForm(request.POST)
            if form.is_valid():
                amount = form.cleaned_data['amount']
        cartmixproduct = CartMixProduct.objects.get(cart=cart,product=product)
        cartmixproduct.amount += amount
    except CartMixProduct.DoesNotExist:
        cartmixproduct = CartMixProduct()
        cartmixproduct.cart = cart
        cartmixproduct.product = product
        cartmixproduct.amount = amount
    except (TypeError, ValueError, KeyError):
        return HttpResponseRedirect(request.META['HTTP_REFERER'])
    cartmixproduct.product.isActive = False
    cartmixproduct.product.save()
    cartmixproduct.save()
    try:
        if mix_id == request.session['mix_id']:
            del request.session['mix_id']
    except:
        pass
    # ähnliche mixes erstellen
    
    context = RequestContext(request, {
        'mixproduct':cartmixproduct.product,
        })
    return render_to_response('shop/cart_added.html', context)
Esempio n. 2
0
def cartAdd(request, product_id):
    cart = requestCurCart(request)
    try:
        product = Product.objects.get(id=product_id,isActive=True)
        amount = 1
        if request.method == 'POST':
            form = CartAddForm(request.POST)
            if form.is_valid():
                amount = form.cleaned_data['amount']
        cartproduct = CartProduct.objects.get(cart=cart,product=product)
        if product.max_order_amount == -1 or (cartproduct.amount + amount) < product.max_order_amount:
            cartproduct.amount += amount
        else:
            cartproduct.amount = product.max_order_amount
            cartproduct.save()
            msg = 'Das Produkt ist auf %s Bestellung(en) limitiert.' % product.max_order_amount
            return render_to_response('error.html', {
                        'errormsg': msg,
                        'caption' : 'Hinweis',
                    },context_instance=RequestContext(request))
    except CartProduct.DoesNotExist:
        cartproduct = CartProduct()
        cartproduct.cart = cart
        cartproduct.product = product
        cartproduct.amount = amount
    except (TypeError, ValueError, KeyError):
        return HttpResponseRedirect(request.META['HTTP_REFERER'])
    cartproduct.save()
    context = RequestContext(request, {
        'product':cartproduct.product,
        })
    return render_to_response('shop/cart_added.html', context)