Shopware 5.5插件配置变量前端输出

问题描述 投票:0回答:1

所以,我更新到SW 5.5,此后我的配置变量没有出现在前端中,但是我很确定自己在代码中犯了一个错误,但是我看不到哪里。

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

        $view->addTemplateDir($this->pluginPath . '/Resources/views');

        $shop = Shopware()->Shop();
        $this->config = Shopware()->Container()->get('shopware.plugin.cached_config_reader')->getByPluginName($this->pluginName, $shop);

        $config = array(
            'height' => $this->config['height']
        );

        $view->assign($this->pluginName, $config);
    }

这是我的功能,所以我可以使用{$height}在前端显示此选项,但此功能不再起作用。如果我忘记了某些内容或您需要更多信息,请告诉我。

symfony smarty shopware
1个回答
0
投票

您可以获取自定义插件存储配置值,如下面的代码

<?php

namespace Brandbassador\Subscriber;
use Enlight\Event\SubscriberInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

class BrandbassadorEvents implements SubscriberInterface
{
    /**
     * @var ContainerInterface
     */
    private $container;
    /**
     * @param ContainerInterface $container
     */
    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;
    }

    public static function getSubscribedEvents()
    {
        return [
            'Enlight_Controller_Action_PostDispatch_Backend_Config' => 'extRegister',
            'Enlight_Controller_Action_PostDispatchSecure_Backend_Config' => 'extRegister'
        ];
    }

    public function extRegister(\Enlight_Event_EventArgs $event_EventArgs)
    {
        $shop = false;
        if ($this->container->initialized('shop')) {
            $shop = $this->container->get('shop');
        }
        if (!$shop) {
            $shop = $this->container->get('models')->getRepository(\Shopware\Models\Shop\Shop::class)->getActiveDefault();
        }
        $config = $this->container->get('shopware.plugin.cached_config_reader')->getByPluginName('Brandbassador', $shop);
        if ($config['authKey'] || $config['authKey'] != "") {
            $authKey = $config['authKey'];
            // error_log(print_r(array($authKey), true)."\n", 3, Shopware()->DocPath() . 'var/log/test.log');
        }
    }

}
© www.soinside.com 2019 - 2024. All rights reserved.