Abo Einmalprodukte und Bestätigung abschließen

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Kevin 2026-06-05 15:28:08 +00:00
parent 2bdc9ada3c
commit 2269ce031f
57 changed files with 3647 additions and 371 deletions

View file

@ -773,10 +773,11 @@ class OrderController extends Controller
$isAbo = str_contains($is_for, 'abo');
$qty = isset($data['qty']) ? (int) $data['qty'] : 0;
if ($qty > 0 && ! ProductOrderContext::isProductAllowedInContext($product, $isAbo, $is_for)) {
return response()->json([
'response' => false,
'message' => __('msg.cart_product_not_allowed_for_order_type'),
]);
return $this->cartUpdateRejected($data, __('msg.cart_product_not_allowed_for_order_type'));
}
if ($qty > 0 && $this->exceedsCartMaxWeight(Yard::instance('shopping'), $product, $qty)) {
return $this->cartUpdateRejected($data, __('msg.cart_max_weight_reached'));
}
$image = '';
@ -831,6 +832,67 @@ class OrderController extends Controller
return response()->json(['response' => true, 'data' => $data, 'html_card' => $html_card, 'html_comp' => $html_comp]);
}
/**
* Lehnt ein Warenkorb-Update ab, ohne den Warenkorb zu verändern. Der Warenkorb
* wird unverändert neu gerendert (Zähler bleibt stehen) und der Hinweis als
* Inline-Meldung über dem Warenkorb ausgegeben.
*
* @param array<string, mixed> $data
*/
private function cartUpdateRejected(array $data, string $message): \Illuminate\Http\JsonResponse
{
$data['error_message'] = $message;
if (isset($data['product_id'])) {
$currentQty = 0;
foreach (Yard::instance('shopping')->content() as $row) {
if (! $row->options->comp && (int) $row->id === (int) $data['product_id']) {
$currentQty = (int) $row->qty;
break;
}
}
$data['qty'] = $currentQty;
}
$html_card = view('user.order.yard_view_form', $data)->render();
$html_comp = view('user.order.comp_product', $data)->render();
return response()->json([
'response' => true,
'data' => $data,
'html_card' => $html_card,
'html_comp' => $html_comp,
'message' => $message,
]);
}
/**
* Prüft, ob das Hochsetzen eines Produkts auf die Zielmenge das Maximalgewicht
* des Versandlandes überschreiten würde. Mengenreduktionen werden nie blockiert.
*/
private function exceedsCartMaxWeight(\App\Services\Yard $yard, Product $product, int $targetQty): bool
{
$productWeight = (int) $product->weight;
if ($productWeight <= 0) {
return false;
}
$currentQty = 0;
foreach ($yard->content() as $row) {
if (! $row->options->comp && (int) $row->id === (int) $product->id) {
$currentQty = (int) $row->qty;
break;
}
}
$additionalWeight = $productWeight * ($targetQty - $currentQty);
if ($additionalWeight <= 0) {
return false;
}
return $yard->exceedsMaxWeight($additionalWeight);
}
/**
* Handle updating shipping country
*/