EC-CUBE   Plugin




                   1
自己紹介



                   吉本 啓顕
                   勤務先
                    株式会社ロックオン

                   主な仕事
                     プロモーション ・ 開発 ・ 運用・サポート




Copyright c LOCKON CO.,LTD. All Rights Reserved.          2
今回のセミナーテーマ




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




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




Copyright c LOCKON CO.,LTD. All Rights Reserved.            5
EC-CUBEとは?




     新コンセプト
EC Open Platform


                   6
プラグインで出来る事


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

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




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




Copyright c LOCKON CO.,LTD. All Rights Reserved.            8
プラグインで出来る事


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

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




Copyright c LOCKON CO.,LTD. All Rights Reserved.   9
本体処理に介入


      ・フォームからのPOST値を変更する。
      ・別のページに遷移させる。
      ・全く別の処理を実行する。




Copyright c LOCKON CO.,LTD. All Rights Reserved.     10
本体処理に介入


      ・フォームからのPOST値を変更する。
          REQUEST{                                 REQUEST{
            ‘mode’ = car t,                          ‘mode’ = car t,
            ‘product_id’ = 1                         ‘product_id’ = 1
            ‘quantity’ = 1                           ‘quantity’ = 1
            ‘price’ = 100                            ‘price’ = 0
          }                                        }




Copyright c LOCKON CO.,LTD. All Rights Reserved.                        11
本体処理に介入

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



                                    配送方法選択

                                                   見積り入力
                                    支払方法選択


                                           確認


                                        購入完了



Copyright c LOCKON CO.,LTD. All Rights Reserved.           12
本体処理に介入

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


                                   商品の価格計算


                                      配送料計算


                                    消費税の計算
                                                   新消費税の計算


                                      合計の計算




Copyright c LOCKON CO.,LTD. All Rights Reserved.             13
本体処理に介入


                                                    本体処理A


                                                   プラグイン処理


                                                   本体処理B


                                                   本体処理C



Copyright c LOCKON CO.,LTD. All Rights Reserved.             14
プラグインで出来る事



                                                      request           response



                                                      Pageクラス
                                                         controller

                                                                             Smarty



                                   SCクラス                              Viewクラス
                                              model                        view


Copyright c LOCKON CO.,LTD. All Rights Reserved.                                      15
プラグインで出来る事



              なんでも出来る。


Copyright c LOCKON CO.,LTD. All Rights Reserved.   16
プラグインで出来る事


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

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




Copyright c LOCKON CO.,LTD. All Rights Reserved.   17
テンプレートに変更を加える


                     ・ボタンを追加する。
                     ・フォームを追加する。
                     ・テーブルを消す。




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




Copyright c LOCKON CO.,LTD. All Rights Reserved.            19
プラグインの作り方



  カテゴリ・コンテンツ。


Copyright c LOCKON CO.,LTD. All Rights Reserved.   20
カテゴリコンテンツ

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


     ②該当のカテゴリが選択・表示される際に
     データを持ってきて画面に表示する。




Copyright c LOCKON CO.,LTD. All Rights Reserved.   21
カテゴリコンテンツ




                                                   demonstration




Copyright c LOCKON CO.,LTD. All Rights Reserved.                   22
プラグインの作り方

       CategoryContents.tar.gz                                              用意するファイル
                                       CategoryContents.php (プラグインメインクラス) [必須]
                                       plugin_info.php (プラグイン情報) [必須]
                                       plugin_update.php (アップデートクラス)


                                       logo.png (縦65x横65ピクセル)

                                                   categorycontents_admin_basis_category_add.tpl

                                                   categorycontents_products_list_add.tpl




Copyright c LOCKON CO.,LTD. All Rights Reserved.                                                   23
プラグインの作り方

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


     ②該当のカテゴリが選択・表示される際に
     データを持ってきて画面に表示する。




Copyright c LOCKON CO.,LTD. All Rights Reserved.   24
本体処理に介入する流れ
                                                                                   dtb_plugin




                                                        SC_Helper_Plugin(エンジンクラス)


                                                              CategoryContents      plugin




                             LC_Page_Products_List

                                     controller
                         LC_Page_Products_List_action_after
                                                                       Viewクラス
                                                                            view



Copyright c LOCKON CO.,LTD. All Rights Reserved.                                             25
プラグインの作り方

       CategoryContents.tar.gz                                              用意するファイル
                                       CategoryContents.php (プラグインメインクラス) [必須]
                                       plugin_info.php (プラグイン情報) [必須]
                                       plugin_update.php (アップデートクラス)
                                       config.php (設定クラス)
                                       logo.png (縦65x横65ピクセル)

                                                   categorycontents_admin_basis_category_add.tpl

                                                   categorycontents_products_list_add.tpl




Copyright c LOCKON CO.,LTD. All Rights Reserved.                                                   26
プラグインメインクラス



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




Copyright c LOCKON CO.,LTD. All Rights Reserved.   27
プラグインメインクラス


         フックポイント通過時
               CategoryContents.php
                      に実行する
               (プラグインメインクラス)
                    コールバック関数


Copyright c LOCKON CO.,LTD. All Rights Reserved.   28
プラグインメインクラス

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


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'];
      }
  }




Copyright c LOCKON CO.,LTD. All Rights Reserved.                                       29
プラグインメインクラス

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


function disp_contents($objPage) {
      // 選択されたカテゴリーID
      $category_id = $objPage->arrSearchData['category_id'];
      if(!empty($category_id)){         カテゴリーのIDをキーに
                        登録されたコンテンツを取得する
          $array_category = CategoryContents::getCategoryByCategoryId($category_id);
          $objPage->plg_categoryContents_category_contents
            = $array_category['plg_categorycontents_category_contents'];
      }
  }




Copyright c LOCKON CO.,LTD. All Rights Reserved.                                 30
プラグインメインクラス

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



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'];
      }
  }




Copyright c LOCKON CO.,LTD. All Rights Reserved.                                       31
用意するファイル

       CategoryContents.tar.gz


                                       CategoryContents.php (プラグインメインクラス) [必須]
                                       plugin_info.php (プラグイン情報) [必須]
                                       plugin_update.php (アップデートクラス)
                                       config.php (設定クラス)
                                       logo.png (縦65x横65ピクセル)

                                                   categorycontents_admin_basis_category_add.tpl

                                                   categorycontents_products_list_add.tpl




Copyright c LOCKON CO.,LTD. All Rights Reserved.                                                   32
プラグイン情報



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




Copyright c LOCKON CO.,LTD. All Rights Reserved.     33
プラグイン情報


                            フックポイント
                と
          plugin_info.php
        コールバック関数を定義
          (プラグイン情報)




Copyright c LOCKON CO.,LTD. All Rights Reserved.     34
プラグイン情報

                          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.                           35
プラグイン情報

                          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.                           36
プラグイン情報

                          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.                           37
プラグイン情報

                          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.                           38
プラグイン情報

      $HOOK_POINTSで定義した定数は
      インストール時に以下のテーブルにINSERTされます。
                    dtb_plugin_hookpoint
                    CREATE TABLE `dtb_plugin_hookpoint` (
                     `plugin_hookpoint_id` int(11) NOT NULL,
                      `plugin_id` int(11) NOT NULL,
                      `hook_point` text NOT NULL,
                      `callback` text,
                      `create_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
                      `update_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
                      PRIMARY KEY (`plugin_hookpoint_id`)
                    ) ENGINE=InnoDB DEFAULT CHARSET=utf8


Copyright c LOCKON CO.,LTD. All Rights Reserved.                                   39
まとめ

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

   作成した関数とフックポイントを
      設定ファイルに定義



Copyright c LOCKON CO.,LTD. All Rights Reserved.         40
テンプレート変更の仕組み
                                                        SC_Helper_Plugin
                                                                     plugin

                                                                           SC_Helper_Transform
                            テンプレート                          テンプレート
                             ファイル                            ファイル




         テンプレート                                     pre                                  コンパイル
          ファイル                                                       解析
                                                   filter                                 ファイル




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


Copyright c LOCKON CO.,LTD. All Rights Reserved.                                                 41
実例
 <!--★タイトル★-->
    <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}-->
                                  <!--▲検索条件-->

Copyright c LOCKON CO.,LTD. All Rights Reserved.                                                           42
プラグインメインクラス
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.                                                                                   43
プラグイン情報

                          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.                           44
プラグインメインクラス

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.                                                                                   45
プラグインメインクラス

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:                           コール元のPageオブジェクト
        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.                                                                                      46
プラグインメインクラス

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.                                                                                   47
プラグインメインクラス
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.                                                                                   48
プラグインメインクラス
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.                               49
プラグインメインクラス
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.                                        50
プラグインメインクラス
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.                               51
プラグインメインクラス
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.                               52
プラグインメインクラス
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.                               53
プラグインメインクラス
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.                                       54
プラグインメインクラス
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.                               55
テンプレート変更のまとめ


               テンプレートで変更したい
                要素をDOM形式で指定

                    要素に対する操作を実行



Copyright c LOCKON CO.,LTD. All Rights Reserved.   56
カテゴリコンテンツ おさらい

   ①インスタンス生成                                                          SC_Helper_Plugin

   ②PHP処理介入                                                                   CategoryContents

   ③テンプレート介入                                           ①


                                                               ②      ③
                                        Pageクラス
                                               controller

                                                                     Smarty



               SCクラス                                        Viewクラス
                         model                                     view


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

20120824_ハンズオンセミナー資料_第1部

  • 1.
    EC-CUBE Plugin 1
  • 2.
    自己紹介 吉本 啓顕 勤務先 株式会社ロックオン 主な仕事 プロモーション ・ 開発 ・ 運用・サポート Copyright c LOCKON CO.,LTD. All Rights Reserved. 2
  • 3.
  • 4.
    Agenda Copyright c LOCKONCO.,LTD. All Rights Reserved. 4
  • 5.
    Agenda Copyright c LOCKONCO.,LTD. All Rights Reserved. 5
  • 6.
    EC-CUBEとは? 新コンセプト EC Open Platform 6
  • 7.
    プラグインで出来る事 ・EC-CUBEの本体処理に介入する。 ・テンプレートに変更を加える。 Copyright c LOCKON CO.,LTD. All Rights Reserved. 7
  • 8.
    Agenda Copyright c LOCKONCO.,LTD. All Rights Reserved. 8
  • 9.
    プラグインで出来る事 ・EC-CUBEの本体処理に介入する。 ・テンプレートに変更を加える。 Copyright c LOCKON CO.,LTD. All Rights Reserved. 9
  • 10.
    本体処理に介入 ・フォームからのPOST値を変更する。 ・別のページに遷移させる。 ・全く別の処理を実行する。 Copyright c LOCKON CO.,LTD. All Rights Reserved. 10
  • 11.
    本体処理に介入 ・フォームからのPOST値を変更する。 REQUEST{ REQUEST{ ‘mode’ = car t, ‘mode’ = car t, ‘product_id’ = 1 ‘product_id’ = 1 ‘quantity’ = 1 ‘quantity’ = 1 ‘price’ = 100 ‘price’ = 0 } } Copyright c LOCKON CO.,LTD. All Rights Reserved. 11
  • 12.
    本体処理に介入 ・別のページに遷移させる カート 配送方法選択 見積り入力 支払方法選択 確認 購入完了 Copyright c LOCKON CO.,LTD. All Rights Reserved. 12
  • 13.
    本体処理に介入 ・全く別の処理を実行する。 初期化 商品の価格計算 配送料計算 消費税の計算 新消費税の計算 合計の計算 Copyright c LOCKON CO.,LTD. All Rights Reserved. 13
  • 14.
    本体処理に介入 本体処理A プラグイン処理 本体処理B 本体処理C Copyright c LOCKON CO.,LTD. All Rights Reserved. 14
  • 15.
    プラグインで出来る事 request response Pageクラス controller Smarty SCクラス Viewクラス model view Copyright c LOCKON CO.,LTD. All Rights Reserved. 15
  • 16.
    プラグインで出来る事 なんでも出来る。 Copyright c LOCKON CO.,LTD. All Rights Reserved. 16
  • 17.
    プラグインで出来る事 ・EC-CUBEの本体処理に介入する。 ・テンプレートに変更を加える。 Copyright c LOCKON CO.,LTD. All Rights Reserved. 17
  • 18.
    テンプレートに変更を加える ・ボタンを追加する。 ・フォームを追加する。 ・テーブルを消す。 Copyright c LOCKON CO.,LTD. All Rights Reserved. 18
  • 19.
    Agenda Copyright c LOCKONCO.,LTD. All Rights Reserved. 19
  • 20.
  • 21.
    カテゴリコンテンツ ①商品カテゴリー毎にデータを持たせる。 ②該当のカテゴリが選択・表示される際に データを持ってきて画面に表示する。 Copyright c LOCKON CO.,LTD. All Rights Reserved. 21
  • 22.
    カテゴリコンテンツ demonstration Copyright c LOCKON CO.,LTD. All Rights Reserved. 22
  • 23.
    プラグインの作り方 CategoryContents.tar.gz 用意するファイル CategoryContents.php (プラグインメインクラス) [必須] plugin_info.php (プラグイン情報) [必須] plugin_update.php (アップデートクラス) logo.png (縦65x横65ピクセル) categorycontents_admin_basis_category_add.tpl categorycontents_products_list_add.tpl Copyright c LOCKON CO.,LTD. All Rights Reserved. 23
  • 24.
    プラグインの作り方 ①商品カテゴリー毎にデータを持たせる。 ②該当のカテゴリが選択・表示される際に データを持ってきて画面に表示する。 Copyright c LOCKON CO.,LTD. All Rights Reserved. 24
  • 25.
    本体処理に介入する流れ dtb_plugin SC_Helper_Plugin(エンジンクラス) CategoryContents plugin LC_Page_Products_List controller LC_Page_Products_List_action_after Viewクラス view Copyright c LOCKON CO.,LTD. All Rights Reserved. 25
  • 26.
    プラグインの作り方 CategoryContents.tar.gz 用意するファイル CategoryContents.php (プラグインメインクラス) [必須] plugin_info.php (プラグイン情報) [必須] plugin_update.php (アップデートクラス) config.php (設定クラス) logo.png (縦65x横65ピクセル) categorycontents_admin_basis_category_add.tpl categorycontents_products_list_add.tpl Copyright c LOCKON CO.,LTD. All Rights Reserved. 26
  • 27.
    プラグインメインクラス CategoryContents.php (プラグインメインクラス) Copyright c LOCKON CO.,LTD. All Rights Reserved. 27
  • 28.
    プラグインメインクラス フックポイント通過時 CategoryContents.php に実行する (プラグインメインクラス) コールバック関数 Copyright c LOCKON CO.,LTD. All Rights Reserved. 28
  • 29.
    プラグインメインクラス CategoryContents.php(プラグインメインクラス) 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']; } } Copyright c LOCKON CO.,LTD. All Rights Reserved. 29
  • 30.
    プラグインメインクラス CategoryContents.php(プラグインメインクラス) function disp_contents($objPage) { // 選択されたカテゴリーID $category_id = $objPage->arrSearchData['category_id']; if(!empty($category_id)){ カテゴリーのIDをキーに 登録されたコンテンツを取得する $array_category = CategoryContents::getCategoryByCategoryId($category_id); $objPage->plg_categoryContents_category_contents = $array_category['plg_categorycontents_category_contents']; } } Copyright c LOCKON CO.,LTD. All Rights Reserved. 30
  • 31.
    プラグインメインクラス CategoryContents.php(プラグインメインクラス) 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']; } } Copyright c LOCKON CO.,LTD. All Rights Reserved. 31
  • 32.
    用意するファイル CategoryContents.tar.gz CategoryContents.php (プラグインメインクラス) [必須] plugin_info.php (プラグイン情報) [必須] plugin_update.php (アップデートクラス) config.php (設定クラス) logo.png (縦65x横65ピクセル) categorycontents_admin_basis_category_add.tpl categorycontents_products_list_add.tpl Copyright c LOCKON CO.,LTD. All Rights Reserved. 32
  • 33.
    プラグイン情報 plugin_info.php (プラグイン情報) Copyright c LOCKON CO.,LTD. All Rights Reserved. 33
  • 34.
    プラグイン情報 フックポイント と plugin_info.php コールバック関数を定義 (プラグイン情報) Copyright c LOCKON CO.,LTD. All Rights Reserved. 34
  • 35.
    プラグイン情報 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. 35
  • 36.
    プラグイン情報 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. 36
  • 37.
    プラグイン情報 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. 37
  • 38.
    プラグイン情報 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. 38
  • 39.
    プラグイン情報 $HOOK_POINTSで定義した定数は インストール時に以下のテーブルにINSERTされます。 dtb_plugin_hookpoint CREATE TABLE `dtb_plugin_hookpoint` ( `plugin_hookpoint_id` int(11) NOT NULL, `plugin_id` int(11) NOT NULL, `hook_point` text NOT NULL, `callback` text, `create_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `update_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (`plugin_hookpoint_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 Copyright c LOCKON CO.,LTD. All Rights Reserved. 39
  • 40.
    まとめ 実行したい関数を メインクラスに作成 作成した関数とフックポイントを 設定ファイルに定義 Copyright c LOCKON CO.,LTD. All Rights Reserved. 40
  • 41.
    テンプレート変更の仕組み SC_Helper_Plugin plugin SC_Helper_Transform テンプレート テンプレート ファイル ファイル テンプレート pre コンパイル ファイル 解析 filter ファイル 一度コンパイルファイルが生成されると 次回からはコンパイルファイルが参照される Copyright c LOCKON CO.,LTD. All Rights Reserved. 41
  • 42.
    実例 <!--★タイトル★--> <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}--> <!--▲検索条件--> Copyright c LOCKON CO.,LTD. All Rights Reserved. 42
  • 43.
    プラグインメインクラス 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. 43
  • 44.
    プラグイン情報 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. 44
  • 45.
    プラグインメインクラス 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. 45
  • 46.
    プラグインメインクラス 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: コール元のPageオブジェクト 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. 46
  • 47.
    プラグインメインクラス 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. 47
  • 48.
    プラグインメインクラス 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. 48
  • 49.
    プラグインメインクラス 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. 49
  • 50.
    プラグインメインクラス 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. 50
  • 51.
    プラグインメインクラス 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. 51
  • 52.
    プラグインメインクラス 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. 52
  • 53.
    プラグインメインクラス 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. 53
  • 54.
    プラグインメインクラス 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. 54
  • 55.
    プラグインメインクラス 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. 55
  • 56.
    テンプレート変更のまとめ テンプレートで変更したい 要素をDOM形式で指定 要素に対する操作を実行 Copyright c LOCKON CO.,LTD. All Rights Reserved. 56
  • 57.
    カテゴリコンテンツ おさらい ①インスタンス生成 SC_Helper_Plugin ②PHP処理介入 CategoryContents ③テンプレート介入 ① ② ③ Pageクラス controller Smarty SCクラス Viewクラス model view Copyright c LOCKON CO.,LTD. All Rights Reserved. 57