Пример #1
0
def show_cart(request):
    cart_items = cart.get_cart_items(request)
    cart_subtotal = cart.cart_subtotal(request)

    return {'cart_items': cart_items,
            'cart_subtotal': cart_subtotal,
            'cart_item_count': cart.distinct_item_count(request)}
Пример #2
0
def checkout(request):
    # TODO need to create email temaplates for managers and clients
    if cart.is_empty(request):
        return HttpResponseRedirect(urlresolvers.reverse('cart'))

    form = Checkout()
    if request.method == 'POST':
        form = Checkout(request.POST)
        if form.is_valid():
            checkout_form = form.save(commit=False)
            checkout_form.save()

            # manager's mail
            manager_message = ''
            manager_message_title = u'Новый заказ №:%s' % checkout_form.id
            for field in form.fields:
                if form.cleaned_data.get(field):
                    manager_message += "%s: %s\n" % (form.fields.get(field).label, form.cleaned_data.get(field))
            mail_managers(manager_message_title, manager_message)

            # clien's mail
            email = form.cleaned_data['email']
            if email:
                user_message = u'Спасибо за заказ.\n Номер заказа:%s' % checkout_form.id
                user_message_title = u'Спасибо за заказ'
                send_mail(user_message_title, user_message, u'Military shop', [email])

            items = cart.get_cart_items(request)
            for i in items:
                order = Order.objects.get(id=checkout_form.id)
                OrderedItems.objects.create(order=order , product=i.product, quantity=i.quantity, price=i.total())
            items.delete()

    cart_items = cart.get_cart_items(request)
    return {'cart_items': cart_items, 'form': form, 'cart_item_count': cart.distinct_item_count(request)}
Пример #3
0
def index(request):
    items = Item.objects.filter(publicated=True).order_by('-date')[:6]
    sliders = HomeSlider.objects.all()

    # sidebar
    categories = Category.objects.all()
    manufacturers = Manufacturer.objects.all()

    return {'items': items, 'categories': categories, 'manufacturers': manufacturers, \
            'cart_item_count': cart.distinct_item_count(request), 'sliders': sliders}
Пример #4
0
def manufacturer_page(request, slug=None):
    manufacturer = get_object_or_404(Manufacturer, slug=slug)
    items = Item.objects.filter(publicated=True, manufacturer=manufacturer.pk).order_by('-date')

    # sidebar
    categories = Category.objects.all()
    manufacturers = Manufacturer.objects.all()

    # pagination
    items = pagination(request, items)

    return {'items': items, 'category': manufacturer, 'categories': categories, 'manufacturers': manufacturers, \
            'cart_item_count': cart.distinct_item_count(request)}
Пример #5
0
def item(request, category_slug, self_slug):
    item = get_object_or_404(Item, slug=self_slug, category__slug=category_slug)
    items = Item.objects.filter(publicated=True, category__slug=category_slug).exclude(slug=self_slug)[:12]

    form = ProductAddToCartForm(request=request, label_suffix=':')
    if request.method == 'POST':
        form = ProductAddToCartForm(request, request.POST)
        if form.is_valid():
            cart.add_to_cart(request)
            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()
            request.success = True

    form.fields['product_slug'].widget.attrs['value'] = self_slug
    request.session.set_test_cookie()

    # sidebar
    categories = Category.objects.all()
    manufacturers = Manufacturer.objects.all()

    return {'item': item, 'items': items, 'form': form, 'cart_item_count': cart.distinct_item_count(request), \
            'categories': categories, 'manufacturers': manufacturers}