api.services.shopify_products

Writes a Shopify product from the state Airtable wants it in.

The live product is read once (fetch_product), compared with the wanted state (DesiredProduct), and only what differs is sent: one productSet for the product, its options, variants, prices, weights and image, then stock changes of existing variants (inventorySetQuantities, compare-and-set) and metafields (metafieldsSet). A product already in sync costs one read and no write.

productSet replaces the lists it is given: the variants sent are the variants the product keeps, the image sent replaces the media. The image is only sent when the Airtable attachment it comes from changed (recorded in the images_airtable_ids metafield).

        flowchart LR
    A[DesiredProduct] --> D{diff with live}
    L[fetch_product] --> D
    D -->|product, variants, image| P[productSet]
    D -->|stock of kept variants| I[inventorySetQuantities]
    D -->|metafields| M[metafieldsSet]
    

Attributes

Classes

Functions

variant_key(values) → VariantKey

Stripped: Shopify trims option values on save ("120x47 " is stored "120x47").

product_gid(product_id) → str

numeric_id(gid) → str

client() → api.integrations.shopify.generated.ShopifyClient

fetch_product(shopify, product_id) → api.integrations.shopify.generated.product_for_sync.ProductForSyncProduct | None

The live product, or None when it does not exist.

delete_product(shopify, product_id) → None

Deletes the product; one already gone counts as deleted.

sync_product(shopify, desired, live) → SyncResult

Creates the product (live None) or brings live to desired.

Module Contents

api.services.shopify_products.logger
api.services.shopify_products.NAMESPACE = 'custom'
api.services.shopify_products.TEXT = 'multi_line_text_field'
api.services.shopify_products.LINE = 'single_line_text_field'
api.services.shopify_products.IMAGES_SOURCE_KEY = 'images_airtable_ids'
api.services.shopify_products.VariantKey
class api.services.shopify_products.DesiredProduct
title: str
description_html: str
vendor: str
product_type: str | None
status: str | None
option_names: list[str]
variants: dict[VariantKey, dict[str, Any]]
weight: float | None
metafields: dict[str, tuple[str | None, str]]
image: dict[str, Any] | None
class api.services.shopify_products.SyncResult
product_id: str
created: bool = False
product_fields_updated: list[str] = []
images_uploaded: int = 0
counts: dict[str, int]
errors: list[str] = []
api.services.shopify_products.variant_key(values: list[Any]) → VariantKey

Stripped: Shopify trims option values on save (“120x47 “ is stored “120x47”).

api.services.shopify_products.product_gid(product_id: int | str) → str
api.services.shopify_products.numeric_id(gid: str) → str
api.services.shopify_products.client() → api.integrations.shopify.generated.ShopifyClient
api.services.shopify_products.fetch_product(shopify: api.integrations.shopify.generated.ShopifyClient, product_id: int | str) → api.integrations.shopify.generated.product_for_sync.ProductForSyncProduct | None

The live product, or None when it does not exist.

api.services.shopify_products.delete_product(shopify: api.integrations.shopify.generated.ShopifyClient, product_id: int | str) → None

Deletes the product; one already gone counts as deleted.

api.services.shopify_products.sync_product(shopify: api.integrations.shopify.generated.ShopifyClient, desired: DesiredProduct, live: api.integrations.shopify.generated.product_for_sync.ProductForSyncProduct | None) → SyncResult

Creates the product (live None) or brings live to desired.

Raises ShopifyError when productSet is refused: nothing was written then. Stock and metafield failures come back in errors, after everything else was written.