Labo

[EC-CUBE 2.12.2] 関連商品(その他のオススメ商品)にカテゴリ情報を表示

2012年12月16日 / 投稿者名:fukap


開発コミュニティで以下のようなスレッドがありました。
[req/fro:54644]【再度】メーカー検索結果へ別のページからリンクさせたい

 

要求仕様がちゃんと理解できていないので、手助けになっているか怪しいのですが、
商品詳細ページの関連商品(その他のオススメ商品)のカテゴリ情報を以下のような感じで表示してみたいと思います。
(複数カテゴリのテストのために、アイスクリームを雑貨カテゴリに関連付けを行っています。)

 

1.data/class/pages/products/LC_Page_Products_Detail.php の lfPreGetRecommendProducts メソッドを以下のように修正

    /* 登録済み関連商品の読み込み */
    function lfPreGetRecommendProducts($product_id) {
        $objProduct = new SC_Product_Ex();
        $objQuery =& SC_Query_Ex::getSingletonInstance();

        $objQuery->setOrder('rank DESC');

        $arrRecommendData = $objQuery->select('recommend_product_id, comment', 'dtb_recommend_products as t1 left join dtb_products as t2 on t1.recommend_product_id = t2.product_id', 't1.product_id = ? and t2.del_flg = 0 and t2.status = 1', array($product_id));

        $arrRecommendProductId = array();
        foreach ($arrRecommendData as $recommend) {
            $arrRecommendProductId[] = $recommend['recommend_product_id'];
            $this->arrRecommendCat[$recommend['recommend_product_id']] = SC_Helper_DB_Ex::sfGetMultiCatTree($recommend['recommend_product_id']);
        }

        $objQuery =& SC_Query_Ex::getSingletonInstance();
        $arrProducts = $objProduct->getListByProductIds($objQuery, $arrRecommendProductId);

        $arrRecommend = array();
        foreach ($arrRecommendData as $key => $arrRow) {
            $arrRecommendData[$key] = array_merge($arrRow, $arrProducts[$arrRow['recommend_product_id']]);
        }
        return $arrRecommendData;
    }

$arrRecommendData を展開して関連商品IDを取得している箇所があったので、そこにカテゴリ情報を取得するコードを挿入し、
カテゴリ情報を $this->arrRecommendCat に代入しています。

 

2.data/Smarty/templates/default/products/detail.tpl の関連商品部分を以下のように修正

    <!--▼関連商品-->
    <!--{if $arrRecommend}-->
        <div id="whobought_area">
            <h2><img src="<!--{$TPL_URLPATH}-->img/title/tit_product_recommend.jpg" alt="その他のオススメ商品" /></h2>
            <!--{foreach from=$arrRecommend item=arrItem name="arrRecommend"}-->
                <div class="product_item">
                    <div class="productImage">
                        <a href="<!--{$smarty.const.P_DETAIL_URLPATH}--><!--{$arrItem.product_id|u}-->">
                            <img src="<!--{$smarty.const.ROOT_URLPATH}-->resize_image.php?image=<!--{$arrItem.main_list_image|sfNoImageMainList|h}-->&amp;width=65&amp;height=65" alt="<!--{$arrItem.name|h}-->" /></a>
                    </div>
                    <!--{assign var=price02_min value=`$arrItem.price02_min_inctax`}-->
                    <!--{assign var=price02_max value=`$arrItem.price02_max_inctax`}-->
                    <div class="productContents">
                        <h3><a href="<!--{$smarty.const.P_DETAIL_URLPATH}--><!--{$arrItem.product_id|u}-->"><!--{$arrItem.name|h}--></a></h3>
                        <dl class="">
                            <dt>カテゴリ:</dt>
                            <!--{foreach from=$arrRecommendCat[$arrItem.product_id] name=rc key=k item=i}-->
                                <dd>
                                <!--{foreach from=$i name=rc2 key=k2 item=i2}-->
                                    <a href="<!--{$smarty.const.ROOT_URLPATH}-->products/list.php?category_id=<!--{$i2.category_id|u}-->">
                                        <!--{$i2.category_name|h}-->
                                    </a>
                                    <!--{if !$smarty.foreach.rc2.last}--><!--{$smarty.const.SEPA_CATNAVI}--><!--{/if}-->
                                <!--{/foreach}-->
                                </dd>
                            <!--{/foreach}-->
                        </dl>
                        <p class="sale_price"><!--{$smarty.const.SALE_PRICE_TITLE}-->(税込):<span class="price">
                            <!--{if $price02_min == $price02_max}-->
                                <!--{$price02_min|number_format}-->
                            <!--{else}-->
                                <!--{$price02_min|number_format}-->~<!--{$price02_max|number_format}-->
                            <!--{/if}-->円</span></p>
                        <p class="mini"><!--{$arrItem.comment|h|nl2br}--></p>
                    </div>
                </div><!--{* /.item *}-->
                <!--{if $smarty.foreach.arrRecommend.iteration % 2 === 0}-->
                    <div class="clear"></div>
                <!--{/if}-->
            <!--{/foreach}-->
        </div>
    <!--{/if}-->
    <!--▲関連商品-->

取得したカテゴリ情報をループで展開して、ツリー上に表示しています。
商品詳細の関連カテゴリとほぼ同じ処理ですが、何となく foreach にしてみました。

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

* Copy This Password *

* Type Or Paste Password Here *

*

コメント欄にコードを挿入したい場合は、[php][/php] を使ってください。