Skip to content

Sylius 2.x compatibility #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,7 @@ $ bin/console doctrine:migrations:diff
$ bin/console doctrine:migrations:migrate
```

### Step 5: Copy template

You can copy the templates under `tests/Application/templates/bundles/SyliusAdminBundle` into your own application to enable the possibility to add an automatic redirection when updating product

### Step 6: Install assets
### Step 5: Install assets
```bash
$ bin/console assets:install
```
Expand Down
51 changes: 26 additions & 25 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,33 @@
"sylius-plugin"
],
"require": {
"php": ">=7.4",
"doctrine/collections": "^1.6",
"php": ">=8.2",
"doctrine/collections": "^2.2",
"doctrine/orm": "^2.7",
"doctrine/persistence": "^1.3 || ^2.1 || ^3.0",
"league/uri": "^6.0 || ^7.5",
"league/uri-components": "^2.3 || ^7.5",
"sylius/channel": "^1.0",
"sylius/channel-bundle": "^1.0",
"sylius/core-bundle": "^1.0",
"sylius/product-bundle": "^1.0",
"sylius/resource-bundle": "^1.6",
"sylius/taxonomy-bundle": "^1.0",
"sylius/ui-bundle": "^1.0",
"symfony/config": "^5.4 || ^6.0",
"symfony/console": "^5.4 || ^6.0",
"symfony/dependency-injection": "^5.4 || ^6.0",
"symfony/event-dispatcher": "^5.4 || ^6.0",
"symfony/form": "^5.4 || ^6.0",
"symfony/http-foundation": "^5.4 || ^6.0",
"symfony/http-kernel": "^5.4 || ^6.0",
"symfony/routing": "^5.4 || ^6.0",
"symfony/validator": "^5.4 || ^6.0",
"sylius/channel": "^2.0",
"sylius/channel-bundle": "^2.0",
"sylius/core-bundle": "^2.0",
"sylius/product-bundle": "^2.0",
"sylius/resource-bundle": "^1.12",
"sylius/taxonomy-bundle": "^2.0",
"sylius/ui-bundle": "^2.0",
"symfony/config": "^6.4 || ^7.1",
"symfony/console": "^6.4 || ^7.1",
"symfony/dependency-injection": "^6.4 || ^7.1",
"symfony/event-dispatcher": "^6.4 || ^7.1",
"symfony/form": "^6.4 || ^7.1",
"symfony/http-foundation": "^6.4 || ^7.1",
"symfony/http-kernel": "^6.4 || ^7.1",
"symfony/routing": "^6.4 || ^7.1",
"symfony/validator": "^6.4 || ^7.1",
"webmozart/assert": "^1.11"
},
"require-dev": {
"api-platform/core": "^2.7",
"lexik/jwt-authentication-bundle": "^2.16",
"lexik/jwt-authentication-bundle": "^3.1",
"php-http/message-factory": "^1.1",
"phpspec/phpspec": "^7.3",
"phpspec/prophecy-phpunit": "^2.0",
Expand All @@ -45,12 +45,12 @@
"psalm/plugin-symfony": "^5.0",
"setono/code-quality-pack": "^2.4",
"setono/sylius-behat-pack": "^0.2",
"sylius/sylius": "~1.10.14",
"symfony/debug-bundle": "^5.4 || ^6.0",
"symfony/dotenv": "^5.4 || ^6.0",
"symfony/intl": "^5.4 || ^6.0",
"symfony/web-profiler-bundle": "^5.4 || ^6.0",
"symfony/webpack-encore-bundle": "^1.16"
"sylius/sylius": "~2.0.0",
"symfony/debug-bundle": "^6.4 || ^7.1",
"symfony/dotenv": "^6.4 || ^7.1",
"symfony/intl": "^6.4 || ^7.1",
"symfony/web-profiler-bundle": "^6.4 || ^7.1",
"symfony/webpack-encore-bundle": "^2.2"
},
"prefer-stable": true,
"autoload": {
Expand All @@ -71,6 +71,7 @@
"dealerdirect/phpcodesniffer-composer-installer": false,
"ergebnis/composer-normalize": true,
"ocramius/package-versions": true,
"php-http/discovery": true,
"symfony/thanks": false
},
"sort-packages": true
Expand Down
21 changes: 12 additions & 9 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@

declare(strict_types=1);

use PhpCsFixer\Fixer\Operator\BinaryOperatorSpacesFixer;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\EasyCodingStandard\ValueObject\Option;
use PhpCsFixer\Fixer\ClassNotation\VisibilityRequiredFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;

return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import('vendor/sylius-labs/coding-standard/ecs.php');
$containerConfigurator->parameters()->set(Option::PATHS, [
'src', 'tests'
return static function (ECSConfig $ecsConfig): void {
$ecsConfig->paths([
__DIR__ . '/src',
__DIR__ . '/tests/',
__DIR__ . '/ecs.php',
]);
$containerConfigurator->parameters()->set(Option::SKIP, [
'tests/Application/**',

$ecsConfig->import('vendor/sylius-labs/coding-standard/ecs.php');

$ecsConfig->skip([
VisibilityRequiredFixer::class => ['*Spec.php'],
]);
};
6 changes: 0 additions & 6 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.14.1@b9d355e0829c397b9b3b47d0c0ed042a8a70284d">
<file src="src/Finder/RemovableRedirectFinder.php">
<InvalidArgument>
<code>$firstRedirect</code>
<code>$firstRedirect</code>
</InvalidArgument>
</file>
</files>
6 changes: 4 additions & 2 deletions src/Command/RemoveRedirectsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

class RemoveRedirectsCommand extends Command
{
protected static $defaultName = 'setono:sylius-redirect:remove';
protected static string $defaultName = 'setono:sylius-redirect:remove';

protected static $defaultDescription = 'This command will remove redirects that have not been accessed later than x days ago where x is the `setono_sylius_redirect.remove_after` parameter';
protected static string $defaultDescription = 'This command will remove redirects that have not been accessed later than x days ago where x is the `setono_sylius_redirect.remove_after` parameter';

private RedirectRepositoryInterface $redirectRepository;

Expand All @@ -25,6 +25,8 @@ class RemoveRedirectsCommand extends Command
public function __construct(RedirectRepositoryInterface $redirectRepository, int $removeAfter)
{
parent::__construct();
$this->setName(self::$defaultName);
$this->setDescription(self::$defaultDescription);

$this->redirectRepository = $redirectRepository;
$this->removeAfter = $removeAfter;
Expand Down
4 changes: 2 additions & 2 deletions src/EventListener/ControllerSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class ControllerSubscriber implements EventSubscriberInterface
public function __construct(
ObjectManager $objectManager,
ChannelContextInterface $channelContext,
RedirectionPathResolverInterface $redirectionPathResolver
RedirectionPathResolverInterface $redirectionPathResolver,
) {
$this->objectManager = $objectManager;
$this->channelContext = $channelContext;
Expand All @@ -51,7 +51,7 @@ public function onKernelController(ControllerEvent $event): void
}
$redirectionPath = $this->redirectionPathResolver->resolveFromRequest(
$request,
$channel
$channel,
);

if ($redirectionPath->isEmpty()) {
Expand Down
4 changes: 2 additions & 2 deletions src/EventListener/NotFoundSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class NotFoundSubscriber implements EventSubscriberInterface
public function __construct(
ObjectManager $objectManager,
ChannelContextInterface $channelContext,
RedirectionPathResolverInterface $redirectionPathResolver
RedirectionPathResolverInterface $redirectionPathResolver,
) {
$this->objectManager = $objectManager;
$this->channelContext = $channelContext;
Expand Down Expand Up @@ -63,7 +63,7 @@ public function onKernelException(ExceptionEvent $event): void
$redirectionPath = $this->redirectionPathResolver->resolveFromRequest(
$request,
$channel,
true
true,
);

if ($redirectionPath->isEmpty()) {
Expand Down
2 changes: 1 addition & 1 deletion src/EventListener/RedirectResponseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static function getRedirectResponse(RedirectInterface $lastRedirect, stri

return new RedirectResponse(
$uri->__toString(),
$lastRedirect->isPermanent() ? Response::HTTP_MOVED_PERMANENTLY : Response::HTTP_FOUND
$lastRedirect->isPermanent() ? Response::HTTP_MOVED_PERMANENTLY : Response::HTTP_FOUND,
);
}
}
2 changes: 1 addition & 1 deletion src/Factory/RedirectFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function createNewWithValues(
string $destination,
bool $permanent = true,
bool $only404 = true,
iterable $channels = []
iterable $channels = [],
): RedirectInterface {
$redirect = $this->createNew();

Expand Down
2 changes: 1 addition & 1 deletion src/Factory/RedirectFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public function createNewWithValues(
string $destination,
bool $permanent = true,
bool $only404 = true,
iterable $channels = []
iterable $channels = [],
): RedirectInterface;
}
1 change: 0 additions & 1 deletion src/Model/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
class Redirect implements RedirectInterface
{
use TimestampableTrait;

use ToggleableTrait;

protected ?int $id = null;
Expand Down
2 changes: 1 addition & 1 deletion src/Repository/RedirectRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function removeNotAccessed(int $threshold): void
->delete()
->orWhere(
'r.lastAccessed is not null and r.lastAccessed <= :threshold',
'r.lastAccessed is null and r.createdAt <= :threshold'
'r.lastAccessed is null and r.createdAt <= :threshold',
)
->setParameter('threshold', $dateTimeThreshold)
->getQuery()
Expand Down
6 changes: 3 additions & 3 deletions src/Resolver/RedirectionPathResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(RedirectRepositoryInterface $redirectRepository)
public function resolve(
string $source,
ChannelInterface $channel = null,
bool $only404 = false
bool $only404 = false,
): RedirectionPath {
$redirectionPath = new RedirectionPath();

Expand All @@ -39,7 +39,7 @@ public function resolve(
$firstRedirect = $redirectionPath->first();

throw new InfiniteLoopException(
null !== $firstRedirect ? ($firstRedirect->getSource() ?? $source) : $source
null !== $firstRedirect ? ($firstRedirect->getSource() ?? $source) : $source,
);
}
} while (null !== $redirect && !$redirect->isOnly404()); // See this issue for explanation of this: https://github.com/Setono/SyliusRedirectPlugin/issues/27
Expand All @@ -50,7 +50,7 @@ public function resolve(
public function resolveFromRequest(
Request $request,
ChannelInterface $channel = null,
bool $only404 = false
bool $only404 = false,
): RedirectionPath {
return $this->resolve($request->getPathInfo(), $channel, $only404);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Resolver/RedirectionPathResolverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ public function resolve(string $source, ChannelInterface $channel = null, bool $
public function resolveFromRequest(
Request $request,
ChannelInterface $channel = null,
bool $only404 = false
bool $only404 = false,
): RedirectionPath;
}
9 changes: 1 addition & 8 deletions src/Resources/config/admin_routing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,7 @@ setono_sylius_redirect_admin_redirect:
alias: setono_sylius_redirect.redirect
section: admin
permission: true
templates: "@SyliusAdmin\\Crud"
templates: "@SyliusAdmin\\shared\\crud"
redirect: update
grid: setono_sylius_redirect_admin_redirect
vars:
all:
subheader: setono_sylius_redirect.ui.manage_redirects
templates:
form: "@SetonoSyliusRedirectPlugin/Admin/Redirect/_form.html.twig"
index:
icon: 'chart bar'
type: sylius.resource
1 change: 1 addition & 0 deletions src/Resources/config/app/config.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
imports:
- { resource: "@SetonoSyliusRedirectPlugin/Resources/config/grids.yaml" }
- { resource: "@SetonoSyliusRedirectPlugin/Resources/config/twig/twig_hooks.yaml" }
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ sylius_grid:
type: twig
label: setono_sylius_redirect.ui.permanent
options:
template: "@SyliusUi/Grid/Field/yesNo.html.twig"
template: "@SyliusUi/grid/field/yes_no.html.twig"
enabled:
type: twig
label: setono_sylius_redirect.ui.enabled
options:
template: "@SyliusUi/Grid/Field/yesNo.html.twig"
template: "@SyliusUi/grid/field/yes_no.html.twig"
count:
type: string
label: setono_sylius_redirect.ui.count
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
<import resource="services/form.xml"/>
<import resource="services/resolver.xml"/>
<import resource="services/slug_update_handler.xml"/>
<import resource="services/twig.xml"/>
</imports>
</container>
16 changes: 16 additions & 0 deletions src/Resources/config/services/twig.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="setono_sylius_redirect.twig.product_form_subscriber" class="Setono\SyliusRedirectPlugin\Twig\EventSubscriber\ProductFormComponentSubscriber">
<argument type="service" id="request_stack" />
<tag name="kernel.event_subscriber" />
</service>

<service id="setono_sylius_redirect.twig.taxon_form_subscriber" class="Setono\SyliusRedirectPlugin\Twig\EventSubscriber\TaxonFormComponentSubscriber">
<argument type="service" id="request_stack" />
<tag name="kernel.event_subscriber" />
</service>
</services>
</container>
10 changes: 10 additions & 0 deletions src/Resources/config/twig/twig_hooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sylius_twig_hooks:
hooks:
'sylius_admin.product.update.content.form.sections.translations':
setono_sylius_redirect_admin_redirect:
template: '@SetonoSyliusRedirectPlugin/Admin/Product/add_automatic_redirect.html.twig'
priority: 350
'sylius_admin.taxon.update.content.sections.form.translations':
setono_sylius_redirect_admin_redirect:
template: '@SetonoSyliusRedirectPlugin/Admin/Taxon/add_automatic_redirect.html.twig'
priority: 50
26 changes: 0 additions & 26 deletions src/Resources/public/admin/js/updateProductSlug.js

This file was deleted.

17 changes: 0 additions & 17 deletions src/Resources/public/admin/js/updateSlug.js

This file was deleted.

Loading