src/Controller/DefaultController.php line 2144

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Pimcore\Controller\FrontendController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use \Pimcore\Model\DataObject;
  8. use \Pimcore\Model\Asset;
  9. class DefaultController extends FrontendController {
  10.     /**
  11.      * @Template
  12.      * @param Request $request
  13.      * @return array
  14.      */
  15.     public function defaultAction(Request $request) {
  16.         return [];
  17.     }
  18.     
  19.     /**
  20.      * @Template
  21.      * @param Request $request
  22.      * @return array
  23.      */
  24.     public function setDebugAction(Request $request) {
  25.         $cookie_name "zeitdebug";
  26.         $cookie_value "true";
  27.         
  28.         setcookie($cookie_name$cookie_valuetime() + (86400 7), "/");
  29.         
  30.         echo "Debugmode successfully set :-)";
  31.         
  32.         exit;
  33.         return [];
  34.     }
  35.     
  36.     /**
  37.      * @Template
  38.      * @param Request $request
  39.      * @return array
  40.      */
  41.     public function addPriceDevAction(Request $request) {
  42.         $data = [
  43.             "54093" => "1185.60",
  44.             "54172" => "5520.00",
  45.             "54173" => "5786.67",
  46.             "54755" => "4426.67",
  47.             "54861" => "2647.50",
  48.             "54863" => "2143.00",
  49.             "54865" => "2445.50",
  50.             "54948" => "7866.67",
  51.             "54949" => "8640.00",
  52.             "55230" => "4588.50",
  53.             "55256" => "8143.00",
  54.             "55257" => "2698.00",
  55.             "55285" => "2213.34",
  56.             "56089" => "1502.80",
  57.             "56711" => "1307.80",
  58.             "57792" => "2054.00",
  59.             "57793" => "2054.00",
  60.             "57798" => "1144.00",
  61.             "57821" => "2145.00",
  62.             "57989" => "1131.00",
  63.             "58276" => "2106.00",
  64.             "58574" => "2119.00",
  65.             "58925" => "2431.00",
  66.             "59229" => "2496.00",
  67.             "59230" => "2496.00",
  68.             "59328" => "1037.40",
  69.             "60062" => "2925.00",
  70.             "60118" => "2275.00",
  71.             "60155" => "1014.00",
  72.             "60157" => "832.00",
  73.             "60455" => "1144.00",
  74.             "60457" => "1209.00",
  75.             "60546" => "1157.00",
  76.             "60666" => "1157.00",
  77.             "60755" => "988.00",
  78.             "61226" => "1443.00",
  79.             "61227" => "1664.00",
  80.             "61229" => "1443.00",
  81.             "61462" => "1404.00",
  82.             "61464" => "2158.00",
  83.             "61670" => "1664.00",
  84.             "61671" => "2145.00",
  85.             "61673" => "1196.00",
  86.             "61676" => "3172.00",
  87.             "61677" => "832.00",
  88.             "61715" => "2496.00",
  89.             "61877" => "1183.00",
  90.             "61880" => "2314.00",
  91.             "61912" => "3536.00",
  92.             "61930" => "1651.00",
  93.             "61931" => "1573.00",
  94.             "61977" => "1196.00",
  95.             "61978" => "1170.00",
  96.             "62014" => "1183.00",
  97.             "62015" => "1170.00",
  98.             "62016" => "5954.00",
  99.             "62017" => "1430.00",
  100.             "62033" => "1222.00",
  101.             "62141" => "2301.00",
  102.             "62162" => "2327.00",
  103.             "62163" => "2236.00",
  104.             "62300" => "2405.00",
  105.             "62524" => "2327.00",
  106.             "62525" => "2327.00",
  107.             "62657" => "1612.00",
  108.             "63750" => "1250.00"
  109.         ];
  110.         
  111.         
  112.         $servername "carat-dev.cp4unapazytb.eu-central-1.rds.amazonaws.com";
  113.         $username "atimis";
  114.         $password "gui8kknyzG";
  115.         $dbname "carat_100";
  116.         
  117.         // Create connection
  118.         $conn = new \mysqli($servername$username$password$dbname);
  119.         // Check connection
  120.         if ($conn->connect_error) {
  121.           die("Connection failed: " $conn->connect_error);
  122.         }
  123.         
  124.         $conn->set_charset("utf8mb4");
  125.         
  126.         foreach($data as $storageNumber => $price) {
  127.             echo "Number: " $storageNumber " Price: " $price "<br>";
  128.             
  129.             $sql "INSERT INTO `PriceDevaluation` (`id`, `created`, `deleted`, `modified`, `note`, `price`, `creator_id`, `modificator_id`, `item_id`, `targetDate`)
  130.             VALUES (NULL, NULL, 0, NULL, 'Teilwert4', $price, NULL, NULL, (SELECT `id` FROM `Item` WHERE `stockNumber` = $storageNumber), '2024-06-30 00:00:00')";
  131.             
  132.             $result $conn->query($sql);
  133.             
  134.             var_dump($result);
  135.         }
  136.         
  137.         $conn->close();
  138.         
  139.         
  140.         exit;
  141.         
  142.         return [];
  143.     }
  144.     
  145.     /**
  146.      * @Template
  147.      * @param Request $request
  148.      * @return array
  149.      */
  150.     public function videopageAction(Request $request) {
  151.         return [];
  152.     }
  153.     
  154.     /**
  155.      * @Template
  156.      * @param Request $request
  157.      * @return array
  158.      */
  159.     public function serviceAction(Request $request) {
  160.         return [];
  161.     }
  162.     
  163.     /**
  164.      * @Template
  165.      * @param Request $request
  166.      * @return array
  167.      */
  168.     public function unternehmenAction(Request $request) {
  169.         return [];
  170.     }
  171.     
  172.     /**
  173.      * @Template
  174.      * @param Request $request
  175.      * @return array
  176.      */
  177.     public function historyAction(Request $request) {
  178.         return [];
  179.     }
  180.     
  181.     /**
  182.      * @Template
  183.      * @param Request $request
  184.      * @return array
  185.      */
  186.     public function emailAction(Request $request) {
  187.         return [];
  188.     }
  189.     
  190.     /**
  191.      * @Template
  192.      * @param Request $request
  193.      * @return array
  194.      */
  195.     public function jaegerAction(Request $request) {
  196.         return [];
  197.     }
  198.     
  199.     /**
  200.      * @Template
  201.      * @param Request $request
  202.      * @return array
  203.      */
  204.     public function aktuellesAction(Request $request) {
  205.         return [];
  206.     }
  207.     
  208.     /**
  209.      * @Template
  210.      * @param Request $request
  211.      * @return array
  212.      */
  213.     public function profileAction(Request $request) {
  214.         return [];
  215.     }
  216.     
  217.     /**
  218.      * @Template
  219.      * @param Request $request
  220.      * @return array
  221.      */
  222.     public function testassetAction(Request $request) {
  223.         
  224.         // $asset = Asset::getById(247380);
  225.         // $versions = $asset->getVersions();
  226.         // 
  227.         // $previousVersion = $versions[count($versions)-3];
  228.         // 
  229.         // $oldData = $previousVersion->getData();
  230.         // 
  231.         // var_dump($previousVersion);
  232.         // exit;
  233.         // $asset->setData($oldData);
  234.         // $asset->save();
  235.         // exit;
  236.         
  237.         
  238.         $assets = new \Pimcore\Model\Asset\Listing();
  239.         $assets->setCondition("path LIKE '%/PIM/01 Uhren/02 Produkte/%' and type = 'image' and id != 273747 and id != 280811 and id != 273482");
  240.         $assets->setLimit(500);
  241.         $assets->setOffset(999);
  242.         $assets->setOrderKey("filename");
  243.         $assets->setOrder("ASC");
  244.         $assets->load();
  245.         
  246.         $i 0;
  247.         
  248.         foreach($assets as $asset) {
  249.             $i++;
  250.             $filename $asset->getFilename();
  251.             // var_dump($filename);
  252.             //$data = file_get_contents("https://huebner.carat.solutions/carat/filedownload?fileName=" . $filename);
  253.             //var_dump($data);
  254.             
  255.             $asset->setData(file_get_contents("https://huebner.carat.solutions/carat/filedownload?fileName=" $filename));
  256.             $asset->save();
  257.         }
  258.         
  259.         echo $i;
  260.          echo "done";
  261.         // $newAsset = new \Pimcore\Model\Asset\Image();
  262.         // $newAsset->setFilename($filename);
  263.         // $newAsset->setData(file_get_contents("https://huebner.carat.solutions/carat/filedownload?fileName=" . $filename));
  264.         // $newAsset->setParent(\Pimcore\Model\Asset::getByPath("/Test"));
  265.         // $newAsset->save();
  266.         
  267.         exit;
  268.         return [];
  269.     }
  270.     
  271.     /**
  272.      * @Template
  273.      * @param Request $request
  274.      * @return array
  275.      */
  276.     public function inquiryAction(Request $request) {
  277.         $productid str_replace("/"""$request->get("productid"));
  278.         
  279.         $product DataObject::getById($productid);
  280.         
  281.         return $this->render('/default/inquiry.html.twig', ["product" => $product]);
  282.     }
  283.     
  284.     /**
  285.      * @Template
  286.      * @param Request $request
  287.      * @return array
  288.      */
  289.     public function sendInquiryAction(Request $request) {
  290.         if ($request->getMethod() === "POST") {
  291.                 
  292.                 
  293.             $params $request->request;
  294.             
  295.             $productId $params->get("productId");
  296.             $product DataObject::getById($productId);
  297.             $reference $product->getarticleNumber();
  298.             
  299.             $newsletter $params->get("newsletter");
  300.             $iwantto $params->get("iwantto");
  301.             $contactoption $params->get("contactoption");
  302.             $branch $params->get("branch");
  303.             $comment $params->get("comment");
  304.             $salutation $params->get("salutation");
  305.             $title $params->get("title");
  306.             $firstname $params->get("firstname");
  307.             $lastname $params->get("lastname");
  308.             $email $params->get("email");
  309.             $phone $params->get("phone");
  310.             $address $params->get("address");
  311.             $zipcode $params->get("zipcode");
  312.             $state $params->get("state");
  313.             $country $params->get("country");
  314.             
  315.             //set branch email
  316.             switch($branch) {
  317.                 case "Wien":
  318.                     $branchemail "wien@uhrenhuebner.at";
  319.                     break;
  320.                 case "Linz":
  321.                     $branchemail "linz@uhrenhuebner.at";
  322.                     break;
  323.                 case "Wels":
  324.                     $branchemail "wels@uhrenhuebner.at";
  325.                     break;
  326.             }
  327.             
  328.             $inquiry = new DataObject\Inquiry();
  329.             $inquiry->setKey(\Pimcore\Model\Element\Service::getValidKey('Anfrage-' $email date('d-m-y h:i:s'), 'object'));
  330.             $inquiry->setParentId(1833);
  331.             $inquiry->setiwantto($iwantto);
  332.             $inquiry->setcontactoption($contactoption);
  333.             $inquiry->setbranch($branch);
  334.             $inquiry->setcomment($comment);
  335.             $inquiry->setnewsletter($newsletter);
  336.             $inquiry->setsalutation($salutation);
  337.             $inquiry->settitle($title);
  338.             $inquiry->setfirstname($firstname);
  339.             $inquiry->setlastname($lastname);
  340.             $inquiry->setemail($email);
  341.             $inquiry->setphone($phone);
  342.             $inquiry->setaddress($address);
  343.             $inquiry->setzipcode($zipcode);
  344.             $inquiry->setstate($state);
  345.             $inquiry->setcountry($country);
  346.             $inquiry->setProduct($product);
  347.             $inquiry->setPublished(true);
  348.             $inquiry->save();
  349.             
  350.             $salutationtext $salutation == "Herr" "Sehr geehrter Herr" "Sehr geehrte Frau";
  351.             $productHtml $this->getProductHtml($product);
  352.             
  353.             $productHtml " " $product->getBrand()->getName() . " - " $product->getModel() . " ";
  354.             
  355.             //send User Mail
  356.             $mail = new \Pimcore\Mail();
  357.             $mail->addTo($email);
  358.             //$mail->addTo("a.daum@ontime.at");
  359.             $mail->setDocument("/Emails/inquiry-user");
  360.             $mail->setParams([
  361.                 'productHtml' => $productHtml,
  362.                 'salutation' => $salutationtext,
  363.                 'iwantto' => $iwantto,
  364.                 'contactoption' => $contactoption,
  365.                 'branch' => $branch,
  366.                 'comment' => $comment,
  367.                 'title' => $title,
  368.                 'firstname' => $firstname,
  369.                 'lastname' => $lastname,
  370.                 'email' => $email,
  371.                 'phone' => $phone,
  372.                 'address' => $address,
  373.                 'zipcode' => $zipcode,
  374.                 'state' => $state,
  375.                 'country' => $country
  376.             ]);
  377.             $mail->send();
  378.             
  379.             //send admin Mail
  380.             $mail2 = new \Pimcore\Mail();
  381.             // $mail->addTo("wien@uhrenhuebner.at");
  382.             $mail2->addTo($branchemail);
  383.             $mail2->addTo("a.daum@ontime.at");
  384.             $mail2->setDocument("/Emails/inquiry-admin");
  385.             $mail2->setParams([
  386.                 'brand' => $product->getBrand()->getName(),
  387.                 'model' => $product->getModel(),
  388.                 'reference' => $reference,
  389.                 'deeplink' => '',
  390.                 'productHtml' => $productHtml,
  391.                 'salutation' => $salutationtext,
  392.                 'iwantto' => $iwantto,
  393.                 'contactoption' => $contactoption,
  394.                 'branch' => $branch,
  395.                 'comment' => $comment,
  396.                 'title' => $title,
  397.                 'firstname' => $firstname,
  398.                 'lastname' => $lastname,
  399.                 'email' => $email,
  400.                 'phone' => $phone,
  401.                 'address' => $address,
  402.                 'zipcode' => $zipcode,
  403.                 'state' => $state,
  404.                 'country' => $country
  405.             ]);
  406.             $mail2->send();
  407.         }
  408.         return [];
  409.     }
  410.     
  411.     protected static function getProductHtml($product) {
  412.         $html '<table style="border:none;"';
  413.             $html .= '<tr>';
  414.                 $html .= '<td style="padding: 10px">';
  415.                     $html .= '<img src="https://zeit.at/'$product->getFrontImage()->getPath() . $product->getFrontImage()->getFilename() .'" alt="' $product->getModel() . '" style="width:100%; height: auto; max-width:200px";>';
  416.                 $html .= '</td>';
  417.                 $html .= '<td style="padding: 10px 0px;">';
  418.                     $html .= '<p>'.$product->getModel().'</p>';
  419.                 $html .= '</td>';
  420.             $html .= '</tr>';
  421.         $html .= '</table>';
  422.         
  423.         return $html;
  424.     }
  425.     
  426.     /**
  427.      * @Template
  428.      * @param Request $request
  429.      * @return array
  430.      */
  431.     public function loginAction(Request $request) {
  432.         if ($request->getMethod() === "POST") {
  433.             $params $request->request;
  434.             $email $params->get("email");
  435.             $password $params->get("password");
  436.             
  437.             $user DataObject::getByPath("/CRM/Users/" $email);
  438.             $passwordhash $user->getPassword();
  439.             
  440.             if(password_verify($password$passwordhash)) {
  441.                 //echo "login good";
  442.                 $loggedInUser $user;
  443.                 $cookie_name "zeituser";
  444.                 $cookie_value "4DFGHJ8765FGHJ".$user->getId()."KJHGF45678JHG4343";
  445.                 setcookie($cookie_name$cookie_valuetime() + (86400 7), "/"); 
  446.                 return $this->redirect("/");
  447.                 //return $this->render('/default/products.html.twig', ["loggedInUser" => $loggedIdUser]);
  448.                 exit;
  449.             } else {
  450.                 echo "login no good";
  451.             }
  452.             
  453.             exit;
  454.         }
  455.         return [];
  456.     }
  457.     
  458.     /**
  459.      * @Template
  460.      * @param Request $request
  461.      * @return array
  462.      */
  463.     public function registerAction(Request $request) {
  464.         if ($request->getMethod() === "POST") {
  465.             $params $request->request;
  466.             
  467.             $salutation $params->get("salutation");
  468.             $title $params->get("title");
  469.             $firstname $params->get("firstname");
  470.             $lastname $params->get("lastname");
  471.             $email $params->get("email");
  472.             $phone $params->get("phone");
  473.             $address $params->get("address");
  474.             $zipcode $params->get("zipcode");
  475.             $state $params->get("city");
  476.             $country $params->get("country");
  477.             
  478.             $password $params->get("password");
  479.             
  480.             $userobject = new DataObject\Customer();
  481.             $userobject->setKey(\Pimcore\Model\Element\Service::getValidKey($email'object'));
  482.             $userobject->setParentId(390);
  483.             
  484.             $userobject->setSalutation($salutation);
  485.             $userobject->setTitle($title);
  486.             $userobject->setFirstName($firstname);
  487.             $userobject->setLastName($lastname);
  488.             $userobject->setAddress($address);
  489.             $userobject->setZipcode($zipcode);
  490.             $userobject->setCity($state);
  491.             $userobject->setPhone($phone);
  492.             $userobject->setEmail($email);
  493.             $userobject->setUsername($email);
  494.             $userobject->setCountry($country);
  495.             
  496.             $userobject->setPassword($password);
  497.             
  498.             $userobject->setPublished(true);
  499.             $userobject->save();
  500.             
  501.             echo "saved";            
  502.             exit;
  503.         } else {
  504.             
  505.         }
  506.     }
  507.     
  508.     /**
  509.      * @Template
  510.      * @param Request $request
  511.      * @return array
  512.      */
  513.     public function logoutAction(Request $request) {
  514.         
  515.         unset($_COOKIE['zeituser']);
  516.         setcookie('zeituser'null, -1'/'); 
  517.         
  518.         exit;
  519.         return [];
  520.     }
  521.     
  522.     /**
  523.      * @Template
  524.      * @param Request $request
  525.      * @return array
  526.      */
  527.     public function checkoutAction(Request $request) {
  528.         return [];
  529.     }
  530.     
  531.     /**
  532.      * @Template
  533.      * @param Request $request
  534.      * @return array
  535.      */
  536.     public function cartAction(Request $request) {
  537.         return [];
  538.     }
  539.     
  540.     /**
  541.      * @Template
  542.      * @param Request $request
  543.      * @return array
  544.      */
  545.     public function deleteSoldProductsAction(Request $request) {
  546.         $checkstring date('d-m-y');
  547.             //$checkstring .= 'manual';
  548.         $products = new DataObject\Product\Listing();
  549.         $products->setCondition("updateinfo != '$checkstring' AND (manualInput != '1' OR manualInput IS NULL)");
  550.         $products $products->load();
  551.         if(count($products) < 100) {
  552.             foreach($products as $product) {
  553.                 $product->delete();
  554.             }
  555.         }
  556.        
  557.         exit;
  558.         return [];
  559.     
  560.     }
  561.     
  562.     /**
  563.      * @Template
  564.      * @param Request $request
  565.      * @return array
  566.      */
  567.     public function createBrandDocumentsAction(Request $request) {
  568.         // $branddocument = \Pimcore\Model\Document::getByPath("/Uhren/Marken/" . "A. Lange - Söhne");
  569.         // $branddocument->setProperty("navigation_name", "text", "A. Lange & Söhne");
  570.         // $branddocument->setController("App\Controller\DefaultController::brandAction");
  571.         // $branddocument->save();
  572.         // exit;
  573.         
  574.         $brands = new DataObject\Brand\Listing();
  575.         $brands->setCondition("o_path LIKE '%Uhren%'");
  576.         $brands $brands->load();
  577.         
  578.         foreach($brands as $brand) {
  579.             $brandkey str_replace(["&"], ["-"], $brand->getKey());
  580.             
  581.             $branddocument \Pimcore\Model\Document::getByPath("/Uhren/Marken/" $brandkey);
  582.             if($branddocument) {
  583.                 
  584.             } else {
  585.                 $page = new \Pimcore\Model\Document\Page();
  586.                 $page->setKey($brandkey);
  587.                 $page->setTitle($brand->getName());
  588.                 $page->setParentId(2);
  589.                 $page->setProperty("navigation_name""text"$brand->getName());
  590.                 $page->setController("App\Controller\DefaultController::brandAction");
  591.                 $page->setPublished(true);
  592.                 $page->save();
  593.             }
  594.         }
  595.         
  596.         exit;
  597.         return [];
  598.     }
  599.     
  600.     /**
  601.      * @Template
  602.      * @param Request $request
  603.      * @return array
  604.      */
  605.     public function createBrandFolderAction(Request $request) {
  606.         
  607.         $brands = new DataObject\Brand\Listing();
  608.         $brands->setCondition("o_path LIKE '%Uhren%'");
  609.         $brands $brands->load();
  610.         
  611.         // $brands = $brands[0];
  612.         
  613.         //var_dump($brands);
  614.         
  615.         // foreach($brands as $brand) {
  616.         //     $brandkey = str_replace(["&"], ["-"], $brand->getKey());
  617.         //     
  618.         //     $newObject = new DataObject\Folder(); 
  619.         //     $newObject->setKey(\Pimcore\Model\Element\Service::getValidKey($brandkey, 'folder'));
  620.         //     $newObject->setParentId(61);
  621.         //     $newObject->save();
  622.         //     
  623.         // }
  624.         
  625.         // $brandkey = "Jaeger-LeCoultre";
  626.         // $folder = DataObject::getByPath("/PIM/01 Uhren/02 Produkte/" . $brandkey);
  627.         // $parentId = $folder->getId();
  628.         // var_dump($folder->getId());
  629.         
  630.         exit;
  631.         return [];
  632.     }
  633.     
  634.     /**
  635.      * @Template
  636.      * @param Request $request
  637.      * @return array
  638.      */
  639.     public function addcollectionAction(Request $request) {
  640.         
  641.         
  642.         $brands = new DataObject\Brand\Listing();
  643.         $brands->setCondition("o_path LIKE '%Uhren%'");
  644.         $brands $brands->load();
  645.         
  646.         //$brand = DataObject\Brand::getById(85);
  647.             
  648.         foreach($brands as $brand) {
  649.             // $collections = new DataObject\Category\Listing();
  650.             // if($brand->getId() == 85) {
  651.             //     $collections->setCondition("o_path LIKE :brand", ["brand" => "%Nomos%"]);
  652.             // } else {
  653.             //     $collections->setCondition("o_path LIKE :brand", ["brand" => "%".$brand->getName()."%"]);
  654.             // }
  655.             // $collections->load();
  656.             
  657.             if($brand->getId() == 84) {
  658.                 //conquest
  659.                 $longinesCollectionConquest DataObject::getById(7901);
  660.                 $products = new DataObject\Product\Listing();
  661.                 $products->setCondition("`o_key` LIKE \"%Conquest%\" OR `o_key` LIKE \"%Hydroconquest%\" AND brand__id = 84");
  662.                 $products->load();
  663.                 foreach($products as $product) {
  664.                     $cats $product->getCategories();
  665.                     if($cats) {
  666.                         if (!in_array($longinesCollectionConquest$catstrue)) {
  667.                             array_push($cats$longinesCollectionConquest);
  668.                         } 
  669.                     } else {
  670.                         array_push($cats$longinesCollectionConquest);
  671.                     }
  672.                    
  673.                     $product->setCategories($cats);
  674.                     $product->save();
  675.                 }
  676.                 
  677.                 //master
  678.                 $longinesCollectionMaster DataObject::getById(316);
  679.                 $products = new DataObject\Product\Listing();
  680.                 $products->setCondition("`o_key` LIKE \"%Master%\" AND brand__id = 84");
  681.                 $products->load();
  682.                 foreach($products as $product) {
  683.                     $cats $product->getCategories();
  684.                     if($cats) {
  685.                         if (!in_array($longinesCollectionMaster$catstrue)) {
  686.                             array_push($cats$longinesCollectionMaster);
  687.                         } 
  688.                     } else {
  689.                         array_push($cats$longinesCollectionMaster);
  690.                     }
  691.                    
  692.                     $product->setCategories($cats);
  693.                     $product->save();
  694.                 }
  695.                 
  696.                 //spirit
  697.                 $longinesCollectionSpirit DataObject::getById(329);
  698.                 $products = new DataObject\Product\Listing();
  699.                 $products->setCondition("`o_key` LIKE \"%Spirit%\" AND brand__id = 84");
  700.                 $products->load();
  701.                 foreach($products as $product) {
  702.                     $cats $product->getCategories();
  703.                     if($cats) {
  704.                         if (!in_array($longinesCollectionSpirit$catstrue)) {
  705.                             array_push($cats$longinesCollectionSpirit);
  706.                         } 
  707.                     } else {
  708.                         array_push($cats$longinesCollectionSpirit);
  709.                     }
  710.                    
  711.                     $product->setCategories($cats);
  712.                     $product->save();
  713.                 }
  714.                 
  715.                 //elegance
  716.                 $longinesCollectionElegance DataObject::getById(10748);
  717.                 $products = new DataObject\Product\Listing();
  718.                 $products->setCondition("`o_key` LIKE \"%Dolcevita%\" OR `o_key` LIKE \"%Primaluna%\" OR `o_key` LIKE \"%Flagship%\" OR `o_key` LIKE \"%Evidenza%\" OR `o_key` LIKE \"%Record%\" OR `o_key` LIKE \"%Elegant%\" OR `o_key` LIKE \"%Classique%\" AND brand__id = 84");
  719.                 $products->load();
  720.                 foreach($products as $product) {
  721.                     $cats $product->getCategories();
  722.                     if($cats) {
  723.                         if (!in_array($longinesCollectionElegance$catstrue)) {
  724.                             array_push($cats$longinesCollectionElegance);
  725.                         } 
  726.                     } else {
  727.                         array_push($cats$longinesCollectionElegance);
  728.                     }
  729.                    
  730.                     $product->setCategories($cats);
  731.                     $product->save();
  732.                 }
  733.                 
  734.                 //heritage
  735.                 $longinesCollectionHeritage DataObject::getById(10749);
  736.                 $products = new DataObject\Product\Listing();
  737.                 $products->setCondition("`o_key` LIKE \"%Legend%\" OR `o_key` LIKE \"%Ultra-Chron%\" OR `o_key` LIKE \"%Majetek%\" OR `o_key` LIKE \"%Heritage%\" OR `o_key` LIKE \"%Avigation%\" AND brand__id = 84");
  738.                 $products->load();
  739.                 foreach($products as $product) {
  740.                     $cats $product->getCategories();
  741.                     if($cats) {
  742.                         if (!in_array($longinesCollectionHeritage$catstrue)) {
  743.                             array_push($cats$longinesCollectionHeritage);
  744.                         } 
  745.                     } else {
  746.                         array_push($cats$longinesCollectionHeritage);
  747.                     }
  748.                    
  749.                     $product->setCategories($cats);
  750.                     $product->save();
  751.                 }
  752.                 
  753.                 continue;
  754.             }
  755.             
  756.             $collections $brand->getCollections();
  757.             
  758.             
  759.             if($collections) {
  760.                 $collections $collections->getChildren();
  761.             } else {
  762.                 continue;
  763.             }
  764.             
  765.             
  766.             $brandid $brand->getId();
  767.             
  768.             foreach($collections as $coll) {
  769.                 
  770.                 $key $coll->getKey();
  771.                 
  772.                 $products = new DataObject\Product\Listing();
  773.                 if($brand->getName() == "A. Lange & Söhne") {
  774.                     $products->setCondition("UPPER(`o_key`) LIKE \"%$key%\" AND brand__id = $brandid");
  775.                 } elseif($coll->getId() == 281) {
  776.                     $products->setCondition("`o_key` LIKE \"%$key%\" AND `o_key` NOT LIKE \"%Superocean Heritage%\" AND brand__id = $brandid");
  777.                 } elseif($coll->getId() == 285) {
  778.                     $products->setCondition("`o_key` LIKE \"% Avi %\" AND brand__id = $brandid");
  779.                 } else {
  780.                     $products->setCondition("`o_key` LIKE \"%$key%\" AND brand__id = $brandid");
  781.                 }
  782.                 
  783.                 $products->load();
  784.                 foreach($products as $product) {
  785.                     $cats $product->getCategories();
  786.                     if($cats) {
  787.                         if (!in_array($coll$catstrue)) {
  788.                             array_push($cats$coll);
  789.                         } 
  790.                     } else {
  791.                         array_push($cats$coll);
  792.                     }
  793.                    
  794.                     $product->setCategories($cats);
  795.                     $product->save();
  796.                 }
  797.                 
  798.             }
  799.             echo "Brand: " $brand->getName() . " done <br><hr><br>";
  800.         }
  801.             exit;
  802.         
  803.         // foreach($brands as $brand) {
  804.         //     $collections = new DataObject\Category\Listing();
  805.         //     $collections->setCondition("o_path LIKE :brand", ["brand" => "%".$brand->getName()."%"]);
  806.         //     $collections->load();
  807.         // 
  808.         //     foreach($collections as $coll) {
  809.         //         $key = $coll->getKey();
  810.         //         $products = new DataObject\Product\Listing();
  811.         //         if($brand->getName() == "A. Lange & Söhne") {
  812.         //             $products->setCondition("UPPER(`o_key`) LIKE '%$key%'");
  813.         //         } else {
  814.         //             $products->setCondition("`o_key` LIKE '%$key%'");
  815.         //         }
  816.         //         $products->load();
  817.         //         foreach($products as $product) {
  818.         //             $cats = $product->getCategories();
  819.         //             if (!in_array($coll, $cats)) {
  820.         //                 array_push($cats, $coll);
  821.         //             }
  822.         //             $product->setCategories($cats);
  823.         //             $product->save();
  824.         //         }
  825.         //         
  826.         //     }
  827.         //     echo "Brand: " . $brand->getName() . " done <br><hr><br>";
  828.         // }
  829.         
  830.         
  831.     
  832.         exit;
  833.         return [];
  834.     }
  835.     
  836.     /**
  837.      * @Template
  838.      * @param Request $request
  839.      * @return array
  840.      */
  841.     public function testAction(Request $request) {
  842.         
  843.         ini_set('memory_limit''1024M');
  844.         $listing = new \Pimcore\Model\Document\Listing();
  845.         $listing $listing->load();
  846.         
  847.         foreach($listing as $doc) {
  848.             $key $doc->getKey();
  849.             $key str_replace(" ""-"$key);
  850.             $doc->setKey($key);
  851.             $doc->save();
  852.         }
  853.         
  854.         exit;
  855.        //  $brands = new DataObject\Product\Listing();
  856.        // 
  857.        //  
  858.        //  $brands->setCondition("o_path LIKE '%Uhren%' AND o_modificationDate > 1667284831");
  859.        //  $brands->load();
  860.        //  
  861.        //  var_dump(count($brands));
  862.         
  863.         exit;
  864.         
  865.         return [];
  866.     }
  867.     
  868.     /**
  869.      * @Template
  870.      * @param Request $request
  871.      * @return array
  872.      */
  873.     public function importSingleProductAction(Request $request) {
  874.         $searchstring str_replace("/"""$request->get("searchstring"));
  875.         
  876.         
  877.         $servername "carat-dev.cp4unapazytb.eu-central-1.rds.amazonaws.com";
  878.         $username "atimis";
  879.         $password "gui8kknyzG";
  880.         $dbname "carat_100";
  881.         
  882.         // Create connection
  883.         $conn = new \mysqli($servername$username$password$dbname);
  884.         // Check connection
  885.         if ($conn->connect_error) {
  886.           die("Connection failed: " $conn->connect_error);
  887.         }
  888.         
  889.         $conn->set_charset("utf8mb4");
  890.         
  891.         $sql "SELECT DISTINCT article.`id`, article.`articleNumber`, article.`brand`, article.`category`, article.`productLine`, article.`subcategory`, item.`price` FROM `Article` article INNER JOIN `Item` item ON item.`article_id` = article.`id` WHERE article.articleNumber LIKE '%$searchstring%' AND article.`category` = 'Uhr' GROUP BY article.`articleNumber`;";
  892.         
  893.         $result $conn->query($sql);
  894.         
  895.         while($row $result->fetch_assoc()) {
  896.             $extId $row["id"];
  897.             
  898.             $prObject DataObject::getByPath("/PIM/01 Uhren/02 Produkte/" $row["brand"] . "/" $row["productLine"] . "-" $row["articleNumber"]);
  899.             
  900.             if($prObject) {
  901.                 $newObject $prObject;
  902.             } else {
  903.                 $newObject = new DataObject\Product(); 
  904.                 $newObject->setKey(\Pimcore\Model\Element\Service::getValidKey($row["productLine"] . "-" $row["articleNumber"], 'object'));
  905.                 
  906.                 $folder DataObject::getByPath("/PIM/01 Uhren/02 Produkte/" $row["brand"]);
  907.                 if($folder == null) {
  908.                     $folder = new DataObject\Folder(); 
  909.                     $folder->setKey(\Pimcore\Model\Element\Service::getValidKey($row["brand"], 'folder'));
  910.                     $folder->setParentId(61);
  911.                     $folder->save();
  912.                 }
  913.                 $parentId $folder->getId();
  914.                 
  915.                 $newObject->setParentId($parentId);
  916.             }
  917.             
  918.             $newObject->setModel($row["productLine"]);
  919.             $newObject->setArticleNumber($row["articleNumber"]);
  920.             $newObject->setExtId($row["id"]);
  921.             $newObject->setPrice($row["price"]);
  922.             //set brand
  923.             $brand $object DataObject::getByPath("/PIM/01 Uhren/01 Marken/" $row["brand"]);
  924.             $newObject->setBrand($brand);
  925.             
  926.             //set specifications
  927.             $items = new DataObject\Fieldcollection();
  928.             $specsql "SELECT name, value FROM `ArticleProperty` WHERE `article_id` = $extId;";
  929.             $specresult $conn->query($specsql);
  930.             
  931.             while($specrow $specresult->fetch_assoc()) {
  932.                 $item = new DataObject\Fieldcollection\Data\Specification();
  933.                 
  934.                 $item->setSpecKey($specrow["name"]);
  935.                 $item->setSpecValue($specrow["value"]);
  936.                 
  937.                 $items->add($item);
  938.             }
  939.         
  940.             $newObject->setSpecs($items);
  941.             
  942.             //set frontimage
  943.             $imagesql "SELECT src FROM `Image` WHERE `article_id` = $extId;";
  944.             $imageresult $conn->query($imagesql);
  945.             $assetfolderpath "/PIM/01 Uhren/02 Produkte/" $row["brand"] . "/" str_replace("/""-"$row["productLine"]) . "-" $row["articleNumber"];
  946.             Asset\Service::createFolderByPath($assetfolderpath);
  947.             
  948.             $counter 0;
  949.             $addImages = [];
  950.             while($imagerow $imageresult->fetch_assoc()) {
  951.                 $counter += 1;
  952.                 $newAsset = new \Pimcore\Model\Asset\Image();
  953.                 $newAsset->setFilename($imagerow["src"]);
  954.                 $newAsset->setData(file_get_contents("https://huebner.carat.solutions/carat/filedownload?fileName=" $imagerow["src"]));
  955.                 $newAsset->setParent(\Pimcore\Model\Asset::getByPath($assetfolderpath));
  956.                 
  957.                 $checkasset null;    
  958.                 $checkasset \Pimcore\Model\Asset::getByPath($assetfolderpath "/" $imagerow["src"]);
  959.                 
  960.                 if($checkasset) {
  961.                     $newAsset $checkasset;
  962.                 } else {
  963.                     $newAsset->save();
  964.                 }
  965.                 
  966.                 
  967.                 if($counter == 1) {
  968.                     $newObject->setFrontimage($newAsset);
  969.                 } else {
  970.                     array_push($addImages$newAsset);
  971.                 }
  972.             }
  973.             
  974.             if(count($addImages) > 0) {
  975.                 $newObject->setImages(new \Pimcore\Model\DataObject\Data\ImageGallery($addImages));
  976.             }
  977.             
  978.             
  979.             //set gender
  980.             $gendercat DataObject::getByPath("/PIM/01 Uhren/03 Kategorien/" $row["subcategory"]);
  981.             $cats = [$gendercat];
  982.             $newObject->setCategories($cats);
  983.             
  984.             $newObject->setPublished(true);
  985.             $newObject->save();
  986.             
  987.             echo "Produkt: " $row["productLine"] . "-" $row["articleNumber"] . " erfolgreich importiert";
  988.             
  989.             //var_dump($brand);
  990.         }
  991.         
  992.         $conn->close();
  993.         exit;
  994.     }
  995.     
  996.     /**
  997.      * @Template
  998.      * @param Request $request
  999.      * @return array
  1000.      */
  1001.     public function addJewelleryCatsAction(Request $request) {
  1002.         $products = new DataObject\Product\Listing();
  1003.         $products->setCondition("o_path LIKE '%Schmuck%'");
  1004.         $products->load();
  1005.         $i 0;
  1006.         
  1007.         foreach($products as $product) {
  1008.             $catstring $product->getCatstring();
  1009.             $categories = new DataObject\Category\Listing();
  1010.             $categories->setCondition("o_path LIKE '%02 Schmuck/03 Kategorien%' AND caratvalues LIKE '%$catstring%'");
  1011.             $categories->load();
  1012.             foreach($categories as $cat) {
  1013.                 $cats $product->getCategories();
  1014.                 if(is_array($cats)) {
  1015.                     if(!in_array($cat$cats)) {
  1016.                         $cats[] = $cat;
  1017.                     }
  1018.                 } else {
  1019.                     if(!in_array($cat$cats)) {
  1020.                         $cats = [];
  1021.                         $cats[] = $cat;
  1022.                     }
  1023.                 }
  1024.                 $product->setCategories($cats);
  1025.                 $product->save();
  1026.                 $i++;
  1027.             }
  1028.         }
  1029.         
  1030.         $brands = new DataObject\Brand\Listing();
  1031.         $brands->setCondition("o_path LIKE '%Schmuck%'");
  1032.         $brands->load();
  1033.         foreach($brands as $brand) {
  1034.             $collections $brand->getCollections();
  1035.             $collections $collections->getChildren();
  1036.             $brandid $brand->getId();
  1037.             
  1038.             foreach($collections as $coll) {
  1039.                 $key $coll->getKey();
  1040.                 
  1041.                 $products = new DataObject\Product\Listing();
  1042.                 $products->setCondition("`o_key` LIKE \"%$key%\" AND brand__id = $brandid AND o_path LIKE '%Schmuck%'");
  1043.                 
  1044.                 $products->load();
  1045.                 foreach($products as $product) {
  1046.                     $cats $product->getCategories();
  1047.                     if($cats) {
  1048.                         if (!in_array($coll$catstrue)) {
  1049.                             array_push($cats$coll);
  1050.                         } 
  1051.                     } else {
  1052.                         array_push($cats$coll);
  1053.                     }
  1054.                    
  1055.                     $product->setCategories($cats);
  1056.                     $product->save();
  1057.                 }
  1058.             }
  1059.         }
  1060.         
  1061.         //echo "done $i products";
  1062.         
  1063.         exit;
  1064.         return [];
  1065.     }
  1066.     
  1067.     /**
  1068.      * @Template
  1069.      * @param Request $request
  1070.      * @return array
  1071.      */
  1072.     public function importSingleJewelleryProductAction(Request $request) {
  1073.         $servername "carat-dev.cp4unapazytb.eu-central-1.rds.amazonaws.com";
  1074.             $username "atimis";
  1075.             $password "gui8kknyzG";
  1076.             $dbname "carat_100";
  1077.             
  1078.             // Create connection
  1079.             $conn = new \mysqli($servername$username$password$dbname);
  1080.             // Check connection
  1081.             if ($conn->connect_error) {
  1082.               die("Connection failed: " $conn->connect_error);
  1083.             }
  1084.             
  1085.             $conn->set_charset("utf8mb4");
  1086.             
  1087.         
  1088.             
  1089.             
  1090.             
  1091.             
  1092.             // FINAL QUERY
  1093.             
  1094.             $sql "SELECT DISTINCT article.`id`, article.`articleNumber`, article.`brand`, article.`category`, article.`productLine`, article.`subcategory`, item.`price`, item.`stockInputDate` FROM `Article` article INNER JOIN `Item` item ON item.`article_id` = article.`id` WHERE item.`sold` = 0 AND article.`category` = 'Schmuck' AND item.`webshop` = 'JA'";
  1095.             
  1096.             // END FINAL QUERY
  1097.             
  1098.             
  1099.            // $sql = "SELECT * FROM Article WHERE `brand` LIKE '%Lange%' LIMIT 10;";
  1100.             
  1101.             $result $conn->query($sql);
  1102.             
  1103.             // var_dump($result);
  1104.             // exit;
  1105.             
  1106.             while($row $result->fetch_assoc()) {
  1107.                 $extId $row["id"];
  1108.                 
  1109.                 $row array_map('trim'$row);
  1110.                 
  1111.                 $key \Pimcore\Model\Element\Service::getValidKey($row["productLine"] . "-" $row["articleNumber"], 'object');
  1112.                 
  1113.                 $prObject DataObject::getByPath("/PIM/02 Schmuck/02 Produkte/" $row["brand"] . "/" $key);
  1114.                 
  1115.                 
  1116.                 
  1117.                 if($prObject) {
  1118.                     $checkstring date('d-m-y');
  1119.                     //$checkstring .= 'manual';
  1120.                     if($prObject->getUpdateInfo() == $checkstring) {
  1121.                         continue;
  1122.                     }
  1123.                     $newObject $prObject;
  1124.                     $newObject->setupdateinfo($checkstring);
  1125.                 } else {
  1126.                     $newObject = new DataObject\Product(); 
  1127.                     $newObject->setKey($key);
  1128.                     $newObject->setupdateinfo($checkstring);
  1129.                     
  1130.                     // get Brand Folder ID
  1131.                     $folder DataObject::getByPath("/PIM/02 Schmuck/02 Produkte/" $row["brand"]);
  1132.                     
  1133.                     // if($row["brand"] == "Jaeger-LeCoultre") {
  1134.                     //     $folder = DataObject::getById(396);
  1135.                     // }
  1136.                     if($row["brand"] == "FOPE") {
  1137.                         $folder DataObject::getById(3160);
  1138.                     }
  1139.                     if($row["brand"] == "Aldusblatt Herzog Loibner") {
  1140.                         $folder DataObject::getById(1712);
  1141.                     }
  1142.                     
  1143.                     if($folder == null) {
  1144.                         $folder = new DataObject\Folder(); 
  1145.                         $folder->setKey(\Pimcore\Model\Element\Service::getValidKey($row["brand"], 'folder'));
  1146.                         $folder->setParentId(64);
  1147.                         $folder->save();
  1148.                     }
  1149.                     $parentId $folder->getId();
  1150.                     
  1151.                     $newObject->setParentId($parentId);
  1152.                 }
  1153.                 
  1154.                 $newObject->setModel($row["productLine"]);
  1155.                 $newObject->setArticleNumber($row["articleNumber"]);
  1156.                 $newObject->setStockInputDate($row["stockInputDate"]);
  1157.                 $newObject->setExtId($row["id"]);
  1158.                 $newObject->setPrice($row["price"]);
  1159.                 $newObject->setCatstring($row["subcategory"]);
  1160.                 
  1161.                 //set brand
  1162.                 $brand DataObject::getByPath("/PIM/02 Schmuck/01 Marken/" $row["brand"]);
  1163.                 // if($row["brand"] == "Jaeger-LeCoultre") {
  1164.                 //     $brand = DataObject\Brand::getById(23);
  1165.                 // }
  1166.                 if($row["brand"] == "FOPE") {
  1167.                     $brand DataObject::getById(3201);
  1168.                 }
  1169.                 if($row["brand"] == "Aldusblatt Herzog Loibner") {
  1170.                     $brand DataObject::getById(99);
  1171.                 }
  1172.                 $newObject->setBrand($brand);
  1173.                 
  1174.                 //set specifications
  1175.                 $items = new DataObject\Fieldcollection();
  1176.                 $specsql "SELECT carat, label, number, description FROM `GemItem` WHERE `article_id` = $extId;";
  1177.                 $specresult $conn->query($specsql);
  1178.                 
  1179.                 while($specrow $specresult->fetch_assoc()) {
  1180.                     $item = new DataObject\Fieldcollection\Data\JewellerySpecification();
  1181.                     
  1182.                     $item->setSpecKey($specrow["label"]);
  1183.                     $item->setSpecValue($specrow["carat"]);
  1184.                     $item->setSpecCount($specrow["number"]);
  1185.                     $item->setSpecDescription($specrow["description"]);                    
  1186.                     $items->add($item);
  1187.                 }
  1188.                 
  1189.                 $specsql "SELECT name, value FROM `ArticleProperty` WHERE `article_id` = $extId;";
  1190.                 $specresult $conn->query($specsql);
  1191.                 
  1192.                 while($specrow $specresult->fetch_assoc()) {
  1193.                     $item = new DataObject\Fieldcollection\Data\JewellerySpecification();
  1194.                     
  1195.                     $item->setSpecKey($specrow["name"]);
  1196.                     $item->setSpecValue($specrow["value"]);
  1197.                     $item->setSpecCount(null);
  1198.                     $item->setSpecDescription(null);                    
  1199.                     $items->add($item);
  1200.                 }
  1201.         
  1202.                 $newObject->setSpecs($items);
  1203.                 
  1204.                 //set frontimage
  1205.                 $imagesql "SELECT src FROM `Image` WHERE `article_id` = $extId;";
  1206.                 $imageresult $conn->query($imagesql);
  1207.                 $articlenumber str_replace("/""-"$row["articleNumber"]);
  1208.                 $assetfolderpath "/PIM/02 Schmuck/02 Produkte/" $row["brand"] . "/" str_replace(["/"'"'"+"], ["-"""""], $row["productLine"]) . "-" $articlenumber;
  1209.                 $assetfolderpath str_replace("+"""$assetfolderpath);
  1210.                 $assetfolderpath str_replace("."""$assetfolderpath);
  1211.                 $assetfolderpath str_replace("|"""$assetfolderpath);
  1212.                 $assetfolderpath str_replace("Ăź""ss"$assetfolderpath);
  1213.                 Asset\Service::createFolderByPath($assetfolderpath);
  1214.                 
  1215.                 $counter 0;
  1216.                 $addImages = [];
  1217.                 while($imagerow $imageresult->fetch_assoc()) {
  1218.                     $counter += 1;
  1219.                     $newAsset = new \Pimcore\Model\Asset\Image();
  1220.                     $newAsset->setFilename($imagerow["src"]);
  1221.                     $newAsset->setData(file_get_contents("https://huebner.carat.solutions/carat/filedownload?fileName=" $imagerow["src"]));
  1222.                     $newAsset->setParent(\Pimcore\Model\Asset::getByPath($assetfolderpath));
  1223.                     
  1224.                     $checkasset null;    
  1225.                     $checkasset \Pimcore\Model\Asset::getByPath($assetfolderpath "/" $imagerow["src"]);
  1226.                     
  1227.                     echo "trying to save asset for " $row["productLine"] . "-" $row["articleNumber"] . "<br><hr><br>";
  1228.                     
  1229.                     if(strpos($imagerow["src"], "html") == false && strpos($imagerow["src"], "avif") == false && $imagerow["src"] != "7281fa99-3001-41a5-9be1-8dcfe04d997b.") {
  1230.                         if($checkasset) {
  1231.                             $checkasset->delete();
  1232.                             $newAsset->save();
  1233.                         } else {
  1234.                             $newAsset->save();
  1235.                         }
  1236.                     }
  1237.                     if($counter == 1) {
  1238.                         $newObject->setFrontimage($newAsset);
  1239.                     } else {
  1240.                         $advancedImage = new \Pimcore\Model\DataObject\Data\Hotspotimage();
  1241.                         $advancedImage->setImage($newAsset);
  1242.                         array_push($addImages$advancedImage);
  1243.                     }
  1244.                 }
  1245.                 
  1246.                 if(count($addImages) > 0) {   
  1247.                     $newObject->setImages(new \Pimcore\Model\DataObject\Data\ImageGallery($addImages));
  1248.                 }
  1249.                 
  1250.                 //var_dump($addImages);
  1251.                 
  1252.                 
  1253.                 //set gender
  1254.                 // $gendercat = DataObject::getByPath("/PIM/01 Uhren/03 Kategorien/" . $row["subcategory"]);
  1255.                 // if(!$gendercat) {
  1256.                 //     $newcat = new DataObject\Category(); 
  1257.                 //     $newcat->setKey(\Pimcore\Model\Element\Service::getValidKey($row["subcategory"], 'object'));
  1258.                 //     $newcat->setParentId(101);
  1259.                 //     $newcat->setTitle($row["subcategory"]);
  1260.                 //     $newcat->setPublished(true);
  1261.                 //     $newcat->save();
  1262.                 //     $gendercat = $newcat;
  1263.                 // }
  1264.                 
  1265.                 // $cats = [$gendercat];
  1266.                 // $newObject->setCategories($cats);
  1267.                 
  1268.                 $newObject->setPublished(true);
  1269.                 $newObject->save();
  1270.                 
  1271.                 //var_dump($brand);
  1272.             }
  1273.             
  1274.             $conn->close();
  1275.             
  1276.             
  1277.             exit;
  1278.             return [];
  1279.     }
  1280.     
  1281.     /**
  1282.      * @Template
  1283.      * @param Request $request
  1284.      * @return array
  1285.      */
  1286.     public function updateProductAction(Request $request) {
  1287.         
  1288.         $id str_replace("/"""$request->get("caratid"));
  1289.         $pimId str_replace("/"""$request->get("pimid"));
  1290.         
  1291.         $servername "carat-dev.cp4unapazytb.eu-central-1.rds.amazonaws.com";
  1292.         //$servername = "52.29.59.182";
  1293.         $username "atimis";
  1294.         $password "gui8kknyzG";
  1295.         $dbname "carat_100";
  1296.         
  1297.         // Create connection
  1298.         $conn = new \mysqli($servername$username$password$dbname);
  1299.         // Check connection
  1300.         if ($conn->connect_error) {
  1301.           die("Connection failed: " $conn->connect_error);
  1302.         }
  1303.         
  1304.         
  1305.         $conn->set_charset("utf8mb4");
  1306.         
  1307.         // FINAL QUERY
  1308.         
  1309.         $sql "SELECT DISTINCT article.`id`, article.`articleNumber`, article.`brand`, article.`category`, article.`productLine`, article.`subcategory`, item.`price`, item.`stockInputDate` FROM `Article` article INNER JOIN `Item` item ON item.`article_id` = article.`id` WHERE article.`id` = $id GROUP BY article.`articleNumber`";
  1310.         
  1311.         // END FINAL QUERY
  1312.         
  1313.         
  1314.        // $sql = "SELECT * FROM Article WHERE `brand` LIKE '%Lange%' LIMIT 10;";
  1315.         
  1316.         $result $conn->query($sql);
  1317.         
  1318.         // var_dump($result);
  1319.         // exit;
  1320.         
  1321.         while($row $result->fetch_assoc()) {
  1322.             $extId $row["id"];
  1323.             $row array_map('trim'$row);
  1324.             
  1325.             $watchjewel $row["category"];
  1326.             
  1327.             if($watchjewel == "Uhr") {
  1328.                 $key \Pimcore\Model\Element\Service::getValidKey($row["productLine"] . "-" $row["articleNumber"], 'object');
  1329.                 
  1330.                 $prObject DataObject::getById($pimId);
  1331.                 $checkstring date('d-m-y');
  1332.             //$checkstring .= 'manual';
  1333.                 // $checkstring .= "-zenith";
  1334.                 if($prObject) {
  1335.                     // if($prObject->getUpdateinfo() == "291122-try1" || $prObject->getUpdateinfo() == "291122-try2" || $prObject->getUpdateinfo() == "291122-try3" || $prObject->getUpdateinfo() == "291122-try4") {
  1336.                     //     continue;
  1337.                     // }
  1338.                     
  1339.                     
  1340.                     if($prObject->getUpdateInfo() == $checkstring) {
  1341.                         //continue;
  1342.                     }
  1343.                     $newObject $prObject;
  1344.                     $newObject->setupdateinfo($checkstring);
  1345.                 } else {
  1346.                     $newObject = new DataObject\Product(); 
  1347.                     $newObject->setKey($key);
  1348.                     $newObject->setupdateinfo($checkstring);
  1349.                     
  1350.                     // get Brand Folder ID
  1351.                     $folder DataObject::getByPath("/PIM/01 Uhren/02 Produkte/" $row["brand"]);
  1352.                     
  1353.                     if($row["brand"] == "Jaeger-LeCoultre") {
  1354.                         $folder DataObject::getById(396);
  1355.                     }
  1356.                     if($row["brand"] == "IWC") {
  1357.                         $folder DataObject::getById(962);
  1358.                     }
  1359.                     if($row["brand"] == "Nomos GlashĂĽtte") {
  1360.                         $folder DataObject::getById(407);
  1361.                     }
  1362.                     
  1363.                     if($folder == null) {
  1364.                         $folder = new DataObject\Folder(); 
  1365.                         $folder->setKey(\Pimcore\Model\Element\Service::getValidKey($row["brand"], 'folder'));
  1366.                         $folder->setParentId(61);
  1367.                         $folder->save();
  1368.                     }
  1369.                     $parentId $folder->getId();
  1370.                     
  1371.                     $newObject->setParentId($parentId);
  1372.                 }
  1373.                 
  1374.                 $newObject->setModel($row["productLine"]);
  1375.                 $newObject->setArticleNumber($row["articleNumber"]);
  1376.                 $newObject->setStockInputDate($row["stockInputDate"]);
  1377.                 $newObject->setExtId($row["id"]);
  1378.                 $newObject->setPrice($row["price"]);
  1379.                 
  1380.                 //set brand
  1381.                 $brand DataObject::getByPath("/PIM/01 Uhren/01 Marken/" $row["brand"]);
  1382.                 if($row["brand"] == "Jaeger-LeCoultre") {
  1383.                     $brand DataObject\Brand::getById(23);
  1384.                 }
  1385.                 if($row["brand"] == "IWC") {
  1386.                     $brand DataObject\Brand::getById(82);
  1387.                 }
  1388.                 if($row["brand"] == "Nomos GlashĂĽtte") {
  1389.                     $brand DataObject\Brand::getById(85);
  1390.                 }
  1391.                 if($row["brand"] == "Sattler") {
  1392.                     $brand DataObject\Brand::getById(77);
  1393.                 }
  1394.                 $newObject->setBrand($brand);
  1395.                 
  1396.                 //set specifications
  1397.                 $items = new DataObject\Fieldcollection();
  1398.                 $specsql "SELECT name, value FROM `ArticleProperty` WHERE `article_id` = $extId;";
  1399.                 $specresult $conn->query($specsql);
  1400.                 
  1401.                 while($specrow $specresult->fetch_assoc()) {
  1402.                     $item = new DataObject\Fieldcollection\Data\Specification();
  1403.                     
  1404.                     $item->setSpecKey($specrow["name"]);
  1405.                     $item->setSpecValue($specrow["value"]);
  1406.                     
  1407.                     $items->add($item);
  1408.                 }
  1409.                 
  1410.                 $newObject->setSpecs($items);
  1411.                 
  1412.                 //set frontimage
  1413.                 $imagesql "SELECT src FROM `Image` WHERE `article_id` = $extId;";
  1414.                 $imageresult $conn->query($imagesql);
  1415.                 $articlenumber str_replace("/""-"$row["articleNumber"]);
  1416.                 $assetfolderpath "/PIM/01 Uhren/02 Produkte/" $row["brand"] . "/" str_replace(["/"'"'"+"], ["-"""""], $row["productLine"]) . "-" $articlenumber;
  1417.                 $assetfolderpath str_replace("+"""$assetfolderpath);
  1418.                 $assetfolderpath str_replace("."""$assetfolderpath);
  1419.                 $assetfolderpath str_replace("|"""$assetfolderpath);
  1420.                 $assetfolderpath str_replace("Ăź""ss"$assetfolderpath);
  1421.                 Asset\Service::createFolderByPath($assetfolderpath);
  1422.                 
  1423.                 $counter 0;
  1424.                 $addImages = [];
  1425.                 while($imagerow $imageresult->fetch_assoc()) {
  1426.                     $counter += 1;
  1427.                     $newAsset = new \Pimcore\Model\Asset\Image();
  1428.                     $newAsset->setFilename($imagerow["src"]);
  1429.                     $newAsset->setData(file_get_contents("https://huebner.carat.solutions/carat/filedownload?fileName=" $imagerow["src"]));
  1430.                     $newAsset->setParent(\Pimcore\Model\Asset::getByPath($assetfolderpath));
  1431.                     
  1432.                     $checkasset null;    
  1433.                     $checkasset \Pimcore\Model\Asset::getByPath($assetfolderpath "/" $imagerow["src"]);
  1434.                     
  1435.                     //echo "trying to save asset for " . $row["productLine"] . "-" . $row["articleNumber"] . "<br><hr><br>";
  1436.                     
  1437.                     if(strpos($imagerow["src"], "html") == false && strpos($imagerow["src"], "avif") == false && $imagerow["src"] != "7281fa99-3001-41a5-9be1-8dcfe04d997b.") {
  1438.                         if($checkasset) {
  1439.                            $checkasset->delete();
  1440.                            $newAsset->save();
  1441.                         } else {
  1442.                             // var_dump($newAsset->getFullPath());
  1443.                             // var_dump($assetfolderpath);
  1444.                             // var_dump(\Pimcore\Model\Asset::getByPath($assetfolderpath));
  1445.                             // exit;
  1446.                             $newAsset->save();
  1447.                         }
  1448.                     }
  1449.                     if($counter == 1) {
  1450.                         $newObject->setFrontimage($newAsset);
  1451.                     } else {
  1452.                         $advancedImage = new \Pimcore\Model\DataObject\Data\Hotspotimage();
  1453.                         $advancedImage->setImage($newAsset);
  1454.                         array_push($addImages$advancedImage);
  1455.                     }
  1456.                 }
  1457.                 
  1458.                 if(count($addImages) > 0) {   
  1459.                     $newObject->setImages(new \Pimcore\Model\DataObject\Data\ImageGallery($addImages));
  1460.                 }
  1461.                 
  1462.                 //var_dump($addImages);
  1463.                 
  1464.                 
  1465.                 //set gender
  1466.                 $gendercat DataObject::getByPath("/PIM/01 Uhren/03 Kategorien/" $row["subcategory"]);
  1467.                 if(!$gendercat) {
  1468.                     $newcat = new DataObject\Category(); 
  1469.                     $newcat->setKey(\Pimcore\Model\Element\Service::getValidKey($row["subcategory"], 'object'));
  1470.                     $newcat->setParentId(101);
  1471.                     $newcat->setTitle($row["subcategory"]);
  1472.                     $newcat->setPublished(true);
  1473.                     $newcat->save();
  1474.                     $gendercat $newcat;
  1475.                 }
  1476.                 
  1477.                 $cats = [$gendercat];
  1478.                 $newObject->setCategories($cats);
  1479.                 
  1480.                 $newObject->setPublished(true);
  1481.                 $newObject->save();
  1482.                 
  1483.                 $this->addBrandCollections($brand);
  1484.                 
  1485.             } elseif($watchjewel == "Schmuck") {
  1486.                
  1487.                 $key \Pimcore\Model\Element\Service::getValidKey($row["productLine"] . "-" $row["articleNumber"], 'object');
  1488.                 
  1489.                 $prObject DataObject::getById($pimId);
  1490.                 $checkstring date('d-m-y');
  1491.             //$checkstring .= 'manual';
  1492.                 // $checkstring .= "-zenith";
  1493.                 if($prObject) {
  1494.                     // if($prObject->getUpdateinfo() == "291122-try1" || $prObject->getUpdateinfo() == "291122-try2" || $prObject->getUpdateinfo() == "291122-try3" || $prObject->getUpdateinfo() == "291122-try4") {
  1495.                     //     continue;
  1496.                     // }
  1497.                     
  1498.                     
  1499.                     if($prObject->getUpdateInfo() == $checkstring) {
  1500.                         //continue;
  1501.                     }
  1502.                     $newObject $prObject;
  1503.                     $newObject->setupdateinfo($checkstring);
  1504.                 } else {
  1505.                     $newObject = new DataObject\Product(); 
  1506.                     $newObject->setKey($key);
  1507.                     $newObject->setupdateinfo($checkstring);
  1508.                     
  1509.                     // get Brand Folder ID
  1510.                     $folder DataObject::getByPath("/PIM/02 Schmuck/02 Produkte/" $row["brand"]);
  1511.                     
  1512.                     if($folder == null) {
  1513.                         $folder = new DataObject\Folder(); 
  1514.                         $folder->setKey(\Pimcore\Model\Element\Service::getValidKey($row["brand"], 'folder'));
  1515.                         $folder->setParentId(64);
  1516.                         $folder->save();
  1517.                     }
  1518.                     $parentId $folder->getId();
  1519.                     
  1520.                     $newObject->setParentId($parentId);
  1521.                 }
  1522.                 
  1523.                 $newObject->setModel($row["productLine"]);
  1524.                 $newObject->setArticleNumber($row["articleNumber"]);
  1525.                 $newObject->setStockInputDate($row["stockInputDate"]);
  1526.                 $newObject->setExtId($row["id"]);
  1527.                 $newObject->setPrice($row["price"]);
  1528.                 
  1529.                 //set brand
  1530.                 $brand DataObject::getByPath("/PIM/02 Schmuck/01 Marken/" $row["brand"]);
  1531.                 if($row["brand"] == "Jaeger-LeCoultre") {
  1532.                     $brand DataObject\Brand::getById(23);
  1533.                 }
  1534.                 if($row["brand"] == "IWC") {
  1535.                     $brand DataObject\Brand::getById(82);
  1536.                 }
  1537.                 if($row["brand"] == "Nomos GlashĂĽtte") {
  1538.                     $brand DataObject\Brand::getById(85);
  1539.                 }
  1540.                 if($row["brand"] == "Sattler") {
  1541.                     $brand DataObject\Brand::getById(77);
  1542.                 }
  1543.                 $newObject->setBrand($brand);
  1544.                 
  1545.                 //set specifications
  1546.                 $items = new DataObject\Fieldcollection();
  1547.                 $specsql "SELECT name, value FROM `ArticleProperty` WHERE `article_id` = $extId;";
  1548.                 $specresult $conn->query($specsql);
  1549.                 
  1550.                 while($specrow $specresult->fetch_assoc()) {
  1551.                     $item = new DataObject\Fieldcollection\Data\Specification();
  1552.                     
  1553.                     $item->setSpecKey($specrow["name"]);
  1554.                     $item->setSpecValue($specrow["value"]);
  1555.                     
  1556.                     $items->add($item);
  1557.                 }
  1558.                 
  1559.                 $newObject->setSpecs($items);
  1560.                 
  1561.                 //set frontimage
  1562.                 $imagesql "SELECT src FROM `Image` WHERE `article_id` = $extId;";
  1563.                 $imageresult $conn->query($imagesql);
  1564.                 $articlenumber str_replace("/""-"$row["articleNumber"]);
  1565.                 $assetfolderpath "/PIM/02 Schmuck/02 Produkte/" $row["brand"] . "/" str_replace(["/"'"'"+"], ["-"""""], $row["productLine"]) . "-" $articlenumber;
  1566.                 $assetfolderpath str_replace("+"""$assetfolderpath);
  1567.                 $assetfolderpath str_replace("."""$assetfolderpath);
  1568.                 $assetfolderpath str_replace("|"""$assetfolderpath);
  1569.                 $assetfolderpath str_replace("Ăź""ss"$assetfolderpath);
  1570.                 Asset\Service::createFolderByPath($assetfolderpath);
  1571.                 
  1572.                 $counter 0;
  1573.                 $addImages = [];
  1574.                 while($imagerow $imageresult->fetch_assoc()) {
  1575.                     $counter += 1;
  1576.                     $newAsset = new \Pimcore\Model\Asset\Image();
  1577.                     $newAsset->setFilename($imagerow["src"]);
  1578.                     $newAsset->setData(file_get_contents("https://huebner.carat.solutions/carat/filedownload?fileName=" $imagerow["src"]));
  1579.                     $newAsset->setParent(\Pimcore\Model\Asset::getByPath($assetfolderpath));
  1580.                     
  1581.                     $checkasset null;    
  1582.                     $checkasset \Pimcore\Model\Asset::getByPath($assetfolderpath "/" $imagerow["src"]);
  1583.                     
  1584.                     //echo "trying to save asset for " . $row["productLine"] . "-" . $row["articleNumber"] . "<br><hr><br>";
  1585.                     
  1586.                     if(strpos($imagerow["src"], "html") == false && strpos($imagerow["src"], "avif") == false && $imagerow["src"] != "7281fa99-3001-41a5-9be1-8dcfe04d997b.") {
  1587.                         if($checkasset) {
  1588.                            $checkasset->delete();
  1589.                            $newAsset->save();
  1590.                         } else {
  1591.                             // var_dump($newAsset->getFullPath());
  1592.                             // var_dump($assetfolderpath);
  1593.                             // var_dump(\Pimcore\Model\Asset::getByPath($assetfolderpath));
  1594.                             // exit;
  1595.                             $newAsset->save();
  1596.                         }
  1597.                     }
  1598.                     if($counter == 1) {
  1599.                         $newObject->setFrontimage($newAsset);
  1600.                     } else {
  1601.                         $advancedImage = new \Pimcore\Model\DataObject\Data\Hotspotimage();
  1602.                         $advancedImage->setImage($newAsset);
  1603.                         array_push($addImages$advancedImage);
  1604.                     }
  1605.                 }
  1606.                 
  1607.                 if(count($addImages) > 0) {   
  1608.                     $newObject->setImages(new \Pimcore\Model\DataObject\Data\ImageGallery($addImages));
  1609.                 }
  1610.                 
  1611.                 //var_dump($addImages);
  1612.                 
  1613.                 
  1614.                 //set gender
  1615.                 // $gendercat = DataObject::getByPath("/PIM/01 Uhren/03 Kategorien/" . $row["subcategory"]);
  1616.                 // if(!$gendercat) {
  1617.                 //     $newcat = new DataObject\Category(); 
  1618.                 //     $newcat->setKey(\Pimcore\Model\Element\Service::getValidKey($row["subcategory"], 'object'));
  1619.                 //     $newcat->setParentId(101);
  1620.                 //     $newcat->setTitle($row["subcategory"]);
  1621.                 //     $newcat->setPublished(true);
  1622.                 //     $newcat->save();
  1623.                 //     $gendercat = $newcat;
  1624.                 // }
  1625.                 // 
  1626.                 // $cats = [$gendercat];
  1627.                 // $newObject->setCategories($cats);
  1628.                 
  1629.                 $newObject->setPublished(true);
  1630.                 $newObject->save();
  1631.                 
  1632.                 $this->addBrandCollections($brand);
  1633.             }
  1634.             
  1635.             
  1636.             
  1637.             //var_dump($brand);
  1638.         }
  1639.         
  1640.         $conn->close();
  1641.         
  1642.         echo "success";
  1643.         
  1644.         exit;
  1645.         return [];
  1646.     }
  1647.     
  1648.     /**
  1649.      * @Template
  1650.      * @param Request $request
  1651.      * @return array
  1652.      */
  1653.     public function importAction(Request $request) {
  1654.         
  1655.         //$servername = "carat-dev.cp4unapazytb.eu-central-1.rds.amazonaws.com";
  1656.         $servername "91.108.184.107";
  1657.         
  1658.         //$username = "atimis";
  1659.         $username "phillip_script";
  1660.         
  1661.         //$password = "gui8kknyzG";
  1662.         $password "CCarat22PentLaks";
  1663.         
  1664.         $dbname "carat_100";
  1665.         //$dbname = null;
  1666.         
  1667.         
  1668.         
  1669.         // Create connection
  1670.         $conn = new \mysqli($servername$username$password$dbname3306);
  1671.         // Check connection
  1672.         
  1673.       
  1674.      
  1675.         
  1676.         if ($conn->connect_error) {
  1677.           die("Connection failed: " $conn->connect_error);
  1678.         }
  1679.         
  1680.         
  1681.         
  1682.         
  1683.         $conn->set_charset("utf8mb4");
  1684.         
  1685.         
  1686.         //$sql = "SELECT * FROM Article LIMIT 10";
  1687.         
  1688.         // $sql = "SELECT DISTINCT article.`id`, article.`articleNumber`, article.`brand`, article.`category`, article.`productLine`, article.`subcategory`, item.`price` FROM `Article` article INNER JOIN `Item` item ON item.`article_id` = article.`id` WHERE article.brand = 'A. Lange & Söhne' AND item.`sold` = 0 AND article.`category` = 'Uhr' GROUP BY article.`articleNumber` LIMIT 10;";
  1689.         
  1690.         // $sql ="SELECT DISTINCT article.`id`, article.`articleNumber`, article.`brand`, article.`category`, article.`productLine`, article.`subcategory`, item.`price` FROM `Article` article INNER JOIN `Item` item ON item.`article_id` = article.`id` WHERE item.`sold` = 0 AND article.`category` = 'Uhr' AND item.`webshop` = 'JA' GROUP BY article.`articleNumber` LIMIT 100 OFFSET 1099";
  1691.         
  1692.         // $sql ="SELECT DISTINCT article.`id`, article.`articleNumber`, article.`brand`, article.`category`, article.`productLine`, article.`subcategory`, item.`price` FROM `Article` article INNER JOIN `Item` item ON item.`article_id` = article.`id` WHERE item.`sold` = 0 AND article.`category` = 'Uhr' AND item.`webshop` = 'JA' AND article.`brand` = 'L\'Epee' GROUP BY article.`articleNumber`;";
  1693.         
  1694.         // fix " "
  1695.         
  1696.         // $sql = "SELECT DISTINCT article.`id`, article.`articleNumber`, article.`brand`, article.`category`, article.`productLine`, article.`subcategory`, item.`price` FROM `Article` article INNER JOIN `Item` item ON item.`article_id` = article.`id` WHERE item.`sold` = 0 AND article.`category` = 'Uhr' AND item.`webshop` = 'JA' AND article.`id` = 7450 GROUP BY article.`articleNumber`";
  1697.         
  1698.         // BRAND QUERY
  1699.         
  1700.         // $sql = "SELECT DISTINCT article.`id`, article.`articleNumber`, article.`brand`, article.`category`, article.`productLine`, article.`subcategory`, item.`price`, item.`stockInputDate` FROM `Article` article INNER JOIN `Item` item ON item.`article_id` = article.`id` WHERE item.`sold` = 0 AND article.`category` = 'Uhr' AND item.`webshop` = 'JA' AND article.`brand` LIKE '%GlashĂĽtte Original%' GROUP BY article.`articleNumber`";
  1701.         
  1702.         
  1703.         // FINAL QUERY
  1704.         
  1705.         $sql "SELECT DISTINCT article.`id`, article.`articleNumber`, article.`brand`, article.`category`, article.`productLine`, article.`subcategory`, item.`price`, item.`stockInputDate` FROM `Article` article INNER JOIN `Item` item ON item.`article_id` = article.`id` WHERE item.`sold` = 0 AND article.`category` = 'Uhr' AND item.`webshop` = 'JA' GROUP BY article.`articleNumber`";
  1706.         
  1707.         //$sql = "USE carat_100;";
  1708.         
  1709.         
  1710.         // $sql = "SELECT DISTINCT article.`id`, article.`articleNumber`, article.`brand`, article.`category`, article.`productLine`, article.`subcategory`, item.`price`, item.`stockInputDate` FROM `Article` article INNER JOIN `Item` item ON item.`article_id` = article.`id` WHERE item.`sold` = 0 AND article.`category` = 'Uhr' AND item.`webshop` = 'JA' AND article.`articleNumber` = 'SLGA025G' GROUP BY article.`articleNumber`";
  1711.         
  1712.         // END FINAL QUERY
  1713.         
  1714.         
  1715.         //$sql = "SELECT * FROM Article WHERE `brand` LIKE '%Lange%' LIMIT 10;";
  1716.         
  1717.         $result $conn->query("SET PERSIST sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));");
  1718.         //$result = $conn->query($sql);
  1719.         
  1720.         var_dump($result);
  1721.         var_dump(mysqli_error($conn));
  1722.         exit;
  1723.         
  1724.         //var_dump($result->fetch_assoc());
  1725.         
  1726.         while($row $result->fetch_assoc()) {
  1727.             var_dump($row);
  1728.         }
  1729.         exit;
  1730.         
  1731.         while($row $result->fetch_assoc()) {
  1732.             $extId $row["id"];
  1733.             $row array_map('trim'$row);
  1734.   
  1735.             
  1736.             $key \Pimcore\Model\Element\Service::getValidKey($row["productLine"] . "-" $row["articleNumber"], 'object');
  1737.             
  1738.             $prObject DataObject::getByPath("/PIM/01 Uhren/02 Produkte/" $row["brand"] . "/" $key);
  1739.             $checkstring date('d-m-y');
  1740.             //$checkstring .= 'manual';
  1741.             // $checkstring .= "-zenith";
  1742.             if($prObject) {
  1743.                 // if($prObject->getUpdateinfo() == "291122-try1" || $prObject->getUpdateinfo() == "291122-try2" || $prObject->getUpdateinfo() == "291122-try3" || $prObject->getUpdateinfo() == "291122-try4") {
  1744.                 //     continue;
  1745.                 // }
  1746.                 
  1747.                 
  1748.                 if($prObject->getUpdateInfo() == $checkstring) {
  1749.                     continue;
  1750.                 }
  1751.                 $newObject $prObject;
  1752.                 $newObject->setupdateinfo($checkstring);
  1753.             } else {
  1754.                 $newObject = new DataObject\Product(); 
  1755.                 $newObject->setKey($key);
  1756.                 $newObject->setupdateinfo($checkstring);
  1757.                 
  1758.                 // get Brand Folder ID
  1759.                 $folder DataObject::getByPath("/PIM/01 Uhren/02 Produkte/" $row["brand"]);
  1760.                 
  1761.                 if($row["brand"] == "Jaeger-LeCoultre") {
  1762.                     $folder DataObject::getById(396);
  1763.                 }
  1764.                 if($row["brand"] == "IWC") {
  1765.                     $folder DataObject::getById(962);
  1766.                 }
  1767.                 if($row["brand"] == "Nomos GlashĂĽtte") {
  1768.                     $folder DataObject::getById(407);
  1769.                 }
  1770.                 
  1771.                 if($folder == null) {
  1772.                     $folder = new DataObject\Folder(); 
  1773.                     $folder->setKey(\Pimcore\Model\Element\Service::getValidKey($row["brand"], 'folder'));
  1774.                     $folder->setParentId(61);
  1775.                     $folder->save();
  1776.                 }
  1777.                 $parentId $folder->getId();
  1778.                 
  1779.                 $newObject->setParentId($parentId);
  1780.             }
  1781.             
  1782.             $newObject->setModel($row["productLine"]);
  1783.             $newObject->setArticleNumber($row["articleNumber"]);
  1784.             $newObject->setStockInputDate($row["stockInputDate"]);
  1785.             $newObject->setExtId($row["id"]);
  1786.             $newObject->setPrice($row["price"]);
  1787.             
  1788.             //set brand
  1789.             $brand DataObject::getByPath("/PIM/01 Uhren/01 Marken/" $row["brand"]);
  1790.             if($row["brand"] == "Jaeger-LeCoultre") {
  1791.                 $brand DataObject\Brand::getById(23);
  1792.             }
  1793.             if($row["brand"] == "IWC") {
  1794.                 $brand DataObject\Brand::getById(82);
  1795.             }
  1796.             if($row["brand"] == "Nomos GlashĂĽtte") {
  1797.                 $brand DataObject\Brand::getById(85);
  1798.             }
  1799.             if($row["brand"] == "Sattler") {
  1800.                 $brand DataObject\Brand::getById(77);
  1801.             }
  1802.             $newObject->setBrand($brand);
  1803.             
  1804.             //set specifications
  1805.             $items = new DataObject\Fieldcollection();
  1806.             $specsql "SELECT name, value FROM `ArticleProperty` WHERE `article_id` = $extId;";
  1807.             $specresult $conn->query($specsql);
  1808.             
  1809.             while($specrow $specresult->fetch_assoc()) {
  1810.                 $item = new DataObject\Fieldcollection\Data\Specification();
  1811.                 
  1812.                 $item->setSpecKey($specrow["name"]);
  1813.                 $item->setSpecValue($specrow["value"]);
  1814.                 
  1815.                 $items->add($item);
  1816.             }
  1817.             $newObject->setSpecs($items);
  1818.             
  1819.             //set frontimage
  1820.             $imagesql "SELECT src FROM `Image` WHERE `article_id` = $extId;";
  1821.             $imageresult $conn->query($imagesql);
  1822.             $articlenumber str_replace("/""-"$row["articleNumber"]);
  1823.             $assetfolderpath "/PIM/01 Uhren/02 Produkte/" $row["brand"] . "/" str_replace(["/"'"'"+"], ["-"""""], $row["productLine"]) . "-" $articlenumber;
  1824.             $assetfolderpath str_replace("+"""$assetfolderpath);
  1825.             $assetfolderpath str_replace("."""$assetfolderpath);
  1826.             $assetfolderpath str_replace("|"""$assetfolderpath);
  1827.             $assetfolderpath str_replace("Ăź""ss"$assetfolderpath);
  1828.             Asset\Service::createFolderByPath($assetfolderpath);
  1829.             
  1830.             $counter 0;
  1831.             $addImages = [];
  1832.             while($imagerow $imageresult->fetch_assoc()) {
  1833.                 $counter += 1;
  1834.                 $newAsset = new \Pimcore\Model\Asset\Image();
  1835.                 $newAsset->setFilename($imagerow["src"]);
  1836.                 $newAsset->setData(file_get_contents("https://huebner.carat.solutions/carat/filedownload?fileName=" $imagerow["src"]));
  1837.                 $newAsset->setParent(\Pimcore\Model\Asset::getByPath($assetfolderpath));
  1838.                 
  1839.                 $checkasset null;    
  1840.                 $checkasset \Pimcore\Model\Asset::getByPath($assetfolderpath "/" $imagerow["src"]);
  1841.                 
  1842.                 echo "trying to save asset for " $row["productLine"] . "-" $row["articleNumber"] . "<br><hr><br>";
  1843.                 
  1844.                 if(strpos($imagerow["src"], "html") == false && strpos($imagerow["src"], "htm") == false && $imagerow["src"] != "7281fa99-3001-41a5-9be1-8dcfe04d997b.") {
  1845.                     if($checkasset) {
  1846.                        $checkasset->setData(file_get_contents("https://huebner.carat.solutions/carat/filedownload?fileName=" $imagerow["src"]));
  1847.                        $checkasset->save();
  1848.                        $newAsset $checkasset;
  1849.                     } else {
  1850.                         // var_dump($newAsset->getFullPath());
  1851.                         // var_dump($assetfolderpath);
  1852.                         // var_dump(\Pimcore\Model\Asset::getByPath($assetfolderpath));
  1853.                         // exit;
  1854.                         $newAsset->save();
  1855.                     }
  1856.                     $newAsset->save();
  1857.                 }
  1858.                 if($counter == 1) {
  1859.                     $newObject->setFrontimage($newAsset);
  1860.                 } else {
  1861.                     $advancedImage = new \Pimcore\Model\DataObject\Data\Hotspotimage();
  1862.                     $advancedImage->setImage($newAsset);
  1863.                     array_push($addImages$advancedImage);
  1864.                 }
  1865.             }
  1866.             
  1867.             if(count($addImages) > 0) {   
  1868.                 $newObject->setImages(new \Pimcore\Model\DataObject\Data\ImageGallery($addImages));
  1869.             }
  1870.             
  1871.             //var_dump($addImages);
  1872.             
  1873.             
  1874.             //set gender
  1875.             $gendercat DataObject::getByPath("/PIM/01 Uhren/03 Kategorien/" $row["subcategory"]);
  1876.             if(!$gendercat) {
  1877.                 $newcat = new DataObject\Category(); 
  1878.                 $newcat->setKey(\Pimcore\Model\Element\Service::getValidKey($row["subcategory"], 'object'));
  1879.                 $newcat->setParentId(101);
  1880.                 $newcat->setTitle($row["subcategory"]);
  1881.                 $newcat->setPublished(true);
  1882.                 $newcat->save();
  1883.                 $gendercat $newcat;
  1884.             }
  1885.             
  1886.             $cats = [$gendercat];
  1887.             $newObject->setCategories($cats);
  1888.             
  1889.             $newObject->setPublished(true);
  1890.             $newObject->save();
  1891.             
  1892.             //var_dump($brand);
  1893.         }
  1894.         
  1895.         $conn->close();
  1896.         
  1897.         
  1898.         exit;
  1899.         return [];
  1900.     }
  1901.     
  1902.     /**
  1903.      * @Template
  1904.      * @param Request $request
  1905.      * @return array
  1906.      */
  1907.     public function categoryAction(Request $request) {
  1908.         
  1909.         
  1910.         return [];
  1911.     }
  1912.     
  1913.     
  1914.     /**
  1915.      * @Template
  1916.      * @param Request $request
  1917.      * @return array
  1918.      */
  1919.     public function homeAction(Request $request) {
  1920.         return [];
  1921.     }
  1922.     
  1923.     /**
  1924.      * @Template
  1925.      * @param Request $request
  1926.      * @return array
  1927.      */
  1928.     public function newProductOverviewAction(Request $request) {
  1929.         if(isset($_COOKIE['zeitdebug'])) {
  1930.             $debug "true";
  1931.         } else {
  1932.             $debug "false";
  1933.         }
  1934.         $jewellerycategory null;
  1935.         $entries = new DataObject\Product\Listing();
  1936.         $filters = [];
  1937.         
  1938.         $page = isset($_GET["page"]) ? $_GET["page"] : 1;
  1939.         if($page) {
  1940.             $offset 24 * (intval($page) -1);
  1941.             $filters["page"] = $page;
  1942.         }
  1943.         
  1944.         $brandValues = new DataObject\Brand\Listing();
  1945.         $brandValues->setCondition('o_path LIKE "%Uhren%"');
  1946.         $brandValues->load();
  1947.         
  1948.         $collection = isset($_GET["collection"]) ? $_GET["collection"] : null;
  1949.         if($collection) {
  1950.             $entries->addConditionParam("categories LIKE ?""%object|$collection%""AND");
  1951.             $filters["collection"] = $collection;
  1952.         }
  1953.         
  1954.         $price = isset($_GET["price"]) ? $_GET["price"] : null;
  1955.         if($price) {
  1956.             switch ($price) {
  1957.                 case "until2500":
  1958.                     $grossPriceFrom 0;
  1959.                     $grossPriceTo 2500;
  1960.                     
  1961.                     $netPriceFrom 0.0;
  1962.                     $netPriceTo $grossPriceTo 1.2;
  1963.                     
  1964.                     $entries->addConditionParam("price < ?"$netPriceTo"AND");
  1965.                     break;
  1966.                     
  1967.                 case "from2500until5000":
  1968.                     $grossPriceFrom 2500;
  1969.                     $grossPriceTo 5000;
  1970.                     
  1971.                     $netPriceFrom $grossPriceFrom 1.2;
  1972.                     $netPriceTo $grossPriceTo 1.2;
  1973.                     
  1974.                     $entries->addConditionParam("price > ?"$netPriceFrom"AND");
  1975.                     $entries->addConditionParam("price < ?"$netPriceTo"AND");
  1976.                     break;
  1977.                 
  1978.                 case "from5000until10000":
  1979.                     $grossPriceFrom 5000;
  1980.                     $grossPriceTo 10000;
  1981.                     
  1982.                     $netPriceFrom $grossPriceFrom 1.2;
  1983.                     $netPriceTo $grossPriceTo 1.2;
  1984.                     
  1985.                     $entries->addConditionParam("price > ?"$netPriceFrom"AND");
  1986.                     $entries->addConditionParam("price < ?"$netPriceTo"AND");
  1987.                     break;
  1988.                 
  1989.                 case "from100000until150000":
  1990.                     $grossPriceFrom 10000;
  1991.                     $grossPriceTo 15000;
  1992.                     
  1993.                     $netPriceFrom $grossPriceFrom 1.2;
  1994.                     $netPriceTo $grossPriceTo 1.2;
  1995.                     
  1996.                     $entries->addConditionParam("price > ?"$netPriceFrom"AND");
  1997.                     $entries->addConditionParam("price < ?"$netPriceTo"AND");
  1998.                     break;
  1999.                 case "from15000until20000":
  2000.                     $grossPriceFrom 15000;
  2001.                     $grossPriceTo 20000;
  2002.                     
  2003.                     $netPriceFrom $grossPriceFrom 1.2;
  2004.                     $netPriceTo $grossPriceTo 1.2;
  2005.                     
  2006.                     $entries->addConditionParam("price > ?"$netPriceFrom"AND");
  2007.                     $entries->addConditionParam("price < ?"$netPriceTo"AND");
  2008.                     break;
  2009.                 case "from20000":
  2010.                     $grossPriceFrom 20000;
  2011.                     $netPriceFrom $grossPriceFrom 1.2;
  2012.                     
  2013.                     $entries->addConditionParam("price > ?"$netPriceFrom"AND");
  2014.                     break;
  2015.             }
  2016.             
  2017.             
  2018.             $filters["price"] = $price;
  2019.         }
  2020.         
  2021.         $type = isset($_GET["type"]) ? $_GET["type"] : null;
  2022.         if($type) {
  2023.             //$entries->addConditionParam("categories LIKE ?", "%object|$type%", "AND");
  2024.             $entries->setCondition("categories LIKE '%object|$type%'");
  2025.             $filters["type"] = $type;
  2026.         }
  2027.         
  2028.         $brand = isset($_GET["brand"]) ? $_GET["brand"] : null;
  2029.         if($brand) {
  2030.             $entries->addConditionParam("brand__id = ?""$brand""AND");
  2031.             $brandobject DataObject::getById($brand);
  2032.             $brandcollections $brandobject->getCollections() ? $brandobject->getCollections()->getChildren() : null;
  2033.             
  2034.             $filters["brand"] = $brand;
  2035.             $filters["brandCollections"] = $brandcollections;
  2036.         } 
  2037.         if (!$brand && $collection) {
  2038.             $collectionObject DataObject::getById($collection);
  2039.                 // var_dump($collection);
  2040.                 // exit;
  2041.             
  2042.             
  2043.             $collectionpath $collectionObject->getPath();
  2044.             // var_dump($collectionpath);
  2045.             // exit;
  2046.             if(str_contains($collectionpath"Schmuck")) {
  2047.                 
  2048.                 $entries->addConditionParam("o_path LIKE '%Schmuck%'""AND");
  2049.                 $jewellerycategory $collectionObject;
  2050.             } else {
  2051.                 $brandkey $collectionObject->getParent()->getKey();
  2052.                 
  2053.                 $brands DataObject\Brand::getByName($brandkey);
  2054.                 $brand $brands->load();
  2055.                 if(is_array($brand)) {
  2056.                     $brand $brand[0];
  2057.                     $brandobject $brand;
  2058.                     $brandcollections $brandobject->getCollections() ? $brandobject->getCollections()->getChildren() : null;
  2059.                     
  2060.                     $filters["brand"] = $brand->getId();
  2061.                     $filters["brandCollections"] = $brandcollections;
  2062.                 } else {
  2063.                     $brand null;
  2064.                     $filters["brand"] = null;
  2065.                     $filters["brandCollections"] = null;
  2066.                 }
  2067.             }
  2068.             
  2069.             
  2070.             
  2071.         }
  2072.         
  2073.         if(!isset($filters["brandCollections"])) {
  2074.             $brandCollections = new DataObject\Category\Listing();
  2075.             $brandCollections->setCondition("o_path LIKE '%Kollektionen%'");
  2076.             $brandCollections $brandCollections->load();
  2077.             $filters["brandCollections"] = $brandCollections;
  2078.         }
  2079.         
  2080.         $casematerial = isset($_GET["casematerial"]) ? $_GET["casematerial"] : null;
  2081.         if($casematerial) {
  2082.             $entries->addFieldCollection("Specification""specs");
  2083.             $entries->addConditionParam("`Specification~specs`.specKey = 'Gehäusematerial' AND `Specification~specs`.specValue LIKE ?""%$casematerial%""AND");
  2084.             $filters["casematerial"] = $casematerial;
  2085.         }
  2086.         
  2087.         $sort = isset($_GET["sort"]) ? $_GET["sort"] : null;
  2088.         if($sort) {
  2089.            switch($sort) {
  2090.                case "actual":
  2091.                    $entries->setOrderKey("stockInputDate");
  2092.                    $entries->setOrder("desc");
  2093.                    break;
  2094.                case "priceasc":
  2095.                    $entries->setOrderKey("price");
  2096.                    $entries->setOrder("asc");
  2097.                    break;
  2098.                 case "pricedesc":
  2099.                     $entries->setOrderKey("price");
  2100.                     $entries->setOrder("desc");
  2101.                     break;
  2102.                 case "name":
  2103.                     $entries->setOrderKey("model");
  2104.                     $entries->setOrder("asc");
  2105.                     break;
  2106.            }
  2107.            $filters["sort"] = $sort;
  2108.         } else {
  2109.             $entries->setOrderKey("stockInputDate");
  2110.             $entries->setOrder("desc");
  2111.             $filters["sort"] = "actual";
  2112.         }
  2113.         
  2114.         
  2115.         
  2116.        
  2117.         $entries->addConditionParam("brand__id IS NOT NULL""""AND");
  2118.         $entries->addConditionParam("o_path LIKE ?""%Uhren%""AND");
  2119.         $Countentries $entries->load();
  2120.         $entryCount count($Countentries);
  2121.         
  2122.         $limit 24;
  2123.         $entries->setLimit($limit);
  2124.         $entries->setOffset($offset);
  2125.         $entries $entries->load();
  2126.         
  2127.         return $this->render('/default/new_product_overview.html.twig', ["products" => $entries"filters" => $filters"jewellerycat" => $jewellerycategory"debug" => $debug'brandValues' => $brandValues"entryCount" => $entryCount]);
  2128.     
  2129.       
  2130.     }
  2131.     
  2132.     /**
  2133.      * @Template
  2134.      * @param Request $request
  2135.      * @return array
  2136.      */
  2137.     public function productOverviewAction(Request $request) {
  2138.         if(isset($_COOKIE['zeitdebug'])) {
  2139.             $debug "true";
  2140.         } else {
  2141.             $debug "false";
  2142.         }
  2143.         $jewellerycategory null;
  2144.         $entries = new DataObject\Product\Listing();
  2145.         $filters = [];
  2146.         
  2147.         $page = isset($_GET["page"]) ? $_GET["page"] : null;
  2148.         if($page) {
  2149.             if($page == 1) {
  2150.                 $entries->setLimit(24);
  2151.             }
  2152.             $filters["page"] = $page;
  2153.         }
  2154.         
  2155.         $collection = isset($_GET["collection"]) ? $_GET["collection"] : null;
  2156.         if($collection) {
  2157.             $entries->addConditionParam("categories LIKE ?""%object|$collection%""AND");
  2158.             $filters["collection"] = $collection;
  2159.         }
  2160.         
  2161.         $price = isset($_GET["price"]) ? $_GET["price"] : null;
  2162.         if($price) {
  2163.             switch ($price) {
  2164.                 case "until2500":
  2165.                     $grossPriceFrom 0;
  2166.                     $grossPriceTo 2500;
  2167.                     
  2168.                     $netPriceFrom 0.0;
  2169.                     $netPriceTo $grossPriceTo 1.2;
  2170.                     
  2171.                     $entries->addConditionParam("price < ?"$netPriceTo"AND");
  2172.                     break;
  2173.                     
  2174.                 case "from2500until5000":
  2175.                     $grossPriceFrom 2500;
  2176.                     $grossPriceTo 5000;
  2177.                     
  2178.                     $netPriceFrom $grossPriceFrom 1.2;
  2179.                     $netPriceTo $grossPriceTo 1.2;
  2180.                     
  2181.                     $entries->addConditionParam("price > ?"$netPriceFrom"AND");
  2182.                     $entries->addConditionParam("price < ?"$netPriceTo"AND");
  2183.                     break;
  2184.                 
  2185.                 case "from5000until10000":
  2186.                     $grossPriceFrom 5000;
  2187.                     $grossPriceTo 10000;
  2188.                     
  2189.                     $netPriceFrom $grossPriceFrom 1.2;
  2190.                     $netPriceTo $grossPriceTo 1.2;
  2191.                     
  2192.                     $entries->addConditionParam("price > ?"$netPriceFrom"AND");
  2193.                     $entries->addConditionParam("price < ?"$netPriceTo"AND");
  2194.                     break;
  2195.                 
  2196.                 case "from100000until150000":
  2197.                     $grossPriceFrom 10000;
  2198.                     $grossPriceTo 15000;
  2199.                     
  2200.                     $netPriceFrom $grossPriceFrom 1.2;
  2201.                     $netPriceTo $grossPriceTo 1.2;
  2202.                     
  2203.                     $entries->addConditionParam("price > ?"$netPriceFrom"AND");
  2204.                     $entries->addConditionParam("price < ?"$netPriceTo"AND");
  2205.                     break;
  2206.                 case "from15000until20000":
  2207.                     $grossPriceFrom 15000;
  2208.                     $grossPriceTo 20000;
  2209.                     
  2210.                     $netPriceFrom $grossPriceFrom 1.2;
  2211.                     $netPriceTo $grossPriceTo 1.2;
  2212.                     
  2213.                     $entries->addConditionParam("price > ?"$netPriceFrom"AND");
  2214.                     $entries->addConditionParam("price < ?"$netPriceTo"AND");
  2215.                     break;
  2216.                 case "from20000":
  2217.                     $grossPriceFrom 20000;
  2218.                     $netPriceFrom $grossPriceFrom 1.2;
  2219.                     
  2220.                     $entries->addConditionParam("price > ?"$netPriceFrom"AND");
  2221.                     break;
  2222.             }
  2223.             
  2224.             
  2225.             $filters["price"] = $price;
  2226.         }
  2227.         
  2228.         $type = isset($_GET["type"]) ? $_GET["type"] : null;
  2229.         if($type) {
  2230.             //$entries->addConditionParam("categories LIKE ?", "%object|$type%", "AND");
  2231.             $entries->setCondition("categories LIKE '%object|$type%'");
  2232.             $filters["type"] = $type;
  2233.         }
  2234.         
  2235.         $brand = isset($_GET["brand"]) ? $_GET["brand"] : null;
  2236.         if($brand) {
  2237.             $entries->addConditionParam("brand__id = ?""$brand""AND");
  2238.             $brandobject DataObject::getById($brand);
  2239.             $brandcollections $brandobject->getCollections() ? $brandobject->getCollections()->getChildren() : null;
  2240.             
  2241.             $filters["brand"] = $brand;
  2242.             $filters["brandCollections"] = $brandcollections;
  2243.         } 
  2244.         if (!$brand && $collection) {
  2245.             $collectionObject DataObject::getById($collection);
  2246.                 // var_dump($collection);
  2247.                 // exit;
  2248.             
  2249.             
  2250.             $collectionpath $collectionObject->getPath();
  2251.             // var_dump($collectionpath);
  2252.             // exit;
  2253.             if(str_contains($collectionpath"Schmuck")) {
  2254.                 
  2255.                 $entries->addConditionParam("o_path LIKE '%Schmuck%'""AND");
  2256.                 $jewellerycategory $collectionObject;
  2257.             } else {
  2258.                 $brandkey $collectionObject->getParent()->getKey();
  2259.                 
  2260.                 $brands DataObject\Brand::getByName($brandkey);
  2261.                 $brand $brands->load();
  2262.                 if(is_array($brand)) {
  2263.                     $brand $brand[0];
  2264.                     $brandobject $brand;
  2265.                     $brandcollections $brandobject->getCollections() ? $brandobject->getCollections()->getChildren() : null;
  2266.                     
  2267.                     $filters["brand"] = $brand->getId();
  2268.                     $filters["brandCollections"] = $brandcollections;
  2269.                 } else {
  2270.                     $brand null;
  2271.                     $filters["brand"] = null;
  2272.                     $filters["brandCollections"] = null;
  2273.                 }
  2274.             }
  2275.             
  2276.             
  2277.             
  2278.         }
  2279.         
  2280.         if(!isset($filters["brandCollections"])) {
  2281.             $brandCollections = new DataObject\Category\Listing();
  2282.             $brandCollections->setCondition("o_path LIKE '%Kollektionen%'");
  2283.             $brandCollections $brandCollections->load();
  2284.             $filters["brandCollections"] = $brandCollections;
  2285.         }
  2286.         
  2287.         $casematerial = isset($_GET["casematerial"]) ? $_GET["casematerial"] : null;
  2288.         if($casematerial) {
  2289.             $entries->addFieldCollection("Specification""specs");
  2290.             $entries->addConditionParam("`Specification~specs`.specKey = 'Gehäusematerial' AND `Specification~specs`.specValue LIKE ?""%$casematerial%""AND");
  2291.             $filters["casematerial"] = $casematerial;
  2292.         }
  2293.         
  2294.         $sort = isset($_GET["sort"]) ? $_GET["sort"] : null;
  2295.         if($sort) {
  2296.            switch($sort) {
  2297.                case "actual":
  2298.                    $entries->setOrderKey("stockInputDate");
  2299.                    $entries->setOrder("desc");
  2300.                    break;
  2301.                case "priceasc":
  2302.                    $entries->setOrderKey("price");
  2303.                    $entries->setOrder("asc");
  2304.                    break;
  2305.                 case "pricedesc":
  2306.                     $entries->setOrderKey("price");
  2307.                     $entries->setOrder("desc");
  2308.                     break;
  2309.                 case "name":
  2310.                     $entries->setOrderKey("model");
  2311.                     $entries->setOrder("asc");
  2312.                     break;
  2313.            }
  2314.            $filters["sort"] = $sort;
  2315.         } else {
  2316.             $entries->setOrderKey("stockInputDate");
  2317.             $entries->setOrder("desc");
  2318.             $filters["sort"] = "actual";
  2319.         }
  2320.         
  2321.         
  2322.         
  2323.         //var_dump($entries);
  2324.         
  2325.         $entries $entries->load();
  2326.         
  2327.        
  2328.        
  2329.         
  2330.         return $this->render('/default/product_overview.html.twig', ["products" => $entries"filters" => $filters"jewellerycat" => $jewellerycategory"debug" => $debug]);
  2331.    
  2332.       
  2333.     }
  2334.     
  2335.     /**
  2336.      * @Template
  2337.      * @param Request $request
  2338.      * @return array
  2339.      */
  2340.     public function brandsOverviewAction(Request $request) {
  2341.         $docpath $this->document->getFullPath();
  2342.         //var_dump($docpath);
  2343.         
  2344.         if(strpos($docpath"Uhren") !== false) {
  2345.             $path "Uhren";
  2346.         } else {
  2347.             $path "Schmuck";
  2348.         }
  2349.         
  2350.         
  2351.         $entries = new DataObject\Brand\Listing();
  2352.         $entries->setCondition("o_path LIKE '%$path%' ");
  2353.         $entries->setOrderKey("o_key");
  2354.         $entries->setOrder("ASC");
  2355.         $entries->load();
  2356.         
  2357.         return $this->render('/default/brands_overview.html.twig', ["brands" => $entries]);
  2358.     }
  2359.     
  2360.     /**
  2361.      * @Template
  2362.      * @param Request $request
  2363.      * @return array
  2364.      */
  2365.     public function teaserOverviewAction(Request $request) {
  2366.         return [];
  2367.     }
  2368.     
  2369.     /**
  2370.      * @Template
  2371.      * @param Request $request
  2372.      * @return array
  2373.      */
  2374.     public function brandAction(Request $request) {
  2375.         return $this->render('/default/brand.html.twig', []);
  2376.     }
  2377.     
  2378.     /**
  2379.      * @Template
  2380.      * @param Request $request
  2381.      * @return array
  2382.      */
  2383.     public function productAction(Request $request) {
  2384.         $id str_replace("/"""$request->get("id"));
  2385.         
  2386.         $product DataObject::getById($id);
  2387.         
  2388.         return $this->render('/default/product.html.twig', ["product" => $product]);
  2389.     }
  2390.     
  2391.     /**
  2392.      * @Template
  2393.      * @param Request $request
  2394.      * @return array
  2395.      */
  2396.     public function newproductAction(Request $request) {
  2397.         $key substr($request->get("key"), 1);
  2398.         $number substr($request->get("number"), 1);
  2399.         $id substr($request->get("id"), 1);
  2400.         
  2401.         // var_dump($id);
  2402.         // // exit;
  2403.         
  2404.         // $product = DataObject\Product::getByArticleNumber($number);
  2405.         //     
  2406.         // $product = $product->load()[0];
  2407.         
  2408.         $product DataObject::getById($id);
  2409.         
  2410.         return $this->render('/default/product.html.twig', ["product" => $product]);
  2411.     }
  2412.     
  2413.     /**
  2414.      * @Template
  2415.      * @param Request $request
  2416.      * @return array
  2417.      */
  2418.     public function teaserAction(Request $request) {
  2419.         $id str_replace("/"""$request->get("id"));
  2420.         
  2421.         $teaser DataObject::getById($id);
  2422.         $relation $teaser->getRelation();
  2423.         
  2424.         if($relation && $relation->getType() == "object" && $relation->getClassName() == "Category") {
  2425.             $collectionObject $relation;
  2426.             $brandkey $collectionObject->getParent()->getKey();
  2427.             $brands DataObject\Brand::getByName($brandkey);
  2428.             $brand $brands->load();
  2429.             if(is_array($brand)) {
  2430.                 $brand $brand[0];
  2431.                 return $this->render('/default/teaser.html.twig', ["teaser" => $teaser"brand" => $brand]);
  2432.             }
  2433.         } else {
  2434.             return $this->render('/default/teaser.html.twig', ["teaser" => $teaser]);
  2435.         }
  2436.             
  2437.         
  2438.         
  2439.        
  2440.     }
  2441.     
  2442.     private static function addBrandCollections($brand) {
  2443.         $collections = new DataObject\Category\Listing();
  2444.         if($brand->getId() == 85) {
  2445.             $collections->setCondition("o_path LIKE :brand", ["brand" => "%Nomos%"]);
  2446.         } else {
  2447.             $collections->setCondition("o_path LIKE :brand", ["brand" => "%".$brand->getName()."%"]);
  2448.         }
  2449.         $collections->load();
  2450.         
  2451.         
  2452.         
  2453.         $brandid $brand->getId();
  2454.         
  2455.         foreach($collections as $coll) {
  2456.             
  2457.             $key $coll->getKey();
  2458.             
  2459.             $products = new DataObject\Product\Listing();
  2460.             if($brand->getName() == "A. Lange & Söhne") {
  2461.                 $products->setCondition("UPPER(`o_key`) LIKE \"%$key%\" AND brand__id = $brandid");
  2462.             } elseif($coll->getId() == 281) {
  2463.                 $products->setCondition("`o_key` LIKE \"%$key%\" AND `o_key` NOT LIKE \"%Superocean Heritage%\" AND brand__id = $brandid");
  2464.             } elseif($coll->getId() == 285) {
  2465.                 $products->setCondition("`o_key` LIKE \"% Avi %\" AND brand__id = $brandid");
  2466.             } else {
  2467.                 $products->setCondition("`o_key` LIKE \"%$key%\" AND brand__id = $brandid");
  2468.             }
  2469.             
  2470.             $products->load();
  2471.             foreach($products as $product) {
  2472.                 $cats $product->getCategories();
  2473.                 if($cats) {
  2474.                     if (!in_array($coll$catstrue)) {
  2475.                         array_push($cats$coll);
  2476.                     } 
  2477.                 } else {
  2478.                     array_push($cats$coll);
  2479.                 }
  2480.                
  2481.                 $product->setCategories($cats);
  2482.                 $product->save();
  2483.             }
  2484.             
  2485.         }
  2486.     }
  2487.     
  2488. }