Fix: Always update print area coordinates when editing product
- Print area was only updated if a new image was uploaded - Now print area is updated even when keeping existing image - Fixes design area positioning mismatch on made-to-order page - Applies to both front and back print areas
This commit is contained in:
@@ -105,7 +105,8 @@
|
||||
"Bash(git commit -m 'Fix: Handle image removal in product editor *)",
|
||||
"Bash(git commit -m 'Refactor: Move image display into PhotoPrintAreaField component *)",
|
||||
"Bash(git commit -m 'Optimize: Skip color photo processing when not uploading new photos *)",
|
||||
"Bash(git commit -m 'Optimize: Fetch only necessary fields from database *)"
|
||||
"Bash(git commit -m 'Optimize: Fetch only necessary fields from database *)",
|
||||
"Bash(git commit -m 'Fix: Always update print area coordinates when editing product *)"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,13 +291,13 @@ export async function updateProduct(formData: FormData) {
|
||||
|
||||
// Handle front photo: new upload, removal, or keep existing
|
||||
const removeImage = String(formData.get('removeImage') ?? '') === '1';
|
||||
const hasCustomPrintArea = String(formData.get('hasCustomPrintArea') ?? '') === '1';
|
||||
|
||||
if (removeImage) {
|
||||
data.imageUrl = null;
|
||||
data.printArea = JSON.stringify(DEFAULT_PRINT_AREAS[mockup] ?? DEFAULT_PRINT_AREAS.tshirt);
|
||||
} else if (imageFile && imageFile.size > 0) {
|
||||
data.imageUrl = await fileToDataUrl(imageFile);
|
||||
|
||||
const hasCustomPrintArea = String(formData.get('hasCustomPrintArea') ?? '') === '1';
|
||||
data.printArea = JSON.stringify(
|
||||
hasCustomPrintArea
|
||||
? {
|
||||
@@ -308,17 +308,37 @@ export async function updateProduct(formData: FormData) {
|
||||
}
|
||||
: DEFAULT_PRINT_AREAS[mockup] ?? DEFAULT_PRINT_AREAS.tshirt,
|
||||
);
|
||||
} else if (existing.imageUrl) {
|
||||
// No new image uploaded, but existing image present — still update print area if custom
|
||||
if (hasCustomPrintArea) {
|
||||
data.printArea = JSON.stringify({
|
||||
xPct: Number(formData.get('printX') ?? 0.3),
|
||||
yPct: Number(formData.get('printY') ?? 0.25),
|
||||
wPct: Number(formData.get('printW') ?? 0.4),
|
||||
hPct: Number(formData.get('printH') ?? 0.35),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Handle back photo: new upload, removal, or keep existing
|
||||
const removeImageBack = String(formData.get('removeImageBack') ?? '') === '1';
|
||||
const hasCustomPrintAreaBack = String(formData.get('hasCustomPrintAreaBack') ?? '') === '1';
|
||||
|
||||
if (removeImageBack) {
|
||||
data.imageUrlBack = null;
|
||||
data.printAreaBack = null;
|
||||
} else if (imageBackFile && imageBackFile.size > 0) {
|
||||
data.imageUrlBack = await fileToDataUrl(imageBackFile);
|
||||
|
||||
const hasCustomPrintAreaBack = String(formData.get('hasCustomPrintAreaBack') ?? '') === '1';
|
||||
if (hasCustomPrintAreaBack) {
|
||||
data.printAreaBack = JSON.stringify({
|
||||
xPct: Number(formData.get('printXBack') ?? 0.3),
|
||||
yPct: Number(formData.get('printYBack') ?? 0.25),
|
||||
wPct: Number(formData.get('printWBack') ?? 0.4),
|
||||
hPct: Number(formData.get('printHBack') ?? 0.35),
|
||||
});
|
||||
}
|
||||
} else if (existing.imageUrlBack) {
|
||||
// No new image uploaded, but existing image present — still update print area if custom
|
||||
if (hasCustomPrintAreaBack) {
|
||||
data.printAreaBack = JSON.stringify({
|
||||
xPct: Number(formData.get('printXBack') ?? 0.3),
|
||||
|
||||
Reference in New Issue
Block a user