src/Controller/ContentController.php line 112

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Enterprise License (PEL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12.  *  @license    http://www.pimcore.org/license     GPLv3 and PEL
  13.  */
  14. namespace App\Controller;
  15. use App\Form\CarSubmitFormType;
  16. use App\Model\Product\Car;
  17. use App\Website\Tool\Text;
  18. use Pimcore\Bundle\EcommerceFrameworkBundle\Factory;
  19. use Pimcore\Controller\Configuration\ResponseHeader;
  20. use Pimcore\Model\DataObject\BodyStyle;
  21. use Pimcore\Model\DataObject\Manufacturer;
  22. use Pimcore\Model\DataObject\Service;
  23. use Pimcore\Translation\Translator;
  24. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  25. use Symfony\Component\HttpFoundation\Request;
  26. use Symfony\Component\HttpFoundation\Response;
  27. class ContentController extends BaseController
  28. {
  29.     /**
  30.      * @Template
  31.      */
  32.     public function defaultAction()
  33.     {
  34.         return [];
  35.     }
  36.     /**
  37.      * The annotations below demonstrate the ResponseHeader annotation which can be
  38.      * used to set custom response headers on the auto-rendered response. At this point, the headers
  39.      * are not really set as we don't have a response yet, but they will be added to the final response
  40.      * by the ResponseHeaderListener.
  41.      *
  42.      * @ResponseHeader("X-Custom-Header", values={"Foo", "Bar"})
  43.      * @ResponseHeader("X-Custom-Header2", values="Bazinga", replace=true)
  44.      *
  45.      * @return Response
  46.      */
  47.     public function portalAction()
  48.     {
  49.         // you can also set the header via code
  50.         $this->addResponseHeader('X-Custom-Header3', ['foo''bar']);
  51.         return $this->render('content/portal.html.twig', [
  52.             'isPortal' => true
  53.         ]);
  54.     }
  55.     /**
  56.      * @return Response
  57.      */
  58.     public function editableRoundupAction()
  59.     {
  60.         return $this->render('content/editable_roundup.html.twig');
  61.     }
  62.     /**
  63.      * @return Response
  64.      */
  65.     public function thumbnailsAction()
  66.     {
  67.         return $this->render('content/thumbnails.html.twig');
  68.     }
  69.     /**
  70.      * @param Request $request
  71.      * @param Translator $translator
  72.      *
  73.      * @return Response
  74.      *
  75.      * @throws \Exception
  76.      */
  77.     public function carSubmitAction(Request $requestTranslator $translator)
  78.     {
  79.         $form $this->createForm(CarSubmitFormType::class);
  80.         $form->handleRequest($request);
  81.         if ($form->isSubmitted() && $form->isValid()) {
  82.             $formData $form->getData();
  83.             $car = new Car();
  84.             $car->setParent(Service::createFolderByPath('/upload/new'));
  85.             $car->setKey(Text::toUrl($formData['name'] . '-' time()));
  86.             $car->setName($formData['name']);
  87.             $car->setDescription($formData['description']);
  88.             $car->setManufacturer(Manufacturer::getById($formData['manufacturer']));
  89.             $car->setBodyStyle(BodyStyle::getById($formData['bodyStyle']));
  90.             $car->setCarClass($formData['carClass']);
  91.             $car->save();
  92.             $this->addFlash('success'$translator->trans('general.car-submitted'));
  93.             return $this->render('content/car_submit_success.html.twig', ['car' => $car]);
  94.         }
  95.         return $this->render('content/car_submit.html.twig', [
  96.             'form' => $form->createView()
  97.         ]);
  98.     }
  99.     /**
  100.      * @param Request $request
  101.      * @param Factory $ecommerceFactory
  102.      *
  103.      * @return Response
  104.      */
  105.     public function tenantSwitchesAction(Request $requestFactory $ecommerceFactory)
  106.     {
  107.         $environment $ecommerceFactory->getEnvironment();
  108.         if ($request->get('change-checkout-tenant')) {
  109.             $checkoutTenant $request->get('change-checkout-tenant');
  110.             $checkoutTenant $checkoutTenant == 'default' '' $checkoutTenant;
  111.             $environment->setCurrentCheckoutTenant(strip_tags($checkoutTenant));
  112.             $environment->save();
  113.         }
  114.         if ($request->get('change-assortment-tenant')) {
  115.             $assortmentTenant $request->get('change-assortment-tenant');
  116.             $assortmentTenant $assortmentTenant == 'default' '' $assortmentTenant;
  117.             $environment->setCurrentAssortmentTenant(strip_tags($assortmentTenant));
  118.             $environment->save();
  119.         }
  120.         $paramsBag['checkoutTenants'] = ['default' => ''];
  121.         $paramsBag['currentCheckoutTenant'] = $environment->getCurrentCheckoutTenant() ? $environment->getCurrentCheckoutTenant() : 'default';
  122.         $paramsBag['assortmentTenants'] = ['default' => '''ElasticSearch' => 'needs to be configured and activated in configuration'];
  123.         $paramsBag['currentAssortmentTenant'] = $environment->getCurrentAssortmentTenant() ? $environment->getCurrentAssortmentTenant() : 'default';
  124.         return $this->render('content/tenant_switches.html.twig'$paramsBag);
  125.     }
  126. }