feat(integrations): добавлена заготовка интеграции Recommerce
- Создана структура marketplaces/ для маркетплейсов - Модели: MarketplaceIntegration, WooCommerceIntegration, RecommerceIntegration - Сервисы: MarketplaceService, WooCommerceService, RecommerceService - RecommerceService содержит методы для работы с API: - test_connection(), sync(), fetch_products() - push_product(), update_stock(), update_price() - IntegrationConfig обновлён с новой интеграцией Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
9
myproject/integrations/models/marketplaces/__init__.py
Normal file
9
myproject/integrations/models/marketplaces/__init__.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from .base import MarketplaceIntegration
|
||||
from .woocommerce import WooCommerceIntegration
|
||||
from .recommerce import RecommerceIntegration
|
||||
|
||||
__all__ = [
|
||||
'MarketplaceIntegration',
|
||||
'WooCommerceIntegration',
|
||||
'RecommerceIntegration',
|
||||
]
|
||||
42
myproject/integrations/models/marketplaces/base.py
Normal file
42
myproject/integrations/models/marketplaces/base.py
Normal file
@@ -0,0 +1,42 @@
|
||||
from django.db import models
|
||||
from ..base import BaseIntegration, IntegrationType
|
||||
|
||||
|
||||
class MarketplaceIntegration(BaseIntegration):
|
||||
"""
|
||||
Базовая модель для интеграций с маркетплейсами.
|
||||
Наследует BaseIntegration и добавляет специфичные поля.
|
||||
"""
|
||||
|
||||
integration_type = models.CharField(
|
||||
max_length=20,
|
||||
choices=IntegrationType.choices,
|
||||
default=IntegrationType.MARKETPLACE,
|
||||
editable=False
|
||||
)
|
||||
|
||||
# URL магазина
|
||||
store_url = models.URLField(
|
||||
blank=True,
|
||||
verbose_name="URL магазина",
|
||||
help_text="Адрес магазина (например, https://shop.example.com)"
|
||||
)
|
||||
|
||||
# Автоматическая синхронизация товаров
|
||||
auto_sync_products = models.BooleanField(
|
||||
default=False,
|
||||
verbose_name="Авто-синхронизация товаров",
|
||||
help_text="Автоматически обновлять товары на маркетплейсе"
|
||||
)
|
||||
|
||||
# Импорт заказов
|
||||
import_orders = models.BooleanField(
|
||||
default=False,
|
||||
verbose_name="Импорт заказов",
|
||||
help_text="Импортировать заказы с маркетплейса"
|
||||
)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
verbose_name = "Интеграция с маркетплейсом"
|
||||
verbose_name_plural = "Интеграции с маркетплейсами"
|
||||
59
myproject/integrations/models/marketplaces/recommerce.py
Normal file
59
myproject/integrations/models/marketplaces/recommerce.py
Normal file
@@ -0,0 +1,59 @@
|
||||
from django.db import models
|
||||
from .base import MarketplaceIntegration
|
||||
|
||||
|
||||
class RecommerceIntegration(MarketplaceIntegration):
|
||||
"""
|
||||
Интеграция с Recommerce.
|
||||
Recommerce - сервис для управления товарами на маркетплейсах.
|
||||
"""
|
||||
|
||||
# API endpoint (может отличаться от store_url)
|
||||
api_endpoint = models.URLField(
|
||||
blank=True,
|
||||
verbose_name="API Endpoint",
|
||||
help_text="URL API Recommerce (если отличается от URL магазина)"
|
||||
)
|
||||
|
||||
# API токен (основной метод авторизации)
|
||||
api_token = models.CharField(
|
||||
max_length=500,
|
||||
blank=True,
|
||||
verbose_name="API Токен",
|
||||
help_text="Токен авторизации Recommerce API"
|
||||
)
|
||||
|
||||
# ID магазина в системе Recommerce
|
||||
merchant_id = models.CharField(
|
||||
max_length=100,
|
||||
blank=True,
|
||||
verbose_name="ID магазина",
|
||||
help_text="Идентификатор магазина в Recommerce"
|
||||
)
|
||||
|
||||
# Синхронизация цен
|
||||
sync_prices = models.BooleanField(
|
||||
default=True,
|
||||
verbose_name="Синхронизировать цены",
|
||||
help_text="Обновлять цены на маркетплейсе"
|
||||
)
|
||||
|
||||
# Синхронизация остатков
|
||||
sync_stock = models.BooleanField(
|
||||
default=True,
|
||||
verbose_name="Синхронизировать остатки",
|
||||
help_text="Обновлять остатки на маркетплейсе"
|
||||
)
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Recommerce"
|
||||
verbose_name_plural = "Recommerce"
|
||||
managed = False # Пока заготовка - без создания таблицы
|
||||
|
||||
def __str__(self):
|
||||
return f"Recommerce: {self.name or self.merchant_id}"
|
||||
|
||||
@property
|
||||
def is_configured(self) -> bool:
|
||||
"""Recommerce требует api_token"""
|
||||
return bool(self.api_token)
|
||||
40
myproject/integrations/models/marketplaces/woocommerce.py
Normal file
40
myproject/integrations/models/marketplaces/woocommerce.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from django.db import models
|
||||
from .base import MarketplaceIntegration
|
||||
|
||||
|
||||
class WooCommerceIntegration(MarketplaceIntegration):
|
||||
"""Интеграция с WooCommerce"""
|
||||
|
||||
# WooCommerce-specific credentials
|
||||
consumer_key = models.CharField(
|
||||
max_length=255,
|
||||
blank=True,
|
||||
verbose_name="Consumer Key"
|
||||
)
|
||||
|
||||
consumer_secret = models.CharField(
|
||||
max_length=255,
|
||||
blank=True,
|
||||
verbose_name="Consumer Secret"
|
||||
)
|
||||
|
||||
# API версия (WooCommerce REST API v1, v2, v3)
|
||||
api_version = models.CharField(
|
||||
max_length=10,
|
||||
default='v3',
|
||||
blank=True,
|
||||
verbose_name="Версия API"
|
||||
)
|
||||
|
||||
class Meta:
|
||||
verbose_name = "WooCommerce"
|
||||
verbose_name_plural = "WooCommerce"
|
||||
managed = False # Пока заготовка - без создания таблицы
|
||||
|
||||
def __str__(self):
|
||||
return f"WooCommerce: {self.name or self.store_url}"
|
||||
|
||||
@property
|
||||
def is_configured(self) -> bool:
|
||||
"""WooCommerce требует consumer_key и consumer_secret"""
|
||||
return bool(self.consumer_key and self.consumer_secret)
|
||||
Reference in New Issue
Block a user