# Add custom field to global search - not working

**URL:** <https://forum.shopware.com/t/add-custom-field-to-global-search-not-working/104073>\
**Category:** Shopware 6 (English)\
**Created:** [21. Mai 2024 um 07:44 UTC](https://forum.shopware.com/t/add-custom-field-to-global-search-not-working/104073 "2024-05-21T07:44:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![boss](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@boss](https://forum.shopware.com/u/boss)\
**Post date:** [21. Mai 2024 um 07:44 UTC](https://forum.shopware.com/t/add-custom-field-to-global-search-not-working/104073/1 "2024-05-21T07:44:02Z")

</div>

hello, I would like to add custom search according to [Add custom data to the search | Shopware Documentation](https://developer.shopware.com/docs/guides/plugins/plugins/administration/search-custom-data.html)

However, I feel like this guide has a lot of mistakes…

I added code like below

```auto
const { Application } = Shopware;

Application.addServiceProviderDecorator('searchTypeService', searchTypeService => {
    searchTypeService.upsertType('test', {
        entityName: 'test',
        placeholderSnippet: 'foo-bar.general.placeholderSearchBar',
        listingRoute: 'test',
        hideOnGlobalSearchBar: false,
    });

    return searchTypeService;
});

```

but when I try find something I get error „Can not get module by the entity name is test“ why? what I must do more ? Entity test exist and working.

I tried creating a new module… but what I need to type in decorator ?

```auto
searchTypeService.upsertType('test', {
        entityName: 'test',

```

My new module:

```auto
Shopware.Module.register('test', {
    entity: 'test',
    defaultSearchConfiguration: {
        _searchable: true,
        name: {
            _searchable: true,
            _score: 500,
        },
        description: {
            name: {
                _searchable: true,
                _score: 500,
            },
        },
    },
});

```

and my decorator

```auto
const { Application } = Shopware;
**import '../module/test/index'** // my module import
Application.addServiceProviderDecorator('searchTypeService', searchTypeService => {
    searchTypeService.upsertType('test', {
        entityName: 'test',
        placeholderSnippet: 'test',
        listingRoute: 'test',
        hideOnGlobalSearchBar: false,
    });

    return searchTypeService;
});

```

{imported module and using}

nothing changes, it same error.

main.js

`import './decorator/searchTypeServiceDecorator'`

structure

![image](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/3X/f/2/f2e4eee8c75542b08902f54b7bb6f318ea33db17.png)

where is the problem ?

---

<div class="post-metadata">

**Author:** ![wolfsmith](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/wolfsmith/32/23860_2.png) [@wolfsmith](https://forum.shopware.com/u/wolfsmith)\
**Post date:** [27. Mai 2024 um 10:31 UTC](https://forum.shopware.com/t/add-custom-field-to-global-search-not-working/104073/2 "2024-05-27T10:31:41Z")

</div>

Hey there,

See in my opinion: Here are the steps to ensure everything is correctly set up:

1. main.js

```auto
import './decorator/searchTypeServiceDecorator';
import './module/test/index'; // Adjusted the import path based on your structure

```

1. Module Registration (in index.js)

```auto
Shopware.Module.register('test', {
    entity: 'test',
    defaultSearchConfiguration: {
        _searchable: true,
        name: {
            _searchable: true,
            _score: 500,
        },
        description: {
            _searchable: true,
            _score: 500,
        },
    },
});

```

1. Decorator (in searchTypeServiceDecorator.js)

```auto
const { Application } = Shopware;
import '../module/test/index'; // Ensure this path is correct

Application.addServiceProviderDecorator('searchTypeService', searchTypeService => {
    searchTypeService.upsertType('test', {
        entityName: 'test',
        placeholderSnippet: 'test.general.placeholderSearchBar',
        listingRoute: 'test',
        hideOnGlobalSearchBar: false,
    });

    return searchTypeService;
});

```

Make sure to clear the cache after making these changes to ensure they take effect. hope the above will be helpful.

Best,  
@wolfsmith
