app/template/bravers/Product/new.twig line 222

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 = 'product_page' %}
  10. {% block javascript %}
  11.     <script>
  12.         eccube.productsClassCategories = {
  13.             {% for Product in pagination %}
  14.             "{{ Product.id|escape('js') }}": {{ class_categories_as_json(Product)|raw }}{% if loop.last == false %}, {% endif %}
  15.             {% endfor %}
  16.         };
  17.         $(function() {
  18.             // 表示件数を変更
  19.             $('.disp-number').change(function() {
  20.                 var dispNumber = $(this).val();
  21.                 $('#disp_number').val(dispNumber);
  22.                 $('#pageno').val(1);
  23.                 $("#form1").submit();
  24.             });
  25.             // 並び順を変更
  26.             $('.order-by').change(function() {
  27.                 var orderBy = $(this).val();
  28.                 $('#orderby').val(orderBy);
  29.                 $('#pageno').val(1);
  30.                 $("#form1").submit();
  31.             });
  32.             var modalTimer;
  33.             $('.add-cart').on('click', function(e) {
  34.                 var self = $(this);
  35.                 onAddCart(e, $(this), 1, function() {
  36.                     var $form = self.parents('li');
  37.                     $form.find(".ec-productRole__btn--only").addClass("d-none");
  38.                     $form.find(".ec-productRole__btn--group").removeClass("d-none");
  39.                     window.clearTimeout(modalTimer);
  40.                     $('.ec-modal').show()
  41.                     modalTimer = window.setTimeout(function() {
  42.                         $('.ec-modal').hide();
  43.                     }, 1500)
  44.                 });
  45.             });
  46.             $('.minus__btn').on('click', function(e) {
  47.                 onAddCart(e, $(this), -1);
  48.             })
  49.             $('.plus__btn').on('click', function(e) {
  50.                 onAddCart(e, $(this));
  51.             })
  52.             function onAddCart(e, self, quantity = 1, callback) {
  53.                 var $form = $(self).parents('li').find('form.productForm');
  54.                 // 個数フォームのチェック
  55.                 $form.parent().find('.quantity').val(quantity);
  56.                 e.preventDefault();
  57.                 $.ajax({
  58.                     url: $form.attr('action'),
  59.                     type: $form.attr('method'),
  60.                     data: $form.serialize(),
  61.                     dataType: 'json',
  62.                     beforeSend: function(xhr, settings) {
  63.                         // Buttonを無効にする
  64.                         $(self).prop('disabled', true);
  65.                     }
  66.                 }).done(function(data) {
  67.                     // レスポンス内のメッセージをalertで表示
  68.                     $.each(data.messages, function() {
  69.                         $('#ec-modal-header').text(this);
  70.                     });
  71.                     var $quantityLabelEl = $(self).parents('li').find('.quantity_label');
  72.                     $quantityLabelEl.text($quantityLabelEl.text() * 1 + quantity * 1);
  73.                     if(callback) {
  74.                         callback();
  75.                     }
  76.                     // カートブロックを更新する
  77.                     $.ajax({
  78.                         url: '{{ url('block_cart') }}',
  79.                         type: 'GET',
  80.                         dataType: 'html'
  81.                     }).done(function(html) {
  82.                         $('.ec-headerRole__cart').html(html);
  83.                     });
  84.                 }).fail(function(data) {
  85.                     alert('{{ 'カートへの追加に失敗しました。'|trans }}');
  86.                     $(self).prop('disabled', false);
  87.                 }).always(function(data) {
  88.                     var $parent = $(self).parents('li');
  89.                     let stockVal = $parent.find('.stock').val() * 1;
  90.                     var $quantityLabelEl = $parent.find('.quantity_label');
  91.                     var _quantity = $quantityLabelEl.text() * 1;
  92.                     if(_quantity == 0) {
  93.                         // enable minus button
  94.                         $(self).prop('disabled', false);
  95.                         $parent.find(".ec-productRole__btn--only").removeClass("d-none");
  96.                         $parent.find(".ec-productRole__btn--group").addClass("d-none");
  97.                     }
  98.                     if(_quantity > 0 && _quantity < stockVal) {
  99.                         // Buttonを有効にする
  100.                         $(self).prop('disabled', false);
  101.                         $parent.find('.plus__btn').prop('disabled', false);
  102.                     }
  103.                 });
  104.             }
  105.         });
  106.         $('.ec-modal-wrap').on('click', function(e) {
  107.             // モーダル内の処理は外側にバブリングさせない
  108.             e.stopPropagation();
  109.         });
  110.         $('.ec-modal-overlay, .ec-modal, .ec-modal-close, .ec-inlineBtn--cancel').on('click', function() {
  111.             $('.ec-modal').hide()
  112.         });
  113.     </script>
  114. {% endblock %}
  115. {% block main %}
  116.     <ul class="breadcrumb w-p">
  117.         <li class="breadcrumb__item">
  118.             <a href="{{ url('homepage') }}" class="breadcrumb__item__link">
  119.                 ホーム
  120.             </a>
  121.         </li>
  122.         <li class="breadcrumb__item">
  123.             <p class="breadcrumb__item__arrow">></p>
  124.         </li>
  125.         <li class="breadcrumb__item">
  126.             <p class="breadcrumb__item__text">新着商品一覧</p>
  127.         </li>
  128.     </ul>
  129.     <div class="ec-pageHeader contentHeader">
  130.         <h1>{{ '新着商品一覧'|trans }}</h1>
  131.     </div>
  132.     {% if search_form.category_id.vars.errors|length > 0 %}
  133.         <div class="ec-searchnavRole">
  134.             <p class="errormsg text-danger">{{ 'ご指定のカテゴリは存在しません'|trans }}</p>
  135.         </div>
  136.     {% else %}
  137.         <div class="ec-searchnavRole">
  138.             <form name="form1" id="form1" method="get" action="?">
  139.                 {% for item in search_form %}
  140.                     <input type="hidden" id="{{ item.vars.id }}"
  141.                            name="{{ item.vars.full_name }}"
  142.                            {% if item.vars.value is not empty %}value="{{ item.vars.value }}" {% endif %}/>
  143.                 {% endfor %}
  144.             </form>
  145.             {# <div class="ec-searchnavRole__topicpath">
  146.                 <ol class="ec-topicpath">
  147.                     <li class="ec-topicpath__item"><a href="{{ url('product_list') }}">{{ '全て'|trans }}</a>
  148.                     </li>
  149.                     {% if Category is not null %}
  150.                         {% for Path in Category.path %}
  151.                             <li class="ec-topicpath__divider">|</li>
  152.                             <li class="ec-topicpath__item{% if loop.last %}--active{% endif %}"><a
  153.                                         href="{{ url('product_list') }}?category_id={{ Path.id }}">{{ Path.name }}</a>
  154.                             </li>
  155.                         {% endfor %}
  156.                     {% endif %}
  157.                     {% if search_form.vars.value and search_form.vars.value.name %}
  158.                         <li class="ec-topicpath__divider">|</li>
  159.                         <li class="ec-topicpath__item">{{ '「%name%」の検索結果'|trans({ '%name%': search_form.vars.value.name }) }}</li>
  160.                     {% endif %}
  161.                 </ol>
  162.             </div> #}
  163.             <div class="ec-searchnavRole__infos">
  164.                 <div class="ec-searchnavRole__counter">
  165.                     {# {% if pagination.totalItemCount > 0 %}
  166.                         <p class="ec-searchnavRole__counter__title">検索結果</p>
  167.                         {{ '<p class="ec-searchnavRole__counter__number">%count%件</p>'|trans({ '%count%': pagination.totalItemCount })|raw }}
  168.                     {% else %}
  169.                         <span>{{ 'お探しの商品は見つかりませんでした'|trans }}</span>
  170.                     {% endif %} #}
  171.                 </div>
  172.                 {% if pagination.totalItemCount > 0 %}
  173.                     <div class="ec-searchnavRole__actions">
  174.                         <div class="ec-select">
  175.                             {{ form_widget(search_form.disp_number, {'id': '', 'attr': {'class': 'disp-number'}}) }}
  176.                             {{ form_widget(search_form.orderby, {'id': '', 'attr': {'class': 'order-by d-none'}}) }}
  177.                         </div>
  178.                     </div>
  179.                 {% endif %}
  180.             </div>
  181.         </div>
  182.         <ul class="stockList">
  183.             <li class="stockList__block">
  184.                 <p class="stockList__block__text">在庫あり:</p>
  185.                 <p class="stockList__block__mark">◎</p>
  186.             </li>
  187.             <li class="stockList__block">
  188.                 <p class="stockList__block__text">残りわずか:</p>
  189.                 <p class="stockList__block__mark">○</p>
  190.             </li>
  191.             <li class="stockList__block">
  192.                 <p class="stockList__block__text">取り寄せ:</p>
  193.                 <p class="stockList__block__mark">■</p>
  194.             </li>
  195.         </ul>
  196.         {% if pagination.totalItemCount > 0 %}
  197.             <div class="ec-shelfRole">
  198.                 <ul class="ec-shelfGrid">
  199.                     {% for Product in pagination %}
  200.                         <li class="ec-shelfGrid__item">
  201.                             <a href="{{ url('product_detail', {'id': Product.id}) }}">
  202.                                 <div class="ec-shelfGrid__item-image">
  203.                                     <img src="{{ asset(Product.main_list_image|no_image_product, 'save_image') }}" alt="{{ Product.name }}" {% if loop.index > 5 %} loading="lazy"{% endif %}>
  204.                                     {% if Product.Tags|length > 0  %}
  205.                                     <ul class="ec-shelfGrid__item-tags">
  206.                                         {% for Tag in Product.Tags %}
  207.                                             <li class="ec-shelfGrid__item-tags__tag tag_{{ Tag.id }}">{{ Tag }}</li>
  208.                                         {% endfor %}
  209.                                     </ul>
  210.                                     {% endif %}
  211.                                 </div>
  212.                                 <p class="ec-shelfGrid__item-name">{{ Product.name }}</p>
  213.                                 {% if is_granted('ROLE_USER') %}
  214.                                 <div class="ec-shelfGrid__item-stock">
  215.                                     <div class="ec-shelfGrid__item-stock__block">
  216.                                         <p class="ec-shelfGrid__item-stock__block__title">
  217.                                             【発送目安】
  218.                                         </p>
  219.                                         <p class="ec-shelfGrid__item-stock__block__detail">
  220.                                             {% if Product.getDeliveryDuration %}
  221.                                                 {{Product.getDeliveryDuration.name}}
  222.                                             {% else %}
  223.                                                 指定なし
  224.                                             {% endif %}
  225.                                         </p>
  226.                                     </div>
  227.                                     <div class="ec-shelfGrid__item-stock__block">
  228.                                         <p class="ec-shelfGrid__item-stock__block__title">
  229.                                             【在庫】
  230.                                         </p>
  231.                                         {# 在庫をマークで表示何個から何個か◎等はこれから確認 #}
  232.                                         <p class="ec-shelfGrid__item-stock__block__detail">
  233.                                             {% if Product.getStockUnlimitedMin or Product.getStockMin >= 10 %}
  234.                                                 ◎
  235.                                             {% else %}
  236.                                                 {% if Product.getStockMin >= 1 and Product.getStockMin <= 9 %}
  237.                                                     ○
  238.                                                 {% endif %}
  239.                                                 {% if Product.getStockMin <= 0 %}
  240.                                                     ■
  241.                                                 {% endif %}
  242.                                             {% endif %}
  243.                                         </p>
  244.                                     </div>
  245.                                 </div>
  246.                                 {# {% if not Product.getStockUnlimitedMin %}
  247.                                     <p>
  248.                                         発送可能{{Product.getStockMin}}個
  249.                                     </p>
  250.                                 {% endif %} #}
  251.                                 {% if Product.description_list %}
  252.                                     <p>{{ Product.description_list|raw|nl2br }}</p>
  253.                                 {% endif %}
  254.                                 <div class="ec-shelfGrid__item-flex">
  255.                                     <p class="price02-default ec-shelfGrid__item-price">
  256.                                         {% if Product.isInSale %}
  257.                                             <span class="ec-shelfGrid__item-price__sale">セール商品</span>
  258.                                         {% endif %}
  259.                                         {% if Product.hasProductClass %}
  260.                                             {% if Product.getPrice02Min == Product.getPrice02Max %}
  261.                                                 {{ Product.getPrice02IncTaxMin|price }}
  262.                                             {% else %}
  263.                                                 {{ Product.getPrice02IncTaxMin|price }} ~ {{ Product.getPrice02IncTaxMax|price }}
  264.                                             {% endif %}
  265.                                         {% else %}
  266.                                             {{ Product.getPrice02IncTaxMin|price }}
  267.                                         {% endif %}
  268.                                     </p>
  269.                                     <div class="ec-shelfGrid__item-flex__favorite">
  270.                                         <form class="ec-favoriteForm" action="?" method="?">
  271.                                             <div class="ec-productRole__btn">
  272.                                                 <button data-method="POST" data-action="{{ url('product_add_favorite', {id:Product.id}) }}" id="favorite" class="{% if isFavorite[Product.id] is defined and isFavorite[Product.id] == true %} d-none {% endif %} ec-blockFavoriteBtn ec-blockBtn--cancel ec-shelfGrid__item-flex__favorite__btn">
  273.                                                     <img src="{{ asset('assets/img/favorite/before.svg') }}" alt="お気に入り" width="24" height="24" loading="lazy">
  274.                                                 </button>
  275.                                                 <button data-method="DELETE" data-action="{{ url('product_favorite_delete', {id:Product.id}) }}" id="favorite" class="{% if isFavorite[Product.id] is defined and isFavorite[Product.id] == false %} d-none {% endif %}ec-blockFavoriteBtnDisable ec-blockBtn--cancel ec-shelfGrid__item-flex__favorite__btn">
  276.                                                    <img src="{{ asset('assets/img/favorite/after.svg') }}" alt="お気に入り" width="24" height="24" loading="lazy">
  277.                                                 </button>
  278.                                             </div>
  279.                                         </form>
  280.                                     </div>
  281.                                 </div>
  282.                             </a>
  283.                                 {% if not Product.getStockUnlimitedMin and Product.getStockMin <= 0 and Product.isStockDiscontinued %}
  284.                                     <div class="ec-productRole__btn">
  285.                                         <button type="button" class="ec-disabled__btn" disabled="disabled">
  286.                                             {{ '在庫なし'|trans }}
  287.                                         </button>
  288.                                     </div>
  289.                                 {% else %}
  290.                                     {% set form = forms[Product.id] %}
  291.                                     <form class="productForm" name="form{{ Product.id }}" id="productForm{{ Product.id }}" action="{{ url('product_add_cart', {id:Product.id}) }}" method="post">
  292.                                         <div class="ec-productRole__actions">
  293.                                             {% if form.classcategory_id1 is defined %}
  294.                                                 <div class="ec-select">
  295.                                                     {{ form_widget(form.classcategory_id1) }}
  296.                                                     {{ form_errors(form.classcategory_id1) }}
  297.                                                 </div>
  298.                                                 {% if form.classcategory_id2 is defined %}
  299.                                                     <div class="ec-select">
  300.                                                         {{ form_widget(form.classcategory_id2) }}
  301.                                                         {{ form_errors(form.classcategory_id2) }}
  302.                                                     </div>
  303.                                                 {% endif %}
  304.                                             {% endif %}
  305.                                                 <div class="ec-numberInput d-none"><span>{{ '数量'|trans }}</span>
  306.                                                     {{ form_widget(form.quantity, {'attr': {'class': 'quantity'}} ) }}
  307.                                                     {{ form_errors(form.quantity) }}
  308.                                                 </div>
  309.                                         
  310.                                         </div>
  311.                                         {{ form_rest(form) }}
  312.                                     </form>
  313.                                     {% set default = 0 %}
  314.                                     {% if itemInCart[Product.id] is defined %}
  315.                                         {% set default = itemInCart[Product.id] %}
  316.                                     {% endif %}
  317.                                     {% set disabled = false %}
  318.                                     {% if not Product.isStockDiscontinued %}
  319.                                         <input type="hidden" name="stock" class="stock" value="999999999999">
  320.                                     {% else %}
  321.                                         {% if Product.getStockMin <= default %}
  322.                                             {% set disabled = true %}
  323.                                         {% endif %}
  324.                                         <input type="hidden" name="stock" class="stock" value="{{Product.getStockMin}}">
  325.                                     {% endif %}
  326.                                     <div class="ec-productRole__btn--group ec-productRole__btn {% if itemInCart[Product.id] is defined %} d-block {% else %} d-none {% endif %}">
  327.                                         <div class="d-flex align-items-center ec-productRole__btn-wrapper">
  328.                                             <button class="minus__btn" data-cartid="{{ Product.id }}" form="productForm{{ Product.id }}">
  329.                                                 <span>−</span>
  330.                                             </button>
  331.                                             <span class="quantity_label">{{ default }}</span>
  332.                                             <button class="plus__btn" data-cartid="{{ Product.id }}" form="productForm{{ Product.id }}" {% if disabled %}disabled{% endif %}>
  333.                                                 <span>+</span>
  334.                                             </button>
  335.                                         </div>
  336.                                     </div>
  337.                                     <div class="ec-productRole__btn--only ec-productRole__btn {% if itemInCart[Product.id] is defined %} d-none {% else %} d-block {% endif %}">
  338.                                         <button type="submit" class="ec-regular__btn add-cart" data-cartid="{{ Product.id }}" form="productForm{{ Product.id }}">
  339.                                             {{ 'カートに入れる'|trans }}
  340.                                         </button>
  341.                                     </div>
  342.                                 {% endif %}
  343.                             {% else %}
  344.                                 <a href="{{ url('entry_contact') }}" class="ec-blockProductBtn--action">会員登録はこちら</a>
  345.                             {% endif %}
  346.                         </li>
  347.                     {% endfor %}
  348.                 </ul>
  349.             </div>
  350.             <div class="ec-modal">
  351.                 <div class="ec-modal-overlay">
  352.                     <div class="ec-modal-wrap">
  353.                         <div class="ec-modal-box">
  354.                             <div class="ec-role">
  355.                                 <div class="ec-modal-icon">
  356.                                     <img src="{{ asset('assets/img/icon/icon_cart.png', 'user_data') }}" alt="">
  357.                                 </div>
  358.                             </div>
  359.                         </div>
  360.                         <div id="ec-modal-header" class="text-center">{{ 'カートに追加しました。'|trans }}</div>
  361.                     </div>
  362.                 </div>
  363.             </div>
  364.             <ul class="stockList bottom">
  365.                 <li class="stockList__block">
  366.                     <p class="stockList__block__text">在庫あり:</p>
  367.                     <p class="stockList__block__mark">◎</p>
  368.                 </li>
  369.                 <li class="stockList__block">
  370.                     <p class="stockList__block__text">残りわずか:</p>
  371.                     <p class="stockList__block__mark">○</p>
  372.                 </li>
  373.                 <li class="stockList__block">
  374.                     <p class="stockList__block__text">取り寄せ:</p>
  375.                     <p class="stockList__block__mark">■</p>
  376.                 </li>
  377.             </ul>
  378.             <div class="ec-pagerRole">
  379.                 {% include "pager.twig" with {'pages': pagination.paginationData} %}
  380.             </div>
  381.         {% endif %}
  382.     {% endif %}
  383. {% endblock %}