Domäne: Rabattcodes mit Geltungsbereich (Warenkorb oder gewählte Ziele) und Einlösungsberechtigung (allgemein oder freigeschaltete Konten) unabhängig voneinander; Prüfung bei Eingabe, in jeder Übersicht und unter Sperre vor Bestellabschluss (Prüfsumme der Übersicht enthält den Rabatt). Rabatt je Position, Zwischensumme und Zahlbetrag in der Bestellung; Stripe erhält den Preis nach Rabatt. Nutzerkreis (Einzel-/Mehrfachlizenz, Trainerzahl) an der Angebotsfassung, kopiert in Bestellposition und Erwerb, Teil der Prüfung "Bereits erworben". OfferService::activate lehnt Angebote ohne veröffentlichten Artikelstand ab. Kasse: Zustimmungen als Pflichtangabe mit Nachweis, "Zahlungspflichtig bestellen", Rechnungsweg für Organisationen, Erstattung über Stripe, Widerruf erklären. Produktivfreigabe SHOP_LIVE_RELEASE standardmäßig aus. Bestandstests geändert (fachlich überholt, Assertions nicht abgeschwächt): die Schaltfläche heißt "Zahlungspflichtig bestellen" (§ 312j BGB), die Summe heißt "Zu zahlen", der Vereinshinweis steht als Rollenliste; Bestellungen über die Kasse senden jetzt die Zustimmungen. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
92 lines
2.5 KiB
PHP
92 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Domain\Commerce;
|
|
|
|
use App\Domain\Commerce\Discount\DiscountResult;
|
|
use App\Domain\Identity\Party;
|
|
|
|
/**
|
|
* Prüfergebnis des Warenkorbs für einen vorgesehenen Lizenzinhaber. Die Prüfsumme bindet die Bestellung an genau
|
|
* diese Übersicht: Inhaber, Fassung und Preis jeder Position samt Zustand, auch der ausgeschlossenen.
|
|
*/
|
|
final class CartReview
|
|
{
|
|
/**
|
|
* @param list<CartLine> $lines
|
|
*/
|
|
public function __construct(
|
|
public readonly array $lines,
|
|
public readonly ?Party $holder,
|
|
public readonly ?DiscountResult $discount = null,
|
|
) {}
|
|
|
|
/** @return list<CartLine> */
|
|
public function orderable(): array
|
|
{
|
|
return array_values(array_filter($this->lines, fn (CartLine $line): bool => $line->orderable()));
|
|
}
|
|
|
|
/** Summe der Listenpreise der Positionen, die in die Bestellung eingehen. */
|
|
public function subtotalCents(): int
|
|
{
|
|
return array_sum(array_map(fn (CartLine $line): int => (int) $line->currentPriceCents, $this->orderable()));
|
|
}
|
|
|
|
public function discountCents(): int
|
|
{
|
|
return $this->discount?->totalCents() ?? 0;
|
|
}
|
|
|
|
/** Endgültiger Zahlbetrag: Listenpreise abzüglich Rabatt. */
|
|
public function totalCents(): int
|
|
{
|
|
return $this->subtotalCents() - $this->discountCents();
|
|
}
|
|
|
|
/** Rabatt einer Position in Cent. */
|
|
public function discountFor(CartLine $line): int
|
|
{
|
|
return $this->discount?->forOffer($line->offer->id) ?? 0;
|
|
}
|
|
|
|
/** Ein vorgemerkter Code, der jetzt nicht gilt, hält die Bestellung an, bis er entfernt wird. */
|
|
public function discountBlocks(): bool
|
|
{
|
|
return $this->discount !== null && ! $this->discount->applied();
|
|
}
|
|
|
|
public function blocked(): bool
|
|
{
|
|
foreach ($this->lines as $line) {
|
|
if ($line->blocks()) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public function empty(): bool
|
|
{
|
|
return $this->orderable() === [];
|
|
}
|
|
|
|
public function canOrder(): bool
|
|
{
|
|
return $this->holder !== null && ! $this->blocked() && ! $this->empty() && ! $this->discountBlocks();
|
|
}
|
|
|
|
public function digest(): string
|
|
{
|
|
$parts = [];
|
|
|
|
foreach ($this->lines as $line) {
|
|
$parts[] = $line->offer->id.':'.($line->version?->id ?? 0).':'.$line->currentPriceCents.':'.$line->state;
|
|
}
|
|
|
|
sort($parts);
|
|
|
|
return hash('sha256', ($this->holder?->id ?? 0).'|'.implode(',', $parts).'|'.($this->discount?->digestPart() ?? '-'));
|
|
}
|
|
}
|