Skip to content

Commit

Permalink
OP-558: Sylius 2 upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
jkindly committed Oct 9, 2024
1 parent 9a5c8ac commit bbb2228
Show file tree
Hide file tree
Showing 17 changed files with 95 additions and 98 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"description": "Blacklist plugin for Sylius.",
"license": "MIT",
"require": {
"php": "^8.0 || ^8.1 || ^8.2 || ^8.3",
"php": "^8.2",
"doctrine/annotations": "^2.0.0",
"sylius-labs/polyfill-symfony-security": "^1.1",
"sylius/calendar": "^0.5.0",
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 @@ -12,7 +12,6 @@ Feature: Adding a new automatic blacklisting configuration
Scenario: Successfully adding a new automatic blacklisting configuration with max number of orders
When I go to the create automatic blacklisting configuration page
And I name it "First configuration"
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 do not want to add fraud suspicion row after exceeding limit
Expand All @@ -24,7 +23,6 @@ Feature: Adding a new automatic blacklisting configuration
Scenario: Successfully adding a new automatic blacklisting configuration
When I go to the create automatic blacklisting configuration page
And I name it "Second configuration"
And I select "United States" as channels
And I enable it
And I add the "Max number of payment failures" rule configured with count "3" and "Per day" as date modifier
And I want to add fraud suspicion row after exceeding limit
Expand All @@ -38,7 +36,6 @@ Feature: Adding a new automatic blacklisting configuration
Scenario: Successfully adding a new automatic blacklisting configuration with max number of payment failures
When I go to the create automatic blacklisting configuration page
And I name it "Third configuration"
And I select "United States" as channels
And I enable it
And I add the "Max number of payment failures" rule configured with count "3" and "Per day" as date modifier
And I do not want to add fraud suspicion row after exceeding limit
Expand All @@ -55,4 +52,4 @@ Feature: Adding a new automatic blacklisting configuration
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
3 changes: 3 additions & 0 deletions src/Form/Type/FraudSuspicionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'constraints' => [
new NotNull(),
],
'attr' => [
'data-test-fraud-suspicion-customer-autocomplete' => '',
],
])
->add('company', TextType::class, [
'required' => false,
Expand Down
3 changes: 1 addition & 2 deletions src/Resources/config/routing/admin/fraud_suspicion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ bitbag_sylius_blacklist_plugin_admin_order_mark_suspicious:
parameters:
orderId: $orderId
section: admin
template: "@SyliusAdmin/Crud/create.html.twig"
form: BitBag\SyliusBlacklistPlugin\Form\Type\FraudSuspicionOrderType
template: "@SyliusAdmin/shared/crud/create.html.twig"
factory:
method: createForOrder
arguments:
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/services/form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
</service>

<service id="sylius.form.type.checkout_address" class="Sylius\Bundle\CoreBundle\Form\Type\Checkout\AddressType">
<argument type="service" id="sylius.address_comparator" />
<argument>%sylius.model.order.class%</argument>
<argument>%bitbag.sylius_blacklist_plugin.form.type.checkout_address.validation_groups%</argument>
<argument type="service" id="sylius.address_comparator" />
<tag name="form.type" />
</service>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<div class="card-body">
{% if fraudSuspicion.order != null %}
{% if fraudSuspicion.order.number != null %}
<i class="circular cart icon"></i>
<a href="{{ path('sylius_admin_order_show', {'id': fraudSuspicion.order.id}) }}">
{{ 'bitbag_sylius_blacklist_plugin.ui.see_more_info_about_order'|trans ~ ' #' ~ fraudSuspicion.order.number }}
</a>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div class="col-12 col-md-6">
<div class="card">
<div class="card-header">
<div class="card-title">
{{ 'sylius.ui.extra_information'|trans }}
</div>
</div>
<div class="card-body">
{% hook 'extra_information' %}
{{ form_row(hookable_metadata.context.form.fraudStatus) }}
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% from '@SyliusAdmin/shared/helper/icon.html.twig' import icon %}
{% set resource = hookable_metadata.context.resource %}

<div class="col-12 col-md-auto ms-auto d-flex">
{% if resource.customer.fraudStatus != 'blacklisted' %}
<a class="btn btn-danger me-2"
href="{{ path('bitbag_sylius_blacklist_plugin_admin_order_mark_suspicious', {'orderId': resource.id}) }}">
{{ icon({ icon: 'warning', class: 'icon icon-tabler' }) }}
{{ 'bitbag_sylius_blacklist_plugin.ui.mark_suspicious'|trans }}
</a>
{% endif %}
<div class="dropdown drop">
<button type="button" class="btn dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
{{ 'sylius.ui.actions'|trans }}
</button>
<div class="dropdown-menu dropdown-menu-end">
{% hook 'actions' with { resource } %}
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@ public function selectOption(string $field, string $value): void

public function addRule(string $ruleName): void
{
$count = count($this->getCollectionItems('rules'));
$this->getElement($ruleName)->press();

$this->getDocument()->clickLink('Add rule');
$form = $this->getElement('form');

$this->getSession()->wait(100);

$this->selectRuleOption('Type', $ruleName);
usleep(500000); // we need to sleep, as sometimes the check below is executed faster than the form sets the busy attribute
$form->waitFor(1500, fn () => !$form->hasAttribute('busy'));
}

public function selectRuleOption(string $option, string $value, bool $multiple = false): void
Expand Down Expand Up @@ -93,6 +92,9 @@ protected function getDefinedElements(): array
{
return [
'rules' => '#bitbag_sylius_blacklist_plugin_automatic_blacklisting_configuration_rules',
'Max number of orders' => '[data-test-add-orders]',
'Max number of payment failures' => '[data-test-add-payment_failures]',
'form' => 'form',
];
}

Expand All @@ -110,8 +112,7 @@ private function getLastCollectionItem(string $collection): NodeElement
*/
private function getCollectionItems(string $collection): array
{
$items = $this->getElement($collection)->findAll('css', 'div[data-form-collection="item"]');

$items = $this->getElement($collection)->findAll('css', '[data-test-entry-row]');
Assert::isArray($items);

return $items;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function uncheckField(string $locator): void

public function update(): void
{
$this->getDocument()->pressButton('Save changes');
$this->getDocument()->pressButton('Update');
}

public function fillRuleOption(string $option, string $value): void
Expand Down Expand Up @@ -64,7 +64,7 @@ private function getLastCollectionItem(string $collection): NodeElement
*/
private function getCollectionItems(string $collection): array
{
$items = $this->getElement($collection)->findAll('css', 'div[data-form-collection="item"]');
$items = $this->getElement($collection)->findAll('css', '[data-test-entry-row]');

Assert::isArray($items);

Expand Down
2 changes: 1 addition & 1 deletion tests/Behat/Page/Admin/Customer/UpdatePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public function selectOption(string $field, string $value): void

public function submit(): void
{
$this->getDocument()->pressButton('Save changes');
$this->getDocument()->pressButton('Update');
}
}
Loading

0 comments on commit bbb2228

Please sign in to comment.