Forms\Components\Select::make('data.importable_statuses')
->label('Geautomatiseerde orderverwerking')
->options(fn (): Collection =>
collect(
CompanyShopSupplier::where('supplier_id', $record->id)->first()->companyShop->settings->where('setting_name', 'woocommerce_statusses')->first()->setting_value
)->mapWithKeys(fn ($item, $key) => [
$key => $item
])
)
->multiple()
->hintAction(
Forms\Components\Actions\Action::make('refresh_status')
->label('Statussen vernieuwen')
->action(function () {
$shopConnection = ConnectToShop::connect();
$response = $shopConnection->get('reports/orders/totals');
if ($response) {
$statuses = [];
foreach($response as $result) {
$statuses[$result->slug] = $result->name;
}
$updated = CompanyShopSetting::updateOrCreate([
'setting_name' => 'woocommerce_statusses',
], [
'setting_value' => $statuses
]);
if ($updated) {
// Here we need to update the select field "data.importable_statuses" with the $statuses
}
}
})
)
php