Upgrade to Pro — share decks privately, control downloads, hide ads and more …

EC-CUBE3プラグイン勉強会

 EC-CUBE3プラグイン勉強会

amidaike

April 27, 2016
Tweet

More Decks by amidaike

Other Decks in Programming

Transcript

  1. ϓϥάΠϯͷ࡞੒खॱ • ϓϥάΠϯͷ࡞੒खॱͱͯ͠ɺओʹҎԼͱͳΓ·͢ɻ 1. ϓϥάΠϯ༻σΟϨΫτϦͷ࡞੒ 2. config.ymlͷ࡞੒ 3. event.ymlͷ࡞੒ 4.

    PluginManagerΫϥεͷ࡞੒ 5. EventΫϥεͷ࡞੒ 6. ServiceProviderΫϥεͷ࡞੒ 7. consoleίϚϯυΛར༻ͨ͠ϓϥάΠϯ։ൃ
  2. ϓϥάΠϯͷ࡞੒खॱ • config.ymlͷ࡞੒
 ϓϥάΠϯσΟϨΫτϦ௚Լʹconfig.ymlΛ࡞੒͠· ͢ɻconstͱݺ͹ΕΔͱఆ਺΋هड़Մೳ͕ͩɺϓϥάΠ ϯ͕ແޮͷ৔߹ɺ͜ͷఆ਺͸ಡΈࠐΊ·ͤΜɻ name: GiftWrappingϓϥάΠϯ ※ඞਢ code:

    GiftWrapping ※ඞਢ version: 1.0.0 ※ඞਢ service: - GiftWrappingServiceProvider orm.path: - /Resource/doctrine ※ϓϥάΠϯͰ௥Ճͨ͠ςʔϒϧΛ࡞੒͢Δ৔߹ɺorm.pathͷهड़͸ඞਢ event: GiftWrappingEvent ※eventΛ௥Ճ͢Δ৔߹ɺeventͷهड़͸ඞਢ
  3. ϓϥάΠϯͷ࡞੒खॱ <?php namespace Plugin\GiftWrapping; use Eccube\Plugin\AbstractPluginManager; use Symfony\Component\Filesystem\Filesystem; class PluginManager

    extends AbstractPluginManager { /** * @var string ίϐʔݩϦιʔεσΟϨΫτϦ */ private $origin; /** * @var string ίϐʔઌϦιʔεσΟϨΫτϦ */ private $target; public function __construct() { // ίϐʔݩͷσΟϨΫτϦ $this->origin = __DIR__.'/Resource/assets'; // ίϐʔઌͷσΟϨΫτϦ $this->target = '/giftwrapping'; } /** * ϓϥάΠϯΠϯετʔϧ࣌ͷॲཧ * * @param $config * @param $app * @throws \Exception */ public function install($config, $app) { // ϦιʔεϑΝΠϧͷίϐʔ $this->copyAssets($app); }
  4. ϓϥάΠϯͷ࡞੒खॱ <?php namespace Plugin\GiftWrapping; use Eccube\Event\EventArgs; use Eccube\Event\TemplateEvent; class GiftWrappingEvent

    { /** @var \Eccube\Application $app */ private $app; public function __construct($app) { $this->app = $app; } public function onShoppingIndexInitialize(EventArgs $event) { // ϑΥʔϜͷ௥Ճ // FormBuilderͷऔಘ $builder = $event->getArgument('builder'); // ߲໨ͷ௥Ճ $builder->add('gift_wrapping', 'choice', array( 'choices' => array( '1' => 'ͷ͠ͷΑ͏ͳ΋ͷ', '2' => 'ϦϘϯ', '3' => 'ࢴแΈ', ), 'expanded' => false, 'multiple' => false, 'required' => false, 'empty_value' => 'ϥοϐϯάͳ͠', 'mapped' => false, )); } public function onShoppingIndexRender(TemplateEvent $event) {
  5. ϓϥάΠϯͷ࡞੒खॱ <?php namespace Plugin\GiftWrapping\ServiceProvider; use Eccube\Application; ɾɾɾɾ ɾɾɾɾ class GiftWrappingServiceProvider

    implements ServiceProviderInterface { public function register(BaseApplication $app) { // // ϝοηʔδొ࿥ $app['translator'] = $app->share($app->extend('translator', function ($translator, \Silex\Application $app) { $translator->addLoader('yaml', new \Symfony\Component\Translation\Loader\YamlFileLoader()); $file = __DIR__.'/../Resource/locale/message.'.$app['locale'].'.yml'; if (file_exists($file)) { $translator->addResource('yaml', $file, $app['locale']); } return $translator; })); // load config $conf = $app['config']; $app['config'] = $app->share(function () use ($conf) { $confarray = array(); $path_file = __DIR__.'/../Resource/config/path.yml'; if (file_exists($path_file)) { $config_yml = Yaml::parse(file_get_contents($path_file)); if (isset($config_yml)) { $confarray = array_replace_recursive($confarray, $config_yml); } } $constant_file = __DIR__.'/../Resource/config/constant.yml'; if (file_exists($constant_file)) { $config_yml = Yaml::parse(file_get_contents($constant_file)); if (isset($config_yml)) { $confarray = array_replace_recursive($confarray, $config_yml); }