def post(self, *args, **kwargs):
     form = CheckoutForm(self.request.POST or None)
     print(self.request.POST)
     try:
         order = Order.objects.get(user=self.request.user, ordered=False)
         if form.is_valid():
             street_address = form.cleaned_data.get('street_address')
             apartment_address = form.cleaned_data.get('apartment_address')
             country = form.cleaned_data.get('country')
             state = form.cleaned_data.get('state')
             city = form.cleaned_data.get('city')
             phone = form.cleaned_data.get('phone')
             # TODO: add functionality for these fields
             # same_shipping_address = form.cleaned_data.get('same_shipping_address')
             # save_info = form.cleaned_data.get('save_info')
             payment_option = form.cleaned_data.get('payment_option')
             billing_address = BillingAddress(
                 user=self.request.user,
                 street_address=street_address,
                 apartment_address=apartment_address,
                 country=country,
                 state=state,
                 city=city,
                 phone=phone,
             )
             billing_address.save()
             order.billing_address = billing_address
             order.save()
             # TODO: add redirect to the selected payment option
             return redirect("core:checkout")
         messages.warning(self.request, "Failed checkout")
         return redirect("core:checkout")
     except ObjectDoesNotExist:
         messages.error(self.request, "You do not have an active order")
         return redirect("core:order-summary")
Beispiel #2
0
    def post(self, *args, **kwargs):
        form = CheckoutForm(self.request.POST or None)
        try:
            order = Order.objects.get(user=self.request.user, ordered=False)
            if form.is_valid():
                street_address = form.cleaned_data.get('street_address')
                apartment_address = form.cleaned_data.get('apartment_address')
                country = form.cleaned_data.get('country')
                zip = form.cleaned_data.get('zip')
                # same_billing_address = form.cleaned_data.get('same_billing_address')
                # save_info = form.cleaned_data.get('save_info')
                payment_option = form.cleaned_data.get('payment_option')
                billing_address = BillingAddress(
                    user=self.request.user,
                    street_address=street_address,
                    apartment_address=apartment_address,
                    country=country,
                    zip=zip)
                billing_address.save()
                order.billing_address = billing_address
                order.save()

                if payment_option == "S":
                    return redirect('core:payment', payment_option='stripe')
                elif payment_option == "P":
                    return redirect('core:payment', payment_option="paypal")
                else:
                    messages.warning(self.request,
                                     "Invalid payment option selected")
                    return redirect('core:checkout')

        except ObjectDoesNotExist:
            messages.error(request, "You do not have and active order")
            return redirect("core:order-summary")
Beispiel #3
0
    def post(self, *args, **kwargs):
        form = CheckoutForm(self.request.POST or None)

        try:
            order = Order.objects.get(user=self.request.user, ordered=False)
            if form.is_valid():
                street_address = form.cleaned_data.get("street_address")
                apartment_address = form.cleaned_data.get("apartment_address")
                country = form.cleaned_data.get("country")
                zip = form.cleaned_data.get("zip")
                # TODO: add functionality for these fields
                # same_shipping_address = form.cleaned_data.get("same_shipping_address")
                # save_info = form.cleaned_data.get("save_info")
                payment_option = form.cleaned_data.get("payment_option")
                billing_address = BillingAddress(
                    user=self.request.user,
                    street_address=street_address,
                    apartment_address=apartment_address,
                    country=country,
                    zip=zip,
                )
                billing_address.save()
                order.billing_address = billing_address
                order.save()
                # TODO: Add a redirect to the selected payment option
                return redirect("core:checkout")
            messages.warning(self.request, "Failed to checkout")
            return redirect("core:checkout")
        except ObjectDoesNotExist:
            messages.error(self.request, "You do not have an active order")
            return redirect("core:order-summary")
Beispiel #4
0
    def test_checkout_form_valid_data(self):
        form = CheckoutForm(
            data={
                'street_address': 'rak 25',
                'apartment_address': '23',
                'country': 'NZ',
                'zip': '12-099',
                'same_shipping_address': False,
                'save_info': False,
                'payment_option': 'P'
            })

        self.assertTrue(form.is_valid())
Beispiel #5
0
    def get(self, *args, **kwargs):
        form = CheckoutForm()
        context = {
            'form': form,
        }

        return render(self.request, "checkout-page.html", context)
Beispiel #6
0
    def post(self, *args, **kwargs):
        cart = Cart(self.request)
        order, created = Order.objects.get_or_create(user=self.request.user,
                                                     ordered=False)
        item_ids = cart.cart.keys()
        items = Item.objects.filter(id__in=item_ids)
        for item in items:
            quantity = cart.cart[str(item.id)]['quantity']
            order_item, created = OrderItem.objects.get_or_create(
                item=item,
                user=self.request.user,
                ordered=False,
                quantity=quantity)
            order.items.add(order_item)

        form = CheckoutForm(self.request.POST or None)

        if form.is_valid():
            street_address = form.cleaned_data.get('street_address')
            apartment_address = form.cleaned_data.get('apartment_address')
            country = form.cleaned_data.get('country')
            zip = form.cleaned_data.get('zip')
            # TODO add funtionality for these fields
            # same_shipping_address = form.cleaned_data.get('same_shipping_address')
            # save_info form.cleaned_data.get('save_info')
            payment_option = form.cleaned_data.get('payment_option')
            billing_address = BillingAddress(
                user=self.request.user,
                street_address=street_address,
                apartment_address=apartment_address,
                country=country,
                zip=zip)
            billing_address.save()
            order.billing_address = billing_address
            order.save()

            print(payment_option)
            if payment_option == 'stripe':
                return redirect('payment', payment_option='stripe')
            elif payment_option == 'paypal':
                return redirect('payment', payment_option='paypal')
            else:
                messages.warning(self.request,
                                 'Invalid payment option selected')
                return redirect('checkout')
Beispiel #7
0
    def post(self, *args, **kwargs):
        form = CheckoutForm(self.request.POST or None)
        if form.is_valid():
            street = form.cleaned_data['street']
            landmark = form.cleaned_data['landmark']
            country = form.cleaned_data['country']
            zip = form.cleaned_data['zip']
            same_bill_address = form.cleaned_data['same_bill_address']
            save_info = form.cleaned_data['save_info']
            payment_option = form.cleaned_data['payment_option']
            print(street,
landmark,
country,
zip,
same_bill_address,
save_info,
payment_option)
        return redirect("core:checkout")
Beispiel #8
0
    def get(self, *args, **kwargs):
        form = CheckoutForm()
        context = {'form': form}

        shipping_address_qs = ShoppingAddress.objects.filter(
            user=self.request.user, default=True)
        if shipping_address_qs.exists():
            context.update(
                {'default_shipping_address': shipping_address_qs[0]})
        return render(self.request, "core/ordine/checkout.html", context)
Beispiel #9
0
    def post(self, *args, **kwargs):
        form = CheckoutForm(self.request.POST or None)

        try:
            order = Order.objects.get(user=self.request.user, ordered=False)
            if form.is_valid():
                street = form.cleaned_data.get('street')
                internal_number = form.cleaned_data.get('internal_number')
                external_number = form.cleaned_data.get('external_number')
                suburb = form.cleaned_data.get('suburb')
                city = form.cleaned_data.get('city')
                country = form.cleaned_data.get('country')
                state = form.cleaned_data.get('state')
                zip_code = form.cleaned_data.get('zip_code')
                phone_number = form.cleaned_data.get('phone_number')
                # TODO: add functionality for these fields.
                # same_billing_address = form.cleaned_data.get('same_billing_address')
                # save_info = form.cleaned_data.get('save_info')
                payment_option = form.cleaned_data.get('payment_option')
                billing_address = BillingAddress(
                    user=self.request.user,
                    street=street,
                    internal_number=internal_number,
                    external_number=external_number,
                    suburb=suburb,
                    city=city,
                    country=country,
                    state=state,
                    zip_code=zip_code,
                    phone_number=phone_number,
                )
                billing_address.save()
                order.billing_address = billing_address
                order.save()
                # TODO: add a redirect to the selected payment option.
                return redirect('core:checkout')
            messages.warning(self.request, "Checkout failed!")
            return redirect('core:checkout')
        except ObjectDoesNotExist:
            messages.error(self.request, "You don't have an active order")
            return redirect("core:checkout")
Beispiel #10
0
    def post(self, *args, **kwargs):
        form = CheckoutForm(self.request.POST or None)

        try:
            order = Order.objects.get(user=self.request.user, ordered=False)

            if form.is_valid():
                street_address = form.cleaned_data.get('street_address')
                apartment_address = form.cleaned_data.get('apartment_address')
                country = form.cleaned_data.get('country')
                zip = form.cleaned_data.get('zip')
                # same_shipping_address = form.cleaned_data.get('same_shipping_address')
                # save_info = form.cleaned_data.get('save_info')
                payment_options = form.cleaned_data.get('payment_options')

                billing_address = BillingAddress(
                    user=self.request.user,
                    street_address=street_address,
                    apartment_address=apartment_address,
                    country=country,
                    zip=zip,
                    # save_info=save_info,
                    # same_shipping_address=same_shipping_address,
                    # payment_options=payment_options,

                )
                billing_address.save()

                order.billing_address = billing_address
                order.save()

                return redirect("core:checkout")

            messages.warning(self.request, "Failed checkout!")
            return redirect("core:checkout")

        except exceptions.ObjectDoesNotExist:
            messages.error(self.request, "You do not have any active order!")
            return redirect("core:order-summary")
    def post(self, *args, **kwargs):
        form = CheckoutForm(self.request.POST or None)
        try:
            order = Order.objects.get(user=self.request.user, ordered=False)
            print(self.request.POST)
            if form.is_valid():
                street_address = form.cleaned_data.get('street_address')
                apartment_address = form.cleaned_data.get('apartment_address')
                country = form.cleaned_data.get('country')
                zip = form.cleaned_data.get('zip')
                # add functionality for these fields
                # same_shipping_address = form.cleaned_data.get(
                #     'same_shipping_address')
                # save_info = form.cleaned_data.get('save_info')
                payment_option = form.cleaned_data.get('payment_option')
                billing_address = BillingAddress(
                    user=self.request.user,
                    street_address=street_address,
                    apartment_address=apartment_address,
                    country=country,
                    zip=zip,
                    address_type='B')
                billing_address.save()
                order.billing_address = billing_address
                order.save()

                # add redirect to the selected payment option
                if payment_option == 'S':
                    return redirect('core:payment', payment_option='stripe')
                elif payment_option == 'P':
                    return redirect('core:payment', payment_option='paypal')
                else:
                    messages.warning(self.request,
                                     "Invalid payment option select")
                    return redirect('core:checkout')
        except ObjectDoesNotExist:
            messages.error(self.request, "You do not have an active order")
            return redirect("core:order-summary")
    def get(self, *args, **kwargs):
        try:
            order = Order.objects.get(user=self.request.user, ordered=False)
            form = CheckoutForm()
            context = {
                'form': form,
                'couponform': CouponForm(),
                'order': order,
                'DISPLAY_COUPON_FORM': True
            }
            return render(self.request, "checkout.html", context)

        except ObjectDoesNotExist:
            messages.info(self.request, "You do not have an active order")
            return redirect("core:checkout")
Beispiel #13
0
    def post(self, *args, **kwargs):
        form = CheckoutForm(self.request.POST or None)

        try:
            ordered_product = Order.objects.get(
                username_order=self.request.user, ordered=False)

            if form.is_valid():
                street_address = form.cleaned_data.get('street_address')
                apartment_address = form.cleaned_data.get('apartment_address')
                country = form.cleaned_data.get('country')
                billing_zip = form.cleaned_data.get('billing_zip')

                # TODO:Add Function for These Fields
                # same_shipping_address = form.cleaned_data.get(
                #     'same_shipping_address')
                # save_info = form.cleaned_data.get('save_info')

                payment_options = form.cleaned_data.get('payment_option')
                billing_address = BillingAddress(
                    username_order=self.request.user,
                    street_address=street_address,
                    apartment_address=apartment_address,
                    country=country,
                    billing_zip=billing_zip)
                billing_address.save()
                ordered_product.billing_address = billing_address
                ordered_product.save()
                # TODO Added redirect to the selected payment option
                return redirect('core:checkout')
            messages.warning(self.request, "Failed Checkout")
            return redirect('core:checkout')

        except ObjectDoesNotExist:
            messages.error(self.request, "You not order yet!")
            return redirect('order_summary.html')
Beispiel #14
0
    def get(self, request, **kwargs):
        order = Order.objects.filter(user=self.request.user, ordered=False)
        if not order.exists():
            messages.error(self.request, 'You do not have an active order.')
            return redirect('/')

        form = CheckoutForm()
        order_items = OrderItem.objects.filter(order=order[0], ordered=False)
        address = Address.objects.filter(user=request.user)

        self.extra_context['order'] = order[0]
        self.extra_context['order_items'] = order_items
        self.extra_context['form'] = form
        if address.exists():
            self.extra_context['address'] = address[0]

        return self.render_to_response(self.extra_context)
Beispiel #15
0
	def get(self,*args,**kwargs):
		try:
			order = Order.objects.get(user=self.request.user,ordered=False)
			form = CheckoutForm()
			conext = {
				'form':form,
				'couponform':CouponForm(),
				'order':order,
				'DISPLAY_COUPON_FORM':True
			}

			shipping_address = Address.objects.filter(user=self.request.user)
			if shipping_address.exists():
				conext.update(
					{'default_shipping_address':shipping_address[0]}
					)
			
			return render(self.request,"checkout.html",conext)

		except ObjectDoesNotExist:
			messages.info(self.request,"You dont have active order!")
			return redirect('core:home')
 def get(self, *args, **kwargs):
     form = CheckoutForm()
     # order
     order = Order.objects.get(user=self.request.user, ordered=False)
     context = {'form': form, 'order': order}
     return render(self.request, "checkout.html", context)
Beispiel #17
0
    def get(self, *args, **kwargs):

        form = CheckoutForm()
        context = {'form': form}
        return render(self.request, 'core/checkout.html', context)
Beispiel #18
0
    def test_checkout_form_no_data(self):
        form = CheckoutForm(data={})

        self.assertFalse(form.is_valid())
        self.assertEquals(len(form.errors), 4)
Beispiel #19
0
 def get(self, *args, **kwargs):
     # form
     form = CheckoutForm()
     context = {"form": form}
     return render(self.request, "checkout.html", context)
Beispiel #20
0
    def post(self, *args, **kwargs):
        form = CheckoutForm(self.request.POST or None)
        try:
            order = Order.objects.get(user=self.request.user, is_ordered=False)
            if form.is_valid():
                # print(form.cleaned_data)
                # print("form valido")
                form.use_default_shipping = form.cleaned_data.get(
                    'use_default_shipping')
                #form.save_info = form.cleaned_data.get('save_info')
                if form.use_default_shipping:
                    print('uso indirizzo di default')
                    address_qs = ShoppingAddress.objects.filter(
                        user=self.request.user, default=True)
                    if address_qs.exists():
                        shopping_address = address_qs[0]
                        order_items = order.items.all()
                        order_items.update(is_ordered=True)
                        order.shopping_address = shopping_address
                        for item in order_items:
                            item.product.ordered = True
                            item.product.compratore = order.get_username()
                            item.product.address = order.get_address()
                            item.product.data = timezone.now()
                            item.product.save()
                            item.save()

                        order.shopping_address = shopping_address
                        order.is_ordered = True
                        order.ordered_date = timezone.now()
                        order.save()
                        payment = Payment()
                        payment.user = self.request.user
                        payment.amount = order.get_total()
                        payment.order = order
                        payment.save()
                    else:
                        messages.info(self.request,
                                      "Nessun indirizzo di default")
                        return redirect('checkout')
                else:
                    form.stato = form.cleaned_data.get('stato')
                    form.città = form.cleaned_data.get('città')
                    form.via = form.cleaned_data.get('via')
                    form.cap = form.cleaned_data.get('cap')
                    form.interno = form.cleaned_data.get('interno')
                    form.note = form.cleaned_data.get('note')

                    #form.save_info = form.cleaned_data.get('save_info')
                    form.opzioni_pagamento = form.cleaned_data.get(
                        'opzioni_pagamento')
                    if is_valid_form(
                        [form.stato, form.città, form.via, form.cap]):
                        shopping_address = ShoppingAddress(
                            user=self.request.user,
                            stato=form.stato,
                            città=form.città,
                            cap=form.cap,
                            via=form.via,
                            interno=form.interno,
                            note=form.note)
                        shopping_address.save()
                        order_items = order.items.all()
                        order_items.update(is_ordered=True)
                        order.shopping_address = shopping_address
                        for item in order_items:
                            item.product.ordered = True
                            item.product.compratore = order.get_username()
                            item.product.data = timezone.now()
                            item.product.address = order.get_address()
                            item.product.save()
                            item.save()

                        order.shopping_address = shopping_address
                        order.is_ordered = True
                        order.ordered_date = timezone.now()
                        order.save()
                        payment = Payment()
                        payment.user = self.request.user
                        payment.amount = order.get_total()
                        payment.order = order
                        payment.save()

                        form.save_info = form.cleaned_data.get('save_info')
                        if form.save_info:
                            shopping_address.default = True
                            shopping_address.save()
                    else:
                        messages.info(
                            self.request,
                            "Compila i campi obbligatori per continuare")
                        return redirect('checkout')

            messages.info(self.request,
                          "l'ordine è stato ricevuto con successo")
            return redirect('home')

            messages.warning(self.request,
                             "il checkout non è andato a buon fine ")
            return redirect('checkout')
            return render(self.request, 'core/ordine/order_summary.html',
                          context)
        except ObjectDoesNotExist:
            messages.warning(self.request, "Non hai nessun ordine in corso")
            return redirect('order-summary')
Beispiel #21
0
	def post(self,*args,**kwargs):
		form = CheckoutForm(self.request.POST or None)
		try:
			order_qs = Order.objects.filter(user = self.request.user, ordered=False)
			if form.is_valid():
				order = order_qs[0]
				use_default_shipping = form.cleaned_data.get(
					'use_default_shipping')
				if use_default_shipping:
					default_shipping = Address.objects.filter(user=self.request.user,default=True)
					if default_shipping.exists():
						address = default_shipping[0]
						order.shipping_address=address
						order.save
					else:
						messages.warning(self.request,"You dont have default shipping address")
						return redirect('core:checkout')
				else:
					print("User is entering a new shipping address")
					shipping_address1 = form.cleaned_data.get(
                        'shipping_address')
					shipping_address2 = form.cleaned_data.get(
                        'shipping_address2')
					shipping_country = form.cleaned_data.get(
                        'shipping_country')
					shipping_zip = form.cleaned_data.get('shipping_zip')
					
					if is_valid_form([shipping_address1,shipping_address2,shipping_country,shipping_zip]):
						shipping_address = Address(
                            user=self.request.user,
                            street_address=shipping_address1,
                            apartment_address=shipping_address2,
                            country=shipping_country,
                            zip=shipping_zip,
						)

						shipping_address.save()
						order.shipping_address=shipping_address
						order.save()

						set_default_shipping = form.cleaned_data.get(
                            'set_default_shipping')
						set_default_shipping = form.cleaned_data.get(
                            'set_default_shipping')
						if set_default_shipping:
							shipping_address.default=True
							shipping_address.save()
							print("I came here too!")
						print("I came here!")
						return redirect('core:payment')
					else:
						messages.warning(self.request,"Fill required fields correctly!")				
						return redirect('core:checkout')
				return redirect('core:payment') #success
				#Shoudld return HTTP Response
			else:
				messages.warning(self.request,"Fill required fields correctly!")				
				return redirect('core:checkout')
		except ObjectDoesNotExist:	
			messages.info(self.request,"You dont have active order!")
			return redirect('core:home')