diff --git a/config/__pycache__/__init__.cpython-311.pyc b/config/__pycache__/__init__.cpython-311.pyc index 423a636..d6476d6 100644 Binary files a/config/__pycache__/__init__.cpython-311.pyc and b/config/__pycache__/__init__.cpython-311.pyc differ diff --git a/config/__pycache__/settings.cpython-311.pyc b/config/__pycache__/settings.cpython-311.pyc index 96bce55..293bddf 100644 Binary files a/config/__pycache__/settings.cpython-311.pyc and b/config/__pycache__/settings.cpython-311.pyc differ diff --git a/config/__pycache__/urls.cpython-311.pyc b/config/__pycache__/urls.cpython-311.pyc index 0b85e94..8d9744a 100644 Binary files a/config/__pycache__/urls.cpython-311.pyc and b/config/__pycache__/urls.cpython-311.pyc differ diff --git a/config/__pycache__/wsgi.cpython-311.pyc b/config/__pycache__/wsgi.cpython-311.pyc index 9c49e09..27aaa70 100644 Binary files a/config/__pycache__/wsgi.cpython-311.pyc and b/config/__pycache__/wsgi.cpython-311.pyc differ diff --git a/config/settings.py b/config/settings.py index 291d043..d1b022f 100644 --- a/config/settings.py +++ b/config/settings.py @@ -133,7 +133,7 @@ AUTH_PASSWORD_VALIDATORS = [ # Internationalization # https://docs.djangoproject.com/en/5.2/topics/i18n/ -LANGUAGE_CODE = 'en-us' +LANGUAGE_CODE = 'uk' TIME_ZONE = 'UTC' diff --git a/core/__pycache__/__init__.cpython-311.pyc b/core/__pycache__/__init__.cpython-311.pyc index 74b1112..f6bacc0 100644 Binary files a/core/__pycache__/__init__.cpython-311.pyc and b/core/__pycache__/__init__.cpython-311.pyc differ diff --git a/core/__pycache__/admin.cpython-311.pyc b/core/__pycache__/admin.cpython-311.pyc index a5ed392..5f9034e 100644 Binary files a/core/__pycache__/admin.cpython-311.pyc and b/core/__pycache__/admin.cpython-311.pyc differ diff --git a/core/__pycache__/apps.cpython-311.pyc b/core/__pycache__/apps.cpython-311.pyc index 6f131d4..3015915 100644 Binary files a/core/__pycache__/apps.cpython-311.pyc and b/core/__pycache__/apps.cpython-311.pyc differ diff --git a/core/__pycache__/context_processors.cpython-311.pyc b/core/__pycache__/context_processors.cpython-311.pyc index 75bf223..927f7c5 100644 Binary files a/core/__pycache__/context_processors.cpython-311.pyc and b/core/__pycache__/context_processors.cpython-311.pyc differ diff --git a/core/__pycache__/models.cpython-311.pyc b/core/__pycache__/models.cpython-311.pyc index e061640..5f509be 100644 Binary files a/core/__pycache__/models.cpython-311.pyc and b/core/__pycache__/models.cpython-311.pyc differ diff --git a/core/__pycache__/urls.cpython-311.pyc b/core/__pycache__/urls.cpython-311.pyc index 5a69659..d858499 100644 Binary files a/core/__pycache__/urls.cpython-311.pyc and b/core/__pycache__/urls.cpython-311.pyc differ diff --git a/core/__pycache__/views.cpython-311.pyc b/core/__pycache__/views.cpython-311.pyc index 2a36fd6..d5c6a5a 100644 Binary files a/core/__pycache__/views.cpython-311.pyc and b/core/__pycache__/views.cpython-311.pyc differ diff --git a/core/admin.py b/core/admin.py index 8c38f3f..5f89531 100644 --- a/core/admin.py +++ b/core/admin.py @@ -1,3 +1,18 @@ from django.contrib import admin +from .models import Product, Variation -# Register your models here. +class VariationInline(admin.TabularInline): + model = Variation + extra = 0 + +@admin.register(Product) +class ProductAdmin(admin.ModelAdmin): + list_display = ('name', 'sku', 'price', 'stock_status', 'total_sales') + search_fields = ('name', 'sku', 'wp_id') + list_filter = ('stock_status',) + inlines = [VariationInline] + +@admin.register(Variation) +class VariationAdmin(admin.ModelAdmin): + list_display = ('product', 'size', 'price', 'stock_quantity') + search_fields = ('product__name', 'size') \ No newline at end of file diff --git a/core/management/__init__.py b/core/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/core/management/__pycache__/__init__.cpython-311.pyc b/core/management/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..fa911a1 Binary files /dev/null and b/core/management/__pycache__/__init__.cpython-311.pyc differ diff --git a/core/management/commands/__init__.py b/core/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/core/management/commands/__pycache__/__init__.cpython-311.pyc b/core/management/commands/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..2e9120f Binary files /dev/null and b/core/management/commands/__pycache__/__init__.cpython-311.pyc differ diff --git a/core/management/commands/__pycache__/sync_woo.cpython-311.pyc b/core/management/commands/__pycache__/sync_woo.cpython-311.pyc new file mode 100644 index 0000000..ca3b480 Binary files /dev/null and b/core/management/commands/__pycache__/sync_woo.cpython-311.pyc differ diff --git a/core/management/commands/sync_woo.py b/core/management/commands/sync_woo.py new file mode 100644 index 0000000..62622ab --- /dev/null +++ b/core/management/commands/sync_woo.py @@ -0,0 +1,93 @@ +import requests +from django.core.management.base import BaseCommand +from core.models import Product, Variation +from django.conf import settings +from decimal import Decimal + +class Command(BaseCommand): + help = "Sync products and variations from WooCommerce REST API" + + CK = "ck_e4107000984fd8752473cdd7974e41d227705215" + CS = "cs_c200854aaf7a9798feae9c0844219a36cb5e46bd" + BASE_URL = "https://theothers.com.ua/wp-json/wc/v3/" + + def handle(self, *args, **options): + self.stdout.write("Starting sync from WooCommerce...") + + # 1. Fetch Products + page = 1 + while True: + response = requests.get( + f"{self.BASE_URL}products", + auth=(self.CK, self.CS), + params={"page": page, "per_page": 100} + ) + + if response.status_code != 200: + self.stderr.write(f"Error fetching products: {response.text}") + break + + products_data = response.json() + if not products_data: + break + + for p in products_data: + # Map product fields + wp_id = str(p.get("id")) + name = p.get("name") + sku = p.get("sku") + price = Decimal(p.get("price") or 0) + stock_status = p.get("stock_status", "outofstock") + total_sales = p.get("total_sales", 0) + image_url = p.get("images")[0]["src"] if p.get("images") else None + + product, created = Product.objects.update_or_create( + wp_id=wp_id, + defaults={ + "name": name, + "sku": sku, + "price": price, + "stock_status": stock_status, + "total_sales": total_sales, + "image": image_url, + } + ) + + # 2. Fetch Variations for variable products + if p.get("type") == "variable": + v_response = requests.get( + f"{self.BASE_URL}products/{wp_id}/variations", + auth=(self.CK, self.CS), + params={"per_page": 100} + ) + + if v_response.status_code == 200: + variations_data = v_response.json() + # Clear old variations to keep it clean (optional, but safer for simple sync) + # Variation.objects.filter(product=product).delete() + + for v in variations_data: + # Use attributes to find size + attributes = v.get("attributes", []) + size = "Default" + for attr in attributes: + if attr.get("name").lower() in ["size", "розмір"]: + size = attr.get("option") + break + + v_price = Decimal(v.get("price") or 0) + v_stock = v.get("stock_quantity") or 0 + + Variation.objects.update_or_create( + product=product, + size=size, + defaults={ + "price": v_price, + "stock_quantity": v_stock, + } + ) + + self.stdout.write(f"Processed page {page}") + page += 1 + + self.stdout.write(self.style.SUCCESS("Successfully synced WooCommerce data!")) diff --git a/core/migrations/0001_initial.py b/core/migrations/0001_initial.py new file mode 100644 index 0000000..b4ced57 --- /dev/null +++ b/core/migrations/0001_initial.py @@ -0,0 +1,49 @@ +# Generated by Django 5.2.7 on 2026-02-22 20:39 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Product', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('wp_id', models.CharField(max_length=50, unique=True, verbose_name='ID WordPress')), + ('image', models.URLField(blank=True, max_length=500, null=True, verbose_name='Фото')), + ('name', models.CharField(max_length=255, verbose_name='Назва товару')), + ('sku', models.CharField(blank=True, max_length=100, null=True, verbose_name='Артикул (SKU)')), + ('price', models.DecimalField(decimal_places=2, max_digits=12, verbose_name='Ціна (грн)')), + ('stock_status', models.CharField(choices=[('instock', 'В наявності'), ('outofstock', 'Немає в наявності')], max_length=20, verbose_name='Статус')), + ('total_sales', models.IntegerField(default=0, verbose_name='Продано')), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ], + options={ + 'verbose_name': 'Товар', + 'verbose_name_plural': 'Товари', + 'ordering': ['-total_sales'], + }, + ), + migrations.CreateModel( + name='Variation', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('size', models.CharField(max_length=50, verbose_name='Розмір')), + ('price', models.DecimalField(decimal_places=2, max_digits=12, verbose_name='Ціна варіації')), + ('stock_quantity', models.IntegerField(default=0, verbose_name='Залишок на складі')), + ('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='variations', to='core.product', verbose_name='Основний товар')), + ], + options={ + 'verbose_name': 'Варіація', + 'verbose_name_plural': 'Варіації', + }, + ), + ] diff --git a/core/migrations/__pycache__/0001_initial.cpython-311.pyc b/core/migrations/__pycache__/0001_initial.cpython-311.pyc new file mode 100644 index 0000000..2129629 Binary files /dev/null and b/core/migrations/__pycache__/0001_initial.cpython-311.pyc differ diff --git a/core/migrations/__pycache__/__init__.cpython-311.pyc b/core/migrations/__pycache__/__init__.cpython-311.pyc index 9c833c8..6b6bd61 100644 Binary files a/core/migrations/__pycache__/__init__.cpython-311.pyc and b/core/migrations/__pycache__/__init__.cpython-311.pyc differ diff --git a/core/models.py b/core/models.py index 71a8362..0bb5926 100644 --- a/core/models.py +++ b/core/models.py @@ -1,3 +1,39 @@ from django.db import models -# Create your models here. +class Product(models.Model): + STOCK_STATUS_CHOICES = [ + ('instock', 'В наявності'), + ('outofstock', 'Немає в наявності'), + ] + + wp_id = models.CharField(max_length=50, unique=True, verbose_name="ID WordPress") + image = models.URLField(max_length=500, blank=True, null=True, verbose_name="Фото") + name = models.CharField(max_length=255, verbose_name="Назва товару") + sku = models.CharField(max_length=100, blank=True, null=True, verbose_name="Артикул (SKU)") + price = models.DecimalField(max_digits=12, decimal_places=2, verbose_name="Ціна (грн)") + stock_status = models.CharField(max_length=20, choices=STOCK_STATUS_CHOICES, verbose_name="Статус") + total_sales = models.IntegerField(default=0, verbose_name="Продано") + + created_at = models.DateTimeField(auto_now_add=True) + updated_at = models.DateTimeField(auto_now=True) + + def __str__(self): + return self.name + + class Meta: + verbose_name = "Товар" + verbose_name_plural = "Товари" + ordering = ['-total_sales'] + +class Variation(models.Model): + product = models.ForeignKey(Product, on_delete=models.CASCADE, related_name='variations', verbose_name="Основний товар") + size = models.CharField(max_length=50, verbose_name="Розмір") + price = models.DecimalField(max_digits=12, decimal_places=2, verbose_name="Ціна варіації") + stock_quantity = models.IntegerField(default=0, verbose_name="Залишок на складі") + + def __str__(self): + return f"{self.product.name} - {self.size}" + + class Meta: + verbose_name = "Варіація" + verbose_name_plural = "Варіації" \ No newline at end of file diff --git a/core/templates/base.html b/core/templates/base.html index 1e7e5fb..3987c48 100644 --- a/core/templates/base.html +++ b/core/templates/base.html @@ -1,25 +1,43 @@ - - + - - {% block title %}Knowledge Base{% endblock %} - {% if project_description %} - - - - {% endif %} - {% if project_image_url %} - - - {% endif %} - {% load static %} - - {% block head %}{% endblock %} + + + {% block title %}Адмін-панель WooCommerce{% endblock %} + + + + + + + + + + {% load static %} + + + {% block head %}{% endblock %} - - {% block content %}{% endblock %} - - + + +
+ {% block content %}{% endblock %} +
+ + + + + {% block scripts %}{% endblock %} + + \ No newline at end of file diff --git a/core/templates/core/index.html b/core/templates/core/index.html index faec813..116b392 100644 --- a/core/templates/core/index.html +++ b/core/templates/core/index.html @@ -1,145 +1,77 @@ -{% extends "base.html" %} +{% extends 'base.html' %} +{% load static %} -{% block title %}{{ project_name }}{% endblock %} - -{% block head %} - - - - -{% endblock %} +{% block title %}Товари — Адмін-панель{% endblock %} {% block content %} -
-
-

Analyzing your requirements and generating your app…

-
- Loading… +
+

Товари

+
+
+ + +
-

AppWizzy AI is collecting your requirements and applying the first changes.

-

This page will refresh automatically as the plan is implemented.

-

- Runtime: Django {{ django_version }} · Python {{ python_version }} - — UTC {{ current_time|date:"Y-m-d H:i:s" }} -

-
-
- -{% endblock %} \ No newline at end of file + + +
+
+ + + + + + + + + + + + + + {% for p in products %} + + + + + + + + + + {% empty %} + + + + {% endfor %} + +
ФотоНазва товаруАртикул (SKU)Ціна (грн)СтатусПроданоДії
+ {% if p.image %} + {{ p.name }} + {% else %} +
N/A
+ {% endif %} +
+
{{ p.name }}
+
WP ID: {{ p.wp_id }}
+
{{ p.sku|default:"-" }} +
{{ p.price }} ₴
+
+ + {% if p.stock_status == 'instock' %} + В наявності + {% else %} + Немає + {% endif %} + + + {{ p.total_sales }} + + Деталі +
+
Товарів не знайдено.
+
Спробуйте інший запит або запустіть синхронізацію.
+
+
+
+{% endblock %} diff --git a/core/templates/core/product_detail.html b/core/templates/core/product_detail.html new file mode 100644 index 0000000..adc4326 --- /dev/null +++ b/core/templates/core/product_detail.html @@ -0,0 +1,95 @@ +{% extends 'base.html' %} +{% load static %} + +{% block title %}{{ product.name }} — Деталі товару{% endblock %} + +{% block content %} +
+ + + + + Назад до списку + +
+

{{ product.name }}

+
WordPress ID: {{ product.wp_id }}
+
+
+ +
+ +
+
+ {% if product.image %} + {{ product.name }} + {% else %} +
N/A
+ {% endif %} +
+
+
Ціна
+
{{ product.price }} ₴
+
+
+
Артикул (SKU)
+
{{ product.sku|default:"-" }}
+
+
+
Статус
+ + {% if product.stock_status == 'instock' %} + В наявності + {% else %} + Немає в наявності + {% endif %} + +
+
+
Усього продано
+
{{ product.total_sales }}
+
+
+
+
+ + +
+
+
+

Варіації (Розміри)

+
+
+
+ + + + + + + + + + {% for v in variations %} + + + + + + {% empty %} + + + + {% endfor %} + +
РозмірЦіна варіаціїЗалишок на складі
{{ v.size }}{{ v.price }} ₴ + + {{ v.stock_quantity }} + +
Варіацій для цього товару не знайдено.
+
+
+
+
+
+{% endblock %} diff --git a/core/urls.py b/core/urls.py index 6299e3d..9f96454 100644 --- a/core/urls.py +++ b/core/urls.py @@ -1,7 +1,9 @@ from django.urls import path +from . import views -from .views import home +app_name = 'core' urlpatterns = [ - path("", home, name="home"), -] + path('', views.product_list, name='index'), + path('product//', views.product_detail, name='product_detail'), +] \ No newline at end of file diff --git a/core/views.py b/core/views.py index c9aed12..b3ce818 100644 --- a/core/views.py +++ b/core/views.py @@ -1,25 +1,26 @@ -import os -import platform +from django.shortcuts import render, get_object_or_404 +from .models import Product, Variation +from django.db.models import Q -from django import get_version as django_version -from django.shortcuts import render -from django.utils import timezone +def product_list(request): + query = request.GET.get('q') + products = Product.objects.all() + + if query: + products = products.filter( + Q(name__icontains=query) | Q(sku__icontains=query) + ) + + return render(request, 'core/index.html', { + 'products': products, + 'query': query + }) - -def home(request): - """Render the landing screen with loader and environment details.""" - host_name = request.get_host().lower() - agent_brand = "AppWizzy" if host_name == "appwizzy.com" else "Flatlogic" - now = timezone.now() - - context = { - "project_name": "New Style", - "agent_brand": agent_brand, - "django_version": django_version(), - "python_version": platform.python_version(), - "current_time": now, - "host_name": host_name, - "project_description": os.getenv("PROJECT_DESCRIPTION", ""), - "project_image_url": os.getenv("PROJECT_IMAGE_URL", ""), - } - return render(request, "core/index.html", context) +def product_detail(request, pk): + product = get_object_or_404(Product, pk=pk) + variations = product.variations.all() + + return render(request, 'core/product_detail.html', { + 'product': product, + 'variations': variations + }) \ No newline at end of file diff --git a/static/css/custom.css b/static/css/custom.css index 925f6ed..5aea72d 100644 --- a/static/css/custom.css +++ b/static/css/custom.css @@ -1,4 +1,101 @@ -/* Custom styles for the application */ -body { - font-family: system-ui, -apple-system, sans-serif; +:root { + --apple-bg: #FBFBFB; + --apple-card: #FFFFFF; + --apple-text: #1D1D1F; + --apple-text-muted: #86868B; + --apple-accent: #0071E3; + --apple-border: rgba(0,0,0,0.1); } + +body { + background-color: var(--apple-bg); + color: var(--apple-text); + font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; + -webkit-font-smoothing: antialiased; +} + +.navbar { + background-color: rgba(255, 255, 255, 0.8); + backdrop-filter: saturate(180%) blur(20px); + border-bottom: 1px solid var(--apple-border); + padding: 0.8rem 1rem; +} + +.card { + background: var(--apple-card); + border: 1px solid var(--apple-border); + border-radius: 12px; + box-shadow: 0 4px 12px rgba(0,0,0,0.05); + transition: transform 0.2s ease, box-shadow 0.2s ease; + overflow: hidden; +} + +.card:hover { + box-shadow: 0 8px 24px rgba(0,0,0,0.08); +} + +.table { + margin-bottom: 0; +} + +.table thead th { + background: #F5F5F7; + border-bottom: 1px solid var(--apple-border); + color: var(--apple-text-muted); + font-weight: 500; + font-size: 0.75rem; + text-transform: uppercase; + letter-spacing: 0.05em; + padding: 12px 16px; +} + +.table tbody td { + padding: 16px; + vertical-align: middle; + border-bottom: 1px solid var(--apple-border); +} + +.btn-primary { + background-color: var(--apple-accent); + border: none; + border-radius: 8px; + font-weight: 500; + padding: 8px 20px; +} + +.btn-primary:hover { + background-color: #0077ED; +} + +.product-img { + width: 48px; + height: 48px; + object-fit: cover; + border-radius: 8px; + background-color: #eee; +} + +.status-instock { + color: #34C759; + font-weight: 600; +} + +.status-outofstock { + color: #FF3B30; + font-weight: 600; +} + +.search-input { + border-radius: 10px; + border: 1px solid var(--apple-border); + background-color: #F5F5F7; + padding: 10px 16px; + font-size: 0.9rem; +} + +.search-input:focus { + background-color: #fff; + box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.1); + border-color: var(--apple-accent); + outline: none; +} \ No newline at end of file