<?php
/*
* This file is part of the CouponPro42 Plugin
*
* Copyright (C) 2022 Diezon.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Plugin\CouponPro42\Controller\Product;
use Eccube\Controller\AbstractController;
use Eccube\Repository\ProductRepository;
use Plugin\CouponPro42\Repository\CouponRepository;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
class ProductCouponController extends AbstractController
{
/**
* @var ProductRepository
*/
protected $productRepository;
/**
* @var CouponRepository
*/
protected $couponRepository;
/**
* ProductController constructor.
* @param CouponRepository $couponRepository
* @param ProductRepository $productRepository
*/
public function __construct(
CouponRepository $couponRepository,
ProductRepository $productRepository
)
{
$this->couponRepository = $couponRepository;
$this->productRepository = $productRepository;
}
/**
* @Route("/products/detail/{id}/coupons", name="product_detail_coupons", requirements={"id" = "\d+"})
* @Template("@CouponPro42/front/Product/coupon_list.twig")
*/
public function detail(Request $request, $id = null)
{
/** Eccube\Entity\Product $Product */
$Product = $this->productRepository->find($id);
/** Customer|null $Customer */
$Customer = $this->getUser();
/** Coupon $Coupon */
$Coupons = $this->couponRepository->getCouponsByProduct($Product, $Customer);
return [
'Coupons' => $Coupons,
];
}
}