示例#1
0
def delivery_add_option():
    if request.method == "POST":
        form = DeliveryOptionForm()
        if form.validate_on_submit():
            toadd = DeliveryOption()
            toadd.option = form.option.data
            toadd.price = float(form.price.data)
            toadd.insert()
            flash(notify_success("Option Added!"))
            return mhelp.redirect_url("shopman.delivery")
        else:
            flash_errors(form)
            return mhelp.redirect_url("shopman.delivery")
示例#2
0
def check_pagecontent():
    if request.method == "POST":
        form = PageForm()
        if not form.validate_on_submit():
            flash_errors(form)
            return redirect(url_for("{}.dashboard".format(module_name)))
        toaddpage = Page(
            slug=form.slug.data,
            content=form.content.data,
            title=form.title.data,
        )
        toaddpage.insert()
        return redirect(url_for("{}.dashboard".format(module_name)))
示例#3
0
def payment_add_option():
    if request.method == "POST":
        form = PaymentOptionForm()
        if form.validate_on_submit():
            toadd = PaymentOption()
            toadd.name = form.name.data
            toadd.text = form.text.data
            toadd.insert()
            flash(notify_success("Option Added!"))
            return mhelp.redirect_url("shopman.payment")
        else:
            flash_errors(form)
            return mhelp.redirect_url("shopman.payment")
示例#4
0
def coupon_add():
    if request.method == "POST":
        form = CouponForm()
        if form.validate_on_submit():
            toadd = Coupon()
            toadd.string = form.string.data
            toadd.type = form.type.data
            toadd.value = form.value.data
            toadd.insert()
            flash(notify_success("Coupon Added!"))
            return mhelp.redirect_url("shopman.coupon")
        else:
            flash_errors(form)
            return mhelp.redirect_url("shopman.coupon")
示例#5
0
def edit_check(announce_id):

    if request.method == "POST":
        announcement = Announcement.query.get(announce_id)
        form = AnnounceForm(obj=announcement)
        if not form.validate_on_submit():
            flash_errors(form)
            return mhelp.redirect_url(
                mhelp.method("edit"), announce_id=announce_id
            )
        form.populate_obj(announcement)
        announcement.update()
        flash(notify_success("Announcement updated!"))
        return mhelp.redirect_url(mhelp.method("list"))
示例#6
0
def add_check():
    if request.method == "POST":
        form = AnnounceForm()
        if not form.validate_on_submit():
            flash_errors(form)
            return mhelp.redirect_url(
                "{}.dashboard".format(mhelp.info["module_name"])
            )
        toadd_announce = Announcement(
            content=form.content.data,
            title=form.title.data,
        )
        toadd_announce.save()
    return mhelp.redirect_url("{}.dashboard".format(mhelp.info["module_name"]))
示例#7
0
def coupon_update():
    if request.method == "POST":
        form = CouponForm()
        if form.validate_on_submit:
            coupon_id = request.form["id"]
            coupon = Coupon.query.get(coupon_id)
            coupon.string = form.string.data
            coupon.type = form.type.data
            coupon.value = form.value.data
            coupon.update()

            flash(notify_success("Coupon updated!"))
            return mhelp.redirect_url("shopman.coupon")
        else:
            flash_errors(form)
            return mhelp.redirect_url("shopman.coupon")
示例#8
0
def register():
    if request.method == 'POST':
        form = RegisterCustomerForm()
        if not form.validate_on_submit():
            flash_errors(form)
        user = User()
        if User.query.filter(User.email == form.email.data).first():
            flash(notify_warning("Email exists"))
            return mhelp.redirect_url('shop.homepage')
        user.email = form.email.data
        password1 = form.password.data
        password2 = form.reconfirm_password.data
        if not password1 == password2:
            flash(notify_warning("Passwords don't match"))
            return mhelp.redirect_url('shop.homepage')
        user.password = password1
        user.is_customer = True
        print(user.email, password1)
        user.save()
        flash(notify_success('Successfully registered, please log in!'))
        return mhelp.redirect_url('shop.homepage')
示例#9
0
def checkout_process():
    if request.method == "POST":
        cart_info = get_cart_data()
        if len(cart_info["cart_data"]) == 0:
            flash(notify_warning("Cart cannot be empty!"))
            return mhelp.redirect_url("shop.checkout")

        form = CheckoutForm()
        with open(
                os.path.join(
                    current_app.config["BASE_DIR"],
                    "modules",
                    "box__ecommerce",
                    "shopman",
                    "data",
                    "country.json",
                )) as f:
            countries = json.load(f)
        # country_choices = [(c["name"], c["name"]) for c in countries]
        # form.default_country.choices = country_choices
        # form.diff_country.choices = country_choices

        country_choices = [('mauritius', 'Mauritius')]
        form.default_country.choices = country_choices
        form.diff_country.choices = country_choices

        # print(dir(form))
        # ordered dict print(form._fields[0][0])

        # print(form._fields['default_first_name'].data)

        checkout_data = {}
        for key in form._fields:
            checkout_data[key] = form._fields[key].data

        session["checkout_data"][0] = checkout_data

        print(request.form["paymentoption"])
        if form.validate_on_submit():
            if not form.diffAddress.data:
                first_name = form.default_first_name.data
                last_name = form.default_last_name.data
                country = form.default_country.data
                street = form.default_street.data
                town_city = form.default_town_city.data
                phone = form.default_phone.data
                email = form.default_email.data
                order_notes = form.default_order_notes.data

            elif form.diffAddress.data:
                first_name = form.diff_first_name.data
                last_name = form.diff_last_name.data
                country = form.diff_country.data
                street = form.diff_street.data
                town_city = form.diff_town_city.data
                phone = form.diff_phone.data
                email = form.diff_email.data
                order_notes = form.dif_order_notes.data

            billing_detail = BillingDetail()
            billing_detail.first_name = first_name
            billing_detail.last_name = last_name
            billing_detail.country = country
            billing_detail.street = street
            billing_detail.town_city = town_city
            billing_detail.phone = phone
            billing_detail.email = email
            billing_detail.order_notes = order_notes

            if form.createAccount.data:
                if not User.query.filter((User.email == email)).first():
                    user = User()
                    user.first_name = first_name
                    user.last_name = last_name
                    user.email = email
                    user.password = form.passoword.data
                    user.email_confirmed = True
                    user.is_customer = True
                    user.email_confirm_date = datetime.now()

            order = Order()
            order.billing_detail = billing_detail
            shipping_option = DeliveryOption.query.get(
                request.form["deliveryoption"])
            order.shipping_option = shipping_option
            payment_option = PaymentOption.query.get(
                request.form["paymentoption"])
            order.payment_option = payment_option
            if current_user.is_authenticated:
                order.logged_in_customer_email = current_user.email

            if form.applyCoupon.data:
                coupon = Coupon.query.filter(
                    Coupon.string == form.coupon.data).first()
                if coupon:
                    order.coupon = coupon
                else:
                    flash(notify_warning("Invalid Coupon"))

            cart_info = get_cart_data()
            cart_data = cart_info["cart_data"]

            for barcode in Cart.data()['items']:
                for item in Cart.data()['items'][barcode]:
                    order_item = OrderItem()
                    product = Product.query.filter_by(barcode=barcode).first()
                    order_item.barcode = barcode
                    order_item.quantity = int(item['quantity'])
                    order_item.size = item['size']
                    order_item.color = item['color']
                    order.order_items.append(order_item)

            template = "shop/emails/order_info"
            subject = "FreaksBoutique - Order Details"
            context = {}
            context.update({'order': order, 'int': int, 'sum': sum})
            send_async_email(email, subject, template, **context)

            order.insert()
            flash(notify_success("Great!"))
            context = mhelp.context()
            Cart.reset()
            return render_template("shop/order_complete.html", **context)
        else:
            flash_errors(form)
        return mhelp.redirect_url("shop.checkout")