auto create shopify discount code and moved to secrets
parent
fb16516ddb
commit
049084f705
|
@ -15,11 +15,6 @@
|
||||||
"type": "text",
|
"type": "text",
|
||||||
"displayName": "E-Mail vom Kunden"
|
"displayName": "E-Mail vom Kunden"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"parameterName": "voucher_code",
|
|
||||||
"type": "text",
|
|
||||||
"displayName": "Gutscheincode für den Kunden (in Shopify erstellen)"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"parameterName": "voucher_type",
|
"parameterName": "voucher_type",
|
||||||
"type": "select",
|
"type": "select",
|
||||||
|
|
|
@ -16,35 +16,26 @@ STATIC_PATH = "../../groupsData/shx-order-voucher-code-activated/"
|
||||||
|
|
||||||
json_object = json.loads(sys.argv[1])
|
json_object = json.loads(sys.argv[1])
|
||||||
customer_email = json_object["customer_email"]
|
customer_email = json_object["customer_email"]
|
||||||
voucher_code = json_object["voucher_code"]
|
|
||||||
voucher_type = json_object["voucher_type"]
|
voucher_type = json_object["voucher_type"]
|
||||||
|
|
||||||
if (customer_email is None
|
if customer_email is None or voucher_type is None:
|
||||||
or voucher_code is None
|
|
||||||
or voucher_type is None):
|
|
||||||
print("Missing required parameters")
|
print("Missing required parameters")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
customer_email = customer_email["value"]
|
customer_email = customer_email["value"]
|
||||||
voucher_code = voucher_code["value"]
|
|
||||||
voucher_type = voucher_type["value"]
|
voucher_type = voucher_type["value"]
|
||||||
|
|
||||||
def load_email_config(filename):
|
secrets = utils.get_secrets()["email"]
|
||||||
with open(filename, "r") as f:
|
|
||||||
config = yaml.safe_load(f)
|
|
||||||
return config["email"], config["smtp"]
|
|
||||||
|
|
||||||
email_config, smtp_config = load_email_config(f"{STATIC_PATH}config.yml")
|
|
||||||
|
|
||||||
# extract the email parameters
|
# extract the email parameters
|
||||||
auth_email = email_config["auth_email"]
|
auth_email = secrets["auth_email"]
|
||||||
from_email_name = email_config["from_email_name"]
|
from_email_name = secrets["from_email_name"]
|
||||||
from_email = email_config["from_email"]
|
from_email = secrets["from_email"]
|
||||||
password = email_config["password"]
|
password = secrets["password"]
|
||||||
|
|
||||||
# extract the smtp parameters
|
# extract the smtp parameters
|
||||||
smtp_server = smtp_config["server"]
|
smtp_server = secrets["smtp_server"]
|
||||||
smtp_port = smtp_config["port"]
|
smtp_port = secrets["smtp_port"]
|
||||||
|
|
||||||
receiver_email = customer_email
|
receiver_email = customer_email
|
||||||
|
|
||||||
|
@ -66,16 +57,24 @@ with open(f"{STATIC_PATH}email.html", "r") as file:
|
||||||
if voucher_type == "5 €":
|
if voucher_type == "5 €":
|
||||||
message = "Wir möchten uns herzlich bei dir bedanken, dass du dir die Zeit genommen hast, uns zu bewerten. Deine Meinung ist uns sehr wichtig und hilft uns, unseren Service stetig zu verbessern."
|
message = "Wir möchten uns herzlich bei dir bedanken, dass du dir die Zeit genommen hast, uns zu bewerten. Deine Meinung ist uns sehr wichtig und hilft uns, unseren Service stetig zu verbessern."
|
||||||
price = "5"
|
price = "5"
|
||||||
|
|
||||||
|
discount_code = utils.create_shopify_discount_code("order_voucher_5_euro")
|
||||||
else:
|
else:
|
||||||
message = "Wir möchten uns herzlich bei dir bedanken, dass du dir die Zeit genommen hast, einen Beitrag über uns auf Social Media zu erstellen."
|
message = "Wir möchten uns herzlich bei dir bedanken, dass du dir die Zeit genommen hast, einen Beitrag über uns auf Social Media zu erstellen."
|
||||||
price = "10"
|
price = "10"
|
||||||
|
|
||||||
|
discount_code = utils.create_shopify_discount_code("order_voucher_10_euro")
|
||||||
|
|
||||||
|
if discount_code == "":
|
||||||
|
sys.exit("Discount code is empty")
|
||||||
|
|
||||||
html = html.replace("{{PRICE}}", price)
|
html = html.replace("{{PRICE}}", price)
|
||||||
html = html.replace("{{MESSAGE}}", message)
|
html = html.replace("{{MESSAGE}}", message)
|
||||||
html = html.replace("{{VOUCHER_CODE}}", voucher_code)
|
html = html.replace("{{DISCOUNT_CODE}}", discount_code)
|
||||||
|
|
||||||
|
text = text.replace("{{PRICE}}", price)
|
||||||
text = text.replace("{{MESSAGE}}", message)
|
text = text.replace("{{MESSAGE}}", message)
|
||||||
text = text.replace("{{VOUCHER_CODE}}", voucher_code)
|
text = text.replace("{{DISCOUNT_CODE}}", discount_code)
|
||||||
|
|
||||||
# add text and html part to the email
|
# add text and html part to the email
|
||||||
part1 = MIMEText(text, "plain", "utf-8")
|
part1 = MIMEText(text, "plain", "utf-8")
|
||||||
|
@ -91,7 +90,7 @@ try:
|
||||||
server.login(auth_email, password)
|
server.login(auth_email, password)
|
||||||
server.sendmail(from_email, receiver_email, msg.as_string())
|
server.sendmail(from_email, receiver_email, msg.as_string())
|
||||||
|
|
||||||
print(f"Email sent to {receiver_email} with voucher code {voucher_code} of type {voucher_type}")
|
print(f"Email sent to {receiver_email} with voucher code {discount_code} of type {voucher_type}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error sending email: {e}")
|
print(f"Error sending email: {e}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
|
@ -151,7 +151,7 @@
|
||||||
"
|
"
|
||||||
>
|
>
|
||||||
Dein Gutscheincode lautet:
|
Dein Gutscheincode lautet:
|
||||||
<strong>{{VOUCHER_CODE}}</strong>
|
<strong>{{DISCOUNT_CODE}}</strong>
|
||||||
</p>
|
</p>
|
||||||
<table
|
<table
|
||||||
class="row actions"
|
class="row actions"
|
||||||
|
@ -189,7 +189,7 @@
|
||||||
bgcolor="#af9363"
|
bgcolor="#af9363"
|
||||||
>
|
>
|
||||||
<a
|
<a
|
||||||
href="https://shinnex.de?utm_source=email&utm_medium=email&utm_campaign=deserved_voucher_{{PRICE}}&utm_content=deserved_voucher_{{PRICE}}"
|
href="https://shinnex.de/discount/{{DISCOUNT_CODE}}?utm_source=email&utm_medium=email&utm_campaign=deserved_voucher_{{PRICE}}&utm_content=deserved_voucher_{{PRICE}}"
|
||||||
class="button__text"
|
class="button__text"
|
||||||
style="
|
style="
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
Dein Gutscheincode als Dankeschön
|
Dein Gutscheincode als Dankeschön
|
||||||
|
|
||||||
{{MESSAGE}} Du kannst den Gutschein beim Checkout einlösen.
|
{{MESSAGE}} Als kleines Dankeschön möchten wir dir einen {{PRICE}} € Gutschein überreichen.
|
||||||
|
Du kannst den Gutschein beim Checkout einlösen.
|
||||||
|
|
||||||
Dein Gutscheincode lautet: {{VOUCHER_CODE}}
|
Dein Gutscheincode lautet: {{DISCOUNT_CODE}}
|
||||||
|
|
||||||
Zu unserem Shop: https://shinnex.de?utm_source=email&utm_medium=email&utm_campaign=deserved_voucher&utm_content=deserved_voucher
|
Zu unserem Shop: https://shinnex.de?/discount/{{DISCOUNT_CODE}}?utm_source=email&utm_medium=email&utm_campaign=deserved_voucher&utm_content=deserved_voucher
|
||||||
|
|
||||||
Falls du Fragen hast, antworte auf diese E-Mail oder kontaktiere uns unter info@shinnex.de.
|
Falls du Fragen hast, antworte auf diese E-Mail oder kontaktiere uns unter info@shinnex.de.
|
Binary file not shown.
Loading…
Reference in New Issue