<?php

namespace OfficeBrain\Bundle\ProductTagBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Translation\Translator;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use OfficeBrain\Bundle\ProductTagBundle\Form\MarginMasterType;
use OfficeBrain\Bundle\SearchBundle\Form\Type\ProductSearchType;
use OfficeBrain\Bundle\SearchBundle\Form\Data\ProductSearchData;
use OfficeBrain\Bundle\SearchBundle\Helper\SearchHelper;
/**
 * @author OfficeBrain 4505 <info@officebrain.com>
 *
 * Description : Margin Controller
 *
 * @Route("/admin/{_locale}/margin")
 */
class MarginAdminController extends Controller {

    private $request;
    private $translator;
    private $marginManager;
    private $countryLanguage;
    private $country;
    private $solrObj;
    private $countryMaster;
    private $validationParams;
    private $responseArray;
    private $requestArray;
    private $projectSetting;
    private $recordsPerPage;
    private $productSearchData;
    private $searchForm;
    public function initAction() {
        $this->request = $this->getRequest();
        $this->translator = $this->get('translator');
        $this->marginManager = $this->container->get('office_brain_product_tag_margin_manager');
        $this->countryLanguage = $this->container->getParameter('language');
        $this->country = $this->container->getParameter('country');
        $this->projectSetting = $this->request->get('project_setting');
        //$this->solrObj = $this->get('solarium.client.product_en'); //EMP4464: Original Line
        
        //EMP4464: Changed above line with below code: Start
        $culture = explode('_', $this->projectSetting['locale_language']);
        //$solrCore = 'solarium.client.product_'.$culture[0];
        $solrCore = 'solarium.client.product_'.$this->projectSetting['locale_language'];
        $this->solrObj = $this->container->get($solrCore);
        //EMP4464: Changed above line with below code: End
        
        $this->countryMaster = $this->marginManager->showCountryLanguage($this->country, $this->countryLanguage);
        $this->validationParams = array('mode' => 'add', 'countryMaster' => $this->countryMaster, 'mode_type' => 'group');
        $this->recordsPerPage = $this->projectSetting['configuration_rule']['site_management']['option']['sub_shop']['option']['sub_shop_record_per_page']['status'];
             $this->searchManager = $this->get('office_brain_search_manager');
             $this->productSearchData;
             $this->searchForm;
    }

    public function addMargin() {
        $responseArray = $this->generateForm();

        $this->responseArray = $responseArray['form_data_response'];
    }

    /**
     * @author Employee Id: 4505
     * Description : Search action
     *
     * @param 1 : null
     *
     * @return type Array
     *
     * @throws Exception: Null
     *
     * @Route("/search", name="office_brain_producttagbundle_marginadmin_searchformargin")
     *
     * @Template("OfficeBrainProductTagBundle:Admin:/Margin/addMargin.html.twig")     
     *
     * @Method({"GET"})
     */
    public function searchForMarginAction() {
        $this->initAction();
        $this->validationParams['mode'] = 'add';
        $this->addMargin();
        
        $this->advanceSearchForMargin();
       // var_dump($searchAttributeFilterArray);exit;
       
        return $this->responseArray;
    }

    /**
     * @author Employee Id: 4505
     * Description : Search action
     *
     * @param 1 : null
     *
     * @return type Array
     *
     * @throws Exception: Null
     *
     * @Route("/addgroup", name="office_brain_producttagbundle_marginadmin_addgroup")
     *
     * @Template("OfficeBrainProductTagBundle:Admin:/Margin/groupMarginForm.html.twig")
     *
     * @Method({"GET"})
     */
    public function addGroupAction() {
        $this->initAction();
        $this->validationParams['mode'] = 'add';
        $this->addMargin();

        return $this->responseArray;
    }

    /**
     * @author Employee Id: 4505
     * Description : Search action
     *
     * @param 1 : null
     *
     * @return type Array
     *
     * @throws Exception: Null
     *
     * @Route("/addindividual/{product_id}", name="office_brain_producttagbundle_marginadmin_addindividual")
     *
     * @Template("OfficeBrainProductTagBundle:Admin:/Margin/individualMarginForm.html.twig")
     *
     * @Method({"GET"})
     */
    public function addIndividualAction($product_id) {
        $this->initAction();

        $this->validationParams['mode'] = 'add';
        $this->validationParams['mode_type'] = 'individual';
        $responseArray = $this->generateForm();
        
        $responseArray['form_data_response']['product'] = $this->marginManager->getProductDetail($product_id);

        return $responseArray['form_data_response'];
    }

    /**
     * @author Employee Id: 4505
     * Description : Process add action
     *
     * @param 1 : $id
     *
     * @return type Array
     *
     * @throws Exception: Null
     *
     * @Route("/add", name="office_brain_producttagbundle_marginadmin_processadd")
     *
     * @Template("OfficeBrainProductTagBundle:Admin:/Margin/addMargin.html.twig")
     *
     * @Method({"POST"})
     */
    public function processAddAction() {

        $this->initAction();
        $this->validationParams['mode'] = 'add';

        $this->responseArray = $this->generateForm();

        $form = $this->responseArray['form_object'];

        if ($this->request->isMethod('POST')) {

            //$form->bind( $this->request );
            if ($form->isValid()) {
                $add = $this->marginManager->processData($form->getData(), $this->validationParams, $this->countryMaster);
              
                $this->bindProductMappping($add->getId());
                $countryShort = $this->marginManager->getCountryName($this->countryMaster, $add->getCountryId());
            }
        }
        $this->responseArray['form_data_response']['form'] = $form->createView(); 
  
        return $this->responseArray['form_data_response'];
    }
    
     /**
     * @author Employee Id: 4505
     * Description : bind Product Mappping.
     *
     * @param 1 : $marginId
     *
     * @return type Array
     *
     * @throws Exception: Null
     */
    public function bindProductMappping($marginId) {
        $productIds = $this->request->get('product_ids');
        $productIdArray = explode(',',$productIds);
        if(count($productIdArray) > 0 && $productIds > 0)
        {
            
//            $this->responseArray = array();
//            $productSearchForm = new ProductSearchType();
//            $searchHelper = new NewSearchHelper();
//            $finalRequest = array(
//              'keyword' => $searchParameters['search_query'],
//            );
//            $productSearch = new ProductSearchData($this->getDoctrine()->getManager(), $searchParameters['language_id']);
//            $form = $this->createForm($productSearchForm, $productSearch, array(
//              'csrf_protection' => false,
//            ));
//            $form->bind($finalRequest);
//
//            if ($form->isValid()) {
//                $productSearchData = $form->getData();
//                $productDetailArray = $this->get('office_brain_search_manager')->searchResult($productSearchData, $searchParameters['facet'], $searchHelper);
//                $this->responseArray = $productDetailArray ['data'];
//            }
//
//            return $this->responseArray;
        }        
    }

    /**
     * @Route("/list/{page}", name="office_brain_producttagbundle_marginadmin_list",
     * requirements={"records_per_page"="12|24|48|96|996","page"="\d+"},
     * defaults={"records_per_page"=12,"page"=1})
     * 
     * @Template("OfficeBrainProductTagBundle:Admin:/Margin/listMargin.html.twig")
     */
    public function listAction() {
        $this->initAction();

        $this->responseArray = $this->marginManager->setPagging($this->countryMaster, $this->recordsPerPage, $this->get('knp_paginator'));

        return $this->responseArray;
    }

    /**
     * @author Employee Id: 4505
     * Description : Ajax list action.
     *
     * @param 1 : null
     *
     * @return type Array
     *
     * @throws Exception: Null
     *
     * @Route("/list-ajax", name="office_brain_producttagbundle_marginadmin_listajax",
     * requirements={"records_per_page"="2|4|8|16|996","page"="\d+"},
     * defaults={"records_per_page"=8,"page"=1,"language"="en"})
     *
     * @Template("OfficeBrainProductTagBundle:Admin:/Margin/listMarginAjax.html.twig")
     */
    public function listAjaxAction() {
        $this->initAction();

        $this->responseArray = $this->marginManager->setPagging($this->countryMaster, $this->recordsPerPage, $this->get('knp_paginator'));

        if ($this->request->isXmlHttpRequest()) {
            $varJason = $this->get('twig')->render('OfficeBrainProductTagBundle:Admin:/Margin/listMarginAjax.html.twig', $this->responseArray);

            return new JsonResponse($varJason);
        } else {
            return $this->render('OfficeBrainProductTagBundle:Admin:/Margin/listMarginAjax.html.twig', $this->responseArray);
        }
    }

    /**
     * @author Employee Id: 4505
     * Description : Edit action for Margin.
     *
     * @param 1 : $id
     *
     * @return type Array
     *
     * @throws Exception: Null
     *
     * @Route("/edit/{id}", name="office_brain_producttagbundle_marginadmin_edit")
     *
     * @Template("OfficeBrainProductTagBundle:Admin:/Margin/editMargin.html.twig")
     *
     * @Method({"GET"})
     */
    public function editAction($id) {
        $this->initAction();
        $this->requestArray = $this->marginManager->advanceSearchParameter();
        // var_dump($this->requestArray['solr']);exit;
        $this->validationParams['mode'] = 'edit';
        $this->validationParams['margin_id'] = $id;

        $this->responseArray = $this->generateForm();

        return $this->responseArray['form_data_response'];
    }

    /**
     * @author Employee Id: 4505
     * Description : Process Edit action for Margin.
     *
     * @param 1 : $id
     *
     * @return type Array
     *
     * @throws Exception: Null
     *
     * @Route("/edit/{id}", name="office_brain_producttagbundle_marginadmin_processedit")
     *
     * @Template("OfficeBrainProductTagBundle:Admin:/Margin/editMargin.html.twig")
     *
     * @Method({"POST"})
     */
    public function processeditAction($id) {
        $this->initAction();
        $this->validationParams['mode'] = 'edit';
        $this->validationParams['margin_id'] = $id;

        $this->responseArray = $this->generateForm();

        $form = $this->responseArray['form_object'];

        if ($form->isValid()) {
            $edit = $this->marginManager->processData($form->getData(), $this->validationParams);
            $countryShort = $this->marginManager->getCountryName($this->countryMaster, $edit->getCountryId());
            $this->get('session')->getFlashBag()->add('success_message', $this->translator->trans('tag.action.cat_edit_success'));

            return $this->redirect($this->generateUrl('office_brain_producttagbundle_marginadmin_list', array('country' => $countryShort)));
        }

        return $this->responseArray['form_data_response'];
    }

    /**
     * @author Employee Id: 4505
     * Description : Bind form data add.
     *
     * @param 1 : null
     *
     * @return type Array
     *
     * @throws Exception: Null
     */
    public function generateForm() {
        $marginMaster = $this->marginManager->bindFormData($this->validationParams);
        $responseArray = $this->marginManager->renderDataInForm($marginMaster, $this->countryMaster);        
        
        $form = $this->createForm(new MarginMasterType($this->container, $this->validationParams, $marginMaster), $marginMaster);
        $form->handleRequest($this->request);
        
        if ($form->getData()->getCountryId() > 0) {
            $responseArray['country_id'] = $form->getData()->getCountryId();
        }
        
        $responseArray['form'] = $form->createView();                
        
        return array('form_object' => $form, 'form_data_response' => $responseArray);
    }

    /**
     * @author Employee Id: 4505
     * Description : Bind form data add.
     *
     * @param 1 : null
     *
     * @return type Array
     *
     * @throws Exception: Null
     */
    public function editFormBind() {
        $this->validationParams['mode'] = 'edit';

        $marginMaster = $this->marginManager->bindFormData($this->validationParams);

        $form = $this->createForm(new MarginMasterType($this->container, $this->validationParams, $marginMaster), $marginMaster);
        $form->handleRequest($this->request);

        $this->responseArray = $this->marginManager->renderDataInForm($marginMaster, $this->countryMaster);
        $this->responseArray['form'] = $form->createView();

        if ($form->getData()->getCountryId() > 0) {
            $this->responseArray['country_id'] = $form->getData()->getCountryId();
        }

        return array('form_object' => $form, 'form_data_response' => $this->responseArray);
    }

    /**
     * @author Employee Id: 4505
     * Description : Public tag product mapping action
     *
     * @param 1 : null
     *
     * @return type Array
     *
     * @throws Exception: Null
     *
     * @Route("/map-product-in-tag/{tag_id}/{product_id}", name="office_brain_producttagbundle_margin_mappproductintag")
     *
     * @Template()
     */
    public function mapPublicProductInTagAction() {
        $this->initAction();

        $this->responseArray = $this->marginManager->addToTag($this->solrObj);

        return $this->redirect($this->generateUrl('office_brain_producttagbundle_margin_productmapping', array('id' => $this->responseArray['tag_id'], 'response_data' => $this->responseArray)));
    }

    /**
     * @author Employee Id: 4505
     * Description : Delete public product action
     *
     * @param 1 : $id
     *
     * @return type Array
     *
     * @throws Exception: Null
     *
     * @Route("/delete-product/{id}", name="office_brain_producttagbundle_margin_deletepublicproduct")
     */
    public function deletePublicProductAction($id) {
        $this->initAction();

        $this->responseArray = $this->marginManager->setDeleteProduct($id);

        if ($this->responseArray['count'] > 0) {
            $this->get('session')->getFlashBag()->add('success_message', $this->translator->trans('tag.action.tag_delete_success'));
        } else {
            $this->get('session')->getFlashBag()->add('error_message', $this->translator->trans('tag.action.tag_delete_error'));
        }

        if ($this->request->isXmlHttpRequest()) {
            return new JsonResponse(array('success' => 'success', 'page_url' => $this->generateUrl('office_brain_producttagbundle_privatetagadmin_list', array())));
        } else {
            return $this->redirect($this->generateUrl('office_brain_producttagbundle_privatetagadmin_list'));
        }
    }

    /**
     * @author Employee Id: 4505
     * Description : Public Mapped product list
     *
     * @param 1 : $id
     *
     * @return type Array
     *
     * @throws Exception: Null
     *
     * @Route("/mapped-product-list/{id}", name="office_brain_producttagbundle_margin_mappedproductlist",
     * requirements={"records_per_page"="2|4|8|16|996","page"="\d+"},
     * defaults={"records_per_page"=8,"page"=1,"type"="sku"})
     *
     * @Template("OfficeBrainProductTagBundle:Admin:/Margin/marginMappedList.html.twig")
     */
    public function publicMappedProductListAction($id) {
        $this->initAction();

        $this->responseArray = $this->generatePublicMappedArray($id);

        if (count($this->responseArray['data'])) {
            $paginator = $this->get('knp_paginator');
            $this->responseArray['pagination'] = $paginator->paginate($this->responseArray['data'], $this->responseArray['page_paramater']['page'], $this->responseArray['page_paramater']['records_per_page'], array(), $this->responseArray['count']);
            unset($this->responseArray['data']);
        }

        if ($this->request->isXmlHttpRequest()) {
            $varJason = $this->get('twig')->render('OfficeBrainProductTagBundle:Admin:/Margin/marginMappedList.html.twig', $this->responseArray);

            return new JsonResponse($varJason);
        } else {
            return $this->render('OfficeBrainProductTagBundle:Admin:/Margin/marginMappedList.html.twig', $this->responseArray);
        }
    }

    /**
     * @author Employee Id: 4505
     * Description : Bind form data add.
     *
     * @param 1 : $searchParameters
     *
     * @return type Array
     *
     * @throws Exception: Null
     */
    public function generatePublicMappedArray($id) {
        $productList = array();

        $this->responseArray = $this->marginManager->setPagging($this->countryMaster);
        $this->responseArrayList = $this->marginManager->getMappedList($id);

        foreach ($this->responseArrayList['data'] as $values) {
            $searchParameters = $this->responseArray['page_paramater'];

            if (trim($values['product_sku']) != '') {
                $searchParameters['search_query'] = $values['product_sku'];
                $result = $this->searchKeyword($searchParameters);
                $result[0]['mapped_id'] = $values['id'];
                $productList[] = $result[0];
            }

            unset($searchParameters);
        }

        $this->responseArray['data'] = $productList;
        $this->responseArray['count'] = count($productList);
        $this->responseArray['page_paramater']['tag_id'] = $id;

        return $this->responseArray;
    }

    /**
     * @author Employee Id: 4505
     * Description : Search product ajax action.
     *
     * @param 1 : $search_query
     *
     * @return type Array
     *
     * @throws Exception: Null
     *
     * @Route("/search-product/{search_query}/{type}/{culture}", name="office_brain_producttagbundle_madmin_searchproductajax",
     * requirements={"records_per_page"="2|4|8|16|996","page"="\d+"},
     * defaults={"records_per_page"=8,"page"=1,"type"="sku", "culture"="en_us", "_locale"="en_us"})
     *
     * @Template()
     */
    public function searchProductAjaxAction($search_query) {
        $this->initAction();

        $this->responseArray = $this->setPaggingProduct($this->countryMaster, $this->get('knp_paginator'));
        $this->responseArray['_locale'] = $this->request->get('_locale');
        if ($this->request->isXmlHttpRequest()) {
            $varJason = $this->get('twig')->render('OfficeBrainProductTagBundle:Admin:/Margin/marginProductListContents.html.twig', $this->responseArray);

            return new JsonResponse($varJason);
        } else {
            return $this->render('OfficeBrainProductTagBundle:Admin:/Margin/marginProductListContents.html.twig', $this->responseArray);
        }
    }

    /**
     * @author Employee Id: 4505
     * Description : Search Keyword.
     *
     * @param 1 : $searchParameters
     *
     * @return type Array
     *
     * @throws Exception: Null
     */
    public function searchKeyword($searchParameters) {
        $this->responseArray = array();
        $productSearchForm = new ProductSearchType();
        $searchHelper = new SearchHelper();
        $finalRequest = array(
          'keyword' => $searchParameters['search_query'],
        );
        $productSearch = new ProductSearchData($this->getDoctrine()->getManager(), $searchParameters['language_id']);
        $form = $this->createForm($productSearchForm, $productSearch, array(
          'csrf_protection' => false,
        ));
        $form->bind($finalRequest);

        if ($form->isValid()) {
            $productSearchData = $form->getData();
            $productDetailArray = $this->get('office_brain_search_manager')->searchResult($productSearchData, $searchParameters['facet'], $searchHelper);
            $this->responseArray = $productDetailArray ['data'];
        }

        return $this->responseArray;
    }

     
    /**
     * @author Employee Id: 4505
     * Description : Set Pagging.
     *
     * @param 1 : $countryMaster
     * @param 2 : $knpPaginator
     *
     * @return type Array
     *
     * @throws Exception: Null
     */
    public function setPaggingProduct($countryMaster, $knpPaginator) {
        $pagingSettings = $this->marginManager->pageParameters($countryMaster);
        $this->responseArray = array();
        $this->responseArray ['pagination'] = array();
        $this->responseArray ['pagination']['items'] = array();
        $this->responseArray ['countryMaster'] = $countryMaster;
        $this->responseArray ['page_paramater'] = $pagingSettings;

        $marginList = $this->searchKeyword($pagingSettings);

        if (count($marginList)) {
            $this->responseArray ['pagination'] = $knpPaginator->paginate($marginList, $pagingSettings['page'], $this->recordsPerPage, array(), count($marginList));
            unset($marginList);
        }

        return $this->responseArray;
    }

    /**
     * @author Employee Id: 4505
     * Description : Advance Search Action.
     *
     * @param  : No Parameters
     *
     * @return type Array
     *
     * @throws Exception: Null         
     */
    public function advanceSearchForMargin() {
        /* Init Action */
        $this->initAction();

        $parameter = $this->marginManager->getAdvanceSearchParameter($this->countryMaster);
        
        /* Get search query */
        $productSearchForm = new ProductSearchType();
        $searchHelper = new SearchHelper();
        $productSearch = new ProductSearchData($this->getDoctrine()->getManager(), $parameter['language_id']);
        
        $finalRequest = array($parameter['main_filter'] => $parameter['search_query']);
        
        $form = $this->createForm($productSearchForm, $productSearch, array('csrf_protection' => false));
        $form->bind($finalRequest);
        if ($form->isValid()) {
            $productSearchData = $form->getData();
            $searchAttributeFilterArray = $this->get('office_brain_search_manager')->searchFilter($productSearchData);
        }

        $this->responseArray['language_id'] = $parameter['language_id'];
        $this->responseArray['finalArray'] = $searchAttributeFilterArray;
        //return $this->render('OfficeBrainSearchBundle:Search:advanceSearchPage.html.twig', array("finalArray"=>$searchAttributeFilterArray));
    }

    /**
     * @author Employee Id: 4014
     * Perform search based on search query in selected culture
     *
     * @param string search_query
     * @param int page
     *
     * @return if result found search result page else no record found error
     * @Route("/search", name="office_brain_producttagbundle_madmin_search", options={"expose"=true})
     * @Method({"GET","POST"})
     * @Template()
     */
    public function searchAction() {
        $this->initAction();
        
        $searchQuery = $this->searchManager->getSearchArray();
        $parameter = $this->marginManager->pageParameters($this->countryMaster);
    	$this->prepareSearchForm($searchQuery['product_search'],$parameter);
        
        $this->responseArray['search_result_array'] = array();
        if ($this->searchForm->isValid()) {
            $this->responseArray['search_result_array'] = $this->searchManager->searchResult($this->searchForm->getData());
        }
        if ($this->request->isXmlHttpRequest()) {
            if (is_array($this->responseArray['search_result_array']) && array_key_exists('data', $this->responseArray['search_result_array']) && !count($this->responseArray['search_result_array'])) {
                return new JsonResponse(array('error' => 'END_OF_PAGINATION'));
            }

            return $this->responseArray;
        }

        $this->responseArray['main_filter'] = $this->mainFilter;
        $this->responseArray['form'] = $this->searchForm->createView();

        return $this->responseArray;
    }

//    private function prepareSearchForm() {
//        $this->productSearchData = new ProductSearchData($this->entityManager, $this->languageId);
//
//        $this->mainFilter = $this->request->query->get('main_filter', 'keyword');
//        $page = $this->request->query->get('page', 1);
//        $this->searchQuery = trim($this->request->query->get('search_query', ''));
//        $this->searchRequestArray['product_search'][$this->mainFilter] = $this->searchQuery;
//        // Added for sort functionality
//        $sortingValArray = explode('::', trim($this->request->query->get('sort_by', 'title::asc')));
//        $sortValArray = array();
//
//        if (isset($sortingValArray)) {
//            if (isset($sortingValArray[0]) && isset($sortingValArray[1])) {
//                $sortValArray['field'] = $sortingValArray[0];
//                $sortValArray['order'] = $sortingValArray[1];
//            }
//        }
//        // End add for sort functionality
//        $this->searchRequestArray['product_search']['min_price'] = trim($this->request->query->get('min_price', ''));
//        $this->searchRequestArray['product_search']['max_price'] = trim($this->request->query->get('max_price', ''));
//        $this->searchRequestArray['product_search']['categoryId'] = trim($this->request->query->get('category_filter', ''));
//        $this->searchRequestArray['product_search']['brandId'] = trim($this->request->query->get('brand_filter', ''));
//        $this->searchRequestArray['product_search']['supplierId'] = trim($this->request->query->get('supplier_filter', ''));
//        $this->searchRequestArray['product_search']['priceCurrency'] = trim($this->request->query->get('currency_filter', ''));
//        $this->searchRequestArray['product_search']['rating'] = trim($this->request->query->get('rating_filter', ''));
//        $this->searchRequestArray['product_search']['priceValidUntil'] = trim($this->request->query->get('price_valid_until', ''));
//        $this->searchRequestArray['product_search']['lineNameId'] = trim($this->request->query->get('line_name_id', ''));
//        $this->searchRequestArray['product_search']['catalogYear'] = trim($this->request->query->get('catalog_year', ''));
//        if ($this->request->query->get('sku') != '') {
//            $this->searchRequestArray['product_search']['sku'] = trim($this->request->query->get('sku', ''));
//        }
//        $this->searchRequestArray['product_search']['sort'] = $sortValArray;
//        if ($this->request->query->get('supplier_name') != '') {
//            $this->searchRequestArray['product_search']['supplierName'] = trim($this->request->query->get('supplier_name', ''));
//        }
//        $this->request->query->set($this->request->query->get('main_filter', 'keyword'), $this->request->query->get('search_query'));
//        $this->responseArray['search_query'] = $this->searchQuery;
////    	echo "<pre>";print_r($this->searchRequestArray['product_search']);exit;
//        $this->searchForm = $this->createForm($this->productSearchForm, $this->productSearchData, array('csrf_protection' => false));
//        $this->searchForm->bind($this->searchRequestArray['product_search']);
//    }

    private function prepareSearchForm($searchArray,$parameter=array()) {
    	$this->productSearchData = new ProductSearchData($this->getDoctrine()->getManager(), $parameter['languageId']);
    	$this->searchForm = $this->createForm(new ProductSearchType(), $this->productSearchData, array('csrf_protection' => false));

    	$this->searchForm->bind($searchArray);
    }
}
