app/template/default/Cart/index.twig line 1

Open in your IDE?
  1. {#
  2. This file is part of EC-CUBE
  3. Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  4. http://www.ec-cube.co.jp/
  5. For the full copyright and license information, please view the LICENSE
  6. file that was distributed with this source code.
  7. #}
  8. {% extends 'default_frame.twig' %}
  9. {% set body_class = 'cart_page' %}
  10. {# style #}
  11. {% block stylesheet %}
  12.     <link rel="stylesheet" href="{{ asset('assets/css/cart.css') }}">
  13. {% endblock %}
  14. {% block main %}
  15.     <!-- breadcrumb section -->
  16.     <div class="breadcrumb-section">
  17.         <div class="container-1360 border-box px-40">
  18.             <nav class="breadcrumb">
  19.                 <a href="{{ url('homepage') }}" class="breadcrumb__item text-black">ホーム</a>
  20.                 <img src="{{ asset('assets/img/default/icons/icon-breadcrumb-arrow.svg') }}" alt=">" class="breadcrumb__separator">
  21.                 <a href="{{ url('cart') }}" class="breadcrumb__item text-black">カート</a>
  22.             </nav>
  23.         </div>
  24.     </div>
  25.     <div class="container-1200">
  26.         <div
  27.             class="product-cart-wrapper">
  28.             <!-- Cart Title Section -->
  29.             <div class="top-header-title-section">
  30.                 <div class="top-header-icon-text">
  31.                     <div class="top-header-icon-text">
  32.                         <svg class="top-header-icon" width="20" height="20" viewbox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
  33.                             <g clip-path="url(#clip0_cart)">
  34.                                 <path d="M5.83398 15.0013C4.91732 15.0013 4.17565 15.7513 4.17565 16.668C4.17565 17.5846 4.91732 18.3346 5.83398 18.3346C6.75065 18.3346 7.50065 17.5846 7.50065 16.668C7.50065 15.7513 6.75065 15.0013 5.83398 15.0013ZM0.833984 1.66797V3.33464H2.50065L5.50065 9.65964L4.37565 11.7013C4.24232 11.9346 4.16732 12.2096 4.16732 12.5013C4.16732 13.418 4.91732 14.168 5.83398 14.168H15.834V12.5013H6.18398C6.06732 12.5013 5.97565 12.4096 5.97565 12.293L6.00065 12.193L6.75065 10.8346H12.959C13.584 10.8346 14.134 10.493 14.4173 9.9763L17.4007 4.56797C17.4673 4.4513 17.5007 4.30964 17.5007 4.16797C17.5007 3.70964 17.1257 3.33464 16.6673 3.33464H4.34232L3.55898 1.66797H0.833984ZM14.1673 15.0013C13.2507 15.0013 12.509 15.7513 12.509 16.668C12.509 17.5846 13.2507 18.3346 14.1673 18.3346C15.084 18.3346 15.834 17.5846 15.834 16.668C15.834 15.7513 15.084 15.0013 14.1673 15.0013Z" fill="#00A854"/>
  35.                             </g>
  36.                             <defs>
  37.                                 <clipPath id="clip0_cart"><rect width="20" height="20" fill="white"/></clipPath>
  38.                             </defs>
  39.                         </svg>
  40.                         <span class="top-header-text">カート</span>
  41.                     </div>
  42.                 </div>
  43.                 <h1 class="top-header-title">SHOPPING CART</h1>
  44.             </div>
  45.             {% set productStr = app.session.flashbag.get('eccube.front.request.product') %}
  46.             {% for error in app.session.flashbag.get('eccube.front.request.error') %}
  47.                 {% set idx = loop.index0 %}
  48.                 <div class="ec-cartRole__error">
  49.                     <div class="ec-alert-warning">
  50.                         <div class="ec-alert-warning__icon"><img src="{{ asset('assets/icon/exclamation-white.svg') }}"></div>
  51.                         <div class="ec-alert-warning__text">
  52.                             {% if productStr[idx] is defined %}
  53.                                 {{ error|trans({'%product%':productStr[idx]})|nl2br }}
  54.                             {% else %}
  55.                                 {{ error|trans|nl2br }}
  56.                             {% endif %}
  57.                         </div>
  58.                     </div>
  59.                 </div>
  60.             {% endfor %}
  61.             {% for error in app.session.flashbag.get('eccube.front.cart.error') %}
  62.                 <div class="ec-cartRole__error">
  63.                     <div class="ec-alert-warning">
  64.                         <div class="ec-alert-warning__icon"><img src="{{ asset('assets/icon/exclamation-white.svg') }}"></div>
  65.                         <div class="ec-alert-warning__text">
  66.                             {{ error|trans|nl2br }}
  67.                         </div>
  68.                     </div>
  69.                 </div>
  70.             {% endfor %}
  71.             {% if totalQuantity > 0 %}
  72.                 {% if Carts|length > 1 %}
  73.                     <div class="ec-cartRole__error">
  74.                         <div class="ec-alert-warning">
  75.                             <div class="ec-alert-warning__text">
  76.                                 {{ 'front.cart.divide_cart'|trans|nl2br }}
  77.                             </div>
  78.                         </div>
  79.                     </div>
  80.                 {% endif %}
  81.                 {% for CartIndex,Cart in Carts %}
  82.                     <div class="cart-wrapper">
  83.                         <div class="cart-left">
  84.                             {% set cartKey = Cart.cart_key %}
  85.                             {% for error in app.session.flashbag.get('eccube.front.cart.' ~ cartKey ~ '.request.error') %}
  86.                                 <div class="ec-cartRole__error">
  87.                                     <div class="ec-alert-warning">
  88.                                         <div class="ec-alert-warning__icon"><img src="{{ asset('assets/icon/exclamation-white.svg') }}"></div>
  89.                                         <div class="ec-alert-warning__text">{{ error|trans|nl2br }}</div>
  90.                                     </div>
  91.                                 </div>
  92.                             {% endfor %}
  93.                             <!-- Cart Table -->
  94.                             <div
  95.                                 class="cart-table">
  96.                                 <!-- Table Header -->
  97.                                 <div class="cart-table-header">
  98.                                     <div class="cart-table-header__product">商品名</div>
  99.                                     <div class="cart-table-header__quantity">数量</div>
  100.                                     <div class="cart-table-header__subtotal">小計</div>
  101.                                 </div>
  102.                                 <div class="cart-table-row-wrapper">
  103.                                     {% for CartItem in Cart.CartItems %}
  104.                                         {% set ProductClass = CartItem.ProductClass %}
  105.                                         {% set Product = ProductClass.Product %}
  106.                                         <div class="cart-table-row">
  107.                                             <div
  108.                                                 class="cart-table-row__product">
  109.                                                 {# delete product from cart #}
  110.                                                 <a href="{{ url('cart_handle_item', {'operation': 'remove', 'productClassId': ProductClass.id }) }}" {{ csrf_token_for_anchor() }} class="product-remove" data-method="put" data-message="カートから商品を削除してもよろしいですか?" data-user-imei="{{ CartItem.user_imei|default('') }}">
  111.                                                     <img src="{{ asset('assets/img/default/icons/close.svg') }}" alt="delete" class="product-remove-icon">
  112.                                                 </a>
  113.                                                 <div class="product-image">
  114.                                                     <a target="_blank" href="{{ url('product_detail', {id : Product.id} ) }}">
  115.                                                         <img src="{{ asset(Product.MainListImage|no_image_product, 'save_image') }}" alt="{{ Product.name }}">
  116.                                                     </a>
  117.                                                 </div>
  118.                                                 <div class="product-info">
  119.                                                     <div class="product-name">
  120.                                                         <a target="_blank" href="{{ url('product_detail', {id : Product.id} ) }}" class="text-black">{{ Product.name }}</a>
  121.                                                     </div>
  122.                                                     <div class="product-price">{{ CartItem.price|price }}</div>
  123.                                                     <div class="product-price-quantity-wrapper container-mobile-flex">
  124.                                                         <span class="container-mobile mr-40">数量:{{ CartItem.quantity|number_format }}</span>
  125.                                                         <span class="container-mobile">小計:{{ CartItem.total_price|price }}</span>
  126.                                                     </div>
  127.                                                     {% if ProductClass.ClassCategory1 and ProductClass.ClassCategory1.id %}
  128.                                                         <div>{{ ProductClass.ClassCategory1.ClassName.name }}:{{ ProductClass.ClassCategory1 }}</div>
  129.                                                     {% endif %}
  130.                                                     {% if ProductClass.ClassCategory2 and ProductClass.ClassCategory2.id %}
  131.                                                         <div>{{ ProductClass.ClassCategory2.ClassName.name }}:{{ ProductClass.ClassCategory2 }}</div>
  132.                                                     {% endif %}
  133.                                                     {% if CartItem.user_imei %}
  134.                                                         <div>{{ 'front.cart.user_imei_title'|trans }}:
  135.                                                             {{ CartItem.user_imei }}</div>
  136.                                                     {% endif %}
  137.                                                 </div>
  138.                                                 <div class="product-remove">
  139.                                                     <a href="{{ url('cart_handle_item', {'operation': 'remove', 'productClassId': ProductClass.id }) }}" {{ csrf_token_for_anchor() }} class="ec-icon" data-method="put" data-message="カートから商品を削除してもよろしいですか?" data-user-imei="{{ CartItem.user_imei|default('') }}">
  140.                                                         <img src="{{ asset('assets/icon/cross.svg') }}" alt="delete">
  141.                                                     </a>
  142.                                                 </div>
  143.                                             </div>
  144.                                             <div class="cart-table-row__quantity container-desktop-flex">
  145.                                                 <span class="quantity-value">{{ CartItem.quantity|number_format }}</span>
  146.                                             </div>
  147.                                             <div class="cart-table-row__subtotal container-desktop-flex">
  148.                                                 <span class="subtotal-value">{{ CartItem.total_price|price }}</span>
  149.                                             </div>
  150.                                         </div>
  151.                                         <!-- Divider -->
  152.                                         <div class="cart-table-divider"></div>
  153.                                     {% endfor %}
  154.                                 </div>
  155.                             </div>
  156.                         </div>
  157.                         <div
  158.                             class="cart-right">
  159.                             <!-- Cart Summary -->
  160.                             <div
  161.                                 class="cart-summary">
  162.                                 <!-- Quantity Row -->
  163.                                 <div class="cart-summary-row">
  164.                                     <span class="cart-summary-label">数量</span>
  165.                                     <span class="cart-summary-value">{{ Cart.totalQuantity|number_format }}</span>
  166.                                 </div>
  167.                                 <!-- Divider -->
  168.                                 <div class="cart-summary-divider"></div>
  169.                                 <!-- Total Price Row -->
  170.                                 <div class="cart-summary-row cart-summary-row-bottom">
  171.                                     <span class="cart-summary-label">商品合計(税込)</span>
  172.                                     <span class="cart-summary-price">{{ Cart.totalPrice|price }}</span>
  173.                                 </div>
  174.                                 <!-- Order Process Button -->
  175.                                 <button class="btn-order-process" onclick="window.location.href='{{ url('product_list') }}'">
  176.                                     ご注文手続きに進みます
  177.                                 </button>
  178.                                 {# if user is logged in #}
  179.                                 {% if is_granted('IS_AUTHENTICATED_FULLY') %}
  180.                                     <button class="btn-checkout" onclick="window.location.href='{{ url('cart_buystep', {'cart_key': Cart.cart_key}) }}'">
  181.                                         お会計に進む
  182.                                     </button>
  183.                                 {% else %}
  184.                                     <div
  185.                                         class="cart-checkout-button-wrapper" style="">
  186.                                         <!-- Checkout Button shopping/nonmember -->
  187.                                         <button class="btn-checkout" onclick="window.location.href='{{ url('shopping_nonmember', {'cart_key': Cart.cart_key}) }}'">
  188.                                             お会計に進む
  189.                                         </button>
  190.                                         <!-- Or Divider -->
  191.                                         <div class="cart-or-divider">
  192.                                             <span class="cart-or-text">または</span>
  193.                                         </div>
  194.                                         <!-- Login Checkout Button -->
  195.                                         <button class="btn-login-checkout" onclick="window.location.href='{{ url('cart_buystep', {'cart_key': Cart.cart_key}) }}'">
  196.                                             ログインしてお会計に進む
  197.                                         </button>
  198.                                     </div>
  199.                                 {% endif %}
  200.                             </div>
  201.                         </div>
  202.                     </div>
  203.                 {% endfor %}
  204.             {% else %}
  205.                 {% for CartIndex,Cart in Carts %}
  206.                     {% set cartKey = Cart.cart_key %}
  207.                     {% for error in app.session.flashbag.get('eccube.front.cart.' ~ cartKey ~ '.request.error') %}
  208.                         <div class="ec-cartRole__error">
  209.                             <div class="ec-alert-warning">
  210.                                 <div class="ec-alert-warning__icon"><img src="{{ asset('assets/icon/exclamation-white.svg') }}"></div>
  211.                                 <div class="ec-alert-warning__text">{{ error|trans|nl2br }}</div>
  212.                             </div>
  213.                         </div>
  214.                     {% endfor %}
  215.                 {% endfor %}
  216.                 <div class="ec-role">
  217.                     <div class="ec-off3Grid">
  218.                         <div class="ec-off3Grid__cell">
  219.                             <div class="ec-alert-warning">
  220.                                 <div class="ec-alert-warning__icon"><img src="{{ asset('assets/icon/exclamation-white.svg') }}"></div>
  221.                                 <div class="ec-alert-warning__text">{{ 'front.cart.no_items'|trans }}</div>
  222.                             </div>
  223.                         </div>
  224.                     </div>
  225.                 </div>
  226.             {% endif %}
  227.         </div>
  228.     </div>
  229. {% endblock %}
  230. {% block javascript %}
  231. <script>
  232. (function() {
  233.     'use strict';
  234.     // Hàm set cookie
  235.     function setCookie(name, value, days) {
  236.         const expires = new Date();
  237.         expires.setTime(expires.getTime() + (days * 24 * 60 * 60 * 1000));
  238.         document.cookie = name + '=' + value + ';expires=' + expires.toUTCString() + ';path=/';
  239.     }
  240.     // Hàm get cookie
  241.     function getCookie(name) {
  242.         const nameEQ = name + '=';
  243.         const ca = document.cookie.split(';');
  244.         for (let i = 0; i < ca.length; i++) {
  245.             let c = ca[i];
  246.             while (c.charAt(0) === ' ') c = c.substring(1, c.length);
  247.             if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
  248.         }
  249.         return null;
  250.     }
  251.     // Hàm delete cookie
  252.     function deleteCookie(name) {
  253.         document.cookie = name + '=;expires=Thu, 01 Jan 1970 00:00:00 UTC;path=/;';
  254.     }
  255.     // Hàm lưu vị trí scroll vào cookie
  256.     function saveScrollPosition() {
  257.         const scrollPosition = window.pageYOffset || document.documentElement.scrollTop;
  258.         setCookie('cart_scroll_position', scrollPosition.toString(), 1);
  259.     }
  260.     // Hàm khôi phục vị trí scroll từ cookie
  261.     function restoreScrollPosition() {
  262.         const savedScrollPosition = getCookie('cart_scroll_position');
  263.         if (savedScrollPosition) {
  264.             setTimeout(function() {
  265.                 const targetPosition = parseInt(savedScrollPosition);
  266.                 window.scrollTo(0, targetPosition);
  267.                 // Kiểm tra xem scroll có thành công không
  268.                 setTimeout(function() {
  269.                     const currentPosition = window.pageYOffset || document.documentElement.scrollTop;
  270.                     // Nếu vị trí hiện tại gần với vị trí mục tiêu (cho phép sai số 10px)
  271.                     if (Math.abs(currentPosition - targetPosition) <= 10) {
  272.                         // Xóa cookie sau khi đã scroll thành công
  273.                         deleteCookie('cart_scroll_position');
  274.                         console.log('Đã khôi phục vị trí scroll và xóa cookie');
  275.                     } else {
  276.                         // Nếu scroll không thành công, thử lại sau 200ms
  277.                         setTimeout(function() {
  278.                             window.scrollTo(0, targetPosition);
  279.                             deleteCookie('cart_scroll_position');
  280.                             console.log('Thử lại scroll và xóa cookie');
  281.                         }, 200);
  282.                     }
  283.                 }, 50);
  284.             }, 100);
  285.         }
  286.     }
  287.     // Hàm khởi tạo event listeners
  288.     function initCartScrollPosition() {
  289.         // Khôi phục vị trí scroll từ cookie khi vào trang
  290.         restoreScrollPosition();
  291.         // Thêm event listener cho các nút + và -
  292.         const upButtons = document.querySelectorAll('.ec-cartRow__amountUpButton');
  293.         const downButtons = document.querySelectorAll('.ec-cartRow__amountDownButton');
  294.         // Thêm event listener cho nút +
  295.         upButtons.forEach(function(button) {
  296.             button.addEventListener('click', function(e) {
  297.                 saveScrollPosition();
  298.             });
  299.         });
  300.         // Thêm event listener cho nút -
  301.         downButtons.forEach(function(button) {
  302.             button.addEventListener('click', function(e) {
  303.                 saveScrollPosition();
  304.             });
  305.         });
  306.     }
  307.     // Khởi tạo khi DOM đã sẵn sàng
  308.     if (document.readyState === 'loading') {
  309.         document.addEventListener('DOMContentLoaded', initCartScrollPosition);
  310.     } else {
  311.         initCartScrollPosition();
  312.     }
  313. })();
  314. </script>
  315. {% endblock %}