{name} diff --git a/src/pages/produkt/[slug].tsx b/src/pages/produkt/[slug].tsx index 711da637c..395ef2c70 100644 --- a/src/pages/produkt/[slug].tsx +++ b/src/pages/produkt/[slug].tsx @@ -48,11 +48,21 @@ const Produkt: NextPage = ({ export default withRouter(Produkt); export const getServerSideProps: GetServerSideProps = async ({ - query: { id }, + params, + query, + res, }) => { + // Handle legacy URLs with ID parameter by removing it + if (query.id) { + res.setHeader('Location', `/produkt/${params?.slug}`); + res.statusCode = 301; + res.end(); + return { props: {} }; + } + const { data, loading, networkStatus } = await client.query({ query: GET_SINGLE_PRODUCT, - variables: { id }, + variables: { slug: params?.slug }, }); return { diff --git a/src/utils/gql/GQL_QUERIES.ts b/src/utils/gql/GQL_QUERIES.ts index b3edca9dd..e39955232 100644 --- a/src/utils/gql/GQL_QUERIES.ts +++ b/src/utils/gql/GQL_QUERIES.ts @@ -1,8 +1,8 @@ import { gql } from '@apollo/client'; export const GET_SINGLE_PRODUCT = gql` - query Product($id: ID!) { - product(id: $id, idType: DATABASE_ID) { + query Product($slug: ID!) { + product(id: $slug, idType: SLUG) { id databaseId averageRating From 443107451b07be35bbfec9b0bc278f1a96c90628 Mon Sep 17 00:00:00 2001 From: w3bdesign <45217974+w3bdesign@users.noreply.github.com> Date: Sat, 15 Feb 2025 22:51:53 +0100 Subject: [PATCH 2/2] Fix npm run build --- .../AlgoliaSearch/SearchResults.component.tsx | 4 ---- .../Product/DisplayProducts.component.tsx | 18 ++++++------------ .../User/UserRegistration.component.tsx | 4 ++-- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/src/components/AlgoliaSearch/SearchResults.component.tsx b/src/components/AlgoliaSearch/SearchResults.component.tsx index a3eb72629..968b0458c 100644 --- a/src/components/AlgoliaSearch/SearchResults.component.tsx +++ b/src/components/AlgoliaSearch/SearchResults.component.tsx @@ -1,5 +1,4 @@ import Link from 'next/link'; - import { trimmedStringToLength } from '@/utils/functions/functions'; interface ISearchResultProps { @@ -10,7 +9,6 @@ interface ISearchResultProps { sale_price: string; on_sale: boolean; short_description: string; - objectID: number; slug: string; }; } @@ -24,7 +22,6 @@ interface ISearchResultProps { * @param {string} sale_price Price when on sale * @param {boolean} on_sale Is the product on sale? True or false * @param {string} short_description Short description of product - * @param {number} objectID ID of product } */ const SearchResults = ({ @@ -35,7 +32,6 @@ const SearchResults = ({ sale_price, on_sale, short_description, - objectID, }, }: ISearchResultProps) => { return ( diff --git a/src/components/Product/DisplayProducts.component.tsx b/src/components/Product/DisplayProducts.component.tsx index 738cbab84..cb2aa13ce 100644 --- a/src/components/Product/DisplayProducts.component.tsx +++ b/src/components/Product/DisplayProducts.component.tsx @@ -23,7 +23,6 @@ interface Variations { interface RootObject { __typename: string; - databaseId: number; name: string; onSale: boolean; slug: string; @@ -55,7 +54,6 @@ const DisplayProducts = ({ products }: IDisplayProductsProps) => ( {products ? ( products.map( ({ - databaseId, name, price, regularPrice, @@ -78,9 +76,7 @@ const DisplayProducts = ({ products }: IDisplayProductsProps) => ( return (
@@ -123,9 +119,7 @@ const DisplayProducts = ({ products }: IDisplayProductsProps) => (