From b179535b6615ba32872d93593c524db829349a46 Mon Sep 17 00:00:00 2001 From: Chris Nanninga Date: Tue, 30 Sep 2025 13:19:56 -0500 Subject: [PATCH 1/3] Add support for deployed custom B2B Buyer Portal based on env vars --- .env.example | 6 ++- core/b2b/loader.tsx | 15 ++++++ core/b2b/script-production-custom.tsx | 67 +++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 core/b2b/script-production-custom.tsx diff --git a/.env.example b/.env.example index c540804870..06ecdeb438 100644 --- a/.env.example +++ b/.env.example @@ -49,4 +49,8 @@ B2B_API_HOST=https://api-b2b.bigcommerce.com B2B_API_TOKEN= # URL for the local buyer portal instance. Uncomment if developing locally. -# LOCAL_BUYER_PORTAL_HOST=http://localhost:3001 \ No newline at end of file +# LOCAL_BUYER_PORTAL_HOST=http://localhost:3001 + +# Base URL for a production build of Buyer Portal. Uncomment if connecting to a deployed custom Buyer Portal. +# Example URL format: ${PROD_BUYER_PORTAL_URL}/index.js +# PROD_BUYER_PORTAL_URL=https://my-b2b-catalyst.com/b2b/20260101 diff --git a/core/b2b/loader.tsx b/core/b2b/loader.tsx index 58db961435..362508d3f6 100644 --- a/core/b2b/loader.tsx +++ b/core/b2b/loader.tsx @@ -4,11 +4,13 @@ import { auth } from '~/auth'; import { ScriptDev } from './script-dev'; import { ScriptProduction } from './script-production'; +import { ScriptProductionCustom } from './script-production-custom'; const EnvironmentSchema = z.object({ BIGCOMMERCE_STORE_HASH: z.string({ message: 'BIGCOMMERCE_STORE_HASH is required' }), BIGCOMMERCE_CHANNEL_ID: z.string({ message: 'BIGCOMMERCE_CHANNEL_ID is required' }), LOCAL_BUYER_PORTAL_HOST: z.string().url().optional(), + PROD_BUYER_PORTAL_URL: z.string().url().optional(), STAGING_B2B_CDN_ORIGIN: z.string().optional(), }); @@ -17,6 +19,7 @@ export async function B2BLoader() { BIGCOMMERCE_STORE_HASH, BIGCOMMERCE_CHANNEL_ID, LOCAL_BUYER_PORTAL_HOST, + PROD_BUYER_PORTAL_URL, STAGING_B2B_CDN_ORIGIN, } = EnvironmentSchema.parse(process.env); @@ -33,6 +36,18 @@ export async function B2BLoader() { /> ); } + + if (PROD_BUYER_PORTAL_URL) { + return ( + + ); + } const environment = STAGING_B2B_CDN_ORIGIN === 'true' ? 'staging' : 'production'; diff --git a/core/b2b/script-production-custom.tsx b/core/b2b/script-production-custom.tsx new file mode 100644 index 0000000000..38081335fa --- /dev/null +++ b/core/b2b/script-production-custom.tsx @@ -0,0 +1,67 @@ +'use client'; + +import Script from 'next/script'; + +import { useB2BAuth } from './use-b2b-auth'; +import { useB2BCart } from './use-b2b-cart'; + +/** + * Use these vars if using build hashes in B2B Buyer Portal files. + */ +const hashIndex = undefined; +const hashIndexLegacy = undefined; +const hashPolyfills = undefined; + +interface Props { + storeHash: string; + channelId: string; + token?: string; + cartId?: string | null; + prodUrl: string; +} + +export function ScriptProductionCustom({ + cartId, + storeHash, + channelId, + token, + prodUrl, +}: Props) { + useB2BAuth(token); + useB2BCart(cartId); + + return ( + <> + + + + + + ); +} From 8a7d7b856b8529eea8bf20f9b565da5d85e38011 Mon Sep 17 00:00:00 2001 From: Chris Nanninga Date: Tue, 30 Sep 2025 13:47:21 -0500 Subject: [PATCH 2/3] Address feedback on naming conventions --- .env.example | 2 +- core/b2b/loader.tsx | 8 ++++---- core/b2b/script-production-custom.tsx | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.env.example b/.env.example index 06ecdeb438..5e5df27f81 100644 --- a/.env.example +++ b/.env.example @@ -53,4 +53,4 @@ B2B_API_TOKEN= # Base URL for a production build of Buyer Portal. Uncomment if connecting to a deployed custom Buyer Portal. # Example URL format: ${PROD_BUYER_PORTAL_URL}/index.js -# PROD_BUYER_PORTAL_URL=https://my-b2b-catalyst.com/b2b/20260101 +# PROD_BUYER_PORTAL_HOST=https://my-b2b-catalyst.com/b2b/20260101 diff --git a/core/b2b/loader.tsx b/core/b2b/loader.tsx index 362508d3f6..eb4ce6dfc1 100644 --- a/core/b2b/loader.tsx +++ b/core/b2b/loader.tsx @@ -10,7 +10,7 @@ const EnvironmentSchema = z.object({ BIGCOMMERCE_STORE_HASH: z.string({ message: 'BIGCOMMERCE_STORE_HASH is required' }), BIGCOMMERCE_CHANNEL_ID: z.string({ message: 'BIGCOMMERCE_CHANNEL_ID is required' }), LOCAL_BUYER_PORTAL_HOST: z.string().url().optional(), - PROD_BUYER_PORTAL_URL: z.string().url().optional(), + PROD_BUYER_PORTAL_HOST: z.string().url().optional(), STAGING_B2B_CDN_ORIGIN: z.string().optional(), }); @@ -19,7 +19,7 @@ export async function B2BLoader() { BIGCOMMERCE_STORE_HASH, BIGCOMMERCE_CHANNEL_ID, LOCAL_BUYER_PORTAL_HOST, - PROD_BUYER_PORTAL_URL, + PROD_BUYER_PORTAL_HOST, STAGING_B2B_CDN_ORIGIN, } = EnvironmentSchema.parse(process.env); @@ -37,14 +37,14 @@ export async function B2BLoader() { ); } - if (PROD_BUYER_PORTAL_URL) { + if (PROD_BUYER_PORTAL_HOST) { return ( ); } diff --git a/core/b2b/script-production-custom.tsx b/core/b2b/script-production-custom.tsx index 38081335fa..38ffa4e031 100644 --- a/core/b2b/script-production-custom.tsx +++ b/core/b2b/script-production-custom.tsx @@ -8,9 +8,9 @@ import { useB2BCart } from './use-b2b-cart'; /** * Use these vars if using build hashes in B2B Buyer Portal files. */ -const hashIndex = undefined; -const hashIndexLegacy = undefined; -const hashPolyfills = undefined; +const hashIndex = null; +const hashIndexLegacy = null; +const hashPolyfills = null; interface Props { storeHash: string; From 75e9dbfa46f9281b6e8172f986a7c30968676e09 Mon Sep 17 00:00:00 2001 From: Chris Nanninga Date: Wed, 22 Oct 2025 10:10:05 -0500 Subject: [PATCH 3/3] Rename Buyer Portal prod var --- .env.example | 4 ++-- core/b2b/loader.tsx | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.env.example b/.env.example index 5e5df27f81..a6585288c0 100644 --- a/.env.example +++ b/.env.example @@ -52,5 +52,5 @@ B2B_API_TOKEN= # LOCAL_BUYER_PORTAL_HOST=http://localhost:3001 # Base URL for a production build of Buyer Portal. Uncomment if connecting to a deployed custom Buyer Portal. -# Example URL format: ${PROD_BUYER_PORTAL_URL}/index.js -# PROD_BUYER_PORTAL_HOST=https://my-b2b-catalyst.com/b2b/20260101 +# Example URL format: ${PROD_BUYER_PORTAL_BASE_URL}/index.js +# PROD_BUYER_PORTAL_BASE_URL=https://my-b2b-catalyst.com/b2b/20260101 diff --git a/core/b2b/loader.tsx b/core/b2b/loader.tsx index eb4ce6dfc1..d31bdcb0b9 100644 --- a/core/b2b/loader.tsx +++ b/core/b2b/loader.tsx @@ -10,7 +10,7 @@ const EnvironmentSchema = z.object({ BIGCOMMERCE_STORE_HASH: z.string({ message: 'BIGCOMMERCE_STORE_HASH is required' }), BIGCOMMERCE_CHANNEL_ID: z.string({ message: 'BIGCOMMERCE_CHANNEL_ID is required' }), LOCAL_BUYER_PORTAL_HOST: z.string().url().optional(), - PROD_BUYER_PORTAL_HOST: z.string().url().optional(), + PROD_BUYER_PORTAL_BASE_URL: z.string().url().optional(), STAGING_B2B_CDN_ORIGIN: z.string().optional(), }); @@ -19,7 +19,7 @@ export async function B2BLoader() { BIGCOMMERCE_STORE_HASH, BIGCOMMERCE_CHANNEL_ID, LOCAL_BUYER_PORTAL_HOST, - PROD_BUYER_PORTAL_HOST, + PROD_BUYER_PORTAL_BASE_URL, STAGING_B2B_CDN_ORIGIN, } = EnvironmentSchema.parse(process.env); @@ -37,14 +37,14 @@ export async function B2BLoader() { ); } - if (PROD_BUYER_PORTAL_HOST) { + if (PROD_BUYER_PORTAL_BASE_URL) { return ( ); }