Exemplo n.º 1
0
def get_category(request, category_slug, template_name="category/list.html"):
    """
    Category Product List View
    """

    try:
        category = Category.objects.get(published=True, slug=category_slug)
    except Category.DoesNotExist:
        return bad_or_missing(request, 'The category you have requested is not in the catalog.')
    
    return render_to_response(template_name, {
        "category": category, 
    }, context_instance=RequestContext(request))
Exemplo n.º 2
0
def get_manufacturer(request, manufacturer_slug, template_name="manufacturer/list.html"):
    """
    Products list for manufacturer
    """

    try:
        manufacturer = Manufacturer.objects.get(published=True, slug=manufacturer_slug)
    except manufacturer.DoesNotExist:
        return bad_or_missing(request, 'The manufacturer you have requested is not in the catalog.')

    return render_to_response(template_name, {
        "manufacturer": manufacturer, 
    }, context_instance=RequestContext(request))
Exemplo n.º 3
0
def get_product(request, product_slug, template_name="product/details.html"):
    """
    Product Detail View
    """
    try:
        product = Product.objects.get(published=True, slug=product_slug)
        related = product.related_products.all()
        images = ProductImage.objects.filter(product=product.id)
        docs = ProductLiterature.objects.filter(product=product.id)
    except Product.DoesNotExist:
        return bad_or_missing(request, 'The product or page you have requested is not in the catalog.')

    return render_to_response(template_name, {
        "product": product, 
        "related": related,
        "images": images,
        "docs": docs,
    }, context_instance=RequestContext(request))
Exemplo n.º 4
0
def add(request):
    """
    Add product to cart
    """

    # TODO: Refactor this MESS!
    
    if request.method == 'POST':
        next = request.POST.get("next")
        try:
            product = Product.objects.get(published=True, slug=request.POST['product'])
        except Product.DoesNotExist:
            return bad_or_missing(request, 'The product have requested is not in the catalog.')

        if 'cart' in request.session:
            if Cart.objects.get(pk=request.session['cart']):
                cart = Cart.objects.get(pk=request.session['cart'])
                if CartItem.objects.filter(cart=cart, object_id=product.id):
                    item = CartItem.objects.get(cart=cart, object_id=product.id)
                    item.quantity = item.quantity + int(request.POST['quantity'])
                    item.save()
                
                else:
                    cartitems = CartItem(cart=cart, content_object=product, quantity=request.POST['quantity'])
                    CartItem.save(cartitems)
        else:
            cart = Cart()
            cart.save()
            request.session['cart'] = cart.id
            cartitems = CartItem(cart=cart, content_object=product, quantity=request.POST['quantity'])
            CartItem.save(cartitems)

        print request.session['cart']
    
        if next:
            return HttpResponseRedirect(next)
        else:
            return HttpResponseRedirect(reverse("show_cart"))