Skip to content

fix: Custom email template for Attendees incorrectly routes back to Order (fix by preserving correct cta.url_token on update) πŸ€– #1189

Open
mrjbj wants to merge 1 commit into
HiEventsDev:developfrom
mrjbj:feature/email-template-cta-url-token-fix
Open

fix: Custom email template for Attendees incorrectly routes back to Order (fix by preserving correct cta.url_token on update) πŸ€– #1189
mrjbj wants to merge 1 commit into
HiEventsDev:developfrom
mrjbj:feature/email-template-cta-url-token-fix

Conversation

@mrjbj
Copy link
Copy Markdown
Contributor

@mrjbj mrjbj commented May 9, 2026

What changes I've made

File: backend/app/Services/Application/Handlers/EmailTemplate/UpdateEmailTemplateHandler.php
Change: New resolveCta() derives url_token from existing template's type via EmailTemplateService::getDefaultTemplate()
────────────────────────────────────────
File: backend/app/Http/Actions/EmailTemplates/UpdateEventEmailTemplateAction.php
Change: Pass only label in CTA; handler is authoritative
────────────────────────────────────────
File: backend/app/Http/Actions/EmailTemplates/UpdateOrganizerEmailTemplateAction.php
Change: Same
────────────────────────────────────────
File: backend/app/Console/Commands/RepairEmailTemplateCtaCommand.php
Change: New email-templates:repair-cta-url-token artisan command (--dry-run supported)
────────────────────────────────────────
File: backend/tests/Unit/Services/Application/Handlers/EmailTemplate/UpdateEmailTemplateHandlerTest.php
Change: 3 new unit tests

Why I've made these changes

When user modifies the custom email template for Attendees, the "View Ticket" call-to-action button gets clobbered and routes to order summary page instead of view-ticket. Code was commented out for some reason, perhaps intentional? I changed it in my instance and now "View Ticket" correctly routes to "view ticket" page in presence of custom attendee email template.

State Before

# The comment never became code. The frontend (EmailTemplateEditor.tsx) only collects the label, so there was no client-  side override either β€” every update silently rewrote url_token to order.url regardless of template type.

$cta = [
    'label' => $validated['ctaLabel'],
    'url_token' => 'order.url', // This will be determined by template type during update
];

Β Β Β Β 

Notes

Β * This was discovered on a production instance where every attendee_ticket template's "View Ticket" button silently routed to the order summary page. After deploying this fix, the bug stops on first save; existing corrupted rows can either (a) be re-saved in the UI or (b) batched via the new artisan command.
Β 

How I've tested these changes

  • php artisan test --filter=UpdateEmailTemplateHandlerTest β€” 3 passed
  • php artisan test --testsuite=Unit --filter='EmailTemplate' β€” 9 passed
  • php artisan email-templates:repair-cta-url-token --dry-run runs cleanly on a fresh dev DB
  • On a deployment with corrupted rows: re-saving an attendee_ticket template via the admin UI restores its CTA to point at the ticket page (no SQL needed).
  • Open a new attendee email; confirm the "View Ticket" CTA URL matches /product/{eventId}/{attendeeShortId}.

Checklist

  • [x ] I have read the contributing guidelines.
  • My code follows the coding standards of the project.
  • I have tested my changes, and they work as expected.
  • I understand that this PR will be closed if I do not follow the contributor guidelines and if this PR template is left unedited.

UpdateEventEmailTemplateAction and UpdateOrganizerEmailTemplateAction
hardcoded cta.url_token to 'order.url' on every update, with a TODO
comment promising to derive it from template type that was never
implemented. Result: any save of an attendee_ticket template overwrote
its CTA target so the "View Ticket" button took recipients to the order
summary page instead of the ticket page.

Move the resolution into UpdateEmailTemplateHandler, which already
fetches the existing row, and derive url_token from
EmailTemplateService::getDefaultTemplate() based on the row's stored
template_type. The actions now pass only the user-supplied label.

Adds an artisan command (email-templates:repair-cta-url-token) to
rewrite already-corrupted rows in place, plus unit tests covering the
attendee_ticket and order_confirmation paths.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant