src/Controller/Front/AfterSalesController.php line 44

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front;
  3. use App\Controller\Core\BaseFrontController;
  4. use App\Entity\FormAfterSales;
  5. use App\Form\Front\FormAfterSalesType;
  6. use App\Manager\AfterSalesManager;
  7. use App\Manager\AfterSalesServicesManager;
  8. use App\Manager\AfterSalesSparePartsManager;
  9. use App\Manager\FormAfterSalesManager;
  10. use App\Service\CRM\ApiCRM;
  11. use App\Service\Mail\AfterSalesMail;
  12. use App\Service\Recaptcha\Validator as RecaptchaValidator;
  13. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  14. use Symfony\Component\HttpFoundation\RedirectResponse;
  15. use Symfony\Component\HttpFoundation\Request;
  16. use Symfony\Component\Routing\Annotation\Route;
  17. class AfterSalesController extends BaseFrontController
  18. {
  19.     const FORM_AFTER_SALES 'sd_form_after_sales_entity';
  20.     /**
  21.      * @Route("/postventa", name="after_sales")
  22.      * @Template("front/after_sales/after_sales.html.twig")
  23.      */
  24.     public function afterSales(
  25.         AfterSalesManager $afterSalesManager,
  26.         AfterSalesSparePartsManager $afterSalesSparePartsManager,
  27.         AfterSalesServicesManager $afterSalesServicesManager
  28.     ): array
  29.     {
  30.         $this->locals['spareParts'] = $afterSalesSparePartsManager->find(1);
  31.         $this->locals['services'] = $afterSalesServicesManager->find(1);
  32.         $this->locals['sd'] = $afterSalesManager->find(1);
  33.         return $this->locals;
  34.     }
  35.     /**
  36.      * @Route("/repuestos", name="spare_parts", methods={"GET"})
  37.      * @Template("front/after_sales/spare_parts.html.twig")
  38.      */
  39.     public function spareParts(AfterSalesSparePartsManager $afterSalesSparePartsManager): array
  40.     {
  41.         $entity $this->getFormSession(self::FORM_AFTER_SALES, new FormAfterSales());
  42.         $form $this->getFormView(FormAfterSalesType::class, $entity'spare_parts_action');
  43.         $this->locals['sd'] = $afterSalesSparePartsManager->find(1);
  44.         $this->locals['form'] = $form;
  45.         return $this->locals;
  46.     }
  47.     /**
  48.      * @Route("/repuestos", name="spare_parts_action", methods={"POST"})
  49.      */
  50.     public function sparePartsAction(Request $requestFormAfterSalesManager $managerAfterSalesMail $mailApiCRM $apiCRMRecaptchaValidator $recaptchaValidator): RedirectResponse
  51.     {
  52.         $entity = new FormAfterSales();
  53.         $form $this->getForm(FormAfterSalesType::class, $entity'spare_parts_action');
  54.         $form->handleRequest($request);
  55.         if ($form->isValid() and $recaptchaValidator->validate($this->getRecaptchaToken(), $this->getClientIp())) {
  56.             $manager->save($entity);
  57.             $mail->load($entity)->send();
  58.             $crmLead $entity->leadToCRM();
  59.             $result $apiCRM->send($crmLead);
  60.             $entity->setCrmBody($crmLead->toCRM());
  61.             $entity->setCrmResult($result);
  62.             $manager->save($entity);
  63.             return $this->redirectToRoute('thanks_slug', ['slug' => 'post-venta']);
  64.         }
  65.         $this->saveFormSession(self::FORM_AFTER_SALES$entity);
  66.         return $this->redirectToRoute('spare_parts_action');
  67.     }
  68. }