feat: Implement pagination and filtering for linked offers by integration

- Refactored `listLinkedOffersByIntegration` to `paginateLinkedOffersByIntegration` in `MarketplaceRepository`.
- Added pagination support with `page` and `per_page` filters.
- Introduced sorting options for offers.
- Created `listOfferChannelsByIntegration` method to retrieve distinct sales channels.
- Enhanced SQL queries to support dynamic filtering based on provided parameters.

feat: Add new fields for products and SKU generation

- Introduced new fields: `new_to_date`, `additional_message`, `additional_message_required`, and `additional_message_text` in the `products` table.
- Added `findAllSkus` method in `ProductRepository` to retrieve all SKUs.
- Created `ProductSkuGenerator` class to handle SKU generation based on a configurable format.
- Implemented `nextSku` method to generate the next available SKU.

feat: Enhance product settings management in the UI

- Added new settings page for product SKU format in `SettingsController`.
- Implemented form handling for saving SKU format settings.
- Updated the view to include SKU format configuration options.

feat: Implement cron job for refreshing ShopPro offer titles

- Created `ShopProOfferTitlesRefreshHandler` to handle the cron job for refreshing offer titles.
- Integrated with the `OfferImportService` to import offers from ShopPro.

docs: Update database schema documentation

- Added documentation for new fields in the `products` table and new cron job for offer title refresh.
- Documented the purpose and structure of the `app_settings` table.

migrations: Add necessary migrations for new features

- Created migration to add `products_sku_format` setting in `app_settings`.
- Added migration to introduce new fields in the `products` table.
- Created migration for the new cron job schedule for refreshing ShopPro offer titles.
This commit is contained in:
2026-03-01 22:05:21 +01:00
parent bcf078baac
commit d1576bc4ab
28 changed files with 1503 additions and 104 deletions

119
DOCS/DB_SCHEMA.md Normal file
View File

@@ -0,0 +1,119 @@
# Struktura bazy danych (orderPRO)
## Cel pliku
- Ten dokument opisuje aktualny schemat bazy danych na podstawie migracji w `database/migrations`.
- Aktualizuj ten plik przy każdej zmianie schematu (nowa tabela, kolumna, indeks, klucz obcy).
## Tabele i przeznaczenie
### `users`
- Uzytkownicy panelu.
- Klucz unikalny: `email`.
### `products`
- Glowna tabela produktow lokalnych.
- Najwazniejsze pola: `type`, `sku`, `ean`, `status`, `promoted`, `vat`, `weight`, `price_*`, `quantity`.
- Pola shopPRO: `new_to_date`, `additional_message`, `additional_message_required`, `additional_message_text`.
- Dodatkowe: `producer_id`, `producer_name`, `product_unit_id`, `custom_fields_json`.
- Soft delete: `deleted_at`.
### `product_translations`
- Globalne tresci produktu per jezyk (`lang`).
- Najwazniejsze pola: `name`, `short_description`, `description`, SEO, `security_information`.
- Unikalnosc: `(product_id, lang)`.
### `product_integration_translations`
- Nadpisania tresci produktu per integracja shopPRO.
- Pola: `name`, `short_description`, `description` (NULL = fallback do `product_translations`).
- Unikalnosc: `(product_id, integration_id)`.
### `product_images`
- Obrazy produktu (`storage_path`, `is_main`, `sort_order`).
### `product_categories`
- Relacja M:N produkt-kategoria (lokalna).
### `attributes`
- Definicje atrybutow wariantow.
### `attribute_translations`
- Tlumaczenia nazw atrybutow per jezyk.
### `attribute_values`
- Wartosci atrybutow (np. kolor, rozmiar), z opcjonalnym `impact_on_price`.
### `attribute_value_translations`
- Tlumaczenia wartosci atrybutow per jezyk.
### `product_variants`
- Warianty produktu.
- Najwazniejsze pola: `permutation_hash`, `sku`, `ean`, `status`, `price_*`, `weight`, `stock_0_buy`.
- Unikalnosc: `sku`, `(product_id, permutation_hash)`.
### `product_variant_attributes`
- Relacja wariant -> (atrybut, wartosc).
- Klucz glowny: `(variant_id, attribute_id)`.
### `product_change_log`
- Log zmian produktow (audyt JSON: `before_json`, `after_json`).
### `sales_channels`
- Slownik kanalow sprzedazy (`shoppro`, `allegro`, `erli`, ...).
### `product_channel_map`
- Mapowanie lokalnego produktu do kanalu/integracji i ID zewnetrznych.
- Najwazniejsze pola: `integration_id`, `external_product_id`, `external_variant_id`, `sync_state`, `link_type`, `link_status`, `confidence`.
- Pola audytowe powiazania: `linked_at`, `linked_by_user_id`, `unlinked_at`, `unlinked_by_user_id`, `sync_meta_json`.
### `channel_offers`
- Cache ofert zewnetrznych dla integracji.
- Najwazniejsze pola: `external_product_id`, `external_variant_id`, `external_offer_id`, `name` (tytul oferty), `sku`, `ean`, `offer_status`, `last_seen_at`, `payload_json`.
- Unikalnosc: `(integration_id, external_product_id, external_variant_id)`.
### `product_link_events`
- Historia zdarzen na powiazaniach (`product_channel_map`).
### `integrations`
- Konfiguracja instancji integracji (obecnie shopPRO).
- Najwazniejsze pola: `type`, `name`, `base_url`, `api_key_encrypted`, `timeout_seconds`, `is_active`.
### `integration_test_logs`
- Historia testow polaczen integracji.
### `cron_jobs`
- Kolejka jobow crona.
### `cron_schedules`
- Harmonogramy okresowych jobow.
- Aktualnie zawiera m.in.:
- `product_links_health_check`
- `shoppro_offer_titles_refresh` (odswiezanie tytulow ofert; domyslnie co 30 dni)
### `product_link_alerts`
- Alerty zdrowia powiazan produktu.
### `app_settings`
- Ustawienia aplikacyjne key-value.
- Przykładowe klucze: `cron_run_on_web`, `cron_web_limit`, `gs1_*`, `products_sku_format`.
## Relacje (skrot)
- `product_translations.product_id -> products.id`
- `product_integration_translations.product_id -> products.id`
- `product_integration_translations.integration_id -> integrations.id`
- `product_images.product_id -> products.id`
- `product_variants.product_id -> products.id`
- `product_variant_attributes.variant_id -> product_variants.id`
- `product_variant_attributes.attribute_id -> attributes.id`
- `product_variant_attributes.value_id -> attribute_values.id`
- `product_channel_map.product_id -> products.id`
- `product_channel_map.channel_id -> sales_channels.id`
- `product_channel_map.integration_id -> integrations.id`
- `channel_offers.integration_id -> integrations.id`
- `channel_offers.channel_id -> sales_channels.id`
- `product_link_events.product_channel_map_id -> product_channel_map.id`
- `product_link_alerts.product_channel_map_id -> product_channel_map.id`
## Jak utrzymywac dokument
1. Po dodaniu migracji zaktualizuj sekcje tabel/kolumn/relacji.
2. Gdy dodajesz nowe klucze do `app_settings`, dopisz je tu.
3. Przy zmianach harmonogramu crona zaktualizuj liste jobow w `cron_schedules`.