バージョン選択

フォーラム

メニュー

オンライン状況

70 人のユーザが現在オンラインです。 (59 人のユーザが フォーラム を参照しています。)
登録ユーザ: 0
ゲスト: 70
もっと...

サイト内検索

質問 > 管理機能 > eccube 孫カテゴリの取得について

管理機能

新規スレッドを追加する

スレッド表示 | 新しいものから 前のトピック | 次のトピック | 下へ
投稿者 スレッド
r.ts
投稿日時: 2024/3/12 17:50
対応状況: −−−
半人前
登録日: 2024/2/29
居住地:
投稿: 11
eccube 孫カテゴリの取得について
▼テンプレート
[EC-CUBE] EC-CUBE4.2

下記のコードから商品一覧ページにて、カテゴリーの取得をしています。取得はうまくいき孫カテゴリーまで表示はできたのですがツリー構造にできません。

{% if Category is not null %}

        
        {% set cate_childs = Category.getDescendants %}
            <div id="cate_list">
            <h2 class="cate_h2">{{ subtitle }} カテゴリー一覧</h2>
            <ul class="cate_list">
            {% for cate in cate_childs %}
              <li><a href="/products/list?category_id={{ cate.id }}">{{ cate.name }}</a></li>
            {% endfor %}
            </ul>
        </div>
        
        
    {% endif %}



<ul>
<li>子カテゴリ</li>
<li>孫カテゴリ</li>
<li>孫カテゴリ</li>
</ul>


という感じではなく


<ul>
<li>子カテゴリ
<ul>
<li>孫カテゴリ</li>
<li>孫カテゴリ</li>
</ul>
</li>
</ul>


と出力させたいです。

[{dump(cate)}}でみると
Eccube\Entity\Category {#4070 ▼
  -id: 13
  -name: "子カテゴリ"
  -hierarchy: 2
  -sort_no: 12
  -create_date: DateTime @1703560681 {#4066 ▶}
  -update_date: DateTime @1703560681 {#4067 ▶}
  -ProductCategories: Doctrine\ORM\PersistentCollection {#4071 ▶}
  -Children: Doctrine\ORM\PersistentCollection {#4074 ▼
    #collection: Doctrine\Common\Collections\ArrayCollection {#4073 ▼
      -elements: array:2 [▼
        0 => Eccube\Entity\Category {#4110 ▼
          -id: 22
          -name: "孫カテゴリ"
          -hierarchy: 3
          -sort_no: 11
          -create_date: DateTime @1705554801 {#4068 ▶}
          -update_date: DateTime @1705554801 {#4069 ▶}
          -ProductCategories: Doctrine\ORM\PersistentCollection {#4108 ▶}
          -Children: Doctrine\ORM\PersistentCollection {#4112 ▶}
          -Parent: Eccube\Entity\Category {#4070}
          -Creator: Proxies\__CG__\Eccube\Entity\Member {#4105 ▶}
        }
        1 => Eccube\Entity\Category {#4117 ▼
          -id: 21
          -name: "孫カテゴリ"
          -hierarchy: 3
          -sort_no: 10
          -create_date: DateTime @1705554785 {#4115 ▶}
          -update_date: DateTime @1705554785 {#4116 ▶}
          -ProductCategories: Doctrine\ORM\PersistentCollection {#4118 ▶}
          -Children: Doctrine\ORM\PersistentCollection {#4121 ▶}
          -Parent: Eccube\Entity\Category {#4070}
          -Creator: Proxies\__CG__\Eccube\Entity\Member {#4105 ▶ …2}
        }
      ]
    }
    #initialized: true
    -snapshot: array:2 [ …2]
    -owner: Eccube\Entity\Category {#4070}
    -association: array:16 [ …16]
    -em: Doctrine\ORM\EntityManager {#363 …11}
    -backRefFieldName: "Parent"
    -typeClass: Doctrine\ORM\Mapping\ClassMetadata {#3625 …}
    -isDirty: false
  }
  -Parent: Eccube\Entity\Category {#4079 ▼
    -id: 7
    -name: "親カテゴリ"
    -hierarchy: 1
    -sort_no: 14
    -create_date: DateTime @1701416829 {#4083 ▶}
    -update_date: DateTime @1701739207 {#4082 ▶}
    -ProductCategories: Doctrine\ORM\PersistentCollection {#4078 ▶}
    -Children: Doctrine\ORM\PersistentCollection {#4075 ▶}
    -Parent: null
    -Creator: Proxies\__CG__\Eccube\Entity\Member {#4105 ▶ …2}
  }
  -Creator: Proxies\__CG__\Eccube\Entity\Member {#4105 ▶ …2}
}


とでており
子カテゴリの取得はできてそうなので、表示はできるのかなと思うのですがいまいちわかれません。

親カテゴリは、{{cate.Parent.neme}}
などで表示できるのですが、、孫カテゴリはどのように取得したらうまくツリー構造にできますでしょうか









yuh
投稿日時: 2024/3/12 18:16
対応状況: −−−
登録日: 2013/1/9
居住地: 大阪
投稿: 1819
Re: eccube 孫カテゴリの取得について
hierarchyを見ればできるかもです。
親:hierarchy =1
子:hierarchy =2
孫:hierarchy =3


----------------


http://ec-lab.net/

スレッド表示 | 新しいものから 前のトピック | 次のトピック | トップ


 



ログイン


EC-CUBE公式 Amazon Payプラグイン

統計情報

総メンバー数は88,894名です
総投稿数は110,002件です

投稿数ランキング

1
seasoft
7367
2
468
3217
3
AMUAMU
2712
4
nanasess
2313
5
umebius
2085
6
yuh
1819
7
h_tanaka
1646
8
red
1570
9
mcontact
1295
10
tsuji
958
11
fukap
907
12
shutta
835
13
tao_s
799
14 ramrun 789
15 karin 689
16 sumida 641
17
homan
633
18 DELIGHT 572
19
patapata
502
20
flealog
485


ネットショップの壺

EC-CUBEインテグレートパートナー

Copyright© EC-CUBE CO.,LTD. All Rights Reserved.