diff --git a/app/Http/Controllers/Admin/PriceController.php b/app/Http/Controllers/Admin/PriceController.php index fbfdec3..18c10ed 100644 --- a/app/Http/Controllers/Admin/PriceController.php +++ b/app/Http/Controllers/Admin/PriceController.php @@ -59,6 +59,18 @@ class PriceController extends Controller ]); } + public function zaarboxProducts(ZaarboxPriceService $zaarboxPriceService) + { + return response()->json([ + 'code' => 0, + 'message' => 'عملیات با موفقیت انجام شد.', + 'data' => [ + 'items' => $zaarboxPriceService->listProductOptions(), + 'api_url' => $zaarboxPriceService->apiUrl(), + ], + ]); + } + public function table(Request $request){ $records = Price::with(['user']); TableEngine::create($records, $request->all()) diff --git a/app/Services/ZaarboxPriceService.php b/app/Services/ZaarboxPriceService.php index 170d838..49b9184 100644 --- a/app/Services/ZaarboxPriceService.php +++ b/app/Services/ZaarboxPriceService.php @@ -167,6 +167,34 @@ class ZaarboxPriceService } } + /** + * @return array + */ + public function listProductOptions(): array + { + $prices = $this->fetchPriceList(); + if ($prices === null) { + return []; + } + + return collect($prices) + ->map(function ($row) { + $row = is_array($row) ? $row : (array) $row; + + return [ + 'key' => trim((string) ($row['key'] ?? '')), + 'name' => trim((string) ($row['name'] ?? '')), + 'id' => trim((string) ($row['id'] ?? '')), + 'category' => trim((string) ($row['category'] ?? '')), + 'active' => (bool) ($row['active'] ?? false), + ]; + }) + ->filter(fn (array $row) => $row['key'] !== '') + ->sortBy('name', SORT_NATURAL | SORT_FLAG_CASE) + ->values() + ->all(); + } + /** * @return array{order_price: int, raw: array|null} */ diff --git a/routes/admin.php b/routes/admin.php index d10cd43..449925a 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -111,6 +111,7 @@ Route::middleware('auth:user')->group(function (){ Route::post('price/table', [PriceController::class, 'table']); Route::post('prices', [PriceController::class, 'priceData']); Route::post('prices/chart', [PriceController::class, 'chartPrices']); + Route::get('zaarbox/products', [PriceController::class, 'zaarboxProducts']); Route::post('finance', [FinanceController::class, 'fall']);