src/Controller/DefaultController.php line 2005

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 addPriceDevAction(Request $request) {
  25.         $data = [            "37931" => "281.25",
  26.            "39017" => "195.65",
  27.            "39018" => "953.16",
  28.            "39428" => "1454.74",
  29.            "39958" => "237.00",
  30.            "40103" => "448.50",
  31.            "40275" => "360.16",
  32.            "40722" => "872.50",
  33.            "41243" => "29.65",
  34.            "41245" => "23.12",
  35.            "41578" => "682.50",
  36.            "42126" => "798.50",
  37.            "42369" => "598.00",
  38.            "42957" => "1220.00",
  39.            "43600" => "529.00",
  40.            "43672" => "329.00",
  41.            "43698" => "2188.44",
  42.            "43761" => "2200.00",
  43.            "43832" => "89.00",
  44.            "43836" => "12.50",
  45.            "43837" => "12.50",
  46.            "43838" => "12.50",
  47.            "43843" => "38.00",
  48.            "43845" => "12.50",
  49.            "43846" => "12.50",
  50.            "43848" => "25.50",
  51.            "43857" => "25.50",
  52.            "43864" => "38.00",
  53.            "43867" => "38.00",
  54.            "43868" => "38.00",
  55.            "43884" => "63.50",
  56.            "43886" => "63.50",
  57.            "43892" => "38.00",
  58.            "43896" => "893.00",
  59.            "43900" => "1590.00",
  60.            "43902" => "226.50",
  61.            "43909" => "447.00",
  62.            "44190" => "127.00",
  63.            "44194" => "89.50",
  64.            "44196" => "38.00",
  65.            "44197" => "38.00",
  66.            "44198" => "38.00",
  67.            "44199" => "38.00",
  68.            "44207" => "12.50",
  69.            "44209" => "12.50",
  70.            "44213" => "115.00",
  71.            "44217" => "138.00",
  72.            "44221" => "1589.50",
  73.            "44225" => "395.50",
  74.            "44228" => "447.00",
  75.            "44235" => "107.50",
  76.            "44615" => "127.00",
  77.            "44619" => "892.50",
  78.            "45005" => "625.14",
  79.            "45007" => "97.23",
  80.            "45186" => "627.90",
  81.            "45960" => "198.50",
  82.            "46490" => "457.76",
  83.            "46492" => "918.02",
  84.            "46497" => "984.05",
  85.            "46511" => "625.35",
  86.            "46514" => "625.35",
  87.            "46519" => "457.76",
  88.            "46522" => "38.02",
  89.            "46523" => "38.02",
  90.            "46662" => "226.50",
  91.            "46667" => "89.00",
  92.            "46688" => "202.00",
  93.            "46690" => "202.00",
  94.            "46819" => "1320.00",
  95.            "47007" => "702.50",
  96.            "47217" => "107.50",
  97.            "47221" => "227.00",
  98.            "47288" => "238.80",
  99.            "47291" => "802.20",
  100.            "47294" => "383.25",
  101.            "47332" => "958.00",
  102.            "47574" => "380.00",
  103.            "47603" => "400.50",
  104.            "47784" => "260.50",
  105.            "48302" => "700.83",
  106.            "48350" => "945.00",
  107.            "48351" => "242.50",
  108.            "48353" => "89.00",
  109.            "48471" => "526.50",
  110.            "48492" => "457.00",
  111.            "48494" => "121.00",
  112.            "48693" => "1092.00",
  113.            "48774" => "127.00",
  114.            "48775" => "108.50",
  115.            "48777" => "108.50",
  116.            "48781" => "38.00",
  117.            "48784" => "188.50",
  118.            "48791" => "458.00",
  119.            "48794" => "574.50",
  120.            "48797" => "108.50",
  121.            "48800" => "25.50",
  122.            "48801" => "38.00",
  123.            "48803" => "188.50",
  124.            "48804" => "188.50",
  125.            "48808" => "213.00",
  126.            "48815" => "127.00",
  127.            "48817" => "364.00",
  128.            "48818" => "25.50",
  129.            "48819" => "38.00",
  130.            "48821" => "188.50",
  131.            "48824" => "188.50",
  132.            "48825" => "338.50",
  133.            "48826" => "1624.50",
  134.            "48828" => "213.00",
  135.            "48843" => "458.00",
  136.            "48892" => "447.30",
  137.            "48893" => "156.45",
  138.            "48894" => "166.95",
  139.            "48895" => "250.95",
  140.            "48972" => "574.50",
  141.            "48973" => "574.50",
  142.            "49355" => "525.00",
  143.            "49358" => "1300.00",
  144.            "49409" => "473.50",
  145.            "49424" => "3907.50",
  146.            "49458" => "1875.00",
  147.            "49495" => "637.50",
  148.            "49501" => "457.00",
  149.            "49503" => "234.00",
  150.            "49504" => "296.00",
  151.            "49510" => "38.00",
  152.            "49563" => "6857.50",
  153.            "50001" => "9580.00",
  154.            "50168" => "395.00",
  155.            "50208" => "703.25",
  156.            "50237" => "435.00",
  157.            "50246" => "430.00",
  158.            "50307" => "737.50",
  159.            "50353" => "4030.00",
  160.            "50383" => "34.50",
  161.            "50386" => "172.00",
  162.            "50554" => "439.38",
  163.            "50627" => "4840.50",
  164.            "50666" => "2847.50",
  165.            "50787" => "775.00",
  166.            "50792" => "247.50",
  167.            "50793" => "247.50",
  168.            "50842" => "3075.00",
  169.            "50883" => "586.85",
  170.            "50896" => "586.85",
  171.            "51012" => "54.50",
  172.            "51015" => "54.50",
  173.            "51016" => "79.50",
  174.            "51024" => "385.00",
  175.            "51025" => "385.00",
  176.            "51084" => "1358.50",
  177.            "51085" => "837.00",
  178.            "51086" => "416.50",
  179.            "51088" => "416.50",
  180.            "51090" => "554.50",
  181.            "51092" => "554.50",
  182.            "51096" => "570.50",
  183.            "51100" => "104.00",
  184.            "51102" => "1213.00",
  185.            "51310" => "622.50",
  186.            "51399" => "664.45",
  187.            "51413" => "535.50",
  188.            "51424" => "2360.00",
  189.            "51441" => "525.00",
  190.            "51475" => "7875.00",
  191.            "51510" => "481.50",
  192.            "51675" => "1318.00",
  193.            "51696" => "1308.00",
  194.            "51740" => "1462.50",
  195.            "51741" => "1830.00",
  196.            "51744" => "1809.00",
  197.            "51751" => "2531.67",
  198.            "51800" => "562.50",
  199.            "51821" => "297.50",
  200.            "51833" => "1292.00",
  201.            "51896" => "256.91",
  202.            "51944" => "586.85",
  203.            "51946" => "520.00",
  204.            "51998" => "415.63",
  205.            "52020" => "5063.33",
  206.            "52068" => "1912.00",
  207.            "52098" => "377.50",
  208.            "52126" => "380.00",
  209.            "52323" => "526.00",
  210.            "52346" => "475.00",
  211.            "52347" => "307.50",
  212.            "52348" => "340.00",
  213.            "52506" => "363.00",
  214.            "52509" => "529.00",
  215.            "52533" => "1188.50",
  216.            "52620" => "1163.00",
  217.            "52648" => "745.00",
  218.            "52863" => "8612.50",
  219.            "52923" => "1210.50",
  220.            "52959" => "142.00",
  221.            "52960" => "257.00",
  222.            "52961" => "87.00",
  223.            "52981" => "240.00",
  224.            "52982" => "173.00",
  225.            "53015" => "848.75",
  226.            "53033" => "3300.00",
  227.            "53173" => "1674.00",
  228.            "53182" => "8325.00",
  229.            "53197" => "962.50",
  230.            "53232" => "1343.50",
  231.            "53255" => "206.00",
  232.            "53257" => "206.00",
  233.            "53258" => "227.00",
  234.            "53273" => "465.00",
  235.            "53319" => "3733.34",
  236.            "53337" => "1562.50",
  237.            "53371" => "552.50",
  238.            "53374" => "552.50",
  239.            "53382" => "3417.00",
  240.            "53383" => "1455.00",
  241.            "53384" => "700.00",
  242.            "53386" => "950.00",
  243.            "53435" => "2412.80",
  244.            "53449" => "1285.00",
  245.            "53526" => "425.00",
  246.            "53558" => "2429.00",
  247.            "53666" => "720.00",
  248.            "53721" => "802.50",
  249.            "53752" => "2647.50",
  250.            "53758" => "552.50",
  251.            "53766" => "1092.50",
  252.            "53828" => "508.00",
  253.            "53838" => "2626.67",
  254.            "53875" => "190.00",
  255.            "53877" => "211.00",
  256.            "53894" => "463.13",
  257.            "53945" => "587.00",
  258.            "54008" => "1679.50",
  259.            "54038" => "1163.00",
  260.            "54091" => "3745.83",
  261.            "54098" => "1163.00",
  262.            "54133" => "657.50",
  263.            "54383" => "1205.00",
  264.            "54404" => "2054.00",
  265.            "54413" => "859.25",
  266.            "54708" => "814.25",
  267.            "55210" => "2028.00",
  268.            "55441" => "1976.00",
  269.            "55561" => "1810.50",
  270.            "55562" => "212.00",
  271.            "55566" => "526.00",
  272.            "55567" => "204.00",
  273.            "55568" => "204.00",
  274.            "55571" => "85.00",
  275.            "55575" => "110.00",
  276.            "55576" => "435.00",
  277.            "55578" => "211.00",
  278.            "55579" => "266.00",
  279.            "55580" => "142.00",
  280.            "55581" => "135.00",
  281.            "55582" => "390.00",
  282.            "55583" => "57.50",
  283.            "55584" => "23.00",
  284.            "55585" => "34.50",
  285.            "55586" => "11.50",
  286.            "55587" => "1169.00",
  287.            "55589" => "547.50",
  288.            "55590" => "227.00",
  289.            "55591" => "227.00",
  290.            "55592" => "172.00",
  291.            "55593" => "172.00",
  292.            "55594" => "859.50",
  293.            "55595" => "1190.50",
  294.            "55966" => "6897.50",
  295.            "56807" => "5554.17",
  296.            "57032" => "2028.00",
  297.            "57174" => "1346.80",
  298.            "57299" => "2028.00",
  299.            "57762" => "216.50",
  300.            "58492" => "2951.00",
  301.            "58601" => "9403.33",
  302.            "58661" => "1924.00",
  303.            "59375" => "1924.00",
  304.            "59490" => "2041.00",
  305.            "59715" => "6665.00"
  306.            
  307.            ];
  308.         
  309.         
  310.         $servername "carat-dev.cp4unapazytb.eu-central-1.rds.amazonaws.com";
  311.         $username "atimis";
  312.         $password "gui8kknyzG";
  313.         $dbname "carat_100";
  314.         
  315.         // Create connection
  316.         $conn = new \mysqli($servername$username$password$dbname);
  317.         // Check connection
  318.         if ($conn->connect_error) {
  319.           die("Connection failed: " $conn->connect_error);
  320.         }
  321.         
  322.         $conn->set_charset("utf8mb4");
  323.         
  324.         foreach($data as $storageNumber => $price) {
  325.             echo "Number: " $storageNumber " Price: " $price "<br>";
  326.             
  327.             $sql "INSERT INTO `PriceDevaluation` (`id`, `created`, `deleted`, `modified`, `note`, `price`, `creator_id`, `modificator_id`, `item_id`, `targetDate`)
  328.             VALUES (NULL, NULL, 0, NULL, 'Teilwert3', $price, NULL, NULL, (SELECT `id` FROM `Item` WHERE `stockNumber` = $storageNumber), '2023-06-30 00:00:00')";
  329.             
  330.             $result $conn->query($sql);
  331.             
  332.             var_dump($result);
  333.         }
  334.         
  335.         $conn->close();
  336.         
  337.         
  338.         exit;
  339.         
  340.         return [];
  341.     }
  342.     
  343.     /**
  344.      * @Template
  345.      * @param Request $request
  346.      * @return array
  347.      */
  348.     public function videopageAction(Request $request) {
  349.         return [];
  350.     }
  351.     
  352.     /**
  353.      * @Template
  354.      * @param Request $request
  355.      * @return array
  356.      */
  357.     public function serviceAction(Request $request) {
  358.         return [];
  359.     }
  360.     
  361.     /**
  362.      * @Template
  363.      * @param Request $request
  364.      * @return array
  365.      */
  366.     public function unternehmenAction(Request $request) {
  367.         return [];
  368.     }
  369.     
  370.     /**
  371.      * @Template
  372.      * @param Request $request
  373.      * @return array
  374.      */
  375.     public function historyAction(Request $request) {
  376.         return [];
  377.     }
  378.     
  379.     /**
  380.      * @Template
  381.      * @param Request $request
  382.      * @return array
  383.      */
  384.     public function emailAction(Request $request) {
  385.         return [];
  386.     }
  387.     
  388.     /**
  389.      * @Template
  390.      * @param Request $request
  391.      * @return array
  392.      */
  393.     public function jaegerAction(Request $request) {
  394.         return [];
  395.     }
  396.     
  397.     /**
  398.      * @Template
  399.      * @param Request $request
  400.      * @return array
  401.      */
  402.     public function aktuellesAction(Request $request) {
  403.         return [];
  404.     }
  405.     
  406.     /**
  407.      * @Template
  408.      * @param Request $request
  409.      * @return array
  410.      */
  411.     public function profileAction(Request $request) {
  412.         return [];
  413.     }
  414.     
  415.     /**
  416.      * @Template
  417.      * @param Request $request
  418.      * @return array
  419.      */
  420.     public function testassetAction(Request $request) {
  421.         
  422.         // $asset = Asset::getById(247380);
  423.         // $versions = $asset->getVersions();
  424.         // 
  425.         // $previousVersion = $versions[count($versions)-3];
  426.         // 
  427.         // $oldData = $previousVersion->getData();
  428.         // 
  429.         // var_dump($previousVersion);
  430.         // exit;
  431.         // $asset->setData($oldData);
  432.         // $asset->save();
  433.         // exit;
  434.         
  435.         
  436.         $assets = new \Pimcore\Model\Asset\Listing();
  437.         $assets->setCondition("path LIKE '%/PIM/02 Schmuck/02 Produkte/%' and type = 'image' and id != 273747 and id != 280811 and id != 273482");
  438.         // $assets->setLimit(500);
  439.         // $assets->setOffset(4499);
  440.         $assets->setOrderKey("filename");
  441.         $assets->setOrder("ASC");
  442.         $assets->load();
  443.         
  444.         foreach($assets as $asset) {
  445.             $filename $asset->getFilename();
  446.             // var_dump($filename);
  447.             //$data = file_get_contents("https://huebner.carat.solutions/carat/filedownload?fileName=" . $filename);
  448.             //var_dump($data);
  449.             
  450.             $asset->setData(file_get_contents("https://huebner.carat.solutions/carat/filedownload?fileName=" $filename));
  451.             $asset->save();
  452.         }
  453.         
  454.          echo "done";
  455.         // $newAsset = new \Pimcore\Model\Asset\Image();
  456.         // $newAsset->setFilename($filename);
  457.         // $newAsset->setData(file_get_contents("https://huebner.carat.solutions/carat/filedownload?fileName=" . $filename));
  458.         // $newAsset->setParent(\Pimcore\Model\Asset::getByPath("/Test"));
  459.         // $newAsset->save();
  460.         
  461.         exit;
  462.         return [];
  463.     }
  464.     
  465.     /**
  466.      * @Template
  467.      * @param Request $request
  468.      * @return array
  469.      */
  470.     public function inquiryAction(Request $request) {
  471.         $productid str_replace("/"""$request->get("productid"));
  472.         
  473.         $product DataObject::getById($productid);
  474.         
  475.         return $this->render('/default/inquiry.html.twig', ["product" => $product]);
  476.     }
  477.     
  478.     /**
  479.      * @Template
  480.      * @param Request $request
  481.      * @return array
  482.      */
  483.     public function sendInquiryAction(Request $request) {
  484.         if ($request->getMethod() === "POST") {
  485.                 
  486.                 
  487.             $params $request->request;
  488.             
  489.             $productId $params->get("productId");
  490.             $product DataObject::getById($productId);
  491.             $reference $product->getarticleNumber();
  492.             
  493.             $newsletter $params->get("newsletter");
  494.             $iwantto $params->get("iwantto");
  495.             $contactoption $params->get("contactoption");
  496.             $branch $params->get("branch");
  497.             $comment $params->get("comment");
  498.             $salutation $params->get("salutation");
  499.             $title $params->get("title");
  500.             $firstname $params->get("firstname");
  501.             $lastname $params->get("lastname");
  502.             $email $params->get("email");
  503.             $phone $params->get("phone");
  504.             $address $params->get("address");
  505.             $zipcode $params->get("zipcode");
  506.             $state $params->get("state");
  507.             $country $params->get("country");
  508.             
  509.             //set branch email
  510.             switch($branch) {
  511.                 case "Wien":
  512.                     $branchemail "wien@uhrenhuebner.at";
  513.                     break;
  514.                 case "Linz":
  515.                     $branchemail "linz@uhrenhuebner.at";
  516.                     break;
  517.                 case "Wels":
  518.                     $branchemail "wels@uhrenhuebner.at";
  519.                     break;
  520.             }
  521.             
  522.             $inquiry = new DataObject\Inquiry();
  523.             $inquiry->setKey(\Pimcore\Model\Element\Service::getValidKey('Anfrage-' $email date('d-m-y h:i:s'), 'object'));
  524.             $inquiry->setParentId(1833);
  525.             $inquiry->setiwantto($iwantto);
  526.             $inquiry->setcontactoption($contactoption);
  527.             $inquiry->setbranch($branch);
  528.             $inquiry->setcomment($comment);
  529.             $inquiry->setnewsletter($newsletter);
  530.             $inquiry->setsalutation($salutation);
  531.             $inquiry->settitle($title);
  532.             $inquiry->setfirstname($firstname);
  533.             $inquiry->setlastname($lastname);
  534.             $inquiry->setemail($email);
  535.             $inquiry->setphone($phone);
  536.             $inquiry->setaddress($address);
  537.             $inquiry->setzipcode($zipcode);
  538.             $inquiry->setstate($state);
  539.             $inquiry->setcountry($country);
  540.             $inquiry->setProduct($product);
  541.             $inquiry->setPublished(true);
  542.             $inquiry->save();
  543.             
  544.             $salutationtext $salutation == "Herr" "Sehr geehrter Herr" "Sehr geehrte Frau";
  545.             $productHtml $this->getProductHtml($product);
  546.             
  547.             $productHtml " " $product->getBrand()->getName() . " - " $product->getModel() . " ";
  548.             
  549.             //send User Mail
  550.             $mail = new \Pimcore\Mail();
  551.             $mail->addTo($email);
  552.             //$mail->addTo("a.daum@ontime.at");
  553.             $mail->setDocument("/Emails/inquiry-user");
  554.             $mail->setParams([
  555.                 'productHtml' => $productHtml,
  556.                 'salutation' => $salutationtext,
  557.                 'iwantto' => $iwantto,
  558.                 'contactoption' => $contactoption,
  559.                 'branch' => $branch,
  560.                 'comment' => $comment,
  561.                 'title' => $title,
  562.                 'firstname' => $firstname,
  563.                 'lastname' => $lastname,
  564.                 'email' => $email,
  565.                 'phone' => $phone,
  566.                 'address' => $address,
  567.                 'zipcode' => $zipcode,
  568.                 'state' => $state,
  569.                 'country' => $country
  570.             ]);
  571.             $mail->send();
  572.             
  573.             //send admin Mail
  574.             $mail2 = new \Pimcore\Mail();
  575.             // $mail->addTo("wien@uhrenhuebner.at");
  576.             $mail2->addTo($branchemail);
  577.             $mail2->addTo("a.daum@ontime.at");
  578.             $mail2->setDocument("/Emails/inquiry-admin");
  579.             $mail2->setParams([
  580.                 'brand' => $product->getBrand()->getName(),
  581.                 'model' => $product->getModel(),
  582.                 'reference' => $reference,
  583.                 'deeplink' => '',
  584.                 'productHtml' => $productHtml,
  585.                 'salutation' => $salutationtext,
  586.                 'iwantto' => $iwantto,
  587.                 'contactoption' => $contactoption,
  588.                 'branch' => $branch,
  589.                 'comment' => $comment,
  590.                 'title' => $title,
  591.                 'firstname' => $firstname,
  592.                 'lastname' => $lastname,
  593.                 'email' => $email,
  594.                 'phone' => $phone,
  595.                 'address' => $address,
  596.                 'zipcode' => $zipcode,
  597.                 'state' => $state,
  598.                 'country' => $country
  599.             ]);
  600.             $mail2->send();
  601.         }
  602.         return [];
  603.     }
  604.     
  605.     protected static function getProductHtml($product) {
  606.         $html '<table style="border:none;"';
  607.             $html .= '<tr>';
  608.                 $html .= '<td style="padding: 10px">';
  609.                     $html .= '<img src="https://zeit.at/'$product->getFrontImage()->getPath() . $product->getFrontImage()->getFilename() .'" alt="' $product->getModel() . '" style="width:100%; height: auto; max-width:200px";>';
  610.                 $html .= '</td>';
  611.                 $html .= '<td style="padding: 10px 0px;">';
  612.                     $html .= '<p>'.$product->getModel().'</p>';
  613.                 $html .= '</td>';
  614.             $html .= '</tr>';
  615.         $html .= '</table>';
  616.         
  617.         return $html;
  618.     }
  619.     
  620.     /**
  621.      * @Template
  622.      * @param Request $request
  623.      * @return array
  624.      */
  625.     public function loginAction(Request $request) {
  626.         if ($request->getMethod() === "POST") {
  627.             $params $request->request;
  628.             $email $params->get("email");
  629.             $password $params->get("password");
  630.             
  631.             $user DataObject::getByPath("/CRM/Users/" $email);
  632.             $passwordhash $user->getPassword();
  633.             
  634.             if(password_verify($password$passwordhash)) {
  635.                 //echo "login good";
  636.                 $loggedInUser $user;
  637.                 $cookie_name "zeituser";
  638.                 $cookie_value "4DFGHJ8765FGHJ".$user->getId()."KJHGF45678JHG4343";
  639.                 setcookie($cookie_name$cookie_valuetime() + (86400 7), "/"); 
  640.                 return $this->redirect("/");
  641.                 //return $this->render('/default/products.html.twig', ["loggedInUser" => $loggedIdUser]);
  642.                 exit;
  643.             } else {
  644.                 echo "login no good";
  645.             }
  646.             
  647.             exit;
  648.         }
  649.         return [];
  650.     }
  651.     
  652.     /**
  653.      * @Template
  654.      * @param Request $request
  655.      * @return array
  656.      */
  657.     public function registerAction(Request $request) {
  658.         if ($request->getMethod() === "POST") {
  659.             $params $request->request;
  660.             
  661.             $salutation $params->get("salutation");
  662.             $title $params->get("title");
  663.             $firstname $params->get("firstname");
  664.             $lastname $params->get("lastname");
  665.             $email $params->get("email");
  666.             $phone $params->get("phone");
  667.             $address $params->get("address");
  668.             $zipcode $params->get("zipcode");
  669.             $state $params->get("city");
  670.             $country $params->get("country");
  671.             
  672.             $password $params->get("password");
  673.             
  674.             $userobject = new DataObject\Customer();
  675.             $userobject->setKey(\Pimcore\Model\Element\Service::getValidKey($email'object'));
  676.             $userobject->setParentId(390);
  677.             
  678.             $userobject->setSalutation($salutation);
  679.             $userobject->setTitle($title);
  680.             $userobject->setFirstName($firstname);
  681.             $userobject->setLastName($lastname);
  682.             $userobject->setAddress($address);
  683.             $userobject->setZipcode($zipcode);
  684.             $userobject->setCity($state);
  685.             $userobject->setPhone($phone);
  686.             $userobject->setEmail($email);
  687.             $userobject->setUsername($email);
  688.             $userobject->setCountry($country);
  689.             
  690.             $userobject->setPassword($password);
  691.             
  692.             $userobject->setPublished(true);
  693.             $userobject->save();
  694.             
  695.             echo "saved";            
  696.             exit;
  697.         } else {
  698.             
  699.         }
  700.     }
  701.     
  702.     /**
  703.      * @Template
  704.      * @param Request $request
  705.      * @return array
  706.      */
  707.     public function logoutAction(Request $request) {
  708.         
  709.         unset($_COOKIE['zeituser']);
  710.         setcookie('zeituser'null, -1'/'); 
  711.         
  712.         exit;
  713.         return [];
  714.     }
  715.     
  716.     /**
  717.      * @Template
  718.      * @param Request $request
  719.      * @return array
  720.      */
  721.     public function checkoutAction(Request $request) {
  722.         return [];
  723.     }
  724.     
  725.     /**
  726.      * @Template
  727.      * @param Request $request
  728.      * @return array
  729.      */
  730.     public function cartAction(Request $request) {
  731.         return [];
  732.     }
  733.     
  734.     /**
  735.      * @Template
  736.      * @param Request $request
  737.      * @return array
  738.      */
  739.     public function deleteSoldProductsAction(Request $request) {
  740.         $checkstring date('d-m-y');
  741.             //$checkstring .= 'manual';
  742.         $products = new DataObject\Product\Listing();
  743.         $products->setCondition("updateinfo != '$checkstring' AND (manualInput != '1' OR manualInput IS NULL)");
  744.         $products $products->load();
  745.         if(count($products) < 100) {
  746.             foreach($products as $product) {
  747.                 $product->delete();
  748.             }
  749.         }
  750.        
  751.         exit;
  752.         return [];
  753.     
  754.     }
  755.     
  756.     /**
  757.      * @Template
  758.      * @param Request $request
  759.      * @return array
  760.      */
  761.     public function createBrandDocumentsAction(Request $request) {
  762.         // $branddocument = \Pimcore\Model\Document::getByPath("/Uhren/Marken/" . "A. Lange - Söhne");
  763.         // $branddocument->setProperty("navigation_name", "text", "A. Lange & Söhne");
  764.         // $branddocument->setController("App\Controller\DefaultController::brandAction");
  765.         // $branddocument->save();
  766.         // exit;
  767.         
  768.         $brands = new DataObject\Brand\Listing();
  769.         $brands->setCondition("o_path LIKE '%Uhren%'");
  770.         $brands $brands->load();
  771.         
  772.         foreach($brands as $brand) {
  773.             $brandkey str_replace(["&"], ["-"], $brand->getKey());
  774.             
  775.             $branddocument \Pimcore\Model\Document::getByPath("/Uhren/Marken/" $brandkey);
  776.             if($branddocument) {
  777.                 
  778.             } else {
  779.                 $page = new \Pimcore\Model\Document\Page();
  780.                 $page->setKey($brandkey);
  781.                 $page->setTitle($brand->getName());
  782.                 $page->setParentId(2);
  783.                 $page->setProperty("navigation_name""text"$brand->getName());
  784.                 $page->setController("App\Controller\DefaultController::brandAction");
  785.                 $page->setPublished(true);
  786.                 $page->save();
  787.             }
  788.         }
  789.         
  790.         exit;
  791.         return [];
  792.     }
  793.     
  794.     /**
  795.      * @Template
  796.      * @param Request $request
  797.      * @return array
  798.      */
  799.     public function createBrandFolderAction(Request $request) {
  800.         
  801.         $brands = new DataObject\Brand\Listing();
  802.         $brands->setCondition("o_path LIKE '%Uhren%'");
  803.         $brands $brands->load();
  804.         
  805.         // $brands = $brands[0];
  806.         
  807.         //var_dump($brands);
  808.         
  809.         // foreach($brands as $brand) {
  810.         //     $brandkey = str_replace(["&"], ["-"], $brand->getKey());
  811.         //     
  812.         //     $newObject = new DataObject\Folder(); 
  813.         //     $newObject->setKey(\Pimcore\Model\Element\Service::getValidKey($brandkey, 'folder'));
  814.         //     $newObject->setParentId(61);
  815.         //     $newObject->save();
  816.         //     
  817.         // }
  818.         
  819.         // $brandkey = "Jaeger-LeCoultre";
  820.         // $folder = DataObject::getByPath("/PIM/01 Uhren/02 Produkte/" . $brandkey);
  821.         // $parentId = $folder->getId();
  822.         // var_dump($folder->getId());
  823.         
  824.         exit;
  825.         return [];
  826.     }
  827.     
  828.     /**
  829.      * @Template
  830.      * @param Request $request
  831.      * @return array
  832.      */
  833.     public function addcollectionAction(Request $request) {
  834.         
  835.         
  836.         $brands = new DataObject\Brand\Listing();
  837.         $brands->setCondition("o_path LIKE '%Uhren%'");
  838.         $brands $brands->load();
  839.         
  840.         //$brand = DataObject\Brand::getById(85);
  841.             
  842.         foreach($brands as $brand) {
  843.             // $collections = new DataObject\Category\Listing();
  844.             // if($brand->getId() == 85) {
  845.             //     $collections->setCondition("o_path LIKE :brand", ["brand" => "%Nomos%"]);
  846.             // } else {
  847.             //     $collections->setCondition("o_path LIKE :brand", ["brand" => "%".$brand->getName()."%"]);
  848.             // }
  849.             // $collections->load();
  850.             
  851.             $collections $brand->getCollections();
  852.             
  853.             
  854.             if($collections) {
  855.                 $collections $collections->getChildren();
  856.             } else {
  857.                 continue;
  858.             }
  859.             
  860.             
  861.             $brandid $brand->getId();
  862.             
  863.             foreach($collections as $coll) {
  864.                 
  865.                 $key $coll->getKey();
  866.                 
  867.                 $products = new DataObject\Product\Listing();
  868.                 if($brand->getName() == "A. Lange & Söhne") {
  869.                     $products->setCondition("UPPER(`o_key`) LIKE \"%$key%\" AND brand__id = $brandid");
  870.                 } elseif($coll->getId() == 281) {
  871.                     $products->setCondition("`o_key` LIKE \"%$key%\" AND `o_key` NOT LIKE \"%Superocean Heritage%\" AND brand__id = $brandid");
  872.                 } elseif($coll->getId() == 285) {
  873.                     $products->setCondition("`o_key` LIKE \"% Avi %\" AND brand__id = $brandid");
  874.                 } else {
  875.                     $products->setCondition("`o_key` LIKE \"%$key%\" AND brand__id = $brandid");
  876.                 }
  877.                 
  878.                 $products->load();
  879.                 foreach($products as $product) {
  880.                     $cats $product->getCategories();
  881.                     if($cats) {
  882.                         if (!in_array($coll$catstrue)) {
  883.                             array_push($cats$coll);
  884.                         } 
  885.                     } else {
  886.                         array_push($cats$coll);
  887.                     }
  888.                    
  889.                     $product->setCategories($cats);
  890.                     $product->save();
  891.                 }
  892.                 
  893.             }
  894.             echo "Brand: " $brand->getName() . " done <br><hr><br>";
  895.         }
  896.             exit;
  897.         
  898.         foreach($brands as $brand) {
  899.             $collections = new DataObject\Category\Listing();
  900.             $collections->setCondition("o_path LIKE :brand", ["brand" => "%".$brand->getName()."%"]);
  901.             $collections->load();
  902.         
  903.             foreach($collections as $coll) {
  904.                 $key $coll->getKey();
  905.                 $products = new DataObject\Product\Listing();
  906.                 if($brand->getName() == "A. Lange & Söhne") {
  907.                     $products->setCondition("UPPER(`o_key`) LIKE '%$key%'");
  908.                 } else {
  909.                     $products->setCondition("`o_key` LIKE '%$key%'");
  910.                 }
  911.                 $products->load();
  912.                 foreach($products as $product) {
  913.                     $cats $product->getCategories();
  914.                     if (!in_array($coll$cats)) {
  915.                         array_push($cats$coll);
  916.                     }
  917.                     $product->setCategories($cats);
  918.                     $product->save();
  919.                 }
  920.                 
  921.             }
  922.             echo "Brand: " $brand->getName() . " done <br><hr><br>";
  923.         }
  924.         
  925.         
  926.     
  927.         exit;
  928.         return [];
  929.     }
  930.     
  931.     /**
  932.      * @Template
  933.      * @param Request $request
  934.      * @return array
  935.      */
  936.     public function testAction(Request $request) {
  937.         
  938.         ini_set('memory_limit''1024M');
  939.         $listing = new \Pimcore\Model\Document\Listing();
  940.         $listing $listing->load();
  941.         
  942.         foreach($listing as $doc) {
  943.             $key $doc->getKey();
  944.             $key str_replace(" ""-"$key);
  945.             $doc->setKey($key);
  946.             $doc->save();
  947.         }
  948.         
  949.         exit;
  950.        //  $brands = new DataObject\Product\Listing();
  951.        // 
  952.        //  
  953.        //  $brands->setCondition("o_path LIKE '%Uhren%' AND o_modificationDate > 1667284831");
  954.        //  $brands->load();
  955.        //  
  956.        //  var_dump(count($brands));
  957.         
  958.         exit;
  959.         
  960.         return [];
  961.     }
  962.     
  963.     /**
  964.      * @Template
  965.      * @param Request $request
  966.      * @return array
  967.      */
  968.     public function importSingleProductAction(Request $request) {
  969.         $searchstring str_replace("/"""$request->get("searchstring"));
  970.         
  971.         
  972.         $servername "carat-dev.cp4unapazytb.eu-central-1.rds.amazonaws.com";
  973.         $username "atimis";
  974.         $password "gui8kknyzG";
  975.         $dbname "carat_100";
  976.         
  977.         // Create connection
  978.         $conn = new \mysqli($servername$username$password$dbname);
  979.         // Check connection
  980.         if ($conn->connect_error) {
  981.           die("Connection failed: " $conn->connect_error);
  982.         }
  983.         
  984.         $conn->set_charset("utf8mb4");
  985.         
  986.         $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`;";
  987.         
  988.         $result $conn->query($sql);
  989.         
  990.         while($row $result->fetch_assoc()) {
  991.             $extId $row["id"];
  992.             
  993.             $prObject DataObject::getByPath("/PIM/01 Uhren/02 Produkte/" $row["brand"] . "/" $row["productLine"] . "-" $row["articleNumber"]);
  994.             
  995.             if($prObject) {
  996.                 $newObject $prObject;
  997.             } else {
  998.                 $newObject = new DataObject\Product(); 
  999.                 $newObject->setKey(\Pimcore\Model\Element\Service::getValidKey($row["productLine"] . "-" $row["articleNumber"], 'object'));
  1000.                 
  1001.                 $folder DataObject::getByPath("/PIM/01 Uhren/02 Produkte/" $row["brand"]);
  1002.                 if($folder == null) {
  1003.                     $folder = new DataObject\Folder(); 
  1004.                     $folder->setKey(\Pimcore\Model\Element\Service::getValidKey($row["brand"], 'folder'));
  1005.                     $folder->setParentId(61);
  1006.                     $folder->save();
  1007.                 }
  1008.                 $parentId $folder->getId();
  1009.                 
  1010.                 $newObject->setParentId($parentId);
  1011.             }
  1012.             
  1013.             $newObject->setModel($row["productLine"]);
  1014.             $newObject->setArticleNumber($row["articleNumber"]);
  1015.             $newObject->setExtId($row["id"]);
  1016.             $newObject->setPrice($row["price"]);
  1017.             //set brand
  1018.             $brand $object DataObject::getByPath("/PIM/01 Uhren/01 Marken/" $row["brand"]);
  1019.             $newObject->setBrand($brand);
  1020.             
  1021.             //set specifications
  1022.             $items = new DataObject\Fieldcollection();
  1023.             $specsql "SELECT name, value FROM `ArticleProperty` WHERE `article_id` = $extId;";
  1024.             $specresult $conn->query($specsql);
  1025.             
  1026.             while($specrow $specresult->fetch_assoc()) {
  1027.                 $item = new DataObject\Fieldcollection\Data\Specification();
  1028.                 
  1029.                 $item->setSpecKey($specrow["name"]);
  1030.                 $item->setSpecValue($specrow["value"]);
  1031.                 
  1032.                 $items->add($item);
  1033.             }
  1034.         
  1035.             $newObject->setSpecs($items);
  1036.             
  1037.             //set frontimage
  1038.             $imagesql "SELECT src FROM `Image` WHERE `article_id` = $extId;";
  1039.             $imageresult $conn->query($imagesql);
  1040.             $assetfolderpath "/PIM/01 Uhren/02 Produkte/" $row["brand"] . "/" str_replace("/""-"$row["productLine"]) . "-" $row["articleNumber"];
  1041.             Asset\Service::createFolderByPath($assetfolderpath);
  1042.             
  1043.             $counter 0;
  1044.             $addImages = [];
  1045.             while($imagerow $imageresult->fetch_assoc()) {
  1046.                 $counter += 1;
  1047.                 $newAsset = new \Pimcore\Model\Asset\Image();
  1048.                 $newAsset->setFilename($imagerow["src"]);
  1049.                 $newAsset->setData(file_get_contents("https://huebner.carat.solutions/carat/filedownload?fileName=" $imagerow["src"]));
  1050.                 $newAsset->setParent(\Pimcore\Model\Asset::getByPath($assetfolderpath));
  1051.                 
  1052.                 $checkasset null;    
  1053.                 $checkasset \Pimcore\Model\Asset::getByPath($assetfolderpath "/" $imagerow["src"]);
  1054.                 
  1055.                 if($checkasset) {
  1056.                     $newAsset $checkasset;
  1057.                 } else {
  1058.                     $newAsset->save();
  1059.                 }
  1060.                 
  1061.                 
  1062.                 if($counter == 1) {
  1063.                     $newObject->setFrontimage($newAsset);
  1064.                 } else {
  1065.                     array_push($addImages$newAsset);
  1066.                 }
  1067.             }
  1068.             
  1069.             if(count($addImages) > 0) {
  1070.                 $newObject->setImages(new \Pimcore\Model\DataObject\Data\ImageGallery($addImages));
  1071.             }
  1072.             
  1073.             
  1074.             //set gender
  1075.             $gendercat DataObject::getByPath("/PIM/01 Uhren/03 Kategorien/" $row["subcategory"]);
  1076.             $cats = [$gendercat];
  1077.             $newObject->setCategories($cats);
  1078.             
  1079.             $newObject->setPublished(true);
  1080.             $newObject->save();
  1081.             
  1082.             echo "Produkt: " $row["productLine"] . "-" $row["articleNumber"] . " erfolgreich importiert";
  1083.             
  1084.             //var_dump($brand);
  1085.         }
  1086.         
  1087.         $conn->close();
  1088.         exit;
  1089.     }
  1090.     
  1091.     /**
  1092.      * @Template
  1093.      * @param Request $request
  1094.      * @return array
  1095.      */
  1096.     public function addJewelleryCatsAction(Request $request) {
  1097.         $products = new DataObject\Product\Listing();
  1098.         $products->setCondition("o_path LIKE '%Schmuck%'");
  1099.         $products->load();
  1100.         $i 0;
  1101.         
  1102.         foreach($products as $product) {
  1103.             $catstring $product->getCatstring();
  1104.             $categories = new DataObject\Category\Listing();
  1105.             $categories->setCondition("o_path LIKE '%02 Schmuck/03 Kategorien%' AND caratvalues LIKE '%$catstring%'");
  1106.             $categories->load();
  1107.             foreach($categories as $cat) {
  1108.                 $cats $product->getCategories();
  1109.                 if(is_array($cats)) {
  1110.                     if(!in_array($cat$cats)) {
  1111.                         $cats[] = $cat;
  1112.                     }
  1113.                 } else {
  1114.                     if(!in_array($cat$cats)) {
  1115.                         $cats = [];
  1116.                         $cats[] = $cat;
  1117.                     }
  1118.                 }
  1119.                 $product->setCategories($cats);
  1120.                 $product->save();
  1121.                 $i++;
  1122.             }
  1123.         }
  1124.         
  1125.         $brands = new DataObject\Brand\Listing();
  1126.         $brands->setCondition("o_path LIKE '%Schmuck%'");
  1127.         $brands->load();
  1128.         foreach($brands as $brand) {
  1129.             $collections $brand->getCollections();
  1130.             $collections $collections->getChildren();
  1131.             $brandid $brand->getId();
  1132.             
  1133.             foreach($collections as $coll) {
  1134.                 $key $coll->getKey();
  1135.                 
  1136.                 $products = new DataObject\Product\Listing();
  1137.                 $products->setCondition("`o_key` LIKE \"%$key%\" AND brand__id = $brandid AND o_path LIKE '%Schmuck%'");
  1138.                 
  1139.                 $products->load();
  1140.                 foreach($products as $product) {
  1141.                     $cats $product->getCategories();
  1142.                     if($cats) {
  1143.                         if (!in_array($coll$catstrue)) {
  1144.                             array_push($cats$coll);
  1145.                         } 
  1146.                     } else {
  1147.                         array_push($cats$coll);
  1148.                     }
  1149.                    
  1150.                     $product->setCategories($cats);
  1151.                     $product->save();
  1152.                 }
  1153.             }
  1154.         }
  1155.         
  1156.         //echo "done $i products";
  1157.         
  1158.         exit;
  1159.         return [];
  1160.     }
  1161.     
  1162.     /**
  1163.      * @Template
  1164.      * @param Request $request
  1165.      * @return array
  1166.      */
  1167.     public function importSingleJewelleryProductAction(Request $request) {
  1168.         $servername "carat-dev.cp4unapazytb.eu-central-1.rds.amazonaws.com";
  1169.             $username "atimis";
  1170.             $password "gui8kknyzG";
  1171.             $dbname "carat_100";
  1172.             
  1173.             // Create connection
  1174.             $conn = new \mysqli($servername$username$password$dbname);
  1175.             // Check connection
  1176.             if ($conn->connect_error) {
  1177.               die("Connection failed: " $conn->connect_error);
  1178.             }
  1179.             
  1180.             $conn->set_charset("utf8mb4");
  1181.             
  1182.         
  1183.             
  1184.             
  1185.             
  1186.             
  1187.             // FINAL QUERY
  1188.             
  1189.             $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'";
  1190.             
  1191.             // END FINAL QUERY
  1192.             
  1193.             
  1194.            // $sql = "SELECT * FROM Article WHERE `brand` LIKE '%Lange%' LIMIT 10;";
  1195.             
  1196.             $result $conn->query($sql);
  1197.             
  1198.             // var_dump($result);
  1199.             // exit;
  1200.             
  1201.             while($row $result->fetch_assoc()) {
  1202.                 $extId $row["id"];
  1203.                 
  1204.                 $row array_map('trim'$row);
  1205.                 
  1206.                 $key \Pimcore\Model\Element\Service::getValidKey($row["productLine"] . "-" $row["articleNumber"], 'object');
  1207.                 
  1208.                 $prObject DataObject::getByPath("/PIM/02 Schmuck/02 Produkte/" $row["brand"] . "/" $key);
  1209.                 
  1210.                 
  1211.                 
  1212.                 if($prObject) {
  1213.                     $checkstring date('d-m-y');
  1214.                     //$checkstring .= 'manual';
  1215.                     if($prObject->getUpdateInfo() == $checkstring) {
  1216.                         continue;
  1217.                     }
  1218.                     $newObject $prObject;
  1219.                     $newObject->setupdateinfo($checkstring);
  1220.                 } else {
  1221.                     $newObject = new DataObject\Product(); 
  1222.                     $newObject->setKey($key);
  1223.                     $newObject->setupdateinfo($checkstring);
  1224.                     
  1225.                     // get Brand Folder ID
  1226.                     $folder DataObject::getByPath("/PIM/02 Schmuck/02 Produkte/" $row["brand"]);
  1227.                     
  1228.                     // if($row["brand"] == "Jaeger-LeCoultre") {
  1229.                     //     $folder = DataObject::getById(396);
  1230.                     // }
  1231.                     if($row["brand"] == "FOPE") {
  1232.                         $folder DataObject::getById(3160);
  1233.                     }
  1234.                     if($row["brand"] == "Aldusblatt Herzog Loibner") {
  1235.                         $folder DataObject::getById(1712);
  1236.                     }
  1237.                     
  1238.                     if($folder == null) {
  1239.                         $folder = new DataObject\Folder(); 
  1240.                         $folder->setKey(\Pimcore\Model\Element\Service::getValidKey($row["brand"], 'folder'));
  1241.                         $folder->setParentId(64);
  1242.                         $folder->save();
  1243.                     }
  1244.                     $parentId $folder->getId();
  1245.                     
  1246.                     $newObject->setParentId($parentId);
  1247.                 }
  1248.                 
  1249.                 $newObject->setModel($row["productLine"]);
  1250.                 $newObject->setArticleNumber($row["articleNumber"]);
  1251.                 $newObject->setStockInputDate($row["stockInputDate"]);
  1252.                 $newObject->setExtId($row["id"]);
  1253.                 $newObject->setPrice($row["price"]);
  1254.                 $newObject->setCatstring($row["subcategory"]);
  1255.                 
  1256.                 //set brand
  1257.                 $brand DataObject::getByPath("/PIM/02 Schmuck/01 Marken/" $row["brand"]);
  1258.                 // if($row["brand"] == "Jaeger-LeCoultre") {
  1259.                 //     $brand = DataObject\Brand::getById(23);
  1260.                 // }
  1261.                 if($row["brand"] == "FOPE") {
  1262.                     $brand DataObject::getById(3201);
  1263.                 }
  1264.                 if($row["brand"] == "Aldusblatt Herzog Loibner") {
  1265.                     $brand DataObject::getById(99);
  1266.                 }
  1267.                 $newObject->setBrand($brand);
  1268.                 
  1269.                 //set specifications
  1270.                 $items = new DataObject\Fieldcollection();
  1271.                 $specsql "SELECT carat, label, number, description FROM `GemItem` WHERE `article_id` = $extId;";
  1272.                 $specresult $conn->query($specsql);
  1273.                 
  1274.                 while($specrow $specresult->fetch_assoc()) {
  1275.                     $item = new DataObject\Fieldcollection\Data\JewellerySpecification();
  1276.                     
  1277.                     $item->setSpecKey($specrow["label"]);
  1278.                     $item->setSpecValue($specrow["carat"]);
  1279.                     $item->setSpecCount($specrow["number"]);
  1280.                     $item->setSpecDescription($specrow["description"]);                    
  1281.                     $items->add($item);
  1282.                 }
  1283.                 
  1284.                 $specsql "SELECT name, value FROM `ArticleProperty` WHERE `article_id` = $extId;";
  1285.                 $specresult $conn->query($specsql);
  1286.                 
  1287.                 while($specrow $specresult->fetch_assoc()) {
  1288.                     $item = new DataObject\Fieldcollection\Data\JewellerySpecification();
  1289.                     
  1290.                     $item->setSpecKey($specrow["name"]);
  1291.                     $item->setSpecValue($specrow["value"]);
  1292.                     $item->setSpecCount(null);
  1293.                     $item->setSpecDescription(null);                    
  1294.                     $items->add($item);
  1295.                 }
  1296.         
  1297.                 $newObject->setSpecs($items);
  1298.                 
  1299.                 //set frontimage
  1300.                 $imagesql "SELECT src FROM `Image` WHERE `article_id` = $extId;";
  1301.                 $imageresult $conn->query($imagesql);
  1302.                 $articlenumber str_replace("/""-"$row["articleNumber"]);
  1303.                 $assetfolderpath "/PIM/02 Schmuck/02 Produkte/" $row["brand"] . "/" str_replace(["/"'"'"+"], ["-"""""], $row["productLine"]) . "-" $articlenumber;
  1304.                 $assetfolderpath str_replace("+"""$assetfolderpath);
  1305.                 $assetfolderpath str_replace("."""$assetfolderpath);
  1306.                 $assetfolderpath str_replace("|"""$assetfolderpath);
  1307.                 $assetfolderpath str_replace("Ăź""ss"$assetfolderpath);
  1308.                 Asset\Service::createFolderByPath($assetfolderpath);
  1309.                 
  1310.                 $counter 0;
  1311.                 $addImages = [];
  1312.                 while($imagerow $imageresult->fetch_assoc()) {
  1313.                     $counter += 1;
  1314.                     $newAsset = new \Pimcore\Model\Asset\Image();
  1315.                     $newAsset->setFilename($imagerow["src"]);
  1316.                     $newAsset->setData(file_get_contents("https://huebner.carat.solutions/carat/filedownload?fileName=" $imagerow["src"]));
  1317.                     $newAsset->setParent(\Pimcore\Model\Asset::getByPath($assetfolderpath));
  1318.                     
  1319.                     $checkasset null;    
  1320.                     $checkasset \Pimcore\Model\Asset::getByPath($assetfolderpath "/" $imagerow["src"]);
  1321.                     
  1322.                     echo "trying to save asset for " $row["productLine"] . "-" $row["articleNumber"] . "<br><hr><br>";
  1323.                     
  1324.                     if(strpos($imagerow["src"], "html") == false && strpos($imagerow["src"], "avif") == false && $imagerow["src"] != "7281fa99-3001-41a5-9be1-8dcfe04d997b.") {
  1325.                         if($checkasset) {
  1326.                             $checkasset->delete();
  1327.                             $newAsset->save();
  1328.                         } else {
  1329.                             $newAsset->save();
  1330.                         }
  1331.                     }
  1332.                     if($counter == 1) {
  1333.                         $newObject->setFrontimage($newAsset);
  1334.                     } else {
  1335.                         $advancedImage = new \Pimcore\Model\DataObject\Data\Hotspotimage();
  1336.                         $advancedImage->setImage($newAsset);
  1337.                         array_push($addImages$advancedImage);
  1338.                     }
  1339.                 }
  1340.                 
  1341.                 if(count($addImages) > 0) {   
  1342.                     $newObject->setImages(new \Pimcore\Model\DataObject\Data\ImageGallery($addImages));
  1343.                 }
  1344.                 
  1345.                 //var_dump($addImages);
  1346.                 
  1347.                 
  1348.                 //set gender
  1349.                 // $gendercat = DataObject::getByPath("/PIM/01 Uhren/03 Kategorien/" . $row["subcategory"]);
  1350.                 // if(!$gendercat) {
  1351.                 //     $newcat = new DataObject\Category(); 
  1352.                 //     $newcat->setKey(\Pimcore\Model\Element\Service::getValidKey($row["subcategory"], 'object'));
  1353.                 //     $newcat->setParentId(101);
  1354.                 //     $newcat->setTitle($row["subcategory"]);
  1355.                 //     $newcat->setPublished(true);
  1356.                 //     $newcat->save();
  1357.                 //     $gendercat = $newcat;
  1358.                 // }
  1359.                 
  1360.                 // $cats = [$gendercat];
  1361.                 // $newObject->setCategories($cats);
  1362.                 
  1363.                 $newObject->setPublished(true);
  1364.                 $newObject->save();
  1365.                 
  1366.                 //var_dump($brand);
  1367.             }
  1368.             
  1369.             $conn->close();
  1370.             
  1371.             
  1372.             exit;
  1373.             return [];
  1374.     }
  1375.     
  1376.     /**
  1377.      * @Template
  1378.      * @param Request $request
  1379.      * @return array
  1380.      */
  1381.     public function updateProductAction(Request $request) {
  1382.         
  1383.         $id str_replace("/"""$request->get("caratid"));
  1384.         $pimId str_replace("/"""$request->get("pimid"));
  1385.         
  1386.         $servername "carat-dev.cp4unapazytb.eu-central-1.rds.amazonaws.com";
  1387.         //$servername = "52.29.59.182";
  1388.         $username "atimis";
  1389.         $password "gui8kknyzG";
  1390.         $dbname "carat_100";
  1391.         
  1392.         // Create connection
  1393.         $conn = new \mysqli($servername$username$password$dbname);
  1394.         // Check connection
  1395.         if ($conn->connect_error) {
  1396.           die("Connection failed: " $conn->connect_error);
  1397.         }
  1398.         
  1399.         
  1400.         $conn->set_charset("utf8mb4");
  1401.         
  1402.         // FINAL QUERY
  1403.         
  1404.         $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`";
  1405.         
  1406.         // END FINAL QUERY
  1407.         
  1408.         
  1409.        // $sql = "SELECT * FROM Article WHERE `brand` LIKE '%Lange%' LIMIT 10;";
  1410.         
  1411.         $result $conn->query($sql);
  1412.         
  1413.         // var_dump($result);
  1414.         // exit;
  1415.         
  1416.         while($row $result->fetch_assoc()) {
  1417.             $extId $row["id"];
  1418.             $row array_map('trim'$row);
  1419.             
  1420.             $watchjewel $row["category"];
  1421.             
  1422.             if($watchjewel == "Uhr") {
  1423.                 $key \Pimcore\Model\Element\Service::getValidKey($row["productLine"] . "-" $row["articleNumber"], 'object');
  1424.                 
  1425.                 $prObject DataObject::getById($pimId);
  1426.                 $checkstring date('d-m-y');
  1427.             //$checkstring .= 'manual';
  1428.                 // $checkstring .= "-zenith";
  1429.                 if($prObject) {
  1430.                     // if($prObject->getUpdateinfo() == "291122-try1" || $prObject->getUpdateinfo() == "291122-try2" || $prObject->getUpdateinfo() == "291122-try3" || $prObject->getUpdateinfo() == "291122-try4") {
  1431.                     //     continue;
  1432.                     // }
  1433.                     
  1434.                     
  1435.                     if($prObject->getUpdateInfo() == $checkstring) {
  1436.                         //continue;
  1437.                     }
  1438.                     $newObject $prObject;
  1439.                     $newObject->setupdateinfo($checkstring);
  1440.                 } else {
  1441.                     $newObject = new DataObject\Product(); 
  1442.                     $newObject->setKey($key);
  1443.                     $newObject->setupdateinfo($checkstring);
  1444.                     
  1445.                     // get Brand Folder ID
  1446.                     $folder DataObject::getByPath("/PIM/01 Uhren/02 Produkte/" $row["brand"]);
  1447.                     
  1448.                     if($row["brand"] == "Jaeger-LeCoultre") {
  1449.                         $folder DataObject::getById(396);
  1450.                     }
  1451.                     if($row["brand"] == "IWC") {
  1452.                         $folder DataObject::getById(962);
  1453.                     }
  1454.                     if($row["brand"] == "Nomos GlashĂĽtte") {
  1455.                         $folder DataObject::getById(407);
  1456.                     }
  1457.                     
  1458.                     if($folder == null) {
  1459.                         $folder = new DataObject\Folder(); 
  1460.                         $folder->setKey(\Pimcore\Model\Element\Service::getValidKey($row["brand"], 'folder'));
  1461.                         $folder->setParentId(61);
  1462.                         $folder->save();
  1463.                     }
  1464.                     $parentId $folder->getId();
  1465.                     
  1466.                     $newObject->setParentId($parentId);
  1467.                 }
  1468.                 
  1469.                 $newObject->setModel($row["productLine"]);
  1470.                 $newObject->setArticleNumber($row["articleNumber"]);
  1471.                 $newObject->setStockInputDate($row["stockInputDate"]);
  1472.                 $newObject->setExtId($row["id"]);
  1473.                 $newObject->setPrice($row["price"]);
  1474.                 
  1475.                 //set brand
  1476.                 $brand DataObject::getByPath("/PIM/01 Uhren/01 Marken/" $row["brand"]);
  1477.                 if($row["brand"] == "Jaeger-LeCoultre") {
  1478.                     $brand DataObject\Brand::getById(23);
  1479.                 }
  1480.                 if($row["brand"] == "IWC") {
  1481.                     $brand DataObject\Brand::getById(82);
  1482.                 }
  1483.                 if($row["brand"] == "Nomos GlashĂĽtte") {
  1484.                     $brand DataObject\Brand::getById(85);
  1485.                 }
  1486.                 if($row["brand"] == "Sattler") {
  1487.                     $brand DataObject\Brand::getById(77);
  1488.                 }
  1489.                 $newObject->setBrand($brand);
  1490.                 
  1491.                 //set specifications
  1492.                 $items = new DataObject\Fieldcollection();
  1493.                 $specsql "SELECT name, value FROM `ArticleProperty` WHERE `article_id` = $extId;";
  1494.                 $specresult $conn->query($specsql);
  1495.                 
  1496.                 while($specrow $specresult->fetch_assoc()) {
  1497.                     $item = new DataObject\Fieldcollection\Data\Specification();
  1498.                     
  1499.                     $item->setSpecKey($specrow["name"]);
  1500.                     $item->setSpecValue($specrow["value"]);
  1501.                     
  1502.                     $items->add($item);
  1503.                 }
  1504.                 
  1505.                 $newObject->setSpecs($items);
  1506.                 
  1507.                 //set frontimage
  1508.                 $imagesql "SELECT src FROM `Image` WHERE `article_id` = $extId;";
  1509.                 $imageresult $conn->query($imagesql);
  1510.                 $articlenumber str_replace("/""-"$row["articleNumber"]);
  1511.                 $assetfolderpath "/PIM/01 Uhren/02 Produkte/" $row["brand"] . "/" str_replace(["/"'"'"+"], ["-"""""], $row["productLine"]) . "-" $articlenumber;
  1512.                 $assetfolderpath str_replace("+"""$assetfolderpath);
  1513.                 $assetfolderpath str_replace("."""$assetfolderpath);
  1514.                 $assetfolderpath str_replace("|"""$assetfolderpath);
  1515.                 $assetfolderpath str_replace("Ăź""ss"$assetfolderpath);
  1516.                 Asset\Service::createFolderByPath($assetfolderpath);
  1517.                 
  1518.                 $counter 0;
  1519.                 $addImages = [];
  1520.                 while($imagerow $imageresult->fetch_assoc()) {
  1521.                     $counter += 1;
  1522.                     $newAsset = new \Pimcore\Model\Asset\Image();
  1523.                     $newAsset->setFilename($imagerow["src"]);
  1524.                     $newAsset->setData(file_get_contents("https://huebner.carat.solutions/carat/filedownload?fileName=" $imagerow["src"]));
  1525.                     $newAsset->setParent(\Pimcore\Model\Asset::getByPath($assetfolderpath));
  1526.                     
  1527.                     $checkasset null;    
  1528.                     $checkasset \Pimcore\Model\Asset::getByPath($assetfolderpath "/" $imagerow["src"]);
  1529.                     
  1530.                     //echo "trying to save asset for " . $row["productLine"] . "-" . $row["articleNumber"] . "<br><hr><br>";
  1531.                     
  1532.                     if(strpos($imagerow["src"], "html") == false && strpos($imagerow["src"], "avif") == false && $imagerow["src"] != "7281fa99-3001-41a5-9be1-8dcfe04d997b.") {
  1533.                         if($checkasset) {
  1534.                            $checkasset->delete();
  1535.                            $newAsset->save();
  1536.                         } else {
  1537.                             // var_dump($newAsset->getFullPath());
  1538.                             // var_dump($assetfolderpath);
  1539.                             // var_dump(\Pimcore\Model\Asset::getByPath($assetfolderpath));
  1540.                             // exit;
  1541.                             $newAsset->save();
  1542.                         }
  1543.                     }
  1544.                     if($counter == 1) {
  1545.                         $newObject->setFrontimage($newAsset);
  1546.                     } else {
  1547.                         $advancedImage = new \Pimcore\Model\DataObject\Data\Hotspotimage();
  1548.                         $advancedImage->setImage($newAsset);
  1549.                         array_push($addImages$advancedImage);
  1550.                     }
  1551.                 }
  1552.                 
  1553.                 if(count($addImages) > 0) {   
  1554.                     $newObject->setImages(new \Pimcore\Model\DataObject\Data\ImageGallery($addImages));
  1555.                 }
  1556.                 
  1557.                 //var_dump($addImages);
  1558.                 
  1559.                 
  1560.                 //set gender
  1561.                 $gendercat DataObject::getByPath("/PIM/01 Uhren/03 Kategorien/" $row["subcategory"]);
  1562.                 if(!$gendercat) {
  1563.                     $newcat = new DataObject\Category(); 
  1564.                     $newcat->setKey(\Pimcore\Model\Element\Service::getValidKey($row["subcategory"], 'object'));
  1565.                     $newcat->setParentId(101);
  1566.                     $newcat->setTitle($row["subcategory"]);
  1567.                     $newcat->setPublished(true);
  1568.                     $newcat->save();
  1569.                     $gendercat $newcat;
  1570.                 }
  1571.                 
  1572.                 $cats = [$gendercat];
  1573.                 $newObject->setCategories($cats);
  1574.                 
  1575.                 $newObject->setPublished(true);
  1576.                 $newObject->save();
  1577.                 
  1578.                 $this->addBrandCollections($brand);
  1579.                 
  1580.             } elseif($watchjewel == "Schmuck") {
  1581.                
  1582.                 $key \Pimcore\Model\Element\Service::getValidKey($row["productLine"] . "-" $row["articleNumber"], 'object');
  1583.                 
  1584.                 $prObject DataObject::getById($pimId);
  1585.                 $checkstring date('d-m-y');
  1586.             //$checkstring .= 'manual';
  1587.                 // $checkstring .= "-zenith";
  1588.                 if($prObject) {
  1589.                     // if($prObject->getUpdateinfo() == "291122-try1" || $prObject->getUpdateinfo() == "291122-try2" || $prObject->getUpdateinfo() == "291122-try3" || $prObject->getUpdateinfo() == "291122-try4") {
  1590.                     //     continue;
  1591.                     // }
  1592.                     
  1593.                     
  1594.                     if($prObject->getUpdateInfo() == $checkstring) {
  1595.                         //continue;
  1596.                     }
  1597.                     $newObject $prObject;
  1598.                     $newObject->setupdateinfo($checkstring);
  1599.                 } else {
  1600.                     $newObject = new DataObject\Product(); 
  1601.                     $newObject->setKey($key);
  1602.                     $newObject->setupdateinfo($checkstring);
  1603.                     
  1604.                     // get Brand Folder ID
  1605.                     $folder DataObject::getByPath("/PIM/02 Schmuck/02 Produkte/" $row["brand"]);
  1606.                     
  1607.                     if($folder == null) {
  1608.                         $folder = new DataObject\Folder(); 
  1609.                         $folder->setKey(\Pimcore\Model\Element\Service::getValidKey($row["brand"], 'folder'));
  1610.                         $folder->setParentId(64);
  1611.                         $folder->save();
  1612.                     }
  1613.                     $parentId $folder->getId();
  1614.                     
  1615.                     $newObject->setParentId($parentId);
  1616.                 }
  1617.                 
  1618.                 $newObject->setModel($row["productLine"]);
  1619.                 $newObject->setArticleNumber($row["articleNumber"]);
  1620.                 $newObject->setStockInputDate($row["stockInputDate"]);
  1621.                 $newObject->setExtId($row["id"]);
  1622.                 $newObject->setPrice($row["price"]);
  1623.                 
  1624.                 //set brand
  1625.                 $brand DataObject::getByPath("/PIM/02 Schmuck/01 Marken/" $row["brand"]);
  1626.                 if($row["brand"] == "Jaeger-LeCoultre") {
  1627.                     $brand DataObject\Brand::getById(23);
  1628.                 }
  1629.                 if($row["brand"] == "IWC") {
  1630.                     $brand DataObject\Brand::getById(82);
  1631.                 }
  1632.                 if($row["brand"] == "Nomos GlashĂĽtte") {
  1633.                     $brand DataObject\Brand::getById(85);
  1634.                 }
  1635.                 if($row["brand"] == "Sattler") {
  1636.                     $brand DataObject\Brand::getById(77);
  1637.                 }
  1638.                 $newObject->setBrand($brand);
  1639.                 
  1640.                 //set specifications
  1641.                 $items = new DataObject\Fieldcollection();
  1642.                 $specsql "SELECT name, value FROM `ArticleProperty` WHERE `article_id` = $extId;";
  1643.                 $specresult $conn->query($specsql);
  1644.                 
  1645.                 while($specrow $specresult->fetch_assoc()) {
  1646.                     $item = new DataObject\Fieldcollection\Data\Specification();
  1647.                     
  1648.                     $item->setSpecKey($specrow["name"]);
  1649.                     $item->setSpecValue($specrow["value"]);
  1650.                     
  1651.                     $items->add($item);
  1652.                 }
  1653.                 
  1654.                 $newObject->setSpecs($items);
  1655.                 
  1656.                 //set frontimage
  1657.                 $imagesql "SELECT src FROM `Image` WHERE `article_id` = $extId;";
  1658.                 $imageresult $conn->query($imagesql);
  1659.                 $articlenumber str_replace("/""-"$row["articleNumber"]);
  1660.                 $assetfolderpath "/PIM/02 Schmuck/02 Produkte/" $row["brand"] . "/" str_replace(["/"'"'"+"], ["-"""""], $row["productLine"]) . "-" $articlenumber;
  1661.                 $assetfolderpath str_replace("+"""$assetfolderpath);
  1662.                 $assetfolderpath str_replace("."""$assetfolderpath);
  1663.                 $assetfolderpath str_replace("|"""$assetfolderpath);
  1664.                 $assetfolderpath str_replace("Ăź""ss"$assetfolderpath);
  1665.                 Asset\Service::createFolderByPath($assetfolderpath);
  1666.                 
  1667.                 $counter 0;
  1668.                 $addImages = [];
  1669.                 while($imagerow $imageresult->fetch_assoc()) {
  1670.                     $counter += 1;
  1671.                     $newAsset = new \Pimcore\Model\Asset\Image();
  1672.                     $newAsset->setFilename($imagerow["src"]);
  1673.                     $newAsset->setData(file_get_contents("https://huebner.carat.solutions/carat/filedownload?fileName=" $imagerow["src"]));
  1674.                     $newAsset->setParent(\Pimcore\Model\Asset::getByPath($assetfolderpath));
  1675.                     
  1676.                     $checkasset null;    
  1677.                     $checkasset \Pimcore\Model\Asset::getByPath($assetfolderpath "/" $imagerow["src"]);
  1678.                     
  1679.                     //echo "trying to save asset for " . $row["productLine"] . "-" . $row["articleNumber"] . "<br><hr><br>";
  1680.                     
  1681.                     if(strpos($imagerow["src"], "html") == false && strpos($imagerow["src"], "avif") == false && $imagerow["src"] != "7281fa99-3001-41a5-9be1-8dcfe04d997b.") {
  1682.                         if($checkasset) {
  1683.                            $checkasset->delete();
  1684.                            $newAsset->save();
  1685.                         } else {
  1686.                             // var_dump($newAsset->getFullPath());
  1687.                             // var_dump($assetfolderpath);
  1688.                             // var_dump(\Pimcore\Model\Asset::getByPath($assetfolderpath));
  1689.                             // exit;
  1690.                             $newAsset->save();
  1691.                         }
  1692.                     }
  1693.                     if($counter == 1) {
  1694.                         $newObject->setFrontimage($newAsset);
  1695.                     } else {
  1696.                         $advancedImage = new \Pimcore\Model\DataObject\Data\Hotspotimage();
  1697.                         $advancedImage->setImage($newAsset);
  1698.                         array_push($addImages$advancedImage);
  1699.                     }
  1700.                 }
  1701.                 
  1702.                 if(count($addImages) > 0) {   
  1703.                     $newObject->setImages(new \Pimcore\Model\DataObject\Data\ImageGallery($addImages));
  1704.                 }
  1705.                 
  1706.                 //var_dump($addImages);
  1707.                 
  1708.                 
  1709.                 //set gender
  1710.                 // $gendercat = DataObject::getByPath("/PIM/01 Uhren/03 Kategorien/" . $row["subcategory"]);
  1711.                 // if(!$gendercat) {
  1712.                 //     $newcat = new DataObject\Category(); 
  1713.                 //     $newcat->setKey(\Pimcore\Model\Element\Service::getValidKey($row["subcategory"], 'object'));
  1714.                 //     $newcat->setParentId(101);
  1715.                 //     $newcat->setTitle($row["subcategory"]);
  1716.                 //     $newcat->setPublished(true);
  1717.                 //     $newcat->save();
  1718.                 //     $gendercat = $newcat;
  1719.                 // }
  1720.                 // 
  1721.                 // $cats = [$gendercat];
  1722.                 // $newObject->setCategories($cats);
  1723.                 
  1724.                 $newObject->setPublished(true);
  1725.                 $newObject->save();
  1726.                 
  1727.                 $this->addBrandCollections($brand);
  1728.             }
  1729.             
  1730.             
  1731.             
  1732.             //var_dump($brand);
  1733.         }
  1734.         
  1735.         $conn->close();
  1736.         
  1737.         echo "success";
  1738.         
  1739.         exit;
  1740.         return [];
  1741.     }
  1742.     
  1743.     /**
  1744.      * @Template
  1745.      * @param Request $request
  1746.      * @return array
  1747.      */
  1748.     public function importAction(Request $request) {
  1749.         
  1750.         $servername "carat-dev.cp4unapazytb.eu-central-1.rds.amazonaws.com";
  1751.         //$servername = "52.29.59.182";
  1752.         $username "atimis";
  1753.         $password "gui8kknyzG";
  1754.         $dbname "carat_100";
  1755.         
  1756.         // Create connection
  1757.         $conn = new \mysqli($servername$username$password$dbname);
  1758.         // Check connection
  1759.         if ($conn->connect_error) {
  1760.           die("Connection failed: " $conn->connect_error);
  1761.         }
  1762.         
  1763.         
  1764.         $conn->set_charset("utf8mb4");
  1765.         
  1766.         
  1767.         //$sql = "SELECT * FROM Article LIMIT 10";
  1768.         
  1769.         // $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;";
  1770.         
  1771.         // $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";
  1772.         
  1773.         // $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`;";
  1774.         
  1775.         // fix " "
  1776.         
  1777.         // $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`";
  1778.         
  1779.         // BRAND QUERY
  1780.         
  1781.         // $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`";
  1782.         
  1783.         
  1784.         // FINAL QUERY
  1785.         
  1786.         $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`";
  1787.         
  1788.         // $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`";
  1789.         
  1790.         // END FINAL QUERY
  1791.         
  1792.         
  1793.        // $sql = "SELECT * FROM Article WHERE `brand` LIKE '%Lange%' LIMIT 10;";
  1794.         
  1795.         $result $conn->query($sql);
  1796.         
  1797.         // var_dump($result);
  1798.         // exit;
  1799.         
  1800.         while($row $result->fetch_assoc()) {
  1801.             $extId $row["id"];
  1802.             $row array_map('trim'$row);
  1803.   
  1804.             
  1805.             $key \Pimcore\Model\Element\Service::getValidKey($row["productLine"] . "-" $row["articleNumber"], 'object');
  1806.             
  1807.             $prObject DataObject::getByPath("/PIM/01 Uhren/02 Produkte/" $row["brand"] . "/" $key);
  1808.             $checkstring date('d-m-y');
  1809.             //$checkstring .= 'manual';
  1810.             // $checkstring .= "-zenith";
  1811.             if($prObject) {
  1812.                 // if($prObject->getUpdateinfo() == "291122-try1" || $prObject->getUpdateinfo() == "291122-try2" || $prObject->getUpdateinfo() == "291122-try3" || $prObject->getUpdateinfo() == "291122-try4") {
  1813.                 //     continue;
  1814.                 // }
  1815.                 
  1816.                 
  1817.                 if($prObject->getUpdateInfo() == $checkstring) {
  1818.                     continue;
  1819.                 }
  1820.                 $newObject $prObject;
  1821.                 $newObject->setupdateinfo($checkstring);
  1822.             } else {
  1823.                 $newObject = new DataObject\Product(); 
  1824.                 $newObject->setKey($key);
  1825.                 $newObject->setupdateinfo($checkstring);
  1826.                 
  1827.                 // get Brand Folder ID
  1828.                 $folder DataObject::getByPath("/PIM/01 Uhren/02 Produkte/" $row["brand"]);
  1829.                 
  1830.                 if($row["brand"] == "Jaeger-LeCoultre") {
  1831.                     $folder DataObject::getById(396);
  1832.                 }
  1833.                 if($row["brand"] == "IWC") {
  1834.                     $folder DataObject::getById(962);
  1835.                 }
  1836.                 if($row["brand"] == "Nomos GlashĂĽtte") {
  1837.                     $folder DataObject::getById(407);
  1838.                 }
  1839.                 
  1840.                 if($folder == null) {
  1841.                     $folder = new DataObject\Folder(); 
  1842.                     $folder->setKey(\Pimcore\Model\Element\Service::getValidKey($row["brand"], 'folder'));
  1843.                     $folder->setParentId(61);
  1844.                     $folder->save();
  1845.                 }
  1846.                 $parentId $folder->getId();
  1847.                 
  1848.                 $newObject->setParentId($parentId);
  1849.             }
  1850.             
  1851.             $newObject->setModel($row["productLine"]);
  1852.             $newObject->setArticleNumber($row["articleNumber"]);
  1853.             $newObject->setStockInputDate($row["stockInputDate"]);
  1854.             $newObject->setExtId($row["id"]);
  1855.             $newObject->setPrice($row["price"]);
  1856.             
  1857.             //set brand
  1858.             $brand DataObject::getByPath("/PIM/01 Uhren/01 Marken/" $row["brand"]);
  1859.             if($row["brand"] == "Jaeger-LeCoultre") {
  1860.                 $brand DataObject\Brand::getById(23);
  1861.             }
  1862.             if($row["brand"] == "IWC") {
  1863.                 $brand DataObject\Brand::getById(82);
  1864.             }
  1865.             if($row["brand"] == "Nomos GlashĂĽtte") {
  1866.                 $brand DataObject\Brand::getById(85);
  1867.             }
  1868.             if($row["brand"] == "Sattler") {
  1869.                 $brand DataObject\Brand::getById(77);
  1870.             }
  1871.             $newObject->setBrand($brand);
  1872.             
  1873.             //set specifications
  1874.             $items = new DataObject\Fieldcollection();
  1875.             $specsql "SELECT name, value FROM `ArticleProperty` WHERE `article_id` = $extId;";
  1876.             $specresult $conn->query($specsql);
  1877.             
  1878.             while($specrow $specresult->fetch_assoc()) {
  1879.                 $item = new DataObject\Fieldcollection\Data\Specification();
  1880.                 
  1881.                 $item->setSpecKey($specrow["name"]);
  1882.                 $item->setSpecValue($specrow["value"]);
  1883.                 
  1884.                 $items->add($item);
  1885.             }
  1886.             $newObject->setSpecs($items);
  1887.             
  1888.             //set frontimage
  1889.             $imagesql "SELECT src FROM `Image` WHERE `article_id` = $extId;";
  1890.             $imageresult $conn->query($imagesql);
  1891.             $articlenumber str_replace("/""-"$row["articleNumber"]);
  1892.             $assetfolderpath "/PIM/01 Uhren/02 Produkte/" $row["brand"] . "/" str_replace(["/"'"'"+"], ["-"""""], $row["productLine"]) . "-" $articlenumber;
  1893.             $assetfolderpath str_replace("+"""$assetfolderpath);
  1894.             $assetfolderpath str_replace("."""$assetfolderpath);
  1895.             $assetfolderpath str_replace("|"""$assetfolderpath);
  1896.             $assetfolderpath str_replace("Ăź""ss"$assetfolderpath);
  1897.             Asset\Service::createFolderByPath($assetfolderpath);
  1898.             
  1899.             $counter 0;
  1900.             $addImages = [];
  1901.             while($imagerow $imageresult->fetch_assoc()) {
  1902.                 $counter += 1;
  1903.                 $newAsset = new \Pimcore\Model\Asset\Image();
  1904.                 $newAsset->setFilename($imagerow["src"]);
  1905.                 $newAsset->setData(file_get_contents("https://huebner.carat.solutions/carat/filedownload?fileName=" $imagerow["src"]));
  1906.                 $newAsset->setParent(\Pimcore\Model\Asset::getByPath($assetfolderpath));
  1907.                 
  1908.                 $checkasset null;    
  1909.                 $checkasset \Pimcore\Model\Asset::getByPath($assetfolderpath "/" $imagerow["src"]);
  1910.                 
  1911.                 echo "trying to save asset for " $row["productLine"] . "-" $row["articleNumber"] . "<br><hr><br>";
  1912.                 
  1913.                 if(strpos($imagerow["src"], "html") == false && strpos($imagerow["src"], "htm") == false && $imagerow["src"] != "7281fa99-3001-41a5-9be1-8dcfe04d997b.") {
  1914.                     if($checkasset) {
  1915.                        $checkasset->setData(file_get_contents("https://huebner.carat.solutions/carat/filedownload?fileName=" $imagerow["src"]));
  1916.                        $checkasset->save();
  1917.                        $newAsset $checkasset;
  1918.                     } else {
  1919.                         // var_dump($newAsset->getFullPath());
  1920.                         // var_dump($assetfolderpath);
  1921.                         // var_dump(\Pimcore\Model\Asset::getByPath($assetfolderpath));
  1922.                         // exit;
  1923.                         $newAsset->save();
  1924.                     }
  1925.                     $newAsset->save();
  1926.                 }
  1927.                 if($counter == 1) {
  1928.                     $newObject->setFrontimage($newAsset);
  1929.                 } else {
  1930.                     $advancedImage = new \Pimcore\Model\DataObject\Data\Hotspotimage();
  1931.                     $advancedImage->setImage($newAsset);
  1932.                     array_push($addImages$advancedImage);
  1933.                 }
  1934.             }
  1935.             
  1936.             if(count($addImages) > 0) {   
  1937.                 $newObject->setImages(new \Pimcore\Model\DataObject\Data\ImageGallery($addImages));
  1938.             }
  1939.             
  1940.             //var_dump($addImages);
  1941.             
  1942.             
  1943.             //set gender
  1944.             $gendercat DataObject::getByPath("/PIM/01 Uhren/03 Kategorien/" $row["subcategory"]);
  1945.             if(!$gendercat) {
  1946.                 $newcat = new DataObject\Category(); 
  1947.                 $newcat->setKey(\Pimcore\Model\Element\Service::getValidKey($row["subcategory"], 'object'));
  1948.                 $newcat->setParentId(101);
  1949.                 $newcat->setTitle($row["subcategory"]);
  1950.                 $newcat->setPublished(true);
  1951.                 $newcat->save();
  1952.                 $gendercat $newcat;
  1953.             }
  1954.             
  1955.             $cats = [$gendercat];
  1956.             $newObject->setCategories($cats);
  1957.             
  1958.             $newObject->setPublished(true);
  1959.             $newObject->save();
  1960.             
  1961.             //var_dump($brand);
  1962.         }
  1963.         
  1964.         $conn->close();
  1965.         
  1966.         
  1967.         exit;
  1968.         return [];
  1969.     }
  1970.     
  1971.     /**
  1972.      * @Template
  1973.      * @param Request $request
  1974.      * @return array
  1975.      */
  1976.     public function categoryAction(Request $request) {
  1977.         
  1978.         
  1979.         return [];
  1980.     }
  1981.     
  1982.     
  1983.     /**
  1984.      * @Template
  1985.      * @param Request $request
  1986.      * @return array
  1987.      */
  1988.     public function homeAction(Request $request) {
  1989.         return [];
  1990.     }
  1991.     
  1992.     /**
  1993.      * @Template
  1994.      * @param Request $request
  1995.      * @return array
  1996.      */
  1997.     public function productOverviewAction(Request $request) {
  1998.         $jewellerycategory null;
  1999.         $entries = new DataObject\Product\Listing();
  2000.         $filters = [];
  2001.         
  2002.         $page = isset($_GET["page"]) ? $_GET["page"] : null;
  2003.         if($page) {
  2004.             if($page == 1) {
  2005.                 $entries->setLimit(24);
  2006.             }
  2007.             $filters["page"] = $page;
  2008.         }
  2009.         
  2010.         $collection = isset($_GET["collection"]) ? $_GET["collection"] : null;
  2011.         if($collection) {
  2012.             $entries->addConditionParam("categories LIKE ?""%object|$collection%""AND");
  2013.             $filters["collection"] = $collection;
  2014.         }
  2015.         
  2016.         $type = isset($_GET["type"]) ? $_GET["type"] : null;
  2017.         if($type) {
  2018.             //$entries->addConditionParam("categories LIKE ?", "%object|$type%", "AND");
  2019.             $entries->setCondition("categories LIKE '%object|$type%'");
  2020.             $filters["type"] = $type;
  2021.         }
  2022.         
  2023.         $brand = isset($_GET["brand"]) ? $_GET["brand"] : null;
  2024.         if($brand) {
  2025.             $entries->addConditionParam("brand__id = ?""$brand""AND");
  2026.             $brandobject DataObject::getById($brand);
  2027.             $brandcollections $brandobject->getCollections() ? $brandobject->getCollections()->getChildren() : null;
  2028.             
  2029.             $filters["brand"] = $brand;
  2030.             $filters["brandCollections"] = $brandcollections;
  2031.         } 
  2032.         if (!$brand && $collection) {
  2033.             $collectionObject DataObject::getById($collection);
  2034.                 // var_dump($collection);
  2035.                 // exit;
  2036.             
  2037.             
  2038.             $collectionpath $collectionObject->getPath();
  2039.             // var_dump($collectionpath);
  2040.             // exit;
  2041.             if(str_contains($collectionpath"Schmuck")) {
  2042.                 
  2043.                 $entries->addConditionParam("o_path LIKE '%Schmuck%'""AND");
  2044.                 $jewellerycategory $collectionObject;
  2045.             } else {
  2046.                 $brandkey $collectionObject->getParent()->getKey();
  2047.                 
  2048.                 $brands DataObject\Brand::getByName($brandkey);
  2049.                 $brand $brands->load();
  2050.                 if(is_array($brand)) {
  2051.                     $brand $brand[0];
  2052.                     $brandobject $brand;
  2053.                     $brandcollections $brandobject->getCollections() ? $brandobject->getCollections()->getChildren() : null;
  2054.                     
  2055.                     $filters["brand"] = $brand->getId();
  2056.                     $filters["brandCollections"] = $brandcollections;
  2057.                 } else {
  2058.                     $brand null;
  2059.                     $filters["brand"] = null;
  2060.                     $filters["brandCollections"] = null;
  2061.                 }
  2062.             }
  2063.             
  2064.             
  2065.             
  2066.         }
  2067.         
  2068.         if(!isset($filters["brandCollections"])) {
  2069.             $brandCollections = new DataObject\Category\Listing();
  2070.             $brandCollections->setCondition("o_path LIKE '%Kollektionen%'");
  2071.             $brandCollections $brandCollections->load();
  2072.             $filters["brandCollections"] = $brandCollections;
  2073.         }
  2074.         
  2075.         $casematerial = isset($_GET["casematerial"]) ? $_GET["casematerial"] : null;
  2076.         if($casematerial) {
  2077.             $entries->addFieldCollection("Specification""specs");
  2078.             $entries->addConditionParam("`Specification~specs`.specKey = 'Gehäusematerial' AND `Specification~specs`.specValue LIKE ?""%$casematerial%""AND");
  2079.             $filters["casematerial"] = $casematerial;
  2080.         }
  2081.         
  2082.         $sort = isset($_GET["sort"]) ? $_GET["sort"] : null;
  2083.         if($sort) {
  2084.            switch($sort) {
  2085.                case "actual":
  2086.                    $entries->setOrderKey("stockInputDate");
  2087.                    $entries->setOrder("desc");
  2088.                    break;
  2089.                case "priceasc":
  2090.                    $entries->setOrderKey("price");
  2091.                    $entries->setOrder("asc");
  2092.                    break;
  2093.                 case "pricedesc":
  2094.                     $entries->setOrderKey("price");
  2095.                     $entries->setOrder("desc");
  2096.                     break;
  2097.                 case "name":
  2098.                     $entries->setOrderKey("model");
  2099.                     $entries->setOrder("asc");
  2100.                     break;
  2101.            }
  2102.            $filters["sort"] = $sort;
  2103.         } else {
  2104.             $entries->setOrderKey("stockInputDate");
  2105.             $entries->setOrder("desc");
  2106.             $filters["sort"] = "actual";
  2107.         }
  2108.         
  2109.         
  2110.         
  2111.         //var_dump($entries);
  2112.         
  2113.         $entries $entries->load();
  2114.         
  2115.        
  2116.         
  2117.         return $this->render('/default/product_overview.html.twig', ["products" => $entries"filters" => $filters"jewellerycat" => $jewellerycategory]);
  2118.    
  2119.       
  2120.     }
  2121.     
  2122.     /**
  2123.      * @Template
  2124.      * @param Request $request
  2125.      * @return array
  2126.      */
  2127.     public function brandsOverviewAction(Request $request) {
  2128.         $docpath $this->document->getFullPath();
  2129.         //var_dump($docpath);
  2130.         
  2131.         if(strpos($docpath"Uhren") !== false) {
  2132.             $path "Uhren";
  2133.         } else {
  2134.             $path "Schmuck";
  2135.         }
  2136.         
  2137.         
  2138.         $entries = new DataObject\Brand\Listing();
  2139.         $entries->setCondition("o_path LIKE '%$path%' ");
  2140.         $entries->setOrderKey("o_key");
  2141.         $entries->setOrder("ASC");
  2142.         $entries->load();
  2143.         
  2144.         return $this->render('/default/brands_overview.html.twig', ["brands" => $entries]);
  2145.     }
  2146.     
  2147.     /**
  2148.      * @Template
  2149.      * @param Request $request
  2150.      * @return array
  2151.      */
  2152.     public function teaserOverviewAction(Request $request) {
  2153.         return [];
  2154.     }
  2155.     
  2156.     /**
  2157.      * @Template
  2158.      * @param Request $request
  2159.      * @return array
  2160.      */
  2161.     public function brandAction(Request $request) {
  2162.         return $this->render('/default/brand.html.twig', []);
  2163.     }
  2164.     
  2165.     /**
  2166.      * @Template
  2167.      * @param Request $request
  2168.      * @return array
  2169.      */
  2170.     public function productAction(Request $request) {
  2171.         $id str_replace("/"""$request->get("id"));
  2172.         
  2173.         $product DataObject::getById($id);
  2174.         
  2175.         return $this->render('/default/product.html.twig', ["product" => $product]);
  2176.     }
  2177.     
  2178.     /**
  2179.      * @Template
  2180.      * @param Request $request
  2181.      * @return array
  2182.      */
  2183.     public function newproductAction(Request $request) {
  2184.         $key substr($request->get("key"), 1);
  2185.         $number substr($request->get("number"), 1);
  2186.         $id substr($request->get("id"), 1);
  2187.         
  2188.         // var_dump($id);
  2189.         // // exit;
  2190.         
  2191.         // $product = DataObject\Product::getByArticleNumber($number);
  2192.         //     
  2193.         // $product = $product->load()[0];
  2194.         
  2195.         $product DataObject::getById($id);
  2196.         
  2197.         return $this->render('/default/product.html.twig', ["product" => $product]);
  2198.     }
  2199.     
  2200.     /**
  2201.      * @Template
  2202.      * @param Request $request
  2203.      * @return array
  2204.      */
  2205.     public function teaserAction(Request $request) {
  2206.         $id str_replace("/"""$request->get("id"));
  2207.         
  2208.         $teaser DataObject::getById($id);
  2209.         $relation $teaser->getRelation();
  2210.         
  2211.         if($relation && $relation->getType() == "object" && $relation->getClassName() == "Category") {
  2212.             $collectionObject $relation;
  2213.             $brandkey $collectionObject->getParent()->getKey();
  2214.             $brands DataObject\Brand::getByName($brandkey);
  2215.             $brand $brands->load();
  2216.             if(is_array($brand)) {
  2217.                 $brand $brand[0];
  2218.                 return $this->render('/default/teaser.html.twig', ["teaser" => $teaser"brand" => $brand]);
  2219.             }
  2220.         } else {
  2221.             return $this->render('/default/teaser.html.twig', ["teaser" => $teaser]);
  2222.         }
  2223.             
  2224.         
  2225.         
  2226.        
  2227.     }
  2228.     
  2229.     private static function addBrandCollections($brand) {
  2230.         $collections = new DataObject\Category\Listing();
  2231.         if($brand->getId() == 85) {
  2232.             $collections->setCondition("o_path LIKE :brand", ["brand" => "%Nomos%"]);
  2233.         } else {
  2234.             $collections->setCondition("o_path LIKE :brand", ["brand" => "%".$brand->getName()."%"]);
  2235.         }
  2236.         $collections->load();
  2237.         
  2238.         
  2239.         
  2240.         $brandid $brand->getId();
  2241.         
  2242.         foreach($collections as $coll) {
  2243.             
  2244.             $key $coll->getKey();
  2245.             
  2246.             $products = new DataObject\Product\Listing();
  2247.             if($brand->getName() == "A. Lange & Söhne") {
  2248.                 $products->setCondition("UPPER(`o_key`) LIKE \"%$key%\" AND brand__id = $brandid");
  2249.             } elseif($coll->getId() == 281) {
  2250.                 $products->setCondition("`o_key` LIKE \"%$key%\" AND `o_key` NOT LIKE \"%Superocean Heritage%\" AND brand__id = $brandid");
  2251.             } elseif($coll->getId() == 285) {
  2252.                 $products->setCondition("`o_key` LIKE \"% Avi %\" AND brand__id = $brandid");
  2253.             } else {
  2254.                 $products->setCondition("`o_key` LIKE \"%$key%\" AND brand__id = $brandid");
  2255.             }
  2256.             
  2257.             $products->load();
  2258.             foreach($products as $product) {
  2259.                 $cats $product->getCategories();
  2260.                 if($cats) {
  2261.                     if (!in_array($coll$catstrue)) {
  2262.                         array_push($cats$coll);
  2263.                     } 
  2264.                 } else {
  2265.                     array_push($cats$coll);
  2266.                 }
  2267.                
  2268.                 $product->setCategories($cats);
  2269.                 $product->save();
  2270.             }
  2271.             
  2272.         }
  2273.     }
  2274.     
  2275. }