src/Controller/DefaultController.php line 62

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\DataMapper\Product\ProductListingDataMapper;
  4. use App\Model\Product\Category;
  5. use Knp\Component\Pager\PaginatorInterface;
  6. use Pimcore\Controller\FrontendController;
  7. use Pimcore\Model\Asset;
  8. use Pimcore\Model\DataObject;
  9. use Pimcore\Model\DataObject\ProductLine;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. class DefaultController extends FrontendController
  14. {
  15.     /**
  16.      * @Route ("/testing-url", name="testing_url")
  17.      * @return void
  18.      */
  19.     public function test(Request $requestPaginatorInterface $paginator){
  20.         /*$test = Product::getById(8389);
  21.       dd($test->getClass()->getFieldDefinition("shoeForm"));
  22.        $paginator = (new ProductRepository())->paginate($request, $paginator);
  23.        dd($paginator->getItems());
  24. */
  25.         $productLines = new DataObject\ProductLine\Listing();
  26.         foreach($productLines as $productLine) {
  27.             $pages[] = [
  28.                 'label' => $productLine->getName(),
  29.                 'url' => '/' $request->getLocale() . '/products/'.$productLine->getKey().'~l' $productLine->getId()
  30.             ];
  31.         }
  32.         dd($productLines);
  33.         $categories Category::getByPath('/Categories/products/')->getChildren();
  34.         foreach($categories as $category){
  35.         }
  36.         dd($pages);
  37.         dd(Category::getByPath('/Categories/products/')->getChildren());
  38.         dd(\App\Model\Product\Product::getById(10939)->getProductCategories());
  39.         dd(ProductListingDataMapper::list([...$paginator->getItems()])->all($request));
  40.     }
  41.     /**
  42.      * @Route ("/{_locale}/konformitaetserklaerungen", name="find_conformity_declaration")
  43.      * @param Request $request
  44.      */
  45.     public function findConformityDeclaration(Request $request){
  46.         $term $request->get('term');
  47.         // remove spaces and special characters from $term
  48.         $term preg_replace('/[^A-Za-z0-9]/'''$term);
  49.         $wrongTerm false;
  50.         $results = [];
  51.         if(strlen($term) >= 9){
  52.             $articleID substr($term06);
  53.             $quality substr($term63);
  54.             // get folder "CEs"
  55.             $folder Asset::getByPath('/Assets/Konformitaetserklaerungen');
  56.             if ($folder && $folder->getType() == 'folder') {
  57.                 $children $folder->getChildren();
  58.                 $specificResults = [];
  59.                 foreach ($children as $asset) {
  60.                     if ($asset->getType() == 'document') {
  61.                         // Extract articleID and quality from the document name
  62.                         $filename $asset->getFilename();
  63.                         // Match different patterns of filenames
  64.                         if (preg_match('/^CE (\d{4}) (\d{3})/'$filename$matches)) {
  65.                             $docArticleID $matches[1]; // Add leading zeros to match the format
  66.                             $docQuality $matches[2];
  67.                             // Check if articleID and quality match
  68.                             if (substr($articleID04) === $docArticleID && $quality === $docQuality) {
  69.                                 $results[] = [
  70.                                     'label' => $filename,
  71.                                     'value' => $asset->getFullPath()
  72.                                 ];
  73.                             }
  74.                         } elseif (preg_match('/^CE (\d{5}) (\d{3})/'$filename$matches)) {
  75.                             $docArticleID $matches[1];
  76.                             $docQuality $matches[2];
  77.                             // Check if articleID and quality match
  78.                             if (substr($articleID05) === $docArticleID && $quality === $docQuality) {
  79.                                 $specificResults[] = [
  80.                                     'label' => $filename,
  81.                                     'value' => $asset->getFullPath()
  82.                                 ];
  83.                             }
  84.                         }
  85.                     }
  86.                     // Prefer specific results if available
  87.                     if (!empty($specificResults)) {
  88.                         $results $specificResults;
  89.                     }
  90.                 }
  91.             }
  92.         }else{
  93.             $wrongTerm true;
  94.         }
  95.         return $this->render('conformity_declaration/index.html.twig', [
  96.             'results' => $results,
  97.             'wrongTerm' => $wrongTerm
  98.         ]);
  99.     }
  100.     /**
  101.      * @param Request $request
  102.      * @return Response
  103.      */
  104.     public function defaultAction(Request $request): Response
  105.     {
  106.         return $this->render('default/default.html.twig');
  107.     }
  108.     /**
  109.      * @param Request $request
  110.      * @param int $code
  111.      * @return Response
  112.      */
  113.     public function errorAction(Request $requestint $code 404): Response
  114.     {
  115.         return $this->render('Exception/error.html.twig', [
  116.             'code' => $code
  117.         ]);
  118.     }
  119. }