A. What is plugins in EC-CUBE?

1. Plugin vs module vs add-in, add-on, extension

2. Plugin EC-CUBE vs bundle of Symfony

B. Why do we need plugins?

C. When do not we need plugins?

D. How about plugin ?

Position

EC-CUBE3n Root Directory
├──    app
│       ├── cache
│       ├── config
│       ├── console
│       ├── log
│       ├── Plugin ★Plugins Folder
│       │      ├── [plugin code]  ☆root folder of the plugin

I. Workflow

1. when you install a plugin:

2. when you enable a plugin:

3. when you disable a plugin:

4. when you uninstall a plugin:

5. when you update a plugin:

6. when running:

  1. Load all Symfony and Bundles
  2. Load EC-CUBE core
  3. Listen feedback of plugin with each event
    • If plugin have register interactive with the event
    • Call function handle event of the event
  4. Finish EC-CUBE core
  5. Finish Symfony and Bundle

II. Elements specification

Require elements

EC-CUBE3n Root Directory
├──    app
│       ├── Plugin                               ☆Folder contain all plugins inside
│       │      ├── [plugin code]                 ★Root folder of specification plugin
│       │      │     ├── config.yml              ★Declare & information of plugin
│       │      │     ├── PluginManager.php       ★Declare & information of plugin
# Required elements
name: [plugin name]
code: [plugin code]
version: 1.0.0

# Optional elements with PSR-4

class PluginManager extends AbstractPluginManager
{
    /**
     * @param array       $config
     * @param Application $app
     * will be called when install plugin
     */
    public function install($config, $app)
    {
    }
    /**
     * @param array       $config
     * @param Application $app
     * will be called when uninstall plugin
     */
    public function uninstall($config, $app)
    {
    }
    /**
     * @param array       $config
     * @param Application $app
     * will be called when enable plugin
     */
    public function enable($config, $app)
    {
    }
    /**
     * @param array       $config
     * @param Application $app
     * will be called when disable plugin
     */
    public function disable($config, $app)
    {
    }
    /**
     * @param array       $config
     * @param Application $app
     * will be called when update plugin
     */
    public function update($config, $app)
    {
    }
}

Optional elements

EC-CUBE3n Root Directory
├──    app
│       ├── Plugin                                   ☆Folder contain all plugins inside
│       │      ├── [plugin code]                     ☆Root folder of specification plugin
│       │      │     ├── Entity                      ★Folder contain all entity inside
│       │      │     │    ├── [Name].php             ★Declare affect to table
│       │      │     │    ├── [Name].php         
│       │      │     ├── Repository                  ★Folder contain all repository inside
│       │      │     │    ├── [Name]Repository.php   ★Declare repository
│       │      │     │    ├── [Name]Repository.php    

EC-CUBE3n Root Directory
├──    app
│       ├── Plugin                                   ☆Folder contain all plugins inside
│       │      ├── [plugin code]                     ☆Root folder of specification plugin
│       │      │     ├── Event                       ★Folder contain all class about event
│       │      │     │    ├── [Name].php             ★Declare handle class
│       │      │     ├── [Name]Event.php             ★Will register listeners for events
class [Name]Event implements EventSubscriberInterface
{
    public static function getSubscribedEvents()
    {
        return [
            'admin.product.edit.initialize' => [['onAdminProductEditInitialize', 10]],
            'admin.product.edit.complete' => [['onAdminProductEditComplete', 10]],
            'Product/detail.twig' => [['onRenderProductDetail', 10]],
        ];
    }
    ...
    public function onRenderProductDetail(TemplateEvent $event)
    {
        // implement with $event
    }
    ...
}
EC-CUBE3n Root Directory
├──    app
│       ├── Plugin                                   ☆Folder contain all plugins inside
│       │      ├── [plugin code]                     ☆Root folder of specification plugin
│       │      │     ├── Form                        ★Folder contain all class about event
│       │      │     │    ├── [Type,Extension]       ★Folder contain form 
│       │      │     │    │    ├── [Name].php        ★Declare form
EC-CUBE3n Root Directory
├──    app
│       ├── Plugin                                  ☆Folder contain all plugins inside
│       │      ├── [plugin code]                    ☆Root folder of specification plugin
│       │      │     ├── Resource                   ★Folder contain all class about event
│       │      │     │    ├── locale                ★Folder contain form 
│       │      │     │    │    ├── [Name].ja.php    ★Japanese    
│       │      │     │    │    ├── [Name].en.php    ★English  
│       │      │     │    ├── template              ★Folder contain form 
│       │      │     │    │    ├── admin            ★Folder contain template for admin 
│       │      │     │    │    │    ├── [Name].php      
│       │      │     │    │    ├── default          ★Folder contain template for front 
│       │      │     │    │    │    ├── [Name].php      
│       │      │     │    ├── asset                 ★Folder contain resource 
│       │      │     │    │    ├── [html,js,css,image..]
│       │      │     │    ├─- config
│       │      │     │    │    ├── services.yml     ★Contain any params, .....
EC-CUBE3n Root Directory
├──    app
│       ├── Plugin                                     ☆Folder contain all plugins inside
│       │      ├── [plugin code]                       ☆Root folder of specification plugin
│       │      │     ├── Tests                         ★Folder contain all class about event
│       │      │     │    ├── [Web/...]                ★Folder contain testsuite
│       │      │     │    │    ├── [Name]Test.php      ★contain testcase    
│       │      │     │    ├── bootstrap.php            ★Setup information for phpUnit    
EC-CUBE3n Root Directory
├──    app
│       ├── Plugin                                     ☆Folder contain all plugins inside
│       │      ├── [plugin code]                       ☆Root folder of specification plugin 
│       │      │     ├── Nav.php                       ★Specify position in menu 
class Nav implements EccubeNav
{
    public static function getNav()
    {
        return [
            'product' => [
                'id' => [unique name for menu],
                'name' => [Menu name],
                'url' => [route path]
            ]
        ];
    }
}