there is an issue in adding a size inside a color... even though when I add it it doesn't add to the sizes inside the colors but it does for sizes outside for colors... fix this...
whenever the problem in front end or backend...
{"products":[{"id":683,"name":"Creat 3D Whitestrip Superme Bright","description":"لصقات تبييض الاسنان مع كرست بخطوات سهلة وسريعة للحصول على ابتسامة ناصعة البياض\n-تتكون من عامل التبييض الآمن بالمينا\n-تقنية خالية من الانزلاق تظل ثابتة.\n-سهل الاستخدام للغاية يمكنك التبييض أثناء المشي والتحدث والعمل وحتى شرب الماء\n-طريقة الاستخدام:\nتستخدم مرة واحدة يوميا على اسنان نظيفة ضعي الشرائح على الفك العلوي والسفلي وازيليها بعد 45 دقيقة","brand_id":225,"has_color":false,"has_size":true,"product_type":"size","price":0,"qty":0,"sold":0,"created_at":"2024-09-09T09:40:47.835Z","updated_at":"2024-09-14T11:27:34.532Z","categories":[{"id":226,"name":"Teeth","main_category_id":23,"main_category_name":"Mouth Care"}],"colors":[],"sizes":[{"id":1258,"name":"1 strip","price":5000,"qty":76,"sold":0,"color_id":null,"images":["1795.webp"]},{"id":1259,"name":"20 strips","price":90000,"qty":5,"sold":0,"color_id":null,"images":[]}],"images":[{"id":2172,"url":"1795.webp","color_id":null,"size_id":1258}]},{"id":1204,"name":"test","description":"test","brand_id":78,"has_color":true,"has_size":false,"product_type":"color","price":0,"qty":0,"sold":0,"created_at":"2024-09-24T11:46:34.216Z","updated_at":"2024-09-24T11:46:34.216Z","categories":[{"id":178,"name":"Body Cleansers","main_category_id":2,"main_category_name":"Body Care"}],"colors":[{"id":42,"name":"red","price":0,"qty":0,"sold":0,"has_size":false,"sizes":[],"images":[]}],"sizes":[{"id":7,"name":"20ml","price":20000,"qty":20,"sold":0,"color_id":42,"images":[]}],"images":[]}],"total":2,"page":1,"itemsPerPage":15,"totalPages":1,"hasMore":false,"minPrice":0,"maxPrice":250000}
front:
"use client";
import React, { useState, useEffect } from "react";
import { X, Plus } from "lucide-react";
import { MultipartFileUploader } from "@/components/MultipartFileUploader";
import { toast } from "react-toastify";
import { getToken } from "@/app/auth";
};
export const loadAndCacheAllProducts = async (): Promise => {
const q = SELECT p.id, p.name, p.description, p.brand_id, p.has_color, p.has_size, p.product_type, p.price, p.qty, p.sold, p.created_at, p.updated_at, sc.id AS subcategory_id, sc.name AS subcategory_name, c.id AS main_category_id, c.name AS main_category_name, s.id AS size_id, s.name AS size_name, s.price AS size_price, s.qty AS size_qty, s.sold AS size_sold, cl.id AS color_id, cl.name AS color_name, cl.price AS color_price, cl.qty AS color_qty, cl.sold AS color_sold, i.id AS image_id, i.url AS image_url, i.color_id AS image_color_id, i.size_id AS image_size_id FROM products p LEFT JOIN product_categories pc ON p.id = pc.product_id LEFT JOIN subcategories sc ON pc.category_id = sc.id LEFT JOIN categories c ON sc.category_id = c.id LEFT JOIN sizes s ON p.id = s.product_id LEFT JOIN colors cl ON p.id = cl.product_id LEFT JOIN images i ON (p.id = i.product_id AND (cl.id = i.color_id OR i.color_id IS NULL) AND (s.id = i.size_id OR i.size_id IS NULL)) ;
code
try {
const result = await query(q, []);
const productsMap: Record<number, Product> = {};
result.rows.forEach((row: any) => {
const productId = Number(row.id);
if (!productsMap[productId]) {
productsMap[productId] = {
id: productId,
name: row.name,
description: row.description,
brand_id: Number(row.brand_id),
has_color: Boolean(row.has_color),
has_size: Boolean(row.has_size),
product_type: row.product_type,
price: Number(row.price),
qty: Number(row.qty),
sold: Number(row.sold),
created_at: new Date(row.created_at).toISOString(),
updated_at: new Date(row.updated_at).toISOString(),
categories: [],
colors: [],
sizes: [],
images: []
};
}
// Add category if not already present
if (
row.subcategory_id &&
row.subcategory_name &&
row.main_category_id &&
row.main_category_name
) {
const categoryId = Number(row.subcategory_id);
const mainCategoryId = Number(row.main_category_id);
const existingCategory = productsMap[productId].categories.find(cat => cat.id === categoryId);
if (!existingCategory) {
productsMap[productId].categories.push({
id: categoryId,
name: row.subcategory_name,
main_category_id: mainCategoryId,
main_category_name: row.main_category_name,
});
}
}
// Add color if not already present
if (row.color_id && row.color_name && row.has_size !== undefined) {
const colorId = Number(row.color_id);
const existingColor = productsMap[productId].colors.find(color => color.id === colorId);
if (!existingColor) {
productsMap[productId].colors.push({
id: colorId,
name: row.color_name,
price: Number(row.color_price),
qty: Number(row.color_qty),
sold: Number(row.color_sold),
has_size: Boolean(row.has_size),
sizes: [],
images: []
});
}
}
// Add size if not already present
if (row.size_id && row.size_name) {
const sizeId = Number(row.size_id);
const existingSize = productsMap[productId].sizes.find(size => size.id === sizeId);
if (!existingSize) {
productsMap[productId].sizes.push({
id: sizeId,
name: row.size_name,
price: Number(row.size_price),
qty: Number(row.size_qty),
sold: Number(row.size_sold),
color_id: row.color_id ? Number(row.color_id) : null,
images: []
});
}
}
// Add image if not already present
if (row.image_id && row.image_url) {
const imageId = Number(row.image_id);
const existingImage = productsMap[productId].images.find(img => img.id === imageId);
if (!existingImage) {
productsMap[productId].images.push({
id: imageId,
url: row.image_url,
color_id: row.image_color_id ? Number(row.image_color_id) : null,
size_id: row.image_size_id ? Number(row.image_size_id) : null
});
}
// Associate image with color if applicable
if (row.image_color_id) {
const color = productsMap[productId].colors.find(c => c.id === Number(row.image_color_id));
if (color && !color.images.includes(row.image_url)) {
color.images.push(row.image_url);
}
}
// Associate image with size if applicable
if (row.image_size_id) {
const size = productsMap[productId].sizes.find(s => s.id === Number(row.image_size_id));
if (size && !size.images.includes(row.image_url)) {
size.images.push(row.image_url);
}
}
}
});
const allProducts = Object.values(productsMap);
// Calculate min and max prices across all products
let minPrice = Infinity;
let maxPrice = -Infinity;
allProducts.forEach(product => {
// Product price
if (product.price < minPrice) minPrice = product.price;
if (product.price > maxPrice) maxPrice = product.price;
// Prices from colors and their sizes
product.colors.forEach(color => {
if (color.price < minPrice) minPrice = color.price;
if (color.price > maxPrice) maxPrice = color.price;
color.sizes.forEach(size => {
if (size.price < minPrice) minPrice = size.price;
if (size.price > maxPrice) maxPrice = size.price;
});
});
// Prices from standalone sizes
product.sizes.forEach(size => {
if (size.price < minPrice) minPrice = size.price;
if (size.price > maxPrice) maxPrice = size.price;
});
});
// Fallback in case no prices are present
if (minPrice === Infinity) minPrice = 0;
if (maxPrice === -Infinity) maxPrice = 0;
// Cache the data with a consistent key
const cacheData: CacheData = { allProducts, minPrice, maxPrice };
productCache.set('allProducts', cacheData);
console.log(`Cached ${allProducts.length} products with minPrice: ${minPrice} and maxPrice: ${maxPrice}.`);
return cacheData;
} catch (error) {
console.error('Error loading products from DB:', error);
throw error; // Propagate error to be handled by caller
}
};
/**
Fetches all brands from the database and caches them.
@returns {Promise} A promise that resolves to the cached brand data.
*/
const loadAndCacheAllBrands = async (): Promise => {
const q = SELECT s.*, c.name as category_name FROM subcategories s JOIN categories c ON s.category_id = c.id AND c.is_brand ORDER BY c.name, s.name ;
if (!cacheData) {
// Cache miss: Load from DB and cache
cacheData = await loadAndCacheAllProducts();
console.log('Loaded products from database and cached them.');
} else {
console.log('Loaded products from cache.');
}
const { allProducts, minPrice, maxPrice } = cacheData;
// Log total products before any filtering
console.log(`Total products before filtering: ${allProducts.length}`);
// Extract and sanitize query parameters
let {
search = '',
c,
sc,
b,
minPriceA = '0',
maxPriceA = '',
availability = 'all',
sortBy = '',
page = '1',
itemsPerPage = '15',
} = req.query;
// Parse numerical values
const pageNum = parseInt(page as string, 10) || 1;
const itemsPerPageNum = parseInt(itemsPerPage as string, 10) || 15;
const minPriceANum = parseFloat(minPriceA as string) || 0;
let maxPriceANum = maxPriceA ? parseFloat(maxPriceA as string) : Infinity;
// If maxPriceA is less than minPriceA, reset to Infinity
if (!isNaN(maxPriceANum) && maxPriceANum < minPriceANum) {
console.warn('Provided maxPriceA is less than minPriceA. Resetting maxPriceANum to Infinity.');
maxPriceANum = Infinity;
} else if (isNaN(maxPriceANum)) {
maxPriceANum = Infinity;
}
// Parse c, sc, b as numbers if present
const cNum = c ? parseInt(c as string, 10) : undefined;
const scNum = sc ? parseInt(sc as string, 10) : undefined;
const bNum = b ? parseInt(b as string, 10) : undefined;
// Initialize brand-related variables if 'b' is provided
let allBrands: Brand[] = [];
if (bNum !== undefined && !isNaN(bNum)) {
// Retrieve cached brands
let brandsCacheData: BrandsCacheData | undefined = brandsCache.get('allBrands');
if (!brandsCacheData) {
// Cache miss: Load from DB and cache
brandsCacheData = await loadAndCacheAllBrands();
console.log('Loaded brands from database and cached them.');
} else {
console.log('Loaded brands from cache.');
}
console.log(brandsCacheData)
allBrands = brandsCacheData.allBrands;
// Check if 'bNum' is a valid brand ID
const isValidBrand = allBrands.some(brand => brand.category_id === bNum);
if (!isValidBrand) {
console.warn(`Brand ID ${bNum} is invalid.`);
// Return zero products since 'b' is invalid
res.json({
products: [],
total: 0,
page: pageNum,
itemsPerPage: itemsPerPageNum,
totalPages: 0,
hasMore: false,
minPrice,
maxPrice,
});
return;
}
}
// Start with all products
let filteredProducts = [...allProducts];
// Apply Search Filter
if (search && typeof search === 'string') {
const searchLower = search.toLowerCase();
const searchWords = searchLower.split(/\s+/).filter(Boolean);
filteredProducts = filteredProducts.filter(product =>
searchWords.every(word => product.name.toLowerCase().includes(word))
);
}
// Apply Category Filter (c)
if (cNum !== undefined && !isNaN(cNum)) {
filteredProducts = filteredProducts.filter(product =>
product.categories.some(cat => cat.main_category_id === cNum)
);
}
// Apply Subcategory Filter (sc)
if (scNum !== undefined && !isNaN(scNum)) {
filteredProducts = filteredProducts.filter(product =>
product.brand_id === scNum ||
product.categories.some(cat => cat.id === scNum)
);
}
// Apply Brand Filter (b)
if (bNum !== undefined && !isNaN(bNum)) {
console.log(`Applying Brand Filter: brand_id === ${bNum}`);
const preFilterCount = filteredProducts.length;
allBrands = allBrands.filter(brand => brand.category_id === bNum)
filteredProducts = filteredProducts.filter(product =>
allBrands.some(brand => brand.id === product.brand_id)
);
console.log(`Filtered from ${preFilterCount} to ${filteredProducts.length} products after applying brand filter.`);
}
// Apply Price Range Filter
if (minPriceANum > 0 || maxPriceANum < Infinity) {
filteredProducts = filteredProducts.filter(product => {
const productPrices = product.sizes.map(size => size.price);
// If product has no sizes, exclude it
if (productPrices.length === 0) return false;
const productMinPrice = Math.min(...productPrices);
const productMaxPrice = Math.max(...productPrices);
return productMinPrice >= minPriceANum && productMaxPrice <= maxPriceANum;
});
}
// Apply Availability Filter
if (availability === 'in_stock') {
filteredProducts = filteredProducts.filter(product =>
product.sizes.some(size => size.qty > 0)
);
} else if (availability === 'out_of_stock') {
filteredProducts = filteredProducts.filter(product =>
product.sizes.every(size => size.qty === 0)
);
}
// Log total after filtering
console.log(`Total products after filtering: ${filteredProducts.length}`);
// Apply Sorting
if (sortBy && typeof sortBy === 'string') {
switch (sortBy) {
case 'Price: Low to High':
filteredProducts.sort((a, b) => {
const aMin = Math.min(...a.sizes.map(s => s.price));
const bMin = Math.min(...b.sizes.map(s => s.price));
return aMin - bMin;
});
break;
case 'Price: High to Low':
filteredProducts.sort((a, b) => {
const aMax = Math.max(...a.sizes.map(s => s.price));
const bMax = Math.max(...b.sizes.map(s => s.price));
return bMax - aMax;
});
break;
case 'Name: A to Z':
filteredProducts.sort((a, b) => a.name.localeCompare(b.name));
break;
case 'Name: Z to A':
filteredProducts.sort((a, b) => b.name.localeCompare(a.name));
break;
case 'Best Selling':
filteredProducts.sort((a, b) => b.sold - a.sold);
break;
case 'Newest Arrivals':
filteredProducts.sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime());
break;
default:
// If sortBy parameter doesn't match any case, do not sort
break;
}
}
// Apply Pagination
const totalFilteredProducts = filteredProducts.length;
const totalPages = Math.ceil(totalFilteredProducts / itemsPerPageNum);
const startIdx = (pageNum - 1) * itemsPerPageNum;
const endIdx = startIdx + itemsPerPageNum;
const paginatedProducts = filteredProducts.slice(startIdx, endIdx);
// Construct Response
const response = {
products: paginatedProducts,
total: totalFilteredProducts,
page: pageNum,
itemsPerPage: itemsPerPageNum,
totalPages,
hasMore: endIdx < totalFilteredProducts,
minPrice, // Global minPrice across all products
maxPrice, // Global maxPrice across all products
};
// Send Response
res.json(response);
} catch (error) {
console.error('Error fetching products:', error);
res.status(500).json({ error: 'Internal server error' });
} finally {
// Optional: Any cleanup operations can be performed here
// For example, monitoring memory usage or logging request completion
}
};
export const getProductById = async (req: Request, res: Response) => {
const { id } = req.params;
try {
const productQuery = SELECT p.id AS product_id, p.name AS product_name, p.description, p.brand_id, p.has_color, p.has_size, p.product_type, p.price AS product_price, p.qty AS product_qty, p.sold AS product_sold, p.created_at, p.updated_at, pc.category_id, sc.name AS category_name, cl.id AS color_id, cl.name AS color_name, cl.price AS color_price, cl.qty AS color_qty, cl.sold AS color_sold, s.id AS size_id, s.name AS size_name, s.price AS size_price, s.qty AS size_qty, s.sold AS size_sold, i.id AS image_id, i.url AS image_url FROM products p LEFT JOIN product_categories pc ON p.id = pc.product_id LEFT JOIN subcategories sc ON pc.category_id = sc.id LEFT JOIN colors cl ON p.id = cl.product_id LEFT JOIN sizes s ON (p.id = s.product_id AND (cl.id = s.color_id OR s.color_id IS NULL)) LEFT JOIN images i ON (p.id = i.product_id AND (cl.id = i.color_id OR i.color_id IS NULL) AND (s.id = i.size_id OR i.size_id IS NULL)) WHERE p.id = $1 ORDER BY pc.category_id, cl.id, s.id, i.id ;
code
const result = await query(productQuery, [id]);
if (result.rows.length === 0) {
return res.status(404).json({ error: 'Product not found' });
}
// Process the result to group related data
let product: {
sold: any;
has_size: any;
images: any[];
description: any;
created_at: any;
colors: any[];
brand_id: any;
has_color: any;
product_type: any;
updated_at: any;
sizes: any[];
price: any;
qty: any;
name: any;
id: number;
categories: any[]
};
product = {
id: result.rows[0].product_id,
name: result.rows[0].product_name,
description: result.rows[0].description,
brand_id: result.rows[0].brand_id,
has_color: result.rows[0].has_color,
has_size: result.rows[0].has_size,
product_type: result.rows[0].product_type,
price: result.rows[0].product_price,
qty: result.rows[0].product_qty,
sold: result.rows[0].product_sold,
created_at: result.rows[0].created_at,
updated_at: result.rows[0].updated_at,
categories: [],
colors: [],
sizes: [],
images: []
};
for (const row of result.rows) {
if (row.category_id && !product.categories.some(c => c.id === row.category_id)) {
product.categories.push({
id: row.category_id,
name: row.category_name
});
}
// Add color if not already added
if (row.color_id && !product.colors.some(c => c.id === row.color_id)) {
product.colors.push({
id: row.color_id,
name: row.color_name,
price: row.color_price,
qty: row.color_qty,
sold: row.color_sold,
images: [],
sizes: []
});
}
// Add size if not already added
if (row.size_id && !product.sizes.some(s => s.id === row.size_id)) {
const newSize = {
id: row.size_id,
name: row.size_name,
price: row.size_price,
qty: row.size_qty,
sold: row.size_sold,
color_id: row.color_id,
// @ts-ignore
images: []
};
product.sizes.push(newSize);
// Add size to the corresponding color
if (row.color_id) {
const color = product.colors.find(c => c.id === row.color_id);
if (color && !color.sizes.some((s: { id: any; }) => s.id === row.size_id)) {
color.sizes.push(newSize);
}
}
}
if (row.image_id && !product.images.some(i => i.id === row.image_id)) {
const newImage = {
id: row.image_id,
url: row.image_url,
color_id: row.color_id,
size_id: row.size_id
};
product.images.push(newImage);
if (row.color_id) {
const color = product.colors.find(c => c.id === row.color_id);
if (color && !color.images.includes(row.image_url)) {
color.images.push(row.image_url);
}
}
if (row.size_id) {
const size = product.sizes.find(s => s.id === row.size_id);
if (size && !size.images.includes(row.image_url)) {
size.images.push(row.image_url);
}
}
}
}
res.json({ product });
} catch (error) {
console.error('Error fetching product by ID:', error);
res.status(500).json({ error: 'Internal server error' });
}
if (isNaN(productId)) {
return res.status(400).json({ error: 'Invalid product ID' });
}
try {
await query('BEGIN');
// Delete related data first
await query('DELETE FROM product_categories WHERE product_id = $1', [productId]);
await query('DELETE FROM images WHERE product_id = $1', [productId]);
await query('DELETE FROM sizes WHERE product_id = $1', [productId]);
await query('DELETE FROM colors WHERE product_id = $1', [productId]);
// Delete the product
const result = await query('DELETE FROM products WHERE id = $1 RETURNING *', [productId]);
if (result.rows.length === 0) {
await query('ROLLBACK');
return res.status(404).json({ error: 'Product not found' });
}
// Delete the product from the cache
deleteProductFromCache(productId);
await query('COMMIT');
res.json({ message: 'Product and related data deleted successfully' });
} catch (error) {
await query('ROLLBACK');
console.error('Error deleting product:', error);
res.status(500).json({ error: 'Internal server error' });
}
};
It appears that the issue stems from how the frontend constructs and submits the product data, particularly regarding the association of sizes within colors. The backend logic you've provided seems correctly structured to handle sizes within colors, assuming the incoming data is properly formatted. Therefore, the primary area to focus on is the frontend's data handling and submission process.
Below, I'll outline the key problems and provide detailed steps to fix them:
Incorrect product_type Determination:
The current logic for determining the product_type in the handleSubmit function is flawed. Specifically, it incorrectly checks product.colors.sizes, which is undefined because product.colors is an array.
Improper Mapping of Colors and Sizes:
The use of the logical OR (||) operator when mapping colors and sizes leads to sizes not being correctly associated with colors. This results in sizes being added at the product level instead of within specific colors.
Inaccurate has_size Flag for Colors:
The has_size flag for each color incorrectly refers to product.colors.sizes, which doesn't exist. This prevents the backend from recognizing that colors have associated sizes.
Explanation:
This fix correctly iterates through the product.colors array to check if any color has associated sizes, thereby accurately determining the product_type.
2. Proper Mapping of Colors and Sizes Without Using Logical OR (||)
Issue:
Using the || operator here causes the product.sizes.map(...) to be ignored when product.colors.map(...) returns a truthy value (which it always does if product.colors is not empty).
Explanation:
By removing the || operator, you ensure that colors and their associated sizes are mapped correctly. Additionally, sizes are only mapped at the product level if hasColor is false, maintaining a clear separation between global sizes and color-specific sizes.
Issue: product.colors.sizes is invalid because product.colors is an array.
Fixed Code:
javascript
has_size: color.hasSize,
Explanation:
Each color should independently have its own has_size flag based on whether that specific color has sizes. This avoids confusion and ensures accurate data representation.
Updated handleSubmit Function
Here's the revised handleSubmit function incorporating all the fixes:
javascript
const handleSubmit = async (e) => {
e.preventDefault();
// Determine if any color has sizes
const colorsHaveSizes = product.hasColor && product.colors.some(color => color.hasSize && color.sizes.length > 0);
// Determine productType based on the presence of colors and sizes
let productType;
if (colorsHaveSizes) {
productType = "color_size";
} else if (product.hasColor) {
productType = "color";
} else if (product.hasSize) {
productType = "size";
} else {
productType = "simple";
}
// Construct productData without using ||
const productData = {
name: product.name,
description: product.description,
brand_id: parseInt(product.brand, 10),
has_color: product.hasColor,
has_size: product.hasSize,
product_type: productType,
category_ids: product.categories,
colors: product.colors.map((color) => ({
name: color.name,
images: color.images,
has_size: color.hasSize,
sizes: color.hasSize
? color.sizes.map((size) => ({
name: size.name,
price: parseFloat(size.price),
qty: parseInt(size.qty, 10) || 0,
images: size.images,
}))
: [],
price: parseFloat(color.price),
qty: parseInt(color.qty, 10) || 0,
})),
sizes: !product.hasColor
? product.sizes.map((size) => ({
name: size.name,
price: parseFloat(size.price),
qty: parseInt(size.qty, 10) || 0,
images: size.images,
}))
: [],
price: parseFloat(product.price),
qty: parseInt(product.qty, 10) || 0,
images: product.images,
};
try {
const token = getToken(); // Retrieve the token from localStorage
if (!token) {
toast.error("You must be logged in to add a product.");
return;
}
const response = await fetch("http://localhost:3000/products", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`, // Include the token here
},
body: JSON.stringify(productData),
});
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.message || "Failed to create product");
}
// Reset the form after successful submission
setProduct({
name: "",
description: "",
category: "",
subcategory: "",
brand: "",
hasColor: false,
colors: [],
hasSize: false,
sizes: [],
categories: [],
price: "",
qty: "",
images: [],
});
toast.success("Product added successfully!");
onClose();
} catch (error) {
console.error("Error creating product:", error);
toast.error("Failed to add product. Please try again.");
}
};
Additional Recommendations:
Validate Backend Response:
Ensure that the backend is correctly receiving and processing the structured productData. You can add logging on the backend to verify the incoming data structure.
Frontend Form Validation:
Implement additional frontend validations to ensure that sizes are correctly associated with colors before submission. This can prevent malformed data from being sent to the backend.
Error Handling:
Enhance error handling both on the frontend and backend to provide more descriptive error messages, which can aid in debugging similar issues in the future.
Consistent Data Structures:
Maintain consistency in your data structures across the frontend and backend. Clearly define interfaces or types to ensure that both ends are synchronized in terms of data expectations.
By implementing these fixes, your frontend should correctly associate sizes within colors, ensuring that the backend receives well-structured data to process and store. This should resolve the issue where sizes within colors are not being added as expected.
If after these changes the issue persists, further debugging would involve:
Inspecting Network Requests:
Use browser developer tools to inspect the network requests and ensure that the payload sent to the backend correctly nests sizes within colors.
Backend Logging:
Add detailed logging in the backend's createProduct function to verify that sizes within colors are being received and processed correctly.
Feel free to reach out if you encounter further issues or need additional assistance!