# Creating or replacing service with tag

**URL:** <https://forum.shopware.com/t/creating-or-replacing-service-with-tag/47956>\
**Category:** International (English Only)\
**Tags:** programming\
**Created:** [31. August 2017 um 10:24 UTC](https://forum.shopware.com/t/creating-or-replacing-service-with-tag/47956 "2017-08-31T10:24:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dkasperski](https://avatars.discourse-cdn.com/v4/letter/d/d07c76/32.png) [@dkasperski](https://forum.shopware.com/u/dkasperski)\
**Post date:** [31. August 2017 um 10:24 UTC](https://forum.shopware.com/t/creating-or-replacing-service-with-tag/47956/1 "2017-08-31T10:24:28Z")

</div>

Hello everyone,

I have one question about creating or replacing services in custom plugins. More precisely, I’m going to replace service “shopware\_searchdbal.property\_facet\_handler\_dbal”, service definition in shopware core looks like:

My service definition in my custom plugin looks like:

```
    public function replaceSearchdbalPropertyFacetHandlerDbalService()
    {
        $shopwareStorefrontPropertyGatewayService = Shopware()->Container()->get('shopware_storefront.property_gateway');
        $dbalQueryBuilderFactoryService = Shopware()->Container()->get('shopware_searchdbal.dbal_query_builder_factory');
        $queryAliasMapperService = Shopware()->Container()->get('query_alias_mapper');

        Shopware()->Container()->set(
            'shopware_searchdbal.property_facet_handler_dbal',
            new AmsPropertyFacetHandler(
                $shopwareStorefrontPropertyGatewayService,
                $dbalQueryBuilderFactoryService,
                $queryAliasMapperService
            )
        );
    }

```

my question is how to add tag in plugin service definition?

Thanks in advice.

---

<div class="post-metadata">

**Author:** ![dkasperski](https://avatars.discourse-cdn.com/v4/letter/d/d07c76/32.png) [@dkasperski](https://forum.shopware.com/u/dkasperski)\
**Post date:** [3. Oktober 2017 um 11:33 UTC](https://forum.shopware.com/t/creating-or-replacing-service-with-tag/47956/2 "2017-10-03T11:33:00Z")

</div>

Whoever is able to help?

---

<div class="post-metadata">

**Author:** ![irfanh94](https://avatars.discourse-cdn.com/v4/letter/i/8dc957/32.png) [@irfanh94](https://forum.shopware.com/u/irfanh94)\
**Post date:** [4. Oktober 2017 um 07:47 UTC](https://forum.shopware.com/t/creating-or-replacing-service-with-tag/47956/3 "2017-10-04T07:47:30Z")

</div>

I can help you, but what excatly do you want to do? To create your own service for some events or to decorate shopwares existing event?

---

<div class="post-metadata">

**Author:** ![dkasperski](https://avatars.discourse-cdn.com/v4/letter/d/d07c76/32.png) [@dkasperski](https://forum.shopware.com/u/dkasperski)\
**Post date:** [4. Oktober 2017 um 08:02 UTC](https://forum.shopware.com/t/creating-or-replacing-service-with-tag/47956/4 "2017-10-04T08:02:34Z")

</div>

I want to extend “PropertyFacetHandler” because I would like filters that have numerical values to be presented as sliders. I modified method (createCollectionResult)&nbsp; from my custom PropertyFacetHandler:

```
                if ($useSlider) {

                    list($min, $max, $activeMin, $activeMax, $minField, $maxField) = $this->getStats($group, $criteria);

                    $results[] = new RangeFacetResult(
                        $facet->getName(),
                        $criteria->hasCondition($facet->getName()),
                        $group->getName(),
                        (float) $min,
                        (float) $max,
                        (float) $activeMin,
                        (float) $activeMax,
                        $minField,
                        $maxField,
                        [],
                        null,
                        0,
                        'frontend/listing/filter/facet-range.tpl'
                    );
                } elseif ($useMedia) {
                    $results[] = new MediaListFacetResult(
                        $facet->getName(),
                        $isActive,
                        $group->getName(),
                        $items,
                        $this->fieldName,
                        $group->getAttributes()
                    );
                } else {
                    $results[] = new ValueListFacetResult(
                        $facet->getName(),
                        $isActive,
                        $group->getName(),
                        $items,
                        $this->fieldName,
                        $group->getAttributes()
                    );
                }

```

And that all I want to modify. To do this, I need to overwrite the service:

```
shopware_searchdbal.property_facet_handler_dbal

```

But I don’t know how to add tag to service in plugin configuration.

---

<div class="post-metadata">

**Author:** ![irfanh94](https://avatars.discourse-cdn.com/v4/letter/i/8dc957/32.png) [@irfanh94](https://forum.shopware.com/u/irfanh94)\
**Post date:** [4. Oktober 2017 um 08:30 UTC](https://forum.shopware.com/t/creating-or-replacing-service-with-tag/47956/5 "2017-10-04T08:30:05Z")

</div>

In that case you have to decorate shopwares event.

Create custom service in services.xml, for example:  
&nbsp;

&nbsp;

- Then create class (SearchDbal) in “CustomPlugin/Events”
- Create public method in that class (propertyFacetHandlerDbal)

In that method you have to get shopwares service id, and put it into the new class and then replace that class with the old one by returnin it into the service id  
There is an example in the shopwares documentation about decorating an service, just go to the line where the title is “[Decorate the WhiteListService](https://developers.shopware.com/developers-guide/plugin-extension-by-plugin/)”
