Skip to content

Commit

Permalink
OP-289: List bundles on product detail admin page
Browse files Browse the repository at this point in the history
  • Loading branch information
hmfilar committed Aug 20, 2024
1 parent a9d546c commit 01587f2
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/Resources/config/services/filter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
<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_product_bundle.grid.filter.is_bundle" class="BitBag\SyliusProductBundlePlugin\Grid\Filter\IsBundleFilter">
<service id="bitbag_sylius_product_bundle.grid.filter.is_bundle"
class="BitBag\SyliusProductBundlePlugin\Grid\Filter\IsBundleFilter">
<argument type="service" id="bitbag_sylius_product_bundle.repository.product_bundle"/>
<tag name="sylius.grid_filter" type="is_bundle" form_type="Sylius\Bundle\GridBundle\Form\Type\Filter\BooleanFilterType" />
<tag name="sylius.grid_filter" type="is_bundle"
form_type="Sylius\Bundle\GridBundle\Form\Type\Filter\BooleanFilterType"/>
</service>
</services>
</container>
17 changes: 12 additions & 5 deletions src/Resources/config/services/twig.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
<?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">
<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_product_bundle.twig.extension.smash_promotion" class="BitBag\SyliusProductBundlePlugin\Twig\Extension\ProductBundleOrderItemExtension" public="false">
<argument type="service" id="bitbag_sylius_product_bundle.repository.product_bundle_order_item" />
<argument type="service" id="twig" />
<tag name="twig.extension" />
<service id="bitbag_sylius_product_bundle.twig.extension.smash_promotion"
class="BitBag\SyliusProductBundlePlugin\Twig\Extension\ProductBundleOrderItemExtension" public="false">
<argument type="service" id="bitbag_sylius_product_bundle.repository.product_bundle_order_item"/>
<argument type="service" id="twig"/>
<tag name="twig.extension"/>
</service>
<service id="bitbag_sylius_product_bundle.twig.extension.product_bundles"
class="BitBag\SyliusProductBundlePlugin\Twig\Extension\ProductBundlesExtension" public="false">
<argument type="service" id="bitbag_sylius_product_bundle.repository.product_bundle"/>
<tag name="twig.extension"/>
</service>
</services>
</container>
1 change: 1 addition & 0 deletions src/Resources/translations/messages.en.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
bitbag_sylius_product_bundle:
ui:
bundle: Bundle
bundles: Bundles
product_variant: Product variant
quantity: Quantity
delete: Delete
Expand Down
26 changes: 26 additions & 0 deletions src/Resources/views/Admin/Product/show.html.twig
Original file line number Diff line number Diff line change
@@ -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 %}
<div class="ui hidden divider"></div>
<div>
<h4 class="ui top attached large header">{{ 'bitbag_sylius_product_bundle.ui.bundles'|trans }}</h4>
{% for bundle in bundles %}
<div class="ui attached segment text-break">
<a href="{{ path('sylius_admin_product_update', {id: bundle.product.id}) }}">
{{ bundle.product.name }}
</a>
</div>
{% endfor %}
</div>
{% endif %}
{% endblock %}
39 changes: 39 additions & 0 deletions src/Twig/Extension/ProductBundlesExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?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);

namespace BitBag\SyliusProductBundlePlugin\Twig\Extension;

use BitBag\SyliusProductBundlePlugin\Entity\ProductBundleInterface;
use BitBag\SyliusProductBundlePlugin\Entity\ProductInterface;
use BitBag\SyliusProductBundlePlugin\Repository\ProductBundleRepositoryInterface;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

final class ProductBundlesExtension extends AbstractExtension
{
public function __construct(
private ProductBundleRepositoryInterface $productBundleRepository,
) {
}

public function getFunctions(): array
{
return [
new TwigFunction('bitbag_get_bundles_containing_product', [$this, 'getBundlesForProduct'], ['is_safe' => ['html']]),
];
}

/** @return ProductBundleInterface[] */
public function getBundlesForProduct(ProductInterface $product): array
{
return $this->productBundleRepository->findBundlesByVariants($product->getVariants());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% include '@BitBagSyliusProductBundlePlugin/Admin/Product/show.html.twig' %}

0 comments on commit 01587f2

Please sign in to comment.