Beispiel #1
0
def delete_product(id):
    if request.method == "GET":
        #delete product and it's details.
        ProductDetails.delete_product_details(ProductDetails, id)
        flash("Product deleted successfully!!", "success")
        return redirect(url_for("vendors.sales"))
    else:
        abort(403)
Beispiel #2
0
def product_upload():
    form = AddProduct()
    if form.validate_on_submit():
        sub_category = session.query(SubCategory).filter_by(
            name=form.sub_category.data).first()
        shop = session.query(Shop).filter_by(id=current_user.id).first()
        if sub_category:
            #save product
            product = Product(form.name.data, sub_category, shop)
            if product:
                #upload photo to the server
                front_picture = save_picture(form.front_pic.data,
                                             "static/vendor_product_pictures",
                                             800, 800)
                back_picture = save_picture(form.back_pic.data,
                                            "static/vendor_product_pictures",
                                            800, 800)
                #save product details
                ProductDetails(product_type=form.product_type.data,
                               brand=form.brand.data,
                               color=form.color.data,
                               size=form.size.data,
                               front_picture=front_picture,
                               back_picture=back_picture,
                               key_features=form.key_features.data,
                               quantity=form.quantity.data,
                               prize=form.prize.data,
                               weight=form.weight.data,
                               description=form.description.data,
                               warranty=form.warranty.data,
                               guarantee=form.guarantee.data,
                               product=product)
                flash("Your product has been saved successfully!!", "success")
                return redirect(url_for("vendors.product_upload"))
    return render_template('vendor/product-upload.html', form=form)
Beispiel #3
0
def product_details(id):
    form = AddStock()
    if request.method == "GET":
        product = ProductDetails.read_product_details(ProductDetails, id)
        return render_template('vendor/product-detail-vendor.html',
                               form=form,
                               product=product)
Beispiel #4
0
def add_stock(id):
    if request.method == "POST":
        product = ProductDetails.read_product_details(ProductDetails, id)
        if product:
            #increase stock
            try:
                quantity = int(request.form['quantity'])
                ProductDetails.increase_stock(ProductDetails,
                                              product.prod_details_id,
                                              quantity)
                # TrackProducts(quantity, product)
                flash("Product stock increased successfully!!", "success")
                return redirect(url_for("vendors.product_details", id=id))
            except ValueError:
                flash("Must be a number e.g 1.", "info")
                return redirect(url_for("vendors.product_details", id=id))
        else:
            flash("Product doesnot exists!!", "error")
            return redirect(url_for("vendors.product_details", id=id))
Beispiel #5
0
def set_promo_price(id):
    form = AddStock()
    if request.method == "POST":
        product = ProductDetails.read_product_details(ProductDetails, id)
        #check if product exists
        if product:
            # adding promotional price
            try:
                promotional_price = int(form.price.data)
                ProductDetails.set_promotional_price(ProductDetails,
                                                     product.prod_details_id,
                                                     promotional_price)
                flash("Promotional price has been set up successfully!!",
                      "success")
                return redirect(url_for("vendors.product_details", id=id))

            except ValueError:
                flash("Must be a number e.g 1000.", "info")
                return redirect(url_for("vendors.product_details", id=id))
        else:
            flash("Product doesnot exists!!", "error")
            return redirect(url_for("vendors.product_details", id=id))
Beispiel #6
0
def product():
    if request.method == "GET":
        page_number = request.args.get("page", 1, type=int)
        pages = Paginate(ProductDetails.read_products_details(ProductDetails),
                         page_number, 10)
        prev_url = url_for(
            "vendors.product",
            page=pages.previous_page) if pages.has_previous else None
        next_url = url_for("vendors.product",
                           page=pages.next_page) if pages.has_next else None

    return render_template('vendor/listed-products.html',
                           pages=pages,
                           next_url=next_url,
                           prev_url=prev_url)
Beispiel #7
0
def home():
    form = LoginForm()
    # cart_items = AddToCart.read_customer_cart_items(AddToCart, current_user.id)
    if request.method == "GET":
        images = session.query(HomeSlideShowImages)\
        .order_by(HomeSlideShowImages.order).all()

        ordered_categories = Category.getHomeDisplayCategories(Category)
        page_number = request.args.get("page", 1, type=int)
        pages = Paginate(ProductDetails.read_products_details(ProductDetails),
                         page_number, 10)
        prev_url = url_for(
            "customers.home",
            page=pages.previous_page) if pages.has_previous else None
        next_url = url_for("customers.home",
                           page=pages.next_page) if pages.has_next else None
    return render_template('customer/index.html',
                           form=form,
                           pages=pages,
                           next_url=next_url,
                           prev_url=prev_url,
                           images=images,
                           enumerate=enumerate,
                           ordered_categories=ordered_categories)
Beispiel #8
0
def product_details(id):
    form = AddToCartForm()

    if request.method == "GET":
        pdt = ProductDetails.read_product_details(ProductDetails, id)
        product_key = "product-%s" % pdt.prod_details_id
        redis.set(product_key, json.dumps(pdt.serialize()))
        redis.expire(product_key, 600)
        keys_live = redis.keys("product-*")
        recently_viewed = [json.loads(redis.get(k)) for k in keys_live]
        sub_cat = pdt.product.sub_category
        cat = sub_cat.category
        products_same_sub_cat = ProductDetails.products_same_sub_cat(
            ProductDetails, sub_cat.sub_category_id)
        form.product_image.data = pdt.front_picture
        form.product_name.data = pdt.product.name
        if pdt.promotional_price:
            form.unit_price.data = pdt.promotional_price
        else:
            form.unit_price.data = pdt.prize
        if pdt.color:
            form.color.choices = [(color, color)
                                  for color in pdt.color.split(',')]
        else:
            pass
        if pdt.size:
            form.size.choices = [(size, size) for size in pdt.size.split(',')]
        else:
            pass
        if pdt.weight:
            form.weight.choices = [(weight, weight)
                                   for weight in pdt.weight.split(',')]
        else:
            pass
        return render_template('customer/detail.html',
                               form=form,
                               pdt=pdt,
                               sub_category=sub_cat.name,
                               category=cat.name,
                               you_may_like=products_same_sub_cat,
                               recently_viewed=recently_viewed)

    elif request.method == "POST":
        if form.quantity.data and form.unit_price.data and form.product_image.data and form.product_name.data:
            pdt = ProductDetails.read_product_details(ProductDetails, id)
            if form.quantity.data > pdt.quantity:
                flash("You specified more than is available", "info")
                return redirect(url_for("customers.product_details", id=id))
            else:
                if pdt.promotional_price:
                    customer = Customer.read_customer(Customer,
                                                      current_user.id)
                    AddToCart(form.product_image.data, form.product_name.data,
                              form.quantity.data, pdt.promotional_price,
                              form.size.data, form.color.data,
                              form.weight.data, customer)
                    cart_items = AddToCart.read_customer_cart_items(
                        AddToCart, current_user.id)
                    period["cart_len"] = len(cart_items)
                    flash("Product added successfully to the Cart", "success")
                    return redirect(url_for("customers.product_details",
                                            id=id))
                else:
                    customer = Customer.read_customer(Customer,
                                                      current_user.id)
                    AddToCart(form.product_image.data, form.product_name.data,
                              form.quantity.data, form.unit_price.data,
                              form.size.data, form.color.data,
                              form.weight.data, customer)
                    cart_items = AddToCart.read_customer_cart_items(
                        AddToCart, current_user.id)
                    period["cart_len"] = len(cart_items)
                    flash("Product added successfully to the Cart", "success")
                    return redirect(url_for("customers.product_details",
                                            id=id))

        else:
            flash(
                "Please fill the specification form in order to get the right product!!",
                "info")
            return redirect(url_for("customers.product_details", id=id))
Beispiel #9
0
def edit_product(id):
    form = EditProductForm()
    if request.method == "GET":
        product = ProductDetails.read_product_details(ProductDetails, id)
        sub_cat = product.product.sub_category
        cat = sub_cat.category
        form.name.data = product.product.name
        form.category.data = cat.name
        form.sub_category.data = sub_cat.name
        form.brand.data = product.brand
        form.product_type.data = product.product_type
        form.size.data = product.size
        form.color.data = product.color
        form.weight.data = product.weight
        form.description.data = product.description
        form.prize.data = product.prize
        form.key_features.data = product.key_features
        form.warranty.data = product.warranty
        form.guarantee.data = product.guarantee
        return render_template('vendor/edit_product.html',
                               form=form,
                               front_pic=product.front_picture,
                               back_pic=product.back_picture,
                               id=id)

    elif request.method == "POST":
        if form.validate_on_submit():
            #update product details
            if form.front_pic.data and form.back_pic.data:
                front_picture = save_picture(form.front_pic.data,
                                             "static/vendor_product_pictures",
                                             800, 800)
                back_picture = save_picture(form.back_pic.data,
                                            "static/vendor_product_pictures",
                                            800, 800)
                product = ProductDetails.read_product_details(
                    ProductDetails, id)
                Product.update_product(Product, product.product_id,
                                       form.name.data)
                ProductDetails.update_product_details(
                    ProductDetails, id, form.brand.data,
                    form.product_type.data, form.size.data, form.color.data,
                    form.weight.data, form.key_features.data,
                    form.description.data, form.prize.data, form.warranty.data,
                    form.guarantee.data, front_picture, back_picture)
                flash("Product has been updated successfully!!", "success")
                return redirect(url_for("vendors.edit_product", id=id))
            else:
                product = ProductDetails.read_product_details(
                    ProductDetails, id)
                Product.update_product(Product, product.product_id,
                                       form.name.data)
                ProductDetails.update_product_details(
                    ProductDetails, id, form.brand.data,
                    form.product_type.data, form.size.data, form.color.data,
                    form.weight.data, form.key_features.data,
                    form.description.data, form.prize.data, form.warranty.data,
                    form.guarantee.data, product.front_picture,
                    product.back_picture)
                flash("Product has been updated successfully!!", "success")
                return redirect(url_for("vendors.edit_product", id=id))
        else:
            flash("Form not validated well!!", "info")
            return redirect(url_for("vendors.edit_product", id=id))