Beispiel #1
0
def show_cart(request):
    if request.method == 'POST':
        post_data = request.POST.copy()
        if 'submit_remove.x' in post_data:
            cart.remove_from_cart(request)
        if 'submit_update.x' in post_data:
            cart.update_cart(request)
    cart_item_count = cart.cart_distinct_item_count(request)
    cart_items = cart.get_cart_items(request)
    # mostrar el panel amarillo con infos muy importantes(1 de solo 2)
    if request.user.is_authenticated():
        try:
            promo4 = Promo4.objects.get(winner_user=request.user, active=True)
            small_text = "Ud. ha sido el ganador de una rifa, y ahora puede comprar estos productos<br/>"
            big_text = "Por un descuento del %d%%" % promo4.discount
        except Promo4.DoesNotExist:
            code, discount_ = get_discount_code(request)
            small_text = u"Puedes usar tu código de descuento aquí. %s%%" % discount_
            big_text = code

    total, discount, promotions, cart_subtotal, shipping_tax, shipping_tax_promotions = promo(
        request, cart_item_count, cart_items)
    page_title = 'Shopping Cart'
    return render_to_response('cart/show_cart.html',
                              locals(),
                              context_instance=RequestContext(request))
Beispiel #2
0
    def test_remove_unknown_item(self):
        with f.app_context():
            cart.my_cart = None
            cart.create()

            with pytest.raises(NotFound):
                cart.remove_from_cart('Noisy crow')
Beispiel #3
0
def show_cart(request):
	template = 'cart/cart.html'

	if request.method == 'POST':
		postdata = request.POST.copy()
		
		if 'remove' in postdata:
			cart.remove_from_cart(request) 

		if 'update' in postdata:
			cart.update_cart(request) 

		if 'Checkout' in postdata:
			checkout_url = checkout.get_checkout_url(request)
			return HttpResponseRedirect(checkout_url)
	
	cart_items = cart.get_cart_items(request)
	page_title = 'Shopping Cart'
	cart_subtotal = cart.cart_subtotal(request)
	
	context = {
			  'cart_items': cart_items,
			  'page_title': page_title,
			  'cart_subtotal': cart_subtotal,
			  }
	return render(request, template, context) 
Beispiel #4
0
def show_cart(request, template_name="cart/cart.html"): 
    if request.method == 'POST': 
        postdata = request.POST.copy() 
        if postdata['submit'] == 'Remove': 
            cart.remove_from_cart(request) 
        if postdata['submit'] == 'Update': 
            cart.update_cart(request) 
    cart_items = cart.get_cart_items(request) 
    page_title = 'Shopping Cart' 
    cart_subtotal = cart.cart_subtotal(request) 
    return render_to_response(template_name, locals(),context_instance=RequestContext(request))
Beispiel #5
0
def show_cart(request, template_name='cart/cart.html'):
    if request.method == "POST":
        postdata = request.POST.copy()
        if postdata['submit'] == "Remove":
            cart.remove_from_cart(request)
        if postdata['submit'] == "Update":
            cart.update_cart(request)
    cart_items = cart.get_cart_items(request)
    page_title = "Shopping Cart"
    cart_subtotal = cart.cart_subtotal(request)
    return render_to_response(template_name, locals(), RequestContext(request))
Beispiel #6
0
def show_cart(request):
    cart_items = cart.get_cart_items(request)

    if request.method == 'POST':
        postdata = request.POST.copy()
        if 'update' in postdata.keys():
            cart.update_cart(request)
        if 'remove' in postdata.keys():
            cart.remove_from_cart(request)
            
    cart_subtotal = cart.get_cart_subtotal(request)
    total = cart_subtotal
    return render_to_response('irteerak/cart.html',locals(),context_instance=RequestContext(request))
Beispiel #7
0
def show_cart(request, template_name = 'cart/cart.html'):
    if request.method == 'POST':
        postdata = request.POST.copy()
        if postdata['submit']=='Remove':
            cart.remove_from_cart(request)
        if postdata['submit']=='Update':
            cart.update_cart(request)
    cart_item = cart.get_cart_items(request)
    cart_id = cart._cart_id(request)
    page_title = 'Корзина'
    cart_subtotal = cart.cart_subtotal(request)
    context = {'cart_item': cart_item, 'cart_id': cart_id, 'cart_subtotal': cart_subtotal}
    return render(request, template_name, context)
Beispiel #8
0
def show_cart(request, template_name="cart/cart.html"):
    if request.method == "POST":
        postdata = request.POST.copy()
        if postdata['submit'] == "Remove":
            cart.remove_from_cart(request)
        if postdata['submit'] == "Update":
            cart.update_cart(request)
            
    cart_items = cart.get_cart_items(request)
    page_title = 'Shopping Cart'
    cart_subtotal = cart.cart_subtotal(request)

    return render_to_response(template_name, locals(),
                              context_instance=RequestContext(request))
Beispiel #9
0
def show_cart(request):
    if request.method == 'POST':
        postdata = request.POST.copy()
        if postdata['submit'] == 'Remove':
            cart.remove_from_cart(request)
        if postdata['submit'] == 'Update':
            cart.update_cart(request)
        if postdata['submit'] == 'Checkout':
            checkout_url = checkout.get_checkout(request)
            return HttpResponseRedirect(checkout_url)
    cart_items = cart.get_cart_items(request)
    page_title = 'Shopping Cart'
    cart_subtotal = cart.cart_subtotal(request)
    return render(request, 'cart/cart.html', locals())
Beispiel #10
0
def show_cart(request, template_name="cart/show_cart.html"):
    page_title = 'Musical Instruments and Sheet Music for Musicians'
    if request.method == 'POST':
        post_data = request.POST.copy()
        if post_data['submit'] == "Update":
            cart.update_cart(request)
        if post_data['submit'] == 'Remove':
            cart.remove_from_cart(request)

    cart_subtotal = cart.cart_subtotal(request)    
    cart_items =  cart.get_cart_items(request)
    
    
    return render_to_response(template_name, locals(),
                              context_instance=RequestContext(request))
Beispiel #11
0
def show_cart_page(request):
	categories = Product.objects.values_list('category_name', flat = True ).distinct()
	if request.method == 'POST':
		postdata = request.POST.copy()
		if postdata['submit'] == 'Update':
			update_cart(request)
			orders = request.session.get('cart', '')
			cart_sum = cart_total(request)
			return render(request, "frontend/shoppingcart.html", locals())
		if postdata['submit'] == 'Delete':
			remove_from_cart(request)

	orders = request.session.get('cart', '')
	cart_sum = cart_total(request)
	return render(request, "frontend/shoppingcart.html", locals())
Beispiel #12
0
def show_cart(request, template_name="cart/cart.html"):
    if request.method == 'POST':
        postdata = request.POST.copy()
        if postdata['submit'] == 'Remove':
            cart.remove_from_cart(request)
        if postdata['submit'] == 'Update':
            cart.update_cart(request)
        if postdata['submit'] == 'Checkout':
            checkout_url = checkout.get_checkout_url(request)
            return HttpResponseRedirect(checkout_url)
    cart_items = cart.get_cart_items(request)
    page_title = 'Shopping Cart'
    cart_subtotal = cart.cart_subtotal(request)
    # need for Google Checkout button
    #merchant_id = settings.GOOGLE_CHECKOUT_MERCHANT_ID
    return render_to_response(template_name, locals(),context_instance=RequestContext(request))
Beispiel #13
0
def show_cart(request, template_name="cart/cart.html"):
    categories = Category.objects.all()
    if request.method == "POST":
        postdata = request.POST.copy()
        if postdata["submit"] == "Remove":
            cart.remove_from_cart(request)
        if postdata["submit"] == "Update":
            cart.update_cart(request)
        if postdata["submit"] == "Checkout":
            checkout_url = checkout.get_checkout_url(request)
            return HttpResponseRedirect(checkout_url)
    cart_items = cart.get_cart_items(request)
    page_title = "Shopping Cart"
    cart_subtotal = cart.cart_subtotal(request)
    # for Google Checkout button
    merchant_id = settings.GOOGLE_CHECKOUT_MERCHANT_ID
    return render_to_response(template_name, locals(), context_instance=RequestContext(request))
Beispiel #14
0
def show_cart(request, template_name="cart/cart.html"):
  """Displays the shopping cart page
  """
  context = set_context(request, Context({
    'page_title': 'Shopping Cart',
  }))

  if request.method == 'POST':
    postdata = request.POST.copy()
    if postdata['submit'] == 'Remove':
      cart.remove_from_cart(request)
    if postdata['submit'] == 'Update':
      cart.update_cart(request)

  context['cart_items'] = cart.get_cart_items(request)
  context['cart_subtotal'] = cart.cart_subtotal(request)

  return render(request, template_name, context)
Beispiel #15
0
def show_cart(request, template_name="cart/cart.html"):
    categories = Category.objects.all()
    if request.method == 'POST':
        postdata = request.POST.copy()
        if postdata['submit'] == 'Remove':
            cart.remove_from_cart(request)
        if postdata['submit'] == 'Update':
            cart.update_cart(request)
        if postdata['submit'] == 'Checkout':
            checkout_url = checkout.get_checkout_url(request)
            return HttpResponseRedirect(checkout_url)
    cart_items = cart.get_cart_items(request)
    page_title = 'Shopping Cart'
    cart_subtotal = cart.cart_subtotal(request)
    # for Google Checkout button
    merchant_id = settings.GOOGLE_CHECKOUT_MERCHANT_ID
    return render_to_response(template_name,
                              locals(),
                              context_instance=RequestContext(request))
Beispiel #16
0
def show_cart(request, template_name="cart.html"):
    if request.method == 'POST':
        postdata = request.POST.copy()
        s = postdata['submit']
        c = u'\uf021'
        r = u'\uf00d'

        if postdata['submit'] == r:
            cart.remove_from_cart(request)

        if postdata['submit'] == c:
            cart.update_cart(request)

    cart_items = cart.get_cart_items(request)
    page_title = "Ваш Заказ"
    cart_subtotal = cart.cart_subtotal(request)
    cart_distinct = cart.cart_distinct_item_count(request)

    categories = Category.objects.filter(is_active=True)
    brands = Brand.objects.filter(is_active=True)

    return render_to_response(template_name, locals(), context_instance=RequestContext(request))
Beispiel #17
0
def show_cart(request, template_name="cart/cart.html"):
    cart_item_count = cart.cart_item_count(request)
    if request.method == 'POST':
        postdata = request.POST.copy()
        print postdata
        if postdata['submit'] == u'Удалить':
            cart.remove_from_cart(request)
            message = u'Товар удален из корзины.'
            messages.success(request, message)
        if postdata['submit'] == u'Сохранить':
            cart.update_cart(request)
            message = u'Изменения приняты.'
            messages.success(request, message)
        return redirect('show_cart')
    cart_items = cart.get_cart_items(request)
    page_title = u'Корзина'
    cart_total = cart.cart_total(request)
    torgpred = False
    user = request.user
    if user.groups.filter(name=u'Торговые представители').exists():
        torgpred = True
    return render_to_response(template_name, locals(), context_instance=RequestContext(request))
Beispiel #18
0
def show_cart(request, template_name="cart/cart.html"):
    if request.method == 'POST':
        subtotal_class = cart.Subtotal(request)
        cart_items = cart.get_cart_items(request)
#        cart_subtotal = subtotal_class.subtotal()
        discount = subtotal_class.discount
        postdata = request.POST.copy()
        form = OrderForm(request.POST)

        if 'Remove' in postdata:
            cart.remove_from_cart(request)
        if 'Update' in postdata:
            cart.update_cart(request)
        if form.is_valid():
            # Пишу клиента в базу
            cart.save_client(request, form)
            # Удаляю сессию у клиента
            del request.session['cart_id']
            is_order = 1
            # Отправляем админу смс
            if SEND_SMS:
                cart.send_sms(cart_items, form)
            # Отправляем админу email
            if SEND_EMAIL:
                cart.send_admin_email(request, cart_items, form)
                if form.cleaned_data['email']:
                    # Отправляем email клиенту
                    cart.send_client_email(cart_items, form)
    else:
        form = OrderForm()

    cart_items = cart.get_cart_items(request)
#    if cart_items:
#        subtotal_class = cart.Subtotal(request)
#        cart_subtotal = subtotal_class.subtotal()
#        discount = subtotal_class.discount
    page_title = 'Корзина'
    return render_to_response(template_name, locals(), context_instance=RequestContext(request))
Beispiel #19
0
    def test_remove_item_not_in_cart(self):
        with f.app_context():
            cart.my_cart = None
            cart.create()

            cart.add_to_cart('Turtle dove')
            cart.remove_from_cart('Turtle dove')
            with pytest.raises(NotAcceptable):
                cart.remove_from_cart('Turtle dove')
            with pytest.raises(NotAcceptable):
                cart.remove_from_cart('Chachalaca')
Beispiel #20
0
    def test_remove_items(self):
        with f.app_context():
            cart.my_cart = None
            cart.create()

            cart.add_to_cart('Turtle dove')
            cart.add_to_cart('Turtle dove')
            cart.add_to_cart('French hen')
            cart.remove_from_cart('Turtle dove')
            cartstruct = cart.view_cart()
            assert cartstruct['total'] == Decimal('22.42')
            assert cartstruct['items'] == [
                {'product': DOVE, 'quantity': 1},
                {'product': HEN, 'quantity': 1}
            ]

            cart.remove_from_cart('Turtle dove')
            cart.remove_from_cart('French hen')
            cartstruct = cart.view_cart()
            assert cartstruct['total'] == Decimal('0')
            assert cartstruct['items'] == []
Beispiel #21
0
def cart_view(request, template_name="cart/cart.html"):
    """Представление для отображения корзины"""

    postdata = request.POST.copy()

    if request.method == 'POST':

        if postdata.has_key('add'):
            cart.add_to_cart(request)
            order = cart.get_cart(request)
            # res = {'order': order, }
            # html = render_to_string('cart/summary.html', res, context_instance=RequestContext(request))
            # return JsonResponse({
            #     'success': True,
            #     'action_add': True,
            #     'panel_html': html,
            # })
        if postdata.has_key('remove'):
            cart.remove_from_cart(request)

        if postdata.has_key('update'):
            cart.update_cart(request)

        if postdata.has_key('update') or postdata.has_key('remove') or postdata.has_key('add'):
            order = cart.get_cart(request)
            formset = OrderFormset(instance=order)
            res = {
                'order_form': DefaultOrderForm(request.POST),
                'formset': formset,
                'order': order,
                'keep': BASKET_OPTIONS_USE_KEEP,
                'delete': True,
            }
            html = render_to_string('cart/cart_table.html', res, context_instance=RequestContext(request))
            panel_html = render_to_string('cart/summary.html', res, context_instance=RequestContext(request))
            return JsonResponse({
                'success': True,
                # 'action_remove': True,
                'html': html,
                'panel_html': panel_html,
            })

        # if postdata.has_key('checkout'):
        #     checkout_url = checkout.get_checkout_url(request)
        #     return HttpResponseRedirect(checkout_url)
    # Получаем список всех товаров в корзине из cookies
    #cart_item_count = cart.cart_item_count(request)
    # cart_items = cart.get_cart_items(request)
    # cart_subtotal = cart.cart_subtotal(request)
    # return render_to_response(template_name, locals(),
    #                           context_instance=RequestContext(request))

    form = DefaultOrderForm(postdata or None)
    order = cart.get_cart(request)

    if form.is_valid() and order.goods > 0:
        contact = form.save(commit=False)
        contact.order = order
        contact.save()

        remote_address = request.META.get('REMOTE_ADDR')
        order.ip_address=remote_address
        order.status = 2
        order.save()

        return HttpResponseRedirect(reverse('cart:cart_confirm'))

    # else:
    #     return HttpResponseRedirect(reverse('cart:show_cart'))

    # order = cart.get_cart(request)
    formset = OrderFormset(instance=order)
    # form = DefaultOrderForm(postdata or None)
    return {
        'order_form': form,
        'formset': formset,
        'order': order,
        'keep': BASKET_OPTIONS_USE_KEEP,
        'delete': True,
    }
def remove_cart(request):
    cart.remove_from_cart(request)
    return HttpResponseRedirect('/cart/')
Beispiel #23
0
 def test_remove_from_unopened_cart(self):
     with f.app_context():
         cart.my_cart = None
         with pytest.raises(NotAcceptable):
             cart.remove_from_cart('Turtle dove')