Skip to content

Developer notes

  • Client\Printful and Client\Printify (both extend Client\BaseClient, implement Client\ProviderInterface): cURL with TLS verification, JSON, error mapping, masked logging. They return the decoded JSON of the official API untouched.
  • Mapper: pure mapping to neutral shapes (product, order, shipment, quote, webhook event). Unit tested with the examples of the official docs (tests/fixtures, each file names its doc section).
  • Connections: one row per Printful store / Printify shop, company_id 0 = owner, vendor id otherwise; token and webhook secret sealed with Secret (AES-256-GCM).
  • Catalog (import, field locks, variant option), Sync (price and availability batch), PriceRules, Options, Fulfilment (routing, tracking, cancel, polling), Freight + RateCalculator + Tygh\Shippings\Services\KvPrintOnDemand (checkout rates), Jobs + Queue (retrying job queue with named locks), Webhook, Log.
  • Hooks: change_order_status_post (queues push / cancel), delete_product_post. No template hooks and no output on storefront pages (full page cache safe).
  • Tables: connections, product_map, variant_map, order_map, options, category_map, cache, jobs, log.

Printful API v1 (https://api.printful.com, Authorization: Bearer <private token>, optional X-PF-Store-Id): GET /store/products (offset, limit), GET /store/products/{id}, GET /products/variant/{id} (catalog cost), POST /orders (?confirm=true only in the immediate mode), GET /orders/@{external_id} and GET /orders/{id}, POST /orders/{id}/confirm, DELETE /orders/{id}, POST /shipping/rates, POST /webhooks. Events: package_shipped, package_returned, order_created / updated / failed / canceled / put_hold / remove_hold / refunded, product_synced / updated / deleted, stock_updated.

Printify API v1 (https://api.printify.com/v1, Bearer personal access token, User-Agent on every call): GET /shops.json, GET /shops/{shop}/products.json (limit at most 50) and .../products/{id}.json, POST .../orders.json, GET .../orders.json and .../orders/{id}.json, POST .../orders/{id}/send_to_production.json, POST .../orders/{id}/cancel.json, POST .../orders/shipping.json, GET/POST/PUT .../webhooks.json. Topics: order:updated, order:sent-to-production, order:shipment:created, order:shipment:delivered, product:updated, product:deleted, shop:disconnected.

Printful API v2 is “2.0.0-beta” and not used. Both providers let a merchant create a token in his own account (Printful private token, Printify personal access token); the add-on uses exactly that and needs no partner approval. Printify’s API terms ask that a merchant grants access (the merchant pasting his own token is that grant), that its marks are used only to show compatibility, and that merchant data is deleted when the merchant disconnects (Disconnect removes the token).

  1. A row in order_map (state P) with the deterministic external id (prefix + order id + connection id, at most 32 characters) is written before the request.
  2. GET_LOCK per order and connection surrounds “look up, create, store”.
  3. Before every create the provider is asked: Printful GET /orders/@external_id; Printify the stored order id, otherwise the newest 150 orders matched on metadata.shop_order_id (the list has no external id filter). A hit is adopted.
  4. A Printify duplicate (409 with the existing order id) is adopted the same way.
  5. The provider order id is stored the moment the create answers, before Printify’s send_to_production call; a later failure of that call is logged and leaves the order for the Confirm button.
  6. A retryable error (timeout, 429, 5xx) leaves the row pending and the job retries; a permanent error (4xx) marks the row Failed with the provider’s reason and the job dead (Send now repeats it with the same id).
  7. A cancelled order is never revived: a new external id (...r1) is used for the next send.

Webhooks are hints: Fulfilment::applyEvent finds the row through the connection’s own order map and reads the order back from the API before anything changes. Late messages never move an order backwards (fulfilled stays fulfilled).

$config['kv_print_on_demand_base_url'] = 'http://127.0.0.1:11841'; in config.local.php points both clients at the mock server (tests/mock-server/server.js). The e2e refuses to run unless the store points at 127.0.0.1 / localhost.

Verified against the official docs and a docs-shaped mock only (not against a live account; the owner may supply free Printful / Printify test tokens). Items the docs leave open and that the code handles defensively:

  • The currency of a Printful catalog variant price is read from result.product.currency (the variant carries none); sync variants carry a currency.
  • Printify’s shipping calculation returns {standard, express, priority, printify_express, economy}; the unit is not stated, treated as cents like every other Printify money field. Only method 1 (standard, the documented default of an order) is quoted and used.
  • The body of Printify’s 409 for a duplicate external id is documented as “error 8503 with the existing order id”; the add-on looks for id / order_id and otherwise falls back to the order list.
  • Printful cost fields of an order (costs.total, costs.currency) and the order_failed / put_hold reasons are read when present.
  • Printful documents no webhook signature: the URL key plus the read-back is the protection. Printify’s X-Pfy-Signature is sha256=<hex HMAC of the raw body>.
  • A Printful shipment sample shows tracking_number: 0 for a shipment without tracking: no number, no CS-Cart shipment.
  • Product Personalizer files per order item: Printful accepts files per item; Printify per-order print areas were not verified. Planned for 1.1.
  • Product creation and publishing from CS-Cart to the providers: products are designed at Printful or Printify and imported.
  • Several parcels of one provider order: the first tracking number creates the shipment, further numbers are appended to it (the providers’ line ids are not CS-Cart item ids).

Everything provider specific is in Client\Printful, Client\Printify and Mapper; a third print provider needs a ProviderInterface implementation, its mappings and a case in Client::forConn.