---
phase: 84-order-imported-automation-event
plan: 01
subsystem: automation, settings
tags: [automation, event, import, allegro, shoppro]

requires:
  - phase: 16-automated-tasks
    provides: automation engine (AutomationService, rules, conditions, actions)
provides:
  - event type order.imported for automation rules
  - trigger in Allegro and shopPRO import flows
affects: [automation, cron-import]

tech-stack:
  added: []
  patterns: [nullable AutomationService injection for optional trigger]

key-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

key-decisions:
  - "Nullable AutomationService — backward compat, trigger only when injected"
  - "No trigger on payment_transition in shopPRO — that's a re-import status change, not a new import"
  - "Cron context has full injection; web controller context has null (99% imports are via cron)"

patterns-established:
  - "Event trigger after recordActivity, before return — consistent with shipment.created pattern"

duration: ~15min
started: 2026-04-07T19:00:00Z
completed: 2026-04-07T19:15:00Z
---

# Phase 84 Plan 01: Order Imported Automation Event — Summary

**Nowe zdarzenie automatyzacji `order.imported` wyzwalane przy imporcie zamowien z Allegro i shopPRO**

## Performance

| Metric | Value |
|--------|-------|
| Duration | ~15min |
| Tasks | 3 planned, 3 completed |
| Files modified | 6 |

## Acceptance Criteria Results

| Criterion | Status | Notes |
|-----------|--------|-------|
| AC-1: Event zarejestrowany w systemie | Pass | Dodany do ALLOWED_EVENTS + UI labels |
| AC-2: Event wyzwalany przy imporcie Allegro | Pass | Trigger po recordActivity w importSingleOrder() |
| AC-3: Event wyzwalany przy imporcie shopPRO | Pass | Trigger po recordActivity w processOrder() |
| AC-4: Warunek integration dziala | Pass | Istniejacy warunek 'integration' filtruje po integration_id |

## Accomplishments

- Nowy event type `order.imported` w systemie automatyzacji z etykieta "Pobranie zamowienia"
- Trigger w AllegroOrderImportService po kazdym imporcie (nowe i re-import)
- Trigger w ShopproOrdersSyncService po kazdym imporcie (bez payment_transition)
- Context eventu zawiera: source, created (bool), integration_id
- Istniejacy warunek `integration` pozwala filtrowac po zrodle zamowienia

## Files Created/Modified

| File | Change | Purpose |
|------|--------|---------|
| `src/Modules/Automation/AutomationController.php` | Modified | Dodanie 'order.imported' do ALLOWED_EVENTS |
| `src/Modules/Settings/AllegroOrderImportService.php` | Modified | AutomationService dep + trigger po imporcie |
| `src/Modules/Settings/ShopproOrdersSyncService.php` | Modified | AutomationService dep + trigger po imporcie |
| `src/Modules/Cron/CronHandlerFactory.php` | Modified | Wstrzykniecie automationService do obu serwisow |
| `resources/views/automation/form.php` | Modified | Label 'Pobranie zamowienia' w dropdown |
| `resources/views/automation/index.php` | Modified | Label 'Pobranie zamowienia' w liscie/historii |

## Decisions Made

| Decision | Rationale | Impact |
|----------|-----------|--------|
| Nullable AutomationService | Backward compat + kontroler web nie ma dostepnego AutomationService w momencie tworzenia | Trigger dziala w cron (99% importow), nie w recznym imporcie z UI |
| Brak triggera na payment_transition | Payment transition to re-import ze zmiana statusu platnosci, nie nowy import | Nie generuje falszywych triggerow |
| Reuse istniejacego warunku integration | Warunek juz obsluguje filtrowanie po integration_id | Zero zmian w logice ewaluacji warunkow |

## Deviations from Plan

None — plan executed as written.

## Next Phase Readiness

**Ready:**
- Event order.imported dziala w kontekscie cron (Allegro + shopPRO)
- User moze tworzyc reguly: np. "Gdy pobrano zamowienie z integracji X → wyslij e-mail / zmien status"

**Concerns:**
- Reczny import z UI (Allegro controller) nie triggeruje eventu (AutomationService = null)
- Jesli potrzebne — wymaga refactoru kolejnosci tworzenia obiektow w routes/web.php

**Blockers:**
- None — kod wymaga deploy na serwer (FTP)

---
*Phase: 84-order-imported-automation-event, Plan: 01*
*Completed: 2026-04-07*
