質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

Twig

Twig は、簡潔で可読性の高いテンプレートを記述することができ、 シンプルに記述することを目的として作られた PHPテンプレートエンジンです。

EC-CUBE

EC-CUBEは、主に日本国内で開発されているECコンテンツ管理システムです。ロックオン社のECKitを元にしてオープンソース化され、商品管理・受注管理・顧客管理・売上集計などECに特化した様々な機能を備えています。

Q&A

解決済

2回答

6473閲覧

商品一覧をindex.twigに表示する方法を教えてください。

sabamiso

総合スコア14

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

Twig

Twig は、簡潔で可読性の高いテンプレートを記述することができ、 シンプルに記述することを目的として作られた PHPテンプレートエンジンです。

EC-CUBE

EC-CUBEは、主に日本国内で開発されているECコンテンツ管理システムです。ロックオン社のECKitを元にしてオープンソース化され、商品管理・受注管理・顧客管理・売上集計などECに特化した様々な機能を備えています。

0グッド

1クリップ

投稿2018/02/27 15:05

やりたいこと

EC-CUBEのトップページで、登録している商品の一覧を表示したい。

試したこと

デフォルト(app/template/default/Product)にあるlist.twigの{% javascript %},{% block main %}の中身をindex.twigに転記↓

twig

1{% extends 'default_frame.twig' %} 2 3{% set body_class = 'front_page' %} 4 5{% block javascript %} 6<script> 7// 並び順を変更 8function fnChangeOrderBy(orderby) { 9 eccube.setValue('orderby', orderby); 10 eccube.setValue('pageno', 1); 11 eccube.submitForm(); 12} 13 14// 表示件数を変更 15function fnChangeDispNumber(dispNumber) { 16 eccube.setValue('disp_number', dispNumber); 17 eccube.setValue('pageno', 1); 18 eccube.submitForm(); 19} 20// 商品表示BOXの高さを揃える 21$(window).load(function() { 22 $('.product_item').matchHeight(); 23}); 24 25$(function(){ 26 $('.main_visual').slick({ 27 dots: true, 28 arrows: false, 29 autoplay: true, 30 speed: 300 31 }); 32}); 33</script> 34{% endblock %} 35 36{% block main %} 37 {% if search_form.category_id.vars.errors|length == 0 %} 38 <form name="form1" id="form1" method="get" action="?"> 39 {{ form_widget(search_form) }} 40 </form> 41 <!-- ▼topicpath▼ --> 42 <div id="topicpath" class="row"> 43 <ol id="list_header_menu"> 44 <li><a href="{{ url('product_list') }}">全商品</a></li> 45 {% if Category is not null %} 46 {% for Path in Category.path %} 47 <li><a href="{{ url('product_list') }}?category_id={{ Path.id }}">{{ Path.name }}</a></li> 48 {% endfor %} 49 {% endif %} 50 {% if search_form.vars.value.name %} 51 <li>{{ search_form.vars.value.name }}」の検索結果</li> 52 {% endif %} 53 </ol> 54 </div> 55 <!-- ▲topicpath▲ --> 56 <div id="result_info_box" class="row"> 57 <form name="page_navi_top" id="page_navi_top" action="?"> 58 {% if pagination.totalItemCount > 0 %} 59 <p id="result_info_box__item_count" class="intro col-sm-6"><strong><span id="productscount">{{ pagination.totalItemCount }}</span></strong>の商品がみつかりました。 60 </p> 61 62 <div id="result_info_box__menu_box" class="col-sm-6 no-padding"> 63 <ul id="result_info_box__menu" class="pagenumberarea clearfix"> 64 <li id="result_info_box__disp_menu"> 65 {{ form_widget(disp_number_form, {'id': '', 'attr': {'onchange': "javascript:fnChangeDispNumber(this.value);"}}) }} 66 </li> 67 <li id="result_info_box__order_menu"> 68 {{ form_widget(order_by_form, {'id': '', 'attr': {'onchange': "javascript:fnChangeOrderBy(this.value);"}}) }} 69 </li> 70 </ul> 71 </div> 72 73 {% for f in disp_number_form.getIterator %} 74 {% if f.vars.name matches '[^plg*]' %} 75 {{ form_label(f) }} 76 {{ form_widget(f) }} 77 {{ form_errors(f) }} 78 {% endif %} 79 {% endfor %} 80 81 {% for f in order_by_form.getIterator %} 82 {% if f.vars.name matches '[^plg*]' %} 83 {{ form_label(f) }} 84 {{ form_widget(f) }} 85 {{ form_errors(f) }} 86 {% endif %} 87 {% endfor %} 88 {% else %} 89 <p id="result_info_box__item_count" class="intro col-sm-6"><strong style="display: none;"><span id="productscount">{{ pagination.totalItemCount }}</span></strong>お探しの商品は見つかりませんでした。</p> 90 {% endif %} 91 </form> 92 </div> 93 94 <!-- ▼item_list▼ --> 95 <div id="item_list"> 96 <div class="row no-padding"> 97 {% for Product in pagination %} 98 <div id="result_list_box--{{ Product.id }}" class="col-sm-3 col-xs-6"> 99 <div id="result_list__item--{{ Product.id }}" class="product_item"> 100 <a href="{{ url('product_detail', {'id': Product.id}) }}"> 101 <div id="result_list__image--{{ Product.id }}" class="item_photo"> 102 <img src="{{ app.config.image_save_urlpath }}/{{ Product.main_list_image|no_image_product }}"> 103 </div> 104 <dl id="result_list__detail--{{ Product.id }}"> 105 <dt id="result_list__name--{{ Product.id }}" class="item_name">{{ Product.name }}</dt> 106 {% if Product.description_list %} 107 <dd id="result_list__description_list--{{ Product.id }}" class="item_comment">{{ Product.description_list|raw|nl2br }}</dd> 108 {% endif %} 109 {% if Product.hasProductClass %} 110 {% if Product.getPrice02Min == Product.getPrice02Max %} 111 <dd id="result_list__price02_inc_tax--{{ Product.id }}" class="item_price"> 112 {{ Product.getPrice02IncTaxMin|price }} 113 </dd> 114 {% else %} 115 <dd id="result_list__price02_inc_tax--{{ Product.id }}" class="item_price"> 116 {{ Product.getPrice02IncTaxMin|price }} {{ Product.getPrice02IncTaxMax|price }} 117 </dd> 118 {% endif %} 119 {% else %} 120 <dd id="result_list__price02_inc_tax--{{ Product.id }}" class="item_price">{{ Product.getPrice02IncTaxMin|price }}</dd> 121 {% endif %} 122 </dl> 123 </a> 124 </div> 125 </div> 126 {% endfor %} 127 </div> 128 129 </div> 130 <!-- ▲item_list▲ --> 131 {% if pagination.totalItemCount > 0 %} 132 {% include "pagination.twig" with { 'pages' : pagination.paginationData } %} 133 {% endif %} 134 {% else %} 135 <p class="errormsg text-danger">ご指定のカテゴリは存在しません。</p> 136 {% endif %} 137{% endblock %}

結果

トップページにアクセスした際に、システムにエラーが出ました。と表示されました。

商品一覧を表示する方法は、なんでもよいのですが、有識者の方、良ければ教えていただきたいです

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

自己解決

list.twigのコピーとともに、src/eccube/controller/prodouctcontrollerをtopcontlloerへコピペすると、簡易だが、index.twigに表示される

投稿2018/02/27 16:51

sabamiso

総合スコア14

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

(ページレイアウト)ブロックの機能を使うか、イベントリスナーを使いましょう。

ブロックの利用
イベント

投稿2018/02/27 15:14

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

sabamiso

2018/02/27 15:22

ブロックの利用ということは、独自のブロックを作成→登録して、使うという認識でよろしいでしょうか。 また、全件の商品情報は「search_form.category_id.vars.errors」で呼び出しいると思っているのですが、認識はあってますでしょうか。
退会済みユーザー

退会済みユーザー

2018/02/27 15:34

なんでもいいんじゃないのかい?
退会済みユーザー

退会済みユーザー

2018/02/27 15:36

あなたが行ったPHPソース側のカスタマイズもしらんしな
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問