<div class="topBlocks">
<div class="titleBlock">
<div class="titleBlock__name">
<img class="titleBlock__name__icon" src="{{ asset('assets/img/top/new.svg') }}" alt="新着商品" width="32" height="32" loading="lazy">
<h2 class="titleBlock__name__title">新着商品</h2>
</div>
<a href="{{ url('new_product') }}" class="titleBlock__link">もっとみる</a>
</div>
<div class="topBlocks__scroll">
{% for Product in Products %}
{% set form = newForms[Product.id] %}
<div class="topBlocks__item popular-item">
{% set default = 0 %}
{% if newItemInCart[Product.id] is defined %}
{% set default = newItemInCart[Product.id] %}
{% endif %}
{% set disabled = false %}
{% if not Product.isStockDiscontinued %}
<input type="hidden" name="stock" class="stock" value="999999999999">
{% else %}
{% if Product.getStockMin <= default %}
{% set disabled = true %}
{% endif %}
<input type="hidden" name="stock" class="stock" value="{{Product.getStockMin}}">
{% endif %}
<div class="topBlocks__form">
<a href="{{ url('product_detail', {'id': Product.id}) }}" role="group" >
{# <div class="popular-item__rank">
<span class="index">{{ loop.index }}</span>
<img src="{{ asset('assets/img/icon/ic_medal.png', 'user_data') }}" alt="">
</div> #}
<div class="topBlocks__item__image">
<img src="{{ asset(Product.main_list_image|no_image_product, 'save_image') }}" alt="{{Product.name}}">
{% if Product.Tags|length > 0 %}
<ul class="topBlocks__item__image__tags">
{% for Tag in Product.Tags %}
<li class="topBlocks__item__image__tags__tag tag_{{ Tag.id }}">{{ Tag }}</li>
{% endfor %}
</ul>
{% endif %}
</div>
<p class="topBlocks__item__name">
{{Product.name}}
</p>
{% if is_granted('ROLE_USER') %}
<div class="topBlocks__item__flex">
<div class="topBlocks__item__price">
{% if Product.isInSale %}
<p class="topBlocks__item__price__sale">セール商品</p>
{% endif %}
{% if Product.hasProductClass %}
{% if Product.getPrice02Min == Product.getPrice02Max %}
{{ Product.getPrice02IncTaxMin|price }}(税込)
{% else %}
{{ Product.getPrice02IncTaxMin|price }} ~ <span>{{ Product.getPrice02IncTaxMax|price }}(税込)</span>
{% endif %}
{% else %}
{{ Product.getPrice02IncTaxMin|price }}(税込)
{% endif %}
</div>
<div class="ec-shelfGrid__item-flex__favorite">
<form class="ec-favoriteForm" action="?" method="?">
<div class="ec-productRole__btn">
<button data-method="POST" data-action="{{ url('product_add_favorite', {id:Product.id}) }}" id="favorite" class="{% if isNewItemFavorite[Product.id] is defined and isNewItemFavorite[Product.id] == true %} d-none {% endif %} topBlocks__item__favorite ec-blockFavoriteBtn ec-blockBtn--cancel ec-shelfGrid__item-flex__favorite__btn">
<img src="{{ asset('assets/img/favorite/before.svg') }}" alt="お気に入り" width="24" height="24" loading="lazy">
</button>
<button data-method="DELETE" data-action="{{ url('product_favorite_delete', {id:Product.id}) }}" id="favorite" class="{% if isNewItemFavorite[Product.id] is defined and isNewItemFavorite[Product.id] == false %} d-none {% endif %} topBlocks__item__favorite ec-blockFavoriteBtnDisable ec-blockBtn--cancel ec-shelfGrid__item-flex__favorite__btn">
<img src="{{ asset('assets/img/favorite/after.svg') }}" alt="お気に入り" width="24" height="24" loading="lazy">
</button>
</div>
</form>
</div>
</div>
{% endif %}
</a>
{% if is_granted('ROLE_USER') %}
<form class="topBlocks__form" name="form{{ Product.id }}" id="productForm{{ Product.id }}" action="{{ url('product_add_cart', {id:Product.id}) }}" method="post">
{% if not Product.getStockUnlimitedMin and Product.getStockMin <= 0 and Product.isStockDiscontinued %}
<div class="ec-productRole__btn">
<button type="button" class="ec-disabled__btn" disabled="disabled">
{{ '在庫なし'|trans }}
</button>
</div>
{% else %}
<div class="ec-numberInput d-none"><span>{{ '数量'|trans }}</span>
{{ form_widget(form.quantity, {'attr': {'class': 'quantity'}} ) }}
{{ form_errors(form.quantity) }}
</div>
<div class="d-none">
{{ form_rest(form) }}
</div>
<div class="ec-productRole__btn--group ec-productRole__btn {% if newItemInCart[Product.id] is defined %} d-block {% else %} d-none {% endif %}">
<div class="d-flex align-items-center ec-productRole__btn-wrapper">
<button class="minus__btn" type="button" data-cartid="{{ Product.id }}" form="productForm{{ Product.id }}">
<span>−</span>
</button>
<span class="quantity_label quantity_label_{{ Product.id }}">{{ default }}</span>
<button class="plus__btn" type="button" data-cartid="{{ Product.id }}" form="productForm{{ Product.id }}" {% if disabled %}disabled{% endif %}>
<span>+</span>
</button>
</div>
</div>
<div class="ec-productRole__btn--only ec-productRole__btn {% if newItemInCart[Product.id] is defined %} d-none {% else %} d-block {% endif %}">
<button type="submit" class="ec-regular__btn add-new-cart" data-cartid="{{ Product.id }}" form="productForm{{ Product.id }}">
{{ 'カートに入れる'|trans }}
</button>
</div>
{% endif %}
</form>
{% endif %}
</div>
</div>
{% endfor %}
<div class="ec-modal ec-new-modal">
<div class="ec-modal-overlay">
<div class="ec-modal-wrap">
<span class="ec-modal-close"><span class="ec-icon"><img src="{{ asset('assets/icon/cross-dark.svg') }}" alt=""/></span></span>
<div id="ec-modal-header" class="text-center">{{ 'カートに追加しました。'|trans }}</div>
<div class="ec-modal-box">
<div class="ec-role">
<span class="ec-inlineBtn--cancel">{{ 'お買い物を続ける'|trans }}</span>
<a href="{{ url('cart') }}" class="ec-inlineBtn--action">{{ 'カートへ進む'|trans }}</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
$('.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()
});
var modalTimer;
$('.add-new-cart').on('click', function(e) {
var self = $(this);
console.log(e);
onAddCart(e, $(this), 1, function() {
window.clearTimeout(modalTimer);
$('.ec-modal.ec-history-modal').show()
modalTimer = window.setTimeout(function() {
$('.ec-modal').hide();
}, 1500)
});
});
{# $('.minus__btn').on('click', function(e) {
e.preventDefault();
e.stopPropagation();
onAddCart(e, $(this), -1);
}) #}
$(document).off('click').on('click', '.minus__btn', function(e) {
console.log(e);
e.preventDefault();
e.stopPropagation();
onAddCart(e, $(this), -1);
return false;
})
$('.plus__btn').on('click', function(e) {
e.preventDefault();
e.stopPropagation();
onAddCart(e, $(this), 1);
return false;
});
</script>