<?php
namespace App\Controller;
use Pimcore\Controller\FrontendController;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Routing\Annotation\Route;
use \Pimcore\Model\DataObject;
use \Pimcore\Model\Asset;
class DefaultController extends FrontendController {
/**
* @Template
* @param Request $request
* @return array
*/
public function defaultAction(Request $request) {
return [];
}
/**
* @Template
* @param Request $request
* @return array
*/
public function addPriceDevAction(Request $request) {
$data = [ "37931" => "281.25",
"39017" => "195.65",
"39018" => "953.16",
"39428" => "1454.74",
"39958" => "237.00",
"40103" => "448.50",
"40275" => "360.16",
"40722" => "872.50",
"41243" => "29.65",
"41245" => "23.12",
"41578" => "682.50",
"42126" => "798.50",
"42369" => "598.00",
"42957" => "1220.00",
"43600" => "529.00",
"43672" => "329.00",
"43698" => "2188.44",
"43761" => "2200.00",
"43832" => "89.00",
"43836" => "12.50",
"43837" => "12.50",
"43838" => "12.50",
"43843" => "38.00",
"43845" => "12.50",
"43846" => "12.50",
"43848" => "25.50",
"43857" => "25.50",
"43864" => "38.00",
"43867" => "38.00",
"43868" => "38.00",
"43884" => "63.50",
"43886" => "63.50",
"43892" => "38.00",
"43896" => "893.00",
"43900" => "1590.00",
"43902" => "226.50",
"43909" => "447.00",
"44190" => "127.00",
"44194" => "89.50",
"44196" => "38.00",
"44197" => "38.00",
"44198" => "38.00",
"44199" => "38.00",
"44207" => "12.50",
"44209" => "12.50",
"44213" => "115.00",
"44217" => "138.00",
"44221" => "1589.50",
"44225" => "395.50",
"44228" => "447.00",
"44235" => "107.50",
"44615" => "127.00",
"44619" => "892.50",
"45005" => "625.14",
"45007" => "97.23",
"45186" => "627.90",
"45960" => "198.50",
"46490" => "457.76",
"46492" => "918.02",
"46497" => "984.05",
"46511" => "625.35",
"46514" => "625.35",
"46519" => "457.76",
"46522" => "38.02",
"46523" => "38.02",
"46662" => "226.50",
"46667" => "89.00",
"46688" => "202.00",
"46690" => "202.00",
"46819" => "1320.00",
"47007" => "702.50",
"47217" => "107.50",
"47221" => "227.00",
"47288" => "238.80",
"47291" => "802.20",
"47294" => "383.25",
"47332" => "958.00",
"47574" => "380.00",
"47603" => "400.50",
"47784" => "260.50",
"48302" => "700.83",
"48350" => "945.00",
"48351" => "242.50",
"48353" => "89.00",
"48471" => "526.50",
"48492" => "457.00",
"48494" => "121.00",
"48693" => "1092.00",
"48774" => "127.00",
"48775" => "108.50",
"48777" => "108.50",
"48781" => "38.00",
"48784" => "188.50",
"48791" => "458.00",
"48794" => "574.50",
"48797" => "108.50",
"48800" => "25.50",
"48801" => "38.00",
"48803" => "188.50",
"48804" => "188.50",
"48808" => "213.00",
"48815" => "127.00",
"48817" => "364.00",
"48818" => "25.50",
"48819" => "38.00",
"48821" => "188.50",
"48824" => "188.50",
"48825" => "338.50",
"48826" => "1624.50",
"48828" => "213.00",
"48843" => "458.00",
"48892" => "447.30",
"48893" => "156.45",
"48894" => "166.95",
"48895" => "250.95",
"48972" => "574.50",
"48973" => "574.50",
"49355" => "525.00",
"49358" => "1300.00",
"49409" => "473.50",
"49424" => "3907.50",
"49458" => "1875.00",
"49495" => "637.50",
"49501" => "457.00",
"49503" => "234.00",
"49504" => "296.00",
"49510" => "38.00",
"49563" => "6857.50",
"50001" => "9580.00",
"50168" => "395.00",
"50208" => "703.25",
"50237" => "435.00",
"50246" => "430.00",
"50307" => "737.50",
"50353" => "4030.00",
"50383" => "34.50",
"50386" => "172.00",
"50554" => "439.38",
"50627" => "4840.50",
"50666" => "2847.50",
"50787" => "775.00",
"50792" => "247.50",
"50793" => "247.50",
"50842" => "3075.00",
"50883" => "586.85",
"50896" => "586.85",
"51012" => "54.50",
"51015" => "54.50",
"51016" => "79.50",
"51024" => "385.00",
"51025" => "385.00",
"51084" => "1358.50",
"51085" => "837.00",
"51086" => "416.50",
"51088" => "416.50",
"51090" => "554.50",
"51092" => "554.50",
"51096" => "570.50",
"51100" => "104.00",
"51102" => "1213.00",
"51310" => "622.50",
"51399" => "664.45",
"51413" => "535.50",
"51424" => "2360.00",
"51441" => "525.00",
"51475" => "7875.00",
"51510" => "481.50",
"51675" => "1318.00",
"51696" => "1308.00",
"51740" => "1462.50",
"51741" => "1830.00",
"51744" => "1809.00",
"51751" => "2531.67",
"51800" => "562.50",
"51821" => "297.50",
"51833" => "1292.00",
"51896" => "256.91",
"51944" => "586.85",
"51946" => "520.00",
"51998" => "415.63",
"52020" => "5063.33",
"52068" => "1912.00",
"52098" => "377.50",
"52126" => "380.00",
"52323" => "526.00",
"52346" => "475.00",
"52347" => "307.50",
"52348" => "340.00",
"52506" => "363.00",
"52509" => "529.00",
"52533" => "1188.50",
"52620" => "1163.00",
"52648" => "745.00",
"52863" => "8612.50",
"52923" => "1210.50",
"52959" => "142.00",
"52960" => "257.00",
"52961" => "87.00",
"52981" => "240.00",
"52982" => "173.00",
"53015" => "848.75",
"53033" => "3300.00",
"53173" => "1674.00",
"53182" => "8325.00",
"53197" => "962.50",
"53232" => "1343.50",
"53255" => "206.00",
"53257" => "206.00",
"53258" => "227.00",
"53273" => "465.00",
"53319" => "3733.34",
"53337" => "1562.50",
"53371" => "552.50",
"53374" => "552.50",
"53382" => "3417.00",
"53383" => "1455.00",
"53384" => "700.00",
"53386" => "950.00",
"53435" => "2412.80",
"53449" => "1285.00",
"53526" => "425.00",
"53558" => "2429.00",
"53666" => "720.00",
"53721" => "802.50",
"53752" => "2647.50",
"53758" => "552.50",
"53766" => "1092.50",
"53828" => "508.00",
"53838" => "2626.67",
"53875" => "190.00",
"53877" => "211.00",
"53894" => "463.13",
"53945" => "587.00",
"54008" => "1679.50",
"54038" => "1163.00",
"54091" => "3745.83",
"54098" => "1163.00",
"54133" => "657.50",
"54383" => "1205.00",
"54404" => "2054.00",
"54413" => "859.25",
"54708" => "814.25",
"55210" => "2028.00",
"55441" => "1976.00",
"55561" => "1810.50",
"55562" => "212.00",
"55566" => "526.00",
"55567" => "204.00",
"55568" => "204.00",
"55571" => "85.00",
"55575" => "110.00",
"55576" => "435.00",
"55578" => "211.00",
"55579" => "266.00",
"55580" => "142.00",
"55581" => "135.00",
"55582" => "390.00",
"55583" => "57.50",
"55584" => "23.00",
"55585" => "34.50",
"55586" => "11.50",
"55587" => "1169.00",
"55589" => "547.50",
"55590" => "227.00",
"55591" => "227.00",
"55592" => "172.00",
"55593" => "172.00",
"55594" => "859.50",
"55595" => "1190.50",
"55966" => "6897.50",
"56807" => "5554.17",
"57032" => "2028.00",
"57174" => "1346.80",
"57299" => "2028.00",
"57762" => "216.50",
"58492" => "2951.00",
"58601" => "9403.33",
"58661" => "1924.00",
"59375" => "1924.00",
"59490" => "2041.00",
"59715" => "6665.00"
];
$servername = "carat-dev.cp4unapazytb.eu-central-1.rds.amazonaws.com";
$username = "atimis";
$password = "gui8kknyzG";
$dbname = "carat_100";
// Create connection
$conn = new \mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$conn->set_charset("utf8mb4");
foreach($data as $storageNumber => $price) {
echo "Number: " . $storageNumber . " Price: " . $price . "<br>";
$sql = "INSERT INTO `PriceDevaluation` (`id`, `created`, `deleted`, `modified`, `note`, `price`, `creator_id`, `modificator_id`, `item_id`, `targetDate`)
VALUES (NULL, NULL, 0, NULL, 'Teilwert3', $price, NULL, NULL, (SELECT `id` FROM `Item` WHERE `stockNumber` = $storageNumber), '2023-06-30 00:00:00')";
$result = $conn->query($sql);
var_dump($result);
}
$conn->close();
exit;
return [];
}
/**
* @Template
* @param Request $request
* @return array
*/
public function videopageAction(Request $request) {
return [];
}
/**
* @Template
* @param Request $request
* @return array
*/
public function serviceAction(Request $request) {
return [];
}
/**
* @Template
* @param Request $request
* @return array
*/
public function unternehmenAction(Request $request) {
return [];
}
/**
* @Template
* @param Request $request
* @return array
*/
public function historyAction(Request $request) {
return [];
}
/**
* @Template
* @param Request $request
* @return array
*/
public function emailAction(Request $request) {
return [];
}
/**
* @Template
* @param Request $request
* @return array
*/
public function jaegerAction(Request $request) {
return [];
}
/**
* @Template
* @param Request $request
* @return array
*/
public function aktuellesAction(Request $request) {
return [];
}
/**
* @Template
* @param Request $request
* @return array
*/
public function profileAction(Request $request) {
return [];
}
/**
* @Template
* @param Request $request
* @return array
*/
public function testassetAction(Request $request) {
// $asset = Asset::getById(247380);
// $versions = $asset->getVersions();
//
// $previousVersion = $versions[count($versions)-3];
//
// $oldData = $previousVersion->getData();
//
// var_dump($previousVersion);
// exit;
// $asset->setData($oldData);
// $asset->save();
// exit;
$assets = new \Pimcore\Model\Asset\Listing();
$assets->setCondition("path LIKE '%/PIM/02 Schmuck/02 Produkte/%' and type = 'image' and id != 273747 and id != 280811 and id != 273482");
// $assets->setLimit(500);
// $assets->setOffset(4499);
$assets->setOrderKey("filename");
$assets->setOrder("ASC");
$assets->load();
foreach($assets as $asset) {
$filename = $asset->getFilename();
// var_dump($filename);
//$data = file_get_contents("https://huebner.carat.solutions/carat/filedownload?fileName=" . $filename);
//var_dump($data);
$asset->setData(file_get_contents("https://huebner.carat.solutions/carat/filedownload?fileName=" . $filename));
$asset->save();
}
echo "done";
// $newAsset = new \Pimcore\Model\Asset\Image();
// $newAsset->setFilename($filename);
// $newAsset->setData(file_get_contents("https://huebner.carat.solutions/carat/filedownload?fileName=" . $filename));
// $newAsset->setParent(\Pimcore\Model\Asset::getByPath("/Test"));
// $newAsset->save();
exit;
return [];
}
/**
* @Template
* @param Request $request
* @return array
*/
public function inquiryAction(Request $request) {
$productid = str_replace("/", "", $request->get("productid"));
$product = DataObject::getById($productid);
return $this->render('/default/inquiry.html.twig', ["product" => $product]);
}
/**
* @Template
* @param Request $request
* @return array
*/
public function sendInquiryAction(Request $request) {
if ($request->getMethod() === "POST") {
$params = $request->request;
$productId = $params->get("productId");
$product = DataObject::getById($productId);
$reference = $product->getarticleNumber();
$newsletter = $params->get("newsletter");
$iwantto = $params->get("iwantto");
$contactoption = $params->get("contactoption");
$branch = $params->get("branch");
$comment = $params->get("comment");
$salutation = $params->get("salutation");
$title = $params->get("title");
$firstname = $params->get("firstname");
$lastname = $params->get("lastname");
$email = $params->get("email");
$phone = $params->get("phone");
$address = $params->get("address");
$zipcode = $params->get("zipcode");
$state = $params->get("state");
$country = $params->get("country");
//set branch email
switch($branch) {
case "Wien":
$branchemail = "wien@uhrenhuebner.at";
break;
case "Linz":
$branchemail = "linz@uhrenhuebner.at";
break;
case "Wels":
$branchemail = "wels@uhrenhuebner.at";
break;
}
$inquiry = new DataObject\Inquiry();
$inquiry->setKey(\Pimcore\Model\Element\Service::getValidKey('Anfrage-' . $email . date('d-m-y h:i:s'), 'object'));
$inquiry->setParentId(1833);
$inquiry->setiwantto($iwantto);
$inquiry->setcontactoption($contactoption);
$inquiry->setbranch($branch);
$inquiry->setcomment($comment);
$inquiry->setnewsletter($newsletter);
$inquiry->setsalutation($salutation);
$inquiry->settitle($title);
$inquiry->setfirstname($firstname);
$inquiry->setlastname($lastname);
$inquiry->setemail($email);
$inquiry->setphone($phone);
$inquiry->setaddress($address);
$inquiry->setzipcode($zipcode);
$inquiry->setstate($state);
$inquiry->setcountry($country);
$inquiry->setProduct($product);
$inquiry->setPublished(true);
$inquiry->save();
$salutationtext = $salutation == "Herr" ? "Sehr geehrter Herr" : "Sehr geehrte Frau";
$productHtml = $this->getProductHtml($product);
$productHtml = " " . $product->getBrand()->getName() . " - " . $product->getModel() . " ";
//send User Mail
$mail = new \Pimcore\Mail();
$mail->addTo($email);
//$mail->addTo("a.daum@ontime.at");
$mail->setDocument("/Emails/inquiry-user");
$mail->setParams([
'productHtml' => $productHtml,
'salutation' => $salutationtext,
'iwantto' => $iwantto,
'contactoption' => $contactoption,
'branch' => $branch,
'comment' => $comment,
'title' => $title,
'firstname' => $firstname,
'lastname' => $lastname,
'email' => $email,
'phone' => $phone,
'address' => $address,
'zipcode' => $zipcode,
'state' => $state,
'country' => $country
]);
$mail->send();
//send admin Mail
$mail2 = new \Pimcore\Mail();
// $mail->addTo("wien@uhrenhuebner.at");
$mail2->addTo($branchemail);
$mail2->addTo("a.daum@ontime.at");
$mail2->setDocument("/Emails/inquiry-admin");
$mail2->setParams([
'brand' => $product->getBrand()->getName(),
'model' => $product->getModel(),
'reference' => $reference,
'deeplink' => '',
'productHtml' => $productHtml,
'salutation' => $salutationtext,
'iwantto' => $iwantto,
'contactoption' => $contactoption,
'branch' => $branch,
'comment' => $comment,
'title' => $title,
'firstname' => $firstname,
'lastname' => $lastname,
'email' => $email,
'phone' => $phone,
'address' => $address,
'zipcode' => $zipcode,
'state' => $state,
'country' => $country
]);
$mail2->send();
}
return [];
}
protected static function getProductHtml($product) {
$html = '<table style="border:none;"';
$html .= '<tr>';
$html .= '<td style="padding: 10px">';
$html .= '<img src="https://zeit.at/'. $product->getFrontImage()->getPath() . $product->getFrontImage()->getFilename() .'" alt="' . $product->getModel() . '" style="width:100%; height: auto; max-width:200px";>';
$html .= '</td>';
$html .= '<td style="padding: 10px 0px;">';
$html .= '<p>'.$product->getModel().'</p>';
$html .= '</td>';
$html .= '</tr>';
$html .= '</table>';
return $html;
}
/**
* @Template
* @param Request $request
* @return array
*/
public function loginAction(Request $request) {
if ($request->getMethod() === "POST") {
$params = $request->request;
$email = $params->get("email");
$password = $params->get("password");
$user = DataObject::getByPath("/CRM/Users/" . $email);
$passwordhash = $user->getPassword();
if(password_verify($password, $passwordhash)) {
//echo "login good";
$loggedInUser = $user;
$cookie_name = "zeituser";
$cookie_value = "4DFGHJ8765FGHJ".$user->getId()."KJHGF45678JHG4343";
setcookie($cookie_name, $cookie_value, time() + (86400 * 7), "/");
return $this->redirect("/");
//return $this->render('/default/products.html.twig', ["loggedInUser" => $loggedIdUser]);
exit;
} else {
echo "login no good";
}
exit;
}
return [];
}
/**
* @Template
* @param Request $request
* @return array
*/
public function registerAction(Request $request) {
if ($request->getMethod() === "POST") {
$params = $request->request;
$salutation = $params->get("salutation");
$title = $params->get("title");
$firstname = $params->get("firstname");
$lastname = $params->get("lastname");
$email = $params->get("email");
$phone = $params->get("phone");
$address = $params->get("address");
$zipcode = $params->get("zipcode");
$state = $params->get("city");
$country = $params->get("country");
$password = $params->get("password");
$userobject = new DataObject\Customer();
$userobject->setKey(\Pimcore\Model\Element\Service::getValidKey($email, 'object'));
$userobject->setParentId(390);
$userobject->setSalutation($salutation);
$userobject->setTitle($title);
$userobject->setFirstName($firstname);
$userobject->setLastName($lastname);
$userobject->setAddress($address);
$userobject->setZipcode($zipcode);
$userobject->setCity($state);
$userobject->setPhone($phone);
$userobject->setEmail($email);
$userobject->setUsername($email);
$userobject->setCountry($country);
$userobject->setPassword($password);
$userobject->setPublished(true);
$userobject->save();
echo "saved";
exit;
} else {
}
}
/**
* @Template
* @param Request $request
* @return array
*/
public function logoutAction(Request $request) {
unset($_COOKIE['zeituser']);
setcookie('zeituser', null, -1, '/');
exit;
return [];
}
/**
* @Template
* @param Request $request
* @return array
*/
public function checkoutAction(Request $request) {
return [];
}
/**
* @Template
* @param Request $request
* @return array
*/
public function cartAction(Request $request) {
return [];
}
/**
* @Template
* @param Request $request
* @return array
*/
public function deleteSoldProductsAction(Request $request) {
$checkstring = date('d-m-y');
//$checkstring .= 'manual';
$products = new DataObject\Product\Listing();
$products->setCondition("updateinfo != '$checkstring' AND (manualInput != '1' OR manualInput IS NULL)");
$products = $products->load();
if(count($products) < 100) {
foreach($products as $product) {
$product->delete();
}
}
exit;
return [];
}
/**
* @Template
* @param Request $request
* @return array
*/
public function createBrandDocumentsAction(Request $request) {
// $branddocument = \Pimcore\Model\Document::getByPath("/Uhren/Marken/" . "A. Lange - Söhne");
// $branddocument->setProperty("navigation_name", "text", "A. Lange & Söhne");
// $branddocument->setController("App\Controller\DefaultController::brandAction");
// $branddocument->save();
// exit;
$brands = new DataObject\Brand\Listing();
$brands->setCondition("o_path LIKE '%Uhren%'");
$brands = $brands->load();
foreach($brands as $brand) {
$brandkey = str_replace(["&"], ["-"], $brand->getKey());
$branddocument = \Pimcore\Model\Document::getByPath("/Uhren/Marken/" . $brandkey);
if($branddocument) {
} else {
$page = new \Pimcore\Model\Document\Page();
$page->setKey($brandkey);
$page->setTitle($brand->getName());
$page->setParentId(2);
$page->setProperty("navigation_name", "text", $brand->getName());
$page->setController("App\Controller\DefaultController::brandAction");
$page->setPublished(true);
$page->save();
}
}
exit;
return [];
}
/**
* @Template
* @param Request $request
* @return array
*/
public function createBrandFolderAction(Request $request) {
$brands = new DataObject\Brand\Listing();
$brands->setCondition("o_path LIKE '%Uhren%'");
$brands = $brands->load();
// $brands = $brands[0];
//var_dump($brands);
// foreach($brands as $brand) {
// $brandkey = str_replace(["&"], ["-"], $brand->getKey());
//
// $newObject = new DataObject\Folder();
// $newObject->setKey(\Pimcore\Model\Element\Service::getValidKey($brandkey, 'folder'));
// $newObject->setParentId(61);
// $newObject->save();
//
// }
// $brandkey = "Jaeger-LeCoultre";
// $folder = DataObject::getByPath("/PIM/01 Uhren/02 Produkte/" . $brandkey);
// $parentId = $folder->getId();
// var_dump($folder->getId());
exit;
return [];
}
/**
* @Template
* @param Request $request
* @return array
*/
public function addcollectionAction(Request $request) {
$brands = new DataObject\Brand\Listing();
$brands->setCondition("o_path LIKE '%Uhren%'");
$brands = $brands->load();
//$brand = DataObject\Brand::getById(85);
foreach($brands as $brand) {
// $collections = new DataObject\Category\Listing();
// if($brand->getId() == 85) {
// $collections->setCondition("o_path LIKE :brand", ["brand" => "%Nomos%"]);
// } else {
// $collections->setCondition("o_path LIKE :brand", ["brand" => "%".$brand->getName()."%"]);
// }
// $collections->load();
$collections = $brand->getCollections();
if($collections) {
$collections = $collections->getChildren();
} else {
continue;
}
$brandid = $brand->getId();
foreach($collections as $coll) {
$key = $coll->getKey();
$products = new DataObject\Product\Listing();
if($brand->getName() == "A. Lange & Söhne") {
$products->setCondition("UPPER(`o_key`) LIKE \"%$key%\" AND brand__id = $brandid");
} elseif($coll->getId() == 281) {
$products->setCondition("`o_key` LIKE \"%$key%\" AND `o_key` NOT LIKE \"%Superocean Heritage%\" AND brand__id = $brandid");
} elseif($coll->getId() == 285) {
$products->setCondition("`o_key` LIKE \"% Avi %\" AND brand__id = $brandid");
} else {
$products->setCondition("`o_key` LIKE \"%$key%\" AND brand__id = $brandid");
}
$products->load();
foreach($products as $product) {
$cats = $product->getCategories();
if($cats) {
if (!in_array($coll, $cats, true)) {
array_push($cats, $coll);
}
} else {
array_push($cats, $coll);
}
$product->setCategories($cats);
$product->save();
}
}
echo "Brand: " . $brand->getName() . " done <br><hr><br>";
}
exit;
foreach($brands as $brand) {
$collections = new DataObject\Category\Listing();
$collections->setCondition("o_path LIKE :brand", ["brand" => "%".$brand->getName()."%"]);
$collections->load();
foreach($collections as $coll) {
$key = $coll->getKey();
$products = new DataObject\Product\Listing();
if($brand->getName() == "A. Lange & Söhne") {
$products->setCondition("UPPER(`o_key`) LIKE '%$key%'");
} else {
$products->setCondition("`o_key` LIKE '%$key%'");
}
$products->load();
foreach($products as $product) {
$cats = $product->getCategories();
if (!in_array($coll, $cats)) {
array_push($cats, $coll);
}
$product->setCategories($cats);
$product->save();
}
}
echo "Brand: " . $brand->getName() . " done <br><hr><br>";
}
exit;
return [];
}
/**
* @Template
* @param Request $request
* @return array
*/
public function testAction(Request $request) {
ini_set('memory_limit', '1024M');
$listing = new \Pimcore\Model\Document\Listing();
$listing = $listing->load();
foreach($listing as $doc) {
$key = $doc->getKey();
$key = str_replace(" ", "-", $key);
$doc->setKey($key);
$doc->save();
}
exit;
// $brands = new DataObject\Product\Listing();
//
//
// $brands->setCondition("o_path LIKE '%Uhren%' AND o_modificationDate > 1667284831");
// $brands->load();
//
// var_dump(count($brands));
exit;
return [];
}
/**
* @Template
* @param Request $request
* @return array
*/
public function importSingleProductAction(Request $request) {
$searchstring = str_replace("/", "", $request->get("searchstring"));
$servername = "carat-dev.cp4unapazytb.eu-central-1.rds.amazonaws.com";
$username = "atimis";
$password = "gui8kknyzG";
$dbname = "carat_100";
// Create connection
$conn = new \mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$conn->set_charset("utf8mb4");
$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`;";
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$extId = $row["id"];
$prObject = DataObject::getByPath("/PIM/01 Uhren/02 Produkte/" . $row["brand"] . "/" . $row["productLine"] . "-" . $row["articleNumber"]);
if($prObject) {
$newObject = $prObject;
} else {
$newObject = new DataObject\Product();
$newObject->setKey(\Pimcore\Model\Element\Service::getValidKey($row["productLine"] . "-" . $row["articleNumber"], 'object'));
$folder = DataObject::getByPath("/PIM/01 Uhren/02 Produkte/" . $row["brand"]);
if($folder == null) {
$folder = new DataObject\Folder();
$folder->setKey(\Pimcore\Model\Element\Service::getValidKey($row["brand"], 'folder'));
$folder->setParentId(61);
$folder->save();
}
$parentId = $folder->getId();
$newObject->setParentId($parentId);
}
$newObject->setModel($row["productLine"]);
$newObject->setArticleNumber($row["articleNumber"]);
$newObject->setExtId($row["id"]);
$newObject->setPrice($row["price"]);
//set brand
$brand = $object = DataObject::getByPath("/PIM/01 Uhren/01 Marken/" . $row["brand"]);
$newObject->setBrand($brand);
//set specifications
$items = new DataObject\Fieldcollection();
$specsql = "SELECT name, value FROM `ArticleProperty` WHERE `article_id` = $extId;";
$specresult = $conn->query($specsql);
while($specrow = $specresult->fetch_assoc()) {
$item = new DataObject\Fieldcollection\Data\Specification();
$item->setSpecKey($specrow["name"]);
$item->setSpecValue($specrow["value"]);
$items->add($item);
}
$newObject->setSpecs($items);
//set frontimage
$imagesql = "SELECT src FROM `Image` WHERE `article_id` = $extId;";
$imageresult = $conn->query($imagesql);
$assetfolderpath = "/PIM/01 Uhren/02 Produkte/" . $row["brand"] . "/" . str_replace("/", "-", $row["productLine"]) . "-" . $row["articleNumber"];
Asset\Service::createFolderByPath($assetfolderpath);
$counter = 0;
$addImages = [];
while($imagerow = $imageresult->fetch_assoc()) {
$counter += 1;
$newAsset = new \Pimcore\Model\Asset\Image();
$newAsset->setFilename($imagerow["src"]);
$newAsset->setData(file_get_contents("https://huebner.carat.solutions/carat/filedownload?fileName=" . $imagerow["src"]));
$newAsset->setParent(\Pimcore\Model\Asset::getByPath($assetfolderpath));
$checkasset = null;
$checkasset = \Pimcore\Model\Asset::getByPath($assetfolderpath . "/" . $imagerow["src"]);
if($checkasset) {
$newAsset = $checkasset;
} else {
$newAsset->save();
}
if($counter == 1) {
$newObject->setFrontimage($newAsset);
} else {
array_push($addImages, $newAsset);
}
}
if(count($addImages) > 0) {
$newObject->setImages(new \Pimcore\Model\DataObject\Data\ImageGallery($addImages));
}
//set gender
$gendercat = DataObject::getByPath("/PIM/01 Uhren/03 Kategorien/" . $row["subcategory"]);
$cats = [$gendercat];
$newObject->setCategories($cats);
$newObject->setPublished(true);
$newObject->save();
echo "Produkt: " . $row["productLine"] . "-" . $row["articleNumber"] . " erfolgreich importiert";
//var_dump($brand);
}
$conn->close();
exit;
}
/**
* @Template
* @param Request $request
* @return array
*/
public function addJewelleryCatsAction(Request $request) {
$products = new DataObject\Product\Listing();
$products->setCondition("o_path LIKE '%Schmuck%'");
$products->load();
$i = 0;
foreach($products as $product) {
$catstring = $product->getCatstring();
$categories = new DataObject\Category\Listing();
$categories->setCondition("o_path LIKE '%02 Schmuck/03 Kategorien%' AND caratvalues LIKE '%$catstring%'");
$categories->load();
foreach($categories as $cat) {
$cats = $product->getCategories();
if(is_array($cats)) {
if(!in_array($cat, $cats)) {
$cats[] = $cat;
}
} else {
if(!in_array($cat, $cats)) {
$cats = [];
$cats[] = $cat;
}
}
$product->setCategories($cats);
$product->save();
$i++;
}
}
$brands = new DataObject\Brand\Listing();
$brands->setCondition("o_path LIKE '%Schmuck%'");
$brands->load();
foreach($brands as $brand) {
$collections = $brand->getCollections();
$collections = $collections->getChildren();
$brandid = $brand->getId();
foreach($collections as $coll) {
$key = $coll->getKey();
$products = new DataObject\Product\Listing();
$products->setCondition("`o_key` LIKE \"%$key%\" AND brand__id = $brandid AND o_path LIKE '%Schmuck%'");
$products->load();
foreach($products as $product) {
$cats = $product->getCategories();
if($cats) {
if (!in_array($coll, $cats, true)) {
array_push($cats, $coll);
}
} else {
array_push($cats, $coll);
}
$product->setCategories($cats);
$product->save();
}
}
}
//echo "done $i products";
exit;
return [];
}
/**
* @Template
* @param Request $request
* @return array
*/
public function importSingleJewelleryProductAction(Request $request) {
$servername = "carat-dev.cp4unapazytb.eu-central-1.rds.amazonaws.com";
$username = "atimis";
$password = "gui8kknyzG";
$dbname = "carat_100";
// Create connection
$conn = new \mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$conn->set_charset("utf8mb4");
// FINAL QUERY
$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'";
// END FINAL QUERY
// $sql = "SELECT * FROM Article WHERE `brand` LIKE '%Lange%' LIMIT 10;";
$result = $conn->query($sql);
// var_dump($result);
// exit;
while($row = $result->fetch_assoc()) {
$extId = $row["id"];
$row = array_map('trim', $row);
$key = \Pimcore\Model\Element\Service::getValidKey($row["productLine"] . "-" . $row["articleNumber"], 'object');
$prObject = DataObject::getByPath("/PIM/02 Schmuck/02 Produkte/" . $row["brand"] . "/" . $key);
if($prObject) {
$checkstring = date('d-m-y');
//$checkstring .= 'manual';
if($prObject->getUpdateInfo() == $checkstring) {
continue;
}
$newObject = $prObject;
$newObject->setupdateinfo($checkstring);
} else {
$newObject = new DataObject\Product();
$newObject->setKey($key);
$newObject->setupdateinfo($checkstring);
// get Brand Folder ID
$folder = DataObject::getByPath("/PIM/02 Schmuck/02 Produkte/" . $row["brand"]);
// if($row["brand"] == "Jaeger-LeCoultre") {
// $folder = DataObject::getById(396);
// }
if($row["brand"] == "FOPE") {
$folder = DataObject::getById(3160);
}
if($row["brand"] == "Aldusblatt Herzog Loibner") {
$folder = DataObject::getById(1712);
}
if($folder == null) {
$folder = new DataObject\Folder();
$folder->setKey(\Pimcore\Model\Element\Service::getValidKey($row["brand"], 'folder'));
$folder->setParentId(64);
$folder->save();
}
$parentId = $folder->getId();
$newObject->setParentId($parentId);
}
$newObject->setModel($row["productLine"]);
$newObject->setArticleNumber($row["articleNumber"]);
$newObject->setStockInputDate($row["stockInputDate"]);
$newObject->setExtId($row["id"]);
$newObject->setPrice($row["price"]);
$newObject->setCatstring($row["subcategory"]);
//set brand
$brand = DataObject::getByPath("/PIM/02 Schmuck/01 Marken/" . $row["brand"]);
// if($row["brand"] == "Jaeger-LeCoultre") {
// $brand = DataObject\Brand::getById(23);
// }
if($row["brand"] == "FOPE") {
$brand = DataObject::getById(3201);
}
if($row["brand"] == "Aldusblatt Herzog Loibner") {
$brand = DataObject::getById(99);
}
$newObject->setBrand($brand);
//set specifications
$items = new DataObject\Fieldcollection();
$specsql = "SELECT carat, label, number, description FROM `GemItem` WHERE `article_id` = $extId;";
$specresult = $conn->query($specsql);
while($specrow = $specresult->fetch_assoc()) {
$item = new DataObject\Fieldcollection\Data\JewellerySpecification();
$item->setSpecKey($specrow["label"]);
$item->setSpecValue($specrow["carat"]);
$item->setSpecCount($specrow["number"]);
$item->setSpecDescription($specrow["description"]);
$items->add($item);
}
$specsql = "SELECT name, value FROM `ArticleProperty` WHERE `article_id` = $extId;";
$specresult = $conn->query($specsql);
while($specrow = $specresult->fetch_assoc()) {
$item = new DataObject\Fieldcollection\Data\JewellerySpecification();
$item->setSpecKey($specrow["name"]);
$item->setSpecValue($specrow["value"]);
$item->setSpecCount(null);
$item->setSpecDescription(null);
$items->add($item);
}
$newObject->setSpecs($items);
//set frontimage
$imagesql = "SELECT src FROM `Image` WHERE `article_id` = $extId;";
$imageresult = $conn->query($imagesql);
$articlenumber = str_replace("/", "-", $row["articleNumber"]);
$assetfolderpath = "/PIM/02 Schmuck/02 Produkte/" . $row["brand"] . "/" . str_replace(["/", '"', "+"], ["-", "", ""], $row["productLine"]) . "-" . $articlenumber;
$assetfolderpath = str_replace("+", "", $assetfolderpath);
$assetfolderpath = str_replace(".", "", $assetfolderpath);
$assetfolderpath = str_replace("|", "", $assetfolderpath);
$assetfolderpath = str_replace("Ăź", "ss", $assetfolderpath);
Asset\Service::createFolderByPath($assetfolderpath);
$counter = 0;
$addImages = [];
while($imagerow = $imageresult->fetch_assoc()) {
$counter += 1;
$newAsset = new \Pimcore\Model\Asset\Image();
$newAsset->setFilename($imagerow["src"]);
$newAsset->setData(file_get_contents("https://huebner.carat.solutions/carat/filedownload?fileName=" . $imagerow["src"]));
$newAsset->setParent(\Pimcore\Model\Asset::getByPath($assetfolderpath));
$checkasset = null;
$checkasset = \Pimcore\Model\Asset::getByPath($assetfolderpath . "/" . $imagerow["src"]);
echo "trying to save asset for " . $row["productLine"] . "-" . $row["articleNumber"] . "<br><hr><br>";
if(strpos($imagerow["src"], "html") == false && strpos($imagerow["src"], "avif") == false && $imagerow["src"] != "7281fa99-3001-41a5-9be1-8dcfe04d997b.") {
if($checkasset) {
$checkasset->delete();
$newAsset->save();
} else {
$newAsset->save();
}
}
if($counter == 1) {
$newObject->setFrontimage($newAsset);
} else {
$advancedImage = new \Pimcore\Model\DataObject\Data\Hotspotimage();
$advancedImage->setImage($newAsset);
array_push($addImages, $advancedImage);
}
}
if(count($addImages) > 0) {
$newObject->setImages(new \Pimcore\Model\DataObject\Data\ImageGallery($addImages));
}
//var_dump($addImages);
//set gender
// $gendercat = DataObject::getByPath("/PIM/01 Uhren/03 Kategorien/" . $row["subcategory"]);
// if(!$gendercat) {
// $newcat = new DataObject\Category();
// $newcat->setKey(\Pimcore\Model\Element\Service::getValidKey($row["subcategory"], 'object'));
// $newcat->setParentId(101);
// $newcat->setTitle($row["subcategory"]);
// $newcat->setPublished(true);
// $newcat->save();
// $gendercat = $newcat;
// }
// $cats = [$gendercat];
// $newObject->setCategories($cats);
$newObject->setPublished(true);
$newObject->save();
//var_dump($brand);
}
$conn->close();
exit;
return [];
}
/**
* @Template
* @param Request $request
* @return array
*/
public function updateProductAction(Request $request) {
$id = str_replace("/", "", $request->get("caratid"));
$pimId = str_replace("/", "", $request->get("pimid"));
$servername = "carat-dev.cp4unapazytb.eu-central-1.rds.amazonaws.com";
//$servername = "52.29.59.182";
$username = "atimis";
$password = "gui8kknyzG";
$dbname = "carat_100";
// Create connection
$conn = new \mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$conn->set_charset("utf8mb4");
// FINAL QUERY
$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`";
// END FINAL QUERY
// $sql = "SELECT * FROM Article WHERE `brand` LIKE '%Lange%' LIMIT 10;";
$result = $conn->query($sql);
// var_dump($result);
// exit;
while($row = $result->fetch_assoc()) {
$extId = $row["id"];
$row = array_map('trim', $row);
$watchjewel = $row["category"];
if($watchjewel == "Uhr") {
$key = \Pimcore\Model\Element\Service::getValidKey($row["productLine"] . "-" . $row["articleNumber"], 'object');
$prObject = DataObject::getById($pimId);
$checkstring = date('d-m-y');
//$checkstring .= 'manual';
// $checkstring .= "-zenith";
if($prObject) {
// if($prObject->getUpdateinfo() == "291122-try1" || $prObject->getUpdateinfo() == "291122-try2" || $prObject->getUpdateinfo() == "291122-try3" || $prObject->getUpdateinfo() == "291122-try4") {
// continue;
// }
if($prObject->getUpdateInfo() == $checkstring) {
//continue;
}
$newObject = $prObject;
$newObject->setupdateinfo($checkstring);
} else {
$newObject = new DataObject\Product();
$newObject->setKey($key);
$newObject->setupdateinfo($checkstring);
// get Brand Folder ID
$folder = DataObject::getByPath("/PIM/01 Uhren/02 Produkte/" . $row["brand"]);
if($row["brand"] == "Jaeger-LeCoultre") {
$folder = DataObject::getById(396);
}
if($row["brand"] == "IWC") {
$folder = DataObject::getById(962);
}
if($row["brand"] == "Nomos GlashĂĽtte") {
$folder = DataObject::getById(407);
}
if($folder == null) {
$folder = new DataObject\Folder();
$folder->setKey(\Pimcore\Model\Element\Service::getValidKey($row["brand"], 'folder'));
$folder->setParentId(61);
$folder->save();
}
$parentId = $folder->getId();
$newObject->setParentId($parentId);
}
$newObject->setModel($row["productLine"]);
$newObject->setArticleNumber($row["articleNumber"]);
$newObject->setStockInputDate($row["stockInputDate"]);
$newObject->setExtId($row["id"]);
$newObject->setPrice($row["price"]);
//set brand
$brand = DataObject::getByPath("/PIM/01 Uhren/01 Marken/" . $row["brand"]);
if($row["brand"] == "Jaeger-LeCoultre") {
$brand = DataObject\Brand::getById(23);
}
if($row["brand"] == "IWC") {
$brand = DataObject\Brand::getById(82);
}
if($row["brand"] == "Nomos GlashĂĽtte") {
$brand = DataObject\Brand::getById(85);
}
if($row["brand"] == "Sattler") {
$brand = DataObject\Brand::getById(77);
}
$newObject->setBrand($brand);
//set specifications
$items = new DataObject\Fieldcollection();
$specsql = "SELECT name, value FROM `ArticleProperty` WHERE `article_id` = $extId;";
$specresult = $conn->query($specsql);
while($specrow = $specresult->fetch_assoc()) {
$item = new DataObject\Fieldcollection\Data\Specification();
$item->setSpecKey($specrow["name"]);
$item->setSpecValue($specrow["value"]);
$items->add($item);
}
$newObject->setSpecs($items);
//set frontimage
$imagesql = "SELECT src FROM `Image` WHERE `article_id` = $extId;";
$imageresult = $conn->query($imagesql);
$articlenumber = str_replace("/", "-", $row["articleNumber"]);
$assetfolderpath = "/PIM/01 Uhren/02 Produkte/" . $row["brand"] . "/" . str_replace(["/", '"', "+"], ["-", "", ""], $row["productLine"]) . "-" . $articlenumber;
$assetfolderpath = str_replace("+", "", $assetfolderpath);
$assetfolderpath = str_replace(".", "", $assetfolderpath);
$assetfolderpath = str_replace("|", "", $assetfolderpath);
$assetfolderpath = str_replace("Ăź", "ss", $assetfolderpath);
Asset\Service::createFolderByPath($assetfolderpath);
$counter = 0;
$addImages = [];
while($imagerow = $imageresult->fetch_assoc()) {
$counter += 1;
$newAsset = new \Pimcore\Model\Asset\Image();
$newAsset->setFilename($imagerow["src"]);
$newAsset->setData(file_get_contents("https://huebner.carat.solutions/carat/filedownload?fileName=" . $imagerow["src"]));
$newAsset->setParent(\Pimcore\Model\Asset::getByPath($assetfolderpath));
$checkasset = null;
$checkasset = \Pimcore\Model\Asset::getByPath($assetfolderpath . "/" . $imagerow["src"]);
//echo "trying to save asset for " . $row["productLine"] . "-" . $row["articleNumber"] . "<br><hr><br>";
if(strpos($imagerow["src"], "html") == false && strpos($imagerow["src"], "avif") == false && $imagerow["src"] != "7281fa99-3001-41a5-9be1-8dcfe04d997b.") {
if($checkasset) {
$checkasset->delete();
$newAsset->save();
} else {
// var_dump($newAsset->getFullPath());
// var_dump($assetfolderpath);
// var_dump(\Pimcore\Model\Asset::getByPath($assetfolderpath));
// exit;
$newAsset->save();
}
}
if($counter == 1) {
$newObject->setFrontimage($newAsset);
} else {
$advancedImage = new \Pimcore\Model\DataObject\Data\Hotspotimage();
$advancedImage->setImage($newAsset);
array_push($addImages, $advancedImage);
}
}
if(count($addImages) > 0) {
$newObject->setImages(new \Pimcore\Model\DataObject\Data\ImageGallery($addImages));
}
//var_dump($addImages);
//set gender
$gendercat = DataObject::getByPath("/PIM/01 Uhren/03 Kategorien/" . $row["subcategory"]);
if(!$gendercat) {
$newcat = new DataObject\Category();
$newcat->setKey(\Pimcore\Model\Element\Service::getValidKey($row["subcategory"], 'object'));
$newcat->setParentId(101);
$newcat->setTitle($row["subcategory"]);
$newcat->setPublished(true);
$newcat->save();
$gendercat = $newcat;
}
$cats = [$gendercat];
$newObject->setCategories($cats);
$newObject->setPublished(true);
$newObject->save();
$this->addBrandCollections($brand);
} elseif($watchjewel == "Schmuck") {
$key = \Pimcore\Model\Element\Service::getValidKey($row["productLine"] . "-" . $row["articleNumber"], 'object');
$prObject = DataObject::getById($pimId);
$checkstring = date('d-m-y');
//$checkstring .= 'manual';
// $checkstring .= "-zenith";
if($prObject) {
// if($prObject->getUpdateinfo() == "291122-try1" || $prObject->getUpdateinfo() == "291122-try2" || $prObject->getUpdateinfo() == "291122-try3" || $prObject->getUpdateinfo() == "291122-try4") {
// continue;
// }
if($prObject->getUpdateInfo() == $checkstring) {
//continue;
}
$newObject = $prObject;
$newObject->setupdateinfo($checkstring);
} else {
$newObject = new DataObject\Product();
$newObject->setKey($key);
$newObject->setupdateinfo($checkstring);
// get Brand Folder ID
$folder = DataObject::getByPath("/PIM/02 Schmuck/02 Produkte/" . $row["brand"]);
if($folder == null) {
$folder = new DataObject\Folder();
$folder->setKey(\Pimcore\Model\Element\Service::getValidKey($row["brand"], 'folder'));
$folder->setParentId(64);
$folder->save();
}
$parentId = $folder->getId();
$newObject->setParentId($parentId);
}
$newObject->setModel($row["productLine"]);
$newObject->setArticleNumber($row["articleNumber"]);
$newObject->setStockInputDate($row["stockInputDate"]);
$newObject->setExtId($row["id"]);
$newObject->setPrice($row["price"]);
//set brand
$brand = DataObject::getByPath("/PIM/02 Schmuck/01 Marken/" . $row["brand"]);
if($row["brand"] == "Jaeger-LeCoultre") {
$brand = DataObject\Brand::getById(23);
}
if($row["brand"] == "IWC") {
$brand = DataObject\Brand::getById(82);
}
if($row["brand"] == "Nomos GlashĂĽtte") {
$brand = DataObject\Brand::getById(85);
}
if($row["brand"] == "Sattler") {
$brand = DataObject\Brand::getById(77);
}
$newObject->setBrand($brand);
//set specifications
$items = new DataObject\Fieldcollection();
$specsql = "SELECT name, value FROM `ArticleProperty` WHERE `article_id` = $extId;";
$specresult = $conn->query($specsql);
while($specrow = $specresult->fetch_assoc()) {
$item = new DataObject\Fieldcollection\Data\Specification();
$item->setSpecKey($specrow["name"]);
$item->setSpecValue($specrow["value"]);
$items->add($item);
}
$newObject->setSpecs($items);
//set frontimage
$imagesql = "SELECT src FROM `Image` WHERE `article_id` = $extId;";
$imageresult = $conn->query($imagesql);
$articlenumber = str_replace("/", "-", $row["articleNumber"]);
$assetfolderpath = "/PIM/02 Schmuck/02 Produkte/" . $row["brand"] . "/" . str_replace(["/", '"', "+"], ["-", "", ""], $row["productLine"]) . "-" . $articlenumber;
$assetfolderpath = str_replace("+", "", $assetfolderpath);
$assetfolderpath = str_replace(".", "", $assetfolderpath);
$assetfolderpath = str_replace("|", "", $assetfolderpath);
$assetfolderpath = str_replace("Ăź", "ss", $assetfolderpath);
Asset\Service::createFolderByPath($assetfolderpath);
$counter = 0;
$addImages = [];
while($imagerow = $imageresult->fetch_assoc()) {
$counter += 1;
$newAsset = new \Pimcore\Model\Asset\Image();
$newAsset->setFilename($imagerow["src"]);
$newAsset->setData(file_get_contents("https://huebner.carat.solutions/carat/filedownload?fileName=" . $imagerow["src"]));
$newAsset->setParent(\Pimcore\Model\Asset::getByPath($assetfolderpath));
$checkasset = null;
$checkasset = \Pimcore\Model\Asset::getByPath($assetfolderpath . "/" . $imagerow["src"]);
//echo "trying to save asset for " . $row["productLine"] . "-" . $row["articleNumber"] . "<br><hr><br>";
if(strpos($imagerow["src"], "html") == false && strpos($imagerow["src"], "avif") == false && $imagerow["src"] != "7281fa99-3001-41a5-9be1-8dcfe04d997b.") {
if($checkasset) {
$checkasset->delete();
$newAsset->save();
} else {
// var_dump($newAsset->getFullPath());
// var_dump($assetfolderpath);
// var_dump(\Pimcore\Model\Asset::getByPath($assetfolderpath));
// exit;
$newAsset->save();
}
}
if($counter == 1) {
$newObject->setFrontimage($newAsset);
} else {
$advancedImage = new \Pimcore\Model\DataObject\Data\Hotspotimage();
$advancedImage->setImage($newAsset);
array_push($addImages, $advancedImage);
}
}
if(count($addImages) > 0) {
$newObject->setImages(new \Pimcore\Model\DataObject\Data\ImageGallery($addImages));
}
//var_dump($addImages);
//set gender
// $gendercat = DataObject::getByPath("/PIM/01 Uhren/03 Kategorien/" . $row["subcategory"]);
// if(!$gendercat) {
// $newcat = new DataObject\Category();
// $newcat->setKey(\Pimcore\Model\Element\Service::getValidKey($row["subcategory"], 'object'));
// $newcat->setParentId(101);
// $newcat->setTitle($row["subcategory"]);
// $newcat->setPublished(true);
// $newcat->save();
// $gendercat = $newcat;
// }
//
// $cats = [$gendercat];
// $newObject->setCategories($cats);
$newObject->setPublished(true);
$newObject->save();
$this->addBrandCollections($brand);
}
//var_dump($brand);
}
$conn->close();
echo "success";
exit;
return [];
}
/**
* @Template
* @param Request $request
* @return array
*/
public function importAction(Request $request) {
$servername = "carat-dev.cp4unapazytb.eu-central-1.rds.amazonaws.com";
//$servername = "52.29.59.182";
$username = "atimis";
$password = "gui8kknyzG";
$dbname = "carat_100";
// Create connection
$conn = new \mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$conn->set_charset("utf8mb4");
//$sql = "SELECT * FROM Article LIMIT 10";
// $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;";
// $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";
// $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`;";
// fix " "
// $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`";
// BRAND QUERY
// $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`";
// FINAL QUERY
$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`";
// $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`";
// END FINAL QUERY
// $sql = "SELECT * FROM Article WHERE `brand` LIKE '%Lange%' LIMIT 10;";
$result = $conn->query($sql);
// var_dump($result);
// exit;
while($row = $result->fetch_assoc()) {
$extId = $row["id"];
$row = array_map('trim', $row);
$key = \Pimcore\Model\Element\Service::getValidKey($row["productLine"] . "-" . $row["articleNumber"], 'object');
$prObject = DataObject::getByPath("/PIM/01 Uhren/02 Produkte/" . $row["brand"] . "/" . $key);
$checkstring = date('d-m-y');
//$checkstring .= 'manual';
// $checkstring .= "-zenith";
if($prObject) {
// if($prObject->getUpdateinfo() == "291122-try1" || $prObject->getUpdateinfo() == "291122-try2" || $prObject->getUpdateinfo() == "291122-try3" || $prObject->getUpdateinfo() == "291122-try4") {
// continue;
// }
if($prObject->getUpdateInfo() == $checkstring) {
continue;
}
$newObject = $prObject;
$newObject->setupdateinfo($checkstring);
} else {
$newObject = new DataObject\Product();
$newObject->setKey($key);
$newObject->setupdateinfo($checkstring);
// get Brand Folder ID
$folder = DataObject::getByPath("/PIM/01 Uhren/02 Produkte/" . $row["brand"]);
if($row["brand"] == "Jaeger-LeCoultre") {
$folder = DataObject::getById(396);
}
if($row["brand"] == "IWC") {
$folder = DataObject::getById(962);
}
if($row["brand"] == "Nomos GlashĂĽtte") {
$folder = DataObject::getById(407);
}
if($folder == null) {
$folder = new DataObject\Folder();
$folder->setKey(\Pimcore\Model\Element\Service::getValidKey($row["brand"], 'folder'));
$folder->setParentId(61);
$folder->save();
}
$parentId = $folder->getId();
$newObject->setParentId($parentId);
}
$newObject->setModel($row["productLine"]);
$newObject->setArticleNumber($row["articleNumber"]);
$newObject->setStockInputDate($row["stockInputDate"]);
$newObject->setExtId($row["id"]);
$newObject->setPrice($row["price"]);
//set brand
$brand = DataObject::getByPath("/PIM/01 Uhren/01 Marken/" . $row["brand"]);
if($row["brand"] == "Jaeger-LeCoultre") {
$brand = DataObject\Brand::getById(23);
}
if($row["brand"] == "IWC") {
$brand = DataObject\Brand::getById(82);
}
if($row["brand"] == "Nomos GlashĂĽtte") {
$brand = DataObject\Brand::getById(85);
}
if($row["brand"] == "Sattler") {
$brand = DataObject\Brand::getById(77);
}
$newObject->setBrand($brand);
//set specifications
$items = new DataObject\Fieldcollection();
$specsql = "SELECT name, value FROM `ArticleProperty` WHERE `article_id` = $extId;";
$specresult = $conn->query($specsql);
while($specrow = $specresult->fetch_assoc()) {
$item = new DataObject\Fieldcollection\Data\Specification();
$item->setSpecKey($specrow["name"]);
$item->setSpecValue($specrow["value"]);
$items->add($item);
}
$newObject->setSpecs($items);
//set frontimage
$imagesql = "SELECT src FROM `Image` WHERE `article_id` = $extId;";
$imageresult = $conn->query($imagesql);
$articlenumber = str_replace("/", "-", $row["articleNumber"]);
$assetfolderpath = "/PIM/01 Uhren/02 Produkte/" . $row["brand"] . "/" . str_replace(["/", '"', "+"], ["-", "", ""], $row["productLine"]) . "-" . $articlenumber;
$assetfolderpath = str_replace("+", "", $assetfolderpath);
$assetfolderpath = str_replace(".", "", $assetfolderpath);
$assetfolderpath = str_replace("|", "", $assetfolderpath);
$assetfolderpath = str_replace("Ăź", "ss", $assetfolderpath);
Asset\Service::createFolderByPath($assetfolderpath);
$counter = 0;
$addImages = [];
while($imagerow = $imageresult->fetch_assoc()) {
$counter += 1;
$newAsset = new \Pimcore\Model\Asset\Image();
$newAsset->setFilename($imagerow["src"]);
$newAsset->setData(file_get_contents("https://huebner.carat.solutions/carat/filedownload?fileName=" . $imagerow["src"]));
$newAsset->setParent(\Pimcore\Model\Asset::getByPath($assetfolderpath));
$checkasset = null;
$checkasset = \Pimcore\Model\Asset::getByPath($assetfolderpath . "/" . $imagerow["src"]);
echo "trying to save asset for " . $row["productLine"] . "-" . $row["articleNumber"] . "<br><hr><br>";
if(strpos($imagerow["src"], "html") == false && strpos($imagerow["src"], "htm") == false && $imagerow["src"] != "7281fa99-3001-41a5-9be1-8dcfe04d997b.") {
if($checkasset) {
$checkasset->setData(file_get_contents("https://huebner.carat.solutions/carat/filedownload?fileName=" . $imagerow["src"]));
$checkasset->save();
$newAsset = $checkasset;
} else {
// var_dump($newAsset->getFullPath());
// var_dump($assetfolderpath);
// var_dump(\Pimcore\Model\Asset::getByPath($assetfolderpath));
// exit;
$newAsset->save();
}
$newAsset->save();
}
if($counter == 1) {
$newObject->setFrontimage($newAsset);
} else {
$advancedImage = new \Pimcore\Model\DataObject\Data\Hotspotimage();
$advancedImage->setImage($newAsset);
array_push($addImages, $advancedImage);
}
}
if(count($addImages) > 0) {
$newObject->setImages(new \Pimcore\Model\DataObject\Data\ImageGallery($addImages));
}
//var_dump($addImages);
//set gender
$gendercat = DataObject::getByPath("/PIM/01 Uhren/03 Kategorien/" . $row["subcategory"]);
if(!$gendercat) {
$newcat = new DataObject\Category();
$newcat->setKey(\Pimcore\Model\Element\Service::getValidKey($row["subcategory"], 'object'));
$newcat->setParentId(101);
$newcat->setTitle($row["subcategory"]);
$newcat->setPublished(true);
$newcat->save();
$gendercat = $newcat;
}
$cats = [$gendercat];
$newObject->setCategories($cats);
$newObject->setPublished(true);
$newObject->save();
//var_dump($brand);
}
$conn->close();
exit;
return [];
}
/**
* @Template
* @param Request $request
* @return array
*/
public function categoryAction(Request $request) {
return [];
}
/**
* @Template
* @param Request $request
* @return array
*/
public function homeAction(Request $request) {
return [];
}
/**
* @Template
* @param Request $request
* @return array
*/
public function productOverviewAction(Request $request) {
$jewellerycategory = null;
$entries = new DataObject\Product\Listing();
$filters = [];
$page = isset($_GET["page"]) ? $_GET["page"] : null;
if($page) {
if($page == 1) {
$entries->setLimit(24);
}
$filters["page"] = $page;
}
$collection = isset($_GET["collection"]) ? $_GET["collection"] : null;
if($collection) {
$entries->addConditionParam("categories LIKE ?", "%object|$collection%", "AND");
$filters["collection"] = $collection;
}
$type = isset($_GET["type"]) ? $_GET["type"] : null;
if($type) {
//$entries->addConditionParam("categories LIKE ?", "%object|$type%", "AND");
$entries->setCondition("categories LIKE '%object|$type%'");
$filters["type"] = $type;
}
$brand = isset($_GET["brand"]) ? $_GET["brand"] : null;
if($brand) {
$entries->addConditionParam("brand__id = ?", "$brand", "AND");
$brandobject = DataObject::getById($brand);
$brandcollections = $brandobject->getCollections() ? $brandobject->getCollections()->getChildren() : null;
$filters["brand"] = $brand;
$filters["brandCollections"] = $brandcollections;
}
if (!$brand && $collection) {
$collectionObject = DataObject::getById($collection);
// var_dump($collection);
// exit;
$collectionpath = $collectionObject->getPath();
// var_dump($collectionpath);
// exit;
if(str_contains($collectionpath, "Schmuck")) {
$entries->addConditionParam("o_path LIKE '%Schmuck%'", "AND");
$jewellerycategory = $collectionObject;
} else {
$brandkey = $collectionObject->getParent()->getKey();
$brands = DataObject\Brand::getByName($brandkey);
$brand = $brands->load();
if(is_array($brand)) {
$brand = $brand[0];
$brandobject = $brand;
$brandcollections = $brandobject->getCollections() ? $brandobject->getCollections()->getChildren() : null;
$filters["brand"] = $brand->getId();
$filters["brandCollections"] = $brandcollections;
} else {
$brand = null;
$filters["brand"] = null;
$filters["brandCollections"] = null;
}
}
}
if(!isset($filters["brandCollections"])) {
$brandCollections = new DataObject\Category\Listing();
$brandCollections->setCondition("o_path LIKE '%Kollektionen%'");
$brandCollections = $brandCollections->load();
$filters["brandCollections"] = $brandCollections;
}
$casematerial = isset($_GET["casematerial"]) ? $_GET["casematerial"] : null;
if($casematerial) {
$entries->addFieldCollection("Specification", "specs");
$entries->addConditionParam("`Specification~specs`.specKey = 'Gehäusematerial' AND `Specification~specs`.specValue LIKE ?", "%$casematerial%", "AND");
$filters["casematerial"] = $casematerial;
}
$sort = isset($_GET["sort"]) ? $_GET["sort"] : null;
if($sort) {
switch($sort) {
case "actual":
$entries->setOrderKey("stockInputDate");
$entries->setOrder("desc");
break;
case "priceasc":
$entries->setOrderKey("price");
$entries->setOrder("asc");
break;
case "pricedesc":
$entries->setOrderKey("price");
$entries->setOrder("desc");
break;
case "name":
$entries->setOrderKey("model");
$entries->setOrder("asc");
break;
}
$filters["sort"] = $sort;
} else {
$entries->setOrderKey("stockInputDate");
$entries->setOrder("desc");
$filters["sort"] = "actual";
}
//var_dump($entries);
$entries = $entries->load();
return $this->render('/default/product_overview.html.twig', ["products" => $entries, "filters" => $filters, "jewellerycat" => $jewellerycategory]);
}
/**
* @Template
* @param Request $request
* @return array
*/
public function brandsOverviewAction(Request $request) {
$docpath = $this->document->getFullPath();
//var_dump($docpath);
if(strpos($docpath, "Uhren") !== false) {
$path = "Uhren";
} else {
$path = "Schmuck";
}
$entries = new DataObject\Brand\Listing();
$entries->setCondition("o_path LIKE '%$path%' ");
$entries->setOrderKey("o_key");
$entries->setOrder("ASC");
$entries->load();
return $this->render('/default/brands_overview.html.twig', ["brands" => $entries]);
}
/**
* @Template
* @param Request $request
* @return array
*/
public function teaserOverviewAction(Request $request) {
return [];
}
/**
* @Template
* @param Request $request
* @return array
*/
public function brandAction(Request $request) {
return $this->render('/default/brand.html.twig', []);
}
/**
* @Template
* @param Request $request
* @return array
*/
public function productAction(Request $request) {
$id = str_replace("/", "", $request->get("id"));
$product = DataObject::getById($id);
return $this->render('/default/product.html.twig', ["product" => $product]);
}
/**
* @Template
* @param Request $request
* @return array
*/
public function newproductAction(Request $request) {
$key = substr($request->get("key"), 1);
$number = substr($request->get("number"), 1);
$id = substr($request->get("id"), 1);
// var_dump($id);
// // exit;
// $product = DataObject\Product::getByArticleNumber($number);
//
// $product = $product->load()[0];
$product = DataObject::getById($id);
return $this->render('/default/product.html.twig', ["product" => $product]);
}
/**
* @Template
* @param Request $request
* @return array
*/
public function teaserAction(Request $request) {
$id = str_replace("/", "", $request->get("id"));
$teaser = DataObject::getById($id);
$relation = $teaser->getRelation();
if($relation && $relation->getType() == "object" && $relation->getClassName() == "Category") {
$collectionObject = $relation;
$brandkey = $collectionObject->getParent()->getKey();
$brands = DataObject\Brand::getByName($brandkey);
$brand = $brands->load();
if(is_array($brand)) {
$brand = $brand[0];
return $this->render('/default/teaser.html.twig', ["teaser" => $teaser, "brand" => $brand]);
}
} else {
return $this->render('/default/teaser.html.twig', ["teaser" => $teaser]);
}
}
private static function addBrandCollections($brand) {
$collections = new DataObject\Category\Listing();
if($brand->getId() == 85) {
$collections->setCondition("o_path LIKE :brand", ["brand" => "%Nomos%"]);
} else {
$collections->setCondition("o_path LIKE :brand", ["brand" => "%".$brand->getName()."%"]);
}
$collections->load();
$brandid = $brand->getId();
foreach($collections as $coll) {
$key = $coll->getKey();
$products = new DataObject\Product\Listing();
if($brand->getName() == "A. Lange & Söhne") {
$products->setCondition("UPPER(`o_key`) LIKE \"%$key%\" AND brand__id = $brandid");
} elseif($coll->getId() == 281) {
$products->setCondition("`o_key` LIKE \"%$key%\" AND `o_key` NOT LIKE \"%Superocean Heritage%\" AND brand__id = $brandid");
} elseif($coll->getId() == 285) {
$products->setCondition("`o_key` LIKE \"% Avi %\" AND brand__id = $brandid");
} else {
$products->setCondition("`o_key` LIKE \"%$key%\" AND brand__id = $brandid");
}
$products->load();
foreach($products as $product) {
$cats = $product->getCategories();
if($cats) {
if (!in_array($coll, $cats, true)) {
array_push($cats, $coll);
}
} else {
array_push($cats, $coll);
}
$product->setCategories($cats);
$product->save();
}
}
}
}