from flask import Blueprint, render_template, abort, request from app.services.helpers import ( FEATURED_PRODUCTS, get_products_by_filter, get_product, get_related_products, get_product_filter_options, ) shop_bp = Blueprint("shop", __name__) @shop_bp.route("/shop/") def hub(): q = (request.args.get("q") or "").strip() level = (request.args.get("level") or "").strip() category = (request.args.get("category") or "").strip() products = get_products_by_filter( filter_slug=None, q=q or None, level=level or None, category=category or None, ) return render_template( "shop/hub.html", title="Shop Teaching Resources | EFL by Level", meta_description="Shop CEFR teaching resources, IELTS packs, worksheets, games, and bundles.", products=products, filter_options=get_product_filter_options(), current_filters={ "q": q, "level": level, "category": category, }, ) @shop_bp.route("/shop//") def category(filter_slug): q = (request.args.get("q") or "").strip() level = (request.args.get("level") or "").strip() category_value = (request.args.get("category") or "").strip() products = get_products_by_filter( filter_slug=filter_slug, q=q or None, level=level or None, category=category_value or None, ) return render_template( "shop/category.html", title=f"Shop {filter_slug.replace('-', ' ').title()} | EFL by Level", meta_description="Browse filtered teaching resources.", filter_slug=filter_slug, products=products, filter_options=get_product_filter_options(), current_filters={ "q": q, "level": level, "category": category_value, }, ) @shop_bp.route("/product//") def product(slug): item = get_product(slug) if not item: abort(404) related_products = get_related_products( current_slug=item["slug"], category=item.get("category"), limit=3, ) return render_template( "shop/product.html", title=f"{item['title']} | EFL by Level", meta_description=item["description"], product=item, related_products=related_products, ) @shop_bp.route("/membership/") @shop_bp.route("/membership") def membership(): return render_template( "shop/membership.html", title="Teacher Membership | EFL by Level", meta_description="Join the teacher membership for monthly resources and discounts.", )