Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- from fyfe_task.settings import SHOPIFY_TOKEN, SHOPIFY_PASS, SHOPIFY_SHOP_NAME
- default_url = f'https://{SHOPIFY_TOKEN}:{SHOPIFY_PASS}@{SHOPIFY_SHOP_NAME}.myshopify.com'
- def get_variant_id(product):
- url = default_url + f"/admin/products/{product.id}.json"
- headers = {
- 'content-type': "application/json"
- }
- response = requests.get(url, headers=headers).json()
- for variant in response["product"]["variants"]:
- for num in range(1, len(response["product"]["options"]) + 1):
- if variant["option" + str(num)] == product.color:
- return variant["id"]
- elif variant["option" + str(num)] == product.size:
- return variant["id"]
- class Product():
- def __init__(self):
- self.id = '1342789189691'
- self.size = '1 oz'
- self.color = '3 - Gold Bronze'
- product = Product()
- id = get_variant_id(product)
- print(id)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement