src/Controller/DefaultController.php line 2390

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.         // 
  1657.         // $username = "atimis";
  1658.         // $password = "gui8kknyzG";
  1659.         // $dbname = "carat_100";
  1660.         
  1661.         $servername "node190984-carat.sh1.hidora.net";
  1662.         
  1663.         $username "phillip_script";
  1664.         $password "CCarat22PentLaks";
  1665.         $dbname "carat_100";
  1666.         
  1667.         // Verbindungsdaten
  1668.         $host $servername;
  1669.         $port 443;
  1670.         $user $username// Ersetze 'user' mit deinem tatsächlichen Benutzername
  1671.         
  1672.         try {
  1673.             // Verbindungsstring (DSN)
  1674.             $dsn "mysql:host=$host; port=$port; dbname=$dbname; charset=utf8";
  1675.         
  1676.             // Verbindung herstellen
  1677.             $pdo = new \PDO($dsn$user$password);
  1678.         
  1679.             // Fehlerbehandlung auf Exceptions umstellen
  1680.             $pdo->setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION);
  1681.         
  1682.             echo "Verbindung erfolgreich!";
  1683.         } catch (PDOException $e) {
  1684.             // Fehler ausgeben
  1685.             echo "Verbindung fehlgeschlagen: " $e->getMessage();
  1686.         } finally {
  1687.             $pdo null;
  1688.             echo "Verbindung geschlossen.";
  1689.         }
  1690.         
  1691.         
  1692.         
  1693.         exit;
  1694.         
  1695.         // Create connection
  1696.         $conn = new \mysqli($servername$username$password$dbname3306);
  1697.         // Check connection
  1698.         if ($conn->connect_error) {
  1699.           die("Connection failed: " $conn->connect_error);
  1700.         }
  1701.         
  1702.         
  1703.         $conn->set_charset("utf8mb4");
  1704.         
  1705.         
  1706.         //$sql = "SELECT * FROM Article LIMIT 10";
  1707.         
  1708.         // $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;";
  1709.         
  1710.         // $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";
  1711.         
  1712.         // $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`;";
  1713.         
  1714.         // fix " "
  1715.         
  1716.         // $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`";
  1717.         
  1718.         // BRAND QUERY
  1719.         
  1720.         // $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`";
  1721.         
  1722.         
  1723.         // FINAL QUERY
  1724.         
  1725.         $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` LIMIT 10";
  1726.         
  1727.         // $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`";
  1728.         
  1729.         // END FINAL QUERY
  1730.         
  1731.         
  1732.        // $sql = "SELECT * FROM Article WHERE `brand` LIKE '%Lange%' LIMIT 10;";
  1733.         
  1734.         $result $conn->query($sql);
  1735.         
  1736.         var_dump($result);
  1737.         exit;
  1738.         
  1739.         while($row $result->fetch_assoc()) {
  1740.             $extId $row["id"];
  1741.             $row array_map('trim'$row);
  1742.   
  1743.             
  1744.             $key \Pimcore\Model\Element\Service::getValidKey($row["productLine"] . "-" $row["articleNumber"], 'object');
  1745.             
  1746.             $prObject DataObject::getByPath("/PIM/01 Uhren/02 Produkte/" $row["brand"] . "/" $key);
  1747.             $checkstring date('d-m-y');
  1748.             //$checkstring .= 'manual';
  1749.             // $checkstring .= "-zenith";
  1750.             if($prObject) {
  1751.                 // if($prObject->getUpdateinfo() == "291122-try1" || $prObject->getUpdateinfo() == "291122-try2" || $prObject->getUpdateinfo() == "291122-try3" || $prObject->getUpdateinfo() == "291122-try4") {
  1752.                 //     continue;
  1753.                 // }
  1754.                 
  1755.                 
  1756.                 if($prObject->getUpdateInfo() == $checkstring) {
  1757.                     continue;
  1758.                 }
  1759.                 $newObject $prObject;
  1760.                 $newObject->setupdateinfo($checkstring);
  1761.             } else {
  1762.                 $newObject = new DataObject\Product(); 
  1763.                 $newObject->setKey($key);
  1764.                 $newObject->setupdateinfo($checkstring);
  1765.                 
  1766.                 // get Brand Folder ID
  1767.                 $folder DataObject::getByPath("/PIM/01 Uhren/02 Produkte/" $row["brand"]);
  1768.                 
  1769.                 if($row["brand"] == "Jaeger-LeCoultre") {
  1770.                     $folder DataObject::getById(396);
  1771.                 }
  1772.                 if($row["brand"] == "IWC") {
  1773.                     $folder DataObject::getById(962);
  1774.                 }
  1775.                 if($row["brand"] == "Nomos GlashĂĽtte") {
  1776.                     $folder DataObject::getById(407);
  1777.                 }
  1778.                 
  1779.                 if($folder == null) {
  1780.                     $folder = new DataObject\Folder(); 
  1781.                     $folder->setKey(\Pimcore\Model\Element\Service::getValidKey($row["brand"], 'folder'));
  1782.                     $folder->setParentId(61);
  1783.                     $folder->save();
  1784.                 }
  1785.                 $parentId $folder->getId();
  1786.                 
  1787.                 $newObject->setParentId($parentId);
  1788.             }
  1789.             
  1790.             $newObject->setModel($row["productLine"]);
  1791.             $newObject->setArticleNumber($row["articleNumber"]);
  1792.             $newObject->setStockInputDate($row["stockInputDate"]);
  1793.             $newObject->setExtId($row["id"]);
  1794.             $newObject->setPrice($row["price"]);
  1795.             
  1796.             //set brand
  1797.             $brand DataObject::getByPath("/PIM/01 Uhren/01 Marken/" $row["brand"]);
  1798.             if($row["brand"] == "Jaeger-LeCoultre") {
  1799.                 $brand DataObject\Brand::getById(23);
  1800.             }
  1801.             if($row["brand"] == "IWC") {
  1802.                 $brand DataObject\Brand::getById(82);
  1803.             }
  1804.             if($row["brand"] == "Nomos GlashĂĽtte") {
  1805.                 $brand DataObject\Brand::getById(85);
  1806.             }
  1807.             if($row["brand"] == "Sattler") {
  1808.                 $brand DataObject\Brand::getById(77);
  1809.             }
  1810.             $newObject->setBrand($brand);
  1811.             
  1812.             //set specifications
  1813.             $items = new DataObject\Fieldcollection();
  1814.             $specsql "SELECT name, value FROM `ArticleProperty` WHERE `article_id` = $extId;";
  1815.             $specresult $conn->query($specsql);
  1816.             
  1817.             while($specrow $specresult->fetch_assoc()) {
  1818.                 $item = new DataObject\Fieldcollection\Data\Specification();
  1819.                 
  1820.                 $item->setSpecKey($specrow["name"]);
  1821.                 $item->setSpecValue($specrow["value"]);
  1822.                 
  1823.                 $items->add($item);
  1824.             }
  1825.             $newObject->setSpecs($items);
  1826.             
  1827.             //set frontimage
  1828.             $imagesql "SELECT src FROM `Image` WHERE `article_id` = $extId;";
  1829.             $imageresult $conn->query($imagesql);
  1830.             $articlenumber str_replace("/""-"$row["articleNumber"]);
  1831.             $assetfolderpath "/PIM/01 Uhren/02 Produkte/" $row["brand"] . "/" str_replace(["/"'"'"+"], ["-"""""], $row["productLine"]) . "-" $articlenumber;
  1832.             $assetfolderpath str_replace("+"""$assetfolderpath);
  1833.             $assetfolderpath str_replace("."""$assetfolderpath);
  1834.             $assetfolderpath str_replace("|"""$assetfolderpath);
  1835.             $assetfolderpath str_replace("Ăź""ss"$assetfolderpath);
  1836.             Asset\Service::createFolderByPath($assetfolderpath);
  1837.             
  1838.             $counter 0;
  1839.             $addImages = [];
  1840.             while($imagerow $imageresult->fetch_assoc()) {
  1841.                 $counter += 1;
  1842.                 $newAsset = new \Pimcore\Model\Asset\Image();
  1843.                 $newAsset->setFilename($imagerow["src"]);
  1844.                 $newAsset->setData(file_get_contents("https://huebner.carat.solutions/carat/filedownload?fileName=" $imagerow["src"]));
  1845.                 $newAsset->setParent(\Pimcore\Model\Asset::getByPath($assetfolderpath));
  1846.                 
  1847.                 $checkasset null;    
  1848.                 $checkasset \Pimcore\Model\Asset::getByPath($assetfolderpath "/" $imagerow["src"]);
  1849.                 
  1850.                 echo "trying to save asset for " $row["productLine"] . "-" $row["articleNumber"] . "<br><hr><br>";
  1851.                 
  1852.                 if(strpos($imagerow["src"], "html") == false && strpos($imagerow["src"], "htm") == false && $imagerow["src"] != "7281fa99-3001-41a5-9be1-8dcfe04d997b.") {
  1853.                     if($checkasset) {
  1854.                        $checkasset->setData(file_get_contents("https://huebner.carat.solutions/carat/filedownload?fileName=" $imagerow["src"]));
  1855.                        $checkasset->save();
  1856.                        $newAsset $checkasset;
  1857.                     } else {
  1858.                         // var_dump($newAsset->getFullPath());
  1859.                         // var_dump($assetfolderpath);
  1860.                         // var_dump(\Pimcore\Model\Asset::getByPath($assetfolderpath));
  1861.                         // exit;
  1862.                         $newAsset->save();
  1863.                     }
  1864.                     $newAsset->save();
  1865.                 }
  1866.                 if($counter == 1) {
  1867.                     $newObject->setFrontimage($newAsset);
  1868.                 } else {
  1869.                     $advancedImage = new \Pimcore\Model\DataObject\Data\Hotspotimage();
  1870.                     $advancedImage->setImage($newAsset);
  1871.                     array_push($addImages$advancedImage);
  1872.                 }
  1873.             }
  1874.             
  1875.             if(count($addImages) > 0) {   
  1876.                 $newObject->setImages(new \Pimcore\Model\DataObject\Data\ImageGallery($addImages));
  1877.             }
  1878.             
  1879.             //var_dump($addImages);
  1880.             
  1881.             
  1882.             //set gender
  1883.             $gendercat DataObject::getByPath("/PIM/01 Uhren/03 Kategorien/" $row["subcategory"]);
  1884.             if(!$gendercat) {
  1885.                 $newcat = new DataObject\Category(); 
  1886.                 $newcat->setKey(\Pimcore\Model\Element\Service::getValidKey($row["subcategory"], 'object'));
  1887.                 $newcat->setParentId(101);
  1888.                 $newcat->setTitle($row["subcategory"]);
  1889.                 $newcat->setPublished(true);
  1890.                 $newcat->save();
  1891.                 $gendercat $newcat;
  1892.             }
  1893.             
  1894.             $cats = [$gendercat];
  1895.             $newObject->setCategories($cats);
  1896.             
  1897.             $newObject->setPublished(true);
  1898.             $newObject->save();
  1899.             
  1900.             //var_dump($brand);
  1901.         }
  1902.         
  1903.         $conn->close();
  1904.         
  1905.         
  1906.         exit;
  1907.         return [];
  1908.     }
  1909.     
  1910.     /**
  1911.      * @Template
  1912.      * @param Request $request
  1913.      * @return array
  1914.      */
  1915.     public function categoryAction(Request $request) {
  1916.         
  1917.         
  1918.         return [];
  1919.     }
  1920.     
  1921.     
  1922.     /**
  1923.      * @Template
  1924.      * @param Request $request
  1925.      * @return array
  1926.      */
  1927.     public function homeAction(Request $request) {
  1928.         return [];
  1929.     }
  1930.     
  1931.     /**
  1932.      * @Template
  1933.      * @param Request $request
  1934.      * @return array
  1935.      */
  1936.     public function newProductOverviewAction(Request $request) {
  1937.         if(isset($_COOKIE['zeitdebug'])) {
  1938.             $debug "true";
  1939.         } else {
  1940.             $debug "false";
  1941.         }
  1942.         $jewellerycategory null;
  1943.         $entries = new DataObject\Product\Listing();
  1944.         $filters = [];
  1945.         
  1946.         $page = isset($_GET["page"]) ? $_GET["page"] : 1;
  1947.         if($page) {
  1948.             $offset 24 * (intval($page) -1);
  1949.             $filters["page"] = $page;
  1950.         }
  1951.         
  1952.         $brandValues = new DataObject\Brand\Listing();
  1953.         $brandValues->setCondition('o_path LIKE "%Uhren%"');
  1954.         $brandValues->load();
  1955.         
  1956.         $collection = isset($_GET["collection"]) ? $_GET["collection"] : null;
  1957.         if($collection) {
  1958.             $entries->addConditionParam("categories LIKE ?""%object|$collection%""AND");
  1959.             $filters["collection"] = $collection;
  1960.         }
  1961.         
  1962.         $price = isset($_GET["price"]) ? $_GET["price"] : null;
  1963.         if($price) {
  1964.             switch ($price) {
  1965.                 case "until2500":
  1966.                     $grossPriceFrom 0;
  1967.                     $grossPriceTo 2500;
  1968.                     
  1969.                     $netPriceFrom 0.0;
  1970.                     $netPriceTo $grossPriceTo 1.2;
  1971.                     
  1972.                     $entries->addConditionParam("price < ?"$netPriceTo"AND");
  1973.                     break;
  1974.                     
  1975.                 case "from2500until5000":
  1976.                     $grossPriceFrom 2500;
  1977.                     $grossPriceTo 5000;
  1978.                     
  1979.                     $netPriceFrom $grossPriceFrom 1.2;
  1980.                     $netPriceTo $grossPriceTo 1.2;
  1981.                     
  1982.                     $entries->addConditionParam("price > ?"$netPriceFrom"AND");
  1983.                     $entries->addConditionParam("price < ?"$netPriceTo"AND");
  1984.                     break;
  1985.                 
  1986.                 case "from5000until10000":
  1987.                     $grossPriceFrom 5000;
  1988.                     $grossPriceTo 10000;
  1989.                     
  1990.                     $netPriceFrom $grossPriceFrom 1.2;
  1991.                     $netPriceTo $grossPriceTo 1.2;
  1992.                     
  1993.                     $entries->addConditionParam("price > ?"$netPriceFrom"AND");
  1994.                     $entries->addConditionParam("price < ?"$netPriceTo"AND");
  1995.                     break;
  1996.                 
  1997.                 case "from100000until150000":
  1998.                     $grossPriceFrom 10000;
  1999.                     $grossPriceTo 15000;
  2000.                     
  2001.                     $netPriceFrom $grossPriceFrom 1.2;
  2002.                     $netPriceTo $grossPriceTo 1.2;
  2003.                     
  2004.                     $entries->addConditionParam("price > ?"$netPriceFrom"AND");
  2005.                     $entries->addConditionParam("price < ?"$netPriceTo"AND");
  2006.                     break;
  2007.                 case "from15000until20000":
  2008.                     $grossPriceFrom 15000;
  2009.                     $grossPriceTo 20000;
  2010.                     
  2011.                     $netPriceFrom $grossPriceFrom 1.2;
  2012.                     $netPriceTo $grossPriceTo 1.2;
  2013.                     
  2014.                     $entries->addConditionParam("price > ?"$netPriceFrom"AND");
  2015.                     $entries->addConditionParam("price < ?"$netPriceTo"AND");
  2016.                     break;
  2017.                 case "from20000":
  2018.                     $grossPriceFrom 20000;
  2019.                     $netPriceFrom $grossPriceFrom 1.2;
  2020.                     
  2021.                     $entries->addConditionParam("price > ?"$netPriceFrom"AND");
  2022.                     break;
  2023.             }
  2024.             
  2025.             
  2026.             $filters["price"] = $price;
  2027.         }
  2028.         
  2029.         $type = isset($_GET["type"]) ? $_GET["type"] : null;
  2030.         if($type) {
  2031.             //$entries->addConditionParam("categories LIKE ?", "%object|$type%", "AND");
  2032.             $entries->setCondition("categories LIKE '%object|$type%'");
  2033.             $filters["type"] = $type;
  2034.         }
  2035.         
  2036.         $brand = isset($_GET["brand"]) ? $_GET["brand"] : null;
  2037.         if($brand) {
  2038.             $entries->addConditionParam("brand__id = ?""$brand""AND");
  2039.             $brandobject DataObject::getById($brand);
  2040.             $brandcollections $brandobject->getCollections() ? $brandobject->getCollections()->getChildren() : null;
  2041.             
  2042.             $filters["brand"] = $brand;
  2043.             $filters["brandCollections"] = $brandcollections;
  2044.         } 
  2045.         if (!$brand && $collection) {
  2046.             $collectionObject DataObject::getById($collection);
  2047.                 // var_dump($collection);
  2048.                 // exit;
  2049.             
  2050.             
  2051.             $collectionpath $collectionObject->getPath();
  2052.             // var_dump($collectionpath);
  2053.             // exit;
  2054.             if(str_contains($collectionpath"Schmuck")) {
  2055.                 
  2056.                 $entries->addConditionParam("o_path LIKE '%Schmuck%'""AND");
  2057.                 $jewellerycategory $collectionObject;
  2058.             } else {
  2059.                 $brandkey $collectionObject->getParent()->getKey();
  2060.                 
  2061.                 $brands DataObject\Brand::getByName($brandkey);
  2062.                 $brand $brands->load();
  2063.                 if(is_array($brand)) {
  2064.                     $brand $brand[0];
  2065.                     $brandobject $brand;
  2066.                     $brandcollections $brandobject->getCollections() ? $brandobject->getCollections()->getChildren() : null;
  2067.                     
  2068.                     $filters["brand"] = $brand->getId();
  2069.                     $filters["brandCollections"] = $brandcollections;
  2070.                 } else {
  2071.                     $brand null;
  2072.                     $filters["brand"] = null;
  2073.                     $filters["brandCollections"] = null;
  2074.                 }
  2075.             }
  2076.             
  2077.             
  2078.             
  2079.         }
  2080.         
  2081.         if(!isset($filters["brandCollections"])) {
  2082.             $brandCollections = new DataObject\Category\Listing();
  2083.             $brandCollections->setCondition("o_path LIKE '%Kollektionen%'");
  2084.             $brandCollections $brandCollections->load();
  2085.             $filters["brandCollections"] = $brandCollections;
  2086.         }
  2087.         
  2088.         $casematerial = isset($_GET["casematerial"]) ? $_GET["casematerial"] : null;
  2089.         if($casematerial) {
  2090.             $entries->addFieldCollection("Specification""specs");
  2091.             $entries->addConditionParam("`Specification~specs`.specKey = 'Gehäusematerial' AND `Specification~specs`.specValue LIKE ?""%$casematerial%""AND");
  2092.             $filters["casematerial"] = $casematerial;
  2093.         }
  2094.         
  2095.         $sort = isset($_GET["sort"]) ? $_GET["sort"] : null;
  2096.         if($sort) {
  2097.            switch($sort) {
  2098.                case "actual":
  2099.                    $entries->setOrderKey("stockInputDate");
  2100.                    $entries->setOrder("desc");
  2101.                    break;
  2102.                case "priceasc":
  2103.                    $entries->setOrderKey("price");
  2104.                    $entries->setOrder("asc");
  2105.                    break;
  2106.                 case "pricedesc":
  2107.                     $entries->setOrderKey("price");
  2108.                     $entries->setOrder("desc");
  2109.                     break;
  2110.                 case "name":
  2111.                     $entries->setOrderKey("model");
  2112.                     $entries->setOrder("asc");
  2113.                     break;
  2114.            }
  2115.            $filters["sort"] = $sort;
  2116.         } else {
  2117.             $entries->setOrderKey("stockInputDate");
  2118.             $entries->setOrder("desc");
  2119.             $filters["sort"] = "actual";
  2120.         }
  2121.         
  2122.         
  2123.         
  2124.        
  2125.         $entries->addConditionParam("brand__id IS NOT NULL""""AND");
  2126.         $entries->addConditionParam("o_path LIKE ?""%Uhren%""AND");
  2127.         $Countentries $entries->load();
  2128.         $entryCount count($Countentries);
  2129.         
  2130.         $limit 24;
  2131.         $entries->setLimit($limit);
  2132.         $entries->setOffset($offset);
  2133.         $entries $entries->load();
  2134.         
  2135.         return $this->render('/default/new_product_overview.html.twig', ["products" => $entries"filters" => $filters"jewellerycat" => $jewellerycategory"debug" => $debug'brandValues' => $brandValues"entryCount" => $entryCount]);
  2136.     
  2137.       
  2138.     }
  2139.     
  2140.     /**
  2141.      * @Template
  2142.      * @param Request $request
  2143.      * @return array
  2144.      */
  2145.     public function productOverviewAction(Request $request) {
  2146.         if(isset($_COOKIE['zeitdebug'])) {
  2147.             $debug "true";
  2148.         } else {
  2149.             $debug "false";
  2150.         }
  2151.         $jewellerycategory null;
  2152.         $entries = new DataObject\Product\Listing();
  2153.         $filters = [];
  2154.         
  2155.         $page = isset($_GET["page"]) ? $_GET["page"] : null;
  2156.         if($page) {
  2157.             if($page == 1) {
  2158.                 $entries->setLimit(24);
  2159.             }
  2160.             $filters["page"] = $page;
  2161.         }
  2162.         
  2163.         $collection = isset($_GET["collection"]) ? $_GET["collection"] : null;
  2164.         if($collection) {
  2165.             $entries->addConditionParam("categories LIKE ?""%object|$collection%""AND");
  2166.             $filters["collection"] = $collection;
  2167.         }
  2168.         
  2169.         $price = isset($_GET["price"]) ? $_GET["price"] : null;
  2170.         if($price) {
  2171.             switch ($price) {
  2172.                 case "until2500":
  2173.                     $grossPriceFrom 0;
  2174.                     $grossPriceTo 2500;
  2175.                     
  2176.                     $netPriceFrom 0.0;
  2177.                     $netPriceTo $grossPriceTo 1.2;
  2178.                     
  2179.                     $entries->addConditionParam("price < ?"$netPriceTo"AND");
  2180.                     break;
  2181.                     
  2182.                 case "from2500until5000":
  2183.                     $grossPriceFrom 2500;
  2184.                     $grossPriceTo 5000;
  2185.                     
  2186.                     $netPriceFrom $grossPriceFrom 1.2;
  2187.                     $netPriceTo $grossPriceTo 1.2;
  2188.                     
  2189.                     $entries->addConditionParam("price > ?"$netPriceFrom"AND");
  2190.                     $entries->addConditionParam("price < ?"$netPriceTo"AND");
  2191.                     break;
  2192.                 
  2193.                 case "from5000until10000":
  2194.                     $grossPriceFrom 5000;
  2195.                     $grossPriceTo 10000;
  2196.                     
  2197.                     $netPriceFrom $grossPriceFrom 1.2;
  2198.                     $netPriceTo $grossPriceTo 1.2;
  2199.                     
  2200.                     $entries->addConditionParam("price > ?"$netPriceFrom"AND");
  2201.                     $entries->addConditionParam("price < ?"$netPriceTo"AND");
  2202.                     break;
  2203.                 
  2204.                 case "from100000until150000":
  2205.                     $grossPriceFrom 10000;
  2206.                     $grossPriceTo 15000;
  2207.                     
  2208.                     $netPriceFrom $grossPriceFrom 1.2;
  2209.                     $netPriceTo $grossPriceTo 1.2;
  2210.                     
  2211.                     $entries->addConditionParam("price > ?"$netPriceFrom"AND");
  2212.                     $entries->addConditionParam("price < ?"$netPriceTo"AND");
  2213.                     break;
  2214.                 case "from15000until20000":
  2215.                     $grossPriceFrom 15000;
  2216.                     $grossPriceTo 20000;
  2217.                     
  2218.                     $netPriceFrom $grossPriceFrom 1.2;
  2219.                     $netPriceTo $grossPriceTo 1.2;
  2220.                     
  2221.                     $entries->addConditionParam("price > ?"$netPriceFrom"AND");
  2222.                     $entries->addConditionParam("price < ?"$netPriceTo"AND");
  2223.                     break;
  2224.                 case "from20000":
  2225.                     $grossPriceFrom 20000;
  2226.                     $netPriceFrom $grossPriceFrom 1.2;
  2227.                     
  2228.                     $entries->addConditionParam("price > ?"$netPriceFrom"AND");
  2229.                     break;
  2230.             }
  2231.             
  2232.             
  2233.             $filters["price"] = $price;
  2234.         }
  2235.         
  2236.         $type = isset($_GET["type"]) ? $_GET["type"] : null;
  2237.         if($type) {
  2238.             //$entries->addConditionParam("categories LIKE ?", "%object|$type%", "AND");
  2239.             $entries->setCondition("categories LIKE '%object|$type%'");
  2240.             $filters["type"] = $type;
  2241.         }
  2242.         
  2243.         $brand = isset($_GET["brand"]) ? $_GET["brand"] : null;
  2244.         if($brand) {
  2245.             $entries->addConditionParam("brand__id = ?""$brand""AND");
  2246.             $brandobject DataObject::getById($brand);
  2247.             $brandcollections $brandobject->getCollections() ? $brandobject->getCollections()->getChildren() : null;
  2248.             
  2249.             $filters["brand"] = $brand;
  2250.             $filters["brandCollections"] = $brandcollections;
  2251.         } 
  2252.         if (!$brand && $collection) {
  2253.             $collectionObject DataObject::getById($collection);
  2254.                 // var_dump($collection);
  2255.                 // exit;
  2256.             
  2257.             
  2258.             $collectionpath $collectionObject->getPath();
  2259.             // var_dump($collectionpath);
  2260.             // exit;
  2261.             if(str_contains($collectionpath"Schmuck")) {
  2262.                 
  2263.                 $entries->addConditionParam("o_path LIKE '%Schmuck%'""AND");
  2264.                 $jewellerycategory $collectionObject;
  2265.             } else {
  2266.                 $brandkey $collectionObject->getParent()->getKey();
  2267.                 
  2268.                 $brands DataObject\Brand::getByName($brandkey);
  2269.                 $brand $brands->load();
  2270.                 if(is_array($brand)) {
  2271.                     $brand $brand[0];
  2272.                     $brandobject $brand;
  2273.                     $brandcollections $brandobject->getCollections() ? $brandobject->getCollections()->getChildren() : null;
  2274.                     
  2275.                     $filters["brand"] = $brand->getId();
  2276.                     $filters["brandCollections"] = $brandcollections;
  2277.                 } else {
  2278.                     $brand null;
  2279.                     $filters["brand"] = null;
  2280.                     $filters["brandCollections"] = null;
  2281.                 }
  2282.             }
  2283.             
  2284.             
  2285.             
  2286.         }
  2287.         
  2288.         if(!isset($filters["brandCollections"])) {
  2289.             $brandCollections = new DataObject\Category\Listing();
  2290.             $brandCollections->setCondition("o_path LIKE '%Kollektionen%'");
  2291.             $brandCollections $brandCollections->load();
  2292.             $filters["brandCollections"] = $brandCollections;
  2293.         }
  2294.         
  2295.         $casematerial = isset($_GET["casematerial"]) ? $_GET["casematerial"] : null;
  2296.         if($casematerial) {
  2297.             $entries->addFieldCollection("Specification""specs");
  2298.             $entries->addConditionParam("`Specification~specs`.specKey = 'Gehäusematerial' AND `Specification~specs`.specValue LIKE ?""%$casematerial%""AND");
  2299.             $filters["casematerial"] = $casematerial;
  2300.         }
  2301.         
  2302.         $sort = isset($_GET["sort"]) ? $_GET["sort"] : null;
  2303.         if($sort) {
  2304.            switch($sort) {
  2305.                case "actual":
  2306.                    $entries->setOrderKey("stockInputDate");
  2307.                    $entries->setOrder("desc");
  2308.                    break;
  2309.                case "priceasc":
  2310.                    $entries->setOrderKey("price");
  2311.                    $entries->setOrder("asc");
  2312.                    break;
  2313.                 case "pricedesc":
  2314.                     $entries->setOrderKey("price");
  2315.                     $entries->setOrder("desc");
  2316.                     break;
  2317.                 case "name":
  2318.                     $entries->setOrderKey("model");
  2319.                     $entries->setOrder("asc");
  2320.                     break;
  2321.            }
  2322.            $filters["sort"] = $sort;
  2323.         } else {
  2324.             $entries->setOrderKey("stockInputDate");
  2325.             $entries->setOrder("desc");
  2326.             $filters["sort"] = "actual";
  2327.         }
  2328.         
  2329.         
  2330.         
  2331.         //var_dump($entries);
  2332.         
  2333.         $entries $entries->load();
  2334.         
  2335.        
  2336.        
  2337.         
  2338.         return $this->render('/default/product_overview.html.twig', ["products" => $entries"filters" => $filters"jewellerycat" => $jewellerycategory"debug" => $debug]);
  2339.    
  2340.       
  2341.     }
  2342.     
  2343.     /**
  2344.      * @Template
  2345.      * @param Request $request
  2346.      * @return array
  2347.      */
  2348.     public function brandsOverviewAction(Request $request) {
  2349.         $docpath $this->document->getFullPath();
  2350.         //var_dump($docpath);
  2351.         
  2352.         if(strpos($docpath"Uhren") !== false) {
  2353.             $path "Uhren";
  2354.         } else {
  2355.             $path "Schmuck";
  2356.         }
  2357.         
  2358.         
  2359.         $entries = new DataObject\Brand\Listing();
  2360.         $entries->setCondition("o_path LIKE '%$path%' ");
  2361.         $entries->setOrderKey("o_key");
  2362.         $entries->setOrder("ASC");
  2363.         $entries->load();
  2364.         
  2365.         return $this->render('/default/brands_overview.html.twig', ["brands" => $entries]);
  2366.     }
  2367.     
  2368.     /**
  2369.      * @Template
  2370.      * @param Request $request
  2371.      * @return array
  2372.      */
  2373.     public function teaserOverviewAction(Request $request) {
  2374.         return [];
  2375.     }
  2376.     
  2377.     /**
  2378.      * @Template
  2379.      * @param Request $request
  2380.      * @return array
  2381.      */
  2382.     public function brandAction(Request $request) {
  2383.         return $this->render('/default/brand.html.twig', []);
  2384.     }
  2385.     
  2386.     /**
  2387.      * @Template
  2388.      * @param Request $request
  2389.      * @return array
  2390.      */
  2391.     public function productAction(Request $request) {
  2392.         $id str_replace("/"""$request->get("id"));
  2393.         
  2394.         $product DataObject::getById($id);
  2395.         
  2396.         return $this->render('/default/product.html.twig', ["product" => $product]);
  2397.     }
  2398.     
  2399.     /**
  2400.      * @Template
  2401.      * @param Request $request
  2402.      * @return array
  2403.      */
  2404.     public function newproductAction(Request $request) {
  2405.         $key substr($request->get("key"), 1);
  2406.         $number substr($request->get("number"), 1);
  2407.         $id substr($request->get("id"), 1);
  2408.         
  2409.         // var_dump($id);
  2410.         // // exit;
  2411.         
  2412.         // $product = DataObject\Product::getByArticleNumber($number);
  2413.         //     
  2414.         // $product = $product->load()[0];
  2415.         
  2416.         $product DataObject::getById($id);
  2417.         
  2418.         return $this->render('/default/product.html.twig', ["product" => $product]);
  2419.     }
  2420.     
  2421.     /**
  2422.      * @Template
  2423.      * @param Request $request
  2424.      * @return array
  2425.      */
  2426.     public function teaserAction(Request $request) {
  2427.         $id str_replace("/"""$request->get("id"));
  2428.         
  2429.         $teaser DataObject::getById($id);
  2430.         $relation $teaser->getRelation();
  2431.         
  2432.         if($relation && $relation->getType() == "object" && $relation->getClassName() == "Category") {
  2433.             $collectionObject $relation;
  2434.             $brandkey $collectionObject->getParent()->getKey();
  2435.             $brands DataObject\Brand::getByName($brandkey);
  2436.             $brand $brands->load();
  2437.             if(is_array($brand)) {
  2438.                 $brand $brand[0];
  2439.                 return $this->render('/default/teaser.html.twig', ["teaser" => $teaser"brand" => $brand]);
  2440.             }
  2441.         } else {
  2442.             return $this->render('/default/teaser.html.twig', ["teaser" => $teaser]);
  2443.         }
  2444.             
  2445.         
  2446.         
  2447.        
  2448.     }
  2449.     
  2450.     private static function addBrandCollections($brand) {
  2451.         $collections = new DataObject\Category\Listing();
  2452.         if($brand->getId() == 85) {
  2453.             $collections->setCondition("o_path LIKE :brand", ["brand" => "%Nomos%"]);
  2454.         } else {
  2455.             $collections->setCondition("o_path LIKE :brand", ["brand" => "%".$brand->getName()."%"]);
  2456.         }
  2457.         $collections->load();
  2458.         
  2459.         
  2460.         
  2461.         $brandid $brand->getId();
  2462.         
  2463.         foreach($collections as $coll) {
  2464.             
  2465.             $key $coll->getKey();
  2466.             
  2467.             $products = new DataObject\Product\Listing();
  2468.             if($brand->getName() == "A. Lange & Söhne") {
  2469.                 $products->setCondition("UPPER(`o_key`) LIKE \"%$key%\" AND brand__id = $brandid");
  2470.             } elseif($coll->getId() == 281) {
  2471.                 $products->setCondition("`o_key` LIKE \"%$key%\" AND `o_key` NOT LIKE \"%Superocean Heritage%\" AND brand__id = $brandid");
  2472.             } elseif($coll->getId() == 285) {
  2473.                 $products->setCondition("`o_key` LIKE \"% Avi %\" AND brand__id = $brandid");
  2474.             } else {
  2475.                 $products->setCondition("`o_key` LIKE \"%$key%\" AND brand__id = $brandid");
  2476.             }
  2477.             
  2478.             $products->load();
  2479.             foreach($products as $product) {
  2480.                 $cats $product->getCategories();
  2481.                 if($cats) {
  2482.                     if (!in_array($coll$catstrue)) {
  2483.                         array_push($cats$coll);
  2484.                     } 
  2485.                 } else {
  2486.                     array_push($cats$coll);
  2487.                 }
  2488.                
  2489.                 $product->setCategories($cats);
  2490.                 $product->save();
  2491.             }
  2492.             
  2493.         }
  2494.     }
  2495.     
  2496. }