忍者ブログ
[PR]
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。



2024/03/28 19:26 |
EC-CUBE オススメ商品ブロック
{section}を使用して相当わかりにくくなっているので、{foreach}で作り直してみます。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<!-- ▼おすすめ情報 ここから-->
<!--{if count($arrBestProducts) > 0}-->
    <div id="recomendarea">
        <div class="title">おすすめ情報</div>
        
        <!--{foreach from=$arrBestProducts key=cnt item=BestProducts name=loop}-->
            <!--{if $smarty.foreach.loop.index is even }-->
                <!--{* 2件毎に段落開始 *}-->
                <div class="recomendblock">
                <div class="recomendleft">
            <!--{else}-->
                <div class="recomendright">
            <!--{/if}-->
            
                <a href="<!--{$smarty.const.URL_DIR}-->products/detail.php
                    ?product_id=<!--{$BestProducts.product_id|escape}-->">
                    <img src="<!--{$smarty.const.SITE_URL}-->resize_image.php
                        ?image=<!--{$BestProducts.main_list_image|sfRmDupSlash}-->
                        &width=48&height=48" 
                        alt="<!--{$BestProducts.name|escape}-->" />
                </a>
                <a href="<!--{$smarty.const.URL_DIR}-->products/detail.php
                    ?product_id=<!--{$BestProducts.product_id|escape}-->">
                    <!--{$BestProducts.name|escape}-->
                </a>
                <p><!--{$BestProducts.comment|escape}--></p>
            
            <!--{if ( ($smarty.foreach.loop.index is odd) 
                || ($smarty.foreach.loop.last) ) }-->
                <!--{* 2件毎、もしくは最後であれば段落終了 *}-->
                </div>
                </div>
            <!--{else}-->
                </div>
            <!--{/if}-->
        <!--{/foreach}-->
        
    </div>
<!--{/if}-->
<!-- ▲おすすめ情報 ここまで-->


価格とか画像のあたりは端折ってる処理もありますが、たったこれだけでほぼ同等の機能を実現できます。
なんで倍以上の長さを使ってあんなわかりにくい作りにしてるんだろう。
なんかEC-CUBEのテンプレ作った人がやたらsection好きみたいで困る。
ロジックもやたらforが好きだし。foreach使えと。

↓ちなみに元のソース
cnt2の求め方のあたりが非常にださい。
 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!--▼おすすめ情報ここから-->
<!--{if count($arrBestProducts) > 0}-->
<div id="recomendarea">
  <h2>
    <img src="img/top/osusume.jpg" width="400" height="29" alt="おすすめ情報" />
  </h2>
  <!--{section name=cnt loop=$arrBestProducts step=2}-->
  <div class="recomendblock">
    <div class="recomendleft">
    <!--{if $arrBestProducts[cnt].main_list_image != ""}-->
      <!--{assign var=image_path 
        value="`$arrBestProducts[cnt].main_list_image`"}-->
    <!--{else}-->
      <!--{assign var=image_path value="`$smarty.const.NO_IMAGE_DIR`"}-->
    <!--{/if}-->
 
      <a href="<!--{$smarty.const.URL_DIR}-->products/detail.php
        ?product_id=<!--{$arrBestProducts[cnt].product_id}-->">
        <img src="<!--{$smarty.const.SITE_URL}-->resize_image.php
          ?image=<!--{$image_path|sfRmDupSlash}-->&amp;width=48&amp;height=48"
          alt="<!--{$arrBestProducts[cnt].name|escape}-->" /></a>
      <h3>
        <a href="<!--{$smarty.const.URL_DIR}-->products/detail.php
          ?product_id=<!--{$arrBestProducts[cnt].product_id}-->">
          <!--{$arrBestProducts[cnt].name|escape}--></a>
      </h3>
 
<!--{assign var=price01 value=`$arrBestProducts[cnt].price01_min`}-->
<!--{assign var=price02 value=`$arrBestProducts[cnt].price02_min`}-->
 
      <p>価格<span class="mini">(税込)</span><span class="price">
  <!--{if $price02 == ""}-->
    <!--{$price01|sfPreTax:$arrInfo.tax:$arrInfo.tax_rule|number_format}-->
  <!--{else}-->
    <!--{$price02|sfPreTax:$arrInfo.tax:$arrInfo.tax_rule|number_format}-->
  <!--{/if}--></span>
      </p>
      <p class="mini"><!--{$arrBestProducts[cnt].comment|escape|nl2br}--></p>
    </div>
 
    <div class="recomendright">
      <!--{assign var=cnt2 
        value=`$smarty.section.cnt.iteration*$smarty.section.cnt.step-1` }-->
      <!--{if $arrBestProducts[$cnt2]|count > 0}-->
        <!--{if $arrBestProducts[$cnt2].main_list_image != ""}-->
          <!--{assign var=image_path 
            value="`$arrBestProducts[$cnt2].main_list_image`"}-->
        <!--{else}-->
          <!--{assign var=image_path value="`$smarty.const.NO_IMAGE_DIR`"}-->
        <!--{/if}-->
 
      <a href="<!--{$smarty.const.URL_DIR}-->products/detail.php
        ?product_id=<!--{$arrBestProducts[$cnt2].product_id}-->">
        <img src="<!--{$smarty.const.SITE_URL}-->resize_image.php
           ?image=<!--{$image_path|sfRmDupSlash}-->&amp;width=48&amp;height=48"
           alt="<!--{$arrBestProducts[$cnt2].name|escape}-->" /></a>
      <h3>
      <a href="<!--{$smarty.const.URL_DIR}-->products/detail.php
        ?product_id=<!--{$arrBestProducts[$cnt2].product_id}-->">
        <!--{$arrBestProducts[$cnt2].name|escape}--></a>
      </h3>
 
<!--{assign var=price01 value=`$arrBestProducts[$cnt2].price01_min`}-->
<!--{assign var=price02 value=`$arrBestProducts[$cnt2].price02_min`}-->
 
      <p>価格<span class="mini">(税込)</span><span class="price">
  <!--{if $price02 == ""}-->
    <!--{$price01|sfPreTax:$arrInfo.tax:$arrInfo.tax_rule|number_format}-->
  <!--{else}-->
    <!--{$price02|sfPreTax:$arrInfo.tax:$arrInfo.tax_rule|number_format}-->
  <!--{/if}--></span>
      </p>
 
      <p class="mini"><!--{$arrBestProducts[$cnt2].comment|escape|nl2br}--></p>
      <!--{/if}-->
    </div>
  </div>
  <!--{/section}-->
</div>
<!--{/if}-->
<!--▲おすすめ情報ここまで-->


EC-CUBEの記事
PR


2010/03/19 23:28 | Comments(0) | TrackBack() | PHP

トラックバック

トラックバックURL:

コメント

コメントを投稿する






Vodafone絵文字 i-mode絵文字 Ezweb絵文字 (絵文字)



<<買ったものリスト 2010/03/21 | HOME | ==NOVEL PHILOSOMA== 06>>
忍者ブログ[PR]