Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automate sites.yaml config #81

Merged
merged 17 commits into from
Nov 6, 2024
Merged
3 changes: 0 additions & 3 deletions config/rapidez/statamic.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,10 @@

'sites' => [
kevinmeijer97 marked this conversation as resolved.
Show resolved Hide resolved
'default' => [
'name' => env('APP_NAME', 'Statamic'),
'locale' => 'en_EN',
'lang' => 'en_EN',
'url' => '/',
'attributes' => [
'magento_store_id' => 1,
'group' => 'default',
'disabled' => false,
],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this whole sites config?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this around, see #81 (comment)

],
Expand Down
29 changes: 27 additions & 2 deletions src/RapidezStatamicServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Rapidez\Statamic;

use Statamic\Statamic;
use Statamic\Sites\Sites;
use Statamic\Facades\Site;
use Statamic\Facades\Entry;
Expand Down Expand Up @@ -33,7 +32,7 @@ class RapidezStatamicServiceProvider extends ServiceProvider
public function register()
{
$this->app->extend(Sites::class, function () {
return new SitesLinkedToMagentoStores(config('statamic.sites'));
return new SitesLinkedToMagentoStores();
});
kevinmeijer97 marked this conversation as resolved.
Show resolved Hide resolved
}

Expand All @@ -42,6 +41,7 @@ public function boot()
$this
->bootCommands()
->bootConfig()
->bootSites()
->bootRoutes()
->bootViews()
->bootListeners()
Expand All @@ -55,6 +55,31 @@ public function boot()
Alternates::register();
}

public function bootSites() : self
{
$sites = [];
$stores = Rapidez::getStores();
kevinmeijer97 marked this conversation as resolved.
Show resolved Hide resolved

foreach ($stores as $store) {
$sites[$store['code']] = [
'name' => $store['name'] ?? $store['code'],
'locale' => '{{ config:rapidez.statamic.sites.' . $store['code'] . '.locale }}',
'lang' => '{{ config:rapidez.statamic.sites.' . $store['code'] . '.lang }}',
'url' => '{{ config:rapidez.statamic.sites.' . $store['code'] . '.url }}',
kevinmeijer97 marked this conversation as resolved.
Show resolved Hide resolved
'attributes' => [
'magento_store_id' => $store['store_id'],
'group' => $store['website_code'] ?? '',
'disabled' => '{{ config:rapidez.statamic.sites.' . $store['code'] . '.attributes.disabled }}',
]
];
}

Site::setSites($sites);
Site::save();

return $this;
}

public function bootCommands() : self
{
$this->commands([
Expand Down