{% extends 'default_frame.twig' %}
{% set body_class = 'cart_page' %}
{% block main %}
<script>
const formatCurrency = (value) => {
value = value.toLocaleString("en",{
minimumFractionDigits: 0,
maximumFractionDigits: 0,
});
return `¥${value}`
}
$(function() {
$(".ec-cartRow__Action").on("click", function(e) {
e.preventDefault();
var href = $(this).attr("href");
var confirmMessage = $(this).attr("data-message");
var action = $(this).attr("data-action");
var self = $(this);
if(confirmMessage) {
if(!confirm(confirmMessage)) {
return false;
}
}
$.ajax({
url: href,
type: "PUT",
}).done(function(data) {
var $curQuantityEl = $(self).parents(".ec-cartRow__amountColumn").find(".ec-cartRow__amount");
var $curQuantitySPEl = $(self).parents(".ec-cartRow__amountColumn").find(".ec-cartRow__amountSP");
var stock = $(self).parents(".ec-cartRow").find(".stock").val() * 1;
var cartItemPrice = $(self).parents(".ec-cartRow").find(".cart-item__price").val() * 1;
var $pinpointSaleQtyEl = $(self).parents(".ec-cartRow").find(".pinpoint_sale_quantity");
var $totalEl = $(self).parents(".ec-cartRole__cart").next().next().find(".ec-cartRole__totalAmount");
var $cartTable = $(self).parents(".ec-cartTable");
var $curRowPriceEl = $(self).parents(".ec-cartRow").find(".ec-cartRow__sutbtotal");
var $curRowPriceSPEl = $(self).parents(".ec-cartRow").find(".ec-cartRow__sutbtotalSP");
var $table = $(self).parents(".ec-cartRole__cart")
var cartKey = $table.data("cart-key");
var cartLeastUrl = $table.data("url");
// Reload quantity START
var curQuantity = $($curQuantityEl).text() * 1;
if(action == "down") {
curQuantity = curQuantity - 1;
} else if(action == "up") {
curQuantity = curQuantity + 1;
} else if(action == "remove") {
$(self).parents("ul.ec-cartRow").remove();
}
if(curQuantity == 1 || curQuantity == stock) {
$(self).prop("disabled", true);
} else {
$(self).parents(".ec-cartRow__amountColumn").find(".ec-cartRow__Action").prop("disabled", false);
}
$($curQuantityEl).text(curQuantity);
$($curQuantitySPEl).text(`${curQuantity}`);
$($pinpointSaleQtyEl).text(curQuantity);
// Reload quantity END
// Reload total in current row START
$($curRowPriceEl).text(formatCurrency(curQuantity * cartItemPrice));
$($curRowPriceSPEl).text(`小計:${formatCurrency(curQuantity * cartItemPrice)}`);
// Reload total in current row END
// Reload total in cart START
var totalPrice = 0;
$cartRows = $($cartTable).find(".ec-cartRow");
$($cartRows).each(function(index, el){
var quantity = $(el).find(".ec-cartRow__amount").text() * 1;
var price = $(el).find(".cart-item__price").val() * 1;
totalPrice += quantity * price;
});
$($totalEl).text(`${formatCurrency(totalPrice)}`)
// Reload total in cart END
// Reload total by all cart START
var totalByCarts = 0;
$(".ec-cartRole__cart").each(function(index, el) {
var $_cartRows = $(el).find(".ec-cartRow");
$_cartRows.each(function(indx, rowEl) {
var quantity = $(rowEl).find(".ec-cartRow__amount").text() * 1;
var price = $(rowEl).find(".cart-item__price").val() * 1;
totalByCarts += quantity * price;
});
});
$(".ec-cartRole__totalText strong").text(formatCurrency(totalByCarts));
// Reload total by all cart END
// Update cart block in header START
$.ajax({
url: '{{ url('block_cart') }}',
type: 'GET',
dataType: 'html'
}).done(function(html) {
$('.ec-headerRole__cart').html(html);
});
// Update cart block in header END
// update free condition START
$.ajax({
url: cartLeastUrl,
type: 'GET',
dataType: 'html'
}).done(function(html) {
$(`#cartRole__progress__${cartKey}`).html(html);
});
// update free condition END
}).fail(function(error) {
console.log(error);
})
return false;
});
});
</script>
<ul class="breadcrumb w-p">
<li class="breadcrumb__item">
<a href="{{ url('homepage') }}" class="breadcrumb__item__link">
ホーム
</a>
</li>
<li class="breadcrumb__item">
<p class="breadcrumb__item__arrow">></p>
</li>
<li class="breadcrumb__item">
<p class="breadcrumb__item__text">カート</p>
</li>
</ul>
<div class="ec-role">
<div class="ec-pageHeader text-center">
<h1>{{ 'ショッピングカート'|trans }}</h1>
</div>
</div>
<div class="ec-cartRole">
<div class="ec-cartRole__progress">
<ul class="ec-progress">
{% set step = 1 %}
<li class="ec-progress__item is-complete">
<div class="ec-progress__number">0{{ step }}{% set step = step + 1 %}
</div>
<div class="ec-progress__label">{{ 'カートの商品'|trans }}
</div>
</li>
{% if is_granted('ROLE_USER') == false %}
<li class="ec-progress__item">
<div class="ec-progress__number">0{{ step }}{% set step = step + 1 %}
</div>
<div class="ec-progress__label">{{ 'お客様情報'|trans }}
</div>
</li>
{% endif %}
<li class="ec-progress__item">
<div class="ec-progress__number">0{{ step }}{% set step = step + 1 %}
</div>
<div class="ec-progress__label">{{ 'ご注文手続き'|trans }}
</div>
</li>
<li class="ec-progress__item">
<div class="ec-progress__number">0{{ step }}{% set step = step + 1 %}
</div>
<div class="ec-progress__label">{{ 'ご注文内容確認'|trans }}
</div>
</li>
<li class="ec-progress__item">
<div class="ec-progress__number">0{{ step }}{% set step = step + 1 %}
</div>
<div class="ec-progress__label">{{ '完了'|trans }}
</div>
</li>
</ul>
</div>
{% set productStr = app.session.flashbag.get('eccube.front.request.product') %}
{% for error in app.session.flashbag.get('eccube.front.request.error') %}
{% set idx = loop.index0 %}
<div class="ec-cartRole__error">
<div class="ec-alert-warning">
<div class="ec-alert-warning__icon"><img src="{{ asset('assets/icon/exclamation-white.svg') }}"></div>
<div class="ec-alert-warning__text">
{% if productStr[idx] is defined %}
{{ error|trans({'%product%':productStr[idx]})|nl2br }}
{% else %}
{{ error|trans|nl2br }}
{% endif %}
</div>
</div>
</div>
{% endfor %}
{% for error in app.session.flashbag.get('eccube.front.cart.error') %}
<div class="ec-cartRole__error">
<div class="ec-alert-warning">
<div class="ec-alert-warning__icon"><img src="{{ asset('assets/icon/exclamation-white.svg') }}"></div>
<div class="ec-alert-warning__text">
{{ error|trans|nl2br }}
</div>
</div>
</div>
{% endfor %}
{% if totalQuantity > 0 %}
<div class="ec-cartRole__totalText">
<p>
{{ '商品の合計金額は「<strong>%price%</strong>」です。'|trans({ '%price%': totalPrice|price })|raw }}
</p>
</div>
{% if Carts|length > 1 %}
<div class="ec-cartRole__error">
<div class="ec-alert-warning">
<div class="ec-alert-warning__text">
{{ '同時購入できない商品がカートに含まれています。'|trans|nl2br }}
</div>
</div>
</div>
{% endif %}
<form name="form" id="form_cart" class="ec-cartRole__form" method="post" action="{{ url('cart') }}">
{% for CartIndex,Cart in Carts %}
{% set cartKey = Cart.cart_key %}
{% for error in app.session.flashbag.get('eccube.front.cart.' ~ cartKey ~ '.request.error') %}
<div class="ec-cartRole__error">
<div class="ec-alert-warning">
<div class="ec-alert-warning__icon"><img src="{{ asset('assets/icon/exclamation-white.svg') }}"></div>
<div class="ec-alert-warning__text">
{{ error|trans|nl2br }}
</div>
</div>
</div>
{% endfor %}
<div class="ec-cartRole__cart" data-cart-key="{{cartKey}}" data-url="{{ url('cart_least', {"cart_key": cartKey}) }}">
<div class="ec-cartTable">
<ol class="ec-cartHeader">
<li class="ec-cartHeader__label">{{ '商品内容'|trans }}</li>
<li class="ec-cartHeader__label">{{ '数量'|trans }}</li>
<li class="ec-cartHeader__label">{{ '小計'|trans }}</li>
<li class="ec-cartHeader__label">{{ '削除'|trans }}</li>
</ol>
{% for CartItem in Cart.CartItems %}
{% set ProductClass = CartItem.ProductClass %}
{% set Product = ProductClass.Product %}
<ul class="ec-cartRow">
{% set disabled = false %}
{% set default = CartItem.quantity %}
{% 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 %}
<input type="hidden" name="cart-item__price" class="cart-item__price" value="{{ CartItem.price }}">
<li class="ec-cartRow__contentColumn">
<div class="ec-cartRow__img">
<a target="_blank" href="{{ url('product_detail', {id : Product.id} ) }}">
<img src="{{ asset(Product.MainListImage|no_image_product, 'save_image') }}" alt="{{ Product.name }}"/>
</a>
</div>
<div class="ec-cartRow__summary">
<div class="ec-cartRow__name">
<a target="_blank" href="{{ url('product_detail', {id : Product.id} ) }}">{{ Product.name }}</a>
{% if ProductClass.ClassCategory1 and ProductClass.ClassCategory1.id %}
<br>{{ ProductClass.ClassCategory1.ClassName.name }}:{{ ProductClass.ClassCategory1 }}
{% endif %}
{% if ProductClass.ClassCategory2 and ProductClass.ClassCategory2.id %}
<br>{{ ProductClass.ClassCategory2.ClassName.name }}:{{ ProductClass.ClassCategory2 }}
{% endif %}
</div>
<div class="ec-cartRow__unitPrice">{{ CartItem.price|price }}</div>
<div class="ec-cartRow__sutbtotalSP">{{ '小計:'|trans }}{{ CartItem.total_price|price }}</div>
</div>
</li>
<li class="ec-cartRow__amountColumn">
<div class="ec-cartRow__amountSP">{{ CartItem.quantity|number_format }}</div>
<div class="ec-cartRow__amountUpDown">
<button {% if CartItem.quantity == 1 %}disabled{% endif %} href="{{ url('cart_handle_item', {'operation': 'down', 'productClassId': ProductClass.id}) }}" {{ csrf_token_for_anchor() }} class="ec-cartRow__Action ec-cartRow__amountDownButton" data-action="down" data-confirm="false">
<span class="ec-cartRow__amountDownButton__icon"></span>
</button>
<div class="ec-cartRow__amount">{{ CartItem.quantity|number_format }}</div>
<button {% if disabled %}disabled{% endif %} href="{{ url('cart_handle_item', {'operation': 'up', 'productClassId': ProductClass.id}) }}" {{ csrf_token_for_anchor() }} class="ec-cartRow__Action ec-cartRow__amountUpButton" data-action="up" data-confirm="false">
<span class="ec-cartRow__amountUpButton__icon"></span>
</button>
</div>
</li>
<li class="ec-cartRow__subtotalColumn">
<div class="ec-cartRow__sutbtotal">{{ CartItem.total_price|price }}</div>
</li>
<li class="ec-cartRow__delColumn">
<button href="{{ url('cart_handle_item', {'operation': 'remove', 'productClassId': ProductClass.id }) }}" {{ csrf_token_for_anchor() }} class="ec-icon ec-cartRow__Action" data-action="remove" data-message="カートから商品を削除してもよろしいですか?">
<img src="{{ asset('assets/img/cart/close.svg') }}" alt="delete">
</button>
</li>
</ul>
{% endfor %}
</div>
</div>
<div class="ec-cartRole__progress" id="cartRole__progress__{{cartKey}}">
{% if BaseInfo.delivery_free_amount and BaseInfo.delivery_free_quantity %}
<br/>
{% if is_delivery_free[cartKey] %}
{{ '現在送料無料です。'|trans }}
{% else %}
{{ 'あと「<strong>%price%</strong>」または「<strong>%quantity%個</strong>」のお買い上げで<strong class="ec-color-red">送料無料</strong>になります。'|trans({ '%price%': least[cartKey]|price, '%quantity%': quantity[cartKey]|number_format })|raw }}
{% endif %}
{% elseif BaseInfo.delivery_free_amount %}
<br/>
{% if is_delivery_free[cartKey] %}
{{ '現在送料無料です。'|trans }}
{% else %}
{{ 'あと「<strong>%price%</strong>」のお買い上げで<strong class="ec-color-red">送料無料</strong>になります。'|trans({ '%price%': least[cartKey]|price })|raw }}
{% endif %}
{% elseif BaseInfo.delivery_free_quantity %}
<br/>
{% if is_delivery_free[cartKey] %}
{{ '現在送料無料です。'|trans }}
{% else %}
{{ 'あと「<strong>%quantity%個</strong>」のお買い上げで<strong class="ec-color-red">送料無料</strong>になります。'|trans({ '%quantity%': quantity[cartKey]|number_format })|raw }}
{% endif %}
{% endif %}
</div>
<div class="ec-cartRole__actions">
<div class="ec-cartRole__actions__inner">
<div class="ec-cartRole__total"><span>{{ '合計'|trans }}</span><span class="ec-cartRole__totalAmount">{{ Cart.totalPrice|price }}</span></div>
<div class="ec-cartRole__actions__flex">
{% if loop.last %}
<a class="ec-blockBtn--back" href="{{ path('homepage') }}">{{ 'お買い物を続ける'|trans }}</a>
{% endif %}
<a class="ec-regular__btn" href="{{ path('cart_buystep', {'cart_key':cartKey}) }}">{{ 'レジに進む'|trans }}</a>
</div>
</div>
</div>
{% endfor %}
</form>
{% else %}
{% for CartIndex,Cart in Carts %}
{% set cartKey = Cart.cart_key %}
{% for error in app.session.flashbag.get('eccube.front.cart.' ~ cartKey ~ '.request.error') %}
<div class="ec-cartRole__error">
<div class="ec-alert-warning">
<div class="ec-alert-warning__icon"><img src="{{ asset('assets/icon/exclamation-white.svg') }}"></div>
<div class="ec-alert-warning__text">
{{ error|trans|nl2br }}
</div>
</div>
</div>
{% endfor %}
{% endfor %}
<div class="ec-role">
<div class="ec-alert-warning cart-warning">
<div class="ec-alert-warning__icon"><img src="{{ asset('assets/icon/exclamation-white.svg') }}"></div>
<div class="ec-alert-warning__text">{{ '現在カート内に商品はございません。'|trans }}</div>
</div>
</div>
{% endif %}
</div>
{% endblock %}