120512 phpカンファレンス用資料
DESCRIPTION
EC-CUBEプラグイン機能についてTRANSCRIPT
1
EC-CUBEプラグイン機能について
Copyright c LOCKON CO.,LTD. All Rights Reserved. 2 2
自己紹介
吉本 啓顕(よしもと ひろあき)
勤務先
株式会社ロックオン
EC-CUBE プロジェクト担当
主な仕事
プロジェクト管理
開発
運用・サポート
Copyright c LOCKON CO.,LTD. All Rights Reserved. 3 3
運営会社紹介
株式会社ロックオン
• 2001年6月4日 設立
• 従業員:54名
(平均:約30歳)
• 本社:大阪(梅田)
• 支社:東京(銀座)、シリコンバレー
ベトナム(オフショア拠点)
• 経営理念:Impact On The World
Copyright c LOCKON CO.,LTD. All Rights Reserved. 4 4
ロックオン 製品紹介
つくる
はかる
運用する
分析する
Copyright c LOCKON CO.,LTD. All Rights Reserved. 5 5
今日のテーマ
Copyright c LOCKON CO.,LTD. All Rights Reserved. 6 6
Agenda
Copyright c LOCKON CO.,LTD. All Rights Reserved. 7 7
Agenda
Copyright c LOCKON CO.,LTD. All Rights Reserved. 8 8
EC-CUBEとは?
Copyright c LOCKON CO.,LTD. All Rights Reserved. 9 9
EC-CUBEとは?
EC構築オープンソース として
国内No.1シェア
Copyright c LOCKON CO.,LTD. All Rights Reserved. 10 10
EC-CUBEとは?
1万7000店舗以上
Copyright c LOCKON CO.,LTD. All Rights Reserved. 11 11
EC-CUBEとは?
Copyright c LOCKON CO.,LTD. All Rights Reserved. 12 12
EC-CUBEとは?
demonstration
Copyright c LOCKON CO.,LTD. All Rights Reserved. 13 13
Agenda
Copyright c LOCKON CO.,LTD. All Rights Reserved. 14 14
ソフトウェア要件
IIS
Copyright c LOCKON CO.,LTD. All Rights Reserved. 15 15
EC-CUBEの構造
controller
model view
request response
Pageクラス
SCクラス Viewクラス
Smarty
Copyright c LOCKON CO.,LTD. All Rights Reserved. 16 16
EC-CUBEの構造
controller
model view
request response
Pageクラス
SCクラス Viewクラス
Smarty
Copyright c LOCKON CO.,LTD. All Rights Reserved. 17 17
EC-CUBEの構造
controller
model view
request response
Pageクラス
SCクラス Viewクラス
Smarty
Copyright c LOCKON CO.,LTD. All Rights Reserved. 18 18
EC-CUBEの構造
controller
model view
request response
Pageクラス
SCクラス Viewクラス
Smarty
Copyright c LOCKON CO.,LTD. All Rights Reserved. 19 19
EC-CUBEの構造
controller
model view
request response
Pageクラス
SCクラス Viewクラス
Smarty
Copyright c LOCKON CO.,LTD. All Rights Reserved. 20 20
EC-CUBEの構造
controller
model view
request response
Pageクラス
SCクラス Viewクラス
Smarty
Copyright c LOCKON CO.,LTD. All Rights Reserved. 21 21
Agenda
Copyright c LOCKON CO.,LTD. All Rights Reserved. 22 22
プラグインで出来る事
・EC-CUBEの本体処理に介入する。
・テンプレートに変更を加える。
Copyright c LOCKON CO.,LTD. All Rights Reserved. 23 23
プラグインで出来る事
・EC-CUBEの本体処理に介入する。
・テンプレートに変更を加える。
Copyright c LOCKON CO.,LTD. All Rights Reserved. 24 24
プラグインで出来る事
・フォームからのPOST値を変更する。
・別のページに遷移させる。
・全く別の処理を実行する。
Copyright c LOCKON CO.,LTD. All Rights Reserved. 25 25
プラグインで出来る事
なんでも出来る。
Copyright c LOCKON CO.,LTD. All Rights Reserved. 26 26
プラグインで出来る事
・EC-CUBEの本体処理に介入する。
・テンプレートに変更を加える。
Copyright c LOCKON CO.,LTD. All Rights Reserved. 27 27
プラグインで出来る事
・ボタンを追加する。
・フォームを追加する。
・テーブルを消す。
Copyright c LOCKON CO.,LTD. All Rights Reserved. 28 28
プラグインで出来る事
controller
model view
request response
Pageクラス
SCクラス Viewクラス
Smarty
Copyright c LOCKON CO.,LTD. All Rights Reserved. 29 29
Agenda
Copyright c LOCKON CO.,LTD. All Rights Reserved. 30 30
プラグインの作り方
何を作るのか?
Copyright c LOCKON CO.,LTD. All Rights Reserved. 31 31
プラグインの作り方
カテゴリ・コンテンツ。
Copyright c LOCKON CO.,LTD. All Rights Reserved. 32 32
プラグインの作り方
①商品カテゴリー毎にデータを持たせる。
②該当のカテゴリが選択・表示される際に
データを持ってきて画面に表示する。
Copyright c LOCKON CO.,LTD. All Rights Reserved. 33 33
プラグインの作り方
CategoryContents.php (プラグインメインクラス) [必須]
CategoryContents.tar.gz
plugin_info.php (プラグイン情報) [必須]
plugin_update.php (アップデートクラス)
logo.png (縦65x横65ピクセル)
categorycontents_products_list_add.tpl
categorycontents_admin_basis_category_add.tpl
用意するファイル
Copyright c LOCKON CO.,LTD. All Rights Reserved. 34 34
プラグインの作り方
①商品カテゴリー毎にデータを持たせる。
②該当のカテゴリが選択・表示される際に
データを持ってきて画面に表示する。
Copyright c LOCKON CO.,LTD. All Rights Reserved. 35 35
plugin
SC_Helper_Plugin
プラグインの作り方
controller
LC_Page_Products_List
view
Viewクラス
CategoryContents
LC_Page_Products_List_action_after
Copyright c LOCKON CO.,LTD. All Rights Reserved. 36 36
プラグインの作り方
CategoryContents.php (プラグインメインクラス) [必須]
CategoryContents.tar.gz
plugin_info.php (プラグイン情報) [必須]
plugin_update.php (アップデートクラス)
config.php (設定クラス)
logo.png (縦65x横65ピクセル)
categorycontents_products_list_add.tpl
categorycontents_admin_basis_category_add.tpl
用意するファイル
Copyright c LOCKON CO.,LTD. All Rights Reserved. 37 37
プラグインメインクラス
CategoryContents.php (プラグインメインクラス)
Copyright c LOCKON CO.,LTD. All Rights Reserved. 38 38
プラグインメインクラス
CategoryContents.php (プラグインメインクラス)
Copyright c LOCKON CO.,LTD. All Rights Reserved. 39 39
プラグインメインクラス
CategoryContents.php (プラグインメインクラス)
Copyright c LOCKON CO.,LTD. All Rights Reserved. 40 40
プラグインメインクラス
CategoryContents.php (プラグインメインクラス)
Copyright c LOCKON CO.,LTD. All Rights Reserved. 41 41
プラグインメインクラス
CategoryContents.php (プラグインメインクラス)
フックポイント通過時 に実行する
コールバック関数
Copyright c LOCKON CO.,LTD. All Rights Reserved. 42 42
プラグインメインクラス
function disp_contents($objPage) {
// 選択されたカテゴリーID
$category_id = $objPage->arrSearchData['category_id'];
if(!empty($category_id)){
$array_category = CategoryContents::getCategoryByCategoryId($category_id);
$objPage->plg_categoryContents_category_contents
= $array_category['plg_categorycontents_category_contents'];
}
}
CategoryContents.php(プラグインメインクラス)
Copyright c LOCKON CO.,LTD. All Rights Reserved. 43 43
プラグインメインクラス
function disp_contents($objPage) {
// 選択されたカテゴリーID
$category_id = $objPage->arrSearchData['category_id'];
if(!empty($category_id)){
$array_category = CategoryContents::getCategoryByCategoryId($category_id);
$objPage->plg_categoryContents_category_contents
= $array_category['plg_categorycontents_category_contents'];
}
}
CategoryContents.php(プラグインメインクラス)
カテゴリーのIDをキーに 登録されたコンテンツを取得する
Copyright c LOCKON CO.,LTD. All Rights Reserved. 44 44
用意するファイル
CategoryContents.php (プラグインメインクラス) [必須]
CategoryContents.tar.gz
plugin_info.php (プラグイン情報) [必須]
plugin_update.php (アップデートクラス)
config.php (設定クラス)
logo.png (縦65x横65ピクセル)
categorycontents_products_list_add.tpl
categorycontents_admin_basis_category_add.tpl
Copyright c LOCKON CO.,LTD. All Rights Reserved. 45 45
プラグイン情報
plugin_info.php (プラグイン情報)
Copyright c LOCKON CO.,LTD. All Rights Reserved. 46 46
プラグイン情報クラス
プラグインメインクラス
plugin_info.php (プラグイン情報)
Copyright c LOCKON CO.,LTD. All Rights Reserved. 47 47
プラグイン情報クラス
plugin_info.php (プラグイン情報)
Copyright c LOCKON CO.,LTD. All Rights Reserved. 48 48
プラグイン情報クラス
plugin_info.php (プラグイン情報)
フックポイント と
コールバック関数を定義
Copyright c LOCKON CO.,LTD. All Rights Reserved. 49 49
プラグインメインクラス
plugin_info.php(プラグイン情報)
class plugin_info {
static $PLUGIN_CODE = "CategoryContents ";
static $PLUGIN_NAME = "カテゴリ・コンテンツ";
static $PLUGIN_VERSION = "0.1";
static $COMPLIANT_VERSION = "2.12.0";
static $AUTHOR = “株式会社ロックオン";
static $DESCRIPTION = “カテゴリにコンテンツを表示。";
static $PLUGIN_SITE_URL = "http://www.ec-cube.net/";
static $AUTHOR_SITE_URL = "http:// www.ec-cube.net /";
static $CLASS_NAME = "SampleClassHook";
static $HOOK_POINTS = array(
array(" LC_Page_Admin_Products_Category_action_after ", 'contents_set'),
array(" LC_Page_Products_List_action_after ", 'disp_contents'),
array("prefilterTransform", 'prefilterTransform'));
}
介入したいフックポイントとコールバック関数定義
Copyright c LOCKON CO.,LTD. All Rights Reserved. 50 50
プラグインメインクラス
plugin_info.php(プラグイン情報)
class plugin_info {
static $PLUGIN_CODE = "CategoryContents ";
static $PLUGIN_NAME = "カテゴリ・コンテンツ";
static $PLUGIN_VERSION = "0.1";
static $COMPLIANT_VERSION = "2.12.0";
static $AUTHOR = “株式会社ロックオン";
static $DESCRIPTION = “カテゴリにコンテンツを表示。";
static $PLUGIN_SITE_URL = "http://www.ec-cube.net/";
static $AUTHOR_SITE_URL = "http:// www.ec-cube.net /";
static $CLASS_NAME = "SampleClassHook";
static $HOOK_POINTS = array(
array(" LC_Page_Admin_Products_Category_action_after ", 'contents_set'),
array(" LC_Page_Products_List_action_after ", 'disp_contents'), array("prefilterTransform", 'prefilterTransform'));
}
Copyright c LOCKON CO.,LTD. All Rights Reserved. 51 51
プラグインメインクラス
plugin_info.php(プラグイン情報)
class plugin_info {
static $PLUGIN_CODE = "CategoryContents ";
static $PLUGIN_NAME = "カテゴリ・コンテンツ";
static $PLUGIN_VERSION = "0.1";
static $COMPLIANT_VERSION = "2.12.0";
static $AUTHOR = “株式会社ロックオン";
static $DESCRIPTION = “カテゴリにコンテンツを表示。";
static $PLUGIN_SITE_URL = "http://www.ec-cube.net/";
static $AUTHOR_SITE_URL = "http:// www.ec-cube.net /";
static $CLASS_NAME = "SampleClassHook";
static $HOOK_POINTS = array(
array(" LC_Page_Admin_Products_Category_action_after ", 'contents_set'),
array(" LC_Page_Products_List_action_after ", 'disp_contents'), array("prefilterTransform", 'prefilterTransform'));
}
介入したい場所
Copyright c LOCKON CO.,LTD. All Rights Reserved. 52 52
プラグインメインクラス
plugin_info.php(プラグイン情報)
class plugin_info {
static $PLUGIN_CODE = "CategoryContents ";
static $PLUGIN_NAME = "カテゴリ・コンテンツ";
static $PLUGIN_VERSION = "0.1";
static $COMPLIANT_VERSION = "2.12.0";
static $AUTHOR = “株式会社ロックオン";
static $DESCRIPTION = “カテゴリにコンテンツを表示。";
static $PLUGIN_SITE_URL = "http://www.ec-cube.net/";
static $AUTHOR_SITE_URL = "http:// www.ec-cube.net /";
static $CLASS_NAME = "SampleClassHook";
static $HOOK_POINTS = array(
array(" LC_Page_Admin_Products_Category_action_after ", 'contents_set'),
array(" LC_Page_Products_List_action_after ", 'disp_contents'), array("prefilterTransform", 'prefilterTransform'));
}
実行する関数
Copyright c LOCKON CO.,LTD. All Rights Reserved. 53 53
プラグインメインクラス
実行したい関数を メインクラスに作成
作成した関数とフックポイントを
設定ファイルに定義
Copyright c LOCKON CO.,LTD. All Rights Reserved. 54 54
テンプレート変更の仕組み
テンプレート ファイル
コンパイル ファイル
解析
plugin
SC_Helper_Plugin
pre filter
テンプレート ファイル
テンプレート ファイル
コンパイル ファイル
一度コンパイルファイルが生成されると 次回からはコンパイルファイルが参照される
Copyright c LOCKON CO.,LTD. All Rights Reserved. 55 55
テンプレート変更の仕組み
<!--★タイトル★-->
<h2 class="title"><!--{$tpl_subtitle|h}--></h2>
<!--▼検索条件-->
<!--{if $tpl_subtitle == "検索結果"}-->
<ul class="pagecond_area">
<li><strong>商品カテゴリ:</strong><!--{$arrSearch.category|h}--></li>
<li><strong>商品名:</strong><!--{$arrSearch.name|h}--></li>
</ul>
<!--{/if}-->
<!--▲検索条件-->
<!--★タイトル★-->
<!--PLG:CategoryContents↓-->
<div><!--{$plg_categoryContents_category_contents|nl2br_html}--></div>
<!--PLG:CategoryContents↑-->
<h2 class="title"><!--{$tpl_subtitle|h}--></h2>
<!--▼検索条件-->
<!--{if $tpl_subtitle == "検索結果"}-->
<ul class="pagecond_area">
<li><strong>商品カテゴリ:</strong><!--{$arrSearch.category|h}--></li>
<li><strong>商品名:</strong><!--{$arrSearch.name|h}--></li>
</ul>
<!--{/if}-->
<!--▲検索条件-->
SC_Helper_Transform
plugin
SC_Helper_Plugin
Copyright c LOCKON CO.,LTD. All Rights Reserved. 56 56
テンプレート変更の仕組み
function prefilterTransform(&$source, LC_Page_Ex $objPage, $filename) {
$objTransform = new SC_Helper_Transform($source);
$template_dir = PLUGIN_UPLOAD_REALDIR . 'CategoryContents/templates/';
switch($objPage->arrPageLayout['device_type_id']){
case DEVICE_TYPE_MOBILE:
case DEVICE_TYPE_SMARTPHONE:
case DEVICE_TYPE_PC:
// 商品一覧画面
if (strpos($filename, 'products/list.tpl') !== false) { $objTransform->select('h2.title')->insertBefore(file_get_contents($template_dir . 'categorycontents_products_list_add.tpl'));
}
break;
default:
break;
}
$source = $objTransform->getHTML();
}
Copyright c LOCKON CO.,LTD. All Rights Reserved. 57 57
テンプレート変更の仕組み
function prefilterTransform(&$source, LC_Page_Ex $objPage, $filename) {
$objTransform = new SC_Helper_Transform($source); $template_dir = PLUGIN_UPLOAD_REALDIR . 'CategoryContents/templates/';
switch($objPage->arrPageLayout['device_type_id']){
case DEVICE_TYPE_MOBILE:
case DEVICE_TYPE_SMARTPHONE:
case DEVICE_TYPE_PC:
// 商品一覧画面
if (strpos($filename, 'products/list.tpl') !== false) {
$objTransform->select('h2.title')->insertBefore(
file_get_contents($template_dir . 'categorycontents_products_list_add.tpl')
); }
break;
default:
break;
}
$source = $objTransform->getHTML();
}
Copyright c LOCKON CO.,LTD. All Rights Reserved. 58 58
テンプレート変更の仕組み
function prefilterTransform(&$source, LC_Page_Ex $objPage, $filename) {
$objTransform = new SC_Helper_Transform($source); $template_dir = PLUGIN_UPLOAD_REALDIR . 'CategoryContents/templates/';
switch($objPage->arrPageLayout['device_type_id']){
case DEVICE_TYPE_MOBILE:
case DEVICE_TYPE_SMARTPHONE:
case DEVICE_TYPE_PC:
// 商品一覧画面
if (strpos($filename, 'products/list.tpl') !== false) {
$objTransform->select('h2.title')->insertBefore(
file_get_contents($template_dir . 'categorycontents_products_list_add.tpl')
); }
break;
default:
break;
}
$source = $objTransform->getHTML();
}
変更を加える ソース
Copyright c LOCKON CO.,LTD. All Rights Reserved. 59 59
テンプレート変更の仕組み
function prefilterTransform(&$source, LC_Page_Ex $objPage, $filename) {
$objTransform = new SC_Helper_Transform($source); $template_dir = PLUGIN_UPLOAD_REALDIR . 'CategoryContents/templates/';
switch($objPage->arrPageLayout['device_type_id']){
case DEVICE_TYPE_MOBILE:
case DEVICE_TYPE_SMARTPHONE:
case DEVICE_TYPE_PC:
// 商品一覧画面
if (strpos($filename, 'products/list.tpl') !== false) {
$objTransform->select('h2.title')->insertBefore(
file_get_contents($template_dir . 'categorycontents_products_list_add.tpl')
); }
break;
default:
break;
}
$source = $objTransform->getHTML();
}
要素を指定
Copyright c LOCKON CO.,LTD. All Rights Reserved. 60 60
テンプレート変更の仕組み
function prefilterTransform(&$source, LC_Page_Ex $objPage, $filename) {
$objTransform = new SC_Helper_Transform($source); $template_dir = PLUGIN_UPLOAD_REALDIR . 'CategoryContents/templates/';
switch($objPage->arrPageLayout['device_type_id']){
case DEVICE_TYPE_MOBILE:
case DEVICE_TYPE_SMARTPHONE:
case DEVICE_TYPE_PC:
// 商品一覧画面
if (strpos($filename, 'products/list.tpl') !== false) {
$objTransform->select('h2.title')->insertBefore(
file_get_contents($template_dir . 'categorycontents_products_list_add.tpl')
); }
break;
default:
break;
}
$source = $objTransform->getHTML();
}
指定した要素の操作
Copyright c LOCKON CO.,LTD. All Rights Reserved. 61 61
テンプレート変更の仕組み
function prefilterTransform(&$source, LC_Page_Ex $objPage, $filename) {
$objTransform = new SC_Helper_Transform($source); $template_dir = PLUGIN_UPLOAD_REALDIR . 'CategoryContents/templates/';
switch($objPage->arrPageLayout['device_type_id']){
case DEVICE_TYPE_MOBILE:
case DEVICE_TYPE_SMARTPHONE:
case DEVICE_TYPE_PC:
// 商品一覧画面
if (strpos($filename, 'products/list.tpl') !== false) {
$objTransform->select('h2.title')->insertBefore(
file_get_contents($template_dir . 'categorycontents_products_list_add.tpl')
); }
break;
default:
break;
}
$source = $objTransform->getHTML();
}
プラグインで用意した テンプレートを指定
Copyright c LOCKON CO.,LTD. All Rights Reserved. 62 62
プラグインメインクラス
テンプレートで
変更した要素を指定
要素に対する操作
Copyright c LOCKON CO.,LTD. All Rights Reserved. 63 63
プラグインの作り方
カテゴリ・コンテンツ。
Copyright c LOCKON CO.,LTD. All Rights Reserved. 64 64
Agenda
Copyright c LOCKON CO.,LTD. All Rights Reserved. 65 65
おまけ
Copyright c LOCKON CO.,LTD. All Rights Reserved. 66 66
おまけ