Skip to content

Instantly share code, notes, and snippets.

@stlk
Last active January 3, 2022 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stlk/3484e79ed3d63fdf400f866b46d16286 to your computer and use it in GitHub Desktop.
Save stlk/3484e79ed3d63fdf400f866b46d16286 to your computer and use it in GitHub Desktop.
How to generate a product with 100 variants
import shopify
from django.core.management.base import BaseCommand
from console.models import AuthAppShopUser
class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument(
"myshopify_domain",
type=str,
)
def handle(self, *args, **options):
myshopify_domain = options["myshopify_domain"]
shop = AuthAppShopUser.objects.get(myshopify_domain=myshopify_domain)
with shop.session:
variants = [{"option1":f"Variant {idx}", "inventory_management": "shopify","price":idx} for idx in range(100)]
shopify.Product.create({
"title":"Burton Custom Freestyle 222",
"body_html":"\u003cstrong\u003eGood snowboard!\u003c\/strong\u003e",
"variants": variants,
"vendor":"Burton","product_type":"Snowboard","tags":["Barnes \u0026 Noble","Big Air","John's Fav"]})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment