Exemplo n.º 1
0
def orderAddPayment(request):
    cart = requestCurCart(request)
    if int(cart.get_item_count()) > 0:
        errormsg = None
        if request.method == 'POST':
            try:
                payment = request.POST['payment']
                pay = Payment.objects.get(code=payment)
                try:
                    order = Order.objects.get(id=request.session['order_id'],user=request.user,order_date__isnull=True)
                    order.paymenttype = pay
                    order.save()
                except:
                    return render_to_response('error.html', {
                        'errormsg': 'Bestellung nicht gefunden.',
                    },context_instance=RequestContext(request))
                return HttpResponseRedirect(reverse('shoppy_order_overview'))
            except:
                errormsg = u'Bitte wählen Sie ein Zahlungsverfahren aus.'
        if decimal.Decimal(cart.get_total()) > decimal.Decimal(settings.SHOPPY_MAX_BILL_AMOUNT):
            paynamelist = Paymentname.objects.all().filter(language=Language.objects.get(code=settings.SHOPPY_DEFAULT_LANGUAGE_CODE),payment__pay_first=True)
        else:
            paynamelist = Paymentname.objects.all().filter(language=Language.objects.get(code=settings.SHOPPY_DEFAULT_LANGUAGE_CODE))
        return render_to_response('shop/payment_form.html', {
                        'hideRightNavi':True,
                        'hideLeftNavi':True,
                        'paynamelist': paynamelist,
                        'errormsg': errormsg,
                        },context_instance=RequestContext(request))
    else:
        return HttpResponseRedirect(reverse('shoppy_cart'))
Exemplo n.º 2
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)
Exemplo n.º 3
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)
Exemplo n.º 4
0
def cartRemoveMix(request, mix_id):
    try:
        cart = requestCurCart(request)
        p = MixProduct.objects.get(id=mix_id)
        CartMixProduct.objects.get(cart=cart,product=p).delete()
        return HttpResponseRedirect(reverse('shoppy_cart'))
    except (TypeError, ValueError, KeyError, MixProduct.DoesNotExist):
        return HttpResponseRedirect(reverse('shoppy_cart'))
Exemplo n.º 5
0
def cartDisplay(request):
    cart = requestCurCart(request)
    cproducts = CartProduct.objects.all().filter(cart=cart)
    cmixes = CartMixProduct.objects.all().filter(cart=cart)
    cartcoupon = CartCoupon.objects.all().filter(cart=cart)
    couponmoney = decimal.Decimal('0.00')
    for cc in cartcoupon:
        couponmoney += cc.coupon.valueMoney
    couponmoney = moneyfmt(couponmoney, places=2, dp=',', sep='.')
    context = RequestContext(request, {
        'cart': cart,
        'cproducts': cproducts,
        'cmixproducts': cmixes,
        'couponmoney': couponmoney
        })
    return render_to_response('shop/cart.html', context)
Exemplo n.º 6
0
def orderAddBillContact(request):
    form = AddContactForm()
    cart = requestCurCart(request)
    if int(cart.get_item_count()) > 0:
        #form = None

        if request.method == 'POST':
            contact = None
            try:
                addrID = request.POST['addressID']
            except (KeyError):
                addrID = None
            if addrID:
                contact = Contact.objects.get(user=request.user,id=addrID)
            else:
                form = AddContactForm(request.POST)
                if form.is_valid():
                    contact = form.save(request)
            if contact:
                try:
                    orderid = request.session['order_id']
                    order = Order.objects.get(id=orderid,order_date__isnull=True)
                except:
                    order = Order()
                order.user = request.user
                order.cart = cart
                order.billing_addr = contact
                try:
                    if not order.delivery_addr:
                        order.delivery_addr = contact
                except:
                    order.delivery_addr = contact
                order.save()
                request.session['order_id'] = order.id
                return HttpResponseRedirect(reverse('shoppy_order_deliverycontact'))

        
        contact_list = Contact.objects.all().filter(user=request.user,isActive=True)

        return render_to_response('shop/bill_contact_form.html', {
                    'form': form,
                    'contact_list': contact_list,
                    'hideRightNavi':True,
                    'hideLeftNavi':True
                },context_instance=RequestContext(request))
    else:
        return HttpResponseRedirect(reverse('shoppy_cart'))
Exemplo n.º 7
0
def cartPreview(context):
    request = context['request']
    cart = requestCurCart(request)
    cproducts = CartProduct.objects.all().filter(cart=cart)
    cmixproducts = CartMixProduct.objects.all().filter(cart=cart)
    return {'cart': cart, 'cproducts': cproducts, 'cmixproducts': cmixproducts, 'request': request}
Exemplo n.º 8
0
def orderOverview(request):
    cart = requestCurCart(request)
    if int(cart.get_item_count()) > 0:
        try:
            order = Order.objects.get(id=request.session['order_id'], user=request.user,order_date__isnull=True)
            # Wurde Bestellung abgeschickt?
            if request.method == 'POST':
                order.order_date = datetime.datetime.now()
                # copy the current shipping fee
                order.shipping_cost = decimal.Decimal('%s' % order.cart.get_shipping_fee())
                order.save()
                order.billnumber()
                #Speichern, dass Cart bestellt wurde
                order.cart.isActive = False
                order.cart.isOrdered = True
                order.cart.save()
                # Kopie anlegen, wenn Cart einen Namen hat
                # ansonsten kann ein Cart doppelt bestellt werden
                if order.cart.name:
                    # neuen Cart mit alten Cart-Daten erstellen
                    newcart = Cart()
                    newcart.name = order.cart.name
                    newcart.user = order.cart.user
                    newcart.save()
                    # Produkte aus altem Cart in neuen legen
                    for cp in CartProduct.objects.filter(cart=order.cart):
                        newcp = CartProduct(cart=newcart)
                        newcp.product = cp.product
                        newcp.amount = cp.amount
                        newcp.save()
                    # MixedProdukte aus altem Cart in neuen legen
                    for mcp in CartProduct.objects.filter(cart=order.cart):
                        newmcp = CartMixProduct(cart=newcart)
                        newmcp.product = mcp.product
                        newmcp.amount = mcp.amount
                        newmcp.save()
                # Die verwendeten Gutscheine entwerten
                ccs = CartCoupon.objects.filter(cart=order.cart)
                for cc in ccs:
                    # ist der Gutschein ein einmaliger Gutschein?
                    if cc.coupon.isgift == True:
                        cc.coupon.isValid = False
                        cc.coupon.valid_to = datetime.datetime.now()
                        cc.coupon.save()
                # Restguthaben von Gutscheinen dem Guthabenkonto gutschreiben
                if decimal.Decimal(order.cart.get_total_with_fee()) < decimal.Decimal('0.00'):
                    try:
                        cacc = CouponAccount.objects.get(user=request.user)
                    except CouponAccount.DoesNotExist:
                        cacc = CouponAccount(user=request.user,
                                             balance=0
                                             )
                        cacc.save()

                    ctrans = CouponAccountTransaction(cacc=cacc)
                    ctrans.amount = decimal.Decimal(order.cart.get_total_with_fee()) * -1
                    ctrans.message = 'Restguthaben von Bestellung %s' % order.billnumber()
                    ctrans.isValid = False
                    ctrans.save()
                    cacc.balance += decimal.Decimal(order.cart.get_total_with_fee()) * -1
                    cacc.save()
                
                sendOrderMail(order)
                sendOrderMailAdmin(order)
                if order.paymenttype.code == 'bill':
                    return HttpResponseRedirect(reverse('shoppy_order_thanks'))
                else:
                    return HttpResponseRedirect(reverse('shoppy_custom_order_view',args=[order.id]))
            cart = order.cart
            cartitems = CartProduct.objects.all().filter(cart=cart)
            cartmixitems = CartMixProduct.objects.all().filter(cart=cart)
            cartcoupon = CartCoupon.objects.all().filter(cart=cart)
            couponmoney = decimal.Decimal('0.00')
            for cc in cartcoupon:
                couponmoney += cc.coupon.valueMoney
            couponmoney = moneyfmt(couponmoney, places=2, dp=',', sep='.')
            return render_to_response('shop/overview.html',{
                                    'order': order,
                                    'couponmoney': couponmoney,
                                    'cartitems': cartitems,
                                    'cartmixitems': cartmixitems,
                                    'hideRightNavi':True,
                                    'hideLeftNavi':True
                                    },context_instance=RequestContext(request))
        except Order.DoesNotExist, KeyError:
            return render_to_response('error.html', {
                    'errormsg': 'Oooops. Da lief wohl was falsch!',
                },context_instance=RequestContext(request))