feat: implement vendor landing pages with multi-template support and fix shop routing
Major improvements to shop URL routing and vendor landing page system:
## Landing Page System
- Add template field to ContentPage model for flexible landing page designs
- Create 4 landing page templates: default, minimal, modern, and full
- Implement smart root handler to serve landing pages or redirect to shop
- Add create_landing_page.py script for easy landing page management
- Support both domain/subdomain and path-based vendor access
- Add comprehensive landing page documentation
## Route Fixes
- Fix duplicate /shop prefix in shop_pages.py routes
- Correct product detail page routing (was /shop/shop/products/{id})
- Update all shop routes to work with router prefix mounting
- Remove unused public vendor endpoints (/api/v1/public/vendors)
## Template Link Corrections
- Fix all shop template links to include /shop/ prefix
- Update breadcrumb 'Home' links to point to vendor root (landing page)
- Update header navigation 'Home' link to point to vendor root
- Correct CMS page links in footer navigation
- Fix account, cart, and error page navigation links
## Navigation Architecture
- Establish two-tier navigation: landing page (/) and shop (/shop/)
- Document complete navigation flow and URL hierarchy
- Support for vendors with or without landing pages (auto-redirect fallback)
- Consistent breadcrumb and header navigation behavior
## Documentation
- Add vendor-landing-pages.md feature documentation
- Add navigation-flow.md with complete URL hierarchy
- Update shop architecture docs with error handling section
- Add orphaned docs to mkdocs.yml navigation
- Document multi-access routing patterns
## Database
- Migration f68d8da5315a: add template field to content_pages table
- Support template values: default, minimal, modern, full
This establishes a complete landing page system allowing vendors to have
custom marketing homepages separate from their e-commerce shop, with
flexible template options and proper navigation hierarchy.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
101
main.py
101
main.py
@@ -230,6 +230,48 @@ app.include_router(
|
||||
include_in_schema=False
|
||||
)
|
||||
|
||||
# Add handler for /vendors/{vendor_code}/ root path
|
||||
@app.get("/vendors/{vendor_code}/", response_class=HTMLResponse, include_in_schema=False)
|
||||
async def vendor_root_path(vendor_code: str, request: Request, db: Session = Depends(get_db)):
|
||||
"""Handle vendor root path (e.g., /vendors/wizamart/)"""
|
||||
# Vendor should already be in request.state from middleware
|
||||
vendor = getattr(request.state, 'vendor', None)
|
||||
|
||||
if not vendor:
|
||||
raise HTTPException(status_code=404, detail=f"Vendor '{vendor_code}' not found")
|
||||
|
||||
from app.services.content_page_service import content_page_service
|
||||
from app.routes.shop_pages import get_shop_context
|
||||
|
||||
# Try to find landing page
|
||||
landing_page = content_page_service.get_page_for_vendor(
|
||||
db,
|
||||
slug="landing",
|
||||
vendor_id=vendor.id,
|
||||
include_unpublished=False
|
||||
)
|
||||
|
||||
if not landing_page:
|
||||
landing_page = content_page_service.get_page_for_vendor(
|
||||
db,
|
||||
slug="home",
|
||||
vendor_id=vendor.id,
|
||||
include_unpublished=False
|
||||
)
|
||||
|
||||
if landing_page:
|
||||
# Render landing page with selected template
|
||||
template_name = landing_page.template or "default"
|
||||
template_path = f"vendor/landing-{template_name}.html"
|
||||
|
||||
return templates.TemplateResponse(
|
||||
template_path,
|
||||
get_shop_context(request, db=db, page=landing_page)
|
||||
)
|
||||
else:
|
||||
# No landing page - redirect to shop
|
||||
return RedirectResponse(url=f"/vendors/{vendor_code}/shop/", status_code=302)
|
||||
|
||||
logger.info("=" * 80)
|
||||
|
||||
# Log all registered routes
|
||||
@@ -247,10 +289,61 @@ logger.info("=" * 80)
|
||||
# ============================================================================
|
||||
|
||||
# Public Routes (no authentication required)
|
||||
@app.get("/", include_in_schema=False)
|
||||
async def root():
|
||||
"""Redirect root to documentation"""
|
||||
return RedirectResponse(url="/documentation")
|
||||
@app.get("/", response_class=HTMLResponse, include_in_schema=False)
|
||||
async def root(request: Request, db: Session = Depends(get_db)):
|
||||
"""
|
||||
Smart root handler:
|
||||
- If vendor detected (domain/subdomain): Show vendor landing page or redirect to shop
|
||||
- If no vendor (platform root): Redirect to documentation
|
||||
"""
|
||||
vendor = getattr(request.state, 'vendor', None)
|
||||
|
||||
if vendor:
|
||||
# Vendor context detected - serve landing page
|
||||
from app.services.content_page_service import content_page_service
|
||||
|
||||
# Try to find landing page (slug='landing' or 'home')
|
||||
landing_page = content_page_service.get_page_for_vendor(
|
||||
db,
|
||||
slug="landing",
|
||||
vendor_id=vendor.id,
|
||||
include_unpublished=False
|
||||
)
|
||||
|
||||
if not landing_page:
|
||||
# Try 'home' slug as fallback
|
||||
landing_page = content_page_service.get_page_for_vendor(
|
||||
db,
|
||||
slug="home",
|
||||
vendor_id=vendor.id,
|
||||
include_unpublished=False
|
||||
)
|
||||
|
||||
if landing_page:
|
||||
# Render landing page with selected template
|
||||
from app.routes.shop_pages import get_shop_context
|
||||
|
||||
template_name = landing_page.template or "default"
|
||||
template_path = f"vendor/landing-{template_name}.html"
|
||||
|
||||
return templates.TemplateResponse(
|
||||
template_path,
|
||||
get_shop_context(request, db=db, page=landing_page)
|
||||
)
|
||||
else:
|
||||
# No landing page - redirect to shop
|
||||
vendor_context = getattr(request.state, 'vendor_context', None)
|
||||
access_method = vendor_context.get('detection_method', 'unknown') if vendor_context else 'unknown'
|
||||
|
||||
if access_method == "path":
|
||||
full_prefix = vendor_context.get('full_prefix', '/vendor/') if vendor_context else '/vendor/'
|
||||
return RedirectResponse(url=f"{full_prefix}{vendor.subdomain}/shop/", status_code=302)
|
||||
else:
|
||||
# Domain/subdomain
|
||||
return RedirectResponse(url="/shop/", status_code=302)
|
||||
else:
|
||||
# No vendor - platform root
|
||||
return RedirectResponse(url="/documentation")
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
|
||||
Reference in New Issue
Block a user