Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Gift cards - email context with more data

Tomasz Szymanskie0e4bfec5e74
diff --git a/saleor/giftcard/notifications.py b/saleor/giftcard/notifications.py
index 707c2b4064..b607b25947 100644
--- a/saleor/giftcard/notifications.py
+++ b/saleor/giftcard/notifications.py
@@ -1,18 +1,31 @@
+from ..account.models import User
from ..core.notifications import get_site_context
from ..core.notify_events import NotifyEventType
+def _get_recipient_name(email):
+ if user := User.objects.filter(email=email).first():
+ return user.get_full_name()
+ return email
+
+
def send_gift_card_notification(user, app, email, gift_card, manager):
"""Trigger sending a gift card notification for the given recipient."""
payload = {
"requester": {
- "user_id": user.id if user else None,
"email": user.email if user else None,
- "app_id": app.id if app else None,
"app_name": app.name if app else None,
},
- "recipient_email": email,
- "gift_card": {"id": gift_card.id, "code": gift_card.code},
+ "recipient": {
+ "email": email,
+ "name": _get_recipient_name(email),
+ },
+ "gift_card": {
+ "id": gift_card.id,
+ "code": gift_card.code,
+ "balance": gift_card.current_balance_amount,
+ "currency": gift_card.currency,
+ },
**get_site_context(),
}
manager.notify(NotifyEventType.SEND_GIFT_CARD, payload=payload)
diff --git a/saleor/plugins/sendgrid/tests/test_tasks.py b/saleor/plugins/sendgrid/tests/test_tasks.py
index 42565075d7..0c618600d4 100644
--- a/saleor/plugins/sendgrid/tests/test_tasks.py
+++ b/saleor/plugins/sendgrid/tests/test_tasks.py
@@ -733,17 +733,24 @@ def test_send_gift_card_email_task_by_user(
mocked_send_email, staff_user, gift_card, sendgrid_email_plugin
):
template_id = "ABC1"
-
recipient_email = "[email protected]"
+ recipient_name = "John Doe"
+
payload = {
"requester": {
- "user_id": staff_user.pk,
"email": staff_user.email,
- "app_id": None,
"app_name": None,
},
- "recipient_email": recipient_email,
- "gift_card": {"id": gift_card.id, "code": gift_card.code},
+ "recipient": {
+ "email": recipient_email,
+ "name": recipient_name,
+ },
+ "gift_card": {
+ "id": gift_card.id,
+ "code": gift_card.code,
+ "balance": gift_card.current_balance_amount,
+ "currency": gift_card.currency,
+ },
}
plugin = sendgrid_email_plugin(
diff --git a/saleor/plugins/user_email/default_email_templates/gift_card.html b/saleor/plugins/user_email/default_email_templates/gift_card.html
index 236b709c71..c3af159eb9 100644
--- a/saleor/plugins/user_email/default_email_templates/gift_card.html
+++ b/saleor/plugins/user_email/default_email_templates/gift_card.html
@@ -119,7 +119,8 @@
<div
style="font-family:Ubuntu, Helvetica, Arial, sans-serif;font-size:16px;line-height:1;text-align:left;color:#000000;">
- Hi!</div>
+ Hi, {{ recipient.name }}
+ Here is your gift card!</div>
</td>
</tr>
@@ -129,8 +130,31 @@
<div
style="font-family:Ubuntu, Helvetica, Arial, sans-serif;font-size:13px;line-height:1;text-align:left;color:#000000;">
- You have received new gift card in {{ site_name }}!
- The gift card code is: {{ gift_card.code }}</div>
+ {{ gift_card.currency }} {{ gift_card.balance }}
+ Gift card code: {{ gift_card.code }}</div>
+
+ </td>
+ </tr>
+
+ <tr>
+ <td align="left" style="font-size: 0px; padding: 10px 25px; word-break: break-word;">
+
+ <div
+ style="font-family:Ubuntu, Helvetica, Arial, sans-serif;font-size:13px;line-height:1;text-align:left;color:#000000;">
+ Use this card as payment for anything you like in {{ site_name }}.
+ Enter the gift card code at checkout to redeem your gift card.</div>
+
+ </td>
+ </tr>
+
+ <tr>
+ <td align="left" style="font-size: 0px; padding: 10px 25px; word-break: break-word;">
+
+ <div
+ style="font-family:Ubuntu, Helvetica, Arial, sans-serif;font-size:13px;line-height:1;text-align:left;color:#000000;">
+ <a href="{{ domain }}">
+ {{ site_name }}
+ </a></div>
</td>
</tr>