{#
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') }}">
<style>
.tab {
margin: 100px 10% 0;
}
.tab-list {
display: flex;
gap: 1px;
}
.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;
padding: 0.5em 1.2em;
color: #FFF;
cursor: pointer;
}
.tab-content {
display: flex;
justify-content: space-between;
border: solid 1px #09860D;
border-radius: 0 8px 8px 8px;
}
.tab-panel {
display: none;
}
.tab-item.active {
background-color: #fff;
color: #09860D;
font-weight: bold;
position: relative;
}
.tab-item.active::before{
content: "";
width: 100%;
border-bottom: 1px solid #FFF;
position: absolute;
bottom: -1px;
left: 0;
}
.tab-panel.active {
display: block;
padding: 3%;
}
.tab-panel.active h2 {
font-size: 20px;
font-weight: bold;
}
</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()
});
// タブの見出し(tab-item)を取得
const tabItems = document.querySelectorAll(".tab-item");
let activeTabId = document.querySelector(".tab-item.active").id;
document.querySelector(".category-btn").value = activeTabId;
tabItems.forEach((tabItem) => {
tabItem.addEventListener("click", () => {
// すべてのタブを非アクティブにする
tabItems.forEach((t) => {
t.classList.remove("active");
});
// すべてのコンテンツを非表示にする
const tabPanels = document.querySelectorAll(".tab-panel");
tabPanels.forEach((tabPanel) => {
tabPanel.classList.remove("active");
});
// クリックされたタブをアクティブにする
tabItem.classList.add("active");
//アクティブになったタブのidを取得して、buttonのvalueにいれる
activeTabId = document.querySelector(".tab-item.active").id;
document.querySelector(".category-btn").value = activeTabId;
// 対応するコンテンツを表示
const tabIndex = Array.from(tabItems).indexOf(tabItem);
tabPanels[tabIndex].classList.add("active");
});
});
document.getElementById('category-form').addEventListener('submit', function(e) {
const selects = this.querySelectorAll('select[name="category_ids[]"]');
const nonActiveSelects = document.querySelectorAll('.tab-panel:not(.active) select');
selects.forEach(select => {
if (select.value === '') {
select.disabled = true; // 空なら無効にして送らない
}
});
nonActiveSelects.forEach(select =>{
select.disabled = true; //activeを親にactiveを持たないselectは無効
});
});
</script>
{% endblock %}
{% block main %}
<!-- カテゴリ検索 -->
{% set Categories = repository('Eccube\\Entity\\Category').getList() %}
{% set selected_categories = app.request.query.get('category_ids', []) %}
{% set parent_category = app.request.query.get('parent_category', []) %}
{% if app.request.query.get('category_id') not in [7, 8] %}
<form action="{{ url('product_list') }}" method="get" class="tab" id="category-form">
<ul class="tab-list">
{% for tab in Categories|slice(0, 3)%}
{% set children_ids = [] %}
{% for Child in tab.Children %}
{% set children_ids = children_ids|merge([Child.id]) %}
{% endfor %}
{% if tab.id == app.request.query.get('category_id')
or tab.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="{{tab.id}}">{{tab.name}}</li>
{% else %}
<li class="tab-item" tabindex="0" id="{{tab.id}}">{{tab.name}}</li>
{% endif %}
{% endfor %}
</ul>
<div class="tab-content">
{% for Category in Categories|slice(0, 3)%}
{% set children_ids = [] %}
{% for Child in Category.Children %}
{% set children_ids = children_ids|merge([Child.id]) %}
{% endfor %}
{% if Category.id == app.request.query.get('category_id')
or Category.id == app.request.query.get('search_parent_id')
or app.request.query.get('category_id') in children_ids
%}
<div class="tab-panel active">
{% for Child in Category.Children%}
<select name="category_ids[]">
<option value="">{{Child.name}}から選択</option>
{% for grandchild in Child.Children %}
<option value="{{grandchild.id}}"
{% if grandchild.id in selected_categories %}
selected
{% endif %}
>{{grandchild.name}}</option>
{% endfor %}
</select>
{% endfor %}
</div>
{% else %}
<div class="tab-panel">
<div>
{% for Child in Category.Children%}
<select name="category_ids[]">
<option value="" selected>{{Child.name}}から選択</option>
{% for grandchild in Child.Children %}
<option value="{{grandchild.id}}">{{grandchild.name}}</option>
{% endfor %}
</select>
{% endfor %}
</div>
</div>
{% endif %}
{% endfor %}
<button type="submit" class="category-btn" name="search_parent_id" value="">
<img src="{{ asset('/html/user_data/assets/icon/btn_ic_search.svg ', 'user_data') }}" alt="お気に入り">
カテゴリ検索
</button>
</div>
</form>
{% endif %}
<section class="contents-list">
{#<form name="form1" id="form1" method="get" action="?">#}
{# {% for item in search_form %}#}
{# <input type="hidden" id="{{ item.vars.id }}"#}
{# name="{{ item.vars.full_name }}"#}
{# {% if item.vars.value is not empty %}value="{{ item.vars.value }}" {% endif %}/>#}
{# {% endfor %}#}
{#</form>#}
<!-- 商品リスト -->
<div class="list-view">
<div class="list-title">
{% if Category is not null %}
{% for Path in Category.path|slice(0, 1) %}
<h2 class="ec-topicpath__item">{{ Path.name }}</h2>
{% endfor %}
{% endif %}
{% if pagination.totalItemCount > 0 %}
{{ '<p>%count%冊</p>'|trans({ '%count%': pagination.totalItemCount })|raw }}
{% else %}
<p>{{ 'お探しの商品は見つかりませんでした'|trans }}</p>
{% endif %}
</div>
<!-- カテゴリ説明 -->
{#<p class="lead-sentence">テキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキスト</p>#}
<!-- リストエリア -->
{% if pagination.totalItemCount > 0 %}
<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 }}税込
</p>
</a>
</div>
{% endfor %}
<!-- ページネーション -->
{% 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 %}