Skip to content

Commit

Permalink
OP-231 - CR and readme fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
BartoszWojdalowicz committed Feb 26, 2024
1 parent 9cec5ea commit e9911d9
Show file tree
Hide file tree
Showing 27 changed files with 205 additions and 35 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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!
Expand Down
2 changes: 2 additions & 0 deletions config/services/strategy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
id="bitbag.sylius_sulu_plugin.renderer.block.sulu_block_renderer_strategy"
>
<argument type="tagged_iterator" tag="bitbag.sylius_sulu_plugin.strategy.block_renderer"/>
<argument type="service" id="monolog.logger"/>
</service>

<service class="BitBag\SyliusSuluPlugin\Renderer\Page\SuluPageRendererStrategy"
id="bitbag.sylius_sulu_plugin.renderer.page.sulu_page_renderer_strategy">
<argument type="tagged_iterator" tag="bitbag.sylius_sulu_plugin.strategy.page_renderer"/>
<argument type="service" id="monolog.logger"/>
</service>
</services>
</container>
11 changes: 11 additions & 0 deletions docs/examples.md
Original file line number Diff line number Diff line change
@@ -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

52 changes: 44 additions & 8 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping
xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"
>
<entity name="App\Entity\Channel\Channel" table="sylius_channel">
<field name="suluUseLocalizedUrls" column="sulu_use_localized_url" type="boolean"/>
</entity>
</doctrine-mapping>
```

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
Expand All @@ -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
Expand Down
9 changes: 4 additions & 5 deletions docs/twig_functions.md
Original file line number Diff line number Diff line change
@@ -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.
```
8 changes: 8 additions & 0 deletions spec/Controller/Action/PurgeSuluCacheActionSpec.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace spec\BitBag\SyliusSuluPlugin\Controller\Action;
Expand All @@ -8,6 +14,7 @@
use BitBag\SyliusSuluPlugin\Entity\ChannelInterface;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
use Sylius\Component\Core\Model\ChannelInterface as BaseChannelInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
Expand Down Expand Up @@ -52,6 +59,7 @@ function it_returns_response(
$serverBag->get('HTTP_REFERER')->willReturn($referer);
$session->getFlashBag()->willReturn($flashbag);

$channel->implement(BaseChannelInterface::class);
$channel->getCode()->willReturn('TEST');
$channelRepository->find($channelId)->willReturn($channel);

Expand Down
6 changes: 6 additions & 0 deletions spec/Controller/Action/RenderPageActionSpec.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace spec\BitBag\SyliusSuluPlugin\Controller\Action;
Expand Down
15 changes: 13 additions & 2 deletions spec/Renderer/Block/SuluBlockRendererStrategySpec.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace spec\BitBag\SyliusSuluPlugin\Renderer\Block;

use BitBag\SyliusSuluPlugin\Renderer\Block\SuluBlockRendererStrategy;
use BitBag\SyliusSuluPlugin\Renderer\Block\SuluBlockRenderStrategyInterface;
use PhpSpec\ObjectBehavior;
use Psr\Log\LoggerInterface;
use Twig\Error\Error;
use Twig\Error\RuntimeError;

class SuluBlockRendererStrategySpec extends ObjectBehavior
{
function let(SuluBlockRenderStrategyInterface $blockRenderer1, SuluBlockRenderStrategyInterface $blockRenderer2)
function let(
SuluBlockRenderStrategyInterface $blockRenderer1,
SuluBlockRenderStrategyInterface $blockRenderer2,
LoggerInterface $logger
)
{
$this->beConstructedWith([$blockRenderer1, $blockRenderer2]);
$this->beConstructedWith([$blockRenderer1, $blockRenderer2], $logger);
}

function it_is_initializable()
Expand Down
10 changes: 9 additions & 1 deletion spec/Renderer/Page/SuluPageRendererStrategySpec.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace spec\BitBag\SyliusSuluPlugin\Renderer\Page;

use BitBag\SyliusSuluPlugin\Renderer\Page\SuluPageRendererStrategy;
use BitBag\SyliusSuluPlugin\Renderer\Page\SuluPageRenderStrategyInterface;
use PhpSpec\ObjectBehavior;
use Psr\Log\LoggerInterface;
use Twig\Error\Error;

class SuluPageRendererStrategySpec extends ObjectBehavior
{
function let(
SuluPageRenderStrategyInterface $pageRenderer1,
SuluPageRenderStrategyInterface $pageRenderer2,
LoggerInterface $logger
) {
$this->beConstructedWith([$pageRenderer1, $pageRenderer2]);
$this->beConstructedWith([$pageRenderer1, $pageRenderer2], $logger);
}

function it_is_initializable()
Expand Down
6 changes: 6 additions & 0 deletions spec/Twig/Runtime/SuluRuntimeSpec.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace spec\BitBag\SyliusSuluPlugin\Twig\Runtime;
Expand Down
4 changes: 1 addition & 3 deletions src/Entity/ChannelInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

namespace BitBag\SyliusSuluPlugin\Entity;

use Sylius\Component\Core\Model\ChannelInterface as BaseChannelInterface;

interface ChannelInterface extends BaseChannelInterface
interface ChannelInterface
{
public function isSuluUseLocalizedUrls(): bool;

Expand Down
10 changes: 0 additions & 10 deletions src/Entity/SuluChannelConfigurationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,8 @@

namespace BitBag\SyliusSuluPlugin\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
*
* @ORM\Table(name="sylius_channel")
*/
#[ORM\Entity]
#[ORM\Table(name: 'sylius_channel')]
trait SuluChannelConfigurationTrait
{
/** @ORM\Column(type="boolean", nullable=false) */
protected bool $suluUseLocalizedUrls = false;

public function isSuluUseLocalizedUrls(): bool
Expand Down
8 changes: 8 additions & 0 deletions src/Renderer/Block/SuluBlockRendererStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@

namespace BitBag\SyliusSuluPlugin\Renderer\Block;

use Psr\Log\LoggerInterface;
use Twig\Error\Error;
use Twig\Error\RuntimeError;

final class SuluBlockRendererStrategy implements SuluBlockRendererStrategyInterface
{
public function __construct(
private iterable $blockRenderers,
private LoggerInterface $logger,
) {
}

Expand All @@ -33,6 +35,12 @@ public function renderBlock(array $blockData): string

return $content;
} catch (Error $error) {
$this->logger->error(sprintf(
'%s%s',
'Something goes wrong on page render. Error message : ',
$error->getMessage(),
));

return '';
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/Renderer/Page/SuluPageRendererStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@

namespace BitBag\SyliusSuluPlugin\Renderer\Page;

use Psr\Log\LoggerInterface;
use Twig\Error\Error;
use Twig\Error\RuntimeError;

final class SuluPageRendererStrategy implements SuluPageRendererStrategyInterface
{
public function __construct(
private iterable $pageRenderers,
private LoggerInterface $logger,
) {
}

Expand All @@ -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 '';
}
}
Expand Down
6 changes: 6 additions & 0 deletions tests/Application/src/Entity/Channel/Channel.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace Tests\BitBag\SyliusSuluPlugin\Application\src\Entity\Channel;
Expand Down
6 changes: 6 additions & 0 deletions tests/Application/src/Renderer/Block/ImageRenderer.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace Tests\BitBag\SyliusSuluPlugin\Application\src\Renderer\Block;
Expand Down
6 changes: 6 additions & 0 deletions tests/Application/src/Renderer/Block/QuoteRenderer.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace Tests\BitBag\SyliusSuluPlugin\Application\src\Renderer\Block;
Expand Down
6 changes: 6 additions & 0 deletions tests/Application/src/Renderer/Block/TextRenderer.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace Tests\BitBag\SyliusSuluPlugin\Application\src\Renderer\Block;
Expand Down
6 changes: 6 additions & 0 deletions tests/Application/src/Renderer/Page/BlogPageRenderer.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace Tests\BitBag\SyliusSuluPlugin\Application\src\Renderer\Page;
Expand Down
Loading

0 comments on commit e9911d9

Please sign in to comment.