Add feature tests for shop functionality and organization purchases
- Implement OfferOptionAdminTest to validate offer option management, including price display, activation, and cancellation. - Create OrganizationPurchaseTest to ensure correct handling of organization purchases, including access control and order processing. - Add ShopProductPageTest to verify shop product listings, search functionality, and product page details. - Introduce BuildsShop trait for seeding test data related to shop functionality. - Implement MoneyTest to validate money parsing and formatting, ensuring correct handling of euro amounts.
This commit is contained in:
1 parent
6c8bbee363
commit
4e0760db1e
106 files changed
+4068
-76
No files matched your search
@@ -25,7 +25,8 @@ public function verify(EmailVerificationRequest $request): RedirectResponse
|
||||
$request->fulfill();
|
||||
app(GrantIssuer::class)->grantRegistrationOffers($request->user());
|
||||
|
||||
return redirect()->route('member.dashboard');
|
||||
// Wer aus dem Warenkorb kam, kehrt nach der Bestätigung zur Kasse zurück (gespeichertes Ziel der Sitzung).
|
||||
return redirect()->intended(route('member.dashboard'));
|
||||
}
|
||||
|
||||
public function send(Request $request): RedirectResponse
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Domain\Catalog\Offer;
|
||||
use App\Domain\Cms\Catalog\PublicCatalogReader;
|
||||
use App\Domain\Commerce\Cart;
|
||||
use App\Domain\Commerce\Money;
|
||||
use App\Domain\Commerce\OrderHolders;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
/**
|
||||
* Öffentlicher Warenkorb (Etappe 1, nur Testzahlung). Er ist vor der Anmeldung nutzbar; die Prüfung der
|
||||
* vorhandenen Rechte erfolgt, sobald ein Konto angemeldet ist.
|
||||
*/
|
||||
class CartController extends Controller
|
||||
{
|
||||
public function show(Request $request, Cart $cart, OrderHolders $holders): View
|
||||
{
|
||||
$user = $request->user();
|
||||
$review = $cart->review($user, $request->integer('bestellen_als') ?: null);
|
||||
|
||||
return view('shop.cart', [
|
||||
'review' => $review,
|
||||
'holders' => $user === null ? collect() : $holders->for($user),
|
||||
]);
|
||||
}
|
||||
|
||||
public function add(Offer $offer, Cart $cart, PublicCatalogReader $catalog): RedirectResponse
|
||||
{
|
||||
$page = $offer->composition;
|
||||
$result = $page !== null && $catalog->shownVersion($page) !== null
|
||||
? $cart->add($offer)
|
||||
: Cart::UNAVAILABLE;
|
||||
$back = $this->productPage($offer);
|
||||
|
||||
return match ($result) {
|
||||
Cart::ADDED => $back->with('status', 'Die Option liegt im Warenkorb.'),
|
||||
Cart::PRESENT => $back->with('status', 'Diese Option liegt bereits im Warenkorb. Sie erscheint nur einmal.'),
|
||||
Cart::ALTERNATIVE => $back->with('shop.switch', $offer->id),
|
||||
default => $back->withErrors(['shop' => 'Diese Option ist gerade nicht erhältlich.']),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Ausdrücklicher Wechsel zwischen Alternativoptionen derselben Produktseite.
|
||||
*/
|
||||
public function switch(Offer $offer, Cart $cart): RedirectResponse
|
||||
{
|
||||
if (! $cart->switchTo($offer)) {
|
||||
return $this->productPage($offer)->withErrors(['shop' => 'Diese Option ist gerade nicht erhältlich.']);
|
||||
}
|
||||
|
||||
return redirect()->route('cart')->with('status', 'Die Option wurde gewechselt.');
|
||||
}
|
||||
|
||||
public function remove(Offer $offer, Cart $cart): RedirectResponse
|
||||
{
|
||||
$cart->remove($offer);
|
||||
|
||||
return redirect()->route('cart')->with('status', 'Die Position ist entfernt.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Der Käufer übernimmt den aktuell gezeigten Preis und die aktuellen Bedingungen einer Position.
|
||||
*/
|
||||
public function accept(Offer $offer, Cart $cart): RedirectResponse
|
||||
{
|
||||
$seen = $cart->items()[$offer->id]['price_cents'] ?? null;
|
||||
$cart->acceptCurrent($offer);
|
||||
$price = $cart->purchasable($offer)?->price_cents;
|
||||
|
||||
return redirect()->route('cart')->with('status', match (true) {
|
||||
$price === null => 'Die Option ist nicht mehr erhältlich.',
|
||||
$seen !== null && (int) $seen !== (int) $price => 'Der aktuelle Preis von '.Money::format($price).' ist übernommen.',
|
||||
default => 'Die aktuellen Bedingungen sind übernommen.',
|
||||
});
|
||||
}
|
||||
|
||||
private function productPage(Offer $offer): RedirectResponse
|
||||
{
|
||||
return $offer->composition_id !== null
|
||||
? redirect()->route('public.program', $offer->composition_id)
|
||||
: redirect()->route('cart');
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,11 @@
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Catalog\Offer;
|
||||
use App\Domain\Catalog\OfferStatus;
|
||||
use App\Domain\Commerce\Cart;
|
||||
use App\Domain\Commerce\Checkout;
|
||||
use App\Domain\Commerce\Order;
|
||||
use App\Domain\Commerce\OrderHolders;
|
||||
use App\Domain\Commerce\StaleOverview;
|
||||
use App\Domain\Entitlement\GrantIssuer;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
@@ -48,10 +51,50 @@ public function place(Request $request, Offer $offer, Checkout $checkout): Redir
|
||||
return redirect()->route('member.order', $order);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bestellübersicht: zeigt die geprüften Positionen mit dem Inhaber, für den bestellt wird.
|
||||
*/
|
||||
public function checkout(Request $request, Cart $cart, OrderHolders $holders): View|RedirectResponse
|
||||
{
|
||||
if ($cart->count() === 0) {
|
||||
return redirect()->route('cart');
|
||||
}
|
||||
|
||||
$review = $cart->review($request->user(), $request->integer('bestellen_als') ?: null);
|
||||
|
||||
return view('shop.checkout', [
|
||||
'review' => $review,
|
||||
'holders' => $holders->for($request->user()),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Legt die Bestellung an, aber nur, wenn die serverseitige Prüfung zur gezeigten Übersicht passt.
|
||||
*/
|
||||
public function placeOrder(Request $request, Cart $cart, Checkout $checkout): RedirectResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'digest' => ['required', 'string'],
|
||||
'bestellen_als' => ['nullable', 'integer'],
|
||||
]);
|
||||
$holderId = isset($data['bestellen_als']) ? (int) $data['bestellen_als'] : null;
|
||||
$back = redirect()->route('checkout', array_filter(['bestellen_als' => $holderId]));
|
||||
|
||||
try {
|
||||
$order = $checkout->placeFromCart($request->user(), $cart, $holderId, $data['digest']);
|
||||
} catch (StaleOverview $exception) {
|
||||
return $back->withErrors(['checkout' => $exception->getMessage()]);
|
||||
} catch (DomainRuleException $exception) {
|
||||
return $back->withErrors(['checkout' => $exception->getMessage()]);
|
||||
}
|
||||
|
||||
return redirect()->route('member.order', $order)->with('status', 'Die Bestellung ist angelegt. Bestätige jetzt die Testzahlung.');
|
||||
}
|
||||
|
||||
public function show(Request $request, Order $order): View
|
||||
{
|
||||
abort_unless($order->user_id === $request->user()->id, 403);
|
||||
$order->load('lines.offerVersion.offer', 'payments');
|
||||
$order->load('lines.offerVersion.offer', 'lines.holder', 'payments', 'party', 'user');
|
||||
|
||||
return view('member.order', [
|
||||
'order' => $order,
|
||||
|
||||
@@ -466,7 +466,7 @@ private function grantQuery(Request $request)
|
||||
{
|
||||
return Grant::query()
|
||||
->where('status', GrantStatus::Aktiv)
|
||||
->whereHas('acquisition', fn ($query) => $query->where('party_id', $request->user()->party_id))
|
||||
->usableBy($request->user())
|
||||
->with('article.currentRelease')
|
||||
->orderBy('id');
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
use App\Domain\Catalog\Composition;
|
||||
use App\Domain\Catalog\CompositionStructureReader;
|
||||
use App\Domain\Cms\Catalog\PublicCatalogReader;
|
||||
use App\Domain\Commerce\Cart;
|
||||
use App\Domain\Commerce\ProductOptions;
|
||||
use App\Domain\Commerce\Shop;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class PublicCatalogController extends Controller
|
||||
@@ -14,7 +17,7 @@ public function index(PublicCatalogReader $catalog): View
|
||||
return view('public.programs', ['programs' => $catalog->publicPrograms()]);
|
||||
}
|
||||
|
||||
public function program(Composition $composition, PublicCatalogReader $catalog): View
|
||||
public function program(Composition $composition, PublicCatalogReader $catalog, ProductOptions $products, Cart $cart): View
|
||||
{
|
||||
$version = $catalog->shownVersion($composition);
|
||||
abort_if($version === null, 404);
|
||||
@@ -23,6 +26,9 @@ public function program(Composition $composition, PublicCatalogReader $catalog):
|
||||
'composition' => $composition,
|
||||
'version' => $version,
|
||||
'nodes' => app(CompositionStructureReader::class)->tree($version),
|
||||
'options' => Shop::enabled() ? $products->forComposition($composition) : [],
|
||||
'cart' => $cart,
|
||||
'switchTo' => session('shop.switch'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Domain\Catalog\Composition;
|
||||
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.' '.$composition->summary.' '.$composition->search_terms);
|
||||
|
||||
if ($term !== '' && ! str_contains($haystack, mb_strtolower($term))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$summary = $summaries[$composition->id];
|
||||
$cards[] = [
|
||||
'composition' => $composition,
|
||||
'title' => $title,
|
||||
'teaser' => (string) ($composition->teaser ?: $composition->summary),
|
||||
'from' => Money::format($summary['from_cents']),
|
||||
'count' => $summary['count'],
|
||||
];
|
||||
}
|
||||
|
||||
return view('shop.index', ['cards' => $cards, 'term' => $term]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user