@@ -46,20 +46,20 @@ class CartController extends Controller
|
||||
public function add(Product $product)
|
||||
{
|
||||
if (!$product->is_active || $product->stock < 1) {
|
||||
return back()->with('status', 'Товар сейчас недоступен для заказа.');
|
||||
return back()->with('status', __('Товар сейчас недоступен для заказа.'));
|
||||
}
|
||||
|
||||
$cart = (array) session()->get('cart', []);
|
||||
$current = (int) ($cart[$product->id] ?? 0);
|
||||
|
||||
if ($current >= $product->stock) {
|
||||
return back()->with('status', 'В корзине уже максимальное доступное количество.');
|
||||
return back()->with('status', __('В корзине уже максимальное доступное количество.'));
|
||||
}
|
||||
|
||||
$cart[$product->id] = $current + 1;
|
||||
session()->put('cart', $cart);
|
||||
|
||||
return back()->with('status', "Товар \"{$product->name}\" добавлен в корзину.");
|
||||
return back()->with('status', __('Товар ":name" добавлен в корзину.', ['name' => $product->name]));
|
||||
}
|
||||
|
||||
public function update(Request $request, Product $product)
|
||||
@@ -80,15 +80,15 @@ class CartController extends Controller
|
||||
unset($cart[$product->id]);
|
||||
session()->put('cart', $cart);
|
||||
|
||||
return back()->with('status', "Товар \"{$product->name}\" удален из корзины.");
|
||||
return back()->with('status', __('Товар ":name" удален из корзины.', ['name' => $product->name]));
|
||||
}
|
||||
|
||||
$cart[$product->id] = $quantity;
|
||||
session()->put('cart', $cart);
|
||||
|
||||
$message = $quantity < (int) $validated['quantity']
|
||||
? 'Количество ограничено текущим остатком.'
|
||||
: 'Количество товара обновлено.';
|
||||
? __('Количество ограничено текущим остатком.')
|
||||
: __('Количество товара обновлено.');
|
||||
|
||||
return back()->with('status', $message);
|
||||
}
|
||||
@@ -101,6 +101,6 @@ class CartController extends Controller
|
||||
session()->put('cart', $cart);
|
||||
}
|
||||
|
||||
return back()->with('status', "Товар \"{$product->name}\" удален из корзины.");
|
||||
return back()->with('status', __('Товар ":name" удален из корзины.', ['name' => $product->name]));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user