From eec681ec9bac57c4c457c0ebaba323495adc48be Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Fri, 5 Apr 2024 14:14:02 +0200 Subject: [PATCH 01/39] [Admin] Add Promotion edit page with hooks --- .../app/twig_hooks/promotion/update.yaml | 55 +++++++++++++++++++ .../Form/Sections/_translations.html.twig | 2 +- .../Configuration/Left/_endsAt.html.twig | 3 + .../Configuration/Left/_priority.html.twig | 3 + .../Configuration/Left/_startsAt.html.twig | 3 + .../Configuration/Left/_usageLimit.html.twig | 3 + .../Right/_appliesToDiscounted.html.twig | 4 ++ .../Right/_couponBased.html.twig | 3 + .../Configuration/Right/_exclusive.html.twig | 3 + .../Configuration/Right/_header.html.twig | 1 + .../Sections/Configuration/_left.html.twig | 9 +++ .../Sections/Configuration/_right.html.twig | 9 +++ .../Form/Sections/General/_channels.html.twig | 3 + .../Form/Sections/General/_code.html.twig | 3 + .../Sections/General/_description.html.twig | 1 + .../Form/Sections/General/_name.html.twig | 3 + .../Form/Sections/_configuration.html.twig | 20 +++++++ .../Form/Sections/_general.html.twig | 20 +++++++ .../Form/Sections/_translations.html.twig | 7 +++ .../views/Promotion/Form/_sections.html.twig | 9 +++ .../Shared/Helper/translations.html.twig | 8 +-- .../Resources/translations/messages.en.yml | 1 + 22 files changed, 166 insertions(+), 7 deletions(-) create mode 100644 src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/update.yaml create mode 100644 src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Left/_endsAt.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Left/_priority.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Left/_startsAt.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Left/_usageLimit.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Right/_appliesToDiscounted.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Right/_couponBased.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Right/_exclusive.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Right/_header.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/_left.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/_right.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/_channels.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/_code.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/_description.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/_name.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_configuration.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_general.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_translations.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/_sections.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/update.yaml b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/update.yaml new file mode 100644 index 00000000000..032494aaccc --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/update.yaml @@ -0,0 +1,55 @@ +twig_hooks: + hooks: + 'sylius_admin.promotion.update.content': + form: + template: '@SyliusAdmin/Shared/Crud/Update/Content/_form.html.twig' + configuration: + render_rest: false + + 'sylius_admin.promotion.update.content.form': + sections: + template: '@SyliusAdmin/Promotion/Form/_sections.html.twig' + + 'sylius_admin.promotion.update.content.form.sections': + general: + template: '@SyliusAdmin/Promotion/Form/Sections/_general.html.twig' + configuration: + template: '@SyliusAdmin/Promotion/Form/Sections/_configuration.html.twig' + translations: + template: '@SyliusAdmin/Promotion/Form/Sections/_translations.html.twig' + + 'sylius_admin.promotion.update.content.form.sections.general': + _name: + template: '@SyliusAdmin/Promotion/Form/Sections/General/_name.html.twig' + code: + template: '@SyliusAdmin/Promotion/Form/Sections/General/_code.html.twig' + description: + template: '@SyliusAdmin/Promotion/Form/Sections/General/_description.html.twig' + channels: + template: '@SyliusAdmin/Promotion/Form/Sections/General/_channels.html.twig' + + 'sylius_admin.promotion.update.content.form.sections.configuration': + left: + template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/_left.html.twig' + right: + template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/_right.html.twig' + + 'sylius_admin.promotion.update.content.form.sections.configuration.left': + usage_limit: + template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/Left/_usageLimit.html.twig' + priority: + template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/Left/_priority.html.twig' + starts_at: + template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/Left/_startsAt.html.twig' + ends_at: + template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/Left/_endsAt.html.twig' + + 'sylius_admin.promotion.update.content.form.sections.configuration.right': + header: + template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/Right/_header.html.twig' + coupon_based: + template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/Right/_couponBased.html.twig' + exclusive: + template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/Right/_exclusive.html.twig' + applies_to_discounted: + template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/Right/_appliesToDiscounted.html.twig' diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Product/Form/Sections/_translations.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Product/Form/Sections/_translations.html.twig index 4f00bd30279..2a6899b0721 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/views/Product/Form/Sections/_translations.html.twig +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Product/Form/Sections/_translations.html.twig @@ -39,6 +39,6 @@ {% endverbatim %} {% endset %} - {{ _translations.default(hookable_data.form.translations, body) }} + {{ _translations.default(hookable_data.form.translations, body, {accordionId: 'product-translations'}) }} diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Left/_endsAt.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Left/_endsAt.html.twig new file mode 100644 index 00000000000..814105436ce --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Left/_endsAt.html.twig @@ -0,0 +1,3 @@ +
+ {{ form_row(hookable_data.form.endsAt) }} +
diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Left/_priority.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Left/_priority.html.twig new file mode 100644 index 00000000000..2dad0259c58 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Left/_priority.html.twig @@ -0,0 +1,3 @@ +
+ {{ form_row(hookable_data.form.priority) }} +
diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Left/_startsAt.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Left/_startsAt.html.twig new file mode 100644 index 00000000000..90baf7f80c8 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Left/_startsAt.html.twig @@ -0,0 +1,3 @@ +
+ {{ form_row(hookable_data.form.startsAt) }} +
diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Left/_usageLimit.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Left/_usageLimit.html.twig new file mode 100644 index 00000000000..124131c204f --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Left/_usageLimit.html.twig @@ -0,0 +1,3 @@ +
+ {{ form_row(hookable_data.form.usageLimit) }} +
diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Right/_appliesToDiscounted.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Right/_appliesToDiscounted.html.twig new file mode 100644 index 00000000000..a1e13bb40d1 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Right/_appliesToDiscounted.html.twig @@ -0,0 +1,4 @@ +
+ {{ form_row(hookable_data.form.appliesToDiscounted) }} + {{ 'sylius.form.promotion.applies_to_discounted_details'|trans }} +
diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Right/_couponBased.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Right/_couponBased.html.twig new file mode 100644 index 00000000000..8abbd3cef63 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Right/_couponBased.html.twig @@ -0,0 +1,3 @@ +
+ {{ form_row(hookable_data.form.couponBased) }} +
diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Right/_exclusive.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Right/_exclusive.html.twig new file mode 100644 index 00000000000..5f510eef4ad --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Right/_exclusive.html.twig @@ -0,0 +1,3 @@ +
+ {{ form_row(hookable_data.form.exclusive) }} +
diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Right/_header.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Right/_header.html.twig new file mode 100644 index 00000000000..923f5d4a1c1 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Right/_header.html.twig @@ -0,0 +1 @@ +
{{ 'sylius.ui.options'|trans }}
diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/_left.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/_left.html.twig new file mode 100644 index 00000000000..0e9191f954c --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/_left.html.twig @@ -0,0 +1,9 @@ +{% set main_hook = hook_name(hookable_data.parent_main_hook, 'left') %} +{% set fallback_hook = hook_name(hookable_data.parent_fallback_hook, 'left') %} + +
+ {% hook [main_hook, fallback_hook] with hookable_data|merge({ + parent_main_hook: main_hook, + parent_fallback_hook: fallback_hook, + }) %} +
diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/_right.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/_right.html.twig new file mode 100644 index 00000000000..9895de7b07b --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/_right.html.twig @@ -0,0 +1,9 @@ +{% set main_hook = hook_name(hookable_data.parent_main_hook, 'right') %} +{% set fallback_hook = hook_name(hookable_data.parent_fallback_hook, 'right') %} + +
+ {% hook [main_hook, fallback_hook] with hookable_data|merge({ + parent_main_hook: main_hook, + parent_fallback_hook: fallback_hook, + }) %} +
diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/_channels.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/_channels.html.twig new file mode 100644 index 00000000000..ffc1c22ff96 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/_channels.html.twig @@ -0,0 +1,3 @@ +
+ {{ form_row(hookable_data.form.channels) }} +
diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/_code.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/_code.html.twig new file mode 100644 index 00000000000..0e2050b5ace --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/_code.html.twig @@ -0,0 +1,3 @@ +
+ {{ form_row(hookable_data.form.code) }} +
diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/_description.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/_description.html.twig new file mode 100644 index 00000000000..dc40c7de1f1 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/_description.html.twig @@ -0,0 +1 @@ +{{ form_row(hookable_data.form.description, sylius_test_form_attribute('description')) }} diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/_name.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/_name.html.twig new file mode 100644 index 00000000000..9f648f706b5 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/_name.html.twig @@ -0,0 +1,3 @@ +
+ {{ form_row(hookable_data.form.name) }} +
diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_configuration.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_configuration.html.twig new file mode 100644 index 00000000000..016f8e84b03 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_configuration.html.twig @@ -0,0 +1,20 @@ +{% set main_hook = hook_name(hookable_data.parent_main_hook, 'configuration') %} +{% set fallback_hook = hook_name(hookable_data.parent_fallback_hook, 'configuration') %} + +
+
+
+
+ {{ 'sylius.ui.configuration'|trans }} +
+
+
+
+ {% hook [main_hook, fallback_hook] with hookable_data|merge({ + parent_main_hook: main_hook, + parent_fallback_hook: fallback_hook, + }) %} +
+
+
+
diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_general.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_general.html.twig new file mode 100644 index 00000000000..58446839802 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_general.html.twig @@ -0,0 +1,20 @@ +{% set main_hook = hook_name(hookable_data.parent_main_hook, 'general') %} +{% set fallback_hook = hook_name(hookable_data.parent_fallback_hook, 'general') %} + +
+
+
+
+ {{ 'sylius.ui.general'|trans }} +
+
+
+
+ {% hook [main_hook, fallback_hook] with hookable_data|merge({ + parent_main_hook: main_hook, + parent_fallback_hook: fallback_hook, + }) %} +
+
+
+
diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_translations.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_translations.html.twig new file mode 100644 index 00000000000..6ae92518456 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_translations.html.twig @@ -0,0 +1,7 @@ +{% import '@SyliusAdmin/Shared/Helper/translations.html.twig' as _translations %} + +
+
+ {{ _translations.default(hookable_data.form.translations, null, {accordionId: 'promotion-translations'}) }} +
+
diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/_sections.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/_sections.html.twig new file mode 100644 index 00000000000..ac0bb12eb19 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/_sections.html.twig @@ -0,0 +1,9 @@ +{% set main_hook = hook_name(hookable_data.parent_main_hook, 'sections') %} +{% set fallback_hook = hook_name(hookable_data.parent_fallback_hook, 'sections') %} + +
+ {% hook [main_hook, fallback_hook] with hookable_data|merge({ + parent_main_hook: main_hook, + parent_fallback_hook: fallback_hook, + }) %} +
diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/Helper/translations.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/Helper/translations.html.twig index 76c894b5483..31897a1c82c 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/Helper/translations.html.twig +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/Helper/translations.html.twig @@ -1,8 +1,4 @@ {% macro default(translationFields, body = null, options = {}) %} - {% set options = { - accordionId: 'product-translations' - }|merge(options) %} -
{% for locale, translationForm in translationFields %}
@@ -14,13 +10,13 @@ data-bs-target="#translation-{{ locale }}" aria-expanded="{% if loop.first %}true{% else %}false{% endif %}" aria-controls="translation-{{ locale }}" - {{ sylius_test_html_attribute('product-translation-accordion', locale) }} + {{ sylius_test_html_attribute(options.accordionId ~ '-accordion', locale) }} > {{ locale|sylius_locale_name }} -
+
{% if body is not null %} {{ include(template_from_string(body), { locale: locale, translationForm: translationForm }) }} diff --git a/src/Sylius/Bundle/UiBundle/Resources/translations/messages.en.yml b/src/Sylius/Bundle/UiBundle/Resources/translations/messages.en.yml index 9b73e159431..5d2d9f3a0bb 100644 --- a/src/Sylius/Bundle/UiBundle/Resources/translations/messages.en.yml +++ b/src/Sylius/Bundle/UiBundle/Resources/translations/messages.en.yml @@ -684,6 +684,7 @@ sylius: products_categorized_under_taxon_taxon: 'Products Categorized under "%taxon%" taxon' products_index_of_all_products_in_your_store: 'Products Index of all products in your store' profile: 'Profile' + promotion: 'Cart promotion' promotion_configuration: 'Promotion configuration' promotion_coupons: 'Coupons' promotion_details: 'Promotion details' From e1f0ae2a867f97621dc0a9cfcb913df6d8b8c56a Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Fri, 5 Apr 2024 14:16:07 +0200 Subject: [PATCH 02/39] [Admin] Add Promotion create page with hooks --- .../app/twig_hooks/promotion/create.yaml | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/create.yaml diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/create.yaml b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/create.yaml new file mode 100644 index 00000000000..3077b8bdb57 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/create.yaml @@ -0,0 +1,55 @@ +twig_hooks: + hooks: + 'sylius_admin.promotion.create.content': + form: + template: '@SyliusAdmin/Shared/Crud/Create/Content/_form.html.twig' + configuration: + render_rest: false + + 'sylius_admin.promotion.create.content.form': + sections: + template: '@SyliusAdmin/Promotion/Form/_sections.html.twig' + + 'sylius_admin.promotion.create.content.form.sections': + general: + template: '@SyliusAdmin/Promotion/Form/Sections/_general.html.twig' + configuration: + template: '@SyliusAdmin/Promotion/Form/Sections/_configuration.html.twig' + translations: + template: '@SyliusAdmin/Promotion/Form/Sections/_translations.html.twig' + + 'sylius_admin.promotion.create.content.form.sections.general': + _name: + template: '@SyliusAdmin/Promotion/Form/Sections/General/_name.html.twig' + code: + template: '@SyliusAdmin/Promotion/Form/Sections/General/_code.html.twig' + description: + template: '@SyliusAdmin/Promotion/Form/Sections/General/_description.html.twig' + channels: + template: '@SyliusAdmin/Promotion/Form/Sections/General/_channels.html.twig' + + 'sylius_admin.promotion.create.content.form.sections.configuration': + left: + template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/_left.html.twig' + right: + template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/_right.html.twig' + + 'sylius_admin.promotion.create.content.form.sections.configuration.left': + usage_limit: + template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/Left/_usageLimit.html.twig' + priority: + template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/Left/_priority.html.twig' + starts_at: + template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/Left/_startsAt.html.twig' + ends_at: + template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/Left/_endsAt.html.twig' + + 'sylius_admin.promotion.create.content.form.sections.configuration.right': + header: + template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/Right/_header.html.twig' + coupon_based: + template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/Right/_couponBased.html.twig' + exclusive: + template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/Right/_exclusive.html.twig' + applies_to_discounted: + template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/Right/_appliesToDiscounted.html.twig' From 585f4f7b6c28ff8fb59deb440b2e0814a6c699e4 Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Mon, 8 Apr 2024 15:17:53 +0200 Subject: [PATCH 03/39] [Admin] Add initial rules to Promotion edit page --- .../Form/Extension/PromotionTypeExtension.php | 45 +++++++++++ .../app/twig_hooks/promotion/update.yaml | 13 +++- .../Resources/config/services/form.xml | 4 + .../config/services/twig/component.xml | 6 ++ .../Promotion/Form/Sections/_rules.html.twig | 22 ++++++ .../Resources/views/Promotion/_form.html.twig | 23 ++++++ .../TwigComponent/Promotion/FormComponent.php | 74 +++++++++++++++++++ .../Resources/config/integrations/swagger.xml | 2 +- ...stractConfigurablePromotionElementType.php | 3 +- 9 files changed, 187 insertions(+), 5 deletions(-) create mode 100644 src/Sylius/Bundle/AdminBundle/Form/Extension/PromotionTypeExtension.php create mode 100644 src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_rules.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/_form.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/TwigComponent/Promotion/FormComponent.php diff --git a/src/Sylius/Bundle/AdminBundle/Form/Extension/PromotionTypeExtension.php b/src/Sylius/Bundle/AdminBundle/Form/Extension/PromotionTypeExtension.php new file mode 100644 index 00000000000..211a282687c --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Form/Extension/PromotionTypeExtension.php @@ -0,0 +1,45 @@ + $options */ + public function buildForm(FormBuilderInterface $builder, array $options): void + { + $builder + ->add('rules', LiveCollectionType::class, [ + 'entry_type' => PromotionRuleType::class, + 'allow_add' => true, + 'allow_delete' => true, + 'by_reference' => false, + 'button_add_options' => [ + 'label' => 'sylius.ui.add_rule', + ], + ]) + ; + } + + /** @return iterable */ + public static function getExtendedTypes(): iterable + { + return [PromotionType::class]; + } +} diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/update.yaml b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/update.yaml index 032494aaccc..c1768629a68 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/update.yaml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/update.yaml @@ -2,10 +2,15 @@ twig_hooks: hooks: 'sylius_admin.promotion.update.content': form: - template: '@SyliusAdmin/Shared/Crud/Update/Content/_form.html.twig' + component: 'SyliusAdmin.Promotion.Form' + data: + resource: '@=resource' + form: '@=form' + parentMainHook: '@=parent_main_hook' + parentFallbackHook: '@=parent_fallback_hook' configuration: - render_rest: false - + method: 'PUT' + 'sylius_admin.promotion.update.content.form': sections: template: '@SyliusAdmin/Promotion/Form/_sections.html.twig' @@ -17,6 +22,8 @@ twig_hooks: template: '@SyliusAdmin/Promotion/Form/Sections/_configuration.html.twig' translations: template: '@SyliusAdmin/Promotion/Form/Sections/_translations.html.twig' + rules: + template: '@SyliusAdmin/Promotion/Form/Sections/_rules.html.twig' 'sylius_admin.promotion.update.content.form.sections.general': _name: diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/services/form.xml b/src/Sylius/Bundle/AdminBundle/Resources/config/services/form.xml index f49c9601086..c856ba22a19 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/services/form.xml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/services/form.xml @@ -67,6 +67,10 @@ + + + + %sylius.form.type.admin.password_reset_request.validation_groups% diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/services/twig/component.xml b/src/Sylius/Bundle/AdminBundle/Resources/config/services/twig/component.xml index c4144f00de2..fb97c738ba6 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/services/twig/component.xml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/services/twig/component.xml @@ -73,6 +73,12 @@ + + + Sylius\Bundle\PromotionBundle\Form\Type\PromotionType + %sylius.promotion_rules% + + Sylius\Bundle\OrderBundle\Form\Type\OrderType diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_rules.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_rules.html.twig new file mode 100644 index 00000000000..228f9085dc5 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_rules.html.twig @@ -0,0 +1,22 @@ +{% set main_hook = hook_name(hookable_data.parent_main_hook, 'rules') %} +{% set fallback_hook = hook_name(hookable_data.parent_fallback_hook, 'rules') %} + +
+
+
+
+ {{ 'sylius.ui.rules'|trans }} +
+
+
+
+ {{ form_row(hookable_data.form.rules) }} + + {% hook [main_hook, fallback_hook] with hookable_data|merge({ + parent_main_hook: main_hook, + parent_fallback_hook: fallback_hook, + }) %} +
+
+
+
diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/_form.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/_form.html.twig new file mode 100644 index 00000000000..0a278780b2d --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/_form.html.twig @@ -0,0 +1,23 @@ +{# Rendered with using \Sylius\Bundle\AdminBundle\TwigComponent\Promotion\PromotionType #} + +{% form_theme form '@SyliusAdmin/Shared/form_theme.html.twig' %} + +{% set main_hook = hook_name(parent_main_hook, 'form') %} +{% set fallback_hook = hook_name(parent_fallback_hook, 'form') %} + +
+ {{ form_start(form, {'attr': {'class': 'ui loadable form', 'novalidate': 'novalidate', 'id': form.vars.id}}) }} + {% if hookable_configuration.method is defined %} + + {% endif %} + {{ form_errors(form) }} + {{ form_widget(form._token) }} + + {% hook [main_hook, fallback_hook] with { + parent_main_hook: main_hook, + parent_fallback_hook: fallback_hook, + form, + } %} + + {{ form_end(form, {render_rest: hookable.configuration.render_rest|default(false)}) }} +
diff --git a/src/Sylius/Bundle/AdminBundle/TwigComponent/Promotion/FormComponent.php b/src/Sylius/Bundle/AdminBundle/TwigComponent/Promotion/FormComponent.php new file mode 100644 index 00000000000..89f5b29f296 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/TwigComponent/Promotion/FormComponent.php @@ -0,0 +1,74 @@ +resource?->getId(); + } + + #[LiveAction] + public function addCollectionItem(PropertyAccessorInterface $propertyAccessor, #[LiveArg] string $name): void + { + $propertyPath = $this->fieldNameToPropertyPath($name, $this->formName); + $data = $propertyAccessor->getValue($this->formValues, $propertyPath); + + if (!\is_array($data)) { + $propertyAccessor->setValue($this->formValues, $propertyPath, []); + $data = []; + } + + $index = [] !== $data ? max(array_keys($data)) + 1 : 0; + $propertyAccessor->setValue( + $this->formValues, + $propertyPath."[$index]", + ['type' => array_key_first($this->rules)], + ); + } + + protected function instantiateForm(): FormInterface + { + return $this->formFactory->create($this->formClass, $this->resource); + } +} diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/integrations/swagger.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/integrations/swagger.xml index ebc20f05649..97b9a73df98 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/integrations/swagger.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/integrations/swagger.xml @@ -85,7 +85,7 @@
- + %sylius.security.new_api_route% %sylius.promotion_actions% %sylius.promotion_rules% diff --git a/src/Sylius/Bundle/PromotionBundle/Form/Type/AbstractConfigurablePromotionElementType.php b/src/Sylius/Bundle/PromotionBundle/Form/Type/AbstractConfigurablePromotionElementType.php index 61edeb4dd59..adb68e8d461 100644 --- a/src/Sylius/Bundle/PromotionBundle/Form/Type/AbstractConfigurablePromotionElementType.php +++ b/src/Sylius/Bundle/PromotionBundle/Form/Type/AbstractConfigurablePromotionElementType.php @@ -53,7 +53,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event): void { $data = $event->getData(); - if (!isset($data['type'])) { + if (!isset($data['type']) || $data['type'] === '') { + return; } From 75a10a547375520e8ad194361c6762940d3faffa Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Tue, 9 Apr 2024 10:35:31 +0200 Subject: [PATCH 04/39] [Admin] Add initial actions to Promotion edit page --- .../Form/Extension/PromotionTypeExtension.php | 10 ++++++++ .../app/twig_hooks/promotion/update.yaml | 10 ++++++-- .../config/services/twig/component.xml | 1 + .../RulesAndActions/_actions.html.twig | 22 +++++++++++++++++ .../{ => RulesAndActions}/_rules.html.twig | 0 .../Form/Sections/_configuration.html.twig | 24 +++++++++---------- .../Form/Sections/_general.html.twig | 24 +++++++++---------- .../Form/Sections/_rulesAndActions.html.twig | 9 +++++++ .../Form/Sections/_translations.html.twig | 6 ++--- .../views/Promotion/Form/_sections.html.twig | 10 ++++---- .../TwigComponent/Promotion/FormComponent.php | 17 ++++++++++++- 11 files changed, 94 insertions(+), 39 deletions(-) create mode 100644 src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/RulesAndActions/_actions.html.twig rename src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/{ => RulesAndActions}/_rules.html.twig (100%) create mode 100644 src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_rulesAndActions.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Form/Extension/PromotionTypeExtension.php b/src/Sylius/Bundle/AdminBundle/Form/Extension/PromotionTypeExtension.php index 211a282687c..e03af88e38b 100644 --- a/src/Sylius/Bundle/AdminBundle/Form/Extension/PromotionTypeExtension.php +++ b/src/Sylius/Bundle/AdminBundle/Form/Extension/PromotionTypeExtension.php @@ -13,6 +13,7 @@ namespace Sylius\Bundle\AdminBundle\Form\Extension; +use Sylius\Bundle\PromotionBundle\Form\Type\PromotionActionType; use Sylius\Bundle\PromotionBundle\Form\Type\PromotionRuleType; use Sylius\Bundle\PromotionBundle\Form\Type\PromotionType; use Symfony\Component\Form\AbstractTypeExtension; @@ -34,6 +35,15 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'label' => 'sylius.ui.add_rule', ], ]) + ->add('actions', LiveCollectionType::class, [ + 'entry_type' => PromotionActionType::class, + 'allow_add' => true, + 'allow_delete' => true, + 'by_reference' => false, + 'button_add_options' => [ + 'label' => 'sylius.ui.add_action', + ], + ]) ; } diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/update.yaml b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/update.yaml index c1768629a68..b6b71f725bd 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/update.yaml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/update.yaml @@ -22,8 +22,8 @@ twig_hooks: template: '@SyliusAdmin/Promotion/Form/Sections/_configuration.html.twig' translations: template: '@SyliusAdmin/Promotion/Form/Sections/_translations.html.twig' - rules: - template: '@SyliusAdmin/Promotion/Form/Sections/_rules.html.twig' + rules_and_actions: + template: '@SyliusAdmin/Promotion/Form/Sections/_rulesAndActions.html.twig' 'sylius_admin.promotion.update.content.form.sections.general': _name: @@ -60,3 +60,9 @@ twig_hooks: template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/Right/_exclusive.html.twig' applies_to_discounted: template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/Right/_appliesToDiscounted.html.twig' + + 'sylius_admin.promotion.update.content.form.sections.rules_and_actions': + rules: + template: '@SyliusAdmin/Promotion/Form/Sections/RulesAndActions/_rules.html.twig' + actions: + template: '@SyliusAdmin/Promotion/Form/Sections/RulesAndActions/_actions.html.twig' diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/services/twig/component.xml b/src/Sylius/Bundle/AdminBundle/Resources/config/services/twig/component.xml index fb97c738ba6..49c270a0df8 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/services/twig/component.xml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/services/twig/component.xml @@ -77,6 +77,7 @@ Sylius\Bundle\PromotionBundle\Form\Type\PromotionType %sylius.promotion_rules% + %sylius.promotion_actions% diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/RulesAndActions/_actions.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/RulesAndActions/_actions.html.twig new file mode 100644 index 00000000000..f02632980d8 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/RulesAndActions/_actions.html.twig @@ -0,0 +1,22 @@ +{% set main_hook = hook_name(hookable_data.parent_main_hook, 'actions') %} +{% set fallback_hook = hook_name(hookable_data.parent_fallback_hook, 'actions') %} + +
+
+
+
+ {{ 'sylius.ui.actions'|trans }} +
+
+
+
+ {{ form_row(hookable_data.form.actions) }} + + {% hook [main_hook, fallback_hook] with hookable_data|merge({ + parent_main_hook: main_hook, + parent_fallback_hook: fallback_hook, + }) %} +
+
+
+
diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_rules.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/RulesAndActions/_rules.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_rules.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/RulesAndActions/_rules.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_configuration.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_configuration.html.twig index 016f8e84b03..4e63809ec85 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_configuration.html.twig +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_configuration.html.twig @@ -1,20 +1,18 @@ {% set main_hook = hook_name(hookable_data.parent_main_hook, 'configuration') %} {% set fallback_hook = hook_name(hookable_data.parent_fallback_hook, 'configuration') %} -
-
-
-
- {{ 'sylius.ui.configuration'|trans }} -
+
+
+
+ {{ 'sylius.ui.configuration'|trans }}
-
-
- {% hook [main_hook, fallback_hook] with hookable_data|merge({ - parent_main_hook: main_hook, - parent_fallback_hook: fallback_hook, - }) %} -
+
+
+
+ {% hook [main_hook, fallback_hook] with hookable_data|merge({ + parent_main_hook: main_hook, + parent_fallback_hook: fallback_hook, + }) %}
diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_general.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_general.html.twig index 58446839802..cc2c9c63db2 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_general.html.twig +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_general.html.twig @@ -1,20 +1,18 @@ {% set main_hook = hook_name(hookable_data.parent_main_hook, 'general') %} {% set fallback_hook = hook_name(hookable_data.parent_fallback_hook, 'general') %} -
-
-
-
- {{ 'sylius.ui.general'|trans }} -
+
+
+
+ {{ 'sylius.ui.general'|trans }}
-
-
- {% hook [main_hook, fallback_hook] with hookable_data|merge({ - parent_main_hook: main_hook, - parent_fallback_hook: fallback_hook, - }) %} -
+
+
+
+ {% hook [main_hook, fallback_hook] with hookable_data|merge({ + parent_main_hook: main_hook, + parent_fallback_hook: fallback_hook, + }) %}
diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_rulesAndActions.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_rulesAndActions.html.twig new file mode 100644 index 00000000000..f6daf4aee46 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_rulesAndActions.html.twig @@ -0,0 +1,9 @@ +{% set main_hook = hook_name(hookable_data.parent_main_hook, 'rules_and_actions') %} +{% set fallback_hook = hook_name(hookable_data.parent_fallback_hook, 'rules_and_actions') %} + +
+ {% hook [main_hook, fallback_hook] with hookable_data|merge({ + parent_main_hook: main_hook, + parent_fallback_hook: fallback_hook, + }) %} +
diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_translations.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_translations.html.twig index 6ae92518456..befa61d45ad 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_translations.html.twig +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_translations.html.twig @@ -1,7 +1,5 @@ {% import '@SyliusAdmin/Shared/Helper/translations.html.twig' as _translations %} -
-
- {{ _translations.default(hookable_data.form.translations, null, {accordionId: 'promotion-translations'}) }} -
+
+ {{ _translations.default(hookable_data.form.translations, null, {accordionId: 'promotion-translations'}) }}
diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/_sections.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/_sections.html.twig index ac0bb12eb19..535e2592eb2 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/_sections.html.twig +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/_sections.html.twig @@ -1,9 +1,7 @@ {% set main_hook = hook_name(hookable_data.parent_main_hook, 'sections') %} {% set fallback_hook = hook_name(hookable_data.parent_fallback_hook, 'sections') %} -
- {% hook [main_hook, fallback_hook] with hookable_data|merge({ - parent_main_hook: main_hook, - parent_fallback_hook: fallback_hook, - }) %} -
+{% hook [main_hook, fallback_hook] with hookable_data|merge({ + parent_main_hook: main_hook, + parent_fallback_hook: fallback_hook, +}) %} diff --git a/src/Sylius/Bundle/AdminBundle/TwigComponent/Promotion/FormComponent.php b/src/Sylius/Bundle/AdminBundle/TwigComponent/Promotion/FormComponent.php index 89f5b29f296..8624ca2b133 100644 --- a/src/Sylius/Bundle/AdminBundle/TwigComponent/Promotion/FormComponent.php +++ b/src/Sylius/Bundle/AdminBundle/TwigComponent/Promotion/FormComponent.php @@ -40,6 +40,7 @@ public function __construct( private readonly FormFactoryInterface $formFactory, private readonly string $formClass, private readonly array $rules, + private readonly array $actions, ) { } @@ -60,10 +61,11 @@ public function addCollectionItem(PropertyAccessorInterface $propertyAccessor, # } $index = [] !== $data ? max(array_keys($data)) + 1 : 0; + $propertyAccessor->setValue( $this->formValues, $propertyPath."[$index]", - ['type' => array_key_first($this->rules)], + ['type' => $this->provideItemType($name)], ); } @@ -71,4 +73,17 @@ protected function instantiateForm(): FormInterface { return $this->formFactory->create($this->formClass, $this->resource); } + + private function provideItemType(string $name): string + { + if (str_contains($name, 'rules')) { + return array_key_first($this->rules); + } + + if (str_contains($name, 'actions')) { + return array_key_first($this->actions); + } + + return ''; + } } From 28b424fe4d39fca492ea946bb056487de5c7c978 Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Tue, 9 Apr 2024 11:09:36 +0200 Subject: [PATCH 05/39] [Admin] Implement autocompletes for Promotion's rules and action on edit page --- .../Autocompleter/ProductAutocompleter.php | 58 +++++++++++++++++++ ...roductFilterConfigurationTypeExtension.php | 45 ++++++++++++++ .../TaxonFilterConfigurationTypeExtension.php | 46 +++++++++++++++ ...tainsProductConfigurationTypeExtension.php | 48 +++++++++++++++ .../HasTaxonConfigurationTypeExtension.php | 45 ++++++++++++++ ...emsFromTaxonConfigurationTypeExtension.php | 48 +++++++++++++++ .../Form/Field/ProductAutocompleteField.php | 44 ++++++++++++++ .../Type/ProductAutocompleteChoiceType.php | 47 +++++++++++++++ .../config/services/autocompleter.xml | 7 ++- .../Resources/config/services/form.xml | 39 +++++++++++++ 10 files changed, 426 insertions(+), 1 deletion(-) create mode 100644 src/Sylius/Bundle/AdminBundle/Autocompleter/ProductAutocompleter.php create mode 100644 src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Filter/ProductFilterConfigurationTypeExtension.php create mode 100644 src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Filter/TaxonFilterConfigurationTypeExtension.php create mode 100644 src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Rule/ContainsProductConfigurationTypeExtension.php create mode 100644 src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Rule/HasTaxonConfigurationTypeExtension.php create mode 100644 src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Rule/TotalOfItemsFromTaxonConfigurationTypeExtension.php create mode 100644 src/Sylius/Bundle/AdminBundle/Form/Field/ProductAutocompleteField.php create mode 100644 src/Sylius/Bundle/AdminBundle/Form/Type/ProductAutocompleteChoiceType.php diff --git a/src/Sylius/Bundle/AdminBundle/Autocompleter/ProductAutocompleter.php b/src/Sylius/Bundle/AdminBundle/Autocompleter/ProductAutocompleter.php new file mode 100644 index 00000000000..17530dbcd81 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Autocompleter/ProductAutocompleter.php @@ -0,0 +1,58 @@ +productClass; + } + + /** @param EntityRepository $repository */ + public function createFilteredQueryBuilder(EntityRepository $repository, string $query): QueryBuilder + { + return $repository->createQueryBuilder('o'); + } + + public function getLabel(object $entity): string + { + return $entity->getName(); + } + + public function getValue(object $entity): mixed + { + return $entity->getCode(); + } + + public function isGranted(Security $security): bool + { + return true; + } + + /** @param array $options */ + public function setOptions(array $options): void + { + } +} diff --git a/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Filter/ProductFilterConfigurationTypeExtension.php b/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Filter/ProductFilterConfigurationTypeExtension.php new file mode 100644 index 00000000000..550256e47f8 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Filter/ProductFilterConfigurationTypeExtension.php @@ -0,0 +1,45 @@ + $options */ + public function buildForm(FormBuilderInterface $builder, array $options): void + { + $builder + ->add('products', ProductAutocompleteChoiceType::class, [ + 'label' => 'sylius.form.promotion_filter.products', + 'multiple' => true, + ]) + ->get('products')->addModelTransformer($this->productsToCodesTransformer) + ; + } + + /** @return iterable */ + public static function getExtendedTypes(): iterable + { + return [ProductFilterConfigurationType::class]; + } +} diff --git a/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Filter/TaxonFilterConfigurationTypeExtension.php b/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Filter/TaxonFilterConfigurationTypeExtension.php new file mode 100644 index 00000000000..58119ad2228 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Filter/TaxonFilterConfigurationTypeExtension.php @@ -0,0 +1,46 @@ + $options */ + public function buildForm(FormBuilderInterface $builder, array $options): void + { + $builder + ->add('taxons', TaxonAutocompleteChoiceType::class, [ + 'label' => 'sylius.form.promotion_filter.taxons', + 'multiple' => true, + 'required' => false, + ]) + ->get('taxons')->addModelTransformer($this->taxonsToCodesTransformer) + ; + } + + /** @return iterable */ + public static function getExtendedTypes(): iterable + { + return [TaxonFilterConfigurationType::class]; + } +} diff --git a/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Rule/ContainsProductConfigurationTypeExtension.php b/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Rule/ContainsProductConfigurationTypeExtension.php new file mode 100644 index 00000000000..1ffedb644c6 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Rule/ContainsProductConfigurationTypeExtension.php @@ -0,0 +1,48 @@ + $options */ + public function buildForm(FormBuilderInterface $builder, array $options): void + { + $builder + ->add('product_code', ProductAutocompleteChoiceType::class, [ + 'label' => 'sylius.form.promotion_action.add_product_configuration.product', + ]) + ->get('product_code')->addModelTransformer( + new ReversedTransformer(new ResourceToIdentifierTransformer($this->productRepository, 'code')), + ) + ; + } + + /** @return iterable */ + public static function getExtendedTypes(): iterable + { + return [ContainsProductConfigurationType::class]; + } +} diff --git a/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Rule/HasTaxonConfigurationTypeExtension.php b/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Rule/HasTaxonConfigurationTypeExtension.php new file mode 100644 index 00000000000..5c5ad4a3b4f --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Rule/HasTaxonConfigurationTypeExtension.php @@ -0,0 +1,45 @@ + $options */ + public function buildForm(FormBuilderInterface $builder, array $options): void + { + $builder + ->add('taxons', TaxonAutocompleteChoiceType::class, [ + 'label' => 'sylius.form.promotion_rule.has_taxon.taxons', + 'multiple' => true, + ]) + ->get('taxons')->addModelTransformer($this->taxonsToCodesTransformer) + ; + } + + /** @return iterable */ + public static function getExtendedTypes(): iterable + { + return [HasTaxonConfigurationType::class]; + } +} diff --git a/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Rule/TotalOfItemsFromTaxonConfigurationTypeExtension.php b/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Rule/TotalOfItemsFromTaxonConfigurationTypeExtension.php new file mode 100644 index 00000000000..a9c7eca8023 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Rule/TotalOfItemsFromTaxonConfigurationTypeExtension.php @@ -0,0 +1,48 @@ + $options */ + public function buildForm(FormBuilderInterface $builder, array $options): void + { + $builder + ->add('taxon', TaxonAutocompleteChoiceType::class, [ + 'label' => 'sylius.form.promotion_rule.total_of_items_from_taxon.taxon', + ]) + ->get('taxon')->addModelTransformer( + new ReversedTransformer(new ResourceToIdentifierTransformer($this->taxonRepository, 'code')), + ) + ; + } + + /** @return iterable */ + public static function getExtendedTypes(): iterable + { + return [TotalOfItemsFromTaxonConfigurationType::class]; + } +} diff --git a/src/Sylius/Bundle/AdminBundle/Form/Field/ProductAutocompleteField.php b/src/Sylius/Bundle/AdminBundle/Form/Field/ProductAutocompleteField.php new file mode 100644 index 00000000000..81cd9184e55 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Form/Field/ProductAutocompleteField.php @@ -0,0 +1,44 @@ +setDefaults([ + 'class' => Food::class, + 'placeholder' => 'What should we eat?', + + // choose which fields to use in the search + // if not passed, *all* fields are used + //'searchable_fields' => ['name'], + + // if the autocomplete endpoint needs to be secured + //'security' => 'ROLE_FOOD_ADMIN', + + // ... any other normal EntityType options + // e.g. query_builder, choice_label + ]); + } + + public function getParent(): string + { + return BaseEntityAutocompleteType::class; + } +} diff --git a/src/Sylius/Bundle/AdminBundle/Form/Type/ProductAutocompleteChoiceType.php b/src/Sylius/Bundle/AdminBundle/Form/Type/ProductAutocompleteChoiceType.php new file mode 100644 index 00000000000..73d14128fbc --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Form/Type/ProductAutocompleteChoiceType.php @@ -0,0 +1,47 @@ +setDefaults([ + 'class' => $this->productClass, + 'choice_name' => 'name', + 'choice_value' => 'code', + ]); + } + + public function getBlockPrefix(): string + { + return 'sylius_admin_product_autocomplete_choice'; + } + + public function getParent(): string + { + return BaseEntityAutocompleteType::class; + } +} diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/services/autocompleter.xml b/src/Sylius/Bundle/AdminBundle/Resources/config/services/autocompleter.xml index c82510f975b..d0625a30423 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/services/autocompleter.xml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/services/autocompleter.xml @@ -13,11 +13,16 @@ - + %sylius.model.product_attribute.class% + + %sylius.model.product.class% + + + %sylius.model.taxon.class% diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/services/form.xml b/src/Sylius/Bundle/AdminBundle/Resources/config/services/form.xml index c856ba22a19..5a564802efd 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/services/form.xml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/services/form.xml @@ -71,6 +71,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + %sylius.model.product.class% + + + + + %sylius.model.taxon.class% + + + %sylius.form.type.admin.password_reset_request.validation_groups% From 3cb4de7a82cad01126fbbc2da76fb0af28c85b6f Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Tue, 9 Apr 2024 12:43:00 +0200 Subject: [PATCH 06/39] [Admin] Add rules and actions to Promotion create page --- .../config/app/twig_hooks/promotion/create.yaml | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/create.yaml b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/create.yaml index 3077b8bdb57..b1e9d6cd3b5 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/create.yaml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/create.yaml @@ -2,10 +2,15 @@ twig_hooks: hooks: 'sylius_admin.promotion.create.content': form: - template: '@SyliusAdmin/Shared/Crud/Create/Content/_form.html.twig' + component: 'SyliusAdmin.Promotion.Form' + data: + resource: '@=resource' + form: '@=form' + parentMainHook: '@=parent_main_hook' + parentFallbackHook: '@=parent_fallback_hook' configuration: render_rest: false - + 'sylius_admin.promotion.create.content.form': sections: template: '@SyliusAdmin/Promotion/Form/_sections.html.twig' @@ -17,6 +22,8 @@ twig_hooks: template: '@SyliusAdmin/Promotion/Form/Sections/_configuration.html.twig' translations: template: '@SyliusAdmin/Promotion/Form/Sections/_translations.html.twig' + rules_and_actions: + template: '@SyliusAdmin/Promotion/Form/Sections/_rulesAndActions.html.twig' 'sylius_admin.promotion.create.content.form.sections.general': _name: @@ -53,3 +60,9 @@ twig_hooks: template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/Right/_exclusive.html.twig' applies_to_discounted: template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/Right/_appliesToDiscounted.html.twig' + + 'sylius_admin.promotion.create.content.form.sections.rules_and_actions': + rules: + template: '@SyliusAdmin/Promotion/Form/Sections/RulesAndActions/_rules.html.twig' + actions: + template: '@SyliusAdmin/Promotion/Form/Sections/RulesAndActions/_actions.html.twig' From f044a7ab78e48adbc4e1d66508af09a0cae5e2ef Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Tue, 9 Apr 2024 12:57:40 +0200 Subject: [PATCH 07/39] [Behat][Admin] Enable deleting promotion scenario --- .../promotion/managing_promotions/deleting_promotion.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/admin/promotion/managing_promotions/deleting_promotion.feature b/features/admin/promotion/managing_promotions/deleting_promotion.feature index 27374d22385..b032fde706f 100644 --- a/features/admin/promotion/managing_promotions/deleting_promotion.feature +++ b/features/admin/promotion/managing_promotions/deleting_promotion.feature @@ -9,7 +9,7 @@ Feature: Deleting a promotion And there is a promotion "Christmas sale" And I am logged in as an administrator - @api @todo @ui + @api @ui Scenario: Deleted promotion should disappear from the registry When I delete a "Christmas sale" promotion Then I should be notified that it has been successfully deleted From fc8219d35d5cf9e31c5a03c601aecc5ad5535053 Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Tue, 9 Apr 2024 13:59:04 +0200 Subject: [PATCH 08/39] [Behat][Admin] Cover scenarios for adding promotion --- .../adding_promotion.feature | 14 ++-- .../Ui/Admin/ManagingPromotionsContext.php | 8 +-- .../Behat/Page/Admin/Promotion/CreatePage.php | 48 +------------ .../Admin/Promotion/CreatePageInterface.php | 16 +---- .../Admin/Promotion/FormAwareInterface.php | 22 ++++++ .../Behat/Page/Admin/Promotion/FormTrait.php | 67 +++++++++++++++++++ .../Configuration/Left/_usageLimit.html.twig | 2 +- 7 files changed, 105 insertions(+), 72 deletions(-) create mode 100644 src/Sylius/Behat/Page/Admin/Promotion/FormAwareInterface.php create mode 100644 src/Sylius/Behat/Page/Admin/Promotion/FormTrait.php diff --git a/features/admin/promotion/managing_promotions/adding_promotion.feature b/features/admin/promotion/managing_promotions/adding_promotion.feature index a96941ac760..8ca1c91bea6 100644 --- a/features/admin/promotion/managing_promotions/adding_promotion.feature +++ b/features/admin/promotion/managing_promotions/adding_promotion.feature @@ -8,7 +8,7 @@ Feature: Adding a new promotion Given the store operates on a single channel in "United States" And I am logged in as an administrator - @api @todo @ui + @api @ui Scenario: Adding a new promotion When I want to create a new promotion And I specify its code as "FULL_METAL_PROMOTION" @@ -17,7 +17,7 @@ Feature: Adding a new promotion Then I should be notified that it has been successfully created And the "Full metal promotion" promotion should appear in the registry - @api @todo @ui + @api @ui Scenario: Adding a new promotion with usage limit When I want to create a new promotion And I specify its code as "FULL_METAL_PROMOTION" @@ -27,7 +27,7 @@ Feature: Adding a new promotion Then I should be notified that it has been successfully created And the "Full metal promotion" promotion should be available to be used only 50 times - @api @todo @ui + @api @ui Scenario: Adding a new exclusive promotion When I want to create a new promotion And I specify its code as "FULL_METAL_PROMOTION" @@ -37,7 +37,7 @@ Feature: Adding a new promotion Then I should be notified that it has been successfully created And the "Full metal promotion" promotion should be exclusive - @api @todo @ui + @api @ui Scenario: Adding a new coupon based promotion When I want to create a new promotion And I specify its code as "FULL_METAL_PROMOTION" @@ -47,7 +47,7 @@ Feature: Adding a new promotion Then I should be notified that it has been successfully created And the "Full metal promotion" promotion should be coupon based - @api @todo @ui + @api @ui Scenario: Adding a new channels promotion When I want to create a new promotion And I specify its code as "FULL_METAL_PROMOTION" @@ -57,7 +57,7 @@ Feature: Adding a new promotion Then I should be notified that it has been successfully created And the "Full metal promotion" promotion should be applicable for the "United States" channel - @api @todo @ui + @api @ui Scenario: Adding a promotion with start and end date When I want to create a new promotion And I specify its code as "FULL_METAL_PROMOTION" @@ -66,7 +66,7 @@ Feature: Adding a new promotion And I add it Then I should be notified that it has been successfully created - @api @todo @ui + @api @ui Scenario: Adding a promotion not applies to discounted by catalog promotion items When I want to create a new promotion And I specify its code as "FULL_METAL_PROMOTION" diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php index 54b92f67362..9e1fb739745 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php @@ -380,12 +380,12 @@ public function thereShouldStillBeOnlyOnePromotionWith($element, $value) /** * @When I set its usage limit to :usageLimit */ - public function iSetItsUsageLimitTo($usageLimit) + public function iSetItsUsageLimitTo(int $usageLimit): void { /** @var CreatePageInterface|UpdatePageInterface $currentPage */ $currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]); - $currentPage->fillUsageLimit($usageLimit); + $currentPage->setUsageLimit($usageLimit); } /** @@ -439,12 +439,12 @@ public function thePromotionShouldNotAppliesToDiscountedItems(PromotionInterface /** * @When I make it coupon based */ - public function iMakeItCouponBased() + public function iMakeItCouponBased(): void { /** @var CreatePageInterface|UpdatePageInterface $currentPage */ $currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]); - $currentPage->checkCouponBased(); + $currentPage->makeCouponBased(); } /** diff --git a/src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php b/src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php index 7347b83199e..414658b5f50 100644 --- a/src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php +++ b/src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php @@ -24,6 +24,7 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface { + use FormTrait; use NamesIt; use SpecifiesItsField; @@ -111,46 +112,6 @@ public function fillActionOptionForChannel(string $channelCode, string $option, $lastAction->fillField($option, $value); } - public function fillUsageLimit(string $limit): void - { - $this->getDocument()->fillField('Usage limit', $limit); - } - - public function makeExclusive(): void - { - $this->getDocument()->checkField('Exclusive'); - } - - public function makeNotAppliesToDiscountedItem(): void - { - $this->getDocument()->unCheckField('Applies to already discounted order items'); - } - - public function checkCouponBased(): void - { - $this->getDocument()->checkField('Coupon based'); - } - - public function checkChannel(string $name): void - { - $this->getDocument()->checkField($name); - } - - public function setStartsAt(\DateTimeInterface $dateTime): void - { - $timestamp = $dateTime->getTimestamp(); - - $this->getDocument()->fillField('sylius_promotion_startsAt_date', date('Y-m-d', $timestamp)); - $this->getDocument()->fillField('sylius_promotion_startsAt_time', date('H:i', $timestamp)); - } - - public function setEndsAt(\DateTimeInterface $dateTime): void - { - $timestamp = $dateTime->getTimestamp(); - - $this->getDocument()->fillField('sylius_promotion_endsAt_date', date('Y-m-d', $timestamp)); - $this->getDocument()->fillField('sylius_promotion_endsAt_time', date('H:i', $timestamp)); - } public function getValidationMessageForAction(): string { @@ -207,18 +168,15 @@ public function hasLabel(string $label, string $localeCode): bool protected function getDefinedElements(): array { - return [ + return array_merge(parent::getDefinedElements(), $this->getDefinedFormElements(), [ 'actions' => '#sylius_promotion_actions', 'code' => '#sylius_promotion_code', - 'ends_at' => '#sylius_promotion_endsAt', 'minimum' => '#sylius_promotion_actions_0_configuration_WEB-US_filters_price_range_filter_min', 'maximum' => '#sylius_promotion_actions_0_configuration_WEB-US_filters_price_range_filter_max', - 'name' => '#sylius_promotion_name', 'rules' => '#sylius_promotion_rules', - 'starts_at' => '#sylius_promotion_startsAt', 'count' => '#sylius_promotion_rules_0_configuration_count', 'amount' => '#sylius_promotion_actions_0_configuration_WEB-US_amount', - ]; + ]); } private function getChannelConfigurationOfLastAction(string $channelCode): NodeElement diff --git a/src/Sylius/Behat/Page/Admin/Promotion/CreatePageInterface.php b/src/Sylius/Behat/Page/Admin/Promotion/CreatePageInterface.php index 30a0fb094a2..56832ab218e 100644 --- a/src/Sylius/Behat/Page/Admin/Promotion/CreatePageInterface.php +++ b/src/Sylius/Behat/Page/Admin/Promotion/CreatePageInterface.php @@ -16,7 +16,7 @@ use Behat\Mink\Exception\ElementNotFoundException; use Sylius\Behat\Page\Admin\Crud\CreatePageInterface as BaseCreatePageInterface; -interface CreatePageInterface extends BaseCreatePageInterface +interface CreatePageInterface extends BaseCreatePageInterface, FormAwareInterface { public function specifyCode(string $code): void; @@ -45,20 +45,6 @@ public function fillActionOption(string $option, string $value): void; public function fillActionOptionForChannel(string $channelCode, string $option, string $value): void; - public function fillUsageLimit(string $limit): void; - - public function makeExclusive(): void; - - public function makeNotAppliesToDiscountedItem(): void; - - public function checkCouponBased(): void; - - public function checkChannel(string $name): void; - - public function setStartsAt(\DateTimeInterface $dateTime): void; - - public function setEndsAt(\DateTimeInterface $dateTime): void; - /** * @throws ElementNotFoundException */ diff --git a/src/Sylius/Behat/Page/Admin/Promotion/FormAwareInterface.php b/src/Sylius/Behat/Page/Admin/Promotion/FormAwareInterface.php new file mode 100644 index 00000000000..ef92065ed47 --- /dev/null +++ b/src/Sylius/Behat/Page/Admin/Promotion/FormAwareInterface.php @@ -0,0 +1,22 @@ +getTimestamp(); + + $this->getElement('field_starts_at_date')->setValue(date('Y-m-d', $timestamp)); + $this->getElement('field_starts_at_time')->setValue(date('H:i', $timestamp)); + } + + public function setEndsAt(\DateTimeInterface $dateTime): void + { + $timestamp = $dateTime->getTimestamp(); + + $this->getElement('field_ends_at_date')->setValue(date('Y-m-d', $timestamp)); + $this->getElement('field_ends_at_time')->setValue(date('H:i', $timestamp)); + } + + public function setUsageLimit(int $limit): void + { + $this->getElement('field_usage_limit')->setValue($limit); + } + + public function makeExclusive(): void + { + $this->getElement('field_exclusive')->check(); + } + + public function makeNotAppliesToDiscountedItem(): void + { + $this->getElement('field_applies_to_discounted')->uncheck(); + } + + public function makeCouponBased(): void + { + $this->getElement('field_coupon_based')->check(); + } + + public function checkChannel(string $name): void + { + $this->getElement('channels')->checkField($name); + } + + /** @return array */ + protected function getDefinedFormElements(): array + { + return [ + 'channels' => '#sylius_promotion_channels', + 'field_applies_to_discounted' => '#sylius_promotion_appliesToDiscounted', + 'field_coupon_based' => '#sylius_promotion_couponBased', + 'field_ends_at_date' => '#sylius_promotion_endsAt_date', + 'field_ends_at_time' => '#sylius_promotion_endsAt_time', + 'field_exclusive' => '#sylius_promotion_exclusive', + 'field_label' => '[name="sylius_promotion[translations][%localeCode%][label]"]', + 'field_name' => '#sylius_promotion_name', + 'field_usage_limit' => '#sylius_promotion_usageLimit', + 'field_starts_at_date' => '#sylius_promotion_startsAt_date', + 'field_starts_at_time' => '#sylius_promotion_startsAt_time', + ]; + } +} diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Left/_usageLimit.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Left/_usageLimit.html.twig index 124131c204f..b31d710ba3a 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Left/_usageLimit.html.twig +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Left/_usageLimit.html.twig @@ -1,3 +1,3 @@
- {{ form_row(hookable_data.form.usageLimit) }} + {{ form_row(hookable_data.form.usageLimit, sylius_test_form_attribute('usage-limit')) }}
From c41bd55e7d05ff8ca3e3111d7ba2f7604de1968d Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Tue, 9 Apr 2024 14:38:45 +0200 Subject: [PATCH 09/39] [Behat][Admin] Cover scenarios for adding promotion with a label --- ...g_promotion_in_different_languages.feature | 2 +- .../Behat/Page/Admin/Promotion/CreatePage.php | 19 ------------------- .../Admin/Promotion/CreatePageInterface.php | 4 ---- .../Admin/Promotion/FormAwareInterface.php | 4 ++++ .../Behat/Page/Admin/Promotion/FormTrait.php | 12 +++++++++++- 5 files changed, 16 insertions(+), 25 deletions(-) diff --git a/features/admin/promotion/managing_promotions/adding_promotion_in_different_languages.feature b/features/admin/promotion/managing_promotions/adding_promotion_in_different_languages.feature index 341ee1305f9..12bcaed0682 100644 --- a/features/admin/promotion/managing_promotions/adding_promotion_in_different_languages.feature +++ b/features/admin/promotion/managing_promotions/adding_promotion_in_different_languages.feature @@ -9,7 +9,7 @@ Feature: Adding promotion in different languages And that channel allows to shop using "English (United States)" and "Polish (Poland)" locales And I am logged in as an administrator - @api @todo @ui @javascript + @api @ui Scenario: Adding a promotion with a label in a different language When I want to create a new promotion And I specify its code as "FULL_METAL_PROMOTION" diff --git a/src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php b/src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php index 414658b5f50..2e6d913e451 100644 --- a/src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php +++ b/src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php @@ -28,13 +28,6 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface use NamesIt; use SpecifiesItsField; - public function specifyLabel(string $label, string $localeCode): void - { - $this->getDocument()->find('css', 'div[data-locale="' . $localeCode . '"]')->click(); - - $this->getDocument()->fillField(sprintf('sylius_promotion_translations_%s_label', $localeCode), $label); - } - public function addRule(?string $ruleName): void { $count = count($this->getCollectionItems('rules')); @@ -154,18 +147,6 @@ public function checkIfActionConfigurationFormIsVisible(): bool return $this->hasElement('amount'); } - public function hasLabel(string $label, string $localeCode): bool - { - $this->getDocument()->find('css', 'div[data-locale="' . $localeCode . '"]')->click(); - - $labelElement = $this->getDocument()->find('css', sprintf('label:contains("%s")', $label)); - if (null === $labelElement) { - return false; - } - - return $labelElement->hasClass(sprintf('sylius-locale-%s', $localeCode)); - } - protected function getDefinedElements(): array { return array_merge(parent::getDefinedElements(), $this->getDefinedFormElements(), [ diff --git a/src/Sylius/Behat/Page/Admin/Promotion/CreatePageInterface.php b/src/Sylius/Behat/Page/Admin/Promotion/CreatePageInterface.php index 56832ab218e..5e46918ea17 100644 --- a/src/Sylius/Behat/Page/Admin/Promotion/CreatePageInterface.php +++ b/src/Sylius/Behat/Page/Admin/Promotion/CreatePageInterface.php @@ -20,8 +20,6 @@ interface CreatePageInterface extends BaseCreatePageInterface, FormAwareInterfac { public function specifyCode(string $code): void; - public function specifyLabel(string $label, string $localeCode): void; - public function nameIt(string $name): void; public function addRule(?string $ruleName): void; @@ -58,6 +56,4 @@ public function selectAutoCompleteFilterOption(string $option, array|string $val public function checkIfRuleConfigurationFormIsVisible(): bool; public function checkIfActionConfigurationFormIsVisible(): bool; - - public function hasLabel(string $label, string $localeCode): bool; } diff --git a/src/Sylius/Behat/Page/Admin/Promotion/FormAwareInterface.php b/src/Sylius/Behat/Page/Admin/Promotion/FormAwareInterface.php index ef92065ed47..3de8e43679a 100644 --- a/src/Sylius/Behat/Page/Admin/Promotion/FormAwareInterface.php +++ b/src/Sylius/Behat/Page/Admin/Promotion/FormAwareInterface.php @@ -19,4 +19,8 @@ public function makeNotAppliesToDiscountedItem(): void; public function makeCouponBased(): void; public function checkChannel(string $name): void; + + public function specifyLabel(string $label, string $localeCode): void; + + public function hasLabel(string $label, string $localeCode): bool; } diff --git a/src/Sylius/Behat/Page/Admin/Promotion/FormTrait.php b/src/Sylius/Behat/Page/Admin/Promotion/FormTrait.php index f976dc3056d..1d126a2f143 100644 --- a/src/Sylius/Behat/Page/Admin/Promotion/FormTrait.php +++ b/src/Sylius/Behat/Page/Admin/Promotion/FormTrait.php @@ -47,6 +47,16 @@ public function checkChannel(string $name): void $this->getElement('channels')->checkField($name); } + public function specifyLabel(string $label, string $localeCode): void + { + $this->getElement('field_label', ['%locale_code%' => $localeCode])->setValue($label); + } + + public function hasLabel(string $label, string $localeCode): bool + { + return $label === $this->getElement('field_label', ['%locale_code%' => $localeCode])->getValue(); + } + /** @return array */ protected function getDefinedFormElements(): array { @@ -57,7 +67,7 @@ protected function getDefinedFormElements(): array 'field_ends_at_date' => '#sylius_promotion_endsAt_date', 'field_ends_at_time' => '#sylius_promotion_endsAt_time', 'field_exclusive' => '#sylius_promotion_exclusive', - 'field_label' => '[name="sylius_promotion[translations][%localeCode%][label]"]', + 'field_label' => '[name="sylius_promotion[translations][%locale_code%][label]"]', 'field_name' => '#sylius_promotion_name', 'field_usage_limit' => '#sylius_promotion_usageLimit', 'field_starts_at_date' => '#sylius_promotion_startsAt_date', From d2d7fa96129900343bcbc2d6049874509668d68a Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Tue, 9 Apr 2024 14:56:02 +0200 Subject: [PATCH 10/39] [Behat][Admin] Cover scenarios for editing promotion --- .../editing_promotion.feature | 18 ++++---- .../Ui/Admin/ManagingPromotionsContext.php | 2 +- .../Behat/Page/Admin/Promotion/FormTrait.php | 40 ++++++++--------- .../Behat/Page/Admin/Promotion/UpdatePage.php | 45 ++----------------- .../Admin/Promotion/UpdatePageInterface.php | 14 +----- 5 files changed, 34 insertions(+), 85 deletions(-) diff --git a/features/admin/promotion/managing_promotions/editing_promotion.feature b/features/admin/promotion/managing_promotions/editing_promotion.feature index 09198dbfd14..2eabd044bd7 100644 --- a/features/admin/promotion/managing_promotions/editing_promotion.feature +++ b/features/admin/promotion/managing_promotions/editing_promotion.feature @@ -10,12 +10,12 @@ Feature: Editing promotion And there is a promotion "Holiday sale" with priority 1 And I am logged in as an administrator - @api @todo @ui + @api @ui Scenario: Being unable to change code of promotion When I want to modify a "Christmas sale" promotion Then I should not be able to edit its code - @api @todo @ui + @api @ui Scenario: Editing promotions usage limit When I want to modify a "Christmas sale" promotion And I set its usage limit to 50 @@ -23,7 +23,7 @@ Feature: Editing promotion Then I should be notified that it has been successfully edited And the "Christmas sale" promotion should be available to be used only 50 times - @api @todo @ui + @api @ui Scenario: Editing promotion exclusiveness When I want to modify a "Christmas sale" promotion And I set it as exclusive @@ -31,7 +31,7 @@ Feature: Editing promotion Then I should be notified that it has been successfully edited And the "Christmas sale" promotion should be exclusive - @api @todo @ui + @api @ui Scenario: Editing promotions coupon based option When I want to modify a "Christmas sale" promotion And I make it coupon based @@ -39,7 +39,7 @@ Feature: Editing promotion Then I should be notified that it has been successfully edited And the "Christmas sale" promotion should be coupon based - @api @todo @ui + @api @ui Scenario: Editing promotions channels When I want to modify a "Christmas sale" promotion And I make it applicable for the "United States" channel @@ -47,7 +47,7 @@ Feature: Editing promotion Then I should be notified that it has been successfully edited And the "Christmas sale" promotion should be applicable for the "United States" channel - @api @todo @ui + @api @ui Scenario: Editing a promotion with start and end date When I want to modify a "Christmas sale" promotion And I make it available from "12.12.2017" to "24.12.2017" @@ -55,13 +55,13 @@ Feature: Editing promotion Then I should be notified that it has been successfully edited And the "Christmas sale" promotion should be available from "12.12.2017" to "24.12.2017" - @api @todo @ui + @api @ui Scenario: Editing promotion after adding a new channel Given this promotion gives "$10.00" discount to every order When the store also operates on another channel named "EU-WEB" Then I should be able to modify a "Christmas sale" promotion - @todo @ui @no-api + @ui @no-api Scenario: Remove priority from existing promotion When I want to modify a "Christmas sale" promotion And I remove its priority @@ -69,7 +69,7 @@ Feature: Editing promotion Then I should be notified that it has been successfully edited And the "Christmas sale" promotion should have priority 1 - @api @todo @ui + @api @ui Scenario: Setting promotion to the lowest priority When I want to modify a "Christmas sale" promotion And I set its priority to "-1" diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php index 9e1fb739745..6eea39f87ae 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php @@ -391,7 +391,7 @@ public function iSetItsUsageLimitTo(int $usageLimit): void /** * @Then the :promotion promotion should be available to be used only :usageLimit times */ - public function thePromotionShouldBeAvailableToUseOnlyTimes(PromotionInterface $promotion, $usageLimit) + public function thePromotionShouldBeAvailableToUseOnlyTimes(PromotionInterface $promotion, int $usageLimit): void { $this->iWantToModifyAPromotion($promotion); diff --git a/src/Sylius/Behat/Page/Admin/Promotion/FormTrait.php b/src/Sylius/Behat/Page/Admin/Promotion/FormTrait.php index 1d126a2f143..d8e8aeb09f0 100644 --- a/src/Sylius/Behat/Page/Admin/Promotion/FormTrait.php +++ b/src/Sylius/Behat/Page/Admin/Promotion/FormTrait.php @@ -10,36 +10,36 @@ public function setStartsAt(\DateTimeInterface $dateTime): void { $timestamp = $dateTime->getTimestamp(); - $this->getElement('field_starts_at_date')->setValue(date('Y-m-d', $timestamp)); - $this->getElement('field_starts_at_time')->setValue(date('H:i', $timestamp)); + $this->getElement('starts_at_date')->setValue(date('Y-m-d', $timestamp)); + $this->getElement('starts_at_time')->setValue(date('H:i', $timestamp)); } public function setEndsAt(\DateTimeInterface $dateTime): void { $timestamp = $dateTime->getTimestamp(); - $this->getElement('field_ends_at_date')->setValue(date('Y-m-d', $timestamp)); - $this->getElement('field_ends_at_time')->setValue(date('H:i', $timestamp)); + $this->getElement('ends_at_date')->setValue(date('Y-m-d', $timestamp)); + $this->getElement('ends_at_time')->setValue(date('H:i', $timestamp)); } public function setUsageLimit(int $limit): void { - $this->getElement('field_usage_limit')->setValue($limit); + $this->getElement('usage_limit')->setValue($limit); } public function makeExclusive(): void { - $this->getElement('field_exclusive')->check(); + $this->getElement('exclusive')->check(); } public function makeNotAppliesToDiscountedItem(): void { - $this->getElement('field_applies_to_discounted')->uncheck(); + $this->getElement('applies_to_discounted')->uncheck(); } public function makeCouponBased(): void { - $this->getElement('field_coupon_based')->check(); + $this->getElement('coupon_based')->check(); } public function checkChannel(string $name): void @@ -49,12 +49,12 @@ public function checkChannel(string $name): void public function specifyLabel(string $label, string $localeCode): void { - $this->getElement('field_label', ['%locale_code%' => $localeCode])->setValue($label); + $this->getElement('label', ['%locale_code%' => $localeCode])->setValue($label); } public function hasLabel(string $label, string $localeCode): bool { - return $label === $this->getElement('field_label', ['%locale_code%' => $localeCode])->getValue(); + return $label === $this->getElement('label', ['%locale_code%' => $localeCode])->getValue(); } /** @return array */ @@ -62,16 +62,16 @@ protected function getDefinedFormElements(): array { return [ 'channels' => '#sylius_promotion_channels', - 'field_applies_to_discounted' => '#sylius_promotion_appliesToDiscounted', - 'field_coupon_based' => '#sylius_promotion_couponBased', - 'field_ends_at_date' => '#sylius_promotion_endsAt_date', - 'field_ends_at_time' => '#sylius_promotion_endsAt_time', - 'field_exclusive' => '#sylius_promotion_exclusive', - 'field_label' => '[name="sylius_promotion[translations][%locale_code%][label]"]', - 'field_name' => '#sylius_promotion_name', - 'field_usage_limit' => '#sylius_promotion_usageLimit', - 'field_starts_at_date' => '#sylius_promotion_startsAt_date', - 'field_starts_at_time' => '#sylius_promotion_startsAt_time', + 'applies_to_discounted' => '#sylius_promotion_appliesToDiscounted', + 'coupon_based' => '#sylius_promotion_couponBased', + 'ends_at_date' => '#sylius_promotion_endsAt_date', + 'ends_at_time' => '#sylius_promotion_endsAt_time', + 'exclusive' => '#sylius_promotion_exclusive', + 'label' => '[name="sylius_promotion[translations][%locale_code%][label]"]', + 'name' => '#sylius_promotion_name', + 'usage_limit' => '#sylius_promotion_usageLimit', + 'starts_at_date' => '#sylius_promotion_startsAt_date', + 'starts_at_time' => '#sylius_promotion_startsAt_time', ]; } } diff --git a/src/Sylius/Behat/Page/Admin/Promotion/UpdatePage.php b/src/Sylius/Behat/Page/Admin/Promotion/UpdatePage.php index f9072e2889e..2145f55f690 100644 --- a/src/Sylius/Behat/Page/Admin/Promotion/UpdatePage.php +++ b/src/Sylius/Behat/Page/Admin/Promotion/UpdatePage.php @@ -24,6 +24,7 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface { use ChecksCodeImmutability; use CountsChannelBasedErrors; + use FormTrait; use NamesIt; public function setPriority(?int $priority): void @@ -43,42 +44,6 @@ public function checkChannelsState(string $channelName): bool return (bool) $field->getValue(); } - public function fillUsageLimit(string $limit): void - { - $this->getDocument()->fillField('Usage limit', $limit); - } - - public function makeExclusive(): void - { - $this->getDocument()->checkField('Exclusive'); - } - - public function checkCouponBased(): void - { - $this->getDocument()->checkField('Coupon based'); - } - - public function checkChannel(string $name): void - { - $this->getDocument()->checkField($name); - } - - public function setStartsAt(\DateTimeInterface $dateTime): void - { - $timestamp = $dateTime->getTimestamp(); - - $this->getDocument()->fillField('sylius_promotion_startsAt_date', date('Y-m-d', $timestamp)); - $this->getDocument()->fillField('sylius_promotion_startsAt_time', date('H:i', $timestamp)); - } - - public function setEndsAt(\DateTimeInterface $dateTime): void - { - $timestamp = $dateTime->getTimestamp(); - - $this->getDocument()->fillField('sylius_promotion_endsAt_date', date('Y-m-d', $timestamp)); - $this->getDocument()->fillField('sylius_promotion_endsAt_time', date('H:i', $timestamp)); - } - public function hasStartsAt(\DateTimeInterface $dateTime): bool { $timestamp = $dateTime->getTimestamp(); @@ -189,16 +154,13 @@ protected function getCodeElement(): NodeElement protected function getDefinedElements(): array { - return [ + return array_merge(parent::getDefinedElements(), $this->getDefinedFormElements(), [ 'action_field' => '[id^="sylius_promotion_actions_"][id$="_configuration_%channelCode%_%field%"]', 'actions' => '#actions', - 'applies_to_discounted' => '#sylius_promotion_appliesToDiscounted', 'code' => '#sylius_promotion_code', - 'coupon_based' => '#sylius_promotion_couponBased', 'ends_at' => '#sylius_promotion_endsAt', 'ends_at_date' => '#sylius_promotion_endsAt_date', 'ends_at_time' => '#sylius_promotion_endsAt_time', - 'exclusive' => '#sylius_promotion_exclusive', 'label' => '#sylius_promotion_translations_%localeCode%_label', 'name' => '#sylius_promotion_name', 'order_percentage_action_field' => '[id^="sylius_promotion_actions_"][id$="_configuration_percentage"]', @@ -208,7 +170,6 @@ protected function getDefinedElements(): array 'starts_at' => '#sylius_promotion_startsAt', 'starts_at_date' => '#sylius_promotion_startsAt_date', 'starts_at_time' => '#sylius_promotion_startsAt_time', - 'usage_limit' => '#sylius_promotion_usageLimit', - ]; + ]); } } diff --git a/src/Sylius/Behat/Page/Admin/Promotion/UpdatePageInterface.php b/src/Sylius/Behat/Page/Admin/Promotion/UpdatePageInterface.php index 3f3804b1ff4..e574b968008 100644 --- a/src/Sylius/Behat/Page/Admin/Promotion/UpdatePageInterface.php +++ b/src/Sylius/Behat/Page/Admin/Promotion/UpdatePageInterface.php @@ -16,7 +16,7 @@ use Behat\Mink\Exception\ElementNotFoundException; use Sylius\Behat\Page\Admin\Crud\UpdatePageInterface as BaseUpdatePageInterface; -interface UpdatePageInterface extends BaseUpdatePageInterface +interface UpdatePageInterface extends BaseUpdatePageInterface, FormAwareInterface { public function setPriority(?int $priority): void; @@ -28,18 +28,6 @@ public function checkChannelsState(string $channelName): bool; public function isCodeDisabled(): bool; - public function fillUsageLimit(string $limit): void; - - public function makeExclusive(): void; - - public function checkCouponBased(): void; - - public function checkChannel(string $name): void; - - public function setStartsAt(\DateTimeInterface $dateTime): void; - - public function setEndsAt(\DateTimeInterface $dateTime): void; - public function hasStartsAt(\DateTimeInterface $dateTime): bool; public function hasEndsAt(\DateTimeInterface $dateTime): bool; From 1fbd400cd140dac63f8b6aefd6cc6f2dae174ab7 Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Tue, 9 Apr 2024 15:18:32 +0200 Subject: [PATCH 11/39] [Behat][Admin] Use element instead of trait for promotion form --- .../Ui/Admin/ManagingPromotionsContext.php | 53 ++++--------- .../Element/Admin/Promotion/FormElement.php | 62 +++++++++++++++ .../Admin/Promotion/FormElementInterface.php | 18 +++++ .../Behat/Page/Admin/Promotion/CreatePage.php | 3 +- .../Admin/Promotion/CreatePageInterface.php | 2 +- .../Admin/Promotion/FormAwareInterface.php | 26 ------- .../Behat/Page/Admin/Promotion/FormTrait.php | 77 ------------------- .../Behat/Page/Admin/Promotion/UpdatePage.php | 7 +- .../Admin/Promotion/UpdatePageInterface.php | 2 +- 9 files changed, 105 insertions(+), 145 deletions(-) delete mode 100644 src/Sylius/Behat/Page/Admin/Promotion/FormAwareInterface.php delete mode 100644 src/Sylius/Behat/Page/Admin/Promotion/FormTrait.php diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php index 6eea39f87ae..b8fe0abfc9d 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php @@ -58,7 +58,7 @@ public function iWantToCreateANewPromotion(): void * @When I want to browse promotions * @When I browse promotions */ - public function iWantToBrowsePromotions() + public function iWantToBrowsePromotions(): void { $this->indexPage->open(); } @@ -118,7 +118,7 @@ public function iAddIt() */ public function iSpecifyItsLabelInLocaleCode(string $label, string $localeCode): void { - $this->createPage->specifyLabel($label, $localeCode); + $this->formElement->setLabel($label, $localeCode); } /** @@ -126,7 +126,7 @@ public function iSpecifyItsLabelInLocaleCode(string $label, string $localeCode): */ public function iSpecifyItsLabelWithAStringExceedingTheLimitInLocale(string $localeCode): void { - $this->createPage->specifyLabel(str_repeat('a', 256), $localeCode); + $this->formElement->setLabel(str_repeat('a', 256), $localeCode); } /** @@ -135,7 +135,7 @@ public function iSpecifyItsLabelWithAStringExceedingTheLimitInLocale(string $loc public function thePromotionShouldHaveLabelInLocale(PromotionInterface $promotion, string $label, string $localeCode): void { $this->updatePage->open(['id' => $promotion->getId()]); - $this->createPage->hasLabel($label, $localeCode); + $this->formElement->hasLabel($label, $localeCode); } /** @@ -382,10 +382,7 @@ public function thereShouldStillBeOnlyOnePromotionWith($element, $value) */ public function iSetItsUsageLimitTo(int $usageLimit): void { - /** @var CreatePageInterface|UpdatePageInterface $currentPage */ - $currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]); - - $currentPage->setUsageLimit($usageLimit); + $this->formElement->setUsageLimit($usageLimit); } /** @@ -403,10 +400,7 @@ public function thePromotionShouldBeAvailableToUseOnlyTimes(PromotionInterface $ */ public function iSetItAsExclusive(): void { - /** @var CreatePageInterface|UpdatePageInterface $currentPage */ - $currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]); - - $currentPage->makeExclusive(); + $this->formElement->makeExclusive(); } /** @@ -414,16 +408,13 @@ public function iSetItAsExclusive(): void */ public function iSetItAsNotAppliesToDiscountedByCatalogPromotionItems(): void { - /** @var CreatePageInterface|UpdatePageInterface $currentPage */ - $currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]); - - $currentPage->makeNotAppliesToDiscountedItem(); + $this->formElement->makeNotAppliesToDiscountedItem(); } /** * @Then the :promotion promotion should be exclusive */ - public function thePromotionShouldBeExclusive(PromotionInterface $promotion) + public function thePromotionShouldBeExclusive(PromotionInterface $promotion): void { $this->assertIfFieldIsTrue($promotion, 'exclusive'); } @@ -441,16 +432,13 @@ public function thePromotionShouldNotAppliesToDiscountedItems(PromotionInterface */ public function iMakeItCouponBased(): void { - /** @var CreatePageInterface|UpdatePageInterface $currentPage */ - $currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]); - - $currentPage->makeCouponBased(); + $this->formElement->makeCouponBased(); } /** * @Then the :promotion promotion should be coupon based */ - public function thePromotionShouldBeCouponBased(PromotionInterface $promotion) + public function thePromotionShouldBeCouponBased(PromotionInterface $promotion): void { $this->assertIfFieldIsTrue($promotion, 'coupon_based'); } @@ -458,18 +446,15 @@ public function thePromotionShouldBeCouponBased(PromotionInterface $promotion) /** * @When I make it applicable for the :channelName channel */ - public function iMakeItApplicableForTheChannel($channelName) + public function iMakeItApplicableForTheChannel(string $channelName): void { - /** @var CreatePageInterface|UpdatePageInterface $currentPage */ - $currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]); - - $currentPage->checkChannel($channelName); + $this->formElement->checkChannel($channelName); } /** * @Then the :promotion promotion should be applicable for the :channelName channel */ - public function thePromotionShouldBeApplicableForTheChannel(PromotionInterface $promotion, $channelName) + public function thePromotionShouldBeApplicableForTheChannel(PromotionInterface $promotion, string $channelName): void { $this->iWantToModifyAPromotion($promotion); @@ -549,13 +534,10 @@ public function iShouldBeNotifiedOfFailure() /** * @When I make it available from :startsDate to :endsDate */ - public function iMakeItAvailableFromTo(\DateTimeInterface $startsDate, \DateTimeInterface $endsDate) + public function iMakeItAvailableFromTo(\DateTimeInterface $startsDate, \DateTimeInterface $endsDate): void { - /** @var CreatePageInterface|UpdatePageInterface $currentPage */ - $currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]); - - $currentPage->setStartsAt($startsDate); - $currentPage->setEndsAt($endsDate); + $this->formElement->setStartsAt($startsDate); + $this->formElement->setEndsAt($endsDate); } /** @@ -566,7 +548,6 @@ public function thePromotionShouldBeAvailableFromTo(PromotionInterface $promotio $this->iWantToModifyAPromotion($promotion); Assert::true($this->updatePage->hasStartsAt($startsDate)); - Assert::true($this->updatePage->hasEndsAt($endsDate)); } @@ -584,7 +565,7 @@ public function iShouldBeNotifiedThatPromotionCannotEndBeforeItsEvenStarts(): vo /** * @Then I should be notified that this value should not be blank */ - public function iShouldBeNotifiedThatThisValueShouldNotBeBlank() + public function iShouldBeNotifiedThatThisValueShouldNotBeBlank(): void { Assert::same( $this->createPage->getValidationMessageForAction(), diff --git a/src/Sylius/Behat/Element/Admin/Promotion/FormElement.php b/src/Sylius/Behat/Element/Admin/Promotion/FormElement.php index dd24b30e41a..5f8f2e271cc 100644 --- a/src/Sylius/Behat/Element/Admin/Promotion/FormElement.php +++ b/src/Sylius/Behat/Element/Admin/Promotion/FormElement.php @@ -22,10 +22,72 @@ public function prioritizeIt(?int $priority): void $this->getElement('priority')->setValue($priority); } + public function setStartsAt(\DateTimeInterface $dateTime): void + { + $timestamp = $dateTime->getTimestamp(); + + $this->getElement('starts_at_date')->setValue(date('Y-m-d', $timestamp)); + $this->getElement('starts_at_time')->setValue(date('H:i', $timestamp)); + } + + public function setEndsAt(\DateTimeInterface $dateTime): void + { + $timestamp = $dateTime->getTimestamp(); + + $this->getElement('ends_at_date')->setValue(date('Y-m-d', $timestamp)); + $this->getElement('ends_at_time')->setValue(date('H:i', $timestamp)); + } + + public function setUsageLimit(int $limit): void + { + $this->getElement('usage_limit')->setValue($limit); + } + + public function makeExclusive(): void + { + $this->getElement('exclusive')->check(); + } + + public function makeNotAppliesToDiscountedItem(): void + { + $this->getElement('applies_to_discounted')->uncheck(); + } + + public function makeCouponBased(): void + { + $this->getElement('coupon_based')->check(); + } + + public function checkChannel(string $name): void + { + $this->getElement('channels')->checkField($name); + } + + public function setLabel(string $label, string $localeCode): void + { + $this->getElement('label', ['%locale_code%' => $localeCode])->setValue($label); + } + + public function hasLabel(string $label, string $localeCode): bool + { + return $label === $this->getElement('label', ['%locale_code%' => $localeCode])->getValue(); + } + protected function getDefinedElements(): array { return array_merge(parent::getDefinedElements(), [ + 'applies_to_discounted' => '#sylius_promotion_appliesToDiscounted', + 'channels' => '#sylius_promotion_channels', + 'coupon_based' => '#sylius_promotion_couponBased', + 'ends_at_date' => '#sylius_promotion_endsAt_date', + 'ends_at_time' => '#sylius_promotion_endsAt_time', + 'exclusive' => '#sylius_promotion_exclusive', + 'label' => '[name="sylius_promotion[translations][%locale_code%][label]"]', + 'name' => '#sylius_promotion_name', 'priority' => '#sylius_promotion_priority', + 'usage_limit' => '#sylius_promotion_usageLimit', + 'starts_at_date' => '#sylius_promotion_startsAt_date', + 'starts_at_time' => '#sylius_promotion_startsAt_time', ]); } } diff --git a/src/Sylius/Behat/Element/Admin/Promotion/FormElementInterface.php b/src/Sylius/Behat/Element/Admin/Promotion/FormElementInterface.php index 55c792c454e..25fa750d2d8 100644 --- a/src/Sylius/Behat/Element/Admin/Promotion/FormElementInterface.php +++ b/src/Sylius/Behat/Element/Admin/Promotion/FormElementInterface.php @@ -16,4 +16,22 @@ interface FormElementInterface { public function prioritizeIt(?int $priority): void; + + public function setStartsAt(\DateTimeInterface $dateTime): void; + + public function setEndsAt(\DateTimeInterface $dateTime): void; + + public function setUsageLimit(int $limit): void; + + public function makeExclusive(): void; + + public function makeNotAppliesToDiscountedItem(): void; + + public function makeCouponBased(): void; + + public function checkChannel(string $name): void; + + public function setLabel(string $label, string $localeCode): void; + + public function hasLabel(string $label, string $localeCode): bool; } diff --git a/src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php b/src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php index 2e6d913e451..76079572f26 100644 --- a/src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php +++ b/src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php @@ -24,7 +24,6 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface { - use FormTrait; use NamesIt; use SpecifiesItsField; @@ -149,7 +148,7 @@ public function checkIfActionConfigurationFormIsVisible(): bool protected function getDefinedElements(): array { - return array_merge(parent::getDefinedElements(), $this->getDefinedFormElements(), [ + return array_merge(parent::getDefinedElements(), [ 'actions' => '#sylius_promotion_actions', 'code' => '#sylius_promotion_code', 'minimum' => '#sylius_promotion_actions_0_configuration_WEB-US_filters_price_range_filter_min', diff --git a/src/Sylius/Behat/Page/Admin/Promotion/CreatePageInterface.php b/src/Sylius/Behat/Page/Admin/Promotion/CreatePageInterface.php index 5e46918ea17..c475a857610 100644 --- a/src/Sylius/Behat/Page/Admin/Promotion/CreatePageInterface.php +++ b/src/Sylius/Behat/Page/Admin/Promotion/CreatePageInterface.php @@ -16,7 +16,7 @@ use Behat\Mink\Exception\ElementNotFoundException; use Sylius\Behat\Page\Admin\Crud\CreatePageInterface as BaseCreatePageInterface; -interface CreatePageInterface extends BaseCreatePageInterface, FormAwareInterface +interface CreatePageInterface extends BaseCreatePageInterface { public function specifyCode(string $code): void; diff --git a/src/Sylius/Behat/Page/Admin/Promotion/FormAwareInterface.php b/src/Sylius/Behat/Page/Admin/Promotion/FormAwareInterface.php deleted file mode 100644 index 3de8e43679a..00000000000 --- a/src/Sylius/Behat/Page/Admin/Promotion/FormAwareInterface.php +++ /dev/null @@ -1,26 +0,0 @@ -getTimestamp(); - - $this->getElement('starts_at_date')->setValue(date('Y-m-d', $timestamp)); - $this->getElement('starts_at_time')->setValue(date('H:i', $timestamp)); - } - - public function setEndsAt(\DateTimeInterface $dateTime): void - { - $timestamp = $dateTime->getTimestamp(); - - $this->getElement('ends_at_date')->setValue(date('Y-m-d', $timestamp)); - $this->getElement('ends_at_time')->setValue(date('H:i', $timestamp)); - } - - public function setUsageLimit(int $limit): void - { - $this->getElement('usage_limit')->setValue($limit); - } - - public function makeExclusive(): void - { - $this->getElement('exclusive')->check(); - } - - public function makeNotAppliesToDiscountedItem(): void - { - $this->getElement('applies_to_discounted')->uncheck(); - } - - public function makeCouponBased(): void - { - $this->getElement('coupon_based')->check(); - } - - public function checkChannel(string $name): void - { - $this->getElement('channels')->checkField($name); - } - - public function specifyLabel(string $label, string $localeCode): void - { - $this->getElement('label', ['%locale_code%' => $localeCode])->setValue($label); - } - - public function hasLabel(string $label, string $localeCode): bool - { - return $label === $this->getElement('label', ['%locale_code%' => $localeCode])->getValue(); - } - - /** @return array */ - protected function getDefinedFormElements(): array - { - return [ - 'channels' => '#sylius_promotion_channels', - 'applies_to_discounted' => '#sylius_promotion_appliesToDiscounted', - 'coupon_based' => '#sylius_promotion_couponBased', - 'ends_at_date' => '#sylius_promotion_endsAt_date', - 'ends_at_time' => '#sylius_promotion_endsAt_time', - 'exclusive' => '#sylius_promotion_exclusive', - 'label' => '[name="sylius_promotion[translations][%locale_code%][label]"]', - 'name' => '#sylius_promotion_name', - 'usage_limit' => '#sylius_promotion_usageLimit', - 'starts_at_date' => '#sylius_promotion_startsAt_date', - 'starts_at_time' => '#sylius_promotion_startsAt_time', - ]; - } -} diff --git a/src/Sylius/Behat/Page/Admin/Promotion/UpdatePage.php b/src/Sylius/Behat/Page/Admin/Promotion/UpdatePage.php index 2145f55f690..a5f2cd459a9 100644 --- a/src/Sylius/Behat/Page/Admin/Promotion/UpdatePage.php +++ b/src/Sylius/Behat/Page/Admin/Promotion/UpdatePage.php @@ -24,7 +24,6 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface { use ChecksCodeImmutability; use CountsChannelBasedErrors; - use FormTrait; use NamesIt; public function setPriority(?int $priority): void @@ -154,19 +153,23 @@ protected function getCodeElement(): NodeElement protected function getDefinedElements(): array { - return array_merge(parent::getDefinedElements(), $this->getDefinedFormElements(), [ + return array_merge(parent::getDefinedElements(), [ 'action_field' => '[id^="sylius_promotion_actions_"][id$="_configuration_%channelCode%_%field%"]', 'actions' => '#actions', + 'applies_to_discounted' => '#sylius_promotion_appliesToDiscounted', 'code' => '#sylius_promotion_code', 'ends_at' => '#sylius_promotion_endsAt', 'ends_at_date' => '#sylius_promotion_endsAt_date', 'ends_at_time' => '#sylius_promotion_endsAt_time', + 'exclusive' => '#sylius_promotion_exclusive', + 'coupon_based' => '#sylius_promotion_couponBased', 'label' => '#sylius_promotion_translations_%localeCode%_label', 'name' => '#sylius_promotion_name', 'order_percentage_action_field' => '[id^="sylius_promotion_actions_"][id$="_configuration_percentage"]', 'priority' => '#sylius_promotion_priority', 'rule_amount' => '[id^="sylius_promotion_rules_"][id$="_configuration_%channelCode%_amount"]', 'rules' => '#rules', + 'usage_limit' => '#sylius_promotion_usageLimit', 'starts_at' => '#sylius_promotion_startsAt', 'starts_at_date' => '#sylius_promotion_startsAt_date', 'starts_at_time' => '#sylius_promotion_startsAt_time', diff --git a/src/Sylius/Behat/Page/Admin/Promotion/UpdatePageInterface.php b/src/Sylius/Behat/Page/Admin/Promotion/UpdatePageInterface.php index e574b968008..9bb33a99da4 100644 --- a/src/Sylius/Behat/Page/Admin/Promotion/UpdatePageInterface.php +++ b/src/Sylius/Behat/Page/Admin/Promotion/UpdatePageInterface.php @@ -16,7 +16,7 @@ use Behat\Mink\Exception\ElementNotFoundException; use Sylius\Behat\Page\Admin\Crud\UpdatePageInterface as BaseUpdatePageInterface; -interface UpdatePageInterface extends BaseUpdatePageInterface, FormAwareInterface +interface UpdatePageInterface extends BaseUpdatePageInterface { public function setPriority(?int $priority): void; From 66bc58e6454b7da51857f27d5c63aa5f7aa9eee2 Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Wed, 10 Apr 2024 07:17:02 +0200 Subject: [PATCH 12/39] [Admin] Improve appearance of channel based promotion rules and actions --- .../views/Shared/form_theme.html.twig | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/form_theme.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/form_theme.html.twig index 535cd24d411..0f9492112ef 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/form_theme.html.twig +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/form_theme.html.twig @@ -24,3 +24,33 @@ {{- form_errors(form) -}}
{% endblock %} + +{% block sylius_channel_collection_row %} + +
+ +
+
+
+ {% for channelCode, channelConfiguration in form %} +
+ {{ form_row(channelConfiguration, {'label': false}) }} +
+ {% endfor %} +
+
+
+{% endblock %} From 891a998710ff5b696a8a26ac7dd156ab2e432000 Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Wed, 10 Apr 2024 11:34:28 +0200 Subject: [PATCH 13/39] [Behat][Admin] Cover scenarios for adding promotion with action --- .../adding_promotion_with_action.feature | 4 +- ..._with_action_in_different_channels.feature | 2 +- .../Ui/Admin/ManagingPromotionsContext.php | 26 ++++---- .../Element/Admin/Promotion/FormElement.php | 61 +++++++++++++++++++ .../Admin/Promotion/FormElementInterface.php | 8 +++ .../Behat/Page/Admin/Promotion/CreatePage.php | 42 +------------ .../Admin/Promotion/CreatePageInterface.php | 16 +---- src/Sylius/Behat/Service/TabsHelper.php | 4 +- .../views/Shared/form_theme.html.twig | 13 +++- 9 files changed, 102 insertions(+), 74 deletions(-) diff --git a/features/admin/promotion/managing_promotions/adding_promotion_with_action.feature b/features/admin/promotion/managing_promotions/adding_promotion_with_action.feature index 576b564e378..9aed8f50609 100644 --- a/features/admin/promotion/managing_promotions/adding_promotion_with_action.feature +++ b/features/admin/promotion/managing_promotions/adding_promotion_with_action.feature @@ -8,7 +8,7 @@ Feature: Adding a new promotion with action Given the store operates on a single channel in "United States" And I am logged in as an administrator - @api @todo @ui @javascript + @api @ui @javascript Scenario: Adding a new promotion with fixed discount When I want to create a new promotion And I specify its code as "10_for_all_products" @@ -18,7 +18,7 @@ Feature: Adding a new promotion with action Then I should be notified that it has been successfully created And the "$10.00 for all products!" promotion should appear in the registry - @api @todo @ui @javascript + @api @ui @javascript Scenario: Adding a promotion with item percentage discount When I want to create a new promotion And I specify its code as "promotion_for_all_product_items" diff --git a/features/admin/promotion/managing_promotions/adding_promotion_with_action_in_different_channels.feature b/features/admin/promotion/managing_promotions/adding_promotion_with_action_in_different_channels.feature index 4574ee79767..97e62b3376b 100644 --- a/features/admin/promotion/managing_promotions/adding_promotion_with_action_in_different_channels.feature +++ b/features/admin/promotion/managing_promotions/adding_promotion_with_action_in_different_channels.feature @@ -9,7 +9,7 @@ Feature: Adding a new promotion with action configured in different channels And the store also operates on another channel named "Web-GB" in "GBP" currency And I am logged in as an administrator - @todo @ui @mink:chromedriver @api + @ui @javascript @api Scenario: Adding a new promotion with item fixed discount When I want to create a new promotion And I specify its code as "20_for_all_products" diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php index b8fe0abfc9d..b5d159fbee7 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php @@ -178,8 +178,8 @@ public function iAddTheItemTotalRuleConfiguredWithTwoChannel( */ public function iAddTheActionConfiguredWithAmountForChannel($actionType, $amount, ChannelInterface $channel) { - $this->createPage->addAction($actionType); - $this->createPage->fillActionOptionForChannel($channel->getCode(), 'Amount', $amount); + $this->formElement->addAction($actionType); + $this->formElement->fillActionOptionForChannel($channel->getCode(), 'Amount', $amount); } /** @@ -187,7 +187,7 @@ public function iAddTheActionConfiguredWithAmountForChannel($actionType, $amount */ public function itIsConfiguredWithAmountForChannel($amount, ChannelInterface $channel) { - $this->createPage->fillActionOptionForChannel($channel->getCode(), 'Amount', $amount); + $this->formElement->fillActionOptionForChannel($channel->getCode(), 'Amount', $amount); } /** @@ -195,7 +195,7 @@ public function itIsConfiguredWithAmountForChannel($amount, ChannelInterface $ch */ public function iAddAMinPriceFilterRangeForChannel(ChannelInterface $channel, $minimum) { - $this->createPage->fillActionOptionForChannel($channel->getCode(), 'Min', $minimum); + $this->formElement->fillActionOptionForChannel($channel->getCode(), 'Min', $minimum); } /** @@ -203,7 +203,7 @@ public function iAddAMinPriceFilterRangeForChannel(ChannelInterface $channel, $m */ public function iAddAMaxPriceFilterRangeForChannel(ChannelInterface $channel, $maximum) { - $this->createPage->fillActionOptionForChannel($channel->getCode(), 'Max', $maximum); + $this->formElement->fillActionOptionForChannel($channel->getCode(), 'Max', $maximum); } /** @@ -231,8 +231,8 @@ public function iAddTheActionConfiguredWithAPercentageValueForChannel( string $percentage, ChannelInterface $channel, ): void { - $this->createPage->addAction($actionType); - $this->createPage->fillActionOptionForChannel($channel->getCode(), 'Percentage', $percentage); + $this->formElement->addAction($actionType); + $this->formElement->fillActionOptionForChannel($channel->getCode(), 'Percentage', $percentage); } /** @@ -242,8 +242,8 @@ public function iAddTheActionConfiguredWithoutAPercentageValueForChannel( string $actionType, ChannelInterface $channel, ): void { - $this->createPage->addAction($actionType); - $this->createPage->fillActionOptionForChannel($channel->getCode(), 'Percentage', ''); + $this->formElement->addAction($actionType); + $this->formElement->fillActionOptionForChannel($channel->getCode(), 'Percentage', ''); } /** @@ -252,8 +252,8 @@ public function iAddTheActionConfiguredWithoutAPercentageValueForChannel( */ public function iAddTheActionConfiguredWithAPercentageValue($actionType, $percentage = null) { - $this->createPage->addAction($actionType); - $this->createPage->fillActionOption('Percentage', $percentage ?? ''); + $this->formElement->addAction($actionType); + $this->formElement->fillActionOption('Percentage', $percentage ?? ''); } /** @@ -746,9 +746,9 @@ public function iAddANewRule() /** * @When I add a new action */ - public function iAddANewAction() + public function iAddANewAction(): void { - $this->createPage->addAction(null); + $this->formElement->addAction(null); } /** diff --git a/src/Sylius/Behat/Element/Admin/Promotion/FormElement.php b/src/Sylius/Behat/Element/Admin/Promotion/FormElement.php index 5f8f2e271cc..d78862e3aef 100644 --- a/src/Sylius/Behat/Element/Admin/Promotion/FormElement.php +++ b/src/Sylius/Behat/Element/Admin/Promotion/FormElement.php @@ -13,7 +13,10 @@ namespace Sylius\Behat\Element\Admin\Promotion; +use Behat\Mink\Element\NodeElement; use FriendsOfBehat\PageObjectExtension\Element\Element; +use Sylius\Behat\Service\TabsHelper; +use Webmozart\Assert\Assert; final class FormElement extends Element implements FormElementInterface { @@ -73,15 +76,45 @@ public function hasLabel(string $label, string $localeCode): bool return $label === $this->getElement('label', ['%locale_code%' => $localeCode])->getValue(); } + public function addAction(?string $actionName): void + { + $this->getElement('add_action_button')->press(); + $this->waitForFormUpdate(); + + if (null !== $actionName) { + $this->selectActionOption('Type', $actionName); + $this->waitForFormUpdate(); + } + } + + public function fillActionOption(string $option, string $value): void + { + $this->getLastAction()->fillField($option, $value); + } + + public function fillActionOptionForChannel(string $channelCode, string $option, string $value): void + { + $lastAction = $this->getChannelConfigurationOfLastAction($channelCode); + $lastAction->fillField($option, $value); + } + + public function selectActionOption(string $option, string $value, bool $multiple = false): void + { + $this->getLastAction()->find('named', ['select', $option])->selectOption($value, $multiple); + } + protected function getDefinedElements(): array { return array_merge(parent::getDefinedElements(), [ + 'actions' => '#sylius_promotion_actions', + 'add_action_button' => '#sylius_promotion_actions_add', 'applies_to_discounted' => '#sylius_promotion_appliesToDiscounted', 'channels' => '#sylius_promotion_channels', 'coupon_based' => '#sylius_promotion_couponBased', 'ends_at_date' => '#sylius_promotion_endsAt_date', 'ends_at_time' => '#sylius_promotion_endsAt_time', 'exclusive' => '#sylius_promotion_exclusive', + 'form' => '[data-live-name-value="SyliusAdmin.Promotion.Form"]', 'label' => '[name="sylius_promotion[translations][%locale_code%][label]"]', 'name' => '#sylius_promotion_name', 'priority' => '#sylius_promotion_priority', @@ -90,4 +123,32 @@ protected function getDefinedElements(): array 'starts_at_time' => '#sylius_promotion_startsAt_time', ]); } + + private function getLastAction(): NodeElement + { + $items = $this->getElement('actions')->findAll('css', '[data-test-promotion-action]'); + Assert::notEmpty($items); + + return end($items); + } + + private function getChannelConfigurationOfLastAction(string $channelCode): NodeElement + { + $lastAction = $this->getLastAction(); + + TabsHelper::switchTab($this->getSession(), $lastAction, $channelCode); + + return $lastAction + ->find('css', sprintf('[id^="sylius_promotion_actions_"][id$="_configuration_%s"]', $channelCode)) + ; + } + + private function waitForFormUpdate(): void + { + $form = $this->getElement('form'); + sleep(1); // we need to sleep, as sometimes the check below is executed faster than the form sets the busy attribute + $form->waitFor(1500, function () use ($form) { + return !$form->hasAttribute('busy'); + }); + } } diff --git a/src/Sylius/Behat/Element/Admin/Promotion/FormElementInterface.php b/src/Sylius/Behat/Element/Admin/Promotion/FormElementInterface.php index 25fa750d2d8..075b2ee7b85 100644 --- a/src/Sylius/Behat/Element/Admin/Promotion/FormElementInterface.php +++ b/src/Sylius/Behat/Element/Admin/Promotion/FormElementInterface.php @@ -34,4 +34,12 @@ public function checkChannel(string $name): void; public function setLabel(string $label, string $localeCode): void; public function hasLabel(string $label, string $localeCode): bool; + + public function addAction(?string $actionName): void; + + public function fillActionOption(string $option, string $value): void; + + public function fillActionOptionForChannel(string $channelCode, string $option, string $value): void; + + public function selectActionOption(string $option, string $value, bool $multiple = false): void; } diff --git a/src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php b/src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php index 76079572f26..be746380f58 100644 --- a/src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php +++ b/src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php @@ -75,35 +75,6 @@ public function fillRuleOptionForChannel(string $channelCode, string $option, st $lastAction->fillField($option, $value); } - public function addAction(?string $actionName): void - { - $count = count($this->getCollectionItems('actions')); - - $this->getDocument()->clickLink('Add action'); - - $this->getDocument()->waitFor(5, fn () => $count + 1 === count($this->getCollectionItems('actions'))); - - if (null !== $actionName) { - $this->selectActionOption('Type', $actionName); - } - } - - public function selectActionOption(string $option, string $value, bool $multiple = false): void - { - $this->getLastCollectionItem('actions')->find('named', ['select', $option])->selectOption($value, $multiple); - } - - public function fillActionOption(string $option, string $value): void - { - $this->getLastCollectionItem('actions')->fillField($option, $value); - } - - public function fillActionOptionForChannel(string $channelCode, string $option, string $value): void - { - $lastAction = $this->getChannelConfigurationOfLastAction($channelCode); - $lastAction->fillField($option, $value); - } - public function getValidationMessageForAction(): string { @@ -149,8 +120,8 @@ public function checkIfActionConfigurationFormIsVisible(): bool protected function getDefinedElements(): array { return array_merge(parent::getDefinedElements(), [ - 'actions' => '#sylius_promotion_actions', 'code' => '#sylius_promotion_code', + 'form' => '[data-live-name-value="SyliusAdmin.Promotion.Form"]', 'minimum' => '#sylius_promotion_actions_0_configuration_WEB-US_filters_price_range_filter_min', 'maximum' => '#sylius_promotion_actions_0_configuration_WEB-US_filters_price_range_filter_max', 'rules' => '#sylius_promotion_rules', @@ -159,17 +130,6 @@ protected function getDefinedElements(): array ]); } - private function getChannelConfigurationOfLastAction(string $channelCode): NodeElement - { - $lastAction = $this->getLastCollectionItem('actions'); - - TabsHelper::switchTab($this->getSession(), $lastAction, $channelCode); - - return $lastAction - ->find('css', sprintf('[id^="sylius_promotion_actions_"][id$="_configuration_%s"]', $channelCode)) - ; - } - private function getChannelConfigurationOfLastRule(string $channelCode): NodeElement { $lastRule = $this->getLastCollectionItem('rules'); diff --git a/src/Sylius/Behat/Page/Admin/Promotion/CreatePageInterface.php b/src/Sylius/Behat/Page/Admin/Promotion/CreatePageInterface.php index c475a857610..6ec26353f31 100644 --- a/src/Sylius/Behat/Page/Admin/Promotion/CreatePageInterface.php +++ b/src/Sylius/Behat/Page/Admin/Promotion/CreatePageInterface.php @@ -35,22 +35,10 @@ public function fillRuleOption(string $option, string $value): void; public function fillRuleOptionForChannel(string $channelCode, string $option, string $value): void; - public function addAction(?string $actionName): void; - - public function selectActionOption(string $option, string $value, bool $multiple = false): void; - - public function fillActionOption(string $option, string $value): void; - - public function fillActionOptionForChannel(string $channelCode, string $option, string $value): void; - - /** - * @throws ElementNotFoundException - */ + /** @throws ElementNotFoundException */ public function getValidationMessageForAction(): string; - /** - * @param string|string[] $value - */ + /** @param string|string[] $value */ public function selectAutoCompleteFilterOption(string $option, array|string $value, bool $multiple = false): void; public function checkIfRuleConfigurationFormIsVisible(): bool; diff --git a/src/Sylius/Behat/Service/TabsHelper.php b/src/Sylius/Behat/Service/TabsHelper.php index 8adf746d2b9..b6dfa1640ed 100644 --- a/src/Sylius/Behat/Service/TabsHelper.php +++ b/src/Sylius/Behat/Service/TabsHelper.php @@ -27,14 +27,14 @@ public static function switchTab(Session $session, NodeElement $tabsContainer, s return; } - $tab = $tabsContainer->find('css', sprintf('.item[data-tab*="%s"]', $dataTabHook)); + $tab = $tabsContainer->find('css', sprintf('[data-test-tab*="%s"]', $dataTabHook)); if ($tab->hasClass('active')) { return; } $tab->click(); - $tabContent = $tabsContainer->find('css', sprintf('.tab[data-tab*="%s"]', $dataTabHook)); + $tabContent = $tabsContainer->find('css', sprintf('#%s', $dataTabHook)); $session->getPage()->waitFor(5, fn () => $tabContent->isVisible()); } diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/form_theme.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/form_theme.html.twig index 0f9492112ef..823aa4a9ab9 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/form_theme.html.twig +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/form_theme.html.twig @@ -25,6 +25,16 @@
{% endblock %} +{% block sylius_promotion_action_row %} + +
+ {{- form_label(form) -}} + {{- form_widget(form) -}} + {{- form_errors(form) -}} +
+
+{% endblock %} + {% block sylius_channel_collection_row %}
@@ -36,6 +46,7 @@ data-bs-toggle="tab" href="#{{ channelCode }}" role="tab" + {{ sylius_test_html_attribute('tab', channelCode) }} > {{ channelConfiguration.vars.label }} @@ -47,7 +58,7 @@
{% for channelCode, channelConfiguration in form %}
- {{ form_row(channelConfiguration, {'label': false}) }} + {{ form_row(channelConfiguration, sylius_test_form_attribute('tab-content')|merge({'label': false})) }}
{% endfor %}
From edb3e077fdb7d452f5faf5adb65803dd4f8738a0 Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Wed, 10 Apr 2024 13:11:05 +0200 Subject: [PATCH 14/39] [Behat][Admin] Enable preventing deletion of promotion scenario --- .../preventing_deletion_of_promotions_in_use.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/admin/promotion/managing_promotions/preventing_deletion_of_promotions_in_use.feature b/features/admin/promotion/managing_promotions/preventing_deletion_of_promotions_in_use.feature index bbe9656b046..44250833742 100644 --- a/features/admin/promotion/managing_promotions/preventing_deletion_of_promotions_in_use.feature +++ b/features/admin/promotion/managing_promotions/preventing_deletion_of_promotions_in_use.feature @@ -16,7 +16,7 @@ Feature: Prevent deletion of promotions applied to order And the customer chose "Free" shipping method to "United States" with "Cash on Delivery" payment And I am logged in as an administrator - @api @todo @ui + @api @ui Scenario: Being unable to delete a promotion that was applied to an order When I try to delete a "Christmas sale" promotion Then I should be notified that it is in use and cannot be deleted From d9892172e0bbc799a291530112ccf31da5a26c07 Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Wed, 10 Apr 2024 13:39:30 +0200 Subject: [PATCH 15/39] [Behat] Improve AutocompleteHelper to allow to select by name or by value --- .../Autocompleter/TaxonAutocompleter.php | 2 +- .../Form/Field/ProductAutocompleteField.php | 44 ------------------- 2 files changed, 1 insertion(+), 45 deletions(-) delete mode 100644 src/Sylius/Bundle/AdminBundle/Form/Field/ProductAutocompleteField.php diff --git a/src/Sylius/Bundle/AdminBundle/Autocompleter/TaxonAutocompleter.php b/src/Sylius/Bundle/AdminBundle/Autocompleter/TaxonAutocompleter.php index 8ccc9b868b4..4d247b79ffc 100644 --- a/src/Sylius/Bundle/AdminBundle/Autocompleter/TaxonAutocompleter.php +++ b/src/Sylius/Bundle/AdminBundle/Autocompleter/TaxonAutocompleter.php @@ -38,7 +38,7 @@ public function createFilteredQueryBuilder(EntityRepository $repository, string public function getLabel(object $entity): string { - return $entity->getFullName(); + return $entity->getFullname(); } public function getValue(object $entity): mixed diff --git a/src/Sylius/Bundle/AdminBundle/Form/Field/ProductAutocompleteField.php b/src/Sylius/Bundle/AdminBundle/Form/Field/ProductAutocompleteField.php deleted file mode 100644 index 81cd9184e55..00000000000 --- a/src/Sylius/Bundle/AdminBundle/Form/Field/ProductAutocompleteField.php +++ /dev/null @@ -1,44 +0,0 @@ -setDefaults([ - 'class' => Food::class, - 'placeholder' => 'What should we eat?', - - // choose which fields to use in the search - // if not passed, *all* fields are used - //'searchable_fields' => ['name'], - - // if the autocomplete endpoint needs to be secured - //'security' => 'ROLE_FOOD_ADMIN', - - // ... any other normal EntityType options - // e.g. query_builder, choice_label - ]); - } - - public function getParent(): string - { - return BaseEntityAutocompleteType::class; - } -} From 2f749b628cbb502484d86597ad6dc97606801056 Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Wed, 10 Apr 2024 18:36:43 +0200 Subject: [PATCH 16/39] [Behat][Admin] Cover scenarios for adding promotion with rules and actions filters --- .../adding_promotion_with_filter.feature | 24 ++-- .../adding_promotion_with_rule.feature | 10 +- ...on_with_rule_in_different_channels.feature | 2 +- .../Api/Admin/ManagingPromotionsContext.php | 22 ++-- .../Ui/Admin/ManagingPromotionsContext.php | 42 +++---- .../Element/Admin/Promotion/FormElement.php | 118 ++++++++++++++++++ .../Admin/Promotion/FormElementInterface.php | 14 +++ .../Behat/Page/Admin/Crud/CreatePage.php | 30 ----- .../Page/Admin/Crud/CreatePageInterface.php | 5 - .../Behat/Page/Admin/Promotion/CreatePage.php | 81 ------------ .../Admin/Promotion/CreatePageInterface.php | 16 --- .../config/services/elements/admin.xml | 4 +- .../views/Shared/form_theme.html.twig | 10 ++ 13 files changed, 196 insertions(+), 182 deletions(-) diff --git a/features/admin/promotion/managing_promotions/adding_promotion_with_filter.feature b/features/admin/promotion/managing_promotions/adding_promotion_with_filter.feature index 8ab12d48539..fcbb7732d90 100644 --- a/features/admin/promotion/managing_promotions/adding_promotion_with_filter.feature +++ b/features/admin/promotion/managing_promotions/adding_promotion_with_filter.feature @@ -8,7 +8,7 @@ Feature: Adding promotion with filter Given the store operates on a single channel in "United States" And I am logged in as an administrator - @api @todo @ui @mink:chromedriver + @api @ui @mink:chromedriver Scenario: Adding a promotion with item fixed discount only for products over 10 When I want to create a new promotion And I specify its code as "10_for_all_products_over_10" @@ -19,7 +19,7 @@ Feature: Adding promotion with filter Then I should be notified that it has been successfully created And the "$10 discount for all products over $10!" promotion should appear in the registry - @api @todo @ui @javascript + @api @ui @javascript Scenario: Adding a promotion with item fixed discount only for products between 10 and 100 When I want to create a new promotion And I specify its code as "10_for_all_products_over_10" @@ -30,31 +30,31 @@ Feature: Adding promotion with filter Then I should be notified that it has been successfully created And the "$10 discount for (almost) all products!" promotion should appear in the registry - @api @todo @ui @javascript + @api @ui @javascript Scenario: Adding a promotion with fixed discount for all t-shirts Given the store classifies its products as "T-Shirts" and "Mugs" When I want to create a new promotion And I specify its code as "10_for_all_t_shirts" And I name it "$10 discount for all T-Shirts!" And I add the "Item fixed discount" action configured with amount of "$10.00" for "United States" channel - And I specify that this action should be applied to items from "T-Shirts" category + And I specify that this action should be applied to items from "T-Shirts" category for "United States" channel And I add it Then I should be notified that it has been successfully created And the "$10 discount for all T-Shirts!" promotion should appear in the registry - @api @todo @ui @javascript + @api @ui @javascript Scenario: Adding a promotion with fixed discount for PHP T-Shirt Given the store has a product "PHP T-Shirt" priced at "$100.00" When I want to create a new promotion And I specify its code as "10_for_php_t_shirt" And I name it "$10 discount for PHP T-Shirts!" And I add the "Item fixed discount" action configured with amount of "$10.00" for "United States" channel - And I specify that this action should be applied to the "PHP T-Shirt" product + And I specify that this action should be applied to the "PHP T-Shirt" product for "United States" channel And I add it Then I should be notified that it has been successfully created And the "$10 discount for PHP T-Shirts!" promotion should appear in the registry - @api @todo @ui @javascript + @api @ui @javascript Scenario: Adding a promotion with item percentage discount only for products over 10 When I want to create a new promotion And I specify its code as "10_for_all_products_over_10" @@ -65,7 +65,7 @@ Feature: Adding promotion with filter Then I should be notified that it has been successfully created And the "$10 discount for all products over $10!" promotion should appear in the registry - @api @todo @ui @javascript + @api @ui @javascript Scenario: Adding a promotion with item percentage discount only for products between 10 and 100 When I want to create a new promotion And I specify its code as "10_for_all_products_over_10" @@ -76,26 +76,26 @@ Feature: Adding promotion with filter Then I should be notified that it has been successfully created And the "$10 discount for (almost) all products!" promotion should appear in the registry - @api @todo @ui @javascript + @api @ui @javascript Scenario: Adding a promotion with 10% percentage discount for all t-shirts Given the store classifies its products as "T-Shirts" and "Mugs" When I want to create a new promotion And I specify its code as "10_for_all_t_shirts" And I name it "$10 discount for all T-Shirts!" And I add the "Item percentage discount" action configured with a percentage value of "10%" for "United States" channel - And I specify that this action should be applied to items from "T-Shirts" category + And I specify that this action should be applied to items from "T-Shirts" category for "United States" channel And I add it Then I should be notified that it has been successfully created And the "$10 discount for all T-Shirts!" promotion should appear in the registry - @api @todo @ui @javascript + @api @ui @javascript Scenario: Adding a promotion with 10% percentage discount for PHP T-Shirt Given the store has a product "PHP T-Shirt" priced at "$100.00" When I want to create a new promotion And I specify its code as "10_for_php_t_shirt" And I name it "10% discount for PHP T-Shirts!" And I add the "Item percentage discount" action configured with a percentage value of "10%" for "United States" channel - And I specify that this action should be applied to the "PHP T-Shirt" product + And I specify that this action should be applied to the "PHP T-Shirt" product for "United States" channel And I add it Then I should be notified that it has been successfully created And the "10% discount for PHP T-Shirts!" promotion should appear in the registry diff --git a/features/admin/promotion/managing_promotions/adding_promotion_with_rule.feature b/features/admin/promotion/managing_promotions/adding_promotion_with_rule.feature index 5582400607f..8014a1e5f19 100644 --- a/features/admin/promotion/managing_promotions/adding_promotion_with_rule.feature +++ b/features/admin/promotion/managing_promotions/adding_promotion_with_rule.feature @@ -9,7 +9,7 @@ Feature: Adding a new promotion with rule And the store classifies its products as "T-Shirts" and "Mugs" And I am logged in as an administrator - @api @todo @ui @javascript + @api @ui @javascript Scenario: Adding a new promotion with taxon rule When I want to create a new promotion And I specify its code as "HOLIDAY_SALE" @@ -19,7 +19,7 @@ Feature: Adding a new promotion with rule Then I should be notified that it has been successfully created And the "Holiday sale" promotion should appear in the registry - @api @todo @ui @javascript + @api @ui @javascript Scenario: Adding a new promotion with total price of items from taxon rule When I want to create a new promotion And I specify its code as "100_MUGS_PROMOTION" @@ -29,7 +29,7 @@ Feature: Adding a new promotion with rule Then I should be notified that it has been successfully created And the "100 Mugs promotion" promotion should appear in the registry - @api @todo @ui @javascript + @api @ui @javascript Scenario: Adding a new promotion with contains product rule Given the store has a product "PHP T-Shirt" priced at "$100.00" When I want to create a new promotion @@ -40,7 +40,7 @@ Feature: Adding a new promotion with rule Then I should be notified that it has been successfully created And the "PHP T-Shirt promotion" promotion should appear in the registry - @api @todo @ui @javascript + @api @ui @javascript Scenario: Adding a new group based promotion Given the store has a customer group "Wholesale" When I want to create a new promotion @@ -51,7 +51,7 @@ Feature: Adding a new promotion with rule Then I should be notified that it has been successfully created And the "Wholesale promotion" promotion should appear in the registry - @todo @ui @javascript @no-api + @ui @javascript @no-api Scenario: Adding a new promotion of default type with one action When I want to create a new promotion And I add a new rule diff --git a/features/admin/promotion/managing_promotions/adding_promotion_with_rule_in_different_channels.feature b/features/admin/promotion/managing_promotions/adding_promotion_with_rule_in_different_channels.feature index ea880f49a1f..144629afd44 100644 --- a/features/admin/promotion/managing_promotions/adding_promotion_with_rule_in_different_channels.feature +++ b/features/admin/promotion/managing_promotions/adding_promotion_with_rule_in_different_channels.feature @@ -9,7 +9,7 @@ Feature: Adding a new promotion with rule configured in different channels And the store operates on a channel named "Web-GB" in "GBP" currency And I am logged in as an administrator - @todo @api @ui @mink:chromedriver + @api @ui @mink:chromedriver Scenario: Adding a new promotion with total price of items from taxon rule When I want to create a new promotion And I specify its code as "100_IN_EVERY_CURRENCY" diff --git a/src/Sylius/Behat/Context/Api/Admin/ManagingPromotionsContext.php b/src/Sylius/Behat/Context/Api/Admin/ManagingPromotionsContext.php index 7e97d2ddfb1..d0b1cd66ba5 100644 --- a/src/Sylius/Behat/Context/Api/Admin/ManagingPromotionsContext.php +++ b/src/Sylius/Behat/Context/Api/Admin/ManagingPromotionsContext.php @@ -321,25 +321,27 @@ public function iAddAMinMaxPriceFilterRangeForChannel(ChannelInterface $channel, } /** - * @When I specify that this action should be applied to items from :taxon category + * @When I specify that this action should be applied to items from :taxon category for :channel channel */ - public function iSpecifyThatThisActionShouldBeAppliedToItemsFromCategory(TaxonInterface $taxon): void - { + public function iSpecifyThatThisActionShouldBeAppliedToItemsFromCategory( + TaxonInterface $taxon, + ChannelInterface $channel, + ): void { $actions = $this->getActions(); - $channelCode = key($actions[0]['configuration']); - $actions[0]['configuration'][$channelCode]['filters']['taxons_filter']['taxons'] = [$taxon->getCode()]; + $actions[0]['configuration'][$channel->getCode()]['filters']['taxons_filter']['taxons'] = [$taxon->getCode()]; $this->client->addRequestData('actions', $actions); } /** - * @When I specify that this action should be applied to the :product product + * @When I specify that this action should be applied to the :product product for :channel channel */ - public function iSpecifyThatThisActionShouldBeAppliedToTheProduct(ProductInterface $product): void - { + public function iSpecifyThatThisActionShouldBeAppliedToTheProduct( + ProductInterface $product, + ChannelInterface $channel, + ): void { $actions = $this->getActions(); - $channelCode = key($actions[0]['configuration']); - $actions[0]['configuration'][$channelCode]['filters']['products_filter']['products'] = [$product->getCode()]; + $actions[0]['configuration'][$channel->getCode()]['filters']['products_filter']['products'] = [$product->getCode()]; $this->client->addRequestData('actions', $actions); } diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php index b5d159fbee7..225bd1ad4c5 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php @@ -144,19 +144,19 @@ public function thePromotionShouldHaveLabelInLocale(PromotionInterface $promotio */ public function iAddTheHasTaxonRuleConfiguredWith(string ...$taxons): void { - $this->createPage->addRule('Has at least one from taxons'); + $this->formElement->addRule('Has at least one from taxons'); - $this->createPage->selectAutocompleteRuleOption('Taxons', $taxons, true); + $this->formElement->selectAutocompleteRuleOptions($taxons); } /** * @When /^I add the "Total price of items from taxon" rule configured with "([^"]+)" taxon and "(?:€|£|\$)([^"]+)" amount for ("[^"]+" channel)$/ */ - public function iAddTheRuleConfiguredWith($taxonName, $amount, ChannelInterface $channel) + public function iAddTheRuleConfiguredWith(string $taxonName, $amount, ChannelInterface $channel): void { - $this->createPage->addRule('Total price of items from taxon'); - $this->createPage->selectAutocompleteRuleOption('Taxon', $taxonName); - $this->createPage->fillRuleOptionForChannel($channel->getCode(), 'Amount', $amount); + $this->formElement->addRule('Total price of items from taxon'); + $this->formElement->selectAutocompleteRuleOptions([$taxonName], $channel->getCode()); + $this->formElement->fillRuleOptionForChannel($channel->getCode(), 'Amount', $amount); } /** @@ -168,9 +168,9 @@ public function iAddTheItemTotalRuleConfiguredWithTwoChannel( $secondAmount, ChannelInterface $secondChannel, ) { - $this->createPage->addRule('Item total'); - $this->createPage->fillRuleOptionForChannel($firstChannel->getCode(), 'Amount', $firstAmount); - $this->createPage->fillRuleOptionForChannel($secondChannel->getCode(), 'Amount', $secondAmount); + $this->formElement->addRule('Item total'); + $this->formElement->fillRuleOptionForChannel($firstChannel->getCode(), 'Amount', $firstAmount); + $this->formElement->fillRuleOptionForChannel($secondChannel->getCode(), 'Amount', $secondAmount); } /** @@ -216,11 +216,11 @@ public function iAddAMinMaxPriceFilterRangeForChannel(ChannelInterface $channel, } /** - * @When I specify that this action should be applied to items from :taxonName category + * @When I specify that this action should be applied to items from :taxonName category for :channel channel */ - public function iSpecifyThatThisActionShouldBeAppliedToItemsFromCategory($taxonName) + public function iSpecifyThatThisActionShouldBeAppliedToItemsFromCategory(string $taxonName, ChannelInterface $channel): void { - $this->createPage->selectAutoCompleteFilterOption('Taxons', $taxonName); + $this->formElement->selectAutocompleteFilterOptions([$taxonName], $channel->getCode(), 'taxons'); } /** @@ -261,8 +261,8 @@ public function iAddTheActionConfiguredWithAPercentageValue($actionType, $percen */ public function iAddTheCustomerGroupRuleConfiguredForGroup($customerGroupName) { - $this->createPage->addRule('Customer group'); - $this->createPage->selectRuleOption('Customer group', $customerGroupName); + $this->formElement->addRule('Customer group'); + $this->formElement->selectRuleOption('Customer group', $customerGroupName); } /** @@ -602,18 +602,18 @@ public function thePromotionShouldBeUsedTime(PromotionInterface $promotion, $usa /** * @When I add the "Contains product" rule configured with the :productName product */ - public function iAddTheRuleConfiguredWithTheProduct($productName) + public function iAddTheRuleConfiguredWithTheProduct(string $productName): void { - $this->createPage->addRule('Contains product'); - $this->createPage->selectAutocompleteRuleOption('Product code', $productName); + $this->formElement->addRule('Contains product'); + $this->formElement->selectAutocompleteRuleOptions([$productName]); } /** - * @When I specify that this action should be applied to the :productName product + * @When I specify that this action should be applied to the :productName product for :channel channel */ - public function iSpecifyThatThisActionShouldBeAppliedToTheProduct($productName) + public function iSpecifyThatThisActionShouldBeAppliedToTheProduct(string $productName, ChannelInterface $channel): void { - $this->createPage->selectAutoCompleteFilterOption('Products', $productName); + $this->formElement->selectAutocompleteFilterOptions([$productName], $channel->getCode(), 'products'); } /** @@ -740,7 +740,7 @@ public function iFilterPromotionsByCouponCodeEqual(string $value): void */ public function iAddANewRule() { - $this->createPage->addRule(null); + $this->formElement->addRule(null); } /** diff --git a/src/Sylius/Behat/Element/Admin/Promotion/FormElement.php b/src/Sylius/Behat/Element/Admin/Promotion/FormElement.php index d78862e3aef..19aa0dbe08b 100644 --- a/src/Sylius/Behat/Element/Admin/Promotion/FormElement.php +++ b/src/Sylius/Behat/Element/Admin/Promotion/FormElement.php @@ -14,12 +14,23 @@ namespace Sylius\Behat\Element\Admin\Promotion; use Behat\Mink\Element\NodeElement; +use Behat\Mink\Exception\ElementNotFoundException; +use Behat\Mink\Session; use FriendsOfBehat\PageObjectExtension\Element\Element; +use Sylius\Behat\Service\Helper\AutocompleteHelperInterface; use Sylius\Behat\Service\TabsHelper; use Webmozart\Assert\Assert; final class FormElement extends Element implements FormElementInterface { + public function __construct( + Session $session, + $minkParameters, + private readonly AutocompleteHelperInterface $autocompleteHelper, + ) { + parent::__construct($session, $minkParameters); + } + public function prioritizeIt(?int $priority): void { $this->getElement('priority')->setValue($priority); @@ -103,11 +114,87 @@ public function selectActionOption(string $option, string $value, bool $multiple $this->getLastAction()->find('named', ['select', $option])->selectOption($value, $multiple); } + public function addRule(?string $ruleName): void + { + $this->getElement('add_rule_button')->press(); + $this->waitForFormUpdate(); + + if (null !== $ruleName) { + $this->selectRuleOption('Type', $ruleName); + $this->waitForFormUpdate(); + } + } + + public function selectRuleOption(string $option, string $value, bool $multiple = false): void + { + $this->getLastRule()->find('named', ['select', $option])->selectOption($value, $multiple); + } + + public function fillRuleOption(string $option, string $value): void + { + $this->getLastRule()->fillField($option, $value); + } + + public function fillRuleOptionForChannel(string $channelCode, string $option, string $value): void + { + $lastRule = $this->getChannelConfigurationOfLastRule($channelCode); + $lastRule->fillField($option, $value); + } + + public function selectAutocompleteRuleOptions(array $values, ?string $channelCode = null): void + { + $count = count($this->getElement('rules')->findAll('css', '[data-test-promotion-rule]')); + $locator = $channelCode ? + sprintf('#sylius_promotion_rules_%d_configuration_%s select', $count - 1, $channelCode) : + sprintf('#sylius_promotion_rules_%d_configuration select', $count - 1) + ; + foreach ($values as $value) { + $this->autocompleteHelper->selectByName( + $this->getDriver(), + $this->getLastRule()->find('css', $locator)->getXpath(), + $value, + ); + } + + $this->waitForFormUpdate(); + } + + public function selectAutocompleteFilterOptions(array $values, string $channelCode, string $filterType): void + { + $count = count($this->getElement('actions')->findAll('css', '[data-test-promotion-action]')); + $locator = sprintf('#sylius_promotion_actions_%d_configuration_%s_filters_%s_filter select', $count - 1, $channelCode, $filterType); + foreach ($values as $value) { + $this->autocompleteHelper->selectByName( + $this->getDriver(), + $this->getLastAction()->find('css', $locator)->getXpath(), + $value, + ); + } + + $this->waitForFormUpdate(); + } + + public function getValidationMessage(string $element): string + { + $foundElement = $this->getFieldElement($element); + if (null === $foundElement) { + throw new ElementNotFoundException($this->getSession(), 'Field element'); + } + + $validationMessage = $foundElement->find('css', '.invalid-feedback'); + if (null === $validationMessage) { + throw new ElementNotFoundException($this->getSession(), 'Validation message', 'css', '.invalid-feedback'); + } + + return $validationMessage->getText(); + } + protected function getDefinedElements(): array { return array_merge(parent::getDefinedElements(), [ 'actions' => '#sylius_promotion_actions', 'add_action_button' => '#sylius_promotion_actions_add', + 'add_rule_button' => '#sylius_promotion_rules_add', 'applies_to_discounted' => '#sylius_promotion_appliesToDiscounted', 'channels' => '#sylius_promotion_channels', 'coupon_based' => '#sylius_promotion_couponBased', @@ -118,6 +205,7 @@ protected function getDefinedElements(): array 'label' => '[name="sylius_promotion[translations][%locale_code%][label]"]', 'name' => '#sylius_promotion_name', 'priority' => '#sylius_promotion_priority', + 'rules' => '#sylius_promotion_rules', 'usage_limit' => '#sylius_promotion_usageLimit', 'starts_at_date' => '#sylius_promotion_startsAt_date', 'starts_at_time' => '#sylius_promotion_startsAt_time', @@ -143,6 +231,36 @@ private function getChannelConfigurationOfLastAction(string $channelCode): NodeE ; } + private function getLastRule(): NodeElement + { + $items = $this->getElement('rules')->findAll('css', '[data-test-promotion-rule]'); + Assert::notEmpty($items); + + return end($items); + } + + private function getChannelConfigurationOfLastRule(string $channelCode): NodeElement + { + $lastRule = $this->getLastRule(); + + TabsHelper::switchTab($this->getSession(), $lastRule, $channelCode); + + return $lastRule + ->find('css', sprintf('[id^="sylius_promotion_rules_"][id$="_configuration_%s"]', $channelCode)) + ; + } + + /** @throws ElementNotFoundException */ + private function getFieldElement(string $element): ?NodeElement + { + $element = $this->getElement($element); + while (null !== $element && !$element->hasClass('field')) { + $element = $element->getParent(); + } + + return $element; + } + private function waitForFormUpdate(): void { $form = $this->getElement('form'); diff --git a/src/Sylius/Behat/Element/Admin/Promotion/FormElementInterface.php b/src/Sylius/Behat/Element/Admin/Promotion/FormElementInterface.php index 075b2ee7b85..10c571d9432 100644 --- a/src/Sylius/Behat/Element/Admin/Promotion/FormElementInterface.php +++ b/src/Sylius/Behat/Element/Admin/Promotion/FormElementInterface.php @@ -42,4 +42,18 @@ public function fillActionOption(string $option, string $value): void; public function fillActionOptionForChannel(string $channelCode, string $option, string $value): void; public function selectActionOption(string $option, string $value, bool $multiple = false): void; + + public function addRule(?string $ruleName): void; + + public function selectRuleOption(string $option, string $value, bool $multiple = false): void; + + public function fillRuleOption(string $option, string $value): void; + + public function fillRuleOptionForChannel(string $channelCode, string $option, string $value): void; + + public function selectAutocompleteRuleOptions(array $values, ?string $channelCode = null): void; + + public function selectAutocompleteFilterOptions(array $values, string $channelCode, string $filterType): void; + + public function getValidationMessage(string $element): string; } diff --git a/src/Sylius/Behat/Page/Admin/Crud/CreatePage.php b/src/Sylius/Behat/Page/Admin/Crud/CreatePage.php index 7b69425e437..dd1772662ca 100644 --- a/src/Sylius/Behat/Page/Admin/Crud/CreatePage.php +++ b/src/Sylius/Behat/Page/Admin/Crud/CreatePage.php @@ -13,9 +13,7 @@ namespace Sylius\Behat\Page\Admin\Crud; -use Behat\Mink\Element\NodeElement; use Behat\Mink\Exception\DriverException; -use Behat\Mink\Exception\ElementNotFoundException; use Behat\Mink\Session; use FriendsOfBehat\PageObjectExtension\Page\SymfonyPage; use FriendsOfBehat\PageObjectExtension\Page\UnexpectedPageException; @@ -37,21 +35,6 @@ public function create(): void $this->getDocument()->pressButton('Create'); } - public function getValidationMessage(string $element): string - { - $foundElement = $this->getFieldElement($element); - if (null === $foundElement) { - throw new ElementNotFoundException($this->getSession(), 'Field element'); - } - - $validationMessage = $foundElement->find('css', '.invalid-feedback'); - if (null === $validationMessage) { - throw new ElementNotFoundException($this->getSession(), 'Validation message', 'css', '.invalid-feedback'); - } - - return $validationMessage->getText(); - } - public function getRouteName(): string { return $this->routeName; @@ -79,17 +62,4 @@ protected function verifyStatusCode(): void throw new UnexpectedPageException($message); } - - /** - * @throws ElementNotFoundException - */ - private function getFieldElement(string $element): ?NodeElement - { - $element = $this->getElement($element); - while (null !== $element && !$element->hasClass('field')) { - $element = $element->getParent(); - } - - return $element; - } } diff --git a/src/Sylius/Behat/Page/Admin/Crud/CreatePageInterface.php b/src/Sylius/Behat/Page/Admin/Crud/CreatePageInterface.php index 35036020b19..a0b762c585e 100644 --- a/src/Sylius/Behat/Page/Admin/Crud/CreatePageInterface.php +++ b/src/Sylius/Behat/Page/Admin/Crud/CreatePageInterface.php @@ -18,11 +18,6 @@ interface CreatePageInterface extends SymfonyPageInterface { - /** - * @throws ElementNotFoundException - */ - public function getValidationMessage(string $element): string; - /** * @throws ElementNotFoundException */ diff --git a/src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php b/src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php index be746380f58..45ebd3ed920 100644 --- a/src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php +++ b/src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php @@ -18,8 +18,6 @@ use Sylius\Behat\Behaviour\NamesIt; use Sylius\Behat\Behaviour\SpecifiesItsField; use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage; -use Sylius\Behat\Service\AutocompleteHelper; -use Sylius\Behat\Service\TabsHelper; use Webmozart\Assert\Assert; class CreatePage extends BaseCreatePage implements CreatePageInterface @@ -27,55 +25,6 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface use NamesIt; use SpecifiesItsField; - public function addRule(?string $ruleName): void - { - $count = count($this->getCollectionItems('rules')); - - $this->getDocument()->clickLink('Add rule'); - - $this->getDocument()->waitFor(5, fn () => $count + 1 === count($this->getCollectionItems('rules'))); - - if (null !== $ruleName) { - $this->selectRuleOption('Type', $ruleName); - } - } - - public function selectRuleOption(string $option, string $value, bool $multiple = false): void - { - $this->getLastCollectionItem('rules')->find('named', ['select', $option])->selectOption($value, $multiple); - } - - public function selectAutocompleteRuleOption(string $option, $value, bool $multiple = false): void - { - $option = strtolower(str_replace(' ', '_', $option)); - - $ruleAutocomplete = $this - ->getLastCollectionItem('rules') - ->find('css', sprintf('input[type="hidden"][name*="[%s]"]', $option)) - ->getParent() - ; - - if ($multiple && is_array($value)) { - AutocompleteHelper::chooseValues($this->getSession(), $ruleAutocomplete, $value); - - return; - } - - AutocompleteHelper::chooseValue($this->getSession(), $ruleAutocomplete, $value); - } - - public function fillRuleOption(string $option, string $value): void - { - $this->getLastCollectionItem('rules')->fillField($option, $value); - } - - public function fillRuleOptionForChannel(string $channelCode, string $option, string $value): void - { - $lastAction = $this->getChannelConfigurationOfLastRule($channelCode); - $lastAction->fillField($option, $value); - } - - public function getValidationMessageForAction(): string { $actionForm = $this->getLastCollectionItem('actions'); @@ -88,25 +37,6 @@ public function getValidationMessageForAction(): string return $foundElement->getText(); } - public function selectAutoCompleteFilterOption(string $option, $value, bool $multiple = false): void - { - $option = strtolower(str_replace(' ', '_', $option)); - - $filterAutocomplete = $this - ->getLastCollectionItem('actions') - ->find('css', sprintf('input[type="hidden"][name*="[%s_filter]"]', $option)) - ->getParent() - ; - - if ($multiple && is_array($value)) { - AutocompleteHelper::chooseValues($this->getSession(), $filterAutocomplete, $value); - - return; - } - - AutocompleteHelper::chooseValue($this->getSession(), $filterAutocomplete, $value); - } - public function checkIfRuleConfigurationFormIsVisible(): bool { return $this->hasElement('count'); @@ -130,17 +60,6 @@ protected function getDefinedElements(): array ]); } - private function getChannelConfigurationOfLastRule(string $channelCode): NodeElement - { - $lastRule = $this->getLastCollectionItem('rules'); - - TabsHelper::switchTab($this->getSession(), $lastRule, $channelCode); - - return $lastRule - ->find('css', sprintf('[id^="sylius_promotion_rules_"][id$="_configuration_%s"]', $channelCode)) - ; - } - private function getLastCollectionItem(string $collection): NodeElement { $items = $this->getCollectionItems($collection); diff --git a/src/Sylius/Behat/Page/Admin/Promotion/CreatePageInterface.php b/src/Sylius/Behat/Page/Admin/Promotion/CreatePageInterface.php index 6ec26353f31..70e2d0844e1 100644 --- a/src/Sylius/Behat/Page/Admin/Promotion/CreatePageInterface.php +++ b/src/Sylius/Behat/Page/Admin/Promotion/CreatePageInterface.php @@ -22,25 +22,9 @@ public function specifyCode(string $code): void; public function nameIt(string $name): void; - public function addRule(?string $ruleName): void; - - public function selectRuleOption(string $option, string $value, bool $multiple = false): void; - - /** - * @param string|string[] $value - */ - public function selectAutocompleteRuleOption(string $option, array|string $value, bool $multiple = false): void; - - public function fillRuleOption(string $option, string $value): void; - - public function fillRuleOptionForChannel(string $channelCode, string $option, string $value): void; - /** @throws ElementNotFoundException */ public function getValidationMessageForAction(): string; - /** @param string|string[] $value */ - public function selectAutoCompleteFilterOption(string $option, array|string $value, bool $multiple = false): void; - public function checkIfRuleConfigurationFormIsVisible(): bool; public function checkIfActionConfigurationFormIsVisible(): bool; diff --git a/src/Sylius/Behat/Resources/config/services/elements/admin.xml b/src/Sylius/Behat/Resources/config/services/elements/admin.xml index 65c413b8487..622aee72399 100644 --- a/src/Sylius/Behat/Resources/config/services/elements/admin.xml +++ b/src/Sylius/Behat/Resources/config/services/elements/admin.xml @@ -56,6 +56,8 @@ id="Sylius\Behat\Element\Admin\Promotion\FormElementInterface" class="Sylius\Behat\Element\Admin\Promotion\FormElement" parent="sylius.behat.element" - /> + > + + diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/form_theme.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/form_theme.html.twig index 823aa4a9ab9..5fd60053e43 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/form_theme.html.twig +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/form_theme.html.twig @@ -35,6 +35,16 @@
{% endblock %} +{% block sylius_promotion_rule_row %} + +
+ {{- form_label(form) -}} + {{- form_widget(form) -}} + {{- form_errors(form) -}} +
+
+{% endblock %} + {% block sylius_channel_collection_row %}
From b63fd0934c3712005cbd969446537bc6a2ac6ff8 Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Wed, 10 Apr 2024 18:38:53 +0200 Subject: [PATCH 17/39] [Behat][Admin] Enable seeing correct percentage discounts scenario --- ...diting_promotion_with_action_and_decimal_places.feature} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename features/admin/promotion/managing_promotions/{seeing_correct_percantage_discounts_while_editing_promotion_with_action_and_decimal_places.feature => seeing_correct_percentage_discounts_while_editing_promotion_with_action_and_decimal_places.feature} (96%) diff --git a/features/admin/promotion/managing_promotions/seeing_correct_percantage_discounts_while_editing_promotion_with_action_and_decimal_places.feature b/features/admin/promotion/managing_promotions/seeing_correct_percentage_discounts_while_editing_promotion_with_action_and_decimal_places.feature similarity index 96% rename from features/admin/promotion/managing_promotions/seeing_correct_percantage_discounts_while_editing_promotion_with_action_and_decimal_places.feature rename to features/admin/promotion/managing_promotions/seeing_correct_percentage_discounts_while_editing_promotion_with_action_and_decimal_places.feature index 25d5349e7f9..33a6bb9fdfb 100644 --- a/features/admin/promotion/managing_promotions/seeing_correct_percantage_discounts_while_editing_promotion_with_action_and_decimal_places.feature +++ b/features/admin/promotion/managing_promotions/seeing_correct_percentage_discounts_while_editing_promotion_with_action_and_decimal_places.feature @@ -10,7 +10,7 @@ Feature: Seeing correct percentage discounts while editing promotion with action And this promotion gives "12.00%" discount to every order And I am logged in as an administrator - @api @todo @ui + @api @ui Scenario: Seeing an accurate percentage amount after editing the promotion including the value up to one decimal place When I want to modify a "Cheap Stuff" promotion And I edit this promotion percentage action to have "2.5%" @@ -18,7 +18,7 @@ Feature: Seeing correct percentage discounts while editing promotion with action Then I should be notified that it has been successfully edited And it should have "2.50%" of order percentage discount - @api @todo @ui + @api @ui Scenario: Seeing an accurate percentage amount after editing the promotion including the value up to two decimal places When I want to modify a "Cheap Stuff" promotion And I edit this promotion percentage action to have "2.56%" @@ -26,7 +26,7 @@ Feature: Seeing correct percentage discounts while editing promotion with action Then I should be notified that it has been successfully edited And it should have "2.56%" of order percentage discount - @todo @ui @no-api + @ui @no-api Scenario: Seeing an accurate percentage amount after using a comma as a decimal separator When I want to modify a "Cheap Stuff" promotion And I edit this promotion percentage action to have "2,56%" From 4acb85555982240e0aa59a178a18c332ceb8b19e Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Wed, 10 Apr 2024 18:42:37 +0200 Subject: [PATCH 18/39] [Behat][Admin] Cover scenarios for promotions filters validation --- .../promotions_filter_validation.feature | 4 ++-- .../Context/Ui/Admin/ManagingPromotionsContext.php | 12 +++--------- .../Behat/Element/Admin/Promotion/FormElement.php | 2 ++ src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php | 2 -- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/features/admin/promotion/managing_promotions/promotions_filter_validation.feature b/features/admin/promotion/managing_promotions/promotions_filter_validation.feature index d4e7cef4956..6fe1bd30444 100644 --- a/features/admin/promotion/managing_promotions/promotions_filter_validation.feature +++ b/features/admin/promotion/managing_promotions/promotions_filter_validation.feature @@ -8,7 +8,7 @@ Feature: Promotion filters validation Given the store operates on a single channel in "United States" And I am logged in as an administrator - @api @todo @ui @javascript + @api @ui @javascript Scenario: Adding a promotion with wrong minimum price on price range filter When I want to create a new promotion And I specify its code as "10_for_all_products_over_10" @@ -19,7 +19,7 @@ Feature: Promotion filters validation Then I should be notified that a minimum value should be a numeric value And promotion with name "$10 discount for all products over $10!" should not be added - @api @todo @ui @javascript + @api @ui @javascript Scenario: Adding a promotion with wrong maximum price on price range filter When I want to create a new promotion And I specify its code as "10_for_all_products_over_10" diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php index 225bd1ad4c5..575570f9a06 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php @@ -354,7 +354,7 @@ public function iShouldBeNotifiedThatAMinimalValueShouldBeNumeric($element) */ public function iShouldBeNotifiedThatPromotionWithThisCodeAlreadyExists() { - Assert::same($this->createPage->getValidationMessage('code'), 'The promotion with given code already exists.'); + Assert::same($this->formElement->getValidationMessage('code'), 'The promotion with given code already exists.'); } /** @@ -556,10 +556,7 @@ public function thePromotionShouldBeAvailableFromTo(PromotionInterface $promotio */ public function iShouldBeNotifiedThatPromotionCannotEndBeforeItsEvenStarts(): void { - /** @var CreatePageInterface|UpdatePageInterface $currentPage */ - $currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]); - - Assert::same($currentPage->getValidationMessage('ends_at'), 'End date cannot be set prior start date.'); + Assert::same($this->formElement->getValidationMessage('ends_at'), 'End date cannot be set prior start date.'); } /** @@ -866,10 +863,7 @@ public function iShouldBeViewingNonArchivalPromotions(): void private function assertFieldValidationMessage(string $element, string $expectedMessage) { - /** @var CreatePageInterface|UpdatePageInterface $currentPage */ - $currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]); - - Assert::same($currentPage->getValidationMessage($element), $expectedMessage); + Assert::same($this->formElement->getValidationMessage($element), $expectedMessage); } /** diff --git a/src/Sylius/Behat/Element/Admin/Promotion/FormElement.php b/src/Sylius/Behat/Element/Admin/Promotion/FormElement.php index 19aa0dbe08b..6e21a9259b3 100644 --- a/src/Sylius/Behat/Element/Admin/Promotion/FormElement.php +++ b/src/Sylius/Behat/Element/Admin/Promotion/FormElement.php @@ -203,6 +203,8 @@ protected function getDefinedElements(): array 'exclusive' => '#sylius_promotion_exclusive', 'form' => '[data-live-name-value="SyliusAdmin.Promotion.Form"]', 'label' => '[name="sylius_promotion[translations][%locale_code%][label]"]', + 'minimum' => '#sylius_promotion_actions_0_configuration_WEB-US_filters_price_range_filter_min', + 'maximum' => '#sylius_promotion_actions_0_configuration_WEB-US_filters_price_range_filter_max', 'name' => '#sylius_promotion_name', 'priority' => '#sylius_promotion_priority', 'rules' => '#sylius_promotion_rules', diff --git a/src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php b/src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php index 45ebd3ed920..ef601e2cc95 100644 --- a/src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php +++ b/src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php @@ -52,8 +52,6 @@ protected function getDefinedElements(): array return array_merge(parent::getDefinedElements(), [ 'code' => '#sylius_promotion_code', 'form' => '[data-live-name-value="SyliusAdmin.Promotion.Form"]', - 'minimum' => '#sylius_promotion_actions_0_configuration_WEB-US_filters_price_range_filter_min', - 'maximum' => '#sylius_promotion_actions_0_configuration_WEB-US_filters_price_range_filter_max', 'rules' => '#sylius_promotion_rules', 'count' => '#sylius_promotion_rules_0_configuration_count', 'amount' => '#sylius_promotion_actions_0_configuration_WEB-US_amount', From 5411867b22de8914279679a2867f3d5cb970a77d Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Wed, 10 Apr 2024 19:10:40 +0200 Subject: [PATCH 19/39] [Behat][Admin] Cover scenarios for promotions validation --- .../promotion_unique_code_validation.feature | 2 +- .../promotion_validation.feature | 22 +++++++------- .../Ui/Admin/ManagingPromotionsContext.php | 11 +++---- .../Element/Admin/Promotion/FormElement.php | 30 ++++++++++++++++++- .../Admin/Promotion/FormElementInterface.php | 4 +++ .../Behat/Page/Admin/Promotion/CreatePage.php | 26 ++++++++++++---- .../Admin/Promotion/CreatePageInterface.php | 4 +-- 7 files changed, 70 insertions(+), 29 deletions(-) diff --git a/features/admin/promotion/managing_promotions/promotion_unique_code_validation.feature b/features/admin/promotion/managing_promotions/promotion_unique_code_validation.feature index c70932ea7b9..7f290f63f06 100644 --- a/features/admin/promotion/managing_promotions/promotion_unique_code_validation.feature +++ b/features/admin/promotion/managing_promotions/promotion_unique_code_validation.feature @@ -9,7 +9,7 @@ Feature: Promotion unique code validation And there is a promotion "No-VAT promotion" identified by "NO_VAT" code And I am logged in as an administrator - @api @todo @ui + @api @ui Scenario: Trying to add promotion with taken code When I want to create a new promotion And I specify its code as "NO_VAT" diff --git a/features/admin/promotion/managing_promotions/promotion_validation.feature b/features/admin/promotion/managing_promotions/promotion_validation.feature index 615f4968489..3ffb1944aaa 100644 --- a/features/admin/promotion/managing_promotions/promotion_validation.feature +++ b/features/admin/promotion/managing_promotions/promotion_validation.feature @@ -17,7 +17,7 @@ Feature: Promotion validation And I try to save my changes Then I should be notified that the locale is not available - @api @todo @ui + @api @ui Scenario: Trying to add a new promotion without specifying its code When I want to create a new promotion And I name it "No-VAT promotion" @@ -26,7 +26,7 @@ Feature: Promotion validation Then I should be notified that code is required And promotion with name "No-VAT promotion" should not be added - @api @todo @ui + @api @ui Scenario: Trying to add a new promotion with a too long code When I want to create a new promotion And I name it "No-VAT promotion" @@ -34,7 +34,7 @@ Feature: Promotion validation And I try to add it Then I should be notified that code is too long - @api @todo @ui + @api @ui Scenario: Trying to add a new promotion without specifying its name When I want to create a new promotion And I specify its code as "no_vat_promotion" @@ -43,7 +43,7 @@ Feature: Promotion validation Then I should be notified that name is required And promotion with code "no_vat_promotion" should not be added - @api @todo @ui + @api @ui Scenario: Adding a promotion with start date set up after end date When I want to create a new promotion And I specify its code as "FULL_METAL_PROMOTION" @@ -52,7 +52,7 @@ Feature: Promotion validation And I try to add it Then I should be notified that promotion cannot end before it starts - @api @todo @ui + @api @ui Scenario: Trying to remove name from existing promotion Given there is a promotion "Christmas sale" When I want to modify this promotion @@ -61,7 +61,7 @@ Feature: Promotion validation Then I should be notified that name is required And this promotion should still be named "Christmas sale" - @api @todo @ui + @api @ui Scenario: Trying to add start later then end date for existing promotion Given there is a promotion "Christmas sale" When I want to modify this promotion @@ -69,7 +69,7 @@ Feature: Promotion validation And I try to save my changes Then I should be notified that promotion cannot end before it starts - @api @todo @ui @mink:chromedriver + @api @ui @mink:chromedriver Scenario: Adding a promotion with label exceeding 255 characters Given there is a promotion "Christmas sale" When I want to modify this promotion @@ -77,7 +77,7 @@ Feature: Promotion validation And I try to save my changes Then I should be notified that promotion label in "Polish (Poland)" locale is too long - @api @todo @ui @javascript + @api @ui @javascript Scenario: Trying to add a new promotion without specifying a order percentage discount When I want to create a new promotion And I specify its code as "christmas_sale" @@ -87,7 +87,7 @@ Feature: Promotion validation Then I should be notified that this value should not be blank And promotion with name "Christmas sale" should not be added - @api @todo @ui @javascript + @api @ui @javascript Scenario: Trying to add a new promotion without specifying an item percentage discount When I want to create a new promotion And I specify its code as "christmas_sale" @@ -97,7 +97,7 @@ Feature: Promotion validation Then I should be notified that this value should not be blank And promotion with name "Christmas sale" should not be added - @api @todo @ui @javascript + @api @ui @javascript Scenario: Trying to add a new promotion with a wrong order percentage discount When I want to create a new promotion And I specify its code as "christmas_sale" @@ -107,7 +107,7 @@ Feature: Promotion validation Then I should be notified that a percentage discount value must be between 0% and 100% And promotion with name "Christmas sale" should not be added - @api @todo @ui @javascript + @api @ui @javascript Scenario: Trying to add a new promotion with a wrong item percentage discount When I want to create a new promotion And I specify its code as "christmas_sale" diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php index 575570f9a06..7f484db819b 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php @@ -556,7 +556,7 @@ public function thePromotionShouldBeAvailableFromTo(PromotionInterface $promotio */ public function iShouldBeNotifiedThatPromotionCannotEndBeforeItsEvenStarts(): void { - Assert::same($this->formElement->getValidationMessage('ends_at'), 'End date cannot be set prior start date.'); + Assert::same($this->formElement->getValidationMessage('ends_at_date'), 'End date cannot be set prior start date.'); } /** @@ -565,7 +565,7 @@ public function iShouldBeNotifiedThatPromotionCannotEndBeforeItsEvenStarts(): vo public function iShouldBeNotifiedThatThisValueShouldNotBeBlank(): void { Assert::same( - $this->createPage->getValidationMessageForAction(), + $this->formElement->getValidationMessageForAction(), 'This value should not be blank.', ); } @@ -578,7 +578,7 @@ public function iShouldBeNotifiedThatThisValueShouldNotBeBlank(): void public function iShouldBeNotifiedThatPercentageDiscountShouldBeBetween(): void { Assert::same( - $this->createPage->getValidationMessageForAction(), + $this->formElement->getValidationMessageForAction(), 'The percentage discount must be between 0% and 100%.', ); } @@ -828,11 +828,8 @@ public function iShouldBeNotifiedThatPromotionsHaveBeenUpdated(PromotionInterfac */ public function iShouldBeNotifiedThatPromotionLabelIsTooLong(string $localeCode): void { - /** @var CreatePageInterface|UpdatePageInterface $currentPage */ - $currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]); - Assert::same( - $currentPage->getValidationMessageForTranslation('label', $localeCode), + $this->formElement->getValidationMessageForTranslation('label', $localeCode), 'This value is too long. It should have 255 characters or less.', ); } diff --git a/src/Sylius/Behat/Element/Admin/Promotion/FormElement.php b/src/Sylius/Behat/Element/Admin/Promotion/FormElement.php index 6e21a9259b3..3ec5fe1e49d 100644 --- a/src/Sylius/Behat/Element/Admin/Promotion/FormElement.php +++ b/src/Sylius/Behat/Element/Admin/Promotion/FormElement.php @@ -79,6 +79,7 @@ public function checkChannel(string $name): void public function setLabel(string $label, string $localeCode): void { + $this->getElement('translation_tab', ['%locale_code%' => $localeCode])->press(); $this->getElement('label', ['%locale_code%' => $localeCode])->setValue($label); } @@ -189,6 +190,31 @@ public function getValidationMessage(string $element): string return $validationMessage->getText(); } + public function getValidationMessageForAction(): string + { + $actionForm = $this->getLastAction(); + + $foundElement = $actionForm->find('css', '.invalid-feedback'); + if (null === $foundElement) { + throw new ElementNotFoundException($this->getSession(), 'Tag', 'css', '.invalid-feedback'); + } + + return $foundElement->getText(); + } + + public function getValidationMessageForTranslation(string $element, string $localeCode): string + { + $this->getElement('translation_tab', ['%locale_code%' => $localeCode])->press(); + $foundElement = $this->getElement($element, ['%locale_code%' => $localeCode])->getParent(); + + $validationMessage = $foundElement->find('css', '.invalid-feedback'); + if (null === $validationMessage) { + throw new ElementNotFoundException($this->getSession(), 'Validation message', 'css', '.invalid-feedback'); + } + + return $validationMessage->getText(); + } + protected function getDefinedElements(): array { return array_merge(parent::getDefinedElements(), [ @@ -197,6 +223,7 @@ protected function getDefinedElements(): array 'add_rule_button' => '#sylius_promotion_rules_add', 'applies_to_discounted' => '#sylius_promotion_appliesToDiscounted', 'channels' => '#sylius_promotion_channels', + 'code' => '#sylius_promotion_code', 'coupon_based' => '#sylius_promotion_couponBased', 'ends_at_date' => '#sylius_promotion_endsAt_date', 'ends_at_time' => '#sylius_promotion_endsAt_time', @@ -208,9 +235,10 @@ protected function getDefinedElements(): array 'name' => '#sylius_promotion_name', 'priority' => '#sylius_promotion_priority', 'rules' => '#sylius_promotion_rules', - 'usage_limit' => '#sylius_promotion_usageLimit', 'starts_at_date' => '#sylius_promotion_startsAt_date', 'starts_at_time' => '#sylius_promotion_startsAt_time', + 'translation_tab' => '[data-test-promotion-translations-accordion="%locale_code%"]', + 'usage_limit' => '#sylius_promotion_usageLimit', ]); } diff --git a/src/Sylius/Behat/Element/Admin/Promotion/FormElementInterface.php b/src/Sylius/Behat/Element/Admin/Promotion/FormElementInterface.php index 10c571d9432..e46c8f9ec9c 100644 --- a/src/Sylius/Behat/Element/Admin/Promotion/FormElementInterface.php +++ b/src/Sylius/Behat/Element/Admin/Promotion/FormElementInterface.php @@ -56,4 +56,8 @@ public function selectAutocompleteRuleOptions(array $values, ?string $channelCod public function selectAutocompleteFilterOptions(array $values, string $channelCode, string $filterType): void; public function getValidationMessage(string $element): string; + + public function getValidationMessageForAction(): string; + + public function getValidationMessageForTranslation(string $element, string $localeCode): string; } diff --git a/src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php b/src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php index ef601e2cc95..cf8850bbcc1 100644 --- a/src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php +++ b/src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php @@ -25,16 +25,19 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface use NamesIt; use SpecifiesItsField; - public function getValidationMessageForAction(): string + public function getValidationMessage(string $element): string { - $actionForm = $this->getLastCollectionItem('actions'); - - $foundElement = $actionForm->find('css', '.sylius-validation-error'); + $foundElement = $this->getFieldElement($element); if (null === $foundElement) { - throw new ElementNotFoundException($this->getSession(), 'Tag', 'css', '.sylius-validation-error'); + throw new ElementNotFoundException($this->getSession(), 'Field element'); + } + + $validationMessage = $foundElement->find('css', '.invalid-feedback'); + if (null === $validationMessage) { + throw new ElementNotFoundException($this->getSession(), 'Validation message', 'css', '.invalid-feedback'); } - return $foundElement->getText(); + return $validationMessage->getText(); } public function checkIfRuleConfigurationFormIsVisible(): bool @@ -78,4 +81,15 @@ private function getCollectionItems(string $collection): array return $items; } + + /** @throws ElementNotFoundException */ + private function getFieldElement(string $element): ?NodeElement + { + $element = $this->getElement($element); + while (null !== $element && !$element->hasClass('field')) { + $element = $element->getParent(); + } + + return $element; + } } diff --git a/src/Sylius/Behat/Page/Admin/Promotion/CreatePageInterface.php b/src/Sylius/Behat/Page/Admin/Promotion/CreatePageInterface.php index 70e2d0844e1..7e2b8053f7d 100644 --- a/src/Sylius/Behat/Page/Admin/Promotion/CreatePageInterface.php +++ b/src/Sylius/Behat/Page/Admin/Promotion/CreatePageInterface.php @@ -13,7 +13,6 @@ namespace Sylius\Behat\Page\Admin\Promotion; -use Behat\Mink\Exception\ElementNotFoundException; use Sylius\Behat\Page\Admin\Crud\CreatePageInterface as BaseCreatePageInterface; interface CreatePageInterface extends BaseCreatePageInterface @@ -22,8 +21,7 @@ public function specifyCode(string $code): void; public function nameIt(string $name): void; - /** @throws ElementNotFoundException */ - public function getValidationMessageForAction(): string; + public function getValidationMessage(string $element): string; public function checkIfRuleConfigurationFormIsVisible(): bool; From 737f8a03585fea6d9ad03e97919c2d1229f191d5 Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Thu, 11 Apr 2024 14:48:28 +0200 Subject: [PATCH 20/39] [Admin] Overwrite promotion rules configuration instead of morphing to fix replacing autocomplete fields --- .../AdminBundle/Resources/views/Shared/form_theme.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/form_theme.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/form_theme.html.twig index 5fd60053e43..6441e6476df 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/form_theme.html.twig +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/form_theme.html.twig @@ -37,7 +37,7 @@ {% block sylius_promotion_rule_row %} -
+
{{- form_label(form) -}} {{- form_widget(form) -}} {{- form_errors(form) -}} From b26482100f663e0eb0279d0be5d7a103065fb22d Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Thu, 11 Apr 2024 15:13:09 +0200 Subject: [PATCH 21/39] [Behat][Admin] Minor clean up in promotion pages --- .../Ui/Admin/ManagingPromotionsContext.php | 10 +++--- .../Element/Admin/Promotion/FormElement.php | 19 ++++++++++- .../Admin/Promotion/FormElementInterface.php | 8 ++++- .../Behat/Page/Admin/Promotion/CreatePage.php | 34 ------------------- .../Admin/Promotion/CreatePageInterface.php | 4 --- .../Behat/Page/Admin/Promotion/UpdatePage.php | 27 --------------- .../Admin/Promotion/UpdatePageInterface.php | 10 ------ 7 files changed, 30 insertions(+), 82 deletions(-) diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php index 7f484db819b..0e9469df38a 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php @@ -88,7 +88,7 @@ public function iNameIt($name = null) */ public function iRemoveItsPriority(?int $priority = null): void { - $this->formElement->prioritizeIt($priority); + $this->formElement->setPriority($priority); } /** @@ -664,7 +664,7 @@ public function thePromotionsShouldHavePriority(PromotionInterface $promotion, i { $this->iWantToModifyAPromotion($promotion); - Assert::same($this->updatePage->getPriority(), $priority); + Assert::same($this->formElement->getPriority(), $priority); } /** @@ -767,9 +767,9 @@ public function iRemoveTheRuleAmountForChannel(ChannelInterface $channel): void /** * @Then I should see the rule configuration form */ - public function iShouldSeeTheRuleConfigurationForm() + public function iShouldSeeTheRuleConfigurationForm(): void { - Assert::true($this->createPage->checkIfRuleConfigurationFormIsVisible(), 'Cart promotion rule configuration form is not visible.'); + Assert::true($this->formElement->checkIfRuleConfigurationFormIsVisible(), 'Cart promotion rule configuration form is not visible.'); } /** @@ -793,7 +793,7 @@ public function itShouldHaveOfItemPercentageDiscount(string $amount, ChannelInte */ public function iShouldSeeTheActionConfigurationForm() { - Assert::true($this->createPage->checkIfActionConfigurationFormIsVisible(), 'Cart promotion action configuration form is not visible.'); + Assert::true($this->formElement->checkIfActionConfigurationFormIsVisible(), 'Cart promotion action configuration form is not visible.'); } /** diff --git a/src/Sylius/Behat/Element/Admin/Promotion/FormElement.php b/src/Sylius/Behat/Element/Admin/Promotion/FormElement.php index 3ec5fe1e49d..111523e6747 100644 --- a/src/Sylius/Behat/Element/Admin/Promotion/FormElement.php +++ b/src/Sylius/Behat/Element/Admin/Promotion/FormElement.php @@ -31,7 +31,12 @@ public function __construct( parent::__construct($session, $minkParameters); } - public function prioritizeIt(?int $priority): void + public function getPriority(): int + { + return (int) $this->getElement('priority')->getValue(); + } + + public function setPriority(?int $priority): void { $this->getElement('priority')->setValue($priority); } @@ -175,6 +180,16 @@ public function selectAutocompleteFilterOptions(array $values, string $channelCo $this->waitForFormUpdate(); } + public function checkIfRuleConfigurationFormIsVisible(): bool + { + return $this->hasElement('rule_count'); + } + + public function checkIfActionConfigurationFormIsVisible(): bool + { + return $this->hasElement('action_amount'); + } + public function getValidationMessage(string $element): string { $foundElement = $this->getFieldElement($element); @@ -218,6 +233,7 @@ public function getValidationMessageForTranslation(string $element, string $loca protected function getDefinedElements(): array { return array_merge(parent::getDefinedElements(), [ + 'action_amount' => '#sylius_promotion_actions_0_configuration_WEB-US_amount', 'actions' => '#sylius_promotion_actions', 'add_action_button' => '#sylius_promotion_actions_add', 'add_rule_button' => '#sylius_promotion_rules_add', @@ -234,6 +250,7 @@ protected function getDefinedElements(): array 'maximum' => '#sylius_promotion_actions_0_configuration_WEB-US_filters_price_range_filter_max', 'name' => '#sylius_promotion_name', 'priority' => '#sylius_promotion_priority', + 'rule_count' => '#sylius_promotion_rules_0_configuration_count', 'rules' => '#sylius_promotion_rules', 'starts_at_date' => '#sylius_promotion_startsAt_date', 'starts_at_time' => '#sylius_promotion_startsAt_time', diff --git a/src/Sylius/Behat/Element/Admin/Promotion/FormElementInterface.php b/src/Sylius/Behat/Element/Admin/Promotion/FormElementInterface.php index e46c8f9ec9c..a479e50428d 100644 --- a/src/Sylius/Behat/Element/Admin/Promotion/FormElementInterface.php +++ b/src/Sylius/Behat/Element/Admin/Promotion/FormElementInterface.php @@ -15,7 +15,9 @@ interface FormElementInterface { - public function prioritizeIt(?int $priority): void; + public function setPriority(?int $priority): void; + + public function getPriority(): int; public function setStartsAt(\DateTimeInterface $dateTime): void; @@ -55,6 +57,10 @@ public function selectAutocompleteRuleOptions(array $values, ?string $channelCod public function selectAutocompleteFilterOptions(array $values, string $channelCode, string $filterType): void; + public function checkIfRuleConfigurationFormIsVisible(): bool; + + public function checkIfActionConfigurationFormIsVisible(): bool; + public function getValidationMessage(string $element): string; public function getValidationMessageForAction(): string; diff --git a/src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php b/src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php index cf8850bbcc1..f7f3cd09d99 100644 --- a/src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php +++ b/src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php @@ -18,7 +18,6 @@ use Sylius\Behat\Behaviour\NamesIt; use Sylius\Behat\Behaviour\SpecifiesItsField; use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage; -use Webmozart\Assert\Assert; class CreatePage extends BaseCreatePage implements CreatePageInterface { @@ -40,48 +39,15 @@ public function getValidationMessage(string $element): string return $validationMessage->getText(); } - public function checkIfRuleConfigurationFormIsVisible(): bool - { - return $this->hasElement('count'); - } - - public function checkIfActionConfigurationFormIsVisible(): bool - { - return $this->hasElement('amount'); - } - protected function getDefinedElements(): array { return array_merge(parent::getDefinedElements(), [ 'code' => '#sylius_promotion_code', 'form' => '[data-live-name-value="SyliusAdmin.Promotion.Form"]', 'rules' => '#sylius_promotion_rules', - 'count' => '#sylius_promotion_rules_0_configuration_count', - 'amount' => '#sylius_promotion_actions_0_configuration_WEB-US_amount', ]); } - private function getLastCollectionItem(string $collection): NodeElement - { - $items = $this->getCollectionItems($collection); - - Assert::notEmpty($items); - - return end($items); - } - - /** - * @return NodeElement[] - */ - private function getCollectionItems(string $collection): array - { - $items = $this->getElement($collection)->findAll('css', 'div[data-form-collection="item"]'); - - Assert::isArray($items); - - return $items; - } - /** @throws ElementNotFoundException */ private function getFieldElement(string $element): ?NodeElement { diff --git a/src/Sylius/Behat/Page/Admin/Promotion/CreatePageInterface.php b/src/Sylius/Behat/Page/Admin/Promotion/CreatePageInterface.php index 7e2b8053f7d..c1102bfd662 100644 --- a/src/Sylius/Behat/Page/Admin/Promotion/CreatePageInterface.php +++ b/src/Sylius/Behat/Page/Admin/Promotion/CreatePageInterface.php @@ -22,8 +22,4 @@ public function specifyCode(string $code): void; public function nameIt(string $name): void; public function getValidationMessage(string $element): string; - - public function checkIfRuleConfigurationFormIsVisible(): bool; - - public function checkIfActionConfigurationFormIsVisible(): bool; } diff --git a/src/Sylius/Behat/Page/Admin/Promotion/UpdatePage.php b/src/Sylius/Behat/Page/Admin/Promotion/UpdatePage.php index a5f2cd459a9..ec46e6cf4ef 100644 --- a/src/Sylius/Behat/Page/Admin/Promotion/UpdatePage.php +++ b/src/Sylius/Behat/Page/Admin/Promotion/UpdatePage.php @@ -14,7 +14,6 @@ namespace Sylius\Behat\Page\Admin\Promotion; use Behat\Mink\Element\NodeElement; -use Behat\Mink\Exception\ElementNotFoundException; use Sylius\Behat\Behaviour\ChecksCodeImmutability; use Sylius\Behat\Behaviour\CountsChannelBasedErrors; use Sylius\Behat\Behaviour\NamesIt; @@ -26,16 +25,6 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface use CountsChannelBasedErrors; use NamesIt; - public function setPriority(?int $priority): void - { - $this->getDocument()->fillField('Priority', $priority); - } - - public function getPriority(): int - { - return (int) $this->getElement('priority')->getValue(); - } - public function checkChannelsState(string $channelName): bool { $field = $this->getDocument()->findField($channelName); @@ -131,21 +120,6 @@ public function getRuleValidationErrorsCount(string $channelCode): int return $this->countChannelErrors($this->getElement('rules'), $channelCode); } - /** - * @throws ElementNotFoundException - */ - public function getValidationMessageForTranslation(string $element, string $localeCode): string - { - $foundElement = $this->getElement($element, ['%localeCode%' => $localeCode])->getParent(); - - $validationMessage = $foundElement->find('css', '.sylius-validation-error'); - if (null === $validationMessage) { - throw new ElementNotFoundException($this->getSession(), 'Validation message', 'css', '.sylius-validation-error'); - } - - return $validationMessage->getText(); - } - protected function getCodeElement(): NodeElement { return $this->getElement('code'); @@ -163,7 +137,6 @@ protected function getDefinedElements(): array 'ends_at_time' => '#sylius_promotion_endsAt_time', 'exclusive' => '#sylius_promotion_exclusive', 'coupon_based' => '#sylius_promotion_couponBased', - 'label' => '#sylius_promotion_translations_%localeCode%_label', 'name' => '#sylius_promotion_name', 'order_percentage_action_field' => '[id^="sylius_promotion_actions_"][id$="_configuration_percentage"]', 'priority' => '#sylius_promotion_priority', diff --git a/src/Sylius/Behat/Page/Admin/Promotion/UpdatePageInterface.php b/src/Sylius/Behat/Page/Admin/Promotion/UpdatePageInterface.php index 9bb33a99da4..be0d90f9675 100644 --- a/src/Sylius/Behat/Page/Admin/Promotion/UpdatePageInterface.php +++ b/src/Sylius/Behat/Page/Admin/Promotion/UpdatePageInterface.php @@ -13,15 +13,10 @@ namespace Sylius\Behat\Page\Admin\Promotion; -use Behat\Mink\Exception\ElementNotFoundException; use Sylius\Behat\Page\Admin\Crud\UpdatePageInterface as BaseUpdatePageInterface; interface UpdatePageInterface extends BaseUpdatePageInterface { - public function setPriority(?int $priority): void; - - public function getPriority(): int; - public function nameIt(string $name): void; public function checkChannelsState(string $channelName): bool; @@ -53,9 +48,4 @@ public function removeRuleAmount(string $channelCode): void; public function getActionValidationErrorsCount(string $channelCode): int; public function getRuleValidationErrorsCount(string $channelCode): int; - - /** - * @throws ElementNotFoundException - */ - public function getValidationMessageForTranslation(string $element, string $localeCode): string; } From bb3741771f6c6e84d97668546aec95d620549ccb Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Thu, 11 Apr 2024 15:21:40 +0200 Subject: [PATCH 22/39] [Admin] Fix static analysis --- .../ProductFilterConfigurationTypeExtension.php | 2 ++ .../TaxonFilterConfigurationTypeExtension.php | 2 ++ .../ContainsProductConfigurationTypeExtension.php | 2 ++ .../Rule/HasTaxonConfigurationTypeExtension.php | 2 ++ ...lOfItemsFromTaxonConfigurationTypeExtension.php | 2 ++ .../TwigComponent/Promotion/FormComponent.php | 14 +++++++++----- .../Resources/config/integrations/swagger.xml | 2 +- 7 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Filter/ProductFilterConfigurationTypeExtension.php b/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Filter/ProductFilterConfigurationTypeExtension.php index 550256e47f8..8556def5fd0 100644 --- a/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Filter/ProductFilterConfigurationTypeExtension.php +++ b/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Filter/ProductFilterConfigurationTypeExtension.php @@ -15,12 +15,14 @@ use Sylius\Bundle\AdminBundle\Form\Type\ProductAutocompleteChoiceType; use Sylius\Bundle\CoreBundle\Form\Type\Promotion\Filter\ProductFilterConfigurationType; +use Sylius\Component\Core\Model\ProductInterface; use Symfony\Component\Form\AbstractTypeExtension; use Symfony\Component\Form\DataTransformerInterface; use Symfony\Component\Form\FormBuilderInterface; final class ProductFilterConfigurationTypeExtension extends AbstractTypeExtension { + /** @param DataTransformerInterface $productsToCodesTransformer */ public function __construct(private readonly DataTransformerInterface $productsToCodesTransformer) { } diff --git a/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Filter/TaxonFilterConfigurationTypeExtension.php b/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Filter/TaxonFilterConfigurationTypeExtension.php index 58119ad2228..da550dd432b 100644 --- a/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Filter/TaxonFilterConfigurationTypeExtension.php +++ b/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Filter/TaxonFilterConfigurationTypeExtension.php @@ -15,12 +15,14 @@ use Sylius\Bundle\AdminBundle\Form\Type\TaxonAutocompleteChoiceType; use Sylius\Bundle\CoreBundle\Form\Type\Promotion\Filter\TaxonFilterConfigurationType; +use Sylius\Component\Core\Model\TaxonInterface; use Symfony\Component\Form\AbstractTypeExtension; use Symfony\Component\Form\DataTransformerInterface; use Symfony\Component\Form\FormBuilderInterface; final class TaxonFilterConfigurationTypeExtension extends AbstractTypeExtension { + /** @param DataTransformerInterface $taxonsToCodesTransformer */ public function __construct(private readonly DataTransformerInterface $taxonsToCodesTransformer) { } diff --git a/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Rule/ContainsProductConfigurationTypeExtension.php b/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Rule/ContainsProductConfigurationTypeExtension.php index 1ffedb644c6..f957323c39f 100644 --- a/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Rule/ContainsProductConfigurationTypeExtension.php +++ b/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Rule/ContainsProductConfigurationTypeExtension.php @@ -16,6 +16,7 @@ use Sylius\Bundle\AdminBundle\Form\Type\ProductAutocompleteChoiceType; use Sylius\Bundle\CoreBundle\Form\Type\Promotion\Rule\ContainsProductConfigurationType; use Sylius\Bundle\ResourceBundle\Form\DataTransformer\ResourceToIdentifierTransformer; +use Sylius\Component\Core\Model\ProductInterface; use Sylius\Component\Core\Repository\ProductRepositoryInterface; use Symfony\Component\Form\AbstractTypeExtension; use Symfony\Component\Form\FormBuilderInterface; @@ -23,6 +24,7 @@ final class ContainsProductConfigurationTypeExtension extends AbstractTypeExtension { + /** @param ProductRepositoryInterface $productRepository */ public function __construct(private readonly ProductRepositoryInterface $productRepository) { } diff --git a/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Rule/HasTaxonConfigurationTypeExtension.php b/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Rule/HasTaxonConfigurationTypeExtension.php index 5c5ad4a3b4f..f38a1a57b32 100644 --- a/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Rule/HasTaxonConfigurationTypeExtension.php +++ b/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Rule/HasTaxonConfigurationTypeExtension.php @@ -15,12 +15,14 @@ use Sylius\Bundle\AdminBundle\Form\Type\TaxonAutocompleteChoiceType; use Sylius\Bundle\CoreBundle\Form\Type\Promotion\Rule\HasTaxonConfigurationType; +use Sylius\Component\Core\Model\TaxonInterface; use Symfony\Component\Form\AbstractTypeExtension; use Symfony\Component\Form\DataTransformerInterface; use Symfony\Component\Form\FormBuilderInterface; final class HasTaxonConfigurationTypeExtension extends AbstractTypeExtension { + /** @param DataTransformerInterface $taxonsToCodesTransformer */ public function __construct(private readonly DataTransformerInterface $taxonsToCodesTransformer) { } diff --git a/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Rule/TotalOfItemsFromTaxonConfigurationTypeExtension.php b/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Rule/TotalOfItemsFromTaxonConfigurationTypeExtension.php index a9c7eca8023..68701a12894 100644 --- a/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Rule/TotalOfItemsFromTaxonConfigurationTypeExtension.php +++ b/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Rule/TotalOfItemsFromTaxonConfigurationTypeExtension.php @@ -16,6 +16,7 @@ use Sylius\Bundle\AdminBundle\Form\Type\TaxonAutocompleteChoiceType; use Sylius\Bundle\CoreBundle\Form\Type\Promotion\Rule\TotalOfItemsFromTaxonConfigurationType; use Sylius\Bundle\ResourceBundle\Form\DataTransformer\ResourceToIdentifierTransformer; +use Sylius\Component\Core\Model\TaxonInterface; use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface; use Symfony\Component\Form\AbstractTypeExtension; use Symfony\Component\Form\FormBuilderInterface; @@ -23,6 +24,7 @@ final class TotalOfItemsFromTaxonConfigurationTypeExtension extends AbstractTypeExtension { + /** @param TaxonRepositoryInterface $taxonRepository */ public function __construct(private readonly TaxonRepositoryInterface $taxonRepository) { } diff --git a/src/Sylius/Bundle/AdminBundle/TwigComponent/Promotion/FormComponent.php b/src/Sylius/Bundle/AdminBundle/TwigComponent/Promotion/FormComponent.php index 8624ca2b133..acea3d97df4 100644 --- a/src/Sylius/Bundle/AdminBundle/TwigComponent/Promotion/FormComponent.php +++ b/src/Sylius/Bundle/AdminBundle/TwigComponent/Promotion/FormComponent.php @@ -35,12 +35,16 @@ final class FormComponent #[LiveProp(dehydrateWith: 'dehydrateResource', fieldName: 'resource')] public ?Promotion $resource = null; - /** @param class-string $formClass */ + /** + * @param class-string $formClass + * @param array $ruleTypes + * @param array $actionTypes + */ public function __construct( private readonly FormFactoryInterface $formFactory, private readonly string $formClass, - private readonly array $rules, - private readonly array $actions, + private readonly array $ruleTypes, + private readonly array $actionTypes, ) { } @@ -77,11 +81,11 @@ protected function instantiateForm(): FormInterface private function provideItemType(string $name): string { if (str_contains($name, 'rules')) { - return array_key_first($this->rules); + return array_key_first($this->ruleTypes); } if (str_contains($name, 'actions')) { - return array_key_first($this->actions); + return array_key_first($this->actionTypes); } return ''; diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/integrations/swagger.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/integrations/swagger.xml index 97b9a73df98..ebc20f05649 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/integrations/swagger.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/integrations/swagger.xml @@ -85,7 +85,7 @@ - + %sylius.security.new_api_route% %sylius.promotion_actions% %sylius.promotion_rules% From 5e641b2c48714363e17ae981bc5e64fa4569ac62 Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Fri, 12 Apr 2024 07:07:36 +0200 Subject: [PATCH 23/39] [Admin] Fix accordion for translations --- .../views/ProductVariant/Form/Sections/_translations.html.twig | 2 +- .../Resources/views/Taxon/Form/Sections/_translations.html.twig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/ProductVariant/Form/Sections/_translations.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/ProductVariant/Form/Sections/_translations.html.twig index b0a803f3c61..a3a6480dd4f 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/views/ProductVariant/Form/Sections/_translations.html.twig +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/ProductVariant/Form/Sections/_translations.html.twig @@ -11,6 +11,6 @@
{% endverbatim %} {% endset %} - {{ _translations.default(hookable_data.form.translations, body) }} + {{ _translations.default(hookable_data.form.translations, body, {accordionId: 'product-variant-translations'}) }}
diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Taxon/Form/Sections/_translations.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Taxon/Form/Sections/_translations.html.twig index f2389ad5438..8a595c0fcb7 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/views/Taxon/Form/Sections/_translations.html.twig +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Taxon/Form/Sections/_translations.html.twig @@ -21,5 +21,5 @@
{% endverbatim %} {% endset %} - {{ _translations.default(hookable_data.form.translations, body) }} + {{ _translations.default(hookable_data.form.translations, body, {accordionId: 'taxon-translations'}) }}
From 8b93095e5c15347c3cea1b99485db351b573abc1 Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Fri, 12 Apr 2024 07:28:33 +0200 Subject: [PATCH 24/39] [Admin] Refactor naming of promotion Twig Hooks and templates --- .../app/twig_hooks/promotion/create.yaml | 48 ++++++++----------- .../app/twig_hooks/promotion/update.yaml | 48 ++++++++----------- .../Sections/Configuration/_left.html.twig | 9 ---- .../Sections/Configuration/_right.html.twig | 9 ---- ...l.twig => applies_to_discounted.html.twig} | 0 ...Based.html.twig => coupon_based.html.twig} | 0 .../_endsAt.html.twig => ends_at.html.twig} | 0 ...xclusive.html.twig => exclusive.html.twig} | 0 .../_header.html.twig => header.html.twig} | 0 ..._priority.html.twig => priority.html.twig} | 0 ...startsAt.html.twig => starts_at.html.twig} | 0 ...eLimit.html.twig => usage_limit.html.twig} | 0 ..._channels.html.twig => channels.html.twig} | 0 .../{_code.html.twig => code.html.twig} | 0 ...iption.html.twig => description.html.twig} | 0 .../{_name.html.twig => name.html.twig} | 0 .../{_actions.html.twig => actions.html.twig} | 0 .../{_rules.html.twig => rules.html.twig} | 0 ...tion.html.twig => configuration.html.twig} | 14 ++++++ .../{_general.html.twig => general.html.twig} | 0 ....html.twig => rules_and_actions.html.twig} | 0 ...tions.html.twig => translations.html.twig} | 0 ..._sections.html.twig => sections.html.twig} | 0 .../{_form.html.twig => form.html.twig} | 0 .../TwigComponent/Promotion/FormComponent.php | 2 +- 25 files changed, 57 insertions(+), 73 deletions(-) delete mode 100644 src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/_left.html.twig delete mode 100644 src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/_right.html.twig rename src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/{Right/_appliesToDiscounted.html.twig => applies_to_discounted.html.twig} (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/{Right/_couponBased.html.twig => coupon_based.html.twig} (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/{Left/_endsAt.html.twig => ends_at.html.twig} (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/{Right/_exclusive.html.twig => exclusive.html.twig} (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/{Right/_header.html.twig => header.html.twig} (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/{Left/_priority.html.twig => priority.html.twig} (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/{Left/_startsAt.html.twig => starts_at.html.twig} (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/{Left/_usageLimit.html.twig => usage_limit.html.twig} (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/{_channels.html.twig => channels.html.twig} (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/{_code.html.twig => code.html.twig} (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/{_description.html.twig => description.html.twig} (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/{_name.html.twig => name.html.twig} (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/RulesAndActions/{_actions.html.twig => actions.html.twig} (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/RulesAndActions/{_rules.html.twig => rules.html.twig} (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/{_configuration.html.twig => configuration.html.twig} (52%) rename src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/{_general.html.twig => general.html.twig} (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/{_rulesAndActions.html.twig => rules_and_actions.html.twig} (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/{_translations.html.twig => translations.html.twig} (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/{_sections.html.twig => sections.html.twig} (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/{_form.html.twig => form.html.twig} (100%) diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/create.yaml b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/create.yaml index b1e9d6cd3b5..56612b8b67c 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/create.yaml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/create.yaml @@ -13,56 +13,50 @@ twig_hooks: 'sylius_admin.promotion.create.content.form': sections: - template: '@SyliusAdmin/Promotion/Form/_sections.html.twig' + template: '@SyliusAdmin/Promotion/Form/sections.html.twig' 'sylius_admin.promotion.create.content.form.sections': general: - template: '@SyliusAdmin/Promotion/Form/Sections/_general.html.twig' + template: '@SyliusAdmin/Promotion/Form/Sections/general.html.twig' configuration: - template: '@SyliusAdmin/Promotion/Form/Sections/_configuration.html.twig' + template: '@SyliusAdmin/Promotion/Form/Sections/configuration.html.twig' translations: - template: '@SyliusAdmin/Promotion/Form/Sections/_translations.html.twig' + template: '@SyliusAdmin/Promotion/Form/Sections/translations.html.twig' rules_and_actions: - template: '@SyliusAdmin/Promotion/Form/Sections/_rulesAndActions.html.twig' + template: '@SyliusAdmin/Promotion/Form/Sections/rules_and_actions.html.twig' 'sylius_admin.promotion.create.content.form.sections.general': _name: - template: '@SyliusAdmin/Promotion/Form/Sections/General/_name.html.twig' + template: '@SyliusAdmin/Promotion/Form/Sections/General/name.html.twig' code: - template: '@SyliusAdmin/Promotion/Form/Sections/General/_code.html.twig' + template: '@SyliusAdmin/Promotion/Form/Sections/General/code.html.twig' description: - template: '@SyliusAdmin/Promotion/Form/Sections/General/_description.html.twig' + template: '@SyliusAdmin/Promotion/Form/Sections/General/description.html.twig' channels: - template: '@SyliusAdmin/Promotion/Form/Sections/General/_channels.html.twig' + template: '@SyliusAdmin/Promotion/Form/Sections/General/channels.html.twig' - 'sylius_admin.promotion.create.content.form.sections.configuration': - left: - template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/_left.html.twig' - right: - template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/_right.html.twig' - - 'sylius_admin.promotion.create.content.form.sections.configuration.left': + 'sylius_admin.promotion.create.content.form.sections.configuration#left': usage_limit: - template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/Left/_usageLimit.html.twig' + template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/usage_limit.html.twig' priority: - template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/Left/_priority.html.twig' + template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/priority.html.twig' starts_at: - template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/Left/_startsAt.html.twig' + template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/starts_at.html.twig' ends_at: - template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/Left/_endsAt.html.twig' + template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/ends_at.html.twig' - 'sylius_admin.promotion.create.content.form.sections.configuration.right': + 'sylius_admin.promotion.create.content.form.sections.configuration#right': header: - template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/Right/_header.html.twig' + template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/header.html.twig' coupon_based: - template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/Right/_couponBased.html.twig' + template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/coupon_based.html.twig' exclusive: - template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/Right/_exclusive.html.twig' + template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/exclusive.html.twig' applies_to_discounted: - template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/Right/_appliesToDiscounted.html.twig' + template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/applies_to_discounted.html.twig' 'sylius_admin.promotion.create.content.form.sections.rules_and_actions': rules: - template: '@SyliusAdmin/Promotion/Form/Sections/RulesAndActions/_rules.html.twig' + template: '@SyliusAdmin/Promotion/Form/Sections/RulesAndActions/rules.html.twig' actions: - template: '@SyliusAdmin/Promotion/Form/Sections/RulesAndActions/_actions.html.twig' + template: '@SyliusAdmin/Promotion/Form/Sections/RulesAndActions/actions.html.twig' diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/update.yaml b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/update.yaml index b6b71f725bd..2b321e1d0c7 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/update.yaml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/update.yaml @@ -13,56 +13,50 @@ twig_hooks: 'sylius_admin.promotion.update.content.form': sections: - template: '@SyliusAdmin/Promotion/Form/_sections.html.twig' + template: '@SyliusAdmin/Promotion/Form/sections.html.twig' 'sylius_admin.promotion.update.content.form.sections': general: - template: '@SyliusAdmin/Promotion/Form/Sections/_general.html.twig' + template: '@SyliusAdmin/Promotion/Form/Sections/general.html.twig' configuration: - template: '@SyliusAdmin/Promotion/Form/Sections/_configuration.html.twig' + template: '@SyliusAdmin/Promotion/Form/Sections/configuration.html.twig' translations: - template: '@SyliusAdmin/Promotion/Form/Sections/_translations.html.twig' + template: '@SyliusAdmin/Promotion/Form/Sections/translations.html.twig' rules_and_actions: - template: '@SyliusAdmin/Promotion/Form/Sections/_rulesAndActions.html.twig' + template: '@SyliusAdmin/Promotion/Form/Sections/rules_and_actions.html.twig' 'sylius_admin.promotion.update.content.form.sections.general': _name: - template: '@SyliusAdmin/Promotion/Form/Sections/General/_name.html.twig' + template: '@SyliusAdmin/Promotion/Form/Sections/General/name.html.twig' code: - template: '@SyliusAdmin/Promotion/Form/Sections/General/_code.html.twig' + template: '@SyliusAdmin/Promotion/Form/Sections/General/code.html.twig' description: - template: '@SyliusAdmin/Promotion/Form/Sections/General/_description.html.twig' + template: '@SyliusAdmin/Promotion/Form/Sections/General/description.html.twig' channels: - template: '@SyliusAdmin/Promotion/Form/Sections/General/_channels.html.twig' + template: '@SyliusAdmin/Promotion/Form/Sections/General/channels.html.twig' - 'sylius_admin.promotion.update.content.form.sections.configuration': - left: - template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/_left.html.twig' - right: - template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/_right.html.twig' - - 'sylius_admin.promotion.update.content.form.sections.configuration.left': + 'sylius_admin.promotion.update.content.form.sections.configuration#left': usage_limit: - template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/Left/_usageLimit.html.twig' + template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/usage_limit.html.twig' priority: - template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/Left/_priority.html.twig' + template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/priority.html.twig' starts_at: - template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/Left/_startsAt.html.twig' + template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/starts_at.html.twig' ends_at: - template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/Left/_endsAt.html.twig' + template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/ends_at.html.twig' - 'sylius_admin.promotion.update.content.form.sections.configuration.right': + 'sylius_admin.promotion.update.content.form.sections.configuration#right': header: - template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/Right/_header.html.twig' + template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/header.html.twig' coupon_based: - template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/Right/_couponBased.html.twig' + template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/coupon_based.html.twig' exclusive: - template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/Right/_exclusive.html.twig' + template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/exclusive.html.twig' applies_to_discounted: - template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/Right/_appliesToDiscounted.html.twig' + template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/applies_to_discounted.html.twig' 'sylius_admin.promotion.update.content.form.sections.rules_and_actions': rules: - template: '@SyliusAdmin/Promotion/Form/Sections/RulesAndActions/_rules.html.twig' + template: '@SyliusAdmin/Promotion/Form/Sections/RulesAndActions/rules.html.twig' actions: - template: '@SyliusAdmin/Promotion/Form/Sections/RulesAndActions/_actions.html.twig' + template: '@SyliusAdmin/Promotion/Form/Sections/RulesAndActions/actions.html.twig' diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/_left.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/_left.html.twig deleted file mode 100644 index 0e9191f954c..00000000000 --- a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/_left.html.twig +++ /dev/null @@ -1,9 +0,0 @@ -{% set main_hook = hook_name(hookable_data.parent_main_hook, 'left') %} -{% set fallback_hook = hook_name(hookable_data.parent_fallback_hook, 'left') %} - -
- {% hook [main_hook, fallback_hook] with hookable_data|merge({ - parent_main_hook: main_hook, - parent_fallback_hook: fallback_hook, - }) %} -
diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/_right.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/_right.html.twig deleted file mode 100644 index 9895de7b07b..00000000000 --- a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/_right.html.twig +++ /dev/null @@ -1,9 +0,0 @@ -{% set main_hook = hook_name(hookable_data.parent_main_hook, 'right') %} -{% set fallback_hook = hook_name(hookable_data.parent_fallback_hook, 'right') %} - -
- {% hook [main_hook, fallback_hook] with hookable_data|merge({ - parent_main_hook: main_hook, - parent_fallback_hook: fallback_hook, - }) %} -
diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Right/_appliesToDiscounted.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/applies_to_discounted.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Right/_appliesToDiscounted.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/applies_to_discounted.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Right/_couponBased.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/coupon_based.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Right/_couponBased.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/coupon_based.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Left/_endsAt.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/ends_at.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Left/_endsAt.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/ends_at.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Right/_exclusive.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/exclusive.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Right/_exclusive.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/exclusive.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Right/_header.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/header.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Right/_header.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/header.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Left/_priority.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/priority.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Left/_priority.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/priority.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Left/_startsAt.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/starts_at.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Left/_startsAt.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/starts_at.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Left/_usageLimit.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/usage_limit.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/Left/_usageLimit.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/usage_limit.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/_channels.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/channels.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/_channels.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/channels.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/_code.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/code.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/_code.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/code.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/_description.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/description.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/_description.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/description.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/_name.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/name.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/_name.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/name.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/RulesAndActions/_actions.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/RulesAndActions/actions.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/RulesAndActions/_actions.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/RulesAndActions/actions.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/RulesAndActions/_rules.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/RulesAndActions/rules.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/RulesAndActions/_rules.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/RulesAndActions/rules.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_configuration.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/configuration.html.twig similarity index 52% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_configuration.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/configuration.html.twig index 4e63809ec85..b2e6fb9b4e7 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_configuration.html.twig +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/configuration.html.twig @@ -13,6 +13,20 @@ parent_main_hook: main_hook, parent_fallback_hook: fallback_hook, }) %} + +
+ {% hook [main_hook ~ '#left', fallback_hook] with hookable_data|merge({ + parent_main_hook: main_hook, + parent_fallback_hook: fallback_hook, + }) %} +
+ +
+ {% hook [main_hook ~ '#right', fallback_hook] with hookable_data|merge({ + parent_main_hook: main_hook, + parent_fallback_hook: fallback_hook, + }) %} +
diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_general.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/general.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_general.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/general.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_rulesAndActions.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/rules_and_actions.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_rulesAndActions.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/rules_and_actions.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_translations.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/translations.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/_translations.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/translations.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/_sections.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/sections.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/_sections.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/sections.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/_form.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/form.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/_form.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/form.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/TwigComponent/Promotion/FormComponent.php b/src/Sylius/Bundle/AdminBundle/TwigComponent/Promotion/FormComponent.php index acea3d97df4..fc64bd377b9 100644 --- a/src/Sylius/Bundle/AdminBundle/TwigComponent/Promotion/FormComponent.php +++ b/src/Sylius/Bundle/AdminBundle/TwigComponent/Promotion/FormComponent.php @@ -25,7 +25,7 @@ use Symfony\UX\LiveComponent\DefaultActionTrait; use Symfony\UX\LiveComponent\LiveCollectionTrait; -#[AsLiveComponent(name: 'SyliusAdmin.Promotion.Form', template: '@SyliusAdmin/Promotion/_form.html.twig')] +#[AsLiveComponent(name: 'SyliusAdmin.Promotion.Form', template: '@SyliusAdmin/Promotion/form.html.twig')] final class FormComponent { use DefaultActionTrait; From a8f9c56a9167a2fbb662579c3df8b8d038fb8b99 Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Fri, 12 Apr 2024 07:52:43 +0200 Subject: [PATCH 25/39] [Behat][Admin] Revert removing getValidationMessage from Crud/CreatePage --- .../Behat/Page/Admin/Crud/CreatePage.php | 30 +++++++++++++++++++ .../Page/Admin/Crud/CreatePageInterface.php | 5 ++++ 2 files changed, 35 insertions(+) diff --git a/src/Sylius/Behat/Page/Admin/Crud/CreatePage.php b/src/Sylius/Behat/Page/Admin/Crud/CreatePage.php index dd1772662ca..7b69425e437 100644 --- a/src/Sylius/Behat/Page/Admin/Crud/CreatePage.php +++ b/src/Sylius/Behat/Page/Admin/Crud/CreatePage.php @@ -13,7 +13,9 @@ namespace Sylius\Behat\Page\Admin\Crud; +use Behat\Mink\Element\NodeElement; use Behat\Mink\Exception\DriverException; +use Behat\Mink\Exception\ElementNotFoundException; use Behat\Mink\Session; use FriendsOfBehat\PageObjectExtension\Page\SymfonyPage; use FriendsOfBehat\PageObjectExtension\Page\UnexpectedPageException; @@ -35,6 +37,21 @@ public function create(): void $this->getDocument()->pressButton('Create'); } + public function getValidationMessage(string $element): string + { + $foundElement = $this->getFieldElement($element); + if (null === $foundElement) { + throw new ElementNotFoundException($this->getSession(), 'Field element'); + } + + $validationMessage = $foundElement->find('css', '.invalid-feedback'); + if (null === $validationMessage) { + throw new ElementNotFoundException($this->getSession(), 'Validation message', 'css', '.invalid-feedback'); + } + + return $validationMessage->getText(); + } + public function getRouteName(): string { return $this->routeName; @@ -62,4 +79,17 @@ protected function verifyStatusCode(): void throw new UnexpectedPageException($message); } + + /** + * @throws ElementNotFoundException + */ + private function getFieldElement(string $element): ?NodeElement + { + $element = $this->getElement($element); + while (null !== $element && !$element->hasClass('field')) { + $element = $element->getParent(); + } + + return $element; + } } diff --git a/src/Sylius/Behat/Page/Admin/Crud/CreatePageInterface.php b/src/Sylius/Behat/Page/Admin/Crud/CreatePageInterface.php index a0b762c585e..35036020b19 100644 --- a/src/Sylius/Behat/Page/Admin/Crud/CreatePageInterface.php +++ b/src/Sylius/Behat/Page/Admin/Crud/CreatePageInterface.php @@ -18,6 +18,11 @@ interface CreatePageInterface extends SymfonyPageInterface { + /** + * @throws ElementNotFoundException + */ + public function getValidationMessage(string $element): string; + /** * @throws ElementNotFoundException */ From 769bcc78c3d04afee315e3d36ec240d724708fb0 Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Fri, 12 Apr 2024 07:53:18 +0200 Subject: [PATCH 26/39] [Behat][Admin] Introduce shared FormElement --- .../Behat/Element/Admin/Crud/FormElement.php | 47 +++++++++++++++++++ .../Admin/Crud/FormElementInterface.php | 22 +++++++++ .../Element/Admin/Promotion/FormElement.php | 30 +----------- .../Admin/Promotion/FormElementInterface.php | 6 +-- .../config/services/elements/admin.xml | 4 +- 5 files changed, 77 insertions(+), 32 deletions(-) create mode 100644 src/Sylius/Behat/Element/Admin/Crud/FormElement.php create mode 100644 src/Sylius/Behat/Element/Admin/Crud/FormElementInterface.php diff --git a/src/Sylius/Behat/Element/Admin/Crud/FormElement.php b/src/Sylius/Behat/Element/Admin/Crud/FormElement.php new file mode 100644 index 00000000000..1b41c771819 --- /dev/null +++ b/src/Sylius/Behat/Element/Admin/Crud/FormElement.php @@ -0,0 +1,47 @@ +getFieldElement($element); + if (null === $foundElement) { + throw new ElementNotFoundException($this->getSession(), 'Field element'); + } + + $validationMessage = $foundElement->find('css', '.invalid-feedback'); + if (null === $validationMessage) { + throw new ElementNotFoundException($this->getSession(), 'Validation message', 'css', '.invalid-feedback'); + } + + return $validationMessage->getText(); + } + + /** @throws ElementNotFoundException */ + private function getFieldElement(string $element): ?NodeElement + { + $element = $this->getElement($element); + while (null !== $element && !$element->hasClass('field')) { + $element = $element->getParent(); + } + + return $element; + } +} diff --git a/src/Sylius/Behat/Element/Admin/Crud/FormElementInterface.php b/src/Sylius/Behat/Element/Admin/Crud/FormElementInterface.php new file mode 100644 index 00000000000..364e3ec3731 --- /dev/null +++ b/src/Sylius/Behat/Element/Admin/Crud/FormElementInterface.php @@ -0,0 +1,22 @@ +hasElement('action_amount'); } - public function getValidationMessage(string $element): string - { - $foundElement = $this->getFieldElement($element); - if (null === $foundElement) { - throw new ElementNotFoundException($this->getSession(), 'Field element'); - } - - $validationMessage = $foundElement->find('css', '.invalid-feedback'); - if (null === $validationMessage) { - throw new ElementNotFoundException($this->getSession(), 'Validation message', 'css', '.invalid-feedback'); - } - - return $validationMessage->getText(); - } - public function getValidationMessageForAction(): string { $actionForm = $this->getLastAction(); @@ -297,17 +282,6 @@ private function getChannelConfigurationOfLastRule(string $channelCode): NodeEle ; } - /** @throws ElementNotFoundException */ - private function getFieldElement(string $element): ?NodeElement - { - $element = $this->getElement($element); - while (null !== $element && !$element->hasClass('field')) { - $element = $element->getParent(); - } - - return $element; - } - private function waitForFormUpdate(): void { $form = $this->getElement('form'); diff --git a/src/Sylius/Behat/Element/Admin/Promotion/FormElementInterface.php b/src/Sylius/Behat/Element/Admin/Promotion/FormElementInterface.php index a479e50428d..f018a71874a 100644 --- a/src/Sylius/Behat/Element/Admin/Promotion/FormElementInterface.php +++ b/src/Sylius/Behat/Element/Admin/Promotion/FormElementInterface.php @@ -13,7 +13,9 @@ namespace Sylius\Behat\Element\Admin\Promotion; -interface FormElementInterface +use Sylius\Behat\Element\Admin\Crud\FormElementInterface as BaseFormElementInterface; + +interface FormElementInterface extends BaseFormElementInterface { public function setPriority(?int $priority): void; @@ -61,8 +63,6 @@ public function checkIfRuleConfigurationFormIsVisible(): bool; public function checkIfActionConfigurationFormIsVisible(): bool; - public function getValidationMessage(string $element): string; - public function getValidationMessageForAction(): string; public function getValidationMessageForTranslation(string $element, string $localeCode): string; diff --git a/src/Sylius/Behat/Resources/config/services/elements/admin.xml b/src/Sylius/Behat/Resources/config/services/elements/admin.xml index 622aee72399..b9c3ccbe71a 100644 --- a/src/Sylius/Behat/Resources/config/services/elements/admin.xml +++ b/src/Sylius/Behat/Resources/config/services/elements/admin.xml @@ -16,6 +16,8 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd" > + + @@ -55,7 +57,7 @@ From f93ae5b869f2000f222496a3aafa2c43cde9e616 Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Fri, 12 Apr 2024 10:41:21 +0200 Subject: [PATCH 27/39] [Admin] Remove unneeded labels for promotion rules and actions --- .../Promotion/Form/Sections/RulesAndActions/actions.html.twig | 2 +- .../Promotion/Form/Sections/RulesAndActions/rules.html.twig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/RulesAndActions/actions.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/RulesAndActions/actions.html.twig index f02632980d8..f7640a0a5dc 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/RulesAndActions/actions.html.twig +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/RulesAndActions/actions.html.twig @@ -10,7 +10,7 @@
- {{ form_row(hookable_data.form.actions) }} + {{ form_row(hookable_data.form.actions, {label: false}) }} {% hook [main_hook, fallback_hook] with hookable_data|merge({ parent_main_hook: main_hook, diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/RulesAndActions/rules.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/RulesAndActions/rules.html.twig index 228f9085dc5..4a3b6a73e45 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/RulesAndActions/rules.html.twig +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/RulesAndActions/rules.html.twig @@ -10,7 +10,7 @@
- {{ form_row(hookable_data.form.rules) }} + {{ form_row(hookable_data.form.rules, {label: false}) }} {% hook [main_hook, fallback_hook] with hookable_data|merge({ parent_main_hook: main_hook, From c7ee6efd423ac935c5b650219d2613bb761738d1 Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Fri, 12 Apr 2024 13:37:59 +0200 Subject: [PATCH 28/39] [Behat] Change driver of some scenarios to chromedriver --- ...ng_promotion_with_action_in_different_channels.feature | 2 +- .../adding_promotion_with_filter.feature | 8 ++++---- .../adding_promotion_with_rule.feature | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/features/admin/promotion/managing_promotions/adding_promotion_with_action_in_different_channels.feature b/features/admin/promotion/managing_promotions/adding_promotion_with_action_in_different_channels.feature index 97e62b3376b..da704d642d4 100644 --- a/features/admin/promotion/managing_promotions/adding_promotion_with_action_in_different_channels.feature +++ b/features/admin/promotion/managing_promotions/adding_promotion_with_action_in_different_channels.feature @@ -9,7 +9,7 @@ Feature: Adding a new promotion with action configured in different channels And the store also operates on another channel named "Web-GB" in "GBP" currency And I am logged in as an administrator - @ui @javascript @api + @ui @mink:chromedriver @api Scenario: Adding a new promotion with item fixed discount When I want to create a new promotion And I specify its code as "20_for_all_products" diff --git a/features/admin/promotion/managing_promotions/adding_promotion_with_filter.feature b/features/admin/promotion/managing_promotions/adding_promotion_with_filter.feature index fcbb7732d90..673b7f81ece 100644 --- a/features/admin/promotion/managing_promotions/adding_promotion_with_filter.feature +++ b/features/admin/promotion/managing_promotions/adding_promotion_with_filter.feature @@ -30,7 +30,7 @@ Feature: Adding promotion with filter Then I should be notified that it has been successfully created And the "$10 discount for (almost) all products!" promotion should appear in the registry - @api @ui @javascript + @api @ui @mink:chromedriver Scenario: Adding a promotion with fixed discount for all t-shirts Given the store classifies its products as "T-Shirts" and "Mugs" When I want to create a new promotion @@ -42,7 +42,7 @@ Feature: Adding promotion with filter Then I should be notified that it has been successfully created And the "$10 discount for all T-Shirts!" promotion should appear in the registry - @api @ui @javascript + @api @ui @mink:chromedriver Scenario: Adding a promotion with fixed discount for PHP T-Shirt Given the store has a product "PHP T-Shirt" priced at "$100.00" When I want to create a new promotion @@ -76,7 +76,7 @@ Feature: Adding promotion with filter Then I should be notified that it has been successfully created And the "$10 discount for (almost) all products!" promotion should appear in the registry - @api @ui @javascript + @api @ui @mink:chromedriver Scenario: Adding a promotion with 10% percentage discount for all t-shirts Given the store classifies its products as "T-Shirts" and "Mugs" When I want to create a new promotion @@ -88,7 +88,7 @@ Feature: Adding promotion with filter Then I should be notified that it has been successfully created And the "$10 discount for all T-Shirts!" promotion should appear in the registry - @api @ui @javascript + @api @ui @mink:chromedriver Scenario: Adding a promotion with 10% percentage discount for PHP T-Shirt Given the store has a product "PHP T-Shirt" priced at "$100.00" When I want to create a new promotion diff --git a/features/admin/promotion/managing_promotions/adding_promotion_with_rule.feature b/features/admin/promotion/managing_promotions/adding_promotion_with_rule.feature index 8014a1e5f19..30cdcffe795 100644 --- a/features/admin/promotion/managing_promotions/adding_promotion_with_rule.feature +++ b/features/admin/promotion/managing_promotions/adding_promotion_with_rule.feature @@ -9,7 +9,7 @@ Feature: Adding a new promotion with rule And the store classifies its products as "T-Shirts" and "Mugs" And I am logged in as an administrator - @api @ui @javascript + @api @ui @mink:chromedriver Scenario: Adding a new promotion with taxon rule When I want to create a new promotion And I specify its code as "HOLIDAY_SALE" @@ -19,7 +19,7 @@ Feature: Adding a new promotion with rule Then I should be notified that it has been successfully created And the "Holiday sale" promotion should appear in the registry - @api @ui @javascript + @api @ui @mink:chromedriver Scenario: Adding a new promotion with total price of items from taxon rule When I want to create a new promotion And I specify its code as "100_MUGS_PROMOTION" @@ -29,7 +29,7 @@ Feature: Adding a new promotion with rule Then I should be notified that it has been successfully created And the "100 Mugs promotion" promotion should appear in the registry - @api @ui @javascript + @api @ui @mink:chromedriver Scenario: Adding a new promotion with contains product rule Given the store has a product "PHP T-Shirt" priced at "$100.00" When I want to create a new promotion From f2b88d2b945d13cee262e3196ee49024b6d4426b Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Fri, 12 Apr 2024 09:56:52 +0200 Subject: [PATCH 29/39] [Behat] Minor fixes --- ...romotion_with_rule_in_different_channels.feature | 3 ++- .../promotion_validation.feature | 2 +- .../Behat/Element/Admin/Promotion/FormElement.php | 13 ++++++------- src/Sylius/Behat/Page/Admin/Product/FormTrait.php | 2 +- src/Sylius/Behat/Service/TabsHelper.php | 4 +--- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/features/admin/promotion/managing_promotions/adding_promotion_with_rule_in_different_channels.feature b/features/admin/promotion/managing_promotions/adding_promotion_with_rule_in_different_channels.feature index 144629afd44..54f58af177b 100644 --- a/features/admin/promotion/managing_promotions/adding_promotion_with_rule_in_different_channels.feature +++ b/features/admin/promotion/managing_promotions/adding_promotion_with_rule_in_different_channels.feature @@ -9,7 +9,8 @@ Feature: Adding a new promotion with rule configured in different channels And the store operates on a channel named "Web-GB" in "GBP" currency And I am logged in as an administrator - @api @ui @mink:chromedriver +# @api + @ui @mink:chromedriver Scenario: Adding a new promotion with total price of items from taxon rule When I want to create a new promotion And I specify its code as "100_IN_EVERY_CURRENCY" diff --git a/features/admin/promotion/managing_promotions/promotion_validation.feature b/features/admin/promotion/managing_promotions/promotion_validation.feature index 3ffb1944aaa..b0e22f895f9 100644 --- a/features/admin/promotion/managing_promotions/promotion_validation.feature +++ b/features/admin/promotion/managing_promotions/promotion_validation.feature @@ -69,7 +69,7 @@ Feature: Promotion validation And I try to save my changes Then I should be notified that promotion cannot end before it starts - @api @ui @mink:chromedriver + @api @ui Scenario: Adding a promotion with label exceeding 255 characters Given there is a promotion "Christmas sale" When I want to modify this promotion diff --git a/src/Sylius/Behat/Element/Admin/Promotion/FormElement.php b/src/Sylius/Behat/Element/Admin/Promotion/FormElement.php index 09fd5b595f9..4b347b1442d 100644 --- a/src/Sylius/Behat/Element/Admin/Promotion/FormElement.php +++ b/src/Sylius/Behat/Element/Admin/Promotion/FormElement.php @@ -84,7 +84,6 @@ public function checkChannel(string $name): void public function setLabel(string $label, string $localeCode): void { - $this->getElement('translation_tab', ['%locale_code%' => $localeCode])->press(); $this->getElement('label', ['%locale_code%' => $localeCode])->setValue($label); } @@ -160,9 +159,8 @@ public function selectAutocompleteRuleOptions(array $values, ?string $channelCod $this->getLastRule()->find('css', $locator)->getXpath(), $value, ); + $this->waitForFormUpdate(); } - - $this->waitForFormUpdate(); } public function selectAutocompleteFilterOptions(array $values, string $channelCode, string $filterType): void @@ -204,7 +202,6 @@ public function getValidationMessageForAction(): string public function getValidationMessageForTranslation(string $element, string $localeCode): string { - $this->getElement('translation_tab', ['%locale_code%' => $localeCode])->press(); $foundElement = $this->getElement($element, ['%locale_code%' => $localeCode])->getParent(); $validationMessage = $foundElement->find('css', '.invalid-feedback'); @@ -276,10 +273,12 @@ private function getChannelConfigurationOfLastRule(string $channelCode): NodeEle $lastRule = $this->getLastRule(); TabsHelper::switchTab($this->getSession(), $lastRule, $channelCode); +// $this->waitForFormUpdate(); - return $lastRule - ->find('css', sprintf('[id^="sylius_promotion_rules_"][id$="_configuration_%s"]', $channelCode)) - ; + return $lastRule->find( + 'css', + sprintf('[id^="sylius_promotion_rules_"][id$="_configuration_%s"]', $channelCode), + ); } private function waitForFormUpdate(): void diff --git a/src/Sylius/Behat/Page/Admin/Product/FormTrait.php b/src/Sylius/Behat/Page/Admin/Product/FormTrait.php index f5008bffc79..d0cfa1ba282 100644 --- a/src/Sylius/Behat/Page/Admin/Product/FormTrait.php +++ b/src/Sylius/Behat/Page/Admin/Product/FormTrait.php @@ -43,7 +43,7 @@ public function getDefinedFormElements(): array 'product_attribute_input' => 'input[name="product_attributes"]', 'product_attribute_tab' => '[data-test-product-attribute-tab="%name%"]', 'product_options_autocomplete' => '[data-test-product-options-autocomplete]', - 'product_translation_accordion' => '[data-test-product-translation-accordion="%localeCode%"]', + 'product_translation_accordion' => '[data-test-product-translations-accordion="%localeCode%"]', 'side_navigation_tab' => '[data-test-side-navigation-tab="%name%"]', ]; } diff --git a/src/Sylius/Behat/Service/TabsHelper.php b/src/Sylius/Behat/Service/TabsHelper.php index b6dfa1640ed..50597bf6e79 100644 --- a/src/Sylius/Behat/Service/TabsHelper.php +++ b/src/Sylius/Behat/Service/TabsHelper.php @@ -34,8 +34,6 @@ public static function switchTab(Session $session, NodeElement $tabsContainer, s $tab->click(); - $tabContent = $tabsContainer->find('css', sprintf('#%s', $dataTabHook)); - - $session->getPage()->waitFor(5, fn () => $tabContent->isVisible()); + $session->getPage()->waitFor(5, fn () => $tab->hasClass('active')); } } From 498f0f296ef665d94d96d1892313e3deafc74e1a Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Mon, 15 Apr 2024 07:38:57 +0200 Subject: [PATCH 30/39] [Admin] Bring back delete button for promotion rules and actions --- .../adding_promotion.feature | 8 +++++ .../adding_promotion_with_rule.feature | 8 ----- .../editing_promotion.feature | 12 ++++++- .../Ui/Admin/ManagingPromotionsContext.php | 34 ++++++++++++++++++- .../Element/Admin/Promotion/FormElement.php | 13 ++++++- .../Admin/Promotion/FormElementInterface.php | 4 +++ .../Form/Extension/PromotionTypeExtension.php | 6 ++++ .../views/Shared/form_theme.html.twig | 2 ++ .../Factory/PromotionRuleFactoryInterface.php | 1 - 9 files changed, 76 insertions(+), 12 deletions(-) diff --git a/features/admin/promotion/managing_promotions/adding_promotion.feature b/features/admin/promotion/managing_promotions/adding_promotion.feature index 8ca1c91bea6..cc1a9b96e27 100644 --- a/features/admin/promotion/managing_promotions/adding_promotion.feature +++ b/features/admin/promotion/managing_promotions/adding_promotion.feature @@ -75,3 +75,11 @@ Feature: Adding a new promotion And I add it Then I should be notified that it has been successfully created And the "Full metal promotion" promotion should not applies to discounted items + + @ui @javascript @no-api + Scenario: Seeing rule and action configuration forms + When I want to create a new promotion + And I add a new rule + And I add a new action + Then I should see the rule configuration form + And I should see the action configuration form diff --git a/features/admin/promotion/managing_promotions/adding_promotion_with_rule.feature b/features/admin/promotion/managing_promotions/adding_promotion_with_rule.feature index 30cdcffe795..74127af5b0e 100644 --- a/features/admin/promotion/managing_promotions/adding_promotion_with_rule.feature +++ b/features/admin/promotion/managing_promotions/adding_promotion_with_rule.feature @@ -50,11 +50,3 @@ Feature: Adding a new promotion with rule And I add it Then I should be notified that it has been successfully created And the "Wholesale promotion" promotion should appear in the registry - - @ui @javascript @no-api - Scenario: Adding a new promotion of default type with one action - When I want to create a new promotion - And I add a new rule - And I add a new action - Then I should see the rule configuration form - And I should see the action configuration form diff --git a/features/admin/promotion/managing_promotions/editing_promotion.feature b/features/admin/promotion/managing_promotions/editing_promotion.feature index 2eabd044bd7..965214a267f 100644 --- a/features/admin/promotion/managing_promotions/editing_promotion.feature +++ b/features/admin/promotion/managing_promotions/editing_promotion.feature @@ -62,7 +62,7 @@ Feature: Editing promotion Then I should be able to modify a "Christmas sale" promotion @ui @no-api - Scenario: Remove priority from existing promotion + Scenario: Removing priority from existing promotion When I want to modify a "Christmas sale" promotion And I remove its priority And I save my changes @@ -76,3 +76,13 @@ Feature: Editing promotion And I save my changes Then I should be notified that it has been successfully edited And the "Christmas sale" promotion should have priority 1 + + @ui @javascript + Scenario: Removing rule and action from existing promotion + Given the promotion gives "$10.00" discount to every order with quantity at least 1 + When I want to modify a "Holiday sale" promotion + And I remove its last rule + And I remove its last action + And I save my changes + Then I should not see the rule configuration form + And I should not see the action configuration form diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php index 0e9469df38a..32267ce2ad2 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php @@ -273,6 +273,22 @@ public function iCheckThePromotion(string $promotionName): void $this->indexPage->checkResourceOnPage(['name' => $promotionName]); } + /** + * @When I remove its last rule + */ + public function iRemoveItsLastRule(): void + { + $this->formElement->removeLastRule(); + } + + /** + * @When I remove its last action + */ + public function iRemoveItsLastAction(): void + { + $this->formElement->removeLastAction(); + } + /** * @When I delete them */ @@ -772,6 +788,14 @@ public function iShouldSeeTheRuleConfigurationForm(): void Assert::true($this->formElement->checkIfRuleConfigurationFormIsVisible(), 'Cart promotion rule configuration form is not visible.'); } + /** + * @Then I should not see the rule configuration form + */ + public function iShouldNotSeeTheRuleConfigurationForm(): void + { + Assert::false($this->formElement->checkIfRuleConfigurationFormIsVisible(), 'Cart promotion rule configuration form is visible.'); + } + /** * @Then it should have :amount of order percentage discount */ @@ -791,11 +815,19 @@ public function itShouldHaveOfItemPercentageDiscount(string $amount, ChannelInte /** * @Then I should see the action configuration form */ - public function iShouldSeeTheActionConfigurationForm() + public function iShouldSeeTheActionConfigurationForm(): void { Assert::true($this->formElement->checkIfActionConfigurationFormIsVisible(), 'Cart promotion action configuration form is not visible.'); } + /** + * @Then I should not see the action configuration form + */ + public function iShouldNotSeeTheActionConfigurationForm(): void + { + Assert::false($this->formElement->checkIfActionConfigurationFormIsVisible(), 'Cart promotion action configuration form is visible.'); + } + /** * @Then /^I should see that the rule for ("[^"]+" channel) has (\d+) validation errors?$/ */ diff --git a/src/Sylius/Behat/Element/Admin/Promotion/FormElement.php b/src/Sylius/Behat/Element/Admin/Promotion/FormElement.php index 4b347b1442d..2717d77b9e1 100644 --- a/src/Sylius/Behat/Element/Admin/Promotion/FormElement.php +++ b/src/Sylius/Behat/Element/Admin/Promotion/FormElement.php @@ -103,6 +103,12 @@ public function addAction(?string $actionName): void } } + public function removeLastAction(): void + { + $this->getLastAction()->find('css', 'button[data-test-delete-action]')->press(); + $this->waitForFormUpdate(); + } + public function fillActionOption(string $option, string $value): void { $this->getLastAction()->fillField($option, $value); @@ -130,6 +136,12 @@ public function addRule(?string $ruleName): void } } + public function removeLastRule(): void + { + $this->getLastRule()->find('css', 'button[data-test-delete-rule]')->press(); + $this->waitForFormUpdate(); + } + public function selectRuleOption(string $option, string $value, bool $multiple = false): void { $this->getLastRule()->find('named', ['select', $option])->selectOption($value, $multiple); @@ -273,7 +285,6 @@ private function getChannelConfigurationOfLastRule(string $channelCode): NodeEle $lastRule = $this->getLastRule(); TabsHelper::switchTab($this->getSession(), $lastRule, $channelCode); -// $this->waitForFormUpdate(); return $lastRule->find( 'css', diff --git a/src/Sylius/Behat/Element/Admin/Promotion/FormElementInterface.php b/src/Sylius/Behat/Element/Admin/Promotion/FormElementInterface.php index f018a71874a..a91cef36b41 100644 --- a/src/Sylius/Behat/Element/Admin/Promotion/FormElementInterface.php +++ b/src/Sylius/Behat/Element/Admin/Promotion/FormElementInterface.php @@ -41,6 +41,8 @@ public function hasLabel(string $label, string $localeCode): bool; public function addAction(?string $actionName): void; + public function removeLastAction(): void; + public function fillActionOption(string $option, string $value): void; public function fillActionOptionForChannel(string $channelCode, string $option, string $value): void; @@ -49,6 +51,8 @@ public function selectActionOption(string $option, string $value, bool $multiple public function addRule(?string $ruleName): void; + public function removeLastRule(): void; + public function selectRuleOption(string $option, string $value, bool $multiple = false): void; public function fillRuleOption(string $option, string $value): void; diff --git a/src/Sylius/Bundle/AdminBundle/Form/Extension/PromotionTypeExtension.php b/src/Sylius/Bundle/AdminBundle/Form/Extension/PromotionTypeExtension.php index e03af88e38b..d137427acdf 100644 --- a/src/Sylius/Bundle/AdminBundle/Form/Extension/PromotionTypeExtension.php +++ b/src/Sylius/Bundle/AdminBundle/Form/Extension/PromotionTypeExtension.php @@ -34,6 +34,12 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'button_add_options' => [ 'label' => 'sylius.ui.add_rule', ], + 'button_delete_options' => [ + 'label' => 'sylius.ui.delete', +// 'attr' => [ +// 'class' => 'btn btn-outline-danger', +// ], + ] ]) ->add('actions', LiveCollectionType::class, [ 'entry_type' => PromotionActionType::class, diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/form_theme.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/form_theme.html.twig index 6441e6476df..3bc7bd45561 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/form_theme.html.twig +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/form_theme.html.twig @@ -31,6 +31,7 @@ {{- form_label(form) -}} {{- form_widget(form) -}} {{- form_errors(form) -}} + {{- form_row(button_delete, sylius_test_form_attribute('delete-action')) -}}
{% endblock %} @@ -41,6 +42,7 @@ {{- form_label(form) -}} {{- form_widget(form) -}} {{- form_errors(form) -}} + {{- form_row(button_delete, sylius_test_form_attribute('delete-rule')) -}}
{% endblock %} diff --git a/src/Sylius/Component/Core/Factory/PromotionRuleFactoryInterface.php b/src/Sylius/Component/Core/Factory/PromotionRuleFactoryInterface.php index e06844ba482..73aed301241 100644 --- a/src/Sylius/Component/Core/Factory/PromotionRuleFactoryInterface.php +++ b/src/Sylius/Component/Core/Factory/PromotionRuleFactoryInterface.php @@ -29,7 +29,6 @@ public function createItemTotal(string $channelCode, int $amount): PromotionRule public function createHasTaxon(array $taxons): PromotionRuleInterface; - public function createItemsFromTaxonTotal(string $channelCode, string $taxonCode, int $amount): PromotionRuleInterface; public function createNthOrder(int $nth): PromotionRuleInterface; From 812eb02a1a0c75885b814d7cef88c5f5d1bfc829 Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Mon, 15 Apr 2024 08:20:06 +0200 Subject: [PATCH 31/39] [Admin] Fix submenu for managing coupons on promotion index page --- .../Resources/config/grids/promotion.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/grids/promotion.yml b/src/Sylius/Bundle/AdminBundle/Resources/config/grids/promotion.yml index 7687e1f6f3a..8d88a58cd2b 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/grids/promotion.yml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/grids/promotion.yml @@ -62,6 +62,13 @@ sylius_grid: create: type: create item: + update: + type: update + delete: + type: delete + archive: + type: archive + subitem: coupons: type: links label: sylius.ui.manage_coupons @@ -87,12 +94,6 @@ sylius_grid: route: sylius_admin_promotion_coupon_generate parameters: promotionId: resource.id - update: - type: update - delete: - type: delete - archive: - type: archive bulk: delete: type: delete From 666344d6091578bcdabc5491a681eef8be7b40af Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Mon, 15 Apr 2024 10:25:38 +0200 Subject: [PATCH 32/39] [Admin] Rename promotion form component --- .../Resources/config/app/twig_hooks/promotion/create.yaml | 2 +- .../Resources/config/app/twig_hooks/promotion/update.yaml | 2 +- .../AdminBundle/TwigComponent/Promotion/FormComponent.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/create.yaml b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/create.yaml index 56612b8b67c..85f43908dab 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/create.yaml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/create.yaml @@ -2,7 +2,7 @@ twig_hooks: hooks: 'sylius_admin.promotion.create.content': form: - component: 'SyliusAdmin.Promotion.Form' + component: 'sylius_admin:promotion:form' data: resource: '@=resource' form: '@=form' diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/update.yaml b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/update.yaml index 2b321e1d0c7..17ea6aa12a6 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/update.yaml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/update.yaml @@ -2,7 +2,7 @@ twig_hooks: hooks: 'sylius_admin.promotion.update.content': form: - component: 'SyliusAdmin.Promotion.Form' + component: 'sylius_admin:promotion:form' data: resource: '@=resource' form: '@=form' diff --git a/src/Sylius/Bundle/AdminBundle/TwigComponent/Promotion/FormComponent.php b/src/Sylius/Bundle/AdminBundle/TwigComponent/Promotion/FormComponent.php index fc64bd377b9..ff6dad761f8 100644 --- a/src/Sylius/Bundle/AdminBundle/TwigComponent/Promotion/FormComponent.php +++ b/src/Sylius/Bundle/AdminBundle/TwigComponent/Promotion/FormComponent.php @@ -25,7 +25,7 @@ use Symfony\UX\LiveComponent\DefaultActionTrait; use Symfony\UX\LiveComponent\LiveCollectionTrait; -#[AsLiveComponent(name: 'SyliusAdmin.Promotion.Form', template: '@SyliusAdmin/Promotion/form.html.twig')] +#[AsLiveComponent(name: 'sylius_admin:promotion:form', template: '@SyliusAdmin/Promotion/form.html.twig')] final class FormComponent { use DefaultActionTrait; From 756965ce544220ce60ee9c1810c316e7b634db4a Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Mon, 15 Apr 2024 11:08:55 +0200 Subject: [PATCH 33/39] [Admin] Apply snake_case to promotion templates names --- .../Resources/config/app/config.yml | 2 +- .../app/twig_hooks/promotion/create.yaml | 38 +++++++++---------- .../app/twig_hooks/promotion/update.yaml | 38 +++++++++---------- .../config/grids/catalog_promotion.yaml | 2 +- .../Resources/config/grids/promotion.yml | 4 +- .../Action/deleteCatalogPromotion.html.twig | 0 .../Grid/Field/state.html.twig | 0 .../{Promotion => promotion}/form.html.twig | 0 .../form}/sections.html.twig | 0 .../form/sections}/configuration.html.twig | 0 .../applies_to_discounted.html.twig | 0 .../configuration}/coupon_based.html.twig | 0 .../sections/configuration}/ends_at.html.twig | 0 .../configuration}/exclusive.html.twig | 0 .../sections/configuration}/header.html.twig | 0 .../configuration}/priority.html.twig | 0 .../configuration}/starts_at.html.twig | 0 .../configuration}/usage_limit.html.twig | 0 .../form/sections}/general.html.twig | 0 .../form/sections/general}/channels.html.twig | 0 .../form/sections/general}/code.html.twig | 0 .../sections/general}/description.html.twig | 0 .../form/sections/general}/name.html.twig | 0 .../sections}/rules_and_actions.html.twig | 0 .../rules_and_actions}/actions.html.twig | 0 .../rules_and_actions}/rules.html.twig | 0 .../form/sections}/translations.html.twig | 0 .../grid/field}/priority.html.twig | 0 .../grid/field}/usage.html.twig | 0 .../TwigComponent/Promotion/FormComponent.php | 2 +- 30 files changed, 43 insertions(+), 43 deletions(-) rename src/Sylius/Bundle/AdminBundle/Resources/views/{Promotion => CatalogPromotion}/Grid/Action/deleteCatalogPromotion.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/{Promotion => CatalogPromotion}/Grid/Field/state.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/{Promotion => promotion}/form.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/{Promotion/Form => promotion/form}/sections.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/{Promotion/Form/Sections => promotion/form/sections}/configuration.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/{Promotion/Form/Sections/Configuration => promotion/form/sections/configuration}/applies_to_discounted.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/{Promotion/Form/Sections/Configuration => promotion/form/sections/configuration}/coupon_based.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/{Promotion/Form/Sections/Configuration => promotion/form/sections/configuration}/ends_at.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/{Promotion/Form/Sections/Configuration => promotion/form/sections/configuration}/exclusive.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/{Promotion/Form/Sections/Configuration => promotion/form/sections/configuration}/header.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/{Promotion/Form/Sections/Configuration => promotion/form/sections/configuration}/priority.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/{Promotion/Form/Sections/Configuration => promotion/form/sections/configuration}/starts_at.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/{Promotion/Form/Sections/Configuration => promotion/form/sections/configuration}/usage_limit.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/{Promotion/Form/Sections => promotion/form/sections}/general.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/{Promotion/Form/Sections/General => promotion/form/sections/general}/channels.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/{Promotion/Form/Sections/General => promotion/form/sections/general}/code.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/{Promotion/Form/Sections/General => promotion/form/sections/general}/description.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/{Promotion/Form/Sections/General => promotion/form/sections/general}/name.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/{Promotion/Form/Sections => promotion/form/sections}/rules_and_actions.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/{Promotion/Form/Sections/RulesAndActions => promotion/form/sections/rules_and_actions}/actions.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/{Promotion/Form/Sections/RulesAndActions => promotion/form/sections/rules_and_actions}/rules.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/{Promotion/Form/Sections => promotion/form/sections}/translations.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/{Promotion/Grid/Field => promotion/grid/field}/priority.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/Resources/views/{Promotion/Grid/Field => promotion/grid/field}/usage.html.twig (100%) diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/app/config.yml b/src/Sylius/Bundle/AdminBundle/Resources/config/app/config.yml index 4014da4db92..344389d905d 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/app/config.yml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/app/config.yml @@ -58,7 +58,7 @@ sylius_admin: show: '@SyliusAdmin/Shared/Grid/ItemAction/_show.html.twig' update: '@SyliusAdmin/Shared/Grid/ItemAction/_update.html.twig' ship_with_tracking_code: '@SyliusAdmin/Shipment/Grid/Action/shipWithTrackingCode.html.twig' - delete_catalog_promotion: "@SyliusAdmin/Promotion/Grid/Action/deleteCatalogPromotion.html.twig" + delete_catalog_promotion: "@SyliusAdmin/CatalogPromotion/Grid/Action/deleteCatalogPromotion.html.twig" sylius_grid: templates: diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/create.yaml b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/create.yaml index 85f43908dab..f0469c40d66 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/create.yaml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/create.yaml @@ -13,50 +13,50 @@ twig_hooks: 'sylius_admin.promotion.create.content.form': sections: - template: '@SyliusAdmin/Promotion/Form/sections.html.twig' + template: '@SyliusAdmin/promotion/form/sections.html.twig' 'sylius_admin.promotion.create.content.form.sections': general: - template: '@SyliusAdmin/Promotion/Form/Sections/general.html.twig' + template: '@SyliusAdmin/promotion/form/sections/general.html.twig' configuration: - template: '@SyliusAdmin/Promotion/Form/Sections/configuration.html.twig' + template: '@SyliusAdmin/promotion/form/sections/configuration.html.twig' translations: - template: '@SyliusAdmin/Promotion/Form/Sections/translations.html.twig' + template: '@SyliusAdmin/promotion/form/sections/translations.html.twig' rules_and_actions: - template: '@SyliusAdmin/Promotion/Form/Sections/rules_and_actions.html.twig' + template: '@SyliusAdmin/promotion/form/sections/rules_and_actions.html.twig' 'sylius_admin.promotion.create.content.form.sections.general': _name: - template: '@SyliusAdmin/Promotion/Form/Sections/General/name.html.twig' + template: '@SyliusAdmin/promotion/form/sections/general/name.html.twig' code: - template: '@SyliusAdmin/Promotion/Form/Sections/General/code.html.twig' + template: '@SyliusAdmin/promotion/form/sections/general/code.html.twig' description: - template: '@SyliusAdmin/Promotion/Form/Sections/General/description.html.twig' + template: '@SyliusAdmin/promotion/form/sections/general/description.html.twig' channels: - template: '@SyliusAdmin/Promotion/Form/Sections/General/channels.html.twig' + template: '@SyliusAdmin/promotion/form/sections/general/channels.html.twig' 'sylius_admin.promotion.create.content.form.sections.configuration#left': usage_limit: - template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/usage_limit.html.twig' + template: '@SyliusAdmin/promotion/form/sections/configuration/usage_limit.html.twig' priority: - template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/priority.html.twig' + template: '@SyliusAdmin/promotion/form/sections/configuration/priority.html.twig' starts_at: - template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/starts_at.html.twig' + template: '@SyliusAdmin/promotion/form/sections/configuration/starts_at.html.twig' ends_at: - template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/ends_at.html.twig' + template: '@SyliusAdmin/promotion/form/sections/configuration/ends_at.html.twig' 'sylius_admin.promotion.create.content.form.sections.configuration#right': header: - template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/header.html.twig' + template: '@SyliusAdmin/promotion/form/sections/configuration/header.html.twig' coupon_based: - template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/coupon_based.html.twig' + template: '@SyliusAdmin/promotion/form/sections/configuration/coupon_based.html.twig' exclusive: - template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/exclusive.html.twig' + template: '@SyliusAdmin/promotion/form/sections/configuration/exclusive.html.twig' applies_to_discounted: - template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/applies_to_discounted.html.twig' + template: '@SyliusAdmin/promotion/form/sections/configuration/applies_to_discounted.html.twig' 'sylius_admin.promotion.create.content.form.sections.rules_and_actions': rules: - template: '@SyliusAdmin/Promotion/Form/Sections/RulesAndActions/rules.html.twig' + template: '@SyliusAdmin/promotion/form/sections/rules_and_actions/rules.html.twig' actions: - template: '@SyliusAdmin/Promotion/Form/Sections/RulesAndActions/actions.html.twig' + template: '@SyliusAdmin/promotion/form/sections/rules_and_actions/actions.html.twig' diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/update.yaml b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/update.yaml index 17ea6aa12a6..4e84c8dfea2 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/update.yaml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/promotion/update.yaml @@ -13,50 +13,50 @@ twig_hooks: 'sylius_admin.promotion.update.content.form': sections: - template: '@SyliusAdmin/Promotion/Form/sections.html.twig' + template: '@SyliusAdmin/promotion/form/sections.html.twig' 'sylius_admin.promotion.update.content.form.sections': general: - template: '@SyliusAdmin/Promotion/Form/Sections/general.html.twig' + template: '@SyliusAdmin/promotion/form/sections/general.html.twig' configuration: - template: '@SyliusAdmin/Promotion/Form/Sections/configuration.html.twig' + template: '@SyliusAdmin/promotion/form/sections/configuration.html.twig' translations: - template: '@SyliusAdmin/Promotion/Form/Sections/translations.html.twig' + template: '@SyliusAdmin/promotion/form/sections/translations.html.twig' rules_and_actions: - template: '@SyliusAdmin/Promotion/Form/Sections/rules_and_actions.html.twig' + template: '@SyliusAdmin/promotion/form/sections/rules_and_actions.html.twig' 'sylius_admin.promotion.update.content.form.sections.general': _name: - template: '@SyliusAdmin/Promotion/Form/Sections/General/name.html.twig' + template: '@SyliusAdmin/promotion/form/sections/general/name.html.twig' code: - template: '@SyliusAdmin/Promotion/Form/Sections/General/code.html.twig' + template: '@SyliusAdmin/promotion/form/sections/general/code.html.twig' description: - template: '@SyliusAdmin/Promotion/Form/Sections/General/description.html.twig' + template: '@SyliusAdmin/promotion/form/sections/general/description.html.twig' channels: - template: '@SyliusAdmin/Promotion/Form/Sections/General/channels.html.twig' + template: '@SyliusAdmin/promotion/form/sections/general/channels.html.twig' 'sylius_admin.promotion.update.content.form.sections.configuration#left': usage_limit: - template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/usage_limit.html.twig' + template: '@SyliusAdmin/promotion/form/sections/configuration/usage_limit.html.twig' priority: - template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/priority.html.twig' + template: '@SyliusAdmin/promotion/form/sections/configuration/priority.html.twig' starts_at: - template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/starts_at.html.twig' + template: '@SyliusAdmin/promotion/form/sections/configuration/starts_at.html.twig' ends_at: - template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/ends_at.html.twig' + template: '@SyliusAdmin/promotion/form/sections/configuration/ends_at.html.twig' 'sylius_admin.promotion.update.content.form.sections.configuration#right': header: - template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/header.html.twig' + template: '@SyliusAdmin/promotion/form/sections/configuration/header.html.twig' coupon_based: - template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/coupon_based.html.twig' + template: '@SyliusAdmin/promotion/form/sections/configuration/coupon_based.html.twig' exclusive: - template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/exclusive.html.twig' + template: '@SyliusAdmin/promotion/form/sections/configuration/exclusive.html.twig' applies_to_discounted: - template: '@SyliusAdmin/Promotion/Form/Sections/Configuration/applies_to_discounted.html.twig' + template: '@SyliusAdmin/promotion/form/sections/configuration/applies_to_discounted.html.twig' 'sylius_admin.promotion.update.content.form.sections.rules_and_actions': rules: - template: '@SyliusAdmin/Promotion/Form/Sections/RulesAndActions/rules.html.twig' + template: '@SyliusAdmin/promotion/form/sections/rules_and_actions/rules.html.twig' actions: - template: '@SyliusAdmin/Promotion/Form/Sections/RulesAndActions/actions.html.twig' + template: '@SyliusAdmin/promotion/form/sections/rules_and_actions/actions.html.twig' diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/grids/catalog_promotion.yaml b/src/Sylius/Bundle/AdminBundle/Resources/config/grids/catalog_promotion.yaml index dffae96555a..402729249c9 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/grids/catalog_promotion.yaml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/grids/catalog_promotion.yaml @@ -44,7 +44,7 @@ sylius_grid: label: sylius.ui.state path: state options: - template: '@SyliusAdmin/Promotion/Grid/Field/state.html.twig' + template: '@SyliusAdmin/CatalogPromotion/Grid/Field/state.html.twig' enabled: type: twig label: sylius.ui.enabled diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/grids/promotion.yml b/src/Sylius/Bundle/AdminBundle/Resources/config/grids/promotion.yml index 8d88a58cd2b..da45cc3281c 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/grids/promotion.yml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/grids/promotion.yml @@ -13,7 +13,7 @@ sylius_grid: label: sylius.ui.priority sortable: ~ options: - template: "@SyliusAdmin/Promotion/Grid/Field/priority.html.twig" + template: "@SyliusAdmin/promotion/grid/field/priority.html.twig" code: type: string label: sylius.ui.code @@ -36,7 +36,7 @@ sylius_grid: path: . sortable: used options: - template: "@SyliusAdmin/Promotion/Grid/Field/usage.html.twig" + template: "@SyliusAdmin/promotion/grid/field/usage.html.twig" filters: search: type: string diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Grid/Action/deleteCatalogPromotion.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/CatalogPromotion/Grid/Action/deleteCatalogPromotion.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Grid/Action/deleteCatalogPromotion.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/CatalogPromotion/Grid/Action/deleteCatalogPromotion.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Grid/Field/state.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/CatalogPromotion/Grid/Field/state.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Grid/Field/state.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/CatalogPromotion/Grid/Field/state.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/form.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/form.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/sections.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/sections.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/configuration.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/configuration.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/configuration.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/configuration.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/applies_to_discounted.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/configuration/applies_to_discounted.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/applies_to_discounted.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/configuration/applies_to_discounted.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/coupon_based.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/configuration/coupon_based.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/coupon_based.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/configuration/coupon_based.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/ends_at.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/configuration/ends_at.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/ends_at.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/configuration/ends_at.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/exclusive.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/configuration/exclusive.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/exclusive.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/configuration/exclusive.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/header.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/configuration/header.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/header.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/configuration/header.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/priority.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/configuration/priority.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/priority.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/configuration/priority.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/starts_at.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/configuration/starts_at.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/starts_at.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/configuration/starts_at.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/usage_limit.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/configuration/usage_limit.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/Configuration/usage_limit.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/configuration/usage_limit.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/general.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/general.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/general.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/general.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/channels.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/general/channels.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/channels.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/general/channels.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/code.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/general/code.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/code.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/general/code.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/description.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/general/description.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/description.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/general/description.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/name.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/general/name.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/General/name.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/general/name.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/rules_and_actions.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/rules_and_actions.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/rules_and_actions.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/rules_and_actions.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/RulesAndActions/actions.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/rules_and_actions/actions.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/RulesAndActions/actions.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/rules_and_actions/actions.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/RulesAndActions/rules.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/rules_and_actions/rules.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/RulesAndActions/rules.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/rules_and_actions/rules.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/translations.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/translations.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Form/Sections/translations.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/translations.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Grid/Field/priority.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/promotion/grid/field/priority.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Grid/Field/priority.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/promotion/grid/field/priority.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Grid/Field/usage.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/promotion/grid/field/usage.html.twig similarity index 100% rename from src/Sylius/Bundle/AdminBundle/Resources/views/Promotion/Grid/Field/usage.html.twig rename to src/Sylius/Bundle/AdminBundle/Resources/views/promotion/grid/field/usage.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/TwigComponent/Promotion/FormComponent.php b/src/Sylius/Bundle/AdminBundle/TwigComponent/Promotion/FormComponent.php index ff6dad761f8..ff6ef5ebe84 100644 --- a/src/Sylius/Bundle/AdminBundle/TwigComponent/Promotion/FormComponent.php +++ b/src/Sylius/Bundle/AdminBundle/TwigComponent/Promotion/FormComponent.php @@ -25,7 +25,7 @@ use Symfony\UX\LiveComponent\DefaultActionTrait; use Symfony\UX\LiveComponent\LiveCollectionTrait; -#[AsLiveComponent(name: 'sylius_admin:promotion:form', template: '@SyliusAdmin/Promotion/form.html.twig')] +#[AsLiveComponent(name: 'sylius_admin:promotion:form', template: '@SyliusAdmin/promotion/form.html.twig')] final class FormComponent { use DefaultActionTrait; From 31386813126ae0394760baa4ca1e8a663fcc00da Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Mon, 15 Apr 2024 15:29:11 +0200 Subject: [PATCH 34/39] [Admin][Promotion] Fixes after code review --- ...dding_promotion_with_rule_in_different_channels.feature | 3 +-- .../Behat/Context/Ui/Admin/ManagingPromotionsContext.php | 4 ++-- src/Sylius/Behat/Element/Admin/Promotion/FormElement.php | 4 ++-- .../Behat/Element/Admin/Promotion/FormElementInterface.php | 2 +- src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php | 2 +- .../AdminBundle/Form/Extension/PromotionTypeExtension.php | 6 ------ .../Bundle/AdminBundle/Resources/config/services/form.xml | 6 +----- .../AdminBundle/Resources/views/promotion/form.html.twig | 2 +- .../AdminBundle/TwigComponent/Promotion/FormComponent.php | 7 +------ 9 files changed, 10 insertions(+), 26 deletions(-) diff --git a/features/admin/promotion/managing_promotions/adding_promotion_with_rule_in_different_channels.feature b/features/admin/promotion/managing_promotions/adding_promotion_with_rule_in_different_channels.feature index 54f58af177b..144629afd44 100644 --- a/features/admin/promotion/managing_promotions/adding_promotion_with_rule_in_different_channels.feature +++ b/features/admin/promotion/managing_promotions/adding_promotion_with_rule_in_different_channels.feature @@ -9,8 +9,7 @@ Feature: Adding a new promotion with rule configured in different channels And the store operates on a channel named "Web-GB" in "GBP" currency And I am logged in as an administrator -# @api - @ui @mink:chromedriver + @api @ui @mink:chromedriver Scenario: Adding a new promotion with total price of items from taxon rule When I want to create a new promotion And I specify its code as "100_IN_EVERY_CURRENCY" diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php index 32267ce2ad2..2b0184cc59a 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php @@ -220,7 +220,7 @@ public function iAddAMinMaxPriceFilterRangeForChannel(ChannelInterface $channel, */ public function iSpecifyThatThisActionShouldBeAppliedToItemsFromCategory(string $taxonName, ChannelInterface $channel): void { - $this->formElement->selectAutocompleteFilterOptions([$taxonName], $channel->getCode(), 'taxons'); + $this->formElement->selectAutocompleteActionFilterOptions([$taxonName], $channel->getCode(), 'taxons'); } /** @@ -626,7 +626,7 @@ public function iAddTheRuleConfiguredWithTheProduct(string $productName): void */ public function iSpecifyThatThisActionShouldBeAppliedToTheProduct(string $productName, ChannelInterface $channel): void { - $this->formElement->selectAutocompleteFilterOptions([$productName], $channel->getCode(), 'products'); + $this->formElement->selectAutocompleteActionFilterOptions([$productName], $channel->getCode(), 'products'); } /** diff --git a/src/Sylius/Behat/Element/Admin/Promotion/FormElement.php b/src/Sylius/Behat/Element/Admin/Promotion/FormElement.php index 2717d77b9e1..6a735fcc659 100644 --- a/src/Sylius/Behat/Element/Admin/Promotion/FormElement.php +++ b/src/Sylius/Behat/Element/Admin/Promotion/FormElement.php @@ -175,7 +175,7 @@ public function selectAutocompleteRuleOptions(array $values, ?string $channelCod } } - public function selectAutocompleteFilterOptions(array $values, string $channelCode, string $filterType): void + public function selectAutocompleteActionFilterOptions(array $values, string $channelCode, string $filterType): void { $count = count($this->getElement('actions')->findAll('css', '[data-test-promotion-action]')); $locator = sprintf('#sylius_promotion_actions_%d_configuration_%s_filters_%s_filter select', $count - 1, $channelCode, $filterType); @@ -238,7 +238,7 @@ protected function getDefinedElements(): array 'ends_at_date' => '#sylius_promotion_endsAt_date', 'ends_at_time' => '#sylius_promotion_endsAt_time', 'exclusive' => '#sylius_promotion_exclusive', - 'form' => '[data-live-name-value="SyliusAdmin.Promotion.Form"]', + 'form' => '[data-live-name-value="sylius_admin:promotion:form"]', 'label' => '[name="sylius_promotion[translations][%locale_code%][label]"]', 'minimum' => '#sylius_promotion_actions_0_configuration_WEB-US_filters_price_range_filter_min', 'maximum' => '#sylius_promotion_actions_0_configuration_WEB-US_filters_price_range_filter_max', diff --git a/src/Sylius/Behat/Element/Admin/Promotion/FormElementInterface.php b/src/Sylius/Behat/Element/Admin/Promotion/FormElementInterface.php index a91cef36b41..bdabe4b5b4b 100644 --- a/src/Sylius/Behat/Element/Admin/Promotion/FormElementInterface.php +++ b/src/Sylius/Behat/Element/Admin/Promotion/FormElementInterface.php @@ -61,7 +61,7 @@ public function fillRuleOptionForChannel(string $channelCode, string $option, st public function selectAutocompleteRuleOptions(array $values, ?string $channelCode = null): void; - public function selectAutocompleteFilterOptions(array $values, string $channelCode, string $filterType): void; + public function selectAutocompleteActionFilterOptions(array $values, string $channelCode, string $filterType): void; public function checkIfRuleConfigurationFormIsVisible(): bool; diff --git a/src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php b/src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php index f7f3cd09d99..4c735f29702 100644 --- a/src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php +++ b/src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php @@ -43,7 +43,7 @@ protected function getDefinedElements(): array { return array_merge(parent::getDefinedElements(), [ 'code' => '#sylius_promotion_code', - 'form' => '[data-live-name-value="SyliusAdmin.Promotion.Form"]', + 'form' => '[data-live-name-value="sylius_admin:promotion:form"]', 'rules' => '#sylius_promotion_rules', ]); } diff --git a/src/Sylius/Bundle/AdminBundle/Form/Extension/PromotionTypeExtension.php b/src/Sylius/Bundle/AdminBundle/Form/Extension/PromotionTypeExtension.php index d137427acdf..e03af88e38b 100644 --- a/src/Sylius/Bundle/AdminBundle/Form/Extension/PromotionTypeExtension.php +++ b/src/Sylius/Bundle/AdminBundle/Form/Extension/PromotionTypeExtension.php @@ -34,12 +34,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'button_add_options' => [ 'label' => 'sylius.ui.add_rule', ], - 'button_delete_options' => [ - 'label' => 'sylius.ui.delete', -// 'attr' => [ -// 'class' => 'btn btn-outline-danger', -// ], - ] ]) ->add('actions', LiveCollectionType::class, [ 'entry_type' => PromotionActionType::class, diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/services/form.xml b/src/Sylius/Bundle/AdminBundle/Resources/config/services/form.xml index 5a564802efd..dbcabc43613 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/services/form.xml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/services/form.xml @@ -67,11 +67,7 @@ - - - - - + diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form.html.twig index 0a278780b2d..a2eafe3d017 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form.html.twig +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form.html.twig @@ -1,4 +1,4 @@ -{# Rendered with using \Sylius\Bundle\AdminBundle\TwigComponent\Promotion\PromotionType #} +{# Rendered with \Sylius\Bundle\AdminBundle\TwigComponent\Promotion\FormComponent #} {% form_theme form '@SyliusAdmin/Shared/form_theme.html.twig' %} diff --git a/src/Sylius/Bundle/AdminBundle/TwigComponent/Promotion/FormComponent.php b/src/Sylius/Bundle/AdminBundle/TwigComponent/Promotion/FormComponent.php index ff6ef5ebe84..812c7e0da9b 100644 --- a/src/Sylius/Bundle/AdminBundle/TwigComponent/Promotion/FormComponent.php +++ b/src/Sylius/Bundle/AdminBundle/TwigComponent/Promotion/FormComponent.php @@ -32,7 +32,7 @@ final class FormComponent use HookableComponentTrait; use LiveCollectionTrait; - #[LiveProp(dehydrateWith: 'dehydrateResource', fieldName: 'resource')] + #[LiveProp(fieldName: 'resource')] public ?Promotion $resource = null; /** @@ -48,11 +48,6 @@ public function __construct( ) { } - public function dehydrateResource(): ?int - { - return $this->resource?->getId(); - } - #[LiveAction] public function addCollectionItem(PropertyAccessorInterface $propertyAccessor, #[LiveArg] string $name): void { From 77d36d4b3dbe5bc89c10dc31a7127e0e76b24121 Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Wed, 17 Apr 2024 13:29:55 +0200 Subject: [PATCH 35/39] [Admin] Move the data-skip-morph attribute to specific promotion rule configurations --- .../views/Shared/form_theme.html.twig | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/form_theme.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/form_theme.html.twig index 3bc7bd45561..a9dd0d2ff0c 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/form_theme.html.twig +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/form_theme.html.twig @@ -37,8 +37,8 @@ {% endblock %} {% block sylius_promotion_rule_row %} - -
+
+
{{- form_label(form) -}} {{- form_widget(form) -}} {{- form_errors(form) -}} @@ -47,6 +47,22 @@
{% endblock %} +{% block sylius_promotion_rule_has_taxon_configuration_row %} +
+ {{- form_label(form) -}} + {{- form_widget(form) -}} + {{- form_errors(form) -}} +
+{% endblock %} + +{% block sylius_promotion_rule_contains_product_configuration_row %} +
+ {{- form_label(form) -}} + {{- form_widget(form) -}} + {{- form_errors(form) -}} +
+{% endblock %} + {% block sylius_channel_collection_row %}
From 2ab9a82c0b6554f41618c9a7c3476965db59c4fb Mon Sep 17 00:00:00 2001 From: Jacob Tobiasz Date: Wed, 17 Apr 2024 13:39:48 +0200 Subject: [PATCH 36/39] Move a knowledge about the `data-skip-morph` from the form_theme to the type extension --- ...ContainsProductConfigurationTypeExtension.php | 3 +++ .../Rule/HasTaxonConfigurationTypeExtension.php | 3 +++ ...fItemsFromTaxonConfigurationTypeExtension.php | 3 +++ .../Resources/views/Shared/form_theme.html.twig | 16 ---------------- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Rule/ContainsProductConfigurationTypeExtension.php b/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Rule/ContainsProductConfigurationTypeExtension.php index f957323c39f..325572bd0b1 100644 --- a/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Rule/ContainsProductConfigurationTypeExtension.php +++ b/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Rule/ContainsProductConfigurationTypeExtension.php @@ -35,6 +35,9 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $builder ->add('product_code', ProductAutocompleteChoiceType::class, [ 'label' => 'sylius.form.promotion_action.add_product_configuration.product', + 'row_attr' => [ + 'data-skip-morph' => '', + ], ]) ->get('product_code')->addModelTransformer( new ReversedTransformer(new ResourceToIdentifierTransformer($this->productRepository, 'code')), diff --git a/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Rule/HasTaxonConfigurationTypeExtension.php b/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Rule/HasTaxonConfigurationTypeExtension.php index f38a1a57b32..9699171ceda 100644 --- a/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Rule/HasTaxonConfigurationTypeExtension.php +++ b/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Rule/HasTaxonConfigurationTypeExtension.php @@ -34,6 +34,9 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ->add('taxons', TaxonAutocompleteChoiceType::class, [ 'label' => 'sylius.form.promotion_rule.has_taxon.taxons', 'multiple' => true, + 'row_attr' => [ + 'data-skip-morph' => '', + ], ]) ->get('taxons')->addModelTransformer($this->taxonsToCodesTransformer) ; diff --git a/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Rule/TotalOfItemsFromTaxonConfigurationTypeExtension.php b/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Rule/TotalOfItemsFromTaxonConfigurationTypeExtension.php index 68701a12894..750643c6261 100644 --- a/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Rule/TotalOfItemsFromTaxonConfigurationTypeExtension.php +++ b/src/Sylius/Bundle/AdminBundle/Form/Extension/Promotion/Rule/TotalOfItemsFromTaxonConfigurationTypeExtension.php @@ -35,6 +35,9 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $builder ->add('taxon', TaxonAutocompleteChoiceType::class, [ 'label' => 'sylius.form.promotion_rule.total_of_items_from_taxon.taxon', + 'row_attr' => [ + 'data-skip-morph' => '', + ], ]) ->get('taxon')->addModelTransformer( new ReversedTransformer(new ResourceToIdentifierTransformer($this->taxonRepository, 'code')), diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/form_theme.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/form_theme.html.twig index a9dd0d2ff0c..4090011d01c 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/form_theme.html.twig +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/form_theme.html.twig @@ -47,22 +47,6 @@
{% endblock %} -{% block sylius_promotion_rule_has_taxon_configuration_row %} -
- {{- form_label(form) -}} - {{- form_widget(form) -}} - {{- form_errors(form) -}} -
-{% endblock %} - -{% block sylius_promotion_rule_contains_product_configuration_row %} -
- {{- form_label(form) -}} - {{- form_widget(form) -}} - {{- form_errors(form) -}} -
-{% endblock %} - {% block sylius_channel_collection_row %}
From f68cbd27643d6ce94de7a01f741ad8ff5e0773c6 Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Thu, 18 Apr 2024 07:27:35 +0200 Subject: [PATCH 37/39] [Admin] Minor improvements after code review of cart promotions --- .../Bundle/AdminBundle/Resources/config/services/form.xml | 2 +- .../sections/configuration/applies_to_discounted.html.twig | 3 +-- src/Sylius/Bundle/PromotionBundle/Form/Type/PromotionType.php | 1 + 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/services/form.xml b/src/Sylius/Bundle/AdminBundle/Resources/config/services/form.xml index dbcabc43613..b5182efcd07 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/services/form.xml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/services/form.xml @@ -67,7 +67,7 @@ - + diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/configuration/applies_to_discounted.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/configuration/applies_to_discounted.html.twig index a1e13bb40d1..2cb40aef5e5 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/configuration/applies_to_discounted.html.twig +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/promotion/form/sections/configuration/applies_to_discounted.html.twig @@ -1,4 +1,3 @@
- {{ form_row(hookable_data.form.appliesToDiscounted) }} - {{ 'sylius.form.promotion.applies_to_discounted_details'|trans }} + {{ form_row(hookable_data.form.appliesToDiscounted, {help_attr: { 'class': 'form-hint' }}) }}
diff --git a/src/Sylius/Bundle/PromotionBundle/Form/Type/PromotionType.php b/src/Sylius/Bundle/PromotionBundle/Form/Type/PromotionType.php index 931976bba23..d584f0c40c6 100644 --- a/src/Sylius/Bundle/PromotionBundle/Form/Type/PromotionType.php +++ b/src/Sylius/Bundle/PromotionBundle/Form/Type/PromotionType.php @@ -52,6 +52,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ]) ->add('appliesToDiscounted', CheckboxType::class, [ 'label' => 'sylius.form.promotion.applies_to_discounted', + 'help' => 'sylius.form.promotion.applies_to_discounted_details', ]) ->add('usageLimit', IntegerType::class, [ 'label' => 'sylius.form.promotion.usage_limit', From e803c6f7cc8eaeb43fa0170a0814dd4d13214670 Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Thu, 18 Apr 2024 07:59:45 +0200 Subject: [PATCH 38/39] [Behat][Admin] Replace step with checking successfully created promotion --- ...g_promotion_with_action_in_different_channels.feature | 3 +-- .../adding_promotion_with_filter.feature | 3 +-- ...ing_promotion_with_rule_in_different_channels.feature | 3 +-- .../Context/Api/Admin/ManagingPromotionsContext.php | 9 +++++++++ .../Behat/Context/Ui/Admin/ManagingPromotionsContext.php | 8 ++++++++ 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/features/admin/promotion/managing_promotions/adding_promotion_with_action_in_different_channels.feature b/features/admin/promotion/managing_promotions/adding_promotion_with_action_in_different_channels.feature index da704d642d4..3620dcd099d 100644 --- a/features/admin/promotion/managing_promotions/adding_promotion_with_action_in_different_channels.feature +++ b/features/admin/promotion/managing_promotions/adding_promotion_with_action_in_different_channels.feature @@ -17,5 +17,4 @@ Feature: Adding a new promotion with action configured in different channels And I add the "Item fixed discount" action configured with amount of "$10.00" for "United States" channel And it is also configured with amount of "£16.00" for "Web-GB" channel And I add it - Then I should be notified that it has been successfully created - And the "Item fixed discount for all products!" promotion should appear in the registry + Then the "Item fixed discount for all products!" promotion should be successfully created diff --git a/features/admin/promotion/managing_promotions/adding_promotion_with_filter.feature b/features/admin/promotion/managing_promotions/adding_promotion_with_filter.feature index 673b7f81ece..cce21ace28d 100644 --- a/features/admin/promotion/managing_promotions/adding_promotion_with_filter.feature +++ b/features/admin/promotion/managing_promotions/adding_promotion_with_filter.feature @@ -16,8 +16,7 @@ Feature: Adding promotion with filter And I add the "Item fixed discount" action configured with amount of "$10.00" for "United States" channel And I specify that on "United States" channel this action should be applied to items with price greater than "$10.00" And I add it - Then I should be notified that it has been successfully created - And the "$10 discount for all products over $10!" promotion should appear in the registry + Then the "$10 discount for all products over $10!" promotion should be successfully created @api @ui @javascript Scenario: Adding a promotion with item fixed discount only for products between 10 and 100 diff --git a/features/admin/promotion/managing_promotions/adding_promotion_with_rule_in_different_channels.feature b/features/admin/promotion/managing_promotions/adding_promotion_with_rule_in_different_channels.feature index 144629afd44..35be86e7e17 100644 --- a/features/admin/promotion/managing_promotions/adding_promotion_with_rule_in_different_channels.feature +++ b/features/admin/promotion/managing_promotions/adding_promotion_with_rule_in_different_channels.feature @@ -16,5 +16,4 @@ Feature: Adding a new promotion with rule configured in different channels And I name it "100 in every currency" And I add the "Item total" rule configured with "€100.00" amount for "United States" channel and "£100.00" amount for "Web-GB" channel And I add it - Then I should be notified that it has been successfully created - And the "100 in every currency" promotion should appear in the registry + Then the "100 in every currency" promotion should be successfully created diff --git a/src/Sylius/Behat/Context/Api/Admin/ManagingPromotionsContext.php b/src/Sylius/Behat/Context/Api/Admin/ManagingPromotionsContext.php index d0b1cd66ba5..f96533cfa61 100644 --- a/src/Sylius/Behat/Context/Api/Admin/ManagingPromotionsContext.php +++ b/src/Sylius/Behat/Context/Api/Admin/ManagingPromotionsContext.php @@ -564,6 +564,15 @@ public function promotionShouldNotExistInTheRegistry(PromotionInterface $promoti ); } + /** + * @Then the :promotionName promotion should be successfully created + */ + public function thePromotionShouldBeSuccessfullyCreated(string $promotionName): void + { + $this->iShouldBeNotifiedThatItHasBeenSuccessfullyCreated(); + $this->thePromotionShouldAppearInTheRegistry($promotionName); + } + /** * @Then I should be notified that it has been successfully created */ diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php index 2b0184cc59a..e92a9cd8fdb 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php @@ -890,6 +890,14 @@ public function iShouldBeViewingNonArchivalPromotions(): void Assert::false($this->indexPage->isArchivalFilterEnabled()); } + /** + * @Then the :promotion promotion should be successfully created + */ + public function thePromotionShouldBeSuccessfullyCreated(PromotionInterface $promotion): void + { + $this->updatePage->verify(['id' => $promotion->getId()]); + } + private function assertFieldValidationMessage(string $element, string $expectedMessage) { Assert::same($this->formElement->getValidationMessage($element), $expectedMessage); From b004e01f6ea3380144b451ad7359ab9ec3124d2f Mon Sep 17 00:00:00 2001 From: Grzegorz Sadowski Date: Thu, 18 Apr 2024 12:57:18 +0200 Subject: [PATCH 39/39] [Admin] Minor improvements for promotion's form component --- .../TwigComponent/Promotion/FormComponent.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Sylius/Bundle/AdminBundle/TwigComponent/Promotion/FormComponent.php b/src/Sylius/Bundle/AdminBundle/TwigComponent/Promotion/FormComponent.php index 812c7e0da9b..3facda289a0 100644 --- a/src/Sylius/Bundle/AdminBundle/TwigComponent/Promotion/FormComponent.php +++ b/src/Sylius/Bundle/AdminBundle/TwigComponent/Promotion/FormComponent.php @@ -59,11 +59,9 @@ public function addCollectionItem(PropertyAccessorInterface $propertyAccessor, # $data = []; } - $index = [] !== $data ? max(array_keys($data)) + 1 : 0; - $propertyAccessor->setValue( $this->formValues, - $propertyPath."[$index]", + sprintf('%s[%d]', $propertyPath, $this->resolveItemIndex($data)), ['type' => $this->provideItemType($name)], ); } @@ -85,4 +83,10 @@ private function provideItemType(string $name): string return ''; } + + /** @param array> $data */ + private function resolveItemIndex(array $data): int + { + return [] !== $data ? max(array_keys($data)) + 1 : 0; + } }