Öffentliche Leser, Shop, Medienliste und Bibliothek lesen Kurzbeschreibung, Beschreibung und Lernziel als Klartext; Mitgliederseiten zu Programm, Inhalt und Artikel zeigen die formatierte Fassung. Der Editor trägt die deutsche Bezeichnung des Felds als Namen für Hilfstechnik, der Tastaturfokus landet im Editor, und der Abgleich merkt sich nur eine Prüfsumme. ADR-50 nennt Rückfall und Suche. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
73 lines
3.0 KiB
PHP
73 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Domain\Catalog\Bundle;
|
|
use App\Domain\Catalog\Composition;
|
|
use App\Domain\Catalog\FormattedText;
|
|
use App\Domain\Cms\Catalog\PublicCatalogReader;
|
|
use App\Domain\Commerce\Money;
|
|
use App\Domain\Commerce\ProductOptions;
|
|
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
|
|
{
|
|
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'],
|
|
];
|
|
}
|
|
|
|
// 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]);
|
|
}
|
|
}
|