#!/usr/bin/env python3
"""
Seed default email templates.
Run: python scripts/seed_email_templates.py
"""
import contextlib
import json
import sys
from pathlib import Path
# Add project root to path
sys.path.insert(0, str(Path(__file__).parent.parent))
# Register all models with SQLAlchemy so string-based relationships resolve
for _mod in [
"app.modules.billing.models",
"app.modules.inventory.models",
"app.modules.cart.models",
"app.modules.messaging.models",
"app.modules.loyalty.models",
"app.modules.catalog.models",
"app.modules.customers.models",
"app.modules.orders.models",
"app.modules.marketplace.models",
"app.modules.cms.models",
]:
with contextlib.suppress(ImportError):
__import__(_mod)
from app.core.database import get_db
from app.modules.messaging.models import EmailCategory, EmailTemplate
# =============================================================================
# EMAIL TEMPLATES
# =============================================================================
TEMPLATES = [
# -------------------------------------------------------------------------
# SIGNUP WELCOME
# -------------------------------------------------------------------------
{
"code": "signup_welcome",
"language": "en",
"name": "Signup Welcome",
"description": "Sent to new stores after successful signup",
"category": EmailCategory.AUTH.value,
"variables": json.dumps([
"first_name", "merchant_name", "email", "store_code",
"login_url", "trial_days", "tier_name"
]),
"subject": "Welcome to Orion, {{ first_name }}!",
"body_html": """
Welcome to Orion!
Hi {{ first_name }},
Thank you for signing up for Orion! Your account for {{ merchant_name }} is now active.
Your Account Details
Store Code: {{ store_code }}
Plan: {{ tier_name }}
Trial Period: {{ trial_days }} days free
You can start managing your orders, inventory, and invoices right away:
Getting Started
- Complete your merchant profile
- Connect your Letzshop API credentials
- Import your products
- Start syncing orders!
If you have any questions, just reply to this email or visit our help center.
Best regards,
The Orion Team
© 2024 Orion. Built for Luxembourg e-commerce.
""",
"body_text": """Welcome to Orion!
Hi {{ first_name }},
Thank you for signing up for Orion! Your account for {{ merchant_name }} is now active.
Your Account Details:
- Store Code: {{ store_code }}
- Plan: {{ tier_name }}
- Trial Period: {{ trial_days }} days free
You can start managing your orders, inventory, and invoices right away.
Go to Dashboard: {{ login_url }}
Getting Started:
1. Complete your merchant profile
2. Connect your Letzshop API credentials
3. Import your products
4. Start syncing orders!
If you have any questions, just reply to this email.
Best regards,
The Orion Team
""",
},
{
"code": "signup_welcome",
"language": "fr",
"name": "Bienvenue après inscription",
"description": "Envoyé aux nouveaux vendeurs après inscription",
"category": EmailCategory.AUTH.value,
"variables": json.dumps([
"first_name", "merchant_name", "email", "store_code",
"login_url", "trial_days", "tier_name"
]),
"subject": "Bienvenue sur Orion, {{ first_name }} !",
"body_html": """
Bienvenue sur Orion !
Bonjour {{ first_name }},
Merci de vous être inscrit sur Orion ! Votre compte pour {{ merchant_name }} est maintenant actif.
Détails de votre compte
Code vendeur : {{ store_code }}
Forfait : {{ tier_name }}
Période d'essai : {{ trial_days }} jours gratuits
Vous pouvez commencer à gérer vos commandes, stocks et factures dès maintenant :
Pour commencer
- Complétez votre profil d'entreprise
- Connectez vos identifiants API Letzshop
- Importez vos produits
- Commencez à synchroniser vos commandes !
Si vous avez des questions, répondez simplement à cet email.
Cordialement,
L'équipe Orion
© 2024 Orion. Conçu pour le e-commerce luxembourgeois.
""",
"body_text": """Bienvenue sur Orion !
Bonjour {{ first_name }},
Merci de vous être inscrit sur Orion ! Votre compte pour {{ merchant_name }} est maintenant actif.
Détails de votre compte :
- Code vendeur : {{ store_code }}
- Forfait : {{ tier_name }}
- Période d'essai : {{ trial_days }} jours gratuits
Accéder au tableau de bord : {{ login_url }}
Pour commencer :
1. Complétez votre profil d'entreprise
2. Connectez vos identifiants API Letzshop
3. Importez vos produits
4. Commencez à synchroniser vos commandes !
Cordialement,
L'équipe Orion
""",
},
{
"code": "signup_welcome",
"language": "de",
"name": "Willkommen nach Anmeldung",
"description": "An neue Verkäufer nach erfolgreicher Anmeldung gesendet",
"category": EmailCategory.AUTH.value,
"variables": json.dumps([
"first_name", "merchant_name", "email", "store_code",
"login_url", "trial_days", "tier_name"
]),
"subject": "Willkommen bei Orion, {{ first_name }}!",
"body_html": """
Willkommen bei Orion!
Hallo {{ first_name }},
Vielen Dank für Ihre Anmeldung bei Orion! Ihr Konto für {{ merchant_name }} ist jetzt aktiv.
Ihre Kontodaten
Verkäufercode: {{ store_code }}
Tarif: {{ tier_name }}
Testzeitraum: {{ trial_days }} Tage kostenlos
Sie können sofort mit der Verwaltung Ihrer Bestellungen, Bestände und Rechnungen beginnen:
Erste Schritte
- Vervollständigen Sie Ihr Firmenprofil
- Verbinden Sie Ihre Letzshop API-Zugangsdaten
- Importieren Sie Ihre Produkte
- Starten Sie die Bestellungssynchronisierung!
Bei Fragen antworten Sie einfach auf diese E-Mail.
Mit freundlichen Grüßen,
Das Orion-Team
© 2024 Orion. Entwickelt für den luxemburgischen E-Commerce.
""",
"body_text": """Willkommen bei Orion!
Hallo {{ first_name }},
Vielen Dank für Ihre Anmeldung bei Orion! Ihr Konto für {{ merchant_name }} ist jetzt aktiv.
Ihre Kontodaten:
- Verkäufercode: {{ store_code }}
- Tarif: {{ tier_name }}
- Testzeitraum: {{ trial_days }} Tage kostenlos
Zum Dashboard: {{ login_url }}
Erste Schritte:
1. Vervollständigen Sie Ihr Firmenprofil
2. Verbinden Sie Ihre Letzshop API-Zugangsdaten
3. Importieren Sie Ihre Produkte
4. Starten Sie die Bestellungssynchronisierung!
Mit freundlichen Grüßen,
Das Orion-Team
""",
},
{
"code": "signup_welcome",
"language": "lb",
"name": "Wëllkomm no der Umeldung",
"description": "Un nei Verkeefer no erfollegräicher Umeldung geschéckt",
"category": EmailCategory.AUTH.value,
"variables": json.dumps([
"first_name", "merchant_name", "email", "store_code",
"login_url", "trial_days", "tier_name"
]),
"subject": "Wëllkomm op Orion, {{ first_name }}!",
"body_html": """
Wëllkomm op Orion!
Moien {{ first_name }},
Merci fir d'Umeldung op Orion! Äre Kont fir {{ merchant_name }} ass elo aktiv.
Är Kontdetailer
Verkeefer Code: {{ store_code }}
Plang: {{ tier_name }}
Testperiod: {{ trial_days }} Deeg gratis
Dir kënnt direkt ufänken Är Bestellungen, Lager a Rechnungen ze verwalten:
Fir unzefänken
- Fëllt Äre Firmeprofil aus
- Verbindt Är Letzshop API Zougangsdaten
- Importéiert Är Produkter
- Fänkt un Bestellungen ze synchroniséieren!
Wann Dir Froen hutt, äntwert einfach op dës E-Mail.
Mat beschte Gréiss,
D'Orion Team
© 2024 Orion. Gemaach fir de lëtzebuergeschen E-Commerce.
""",
"body_text": """Wëllkomm op Orion!
Moien {{ first_name }},
Merci fir d'Umeldung op Orion! Äre Kont fir {{ merchant_name }} ass elo aktiv.
Är Kontdetailer:
- Verkeefer Code: {{ store_code }}
- Plang: {{ tier_name }}
- Testperiod: {{ trial_days }} Deeg gratis
Zum Dashboard: {{ login_url }}
Fir unzefänken:
1. Fëllt Äre Firmeprofil aus
2. Verbindt Är Letzshop API Zougangsdaten
3. Importéiert Är Produkter
4. Fänkt un Bestellungen ze synchroniséieren!
Mat beschte Gréiss,
D'Orion Team
""",
},
# -------------------------------------------------------------------------
# ORDER CONFIRMATION
# -------------------------------------------------------------------------
{
"code": "order_confirmation",
"language": "en",
"name": "Order Confirmation",
"description": "Sent to customers after placing an order",
"category": EmailCategory.ORDERS.value,
"variables": json.dumps([
"customer_name", "order_number", "order_total",
"order_items_count", "order_date", "shipping_address"
]),
"subject": "Order Confirmation - {{ order_number }}",
"body_html": """
Order Confirmed!
Hi {{ customer_name }},
Thank you for your order! We've received your order and it's being processed.
Order Details
Order Number: {{ order_number }}
Date: {{ order_date }}
Items: {{ order_items_count }}
Total: {{ order_total }}
Shipping Address
{{ shipping_address }}
You will receive another email when your order ships.
If you have any questions about your order, please contact us.
Thank you for shopping with us!
The Team
This is an automated email. Please do not reply directly.
""",
"body_text": """Order Confirmed!
Hi {{ customer_name }},
Thank you for your order! We've received your order and it's being processed.
Order Details:
- Order Number: {{ order_number }}
- Date: {{ order_date }}
- Items: {{ order_items_count }}
- Total: {{ order_total }}
Shipping Address:
{{ shipping_address }}
You will receive another email when your order ships.
Thank you for shopping with us!
""",
},
{
"code": "order_confirmation",
"language": "fr",
"name": "Confirmation de commande",
"description": "Envoyé aux clients après avoir passé une commande",
"category": EmailCategory.ORDERS.value,
"variables": json.dumps([
"customer_name", "order_number", "order_total",
"order_items_count", "order_date", "shipping_address"
]),
"subject": "Confirmation de commande - {{ order_number }}",
"body_html": """
Commande confirmée !
Bonjour {{ customer_name }},
Merci pour votre commande ! Nous l'avons bien reçue et elle est en cours de traitement.
Détails de la commande
Numéro de commande : {{ order_number }}
Date : {{ order_date }}
Articles : {{ order_items_count }}
Total : {{ order_total }}
Adresse de livraison
{{ shipping_address }}
Vous recevrez un autre email lors de l'expédition de votre commande.
Si vous avez des questions concernant votre commande, n'hésitez pas à nous contacter.
Merci pour votre achat !
L'équipe
""",
"body_text": """Commande confirmée !
Bonjour {{ customer_name }},
Merci pour votre commande ! Nous l'avons bien reçue et elle est en cours de traitement.
Détails de la commande :
- Numéro de commande : {{ order_number }}
- Date : {{ order_date }}
- Articles : {{ order_items_count }}
- Total : {{ order_total }}
Adresse de livraison :
{{ shipping_address }}
Vous recevrez un autre email lors de l'expédition de votre commande.
Merci pour votre achat !
""",
},
{
"code": "order_confirmation",
"language": "de",
"name": "Bestellbestätigung",
"description": "An Kunden nach einer Bestellung gesendet",
"category": EmailCategory.ORDERS.value,
"variables": json.dumps([
"customer_name", "order_number", "order_total",
"order_items_count", "order_date", "shipping_address"
]),
"subject": "Bestellbestätigung - {{ order_number }}",
"body_html": """
Bestellung bestätigt!
Hallo {{ customer_name }},
Vielen Dank für Ihre Bestellung! Wir haben Ihre Bestellung erhalten und sie wird bearbeitet.
Bestelldetails
Bestellnummer: {{ order_number }}
Datum: {{ order_date }}
Artikel: {{ order_items_count }}
Summe: {{ order_total }}
Lieferadresse
{{ shipping_address }}
Sie erhalten eine weitere E-Mail, sobald Ihre Bestellung versandt wird.
Bei Fragen zu Ihrer Bestellung kontaktieren Sie uns bitte.
Vielen Dank für Ihren Einkauf!
Das Team
""",
"body_text": """Bestellung bestätigt!
Hallo {{ customer_name }},
Vielen Dank für Ihre Bestellung! Wir haben Ihre Bestellung erhalten und sie wird bearbeitet.
Bestelldetails:
- Bestellnummer: {{ order_number }}
- Datum: {{ order_date }}
- Artikel: {{ order_items_count }}
- Summe: {{ order_total }}
Lieferadresse:
{{ shipping_address }}
Sie erhalten eine weitere E-Mail, sobald Ihre Bestellung versandt wird.
Vielen Dank für Ihren Einkauf!
""",
},
{
"code": "order_confirmation",
"language": "lb",
"name": "Bestellung Konfirmatioun",
"description": "Un Clienten no enger Bestellung geschéckt",
"category": EmailCategory.ORDERS.value,
"variables": json.dumps([
"customer_name", "order_number", "order_total",
"order_items_count", "order_date", "shipping_address"
]),
"subject": "Bestellung Konfirmatioun - {{ order_number }}",
"body_html": """
Bestellung confirméiert!
Moien {{ customer_name }},
Merci fir Är Bestellung! Mir hunn Är Bestellung kritt an si gëtt beaarbecht.
Bestelldetailer
Bestellnummer: {{ order_number }}
Datum: {{ order_date }}
Artikelen: {{ order_items_count }}
Total: {{ order_total }}
Liwweradress
{{ shipping_address }}
Dir kritt eng weider E-Mail wann Är Bestellung verschéckt gëtt.
Wann Dir Froen iwwer Är Bestellung hutt, kontaktéiert eis w.e.g.
Merci fir Ären Akaf!
D'Team
""",
"body_text": """Bestellung confirméiert!
Moien {{ customer_name }},
Merci fir Är Bestellung! Mir hunn Är Bestellung kritt an si gëtt beaarbecht.
Bestelldetailer:
- Bestellnummer: {{ order_number }}
- Datum: {{ order_date }}
- Artikelen: {{ order_items_count }}
- Total: {{ order_total }}
Liwweradress:
{{ shipping_address }}
Dir kritt eng weider E-Mail wann Är Bestellung verschéckt gëtt.
Merci fir Ären Akaf!
""",
},
# -------------------------------------------------------------------------
# PASSWORD RESET
# -------------------------------------------------------------------------
{
"code": "password_reset",
"language": "en",
"name": "Password Reset",
"description": "Sent to customers when they request a password reset",
"category": EmailCategory.AUTH.value,
"variables": json.dumps([
"customer_name", "reset_link", "expiry_hours"
]),
"subject": "Reset Your Password",
"body_html": """
Reset Your Password
Hi {{ customer_name }},
We received a request to reset your password. Click the button below to create a new password:
This link will expire in {{ expiry_hours }} hour(s). If you didn't request this password reset, you can safely ignore this email.
If the button doesn't work, copy and paste this link into your browser:
{{ reset_link }}
Best regards,
The Team
This is an automated email. Please do not reply directly.
""",
"body_text": """Reset Your Password
Hi {{ customer_name }},
We received a request to reset your password. Click the link below to create a new password:
{{ reset_link }}
This link will expire in {{ expiry_hours }} hour(s). If you didn't request this password reset, you can safely ignore this email.
Best regards,
The Team
""",
},
{
"code": "password_reset",
"language": "fr",
"name": "Reinitialisation du mot de passe",
"description": "Envoye aux clients lorsqu'ils demandent une reinitialisation de mot de passe",
"category": EmailCategory.AUTH.value,
"variables": json.dumps([
"customer_name", "reset_link", "expiry_hours"
]),
"subject": "Reinitialiser votre mot de passe",
"body_html": """
Reinitialiser votre mot de passe
Bonjour {{ customer_name }},
Nous avons recu une demande de reinitialisation de votre mot de passe. Cliquez sur le bouton ci-dessous pour creer un nouveau mot de passe :
Ce lien expirera dans {{ expiry_hours }} heure(s). Si vous n'avez pas demande cette reinitialisation, vous pouvez ignorer cet email.
Si le bouton ne fonctionne pas, copiez et collez ce lien dans votre navigateur :
{{ reset_link }}
Cordialement,
L'equipe
""",
"body_text": """Reinitialiser votre mot de passe
Bonjour {{ customer_name }},
Nous avons recu une demande de reinitialisation de votre mot de passe. Cliquez sur le lien ci-dessous pour creer un nouveau mot de passe :
{{ reset_link }}
Ce lien expirera dans {{ expiry_hours }} heure(s). Si vous n'avez pas demande cette reinitialisation, vous pouvez ignorer cet email.
Cordialement,
L'equipe
""",
},
{
"code": "password_reset",
"language": "de",
"name": "Passwort zurucksetzen",
"description": "An Kunden gesendet, wenn sie eine Passwortzurucksetzung anfordern",
"category": EmailCategory.AUTH.value,
"variables": json.dumps([
"customer_name", "reset_link", "expiry_hours"
]),
"subject": "Passwort zurucksetzen",
"body_html": """
Passwort zurucksetzen
Hallo {{ customer_name }},
Wir haben eine Anfrage zur Zurucksetzung Ihres Passworts erhalten. Klicken Sie auf die Schaltflache unten, um ein neues Passwort zu erstellen:
Dieser Link lauft in {{ expiry_hours }} Stunde(n) ab. Wenn Sie diese Passwortzurucksetzung nicht angefordert haben, konnen Sie diese E-Mail ignorieren.
Wenn die Schaltflache nicht funktioniert, kopieren Sie diesen Link in Ihren Browser:
{{ reset_link }}
Mit freundlichen Grussen,
Das Team
""",
"body_text": """Passwort zurucksetzen
Hallo {{ customer_name }},
Wir haben eine Anfrage zur Zurucksetzung Ihres Passworts erhalten. Klicken Sie auf den Link unten, um ein neues Passwort zu erstellen:
{{ reset_link }}
Dieser Link lauft in {{ expiry_hours }} Stunde(n) ab. Wenn Sie diese Passwortzurucksetzung nicht angefordert haben, konnen Sie diese E-Mail ignorieren.
Mit freundlichen Grussen,
Das Team
""",
},
{
"code": "password_reset",
"language": "lb",
"name": "Passwuert zrecksetzen",
"description": "Un Clienten gescheckt wann si eng Passwuertzrecksetzung ufroen",
"category": EmailCategory.AUTH.value,
"variables": json.dumps([
"customer_name", "reset_link", "expiry_hours"
]),
"subject": "Passwuert zrecksetzen",
"body_html": """
Passwuert zrecksetzen
Moien {{ customer_name }},
Mir hunn eng Ufro kritt fir Aert Passwuert zreckzesetzen. Klickt op de Knäppchen hei drënner fir en neit Passwuert ze kreéieren:
Dëse Link leeft an {{ expiry_hours }} Stonn(en) of. Wann Dir dës Passwuertzrecksetzung net ugefrot hutt, kënnt Dir dës E-Mail ignoréieren.
Wann de Knäppchen net fonctionnéiert, kopéiert dëse Link an Äre Browser:
{{ reset_link }}
Mat beschte Gréiss,
D'Team
""",
"body_text": """Passwuert zrecksetzen
Moien {{ customer_name }},
Mir hunn eng Ufro kritt fir Aert Passwuert zreckzesetzen. Klickt op de Link hei drënner fir en neit Passwuert ze kreéieren:
{{ reset_link }}
Dëse Link leeft an {{ expiry_hours }} Stonn(en) of. Wann Dir dës Passwuertzrecksetzung net ugefrot hutt, kënnt Dir dës E-Mail ignoréieren.
Mat beschte Gréiss,
D'Team
""",
},
# -------------------------------------------------------------------------
# PLATFORM-ONLY BILLING TEMPLATES
# -------------------------------------------------------------------------
{
"code": "subscription_welcome",
"language": "en",
"name": "Subscription Welcome",
"description": "Sent to stores when they subscribe to a paid plan",
"category": EmailCategory.BILLING.value,
"is_platform_only": True,
"required_variables": json.dumps(["store_name", "tier_name", "billing_cycle", "amount"]),
"variables": json.dumps([
"store_name", "tier_name", "billing_cycle", "amount",
"next_billing_date", "dashboard_url"
]),
"subject": "Welcome to {{ tier_name }} - Subscription Confirmed",
"body_html": """
Subscription Confirmed!
Hi {{ store_name }},
Thank you for subscribing to Orion! Your {{ tier_name }} subscription is now active.
Subscription Details
Plan: {{ tier_name }}
Billing Cycle: {{ billing_cycle }}
Amount: {{ amount }}
Next Billing Date: {{ next_billing_date }}
If you have any questions about your subscription, please contact our support team.
Best regards,
The Orion Team
© 2024 Orion. All rights reserved.
""",
"body_text": """Subscription Confirmed!
Hi {{ store_name }},
Thank you for subscribing to Orion! Your {{ tier_name }} subscription is now active.
Subscription Details:
- Plan: {{ tier_name }}
- Billing Cycle: {{ billing_cycle }}
- Amount: {{ amount }}
- Next Billing Date: {{ next_billing_date }}
Go to Dashboard: {{ dashboard_url }}
If you have any questions about your subscription, please contact our support team.
Best regards,
The Orion Team
""",
},
{
"code": "payment_failed",
"language": "en",
"name": "Payment Failed",
"description": "Sent when a subscription payment fails",
"category": EmailCategory.BILLING.value,
"is_platform_only": True,
"required_variables": json.dumps(["store_name", "tier_name", "amount"]),
"variables": json.dumps([
"store_name", "tier_name", "amount", "retry_date",
"update_payment_url", "support_email"
]),
"subject": "Action Required: Payment Failed for Your Subscription",
"body_html": """
Payment Failed
Hi {{ store_name }},
We were unable to process your payment of {{ amount }} for your {{ tier_name }} subscription.
What happens next?
We'll automatically retry the payment on {{ retry_date }}.
To avoid any service interruption, please update your payment method.
If you need assistance, please contact us at {{ support_email }}.
Best regards,
The Orion Team
""",
"body_text": """Payment Failed
Hi {{ store_name }},
We were unable to process your payment of {{ amount }} for your {{ tier_name }} subscription.
What happens next?
- We'll automatically retry the payment on {{ retry_date }}.
- To avoid any service interruption, please update your payment method.
Update Payment Method: {{ update_payment_url }}
If you need assistance, please contact us at {{ support_email }}.
Best regards,
The Orion Team
""",
},
{
"code": "subscription_cancelled",
"language": "en",
"name": "Subscription Cancelled",
"description": "Sent when a subscription is cancelled",
"category": EmailCategory.BILLING.value,
"is_platform_only": True,
"required_variables": json.dumps(["store_name", "tier_name"]),
"variables": json.dumps([
"store_name", "tier_name", "end_date", "reactivate_url"
]),
"subject": "Your Orion Subscription Has Been Cancelled",
"body_html": """
Subscription Cancelled
Hi {{ store_name }},
Your {{ tier_name }} subscription has been cancelled as requested.
What happens now?
You'll continue to have access to your {{ tier_name }} features until {{ end_date }}.
After that date, your account will be downgraded to the Free tier.
Changed your mind? You can reactivate your subscription at any time:
We're sorry to see you go. If there's anything we could have done better, please let us know.
Best regards,
The Orion Team
""",
"body_text": """Subscription Cancelled
Hi {{ store_name }},
Your {{ tier_name }} subscription has been cancelled as requested.
What happens now?
- You'll continue to have access to your {{ tier_name }} features until {{ end_date }}.
- After that date, your account will be downgraded to the Free tier.
Changed your mind? You can reactivate your subscription at any time:
{{ reactivate_url }}
We're sorry to see you go. If there's anything we could have done better, please let us know.
Best regards,
The Orion Team
""",
},
{
"code": "trial_ending",
"language": "en",
"name": "Trial Ending Soon",
"description": "Sent when a trial is about to end",
"category": EmailCategory.BILLING.value,
"is_platform_only": True,
"required_variables": json.dumps(["store_name", "days_remaining"]),
"variables": json.dumps([
"store_name", "tier_name", "days_remaining", "trial_end_date",
"upgrade_url", "features_list"
]),
"subject": "Your Trial Ends in {{ days_remaining }} Days",
"body_html": """
Your Trial is Ending Soon
Hi {{ store_name }},
Your {{ tier_name }} trial ends in {{ days_remaining }} days ({{ trial_end_date }}).
Don't lose these features:
{{ features_list }}
Subscribe now to continue using all {{ tier_name }} features without interruption:
Have questions? Reply to this email and we'll help you choose the right plan.
Best regards,
The Orion Team
""",
"body_text": """Your Trial is Ending Soon
Hi {{ store_name }},
Your {{ tier_name }} trial ends in {{ days_remaining }} days ({{ trial_end_date }}).
Don't lose these features:
{{ features_list }}
Subscribe now to continue using all {{ tier_name }} features without interruption:
{{ upgrade_url }}
Have questions? Reply to this email and we'll help you choose the right plan.
Best regards,
The Orion Team
""",
},
{
"code": "team_invite",
"language": "en",
"name": "Team Member Invitation",
"description": "Sent when a store invites a team member",
"category": EmailCategory.SYSTEM.value,
"is_platform_only": False,
"required_variables": json.dumps(["invitee_name", "inviter_name", "store_name", "accept_url"]),
"variables": json.dumps([
"invitee_name", "inviter_name", "store_name", "role",
"accept_url", "expires_in_days"
]),
"subject": "{{ inviter_name }} invited you to join {{ store_name }} on Orion",
"body_html": """
You've Been Invited!
Hi {{ invitee_name }},
{{ inviter_name }} has invited you to join {{ store_name }} as a team member on Orion.
Invitation Details
Store: {{ store_name }}
Role: {{ role }}
Invited by: {{ inviter_name }}
This invitation will expire in {{ expires_in_days }} days.
If you weren't expecting this invitation, you can safely ignore this email.
Best regards,
The Orion Team
""",
"body_text": """You've Been Invited!
Hi {{ invitee_name }},
{{ inviter_name }} has invited you to join {{ store_name }} as a team member on Orion.
Invitation Details:
- Store: {{ store_name }}
- Role: {{ role }}
- Invited by: {{ inviter_name }}
Accept Invitation: {{ accept_url }}
This invitation will expire in {{ expires_in_days }} days.
If you weren't expecting this invitation, you can safely ignore this email.
Best regards,
The Orion Team
""",
},
]
def seed_templates():
"""Seed email templates into database."""
db = next(get_db())
try:
created = 0
updated = 0
for template_data in TEMPLATES:
# Set defaults for new fields
template_data.setdefault("is_platform_only", False)
template_data.setdefault("required_variables", None)
# Check if template already exists
existing = (
db.query(EmailTemplate)
.filter(
EmailTemplate.code == template_data["code"],
EmailTemplate.language == template_data["language"],
)
.first()
)
if existing:
# Update existing template
for key, value in template_data.items():
setattr(existing, key, value)
updated += 1
platform_only_tag = " [platform-only]" if template_data.get("is_platform_only") else ""
print(f"Updated: {template_data['code']} ({template_data['language']}){platform_only_tag}")
else:
# Create new template
template = EmailTemplate(**template_data)
db.add(template) # noqa: PERF006
created += 1
platform_only_tag = " [platform-only]" if template_data.get("is_platform_only") else ""
print(f"Created: {template_data['code']} ({template_data['language']}){platform_only_tag}")
db.commit()
print(f"\nDone! Created: {created}, Updated: {updated}")
except Exception as e:
db.rollback()
print(f"Error: {e}")
raise
finally:
db.close()
if __name__ == "__main__":
seed_templates()