src/Controller/ProductB2CController.php line 558

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 Pimcore\Model\DataObject\Manufacturer;
  20. use App\Services\SegmentTrackingHelperService;
  21. use App\Website\LinkGenerator\ProductLinkGenerator;
  22. use App\Website\Navigation\BreadcrumbHelperService;
  23. use Knp\Component\Pager\Pagination\SlidingPagination;
  24. use Knp\Component\Pager\PaginatorInterface;
  25. use Pimcore\Bundle\EcommerceFrameworkBundle\Factory;
  26. use Pimcore\Bundle\EcommerceFrameworkBundle\FilterService\ListHelper;
  27. use Pimcore\Bundle\EcommerceFrameworkBundle\IndexService\ProductList\DefaultMysql;
  28. use Pimcore\Bundle\EcommerceFrameworkBundle\IndexService\ProductList\ElasticSearch\AbstractElasticSearch;
  29. use Pimcore\Bundle\EcommerceFrameworkBundle\IndexService\ProductList\ProductListInterface;
  30. use Pimcore\Config;
  31. use Pimcore\Model\DataObject\AbstractObject;
  32. use Pimcore\Model\DataObject\Concrete;
  33. use Pimcore\Model\DataObject\Data\UrlSlug;
  34. use Pimcore\Model\DataObject\FilterDefinition;
  35. use Pimcore\Translation\Translator;
  36. use Pimcore\Twig\Extension\Templating\HeadTitle;
  37. use Pimcore\Twig\Extension\Templating\Placeholder;
  38. use Symfony\Component\HttpFoundation\JsonResponse;
  39. use Symfony\Component\HttpFoundation\Request;
  40. use Symfony\Component\HttpFoundation\Response;
  41. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  42. use Symfony\Component\Routing\Annotation\Route;
  43. use Symfony\Component\Security\Core\User\UserInterface;
  44. use Pimcore\Model\DataObject;
  45. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  46. use Pimcore\Db;
  47. use App\Lib\Utility;
  48. class ProductB2CController extends BaseB2CController
  49. {
  50.     /**
  51.      * @param Request $request
  52.      * @param AbstractObject $object
  53.      * @param UrlSlug $urlSlug
  54.      * @return Response
  55.      */
  56.     public function productDetailSlugAction(Request $requestAbstractObject $objectUrlSlug $urlSlug) {
  57.         return $this->forward('App\Controller\ProductB2CController::detailAction', ['product' => $object]);
  58.     }
  59.     /**
  60.      * @Route("/b2c/shop/{path}{productname}~p{product}", name="b2c-shop-detail", defaults={"path"=""}, requirements={"path"=".*?", "productname"="[\w-]+", "product"="\d+"})
  61.      * @param Request $request
  62.      * @param HeadTitle $headTitleHelper
  63.      * @param BreadcrumbHelperService $breadcrumbHelperService
  64.      * @param Factory $ecommerceFactory
  65.      * @param SegmentTrackingHelperService $segmentTrackingHelperService
  66.      * @param Concrete $product built-in parameter conversion, please see https://github.com/pimcore/pimcore/pull/5554
  67.      * @param ProductLinkGenerator $productLinkGenerator
  68.      *
  69.      * @return Response
  70.      *
  71.      * @throws \Exception
  72.      */
  73.     public function detailAction(
  74.         Request $request,
  75.         HeadTitle $headTitleHelper,
  76.         BreadcrumbHelperService $breadcrumbHelperService,
  77.         Factory $ecommerceFactory,
  78.         SegmentTrackingHelperService $segmentTrackingHelperService,
  79.         Concrete $product,
  80.         ProductLinkGenerator $productLinkGenerator
  81.     )
  82.     {
  83.         if (!(
  84.                 $product && $product->isPublished()
  85.             )
  86.         ) {
  87.             throw new NotFoundHttpException('Product not found.');
  88.         }
  89.         $file null;
  90.         $fileExists false;
  91.         $file BASE_URL.'/document/'.$product->getItem().'.pdf';
  92.         /*if(Utility::check_file_exist($file))
  93.         {
  94.            $fileExists = true;
  95.            $file = BASE_URL.'/document/'.$product->getItem().'.pdf';
  96.         }else{
  97.             $file = null;
  98.         }*/
  99.         if($file $product->getProductPdf()){
  100.             $fileExists true;
  101.             $file $product->getProductPdf();
  102.         }
  103.         // //redirect to main url
  104.         // $generatorUrl = $productLinkGenerator->generate($product);
  105.         // if($generatorUrl != $request->getPathInfo()) {
  106.         //     $queryString = $request->getQueryString();
  107.         //     return $this->redirect($generatorUrl . ($queryString ? '?' . $queryString : ''));
  108.         // }
  109.         $breadcrumbHelperService->enrichProductDetailPage($product);
  110.         $headTitleHelper($product->getOSName());
  111.         $paramBag $this->getAllParameters($request);
  112.         $paramBag['product'] = $product;
  113.         $paramBag['category'] = $product->getMainCategory();
  114.         $paramBag['brand'] = $product->getManufacturer();
  115.         $paramBag['search'] = false;
  116.         $paramBag['file'] = $file;
  117.         $paramBag['fileExists'] = $fileExists;
  118.         $paramBag['isMecstoreUser'] =  false;
  119.         //track segments for personalization
  120.         $segmentTrackingHelperService->trackSegmentsForProduct($product);
  121.         $trackingManager $ecommerceFactory->getTrackingManager();
  122.         $trackingManager->trackProductView($product);
  123.         $salesRepesentative = [];
  124.         $manufacturer $product->getManufacturer();
  125.         if($manufacturer){
  126.             $sales $manufacturer->getSalesRepesentative();
  127.             if($sales)
  128.             {
  129.                 $count 0;
  130.                 foreach($sales as $key=>$sale){
  131.                     $salesRepesentative[$count]['Name'] = $sale['Name']->getData().' ('.$sale['Area']->getData().')';
  132.                     $salesRepesentative[$count]['PhoneNo'] = $sale['PhoneNo']->getData();
  133.                     $count++;
  134.                 }
  135.             }
  136.             $salesRepesentative $input array_map("unserialize"array_unique(array_map("serialize"$salesRepesentative)));
  137.         }
  138.         $paramBag['sales_representative'] = $salesRepesentative;
  139.         $paramBag['crossselling_products'] = $product->getCrossSelling();
  140.        // $_SERVER['HTTP_REFERER'] ="";
  141.         if(isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'],'shop-by-brand') !== false){
  142.             return $this->render('product_b2c/detail_brand.html.twig'$paramBag);
  143.         }
  144.         else if(isset($_SERVER['HTTP_REFERER']) &&  strpos($_SERVER['HTTP_REFERER'],'ovunque') !== false){
  145.             $paramBag['search'] = true;
  146.             return $this->render('product_b2c/detail.html.twig'$paramBag);
  147.         }
  148.         else{
  149.             return $this->render('product_b2c/detail.html.twig'$paramBag);
  150.         }
  151.     }
  152.     /**
  153.      * @Route("/b2c/shop/{categoryname}~c{category}", name="b2c-shop-category")
  154.      *
  155.      * @param Request $request
  156.      * @param HeadTitle $headTitleHelper
  157.      * @param BreadcrumbHelperService $breadcrumbHelperService
  158.      * @param Factory $ecommerceFactory
  159.      * @param SegmentTrackingHelperService $segmentTrackingHelperService
  160.      * @param ListHelper $listHelper
  161.      *
  162.      * @return Response
  163.      */
  164.     public function listingAction(Request $requestHeadTitle $headTitleHelperBreadcrumbHelperService $breadcrumbHelperServiceFactory $ecommerceFactorySegmentTrackingHelperService $segmentTrackingHelperServiceListHelper $listHelperPaginatorInterface $paginator)
  165.     {
  166.         $masterFilterDefinition Config::getWebsiteConfig()->get('masterFilterDefinition');
  167.         $params array_merge($request->query->all(), $request->attributes->all());
  168.         $params['maxRange'] = 10;
  169.         //Get pricelist name
  170.         $priceListName DEFAULT_PRICELIST_COLUMN;
  171.         //needed to make sure category filter filters for active category
  172.         $params['parentCategoryIds'] = $params['category'] ?? null;
  173.         $category Category::getById($params['category'] ?? null);
  174.         $params['category'] = $category;
  175.         if ($category) {
  176.             $headTitleHelper($category->getName());
  177.             $breadcrumbHelperService->enrichCategoryPage($category);
  178.         }else{
  179.             $category = new \stdClass();
  180.             $category->name "tutto il catalogo";
  181.             $params['category'] = $category;
  182.         }
  183.         $indexService $ecommerceFactory->getIndexService();
  184.         $productListing $indexService->getProductListForCurrentTenant();
  185.         $productListing->addCondition("disabled != 1");
  186.      //p_r(get_class_methods($productListing));exit;
  187.         $params['term'] = isset($params['term'])?$params['term']:"";
  188.         if(isset($params['term'])){
  189.             //p_r($params);
  190.             //p_r('lower(description) LIKE "%'.strtolower($params['term']).'%"');exit;
  191.             if(strtolower($params['term']) != "ovunque"){
  192.                 if($category instanceof \Pimcore\Model\DataObject){
  193.                     if($params['term']){
  194.                         $searchTerms explode(" ",$params['term']);
  195.                         if($searchTerms)
  196.                         {
  197.                             foreach($searchTerms as $term)
  198.                             {
  199.                                 $productListing->addCondition("searchelem LIKE '%".$term."%' AND categoryIds LIKE '%".$category->getId()."%'");
  200.                             }
  201.                         }
  202.                     }else{
  203.                         $productListing->addCondition("categoryIds LIKE '%".$category->getId()."%'");
  204.                     }
  205.                 }else{
  206.                     if(is_object($category)){
  207.                         if($category->name == "tutto il catalogo"){
  208.                             $filterDefinition $masterFilterDefinition;
  209.                             $category->name "RICERCA";
  210.                         }
  211.                     }
  212.                    // echo "(lower(description) LIKE '".strtolower($params['term'])."%' OR lower(name) LIKE '".strtolower($params['term'])."%' )";exit;
  213.                     if($params['term']){
  214.                         $searchTerms explode(" ",$params['term']);
  215.                         if($searchTerms)
  216.                         {
  217.                             foreach($searchTerms as $term)
  218.                             {
  219.                                 $productListing->addCondition("searchelem LIKE '%".$term."%'");
  220.                             }
  221.                         }
  222.                     }
  223.                 }
  224.             }
  225.             else if($category)
  226.             {
  227.                 $productListing->addCondition("categories LIKE '%".$category->getId()."%'");
  228.             }
  229.         }
  230.          $productListing->setOrderKey('o_id');
  231.          $productListing->setOrder('asc');
  232.         if(isset($params['orderby'])){
  233.            // p_r($params['orderby']);exit;
  234.             if($params['orderby'] == "price")
  235.             {
  236.                 $productListing->setOrderKey($priceListName);
  237.                 $productListing->setOrder('asc');
  238.             }else if($params['orderby'] == "price-desc"){
  239.                 $productListing->setOrderKey($priceListName);
  240.                 $productListing->setOrder('DESC');
  241.             }else if($params['orderby'] == "date"){
  242.                 $productListing->setOrderKey('o_id');
  243.                 $productListing->setOrder('DESC');
  244.             }else if($params['orderby'] == "popularity"){
  245.                 // $productListing->setOrderKey('price');
  246.                 // $productListing->setOrder('DESC');
  247.             }
  248.         }else{
  249.             $params['orderby'] = "o_id";
  250.         }
  251.         $params['productListing'] = $productListing;
  252.         // load current filter
  253.         if ($category instanceof \Pimcore\Model\DataObject) {
  254.             $filterDefinition $category->getFilterdefinition();
  255.             //track segments for personalization
  256.             $segmentTrackingHelperService->trackSegmentsForCategory($category);
  257.             $trackingManager $ecommerceFactory->getTrackingManager();
  258.             $trackingManager->trackCategoryPageView($category->getName(), null);
  259.         }
  260.         if ($request->get('filterdefinition') instanceof FilterDefinition) {
  261.             $filterDefinition $request->get('filterdefinition');
  262.         }
  263.         if (empty($filterDefinition)) {
  264.             $filterDefinition Config::getWebsiteConfig()->get('fallbackFilterdefinition');
  265.         }
  266.         $filterService $ecommerceFactory->getFilterService();
  267.         // Get Max price
  268.         $maxPriceList = clone $productListing;
  269.         $maxParam $params;
  270.         unset($maxParam['page']);
  271.         //p_r($maxPriceList);exit;
  272.         $listHelper->setupProductList($filterDefinition$maxPriceList$maxParam$filterServicetrue);
  273.         $maxPriceList->setOrderKey($priceListName);
  274.         $maxPriceList->setOrder('desc');
  275.         $maxPriceList->setLimit(1);
  276.         $maxPriceItems $maxPriceList->load();
  277.         if($maxPriceItems){
  278.             $getter "getPrice";
  279.             $params['maxRange'] = (int)$maxPriceItems[0]->$getter() +1;
  280.         }
  281.         $listHelper->setupProductList($filterDefinition$productListing$params$filterServicetrue);
  282.         //p_);
  283.         $params['filterService'] = $filterService;
  284.         $params['filterDefinition'] = $filterDefinition;
  285.         //$
  286.         /** @var SlidingPagination $paginator */
  287.         // init pagination
  288.         $pagelimit $request->get('limit'24);
  289.         $paginator $paginator->paginate(
  290.             $productListing,
  291.             $request->get('page'1),
  292.             ($pagelimit)?$pagelimit:24
  293.         );
  294.        // p_r(get_class_methods($paginator));exit;
  295.         $params['results'] = $paginator;
  296.         $params['paginationVariables'] = $paginator->getPaginationData();
  297.         $params['totalCount'] = $paginator->getTotalItemCount();
  298.         $params['offset'] = $paginator->getCurrentPageNumber();
  299.         $params['limit'] =  $pagelimit;
  300.         $params['isMecstoreUser'] =  false;
  301.         if ($request->attributes->get('noLayout')) {
  302.             return $this->render('product_b2c/listing_content.html.twig'$params);
  303.         }
  304.         // track product impressions
  305.         $trackingManager $ecommerceFactory->getTrackingManager();
  306.         foreach ($paginator as $product) {
  307.             $trackingManager->trackProductImpression($product'grid');
  308.         }
  309.         //p_r($params);exit;
  310.         return $this->render('product_b2c/listing.html.twig'$params);
  311.     }
  312.     /**
  313.      * @Route("/b2c/brand/{brandname}~c{brand}", name="b2c-brand")
  314.      *
  315.      * @param Request $request
  316.      * @param HeadTitle $headTitleHelper
  317.      * @param BreadcrumbHelperService $breadcrumbHelperService
  318.      * @param Factory $ecommerceFactory
  319.      * @param SegmentTrackingHelperService $segmentTrackingHelperService
  320.      * @param ListHelper $listHelper
  321.      *
  322.      * @return Response
  323.      */
  324.     public function brandsDetailAction(Request $requestHeadTitle $headTitleHelperBreadcrumbHelperService $breadcrumbHelperServiceFactory $ecommerceFactorySegmentTrackingHelperService $segmentTrackingHelperServiceListHelper $listHelperPaginatorInterface $paginator)
  325.     {
  326.         $params array_merge($request->query->all(), $request->attributes->all());
  327.         $params['maxRange'] = 10;
  328.         //Get pricelist name
  329.         $priceListName DEFAULT_PRICELIST_COLUMN;
  330.         // if($user){
  331.         //     $partner = $user->getPartner();
  332.         //     if($partner){
  333.         //         //$priceListName = $partner->getPriceList();
  334.         //     }
  335.         // }
  336.         //needed to make sure category filter filters for active category
  337.         $params['parentCategoryIds'] = $params['category'] ?? null;
  338.         $brand Manufacturer::getById($params['brand'] ?? null);
  339.         $params['manufacturer'] = $brand;
  340.         if ($brand) {
  341.             $headTitleHelper($brand->getName());
  342.         }else{
  343.             $brand = new \stdClass();
  344.             $brand->name "tutto il catalogo";
  345.             $params['manufacturer'] = $brand;
  346.         }
  347.         $indexService $ecommerceFactory->getIndexService();
  348.         $productListing $indexService->getProductListForCurrentTenant();
  349.         $productListing->addCondition("disabled != 1");
  350.         $params['term'] = isset($params['term'])?$params['term']:"";
  351.         if(isset($params['term'])){
  352.             $brandName $brand->getName();
  353.             //p_r($params);
  354.             //p_r('lower(description) LIKE "%'.strtolower($params['term']).'%"');exit;
  355.             if(strtolower($params['term']) != "ovunque"){
  356.                 //echo "searchelem LIKE '%".$brandName."%' OR lower(searchelem) LIKE '".strtolower($params['term'])."%'";exit;
  357.                 if($params['term'])
  358.                 {
  359.                     $productListing->addCondition("manufacturer_name LIKE '%".$brandName."%' AND lower(searchelem) LIKE '%".strtolower($params['term'])."%'");
  360.                 }else{
  361.                     $productListing->addCondition("searchelem LIKE '%".$brandName."%'");
  362.                 }
  363.             }else
  364.             {
  365.                 $productListing->addCondition("searchelem LIKE '%".$brandName."%'");
  366.             }
  367.         }
  368.         // $productListing->setOrderKey('o_id');
  369.         // $productListing->setOrder('asc');
  370.         if(isset($params['orderby'])){
  371.            // p_r($params['orderby']);exit;
  372.             if($params['orderby'] == "price")
  373.             {
  374.                 $productListing->setOrderKey($priceListName);
  375.                 $productListing->setOrder('asc');
  376.             }else if($params['orderby'] == "price-desc"){
  377.                 $productListing->setOrderKey($priceListName);
  378.                 $productListing->setOrder('DESC');
  379.             }else if($params['orderby'] == "date"){
  380.                 $productListing->setOrderKey('o_id');
  381.                 $productListing->setOrder('DESC');
  382.             }else if($params['orderby'] == "popularity"){
  383.                 // $productListing->setOrderKey('price');
  384.                 // $productListing->setOrder('DESC');
  385.             }
  386.         }else{
  387.             $productListing->setOrderKey('manufacturer_name = "'.$brandName.'"');
  388.             $productListing->setOrder('DESC');
  389.             $params['orderby'] = "manufacturer_name";
  390.         }
  391.         $params['productListing'] = $productListing;
  392.         $filterDefinition Config::getWebsiteConfig()->get('manufacturerFilterdefinition');
  393.         $filterService $ecommerceFactory->getFilterService();
  394.         // Get Max price
  395.         $maxPriceList = clone $productListing;
  396.         $maxParam $params;
  397.         unset($maxParam['page']);
  398.         // p_r($maxParam);
  399.         // p_r($filterDefinition);
  400.         // p_r($maxPriceList);
  401.         // p_r($filterService);exit;
  402.         $listHelper->setupProductList($filterDefinition$maxPriceList$maxParam$filterServicetrue);
  403.         $maxPriceList->setOrderKey($priceListName);
  404.         $maxPriceList->setOrder('desc');
  405.         $maxPriceList->setLimit(1);
  406.         $maxPriceItems $maxPriceList->load();
  407.         if($maxPriceItems){
  408.             $params['maxRange'] = $maxPriceItems[0]->getPrice()+1;
  409.         }
  410.         //p_r($params);exit;
  411.         $listHelper->setupProductList($filterDefinition$productListing$params$filterServicetrue);
  412.         $params['filterService'] = $filterService;
  413.         $params['filterDefinition'] = $filterDefinition;
  414.        // p_r(get_class_methods($productListing));exit;
  415.         //$
  416.         /** @var SlidingPagination $paginator */
  417.         // init pagination
  418.         $pagelimit $request->get('limit'12);
  419.         $paginator $paginator->paginate(
  420.             $productListing,
  421.             $request->get('page'1),
  422.             ($pagelimit)?$pagelimit:12
  423.         );
  424.        // p_r(get_class_methods($paginator));exit;
  425.         $params['results'] = $paginator;
  426.         $params['paginationVariables'] = $paginator->getPaginationData();
  427.         $params['totalCount'] = $paginator->getTotalItemCount();
  428.         $params['offset'] = $paginator->getCurrentPageNumber();
  429.         $params['limit'] =  $pagelimit;
  430.         $params['brandObj'] =  $brand;
  431.         $params['isMecstoreUser'] =  false;
  432.         if ($request->attributes->get('noLayout')) {
  433.             return $this->render('product/listing_content_brand.html.twig'$params);
  434.         }
  435.         // track product impressions
  436.         $trackingManager $ecommerceFactory->getTrackingManager();
  437.         foreach ($paginator as $product) {
  438.             $trackingManager->trackProductImpression($product'grid');
  439.         }
  440.         //p_r($params);exit;
  441.         return $this->render('product_b2c/shop-in-shop_b2c.html.twig'$params);
  442.     }
  443.     /**
  444.      * @Route("/b2c/shop-by-brand/{brandname}~c{brand}", name="b2c-shop-brand")
  445.      *
  446.      * @param Request $request
  447.      * @param HeadTitle $headTitleHelper
  448.      * @param BreadcrumbHelperService $breadcrumbHelperService
  449.      * @param Factory $ecommerceFactory
  450.      * @param SegmentTrackingHelperService $segmentTrackingHelperService
  451.      * @param ListHelper $listHelper
  452.      *
  453.      * @return Response
  454.      */
  455.     public function listingBrandsAction(Request $requestHeadTitle $headTitleHelperBreadcrumbHelperService $breadcrumbHelperServiceFactory $ecommerceFactorySegmentTrackingHelperService $segmentTrackingHelperServiceListHelper $listHelperPaginatorInterface $paginator)
  456.     {
  457.         $params array_merge($request->query->all(), $request->attributes->all());
  458.         $params['maxRange'] = 10;
  459.         //Get pricelist name
  460.         $priceListName DEFAULT_PRICELIST_COLUMN;
  461.         // if($user){
  462.         //     $partner = $user->getPartner();
  463.         //     if($partner){
  464.         //         //$priceListName = $partner->getPriceList();
  465.         //     }
  466.         // }
  467.         //needed to make sure category filter filters for active category
  468.         $params['parentCategoryIds'] = $params['category'] ?? null;
  469.         $brand Manufacturer::getById($params['brand'] ?? null);
  470.         $params['manufacturer'] = $brand;
  471.         if ($brand) {
  472.             $headTitleHelper($brand->getName());
  473.         }else{
  474.             $brand = new \stdClass();
  475.             $brand->name "tutto il catalogo";
  476.             $params['manufacturer'] = $brand;
  477.         }
  478.         $indexService $ecommerceFactory->getIndexService();
  479.         $productListing $indexService->getProductListForCurrentTenant();
  480.         $productListing->addCondition("disabled != 1");
  481.         $params['term'] = isset($params['term'])?$params['term']:"";
  482.         if(isset($params['term'])){
  483.             $brandName $brand->getName();
  484.             //p_r($params);
  485.             //p_r('lower(description) LIKE "%'.strtolower($params['term']).'%"');exit;
  486.             if(strtolower($params['term']) != "ovunque"){
  487.                 //echo "searchelem LIKE '%".$brandName."%' OR lower(searchelem) LIKE '".strtolower($params['term'])."%'";exit;
  488.                 if($params['term'])
  489.                 {
  490.                     $productListing->addCondition("manufacturer_name LIKE '%".$brandName."%' AND lower(searchelem) LIKE '%".strtolower($params['term'])."%'");
  491.                 }else{
  492.                     $productListing->addCondition("manufacturer_name LIKE '%".$brandName."%'");
  493.                 }
  494.             }else
  495.             {
  496.                 $productListing->addCondition("searchelem LIKE '%".$brandName."%'");
  497.             }
  498.         }
  499.         // $productListing->setOrderKey('o_id');
  500.         // $productListing->setOrder('asc');
  501.         if(isset($params['orderby'])){
  502.            // p_r($params['orderby']);exit;
  503.             if($params['orderby'] == "price")
  504.             {
  505.                 $productListing->setOrderKey($priceListName);
  506.                 $productListing->setOrder('asc');
  507.             }else if($params['orderby'] == "price-desc"){
  508.                 $productListing->setOrderKey($priceListName);
  509.                 $productListing->setOrder('DESC');
  510.             }else if($params['orderby'] == "date"){
  511.                 $productListing->setOrderKey('o_id');
  512.                 $productListing->setOrder('DESC');
  513.             }else if($params['orderby'] == "popularity"){
  514.                 // $productListing->setOrderKey('price');
  515.                 // $productListing->setOrder('DESC');
  516.             }
  517.         }else{
  518.             $productListing->setOrderKey('manufacturer_name = "'.$brandName.'"');
  519.             $productListing->setOrder('DESC');
  520.             $params['orderby'] = "manufacturer_name";
  521.         }
  522.         $params['productListing'] = $productListing;
  523.         $filterDefinition Config::getWebsiteConfig()->get('manufacturerFilterdefinition');
  524.         $filterService $ecommerceFactory->getFilterService();
  525.         // Get Max price
  526.         $maxPriceList = clone $productListing;
  527.         $maxParam $params;
  528.         unset($maxParam['page']);
  529.         // p_r($maxParam);
  530.         // p_r($filterDefinition);
  531.         // p_r($maxPriceList);
  532.         // p_r($filterService);exit;
  533.         $listHelper->setupProductList($filterDefinition$maxPriceList$maxParam$filterServicetrue);
  534.         $maxPriceList->setOrderKey($priceListName);
  535.         $maxPriceList->setOrder('desc');
  536.         $maxPriceList->setLimit(1);
  537.         $maxPriceItems $maxPriceList->load();
  538.         if($maxPriceItems){
  539.             $params['maxRange'] = $maxPriceItems[0]->getPrice()+1;
  540.         }
  541.         //p_r($params);exit;
  542.         $listHelper->setupProductList($filterDefinition$productListing$params$filterServicetrue);
  543.         $params['filterService'] = $filterService;
  544.         $params['filterDefinition'] = $filterDefinition;
  545.        // p_r(get_class_methods($productListing));exit;
  546.         //$
  547.         /** @var SlidingPagination $paginator */
  548.         // init pagination
  549.         $pagelimit $request->get('limit'12);
  550.         $paginator $paginator->paginate(
  551.             $productListing,
  552.             $request->get('page'1),
  553.             ($pagelimit)?$pagelimit:12
  554.         );
  555.        // p_r(get_class_methods($paginator));exit;
  556.         $params['results'] = $paginator;
  557.         $params['paginationVariables'] = $paginator->getPaginationData();
  558.         $params['totalCount'] = $paginator->getTotalItemCount();
  559.         $params['offset'] = $paginator->getCurrentPageNumber();
  560.         $params['limit'] =  $pagelimit;
  561.         $params['brandObj'] =  $brand;
  562.         $params['isMecstoreUser'] =  false;
  563.         if ($request->attributes->get('noLayout')) {
  564.             return $this->render('product/listing_content_brand.html.twig'$params);
  565.         }
  566.         // track product impressions
  567.         $trackingManager $ecommerceFactory->getTrackingManager();
  568.         foreach ($paginator as $product) {
  569.             $trackingManager->trackProductImpression($product'grid');
  570.         }
  571.         //p_r($params);exit;
  572.         return $this->render('product_b2c/shop-in-shop_b2c_listing.html.twig'$params);
  573.     }
  574.     /**
  575.      * @param Request $request
  576.      * @param Factory $ecommerceFactory
  577.      *
  578.      * @return Response
  579.      */
  580.     public function productTeaserAction(Request $requestFactory $ecommerceFactory)
  581.     {
  582.         $paramsBag = [];
  583.         if ($request->get('type') == 'object') {
  584.             AbstractObject::setGetInheritedValues(true);
  585.             $product AbstractProduct::getById($request->get('id'));
  586.             $paramsBag['product'] = $product;
  587.             $paramsBag['backend'] = true;
  588.             //track product impression
  589.             $trackingManager $ecommerceFactory->getTrackingManager();
  590.             $trackingManager->trackProductImpression($product'teaser');
  591.             return $this->render('product_b2c/product_teaser.html.twig'$paramsBag);
  592.         }
  593.         throw new NotFoundHttpException('Product not found.');
  594.     }
  595.     /**
  596.      * @Route("/b2c/search", name="b2c-search")
  597.      *
  598.      * @param Request $request
  599.      * @param ListHelper $listHelper
  600.      * @param Factory $ecommerceFactory
  601.      * @param ProductLinkGenerator $productLinkGenerator
  602.      * @param Translator $translator
  603.      * @param BreadcrumbHelperService $breadcrumbHelperService
  604.      * @param HeadTitle $headTitleHelper
  605.      * @param Placeholder $placeholder
  606.      *
  607.      * @return Response|JsonResponse
  608.      */
  609.     public function searchAction(Request $requestListHelper $listHelperFactory $ecommerceFactoryProductLinkGenerator $productLinkGeneratorTranslator $translatorBreadcrumbHelperService $breadcrumbHelperServiceHeadTitle $headTitleHelperPlaceholder $placeholderPaginatorInterface $paginator)
  610.     {
  611.        // die('sddsd');
  612.         $params $request->query->all();
  613.         $params['category'] = Category::getById($params['category'] ?? null);
  614.         $indexService $ecommerceFactory->getIndexService();
  615.         $productListing $indexService->getProductListForCurrentTenant();
  616.         $productListing->setVariantMode(ProductListInterface::VARIANT_MODE_VARIANTS_ONLY);
  617.         $term strip_tags($request->get('term'));
  618.         if($productListing instanceof AbstractElasticSearch) {
  619.             // simple elastic search query - uses multi-match query on all defined search_attributes
  620. //            $productListing->addQueryCondition($term);
  621.             //sample for a more specific elastic search query - not considers search_attributes but provides full flexibility
  622.             // this query weights cars more that accessories
  623.             $query = [
  624.                 'function_score' => [
  625.                     'query' => [
  626.                         'multi_match' => [
  627.                             "query" => $term,
  628.                             "type" => "cross_fields",
  629.                             "operator" => "and",
  630.                             "fields" => [
  631.                                 "attributes.name^4",
  632.                                 "attributes.name.analyzed",
  633.                                 "attributes.name.analyzed_ngram",
  634.                                 "attributes.manufacturer_name^3",
  635.                                 "attributes.manufacturer_name.analyzed",
  636.                                 "attributes.manufacturer_name.analyzed_ngram",
  637.                                 "attributes.color",
  638.                                 "attributes.color.analyzed",
  639.                                 "attributes.color.analyzed_ngram",
  640.                                 "attributes.carClass",
  641.                                 "attributes.carClass.analyzed",
  642.                                 "attributes.carClass.analyzed_ngram"
  643.                             ]
  644.                         ]
  645.                     ],
  646.                     'functions' => [
  647.                         [
  648.                             'filter' => ['match' => ['system.o_classId' => 'AP']],
  649.                             'weight' => 1
  650.                         ],
  651.                         [
  652.                             'filter' => ['match' => ['system.o_classId' => 'CAR']],
  653.                             'weight' => 2
  654.                         ]
  655.                     ],
  656.                     'boost_mode' => 'multiply'
  657.                 ]
  658.             ];
  659.             $productListing->addQueryCondition($query'searchTerm');
  660.         } else {
  661.             //default mysql search query condition - would also work for elastic search in that way
  662.             $term trim(preg_replace('/\s+/'' '$term));
  663.             if (!empty($term)) {
  664.                 foreach (explode(' '$term) as $t) {
  665.                     $productListing->addQueryCondition($t);
  666.                 }
  667.             }
  668.         }
  669.         if (isset($params['autocomplete'])) {
  670.             $resultset = [];
  671.             $productListing->setLimit(10);
  672.             foreach ($productListing as $product) {
  673.                 $result['href'] = $productLinkGenerator->generateWithMockup($product, []);
  674.                 if ($product instanceof Car) {
  675.                     $result['product'] = $product->getOSName() . ' ' $product->getColor()[0] . ', ' $product->getCarClass();
  676.                 } else {
  677.                     $result['product'] = $product->getOSName();
  678.                 }
  679.                 $resultset[] = $result;
  680.             }
  681.             return $this->json($resultset);
  682.         }
  683.         $filterDefinition $params['filterDefinition'] = Config::getWebsiteConfig()->get('fallbackFilterdefinition');
  684.         // create and init filter service
  685.         $filterService Factory::getInstance()->getFilterService();
  686.         $listHelper->setupProductList($filterDefinition$productListing$params$filterServicetrue);
  687.         $params['filterService'] = $filterService;
  688.         $params['products'] = $productListing;
  689.         // init pagination
  690.         $paginator $paginator->paginate(
  691.             $productListing,
  692.             $request->get('page'1),
  693.             $filterDefinition->getPageLimit()
  694.         );
  695.         $params['results'] = $paginator;
  696.         $params['paginationVariables'] = $paginator->getPaginationData();
  697.         $trackingManager $ecommerceFactory->getTrackingManager();
  698.         foreach ($paginator as $product) {
  699.             $trackingManager->trackProductImpression($product'search-results');
  700.         }
  701.         //breadcrumbs
  702.         $placeholder('addBreadcrumb')->append([
  703.             'parentId' => $this->document->getId(),
  704.             'id' => 'search-result',
  705.             'label' => $translator->trans('shop.search-result', [$term])
  706.         ]);
  707.         $params['language'] = $request->getLocale();
  708.         $params['term'] = $term;
  709.         $breadcrumbHelperService->enrichGenericDynamicPage($translator->trans('shop.search-result', [$term]));
  710.         $headTitleHelper($translator->trans('shop.search-result', [$term]));
  711.         return $this->render('product_b2c/search.html.twig'$params);
  712.     }
  713.     private function getProductsInWishList($user){
  714.         $products = new \Pimcore\Model\DataObject\Wishlist\Listing();
  715.         $products->setCondition('user__id = ?',[$user->getId()]);
  716.         return $products->getCount();
  717.     }
  718. }