add stock

This commit is contained in:
hamid zarghami
2026-02-14 16:18:13 +03:30
parent 1c735fcebb
commit a9c8b89829
4 changed files with 61 additions and 8 deletions
+9 -4
View File
@@ -46,7 +46,9 @@ const UpdateProduct: FC = () => {
images: [],
discount: 0,
isSpecialOffer: false,
order: 0
order: 0,
stock: undefined,
maxPurchaseQuantity: undefined
},
validationSchema: Yup.object().shape({
title: Yup.string().required('نام کالا الزامی است'),
@@ -75,9 +77,10 @@ const UpdateProduct: FC = () => {
? values.variants.map((v) => ({
...(v.id && { id: v.id }),
value: v.value ?? '',
price: v.price ?? 0
price: v.price ?? 0,
...(v.stock !== undefined && v.stock !== null && { stock: v.stock })
}))
: [{ value: '', price: values.price }]
: [{ value: '', price: values.price, ...(values.stock !== undefined && values.stock !== null && { stock: values.stock }) }]
const productData: CreateProductType = {
...values,
variants,
@@ -130,7 +133,9 @@ const UpdateProduct: FC = () => {
images: product.images || [],
discount: product.discount || 0,
isSpecialOffer: product.isSpecialOffer || false,
order: product.order ?? 0
order: product.order ?? 0,
stock: product.variants?.[0]?.stock,
maxPurchaseQuantity: product.maxPurchaseQuantity
})
setIsActive(product.isActive || false)
setIsSpecial(product.isSpecialOffer || false)