Hide after-hours prices and skip stock checks when the shop is not a store.

This commit is contained in:
2026-09-11 00:49:29 +03:30
parent 0da9f68353
commit b78fbbdc4e
4 changed files with 47 additions and 4 deletions
+16 -1
View File
@@ -1,3 +1,5 @@
import { useSettingsStore } from '@/store/settingsStore'
/** دسته‌بندی یکسان محصول — هم‌تراز با khaneghi_user */
export const PRODUCT_CATEGORY_ABSHODE = 'آبشده'
@@ -99,5 +101,18 @@ export function isProductOutOfStock(product?: {
return false
}
return Number(product.inventory ?? 0) <= 0
if (product.inventory === undefined || product.inventory === null) {
return false
}
try {
const settings = useSettingsStore()
if (settings.loaded && !settings.isSettingTruthy('is_store')) {
return false
}
} catch {
/* تنظیمات در دسترس نیست — فقط روی خود فیلد موجودی تکیه کن */
}
return Number(product.inventory) <= 0
}
+5
View File
@@ -8,6 +8,7 @@ import {
isMetalCommodityGroup,
usesQuantityTrade,
} from '@/utils/productCategories'
import { isProductTradingHoursOpen } from '@/utils/productTradeOpen'
/**
* قیمت‌گیری محصول — هم‌تراز با khaneghi_user:
@@ -238,6 +239,10 @@ export function isProductPriceInactive(product?: Product | null): boolean {
return true
}
if (!isProductTradingHoursOpen(product)) {
return true
}
if (
hasReferenceReadingMethod(product)
&& !productUsesLastPriceIfZero(product)
+9 -2
View File
@@ -1,4 +1,5 @@
import type { Product } from '@/models/products'
import { isOutsideProductActivationWindow } from '@/utils/storeHours'
type TradeOpenProduct = Pick<Product, 'open_buy' | 'open_sell'> | null | undefined
@@ -24,11 +25,17 @@ export function isProductTradeOpen(product: TradeOpenProduct, isBuy: boolean) {
return isBuy ? isProductBuyOpen(product) : isProductSellOpen(product)
}
/** ساعت کاری محصول از استریم (trade_open) — نه ساعت دستگاه */
/** ساعت فعال‌سازی محصول: بازهٔ auto_open/auto_close، بعد فلگ استریم */
export function isProductTradingHoursOpen(
product?: { show?: boolean; trade_open?: boolean } | null,
product?: {
show?: boolean
trade_open?: boolean
auto_open_at?: string | null
auto_close_at?: string | null
} | null,
) {
if (!product) return false
if (isOutsideProductActivationWindow(product)) return false
if (typeof product.trade_open === 'boolean') return product.trade_open
return product.show === true
}
+17 -1
View File
@@ -60,7 +60,7 @@ export function formatTradingTimeDisplay(time: string): string {
return normalized
}
function hasProductTradingWindow(start?: string | null, end?: string | null): boolean {
export function hasProductTradingWindow(start?: string | null, end?: string | null): boolean {
const open = formatTradingTimeDisplay(normalizeTradingTimeSetting(start, '00:00:00'))
const close = formatTradingTimeDisplay(normalizeTradingTimeSetting(end, '00:00:00'))
if (!open || !close) {
@@ -130,6 +130,22 @@ function parseWeeklySchedule(raw: unknown): WeeklySchedule | null {
}
}
export function isOutsideProductActivationWindow(
product?: { auto_open_at?: string | null; auto_close_at?: string | null } | null,
now = new Date(),
): boolean {
void productTradingHoursVersion.value
if (!product || !hasProductTradingWindow(product.auto_open_at, product.auto_close_at)) {
return false
}
return isOutsideTimeWindow(
now,
normalizeTradingTimeSetting(product.auto_open_at, '00:00:00'),
normalizeTradingTimeSetting(product.auto_close_at, '00:00:00'),
)
}
function isOutsideTimeWindow(now: Date, start: string, end: string): boolean {
const currentSeconds = now.getHours() * 3600 + now.getMinutes() * 60 + now.getSeconds()
const openSeconds = parseTimeToSeconds(start)