src/Controller/DefaultController.php line 2020

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.             // $params = $request->request;
  487.             // var_dump($params);
  488.             // exit;
  489.             // 
  490.             // $recaptchaSecret = '6LecQPMpAAAAAOx6s8_Q9LfbdubBE8G4IOOEwd4-';
  491.             // $recaptchaResponse = $_POST['g-recaptcha-response'];
  492.             // $recaptcha = new \ReCaptcha\ReCaptcha($recaptchaSecret);
  493.             // $recaptchaResult = $recaptcha->verify($recaptchaResponse);
  494.             
  495.             // if (!$recaptchaResult->isSuccess()) {
  496.             if (!= 0) {
  497.                 echo("not valid");
  498.             } else {
  499.                 // reCaptcha validation succeeded, proceed with form processing
  500.                     
  501.                     
  502.                 $params $request->request;
  503.                 
  504.                 $productId $params->get("productId");
  505.                 $product DataObject::getById($productId);
  506.                 $reference $product->getarticleNumber();
  507.                 
  508.                 $newsletter $params->get("newsletter");
  509.                 $iwantto $params->get("iwantto");
  510.                 $contactoption $params->get("contactoption");
  511.                 $branch $params->get("branch");
  512.                 $comment $params->get("comment");
  513.                 $salutation $params->get("salutation");
  514.                 $title $params->get("title");
  515.                 $firstname $params->get("firstname");
  516.                 $lastname $params->get("lastname");
  517.                 $email $params->get("email");
  518.                 $phone $params->get("phone");
  519.                 $address $params->get("address");
  520.                 $zipcode $params->get("zipcode");
  521.                 $state $params->get("state");
  522.                 $country $params->get("country");
  523.                 
  524.                 //set branch email
  525.                 switch($branch) {
  526.                     case "Wien":
  527.                         $branchemail "wien@uhrenhuebner.at";
  528.                         break;
  529.                     case "Linz":
  530.                         $branchemail "linz@uhrenhuebner.at";
  531.                         break;
  532.                     case "Wels":
  533.                         $branchemail "wels@uhrenhuebner.at";
  534.                         break;
  535.                 }
  536.                 
  537.                 $inquiry = new DataObject\Inquiry();
  538.                 $inquiry->setKey(\Pimcore\Model\Element\Service::getValidKey('Anfrage-' $email date('d-m-y h:i:s'), 'object'));
  539.                 $inquiry->setParentId(1833);
  540.                 $inquiry->setiwantto($iwantto);
  541.                 $inquiry->setcontactoption($contactoption);
  542.                 $inquiry->setbranch($branch);
  543.                 $inquiry->setcomment($comment);
  544.                 $inquiry->setnewsletter($newsletter);
  545.                 $inquiry->setsalutation($salutation);
  546.                 $inquiry->settitle($title);
  547.                 $inquiry->setfirstname($firstname);
  548.                 $inquiry->setlastname($lastname);
  549.                 $inquiry->setemail($email);
  550.                 $inquiry->setphone($phone);
  551.                 $inquiry->setaddress($address);
  552.                 $inquiry->setzipcode($zipcode);
  553.                 $inquiry->setstate($state);
  554.                 $inquiry->setcountry($country);
  555.                 $inquiry->setProduct($product);
  556.                 $inquiry->setPublished(true);
  557.                 $inquiry->save();
  558.                 
  559.                 $salutationtext $salutation == "Herr" "Sehr geehrter Herr" "Sehr geehrte Frau";
  560.                 $productHtml $this->getProductHtml($product);
  561.                 
  562.                 $productHtml " " $product->getBrand()->getName() . " - " $product->getModel() . " ";
  563.                 
  564.                 //send User Mail
  565.                 $mail = new \Pimcore\Mail();
  566.                 $mail->addTo($email);
  567.                 //$mail->addTo("a.daum@ontime.at");
  568.                 $mail->setDocument("/Emails/inquiry-user");
  569.                 $mail->setParams([
  570.                     'productHtml' => $productHtml,
  571.                     'salutation' => $salutationtext,
  572.                     'iwantto' => $iwantto,
  573.                     'contactoption' => $contactoption,
  574.                     'branch' => $branch,
  575.                     'comment' => $comment,
  576.                     'title' => $title,
  577.                     'firstname' => $firstname,
  578.                     'lastname' => $lastname,
  579.                     'email' => $email,
  580.                     'phone' => $phone,
  581.                     'address' => $address,
  582.                     'zipcode' => $zipcode,
  583.                     'state' => $state,
  584.                     'country' => $country
  585.                 ]);
  586.                 $mail->send();
  587.                 
  588.                 //send admin Mail
  589.                 $mail2 = new \Pimcore\Mail();
  590.                 // $mail->addTo("wien@uhrenhuebner.at");
  591.                 $mail2->addTo($branchemail);
  592.                 $mail2->addTo("a.daum@ontime.at");
  593.                 $mail2->setDocument("/Emails/inquiry-admin");
  594.                 $mail2->setParams([
  595.                     'brand' => $product->getBrand()->getName(),
  596.                     'model' => $product->getModel(),
  597.                     'reference' => $reference,
  598.                     'deeplink' => '',
  599.                     'productHtml' => $productHtml,
  600.                     'salutation' => $salutationtext,
  601.                     'iwantto' => $iwantto,
  602.                     'contactoption' => $contactoption,
  603.                     'branch' => $branch,
  604.                     'comment' => $comment,
  605.                     'title' => $title,
  606.                     'firstname' => $firstname,
  607.                     'lastname' => $lastname,
  608.                     'email' => $email,
  609.                     'phone' => $phone,
  610.                     'address' => $address,
  611.                     'zipcode' => $zipcode,
  612.                     'state' => $state,
  613.                     'country' => $country
  614.                 ]);
  615.                 $mail2->send();
  616.             }
  617.         }
  618.         return [];
  619.     }
  620.     
  621.     protected static function getProductHtml($product) {
  622.         $html '<table style="border:none;"';
  623.             $html .= '<tr>';
  624.                 $html .= '<td style="padding: 10px">';
  625.                     $html .= '<img src="https://zeit.at/'$product->getFrontImage()->getPath() . $product->getFrontImage()->getFilename() .'" alt="' $product->getModel() . '" style="width:100%; height: auto; max-width:200px";>';
  626.                 $html .= '</td>';
  627.                 $html .= '<td style="padding: 10px 0px;">';
  628.                     $html .= '<p>'.$product->getModel().'</p>';
  629.                 $html .= '</td>';
  630.             $html .= '</tr>';
  631.         $html .= '</table>';
  632.         
  633.         return $html;
  634.     }
  635.     
  636.     /**
  637.      * @Template
  638.      * @param Request $request
  639.      * @return array
  640.      */
  641.     public function loginAction(Request $request) {
  642.         if ($request->getMethod() === "POST") {
  643.             $params $request->request;
  644.             $email $params->get("email");
  645.             $password $params->get("password");
  646.             
  647.             $user DataObject::getByPath("/CRM/Users/" $email);
  648.             $passwordhash $user->getPassword();
  649.             
  650.             if(password_verify($password$passwordhash)) {
  651.                 //echo "login good";
  652.                 $loggedInUser $user;
  653.                 $cookie_name "zeituser";
  654.                 $cookie_value "4DFGHJ8765FGHJ".$user->getId()."KJHGF45678JHG4343";
  655.                 setcookie($cookie_name$cookie_valuetime() + (86400 7), "/"); 
  656.                 return $this->redirect("/");
  657.                 //return $this->render('/default/products.html.twig', ["loggedInUser" => $loggedIdUser]);
  658.                 exit;
  659.             } else {
  660.                 echo "login no good";
  661.             }
  662.             
  663.             exit;
  664.         }
  665.         return [];
  666.     }
  667.     
  668.     /**
  669.      * @Template
  670.      * @param Request $request
  671.      * @return array
  672.      */
  673.     public function registerAction(Request $request) {
  674.         if ($request->getMethod() === "POST") {
  675.             $params $request->request;
  676.             
  677.             $salutation $params->get("salutation");
  678.             $title $params->get("title");
  679.             $firstname $params->get("firstname");
  680.             $lastname $params->get("lastname");
  681.             $email $params->get("email");
  682.             $phone $params->get("phone");
  683.             $address $params->get("address");
  684.             $zipcode $params->get("zipcode");
  685.             $state $params->get("city");
  686.             $country $params->get("country");
  687.             
  688.             $password $params->get("password");
  689.             
  690.             $userobject = new DataObject\Customer();
  691.             $userobject->setKey(\Pimcore\Model\Element\Service::getValidKey($email'object'));
  692.             $userobject->setParentId(390);
  693.             
  694.             $userobject->setSalutation($salutation);
  695.             $userobject->setTitle($title);
  696.             $userobject->setFirstName($firstname);
  697.             $userobject->setLastName($lastname);
  698.             $userobject->setAddress($address);
  699.             $userobject->setZipcode($zipcode);
  700.             $userobject->setCity($state);
  701.             $userobject->setPhone($phone);
  702.             $userobject->setEmail($email);
  703.             $userobject->setUsername($email);
  704.             $userobject->setCountry($country);
  705.             
  706.             $userobject->setPassword($password);
  707.             
  708.             $userobject->setPublished(true);
  709.             $userobject->save();
  710.             
  711.             echo "saved";            
  712.             exit;
  713.         } else {
  714.             
  715.         }
  716.     }
  717.     
  718.     /**
  719.      * @Template
  720.      * @param Request $request
  721.      * @return array
  722.      */
  723.     public function logoutAction(Request $request) {
  724.         
  725.         unset($_COOKIE['zeituser']);
  726.         setcookie('zeituser'null, -1'/'); 
  727.         
  728.         exit;
  729.         return [];
  730.     }
  731.     
  732.     /**
  733.      * @Template
  734.      * @param Request $request
  735.      * @return array
  736.      */
  737.     public function checkoutAction(Request $request) {
  738.         return [];
  739.     }
  740.     
  741.     /**
  742.      * @Template
  743.      * @param Request $request
  744.      * @return array
  745.      */
  746.     public function cartAction(Request $request) {
  747.         return [];
  748.     }
  749.     
  750.     /**
  751.      * @Template
  752.      * @param Request $request
  753.      * @return array
  754.      */
  755.     public function deleteSoldProductsAction(Request $request) {
  756.         $checkstring date('d-m-y');
  757.             //$checkstring .= 'manual';
  758.         $products = new DataObject\Product\Listing();
  759.         $products->setCondition("updateinfo != '$checkstring' AND (manualInput != '1' OR manualInput IS NULL)");
  760.         $products $products->load();
  761.         if(count($products) < 100) {
  762.             foreach($products as $product) {
  763.                 $product->delete();
  764.             }
  765.         }
  766.        
  767.         exit;
  768.         return [];
  769.     
  770.     }
  771.     
  772.     /**
  773.      * @Template
  774.      * @param Request $request
  775.      * @return array
  776.      */
  777.     public function createBrandDocumentsAction(Request $request) {
  778.         // $branddocument = \Pimcore\Model\Document::getByPath("/Uhren/Marken/" . "A. Lange - Söhne");
  779.         // $branddocument->setProperty("navigation_name", "text", "A. Lange & Söhne");
  780.         // $branddocument->setController("App\Controller\DefaultController::brandAction");
  781.         // $branddocument->save();
  782.         // exit;
  783.         
  784.         $brands = new DataObject\Brand\Listing();
  785.         $brands->setCondition("o_path LIKE '%Uhren%'");
  786.         $brands $brands->load();
  787.         
  788.         foreach($brands as $brand) {
  789.             $brandkey str_replace(["&"], ["-"], $brand->getKey());
  790.             
  791.             $branddocument \Pimcore\Model\Document::getByPath("/Uhren/Marken/" $brandkey);
  792.             if($branddocument) {
  793.                 
  794.             } else {
  795.                 $page = new \Pimcore\Model\Document\Page();
  796.                 $page->setKey($brandkey);
  797.                 $page->setTitle($brand->getName());
  798.                 $page->setParentId(2);
  799.                 $page->setProperty("navigation_name""text"$brand->getName());
  800.                 $page->setController("App\Controller\DefaultController::brandAction");
  801.                 $page->setPublished(true);
  802.                 $page->save();
  803.             }
  804.         }
  805.         
  806.         exit;
  807.         return [];
  808.     }
  809.     
  810.     /**
  811.      * @Template
  812.      * @param Request $request
  813.      * @return array
  814.      */
  815.     public function createBrandFolderAction(Request $request) {
  816.         
  817.         $brands = new DataObject\Brand\Listing();
  818.         $brands->setCondition("o_path LIKE '%Uhren%'");
  819.         $brands $brands->load();
  820.         
  821.         // $brands = $brands[0];
  822.         
  823.         //var_dump($brands);
  824.         
  825.         // foreach($brands as $brand) {
  826.         //     $brandkey = str_replace(["&"], ["-"], $brand->getKey());
  827.         //     
  828.         //     $newObject = new DataObject\Folder(); 
  829.         //     $newObject->setKey(\Pimcore\Model\Element\Service::getValidKey($brandkey, 'folder'));
  830.         //     $newObject->setParentId(61);
  831.         //     $newObject->save();
  832.         //     
  833.         // }
  834.         
  835.         // $brandkey = "Jaeger-LeCoultre";
  836.         // $folder = DataObject::getByPath("/PIM/01 Uhren/02 Produkte/" . $brandkey);
  837.         // $parentId = $folder->getId();
  838.         // var_dump($folder->getId());
  839.         
  840.         exit;
  841.         return [];
  842.     }
  843.     
  844.     /**
  845.      * @Template
  846.      * @param Request $request
  847.      * @return array
  848.      */
  849.     public function addcollectionAction(Request $request) {
  850.         
  851.         
  852.         $brands = new DataObject\Brand\Listing();
  853.         $brands->setCondition("o_path LIKE '%Uhren%'");
  854.         $brands $brands->load();
  855.         
  856.         //$brand = DataObject\Brand::getById(85);
  857.             
  858.         foreach($brands as $brand) {
  859.             // $collections = new DataObject\Category\Listing();
  860.             // if($brand->getId() == 85) {
  861.             //     $collections->setCondition("o_path LIKE :brand", ["brand" => "%Nomos%"]);
  862.             // } else {
  863.             //     $collections->setCondition("o_path LIKE :brand", ["brand" => "%".$brand->getName()."%"]);
  864.             // }
  865.             // $collections->load();
  866.             
  867.             $collections $brand->getCollections();
  868.             
  869.             
  870.             if($collections) {
  871.                 $collections $collections->getChildren();
  872.             } else {
  873.                 continue;
  874.             }
  875.             
  876.             
  877.             $brandid $brand->getId();
  878.             
  879.             foreach($collections as $coll) {
  880.                 
  881.                 $key $coll->getKey();
  882.                 
  883.                 $products = new DataObject\Product\Listing();
  884.                 if($brand->getName() == "A. Lange & Söhne") {
  885.                     $products->setCondition("UPPER(`o_key`) LIKE \"%$key%\" AND brand__id = $brandid");
  886.                 } elseif($coll->getId() == 281) {
  887.                     $products->setCondition("`o_key` LIKE \"%$key%\" AND `o_key` NOT LIKE \"%Superocean Heritage%\" AND brand__id = $brandid");
  888.                 } elseif($coll->getId() == 285) {
  889.                     $products->setCondition("`o_key` LIKE \"% Avi %\" AND brand__id = $brandid");
  890.                 } else {
  891.                     $products->setCondition("`o_key` LIKE \"%$key%\" AND brand__id = $brandid");
  892.                 }
  893.                 
  894.                 $products->load();
  895.                 foreach($products as $product) {
  896.                     $cats $product->getCategories();
  897.                     if($cats) {
  898.                         if (!in_array($coll$catstrue)) {
  899.                             array_push($cats$coll);
  900.                         } 
  901.                     } else {
  902.                         array_push($cats$coll);
  903.                     }
  904.                    
  905.                     $product->setCategories($cats);
  906.                     $product->save();
  907.                 }
  908.                 
  909.             }
  910.             echo "Brand: " $brand->getName() . " done <br><hr><br>";
  911.         }
  912.             exit;
  913.         
  914.         foreach($brands as $brand) {
  915.             $collections = new DataObject\Category\Listing();
  916.             $collections->setCondition("o_path LIKE :brand", ["brand" => "%".$brand->getName()."%"]);
  917.             $collections->load();
  918.         
  919.             foreach($collections as $coll) {
  920.                 $key $coll->getKey();
  921.                 $products = new DataObject\Product\Listing();
  922.                 if($brand->getName() == "A. Lange & Söhne") {
  923.                     $products->setCondition("UPPER(`o_key`) LIKE '%$key%'");
  924.                 } else {
  925.                     $products->setCondition("`o_key` LIKE '%$key%'");
  926.                 }
  927.                 $products->load();
  928.                 foreach($products as $product) {
  929.                     $cats $product->getCategories();
  930.                     if (!in_array($coll$cats)) {
  931.                         array_push($cats$coll);
  932.                     }
  933.                     $product->setCategories($cats);
  934.                     $product->save();
  935.                 }
  936.                 
  937.             }
  938.             echo "Brand: " $brand->getName() . " done <br><hr><br>";
  939.         }
  940.         
  941.         
  942.     
  943.         exit;
  944.         return [];
  945.     }
  946.     
  947.     /**
  948.      * @Template
  949.      * @param Request $request
  950.      * @return array
  951.      */
  952.     public function testAction(Request $request) {
  953.         
  954.         ini_set('memory_limit''1024M');
  955.         $listing = new \Pimcore\Model\Document\Listing();
  956.         $listing $listing->load();
  957.         
  958.         foreach($listing as $doc) {
  959.             $key $doc->getKey();
  960.             $key str_replace(" ""-"$key);
  961.             $doc->setKey($key);
  962.             $doc->save();
  963.         }
  964.         
  965.         exit;
  966.        //  $brands = new DataObject\Product\Listing();
  967.        // 
  968.        //  
  969.        //  $brands->setCondition("o_path LIKE '%Uhren%' AND o_modificationDate > 1667284831");
  970.        //  $brands->load();
  971.        //  
  972.        //  var_dump(count($brands));
  973.         
  974.         exit;
  975.         
  976.         return [];
  977.     }
  978.     
  979.     /**
  980.      * @Template
  981.      * @param Request $request
  982.      * @return array
  983.      */
  984.     public function importSingleProductAction(Request $request) {
  985.         $searchstring str_replace("/"""$request->get("searchstring"));
  986.         
  987.         
  988.         $servername "carat-dev.cp4unapazytb.eu-central-1.rds.amazonaws.com";
  989.         $username "atimis";
  990.         $password "gui8kknyzG";
  991.         $dbname "carat_100";
  992.         
  993.         // Create connection
  994.         $conn = new \mysqli($servername$username$password$dbname);
  995.         // Check connection
  996.         if ($conn->connect_error) {
  997.           die("Connection failed: " $conn->connect_error);
  998.         }
  999.         
  1000.         $conn->set_charset("utf8mb4");
  1001.         
  1002.         $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`;";
  1003.         
  1004.         $result $conn->query($sql);
  1005.         
  1006.         while($row $result->fetch_assoc()) {
  1007.             $extId $row["id"];
  1008.             
  1009.             $prObject DataObject::getByPath("/PIM/01 Uhren/02 Produkte/" $row["brand"] . "/" $row["productLine"] . "-" $row["articleNumber"]);
  1010.             
  1011.             if($prObject) {
  1012.                 $newObject $prObject;
  1013.             } else {
  1014.                 $newObject = new DataObject\Product(); 
  1015.                 $newObject->setKey(\Pimcore\Model\Element\Service::getValidKey($row["productLine"] . "-" $row["articleNumber"], 'object'));
  1016.                 
  1017.                 $folder DataObject::getByPath("/PIM/01 Uhren/02 Produkte/" $row["brand"]);
  1018.                 if($folder == null) {
  1019.                     $folder = new DataObject\Folder(); 
  1020.                     $folder->setKey(\Pimcore\Model\Element\Service::getValidKey($row["brand"], 'folder'));
  1021.                     $folder->setParentId(61);
  1022.                     $folder->save();
  1023.                 }
  1024.                 $parentId $folder->getId();
  1025.                 
  1026.                 $newObject->setParentId($parentId);
  1027.             }
  1028.             
  1029.             $newObject->setModel($row["productLine"]);
  1030.             $newObject->setArticleNumber($row["articleNumber"]);
  1031.             $newObject->setExtId($row["id"]);
  1032.             $newObject->setPrice($row["price"]);
  1033.             //set brand
  1034.             $brand $object DataObject::getByPath("/PIM/01 Uhren/01 Marken/" $row["brand"]);
  1035.             $newObject->setBrand($brand);
  1036.             
  1037.             //set specifications
  1038.             $items = new DataObject\Fieldcollection();
  1039.             $specsql "SELECT name, value FROM `ArticleProperty` WHERE `article_id` = $extId;";
  1040.             $specresult $conn->query($specsql);
  1041.             
  1042.             while($specrow $specresult->fetch_assoc()) {
  1043.                 $item = new DataObject\Fieldcollection\Data\Specification();
  1044.                 
  1045.                 $item->setSpecKey($specrow["name"]);
  1046.                 $item->setSpecValue($specrow["value"]);
  1047.                 
  1048.                 $items->add($item);
  1049.             }
  1050.         
  1051.             $newObject->setSpecs($items);
  1052.             
  1053.             //set frontimage
  1054.             $imagesql "SELECT src FROM `Image` WHERE `article_id` = $extId;";
  1055.             $imageresult $conn->query($imagesql);
  1056.             $assetfolderpath "/PIM/01 Uhren/02 Produkte/" $row["brand"] . "/" str_replace("/""-"$row["productLine"]) . "-" $row["articleNumber"];
  1057.             Asset\Service::createFolderByPath($assetfolderpath);
  1058.             
  1059.             $counter 0;
  1060.             $addImages = [];
  1061.             while($imagerow $imageresult->fetch_assoc()) {
  1062.                 $counter += 1;
  1063.                 $newAsset = new \Pimcore\Model\Asset\Image();
  1064.                 $newAsset->setFilename($imagerow["src"]);
  1065.                 $newAsset->setData(file_get_contents("https://huebner.carat.solutions/carat/filedownload?fileName=" $imagerow["src"]));
  1066.                 $newAsset->setParent(\Pimcore\Model\Asset::getByPath($assetfolderpath));
  1067.                 
  1068.                 $checkasset null;    
  1069.                 $checkasset \Pimcore\Model\Asset::getByPath($assetfolderpath "/" $imagerow["src"]);
  1070.                 
  1071.                 if($checkasset) {
  1072.                     $newAsset $checkasset;
  1073.                 } else {
  1074.                     $newAsset->save();
  1075.                 }
  1076.                 
  1077.                 
  1078.                 if($counter == 1) {
  1079.                     $newObject->setFrontimage($newAsset);
  1080.                 } else {
  1081.                     array_push($addImages$newAsset);
  1082.                 }
  1083.             }
  1084.             
  1085.             if(count($addImages) > 0) {
  1086.                 $newObject->setImages(new \Pimcore\Model\DataObject\Data\ImageGallery($addImages));
  1087.             }
  1088.             
  1089.             
  1090.             //set gender
  1091.             $gendercat DataObject::getByPath("/PIM/01 Uhren/03 Kategorien/" $row["subcategory"]);
  1092.             $cats = [$gendercat];
  1093.             $newObject->setCategories($cats);
  1094.             
  1095.             $newObject->setPublished(true);
  1096.             $newObject->save();
  1097.             
  1098.             echo "Produkt: " $row["productLine"] . "-" $row["articleNumber"] . " erfolgreich importiert";
  1099.             
  1100.             //var_dump($brand);
  1101.         }
  1102.         
  1103.         $conn->close();
  1104.         exit;
  1105.     }
  1106.     
  1107.     /**
  1108.      * @Template
  1109.      * @param Request $request
  1110.      * @return array
  1111.      */
  1112.     public function addJewelleryCatsAction(Request $request) {
  1113.         $products = new DataObject\Product\Listing();
  1114.         $products->setCondition("o_path LIKE '%Schmuck%'");
  1115.         $products->load();
  1116.         $i 0;
  1117.         
  1118.         foreach($products as $product) {
  1119.             $catstring $product->getCatstring();
  1120.             $categories = new DataObject\Category\Listing();
  1121.             $categories->setCondition("o_path LIKE '%02 Schmuck/03 Kategorien%' AND caratvalues LIKE '%$catstring%'");
  1122.             $categories->load();
  1123.             foreach($categories as $cat) {
  1124.                 $cats $product->getCategories();
  1125.                 if(is_array($cats)) {
  1126.                     if(!in_array($cat$cats)) {
  1127.                         $cats[] = $cat;
  1128.                     }
  1129.                 } else {
  1130.                     if(!in_array($cat$cats)) {
  1131.                         $cats = [];
  1132.                         $cats[] = $cat;
  1133.                     }
  1134.                 }
  1135.                 $product->setCategories($cats);
  1136.                 $product->save();
  1137.                 $i++;
  1138.             }
  1139.         }
  1140.         
  1141.         $brands = new DataObject\Brand\Listing();
  1142.         $brands->setCondition("o_path LIKE '%Schmuck%'");
  1143.         $brands->load();
  1144.         foreach($brands as $brand) {
  1145.             $collections $brand->getCollections();
  1146.             $collections $collections->getChildren();
  1147.             $brandid $brand->getId();
  1148.             
  1149.             foreach($collections as $coll) {
  1150.                 $key $coll->getKey();
  1151.                 
  1152.                 $products = new DataObject\Product\Listing();
  1153.                 $products->setCondition("`o_key` LIKE \"%$key%\" AND brand__id = $brandid AND o_path LIKE '%Schmuck%'");
  1154.                 
  1155.                 $products->load();
  1156.                 foreach($products as $product) {
  1157.                     $cats $product->getCategories();
  1158.                     if($cats) {
  1159.                         if (!in_array($coll$catstrue)) {
  1160.                             array_push($cats$coll);
  1161.                         } 
  1162.                     } else {
  1163.                         array_push($cats$coll);
  1164.                     }
  1165.                    
  1166.                     $product->setCategories($cats);
  1167.                     $product->save();
  1168.                 }
  1169.             }
  1170.         }
  1171.         
  1172.         //echo "done $i products";
  1173.         
  1174.         exit;
  1175.         return [];
  1176.     }
  1177.     
  1178.     /**
  1179.      * @Template
  1180.      * @param Request $request
  1181.      * @return array
  1182.      */
  1183.     public function importSingleJewelleryProductAction(Request $request) {
  1184.         $servername "carat-dev.cp4unapazytb.eu-central-1.rds.amazonaws.com";
  1185.             $username "atimis";
  1186.             $password "gui8kknyzG";
  1187.             $dbname "carat_100";
  1188.             
  1189.             // Create connection
  1190.             $conn = new \mysqli($servername$username$password$dbname);
  1191.             // Check connection
  1192.             if ($conn->connect_error) {
  1193.               die("Connection failed: " $conn->connect_error);
  1194.             }
  1195.             
  1196.             $conn->set_charset("utf8mb4");
  1197.             
  1198.         
  1199.             
  1200.             
  1201.             
  1202.             
  1203.             // FINAL QUERY
  1204.             
  1205.             $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'";
  1206.             
  1207.             // END FINAL QUERY
  1208.             
  1209.             
  1210.            // $sql = "SELECT * FROM Article WHERE `brand` LIKE '%Lange%' LIMIT 10;";
  1211.             
  1212.             $result $conn->query($sql);
  1213.             
  1214.             // var_dump($result);
  1215.             // exit;
  1216.             
  1217.             while($row $result->fetch_assoc()) {
  1218.                 $extId $row["id"];
  1219.                 
  1220.                 $row array_map('trim'$row);
  1221.                 
  1222.                 $key \Pimcore\Model\Element\Service::getValidKey($row["productLine"] . "-" $row["articleNumber"], 'object');
  1223.                 
  1224.                 $prObject DataObject::getByPath("/PIM/02 Schmuck/02 Produkte/" $row["brand"] . "/" $key);
  1225.                 
  1226.                 
  1227.                 
  1228.                 if($prObject) {
  1229.                     $checkstring date('d-m-y');
  1230.                     //$checkstring .= 'manual';
  1231.                     if($prObject->getUpdateInfo() == $checkstring) {
  1232.                         continue;
  1233.                     }
  1234.                     $newObject $prObject;
  1235.                     $newObject->setupdateinfo($checkstring);
  1236.                 } else {
  1237.                     $newObject = new DataObject\Product(); 
  1238.                     $newObject->setKey($key);
  1239.                     $newObject->setupdateinfo($checkstring);
  1240.                     
  1241.                     // get Brand Folder ID
  1242.                     $folder DataObject::getByPath("/PIM/02 Schmuck/02 Produkte/" $row["brand"]);
  1243.                     
  1244.                     // if($row["brand"] == "Jaeger-LeCoultre") {
  1245.                     //     $folder = DataObject::getById(396);
  1246.                     // }
  1247.                     if($row["brand"] == "FOPE") {
  1248.                         $folder DataObject::getById(3160);
  1249.                     }
  1250.                     if($row["brand"] == "Aldusblatt Herzog Loibner") {
  1251.                         $folder DataObject::getById(1712);
  1252.                     }
  1253.                     
  1254.                     if($folder == null) {
  1255.                         $folder = new DataObject\Folder(); 
  1256.                         $folder->setKey(\Pimcore\Model\Element\Service::getValidKey($row["brand"], 'folder'));
  1257.                         $folder->setParentId(64);
  1258.                         $folder->save();
  1259.                     }
  1260.                     $parentId $folder->getId();
  1261.                     
  1262.                     $newObject->setParentId($parentId);
  1263.                 }
  1264.                 
  1265.                 $newObject->setModel($row["productLine"]);
  1266.                 $newObject->setArticleNumber($row["articleNumber"]);
  1267.                 $newObject->setStockInputDate($row["stockInputDate"]);
  1268.                 $newObject->setExtId($row["id"]);
  1269.                 $newObject->setPrice($row["price"]);
  1270.                 $newObject->setCatstring($row["subcategory"]);
  1271.                 
  1272.                 //set brand
  1273.                 $brand DataObject::getByPath("/PIM/02 Schmuck/01 Marken/" $row["brand"]);
  1274.                 // if($row["brand"] == "Jaeger-LeCoultre") {
  1275.                 //     $brand = DataObject\Brand::getById(23);
  1276.                 // }
  1277.                 if($row["brand"] == "FOPE") {
  1278.                     $brand DataObject::getById(3201);
  1279.                 }
  1280.                 if($row["brand"] == "Aldusblatt Herzog Loibner") {
  1281.                     $brand DataObject::getById(99);
  1282.                 }
  1283.                 $newObject->setBrand($brand);
  1284.                 
  1285.                 //set specifications
  1286.                 $items = new DataObject\Fieldcollection();
  1287.                 $specsql "SELECT carat, label, number, description FROM `GemItem` WHERE `article_id` = $extId;";
  1288.                 $specresult $conn->query($specsql);
  1289.                 
  1290.                 while($specrow $specresult->fetch_assoc()) {
  1291.                     $item = new DataObject\Fieldcollection\Data\JewellerySpecification();
  1292.                     
  1293.                     $item->setSpecKey($specrow["label"]);
  1294.                     $item->setSpecValue($specrow["carat"]);
  1295.                     $item->setSpecCount($specrow["number"]);
  1296.                     $item->setSpecDescription($specrow["description"]);                    
  1297.                     $items->add($item);
  1298.                 }
  1299.                 
  1300.                 $specsql "SELECT name, value FROM `ArticleProperty` WHERE `article_id` = $extId;";
  1301.                 $specresult $conn->query($specsql);
  1302.                 
  1303.                 while($specrow $specresult->fetch_assoc()) {
  1304.                     $item = new DataObject\Fieldcollection\Data\JewellerySpecification();
  1305.                     
  1306.                     $item->setSpecKey($specrow["name"]);
  1307.                     $item->setSpecValue($specrow["value"]);
  1308.                     $item->setSpecCount(null);
  1309.                     $item->setSpecDescription(null);                    
  1310.                     $items->add($item);
  1311.                 }
  1312.         
  1313.                 $newObject->setSpecs($items);
  1314.                 
  1315.                 //set frontimage
  1316.                 $imagesql "SELECT src FROM `Image` WHERE `article_id` = $extId;";
  1317.                 $imageresult $conn->query($imagesql);
  1318.                 $articlenumber str_replace("/""-"$row["articleNumber"]);
  1319.                 $assetfolderpath "/PIM/02 Schmuck/02 Produkte/" $row["brand"] . "/" str_replace(["/"'"'"+"], ["-"""""], $row["productLine"]) . "-" $articlenumber;
  1320.                 $assetfolderpath str_replace("+"""$assetfolderpath);
  1321.                 $assetfolderpath str_replace("."""$assetfolderpath);
  1322.                 $assetfolderpath str_replace("|"""$assetfolderpath);
  1323.                 $assetfolderpath str_replace("Ăź""ss"$assetfolderpath);
  1324.                 Asset\Service::createFolderByPath($assetfolderpath);
  1325.                 
  1326.                 $counter 0;
  1327.                 $addImages = [];
  1328.                 while($imagerow $imageresult->fetch_assoc()) {
  1329.                     $counter += 1;
  1330.                     $newAsset = new \Pimcore\Model\Asset\Image();
  1331.                     $newAsset->setFilename($imagerow["src"]);
  1332.                     $newAsset->setData(file_get_contents("https://huebner.carat.solutions/carat/filedownload?fileName=" $imagerow["src"]));
  1333.                     $newAsset->setParent(\Pimcore\Model\Asset::getByPath($assetfolderpath));
  1334.                     
  1335.                     $checkasset null;    
  1336.                     $checkasset \Pimcore\Model\Asset::getByPath($assetfolderpath "/" $imagerow["src"]);
  1337.                     
  1338.                     echo "trying to save asset for " $row["productLine"] . "-" $row["articleNumber"] . "<br><hr><br>";
  1339.                     
  1340.                     if(strpos($imagerow["src"], "html") == false && strpos($imagerow["src"], "avif") == false && $imagerow["src"] != "7281fa99-3001-41a5-9be1-8dcfe04d997b.") {
  1341.                         if($checkasset) {
  1342.                             $checkasset->delete();
  1343.                             $newAsset->save();
  1344.                         } else {
  1345.                             $newAsset->save();
  1346.                         }
  1347.                     }
  1348.                     if($counter == 1) {
  1349.                         $newObject->setFrontimage($newAsset);
  1350.                     } else {
  1351.                         $advancedImage = new \Pimcore\Model\DataObject\Data\Hotspotimage();
  1352.                         $advancedImage->setImage($newAsset);
  1353.                         array_push($addImages$advancedImage);
  1354.                     }
  1355.                 }
  1356.                 
  1357.                 if(count($addImages) > 0) {   
  1358.                     $newObject->setImages(new \Pimcore\Model\DataObject\Data\ImageGallery($addImages));
  1359.                 }
  1360.                 
  1361.                 //var_dump($addImages);
  1362.                 
  1363.                 
  1364.                 //set gender
  1365.                 // $gendercat = DataObject::getByPath("/PIM/01 Uhren/03 Kategorien/" . $row["subcategory"]);
  1366.                 // if(!$gendercat) {
  1367.                 //     $newcat = new DataObject\Category(); 
  1368.                 //     $newcat->setKey(\Pimcore\Model\Element\Service::getValidKey($row["subcategory"], 'object'));
  1369.                 //     $newcat->setParentId(101);
  1370.                 //     $newcat->setTitle($row["subcategory"]);
  1371.                 //     $newcat->setPublished(true);
  1372.                 //     $newcat->save();
  1373.                 //     $gendercat = $newcat;
  1374.                 // }
  1375.                 
  1376.                 // $cats = [$gendercat];
  1377.                 // $newObject->setCategories($cats);
  1378.                 
  1379.                 $newObject->setPublished(true);
  1380.                 $newObject->save();
  1381.                 
  1382.                 //var_dump($brand);
  1383.             }
  1384.             
  1385.             $conn->close();
  1386.             
  1387.             
  1388.             exit;
  1389.             return [];
  1390.     }
  1391.     
  1392.     /**
  1393.      * @Template
  1394.      * @param Request $request
  1395.      * @return array
  1396.      */
  1397.     public function updateProductAction(Request $request) {
  1398.         
  1399.         $id str_replace("/"""$request->get("caratid"));
  1400.         $pimId str_replace("/"""$request->get("pimid"));
  1401.         
  1402.         $servername "carat-dev.cp4unapazytb.eu-central-1.rds.amazonaws.com";
  1403.         //$servername = "52.29.59.182";
  1404.         $username "atimis";
  1405.         $password "gui8kknyzG";
  1406.         $dbname "carat_100";
  1407.         
  1408.         // Create connection
  1409.         $conn = new \mysqli($servername$username$password$dbname);
  1410.         // Check connection
  1411.         if ($conn->connect_error) {
  1412.           die("Connection failed: " $conn->connect_error);
  1413.         }
  1414.         
  1415.         
  1416.         $conn->set_charset("utf8mb4");
  1417.         
  1418.         // FINAL QUERY
  1419.         
  1420.         $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`";
  1421.         
  1422.         // END FINAL QUERY
  1423.         
  1424.         
  1425.        // $sql = "SELECT * FROM Article WHERE `brand` LIKE '%Lange%' LIMIT 10;";
  1426.         
  1427.         $result $conn->query($sql);
  1428.         
  1429.         // var_dump($result);
  1430.         // exit;
  1431.         
  1432.         while($row $result->fetch_assoc()) {
  1433.             $extId $row["id"];
  1434.             $row array_map('trim'$row);
  1435.             
  1436.             $watchjewel $row["category"];
  1437.             
  1438.             if($watchjewel == "Uhr") {
  1439.                 $key \Pimcore\Model\Element\Service::getValidKey($row["productLine"] . "-" $row["articleNumber"], 'object');
  1440.                 
  1441.                 $prObject DataObject::getById($pimId);
  1442.                 $checkstring date('d-m-y');
  1443.             //$checkstring .= 'manual';
  1444.                 // $checkstring .= "-zenith";
  1445.                 if($prObject) {
  1446.                     // if($prObject->getUpdateinfo() == "291122-try1" || $prObject->getUpdateinfo() == "291122-try2" || $prObject->getUpdateinfo() == "291122-try3" || $prObject->getUpdateinfo() == "291122-try4") {
  1447.                     //     continue;
  1448.                     // }
  1449.                     
  1450.                     
  1451.                     if($prObject->getUpdateInfo() == $checkstring) {
  1452.                         //continue;
  1453.                     }
  1454.                     $newObject $prObject;
  1455.                     $newObject->setupdateinfo($checkstring);
  1456.                 } else {
  1457.                     $newObject = new DataObject\Product(); 
  1458.                     $newObject->setKey($key);
  1459.                     $newObject->setupdateinfo($checkstring);
  1460.                     
  1461.                     // get Brand Folder ID
  1462.                     $folder DataObject::getByPath("/PIM/01 Uhren/02 Produkte/" $row["brand"]);
  1463.                     
  1464.                     if($row["brand"] == "Jaeger-LeCoultre") {
  1465.                         $folder DataObject::getById(396);
  1466.                     }
  1467.                     if($row["brand"] == "IWC") {
  1468.                         $folder DataObject::getById(962);
  1469.                     }
  1470.                     if($row["brand"] == "Nomos GlashĂĽtte") {
  1471.                         $folder DataObject::getById(407);
  1472.                     }
  1473.                     
  1474.                     if($folder == null) {
  1475.                         $folder = new DataObject\Folder(); 
  1476.                         $folder->setKey(\Pimcore\Model\Element\Service::getValidKey($row["brand"], 'folder'));
  1477.                         $folder->setParentId(61);
  1478.                         $folder->save();
  1479.                     }
  1480.                     $parentId $folder->getId();
  1481.                     
  1482.                     $newObject->setParentId($parentId);
  1483.                 }
  1484.                 
  1485.                 $newObject->setModel($row["productLine"]);
  1486.                 $newObject->setArticleNumber($row["articleNumber"]);
  1487.                 $newObject->setStockInputDate($row["stockInputDate"]);
  1488.                 $newObject->setExtId($row["id"]);
  1489.                 $newObject->setPrice($row["price"]);
  1490.                 
  1491.                 //set brand
  1492.                 $brand DataObject::getByPath("/PIM/01 Uhren/01 Marken/" $row["brand"]);
  1493.                 if($row["brand"] == "Jaeger-LeCoultre") {
  1494.                     $brand DataObject\Brand::getById(23);
  1495.                 }
  1496.                 if($row["brand"] == "IWC") {
  1497.                     $brand DataObject\Brand::getById(82);
  1498.                 }
  1499.                 if($row["brand"] == "Nomos GlashĂĽtte") {
  1500.                     $brand DataObject\Brand::getById(85);
  1501.                 }
  1502.                 if($row["brand"] == "Sattler") {
  1503.                     $brand DataObject\Brand::getById(77);
  1504.                 }
  1505.                 $newObject->setBrand($brand);
  1506.                 
  1507.                 //set specifications
  1508.                 $items = new DataObject\Fieldcollection();
  1509.                 $specsql "SELECT name, value FROM `ArticleProperty` WHERE `article_id` = $extId;";
  1510.                 $specresult $conn->query($specsql);
  1511.                 
  1512.                 while($specrow $specresult->fetch_assoc()) {
  1513.                     $item = new DataObject\Fieldcollection\Data\Specification();
  1514.                     
  1515.                     $item->setSpecKey($specrow["name"]);
  1516.                     $item->setSpecValue($specrow["value"]);
  1517.                     
  1518.                     $items->add($item);
  1519.                 }
  1520.                 
  1521.                 $newObject->setSpecs($items);
  1522.                 
  1523.                 //set frontimage
  1524.                 $imagesql "SELECT src FROM `Image` WHERE `article_id` = $extId;";
  1525.                 $imageresult $conn->query($imagesql);
  1526.                 $articlenumber str_replace("/""-"$row["articleNumber"]);
  1527.                 $assetfolderpath "/PIM/01 Uhren/02 Produkte/" $row["brand"] . "/" str_replace(["/"'"'"+"], ["-"""""], $row["productLine"]) . "-" $articlenumber;
  1528.                 $assetfolderpath str_replace("+"""$assetfolderpath);
  1529.                 $assetfolderpath str_replace("."""$assetfolderpath);
  1530.                 $assetfolderpath str_replace("|"""$assetfolderpath);
  1531.                 $assetfolderpath str_replace("Ăź""ss"$assetfolderpath);
  1532.                 Asset\Service::createFolderByPath($assetfolderpath);
  1533.                 
  1534.                 $counter 0;
  1535.                 $addImages = [];
  1536.                 while($imagerow $imageresult->fetch_assoc()) {
  1537.                     $counter += 1;
  1538.                     $newAsset = new \Pimcore\Model\Asset\Image();
  1539.                     $newAsset->setFilename($imagerow["src"]);
  1540.                     $newAsset->setData(file_get_contents("https://huebner.carat.solutions/carat/filedownload?fileName=" $imagerow["src"]));
  1541.                     $newAsset->setParent(\Pimcore\Model\Asset::getByPath($assetfolderpath));
  1542.                     
  1543.                     $checkasset null;    
  1544.                     $checkasset \Pimcore\Model\Asset::getByPath($assetfolderpath "/" $imagerow["src"]);
  1545.                     
  1546.                     //echo "trying to save asset for " . $row["productLine"] . "-" . $row["articleNumber"] . "<br><hr><br>";
  1547.                     
  1548.                     if(strpos($imagerow["src"], "html") == false && strpos($imagerow["src"], "avif") == false && $imagerow["src"] != "7281fa99-3001-41a5-9be1-8dcfe04d997b.") {
  1549.                         if($checkasset) {
  1550.                            $checkasset->delete();
  1551.                            $newAsset->save();
  1552.                         } else {
  1553.                             // var_dump($newAsset->getFullPath());
  1554.                             // var_dump($assetfolderpath);
  1555.                             // var_dump(\Pimcore\Model\Asset::getByPath($assetfolderpath));
  1556.                             // exit;
  1557.                             $newAsset->save();
  1558.                         }
  1559.                     }
  1560.                     if($counter == 1) {
  1561.                         $newObject->setFrontimage($newAsset);
  1562.                     } else {
  1563.                         $advancedImage = new \Pimcore\Model\DataObject\Data\Hotspotimage();
  1564.                         $advancedImage->setImage($newAsset);
  1565.                         array_push($addImages$advancedImage);
  1566.                     }
  1567.                 }
  1568.                 
  1569.                 if(count($addImages) > 0) {   
  1570.                     $newObject->setImages(new \Pimcore\Model\DataObject\Data\ImageGallery($addImages));
  1571.                 }
  1572.                 
  1573.                 //var_dump($addImages);
  1574.                 
  1575.                 
  1576.                 //set gender
  1577.                 $gendercat DataObject::getByPath("/PIM/01 Uhren/03 Kategorien/" $row["subcategory"]);
  1578.                 if(!$gendercat) {
  1579.                     $newcat = new DataObject\Category(); 
  1580.                     $newcat->setKey(\Pimcore\Model\Element\Service::getValidKey($row["subcategory"], 'object'));
  1581.                     $newcat->setParentId(101);
  1582.                     $newcat->setTitle($row["subcategory"]);
  1583.                     $newcat->setPublished(true);
  1584.                     $newcat->save();
  1585.                     $gendercat $newcat;
  1586.                 }
  1587.                 
  1588.                 $cats = [$gendercat];
  1589.                 $newObject->setCategories($cats);
  1590.                 
  1591.                 $newObject->setPublished(true);
  1592.                 $newObject->save();
  1593.                 
  1594.                 $this->addBrandCollections($brand);
  1595.                 
  1596.             } elseif($watchjewel == "Schmuck") {
  1597.                
  1598.                 $key \Pimcore\Model\Element\Service::getValidKey($row["productLine"] . "-" $row["articleNumber"], 'object');
  1599.                 
  1600.                 $prObject DataObject::getById($pimId);
  1601.                 $checkstring date('d-m-y');
  1602.             //$checkstring .= 'manual';
  1603.                 // $checkstring .= "-zenith";
  1604.                 if($prObject) {
  1605.                     // if($prObject->getUpdateinfo() == "291122-try1" || $prObject->getUpdateinfo() == "291122-try2" || $prObject->getUpdateinfo() == "291122-try3" || $prObject->getUpdateinfo() == "291122-try4") {
  1606.                     //     continue;
  1607.                     // }
  1608.                     
  1609.                     
  1610.                     if($prObject->getUpdateInfo() == $checkstring) {
  1611.                         //continue;
  1612.                     }
  1613.                     $newObject $prObject;
  1614.                     $newObject->setupdateinfo($checkstring);
  1615.                 } else {
  1616.                     $newObject = new DataObject\Product(); 
  1617.                     $newObject->setKey($key);
  1618.                     $newObject->setupdateinfo($checkstring);
  1619.                     
  1620.                     // get Brand Folder ID
  1621.                     $folder DataObject::getByPath("/PIM/02 Schmuck/02 Produkte/" $row["brand"]);
  1622.                     
  1623.                     if($folder == null) {
  1624.                         $folder = new DataObject\Folder(); 
  1625.                         $folder->setKey(\Pimcore\Model\Element\Service::getValidKey($row["brand"], 'folder'));
  1626.                         $folder->setParentId(64);
  1627.                         $folder->save();
  1628.                     }
  1629.                     $parentId $folder->getId();
  1630.                     
  1631.                     $newObject->setParentId($parentId);
  1632.                 }
  1633.                 
  1634.                 $newObject->setModel($row["productLine"]);
  1635.                 $newObject->setArticleNumber($row["articleNumber"]);
  1636.                 $newObject->setStockInputDate($row["stockInputDate"]);
  1637.                 $newObject->setExtId($row["id"]);
  1638.                 $newObject->setPrice($row["price"]);
  1639.                 
  1640.                 //set brand
  1641.                 $brand DataObject::getByPath("/PIM/02 Schmuck/01 Marken/" $row["brand"]);
  1642.                 if($row["brand"] == "Jaeger-LeCoultre") {
  1643.                     $brand DataObject\Brand::getById(23);
  1644.                 }
  1645.                 if($row["brand"] == "IWC") {
  1646.                     $brand DataObject\Brand::getById(82);
  1647.                 }
  1648.                 if($row["brand"] == "Nomos GlashĂĽtte") {
  1649.                     $brand DataObject\Brand::getById(85);
  1650.                 }
  1651.                 if($row["brand"] == "Sattler") {
  1652.                     $brand DataObject\Brand::getById(77);
  1653.                 }
  1654.                 $newObject->setBrand($brand);
  1655.                 
  1656.                 //set specifications
  1657.                 $items = new DataObject\Fieldcollection();
  1658.                 $specsql "SELECT name, value FROM `ArticleProperty` WHERE `article_id` = $extId;";
  1659.                 $specresult $conn->query($specsql);
  1660.                 
  1661.                 while($specrow $specresult->fetch_assoc()) {
  1662.                     $item = new DataObject\Fieldcollection\Data\Specification();
  1663.                     
  1664.                     $item->setSpecKey($specrow["name"]);
  1665.                     $item->setSpecValue($specrow["value"]);
  1666.                     
  1667.                     $items->add($item);
  1668.                 }
  1669.                 
  1670.                 $newObject->setSpecs($items);
  1671.                 
  1672.                 //set frontimage
  1673.                 $imagesql "SELECT src FROM `Image` WHERE `article_id` = $extId;";
  1674.                 $imageresult $conn->query($imagesql);
  1675.                 $articlenumber str_replace("/""-"$row["articleNumber"]);
  1676.                 $assetfolderpath "/PIM/02 Schmuck/02 Produkte/" $row["brand"] . "/" str_replace(["/"'"'"+"], ["-"""""], $row["productLine"]) . "-" $articlenumber;
  1677.                 $assetfolderpath str_replace("+"""$assetfolderpath);
  1678.                 $assetfolderpath str_replace("."""$assetfolderpath);
  1679.                 $assetfolderpath str_replace("|"""$assetfolderpath);
  1680.                 $assetfolderpath str_replace("Ăź""ss"$assetfolderpath);
  1681.                 Asset\Service::createFolderByPath($assetfolderpath);
  1682.                 
  1683.                 $counter 0;
  1684.                 $addImages = [];
  1685.                 while($imagerow $imageresult->fetch_assoc()) {
  1686.                     $counter += 1;
  1687.                     $newAsset = new \Pimcore\Model\Asset\Image();
  1688.                     $newAsset->setFilename($imagerow["src"]);
  1689.                     $newAsset->setData(file_get_contents("https://huebner.carat.solutions/carat/filedownload?fileName=" $imagerow["src"]));
  1690.                     $newAsset->setParent(\Pimcore\Model\Asset::getByPath($assetfolderpath));
  1691.                     
  1692.                     $checkasset null;    
  1693.                     $checkasset \Pimcore\Model\Asset::getByPath($assetfolderpath "/" $imagerow["src"]);
  1694.                     
  1695.                     //echo "trying to save asset for " . $row["productLine"] . "-" . $row["articleNumber"] . "<br><hr><br>";
  1696.                     
  1697.                     if(strpos($imagerow["src"], "html") == false && strpos($imagerow["src"], "avif") == false && $imagerow["src"] != "7281fa99-3001-41a5-9be1-8dcfe04d997b.") {
  1698.                         if($checkasset) {
  1699.                            $checkasset->delete();
  1700.                            $newAsset->save();
  1701.                         } else {
  1702.                             // var_dump($newAsset->getFullPath());
  1703.                             // var_dump($assetfolderpath);
  1704.                             // var_dump(\Pimcore\Model\Asset::getByPath($assetfolderpath));
  1705.                             // exit;
  1706.                             $newAsset->save();
  1707.                         }
  1708.                     }
  1709.                     if($counter == 1) {
  1710.                         $newObject->setFrontimage($newAsset);
  1711.                     } else {
  1712.                         $advancedImage = new \Pimcore\Model\DataObject\Data\Hotspotimage();
  1713.                         $advancedImage->setImage($newAsset);
  1714.                         array_push($addImages$advancedImage);
  1715.                     }
  1716.                 }
  1717.                 
  1718.                 if(count($addImages) > 0) {   
  1719.                     $newObject->setImages(new \Pimcore\Model\DataObject\Data\ImageGallery($addImages));
  1720.                 }
  1721.                 
  1722.                 //var_dump($addImages);
  1723.                 
  1724.                 
  1725.                 //set gender
  1726.                 // $gendercat = DataObject::getByPath("/PIM/01 Uhren/03 Kategorien/" . $row["subcategory"]);
  1727.                 // if(!$gendercat) {
  1728.                 //     $newcat = new DataObject\Category(); 
  1729.                 //     $newcat->setKey(\Pimcore\Model\Element\Service::getValidKey($row["subcategory"], 'object'));
  1730.                 //     $newcat->setParentId(101);
  1731.                 //     $newcat->setTitle($row["subcategory"]);
  1732.                 //     $newcat->setPublished(true);
  1733.                 //     $newcat->save();
  1734.                 //     $gendercat = $newcat;
  1735.                 // }
  1736.                 // 
  1737.                 // $cats = [$gendercat];
  1738.                 // $newObject->setCategories($cats);
  1739.                 
  1740.                 $newObject->setPublished(true);
  1741.                 $newObject->save();
  1742.                 
  1743.                 $this->addBrandCollections($brand);
  1744.             }
  1745.             
  1746.             
  1747.             
  1748.             //var_dump($brand);
  1749.         }
  1750.         
  1751.         $conn->close();
  1752.         
  1753.         echo "success";
  1754.         
  1755.         exit;
  1756.         return [];
  1757.     }
  1758.     
  1759.     /**
  1760.      * @Template
  1761.      * @param Request $request
  1762.      * @return array
  1763.      */
  1764.     public function importAction(Request $request) {
  1765.         
  1766.         $servername "carat-dev.cp4unapazytb.eu-central-1.rds.amazonaws.com";
  1767.         //$servername = "52.29.59.182";
  1768.         $username "atimis";
  1769.         $password "gui8kknyzG";
  1770.         $dbname "carat_100";
  1771.         
  1772.         // Create connection
  1773.         $conn = new \mysqli($servername$username$password$dbname);
  1774.         // Check connection
  1775.         if ($conn->connect_error) {
  1776.           die("Connection failed: " $conn->connect_error);
  1777.         }
  1778.         
  1779.         
  1780.         $conn->set_charset("utf8mb4");
  1781.         
  1782.         
  1783.         //$sql = "SELECT * FROM Article LIMIT 10";
  1784.         
  1785.         // $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;";
  1786.         
  1787.         // $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";
  1788.         
  1789.         // $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`;";
  1790.         
  1791.         // fix " "
  1792.         
  1793.         // $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`";
  1794.         
  1795.         // BRAND QUERY
  1796.         
  1797.         // $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`";
  1798.         
  1799.         
  1800.         // FINAL QUERY
  1801.         
  1802.         $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`";
  1803.         
  1804.         // $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`";
  1805.         
  1806.         // END FINAL QUERY
  1807.         
  1808.         
  1809.        // $sql = "SELECT * FROM Article WHERE `brand` LIKE '%Lange%' LIMIT 10;";
  1810.         
  1811.         $result $conn->query($sql);
  1812.         
  1813.         // var_dump($result);
  1814.         // exit;
  1815.         
  1816.         while($row $result->fetch_assoc()) {
  1817.             $extId $row["id"];
  1818.             $row array_map('trim'$row);
  1819.   
  1820.             
  1821.             $key \Pimcore\Model\Element\Service::getValidKey($row["productLine"] . "-" $row["articleNumber"], 'object');
  1822.             
  1823.             $prObject DataObject::getByPath("/PIM/01 Uhren/02 Produkte/" $row["brand"] . "/" $key);
  1824.             $checkstring date('d-m-y');
  1825.             //$checkstring .= 'manual';
  1826.             // $checkstring .= "-zenith";
  1827.             if($prObject) {
  1828.                 // if($prObject->getUpdateinfo() == "291122-try1" || $prObject->getUpdateinfo() == "291122-try2" || $prObject->getUpdateinfo() == "291122-try3" || $prObject->getUpdateinfo() == "291122-try4") {
  1829.                 //     continue;
  1830.                 // }
  1831.                 
  1832.                 
  1833.                 if($prObject->getUpdateInfo() == $checkstring) {
  1834.                     continue;
  1835.                 }
  1836.                 $newObject $prObject;
  1837.                 $newObject->setupdateinfo($checkstring);
  1838.             } else {
  1839.                 $newObject = new DataObject\Product(); 
  1840.                 $newObject->setKey($key);
  1841.                 $newObject->setupdateinfo($checkstring);
  1842.                 
  1843.                 // get Brand Folder ID
  1844.                 $folder DataObject::getByPath("/PIM/01 Uhren/02 Produkte/" $row["brand"]);
  1845.                 
  1846.                 if($row["brand"] == "Jaeger-LeCoultre") {
  1847.                     $folder DataObject::getById(396);
  1848.                 }
  1849.                 if($row["brand"] == "IWC") {
  1850.                     $folder DataObject::getById(962);
  1851.                 }
  1852.                 if($row["brand"] == "Nomos GlashĂĽtte") {
  1853.                     $folder DataObject::getById(407);
  1854.                 }
  1855.                 
  1856.                 if($folder == null) {
  1857.                     $folder = new DataObject\Folder(); 
  1858.                     $folder->setKey(\Pimcore\Model\Element\Service::getValidKey($row["brand"], 'folder'));
  1859.                     $folder->setParentId(61);
  1860.                     $folder->save();
  1861.                 }
  1862.                 $parentId $folder->getId();
  1863.                 
  1864.                 $newObject->setParentId($parentId);
  1865.             }
  1866.             
  1867.             $newObject->setModel($row["productLine"]);
  1868.             $newObject->setArticleNumber($row["articleNumber"]);
  1869.             $newObject->setStockInputDate($row["stockInputDate"]);
  1870.             $newObject->setExtId($row["id"]);
  1871.             $newObject->setPrice($row["price"]);
  1872.             
  1873.             //set brand
  1874.             $brand DataObject::getByPath("/PIM/01 Uhren/01 Marken/" $row["brand"]);
  1875.             if($row["brand"] == "Jaeger-LeCoultre") {
  1876.                 $brand DataObject\Brand::getById(23);
  1877.             }
  1878.             if($row["brand"] == "IWC") {
  1879.                 $brand DataObject\Brand::getById(82);
  1880.             }
  1881.             if($row["brand"] == "Nomos GlashĂĽtte") {
  1882.                 $brand DataObject\Brand::getById(85);
  1883.             }
  1884.             if($row["brand"] == "Sattler") {
  1885.                 $brand DataObject\Brand::getById(77);
  1886.             }
  1887.             $newObject->setBrand($brand);
  1888.             
  1889.             //set specifications
  1890.             $items = new DataObject\Fieldcollection();
  1891.             $specsql "SELECT name, value FROM `ArticleProperty` WHERE `article_id` = $extId;";
  1892.             $specresult $conn->query($specsql);
  1893.             
  1894.             while($specrow $specresult->fetch_assoc()) {
  1895.                 $item = new DataObject\Fieldcollection\Data\Specification();
  1896.                 
  1897.                 $item->setSpecKey($specrow["name"]);
  1898.                 $item->setSpecValue($specrow["value"]);
  1899.                 
  1900.                 $items->add($item);
  1901.             }
  1902.             $newObject->setSpecs($items);
  1903.             
  1904.             //set frontimage
  1905.             $imagesql "SELECT src FROM `Image` WHERE `article_id` = $extId;";
  1906.             $imageresult $conn->query($imagesql);
  1907.             $articlenumber str_replace("/""-"$row["articleNumber"]);
  1908.             $assetfolderpath "/PIM/01 Uhren/02 Produkte/" $row["brand"] . "/" str_replace(["/"'"'"+"], ["-"""""], $row["productLine"]) . "-" $articlenumber;
  1909.             $assetfolderpath str_replace("+"""$assetfolderpath);
  1910.             $assetfolderpath str_replace("."""$assetfolderpath);
  1911.             $assetfolderpath str_replace("|"""$assetfolderpath);
  1912.             $assetfolderpath str_replace("Ăź""ss"$assetfolderpath);
  1913.             Asset\Service::createFolderByPath($assetfolderpath);
  1914.             
  1915.             $counter 0;
  1916.             $addImages = [];
  1917.             while($imagerow $imageresult->fetch_assoc()) {
  1918.                 $counter += 1;
  1919.                 $newAsset = new \Pimcore\Model\Asset\Image();
  1920.                 $newAsset->setFilename($imagerow["src"]);
  1921.                 $newAsset->setData(file_get_contents("https://huebner.carat.solutions/carat/filedownload?fileName=" $imagerow["src"]));
  1922.                 $newAsset->setParent(\Pimcore\Model\Asset::getByPath($assetfolderpath));
  1923.                 
  1924.                 $checkasset null;    
  1925.                 $checkasset \Pimcore\Model\Asset::getByPath($assetfolderpath "/" $imagerow["src"]);
  1926.                 
  1927.                 echo "trying to save asset for " $row["productLine"] . "-" $row["articleNumber"] . "<br><hr><br>";
  1928.                 
  1929.                 if(strpos($imagerow["src"], "html") == false && strpos($imagerow["src"], "htm") == false && $imagerow["src"] != "7281fa99-3001-41a5-9be1-8dcfe04d997b.") {
  1930.                     if($checkasset) {
  1931.                        $checkasset->setData(file_get_contents("https://huebner.carat.solutions/carat/filedownload?fileName=" $imagerow["src"]));
  1932.                        $checkasset->save();
  1933.                        $newAsset $checkasset;
  1934.                     } else {
  1935.                         // var_dump($newAsset->getFullPath());
  1936.                         // var_dump($assetfolderpath);
  1937.                         // var_dump(\Pimcore\Model\Asset::getByPath($assetfolderpath));
  1938.                         // exit;
  1939.                         $newAsset->save();
  1940.                     }
  1941.                     $newAsset->save();
  1942.                 }
  1943.                 if($counter == 1) {
  1944.                     $newObject->setFrontimage($newAsset);
  1945.                 } else {
  1946.                     $advancedImage = new \Pimcore\Model\DataObject\Data\Hotspotimage();
  1947.                     $advancedImage->setImage($newAsset);
  1948.                     array_push($addImages$advancedImage);
  1949.                 }
  1950.             }
  1951.             
  1952.             if(count($addImages) > 0) {   
  1953.                 $newObject->setImages(new \Pimcore\Model\DataObject\Data\ImageGallery($addImages));
  1954.             }
  1955.             
  1956.             //var_dump($addImages);
  1957.             
  1958.             
  1959.             //set gender
  1960.             $gendercat DataObject::getByPath("/PIM/01 Uhren/03 Kategorien/" $row["subcategory"]);
  1961.             if(!$gendercat) {
  1962.                 $newcat = new DataObject\Category(); 
  1963.                 $newcat->setKey(\Pimcore\Model\Element\Service::getValidKey($row["subcategory"], 'object'));
  1964.                 $newcat->setParentId(101);
  1965.                 $newcat->setTitle($row["subcategory"]);
  1966.                 $newcat->setPublished(true);
  1967.                 $newcat->save();
  1968.                 $gendercat $newcat;
  1969.             }
  1970.             
  1971.             $cats = [$gendercat];
  1972.             $newObject->setCategories($cats);
  1973.             
  1974.             $newObject->setPublished(true);
  1975.             $newObject->save();
  1976.             
  1977.             //var_dump($brand);
  1978.         }
  1979.         
  1980.         $conn->close();
  1981.         
  1982.         
  1983.         exit;
  1984.         return [];
  1985.     }
  1986.     
  1987.     /**
  1988.      * @Template
  1989.      * @param Request $request
  1990.      * @return array
  1991.      */
  1992.     public function categoryAction(Request $request) {
  1993.         
  1994.         
  1995.         return [];
  1996.     }
  1997.     
  1998.     
  1999.     /**
  2000.      * @Template
  2001.      * @param Request $request
  2002.      * @return array
  2003.      */
  2004.     public function homeAction(Request $request) {
  2005.         return [];
  2006.     }
  2007.     
  2008.     /**
  2009.      * @Template
  2010.      * @param Request $request
  2011.      * @return array
  2012.      */
  2013.     public function productOverviewAction(Request $request) {
  2014.         $jewellerycategory null;
  2015.         $entries = new DataObject\Product\Listing();
  2016.         $filters = [];
  2017.         
  2018.         $page = isset($_GET["page"]) ? $_GET["page"] : null;
  2019.         if($page) {
  2020.             if($page == 1) {
  2021.                 $entries->setLimit(24);
  2022.             }
  2023.             $filters["page"] = $page;
  2024.         }
  2025.         
  2026.         $collection = isset($_GET["collection"]) ? $_GET["collection"] : null;
  2027.         if($collection) {
  2028.             $entries->addConditionParam("categories LIKE ?""%object|$collection%""AND");
  2029.             $filters["collection"] = $collection;
  2030.         }
  2031.         
  2032.         $type = isset($_GET["type"]) ? $_GET["type"] : null;
  2033.         if($type) {
  2034.             //$entries->addConditionParam("categories LIKE ?", "%object|$type%", "AND");
  2035.             $entries->setCondition("categories LIKE '%object|$type%'");
  2036.             $filters["type"] = $type;
  2037.         }
  2038.         
  2039.         $brand = isset($_GET["brand"]) ? $_GET["brand"] : null;
  2040.         if($brand) {
  2041.             $entries->addConditionParam("brand__id = ?""$brand""AND");
  2042.             $brandobject DataObject::getById($brand);
  2043.             $brandcollections $brandobject->getCollections() ? $brandobject->getCollections()->getChildren() : null;
  2044.             
  2045.             $filters["brand"] = $brand;
  2046.             $filters["brandCollections"] = $brandcollections;
  2047.         } 
  2048.         if (!$brand && $collection) {
  2049.             $collectionObject DataObject::getById($collection);
  2050.                 // var_dump($collection);
  2051.                 // exit;
  2052.             
  2053.             
  2054.             $collectionpath $collectionObject->getPath();
  2055.             // var_dump($collectionpath);
  2056.             // exit;
  2057.             if(str_contains($collectionpath"Schmuck")) {
  2058.                 
  2059.                 $entries->addConditionParam("o_path LIKE '%Schmuck%'""AND");
  2060.                 $jewellerycategory $collectionObject;
  2061.             } else {
  2062.                 $brandkey $collectionObject->getParent()->getKey();
  2063.                 
  2064.                 $brands DataObject\Brand::getByName($brandkey);
  2065.                 $brand $brands->load();
  2066.                 if(is_array($brand)) {
  2067.                     $brand $brand[0];
  2068.                     $brandobject $brand;
  2069.                     $brandcollections $brandobject->getCollections() ? $brandobject->getCollections()->getChildren() : null;
  2070.                     
  2071.                     $filters["brand"] = $brand->getId();
  2072.                     $filters["brandCollections"] = $brandcollections;
  2073.                 } else {
  2074.                     $brand null;
  2075.                     $filters["brand"] = null;
  2076.                     $filters["brandCollections"] = null;
  2077.                 }
  2078.             }
  2079.             
  2080.             
  2081.             
  2082.         }
  2083.         
  2084.         if(!isset($filters["brandCollections"])) {
  2085.             $brandCollections = new DataObject\Category\Listing();
  2086.             $brandCollections->setCondition("o_path LIKE '%Kollektionen%'");
  2087.             $brandCollections $brandCollections->load();
  2088.             $filters["brandCollections"] = $brandCollections;
  2089.         }
  2090.         
  2091.         $casematerial = isset($_GET["casematerial"]) ? $_GET["casematerial"] : null;
  2092.         if($casematerial) {
  2093.             $entries->addFieldCollection("Specification""specs");
  2094.             $entries->addConditionParam("`Specification~specs`.specKey = 'Gehäusematerial' AND `Specification~specs`.specValue LIKE ?""%$casematerial%""AND");
  2095.             $filters["casematerial"] = $casematerial;
  2096.         }
  2097.         
  2098.         $sort = isset($_GET["sort"]) ? $_GET["sort"] : null;
  2099.         if($sort) {
  2100.            switch($sort) {
  2101.                case "actual":
  2102.                    $entries->setOrderKey("stockInputDate");
  2103.                    $entries->setOrder("desc");
  2104.                    break;
  2105.                case "priceasc":
  2106.                    $entries->setOrderKey("price");
  2107.                    $entries->setOrder("asc");
  2108.                    break;
  2109.                 case "pricedesc":
  2110.                     $entries->setOrderKey("price");
  2111.                     $entries->setOrder("desc");
  2112.                     break;
  2113.                 case "name":
  2114.                     $entries->setOrderKey("model");
  2115.                     $entries->setOrder("asc");
  2116.                     break;
  2117.            }
  2118.            $filters["sort"] = $sort;
  2119.         } else {
  2120.             $entries->setOrderKey("stockInputDate");
  2121.             $entries->setOrder("desc");
  2122.             $filters["sort"] = "actual";
  2123.         }
  2124.         
  2125.         
  2126.         
  2127.         //var_dump($entries);
  2128.         
  2129.         $entries $entries->load();
  2130.         
  2131.        
  2132.         
  2133.         return $this->render('/default/product_overview.html.twig', ["products" => $entries"filters" => $filters"jewellerycat" => $jewellerycategory]);
  2134.    
  2135.       
  2136.     }
  2137.     
  2138.     /**
  2139.      * @Template
  2140.      * @param Request $request
  2141.      * @return array
  2142.      */
  2143.     public function brandsOverviewAction(Request $request) {
  2144.         $docpath $this->document->getFullPath();
  2145.         //var_dump($docpath);
  2146.         
  2147.         if(strpos($docpath"Uhren") !== false) {
  2148.             $path "Uhren";
  2149.         } else {
  2150.             $path "Schmuck";
  2151.         }
  2152.         
  2153.         
  2154.         $entries = new DataObject\Brand\Listing();
  2155.         $entries->setCondition("o_path LIKE '%$path%' ");
  2156.         $entries->setOrderKey("o_key");
  2157.         $entries->setOrder("ASC");
  2158.         $entries->load();
  2159.         
  2160.         return $this->render('/default/brands_overview.html.twig', ["brands" => $entries]);
  2161.     }
  2162.     
  2163.     /**
  2164.      * @Template
  2165.      * @param Request $request
  2166.      * @return array
  2167.      */
  2168.     public function teaserOverviewAction(Request $request) {
  2169.         return [];
  2170.     }
  2171.     
  2172.     /**
  2173.      * @Template
  2174.      * @param Request $request
  2175.      * @return array
  2176.      */
  2177.     public function brandAction(Request $request) {
  2178.         return $this->render('/default/brand.html.twig', []);
  2179.     }
  2180.     
  2181.     /**
  2182.      * @Template
  2183.      * @param Request $request
  2184.      * @return array
  2185.      */
  2186.     public function productAction(Request $request) {
  2187.         $id str_replace("/"""$request->get("id"));
  2188.         
  2189.         $product DataObject::getById($id);
  2190.         
  2191.         return $this->render('/default/product.html.twig', ["product" => $product]);
  2192.     }
  2193.     
  2194.     /**
  2195.      * @Template
  2196.      * @param Request $request
  2197.      * @return array
  2198.      */
  2199.     public function newproductAction(Request $request) {
  2200.         $key substr($request->get("key"), 1);
  2201.         $number substr($request->get("number"), 1);
  2202.         $id substr($request->get("id"), 1);
  2203.         
  2204.         // var_dump($id);
  2205.         // // exit;
  2206.         
  2207.         // $product = DataObject\Product::getByArticleNumber($number);
  2208.         //     
  2209.         // $product = $product->load()[0];
  2210.         
  2211.         $product DataObject::getById($id);
  2212.         
  2213.         return $this->render('/default/product.html.twig', ["product" => $product]);
  2214.     }
  2215.     
  2216.     /**
  2217.      * @Template
  2218.      * @param Request $request
  2219.      * @return array
  2220.      */
  2221.     public function teaserAction(Request $request) {
  2222.         $id str_replace("/"""$request->get("id"));
  2223.         
  2224.         $teaser DataObject::getById($id);
  2225.         $relation $teaser->getRelation();
  2226.         
  2227.         if($relation && $relation->getType() == "object" && $relation->getClassName() == "Category") {
  2228.             $collectionObject $relation;
  2229.             $brandkey $collectionObject->getParent()->getKey();
  2230.             $brands DataObject\Brand::getByName($brandkey);
  2231.             $brand $brands->load();
  2232.             if(is_array($brand)) {
  2233.                 $brand $brand[0];
  2234.                 return $this->render('/default/teaser.html.twig', ["teaser" => $teaser"brand" => $brand]);
  2235.             }
  2236.         } else {
  2237.             return $this->render('/default/teaser.html.twig', ["teaser" => $teaser]);
  2238.         }
  2239.             
  2240.         
  2241.         
  2242.        
  2243.     }
  2244.     
  2245.     private static function addBrandCollections($brand) {
  2246.         $collections = new DataObject\Category\Listing();
  2247.         if($brand->getId() == 85) {
  2248.             $collections->setCondition("o_path LIKE :brand", ["brand" => "%Nomos%"]);
  2249.         } else {
  2250.             $collections->setCondition("o_path LIKE :brand", ["brand" => "%".$brand->getName()."%"]);
  2251.         }
  2252.         $collections->load();
  2253.         
  2254.         
  2255.         
  2256.         $brandid $brand->getId();
  2257.         
  2258.         foreach($collections as $coll) {
  2259.             
  2260.             $key $coll->getKey();
  2261.             
  2262.             $products = new DataObject\Product\Listing();
  2263.             if($brand->getName() == "A. Lange & Söhne") {
  2264.                 $products->setCondition("UPPER(`o_key`) LIKE \"%$key%\" AND brand__id = $brandid");
  2265.             } elseif($coll->getId() == 281) {
  2266.                 $products->setCondition("`o_key` LIKE \"%$key%\" AND `o_key` NOT LIKE \"%Superocean Heritage%\" AND brand__id = $brandid");
  2267.             } elseif($coll->getId() == 285) {
  2268.                 $products->setCondition("`o_key` LIKE \"% Avi %\" AND brand__id = $brandid");
  2269.             } else {
  2270.                 $products->setCondition("`o_key` LIKE \"%$key%\" AND brand__id = $brandid");
  2271.             }
  2272.             
  2273.             $products->load();
  2274.             foreach($products as $product) {
  2275.                 $cats $product->getCategories();
  2276.                 if($cats) {
  2277.                     if (!in_array($coll$catstrue)) {
  2278.                         array_push($cats$coll);
  2279.                     } 
  2280.                 } else {
  2281.                     array_push($cats$coll);
  2282.                 }
  2283.                
  2284.                 $product->setCategories($cats);
  2285.                 $product->save();
  2286.             }
  2287.             
  2288.         }
  2289.     }
  2290.     
  2291. }