logo

Select Sidearea

Populate the sidearea with useful widgets. It’s simple to add images, categories, latest post, social media icon links, tag clouds, and more.
hello@youremail.com
+1234567890
 

EC-CUBE4 問合せフォームをプラグインに複製する方法

EC-CUBE4 問合せフォームをプラグインに複製する方法

EC-CUBE4の問合せフォーム(/contact)をプラグインで複製する方法を紹介します。

 

・以下のリンクを参考にプラグインの雛形を作成してください。

EC-CUBE4プラグインの雛形の作成方法はこちら

 

・以下の3ファイルを指定のフォルダーにコピーしてください。(本記事では、例としてプラグインフォルダー名の部分をHogePluginとしています。)

パス:src/Eccube/Controller/ContactController.php

⇒app/Plugin/HogePlugin/Controllerフォルダー内

 

パス:src/Resource/template/default/Contact/index.twig および同フォルダー内のconfirm.twig

⇒app/Plugin/HogePlugin/Resource/templateフォルダー内

※指定のフォルダー以外にコピーするとエラーが発生するようなので、必ず上記のフォルダー内にコピーしてください。

 

・ContactController.phpの変更点

・14行目、namespaceの変更(Plugin/HogePlugin/Controller)

・25行目、クラス名の変更。(例:NewContactController等)

・ファイル名を変更(クラス名に合わせる)

・46行目、@Route(“/contact”, name=”contact”)を修正。 例:@Route(“/new_contact”, name=”new_contact”)

・47行目、@Template(“Contact/index.twig”)を修正。例:@Template(“@HogePlugin/new_index.twig”)

・90行目、render(‘Contact/confirm.twig’を修正。例:render(“@HogePlugin/new_confire.twig”)

・23行目の次に、以下のコードを追加。

use Eccube\Controller\AbstractController;

 

・index.twigの変更点

・27行目、action=”{{ url(‘contact’) }}”を修正。例:action=”{{ url(‘new_contact’) }}”

・confire.twigの変更点

・22行目、action=”{{ url(‘contact’) }}”を修正。例:action=”{{ url(‘new_contact’) }}”

 

これで問合せフォームが表示されますが、ヘッダーやフッターが表示されていないので、別途設定が必要になります。