Skip to content

Instantly share code, notes, and snippets.

@ketul-andev
Last active June 10, 2025 10:36
Show Gist options
  • Save ketul-andev/d8b9d0afba9ec1ffddc82bb61fea2c90 to your computer and use it in GitHub Desktop.
Save ketul-andev/d8b9d0afba9ec1ffddc82bb61fea2c90 to your computer and use it in GitHub Desktop.
from shopify_core.models import Plan, Subscription, ShopifyConfiguration, Shop
from datetime import datetime
shop_ids = ShopifyConfiguration.objects.filter(app_id='FACEBOOK_PIXEL', active=True).values_list('shop', flat=True)
shops = Shop.objects.filter(id__in=shop_ids)
#inactive plan with same features as advanced plan
plan = Plan.objects.get(id=37)
subscriptions = []
for shop in shops:
subscription = Subscription(
shop=shop, plan=plan, merchant_center_account=None, created_on=datetime.now(),
adwords_account=None, active=True, test=False,
recurring_charge_id=None, cancelled_on=None)
subscriptions.append(subscription)
Subscription.objects.bulk_create(subscriptions)
print(f"Created {len(subscriptions)} subscriptions")
@Yash-Adnabu
Copy link

If you're doing this for a large number of shops, use bulk_create.

@Yash-Adnabu
Copy link

Add logs as well if needed.

@ketul-andev
Copy link
Author

@amit-adnabu
Copy link

Approved.

@sahal-adnabu
Copy link

Approved

@rahul-adnabu
Copy link

Approved

@Yash-Adnabu
Copy link

Approved.

@glenn-adnabu
Copy link

glenn-adnabu commented Jun 10, 2025

Why are we basing this on shop configurations? Are all stores going to have a configuration? Even historically?
There was a time when the facebook pixel app did not require any configuration to function (I could be wrong). Should the app be restricted for those older customers?
If not, consider using credentials instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment