Skip to content

Neuer CLI Command für alle Produkte: wsc:variant:update-all #6

@csaeum

Description

@csaeum

Beschreibung

Ein zusätzlicher CLI Command, der alle Produkte mit Varianten im Shop aktualisiert, ohne dass Produktnummern angegeben werden müssen.

Anforderungen

1. Neuer Command

bin/console wsc:variant:update-all [OPTIONS]

Optionen

  • --dry-run: Vorschau ohne Speichern
  • --name-only: Nur Namen aktualisieren
  • --number-only: Nur Nummern aktualisieren
  • --sync: Synchrone Verarbeitung (Standard: async via Message Queue)
  • --limit=N: Max. N Produkte verarbeiten (für Tests)
  • --offset=N: Ab Produkt N starten (für manuelle Paginierung)

2. Sicherheits-Bestätigung

Da dieser Command alle Produkte betrifft, soll eine interaktive Bestätigung erforderlich sein:

⚠️  WARNUNG: Sie sind dabei, alle Produkte mit Varianten zu aktualisieren!
   Gefundene Produkte: 1.247
   Geschätzte Varianten: ~4.500
   
   Möchten Sie fortfahren? (yes/no) [no]:

Bypass für Automation

# Für Scripts/Cron ohne Interaktion
bin/console wsc:variant:update-all --force --sync

3. Produktauswahl-Logik

// Alle Parent-Produkte mit mindestens einer Variante
$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('parentId', null)); // Nur Parents
$criteria->addFilter(new RangeFilter('childCount', [
    RangeFilter::GT => 0
])); // Mindestens 1 Kind
$criteria->addAssociation('children.options.group');

4. Output-Format

Synchron

WSC Variant Updater - Alle Produkte
====================================

Lade Produkte...
✓ 1.247 Produkte mit Varianten gefunden

Verarbeite Produkte:
  1/1.247 [▓░░░░░░░░░] 0% - jacket-001 (5 Varianten aktualisiert)
  2/1.247 [▓░░░░░░░░░] 0% - shoes-042 (12 Varianten aktualisiert)
  ...
  1.247/1.247 [▓▓▓▓▓▓▓▓▓▓] 100%

✓ Fertig!
  - Produkte: 1.247
  - Varianten: 4.521
  - Dauer: 3m 42s

Asynchron

WSC Variant Updater - Alle Produkte
====================================

Lade Produkte...
✓ 1.247 Produkte mit Varianten gefunden

Message Queue Job erstellt:
  - Batch ID: batch_6a8f9c2e
  - Batches: 13 (à ~100 Produkte)
  
Fortschritt verfolgen:
  bin/console wsc:variant:status batch_6a8f9c2e
  
Oder im Admin unter: Einstellungen → Plugins → WSC Variant Updater

5. Status-Command (optional)

bin/console wsc:variant:status <batch-id>

Output:

Batch: batch_6a8f9c2e
Status: In Bearbeitung
Fortschritt: 842/1.247 Produkte (67%)
Fehler: 3
Gestartet: vor 2 Minuten
Geschätzte Restzeit: ~1 Minute

Technische Umsetzung

Neue Datei

src/Command/UpdateAllVariantsCommand.php

Services registrieren

<service id="WSCPlugin\SWVariantUpdater\Command\UpdateAllVariantsCommand">
    <argument type="service" id="product.repository"/>
    <argument type="service" id="messenger.bus.shopware"/>
    <tag name="console.command"/>
</service>

Code-Struktur

class UpdateAllVariantsCommand extends Command
{
    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $io = new SymfonyStyle($input, $output);
        
        // 1. Produkte laden
        $products = $this->loadAllParentProducts();
        
        // 2. Bestätigung einholen (wenn nicht --force)
        if (!$input->getOption('force')) {
            if (!$this->confirmExecution($io, count($products))) {
                return Command::SUCCESS;
            }
        }
        
        // 3. Sync oder Async?
        if ($input->getOption('sync')) {
            return $this->executeSync($products, $input, $io);
        } else {
            return $this->executeAsync($products, $input, $io);
        }
    }
    
    private function confirmExecution(SymfonyStyle $io, int $count): bool
    {
        $io->warning([
            'Sie sind dabei, alle Produkte mit Varianten zu aktualisieren!',
            sprintf('Gefundene Produkte: %d', $count),
        ]);
        
        return $io->confirm('Möchten Sie fortfahren?', false);
    }
}

Akzeptanzkriterien

  • Command wsc:variant:update-all existiert
  • Interaktive Bestätigung wird angezeigt
  • --force bypassed Bestätigung
  • Sync-Modus funktioniert mit Progress-Bar
  • Async-Modus erstellt Message Queue Job
  • Alle Standard-Optionen (dry-run, name-only, etc.) funktionieren
  • Output ist informativ und verständlich

Sicherheitsüberlegungen

  • ⚠️ Kein Auto-Confirm: Niemals standardmäßig --force verwenden
  • ⚠️ Logging: Jeden Aufruf loggen (wer, wann, wie viele Produkte)
  • ⚠️ Rollback: In Dokumentation Hinweis auf Datenbank-Backup vor Ausführung

Abhängigkeiten

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions