src/Controller/ProductController.php line 217

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Enterprise License (PEL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12.  *  @license    http://www.pimcore.org/license     GPLv3 and PEL
  13.  */
  14. namespace App\Controller;
  15. use App\Model\Product\AbstractProduct;
  16. use App\Model\Product\AccessoryPart;
  17. use App\Model\Product\Car;
  18. use App\Model\Product\Category;
  19. use App\Services\CurlService;
  20. use Pimcore\Model\DataObject\Manufacturer;
  21. use App\Services\SegmentTrackingHelperService;
  22. use App\Website\LinkGenerator\ProductLinkGenerator;
  23. use App\Website\Navigation\BreadcrumbHelperService;
  24. use Knp\Component\Pager\Pagination\SlidingPagination;
  25. use Knp\Component\Pager\PaginatorInterface;
  26. use Pimcore\Bundle\EcommerceFrameworkBundle\Factory;
  27. use Pimcore\Bundle\EcommerceFrameworkBundle\FilterService\ListHelper;
  28. use Pimcore\Bundle\EcommerceFrameworkBundle\IndexService\ProductList\DefaultMysql;
  29. use Pimcore\Bundle\EcommerceFrameworkBundle\IndexService\ProductList\ElasticSearch\AbstractElasticSearch;
  30. use Pimcore\Bundle\EcommerceFrameworkBundle\IndexService\ProductList\ProductListInterface;
  31. use Pimcore\Config;
  32. use Pimcore\Model\DataObject\AbstractObject;
  33. use Pimcore\Model\DataObject\Concrete;
  34. use Pimcore\Model\DataObject\Data\UrlSlug;
  35. use Pimcore\Model\DataObject\FilterDefinition;
  36. use Pimcore\Translation\Translator;
  37. use Pimcore\Twig\Extension\Templating\HeadTitle;
  38. use Pimcore\Twig\Extension\Templating\Placeholder;
  39. use Symfony\Component\HttpFoundation\JsonResponse;
  40. use Symfony\Component\HttpFoundation\Request;
  41. use Symfony\Component\HttpFoundation\Response;
  42. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  43. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  44. use Symfony\Component\Routing\Annotation\Route;
  45. use Symfony\Component\Security\Core\User\UserInterface;
  46. use Pimcore\Model\DataObject;
  47. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  48. use Pimcore\Db;
  49. use App\Model\Order;
  50. use App\Lib\Utility;
  51. class ProductController extends BaseController
  52. {
  53.     /**
  54.      * @param Request $request
  55.      * @param AbstractObject $object
  56.      * @param UrlSlug $urlSlug
  57.      * @return Response
  58.      */
  59.     public function productDetailSlugAction(Request $requestAbstractObject $objectUrlSlug $urlSlug) {
  60.         return $this->forward('App\Controller\ProductController::detailAction', ['product' => $object]);
  61.     }
  62.     /**
  63.      * @Route("/shop/{path}{productname}~p{product}", name="shop-detail", defaults={"path"=""}, requirements={"path"=".*?", "productname"="[\w-]+", "product"="\d+"})
  64.      * @Security("is_granted('ROLE_USER')")
  65.      * @param Request $request
  66.      * @param HeadTitle $headTitleHelper
  67.      * @param BreadcrumbHelperService $breadcrumbHelperService
  68.      * @param Factory $ecommerceFactory
  69.      * @param SegmentTrackingHelperService $segmentTrackingHelperService
  70.      * @param Concrete $product built-in parameter conversion, please see https://github.com/pimcore/pimcore/pull/5554
  71.      * @param ProductLinkGenerator $productLinkGenerator
  72.      *
  73.      * @return Response
  74.      *
  75.      * @throws \Exception
  76.      */
  77.     public function detailAction(
  78.         Request $request,
  79.         HeadTitle $headTitleHelper,
  80.         BreadcrumbHelperService $breadcrumbHelperService,
  81.         Factory $ecommerceFactory,
  82.         SegmentTrackingHelperService $segmentTrackingHelperService,
  83.         Concrete $product,
  84.         ProductLinkGenerator $productLinkGenerator,
  85.         UserInterface $user,
  86.         SessionInterface $session,
  87.         PaginatorInterface $paginator
  88.     )
  89.     {
  90.         if (!(
  91.                 $product && $product->isPublished()
  92.             )
  93.         ) {
  94.             throw new NotFoundHttpException('Product not found.');
  95.         }
  96.         $file null;
  97.         $fileExists false;
  98.         /*$file = BASE_URL.'/document/'.$product->getItem().'.pdf';
  99.        // p_r($file);
  100.         if(Utility::check_file_exist($file))
  101.         {
  102.            $fileExists = true;
  103.            $file = BASE_URL.'/document/'.$product->getItem().'.pdf';
  104.         }else{
  105.             $file = null;
  106.         }*/
  107.         if($file $product->getProductPdf()){
  108.             $fileExists true;
  109.             $file $product->getProductPdf();
  110.         }
  111.         //redirect to main url
  112.         $generatorUrl $productLinkGenerator->generate($product);
  113.         if($generatorUrl != $request->getPathInfo()) {
  114.             $queryString $request->getQueryString();
  115.             return $this->redirect($generatorUrl . ($queryString '?' $queryString ''));
  116.         }
  117.         $breadcrumbHelperService->enrichProductDetailPage($product);
  118.         $headTitleHelper($product->getOSName());
  119.         $paramBag $this->getAllParameters($request);
  120.         $paramBag['product'] = $product;
  121.         $paramBag['category'] = $product->getMainCategory();
  122.         $paramBag['brand'] = $product->getManufacturer();
  123.         $paramBag['search'] = false;
  124.         $paramBag['file'] = $file;
  125.         $paramBag['fileExists'] = $fileExists;
  126.         $addToDraftEnabled 0;
  127.         $draftOrder false;
  128.         if($user){
  129.             $order = new Order();
  130.             $branches $this->getBranches($session,$user);
  131.             $draftOrder $order->getOrderByStatus('Draft',$branches,$paginator);
  132.             if(count($draftOrder)>0)
  133.                 $addToDraftEnabled count($draftOrder);
  134.         }
  135.         $paramBag['addToDraftEnabled'] = $addToDraftEnabled;
  136.         $paramBag['draftOrder'] = $draftOrder;
  137.         $paramBag['isMecstoreUser'] =  false;
  138.         $partner $user->getPartner();
  139.        // p_r($partner->getisMecstoreHQ());exit;
  140.         if($partner->getisMecstoreHQ()){
  141.             $paramBag['isMecstoreUser'] =  true;
  142.         }
  143.         //track segments for personalization
  144.         $segmentTrackingHelperService->trackSegmentsForProduct($product);
  145.         $trackingManager $ecommerceFactory->getTrackingManager();
  146.         $trackingManager->trackProductView($product);
  147.         $salesRepesentative = [];
  148.         $manufacturer $product->getManufacturer();
  149.         if($manufacturer){
  150.             $sales $manufacturer->getSalesRepesentative();
  151.             if($sales)
  152.             {
  153.                 $count 0;
  154.                 foreach($sales as $key=>$sale){
  155.                     $salesRepesentative[$count]['Name'] = $sale['Name']->getData().' ('.$sale['Area']->getData().')';
  156.                     $salesRepesentative[$count]['PhoneNo'] = $sale['PhoneNo']->getData();
  157.                     $count++;
  158.                 }
  159.             }
  160.             $salesRepesentative $input array_map("unserialize"array_unique(array_map("serialize"$salesRepesentative)));
  161.         }
  162.         $paramBag['sales_representative'] = $salesRepesentative;
  163.        // $_SERVER['HTTP_REFERER'] ="";
  164.         if(isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'],'shop-by-brand') !== false){
  165.             return $this->render('product/detail_brand.html.twig'$paramBag);
  166.         }
  167.         else if(isset($_SERVER['HTTP_REFERER']) &&  strpos($_SERVER['HTTP_REFERER'],'ovunque') !== false){
  168.             $paramBag['search'] = true;
  169.             return $this->render('product/detail.html.twig'$paramBag);
  170.         }
  171.         else{
  172.             return $this->render('product/detail.html.twig'$paramBag);
  173.         }
  174.     }
  175.     /**
  176.      * @Route("/wishlist/{id}/{remove}", name="wishlist-add")
  177.      * @Security("is_granted('ROLE_USER')")
  178.      * @param Request $request
  179.      * @param HeadTitle $headTitleHelper
  180.      * @param BreadcrumbHelperService $breadcrumbHelperService
  181.      * @param Factory $ecommerceFactory
  182.      * @param SegmentTrackingHelperService $segmentTrackingHelperService
  183.      * @param Concrete $product built-in parameter conversion, please see https://github.com/pimcore/pimcore/pull/5554
  184.      * @param ProductLinkGenerator $productLinkGenerator
  185.      *
  186.      * @return Response
  187.      *
  188.      * @throws \Exception
  189.      */
  190.     public function wishlistAddAction(Request $request)
  191.     {
  192.         $user $this->getUser();
  193.         if(!$user){
  194.             return $this->json(['success'=>false,'message'=>"User is not logged in"]);
  195.         }
  196.         $result = [];
  197.         $products = [];
  198.         $productId $request->get('id',0);
  199.         $remove $request->get('remove',false);
  200.         $product \Pimcore\Model\DataObject::getById($productId);
  201.         if($product){
  202.             $wishlist = new DataObject\Wishlist\Listing();
  203.             $wishlist->setCondition("user__id = ? AND item__id = ?",[$user->getId(),$product->getId()]);
  204.             $lists $wishlist->load();
  205.             if($remove == 'true' && $lists)
  206.             {
  207.                 $wishlist $lists[0];
  208.                 $wishlist->delete();
  209.             }else{
  210.                 if($lists)
  211.                 {
  212.                     $wishlist $lists[0];
  213.                 }else{
  214.                     $wishlist = new DataObject\Wishlist();
  215.                     $wishlist->setKey(\Pimcore\Model\Element\Service::getValidKey($user->getId().'-'.$product->getKey(), 'object'));
  216.                     $wishlist->setParent(\Pimcore\Model\DataObject\Service::createFolderByPath('/customers/Wishlist/'.$user->getEmail()));
  217.                 }
  218.                 $wishlist->setUser($user);
  219.                 $wishlist->setPublished(TRUE);
  220.                 $wishlist->setItem($product);
  221.                 $wishlist->save();
  222.             }
  223.         }
  224.         $totalCount $this->getProductsInWishList($user);
  225.         return $this->json(['success'=>true,'products'=>$totalCount]);
  226.     }
  227.     /**
  228.      * @Route("/wish-list/index", name="wishlist-index")
  229.      * @Security("is_granted('ROLE_USER')")
  230.      * @param Request $request
  231.      * @return Response
  232.      *
  233.      * @throws \Exception
  234.      */
  235.     public function wishListIndexAction(Request $request,UserInterface $user)
  236.     {
  237.         $result = [];
  238.         $products = [];
  239.         $productId $request->get('id',0);
  240.         $params array_merge($request->query->all(), $request->attributes->all());
  241.         if($user){
  242.             $db Db::get();
  243.             $orderBy " ow.oo_id DESC";
  244.             if(isset($params['orderby'])){
  245.                 if($params['orderby'] == "price")
  246.                 {
  247.                     $orderBy 'CONSORZ ASC';
  248.                 }else if($params['orderby'] == "price-desc"){
  249.                     $orderBy =  'CONSORZ DESC';
  250.                 }else if($params['orderby'] == "date"){
  251.                     $orderBy 'oo_id DESC';
  252.                 }else if($params['orderby'] == "popularity"){
  253.                     $orderBy 'oo_id DESC';
  254.                 }
  255.             }else{
  256.                 $orderBy  "ow.o_modificationDate DESC";
  257.             }
  258.             $lists = [];
  259.             $sql 'SELECT ow.oo_id FROM `object_wishlist` ow LEFT JOIN object_prod op ON ow.item__id = op.oo_id WHERE user__id = '.$user->getId().' ORDER BY '.$orderBy;
  260.             $products $db->fetchAll($sql);
  261.             if($products)
  262.             {
  263.                 foreach($products as $prod){
  264.                     $lists[] = \Pimcore\Model\DataObject::getById($prod['oo_id']);
  265.                 }
  266.             }
  267.             $params['products'] = $lists;
  268.             $params['orderby'] = $orderBy;
  269.             $params['isMecstoreUser'] =  false;
  270.             $partner $user->getPartner();
  271.             if($partner->getisMecstoreHQ()){
  272.                 $params['isMecstoreUser'] =  true;
  273.             }
  274.         }
  275.         return $this->render('product/wishlist.html.twig'$params);
  276.     }
  277.     /**
  278.      * @Route("/shop/{categoryname}~c{category}", name="shop-category")
  279.      *
  280.      * @param Request $request
  281.      * @param HeadTitle $headTitleHelper
  282.      * @param BreadcrumbHelperService $breadcrumbHelperService
  283.      * @param Factory $ecommerceFactory
  284.      * @param SegmentTrackingHelperService $segmentTrackingHelperService
  285.      * @param ListHelper $listHelper
  286.      *
  287.      * @return Response
  288.      */
  289.     public function listingAction(Request $requestHeadTitle $headTitleHelperBreadcrumbHelperService $breadcrumbHelperServiceFactory $ecommerceFactorySegmentTrackingHelperService $segmentTrackingHelperServiceListHelper $listHelperPaginatorInterface $paginator,UserInterface $userSessionInterface $session)
  290.     {
  291.         $masterFilterDefinition Config::getWebsiteConfig()->get('masterFilterDefinition');
  292.         $params array_merge($request->query->all(), $request->attributes->all());
  293.         $addToDraftEnabled 0;
  294.         $draftOrder false;
  295.         if($user){
  296.             $order = new Order();
  297.             $branches $this->getBranches($session,$user);
  298.             $draftOrder $order->getOrderByStatus('Draft',$branches,$paginator);
  299.             if(count($draftOrder)>0)
  300.                 $addToDraftEnabled count($draftOrder);
  301.         }
  302.         $params['addToDraftEnabled'] = $addToDraftEnabled;
  303.         $params['draftOrder'] = $draftOrder;
  304.         $params['maxRange'] = 10;
  305.         //Get pricelist name
  306.         $priceListName DEFAULT_PRICELIST_COLUMN;
  307.         if($user){
  308.             $partner $user->getPartner();
  309.             if($partner){
  310.                 //$priceListName = $partner->getPriceList();
  311.             }
  312.         }
  313.         //needed to make sure category filter filters for active category
  314.         $params['parentCategoryIds'] = $params['category'] ?? null;
  315.         $category Category::getById($params['category'] ?? null);
  316.         $params['category'] = $category;
  317.         if ($category) {
  318.             $headTitleHelper($category->getName());
  319.             $breadcrumbHelperService->enrichCategoryPage($category);
  320.         }else{
  321.             $category = new \stdClass();
  322.             $category->name "tutto il catalogo";
  323.             $params['category'] = $category;
  324.         }
  325.         $indexService $ecommerceFactory->getIndexService();
  326.         $productListing $indexService->getProductListForCurrentTenant();
  327.         $productListing->addCondition("disabled != 1");
  328.      //p_r(get_class_methods($productListing));exit;
  329.         $params['term'] = isset($params['term'])?$params['term']:"";
  330.         if(isset($params['term'])){
  331.             //p_r($params);
  332.             //p_r('lower(description) LIKE "%'.strtolower($params['term']).'%"');exit;
  333.             if(strtolower($params['term']) != "ovunque"){
  334.                 if($category instanceof \Pimcore\Model\DataObject){
  335.                     if($params['term']){
  336.                         $searchTerms explode(" ",$params['term']);
  337.                         if($searchTerms)
  338.                         {
  339.                             foreach($searchTerms as $term)
  340.                             {
  341.                                 $productListing->addCondition("searchelem LIKE '%".$term."%' AND categoryIds LIKE '%".$category->getId()."%'");
  342.                             }
  343.                         }
  344.                     }else{
  345.                         $productListing->addCondition("categoryIds LIKE '%".$category->getId()."%'");
  346.                     }
  347.                 }else{
  348.                     if(is_object($category)){
  349.                         if($category->name == "tutto il catalogo"){
  350.                             $filterDefinition $masterFilterDefinition;
  351.                             $category->name "RICERCA";
  352.                         }
  353.                     }
  354.                    // echo "(lower(description) LIKE '".strtolower($params['term'])."%' OR lower(name) LIKE '".strtolower($params['term'])."%' )";exit;
  355.                     if($params['term']){
  356.                         $searchTerms explode(" ",$params['term']);
  357.                         if($searchTerms)
  358.                         {
  359.                             foreach($searchTerms as $term)
  360.                             {
  361.                                 $productListing->addCondition("searchelem LIKE '%".$term."%' OR name LIKE '%".$term."%'");
  362.                             }
  363.                         }
  364.                     }
  365.                 }
  366.             }
  367.             else if($category)
  368.             {
  369.                 $productListing->addCondition("categories LIKE '%".$category->getId()."%'");
  370.             }
  371.         }
  372.          $productListing->setOrderKey('o_id');
  373.          $productListing->setOrder('asc');
  374.         if(isset($params['orderby'])){
  375.            // p_r($params['orderby']);exit;
  376.             if($params['orderby'] == "price")
  377.             {
  378.                 $productListing->setOrderKey($priceListName);
  379.                 $productListing->setOrder('asc');
  380.             }else if($params['orderby'] == "price-desc"){
  381.                 $productListing->setOrderKey($priceListName);
  382.                 $productListing->setOrder('DESC');
  383.             }else if($params['orderby'] == "date"){
  384.                 $productListing->setOrderKey('o_id');
  385.                 $productListing->setOrder('DESC');
  386.             }else if($params['orderby'] == "popularity"){
  387.                 // $productListing->setOrderKey('price');
  388.                 // $productListing->setOrder('DESC');
  389.             }
  390.         }else{
  391.             $params['orderby'] = "o_id";
  392.         }
  393.         $params['productListing'] = $productListing;
  394.         // load current filter
  395.         if ($category instanceof \Pimcore\Model\DataObject) {
  396.             $filterDefinition $category->getFilterdefinition();
  397.             //track segments for personalization
  398.             $segmentTrackingHelperService->trackSegmentsForCategory($category);
  399.             $trackingManager $ecommerceFactory->getTrackingManager();
  400.             $trackingManager->trackCategoryPageView($category->getName(), null);
  401.         }
  402.         if ($request->get('filterdefinition') instanceof FilterDefinition) {
  403.             $filterDefinition $request->get('filterdefinition');
  404.         }
  405.         if (empty($filterDefinition)) {
  406.             $filterDefinition Config::getWebsiteConfig()->get('fallbackFilterdefinition');
  407.         }
  408.         $filterService $ecommerceFactory->getFilterService();
  409.         // Get Max price
  410.         $maxPriceList = clone $productListing;
  411.         $maxParam $params;
  412.         unset($maxParam['page']);
  413.         //p_r($maxPriceList);exit;
  414.         $listHelper->setupProductList($filterDefinition$maxPriceList$maxParam$filterServicetrue);
  415.         $maxPriceList->setOrderKey($priceListName);
  416.         $maxPriceList->setOrder('desc');
  417.         $maxPriceList->setLimit(1);
  418.         $maxPriceItems $maxPriceList->load();
  419.         if($maxPriceItems){
  420.             $getter "getPrice";
  421.             $params['maxRange'] = (int)$maxPriceItems[0]->$getter() +1;
  422.         }
  423.         $listHelper->setupProductList($filterDefinition$productListing$params$filterServicetrue);
  424.         //p_);
  425.         $params['filterService'] = $filterService;
  426.         $params['filterDefinition'] = $filterDefinition;
  427.         //$
  428.         /** @var SlidingPagination $paginator */
  429.         // init pagination
  430.         $pagelimit $request->get('limit'24);
  431.         $paginator $paginator->paginate(
  432.             $productListing,
  433.             $request->get('page'1),
  434.             ($pagelimit)?$pagelimit:24
  435.         );
  436.        // p_r(get_class_methods($paginator));exit;
  437.         $params['results'] = $paginator;
  438.         $params['paginationVariables'] = $paginator->getPaginationData();
  439.         $params['totalCount'] = $paginator->getTotalItemCount();
  440.         $params['offset'] = $paginator->getCurrentPageNumber();
  441.         $params['limit'] =  $pagelimit;
  442.         $params['isMecstoreUser'] =  false;
  443.         $partner $user->getPartner();
  444.         if($partner->getisMecstoreHQ()){
  445.             $params['isMecstoreUser'] =  true;
  446.         }
  447.         //p_r($params);exit;
  448.         if ($request->attributes->get('noLayout')) {
  449.             return $this->render('product/listing_content.html.twig'$params);
  450.         }
  451.         // track product impressions
  452.         $trackingManager $ecommerceFactory->getTrackingManager();
  453.         foreach ($paginator as $product) {
  454.             $trackingManager->trackProductImpression($product'grid');
  455.         }
  456.         //p_r($params);exit;
  457.         return $this->render('product/listing.html.twig'$params);
  458.     }
  459.     /**
  460.      * @Route("/shop-by-brand/{brandname}~c{brand}", name="shop-brand")
  461.      *
  462.      * @param Request $request
  463.      * @param HeadTitle $headTitleHelper
  464.      * @param BreadcrumbHelperService $breadcrumbHelperService
  465.      * @param Factory $ecommerceFactory
  466.      * @param SegmentTrackingHelperService $segmentTrackingHelperService
  467.      * @param ListHelper $listHelper
  468.      *
  469.      * @return Response
  470.      */
  471.     public function listingBrandsAction(Request $requestHeadTitle $headTitleHelperBreadcrumbHelperService $breadcrumbHelperServiceFactory $ecommerceFactorySegmentTrackingHelperService $segmentTrackingHelperServiceListHelper $listHelperPaginatorInterface $paginator,UserInterface $user)
  472.     {
  473.         $params array_merge($request->query->all(), $request->attributes->all());
  474.         $params['maxRange'] = 10;
  475.         //Get pricelist name
  476.         $priceListName DEFAULT_PRICELIST_COLUMN;
  477.         if($user){
  478.             $partner $user->getPartner();
  479.             if($partner){
  480.                 //$priceListName = $partner->getPriceList();
  481.             }
  482.         }
  483.         //needed to make sure category filter filters for active category
  484.         $params['parentCategoryIds'] = $params['category'] ?? null;
  485.         $brand Manufacturer::getById($params['brand'] ?? null);
  486.         $params['manufacturer'] = $brand;
  487.         if ($brand) {
  488.             $headTitleHelper($brand->getName());
  489.         }else{
  490.             $brand = new \stdClass();
  491.             $brand->name "tutto il catalogo";
  492.             $params['manufacturer'] = $brand;
  493.         }
  494.         $indexService $ecommerceFactory->getIndexService();
  495.         $productListing $indexService->getProductListForCurrentTenant();
  496.         $productListing->addCondition("disabled != 1");
  497.         $params['term'] = isset($params['term'])?$params['term']:"";
  498.         if(isset($params['term'])){
  499.             $brandName $brand->getName();
  500.             //p_r($params);
  501.             //p_r('lower(description) LIKE "%'.strtolower($params['term']).'%"');exit;
  502.             if(strtolower($params['term']) != "ovunque"){
  503.                 //echo "searchelem LIKE '%".$brandName."%' OR lower(searchelem) LIKE '".strtolower($params['term'])."%'";exit;
  504.                 if($params['term'])
  505.                 {
  506.                     $productListing->addCondition("manufacturer_name LIKE '%".$brandName."%' OR lower(searchelem) LIKE '%".strtolower($params['term'])."%'");
  507.                 }else{
  508.                     $productListing->addCondition("manufacturer_name LIKE '%".$brandName."%'");
  509.                 }
  510.             }else
  511.             {
  512.                 $productListing->addCondition("searchelem LIKE '%".$brandName."%'");
  513.             }
  514.         }
  515.         // $productListing->setOrderKey('o_id');
  516.         // $productListing->setOrder('asc');
  517.         if(isset($params['orderby'])){
  518.            // p_r($params['orderby']);exit;
  519.             if($params['orderby'] == "price")
  520.             {
  521.                 $productListing->setOrderKey($priceListName);
  522.                 $productListing->setOrder('asc');
  523.             }else if($params['orderby'] == "price-desc"){
  524.                 $productListing->setOrderKey($priceListName);
  525.                 $productListing->setOrder('DESC');
  526.             }else if($params['orderby'] == "date"){
  527.                 $productListing->setOrderKey('o_id');
  528.                 $productListing->setOrder('DESC');
  529.             }else if($params['orderby'] == "popularity"){
  530.                 // $productListing->setOrderKey('price');
  531.                 // $productListing->setOrder('DESC');
  532.             }
  533.         }else{
  534.             $productListing->setOrderKey('manufacturer_name = "'.$brandName.'"');
  535.             $productListing->setOrder('DESC');
  536.             $params['orderby'] = "manufacturer_name";
  537.         }
  538.         $params['productListing'] = $productListing;
  539.         $filterDefinition Config::getWebsiteConfig()->get('manufacturerFilterdefinition');
  540.         $filterService $ecommerceFactory->getFilterService();
  541.         // Get Max price
  542.         $maxPriceList = clone $productListing;
  543.         $maxParam $params;
  544.         unset($maxParam['page']);
  545.         // p_r($maxParam);
  546.         // p_r($filterDefinition);
  547.         // p_r($maxPriceList);
  548.         // p_r($filterService);exit;
  549.         $listHelper->setupProductList($filterDefinition$maxPriceList$maxParam$filterServicetrue);
  550.         $maxPriceList->setOrderKey($priceListName);
  551.         $maxPriceList->setOrder('desc');
  552.         $maxPriceList->setLimit(1);
  553.         $maxPriceItems $maxPriceList->load();
  554.         if($maxPriceItems){
  555.             $params['maxRange'] = $maxPriceItems[0]->getPrice()+1;
  556.         }
  557.         //p_r($params);exit;
  558.         $listHelper->setupProductList($filterDefinition$productListing$params$filterServicetrue);
  559.         $params['filterService'] = $filterService;
  560.         $params['filterDefinition'] = $filterDefinition;
  561.        // p_r(get_class_methods($productListing));exit;
  562.         //$
  563.         /** @var SlidingPagination $paginator */
  564.         // init pagination
  565.         $pagelimit $request->get('limit'12);
  566.         $paginator $paginator->paginate(
  567.             $productListing,
  568.             $request->get('page'1),
  569.             ($pagelimit)?$pagelimit:12
  570.         );
  571.        // p_r(get_class_methods($paginator));exit;
  572.         $params['results'] = $paginator;
  573.         $params['paginationVariables'] = $paginator->getPaginationData();
  574.         $params['totalCount'] = $paginator->getTotalItemCount();
  575.         $params['offset'] = $paginator->getCurrentPageNumber();
  576.         $params['limit'] =  $pagelimit;
  577.         $params['brandObj'] =  $brand;
  578.         $params['isMecstoreUser'] =  false;
  579.         $partner $user->getPartner();
  580.         if($partner->getisMecstoreHQ()){
  581.             $params['isMecstoreUser'] =  true;
  582.         }
  583.         if ($request->attributes->get('noLayout')) {
  584.             return $this->render('product/listing_content_brand.html.twig'$params);
  585.         }
  586.         // track product impressions
  587.         $trackingManager $ecommerceFactory->getTrackingManager();
  588.         foreach ($paginator as $product) {
  589.             $trackingManager->trackProductImpression($product'grid');
  590.         }
  591.         //p_r($params);exit;
  592.         return $this->render('product/shop-in-shop_listing.html.twig'$params);
  593.     }
  594.     /**
  595.      * @Route("/brand/{brandname}~c{brand}", name="shop-brand-product")
  596.      *
  597.      * @param Request $request
  598.      * @param HeadTitle $headTitleHelper
  599.      * @param BreadcrumbHelperService $breadcrumbHelperService
  600.      * @param Factory $ecommerceFactory
  601.      * @param SegmentTrackingHelperService $segmentTrackingHelperService
  602.      * @param ListHelper $listHelper
  603.      *
  604.      * @return Response
  605.      */
  606.     public function brandsProductsAction(Request $requestHeadTitle $headTitleHelperBreadcrumbHelperService $breadcrumbHelperServiceFactory $ecommerceFactorySegmentTrackingHelperService $segmentTrackingHelperServiceListHelper $listHelperPaginatorInterface $paginator,UserInterface $user)
  607.     {
  608.         $params array_merge($request->query->all(), $request->attributes->all());
  609.         $params['maxRange'] = 10;
  610.         //Get pricelist name
  611.         $priceListName DEFAULT_PRICELIST_COLUMN;
  612.         if($user){
  613.             $partner $user->getPartner();
  614.             if($partner){
  615.                 //$priceListName = $partner->getPriceList();
  616.             }
  617.         }
  618.         //needed to make sure category filter filters for active category
  619.         $params['parentCategoryIds'] = $params['category'] ?? null;
  620.         $brand Manufacturer::getById($params['brand'] ?? null);
  621.         $params['manufacturer'] = $brand;
  622.         if ($brand) {
  623.             $headTitleHelper($brand->getName());
  624.         }else{
  625.             $brand = new \stdClass();
  626.             $brand->name "tutto il catalogo";
  627.             $params['manufacturer'] = $brand;
  628.         }
  629.         $indexService $ecommerceFactory->getIndexService();
  630.         $productListing $indexService->getProductListForCurrentTenant();
  631.         $productListing->addCondition("disabled != 1");
  632.         $params['term'] = isset($params['term'])?$params['term']:"";
  633.         if(isset($params['term'])){
  634.             $brandName $brand->getName();
  635.             //p_r($params);
  636.             //p_r('lower(description) LIKE "%'.strtolower($params['term']).'%"');exit;
  637.             if(strtolower($params['term']) != "ovunque"){
  638.                 //echo "searchelem LIKE '%".$brandName."%' OR lower(searchelem) LIKE '".strtolower($params['term'])."%'";exit;
  639.                 if($params['term'])
  640.                 {
  641.                     $productListing->addCondition("manufacturer_name LIKE '%".$brandName."%' OR lower(searchelem) LIKE '%".strtolower($params['term'])."%'");
  642.                 }else{
  643.                     $productListing->addCondition("searchelem LIKE '%".$brandName."%'");
  644.                 }
  645.             }else
  646.             {
  647.                 $productListing->addCondition("searchelem LIKE '%".$brandName."%'");
  648.             }
  649.         }
  650.         // $productListing->setOrderKey('o_id');
  651.         // $productListing->setOrder('asc');
  652.         if(isset($params['orderby'])){
  653.            // p_r($params['orderby']);exit;
  654.             if($params['orderby'] == "price")
  655.             {
  656.                 $productListing->setOrderKey($priceListName);
  657.                 $productListing->setOrder('asc');
  658.             }else if($params['orderby'] == "price-desc"){
  659.                 $productListing->setOrderKey($priceListName);
  660.                 $productListing->setOrder('DESC');
  661.             }else if($params['orderby'] == "date"){
  662.                 $productListing->setOrderKey('o_id');
  663.                 $productListing->setOrder('DESC');
  664.             }else if($params['orderby'] == "popularity"){
  665.                 // $productListing->setOrderKey('price');
  666.                 // $productListing->setOrder('DESC');
  667.             }
  668.         }else{
  669.             $productListing->setOrderKey('manufacturer_name = "'.$brandName.'"');
  670.             $productListing->setOrder('DESC');
  671.             $params['orderby'] = "manufacturer_name";
  672.         }
  673.         $params['productListing'] = $productListing;
  674.         $filterDefinition Config::getWebsiteConfig()->get('manufacturerFilterdefinition');
  675.         $filterService $ecommerceFactory->getFilterService();
  676.         // Get Max price
  677.         $maxPriceList = clone $productListing;
  678.         $maxParam $params;
  679.         unset($maxParam['page']);
  680.         // p_r($maxParam);
  681.         // p_r($filterDefinition);
  682.         // p_r($maxPriceList);
  683.         // p_r($filterService);exit;
  684.         $listHelper->setupProductList($filterDefinition$maxPriceList$maxParam$filterServicetrue);
  685.         $maxPriceList->setOrderKey($priceListName);
  686.         $maxPriceList->setOrder('desc');
  687.         $maxPriceList->setLimit(1);
  688.         $maxPriceItems $maxPriceList->load();
  689.         if($maxPriceItems){
  690.             $params['maxRange'] = $maxPriceItems[0]->getPrice()+1;
  691.         }
  692.         //p_r($params);exit;
  693.         $listHelper->setupProductList($filterDefinition$productListing$params$filterServicetrue);
  694.         $params['filterService'] = $filterService;
  695.         $params['filterDefinition'] = $filterDefinition;
  696.        // p_r(get_class_methods($productListing));exit;
  697.         //$
  698.         /** @var SlidingPagination $paginator */
  699.         // init pagination
  700.         $pagelimit $request->get('limit'12);
  701.         $paginator $paginator->paginate(
  702.             $productListing,
  703.             $request->get('page'1),
  704.             ($pagelimit)?$pagelimit:12
  705.         );
  706.        // p_r(get_class_methods($paginator));exit;
  707.         $params['results'] = $paginator;
  708.         $params['paginationVariables'] = $paginator->getPaginationData();
  709.         $params['totalCount'] = $paginator->getTotalItemCount();
  710.         $params['offset'] = $paginator->getCurrentPageNumber();
  711.         $params['limit'] =  $pagelimit;
  712.         $params['brandObj'] =  $brand;
  713.         $params['isMecstoreUser'] =  false;
  714.         $partner $user->getPartner();
  715.         if($partner->getisMecstoreHQ()){
  716.             $params['isMecstoreUser'] =  true;
  717.         }
  718.         if ($request->attributes->get('noLayout')) {
  719.             return $this->render('product/listing_content_brand.html.twig'$params);
  720.         }
  721.         // track product impressions
  722.         $trackingManager $ecommerceFactory->getTrackingManager();
  723.         foreach ($paginator as $product) {
  724.             $trackingManager->trackProductImpression($product'grid');
  725.         }
  726.         //p_r($params);exit;
  727.         return $this->render('product/shop-in-shop.html.twig'$params);
  728.     }
  729.     /**
  730.      * @param Request $request
  731.      * @param Factory $ecommerceFactory
  732.      *
  733.      * @return Response
  734.      */
  735.     public function productTeaserAction(Request $requestFactory $ecommerceFactory)
  736.     {
  737.         $paramsBag = [];
  738.         if ($request->get('type') == 'object') {
  739.             AbstractObject::setGetInheritedValues(true);
  740.             $product AbstractProduct::getById($request->get('id'));
  741.             $paramsBag['product'] = $product;
  742.             $paramsBag['backend'] = true;
  743.             //track product impression
  744.             $trackingManager $ecommerceFactory->getTrackingManager();
  745.             $trackingManager->trackProductImpression($product'teaser');
  746.             return $this->render('product/product_teaser.html.twig'$paramsBag);
  747.         }
  748.         throw new NotFoundHttpException('Product not found.');
  749.     }
  750.     /**
  751.      * @Route("/search", name="search")
  752.      *
  753.      * @param Request $request
  754.      * @param ListHelper $listHelper
  755.      * @param Factory $ecommerceFactory
  756.      * @param ProductLinkGenerator $productLinkGenerator
  757.      * @param Translator $translator
  758.      * @param BreadcrumbHelperService $breadcrumbHelperService
  759.      * @param HeadTitle $headTitleHelper
  760.      * @param Placeholder $placeholder
  761.      *
  762.      * @return Response|JsonResponse
  763.      */
  764.     public function searchAction(Request $requestListHelper $listHelperFactory $ecommerceFactoryProductLinkGenerator $productLinkGeneratorTranslator $translatorBreadcrumbHelperService $breadcrumbHelperServiceHeadTitle $headTitleHelperPlaceholder $placeholderPaginatorInterface $paginator)
  765.     {
  766.         $params $request->query->all();
  767.         $params['category'] = Category::getById($params['category'] ?? null);
  768.         $indexService $ecommerceFactory->getIndexService();
  769.         $productListing $indexService->getProductListForCurrentTenant();
  770.         $productListing->setVariantMode(ProductListInterface::VARIANT_MODE_VARIANTS_ONLY);
  771.         $term strip_tags($request->get('term'));
  772.         if($productListing instanceof AbstractElasticSearch) {
  773.             // simple elastic search query - uses multi-match query on all defined search_attributes
  774. //            $productListing->addQueryCondition($term);
  775.             //sample for a more specific elastic search query - not considers search_attributes but provides full flexibility
  776.             // this query weights cars more that accessories
  777.             $query = [
  778.                 'function_score' => [
  779.                     'query' => [
  780.                         'multi_match' => [
  781.                             "query" => $term,
  782.                             "type" => "cross_fields",
  783.                             "operator" => "and",
  784.                             "fields" => [
  785.                                 "attributes.name^4",
  786.                                 "attributes.name.analyzed",
  787.                                 "attributes.name.analyzed_ngram",
  788.                                 "attributes.manufacturer_name^3",
  789.                                 "attributes.manufacturer_name.analyzed",
  790.                                 "attributes.manufacturer_name.analyzed_ngram",
  791.                                 "attributes.color",
  792.                                 "attributes.color.analyzed",
  793.                                 "attributes.color.analyzed_ngram",
  794.                                 "attributes.carClass",
  795.                                 "attributes.carClass.analyzed",
  796.                                 "attributes.carClass.analyzed_ngram"
  797.                             ]
  798.                         ]
  799.                     ],
  800.                     'functions' => [
  801.                         [
  802.                             'filter' => ['match' => ['system.o_classId' => 'AP']],
  803.                             'weight' => 1
  804.                         ],
  805.                         [
  806.                             'filter' => ['match' => ['system.o_classId' => 'CAR']],
  807.                             'weight' => 2
  808.                         ]
  809.                     ],
  810.                     'boost_mode' => 'multiply'
  811.                 ]
  812.             ];
  813.             $productListing->addQueryCondition($query'searchTerm');
  814.         } else {
  815.             //default mysql search query condition - would also work for elastic search in that way
  816.             $term trim(preg_replace('/\s+/'' '$term));
  817.             if (!empty($term)) {
  818.                 foreach (explode(' '$term) as $t) {
  819.                     $productListing->addQueryCondition($t);
  820.                 }
  821.             }
  822.         }
  823.         if (isset($params['autocomplete'])) {
  824.             $resultset = [];
  825.             $productListing->setLimit(10);
  826.             foreach ($productListing as $product) {
  827.                 $result['href'] = $productLinkGenerator->generateWithMockup($product, []);
  828.                 if ($product instanceof Car) {
  829.                     $result['product'] = $product->getOSName() . ' ' $product->getColor()[0] . ', ' $product->getCarClass();
  830.                 } else {
  831.                     $result['product'] = $product->getOSName();
  832.                 }
  833.                 $resultset[] = $result;
  834.             }
  835.             return $this->json($resultset);
  836.         }
  837.         $filterDefinition $params['filterDefinition'] = Config::getWebsiteConfig()->get('fallbackFilterdefinition');
  838.         // create and init filter service
  839.         $filterService Factory::getInstance()->getFilterService();
  840.         $listHelper->setupProductList($filterDefinition$productListing$params$filterServicetrue);
  841.         $params['filterService'] = $filterService;
  842.         $params['products'] = $productListing;
  843.         // init pagination
  844.         $paginator $paginator->paginate(
  845.             $productListing,
  846.             $request->get('page'1),
  847.             $filterDefinition->getPageLimit()
  848.         );
  849.         $params['results'] = $paginator;
  850.         $params['paginationVariables'] = $paginator->getPaginationData();
  851.         $trackingManager $ecommerceFactory->getTrackingManager();
  852.         foreach ($paginator as $product) {
  853.             $trackingManager->trackProductImpression($product'search-results');
  854.         }
  855.         //breadcrumbs
  856.         $placeholder('addBreadcrumb')->append([
  857.             'parentId' => $this->document->getId(),
  858.             'id' => 'search-result',
  859.             'label' => $translator->trans('shop.search-result', [$term])
  860.         ]);
  861.         $params['language'] = $request->getLocale();
  862.         $params['term'] = $term;
  863.         $breadcrumbHelperService->enrichGenericDynamicPage($translator->trans('shop.search-result', [$term]));
  864.         $headTitleHelper($translator->trans('shop.search-result', [$term]));
  865.         return $this->render('product/search.html.twig'$params);
  866.     }
  867.     private function getProductsInWishList($user){
  868.         $products = new \Pimcore\Model\DataObject\Wishlist\Listing();
  869.         $products->setCondition('user__id = ?',[$user->getId()]);
  870.         return $products->getCount();
  871.     }
  872.     /**
  873.      * @Route("/get-product-statistics/{id}", name="get-product-statistics")
  874.      *
  875.      * @param Request $request
  876.      *
  877.      * @return Response|JsonResponse
  878.      */
  879.     public function getProductStatistics(Request $request,UserInterface $user null){
  880.         $order = new Order();
  881.         $db \Pimcore\Db::get();
  882.         $response = [];
  883.         $jsonResponse = [];
  884.         $partner $user->getPartner();
  885.         // p_r($partner->getisMecstoreHQ());exit;
  886.         if($partner->getisMecstoreHQ()){
  887.             try{
  888.                 $productId $request->get('id',null);
  889.                 if(!$productId){
  890.                     throw new \Exception("Product not found ");
  891.                 }
  892.                 // Product
  893.                 $product \Pimcore\Model\DataObject::getById($productId);
  894.                 //User
  895.                 $partner $user->getPartner();
  896.                 // Order statistics
  897.                 $response['order'] = $order->getOrderStatistics($db,$productId);
  898.                 //print_r($response['order']); die();
  899.                 $deliveredQty $this->getProductDeliveredQty($response['order'], $product->getItem());
  900.                 $response['deliveredQty'] = (float)$deliveredQty;
  901.                 $this->deleteOrdersDeleted($response['order']);
  902.                 // Booking statistics
  903.                 $response['booking'] = $order->getBookingStatistics($db,$productId);
  904.                 // Booking statistics
  905.                 $response['draft'] = $order->getBookingStatistics($db,$productId,'draft');
  906.                 // Pre Order statistics
  907.                 $response['pre_order'] = $order->getPreOrderStatistics($db,$productId);
  908.                 $response['item'] = \App\Model\Utility::getOrders([$product->getItem()],$partner->getCustSupp());
  909.                 $response['product'] = $product;
  910.                 $response['giacenza'] = $this->getProductGiacenza($product->getItem());
  911.             //  p_r($response);exit;
  912.                 $jsonResponse['success'] = true;
  913.                 $html $this->renderView('product/_availability_modal.html.twig',$response);
  914.                 $jsonResponse['html'] = $html;
  915.             }catch(\Exception $ex){
  916.                 $jsonResponse['success'] = false;
  917.                 $jsonResponse['message'] = $ex->getMessage();
  918.             }
  919.         }
  920.         return $this->json($jsonResponse);
  921.     }
  922.     public function getBranches(SessionInterface $session nullUserInterface $user){
  923.         $branches = [];
  924.         if($user){
  925.             $partner $user->getPartner();
  926.             if($partner){
  927.                 $taxIdNumber $partner->getTaxIdNumber();
  928.                 if($user->getUserRoles() == "Executive" || $user->getUserRoles() == "Customer" || $user->getUserRoles() == "Affiliate"){
  929.                     $branches[] = $partner->getId();
  930.                 }
  931.                 else if($user->getUserRoles() == 'Manager'){
  932.                     $partnerBranches = new DataObject\Partners\Listing();
  933.                     $partnerBranches->setCondition("TaxIdNumber = ?",[$partner->getTaxIdNumber()]);
  934.                     $partnerBranches $partnerBranches->load();
  935.                     if($partnerBranches)
  936.                     {
  937.                         foreach($partnerBranches as $branch){
  938.                             $branches[] = $branch->getId();
  939.                         }
  940.                     }
  941.                 }
  942.             }
  943.         }
  944.         return $branches;
  945.     }
  946.     /**
  947.      * @Route("/get-product-opd/{id}", name="get-product-opd")
  948.      *
  949.      * @param Request $request
  950.      *
  951.      * @return Response|JsonResponse
  952.      */
  953.     public function getProductOpd(Request $request,UserInterface $user nullPaginatorInterface $paginatorSessionInterface $session){
  954.         $order = new Order();
  955.         $db \Pimcore\Db::get();
  956.         $response = [];
  957.         $jsonResponse = [];
  958.         $partner $user->getPartner();
  959.         $branches $this->getBranches($session,$user);
  960.         // p_r($partner->getisMecstoreHQ());exit;
  961.         if(true){
  962.             try{
  963.                 $productId $request->get('id',null);
  964.                 if(!$productId){
  965.                     throw new \Exception("Product not found ");
  966.                 }
  967.                 // Product
  968.                 $product \Pimcore\Model\DataObject::getById($productId);
  969.                 //User
  970.                 $partner $user->getPartner();
  971.                 // Order statistics
  972.                 $response['order'] = $order->getCustomerOrderWithProduct($db$user->getId(), $productId);
  973.                 //print_r($response['order']); die();
  974.                 $deliveredQty $this->getProductDeliveredQty($response['order'], $product->getItem());
  975.                 $response['deliveredQty'] = (float)$deliveredQty;
  976.                 //$this->deleteOrdersDeleted($response['order']);
  977.                 // Booking statistics
  978.                 $response['booking'] = $order->getCustomerPrenotazioniProduct($db$user->getId(), $productId);
  979.                 // Booking statistics
  980.                 $response['draft'] = $order->getCustomerDraftWithProduct($db$user->getId(), $productId);
  981.                 // Pre Order statistics
  982.                 $response['pre_order'] = $order->getCustomerPreorderProduct($db$user->getId(), $productId);
  983.                 $response['item'] = \App\Model\Utility::getOrders([$product->getItem()],$partner->getCustSupp());
  984.                 $response['product'] = $product;
  985.                 //  p_r($response);exit;
  986.                 $jsonResponse['success'] = true;
  987.                 $html $this->renderView('product/_opd_modal.html.twig',$response);
  988.                 $jsonResponse['html'] = $html;
  989.             }catch(\Exception $ex){
  990.                 $jsonResponse['success'] = false;
  991.                 $jsonResponse['message'] = $ex->getMessage();
  992.             }
  993.         }
  994.         return $this->json($jsonResponse);
  995.     }
  996.     /**
  997.      * @Route("/get-products-opd/{ids}", name="get-products-opd")
  998.      *
  999.      * @param Request $request
  1000.      *
  1001.      * @return Response|JsonResponse
  1002.      */
  1003.     public function getProductsOpd(Request $request,UserInterface $user nullPaginatorInterface $paginatorSessionInterface $session){
  1004.         $order = new Order();
  1005.         $db \Pimcore\Db::get();
  1006.         $response = [];
  1007.         $jsonResponse = [];
  1008.         $partner $user->getPartner();
  1009.         $branches $this->getBranches($session,$user);
  1010.         $ids explode(","substr($request->get('ids',null),1));
  1011.         //p_r($ids);
  1012.         // p_r($partner->getisMecstoreHQ());exit;
  1013.         $data = [];
  1014.         if(true){
  1015.             foreach($ids as $productId) {
  1016.                 try {
  1017.                     if (!$productId) {
  1018.                         continue;
  1019.                     }
  1020.                     $temp = [];
  1021.                     // Product
  1022.                     $product \Pimcore\Model\DataObject::getById($productId);
  1023.                     //User
  1024.                     $partner $user->getPartner();
  1025.                     // Order statistics
  1026.                     $response['order'] = $order->getCustomerOrderWithProduct($db$user->getId(), $productId);
  1027.                     //print_r($response['order']); die();
  1028.                     $deliveredQty $this->getProductDeliveredQty($response['order'], $product->getItem());
  1029.                     $response['deliveredQty'] = (float)$deliveredQty;
  1030.                     //$this->deleteOrdersDeleted($response['order']);
  1031.                     // Booking statistics
  1032.                     $response['booking'] = $order->getCustomerPrenotazioniProduct($db$user->getId(), $productId);
  1033.                     // Booking statistics
  1034.                     $response['draft'] = $order->getCustomerDraftWithProduct($db$user->getId(), $productId);
  1035.                     // Pre Order statistics
  1036.                     $response['pre_order'] = $order->getCustomerPreorderProduct($db$user->getId(), $productId);
  1037.                     //$response['item'] = \App\Model\Utility::getOrders([$product->getItem()], $partner->getCustSupp());
  1038.                     //$response['product'] = $product;
  1039.                     if(
  1040.                         count($response['order'])>||
  1041.                         $response['booking'][0]['order_id'] != '' ||
  1042.                         count($response['draft'])>||
  1043.                         $response['pre_order'][0]['company'] != ''
  1044.                     ){
  1045.                         $temp[$productId] = 'custom-yellow';
  1046.                     }else{
  1047.                         $temp[$productId] = 'custom-green';
  1048.                     }
  1049.                     $data[] = $temp;
  1050.                 } catch (\Exception $ex) {
  1051.                     $data[] = $ex->getMessage();
  1052.                 }
  1053.             }
  1054.         }
  1055.         return $this->json($data);
  1056.     }
  1057.     public function deleteOrdersDeleted($listaOrdini){
  1058.         //print_r($listaOrdini);
  1059.         $salesOrdersIds = [];
  1060.         foreach($listaOrdini as $ordine){
  1061.             $ord \Pimcore\Model\DataObject\OnlineShopOrder::getById($ordine['order_id'], true);
  1062.             $salesOrdersIds[] = $ord->getSalesOrderId();
  1063.         }
  1064.         $salesOrdersIds implode(","$salesOrdersIds);
  1065.         //echo $salesOrdersIds;
  1066.         $responseArr = [];
  1067.         if($salesOrdersIds != '') {
  1068.             $curl = new CurlService();
  1069.             try {
  1070.                 $request '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
  1071.             <soapenv:Header/>
  1072.             <soapenv:Body>
  1073.                 <tem:getNumOrdNoMatch>
  1074.                     <tem:Token_Client>' SOAP_TOKEN '</tem:Token_Client>
  1075.                     <tem:ListSaleOrdId>' $salesOrdersIds '</tem:ListSaleOrdId>
  1076.                 </tem:getNumOrdNoMatch>
  1077.             </soapenv:Body>
  1078.             </soapenv:Envelope>';
  1079.                 \Pimcore\Log\Simple::log('erp_order_request'$request);
  1080.                 $xml sprintf($requestSOAP_TOKEN);
  1081.                 $response $curl->getCurlResponseNew($request$xml);
  1082.                 $ordersToDelete $response->xpath('//ListaOrdiniRichiesti/SaleOrdId');
  1083.             } catch (Exception $e) {
  1084.                 //\Pimcore\Log\Simple::log('soap', $e->getMessage());
  1085.                 echo "ERRORE";
  1086.             }
  1087.             //echo $xml; //die();
  1088.             //print_r($response);
  1089.             //print_r($ordersToDelete); die();
  1090.             foreach ($ordersToDelete as $orderToDelete) {
  1091.                 $otd \Pimcore\Model\DataObject\OnlineShopOrder::getBySalesOrderId($orderToDeletetrue);
  1092.                 if ($otd) {
  1093.                     //echo $otd->getOrdernumber();
  1094.                     $otd->delete();
  1095.                 }
  1096.             }
  1097.         }
  1098.     }
  1099.     private function getProductGiacenza($productId)
  1100.     {
  1101.         $curl = new CurlService();
  1102.         $request '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
  1103.             <soapenv:Header/>
  1104.             <soapenv:Body>
  1105.             <tem:getDisponibilitaItems>
  1106.                 <!--Optional:-->
  1107.                 <tem:Token_Client>'.SOAP_TOKEN.'</tem:Token_Client>
  1108.                 <!--Optional:-->
  1109.                 <tem:ListItems>'.$productId.'</tem:ListItems>
  1110.             </tem:getDisponibilitaItems>
  1111.             </soapenv:Body>
  1112.         </soapenv:Envelope>';
  1113.         // echo $request;exit;
  1114.         $xml sprintf($request,SOAP_TOKEN);
  1115.         $response $curl->getCurlResponseNew($request,$xml);
  1116.         $output = [
  1117.             'giacenza' => null,
  1118.             'disponibilita' => null
  1119.         ];
  1120.         if($response instanceof \SimpleXMLElement) {
  1121.             $results $response->xpath('//Disponibilita/Giacenza');
  1122.             foreach ($results as $item) {
  1123.                 $xmlResponse = (array)$item;
  1124.                 if (isset($xmlResponse[0])) {
  1125.                     $output['giacenza'] = $xmlResponse[0];
  1126.                 }
  1127.             }
  1128.             $results $response->xpath('//Disponibilita/Disponibilita');
  1129.             foreach ($results as $item) {
  1130.                 $xmlResponse = (array)$item;
  1131.                 if (isset($xmlResponse[0])) {
  1132.                     $output['disponibilita'] = $xmlResponse[0];
  1133.                 }
  1134.             }
  1135.         }
  1136.         return $output;
  1137.     }
  1138.     private function getProductDeliveredQty($orderId$item){
  1139.         $return 0;
  1140.         if(isset($orderId[0]['order_id'])) {
  1141.             $ord \Pimcore\Model\DataObject\OnlineShopOrder::getById($orderId[0]['order_id'], true);
  1142.             if ($ord) {
  1143.                 $salesOrderId $ord->getSalesOrderId();
  1144.                 $curl = new CurlService();
  1145.                 $request '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
  1146.                 <soapenv:Header/>
  1147.                 <soapenv:Body>
  1148.                     <tem:getMembersSaleOrdersDetails_Parameters>
  1149.                         <!--Optional:-->
  1150.                         <tem:Token_Client>%s</tem:Token_Client>
  1151.                         <!--Optional:-->
  1152.                         <tem:ToDate></tem:ToDate>
  1153.                         <!--Optional:-->
  1154.                         <tem:Customer/>
  1155.                         <tem:FromSaleOrdId>%s</tem:FromSaleOrdId>
  1156.                         <!--Optional:-->
  1157.                         <tem:LimitRecords>1</tem:LimitRecords>
  1158.                         <!--Optional:-->
  1159.                         <tem:FromDate></tem:FromDate>
  1160.                     </tem:getMembersSaleOrdersDetails_Parameters>
  1161.                 </soapenv:Body>
  1162.                 </soapenv:Envelope>';
  1163.                 $xml sprintf($requestSOAP_TOKEN$salesOrderId);
  1164.                 $response $curl->getCurlResponseNew($request$xml);
  1165.                 //print_r($response);
  1166.                 $membersOrdersDetails $response->xpath('//MembersOrdersDetailsParameters');
  1167.                 if (count($membersOrdersDetails)) {
  1168.                     foreach ($membersOrdersDetails as $membersOrderDetails) {
  1169.                         if ($membersOrderDetails->Item == $item) {
  1170.                             $return $membersOrderDetails->DeliveredQty;
  1171.                         }
  1172.                     }
  1173.                 }
  1174.             }
  1175.         }
  1176.         return $return;
  1177.     }
  1178.     /**
  1179.      * @Route("/admin/tutti-i-prodotti", name="tutti-i-prodotti")
  1180.      *
  1181.      * @param Request $request
  1182.      * @param HeadTitle $headTitleHelper
  1183.      * @param BreadcrumbHelperService $breadcrumbHelperService
  1184.      * @param Factory $ecommerceFactory
  1185.      * @param SegmentTrackingHelperService $segmentTrackingHelperService
  1186.      * @param ListHelper $listHelper
  1187.      *
  1188.      * @return Response
  1189.      */
  1190.     public function tuttiIProdottiAction(Request $requestHeadTitle $headTitleHelperBreadcrumbHelperService $breadcrumbHelperServiceFactory $ecommerceFactorySegmentTrackingHelperService $segmentTrackingHelperServiceListHelper $listHelperPaginatorInterface $paginator,UserInterface $userSessionInterface $session)
  1191.     {
  1192.         $masterFilterDefinition Config::getWebsiteConfig()->get('masterFilterDefinition');
  1193.         $params array_merge($request->query->all(), $request->attributes->all());
  1194.         $addToDraftEnabled 0;
  1195.         $draftOrder false;
  1196.         $params['addToDraftEnabled'] = $addToDraftEnabled;
  1197.         $params['draftOrder'] = $draftOrder;
  1198.         $params['maxRange'] = 10;
  1199.         //Get pricelist name
  1200.         $priceListName DEFAULT_PRICELIST_COLUMN;
  1201.         //needed to make sure category filter filters for active category
  1202.         $params['parentCategoryIds'] = $params['category'] ?? null;
  1203.         $category Category::getById($params['category'] ?? null);
  1204.         $params['category'] = $category;
  1205.         if ($category) {
  1206.             $headTitleHelper($category->getName());
  1207.             $breadcrumbHelperService->enrichCategoryPage($category);
  1208.         }else{
  1209.             $category = new \stdClass();
  1210.             $category->name "tutto il catalogo";
  1211.             $params['category'] = $category;
  1212.         }
  1213.         $indexService $ecommerceFactory->getIndexService();
  1214.         $productListing $indexService->getProductListForCurrentTenant();
  1215.         $productListing->addCondition("disabled != 1");
  1216.         //p_r(get_class_methods($productListing));exit;
  1217.         $params['term'] = isset($params['term'])?$params['term']:"";
  1218.         if(isset($params['term'])){
  1219.             //p_r($params);
  1220.             //p_r('lower(description) LIKE "%'.strtolower($params['term']).'%"');exit;
  1221.             if(strtolower($params['term']) != "ovunque"){
  1222.                 if($category instanceof \Pimcore\Model\DataObject){
  1223.                     if($params['term']){
  1224.                         $searchTerms explode(" ",$params['term']);
  1225.                         if($searchTerms)
  1226.                         {
  1227.                             foreach($searchTerms as $term)
  1228.                             {
  1229.                                 $productListing->addCondition("searchelem LIKE '%".$term."%' AND categoryIds LIKE '%".$category->getId()."%'");
  1230.                             }
  1231.                         }
  1232.                     }else{
  1233.                         $productListing->addCondition("categoryIds LIKE '%".$category->getId()."%'");
  1234.                     }
  1235.                 }else{
  1236.                     if(is_object($category)){
  1237.                         if($category->name == "tutto il catalogo"){
  1238.                             $filterDefinition $masterFilterDefinition;
  1239.                             $category->name "RICERCA";
  1240.                         }
  1241.                     }
  1242.                     // echo "(lower(description) LIKE '".strtolower($params['term'])."%' OR lower(name) LIKE '".strtolower($params['term'])."%' )";exit;
  1243.                     if($params['term']){
  1244.                         $searchTerms explode(" ",$params['term']);
  1245.                         if($searchTerms)
  1246.                         {
  1247.                             foreach($searchTerms as $term)
  1248.                             {
  1249.                                 $productListing->addCondition("searchelem LIKE '%".$term."%'");
  1250.                             }
  1251.                         }
  1252.                     }
  1253.                 }
  1254.             }
  1255.             else if($category)
  1256.             {
  1257.                 $productListing->addCondition("categories LIKE '%".$category->getId()."%'");
  1258.             }
  1259.         }
  1260.         $productListing->setOrderKey('o_id');
  1261.         $productListing->setOrder('asc');
  1262.         if(isset($params['orderby'])){
  1263.             // p_r($params['orderby']);exit;
  1264.             if($params['orderby'] == "price")
  1265.             {
  1266.                 $productListing->setOrderKey($priceListName);
  1267.                 $productListing->setOrder('asc');
  1268.             }else if($params['orderby'] == "price-desc"){
  1269.                 $productListing->setOrderKey($priceListName);
  1270.                 $productListing->setOrder('DESC');
  1271.             }else if($params['orderby'] == "date"){
  1272.                 $productListing->setOrderKey('o_id');
  1273.                 $productListing->setOrder('DESC');
  1274.             }else if($params['orderby'] == "popularity"){
  1275.                 // $productListing->setOrderKey('price');
  1276.                 // $productListing->setOrder('DESC');
  1277.             }
  1278.         }else{
  1279.             $params['orderby'] = "o_id";
  1280.         }
  1281.         $params['productListing'] = $productListing;
  1282.         // load current filter
  1283.         if ($category instanceof \Pimcore\Model\DataObject) {
  1284.             $filterDefinition $category->getFilterdefinition();
  1285.             //track segments for personalization
  1286.             $segmentTrackingHelperService->trackSegmentsForCategory($category);
  1287.             $trackingManager $ecommerceFactory->getTrackingManager();
  1288.             $trackingManager->trackCategoryPageView($category->getName(), null);
  1289.         }
  1290.         if ($request->get('filterdefinition') instanceof FilterDefinition) {
  1291.             $filterDefinition $request->get('filterdefinition');
  1292.         }
  1293.         if (empty($filterDefinition)) {
  1294.             $filterDefinition Config::getWebsiteConfig()->get('fallbackFilterdefinition');
  1295.         }
  1296.         $filterService $ecommerceFactory->getFilterService();
  1297.         // Get Max price
  1298.         $maxPriceList = clone $productListing;
  1299.         $maxParam $params;
  1300.         unset($maxParam['page']);
  1301.         //p_r($maxPriceList);exit;
  1302.         $listHelper->setupProductList($filterDefinition$maxPriceList$maxParam$filterServicetrue);
  1303.         $maxPriceList->setOrderKey($priceListName);
  1304.         $maxPriceList->setOrder('desc');
  1305.         $maxPriceList->setLimit(1);
  1306.         $maxPriceItems $maxPriceList->load();
  1307.         if($maxPriceItems){
  1308.             $getter "getPrice";
  1309.             $params['maxRange'] = (int)$maxPriceItems[0]->$getter() +1;
  1310.         }
  1311.         $listHelper->setupProductList($filterDefinition$productListing$params$filterServicetrue);
  1312.         //p_);
  1313.         $params['filterService'] = $filterService;
  1314.         $params['filterDefinition'] = $filterDefinition;
  1315.         //$
  1316.         /** @var SlidingPagination $paginator */
  1317.         // init pagination
  1318.         $pagelimit $request->get('limit'24);
  1319.         $paginator $paginator->paginate(
  1320.             $productListing,
  1321.             $request->get('page'1),
  1322.             99999
  1323.         );
  1324.         // p_r(get_class_methods($paginator));exit;
  1325.         $params['results'] = $paginator;
  1326.         $params['paginationVariables'] = $paginator->getPaginationData();
  1327.         $params['totalCount'] = $paginator->getTotalItemCount();
  1328.         $params['offset'] = $paginator->getCurrentPageNumber();
  1329.         $params['limit'] =  $pagelimit;
  1330.         $params['isMecstoreUser'] =  false;
  1331.         p_r($params);
  1332.         $contatore 1;
  1333.         foreach($params['results'] as $item){
  1334.             echo $contatore.";".$item->getItem()."<br/>";
  1335.             $contatore++;
  1336.         }
  1337.         return new Response('');
  1338.     }
  1339. }