2016/05/23
ECCUBE2.13
今回のカスタムでは、クライアントさんから、
もうひとつ別で商品ステータスが増やせないかという要望がありました。
しかし、ステータスアイコンの追加方法については、
いろいろと検索でヒットしますが、
別で商品ステータスを用意するカスタムについては全く見つかりませんでした。
そこで、過去にプログラマーさんに依頼したカスタマイズを参考にして、
自分で商品ステータス2を実装しました。
カスタムは2.13.5です。
カスタマイズイメージ
※画像では通常のステータスが商品ステータス2になっています。

以下のファイルをカスタマイズします。
管理画面
・SC_Products.php
・LC_Page_Admin_Products_Product.php
・product.tpl
・confirm.tpl
フロント
・LC_Page_Products_Detail.php
・LC_Page_Products_list.php
・detail.tpl
・list.tpl
説明しやすいようにclassファイルにしていますが、
実際には、class_exファイルをカスタムしました。
【DB】
dtb_product_status2を追加
CREATE TABLE IF NOT EXISTS `dtb_product_status2` ( `status2_id` smallint(6) NOT NULL, `product_id` int(11) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; ALTER TABLE `dtb_product_status2` ADD PRIMARY KEY (`status2_id`); ADD PRIMARY KEY (`product_id`);
mtb_status2を追加
CREATE TABLE IF NOT EXISTS `mtb_status2` ( `id` smallint(6) NOT NULL DEFAULT '0', `name` text, `rank` smallint(6) NOT NULL DEFAULT '0' ) ENGINE=InnoDB DEFAULT CHARSET=utf8; ALTER TABLE `mtb_status2` ADD PRIMARY KEY (`id`);
mtb_status_image2を追加
CREATE TABLE IF NOT EXISTS `mtb_status_image2` ( `id` smallint(6) NOT NULL DEFAULT '0', `name` text, `rank` smallint(6) NOT NULL DEFAULT '0' ) ENGINE=InnoDB DEFAULT CHARSET=utf8; ALTER TABLE `mtb_status_image2` ADD PRIMARY KEY (`id`);
【管理画面ファイルのカスタマイズ】
data/class/SC_Product.php
商品ステータス2の箇所を追加
/**
* 商品IDをキーにした, 商品ステータスIDの配列を取得する.
*
* @param array 商品ID の配列
* @return array 商品IDをキーにした商品ステータスIDの配列
*/
public function getProductStatus($productIds)
{
if (empty($productIds)) {
return array();
}
$objQuery =& SC_Query_Ex::getSingletonInstance();
$cols = 'product_id, product_status_id';
$from = 'dtb_product_status';
$where = 'del_flg = 0 AND product_id IN (' . SC_Utils_Ex::repeatStrWithSeparator('?', count($productIds)) . ')';
$productStatus = $objQuery->select($cols, $from, $where, $productIds);
$results = array();
foreach ($productStatus as $status) {
$results[$status['product_id']][] = $status['product_status_id'];
}
return $results;
}
/**
* 商品IDをキーにした, 商品ステータス2のIDの配列を取得する.
*
* @param array 商品ID の配列
* @return array 商品IDをキーにした商品ステータス2のIDの配列
*/
function getProductStatus2($productIds) {
if (empty($productIds)) {
return array();
}
$objQuery =& SC_Query_Ex::getSingletonInstance();
$cols = 'product_id, status2_id';
$from = 'dtb_product_status2';
$where = 'product_id IN (' . SC_Utils_Ex::repeatStrWithSeparator('?', count($productIds)) . ')';
$productStatus = $objQuery->select($cols, $from, $where, $productIds);
$results = array();
foreach ($productStatus as $status) {
$results[$status['product_id']][] = $status['status2_id'];
}
return $results;
}
/**
* 商品ステータスを設定する.
*
* TODO 現在は DELETE/INSERT だが, UPDATE を検討する.
*
* @param integer $productId 商品ID
* @param array $productStatusIds ON にする商品ステータスIDの配列
*/
public function setProductStatus($productId, $productStatusIds)
{
$val['product_id'] = $productId;
$val['creator_id'] = $_SESSION['member_id'];
$val['create_date'] = 'CURRENT_TIMESTAMP';
$val['update_date'] = 'CURRENT_TIMESTAMP';
$val['del_flg'] = '0';
$objQuery =& SC_Query_Ex::getSingletonInstance();
$objQuery->delete('dtb_product_status', 'product_id = ?', array($productId));
foreach ($productStatusIds as $productStatusId) {
if ($productStatusId == '') continue;
$val['product_status_id'] = $productStatusId;
$objQuery->insert('dtb_product_status', $val);
}
}
/**
* 商品ステータス2を設定する.
*
* @param integer $productId 商品ID
* @param array $productStatusIds ON にする商品ステータス2のIDの配列
*/
function setProductStatus2($productId, $productStatusIds, &$objQuery=null) {
$cmt = 0;
if($objQuery == null){
$objQuery =& SC_Query_Ex::getSingletonInstance();
$objQuery->begin();
$cmt = 1;
}
$val['product_id'] = $productId;
$objQuery =& SC_Query_Ex::getSingletonInstance();
$objQuery->delete('dtb_product_status2', 'product_id = ?', array($productId));
foreach ($productStatusIds as $statusId) {
if ($statusId == '') continue;
$val['status2_id'] = $statusId;
$objQuery->insert('dtb_product_status2', $val);
}
if($cmt){
$objQuery->commit();
}
}
data/class/pages/admin/products/LC_Page_Admin_Products_Product.php
商品ステータス2を追加
/**
* Page を初期化する.
*
* @return void
*/
public function init()
{
parent::init();
$this->tpl_mainpage = 'products/product.tpl';
$this->tpl_mainno = 'products';
$this->tpl_subno = 'product';
$this->tpl_maintitle = '商品管理';
$this->tpl_subtitle = '商品登録';
$masterData = new SC_DB_MasterData_Ex();
$this->arrProductType = $masterData->getMasterData('mtb_product_type');
$this->arrDISP = $masterData->getMasterData('mtb_disp');
$this->arrSTATUS = $masterData->getMasterData('mtb_status');
$this->arrSTATUS_IMAGE = $masterData->getMasterData('mtb_status_image');
/*## 商品ステータス2を追加 ADD BEGIN ##*/
$this->arrSTATUS2 = $masterData->getMasterData('mtb_status2');
$this->arrSTATUS_IMAGE2 = $masterData->getMasterData('mtb_status_image2');
/*## 商品ステータス2を追加 ADD END ##*/
$this->arrDELIVERYDATE = $masterData->getMasterData('mtb_delivery_date');
$this->arrMaker = SC_Helper_Maker_Ex::getIDValueList();
$this->arrAllowedTag = $masterData->getMasterData('mtb_allowed_tag');
}
(中略)
/**
* パラメーター情報の初期化
*
* @param SC_FormParam_Ex $objFormParam SC_FormParamインスタンス
* @param array $arrPost $_POSTデータ
* @return void
*/
public function lfInitFormParam(&$objFormParam, $arrPost)
{
$objFormParam->addParam('商品ID', 'product_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
$objFormParam->addParam('商品名', 'name', STEXT_LEN, 'KVa', array('EXIST_CHECK', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
$objFormParam->addParam('商品カテゴリ', 'category_id', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
$objFormParam->addParam('公開・非公開', 'status', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
$objFormParam->addParam('商品ステータス', 'product_status', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
/*## 商品ステータス2を追加 ADD BEGIN ##*/
$objFormParam->addParam('商品ステータス2', 'product_status2', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
/*## 商品ステータス2を追加 ADD END ##*/
if (!$arrPost['has_product_class']) {
// 新規登録, 規格なし商品の編集の場合
$objFormParam->addParam('商品種別', 'product_type_id', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
$objFormParam->addParam('ダウンロード商品ファイル名', 'down_filename', STEXT_LEN, 'KVa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
$objFormParam->addParam('ダウンロード商品実ファイル名', 'down_realfilename', MTEXT_LEN, 'KVa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
$objFormParam->addParam('temp_down_file', 'temp_down_file', '', '', array());
$objFormParam->addParam('save_down_file', 'save_down_file', '', '', array());
$objFormParam->addParam('商品コード', 'product_code', STEXT_LEN, 'KVa', array('EXIST_CHECK', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
$objFormParam->addParam(NORMAL_PRICE_TITLE, 'price01', PRICE_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK', 'ZERO_START'));
$objFormParam->addParam(SALE_PRICE_TITLE, 'price02', PRICE_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK', 'ZERO_START'));
if (OPTION_PRODUCT_TAX_RULE) {
$objFormParam->addParam('消費税率', 'tax_rate', PERCENTAGE_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
}
$objFormParam->addParam('在庫数', 'stock', AMOUNT_LEN, 'n', array('SPTAB_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK', 'ZERO_START'));
$objFormParam->addParam('在庫無制限', 'stock_unlimited', INT_LEN, 'n', array('SPTAB_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
}
$objFormParam->addParam('商品送料', 'deliv_fee', PRICE_LEN, 'n', array('NUM_CHECK', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK', 'ZERO_START'));
$objFormParam->addParam('ポイント付与率', 'point_rate', PERCENTAGE_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK', 'ZERO_START'));
$objFormParam->addParam('発送日目安', 'deliv_date_id', INT_LEN, 'n', array('NUM_CHECK'));
$objFormParam->addParam('販売制限数', 'sale_limit', AMOUNT_LEN, 'n', array('SPTAB_CHECK', 'ZERO_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK', 'ZERO_START'));
$objFormParam->addParam('メーカー', 'maker_id', INT_LEN, 'n', array('NUM_CHECK'));
$objFormParam->addParam('メーカーURL', 'comment1', URL_LEN, 'a', array('SPTAB_CHECK', 'URL_CHECK', 'MAX_LENGTH_CHECK'));
$objFormParam->addParam('検索ワード', 'comment3', LLTEXT_LEN, 'KVa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
$objFormParam->addParam('備考欄(SHOP専用)', 'note', LLTEXT_LEN, 'KVa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
$objFormParam->addParam('一覧-メインコメント', 'main_list_comment', MTEXT_LEN, 'KVa', array('EXIST_CHECK', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
$objFormParam->addParam('詳細-メインコメント', 'main_comment', LLTEXT_LEN, 'KVa', array('EXIST_CHECK', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
$objFormParam->addParam('save_main_list_image', 'save_main_list_image', '', '', array());
$objFormParam->addParam('save_main_image', 'save_main_image', '', '', array());
$objFormParam->addParam('save_main_large_image', 'save_main_large_image', '', '', array());
$objFormParam->addParam('temp_main_list_image', 'temp_main_list_image', '', '', array());
$objFormParam->addParam('temp_main_image', 'temp_main_image', '', '', array());
$objFormParam->addParam('temp_main_large_image', 'temp_main_large_image', '', '', array());
for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
$objFormParam->addParam('詳細-サブタイトル' . $cnt, 'sub_title' . $cnt, STEXT_LEN, 'KVa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
$objFormParam->addParam('詳細-サブコメント' . $cnt, 'sub_comment' . $cnt, LLTEXT_LEN, 'KVa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
$objFormParam->addParam('save_sub_image' . $cnt, 'save_sub_image' . $cnt, '', '', array());
$objFormParam->addParam('save_sub_large_image' . $cnt, 'save_sub_large_image' . $cnt, '', '', array());
$objFormParam->addParam('temp_sub_image' . $cnt, 'temp_sub_image' . $cnt, '', '', array());
$objFormParam->addParam('temp_sub_large_image' . $cnt, 'temp_sub_large_image' . $cnt, '', '', array());
}
for ($cnt = 1; $cnt <= RECOMMEND_PRODUCT_MAX; $cnt++) {
$objFormParam->addParam('関連商品コメント' . $cnt, 'recommend_comment' . $cnt, LTEXT_LEN, 'KVa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
$objFormParam->addParam('関連商品ID' . $cnt, 'recommend_id' . $cnt, INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
$objFormParam->addParam('recommend_delete' . $cnt, 'recommend_delete' . $cnt, '', 'n', array());
}
$objFormParam->addParam('商品ID', 'copy_product_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
$objFormParam->addParam('has_product_class', 'has_product_class', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
$objFormParam->addParam('product_class_id', 'product_class_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
$objFormParam->setParam($arrPost);
$objFormParam->convParam();
}
(中略)
/**
* DBから商品データを取得する
*
* @param integer $product_id 商品ID
* @return string 商品データ配列
*/
public function lfGetProductData_FromDB($product_id)
{
$objQuery =& SC_Query_Ex::getSingletonInstance();
$arrProduct = array();
// 商品データ取得
$col = '*';
$table = <<< __EOF__
dtb_products AS T1
LEFT JOIN (
SELECT product_id AS product_id_sub,
product_code,
price01,
price02,
deliv_fee,
stock,
stock_unlimited,
sale_limit,
point_rate,
product_type_id,
down_filename,
down_realfilename
FROM dtb_products_class
) AS T2
ON T1.product_id = T2.product_id_sub
__EOF__;
$where = 'product_id = ?';
$objQuery->setLimit('1');
$arrProduct = $objQuery->select($col, $table, $where, array($product_id));
// カテゴリID取得
$col = 'category_id';
$table = 'dtb_product_categories';
$where = 'product_id = ?';
$objQuery->setOption('');
$arrProduct[0]['category_id'] = $objQuery->getCol($col, $table, $where, array($product_id));
// 規格情報ありなしフラグ取得
$objDb = new SC_Helper_DB_Ex();
$arrProduct[0]['has_product_class'] = $objDb->sfHasProductClass($product_id);
// 規格が登録されていなければ規格ID取得
if ($arrProduct[0]['has_product_class'] == false) {
$arrProduct[0]['product_class_id'] = SC_Utils_Ex::sfGetProductClassId($product_id, '0', '0');
}
// 商品ステータス取得
$objProduct = new SC_Product_Ex();
$productStatus = $objProduct->getProductStatus(array($product_id));
$arrProduct[0]['product_status'] = $productStatus[$product_id];
/*## 商品ステータス2を追加 ADD BEGIN ##*/
$objProduct = new SC_Product_Ex();
$productStatus2 = $objProduct->getProductStatus2(array($product_id));
$arrProduct[0]['product_status2'] = $productStatus2[$product_id];
/*## 商品ステータス2を追加 ADD END ##*/
// 関連商品データ取得
$arrRecommend = $this->lfGetRecommendProductsData_FromDB($product_id);
$arrProduct[0] = array_merge($arrProduct[0], $arrRecommend);
return $arrProduct[0];
}
(中略)
/**
* DBに商品データを登録する
*
* @param SC_UploadFile_Ex $objUpFile SC_UploadFileインスタンス
* @param SC_UploadFile_Ex $objDownFile SC_UploadFileインスタンス
* @param array $arrList フォーム入力パラメーター配列
* @return integer 登録商品ID
*/
public function lfRegistProduct(&$objUpFile, &$objDownFile, $arrList)
{
$objQuery =& SC_Query_Ex::getSingletonInstance();
$objDb = new SC_Helper_DB_Ex();
// 配列の添字を定義
$checkArray = array('name', 'status',
'main_list_comment', 'main_comment', 'main_comment2', 'main_comment3',
'deliv_fee', 'comment1', 'comment2', 'comment3',
'comment4', 'comment5', 'comment6',
'sale_limit', 'deliv_date_id', 'maker_id', 'note');
$arrList = SC_Utils_Ex::arrayDefineIndexes($arrList, $checkArray);
// INSERTする値を作成する。
$sqlval['name'] = $arrList['name'];
$sqlval['status'] = $arrList['status'];
$sqlval['main_list_comment'] = $arrList['main_list_comment'];
$sqlval['main_comment'] = $arrList['main_comment'];
$sqlval['main_comment2'] = $arrList['main_comment2'];
$sqlval['main_comment3'] = $arrList['main_comment3'];
$sqlval['comment1'] = $arrList['comment1'];
$sqlval['comment2'] = $arrList['comment2'];
$sqlval['comment3'] = $arrList['comment3'];
$sqlval['comment4'] = $arrList['comment4'];
$sqlval['comment5'] = $arrList['comment5'];
$sqlval['comment6'] = $arrList['comment6'];
$sqlval['deliv_date_id'] = $arrList['deliv_date_id'];
$sqlval['maker_id'] = $arrList['maker_id'];
$sqlval['note'] = $arrList['note'];
$sqlval['update_date'] = 'CURRENT_TIMESTAMP';
$sqlval['creator_id'] = $_SESSION['member_id'];
$arrRet = $objUpFile->getDBFileList();
$sqlval = array_merge($sqlval, $arrRet);
for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
$sqlval['sub_title'.$cnt] = $arrList['sub_title'.$cnt];
$sqlval['sub_comment'.$cnt] = $arrList['sub_comment'.$cnt];
}
$objQuery->begin();
// 新規登録(複製時を含む)
if ($arrList['product_id'] == '') {
$product_id = $objQuery->nextVal('dtb_products_product_id');
$sqlval['product_id'] = $product_id;
// INSERTの実行
$sqlval['create_date'] = 'CURRENT_TIMESTAMP';
$objQuery->insert('dtb_products', $sqlval);
$arrList['product_id'] = $product_id;
// カテゴリを更新
$objDb->updateProductCategories($arrList['category_id'], $product_id);
// 複製商品の場合には規格も複製する
if ($arrList['copy_product_id'] != '' && SC_Utils_Ex::sfIsInt($arrList['copy_product_id'])) {
if (!$arrList['has_product_class']) {
//規格なしの場合、複製は価格等の入力が発生しているため、その内容で追加登録を行う
$this->lfCopyProductClass($arrList, $objQuery);
} else {
//規格がある場合の複製は複製元の内容で追加登録を行う
// dtb_products_class のカラムを取得
$dbFactory = SC_DB_DBFactory_Ex::getInstance();
$arrColList = $objQuery->listTableFields('dtb_products_class');
$arrColList_tmp = array_flip($arrColList);
// 複製しない列
unset($arrColList[$arrColList_tmp['product_class_id']]); //規格ID
unset($arrColList[$arrColList_tmp['product_id']]); //商品ID
unset($arrColList[$arrColList_tmp['create_date']]);
// 複製元商品の規格データ取得
$col = SC_Utils_Ex::sfGetCommaList($arrColList);
$table = 'dtb_products_class';
$where = 'product_id = ?';
$objQuery->setOrder('product_class_id');
$arrProductsClass = $objQuery->select($col, $table, $where, array($arrList['copy_product_id']));
// 規格データ登録
$objQuery =& SC_Query_Ex::getSingletonInstance();
foreach ($arrProductsClass as $arrData) {
$sqlval = $arrData;
$sqlval['product_class_id'] = $objQuery->nextVal('dtb_products_class_product_class_id');
$sqlval['deliv_fee'] = $arrList['deliv_fee'];
$sqlval['point_rate'] = $arrList['point_rate'];
$sqlval['sale_limit'] = $arrList['sale_limit'];
$sqlval['product_id'] = $product_id;
$sqlval['create_date'] = 'CURRENT_TIMESTAMP';
$sqlval['update_date'] = 'CURRENT_TIMESTAMP';
$objQuery->insert($table, $sqlval);
}
}
}
// 更新
} else {
$product_id = $arrList['product_id'];
// 削除要求のあった既存ファイルの削除
$arrRet = $this->lfGetProductData_FromDB($arrList['product_id']);
// TODO: SC_UploadFile::deleteDBFileの画像削除条件見直し要
$objImage = new SC_Image_Ex($objUpFile->temp_dir);
$arrKeyName = $objUpFile->keyname;
$arrSaveFile = $objUpFile->save_file;
$arrImageKey = array();
foreach ($arrKeyName as $key => $keyname) {
if ($arrRet[$keyname] && !$arrSaveFile[$key]) {
$arrImageKey[] = $keyname;
$has_same_image = $this->lfHasSameProductImage($arrList['product_id'], $arrImageKey, $arrRet[$keyname]);
if (!$has_same_image) {
$objImage->deleteImage($arrRet[$keyname], $objUpFile->save_dir);
}
}
}
$objDownFile->deleteDBDownFile($arrRet);
// UPDATEの実行
$where = 'product_id = ?';
$objQuery->update('dtb_products', $sqlval, $where, array($product_id));
// カテゴリを更新
$objDb->updateProductCategories($arrList['category_id'], $product_id);
}
// 商品登録の時は規格を生成する。複製の場合は規格も複製されるのでこの処理は不要。
if ($arrList['copy_product_id'] == '') {
// 規格登録
if ($objDb->sfHasProductClass($product_id)) {
// 規格あり商品(商品規格テーブルのうち、商品登録フォームで設定するパラメーターのみ更新)
$this->lfUpdateProductClass($arrList);
} else {
// 規格なし商品(商品規格テーブルの更新)
$arrList['product_class_id'] = $this->lfInsertDummyProductClass($arrList);
}
}
// 商品ステータス設定
$objProduct = new SC_Product_Ex();
$objProduct->setProductStatus($product_id, $arrList['product_status']);
/*## 商品ステータス2を追加 ADD BEGIN ##*/
$objProduct = new SC_Product_Ex();
$objProduct->setProductStatus2($product_id, $arrList['product_status2'], $objQuery);
/*## 商品ステータス2を追加 ADD END ##*/
// 税情報設定
if (OPTION_PRODUCT_TAX_RULE && !$objDb->sfHasProductClass($product_id)) {
SC_Helper_TaxRule_Ex::setTaxRuleForProduct($arrList['tax_rate'], $arrList['product_id'], $arrList['product_class_id']);
}
// 関連商品登録
$this->lfInsertRecommendProducts($objQuery, $arrList, $product_id);
$objQuery->commit();
return $product_id;
}
data/Smarty/templates/admin/products/product.tpl
商品ステータスの下に商品ステータス2を追加
<tr>
<th>商品ステータス</th>
<td>
<!--{html_checkboxes name="product_status" options=$arrSTATUS selected=$arrForm.product_status separator=' '}-->
</td>
</tr>
<tr>
<th>商品ステータス2</th>
<td>
<!--{html_checkboxes name="product_status2" options=$arrSTATUS2 selected=$arrForm.product_status2 separator=' '}-->
</td>
</tr>
data/Smarty/templates/admin/products/confirm.tpl
・上部のforeachに商品ステータス2を追加
・商品ステータスの下に商品ステータス2を追加
<!--{foreach key=key item=item from=$arrSearchHidden}-->
<!--{if is_array($item)}-->
<!--{foreach item=c_item from=$item}-->
<input type="hidden" name="<!--{$key|h}-->[]" value="<!--{$c_item|h}-->" />
<!--{/foreach}-->
<!--{else}-->
<input type="hidden" name="<!--{$key|h}-->" value="<!--{$item|h}-->" />
<!--{/if}-->
<!--{/foreach}-->
<!--{foreach key=key item=item from=$arrForm}-->
<!--{if $key == 'product_status'}-->
<!--{foreach item=statusVal from=$item}-->
<input type="hidden" name="<!--{$key}-->[]" value="<!--{$statusVal|h}-->" />
<!--{/foreach}-->
<!--{*# 商品ステータス2を追加 ADD BEGIN #*}-->
<!--{elseif $key == 'product_status2'}-->
<!--{foreach item=statusVal from=$item}-->
<input type="hidden" name="<!--{$key}-->[]" value="<!--{$statusVal|h}-->" />
<!--{/foreach}-->
<!--{*# 商品ステータス2を追加 ADD END #*}-->
<!--{elseif $key == 'arrCategoryId'}-->
<!--{* nop *}-->
<!--{elseif $key == 'arrFile'}-->
<!--{* nop *}-->
<!--{else}-->
<input type="hidden" name="<!--{$key}-->" value="<!--{$item|h}-->" />
<!--{/if}-->
<!--{/foreach}-->
(中略)
<tr>
<th>商品ステータス</th>
<td>
<!--{foreach from=$arrForm.product_status item=status}-->
<!--{if $status != ""}-->
<img src="<!--{$TPL_URLPATH_PC}--><!--{$arrSTATUS_IMAGE[$status]}-->">
<!--{/if}-->
<!--{/foreach}-->
</td>
</tr>
<tr>
<th>商品ステータス2</th>
<td>
<!--{foreach from=$arrForm.product_status2 item=status}-->
<!--{if $status != ""}-->
<img src="<!--{$TPL_URLPATH_PC}--><!--{$arrSTATUS_IMAGE2[$status]}-->">
<!--{/if}-->
<!--{/foreach}-->
</td>
</tr>
管理画面のシステム設定>マスターデータ管理で
mtb_status2とmtb_status_image2にステータス名とimageを追加してください。
(imageはimg/icon/ico_11.gifなどにするとわかりやすいです)
【フロントのカスタム】
class/pages/products/LC_Page_Products_Detail.php
商品ステータス2を追加
/**
* Page を初期化する.
*
* @return void
*/
function init()
{
parent::init();
$masterData = new SC_DB_MasterData_Ex();
$this->arrSTATUS = $masterData->getMasterData('mtb_status');
$this->arrSTATUS_IMAGE = $masterData->getMasterData('mtb_status_image');
/*## 商品ステータス2を追加 ## ADD BEGIN*/
$this->arrSTATUS2 = $masterData->getMasterData('mtb_status2');
$this->arrSTATUS_IMAGE2 = $masterData->getMasterData('mtb_status_image2');
/*## 商品ステータス2を追加 ADD END ##*/
$this->arrDELIVERYDATE = $masterData->getMasterData('mtb_delivery_date');
$this->arrRECOMMEND = $masterData->getMasterData('mtb_recommend');
// POST に限定する mode
$this->arrLimitPostMode[] = 'cart';
$this->arrLimitPostMode[] = 'add_favorite';
$this->arrLimitPostMode[] = 'add_favorite_sphone';
$this->arrLimitPostMode[] = 'select';
$this->arrLimitPostMode[] = 'select2';
$this->arrLimitPostMode[] = 'selectItem';
}
(中略)
/**
* Page のAction.
*
* @return void
*/
public function action()
{
//決済処理中ステータスのロールバック
$objPurchase = new SC_Helper_Purchase_Ex();
$objPurchase->cancelPendingOrder(PENDING_ORDER_CANCEL_FLAG);
// 会員クラス
$objCustomer = new SC_Customer_Ex();
// パラメーター管理クラス
$this->objFormParam = new SC_FormParam_Ex();
// パラメーター情報の初期化
$this->arrForm = $this->lfInitParam($this->objFormParam);
// ファイル管理クラス
$this->objUpFile = new SC_UploadFile_Ex(IMAGE_TEMP_REALDIR, IMAGE_SAVE_REALDIR);
// ファイル情報の初期化
$this->objUpFile = $this->lfInitFile($this->objUpFile);
$this->mode = $this->getMode();
$objProduct = new SC_Product_Ex();
// プロダクトIDの正当性チェック
$product_id = $this->lfCheckProductId($this->objFormParam->getValue('admin'), $this->objFormParam->getValue('product_id'), $objProduct);
$objProduct->setProductsClassByProductIds(array($product_id));
// 規格1クラス名
$this->tpl_class_name1 = $objProduct->className1[$product_id];
// 規格2クラス名
$this->tpl_class_name2 = $objProduct->className2[$product_id];
// 規格1
$this->arrClassCat1 = $objProduct->classCats1[$product_id];
// 規格1が設定されている
$this->tpl_classcat_find1 = $objProduct->classCat1_find[$product_id];
// 規格2が設定されている
$this->tpl_classcat_find2 = $objProduct->classCat2_find[$product_id];
$this->tpl_stock_find = $objProduct->stock_find[$product_id];
$this->tpl_product_class_id = $objProduct->classCategories[$product_id]['__unselected']['__unselected']['product_class_id'];
$this->tpl_product_type = $objProduct->classCategories[$product_id]['__unselected']['__unselected']['product_type'];
// 在庫が無い場合は、OnLoadしない。(javascriptエラー防止)
if ($this->tpl_stock_find) {
// 規格選択セレクトボックスの作成
$this->js_lnOnload .= $this->lfMakeSelect();
}
$this->tpl_javascript .= 'eccube.classCategories = ' . SC_Utils_Ex::jsonEncode($objProduct->classCategories[$product_id]) . ';';
$this->tpl_javascript .= 'function lnOnLoad()
{' . $this->js_lnOnload . '}';
$this->tpl_onload .= 'lnOnLoad();';
// モバイル用 規格選択セレクトボックスの作成
if (SC_Display_Ex::detectDevice() == DEVICE_TYPE_MOBILE) {
$this->lfMakeSelectMobile($this, $product_id, $this->objFormParam->getValue('classcategory_id1'));
}
// 商品IDをFORM内に保持する
$this->tpl_product_id = $product_id;
switch ($this->mode) {
case 'cart':
$this->doCart();
break;
case 'add_favorite':
$this->doAddFavorite($objCustomer);
break;
case 'add_favorite_sphone':
$this->doAddFavoriteSphone($objCustomer);
break;
case 'select':
case 'select2':
case 'selectItem':
/**
* モバイルの数量指定・規格選択の際に、
* $_SESSION['cart_referer_url'] を上書きさせないために、
* 何もせずbreakする。
*/
break;
default:
$this->doDefault();
break;
}
// モバイル用 ポストバック処理
if (SC_Display_Ex::detectDevice() == DEVICE_TYPE_MOBILE) {
switch ($this->mode) {
case 'select':
$this->doMobileSelect();
break;
case 'select2':
$this->doMobileSelect2();
break;
case 'selectItem':
$this->doMobileSelectItem();
break;
case 'cart':
$this->doMobileCart();
break;
default:
$this->doMobileDefault();
break;
}
}
// 商品詳細を取得
$this->arrProduct = $objProduct->getDetail($product_id);
// サブタイトルを取得
$this->tpl_subtitle = $this->arrProduct['name'];
// 関連カテゴリを取得
$this->arrRelativeCat = SC_Helper_DB_Ex::sfGetMultiCatTree($product_id);
// 商品ステータスを取得
$this->productStatus = $objProduct->getProductStatus($product_id);
/*## 商品ステータス2を追加 ## ADD BEGIN*/
$this->productStatus2 = $objProduct->getProductStatus2($product_id);
/*## 商品ステータス2を追加 ADD END ##*/
// 画像ファイル指定がない場合の置換処理
$this->arrProduct['main_image']
= SC_Utils_Ex::sfNoImageMain($this->arrProduct['main_image']);
$this->subImageFlag = $this->lfSetFile($this->objUpFile, $this->arrProduct, $this->arrFile);
//レビュー情報の取得
$this->arrReview = $this->lfGetReviewData($product_id);
//関連商品情報表示
$this->arrRecommend = $this->lfPreGetRecommendProducts($product_id);
// ログイン判定
if ($objCustomer->isLoginSuccess() === true) {
//お気に入りボタン表示
$this->tpl_login = true;
$this->is_favorite = SC_Helper_DB_Ex::sfDataExists('dtb_customer_favorite_products', 'customer_id = ? AND product_id = ?', array($objCustomer->getValue('customer_id'), $product_id));
}
}
class/pages/products/LC_Page_Products_List.php
商品ステータス2を追加
/**
* Page を初期化する.
*
* @return void
*/
function init()
{
parent::init();
$masterData = new SC_DB_MasterData_Ex();
$this->arrSTATUS = $masterData->getMasterData('mtb_status');
$this->arrSTATUS_IMAGE = $masterData->getMasterData('mtb_status_image');
/*## 商品ステータス2を追加 ## ADD BEGIN*/
$this->arrSTATUS2 = $masterData->getMasterData('mtb_status2');
$this->arrSTATUS_IMAGE2 = $masterData->getMasterData('mtb_status_image2');
/*## 商品ステータス2を追加 ADD END ##*/
$this->arrDELIVERYDATE = $masterData->getMasterData('mtb_delivery_date');
$this->arrPRODUCTLISTMAX = $masterData->getMasterData('mtb_product_list_max');
}
(中略)
/**
* 商品情報配列に商品ステータス情報を追加する
*
* @param Array $arrProducts 商品一覧情報
* @param Array $arrStatus 商品ステータス配列
* @param Array $arrStatusImage スタータス画像配列
* @return Array $arrProducts 商品一覧情報
*/
public function setStatusDataTo($arrProducts, $arrStatus, $arrStatusImage)
{
foreach ($arrProducts['productStatus'] as $product_id => $arrValues) {
for ($i = 0; $i < count($arrValues); $i++) {
$product_status_id = $arrValues[$i];
if (!empty($product_status_id)) {
$arrProductStatus = array(
'status_cd' => $product_status_id,
'status_name' => $arrStatus[$product_status_id],
'status_image' =>$arrStatusImage[$product_status_id],
);
$arrProducts['productStatus'][$product_id][$i] = $arrProductStatus;
}
}
}
return $arrProducts;
}
/**
* 商品情報配列に商品ステータス2情報を追加する
*
* @param Array $arrProducts2 商品一覧情報
* @param Array $arrStatus2 商品ステータス2配列
* @param Array $arrStatusImage2 スタータス画像2配列
* @return Array $arrProducts 商品一覧情報
*/
public function setStatusDataTo($arrProducts, $arrStatus2, $arrStatusImage2)
{
foreach ($arrProducts['productStatus2'] as $product_id => $arrValues) {
for ($i = 0; $i < count($arrValues); $i++) {
$status2_id = $arrValues[$i];
if (!empty($status2_id)) {
$arrProductStatus2 = array(
'status_cd' => $status2_id,
'status_name' => $arrStatus2[$status2_id],
'status_image2' =>$arrStatusImage2[$status2_id],
);
$arrProducts['productStatus2'][$product_id][$i] = $arrProductStatus2;
}
}
}
return $arrProducts;
}
(中略)
/**
*
* @param SC_Product_Ex $objProduct
* @param SC_FormParam_Ex $objFormParam
* @return void
*/
public function doDefault(&$objProduct, &$objFormParam)
{
//商品一覧の表示処理
$strnavi = $this->objNavi->strnavi;
// 表示文字列
$this->tpl_strnavi = empty($strnavi) ? ' ' : $strnavi;
// 規格1クラス名
$this->tpl_class_name1 = $objProduct->className1;
// 規格2クラス名
$this->tpl_class_name2 = $objProduct->className2;
// 規格1
$this->arrClassCat1 = $objProduct->classCats1;
// 規格1が設定されている
$this->tpl_classcat_find1 = $objProduct->classCat1_find;
// 規格2が設定されている
$this->tpl_classcat_find2 = $objProduct->classCat2_find;
$this->tpl_stock_find = $objProduct->stock_find;
$this->tpl_product_class_id = $objProduct->product_class_id;
$this->tpl_product_type = $objProduct->product_type;
// 商品ステータスを取得
$this->productStatus = $this->arrProducts['productStatus'];
unset($this->arrProducts['productStatus']);
// 商品ステータス2を取得
$this->productStatus2 = $this->arrProducts['productStatus2'];
unset($this->arrProducts['productStatus2']);
$this->tpl_javascript .= 'eccube.productsClassCategories = ' . SC_Utils_Ex::jsonEncode($objProduct->classCategories) . ';';
if (SC_Display_Ex::detectDevice() === DEVICE_TYPE_PC) {
//onloadスクリプトを設定. 在庫ありの商品のみ出力する
foreach ($this->arrProducts as $arrProduct) {
if ($arrProduct['stock_unlimited_max'] || $arrProduct['stock_max'] > 0) {
$js_fnOnLoad .= "fnSetClassCategories(document.product_form{$arrProduct['product_id']});";
}
}
}
//カート処理
$target_product_id = intval($this->arrForm['product_id']);
if ($target_product_id > 0) {
// 商品IDの正当性チェック
if (!SC_Utils_Ex::sfIsInt($this->arrForm['product_id'])
|| !SC_Helper_DB_Ex::sfIsRecord('dtb_products', 'product_id', $this->arrForm['product_id'], 'del_flg = 0 AND status = 1')) {
SC_Utils_Ex::sfDispSiteError(PRODUCT_NOT_FOUND);
}
// 入力内容のチェック
$arrErr = $this->lfCheckError($objFormParam);
if (empty($arrErr)) {
$this->lfAddCart($this->arrForm);
// 開いているカテゴリーツリーを維持するためのパラメーター
$arrQueryString = array(
'category_id' => $this->arrForm['category_id'],
);
SC_Response_Ex::sendRedirect(CART_URL, $arrQueryString);
SC_Response_Ex::actionExit();
}
$js_fnOnLoad .= $this->lfSetSelectedData($this->arrProducts, $this->arrForm, $arrErr, $target_product_id);
} else {
// カート「戻るボタン」用に保持
$netURL = new Net_URL();
//該当メソッドが無いため、$_SESSIONに直接セット
$_SESSION['cart_referer_url'] = $netURL->getURL();
}
$this->tpl_javascript .= 'function fnOnLoad() {' . $js_fnOnLoad . '}';
$this->tpl_onload .= 'fnOnLoad(); ';
}
商品詳細
data/Smarty/templates/default/detail.tpl
<!--▼商品ステータス-->
<!--{assign var=ps value=$productStatus[$tpl_product_id]}-->
<!--{if count($ps) > 0}-->
<ul class="status_icon clearfix">
<!--{foreach from=$ps item=status}-->
<li>
<img src="<!--{$TPL_URLPATH}--><!--{$arrSTATUS_IMAGE[$status]}-->" alt="<!--{$arrSTATUS[$status]}-->" id="icon<!--{$status}-->" />
</li>
<!--{/foreach}-->
</ul>
<!--{/if}-->
<!--▲商品ステータス-->
<!--▼商品ステータス2-->
<!--{assign var=ps value=$productStatus2[$tpl_product_id]}-->
<!--{if count($ps) > 0}-->
<div class="icon">
<!--{foreach from=$ps item=status}-->
<div class="item l-box">
<img src="<!--{$TPL_URLPATH}--><!--{$arrSTATUS_IMAGE2[$status]}-->" width="" height="" alt="<!--{$arrSTATUS2[$status]}-->"/>
</div>
<!--{/foreach}-->
</div>
<!--{/if}-->
<!--▲商品ステータス2-->
商品一覧
data/Smarty/templates/default/list.tpl
<!--▼商品ステータス-->
<!--{if count($productStatus[$id]) > 0}-->
<ul class="status_icon clearfix">
<!--{foreach from=$productStatus[$id] item=status}-->
<li>
<img src="<!--{$TPL_URLPATH}--><!--{$arrSTATUS_IMAGE[$status]}-->" alt="<!--{$arrSTATUS[$status]}-->"/>
</li>
<!--{/foreach}-->
</ul>
<!--{/if}-->
<!--▲商品ステータス-->
<!--▼商品ステータス2-->
<!--{if count($productStatus2[$id]) > 0}-->
<ul class="status_icon clearfix">
<!--{foreach from=$productStatus2[$id] item=status}-->
<li>
<img src="<!--{$TPL_URLPATH}--><!--{$arrSTATUS_IMAGE2[$status]}-->" alt="<!--{$arrSTATUS2[$status]}-->"/>
</li>
<!--{/foreach}-->
</ul>
<!--{/if}-->
<!--▲商品ステータス2-->
とりあえず、商品ステータスの下に表示をしていますが、
位置は自由に変えてください。
ゼヒトモ内でのプロフィール: ROCKSTREAM, ゼヒトモのホームページ作成・制作サービス, 仕事をお願いしたい依頼者と様々な「プロ」をつなぐサービス
2025/01/31
JQuery
2025/01/01
神社
御朱印
相模原
2024/10/27
ブラウザ
カスタム投稿
Wordpress
2024/08/20
神社
御朱印
2024/07/06
神社
御朱印