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>
|
||||
118
.paul/phases/59-order-status-automation-event/59-01-SUMMARY.md
Normal file
118
.paul/phases/59-order-status-automation-event/59-01-SUMMARY.md
Normal file
@@ -0,0 +1,118 @@
|
||||
---
|
||||
phase: 59-order-status-automation-event
|
||||
plan: 01
|
||||
subsystem: automation
|
||||
tags: [automation, events, order-status, conditions]
|
||||
|
||||
requires:
|
||||
- phase: 57-payment-automation-event
|
||||
provides: payment.status_changed event pattern, condition evaluation pattern
|
||||
provides:
|
||||
- order.status_changed automation event
|
||||
- order_status condition type with checkbox UI
|
||||
- chain emission from update_order_status action
|
||||
affects: [future automation events, order workflow]
|
||||
|
||||
tech-stack:
|
||||
added: []
|
||||
patterns: [order status condition evaluation analogous to payment_status]
|
||||
|
||||
key-files:
|
||||
created: []
|
||||
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
|
||||
|
||||
key-decisions:
|
||||
- "Emisja eventu tylko przy realnej zmianie statusu (old != new)"
|
||||
- "Chain emission z akcji update_order_status przez emitEvent() z depth protection"
|
||||
|
||||
patterns-established:
|
||||
- "order_status condition: order_status_codes array z lowercase kodami statusow"
|
||||
|
||||
duration: 15min
|
||||
started: 2026-03-30T23:45:00Z
|
||||
completed: 2026-03-31T00:00:00Z
|
||||
---
|
||||
|
||||
# Phase 59 Plan 01: Order Status Automation Event Summary
|
||||
|
||||
**Event automatyzacji `order.status_changed` z warunkiem `order_status` — emisja z recznej zmiany statusu i chain z akcji automatyzacji**
|
||||
|
||||
## Performance
|
||||
|
||||
| Metric | Value |
|
||||
|--------|-------|
|
||||
| Duration | ~15min |
|
||||
| Tasks | 2 completed |
|
||||
| Files modified | 6 |
|
||||
|
||||
## Acceptance Criteria Results
|
||||
|
||||
| Criterion | Status | Notes |
|
||||
|-----------|--------|-------|
|
||||
| AC-1: Event order.status_changed dostepny w formularzu | Pass | Opcja "Zmiana statusu zamowienia" w dropdown zdarzenia |
|
||||
| AC-2: Warunek order_status z checkboxami statusow | Pass | Checkboxy z aktywnymi statusami zamowien (PHP + JS) |
|
||||
| AC-3: Emisja eventu przy recznej zmianie statusu | Pass | OrdersController emituje po udanym updateOrderStatus() |
|
||||
| AC-4: Chain emission z akcji update_order_status | Pass | AutomationService emituje przez emitEvent() z depth protection |
|
||||
| AC-5: Etykieta w widoku listy regul i historii | Pass | index.php zawiera etykiety payment.status_changed + order.status_changed |
|
||||
|
||||
## Accomplishments
|
||||
|
||||
- Event `order.status_changed` dostepny w silniku automatyzacji z pelnym UI (dropdown zdarzenia, checkboxy warunku)
|
||||
- Emisja z dwoch zrodel: reczna zmiana statusu (OrdersController) i chain z akcji automatyzacji (AutomationService)
|
||||
- Naprawiono brakujaca etykiete `payment.status_changed` w index.php (bug z Phase 57)
|
||||
|
||||
## Files Created/Modified
|
||||
|
||||
| File | Change | Purpose |
|
||||
|------|--------|---------|
|
||||
| `src/Modules/Automation/AutomationController.php` | Modified | ALLOWED_EVENTS + order.status_changed, ALLOWED_CONDITION_TYPES + order_status, parseConditionValue + order_status, buildRuleFromRequest + order_status |
|
||||
| `src/Modules/Automation/AutomationService.php` | Modified | evaluateOrderStatusCondition(), chain emit z handleUpdateOrderStatus(), dodano $context param |
|
||||
| `src/Modules/Orders/OrdersController.php` | Modified | Pobranie oldStatus przed zmiana, emisja order.status_changed po sukcesie |
|
||||
| `resources/views/automation/form.php` | Modified | Etykieta zdarzenia, opcja warunku order_status, checkboxy statusow zamowien |
|
||||
| `resources/views/automation/index.php` | Modified | Etykiety payment.status_changed + order.status_changed |
|
||||
| `public/assets/js/modules/automation-form.js` | Modified | buildOrderStatusCheckboxes(), opcja order_status w addCondition, onConditionTypeChange |
|
||||
|
||||
## Decisions Made
|
||||
|
||||
| Decision | Rationale | Impact |
|
||||
|----------|-----------|--------|
|
||||
| Emisja tylko przy old_status != new_status | Brak falszywych triggerow przy ustawieniu tego samego statusu | Spojnosc z wzorcem shipment.status_changed |
|
||||
| handleUpdateOrderStatus otrzymuje $context dla chain | Potrzebny do emitEvent() z depth/dedup protection | Zapobiega petlom automatyzacji |
|
||||
|
||||
## Deviations from Plan
|
||||
|
||||
### Auto-fixed Issues
|
||||
|
||||
**1. Bugfix: brakujaca etykieta payment.status_changed w index.php**
|
||||
- **Found during:** Poczatek sesji (zgloszenie uzytkownika)
|
||||
- **Issue:** Phase 57 nie dodala etykiety do index.php — wyswietlala sie surowa nazwa
|
||||
- **Fix:** Dodano wpis do $eventLabels w index.php
|
||||
- **Files:** resources/views/automation/index.php
|
||||
|
||||
**Total impact:** Jeden bugfix z Phase 57 naprawiony przy okazji
|
||||
|
||||
## Issues Encountered
|
||||
|
||||
None
|
||||
|
||||
## Next Phase Readiness
|
||||
|
||||
**Ready:**
|
||||
- Pelny zestaw eventow automatyzacji: receipt.created, shipment.created, shipment.status_changed, payment.status_changed, order.status_changed
|
||||
- Wszystkie warianty warunkow: integration, shipment_status, payment_status, order_status
|
||||
|
||||
**Concerns:**
|
||||
- None
|
||||
|
||||
**Blockers:**
|
||||
- None
|
||||
|
||||
---
|
||||
*Phase: 59-order-status-automation-event, Plan: 01*
|
||||
*Completed: 2026-03-31*
|
||||
Reference in New Issue
Block a user