<?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 setDebugAction(Request $request) {
$cookie_name = "zeitdebug";
$cookie_value = "true";
setcookie($cookie_name, $cookie_value, time() + (86400 * 7), "/");
echo "Debugmode successfully set :-)";
exit;
return [];
}
/**
* @Template
* @param Request $request
* @return array
*/
public function addPriceDevAction(Request $request) {
$data = [
"54093" => "1185.60",
"54172" => "5520.00",
"54173" => "5786.67",
"54755" => "4426.67",
"54861" => "2647.50",
"54863" => "2143.00",
"54865" => "2445.50",
"54948" => "7866.67",
"54949" => "8640.00",
"55230" => "4588.50",
"55256" => "8143.00",
"55257" => "2698.00",
"55285" => "2213.34",
"56089" => "1502.80",
"56711" => "1307.80",
"57792" => "2054.00",
"57793" => "2054.00",
"57798" => "1144.00",
"57821" => "2145.00",
"57989" => "1131.00",
"58276" => "2106.00",
"58574" => "2119.00",
"58925" => "2431.00",
"59229" => "2496.00",
"59230" => "2496.00",
"59328" => "1037.40",
"60062" => "2925.00",
"60118" => "2275.00",
"60155" => "1014.00",
"60157" => "832.00",
"60455" => "1144.00",
"60457" => "1209.00",
"60546" => "1157.00",
"60666" => "1157.00",
"60755" => "988.00",
"61226" => "1443.00",
"61227" => "1664.00",
"61229" => "1443.00",
"61462" => "1404.00",
"61464" => "2158.00",
"61670" => "1664.00",
"61671" => "2145.00",
"61673" => "1196.00",
"61676" => "3172.00",
"61677" => "832.00",
"61715" => "2496.00",
"61877" => "1183.00",
"61880" => "2314.00",
"61912" => "3536.00",
"61930" => "1651.00",
"61931" => "1573.00",
"61977" => "1196.00",
"61978" => "1170.00",
"62014" => "1183.00",
"62015" => "1170.00",
"62016" => "5954.00",
"62017" => "1430.00",
"62033" => "1222.00",
"62141" => "2301.00",
"62162" => "2327.00",
"62163" => "2236.00",
"62300" => "2405.00",
"62524" => "2327.00",
"62525" => "2327.00",
"62657" => "1612.00",
"63750" => "1250.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, 'Teilwert4', $price, NULL, NULL, (SELECT `id` FROM `Item` WHERE `stockNumber` = $storageNumber), '2024-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/01 Uhren/02 Produkte/%' and type = 'image' and id != 273747 and id != 280811 and id != 273482");
$assets->setLimit(500);
$assets->setOffset(999);
$assets->setOrderKey("filename");
$assets->setOrder("ASC");
$assets->load();
$i = 0;
foreach($assets as $asset) {
$i++;
$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 $i;
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();
if($brand->getId() == 84) {
//conquest
$longinesCollectionConquest = DataObject::getById(7901);
$products = new DataObject\Product\Listing();
$products->setCondition("`o_key` LIKE \"%Conquest%\" OR `o_key` LIKE \"%Hydroconquest%\" AND brand__id = 84");
$products->load();
foreach($products as $product) {
$cats = $product->getCategories();
if($cats) {
if (!in_array($longinesCollectionConquest, $cats, true)) {
array_push($cats, $longinesCollectionConquest);
}
} else {
array_push($cats, $longinesCollectionConquest);
}
$product->setCategories($cats);
$product->save();
}
//master
$longinesCollectionMaster = DataObject::getById(316);
$products = new DataObject\Product\Listing();
$products->setCondition("`o_key` LIKE \"%Master%\" AND brand__id = 84");
$products->load();
foreach($products as $product) {
$cats = $product->getCategories();
if($cats) {
if (!in_array($longinesCollectionMaster, $cats, true)) {
array_push($cats, $longinesCollectionMaster);
}
} else {
array_push($cats, $longinesCollectionMaster);
}
$product->setCategories($cats);
$product->save();
}
//spirit
$longinesCollectionSpirit = DataObject::getById(329);
$products = new DataObject\Product\Listing();
$products->setCondition("`o_key` LIKE \"%Spirit%\" AND brand__id = 84");
$products->load();
foreach($products as $product) {
$cats = $product->getCategories();
if($cats) {
if (!in_array($longinesCollectionSpirit, $cats, true)) {
array_push($cats, $longinesCollectionSpirit);
}
} else {
array_push($cats, $longinesCollectionSpirit);
}
$product->setCategories($cats);
$product->save();
}
//elegance
$longinesCollectionElegance = DataObject::getById(10748);
$products = new DataObject\Product\Listing();
$products->setCondition("`o_key` LIKE \"%Dolcevita%\" OR `o_key` LIKE \"%Primaluna%\" OR `o_key` LIKE \"%Flagship%\" OR `o_key` LIKE \"%Evidenza%\" OR `o_key` LIKE \"%Record%\" OR `o_key` LIKE \"%Elegant%\" OR `o_key` LIKE \"%Classique%\" AND brand__id = 84");
$products->load();
foreach($products as $product) {
$cats = $product->getCategories();
if($cats) {
if (!in_array($longinesCollectionElegance, $cats, true)) {
array_push($cats, $longinesCollectionElegance);
}
} else {
array_push($cats, $longinesCollectionElegance);
}
$product->setCategories($cats);
$product->save();
}
//heritage
$longinesCollectionHeritage = DataObject::getById(10749);
$products = new DataObject\Product\Listing();
$products->setCondition("`o_key` LIKE \"%Legend%\" OR `o_key` LIKE \"%Ultra-Chron%\" OR `o_key` LIKE \"%Majetek%\" OR `o_key` LIKE \"%Heritage%\" OR `o_key` LIKE \"%Avigation%\" AND brand__id = 84");
$products->load();
foreach($products as $product) {
$cats = $product->getCategories();
if($cats) {
if (!in_array($longinesCollectionHeritage, $cats, true)) {
array_push($cats, $longinesCollectionHeritage);
}
} else {
array_push($cats, $longinesCollectionHeritage);
}
$product->setCategories($cats);
$product->save();
}
continue;
}
$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";
//
// $username = "atimis";
// $password = "gui8kknyzG";
// $dbname = "carat_100";
$servername = "node190984-carat.sh1.hidora.net";
$username = "phillip_script";
$password = "CCarat22PentLaks";
$dbname = "carat_100";
// Verbindungsdaten
$host = $servername;
$port = 443;
$user = $username; // Ersetze 'user' mit deinem tatsächlichen Benutzername
try {
// Verbindungsstring (DSN)
$dsn = "mysql:host=$host; port=$port; dbname=$dbname; charset=utf8";
// Verbindung herstellen
$pdo = new \PDO($dsn, $user, $password);
// Fehlerbehandlung auf Exceptions umstellen
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Verbindung erfolgreich!";
} catch (PDOException $e) {
// Fehler ausgeben
echo "Verbindung fehlgeschlagen: " . $e->getMessage();
} finally {
$pdo = null;
echo "Verbindung geschlossen.";
}
exit;
// Create connection
$conn = new \mysqli($servername, $username, $password, $dbname, 3306);
// 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` LIMIT 10";
// $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 newProductOverviewAction(Request $request) {
if(isset($_COOKIE['zeitdebug'])) {
$debug = "true";
} else {
$debug = "false";
}
$jewellerycategory = null;
$entries = new DataObject\Product\Listing();
$filters = [];
$page = isset($_GET["page"]) ? $_GET["page"] : 1;
if($page) {
$offset = 24 * (intval($page) -1);
$filters["page"] = $page;
}
$brandValues = new DataObject\Brand\Listing();
$brandValues->setCondition('o_path LIKE "%Uhren%"');
$brandValues->load();
$collection = isset($_GET["collection"]) ? $_GET["collection"] : null;
if($collection) {
$entries->addConditionParam("categories LIKE ?", "%object|$collection%", "AND");
$filters["collection"] = $collection;
}
$price = isset($_GET["price"]) ? $_GET["price"] : null;
if($price) {
switch ($price) {
case "until2500":
$grossPriceFrom = 0;
$grossPriceTo = 2500;
$netPriceFrom = 0.0;
$netPriceTo = $grossPriceTo / 1.2;
$entries->addConditionParam("price < ?", $netPriceTo, "AND");
break;
case "from2500until5000":
$grossPriceFrom = 2500;
$grossPriceTo = 5000;
$netPriceFrom = $grossPriceFrom / 1.2;
$netPriceTo = $grossPriceTo / 1.2;
$entries->addConditionParam("price > ?", $netPriceFrom, "AND");
$entries->addConditionParam("price < ?", $netPriceTo, "AND");
break;
case "from5000until10000":
$grossPriceFrom = 5000;
$grossPriceTo = 10000;
$netPriceFrom = $grossPriceFrom / 1.2;
$netPriceTo = $grossPriceTo / 1.2;
$entries->addConditionParam("price > ?", $netPriceFrom, "AND");
$entries->addConditionParam("price < ?", $netPriceTo, "AND");
break;
case "from100000until150000":
$grossPriceFrom = 10000;
$grossPriceTo = 15000;
$netPriceFrom = $grossPriceFrom / 1.2;
$netPriceTo = $grossPriceTo / 1.2;
$entries->addConditionParam("price > ?", $netPriceFrom, "AND");
$entries->addConditionParam("price < ?", $netPriceTo, "AND");
break;
case "from15000until20000":
$grossPriceFrom = 15000;
$grossPriceTo = 20000;
$netPriceFrom = $grossPriceFrom / 1.2;
$netPriceTo = $grossPriceTo / 1.2;
$entries->addConditionParam("price > ?", $netPriceFrom, "AND");
$entries->addConditionParam("price < ?", $netPriceTo, "AND");
break;
case "from20000":
$grossPriceFrom = 20000;
$netPriceFrom = $grossPriceFrom / 1.2;
$entries->addConditionParam("price > ?", $netPriceFrom, "AND");
break;
}
$filters["price"] = $price;
}
$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";
}
$entries->addConditionParam("brand__id IS NOT NULL", "", "AND");
$entries->addConditionParam("o_path LIKE ?", "%Uhren%", "AND");
$Countentries = $entries->load();
$entryCount = count($Countentries);
$limit = 24;
$entries->setLimit($limit);
$entries->setOffset($offset);
$entries = $entries->load();
return $this->render('/default/new_product_overview.html.twig', ["products" => $entries, "filters" => $filters, "jewellerycat" => $jewellerycategory, "debug" => $debug, 'brandValues' => $brandValues, "entryCount" => $entryCount]);
}
/**
* @Template
* @param Request $request
* @return array
*/
public function productOverviewAction(Request $request) {
if(isset($_COOKIE['zeitdebug'])) {
$debug = "true";
} else {
$debug = "false";
}
$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;
}
$price = isset($_GET["price"]) ? $_GET["price"] : null;
if($price) {
switch ($price) {
case "until2500":
$grossPriceFrom = 0;
$grossPriceTo = 2500;
$netPriceFrom = 0.0;
$netPriceTo = $grossPriceTo / 1.2;
$entries->addConditionParam("price < ?", $netPriceTo, "AND");
break;
case "from2500until5000":
$grossPriceFrom = 2500;
$grossPriceTo = 5000;
$netPriceFrom = $grossPriceFrom / 1.2;
$netPriceTo = $grossPriceTo / 1.2;
$entries->addConditionParam("price > ?", $netPriceFrom, "AND");
$entries->addConditionParam("price < ?", $netPriceTo, "AND");
break;
case "from5000until10000":
$grossPriceFrom = 5000;
$grossPriceTo = 10000;
$netPriceFrom = $grossPriceFrom / 1.2;
$netPriceTo = $grossPriceTo / 1.2;
$entries->addConditionParam("price > ?", $netPriceFrom, "AND");
$entries->addConditionParam("price < ?", $netPriceTo, "AND");
break;
case "from100000until150000":
$grossPriceFrom = 10000;
$grossPriceTo = 15000;
$netPriceFrom = $grossPriceFrom / 1.2;
$netPriceTo = $grossPriceTo / 1.2;
$entries->addConditionParam("price > ?", $netPriceFrom, "AND");
$entries->addConditionParam("price < ?", $netPriceTo, "AND");
break;
case "from15000until20000":
$grossPriceFrom = 15000;
$grossPriceTo = 20000;
$netPriceFrom = $grossPriceFrom / 1.2;
$netPriceTo = $grossPriceTo / 1.2;
$entries->addConditionParam("price > ?", $netPriceFrom, "AND");
$entries->addConditionParam("price < ?", $netPriceTo, "AND");
break;
case "from20000":
$grossPriceFrom = 20000;
$netPriceFrom = $grossPriceFrom / 1.2;
$entries->addConditionParam("price > ?", $netPriceFrom, "AND");
break;
}
$filters["price"] = $price;
}
$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, "debug" => $debug]);
}
/**
* @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();
}
}
}
}