Skip to content

Shopify Articles Endpoints & Repricer Workflow

Location: backend/service_multi-repricer/app/api/v1/endpoints/shopify_articles.py

Overview

This module contains the main workflows for recalculating Shopify-target prices, exporting updates to Plenty/Shopify, and scheduling the repricer via CronJobManager.

Key endpoints

  • POST /cron/start — Start or update the Shopify repricer cron job
  • Query/body: schedule (CRON expression, default 0 8 * * *)
  • Response: CronStartResponse
  • Uses: CronJobManager.upsert_job(name="shopify_repricer_cron", func=shopify_repricer_runner)

  • POST /cron/stop — Stop the Shopify repricer cron job

  • Response: CronStopResponse

  • GET /cron/status — Get status of the scheduled job

  • Response: CronStatusResponse with expression, last_run_at, next_run_at, active flag

  • POST /recalculate/{sku} — Trigger recalculation for a single SKU or all SKUs

  • Path: sku (use all to trigger full run)
  • Runs recalculate_articles in a background task and returns immediately with a start message.

  • POST /export-updates — Export articles flagged UPDATE_NEEDED (or a single SKU if sku provided) to Shopify

  • Runs run_shopify_export in a background task; uses Plenty_Manager.export_to_shopify for each item.

Representative behavior

  • recalculate_articles(db, sku=None, provision_pct=None)
  • Loads RepricerArticle records (single SKU or all). For each article:

    • Ensures brutto_buy_price and package_cost are present; otherwise marks ShopifyDetails.status = ERROR.
    • Finds MarginRule using get_margin_rule_for_price(db, buy_price).
    • Calculates desired_price using calculate_profit_data(...) (see below).
    • If the article's ShopifyDetails.use_min_max_rules is false, preserves the stored price instead of using calculated desired_price.
    • Sets ShopifyDetails.status to UPDATE_NEEDED if price changed, otherwise ACTIVE.
    • Updates or creates ShopifyDetails via repricer_article CRUD helpers.
  • run_shopify_export(sku_inner)

  • Collects export items (item_id, variation_id, target price) and calls Plenty_Manager.export_to_shopify.
  • On success updates ShopifyDetails status to ACTIVE and writes expected_profit.
  • Notifies websockets about start and finish via notifications.notify_clients.

Pricing function: calculate_profit_data

  • Inputs: buy_price, provision_pct (default 2.99), fixed_fee (default 0.35), package_cost, target_margin, min_profit.
  • Behavior:
  • Uses VAT factor 1.19 (19% VAT) to compute net_buy_price.
  • Computes candidate prices that satisfy either the margin percentage or minimum profit, picks the higher.
  • Applies business rounding to an .90 / -.10 candidate and returns a Decimal rounded to cents.

Examples

  • Trigger full recalculation (background):
curl -X POST "http://localhost:8000/api/v1/multi/recalculate/all"
  • Trigger export for a specific SKU:
curl -X POST "http://localhost:8000/api/v1/multi/export-updates?sku=SKU123"

Operational notes

  • Requires active Plenty credentials for exports: plenty_crud.get_active() must return a credential record.
  • The export process updates DB records and can be long-running; monitor logs and the websocket notifications for progress.
  • Background tasks use SessionLocal() for DB access to avoid interfering with request-scoped sessions.

Shopify Articles Endpoints

Router prefix: /shopify/articles → full base: /api/v1/multi/shopify/articles

Summary: Shopify-specific article details, margin rule management, and repricer triggers.

Implementation: backend/service_multi-repricer/app/api/v1/endpoints/shopify_articles.py


TODO: Populate detailed method table and examples.