From 0fa76edd4afe055daa8e7c9c3ba6fa528f77105d Mon Sep 17 00:00:00 2001 From: Kevin Meijer Date: Thu, 8 Aug 2024 09:18:17 +0200 Subject: [PATCH 1/3] Statamic 5 support + install command (#67) --- README.md | 49 ++++++++++++----- composer.json | 12 +++-- resources/views/page_builder.blade.php | 2 +- .../views/page_builder/content.blade.php | 2 +- src/Commands/InstallCommand.php | 52 +++++++++++++++++++ src/Models/Brand.php | 4 +- src/Models/Category.php | 4 +- src/Models/Product.php | 4 +- src/RapidezStatamicServiceProvider.php | 6 ++- 9 files changed, 106 insertions(+), 29 deletions(-) create mode 100644 src/Commands/InstallCommand.php diff --git a/README.md b/README.md index ec6f9e8..77123c2 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,28 @@ 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. + +``` +php artisan rapidez-statamic:install +``` + +Please make sure to use the following settings 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: @@ -57,6 +79,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 ``` @@ -70,21 +94,18 @@ 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. +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. 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: '{{ config:app:name }}' + url: / + locale: nl_NL + attributes: + magento_store_id: 1 + group: 'default' + disabled: false -```php -'sites' => [ - 'default' => [ - 'name' => config('app.name'), - 'locale' => 'nl_NL', - 'url' => '/', - 'attributes' => [ - 'magento_store_id' => 1, - 'group' => 'default', - 'disabled' => false, - ] - ], -] ``` ### Showing content on categories and products diff --git a/composer.json b/composer.json index 8ebf725..9c9b117 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/resources/views/page_builder.blade.php b/resources/views/page_builder.blade.php index 68f6c54..a8ca800 100644 --- a/resources/views/page_builder.blade.php +++ b/resources/views/page_builder.blade.php @@ -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 diff --git a/resources/views/page_builder/content.blade.php b/resources/views/page_builder/content.blade.php index c4bd18d..285cf89 100644 --- a/resources/views/page_builder/content.blade.php +++ b/resources/views/page_builder/content.blade.php @@ -1,6 +1,6 @@
@foreach($content as $set) - @if($set->type->get() == 'text') + @if($set->type === 'text') {!! $set->text !!} @else
diff --git a/src/Commands/InstallCommand.php b/src/Commands/InstallCommand.php new file mode 100644 index 0000000..f66718d --- /dev/null +++ b/src/Commands/InstallCommand.php @@ -0,0 +1,52 @@ +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 🚀'); + } +} diff --git a/src/Models/Brand.php b/src/Models/Brand.php index 2448e8c..79476f9 100644 --- a/src/Models/Brand.php +++ b/src/Models/Brand.php @@ -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; @@ -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')); }); diff --git a/src/Models/Category.php b/src/Models/Category.php index 69f4908..96a5c2f 100644 --- a/src/Models/Category.php +++ b/src/Models/Category.php @@ -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; @@ -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')); } } diff --git a/src/Models/Product.php b/src/Models/Product.php index 27c6b44..12636c7 100644 --- a/src/Models/Product.php +++ b/src/Models/Product.php @@ -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; @@ -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'); } } diff --git a/src/RapidezStatamicServiceProvider.php b/src/RapidezStatamicServiceProvider.php index b9b16a8..dd4b094 100644 --- a/src/RapidezStatamicServiceProvider.php +++ b/src/RapidezStatamicServiceProvider.php @@ -18,6 +18,7 @@ use Illuminate\Support\ServiceProvider; use Illuminate\View\View as RenderedView; use Rapidez\Statamic\Commands\ImportBrands; +use Rapidez\Statamic\Commands\InstallCommand; use Rapidez\Statamic\Forms\JsDrivers\Vue; use Rapidez\Statamic\Commands\ImportProducts; use Rapidez\Statamic\Commands\ImportCategories; @@ -60,6 +61,7 @@ public function bootCommands() : self ImportCategories::class, ImportProducts::class, ImportBrands::class, + InstallCommand::class, ]); return $this; @@ -119,8 +121,8 @@ public function bootRunway() : self { if (config('rapidez.statamic.runway.configure') && $this->currentSiteIsEnabled()) { config(['runway.resources' => array_merge( - config('rapidez.statamic.runway.resources'), - config('runway.resources') + config('rapidez.statamic.runway.resources') ?? [], + config('runway.resources') ?? [] )]); } From 9a5f52bc11f4bde162e868b1834be7331756ed15 Mon Sep 17 00:00:00 2001 From: Kevin Meijer Date: Thu, 8 Aug 2024 09:58:47 +0200 Subject: [PATCH 2/3] Updated readme --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 77123c2..523ab82 100644 --- a/README.md +++ b/README.md @@ -24,12 +24,15 @@ 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 ``` -Please make sure to use the following settings when setting up the eloquent driver: +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 @@ -208,6 +211,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! From 1670d5ecfc874e5107995eddb59a7a9e0b7c2a7a Mon Sep 17 00:00:00 2001 From: Bob Date: Thu, 8 Aug 2024 13:45:29 +0200 Subject: [PATCH 3/3] Config and runway blueprints --- README.md | 30 +++++++++++---- config/rapidez/statamic.php | 47 +++++++---------------- resources/blueprints/runway/brand.yaml | 31 +++++++++++++++ resources/blueprints/runway/category.yaml | 17 ++++++++ resources/blueprints/runway/product.yaml | 23 +++++++++++ src/RapidezStatamicServiceProvider.php | 1 + 6 files changed, 108 insertions(+), 41 deletions(-) create mode 100644 resources/blueprints/runway/brand.yaml create mode 100644 resources/blueprints/runway/category.yaml create mode 100644 resources/blueprints/runway/product.yaml diff --git a/README.md b/README.md index 523ab82..fa2a754 100644 --- a/README.md +++ b/README.md @@ -97,18 +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 `resources/sites.yaml` 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. +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:app:name }}' - url: / - locale: nl_NL + 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: 1 - group: 'default' - disabled: false - + 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 diff --git a/config/rapidez/statamic.php b/config/rapidez/statamic.php index 1b32c03..0ff694b 100644 --- a/config/rapidez/statamic.php +++ b/config/rapidez/statamic.php @@ -59,17 +59,6 @@ '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 => [ @@ -77,16 +66,6 @@ '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 => [ @@ -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, + ], + ], + ] ]; diff --git a/resources/blueprints/runway/brand.yaml b/resources/blueprints/runway/brand.yaml new file mode 100644 index 0000000..4348142 --- /dev/null +++ b/resources/blueprints/runway/brand.yaml @@ -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 diff --git a/resources/blueprints/runway/category.yaml b/resources/blueprints/runway/category.yaml new file mode 100644 index 0000000..eb76fee --- /dev/null +++ b/resources/blueprints/runway/category.yaml @@ -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 diff --git a/resources/blueprints/runway/product.yaml b/resources/blueprints/runway/product.yaml new file mode 100644 index 0000000..9be5997 --- /dev/null +++ b/resources/blueprints/runway/product.yaml @@ -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 diff --git a/src/RapidezStatamicServiceProvider.php b/src/RapidezStatamicServiceProvider.php index dd4b094..be77fcb 100644 --- a/src/RapidezStatamicServiceProvider.php +++ b/src/RapidezStatamicServiceProvider.php @@ -170,6 +170,7 @@ public function bootPublishables() : self __DIR__.'/../resources/content/collections' => base_path('content/collections'), __DIR__.'/../resources/content/assets' => base_path('content/assets'), __DIR__.'/../resources/fieldsets' => resource_path('fieldsets'), + __DIR__.'/../resources/blueprints/runway' => resource_path('blueprints/vendor/runway'), ], 'rapidez-statamic-content'); $this->publishes([