{#
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 = 'front_page' %}
{% block stylesheet %}
<style>
.main_visual {
text-align: center;
margin: 0 auto;
padding-left: 20px;
padding-right: 20px;
}
.main_visual img {
width: 100%;
height: auto;
max-width: 100%;
}
@media only screen and (min-width: 768px) {
.main_visual img {
width: 80%;
margin: auto;
}
}
/* モバイルでのLCP最適化 */
@media only screen and (max-width: 767px) {
.main_visual img {
width: 100%;
height: auto;
object-fit: cover;
}
}
.slick-slider {
margin-bottom: 30px;
}
.slick-dots {
position: absolute;
bottom: -45px;
display: block;
width: 100%;
padding: 0;
list-style: none;
text-align: center;
}
.slick-dots li {
position: relative;
display: inline-block;
width: 20px;
height: 20px;
margin: 0 5px;
padding: 0;
cursor: pointer;
}
.slick-dots li button {
font-size: 0;
line-height: 0;
display: block;
width: 20px;
height: 20px;
padding: 5px;
cursor: pointer;
color: transparent;
border: 0;
outline: none;
background: transparent;
}
.slick-dots li button:hover,
.slick-dots li button:focus {
outline: none;
}
.slick-dots li button:hover:before,
.slick-dots li button:focus:before {
opacity: 1;
}
.slick-dots li button:before {
content: " ";
line-height: 20px;
position: absolute;
top: 0;
left: 0;
width: 12px;
height: 12px;
text-align: center;
opacity: .25;
background-color: black;
border-radius: 50%;
}
.slick-dots li.slick-active button:before {
opacity: .75;
background-color: black;
}
.slick-dots li button.thumbnail img {
width: 0;
height: 0;
}
</style>
{% endblock %}
{% block javascript %}
<script>
$(function () {
eccube.productsClassCategories = {
{% for Product in Products_new %}
"{{ Product.id|escape('js') }}": {{ class_categories_as_json(Product)|raw }}{% if not loop.last or Products_semi is not empty %}, {% endif %}
{% endfor %}
{% for Product in Products_semi %}
"{{ Product.id|escape('js') }}": {{ class_categories_as_json(Product)|raw }}{% if not loop.last %}, {% endif %}
{% endfor %}
};
eccube.common.initProductDetail($('.add-cart').closest('form'));
});
$(function() {
// お気に入り追加
$('.add_favorite').on('click', function(e) {
var data = $(this).data();
if (confirm(data.product_name + '\r\n\r\n' + 'こちらの商品をお気に入りに登録しますか?') ) {
} else {
return false;
}
});
$('.add-cart').on('click', function(e) {
var data = $(this).data();
var $form = $('#productForm' + data.cartid);
e.preventDefault();
var formData = new FormData($form[0]);
// ✅ `ProductClass` の値を確実にセット
let productClassValue = $form.find('input[name="ProductClass"]').val();
if (!productClassValue) {
alert("商品規格が選択されていません");
return;
}
formData.append('ProductClass', productClassValue);
$.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').text(this);
});
// カートブロックを更新する
$.ajax({
url: '{{ url('block_cart') }}',
type: 'GET',
dataType: 'html'
}).done(function(html) {
const $html = $('<div>').html(html);
// ① ヘッダー用のカート部分を更新
const $headerCart = $html.find('.ec-headerRole__cart');
if ($headerCart.length) {
$('.ec-headerRole__cart').replaceWith($headerCart);
}
// ② サイドカート(ec-cartNaviWrap)も更新
const $sideCart = $html.find('.ec-cartNaviWrap');
if ($sideCart.length) {
$('.ec-cartNaviWrap').replaceWith($sideCart);
}
});
$('.ec-modal').show()
}).fail(function(xhr, textStatus, errorThrown) {
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>
{% endblock javascript %}
{% block main %}
{% endblock %}