Last active
January 3, 2022 10:54
-
-
Save stlk/3484e79ed3d63fdf400f866b46d16286 to your computer and use it in GitHub Desktop.
How to generate a product with 100 variants
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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