Neu Entwicklung eines Plugins Newbee Fragen.

mnause

Aktives Mitglied
19. Juli 2016
89
17
Essen
Firma
NAAM Distribution GmbH
Hallo ich interessiere mich für die Plugin Entwicklung.

Wie kann ich auf Variablen aus den Plugin Einstellungen im Frontend zugreifen?
 

mnause

Aktives Mitglied
19. Juli 2016
89
17
Essen
Firma
NAAM Distribution GmbH
Es geht darum das ich die /Productdetails/tabs.tpl

Code:
{block name='productdetails-tabs' append}
<div class="container">
    {block name='productdetails-clp'}
    {row class="clp"}
    {col}<h3 class="clp" id="clp">{lang key='CLP' section='mnnetzwerk_clp_info'} - {$Artikel->cName}</h3>{/col}
    {/row}
    {/block}
</div>

{/block}
an einen block etwas anhänge und dort auf Variablen aus dem Adminmenü

zugreifen möchte
 
Zuletzt bearbeitet:

mnause

Aktives Mitglied
19. Juli 2016
89
17
Essen
Firma
NAAM Distribution GmbH
Code:
{$plugin->getMeta()->getName()}

bringt Fatal error: Uncaught Error: Call to a member function getMeta() on null in
 

Trigoda

Aktives Mitglied
8. September 2022
44
4
Hängt halt davon ab, wo du das aufrufst, da müsste $plugin definiert sein, damit es geht.

Code:
// i.e. within Bootstrap.php in the boot method:
$plugin = $this->getPlugin();
 

mnause

Aktives Mitglied
19. Juli 2016
89
17
Essen
Firma
NAAM Distribution GmbH
Ich hänge mich an einen Block in der productdetails/tabs.tpl

Code:
{block name='productdetails-tabs' append}
<div class="container clpbox"> {block name='productdetails-clp'}
  {row class="clp clphead"}
  {col cols=12}
  <h3 class="clp" id="clp">{lang key='CLP' section='mnnetzwerk_clpinfo'} - {$Artikel->cName}</h3>
  {/col}
  {/row}
  {row class="clp"}
  {col cols=12 lg=4 class='clp1b'}Piktogramm(e){/col}
  {col cols=12 lg=8 class='clp1'} {/col}
  {/row}
  {row class="clp bg-light"}
  {col cols=12 lg=4 class='clp1b'}Signalwort{/col}
  {col cols=12 lg=8 class='clp1'} {/col}
  {/row}
  {row class="clp"}
  {col cols=12 lg=4 class='clp1b'}Gefahrenhinweise{/col}
  {col cols=12 lg=8 class='clp1'}
        {assign var="string" value=$Artikel->FunktionsAttribute.hsentences} ////   Eigenes Feld aus Clp_Hsentences
        {assign var=hsentences value=","|explode:$string}       
        {foreach from=$hsentences item=foo}{lang key={$foo} section='CLP'}<br>
        {/foreach}
{/col}
  {/row}
  {row class="clp bg-light"}
  {col cols=12 lg=4 class='clp1b'}Sicherheitshinweise{/col}
  {col cols=12 lg=8 class='clp1'} {/col}
  {/row}
  {row class="clp"}
  {col cols=12 lg=4 class='clp1b'}Besondere Kennzeichnung bestimmter Gemische{/col}
  {col cols=12 lg=8 class='clp1'}Besondere Kennzeichnung bestimmter Gemische{/col}
  {/row}
  {/block}


</div>
{/block}

und hier möchte auf diese Variablen in genau dieser tpl zugreifen
Code:
<Setting type="text" initialValue="Piktogramm" sort="1" conf="Y">
          <Name>Eigenes Feld Piktogramme</Name>
          <Description>Eigenes Feld Piktogramme</Description>
          <ValueName>Clp_Piktogramm</ValueName>
        </Setting>
        <Setting type="text" initialValue="Signalwort" sort="1" conf="Y">
          <Name>Eigenes Feld Signalwort</Name>
          <Description>Eigenes Feld Signalwort</Description>
          <ValueName>Clp_Signalwort</ValueName>
        </Setting>
        <Setting type="text" initialValue="Hsentences" sort="1" conf="Y">
          <Name>Eigenes Feld Hsentences</Name>
          <Description>Eigenes Feld Hsentences</Description>
          <ValueName>Clp_Hsentences</ValueName>
        </Setting>
        <Setting type="text" initialValue="Psentences" sort="1" conf="Y">
          <Name>Eigenes Feld Psentences</Name>
          <Description>Eigenes Feld Psentences</Description>
          <ValueName>Clp_Psentences</ValueName>
        </Setting>
        <Setting type="text" initialValue="EUHSentences" sort="1" conf="Y">
          <Name>Eigenes Feld EUHSentences</Name>
          <Description>Eigenes Feld EUHSentences</Description>
          <ValueName>Clp_EUHSentences</ValueName>
        </Setting>
        <Setting type="text" initialValue="sensiblerstoff" sort="1" conf="Y">
          <Name>Eigenes Feld Sensible Stoffe</Name>
          <Description>Eigenes Feld sensiblerstoff</Description>
          <ValueName>Clp_sensiblerstoff</ValueName>
        </Setting>
 
Zuletzt bearbeitet:

FMoche

Moderator
Mitarbeiter
15. Dezember 2014
1.369
347
Halle (Saale)
Minimalbeispiel:
Code:
<?php declare(strict_types=1);

namespace Plugin\my_plugin_id;

use JTL\Events\Dispatcher;
use JTL\Plugin\Bootstrapper;
use JTL\Smarty\JTLSmarty;

class Bootstrap extends Bootstrapper
{
    public function boot(Dispatcher $dispatcher)
    {
    parent::boot($dispatcher);
    $dispatcher->listen('shop.hook.' . \HOOK_SMARTY_INC, function (array $args) {
            /** @var JTLSmarty $smarty */
            $smarty = $args['smarty'];
            $smarty->assign('myCustomVariable', $this->getPlugin()->getConfig()->getValue('myCustomOption'));
        });
    }
}


Dann könntest du in deinem Template auf die Smarty-Variable $myCustomVariable zugreifen, die den Wert der Option "myCustomOption" hat.
 

mnause

Aktives Mitglied
19. Juli 2016
89
17
Essen
Firma
NAAM Distribution GmbH
Minimalbeispiel:
Code:
<?php declare(strict_types=1);

namespace Plugin\my_plugin_id;

use JTL\Events\Dispatcher;
use JTL\Plugin\Bootstrapper;
use JTL\Smarty\JTLSmarty;

class Bootstrap extends Bootstrapper
{
    public function boot(Dispatcher $dispatcher)
    {
    parent::boot($dispatcher);
    $dispatcher->listen('shop.hook.' . \HOOK_SMARTY_INC, function (array $args) {
            /** @var JTLSmarty $smarty */
            $smarty = $args['smarty'];
            $smarty->assign('myCustomVariable', $this->getPlugin()->getConfig()->getValue('myCustomOption'));
        });
    }
}


Dann könntest du in deinem Template auf die Smarty-Variable $myCustomVariable zugreifen, die den Wert der Option "myCustomOption" hat.
Danke das war es !
 
Zuletzt bearbeitet:

mnause

Aktives Mitglied
19. Juli 2016
89
17
Essen
Firma
NAAM Distribution GmbH
gibt er eigentlichen eine andere Möglichkeit Sprachvariablen außer über die info.xml zu definieren?
 
Zuletzt bearbeitet:

mnause

Aktives Mitglied
19. Juli 2016
89
17
Essen
Firma
NAAM Distribution GmbH
Link Seite

test.php

Code:
<?php
use JTL\Events\Dispatcher;
use JTL\Plugin\Bootstrapper;
use JTL\Smarty\JTLSmarty;
use JTL\Session\Frontend;

......

  if ( file_exists( $datei ) ) // Prüfen ob Datei auf dem Server verfügbar ist
  {
 .....
  } else {
    $plug_error = "Die Datei steht nicht zum Download zur Verfügung!"; .
  }



//---- TEMPLATE VARS

    global $smarty;
    $smarty->assign('plug_error', $plug_error);

?>

test.tpl

Code:
{row}
{col}
{$plug_error}
{/col}
{/row}

Die Variable $plug_error bekomme ich nicht ins Frontend übergeben wo liegt mein Fehler

Warning: Undefined array key "plug_error" in /templates_c/NOVA/93600f5c385edc3982b4110415c120090058edd5_0.file.invoice.tpl.php on line 42

Warning
: Attempt to read property "value" on null in templates_c/NOVA/93600f5c385edc3982b4110415c120090058edd5_0.file.invoice.tpl.php on line 42