[Tep-j-develop] oscommerce.org の拡張モジュールの文書

Back to archive index

Masahiko Nagata nagat****@ideas*****
2002年 10月 28日 (月) 20:16:54 JST


鈴川さん、みなさん、こんばんは。
永田です。

少し間が空いてしまいましたが、Description_in_Product_Listing_v.2を自社サイト
に組み込んでみましたので報告します。
こんな感じになりました。
http://www.ideastore.co.jp/default.php?cPath=113

組込方法は下記の通りです。(大ざっぱです)
・Description_in_Product_Listing_v.2各ファイルの変更部分を、osCommerce日本語
 版の各ファイルに追記
・鈴川さんよりご教授頂いたソースコードの追記・変更
 catalog/stylesheet.css
 catalog/includes/modules/product_listing.php

さらに、
・stylesheet.cssにて、内容表示部分部分のカラー変更
・同じく内容表示文字のカラー追加
・リスト表示時のテーブルセルスペースの追加

等を行っています。

組込で一番困ったのが、表示文字数の部分でした。
Description_in_Product_Listing_v.2に付属してくるgeneral.phpに追記された部分
を、そのまま日本語版のgeneral.phpへ追記しても、マルチバイト文字(日本語)が
正しく(?)カウントされないのと、半角スペースが説明文に含まれていると、半角
スペースが出現する箇所と表示文字数の設定によって、テーブルの半分ぐらいしか表
示されなかったり、場合によっては全く説明文が表示されずに、自動的に付加される
「...」のみしか表示されないと言う現象でした。

マルチバイト文字のカウントについては、関数strlenやsubstrをmb_strlen
とmb_substrにする事で解決したのですが、半角スペースの方は、半ばお手上げ状態
でほったらかしにしてました。が、ふと該当スクリプト部分をコメントアウトすれば
良いのかと思いつき、下記の様にしましたところ、無事解決しました。

// Products Description Hack begins
//  
// grabs a length from a string, but goes back to the last space if it cut
into
// the middle of a string.  If the string is longer than that, cut, then add
'...'
// to the end of the string, if the $more == 1
      function osc_trunc_string($str="",$len=150,$more=1)
      {
            if ($str=="") return $str;
            if (is_array($str)) return $str;
            $str = trim($str);
            // if it's les than the size given, then return it
            if (mb_strlen($str) <= $len) return $str;
            // else get that size of text
            $str = mb_substr($str,0,$len);
            // backtrack to the end of a word
            /*if ($str != "") {         <---ここから
                  // check to see if there are any spaces left
                  if (!substr_count($str," ")) {
                        if ($more) $str .= "...";
                        return $str;
                   }
                  // backtrack
                  while(mb_strlen($str) && ($str[mb_strlen($str)-1] != " "))
{
                        $str = mb_substr($str,0,-1);
                   }*/              <---ここまでコメントアウト
                  $str = mb_substr($str,0,-1);
                  if ($more) $str .= "...";
            //}                 <---ここもコメントアウト
            return $str;
      }
// Products Description Hack ends

上記変更が書式的に合っているかどうか?状態ですが、結果オーライという事でその
ままにしてます。

# これは間違いだ!との事であれば、教えてください(^^;)
# で、問題無ければまとめ直してSourceForge.jpへ登録しますが...

私的には、リスト表示が非常に見やすくなって、凄く満足しています(^_^)




Tep-j-develop メーリングリストの案内
Back to archive index