Ejemplo n.º 1
0
Archivo: views.py Proyecto: vuonghv/brs
    def form_valid(self, form):
        cart = utils.get_cart(self.request)
        book_id = form.cleaned_data['book']
        quantity = form.cleaned_data['quantity']
        exist = cart.get(str(book_id))

        if exist is not None:
            cart[str(book_id)] += quantity
        else:
            cart[str(book_id)] = quantity

        # Need for update session database
        self.request.session.modified = True

        book = get_object_or_404(Book, id=book_id)
        messages.success(self.request,
                         '"{}" has been added to your cart.'.format(
                             book.title),
                         extra_tags='woocommerce-message')

        return HttpResponseRedirect(
            reverse('books:detail', kwargs={
                'pk': book_id,
                'slug': book.slug
            }))
Ejemplo n.º 2
0
def get_one_book_total_price(context, item_id):
    try:
        cart = get_cart(context['request'])
        book = Book.objects.get(id=item_id)
        total_price = book.price * cart[str(item_id)]
    except Exception:
        total_price = 0
    return total_price
Ejemplo n.º 3
0
def get_one_book_total_price(context, item_id):
    try:
        cart = get_cart(context['request'])
        book = Book.objects.get(id=item_id)
        total_price = book.price * cart[str(item_id)]
    except Exception:
        total_price = 0
    return total_price
Ejemplo n.º 4
0
    def form_valid(self, form):
        cart = utils.get_cart(self.request)
        book_id = form.cleaned_data['book']
        quantity = form.cleaned_data['quantity']
        cart[str(book_id)] = quantity

        self.request.session.modified = True
        book = get_object_or_404(Book, id=book_id)
        return HttpResponseRedirect(reverse('books:detail',
                            kwargs={'pk': book_id, 'slug': book.slug}))
Ejemplo n.º 5
0
def get_total_price(context):
    try:
        total_price = 0
        cart = get_cart(context['request'])
        for key, value in cart.items():
            book = Book.objects.get(id=key)
            total_price += (book.price * int(value))
    except Exception:
        total_price = 0
    return total_price
Ejemplo n.º 6
0
def get_total_price(context):
    try:
        total_price = 0
        cart = get_cart(context['request'])
        for key, value in cart.items():
            book = Book.objects.get(id=key)
            total_price += (book.price * int(value))
    except Exception:
        total_price = 0
    return total_price
Ejemplo n.º 7
0
    def form_valid(self, form):
        cart = utils.get_cart(self.request)
        formset = form
        for form in formset:
            book_id = form.cleaned_data['book']
            quantity = form.cleaned_data['quantity']
            cart.update({str(book_id): quantity})

        self.request.session.modified = True
        messages.success(self.request, "Cart is updated successfully!",
                            extra_tags='woocommerce-message')
        return HttpResponseRedirect(self.success_url)
Ejemplo n.º 8
0
Archivo: views.py Proyecto: vuonghv/brs
    def form_valid(self, form):
        cart = utils.get_cart(self.request)
        book_id = form.cleaned_data['book']
        quantity = form.cleaned_data['quantity']
        cart[str(book_id)] = quantity

        self.request.session.modified = True
        book = get_object_or_404(Book, id=book_id)
        return HttpResponseRedirect(
            reverse('books:detail', kwargs={
                'pk': book_id,
                'slug': book.slug
            }))
Ejemplo n.º 9
0
    def form_valid(self, form):
        book_id = form.cleaned_data['book']
        cart = utils.get_cart(self.request)
        book_id = form.cleaned_data['book']
        if str(book_id) in cart.keys():
            del cart[str(book_id)]

        self.request.session.modified = True
        book = get_object_or_404(Book, id=book_id)
        messages.success(self.request,
                    '"{}" has been removed from your cart.'.format(book.title),
                    extra_tags='woocommerce-message')
        return HttpResponseRedirect(reverse('carts:view'))
Ejemplo n.º 10
0
Archivo: views.py Proyecto: vuonghv/brs
    def form_valid(self, form):
        cart = utils.get_cart(self.request)
        formset = form
        for form in formset:
            book_id = form.cleaned_data['book']
            quantity = form.cleaned_data['quantity']
            cart.update({str(book_id): quantity})

        self.request.session.modified = True
        messages.success(self.request,
                         "Cart is updated successfully!",
                         extra_tags='woocommerce-message')
        return HttpResponseRedirect(self.success_url)
Ejemplo n.º 11
0
Archivo: views.py Proyecto: vuonghv/brs
    def form_valid(self, form):
        book_id = form.cleaned_data['book']
        cart = utils.get_cart(self.request)
        book_id = form.cleaned_data['book']
        if str(book_id) in cart.keys():
            del cart[str(book_id)]

        self.request.session.modified = True
        book = get_object_or_404(Book, id=book_id)
        messages.success(self.request,
                         '"{}" has been removed from your cart.'.format(
                             book.title),
                         extra_tags='woocommerce-message')
        return HttpResponseRedirect(reverse('carts:view'))
Ejemplo n.º 12
0
    def form_valid(self, form):
        cart = utils.get_cart(self.request)
        form.instance.user_profile = self.request.user.profile
        self.object = form.save()

        for key, value in cart.items():
            book = Book.objects.get(pk=int(key))
            item = Item.objects.create(product=book, quantity=value,
                                        cart=self.object)
            item.save()
        

        cart.clear()
        self.request.session.modified = True

        messages.success(self.request, "You checked out successfully.",
                            extra_tags='woocommerce-message')

        return HttpResponseRedirect(self.get_success_url())
Ejemplo n.º 13
0
Archivo: views.py Proyecto: vuonghv/brs
    def form_valid(self, form):
        cart = utils.get_cart(self.request)
        form.instance.user_profile = self.request.user.profile
        self.object = form.save()

        for key, value in cart.items():
            book = Book.objects.get(pk=int(key))
            item = Item.objects.create(product=book,
                                       quantity=value,
                                       cart=self.object)
            item.save()

        cart.clear()
        self.request.session.modified = True

        messages.success(self.request,
                         "You checked out successfully.",
                         extra_tags='woocommerce-message')

        return HttpResponseRedirect(self.get_success_url())
Ejemplo n.º 14
0
    def form_valid(self, form):
        cart = utils.get_cart(self.request)
        book_id = form.cleaned_data['book']
        quantity = form.cleaned_data['quantity']
        exist = cart.get(str(book_id))

        if exist is not None:
            cart[str(book_id)] += quantity
        else:
            cart[str(book_id)] = quantity
        
        # Need for update session database
        self.request.session.modified = True

        book = get_object_or_404(Book, id=book_id)
        messages.success(self.request,
                    '"{}" has been added to your cart.'.format(book.title),
                    extra_tags='woocommerce-message')
        
        return HttpResponseRedirect(reverse('books:detail',
                            kwargs={'pk': book_id, 'slug': book.slug}))
Ejemplo n.º 15
0
Archivo: views.py Proyecto: vuonghv/brs
 def get_initial(self):
     cart = utils.get_cart(self.request)
     initial = [{'book': k, 'quantity': v} for k, v in cart.items()]
     return initial
Ejemplo n.º 16
0
Archivo: views.py Proyecto: vuonghv/brs
 def post(self, request, *args, **kwargs):
     cart = utils.get_cart(request)
     cart.clear()
     request.session.modified = True
     return HttpResponseRedirect(reverse('carts:view'))
Ejemplo n.º 17
0
def get_quantity(context, item_id):
    cart = get_cart(context['request'])
    return cart[str(item_id)]
Ejemplo n.º 18
0
 def get_initial(self):
     cart = utils.get_cart(self.request)
     initial = [{'book': k, 'quantity': v} for k, v in cart.items()]
     return initial
Ejemplo n.º 19
0
 def post(self, request, *args, **kwargs):
     cart = utils.get_cart(request)
     cart.clear()
     request.session.modified = True
     return HttpResponseRedirect(reverse('carts:view'))
Ejemplo n.º 20
0
def get_quantity(context, item_id):
    cart = get_cart(context['request'])
    return cart[str(item_id)]