Sylius\Bundle\PromotionBundle\Controller\PromotionCouponController::generateAction PHP Method

generateAction() public method

public generateAction ( Request $request ) : Response
$request Symfony\Component\HttpFoundation\Request
return Symfony\Component\HttpFoundation\Response
    public function generateAction(Request $request)
    {
        $configuration = $this->requestConfigurationFactory->create($this->metadata, $request);
        if (null === ($promotionId = $request->attributes->get('promotionId'))) {
            throw new NotFoundHttpException('No promotion id given.');
        }
        if (null === ($promotion = $this->container->get('sylius.repository.promotion')->find($promotionId))) {
            throw new NotFoundHttpException('Promotion not found.');
        }
        $form = $this->container->get('form.factory')->create(PromotionCouponGeneratorInstructionType::class);
        if ($form->handleRequest($request)->isValid()) {
            $this->getGenerator()->generate($promotion, $form->getData());
            $this->flashHelper->addSuccessFlash($configuration, 'generate');
            return $this->redirectHandler->redirectToResource($configuration, $promotion);
        }
        if (!$configuration->isHtmlRequest()) {
            return $this->viewHandler->handle($configuration, View::create($form));
        }
        $view = View::create()->setTemplate($configuration->getTemplate('generate.html'))->setData(['configuration' => $configuration, 'metadata' => $this->metadata, 'promotion' => $promotion, 'form' => $form->createView()]);
        return $this->viewHandler->handle($configuration, $view);
    }
PromotionCouponController