<?php
namespace OfficeBrain\Bundle\CompareProductBundle\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\Session\Session;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Translation\Translator;
use Symfony\Component\HttpFoundation\Response;
use OfficeBrain\Bundle\CompareProductBundle\Form\CompareProductEmailToFriendType;

/**
 * 
 * @author OfficeBrain 4074 <info@officebrain.com>
 * 
 * Desciption: This controller help user to compare various product
 *
 * @package: OfficeBrain eCommerce Product Web Client
 * 
 * @subpackage: Compare Product
 * 
 * @version 1.0
 * 
 */
class CompareProductController extends Controller
{
    /**
     *
     * @author Employee Id: 4074
     *
     * Desciption: Define member variables with thier default value
     *
     * @param NULL
     * 
     * @return NULL
     * 
     * @throws NULL
     * 
     */
    public function __construct()
    {
        $this->request = null;
        $this->cultureId = null;
        $this->refererUrl = null;
        $this->productId = null;
        $this->cultureProductId = null;
        $this->responseArray = array();    
        $this->projectSetting = array();
        $this->comapreProductMaxLimit = null;
        $this->commonLibraryManager = null;
        $this->compareProductManager = null;
        $this->sessionManager = null;
        $this->emailManager = null;
    }
    
    /**
     *
     * @author Employee Id: 4074
     *
     * Desciption: Unset member variables
     *
     * @param NULL
     * 
     * @return NULL
     * 
     * @throws NULL
     * 
     */
    public function __destruct()
    {
        unset($this->request);
        unset($this->cultureId);
        unset($this->refererUrl);
        unset($this->productId);
        unset($this->cultureProductId);
        unset($this->responseArray);
        unset($this->projectSetting);
        unset($this->comapreProductMaxLimit);
        unset($this->commonLibraryManager);
        unset($this->compareProductManager);
        unset($this->sessionManager);
        unset($this->emailManager);
    }
    
    /**
     *
     * @author Employee Id: 4074
     *
     * Desciption: Create and initialize various required object and member variables
     *
     * @param NULL
     *
     * @return NULL
     *
     * @throws NULL
     *
     */
    public function initAction()
    {
    	$this->request = $this->getRequest();
    	$this->productId = $this->request->get('productId', null);
    	$this->cultureProductId = $this->request->get('cultureProductId', null);
    	$this->projectSetting = $this->request->get('project_setting');
    	$this->cultureId = $this->projectSetting['culture_id'];
    	$this->comapreProductMaxLimit = $this->projectSetting['configuration_rule']['transaction']['compare_product']['inline_view']['option']['no_of_product'];
    
    	$this->sessionManager = $this->get('office_brain_session_manager');
    	$this->commonLibraryManager = $this->get('office_brain_common_library');
    	$this->compareProductManager = $this->get('office_brain_compare_product_manager');
    	$this->emailManager = $this->get('office_brain_email_service');
    
    	$this->responseArray['status'] = 'error';
    	$this->responseArray['product_id'] = $this->productId;
    	$this->mediaFilePath = $this->container->getParameter('cms.media_file_path');
    }
    
    /**
     *
     * @author Employee Id: 4074
     *
     * Desciption: Show recently addded product for compare in quick list 
     *
     * @param NULL
     *
     * @return Html Response 
     *
     * @throws NULL
     *
     * @Route("/{_locale}/recent-product-compare-list",
     * 	name="office_brain_compareproductbundle_compareproduct_recentcompareproductlist",
     *  options={"expose"=true}
     * )
     *
     * @Method({"GET"})
     * 
     * @Template("OfficeBrainCompareProductBundle:CompareProduct:recentCompareProductList.html.twig")
     * 
     */
    public function recentCompareProductListAction()
    {
        $this->initAction();

        $this->responseArray['record_set'] = $this->compareProductManager->getCompareProduct();
        $this->responseArray['total_record'] = $this->compareProductManager->getTotalCount();
        return $this->responseArray;
    }
    
    /**
     *
     * @author Employee Id: 4074
     *
     * Desciption: This function allow user to compare selected product feature wise.  
     *
     * @param NULL
     *
     * @return Html Response
     *
     * @throws NULL
     * 
     * @Route("/{_locale}/compare-product",
     * 	name="office_brain_compareproductbundle_compareproduct_compareproduct", options={"expose"=true}
     * )
     * 
     * @Method({"GET", "POST"})
     * 
     * @Template("OfficeBrainCompareProductBundle:CompareProduct:compareProduct.html.twig")
     * 
     */
    public function compareProductAction()
    {
        $this->initAction();

        $this->responseArray['record_set'] = $this->compareProductManager->getCompareProduct();
        $this->responseArray['total_record'] = $this->compareProductManager->getTotalCount();
        $this->responseArray['remaining_compare_product'] = $this->comapreProductMaxLimit - $this->responseArray['total_record'];
        $this->compareProductManager->setContinueShoppingUrl($this->commonLibraryManager->getRefererRouteName(), $this->commonLibraryManager->getRefererUrl());
        return $this->responseArray;
    }
    
    /**
     *
     * @author Employee Id: 4074
     *
     * Desciption: This function allow user to download compare product page as pdf.  
     *
     * @param integer productId
     * @param integer cultureProductId
     *
     * @return application/pdf compare-product.pdf
     *
     * @throws NULL
     *
     * @Route("/{_locale}/compare-product-pdf",
     * 	name="office_brain_compareproductbundle_compareproduct_downloadcompareproductaspdf",
     *  options={"expose"=true}
     * )
     * 
     * @Method({"GET"})
     * 
     * @Template()
     * 
     */
    public function downloadCompareProductAsPdfAction()
    {
        $this->initAction();
        $data=$this->request->get('data');
        $this->responseArray['QtyValues'] = $data['qty_values'];
        $this->responseArray['priceProd'] = $data['price'];
        $this->responseArray['record_set'] = $this->compareProductManager->getCompareProduct();
        $this->responseArray['total_record'] = $this->compareProductManager->getTotalCount();
        $this->responseArray['remaining_compare_product'] = $this->comapreProductMaxLimit - $this->responseArray['total_record'];
        $response = $this->render('OfficeBrainCompareProductBundle:CompareProduct:downloadCompareProductAsPdf.html.twig', $this->responseArray);
        
        $content = $response->getContent();        
        $baseURL = $this->container->getParameter('base_url');
        $basePath = $this->container->getParameter('base_path');
        $content = str_replace($baseURL,$basePath,$content);
        
        //return new Response ($content);
        $this->get('knp_snappy.pdf')->getInternalGenerator()->setTimeout(300);
        return new Response(
        		$this->get('knp_snappy.pdf')->getOutputFromHtml($content),
        		200,
        		array(
        				'Content-Type'        => 'application/pdf',
        				'Content-Disposition' => 'attachment; filename="compare-product.pdf"'
        		)
        );
    }
    
    /**
     *
     * @author Employee Id: 4074
     *
     * Desciption: This function allow user add product to compare product feature.  
     *
     * @param integer productId
     * @param integer cultureProductId
     *
     * @return Json Response
     *
     * @throws NULL
     *
     * @Route("/{_locale}/add-to-compare-product",
     * name="office_brain_compareproductbundle_compareproduct_addproducttocompare",
     *  options={"expose"=true}
     * )
     *
     * @Method({"POST"})
     * 
     * @Template()
     * 
     */
    public function addProductToCompareAction()
    {
        $this->initAction();

        if ($this->productId && $this->cultureProductId) {
            $status = $this->compareProductManager->setCompareProduct($this->productId, $this->cultureProductId);
            switch ($status) {
                case 'ERROR_MAX_LIMIT_REACHED':
                        $this->responseArray['error_message'] = $this->get('translator')->trans('product_compare.max_product_compare', array('%no_of_compare_product%' => $this->comapreProductMaxLimit));
                    break;
                case 'ERROR_PRODUCT_ALREADY_EXISTS':
                        $this->responseArray['error_message'] = $this->get('translator')->trans('product_compare.product_already_exists');
                    break;
                case 'SUCCESS':
                        $this->responseArray['status'] = 'success';
                        $this->responseArray['success_message'] = $this->get('translator')->trans('product_compare.add_success_message');
                        
                        $this->refererUrl = $this->commonLibraryManager->getRefererRouteName();
                    break;
            }
        }

        if ($this->refererUrl=='office_brain_compareproductbundle_compareproduct_compareproduct') {
            $this->responseArray['page_url'] = $this->generateUrl('office_brain_compareproductbundle_compareproduct_compareproduct');
        } else {
            $this->responseArray['total_record'] = $this->compareProductManager->getTotalCount();
        }

        return new JsonResponse($this->responseArray);
    }
    
    /**
     *
     * @author Employee Id: 4074
     *
     * Desciption: This function allow user to delete product from compare product section.  
     *
     * @param integer productId
     * @param integer cultureProductId
     *
     * @return Json Response
     *
     * @throws NULL
	 *
     * @Route("/{_locale}/compare-product-delete",
     * 	name="office_brain_compareproductbundle_compareproduct_deletecompareproduct",
     *  options={"expose"=true}
     * )
     *
     * @Method({"POST"})
     * 
     * @Template()
     * 
     */
    public function deleteCompareProductAction()
    {
        $this->initAction();

        if ($this->productId && $this->cultureProductId) {
            $status = $this->compareProductManager->deleteCompareProduct($this->productId, $this->cultureProductId);
            switch ($status) {
                case 'ERROR_PRODUCT_ALREADY_EXISTS':
                    $this->responseArray['error_message'] = $this->get('translator')->trans('product_compare.product_already_exists');
                    break;
                case 'SUCCESS':
                    $this->responseArray['status'] = 'success';
                    $this->responseArray['success_message'] = $this->get('translator')->trans('product_compare.remove_success_message');

                    $this->refererUrl = $this->commonLibraryManager->getRefererRouteName();
                    break;
            }
        }
       
        if ($this->refererUrl=='office_brain_compareproductbundle_compareproduct_compareproduct') {
            //$this->sessionManager->set('compareProd_success_deleted',$this->get('translator')->trans('product_compare.remove_success_message'));
            $this->responseArray['page_url'] = $this->generateUrl('office_brain_compareproductbundle_compareproduct_compareproduct');
        } else {
            $this->responseArray['total_record'] = $this->compareProductManager->getTotalCount();
        }

        return new JsonResponse($this->responseArray);
    }
    
    /**
     *
     * @author Employee Id: 4074
     *
     * Desciption: This function allow user to delete all products from compare product section.  
     *
     * @param NULL
     *
     * @return Json Response
     *
     * @throws NULL
	 *
     * @Route("/{_locale}/compare-product-delete-all",
     * 	name="office_brain_compareproductbundle_compareproduct_deleteallcompareproduct",
     *  options={"expose"=true}
     * )
     *
     * @Method({"POST"})
     * 
     * @Template()
     * 
     */
    public function deleteAllCompareProductAction()
    {
        $this->initAction();
    
        $status = $this->compareProductManager->deleteAllCompareProduct();
        switch ($status) {
            case 'ERROR_PRODUCT_ALREADY_EXISTS':
                $this->responseArray['error_message'] = $this->get('translator')->trans('product_compare.product_already_exists');
                break;
            case 'SUCCESS':
                $this->responseArray['status'] = 'success';
                $this->responseArray['success_message'] = $this->get('translator')->trans('product_compare.remove_success_message');
                $this->refererUrl = $this->commonLibraryManager->getRefererRouteName();
                break;
        }
        
        if ($this->refererUrl=='office_brain_compareproductbundle_compareproduct_compareproduct') {
//            $this->sessionManager->set('compareProd_success_deleted',$this->get('translator')->trans('product_compare.remove_success_message'));
            $this->responseArray['page_url'] = $this->generateUrl('office_brain_compareproductbundle_compareproduct_compareproduct',array(),true);
        } else {
            $this->responseArray['total_record'] = $this->compareProductManager->getTotalCount();
        }

        return new JsonResponse($this->responseArray);
    }

    /**
     *
     * @author Employee Id: 4471
     *
     * Desciption: This function generate form which allow user send compare product page as email to friends.  
     *
     * @param NULL
     *
     * @return Html Response
     *
     * @throws NULL
     *
     * @Route("/{_locale}/compare-product-email-to-friend",
     * 	name="office_brain_compareproductbundle_compareproduct_emailtofriend",
     * )
     * 
     * @Method({"GET"})
     * 
     * @Template("OfficeBrainCompareProductBundle:CompareProduct:emailToFriend.html.twig")
     * 
     */
    public function emailToFriendAction()
    {
        $this->initAction();

        $this->responseArray = '';
        //$this->responseArray['product_id'] = $data['productId'];
        // $this->responseArray['QtyValues'] = json_encode($this->request->get('QtyValues'));
        // $this->responseArray['priceProd'] = json_encode($this->request->get('priceProd'));
        $this->form = $this->createForm(new CompareProductEmailToFriendType());
        // $this->responseArray['form'] = $this->form->createView();
        
        return  $this->render('OfficeBrainCompareProductBundle:CompareProduct:emailToFriend.html.twig', array(
            'QtyValues' => json_encode($this->request->get('QtyValues')),
            'priceProd' => json_encode($this->request->get('priceProd')),
            'form' => $this->form->createView(),
        ));
        // return $this->responseArray;
    }
    
    /**
     *
     * @author Employee Id: 4471
     *
     * Desciption: This function allow user send compare product page as email to friends.  
     *
     * @param NULL
     *
     * @return Html Response
     *
     * @throws NULL
     *
     * @Route("/{_locale}/compare-product-email-to-friend-submit",
     * 	name="office_brain_compareproductbundle_compareproduct_emailtofriend_submit",
     * )
     * 
     * @Method({"POST"})
     * 
     * @Template()
     * 
     */
    public function submitMailEmailToFriendCompareProductAction()
    {
        $this->initAction();

        $this->form = $this->createForm(new CompareProductEmailToFriendType());
        $this->form->handleRequest($this->request);
    	
    	if ($this->form->isValid()) {
            /*if(isset($_POST['g-recaptcha-response']) && $_POST['g-recaptcha-response']!=''){
                    $captcha=$_POST['g-recaptcha-response'];
            
                    $secretKey = "6LdFSNYjAAAAAIRwiVnI4UJIfjq1oCbzWuSFQ9a-";
                    $url = 'https://www.google.com/recaptcha/api/siteverify?secret=' . urlencode($secretKey) .  '&response=' . urlencode($captcha);
                    $response = file_get_contents($url);
                    $responseKeys = json_decode($response,true);
            }

            if($responseKeys['success']!=1){

                    $this->responseArray['form_status'] = 'error';
                    $this->responseArray['captcha_error'] = 'Oops, you have to check the recaptcha !';
                    return new JsonResponse($this->responseArray);
                            
            }*/
    		$this->sendMailToFriend();
    		$this->responseArray['status'] = 'success';
    		$this->responseArray['close_modal'] = true;
    		$this->responseArray['success_message'] = $this->get('translator')->trans('product_compare.email_msg_sucess');
    	} else {
   			$this->responseArray = $this->commonLibraryManager->prepareFormJsonError($this->form);
    	}

    	return new JsonResponse($this->responseArray);
    }
    
    /**
     *
     * @author Employee Id: 4471
     *
     * Desciption: This function allow user print compare product page.  
     *
     * @param NULL
     *
     * @return Html Response
     *
     * @throws NULL
     *
     * @Route("/{_locale}/compare-product-print",
     * 	name="office_brain_compareproductbundle_compareproduct_print",
     * )
     * 
     * @Method({"GET"})
     * 
     * @Template("OfficeBrainCompareProductBundle:CompareProduct:printCompareProduct.html.twig")
     * 
     */
    public function printCompareProductAction()
    {
        $this->initAction();
        //$this->responseArray = array();
        $data   =   $this->request->get('result');
        $data   =    json_decode("$data",true);
        //$this->responseArray['product_id'] = $data['productId'];
        $this->responseArray['QtyValues'] = $data['qty'];
        $this->responseArray['priceProd'] = $data['price'];
        $this->responseArray['record_set'] = $this->compareProductManager->getCompareProduct();
        $this->responseArray['total_record'] = $this->compareProductManager->getTotalCount();
        $this->responseArray['remaining_compare_product'] = $this->comapreProductMaxLimit - $this->responseArray['total_record'];
		
        return $this->responseArray;
    }

    /**
     *
     * @author Employee Id: 4471
     *
     * Desciption: This function allow user check the product column quantity price  
     *
     * @param NULL
     *
     * @return Html Response
     *
     * @throws NULL
     *
     * @Route("/{_locale}/compare-product-price-listing",
     * 	name="office_brain_compareproductbundle_compareproduct_pricelisting"
     * )
     * 
     * @Method({"POST"})
     * 
     * @Template("OfficeBrainCompareProductBundle:CompareProduct:priceListingCompareProduct.html.twig")
     * 
     */
    public function priceListingCompareProductAction()
    {
        $this->initAction();

        $recordSet = $this->compareProductManager->getProductDetailById($this->productId, $this->cultureId);
        $this->responseArray['record_set'] = $recordSet[$this->productId];
        unset($recordSet);
        
        if(isset($this->responseArray['record_set']['price_type']) && $this->responseArray['record_set']['price_type']== 'variations')
        {
        	/*if(isset($this->responseArray['record_set']['variation_pricing']))
        	{
        		$firstVariationDataWithSpecial = array();
        		$count = 0;
        		foreach($this->responseArray['record_set']['variation_pricing'] as $variationId => $variationData)
        		{
        			if($count == 0)
        			{
        				$firstVariationDataWithSpecial = $variationData['pricing']['decorative'];
        			}
        			$count = $count + 1;
        		}
        		if(!(empty($firstVariationDataWithSpecial)))
        		{
        			foreach($firstVariationDataWithSpecial as $firstVariationRangeIndex => $firstVariationRange)
        			{
        				if(isset($firstVariationDataWithSpecial[$firstVariationRangeIndex]['rate']))
        				{
        					$firstVariationDataWithSpecial[$firstVariationRangeIndex]['rate'] = 'N/A';
        				}
        				if(isset($firstVariationDataWithSpecial[$firstVariationRangeIndex]['rate_orig']))
        				{
        					$firstVariationDataWithSpecial[$firstVariationRangeIndex]['rate_orig'] = 'N/A';
        				}
        				if(isset($firstVariationDataWithSpecial[$firstVariationRangeIndex]['code']))
        				{
        					$firstVariationDataWithSpecial[$firstVariationRangeIndex]['code'] = '';
        				}
        				if(isset($firstVariationDataWithSpecial[$firstVariationRangeIndex]['code_orig']))
        				{
        					$firstVariationDataWithSpecial[$firstVariationRangeIndex]['code_orig'] = '';
        				}
        			}
        		}
        		if(!(empty($firstVariationDataWithSpecial)))
        		{
        			foreach($this->responseArray['record_set']['variation_pricing'] as $variationId => $variationData)
        			{
        				//echo "<br/><br/><br/><br/>Variation Changed";
        				$originalData = $variationData['pricing']['decorative'];
        				$this->responseArray['record_set']['variation_pricing'][$variationId]['pricing']['decorative'] = $firstVariationDataWithSpecial;
        				foreach($firstVariationDataWithSpecial as $firstVariationRangeIndex => $firstVariationRange)
        				{
        					//echo "<br/><br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Variation Range Changed";
        					foreach($originalData as $originalDataRangeIndex => $originalDataRange)
        					{
        						//echo "<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;originalDataRange: ".$originalDataRange['from_qty'];
        						//echo "<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;firstVariationRange: ".$firstVariationRange['from_qty'];
        						if($originalDataRange['from_qty'] == $firstVariationRange['from_qty'])
        						{
        							//echo "<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;We are updating original data";
        							$this->responseArray['record_set']['variation_pricing'][$variationId]['pricing']['decorative'][$firstVariationRangeIndex] = $originalDataRange;
        						}
        					}
        				}
        			}
        		}
        	}*/
        	if(isset($this->responseArray['record_set']['variation_pricing_for_other_country']))
        	{
        		foreach($this->responseArray['record_set']['variation_pricing_for_other_country'] as $countryIndex=> $countryCode)
        		{
	        		$firstVariationDataWithSpecial = array();
	        		$firstVariationDataWithoutSpecial= array();
	        		$count = 0;
	        		foreach($this->responseArray['record_set']['variation_pricing_for_other_country'][$countryIndex] as $variationId => $variationData)
	        		{
	        			if($count == 0)
	        			{
	        				$firstVariationDataWithSpecial = $variationData['pricing']['decorative'];
	        				$firstVariationDataWithoutSpecial= $variationData['pricing']['decorative'];
	        			}
	        			$count = $count + 1;
	        		}
	        		// Now update the rate and other things if provided
	        		if(!(empty($firstVariationDataWithSpecial)))
	        		{
	        			foreach($firstVariationDataWithSpecial as $firstVariationRangeIndex => $firstVariationRange)
	        			{
	        				if(isset($firstVariationDataWithSpecial[$firstVariationRangeIndex]['rate']))
	        				{
	        					$firstVariationDataWithSpecial[$firstVariationRangeIndex]['rate'] = 'N/A';
	        					$firstVariationDataWithoutSpecial[$firstVariationRangeIndex]['rate'] = 'N/A';
	        				}
	        				if(isset($firstVariationDataWithSpecial[$firstVariationRangeIndex]['rate_orig']))
	        				{
	        					$firstVariationDataWithSpecial[$firstVariationRangeIndex]['rate_orig'] = 'N/A';
	        					$firstVariationDataWithoutSpecial[$firstVariationRangeIndex]['rate_orig'] = 'N/A';
	        				}
	        				if(isset($firstVariationDataWithSpecial[$firstVariationRangeIndex]['code']))
	        				{
	        					$firstVariationDataWithSpecial[$firstVariationRangeIndex]['code'] = '';
	        					$firstVariationDataWithoutSpecial[$firstVariationRangeIndex]['code'] = '';
	        				}
	        				if(isset($firstVariationDataWithSpecial[$firstVariationRangeIndex]['code_orig']))
	        				{
	        					$firstVariationDataWithSpecial[$firstVariationRangeIndex]['code_orig'] = '';
	        					$firstVariationDataWithoutSpecial[$firstVariationRangeIndex]['code_orig'] = '';
	        				}
	        				
	        				// Remove special data from without special array
	        				unset($firstVariationDataWithoutSpecial[$firstVariationRangeIndex]['rate_orig']);
	        				unset($firstVariationDataWithoutSpecial[$firstVariationRangeIndex]['expired_at']);
	        			}
	        		}
	        		if(!(empty($firstVariationDataWithSpecial)))
	        		{
	        			foreach($this->responseArray['record_set']['variation_pricing_for_other_country'][$countryIndex] as $variationId => $variationData)
	        			{
	        				//echo "<br/><br/><br/><br/>Variation Changed";
	        				$originalData = $variationData['pricing']['decorative'];
	        				
	        				if(isset($this->responseArray['record_set']['variation_pricing_for_other_country'][$countryIndex][$variationId]['pricing']['decorative'][0]['rate_orig']))
	        				{
	        					$this->responseArray['record_set']['variation_pricing_for_other_country'][$countryIndex][$variationId]['pricing']['decorative'] = $firstVariationDataWithSpecial;	
	        				}
	        				else 
	        				{
	        					$this->responseArray['record_set']['variation_pricing_for_other_country'][$countryIndex][$variationId]['pricing']['decorative'] = $firstVariationDataWithoutSpecial;
	        				}
	        				foreach($firstVariationDataWithSpecial as $firstVariationRangeIndex => $firstVariationRange)
	        				{
	        					//echo "<br/><br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Variation Range Changed";
	        					foreach($originalData as $originalDataRangeIndex => $originalDataRange)
	        					{
	        						//echo "<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;originalDataRange: ".$originalDataRange['from_qty'];
	        						//echo "<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;firstVariationRange: ".$firstVariationRange['from_qty'];
	        						if($originalDataRange['from_qty'] == $firstVariationRange['from_qty'])
	        						{
	        							//echo "<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;We are updating original data";
	        							$this->responseArray['record_set']['variation_pricing_for_other_country'][$countryIndex][$variationId]['pricing']['decorative'][$firstVariationRangeIndex] = $originalDataRange;
	        						}
	        					}
	        				}
	        			}
	        		}
        		}
        	}
        }
        //dump($this->responseArray['record_set']['variation_pricing_for_other_country']['us']);exit;

        return $this->responseArray;
    }

    /**
     *
     * @author Employee Id: 4471
     *
     * Desciption: This function allow user check the product price by changing quantity  
     *
     * @param NULL
     *
     * @return Html Response
     *
     * @throws NULL
     *
     * @Route("/{_locale}/compare-product-price-qty",
     * 	name="office_brain_compareproductbundle_compareproduct_priceqty"
     * )
     * 
     * @Method({"POST"})
     * 
     * @Template()
     * 
     */
    public function priceQtyCompareProductAction()
    {
        $this->initAction();
        $this->qty = $this->request->get('qty', null);

        if ($this->qty === null) {
        	$this->responseArray['error_message'] = $this->get('translator')->trans('product_compare.error_message.require_quantity');
        } elseif ($this->qty == 0 || !$this->commonLibraryManager->isInteger($this->qty)) {
        	$this->responseArray['error_message'] = $this->get('translator')->trans('product_compare.error_message.invalid_quantity');
        } elseif ($this->productId && $this->qty) {
        	$price = $this->compareProductManager->getProductPriceByQty($this->productId, $this->cultureId, $this->qty);
        	
        	if ($price != null) {
        		$this->responseArray['status'] = 'success';
        		$this->responseArray['price'] = $price;
        	} else {
        		$recordSet = $this->compareProductManager->getProductDetailById($this->productId, $this->cultureId);
        		$priceType = "decorative";        		
        		if (!isset($recordSet[$this->productId][$priceType]) && isset($recordSet[$this->productId]['blank']) && !empty($recordSet[$this->productId]['blank'])) {
        			$priceType = "blank";
        		}
        		$this->responseArray['error_message'] = $this->get('translator')->trans('product_compare.error_message.invalid_lowest_quantity', array('%min_quantity%'=>$this->commonLibraryManager->getLowestProductQty($recordSet[$this->productId]['pricing'][$priceType])));
        		unset($recordSet);
        	}
        }

		return new JsonResponse($this->responseArray);
    }

    /**
     *
     * @author Employee Id: 4074
     *
     * Desciption: This function allow user go back to page from where he/she came to compare product page.  
     *
     * @param NULL
     *
     * @return 302 Redirection Response
     *
     * @throws NULL
     *
     * @Route("/{_locale}/continue-shopping-from-compare-product",
     * 	name="office_brain_compareproductbundle_compareproduct_continueshopping"
     * )
     * 
     * @Method({"GET"})
     * 
     */
    public function continueShoppingAction()
    {
    	return $this->redirect($this->generateUrl('office_brain_searchbundle_search_continueshopping'));
    	/*
        $this->initAction();
        return $this->redirect($this->compareProductManager->getContinueShoppingUrl());
        */
    }
    
    
    /**
     *
     * @author Employee Id: 4074
     *
     * Desciption: Prepare email html response and send to friend
     *
     * @param NULL
     *
     * @return NULL
     *
     * @throws NULL
     *
     */
    private function sendMailToFriend()
    {
    	$eventKey = 'send_mail_to_friend';
		
    	$this->responseArray['QtyValues'] = json_decode($this->request->get('QtyValues'));
    	$this->responseArray['priceProd'] = json_decode($this->request->get('priceProd'));
    	
    	$this->responseArray['record_set'] = $this->compareProductManager->getCompareProduct();
    	$this->responseArray['total_record'] = $this->compareProductManager->getTotalCount();
    	$this->responseArray['message'] = $this->form['message']->getData();
    	$response = $this->render('OfficeBrainCompareProductBundle:CompareProduct:mailTempleteEmailToFriendCompareProduct.html.twig', $this->responseArray);
    	
    	$templateParameterArray = array(
			'message' => $this->form['message']->getData(),
    		'send_email_to_friend_template' => $response->getContent()
    	);
    	
    	$toEmailData = $this->form['to_email']->getData();
    	$toEmailAry = explode(",", $toEmailData);
    	if(count($toEmailAry) > 0 ){
    		foreach ($toEmailAry as $toEmail){
    			$this->emailManager->sendMail($eventKey, $toEmail, $templateParameterArray, $this->cultureId , $this->form['from_email']->getData());
    		}
    	}
    	
    	unset($eventKey);
    	unset($response);
    	unset($templateParameterArray);
    }
}
