diff --git a/framework/spree/.env.template b/framework/spree/.env.template index 7d2b52026..a17269657 100644 --- a/framework/spree/.env.template +++ b/framework/spree/.env.template @@ -10,8 +10,8 @@ NEXT_PUBLIC_SPREE_CART_COOKIE_NAME=spree_cart_token NEXT_PUBLIC_SPREE_CART_COOKIE_EXPIRE=7 NEXT_PUBLIC_SPREE_IMAGE_HOST=http://localhost:4000 NEXT_PUBLIC_SPREE_ALLOWED_IMAGE_DOMAIN=localhost -NEXT_PUBLIC_SPREE_CATEGORIES_TAXONOMY_ID=1 -NEXT_PUBLIC_SPREE_BRANDS_TAXONOMY_ID=27 +NEXT_PUBLIC_SPREE_CATEGORIES_TAXONOMY_PERMALINK=categories +NEXT_PUBLIC_SPREE_BRANDS_TAXONOMY_PERMALINK=brands NEXT_PUBLIC_SPREE_SHOW_SINGLE_VARIANT_OPTIONS=false NEXT_PUBLIC_SPREE_LAST_UPDATED_PRODUCTS_PRERENDER_COUNT=10 NEXT_PUBLIC_SPREE_PRODUCT_PLACEHOLDER_IMAGE_URL=/product-img-placeholder.svg diff --git a/framework/spree/README.md b/framework/spree/README.md index 2a47b9e16..305ef53f5 100644 --- a/framework/spree/README.md +++ b/framework/spree/README.md @@ -10,7 +10,7 @@ Start by following the [instructions for setting up NextJS Commerce][2]. Afterwards, configure NextJS Commerce to use the Spree Provider. Create a `.env.local` file in the root of the project. Its contents must be based on `framework/spree/.env.template`. -`NEXT_PUBLIC_SPREE_CATEGORIES_TAXONOMY_ID` and `NEXT_PUBLIC_SPREE_BRANDS_TAXONOMY_ID` rely on IDs generated by Spree and need to be changed from the defaults. Go to the Spree admin panel and create Categories and Brands taxonomies if they don't exist and copy their IDs into `.env.local` in NextJS Commerce. The values of the other environment variables can be copied from `framework/spree/.env.template` as is. +`NEXT_PUBLIC_SPREE_CATEGORIES_TAXONOMY_PERMALINK` and `NEXT_PUBLIC_SPREE_BRANDS_TAXONOMY_PERMALINK` rely on taxonomies' permalinks in Spree. Go to the Spree admin panel and create Categories and Brands taxonomies if they don't exist and copy their permalinks into `.env.local` in NextJS Commerce. The values of the other environment variables can be copied from `framework/spree/.env.template` as is. --- diff --git a/framework/spree/api/operations/get-site-info.ts b/framework/spree/api/operations/get-site-info.ts index 456c62465..5b4ba4bf7 100644 --- a/framework/spree/api/operations/get-site-info.ts +++ b/framework/spree/api/operations/get-site-info.ts @@ -68,14 +68,12 @@ export default function getSiteInfoOperation({ userConfig ) - // Fetch first and level taxons - - const createVariables = (parentId: string): SpreeSdkVariables => ({ + const createVariables = (parentPermalink: string): SpreeSdkVariables => ({ methodPath: 'taxons.list', arguments: [ { filter: { - parent_id: parentId, + parent_permalink: parentPermalink, }, }, ], @@ -93,7 +91,7 @@ export default function getSiteInfoOperation({ SpreeSdkVariables >('__UNUSED__', { variables: createVariables( - requireConfigValue('categoriesTaxonomyId') as string + requireConfigValue('categoriesTaxonomyPermalink') as string ), }) @@ -106,7 +104,7 @@ export default function getSiteInfoOperation({ SpreeSdkVariables >('__UNUSED__', { variables: createVariables( - requireConfigValue('brandsTaxonomyId') as string + requireConfigValue('brandsTaxonomyPermalink') as string ), }) diff --git a/framework/spree/isomorphic-config.ts b/framework/spree/isomorphic-config.ts index b665fcd4f..1fb5f3485 100644 --- a/framework/spree/isomorphic-config.ts +++ b/framework/spree/isomorphic-config.ts @@ -12,8 +12,10 @@ const isomorphicConfig = { process.env.NEXT_PUBLIC_SPREE_CART_COOKIE_EXPIRE ), imageHost: process.env.NEXT_PUBLIC_SPREE_IMAGE_HOST, - categoriesTaxonomyId: process.env.NEXT_PUBLIC_SPREE_CATEGORIES_TAXONOMY_ID, - brandsTaxonomyId: process.env.NEXT_PUBLIC_SPREE_BRANDS_TAXONOMY_ID, + categoriesTaxonomyPermalink: + process.env.NEXT_PUBLIC_SPREE_CATEGORIES_TAXONOMY_PERMALINK, + brandsTaxonomyPermalink: + process.env.NEXT_PUBLIC_SPREE_BRANDS_TAXONOMY_PERMALINK, showSingleVariantOptions: process.env.NEXT_PUBLIC_SPREE_SHOW_SINGLE_VARIANT_OPTIONS === 'true', lastUpdatedProductsPrerenderCount: validateProductsPrerenderCount( @@ -36,8 +38,8 @@ export default forceIsomorphicConfigValues( 'cartCookieName', 'cartCookieExpire', 'imageHost', - 'categoriesTaxonomyId', - 'brandsTaxonomyId', + 'categoriesTaxonomyPermalink', + 'brandsTaxonomyPermalink', 'showSingleVariantOptions', 'lastUpdatedProductsPrerenderCount', 'productPlaceholderImageUrl',