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), + ]; + }), ]; } }