diff --git a/.env.example b/.env.example index c540804870..a6585288c0 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_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 58db961435..d31bdcb0b9 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_BASE_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_BASE_URL, STAGING_B2B_CDN_ORIGIN, } = EnvironmentSchema.parse(process.env); @@ -33,6 +36,18 @@ export async function B2BLoader() { /> ); } + + if (PROD_BUYER_PORTAL_BASE_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..38ffa4e031 --- /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 = null; +const hashIndexLegacy = null; +const hashPolyfills = null; + +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 ( + <> + + + + + + ); +}