Warenkorb: nicht-numerische Mengen brechen die Gewichtsberechnung nicht mehr

Yard::weight() multiplizierte Gewicht und Menge ohne Cast. Beide Werte stammen
aus Session- bzw. Request-Daten; ein fuehrend-numerischer String wie "2,5" loeste
unter PHP 8 die ErrorException "A non-numeric value encountered" aus. Danach war
die Position dauerhaft defekt, da reCalculateShippingPrice() bei jedem Aufruf
erneut fehlschlug.

Cart::update() setzt die Menge ohne Validierung (anders als setQuantity()).
Eintrittspunkte waren das quantity-Feld im Shop-POST sowie das Textfeld fuer die
Menge im Backoffice-Warenkorb.

- Yard: neue cartItemWeight() mit explizitem int-Cast fuer Gewicht und Menge
- CardController: nicht-numerische Mengen werden uebersprungen, Schutz gegen ein
  quantity-Feld, das kein Array ist
- OrderController: nutzt das bereits vorhandene $qty (int) statt $data['qty'] roh

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Kevin 2026-09-09 07:16:30 +00:00
parent 2e71173c66
commit 384b2dcff1
4 changed files with 82 additions and 5 deletions

View file

@ -899,8 +899,8 @@ class OrderController extends Controller
Yard::setTax($cartItem->rowId, $product->getTaxWith(Yard::instance('shopping')->getUserCountry()));
}
if (isset($data['qty']) && $data['qty'] > 0) {
Yard::instance('shopping')->update($cartItem->rowId, $data['qty']);
if ($qty > 0) {
Yard::instance('shopping')->update($cartItem->rowId, $qty);
} else {
// If 0 get the item by qty:1 and remove it
Yard::instance('shopping')->remove($cartItem->rowId);

View file

@ -127,7 +127,14 @@ class CardController extends Controller
$data = Request::all();
if (isset($data['quantity'])) {
if (! is_array($data['quantity'])) {
return back();
}
foreach ($data['quantity'] as $rowId => $qty) {
if (! is_numeric($qty)) {
continue;
}
$qty = (int) $qty;
$cartItem = Yard::instance($this->instance)->get($rowId);
if ($cartItem) {
$product = Product::find($cartItem->id);
@ -135,7 +142,7 @@ class CardController extends Controller
$qty = 1;
}
if ($product) {
$additionalWeight = (int) $product->weight * ((int) $qty - (int) $cartItem->qty);
$additionalWeight = (int) $product->weight * ($qty - (int) $cartItem->qty);
if ($additionalWeight > 0 && Yard::instance($this->instance)->exceedsMaxWeight($additionalWeight)) {
\Session::flash('alert-error', __('msg.cart_max_weight_reached'));