Commit e220abc6 by Ravindra Kanojiya

updated slug same name

1 parent 44372be9
...@@ -37,15 +37,15 @@ const ProductPage = ({ productData, cataloguesData }) => { ...@@ -37,15 +37,15 @@ const ProductPage = ({ productData, cataloguesData }) => {
{ href: "/", label: "Collections" }, { href: "/", label: "Collections" },
{ {
href: `/collections/${category}`, href: `/collections/${category}`,
label: category.replace(/-/g, " "), label: category?.replace(/-/g, " ") || "",
}, },
{ {
href: `/collections/${category}/${subCategoryData.slug}`, href: `/collections/${category}/${subCategoryData?.slug ?? subCategorySlug ?? ""}`,
label: subCategoryData.title, label: subCategoryData?.title ?? subCategorySlug?.replace(/-/g, " ") ?? "",
}, },
{ {
href: router.asPath, href: router.asPath,
label: productData.title, label: productData?.title ?? "",
}, },
]; ];
...@@ -129,9 +129,9 @@ export default ProductPage; ...@@ -129,9 +129,9 @@ export default ProductPage;
/* ---------- SSR ---------- */ /* ---------- SSR ---------- */
export async function getServerSideProps({ params }) { export async function getServerSideProps({ params }) {
try { try {
const { productSlug } = params; const { productSlug, subCategory } = params;
const productData = await getCollectionDetailCategoryData(productSlug); const productData = await getCollectionDetailCategoryData(productSlug, subCategory);
const cataloguesData = await getCataloguesBySlug(); const cataloguesData = await getCataloguesBySlug();
if (!productData || productData.length === 0) { if (!productData || productData.length === 0) {
......
import { fetchFromStrapi } from "./api"; import { fetchFromStrapi } from "./api";
export async function getCollectionDetailCategoryData(productSlug) { const POPULATE = {
try { image: true,
const query = { collection_sub_category: {
filters: { populate: true,
slug: { },
$eq: productSlug, gallery: {
populate: {
image: true,
},
},
aboutInfo: {
populate: true,
},
video: {
populate: {
video: true,
},
},
exploreProducts: {
populate: {
item: {
populate: {
image: true,
}, },
}, },
populate: { },
image: true, },
// isDoorAndPartitionsLayouts:true, productTabs: {
collection_sub_category: { populate: {
populate: true, companyOverview: {
}, populate: {
items: {
gallery: { populate: {
populate: { image: true,
image: true, },
}, },
}, },
aboutInfo: { },
populate: true, videoSection: {
populate: {
video: true,
}, },
video: { },
populate: { aboutInfo: true,
video: true, technicalDetails: {
}, populate: {
image: true,
details: true,
}, },
exploreProducts: { },
populate: { gallery: {
item: { populate: {
populate: { image: true,
image: true,
},
},
},
}, },
},
productTabs: { },
populate: { },
companyOverview: { aboutInfoStone: {
populate: { populate: {
items: { aboutInfo: { populate: "*" },
populate: { detailsItem: { populate: "*" },
image: true, aboutInfoTwo: { populate: "*" },
}, detailsItemTwo: { populate: "*" },
}, bottomInfo: { populate: "*" },
}, video: { populate: "*" },
}, gallery: {
videoSection: { populate: {
populate: { image: true,
video: true,
},
},
aboutInfo: true,
technicalDetails: {
populate: {
image: true,
details: true,
},
},
gallery: {
populate: {
image: true,
},
},
},
}, },
aboutInfoStone: { },
populate: { },
aboutInfo: { },
populate: "*", };
},
detailsItem: { export async function getCollectionDetailCategoryData(productSlug, subCategorySlug) {
populate: "*", try {
}, if (subCategorySlug) {
aboutInfoTwo: { const scopedQuery = {
populate: "*", filters: {
}, slug: { $eq: productSlug },
detailsItemTwo: { collection_sub_category: {
populate: "*", slug: { $eq: subCategorySlug },
},
bottomInfo: {
populate: "*",
},
video: {
populate: "*",
},
gallery: {
populate: {
image: true,
},
},
}, },
}, },
populate: POPULATE,
};
const scopedResponse = await fetchFromStrapi(
"/api/collection-detail-categories",
scopedQuery,
);
// productTabs:{ if (scopedResponse?.data?.length > 0) {
// populate: "*", return scopedResponse.data;
}
}
// }, const fallbackQuery = {
// technicalDetails:{ filters: {
// populate:"*" slug: { $eq: productSlug },
// },
// explore:{
// populate:"*"
// }
}, },
populate: POPULATE,
}; };
const response = await fetchFromStrapi( const fallbackResponse = await fetchFromStrapi(
"/api/collection-detail-categories", "/api/collection-detail-categories",
query, fallbackQuery,
); );
return response?.data || []; return fallbackResponse?.data || [];
} catch (error) { } catch (error) {
console.error("Product fetch error:", error); console.error("Product fetch error:", error);
return []; return [];
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!