Skip to content

Commit

Permalink
Statamic 5 support + install command (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
royduin authored Aug 13, 2024
1 parent fc5b4d8 commit 7491ead
Show file tree
Hide file tree
Showing 13 changed files with 215 additions and 62 deletions.
72 changes: 58 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,31 @@ You need to have `statamic/cms` installed in your Rapidez installation. Follow t
composer require rapidez/statamic
```

## Install command

The install command will help you set up all the necessary settings.
It will mainly setup the [Eloquent driver](https://github.com/statamic/eloquent-driver) and publish the necessary vendor from the rapidez/statamic repo.

```
php artisan rapidez-statamic:install
```

When running the install command you will be prompted to setup the Eloquent driver.
In this configuration you can choose what to keep in the flat file system and what to migrate to the database.
We recommend migrating the following options to the database when setting up the eloquent driver:
- Assets
- Collection Trees
- Entries
- Forms
- Form Submissions
- Globals
- Global Variables
- Navigation Trees
- Terms
- Tokens

After you're done running the install command make sure to check the guide below for some manual changes.

## Configuration

Have a look within the `rapidez/statamic.php` config file, if you need to change something you can publish it with:
Expand Down Expand Up @@ -57,6 +82,8 @@ If you'd like to use the homepage from Statamic instead of the CMS page from Mag

### Publish Collections, Blueprints and Fieldsets

If you have run the install command these will already have been published.

```
php artisan vendor:publish --provider="Rapidez\Statamic\RapidezStatamicServiceProvider" --tag=rapidez-statamic-content
```
Expand All @@ -70,21 +97,32 @@ php artisan vendor:publish --provider="Rapidez\Statamic\RapidezStatamicServicePr

### Magento Store ID

It is important to add the Magento store ID for every site in the attributes section within `config/statamic/sites.php` 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. If you need to generate some urls with a multisite it's a best practice to specify the `url` per site from env variables. See the [Statamic multisite docs](https://statamic.dev/multi-site#url). Optionally you could set the `group` within the `attributes` if you'd like to group sites to filter the alternate hreflang link tags. You could also set the `disabled` within the `attributes` section to true if you want to exclude this site from being altered with Statamic data.

```php
'sites' => [
'default' => [
'name' => config('app.name'),
'locale' => 'nl_NL',
'url' => '/',
'attributes' => [
'magento_store_id' => 1,
'group' => 'default',
'disabled' => false,
]
It is important to add the Magento store ID for every site in the attributes section within `resources/sites.yaml` and use the store code as key. Because the url can vary per enviroment(local, testing, staging, production) we use the "sites" section of the config file and reference that in the `sites.yaml`. 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. If you need to generate some urls with a multisite it's a best practice to specify the `url` per site from env variables. See the [Statamic multisite docs](https://statamic.dev/multi-site#url). Optionally you could set the `group` within the `attributes` if you'd like to group sites to filter the alternate hreflang link tags. You could also set the `disabled` within the `attributes` section to true if you want to exclude this site from being altered with Statamic data.
```yaml
'default' => [
'name' => env('APP_NAME', 'Statamic'),
'locale' => 'en_EN',
'lang' => 'en_EN',
'url' => '/',
'attributes' => [
'magento_store_id' => 1,
'group' => 'default',
'disabled' => false,
],
]
],
```


```yaml
default:
name: '{{ config:rapidez.statamic.sites.default.name }}'
locale: '{{ config:rapidez.statamic.sites.default.locale }}'
lang: '{{ config:rapidez.statamic.sites.default.lang }}'
url: '{{ config:rapidez.statamic.sites.default.url }}'
attributes:
magento_store_id: '{{ config:rapidez.statamic.sites.default.attributes.magento_store_id }}'
group: '{{ config:rapidez.statamic.sites.default.attributes.group }}'
disabled: '{{ config:rapidez.statamic.sites.default.attributes.disabled }}'
```
### Showing content on categories and products
Expand Down Expand Up @@ -187,6 +225,12 @@ Eventy::addFilter('rapidez.statamic.brand.entry.data', fn($brand) => [
);
```

### Globals

Globals will be available through the `$globals` variable.
For example; If you created a global with the handle `header` and added a field called `logo` in this global it will be available as `$globals->header->logo`.


### Forms

When you create a form you could use `rapidez-statamic::emails.form` as HTML template which uses the [Laravel mail template](https://laravel.com/docs/master/mail#customizing-the-components) with all fields in a table, make sure you enable markdown!
Expand Down
12 changes: 7 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": "^8.0|^8.1",
"doublethreedigital/runway": "^5.0",
"rapidez/blade-directives": "^0.4",
"spatie/statamic-responsive-images": "^4.0",
"statamic/cms": "^4.0",
"php": "^8.1|^8.2",
"justbetter/statamic-eloquent-driver-globalset-migration-generator": "^0.1.0",
"rapidez/blade-directives": "^0.6",
"spatie/statamic-responsive-images": "^5.0",
"statamic-rad-pack/runway": "^7.6",
"statamic/cms": "^5.0",
"statamic/eloquent-driver": "^4.9",
"tormjens/eventy": "^0.8"
},
"autoload": {
Expand Down
47 changes: 14 additions & 33 deletions config/rapidez/statamic.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,34 +59,13 @@
'read_only' => true,
'title_field' => 'name',
'cp_icon' => 'table',
'blueprint' => [
'sections' => [
'main' => [
'fields' => [
['handle' => 'entity_id', 'field' => ['type' => 'integer']],
['handle' => 'sku', 'field' => ['type' => 'text']],
['handle' => 'name', 'field' => ['type' => 'text']],
]
]
]
]
],

\Rapidez\Statamic\Models\Category::class => [
'name' => 'Categories',
'read_only' => true,
'title_field' => 'name',
'cp_icon' => 'array',
'blueprint' => [
'sections' => [
'main' => [
'fields' => [
['handle' => 'entity_id', 'field' => ['type' => 'integer']],
['handle' => 'name', 'field' => ['type' => 'text']],
]
]
]
]
],

\Rapidez\Statamic\Models\Brand::class => [
Expand All @@ -95,19 +74,21 @@
'title_field' => 'value_store',
'cp_icon' => 'tags',
'order_by' => 'sort_order',
'blueprint' => [
'sections' => [
'main' => [
'fields' => [
['handle' => 'option_id', 'field' => ['type' => 'integer']],
['handle' => 'sort_order', 'field' => ['type' => 'integer']],
['handle' => 'value_admin', 'field' => ['type' => 'text']],
['handle' => 'value_store', 'field' => ['type' => 'text']],
]
]
]
],
],
],
],

'sites' => [
'default' => [
'name' => env('APP_NAME', 'Statamic'),
'locale' => 'en_EN',
'lang' => 'en_EN',
'url' => '/',
'attributes' => [
'magento_store_id' => 1,
'group' => 'default',
'disabled' => false,
],
],
]
];
31 changes: 31 additions & 0 deletions resources/blueprints/runway/brand.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
tabs:
main:
display: Main
sections:
-
fields:
-
handle: option_id
field:
type: integer
localizable: false
visibility: read_only
-
handle: sort_order
field:
type: integer
localizable: false
visibility: read_only
-
handle: value_admin
field:
type: text
localizable: false
visibility: read_only
-
handle: value_store
field:
type: text
localizable: false
visibility: read_only
title: Brand
17 changes: 17 additions & 0 deletions resources/blueprints/runway/category.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
tabs:
main:
sections:
-
fields:
-
handle: entity_id
field:
type: integer
localizable: false
visibility: read_only
-
handle: name
field:
type: text
localizable: false
visibility: read_only
23 changes: 23 additions & 0 deletions resources/blueprints/runway/product.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
tabs:
main:
sections:
-
fields:
-
handle: entity_id
field:
type: integer
localizable: false
visibility: read_only
-
handle: sku
field:
type: text
localizable: false
visibility: read_only
-
handle: name
field:
type: text
localizable: false
visibility: read_only
2 changes: 1 addition & 1 deletion resources/views/page_builder.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@foreach ($content as $set)
@includeFirstSafe(['page_builder.' . $set['type'], 'rapidez-statamic::page_builder.' . $set['type']], $set)
@includeFirstSafe(['page_builder.' . $set['type'], 'rapidez-statamic::page_builder.' . $set['type']], optionalDeep($set)->toArray())
@endforeach
2 changes: 1 addition & 1 deletion resources/views/page_builder/content.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="prose max-w-none">
@foreach($content as $set)
@if($set->type->get() == 'text')
@if($set->type === 'text')
{!! $set->text !!}
@else
<div class="not-prose">
Expand Down
52 changes: 52 additions & 0 deletions src/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Rapidez\Statamic\Commands;

use Illuminate\Console\Command;

class InstallCommand extends Command
{
protected $signature = 'rapidez-statamic:install';

protected $description = 'Install Rapidez Statamic';

public function handle(): void
{
$this->call('vendor:publish', [
'--tag' => 'runway-config',
]);

$this->call('vendor:publish', [
'--provider' => 'Statamic\Eloquent\ServiceProvider',
'--tag' => 'statamic-eloquent-config',
]);

$this->confirm('Did you set the table_prefix in config/statamic/eloquent-driver.php to "statamic_"?', 1);

$this->call('statamic:install:eloquent-driver');

$this->info('If you would like to store users in the database please make sure to follow this guide: https://statamic.dev/tips/storing-users-in-a-database#from-a-fresh-statamic-project');

if ($this->confirm('Would you like to configure a multisite? Note: Configuring a multisite requires a Statamic PRO license.')) {
$this->call('statamic:multisite');
}

if ($this->confirm('Would you like to publish Collections, Blueprints, Fieldsets & Views?', 1)) {
$this->call('vendor:publish', [
'--provider' => 'Rapidez\Statamic\RapidezStatamicServiceProvider',
'--tag' => 'rapidez-statamic-content',
]);

$this->call('vendor:publish', [
'--provider' => 'Rapidez\Statamic\RapidezStatamicServiceProvider',
'--tag' => 'views',
]);
}

if ($this->confirm('Would you like to make a user?', 1)) {
$this->call('statamic:make:user');
}

$this->info('Done 🚀');
}
}
4 changes: 2 additions & 2 deletions src/Models/Brand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Rapidez\Statamic\Models;

use DoubleThreeDigital\Runway\Traits\HasRunwayResource;
use StatamicRadPack\Runway\Traits\HasRunwayResource;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
Expand Down Expand Up @@ -37,7 +37,7 @@ protected static function booting()
})
->leftJoinSub($renamedStore, 'store_value', function ($join) {
$join->on('store_value.sub_option_id', '=', 'eav_attribute_option.option_id')
->where('store_value.store_id', (Statamic::isCpRoute() ? Site::selected()->attributes['magento_store_id'] : Site::current()->attributes['magento_store_id']));
->where('store_value.store_id', (Statamic::isCpRoute() ? (Site::selected()->attributes['magento_store_id'] ?? '1') : (Site::current()->attributes['magento_store_id'] ?? '1')));
})
->where('attribute_id', config('rapidez.statamic.runway.brand_attribute_id'));
});
Expand Down
4 changes: 2 additions & 2 deletions src/Models/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Rapidez\Statamic\Models;

use DoubleThreeDigital\Runway\Traits\HasRunwayResource;
use StatamicRadPack\Runway\Traits\HasRunwayResource;
use Illuminate\Database\Eloquent\Model;
use Statamic\Facades\Site;
use Statamic\Statamic;
Expand All @@ -15,6 +15,6 @@ class Category extends Model

public function getTable()
{
return 'catalog_category_flat_store_'.(Statamic::isCpRoute() ? Site::selected()->attributes['magento_store_id'] : Site::current()->attributes['magento_store_id']);
return 'catalog_category_flat_store_'.(Statamic::isCpRoute() ? (Site::selected()->attributes['magento_store_id'] ?? '1') : (Site::current()->attributes['magento_store_id'] ?? '1'));
}
}
4 changes: 2 additions & 2 deletions src/Models/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Rapidez\Statamic\Models;

use DoubleThreeDigital\Runway\Traits\HasRunwayResource;
use StatamicRadPack\Runway\Traits\HasRunwayResource;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Statamic\Facades\Site;
Expand All @@ -24,6 +24,6 @@ protected static function booting()

public function getTable()
{
return 'catalog_product_flat_' . (Statamic::isCpRoute() ? Site::selected()->attributes['magento_store_id'] : Site::current()->attributes['magento_store_id']);
return 'catalog_product_flat_' . (Statamic::isCpRoute() ? (Site::selected()->attributes['magento_store_id'] ?? '1') : Site::current()->attributes['magento_store_id'] ?? '1');
}
}
Loading

0 comments on commit 7491ead

Please sign in to comment.