feat: platform-aware storefront routing and billing improvements
Overhaul storefront URL routing to be platform-aware:
- Dev: /platforms/{code}/storefront/{store_code}/
- Prod: subdomain.platform.lu/ (internally rewritten to /storefront/)
- Add subdomain detection in PlatformContextMiddleware
- Add /storefront/ path rewrite for prod mode (subdomain/custom domain)
- Remove all silent platform fallbacks (platform_id=1)
- Add require_platform dependency for clean endpoint validation
- Update route registration, templates, module definitions, base_url calc
- Update StoreContextMiddleware for /storefront/ path detection
- Remove /stores/ from FrontendDetector STOREFRONT_PATH_PREFIXES
Billing service improvements:
- Add store_platform_sync_service to keep store_platforms in sync
- Make tier lookups platform-aware across billing services
- Add tiers for all platforms in seed data
- Add demo subscriptions to seed
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -56,13 +56,14 @@ class AdminSubscriptionService:
|
||||
|
||||
return query.order_by(SubscriptionTier.display_order).all()
|
||||
|
||||
def get_tier_by_code(self, db: Session, tier_code: str) -> SubscriptionTier:
|
||||
"""Get a subscription tier by code."""
|
||||
tier = (
|
||||
db.query(SubscriptionTier)
|
||||
.filter(SubscriptionTier.code == tier_code)
|
||||
.first()
|
||||
)
|
||||
def get_tier_by_code(
|
||||
self, db: Session, tier_code: str, platform_id: int | None = None
|
||||
) -> SubscriptionTier:
|
||||
"""Get a subscription tier by code, optionally scoped to a platform."""
|
||||
query = db.query(SubscriptionTier).filter(SubscriptionTier.code == tier_code)
|
||||
if platform_id is not None:
|
||||
query = query.filter(SubscriptionTier.platform_id == platform_id)
|
||||
tier = query.first()
|
||||
|
||||
if not tier:
|
||||
raise TierNotFoundException(tier_code)
|
||||
@@ -214,7 +215,7 @@ class AdminSubscriptionService:
|
||||
db, merchant_id, platform_id, tier_code, sub.is_annual
|
||||
)
|
||||
else:
|
||||
tier = self.get_tier_by_code(db, tier_code)
|
||||
tier = self.get_tier_by_code(db, tier_code, platform_id=platform_id)
|
||||
sub.tier_id = tier.id
|
||||
|
||||
for field, value in update_data.items():
|
||||
@@ -350,6 +351,22 @@ class AdminSubscriptionService:
|
||||
|
||||
return results
|
||||
|
||||
def get_subscriptions_for_store(
|
||||
self, db: Session, store_id: int
|
||||
) -> list[dict]:
|
||||
"""Get subscriptions + feature usage for a store (resolves to merchant).
|
||||
|
||||
Convenience method for admin store detail page. Resolves
|
||||
store -> merchant -> all platform subscriptions.
|
||||
"""
|
||||
from app.modules.tenancy.models import Store
|
||||
|
||||
store = db.query(Store).filter(Store.id == store_id).first()
|
||||
if not store or not store.merchant_id:
|
||||
raise ResourceNotFoundException("Store", str(store_id))
|
||||
|
||||
return self.get_merchant_subscriptions_with_usage(db, store.merchant_id)
|
||||
|
||||
# =========================================================================
|
||||
# Statistics
|
||||
# =========================================================================
|
||||
|
||||
Reference in New Issue
Block a user