# Inventory (Shopify & Virtualstock Supplier)

## Introduction

This process flow retrieves the product listing associated with the Patchworks sales channel that you [defined in Shopify](https://doc.wearepatchworks.com/product-documentation/blueprints/patchworks-blueprints/shopify-and-virtualstock-supplier/installation-guide-shopify-and-virtualstock-supplier/stage-1-create-a-shopify-app-sales-channel-for-patchworks), and then updates *Virtualstock Supplier* with new stock levels:

<figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FclCsTmz8aLxmctHH7dfg%2Finventory%20flow%20illustration.png?alt=media&#x26;token=6abee44f-2709-47f4-9015-12a02b783fb5" alt=""><figcaption></figcaption></figure>

{% hint style="danger" %}
It's important to ensure that ONLY SKUs that you want to sync with *Virtualstock Supplier* are associated with the Patchworks app sales channel in Shopify - otherwise processing time will be longer.
{% endhint %}

Any SKUs pulled from *Shopify* are checked against the [SKU Lookup cross-reference table](#cross-reference-lookups-used-in-this-process-flow) and mapped to the relevant *Virtualstock Supplier* part number.

Then, Patchworks makes a call to *Virtualstock Supplier* to retrieve the product by part number (this is needed to obtain the associated `URL ID` of the product).  We then use the `URL ID` to make a second call into *Virtualstock Supplier* to update the stock level.

## Process flow snapshot

<details>

<summary><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FSUvxsp8XwrC9qsafJMIe%2Ficon%20process%20flow.svg?alt=media&#x26;token=ad1dc886-4a4e-4cad-9ad0-3d755e0f3b5a" alt="" data-size="line"> Process flow snapshot</summary>

<img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FZvCPQgDWUw2k6xaaDGIP%2Finventory%20flow%20example.png?alt=media&#x26;token=ae160f7d-b539-4ecb-88c5-f279690e11a1" alt="" data-size="original">

</details>

## Operations count

The operations count for this process flow is: **3 per sync**.

## Process flow shapes

For reference, all shapes in this process flow are documented below. Do not change shape settings unless advised to do so in our [installation guide](https://doc.wearepatchworks.com/product-documentation/blueprints/patchworks-blueprints/shopify-and-virtualstock-supplier/installation-guide-shopify-and-virtualstock-supplier). &#x20;

<table data-full-width="false"><thead><tr><th width="270">Shape</th><th>Notes</th></tr></thead><tbody><tr><td>Trigger</td><td>Having installed the app, edit this shape and define your preferred run schedule. The default setting is to run twice per day at 08:05 a.m. and 06:05 p.m. Please see the <a href="../installation-guide-shopify-and-virtualstock-supplier/stage-7-review-and-test-the-inventory-process-flow-shopify-to-virtualstock-supplier">installation guide</a> for specific notes.</td></tr><tr><td>Connector</td><td>This shape includes parameters that you should review/update. Please see the <a href="../installation-guide-shopify-and-virtualstock-supplier/stage-7-review-and-test-the-inventory-process-flow-shopify-to-virtualstock-supplier">installation guide</a> for specific notes.<br><br><code>Source instance</code>: Shopify <br><code>Source endpoint</code>: GET Retrieve product listings that are published to your app<br><code>Parameters</code>: <code>updated_at_min</code></td></tr><tr><td>Script</td><td>These settings should not be changed. For reference, the required settings are:<br><br><code>Script</code>: Replace negative qtys with 0<br><code>Version</code>: v1 (latest) </td></tr><tr><td>Flow control</td><td><p>There should be no need to change any settings for this shape. For reference, the required settings are:<br><br><code>Source instance</code>: N/A <br><code>Source endpoint</code>: N/A</p><p><code>Batch level</code>: *<br><code>Batch size</code>: 1</p></td></tr><tr><td>Flow control</td><td><p>There should be no need to change any settings for this shape. For reference, the required settings are:<br><br><code>Source instance</code>: N/A <br><code>Source endpoint</code>: N/A</p><p><code>Batch level</code>: *.variants<br><code>Batch size</code>: 1</p></td></tr><tr><td>Set variables</td><td>There should be no need to change any settings for this shape. For reference, the required settings are:<br><br><code>Meta</code>: Set as <code>key</code>: <code>sku</code> <code>value</code>: <code>[[payload.0.sku]]</code></td></tr><tr><td>Add to cache</td><td>These settings should not be changed. For reference, the required settings are:<br><br><code>Cache</code>: (Flow run) ShopifyVariantStockLevel<br><code>Cache key</code>: ShopifyVariantStockLevel.[[payload.0.sku]]<br><code>Append</code>: OFF<br><code>Save all pages</code>: OFF</td></tr><tr><td>Map</td><td>Generally, field mappings should not be changed. However please refer to the <a href="../installation-guide-shopify-and-virtualstock-supplier/stage-7-review-and-test-the-inventory-process-flow-shopify-to-virtualstock-supplier">installation guidelines</a> for this process flow for any fields that are noted for special attention.<br><br><code>Source instance</code>: None <br><code>Source endpoint</code>: None</td></tr><tr><td>Filter</td><td><p>There should be no need to change any settings for this shape. For reference, the required settings are:<br></p><p><code>Source instance</code>: N/A <br><code>Source endpoint</code>: N/A<br><code>Filters</code>: Set as: <code>*.part_number</code> <code>string</code> <code>not equals</code> <code>0</code><br><code>Keep matching</code>: ON</p></td></tr><tr><td>Connector</td><td><p>If instance credentials are provided as part of the blueprint installation, there should be no need to change any settings for this shape. For reference, the required settings are:<br></p><p><code>Source instance</code>: Virtualstock Supplier<br><code>Source endpoint</code>: GET Retrieve a product by part number<br><code>Variables</code>: Set as <code>part number</code> / <code>[[payload.0.part_number]]</code></p></td></tr><tr><td>Add to cache</td><td>These settings should not be changed. For reference, required settings are:<br><br><code>Cache</code>: (Flow run) ShopifyVariantStockLevel<br><code>Cache key</code>: ShopifyVariantStockLevel.[[meta.sku]]<br><code>Append</code>: ON<br><code>Save all pages</code>: OFF</td></tr><tr><td>Load from cache</td><td>These settings should not be changed. For reference, the required settings are:<br><br><code>Cache</code>: (Flow run) ShopifyVariantStockLevel<br><code>Cache key</code>: ShopifyVariantStockLevel.[[meta.sku]]<br><code>Fail on cache miss</code>: OFF<br><code>Load all pages</code>: OFF</td></tr><tr><td>Script</td><td>These settings should not be changed. For reference, the required settings are:<br><br><code>Script</code>: Extract ProductId from URL<br><code>Version</code>: v3 (latest) </td></tr><tr><td>Map</td><td>Generally, field mappings should not be changed. However please refer to the <a href="../installation-guide-shopify-and-virtualstock-supplier/stage-7-review-and-test-the-inventory-process-flow-shopify-to-virtualstock-supplier">installation guidelines</a> for this process flow for any fields that are noted for special attention.<br><br><code>Source instance</code>: None <br><code>Source endpoint</code>: None</td></tr><tr><td>Connector</td><td><p>If instance credentials are provided as part of the blueprint installation, there should be no need to change any settings for this shape. For reference, the required settings are:<br></p><p><code>Source instance</code>: Virtualstock Supplier<br><code>Source endpoint</code>: PATCH Update stock availability<br><code>Variables</code>: Set as <code>Product Rest Id</code> / <code>[[meta.productId]]</code></p></td></tr></tbody></table>

## Scripts used in this process flow

<table><thead><tr><th width="293">Script</th><th>Summary</th></tr></thead><tbody><tr><td>Replace negative qtys with 0</td><td>Replaces negative inventory quantities to zero quantities</td></tr><tr><td>Extract ProductId from URL</td><td>Extracts the URI from product details</td></tr></tbody></table>

## Cross-reference lookups used in this process flow

<table><thead><tr><th width="293">Cross-reference lookup</th><th>Summary</th></tr></thead><tbody><tr><td>SKU Lookup</td><td>Maps <em>Virtualstock Supplier</em> part numbers to Shopify SKUs. You need to update this table with your own values - please see the <a href="../installation-guide-shopify-and-virtualstock-supplier/stage-4-update-cross-reference-lookups-shopify-to-virtualstock-supplier">installation guide</a> for details.</td></tr></tbody></table>
