Recent Topics

EVENTServiceProvider issues



  • Hello ,
    i'm trying to create plugin to change color frontend from admin area i'm reading this tutorial to do it
    https://bagisto.com/en/how-to-make-frontend-changes-in-all-the-tenants-as-a-super-admin/
    He is my files
    WebfontsServiceProvider

    
    namespace WEBFONT\Webfonts\Providers;
    
    use Illuminate\Support\ServiceProvider;
    use Illuminate\Support\Facades\Event;
    use WEBFONT\Webfonts\Providers\EventServiceProvider;
    
    class WebfontsServiceProvider extends ServiceProvider
    {
        /**
         * Bootstrap services.
         *
         * @return void
         */
        public function boot()
        {
            $this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations');
    
            $this->loadRoutesFrom(__DIR__ . '/../Http/admin-routes.php');
    
            $this->loadRoutesFrom(__DIR__ . '/../Http/shop-routes.php');
    
            $this->loadTranslationsFrom(__DIR__ . '/../Resources/lang', 'webfonts');
    
            /*$this->publishes([
                __DIR__ . '/../../publishable/assets' => public_path('themes/default/assets'),
            ], 'public');*/
    
            $this->publishes([
                __DIR__ . '/../../publishable/assets' => public_path('vendor/webkul/webfonts/assets'),
                __DIR__ . '/../../publishable/webfonts' => public_path(),
            ], 'public');
    
            $this->loadViewsFrom(__DIR__ . '/../Resources/views', 'webfonts');
    
            Event::listen('bagisto.admin.layout.head', function($viewRenderEventManager) {
                $viewRenderEventManager->addTemplate('webfonts::admin.layouts.style');
            });
    
    
            $this->app->register(EventServiceProvider::class);
    
           // if(core()->getConfigData())
        }
    
        /**
         * Register services.
         *
         * @return void
         */
        public function register()
        {
            $this->registerConfig();
        }
    
        /**
         * Register package config.
         *
         * @return void
         */
        protected function registerConfig()
        {
            $this->mergeConfigFrom(
                dirname(__DIR__) . '/Config/admin-menu.php', 'menu.admin'
            );
    
            $this->mergeConfigFrom(
                dirname(__DIR__) . '/Config/acl.php', 'acl'
            );
            $this->mergeConfigFrom(
                dirname(__DIR__) . '/Config/system.php', 'core'
            );
        }
    

    EventServiceProvider

    <?php
    
    
    namespace WEBFONT\Webfonts\Providers;
    
    use Illuminate\Support\ServiceProvider;
    use Illuminate\Support\Facades\Event;
    
    class EventServiceProvider extends ServiceProvider
    {
        /**
         * Bootstrap services.
         *
         * @return void
         */
        public function boot()
        {
            $this->loadViewsFrom(__DIR__ . '/../Resources/views', 'webfonts');
           Event::listen('bagisto.shop.layout.head',function($viewRenderEventManager){
                //$viewRenderEventManager->addTemplate('webfonts::styles');
                $viewRenderEventManager->addTemplate('webfonts::styles');
            });
        }
    }
    

    styles.blade.php

    <?php
    header("content-type: text/css");
    $newBrandColor = core()->getConfigData('general.design.webfonts.brand_color') ?? "#191656";
    $newLinkColor = core()->getConfigData('general.design.webfonts.link_color') ?? "#48E7F3";
    $headerThemeColor = core()->getConfigData('general.design.webfonts.header_theme_color') ?? "#205686";
    ?>
    <style>
    .main-container-wrapper #top {
        background.color: <?=$headerThemeColor?>;
    }
    
    #top .local-switcher option {
        background.color: <?=$headerThemeColor?>;
    }
    
    .header #search-form input::placeholder {
        color: #ffffff !important;
    }
    
    .btn-add-to-cart {
        background-color! <?=$newBrandColor?> !important;
    }
    .btn-add-to-cart:hover, .theme-btn:hover, div label.btn:hover {
    background-color: <?$newBrandColor?> !important;
    
    } 
    </style>
    
    

    System.php

    <?php
    
    return [
        /*[
            'key' => 'webfonts',
            'name' => 'Design',
            'sort' => 1
        ],*/ [
            'key' => 'general.design',
            'name' => 'Design',
            'sort' => 1,
        ], [
            'key' => 'general.design.webfonts',
            'name' => 'Design',
            'sort' => 2,
            'fields' => [
                [
                    'name' => 'status',
                    'title' => 'Status',
                    'type' => 'boolean',
                    'channel_based' => true,
                    'locale_based' => false
                ],
                [
                    'name' => 'brand_color',
                    'title' => 'color',
                    'type' => 'color',
                    'channel_based' => true,
                    'locale_based' => false
                ],
                [
                    'name' => 'link_color',
                    'title' => 'link_color',
                    'type' => 'color',
                    'channel_based' => true,
                    'locale_based' => false
                ],
            ],
        ]
    ];
    
    

    For the admin i have what i expect but the default value of color did not apply
    alt text

    for front end the style is not applyed when i inspect Html here is error

    <body style="display: block;" cz-shortcut-listen="true">webfonts::styles
    

    How can i fix that?
    please can anyone help me ?
    Thank you



  • Hi @raouf415,

    Maybe it's working. You just forget to publish your package I guess.



  • @devansh-webkul
    i have renamed styles to theme now it works
    Thank you for your help


Log in to reply