fix bug
This commit is contained in:
@@ -56,12 +56,24 @@ export type ProductEditorPricePreview =
|
||||
| { status: 'ready'; amount: number; source: string }
|
||||
| { status: 'empty'; message: string }
|
||||
|
||||
function resolveStoredFallbackPrice(
|
||||
storedPrice: number | null | undefined,
|
||||
useLastPriceIfZero: boolean | undefined
|
||||
): number {
|
||||
if (!useLastPriceIfZero) {
|
||||
return 0
|
||||
}
|
||||
|
||||
return Number(storedPrice) || 0
|
||||
}
|
||||
|
||||
export function computeProductEditorPricePreview(input: {
|
||||
form: {
|
||||
group_type?: string
|
||||
price?: number | null
|
||||
reading_method?: string | null
|
||||
price_offset_percent?: number | null
|
||||
use_last_price_if_zero?: boolean | null
|
||||
}
|
||||
methodOption: string
|
||||
meltedPriceOption: MeltedPriceSource
|
||||
@@ -99,11 +111,17 @@ export function computeProductEditorPricePreview(input: {
|
||||
return { status: 'empty', message: '' }
|
||||
}
|
||||
const { base, profit } = normalizeReferenceBase(entry)
|
||||
return {
|
||||
status: 'ready',
|
||||
amount: adjustedProductPrice(base, profit, offsetPercent),
|
||||
source: entry.name
|
||||
const liveAmount = adjustedProductPrice(base, profit, offsetPercent)
|
||||
if (liveAmount > 0) {
|
||||
return { status: 'ready', amount: liveAmount, source: entry.name }
|
||||
}
|
||||
const fallback = resolveStoredFallbackPrice(
|
||||
input.form.price,
|
||||
input.form.use_last_price_if_zero ?? false
|
||||
)
|
||||
return fallback > 0
|
||||
? { status: 'ready', amount: fallback, source: 'آخرین قیمت ذخیرهشده' }
|
||||
: { status: 'empty', message: 'قیمت provider صفر است' }
|
||||
}
|
||||
|
||||
if (input.methodOption === '1') {
|
||||
@@ -121,9 +139,15 @@ export function computeProductEditorPricePreview(input: {
|
||||
return { status: 'empty', message: '' }
|
||||
}
|
||||
const { base, profit } = normalizeReferenceBase(entry)
|
||||
return {
|
||||
status: 'ready',
|
||||
amount: adjustedProductPrice(base, profit, offsetPercent),
|
||||
source: entry.name
|
||||
const liveAmount = adjustedProductPrice(base, profit, offsetPercent)
|
||||
if (liveAmount > 0) {
|
||||
return { status: 'ready', amount: liveAmount, source: entry.name }
|
||||
}
|
||||
const fallback = resolveStoredFallbackPrice(
|
||||
input.form.price,
|
||||
input.form.use_last_price_if_zero ?? false
|
||||
)
|
||||
return fallback > 0
|
||||
? { status: 'ready', amount: fallback, source: 'آخرین قیمت ذخیرهشده' }
|
||||
: { status: 'empty', message: 'قیمت provider صفر است' }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user