src/AppBundle/Controller/ContentController.php line 30

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 AppBundle\Controller;
  15. use AppBundle\Form\CarSubmitFormType;
  16. use AppBundle\Model\Product\Car;
  17. use AppBundle\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 Symfony\Component\HttpFoundation\Request;
  25. use Symfony\Component\HttpFoundation\Response;
  26. class ContentController extends BaseController
  27. {
  28.     public function defaultAction()
  29.     {
  30.     }
  31.     /**
  32.      * The annotations below demonstrate the ResponseHeader annotation which can be
  33.      * used to set custom response headers on the auto-rendered response. At this point, the headers
  34.      * are not really set as we don't have a response yet, but they will be added to the final response
  35.      * by the ResponseHeaderListener.
  36.      *
  37.      * @ResponseHeader("X-Custom-Header", values={"Foo", "Bar"})
  38.      * @ResponseHeader("X-Custom-Header2", values="Bazinga", replace=true)
  39.      *
  40.      * @return array
  41.      */
  42.     public function portalAction()
  43.     {
  44.         // you can also set the header via code
  45.         $this->addResponseHeader('X-Custom-Header3', ['foo''bar']);
  46.         return [
  47.             'isPortal' => true
  48.         ];
  49.     }
  50.     public function editableRoundupAction()
  51.     {
  52.     }
  53.     public function thumbnailsAction()
  54.     {
  55.     }
  56.     public function carSubmitAction(Request $requestTranslator $translator)
  57.     {
  58.         $form $this->createForm(CarSubmitFormType::class);
  59.         $form->handleRequest($request);
  60.         if ($form->isSubmitted() && $form->isValid()) {
  61.             $formData $form->getData();
  62.             $car = new Car();
  63.             $car->setParent(Service::createFolderByPath('/upload/new'));
  64.             $car->setKey(Text::toUrl($formData['name'] . '-' time()));
  65.             $car->setName($formData['name']);
  66.             $car->setDescription($formData['description']);
  67.             $car->setManufacturer(Manufacturer::getById($formData['manufacturer']));
  68.             $car->setBodyStyle(BodyStyle::getById($formData['bodyStyle']));
  69.             $car->setCarClass($formData['carClass']);
  70.             $car->save();
  71.             $this->addFlash('success'$translator->trans('general.car-submitted'));
  72.             return $this->renderTemplate('content/car_submit_success.html.twig'array_merge($this->view->getAllParameters(), ['car' => $car]));
  73.         }
  74.         return [
  75.             'form' => $form->createView()
  76.         ];
  77.     }
  78.     public function tenantSwitchesAction(Request $requestFactory $ecommerceFactory)
  79.     {
  80.         $environment $ecommerceFactory->getEnvironment();
  81.         if ($request->get('change-checkout-tenant')) {
  82.             $checkoutTenant $request->get('change-checkout-tenant');
  83.             $checkoutTenant $checkoutTenant == 'default' '' $checkoutTenant;
  84.             $environment->setCurrentCheckoutTenant(strip_tags($checkoutTenant));
  85.             $environment->save();
  86.         }
  87.         if ($request->get('change-assortment-tenant')) {
  88.             $assortmentTenant $request->get('change-assortment-tenant');
  89.             $assortmentTenant $assortmentTenant == 'default' '' $assortmentTenant;
  90.             $environment->setCurrentAssortmentTenant(strip_tags($assortmentTenant));
  91.             $environment->save();
  92.         }
  93.         $paramsBag['checkoutTenants'] = ['default' => ''];
  94.         $paramsBag['currentCheckoutTenant'] = $environment->getCurrentCheckoutTenant() ? $environment->getCurrentCheckoutTenant() : 'default';
  95.         $paramsBag['assortmentTenants'] = ['default' => '''ElasticSearch' => 'needs to be configured and activated in configuration'];
  96.         $paramsBag['currentAssortmentTenant'] = $environment->getCurrentAssortmentTenant() ? $environment->getCurrentAssortmentTenant() : 'default';
  97.         return $paramsBag;
  98.     }
  99. }