src/StockBundle/Controller/FeedsController.php line 14

Open in your IDE?
  1. <?php
  2. namespace StockBundle\Controller;
  3. use Pimcore\Controller\FrontendController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\HttpFoundation\RedirectResponse;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use \Pimcore\Model\DataObject;
  9. use \Pimcore\Model\Asset;
  10. use StockBundle\Tools\Common\MonkeyFeeds;
  11. class FeedsController extends FrontendController
  12. {
  13.     /**
  14.      * @Route("/feeds/hotline.xml", defaults={"format"="_xml"}, name="feed_hotline")
  15.      */
  16.     public function hotlineAction(Request $request)
  17.     {
  18.         $date date("Y-m-d H:i");
  19.         $items = [];
  20.         $categories MonkeyFeeds::getHotlineCategoriesUa();
  21.         $products MonkeyFeeds::getHotlineProducts();
  22.         foreach ($products as $key => $product) {
  23.             // $pim_id = $product['pim_id']; // old value, migrate to product key
  24.             $qty = (int)$product['qty_misha'] + (int)$product['qty_suppliers'];
  25.             $price $product['sale_price'];
  26.             // Убираем все товары, которые не в наличии
  27.             if ($qty == 0) { continue;}
  28.             $product DataObject::getById($product['pim_id']);
  29.             if ( is_null($product) || $product->getOpencartId() == || empty($product->getCategory()) ) { 
  30.                 continue;
  31.             }
  32.             $class $product->getClassName();
  33.             
  34.             $object = new \stdClass();
  35.             $object->id $product->getkey();
  36.             $object->categoryId $product->getCategory()->geto_id();
  37.             $object->code $product->getModel();
  38.             $object->vendor $product->getManufacturer()->getname();
  39.             $object->name htmlspecialchars($product->getproductName("uk"));
  40.             $object->url "https://monkeymusic.ua/ua/".$product->getkey();
  41.             $object->image FALSE;
  42.             if($product->getphotomain()) {
  43.                 $tmp $product->getphotomain();
  44.                 $object->image ="http://pim.monkeymusic.ua".$tmp->getpath().$tmp->getfilename();
  45.             }
  46.             $object->priceRUAH $price;
  47.             $object->stock "В наявності";
  48.             $object->guarantee = [];
  49.             $object->params = [
  50.                 ['name' => "Оригінальність"'value' => "Оригінал"]
  51.             ];
  52.             MonkeyFeeds::allParamsUa($product$object);
  53.             
  54.             if ($class == "Microphones") {
  55.                 $object->guarantee = [
  56.                     'type' => "manufacturer",
  57.                     'value' => "12",
  58.                 ];
  59.             }
  60.             $items[] = $object;
  61.             // skip for debug
  62.             //if ($key >= 10) {break;}
  63.         }
  64.         $response $this->render('StockBundle:Feeds:hotline.html.twig', [
  65.             'date' => $date,
  66.             'products' => $items,
  67.             'categories' => $categories,
  68.         ]);
  69.         
  70.         $response->setPublic();
  71.         $response->headers->set('Content-Type''text/xml');
  72.         return $response;
  73.     }
  74.     /**
  75.      * @Route("/feeds/hotline_sales.xml", defaults={"format"="_xml"}, name="feed_hotline_sales")
  76.      */
  77.     public function hotlineSalesAction(Request $request)
  78.     {   
  79.         $now strtotime("now");
  80.         $date_start date("Y-m-d");
  81.         $date_end date("Y-m-d"strtotime("+1 month"$now));
  82.         
  83.         $sales = [];
  84.         $products MonkeyFeeds::getHotlineSalesProducts();
  85.         foreach ($products as $key => $product) {
  86.             $qty = (int)$product['qty'];
  87.             $price $product['sale_price'];
  88.             $discount_sum $product['discount_sum'];
  89.             // Убираем все товары, которые не в наличии
  90.             if ($qty == 0) { continue;}
  91.             $product DataObject::getById($product['pim_id']);
  92.             if ( is_null($product) || $product->getOpencartId() == || empty($product->getCategory()) ) { 
  93.                 continue;
  94.             }
  95.             $class $product->getClassName();
  96.             $object = new \stdClass();
  97.             $object->id $product->getkey();
  98.             $object->url "https://monkeymusic.ua/ua/".$product->getkey();
  99.             $object->discount_sum $discount_sum;
  100.             $sales[] = $object;
  101.         }
  102.         $response $this->render('StockBundle:Feeds:hotlinesales.html.twig', [
  103.             'date_start' => $date_start,
  104.             'date_end' => $date_end,
  105.             'sales' => $sales,
  106.         ]);
  107.         $response->setPublic();
  108.         $response->headers->set('Content-Type''text/xml');
  109.         return $response;
  110.     }
  111.     /**
  112.      * @Route("/feeds/allo.xml", defaults={"format"="_xml"}, name="feed_allo")
  113.      */
  114.     public function alloAction(Request $request)
  115.     {
  116.         $date date("Y-m-d H:i");
  117.         $priceCorrector 1.16// Если увеличить цену, ставим больше 0.
  118.         $items = [];
  119.         $categories MonkeyFeeds::getAlloCategories();
  120.         $products MonkeyFeeds::getAlloProducts();
  121.         foreach ($products as $key => $product) {
  122.             $pim_id $product['pim_id'];
  123.             $qty = (int)$product['qty_misha'] + (int)$product['qty_suppliers'];
  124.             $price round($product['sale_price'] * $priceCorrector0);
  125.             // Убираем все товары, которые не в наличии
  126.             if ($qty == 0) {
  127.                 continue;
  128.             }
  129.             $product DataObject::getById($pim_id);
  130.             if ( is_null($product) || $product->getOpencartId() == || empty($product->getCategory()) ) { 
  131.                 continue;
  132.             }
  133.             $class $product->getClassName();
  134.             
  135.             $object = new \stdClass();
  136.             $object->id $product->getproductFeedId();
  137.             $object->categoryId $product->getCategory()->geto_id();
  138.             $object->code $product->getModel();
  139.             $object->vendor $product->getManufacturer()->getname();
  140.             $object->name htmlspecialchars($product->getproductName("uk"));
  141.             $object->url "https://monkeymusic.ua/ua/".$product->getkey();
  142.             $object->description $product->getproductFeedDescription("uk");
  143.             $object->image FALSE;
  144.             if($product->getphotomain()) {
  145.                 $tmp $product->getphotomain();
  146.                 $object->image ="http://pim.monkeymusic.ua".$tmp->getpath().$tmp->getfilename();
  147.             }
  148.             $object->image2 FALSE;
  149.             if($product->getdop1()){
  150.                 $tmp $product->getdop1();
  151.                 $object->image2 "https://pim.monkeymusic.ua".$tmp->getpath().$tmp->getfilename();
  152.             }
  153.                     
  154.             $object->image3 FALSE;
  155.             if($product->getdop2()){
  156.                 $tmp $product->getdop2();
  157.                 $object->image3 "https://pim.monkeymusic.ua".$tmp->getpath().$tmp->getfilename();
  158.             }
  159.                     
  160.             $object->image4 FALSE;
  161.             if($product->getdop3()){
  162.                 $tmp $product->getdop3();
  163.                 $object->image4 "https://pim.monkeymusic.ua".$tmp->getpath().$tmp->getfilename();
  164.             }
  165.             $object->priceRUAH $price;
  166.             $object->stock "В наявності";
  167.             $object->guarantee = [];
  168.             $object->params = [
  169.                 ['name' => "Оригінальність"'value' => "Оригінал"]
  170.             ];
  171.             if ($class == "Microphones") {
  172.                 $object->guarantee = [
  173.                     'type' => "manufacturer",
  174.                     'value' => "12",
  175.                 ];
  176.             }
  177.             MonkeyFeeds::allParamsUa($product$object);
  178.             $items[] = $object;
  179.             // skip for debug
  180.             //if ($key >= 10) {break;}
  181.         }
  182.         $response $this->render('StockBundle:Feeds:allo.html.twig', [
  183.             'date' => $date,
  184.             'products' => $items,
  185.             'categories' => $categories,
  186.         ]);
  187.         $response->setPublic();
  188.         $response->headers->set('Content-Type''text/xml');
  189.         return $response;
  190.     }
  191.     /**
  192.      * @Route("/feeds/rozetka.xml", defaults={"format"="_xml"}, name="feed_rozetka")
  193.      */
  194.     public function rozetkaAction(Request $request)
  195.     {
  196.         $db = \Pimcore\Db::get();
  197.         $date date("Y-m-d H:i");
  198.         $priceCorrector 1.16;
  199.         $items = [];
  200.         $categories MonkeyFeeds::getRozetkaCategories();
  201.         $excluded_categories MonkeyFeeds::getExcludedCategoryIds();
  202.         $excluded_manufacturers MonkeyFeeds::getExcludedManufacturerIds();
  203.         $products MonkeyFeeds::getRozetkaProducts();
  204.         $price_exceptions MonkeyFeeds::getRozetkaOdooPriceExceptions();
  205.         foreach ($products as $key => $item) {
  206.             $item = (object)$item;
  207.             $pim_id $item->pim_id;
  208.             $product DataObject::getById($pim_id);
  209.             if ( is_null($product) || $product->getOpencartId() == || empty($product->getCategory()) ) { 
  210.                 continue;
  211.             }
  212.             $categoryId $product->getCategory()->geto_id();
  213.             $class $product->getClassName();
  214.             
  215.             if ($class == 'GeneralProduct') {
  216.                 continue;
  217.             }
  218.             if (in_array($categoryId$excluded_categories)) {
  219.                 continue;
  220.             }
  221.             if (in_array($product->getManufacturer()->getId(), $excluded_manufacturers)) {
  222.                 continue;
  223.             }
  224.             
  225.             // if ($item->pim_id != 9045) {
  226.             //     continue;
  227.             // }
  228.             $qty = (int)$item->qty_misha + (int)$item->qty_suppliers;
  229.             $price $item->sale_price;
  230.             $available $qty 'true' 'false';
  231.             $tags $item->tags;
  232.             if ($tags) {
  233.                 if (strpos($tags'Attrade')) {
  234.                     continue;
  235.                 }
  236.             }
  237.             
  238.             $is_sale FALSE;
  239.             if ($item->discount_price && $item->discount_price != $item->sale_price) {
  240.                 $is_sale TRUE;
  241.                 $price $item->discount_price;
  242.                 $old_price ceil($item->sale_price $priceCorrector);
  243.             }
  244.             $price ceil($price $priceCorrector);
  245.         
  246.             if (array_key_exists($pim_id$price_exceptions)) {
  247.                 $is_sale FALSE;
  248.                 $price $price_exceptions[$pim_id]->price;
  249.             }
  250.             $product_description_ru $product->getproductFeedDescription("ru");
  251.             $product_description_ua $product->getproductFeedDescription("uk");
  252.             $object = new \stdClass();
  253.             $object->id $product->getproductFeedId();
  254.             $object->available $available;
  255.             $object->name htmlspecialchars($product->getproductName("ru"));
  256.             $object->name_ua htmlspecialchars($product->getproductName("uk"));
  257.             $object->price $price;
  258.             $object->price_old FALSE;
  259.             if ($is_sale) {
  260.                 $object->price_old $old_price;
  261.             }
  262.             // Динамические микрофоны привязываем к обычным микрофонам
  263.             if ($categoryId == 6290) {
  264.                 $categoryId 176;
  265.             }
  266.             $object->categoryId $categoryId;
  267.             $object->stock_quantity $qty;
  268.             $vendor $product->getManufacturer()->getname();
  269.             if ($vendor == 'Thomastik-Infeld') {
  270.                 $vendor 'Thomastik';
  271.             }
  272.             $object->vendor $vendor;
  273.             $object->url "https://monkeymusic.ua/".$product->getkey();
  274.             $object->product_description_ru = !empty($product_description_ru) ? $product_description_ru FALSE;
  275.             $object->product_description_ua = !empty($product_description_ua) ? $product_description_ua FALSE;
  276.             $object->images MonkeyFeeds::getFotoForFeed($product);
  277.             $object->series FALSE;
  278.             if (property_exists($product'Series')) {
  279.                 $object->series $product->getSeries();
  280.             }
  281.             $object->params = [];
  282.             MonkeyFeeds::allParams($product$object);
  283.             $items[] = $object;
  284.             // skip for debug
  285.             //if ($key >= 15) {break;}
  286.         }
  287.         $response $this->render('StockBundle:Feeds:rozetka.html.twig', [
  288.             'date' => $date,
  289.             'products' => $items,
  290.             'categories' => $categories,
  291.         ]);
  292.         $response->setPublic();
  293.         $response->headers->set('Content-Type''text/xml');
  294.         return $response;
  295.     }
  296.     /**
  297.      * @Route("/feeds/hubber.xml", defaults={"format"="_xml"}, name="feed_hubber")
  298.      */
  299.     public function hubberAction(Request $request)
  300.     {
  301.         $db = \Pimcore\Db::get();
  302.         $date date("Y-m-d H:i");
  303.         $priceCorrector 1.16;
  304.         $items = [];
  305.         $categories MonkeyFeeds::getRozetkaCategories();
  306.         $products MonkeyFeeds::getRozetkaProducts();
  307.         foreach ($products as $key => $item) {
  308.             $item = (object)$item;
  309.         
  310.             $qty = (int)$item->qty_misha + (int)$item->qty_suppliers;
  311.             $price $item->sale_price;
  312.             $pim_id $item->pim_id;
  313.             $available $qty 'true' 'false';
  314.         
  315.             $is_sale FALSE;
  316.             if ($item->discount_price && $item->discount_price != $item->sale_price) {
  317.                 $is_sale TRUE;
  318.                 $price $item->discount_price;
  319.                 $old_price ceil($old_price $priceCorrector);
  320.             }
  321.             $price ceil($price $priceCorrector);
  322.         
  323.             $product DataObject::getById($pim_id);
  324.             if ( is_null($product) || $product->getOpencartId() == || empty($product->getCategory()) ) { 
  325.                 continue;
  326.             }
  327.             $class $product->getClassName();
  328.             if ($class == 'GeneralProduct') {
  329.                 continue;
  330.             }
  331.             $product_description_ru $product->getproductMainDescription("ru");
  332.             $product_description_ua $product->getproductMainDescription("uk");
  333.             $object = new \stdClass();
  334.             $object->id $product->getproductFeedId();
  335.             $object->available $available;
  336.             $object->name htmlspecialchars($product->getproductName("ru"));
  337.             $object->name_ua htmlspecialchars($product->getproductName("uk"));
  338.             $object->price $price;
  339.             $object->price_old FALSE;
  340.             if ($is_sale) {
  341.                 $object->price_old $old_price;
  342.             }
  343.             $object->categoryId $product->getCategory()->geto_id();
  344.             $object->stock_quantity $qty;
  345.             $object->vendor $product->getManufacturer()->getname();
  346.             $object->url "https://monkeymusic.ua/".$product->getkey();
  347.             $object->product_description_ru = !empty($product_description_ru) ? $product_description_ru FALSE;
  348.             $object->product_description_ua = !empty($product_description_ua) ? $product_description_ua FALSE;
  349.             $object->images MonkeyFeeds::getFotoForFeed($product);
  350.             $object->params = [];
  351.             MonkeyFeeds::allParams($product$object);
  352.             $items[] = $object;
  353.             // skip for debug
  354.             //if ($key >= 15) {break;}
  355.         }
  356.         $response $this->render('StockBundle:Feeds:hubber.html.twig', [
  357.             'date' => $date,
  358.             'products' => $items,
  359.             'categories' => $categories,
  360.         ]);
  361.         $response->setPublic();
  362.         $response->headers->set('Content-Type''text/xml');
  363.         return $response;
  364.     }
  365.     /**
  366.      * @Route("/feeds/prom.xml", defaults={"format"="_xml"}, name="feed_prom")
  367.      */
  368.     public function promAction(Request $request)
  369.     {
  370.         $date date("Y-m-d H:i");
  371.         $priceCorrector 1// Если увеличить цену, ставим больше 0.
  372.         $items = [];
  373.         $categories MonkeyFeeds::getPromCategories();
  374.         $products MonkeyFeeds::getPromProducts();
  375.         foreach ($products as $key => $item) {
  376.             $item = (object)$item;
  377.         
  378.             $qty = (int)$item->qty_misha + (int)$item->qty_suppliers;
  379.             $price $item->sale_price;
  380.             $pim_id $item->pim_id;
  381.             $available $qty 'true' 'false';
  382.             $product DataObject::getById($pim_id);
  383.             if ( is_null($product) || $product->getOpencartId() == || empty($product->getCategory()) ) { 
  384.                 continue;
  385.             }
  386.             $class $product->getClassName();
  387.             if (!in_array($class, ["Cases"])) {
  388.                 $priceCorrector 1.08;
  389.             }
  390.         
  391.             $is_sale FALSE;
  392.             if ($item->discount_price && $item->discount_price != $item->sale_price) {
  393.                 $is_sale TRUE;
  394.                 $price $item->discount_price;
  395.                 $old_price ceil($old_price $priceCorrector);
  396.             }
  397.             $price ceil($price $priceCorrector);
  398.             $object = new \stdClass();
  399.             $object->id $product->getproductFeedId();
  400.             $object->available $available;
  401.             $object->name htmlspecialchars($product->getproductName("ru"));
  402.             $object->name_ua htmlspecialchars($product->getproductName("uk"));
  403.             $object->price $price;
  404.             $object->price_old FALSE;
  405.             if ($is_sale) {
  406.                 $object->price_old $old_price;
  407.             }
  408.             $product_description $product->getproductFeedDescription("ru");
  409.             $product_description_ua $product->getproductFeedDescription("uk");
  410.             $object->categoryId $product->getCategory()->geto_id();
  411.             $object->stock_quantity $qty;
  412.             $object->vendor $product->getManufacturer()->getname();
  413.             $object->vendorCode htmlspecialchars(substr($product->getmodel(), 024));
  414.             $object->country $product->getManufacturer_country();
  415.             $object->keywords_ru $product->getKeywords("ru");
  416.             $object->keywords_ua $product->getKeywords("uk");
  417.             $object->description = !empty($product_description) ? $product_description FALSE;
  418.             $object->description_ua = !empty($product_description_ua) ? $product_description_ua FALSE;
  419.             $object->images MonkeyFeeds::getFotoForFeed($product);
  420.             $object->params = [];
  421.             MonkeyFeeds::allParams($product$object);
  422.             $items[] = $object;
  423.             // skip for debug
  424.             //if ($key >= 15) {break;}
  425.         }
  426.         $response $this->render('StockBundle:Feeds:prom.html.twig', [
  427.             'date' => $date,
  428.             'products' => $items,
  429.             'categories' => $categories,
  430.         ]);
  431.         $response->setPublic();
  432.         $response->headers->set('Content-Type''text/xml');
  433.         return $response;
  434.     }
  435.     /**
  436.      * @Route("/feeds/fua.xml", defaults={"format"="_xml"}, name="feed_fua")
  437.      */
  438.     public function fuaAction(Request $request)
  439.     {
  440.         $db = \Pimcore\Db::get();
  441.         $date date("Y-m-d H:i");
  442.         $priceCorrector 1.16;
  443.         $items = [];
  444.         $categories MonkeyFeeds::getRozetkaCategories();
  445.         $products MonkeyFeeds::getFuaProducts();
  446.         foreach ($products as $key => $item) {
  447.             $item = (object)$item;
  448.         
  449.             $qty = (int)$item->qty_misha + (int)$item->qty_suppliers;
  450.             $price $item->sale_price;
  451.             $pim_id $item->pim_id;
  452.             $available $qty 'true' 'false';
  453.         
  454.             $is_sale FALSE;
  455.             if ($item->discount_price && $item->discount_price != $item->sale_price) {
  456.                 $is_sale TRUE;
  457.                 $price $item->discount_price;
  458.                 $old_price ceil($old_price $priceCorrector);
  459.             }
  460.             $price ceil($price $priceCorrector);
  461.     
  462.         
  463.             $product DataObject::getById($pim_id);
  464.             if ( is_null($product) || $product->getOpencartId() == || empty($product->getCategory()) ) { 
  465.                 continue;
  466.             }
  467.             $class $product->getClassName();
  468.             $product_description strip_tags($product->getproductFeedDescription("ru"), "<p><ul><li>");
  469.             $object = new \stdClass();
  470.             $object->id $product->getkey();
  471.             $object->available $available;
  472.             $object->name htmlspecialchars($product->getproductName("ru"));
  473.             $object->price $price;
  474.             $object->price_old FALSE;
  475.             if ($is_sale) {
  476.                 $object->price_old $old_price;
  477.             }
  478.             $object->categoryId $product->getCategory()->geto_id();
  479.             $object->stock_quantity $qty;
  480.             $object->vendor $product->getManufacturer()->getname();
  481.             $object->url "https://monkeymusic.ua/".$product->getkey();
  482.             $object->description $product_description;
  483.             $object->images MonkeyFeeds::getFotoForFeed($product);
  484.             $object->params = [];
  485.             MonkeyFeeds::allParams($product$object);
  486.             $items[] = $object;
  487.             // skip for debug
  488.             //if ($key >= 15) {break;}
  489.         }
  490.         $response $this->render('StockBundle:Feeds:fua.html.twig', [
  491.             'date' => $date,
  492.             'products' => $items,
  493.             'categories' => $categories,
  494.         ]);
  495.         $response->setPublic();
  496.         $response->headers->set('Content-Type''text/xml');
  497.         return $response;
  498.     }
  499.     /**
  500.      * @Route("/feeds/epicentr.xml", defaults={"format"="_xml"}, name="feed_epicentr")
  501.      */
  502.     public function epicentrAction(Request $request)
  503.     {
  504.         $db = \Pimcore\Db::get();
  505.         $date date("Y-m-d H:i");
  506.         $priceCorrector 1.16;
  507.         $items = [];
  508.         $products MonkeyFeeds::getEpicentrProducts();
  509.         foreach ($products as $key => $item) {
  510.             $item = (object)$item;
  511.             $qty = (int)$item->qty_misha + (int)$item->qty_suppliers;
  512.             $price $item->sale_price;
  513.             $pim_id $item->pim_id;
  514.             $available $qty 'true' 'false';
  515.         
  516.             $is_sale FALSE;
  517.             if ($item->discount_price && $item->discount_price != $item->sale_price) {
  518.                 $is_sale TRUE;
  519.                 $price $item->discount_price;
  520.                 $old_price ceil($old_price $priceCorrector);
  521.             }
  522.             $price ceil($price $priceCorrector);
  523.         
  524.             $product DataObject::getById($pim_id);
  525.             if ( is_null($product) || empty($product->getCategory()) ) { 
  526.                 continue;
  527.             }
  528.             $product_description_ru $product->getproductFeedDescription("ru");
  529.             $product_description_ua $product->getproductFeedDescription("uk");
  530.             $object = new \stdClass();
  531.             $object->id $product->getproductFeedId();
  532.             $object->available $available;
  533.             $object->name_ru htmlspecialchars($product->getproductName("ru"));
  534.             $object->name_ua htmlspecialchars($product->getproductName("uk"));
  535.             $object->price $price;
  536.             $object->price_old FALSE;
  537.             if ($is_sale) {
  538.                 $object->price_old $old_price;
  539.             }
  540.             $object->category $product->getCategory()->getepicentrName() ? $product->getCategory()->getepicentrName() : FALSE;
  541.             $object->vendor $product->getManufacturer()->getname();
  542.             $object->country_of_origin $product->getManufacturer_country() ? $product->getManufacturer_country() : FALSE;
  543.             $object->description_ru = !empty($product_description_ru) ? strip_tags($product_description_ru) : FALSE;
  544.             $object->description_ua = !empty($product_description_ua) ? strip_tags($product_description_ua) : FALSE;
  545.             $object->barcode = !empty($product->getEAN()) ? $product->getEAN() : FALSE;
  546.             $object->images MonkeyFeeds::getFotoForFeed($product);
  547.             $items[] = $object;
  548.             // skip for debug
  549.             //if ($key >= 15) {break;}
  550.         }
  551.         $response $this->render('StockBundle:Feeds:epicentr.html.twig', [
  552.             'date' => $date,
  553.             'products' => $items,
  554.         ]);
  555.         $response->setPublic();
  556.         $response->headers->set('Content-Type''text/xml');
  557.         return $response;
  558.     }
  559. }