2016/06/30
ECCUBE2.13
備忘録です。
管理画面に「おすすめ商品2」の入力欄追加とブロックを作成します。
DBに以下を追加します。
INSERT INTO mtb_constants (id, rank, name, remarks) VALUES ('RECOMMEND_NUM2', (SELECT max(rank)+1 FROM mtb_constants), 3, 'おすすめ商品表示数2');
INSERT INTO dtb_bloc (device_type_id, bloc_id, bloc_name, tpl_path, filename, create_date, update_date, php_path, deletable_flg, plugin_id) VALUES (10, (SELECT max(bloc_id)+1 FROM dtb_bloc WHERE device_type_id = 10), 'おすすめ商品(2)', 'recommend2.tpl', 'recommend2', now(), now(), 'frontparts/bloc/recommend2.php', 0, NULL);
INSERT INTO dtb_csv (no, csv_id, col, disp_name, rank, rw_flg, status, create_date, update_date, mb_convert_kana_option, size_const_type, error_check_types)
VALUES (nextval('dtb_csv_no_seq'), 5, 'rcmd2_id', 'おすすめ商品ID-2', NULL, 1, 2, now(), now(), 'n', 'INT_LEN', 'NUM_CHECK,MAX_LENGTH_CHECK');
INSERT INTO dtb_csv (no, csv_id, col, disp_name, rank, rw_flg, status, create_date, update_date, mb_convert_kana_option, size_const_type, error_check_types)
VALUES (nextval('dtb_csv_no_seq'), 5, 'rcmd2_text', 'おすすめコメント2', NULL, 1, 2, now(), now(), 'KVa', 'LTEXT_LEN', 'MAX_LENGTH_CHECK');
【管理画面】
SC_Helper_BestProducts_Ex.php
{
public static $arrRcmdBlocks = array(
array('name' => 'オススメ商品管理', 'num' => RECOMMEND_NUM),
array('name' => 'オススメ商品(2)管理', 'num' => RECOMMEND_NUM2),
);
/**
* おすすめ商品の削除.
*
* @param integer $best_id おすすめ商品ID
* @return void
*/
public function deleteBestProducts($best_id)
{
// ここではランクを意識せずに削除
// ※ランク付きレコードの削除では他のブロックのおすすめ商品が繰り上がってきてしまうため
$objQuery =& SC_Query_Ex::getSingletonInstance();
$objQuery->delete('dtb_best_products', 'best_id = ?', array($best_id));
}
/**
* おすすめ商品一覧の取得.
*
* @param integer $block_id ブロックID
* @return array
*/
public function getProductsByBlock($block_id = 0)
{
$arrProducts = array();
if(($block_id >= 0) && ($block_id < count(self::$arrRcmdBlocks))){
$objQuery =& SC_Query_Ex::getSingletonInstance();
$objProduct = new SC_Product_Ex();
$start_rank = 1;
for($idx = 0; $idx < $block_id; $idx++){
$start_rank += self::$arrRcmdBlocks[$idx]['num'];
}
$end_rank = $start_rank + self::$arrRcmdBlocks[$block_id]['num'] - 1;
// 商品取得
$col = 'best_id, category_id, rank, product_id, title, comment, create_date, update_date';
$table = 'dtb_best_products';
$where = 'del_flg = 0 AND rank >= ? AND rank <= ?';
$objQuery->setOrder('rank');
$objQuery->setLimitOffset(self::$arrRcmdBlocks[$block_id]['num']);
$arrProducts = $objQuery->select($col, $table, $where, array($start_rank, $end_rank));
$objQuery =& SC_Query_Ex::getSingletonInstance();
if (count($arrProducts) > 0) {
// 商品一覧を取得
// where条件生成&セット
$arrProductId = array();
$where = 'product_id IN (';
foreach ($arrProducts as $key => $val) {
$arrProductId[] = $val['product_id'];
}
// 取得
$arrTmp = $objProduct->getListByProductIds($objQuery, $arrProductId);
foreach ($arrTmp as $key => $arrRow) {
$arrProductList[$arrRow['product_id']] = $arrRow;
}
// 商品情報にマージ
foreach (array_keys($arrProducts) as $key) {
$arrRow =& $arrProducts[$key];
if (isset($arrProductList[$arrRow['product_id']])) {
$arrRow = array_merge($arrRow, $arrProductList[$arrRow['product_id']]);
} else {
// 削除済み商品は除外
unset($arrProducts[$key]);
}
}
}
}
return $arrProducts;
}
}
LC_Page_Admin_Contents_Recommend_Ex.php
{
/**
* Page を初期化する.
*
* @return void
*/
function init()
{
parent::init();
$this->arrRcmdBlocks = SC_Helper_BestProducts_Ex::$arrRcmdBlocks;
//最大登録数の表示
$this->tpl_disp_max = 0;
foreach($this->arrRcmdBlocks as $val){
$this->tpl_disp_max += $val[num];
}
}
/**
* Page のプロセス.
*
* @return void
*/
function process()
{
parent::process();
}
/**
* Page のアクション.
*
* @return void
*/
function action() {
parent::action();
}
/**
* パラメーターの初期化を行う
* @param Object $objFormParam
*/
public function lfInitParam(&$objFormParam)
{
$objFormParam->addParam('おすすめ商品ID', 'best_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
$objFormParam->addParam('商品ID', 'product_id', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
$objFormParam->addParam('カテゴリID', 'category_id', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
$objFormParam->addParam('ランク', 'rank', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
$objFormParam->addParam('コメント', 'comment', LTEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK'));
}
}
recommend.tpl
<script type="text/javascript">
function lfnCheckSubmit( fm ){
var err = '';
if ( ! fm["product_id"].value ){
err += '商品を選択して下さい。';
}
/*
if ( fm["comment"] && !fm["comment"].value ){
if ( err ) err += '';
err += 'コメントを入力して下さい。';
}
*/
if ( err ){
alert(err);
return false;
} else {
if(window.confirm('内容を登録しても宜しいですか')){
fm.submit();
return true;
}
}
}
function lfnCheckSetItem( rank ){
var flag = true;
var checkRank = '<!--{$checkRank|h}-->';
if ( checkRank ){
if ( rank != checkRank ){
if( ! window.confirm('さきほど選択したおすすめ商品(<!--{$checkRank|h}-->)の情報は破棄されます。宜しいでしょうか')){
flag = false;
}
}
}
if ( flag ){
eccube.openWindow('./recommend_search.php?rank=' + rank,'search','615','600',{menubar:'no'});
}
}
function lfnSortItem(mode,data){
var flag = true;
var checkRank = '<!--{$checkRank|h}-->';
if ( checkRank ){
if( ! window.confirm('さきほど選択した<!--{$checkRank|h}-->位の情報は破棄されます。宜しいでしょうか')){
flag = false;
}
}
if ( flag ){
document.form1["mode"].value = mode;
document.form1["best_id"].value = data;
document.form1.submit();
}
}
</script>
<div id="admin-contents" class="contents-main">
<!--{section name=cnt loop=$tpl_disp_max}-->
<!--{if $smarty.section.cnt.first}-->
<!--{foreach from=$arrRcmdBlocks key=key item=val name=blk}-->
<!--{if $smarty.foreach.blk.first}--><ul style="margin:0 0 20px; line-height:1.7em;"><!--{/if}-->
<li><a href="#blk<!--{$smarty.foreach.blk.index}-->"><!--{$val.name}--></a></li>
<!--{if $smarty.foreach.blk.last}--></ul><!--{/if}-->
<!--{/foreach}-->
<!--{assign var="block_idx" value=0}-->
<!--{assign var="block_num" value=1}-->
<!--{assign var="block_limit" value=1}-->
<!--{/if}-->
<!--{if $block_num == $block_limit}-->
<h3 style="border:solid 1px #ccc; margin: 0 0 10px;"><a name="blk<!--{$block_idx}-->" name="blk<!--{$block_idx}-->"></a><!--{$arrRcmdBlocks[$block_idx].name}--></h3>
<!--{assign var="block_limit" value=$block_limit+$arrRcmdBlocks[$block_idx].num}-->
<!--{assign var="block_idx" value=$block_idx+1}-->
<!--{/if}-->
<div class="recommend-product <!--{if $arrItems[$smarty.section.cnt.iteration].status == "2"}-->hidden<!--{/if}-->">
<table class="list center recommend-table">
<col width="13%" />
<col width="73%" />
<col width="7%" />
<col width="7%" />
<tr>
<th>順位</th>
<th>商品/コメント</th>
<th>編集</th>
<th>削除</th>
<th>並び替え</th>
</tr>
<tr>
<td>おすすめ商品(<!--{$smarty.section.cnt.iteration}-->)</td>
<!--{if $arrItems[$smarty.section.cnt.iteration].product_id}-->
<td>
<div class="clearfix table-wrap">
<div class="table-img">
<!--{if $arrItems[$smarty.section.cnt.iteration].product_id}-->
<img src="<!--{$smarty.const.IMAGE_SAVE_URLPATH}--><!--{$arrItems[$smarty.section.cnt.iteration].main_list_image|sfNoImageMainList|h}-->" alt="<!--{$arrItems[$smarty.section.cnt.iteration].name|h}-->" width="100" height="100" />
<!--{/if}-->
</div>
<div class="table-detail">
<div class="detail-name">
商品名: <!--{$arrItems[$smarty.section.cnt.iteration].name|h}-->
</div>
<div class="detail-form">
<form name="form<!--{$smarty.section.cnt.iteration}-->" id="form<!--{$smarty.section.cnt.iteration}-->" method="post" action="?">
<input type="hidden" name="<!--{$smarty.const.TRANSACTION_ID_NAME}-->" value="<!--{$transactionid}-->" />
<input type="hidden" name="mode" value="regist" />
<input type="hidden" name="best_id" value="<!--{$arrItems[$smarty.section.cnt.iteration].best_id|h}-->" />
<input type="hidden" name="product_id" value="<!--{$arrItems[$smarty.section.cnt.iteration].product_id|h}-->" />
<input type="hidden" name="category_id" value="<!--{$category_id|h}-->" />
<input type="hidden" name="rank" value="<!--{$arrItems[$smarty.section.cnt.iteration].rank|h}-->" />
<span class="attention"><!--{$arrErr[$smarty.section.cnt.iteration].comment}--></span>
<textarea class="top" name="comment" cols="45" rows="4" style="width: 586px; height: 80px; <!--{$arrErr[$smarty.section.cnt.iteration].comment|sfGetErrorColor}-->" <!--{$arrItems[$smarty.section.cnt.iteration].product_id|sfGetEnabled}-->><!--{"\n"}--><!--{$arrItems[$smarty.section.cnt.iteration].comment|h}--></textarea>
</form>
</div>
</div>
</div>
</td>
<!--{else}-->
<td class="AlignLeft">
<a class="btn-action-m" href="javascript:;" onclick="lfnCheckSetItem('<!--{$smarty.section.cnt.iteration}-->'); return false;" target="_blank"><span class="btn-next">商品を選択する</span></a>
<form name="form<!--{$smarty.section.cnt.iteration}-->" id="form<!--{$smarty.section.cnt.iteration}-->" method="post" action="?">
<input type="hidden" name="<!--{$smarty.const.TRANSACTION_ID_NAME}-->" value="<!--{$transactionid}-->" />
<input type="hidden" name="mode" value="regist" />
<input type="hidden" name="best_id" value="<!--{$arrItems[$smarty.section.cnt.iteration].best_id|h}-->" />
<input type="hidden" name="product_id" value="<!--{$arrItems[$smarty.section.cnt.iteration].product_id|h}-->" />
<input type="hidden" name="category_id" value="<!--{$category_id|h}-->" />
<input type="hidden" name="rank" value="<!--{$arrItems[$smarty.section.cnt.iteration].rank|h}-->" />
</form>
</td>
<!--{/if}-->
<td>
<!--{if $arrItems[$smarty.section.cnt.iteration].product_id}-->
<a href="javascript:;" onclick="lfnCheckSetItem('<!--{$smarty.section.cnt.iteration}-->'); return false;" target="_blank">
編集
</a>
<!--{else}-->
- -
<!--{/if}-->
</td>
<td>
<!--{if $arrItems[$smarty.section.cnt.iteration].product_id}-->
<a href="javascript:;" onclick="return eccube.insertValueAndSubmit( document.form<!--{$smarty.section.cnt.iteration}-->, 'mode', 'delete', '削除します。宜しいですか' )">削除</a>
<!--{else}-->
- -
<!--{/if}-->
</td>
<td>
<!--{* 移動 *}-->
<!--{if $smarty.section.cnt.iteration != 1 && $arrItems[$smarty.section.cnt.iteration].product_id}-->
<a href="?" onclick="lfnSortItem('up',<!--{$arrItems[$smarty.section.cnt.iteration].best_id}-->); return false;">上へ</a><br />
<!--{/if}-->
<!--{if $smarty.section.cnt.iteration != $tpl_disp_max && $arrItems[$smarty.section.cnt.iteration].product_id}-->
<a href="?" onclick="lfnSortItem('down',<!--{$arrItems[$smarty.section.cnt.iteration].best_id}-->); return false;">下へ</a>
<!--{/if}-->
</td>
</tr>
</table>
<div class="btn-area">
<a class="btn-action" href="javascript:;" onclick="lfnCheckSubmit(document.form<!--{$smarty.section.cnt.iteration}-->); return false;"><span class="btn-next">この内容で登録する</span></a>
</div>
</div>
<!--▲おすすめ商品<!--{$smarty.section.cnt.iteration}-->-->
<!--{assign var="block_num" value=$block_num+1}-->
<!--{/section}-->
</div>
これでコンテンツ管理>おすすめ商品管理にオススメ商品(2)管理が表示されます。
【フロント】
LC_Page_FrontParts_Bloc_Recommend2_Ex.phpを追加
require_once CLASS_REALDIR . 'pages/frontparts/bloc/LC_Page_FrontParts_Bloc_Recommend.php';
/**
* Recommend のページクラス(拡張).
*
* LC_Page_FrontParts_Bloc_Recommend をカスタマイズする場合はこのクラスを編集する.
*
* @package Page
* @author LOCKON CO.,LTD.
* @version $Id: LC_Page_FrontParts_Bloc__Ex.php -1 $
*/
class LC_Page_FrontParts_Bloc_Recommend2_Ex extends LC_Page_FrontParts_Bloc_Recommend
{
/**
* Page を初期化する.
*
* @return void
*/
function init()
{
parent::init();
}
/**
* Page のプロセス.
*
* @return void
*/
function process()
{
parent::process();
}
/**
* おすすめ商品検索.
*
* @return array $arrBestProducts 検索結果配列
*/
public function lfGetRanking()
{
$objRecommend = new SC_Helper_BestProducts_Ex();
// おすすめ商品取得
$arrRecommends = $objRecommend->getProductsByBlock(1);
return $arrRecommends;
}
}
recommend2.tplを追加
<!--{strip}-->
<!--{if count($arrBestProducts) > 0}-->
<div class="block_outer clearfix">
<div id="recommend_area">
<h2>おすすめ商品(2)</h2>
<div class="block_body clearfix">
<!--{foreach from=$arrBestProducts item=arrProduct name="recommend_products"}-->
<div class="product_item clearfix">
<div class="productImage">
<a href="<!--{$smarty.const.HTTP_URL}-->products/detail<!--{$arrProduct.product_id|u}-->.html">
<img src="<!--{$smarty.const.IMAGE_SAVE_URLPATH}--><!--{$arrProduct.main_list_image|sfNoImageMainList|h}-->" style="max-width: 80px;max-height: 80px;" alt="<!--{$arrProduct.name|h}-->" />
</a>
</div>
<div class="productContents">
<h3>
<a href="<!--{$smarty.const.HTTP_URL}-->products/detail<!--{$arrProduct.product_id|u}-->.html"><!--{$arrProduct.name|h}--></a>
</h3>
<p class="sale_price">
<!--{$smarty.const.SALE_PRICE_TITLE}-->(税込): <span class="price"><!--{$arrProduct.price02_min_inctax|number_format}--> 円</span>
</p>
<p class="mini comment"><!--{$arrProduct.comment|h|nl2br}--></p>
</div>
</div>
<!--{if $smarty.foreach.recommend_products.iteration % 2 === 0}-->
<div class="clear"></div>
<!--{/if}-->
<!--{/foreach}-->
</div>
</div>
</div>
<!--{/if}-->
<!--{/strip}-->
html/frontparts/bloc/recommend2.phpを追加
require_once realpath(dirname(__FILE__)) . '/../../require.php'; require_once CLASS_EX_REALDIR . 'page_extends/frontparts/bloc/LC_Page_FrontParts_Bloc_Recommend2_Ex.php'; $objPage = new LC_Page_FrontParts_Bloc_Recommend2_Ex(); $objPage->blocItems = $params['items']; $objPage->init(); $objPage->process();
ブロックに「おすすめ商品(2)」が追加されます。
商品を追加して表示を確認後、CSSで調整して完了です。
ゼヒトモ内でのプロフィール: ROCKSTREAM, ゼヒトモのホームページ作成・制作サービス, 仕事をお願いしたい依頼者と様々な「プロ」をつなぐサービス
2025/01/31
JQuery
2025/01/01
神社
御朱印
相模原
2024/10/27
ブラウザ
カスタム投稿
Wordpress
2024/08/20
神社
御朱印
2024/07/06
神社
御朱印