<?php
namespace App\project\OfficeBrain\CustomBundle\SearchBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use App\OfficeBrain\Bundle\SearchBundle\Controller\BrowseCategoryController as BaseBrowseCategoryController;
use App\OfficeBrain\Bundle\SearchBundle\Form\Data\ProductSearchData;
use App\OfficeBrain\Bundle\CoreBundle\Cache\RedisCacheService;
use App\project\OfficeBrain\CustomBundle\SearchBundle\Form\Type\ProductSearchType;
use Symfony\Component\DependencyInjection\ContainerInterface as Container;
use Doctrine\ORM\EntityManagerInterface;
use App\OfficeBrain\Bundle\SearchBundle\Manager\Service\SearchManager;
use App\OfficeBrain\Bundle\ProductBundle\Manager\Service\ProductDetailService;
use App\OfficeBrain\Bundle\CategoryBundle\Manager\ApiManager as CategoryApiManager;
use App\OfficeBrain\Bundle\CoreBundle\Service\SessionManager;
use Knp\Component\Pager\PaginatorInterface;
use App\OfficeBrain\Bundle\SearchBundle\Manager\Extended\SolrSearchExtended;
use App\OfficeBrain\Bundle\SearchBundle\Manager\Extended\BrowseCategoryExtended;
use App\OfficeBrain\Bundle\ProductBundle\ApiClient\ProductApiClient;
use App\OfficeBrain\Bundle\SearchBundle\Manager\Service\BrowseCategoryManager;
use App\OfficeBrain\Bundle\CmsBundle\Manager\Service\CmsMenuService;
use App\project\OfficeBrain\CustomBundle\ProductBundle\Manager\Service\ProductDetailService as CustomProductDetailService;
use App\OfficeBrain\Bundle\ProductTagBundle\Manager\Service\ProductTagManager;
class BrowseCategoryController extends BaseBrowseCategoryController
{
protected $request;
/**
*
* @author Employee Id: 4488
*
* To set member variables default value
*
* @return NULL
*
*/
public function __construct(EntityManagerInterface $entityManager, RequestStack $request, SearchManager $solrManager, CategoryApiManager $categoryManager, SessionManager $sessionManager, PaginatorInterface $paginatorManager, Container $serviceContainer, BrowseCategoryManager $browserCategoryManager, ProductDetailService $productDetailService, CustomProductDetailService $customProductDetailManager, CmsMenuService $cmsMenuService, ProductTagManager $productTagManager)
{
parent::__construct($entityManager, $request, $solrManager, $categoryManager, $sessionManager, $paginatorManager, $serviceContainer, $browserCategoryManager, $productDetailService, $customProductDetailManager);
$this->statsh_cache_wrapper=RedisCacheService::create();
$this->browserCategoryManager = $browserCategoryManager->getBrowserCategoryExtended();
$this->cmsMenuService = $cmsMenuService->getCmsMenuExtended();
$this->productTagManager = $productTagManager->getProductTagManagerExtended();
}
/**
*
* @author Employee Id: 4488
* To Initialize the member variables
*
* @return NULL
*/
public function initAction(Request $request)
{
parent::initAction($request);
// $this->productDetailManager = $this->get('office_brain_product_detail_manager_custom'); // symfony 4
$this->request = $request;
// $this->searchManager = $this->get('office_brain_custom_bundle_search_manager'); // symfony 4
$this->searchManager = $this->searchManager;
$this->twigManager = $this->serviceContainer->get('twig');
}
/**
* @author Employee Id: 4488
*
* Browse by Menu Tag and sub category
*
* @param string category slug
*
* @return if result found return sub category list and Product tag else null
*
* @Route("/{_locale}/browse-sub-category/{category_slug}", name="office_brain_search_bundle_browse_sub_category", options={"expose"=true})
* @Method({"GET"})
*
* @Template("project/OfficeBrain/CustomBundle/SearchBundle/BrowseCategory/browseSubCategory.html.twig")
*/
public function browseSubCategoryAction(Request $request)
{
$this->initAction($request);
// $categoryObj = $this->serviceContainer->get('office_brain_browse_category_extended');
$categoryObj = $this->browserCategoryManager;
// $menuItemObj = $this->serviceContainer->get('office_brain_cms_menu_extended');
$menuItemObj = $this->cmsMenuService;
// $productTagObj=$this->serviceContainer->get('office_brain_private_tag_extended');
$productTagObj = $this->productTagManager;
$categorySlug = $this->request->get('category_slug');
$categoryId = $categoryObj->getCategoryIdFromSlug($categorySlug);
$this->responseArray['category_list']=array();
if($categoryId>0)
{
/*
* menu Tag And sub category
*/
$tagArray=$menuItemObj->getTagListFromCmsMenu($categoryId);
$menu_category=array();
if(count($tagArray)>0)
{
foreach ($tagArray as $cat){
if($cat['menutype']=='product-category')
$menu_category['category'][]=$cat['id'];
else
$menu_category['category'][]=null;
if($cat['menutype']=='product-tag')
$menu_category['tag'][]=$cat['id'];
else
$menu_category['tag'][]=null;
}
if(count($menu_category['category'])>0)
{
// Commented by 4248
// /$this->responseArray['category_list'] = $categoryObj->getCategoryNameFromId($menu_category['category']);
}
if(count($menu_category['tag'])>0)
{
$productTagData=$productTagObj->getProductTagList($menu_category['tag']);
if(count($productTagData)>0)
$this->responseArray['product_tag_list']=$productTagData;
}
}
/*
*Get Sub Category List
*
* */
$subCategoryList=array();
$subCategoryList = $categoryObj->getSubCategoryList($categoryId);
if(isset($subCategoryList['parent'])){
$this->responseArray['parent_category_info'] = $subCategoryList['parent'];
}
$this->responseArray['category_name']=$subCategoryList['name'];
array_push($this->responseArray['category_list'],$subCategoryList);
}
else
{
$slug=parent::create_slug($categorySlug);
$this->responseArray['product_tag_list']=$productTagObj->getTagIdFromSlug($slug);
$this->responseArray['category_name']=$slug;
}
return $this->responseArray;
}
/**
* @author Employee Id: 410175
*
* Product listing accordingly parent category
*
* @param string category id
*
* @return if result found return category products else null
*
* @Route("/{_locale}/category-product-list/{category_slug}", name="office_brain_search_bundle_category_product_list", options={"expose"=true})
*
* @Method({"GET"})
*
* @Template("OfficeBrain/Bundle/SearchBundle/BrowseCategory/browseCategoryPage.html.twig")
*/
public function categoryProductListAction(Request $request)
{
$this->initAction($request);
$this->responseArray = array();
$youFirstChidrenCat = array();
$youFirstMatchCat = array(); // this is match side filter with all category of you first
//youfirst Logic
// this is for you first and child category array
$cateogryApiManager= $this->serviceContainer->get("officebrain_category_api_manager");
$youFistcatId = 16115;
$youFirstChidrenCat = $cateogryApiManager->getChildrenCatByCatId($youFistcatId);
$youFirstChidrenCat= array_column($youFirstChidrenCat, 'pms_id');
array_push($youFirstChidrenCat,$youFistcatId);
// echo "<>"print_r($this->responseArray['youFirstChidrenCat'])
// ---END -----
$searchQuery = $this->searchManager->getSearchArray();
$categoryFilter = $this->request->get('category_filter','');
$categoryslug = $this->request->get('category_slug');
// $categoryObj = $this->serviceContainer->get('office_brain_category_manager');
$categoryObj = $this->browserCategoryManager; // OfficeBrain\Bundle\SearchBundle\Manager\Extended\BrowseCategoryExtended
$categoryId = $categoryObj->getCategoryIdFromSlug($categoryslug);
//echo $categoryId.'===='.$categoryslug;
$subCategoryList = $categoryObj->getSubCategoryList($categoryId);
$cultures = $this->serviceContainer->getParameter('language');
$api_manager = $this->serviceContainer->get('officebrain_category_api_manager');
$categoryInfo = $api_manager->getCategoryInfoByCategoryId($cultures,$categoryId);
$categoryKeywords = isset($categoryInfo["en"]["keywords"])?explode(",",$categoryInfo["en"]["keywords"]):'';
//echo $categoryId;exit;
if($categoryFilter == ''){
if( isset($subCategoryList['child']) ) {
$caregoryArray= array_keys($subCategoryList['child']);
array_push($caregoryArray,(int)$categoryId);
$categoryListJson = $caregoryArray;
// $categoryListJson = json_encode($caregoryArray); // symfony 4
// $categoryListJson = json_encode(array_keys($subCategoryList['child']));
} else {
$caregoryArray[] = (int)$categoryId;
$categoryListJson = $caregoryArray;
// $categoryListJson = json_encode($caregoryArray); // symfony 4
}
} else {
$caregoryArray = [];
$categoryListJson = $categoryFilter;
}
if($categoryId){
$catFilterArr = $caregoryArray;
$youFirstMatchCat= array_intersect($catFilterArr,$youFirstChidrenCat);
}
//print_r($categoryListJson);exit;
$this->prepareSearchForm($searchQuery['product_search'],$categoryListJson,$categoryId);
if ($this->form->isValid()) {
$this->responseArray = $this->searchManager->searchResult($this->form->getData());
// echo "<pre>"; dump($this->responseArray); exit;
$this->responseArray['youFirstChidrenCat'] = $youFirstMatchCat;
if (!$this->request->get('page', null)) {
$this->responseArray['search_attribute_filter_array'] = $this->searchManager->searchFilter($this->form->getData());
}
}
/* Rush Category Array */
$rushCategoriesArray = $this->serviceContainer->getParameter('category_page_extra_filter_categories');
$rushCategoryValues = [];
if (isset($this->responseArray['search_attribute_filter_array'])) {
foreach($rushCategoriesArray as $catData){
$key = array_search($catData['pms_id'], array_column($this->responseArray['search_attribute_filter_array']["parentchildCategoryIdName"], 'id'));
if (!empty($key) || $key === 0) {
$rushCategoryValues[$catData['pms_id']] = $this->responseArray['search_attribute_filter_array']["parentchildCategoryIdName"][$key];
}
}
}
if(!empty($rushCategoryValues)){
$this->responseArray['search_attribute_filter_array']['rush_categories'] = $rushCategoryValues;
}
/* EO: Rush Category Array */
if (isset($this->responseArray['search_attribute_filter_array'])) {
$this->responseArray['search_attribute_filter_array']["parentchildCategoryIdName"] = [$this->filterCat($this->responseArray['search_attribute_filter_array']["parentchildCategoryIdName"],$categoryId)];
}
// echo $categoryId;
// -----------------------------------------------------------------------
$this->responseArray['catname'] = $this->productDetailManager->productDetailBreadcrumbs($categoryId);
/* Remove Ideas By Market From Category Filter */
// $allCategoryIds = array_column($this->responseArray['search_attribute_filter_array']['parentchildCategoryIdName'], 'id');
// $categoryIdsToRemove = $this->container->getParameter('category_remove_from_filter');
// foreach($categoryIdsToRemove as $catId){
// $keyToUnset = array_search ($catId, $allCategoryIds);
// if(isset($this->responseArray['search_attribute_filter_array']['parentchildCategoryIdName'][$keyToUnset])){
// unset($this->responseArray['search_attribute_filter_array']['parentchildCategoryIdName'][$keyToUnset]);
// }
// }
/* Remove Ideas By Market From Category Filter */
/* EO - Category Brand Merging */
if(isset($this->responseArray['search_attribute_filter_array']['publicCustomTagText']) && is_array($this->responseArray['search_attribute_filter_array']['publicCustomTagText'])){
if(!isset($this->responseArray['search_attribute_filter_array']['parentchildCategoryIdName'][0]['values'])){
$this->responseArray['search_attribute_filter_array']['parentchildCategoryIdName'][0]['values'] = array();
}
$parentCategoryNamesArray = array_column($this->responseArray['search_attribute_filter_array']['parentchildCategoryIdName'][0]['values'], 'name');
$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');
$brandFinalArray = array();
$count = 0;
foreach($this->responseArray['search_attribute_filter_array']['publicCustomTagText'] as $brandData => $productCount){
$brandArray = explode('|', $brandData);
if(in_array(trim($brandArray[5]), $brandSlugs) && !in_array(trim($brandArray[1]), $parentCategoryNamesArray)){
$brandFinalArray[$count]['id'] = trim($brandArray[0]);
$brandFinalArray[$count]['name'] = trim($brandArray[1]);
$brandFinalArray[$count]['slug'] = trim($brandArray[5]);
$brandFinalArray[$count]['count'] = $productCount;
$brandFinalArray[$count]['type'] = 'brand';
$count++;
}
}
if(!empty($brandFinalArray)){
if(!isset($this->responseArray['search_attribute_filter_array']['parentchildCategoryIdName'][0]['values'])){
$this->responseArray['search_attribute_filter_array']['parentchildCategoryIdName'][0]['values'] = array();
}
$this->responseArray['search_attribute_filter_array']['parentchildCategoryIdName'][0]['values'] = array_merge($this->responseArray['search_attribute_filter_array']['parentchildCategoryIdName'][0]['values'], $brandFinalArray);
$categoryData = array_column($this->responseArray['search_attribute_filter_array']['parentchildCategoryIdName'][0]['values'], 'name');
array_multisort($categoryData, SORT_ASC, $this->responseArray['search_attribute_filter_array']['parentchildCategoryIdName'][0]['values']);
}
}
/* EO - Category Brand Merging */
// -----------------------------------------------------------------------
if (!$this->request->isXmlHttpRequest()) {
// get IdeasByMarket cat from All search filter cat
$api_manager = $this->serviceContainer->get('officebrain_category_api_manager');
$dataOfIdeas = $api_manager->getIdeasByMarketCat();
$dataOfIdeas_final = array_column($dataOfIdeas, 'pms_id');
if (isset($this->responseArray['search_attribute_filter_array'])) {
$this->responseArray['search_attribute_filter_array']['Ideas_by_market_Cat'] = array_filter($this->responseArray['search_attribute_filter_array']['categoryNameId'], function($array) use($dataOfIdeas_final){
if (in_array($array['id'], $dataOfIdeas_final)) {
return true ;
}
else{
return false;
}
}
);
}
if (isset($this->responseArray['search_attribute_filter_array'])) {
$arr = array_filter($this->responseArray['search_attribute_filter_array']['categoryNameId'], function($array) use($dataOfIdeas_final){
if (in_array($array['id'], $dataOfIdeas_final)) {
return false ;
}
else{
return true;
}
});
}
if (isset($this->responseArray['search_attribute_filter_array'])) {
$this->responseArray['search_attribute_filter_array']['categoryNameId'] = $arr;
}
/* For Default Category Filter */
$this->responseArray['is_from_category_page'] = 1;
$this->responseArray['category_id'] = $categoryId;
//
$locale=$this->request->getLocale();
$search = base64_encode(json_encode($searchQuery));
// $cacheSiteKey = array('SearchFilter',$search,$categoryslug,$locale,$this->instanceId,$this->container->getParameter('kernel.environment')); // symfony 4
$cacheSiteKey = array('SearchFilter',$search,$categoryslug,$locale,$this->instanceId,$this->projectSetting['kernelEnvironment']);
$this->moduleCachePrefix='__Search__:';
$cacheKey = $this->moduleCachePrefix.RedisCacheService::generateKey($this->statsh_cache_wrapper,$cacheSiteKey);
$cacheData = RedisCacheService::getCacheData($this->statsh_cache_wrapper,$cacheKey);
if($cacheData){
$this->responseArray['filterHtml']= $cacheData;
}
else{
// echo "<pre>";print_r($this->responseArray['search_attribute_filter_array']["parentchildCategoryIdName"]);exit;
$response = $this->twigManager->render('project/OfficeBrain/CustomBundle/SearchBundle/Search/searchAttributeFilterList.html.twig', $this->responseArray);
if(!empty($cacheKey))
{
RedisCacheService::saveCacheData($this->statsh_cache_wrapper,$cacheKey,$response);
}
$this->responseArray['filterHtml'] = $response;
}
}
$this->responseArray['sub_category_list'] = $categoryListJson;
$this->responseArray['breadcrumbs'] = $this->productDetailManager->productDetailBreadcrumbs($categoryId);
$this->responseArray['search_query'] = $searchQuery['search']['query'];
$this->responseArray['main_filter'] = $searchQuery['search']['main_filter'];
$this->responseArray['form'] = $this->form->createView();
$this->responseArray['Recent_search'] = $this->request->getSession()->get('recent_search');
$this->responseArray['save_search'] = $this->searchManager->getSaveSearch();
$recentSearch = $this->request->query->get('is_filter','check');
if($recentSearch == 'check'){
$this->searchManager->setRecentSearch();
}
$this->responseArray['category_breadcrumb']= array($this->translator->trans('breadcrumb_category'),(isset($subCategoryList['name'])?$subCategoryList['name']:''));
$this->responseArray['category_slug'] = $categoryslug;
$this->responseArray['categoryInfo'] = $categoryInfo;
$this->responseArray['categoryKeywords'] = $categoryKeywords;
if( isset($subCategoryList['child']) ) {
$this->responseArray['sub_category_ids'] = array_keys($subCategoryList['child']);
}
// $categoryId = 320; // comment because we don't want display advertise on product page
$this->responseArray['categoryAdvertiseData'] = $this->customProductDetailManager->getAdvertiseForFrontByRefId($categoryId,'category');//type =catwgory
//print_r($this->responseArray);die('==========');
return $this->responseArray;
}
private function filterCat($catArr, $catId){
foreach ($catArr as $val){
if($val["id"] == $catId){
return $val;
break;
}
if(array_key_exists("values",$val) && $val["values"]){
$returnVal = $this->filterCat($val["values"], $catId);
if($returnVal){
return $returnVal;
break;
}
}
}
// echo "<pre>";print_r($catArr);die;
}
private function prepareSearchForm($searchArray,$categoryListJson,$categoryId = "") {
$searchArray['categoryId'] = $categoryListJson;
/* For displaying category order wise*/
$searchArray['sort'] = array(
'field' => 'category||sorting_product_by_categoryid_'. $categoryId .'_i',
'order' => 'desc'
);
$this->productSearchData = new ProductSearchData($this->entityManager, $this->languageId);;
$this->form = $this->createForm(ProductSearchType::class, $this->productSearchData, [
'csrf_protection' => false,
'searchData' => $searchArray,
]);
$this->form->submit($searchArray);
// if (!$this->form->isValid()) {
// foreach ($this->form->getErrors(true) as $error) {
// $field = $error->getOrigin()->getName(); // Get the field name
// $message = $error->getMessage(); // Get the error message
// dump("Field: $field, Error: $message");
// }
// exit;
// }
}
/**
* @author Employee Id: 5429
*
* Product listing accordingly parent category
*
* @param string category id
*
* @return if result found return category products else null
*
* @Route("/{_locale}/subcategory-product-list", name="office_brain_search_bundle_subcategory_product_list", options={"expose"=true})
*
* @Method({"GET"})
*
* @Template()
*/
public function subCategoryProductPageAction(Request $request)
{
$this->initAction($request);
$recordparpage=1200;
$searchQuery = $this->searchManager->getSearchArray();
$data = $this->request->get('data','');
$serchtype = $this->request->get('search_type','');
if($serchtype==1)
{
$categoryListJson='['.$data.']';
$this->prepareSearchForm($searchQuery['product_search'],$categoryListJson);
}
else
{
$this->prepareSearchForm($searchQuery['product_search'],'');
}
$this->responseArray = array();
if ($this->form->isValid()) {
$this->responseArray['productdata'] = $this->searchManager->searchResult($this->form->getData(),'',$recordparpage);
}
return $this->responseArray;
}
/**
* @author Employee Id: 5429
*
* Download product images.
*
* @param string product sku
*
* @param integer supplier id
*
* @return download product template
* @Route("/{_locale}/download-imagecontent", name="office_brain_custom_bundle_search_download_image_content", options={"expose"=true})
*
* @Method({"GET"})
*
* @Template()
*/
public function downloadImageContentAction(Request $request)
{
$this->initAction($request);
$path = $this->request->get('path', null);
$filename=array_reverse(explode('/',$path));
$response = new Response();
$response->headers->set('Content-Disposition','attachment;filename='.$filename[0]);
$response->headers->set('Content-Type', 'image/jpg');
$response->setContent(file_get_contents($path));
return $response;
}
/**
* @Route("/{_locale}/suggested-product-by-category/{categoryId}",
* name="office_brain_search_bundle_category_suggested_product_list",
* )
* @Template("project/OfficeBrain/CustomBundle/SearchBundle/BrowseCategory/suggestedProduct.html.twig")
*/
public function getSuggestedProductByCategoryAction(Request $request, $categoryId){
$this->initAction($request);
$pmsId = $categoryId;
// $api_manager = $this->get('officebrain_category_api_manager');
// $data = $api_manager->getSuggestedProductByCategoryId($pmsId);
// if($data && count($data['suggestedProducts'])> 0){
// $result = array();
// if(count($data['suggestedProducts']))
// $sku = $data['suggestedProducts'] ;// implode($data['suggestedProducts'], ',');
// // $sku = $data['suggestedProducts'];//
// $this->request->query->set('sku',$sku);
// $this->request->query->set('search_type','exact');
// // this is for remove By Default soring(which is Price:desc)
// $this->request->query->set('sort_by', '1');
$api_manager = $this->serviceContainer->get('officebrain_category_api_manager');
$categoryWiseSuggestedArr = $api_manager->getSuggestedProductByCatId($pmsId);
// if(count($categoryWiseSuggestedArr)==0){
// $categoryWiseSuggestedArr = $api_manager->getSuggestedProductByRelatedCat($pmsId);
// }
// if( (count($categoryWiseSuggestedArr) == 0) || ( count($categoryWiseSuggestedArr) && (!$categoryWiseSuggestedArr[0]['suggestedProduct'] || $categoryWiseSuggestedArr[0]['suggestedProduct'] == '0')) ){
// $categoryWiseSuggestedArr = $api_manager->getSuggestedProductByRelatedCat($pmsId);
// }
// $categoryWiseSuggestedArr = $api_manager->getSuggestedProductByRelatedCat($pmsId);
$categoryWiseSuggestedArr= array_column($categoryWiseSuggestedArr, 'suggestedProduct');
$suggestedProductData='';
// print_r($categoryWiseSuggestedArr);
foreach ($categoryWiseSuggestedArr as $suggProductIdArr){
if($suggProductIdArr){
$suggestedProductData .= ($suggestedProductData ? ',': '' ).$suggProductIdArr;//array_filter - remove blank element
}
}
$suggestedProductData = explode(',',$suggestedProductData);
$suggestedProductData = array_filter($suggestedProductData);
// echo "<pre>";print_r(array_filter($suggestedProductData ));exit;
if( $suggestedProductData && count($suggestedProductData)> 0){
$result = array();
if(count($suggestedProductData))
$sku = $suggestedProductData;// implode($data['suggestedProducts'], ',');
// $sku = $data['suggestedProducts'];//
$this->request->query->set('sku',$sku );
$this->request->query->set('search_type','exact');
// this is for remove By Default soring(which is Price:desc)
$this->request->query->set('sort_by', '1');
$this->responseArray = $this->searchManager->searchService(true);
$data=array();
//$data = $this->site_module->getProduct($criteria);
#print_r(array_keys((array)$this->responseArray['search_result_array']));
#echo(array_keys($this->responseArray['search_result_array']));exit;
// print_r($this->responseArray);exit;
$data['search_result_array'] = $this->responseArray['search_result_array'];
// print_r($data['search_result_array']);exit;
$data['product_box_bootstrap_class']='item';
$data['render_model']=0;
//return $this->render('OfficeBrainPageBundle:tempUIElements:recommendProducts.html.twig', $data);
$response = $this->render("project/OfficeBrain/CustomBundle/SearchBundle/BrowseCategory/suggestedProduct.html.twig", $data);
// print_r($response);exit;
// if(!empty($cacheKey))
// {
// RedisCacheService::saveCacheData($this->statsh_cache_wrapper,$cacheKey,$response);
// }
return $response;
}
else{
return array();
}
}
/**
* @Route("/{_locale}/trending-product-by-category/{categoryId}",
* name="office_brain_search_bundle_category_trending_product_list",
* )
* @Template("project/OfficeBrain/CustomBundle/SearchBundle/BrowseCategory/trendingProduct.html.twig")
*/
public function getTrendingProductByCategoryAction(Request $request, $categoryId){
$this->initAction($request);
$pmsId = $categoryId;
$api_manager = $this->serviceContainer->get('officebrain_category_api_manager');
$categoryWiseTrendingArr = $api_manager->getTrendingProductByCatId($pmsId);
$categoryWiseTrendingArr= array_column($categoryWiseTrendingArr, 'trendingProduct');
$trendingProductData='';
// print_r($categoryWiseSuggestedArr);
foreach ($categoryWiseTrendingArr as $trendProductIdArr){
if($trendProductIdArr){
$trendingProductData .= ($trendingProductData ? ',': '' ).$trendProductIdArr;//array_filter - remove blank element
}
}
$trendingProductData = explode(',',$trendingProductData);
$trendingProductData = array_filter($trendingProductData);
// echo "<pre>";print_r(array_filter($suggestedProductData ));exit;
if( $trendingProductData && count($trendingProductData)> 0){
$result = array();
if(count($trendingProductData))
$sku = $trendingProductData;// implode($data['suggestedProducts'], ',');
// $sku = $data['suggestedProducts'];//
$this->request->query->set('sku',$sku );
$this->request->query->set('search_type','exact');
// this is for remove By Default soring(which is Price:desc)
$this->request->query->set('sort_by', '1');
$this->responseArray = $this->searchManager->searchService(true);
$data=array();
//$data = $this->site_module->getProduct($criteria);
#print_r(array_keys((array)$this->responseArray['search_result_array']));
#echo(array_keys($this->responseArray['search_result_array']));exit;
// print_r($this->responseArray);exit;
$data['search_result_array'] = $this->responseArray['search_result_array'];
// print_r($data['search_result_array']);exit;
$data['product_box_bootstrap_class']='item';
$data['render_model']=0;
$response = $this->render("project/OfficeBrain/CustomBundle/SearchBundle/BrowseCategory/trendingProduct.html.twig", $data);
// print_r($response);exit;
// if(!empty($cacheKey))
// {
// RedisCacheService::saveCacheData($this->statsh_cache_wrapper,$cacheKey,$response);
// }
return $response;
}
else{
return array();
}
}
/**
* @Route("/{_locale}/bestseller-product-by-category/{categoryId}",
* name="office_brain_search_bundle_category_bestseller_product_list",
* )
* @Template("project/OfficeBrain/CustomBundle/SearchBundle/BrowseCategory/bestSellerProduct.html.twig")
*/
public function getBestSellerProductByCategoryAction(Request $request, $categoryId){
$this->initAction($request);
$pmsId = $categoryId;
$api_manager = $this->serviceContainer->get('officebrain_category_api_manager');
$categoryWiseBestSellerArr = $api_manager->getBestSellerProductByCatId($pmsId);
$categoryWiseBestSellerArr= array_column($categoryWiseBestSellerArr, 'bestSellerProduct');
$bestSellerProductData='';
// print_r($categoryWiseSuggestedArr);
foreach ($categoryWiseBestSellerArr as $bestSellerProductIdArr){
if($bestSellerProductIdArr){
$bestSellerProductData .= ($bestSellerProductData ? ',': '' ).$bestSellerProductIdArr;//array_filter - remove blank element
}
}
$bestSellerProductData = explode(',',$bestSellerProductData);
$bestSellerProductData = array_filter($bestSellerProductData);
// echo "<pre>";print_r(array_filter($suggestedProductData ));exit;
if( $bestSellerProductData && count($bestSellerProductData)> 0){
$result = array();
if(count($bestSellerProductData))
$sku = $bestSellerProductData;
$this->request->query->set('sku',$sku );
$this->request->query->set('search_type','exact');
// this is for remove By Default soring(which is Price:desc)
$this->request->query->set('sort_by', '1');
$this->responseArray = $this->searchManager->searchService(true);
$data=array();
$data['search_result_array'] = $this->responseArray['search_result_array'];
// print_r($data['search_result_array']);exit;
$data['product_box_bootstrap_class']='item';
$data['render_model']=0;
$response = $this->render("project/OfficeBrain/CustomBundle/SearchBundle/BrowseCategory/bestSellerProduct.html.twig", $data);
// print_r($response);exit;
// if(!empty($cacheKey))
// {
// RedisCacheService::saveCacheData($this->statsh_cache_wrapper,$cacheKey,$response);
// }
return $response;
}
else{
return array();
}
}
}