@@ -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