120512 phpカンファレンス用資料

66
1 EC-CUBEプラグイン機能について

Upload: hiroaki-yoshimoto

Post on 10-May-2015

1.693 views

Category:

Entertainment & Humor


0 download

DESCRIPTION

EC-CUBEプラグイン機能について

TRANSCRIPT

Page 1: 120512 phpカンファレンス用資料

1

EC-CUBEプラグイン機能について

Page 2: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 2 2

自己紹介

吉本 啓顕(よしもと ひろあき)

勤務先

株式会社ロックオン

EC-CUBE プロジェクト担当

主な仕事

プロジェクト管理

開発

運用・サポート

Page 3: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 3 3

運営会社紹介

株式会社ロックオン

• 2001年6月4日 設立

• 従業員:54名

(平均:約30歳)

• 本社:大阪(梅田)

• 支社:東京(銀座)、シリコンバレー

ベトナム(オフショア拠点)

• 経営理念:Impact On The World

Page 4: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 4 4

ロックオン 製品紹介

つくる

はかる

運用する

分析する

Page 5: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 5 5

今日のテーマ

Page 6: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 6 6

Agenda

Page 7: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 7 7

Agenda

Page 8: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 8 8

EC-CUBEとは?

Page 9: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 9 9

EC-CUBEとは?

EC構築オープンソース として

国内No.1シェア

Page 10: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 10 10

EC-CUBEとは?

1万7000店舗以上

Page 11: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 11 11

EC-CUBEとは?

Page 12: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 12 12

EC-CUBEとは?

demonstration

Page 13: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 13 13

Agenda

Page 14: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 14 14

ソフトウェア要件

IIS

Page 15: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 15 15

EC-CUBEの構造

controller

model view

request response

Pageクラス

SCクラス Viewクラス

Smarty

Page 16: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 16 16

EC-CUBEの構造

controller

model view

request response

Pageクラス

SCクラス Viewクラス

Smarty

Page 17: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 17 17

EC-CUBEの構造

controller

model view

request response

Pageクラス

SCクラス Viewクラス

Smarty

Page 18: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 18 18

EC-CUBEの構造

controller

model view

request response

Pageクラス

SCクラス Viewクラス

Smarty

Page 19: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 19 19

EC-CUBEの構造

controller

model view

request response

Pageクラス

SCクラス Viewクラス

Smarty

Page 20: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 20 20

EC-CUBEの構造

controller

model view

request response

Pageクラス

SCクラス Viewクラス

Smarty

Page 21: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 21 21

Agenda

Page 22: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 22 22

プラグインで出来る事

・EC-CUBEの本体処理に介入する。

・テンプレートに変更を加える。

Page 23: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 23 23

プラグインで出来る事

・EC-CUBEの本体処理に介入する。

・テンプレートに変更を加える。

Page 24: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 24 24

プラグインで出来る事

・フォームからのPOST値を変更する。

・別のページに遷移させる。

・全く別の処理を実行する。

Page 25: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 25 25

プラグインで出来る事

なんでも出来る。

Page 26: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 26 26

プラグインで出来る事

・EC-CUBEの本体処理に介入する。

・テンプレートに変更を加える。

Page 27: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 27 27

プラグインで出来る事

・ボタンを追加する。

・フォームを追加する。

・テーブルを消す。

Page 28: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 28 28

プラグインで出来る事

controller

model view

request response

Pageクラス

SCクラス Viewクラス

Smarty

Page 29: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 29 29

Agenda

Page 30: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 30 30

プラグインの作り方

何を作るのか?

Page 31: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 31 31

プラグインの作り方

カテゴリ・コンテンツ。

Page 32: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 32 32

プラグインの作り方

①商品カテゴリー毎にデータを持たせる。

②該当のカテゴリが選択・表示される際に

データを持ってきて画面に表示する。

Page 33: 120512 phpカンファレンス用資料

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

用意するファイル

Page 34: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 34 34

プラグインの作り方

①商品カテゴリー毎にデータを持たせる。

②該当のカテゴリが選択・表示される際に

データを持ってきて画面に表示する。

Page 35: 120512 phpカンファレンス用資料

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

Page 36: 120512 phpカンファレンス用資料

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

用意するファイル

Page 37: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 37 37

プラグインメインクラス

CategoryContents.php (プラグインメインクラス)

Page 38: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 38 38

プラグインメインクラス

CategoryContents.php (プラグインメインクラス)

Page 39: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 39 39

プラグインメインクラス

CategoryContents.php (プラグインメインクラス)

Page 40: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 40 40

プラグインメインクラス

CategoryContents.php (プラグインメインクラス)

Page 41: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 41 41

プラグインメインクラス

CategoryContents.php (プラグインメインクラス)

フックポイント通過時 に実行する

コールバック関数

Page 42: 120512 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(プラグインメインクラス)

Page 43: 120512 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をキーに 登録されたコンテンツを取得する

Page 44: 120512 phpカンファレンス用資料

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

Page 45: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 45 45

プラグイン情報

plugin_info.php (プラグイン情報)

Page 46: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 46 46

プラグイン情報クラス

プラグインメインクラス

plugin_info.php (プラグイン情報)

Page 47: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 47 47

プラグイン情報クラス

plugin_info.php (プラグイン情報)

Page 48: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 48 48

プラグイン情報クラス

plugin_info.php (プラグイン情報)

フックポイント と

コールバック関数を定義

Page 49: 120512 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'));

}

介入したいフックポイントとコールバック関数定義

Page 50: 120512 phpカンファレンス用資料

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'));

}

Page 51: 120512 phpカンファレンス用資料

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'));

}

介入したい場所

Page 52: 120512 phpカンファレンス用資料

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'));

}

実行する関数

Page 53: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 53 53

プラグインメインクラス

実行したい関数を メインクラスに作成

作成した関数とフックポイントを

設定ファイルに定義

Page 54: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 54 54

テンプレート変更の仕組み

テンプレート ファイル

コンパイル ファイル

解析

plugin

SC_Helper_Plugin

pre filter

テンプレート ファイル

テンプレート ファイル

コンパイル ファイル

一度コンパイルファイルが生成されると 次回からはコンパイルファイルが参照される

Page 55: 120512 phpカンファレンス用資料

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

Page 56: 120512 phpカンファレンス用資料

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();

}

Page 57: 120512 phpカンファレンス用資料

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();

}

Page 58: 120512 phpカンファレンス用資料

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();

}

変更を加える ソース

Page 59: 120512 phpカンファレンス用資料

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();

}

要素を指定

Page 60: 120512 phpカンファレンス用資料

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();

}

指定した要素の操作

Page 61: 120512 phpカンファレンス用資料

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();

}

プラグインで用意した テンプレートを指定

Page 62: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 62 62

プラグインメインクラス

テンプレートで

変更した要素を指定

要素に対する操作

Page 63: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 63 63

プラグインの作り方

カテゴリ・コンテンツ。

Page 64: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 64 64

Agenda

Page 65: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 65 65

おまけ

Page 66: 120512 phpカンファレンス用資料

Copyright c LOCKON CO.,LTD. All Rights Reserved. 66 66

おまけ