Shopify B2B: supplying the company location
On a Shopify B2B store that restricts products to a B2B catalog, Fast Simon needs the buyer's company location to resolve which catalogs that buyer is entitled to.
Without it the buyer is evaluated as an ordinary shopper in their market, and the products restricted to their catalog are filtered out of everything the SDK returns: search, collections, recommendations and popular products alike. On a store whose entire catalog is B2B-restricted, that is an empty page for a buyer who should see products.
Supplying it
Set companyLocationProvider on __fast_options. Shopify exposes the buyer's active location to
Liquid as customer.current_location, a
company_location object, so a
theme can render its id and hand it back:
<script>
var __fast_options = __fast_options || {};
{%- comment -%} Assigned unconditionally: on a theme that navigates client-side, leaving a
previous page's value in place would keep sending a location the shopper no longer has. {%- endcomment -%}
window.fsCompanyLocation = {% if customer and customer.b2b? and customer.current_location %}{{ customer.current_location.id }}{% else %}undefined{% endif %};
__fast_options.companyLocationProvider = function () {
return window.fsCompanyLocation;
};
</script>
Set this before the SDK initializes. Fast Simon sends the value as the company_location_context
request parameter.
If your bundle predates companyLocationProvider
Set the value directly on window.__FAST_CUSTOMER_DETAILS instead. Every Fast Simon storefront
bundle reads it, including versions released before the provider existed, so this works today on any
bundle you already have:
{% if customer and customer.b2b? and customer.current_location %}
<script>
window.__FAST_CUSTOMER_DETAILS = {
customer_current_location: "{{ customer.current_location.id }}"
};
</script>
{% endif %}
Place it above the Fast Simon script tag and render it per page, for the same reasons as above. Where both are present the provider wins, so you can add the provider later without removing this first.
Value format
Liquid renders the location id as a number, so the provider example above hands back a number
while the __FAST_CUSTOMER_DETAILS example quotes it and hands back a string. Both are accepted, and
so is the gid://shopify/CompanyLocation/... string form you get if you source the location from the
Storefront or Admin GraphQL API instead. Fast Simon trims the value and sends it as-is, so pick
whichever is convenient in your theme.
Two behaviors worth knowing
The provider is called on every request, not once at initialization. A buyer who switches company location mid-session, or who masquerades between companies, is picked up as soon as your code updates the value. Nothing needs to be re-initialized and the page does not need to reload.
While a provider is configured it is authoritative. Return undefined for visitors who are not
buying on behalf of a company; Fast Simon will not substitute a location for them. A provider that
throws, or that is set to something other than a function, is ignored with a one-time console
warning.