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, default0 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:
CronStatusResponsewithexpression,last_run_at,next_run_at,activeflag -
POST
/recalculate/{sku}— Trigger recalculation for a single SKU or all SKUs - Path:
sku(useallto trigger full run) -
Runs
recalculate_articlesin a background task and returns immediately with a start message. -
POST
/export-updates— Export articles flaggedUPDATE_NEEDED(or a single SKU ifskuprovided) to Shopify - Runs
run_shopify_exportin a background task; usesPlenty_Manager.export_to_shopifyfor each item.
Representative behavior
recalculate_articles(db, sku=None, provision_pct=None)-
Loads
RepricerArticlerecords (single SKU or all). For each article:- Ensures
brutto_buy_priceandpackage_costare present; otherwise marksShopifyDetails.status = ERROR. - Finds
MarginRuleusingget_margin_rule_for_price(db, buy_price). - Calculates
desired_priceusingcalculate_profit_data(...)(see below). - If the article's
ShopifyDetails.use_min_max_rulesis false, preserves the storedpriceinstead of using calculateddesired_price. - Sets
ShopifyDetails.statustoUPDATE_NEEDEDif price changed, otherwiseACTIVE. - Updates or creates
ShopifyDetailsviarepricer_articleCRUD helpers.
- Ensures
-
run_shopify_export(sku_inner) - Collects export items (item_id, variation_id, target price) and calls
Plenty_Manager.export_to_shopify. - On success updates
ShopifyDetailsstatus toACTIVEand writesexpected_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 / -.10candidate and returns aDecimalrounded 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.