<?php
namespace StockBundle\Controller;
use Pimcore\Controller\FrontendController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Annotation\Route;
use \Pimcore\Model\DataObject;
use \Pimcore\Model\Asset;
use StockBundle\Tools\Common\MonkeyFeeds;
class FeedsController extends FrontendController
{
/**
* @Route("/feeds/hotline.xml", defaults={"format"="_xml"}, name="feed_hotline")
*/
public function hotlineAction(Request $request)
{
$date = date("Y-m-d H:i");
$items = [];
$categories = MonkeyFeeds::getHotlineCategoriesUa();
$products = MonkeyFeeds::getHotlineProducts();
foreach ($products as $key => $product) {
// $pim_id = $product['pim_id']; // old value, migrate to product key
$qty = (int)$product['qty_misha'] + (int)$product['qty_suppliers'];
$price = $product['sale_price'];
// Убираем все товары, которые не в наличии
if ($qty == 0) { continue;}
$product = DataObject::getById($product['pim_id']);
if ( is_null($product) || $product->getOpencartId() == 0 || empty($product->getCategory()) ) {
continue;
}
$class = $product->getClassName();
$object = new \stdClass();
$object->id = $product->getkey();
$object->categoryId = $product->getCategory()->geto_id();
$object->code = $product->getModel();
$object->vendor = $product->getManufacturer()->getname();
$object->name = htmlspecialchars($product->getproductName("uk"));
$object->url = "https://monkeymusic.ua/ua/".$product->getkey();
$object->image = FALSE;
if($product->getphotomain()) {
$tmp = $product->getphotomain();
$object->image ="http://pim.monkeymusic.ua".$tmp->getpath().$tmp->getfilename();
}
$object->priceRUAH = $price;
$object->stock = "В наявності";
$object->guarantee = [];
$object->params = [
['name' => "Оригінальність", 'value' => "Оригінал"]
];
MonkeyFeeds::allParamsUa($product, $object);
if ($class == "Microphones") {
$object->guarantee = [
'type' => "manufacturer",
'value' => "12",
];
}
$items[] = $object;
// skip for debug
//if ($key >= 10) {break;}
}
$response = $this->render('StockBundle:Feeds:hotline.html.twig', [
'date' => $date,
'products' => $items,
'categories' => $categories,
]);
$response->setPublic();
$response->headers->set('Content-Type', 'text/xml');
return $response;
}
/**
* @Route("/feeds/hotline_sales.xml", defaults={"format"="_xml"}, name="feed_hotline_sales")
*/
public function hotlineSalesAction(Request $request)
{
$now = strtotime("now");
$date_start = date("Y-m-d");
$date_end = date("Y-m-d", strtotime("+1 month", $now));
$sales = [];
$products = MonkeyFeeds::getHotlineSalesProducts();
foreach ($products as $key => $product) {
$qty = (int)$product['qty'];
$price = $product['sale_price'];
$discount_sum = $product['discount_sum'];
// Убираем все товары, которые не в наличии
if ($qty == 0) { continue;}
$product = DataObject::getById($product['pim_id']);
if ( is_null($product) || $product->getOpencartId() == 0 || empty($product->getCategory()) ) {
continue;
}
$class = $product->getClassName();
$object = new \stdClass();
$object->id = $product->getkey();
$object->url = "https://monkeymusic.ua/ua/".$product->getkey();
$object->discount_sum = $discount_sum;
$sales[] = $object;
}
$response = $this->render('StockBundle:Feeds:hotlinesales.html.twig', [
'date_start' => $date_start,
'date_end' => $date_end,
'sales' => $sales,
]);
$response->setPublic();
$response->headers->set('Content-Type', 'text/xml');
return $response;
}
/**
* @Route("/feeds/allo.xml", defaults={"format"="_xml"}, name="feed_allo")
*/
public function alloAction(Request $request)
{
$date = date("Y-m-d H:i");
$priceCorrector = 1.16; // Если увеличить цену, ставим больше 0.
$items = [];
$categories = MonkeyFeeds::getAlloCategories();
$products = MonkeyFeeds::getAlloProducts();
foreach ($products as $key => $product) {
$pim_id = $product['pim_id'];
$qty = (int)$product['qty_misha'] + (int)$product['qty_suppliers'];
$price = round($product['sale_price'] * $priceCorrector, 0);
// Убираем все товары, которые не в наличии
if ($qty == 0) {
continue;
}
$product = DataObject::getById($pim_id);
if ( is_null($product) || $product->getOpencartId() == 0 || empty($product->getCategory()) ) {
continue;
}
$class = $product->getClassName();
$object = new \stdClass();
$object->id = $product->getproductFeedId();
$object->categoryId = $product->getCategory()->geto_id();
$object->code = $product->getModel();
$object->vendor = $product->getManufacturer()->getname();
$object->name = htmlspecialchars($product->getproductName("uk"));
$object->url = "https://monkeymusic.ua/ua/".$product->getkey();
$object->description = $product->getproductFeedDescription("uk");
$object->image = FALSE;
if($product->getphotomain()) {
$tmp = $product->getphotomain();
$object->image ="http://pim.monkeymusic.ua".$tmp->getpath().$tmp->getfilename();
}
$object->image2 = FALSE;
if($product->getdop1()){
$tmp = $product->getdop1();
$object->image2 = "https://pim.monkeymusic.ua".$tmp->getpath().$tmp->getfilename();
}
$object->image3 = FALSE;
if($product->getdop2()){
$tmp = $product->getdop2();
$object->image3 = "https://pim.monkeymusic.ua".$tmp->getpath().$tmp->getfilename();
}
$object->image4 = FALSE;
if($product->getdop3()){
$tmp = $product->getdop3();
$object->image4 = "https://pim.monkeymusic.ua".$tmp->getpath().$tmp->getfilename();
}
$object->priceRUAH = $price;
$object->stock = "В наявності";
$object->guarantee = [];
$object->params = [
['name' => "Оригінальність", 'value' => "Оригінал"]
];
if ($class == "Microphones") {
$object->guarantee = [
'type' => "manufacturer",
'value' => "12",
];
}
MonkeyFeeds::allParamsUa($product, $object);
$items[] = $object;
// skip for debug
//if ($key >= 10) {break;}
}
$response = $this->render('StockBundle:Feeds:allo.html.twig', [
'date' => $date,
'products' => $items,
'categories' => $categories,
]);
$response->setPublic();
$response->headers->set('Content-Type', 'text/xml');
return $response;
}
/**
* @Route("/feeds/rozetka.xml", defaults={"format"="_xml"}, name="feed_rozetka")
*/
public function rozetkaAction(Request $request)
{
$db = \Pimcore\Db::get();
$date = date("Y-m-d H:i");
$priceCorrector = 1.16;
$items = [];
$categories = MonkeyFeeds::getRozetkaCategories();
$excluded_categories = MonkeyFeeds::getExcludedCategoryIds();
$excluded_manufacturers = MonkeyFeeds::getExcludedManufacturerIds();
$products = MonkeyFeeds::getRozetkaProducts();
$price_exceptions = MonkeyFeeds::getRozetkaOdooPriceExceptions();
foreach ($products as $key => $item) {
$item = (object)$item;
$pim_id = $item->pim_id;
$product = DataObject::getById($pim_id);
if ( is_null($product) || $product->getOpencartId() == 0 || empty($product->getCategory()) ) {
continue;
}
$categoryId = $product->getCategory()->geto_id();
$class = $product->getClassName();
if ($class == 'GeneralProduct') {
continue;
}
if (in_array($categoryId, $excluded_categories)) {
continue;
}
if (in_array($product->getManufacturer()->getId(), $excluded_manufacturers)) {
continue;
}
// if ($item->pim_id != 9045) {
// continue;
// }
$qty = (int)$item->qty_misha + (int)$item->qty_suppliers;
$price = $item->sale_price;
$available = $qty > 0 ? 'true' : 'false';
$tags = $item->tags;
if ($tags) {
if (strpos($tags, 'Attrade')) {
continue;
}
}
$is_sale = FALSE;
if ($item->discount_price > 0 && $item->discount_price != $item->sale_price) {
$is_sale = TRUE;
$price = $item->discount_price;
$old_price = ceil($item->sale_price * $priceCorrector);
}
$price = ceil($price * $priceCorrector);
if (array_key_exists($pim_id, $price_exceptions)) {
$is_sale = FALSE;
$price = $price_exceptions[$pim_id]->price;
}
$product_description_ru = $product->getproductFeedDescription("ru");
$product_description_ua = $product->getproductFeedDescription("uk");
$object = new \stdClass();
$object->id = $product->getproductFeedId();
$object->available = $available;
$object->name = htmlspecialchars($product->getproductName("ru"));
$object->name_ua = htmlspecialchars($product->getproductName("uk"));
$object->price = $price;
$object->price_old = FALSE;
if ($is_sale) {
$object->price_old = $old_price;
}
// Динамические микрофоны привязываем к обычным микрофонам
if ($categoryId == 6290) {
$categoryId = 176;
}
$object->categoryId = $categoryId;
$object->stock_quantity = $qty;
$vendor = $product->getManufacturer()->getname();
if ($vendor == 'Thomastik-Infeld') {
$vendor = 'Thomastik';
}
$object->vendor = $vendor;
$object->url = "https://monkeymusic.ua/".$product->getkey();
$object->product_description_ru = !empty($product_description_ru) ? $product_description_ru : FALSE;
$object->product_description_ua = !empty($product_description_ua) ? $product_description_ua : FALSE;
$object->images = MonkeyFeeds::getFotoForFeed($product);
$object->series = FALSE;
if (property_exists($product, 'Series')) {
$object->series = $product->getSeries();
}
$object->params = [];
MonkeyFeeds::allParams($product, $object);
$items[] = $object;
// skip for debug
//if ($key >= 15) {break;}
}
$response = $this->render('StockBundle:Feeds:rozetka.html.twig', [
'date' => $date,
'products' => $items,
'categories' => $categories,
]);
$response->setPublic();
$response->headers->set('Content-Type', 'text/xml');
return $response;
}
/**
* @Route("/feeds/hubber.xml", defaults={"format"="_xml"}, name="feed_hubber")
*/
public function hubberAction(Request $request)
{
$db = \Pimcore\Db::get();
$date = date("Y-m-d H:i");
$priceCorrector = 1.16;
$items = [];
$categories = MonkeyFeeds::getRozetkaCategories();
$products = MonkeyFeeds::getRozetkaProducts();
foreach ($products as $key => $item) {
$item = (object)$item;
$qty = (int)$item->qty_misha + (int)$item->qty_suppliers;
$price = $item->sale_price;
$pim_id = $item->pim_id;
$available = $qty > 0 ? 'true' : 'false';
$is_sale = FALSE;
if ($item->discount_price > 0 && $item->discount_price != $item->sale_price) {
$is_sale = TRUE;
$price = $item->discount_price;
$old_price = ceil($old_price * $priceCorrector);
}
$price = ceil($price * $priceCorrector);
$product = DataObject::getById($pim_id);
if ( is_null($product) || $product->getOpencartId() == 0 || empty($product->getCategory()) ) {
continue;
}
$class = $product->getClassName();
if ($class == 'GeneralProduct') {
continue;
}
$product_description_ru = $product->getproductMainDescription("ru");
$product_description_ua = $product->getproductMainDescription("uk");
$object = new \stdClass();
$object->id = $product->getproductFeedId();
$object->available = $available;
$object->name = htmlspecialchars($product->getproductName("ru"));
$object->name_ua = htmlspecialchars($product->getproductName("uk"));
$object->price = $price;
$object->price_old = FALSE;
if ($is_sale) {
$object->price_old = $old_price;
}
$object->categoryId = $product->getCategory()->geto_id();
$object->stock_quantity = $qty;
$object->vendor = $product->getManufacturer()->getname();
$object->url = "https://monkeymusic.ua/".$product->getkey();
$object->product_description_ru = !empty($product_description_ru) ? $product_description_ru : FALSE;
$object->product_description_ua = !empty($product_description_ua) ? $product_description_ua : FALSE;
$object->images = MonkeyFeeds::getFotoForFeed($product);
$object->params = [];
MonkeyFeeds::allParams($product, $object);
$items[] = $object;
// skip for debug
//if ($key >= 15) {break;}
}
$response = $this->render('StockBundle:Feeds:hubber.html.twig', [
'date' => $date,
'products' => $items,
'categories' => $categories,
]);
$response->setPublic();
$response->headers->set('Content-Type', 'text/xml');
return $response;
}
/**
* @Route("/feeds/prom.xml", defaults={"format"="_xml"}, name="feed_prom")
*/
public function promAction(Request $request)
{
$date = date("Y-m-d H:i");
$priceCorrector = 1; // Если увеличить цену, ставим больше 0.
$items = [];
$categories = MonkeyFeeds::getPromCategories();
$products = MonkeyFeeds::getPromProducts();
foreach ($products as $key => $item) {
$item = (object)$item;
$qty = (int)$item->qty_misha + (int)$item->qty_suppliers;
$price = $item->sale_price;
$pim_id = $item->pim_id;
$available = $qty > 0 ? 'true' : 'false';
$product = DataObject::getById($pim_id);
if ( is_null($product) || $product->getOpencartId() == 0 || empty($product->getCategory()) ) {
continue;
}
$class = $product->getClassName();
if (!in_array($class, ["Cases"])) {
$priceCorrector = 1.08;
}
$is_sale = FALSE;
if ($item->discount_price > 0 && $item->discount_price != $item->sale_price) {
$is_sale = TRUE;
$price = $item->discount_price;
$old_price = ceil($old_price * $priceCorrector);
}
$price = ceil($price * $priceCorrector);
$object = new \stdClass();
$object->id = $product->getproductFeedId();
$object->available = $available;
$object->name = htmlspecialchars($product->getproductName("ru"));
$object->name_ua = htmlspecialchars($product->getproductName("uk"));
$object->price = $price;
$object->price_old = FALSE;
if ($is_sale) {
$object->price_old = $old_price;
}
$product_description = $product->getproductFeedDescription("ru");
$product_description_ua = $product->getproductFeedDescription("uk");
$object->categoryId = $product->getCategory()->geto_id();
$object->stock_quantity = $qty;
$object->vendor = $product->getManufacturer()->getname();
$object->vendorCode = htmlspecialchars(substr($product->getmodel(), 0, 24));
$object->country = $product->getManufacturer_country();
$object->keywords_ru = $product->getKeywords("ru");
$object->keywords_ua = $product->getKeywords("uk");
$object->description = !empty($product_description) ? $product_description : FALSE;
$object->description_ua = !empty($product_description_ua) ? $product_description_ua : FALSE;
$object->images = MonkeyFeeds::getFotoForFeed($product);
$object->params = [];
MonkeyFeeds::allParams($product, $object);
$items[] = $object;
// skip for debug
//if ($key >= 15) {break;}
}
$response = $this->render('StockBundle:Feeds:prom.html.twig', [
'date' => $date,
'products' => $items,
'categories' => $categories,
]);
$response->setPublic();
$response->headers->set('Content-Type', 'text/xml');
return $response;
}
/**
* @Route("/feeds/fua.xml", defaults={"format"="_xml"}, name="feed_fua")
*/
public function fuaAction(Request $request)
{
$db = \Pimcore\Db::get();
$date = date("Y-m-d H:i");
$priceCorrector = 1.16;
$items = [];
$categories = MonkeyFeeds::getRozetkaCategories();
$products = MonkeyFeeds::getFuaProducts();
foreach ($products as $key => $item) {
$item = (object)$item;
$qty = (int)$item->qty_misha + (int)$item->qty_suppliers;
$price = $item->sale_price;
$pim_id = $item->pim_id;
$available = $qty > 0 ? 'true' : 'false';
$is_sale = FALSE;
if ($item->discount_price > 0 && $item->discount_price != $item->sale_price) {
$is_sale = TRUE;
$price = $item->discount_price;
$old_price = ceil($old_price * $priceCorrector);
}
$price = ceil($price * $priceCorrector);
$product = DataObject::getById($pim_id);
if ( is_null($product) || $product->getOpencartId() == 0 || empty($product->getCategory()) ) {
continue;
}
$class = $product->getClassName();
$product_description = strip_tags($product->getproductFeedDescription("ru"), "<p><ul><li>");
$object = new \stdClass();
$object->id = $product->getkey();
$object->available = $available;
$object->name = htmlspecialchars($product->getproductName("ru"));
$object->price = $price;
$object->price_old = FALSE;
if ($is_sale) {
$object->price_old = $old_price;
}
$object->categoryId = $product->getCategory()->geto_id();
$object->stock_quantity = $qty;
$object->vendor = $product->getManufacturer()->getname();
$object->url = "https://monkeymusic.ua/".$product->getkey();
$object->description = $product_description;
$object->images = MonkeyFeeds::getFotoForFeed($product);
$object->params = [];
MonkeyFeeds::allParams($product, $object);
$items[] = $object;
// skip for debug
//if ($key >= 15) {break;}
}
$response = $this->render('StockBundle:Feeds:fua.html.twig', [
'date' => $date,
'products' => $items,
'categories' => $categories,
]);
$response->setPublic();
$response->headers->set('Content-Type', 'text/xml');
return $response;
}
/**
* @Route("/feeds/epicentr.xml", defaults={"format"="_xml"}, name="feed_epicentr")
*/
public function epicentrAction(Request $request)
{
$db = \Pimcore\Db::get();
$date = date("Y-m-d H:i");
$priceCorrector = 1.16;
$items = [];
$products = MonkeyFeeds::getEpicentrProducts();
foreach ($products as $key => $item) {
$item = (object)$item;
$qty = (int)$item->qty_misha + (int)$item->qty_suppliers;
$price = $item->sale_price;
$pim_id = $item->pim_id;
$available = $qty > 0 ? 'true' : 'false';
$is_sale = FALSE;
if ($item->discount_price > 0 && $item->discount_price != $item->sale_price) {
$is_sale = TRUE;
$price = $item->discount_price;
$old_price = ceil($old_price * $priceCorrector);
}
$price = ceil($price * $priceCorrector);
$product = DataObject::getById($pim_id);
if ( is_null($product) || empty($product->getCategory()) ) {
continue;
}
$product_description_ru = $product->getproductFeedDescription("ru");
$product_description_ua = $product->getproductFeedDescription("uk");
$object = new \stdClass();
$object->id = $product->getproductFeedId();
$object->available = $available;
$object->name_ru = htmlspecialchars($product->getproductName("ru"));
$object->name_ua = htmlspecialchars($product->getproductName("uk"));
$object->price = $price;
$object->price_old = FALSE;
if ($is_sale) {
$object->price_old = $old_price;
}
$object->category = $product->getCategory()->getepicentrName() ? $product->getCategory()->getepicentrName() : FALSE;
$object->vendor = $product->getManufacturer()->getname();
$object->country_of_origin = $product->getManufacturer_country() ? $product->getManufacturer_country() : FALSE;
$object->description_ru = !empty($product_description_ru) ? strip_tags($product_description_ru) : FALSE;
$object->description_ua = !empty($product_description_ua) ? strip_tags($product_description_ua) : FALSE;
$object->barcode = !empty($product->getEAN()) ? $product->getEAN() : FALSE;
$object->images = MonkeyFeeds::getFotoForFeed($product);
$items[] = $object;
// skip for debug
//if ($key >= 15) {break;}
}
$response = $this->render('StockBundle:Feeds:epicentr.html.twig', [
'date' => $date,
'products' => $items,
]);
$response->setPublic();
$response->headers->set('Content-Type', 'text/xml');
return $response;
}
}