Exemplo n.º 1
0
def coupon_apply(request):
    now = timezone.now()
    form = CouponApplyForm(request.POST)
    if form.is_valid():
        code=form.cleaned_data['code']
        try:
            coupon= Coupon.objects.get(code__iexact=code,valid_from__lte=now, valid_to__gte=now,active=True)
            request.session['coupon_id']= coupon.id
        except Coupon.DoesNotExist:
            request.session['coupon_id']= None

    return redirect('cart:cart_detail')
Exemplo n.º 2
0
def cart_detail(request):
    user_id = ''
    if request.user.is_authenticated:
        user_id = request.user.id
    cart = Cart(request)
    data1 = []
    data = []
    m = len(cart)
    if m == 0:
        return redirect('myshop:home')

    for item in cart:
        item['update_quantity_form'] = CartAddProductFrom(
            initial={
                'quantity': item['quantity'],
                'update': True
            })

        coupon_apply_form = CouponApplyForm()

    for item1 in cart:
        objects = item1['product']
        data1.append({
            'images':
            Upload_images.objects.filter(image_id__id=objects.id),
            'product_size':
            Size_quantity.objects.filter(product__id=objects.id)
        })

    category = Category.objects.all().order_by('created')
    for category in category:
        data.append({
            'category':
            category,
            'sub_categories':
            Sub_Category.objects.filter(categories__id=category.id)
        })
    user = request.user

    return render(
        request, 'cart.html', {
            'cart': cart,
            'coupon_apply_form': coupon_apply_form,
            'data1': data1,
            'data': data,
            'user': user,
            'id': user_id
        })
Exemplo n.º 3
0
def cart_detail(request):
    cart = Cart(request)
    for item in cart:
        item['update_quantity_form'] = CartAddProductForm(
            initial={
                'quantity': item['quantity'],
                'override': True
            })
    coupon_apply_form = CouponApplyForm()

    r = Recommender()
    cart_products = [item['product'] for item in cart]
    recommended_products = r.suggest_products_for(cart_products, max_results=4)

    return render(
        request, 'cart/detail.html', {
            'cart': cart,
            'coupon_apply_form': coupon_apply_form,
            'recommended_products': recommended_products
        })
Exemplo n.º 4
0
def cart_detail(request, total=0, counter=0, cart_items=None, subtotal=0):
    coupon_apply_form = CouponApplyForm()

    try:
        cart = Cart.objects.get(cart_id=_cart_id(request))
        cart_items = CartItem.objects.filter(cart=cart, active=True)
        for cart_item in cart_items:
            total += (cart_item.discountPrice * cart_item.quantity)
            counter += cart_item.quantity
    except ObjectDoesNotExist:
        pass

    subtotal = total
    request.session['subtotal'] = str(subtotal)

    return render(
        request, 'cart.html',
        dict(cart_items=cart_items,
             total=total,
             counter=counter,
             subtotal=subtotal,
             coupon_apply_form=coupon_apply_form))
Exemplo n.º 5
0
def cart_detail(request):
    """
    List cart items.
    Accept coupon for discount.
    """

    cart = Cart(request)

    if cart.cart:
        for item in cart:
            item['update_quantity_form'] = CartAddProductForm(
                initial={
                    'quantity': item['quantity'],
                    'override': True
                })

        coupon_form = CouponApplyForm()
        return render(request, 'cart/cart_detail.html', {
            'cart': cart,
            'coupon_form': coupon_form
        })

    return redirect('shop:product-list')