fix(products): ignore foreign SSE catalogs
Drop list events from other shops and honor show_in_list so the grid stops jumping. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -117,14 +117,36 @@ function mergeLiveProductList(incoming: Product[], current?: Product[]): Product
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/** فقط محصول فعال ادمین (باز) — فیلد خالی/undefined را فعال نگیر */
|
function flagOn(value: unknown): boolean {
|
||||||
function isActiveProduct(product: Product): boolean {
|
return value === true || value === 1 || value === '1'
|
||||||
const active = product.active as unknown
|
}
|
||||||
return active === true || active === 1 || active === '1'
|
|
||||||
|
function flagOff(value: unknown): boolean {
|
||||||
|
return value === false || value === 0 || value === '0'
|
||||||
|
}
|
||||||
|
|
||||||
|
/** سوییچ «نمایش در لیست محصولات»؛ اگر فیلد نبود همان active */
|
||||||
|
function isListedProduct(product: Product): boolean {
|
||||||
|
const listed = (product as Product & { show_in_list?: unknown }).show_in_list
|
||||||
|
if (flagOn(listed)) return true
|
||||||
|
if (flagOff(listed)) return false
|
||||||
|
return flagOn(product.active)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** لیست SSE فروشگاه دیگر را روی این صفحه ننشان */
|
||||||
|
function isSameShopCatalog(incoming: Product[], current?: Product[]): boolean {
|
||||||
|
if (!current?.length) return true
|
||||||
|
const incomingIds = new Set(incoming.map((item) => item.id))
|
||||||
|
const currentIds = new Set(current.map((item) => item.id))
|
||||||
|
let overlap = 0
|
||||||
|
incomingIds.forEach((id) => {
|
||||||
|
if (currentIds.has(id)) overlap += 1
|
||||||
|
})
|
||||||
|
return overlap / Math.max(incomingIds.size, currentIds.size) >= 0.5
|
||||||
}
|
}
|
||||||
|
|
||||||
function applyProductsList(products: Product[]) {
|
function applyProductsList(products: Product[]) {
|
||||||
const visible = products.filter(isActiveProduct)
|
const visible = products.filter(isListedProduct)
|
||||||
const sorted = sortProductsByInventory(visible)
|
const sorted = sortProductsByInventory(visible)
|
||||||
productsFirstItems.value = sorted
|
productsFirstItems.value = sorted
|
||||||
getProductsCatalogRef().value = sorted
|
getProductsCatalogRef().value = sorted
|
||||||
@@ -147,8 +169,12 @@ function applyProductsList(products: Product[]) {
|
|||||||
* آپدیت قیمت روی همان آبجکتها تا گرید نپرد.
|
* آپدیت قیمت روی همان آبجکتها تا گرید نپرد.
|
||||||
*/
|
*/
|
||||||
function applySocketProductList(incoming: Product[], current?: Product[]) {
|
function applySocketProductList(incoming: Product[], current?: Product[]) {
|
||||||
|
if (!isSameShopCatalog(incoming, current)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const next = sortProductsByInventory(
|
const next = sortProductsByInventory(
|
||||||
mergeLiveProductList(incoming, current).filter(isActiveProduct),
|
mergeLiveProductList(incoming, current).filter(isListedProduct),
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!current?.length) {
|
if (!current?.length) {
|
||||||
|
|||||||
Reference in New Issue
Block a user