# Register a custom rule via plugin

**URL:** <https://forum.shopware.com/t/register-a-custom-rule-via-plugin/66788>\
**Category:** Programmierung\
**Created:** [7. Mai 2020 um 13:33 UTC](https://forum.shopware.com/t/register-a-custom-rule-via-plugin/66788 "2020-05-07T13:33:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexey](https://avatars.discourse-cdn.com/v4/letter/a/47e85d/32.png) [@Alexey](https://forum.shopware.com/u/Alexey)\
**Post date:** [7. Mai 2020 um 13:33 UTC](https://forum.shopware.com/t/register-a-custom-rule-via-plugin/66788/1 "2020-05-07T13:33:57Z")

</div>

Ich möchte eine neue Regel für das Feld “Customer Tag” per Plugin für Admin definieren.

Ich habe mir alles nach den How-To [https://docs.shopware.com/en/shopware-platform-dev-en/how-to/custom-rule&nbsp;](https://docs.shopware.com/en/shopware-platform-dev-en/how-to/custom-rule) gemacht =\> das Plugin wurde installiert, aber es gibt im Admin unter “Rule Builder =\> Bedingungen durchsuchen” keine meine Bedingung.

Dann habe ich das Beispielplugin [https://github.com/shopware/swag-docs-custom-rule](https://github.com/shopware/swag-docs-custom-rule) installiert =\> und es funktioniert alles wunderbar. ABER das Plugin beinhaltet den File [https://github.com/shopware/swag-docs-custom-rule/blob/master/src/Resources/public/administration/js/custom-rule.js](https://github.com/shopware/swag-docs-custom-rule/blob/master/src/Resources/public/administration/js/custom-rule.js), was aus meiner Sicht generisch ist. Es gibt keine Anleitung, wie man ihn erzeugt. Dieser File beinhaltet alles: Logic, Template, Scripts. Wenn ich den File umbenenne, dann funktioniert das Beispiel von Swag auch nicht mehr.

Bitte um jede Hilfe.

---

<div class="post-metadata">

**Author:** ![oerkel](https://avatars.discourse-cdn.com/v4/letter/o/a9adbd/32.png) [@oerkel](https://forum.shopware.com/u/oerkel)\
**Post date:** [8. Mai 2020 um 06:37 UTC](https://forum.shopware.com/t/register-a-custom-rule-via-plugin/66788/2 "2020-05-08T06:37:53Z")

</div>

du musst in der Console ./psh.phar adminstration:build ausführen, danach wird die js im public Verzeichnis neu erzeugt.

Du kannst im Rule Builder die Lunar Eclipse Rule ausführen und auch Ja / Nein als Bedingung auswählen? Spannend.&nbsp; Ich habe die custom rule installiert und bekomme mit der 6.1 sowie 6.2 einen JS Fehler.

&nbsp;

---

<div class="post-metadata">

**Author:** ![Alexey](https://avatars.discourse-cdn.com/v4/letter/a/47e85d/32.png) [@Alexey](https://forum.shopware.com/u/Alexey)\
**Post date:** [8. Mai 2020 um 10:44 UTC](https://forum.shopware.com/t/register-a-custom-rule-via-plugin/66788/3 "2020-05-08T10:44:24Z")

</div>

> [@oerkel schrieb:](https://forum.shopware.com/profile/21296/oerkel "oerkel")

> … Ich habe die custom rule installiert und bekomme mit der 6.1 sowie 6.2 einen JS Fehler.

Ich bekomme auch den JS-Fehler. Da ich aber die Rule für Customer Tag haben möchte, habe ich die bestehende Rule für LineItemTag angeschaut und QuellCode zum testen übernommen - und es funktioniert alles einwandrei in Admin

---

<div class="post-metadata">

**Author:** ![Leoo](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/leoo/32/14252_2.png) [@Leoo](https://forum.shopware.com/u/Leoo)\
**Post date:** [16. September 2020 um 12:40 UTC](https://forum.shopware.com/t/register-a-custom-rule-via-plugin/66788/4 "2020-09-16T12:40:56Z")

</div>

Falls jemand anderes auch gerade das Problem hat, aktuell ist da ein Fehler in dem [How-To](https://docs.shopware.com/en/shopware-platform-dev-en/how-to/custom-rule):

Der Inhalt der main.js muss sein:

```
import './decorator/rule-condition-service-decoration';

```

nicht

```
import './src/decorator/rule-condition-service-decoration';

```

PS: Sorry fürs das Wiederaufleben von diesem toten Thread :/&nbsp;

---

<div class="post-metadata">

**Author:** ![D4ni3l](https://avatars.discourse-cdn.com/v4/letter/d/839c29/32.png) [@D4ni3l](https://forum.shopware.com/u/D4ni3l)\
**Post date:** [23. Dezember 2021 um 14:14 UTC](https://forum.shopware.com/t/register-a-custom-rule-via-plugin/66788/5 "2021-12-23T14:14:51Z")

</div>

```auto
WARNING in /var/www/html/custom/plugins/SwagRule/src/Resources/app/administration/src/decorator/rule-condition-service-decoration.js 1:88-99
    "export 'Application' was not found in 'src/core/shopware'
    
    WARNING in /var/www/html/custom/plugins/SwagRule/src/Resources/app/administration/src/core/component/swag-lunar-eclipse/index.js 1:1072-1081
    "export 'Component' was not found in 'src/core/shopware'
    
    ERROR in 
    /var/www/html/custom/plugins/SwagRule/src/Resources/app/administration/src/core/component/swag-lunar-eclipse/index.js
      1:27 error You can't use imports directly from the Shopware Core via "src/core/shopware". Use the global Shopware object directly instead (https://developer.shopware.com/docs/guides/plugins/plugins/administration/the-shopware-object) plugin-rules/no-src-imports
    
    /var/www/html/custom/plugins/SwagRule/src/Resources/app/administration/src/decorator/rule-condition-service-decoration.js
      1:29 error You can't use imports directly from the Shopware Core via "src/core/shopware". Use the global Shopware object directly instead (https://developer.shopware.com/docs/guides/plugins/plugins/administration/the-shopware-object) plugin-rules/no-src-imports
    
    ✖ 2 problems (2 errors, 0 warnings)

```

Momentan scheint das Plugin aber so auch wieder nicht mehr zu funktionieren …

---

<div class="post-metadata">

**Author:** ![Max\_Shop](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@Max\_Shop](https://forum.shopware.com/u/Max_Shop)\
**Post date:** [23. Dezember 2021 um 14:17 UTC](https://forum.shopware.com/t/register-a-custom-rule-via-plugin/66788/6 "2021-12-23T14:17:17Z")

</div>

Die Fehlermeldung als auch die Lösung steht in dem von dir kopierten Code.

> **[The Shopware object](https://developer.shopware.com/docs/guides/plugins/plugins/administration/the-shopware-object)**

---

<div class="post-metadata">

**Author:** ![D4ni3l](https://avatars.discourse-cdn.com/v4/letter/d/839c29/32.png) [@D4ni3l](https://forum.shopware.com/u/D4ni3l)\
**Post date:** [23. Dezember 2021 um 14:25 UTC](https://forum.shopware.com/t/register-a-custom-rule-via-plugin/66788/7 "2021-12-23T14:25:41Z")

</div>

> [@D4ni3l](#):
>
> `/var/www/html/custom/plugins/SwagRule/src/Resources/app/administration/src/core/component/swag-lunar-eclipse/index.js`

Ja, wäre nur gut wenn das in der Dokumentation geändert werden würde. Wir wollen doch alle nachhaltig arbeiten und nicht jeden erneut debuggen lassen?

> const { Component } = Shopware;  
> const Application = Shopware.Application;

statt

> import { Component } from ‚src/core/shopware‘;  
> import Application from ‚src/core/shopware‘;

😉

PS: in github dauert es ja ab und an etwas länger bis Änderungen zugelassen werden, deshalb doku hier im Thread der bei google als Treffer fürs Problem gelistet ist.
