0) { $packagePrice = round($oldPackagePrice * (1 - ($discountPercent / 100)), 2); $discountType = 'percent'; } elseif ($oldPackagePrice !== null) { $discountType = 'manual_old_price'; } $productRepository->createWithVariant([ 'category_id' => $_POST['category_id'] !== '' ? (int) $_POST['category_id'] : null, 'name' => trim((string) $_POST['name']), 'slug' => trim((string) $_POST['slug']), 'short_description' => trim((string) ($_POST['short_description'] ?? '')), 'seo_title' => trim((string) ($_POST['seo_title'] ?? '')), 'seo_description' => trim((string) ($_POST['seo_description'] ?? '')), 'seo_keywords' => trim((string) ($_POST['seo_keywords'] ?? '')), 'base_unit' => (string) ($_POST['base_unit'] ?? 'kg'), 'is_published' => isset($_POST['is_published']) ? 1 : 0, 'variant_name' => trim((string) ($_POST['variant_name'] ?? '')), 'package_quantity' => (float) ($_POST['package_quantity'] ?? 1), 'step_quantity' => (float) ($_POST['step_quantity'] ?? 1), 'price_per_unit' => $_POST['price_per_unit'] !== '' ? (float) $_POST['price_per_unit'] : null, 'package_price' => $packagePrice, 'old_package_price' => $oldPackagePrice, 'discount_type' => $discountType, 'discount_percent' => $discountPercent, ]); $message = 'Товар добавлен.'; } catch (\Throwable $exception) { $error = app_env('APP_DEBUG', 'false') === 'true' ? $exception->getMessage() : 'Не удалось добавить товар.'; } } view('admin/products', [ 'title' => 'Товары - админка Рыбсток', 'breadcrumbs' => [ ['title' => 'Главная', 'url' => '/'], ['title' => 'Админка', 'url' => '/admin/'], ['title' => 'Товары'], ], 'categories' => $categoryRepository->flatActive(), 'products' => $productRepository->adminLatest(30), 'message' => $message, 'error' => $error, ]); } }