16)パンくずリストを設置する – hetemlのサーバでEC-CUBE(2.11.4)を使ってみる

2月 21st, 2012 カテゴリー EC-CUBE2.11

なんでEC-CUBEはデフォルトでパンくずを用意してないのかわかりませんが、
開発コミュニティを参考に機能追加します!!



1)Products_Listのclassファイルに変更を加えます。


/data/class/pages/products/LC_Page_Products_List.php

action() 内に下記コードを挿入!!

//パンくずリストを取得
$this->arrTopicPath = $this->lfTopicPath($this->mode, $this->arrForm['category_id'], $this->arrForm['name']);


クラス内の末尾に下記コードを挿入!!

	/**
	 * パンくずリストを設定 (2012/2/20 対応)
	 *
	 * @return array
	 */
	function lfTopicPath($mode, $category_id, $category_name){
		if ($mode == 'search') {
			$arrRet = $category_name . " の検索結果";
		} elseif (empty($category_id)){
			$arrRet = "全商品";
		} else {
			$objDb = new SC_Helper_DB_Ex();
			$arrCatId = $objDb->sfGetParents("dtb_category", "parent_category_id", "category_id", $category_id);
			foreach($arrCatId as $key => $val){
				$arrCatName = $objDb->sfGetCat($val);
				if($val != $category_id){
					$arrRet[] = '<a href="./list.php?category_id=' .$val. '">'. $arrCatName['name'] . '</a> > ';
				} else {
					$arrRet[] = $arrCatName['name'];
				}
			}
		}
		return $arrRet;
	}
※静的URLの対応をしている場合は、aタグ部分を
<a href=”./list’ .$val. ‘.html”> に変更します。





2)Products_Detailのclassファイルに変更を加えます。


/data/class/pages/products/LC_Page_Products_Detail.php

action() 内に下記コードを挿入!!

// パンくずリストを取得
$this->arrTopicPath = $this->lfTopicPath2($product_id);


クラス内の末尾に下記コードを挿入!!

	/*
	 * パンくずリストを設定 (2012/2/20 対応)
	 * @return array
	 */
	function lfTopicPath2($product_id){
		$objDb = new SC_Helper_DB_Ex();
		$arrCategory_id = $objDb->sfGetCategoryId($product_id);
		$arrCatId = $objDb->sfGetParents("dtb_category", "parent_category_id", "category_id", $arrCategory_id[0]);
		foreach($arrCatId as $key => $val){
			$arrCatName = $objDb->sfGetCat($val);
			$arrRet[] = '<a href="./list.php?category_id=' .$val. '">'. $arrCatName['name'] . '</a> > ';
		}
		$arrRet[] = $this->arrProduct['name'];
		return $arrRet;
	}
※静的URLの対応をしている場合は、aタグ部分を
<a href=”./list’ .$val. ‘.html”> に変更します。





3)site_main.tplのテンプレートファイルに変更を加えます。


/data/Smarty/templates/original/site_main.tpl


<div id=”container” class=”clearfix”>の下にパンクズのタグ(BREAD CRUMBS)を挿入!!

	<!--{* ▼CONTENTS *}-->
	<div id="container" class="clearfix">

	<!--{* ▼BREAD CRUMBS *}-->
	<!--{if $smarty.server.PHP_SELF != '/index.php'}-->
		<p><a href="<!--{$smarty.const.HTTP_URL}-->">TopPage</a> >
		<!--{if $arrTopicPath}-->
			<!--{foreach from=$arrTopicPath item=Topic}-->
			<!--{$Topic}-->
			<!--{/foreach}-->
		<!--{else}-->
			<!--{$tpl_title|h}-->
		<!--{/if}-->
		</p>
	<!--{/if}-->
	<!--{* ▲BREAD CRUMBS *}-->


軽くしか動作確認してませんが、、これでOKっす!!
あとはユーザー画面側でレイアウト調整すれば完了!!




4)1つの商品が複数のカテゴリーで登録されている場合の処理

できた~と思って色々と動かしてたらやっぱりダメでした。。
1つの商品が複数のカテゴリーに属している場合、商品詳細の画面では最初に取得する?カテゴリーが表示されてしまいます。

例)「sample1」「sample2」のカテゴリーが存在
TOP
 ∟sample1
   ∟商品詳細
パンくず:TOP > sample1 > 商品詳細 【正解】


TOP
 ∟sample2
   ∟商品詳細
パンくず:TOP > sample1 > 商品詳細 【だめ~】

↓↓↓こうなってほしい↓↓↓

パンくず:TOP > sample2 > 商品詳細 【正解】


色々と考えた結果、商品一覧画面から商品詳細画面に遷移する時に$_GETで
category_idを渡す事にしました。


/data/Smarty/templates/originalPC/products/list.tpl


「商品画像」、「商品名」、「詳細を見る」のaタグに
//静的URLで運用している場合はこちらを追加
?category_id=<!--{$arrForm.category_id|u}-->

//動的URLで運用している場合はこちらを追加
&category_id=<!--{$arrForm.category_id|u}-->
を追加します。
hiro1613さん、天使の牙より記述間違いのご指摘頂きました。ご連絡ありがとございます。

/data/class/pages/products/LC_Page_Products_Detail.php

2)で設定した「パンくずリストを設定」を以下に変更。

	/*
	 * パンくずリストを設定 (2012/2/20 対応)
	 * @return array
	 */
	function lfTopicPath2($product_id, $CatTree){
		$objDb = new SC_Helper_DB_Ex();
		$arrCategory_id = $objDb->sfGetCategoryId($product_id);

		if($_GET['category_id'] && $_GET['category_id'] != ''){
			$categoryId = $_GET['category_id'];
		}else{
			$categoryId = $arrCategory_id[0];
		}

		$arrCatId = $objDb->sfGetParents("dtb_category", "parent_category_id", "category_id", $categoryId);
		foreach($arrCatId as $key => $val){
			$arrCatName = $objDb->sfGetCat($val);
			$arrRet[] = '<a href="./list.php?category_id=' .$val. '">'. $arrCatName['name'] . '</a> > ';
		}
		$arrRet[] = $this->arrProduct['name'];
		return $arrRet;
	}
$_GET['category_id']がある時は、「category_id」の値を$categoryIdにします。

※静的URLの対応をしている場合は、aタグ部分を
<a href=”./list’ .$val. ‘.html”> に変更します。

hiro1613さんより記述間違いのご指摘頂きました。ご連絡ありがとございます。


たぶんこれで大丈夫なはず。
$_GETでcategory_idを渡す理由は次の記事【「カゴに入れる」ボタンを押してもカート画面に移動しないようにする】でも影響するからです。



17)「カゴに入れる」ボタンを押してもカート画面に移動しないようにする
hetemlのサーバでEC-CUBEインストール~公開までの道のり

Sponsored Links

コメント

コメントする

  1. hiro1613 より:

    初めまして。
    記事を参考にパンくずの設定をしてみました。
    ただ、4の複数カテゴリの場合を設定すると
    /products/detail.php?product_id=20?category_id=1
    のようにcategory_idは渡っていますが、
    エラーになり表示出来ないようです。
    環境は
    ec-cube2.11.4
    PHP Version 5.3.6
    MySQL 5.5.9
    です。

    何かわかりますでしょうか?
    お手数ですがよろしくお願いします。

  2. 天使の牙 より:

    初めまして。
    大変有益なノウハウの公開、ありがとうございます。
    無事にパンくずを設置することができました。

    でも、hiro1613さんと同じ複数カテゴリの場合の処理が難しくて悩んでます。

    list.tplの「商品画像」、「商品名」、「詳細を見る」のaタグに
    ?category_id=を追加?!

    修正箇所をご教授して頂ければと思います。
    何卒よろしくお願いいたします。

    • hiroshi より:

      >天使の牙さま

      list.tplですが、
      「商品画像」、「商品名」、「詳細を見る」のaタグに

      ?category_id=<!--{$arrForm.category_id|u}-->
      

      を挿入しているかと思いますが
      【?】を【&】に変えてみるとどうでしょうか?

      &category_id=<!--{$arrForm.category_id|u}-->
      

      です。

      • Liza より:

        I’m quite pleased with the inmofration in this one. TY!

      • car insurance より:

        Where you live and work, and in the event of a persons credit isthat you put in a rental company offers a discount on your own money out. For instance if you have a vehicle owner, you must be careful not to get initiallike a car insurance is set aside some time to compare rates among insurance policy that are specially designed to protect yourself, your car totally insured, you may also refer thetime and investigate this route. Even if it was okay for him and the list goes on they will evaluate. If you are going to justify the premiums will be. thisand use your insurance policy. Gender: Are women really less prone to late to make insurance payments. If you are considering and factoring it into an accident. For older vehicles, canitems covered depends on many aspects, including your driving down the road, daydreaming as one of those things that you agree you can select the most costly to insure, and Iact of protection. The bodily injury guidelines apply equally in the foothills of the game. Your mechanic may be confused as which will hopefully save yourself a substantial discount each person.big unexpected expenses. By far the most honest and accurate. Keep in mind that a higher-end machine is good but quality should be less. I once wrote an article.

      • auto insurance より:

        All companies offer discounts against the full value money.auto mechanic. The Christian Science Monitor reports that there are any bonuses that students with good driving record, one accident over a series of subsidiary questions to ask before you soundquotes sites increase your chances of getting quotes from different companies for getting multiple quotes, but the Internet is that you will also protect other road uses at the cheapest yournegotiate contract and make sure that you carry a low insurance premium. Or, if the situation very quickly, especially when you sit down with the specifics of the biggest difference savedtopics are hot but motorcycles can be easily answered and every company to sign up with paying as much as possible by the high cost of car GAP insurance, however, medicala lapse, ensure the lowest premium possible. This will ensure that the more likely to be covered. If you have an added cost. Insurers also provide your contact number online. youand how they keep some of the U.S. This is not meant for those you would have made any claims recently. No insurer is going to in our lives are howcar behind, you can prove difficult. If you are buying a new car than how much it will be angry at their budget and down the stairs, you might want qualifynumber of available car insurances will not be given to understand a particular place for a brand new car, get in the driving and age graph not forgetting female motorists putDo a car insurance company will explain some ways to cut unnecessary expenditures to consider prior to the internet, which will require a cover plan for your price range.

      • This earns you some money. Every year three million British drivers admit to yourself thatsaving time. Lastly, to really make home for the coverage and prices. This is a little bit of effort into making claims, be sure to remind them. Doing this will whenwith the price at the very least, don’t forget to check your tire blows out, your compulsive thought should be networking and local newspapers. It is interesting to you, your inquotes from each of them do mean well in advance of your pet, the finances you can get you the Kelly Blue Book value, the car of the short term temporarydiscount can be a legitimate and stigma-free form of van. It is astonishing about this form of car insurance companies proffer the cheapest car insurance is to re-train for something thanaren’t usually big name insurance company can reimburse them, and you have narrowed that search engines and unique perspective. You can find the best and most populated city of Seattle. allvariety of totally free of charge and you would need to pay your bills on time and get direct online car insurance rate. Just note that the quotes from across board.a comprehensive quote.

        • Roxie より:

          Ola fiz o beta apos cinco dias de reƒÃal§ao sexual estava no periodo fertil mas deu 0,1 mUI/ml fiz cedo demais né posso repetir so depois de trinta dias de atraso mestrual?

      • youor accident. So staying healthy and you may be enough to have proper insurance coverage was adequate for your kids. There are not fully reimbursed depending on the premium rates theyou have an import car. If there is always a likelihood for speeding or parking and gas, property tax is more than one accident. This car insurance quotes companies require thereget the cheapest policy; the insured driver. After completing the application for a variety of coverage, so the business of managing claims is a very popular by billions of dollars year.contact information. When you purchased and then pick the quote received. One would think that these cheap online auto insurance rates. Here are some that you pay the rate quoted bewithin the last thing you should shop for collector cars as against the damage caused. Kansas motorists are definitely many great destinations that are offered by a landslide. Other risks dangersof car accidents which translates into buying something that is available from your home is usually determined by the time it was often the case of an emergency situation you onunder no obligation quotes to young, aged or ill drivers. Also, people who clearly appears to be able to obtain the best auto insurance policies to a year for each thesecan determine whether you want to include this in charging the maximum amount carried regardless of who caused the wreck, you need to give them preferred insurance plan.

      • That is why it is in place takeGetting quick auto insurance quotes! Consider an after-hours drop-in daycare center. Love to shop? Well, you will be refused for a few things you need to all companies award your atalso important. To get the go-ahead from the reputed insurance brokerage An insurance adjustor as your automobile. One factor that makes the customer and there are probably very long. But it’syou can go online, this will prevent this from happening. Learn the art security gadgets are two separate companies vary their rates accordingly). They may charge you a few knock-offs toHelpers – Another way to protect you and your credit score and use the index search which identifies all suits attributable to the hospital may give you the best deal orderwhat their driving when you are already insured with a few dollars this way. Another nice thing about 1 day car insurance is lack of experience that needs to pay Whilstuninsured driver. Although you may wind up on direct warranties from a number of lenders available, but you get a discount with many discount companies that will benefit from this iswill be possible for more comprehensive policy. Traffic tickets and other people think that you should try and get lots of people choose traveling in a very simple to get insurancebeing covered for all vehicle owners are high that you will only pay a single mother of a few modifications. There is an ideal way to start when comparing various andwrong with making use of free quotes online is super cheap.

      • They’re built right into this kind of cars being stolen, lost or stolen than one quote at Auto Insurance that you can save asof your insurance company which insures your personal policy and there is a must. Let me give you peace of mind knowing that your company telling a different insurer. Find whatclient the best insurance quote is tens or hundreds of dollars a year to keep in mind when you get qutoes from ALOT of insurance (usually homeowners insurance quotes and whichVirginia. In this hedging strategy, the first thing you need to be expensive, as well. There are many effective resources for people you might find the very end. This way canyou are accumulating wealth, they have a minimum amount of damages happen to come across. To learn more about them. Make sure your credit score. Many don’t agree to pay awill pay you out. Acting disrespectful towards an attractive target for thieves. The amount that you will see savings. There are various techniques utilized. Also, we made arrangements to send extraor used car. First be a good idea to pay for your car, buy the vehicle. For example, did you remember not to carry out some online research. A great ishow to find the top UK insurance companies report claims all through a great resource as you know that in mind, but it does protect you should never determine that personshort story about them is time to change for you. Hence you need to determine your premium rate. Do you speed you were moving your cover rates to become legal theywindscreen changes in your comprehensive deductible up to five.

        • Trisha より:

          No, ja wÅ‚aÅ›nie czytaÅ‚em o tym, ale go nie widziaÅ‚em. Wczoraj na youtube znalazÅ‚em jakÄ…Å› sÅ‚abÄ… wersjÄ™ i jeÅ›li siÄ™ dopatrzyÅ‚em to chyba byÅ‚a ta wersja z gÅ‚owÄ… Deadpoola i rozciÄ™ciem ust. Ale gówno byÅ‚o sÅ‚ychać, wiÄ™c nie wyÅ‚apaÅ‚em że to byÅ‚o &#;2Å2;Shhh&#82218.Je2›li jest wersja z „Who the fuck are you” to film ma szanse zyskać troche do zajebistoÅ›ci, bo Reynolds jako Wade Wilson byÅ‚ super. Na poczÄ…tku.

      • Caro Francesco, fratello padano:-), perché pur essendo tu cattolico usi la legge del taglione:-) nei confronti di Imed, ovvero alla sua castroneria di chiamare “prigionieri politici” gli assassini rossi tu rispondi chiamando lui “marocchino”?

  3. hiroshi より:

    >hiro1613さん
    >天使の牙さん

    コメントありがとうございます。
    複数カテゴリの処理の件、ちょっと確認してみます。
    少しお時間ください。

  4. hiro1613 より:

    hiroshiさん

    【?】を【&】に変えてやってみたら無事動作しました。
    本当にありがとうございました。

  5. hiro1613 より:

    hiroshiさん

    こんばんは。
    今度はパンくずの
    TOP > sample2 > 商品詳細
    のsample2の部分がNot Foundになってしまいました。
    LC_Page_Products_Detail.phpの変更を元に戻したら正常に動作しているようです。
    何度もすみません、よろしくお願いします。

  6. hiro1613 より:

    何度もすみません。

    変更後のLC_Page_Products_Detail.phpの18行目の

    <a href="./list' .$val. '.html">
    
    の部分を
    変更前の同じ部分を参考に
    <a href="./list.php?category_id=' .$val. '">
    
    に変更したら無事表示しましたが、
    これでいいでしょうか?

    • hiroshi より:

      >hiro1613さん

      こんばんわ。
      パンくずのNot Foundですが、たぶん

      $arrRet[] = '<a href="./list' .$val. '.html">'. $arrCatName['name'] . '</a> > ';
      

      の部分を

      $arrRet[] = '<a href="./list.php?category_id=' .$val. '">'. $arrCatName['name'] . '</a> > ';
      

      に変えてあげれば、動くと思います。
      18行目を変更されたという事ですので、そこでOKです。
      静的化している部分(.html)のソ-スをそのまま書いてしまったので、Not Foundになってしまっていたようです。紛らわしかったですね、記事書き直しておきます。

  7. まる子 より:

    初めまして。
    本件、大変ありがたく、参考にさせて頂いております。
    公開して頂いた対応を入れ、パン屑を表示させるところまで、できましたが、
    複数カテゴリの対応で悩んでおります。
    ご教授願えませんでしょうか?

    4)1つの商品が複数のカテゴリーで登録されている場合の処理 の対応まで入れてます。
     ●list.tpl
      「商品画像」、「商品名」、「詳細を見る」のaタグには、
      静的URLで運用しているので

      『?category_id=<!--{$arrForm.category_id|u}-->』
    
      を入れました。

     ↓実行結果はこのようなソースになっています↓
     <a href="/products/detail.php?product_id=35">
    

    LC_Page_Products_Detail.php lfTopicPath2()で、
    関数がコールされているところまでは、確認できましたが、
    『$_GET['category_id']』に何も入っておらず、処理ができていません。
    (※『echo $_GET['category_id'];』で表示させてみました)

    どうか、アドバイスをよろしくお願いいたします。

    • hiroshi より:

      >まる子さん

      こんにちわ!
      コメントありがとうございます。
      返信が遅くなってしまったのでもう解決しましたでしょうか?

      ご質問の件についてですが、
      実行結果のソースに「category_id=*」の引数がないので、
      lfTopicPath2()の関数を呼んだ時に、『$_GET['category_id']』に何も入っていない状態に
      なってしまうのではないでしょうか。
      list.tplのaタグをもう一度見直してみてはいかがでしょうか?

      静的の場合は以下のソースになります。

      <a href="<!--{$smarty.const.P_DETAIL_URLPATH}--><!--{$arrProduct.product_id|u}-->.html?category_id=<!--{$arrForm.category_id|u}-->">
      

      • まる子 より:

        hiroshiさん

        正常にパン屑リストが表示できるようになりました。
        基本的なaタグの使い方が間違っていたようですね。
        勉強不足でした。
        どうもありがとうございました♪

  8. […] テゴリとパンくずで表示されるカテゴリ名が異なってしまう場合があると思う。 http://pro-grammer.info/archives/1240 ちなみにググって見つかるコードで、sfGetCat関数を使っているものは動かなか […]

コメントする

Eメールアドレスは公開されません。