バージョン選択

フォーラム

メニュー

オンライン状況

93 人のユーザが現在オンラインです。 (84 人のユーザが フォーラム を参照しています。)
登録ユーザ: 0
ゲスト: 93
もっと...

サイト内検索

質問 > フロント機能 > 【2.13.0】新着商品プラグインの特定カテゴリ非表示

フロント機能

新規スレッドを追加する

スレッド表示 | 新しいものから 前のトピック | 次のトピック | 下へ
投稿者 スレッド
k14lost
投稿日時: 2013/11/1 13:40
対応状況: −−−
新米
登録日: 2013/5/2
居住地:
投稿: 9
【2.13.0】新着商品プラグインの特定カテゴリ非表示
・EC-CUBE 2.13.0
・PHP   PHP 5.3.11-dev
・DB    MySQL 5.5.21


いつもお世話になります。

プラグイン「新着商品ブロック」で、
特定カテゴリの非表示をしたいのですが、
中々うまくきません。

それ以外のサイドバー商品カテゴリ・商品一覧では
特定カテゴリの非表示がうまくいきました。

以下ソースです。
-----------------

<?php
// {{{ requires
require_once CLASS_REALDIR . 'pages/frontparts/bloc/LC_Page_FrontParts_Bloc.php';

/**
* 新着商品ブロックのブロッククラス
*/
class LC_Page_FrontParts_Bloc_NewItems extends LC_Page_FrontParts_Bloc {

/**
* 初期化する.
*
* @return void
*/
function init() {
parent::init();
}

/**
* プロセス.
*
* @return void
*/
function process() {
$this->action();
$this->sendResponse();
}

/**
* Page のアクション.
*
* @return void
*/
function action() {
//商品情報取得
$this->arrNewItems = $this->lfGetNewitems();
}

/**
* デストラクタ.
*
* @return void
*/
function destroy() {
parent::destroy();
}

/**
* 新着商品の情報を取得
*
* @return array
* @setcookie array
*/
function lfGetNewitems(){
$objQuery =& SC_Query_Ex::getSingletonInstance();
$objProduct = new SC_Product_Ex();


// プラグイン情報を取得.
$plugin = SC_Plugin_Util_Ex::getPluginByPluginCode("NewItems");
//表示条件
$disp_rule = is_numeric($plugin['free_field1']) ? $plugin['free_field1'] : 0;
//表示件数
$disp_count = unserialize($plugin['free_field2']);
//表示ステータス
$product_status = $plugin['free_field3'];

//デバイスフラグ
$disp_device == SC_Display_Ex::detectDevice();


// 新着商品情報取得
$col = 'product_id';
$table = 'dtb_products';
$where = 'status = 1 and del_flg = 0';

if($product_status){
$arrStatus = unserialize($product_status);
if(is_array( $arrStatus )){
$strstatus = '';
foreach( $arrStatus as $status ){
if( $strstatus ) $strstatus .= ',';
$strstatus .= $status;
}
$where .= ' '
. 'AND product_id IN ('
. ' SELECT product_id FROM dtb_product_status WHERE product_status_id IN (' . $strstatus . ')'
. ')';
}
}
switch($disp_rule) {
case 1://登録日順
$objQuery->setOrder('create_date desc');
break;
case 2://更新日順
$objQuery->setOrder('update_date desc');
break;
}

if (SC_Display_Ex::detectDevice() == DEVICE_TYPE_PC ) {
$objQuery->setLimit($disp_count[10]);
}elseif(SC_Display_Ex::detectDevice() == DEVICE_TYPE_MOBILE){
$objQuery->setLimit($disp_count[1]);
}elseif(SC_Display_Ex::detectDevice() == DEVICE_TYPE_SMARTPHONE ){
$objQuery->setLimit($disp_count[2]);
}
$arrProducts = $objQuery->select($col, $table, $where);


$objQuery =& SC_Query_Ex::getSingletonInstance();
if (count($arrProducts) > 0) {

$arrProductId = array();
foreach ($arrProducts as $key => $val) {
$arrProductId[] = $val['product_id'];
}


// category_id=7 を含む商品情報を配列から削除
foreach($arrProducts as $arrProduct){
$arrCategoryId = SC_Helper_DB_Ex::sfGetCategoryId($arrProduct['product_id']);
if(in_array(7, $arrCategoryId)){
unset($arrProducts[$arrProduct['product_id']]);
}
}

// 商品詳細情報取得
$arrTmp = $objProduct->getListByProductIds($objQuery, $arrProductId);
foreach ($arrTmp as $key => $arrRow) {
$_row = $arrRow;
$arrProductList[] = $_row;
}
}
return $arrProductList;
}

}
?>

-----------------

プラグイン対応バージョンが2.12系でしたが、
現在正常に動いております。

どなたかご教授をお願い致します。

namahage
投稿日時: 2013/11/1 15:16
対応状況: −−−
長老
登録日: 2013/2/28
居住地: 大阪
投稿: 198
Re: 【2.13.0】新着商品プラグインの特定カテゴリ非表示
ども

SC_Helper_DB_Ex::sfGetCategoryId($arrProduct['product_id']);
の戻り値は、2.12.5では、$category_idですね。
配列ではないですよ。

よって、


// category_id=7 を含む商品情報を配列から削除
foreach($arrProducts as $key => $arrProduct){
$categoryId = SC_Helper_DB_Ex::sfGetCategoryId($arrProduct['product_id']);
if($categoryId == 7){
unset($arrProducts[$key]);
}
}

とかでいかがでしょ?

ポイントは$arrProductsの何番目の要素を削除したいかを$keyで知ることだと思います。
k14lost
投稿日時: 2013/11/1 15:36
対応状況: −−−
新米
登録日: 2013/5/2
居住地:
投稿: 9
Re: 【2.13.0】新着商品プラグインの特定カテゴリ非表示
namahage様

お返事ありがとうございます!

// category_id=7 を含む商品情報を配列から削除
foreach($arrProducts as $key => $arrProduct){
$categoryId = SC_Helper_DB_Ex::sfGetCategoryId($arrProduct['product_id']);
if($categoryId == 7){
unset($arrProducts[$key]);
}
}


上記のコードで試してみましたが、
表示されたままでした・・・。


sumida
投稿日時: 2013/11/1 16:31
対応状況: −−−
仙人
登録日: 2013/2/10
居住地: 広島県呉市ときどき瀬戸内海
投稿: 641
Re: 【2.13.0】新着商品プラグインの特定カテゴリ非表示
これではどうでしょう。

// category_id=7 を含む商品情報を配列から削除
foreach($arrProducts as $arrKey => $arrProduct){
$arrCategoryId = SC_Helper_DB_Ex::sfGetCategoryId($arrProduct['product_id']);
if(in_array(7, $arrCategoryId)){
unset($arrProducts[$arrKey]);
}
}

ただ、foreach中の要素をunsetするのって、PHP的にどうなんでしょう。
k14lost
投稿日時: 2013/11/1 17:00
対応状況: −−−
新米
登録日: 2013/5/2
居住地:
投稿: 9
Re: 【2.13.0】新着商品プラグインの特定カテゴリ非表示
sumida様
お返事ありがとうございます!
当方、初心者なものですいません・・。

// category_id=7 を含む商品情報を配列から削除
foreach($arrProducts as $arrKey => $arrProduct){
$arrCategoryId = SC_Helper_DB_Ex::sfGetCategoryId($arrProduct['product_id']);
if(in_array(7, $arrCategoryId)){
unset($arrProducts[$arrKey]);
}
}


上記コード、非表示になりませんでした・・。
namahage
投稿日時: 2013/11/1 17:28
対応状況: −−−
長老
登録日: 2013/2/28
居住地: 大阪
投稿: 198
Re: 【2.13.0】新着商品プラグインの特定カテゴリ非表示
ほんとにすみませんが嘘教えちゃってました。
SC_Helper_DB_Ex::sfGetCategoryIdの戻り値は配列でした。
ほんとにお恥ずかしい。

sumidaさまのコードでぼくの環境で
カテゴリーが除去されることを確認しました。


原因は、arrProductListをリターンしている事だと思います。



	    // category_id=7 を含む商品情報を配列から削除
		foreach($arrProducts as $key => $arrProduct){
			$categoryId = SC_Helper_DB_Ex::sfGetCategoryId($arrProduct['product_id']);
			if(in_array(7, $categoryId)){
				unset($arrProducts[$key]);
			}
		}

で7のカテゴリーの商品は除去してるけど、その後、$arrProductsは使われてません。
戻り値として返されているのは、下のarrProductListだからです。



// 商品詳細情報取得
$arrTmp = $objProduct->getListByProductIds($objQuery, $arrProductId);
foreach ($arrTmp as $key => $arrRow) {
$_row = $arrRow;
$arrProductList[] = $_row;
}
}
return $arrProductList;
}




詳細情報のとりかたが間違ってるんですね。
namahage
投稿日時: 2013/11/1 17:45
対応状況: −−−
長老
登録日: 2013/2/28
居住地: 大阪
投稿: 198
Re: 【2.13.0】新着商品プラグインの特定カテゴリ非表示

// category_id=7 を含む商品情報を配列から削除
foreach($arrProducts as $arrProduct){
	$arrCategoryId = SC_Helper_DB_Ex::sfGetCategoryId($arrProduct['product_id']);
	if(in_array(7, $arrCategoryId)){
		unset($arrProducts[$arrProduct['product_id']]);
	}
}

を、

$arrProductId = array();
foreach ($arrProducts as $key => $val) {
$arrProductId[] = $val['product_id'];
}

より上に持ってくれば大丈夫ですけど、欲を言えば、



$arrProductId = array();
foreach ($arrProducts as $key => $val) {
	$arrProductId[] = $val['product_id'];
}


を、


$arrProductId = array();
foreach ($arrProducts as $key => $val) {
	$arrCategoryId = SC_Helper_DB_Ex::sfGetCategoryId($val['product_id']);
	if(!in_array(7, $arrCategoryId)){
		$arrProductId[] = $val['product_id'];
	}
}

にすれば


// category_id=7 を含む商品情報を配列から削除
foreach($arrProducts as $arrProduct){
	$arrCategoryId = SC_Helper_DB_Ex::sfGetCategoryId($arrProduct['product_id']);
	if(in_array(7, $arrCategoryId)){
		unset($arrProducts[$arrProduct['product_id']]);
	}
}

を、削除できますんで良いと思います。
k14lost
投稿日時: 2013/11/5 9:51
対応状況: 解決済
新米
登録日: 2013/5/2
居住地:
投稿: 9
Re: 【2.13.0】新着商品プラグインの特定カテゴリ非表示

namahage様

特定カテゴリの非表示ができました!
本当に嬉しいです・・!
心よりお礼を申し上げます。
D-18
投稿日時: 2016/2/19 1:03
対応状況: −−−
半人前
登録日: 2012/10/31
居住地:
投稿: 16
Re: 【2.13.0】新着商品プラグインの特定カテゴリ非表示
namahage様

現在、特定のカテゴリのみ非表示ではなく、特定のカテゴリのみ表示をしたく作業をしています。

$arrProductId = array();
foreach ($arrProducts as $key => $val) {
	$arrCategoryId = SC_Helper_DB_Ex::sfGetCategoryId($val['product_id']);
	if(in_array(7, $arrCategoryId)){
		$arrProductId[] = $val['product_id'];
	}
}



if(!in_array(7, $arrCategoryId)){

の「!」を外すだけで対応してみてうまく表示が出来たと喜んでいたのですが、、、

管理画面 > プラグイン管理 > プラグイン設定より表示個数を5個にして保存しているのですが3件とか、、2件とかしか表示されません。

私の理解出来る範囲を超えております。。。。

助言の程、よろしくお願いいたします。。。。

私の環境は下記になります。
---------------------------
・EC-CUBE 2.12.3
・PHP   PHP 5.3.29
・DB    MySQL 5.5.46
---------------------------
スレッド表示 | 新しいものから 前のトピック | 次のトピック | トップ


 



ログイン


EC-CUBE公式 Amazon Payプラグイン

統計情報

総メンバー数は88,856名です
総投稿数は109,989件です

投稿数ランキング

1
seasoft
7367
2
468
3217
3
AMUAMU
2712
4
nanasess
2313
5
umebius
2085
6
yuh
1819
7
h_tanaka
1646
8
red
1570
9
mcontact
1291
10
tsuji
958
11
fukap
907
12
shutta
835
13
tao_s
799
14 ramrun 789
15 karin 689
16 sumida 641
17
homan
633
18 DELIGHT 572
19
patapata
502
20
flealog
485


ネットショップの壺

EC-CUBEインテグレートパートナー

Copyright© EC-CUBE CO.,LTD. All Rights Reserved.