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
Namespace and metafields
Theme integration uses the app-reserved namespaceapp--{APP_ID}--inventory. The full list of keys, types, and how to find your app ID is in Metafields reference.
For non-theme integrations (product feeds, smart collections, storefront filters), use the public
charlie_inventory namespace instead. See Metafields reference.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.Related
Metafields reference
All Charlie metafields and namespaces
App integrations
Wire product feeds, search, and filter apps
Safety Stock
Configure safety stock rules and settings
Inventory Overview
How Charlie syncs inventory data