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>
This commit is contained in:
1 parent
28e3342b1f
commit
3d76062097
36 files changed
+756
-150
No files matched your search
@@ -31,14 +31,7 @@ public function show(Request $request, Cart $cart, OrderHolders $holders): View
|
||||
|
||||
public function add(Offer $offer, Cart $cart, PublicCatalogReader $catalog): RedirectResponse
|
||||
{
|
||||
$key = app(ProductOptions::class)->groupKey($offer);
|
||||
$page = $offer->composition;
|
||||
$listed = match (true) {
|
||||
$key === null => false,
|
||||
$key[0] === 'c' => $page !== null && $catalog->shownVersion($page) !== null,
|
||||
default => true,
|
||||
};
|
||||
$result = $listed ? $cart->add($offer) : Cart::UNAVAILABLE;
|
||||
$result = $this->listed($offer, $catalog) ? $cart->add($offer) : Cart::UNAVAILABLE;
|
||||
$back = $this->productPage($offer);
|
||||
|
||||
return match ($result) {
|
||||
@@ -49,6 +42,27 @@ public function add(Offer $offer, Cart $cart, PublicCatalogReader $catalog): Red
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* „Jetzt kaufen“: die gewählte Option kommt in den Warenkorb (eine andere Option derselben Produktseite wird
|
||||
* ersetzt, weil der Käufer sich ausdrücklich für diese entschieden hat) und die Bestellübersicht öffnet sich. Es
|
||||
* entsteht keine Bestellung; die Kasse prüft wie immer Zustimmungen, Rabatt und Inhaber, und erst „Zahlungspflichtig
|
||||
* bestellen“ legt sie an. Ohne Anmeldung führt die Kasse zur Anmeldung; der Warenkorb liegt in der Sitzung und bleibt.
|
||||
*/
|
||||
public function buy(Request $request, Offer $offer, Cart $cart, PublicCatalogReader $catalog): RedirectResponse
|
||||
{
|
||||
if (! $this->listed($offer, $catalog) || $cart->purchasable($offer) === null) {
|
||||
return $this->productPage($offer)->withErrors(['shop' => 'Diese Option ist gerade nicht erhältlich.']);
|
||||
}
|
||||
|
||||
if ($cart->ownedAmong($request->user(), [$offer]) !== []) {
|
||||
return $this->productPage($offer)->with('status', 'Diese Lizenz besitzt du bereits. Sie liegt in deiner Bibliothek.');
|
||||
}
|
||||
|
||||
$cart->switchTo($offer);
|
||||
|
||||
return redirect()->route('checkout');
|
||||
}
|
||||
|
||||
/**
|
||||
* Ausdrücklicher Wechsel zwischen Alternativoptionen derselben Produktseite.
|
||||
*/
|
||||
@@ -84,6 +98,19 @@ public function accept(Offer $offer, Cart $cart): RedirectResponse
|
||||
});
|
||||
}
|
||||
|
||||
/** Nur Optionen mit öffentlicher Produktseite sind im Shop kaufbar (bei Altbestand mit Programmseite: freigegeben). */
|
||||
private function listed(Offer $offer, PublicCatalogReader $catalog): bool
|
||||
{
|
||||
$key = app(ProductOptions::class)->groupKey($offer);
|
||||
$page = $offer->composition;
|
||||
|
||||
return match (true) {
|
||||
$key === null => false,
|
||||
$key[0] === 'c' => $page !== null && $catalog->shownVersion($page) !== null,
|
||||
default => true,
|
||||
};
|
||||
}
|
||||
|
||||
private function productPage(Offer $offer): RedirectResponse
|
||||
{
|
||||
$url = app(ProductOptions::class)->pageUrl($offer);
|
||||
|
||||
@@ -23,15 +23,19 @@
|
||||
|
||||
class CheckoutController extends Controller
|
||||
{
|
||||
/**
|
||||
* Angebote für das Konto: was sich ohne Kauf in die Bibliothek übernehmen lässt (Vergabe „auf Abruf“ oder „bei
|
||||
* Registrierung“). Gekauft wird ausschließlich im Shop über Warenkorb oder „Jetzt kaufen“ und die Kasse.
|
||||
*/
|
||||
public function offers(): View
|
||||
{
|
||||
$offers = Offer::query()
|
||||
->whereHas('versions', fn ($query) => $query->where('status', OfferStatus::Aktiv)->where('holder_kind', 'person'))
|
||||
->with(['versions' => fn ($query) => $query->where('status', OfferStatus::Aktiv)])
|
||||
->whereHas('versions', fn ($query) => $query->where('status', OfferStatus::Aktiv)->where('holder_kind', 'person')->whereIn('grant_kind', ['auf_abruf', 'bei_registrierung']))
|
||||
->with(['versions' => fn ($query) => $query->where('status', OfferStatus::Aktiv)->orderByDesc('number')])
|
||||
->orderBy('name')
|
||||
->get();
|
||||
|
||||
return view('member.offers', ['offers' => $offers]);
|
||||
return view('member.offers', ['offers' => $offers, 'shop' => Shop::visible()]);
|
||||
}
|
||||
|
||||
public function claim(Request $request, Offer $offer, GrantIssuer $issuer): RedirectResponse
|
||||
@@ -45,17 +49,6 @@ public function claim(Request $request, Offer $offer, GrantIssuer $issuer): Redi
|
||||
return redirect()->route('member.library')->with('status', 'Das Angebot liegt in deiner Bibliothek.');
|
||||
}
|
||||
|
||||
public function place(Request $request, Offer $offer, Checkout $checkout): RedirectResponse
|
||||
{
|
||||
try {
|
||||
$order = $checkout->place($request->user(), $offer);
|
||||
} catch (DomainRuleException $exception) {
|
||||
return back()->withErrors(['offer' => $exception->getMessage()]);
|
||||
}
|
||||
|
||||
return redirect()->route('member.order', $order);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bestellübersicht: zeigt die geprüften Positionen mit dem Inhaber, für den bestellt wird.
|
||||
*/
|
||||
|
||||
@@ -8,7 +8,9 @@
|
||||
use App\Domain\Cms\PageTemplates;
|
||||
use App\Domain\Cms\Sections\SectionRenderer;
|
||||
use App\Domain\Cms\Widgets\RenderContext;
|
||||
use App\Domain\Commerce\Shop;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
@@ -24,6 +26,15 @@ public function show(string $path): View
|
||||
return $this->render(Page::query()->where('path', '/'.$path)->firstOrFail(), preview: false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Die frühere Angebotsseite der Website ist der Shop. Solange er nicht sichtbar ist, bleibt eine noch vorhandene
|
||||
* CMS-Seite unter dieser Adresse erreichbar (sonst 404).
|
||||
*/
|
||||
public function offers(): View|RedirectResponse
|
||||
{
|
||||
return Shop::visible() ? redirect()->route('shop') : $this->show('angebote');
|
||||
}
|
||||
|
||||
public function preview(PageRevision $revision): View
|
||||
{
|
||||
$page = $revision->page;
|
||||
|
||||
@@ -26,7 +26,7 @@ public function index(PublicCatalogReader $catalog): View
|
||||
*/
|
||||
public function package(Bundle $bundle, ProductOptions $products, Cart $cart): View
|
||||
{
|
||||
abort_unless(Shop::enabled(), 404);
|
||||
abort_unless(Shop::visible(), 404);
|
||||
$options = $products->forBundle($bundle);
|
||||
abort_if($options === [], 404);
|
||||
|
||||
@@ -45,7 +45,7 @@ public function package(Bundle $bundle, ProductOptions $products, Cart $cart): V
|
||||
*/
|
||||
public function article(LicenseArticle $article, ProductOptions $products, Cart $cart): View
|
||||
{
|
||||
abort_unless(Shop::enabled() && $article->archived_at === null, 404);
|
||||
abort_unless(Shop::visible() && $article->archived_at === null, 404);
|
||||
$options = $products->forArticle($article);
|
||||
abort_if($options === [], 404);
|
||||
|
||||
@@ -70,8 +70,8 @@ public function program(Composition $composition, PublicCatalogReader $catalog,
|
||||
'composition' => $composition,
|
||||
'version' => $version,
|
||||
'nodes' => app(CompositionStructureReader::class)->tree($version),
|
||||
'options' => Shop::enabled() ? $products->forComposition($composition) : [],
|
||||
'articles' => Shop::enabled() ? $products->articlesOf($composition) : [],
|
||||
'options' => Shop::visible() ? $products->forComposition($composition) : [],
|
||||
'articles' => Shop::visible() ? $products->articlesOf($composition) : [],
|
||||
'cart' => $cart,
|
||||
'switchTo' => session('shop.switch'),
|
||||
]);
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
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;
|
||||
|
||||
@@ -19,6 +21,15 @@
|
||||
*/
|
||||
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', ''));
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Domain\Commerce\Shop;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* Schalter 2: Warenkorb, Kasse und „Jetzt kaufen“ gibt es nur, wenn der Checkout offen ist (Shop::checkoutOpen).
|
||||
* Ist der Shop sichtbar, aber der Kauf noch nicht freigegeben, führt jede Anfrage (auch ein POST) auf die Hinweisseite.
|
||||
* Dort entsteht nichts: kein Warenkorb, keine Bestellung. Die Prüfung liegt auf dem Server, nicht nur in der Oberfläche.
|
||||
*/
|
||||
class EnsureCheckoutOpen
|
||||
{
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
if (! Shop::checkoutOpen()) {
|
||||
abort_unless(Shop::visible(), 404);
|
||||
|
||||
return redirect()->route('shop.closed');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
+4
-3
@@ -8,13 +8,14 @@
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* Warenkorb und Kasse gibt es nur mit Testzahlung und nie in Produktion (Etappe 1 erteilt keine Produktivfreigabe).
|
||||
* Schalter 1: Shop, Produktseiten und Hinweisseite gibt es nur, wenn der Shop sichtbar ist (Shop::visible). Sonst
|
||||
* antwortet die Anwendung, als gäbe es sie nicht.
|
||||
*/
|
||||
class EnsureShopEnabled
|
||||
class EnsureShopVisible
|
||||
{
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
abort_unless(Shop::enabled(), 404);
|
||||
abort_unless(Shop::visible(), 404);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
Reference in new issue
Block a user