Skip to content

Sylius 2.x compatibility #82

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 7 commits into
base: 3.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
2 changes: 1 addition & 1 deletion .github/workflows/backwards-compatibility-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: "Setup PHP, with composer and extensions"
uses: "shivammathur/setup-php@v2"
with:
php-version: "8.1"
php-version: "8.2"
coverage: "none"

- name: "Install tool"
Expand Down
14 changes: 5 additions & 9 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
strategy:
matrix:
php-version:
- "8.1" # Always use the lowest version of PHP since a higher version could create actual syntax errors in lower versions
- "8.2" # Always use the lowest version of PHP since a higher version could create actual syntax errors in lower versions

dependencies:
- "highest"
Expand Down Expand Up @@ -72,16 +72,15 @@ jobs:
strategy:
matrix:
php-version:
- "8.1"
- "8.2"

dependencies:
- "lowest"
- "highest"

symfony:
- "~5.4.0"
- "~6.4.0"
- "~7.1.0"

steps:
- name: "Checkout"
Expand Down Expand Up @@ -119,16 +118,15 @@ jobs:
strategy:
matrix:
php-version:
- "8.1"
- "8.2"

dependencies:
- "lowest"
- "highest"

symfony:
- "~5.4.0"
- "~6.4.0"
- "~7.1.0"

steps:
- name: "Checkout"
Expand Down Expand Up @@ -163,16 +161,15 @@ jobs:
strategy:
matrix:
php-version:
- "8.1"
- "8.2"

dependencies:
- "lowest"
- "highest"

symfony:
- "~5.4.0"
- "~6.4.0"
- "~7.1.0"

steps:
- name: "Checkout"
Expand Down Expand Up @@ -204,16 +201,15 @@ jobs:
strategy:
matrix:
php-version:
- "8.1"
- "8.2"

dependencies:
- "lowest"
- "highest"

symfony:
- "~5.4.0"
- "~6.4.0"
- "~7.1.0"

steps:
- name: "Start MySQL"
Expand Down
32 changes: 0 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,38 +83,6 @@ $ php bin/console doctrine:migrations:diff
$ php bin/console doctrine:migrations:migrate
```

### Step 5: Override checkout complete form

Override the [Sylius Form](https://github.com/Sylius/Sylius/blob/master/src/Sylius/Bundle/ShopBundle/Resources/views/Checkout/Complete/_form.html.twig):

* If you haven't your own `templates/bundles/SyliusShopBundle/Checkout/Complete/_form.html.twig` yet:

```bash
$ cp vendor/sylius/sylius/src/Sylius/Bundle/ShopBundle/Resources/views/Checkout/Complete/_form.html.twig \
templates/bundles/SyliusShopBundle/Checkout/Complete/_form.html.twig
```

* If you already have it:

Add terms field (exactly this conditional way):

```twig
{# templates/bundles/SyliusShopBundle/Checkout/Complete/_form.html.twig #}
{% if form.terms is defined %}
{{ form_row(form.terms) }}
{% endif %}
```

So the final template will look like this:

```twig
{# templates/bundles/SyliusShopBundle/Checkout/Complete/_form.html.twig #}
{{ form_row(form.notes, {'attr': {'rows': 3}}) }}
{% if form.terms is defined %}
{{ form_row(form.terms) }}
{% endif %}
```

# Troubleshooting

* If you see `Neither the property "terms" nor one of the methods "terms()", "getterms()"/"isterms()"/"hasterms()" or "__call()" exist and have public access in class "Symfony\Component\Form\FormView".`
Expand Down
76 changes: 44 additions & 32 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,54 +9,65 @@
"terms"
],
"require": {
"php": ">=8.1",
"doctrine/collections": "^1.6",
"php": ">=8.2",
"doctrine/collections": "^2.2",
"doctrine/orm": "^2.7",
"fakerphp/faker": "^1.23",
"knplabs/knp-menu": "^3.1",
"sylius/channel": "^1.0",
"sylius/channel-bundle": "^1.0",
"sylius/core": "^1.0",
"sylius/core-bundle": "^1.0",
"sylius/locale": "^1.0",
"sylius/resource-bundle": "^1.6",
"sylius/ui-bundle": "^1.0",
"symfony/config": "^5.4 || ^6.4 || ^7.0",
"symfony/dependency-injection": "^5.4 || ^6.4 || ^7.0",
"symfony/event-dispatcher": "^5.4 || ^6.4 || ^7.0",
"symfony/form": "^5.4 || ^6.4 || ^7.0",
"symfony/http-foundation": "^5.4 || ^6.4 || ^7.0",
"symfony/http-kernel": "^5.4 || ^6.4 || ^7.0",
"symfony/options-resolver": "^5.4 || ^6.4 || ^7.0",
"symfony/routing": "^5.4 || ^6.4 || ^7.0",
"symfony/string": "^5.4 || ^6.4 || ^7.0",
"sylius/channel": "^2.0",
"sylius/channel-bundle": "^2.0",
"sylius/core": "^2.0",
"sylius/core-bundle": "^2.0",
"sylius/locale": "^2.0",
"sylius/product": "^2.0",
"sylius/product-bundle": "^2.0",
"sylius/resource-bundle": "^1.12",
"sylius/ui-bundle": "^2.0",
"symfony/config": "^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/options-resolver": "^6.4 || ^7.1",
"symfony/routing": "^6.4 || ^7.1",
"symfony/string": "^6.4 || ^7.1",
"symfony/translation-contracts": "^1.1 || ^2.4 || ^3.4",
"symfony/validator": "^5.4 || ^6.4 || ^7.0",
"symfony/ux-live-component": "^2.20",
"symfony/validator": "^6.4 || ^7.1",
"twig/twig": "^2.14 || ^3.8",
"webmozart/assert": "^1.11"
},
"require-dev": {
"api-platform/core": "^2.7.16",
"babdev/pagerfanta-bundle": "^3.8",
"behat/behat": "^3.14",
"api-platform/core": "^2.7 || ^3.4",
"babdev/pagerfanta-bundle": "^4.4",
"behat/behat": "^3.16",
"doctrine/doctrine-bundle": "^2.11",
"friends-of-behat/mink": "^1.11",
"friends-of-behat/mink-browserkit-driver": "^1.6",
"friends-of-behat/mink-debug-extension": "^2.1",
"friends-of-behat/mink-extension": "^2.7",
"friends-of-behat/page-object-extension": "^0.3",
"friends-of-behat/suite-settings-extension": "^1.1",
"friends-of-behat/symfony-extension": "^2.6",
"friends-of-behat/variadic-extension": "^1.6",
"infection/infection": "^0.27.9",
"jms/serializer-bundle": "^4.2",
"lexik/jwt-authentication-bundle": "^2.17",
"jms/serializer-bundle": "^5.5",
"lexik/jwt-authentication-bundle": "^3.1",
"matthiasnoback/symfony-config-test": "^4.3 || ^5.1",
"matthiasnoback/symfony-dependency-injection-test": "^4.3 || ^5.0",
"phpspec/prophecy-phpunit": "^2.1",
"phpunit/phpunit": "^9.6",
"psalm/plugin-phpunit": "^0.18",
"setono/code-quality-pack": "^2.7",
"sylius/sylius": "~1.12.13",
"symfony/debug-bundle": "^5.4 || ^6.4 || ^7.0",
"symfony/dotenv": "^5.4 || ^6.4 || ^7.0",
"symfony/intl": "^5.4 || ^6.4 || ^7.0",
"symfony/property-info": "^5.4 || ^6.4 || ^7.0",
"symfony/serializer": "^5.4 || ^6.4 || ^7.0",
"symfony/web-profiler-bundle": "^5.4 || ^6.4 || ^7.0",
"symfony/webpack-encore-bundle": "^1.17",
"sylius/sylius": "^2.0",
"symfony/debug-bundle": "^6.4 || ^7.1",
"symfony/dotenv": "^6.4 || ^7.1",
"symfony/intl": "^6.4 || ^7.1",
"symfony/property-info": "^6.4 || ^7.1",
"symfony/serializer": "^6.4 || ^7.1",
"symfony/web-profiler-bundle": "^6.4 || ^7.1",
"symfony/webpack-encore-bundle": "^2.2",
"willdurand/negotiation": "^3.1"
},
"prefer-stable": true,
Expand All @@ -78,6 +89,7 @@
"dealerdirect/phpcodesniffer-composer-installer": false,
"ergebnis/composer-normalize": true,
"infection/extension-installer": true,
"php-http/discovery": true,
"symfony/thanks": false
},
"sort-packages": true
Expand Down
23 changes: 22 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
phpVersion="8.1"
phpVersion="8.2"
errorLevel="1"
findUnusedBaselineEntry="false"
findUnusedPsalmSuppress="false"
Expand All @@ -30,6 +30,11 @@
</forbiddenFunctions>
<issueHandlers>
<MissingTemplateParam errorLevel="suppress"/> <!-- At some point we will add template params, but it's difficult when supporting multiple versions of Sylius/SF/Doctrine etc -->
<InvalidArgument>
<errorLevel type="suppress">
<directory name="src/Fixture"/>
</errorLevel>
</InvalidArgument>
<MixedAssignment>
<errorLevel type="suppress">
<directory name="src/Fixture"/>
Expand All @@ -40,5 +45,21 @@
<directory name="src/Fixture"/>
</errorLevel>
</MixedArgument>
<MixedArrayAccess>
<errorLevel type="suppress">
<directory name="src/Twig/Component"/>
</errorLevel>
</MixedArrayAccess>
<MixedArrayAssignment>
<errorLevel type="suppress">
<directory name="src/Twig/Component"/>
</errorLevel>
</MixedArrayAssignment>
<PropertyNotSetInConstructor>
<errorLevel type="suppress">
<directory name="src/Model"/>
<directory name="src/Twig/Component"/>
</errorLevel>
</PropertyNotSetInConstructor>
</issueHandlers>
</psalm>
4 changes: 2 additions & 2 deletions src/DependencyInjection/SetonoSyliusTermsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function prepend(ContainerBuilder $container): void
],
]);

$container->prependExtensionConfig('sylius_ui', [
/*$container->prependExtensionConfig('sylius_ui', [
'events' => [
'setono_sylius_terms.admin.terms.create.javascripts' => [
'blocks' => [
Expand All @@ -101,6 +101,6 @@ public function prepend(ContainerBuilder $container): void
],
],
],
]);
]);*/
}
}
5 changes: 5 additions & 0 deletions src/Form/Type/TermsTranslationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
->add('name', TextType::class, [
'label' => 'setono_sylius_terms.form.terms.name',
'help' => 'setono_sylius_terms.form.terms.name_help',
'attr' => [
'data-action' => 'live#action',
'data-live-action-param' => 'on(change)|generateTermsSlug',
'data-live-locale-code-param' => $builder->getPropertyPath()?->getElement(0),
],
])
->add('slug', TextType::class, [
'label' => 'setono_sylius_terms.form.terms.slug',
Expand Down
2 changes: 2 additions & 0 deletions src/Resources/config/app/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
imports:
- { resource: "@SetonoSyliusTermsPlugin/Resources/config/twig/twig_hooks.yaml" }
10 changes: 2 additions & 8 deletions src/Resources/config/routes/admin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@ setono_sylius_terms_admin_terms:
resource: |
alias: setono_sylius_terms.terms
section: admin
templates: "@SyliusAdmin\\Crud"
templates: "@SyliusAdmin\\shared\\crud"
redirect: update
except: [show]
grid: setono_sylius_terms_terms
vars:
all:
subheader: setono_sylius_terms.ui.manage_terms
templates:
form: "@SetonoSyliusTermsPlugin/admin/terms/_form.html.twig"
index:
icon: 'check circle outline'
type: sylius.resource
14 changes: 14 additions & 0 deletions src/Resources/config/services/twig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,19 @@

<tag name="twig.runtime"/>
</service>

<service id="setono_sylius_terms.twig.component.terms.form" class="\Setono\SyliusTermsPlugin\Twig\Component\TermsComponent">
<argument type="service" id="setono_sylius_terms.repository.terms" />
<argument type="service" id="form.factory" />
<argument>%setono_sylius_terms.model.terms.class%</argument>
<argument>Setono\SyliusTermsPlugin\Form\Type\TermsType</argument>
<argument type="service" id="sylius.generator.slug" />

<call method="setLiveResponder">
<argument type="service" id="ux.live_component.live_responder"/>
</call>

<tag name="sylius.live_component.admin" key="setono_sylius_terms:terms:form" />
</service>
</services>
</container>
34 changes: 34 additions & 0 deletions src/Resources/config/twig/twig_hooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
sylius_twig_hooks:
hooks:
'sylius_admin.terms.create.content':
form:
component: 'setono_sylius_terms:terms:form'
props:
form: '@=_context.form'
resource: '@=_context.resource'
template: '@SetonoSyliusTermsPlugin/admin/terms/_form.html.twig'
priority: 0
'sylius_admin.terms.create.content.form#left':
form:
template: '@SetonoSyliusTermsPlugin/admin/terms/form/left.html.twig'
'sylius_admin.terms.create.content.form#right':
form:
template: '@SetonoSyliusTermsPlugin/admin/terms/form/right.html.twig'
'sylius_admin.terms.update.content':
form:
component: 'setono_sylius_terms:terms:form'
props:
form: '@=_context.form'
resource: '@=_context.resource'
template: '@SetonoSyliusTermsPlugin/admin/terms/_form.html.twig'
priority: 0
'sylius_admin.terms.update.content.form#left':
form:
template: '@SetonoSyliusTermsPlugin/admin/terms/form/left.html.twig'
'sylius_admin.terms.update.content.form#right':
form:
template: '@SetonoSyliusTermsPlugin/admin/terms/form/right.html.twig'
'sylius_shop.checkout.complete.content.form':
terms:
template: '@SetonoSyliusTermsPlugin/shop/checkout/terms.html.twig'
priority: 50
Loading
Loading