Skip to content
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

OP-558: Sylius 2 upgrade #71

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 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
10 changes: 5 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ["8.0", "8.1", "8.2", "8.3"]
symfony: ["^5.4", "^6.4"]
sylius: ["~1.12.0", "~1.13.0"]
node: ["^18.0", "^20.0"]
php: [ "8.2", "8.3" ]
symfony: [ "^6.4" ]
sylius: [ "~v2.0.0-alpha.2" ]
node: [ "20.x" ]
mysql: ["8.0"]
exclude:
- sylius: "~1.13.0"
dariusz-rup marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -182,7 +182,7 @@ jobs:

-
name: Upload Behat logs
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
if: failure()
with:
name: Behat logs
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/coding_standard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ "8.0", "8.1", "8.2", "8.3" ]
symfony: [ "^5.4", "^6.4" ]
sylius: [ "^1.12", "^1.13" ]
node: [ "18.x", "20.x" ]
php: [ "8.2", "8.3" ]
symfony: [ "^6.4" ]
sylius: [ "~v2.0.0-alpha.2" ]
node: [ "20.x" ]

exclude:
- sylius: ^1.13
dariusz-rup marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
29 changes: 19 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@
"description": "Blacklist plugin for Sylius.",
"license": "MIT",
"require": {
"php": "^8.0 || ^8.1 || ^8.2 || ^8.3",
"sylius/sylius": "~1.12.0 || ~1.13.0",
"doctrine/annotations": "^2.0.0"
"php": "^8.2",
"doctrine/annotations": "^2.0.0",
"sylius-labs/polyfill-symfony-security": "^1.1",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"sylius-labs/polyfill-symfony-security": "^1.1",

"sylius/calendar": "^0.5.0",
"sylius/grid-bundle": "^1.13.0-ALPHA.3",
dariusz-rup marked this conversation as resolved.
Show resolved Hide resolved
"sylius/sylius": "^2.0.0-alpha.2",
"sylius/twig-hooks": "^0.3.0",
"symfony/stimulus-bundle": "^2.20",
"symfony/ux-autocomplete": "^2.20",
"symfony/ux-live-component": "^2.20",
"symfony/ux-twig-component": "^2.20",
"willdurand/hateoas-bundle": "^2.6"
},
"require-dev": {
"behat/behat": "^3.7.0",
Expand All @@ -33,13 +42,13 @@
"phpstan/phpstan-webmozart-assert": "^1.0",
"phpunit/phpunit": "^9.5",
"polishsymfonycommunity/symfony-mocker-container": "^1.0",
"symfony/browser-kit": "^5.4 || 6.4",
"symfony/debug-bundle": "^5.4 || ^6.4",
"symfony/dotenv": "^5.4 || ^6.4",
"symfony/intl": "^5.4 || ^6.4",
"symfony/web-profiler-bundle": "^5.4 || ^6.4",
"vimeo/psalm": "^4.7 || ^5.0",
"symfony/webpack-encore-bundle": "^1.17"
"symfony/browser-kit": "^6.4",
"symfony/debug-bundle": "^6.4",
"symfony/dotenv": "^6.4",
"symfony/intl": "^6.4",
"symfony/web-profiler-bundle": "^6.4",
"symfony/webpack-encore-bundle": "^2.1",
"vimeo/psalm": "^4.7 || ^5.0"
},
"autoload": {
"psr-4": {
Expand Down
30 changes: 18 additions & 12 deletions doc/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ ADDITIONAL
## Requirements:
We work on stable, supported and up-to-date versions of packages. We recommend you to do the same.

| Package | Version |
|---------------|-----------------|
| PHP | \>8.0 |
| sylius/sylius | 1.12.x - 1.13.x |
| MySQL | \>= 5.7 |
| NodeJS | \>= 18.x |
| Package | Version |
|---------------|----------|
| PHP | \>=8.2 |
| sylius/sylius | 2.0.x |
| MySQL | \>= 5.7 |
| NodeJS | \>= 18.x |

## Composer:
```bash
Expand Down Expand Up @@ -178,20 +178,26 @@ bin/console cache:clear

**AdminBundle** (`templates/bundles/SyliusAdminBundle`):

Override Customer form template (`@SyliusAdminBundle\Customer\_form.html.twig`
or `@SyliusAdminBundle/Customer/Form/_firstColumn.html.twig`) by adding lines below:
Override Customer section form template (`@SyliusAdminBundle\customer\form\sections\_extra_information.html.twig`
by adding lines below:

```php
<div class="ui segment">
<h4 class="ui dividing header">{{ 'bitbag_sylius_blacklist_plugin.ui.fraud_status'|trans }}</h4>
{{ form_row(form.fraudStatus) }}
<div class="card-body">
{% hook 'extra_information' %}
{{ form_row(hookable_metadata.context.form.fraudStatus) }}
</div>
```

or copy from the path:

```
vendor/bitbag/blacklist-plugin/tests/Application/templates/bundles/SyliusAdminBundle/Customer/_form.html.twig
vendor/bitbag/blacklist-plugin/tests/Application/templates/bundles/SyliusAdminBundle/customer/form/sections/extra_information.html.twig
```

Copy order actions template from the path:

```
vendor/bitbag/blacklist-plugin/tests/Application/templates/bundles/SyliusAdminBundle/order/show/content/header/title_block/actions.html.twig
```

## Tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ Feature: Adding a new automatic blacklisting configuration
When I go to the create automatic blacklisting configuration page
And I name it "Fourth configuration"
And I select "United States" as channels
And I select "United States" as channels
And I enable it
And I add the "Max number of orders" rule configured with count "5" and "Per day" as date modifier
And I want to add fraud suspicion row after exceeding limit
And I add it
Then I should be notified that I need to add settings to fraud suspicion section
Then I should be notified that I need to add settings to fraud suspicion section
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Feature: Blocking users on checkout
And the customer bought a single "PHP T-Shirt"
And the customer chose "Free" shipping method to "United States" with "Cash on Delivery" payment

@ui
@ui @javascript
Scenario: Successfully complete checkout addressing step
Given I have product "PHP Pullover" in the cart
And there is a automatic blacklisting configuration "First configuration" with rule "orders" configured with count "2" and date modifier "1 day"
Expand All @@ -26,12 +26,12 @@ Feature: Blocking users on checkout
And I complete the addressing step
Then I should be on the checkout shipping step

@ui
@ui @javascript
Scenario: Blocking users on checkout by automatic blacklisting rules
Given I have product "PHP Blouse" in the cart
And there is a automatic blacklisting configuration "First configuration" with rule "orders" configured with count "1" and date modifier "1 day"
And I am at the checkout addressing step
And I specify the billing address as "Ankh Morpork", "Frost Alley", "90210", "United States" for "Jon Snow"
And I complete the addressing step
Then I should be notified that something went wrong
And I should be at the checkout addressing step
And I should be at the checkout addressing step
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Feature: Blocking users on checkout
And the customer chose "Free" shipping method to "United States" with "Cash on Delivery" payment
And the order "#00000022" is marked as suspicious by fake "billing" address

@ui
@ui @javascript
Scenario: Successfully complete checkout addressing step
Given I have product "PHP Pullover" in the cart
And there is a blacklisting rule with "Country" name and "3" permitted strikes and "country" as a rule attributes
Expand All @@ -30,7 +30,7 @@ Feature: Blocking users on checkout
And I complete the addressing step
Then I should be on the checkout shipping step

@ui
@ui @javascript
Scenario: Successfully complete checkout by users for who manual blacklisting rule is not eligible
Given the customer belongs to group "Wholesale"
And I have product "PHP Pullover" in the cart
Expand All @@ -41,7 +41,7 @@ Feature: Blocking users on checkout
And I complete the addressing step
Then I should be on the checkout shipping step

@ui
@ui @javascript
Scenario: Successfully complete checkout by users for who manual blacklisting rule is not eligible
Given I have product "PHP Pullover" in the cart
And there is a blacklisting rule with "Country" name and "1" permitted strikes and "country" as a rule attributes
Expand All @@ -51,12 +51,12 @@ Feature: Blocking users on checkout
And I complete the addressing step
Then I should be on the checkout shipping step

@ui
@ui @javascript
Scenario: Blocking users on checkout by manual blacklisting rules
Given I have product "PHP Blouse" in the cart
And there is a blacklisting rule with "Country" name and "1" permitted strikes and "country" as a rule attributes
And I am at the checkout addressing step
And I specify the billing address as "Francis Underwood", "Groove Street", "91920", "United States" for "Francis Underwood"
And I complete the addressing step
Then I should be notified that something went wrong
And I should be at the checkout addressing step
And I should be at the checkout addressing step
24 changes: 16 additions & 8 deletions src/Form/Type/AutomaticBlacklistingConfigurationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace BitBag\SyliusBlacklistPlugin\Form\Type;

use BitBag\SyliusBlacklistPlugin\Entity\FraudPrevention\AutomaticBlacklistingRuleInterface;
use Sylius\Bundle\AdminBundle\Form\Type\AddButtonType;
use Sylius\Bundle\ChannelBundle\Form\Type\ChannelChoiceType;
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
Expand All @@ -20,19 +21,16 @@
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\GreaterThanOrEqual;
use Symfony\UX\LiveComponent\Form\Type\LiveCollectionType;

final class AutomaticBlacklistingConfigurationType extends AbstractResourceType
{
/** @var array */
private $attributeChoices;

public function __construct(
private array $rules,
string $dataClass,
array $attributeChoices,
array $validationGroups = [],
) {
parent::__construct($dataClass, $validationGroups);
$this->attributeChoices = $attributeChoices;
}

public function buildForm(FormBuilderInterface $builder, array $options): void
Expand Down Expand Up @@ -72,9 +70,19 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
],
'placeholder' => 'bitbag_sylius_blacklist_plugin.ui.choose_time_range',
])
->add('rules', AutomaticBlacklistingRuleCollectionType::class, [
'label' => 'bitbag_sylius_blacklist_plugin.form.automatic_blacklisting_rule.rules',
'button_add_label' => 'sylius.form.promotion.add_rule',
->add('rules', LiveCollectionType::class, [
'entry_type' => AutomaticBlacklistingRuleType::class,
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'button_add_type' => AddButtonType::class,
'button_add_options' => [
'label' => 'sylius.ui.add_rule',
'types' => $this->rules,
],
'button_delete_options' => [
'label' => false,
],
])
;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,38 @@

namespace BitBag\SyliusBlacklistPlugin\Form\Type;

use Sylius\Bundle\ResourceBundle\Form\Type\ResourceAutocompleteChoiceType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class CustomerAutocompleteChoiceType extends AbstractType
use Symfony\UX\Autocomplete\Form\AsEntityAutocompleteField;
use Symfony\UX\Autocomplete\Form\BaseEntityAutocompleteType;

#[AsEntityAutocompleteField(
alias: 'sylius_admin_customer',
route: 'sylius_admin_entity_autocomplete',
)]
final class CustomerAutocompleteType extends AbstractType
{
public function __construct(
private string $customerClass,
) {
}

public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'resource' => 'sylius.customer',
'choice_name' => 'email',
'class' => $this->customerClass,
'choice_label' => 'email',
'choice_value' => 'id',
]);
}

public function buildView(
FormView $view,
FormInterface $form,
array $options,
): void {
$view->vars['remote_criteria_type'] = 'contains';
$view->vars['remote_criteria_name'] = 'email';
}

public function getBlockPrefix(): string
{
return 'bitbag_sylius_customer_autocomplete_choice';
return 'bitbag_sylius_admin_customer_autocomplete';
}

public function getParent(): string
{
return ResourceAutocompleteChoiceType::class;
return BaseEntityAutocompleteType::class;
}
}
5 changes: 4 additions & 1 deletion src/Form/Type/FraudSuspicionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ public function __construct(
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('customer', CustomerAutocompleteChoiceType::class, [
->add('customer', CustomerAutocompleteType::class, [
'label' => 'sylius.ui.customer',
'priority' => 1,
'constraints' => [
new NotNull(),
],
'attr' => [
'data-test-fraud-suspicion-customer-autocomplete' => '',
],
])
->add('company', TextType::class, [
'required' => false,
Expand Down
5 changes: 1 addition & 4 deletions src/Menu/FraudPreventionMenuBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,35 @@ public function buildMenu(MenuBuilderEvent $menuBuilderEvent): void
$rootMenuItem = $menu
->addChild('bitbag_fraud_prevention')
->setLabel('bitbag_sylius_blacklist_plugin.ui.fraud_prevention')
->setLabelAttribute('icon', 'spy')
;

$rootMenuItem
->addChild(self::BLACKLISTING_RULE_TYPE_MENU_KEY, [
'route' => 'bitbag_sylius_blacklist_plugin_admin_blacklisting_rule_index',
])
->setLabel('bitbag_sylius_blacklist_plugin.ui.blacklisting_rules')
->setLabelAttribute('icon', 'hand paper')
;

$rootMenuItem
->addChild(self::AUTOMATIC_BLACKLISTING_CONFIGURATION_TYPE_MENU_KEY, [
'route' => 'bitbag_sylius_blacklist_plugin_admin_automatic_blacklisting_configuration_index',
])
->setLabel('bitbag_sylius_blacklist_plugin.ui.automatic_blacklisting_configurations')
->setLabelAttribute('icon', 'microchip')
;

$rootMenuItem
->addChild(self::FRAUD_SUSPICION_TYPE_MENU_KEY, [
'route' => 'bitbag_sylius_blacklist_plugin_admin_fraud_suspicion_index',
])
->setLabel('bitbag_sylius_blacklist_plugin.ui.fraud_suspicions')
->setLabelAttribute('icon', 'exclamation triangle')
;

$rootMenuItem
->addChild(self::AUTOMATIC_BLACKLISTING_CONFIGURATION_TYPE_MENU_KEY, [
'route' => 'bitbag_sylius_blacklist_plugin_admin_automatic_blacklisting_configuration_index',
])
->setLabel('bitbag_sylius_blacklist_plugin.ui.automatic_blacklisting_configurations')
->setLabelAttribute('icon', 'cog')
;
}
}
1 change: 1 addition & 0 deletions src/Resources/config/config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
imports:
- { resource: "twig_hooks/**/*.yaml" }
- { resource: "resources.yaml" }
- { resource: "services.xml" }
- { resource: "grids.yaml" }
Expand Down
Loading
Loading