src/Controller/ContentController.php line 40

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 Pimcore\Model\DataObject;
  17. use App\Model\Product\Car;
  18. use App\Website\Tool\Text;
  19. use Pimcore\Bundle\EcommerceFrameworkBundle\Factory;
  20. use Pimcore\Bundle\EcommerceFrameworkBundle\IndexService\ProductList\ProductListInterface;
  21. use Pimcore\Controller\Configuration\ResponseHeader;
  22. use Pimcore\Model\DataObject\BodyStyle;
  23. use Pimcore\Model\DataObject\Manufacturer;
  24. use Pimcore\Model\DataObject\Service;
  25. use Pimcore\Translation\Translator;
  26. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  27. use Symfony\Component\HttpFoundation\Request;
  28. use Symfony\Component\HttpFoundation\Response;
  29. use CustomerManagementFrameworkBundle\Security\SsoIdentity\SsoIdentityServiceInterface;
  30. use Symfony\Component\Security\Core\User\UserInterface;
  31. class ContentController extends BaseController
  32. {
  33.     /**
  34.      * @Template
  35.      */
  36.     public function defaultAction()
  37.     {
  38.         return [];
  39.     }
  40.     
  41.     /**
  42.      * The annotations below demonstrate the ResponseHeader annotation which can be
  43.      * used to set custom response headers on the auto-rendered response. At this point, the headers
  44.      * are not really set as we don't have a response yet, but they will be added to the final response
  45.      * by the ResponseHeaderListener.
  46.      *
  47.      * @ResponseHeader("X-Custom-Header", values={"Foo", "Bar"})
  48.      * @ResponseHeader("X-Custom-Header2", values="Bazinga", replace=true)
  49.      *
  50.      * @return Response
  51.      */
  52.     public function portalAction(UserInterface $user null,Factory $ecommerceFactory,Request $request)
  53.     {   
  54.             
  55.         if(!$user instanceof \App\Model\Customer)
  56.         {
  57.             return $this->redirectToRoute('account-login');
  58.         }
  59.         $categories = new DataObject\Category\Listing();
  60.         $cartManager $ecommerceFactory->getCartManager();
  61.         $cart $cartManager->getOrCreateCartByName('cart');           
  62.         // you can also set the header via code
  63.         $this->addResponseHeader('X-Custom-Header3', ['foo''bar']);
  64.         $indexService $ecommerceFactory->getIndexService();
  65.         $productListing $indexService->getProductListForCurrentTenant();
  66.         //
  67.         $productListing->setLimit(5);
  68.         $products $productListing->load();  
  69.         $newsDocuments$this->getDocumentsAndNews();
  70.         $news $newsDocuments['news'];
  71.         $documents $newsDocuments['documents'];
  72.         $aggiornamentoPrezziListing = new DataObject\AggiornamentoPrezzi\Listing();
  73.         $aggiornamentoPrezziListing->setOrderKey('o_id');
  74.         $aggiornamentoPrezziListing->setOrder('DESC');
  75.         $aggiornamentoPrezziListing->setLimit(2);
  76.         $aggiornamentoPrezzi $aggiornamentoPrezziListing->load();
  77.         
  78.        //p_r(get_class_methods($cart));exit;
  79.      //  $this->view->totalCount = $cart->getItemAmount();
  80.         return $this->render('content/portal.html.twig', [
  81.             'isPortal' => true,
  82.             'products'=>$products,
  83.             'totalCount'=>$cart->getItemAmount(),
  84.             'categories'=>$categories,
  85.             'news'=>$news,
  86.             'documents'=>$documents,
  87.             'aggiornamentoprezzi'=>$aggiornamentoPrezzi
  88.         ]);
  89.     }
  90.     /**
  91.      * @return Response
  92.      */
  93.     public function editableRoundupAction()
  94.     {
  95.         return $this->render('content/editable_roundup.html.twig');
  96.     }
  97.     /**
  98.      * @return Response
  99.      */
  100.     public function thumbnailsAction()
  101.     {
  102.         return $this->render('content/thumbnails.html.twig');
  103.     }
  104.     /**
  105.      * @param Request $request
  106.      * @param Translator $translator
  107.      *
  108.      * @return Response
  109.      *
  110.      * @throws \Exception
  111.      */
  112.     public function carSubmitAction(Request $requestTranslator $translator)
  113.     {
  114.         $form $this->createForm(CarSubmitFormType::class);
  115.         $form->handleRequest($request);
  116.         if ($form->isSubmitted() && $form->isValid()) {
  117.             $formData $form->getData();
  118.             $car = new Car();
  119.             $car->setParent(Service::createFolderByPath('/upload/new'));
  120.             $car->setKey(Text::toUrl($formData['name'] . '-' time()));
  121.             $car->setName($formData['name']);
  122.             $car->setDescription($formData['description']);
  123.             $car->setManufacturer(Manufacturer::getById($formData['manufacturer']));
  124.             $car->setBodyStyle(BodyStyle::getById($formData['bodyStyle']));
  125.             $car->setCarClass($formData['carClass']);
  126.             $car->save();
  127.             $this->addFlash('success'$translator->trans('general.car-submitted'));
  128.             return $this->render('content/car_submit_success.html.twig', ['car' => $car]);
  129.         }
  130.         return $this->render('content/car_submit.html.twig', [
  131.             'form' => $form->createView()
  132.         ]);
  133.     }
  134.     /**
  135.      * @param Request $request
  136.      * @param Factory $ecommerceFactory
  137.      *
  138.      * @return Response
  139.      */
  140.     public function tenantSwitchesAction(Request $requestFactory $ecommerceFactory)
  141.     {
  142.         $environment $ecommerceFactory->getEnvironment();
  143.         if ($request->get('change-checkout-tenant')) {
  144.             $checkoutTenant $request->get('change-checkout-tenant');
  145.             $checkoutTenant $checkoutTenant == 'default' '' $checkoutTenant;
  146.             $environment->setCurrentCheckoutTenant(strip_tags($checkoutTenant));
  147.             $environment->save();
  148.         }
  149.         if ($request->get('change-assortment-tenant')) {
  150.             $assortmentTenant $request->get('change-assortment-tenant');
  151.             $assortmentTenant $assortmentTenant == 'default' '' $assortmentTenant;
  152.             $environment->setCurrentAssortmentTenant(strip_tags($assortmentTenant));
  153.             $environment->save();
  154.         }
  155.         $paramsBag['checkoutTenants'] = ['default' => ''];
  156.         $paramsBag['currentCheckoutTenant'] = $environment->getCurrentCheckoutTenant() ? $environment->getCurrentCheckoutTenant() : 'default';
  157.         $paramsBag['assortmentTenants'] = ['default' => '''ElasticSearch' => 'needs to be configured and activated in configuration'];
  158.         $paramsBag['currentAssortmentTenant'] = $environment->getCurrentAssortmentTenant() ? $environment->getCurrentAssortmentTenant() : 'default';
  159.         return $this->render('content/tenant_switches.html.twig'$paramsBag);
  160.     }
  161.     private function getDocumentsAndNews(){
  162.         $result = [];
  163.         $files = [];
  164.         $recentDocuments = new \Pimcore\Model\DataObject\Commerciali\Listing();               
  165.         $recentDocuments->setOrderKey('o_id');
  166.         $recentDocuments->setLimit(2);
  167.         $recentDocuments->setOrder('DESC');
  168.         $documents $recentDocuments->load();
  169.         foreach($documents as $doc)
  170.         {
  171.             $docFiles $doc->getDocuments();
  172.             if($docFiles)
  173.             {
  174.                 foreach($docFiles as $file)
  175.                 {
  176.                     $files[] = $file;                    
  177.                     if(count($files) === 5){  
  178.                         $done true;                      
  179.                         break;
  180.                     }
  181.                 }
  182.             }
  183.         }
  184.         $newsObj = new \Pimcore\Model\DataObject\News\Listing();               
  185.         $newsObj->setOrderKey('o_id');
  186.         $newsObj->setLimit(4);
  187.         $newsObj->setOrder('DESC');
  188.         $news $newsObj->load();
  189.         $result = ['documents'=>$files,'news'=>$news];
  190.         return $result;
  191.     }
  192. }