Files
orderPRO/.paul/phases/84-order-imported-automation-event/84-01-PLAN.md
2026-04-07 22:39:16 +02:00

7.4 KiB

phase, plan, type, wave, depends_on, files_modified, autonomous, delegation
phase plan type wave depends_on files_modified autonomous delegation
84-order-imported-automation-event 01 execute 1
src/Modules/Automation/AutomationController.php
src/Modules/Settings/AllegroOrderImportService.php
src/Modules/Settings/ShopproOrdersSyncService.php
src/Modules/Cron/CronHandlerFactory.php
resources/views/automation/form.php
resources/views/automation/index.php
routes/web.php
true off
## Goal Dodac nowe zdarzenie automatyzacji `order.imported` wyzwalane przy kazdym pobraniu zamowienia (Allegro i shopPRO). Umozliwi tworzenie regul automatycznych reagujacych na import zamowien (np. wyslij e-mail, zmien status, wystaw paragon).

Purpose

Obecnie automatyzacja reaguje na zmiany statusow, przesylki, platnosci i paragony. Brakuje zdarzenia na sam moment pobrania zamowienia — user nie moze automatycznie reagowac na nowe zamowienie.

Output

  • Nowy event type order.imported w ALLOWED_EVENTS
  • Trigger w AllegroOrderImportService i ShopproOrdersSyncService
  • Warunek integration dostepny dla tego eventu (filtrowanie po zrodle)
  • Etykieta w UI automatyzacji
## Project Context @.paul/PROJECT.md @.paul/ROADMAP.md @.paul/STATE.md

Source Files

@src/Modules/Automation/AutomationController.php — ALLOWED_EVENTS (linia 19), ALLOWED_CONDITION_TYPES (linia 20) @src/Modules/Automation/AutomationService.php — trigger() method, evaluateConditions() @src/Modules/Settings/AllegroOrderImportService.php — importSingleOrder() linia 69-96 @src/Modules/Settings/ShopproOrdersSyncService.php — processOrder() linia 225-269 @src/Modules/Cron/CronHandlerFactory.php — kompozycja obiektow @resources/views/automation/form.php — $eventLabels (linia 9) @resources/views/automation/index.php — $eventLabels (linia 14)

<acceptance_criteria>

AC-1: Event zarejestrowany w systemie

Given system automatyzacji z lista dozwolonych zdarzen
When user tworzy nowa regule automatyzacji
Then w dropdownie zdarzen dostepna jest opcja "Pobranie zamowienia" (order.imported)

AC-2: Event wyzwalany przy imporcie Allegro

Given aktywna regula z event_type = order.imported
When zamowienie zostaje zaimportowane z Allegro (nowe lub re-import)
Then AutomationService.trigger('order.imported', orderId, context) jest wywolany
  And context zawiera: source, created (bool), integration_id

AC-3: Event wyzwalany przy imporcie shopPRO

Given aktywna regula z event_type = order.imported
When zamowienie zostaje zaimportowane z shopPRO
Then AutomationService.trigger('order.imported', orderId, context) jest wywolany
  And context zawiera: source, created (bool), integration_id

AC-4: Warunek integration dziala z nowym eventem

Given regula order.imported z warunkiem integration = [konkretna integracja]
When zamowienie jest importowane z innej integracji
Then regula NIE jest wykonywana (warunek nie speliony)

</acceptance_criteria>

Task 1: Rejestracja eventu + UI src/Modules/Automation/AutomationController.php, resources/views/automation/form.php, resources/views/automation/index.php 1. W AutomationController dodac 'order.imported' do ALLOWED_EVENTS (linia 19) 2. W resources/views/automation/form.php dodac do $eventLabels: 'order.imported' => 'Pobranie zamowienia' 3. W resources/views/automation/index.php dodac to samo do $eventLabels Avoid: nie zmieniac ALLOWED_CONDITION_TYPES — warunek 'integration' juz istnieje i dziala PHP lint na 3 plikach; event widoczny w dropdownie formularza AC-1 satisfied: event order.imported zarejestrowany i widoczny w UI Task 2: Trigger w AllegroOrderImportService src/Modules/Settings/AllegroOrderImportService.php, src/Modules/Cron/CronHandlerFactory.php, routes/web.php 1. W AllegroOrderImportService dodac opcjonalna zaleznosc AutomationService (konstruktor): private readonly ?AutomationService $automationService = null 2. Po bloku recordActivity (po linii 95), dodac trigger: if ($savedOrderId > 0 && $this->automationService !== null) { $this->automationService->trigger('order.imported', $savedOrderId, [ 'source' => 'allegro', 'created' => $wasCreated, 'integration_id' => (int) ($mapped['order']['integration_id'] ?? 0), ]); } 3. W CronHandlerFactory wstrzyknac $automationService do AllegroOrderImportService 4. W routes/web.php wstrzyknac $automationService do AllegroOrderImportService Avoid: nie triggerowac wewnatrz upsertOrderAggregate — trigger ma byc na poziomie serwisu importu Uwaga: import use App\Modules\Automation\AutomationService w AllegroOrderImportService PHP lint; import zamowienia Allegro wyzwala event order.imported AC-2 satisfied: import Allegro triggeruje order.imported z kontekstem Task 3: Trigger w ShopproOrdersSyncService src/Modules/Settings/ShopproOrdersSyncService.php, src/Modules/Cron/CronHandlerFactory.php 1. W ShopproOrdersSyncService dodac opcjonalna zaleznosc AutomationService (konstruktor): private readonly ?AutomationService $automationService = null 2. Po bloku recordActivity w processOrder() (po linii 269), dodac trigger: if ($savedOrderId > 0 && $this->automationService !== null) { $this->automationService->trigger('order.imported', $savedOrderId, [ 'source' => 'shoppro', 'created' => $wasCreated, 'integration_id' => $integrationId, ]); } 3. W CronHandlerFactory wstrzyknac $automationService do ShopproOrdersSyncService Avoid: nie triggerowac przy payment_transition (to jest re-import ze zmiana platnosci, nie nowy import) PHP lint; import zamowienia shopPRO wyzwala event order.imported AC-3, AC-4 satisfied: import shopPRO triggeruje order.imported; warunek integration dziala

DO NOT CHANGE

  • src/Modules/Automation/AutomationService.php — logika ewaluacji warunkow juz obsluguje 'integration'
  • src/Modules/Orders/OrderImportRepository.php — trigger na poziomie serwisu, nie repozytorium
  • database/migrations/* — brak zmian DB (event type jest stringiem, nie wymaga migracji)

SCOPE LIMITS

  • Nie dodawac nowych typow warunkow — 'integration' juz istnieje i wystarczy
  • Nie dodawac warunku 'source' (allegro/shoppro) — 'integration' filtruje po konkretnej integracji
  • Nie triggerowac przy payment_transition w shopPRO
Before declaring plan complete: - [ ] PHP lint na wszystkich zmodyfikowanych plikach - [ ] Event 'order.imported' widoczny w dropdown formularza automatyzacji - [ ] AllegroOrderImportService triggeruje event po imporcie - [ ] ShopproOrdersSyncService triggeruje event po imporcie - [ ] AutomationService wstrzykniety w CronHandlerFactory i routes/web.php - [ ] Brak bledow PHP

<success_criteria>

  • Wszystkie taski wykonane
  • Wszystkie verification checks pass
  • User moze tworzyc reguly automatyzacji na zdarzenie "Pobranie zamowienia" </success_criteria>
After completion, create `.paul/phases/84-order-imported-automation-event/84-01-SUMMARY.md`