app/Plugin/CouponPro42/Controller/Product/ProductCouponController.php line 51

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the CouponPro42 Plugin
  4.  *
  5.  * Copyright (C) 2022 Diezon.
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Plugin\CouponPro42\Controller\Product;
  11. use Eccube\Controller\AbstractController;
  12. use Eccube\Repository\ProductRepository;
  13. use Plugin\CouponPro42\Repository\CouponRepository;
  14. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  15. use Symfony\Component\HttpFoundation\Request;
  16. use Symfony\Component\Routing\Annotation\Route;
  17. class ProductCouponController extends AbstractController
  18. {
  19.     /**
  20.      * @var ProductRepository
  21.      */
  22.     protected $productRepository;
  23.     /**
  24.      * @var CouponRepository
  25.      */
  26.     protected $couponRepository;
  27.     /**
  28.      * ProductController constructor.
  29.      * @param CouponRepository $couponRepository
  30.      * @param ProductRepository $productRepository
  31.      */
  32.     public function __construct(
  33.         CouponRepository $couponRepository,
  34.         ProductRepository $productRepository
  35.     )
  36.     {
  37.         $this->couponRepository $couponRepository;
  38.         $this->productRepository $productRepository;
  39.     }
  40.     /**
  41.      * @Route("/products/detail/{id}/coupons", name="product_detail_coupons", requirements={"id" = "\d+"})
  42.      * @Template("@CouponPro42/front/Product/coupon_list.twig")
  43.      */
  44.     public function detail(Request $request$id null)
  45.     {
  46.         /** Eccube\Entity\Product $Product */
  47.         $Product $this->productRepository->find($id);
  48.         /** Customer|null $Customer */
  49.         $Customer $this->getUser();
  50.         /** Coupon $Coupon */
  51.         $Coupons $this->couponRepository->getCouponsByProduct($Product$Customer);
  52.         return [
  53.             'Coupons' => $Coupons,
  54.         ];
  55.     }
  56. }