{#
This file is part of EC-CUBE
Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
http://www.ec-cube.co.jp/
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
#}
{% extends 'default_frame.twig' %}
{% block stylesheet %}
{#<link rel="stylesheet" href="{{ asset('assets/css/contents-list.css', 'user_data') }}">#}
{#<link rel="stylesheet" href="{{ asset('assets/css/main_module.css', 'user_data') }}">#}
<link rel="stylesheet" href="{{ asset('assets/css/page/_product_list.css', 'user_data') }}">
<style>
.ec-topicpath{
display: flex;
margin: 30px 10% 0;
}
.ec-topicpath a{
color: #09860D;
}
.ec-topicpath__divider{
margin: 0 5px;
}
.category-btn{
justify-content: center;
}
.category-btn img{
margin-right: 15px;
}
.tab {
margin: 30px 10% 0;
}
@media screen and (max-width:768px){
.tab img{
width: 15%;
}
.category-btn{
margin-bottom: 15px;
}
}
.tab-list {
display: flex;
gap: 1px;
}
@media screen and (max-width:768px){
.tab-list{
flex-direction: column;
}
}
.tab-item {
border-radius: 5px 5px 0 0;
background-color: #09860D;
border-top: solid 1px #09860D;
border-right: solid 1px #09860D;
border-left: solid 1px #09860D;
}
.tab-item a{
color: #FFF;
padding: 0.5em 1.2em;
display: block;
}
.tab-content:has(.tab-panel.active){
display: flex;
justify-content: space-between;
border-top:solid 1px #09860D;
border-right:solid 1px #09860D;
border-left:solid 1px #09860D;
border-radius: 0 8px 0 0;
}
.tab-content:not(:has(.tab-panel.active)){
display: none;
}
@media screen and (max-width:768px){
.tab-content{
flex-direction: column;
border-radius: 0;
}
}
.tab-panel {
display: none;
}
.tab-item.active {
background-color: #fff;
font-weight: bold;
position: relative;
}
.tab-item.active a{
color: #09860D;
}
.tab-item.active::before{
content: "";
width: 100%;
border-bottom: 1px solid #FFF;
position: absolute;
bottom: -1px;
left: 0;
}
.tab-panel.active {
display: flex;
padding: 3%;
flex-wrap: wrap;
gap:20px 20px;
flex: 10;
}
@media screen and (max-width:768px){
.tab-panel.active{
justify-content: center;
}
}
.tab-panel.active h2 {
font-size: 20px;
font-weight: bold;
}
.search-form-box{
border: solid 1px #09860D;
border-radius: 0 0 8px 8px;
}
.tab-content:not(:has(.active)) + .search-form-box{
border-radius: 0 8px 8px 8px;
}
.search-form-box .search-form-content{
display: flex;
justify-content: space-between;
}
@media screen and (max-width:768px){
.search-form-box .search-form-content{
flex-direction: column;
}
}
.search-form-box .search-form-item{
padding: 3%;
}
@media screen and (max-width:768px){
.search-form-box .search-form-item{
margin: 0 auto;
}
}
.search-form-box .search-form-input{
-webkit-appearance: none;
-moz-appearance:none;
appearance: none;
border:1px solid #09860d;
border-radius:25px;
width: 30vw;
padding-left: 20px;
height: 36px;
background-color: #f5f5f5;
}
@media screen and (max-width:768px){
.search-form-box .search-form-input{
width: 50vw;
box-sizing: border-box;
}
.search-form-box .search-form-input::placeholder{
font-size: 2vw;
}
}
select{
background:none;
appearance: none;
font:inherit;
padding:9.5px 10px;
border:1px solid #09860d;
box-sizing: border-box;
width: 250px;
border-radius:2px;
}
.select {
display: inline-block;
position: relative;
vertical-align: middle;
}
.select::before {
position: absolute;
top: 18px;
right: 16px;
width: 0;
height: 0;
border-width: 10px 5px 0 5px;
border-style: solid;
border-color: #09860d transparent transparent transparent;
content: "";
pointer-events: none;
}
</style>
{% endblock %}
{% set body_class = 'product_page' %}
{% block javascript %}
<script>
eccube.productsClassCategories = {
{% for Product in pagination %}
"{{ Product.id|escape('js') }}": {{ class_categories_as_json(Product)|raw }}{% if loop.last == false %}, {% endif %}
{% endfor %}
};
$(function() {
// 表示件数を変更
$('.disp-number').change(function() {
var dispNumber = $(this).val();
$('#disp_number').val(dispNumber);
$('#pageno').val(1);
$("#form1").submit();
});
// // 並び順を変更
$('.order-by').change(function() {
var orderBy = $(this).val();
$('#orderby').val(orderBy);
$('#pageno').val(1);
$("#form1").submit();
});
$('.add-cart').on('click', function(e) {
var $form = $(this).parents('li').find('form');
// 個数フォームのチェック
var $quantity = $form.parent().find('.quantity');
if ($quantity.val() < 1) {
$quantity[0].setCustomValidity('{{ '1以上で入力してください。'|trans }}');
setTimeout(function() {
loadingOverlay('hide');
}, 100);
return true;
} else {
$quantity[0].setCustomValidity('');
}
e.preventDefault();
$.ajax({
url: $form.attr('action'),
type: $form.attr('method'),
data: $form.serialize(),
dataType: 'json',
beforeSend: function(xhr, settings) {
// Buttonを無効にする
$('.add-cart').prop('disabled', true);
}
}).done(function(data) {
// レスポンス内のメッセージをalertで表示
$.each(data.messages, function() {
$('#ec-modal-header').html(this);
});
$('.ec-modal').show()
// カートブロックを更新する
$.ajax({
url: '{{ url('block_cart') }}',
type: 'GET',
dataType: 'html'
}).done(function(html) {
$('.ec-headerRole__cart').html(html);
});
}).fail(function(data) {
alert('{{ 'カートへの追加に失敗しました。'|trans }}');
}).always(function(data) {
// Buttonを有効にする
$('.add-cart').prop('disabled', false);
});
});
});
$('.ec-modal-wrap').on('click', function(e) {
// モーダル内の処理は外側にバブリングさせない
e.stopPropagation();
});
$('.ec-modal-overlay, .ec-modal, .ec-modal-close, .ec-inlineBtn--cancel').on('click', function() {
$('.ec-modal').hide()
});
</script>
<script>
// 絞り込み検索は、絞り込み検索ボタンが押されたとき、もしくは入力欄にフォーカスされたときに、
// enterを押したときのみ発動する。カテゴリ検索を押したときは発火させない
document.addEventListener('DOMContentLoaded', function () {
const form = document.querySelector('.tab');
const categoryBtn = form.querySelector('button[name="search_parent_id"]:not(.word-search)');
const wordBtn = form.querySelector('.category-btn.word-search');
const wordInput = form.querySelector('input.search-form-input');
// カテゴリ検索 → name を送らせない
categoryBtn.addEventListener('click', function () {
if (wordInput) {
wordInput.disabled = true;
}
});
// 絞り込み検索 → name を有効化
wordBtn?.addEventListener('click', function () {
if (wordInput) {
wordInput.disabled = false;
}
});
// Enterキーで submit 時に絞り込み検索の値を送信するための hidden input 挿入
form.addEventListener('submit', function (e) {
if (document.activeElement === wordInput) {
e.preventDefault();
// 既に存在していたら除去(2重防止)
const existingHidden = form.querySelector('input[name="search_parent_id"].auto-injected');
if (existingHidden) {
existingHidden.remove();
}
// ボタンのvalue属性をそのまま使う
const valueFromButton = wordBtn?.getAttribute('value') || '';
const hidden = document.createElement('input');
hidden.type = 'hidden';
hidden.name = 'search_parent_id';
hidden.value = valueFromButton;
hidden.classList.add('auto-injected');
form.appendChild(hidden);
if (wordInput) {
wordInput.disabled = false;
}
form.submit();
}
});
});
// カテゴリの詳細検索に値が入っていない場合、buttonのnameの値をcategory_idに変更する
document.addEventListener('DOMContentLoaded', function () {
const form = document.querySelector('.tab');
const submitBtn = form.querySelector('button.category-btn');
const categorySelects = form.querySelectorAll('select[name="category_ids[]"]');
form.addEventListener('submit', function (e) {
// category_ids[] に選択されている値が1つもない場合、ボタンのnameを変更
const hasValue = Array.from(categorySelects).some(select => select.value && select.value !== '');
if (!hasValue) {
submitBtn.setAttribute('name', 'category_id');
} else {
submitBtn.setAttribute('name', 'search_parent_id');
}
});
});
</script>
{% endblock %}
{% block main %}
{% set AllCategories = repository('Eccube\\Entity\\Category').getList() %}
{% set Categories = AllCategories|filter(c => c.id is not null and c.id == 1) %}
{% set selected_categories = app.request.query.get('category_ids', []) %}
{% set parent_category = app.request.query.get('search_parent_id') %}
{#パンくず#}
<div class="ec-searchnavRole__topicpath">
<ol class="ec-topicpath">
<li class="ec-topicpath__item"><a href="{{ url('product_list') }}">{{ 'front.product.all_category'|trans }}</a>
</li>
{% if Category is not null %}
{% for Path in Category.path %}
{% if not loop.first %}
<li class="ec-topicpath__divider">></li>
<li class="ec-topicpath__item{% if loop.last %}--active{% endif %}">
<a href="{{ url('product_list') }}?category_id={{ Path.id }}">{{ Path.name }}</a>
</li>
{% endif %}
{% endfor %}
{% endif %}
{% if selected_categories %}
{% set first_matched = true %}
{% for Category in Categories %}
{% for children in Category.Children %}
{% if children.id == parent_category %}
<li class="ec-topicpath__divider">></li>
<li><a href="{{ url('product_list') }}?category_id={{ children.id }}">{{ children.name }}</a></li>
{% endif %}
{% for grandChildren in children.Children %}
{% for grandgrandChild in grandChildren.Children %}
{% if grandgrandChild.id in selected_categories %}
{% if first_matched %}
<li class="ec-topicpath__divider">></li>
<li><a href="{{ url('product_list') }}?category_ids[]={{ grandgrandChild.id }}&search_parent_id={{parent_category}}">{{ grandgrandChild.name }}</a></li>
{% set first_matched = false %}
{% else %}
<li><a href="{{ url('product_list') }}?category_ids[]={{ grandgrandChild.id }}&search_parent_id={{parent_category}}">・{{ grandgrandChild.name }}</a></li>
{% endif %}
{% endif %}
{% endfor %}
{% endfor %}
{% endfor %}
{% endfor %}
{% endif %}
{% if search_form.vars.value.name %}
<li class="ec-topicpath__divider">></li>
<li class="ec-topicpath__item"><a href="{{ url('product_list') }}?name={{ search_form.vars.value.name }}">{{ search_form.vars.value.name }}</a></li>
{% endif %}
</ol>
</div>
<!-- カテゴリ検索 -->
{% if app.request.query.get('category_id') or app.request.query.get('search_parent_id') %}
<form action="{{ url('product_list') }}" method="get" class="tab" >
<ul class="tab-list">
{% for tab in Categories%}
{% for children in tab.Children %}
{% set children_ids = [] %}
{% for grandChild in children.Children %}
{% set children_ids = children_ids|merge([grandChild.id]) %}
{% endfor %}
{% if children.id == app.request.query.get('category_id')
or children.id == app.request.query.get('search_parent_id')
or app.request.query.get('category_id') in children_ids
%}
<li class="tab-item active" tabindex="0" id="{{children.id}}">
<a href="{{ url('product_list', {'category_id': children.id}) }}">{{children.name}}</a>
</li>
{% else %}
<li class="tab-item" tabindex="0" id="{{children.id}}">
<a href="{{ url('product_list', {'category_id': children.id}) }}">{{children.name}}</a>
</li>
{% endif %}
{% endfor %}
{% endfor %}
</ul>
<div class="tab-content" id="category-form">
{% for Category in Categories%}
{% for children in Category.Children %}
{% set children_ids = [] %}
{% for grandChild in children.Children %}
{% set children_ids = children_ids|merge([grandChild.id]) %}
{% endfor %}
{% if (children.id == app.request.query.get('category_id')
or children.id == app.request.query.get('search_parent_id')
or app.request.query.get('category_id') in children_ids)
and children.Children is not empty
%}
<div class="tab-panel active">
{% for grandChild in children.Children%}
<div class=select>
<select name="category_ids[]">
<option value="">{{grandChild.name}}から選択</option>
{% for grandgrandchild in grandChild.Children %}
<option value="{{grandgrandchild.id}}"
{% if grandgrandchild.id in selected_categories %}
selected
{% endif %}
>{{grandgrandchild.name}}</option>
{% endfor %}
</select>
</div>
{% endfor %}
</div>
<button type="submit" class="category-btn" name="search_parent_id"
{% if app.request.query.get('category_id') or app.request.query.get('search_parent_id') %}
value="{{ app.request.query.get('category_id') ?: app.request.query.get('search_parent_id') }}"
>
{% endif %}
<img src="{{ asset('/html/user_data/assets/icon/btn_ic_search.svg ', 'user_data') }}" alt="お気に入り">
カテゴリ検索
</button>
{% else %}
<div class="tab-panel"></div>
{% endif %}
{% endfor %}
{% endfor %}
</div>
<div class="search-form-box">
<div class="search-form-content">
<div class="search-form-item">
<input type="text" name="name" class="search-form-input"
placeholder="カテゴリから絞り込み"
{% if search_form.vars.value.name
and (app.request.query.get('search_parent_id') is not empty or app.request.query.get('category_id') is not empty) %}
value="{{ search_form.vars.value.name }}"
{% endif %}
>
</div>
<button type="submit" class="category-btn word-search" name="search_parent_id"
{% if app.request.query.get('category_id') or app.request.query.get('search_parent_id') %}
value="{{ app.request.query.get('category_id') ?: app.request.query.get('search_parent_id') }}"
>
{% endif%}
<img src="{{ asset('/html/user_data/assets/icon/btn_ic_search.svg ', 'user_data') }}" alt="お気に入り">
絞り込み検索
</button>
</div>
</div>
</form>
{% endif %}
<section class="contents-list">
<!-- 商品リスト -->
<div class="list-view">
<div class="list-title">
{#カテゴリが存在しない(全体検索の場合)#}
{% if search_form.vars.value.name
and app.request.query.get('category_id') is empty
and app.request.query.get('search_parent_id') is empty%}
<h2 class="ec-topicpath__item">「{{ search_form.vars.value.name }}」で検索</h2>
{% endif %}
{#カテゴリが存在する場合(単純にカテゴリナビから言った場合など)#}
{% if Category is not null %}
<h2 class="ec-topicpath__item">{{ Category.name }}</h2>
{% if search_form.vars.value.name %}
<p class="ec-topicpath__item">> {{ search_form.vars.value.name }}</p>
{% endif %}
{% endif %}
{#カテゴリの詳細検索を使った場合#}
{% if selected_categories %}
{% set first_matched = true %}
{% for firstCategory in Categories %}
{% for Category in firstCategory.Children %}
{% if Category.id == parent_category %}
<h2 class="ec-topicpath__item">{{ Category.name }}</h2>
{% endif %}
{% for Child in Category.Children %}
{% for GrandChildren in Child.Children %}
{% if GrandChildren.id in selected_categories %}
{% if first_matched %}
<p class="ec-topicpath__item">> {{ GrandChildren.name }}</p>
{% set first_matched = false %}
{% else %}
<p class="ec-topicpath__item">・ {{ GrandChildren.name }}</p>
{% endif %}
{% endif %}
{% endfor %}
{% endfor %}
{% endfor %}
{% endfor %}
{% if search_form.vars.value.name %}
<p class="ec-topicpath__item">> {{ search_form.vars.value.name }}</p>
{% endif %}
{% endif %}
{% if pagination.totalItemCount > 0 %}
{{ '<p>(%count%冊)</p>'|trans({ '%count%': pagination.totalItemCount })|raw }}
{% else %}
<p>{{ 'お探しの商品は見つかりませんでした'|trans }}</p>
{% endif %}
</div>
<!-- リストエリア -->
{% if pagination.totalItemCount|length > 0 %}
<div>
<div class="list-area">
{% for Product in pagination %}
<div class="card-1">
<a href="{{ url('product_detail', {'id': Product.id}) }}">
<img src="{{ asset(Product.main_list_image|no_image_product, 'save_image') }}" alt="{{ Product.name }}" {% if loop.index > 5 %} loading="lazy"{% endif %}>
<h3>{{ Product.name }}</h3>
<p class="price02-default">
{{ Product.getPrice02IncTaxMin|price }}<span class="tax">(税込)</span>
</p>
</a>
</div>
{% endfor %}
</div>
<!-- ページネーション -->
{% set pages = pagination.paginationData %}
{% if pages.pageCount > 1 %}
<div class="ec-pager pagination">
{# 前へ #}
{% if pages.previous is defined %}
<a class="page-return" href="{{ path(
app.request.attributes.get('_route'),
app.request.query.all|merge({'pageno': pages.previous})) }}">←</a>
{% endif %}
<div class="page-num">
{% for page in pages.pagesInRange %}
{% if page == pages.current %}
<a class="active" href="{{ path(
app.request.attributes.get('_route'),
app.request.query.all|merge({'pageno': page})) }}"> {{ page }} </a>
{% else %}
<a href="{{ path(
app.request.attributes.get('_route'),
app.request.query.all|merge({'pageno': page})) }}"> {{ page }} </a>
{% endif %}
{% endfor %}
</div>
{# 次へ #}
{% if pages.next is defined %}
<a class="page-advance" href="{{ path(
app.request.attributes.get('_route'),
app.request.query.all|merge({'pageno': pages.next})) }}">→</a>
{% endif %}
</div>
{% endif %}
</div>
{% endif %}
</div>
</section>
{% endblock %}