CI Feature / test (push) Failing after 3m16s
Die Produktseite ist die Seite des Artikels (/shop/{id}), den die Option als einzige
Position verkauft, oder die Paketseite. Sie wird nicht mehr einem Programm zugeordnet.
Ein Kauf braucht genau eine Position und einen Preis, sonst lässt er sich nicht aktivieren.
Module und Programme werden dadurch nicht öffentlich (Karten und /programme unverändert).
Tests: Die Tests, die eine Programmseite als Produktseite voraussetzten, prüfen jetzt die
Artikelseite; die Zuordnung „eigene Paketseite oder Programmseite“ entfällt (ADR-52).
Ein Altbestandstest sichert die Programmseite für Angebote mit mehreren Positionen.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
98 lines
4.2 KiB
PHP
98 lines
4.2 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 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'],
|
|
];
|
|
}
|
|
|
|
// 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]);
|
|
}
|
|
}
|