api.services.shopify_products ============================= .. py:module:: api.services.shopify_products .. autoapi-nested-parse:: 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). .. mermaid:: 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 ---------- .. autoapisummary:: api.services.shopify_products.logger api.services.shopify_products.NAMESPACE api.services.shopify_products.TEXT api.services.shopify_products.LINE api.services.shopify_products.IMAGES_SOURCE_KEY api.services.shopify_products.VariantKey Classes ------- .. autoapisummary:: api.services.shopify_products.DesiredProduct api.services.shopify_products.SyncResult Functions --------- .. autoapisummary:: api.services.shopify_products.variant_key api.services.shopify_products.product_gid api.services.shopify_products.numeric_id api.services.shopify_products.client api.services.shopify_products.fetch_product api.services.shopify_products.delete_product api.services.shopify_products.sync_product Module Contents --------------- .. py:data:: logger .. py:data:: NAMESPACE :value: 'custom' .. py:data:: TEXT :value: 'multi_line_text_field' .. py:data:: LINE :value: 'single_line_text_field' .. py:data:: IMAGES_SOURCE_KEY :value: 'images_airtable_ids' .. py:data:: VariantKey .. py:class:: DesiredProduct .. py:attribute:: title :type: str .. py:attribute:: description_html :type: str .. py:attribute:: vendor :type: str .. py:attribute:: product_type :type: str | None .. py:attribute:: status :type: str | None .. py:attribute:: option_names :type: list[str] .. py:attribute:: variants :type: dict[VariantKey, dict[str, Any]] .. py:attribute:: weight :type: float | None .. py:attribute:: metafields :type: dict[str, tuple[str | None, str]] .. py:attribute:: image :type: dict[str, Any] | None .. py:class:: SyncResult .. py:attribute:: product_id :type: str .. py:attribute:: created :type: bool :value: False .. py:attribute:: product_fields_updated :type: list[str] :value: [] .. py:attribute:: images_uploaded :type: int :value: 0 .. py:attribute:: counts :type: dict[str, int] .. py:attribute:: errors :type: list[str] :value: [] .. py:function:: variant_key(values: list[Any]) -> VariantKey Stripped: Shopify trims option values on save ("120x47 " is stored "120x47"). .. py:function:: product_gid(product_id: int | str) -> str .. py:function:: numeric_id(gid: str) -> str .. py:function:: client() -> api.integrations.shopify.generated.ShopifyClient .. py:function:: 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. .. py:function:: delete_product(shopify: api.integrations.shopify.generated.ShopifyClient, product_id: int | str) -> None Deletes the product; one already gone counts as deleted. .. py:function:: 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.