Skip to content

Commit 267f141

Browse files
committed
configure widgets during the install process
1 parent 3a019af commit 267f141

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

src/Commands/InstallCommand.php

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ public function handle(): void
5757
->publishPrebuiltCheckout()
5858
->schedulePurgeAbandonedCartsCommand()
5959
->createGeneralTaxClass()
60-
->setDefaultPreferences();
60+
->setDefaultPreferences()
61+
->configureWidgets();
6162

6263
$this->line(' <fg=green;options=bold>Cargo has been installed successfully!</> 🎉');
6364
$this->newLine();
@@ -283,4 +284,41 @@ private function setDefaultPreferences(): self
283284

284285
return $this;
285286
}
287+
288+
private function configureWidgets(): self
289+
{
290+
$contents = File::get(config_path('statamic/cp.php'));
291+
292+
if (Str::contains($contents, "'type' => 'total_sales'")) {
293+
return $this;
294+
}
295+
296+
$emptyOption = <<<'PHP'
297+
'widgets' => [
298+
//
299+
],
300+
PHP;
301+
302+
$widgets = <<<'PHP'
303+
['type' => 'total_sales', 'width' => 25, 'days' => 7],
304+
['type' => 'total_revenue', 'width' => 25, 'days' => 7],
305+
['type' => 'new_customers', 'width' => 25, 'days' => 7],
306+
['type' => 'returning_customers', 'width' => 25, 'days' => 7],
307+
['type' => 'refunded_orders', 'width' => 25, 'days' => 7],
308+
PHP;
309+
310+
311+
$contents = Str::of($contents)
312+
->replace($emptyOption, <<<'PHP'
313+
'widgets' => [
314+
],
315+
PHP)
316+
->replace("'widgets' => [", "'widgets' => [ \n{$widgets}");
317+
318+
File::put(config_path('statamic/cp.php'), $contents);
319+
320+
$this->components->info('Added widgets to [config/statamic/cp.php].');
321+
322+
return $this;
323+
}
286324
}

0 commit comments

Comments
 (0)