Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Nov 16, 2023
1 parent 86bc656 commit 70a6d52
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/Resources/OrderResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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),
];
}),
];
}
}

0 comments on commit 70a6d52

Please sign in to comment.