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 {
const query = {
filters: {
slug: {
$eq: productSlug,
},
},
populate: {
image: true, image: true,
// isDoorAndPartitionsLayouts:true,
collection_sub_category: { collection_sub_category: {
populate: true, populate: true,
}, },
gallery: { gallery: {
populate: { populate: {
image: true, image: true,
...@@ -37,7 +27,6 @@ export async function getCollectionDetailCategoryData(productSlug) { ...@@ -37,7 +27,6 @@ export async function getCollectionDetailCategoryData(productSlug) {
}, },
}, },
}, },
productTabs: { productTabs: {
populate: { populate: {
companyOverview: { companyOverview: {
...@@ -70,24 +59,12 @@ export async function getCollectionDetailCategoryData(productSlug) { ...@@ -70,24 +59,12 @@ export async function getCollectionDetailCategoryData(productSlug) {
}, },
aboutInfoStone: { aboutInfoStone: {
populate: { populate: {
aboutInfo: { aboutInfo: { populate: "*" },
populate: "*", detailsItem: { populate: "*" },
}, aboutInfoTwo: { populate: "*" },
detailsItem: { detailsItemTwo: { populate: "*" },
populate: "*", bottomInfo: { populate: "*" },
}, video: { populate: "*" },
aboutInfoTwo: {
populate: "*",
},
detailsItemTwo: {
populate: "*",
},
bottomInfo: {
populate: "*",
},
video: {
populate: "*",
},
gallery: { gallery: {
populate: { populate: {
image: true, image: true,
...@@ -95,26 +72,44 @@ export async function getCollectionDetailCategoryData(productSlug) { ...@@ -95,26 +72,44 @@ export async function getCollectionDetailCategoryData(productSlug) {
}, },
}, },
}, },
};
export async function getCollectionDetailCategoryData(productSlug, subCategorySlug) {
try {
if (subCategorySlug) {
const scopedQuery = {
filters: {
slug: { $eq: productSlug },
collection_sub_category: {
slug: { $eq: subCategorySlug },
},
},
populate: POPULATE,
};
// productTabs:{ const scopedResponse = await fetchFromStrapi(
// populate: "*", "/api/collection-detail-categories",
scopedQuery,
);
// }, if (scopedResponse?.data?.length > 0) {
// technicalDetails:{ return scopedResponse.data;
// populate:"*" }
// }, }
// explore:{
// populate:"*" const fallbackQuery = {
// } filters: {
slug: { $eq: productSlug },
}, },
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!