Mağaza stok eşleştirme algoritması düzeltildi
Browse files- Beden (S, M, L vb.) eşleşmesi daha sıkı kontrol ediliyor
- Varyant eşleşmesi iyileştirildi
- Debug loglar eklendi
- Artık sadece doğru bedeni olan mağazaları gösterecek
app.py
CHANGED
@@ -69,18 +69,29 @@ def get_warehouse_stock(product_name):
|
|
69 |
search_name = search_name.replace('(2026)', '').replace('(2025)', '').replace(' gen 3', '').replace(' gen', '').strip()
|
70 |
search_words = search_name.split()
|
71 |
|
|
|
|
|
|
|
|
|
72 |
# Search using new B2B API structure
|
73 |
candidates = []
|
74 |
product_count = 0
|
75 |
max_products = 100 # Increase limit for new API
|
76 |
|
77 |
# Separate size/color words from product words for context-aware search
|
78 |
-
size_color_words = ['s', 'm', 'l', 'xl', 'xs', 'small', 'medium', 'large',
|
79 |
-
'turuncu', 'siyah', 'beyaz', 'mavi', 'kirmizi', 'yesil',
|
80 |
-
'orange', 'black', 'white', 'blue', 'red', 'green'
|
|
|
|
|
|
|
|
|
81 |
|
82 |
variant_words = [word for word in search_words if word in size_color_words]
|
83 |
-
product_words = [word for word in search_words if word not in size_color_words]
|
|
|
|
|
|
|
84 |
|
85 |
for product in root.findall('Product'):
|
86 |
if product_count >= max_products:
|
@@ -108,12 +119,24 @@ def get_warehouse_stock(product_name):
|
|
108 |
else:
|
109 |
name_match = any(word in normalized_name for word in search_words if len(word) > 2)
|
110 |
|
111 |
-
# Check variant match
|
112 |
if variant_words and variant_text:
|
113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
|
115 |
-
# Include if name matches
|
116 |
-
if name_match and
|
117 |
candidates.append((product, xml_product_name, variant_text))
|
118 |
if len(candidates) >= 10: # Limit candidates
|
119 |
break
|
@@ -142,6 +165,11 @@ def get_warehouse_stock(product_name):
|
|
142 |
# Cancel alarm
|
143 |
signal.alarm(0)
|
144 |
|
|
|
|
|
|
|
|
|
|
|
145 |
if warehouse_stock_map:
|
146 |
all_warehouse_info = []
|
147 |
for warehouse_name, total_stock in warehouse_stock_map.items():
|
|
|
69 |
search_name = search_name.replace('(2026)', '').replace('(2025)', '').replace(' gen 3', '').replace(' gen', '').strip()
|
70 |
search_words = search_name.split()
|
71 |
|
72 |
+
print(f"DEBUG - Searching for: {product_name}")
|
73 |
+
print(f"DEBUG - Normalized: {search_name}")
|
74 |
+
print(f"DEBUG - Search words: {search_words}")
|
75 |
+
|
76 |
# Search using new B2B API structure
|
77 |
candidates = []
|
78 |
product_count = 0
|
79 |
max_products = 100 # Increase limit for new API
|
80 |
|
81 |
# Separate size/color words from product words for context-aware search
|
82 |
+
size_color_words = ['s', 'm', 'l', 'xl', 'xs', 'xxl', 'ml', 'small', 'medium', 'large',
|
83 |
+
'turuncu', 'siyah', 'beyaz', 'mavi', 'kirmizi', 'yesil', 'gri',
|
84 |
+
'orange', 'black', 'white', 'blue', 'red', 'green', 'grey', 'gray',
|
85 |
+
'quicksilver']
|
86 |
+
|
87 |
+
# Beden kelimelerini daha spesifik olarak ayır
|
88 |
+
size_indicators = ['beden', 'size', 'boy']
|
89 |
|
90 |
variant_words = [word for word in search_words if word in size_color_words]
|
91 |
+
product_words = [word for word in search_words if word not in size_color_words and word not in size_indicators]
|
92 |
+
|
93 |
+
print(f"DEBUG - Product words: {product_words}")
|
94 |
+
print(f"DEBUG - Variant words: {variant_words}")
|
95 |
|
96 |
for product in root.findall('Product'):
|
97 |
if product_count >= max_products:
|
|
|
119 |
else:
|
120 |
name_match = any(word in normalized_name for word in search_words if len(word) > 2)
|
121 |
|
122 |
+
# Check variant match - be more strict with size matching
|
123 |
if variant_words and variant_text:
|
124 |
+
# For single letter sizes (S, M, L, etc), require exact match
|
125 |
+
if len(variant_words) == 1 and len(variant_words[0]) <= 2:
|
126 |
+
# Check if size appears as a separate token in variant
|
127 |
+
variant_tokens = variant_text.split('-')
|
128 |
+
variant_match = any(variant_words[0] == token.strip() for token in variant_tokens)
|
129 |
+
else:
|
130 |
+
variant_match = all(word in variant_text for word in variant_words)
|
131 |
+
elif variant_words and not variant_text:
|
132 |
+
# If user specified a variant but product has no variant, skip
|
133 |
+
variant_match = False
|
134 |
+
else:
|
135 |
+
# No variant search specified, include all variants
|
136 |
+
variant_match = True
|
137 |
|
138 |
+
# Include if name matches AND variant matches
|
139 |
+
if name_match and variant_match:
|
140 |
candidates.append((product, xml_product_name, variant_text))
|
141 |
if len(candidates) >= 10: # Limit candidates
|
142 |
break
|
|
|
165 |
# Cancel alarm
|
166 |
signal.alarm(0)
|
167 |
|
168 |
+
print(f"DEBUG - Found {len(candidates)} candidates")
|
169 |
+
if candidates:
|
170 |
+
for product, name, variant in candidates[:3]:
|
171 |
+
print(f"DEBUG - Candidate: {name} - {variant}")
|
172 |
+
|
173 |
if warehouse_stock_map:
|
174 |
all_warehouse_info = []
|
175 |
for warehouse_name, total_stock in warehouse_stock_map.items():
|