app/template/default/Product/list.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 = '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.             $('.add-cart').on('click', function(e) {
  33.                 var $form = $(this).parents('li').find('form');
  34.                 // 個数フォームのチェック
  35.                 var $quantity = $form.parent().find('.quantity');
  36.                 if ($quantity.val() < 1) {
  37.                     $quantity[0].setCustomValidity('{{ '1以上で入力してください。'|trans }}');
  38.                     setTimeout(function() {
  39.                         loadingOverlay('hide');
  40.                     }, 100);
  41.                     return true;
  42.                 } else {
  43.                     $quantity[0].setCustomValidity('');
  44.                 }
  45.                 e.preventDefault();
  46.                 $.ajax({
  47.                     url: $form.attr('action'),
  48.                     type: $form.attr('method'),
  49.                     data: $form.serialize(),
  50.                     dataType: 'json',
  51.                     beforeSend: function(xhr, settings) {
  52.                         // Buttonを無効にする
  53.                         $('.add-cart').prop('disabled', true);
  54.                     }
  55.                 }).done(function(data) {
  56.                     // レスポンス内のメッセージをalertで表示
  57.                     $.each(data.messages, function() {
  58.                         $('#ec-modal-header').html(this);
  59.                     });
  60.                     $('.ec-modal').show()
  61.                     // カートブロックを更新する
  62.                     $.ajax({
  63.                         url: '{{ url('block_cart') }}',
  64.                         type: 'GET',
  65.                         dataType: 'html'
  66.                     }).done(function(html) {
  67.                         $('.ec-headerRole__cart').html(html);
  68.                     });
  69.                 }).fail(function(data) {
  70.                     alert('{{ 'カートへの追加に失敗しました。'|trans }}');
  71.                 }).always(function(data) {
  72.                     // Buttonを有効にする
  73.                     $('.add-cart').prop('disabled', false);
  74.                 });
  75.             });
  76.         });
  77.         $('.ec-modal-wrap').on('click', function(e) {
  78.             // モーダル内の処理は外側にバブリングさせない
  79.             e.stopPropagation();
  80.         });
  81.         $('.ec-modal-overlay, .ec-modal, .ec-modal-close, .ec-inlineBtn--cancel').on('click', function() {
  82.             $('.ec-modal').hide()
  83.         });
  84.     $(function(){
  85.       $('.mod_movie-btn-favorite').on('click', function(){
  86.         let loginStatus = {{ is_granted('ROLE_USER') ? 'true' : 'false' }};
  87.         if(loginStatus){
  88.           let pid = $(this).data('pid');
  89.           let tmpbtn = $(this);
  90.           // tmpbtn.children("input").prop('disabled', true);
  91.           tmpbtn.children("input").attr('disabled', true);
  92.           if(tmpbtn.hasClass('favorite__del')){
  93.             $.ajax({
  94.               url: "{{ url('homepage') }}refine_delete_favorite",
  95.               type: 'GET',
  96.               dataType: 'text',
  97.               data: {id: pid}
  98.             })
  99.             .then(
  100.               function (data) {
  101.                   tmpbtn.removeClass('favorite__del');
  102.                   tmpbtn.addClass('favorite__add');
  103.               },
  104.               function () {
  105.                   alert("処理に失敗しました。お手数ですが再度実行してください");
  106.             });
  107.           } else {
  108.               $.ajax({
  109.                 url: "{{ url('homepage') }}products/add_favorite/"+pid,
  110.                 type: 'POST',
  111.               })
  112.               .then(
  113.                 function (data) {
  114.                     tmpbtn.removeClass('favorite__add');
  115.                     tmpbtn.addClass('favorite__del');
  116.                 },
  117.                 function () {
  118.                   alert("処理に失敗しました。お手数ですが再度実行してください");
  119.               });
  120.           }
  121.           // tmpbtn.children("input").prop('disabled', false);
  122.           tmpbtn.children("input").attr('disabled', false);
  123.         } else {
  124.            location.href= "{{ url('mypage_delivery') }}";
  125.         }
  126.       });
  127.     });
  128. </script>
  129. {% endblock %}
  130. {% block main %}
  131.     {% if search_form.category_id.vars.errors|length > 0 %}
  132.         <div class="ec-searchnavRole content__inner">
  133.             <p class="errormsg text-danger">{{ 'ご指定のカテゴリは存在しません'|trans }}</p>
  134.         </div>
  135.     {% else %}
  136.         <div class="ec-searchnavRole content__inner">
  137.             <form name="form1" id="form1" method="get" action="?">
  138.                 {% for item in search_form %}
  139.                     <input type="hidden" id="{{ item.vars.id }}"
  140.                            name="{{ item.vars.full_name }}"
  141.                            {% if item.vars.value is not empty %}value="{{ item.vars.value }}" {% endif %}/>
  142.                 {% endfor %}
  143.             </form>
  144.             <div class="ec-searchnavRole__topicpath">
  145.                 <ol class="ec-topicpath">
  146.                     <li class="ec-topicpath__item"><a href="{{ url('product_list') }}">{{ '全て'|trans }}</a>
  147.                     </li>
  148.                     {% if Category is not null %}
  149.                         {% for Path in Category.path %}
  150.                             <li class="ec-topicpath__divider">|</li>
  151.                             <li class="ec-topicpath__item{% if loop.last %}--active{% endif %}"><a
  152.                                         href="{{ url('product_list') }}?category_id={{ Path.id }}">{{ Path.name }}</a>
  153.                             </li>
  154.                         {% endfor %}
  155.                     {% endif %}
  156.                     {% if search_form.vars.value and search_form.vars.value.name %}
  157.                         <li class="ec-topicpath__divider">|</li>
  158.                         <li class="ec-topicpath__item">{{ '「%name%」の検索結果'|trans({ '%name%': search_form.vars.value.name }) }}</li>
  159.                     {% endif %}
  160.                 </ol>
  161.             </div>
  162.             <div class="ec-searchnavRole__infos">
  163.                 <div class="ec-searchnavRole__counter">
  164.                     {% if pagination.totalItemCount > 0 %}
  165.                         {{ '<span class="ec-font-bold">%count%件</span><span>の動画が見つかりました</span>'|trans({ '%count%': pagination.totalItemCount })|raw }}
  166.                     {% else %}
  167.                         <span>{{ 'お探しの動画は見つかりませんでした'|trans }}</span>
  168.                     {% endif %}
  169.                 </div>
  170.                 {% if pagination.totalItemCount > 0 %}
  171.                     <div class="ec-searchnavRole__actions">
  172.                         <div class="ec-select">
  173.                             {{ form_widget(disp_number_form, {'id': '', 'attr': {'class': 'disp-number'}}) }}
  174.                             {{ form_widget(order_by_form, {'id': '', 'attr': {'class': 'order-by'}}) }}
  175.                         </div>
  176.                     </div>
  177.                 {% endif %}
  178.             </div>
  179.         </div>
  180.         {% if pagination.totalItemCount > 0 %}
  181.         <div class="page__content">
  182.           <div class="page__inner">
  183.             <ul class="mod_movie-list">
  184.             {% for Product in pagination %}
  185.               {% set isFavorite = app.user is not empty and repository('Eccube\\Entity\\CustomerFavoriteProduct').isFavorite(app.user, Product) %}
  186.               {# 配信コンテンツ #}
  187.               {% set productClass = Product.ProductClasses.get(0) %}
  188.               {% set videoContent = productClass.ProductClassContent.get(0) %}
  189.               {% if videoContent is not empty %}
  190.                 {% set anker = url('video/{product_id}/content/{content_id}', {'product_id': Product.id, 'content_id': videoContent.Content.id}) %}
  191.               {% else %}
  192.                 {% set anker = url('product_detail', {'id': Product.id}) %}
  193.               {% endif %}
  194.               <li class="mod_movie-item">
  195.                 <div class="mod_movie-item-inner">
  196.                   <div class="mod_movie-img-wrapper">
  197.                     <a href="{{ anker }}">
  198.                       {% if Product.ProductImage is defined and Product.ProductImage is not empty %}
  199.                         <img src="{{ asset(Product.ProductImage.get(0), 'save_image') }}" alt="Product.name" />
  200.                       {% else %}
  201.                         <img src="{{ asset(''|no_image_product, 'save_image') }}" alt="" />
  202.                       {% endif %}
  203.                     </a>
  204.                   </div>
  205.                   <div class="mod_movie-text-wrapper">
  206.                     <a href="{{ anker }}" class="mod_movie-title">{{ Product.name|trans }}</a>
  207.                     {% set searchWords = Product.search_word|split(',') %}
  208.                     <ul class="mod_movie-keyword-list">
  209.                       {% for word in searchWords %}
  210.                         {% if word is not empty %}
  211.                         <li class="mod_movie-keyword-item">
  212.                           <span>{{ word|trans }}</span>
  213.                         </li>
  214.                         {% endif %}
  215.                       {% endfor %}
  216.                     </ul>
  217.                     <div class="mod_movie-btn-wrapper">
  218.                       <div class="mod_movie-btn-favorite {{ (isFavorite == 1) ? 'favorite__del': 'favorite__add' }}" data-pid="{{ Product.id }}">
  219.                         <input type="button" class="favorite-btn" value="{{ '見たい授業'|trans }}" />
  220.                       </div>
  221.                       <a href="{{ anker }}" class="mod_movie-btn-watch">
  222.                         <span>{{ '見る'|trans }}</span>
  223.                       </a>
  224.                     </div>
  225.                   </div>
  226.                 </div>
  227.               </li>
  228.             {% endfor %}
  229.             </ul>
  230.           </div>
  231.         </div>
  232.             {# 元々のソース #}
  233.             {# <div class="ec-shelfRole">
  234.                 <ul class="ec-shelfGrid">
  235.                     {% for Product in pagination %}
  236.                         <li class="ec-shelfGrid__item">
  237.                             <a href="{{ url('product_detail', {'id': Product.id}) }}">
  238.                                 <p class="ec-shelfGrid__item-image">
  239.                                     <img src="{{ asset(Product.main_list_image|no_image_product, 'save_image') }}" alt="{{ Product.name }}" loading="lazy">
  240.                                 </p>
  241.                                 <p>{{ Product.name }}</p>
  242.                                 {% if Product.description_list %}
  243.                                     <p>{{ Product.description_list|raw|nl2br }}</p>
  244.                                 {% endif %}
  245.                                 <p class="price02-default">
  246.                                     {% if Product.hasProductClass %}
  247.                                         {% if Product.getPrice02Min == Product.getPrice02Max %}
  248.                                             {{ Product.getPrice02IncTaxMin|price }}
  249.                                         {% else %}
  250.                                             {{ Product.getPrice02IncTaxMin|price }} ~ {{ Product.getPrice02IncTaxMax|price }}
  251.                                         {% endif %}
  252.                                     {% else %}
  253.                                         {{ Product.getPrice02IncTaxMin|price }}
  254.                                     {% endif %}
  255.                                 </p>
  256.                             </a> #}
  257.                             {# {% if Product.stock_find %}
  258.                                 {% set form = forms[Product.id] %}
  259.                                 <form name="form{{ Product.id }}" id="productForm{{ Product.id }}" action="{{ url('product_add_cart', {id:Product.id}) }}" method="post">
  260.                                     <div class="ec-productRole__actions">
  261.                                         {% if form.classcategory_id1 is defined %}
  262.                                             <div class="ec-select">
  263.                                                 {{ form_widget(form.classcategory_id1) }}
  264.                                                 {{ form_errors(form.classcategory_id1) }}
  265.                                             </div>
  266.                                             {% if form.classcategory_id2 is defined %}
  267.                                                 <div class="ec-select">
  268.                                                     {{ form_widget(form.classcategory_id2) }}
  269.                                                     {{ form_errors(form.classcategory_id2) }}
  270.                                                 </div>
  271.                                             {% endif %}
  272.                                         {% endif %}
  273.                                         <div class="ec-numberInput"><span>{{ '数量'|trans }}</span>
  274.                                             {{ form_widget(form.quantity, {'attr': {'class': 'quantity'}}) }}
  275.                                             {{ form_errors(form.quantity) }}
  276.                                         </div>
  277.                                     </div>
  278.                                     {{ form_rest(form) }}
  279.                                 </form>
  280.                                 <div class="ec-productRole__btn">
  281.                                     <button type="submit" class="ec-blockBtn--action add-cart" data-cartid="{{ Product.id }}" form="productForm{{ Product.id }}">
  282.                                         {{ 'カートに入れる'|trans }}
  283.                                     </button>
  284.                                 </div>
  285.                             {% else %}
  286.                                 <div class="ec-productRole__btn">
  287.                                     <button type="button" class="ec-blockBtn--action" disabled="disabled">
  288.                                         {{ 'ただいま品切れ中です。'|trans }}
  289.                                     </button>
  290.                                 </div>
  291.                             {% endif %} #}
  292.                         {# </li>
  293.                     {% endfor %}
  294.                 </ul>
  295.             </div>
  296.             <div class="ec-modal">
  297.                 <div class="ec-modal-overlay">
  298.                     <div class="ec-modal-wrap">
  299.                         <span class="ec-modal-close"><span class="ec-icon"><img src="{{ asset('assets/icon/cross-dark.svg') }}" alt=""/></span></span>
  300.                         <div id="ec-modal-header" class="text-center">{{ 'カートに追加しました。'|trans }}</div>
  301.                         <div class="ec-modal-box">
  302.                             <div class="ec-role">
  303.                                 <span class="ec-inlineBtn--cancel">{{ 'お買い物を続ける'|trans }}</span>
  304.                                 <a href="{{ url('cart') }}" class="ec-inlineBtn--action">{{ 'カートへ進む'|trans }}</a>
  305.                             </div>
  306.                         </div>
  307.                     </div>
  308.                 </div>
  309.             </div> #}
  310.             <div class="ec-pagerRole">
  311.                 {% include "pager.twig" with {'pages': pagination.paginationData} %}
  312.             </div>
  313.         {% endif %}
  314.     {% endif %}
  315. {% endblock %}