Skip to content

Commit

Permalink
Determine the site by MAGE_RUN_CODE
Browse files Browse the repository at this point in the history
  • Loading branch information
royduin committed Jun 29, 2023
1 parent 82e15ee commit 7342d7e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ php artisan vendor:publish --provider="Rapidez\Statamic\RapidezStatamicServicePr

### Magento Store ID

It is important to add the Magento store ID in the attributes section within `config/statamic/sites.php` for every site
It is important to add the Magento store ID in the attributes section within `config/statamic/sites.php` for every site and use the store code as key. The current site will be determined based on the `MAGE_RUN_CODE`. By default Statamic uses the url for this; that's still the fallback.

```php
'sites' => [
Expand Down
21 changes: 21 additions & 0 deletions src/Extend/SitesLinkedToMagentoStores.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Rapidez\Statamic\Extend;

use Statamic\Sites\Sites;

class SitesLinkedToMagentoStores extends Sites
{
public function findByMageRunCode($code)
{
return collect($this->sites)->get($code);
}

public function current()
{
return $this->current
?? $this->findByMageRunCode(request()->server('MAGE_RUN_CODE'))
?? $this->findByUrl(request()->getUri())
?? $this->default();
}
}
9 changes: 9 additions & 0 deletions src/RapidezStatamicServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,26 @@
use Illuminate\Support\ServiceProvider;
use Illuminate\View\View as RenderedView;
use Rapidez\Core\Facades\Rapidez;
use Rapidez\Statamic\Extend\SitesLinkedToMagentoStores;
use Rapidez\Statamic\Forms\JsDrivers\Vue;
use Rapidez\Statamic\Http\Controllers\StatamicRewriteController;
use Rapidez\Statamic\Http\ViewComposers\StatamicGlobalDataComposer;
use Statamic\Events\GlobalSetDeleted;
use Statamic\Events\GlobalSetSaved;
use Statamic\Facades\Entry;
use Statamic\Facades\Site;
use Statamic\Sites\Sites;
use Statamic\Statamic;

class RapidezStatamicServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->extend(Sites::class, function () {
return new SitesLinkedToMagentoStores(config('statamic.sites'));
});
}

public function boot()
{
$this
Expand Down

0 comments on commit 7342d7e

Please sign in to comment.