fix: Updating product prices removed existing prices (#8388)
RESOLVES #8376 CLOSES CC-288
This commit is contained in:
1 parent
31ec4d0d71
commit
7569fd1605
2 files changed
+8
-15
No files matched your search
@@ -20,10 +20,10 @@ type VariantPricingFormProps = {
|
|||||||
export const VariantPricingForm = ({ form }: VariantPricingFormProps) => {
|
export const VariantPricingForm = ({ form }: VariantPricingFormProps) => {
|
||||||
const { store } = useStore()
|
const { store } = useStore()
|
||||||
const { regions } = useRegions({ limit: 9999 })
|
const { regions } = useRegions({ limit: 9999 })
|
||||||
const { setCloseOnEscape } = useRouteModal()
|
|
||||||
|
|
||||||
const { price_preferences: pricePreferences } = usePricePreferences({})
|
const { price_preferences: pricePreferences } = usePricePreferences({})
|
||||||
|
|
||||||
|
const { setCloseOnEscape } = useRouteModal()
|
||||||
|
|
||||||
const columns = useVariantPriceGridColumns({
|
const columns = useVariantPriceGridColumns({
|
||||||
currencies: store?.supported_currencies,
|
currencies: store?.supported_currencies,
|
||||||
regions,
|
regions,
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ export const PricingEdit = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { handleSuccess } = useRouteModal()
|
const { handleSuccess } = useRouteModal()
|
||||||
|
const { mutateAsync, isPending } = useUpdateProductVariantsBatch(product.id)
|
||||||
|
|
||||||
const { regions } = useRegions({ limit: 9999 })
|
const { regions } = useRegions({ limit: 9999 })
|
||||||
const regionsCurrencyMap = useMemo(() => {
|
const regionsCurrencyMap = useMemo(() => {
|
||||||
@@ -70,8 +71,6 @@ export const PricingEdit = ({
|
|||||||
resolver: zodResolver(UpdateVariantPricesSchema, {}),
|
resolver: zodResolver(UpdateVariantPricesSchema, {}),
|
||||||
})
|
})
|
||||||
|
|
||||||
const { mutateAsync, isPending } = useUpdateProductVariantsBatch(product.id)
|
|
||||||
|
|
||||||
const handleSubmit = form.handleSubmit(async (values) => {
|
const handleSubmit = form.handleSubmit(async (values) => {
|
||||||
const reqData = values.variants.map((variant, ind) => ({
|
const reqData = values.variants.map((variant, ind) => ({
|
||||||
id: variants[ind].id,
|
id: variants[ind].id,
|
||||||
@@ -100,18 +99,12 @@ export const PricingEdit = ({
|
|||||||
|
|
||||||
const amount = castNumber(value)
|
const amount = castNumber(value)
|
||||||
|
|
||||||
const pricePayload = existingId
|
return {
|
||||||
? {
|
id: existingId,
|
||||||
id: existingId,
|
currency_code: currencyCode,
|
||||||
amount,
|
amount,
|
||||||
}
|
...(regionId ? { rules: { region_id: regionId } } : {}),
|
||||||
: { currency_code: currencyCode, amount }
|
|
||||||
|
|
||||||
if (regionId && !existingId) {
|
|
||||||
pricePayload.rules = { region_id: regionId }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return pricePayload
|
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
}))
|
}))
|
||||||
|
|||||||
Reference in new issue
Block a user