src/project/OfficeBrain/CustomBundle/SearchBundle/Controller/BrowseCategoryController.php line 164

Open in your IDE?
  1. <?php
  2. namespace App\project\OfficeBrain\CustomBundle\SearchBundle\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  4. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  5. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  6. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\RequestStack;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use App\OfficeBrain\Bundle\SearchBundle\Controller\BrowseCategoryController as BaseBrowseCategoryController;
  11. use App\OfficeBrain\Bundle\SearchBundle\Form\Data\ProductSearchData;
  12. use App\OfficeBrain\Bundle\CoreBundle\Cache\RedisCacheService;
  13. use App\project\OfficeBrain\CustomBundle\SearchBundle\Form\Type\ProductSearchType;
  14. use Symfony\Component\DependencyInjection\ContainerInterface as Container;
  15. use Doctrine\ORM\EntityManagerInterface;
  16. use App\OfficeBrain\Bundle\SearchBundle\Manager\Service\SearchManager;
  17. use App\OfficeBrain\Bundle\ProductBundle\Manager\Service\ProductDetailService;
  18. use App\OfficeBrain\Bundle\CategoryBundle\Manager\ApiManager as CategoryApiManager;
  19. use App\OfficeBrain\Bundle\CoreBundle\Service\SessionManager;
  20. use Knp\Component\Pager\PaginatorInterface;
  21. use App\OfficeBrain\Bundle\SearchBundle\Manager\Extended\SolrSearchExtended;
  22. use App\OfficeBrain\Bundle\SearchBundle\Manager\Extended\BrowseCategoryExtended;
  23. use App\OfficeBrain\Bundle\ProductBundle\ApiClient\ProductApiClient;
  24. use App\OfficeBrain\Bundle\SearchBundle\Manager\Service\BrowseCategoryManager;
  25. use App\OfficeBrain\Bundle\CmsBundle\Manager\Service\CmsMenuService;
  26. use App\project\OfficeBrain\CustomBundle\ProductBundle\Manager\Service\ProductDetailService as CustomProductDetailService;
  27. use App\OfficeBrain\Bundle\ProductTagBundle\Manager\Service\ProductTagManager;
  28. class BrowseCategoryController extends BaseBrowseCategoryController
  29. {
  30.     protected $request;
  31.     /**
  32.      *
  33.      * @author Employee Id: 4488
  34.      *
  35.      * To set member variables default value
  36.      *
  37.      * @return NULL
  38.      *
  39.      */
  40.     public function __construct(EntityManagerInterface $entityManagerRequestStack $requestSearchManager $solrManagerCategoryApiManager $categoryManagerSessionManager $sessionManagerPaginatorInterface $paginatorManagerContainer $serviceContainerBrowseCategoryManager $browserCategoryManagerProductDetailService $productDetailServiceCustomProductDetailService $customProductDetailManagerCmsMenuService $cmsMenuServiceProductTagManager $productTagManager)
  41.     {
  42.         parent::__construct($entityManager$request$solrManager$categoryManager$sessionManager$paginatorManager$serviceContainer$browserCategoryManager$productDetailService$customProductDetailManager);
  43.         $this->statsh_cache_wrapper=RedisCacheService::create();
  44.         $this->browserCategoryManager $browserCategoryManager->getBrowserCategoryExtended();
  45.         $this->cmsMenuService $cmsMenuService->getCmsMenuExtended();
  46.         $this->productTagManager $productTagManager->getProductTagManagerExtended();
  47.     }
  48.     /**
  49.      *
  50.      * @author Employee Id: 4488
  51.      * To Initialize the member variables
  52.      *
  53.      * @return NULL
  54.      */
  55.     public function initAction(Request $request)
  56.     {
  57.         parent::initAction($request);
  58.         // $this->productDetailManager = $this->get('office_brain_product_detail_manager_custom'); // symfony 4
  59.         $this->request $request;
  60.         // $this->searchManager = $this->get('office_brain_custom_bundle_search_manager'); // symfony 4
  61.         $this->searchManager $this->searchManager;
  62.         $this->twigManager $this->serviceContainer->get('twig');
  63.         
  64.     }
  65.     /**
  66.      * @author Employee Id: 4488
  67.      *
  68.      * Browse by Menu Tag and sub category
  69.      *
  70.      * @param string category slug
  71.      *
  72.      * @return if result found return sub category list and Product tag  else  null
  73.      *
  74.      * @Route("/{_locale}/browse-sub-category/{category_slug}", name="office_brain_search_bundle_browse_sub_category", options={"expose"=true})
  75.       
  76.      * @Method({"GET"})
  77.      *
  78.      * @Template("project/OfficeBrain/CustomBundle/SearchBundle/BrowseCategory/browseSubCategory.html.twig")
  79.      */
  80.     public function browseSubCategoryAction(Request $request)
  81.     {
  82.         $this->initAction($request);
  83.         // $categoryObj = $this->serviceContainer->get('office_brain_browse_category_extended');
  84.         $categoryObj $this->browserCategoryManager;
  85.         // $menuItemObj = $this->serviceContainer->get('office_brain_cms_menu_extended');
  86.         $menuItemObj $this->cmsMenuService;
  87.         // $productTagObj=$this->serviceContainer->get('office_brain_private_tag_extended');
  88.         $productTagObj $this->productTagManager;
  89.         $categorySlug $this->request->get('category_slug');
  90.         $categoryId $categoryObj->getCategoryIdFromSlug($categorySlug);
  91.         $this->responseArray['category_list']=array();
  92.         if($categoryId>0)
  93.         {
  94.             
  95.             /*
  96.              * menu Tag And sub category  
  97.              */
  98.             $tagArray=$menuItemObj->getTagListFromCmsMenu($categoryId);
  99.             $menu_category=array();
  100.             if(count($tagArray)>0)
  101.             {
  102.                 foreach ($tagArray as $cat){
  103.                     if($cat['menutype']=='product-category')
  104.                         $menu_category['category'][]=$cat['id'];
  105.                     else
  106.                         $menu_category['category'][]=null;
  107.                     if($cat['menutype']=='product-tag')
  108.                         $menu_category['tag'][]=$cat['id'];
  109.                     else
  110.                         $menu_category['tag'][]=null;
  111.                 }
  112.                 if(count($menu_category['category'])>0)
  113.                 {
  114.                     // Commented by 4248
  115. //                     /$this->responseArray['category_list'] = $categoryObj->getCategoryNameFromId($menu_category['category']);                    
  116.                 }    
  117.                 if(count($menu_category['tag'])>0)
  118.                 {
  119.                     $productTagData=$productTagObj->getProductTagList($menu_category['tag']);
  120.                     if(count($productTagData)>0)
  121.                         $this->responseArray['product_tag_list']=$productTagData;
  122.                 }
  123.             }
  124.             /*
  125.              *Get Sub Category List
  126.              * 
  127.              * */
  128.              
  129.             $subCategoryList=array();
  130.             $subCategoryList $categoryObj->getSubCategoryList($categoryId);
  131.             if(isset($subCategoryList['parent'])){
  132.                 $this->responseArray['parent_category_info'] = $subCategoryList['parent'];
  133.             }
  134.             $this->responseArray['category_name']=$subCategoryList['name'];
  135.             array_push($this->responseArray['category_list'],$subCategoryList);
  136.         }
  137.         else
  138.         {
  139.             $slug=parent::create_slug($categorySlug);
  140.             $this->responseArray['product_tag_list']=$productTagObj->getTagIdFromSlug($slug);
  141.             $this->responseArray['category_name']=$slug;
  142.         }
  143.         return $this->responseArray;
  144.     }
  145.     
  146.     /**
  147.      * @author Employee Id: 410175
  148.      *
  149.      * Product listing accordingly parent category
  150.      *
  151.      * @param string category id
  152.      *
  153.      * @return if result found return category products else null
  154.      *
  155.      * @Route("/{_locale}/category-product-list/{category_slug}", name="office_brain_search_bundle_category_product_list", options={"expose"=true})
  156.      *
  157.      * @Method({"GET"})
  158.      *
  159.      * @Template("OfficeBrain/Bundle/SearchBundle/BrowseCategory/browseCategoryPage.html.twig")
  160.      */
  161.     public function categoryProductListAction(Request $request)
  162.     {
  163.         $this->initAction($request);
  164.          
  165.         $this->responseArray = array();
  166.         $youFirstChidrenCat = array();
  167.         $youFirstMatchCat = array(); // this is match side filter with all category of you first
  168.         
  169.         //youfirst Logic   
  170.         // this is for you first and child category array
  171.         $cateogryApiManager$this->serviceContainer->get("officebrain_category_api_manager");
  172.         $youFistcatId 16115;
  173.         $youFirstChidrenCat $cateogryApiManager->getChildrenCatByCatId($youFistcatId);
  174.         $youFirstChidrenCatarray_column($youFirstChidrenCat'pms_id');
  175.         array_push($youFirstChidrenCat,$youFistcatId);
  176.         
  177.         
  178.         
  179. //         echo "<>"print_r($this->responseArray['youFirstChidrenCat'])
  180.         // ---END -----
  181.         $searchQuery $this->searchManager->getSearchArray();
  182.         $categoryFilter $this->request->get('category_filter','');
  183.         $categoryslug $this->request->get('category_slug');
  184.         // $categoryObj = $this->serviceContainer->get('office_brain_category_manager');
  185.         $categoryObj $this->browserCategoryManager// OfficeBrain\Bundle\SearchBundle\Manager\Extended\BrowseCategoryExtended
  186.         $categoryId $categoryObj->getCategoryIdFromSlug($categoryslug);
  187.         //echo $categoryId.'===='.$categoryslug;
  188.         $subCategoryList $categoryObj->getSubCategoryList($categoryId);
  189.         $cultures $this->serviceContainer->getParameter('language');
  190.         $api_manager $this->serviceContainer->get('officebrain_category_api_manager');
  191.         $categoryInfo $api_manager->getCategoryInfoByCategoryId($cultures,$categoryId);
  192.         
  193.         $categoryKeywords = isset($categoryInfo["en"]["keywords"])?explode(",",$categoryInfo["en"]["keywords"]):'';
  194.         //echo $categoryId;exit;
  195.         if($categoryFilter == ''){
  196.             if( isset($subCategoryList['child']) ) {
  197.                 $caregoryArrayarray_keys($subCategoryList['child']);
  198.                 array_push($caregoryArray,(int)$categoryId);
  199.                 $categoryListJson $caregoryArray;
  200.                 // $categoryListJson = json_encode($caregoryArray); // symfony 4
  201. //                 $categoryListJson = json_encode(array_keys($subCategoryList['child']));
  202.             } else {
  203.                 $caregoryArray[] = (int)$categoryId;
  204.                 $categoryListJson $caregoryArray;
  205.                 // $categoryListJson = json_encode($caregoryArray); // symfony 4
  206.             }
  207.         } else {
  208.             $caregoryArray = [];
  209.             $categoryListJson $categoryFilter;
  210.         }
  211.         if($categoryId){
  212.             $catFilterArr $caregoryArray;
  213.             $youFirstMatchCatarray_intersect($catFilterArr,$youFirstChidrenCat);
  214.         }
  215.         //print_r($categoryListJson);exit;
  216.         $this->prepareSearchForm($searchQuery['product_search'],$categoryListJson,$categoryId);
  217.         if ($this->form->isValid()) {
  218.             $this->responseArray $this->searchManager->searchResult($this->form->getData());
  219.             // echo "<pre>"; dump($this->responseArray); exit;
  220.             $this->responseArray['youFirstChidrenCat'] = $youFirstMatchCat;
  221.             if (!$this->request->get('page'null)) {
  222.                 $this->responseArray['search_attribute_filter_array'] = $this->searchManager->searchFilter($this->form->getData());
  223.             }
  224.         }
  225.         /* Rush Category Array */
  226.         $rushCategoriesArray $this->serviceContainer->getParameter('category_page_extra_filter_categories');
  227.         $rushCategoryValues = [];
  228.         if (isset($this->responseArray['search_attribute_filter_array'])) {
  229.             foreach($rushCategoriesArray as $catData){
  230.                 $key array_search($catData['pms_id'], array_column($this->responseArray['search_attribute_filter_array']["parentchildCategoryIdName"], 'id'));
  231.                 if (!empty($key) || $key === 0) {  
  232.                     $rushCategoryValues[$catData['pms_id']] = $this->responseArray['search_attribute_filter_array']["parentchildCategoryIdName"][$key];
  233.                 }
  234.             }
  235.         }
  236.         if(!empty($rushCategoryValues)){
  237.             $this->responseArray['search_attribute_filter_array']['rush_categories'] = $rushCategoryValues;
  238.         }
  239.         /* EO: Rush Category Array */
  240.         if (isset($this->responseArray['search_attribute_filter_array'])) {
  241.             $this->responseArray['search_attribute_filter_array']["parentchildCategoryIdName"] = [$this->filterCat($this->responseArray['search_attribute_filter_array']["parentchildCategoryIdName"],$categoryId)];
  242.         }
  243.         
  244.         // echo $categoryId;
  245.         // -----------------------------------------------------------------------
  246.         $this->responseArray['catname'] = $this->productDetailManager->productDetailBreadcrumbs($categoryId);
  247.         /* Remove Ideas By Market From Category Filter */
  248.         // $allCategoryIds = array_column($this->responseArray['search_attribute_filter_array']['parentchildCategoryIdName'], 'id');
  249.         // $categoryIdsToRemove = $this->container->getParameter('category_remove_from_filter');
  250.         // foreach($categoryIdsToRemove as $catId){
  251.         //     $keyToUnset = array_search ($catId, $allCategoryIds);
  252.         //     if(isset($this->responseArray['search_attribute_filter_array']['parentchildCategoryIdName'][$keyToUnset])){
  253.         //         unset($this->responseArray['search_attribute_filter_array']['parentchildCategoryIdName'][$keyToUnset]);
  254.         //     }
  255.         // }
  256.         /* Remove Ideas By Market From Category Filter */
  257.         
  258.         /* EO - Category Brand Merging */
  259.         if(isset($this->responseArray['search_attribute_filter_array']['publicCustomTagText']) && is_array($this->responseArray['search_attribute_filter_array']['publicCustomTagText'])){
  260.             
  261.             if(!isset($this->responseArray['search_attribute_filter_array']['parentchildCategoryIdName'][0]['values'])){
  262.                 $this->responseArray['search_attribute_filter_array']['parentchildCategoryIdName'][0]['values'] = array();
  263.             }
  264.             $parentCategoryNamesArray array_column($this->responseArray['search_attribute_filter_array']['parentchildCategoryIdName'][0]['values'], 'name');
  265.             
  266.             $brandSlugs = array('barware','circular-cup','dyln','ecovessel','halcyon','hitch','illusion','mag-lites','otaria','pul','reduce','snowfox','stojo','swig','takeya','vinglace','zing-line','mood','microhalt','bindle','hydrapak','made-in-usa','hidratespark','hip','maglite','oceanworks','perfect-shaker','polar-bottle','stojo-1','perf||ma');
  267.             $brandFinalArray = array();
  268.             $count 0;
  269.             foreach($this->responseArray['search_attribute_filter_array']['publicCustomTagText'] as $brandData => $productCount){
  270.                 $brandArray explode('|'$brandData);
  271.                 if(in_array(trim($brandArray[5]), $brandSlugs) && !in_array(trim($brandArray[1]), $parentCategoryNamesArray)){
  272.                     $brandFinalArray[$count]['id'] = trim($brandArray[0]);
  273.                     $brandFinalArray[$count]['name'] = trim($brandArray[1]);
  274.                     $brandFinalArray[$count]['slug'] = trim($brandArray[5]);
  275.                     $brandFinalArray[$count]['count'] = $productCount;
  276.                     $brandFinalArray[$count]['type'] = 'brand';
  277.                     $count++;
  278.                 }
  279.             }
  280.             if(!empty($brandFinalArray)){
  281.                 if(!isset($this->responseArray['search_attribute_filter_array']['parentchildCategoryIdName'][0]['values'])){
  282.                     $this->responseArray['search_attribute_filter_array']['parentchildCategoryIdName'][0]['values'] = array();
  283.                 }
  284.                 $this->responseArray['search_attribute_filter_array']['parentchildCategoryIdName'][0]['values'] = array_merge($this->responseArray['search_attribute_filter_array']['parentchildCategoryIdName'][0]['values'], $brandFinalArray);
  285.                 $categoryData array_column($this->responseArray['search_attribute_filter_array']['parentchildCategoryIdName'][0]['values'], 'name');
  286.                 array_multisort($categoryDataSORT_ASC$this->responseArray['search_attribute_filter_array']['parentchildCategoryIdName'][0]['values']);
  287.             }
  288.         }
  289.         /* EO - Category Brand Merging */
  290.         
  291.         // -----------------------------------------------------------------------
  292.         if (!$this->request->isXmlHttpRequest()) {
  293.             // get IdeasByMarket cat from All search filter cat
  294.             $api_manager $this->serviceContainer->get('officebrain_category_api_manager');
  295.             $dataOfIdeas $api_manager->getIdeasByMarketCat();
  296.             
  297.             $dataOfIdeas_final array_column($dataOfIdeas'pms_id');
  298.             
  299.             if (isset($this->responseArray['search_attribute_filter_array'])) {
  300.                 $this->responseArray['search_attribute_filter_array']['Ideas_by_market_Cat'] = array_filter($this->responseArray['search_attribute_filter_array']['categoryNameId'], function($array) use($dataOfIdeas_final){
  301.                     if (in_array($array['id'], $dataOfIdeas_final)) {
  302.                         return true ;
  303.                     }
  304.                     else{
  305.                         return false;
  306.                     }
  307.                 }
  308.             );
  309.             }
  310.             if (isset($this->responseArray['search_attribute_filter_array'])) {
  311.                 $arr array_filter($this->responseArray['search_attribute_filter_array']['categoryNameId'], function($array) use($dataOfIdeas_final){
  312.                     if (in_array($array['id'], $dataOfIdeas_final)) {
  313.                         return false ;
  314.                     }
  315.                     else{
  316.                         return true;
  317.                     }
  318.                 });
  319.             }
  320.             if (isset($this->responseArray['search_attribute_filter_array'])) {
  321.                 $this->responseArray['search_attribute_filter_array']['categoryNameId'] = $arr;
  322.             }
  323.             /* For Default Category Filter */
  324.             $this->responseArray['is_from_category_page'] = 1;
  325.             $this->responseArray['category_id'] = $categoryId;
  326.                     //                 
  327.             $locale=$this->request->getLocale();
  328.             $search base64_encode(json_encode($searchQuery));
  329.             // $cacheSiteKey = array('SearchFilter',$search,$categoryslug,$locale,$this->instanceId,$this->container->getParameter('kernel.environment')); // symfony 4
  330.             $cacheSiteKey = array('SearchFilter',$search,$categoryslug,$locale,$this->instanceId,$this->projectSetting['kernelEnvironment']);
  331.             $this->moduleCachePrefix='__Search__:';
  332.             $cacheKey $this->moduleCachePrefix.RedisCacheService::generateKey($this->statsh_cache_wrapper,$cacheSiteKey);
  333.             $cacheData RedisCacheService::getCacheData($this->statsh_cache_wrapper,$cacheKey);
  334.             if($cacheData){
  335.                 $this->responseArray['filterHtml']= $cacheData;
  336.             }
  337.             else{
  338.                 // echo "<pre>";print_r($this->responseArray['search_attribute_filter_array']["parentchildCategoryIdName"]);exit;
  339.                 $response $this->twigManager->render('project/OfficeBrain/CustomBundle/SearchBundle/Search/searchAttributeFilterList.html.twig'$this->responseArray);
  340.                 if(!empty($cacheKey))
  341.                 {
  342.                     RedisCacheService::saveCacheData($this->statsh_cache_wrapper,$cacheKey,$response);
  343.                 }
  344.                 $this->responseArray['filterHtml'] = $response;
  345.             }
  346.         }
  347.         
  348.         
  349.         $this->responseArray['sub_category_list'] = $categoryListJson;
  350.         $this->responseArray['breadcrumbs'] = $this->productDetailManager->productDetailBreadcrumbs($categoryId);
  351.         $this->responseArray['search_query'] = $searchQuery['search']['query'];
  352.         $this->responseArray['main_filter'] = $searchQuery['search']['main_filter'];
  353.         $this->responseArray['form'] = $this->form->createView();
  354.         $this->responseArray['Recent_search'] = $this->request->getSession()->get('recent_search');
  355.         $this->responseArray['save_search'] = $this->searchManager->getSaveSearch();
  356.         $recentSearch $this->request->query->get('is_filter','check');
  357.         if($recentSearch == 'check'){
  358.             $this->searchManager->setRecentSearch();
  359.         }
  360.         $this->responseArray['category_breadcrumb']= array($this->translator->trans('breadcrumb_category'),(isset($subCategoryList['name'])?$subCategoryList['name']:''));
  361.         $this->responseArray['category_slug'] = $categoryslug;
  362.         
  363.         $this->responseArray['categoryInfo'] = $categoryInfo;
  364.         $this->responseArray['categoryKeywords'] = $categoryKeywords;
  365.         if( isset($subCategoryList['child']) ) {
  366.             $this->responseArray['sub_category_ids'] = array_keys($subCategoryList['child']);
  367.         }
  368.         
  369. //         $categoryId = 320; // comment because we don't want display advertise on product page
  370.         $this->responseArray['categoryAdvertiseData'] = $this->customProductDetailManager->getAdvertiseForFrontByRefId($categoryId,'category');//type =catwgory
  371.         //print_r($this->responseArray);die('==========');
  372.         
  373.         return $this->responseArray;
  374.     }
  375.     
  376.     private function filterCat($catArr$catId){
  377.         foreach ($catArr as $val){
  378.             if($val["id"] ==  $catId){
  379.                 return $val;
  380.                 break;
  381.             }
  382.             if(array_key_exists("values",$val) && $val["values"]){
  383.                 $returnVal $this->filterCat($val["values"], $catId);
  384.                 if($returnVal){
  385.                     return $returnVal;
  386.                     break;
  387.                 }
  388.                 
  389.             }
  390.         }
  391.         // echo "<pre>";print_r($catArr);die;
  392.     }
  393.     
  394.     private function prepareSearchForm($searchArray,$categoryListJson,$categoryId "") {
  395.         $searchArray['categoryId'] = $categoryListJson;
  396.     
  397.         /* For displaying category order wise*/
  398.          $searchArray['sort'] = array(
  399.             'field' => 'category||sorting_product_by_categoryid_'$categoryId .'_i',
  400.             'order' => 'desc'
  401.          );
  402.         $this->productSearchData = new ProductSearchData($this->entityManager$this->languageId);;
  403.         $this->form $this->createForm(ProductSearchType::class, $this->productSearchData, [
  404.             'csrf_protection' => false,
  405.             'searchData' => $searchArray,
  406.         ]);
  407.             $this->form->submit($searchArray);
  408.         // if (!$this->form->isValid()) {
  409.         //     foreach ($this->form->getErrors(true) as $error) {
  410.         //         $field = $error->getOrigin()->getName(); // Get the field name
  411.         //         $message = $error->getMessage(); // Get the error message
  412.         //         dump("Field: $field, Error: $message");
  413.         //     }
  414.         //     exit;
  415.         // }
  416.     }
  417.     
  418.     /**
  419.      * @author Employee Id: 5429
  420.      *
  421.      * Product listing accordingly parent category
  422.      *
  423.      * @param string category id
  424.      *
  425.      * @return if result found return category products else null
  426.      *
  427.      * @Route("/{_locale}/subcategory-product-list", name="office_brain_search_bundle_subcategory_product_list", options={"expose"=true})
  428.      *
  429.      * @Method({"GET"})
  430.      *
  431.      * @Template()
  432.      */
  433.     public function subCategoryProductPageAction(Request $request)
  434.     {
  435.         $this->initAction($request);
  436.         $recordparpage=1200;
  437.         $searchQuery $this->searchManager->getSearchArray();
  438.         $data $this->request->get('data','');
  439.         $serchtype $this->request->get('search_type','');
  440.         if($serchtype==1)
  441.         {
  442.             $categoryListJson='['.$data.']';
  443.             $this->prepareSearchForm($searchQuery['product_search'],$categoryListJson);
  444.     
  445.         }
  446.         else
  447.         {
  448.             $this->prepareSearchForm($searchQuery['product_search'],'');
  449.         }
  450.         $this->responseArray = array();
  451.         if ($this->form->isValid()) {
  452.             $this->responseArray['productdata'] = $this->searchManager->searchResult($this->form->getData(),'',$recordparpage);
  453.     
  454.         }
  455.         return $this->responseArray;
  456.     }
  457.     
  458.     
  459.     /**
  460.      * @author Employee Id: 5429
  461.      *
  462.      * Download product images.
  463.      *
  464.      *  @param string product sku
  465.      *
  466.      *  @param integer supplier id
  467.      *
  468.      *  @return download product template
  469.      * @Route("/{_locale}/download-imagecontent", name="office_brain_custom_bundle_search_download_image_content", options={"expose"=true})
  470.      *
  471.      * @Method({"GET"})
  472.      *
  473.      * @Template()
  474.      */
  475.     public function downloadImageContentAction(Request $request)
  476.     {
  477.         $this->initAction($request);
  478.         $path $this->request->get('path'null);
  479.         $filename=array_reverse(explode('/',$path));
  480.         $response = new Response();
  481.         $response->headers->set('Content-Disposition','attachment;filename='.$filename[0]);
  482.         $response->headers->set('Content-Type''image/jpg');
  483.         $response->setContent(file_get_contents($path));
  484.         return $response;
  485.     }
  486.     
  487.     /**
  488.      * @Route("/{_locale}/suggested-product-by-category/{categoryId}",
  489.      *     name="office_brain_search_bundle_category_suggested_product_list",
  490.      * )
  491.      * @Template("project/OfficeBrain/CustomBundle/SearchBundle/BrowseCategory/suggestedProduct.html.twig")
  492.      */
  493.     public function getSuggestedProductByCategoryAction(Request $request$categoryId){
  494.         $this->initAction($request);
  495.         $pmsId $categoryId;
  496.         
  497. //         $api_manager = $this->get('officebrain_category_api_manager');
  498. //         $data = $api_manager->getSuggestedProductByCategoryId($pmsId);
  499. //         if($data && count($data['suggestedProducts'])> 0){
  500. //             $result = array();
  501. //             if(count($data['suggestedProducts']))
  502. //             $sku = $data['suggestedProducts'] ;// implode($data['suggestedProducts'], ',');
  503. // //             $sku = $data['suggestedProducts'];//
  504. //             $this->request->query->set('sku',$sku);
  505. //             $this->request->query->set('search_type','exact');
  506. //             // this is for remove By Default soring(which is Price:desc)
  507. //             $this->request->query->set('sort_by', '1');
  508.         $api_manager $this->serviceContainer->get('officebrain_category_api_manager');
  509.         $categoryWiseSuggestedArr $api_manager->getSuggestedProductByCatId($pmsId);
  510.         
  511. //         if(count($categoryWiseSuggestedArr)==0){
  512. //             $categoryWiseSuggestedArr = $api_manager->getSuggestedProductByRelatedCat($pmsId);
  513. //         }
  514.         
  515. //         if( (count($categoryWiseSuggestedArr) == 0)  || ( count($categoryWiseSuggestedArr) && (!$categoryWiseSuggestedArr[0]['suggestedProduct'] || $categoryWiseSuggestedArr[0]['suggestedProduct'] == '0')) ){
  516. //             $categoryWiseSuggestedArr = $api_manager->getSuggestedProductByRelatedCat($pmsId);
  517. //         }
  518. //         $categoryWiseSuggestedArr = $api_manager->getSuggestedProductByRelatedCat($pmsId);
  519.         
  520.         $categoryWiseSuggestedArrarray_column($categoryWiseSuggestedArr'suggestedProduct');
  521.         $suggestedProductData='';
  522. //         print_r($categoryWiseSuggestedArr);
  523.         foreach ($categoryWiseSuggestedArr as $suggProductIdArr){
  524.             if($suggProductIdArr){
  525.                 $suggestedProductData .= ($suggestedProductData ',''' ).$suggProductIdArr;//array_filter - remove blank element
  526.             }            
  527.         }
  528.         $suggestedProductData explode(',',$suggestedProductData);
  529.         $suggestedProductData  array_filter($suggestedProductData); 
  530. //         echo "<pre>";print_r(array_filter($suggestedProductData ));exit;
  531.         if(    $suggestedProductData && count($suggestedProductData)> 0){
  532.         $result = array();
  533.             if(count($suggestedProductData))
  534.                 $sku $suggestedProductData;// implode($data['suggestedProducts'], ',');
  535.             //             $sku = $data['suggestedProducts'];//
  536.             $this->request->query->set('sku',$sku );
  537.             $this->request->query->set('search_type','exact');
  538.             // this is for remove By Default soring(which is Price:desc)
  539.             $this->request->query->set('sort_by''1');
  540.             $this->responseArray $this->searchManager->searchService(true);
  541.             $data=array();
  542.             //$data = $this->site_module->getProduct($criteria);
  543.             #print_r(array_keys((array)$this->responseArray['search_result_array']));
  544.             #echo(array_keys($this->responseArray['search_result_array']));exit;
  545. //             print_r($this->responseArray);exit;
  546.             $data['search_result_array'] = $this->responseArray['search_result_array'];
  547. //             print_r($data['search_result_array']);exit;
  548.             $data['product_box_bootstrap_class']='item';
  549.             $data['render_model']=0;
  550.             //return $this->render('OfficeBrainPageBundle:tempUIElements:recommendProducts.html.twig', $data);
  551.             $response $this->render("project/OfficeBrain/CustomBundle/SearchBundle/BrowseCategory/suggestedProduct.html.twig"$data);
  552.             //             print_r($response);exit;
  553.             //             if(!empty($cacheKey))
  554.             //             {
  555.             //                 RedisCacheService::saveCacheData($this->statsh_cache_wrapper,$cacheKey,$response);
  556.                 //             }
  557.                 return $response;
  558.         }
  559.         else{
  560.             return array();
  561.         }
  562.     }
  563.     
  564.     /**
  565.      * @Route("/{_locale}/trending-product-by-category/{categoryId}",
  566.      *     name="office_brain_search_bundle_category_trending_product_list",
  567.      * )
  568.      * @Template("project/OfficeBrain/CustomBundle/SearchBundle/BrowseCategory/trendingProduct.html.twig")
  569.      */
  570.     public function getTrendingProductByCategoryAction(Request $request$categoryId){
  571.         $this->initAction($request);
  572.         $pmsId $categoryId;
  573.         
  574.         $api_manager $this->serviceContainer->get('officebrain_category_api_manager');
  575.         $categoryWiseTrendingArr $api_manager->getTrendingProductByCatId($pmsId);
  576.         
  577.         
  578.         $categoryWiseTrendingArrarray_column($categoryWiseTrendingArr'trendingProduct');
  579.         $trendingProductData='';
  580.         //         print_r($categoryWiseSuggestedArr);
  581.         foreach ($categoryWiseTrendingArr as $trendProductIdArr){
  582.             if($trendProductIdArr){
  583.                 $trendingProductData .= ($trendingProductData ',''' ).$trendProductIdArr;//array_filter - remove blank element
  584.             }
  585.         }
  586.         $trendingProductData explode(',',$trendingProductData);
  587.         $trendingProductData  array_filter($trendingProductData);
  588.         //         echo "<pre>";print_r(array_filter($suggestedProductData ));exit;
  589.         if(    $trendingProductData && count($trendingProductData)> 0){
  590.             $result = array();
  591.             if(count($trendingProductData))
  592.                 $sku $trendingProductData;// implode($data['suggestedProducts'], ',');
  593.                 //             $sku = $data['suggestedProducts'];//
  594.                 $this->request->query->set('sku',$sku );
  595.                 $this->request->query->set('search_type','exact');
  596.                 // this is for remove By Default soring(which is Price:desc)
  597.                 $this->request->query->set('sort_by''1');
  598.                 $this->responseArray $this->searchManager->searchService(true);
  599.                 $data=array();
  600.                 //$data = $this->site_module->getProduct($criteria);
  601.                 #print_r(array_keys((array)$this->responseArray['search_result_array']));
  602.                 #echo(array_keys($this->responseArray['search_result_array']));exit;
  603.                 //             print_r($this->responseArray);exit;
  604.                 $data['search_result_array'] = $this->responseArray['search_result_array'];
  605.                 //             print_r($data['search_result_array']);exit;
  606.                 $data['product_box_bootstrap_class']='item';
  607.                 $data['render_model']=0;
  608.                 $response $this->render("project/OfficeBrain/CustomBundle/SearchBundle/BrowseCategory/trendingProduct.html.twig"$data);
  609.                 //             print_r($response);exit;
  610.                 //             if(!empty($cacheKey))
  611.                 //             {
  612.                     //                 RedisCacheService::saveCacheData($this->statsh_cache_wrapper,$cacheKey,$response);
  613.                     //             }
  614.                     return $response;
  615.         }
  616.         else{
  617.             return array();
  618.         }
  619.     }
  620.     
  621.     /**
  622.      * @Route("/{_locale}/bestseller-product-by-category/{categoryId}",
  623.      *     name="office_brain_search_bundle_category_bestseller_product_list",
  624.      * )
  625.      * @Template("project/OfficeBrain/CustomBundle/SearchBundle/BrowseCategory/bestSellerProduct.html.twig")
  626.      */
  627.     public function getBestSellerProductByCategoryAction(Request $request$categoryId){
  628.         $this->initAction($request);
  629.         $pmsId $categoryId;
  630.         
  631.         $api_manager $this->serviceContainer->get('officebrain_category_api_manager');
  632.         $categoryWiseBestSellerArr $api_manager->getBestSellerProductByCatId($pmsId);
  633.         
  634.         
  635.         $categoryWiseBestSellerArrarray_column($categoryWiseBestSellerArr'bestSellerProduct');
  636.         $bestSellerProductData='';
  637.         //         print_r($categoryWiseSuggestedArr);
  638.         foreach ($categoryWiseBestSellerArr as $bestSellerProductIdArr){
  639.             if($bestSellerProductIdArr){
  640.                 $bestSellerProductData .= ($bestSellerProductData ',''' ).$bestSellerProductIdArr;//array_filter - remove blank element
  641.             }
  642.         }
  643.         $bestSellerProductData explode(',',$bestSellerProductData);
  644.         $bestSellerProductData  array_filter($bestSellerProductData);
  645.         //         echo "<pre>";print_r(array_filter($suggestedProductData ));exit;
  646.         if(    $bestSellerProductData && count($bestSellerProductData)> 0){
  647.             $result = array();
  648.             if(count($bestSellerProductData))
  649.                 $sku $bestSellerProductData;
  650.                 $this->request->query->set('sku',$sku );
  651.                 $this->request->query->set('search_type','exact');
  652.                 // this is for remove By Default soring(which is Price:desc)
  653.                 $this->request->query->set('sort_by''1');
  654.                 $this->responseArray $this->searchManager->searchService(true);
  655.                 $data=array();
  656.                 
  657.                 $data['search_result_array'] = $this->responseArray['search_result_array'];
  658.                 //             print_r($data['search_result_array']);exit;
  659.                 $data['product_box_bootstrap_class']='item';
  660.                 $data['render_model']=0;
  661.                 
  662.                 $response $this->render("project/OfficeBrain/CustomBundle/SearchBundle/BrowseCategory/bestSellerProduct.html.twig"$data);
  663.                 //             print_r($response);exit;
  664.                 //             if(!empty($cacheKey))
  665.                 //             {
  666.                     //                 RedisCacheService::saveCacheData($this->statsh_cache_wrapper,$cacheKey,$response);
  667.                     //             }
  668.                     return $response;
  669.         }
  670.          else{
  671.             return array();
  672.         }
  673.     }
  674.     
  675. }