Add: Weight field to product admin pages
Added weight (in kilograms) field to both create and edit product pages. Admins can now set the weight for each product, which is converted to grams and stored in the database for Royal Mail shipping calculations.
This commit is contained in:
@@ -96,6 +96,10 @@ export async function createProduct(formData: FormData) {
|
||||
.map((s) => s.trim())
|
||||
.filter(Boolean);
|
||||
|
||||
// Weight in kilograms converted to grams
|
||||
const weightKgInput = String(formData.get('weightKg') ?? '').trim();
|
||||
const weightGrams = weightKgInput ? Math.round(Number(weightKgInput) * 1000) : null;
|
||||
|
||||
const imageUrl = imageFile && imageFile.size > 0 ? await fileToDataUrl(imageFile) : null;
|
||||
const imageUrlBack = imageBackFile && imageBackFile.size > 0 ? await fileToDataUrl(imageBackFile) : null;
|
||||
const colorPhotos = await extractColorPhotos(formData, colors, 'front');
|
||||
@@ -132,6 +136,7 @@ export async function createProduct(formData: FormData) {
|
||||
description: description || `${name} — personalize it your way.`,
|
||||
basePrice: Math.round(priceDollars * 100),
|
||||
personalisedPrice: personalisedPriceDollars ? Math.round(Number(personalisedPriceDollars) * 100) : null,
|
||||
weightGrams,
|
||||
...saleFields,
|
||||
colors: JSON.stringify(colors),
|
||||
colorPhotos: Object.keys(colorPhotos).length > 0 ? JSON.stringify(colorPhotos) : null,
|
||||
@@ -173,6 +178,10 @@ export async function updateProduct(formData: FormData) {
|
||||
const referenceWidthCm = referenceWidthCmInput ? Number(referenceWidthCmInput) : null;
|
||||
const referenceHeightCm = referenceHeightCmInput ? Number(referenceHeightCmInput) : null;
|
||||
|
||||
// Weight in kilograms converted to grams
|
||||
const weightKgInput = String(formData.get('weightKg') ?? '').trim();
|
||||
const weightGrams = weightKgInput ? Math.round(Number(weightKgInput) * 1000) : null;
|
||||
|
||||
if (!id) throw new Error('Missing product id.');
|
||||
if (!name || !category || !priceDollars) {
|
||||
throw new Error('Name, category, and price are required.');
|
||||
@@ -234,6 +243,7 @@ export async function updateProduct(formData: FormData) {
|
||||
showOnProducts: boolean;
|
||||
referenceWidthCm: number | null;
|
||||
referenceHeightCm: number | null;
|
||||
weightGrams: number | null;
|
||||
imageUrl?: string;
|
||||
imageUrlBack?: string;
|
||||
printArea?: string;
|
||||
@@ -255,6 +265,7 @@ export async function updateProduct(formData: FormData) {
|
||||
showOnProducts,
|
||||
referenceWidthCm,
|
||||
referenceHeightCm,
|
||||
weightGrams,
|
||||
};
|
||||
|
||||
// Only touch the front photo/print area if a new photo was actually uploaded —
|
||||
|
||||
Reference in New Issue
Block a user