diff --git a/README.md b/README.md index 5da2f89..72b54b3 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# [![](https://bitbag.io/wp-content/uploads/2021/01/SULU.png)](https://bitbag.io/contact-us/?utm_source=github&utm_medium=referral&utm_campaign=plugins_sulu) +# [![](https://bitbag.io/wp-content/uploads/2024/02/SyliusSuluPlugin.png)](https://bitbag.io/contact-us/?utm_source=github&utm_medium=referral&utm_campaign=plugins_sulu) # BitBag SyliusSuluPlugin @@ -32,11 +32,12 @@ Because the frontend of each store is always personalized, the plugin for the mo It only provides an abstraction layer and examples which you should use to create your own pages or blocks -- [Installation](doc/installation.md) -- [Sulu configuration](doc/sulu_configuration.md) -- [Use Cases](doc/use_case.md) -- [Twig functions](doc/twig-functions.md) -- [Cache](doc/caching.md) +- [Installation](docs/installation.md) +- [Sulu configuration](docs/sulu_configuration.md) +- [Use Cases](docs/use_case.md) +- [Twig functions](docs/twig-functions.md) +- [Cache](docs/caching.md) +- [Examples](docs/examples.md) ## We are here to help This **open-source plugin was developed to help the Sylius community**. If you have any additional questions, would like help with installing or configuring the plugin, or need any assistance with your Sylius project - let us know! diff --git a/config/services/strategy.xml b/config/services/strategy.xml index 7313192..b522f93 100644 --- a/config/services/strategy.xml +++ b/config/services/strategy.xml @@ -10,11 +10,13 @@ id="bitbag.sylius_sulu_plugin.renderer.block.sulu_block_renderer_strategy" > + + diff --git a/docs/examples.md b/docs/examples.md new file mode 100644 index 0000000..747570a --- /dev/null +++ b/docs/examples.md @@ -0,0 +1,11 @@ +## Examples: + +Examples for rendering pages with blocks depending on the response from sulu are included in `tests` directory: + +- `tests/Behat/ApiResponseMock` - Mocked sulu responses +- `tests/Application/src/Renderer/Block` Block renderers +- `tests/Application/templates/bundles/BitBagSyliusSuluPlugin/shop/block` -> Templates for blocks +- `tests/Application/src/Renderer/Page` Page renderers +- `tests/Application/templates/bundles/BitBagSyliusSuluPlugin/shop/page` -> Templates for blocks +- `tests/Application/config/services_test.yaml` -> Manual service declarations + diff --git a/docs/installation.md b/docs/installation.md index 4ad3aae..0e595af 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -46,7 +46,50 @@ class Channel extends BaseChannel use SuluChannelConfigurationTrait; ``` -5. Finish the installation by updating the database schema +6. Implement `\BitBag\SyliusSuluPlugin\Entity\ChannelInterface` + + +7. Add doctrine mapping. Choose xml, attributes or annotations, depending what you use on project. + +Xml +```xml + + + + + + + + +``` + +Attributes or Annotations +```php + +/** + * @ORM\Entity + * @ORM\Table(name='sylius_channel') + */ +#[ORM\Entity] +#[ORM\Table(name: 'sylius_channel')] +class Channel extends BaseChannel +{ + + use SuluChannelConfigurationTrait; + + /** @ORM\Column(type='boolean', nullable=false name='sulu_use_localized_url') */ + #[ORM\Column(type: 'boolean', nullable: false, name: 'sulu_use_localized_url')] + protected bool $suluUseLocalizedUrls = false; +} + +``` + +8. Finish the installation by updating the database schema ``` $ bin/console cache:clear @@ -58,14 +101,7 @@ $ bin/console doctrine:migrations:migrate ```bash $ composer install $ cd tests/Application -``` -Copy file `package.json.~1.XX.0.dist` to `package.json` where `~1.XX.0` is the Sylius version you are using. -```bash -$ cp package.json.~1.12.0.dist package.json -``` - -```bash $ yarn install $ yarn encore dev $ APP_ENV=test bin/console assets:install diff --git a/docs/twig_functions.md b/docs/twig_functions.md index 8584eda..afc7a97 100644 --- a/docs/twig_functions.md +++ b/docs/twig_functions.md @@ -1,12 +1,11 @@ ## Twig functions -Plugins provide a few twig functions which allows to render blocks and pages. - -1.Twig extensions methods: +Plugins provide a few twig functions which allows to render blocks and pages. All of them are listed below: ```php 'bitbag_get_sulu_page(pageUrl)' -> Fetch the page with the specified url from sulu. 'bitbag_render_sulu_page(pageUrl)' -> Render the page. It is using the strategy abstraction for rendering. 'bitbag_render_sulu_blocks(blocks)' -> Render all passed blocks. You can use it when you are sure that you dont need any other html tags. - 'bitbag_render_sulu_blocks_with_type' -> Render blocks with specified type. You can pass a string (or html) which will be added between blocks and at the end - 'bitbag_render_sulu_block_with_type' -> Render one specified block. If is more then one, then only first is rendered + 'bitbag_render_sulu_blocks_with_type(blocks, type)' -> Render blocks with specified type. You can pass a string (or html) which will be added between blocks and at the end + 'bitbag_render_sulu_block_with_type(blocks, type)' -> Render one specified block. If is more then one, then only first is rendered + 'bitbag_page_has_sulu_block(pageUrl, blockType)' -> Check if sulu page contains a block with specified type. ``` diff --git a/spec/Controller/Action/PurgeSuluCacheActionSpec.php b/spec/Controller/Action/PurgeSuluCacheActionSpec.php index 465c477..9ff4fd3 100644 --- a/spec/Controller/Action/PurgeSuluCacheActionSpec.php +++ b/spec/Controller/Action/PurgeSuluCacheActionSpec.php @@ -1,5 +1,11 @@ get('HTTP_REFERER')->willReturn($referer); $session->getFlashBag()->willReturn($flashbag); + $channel->implement(BaseChannelInterface::class); $channel->getCode()->willReturn('TEST'); $channelRepository->find($channelId)->willReturn($channel); diff --git a/spec/Controller/Action/RenderPageActionSpec.php b/spec/Controller/Action/RenderPageActionSpec.php index abadab0..2193175 100644 --- a/spec/Controller/Action/RenderPageActionSpec.php +++ b/spec/Controller/Action/RenderPageActionSpec.php @@ -1,5 +1,11 @@ beConstructedWith([$blockRenderer1, $blockRenderer2]); + $this->beConstructedWith([$blockRenderer1, $blockRenderer2], $logger); } function it_is_initializable() diff --git a/spec/Renderer/Page/SuluPageRendererStrategySpec.php b/spec/Renderer/Page/SuluPageRendererStrategySpec.php index 5442595..9d465b4 100644 --- a/spec/Renderer/Page/SuluPageRendererStrategySpec.php +++ b/spec/Renderer/Page/SuluPageRendererStrategySpec.php @@ -1,5 +1,11 @@ beConstructedWith([$pageRenderer1, $pageRenderer2]); + $this->beConstructedWith([$pageRenderer1, $pageRenderer2], $logger); } function it_is_initializable() diff --git a/spec/Twig/Runtime/SuluRuntimeSpec.php b/spec/Twig/Runtime/SuluRuntimeSpec.php index 41247a0..f02730d 100644 --- a/spec/Twig/Runtime/SuluRuntimeSpec.php +++ b/spec/Twig/Runtime/SuluRuntimeSpec.php @@ -1,5 +1,11 @@ logger->error(sprintf( + '%s%s', + 'Something goes wrong on page render. Error message : ', + $error->getMessage(), + )); + return ''; } } diff --git a/src/Renderer/Page/SuluPageRendererStrategy.php b/src/Renderer/Page/SuluPageRendererStrategy.php index f5d8b5f..ce7a5ea 100644 --- a/src/Renderer/Page/SuluPageRendererStrategy.php +++ b/src/Renderer/Page/SuluPageRendererStrategy.php @@ -10,6 +10,7 @@ namespace BitBag\SyliusSuluPlugin\Renderer\Page; +use Psr\Log\LoggerInterface; use Twig\Error\Error; use Twig\Error\RuntimeError; @@ -17,6 +18,7 @@ final class SuluPageRendererStrategy implements SuluPageRendererStrategyInterfac { public function __construct( private iterable $pageRenderers, + private LoggerInterface $logger, ) { } @@ -33,6 +35,12 @@ public function renderPage(array $page): string return $content; } catch (Error $error) { + $this->logger->error(sprintf( + '%s%s', + 'Something goes wrong on page render. Error message : ', + $error->getMessage(), + )); + return ''; } } diff --git a/tests/Application/src/Entity/Channel/Channel.php b/tests/Application/src/Entity/Channel/Channel.php index e8ccea3..7933b5a 100644 --- a/tests/Application/src/Entity/Channel/Channel.php +++ b/tests/Application/src/Entity/Channel/Channel.php @@ -1,5 +1,11 @@