Skip to content

Discounts

File: app/core/models/discounts.py

Stores campaign discount metadata synced from Shopify.

Key fields

Field Description
id, name, description Identity
provider / provider_id Shopify enum / Shopify discount ID
discount_type, value e.g., percentage, fixed amount
json Metadata: prefix for code generation, product/collection IDs, purchase_type, minimum_spend
code_count Tracks generated codes

Assignment flow

  1. Creation: POST /v1/discounts/ syncs with Shopify, stores in DB
  2. Campaign linking: Campaigns store discount_id, discount_code (static), and use_unique_discount flag
  3. Recipient assignment (methods/runner.py:apply_discount_code()):
  4. Static: Applies campaign-level discount_code to all recipients
  5. Unique: Generates per-recipient codes from Shopify, stores in recipient.json["discount_code"], increments code_count

Attribution integration

methods/attributions.py:check_recipient_order_discount_match() compares recipient's discount code with order's discount codes (case-insensitive). If matched, attribution automatically passes rules regardless of timing window.

Key files

  • Model: core/models/discounts.py
  • Routes: routes/discount_routes.py
  • Assignment: methods/runner.py
  • Attribution: methods/attributions.py