Search taxonomies by permalinks instead of IDs

This commit is contained in:
tniezg 2021-08-26 15:50:52 +02:00
parent 25fd21e69a
commit 2f9e90ed32
4 changed files with 13 additions and 13 deletions

View File

@ -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

View File

@ -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.
---

View File

@ -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
),
})

View File

@ -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',