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")
示例#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")
                # 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")
示例#3
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')
    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():
                first_name = form.cleaned_data.get('first_name')
                last_name = form.cleaned_data.get('last_name')
                email_address = form.cleaned_data.get('email_address')
                phone_number = form.cleaned_data.get('phone_number')
                country = form.cleaned_data.get('country')
                address = form.cleaned_data.get('address')
      
                payment_option = form.cleaned_data.get('payment_option')

                billing_address = BillingAddress(
                    user = self.request.user,
                    first_name = first_name,
                    last_name = last_name,
                    email_address = email_address,
                    phone_number = phone_number,
                    country = country,
                    address = address,
                )
                billing_address.save()
                order.billing_address = billing_address
                order.save()
                order_items = order.items.all()
                order_items.update(ordered=True)

                for item in order_items:
                    item.save()

                order.ordered = True
                order.save()
                messages.success(self.request, "Your order was successful!")
                return redirect('core:order-submitted')
                          
            messages.warning(self.request, 'Invalid entries. Please fill the form correctly')
            return redirect('core:checkout')

        except ObjectDoesNotExist:
            messages.error(self.request,'You do not have an active order')
            return redirect('core:order-summary') 
        print(self.request.POST)
示例#5
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")
示例#6
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")
示例#8
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')
示例#9
0
    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():
                user = form.cleaned_data.get('user')
                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')
                billing_address = BillingAddress(
                    user = self.request.user,
                    street_address = street_address,
                    apartment_address = apartment_address,
                    country = country,
                    zip = zip,
                    same_billing_address = same_billing_address,
                    save_info = save_info,
                )
                billing_address.save()
                order.billing_address = billing_address
                order.save()

                # TODO: add recirect to the selected payment option


                return redirect('core:checkout')
        except ObjectDoesNotExist:
            messages.error(self.request, "You do not have an active order")
            return redirect("core:order-summary")

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