def cupon_aplly(request): now = timezone.now() form = CuponApllyForm(request.POST) if form.is_valid(): code = form.cleaned_data['code'] try: cupon = Cupon.objects.get( code__iexact=code, valid_from__lte=now, valid_to__gte=now, active=True, ) request.session['cupon_id'] = cupon.id except Cupon.DoesNotExist: request.session['cupon_id'] = None return redirect('cart:cart_detail')
def CartDetail(request): cart = Cart(request) for item in cart: item['update_quantity_form'] = CartAddProductForm( initial={ 'quantity': item['quantity'], 'update': True }) cupon_apply_form = CuponApllyForm() return render(request, 'cart/detail.html', {'cart': cart, 'cupon_apply_form': cupon_apply_form})
def CartDetail(request): cart = Cart(request) for item in cart: item['update_quantity_form'] = CartAddProductFormAuto( initial={ 'quantity': item['quantity'], 'update': True }) cupon_apply_form = CuponApllyForm() has_cupons = Cupon.objects.filter(active=True).count() return render(request, 'cart.html', {'cart': cart, 'cupon_apply_form': cupon_apply_form, 'has_cupons': has_cupons})
def cart_detail(request): cart = Cart(request) for item in cart: item['update_quantity_form'] = CartAddProductForm( initial={ 'quantity': item['quantity'], 'update': True, }) cupon_aplly_form = CuponApllyForm() context = { 'cart': cart, 'cupon_aplly_form': cupon_aplly_form, } return render(request, 'cart/cart_detail.html', context)