バージョン選択

フォーラム

メニュー

オンライン状況

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

サイト内検索

質問 > フロント機能 > 固定ページ内にカテゴリごとの商品を表示

フロント機能

新規スレッドを追加する

スレッド表示 | 新しいものから 前のトピック | 次のトピック | 下へ
投稿者 スレッド
tatsuyoshi
投稿日時: 2015/6/22 10:02
対応状況: −−−
常連
登録日: 2015/5/22
居住地: 埼玉県
投稿: 43
固定ページ内にカテゴリごとの商品を表示
固定ページのテンプレを作成し、以下をphpへ記述しました。
表示しようとするとエラーになります。

<PHPファイル>
require_once '../require.php';
require_once CLASS_EX_REALDIR . 'page_extends/LC_Page_Ex.php';
//require_once CLASS_REALDIR . 'pages/frontparts/bloc/LC_Page_FrontParts_Bloc.php';

class LC_Page_User extends LC_Page_Ex
{

function init()
{
parent::init();
}

function process()
{
parent::process();
$this->action();
$this->sendResponse();

}

function action()
{
$this->footsaru_Product();
$this->sosaichi_Product();
}

function footsaru_Product(){
$arrProduct_footsaru= $this->access(8);
return $arrProduct_footsaru;
}


function sosaichi_Product(){
$arrProduct_footsaru= $this->access(9);
return $arrProduct_sosaichi;
}

function access($num){
$objQuery = new SC_Query_Ex();
$from = 'dtb_products as T1 INNER JOIN dtb_products_class as T2 ON T1.product_id = T2.product_id';
$from .= ' INNER JOIN dtb_product_categories as T3 ON T1.product_id = T3.product_id';
$where = 'T2.del_flg = 0 and T2.status = 1 and T3.category_id IN (?)'; //$arrval で指定するカテゴリIDの数だけ ? を増やす
$arrval = Array($num);
$objQuery->setOrder("T1.update_date desc");
$arrProducts = $objQuery->select("*", $from, $where, $arrval);
$this->resets();
return $arrProducts;
}

function resets(){
// 重複データ削除
$tmp = Array();
$i = 0;
$max_count = 10; // 取得したい商品個数を指定する
foreach($arrProducts as $arrProduct){
if(!in_array($arrProduct['product_id'], $tmp)){
$this->arrProducts[$i] = $arrProduct;
$i++;
}
$tmp[] = $arrProduct['product_id'];
if($i >= $max_count){
break;
}
}
$objView->assignobj($this);
$objView->display($this->tpl_mainpage);
}

}

$objPage = new LC_Page_User();
$objPage->init();
$objPage->process();
</PHPファイル>

<tplファイル>
<!--{php}-->
var_dump($arrProduct_footsaru);
<!--{/php}-->
</tplファイル>

長文失礼しました・・。
また、エラーは以下です。
Fatal error(E_USER_ERROR): DB処理でエラーが発生しました。
SQL: [SELECT * FROM dtb_products as T1 INNER JOIN dtb_products_class as T2 ON T1.product_id = T2.product_id INNER JOIN dtb_product_categories as T3 ON T1.product_id = T3.product_id WHERE T2.del_flg = 0 and T2.status = 1 and T3.category_id IN (?) ORDER BY T1.update_date desc ]
MDB2 Error: no such field
_doQuery: [Error message: Could not execute statement]
yuh
投稿日時: 2015/6/22 10:47
対応状況: −−−
登録日: 2013/1/9
居住地: 大阪
投稿: 1819
Re: 固定ページ内にカテゴリごとの商品を表示
http://xoops.ec-cube.net/modules/newbb/viewtopic.php?viewmode=thread&topic_id=16118&forum=10&post_id=71636#forumpost71636

これの拡張で

<?php
require_once '../require.php';
require_once CLASS_EX_REALDIR . 'page_extends/products/LC_Page_Products_List_Ex.php';

class LC_Page_User extends LC_Page_Products_List_Ex
{
    /**
     * Page を初期化する.
     *
     * @return void
     */
    function init()
    {
        parent::init();
    }

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

    /**
     * Page のアクション.
     *
     * @return void
     */
    public function action()
    {
        //決済処理中ステータスのロールバック
        $objPurchase = new SC_Helper_Purchase_Ex();
        $objPurchase->cancelPendingOrder(PENDING_ORDER_CANCEL_FLAG);

        $objProduct = new SC_Product_Ex();
        // パラメーター管理クラス
        $objFormParam = new SC_FormParam_Ex();

        // パラメーター情報の初期化
        $this->lfInitParam($objFormParam);

        // 値の設定
        $objFormParam->setParam($_REQUEST);

        // 入力値の変換
        $objFormParam->convParam();

        // 値の取得
        $this->arrForm = $objFormParam->getHashArray();

        //modeの取得
        $this->mode = $this->getMode();
	
	/*-------------------------------------------*/
	//ここに固定で表示させたいカテゴリのIDを入れる。
	$this->arrForm['category_id'] = 1;
	/*-------------------------------------------*/
	
        //表示条件の取得
        $this->arrSearchData = array(
            'category_id'   => $this->lfGetCategoryId(intval($this->arrForm['category_id'])),
            'maker_id'      => intval($this->arrForm['maker_id']),
            'name'          => $this->arrForm['name']
        );
        $this->orderby = $this->arrForm['orderby'];

        //ページング設定
        $this->tpl_pageno   = $this->arrForm['pageno'];
        $this->disp_number  = $this->lfGetDisplayNum($this->arrForm['disp_number']);

        // 画面に表示するサブタイトルの設定
        $this->tpl_subtitle = $this->lfGetPageTitle($this->mode, $this->arrSearchData['category_id']);

        // 画面に表示する検索条件を設定
        $this->arrSearch    = $this->lfGetSearchConditionDisp($this->arrSearchData);

        // 商品一覧データの取得
        $arrSearchCondition = $this->lfGetSearchCondition($this->arrSearchData);
        $this->tpl_linemax  = $this->lfGetProductAllNum($arrSearchCondition);
        $urlParam           = "category_id={$this->arrSearchData['category_id']}&pageno=#page#";
        // モバイルの場合に検索条件をURLの引数に追加
        if (SC_Display_Ex::detectDevice() === DEVICE_TYPE_MOBILE) {
            $searchNameUrl = urlencode(mb_convert_encoding($this->arrSearchData['name'], 'SJIS-win', 'UTF-8'));
            $urlParam .= "&mode={$this->mode}&name={$searchNameUrl}&orderby={$this->orderby}";
        }
        $this->objNavi      = new SC_PageNavi_Ex($this->tpl_pageno, $this->tpl_linemax, $this->disp_number, 'eccube.movePage', NAVI_PMAX, $urlParam, SC_Display_Ex::detectDevice() !== DEVICE_TYPE_MOBILE);
        $this->arrProducts  = $this->lfGetProductsList($arrSearchCondition, $this->disp_number, $this->objNavi->start_row, $objProduct);

        switch ($this->getMode()) {
            case 'json':
                $this->doJson($objProduct);
                break;

            default:
                $this->doDefault($objProduct, $objFormParam);
                break;
        }

        $this->tpl_rnd = SC_Utils_Ex::sfGetRandomString(3);
    }
}

$objPage = new LC_Page_User();
$objPage->init();
$objPage->process();


このように変更すればできると思います。
$this->arrForm['category_id'] = 1;
この部分でカテゴリを指定してあげればそのカテゴリの商品一覧が表示されると思います。


require_once CLASS_REALDIR . 'pages/frontparts/bloc/LC_Page_FrontParts_Bloc.php';
と書かれてますが、ブロックに対して商品の一覧を表示させたいという意味ですか?
tatsuyoshi
投稿日時: 2015/6/22 10:58
対応状況: −−−
常連
登録日: 2015/5/22
居住地: 埼玉県
投稿: 43
Re: 固定ページ内にカテゴリごとの商品を表示
いつもありがとうございます。
require_once CLASS_REALDIR . 'pages/frontparts/bloc/LC_Page_FrontParts_Bloc.php';
は、ブロック内ではカテゴリごとの出力に成功していたので、それを継承すればできると思っていました。
浅はかな考えで赤面ですね。

ちなみに、固定ページで何か処理を加えたいときはrequire.phpで基本的に完結するのでしょうか?
そのときに実装したい機能にもよると思いますが、EC-CUBE内のDB関連の値を取る際にはrequireで継承するクラスでできますか?
yuh
投稿日時: 2015/6/22 11:07
対応状況: −−−
登録日: 2013/1/9
居住地: 大阪
投稿: 1819
Re: 固定ページ内にカテゴリごとの商品を表示
require.phpを読み込んでおけば
SC_Queryとかが使えるようになったと思います。
スレッド表示 | 新しいものから 前のトピック | 次のトピック | トップ


 



ログイン


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

統計情報

総メンバー数は89,650名です
総投稿数は110,158件です

投稿数ランキング

1
seasoft
7367
2
468
3217
3
AMUAMU
2712
4
nanasess
2314
5
umebius
2085
6
yuh
1819
7
h_tanaka
1657
8
red
1570
9
mcontact
1323
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.