custom/plugins/Metallit/src/Storefront/Controller/MetallitController.php line 124

Open in your IDE?
  1. <?php
  2. namespace Metallit\Storefront\Controller;
  3. use Shopware\Core\Framework\Context;
  4. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\JsonResponse;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Shopware\Core\Framework\Routing\Annotation\RouteScope;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  12. class MetallitController extends AbstractController
  13. {
  14.     /**
  15.      * @Route("/getitemfile", name="getitemfile", methods={"GET"})
  16.      * @RouteScope(scopes={"storefront"})
  17.      */
  18.     public function getitemfile(Request $request): Response
  19.     {
  20.         $filename base64_decode($request->get('filename'));
  21.         if (!is_file($filename)) {
  22.             die('Die gewünschte Datei wurde nicht gefunden');
  23.         }
  24.         $info pathinfo($filename);
  25.         $response = new Response(file_get_contents($filename));
  26.         $response->headers->set('Content-Type''application/pdf');
  27.         $response->headers->set('Content-Disposition'$response->headers->makeDisposition(
  28.             ResponseHeaderBag::DISPOSITION_INLINE,
  29.             urlencode($info['basename'])
  30.         ));
  31.         return $response;
  32.     }
  33.     /**
  34.      * @Route("/getdocuments", name="getdocuments", methods={"GET"})
  35.      * @RouteScope(scopes={"storefront"})
  36.      */
  37.     public function getdocuments(Request $requestContext $context): JsonResponse
  38.     {
  39.         $item_no $request->get('productNumber'); 
  40.         $criteria = new Criteria([$request->get('master')]);
  41.         $master $this->container->get('product.repository')->search($criteria$context)->first();
  42.         $master_nr substr($master->getProductNumber(), 1);
  43.         // Flyer und Sicherheitsdatenblätter
  44.         $SD_FilesPath '/mnt/Storagebox/Produktinformationen/';
  45.         $FL_FilesPath '/mnt/Storagebox/Marketing_Kommunikationsmittel/';
  46.         $folders = array(
  47.             '0100_Sicherheitsdatenblätter' => array($SD_FilesPathscandir($SD_FilesPath '0100_Sicherheitsdatenblätter')),
  48.             '0150_Betriebsanweisungen' => array($SD_FilesPathscandir($SD_FilesPath '0150_Betriebsanweisungen')),
  49.             '0300_Produktflyer' => array($FL_FilesPathscandir($FL_FilesPath '0300_Produktflyer')),
  50.             '0300_Bedienungsanleitungen' => array($SD_FilesPathscandir($SD_FilesPath '0300_Bedienungsanleitungen')),
  51.             '0200_Technische Datenblätter' => array($SD_FilesPathscandir($SD_FilesPath '0200_Technische Datenblätter')),
  52.             '0400_Zertifikate' => array($SD_FilesPathscandir($SD_FilesPath '0400_Zertifikate')),
  53. //            '0600_Bildarchiv' => array($this->SD_FilesPath, scandir($this->SD_FilesPath . '0600_Bildarchiv'))
  54.         );
  55.         $pdf_arr = [];
  56.         $div_template '<div class="card product-box box-standard">
  57.                             <div class="card-body">
  58.                                 <div class="product-badges">
  59.                                 </div>
  60.                             </div>';
  61.         
  62.         foreach($folders as $name => $files) {
  63.             $found false;          
  64.             $itemno trim($item_no); 
  65. StartSearch:
  66.             foreach($files[1] as $file) {
  67.                 if ($file == "." || $file == ".." || $file == "001_Archiv" || $file[0] == "@") continue;
  68. //                $erg .=  "<p>$file</p>";
  69.                 if (is_dir($files[0] . $name '/' $file)) {   
  70.                     // Bei 0400_Zertifikate die Unterverzeichnisse durchsuchen
  71.                     $subdir scandir($files[0] . $name '/' $file);
  72.                     foreach($subdir as $subfile) {
  73.                         if ($subfile == "." || $subfile == ".." || is_dir($subfile)) continue;
  74.                         $cleanfile str_replace(' '''$subfile); // zur Sicherheit noch mal alle Leerzeichen raus
  75.                         $tmp explode('_'$cleanfile);
  76.                         if (count($tmp) < 3) continue;
  77.                         $lang strtoupper($tmp[2]);
  78.                         if (strstr($cleanfile"_" $itemno "_") !== false) {
  79.                             $pdf_arr[$name][] = array(($files[0] . $name '/' $file.'/'.$subfile), $lang);
  80.                             $found true;
  81.                         }
  82.                     }
  83.                 } else {
  84.                     $cleanfile str_replace(' '''$file); // zur Sicherheit noch mal alle Leerzeichen raus
  85.                     $tmp explode('_'$cleanfile);
  86.                     if (count($tmp) < 3) continue;
  87.                     $lang strtoupper($tmp[2]);
  88.                     $tmp explode('_'$name);
  89.                     if (strstr($cleanfile"_" $itemno "_") !== false) {
  90.                         $pdf_arr[$name][] = array(($files[0] . $name '/' $file), $lang);
  91.                         $found true;
  92.                     }
  93.                 }
  94.             } 
  95.             if (!$found) {                
  96.                 if ($itemno !== $master_nr) {
  97.                     $itemno $master_nr;
  98.                     goto StartSearch;
  99.                 }
  100.             }
  101.         }
  102.         if ($pdf_arr) {
  103.             $divcontent '<div class="row">';
  104.             foreach($pdf_arr as $folder => $pdf_files) {
  105.                 $divcontent .= '<div class="metallit-download-documents col-sm-4" style="text-align:center;"><h4>'.explode("_"$folder)[1].'</h4><div class="metallit-download-documents-body">';
  106.                 foreach($pdf_files as $pdf_file) {
  107.                     $divcontent .= '<div class="metallit-download-documents-entry">';
  108.                     $divcontent .= '<a target="_blank" href="/getitemfile?filename='.base64_encode($pdf_file[0]).'" title="'.basename($pdf_file[0]).'">';
  109.                     $divcontent .= '<i class="fa fa-file-pdf" style="font-size:64px!important"></i><div>' /*basename($pdf_file[0]).' ('.$pdf_file[1].')'*/ $pdf_file[1].'</div>';
  110.                     $divcontent .= '</a>';
  111.                     $divcontent .= '</div>';
  112.                 }
  113.                 $divcontent .= '</div></div>';
  114.             }
  115.             $erg $divcontent.'</div>';
  116.         } else {
  117.             $erg 0;
  118.         }
  119.         
  120.         $responseData $erg;
  121.         return $this->json($responseData);
  122.     }
  123.     /**
  124.      * @Route("/getcustomerhistory", name="getcustomerhistory", methods={"GET"})
  125.      * @RouteScope(scopes={"storefront"})
  126.      */
  127.     public function getcustomerhistory(Request $request): Response
  128.     {
  129.         // holt alle Käufe aus Navision von Produkten, die auch im Shop aktiv sind
  130.         try {
  131.             $mysqli = new \mysqli("88.99.105.137""db_aistest""M3tAll!T""db_ais");
  132.             $mysqli->set_charset("utf8");
  133.             if ($mysqli->connect_errno) {
  134.                 return new Response('Verbindung zur Datenbank fehlgeschlagen: ' $mysqli->connect_error);
  135.             }
  136.             $kdnr $request->get('kdnr');//
  137.             //
  138.             $query "SELECT * FROM (SELECT a.A_NO, a.A_RNR, TRIM(CONCAT(i.Description, ' ', i.Description_2)) AS A_BEZ, MAX(A_AD) AS Last_Order_Date
  139.                         , A_MENGE, TRIM(g.groupname) AS Item_Group, u.seo_path_info AS A_BEZ_URL, 
  140.                         i.shop_image_path
  141.                         FROM articles a
  142.                         LEFT JOIN items i ON i.No_ = a.A_NO
  143.                         LEFT JOIN db_pim.maingroups g ON g.code = MID(i.Item_Group, 4, 2)
  144.                         LEFT JOIN db_shop.product p ON a.A_NO = p.product_number
  145.                         LEFT JOIN db_shop.product_translation t ON t.product_id = p.id AND t.product_version_id = p.version_id
  146.                         LEFT JOIN db_shop.seo_url u ON u.foreign_key = p.id
  147.                         WHERE (DBNr = ? OR BillTo = ?) AND A_NO IN (SELECT product_number FROM db_shop.product WHERE active = 1)
  148.                         AND A_AD > SUBDATE(NOW(), INTERVAL 5 YEAR) 
  149.                         GROUP BY i.Item_Group, a.A_NO) t 
  150.                         ORDER BY Item_Group, Last_Order_Date DESC";
  151.             $stmt $mysqli->prepare($query);
  152.             if (!$stmt) {
  153.                 return new Response('Fehler beim Vorbereiten der Abfrage: ' $mysqli->error);
  154.             }
  155.             $stmt->bind_param("ss"$kdnr$kdnr);
  156.             $stmt->execute();
  157.             $result $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
  158.             $stmt->close();
  159.             $mysqli->close();
  160.             return $this->json($result);
  161.         } catch (Exception $ex) {
  162.             return $ex->getMessage();
  163.         }
  164.         
  165.     }
  166. }