# Eigenes JQuery Plugin / init Funktion fehlt...

**URL:** <https://forum.shopware.com/t/eigenes-jquery-plugin-init-funktion-fehlt/36500>\
**Category:** Programmierung\
**Created:** [2. Mai 2016 um 14:20 UTC](https://forum.shopware.com/t/eigenes-jquery-plugin-init-funktion-fehlt/36500 "2016-05-02T14:20:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![coarsy](https://avatars.discourse-cdn.com/v4/letter/c/59ef9b/32.png) [@coarsy](https://forum.shopware.com/u/coarsy)\
**Post date:** [2. Mai 2016 um 14:20 UTC](https://forum.shopware.com/t/eigenes-jquery-plugin-init-funktion-fehlt/36500/1 "2016-05-02T14:20:29Z")

</div>

Hi zusammen,

jetzt habe ich mein Variantenplugin umgeschrieben und erhalte beim Initialisieren diesen Fehler:

```
Plugin CbeVariantsDetail has to have an init function!
	
...nBase.prototype={init:function(){throw new Error('Plugin '+this.getName()+' has ...

```

Aufgerufen wird das Plugin wie folgt:

```
$.plugin('CbeVariantsDetail', {
defaults: {
'requestUrl' : "https://www.meinestruempfe.de/shopware5/CbeVariantsDetail/getVariants",
'articleID' : "61",
'articleTax' : "19",
'availableStockText' : "Artikel verfügbar",
'lowStockText' : "Nur noch sehr wenige Artikel verfügbar",
'lowStockTextPrefix' : "Nur noch",
'lowStockTextSuffix' : "Artikel verfügbar",
'outOfStockText' : "Artikel leider vergriffen",
'intoBasketText' : "In den Warenkorb",
'regularPriceText' : "(Unser regulärer Preis)",
'lastArticleText' : "Das ist der letzte Artikel! Schnell zugreifen!",
'variantsDeliveryText' : "Wieder lieferbar:",
'useZoomPlus' : false,
'lowStockValue' : 2,
'imgSrcSmall' : 0,
'imgSrc' : 1,
'imgSrcZoom' : 2,
'notificationText' : "Benachrichtigen Sie mich, wenn der Artikel lieferbar ist."
}
});
$('#variantselector').CbeVariantsDetail();

```

Jemand ne Idee, wieso das der Fall ist? Die init Funktion ist genauso ausgeführt:

[https://developers.shopware.com/designers-guide/javascript-statemanager-and-pluginbase/](https://developers.shopware.com/designers-guide/javascript-statemanager-and-pluginbase/)

---

<div class="post-metadata">

**Author:** ![coarsy](https://avatars.discourse-cdn.com/v4/letter/c/59ef9b/32.png) [@coarsy](https://forum.shopware.com/u/coarsy)\
**Post date:** [2. Mai 2016 um 14:40 UTC](https://forum.shopware.com/t/eigenes-jquery-plugin-init-funktion-fehlt/36500/2 "2016-05-02T14:40:42Z")

</div>

Das Plugin hat definitiv eine init Funktion…

```
/**
 * CbeVariantsDetail jQuery plugin using the base class
 *
 */
$.plugin('CbeVariantsDetail', {
    
    defaults: {
        sColorPath : '/out/pictures/colors/', // path to color images
			  iColorWidth : 40,
			  iColorHeight : 40,
			  sPictureFormat : 'jpg', // jpg, gif, png
			  noStockValue : 0,
			  lowStockValue : 2,
			  disableBasketButton : true,
			  showStock : false,
			  showDeliveryDate : true,
        useAjaxNotification : true
    },
    
    init: function() {
        var me = this;
        opts = me.opts;
        me.applyDataAttributes();
        
        this.getVariants(opts.articleID, null); 
    },
    
    getVariants: function(articleID, selectedValue) {

```

&nbsp;

---

<div class="post-metadata">

**Author:** ![coarsy](https://avatars.discourse-cdn.com/v4/letter/c/59ef9b/32.png) [@coarsy](https://forum.shopware.com/u/coarsy)\
**Post date:** [2. Mai 2016 um 15:33 UTC](https://forum.shopware.com/t/eigenes-jquery-plugin-init-funktion-fehlt/36500/3 "2016-05-02T15:33:08Z")

</div>

Ich Depp habs natürlich falsch gemacht, so ists richtig:

```
  	  StateManager.addPlugin('#variantselector', 'CbeVariantsDetail', {
        'requestUrl' : "{url controller="CbeVariantsDetail" action="getVariants"}",
        'articleID' : "{$sArticle.articleID}",
        'articleTax' : "{$sArticle.tax}",
        {if $showStock == "2"}'showStock' : true,{/if}
    		'availableStockText' : "{$availableStockText}",
        'lowStockText' : "{$lowStockText}",
    		'lowStockTextPrefix' : "{$lowStockTextPrefix}",
    		'lowStockTextSuffix' : "{$lowStockTextSuffix}",
    		'outOfStockText' : "{$outOfStockText}",
    		'intoBasketText' : "{$intoBasketText}",
    		'regularPriceText' : "(Unser regulärer Preis)",
        'lastArticleText' : "Das ist der letzte Artikel! Schnell zugreifen!",
    		'variantsDeliveryText' : "Wieder lieferbar:",
        'useZoomPlus' : false,
    		'lowStockValue' : {$lowStockValue},    
        'imgSrcSmall' : {$imgSrcSmall},  
        'imgSrc' : {$imgSrc},
        'imgSrcZoom' : {$imgSrcZoom},
        'notificationText' : "Benachrichtigen Sie mich, wenn der Artikel lieferbar ist."
      });

```

&nbsp;
