Skip to content

Commit

Permalink
tax rate resource
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Dec 18, 2024
1 parent 1190d12 commit 9310849
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/BazarServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ protected function registerPublishes(): void
$this->publishes([
__DIR__.'/../stubs/BazarServiceProvider.stub' => $this->app->basePath('app/Providers/BazarServiceProvider.php'),
__DIR__.'/../stubs/CategoryResource.stub' => $this->app->basePath('app/Root/Resources/CategoryResource.php'),
__DIR__.'/../stubs/OrderResource.stub' => $this->app->basePath('app/Root/Resources/OrderResource.php'),
__DIR__.'/../stubs/ProductResource.stub' => $this->app->basePath('app/Root/Resources/ProductResource.php'),
__DIR__.'/../stubs/PropertyResource.stub' => $this->app->basePath('app/Root/Resources/PropertyResource.php'),
__DIR__.'/../stubs/OrderResource.stub' => $this->app->basePath('app/Root/Resources/OrderResource.php'),
__DIR__.'/../stubs/TaxRateResource.stub' => $this->app->basePath('app/Root/Resources/TaxRateResource.php'),
], 'bazar-stubs');
}

Expand Down
2 changes: 1 addition & 1 deletion src/Models/TaxRate.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected function rate(): Attribute
protected function formattedValue(): Attribute
{
return new Attribute(
get: fn (): string => Number::percentage($this->value)
get: fn (): string => Number::percentage($this->value, 2)
);
}

Expand Down
62 changes: 62 additions & 0 deletions src/Resources/TaxRateResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace Cone\Bazar\Resources;

use Cone\Bazar\Models\TaxRate;
use Cone\Root\Fields\Boolean;
use Cone\Root\Fields\ID;
use Cone\Root\Fields\Number;
use Cone\Root\Fields\Text;
use Cone\Root\Resources\Resource;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;

class TaxRateResource extends Resource
{
/**
* The model class.
*/
protected string $model = TaxRate::class;

/**
* The group for the resource.
*/
protected string $group = 'Shop';

/**
* Get the model for the resource.
*/
public function getModel(): string
{
return $this->model::getProxiedClass();
}

/**
* Define the fields.
*/
public function fields(Request $request): array
{
return [
ID::make(),

Text::make(__('Name'), 'name')
->rules(['required', 'string', 'max:256'])
->searchable()
->sortable()
->required(),

Number::make(__('Rate'), 'rate')
->required()
->rules(['required', 'numeric', 'min:0'])
->step(0.1)
->min(0)
->suffix('%')
->format(static function (Request $request, Model $model): string {
return $model->formattedValue;
}),

Boolean::make(__('Shipping'), 'shipping')
->help(__('If the box is checked, the tax rate is applied for the shipping costs.'))
];
}
}
19 changes: 19 additions & 0 deletions stubs/TaxRateResource.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace {{ namespace }}Root\Resources;

use Cone\Bazar\Resources\TaxRateResource as Resource;
use Illuminate\Http\Request;

class TaxRateResource extends Resource
{
/**
* Define the fields.
*/
public function fields(Request $request): array
{
return array_merge(parent::fields($request), [
//
]);
}
}

0 comments on commit 9310849

Please sign in to comment.