feat: Implement comprehensive product management, including categories, pricing, and integration into the order system.
This commit is contained in:
@@ -22,7 +22,28 @@ class OrderController extends Controller
|
||||
try {
|
||||
$customer = $request->user();
|
||||
|
||||
$result = $this->orderService->create($request->validated(), $customer);
|
||||
$data = $request->validated();
|
||||
|
||||
// Convert UUID to ID for internal processing
|
||||
$product = \App\Models\Product::where('uuid', $data['product_id'])->first();
|
||||
|
||||
if (!$product) {
|
||||
// Should not happen if validation passes, but safety first (e.g. race condition or soft delete mismatch)
|
||||
throw new \Exception('Sản phẩm không tìm thấy hoặc đã bị xóa.');
|
||||
}
|
||||
|
||||
$data['product_id'] = $product->id;
|
||||
|
||||
$customer = $request->user();
|
||||
|
||||
if (!$customer) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Người dùng chưa đăng nhập hoặc phiên đăng nhập hết hạn.'
|
||||
], 401);
|
||||
}
|
||||
|
||||
$result = $this->orderService->create($data, $customer);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
@@ -65,4 +86,28 @@ class OrderController extends Controller
|
||||
], 400);
|
||||
}
|
||||
}
|
||||
|
||||
public function getList(Request $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
$customer = $request->user();
|
||||
|
||||
$filters = [
|
||||
'total_price' => $request->query('total_price'),
|
||||
'pending' => $request->query('pending')
|
||||
];
|
||||
|
||||
$orders = $this->orderRepo->getOrders($customer->id, $filters);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $orders
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => $e->getMessage()
|
||||
], 400);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Setting;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Setting;
|
||||
|
||||
class SettingController extends Controller
|
||||
{
|
||||
public function getSetting()
|
||||
{
|
||||
$setting = Setting::where('key', 'setting')->first();
|
||||
return response()->json([
|
||||
'data' => $setting->value,
|
||||
'message' => 'Get setting successfully',
|
||||
'error' => false
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -40,8 +40,8 @@ class ProductController extends Controller
|
||||
{
|
||||
$step = $request->get('step') ?? 1;
|
||||
$title = 'Add new product';
|
||||
// Fetch Product Categories instead of generic groups
|
||||
$group = \App\Models\ProductCategories::where('is_active', \App\Enums\Status::ACTIVE->value)->get();
|
||||
// Fetch Product Categories (Roots only, children via relation)
|
||||
$group = \App\Models\ProductCategories::where('is_active', \App\Enums\Status::ACTIVE->value)->whereNull('parent_id')->get();
|
||||
$type = null;
|
||||
|
||||
// Fetch OS versions with their group for the OS selector component
|
||||
@@ -91,7 +91,7 @@ class ProductController extends Controller
|
||||
$product->load(['pricings', 'osVersions', 'category']);
|
||||
|
||||
$title = 'Edit product: ' . $product->name;
|
||||
$group = \App\Models\ProductCategories::where('is_active', \App\Enums\Status::ACTIVE->value)->get();
|
||||
$group = \App\Models\ProductCategories::where('is_active', \App\Enums\Status::ACTIVE->value)->whereNull('parent_id')->get();
|
||||
$type = null;
|
||||
|
||||
// Fetch OS versions for select
|
||||
|
||||
Reference in New Issue
Block a user