Skip to content

Commit

Permalink
OP-558: init
Browse files Browse the repository at this point in the history
  • Loading branch information
jkindly committed Sep 30, 2024
1 parent 6f819a7 commit f27a33f
Show file tree
Hide file tree
Showing 24 changed files with 305 additions and 75 deletions.
26 changes: 17 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@
"license": "MIT",
"require": {
"php": "^8.0 || ^8.1 || ^8.2 || ^8.3",
"sylius/sylius": "~1.12.0 || ~1.13.0",
"doctrine/annotations": "^2.0.0"
"doctrine/annotations": "^2.0.0",
"sylius-labs/polyfill-symfony-security": "^1.1",
"sylius/calendar": "^0.5.0",
"sylius/grid-bundle": "1.13.0-ALPHA.3",
"sylius/sylius": "2.0.0-alpha.2",
"sylius/twig-hooks": "^0.3.0",
"symfony/stimulus-bundle": "^2.20",
"symfony/ux-autocomplete": "^2.20",
"symfony/ux-live-component": "^2.20",
"symfony/ux-twig-component": "^2.20"
},
"require-dev": {
"behat/behat": "^3.7.0",
Expand All @@ -33,13 +41,13 @@
"phpstan/phpstan-webmozart-assert": "^1.0",
"phpunit/phpunit": "^9.5",
"polishsymfonycommunity/symfony-mocker-container": "^1.0",
"symfony/browser-kit": "^5.4 || 6.4",
"symfony/debug-bundle": "^5.4 || ^6.4",
"symfony/dotenv": "^5.4 || ^6.4",
"symfony/intl": "^5.4 || ^6.4",
"symfony/web-profiler-bundle": "^5.4 || ^6.4",
"vimeo/psalm": "^4.7 || ^5.0",
"symfony/webpack-encore-bundle": "^1.17"
"symfony/browser-kit": "^6.4",
"symfony/debug-bundle": "^6.4",
"symfony/dotenv": "^6.4",
"symfony/intl": "^6.4",
"symfony/web-profiler-bundle": "^6.4",
"symfony/webpack-encore-bundle": "^2.1",
"vimeo/psalm": "^4.7 || ^5.0"
},
"autoload": {
"psr-4": {
Expand Down
24 changes: 21 additions & 3 deletions src/Form/Type/AutomaticBlacklistingConfigurationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@
namespace BitBag\SyliusBlacklistPlugin\Form\Type;

use BitBag\SyliusBlacklistPlugin\Entity\FraudPrevention\AutomaticBlacklistingRuleInterface;
use Sylius\Bundle\AdminBundle\Form\Type\AddButtonType;
use Sylius\Bundle\ChannelBundle\Form\Type\ChannelChoiceType;
use Sylius\Bundle\PromotionBundle\Form\Type\PromotionRuleType;
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\GreaterThanOrEqual;
use Symfony\UX\LiveComponent\Form\Type\LiveCollectionType;

final class AutomaticBlacklistingConfigurationType extends AbstractResourceType
{
Expand All @@ -30,6 +33,7 @@ public function __construct(
string $dataClass,
array $attributeChoices,
array $validationGroups = [],
private array $rules,
) {
parent::__construct($dataClass, $validationGroups);
$this->attributeChoices = $attributeChoices;
Expand Down Expand Up @@ -72,9 +76,23 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
],
'placeholder' => 'bitbag_sylius_blacklist_plugin.ui.choose_time_range',
])
->add('rules', AutomaticBlacklistingRuleCollectionType::class, [
'label' => 'bitbag_sylius_blacklist_plugin.form.automatic_blacklisting_rule.rules',
'button_add_label' => 'sylius.form.promotion.add_rule',
// ->add('rules', AutomaticBlacklistingRuleCollectionType::class, [
// 'label' => 'bitbag_sylius_blacklist_plugin.form.automatic_blacklisting_rule.rules',
// 'button_add_label' => 'sylius.form.promotion.add_rule',
// ])
->add('rules', LiveCollectionType::class, [
'entry_type' => AutomaticBlacklistingRuleType::class,
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'button_add_type' => AddButtonType::class,
'button_add_options' => [
'label' => 'sylius.ui.add_rule',
'types' => $this->rules,
],
'button_delete_options' => [
'label' => false,
],
])
;
}
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
imports:
- { resource: "twig_hooks/**/*.yaml" }
- { resource: "resources.yaml" }
- { resource: "services.xml" }
- { resource: "grids.yaml" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ bitbag_sylius_blacklist_plugin_admin_automatic_blacklisting_configuration:
resource: |
alias: bitbag_sylius_blacklist_plugin.automatic_blacklisting_configuration
section: admin
templates: "@SyliusAdmin\\Crud"
templates: "@SyliusAdmin\\shared\\crud"
grid: bitbag_sylius_blacklist_plugin_automatic_blacklisting_configuration
except: ['show']
permission: true
form:
type: BitBag\SyliusBlacklistPlugin\Form\Type\AutomaticBlacklistingConfigurationType
vars:
all:
subheader: bitbag_sylius_blacklist_plugin.ui.configure_automatic_blacklisting_configurations
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/routing/admin/blacklisting_rule.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ bitbag_sylius_blacklist_plugin_admin_blacklisting_rule:
resource: |
alias: bitbag_sylius_blacklist_plugin.blacklisting_rule
section: admin
templates: "@SyliusAdmin\\Crud"
templates: "@SyliusAdmin\\shared\\crud"
grid: bitbag_sylius_blacklist_plugin_blacklisting_rule
except: ['show']
permission: true
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/routing/admin/fraud_suspicion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ bitbag_sylius_blacklist_plugin_admin_fraud_suspicion:
resource: |
alias: bitbag_sylius_blacklist_plugin.fraud_suspicion
section: admin
templates: "@SyliusAdmin\\Crud"
templates: "@SyliusAdmin\\shared\\crud"
grid: bitbag_sylius_blacklist_plugin_fraud_suspicion
permission: true
vars:
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/services/form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<argument>%bitbag_sylius_blacklist_plugin.model.automatic_blacklisting_configuration.class%</argument>
<argument>%bitbag.sylius_blacklist_plugin.form.type.automatic_blacklisting_configuration.validation_groups%</argument>
<argument>%bitbag.sylius_blacklist_plugin.form.type.validation_groups%</argument>
<argument>%bitbag.sylius_blacklist_plugin.automatic_blacklisting_rules%</argument>
<tag name="form.type" />
</service>
<service id="bitbag.sylius_blacklist_plugin.form.type.automatic_blacklisting_rule"
Expand Down
25 changes: 25 additions & 0 deletions src/Resources/config/services/twig/component.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8" ?>

<container
xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"
>
<services>
<service
id="bitbag.sylius_blacklist_plugin.twig.component.automatic_blacklisting_configuration.form"
class="Sylius\Bundle\UiBundle\Twig\Component\ResourceFormComponent"
>
<argument type="service" id="bitbag_sylius_blacklist_plugin.repository.automatic_blacklisting_configuration" />
<argument type="service" id="form.factory" />
<argument>%bitbag_sylius_blacklist_plugin.model.automatic_blacklisting_configuration.class%</argument>
<argument>BitBag\SyliusBlacklistPlugin\Form\Type\AutomaticBlacklistingConfigurationType</argument>

<tag
name="sylius.live_component"
key="bitbag_sylius_blacklist_plugin:automatic_blacklisting_configuration:form"
template="@BitBagSyliusBlacklistPlugin/AutomaticBlacklistingConfiguration/Admin/form.html.twig"
/>
</service>
</services>
</container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
twig_hooks:
hooks:
'bitbag_sylius_blacklist_plugin.automatic_blacklisting_configuration.create.content':
form:
component: 'bitbag_sylius_blacklist_plugin:automatic_blacklisting_configuration:form'
props:
resource: '@=_context.resource'
form: '@=_context.form'
configuration:
render_rest: false
'bitbag_sylius_blacklist_plugin.automatic_blacklisting_configuration.create.content.form':
sections:
template: '@SyliusAdmin/promotion/form/sections.html.twig'

This file was deleted.

Empty file.
39 changes: 39 additions & 0 deletions src/Resources/views/Form/theme.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,42 @@
'load_edit_url': path('bitbag_sylius_blacklist_plugin_admin_ajax_customer_by_id')
}) }}
{% endblock %}

{% block bitbag_sylius_blacklist_plugin_automatic_blacklisting_rule_widget %}
<div class="ui segment">
{{ block('form_widget') }}
</div>
{% endblock %}

{%- block bitbag_sylius_blacklist_plugin_automatic_blacklisting_rule_row -%}
<div id="{{ id }}" {{ block('attributes') }} {{ sylius_test_html_attribute('entry-row') }}>
{{- form_errors(form) -}}
{{- form_row(form.type) -}}
<div class="alert text-body">
<div class="d-flex mb-3">
<div class="me-auto"><strong>ads</strong></div>
{{- form_row(button_delete, sylius_test_form_attribute('delete')|sylius_merge_recursive({'attr': {'class': 'btn-close'}})) -}}
</div>
<div>
{{- form_row(form.settings, {'label': false}) -}}
</div>
</div>
</div>
{%- endblock bitbag_sylius_blacklist_plugin_automatic_blacklisting_rule_row -%}

{% block add_button_row %}
{% if types is not empty %}
<div class="dropdown">
<button class="btn dropdown-toggle" type="button" data-bs-toggle="dropdown">{{ label|trans }}</button>
<ul class="dropdown-menu">
{% for type, label in types %}
<li>
<button class="dropdown-item" type="button" {{ block('button_attributes') }} data-live-type-param="{{ type }}" {{ sylius_test_html_attribute('add-' ~ type) }}>
{{ (label)|trans }}
</button>
</li>
{% endfor %}
</ul>
</div>
{% endif %}
{% endblock %}
4 changes: 2 additions & 2 deletions tests/Application/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Tests\BitBag\SyliusBlacklistPlugin\Application;

use PSS\SymfonyMockerContainer\DependencyInjection\MockerContainer;
use Sylius\Bundle\CoreBundle\Application\Kernel as SyliusKernel;
use Sylius\Bundle\CoreBundle\SyliusCoreBundle;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Config\Resource\FileResource;
Expand Down Expand Up @@ -113,7 +113,7 @@ private function registerBundlesFromFile(string $bundlesFile): iterable
private function getConfigurationDirectories(): iterable
{
yield $this->getProjectDir() . '/config';
$syliusConfigDir = $this->getProjectDir() . '/config/sylius/' . SyliusKernel::MAJOR_VERSION . '.' . SyliusKernel::MINOR_VERSION;
$syliusConfigDir = $this->getProjectDir() . '/config/sylius/' . SyliusCoreBundle::MAJOR_VERSION . '.' . SyliusCoreBundle::MINOR_VERSION;
if (is_dir($syliusConfigDir)) {
yield $syliusConfigDir;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Application/assets/admin/entry.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import 'sylius/bundle/AdminBundle/Resources/private/entry';
import 'sylius/bundle/AdminBundle/Resources/assets/entrypoint';
1 change: 1 addition & 0 deletions tests/Application/assets/admin/product-entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'sylius/bundle/AdminBundle/Resources/assets/scripts/product/attribute-tabs-refresher';
5 changes: 5 additions & 0 deletions tests/Application/assets/controllers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"controllers": {
},
"entrypoints": []
}
2 changes: 1 addition & 1 deletion tests/Application/assets/shop/entry.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import 'sylius/bundle/ShopBundle/Resources/private/entry';
import 'sylius/bundle/ShopBundle/Resources/assets/entrypoint';
7 changes: 6 additions & 1 deletion tests/Application/config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true],
FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle::class => ['test' => true, 'test_cached' => true],
Sylius\Behat\Application\SyliusTestPlugin\SyliusTestPlugin::class => ['test' => true, 'test_cached' => true],
ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true],
ApiPlatform\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true],
Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle::class => ['all' => true],
Sylius\Bundle\ApiBundle\SyliusApiBundle::class => ['all' => true],
SyliusLabs\DoctrineMigrationsExtraBundle\SyliusLabsDoctrineMigrationsExtraBundle::class => ['all' => true],
Expand All @@ -67,4 +67,9 @@
Sylius\Calendar\SyliusCalendarBundle::class => ['all' => true],
BabDev\PagerfantaBundle\BabDevPagerfantaBundle::class => ['all' => true],
SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true],
Sylius\TwigHooks\TwigHooksBundle::class => ['all' => true],
Symfony\UX\TwigComponent\TwigComponentBundle::class => ['all' => true],
Symfony\UX\LiveComponent\LiveComponentBundle::class => ['all' => true],
Symfony\UX\Autocomplete\AutocompleteBundle::class => ['all' => true],
Symfony\UX\StimulusBundle\StimulusBundle::class => ['all' => true],
];
3 changes: 3 additions & 0 deletions tests/Application/config/routes/ux.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
live_component:
resource: "@LiveComponentBundle/config/routes.php"
prefix: /{_locale}/_components
14 changes: 14 additions & 0 deletions tests/Application/config/sylius/2.0/bundles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://bitbag.io and write us
* an email on [email protected].
*/

declare(strict_types=1);

return [
Sylius\Abstraction\StateMachine\SyliusStateMachineAbstractionBundle::class => ['all' => true],
];
10 changes: 10 additions & 0 deletions tests/Application/config/sylius/2.0/packages/_sylius.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
parameters:
test_default_state_machine_adapter: 'symfony_workflow'
test_sylius_state_machine_adapter: '%env(string:default:test_default_state_machine_adapter:TEST_SYLIUS_STATE_MACHINE_ADAPTER)%'

sylius_state_machine_abstraction:
graphs_to_adapters_mapping:
sylius_refund_refund_payment: '%test_sylius_state_machine_adapter%'

sylius_api:
enabled: true
Loading

0 comments on commit f27a33f

Please sign in to comment.