178 lines
7.4 KiB
Markdown
178 lines
7.4 KiB
Markdown
---
|
|
phase: 84-order-imported-automation-event
|
|
plan: 01
|
|
type: execute
|
|
wave: 1
|
|
depends_on: []
|
|
files_modified:
|
|
- 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
|
|
autonomous: true
|
|
delegation: off
|
|
---
|
|
|
|
<objective>
|
|
## 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
|
|
</objective>
|
|
|
|
<context>
|
|
## 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)
|
|
</context>
|
|
|
|
<acceptance_criteria>
|
|
|
|
## AC-1: Event zarejestrowany w systemie
|
|
```gherkin
|
|
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
|
|
```gherkin
|
|
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
|
|
```gherkin
|
|
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
|
|
```gherkin
|
|
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>
|
|
|
|
<tasks>
|
|
|
|
<task type="auto">
|
|
<name>Task 1: Rejestracja eventu + UI</name>
|
|
<files>src/Modules/Automation/AutomationController.php, resources/views/automation/form.php, resources/views/automation/index.php</files>
|
|
<action>
|
|
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
|
|
</action>
|
|
<verify>PHP lint na 3 plikach; event widoczny w dropdownie formularza</verify>
|
|
<done>AC-1 satisfied: event order.imported zarejestrowany i widoczny w UI</done>
|
|
</task>
|
|
|
|
<task type="auto">
|
|
<name>Task 2: Trigger w AllegroOrderImportService</name>
|
|
<files>src/Modules/Settings/AllegroOrderImportService.php, src/Modules/Cron/CronHandlerFactory.php, routes/web.php</files>
|
|
<action>
|
|
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
|
|
</action>
|
|
<verify>PHP lint; import zamowienia Allegro wyzwala event order.imported</verify>
|
|
<done>AC-2 satisfied: import Allegro triggeruje order.imported z kontekstem</done>
|
|
</task>
|
|
|
|
<task type="auto">
|
|
<name>Task 3: Trigger w ShopproOrdersSyncService</name>
|
|
<files>src/Modules/Settings/ShopproOrdersSyncService.php, src/Modules/Cron/CronHandlerFactory.php</files>
|
|
<action>
|
|
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)
|
|
</action>
|
|
<verify>PHP lint; import zamowienia shopPRO wyzwala event order.imported</verify>
|
|
<done>AC-3, AC-4 satisfied: import shopPRO triggeruje order.imported; warunek integration dziala</done>
|
|
</task>
|
|
|
|
</tasks>
|
|
|
|
<boundaries>
|
|
|
|
## 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
|
|
|
|
</boundaries>
|
|
|
|
<verification>
|
|
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
|
|
</verification>
|
|
|
|
<success_criteria>
|
|
- Wszystkie taski wykonane
|
|
- Wszystkie verification checks pass
|
|
- User moze tworzyc reguly automatyzacji na zdarzenie "Pobranie zamowienia"
|
|
</success_criteria>
|
|
|
|
<output>
|
|
After completion, create `.paul/phases/84-order-imported-automation-event/84-01-SUMMARY.md`
|
|
</output>
|