PhoenixKitEcommerce.Shopify.Sync (PhoenixKitEcommerce v0.3.0)

Copy Markdown View Source

Orchestrates a Shopify → local product sync: fetch, diff, and selectively apply confirmed changes.

This is the domain layer only — no LiveView/UI wiring here (see PhoenixKitEcommerce.Shopify.Provider moduledoc for why "Test Connection" doesn't exercise this; that's this module's job instead, via check/1).

Summary

Functions

Applies fields from change to its product.

Applies fields to every change in changes, partitioning them by outcome.

Fetches Shopify products for integration_uuid, diffs them against the local catalog, and returns the list of changes an operator can review.

Functions

apply_change(change, fields \\ :all)

@spec apply_change(
  PhoenixKitEcommerce.Shopify.ProductDiff.Change.t(),
  :all | [atom()]
) ::
  {:ok, PhoenixKitEcommerce.Product.t()} | {:error, Ecto.Changeset.t()}

Applies fields from change to its product.

fields is :all (every field in change.changes) or an explicit list of field atoms — only fields present in BOTH change.changes and fields are written, everything else on the product is left untouched. Localized fields (title, body_html, description) are merged into the base locale only; other languages already on the product are preserved.

apply_changes(changes, fields \\ :all)

Applies fields to every change in changes, partitioning them by outcome.

A changeset failure on one product doesn't stop the rest from being attempted. Returns %{succeeded: [Change.t()], failed: [Change.t()]}, each preserving the input order — so a caller can drop succeeded and keep offering failed for retry instead of reporting them as done.

check(integration_uuid)

@spec check(String.t()) ::
  {:ok, [PhoenixKitEcommerce.Shopify.ProductDiff.Change.t()]} | {:error, term()}

Fetches Shopify products for integration_uuid, diffs them against the local catalog, and returns the list of changes an operator can review.