fix(): fix models for get flags
This commit is contained in:
1 parent
77ebb0e3a8
commit
81ff26fdb8
4 files changed
+64
-37
No files matched your search
@@ -70,6 +70,7 @@ def get_all_categories_with_attributes(db_name: str = 'pipe_store.db') -> List[D
|
||||
attributes.append({
|
||||
"id": filter_id,
|
||||
"name": filter_name,
|
||||
"flag": filter_key, # добавлено поле flag
|
||||
"vals": vals
|
||||
})
|
||||
|
||||
@@ -77,7 +78,7 @@ def get_all_categories_with_attributes(db_name: str = 'pipe_store.db') -> List[D
|
||||
"id": category_id,
|
||||
"name": cat_row['name'],
|
||||
"image": cat_row['image_path'] or f"/images/categories/{cat_row['name'].lower().replace(' ', '_')}.jpg",
|
||||
"atributes": attributes
|
||||
"attributes": attributes # исправлено atributes → attributes
|
||||
})
|
||||
|
||||
return categories
|
||||
|
||||
@@ -90,20 +90,31 @@ def get_products_with_filters(
|
||||
# 5. Формируем ответ
|
||||
items = []
|
||||
for row in rows:
|
||||
# Вычисляем size
|
||||
size = None
|
||||
if row['diameter'] and row['wall_thickness'] and row['length'] and row['length'] > 0:
|
||||
size = f"{row['diameter']}x{row['wall_thickness']}x{row['length']}"
|
||||
|
||||
# Количество в упаковке
|
||||
amount = get_pack_amount(row['id'], row['diameter'])
|
||||
|
||||
items.append({
|
||||
"id": row['id'],
|
||||
"name": row['name'],
|
||||
"full_name": row['full_name'],
|
||||
"description": row['description'],
|
||||
"categoryId": row['category_id'],
|
||||
"images": [row['image_path']] if row['image_path'] else ["/images/products/default.jpg"],
|
||||
"attributes": {
|
||||
"diameter": row['diameter'],
|
||||
"length": row['length'],
|
||||
"wall_thickness": row['wall_thickness'],
|
||||
"color": row['color'],
|
||||
"amount": amount,
|
||||
"size": size,
|
||||
"diameter": str(row['diameter']) if row['diameter'] else None,
|
||||
"wall_thickness": str(row['wall_thickness']) if row['wall_thickness'] else None,
|
||||
"length": str(row['length']) if row['length'] and row['length'] > 0 else None,
|
||||
"stiffness_class": row['stiffness_class'],
|
||||
"application_type": row['application_type']
|
||||
}
|
||||
},
|
||||
"inStock": True
|
||||
})
|
||||
|
||||
return {
|
||||
@@ -157,9 +168,17 @@ def get_product_by_id(product_id: int, db_name: str = 'pipe_store.db') -> Option
|
||||
|
||||
full_description = generate_full_description(row)
|
||||
|
||||
# Вычисляем size и amount
|
||||
size = None
|
||||
if row['diameter'] and row['wall_thickness'] and row['length'] and row['length'] > 0:
|
||||
size = f"{row['diameter']}x{row['wall_thickness']}x{row['length']}"
|
||||
amount = get_pack_amount(product_id, row['diameter'])
|
||||
|
||||
# Формируем атрибуты
|
||||
attributes = {
|
||||
"color": row['color'],
|
||||
"amount": amount,
|
||||
"size": size,
|
||||
"diameter": str(row['diameter']) if row['diameter'] else None,
|
||||
"wall_thickness": str(row['wall_thickness']) if row['wall_thickness'] else None,
|
||||
"length": str(row['length']) if row['length'] and row['length'] > 0 else None,
|
||||
@@ -167,9 +186,6 @@ def get_product_by_id(product_id: int, db_name: str = 'pipe_store.db') -> Option
|
||||
"application_type": row['application_type'],
|
||||
}
|
||||
|
||||
if all([row['diameter'], row['wall_thickness'], row['length'] and row['length'] > 0]):
|
||||
attributes["size"] = f"{row['diameter']}x{row['wall_thickness']}x{row['length']}"
|
||||
|
||||
# Добавляем дополнительные атрибуты
|
||||
attributes.update(extra_attributes)
|
||||
|
||||
@@ -178,7 +194,7 @@ def get_product_by_id(product_id: int, db_name: str = 'pipe_store.db') -> Option
|
||||
"name": row['name'],
|
||||
"full_name": row['full_name'],
|
||||
"description": full_description,
|
||||
"price": None, # Цена не хранится в БД
|
||||
"price": None,
|
||||
"categoryId": row['category_id'],
|
||||
"images": images,
|
||||
"attributes": attributes,
|
||||
|
||||
Reference in new issue
Block a user