fix: auto-sync and replace legacy random SKUs with TRDX-[cat]-[mid]-[seq] standard in AddProduct
This commit is contained in:
parent
ad3bde264e
commit
47f2ecfd39
1 changed files with 15 additions and 1 deletions
|
|
@ -235,6 +235,16 @@ export const AddProductPage: React.FC = () => {
|
|||
}
|
||||
}, [editProduct]);
|
||||
|
||||
// Synchronize SKU with Category, Seller MID, and Catalog sequence
|
||||
useEffect(() => {
|
||||
const isLegacyOrEmpty = !sku || /^TRDX-\d{4,6}$/.test(sku) || sku.startsWith('TRDX-GEN-');
|
||||
if (!editProduct || isLegacyOrEmpty) {
|
||||
if (category) {
|
||||
setSku(generateTradhoxSku(sellerMid, category, nextProductSeq));
|
||||
}
|
||||
}
|
||||
}, [category, sellerMid, nextProductSeq]);
|
||||
|
||||
const craftTypes = category ? (CRAFT_TYPES[category] || []) : [];
|
||||
const clusters = category ? (CLUSTERS[category] || []) : [];
|
||||
|
||||
|
|
@ -341,7 +351,11 @@ export const AddProductPage: React.FC = () => {
|
|||
try {
|
||||
const activeSupportingImages = supportingImages.filter(img => img && img.trim().length > 0);
|
||||
const productPayload: any = {
|
||||
sku: (sku && sku.trim()) ? sku.trim().toUpperCase() : generateTradhoxSku(sellerMid, category, nextProductSeq),
|
||||
sku: (() => {
|
||||
const trimmed = (sku || '').trim().toUpperCase();
|
||||
const isLegacy = !trimmed || /^TRDX-\d{4,6}$/.test(trimmed) || trimmed.startsWith('TRDX-GEN-');
|
||||
return isLegacy ? generateTradhoxSku(sellerMid, category, nextProductSeq) : trimmed;
|
||||
})(),
|
||||
title: title || 'Authentic Handcrafted Item',
|
||||
category: category || 'Handicrafts & Art',
|
||||
description: story || `${title} - Handcrafted ${category}`,
|
||||
|
|
|
|||
Loading…
Reference in a new issue