update
This commit is contained in:
183
.paul/phases/59-order-status-automation-event/59-01-PLAN.md
Normal file
183
.paul/phases/59-order-status-automation-event/59-01-PLAN.md
Normal file
@@ -0,0 +1,183 @@
|
||||
---
|
||||
phase: 59-order-status-automation-event
|
||||
plan: 01
|
||||
type: execute
|
||||
wave: 1
|
||||
depends_on: []
|
||||
files_modified:
|
||||
- src/Modules/Automation/AutomationController.php
|
||||
- src/Modules/Automation/AutomationService.php
|
||||
- src/Modules/Orders/OrdersController.php
|
||||
- resources/views/automation/form.php
|
||||
- resources/views/automation/index.php
|
||||
- public/assets/js/modules/automation-form.js
|
||||
autonomous: true
|
||||
---
|
||||
|
||||
<objective>
|
||||
## Goal
|
||||
Dodanie zdarzenia automatyzacji `order.status_changed` emitowanego przy zmianie statusu zamowienia. Warunek `order_status` pozwala filtrowac po konkretnym statusie docelowym.
|
||||
|
||||
## Purpose
|
||||
Uzytkownik moze tworzyc reguly automatyzacji reagujace na zmiane statusu zamowienia — np. wyslanie maila po zmianie na "wyslane" lub wystawienie paragonu po zmianie na "oplacone".
|
||||
|
||||
## Output
|
||||
- Event `order.status_changed` dostepny w formularzu automatyzacji
|
||||
- Warunek `order_status` z checkboxami aktywnych statusow
|
||||
- Emisja eventu z OrdersController (reczna zmiana) i AutomationService (chain z akcji update_order_status)
|
||||
</objective>
|
||||
|
||||
<context>
|
||||
## Project Context
|
||||
@.paul/PROJECT.md
|
||||
@.paul/ROADMAP.md
|
||||
@.paul/STATE.md
|
||||
|
||||
## Prior Work
|
||||
@.paul/phases/57-payment-automation-event/57-01-SUMMARY.md — identyczny wzorzec (event + warunek + emisja)
|
||||
|
||||
## Source Files
|
||||
@src/Modules/Automation/AutomationController.php
|
||||
@src/Modules/Automation/AutomationService.php
|
||||
@src/Modules/Orders/OrdersController.php
|
||||
@resources/views/automation/form.php
|
||||
@resources/views/automation/index.php
|
||||
@public/assets/js/modules/automation-form.js
|
||||
</context>
|
||||
|
||||
<acceptance_criteria>
|
||||
|
||||
## AC-1: Event order.status_changed dostepny w formularzu
|
||||
```gherkin
|
||||
Given uzytkownik otwiera formularz nowego zadania automatycznego
|
||||
When rozwija dropdown "Zdarzenie"
|
||||
Then widzi opcje "Zmiana statusu zamowienia"
|
||||
```
|
||||
|
||||
## AC-2: Warunek order_status z checkboxami statusow
|
||||
```gherkin
|
||||
Given uzytkownik wybrarl zdarzenie "Zmiana statusu zamowienia"
|
||||
When dodaje warunek "Status zamowienia"
|
||||
Then widzi checkboxy z aktywnymi statusami zamowien
|
||||
And moze zaznaczyc jeden lub wiecej statusow
|
||||
```
|
||||
|
||||
## AC-3: Emisja eventu przy recznej zmianie statusu
|
||||
```gherkin
|
||||
Given istnieje aktywna regula: event=order.status_changed, warunek=order_status IN [wyslane], akcja=send_email
|
||||
When uzytkownik zmienia status zamowienia na "wyslane" (ze strony szczegolw lub inline z listy)
|
||||
Then event order.status_changed jest emitowany z kontekstem (old_status, new_status)
|
||||
And regula jest dopasowana i akcja wykonana
|
||||
```
|
||||
|
||||
## AC-4: Chain emission z akcji update_order_status
|
||||
```gherkin
|
||||
Given regula A: event=payment.status_changed, akcja=update_order_status(wyslane)
|
||||
And regula B: event=order.status_changed, warunek=order_status IN [wyslane], akcja=send_email
|
||||
When platnosc sie zmienia i regula A zmienia status zamowienia
|
||||
Then regula B jest wyzwalana przez chain event order.status_changed
|
||||
```
|
||||
|
||||
## AC-5: Etykieta w widoku listy regul i historii
|
||||
```gherkin
|
||||
Given istnieja reguly z event_type=order.status_changed
|
||||
When uzytkownik otwiera strone /settings/automation
|
||||
Then w kolumnie "Zdarzenie" widzi "Zmiana statusu zamowienia" (nie surowa nazwe)
|
||||
And w zakladce Historia rowniez widzi czytelna etykiete
|
||||
```
|
||||
|
||||
</acceptance_criteria>
|
||||
|
||||
<tasks>
|
||||
|
||||
<task type="auto">
|
||||
<name>Task 1: Backend — event + warunek + emisja</name>
|
||||
<files>src/Modules/Automation/AutomationController.php, src/Modules/Automation/AutomationService.php, src/Modules/Orders/OrdersController.php</files>
|
||||
<action>
|
||||
**AutomationController.php:**
|
||||
- Dodaj `'order.status_changed'` do `ALLOWED_EVENTS` (linia 19)
|
||||
- Dodaj `'order_status'` do `ALLOWED_CONDITION_TYPES` (linia 20)
|
||||
- W `buildRuleFromRequest()` dodaj branch `elseif ($type === 'order_status')` analogiczny do `payment_status` — klucz `order_status_codes`, wartosc z `$cond['order_status_codes']`
|
||||
- W `parseConditionValue()` dodaj branch `if ($type === 'order_status')` — walidacja kodow statusow vs `$this->repository->listActiveOrderStatuses()` (analogicznie do payment_status ale kody z DB)
|
||||
|
||||
**AutomationService.php:**
|
||||
- Dodaj metode `evaluateOrderStatusCondition(array $value, array $context): bool` — porownuje `$context['new_status']` z `$value['order_status_codes']`
|
||||
- W `evaluateSingleCondition()` dodaj branch: `if ($type === 'order_status') return $this->evaluateOrderStatusCondition($value, $context);`
|
||||
- W `handleUpdateOrderStatus()` po udanej zmianie (`$updated === true`) dodaj `$this->emitEvent('order.status_changed', ...)` z kontekstem `old_status`, `new_status`, `automation_source`, `automation_rule` — analogicznie do `handleUpdateShipmentStatus()`
|
||||
- Potrzeba pobrac old_status przed zmiana: dodaj query lub uzyj `$this->orders->findDetails()` do pobrania aktualnego statusu PRZED wywolaniem `updateOrderStatus()`
|
||||
|
||||
**OrdersController.php:**
|
||||
- Po udanym `updateOrderStatus()` (linia 280, `$success === true`) dodaj emisje:
|
||||
```php
|
||||
try {
|
||||
$this->automation?->trigger('order.status_changed', $orderId, [
|
||||
'old_status' => $oldStatus,
|
||||
'new_status' => $newStatus,
|
||||
]);
|
||||
} catch (Throwable) {}
|
||||
```
|
||||
- Pobierz `$oldStatus` PRZED wywolaniem `updateOrderStatus()` — dodaj query do pobrania aktualnego `external_status_id`
|
||||
</action>
|
||||
<verify>Grep ALLOWED_EVENTS zawiera order.status_changed; grep evaluateOrderStatusCondition istnieje; grep trigger('order.status_changed' w OrdersController</verify>
|
||||
<done>AC-3, AC-4 satisfied: event emitowany z obu zrodel, warunek ewaluowany poprawnie</done>
|
||||
</task>
|
||||
|
||||
<task type="auto">
|
||||
<name>Task 2: Frontend — formularz + widok listy</name>
|
||||
<files>resources/views/automation/form.php, resources/views/automation/index.php, public/assets/js/modules/automation-form.js</files>
|
||||
<action>
|
||||
**form.php:**
|
||||
- Dodaj do `$eventLabels`: `'order.status_changed' => 'Zmiana statusu zamowienia'`
|
||||
- W sekcji renderowania warunkow dodaj branch `elseif ($condType === 'order_status')` — renderuj checkboxy z `$orderStatusOptions` (juz przekazywane do widoku przez renderForm), analogicznie do `payment_status` ale z kodem statusu jako value i nazwa jako label
|
||||
|
||||
**index.php:**
|
||||
- Dodaj do `$eventLabels`: `'order.status_changed' => 'Zmiana statusu zamowienia'`
|
||||
|
||||
**automation-form.js:**
|
||||
- W `addConditionRow()` dodaj opcje `<option value="order_status">Status zamowienia</option>` do selecta typu warunku
|
||||
- Dodaj renderowanie checkboxow statusow zamowien gdy type === 'order_status' — uzyj danych z `window.__orderStatusOptions` (lub analogicznego mechanizmu jak payment/shipment status)
|
||||
- W form.php dodaj `<script>window.__orderStatusOptions = <?= json_encode($orderStatusOptions) ?>;</script>` jesli jeszcze nie istnieje (sprawdz czy juz jest dla akcji update_order_status)
|
||||
- W `onConditionTypeChange()` pokaz/ukryj panel checkboxow order_status
|
||||
</action>
|
||||
<verify>Otworz /settings/automation/create, sprawdz ze "Zmiana statusu zamowienia" jest w dropdown zdarzenia, ze warunek "Status zamowienia" renderuje checkboxy, i ze lista regul pokazuje czytelna etykiete</verify>
|
||||
<done>AC-1, AC-2, AC-5 satisfied: event w dropdown, warunek z checkboxami, etykiety czytelne</done>
|
||||
</task>
|
||||
|
||||
</tasks>
|
||||
|
||||
<boundaries>
|
||||
|
||||
## DO NOT CHANGE
|
||||
- database/migrations/* (brak nowych tabel/kolumn)
|
||||
- src/Modules/Automation/AutomationRepository.php (bez zmian)
|
||||
- src/Modules/Orders/OrdersRepository.php (bez zmian — `updateOrderStatus()` juz istnieje)
|
||||
|
||||
## SCOPE LIMITS
|
||||
- Tylko event `order.status_changed` i warunek `order_status`
|
||||
- Nie dodajemy nowych akcji
|
||||
- Import zamowien z Allegro/shopPRO NIE emituje tego eventu (import ustawia status poczatkowy, nie zmienia istniejacego)
|
||||
- Emisja tylko z recznej zmiany (OrdersController) i chain z akcji automatyzacji (AutomationService)
|
||||
|
||||
</boundaries>
|
||||
|
||||
<verification>
|
||||
Before declaring plan complete:
|
||||
- [ ] `order.status_changed` widoczny w dropdown zdarzenia w formularzu
|
||||
- [ ] Warunek `order_status` renderuje checkboxy z aktywnymi statusami
|
||||
- [ ] Reczna zmiana statusu zamowienia emituje event
|
||||
- [ ] Akcja `update_order_status` emituje chain event `order.status_changed`
|
||||
- [ ] Etykieta "Zmiana statusu zamowienia" wyswietlana w tabeli regul i historii
|
||||
- [ ] Zapis i edycja reguly z tym zdarzeniem/warunkiem dziala poprawnie
|
||||
- [ ] Brak petli: chain protection (depth + dedup) zapobiega nieskonczonej rekurencji
|
||||
</verification>
|
||||
|
||||
<success_criteria>
|
||||
- Wszystkie taski wykonane
|
||||
- Wszystkie AC spelnione
|
||||
- Brak bledow PHP/JS
|
||||
- Formularz zachowuje dane warunku order_status po bledzie walidacji (wzorzec z Phase 58)
|
||||
</success_criteria>
|
||||
|
||||
<output>
|
||||
After completion, create `.paul/phases/59-order-status-automation-event/59-01-SUMMARY.md`
|
||||
</output>
|
||||
Reference in New Issue
Block a user