Calendar

<< 3月  
 123
45678910
11121314151617
18192021222324
25262728293031

Mobile

  • EC-CUBE 商品項目を追加する
  • 2015.07.16
  • ECCUBEの管理画面で商品項目を追加する方法をまとめます。
    今回は「comment7」「comment8」という項目を作ることにします。

    ECCUBEバージョン:2.13.3

    1)「dtb_products」に「comment7」「comment8」というカラムを追加する。
    comment6までは既に存在するので、comment6の次にcomment6と同じ属性で追加します。

    2)/data/class/pages/admin/products/LC_Page_Admin_Products_Product.php変更

    (2-1)lfInitFormParam関数内のループ処理ではない所に下記を追加

    $objFormParam->addParam(‘コメント7’, ‘comment7’, MTEXT_LEN, ‘KVa’, array(‘SPTAB_CHECK’, ‘MAX_LENGTH_CHECK’));
    $objFormParam->addParam(‘コメント8’, ‘comment8’, MTEXT_LEN, ‘KVa’, array(‘SPTAB_CHECK’, ‘MAX_LENGTH_CHECK’));

    この追加項目は必須入力項目ではない為「EXIST_CHECK」は外しています。

    (2-2)lfRegistProduct関数内にcomment7とcomment8を追加

    【変更後】
    // 配列の添字を定義
    $checkArray = array(‘name’, ‘status’,
    ‘main_list_comment’, ‘main_comment’,
    ‘deliv_fee’, ‘comment1’, ‘comment2’, ‘comment3’,
    ‘comment4’, ‘comment5’, ‘comment6’,
    ‘comment7’, ‘comment8’,
    ‘sale_limit’, ‘deliv_date_id’, ‘maker_id’, ‘note’);

    // INSERTする値を作成する。
    $sqlval[‘comment7’] = $arrList[‘comment7’];
    $sqlval[‘comment8’] = $arrList[‘comment8’];

    3)管理画面のテンプレートの該当箇所に「comment7」と「comment8」の入力欄を作成

    ●変更ファイル
    /data/Smarty/templates/admin/products/product.tpl

    <tr>
    <th>コメント7<span class="attention"> </span></th>
    <td>
    <span class="attention"><!–{$arrErr.comment7}–></span>
    <input type="text" name="comment7" value="<!–{$arrForm.comment7|h}–>" maxlength="<!–{$smarty.const.STEXT_LEN}–>" style="<!–{if $arrErr.comment7 != ""}–>background-color: <!–{$smarty.const.ERR_COLOR}–>;<!–{/if}–>" size="60" class="box60" />
    <span class="attention"> (上限<!–{$smarty.const.MTEXT_LEN}–>文字)</span>
    </td>
    </tr>
    <tr>
    <th>コメント8<span class="attention"> </span></th>
    <td>
    <span class="attention"><!–{$arrErr.comment8}–></span>
    <input type="text" name="comment8" value="<!–{$arrForm.comment8|h}–>" maxlength="<!–{$smarty.const.STEXT_LEN}–>" style="<!–{if $arrErr.comment8 != ""}–>background-color: <!–{$smarty.const.ERR_COLOR}–>;<!–{/if}–>" size="60" class="box60" />
    <span class="attention"> (上限<!–{$smarty.const.MTEXT_LEN}–>文字)</span>
    </td>
    </tr>

    上限文字数はlfInitFormParam関数内で設定した「MTEXT_LEN」と連動しています。

    ●変更ファイル
    /data/Smarty/templates/admin/products/confirm.tpl

    <tr>
    <th>サイズ</th>
    <td><!–{$arrForm.comment7|h}–></td>
    </tr>
    <tr>
    <th>カラー</th>
    <td><!–{$arrForm.comment8|h}–></td>
    </tr>

    4)商品一覧や商品詳細といった表示側のテンプレートに表示用の記述を追加
    今回は商品詳細ページのみに追加しました。

    ●変更ファイル
    /data/Smarty/templates/default/products/detail.tpl

    <!–★コメント7★–>
    <div>
    <span class="product_w2">コメント7</span><!–{$arrProduct.comment7|h}–>
    </div>

    <div>
    <!–★コメント8★–>
    <span class="product_w2">コメント8</span><!–{$arrProduct.comment8|h}–>
    </div>

    ※CSSはサイトに合わせて適宜変更する必要があります。

    ★ここまでで、商品項目の追加と追加した項目を表示する事が出来るようになりました。

    5)登録商品をCSVでエクスポートしたりインポートする場合は今回追加した項目分を追加する

    「dtb_csv」に「comment7」「comment8」というカラムを追加する。

    comment7で重要な部分は下記のように登録しました。
    no…160
    csv_id…1
    col…comment7
    disp_name…コメント7
    rank…72
    mb_convert_kana_option…KVa
    size_const_type…MTEXT_LEN
    error_check_types…SPTAB_CHECK,MAX_LENGTH_CHECK

    noはユニークキーなので、元々登録されているnoの最大値に1をプラスした数値で
    rankはCSV項目の順番です。
    その他はlfInitFormParam関数内の項目と同じ様な値を登録します。

    以上で商品項目の追加方法が全てだったと思います。

【この記事のタグ】

コメントを残す

メールアドレスが公開されることはありません。

▲ PAGE TOP