fix(cms): filter pricing tiers by platform_id on homepage
Some checks failed
Some checks failed
_get_tiers_data() was querying all active tiers across all platforms. Now accepts platform_id parameter to scope tiers to the current platform. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -28,16 +28,20 @@ ROUTE_CONFIG = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def _get_tiers_data(db: Session) -> list[dict]:
|
def _get_tiers_data(db: Session, platform_id: int | None = None) -> list[dict]:
|
||||||
"""Build tier data for display in templates from database."""
|
"""Build tier data for display in templates from database."""
|
||||||
from app.modules.billing.models import SubscriptionTier, TierCode
|
from app.modules.billing.models import SubscriptionTier, TierCode
|
||||||
|
|
||||||
|
filters = [
|
||||||
|
SubscriptionTier.is_active.is_(True),
|
||||||
|
SubscriptionTier.is_public.is_(True),
|
||||||
|
]
|
||||||
|
if platform_id is not None:
|
||||||
|
filters.append(SubscriptionTier.platform_id == platform_id)
|
||||||
|
|
||||||
tiers_db = (
|
tiers_db = (
|
||||||
db.query(SubscriptionTier)
|
db.query(SubscriptionTier)
|
||||||
.filter(
|
.filter(*filters)
|
||||||
SubscriptionTier.is_active == True,
|
|
||||||
SubscriptionTier.is_public == True,
|
|
||||||
)
|
|
||||||
.order_by(SubscriptionTier.display_order)
|
.order_by(SubscriptionTier.display_order)
|
||||||
.all()
|
.all()
|
||||||
)
|
)
|
||||||
@@ -156,7 +160,7 @@ async def homepage(
|
|||||||
# Use CMS-based homepage with template selection
|
# Use CMS-based homepage with template selection
|
||||||
context = get_platform_context(request, db)
|
context = get_platform_context(request, db)
|
||||||
context["page"] = cms_homepage
|
context["page"] = cms_homepage
|
||||||
context["tiers"] = _get_tiers_data(db)
|
context["tiers"] = _get_tiers_data(db, platform_id=platform_id)
|
||||||
|
|
||||||
template_name = cms_homepage.template or "default"
|
template_name = cms_homepage.template or "default"
|
||||||
template_path = f"cms/platform/homepage-{template_name}.html"
|
template_path = f"cms/platform/homepage-{template_name}.html"
|
||||||
@@ -167,7 +171,7 @@ async def homepage(
|
|||||||
# Fallback: Default homepage template with placeholder content
|
# Fallback: Default homepage template with placeholder content
|
||||||
logger.info("[HOMEPAGE] No CMS homepage found, using default template with placeholders")
|
logger.info("[HOMEPAGE] No CMS homepage found, using default template with placeholders")
|
||||||
context = get_platform_context(request, db)
|
context = get_platform_context(request, db)
|
||||||
context["tiers"] = _get_tiers_data(db)
|
context["tiers"] = _get_tiers_data(db, platform_id=platform_id)
|
||||||
|
|
||||||
return templates.TemplateResponse(
|
return templates.TemplateResponse(
|
||||||
"cms/platform/homepage-default.html",
|
"cms/platform/homepage-default.html",
|
||||||
|
|||||||
Reference in New Issue
Block a user