Files
laraundfelix/app/Http/Controllers/ShopController.php
T
LarsandClaude Sonnet 5.5 3d76062097
CI Feature / test (push) Successful in 3m23s
Deploy Test / test (push) Successful in 3m22s
Deploy Test / deploy (push) Successful in 30s
Trenne Shop sichtbar und Checkout offen und kaufe nur noch ueber die Kasse
- Zwei Schalter: Shop::visible (SHOP_PUBLIC) und Shop::checkoutOpen; ist der Shop nur sichtbar,
  fuehren Warenkorb, Kasse und Jetzt kaufen auf eine Hinweisseite (noindex), ohne Warenkorb und Bestellung
- Einzelkauf (Checkout::place, Route member.offers.buy) entfernt; Bestellung nur aus dem Warenkorb
- Jetzt kaufen an der Produktseite oeffnet die Bestellübersicht, Bereits erworben auf der Produktseite
- Menuepunkte in den Shop nur bei sichtbarem Shop, /angebote leitet auf /shop, Seeder fuehrt Shop
- Mitgliederseite Angebote zeigt nur kostenlose Angebote zum Uebernehmen
- Middleware EnsureCheckoutOpen laeuft vor der Anmeldepruefung
- Plan und ADR-53, DEPLOYMENT.md

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-26 07:17:25 +01:00

109 lines
4.6 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Domain\Catalog\Bundle;
use App\Domain\Catalog\Composition;
use App\Domain\Catalog\EditorialProfileReader;
use App\Domain\Catalog\FormattedText;
use App\Domain\Catalog\LicenseArticle;
use App\Domain\Cms\Catalog\PublicCatalogReader;
use App\Domain\Commerce\Money;
use App\Domain\Commerce\ProductOptions;
use App\Domain\Commerce\Shop;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
/**
* Durchsuchbarer Shop (Etappe 1): macht kaufbare Produkte auffindbar. Treffer öffnen dieselbe öffentliche Produktseite
* wie die Programmkacheln. Gelistet wird nur, was zur Anzeige freigegeben ist und mindestens eine kaufbare Option hat.
*/
class ShopController extends Controller
{
/**
* Hinweisseite, solange der Shop sichtbar, der Checkout aber noch nicht freigegeben ist: Wer „Kaufen“ wählt, sieht,
* dass der Kauf zum Verkaufsstart möglich wird. Ist der Checkout offen, gibt es sie nicht mehr.
*/
public function closed(): View|RedirectResponse
{
return Shop::checkoutOpen() ? redirect()->route('shop') : view('shop.closed');
}
public function index(Request $request, ProductOptions $products, PublicCatalogReader $catalog): View
{
$term = trim((string) $request->query('suche', ''));
$summaries = $products->summaries();
$cards = [];
foreach (Composition::query()->whereIn('id', array_keys($summaries))->orderBy('designation')->get() as $composition) {
$version = $catalog->shownVersion($composition);
if ($version === null) {
continue;
}
$title = (string) ($composition->display_title ?: $composition->designation);
$haystack = mb_strtolower($title.' '.$composition->teaser.' '.FormattedText::plain($composition->summary).' '.$composition->search_terms);
if ($term !== '' && ! str_contains($haystack, mb_strtolower($term))) {
continue;
}
$summary = $summaries[$composition->id];
$cards[] = [
'url' => route('public.program', $composition),
'title' => $title,
'teaser' => (string) ($composition->teaser ?: FormattedText::plain($composition->summary)),
'from' => Money::format($summary['from_cents']),
'count' => $summary['count'],
];
}
// Lizenzartikel mit kaufbarer Option: Titel und Kurztext aus der Redaktion des Artikels (sonst seines Inhalts).
$articleSummaries = $products->articleSummaries();
foreach (LicenseArticle::query()->whereIn('id', array_keys($articleSummaries))->whereNull('archived_at')->orderBy('code')->get() as $article) {
$profile = app(EditorialProfileReader::class)->read($article, 'kachel');
$title = $products->articleTitle($article);
$teaser = (string) ($profile->value('teaser') ?: $profile->value('summary'));
$haystack = mb_strtolower($title.' '.$teaser.' '.$profile->value('summary').' '.$profile->searchTerms);
if ($term !== '' && ! str_contains($haystack, mb_strtolower($term))) {
continue;
}
$summary = $articleSummaries[$article->id];
$cards[] = [
'url' => route('shop.article', $article),
'title' => $title,
'teaser' => $teaser,
'from' => Money::format($summary['from_cents']),
'count' => $summary['count'],
];
}
// Pakete mit eigener Produktseite: gelistet mit Name und enthaltenen Artikeln.
foreach (Bundle::query()->whereIn('id', array_keys($products->bundleSummaries()))->orderBy('name')->get() as $bundle) {
$options = $products->forBundle($bundle);
$contents = $products->bundleContents($options);
$names = implode(', ', array_column($contents, 'title'));
if ($term !== '' && ! str_contains(mb_strtolower($bundle->name.' '.$names), mb_strtolower($term))) {
continue;
}
$summary = $products->bundleSummaries()[$bundle->id];
$cards[] = [
'url' => route('public.package', $bundle),
'title' => (string) $bundle->name,
'teaser' => 'Paket mit '.count($contents).' '.(count($contents) === 1 ? 'Inhalt' : 'Inhalten').($names !== '' ? ': '.$names : ''),
'from' => Money::format($summary['from_cents']),
'count' => $summary['count'],
];
}
return view('shop.index', ['cards' => $cards, 'term' => $term]);
}
}