Plugin priority

Hi all

 I try to develop new plugin to change footer. And when I install it on dev server it works. But on production not. How I can set priority to plugin? I mean firstly use footer from my plugin and only then from another plugins/themes

It is like

  1. Core

  2. Plug-Ins

  3. Themes

This is how shopware inherits in SW5.

Now you have 2 options to overwrite the default inheritance:

  1. Tell the theme via

    protected $injectBeforePlugins = true

that it should load before the plug-ins

  1. register your functions to the subscribeEvents of your plug-ins with an higher position as the other plug-ins or themes via a third parameter

 

 

 

So, I wrote

   public function install()
    {
        $this->subscribeEvent(
            ‚Enlight_Controller_Action_PostDispatchSecure_Frontend‘,
            ‚onFrontendPostDispatch‘,

           0
        );

        return true;
    }

 

and see nothing. Can you help me?

Well, Zero is a pretty low value for a higher position :wink:

Try PHP_INT_MAX

and if this works try a more feasible value.

Ohh, its not work too.

Maybe exists some way to known what tpl files shopware use to render page? Like debug or something else

anybody can’t help? (

Ok, another idea came to my mind:

Since this is a frontend-extension i am assuming you are appending or prepending some smarty blocks.

There is a known bug that two Plug-Ins appending/prepending the same smarty block won’t both append/prepend. So instead of
 

{block name='x' append}

//my code

{/block}

use
 

{block name='x'}

{$smarty.block.parent}

//my code

{/block}

(for prepend operation just swap //my code with {$smarty.block.parent}

 

Hi

it does not help(

my code is 

{extends file="parent:frontend/index/footer.tpl"}

{block name="frontend_index_shopware_footer_copyright"}
{$smarty.block.parent}

test
{/block}

But I wonder about right way to tpl file.

In plugin I use Views/frontend/index/footer.tpl

Maybe exists some way to known what tpl files shopware use to render page? Like debug or something else

please post your onFrontendPostDispatch

@steinsoftware schrieb:

please post your onFrontendPostDispatch

Sorry, can you explain? I new shopware plugin developer and don’t understand what do you mind 

So, I wrote

   public function install()
    {
        $this->subscribeEvent(
            ‚Enlight_Controller_Action_PostDispatchSecure_Frontend‘,
            ‚onFrontendPostDispatch‘,

           0
        );

        return true;
    }

 

and see nothing. Can you help me?

 

So you registered your own function onFrontendPostDispatch.

If you don’t have such function you should start over here:

https://developers.shopware.com/developers-guide/

 

I have such function

    public function onFrontendPostDispatch(Enlight_Event_EventArgs $args)
    {
        /** @var \Enlight_Controller_Action $controller */
        $controller = $args->get('subject');
        $view = $controller->View();

        $view->addTemplateDir(
            __DIR__. '/Views'
        );
    }

 

Any others idea?(

@Maksim‍ You may have a look at this very simple Plugin which changes the newsletter section in the footer: https://github.com/hostianer/HostiReplaceNewsletter

It does not help because shopware when renredering page use tpl files in unknown order. I need to know what tpl files uses for render page

Hi,

the general hierarchy can be accessed with this command: 

  

Shopware()->Template()->getTemplateDir()

It will print out something like this:

Array
(
    [0] => /var/www/html/52/engine/Shopware/Plugins/Local/Frontend/SwagPromotion/Views/
    [1] => /var/www/html/52/themes/Frontend/Responsive/
    [2] => /var/www/html/52/themes/Frontend/Bare/
)

So in my case, it will look up a given template file in the order SwagPromotion-Plugin, Responsive-Theme, Bare-Theme. If you have a custom theme in place, the hierarchy will look like this:

Array
(
    [0] => /var/www/html/52/themes/Frontend/CustomTheme/
    [1] => /var/www/html/52/engine/Shopware/Plugins/Local/Frontend/SwagPromotion/Views/
    [2] => /var/www/html/52/themes/Frontend/Responsive/
    [3] => /var/www/html/52/themes/Frontend/Bare/
)

So in this case, the custom theme will extend / overwrite my plugin’s template. 

Daniel

@Maksim‍ Which shopware version have you installed?

You may have a look at Getting started with Smarty

This theme configuration property has come with version 5.1.2: SW-12782 - Add theme config property to configure inheritance position · shopware/shopware@163860e · GitHub

You can change the var in your Theme.php to true or falseshopware/Theme.php at 5.1 · shopware/shopware · GitHub