app/Plugin/RefineAdminProductFavorite/Event.php line 29

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of Refine
  4.  *
  5.  * Copyright(c) 2022 Refine Co.,Ltd. All Rights Reserved.
  6.  *
  7.  * https://www.re-fine.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Plugin\RefineAdminProductFavorite;
  13. use Eccube\Entity\Product;
  14. use Eccube\Event\TemplateEvent;
  15. use Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination;
  16. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  17. class Event implements EventSubscriberInterface
  18. {
  19.     public static function getSubscribedEvents()
  20.     {
  21.         return [
  22.             '@admin/Product/index.twig' => 'productList',
  23.         ];
  24.     }
  25.     public function productList(TemplateEvent $event)
  26.     {
  27.         /** @var  $Pagination SlidingPagination */
  28.         $Pagination $event->getParameter('pagination');
  29.         /** @var $Products Product[] */
  30.         $Products $Pagination->getItems();
  31.         // product_idとお気に入り数の配列を作成する
  32.         $favoriteCountList = [];
  33.         foreach ($Products as $product) {
  34.             $favoriteCountList[$product->getId()] = $product->getCustomerFavoriteProductCount();
  35.         }
  36.         $twig '@RefineAdminProductFavorite/admin/product_list.twig';
  37.         $event->setParameter('favoriteCountList'$favoriteCountList);
  38.         $event->addSnippet($twig);
  39.     }
  40. }