src/Modules/VoucherCart/Controller/VoucherController.php line 56
<?phpnamespace App\Modules\VoucherCart\Controller;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpFoundation\Response;use App\Modules\VoucherCart\Service\VoucherService;use App\Modules\VoucherCart\Service\PredefinedVoucherService;use App\Modules\VoucherCart\Service\CartService;use App\Modules\VoucherCart\Form\VoucherType;class VoucherController extends BaseController{private $_voucherService;private $_predefinedVoucherService;private $_cartService;public function __construct(VoucherService $voucherService,PredefinedVoucherService $predefinedVoucherService,CartService $cartService){$this->_voucherService = $voucherService;$this->_predefinedVoucherService = $predefinedVoucherService;$this->_cartService = $cartService;}public function config(Request $request){$voucherSettingsData = $this->_voucherService->getVoucherSettingsData(false);if ($voucherSettingsData){$form = $this->createForm(VoucherType::class);$form->handleRequest($request);if ($form->isSubmitted()){if ($form->isValid()){if ($this->_cartService->addVoucher($form, $errorMessage))return $this->redirectToRoute('voucher_cart_voucher_config');else$this->addFlash('error', $errorMessage);}}}return $this->render('Modules/VoucherCart/Templates/Voucher/config.html.twig', ['formType' => isset($form) ? $form->getConfig()->getType()->getInnerType() : null,'form' => isset($form) ? $form->createView() : null,'cartEmpty' => $this->_cartService->isEmpty()]);}public function predefinedVouchersWidget(){$vouchers = array();foreach($this->_predefinedVoucherService->getVouchers() as $voucher)$vouchers[] = $this->_predefinedVoucherService->getDetails($voucher['id']);if (!$vouchers)return new Response();return $this->render('Modules/VoucherCart/Templates/Voucher/partials/predefinedVouchersWidget.html.twig', ['vouchers' => $vouchers]);}}