From 8264e95b3b29a6eeb65d4224d469518d5c0b4879 Mon Sep 17 00:00:00 2001
From: salaheddineZidani <salaheddine.zidani@marketingconfort.com>
Date: Fri, 27 Sep 2024 13:25:11 +0100
Subject: [PATCH 1/4] Condition for displaying product details

---
 .../products/details/[key]/page.tsx           | 42 ++++++++++++++++++-
 .../product-details/product-description.tsx   | 22 +++++-----
 src/shared/api/product.ts                     |  2 +-
 3 files changed, 54 insertions(+), 12 deletions(-)

diff --git a/src/app/(layout-1)/products/details/[key]/page.tsx b/src/app/(layout-1)/products/details/[key]/page.tsx
index 77e3e49..2966a87 100644
--- a/src/app/(layout-1)/products/details/[key]/page.tsx
+++ b/src/app/(layout-1)/products/details/[key]/page.tsx
@@ -8,6 +8,7 @@ import products from "@/data/product-database";
 import Product from "@/models/Product.model";
 import { Typography } from "@mui/material";
 import { getProductById, getProductByNameUri } from "@/shared/api/product";
+import { ProductType } from "@/shared/types/product";
 
 export const metadata: Metadata = {
   title: "Product Details - Bazaar Next.js E-commerce Template",
@@ -52,12 +53,51 @@ export default async function ProductDetails({ params }: { params: any }) {
       return null;
     }
 
+    if (productData.productType === ProductType.SIMPLE) {
+      if (productData.isDraft) {
+        notFound();
+        return null;
+      }
+      if (productData.stockWebConfig?.quantity === undefined || productData.stockWebConfig?.quantity === null || productData.stockWebConfig?.quantity <= 0) {
+        notFound();
+        return null;
+      }
+      if (!productData.publishWeb) {
+        notFound();
+        return null;
+      }
+    }
+
+    else if (productData.productType === ProductType.VARIABLE) {
+      if (productData.isDraft) {
+        notFound();
+        return null;
+      }
+      if (productData.stockWebConfig?.quantity === undefined || productData.stockWebConfig?.quantity === null || productData.stockWebConfig?.quantity <= 0) {
+        notFound();
+        return null;
+      }
+      if (!productData.publishWeb) {
+        notFound();
+        return null;
+      }
+
+      if (productData.variations) {
+        for (const variation of productData.variations) {
+          if (!variation.publishWeb) {
+            notFound();
+            return null;
+          }
+        }
+      }
+    }
+
     const relatedProducts = getRelatedProducts();
     const frequentlyBought = getFrequentlyBought();
 
     return (
       <>
-          
+
 
         <ProductDetailsPageView
           product={productData}
diff --git a/src/sections/product-details/product-description.tsx b/src/sections/product-details/product-description.tsx
index 13f887b..7f7e670 100644
--- a/src/sections/product-details/product-description.tsx
+++ b/src/sections/product-details/product-description.tsx
@@ -16,16 +16,18 @@ export default function ProductDescription({ product }: Props) {
           UGS : <H6>{product.ugs}</H6>
         </FlexBox>
 
-        <FlexBox alignItems="center" gap={1} mb={2}>
-          <span style={{ fontWeight: 'bold' }}>Catégorie:</span>
-          <div style={{ display: 'flex', flexWrap: 'wrap', gap: '10px' }}>
-            {product.categoryNames.map((category, index) => (
-              <span key={index} style={{ padding: '4px 8px', backgroundColor: '#f0f0f0', borderRadius: '5px', fontSize: '16px' }}>
-                {category}
-              </span>
-            ))}
-          </div>
-        </FlexBox>
+        {product.categoryNames &&
+          <FlexBox alignItems="center" gap={1} mb={2}>
+            <span style={{ fontWeight: 'bold' }}>Catégories:</span>
+            <div style={{ display: 'flex', flexWrap: 'wrap', gap: '10px' }}>
+              {product.categoryNames.map((category, index) => (
+                <span key={index} style={{ padding: '4px 8px', backgroundColor: '#f0f0f0', borderRadius: '5px', fontSize: '16px' }}>
+                  {category}
+                </span>
+              ))}
+            </div>
+          </FlexBox>
+        }
       </div>
     </div>
   );
diff --git a/src/shared/api/product.ts b/src/shared/api/product.ts
index 81dd10b..5da62d3 100644
--- a/src/shared/api/product.ts
+++ b/src/shared/api/product.ts
@@ -1,6 +1,6 @@
 
 import { CustomProductRequest, IProductItem, ProductResponse, ProductSearchResult } from "../types/product";
-import axiosInstance, {endpoints } from './server';
+import axiosInstance, { endpoints } from "./server";
 
 export async function getProductById(productId: string): Promise<IProductItem | null> {
   try {
-- 
GitLab


From 3ed5745adbc0ac3bfe9925ef18f176b0f44b3e48 Mon Sep 17 00:00:00 2001
From: salaheddineZidani <salaheddine.zidani@marketingconfort.com>
Date: Fri, 27 Sep 2024 13:28:25 +0100
Subject: [PATCH 2/4] delete localhost from .env file

---
 src/config-global.ts    | 2 --
 src/shared/api/order.ts | 5 ++---
 2 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/src/config-global.ts b/src/config-global.ts
index ef0ad5b..8a68922 100644
--- a/src/config-global.ts
+++ b/src/config-global.ts
@@ -4,5 +4,3 @@
 // ----------------------------------------------------------------------
 
 export const GATEWAY_HOST_API = process.env.NEXT_PUBLIC_MYDRESSIN_GATEWAY_API_URL;
-
-export const HOST_API_ORDER = process.env.NEXT_PUBLIC_MYDRESSIN_GATEWAY_API_URL;
\ No newline at end of file
diff --git a/src/shared/api/order.ts b/src/shared/api/order.ts
index 35969df..84f8669 100644
--- a/src/shared/api/order.ts
+++ b/src/shared/api/order.ts
@@ -1,12 +1,11 @@
 import axios from "axios";
 import { ClientOrder } from "@/models/Order.model";
 import { endpoints } from "./server";
-import { GATEWAY_HOST_API, HOST_API_ORDER } from "@/config-global"; 
+import { GATEWAY_HOST_API } from "@/config-global"; 
 import { OrderDetails } from '../types/orderDetails';
 
 
-
-export const axiosInstance = axios.create({ baseURL: HOST_API_ORDER });
+export const axiosInstance = axios.create({ baseURL: GATEWAY_HOST_API });
 
 export const getOrders = async (clientId: string): Promise<ClientOrder[]> => {
     try {
-- 
GitLab


From c0c07768a4ed23555992b8484eb738fa03e4c492 Mon Sep 17 00:00:00 2001
From: salaheddineZidani <salaheddine.zidani@marketingconfort.com>
Date: Fri, 27 Sep 2024 13:32:56 +0100
Subject: [PATCH 3/4] Condition for displaying product details

---
 src/app/(layout-1)/products/details/[key]/page.tsx | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/app/(layout-1)/products/details/[key]/page.tsx b/src/app/(layout-1)/products/details/[key]/page.tsx
index 2966a87..72e266a 100644
--- a/src/app/(layout-1)/products/details/[key]/page.tsx
+++ b/src/app/(layout-1)/products/details/[key]/page.tsx
@@ -88,6 +88,10 @@ export default async function ProductDetails({ params }: { params: any }) {
             notFound();
             return null;
           }
+          if (variation.stockWebConfig?.quantity === undefined || variation.stockWebConfig?.quantity === null || variation.stockWebConfig?.quantity <= 0) {
+            notFound();
+            return null;
+          }
         }
       }
     }
-- 
GitLab


From e6961f7796489b10582e0676f7ec38ede1e9546b Mon Sep 17 00:00:00 2001
From: salaheddineZidani <salaheddine.zidani@marketingconfort.com>
Date: Fri, 27 Sep 2024 17:04:17 +0100
Subject: [PATCH 4/4] Condition for displaying product details

---
 src/app/(layout-1)/products/details/[key]/page.tsx | 4 ++++
 src/shared/api/product.ts                          | 6 ++++++
 2 files changed, 10 insertions(+)

diff --git a/src/app/(layout-1)/products/details/[key]/page.tsx b/src/app/(layout-1)/products/details/[key]/page.tsx
index 72e266a..b00d00a 100644
--- a/src/app/(layout-1)/products/details/[key]/page.tsx
+++ b/src/app/(layout-1)/products/details/[key]/page.tsx
@@ -83,6 +83,10 @@ export default async function ProductDetails({ params }: { params: any }) {
       }
 
       if (productData.variations) {
+        if (productData.variations.length <=0){
+          notFound();
+          return null;
+        }
         for (const variation of productData.variations) {
           if (!variation.publishWeb) {
             notFound();
diff --git a/src/shared/api/product.ts b/src/shared/api/product.ts
index 5da62d3..68e4bc8 100644
--- a/src/shared/api/product.ts
+++ b/src/shared/api/product.ts
@@ -1,4 +1,5 @@
 
+import { notFound } from "next/navigation";
 import { CustomProductRequest, IProductItem, ProductResponse, ProductSearchResult } from "../types/product";
 import axiosInstance, { endpoints } from "./server";
 
@@ -9,10 +10,12 @@ export async function getProductById(productId: string): Promise<IProductItem |
       return response.data as IProductItem;
     } else {
       console.error(`No data returned for product with id '${productId}'`);
+      notFound();
       return null;
     }
   } catch (error) {
     console.error(`Failed to fetch product with id '${productId}':`, error);
+    notFound();
     return null;
   }
 }
@@ -24,13 +27,16 @@ export async function getProductByNameUri(productNameUri: string): Promise<IProd
       return response.data as IProductItem;
     } else {
       console.error(`No data returned for product with nameUri '${productNameUri}'`);
+      notFound();
       return null;
     }
   } catch (error) {
     console.error(`Failed to fetch product with nameUri '${productNameUri}':`, error);
+    notFound();
     return null;
   }
 }
+
 export async function getProductByCategory(
   category: string,
   page: number = 0,
-- 
GitLab