feat(47-shipment-created-automation): immediate shipment automation trigger

Phase 47 complete:

- add event shipment.created triggered immediately after shipment creation

- add action update_shipment_status with real-change guard and chain-safe emit

- update automation UI/options, docs, and PAUL state artifacts
This commit is contained in:
2026-03-28 13:24:20 +01:00
parent d3f4bdaecd
commit ad9087d5e4
17 changed files with 784 additions and 310 deletions

View File

@@ -1,5 +1,40 @@
# Tech Changelog
## 2026-03-28 (Phase 47 - Shipment Creation Automation, Plan 01)
- Automatyzacja:
- dodano nowe zdarzenie `shipment.created` (UI: `Utworzenie przesylki`),
- trigger jest uruchamiany natychmiast po sukcesie `ShipmentController::create()` oraz `ShipmentController::createManual()`,
- kontekst triggera zawiera m.in. `package_id`, `provider`, `tracking_number`, `package_status`, `delivery_status`.
- Dodano nowy typ akcji automatyzacji `update_shipment_status` (UI: `Zmiana statusu przesylki`):
- walidacja konfiguracji przez `AutomationController` (`shipment_status_key` -> `status_key`),
- wykonanie przez `AutomationService::handleUpdateShipmentStatus(...)`,
- aktualizacja `delivery_status` tylko przy realnej zmianie (bez falszywych triggerow),
- po zmianie statusu emitowane jest `shipment.status_changed` z kontekstem zmiany.
- Rozszerzono `AutomationService` o zaleznosc `ShipmentPackageRepository`:
- nowa metoda pomocnicza `ShipmentPackageRepository::findLatestByOrderId(int): ?array` (fallback wyboru paczki dla akcji).
- UI automatyzacji (`resources/views/automation/form.php`, `resources/views/automation/index.php`, `public/assets/js/modules/automation-form.js`) rozszerzono o:
- event `Utworzenie przesylki`,
- akcje `Zmiana statusu przesylki` z wyborem docelowego statusu biznesowego.
- Aktualizacja DI:
- `routes/web.php` i `src/Modules/Cron/CronHandlerFactory.php` przekazuja `ShipmentPackageRepository` do `AutomationService`,
- `ShipmentController` otrzymuje `AutomationService` jako zaleznosc konstruktora.
## 2026-03-28 (Allegro Status Push - orderPRO -> Allegro)
- Zaimplementowano kierunek synchronizacji statusow `orderpro_to_allegro` w `AllegroStatusSyncService`.
- `AllegroStatusSyncService`:
- pobiera reczne zmiany statusow (`order_status_history.change_source=manual`) dla zamowien Allegro,
- buduje reverse mapping (`orderpro_status_code -> allegro_status_code`) na podstawie `allegro_order_status_mappings`,
- pushuje statusy do API Allegro i raportuje `pushed/skipped/failed`,
- aktualizuje kursor `integration_order_sync_state.last_status_pushed_at`.
- Nowa metoda `AllegroApiClient::updateCheckoutFormFulfillment()`:
- PUT `/order/checkout-forms/{id}/fulfillment`,
- body JSON: `{"status":"<ALLEGRO_STATUS>"}`.
- `AllegroOrderSyncStateRepository`: dodano obsluge kursora push (`getLastStatusPushedAt`, `updateLastStatusPushedAt`).
- `AllegroStatusMappingRepository`: dodano reverse map builder `buildOrderproToAllegroMap()`.
- UI `Ustawienia > Integracje > Allegro > Ustawienia`:
- odblokowano wybor opcji `orderPRO -> Allegro` (usunieto `disabled` i dopisek `(wkrotce)`),
- zaktualizowano opis hintu kierunku synchronizacji.
- Dodano testy jednostkowe `tests/Unit/AllegroStatusSyncServiceTest.php` dla scenariuszy push/skip/fail/retry-401.
## 2026-03-27 (ShopPRO Status Push — orderPRO -> shopPRO)
- Zaimplementowano kierunek synchronizacji statusow `orderpro_to_shoppro` w `ShopproStatusSyncService`.
- Nowa metoda `ShopproApiClient::updateOrderStatus()` — PUT `/api.php?endpoint=orders&action=change_status&id={id}`.
@@ -702,3 +737,5 @@