Esempio n. 1
0
 def get_initial(self):
     initial = super(CheckoutView, self).get_initial()
     cart = self.cart = check_or_create_cart(self.request)
     user = self.request.user
     if user.is_authenticated:
         profile = user.profile
         initial['first_name'] = profile.first_name
         initial['last_name'] = profile.last_name
         initial['email'] = user.email
         initial['address'] = profile.shipping_address
         initial['city'] = profile.shipping_city
         initial['zip_code'] = profile.shipping_zip_code
         initial['cellphone'] = profile.cellphone
         initial['phone'] = profile.phone
     if CartProfile.objects.filter(cart_related=cart).exists():
         cart_profile = cart.cart_profile
         initial['first_name'] = cart_profile.first_name
         initial['last_name'] = cart_profile.last_name
         initial['email'] = cart_profile.email
         initial['address'] = cart_profile.address
         initial['city'] = cart_profile.city
         initial['zip_code'] = cart_profile.zip_code
         initial['cellphone'] = cart_profile.cellphone
         initial['phone'] = cart_profile.phone
     initial['shipping_method'] = cart.shipping_method
     initial['payment_method'] = cart.payment_method
     return initial
Esempio n. 2
0
def delete_voucher_from_cart_view(request, pk):
    cart = check_or_create_cart(request)
    voucher = get_object_or_404(Voucher, id=pk)
    cart.vouchers.remove(voucher)
    cart.save()
    messages.warning(request, 'Το Κουπόνι αφαιρέθηκε από το καλάθι σας')
    return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
Esempio n. 3
0
def delete_voucher_from_cart_view(request, pk):
    cart = check_or_create_cart(request)
    voucher = get_object_or_404(Voucher, id=pk)
    cart.vouchers.remove(voucher)
    cart.save()
    messages.warning(request, 'The voucher has deleted from the cart')
    return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
Esempio n. 4
0
def payment_done(request):
    cart = check_or_create_cart(request)
    cart_profile = cart.cart_profile
    order = Order.create_eshop_order(request, cart)
    OrderProfile.create_order_profile(request, order, cart)

    send_mail(
        'Καταχώρηση Παραγγελίας no celery',
        f'Η παραγγελία με κωδικο {order.number} καταχωρήθηκε',
        BUSSNESS_EMAIL,
        [
            cart_profile.email,
        ],
    )
    order.is_paid = True
    order.paid_value = order.final_value
    order.save()
    cart.active = False
    cart.status = 'Submitted'
    cart.save()
    profile = order.profile
    title = 'Πραγματοποίηση Παραγγελίας'
    payment_progress = True
    del request.session['cart_id']
    return render(request, 'paypal_/done.html', context=locals())
Esempio n. 5
0
def ajax_delete_cart_item(request, pk, action):
    cart = check_or_create_cart(request)
    if action == 'product':
        cart_item = get_object_or_404(CartItem, id=pk)
        if cart == cart_item.cart:
            cart_item.delete()
    if action == 'attr':
        cart_item_attr = get_object_or_404(CartItemAttribute, id=pk)
        if cart_item_attr.cart_item.cart == cart:
            cart_item = cart_item_attr.cart_item
            cart_item_attr.delete()
            cart_item.refresh_from_db()
            if not cart_item.attribute_items.exists():
                cart_item.delete()
    cart.refresh_from_db()
    data = dict()
    data['cart_items_result'] = render_to_string(
        template_name='frontend/ajax_views/cart_items_container.html',
        request=request,
        context={'cart': cart})
    data['cart_result'] = render_to_string(
        template_name='frontend/ajax_views/cart_container.html',
        request=request,
        context={'cart': cart})
    return JsonResponse(data)
Esempio n. 6
0
def add_product_with_attr_to_cart(request, slug):
    cart = check_or_create_cart(request)
    qty = request.POST.get('qty', None)
    attribute = request.POST.get('attribute', None)
    product = get_object_or_404(Product, slug=slug)
    result, message = CartItem.create_cart_item(cart, product, int(qty),
                                                attribute)
    messages.success(request, message)
    return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
Esempio n. 7
0
 def form_valid(self, form):
     product = get_object_or_404(Product, slug=self.kwargs['slug'])
     qty = form.cleaned_data.get('qty', 1)
     attribute_id = self.request.POST.get('attribute', None)
     cart = check_or_create_cart(self.request)
     result, message = CartItem.create_cart_item(cart, product, qty,
                                                 attribute_id)
     messages.success(self.request, message)
     return super(ProductView, self).form_valid(form)
Esempio n. 8
0
def frontend(request):
    navbar_categories = Category.browse.navbar()
    cart = check_or_create_cart(request)
    login_form = LoginForm()
    return {
        'navbar_categories': navbar_categories,
        'cart': cart,
        'login_form': login_form
    }
Esempio n. 9
0
def decide_what_to_do_with_order_payment(request):
    cart = check_or_create_cart(request)
    payment_method = cart.payment_method
    if payment_method.payment_type in ['a', 'b']:
        return redirect(reverse('order_success_url'))
    if payment_method.payment_type in ['c', 'd']:
        if payment_method.title == 'Paypal':
            return redirect(reverse('paypall_process'))
    return redirect(reverse('order_success_url'))
Esempio n. 10
0
def ajax_delete_voucher(request, pk):
    voucher = get_object_or_404(Voucher, id=pk)
    cart = check_or_create_cart(request)
    cart.vouchers.remove(voucher)
    cart.save()
    data = dict()
    cart.refresh_from_db()
    data['result'] = render_to_string(template_name='',
                                      request=request,
                                      context={'cart': cart})
    return JsonResponse(data)
Esempio n. 11
0
 def form_valid(self, form):
     cart = check_or_create_cart(self.request)
     if not cart.order_items.exists():
         messages.warning(self.request, 'Δε έχετε προσθέσει Προϊόντα')
         return super().form_valid(form)
     self.new_order = new_order = Order.create_eshop_order(
         self.request, form, cart)
     cart.status = 'Submitted'
     cart.save()
     new_profile = OrderProfile.create_profile_from_cart(form, new_order)
     del self.request.session['cart_id']
     OrderProfile.create_profile_from_cart(form, new_order)
     return super().form_valid(form)
Esempio n. 12
0
def order_success_url(request):
    cart = check_or_create_cart(request)
    order = get_object_or_404(Order, cart_related=cart)
    show_bank_div = True if order.payment_method.payment_type == 'b' else False
    title = 'Πραγματοποίηση Παραγγελίας'
    profile = order.order_profiles.first() if order.order_profiles.exists(
    ) else None
    del request.session['cart_id']
    return render(
        request, 'frontend/checkout_success.html', {
            'order': order,
            'profile': profile,
            'title': title,
            'show_bank_div': show_bank_div
        })
Esempio n. 13
0
def ajax_update_cate_shipping_method_view(request):
    cart = check_or_create_cart(request)
    new_shipping_method = request.GET.get('shipping_method', 1)
    shiping_method = get_object_or_404(Shipping, id=new_shipping_method)
    cart.shipping_method = shiping_method
    cart.save()
    data = dict()
    cart.refresh_from_db()
    data['result'] = render_to_string(
        template_name='frontend/ajax_views/checkout_price_container.html',
        request=request,
        context={
            'cart': cart,
            'vouchers': cart.vouchers.all()
        })
    return JsonResponse(data)
Esempio n. 14
0
    def form_valid(self, form):
        # checks if checkout form is valid
        shipping_method = form.cleaned_data['shipping_method']
        payment_method = form.cleaned_data['payment_method']
        cart = check_or_create_cart(self.request)
        if not cart.order_items.exists():
            messages.warning(self.request,
                             'You have to add items to your cart first.')
        cart.shipping_method = shipping_method
        cart.payment_method = payment_method
        cart.save()
        CartProfile.create_cart_profile(form, cart)
        # now we check if the payment type is a service, If its a service we dont create the order now
        # because something can go bad, so will created to success url
        if payment_method.payment_type in ['c', 'd']:
            return super(CheckoutView, self).form_valid(form)

        # if the payment_methos is a regular paymnent type we continue the order process
        cart.active = False
        cart.status = 'Submitted'
        cart.save()
        cart.refresh_from_db()
        self.new_eshop_order = Order.create_eshop_order(self.request, cart)
        OrderProfile.create_order_profile(self.request, self.new_eshop_order,
                                          cart)
        email = form.cleaned_data.get('email')
        send_mail(
            'You have a new order.',
            f'Date.. {self.new_eshop_order.date_expired} |'
            f' {self.new_eshop_order.guest_email} | Value {self.new_eshop_order.tag_final_value}.'
            f'Thank you!, You order code is {self.new_eshop_order.number}. ',
            BUSSNESS_EMAIL,
            [
                email,
            ],
        )
        if PRODUCTION:
            send_mail(
                'You have a new order.',
                f'Date.. {self.new_eshop_order.date_expired} |'
                f' {self.new_eshop_order.guest_email} | Value {self.new_eshop_order.tag_final_value}',
                '*****@*****.**',
                [BUSSNESS_EMAIL, '*****@*****.**'])

        return super(CheckoutView, self).form_valid(form)
Esempio n. 15
0
    def form_valid(self, form):
        title = form.cleaned_data.get('voucher')
        qs = Voucher.objects.filter(code=title.upper())
        voucher = qs.first() if qs.exists() else None
        if not voucher:
            messages.warning(self.request,
                             f'Δεν υπάρχει κουπόνι με κωδικό {title}')
            return super(CartView, self).form_valid(form)

        cart = check_or_create_cart(self.request)
        is_available, message = voucher.check_if_its_available(
            cart, voucher, self.request.user)
        value = 0
        if is_available:
            cart.vouchers.add(voucher)
            cart.save()
        messages.warning(self.request, f'{message} {value}')
        return super(CartView, self).form_valid(form)
Esempio n. 16
0
def payment_process(request):
    cart = check_or_create_cart(request)
    host = request.get_host()

    paypal_dict = {
        'business': BUSSNESS_EMAIL,
        'amount': f'{cart.final_value}',
        'item_name': f'Cart {cart.id}',
        'invoice': str(cart.id),
        'currency_code': 'EUR',
        'notify_url': f'http://{host}{reverse("paypal-ipn")}',
        'return_url': 'http://{}{}'.format(host, reverse('paypal_done')),
        'cancel_return': 'http://{}{}'.format(host,
                                              reverse('paypal_canceled')),
    }
    form = PayPalPaymentsForm(initial=paypal_dict)
    return render(request, 'paypal_/process.html', {
        'order': cart,
        'form': form
    })
Esempio n. 17
0
def add_voucher_to_cart_view(request):
    code = request.GET.get('voucher_code', None)
    if not code:
        messages.warning(request, 'Πληκτρολογήστε κωδικό κουπονιού')
        return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
    if isinstance(code, str):
        code = str(code).upper()
    voucher_exists = Voucher.objects.filter(code=code.upper())
    voucher = voucher_exists.first() if voucher_exists.exists() else None
    if not voucher:
        messages.warning(request, 'Δε υπάρχει κουπόνι με αυτόν τον κωδικό')
        return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
    cart = check_or_create_cart(request)
    is_available, message = voucher.check_if_its_available(
        cart, request.user, voucher)
    messages.success(request, message)
    if is_available:
        cart.vouchers.add(voucher)
        cart.save()
    return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
Esempio n. 18
0
    def form_valid(self, form):
        # checks if checkout form is valid
        shipping_method = form.cleaned_data['shipping_method']
        payment_method = form.cleaned_data['payment_method']
        cart = check_or_create_cart(self.request)
        if not cart.order_items.exists():
            messages.warning(self.request,
                             'Δε έχετε προσθεσει προϊόντα στο καλαθι σας.')
        cart.shipping_method = shipping_method
        cart.payment_method = payment_method
        cart.save()
        CartProfile.create_cart_profile(form, cart)
        # now we check if the payment type is a service, If its a service we dont create the order now
        # because something can go bad, so will created to success url
        if payment_method.payment_type in ['c', 'd']:
            return super(CheckoutView, self).form_valid(form)
        # if the payment_methos is a regular paymnent type we continue the order process
        cart.active = False
        cart.status = 'Submitted'
        cart.save()
        cart.refresh_from_db()
        self.new_eshop_order = Order.create_eshop_order(self.request, cart)
        OrderProfile.create_order_profile(self.request, self.new_eshop_order,
                                          cart)
        email = form.cleaned_data.get('email')
        send_mail(
            'Καταχώρηση Παραγγελίας',
            f'Σας ευχαριστούμε που μας προτιμήσατε! Η παραγγελία σας με κωδικο'
            f' {self.new_eshop_order.number} καταχωρήθηκε',
            BUSSNESS_EMAIL,
            [
                email,
            ],
        )
        send_mail(
            'Έχετε νέα Παραγγελία',
            f'Ημερομηνια.. {self.new_eshop_order.date_expired} |'
            f' {self.new_eshop_order.guest_email} | Ποσο {self.new_eshop_order.tag_final_value}',
            '*****@*****.**', [BUSSNESS_EMAIL, '*****@*****.**'])

        return super(CheckoutView, self).form_valid(form)
Esempio n. 19
0
def add_voucher_to_cart_view(request):
    code = request.GET.get('voucher_code', None)
    if not code:
        messages.warning(request, 'You need to add a code.')
        return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
    if isinstance(code, str):
        code = str(code).upper()
    voucher_exists = Voucher.objects.filter(code=code.upper())
    voucher = voucher_exists.first() if voucher_exists.exists() else None
    if not voucher:
        messages.warning(request,
                         'Sorry, there is no a voucher with this code')
        return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
    cart = check_or_create_cart(request)
    is_available, message = voucher.check_if_its_available(
        cart, request.user, voucher)
    messages.success(request, message)
    if is_available:
        cart.vouchers.add(voucher)
        cart.save()
    return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
Esempio n. 20
0
def ajax_check_voucher(request):
    data = dict()
    cart = check_or_create_cart(request)
    code = request.GET.get('voucher', None)
    qs = Voucher.objects.filter(code=code.upper())
    voucher = Voucher.objects.get(code=code.upper()) if qs.exists() else None
    message = ''
    if not voucher:
        message = 'Δε υπάρχει κουπόνι με τον κωδικό που χρησιμοποιήσατε.'
    else:
        is_valid, message = voucher.check_if_its_available(
            cart, request.user, voucher)
        if is_valid:
            cart.vouchers.add(voucher)
            cart.save()
    cart.refresh_from_db()
    data['cart_result'] = render_to_string(
        template_name='frontend/ajax_views/cart_container.html',
        request=request,
        context={
            'cart': cart,
            'message': message
        })
    return JsonResponse(data)
Esempio n. 21
0
def ajax_estimate_costs(request, action):
    pk = request.GET.get('pk', None)
    cart = check_or_create_cart(request)
    if action == 'shipping':
        shipping = get_object_or_404(Shipping, id=pk)
        cart.shipping_method = shipping
        cart.save()
    if action == 'payment':
        payment_method = get_object_or_404(PaymentMethod, id=pk)
        cart.payment_method = payment_method
        cart.save()
    cart.refresh_from_db()
    data = dict()
    shipping_methods = Shipping.browser.active()
    payment_methods = PaymentMethod.my_query.active_for_site()
    data['cart_result'] = render_to_string(
        template_name='frontend/ajax_views/cart_container.html',
        request=request,
        context={
            'cart': cart,
            'shipping_methods': shipping_methods,
            'payment_methods': payment_methods
        })
    return JsonResponse(data)
Esempio n. 22
0
def add_product_to_cart(request, slug):
    cart = check_or_create_cart(request)
    product = get_object_or_404(Product, slug=slug)
    if product.have_attr:
        messages.warning(request, 'Something is wrongh!')
        return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
    if not product.product_class.have_transcations:
        messages.warning(
            request,
            f'The product {product.eng_title} doesnt support transcations.')
        return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
    session_id = request.session.get('cart_id')
    check_cart_owner = cart.cart_id == session_id
    if check_cart_owner:
        cart_item, created = CartItem.objects.get_or_create(cart=cart,
                                                            product=product)
        if created:
            cart_item.qty = 1
        else:
            messages.warning(request, 'Sorry, there is no enough qty.')
        cart_item.save()
        messages.success(
            request, f'The product {product.eng_title} added to your cart!')
    return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
Esempio n. 23
0
def add_product_to_cart(request, slug):
    cart = check_or_create_cart(request)
    product = get_object_or_404(Product, slug=slug)
    if product.have_attr:
        messages.warning(request, 'Κάτι πήγε λάθος!')
        return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
    if not product.product_class.have_transcations:
        messages.warning(
            request, f'Το προϊόν {product.title} δε υποστηρίζει συναλλαγές.')
        return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
    session_id = request.session.get('cart_id')
    check_cart_owner = cart.cart_id == session_id
    if check_cart_owner:
        cart_item, created = CartItem.objects.get_or_create(cart=cart,
                                                            product=product)
        if created:
            cart_item.qty = 1
        else:
            messages.warning(request, 'Λυπούμαστε δε υπάρχει επαρκή ποσότητα')
        cart_item.save()
        messages.success(
            request,
            f'To Προϊόν {product.title} προστέθηκε επιτιχώς στο καλάθι!')
    return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
Esempio n. 24
0
def remove_voucher_from_cart_view(request, pk):
    voucher = get_object_or_404(Voucher, id=pk)
    cart = check_or_create_cart(request)
    cart.vouchers.remove(voucher)
    cart.save()
    return HttpResponseRedirect(reverse('cart_page'))