Storefront Entitlements
An entitlement is something a customer holds in Open Shop, such as a membership or a perk. Some entitlements describe the kind of business a rep runs: a dealer who sells boats, a rep who works with medical practices. Mark one of those Show on storefront and your site can tell, for every shopper, which kinds of business their rep runs. You can then change how the site looks for those shoppers and offer them products nobody else can buy.
This tutorial sets that up end to end, then walks through two complete examples.
Assumptions
Section titled “Assumptions”- Your site already loads the Open Shop bundle (see the Quickstart).
<os-referral-tracker>is on every page, in a site-wide layout or footer. Everything in this tutorial depends on it, because it is what works out which rep the shopper is shopping with.- Your reps have referral links that work, so a visit to
https://yourdomain.com/?referral=janeshows “Shopping With” Jane.
What you’ll learn
Section titled “What you’ll learn”- Create an entitlement and send it to the storefront
- Give it to reps by hand or automatically
- Theme your site with CSS,
data-os-show, or a script - Limit products to reps who hold the entitlement and the shoppers they refer
- Add a home-page module that shows each rep’s shoppers the products made for them
How it fits together
Section titled “How it fits together”- A rep holds an entitlement, for example Boats, and it is switched to Show on storefront.
- A shopper arrives through that rep’s link.
os-referral-trackerresolves the rep and publishes their storefront entitlements to the page:OpenShop.referral.current.entitlementsholds[{ code: 'BOATS', name: 'Boats' }].<html>getsdata-os-referral-entitlements="BOATS".data-os-show="referral-entitlement:BOATS"elements appear.
- Products with a purchase eligibility rule for Boats become visible and buyable for that shopper, and a collection of those products fills in.
The entitlement code is the thread through all of it, so choose it with care in step 1.
Step 1: Create the entitlement
Section titled “Step 1: Create the entitlement”1.1 In the Open Shop admin, open Settings › Entitlements and add an entitlement.
1.2 Enter a Code. Codes are uppercase (the admin converts what you type) and cannot be changed once the entitlement exists, which is why your CSS and markup match on it rather than on the name. Use one word with letters, digits, and underscores, such as BOATS or MEDICAL_PRACTICE. The storefront lists codes separated by spaces, so a code with a space in it cannot be matched.
1.3 Enter a Name. This is the label staff see, the name your scripts receive, and the label reps see on products limited to it.
1.4 Switch on Show on storefront and save.
Step 2: Give it to reps
Section titled “Step 2: Give it to reps”There are two ways for a rep to hold an entitlement:
- By hand. Open the rep’s customer page, find the Entitlements card, and click Grant. Use this for a handful of reps, or when staff decide who qualifies.
- With a grant rule. In Settings › Grant Rules, create a rule that grants the entitlement when a customer buys a product, such as a starter kit for that kind of business. Every rep who buys the kit then holds the entitlement for as long as the rule says.
When a grant ends, or you switch Show on storefront off, the entitlement is gone from the storefront on the shopper’s next page view. Open Shop reads it fresh every time rather than caching it.
Step 3: Check that it reaches the storefront
Section titled “Step 3: Check that it reaches the storefront”Open your site through a rep who holds the entitlement, for example https://yourdomain.com/?referral=jane, then open your browser’s developer console and run:
OpenShop.referral.current?.entitlements;// [{ code: 'BOATS', name: 'Boats' }]
document.documentElement.dataset.osReferralEntitlements;// 'BOATS'An empty array means the rep holds no storefront entitlements: check the grant on their customer page and the switch in Settings. undefined for the first line means there is no referral to read, so run OpenShop.referral.current on its own: undefined there means the referral has not resolved, which usually means the tracker is missing from the page, and null means Open Shop found no referrer for this visit.
Step 4: Theme your site
Section titled “Step 4: Theme your site”You have three tools, from no code to full control. Use whichever fits each change.
CSS against the <html> attribute
Section titled “CSS against the <html> attribute”Best for colours, images, and other visual swaps. Match a single code with ~=, which checks one word of a space-separated list, so it still matches a rep who holds several:
html[data-os-referral-entitlements~='BOATS'] .hero { background-image: url('/images/hero-boats.jpg');}Codes are uppercase and attribute selectors are case-sensitive, so write 'BOATS' exactly as the code appears in the admin. See data-os-referral-entitlements for the details.
data-os-show and data-os-hide
Section titled “data-os-show and data-os-hide”Best for whole blocks of content that only make sense for one kind of rep. Build each block in your design and mark it with the code it belongs to:
<section data-os-show="referral-entitlement:BOATS">Ask your dealer about this season's boats.</section><section data-os-hide="referral-entitlement:BOATS">Find a dealer near you.</section>The code here is matched case-insensitively. A data-os-hide block stays visible while the referral is still resolving, and a data-os-show block stays hidden until it resolves. That holds once the bundle runs; before it does, the browser paints your markup as written, so add the one-line CSS rule that hides every data-os-show block until then. See referral-entitlement:CODE.
A script on referral:change
Section titled “A script on referral:change”Best when the change depends on more than one code, or needs the entitlement’s name. This example fills a label in your markup, such as <p class="rep-specialties" hidden></p>. The referral resolves after the page loads and can change later, so handle both the current value and the event:
<script> (window.OpenShopQ ??= []).push((os) => { function applyTheme(referral) { const entitlements = referral?.entitlements ?? []; const label = document.querySelector('.rep-specialties'); if (!label) return; label.textContent = entitlements.map((entitlement) => entitlement.name).join(' · '); label.hidden = entitlements.length === 0; }
if (os.referral.current !== undefined) applyTheme(os.referral.current); os.on('referral:change', applyTheme); });</script>referral is null when nobody referred the shopper, and entitlements is always an array, so referral?.entitlements ?? [] covers every case.
What to expect while the page loads
Section titled “What to expect while the page loads”The theme is applied in the browser once the tracker resolves the referral, so the first paint of a page uses your default styles and the theme lands a moment later. On later page views the referral resolves quickly, but the gap never disappears completely. Make the default look complete on its own, and theme things that can swap in place, such as colours, images, and text, rather than layout that would make the page jump.
Step 5: Offer products only those reps’ shoppers can buy
Section titled “Step 5: Offer products only those reps’ shoppers can buy”Theming only changes what the page shows. Anyone can read your markup and CSS, so use purchase eligibility rules for anything that decides who may buy.
5.1 Open the product in the Open Shop admin and find the Purchase Eligibility card.
5.2 Click New rule and build these two conditions, joined by OR:
- Customer · Is · Entitlement · Boats
- Their referrer · Is · Entitlement · Boats
5.3 Set THEN to Can purchase this product, check the In plain English summary, and save the rule.
The first condition lets reps who hold Boats buy the product themselves. The second lets the shoppers they refer buy it. Once a product has any Can rule, only customers who match one can buy it, and everyone else does not see it in product lists or collections.
Reps see the same rule when they pick favorites for their rep site under My Site: a product it unlocks is tagged Boats only, and the picker offers a chip for each storefront entitlement the rep holds. Tags come from Can rules with an Is · Entitlement condition; Cannot rules are ignored.
Shoppers who arrive through a rep’s ?referral= link see these products on their very first page view: when the referral resolves, the product components refetch once and the products appear without a reload.
Step 6: Add an entitlement module to your home page
Section titled “Step 6: Add an entitlement module to your home page”Give each storefront entitlement its own collection and show it on the home page to the shoppers it is for.
6.1 Create one collection per entitlement, for example boats, and add that entitlement’s products to it.
A collection only returns the products the current shopper may buy, and every product in this one carries the rule from step 5. So the collection is full for a Boats rep’s shoppers and empty for everyone else, and os-product-list hides the chip of an empty collection. Your shop page needs no change.
6.2 Add a section per entitlement to the home page. The simplest version links to the shop page, opened on that collection:
<section data-os-show="referral-entitlement:BOATS"> <h2>Boats from your dealer</h2> <a href="/shop/?collection=boats">Shop boats</a></section>6.3 To show the products right on the home page, give each section an empty container naming its collection and its code:
<section data-os-show="referral-entitlement:BOATS"> <h2>Boats from your dealer</h2> <div class="entitlement-products" data-collection="boats" data-entitlement="BOATS"></div></section>Then fill every container with os-single-product cards for the first products in its collection. The script only asks for collections the rep’s entitlements can fill, and ignores a response that arrives after the referral has changed:
<script> (window.OpenShopQ ??= []).push((os) => { let generation = 0;
async function fillContainer(container, currentGeneration) { const collectionSlug = container.dataset.collection; const page = await os.products.paged({ page: 1, perPage: 8, collectionSlug }); if (currentGeneration !== generation) return; for (const product of page.results) { const card = document.createElement('os-single-product'); card.setAttribute('product-slug', product.slug); card.setAttribute('product-url-prefix', '/products'); container.append(card); } }
function fillModules(referral) { generation += 1; const codes = (referral?.entitlements ?? []).map((entitlement) => entitlement.code); for (const container of document.querySelectorAll('.entitlement-products')) { container.replaceChildren(); if (codes.includes(container.dataset.entitlement)) fillContainer(container, generation); } }
if (os.referral.current !== undefined) fillModules(os.referral.current); os.on('referral:change', fillModules); });</script>Style the container as a grid in your own CSS. os-product-list is the wrong tool for this module: it shows the whole catalog with collection chips, while the module shows one fixed collection.
Example: a dealership
Section titled “Example: a dealership”A store supplies dealerships. Some dealers sell boats, some sell cars, and a few sell both. Each kind of dealer should get its own hero image, its own home-page module, and its own parts catalog.
| What | Boats | Cars |
|---|---|---|
| Entitlement | Code BOATS, name Boats, Show on storefront on | Code CARS, name Cars, Show on storefront on |
| How dealers get it | Grant rule on the Boat dealer starter kit product | Grant rule on the Car dealer starter kit product |
| Product rule | Customer Is Boats OR Their referrer Is Boats → Can | Customer Is Cars OR Their referrer Is Cars → Can |
| Collection | boats: hulls, trailers, marine electronics | cars: detailing kits, floor mats, roof racks |
| Home-page module | data-os-show="referral-entitlement:BOATS", boats | data-os-show="referral-entitlement:CARS", cars |
The hero swaps by CSS. A dealer who holds both gets the rule that comes last in your stylesheet, so put the one you want to win at the bottom:
html[data-os-referral-entitlements~='BOATS'] .hero { background-image: url('/images/hero-marina.jpg');}
html[data-os-referral-entitlements~='CARS'] .hero { background-image: url('/images/hero-showroom.jpg');}A shopper who follows a boat dealer’s link sees the marina hero, the Boats module, and the Boats chip on the shop page. A shopper with no dealer sees the default hero and a “Find a dealer” block marked data-os-hide="referral-entitlement:BOATS,referral-entitlement:CARS". A dealer who sells both shows both modules, one after the other.
Example: industries
Section titled “Example: industries”A wellness store has reps who specialise in an industry: some work with sports teams and gyms, others with medical practices. Their shoppers should see that industry’s colours and the products made for it, while every rep keeps selling the regular catalog.
| What | Sports | Medical |
|---|---|---|
| Entitlement | Code SPORTS, name Sports, Show on storefront on | Code MEDICAL, name Medical, Show on storefront on |
| How reps get it | Staff grant it from the rep’s customer page after review | Staff grant it from the rep’s customer page after review |
| Product rule | Customer Is Sports OR Their referrer Is Sports → Can | Customer Is Medical OR Their referrer Is Medical → Can |
| Collection | sports: team recovery packs, bulk hydration | medical: practitioner packs, clinic display kits |
Here the theme is one accent colour, which every themed element picks up through a custom property:
:root { --brand-accent: #4a5568;}
html[data-os-referral-entitlements~='SPORTS'] { --brand-accent: #d9480f;}
html[data-os-referral-entitlements~='MEDICAL'] { --brand-accent: #1971c2;}
.button-primary,.section-heading { color: var(--brand-accent);}The “Shopping with” line names the industry without a script, using a pair of show blocks:
<span data-os-show="referral">Shopping with <span data-os-text="referral.displayName"></span></span><span data-os-show="referral-entitlement:SPORTS">· Sports nutrition specialist</span><span data-os-show="referral-entitlement:MEDICAL">· Medical practice specialist</span>Because the regular catalog has no eligibility rules, every shopper still sees it. The sports and medical collections and their modules appear only for the shoppers of reps in that industry.
Things to know
Section titled “Things to know”- The tracker is required. Without
os-referral-trackeron the page, no referral resolves,<html>never gets the attribute, anddata-os-show="referral-entitlement:…"blocks stay hidden. Products limited to a referrer’s entitlement depend on it too, because the tracker is what records a?referral=link. - The theme arrives just after the first paint. Keep your default design complete and theme what can swap in place.
- Only storefront entitlements reach the page. A rep’s other entitlements never appear in
entitlements, in the attribute, or indata-os-showmatches. - Theming is not access control. Hiding markup does not stop anyone reading it. Decide who can buy with purchase eligibility rules.
- Codes are fixed, names are not. Branch on
codein scripts and CSS, and only displayname.