fix(core-flows): variant pricing batch update (#7677)
* fix: variant pricing batch update * fix: batch endpoint throwing when `create` array isn't passed * fix: batch variants workflow
This commit is contained in:
@@ -166,7 +166,10 @@ export const useUpdateProductVariantsBatch = (
|
||||
return useMutation({
|
||||
mutationFn: (
|
||||
payload: HttpTypes.AdminBatchProductVariantRequest["update"]
|
||||
) => sdk.admin.product.batchVariants(productId, { update: payload }),
|
||||
) =>
|
||||
sdk.admin.product.batchVariants(productId, {
|
||||
update: payload,
|
||||
}),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({ queryKey: variantsQueryKeys.lists() })
|
||||
queryClient.invalidateQueries({
|
||||
|
||||
@@ -48,17 +48,22 @@ export const PricingEdit = ({
|
||||
|
||||
const handleSubmit = form.handleSubmit(
|
||||
async (values) => {
|
||||
const reqData = {
|
||||
update: values.variants.map((variant, ind) => ({
|
||||
id: product.variants[ind].id,
|
||||
prices: Object.entries(variant.prices || {}).map(
|
||||
([key, value]: any) => ({
|
||||
currency_code: key,
|
||||
amount: castNumber(value),
|
||||
})
|
||||
),
|
||||
})),
|
||||
}
|
||||
const reqData = values.variants.map((variant, ind) => ({
|
||||
id: product.variants[ind].id,
|
||||
prices: Object.entries(variant.prices || {}).map(
|
||||
([currency_code, value]: any) => {
|
||||
const id = product.variants[ind].prices.find(
|
||||
(p) => p.currency_code === currency_code
|
||||
)?.id
|
||||
|
||||
const amount = castNumber(value)
|
||||
|
||||
return id
|
||||
? { id, amount, currency_code }
|
||||
: { currency_code, amount }
|
||||
}
|
||||
),
|
||||
}))
|
||||
await mutateAsync(reqData, {
|
||||
onSuccess: () => {
|
||||
handleSuccess(`/products/${product.id}`)
|
||||
|
||||
Reference in New Issue
Block a user