app/template/bynoiezam/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 product_list' %}
  10. {% block stylesheet %}
  11.     <link rel="stylesheet" href="{{ asset('assets/css/game-category-layout.css', 'user_data') }}">
  12. {% endblock %}
  13. {% block javascript %}
  14.     <script>
  15.         eccube.productsClassCategories = {
  16.             {% for Product in pagination %}
  17.             "{{ Product.id|escape('js') }}": {{ class_categories_as_json(Product)|raw }}{% if loop.last == false %}, {% endif %}
  18.             {% endfor %}
  19.         };
  20.         $(function() {
  21.             // 表示件数を変更
  22.             $('.disp-number').change(function() {
  23.                 var dispNumber = $(this).val();
  24.                 $('#disp_number').val(dispNumber);
  25.                 $('#pageno').val(1);
  26.                 $("#form1").submit();
  27.             });
  28.             // 並び順を変更
  29.             $('.order-by').change(function() {
  30.                 var orderBy = $(this).val();
  31.                 $('#orderby').val(orderBy);
  32.                 $('#pageno').val(1);
  33.                 $("#form1").submit();
  34.             });
  35.             $('.add-cart').on('click', function(e) {
  36.                 var $form = $(this).parents('li').find('form');
  37.                 // 個数フォームのチェック
  38.                 var $quantity = $form.parent().find('.quantity');
  39.                 if ($quantity.val() < 1) {
  40.                     $quantity[0].setCustomValidity('{{ '1以上で入力してください。'|trans }}');
  41.                     setTimeout(function() {
  42.                         loadingOverlay('hide');
  43.                     }, 100);
  44.                     return true;
  45.                 } else {
  46.                     $quantity[0].setCustomValidity('');
  47.                 }
  48.                 e.preventDefault();
  49.                 $.ajax({
  50.                     url: $form.attr('action'),
  51.                     type: $form.attr('method'),
  52.                     data: $form.serialize(),
  53.                     dataType: 'json',
  54.                     beforeSend: function(xhr, settings) {
  55.                         // Buttonを無効にする
  56.                         $('.add-cart').prop('disabled', true);
  57.                     }
  58.                 }).done(function(data) {
  59.                     // レスポンス内のメッセージをalertで表示
  60.                     $.each(data.messages, function() {
  61.                         $('#ec-modal-header').html(this);
  62.                     });
  63.                     $('.ec-modal').show()
  64.                     // カートブロックを更新する
  65.                     $.ajax({
  66.                         url: '{{ url('block_cart') }}',
  67.                         type: 'GET',
  68.                         dataType: 'html'
  69.                     }).done(function(html) {
  70.                         $('.ec-headerRole__cart').html(html);
  71.                     });
  72.                 }).fail(function(data) {
  73.                     alert('{{ 'カートへの追加に失敗しました。'|trans }}');
  74.                 }).always(function(data) {
  75.                     // Buttonを有効にする
  76.                     $('.add-cart').prop('disabled', false);
  77.                 });
  78.             });
  79.         });
  80.         $('.ec-modal-wrap').on('click', function(e) {
  81.             // モーダル内の処理は外側にバブリングさせない
  82.             e.stopPropagation();
  83.         });
  84.         $('.ec-modal-overlay, .ec-modal, .ec-modal-close, .ec-inlineBtn--cancel').on('click', function() {
  85.             $('.ec-modal').hide()
  86.         });
  87.         // ゲーム別おすすめPC 親カテゴリ専用レイアウト (ID=46)
  88.         {% if Category and Category.id == 46 %}
  89.         (function() {
  90.             console.log('=== Game category parent layout: Started ===');
  91.             
  92.             // 子カテゴリの定義
  93.             var gameCategories = [
  94.                 {
  95.                     id: 47,
  96.                     name: 'ARC Raiders',
  97.                     icon: '/html/user_data/game_icons/arc_raiders.jpg'
  98.                 },
  99.                 {
  100.                     id: 48,
  101.                     name: 'APEX LEGENDS',
  102.                     icon: '/html/user_data/game_icons/apex_legends.jpg'
  103.                 },
  104.                 {
  105.                     id: 49,
  106.                     name: 'Valorant',
  107.                     icon: '/html/user_data/game_icons/valorant.jpg'
  108.                 },
  109.                 {
  110.                     id: 50,
  111.                     name: '原神',
  112.                     icon: '/html/user_data/game_icons/genshin.jpg'
  113.                 }
  114.             ];
  115.             
  116.             var $shelfGrid = $('.ec-shelfGrid');
  117.             var $items = $shelfGrid.find('.ec-shelfGrid__item');
  118.             
  119.             if ($items.length === 0) {
  120.                 console.warn('No products found');
  121.                 return;
  122.             }
  123.             
  124.             // 商品をカテゴリごとに分類
  125.             var productsByCategory = {};
  126.             
  127.             $items.each(function() {
  128.                 var $item = $(this);
  129.                 var categoryIds = $item.attr('data-category-ids');
  130.                 
  131.                 if (!categoryIds) return;
  132.                 
  133.                 var categories = categoryIds.split(',').map(function(id) {
  134.                     return parseInt(id.trim());
  135.                 });
  136.                 
  137.                 gameCategories.forEach(function(game) {
  138.                     if (categories.indexOf(game.id) !== -1) {
  139.                         if (!productsByCategory[game.id]) {
  140.                             productsByCategory[game.id] = [];
  141.                         }
  142.                         productsByCategory[game.id].push($item.clone());
  143.                     }
  144.                 });
  145.             });
  146.             
  147.             // 新しいレイアウトを構築
  148.             var $newLayout = $('<div class="game-category-parent-layout"></div>');
  149.             
  150.             gameCategories.forEach(function(game) {
  151.                 var products = productsByCategory[game.id] || [];
  152.                 
  153.                 var $section = $('<div class="game-section" data-game-id="' + game.id + '"></div>');
  154.                 var $title = $('<h2 class="game-section-title">' + 
  155.                     '<a href="{{ url("product_list") }}?category_id=' + game.id + '">' + 
  156.                     game.name + ' 推奨PC</a>' +
  157.                     '</h2>');
  158.                 
  159.                 var $layout = $('<div class="game-section-layout"></div>');
  160.                 var $iconSection = $('<a href="{{ url("product_list") }}?category_id=' + game.id + '" class="game-icon-section">' +
  161.                     '<img src="' + game.icon + '" alt="' + game.name + '" class="game-icon-image">' +
  162.                     '</a>');
  163.                 
  164.                 var $productsSection = $('<div class="game-products-section"></div>');
  165.                 var $slider = $('<div class="game-products-slider slider-' + game.id + '"></div>');
  166.                 
  167.                 if (products.length > 0) {
  168.                     products.forEach(function($product) {
  169.                         $slider.append($product);
  170.                     });
  171.                 } else {
  172.                     $slider.html('<div class="no-products"><p>商品準備中です</p></div>');
  173.                 }
  174.                 
  175.                 $productsSection.append($slider);
  176.                 $layout.append($iconSection);
  177.                 $layout.append($productsSection);
  178.                 $section.append($title);
  179.                 $section.append($layout);
  180.                 $newLayout.append($section);
  181.             });
  182.             
  183.             $shelfGrid.replaceWith($newLayout);
  184.             
  185.             // スライダー初期化
  186.             setTimeout(function() {
  187.                 gameCategories.forEach(function(game) {
  188.                     var $sliderElement = $('.slider-' + game.id);
  189.                     var itemCount = $sliderElement.find('.ec-shelfGrid__item').length;
  190.                     
  191.                     if (itemCount > 0) {
  192.                         if ($sliderElement.hasClass('slick-initialized')) {
  193.                             $sliderElement.slick('unslick');
  194.                         }
  195.                         
  196.                         $sliderElement.slick({
  197.                             slidesToShow: 4,
  198.                             slidesToScroll: 1,
  199.                             infinite: false,
  200.                             arrows: true,
  201.                             dots: false,
  202.                             prevArrow: '<button type="button" class="slick-prev"><img src="{{ asset("assets/icon/slick-arrow-left-white.svg") }}" alt="前へ" /></button>',
  203.                             nextArrow: '<button type="button" class="slick-next"><img src="{{ asset("assets/icon/slick-arrow-right-white.svg") }}" alt="次へ" /></button>',
  204.                             responsive: [
  205.                                 {
  206.                                     breakpoint: 1200,
  207.                                     settings: { slidesToShow: 3, dots: false }
  208.                                 },
  209.                                 {
  210.                                     breakpoint: 768,
  211.                                     settings: { slidesToShow: 1, slidesToScroll: 1, arrows: false, dots: false }
  212.                                 },
  213.                                 {
  214.                                     breakpoint: 480,
  215.                                     settings: { slidesToShow: 1, slidesToScroll: 1, arrows: false, dots: false }
  216.                                 }
  217.                             ]
  218.                         });
  219.                         
  220.                         // スマホでスライド状態を監視
  221.                         if ($(window).width() <= 768) {
  222.                             $sliderElement.on('afterChange', function(event, slick, currentSlide) {
  223.                                 var isLast = (currentSlide >= slick.slideCount - 1);
  224.                                 
  225.                                 if (isLast) {
  226.                                     $(this).closest('.game-products-section').addClass('no-more-slides');
  227.                                 } else {
  228.                                     $(this).closest('.game-products-section').removeClass('no-more-slides');
  229.                                 }
  230.                             });
  231.                         }
  232.                     }
  233.                 });
  234.             }, 300);
  235.             
  236.             console.log('=== Game category parent layout: Complete ===');
  237.         })();
  238.         {% endif %}
  239.     </script>
  240. {% endblock %}
  241. {% block main %}
  242.     {% if search_form.vars.value.category_id.id is defined %}
  243.     {{ include('Block/category'~search_form.vars.value.category_id.id~'.twig', ignore_missing = true) }}
  244.     {% endif %}
  245.     {% if search_form.category_id.vars.errors|length > 0 %}
  246.         <div class="ec-searchnavRole">
  247.             <p class="errormsg text-danger">{{ 'ご指定のカテゴリは存在しません'|trans }}</p>
  248.         </div>
  249.     {% else %}
  250.         <div class="ec-searchnavRole">
  251.             <form name="form1" id="form1" method="get" action="?">
  252.                 {% for item in search_form %}
  253.                     <input type="hidden" id="{{ item.vars.id }}"
  254.                            name="{{ item.vars.full_name }}"
  255.                            {% if item.vars.value is not empty %}value="{{ item.vars.value }}" {% endif %}/>
  256.                 {% endfor %}
  257.             </form>
  258.             <div class="ec-searchnavRole__topicpath">
  259.                 <ol class="ec-topicpath">
  260.                     <li class="ec-topicpath__item"><a href="{{ url('product_list') }}">{{ '全て'|trans }}</a>
  261.                     </li>
  262.                     {% if Category is not null %}
  263.                         {% for Path in Category.path %}
  264.                             <li class="ec-topicpath__divider">|</li>
  265.                             <li class="ec-topicpath__item{% if loop.last %}--active{% endif %}"><a
  266.                                         href="{{ url('product_list') }}?category_id={{ Path.id }}">{{ Path.name }}</a>
  267.                             </li>
  268.                         {% endfor %}
  269.                     {% endif %}
  270.                     {% if search_form.vars.value and search_form.vars.value.name %}
  271.                         <li class="ec-topicpath__divider">|</li>
  272.                         <li class="ec-topicpath__item">{{ '「%name%」の検索結果'|trans({ '%name%': search_form.vars.value.name }) }}</li>
  273.                     {% endif %}
  274.                 </ol>
  275.             </div>
  276.             <div class="ec-searchnavRole__infos">
  277.                 <div class="ec-searchnavRole__counter">
  278.                     {% if pagination.totalItemCount > 0 %}
  279.                         {{ '<span class="ec-font-bold">%count%件</span><span>の商品が見つかりました</span>'|trans({ '%count%': pagination.totalItemCount })|raw }}
  280.                     {% else %}
  281.                         <span>{{ 'お探しの商品は見つかりませんでした'|trans }}</span>
  282.                     {% endif %}
  283.                 </div>
  284.                 {% if pagination.totalItemCount > 0 %}
  285.                     <div class="ec-searchnavRole__actions">
  286.                         <div class="ec-select">
  287.                             {{ form_widget(search_form.disp_number, {'id': '', 'attr': {'class': 'disp-number'}}) }}
  288.                             {{ form_widget(search_form.orderby, {'id': '', 'attr': {'class': 'order-by'}}) }}
  289.                         </div>
  290.                     </div>
  291.                 {% endif %}
  292.             </div>
  293.         </div>
  294.         {% if pagination.totalItemCount > 0 %}
  295.             <div class="ec-shelfRole">
  296.                 <ul class="ec-shelfGrid">
  297.                     {% for Product in pagination %}
  298.                         <li class="ec-shelfGrid__item" 
  299.                             data-product-id="{{ Product.id }}"
  300.                             {% if Product.ProductCategories|length > 0 %}
  301.                                 data-category-ids="{% for pc in Product.ProductCategories %}{{ pc.Category.id }}{% if not loop.last %},{% endif %}{% endfor %}"
  302.                             {% endif %}>
  303.                             <a href="{{ url('product_detail', {'id': Product.id}) }}">
  304.                                 <p class="ec-shelfGrid__item-image">
  305.                                     <img src="{{ asset(Product.main_list_image|no_image_product, 'save_image') }}" alt="{{ Product.name }}" loading="lazy">
  306.                                 </p>
  307.                                 <ul class="ec-shelfRole__tags">
  308.                                     {% for Tag in Product.ProductTag %}
  309.                                     {{ include('@DesignTag42/tag_list.twig', ignore_missing = true) }}
  310.                                         {% if Tag %}
  311.                                             <li class="ec-shelfRole__tag">{{ Tag.Tag }}</li>
  312.                                         {% endif %}
  313.                                     {% endfor %}
  314.                                 </ul>
  315.                                 <p class="ec-shelfGrid__item-name">{{ Product.name }}</p>
  316.                                 {% if Product.description_list %}
  317.                                     <p>{{ Product.description_list|raw|nl2br }}</p>
  318.                                 {% endif %}
  319.                                 <p class="price02-default">
  320.                                     {% if Product.hasProductClass %}
  321.                                         {% if Product.getPrice02Min == Product.getPrice02Max %}
  322.                                             {{ Product.getPrice02IncTaxMin|price }}
  323.                                         {% else %}
  324.                                             {{ Product.getPrice02IncTaxMin|price }} ~ {{ Product.getPrice02IncTaxMax|price }}
  325.                                         {% endif %}
  326.                                     {% else %}
  327.                                         {{ Product.getPrice02IncTaxMin|price }}
  328.                                     {% endif %}
  329.                                 </p>
  330.                             </a>
  331.                         </li>
  332.                     {% endfor %}
  333.                 </ul>
  334.             </div>
  335.             <div class="ec-modal">
  336.                 <div class="ec-modal-overlay">
  337.                     <div class="ec-modal-wrap">
  338.                         <span class="ec-modal-close"><span class="ec-icon"><img src="{{ asset('assets/icon/cross-dark.svg') }}" alt=""/></span></span>
  339.                         <div id="ec-modal-header" class="text-center">{{ 'カートに追加しました。'|trans }}</div>
  340.                         <div class="ec-modal-box">
  341.                             <div class="ec-role">
  342.                                 <span class="ec-inlineBtn--cancel">{{ 'お買い物を続ける'|trans }}</span>
  343.                                 <a href="{{ url('cart') }}" class="ec-inlineBtn--action">{{ 'カートへ進む'|trans }}</a>
  344.                             </div>
  345.                         </div>
  346.                     </div>
  347.                 </div>
  348.             </div>
  349.             <div class="ec-pagerRole">
  350.                 {% include "pager.twig" with {'pages': pagination.paginationData} %}
  351.             </div>
  352.         {% endif %}
  353.     {% endif %}
  354. {% endblock %}