import requests

config_script = """
config = env['shopify.config'].search([], limit=1)
token = config._ensure_access_token()
shop_domain = config.shop_url.strip().lower().replace('https://', '').split('/')[0]
product = env['product.template'].search([('name', '=', 'NAVY RED STRIPED POLO')], limit=1)
print(token, shop_domain, product.shopify_id)
"""
import subprocess
out = subprocess.check_output(['docker', 'exec', '-i', 'odoo-16-hazard-new', 'odoo', 'shell', '-d', 'hazard_new', '--no-http', '-c', '/etc/odoo/odoo.conf'], input=config_script.encode()).decode()
lines = [l for l in out.split('\n') if l and not l.startswith('2026') and not l.startswith('Odoo')]
token, shop_domain, shopify_id = lines[-1].split()

url = f"https://{shop_domain}/admin/api/2024-01/graphql.json"
headers = {
    "X-Shopify-Access-Token": token,
    "Content-Type": "application/json"
}
query = """
mutation productVariantsBulkCreate($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {
  productVariantsBulkCreate(productId: $productId, variants: $variants) {
    productVariants {
      id
      title
      sku
      price
    }
    userErrors {
      field
      message
    }
  }
}
"""
variables = {
    "productId": f"gid://shopify/Product/{shopify_id}",
    "variants": [
        {
            "price": "100.00",
            "inventoryItem": {"sku": "HRS-POL-REDSTRP-M-NVBL-XXL", "tracked": True},
            "optionValues": [
                {"linkedMetafieldValue": "XXL", "optionName": "Talla"}
            ]
        }
    ]
}
resp = requests.post(url, headers=headers, json={'query': query, 'variables': variables})
print("Status:", resp.status_code)
print("Response:", resp.json())
