From 17bfae7ca6a617eb9d28f00df8457d6bb0ba8afe Mon Sep 17 00:00:00 2001 From: jkindly Date: Fri, 19 Jul 2024 11:22:51 +0200 Subject: [PATCH 1/8] OP-440: Conditional block rendering --- src/Entity/Block.php | 13 +++++ src/Entity/BlockInterface.php | 7 ++- src/Entity/BlockProductAwareInterface.php | 20 ++++++++ src/Entity/BlockTaxonAwareInterface.php | 18 +++++++ src/Entity/ProductsInTaxonsAwareInterface.php | 30 +++++++++++ src/Entity/Trait/BlockProductAwareTrait.php | 31 ++++++++++++ src/Entity/Trait/BlockTaxonAwareTrait.php | 21 ++++++++ src/Entity/Trait/ProductsAwareTrait.php | 2 +- .../Trait/ProductsInTaxonsAwareTrait.php | 50 +++++++++++++++++++ src/Entity/Trait/TaxonAwareTrait.php | 12 ++--- src/Form/Type/BlockType.php | 17 +++++++ src/Resources/assets/admin/scss/_css.scss | 6 +++ src/Resources/config/doctrine/Block.orm.xml | 33 ++++++++++++ .../views/Block/Crud/_form.html.twig | 6 +++ src/Resources/views/Form/theme.html.twig | 22 ++++++++ src/Twig/Runtime/RenderBlockRuntime.php | 30 +++++++---- .../SyliusShopBundle/Product/show.html.twig | 2 +- .../Taxon/Header/_content.html.twig | 6 +++ 18 files changed, 307 insertions(+), 19 deletions(-) create mode 100644 src/Entity/BlockProductAwareInterface.php create mode 100644 src/Entity/BlockTaxonAwareInterface.php create mode 100755 src/Entity/ProductsInTaxonsAwareInterface.php create mode 100644 src/Entity/Trait/BlockProductAwareTrait.php create mode 100644 src/Entity/Trait/BlockTaxonAwareTrait.php create mode 100644 src/Entity/Trait/ProductsInTaxonsAwareTrait.php create mode 100644 tests/Application/templates/bundles/SyliusShopBundle/Taxon/Header/_content.html.twig diff --git a/src/Entity/Block.php b/src/Entity/Block.php index 4c8cb7341..3457c357c 100755 --- a/src/Entity/Block.php +++ b/src/Entity/Block.php @@ -10,10 +10,15 @@ namespace BitBag\SyliusCmsPlugin\Entity; +use BitBag\SyliusCmsPlugin\Entity\Trait\BlockProductAwareTrait; +use BitBag\SyliusCmsPlugin\Entity\Trait\BlockTaxonAwareTrait; use BitBag\SyliusCmsPlugin\Entity\Trait\ChannelsAwareTrait; use BitBag\SyliusCmsPlugin\Entity\Trait\CollectibleTrait; use BitBag\SyliusCmsPlugin\Entity\Trait\ContentConfigurationAwareTrait; use BitBag\SyliusCmsPlugin\Entity\Trait\LocaleAwareTrait; +use BitBag\SyliusCmsPlugin\Entity\Trait\ProductsAwareTrait; +use BitBag\SyliusCmsPlugin\Entity\Trait\ProductsInTaxonsAwareTrait; +use BitBag\SyliusCmsPlugin\Entity\Trait\TaxonAwareTrait; use Sylius\Component\Resource\Model\ToggleableTrait; class Block implements BlockInterface @@ -23,6 +28,11 @@ class Block implements BlockInterface use ChannelsAwareTrait; use ContentConfigurationAwareTrait; use LocaleAwareTrait; + use ProductsAwareTrait; + use TaxonAwareTrait; + use ProductsInTaxonsAwareTrait; + use BlockTaxonAwareTrait; + use BlockProductAwareTrait; public function __construct() { @@ -30,6 +40,9 @@ public function __construct() $this->initializeChannelsCollection(); $this->initializeContentElementsCollection(); $this->initializeLocalesCollection(); + $this->initializeProductsCollection(); + $this->initializeTaxonCollection(); + $this->initializeProductsInTaxonsCollection(); } protected ?int $id; diff --git a/src/Entity/BlockInterface.php b/src/Entity/BlockInterface.php index c60770207..e3c002ac0 100755 --- a/src/Entity/BlockInterface.php +++ b/src/Entity/BlockInterface.php @@ -20,7 +20,12 @@ interface BlockInterface extends CollectibleInterface, ChannelsAwareInterface, ContentConfigurationAwareInterface, - LocaleAwareInterface + LocaleAwareInterface, + ProductsAwareInterface, + TaxonAwareInterface, + ProductsInTaxonsAwareInterface, + BlockTaxonAwareInterface, + BlockProductAwareInterface { public function getCode(): ?string; diff --git a/src/Entity/BlockProductAwareInterface.php b/src/Entity/BlockProductAwareInterface.php new file mode 100644 index 000000000..fbbb94e9d --- /dev/null +++ b/src/Entity/BlockProductAwareInterface.php @@ -0,0 +1,20 @@ +hasProduct($product); + } + + public function canBeDisplayedForProductInTaxon(ProductInterface $product): bool + { + $taxon = $product->getMainTaxon(); + if (null === $taxon) { + return false; + } + + return $this->hasProductsInTaxon($taxon); + } +} diff --git a/src/Entity/Trait/BlockTaxonAwareTrait.php b/src/Entity/Trait/BlockTaxonAwareTrait.php new file mode 100644 index 000000000..c84cd24cd --- /dev/null +++ b/src/Entity/Trait/BlockTaxonAwareTrait.php @@ -0,0 +1,21 @@ +hasTaxon($taxon); + } +} diff --git a/src/Entity/Trait/ProductsAwareTrait.php b/src/Entity/Trait/ProductsAwareTrait.php index 16478bb2d..3710dea32 100755 --- a/src/Entity/Trait/ProductsAwareTrait.php +++ b/src/Entity/Trait/ProductsAwareTrait.php @@ -17,7 +17,7 @@ trait ProductsAwareTrait { /** @var Collection|ProductInterface[] */ - protected $products; + protected array|Collection $products; public function initializeProductsCollection(): void { diff --git a/src/Entity/Trait/ProductsInTaxonsAwareTrait.php b/src/Entity/Trait/ProductsInTaxonsAwareTrait.php new file mode 100644 index 000000000..6e331bdf8 --- /dev/null +++ b/src/Entity/Trait/ProductsInTaxonsAwareTrait.php @@ -0,0 +1,50 @@ +productsInTaxons = new ArrayCollection(); + } + + public function getProductsInTaxons(): Collection + { + return $this->productsInTaxons; + } + + public function hasProductsInTaxon(TaxonInterface $taxon): bool + { + return $this->productsInTaxons->contains($taxon); + } + + public function addProductsInTaxon(TaxonInterface $taxon): void + { + if (false === $this->hasProductsInTaxon($taxon)) { + $this->productsInTaxons->add($taxon); + } + } + + public function removeProductsInTaxon(TaxonInterface $taxon): void + { + if (true === $this->hasProductsInTaxon($taxon)) { + $this->productsInTaxons->removeElement($taxon); + } + } +} diff --git a/src/Entity/Trait/TaxonAwareTrait.php b/src/Entity/Trait/TaxonAwareTrait.php index 1306731ed..8edc13cc7 100644 --- a/src/Entity/Trait/TaxonAwareTrait.php +++ b/src/Entity/Trait/TaxonAwareTrait.php @@ -17,34 +17,34 @@ trait TaxonAwareTrait { /** @var Collection|TaxonInterface[] */ - protected $taxonomies; + protected array|Collection $taxons; public function initializeTaxonCollection(): void { - $this->taxonomies = new ArrayCollection(); + $this->taxons = new ArrayCollection(); } public function getTaxons(): Collection { - return $this->taxonomies; + return $this->taxons; } public function hasTaxon(TaxonInterface $taxon): bool { - return $this->taxonomies->contains($taxon); + return $this->taxons->contains($taxon); } public function addTaxon(TaxonInterface $taxon): void { if (false === $this->hasTaxon($taxon)) { - $this->taxonomies->add($taxon); + $this->taxons->add($taxon); } } public function removeTaxon(TaxonInterface $taxon): void { if (true === $this->hasTaxon($taxon)) { - $this->taxonomies->removeElement($taxon); + $this->taxons->removeElement($taxon); } } } diff --git a/src/Form/Type/BlockType.php b/src/Form/Type/BlockType.php index c1425b237..73fb6c3de 100755 --- a/src/Form/Type/BlockType.php +++ b/src/Form/Type/BlockType.php @@ -12,7 +12,9 @@ use BitBag\SyliusCmsPlugin\Entity\BlockInterface; use Sylius\Bundle\ChannelBundle\Form\Type\ChannelChoiceType; +use Sylius\Bundle\ProductBundle\Form\Type\ProductAutocompleteChoiceType; use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType; +use Sylius\Bundle\TaxonomyBundle\Form\Type\TaxonAutocompleteChoiceType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\CollectionType; use Symfony\Component\Form\Extension\Core\Type\TextType; @@ -55,6 +57,21 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'by_reference' => false, 'required' => false, ]) + ->add('products', ProductAutocompleteChoiceType::class, [ + 'label' => 'bitbag_sylius_cms_plugin.ui.display_for_products.label', + 'multiple' => true, + 'help' => 'bitbag_sylius_cms_plugin.ui.display_for_products.help', + ]) + ->add('productsInTaxons', TaxonAutocompleteChoiceType::class, [ + 'label' => 'bitbag_sylius_cms_plugin.ui.display_for_products_in_taxons.label', + 'multiple' => true, + 'help' => 'bitbag_sylius_cms_plugin.ui.display_for_products_in_taxons.help' + ]) + ->add('taxons', TaxonAutocompleteChoiceType::class, [ + 'label' => 'bitbag_sylius_cms_plugin.ui.display_for_taxons.label', + 'multiple' => true, + 'help' => 'bitbag_sylius_cms_plugin.ui.display_for_taxons.help', + ]) ; } diff --git a/src/Resources/assets/admin/scss/_css.scss b/src/Resources/assets/admin/scss/_css.scss index 872507af4..d3c63c491 100644 --- a/src/Resources/assets/admin/scss/_css.scss +++ b/src/Resources/assets/admin/scss/_css.scss @@ -115,3 +115,9 @@ .cke_notifications_area { display: none; } + +.help-text { + font-size: 12px; + margin-top: -10px; + opacity: 0.5; +} diff --git a/src/Resources/config/doctrine/Block.orm.xml b/src/Resources/config/doctrine/Block.orm.xml index 78b52ac7b..eaf0eb4cf 100644 --- a/src/Resources/config/doctrine/Block.orm.xml +++ b/src/Resources/config/doctrine/Block.orm.xml @@ -58,5 +58,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Resources/views/Block/Crud/_form.html.twig b/src/Resources/views/Block/Crud/_form.html.twig index d6d326322..d53d42d74 100755 --- a/src/Resources/views/Block/Crud/_form.html.twig +++ b/src/Resources/views/Block/Crud/_form.html.twig @@ -12,6 +12,12 @@ {{ form_row(form.locales) }} {{ form_row(form.collections) }} +
+

{{ 'bitbag_sylius_cms_plugin.ui.manage_block_display'|trans }}

+ {{ form_row(form.products) }} + {{ form_row(form.productsInTaxons) }} + {{ form_row(form.taxons) }} +
diff --git a/src/Resources/views/Form/theme.html.twig b/src/Resources/views/Form/theme.html.twig index 841343b8f..66b88405f 100755 --- a/src/Resources/views/Form/theme.html.twig +++ b/src/Resources/views/Form/theme.html.twig @@ -104,3 +104,25 @@
{% endapply %} {% endmacro %} + +{% block sylius_resource_autocomplete_choice_row %} +
+ {{- form_label(form) -}} + {{- form_help(form) -}} + + {{- form_errors(form) -}} +
+{% endblock %} diff --git a/src/Twig/Runtime/RenderBlockRuntime.php b/src/Twig/Runtime/RenderBlockRuntime.php index ddec96185..6b8798be2 100644 --- a/src/Twig/Runtime/RenderBlockRuntime.php +++ b/src/Twig/Runtime/RenderBlockRuntime.php @@ -12,6 +12,8 @@ use BitBag\SyliusCmsPlugin\Renderer\ContentElementRendererStrategyInterface; use BitBag\SyliusCmsPlugin\Resolver\BlockResourceResolverInterface; +use Sylius\Component\Core\Model\ProductInterface; +use Sylius\Component\Core\Model\TaxonInterface; use Twig\Environment; final class RenderBlockRuntime implements RenderBlockRuntimeInterface @@ -25,21 +27,29 @@ public function __construct( ) { } - public function renderBlock(string $code, ?string $template = null): string + public function renderBlock(string $code, ?string $template = null, ProductInterface|TaxonInterface $context = null): string { $block = $this->blockResourceResolver->findOrLog($code); + if (null === $block) { + return ''; + } - if (null !== $block) { - $template = $template ?? self::DEFAULT_TEMPLATE; + if ($context instanceof TaxonInterface && false === $block->canBeDisplayedForTaxon($context)) { + return ''; + } - return $this->templatingEngine->render( - $template, - [ - 'content' => $this->contentElementRendererStrategy->render($block), - ], - ); + if ($context instanceof ProductInterface && + false === $block->canBeDisplayedForProduct($context) && + false === $block->canBeDisplayedForProductInTaxon($context) + ) { + return ''; } - return ''; + return $this->templatingEngine->render( + $template ?? self::DEFAULT_TEMPLATE, + [ + 'content' => $this->contentElementRendererStrategy->render($block), + ], + ); } } diff --git a/tests/Application/templates/bundles/SyliusShopBundle/Product/show.html.twig b/tests/Application/templates/bundles/SyliusShopBundle/Product/show.html.twig index eb749f4b3..37da1040b 100755 --- a/tests/Application/templates/bundles/SyliusShopBundle/Product/show.html.twig +++ b/tests/Application/templates/bundles/SyliusShopBundle/Product/show.html.twig @@ -52,7 +52,7 @@ {{ render(path('bitbag_sylius_cms_plugin_shop_block_index_by_collection_code', {'collectionCode' : 'products', 'template' : '@BitBagSyliusCmsPlugin/Shop/Block/index.html.twig'})) }} - {{ bitbag_cms_render_block('lorem_ipsum') }} + {{ bitbag_cms_render_block('lorem_ipsum', null, product) }} {{ sonata_block_render_event('sylius.shop.product.show.before_tabs', {'product': product}) }} diff --git a/tests/Application/templates/bundles/SyliusShopBundle/Taxon/Header/_content.html.twig b/tests/Application/templates/bundles/SyliusShopBundle/Taxon/Header/_content.html.twig new file mode 100644 index 000000000..c55f25be1 --- /dev/null +++ b/tests/Application/templates/bundles/SyliusShopBundle/Taxon/Header/_content.html.twig @@ -0,0 +1,6 @@ +

+ {{ taxon.name }} +
{{ taxon.description }}
+

+ +{{ bitbag_cms_render_block('lorem_ipsum', null, taxon) }} From 68bd3f5d53614ea71b30b9b8d060c3861c71f405 Mon Sep 17 00:00:00 2001 From: jkindly Date: Fri, 19 Jul 2024 12:34:57 +0200 Subject: [PATCH 2/8] OP-440: Translations --- src/Resources/translations/messages.cs.yml | 10 ++++++++++ src/Resources/translations/messages.cs_CZ.yml | 10 ++++++++++ src/Resources/translations/messages.de.yml | 10 ++++++++++ src/Resources/translations/messages.en.yml | 10 ++++++++++ src/Resources/translations/messages.es.yml | 10 ++++++++++ src/Resources/translations/messages.fr.yml | 10 ++++++++++ src/Resources/translations/messages.hr.yml | 10 ++++++++++ src/Resources/translations/messages.lt.yml | 10 ++++++++++ src/Resources/translations/messages.nl.yml | 10 ++++++++++ src/Resources/translations/messages.pl.yml | 10 ++++++++++ src/Resources/translations/messages.ru.yml | 10 ++++++++++ src/Resources/translations/messages.sk.yml | 10 ++++++++++ src/Resources/translations/messages.uk.yml | 10 ++++++++++ 13 files changed, 130 insertions(+) diff --git a/src/Resources/translations/messages.cs.yml b/src/Resources/translations/messages.cs.yml index 6ad54fb2f..1648a6c49 100755 --- a/src/Resources/translations/messages.cs.yml +++ b/src/Resources/translations/messages.cs.yml @@ -20,6 +20,16 @@ bitbag_sylius_cms_plugin: products_grid_by_taxon: Produkty v mřížce podle taxonu heading_type: Typ nadpisu taxon: Taxon + display_for_products: + label: Zobrazit pro produkty + help: Vyberte produkty, ve kterých se bude tento blok zobrazovat + display_for_products_in_taxons: + label: Zobrazit pro produkty v taxonech + help: Tento blok bude zobrazen pro produkty ve vybraných taxonech. Pouze "Hlavní taxon" je brán v úvahu. + display_for_taxons: + label: Zobrazit pro taxony + help: Vyberte taxony, ve kterých se bude tento blok zobrazovat + manage_block_display: Správa zobrazení bloku cms: content_management: Obsahový management cms: Obsahový management diff --git a/src/Resources/translations/messages.cs_CZ.yml b/src/Resources/translations/messages.cs_CZ.yml index 6ad54fb2f..1648a6c49 100755 --- a/src/Resources/translations/messages.cs_CZ.yml +++ b/src/Resources/translations/messages.cs_CZ.yml @@ -20,6 +20,16 @@ bitbag_sylius_cms_plugin: products_grid_by_taxon: Produkty v mřížce podle taxonu heading_type: Typ nadpisu taxon: Taxon + display_for_products: + label: Zobrazit pro produkty + help: Vyberte produkty, ve kterých se bude tento blok zobrazovat + display_for_products_in_taxons: + label: Zobrazit pro produkty v taxonech + help: Tento blok bude zobrazen pro produkty ve vybraných taxonech. Pouze "Hlavní taxon" je brán v úvahu. + display_for_taxons: + label: Zobrazit pro taxony + help: Vyberte taxony, ve kterých se bude tento blok zobrazovat + manage_block_display: Správa zobrazení bloku cms: content_management: Obsahový management cms: Obsahový management diff --git a/src/Resources/translations/messages.de.yml b/src/Resources/translations/messages.de.yml index 18cb3c28f..ff3180d51 100755 --- a/src/Resources/translations/messages.de.yml +++ b/src/Resources/translations/messages.de.yml @@ -70,3 +70,13 @@ bitbag_sylius_cms_plugin: products_grid_by_taxon: Produkte im Raster nach Taxon heading_type: Überschrift-Typ taxon: Taxon + display_for_products: + label: Display für Produkte + help: Wählen Sie Produkte aus, in denen dieser Block angezeigt wird + display_for_products_in_taxons: + label: Display für Produkte in Taxons + help: Dieser Block wird für Produkte in ausgewählten Taxonen angezeigt. Nur „Haupttaxon“ ist belegt. + display_for_taxons: + label: Display für Taxons + help: Wählen Sie Taxonen aus, in denen dieser Block angezeigt wird + manage_block_display: Blockanzeige verwalten diff --git a/src/Resources/translations/messages.en.yml b/src/Resources/translations/messages.en.yml index d8daf5cfa..2a6b073a3 100755 --- a/src/Resources/translations/messages.en.yml +++ b/src/Resources/translations/messages.en.yml @@ -75,3 +75,13 @@ bitbag_sylius_cms_plugin: heading_type: Heading type taxon: Taxon seo: SEO + display_for_products: + label: Display for products + help: Select products in which this block will be displayed + display_for_products_in_taxons: + label: Display for products in taxons + help: This block will be displayed for products in selected taxons. Only "Main Taxon" is taken. + display_for_taxons: + label: Display for taxons + help: Select taxons in which this block will be displayed + manage_block_display: Manage block display diff --git a/src/Resources/translations/messages.es.yml b/src/Resources/translations/messages.es.yml index b93bfcac0..6de50ed77 100755 --- a/src/Resources/translations/messages.es.yml +++ b/src/Resources/translations/messages.es.yml @@ -49,3 +49,13 @@ bitbag_sylius_cms_plugin: products_grid_by_taxon: Productos en cuadrícula por taxón heading_type: Tipo de encabezado taxon: Taxón + display_for_products: + label: Mostrar para productos + help: Seleccione productos en los que se mostrará este bloque + display_for_products_in_taxons: + label: Mostrar para productos en taxones + help: Este bloque se mostrará para productos en los taxones seleccionados. Solo se considera el "Taxón principal". + display_for_taxons: + label: Mostrar para taxones + help: Seleccione taxones en los que se mostrará este bloque + manage_block_display: Administrar visualización de bloques diff --git a/src/Resources/translations/messages.fr.yml b/src/Resources/translations/messages.fr.yml index 04ece97e9..1ec73eaa1 100755 --- a/src/Resources/translations/messages.fr.yml +++ b/src/Resources/translations/messages.fr.yml @@ -67,3 +67,13 @@ bitbag_sylius_cms_plugin: products_grid_by_taxon: Produits en grille par taxon heading_type: Type d'en-tête taxon: Taxon + display_for_products: + label: Afficher pour les produits + help: Ce bloc sera affiché pour les produits sélectionnés + display_for_products_in_taxons: + label: Afficher pour les produits dans les taxons + help: Ce bloc sera affiché pour les produits des taxons sélectionnés. Seul le « taxon principal » est pris en compte. + display_for_taxons: + label: Afficher pour les taxons + help: Ce bloc sera affiché pour les taxons sélectionnés + manage_block_display: Gérer l'affichage du bloc diff --git a/src/Resources/translations/messages.hr.yml b/src/Resources/translations/messages.hr.yml index 9296a3222..6f7c423fd 100755 --- a/src/Resources/translations/messages.hr.yml +++ b/src/Resources/translations/messages.hr.yml @@ -49,3 +49,13 @@ bitbag_sylius_cms_plugin: products_grid_by_taxon: Proizvodi u mreži po taksonu heading_type: Tip naslova taxon: Takson + display_for_products: + label: Prikaz za proizvode + help: Ovaj blok će biti prikazan za odabrane proizvode + display_for_products_in_taxons: + label: Prikaz za proizvode u taksonima + help: Ovaj će blok biti prikazan za proizvode u odabranim taksonima. Uzima se samo "Glavni takson". + display_for_taxons: + label: Prikaz za takson + help: Odaberite taksone u kojima će se ovaj blok prikazati + manage_block_display: Upravljanje prikazom bloka diff --git a/src/Resources/translations/messages.lt.yml b/src/Resources/translations/messages.lt.yml index 6799bf34f..6972d8d70 100644 --- a/src/Resources/translations/messages.lt.yml +++ b/src/Resources/translations/messages.lt.yml @@ -66,3 +66,13 @@ bitbag_sylius_cms_plugin: products_grid_by_taxon: Produktų tinklelis pagal taksoną heading_type: Antraštės tipas taxon: Taksonas + display_for_products: + label: Rodyti produktams + help: Pasirinkite produktus, kuriuose šis blokas bus rodomas + display_for_products_in_taxons: + label: Rodyti produktams + help: Šis blokas bus rodomas produktams pasirinktuose taksonuose. Paimamas tik „Pagrindinis taksonas“. + display_for_taxons: + label: Rodyti taksonams + help: Pasirinkite taksonus, kuriuose šis blokas bus rodomas + manage_block_display: Bloko rodymo valdymas diff --git a/src/Resources/translations/messages.nl.yml b/src/Resources/translations/messages.nl.yml index 4b23f947a..15e996263 100755 --- a/src/Resources/translations/messages.nl.yml +++ b/src/Resources/translations/messages.nl.yml @@ -48,3 +48,13 @@ bitbag_sylius_cms_plugin: products_grid_by_taxon: Producten grid per taxon heading_type: Kop type taxon: Taxon + display_for_products: + label: Display voor producten + help: Selecteer producten waarin dit blok wordt weergegeven + display_for_products_in_taxons: + label: Display voor producten in taxons + help: Dit blok wordt weergegeven voor producten in geselecteerde taxonen. Alleen "Hoofdtaxon" wordt gebruikt. + display_for_taxons: + label: Display voor taxons + help: Selecteer taxonen waarin dit blok wordt weergegeven + manage_block_display: Beheer blok weergave diff --git a/src/Resources/translations/messages.pl.yml b/src/Resources/translations/messages.pl.yml index 67a9d2ef3..641ad43cf 100755 --- a/src/Resources/translations/messages.pl.yml +++ b/src/Resources/translations/messages.pl.yml @@ -53,3 +53,13 @@ bitbag_sylius_cms_plugin: products_grid_by_taxon: Siatka produktów według taksonomii heading_type: Typ nagłówka taxon: Taksonomia + display_for_products: + label: Wyświetlaj dla produktów + help: Wybierz produkty, dla których ten blok będzie wyświetlany + display_for_products_in_taxons: + label: Wyświetlaj dla produktów w taksonomiach + help: Ten blok będzie wyświetlany dla produktów w wybranych taksonomiach. Tylko "Główna taksonomia" jest brana pod uwagę. + display_for_taxons: + label: Wyświetlaj dla taksonomii + help: Wybież taksonomie, dla których ten blok będzie wyświetlany + manage_block_display: Zarządzaj wyświetlaniem bloku diff --git a/src/Resources/translations/messages.ru.yml b/src/Resources/translations/messages.ru.yml index 6de939b42..321edc71c 100755 --- a/src/Resources/translations/messages.ru.yml +++ b/src/Resources/translations/messages.ru.yml @@ -66,3 +66,13 @@ bitbag_sylius_cms_plugin: products_grid_by_taxon: Продукты в сетке по таксону heading_type: Тип заголовка taxon: Таксон + display_for_products: + label: Отображать для товаров + help: Выберите товары, для которых этот блок будет отображаться + display_for_products_in_taxons: + label: Отображать для товаров в таксономиях + help: Этот блок будет отображаться для товаров в выбранных таксонах. Берется только «Основной таксон». + display_for_taxons: + label: Отображать для таксонов + help: Выберите таксоны, в которых будет отображаться этот блок + manage_block_display: Управление отображением блоков diff --git a/src/Resources/translations/messages.sk.yml b/src/Resources/translations/messages.sk.yml index 3e8fd8221..7091345c7 100644 --- a/src/Resources/translations/messages.sk.yml +++ b/src/Resources/translations/messages.sk.yml @@ -67,3 +67,13 @@ bitbag_sylius_cms_plugin: products_grid_by_taxon: Produkty v mriežke podľa taxónu heading_type: Typ nadpisu taxon: Taxón + display_for_products: + label: Zobraziť pre produkty + help: Tento blok bude zobrazený pre vybrané produkty + display_for_products_in_taxons: + label: Zobraziť pre produkty v taxónoch + help: Tento blok sa zobrazí pri produktoch vo vybraných taxónoch. Zaberie sa iba „hlavný taxón“. + display_for_taxons: + label: Zobrazenie pre taxóny + help: Vyberte taxóny, v ktorých sa tento blok zobrazí + manage_block_display: Spravovať zobrazenie bloku diff --git a/src/Resources/translations/messages.uk.yml b/src/Resources/translations/messages.uk.yml index dba77b1ec..6786a053e 100755 --- a/src/Resources/translations/messages.uk.yml +++ b/src/Resources/translations/messages.uk.yml @@ -66,3 +66,13 @@ bitbag_sylius_cms_plugin: products_grid_by_taxon: Продукти в сітці за таксоном heading_type: Тип заголовка taxon: Таксон + display_for_products: + label: Дисплей для продуктів + help: Цей блок буде відображатися для вибраних продуктів + display_for_products_in_taxons: + label: Дисплей для таксонів + help: Цей блок відображатиметься для продуктів у вибраних таксонах. Береться лише «Основний таксон». + display_for_taxons: + label: Дисплей для таксонів + help: Виберіть таксони, в яких буде відображатися цей блок + manage_block_display: Керування відображенням блоку From 37b1fbec7dcfc650802a4748c1a43ede2e89772d Mon Sep 17 00:00:00 2001 From: jkindly Date: Fri, 19 Jul 2024 12:35:03 +0200 Subject: [PATCH 3/8] OP-440: Migration --- src/Migrations/Version20240719070318.php | 47 ++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/Migrations/Version20240719070318.php diff --git a/src/Migrations/Version20240719070318.php b/src/Migrations/Version20240719070318.php new file mode 100644 index 000000000..09bd3a4e2 --- /dev/null +++ b/src/Migrations/Version20240719070318.php @@ -0,0 +1,47 @@ +addSql('CREATE TABLE bitbag_cms_block_products (block_id INT NOT NULL, product_id INT NOT NULL, INDEX IDX_C4B9089FE9ED820C (block_id), INDEX IDX_C4B9089F4584665A (product_id), PRIMARY KEY(block_id, product_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE bitbag_cms_block_taxons (block_id INT NOT NULL, taxon_id INT NOT NULL, INDEX IDX_E324C6CEE9ED820C (block_id), INDEX IDX_E324C6CEDE13F470 (taxon_id), PRIMARY KEY(block_id, taxon_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE bitbag_cms_block_products_in_taxons (block_id INT NOT NULL, taxon_id INT NOT NULL, INDEX IDX_DAA9DD18E9ED820C (block_id), INDEX IDX_DAA9DD18DE13F470 (taxon_id), PRIMARY KEY(block_id, taxon_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('ALTER TABLE bitbag_cms_block_products ADD CONSTRAINT FK_C4B9089FE9ED820C FOREIGN KEY (block_id) REFERENCES bitbag_cms_block (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE bitbag_cms_block_products ADD CONSTRAINT FK_C4B9089F4584665A FOREIGN KEY (product_id) REFERENCES sylius_product (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE bitbag_cms_block_taxons ADD CONSTRAINT FK_E324C6CEE9ED820C FOREIGN KEY (block_id) REFERENCES bitbag_cms_block (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE bitbag_cms_block_taxons ADD CONSTRAINT FK_E324C6CEDE13F470 FOREIGN KEY (taxon_id) REFERENCES sylius_taxon (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE bitbag_cms_block_products_in_taxons ADD CONSTRAINT FK_DAA9DD18E9ED820C FOREIGN KEY (block_id) REFERENCES bitbag_cms_block (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE bitbag_cms_block_products_in_taxons ADD CONSTRAINT FK_DAA9DD18DE13F470 FOREIGN KEY (taxon_id) REFERENCES sylius_taxon (id) ON DELETE CASCADE'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE bitbag_cms_block_products DROP FOREIGN KEY FK_C4B9089FE9ED820C'); + $this->addSql('ALTER TABLE bitbag_cms_block_products DROP FOREIGN KEY FK_C4B9089F4584665A'); + $this->addSql('ALTER TABLE bitbag_cms_block_taxons DROP FOREIGN KEY FK_E324C6CEE9ED820C'); + $this->addSql('ALTER TABLE bitbag_cms_block_taxons DROP FOREIGN KEY FK_E324C6CEDE13F470'); + $this->addSql('ALTER TABLE bitbag_cms_block_products_in_taxons DROP FOREIGN KEY FK_DAA9DD18E9ED820C'); + $this->addSql('ALTER TABLE bitbag_cms_block_products_in_taxons DROP FOREIGN KEY FK_DAA9DD18DE13F470'); + $this->addSql('DROP TABLE bitbag_cms_block_products'); + $this->addSql('DROP TABLE bitbag_cms_block_taxons'); + $this->addSql('DROP TABLE bitbag_cms_block_products_in_taxons'); + } +} From e9f77e8ae0e5927c3f856d0a1b6cb2822e2943c6 Mon Sep 17 00:00:00 2001 From: jkindly Date: Fri, 19 Jul 2024 12:47:43 +0200 Subject: [PATCH 4/8] OP-440: PHPStan & ECS fixes --- src/Entity/Trait/ProductsAwareTrait.php | 2 +- src/Entity/Trait/ProductsInTaxonsAwareTrait.php | 2 +- src/Entity/Trait/TaxonAwareTrait.php | 2 +- src/Form/Type/BlockType.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Entity/Trait/ProductsAwareTrait.php b/src/Entity/Trait/ProductsAwareTrait.php index 3710dea32..57c35f557 100755 --- a/src/Entity/Trait/ProductsAwareTrait.php +++ b/src/Entity/Trait/ProductsAwareTrait.php @@ -17,7 +17,7 @@ trait ProductsAwareTrait { /** @var Collection|ProductInterface[] */ - protected array|Collection $products; + protected Collection $products; public function initializeProductsCollection(): void { diff --git a/src/Entity/Trait/ProductsInTaxonsAwareTrait.php b/src/Entity/Trait/ProductsInTaxonsAwareTrait.php index 6e331bdf8..f95dea5a7 100644 --- a/src/Entity/Trait/ProductsInTaxonsAwareTrait.php +++ b/src/Entity/Trait/ProductsInTaxonsAwareTrait.php @@ -17,7 +17,7 @@ trait ProductsInTaxonsAwareTrait { /** @var Collection|TaxonInterface[] */ - protected array|Collection $productsInTaxons; + protected Collection $productsInTaxons; public function initializeProductsInTaxonsCollection(): void { diff --git a/src/Entity/Trait/TaxonAwareTrait.php b/src/Entity/Trait/TaxonAwareTrait.php index 8edc13cc7..6679e4931 100644 --- a/src/Entity/Trait/TaxonAwareTrait.php +++ b/src/Entity/Trait/TaxonAwareTrait.php @@ -17,7 +17,7 @@ trait TaxonAwareTrait { /** @var Collection|TaxonInterface[] */ - protected array|Collection $taxons; + protected Collection $taxons; public function initializeTaxonCollection(): void { diff --git a/src/Form/Type/BlockType.php b/src/Form/Type/BlockType.php index 73fb6c3de..d2472dc34 100755 --- a/src/Form/Type/BlockType.php +++ b/src/Form/Type/BlockType.php @@ -65,7 +65,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ->add('productsInTaxons', TaxonAutocompleteChoiceType::class, [ 'label' => 'bitbag_sylius_cms_plugin.ui.display_for_products_in_taxons.label', 'multiple' => true, - 'help' => 'bitbag_sylius_cms_plugin.ui.display_for_products_in_taxons.help' + 'help' => 'bitbag_sylius_cms_plugin.ui.display_for_products_in_taxons.help', ]) ->add('taxons', TaxonAutocompleteChoiceType::class, [ 'label' => 'bitbag_sylius_cms_plugin.ui.display_for_taxons.label', From 61913108eff792a6a3d4500acfd07a90f37ba5d3 Mon Sep 17 00:00:00 2001 From: jkindly Date: Mon, 22 Jul 2024 08:37:41 +0200 Subject: [PATCH 5/8] OP-440: Spec --- spec/Twig/Runtime/RenderBlockRuntimeSpec.php | 66 ++++++++++++++----- .../SyliusShopBundle/Product/show.html.twig | 2 - 2 files changed, 49 insertions(+), 19 deletions(-) diff --git a/spec/Twig/Runtime/RenderBlockRuntimeSpec.php b/spec/Twig/Runtime/RenderBlockRuntimeSpec.php index 85c9a3df1..72fab0841 100644 --- a/spec/Twig/Runtime/RenderBlockRuntimeSpec.php +++ b/spec/Twig/Runtime/RenderBlockRuntimeSpec.php @@ -18,6 +18,8 @@ use BitBag\SyliusCmsPlugin\Twig\Runtime\RenderBlockRuntime; use BitBag\SyliusCmsPlugin\Twig\Runtime\RenderBlockRuntimeInterface; use PhpSpec\ObjectBehavior; +use Sylius\Component\Core\Model\ProductInterface; +use Sylius\Component\Core\Model\TaxonInterface; use Twig\Environment; final class RenderBlockRuntimeSpec extends ObjectBehavior @@ -25,7 +27,7 @@ final class RenderBlockRuntimeSpec extends ObjectBehavior public function let( BlockResourceResolverInterface $blockResourceResolver, Environment $templatingEngine, - ContentElementRendererStrategyInterface $contentElementRendererStrategy, + ContentElementRendererStrategyInterface $contentElementRendererStrategy ): void { $this->beConstructedWith($blockResourceResolver, $templatingEngine, $contentElementRendererStrategy); } @@ -37,38 +39,68 @@ public function it_is_initializable(): void public function it_implements_render_block_runtime_interface(): void { - $this->shouldHaveType(RenderBlockRuntimeInterface::class); + $this->shouldImplement(RenderBlockRuntimeInterface::class); + } + + public function it_returns_empty_string_when_block_not_found(BlockResourceResolverInterface $blockResourceResolver): void + { + $blockResourceResolver->findOrLog('code')->willReturn(null); + + $this->renderBlock('code')->shouldReturn(''); } - public function it_renders_block( + public function it_returns_empty_string_when_block_not_displayable_for_taxon( BlockResourceResolverInterface $blockResourceResolver, BlockInterface $block, + TaxonInterface $taxon + ): void { + $blockResourceResolver->findOrLog('code')->willReturn($block); + $block->canBeDisplayedForTaxon($taxon)->willReturn(false); + + $this->renderBlock('code', null, $taxon)->shouldReturn(''); + } + + public function it_returns_empty_string_when_block_not_displayable_for_product( + BlockResourceResolverInterface $blockResourceResolver, + BlockInterface $block, + ProductInterface $product + ): void { + $blockResourceResolver->findOrLog('code')->willReturn($block); + $block->canBeDisplayedForProduct($product)->willReturn(false); + $block->canBeDisplayedForProductInTaxon($product)->willReturn(false); + + $this->renderBlock('code', null, $product)->shouldReturn(''); + } + + public function it_renders_block_with_default_template( + BlockResourceResolverInterface $blockResourceResolver, Environment $templatingEngine, ContentElementRendererStrategyInterface $contentElementRendererStrategy, + BlockInterface $block ): void { - $blockResourceResolver->findOrLog('bitbag')->willReturn($block); + $blockResourceResolver->findOrLog('code')->willReturn($block); $contentElementRendererStrategy->render($block)->willReturn('rendered content'); - $templatingEngine->render( - '@BitBagSyliusCmsPlugin/Shop/Block/show.html.twig', - ['content' => 'rendered content'], - )->willReturn('
BitBag
'); - $this->renderBlock('bitbag'); + $templatingEngine->render('@BitBagSyliusCmsPlugin/Shop/Block/show.html.twig', [ + 'content' => 'rendered content', + ])->willReturn('rendered block'); + + $this->renderBlock('code')->shouldReturn('rendered block'); } - public function it_renders_block_with_template( + public function it_renders_block_with_custom_template( BlockResourceResolverInterface $blockResourceResolver, - BlockInterface $block, Environment $templatingEngine, ContentElementRendererStrategyInterface $contentElementRendererStrategy, + BlockInterface $block ): void { - $blockResourceResolver->findOrLog('bitbag')->willReturn($block); + $blockResourceResolver->findOrLog('code')->willReturn($block); $contentElementRendererStrategy->render($block)->willReturn('rendered content'); - $templatingEngine->render( - '@BitBagSyliusCmsPlugin/Shop/Block/otherTemplate.html.twig', - ['content' => 'rendered content'], - )->willReturn('
BitBag Other Template
'); - $this->renderBlock('bitbag', '@BitBagSyliusCmsPlugin/Shop/Block/otherTemplate.html.twig'); + $templatingEngine->render('custom_template.html.twig', [ + 'content' => 'rendered content', + ])->willReturn('rendered block'); + + $this->renderBlock('code', 'custom_template.html.twig')->shouldReturn('rendered block'); } } diff --git a/tests/Application/templates/bundles/SyliusShopBundle/Product/show.html.twig b/tests/Application/templates/bundles/SyliusShopBundle/Product/show.html.twig index 37da1040b..8955ade69 100755 --- a/tests/Application/templates/bundles/SyliusShopBundle/Product/show.html.twig +++ b/tests/Application/templates/bundles/SyliusShopBundle/Product/show.html.twig @@ -50,8 +50,6 @@
- {{ render(path('bitbag_sylius_cms_plugin_shop_block_index_by_collection_code', {'collectionCode' : 'products', 'template' : '@BitBagSyliusCmsPlugin/Shop/Block/index.html.twig'})) }} - {{ bitbag_cms_render_block('lorem_ipsum', null, product) }} {{ sonata_block_render_event('sylius.shop.product.show.before_tabs', {'product': product}) }} From 05d57933f8aaca875c5b21a5b6a34f59191c82d4 Mon Sep 17 00:00:00 2001 From: jkindly Date: Mon, 22 Jul 2024 08:40:33 +0200 Subject: [PATCH 6/8] OP-440: Migration comments --- src/Migrations/Version20240719070318.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Migrations/Version20240719070318.php b/src/Migrations/Version20240719070318.php index 09bd3a4e2..dbbccf8df 100644 --- a/src/Migrations/Version20240719070318.php +++ b/src/Migrations/Version20240719070318.php @@ -1,5 +1,11 @@ addSql('CREATE TABLE bitbag_cms_block_products (block_id INT NOT NULL, product_id INT NOT NULL, INDEX IDX_C4B9089FE9ED820C (block_id), INDEX IDX_C4B9089F4584665A (product_id), PRIMARY KEY(block_id, product_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); $this->addSql('CREATE TABLE bitbag_cms_block_taxons (block_id INT NOT NULL, taxon_id INT NOT NULL, INDEX IDX_E324C6CEE9ED820C (block_id), INDEX IDX_E324C6CEDE13F470 (taxon_id), PRIMARY KEY(block_id, taxon_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); $this->addSql('CREATE TABLE bitbag_cms_block_products_in_taxons (block_id INT NOT NULL, taxon_id INT NOT NULL, INDEX IDX_DAA9DD18E9ED820C (block_id), INDEX IDX_DAA9DD18DE13F470 (taxon_id), PRIMARY KEY(block_id, taxon_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); @@ -33,7 +35,6 @@ public function up(Schema $schema): void public function down(Schema $schema): void { - // this down() migration is auto-generated, please modify it to your needs $this->addSql('ALTER TABLE bitbag_cms_block_products DROP FOREIGN KEY FK_C4B9089FE9ED820C'); $this->addSql('ALTER TABLE bitbag_cms_block_products DROP FOREIGN KEY FK_C4B9089F4584665A'); $this->addSql('ALTER TABLE bitbag_cms_block_taxons DROP FOREIGN KEY FK_E324C6CEE9ED820C'); From a5144b259745bca861d9c0e0df62b59741920695 Mon Sep 17 00:00:00 2001 From: jkindly Date: Mon, 22 Jul 2024 09:01:50 +0200 Subject: [PATCH 7/8] OP-440: PHPUnit fix --- src/Resources/config/serialization/Block.xml | 7 +++++-- .../Api/BlockTest/test_it_get_block_by_id.json | 5 ++++- .../Api/BlockTest/test_it_get_blocks.json | 15 ++++++++++++--- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/Resources/config/serialization/Block.xml b/src/Resources/config/serialization/Block.xml index 7549db77b..6bcab96ea 100644 --- a/src/Resources/config/serialization/Block.xml +++ b/src/Resources/config/serialization/Block.xml @@ -16,15 +16,18 @@ shop:cms:read - + shop:cms:read - + shop:cms:read shop:cms:read + + shop:cms:read + shop:cms:read diff --git a/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_block_by_id.json b/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_block_by_id.json index 857e57f70..dbc9c1802 100644 --- a/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_block_by_id.json +++ b/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_block_by_id.json @@ -16,5 +16,8 @@ "channels": [ "/api/v2/shop/channels/code" ], - "contentElements": [] + "contentElements": [], + "products": [], + "taxons": [], + "productsInTaxons": [] } diff --git a/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_blocks.json b/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_blocks.json index 7a770ed6f..c163c76eb 100644 --- a/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_blocks.json +++ b/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_blocks.json @@ -20,7 +20,10 @@ "channels": [ "/api/v2/shop/channels/code" ], - "contentElements": [] + "contentElements": [], + "products": [], + "taxons": [], + "productsInTaxons": [] }, { "@id": "/api/v2/shop/cms-plugin/blocks/@integer@", @@ -39,7 +42,10 @@ "channels": [ "/api/v2/shop/channels/code" ], - "contentElements": [] + "contentElements": [], + "products": [], + "taxons": [], + "productsInTaxons": [] }, { "@id": "/api/v2/shop/cms-plugin/blocks/@integer@", @@ -58,7 +64,10 @@ "channels": [ "/api/v2/shop/channels/code" ], - "contentElements": [] + "contentElements": [], + "products": [], + "taxons": [], + "productsInTaxons": [] } ], "hydra:totalItems": 3 From 7f948bdc215ca4fd5dae0a8c773357eefd700c91 Mon Sep 17 00:00:00 2001 From: jkindly Date: Wed, 24 Jul 2024 08:51:21 +0200 Subject: [PATCH 8/8] OP-440: Remove unnecessary traits and move methods to existing traits --- src/Entity/Block.php | 4 --- src/Entity/Trait/BlockProductAwareTrait.php | 31 ------------------- src/Entity/Trait/BlockTaxonAwareTrait.php | 21 ------------- src/Entity/Trait/ProductsAwareTrait.php | 5 +++ .../Trait/ProductsInTaxonsAwareTrait.php | 11 +++++++ src/Entity/Trait/TaxonAwareTrait.php | 5 +++ 6 files changed, 21 insertions(+), 56 deletions(-) delete mode 100644 src/Entity/Trait/BlockProductAwareTrait.php delete mode 100644 src/Entity/Trait/BlockTaxonAwareTrait.php diff --git a/src/Entity/Block.php b/src/Entity/Block.php index 3457c357c..072cddcfc 100755 --- a/src/Entity/Block.php +++ b/src/Entity/Block.php @@ -10,8 +10,6 @@ namespace BitBag\SyliusCmsPlugin\Entity; -use BitBag\SyliusCmsPlugin\Entity\Trait\BlockProductAwareTrait; -use BitBag\SyliusCmsPlugin\Entity\Trait\BlockTaxonAwareTrait; use BitBag\SyliusCmsPlugin\Entity\Trait\ChannelsAwareTrait; use BitBag\SyliusCmsPlugin\Entity\Trait\CollectibleTrait; use BitBag\SyliusCmsPlugin\Entity\Trait\ContentConfigurationAwareTrait; @@ -31,8 +29,6 @@ class Block implements BlockInterface use ProductsAwareTrait; use TaxonAwareTrait; use ProductsInTaxonsAwareTrait; - use BlockTaxonAwareTrait; - use BlockProductAwareTrait; public function __construct() { diff --git a/src/Entity/Trait/BlockProductAwareTrait.php b/src/Entity/Trait/BlockProductAwareTrait.php deleted file mode 100644 index 27c13ab82..000000000 --- a/src/Entity/Trait/BlockProductAwareTrait.php +++ /dev/null @@ -1,31 +0,0 @@ -hasProduct($product); - } - - public function canBeDisplayedForProductInTaxon(ProductInterface $product): bool - { - $taxon = $product->getMainTaxon(); - if (null === $taxon) { - return false; - } - - return $this->hasProductsInTaxon($taxon); - } -} diff --git a/src/Entity/Trait/BlockTaxonAwareTrait.php b/src/Entity/Trait/BlockTaxonAwareTrait.php deleted file mode 100644 index c84cd24cd..000000000 --- a/src/Entity/Trait/BlockTaxonAwareTrait.php +++ /dev/null @@ -1,21 +0,0 @@ -hasTaxon($taxon); - } -} diff --git a/src/Entity/Trait/ProductsAwareTrait.php b/src/Entity/Trait/ProductsAwareTrait.php index 57c35f557..c91f80178 100755 --- a/src/Entity/Trait/ProductsAwareTrait.php +++ b/src/Entity/Trait/ProductsAwareTrait.php @@ -47,4 +47,9 @@ public function removeProduct(ProductInterface $product): void $this->products->removeElement($product); } } + + public function canBeDisplayedForProduct(ProductInterface $product): bool + { + return $this->hasProduct($product); + } } diff --git a/src/Entity/Trait/ProductsInTaxonsAwareTrait.php b/src/Entity/Trait/ProductsInTaxonsAwareTrait.php index f95dea5a7..3374808f3 100644 --- a/src/Entity/Trait/ProductsInTaxonsAwareTrait.php +++ b/src/Entity/Trait/ProductsInTaxonsAwareTrait.php @@ -12,6 +12,7 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; +use Sylius\Component\Core\Model\ProductInterface; use Sylius\Component\Core\Model\TaxonInterface; trait ProductsInTaxonsAwareTrait @@ -47,4 +48,14 @@ public function removeProductsInTaxon(TaxonInterface $taxon): void $this->productsInTaxons->removeElement($taxon); } } + + public function canBeDisplayedForProductInTaxon(ProductInterface $product): bool + { + $taxon = $product->getMainTaxon(); + if (null === $taxon) { + return false; + } + + return $this->hasProductsInTaxon($taxon); + } } diff --git a/src/Entity/Trait/TaxonAwareTrait.php b/src/Entity/Trait/TaxonAwareTrait.php index 6679e4931..2a5af43b8 100644 --- a/src/Entity/Trait/TaxonAwareTrait.php +++ b/src/Entity/Trait/TaxonAwareTrait.php @@ -47,4 +47,9 @@ public function removeTaxon(TaxonInterface $taxon): void $this->taxons->removeElement($taxon); } } + + public function canBeDisplayedForTaxon(TaxonInterface $taxon): bool + { + return $this->hasTaxon($taxon); + } }