auto generate discount code

main
alex 2024-06-20 19:07:42 +02:00
parent 3a2c29b2b8
commit 8fb9d31ddd
12 changed files with 249 additions and 30 deletions

View File

@ -42,8 +42,11 @@
"#36521 Charlie das Häschen, FARBE, Hellbraun, (Matt)",
"#48273 Charlie das Häschen, FARBE, Gold, (Glänzend)",
"#71936 Ruby die Schlange, FARBE, Feuerrot, (Glänzend)",
"#58324 Ruby die Schlange, FARBE, Rot/Blau, (Glänzend)",
"#58324 Ruby die Schlange, FARBE, Lila/Blau, (Glänzend)",
"#78648 Ruby die Schlange, FARBE, Gold, (Glänzend)",
"#15809 Ruby die Schlange, FARBE, Himmelblau, (Fluoreszierend)",
"#49461 Ruby die Schlange, FARBE, Rosa, (Matt)",
"#84491 Ruby die Schlange, FARBE, Rot/Schwarz, (Glänzend)",
"#21433 Bruno der Dino, FARBE, Grün/Blau/Orange, (Glänzend)",
"#57953 Bruno der Dino, FARBE, Rot/Blau, (Glänzend)",
"#90578 Bruno der Dino, FARBE, Gold, (Glänzend)",
@ -69,14 +72,19 @@
"#35717 Stella der Phönix, FARBE, Sonderanfertigung, Rosa/Weiß",
"#26843 Stella der Phönix, FARBE, Verlauf Lila/Pink, ",
"#74943 Brain der Fuchs, STIL, Standard, ",
"#78071 Weißer Hund, STIL, Weiß, ",
"#92734 Amigo der Capybara, FARBE, Braun, "
"#78071 Lucky der Barsoi, FARBE, Weiß, ",
"#92734 Amigo der Capybara, FARBE, Braun, ",
"#22318 Witty der Fuchs, STIL, Standard, ",
"#23732 Witty der Fuchs, STIL, Standard, Mit Halstuch",
"#72175 Paco die Bulldogge, FARBE, Grau, ",
"#55172 Sharky der Hai, FARBE, Grau, ",
"#10971 Chibi die Ratte, FARBE, Grau, "
]
}
]
},
{
"name": "Gutscheincodes für Bestellung erstellen (nur die Bestellnummer ohne #)",
"name": "Gutscheincodes für Bestellung erstellen",
"onFinish": "pause",
"undoPossible": false,
"repeatPossible": true,
@ -101,11 +109,6 @@
"parameterName": "productUrl",
"type": "text",
"displayName": "URL vom Produkt (Shopify) (z. B. https://shinnex.de/products/gizmo) (für Direktweiterleitung 5 € Gutschein QR-Code)"
},
{
"parameterName": "discountCode",
"type": "text",
"displayName": "10 % Gutscheincode für den Kunden (in Shopify erstellen)"
}
]
},

View File

@ -33,7 +33,8 @@
"25 Blau/Weiß, TempChange Matte PLA, TRONXY",
"26 Beige, Matte PLA, OVERTURE",
"27 Marineblau, Matte PLA, OVERTURE",
"28 Gelb, Matte PLA, OVERTURE"
"28 Gelb, Matte PLA, OVERTURE",
"29 Rot/Schwarz, Dual-Color Silk PLA, AMOLEN"
]
}
]

View File

@ -22,8 +22,11 @@
"#36521 Charlie das Häschen, FARBE, Hellbraun, (Matt)",
"#48273 Charlie das Häschen, FARBE, Gold, (Glänzend)",
"#71936 Ruby die Schlange, FARBE, Feuerrot, (Glänzend)",
"#58324 Ruby die Schlange, FARBE, Rot/Blau, (Glänzend)",
"#58324 Ruby die Schlange, FARBE, Lila/Blau, (Glänzend)",
"#78648 Ruby die Schlange, FARBE, Gold, (Glänzend)",
"#15809 Ruby die Schlange, FARBE, Himmelblau, (Fluoreszierend)",
"#49461 Ruby die Schlange, FARBE, Rosa, (Matt)",
"#84491 Ruby die Schlange, FARBE, Rot/Schwarz, (Glänzend)",
"#21433 Bruno der Dino, FARBE, Grün/Blau/Orange, (Glänzend)",
"#57953 Bruno der Dino, FARBE, Rot/Blau, (Glänzend)",
"#90578 Bruno der Dino, FARBE, Gold, (Glänzend)",
@ -49,8 +52,13 @@
"#35717 Stella der Phönix, FARBE, Sonderanfertigung, Rosa/Weiß",
"#26843 Stella der Phönix, FARBE, Verlauf Lila/Pink, ",
"#74943 Brain der Fuchs, STIL, Standard, ",
"#78071 Weißer Hund, STIL, Weiß, ",
"#92734 Amigo der Capybara, FARBE, Braun, "
"#78071 Lucky der Barsoi, FARBE, Weiß, ",
"#92734 Amigo der Capybara, FARBE, Braun, ",
"#22318 Witty der Fuchs, STIL, Standard, ",
"#23732 Witty der Fuchs, STIL, Standard, Mit Halstuch",
"#72175 Paco die Bulldogge, FARBE, Grau, ",
"#55172 Sharky der Hai, FARBE, Grau, ",
"#10971 Chibi die Ratte, FARBE, Grau, "
]
}
]

View File

@ -0,0 +1,87 @@
{
"category": "Shinnex",
"name": "Schritte für neue Produktveröffentlichung",
"globalInputs": [],
"tasks": [
{
"name": "Produktvideos/fotos erstellen",
"onFinish": "pause",
"undoPossible": false,
"repeatPossible": true,
"scriptPath": "empty.py",
"parameters": []
},
{
"name": "Produktvideos/fotos auf Seafile hochladen",
"onFinish": "pause",
"undoPossible": false,
"repeatPossible": true,
"scriptPath": "empty.py",
"parameters": []
},
{
"name": "Befehl auf Seafile ausführen um Bilder zu konvertieren",
"onFinish": "pause",
"undoPossible": false,
"repeatPossible": true,
"scriptPath": "empty.py",
"parameters": []
},
{
"name": "TikTok Video drehen",
"onFinish": "pause",
"undoPossible": false,
"repeatPossible": true,
"scriptPath": "empty.py",
"parameters": []
},
{
"name": "TikTok Video schneiden",
"onFinish": "pause",
"undoPossible": false,
"repeatPossible": true,
"scriptPath": "empty.py",
"parameters": []
},
{
"name": "Produktvideos schneiden",
"onFinish": "pause",
"undoPossible": false,
"repeatPossible": true,
"scriptPath": "empty.py",
"parameters": []
},
{
"name": "Produkt in Shop online stellen",
"onFinish": "pause",
"undoPossible": false,
"repeatPossible": true,
"scriptPath": "empty.py",
"parameters": []
},
{
"name": "Produktpipeline aktualisieren",
"onFinish": "pause",
"undoPossible": false,
"repeatPossible": true,
"scriptPath": "empty.py",
"parameters": []
},
{
"name": "TikTok Video hochladen",
"onFinish": "pause",
"undoPossible": false,
"repeatPossible": true,
"scriptPath": "empty.py",
"parameters": []
},
{
"name": "Instagram Post hochladen",
"onFinish": "pause",
"undoPossible": false,
"repeatPossible": true,
"scriptPath": "empty.py",
"parameters": []
}
]
}

View File

@ -4,7 +4,7 @@
"globalInputs": [],
"tasks": [
{
"name": "Gutscheincodes für Bestellung erstellen (nur die Bestellnummer ohne #)",
"name": "Gutscheincodes für Bestellung erstellen",
"onFinish": "next",
"undoPossible": false,
"repeatPossible": true,
@ -29,11 +29,6 @@
"parameterName": "productUrl",
"type": "text",
"displayName": "URL vom Produkt (Shopify) (z. B. https://shinnex.de/products/gizmo) (für Direktweiterleitung 5 € Gutschein QR-Code)"
},
{
"parameterName": "discountCode",
"type": "text",
"displayName": "10 % Gutscheincode für den Kunden (in Shopify erstellen)"
}
]
}

View File

@ -1,10 +1,11 @@
import requests
import sys
import json
import qrcode
import subprocess
import sys
import os
import string
import random
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
@ -26,24 +27,27 @@ headers = {
json_object = json.loads(sys.argv[1])
customerEmail = json_object["customerEmail"]
customerName = json_object["customerName"]
discountCode = json_object["discountCode"]
productUrl = json_object["productUrl"]
orderId = json_object["orderId"]
if (customerEmail is None
or orderId is None
or customerName is None
or productUrl is None
or discountCode is None):
or productUrl is None):
print("Missing required parameters")
sys.exit(1)
customerEmail = customerEmail["value"]
customerName = customerName["value"]
discountCode = discountCode["value"]
productUrl = productUrl["value"]
orderId = orderId["value"]
# remove the # from the orderId if provided
if orderId.startswith('#'):
orderId = orderId[1:]
discountCode = None
def CreateCrmCustomer():
response = requests.post(
@ -114,6 +118,49 @@ def CheckIfCrmCustomerExists():
GetCustomerActivityLinks(customerId=customerId)
# create shopify discount code
# this function will retry 3 times to create a new discount code if the random generate code already exists
def createShopifyDiscountCode(retries):
# generate random code
characters = string.ascii_uppercase + string.digits
discount_code = ''.join(random.choice(characters) for _ in range(12))
# load data from secrets
secrets = utils.get_secrets()
shopify_url = secrets['shopify_url']
x_shopify_access_token = secrets['x_shopify_access_token']
shopify_discount_code_price_rule = secrets['shopify_discount_code_price_rule']
response = requests.post(
url=f"{shopify_url}/admin/api/2024-01/price_rules/{shopify_discount_code_price_rule}/discount_codes.json",
headers={
"X-Shopify-Access-Token": x_shopify_access_token,
"Content-Type": "application/json"
},
json={
"discount_code": {"code": discount_code}
})
retries += 1
if retries >= 3:
sys.exit("Error, tried 3 times to create discount code")
if response.status_code == 422:
print("Failed to create code, response status code 422. Trying to generate new discount code")
createShopifyDiscountCode(retries)
if response.status_code != 201:
sys.exit(f"Failed to create discount code, status code: {response.status_code}")
print(f"Created discount code: {discount_code}")
global discountCode
discountCode = discount_code
def CreateCrmActivityLink(customerId, thirdVoucher):
print(f"Creating CRM activity link for customer {customerId}")
@ -133,6 +180,8 @@ def CreateCrmActivityLink(customerId, thirdVoucher):
print(f"CreateCrmActivityLink req error {response.status_code}")
sys.exit(1)
createShopifyDiscountCode(0)
req("10 % Gutschein", f"https://shinnex.de/discount/{discountCode}?utm_source=order&utm_medium=qrcode&utm_campaign=ordervouchercodes&utm_content=reedemvouchercode")
req("5 € Gutschein", f"{productUrl}?utm_source=order&utm_medium=qrcode&utm_campaign=ordervouchercodes&utm_content=qualifyforvouchercode")

View File

@ -26,8 +26,11 @@
"#36521 Charlie das Häschen, FARBE, Hellbraun, (Matt)",
"#48273 Charlie das Häschen, FARBE, Gold, (Glänzend)",
"#71936 Ruby die Schlange, FARBE, Feuerrot, (Glänzend)",
"#58324 Ruby die Schlange, FARBE, Rot/Blau, (Glänzend)",
"#58324 Ruby die Schlange, FARBE, Lila/Blau, (Glänzend)",
"#78648 Ruby die Schlange, FARBE, Gold, (Glänzend)",
"#15809 Ruby die Schlange, FARBE, Himmelblau, (Fluoreszierend)",
"#49461 Ruby die Schlange, FARBE, Rosa, (Matt)",
"#84491 Ruby die Schlange, FARBE, Rot/Schwarz, (Glänzend)",
"#21433 Bruno der Dino, FARBE, Grün/Blau/Orange, (Glänzend)",
"#57953 Bruno der Dino, FARBE, Rot/Blau, (Glänzend)",
"#90578 Bruno der Dino, FARBE, Gold, (Glänzend)",
@ -53,8 +56,13 @@
"#35717 Stella der Phönix, FARBE, Sonderanfertigung, Rosa/Weiß",
"#26843 Stella der Phönix, FARBE, Verlauf Lila/Pink, ",
"#74943 Brain der Fuchs, STIL, Standard, ",
"#78071 Weißer Hund, STIL, Weiß, ",
"#92734 Amigo der Capybara, FARBE, Braun, "
"#78071 Lucky der Barsoi, FARBE, Weiß, ",
"#92734 Amigo der Capybara, FARBE, Braun, ",
"#22318 Witty der Fuchs, STIL, Standard, ",
"#23732 Witty der Fuchs, STIL, Standard, Mit Halstuch",
"#72175 Paco die Bulldogge, FARBE, Grau, ",
"#55172 Sharky der Hai, FARBE, Grau, ",
"#10971 Chibi die Ratte, FARBE, Grau, "
],
"global": false
}

View File

@ -107,6 +107,12 @@
"name_color": "Gelb",
"material": "Matte PLA",
"manufacturer": "OVERTURE"
},
{
"id": "29",
"name_color": "Rot/Schwarz",
"material": "Dual-Color Silk PLA",
"manufacturer": "AMOLEN"
}
]
}

View File

@ -46,7 +46,7 @@
"id": "58324",
"name": "Ruby_die Schlange",
"product_variant": "FARBE",
"product_characteristic_line_1": "Rot/Blau",
"product_characteristic_line_1": "Lila/Blau",
"product_characteristic_line_2": "(Glänzend)"
},
{
@ -56,6 +56,27 @@
"product_characteristic_line_1": "Gold",
"product_characteristic_line_2": "(Glänzend)"
},
{
"id": "15809",
"name": "Ruby_die Schlange",
"product_variant": "FARBE",
"product_characteristic_line_1": "Himmelblau",
"product_characteristic_line_2": "(Fluoreszierend)"
},
{
"id": "49461",
"name": "Ruby_die Schlange",
"product_variant": "FARBE",
"product_characteristic_line_1": "Rosa",
"product_characteristic_line_2": "(Matt)"
},
{
"id": "84491",
"name": "Ruby_die Schlange",
"product_variant": "FARBE",
"product_characteristic_line_1": "Rot/Schwarz",
"product_characteristic_line_2": "(Glänzend)"
},
{
"id": "21433",
"name": "Bruno_der Dino",
@ -233,8 +254,8 @@
},
{
"id": "78071",
"name": "Weißer_Hund",
"product_variant": "STIL",
"name": "Lucky_der Barsoi",
"product_variant": "FARBE",
"product_characteristic_line_1": "Weiß",
"product_characteristic_line_2": ""
},
@ -244,6 +265,41 @@
"product_variant": "FARBE",
"product_characteristic_line_1": "Braun",
"product_characteristic_line_2": ""
},
{
"id": "22318",
"name": "Witty_der Fuchs",
"product_variant": "STIL",
"product_characteristic_line_1": "Standard",
"product_characteristic_line_2": ""
},
{
"id": "23732",
"name": "Witty_der Fuchs",
"product_variant": "STIL",
"product_characteristic_line_1": "Standard",
"product_characteristic_line_2": "Mit Halstuch"
},
{
"id": "72175",
"name": "Paco_die Bulldogge",
"product_variant": "FARBE",
"product_characteristic_line_1": "Grau",
"product_characteristic_line_2": ""
},
{
"id": "55172",
"name": "Sharky_der Hai",
"product_variant": "FARBE",
"product_characteristic_line_1": "Grau",
"product_characteristic_line_2": ""
},
{
"id": "10971",
"name": "Chibi_die Ratte",
"product_variant": "FARBE",
"product_characteristic_line_1": "Grau",
"product_characteristic_line_2": ""
}
]
}

View File

@ -4,6 +4,7 @@ import os
import shutil
import sys
import qrcode
import json
def clear_workspace(files):
@ -142,3 +143,8 @@ def create_qrcode(qr_code_url, save_path, back_color):
# Save image to a file
# like ./test.png
img.save(save_path)
def get_secrets():
with open('../../secrets/secrets.json') as content:
return json.load(content)