app/template/user_data/books.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 = 'front_page' %}
  10. {% block stylesheet %}
  11.     <link rel="stylesheet" href="{{ asset('assets/css/main_style.css', 'user_data') }}">
  12.     <link rel="stylesheet" href="{{ asset('assets/css/main_module.css', 'user_data') }}">
  13.     <style>
  14.         .new {
  15.           position: absolute;
  16.           top: -1%;
  17.           left: -2%;
  18.           width: 40%;
  19.           height: 19%;
  20.           background: linear-gradient(to top left, transparent 50%, #df0b75 50%);
  21.           z-index: 10;
  22.           display: flex;
  23.           align-items: center;
  24.           justify-content: center;
  25.           transform-origin: top left;
  26.           color: white;
  27.           clip-path: polygon(0 60%, 60% 0, 100% 0, 0 100%);
  28.         }
  29.             
  30.         .new-text {
  31.           position: absolute;
  32.           color: #ffffff;
  33.           font-weight: bold;
  34.           font-size: 1em;
  35.           text-align: center;
  36.           line-height: 3em;
  37.           transform: rotate(-45deg) translate(-10%,-30%);
  38.         }
  39.         
  40.     </style>
  41. {% endblock %}
  42. {% block main %}
  43.   <!-- ファーストビュー -->
  44. <section class="first-carousel">
  45.     <div class="carousel">
  46.         {# ダミー: 最後の画像(ループ用) #}
  47.         <a class="car-cont"><img src="{{ asset('assets/img/mv3.png', 'user_data') }}" alt="slide3" /></a>
  48.         {# 本来のスライド #}
  49.         <a class="car-cont"><img src="{{ asset('assets/img/mv1.png', 'user_data') }}" alt="slide1" /></a>
  50.         <a class="car-cont"><img src="{{ asset('assets/img/mv2.png', 'user_data') }}" alt="slide2" /></a>
  51.         <a class="car-cont"><img src="{{ asset('assets/img/mv3.png', 'user_data') }}" alt="slide3" /></a>
  52.         <a class="car-cont"><img src="{{ asset('assets/img/mv2.png', 'user_data') }}" alt="slide4" /></a>
  53.         {# ダミー: 最初の画像(ループ用) #}
  54.         <a class="car-cont"><img src="{{ asset('assets/img/mv1.png', 'user_data') }}" alt="slide1" /></a>
  55.     </div>
  56.     <div class="carousel-dots">
  57.         <span class="dot active"></span>
  58.         <span class="dot"></span>
  59.         <span class="dot"></span>
  60.         <span class="dot"></span>
  61.     </div>
  62.     <div class="carousel-btn prev-btn" style="display:none;">←</div>
  63.     <div class="carousel-btn next-btn" style="display:none;">→</div>
  64. </section>
  65. {% block javascript %}
  66. <script>
  67. window.addEventListener("load", function () {
  68.     const carousel = document.querySelector(".carousel");
  69.     const dots = document.querySelectorAll(".dot");
  70.     let slides = Array.from(document.querySelectorAll(".carousel a"));
  71.     const firstClone = slides[0].cloneNode(true);
  72.     const lastClone = slides[slides.length - 1].cloneNode(true);
  73.     carousel.appendChild(firstClone);
  74.     carousel.insertBefore(lastClone, slides[0]);
  75.     slides = Array.from(document.querySelectorAll(".carousel a"));
  76.     let currentIndex = 1;
  77.     let slideWidth = slides[0].offsetWidth + 40;
  78.     let isTransitioning = false;
  79.     function updateSlidePosition(withTransition = false) {
  80.         carousel.style.transition = withTransition ? "transform 2s ease-in-out" : "none";
  81.         carousel.style.transform = `translateX(${-slideWidth * currentIndex}px)`;
  82.     }
  83.     function updateDots() {
  84.         dots.forEach(dot => dot.classList.remove("active"));
  85.         const activeDotIndex = (currentIndex - 1 + dots.length) % dots.length;
  86.         dots[activeDotIndex].classList.add("active");
  87.     }
  88.     function updateActiveSlide() {
  89.         slides.forEach(slide => slide.classList.remove("active"));
  90.         slides[currentIndex]?.classList.add("active");
  91.     }
  92.     function goToSlide(index) {
  93.         if (isTransitioning) return; // ← 連打・タイミングずれ防止
  94.         isTransitioning = true;
  95.         currentIndex = index;
  96.         updateSlidePosition(true);
  97.         updateDots();
  98.         updateActiveSlide();
  99.     }
  100.     // 無限ループ処理(修正済)
  101.     carousel.addEventListener("transitionend", () => {
  102.         if (currentIndex === 0) {
  103.             currentIndex = slides.length - 2;
  104.             carousel.style.transition = "none";
  105.             carousel.style.transform = `translateX(${-slideWidth * currentIndex}px)`;
  106.             updateActiveSlide();
  107.         } else if (currentIndex === slides.length - 1) {
  108.             currentIndex = 1;
  109.             carousel.style.transition = "none";
  110.             carousel.style.transform = `translateX(${-slideWidth * currentIndex}px)`;
  111.             updateActiveSlide();
  112.         }
  113.         isTransitioning = false; // ← 切り替え終わったら解放
  114.     });
  115.     document.querySelector(".prev-btn")?.addEventListener("click", () => goToSlide(currentIndex - 1));
  116.     document.querySelector(".next-btn")?.addEventListener("click", () => goToSlide(currentIndex + 1));
  117.     dots.forEach((dot, idx) => {
  118.         dot.addEventListener("click", () => goToSlide(idx + 1));
  119.     });
  120.     window.addEventListener("resize", () => {
  121.         slideWidth = slides[0].offsetWidth + 40;
  122.         updateSlidePosition();
  123.     });
  124.     updateSlidePosition();
  125.     updateActiveSlide();
  126.     updateDots();
  127.     // 自動スライド(isTransitioning考慮)
  128.     let autoSlideInterval = setInterval(() => {
  129.         if (!isTransitioning) {
  130.             goToSlide(currentIndex + 1);
  131.         }
  132.     }, 4500);
  133.     document.addEventListener("visibilitychange", () => {
  134.         if (document.hidden) {
  135.             clearInterval(autoSlideInterval);
  136.         } else {
  137.             autoSlideInterval = setInterval(() => {
  138.                 if (!isTransitioning) {
  139.                     goToSlide(currentIndex + 1);
  140.                 }
  141.             }, 4500);
  142.         }
  143.     });
  144. });
  145. </script>
  146. {% endblock %}
  147.     
  148.         <!-- メインコンテンツ -->
  149.     <main class="main-content">
  150.         <!-- 上位コンテンツ -->
  151.         <section class="special-1">
  152.             <div class="bg-blue-1"></div>
  153.             <!-- 新刊 -->
  154.             <h2 class="newbook-title"><img src="{{ asset('assets/img/title_ic_newbook.svg', 'user_data') }}" alt="new-books" class="newbook-icon"> 新刊案内</h2>
  155.             <div class="pipe-line">
  156.                 <div class="pipe">
  157.                     <div class="line"></div>
  158.                 </div>
  159.                 <div class="white"></div>
  160.             </div>
  161.             {# まず、Tag.id==1の商品だけ別に集める #}
  162.             {% set newTaggedProducts = [] %}
  163.             {% for Product in Products %}
  164.                 {% for ProductTag in Product.ProductTag %}
  165.                     {% if ProductTag.Tag.id == 1 %}
  166.                         {% set newTaggedProducts = newTaggedProducts|merge([Product]) %}
  167.                     {% endif %}
  168.                 {% endfor %}
  169.             {% endfor %}
  170.             {# その上でランダムシャッフルして5件だけ抜く #}
  171.             {% set newTaggedRandomProducts = [] %}
  172.             {% set newTaggedworkingProducts = newTaggedProducts %}
  173.                 {% for i in 0..4 %}
  174.                     {#{% set randomProducts = randomProducts|merge([random(taggedProducts)]) %}#}
  175.                     {% if newTaggedworkingProducts|length > 0 %}
  176.                         {% set newTaggedRandomIndex = random(newTaggedworkingProducts|keys) %}
  177.                         {% set newTaggedrandomProduct = newTaggedworkingProducts[newTaggedRandomIndex] %}
  178.                         {% set newTaggedRandomProducts = newTaggedRandomProducts|merge([newTaggedrandomProduct]) %}
  179.                         {# 選んだやつをworkingProductsから除外する #}
  180.                         {% set newTaggedworkingProducts = newTaggedworkingProducts|filter(p => p != newTaggedrandomProduct) %}
  181.                     {% endif %}
  182.                 {% endfor %}
  183.             <div class="content-1">
  184.                 {% for Product in newTaggedRandomProducts %}
  185.                     <div class="card-1">
  186.                         {% for ProductTags in Product.ProductTag %}
  187.                             {% if ProductTags.Tag.id == 1 %}
  188.                                 <div class="new">
  189.                                     <div class="new-text">New</div>
  190.                                 </div>
  191.                             {% endif %}
  192.                         {% endfor %}
  193.                         <a href="{{ url('product_detail', {'id': Product.id}) }}">
  194.                             <img src="{{asset(Product.main_list_image|no_image_product, 'save_image') }}" class="" alt="コンテンツ1"/>
  195.                         </a>
  196.                         <h3>{{Product.name}}</h3>
  197.                         <p>著者:<span>{{Product.author}}</span></p>
  198.                         <p>¥<span>{{ Product.getPrice02IncTaxMax|number_format(0, '.', ',')  }}</span>税込</p>
  199.                     </div>
  200.                 {% endfor %}
  201.             </div>
  202.             <!-- オススメ書籍 -->
  203.             <h2 class="newbook-title"><img src="{{ asset('assets/img/title_ic_recommend.svg', 'user_data') }}" alt="new-books" class="newbook-icon"> オススメ書籍</h2>
  204.             <div class="pipe-line">
  205.                 <div class="pipe">
  206.                     <div class="line"></div>
  207.                 </div>
  208.                 <div class="blue"></div>
  209.             </div>
  210.             {# まず、Tag.id==1の商品だけ別に集める #}
  211.             {% set taggedProducts = [] %}
  212.             {% for Product in Products %}
  213.                 {% for ProductTag in Product.ProductTag %}
  214.                     {% if ProductTag.Tag.id == 2 %}
  215.                         {% set taggedProducts = taggedProducts|merge([Product]) %}
  216.                     {% endif %}
  217.                 {% endfor %}
  218.             {% endfor %}
  219.             {# その上でランダムシャッフルして5件だけ抜く #}
  220.             {% set randomProducts = [] %}
  221.             {% set workingProducts = taggedProducts %}
  222.                 {% for i in 0..4 %}
  223.                     {#{% set randomProducts = randomProducts|merge([random(taggedProducts)]) %}#}
  224.                     {% if workingProducts|length > 0 %}
  225.                         {% set randomIndex = random(workingProducts|keys) %}
  226.                         {% set randomProduct = workingProducts[randomIndex] %}
  227.                         {% set randomProducts = randomProducts|merge([randomProduct]) %}
  228.                         {# 選んだやつをworkingProductsから除外する #}
  229.                         {% set workingProducts = workingProducts|filter(p => p != randomProduct) %}
  230.                     {% endif %}
  231.                 {% endfor %}
  232.             <div class="content-1">
  233.                 {% for Product in randomProducts %}
  234.                     <div class="card-1">
  235.                         {% for ProductTags in Product.ProductTag %}
  236.                             {% if ProductTags.Tag.id == 1 %}
  237.                                 <div class="new">
  238.                                     <div class="new-text">New</div>
  239.                                 </div>
  240.                             {% endif %}
  241.                         {% endfor %}
  242.                         <a href="{{ url('product_detail', {'id': Product.id}) }}">
  243.                             <img src="{{asset(Product.main_list_image|no_image_product, 'save_image') }}" class="" alt="コンテンツ1"/>
  244.                         </a>
  245.                         <h3>{{Product.name}}</h3>
  246.                         <p>著者:<span>{{Product.author}}</span></p>
  247.                         <p>¥<span>{{ Product.getPrice02IncTaxMax|number_format(0, '.', ',') }}</span>税込</p>
  248.                     </div>
  249.                 {% endfor %}
  250.             </div>
  251.         </section>
  252.         <!-- 中盤コンテンツ -->
  253.         <section class="special-2">
  254.             <!-- 売れ筋ランキング -->
  255.             <h2 class="newbook-title"><img src="{{ asset('assets/img/title_ic_ranking.svg', 'user_data') }}" alt="ranking" class="newbook-icon"> 売れ筋ランキング</h2>
  256.             <div class="pipe-line">
  257.                 <div class="pipe">
  258.                     <div class="line"></div>
  259.                 </div>
  260.                 <div class="green"></div>
  261.             </div>
  262.             <div class="content-2">
  263.                 {% set rankTaggedProducts = [] %}
  264.                 {% for Product in Products %}
  265.                     {% for ProductTag in Product.ProductTag %}
  266.                         {% if ProductTag.Tag.id >=3 and ProductTag.Tag.id<=9 %}
  267.                             {% set rankTaggedProducts = rankTaggedProducts|merge([{'product': Product, 'tag_id': ProductTag.Tag.id}]) %}
  268.                         {% endif %}
  269.                     {% endfor %}
  270.                 {% endfor %}
  271.                 {% set rankTaggedProducts = rankTaggedProducts|sort((a, b) => a.tag_id <=> b.tag_id) %}
  272.                 {% for Product in rankTaggedProducts %}
  273.                         <div class="card-2">
  274.                             <div class="lank">
  275.                                 <div class="lank-num">{{Product.tag_id - 2}}</div>
  276.                             </div>
  277.                             {% for ProductTags in Product.product.ProductTag %}
  278.                                     {% if ProductTags.Tag.id == 1 %}
  279.                                         <div class="new">
  280.                                             <div class="new-text">New</div>
  281.                                         </div>
  282.                                     {% endif %}
  283.                             {% endfor %}
  284.                             <a href="{{ url('product_detail', {'id': Product.product.id}) }}">
  285.                                 <img src="{{asset(Product.product.main_list_image|no_image_product, 'save_image') }}" class="" alt="コンテンツ1"/>
  286.                             </a>
  287.                             <h3>{{Product.product.name}}</h3>
  288.                             <p>著者:<span>{{Product.product.author}}</span></p>
  289.                             <p>¥<span>{{ Product.product.getPrice02IncTaxMax|number_format(0, '.', ',') }}</span>税込</p>
  290.                         </div>
  291.                 {% endfor %}
  292.             </div>
  293.             <!-- 最近チェック -->
  294.             {% if RecentlyViewedProducts|length > 0 %}
  295.             <h2 class="newbook-title"><img src="{{ asset('assets/img/title_ic_check.svg', 'user_data')}}" alt="check" class="newbook-icon"> 最近チェックした商品</h2>
  296.             <div class="pipe-line">
  297.                 <div class="pipe">
  298.                     <div class="line"></div>
  299.                 </div>
  300.                 <div class="green"></div>
  301.             </div>
  302.             {{ render(path('block_recently_viewed_products')) }}
  303.             {% endif %}
  304.             
  305.             
  306.             
  307.             {#あなたへのおすすめ#}
  308.             {% if is_granted('ROLE_USER') %}
  309.             <h2><img src="{{asset('assets/img/title_ic_check.svg', 'user_data') }}" alt="あなたへのオススメ"> あなたへのオススメ</2>
  310.             <div class="pipe-line">
  311.                 <div class="pipe">
  312.                     <div class="line"></div>
  313.                 </div>
  314.                 <div class="green"></div>
  315.             </div>
  316.             <div class="content-2">
  317.                 {# ランダムシャッフルして7件だけ抜く #}
  318.                 {% set randomProducts = [] %}
  319.                 {% set workingProducts = recommendProducts %}
  320.                     {% for i in 0..6 %}
  321.                         {#{% set randomProducts = randomProducts|merge([random(taggedProducts)]) %}#}
  322.                         {% if workingProducts|length > 0 %}
  323.                             {% set randomIndex = random(workingProducts|keys) %}
  324.                             {% set randomProduct = workingProducts[randomIndex] %}
  325.                             {% set randomProducts = randomProducts|merge([randomProduct]) %}
  326.                             {# 選んだやつをworkingProductsから除外する #}
  327.                             {% set workingProducts = workingProducts|filter(p => p != randomProduct) %}
  328.                         {% endif %}
  329.                     {% endfor %}
  330.                     {% for Product in randomProducts %}
  331.                             <div class="card-2 osusume">
  332.                                 {% for ProductTags in Product.ProductTag %}
  333.                                     {% if ProductTags.Tag.id == 1 %}
  334.                                         <div class="new">
  335.                                             <div class="new-text">New</div>
  336.                                         </div>
  337.                                     {% endif %}
  338.                                 {% endfor %}
  339.                                 <a href="{{ url('product_detail', {'id': Product.id}) }}">
  340.                                     <img src="{{asset(Product.main_list_image|no_image_product, 'save_image') }}" class="" alt="コンテンツ1"/>
  341.                                 </a>
  342.                                 <h3>{{Product.name}}</h3>
  343.                                 <p>著者:<span>{{Product.author}}</span></p>
  344.                                 <p>¥<span>{{ Product.getPrice02IncTaxMax|number_format(0, '.', ',') }}</span>税込</p>
  345.                             </div>
  346.                     {% endfor %}
  347.                 </div>
  348.             {% endif %}
  349.         </section>
  350.         <style>
  351.             .ec-historyRole {
  352.                 padding: 0;
  353.             }
  354.             .ec-historyRole__heading {
  355.                 display: none;
  356.             }
  357.             </style>
  358.         <!-- 下位コンテンツ -->
  359.         <section class="special-3">
  360.             <h2 class="newbook-title"><img src="{{ asset('assets/img/title_ic_category.svg', 'user_data') }} " alt="" class="newbook-icon"> 書籍カテゴリー</h2>
  361.             <div class="pipe-line">
  362.                 <div class="pipe">
  363.                     <div class="line"></div>
  364.                 </div>
  365.                 <div class="white"></div>
  366.             </div>
  367.             {# まず、Category.id==1の商品だけ別に集める #}
  368.             {% set CategoryProducts = [] %}
  369.             {% for Product in Products %}
  370.                 {% for ProductCategory in Product.ProductCategories %}
  371.                     {% if ProductCategory.Category.id == 1 %}
  372.                         {% set CategoryProducts = CategoryProducts|merge([Product]) %}
  373.                     {% endif %}
  374.                 {% endfor %}
  375.             {% endfor %}
  376.             {# その上でランダムシャッフルして5件だけ抜く #}
  377.             {% set randomProducts = [] %}
  378.             {% set workingProducts = CategoryProducts %}
  379.                 {% for i in 0..4 %}
  380.                     {% if workingProducts|length > 0 %}
  381.                         {% set randomIndex = random(workingProducts|keys) %}
  382.                         {% set randomProduct = workingProducts[randomIndex] %}
  383.                         {% set randomProducts = randomProducts|merge([randomProduct]) %}
  384.                         {# 選んだやつをworkingProductsから除外する #}
  385.                         {% set workingProducts = workingProducts|filter(p => p != randomProduct) %}
  386.                     {% endif %}
  387.                 {% endfor %}
  388.             <div class="content-3">
  389.                 <!-- 鉄道 -->
  390.                 <div class="sub-cont">
  391.                     <div class="con-title">
  392.                         <h3>鉄道</h3>
  393.                         <a href="{{ url('product_list') }}?category_id=1" class="list-link">
  394.                             <span class="list-btn">一覧はコチラ</span>
  395.                             <span class="btn-l">→</span>
  396.                         </a>
  397.                     </div>
  398.                     <div class="zone">
  399.                     {% for Product in randomProducts %}
  400.                         <div class="card-3">
  401.                             <a href="{{ url('product_detail', {'id': Product.id}) }}">
  402.                                 <img src="{{asset(Product.main_list_image|no_image_product, 'save_image') }}" class="" alt="コンテンツ1"/>
  403.                             </a>
  404.                             <h4>{{Product.name}}</h4>
  405.                         </div>
  406.                     {% endfor %}
  407.                     </div>
  408.                 </div>
  409.             {# まず、Category.id==2の商品だけ別に集める #}
  410.             {% set CategoryProducts = [] %}
  411.             {% for Product in Products %}
  412.                 {% for ProductCategory in Product.ProductCategories %}
  413.                     {% if ProductCategory.Category.id == 2 %}
  414.                         {% set CategoryProducts = CategoryProducts|merge([Product]) %}
  415.                     {% endif %}
  416.                 {% endfor %}
  417.             {% endfor %}
  418.             {# その上でランダムシャッフルして5件だけ抜く #}
  419.             {% set randomProducts = [] %}
  420.             {% set workingProducts = CategoryProducts %}
  421.                 {% for i in 0..4 %}
  422.                     {% if workingProducts|length > 0 %}
  423.                         {% set randomIndex = random(workingProducts|keys) %}
  424.                         {% set randomProduct = workingProducts[randomIndex] %}
  425.                         {% set randomProducts = randomProducts|merge([randomProduct]) %}
  426.                         {# 選んだやつをworkingProductsから除外する #}
  427.                         {% set workingProducts = workingProducts|filter(p => p != randomProduct) %}
  428.                     {% endif %}
  429.                 {% endfor %}
  430.                 <!-- バス   -->
  431.                 <div class="sub-cont">
  432.                     <div class="con-title">
  433.                         <h3>バス</h3>
  434.                         <a href="{{ url('product_list') }}?category_id=2" class="list-link">
  435.                             <span class="list-btn">一覧はコチラ</span>
  436.                             <span class="btn-l">→</span>
  437.                         </a>
  438.                     </div>
  439.                     <div class="zone">
  440.                     {% for Product in randomProducts %}
  441.                         <div class="card-3">
  442.                             <a href="{{ url('product_detail', {'id': Product.id}) }}">
  443.                                 <img src="{{asset(Product.main_list_image|no_image_product, 'save_image') }}" class="" alt="コンテンツ1"/>
  444.                             </a>
  445.                             <h4>{{Product.name}}</h4>
  446.                         </div>
  447.                     {% endfor %}
  448.                     </div>
  449.                 </div>
  450.                 <!-- 古地図・歴史散歩(地域) -->
  451.                 <div class="sub-cont">
  452.                     <div class="con-title">
  453.                         <h3>古地図・歴史散歩(地域)</h3>
  454.                         <a href="" class="list-link">
  455.                             <span class="list-btn">一覧はコチラ</span>
  456.                             <span class="btn-l">→</span>
  457.                         </a>
  458.                     </div>
  459.                     {# まず、Category.id==5の商品だけ別に集める #}
  460.                     {% set CategoryProducts = [] %}
  461.                     {% for Product in Products %}
  462.                         {% for ProductCategory in Product.ProductCategories %}
  463.                             {% if ProductCategory.Category.id == 5 %}
  464.                                 {% set CategoryProducts = CategoryProducts|merge([Product]) %}
  465.                             {% endif %}
  466.                         {% endfor %}
  467.                     {% endfor %}
  468.                     {# その上でランダムシャッフルして5件だけ抜く #}
  469.                     {% set randomProducts = [] %}
  470.                     {% set workingProducts = CategoryProducts %}
  471.                         {% for i in 0..4 %}
  472.                             {% if workingProducts|length > 0 %}
  473.                                 {% set randomIndex = random(workingProducts|keys) %}
  474.                                 {% set randomProduct = workingProducts[randomIndex] %}
  475.                                 {% set randomProducts = randomProducts|merge([randomProduct]) %}
  476.                                 {# 選んだやつをworkingProductsから除外する #}
  477.                                 {% set workingProducts = workingProducts|filter(p => p != randomProduct) %}
  478.                             {% endif %}
  479.                         {% endfor %}
  480.                     <div class="zone">
  481.                     {% for Product in randomProducts %}
  482.                         <div class="card-3">
  483.                             <a href="{{ url('product_detail', {'id': Product.id}) }}">
  484.                                 <img src="{{asset(Product.main_list_image|no_image_product, 'save_image') }}" class="" alt="コンテンツ1"/>
  485.                             </a>
  486.                             <h4>{{Product.name}}</h4>
  487.                         </div>
  488.                     {% endfor %}
  489.                     </div>
  490.                 </div>
  491.                 <!-- その他 -->
  492.                 <div class="sub-cont">
  493.                     <div class="con-title">
  494.                         <h3>その他</h3>
  495.                         <a href="" class="list-link">
  496.                             <span class="list-btn">一覧はコチラ</span>
  497.                             <span class="btn-l">→</span>
  498.                         </a>
  499.                     </div>
  500.                     {# まず、Category.id==7の商品だけ別に集める #}
  501.                     {% set CategoryProducts = [] %}
  502.                     {% for Product in Products %}
  503.                         {% for ProductCategory in Product.ProductCategories %}
  504.                             {% if ProductCategory.Category.id == 7 %}
  505.                                 {% set CategoryProducts = CategoryProducts|merge([Product]) %}
  506.                             {% endif %}
  507.                         {% endfor %}
  508.                     {% endfor %}
  509.                     {# その上でランダムシャッフルして5件だけ抜く #}
  510.                     {% set randomProducts = [] %}
  511.                     {% set workingProducts = CategoryProducts %}
  512.                         {% for i in 0..4 %}
  513.                             {% if workingProducts|length > 0 %}
  514.                                 {% set randomIndex = random(workingProducts|keys) %}
  515.                                 {% set randomProduct = workingProducts[randomIndex] %}
  516.                                 {% set randomProducts = randomProducts|merge([randomProduct]) %}
  517.                                 {# 選んだやつをworkingProductsから除外する #}
  518.                                 {% set workingProducts = workingProducts|filter(p => p != randomProduct) %}
  519.                             {% endif %}
  520.                         {% endfor %}
  521.                     <div class="zone">
  522.                     {% for Product in randomProducts %}
  523.                         <div class="card-3">
  524.                             <a href="{{ url('product_detail', {'id': Product.id}) }}">
  525.                                 <img src="{{asset(Product.main_list_image|no_image_product, 'save_image') }}" class="" alt="コンテンツ1"/>
  526.                             </a>
  527.                             <h4>{{Product.name}}</h4>
  528.                         </div>
  529.                     {% endfor %}
  530.                 </div>
  531.             </div>
  532.         </section>
  533.     </main>
  534. {% endblock %}