Skip to content

Commit 9629b97

Browse files
committed
Support defer
1 parent 6bed99d commit 9629b97

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"require": {
1919
"php": "^8.3",
2020
"bolechen/nova-activitylog": "^0.5.0",
21-
"justbetter/laravel-magento-stock": "^2.0",
21+
"justbetter/laravel-magento-stock": "^2.3.4",
2222
"laravel/framework": "^11.0|^12.0",
2323
"laravel/nova": "^5.0"
2424
},

src/Nova/Actions/RetrieveAll.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
use Illuminate\Bus\Queueable;
66
use Illuminate\Queue\InteractsWithQueue;
77
use Illuminate\Queue\SerializesModels;
8+
use Illuminate\Support\Carbon;
89
use Illuminate\Support\Collection;
910
use JustBetter\MagentoStock\Jobs\Retrieval\RetrieveAllStockJob;
1011
use Laravel\Nova\Actions\Action;
1112
use Laravel\Nova\Actions\ActionResponse;
1213
use Laravel\Nova\Fields\ActionFields;
14+
use Laravel\Nova\Fields\Boolean;
15+
use Laravel\Nova\Fields\DateTime;
16+
use Laravel\Nova\Http\Requests\NovaRequest;
1317

1418
class RetrieveAll extends Action
1519
{
@@ -26,8 +30,30 @@ public function __construct()
2630

2731
public function handle(ActionFields $fields, Collection $models): ActionResponse
2832
{
29-
RetrieveAllStockJob::dispatch();
33+
/** @var ?string $from */
34+
$from = $fields->get('from');
35+
36+
if ($from !== null) {
37+
$carbon = Carbon::parse($from);
38+
}
39+
40+
/** @var bool $defer */
41+
$defer = $fields->get('defer');
42+
43+
RetrieveAllStockJob::dispatch($carbon ?? null, $defer);
3044

3145
return ActionResponse::message(__('Retrieving...'));
3246
}
47+
48+
public function fields(NovaRequest $request): array
49+
{
50+
return [
51+
DateTime::make(__('From'), 'from')
52+
->help(__('Optional, retrieve updated prices from this date')),
53+
54+
Boolean::make(__('Defer'), 'defer')
55+
->default(true)
56+
->help(__('When enabled, the stocks will be marked for retrieval. Otherwise, all stocks will be retrieved immediately.')),
57+
];
58+
}
3359
}

0 commit comments

Comments
 (0)