From 70a6d526a053ff3490d88947acf6dfd398a5c354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=2E=20Nagy=20Gerg=C5=91?= Date: Thu, 16 Nov 2023 11:09:52 +0100 Subject: [PATCH] wip --- src/Resources/OrderResource.php | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/Resources/OrderResource.php b/src/Resources/OrderResource.php index 25023961..e96e2ac9 100644 --- a/src/Resources/OrderResource.php +++ b/src/Resources/OrderResource.php @@ -2,11 +2,17 @@ namespace Cone\Bazar\Resources; +use Cone\Bazar\Bazar; use Cone\Bazar\Models\Order; use Cone\Root\Fields\BelongsTo; use Cone\Root\Fields\ID; +use Cone\Root\Fields\MorphMany; +use Cone\Root\Fields\Number; +use Cone\Root\Fields\Select; use Cone\Root\Resources\Resource; +use Illuminate\Database\Eloquent\Model; use Illuminate\Http\Request; +use Illuminate\Support\Str; class OrderResource extends Resource { @@ -25,6 +31,34 @@ public function fields(Request $request): array BelongsTo::make(__('Customer'), 'user') ->display('name'), + + Select::make(__('Currency'), 'currency') + ->options(Bazar::getCurrencies()), + + MorphMany::make(__('Products'), 'items') + ->display('name') + ->asSubResource() + ->withFields(static function (Request $request): array { + return [ + BelongsTo::make(__('Product'), 'buyable') + ->display('name'), + + Number::make(__('Price'), 'price') + ->min(0) + ->format(static function (Request $request, Model $model, ?float $value): string { + return Str::currency($value, $model->itemable->currency); + }), + + Number::make(__('TAX'), 'tax') + ->min(0) + ->format(static function (Request $request, Model $model, ?float $value): string { + return Str::currency($value, $model->itemable->currency); + }), + + Number::make(__('Quantity'), 'quantity') + ->min(0), + ]; + }), ]; } }