From 01587f2425a7347e187a51f75fafd62260ec3ffb Mon Sep 17 00:00:00 2001 From: Hubert Filar Date: Mon, 19 Aug 2024 12:40:54 +0200 Subject: [PATCH] OP-289: List bundles on product detail admin page --- src/Resources/config/services/filter.xml | 6 ++- src/Resources/config/services/twig.xml | 17 +++++--- src/Resources/translations/messages.en.yml | 1 + .../views/Admin/Product/show.html.twig | 26 +++++++++++++ .../Extension/ProductBundlesExtension.php | 39 +++++++++++++++++++ .../SyliusAdminBundle/Product/show.html.twig | 1 + 6 files changed, 83 insertions(+), 7 deletions(-) create mode 100644 src/Resources/views/Admin/Product/show.html.twig create mode 100644 src/Twig/Extension/ProductBundlesExtension.php create mode 100644 tests/Application/templates/bundles/SyliusAdminBundle/Product/show.html.twig diff --git a/src/Resources/config/services/filter.xml b/src/Resources/config/services/filter.xml index 70cc729d..5d9c7bae 100644 --- a/src/Resources/config/services/filter.xml +++ b/src/Resources/config/services/filter.xml @@ -3,9 +3,11 @@ - + - + diff --git a/src/Resources/config/services/twig.xml b/src/Resources/config/services/twig.xml index e67c3568..e2e9a173 100644 --- a/src/Resources/config/services/twig.xml +++ b/src/Resources/config/services/twig.xml @@ -1,11 +1,18 @@ - + - - - - + + + + + + + + diff --git a/src/Resources/translations/messages.en.yml b/src/Resources/translations/messages.en.yml index e6e23f97..61f378c3 100644 --- a/src/Resources/translations/messages.en.yml +++ b/src/Resources/translations/messages.en.yml @@ -1,6 +1,7 @@ bitbag_sylius_product_bundle: ui: bundle: Bundle + bundles: Bundles product_variant: Product variant quantity: Quantity delete: Delete diff --git a/src/Resources/views/Admin/Product/show.html.twig b/src/Resources/views/Admin/Product/show.html.twig new file mode 100644 index 00000000..2c19840a --- /dev/null +++ b/src/Resources/views/Admin/Product/show.html.twig @@ -0,0 +1,26 @@ +{% extends '@SyliusAdmin/layout.html.twig' %} + +{% block title %}{{ 'sylius.ui.show_product'|trans }} | {{ product.name }}{% endblock %} + +{% block content %} + {% if product.variants|length == 1 %} + {% include "@SyliusAdmin/Product/Show/_simpleProduct.html.twig" %} + {% else %} + {% include "@SyliusAdmin/Product/Show/_configurableProduct.html.twig" %} + {% endif %} + + {% set bundles = bitbag_get_bundles_containing_product(product) %} + {% if bundles|length > 0 %} + +
+

{{ 'bitbag_sylius_product_bundle.ui.bundles'|trans }}

+ {% for bundle in bundles %} + + {% endfor %} +
+ {% endif %} +{% endblock %} diff --git a/src/Twig/Extension/ProductBundlesExtension.php b/src/Twig/Extension/ProductBundlesExtension.php new file mode 100644 index 00000000..eb2824a8 --- /dev/null +++ b/src/Twig/Extension/ProductBundlesExtension.php @@ -0,0 +1,39 @@ + ['html']]), + ]; + } + + /** @return ProductBundleInterface[] */ + public function getBundlesForProduct(ProductInterface $product): array + { + return $this->productBundleRepository->findBundlesByVariants($product->getVariants()); + } +} diff --git a/tests/Application/templates/bundles/SyliusAdminBundle/Product/show.html.twig b/tests/Application/templates/bundles/SyliusAdminBundle/Product/show.html.twig new file mode 100644 index 00000000..054123dd --- /dev/null +++ b/tests/Application/templates/bundles/SyliusAdminBundle/Product/show.html.twig @@ -0,0 +1 @@ +{% include '@BitBagSyliusProductBundlePlugin/Admin/Product/show.html.twig' %}