app/Plugin/NZCategoryLayoutManager42/EventSubscriber/TemplateEventSubscriber.php line 26

Open in your IDE?
  1. <?php
  2. namespace Plugin\NZCategoryLayoutManager42\EventSubscriber;
  3. use Eccube\Event\TemplateEvent;
  4. use Plugin\NZCategoryLayoutManager42\Repository\CategoryLayoutRepository;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpFoundation\RequestStack;
  7. class TemplateEventSubscriber implements EventSubscriberInterface
  8. {
  9.     private $categoryLayoutRepository;
  10.     private $requestStack;
  11.     public function __construct(CategoryLayoutRepository $categoryLayoutRepositoryRequestStack $requestStack)
  12.     {
  13.         $this->categoryLayoutRepository $categoryLayoutRepository;
  14.         $this->requestStack $requestStack;
  15.     }
  16.     public static function getSubscribedEvents()
  17.     {
  18.         return ['Product/list.twig' => 'onProductList'];
  19.     }
  20.     public function onProductList(TemplateEvent $event)
  21.     {
  22.         $request $this->requestStack->getCurrentRequest();
  23.         if (!$request) return;
  24.         $categoryId $request->query->get('category_id');
  25.         if (!$categoryId) return;
  26.         $layout $this->categoryLayoutRepository->findByParentCategoryId($categoryId);
  27.         if (!$layout) return;
  28.         $gameCategories = [];
  29.         foreach ($layout->getCategoryLayoutItems() as $item) {
  30.             $gameCategories[] = ['id' => $item->getChildCategoryId(), 'name' => $item->getDisplayName(), 'icon' => $item->getIconPath()];
  31.         }
  32.         $gameCategoriesJson json_encode($gameCategoriesJSON_UNESCAPED_UNICODE);
  33.         $event->addSnippet('<style>.game-category-parent-layout{width:100%;padding:20px 0}.game-section{margin-bottom:60px;padding-bottom:40px;border-bottom:2px solid #e0e0e0}.game-section:last-child{border-bottom:none}.game-section-title{font-size:1.8rem;margin-bottom:20px;padding-left:10px;border-left:5px solid #333}.game-section-title a{color:#333;text-decoration:none}.game-section-title a:hover{color:#007bff}.game-section-layout{display:flex!important;gap:20px;align-items:flex-start}.game-icon-section{flex:0 0 240px!important;width:240px!important;display:block;position:relative;transition:all .3s;border-radius:12px;overflow:hidden;box-shadow:0 8px 20px rgba(0,0,0,.2)}.game-icon-section:hover{transform:translateY(-8px) scale(1.02);box-shadow:0 12px 30px rgba(0,0,0,.3)}.game-icon-section::before{content:"";position:absolute;top:-50%;left:-50%;width:200%;height:200%;background:linear-gradient(45deg,transparent,rgba(255,255,255,.3),transparent);transform:rotate(45deg);animation:shine 3s infinite}@keyframes shine{0%{left:-50%}50%,100%{left:150%}}.game-icon-image{width:100%!important;height:auto!important;display:block!important;border-radius:12px!important}.game-products-section{flex:1!important;min-width:0!important;overflow:visible!important}.game-products-slider{position:relative;width:100%}.game-products-slider .slick-list{overflow:hidden!important;margin:0 50px}.game-products-slider .slick-track{display:flex!important}.game-products-slider .slick-slide{height:auto!important;float:none!important;margin:0 10px}.game-products-slider .slick-prev,.game-products-slider .slick-next{width:50px!important;height:50px!important;background:rgba(0,0,0,.7)!important;border-radius:50%!important;z-index:10!important;border:2px solid white!important;box-shadow:0 2px 8px rgba(0,0,0,.3)!important}.game-products-slider .slick-prev:hover,.game-products-slider .slick-next:hover{background:rgba(0,0,0,.9)!important}.game-products-slider .slick-prev{left:0!important}.game-products-slider .slick-next{right:0!important}.game-products-slider .slick-prev img,.game-products-slider .slick-next img{width:24px!important;height:24px!important;filter:brightness(0) invert(1)}.game-products-slider .slick-prev:before,.game-products-slider .slick-next:before{content:""!important}.game-products-slider .slick-disabled{opacity:.3!important}.game-products-slider .slick-dots{display:none!important}.no-products{text-align:center;padding:60px 20px;color:#999}@media(max-width:768px){.game-section-layout{gap:15px}.game-icon-section{flex:0 0 120px!important;width:120px!important}.game-products-slider .slick-prev,.game-products-slider .slick-next{display:none!important}.game-products-slider .slick-list{margin:0}.game-products-section{position:relative}.game-products-section::after{content:"››";position:absolute;right:5px;top:50%;transform:translateY(-50%);font-size:80px;font-weight:bold;color:rgba(0,0,0,.6);pointer-events:none;z-index:5;text-shadow:-3px 0 5px rgba(255,255,255,.9),3px 0 5px rgba(255,255,255,.9);animation:slideHint 1.2s ease-in-out infinite}@keyframes slideHint{0%,100%{opacity:.4;right:5px}50%{opacity:.9;right:10px}}.game-products-section.no-more-slides::after{display:none!important}.game-section-title{font-size:1.4rem}}@media(max-width:480px){.game-icon-section{flex:0 0 100px!important;width:100px!important}.game-products-section::after{font-size:50px}}</style>');
  34.         
  35.         $event->addSnippet('<script>(function(){if(typeof eccube==="undefined"||!eccube.productsClassCategories)return;var currentCategoryId='.$categoryId.';var urlParams=new URLSearchParams(window.location.search);var pageCategoryId=parseInt(urlParams.get("category_id"));if(pageCategoryId!==currentCategoryId)return;console.log("=== Game category layout: Started ===");var gameCategories='.$gameCategoriesJson.';var $shelfGrid=$(".ec-shelfGrid");var $items=$shelfGrid.find(".ec-shelfGrid__item");if($items.length===0){console.warn("No products found");return}var productsByCategory={};$items.each(function(){var $item=$(this);var categoryIds=$item.attr("data-category-ids");if(!categoryIds)return;var categories=categoryIds.split(",").map(function(id){return parseInt(id.trim())});gameCategories.forEach(function(game){if(categories.indexOf(game.id)!==-1){if(!productsByCategory[game.id]){productsByCategory[game.id]=[]}productsByCategory[game.id].push($item.clone())}})});var $newLayout=$("<div class=\"game-category-parent-layout\"></div>");gameCategories.forEach(function(game){var products=productsByCategory[game.id]||[];var $section=$("<div class=\"game-section\"></div>");var $title=$("<h2 class=\"game-section-title\"><a href=\"?category_id="+game.id+"\">"+game.name+" 推奨PC</a></h2>");var $layout=$("<div class=\"game-section-layout\"></div>");var $iconSection=$("<a href=\"?category_id="+game.id+"\" class=\"game-icon-section\"><img src=\""+game.icon+"\" alt=\""+game.name+"\" class=\"game-icon-image\"></a>");var $productsSection=$("<div class=\"game-products-section\"></div>");var $slider=$("<div class=\"game-products-slider slider-"+game.id+"\"></div>");if(products.length>0){products.forEach(function($product){$slider.append($product)})}else{$slider.html("<div class=\"no-products\"><p>商品準備中です</p></div>")}$productsSection.append($slider);$layout.append($iconSection);$layout.append($productsSection);$section.append($title);$section.append($layout);$newLayout.append($section)});$shelfGrid.replaceWith($newLayout);setTimeout(function(){gameCategories.forEach(function(game){var $sliderElement=$(".slider-"+game.id);var itemCount=$sliderElement.find(".ec-shelfGrid__item").length;if(itemCount>0){if($sliderElement.hasClass("slick-initialized")){$sliderElement.slick("unslick")}$sliderElement.slick({slidesToShow:4,slidesToScroll:1,infinite:false,arrows:true,dots:false,prevArrow:"<button type=\"button\" class=\"slick-prev\"><img src=\"/html/template/bynoiezam/assets/icon/slick-arrow-left-white.svg\" alt=\"前へ\" /></button>",nextArrow:"<button type=\"button\" class=\"slick-next\"><img src=\"/html/template/bynoiezam/assets/icon/slick-arrow-right-white.svg\" alt=\"次へ\" /></button>",responsive:[{breakpoint:1200,settings:{slidesToShow:3}},{breakpoint:768,settings:{slidesToShow:1,arrows:false}},{breakpoint:480,settings:{slidesToShow:1,arrows:false}}]});if($(window).width()<=768){$sliderElement.on("afterChange",function(event,slick,currentSlide){var isLast=(currentSlide>=slick.slideCount-1);$(this).closest(".game-products-section").toggleClass("no-more-slides",isLast)})}}})},300);console.log("=== Game category layout: Complete ===")})();</script>');
  36.     }
  37. }