About me

Benjamin Cremer

Benjamin Cremer
shopware AG
Feedback @benjamincremer

Questions?

Feel free to ask at any time

But first...

An all new plugin system?

  • Experimental integration in Shopware 5.2 BETA1
  • Fully separated
  • Parallel mode with "legacy" plugin system
  • Easy migration

WHY?

6000 Line Bootstrap.php

Be strong...

There will be XML

Autoloading of DI extension


SwagPromotion
├── Resources
│   ├── snippets
│   ├── views
│   └── services.xml
├── Services
├── Controllers
├── Models
├── plugin.xml
├── phpunit.xml.dist
└── SwagPromotion.php
    

Provide new service

$this->container->get('SwagMyService.SomeService');

Provide new service


class Shopware_Plugins_Frontend_SwagMyService_Bootstrap extends Shopware_Components_Plugin_Bootstrap
{
    public function install()
    {
        $this->subscribeEvent(
            'Enlight_Bootstrap_InitResource_SwagMyService.SomeService',
            'onInitSomeService'
        );

        return true;
    }

    public function onInitSomeService(Enlight_Event_EventArgs $args)
    {
        return new SomeService(
            $this->container->get('database_connection')
        );
    }
}
    

Provide new service (new)


<service id="SwagMyService.SomeService" class="SwagMyService\SomeService">
     <argument type="service" id="database_service"/>
</service>
    

Overwrite Existing service

$this->container->get('validator.email');

Overwrite Existing service


class Shopware_Plugins_Frontend_SwagMyMailValidator_Bootstrap extends Shopware_Components_Plugin_Bootstrap
{
    public function install()
    {
        $this->subscribeEvent(
            'Enlight_Bootstrap_InitResource_validator.email',
            'onValidatorInit'
        );

        return true;
    }

    public function onValidatorInit(Enlight_Event_EventArgs $args)
    {
        return new MyEmailValidator();
    }
}
    

Overwrite Existing service (new)


<service id="SwagMail.MyMailValidator"
         decorates="validator.email"
         class="SwagMail\MyEmailValidator">
         <argument type="service" id="SwagRedis.RedisProductService.inner"/>
</service>
    

Decorate Existing service

$this->container->get('shopware_storefront.list_product_service');

Decorate Existing service


class Shopware_Plugins_Frontend_SwagRedis_Bootstrap extends Shopware_Components_Plugin_Bootstrap
{
    public function install()
    {
        $this->subscribeEvent(
            'Enlight_Bootstrap_AfterInitResource_shopware_storefront.list_product_service',
            'decorateService'
        );

        return true;
    }

    public function decorateService()
    {
        $coreService = $this->container->get('shopware_storefront.list_product_service');

        $redisService = new RedisProductService($coreService);

        $this->container->set('shopware_storefront.list_product_service', $redisService);
    }
}
    

Decorate Existing service (new)


<service id="SwagRedis.RedisProductService"
         decorates="shopware_storefront.list_product_service"
         class="SwagRedis\RedisProductService">
    <argument type="service" id="SwagRedis.RedisProductService.inner"/>
</service>
    

OOP Extensions

CLI Commands

ConditionHandler

PasswordEncoder

OOP Extensions


class Shopware_Plugins_Frontend_SwagExample_Bootstrap extends Shopware_Components_Plugin_Bootstrap
{
    public function install()
    {
        $this->subscribeEvent(
            'Shopware_SearchBundleDBAL_Collect_Condition_Handlers',
            'collectConditionHandlers'
        );

        return true;
    }

    public function collectConditionHandlers()
    {
        return new ArrayCollection(array(
            new FooConditionHandler();
            new BarConditionHandler();
        ));
    }
}
    

OOP Extensions (new)


<service id="SwagExample.FooConditionHandler" class="SwagExample\FooConditionHandler">
    <tag name="condition_handler_dbal" />
</service>

<service id="SwagExample.BarConditionHandler" class="SwagExample\BarConditionHandler">
    <tag name="condition_handler_dbal" />
</service>
    

Event Registration


<service id="theme_backend_registration" class="Shopware\Components\Theme\EventListener\BackendTheme">
    <argument type="service" id="database_connection" />
    <tag name="shopware.event_listener" method="registerBackendTheme" event="Enlight_Controller_Front_RouteShutdown" />
</service>
    

Discuss!

Thank you!

Please leave feedback

joind.in/talk/f71d8
talks.benjamin-cremer.de/scd2016_plugin
@benjamincremer