{#
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' %}
{% set body_class = 'product_page' %}
{# style #}
{% block stylesheet %}
<link rel="stylesheet" href="{{ asset('assets/css/product-list.css') }}">
{% endblock %}
{% block javascript %}
<script>
(function() {
// Lấy URL hiện tại và tạo URLSearchParams
function getCurrentUrlParams() {
const urlParams = new URLSearchParams(window.location.search);
return urlParams;
}
// Cập nhật URL với category filters và reload
function updateCategoryFilters() {
const checkboxes = document.querySelectorAll('.filter-option__checkbox');
const urlParams = getCurrentUrlParams();
// Xóa tất cả category_filter[] cũ (có thể có nhiều giá trị)
const keysToDelete = [];
urlParams.forEach(function(value, key) {
if (key === 'category_filter[]' || key.startsWith('category_filter')) {
keysToDelete.push(key);
}
});
keysToDelete.forEach(function(key) {
urlParams.delete(key);
});
// Thu thập các category IDs đã được chọn
const selectedCategoryIds = [];
checkboxes.forEach(function(checkbox) {
if (checkbox.checked) {
selectedCategoryIds.push(checkbox.value);
}
});
// Chỉ thêm category_filter[] nếu có ít nhất một checkbox được chọn
if (selectedCategoryIds.length > 0) {
selectedCategoryIds.forEach(function(categoryId) {
urlParams.append('category_filter[]', categoryId);
});
}
// Reset về trang 1 khi filter
urlParams.set('pageno', '1');
// Tạo URL mới
const queryString = urlParams.toString();
const newUrl = queryString
? window.location.pathname + '?' + queryString
: window.location.pathname;
// Reload page với query params mới
window.location.href = newUrl;
}
// Khôi phục trạng thái checkbox từ URL và xử lý nút search
document.addEventListener('DOMContentLoaded', function() {
const checkboxes = document.querySelectorAll('.filter-option__checkbox');
const searchButton = document.querySelector('.btn-search');
// Khôi phục trạng thái checkbox từ URL
const urlParams = getCurrentUrlParams();
const selectedCategories = urlParams.getAll('category_filter[]');
checkboxes.forEach(function(checkbox) {
// Set checked nếu category ID có trong URL
if (selectedCategories.includes(checkbox.value)) {
checkbox.checked = true;
}
// Không lắng nghe sự kiện change trên checkbox nữa
});
// Lắng nghe sự kiện click trên nút search
if (searchButton) {
searchButton.addEventListener('click', function() {
updateCategoryFilters();
});
}
});
})();
</script>
{% endblock %}
{% block main %}
<body>
<!-- breadcrumb section -->
<div class="breadcrumb-section">
<div class="container-1360 border-box px-40">
<nav class="breadcrumb">
<a href="#" class="breadcrumb__item text-black">ホーム</a>
<img src="{{ asset('assets/img/default/icons/icon-breadcrumb-arrow.svg') }}" alt=">" class="breadcrumb__separator">
<a href="#" class="breadcrumb__item text-black">商品一覧</a>
</nav>
</div>
</div>
<!-- product list section -->
<div class="container-1200">
<div class="product-list-wrapper">
<div class="product-list-left">
{% if searchable_categories is defined and searchable_categories|length > 0 %}
{% for group in searchable_categories %}
<div class="filter-group">
<div class="filter-group__header">{{ group.parent.name }}</div>
<div class="filter-group__options">
{% if group.children|length > 0 %}
{% for child in group.children %}
<label class="filter-option">
<input type="checkbox"
class="filter-option__checkbox"
name="category_filter[]"
value="{{ child.id }}"
data-category-id="{{ child.id }}">
<span class="filter-option__label">{{ child.name }}</span>
</label>
{% endfor %}
{% else %}
{# Nếu parent category cũng có is_searchable và không có children, hiển thị parent #}
<label class="filter-option">
<input type="checkbox"
class="filter-option__checkbox"
name="category_filter[]"
value="{{ group.parent.id }}"
data-category-id="{{ group.parent.id }}">
<span class="filter-option__label">{{ group.parent.name }}</span>
</label>
{% endif %}
</div>
</div>
{% endfor %}
{% endif %}
<button class="btn-primary btn-search w-100">
<span>検索する</span>
<svg class="btn-search-icon" width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect width="24" height="24" rx="12" fill="black"/>
<path d="M16.252 12.001L16.249 12.0039L16.252 12.0068L11.7266 16.5312L10.5957 15.4004L13.1943 12.8027H7.72852V11.2031H13.1924L10.5957 8.60742L11.7266 7.47656L16.252 12.001Z" fill="#FBE800"/>
</svg>
</button>
</div>
<!-- bottom line -->
<div class="bottom-line container-mobile"></div>
<!-- Product List Right -->
<div class="product-list-right">
<div class="product-grid" id="product-grid">
{% if pagination.totalItemCount > 0 %}
{% for Product in pagination %}
<div class="product-item">
<a href="{{ url('product_detail', {'id': Product.id}) }}" class="product-card-small">
<div class="product-card-small__image">
<img src="{{ asset(Product.main_list_image|no_image_product, 'save_image') }}" alt="{{ Product.name }}" {% if loop.index > 5 %} loading="lazy"{% endif %}>
<div class="product-card-small__arrow">
<img src="{{ asset('assets/img/default/icons/icon-heart.svg') }}" alt="Favorite" loading="lazy">
</div>
</div>
</a>
<div class="product-item__info">
<a href="{{ url('product_detail', {'id': Product.id}) }}">
<h4 class="product-item__title">{{ Product.name }}</h4>
</a>
<div class="product-item__price">
<span class="price-symbol">¥</span>
<span class="price-amount">
{% if Product.hasProductClass %}
{% if Product.getPrice02Min == Product.getPrice02Max %}
{{ Product.getPrice02IncTaxMin|price }}
{% else %}
{{ Product.getPrice02IncTaxMin|price }} ~ {{ Product.getPrice02IncTaxMax|price }}
{% endif %}
{% else %}
{{ Product.getPrice02IncTaxMin|price }}
{% endif %}
</span>
<span class="price-tax">(税込)</span>
</div>
</div>
</div>
{% endfor %}
{% else %}
<span>{{ 'front.product.search__product_not_found'|trans }}</span>
{% endif %}
</div>
<!-- Pagination -->
<div class="pagination-product-list-wrapper">
<div class="pagination-product-list" style="margin: 0 auto;">
{% include "Block/_pagination.twig" with {'pages': pagination.paginationData} %}
</div>
</div>
</div>
</div>
</div>
</body>
{% endblock %}