app/template/default/Block/top_new_product.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. <div class="top-content-box">
  9.     <h2>新入荷カード情報</h2>
  10. {% set Category = repository("Eccube\\Entity\\Category").find(2) %}
  11. {%
  12.     set products = repository("Eccube\\Entity\\Product")
  13.     .getQueryBuilderBySearchData({'category_id': Category})
  14.     .setMaxResults(5)
  15.     .getQuery()
  16.     .getResult()
  17. %}
  18.     <div class="product-big-list">
  19. {% for Product in products %}
  20.         <div class="product-list-box">
  21.             <a href="{{ url('product_detail', {'id': Product.id}) }}">
  22.                 <img src="{{ asset(Product.main_list_image|no_image_product, 'save_image') }}">
  23.             </a>
  24.             <p>{{ Product.name }}</p>
  25.             <p class="price">
  26.                 {% if Product.hasProductClass %}
  27.                     {% if Product.getPrice02Min == Product.getPrice02Max %}
  28.                         {{ Product.getPrice02IncTaxMin|number_format }}
  29.                     {% else %}
  30.                         {{ Product.getPrice02IncTaxMin|number_format }} ~ {{ Product.getPrice02IncTaxMax|number_format }}
  31.                     {% endif %}
  32.                 {% else %}
  33.                     {{ Product.getPrice02IncTaxMin|number_format }}
  34.                 {% endif %}
  35.                 <span>円</span>
  36.             </p>
  37.             {% if Product.stock_find %}
  38.                 <div class="top-new-spin">
  39.                     <form name="form{{ Product.id }}" id="productForm{{ Product.id }}" action="{{ url('product_add_cart', {id:Product.id}) }}" method="post">
  40.                         
  41.                             <label class="number-spinner-wrap">
  42.                                 <input type="number" id="quantity{{ Product.id }}" name="quantity" required="required" min="1" maxlength="9" class="test5" value="1">
  43.                                 <span class="spinner spinner-down"> <img src="{{ asset('/html/user_data/assets/img/minus.png') }}" class="numcursul" alt=""> </span>
  44.                                 <span class="spinner spinner-up"> <img src="{{ asset('/html/user_data/assets/img/plus.png') }}" class="numcursul" alt=""> </span>
  45.                             </label>
  46.                             <input type="hidden" id="product_id{{ Product.id }}" name="product_id" value="{{ Product.id }}">
  47.                             <input type="hidden" id="ProductClass" name="ProductClass" value="{{ Product.ProductClasses[0].id }}">
  48.                             <input type="hidden" id="_token{{ Product.id }}" name="_token" value="{{ csrf_token('Eccube\\Form\\Type\\AddCartType') }}" />
  49.                         
  50.                     </form>
  51.                 </div>
  52.                 <div class="cart-in-btn">
  53.                     <button class="add-cart-custom" data-cartid="{{ Product.id }}" form="productForm{{ Product.id }}" type="submit"> カートに入れる </button>
  54.                 </div>
  55.             {% else %}
  56.                 <div class="cart-in-btn">
  57.                     <button type="button" class="add-cart-custom" disabled="disabled"> {{ '品切れ中'|trans }} </button>
  58.                 </div>
  59.             {% endif %}
  60.         </div>
  61. {% endfor %}
  62.     </div>
  63. </div>
  64. <script>
  65. $(document).ready(function() {
  66.   // プラスボタンがクリックされたとき
  67.   $('.top-new-spin .spinner-up').click(function() {
  68.     // 対応する数量フィールドのIDを取得
  69.     var productId = $(this).closest('.top-new-spin .number-spinner-wrap').find('input[type="number"]').attr('id');
  70.     
  71.     // 対応する数量フィールドの値を取得
  72.     var quantity = parseInt($('.top-new-spin #' + productId).val());
  73.     // 値を増加させて数量フィールドに設定
  74.     $('.top-new-spin #' + productId).val(quantity + 1);
  75.   });
  76.   // マイナスボタンがクリックされたとき
  77.   $('.top-new-spin .spinner-down').click(function() {
  78.     // 対応する数量フィールドのIDを取得
  79.     var productId = $(this).closest('.top-new-spin .number-spinner-wrap').find('input[type="number"]').attr('id');
  80.     
  81.     // 対応する数量フィールドの値を取得
  82.     var quantity = parseInt($('.top-new-spin #' + productId).val());
  83.     // 値を減少させて数量フィールドに設定 (1未満にはしない)
  84.     if (quantity > 1) {
  85.       $('.top-new-spin #' + productId).val(quantity - 1);
  86.     }
  87.   });
  88. });
  89. </script>