When safety stock is enabled in Charlie, your theme needs to display sellable inventory instead of native Shopify availability. This guide shows how to integrate Charlie’s inventory metafields into any Shopify theme.Documentation Index
Fetch the complete documentation index at: https://partners.usecharlie.ai/llms.txt
Use this file to discover all available pages before exploring further.
Reference implementation
See a complete working example in our reference theme repository based on Shopify’s Horizon theme.
Who this is for
- Theme developers customizing themes for Charlie users
- Agencies building or modifying Shopify themes
- Merchants with custom themes who want accurate storefront availability
Finding your app namespace
Charlie’s metafields use a unique namespace per app installation. Before making theme changes, you need to identify your namespace.Navigate to metafield definitions
Go to Shopify Admin, then Settings, then Custom data, then Metafields.
Find the Charlie metafield
Look for a metafield with key containing
inventory.available from Charlie.The namespace is unique per app installation. Example:
app--303723511809--inventoryMetafields reference
Charlie writes these metafields when safety stock is enabled.Shop-level
| Key | Type | Purpose |
|---|---|---|
safety_stock_enabled | boolean | Master switch that indicates if safety stock is active |
Variant-level
| Key | Type | Purpose |
|---|---|---|
available | boolean | True if sellable quantity is greater than 0 |
fulfillable | integer | Total sellable quantity across fulfillment locations |
Product-level
| Key | Type | Purpose |
|---|---|---|
available | boolean | True if any variant has sellable quantity greater than 0 |
first_available_variant | variant_reference | First variant with sellable quantity greater than 0 |
fulfillable | integer | Total fulfillable inventory across all variants, adjusted for safety stock |
The
fulfillable and available metafields are publicly accessible via the Storefront API under the charlie_inventory namespace. You can use them to create smart collections based on inventory availability — for example, a “Low Stock” or “In Stock” collection that updates automatically.Implementation patterns
Basic setup
At the start of any file that needs safety stock awareness, define the namespace and check if safety stock is enabled.YOUR_APP_ID with your actual app ID from the namespace you identified earlier.
We recommend checking
safety_stock_enabled before applying overrides. This ensures your theme gracefully handles scenarios where Charlie is uninstalled or safety stock is disabled. Without this check, stale metafield values could cause incorrect availability displays.Product availability
Use this pattern on collection pages and product cards to determine if a product should show as available.Variant availability
Use this pattern on product detail pages and variant pickers to determine if a specific variant is available.First available variant
Use this pattern when linking to products to ensure the URL points to a sellable variant.Variant JSON for JavaScript
When themes output variant JSON for JavaScript consumption, theavailable property must reflect sellable inventory.
The condition checks for both boolean
true and string 'true' because Liquid metafield values may be returned as strings in some contexts.Sold Out badges
Use this pattern on product cards to correctly show Sold Out badges based on sellable inventory.Price display
When showing prices, usefirst_available_variant to display the price of a sellable variant rather than an unavailable one.
Files to modify
The specific files depend on your theme structure. Here are common files that typically need updates.| File pattern | What to change |
|---|---|
| Product card snippets | Product availability for collection pages |
| Variant picker snippets | Variant availability and JSON override |
| Swatch components | Swatch availability states |
| Buy buttons | Add to cart button enabled/disabled state |
| Quick add modals | Availability in modal variant selectors |
| Price snippets | Selected variant for price display |
| Badge/label snippets | Sold Out badge visibility |
| Inventory display | Stock status based on sellable quantity |
What to ignore
Local pickup availability uses total stock at physical locations and is unaffected by safety stock reserves. No changes are needed for pickup location availability displays.
Testing checklist
Enable safety stock
In Charlie, enable safety stock with “Block orders” mode for the clearest testing.
Create a test rule
Create a rule with 100% reserve on a test product so it shows zero sellable inventory.
Test variant switching
On the product page, switch between variants and verify availability updates correctly.
Troubleshooting
Metafield returns nil
Metafield returns nil
The namespace in your theme code does not match your Charlie installation’s app ID. Double-check the namespace in Shopify Admin under Settings, then Custom data, then Metafields, then Variants.
Availability not updating on variant switch
Availability not updating on variant switch
The variant JSON replacement pattern may not be catching all formats. Ensure you are replacing both
"available":false (no space) and "available": false (with space) as Shopify may output either format.Theme does not revert when safety stock is disabled
Theme does not revert when safety stock is disabled
Your code may be missing the
safety_stock_enabled check. All safety stock logic should be wrapped in a conditional that first checks if safety stock is enabled at the shop level.Quick add shows different availability than product page
Quick add shows different availability than product page
Quick add modals often have separate variant picker implementations. Ensure both the main product page and quick add modal snippets include the safety stock override logic.
Incorrect availability after uninstalling Charlie
Incorrect availability after uninstalling Charlie
When Charlie is uninstalled, inventory metafields are deleted. If your theme only checks for
!= nil, it will correctly fall back to native Shopify behavior. However, if you cached or hardcoded values, clear your theme cache and verify the metafield checks are working.