fix(db): Added db to actual price
This commit is contained in:
1 parent
39cc73d71a
commit
beb94d2b0d
4 files changed
+364
-134
No files matched your search
+94
-28
@@ -23,21 +23,29 @@ def add_category(conn, name, description=None, parent_id=None, image_path=None):
|
||||
def add_filter(conn, name, filter_key, filter_type='single'):
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute('''
|
||||
INSERT OR IGNORE INTO filters (name, filter_key, filter_type)
|
||||
VALUES (?, ?, ?)
|
||||
''', (name, filter_key, filter_type))
|
||||
try:
|
||||
cursor.execute('''
|
||||
INSERT OR IGNORE INTO filters (name, filter_key, filter_type)
|
||||
VALUES (?, ?, ?)
|
||||
''', (name, filter_key, filter_type))
|
||||
except sqlite3.Error as e:
|
||||
log.error(f"Ошибка при добавлении фильтра: {e}")
|
||||
|
||||
def parse_product_data(product_text):
|
||||
"""Парсинг данных продукта из текста"""
|
||||
# Определяем тип применения
|
||||
application_match = re.search(r'(ВНУТРЕННЕЙ|НАРУЖНОЙ)', product_text)
|
||||
application_type = "внутренняя" if application_match and application_match.group(1) == "ВНУТРЕННЕЙ" else "наружная"
|
||||
|
||||
# Определяем цвет
|
||||
color_match = re.search(r'цвет\s+([^)]+)', product_text)
|
||||
color = color_match.group(1).strip() if color_match else None
|
||||
|
||||
# Определяем класс жесткости
|
||||
stiffness_match = re.search(r'SN(\d+)', product_text)
|
||||
stiffness_class = f"SN{stiffness_match.group(1)}" if stiffness_match else None
|
||||
|
||||
# Определяем размеры
|
||||
size_match = re.search(r'(\d+)х(\d+[,.]?\d*)х(\d+)', product_text.replace(',', '.'))
|
||||
if size_match:
|
||||
diameter = int(size_match.group(1))
|
||||
@@ -46,7 +54,16 @@ def parse_product_data(product_text):
|
||||
else:
|
||||
diameter = wall_thickness = length = None
|
||||
|
||||
short_name = f"Труба ПВХ {diameter}мм {application_type} {length}мм"
|
||||
# Для фитингов может не быть длины
|
||||
if not length and diameter:
|
||||
# Проверяем на отводы
|
||||
angle_match = re.search(r'(\d+)°', product_text)
|
||||
if angle_match:
|
||||
length = None
|
||||
else:
|
||||
length = 0
|
||||
|
||||
short_name = f"Труба ПВХ {diameter}мм {application_type} {length}мм" if diameter else product_text[:50]
|
||||
|
||||
return {
|
||||
'short_name': short_name,
|
||||
@@ -59,11 +76,53 @@ def parse_product_data(product_text):
|
||||
'stiffness_class': stiffness_class
|
||||
}
|
||||
|
||||
def add_product(conn, product_text, category_id, image_path=None):
|
||||
"""Добавление товара с парсингом параметров и изображением"""
|
||||
def add_product(conn, product_text, category_id, image_path=None,
|
||||
diameter=None, wall_thickness=None, length=None,
|
||||
color=None, application_type=None, stiffness_class=None,
|
||||
fitting_type=None, angle=None):
|
||||
"""
|
||||
Добавление товара с возможностью явного указания параметров
|
||||
Если параметры не указаны, они парсятся из product_text
|
||||
"""
|
||||
cursor = conn.cursor()
|
||||
|
||||
product_data = parse_product_data(product_text)
|
||||
# Если параметры не указаны явно, парсим из текста
|
||||
if any(p is None for p in [diameter, wall_thickness, length, color, application_type, stiffness_class]):
|
||||
product_data = parse_product_data(product_text)
|
||||
diameter = diameter or product_data['diameter']
|
||||
wall_thickness = wall_thickness or product_data['wall_thickness']
|
||||
length = length or product_data['length']
|
||||
color = color or product_data['color']
|
||||
application_type = application_type or product_data['application_type']
|
||||
stiffness_class = stiffness_class or product_data['stiffness_class']
|
||||
|
||||
# Формируем короткое имя
|
||||
if diameter and length:
|
||||
name = f"Труба ПВХ {diameter}мм {application_type} {length}мм"
|
||||
elif fitting_type and diameter:
|
||||
name = f"{fitting_type.capitalize()} ПВХ {diameter}мм"
|
||||
else:
|
||||
name = product_text[:100]
|
||||
|
||||
# Формируем описание
|
||||
description_parts = []
|
||||
if fitting_type:
|
||||
description_parts.append(f"{fitting_type.capitalize()} для канализационных систем")
|
||||
else:
|
||||
description_parts.append(f"Труба ПВХ для {application_type} канализации")
|
||||
|
||||
if diameter:
|
||||
description_parts.append(f"Диаметр: {diameter}мм")
|
||||
if wall_thickness:
|
||||
description_parts.append(f"Толщина стенки: {wall_thickness}мм")
|
||||
if length and length > 0:
|
||||
description_parts.append(f"Длина: {length}мм")
|
||||
if stiffness_class:
|
||||
description_parts.append(f"Класс жесткости: {stiffness_class}")
|
||||
if angle:
|
||||
description_parts.append(f"Угол: {angle}")
|
||||
|
||||
description = ", ".join(description_parts)
|
||||
|
||||
try:
|
||||
cursor.execute('''
|
||||
@@ -73,33 +132,40 @@ def add_product(conn, product_text, category_id, image_path=None):
|
||||
application_type, stiffness_class, image_path
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
''', (
|
||||
product_data['short_name'],
|
||||
product_data['full_name'],
|
||||
f"Труба ПВХ для {product_data['application_type']} канализации",
|
||||
name,
|
||||
product_text,
|
||||
description,
|
||||
category_id,
|
||||
product_data['diameter'],
|
||||
product_data['wall_thickness'],
|
||||
product_data['length'],
|
||||
product_data['color'],
|
||||
product_data['application_type'],
|
||||
product_data['stiffness_class'],
|
||||
diameter,
|
||||
wall_thickness,
|
||||
length if length and length > 0 else None,
|
||||
color,
|
||||
application_type,
|
||||
stiffness_class,
|
||||
image_path
|
||||
))
|
||||
|
||||
product_id = cursor.lastrowid
|
||||
|
||||
filters_to_add = [
|
||||
('diameter', str(product_data['diameter'])),
|
||||
('length', str(product_data['length'])),
|
||||
('application_type', product_data['application_type']),
|
||||
('color', product_data['color']),
|
||||
]
|
||||
# Добавляем фильтры для товара
|
||||
filters_to_add = []
|
||||
|
||||
if product_data['wall_thickness']:
|
||||
filters_to_add.append(('wall_thickness', str(product_data['wall_thickness'])))
|
||||
|
||||
if product_data['stiffness_class']:
|
||||
filters_to_add.append(('stiffness_class', product_data['stiffness_class']))
|
||||
if diameter:
|
||||
filters_to_add.append(('diameter', str(diameter)))
|
||||
if length and length > 0:
|
||||
filters_to_add.append(('length', str(length)))
|
||||
if application_type:
|
||||
filters_to_add.append(('application_type', application_type))
|
||||
if color:
|
||||
filters_to_add.append(('color', color))
|
||||
if wall_thickness:
|
||||
filters_to_add.append(('wall_thickness', str(wall_thickness)))
|
||||
if stiffness_class:
|
||||
filters_to_add.append(('stiffness_class', stiffness_class))
|
||||
if fitting_type:
|
||||
filters_to_add.append(('fitting_type', fitting_type))
|
||||
if angle:
|
||||
filters_to_add.append(('angle', angle))
|
||||
|
||||
for filter_key, value in filters_to_add:
|
||||
if value:
|
||||
|
||||
Reference in new issue
Block a user