restore composer.json, add mysqli extension

This commit is contained in:
2026-04-13 17:12:58 +05:00
parent e0fe9bd156
commit 2154e97801
7 changed files with 198 additions and 1 deletions

View File

@@ -40,6 +40,8 @@ from core.apps.vendors.models import (
VendorproductModel,
CategoryModel,
SectionModel,
ProductAttributeModel,
ProductVariantModel,
)
# ── Firebase ulanish ─────────────────────────────────────────────────────────
@@ -141,6 +143,23 @@ def print_progress(current, total, created, updated, skipped, errors):
print(line, end="", flush=True)
def sync_attributes():
print("Firebase vendor_attributes kolleksiyasi o'qilmoqda…")
docs = db.collection("vendor_attributes").stream()
count = 0
for doc in docs:
data = doc.to_dict()
attr_id = data.get("id") or doc.id
name = data.get("title") or "Unnamed"
attr, created = ProductAttributeModel.objects.update_or_create(
firestore_id=attr_id,
defaults={"name": name}
)
count += 1
print(f"Jami {count} ta atribut sinxronlandi.\n")
# ── Asosiy funksiya ───────────────────────────────────────────────────────────
def sync_products(dry_run: bool = False, update: bool = False, after: datetime | None = None):
@@ -193,16 +212,43 @@ def sync_products(dry_run: bool = False, update: bool = False, after: datetime |
exists.section = section
if not dry_run:
exists.save()
product_obj = exists
updated += 1
else:
product_obj = None
if not dry_run:
VendorproductModel.objects.create(
product_obj = VendorproductModel.objects.create(
**product_data,
category=category,
section=section,
)
created += 1
# ── Variantlarni qayta ishlash ────────────────────────────────────
item_attr = data.get("item_attribute")
if item_attr and isinstance(item_attr, dict) and not dry_run:
# Agar product_obj yaratilgan bo'lsa (yoki mavjud bo'lsa)
target_product = product_obj or exists
if target_product:
variants_data = item_attr.get("variants") or []
for v_data in variants_data:
v_id = v_data.get("variant_id")
if not v_id:
continue
ProductVariantModel.objects.update_or_create(
firestore_id=v_id,
defaults={
"product": target_product,
"price": to_decimal(v_data.get("variant_price", 0)),
"sku": v_data.get("variant_sku"),
"quantity": to_int(v_data.get("variant_quantity", -1)),
"image_url": v_data.get("variant_image"),
"attribute_data": item_attr.get("attributes")
}
)
except Exception as e:
print(f"\n [XATO] {doc_id}: {e}")
errors += 1
@@ -251,4 +297,5 @@ if __name__ == "__main__":
print(f"[XATO] {e}")
sys.exit(1)
sync_attributes()
sync_products(dry_run=args.dry_run, update=args.update, after=after_dt)