[EC-CUBE2.13]商品詳細のその他オススメ商品(関連商品)に商品ステータスを表示する

  • 公開日:2015/4/24
この記事は最終更新日から8年以上が経過しています。

商品詳細ページのその他オススメ商品(=関連商品)に商品ステータスを表示する方法です。

「LC_Page_Products_Detail」をカスタマイズしたいので、このクラスの拡張クラスである「LC_Page_Products_Detail_Ex」を編集します。
というわけで、
data/class/pages/products/LC_Page_Products_Detail.php
の「action()」(163〜313行目)を
data/class_extends/page_extends/products/LC_Page_Products_Detail_Ex.php
にまるごとコピーします。

/**
 * 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->arrRecommend = $this->lfPreGetRecommendProducts($product_id);

//関連商品の商品ステータスを取得
if(count($this->arrRecommend) > 0){
    $this->recommendProductStatus = array();
    foreach ($this->arrRecommend as $val) {
        $this->recommendProductStatus += $objProduct->getProductStatus($val['product_id']);
    }
}

data/Smarty/templates/default/products/detail.tpl の関連商品部分のコードを以下のような感じで修正します。

<!--▼関連商品-->
<!--{if $arrRecommend}-->
    <div id=&quot;whobought_area&quot;>
        <h2><img src=&quot;<!--{$TPL_URLPATH}-->img/title/tit_product_recommend.png&quot; alt=&quot;その他のオススメ商品&quot; /></h2>
        <!--{foreach from=$arrRecommend item=arrItem name=&quot;arrRecommend&quot;}-->
            <div class=&quot;product_item&quot;>
                <div class=&quot;productImage&quot;>
                    <a href=&quot;<!--{$smarty.const.P_DETAIL_URLPATH}--><!--{$arrItem.product_id|u}-->&quot;>
                        <img src=&quot;<!--{$smarty.const.IMAGE_SAVE_URLPATH}--><!--{$arrItem.main_list_image|sfNoImageMainList|h}-->&quot; style=&quot;max-width: 65px;max-height: 65px;&quot; alt=&quot;<!--{$arrItem.name|h}-->&quot; /></a>
                </div>
                <!--{assign var=price02_min value=`$arrItem.price02_min_inctax`}-->
                <!--{assign var=price02_max value=`$arrItem.price02_max_inctax`}-->
                <div class=&quot;productContents&quot;>
                    <!--▼商品ステータス-->
                    <!--{assign var=ps value=$recommendProductStatus[$arrItem.product_id]}-->
                    <!--{if count($ps) > 0}-->
                        <ul class=&quot;status_icon clearfix&quot;>
                            <!--{foreach from=$ps item=status}-->
                                <li>
                                    <img src=&quot;<!--{$TPL_URLPATH}--><!--{$arrSTATUS_IMAGE[$status]}-->&quot; width=&quot;60&quot; height=&quot;17&quot; alt=&quot;<!--{$arrSTATUS[$status]}-->&quot; id=&quot;icon<!--{$status}-->&quot; />
                                </li>
                            <!--{/foreach}-->
                        </ul>
                    <!--{/if}-->
                    <!--▲商品ステータス-->
                    <h3><a href=&quot;<!--{$smarty.const.P_DETAIL_URLPATH}--><!--{$arrItem.product_id|u}-->&quot;><!--{$arrItem.name|h}--></a></h3>
                    <p class=&quot;sale_price&quot;><!--{$smarty.const.SALE_PRICE_TITLE}-->(税込):<span class=&quot;price&quot;>
                        <!--{if $price02_min == $price02_max}-->
                            <!--{$price02_min|n2s}-->
                        <!--{else}-->
                            <!--{$price02_min|n2s}-->~<!--{$price02_max|n2s}-->
                        <!--{/if}-->円</span></p>
                    <p class=&quot;mini&quot;><!--{$arrItem.comment|h|nl2br}--></p>
                </div>
            </div><!--{* /.item *}-->
            <!--{if $smarty.foreach.arrRecommend.iteration % 2 === 0}-->
                <div class=&quot;clear&quot;></div>
            <!--{/if}-->
        <!--{/foreach}-->
    </div>
<!--{/if}-->
<!--▲関連商品-->