fix(catalog): remove box quantity from sku filters
This commit is contained in:
@@ -4,7 +4,7 @@ import { ClientProductsDocument, type ClientProductsQuery } from '~/composables/
|
||||
import { useClientCart } from '~/composables/useClientCart';
|
||||
|
||||
type ProductNode = ClientProductsQuery['clientProducts'][number];
|
||||
type ParamFieldKey = 'widthMm' | 'lengthM' | 'thicknessMicron' | 'sleeveBrand' | 'quantityPerBox';
|
||||
type ParamFieldKey = 'widthMm' | 'lengthM' | 'thicknessMicron' | 'sleeveBrand';
|
||||
type ParamValue = number | string;
|
||||
|
||||
type ParsedProduct = ProductNode & {
|
||||
@@ -14,6 +14,7 @@ type ParsedProduct = ProductNode & {
|
||||
thicknessMicron: number | null;
|
||||
sleeveBrand: string | null;
|
||||
quantityPerBox: string | null;
|
||||
quantityPerBoxOptions: string[];
|
||||
};
|
||||
|
||||
type ProductGroup = {
|
||||
@@ -27,17 +28,15 @@ type GroupState = {
|
||||
lengthM: number | null;
|
||||
thicknessMicron: number | null;
|
||||
sleeveBrand: string | null;
|
||||
quantityPerBox: string | null;
|
||||
isExpanded: boolean;
|
||||
};
|
||||
|
||||
const PARAM_KEYS: ParamFieldKey[] = ['widthMm', 'lengthM', 'thicknessMicron', 'sleeveBrand', 'quantityPerBox'];
|
||||
const PARAM_KEYS: ParamFieldKey[] = ['widthMm', 'lengthM', 'thicknessMicron', 'sleeveBrand'];
|
||||
const parameterFields: Array<{ key: ParamFieldKey; label: string }> = [
|
||||
{ key: 'widthMm', label: 'Ширина, мм' },
|
||||
{ key: 'lengthM', label: 'Длина, м' },
|
||||
{ key: 'thicknessMicron', label: 'Толщина, мкм' },
|
||||
{ key: 'sleeveBrand', label: 'Бренд втулки' },
|
||||
{ key: 'quantityPerBox', label: 'Количество в коробе' },
|
||||
];
|
||||
|
||||
const coverPresets = [
|
||||
@@ -90,6 +89,7 @@ function parseProductMeta(product: ProductNode) {
|
||||
const thicknessMatch = normalizedName.match(/(\d+)\s*мкм/i);
|
||||
const sleeveMatch = normalizedName.match(/втулка\s+([^,]+)/i);
|
||||
const quantityMatch = normalizedName.match(/короб\s+([^,]+)/i);
|
||||
const quantityPerBox = quantityMatch?.[1]?.trim() ?? null;
|
||||
|
||||
return {
|
||||
productTypeLabel: typeLabel,
|
||||
@@ -97,7 +97,10 @@ function parseProductMeta(product: ProductNode) {
|
||||
lengthM: sizeMatch ? Number.parseInt(sizeMatch[2] ?? '', 10) : null,
|
||||
thicknessMicron: thicknessMatch ? Number.parseInt(thicknessMatch[1] ?? '', 10) : null,
|
||||
sleeveBrand: sleeveMatch?.[1]?.trim() ?? null,
|
||||
quantityPerBox: quantityMatch?.[1]?.trim() ?? null,
|
||||
quantityPerBox,
|
||||
quantityPerBoxOptions: quantityPerBox
|
||||
? quantityPerBox.split('/').map((value) => value.trim()).filter(Boolean)
|
||||
: [],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -215,7 +218,6 @@ function createGroupState(group: ProductGroup): GroupState {
|
||||
lengthM: null,
|
||||
thicknessMicron: null,
|
||||
sleeveBrand: null,
|
||||
quantityPerBox: null,
|
||||
isExpanded: false,
|
||||
};
|
||||
|
||||
@@ -294,6 +296,22 @@ function selectedFieldValue(group: ProductGroup, field: ParamFieldKey) {
|
||||
return formatOptionLabel(field, value);
|
||||
}
|
||||
|
||||
function boxQuantityLabel(group: ProductGroup) {
|
||||
const product = selectedProduct(group);
|
||||
if (product?.quantityPerBox) {
|
||||
return product.quantityPerBox;
|
||||
}
|
||||
|
||||
const values = new Set<string>();
|
||||
for (const item of group.products) {
|
||||
for (const option of item.quantityPerBoxOptions) {
|
||||
values.add(option);
|
||||
}
|
||||
}
|
||||
|
||||
return sortParamValues([...values]).join(' / ') || '—';
|
||||
}
|
||||
|
||||
function incrementProduct(product: ProductNode) {
|
||||
if (getQuantity(product.id) === 0) {
|
||||
addProduct({
|
||||
@@ -379,6 +397,7 @@ function decrementSelected(group: ProductGroup) {
|
||||
<div class="mt-3 flex flex-wrap gap-2">
|
||||
<span class="badge badge-neutral">SKU: {{ selectedProduct(group)?.sku ?? '—' }}</span>
|
||||
<span class="badge badge-outline">Совпадений: {{ matchingCount(group) }}</span>
|
||||
<span class="badge badge-outline">Короб: {{ boxQuantityLabel(group) }}</span>
|
||||
</div>
|
||||
|
||||
<div class="mt-3 flex items-center justify-between rounded-2xl border border-base-300 bg-base-100 px-2 py-1">
|
||||
|
||||
Reference in New Issue
Block a user