src/Controller/ContentController.php line 167

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use ContainerELzgxgm\getGoogleMapService;
  4. use DateTime;
  5. use Exception;
  6. use PhpOffice\PhpSpreadsheet\IOFactory;
  7. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  8. use Pimcore\Config;
  9. use Pimcore\Model\DataObject;
  10. use Pimcore\Controller\FrontendController;
  11. use Pimcore\Model\DataObject\ProductMarca;
  12. use Pimcore\Model\Document;
  13. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  14. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  15. use Symfony\Component\HttpFoundation\Cookie;
  16. use Symfony\Component\HttpFoundation\Request;
  17. use Symfony\Component\HttpFoundation\Response;
  18. use Symfony\Component\HttpFoundation\JsonResponse;
  19. use Symfony\Component\Routing\Annotation\Route;
  20. use App\Service\Product\ProductHelper;
  21. #use App\Ecommerce\Tool\RecentlyViewedProducts;
  22. use App\Model\DefaultProduct;
  23. use App\Model\ShopCategory;
  24. use App\Model\DefaultMarca;
  25. use App\Service\HelperService;
  26. //use OutputDataConfigToolkitBundle\Service;
  27. use Pimcore\Bundle\EcommerceFrameworkBundle\Factory;
  28. use Pimcore\Bundle\EcommerceFrameworkBundle\FilterService\Helper;
  29. use Pimcore\Bundle\EcommerceFrameworkBundle\FilterService\ListHelper;
  30. use Pimcore\Bundle\EcommerceFrameworkBundle\IndexService\ProductList\ProductListInterface;
  31. use Pimcore\Model\DataObject\Product;
  32. use Pimcore\Model\DataObject\ProductCategory;
  33. use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
  34. #use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  35. use Symfony\Component\Security\Core\User\UserInterface;
  36. use Knp\Component\Pager\Pagination\SlidingPagination;
  37. use Knp\Component\Pager\PaginatorInterface;
  38. class ContentController extends FrontendController {
  39.     public function defaultAction(
  40.         Request $request,
  41.         HelperService $helperService,
  42.         Config $config
  43.     ) {
  44.        return $this->render('Shop/ProductDetails/productDetail.html.twig');
  45.         //return new Response("views must be change to twig");
  46.        // $this->checkAccess($request);
  47.        // $this->setCookieTemplate();
  48.         //recuperar la key del systemSettings.
  49.         $apikey $config['services']['google']['browser_api_key'];
  50.         //listar las dos tiendas con el condicional.
  51.         $companies = new DataObject\Company\Listing();
  52.         $companies->setCondition("sede = ?"1);
  53.         $companies->setOrderKey("title");
  54.         //test
  55.         $puntodeventa = new DataObject\Colaborador\Listing();
  56.         $puntodeventa->setOrderKey(["comunidad_autonoma","provincia","ciudad","name"]);
  57.         $puntodeventa->setCondition("ispuntoventa = ?"1);
  58.         $puntodeventa->addConditionParam("showinweb = ?"1"AND");
  59.         $this->view->puntodeventa $puntodeventa;
  60.         $aplicadores = new DataObject\Colaborador\Listing();
  61.         $aplicadores->setOrderKey(["comunidad_autonoma","provincia","ciudad","name"]);
  62.         $aplicadores->setCondition("isaplicador = ?"1);
  63.         $aplicadores->addConditionParam("showinweb = ?"1"AND");
  64.         $this->view->aplicadores $aplicadores;
  65.         $this->view->companies $companies;
  66.         $this->view->apikey $apikey;
  67.         $this->view->unique $helperService->generateUniqueCode();
  68.     }
  69.     public function homeAction(UserInterface $user nullRequest $request){
  70.         $lang $request->getLocale();
  71.         $params = [];
  72.         $ratesDateCookie $request->cookies->get('lastRatesChanges');
  73. //        $eventsDateCookie = json_decode($request->cookies->get('lastEventsChanges'), true) ?? [];
  74.         $filePath __DIR__.'/../../public/var/assets/excel_de_tarifas/temp/changes.xlsx';
  75.         try {
  76.             $spreadsheet IOFactory::load($filePath);
  77.             $sheet $spreadsheet->getActiveSheet();
  78.             $lastRow $sheet->getHighestRow();
  79.             $lastChanges $sheet->getCell('A'.$lastRow);
  80.         } catch (Exception){
  81.             $lastChanges null;
  82.         }
  83. //        $documentName = $lang == 'en' ? '/recent-events' : '/eventos-recientes';
  84. //        $document = Document::getByPath('/'.$lang.$documentName);
  85. //        $modificationDate = $document->getModificationDate();
  86.         if ($user){
  87.             if (isset($ratesDateCookie) && $ratesDateCookie $lastChanges) {
  88.                 $params['modal'] = $lastChanges;
  89.             }
  90. //            if (!is_array($eventsDateCookie)) {
  91. //                $eventsDateCookie = [];
  92. //            }
  93. //
  94. //            if (!isset($eventsDateCookie[$lang])) {
  95. //                $eventsDateCookie[$lang] = null;
  96. //            }
  97. //
  98. //            if($eventsDateCookie[$lang] < $modificationDate ){
  99.                 $params['events'] = true// <- if modal has to appear only when changes are made, change this variable to $modificationDate
  100. //                $eventsDateCookie[$lang] = $modificationDate;
  101. //            }
  102. //
  103. //            $eventCookieData = json_encode($eventsDateCookie);
  104.             $response = new Response();
  105.             $response->headers->setCookie(new Cookie('lastRatesChanges'$lastChangesstrtotime('now + 30 days')));
  106. //            $response->headers->setCookie(new Cookie('lastEventsChanges', $eventCookieData, strtotime('now + 30 days')));
  107.             $response->sendHeaders();
  108.         }
  109.         $params["categories"] = $this->getCategories();
  110.         $params["marcas"] = $this->getMarcas();
  111.         $params["companies"] = $this->getCompanies();
  112.         return $this->render('Default/index.html.twig'$params);
  113.     }
  114.     protected function getCategories(): DataObject\ProductCategory\Listing
  115.     {
  116.         $categories = new DataObject\ProductCategory\Listing();
  117.         $categories->setUnpublished(false);
  118.         $categories->setOrderKey("order");
  119.         $categories->setCondition('o_parentId = ?', [10]);
  120.         $categories->load();
  121.         return $categories;
  122.     }
  123.     protected function getMarcas(): DataObject\ProductMarca\Listing
  124.     {
  125.         $marcas = new DataObject\ProductMarca\Listing();
  126.         $marcas->setUnpublished(false);
  127.         $marcas->setOrderKey("order");
  128.         $marcas->load();
  129.         return $marcas;
  130.     }
  131.     protected function getCompanies(): DataObject\Company\Listing
  132.     {
  133.         $companies = new DataObject\Company\Listing();
  134.         $companies->setOrderKey(["sede","title"]);
  135.         $companies->setOrder(["desc","asc"]);
  136.         $companies->load();
  137.         return $companies;
  138.     }
  139.     public  function aboutUsAction(Request $request){
  140.         return $this->render('Content/aboutUs.html.twig');
  141.     }
  142.     public function footerAction(Request $request){
  143.         return $this->render('include/footer.html.twig');
  144.     }
  145.     public function pointsOfSaleAction(Request $request){
  146.         //getting objects
  147.         $colaboradores = new DataObject\Colaborador\Listing();
  148.         $colaboradores->setCondition("showinweb = ?"1);
  149.         $colaboradores->addConditionParam("showinmap = ?"1"AND");
  150.         $colaboradores->setOrderKey("name");
  151.         $company DataObject\Company::getById(415);
  152.         return $this->render('Content/pointsOfSale.html.twig',[
  153.             'collaborators' => $colaboradores,
  154.             'company'       => $company
  155.         ]);
  156.     }
  157.     public function indrustryProfessionalsAction(Request $request){
  158.         //getting objects
  159.         $professionals = new DataObject\Colaborador\Listing();
  160.         $professionals->addConditionParam("showinweb = ?"1);
  161.         $professionals->addConditionParam("showinmap = ?"1"AND");
  162.         $professionals->setOrderKey("name");
  163.         $brands $professionals->getClass()->getFieldDefinition("brands");
  164.         $specialitazions $professionals->getClass()->getFieldDefinition("specialization");
  165.         $brands $brands->getOptions();
  166.         $specialitazions $specialitazions->getOptions();
  167.         $company DataObject\Company::getById(415);
  168.         return $this->render('Content/industryProfessionals.html.twig',[
  169.             'professionals' => $professionals,
  170.             'company'       => $company,
  171.             'brands'        => $brands,
  172.             'specializations' => $specialitazions
  173.         ]);
  174.     }
  175.     /**
  176.      * @Route("/ajax_professional", name="ajax_professional")
  177.      */
  178.     public function modalProfessionalsAjaxAction(Request $request){
  179.         $id $request->get('data');
  180.         $lang $request->get('lang');
  181.         //getting objects
  182.         $professional DataObject\Colaborador::getById($id);
  183.         $company DataObject\Company::getById(415);
  184.         return $this->render('Content/dataProfessionalsModal.html.twig',
  185.         [
  186.             'professional' => $professional,
  187.             'company'      => $company,
  188.             'lang'         => $lang
  189.         ]);
  190.     }
  191.     /**
  192.     * @Route("/detailCart", name="detailCart")
  193.     * @Security("is_granted('ROLE_USER')")
  194.     */
  195.     public function detailCartAction(Request $request){
  196.         return $this->render('Cart/main-cart.html.twig');
  197.     }
  198.     public function tarifaAction(
  199.         Request $request,
  200.         HelperService $helperService
  201.     ) {
  202.         $pdfFile "BSN";
  203.         /*
  204.         $orgFolder = PIMCORE_PRIVATE_VAR . "/securePDF/" ;
  205.         if (file_exists($orgFolder . $pdfFile )) {
  206.             $copyFolder = PIMCORE_WEB_ROOT . "/static2/pdfjsviewer/tmpPdf/";
  207.             $tmpFileName = uniqid() . ".pdf";
  208.             copy($orgFolder . $pdfFile , $copyFolder . $tmpFileName);
  209.             $this->view->pdf = $tmpFileName;
  210.         }*/
  211.         $params = [];
  212.         $params["unique"] = $helperService->generateUniqueCode();
  213.         $params["pdf"] =  $pdfFile;
  214.         return $this->render('PDF/viewerframe.html.twig'$params);
  215.     }
  216.     #[Route('/tarifaPDF/{pdf}'name'tarifa-pdf-view')]
  217.     public function tarifaPDFAction(
  218.         Request $request,
  219.         $pdf,
  220.         HelperService $helperService
  221.     ) {
  222.         $pdf $pdf.'.pdf';
  223.         $parameters = array(
  224.             //Same parameters as defalt viewer.
  225.             //Tell to the bundle where is the pdf. (absolute path for outside temporal folder pdf, just the <name>.pdf for inside temporal folder)
  226.             'pdf' => $pdf ,
  227.             //Tell to the bundle that its necessary to delete pdf after render.
  228.             'deletePdfInTmpAfterRenderized' => false,
  229.             //pdf.js viewer options
  230.             'showToolBar' => true,
  231.             'showLeftToolbarButton' => true,
  232.             'showSearchInDocumentButton' => true,
  233.             'showPreviousPageButton' => true,
  234.             'showPreviousPageButton' => true,
  235.             'showFindPageInputText' => true,
  236.             'showNumberOfPagesLabel' => true,
  237.             'showZoomInButton'=> true,
  238.             'showZoomOutButton'=> true,
  239.             'showScaleSelectComboBox'=> true,
  240.             'showPresentationModeButton'=> true,
  241.             'showOpenFileButton'=> false,
  242.             'showPrintButton'=> false,
  243.             'showDownloadButton'=> false,
  244.             'showViewBookmarkButton'=> false,
  245.             'showToolsButton'=> true,
  246.         );
  247.   //      $this->view->unique = $helperService->generateUniqueCode();
  248. //        return $this->render('PDF/custom.html.php', $parameters);
  249.         return  $this->render('PDF/custom.html.twig',$parameters);
  250.     }
  251.     /**
  252.      * Pdf system deletion from tmpDir
  253.      *
  254.      * @param string $PdfTmpPath , relative path to the pdf from webroot dir
  255.      * @Route("/deletePDF")
  256.      *
  257.      * @return Response, Error in pdf deletion. If it's ok, this function must return an empty string.
  258.      */
  259.     public function deletePDF (Request $request){
  260.         try{
  261.             unlink(substr($request->get('PdfTmpPath'), 1));
  262.         } catch (Exception $e){
  263.             return new Response('Can not delete pdf file from temporal directory, '.$e->getMessage().', please configure tmpPdfDirectory and pdf variables');
  264.         }
  265.         return new Response('');
  266.     }
  267.     public function cuantapinturanecesarioresultAction(
  268.         Request $request,
  269.         HelperService $helperService
  270.     ) {
  271.         $this->checkAccess($request);
  272.         $this->setCookieTemplate();
  273.         $this->view->unique $helperService->generateUniqueCode();
  274.     }
  275.     /**
  276.      * marcasAction
  277.      *
  278.      * @param Request $request
  279.      * @param HelperService $helperService
  280.      * @return void
  281.      */
  282.     public function marcasAction(
  283.         Request $request,
  284.         HelperService $helperService
  285.     ) {
  286.         $this->checkAccess($request);
  287.         $this->setCookieTemplate();
  288.         $marcas = new DataObject\ProductMarca\Listing();
  289.         $marcas->setUnpublished(false);
  290.         $marcas->setOrderKey("order");
  291.         $this->view->marcas $marcas;
  292.         $this->view->unique $helperService->generateUniqueCode();
  293.         \Pimcore\Cache::disable();
  294.     }
  295.     /**
  296.      * categoriasAction
  297.      *
  298.      * @param Request $request
  299.      * @param HelperService $helperService
  300.      * @return void
  301.      */
  302.     public function categoriasAction(
  303.         Request $request,
  304.         HelperService $helperService
  305.     ) {
  306.         $this->checkAccess($request);
  307.         $this->setCookieTemplate();
  308.         $categories = new DataObject\ProductCategory\Listing();
  309.         $categories->setUnpublished(false);
  310.         $categories->setOrderKey("order");
  311.         $categories->setCondition('o_path LIKE ?', ['/Categorias de producto/']);
  312.         // $categories->setCondition('(productos IS NOT NULL OR productos <> \'\') AND o_path LIKE ?', ['/Categorias de producto/']);
  313.         $this->view->categories $categories;
  314.         $this->view->unique $helperService->generateUniqueCode();
  315.         \Pimcore\Cache::disable();
  316.     }
  317.     /**
  318.      * @Route("/colaboradoresmap/{lang}")
  319.      */
  320.     public function colaboradoresmapAction(
  321.         Request $request,
  322.         $lang,
  323.         HelperService $helperService,
  324.         Config $config) {
  325.         $this->checkAccess($request);
  326.         $this->setCookieTemplate();
  327.         $apikey $config['services']['google']['browser_api_key'];
  328.         $colaboradores = new DataObject\Colaborador\Listing();
  329.         $colaboradores->setCondition("showinweb = ?"1);
  330.         $colaboradores->addConditionParam("showinmap = ?"1"AND");
  331.         $colaboradores->setOrderKey("name");
  332.         $this->view->unique $helperService->generateUniqueCode();
  333.         return $this->render(":Content:puntodeventamap.html.php", ["colaboradores" => $colaboradores"linkTitle" => $this->get("translator")->trans("lnk_open_in_google_map", array(), null$lang), "api_key" => $apikey]);
  334.         // $this->view->colaboradores = $colaboradores;
  335.     }
  336.     public function setCookieTemplate() {
  337.         $cookieListener $this->get(\Pimcore\Bundle\CoreBundle\EventListener\Frontend\CookiePolicyNoticeListener::class);
  338.         $cookieListener->loadTemplateFromResource("@App/Resources/views/Misc/cookie-policy-bsn-template.html");
  339.     }
  340.     private function checkAccess(Request $request) {
  341.         if (!(($request->query->get('pimcore_preview') == "true") || ($request->query->get('pimcore_editmode') == "true"))) {
  342.             // $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
  343.         }
  344.     }
  345.     /**
  346.     * @Route("/squareMeters", name="squareMeters")
  347.     *
  348.     */
  349.     public function squareMetersAction(Request $request){
  350.         return $this->render('Content/squareMeters.html.twig');
  351.     }
  352.     /**
  353.     * @Route("/calculatePaint", name="calculatePaint")
  354.     *
  355.     */
  356.     public function calculatePaintAction(Request $request){
  357.         return $this->render('Content/calculatePaint.html.twig');
  358.     }
  359.     /**
  360.     * @Route("/paintingSchemes", name="paintingSchemes")
  361.     *
  362.     */
  363.     public function paintingSchemesAction(){
  364.         return $this->render('Content/paintingSchemes.html.twig');
  365.     }
  366.     #[Route('/rates'name'rates-view')]
  367.     public function ratesView(Request $request): Response
  368.     {
  369.         $locale $request->getLocale();
  370.         $params['_locale'] = $locale;
  371.         //get the Excel file with the price changes
  372.         $filePath __DIR__.'/../../public/var/assets/excel_de_tarifas/temp/changes.xlsx';
  373.         $arrayData = [];
  374.         try {
  375.             $spreadsheet IOFactory::load($filePath);
  376.             $sheet $spreadsheet->getActiveSheet();
  377.             foreach ($sheet->getRowIterator() as $row) {
  378.                 $cellIterator $row->getCellIterator();
  379.                 $cellIterator->setIterateOnlyExistingCells(false);
  380.                 $value $sheet->getCell('A' $row->getRowIndex())->getValue();
  381.                 $brands = [];
  382.                 foreach ($sheet->getColumnIterator('B') as $column){
  383.                     $columnIterator =  $column->getCellIterator();
  384.                     $columnIterator->setIterateOnlyExistingCells(false);
  385.                     $brandName $sheet->getCell($column->getColumnIndex().$row->getRowIndex())->getValue();
  386.                     $brands[] = ProductMarca::getByName($brandName)->load();
  387.                 }
  388.                 $date = new DateTime();
  389.                 $date->modify('+' $value ' days');
  390.                 $formattedDateFull strftime('%e %B %Y'$value);
  391.                 $arrayData[] = [
  392.                     'date' => $formattedDateFull,
  393.                     'brands' => $brands
  394.                 ];
  395.             }
  396.         } catch (Exception){
  397.         }
  398.         $params['path'] = '/excel_de_tarifas/ExporterWeb.xlsx';
  399.         $params['changes'] = $arrayData;
  400.         return $this->render('Content/rates.html.twig'$params);
  401.     }
  402.     #[Route('/recent-events'name'recent-events')]
  403.     public function eventsViewAction(): Response
  404.     {
  405.         return $this->render('Content/events.html.twig');
  406.     }
  407.     /**
  408.     * @Route("/calculatePaintResult", name="calculatePaintResult")
  409.     *
  410.     */
  411.     public function calculatePaintResultAction(
  412.         Request $request,
  413.         Factory $ecommerceFactory,
  414.         HelperService $helperService,
  415.         ListHelper $listHelper,
  416.         PaginatorInterface $paginator,
  417.     ){
  418.         $params array_merge($request->query->all(), $request->attributes->all(), $request->request->all());
  419.         $resultado = array();
  420.         if (!empty($params['limit'])) {
  421.             $limit $params['limit'];
  422.         }
  423.         $resultado["tipo-embarcacion"] = $params["radio_1"];
  424.         if (preg_match("/^mo/i"$params["radio_1"])) {
  425.             $resultado["tipo-embarcacion"] = $resultado["tipo-embarcacion"] . $params["radio_2"];
  426.         }
  427.         $resultado["base-embarcacion"] = $params["radio_3"];
  428.         $resultado["dimension-eslora"] = $params["value1"];
  429.         $resultado["dimension-calado"] = $params["value2"];
  430.         $resultado["dimension-manga"] = $params["value3"];
  431.         $resultado["resultado-litre"] = round(floatval($params["value_1"]), 2);
  432.         if (!key_exists("calculvariant"$params)) {
  433.             if (empty($params["calculvariant"])) {
  434.                 $params["calculvariant"] = $params["value_hidden"];
  435.             }
  436.         }
  437.         if ($request->get('filterdefinition') instanceof \Pimcore\Model\DataObject\FilterDefinition) {
  438.             $filterDefinition $request->get('filterdefinition');
  439.         }
  440.         if (empty($filterDefinition)) {
  441.             $filterDefinition \Pimcore\Config::getWebsiteConfig()->get('resultcuantapinturaFilterdefinition');
  442.         }
  443.         if (empty($limit)) {
  444.             $limit $filterDefinition->getPageLimit();
  445.         }
  446.         //setting assortment tenant
  447.         $environment $ecommerceFactory->getEnvironment();
  448.         $environment->setCurrentAssortmentTenant("default");
  449.         // create product list
  450.         $indexService $ecommerceFactory->getIndexService();
  451.         $products $indexService->getProductListForCurrentTenant();
  452.         $products->setVariantMode(ProductListInterface::VARIANT_MODE_HIDE);
  453.         $products->addCondition("productstatus NOT IN ('new','decatelogized','for_delete') OR productstatus IS NULL"'productstatus');
  454.         $products->addCondition("calculvariant LIKE '%#" $params["value_hidden"] . "#%'"'calculvariant');
  455.         $params["products"] = $products;
  456.         // create and init filter service
  457.         $filterService $ecommerceFactory->getFilterService();
  458.         $listHelper->setupProductList($filterDefinition$products$params$filterServicetrue);
  459.         $params["filterService"] = $filterService;
  460.         $params["filterDefinition"] = $filterDefinition;
  461.         $currentPage $request->get('page'1);
  462.         $productTotal count($products);
  463.         $maxPage ceil($productTotal $limit);
  464.         if($currentPage $maxPage){
  465.             $currentPage $maxPage;
  466.         }
  467.         /** @var SlidingPagination $paginator */
  468.         $paginator $paginator->paginate(
  469.             $products,
  470.             $currentPage,
  471.             $limit
  472.         );
  473.         $params["paginator"] = $paginator;
  474.         $params['paginationVariables'] = $paginator->getPaginationData();
  475.         $params['perPage'] = $limit;
  476.         $params['resultado'] = $resultado;
  477.         return $this->render('Content/calculatePaintResult.html.twig',$params);
  478.     }
  479.     public function privacyPolicyAction(){
  480.         return $this->render('Content/policy/privacyPolicy.html.twig');
  481.     }
  482.     public function termsAndConditionsAction(){
  483.         return $this->render('Content/policy/termsAndConditions.html.twig');
  484.     }
  485.     public function dataProtectionAction(){
  486.         return $this->render('Content/policy/dataProtection.html.twig');
  487.     }
  488.     public function cookiePolicyAction(){
  489.         return $this->render('Content/policy/cookiePolicy.html.twig');
  490.     }
  491. }