バージョン選択

フォーラム

メニュー

オンライン状況

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

サイト内検索

質問 > フロント機能 > お勧めのランダム表示

フロント機能

新規スレッドを追加する

スレッド表示 | 新しいものから 前のトピック | 次のトピック | 下へ
投稿者 スレッド
cool
投稿日時: 2008/12/10 9:47
対応状況: −−−
新米
登録日: 2008/12/10
居住地:
投稿: 8
お勧めのランダム表示
フロントページで、お勧めをランダム表示したいのですが良くわかりません。

恐らく該当するファイルは2つで、
1)WWWパス/data/class/pages/frontparts/bloc/LC_Page_FrontParts_Bloc_Best5.php

2)WWWパス/data/Smarty/templates/default/bloc/best5.tpl
だと思います。

LC_Page_FrontParts_Bloc_Best5.phpの lfGetRanking()
にSQL文があって、それを
select
a.product_id , a.name, a.main_image,main_list_image,b.price02
from
dtb_products a, dtb_products_class b
where
a.product_id =b.product_id;

に変更し、
http://xoops.ec-cube.net/modules/newbb/viewtopic.php?viewmode=thread&topic_id=1868&forum=6&post_id=7198#forumpost7198
にある乱数で取得するとできそうな気がするのですが、

$col $from $where $order

にどう記述すればいいか教えてください。


kvex2004
投稿日時: 2008/12/10 11:30
対応状況: −−−
長老
登録日: 2007/10/31
居住地: 埼玉
投稿: 218
Re: お勧めのランダム表示
レコード数もたいした数ではないので、戻り値の前でshuffleではダメですか?

shuffle($arrBestProducts);
return $arrBestProducts;

もっと省略して

return shuffle($arrBestProducts);
cool
投稿日時: 2008/12/10 14:46
対応状況: −−−
新米
登録日: 2008/12/10
居住地:
投稿: 8
Re: お勧めのランダム表示
ありがとうございます

説明が足りなくてすみません。
お勧めは以下の2つのテーブルから抽出しています。
dtb_best_products
vw_products_allclass

やりたいことはこのテーブルは関係なく、dtb_productの全商品
から無作為にお勧めとして抽出したいです。

恐らく$colのSQL文が書ければいいと思うのですが、書いて
いいかわかりません。。。
kvex2004
投稿日時: 2008/12/11 15:03
対応状況: −−−
長老
登録日: 2007/10/31
居住地: 埼玉
投稿: 218
Re: お勧めのランダム表示
$col = "a.product_id , a.name, a.main_image,main_list_image,b.price02";
$from = "dtb_products a, dtb_products_class b";
$where = "a.product_id =b.product_id";
$order = "random()";

こういうことですか?
MySQLだったら rand() になるのかな?
それとも、ECCUBEが吸収してくれるのかな?
kvex2004
投稿日時: 2008/12/11 15:09
対応状況: −−−
長老
登録日: 2007/10/31
居住地: 埼玉
投稿: 218
Re: お勧めのランダム表示
あ。でもでも。
商品点数がたくさんあるとすごいことになってしまいそうなので、リミットを付けたほうが良いかもです。

いま、やってみたけど、とりあず取得できました。

$col = "a.product_id , a.name, a.main_image,main_list_image,b.price02";
$from = "dtb_products a, dtb_products_class b";
$where = "a.product_id =b.product_id";
$order = "random()";
$limit = "5";

$objQuery->setorder($order);
$objQuery->setlimit($limit);

cool
投稿日時: 2008/12/11 20:57
対応状況: −−−
新米
登録日: 2008/12/10
居住地:
投稿: 8
Re: お勧めのランダム表示
kvex2004さん ありがとうございます。できました! 
しかも、カテゴリー内だけから抽出できるようにもできました。

ずっと悩んでいたのでとてもとても感謝しています。
ありがとうございました!

一応該当箇所を記載します。
※以下の例ではカテゴリーを指定しています。


    //おすすめ商品検索
    //※カテゴリー内ランダム表示バージョン
    function lfGetRanking(){
        $objQuery = new SC_Query();
/*
	■元ソース
        $col = "DISTINCT A.*, name, price02_min, price01_min, main_list_image ";
        $from = "dtb_best_products AS A INNER JOIN vw_products_allclass AS allcls using(product_id)";
        $where = "status = 1";
        $order = "rank";
        $objQuery->setorder($order);

	■全商品の中からSELECTする
	select 
	a.product_id, a.name, a.main_image, main_list_image, b.price02, c.product_id, c.category_id
	from
	dtb_products a, dtb_products_class b, dtb_product_categories c
	where 
	a.product_id = b.product_id ;


	■全商品の中から対象カテゴリーのみSELECTする
	select 
	a.product_id, a.name, a.main_image, main_list_image, b.price02, c.product_id, c.category_id
	from
	dtb_products a, dtb_products_class b, dtb_product_categories c
	where 
	a.product_id = b.product_id and b.product_id = c.product_id and a.del_flg = 0 and c.category_id=74;

*/
	$col = "a.product_id, a.name, a.main_image, main_list_image, price02 as price02_min, c.product_id, c.category_id ";
	$from = "dtb_products a, dtb_products_class b, dtb_product_categories c ";
	$where = "a.product_id = b.product_id and b.product_id = c.product_id and a.del_flg = 0 and c.category_id=74 "; //複数カテゴリーの場合はc.category_id=を増やす
	$order = "random()";
	$limit = "24"; //抽出する数
	
	$objQuery->setorder($order);
	$objQuery->setlimit($limit);

        $arrBestProducts = $objQuery->select($col, $from, $where);

        return $arrBestProducts;
    }

スレッド表示 | 新しいものから 前のトピック | 次のトピック | トップ


 



ログイン


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

統計情報

総メンバー数は144,991名です
総投稿数は113,505件です

投稿数ランキング

1
seasoft
7369
2
468
3217
3
AMUAMU
2712
4
nanasess
2340
5
h_tanaka
2139
6
umebius
2085
7
yuh
1905
8
mcontact
1820
9
red
1585
10
tsuji
958
11
fukap
907
12
shutta
835
13
tao_s
805
14 ramrun 789
15 karin 689
16 sumida 641
17
homan
633
18
balisys
603
19 DELIGHT 572
20
patapata
502


ネットショップの壺

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

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