app/Plugin/Recommend42/Resource/template/Product/list.twig line 1

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