Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Gift cards mailing backend
Tomasz Szymanskibc84c7991427
diff --git a/saleor/core/notify_events.py b/saleor/core/notify_events.pyindex 583bfc7c8f..a075327016 100644--- a/saleor/core/notify_events.py+++ b/saleor/core/notify_events.py@@ -13,6 +13,7 @@ class UserNotifyEvent:ORDER_PAYMENT_CONFIRMATION = "order_payment_confirmation"ORDER_CANCELED = "order_canceled"ORDER_REFUND_CONFIRMATION = "order_refund_confirmation"+ SEND_GIFT_CARD = "send_gift_card"CHOICES = [ACCOUNT_CONFIRMATION,@@ -29,6 +30,7 @@ class UserNotifyEvent:ORDER_PAYMENT_CONFIRMATION,ORDER_CANCELED,ORDER_REFUND_CONFIRMATION,+ SEND_GIFT_CARD,]diff --git a/saleor/giftcard/notifications.py b/saleor/giftcard/notifications.pynew file mode 100644index 0000000000..e0eb2ff53c--- /dev/null+++ b/saleor/giftcard/notifications.py@@ -0,0 +1,12 @@+from ..core.notifications import get_site_context+from ..core.notify_events import NotifyEventType+++def send_gift_card_notification(email, gift_card, manager):+ """Trigger sending a gift card notification for the given recipient."""+ payload = {+ "recipient_email": email,+ "code": gift_card.code,+ **get_site_context(),+ }+ manager.notify(NotifyEventType.SEND_GIFT_CARD, payload=payload)diff --git a/saleor/graphql/giftcard/mutations.py b/saleor/graphql/giftcard/mutations.pyindex eb9ca5557f..204e85204e 100644--- a/saleor/graphql/giftcard/mutations.py+++ b/saleor/graphql/giftcard/mutations.py@@ -8,6 +8,7 @@ from ...core.utils.promo_code import generate_promo_codefrom ...core.utils.validators import date_passed, user_is_validfrom ...giftcard import GiftCardExpiryType, events, modelsfrom ...giftcard.error_codes import GiftCardErrorCode+from ...giftcard.notifications import send_gift_card_notificationfrom ...giftcard.utils import activate_gift_card, deactivate_gift_cardfrom ..core.descriptions import ADDED_IN_31, DEPRECATED_IN_3X_INPUTfrom ..core.mutations import BaseMutation, ModelDeleteMutation, ModelMutation@@ -181,12 +182,15 @@ class GiftCardCreate(ModelMutation):cleaned_input["initial_balance_amount"] = amount@classmethod- def post_save_action(cls, info, instance, cleaned_input):+ def post_save_action(cls, info, instance, _cleaned_input):events.gift_card_issued_event(gift_card=instance,user=info.context.user,app=info.context.app,)+ send_gift_card_notification(+ info.context.user.email, instance, info.context.plugins+ )class GiftCardUpdate(GiftCardCreate):diff --git a/saleor/plugins/sendgrid/__init__.py b/saleor/plugins/sendgrid/__init__.pyindex caa317d7f9..aedc69a4f6 100644--- a/saleor/plugins/sendgrid/__init__.py+++ b/saleor/plugins/sendgrid/__init__.py@@ -21,3 +21,4 @@ class SendgridConfiguration:order_payment_confirmation_template_id: Optional[str]order_canceled_template_id: Optional[str]order_refund_confirmation_template_id: Optional[str]+ send_gift_card_template_id: Optional[str]diff --git a/saleor/plugins/sendgrid/plugin.py b/saleor/plugins/sendgrid/plugin.pyindex 2c0036323d..c567b25b25 100644--- a/saleor/plugins/sendgrid/plugin.py+++ b/saleor/plugins/sendgrid/plugin.py@@ -13,6 +13,7 @@ from .tasks import (send_account_delete_confirmation_email_task,send_fulfillment_confirmation_email_task,send_fulfillment_update_email_task,+ send_gift_card_email_task,send_invoice_email_task,send_order_canceled_email_task,send_order_confirmation_email_task,@@ -85,6 +86,10 @@ EVENT_MAP = {send_order_refund_email_task,"order_refund_confirmation_template_id",),+ UserNotifyEvent.SEND_GIFT_CARD: (+ send_gift_card_email_task,+ "send_gift_card_template_id",+ ),}HELP_TEXT_TEMPLATE = "ID of the dynamic template in Sendgrid"@@ -113,6 +118,7 @@ class SendgridEmailPlugin(BasePlugin):{"name": "order_payment_confirmation_template_id", "value": None},{"name": "order_canceled_template_id", "value": None},{"name": "order_refund_confirmation_template_id", "value": None},+ {"name": "send_gift_card_template_id", "value": None},{"name": "api_key", "value": None},]CONFIG_STRUCTURE = {@@ -196,6 +202,11 @@ class SendgridEmailPlugin(BasePlugin):"help_text": HELP_TEXT_TEMPLATE,"label": "Order refund confirmation email template",},+ "send_gift_card_template_id": {+ "type": ConfigurationTypeField.STRING,+ "help_text": HELP_TEXT_TEMPLATE,+ "label": "Send gift card email template",+ },"api_key": {"type": ConfigurationTypeField.SECRET,"help_text": "Your Sendgrid API key.",diff --git a/saleor/plugins/sendgrid/tasks.py b/saleor/plugins/sendgrid/tasks.pyindex db280cb681..9c2e00d979 100644--- a/saleor/plugins/sendgrid/tasks.py+++ b/saleor/plugins/sendgrid/tasks.py@@ -289,6 +289,21 @@ def send_order_refund_email_task(payload: dict, configuration: dict):)+ autoretry_for=(SendGridException,),+ retry_backoff=CELERY_RETRY_BACKOFF,+ retry_kwargs={"max_retries": CELERY_RETRY_MAX},+ compression="zlib",+)+def send_gift_card_email_task(payload: dict, configuration: dict):+ configuration = SendgridConfiguration(**configuration)+ send_email(+ configuration=configuration,+ template_id=configuration.send_gift_card_template_id,+ payload=payload,+ )++@app.task(autoretry_for=(SendGridException,),retry_backoff=CELERY_RETRY_BACKOFF,diff --git a/saleor/plugins/sendgrid/tests/conftest.py b/saleor/plugins/sendgrid/tests/conftest.pyindex 662bc4d89a..81b0f825d5 100644--- a/saleor/plugins/sendgrid/tests/conftest.py+++ b/saleor/plugins/sendgrid/tests/conftest.py@@ -24,6 +24,7 @@ def sendgrid_email_plugin(settings, channel_USD):order_payment_confirmation_template_id=None,order_canceled_template_id=None,order_refund_confirmation_template_id=None,+ send_gift_card_template_id=None,api_key=None,):@@ -93,6 +94,10 @@ def sendgrid_email_plugin(settings, channel_USD):"name": "order_refund_confirmation_template_id","value": order_refund_confirmation_template_id,},+ {+ "name": "send_gift_card_template_id",+ "value": send_gift_card_template_id,+ },{"name": "api_key", "value": api_key},],},diff --git a/saleor/plugins/sendgrid/tests/test_tasks.py b/saleor/plugins/sendgrid/tests/test_tasks.pyindex 01288b2219..a98736f722 100644--- a/saleor/plugins/sendgrid/tests/test_tasks.py+++ b/saleor/plugins/sendgrid/tests/test_tasks.py@@ -20,6 +20,7 @@ from ..tasks import (send_email,send_fulfillment_confirmation_email_task,send_fulfillment_update_email_task,+ send_gift_card_email_task,send_invoice_email_task,send_order_canceled_email_task,send_order_confirmation_email_task,@@ -52,7 +53,7 @@ def test_send_email(mocked_api_client, mocked_mail, sendgrid_email_plugin, sample_payload):plugin = sendgrid_email_plugin(- sender_name="Sander Name",+ sender_name="Sender Name",sender_address="[email protected]",api_key="123",)@@ -125,7 +126,7 @@ def test_send_password_reset_email_task(plugin = sendgrid_email_plugin(api_key="A12",account_password_reset_template_id=template_id,- sender_name="Sander Name",+ sender_name="Sender Name",sender_address="[email protected]",)@@ -162,7 +163,7 @@ def test_send_request_email_change_email_task(plugin = sendgrid_email_plugin(api_key="A12",account_change_email_request_template_id=template_id,- sender_name="Sander Name",+ sender_name="Sender Name",sender_address="[email protected]",)@@ -201,7 +202,7 @@ def test_send_user_change_email_notification_task(plugin = sendgrid_email_plugin(api_key="A12",account_change_email_confirm_template_id=template_id,- sender_name="Sander Name",+ sender_name="Sender Name",sender_address="[email protected]",)@@ -241,7 +242,7 @@ def test_send_account_delete_confirmation_email_task(plugin = sendgrid_email_plugin(api_key="A12",account_delete_template_id=template_id,- sender_name="Sander Name",+ sender_name="Sender Name",sender_address="[email protected]",)@@ -274,7 +275,7 @@ def test_send_set_user_password_email_task(plugin = sendgrid_email_plugin(api_key="A12",account_set_customer_password_template_id=template_id,- sender_name="Sander Name",+ sender_name="Sender Name",sender_address="[email protected]",)@@ -312,7 +313,7 @@ def test_send_invoice_email_task_by_user(plugin = sendgrid_email_plugin(api_key="A12",invoice_ready_template_id=template_id,- sender_name="Sander Name",+ sender_name="Sender Name",sender_address="[email protected]",)@@ -359,7 +360,7 @@ def test_send_invoice_email_task_by_app(plugin = sendgrid_email_plugin(api_key="A12",invoice_ready_template_id=template_id,- sender_name="Sander Name",+ sender_name="Sender Name",sender_address="[email protected]",)@@ -398,7 +399,7 @@ def test_send_order_confirmation_email_task(plugin = sendgrid_email_plugin(api_key="A12",order_confirmation_template_id=template_id,- sender_name="Sander Name",+ sender_name="Sender Name",sender_address="[email protected]",)@@ -431,7 +432,7 @@ def test_send_fulfillment_confirmation_email_task_by_user(plugin = sendgrid_email_plugin(api_key="A12",order_fulfillment_confirmation_template_id=template_id,- sender_name="Sander Name",+ sender_name="Sender Name",sender_address="[email protected]",)@@ -466,7 +467,7 @@ def test_send_fulfillment_confirmation_email_task_by_app(plugin = sendgrid_email_plugin(api_key="A12",order_fulfillment_confirmation_template_id=template_id,- sender_name="Sander Name",+ sender_name="Sender Name",sender_address="[email protected]",)@@ -499,7 +500,7 @@ def test_send_fulfillment_update_email_task(plugin = sendgrid_email_plugin(api_key="A12",order_fulfillment_update_template_id=template_id,- sender_name="Sander Name",+ sender_name="Sender Name",sender_address="[email protected]",)@@ -537,7 +538,7 @@ def test_send_payment_confirmation_email_task(plugin = sendgrid_email_plugin(api_key="A12",order_payment_confirmation_template_id=template_id,- sender_name="Sander Name",+ sender_name="Sender Name",sender_address="[email protected]",)@@ -576,7 +577,7 @@ def test_send_order_canceled_email_task_by_user(plugin = sendgrid_email_plugin(api_key="A12",order_canceled_template_id=template_id,- sender_name="Sander Name",+ sender_name="Sender Name",sender_address="[email protected]",)@@ -617,7 +618,7 @@ def test_send_order_canceled_email_task_by_app(plugin = sendgrid_email_plugin(api_key="A12",order_canceled_template_id=template_id,- sender_name="Sander Name",+ sender_name="Sender Name",sender_address="[email protected]",)@@ -660,7 +661,7 @@ def test_send_order_refund_email_task_by_user(plugin = sendgrid_email_plugin(api_key="A12",order_refund_confirmation_template_id=template_id,- sender_name="Sander Name",+ sender_name="Sender Name",sender_address="[email protected]",)@@ -703,7 +704,7 @@ def test_send_order_refund_email_task_by_app(plugin = sendgrid_email_plugin(api_key="A12",order_refund_confirmation_template_id=template_id,- sender_name="Sander Name",+ sender_name="Sender Name",sender_address="[email protected]",)@@ -725,6 +726,70 @@ def test_send_order_refund_email_task_by_app(assert order_event.app == app+@patch("saleor.plugins.sendgrid.tasks.send_email")+def test_send_gift_card_email_task_by_user(+ mocked_send_email, staff_user, order, sendgrid_email_plugin+):+ template_id = "ABC1"++ recipient_email = "[email protected]"+ payload = {+ "order": get_default_order_payload(order, "http://localhost:8000/redirect"),+ "recipient_email": recipient_email,+ "site_name": "Saleor",+ "domain": "localhost:8000",+ "requester_user_id": staff_user.pk,+ "requester_app_id": None,+ }++ plugin = sendgrid_email_plugin(+ api_key="A12",+ send_gift_card_template_id=template_id,+ sender_name="Sender Name",+ sender_address="[email protected]",+ )++ send_gift_card_email_task(payload, asdict(plugin.config))++ mocked_send_email.assert_called_with(+ configuration=plugin.config,+ template_id=template_id,+ payload=payload,+ )+++@patch("saleor.plugins.sendgrid.tasks.send_email")+def test_send_gift_card_email_task_by_app(+ mocked_send_email, app, order, sendgrid_email_plugin+):+ template_id = "ABC1"++ recipient_email = "[email protected]"+ payload = {+ "order": get_default_order_payload(order, "http://localhost:8000/redirect"),+ "recipient_email": recipient_email,+ "site_name": "Saleor",+ "domain": "localhost:8000",+ "requester_user_id": None,+ "requester_app_id": app.pk,+ }++ plugin = sendgrid_email_plugin(+ api_key="A12",+ send_gift_card_template_id=template_id,+ sender_name="Sender Name",+ sender_address="[email protected]",+ )++ send_gift_card_email_task(payload, asdict(plugin.config))++ mocked_send_email.assert_called_with(+ configuration=plugin.config,+ template_id=template_id,+ payload=payload,+ )++@patch("saleor.plugins.sendgrid.tasks.send_email")def test_send_order_confirmed_email_task_by_user(mocked_send_email, staff_user, order, sendgrid_email_plugin@@ -746,7 +811,7 @@ def test_send_order_confirmed_email_task_by_user(plugin = sendgrid_email_plugin(api_key="A12",order_confirmed_template_id=template_id,- sender_name="Sander Name",+ sender_name="Sender Name",sender_address="[email protected]",)@@ -789,7 +854,7 @@ def test_send_order_confirmed_email_task_by_app(plugin = sendgrid_email_plugin(api_key="A12",order_confirmed_template_id=template_id,- sender_name="Sander Name",+ sender_name="Sender Name",sender_address="[email protected]",)diff --git a/saleor/plugins/user_email/constants.py b/saleor/plugins/user_email/constants.pyindex 9c9b881d70..dfb5f454e4 100644--- a/saleor/plugins/user_email/constants.py+++ b/saleor/plugins/user_email/constants.py@@ -23,6 +23,7 @@ ORDER_FULFILLMENT_UPDATE_TEMPLATE_FIELD = "order_fulfillment_update"ORDER_PAYMENT_CONFIRMATION_TEMPLATE_FIELD = "order_payment_confirmation"ORDER_CANCELED_TEMPLATE_FIELD = "order_canceled"ORDER_REFUND_CONFIRMATION_TEMPLATE_FIELD = "order_refund_confirmation"+SEND_GIFT_CARD_TEMPLATE_FIELD = "send_gift_card"TEMPLATE_FIELDS = [ACCOUNT_CONFIRMATION_TEMPLATE_FIELD,@@ -39,6 +40,7 @@ TEMPLATE_FIELDS = [ORDER_PAYMENT_CONFIRMATION_TEMPLATE_FIELD,ORDER_CANCELED_TEMPLATE_FIELD,ORDER_REFUND_CONFIRMATION_TEMPLATE_FIELD,+ SEND_GIFT_CARD_TEMPLATE_FIELD,]ACCOUNT_CONFIRMATION_DEFAULT_TEMPLATE = "confirm.html"@@ -55,6 +57,7 @@ ORDER_FULFILLMENT_UPDATE_DEFAULT_TEMPLATE = "update_fulfillment.html"ORDER_PAYMENT_CONFIRMATION_DEFAULT_TEMPLATE = "confirm_payment.html"ORDER_CANCELED_DEFAULT_TEMPLATE = "order_cancel.html"ORDER_REFUND_CONFIRMATION_DEFAULT_TEMPLATE = "order_refund.html"+SEND_GIFT_CARD_DEFAULT_TEMPLATE = "gift_card.html"ACCOUNT_CONFIRMATION_SUBJECT_FIELD = "account_confirmation_subject"@@ -71,6 +74,7 @@ ORDER_FULFILLMENT_UPDATE_SUBJECT_FIELD = "order_fulfillment_update_subject"ORDER_PAYMENT_CONFIRMATION_SUBJECT_FIELD = "order_payment_confirmation_subject"ORDER_CANCELED_SUBJECT_FIELD = "order_canceled_subject"ORDER_REFUND_CONFIRMATION_SUBJECT_FIELD = "order_refund_confirmation_subject"+SEND_GIFT_CARD_SUBJECT_FIELD = "send_gift_card_subject"ACCOUNT_CONFIRMATION_DEFAULT_SUBJECT = "Account confirmation e-mail"@@ -89,3 +93,4 @@ ORDER_FULFILLMENT_UPDATE_DEFAULT_SUBJECT = "Shipping update for order {{ order.iORDER_PAYMENT_CONFIRMATION_DEFAULT_SUBJECT = "Order {{ order.id }} payment details"ORDER_CANCELED_DEFAULT_SUBJECT = "Order {{ order.id }} canceled"ORDER_REFUND_CONFIRMATION_DEFAULT_SUBJECT = "Order {{ order.id }} refunded"+SEND_GIFT_CARD_DEFAULT_SUBJECT = "Gift card for {{ site_name }}"diff --git a/saleor/plugins/user_email/default_email_templates/gift_card.html b/saleor/plugins/user_email/default_email_templates/gift_card.htmlnew file mode 100644index 0000000000..2b5645f821--- /dev/null+++ b/saleor/plugins/user_email/default_email_templates/gift_card.html@@ -0,0 +1,291 @@+<!doctype html>+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml"+ xmlns:o="urn:schemas-microsoft-com:office:office">++<head>+ <title>++ </title>+ <!--[if !mso]><!-->+ <meta http-equiv="X-UA-Compatible" content="IE=edge">+ <!--<![endif]-->+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">+ <meta name="viewport" content="width=device-width, initial-scale=1">+ <style type="text/css">+ #outlook a {+ padding: 0;+ }++ body {+ margin: 0;+ padding: 0;+ -webkit-text-size-adjust: 100%;+ -ms-text-size-adjust: 100%;+ }++ table,+ td {+ border-collapse: collapse;+ mso-table-lspace: 0pt;+ mso-table-rspace: 0pt;+ }++ img {+ border: 0;+ height: auto;+ line-height: 100%;+ outline: none;+ text-decoration: none;+ -ms-interpolation-mode: bicubic;+ }++ p {+ display: block;+ margin: 13px 0;+ }+ </style>+ <!--[if mso]>+ <xml>+ <o:OfficeDocumentSettings>+ <o:AllowPNG/>+ <o:PixelsPerInch>96</o:PixelsPerInch>+ </o:OfficeDocumentSettings>+ </xml>+ <![endif]-->+ <!--[if lte mso 11]>+ <style type="text/css">+ .mj-outlook-group-fix { width:100% !important; }+ </style>+ <![endif]-->++ <!--[if !mso]><!-->+ <link href="https://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700" rel="stylesheet" type="text/css">+ <style type="text/css">+ @import url(https://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700);+ </style>+ <!--<![endif]-->++++ <style type="text/css">+ @media only screen and (min-width:480px) {+ .mj-column-per-100 {+ width: 100% !important;+ max-width: 100%;+ }+ }+ </style>+++ <style type="text/css">+++ </style>+ <style type="text/css">+ address {+ font-style: inherit;+ font-family: Ubuntu, Helvetica, Arial;+ }+ </style>++</head>++<body style="word-spacing:normal;">+++ <div style>+++ <!--[if mso | IE]><table align="center" border="0" cellpadding="0" cellspacing="0" class="" style="width:600px;" width="600" ><tr><td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;"><![endif]-->+++ <div style="margin:0px auto;max-width:600px;">++ <table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="width:100%;">+ <tbody>+ <tr>+ <td style="direction: ltr; font-size: 0px; padding: 20px 0; text-align: center;" align="center">+ <!--[if mso | IE]><table role="presentation" border="0" cellpadding="0" cellspacing="0"><tr><td class="" style="vertical-align:top;width:600px;" ><![endif]-->++ <div class="mj-column-per-100 mj-outlook-group-fix"+ style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%;">++ <table border="0" cellpadding="0" cellspacing="0" role="presentation" style="vertical-align:top;"+ width="100%">+ <tbody>++ <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:16px;line-height:1;text-align:left;color:#000000;">+ Hi!</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;">+ You have received new gift card in {{ site_name }}!+ The gift card code is: {{ code }}</div>++ </td>+ </tr>++ </tbody>+ </table>++ </div>++ <!--[if mso | IE]></td></tr></table><![endif]-->+ </td>+ </tr>+ </tbody>+ </table>++ </div>+++ <!--[if mso | IE]></td></tr></table><table align="center" border="0" cellpadding="0" cellspacing="0" class="" style="width:600px;" width="600" ><tr><td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;"><![endif]-->+++ <div style="margin:0px auto;max-width:600px;">++ <table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="width:100%;">+ <tbody>+ <tr>+ <td style="direction: ltr; font-size: 0px; padding: 20px 0; text-align: center;" align="center">+ <!--[if mso | IE]><table role="presentation" border="0" cellpadding="0" cellspacing="0"><tr><td class="" style="vertical-align:top;width:600px;" ><![endif]-->++ <div class="mj-column-per-100 mj-outlook-group-fix"+ style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%;">++ <table border="0" cellpadding="0" cellspacing="0" role="presentation" style="vertical-align:top;"+ width="100%">+ <tbody>++ <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;">+ This is an automatically generated e-mail, please do not reply.</div>++ </td>+ </tr>++ </tbody>+ </table>++ </div>++ <!--[if mso | IE]></td></tr></table><![endif]-->+ </td>+ </tr>+ </tbody>+ </table>++ </div>+++ <!--[if mso | IE]></td></tr></table><table align="center" border="0" cellpadding="0" cellspacing="0" class="" style="width:600px;" width="600" ><tr><td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;"><![endif]-->+++ <div style="background:#F2F2F2;background-color:#F2F2F2;margin:0px auto;max-width:600px;">++ <table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation"+ style="background:#F2F2F2;background-color:#F2F2F2;width:100%;">+ <tbody>+ <tr>+ <td style="direction: ltr; font-size: 0px; padding: 20px 0; text-align: center;" align="center">+ <!--[if mso | IE]><table role="presentation" border="0" cellpadding="0" cellspacing="0"><tr><td class="" style="vertical-align:top;width:600px;" ><![endif]-->++ <div class="mj-column-per-100 mj-outlook-group-fix"+ style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%;">++ <table border="0" cellpadding="0" cellspacing="0" role="presentation" style="vertical-align:top;"+ width="100%">+ <tbody>++ <tr>+ <td align="center" 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:center;color:#000000;">+ Sincerely, {{ site_name }}</div>++ </td>+ </tr>++ </tbody>+ </table>++ </div>++ <!--[if mso | IE]></td></tr></table><![endif]-->+ </td>+ </tr>+ </tbody>+ </table>++ </div>+++ <!--[if mso | IE]></td></tr></table><table align="center" border="0" cellpadding="0" cellspacing="0" class="no-display-outlook" style="width:600px;" width="600" ><tr><td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;"><![endif]-->+++ <div class="no-display" style="display: none; margin: 0px auto; max-width: 600px;">++ <table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="width:100%;">+ <tbody>+ <tr>+ <td style="direction: ltr; font-size: 0px; padding: 20px 0; text-align: center;" align="center">+ <!--[if mso | IE]><table role="presentation" border="0" cellpadding="0" cellspacing="0"><tr><td class="" style="vertical-align:top;width:600px;" ><![endif]-->++ <div class="mj-column-per-100 mj-outlook-group-fix"+ style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%;">++ <table border="0" cellpadding="0" cellspacing="0" role="presentation" style="vertical-align:top;"+ width="100%">+ <tbody>++ <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;">+ {{#if order}}+ <script type="application/ld+json">+ {{{{raw}}}}{{schema_markup}}{{{{/raw}}}}+ </script>+ {{/if}}+ </div>++ </td>+ </tr>++ </tbody>+ </table>++ </div>++ <!--[if mso | IE]></td></tr></table><![endif]-->+ </td>+ </tr>+ </tbody>+ </table>++ </div>+++ <!--[if mso | IE]></td></tr></table><![endif]-->+++ </div>++</body>++</html>diff --git a/saleor/plugins/user_email/notify_events.py b/saleor/plugins/user_email/notify_events.pyindex 73b47b690f..2593860fc4 100644--- a/saleor/plugins/user_email/notify_events.py+++ b/saleor/plugins/user_email/notify_events.py@@ -5,6 +5,7 @@ from .tasks import (send_account_delete_confirmation_email_task,send_fulfillment_confirmation_email_task,send_fulfillment_update_email_task,+ send_gift_card_email_task,send_invoice_email_task,send_order_canceled_email_task,send_order_confirmation_email_task,@@ -118,6 +119,23 @@ def send_account_delete(payload: dict, config: dict, plugin_configuration: list))+def send_gift_card(payload: dict, config: dict, plugin_configuration: list):+ recipient_email = payload["recipient_email"]+ template = get_email_template_or_default(+ plugin_configuration,+ constants.SEND_GIFT_CARD_TEMPLATE_FIELD,+ constants.SEND_GIFT_CARD_DEFAULT_TEMPLATE,+ constants.DEFAULT_EMAIL_TEMPLATES_PATH,+ )++ subject = get_email_subject(+ plugin_configuration,+ constants.SEND_GIFT_CARD_SUBJECT_FIELD,+ constants.SEND_GIFT_CARD_DEFAULT_SUBJECT,+ )+ send_gift_card_email_task.delay(recipient_email, payload, config, subject, template)++def send_account_set_customer_password(payload: dict, config: dict, plugin_configuration: list):diff --git a/saleor/plugins/user_email/plugin.py b/saleor/plugins/user_email/plugin.pyindex 53a305f776..963bac8299 100644--- a/saleor/plugins/user_email/plugin.py+++ b/saleor/plugins/user_email/plugin.py@@ -26,6 +26,7 @@ from .notify_events import (send_account_set_customer_password,send_fulfillment_confirmation,send_fulfillment_update,+ send_gift_card,send_invoice,send_order_canceled,send_order_confirmation,@@ -53,6 +54,7 @@ class UserTemplate:order_payment_confirmation: Optional[str]order_canceled: Optional[str]order_refund_confirmation: Optional[str]+ send_gift_card: Optional[str]def get_user_template_map(templates: UserTemplate):@@ -81,6 +83,7 @@ def get_user_template_map(templates: UserTemplate):),UserNotifyEvent.ORDER_CANCELED: templates.order_canceled,UserNotifyEvent.ORDER_REFUND_CONFIRMATION: templates.order_refund_confirmation,+ UserNotifyEvent.SEND_GIFT_CARD: templates.send_gift_card,}@@ -102,6 +105,7 @@ def get_user_event_map():UserNotifyEvent.ORDER_PAYMENT_CONFIRMATION: send_payment_confirmation,UserNotifyEvent.ORDER_CANCELED: send_order_canceled,UserNotifyEvent.ORDER_REFUND_CONFIRMATION: send_order_refund,+ UserNotifyEvent.SEND_GIFT_CARD: send_gift_card,}@@ -214,6 +218,14 @@ class UserEmailPlugin(BasePlugin):"name": constants.ORDER_REFUND_CONFIRMATION_TEMPLATE_FIELD,"value": DEFAULT_EMAIL_VALUE,},+ {+ "name": constants.SEND_GIFT_CARD_SUBJECT_FIELD,+ "value": constants.SEND_GIFT_CARD_DEFAULT_SUBJECT,+ },+ {+ "name": constants.SEND_GIFT_CARD_TEMPLATE_FIELD,+ "value": DEFAULT_EMAIL_VALUE,+ },] + DEFAULT_EMAIL_CONFIGURATION # type: ignoreCONFIG_STRUCTURE = {@@ -357,6 +369,16 @@ class UserEmailPlugin(BasePlugin):"help_text": DEFAULT_TEMPLATE_HELP_TEXT,"label": "Order refund - template",},+ constants.SEND_GIFT_CARD_SUBJECT_FIELD: {+ "type": ConfigurationTypeField.MULTILINE,+ "help_text": DEFAULT_TEMPLATE_HELP_TEXT,+ "label": "Send gift card - subject",+ },+ constants.SEND_GIFT_CARD_TEMPLATE_FIELD: {+ "type": ConfigurationTypeField.MULTILINE,+ "help_text": DEFAULT_TEMPLATE_HELP_TEXT,+ "label": "Send gift card - template",+ },}CONFIG_STRUCTURE.update(DEFAULT_EMAIL_CONFIG_STRUCTURE)@@ -408,6 +430,7 @@ class UserEmailPlugin(BasePlugin):order_refund_confirmation=configuration[constants.ORDER_REFUND_CONFIRMATION_TEMPLATE_FIELD],+ send_gift_card=configuration[constants.SEND_GIFT_CARD_TEMPLATE_FIELD],)def notify(self, event: NotifyEventType, payload: dict, previous_value):diff --git a/saleor/plugins/user_email/tasks.py b/saleor/plugins/user_email/tasks.pyindex e8d0927ec6..b467f6af1b 100644--- a/saleor/plugins/user_email/tasks.py+++ b/saleor/plugins/user_email/tasks.py@@ -112,6 +112,19 @@ def send_set_user_password_email_task()[email protected](compression="zlib")+def send_gift_card_email_task(recipient_email, payload, config, subject, template):+ email_config = EmailConfig(**config)++ send_email(+ config=email_config,+ recipient_list=[recipient_email],+ context=payload,+ subject=subject,+ template_str=template,+ )++@app.task(compression="zlib")def send_invoice_email_task(recipient_email, payload, config, subject, template):"""Send an invoice to user of related order with URL to download it."""diff --git a/saleor/plugins/user_email/tests/test_plugin.py b/saleor/plugins/user_email/tests/test_plugin.pyindex 36dbc4b1b2..2f77afb5b6 100644--- a/saleor/plugins/user_email/tests/test_plugin.py+++ b/saleor/plugins/user_email/tests/test_plugin.py@@ -21,6 +21,7 @@ from ..notify_events import (send_account_set_customer_password,send_fulfillment_confirmation,send_fulfillment_update,+ send_gift_card,send_invoice,send_order_canceled,send_order_confirmation,@@ -49,6 +50,7 @@ def test_event_map():NotifyEventType.ORDER_CANCELED: send_order_canceled,NotifyEventType.ORDER_REFUND_CONFIRMATION: send_order_refund,NotifyEventType.ORDER_CONFIRMED: send_order_confirmed,+ NotifyEventType.SEND_GIFT_CARD: send_gift_card,}