src/project/OfficeBrain/CustomBundle/ProductBundle/Controller/ProductConfigureController.php line 35

Open in your IDE?
  1. <?php
  2. namespace App\project\OfficeBrain\CustomBundle\ProductBundle\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\JsonResponse;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Translation\Translator;
  10. use App\project\OfficeBrain\CustomBundle\ProductBundle\Entity\SellingIdeas;
  11. use App\project\OfficeBrain\CustomBundle\ProductBundle\Form\SellingIdeasType;
  12. use App\project\OfficeBrain\CustomBundle\ProductBundle\Entity\PsaDeal;
  13. use App\project\OfficeBrain\CustomBundle\ProductBundle\Form\PsaDealType;
  14. use App\project\OfficeBrain\CustomBundle\ProductBundle\Entity\QRCode;
  15. use App\project\OfficeBrain\CustomBundle\ProductBundle\Form\QRCodeType;
  16. use App\OfficeBrain\Bundle\ProductBundle\Controller\ProductConfigureController as BaseProductConfigureController;
  17. use App\project\OfficeBrain\CustomBundle\ProductBundle\Entity\ProductAdvertise;
  18. use App\project\OfficeBrain\CustomBundle\ProductBundle\Form\ProductAdvertiseType;
  19. use Symfony\Component\HttpFoundation\Request;
  20. use Symfony\Component\DependencyInjection\ContainerInterface;
  21. use App\OfficeBrain\Bundle\ProductBundle\Manager\Service\ProductAdminManager;
  22. use App\OfficeBrain\Bundle\UserBundle\Manager\Service\UserService;
  23. use App\OfficeBrain\Bundle\ProductBundle\Manager\Service\ProductDetailService;
  24. use App\OfficeBrain\Bundle\ProductBundle\Manager\Service\BrandApiManager;
  25. use App\project\OfficeBrain\CustomBundle\ProductBundle\Manager\Service\ProductDetailService as CustomProductDetailService;
  26. use App\OfficeBrain\Bundle\ProductTagBundle\Manager\Service\ProductTagManager;
  27. use App\OfficeBrain\Bundle\CoreBundle\Service\ArrayToPaginationManager;
  28. use App\OfficeBrain\Bundle\SolrBundle\Manager\Service\SolrService;
  29. use App\OfficeBrain\Bundle\QueueBundle\Manager\Service\ApiManager as QueueApiManager;
  30. /**
  31.  * @Route("/admin/{_locale}/product")
  32.  */
  33. class ProductConfigureController extends BaseProductConfigureController
  34. {
  35.     public function __construct(ContainerInterface $containerProductAdminManager $productAdminManagerUserService $userServiceProductDetailService $productDetailServiceBrandApiManager $brandApiManagerCustomProductDetailService $customProductDetailServiceProductTagManager $productTagManagerArrayToPaginationManager $arrayToPaginationManagerSolrService $solrServiceQueueApiManager $queueApiManager)
  36.     {
  37.         $this->serviceContainer $container;
  38.         $this->productApiManager $productAdminManager;
  39.         $this->userService $userService->getUserExtended();
  40.         $this->productDetailManager $productDetailService->getProductApiExtended();
  41.         $this->brandApiManager $brandApiManager;
  42.         $this->arrayToPaginationManager $arrayToPaginationManager;
  43.         $this->customProductDetailService $customProductDetailService;
  44.         $this->solrService $solrService->getSolrServiceExtended();
  45.         $this->productTagManager $productTagManager->getProductTagManagerExtended();
  46.         $this->queueApiManager $queueApiManager->getQueueInstance();
  47.     }
  48.     const COMMAND_BASIC "bin/console";
  49.     public function init(Request $request)
  50.     {
  51.         parent::init($request);
  52.         // $this->productDetailManager = $this->serviceContainer->get('office_brain_product_detail_manager_custom');
  53.         $this->productDetailManager $this->customProductDetailService->getProductApiExtended();
  54.         $this->cultureCode $this->projectSetting['culture_code'];
  55.     }
  56.     /**
  57.      *
  58.      * @author Employee Id: 5429
  59.      *
  60.      * Description : List action
  61.      *
  62.      * @param  : null
  63.      *
  64.      * @return Array
  65.      *
  66.      * @throws null
  67.      *
  68.      * @Route("/selling-ideas/list/{productId}", name="officebrain_custombundle_productbundle_sellingIdeas_list",
  69.      * requirements={"records_per_page"="12|24|48|100|996","page"="\d+"},
  70.      * defaults={"records_per_page"=100,"page"=1})
  71.      *
  72.      * @Template("project/OfficeBrain/CustomBundle/ProductBundle/ProductAdmin/listSellingIdeas.html.twig")
  73.      *
  74.      **/
  75.     public function listSellingIdeasAction(Request $request$productId)
  76.     {
  77.         $this->init($request);
  78.         $param $this->request->get('_route_params');
  79.         $recordsPerPage $param['records_per_page'];
  80.         $page $this->request->get('page''1');
  81.         $this->responseArray['data'] = $this->productDetailManager->listSellingIdeas($page,$recordsPerPage,$productId);
  82.         //$paginator  = $this->get('knp_paginator');
  83.         //$this->responseArray['pagination'] = $paginator->paginate($this->responseArray['data'], $page, $recordsPerPage);
  84.         $this->responseArray['page']=$page;
  85.         $this->responseArray['productId']=$productId;
  86.         return $this->responseArray;
  87.     }
  88.     
  89.     /**
  90.      * @author Employee Id: 5429
  91.      *
  92.      * Description : This function used for List Product Information
  93.      * @Route("/selling-ideas/add/{productId}",name="officebrain_custombundle_productbundle_sellingIdeas", methods={"GET","POST"})
  94.      * @Template("project/OfficeBrain/CustomBundle/ProductBundle/ProductAdmin/addSellingIdeas.html.twig")
  95.      *
  96.      *
  97.      */
  98.     public function sellingIdeasAction(Request $request$productId)
  99.     {
  100.         $this->init($request);
  101.         $RootDir $this->serviceContainer->get('kernel')->getProjectDir();
  102.         $id $this->request->request->get('id','');
  103.         $SellingIdeasentityobj = new SellingIdeas();
  104.         $SellingIdeasformObj SellingIdeasType::class;
  105.         $ImagePath='';
  106.         if($id>0)
  107.         {
  108.             $SellingIdeasentityobj$this->productDetailManager->sellingIdeasfindById($id);
  109.             $ImagePath=$SellingIdeasentityobj->getPdfPath();
  110.             $SellingIdeasentityobj->setStartDate($SellingIdeasentityobj->getStartDate()->format('m/d/Y'));
  111.             $SellingIdeasentityobj->setEndDate($SellingIdeasentityobj->getEndDate()->format('m/d/Y'));
  112.         }
  113.         $this->form $this->createForm($SellingIdeasformObj$SellingIdeasentityobj, [
  114.             'id' => $id,
  115.         ]);
  116.         $this->form->handleRequest($this->request);
  117.         if($this->form->isSubmitted())
  118.         {
  119.             if ($this->form->isValid())
  120.             {
  121.                 $formdata=$this->form->getdata();
  122.                 $this->productDetailManager->saveSellingIdeas($formdata,$productId,$SellingIdeasentityobj,$RootDir,$ImagePath);
  123.                 $this->get('session')->getFlashBag()->add('success_message'$this->translator->trans('admin.selling_ideas_save_msg'));
  124.                 $response['Message'] = "success";
  125.                 return new JsonResponse($response);
  126.             }
  127.             return new JsonResponse $this->prepareFormJsonError ($this->form) );
  128.         }
  129.         return array('form_selling_ideas'=>$this->form->createView(),'productId'=>$productId,'id'=>$id,'ImagePathedit'=>$ImagePath);
  130.     }
  131.     /**
  132.      * @author Employee Id: 5429
  133.      *
  134.      * Description : This function used for List Product Information
  135.      * @Route("/delete-selling-ideas/",name="officebrain_custombundle_productbundle_sellingIdeas_delete", methods={"GET","POST"})
  136.      * @Template()
  137.      *
  138.      *
  139.      */
  140.     public function deleteSellingIdeasAction(Request $request)
  141.     {
  142.         $this->init($request);
  143.         $id $this->request->request->get('id','');
  144.         $Message $this->productDetailManager->sellingIdeaDdeleteRecords($id);
  145.         $this->get('session')->getFlashBag()->add('success_message'$this->translator->trans('admin.selling_ideas_delete_msg'));
  146.         return new JsonResponse();
  147.         die;
  148.     }
  149.     /**
  150.      *
  151.      * @author Employee Id: 5429
  152.      *
  153.      * Description : List action
  154.      *
  155.      * @param  : null
  156.      *
  157.      * @return Array
  158.      *
  159.      * @throws null
  160.      *
  161.      * @Route("/psa-special/list/{productId}", name="officebrain_custombundle_productbundle_psaSpecial_list",
  162.      * requirements={"records_per_page"="12|24|48|100|996","page"="\d+"},
  163.      * defaults={"records_per_page"=100,"page"=1})
  164.      *
  165.      * @Template("project/OfficeBrain/CustomBundle/ProductBundle/ProductAdmin/listPsaSpecial.html.twig")
  166.      *
  167.      **/
  168.     public function listPsaSpecialAction(Request $request$productId)
  169.     {
  170.         $this->init($request);
  171.         $param $this->request->get('_route_params');
  172.         $recordsPerPage $param['records_per_page'];
  173.         $page $this->request->get('page''1');
  174.         $this->responseArray['data'] = $this->productDetailManager->listPsaSpecial($page,$recordsPerPage,$productId);
  175.         //$paginator  = $this->get('knp_paginator');
  176.         //$this->responseArray['pagination'] = $paginator->paginate($this->responseArray['data'], $page, $recordsPerPage);
  177.         $this->responseArray['page']=$page;
  178.         $this->responseArray['productId']=$productId;
  179.         return $this->responseArray;
  180.     }
  181.     
  182.     /**
  183.      * @author Employee Id: 5429
  184.      *
  185.      * Description : This function used for List Product Information
  186.      * @Route("/psa-special/add/{productId}",name="officebrain_custombundle_productbundle_psaSpecial", methods={"GET","POST"})
  187.      * @Template("project/OfficeBrain/CustomBundle/ProductBundle/ProductAdmin/addPsaSpecial.html.twig")
  188.      * 
  189.      * 
  190.      */
  191.     public function psaSpecialAction(Request $request$productId)
  192.     {
  193.         $this->init($request);
  194.         $RootDir $this->serviceContainer->get('kernel')->getProjectDir();
  195.         $id $this->request->request->get('id','');
  196.         $PsaDealentityobj = new PsaDeal();
  197.         $PsaDealformObj PsaDealType::class;
  198.         $ImagePath='';
  199.         if($id>0)
  200.         {
  201.             $PsaDealentityobj $this->productDetailManager->findById($id);
  202.             $ImagePath=$PsaDealentityobj->getImagePath();
  203.             $PsaDealentityobj->setStartDate($PsaDealentityobj->getStartDate()->format('m/d/Y'));
  204.             $PsaDealentityobj->setEndDate($PsaDealentityobj->getEndDate()->format('m/d/Y'));
  205.         }
  206.         $this->form $this->createForm($PsaDealformObj$PsaDealentityobj, [
  207.             'id' => $id,
  208.         ]);
  209.         $this->form->handleRequest($this->request);
  210.         if($this->form->isSubmitted())
  211.         {
  212.             if ($this->form->isValid())
  213.             {
  214.                 $formdata=$this->form->getdata();
  215.                 $this->productDetailManager->savePsaSpecial($formdata,$productId,$PsaDealentityobj,$RootDir,$ImagePath);
  216.                 $this->get('session')->getFlashBag()->add('success_message'$this->translator->trans('admin.psa_save_msg'));
  217.                 $response['Message'] = "success";
  218.                 return new JsonResponse($response);
  219.             }
  220.             return new JsonResponse $this->prepareFormJsonError ($this->form) );
  221.         }
  222.         return array('form_psa_deal'=>$this->form->createView(),'productId'=>$productId,'id'=>$id,'ImagePathedit'=>$ImagePath);
  223.     }
  224.     private function prepareFormJsonError()
  225.     {
  226.         return array(
  227.                 'form_name' => $this->form->getName(),
  228.                 'form_status' => 'error',
  229.                 'form_errors' => $this->formErrorManager->prepareErrorArray($this->serviceContainer->get('validator')->validate($this->form))
  230.         );
  231.     }
  232.     /**
  233.      * @author Employee Id: 5429
  234.      *
  235.      * Description : This function used for List Product Information
  236.      * @Route("/delete-psa-special/",name="officebrain_custombundle_productbundle_psaSpecial_delete", methods={"GET","POST"})
  237.      * @Template()
  238.      *
  239.      *
  240.      */
  241.     public function deletePsaSpecialAction(Request $request)
  242.     {
  243.         $this->init($request);
  244.         $id $this->request->request->get('id','');
  245.         $Message $this->productDetailManager->deleteRecords($id);
  246.         $this->get('session')->getFlashBag()->add('success_message'$this->translator->trans('admin.psa_management.psa_delete_msg'));
  247.         return new JsonResponse();
  248.         die;
  249.     }
  250.     /**
  251.      *
  252.      * @author Employee Id: 5429
  253.      *
  254.      * Description : List action
  255.      *
  256.      * @param  : null
  257.      *
  258.      * @return Array
  259.      *
  260.      * @throws null
  261.      *
  262.      * @Route("/QRcode/list/", name="office_brain_custom_bundle_qr_code_list",
  263.      * requirements={"records_per_page"="12|24|48|100|996","page"="\d+"},
  264.      * defaults={"records_per_page"=100,"page"=1})
  265.      *
  266.      * @Template("project/OfficeBrain/CustomBundle/ProductBundle/ProductAdmin/listQRcode.html.twig")
  267.      *
  268.      **/
  269.     public function listQRcodeAction(Request $request)
  270.     {
  271.         $this->init($request);
  272.         $param $this->request->get('_route_params');
  273.         $recordsPerPage $param['records_per_page'];
  274.         $page $this->request->get('page''1');
  275.         $this->responseArray['max'] = $this->productDetailManager->MaxQRCodeid();
  276.         $this->responseArray['data'] = $this->productDetailManager->listQRCode($page,$recordsPerPage);
  277.         //$paginator  = $this->get('knp_paginator');
  278.         //$this->responseArray['pagination'] = $paginator->paginate($this->responseArray['data'], $page, $recordsPerPage);
  279.         $this->responseArray['page']=$page;
  280.         return $this->responseArray;
  281.     }
  282.     /**
  283.      * @author Employee Id: 5429
  284.      *
  285.      * Description : This function used for List Product Information
  286.      * @Route("/QRcode/add/",name="officebrain_custombundle_productbundle_qrcodeadd", methods={"GET","POST"})
  287.      * @Template("project/OfficeBrain/CustomBundle/ProductBundle/ProductAdmin/addQRCode.html.twig")
  288.      *
  289.      *
  290.      */
  291.     public function qrCodeAction(Request $request)
  292.     {
  293.         $this->init($request);
  294.         $RootDir $this->serviceContainer->get('kernel')->getProjectDir();
  295.         $id $this->request->request->get('id','');
  296.         $maxid $this->request->request->get('maxid','');
  297.         $PsaDealentityobj = new QRCode();
  298.         $PsaDealformObj QRCodeType::class;
  299.         $qrCodeImagePath='';
  300.         $ImagePath='';
  301.         $LogoImagePath='';
  302.         if($id>0)
  303.         {
  304.             $PsaDealentityobj $this->productDetailManager->qrcodefindById($id);
  305.             $qrCodeImagePath=$PsaDealentityobj->getQrCodeImage();
  306.             $ImagePath=$PsaDealentityobj->getOfferImage();
  307.             $LogoImagePath=$PsaDealentityobj->getlogoImage();
  308.         }
  309.         // $this->form = $this->createForm($PsaDealformObj,$PsaDealentityobj);
  310.         $this->form $this->createForm($PsaDealformObj$PsaDealentityobj, [
  311.             'id' => $id,
  312.         ]);
  313.         $this->form->handleRequest($this->request);
  314.         if($this->form->isSubmitted())
  315.         {
  316.             if ($this->form->isValid())
  317.             {
  318.                 $formdata=$this->form->getdata();
  319.                 $this->productDetailManager->saveQRCode($formdata,$PsaDealentityobj,$RootDir,$qrCodeImagePath,$ImagePath,$LogoImagePath);
  320.                 $this->get('session')->getFlashBag()->add('success_message'$this->translator->trans('admin.qr_save_msg'));
  321.                 $response['Message'] = "success";
  322.                 return new JsonResponse($response);
  323.             }
  324.             return new JsonResponse $this->prepareFormJsonError ($this->form) );
  325.         }
  326.         return array('form_qr_code'=>$this->form->createView(),'id'=>$id,'qrCodeImagePath'=>$qrCodeImagePath,'ImagePathedit'=>$ImagePath,'maxid'=>$maxid,'logoImagePathedit'=>$LogoImagePath);
  327.     }
  328.     /**
  329.      * @author Employee Id: 5429
  330.      *
  331.      * Description : This function used for List Product Information
  332.      * @Route("/delete-qr/",name="officebrain_custombundle_productbundle_qrcode_delete", methods={"GET","POST"})
  333.      * @Template()
  334.      *
  335.      *
  336.      */
  337.     public function deleteQrcodeAction(Request $request)
  338.     {
  339.         $this->init($request);
  340.         $id $this->request->request->get('id','');
  341.         $Message $this->productDetailManager->qrCodedeleteRecords($id);
  342.         $this->get('session')->getFlashBag()->add('success_message'$this->translator->trans('admin.psa_delete_msg'));
  343.         return new JsonResponse();                
  344.         die;
  345.     }
  346.     /**
  347.      * @author Employee Id: 6799
  348.      *
  349.      * Desciption: Get Colors From Inventory
  350.      *
  351.      * @return json Response
  352.      *
  353.      * @Route("/get-product-inventory-colors",
  354.      *     name="officebrain_product_bundle_product_inventory_colors"
  355.      * )
  356.      *
  357.      * @Template("project/OfficeBrain/CustomBundle/ProductBundle/ProductAdmin/productInventoryColors.html.twig")
  358.      */
  359.     public function productInventoryColorsAction(Request $request)
  360.     {
  361.         $this->init($request);
  362.         $itemNo=$this->request->get("itemno");
  363.         $prodctid=$this->request->get("prodctid");
  364.         $this->responseArray['productSku']=$itemNo;
  365.         $this->responseArray['recordSet'][]=$this->productDetailManager->getProductInventoryDetails($itemNo);
  366.         $this->responseArray['productcolor']=$this->productDetailManager->getProductDetailById($prodctid$this->cultureCode);
  367.         /* Color Available Date */
  368.         $inventoryColorDateData=$this->productDetailManager->getProductInventoryColorDateData($itemNo);
  369.         /*if(!empty($inventoryColorDateData)){
  370.             foreach($this->responseArray['recordSet'] as $key=>$inventoryData){
  371.                 if(isset($inventoryData['lstItemInv']['ItemInventory'])){
  372.                     if(isset($inventoryData['lstItemInv']['ItemInventory']['color'])){
  373.                         $dateArrayKey = $this->productDetailManager->searchForColor($inventoryData['lstItemInv']['ItemInventory']['color'][1],$inventoryColorDateData);
  374.                         $this->responseArray['recordSet'][$key]['lstItemInv']['ItemInventory']['availableDate'] = $inventoryColorDateData[$dateArrayKey]['availableDate'];
  375.                     }else{
  376.                         foreach($inventoryData['lstItemInv']['ItemInventory'] as $colorKey=>$colorValue){
  377.                             $dateArrayKey = $this->productDetailManager->searchForColor($colorValue['color'][1],$inventoryColorDateData);
  378.                             $this->responseArray['recordSet'][$key]['lstItemInv']['ItemInventory'][$colorKey]['availableDate'] = $inventoryColorDateData[$dateArrayKey]['availableDate'];
  379.                         }
  380.                     }
  381.                 }
  382.             }
  383.         }*/
  384.         
  385.         if(!empty($inventoryColorDateData)){
  386.             foreach($this->responseArray['recordSet'] as $key=>$inventoryData){
  387.                 if(isset($inventoryData['lstItemInv']['ItemInventory']['color'])){
  388.                     //$dateArrayKey = $this->productDetailManager->searchForColor($inventoryData['lstItemInv']['ItemInventory']['color'][1],$inventoryColorDateData);
  389.                     $dateArrayKey $this->productDetailManager->searchForColor($inventoryData['lstItemInv']['ItemInventory']['color'],$inventoryColorDateData);
  390.                     $this->responseArray['recordSet'][$key]['lstItemInv']['ItemInventory']['availableDate'] = $inventoryColorDateData[$dateArrayKey]['availableDate'];
  391.                 }else{
  392.                     if(isset($inventoryData['lstItemInv']['ItemInventory'])){
  393.                         foreach($inventoryData['lstItemInv']['ItemInventory'] as $colorKey=>$colorValue){
  394.                             //$dateArrayKey = $this->productDetailManager->searchForColor($colorValue['color'][1],$inventoryColorDateData);
  395.                             $dateArrayKey $this->productDetailManager->searchForColor($colorValue['color'],$inventoryColorDateData);
  396.                             if(isset($inventoryColorDateData[$dateArrayKey])){
  397.                             $this->responseArray['recordSet'][$key]['lstItemInv']['ItemInventory'][$colorKey]['availableDate'] = $inventoryColorDateData[$dateArrayKey]['availableDate'];
  398.                             }
  399.                         }
  400.                     }
  401.                 }
  402.             }
  403.         }
  404.         //echo "<pre>";
  405.         //print_r($this->responseArray); die;
  406.         /* EO: Color Available Date */
  407.         return $this->responseArray;
  408.     }
  409.     /**
  410.      * @author Employee Id: 6799
  411.      *
  412.      * Desciption: Get Colors From Inventory
  413.      *
  414.      * @return json Response
  415.      *
  416.      * @Route("/get-product-inventory-colors-submit",
  417.      *     name="officebrain_product_bundle_product_inventory_colors_submit"
  418.      * )
  419.      *
  420.      * @Template("project/OfficeBrain/CustomBundle/ProductBundle/ProductAdmin/productInventoryColors.html.twig")
  421.      */
  422.     public function productInventoryColorsSubmitAction(Request $request)
  423.     {
  424.         $this->init($request);
  425.         $colorValidUntilDate $this->request->get('pricing_valid_until');
  426.         $inventoryColors $this->request->get('inventory_color');
  427.         $productSku $this->request->get('product_sku');
  428.         $returnData $this->productDetailManager->setInventoryColorDate($colorValidUntilDate,$inventoryColors,$productSku);
  429.         if(!empty($returnData)){
  430.             return new JsonResponse(array("status"=>"success","message"=>"Data Successfully Saved.."));;
  431.         }
  432.         else{
  433.             return new JsonResponse(array("status"=>"error","message"=>"There is some error please try again later"));;
  434.         }
  435.     }
  436.     
  437.     /**
  438.      *
  439.      *  @author(Kjethi)
  440.      *
  441.      * Description : List action
  442.      *
  443.      * @param  : null
  444.      *
  445.      * @return Array
  446.      *
  447.      * @throws null
  448.      *
  449.      * @Route("/product-advertise/list/{productId}", name="officebrain_custombundle_productbundle_productadvertise_list",
  450.      * requirements={"records_per_page"="12|24|48|100|996","page"="\d+"},
  451.      * defaults={"records_per_page"=100,"page"=1})
  452.      *
  453.      * @Template("project/OfficeBrain/CustomBundle/ProductBundle/ProductAdmin/listProductAdvertise.html.twig")
  454.      *
  455.      **/
  456.     public function listProductAdvertiseAction(Request $request$productId)
  457.     {
  458.         $this->init($request);
  459.         $param $this->request->get('_route_params');
  460.         $recordsPerPage $param['records_per_page'];
  461.         $page $this->request->get('page''1');
  462.         $this->responseArray['data'] = $this->productDetailManager->listProductAdvertise($page,$recordsPerPage,$productId);
  463.         //$paginator  = $this->get('knp_paginator');
  464.         //$this->responseArray['pagination'] = $paginator->paginate($this->responseArray['data'], $page, $recordsPerPage);
  465.         $this->responseArray['page']=$page;
  466.         $this->responseArray['productId']=$productId;
  467.         $this->responseArray['type']= 'product';
  468. //         print_r($this->responseArray['data']);exit;
  469.         return $this->responseArray;
  470.     }
  471.     /**
  472.      * @author(Kjethi)
  473.      *
  474.      * Description : This function used for Add Product Advertise
  475.      * @Route("/product-advertise/add/{refId}",name="officebrain_custombundle_productbundle_addproductadvertise", methods={"GET","POST"})
  476.      * @Template("project/OfficeBrain/CustomBundle/ProductBundle/ProductAdmin/addProductAdvertise.html.twig")
  477.      *
  478.      */
  479.     public function productAdvertiseAction(Request $request$refId)
  480.     {
  481.         $this->init($request);
  482.         $RootDir $this->serviceContainer->get('kernel')->getProjectDir();
  483.         
  484.         $id $this->request->request->get('id','');
  485.         $type $this->request->request->get('type','product');
  486.         $ProductAdvDealentityobj = new ProductAdvertise();
  487.         $ProductAdvformObj ProductAdvertiseType::class;
  488.         
  489.         $ImagePath='';
  490.         if($id>0)
  491.         {
  492.             $ProductAdvDealentityobj $this->productDetailManager->findProductAdvertiseById($id)[0];
  493.             $ImagePath=$ProductAdvDealentityobj->getUploadImage();
  494.             
  495.         }
  496.         
  497.         $this->form $this->createForm($ProductAdvformObj$ProductAdvDealentityobj, array(
  498.             'id' => $id,
  499.             'type' => $type,
  500.         ));
  501.         $this->form->handleRequest($this->request);
  502.         if($this->form->isSubmitted())
  503.         {
  504.             if ($this->form->isValid())
  505.             {
  506.                 $formdata=$this->form->getdata();
  507.                 $this->productDetailManager->saveProductAdvertise($formdata,$refId,$ProductAdvDealentityobj,$RootDir,$ImagePath);
  508.                 
  509.                 if($id){
  510.                     $this->get('session')->getFlashBag()->add('success_message'$this->translator->trans('admin.productadvertise_update_msg'));
  511.                     
  512.                 }
  513.                 else{
  514.                     
  515.                     $this->get('session')->getFlashBag()->add('success_message'$this->translator->trans('admin.productadvertise_save_msg'));
  516.                 }
  517.                 $response['Message'] = "success";
  518.                 return new JsonResponse($response);
  519.             }
  520.             return new JsonResponse $this->prepareFormJsonError ($this->form) );
  521.         }
  522.         return array('form_psa_deal'=>$this->form->createView(),'refId'=>$refId,'id'=>$id,'ImagePathedit'=>$ImagePath,'type' => $type);
  523.     }
  524.     
  525.     /**
  526.      *
  527.      * @author Kjethi
  528.      *
  529.      * Description : Change Status Product Advertise.
  530.      *
  531.      * 
  532.      *
  533.      * @return type : JsonResponse object
  534.      *
  535.      * @throws Exception: No exception
  536.      *
  537.      * @Route("/product-advertise/change-status", name="officebrain_custombundle_productbundle_productadvertise_change_status",
  538.      * 
  539.      * options={"expose"=true}, methods={"POST"}
  540.      * )
  541.      *
  542.      * @Template()
  543.      *
  544.      */
  545.     public function changeStatusAction(Request $request)
  546.     {
  547.         $this->init($request);
  548.         
  549.         $id $this->request->get('id');
  550.         
  551.         if ($id) {
  552.             $status $this->productDetailManager->productAdvertiseChangeStatus($id);
  553.             if ($status) {
  554.                 return new JsonResponse(array('status' => 'success''status_message' => $this->translator->trans('admin.productadvertise_status_message_success')));
  555.             }
  556.         }
  557.         
  558.         return new JsonResponse(array('status' => 'fail''status_message' => $this->translator->trans('admin.productadvertise_status_message_fail')));
  559.     }
  560.     
  561.     /**
  562.      * @author Kjethi
  563.      *
  564.      * Description : Delete
  565.      * @Route("/delete-product-advertise1",name="officebrain_custombundle_productbundle_productadvertise_product_advertise", methods={"GET","POST"})
  566.      * @Template()
  567.      *
  568.      *
  569.      */
  570.     public function deleteProductAdvertiseAction(Request $request)
  571.     {
  572.         $this->init($request);
  573.         $id $this->request->request->get('id','');
  574.         $Message $this->productDetailManager->deleteProductAdvertiseRecords($id);
  575.         $this->get('session')->getFlashBag()->add('success_message''Advertise deleted successfully');
  576.         return new JsonResponse();
  577.     }
  578.     /**
  579.      * @author 6799
  580.      *
  581.      * Description : Get Esp Product Data
  582.      * @Route("/get-esp-product-data/{productSku}",name="officebrain_custombundle_product_bundle_get_esp_product_data", methods={"GET","POST"})
  583.      * @Template("project/OfficeBrain/CustomBundle/ProductBundle/ProductAdmin/addEspProductData.html.twig")
  584.      *
  585.      *
  586.      */
  587.     public function getEspProductDataAction(Request $request)
  588.     {
  589.         $this->init($request);
  590.         $productSku $this->request->get('productSku','');
  591.         $selectedData $this->productDetailManager->getEspProductData($productSku);
  592.         $this->Response['data']['selected_product_type'] = "";
  593.         if($selectedData){
  594.             $this->Response['data']['selected_categories'] = $selectedData->getEspProductCategory();
  595.             $this->Response['data']['selected_product_type'] = $selectedData->getEspProductType();
  596.         }
  597.         $categoryDataApiUrl "https://productservice.asicentral.com/api/v5/lookup/categorieslist";
  598.         $espCategoriesData $this->productDetailManager->getDataFromEspApi($categoryDataApiUrl);
  599.         $espCategoriesData json_decode($espCategoriesData,true);
  600.         
  601.         $this->Response['data']['categories'] = $espCategoriesData["categories"];
  602.         $typeDataApiUrl ="https://productservice.asicentral.com/api/v5/lookup/producttypes";
  603.         $espProductTypes $this->productDetailManager->getDataFromEspApi($typeDataApiUrl);
  604.         $espProductTypes json_decode($espProductTypes,true);
  605.         $this->Response['data']['product_types'] = $espProductTypes["productTypes"];
  606.         $this->Response['data']['product_sku'] = $productSku;
  607.         
  608.         return $this->Response;
  609.     }
  610.     /**
  611.      * @author 6799
  612.      *
  613.      * Description : SET Esp Product Data
  614.      * @Route("/set-esp-product-data/{productSku}",name="officebrain_custombundle_product_bundle_set_esp_product_data", methods={"GET","POST"})
  615.      * @Template()
  616.      *
  617.      *
  618.      */
  619.     public function setEspProductDataAction(Request $request)
  620.     {
  621.         $this->init($request);
  622.         $productSku $this->request->get("productSku");
  623.         $formData $request->request->all();
  624.         $responseData $this->productDetailManager->setEspProductData($productSku,$formData);
  625.         if(!empty($responseData)){
  626.             $data['status'] = "success_message";
  627.             $data['message'] = "Data Updated Successfully!!";
  628.         }
  629.         else{
  630.             $data['status'] = "error_message";
  631.             $data['message'] = "Something went wrong please try again later!!";
  632.         }
  633.         
  634.         return new JsonResponse($data);
  635.     }
  636.     
  637.     /**
  638.      * @author Employee Id: 6799
  639.      *
  640.      * Description : This function used for Import esp Data
  641.      * @return array
  642.      * @Route("/esp-data-import", name="officebrain_product_esp_data_import"),
  643.      * @Template("project/OfficeBrain/CustomBundle/ProductBundle/ProductAdmin/espDataImport.html.twig")
  644.      */
  645.     
  646.     public function espDataimportAction(Request $request){
  647.         $this->init($request);
  648.         $response null;
  649.         if ($this->request->isXmlHttpRequest() && $this->request->getMethod()=='POST') {
  650.             if(!empty($_FILES)){
  651.                 $file $_FILES["esp_data_file"];
  652.                 $response $this->productDetailManager->importEspProductData($file);
  653.             }
  654.             if($response){
  655.                 $return = array (
  656.                     'status' => 'success',
  657.                     'success_message'=> "Data Successfully Imported",
  658.                 );
  659.             } else {
  660.                 $return = array (
  661.                     'status' => 'error',
  662.                     'error_message' => "Something went wrong please try again later!"
  663.                 );
  664.             }
  665.             return new JsonResponse($return);
  666.         }
  667.         
  668.     }
  669.     /**
  670.      * @author Employee Id: 6799
  671.      *
  672.      * Description : This function used for Export esp Data
  673.      * @return array
  674.      * @Route("/esp-data-export.csv", name="officebrain_product_esp_data_export"),
  675.      * @Template()
  676.      */
  677.     
  678.     public function espDataExportAction(Request $request){
  679.         $this->init($request);
  680.         $responseData $this->productDetailManager->getAllEspProductData();
  681.         $data = array("product_sku","esp_product_type","esp_category");
  682.         $rows[] = implode(','$data);
  683.         foreach($responseData as $espData){
  684.             $rows[] = '"'.$espData->getProductSku().'","'.$espData->getEspProductType().'","'.$espData->getEspProductCategory().'"';
  685.         }
  686.         $content implode("\n"$rows);
  687.         $response = new Response($content);
  688.         $response->headers->set('Content-Type''text/csv');
  689.         return $response;
  690.     }
  691.     
  692.     /**
  693.      * @author Employee Id: 6799
  694.      *
  695.      * @return array
  696.      * @Route("/allowed-user-list", name="office_brain_custom_bundle_allowed_user_list"),
  697.      * @Template("project/OfficeBrain/CustomBundle/ProductBundle/ProductAdmin/allowed_user_list.html.twig")
  698.      */ 
  699.     public function allowedUserListAction(Request $request)
  700.     {
  701.         $this->init($request);  
  702.         $url "https://psservices.aakronline.com/";
  703.         $jsonUsers = @file_get_contents($url."allowed-users");
  704.         $users json_decode($jsonUserstrue);
  705.         return $users;
  706.     }
  707.     
  708.     /**
  709.      * @author Employee Id: 6799
  710.      *
  711.      * @return array
  712.      * @Route("/add-user", name="office_brain_custom_bundle_add_user_allowed"),
  713.      * @Template("project/OfficeBrain/CustomBundle/ProductBundle/ProductAdmin/allowed_user_list.html.twig")
  714.      */ 
  715.     public function addAllowedUserAction(Request $request)
  716.     {
  717.         $this->init($request);  
  718.         $username $this->request->get('username','');
  719.         $password $this->request->get('password',''); 
  720.         $url "https://psservices.aakronline.com/";
  721.         $jsonUsers = @file_get_contents($url."add-user?uu=".$username."&up=".$password);
  722.         $users json_decode($jsonUserstrue);
  723.         if($users['status']==0){
  724.             $message $users['message'];
  725.             $this->get('session')->getFlashBag()->add('error_message'$message);
  726.         }else{
  727.             $message $users['message'];
  728.             $this->get('session')->getFlashBag()->add('success_message'$message);
  729.         }
  730.         
  731.         return $this->redirect($this->generateUrl('office_brain_custom_bundle_allowed_user_list'));
  732.     }
  733.     
  734.     /**
  735.      * @author Employee Id: 6799
  736.      *
  737.      * @return array
  738.      * @Route("/delete-user-list/{id}", name="office_brain_custom_bundle_delete_user_list"),
  739.      * @Template("project/OfficeBrain/CustomBundle/ProductBundle/ProductAdmin/allowed_user_list.html.twig")
  740.      */ 
  741.     public function deleteAllowedUserAction(Request $request)
  742.     {
  743.         $this->init($request);  
  744.         $id $this->request->get('id','');
  745.         $url "https://psservices.aakronline.com/";
  746.         $jsonUsers = @file_get_contents($url."delete-user?indx=".$id);
  747.         $this->get('session')->getFlashBag()->add('success_message''Allowed User deleted successfully');
  748.         return $this->redirect($this->generateUrl('office_brain_custom_bundle_allowed_user_list'));
  749.     }
  750.     
  751.     /**
  752.      * @author Employee Id: 4246
  753.      *
  754.      * Description : This function used for Sync Product data to solr
  755.      *
  756.      * @Route("/sync-product-data",
  757.      * name="officebrain_custom_bundle_product_sync_product_data",
  758.      * options={"expose"=true})
  759.      * @Template("project/OfficeBrain/CustomBundle/ProductBundle/ProductAdmin/syncProductData.html.twig")
  760.      */
  761.     public function syncProductDataAction(Request $request){
  762.         $this->init($request);
  763.         $connection $this->entityManager->getConnection();
  764.         $projectSetting $this->request->get('project_setting');
  765.         $projectId $projectSetting['project_id'];
  766.         list($defaultCulture,$defaultCountry) = explode("_",$this->request->get("_locale"));
  767.         $culture $this->request->get('language',$defaultCulture);
  768.         $country $this->request->get('country',$defaultCountry);
  769.         $supplier_id $this->request->query->get('supplier_id',5);
  770.         $countryArray $this->serviceContainer->getParameter('country');
  771.         $languageArray $this->serviceContainer->getParameter('language');
  772.         
  773.         $supplierData $this->productApiManager->getSupplierNameList($projectId);
  774.         $instanceType $projectSetting['instance_type'];
  775.         //$country_to_pass = array_column($countryArray,'short_name');
  776.         //$language_to_pass = array_keys($languageArray);
  777.         
  778.         // if ($this->user->getUserType()=='admin' && $instanceType=='association'){ // symfony 4
  779.         if ($this->user && $this->user->getUserType()=='admin' && $instanceType=='association'){
  780.             $supplier_id $this->request->query->get('supplier_id','');
  781.         // } else if($this->user->getUserType()=='supplier' || $this->user->getUserType()=='distributor' || ($this->user->getUserType() == 'admin' && $instanceType == 'distributor') || ($this->user->getUserType() == 'admin' && $instanceType == 'supplier')){ // symfony 4
  782.         
  783.         } elseif ($this->user && (
  784.             $this->user->getUserType() == 'supplier' || 
  785.             $this->user->getUserType() == 'distributor' || ( 
  786.                 $this->user->getUserType() == 'admin' && (
  787.                     $instanceType == 'distributor' || 
  788.                     $instanceType == 'supplier'
  789.                 
  790.             ) 
  791.         ) ) {
  792.                 $supplier_id $this->user->getObCustomerId();
  793.                 $supplier_id str_replace(array('OB','ob'), ''$supplier_id);
  794.                 
  795.                 if(empty($supplier_id)){
  796.                     $supplier_id 0;
  797.                 }
  798.         }else{
  799.             $supplier_id 0;
  800.         }
  801.         
  802.         foreach($countryArray as $countryKey => $country){
  803.             $data['country_data'][] = array('id'=>$country['id'],'code'=>$country['short_name'],'title'=>$country['name'],'language'=>$country['language']);
  804.         }
  805.         if ($this->request->isXmlHttpRequest() && $this->request->getMethod()=='POST') {
  806.             $data $this->request->request->all();
  807.             if($data['country_short_name'] != "" && $data['language_short_name'] != ""){
  808.                 $culture $data['language_short_name']."_".$data['country_short_name'];
  809.             }else{
  810.                 $culture $this->request->get("_locale");
  811.             }
  812.             $imprintMethodMasterId $this->serviceContainer->getParameter('imprint_method_master_id');
  813.             $imprintPositionMasterId $this->serviceContainer->getParameter('imprint_position_master_id');
  814.             $packagingTypeMasterId $this->serviceContainer->getParameter('packaging_type_master_id');
  815.             
  816.             /* Data Mapping */
  817.             /*
  818.              $brandData = $this->brandApiManager->doBrandMappingFromProjectId($projectId);
  819.              $attributeData = $this->attributeApiManager->doAttributeMappingFromProjectId($projectId);
  820.              $imprintMethodAttributeData = $this->attributeApiManager->doAttributeMappingFromProjectId($projectId,'imprint_method',$imprintMethodMasterId);
  821.              $imprintLocationAttributeData = $this->attributeApiManager->doAttributeMappingFromProjectId($projectId,'imprint_location',$imprintPositionMasterId);
  822.              $imprintLocationAttributeData = $this->attributeApiManager->doAttributeMappingFromProjectId($projectId,'packaging',$imprintPositionMasterId);
  823.              $attributeMappingData = $this->attributeApiManager->doAttributeMapping();
  824.              $categoryMapping = $this->categoryApiManager->doCategoryMapping($projectId);
  825.              $productCategoryMapping = $this->productApiManager->doProductCategoryMapping($projectId,$data['country_id']);
  826.              */
  827.             /* End Data Mapping */
  828.             $this->phpPath $this->serviceContainer->getParameter('office_brain_ob_solr_operation.php_path');
  829.             $this->applicationPath $this->serviceContainer->getParameter('office_brain_ob_solr_operation.application_path');
  830.             // $command = 'office_brain:solr:sync:product --projectId='.$data["project_id"].' --supplierId='.$data["supplier_id"].' --culture='.$culture.'  > /dev/null 2>/dev/null &'; // symfony 4
  831.             $command $this->phpPath ' ' $this->applicationPath self::COMMAND_BASIC ' ' 'office_brain:solr:sync:product --projectId='.$data["project_id"].' --supplierId='.$data["supplier_id"].' --culture='.$culture;
  832.             $command 'nohup ' $command ' > /dev/null 2>/dev/null &';
  833.             // $command = 'nohup php ' . $this->get('kernel')->getRootDir() . '/console ' .$command ; // symfony 4
  834.             
  835.             shell_exec($command);
  836.             unset($command);
  837.             $statement $connection->prepare(
  838.                'UPDATE `tbl_solar_sync_status` SET  status=0 WHERE id = :id'
  839.             );
  840.             $statement->bindValue('id'1);
  841.             $statement->execute();
  842.             return new JsonResponse(array('status'=>'success','message'=>'Sync is on progress'));
  843.             /*if($output){
  844.                 $time = date('d_m_Y_H_i_s');
  845.                 $fp = fopen($this->get('kernel')->getRootDir()."/../web/solr_logs/solr_sync_error_log_".$time.".txt", 'w+');
  846.                 fwrite($fp, $output);
  847.                 fclose($fp);
  848.                 
  849.                 return new JsonResponse(array('status'=>'success'));
  850.             }else{
  851.                 return new JsonResponse(array('status'=>'fail','message'=>"There is some issue please check after some time"));
  852.             }*/
  853.             
  854.         }
  855.         
  856.          /*$statement = $connection->prepare(
  857.                'UPDATE `tbl_solar_sync_status` SET  status=1 WHERE id = :id'
  858.             );
  859.             $statement->bindValue('id', 1);
  860.             $statement->execute();
  861.           */ 
  862.           // commented for symfony 5
  863.           // $statement = $connection->prepare(
  864.           //       'SELECT status FROM `tbl_solar_sync_status` WHERE id = :id'
  865.           // );
  866.           // $statement->bindValue('id', 1);
  867.           // $statement->execute();
  868.           // $result = $statement->fetchAll();
  869.         $query 'SELECT status FROM tbl_solar_sync_status WHERE id = :id';
  870.         $result $connection->executeQuery($query, ['id' => 1]); 
  871.         $result $result->fetchAllAssociative();
  872.         $data['solar_sync_status']=$result[0]['status'];
  873.         $data['project_id'] = $projectId;
  874.         $data['country_array'] = $countryArray;
  875.         $data['language_data'] = $languageArray;
  876.         $data['supplier_data'] = $supplierData;
  877.         $data['INSTANCE_TYPE'] = $instanceType;
  878.         $data['supplier_id']=$supplier_id;
  879.         
  880.         return array('data'=>$data);
  881.     }
  882.     /**
  883.      * @author Employee Id: 5190
  884.      *
  885.      * Description : This function used for solar sync status
  886.      * @return array
  887.      * @Route("/check-solar-sync-status", name="officebrain_product_check_solar_sync_status"),
  888.      *
  889.      */
  890.     public function checkSolarSyncStatus(Request $request){
  891.       $this->init($request);
  892.       $connection $this->entityManager->getConnection();
  893.       $query 'SELECT status FROM `tbl_solar_sync_status` WHERE id = :id';
  894.       $result $connection->executeQuery($query, ['id' => 1]); 
  895.       $result $result->fetchAllAssociative();
  896.       // $statement->bindValue('id', 1);
  897.       // $statement->execute();
  898.       // $result = $statement->fetchAll();
  899.       $data = array();
  900.       $data['status'] = 'success';
  901.      $data['solar_sync_status']=$result[0]['status'];
  902.       return new JsonResponse($data);
  903.     }
  904.     
  905. }