src/OfficeBrain/Bundle/ProductBundle/Controller/ProductConfigureController.php line 543

  1. <?php
  2. namespace App\OfficeBrain\Bundle\ProductBundle\Controller;
  3. // use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. // use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  6. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Symfony\Component\HttpFoundation\JsonResponse;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Translation\Translator;
  11. use App\OfficeBrain\Bundle\CoreBundle\CustomeHandler as FormErrorManager;
  12. use App\OfficeBrain\Bundle\CoreBundle\Cache\RedisCacheService;
  13. use App\OfficeBrain\Bundle\ProductTagBundle\Entity\ImprintProductMapping;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\DependencyInjection\ContainerInterface;
  16. use App\OfficeBrain\Bundle\ProductBundle\Manager\Service\ProductAdminManager;
  17. use App\OfficeBrain\Bundle\UserBundle\Manager\Service\UserService;
  18. use App\OfficeBrain\Bundle\ProductBundle\Manager\Service\ProductDetailService;
  19. use App\OfficeBrain\Bundle\ProductBundle\Manager\Service\BrandApiManager;
  20. use App\OfficeBrain\Bundle\ProductTagBundle\Manager\Service\ProductTagManager;
  21. use App\OfficeBrain\Bundle\SolrBundle\Manager\Service\SolrService;
  22. use App\OfficeBrain\Bundle\QueueBundle\Manager\Service\ApiManager as QueueApiManager;
  23. use App\OfficeBrain\Bundle\CategoryBundle\Manager\ApiManager as CategoryApiManager;
  24. use Doctrine\Persistence\ManagerRegistry;
  25. /*
  26.  * This class for base functionality related to product admin. @author Office Brain - 4808 <support@officebrain.com>
  27.  */
  28.     // /**
  29.     //  * @Route("/admin/{_locale}/product")
  30.     //  */
  31. #[Route('/admin/{_locale}/product')]
  32. class ProductConfigureController extends AbstractController
  33. {
  34.     public function __construct(ContainerInterface $containerProductAdminManager $productAdminManagerUserService $userServiceProductDetailService $productDetailServiceBrandApiManager $brandApiManagerProductTagManager $productTagManagerSolrService $solrServiceQueueApiManager $queueApiManagerManagerRegistry $doctrine)
  35.     {
  36.         $this->serviceContainer $container;
  37.         $this->productApiManager $productAdminManager;
  38.         $this->userService $userService->getUserExtended();
  39.         $this->productDetailManager $productDetailService->getProductApiExtended();
  40.         $this->brandApiManager $brandApiManager;
  41.         $this->productTagManager $productTagManager->getProductTagManagerExtended();
  42.         $this->solrService $solrService->getSolrServiceExtended();
  43.         $this->queueApiManager $queueApiManager->getQueueInstance();
  44.         $this->doctrine $doctrine;
  45.     }
  46.     CONST PRODUCT_CACHE_CLIENT 'product';
  47.     
  48.    /**
  49.      * @author Employee Id: 4808
  50.      * 
  51.      * Description : This function used for Set and intilize variables and request array
  52.      *
  53.      **/
  54.     public function init(Request $request){
  55.          $this->request $request;
  56.         $this->entityManager $this->doctrine->getManager();
  57.         $this->session $this->request->getSession();
  58.         $this->translator $this->serviceContainer->get('translator');
  59.         $this->formErrorManager = new FormErrorManager\JsonError();
  60.         // $this->productApiManager = $this->serviceContainer->get("office_brain_product_admin_manager");
  61.         $this->productApiManager $this->productApiManager;
  62.         // $this->brandApiManager = $this->serviceContainer->get("officebrain_brand_api_manager");
  63.         $this->brandApiManager $this->brandApiManager;
  64.         $this->categoryApiManager $this->serviceContainer->get("officebrain_category_api_manager");
  65.         // $this->userManager = $this->serviceContainer->get("office_brain_user_manager");
  66.         $this->userManager $this->userService;
  67.         $this->projectSetting $this->request->get('project_setting');
  68.         $this->projectUserSetting $this->request->get('project_user_setting');
  69.         $this->userId $this->projectUserSetting['user_data'] ? $this->projectUserSetting['user_data']->getId() : 0;
  70.         // $this->productDetailManager = $this->serviceContainer->get('office_brain_product_detail_manager');
  71.         $this->productDetailManager $this->productDetailManager;
  72.         $this->productTagManager $this->productTagManager;
  73.         
  74.         $this->user $this->projectUserSetting['user_data'];
  75.         if (!$this->user && $this->request->isXmlHttpRequest()) {
  76.            // throw new AccessDeniedHttpException();
  77.         }
  78.         // if ($this->serviceContainer->has('office_brain_queue_api_manager')) {
  79.         //     $this->request->attributes->set('object', 'Product');
  80.         //     $this->queueApiManager = $this->serviceContainer->get('office_brain_queue_api_manager');
  81.         // }
  82.         if ($this->queueApiManager) {
  83.             $this->request->attributes->set('object''Product');
  84.             $this->queueApiManager $this->queueApiManager;
  85.         }
  86.         
  87.         $this->statsh_cache_wrapper RedisCacheService::create();
  88.         $this->moduleCachePrefix='__RelatedProducts__';
  89.     }
  90.     
  91.     // /**
  92.     //  * @author Employee Id: 4808
  93.     //  *
  94.     //  * Description : This function used for List Product Information
  95.     //  *
  96.     //  * @Route("/list/{page}",
  97.     //  * name="officebrain_bundle_product_list_product_wo_culture",
  98.     //  * requirements={"records_per_page"="12|24|48|100|996", "page"="\d+"},
  99.     //  * defaults={"records_per_page"=100,"page"=1})
  100.     //  *
  101.     //  * @Route("/list/{country}/{language}/{page}",
  102.     //  * name="officebrain_bundle_product_list_product",
  103.     //  * requirements={"records_per_page"="12|24|48|100|996","page"="\d+"},
  104.     //  * defaults={"records_per_page"=20,"page"=1})
  105.     //  * @Template("OfficeBrain/Bundle/ProductBundle/ProductAdmin/list.html.twig")
  106.     //  */
  107.     
  108.     #[Route(
  109.         path'/list/{page}',
  110.         name'officebrain_bundle_product_list_product_wo_culture',
  111.         requirements: ['records_per_page' => '12|24|48|100|996''page' => '\d+'],
  112.         defaults: ['records_per_page' => 100'page' => 1],
  113.         methods: ['GET']
  114.     )]
  115.     #[Route(
  116.         path'/list/{country}/{language}/{page}',
  117.         name'officebrain_bundle_product_list_product',
  118.         requirements: ['records_per_page' => '12|24|48|100|996''page' => '\d+'],
  119.         defaults: ['records_per_page' => 20'page' => 1],
  120.         methods: ['GET']
  121.     )]
  122.     #[Template('OfficeBrain/Bundle/ProductBundle/ProductAdmin/list.html.twig')]
  123.     public function listProductAction(Request $request){
  124.         $this->init($request);
  125.         $projectSetting $this->request->get('project_setting');
  126.         list($defaultCulture,$defaultCountry) = explode("_",$this->request->get("_locale"));
  127.     
  128.         $param $this->request->get('_route_params');
  129.         $culture $this->request->get('language',$defaultCulture);
  130.         $country $this->request->get('country',$defaultCountry);
  131.         $activeCulture $culture;
  132.         $searchStatus $this->request->query->get('search_status''');
  133.         $searchQuery $this->request->query->get('search_query''');
  134.         $sortBy $this->request->query->get('sort''updatedAt');
  135.         $sortType $this->request->query->get('direction''desc');
  136.         $searchParam $this->request->query->get('search_param''');
  137.         $supplier_id $this->request->query->get('supplier_id','');
  138.         $brandIds $this->request->query->get('brand_id','');
  139.         $catIds $this->request->query->get('cat_id','');
  140.         $instanceType $projectSetting['instance_type'];
  141.         $cultureCategory =  $activeCulture "_" $country;
  142.     
  143.         // For Pagination
  144.         $page $this->request->get('page''1');
  145.         $records_per_page $param['records_per_page'];
  146.         $recordsPerPage $this->request->query->get('recordsPerPage',$records_per_page);
  147.         $start_index = (($page 1) * $recordsPerPage 1);
  148.         // End Pagination
  149.         $projectSetting $this->request->get('project_setting');
  150.     
  151.         $projectId $projectSetting['project_id'];
  152.         $productData $this->productApiManager->listProduct($searchStatus,$searchParam$searchQuery$sortType$sortBy,$activeCulture,$country,$supplier_id,$records_per_page,$page,$projectId,$brandIds,$catIds);
  153.         $supplierData $this->productApiManager->getSupplierNameList($projectId);
  154.         $brandData $this->brandApiManager->getList($culture);
  155.         //GET CATEGORY AND SUBCATEGORY
  156.         $categoryAndSubCategoryData $this->categoryApiManager->getList(array($cultureCategory),array(),true);
  157.         $this->catArrayNew = array();
  158.         if ($categoryAndSubCategoryData) {
  159.             foreach($categoryAndSubCategoryData[$cultureCategory] as $catKey=>$categoryAndSubCategory){
  160.                 $this->recursiveCategory($categoryAndSubCategory);
  161.             }
  162.             // Sort Category array using category name
  163.             usort($this->catArrayNew, function ($a$b) {
  164.                 return strcasecmp($a['cat_name'], $b['cat_name']);
  165.             });
  166.         }
  167.         $data['category_SubCategory_data'] = $this->catArrayNew;
  168.         $paginator  $this->serviceContainer->get('knp_paginator');
  169.         $data['pagination'] = $paginator->paginate($productData$page$recordsPerPage);
  170.         $data['page']=$page;
  171.         $data['search_status']=$searchStatus;
  172.         $data['search_query']=$searchQuery;
  173.         $data['sort_by']=$sortBy;
  174.         $data['sort_type']=$sortType;
  175.         $data['search_param']=$searchParam;
  176.         $data['supplier_id']=$supplier_id;
  177.         $data['records_per_page'] = $recordsPerPage;
  178.         $data['supplier_data'] = $supplierData;
  179.         $data['brand_id']=$brandIds;
  180.         $data['cat_id']=$catIds;
  181.         $data['brand_data']= $brandData[$culture];
  182.     
  183.         if(array_key_exists('status',$productData) && $productData['status'] == 'error' && is_array($productData))
  184.         {
  185.             $productSentData = array();
  186.             $data['error_message'] = $productData['error_message'];
  187.         }
  188.         else
  189.         {
  190.             if($productData['data']){
  191.                 $data['total_product'] = $productData['count'];
  192.                 $data['image_url'] = (array_key_exists('image_url',$productData)?$productData['image_url']:'');
  193.                 $productSentData $productData['data'];
  194.             }else{
  195.                 $productSentData = array();
  196.                 $data['error_message'] = $this->serviceContainer->get('translator')->trans("product.RECORD_NOT_FOUND");
  197.             }
  198.         }
  199.     
  200.         $data['params_to_append'] = array_merge($this->request->get('_route_params'), $this->request->query->all());
  201.     
  202.         return array('data'=>$data,'activeCountry' => $country'activeCulture'=>$activeCulture,'productData'=>$productSentData);
  203.     }
  204.     
  205.     
  206.     // /**
  207.     //  * @author Employee Id: 5406
  208.     //  * 
  209.     //  * Description : This function used for List Product Information
  210.     //  * 
  211.     //  * @Route("/list-product-filtered-by-category/{productId}/{page}",
  212.     //  * name="officebrain_bundle_product_list_product_filtered_by_category_wo_culture",
  213.     //  * requirements={"records_per_page"="12|24|48|100|996", "page"="\d+"},
  214.     //  * defaults={"records_per_page"=20,"page"=1})
  215.     //  *
  216.     //  * @Route("/list-product-filtered-by-category/{productId}/{country}/{language}/{page}",
  217.     //  * name="officebrain_bundle_product_list_product_filtered_by_category",
  218.     //  * requirements={"records_per_page"="12|24|48|100|996","page"="\d+"},
  219.     //  * defaults={"records_per_page"=20,"page"=1})
  220.     //  * @Template("OfficeBrain/Bundle/ProductBundle/ProductAdmin/listProductFilteredByCategory.html.twig")
  221.     //  */
  222.     
  223.     #[Route(path'/list-product-filtered-by-category/{productId}/{page}'
  224.             name'officebrain_bundle_product_list_product_filtered_by_category_wo_culture'
  225.             requirements: ['page' => '\d+'], 
  226.             defaults: ['records_per_page' => 20'page' => 1])
  227.     ]
  228.     #[Route(path'/list-product-filtered-by-category/{productId}/{country}/{language}/{page}'
  229.             name'officebrain_bundle_product_list_product_filtered_by_category'
  230.             requirements: ['page' => '\d+'], 
  231.             defaults: ['records_per_page' => 20'page' => 1])
  232.     ]
  233.     #[Template('OfficeBrain/Bundle/ProductBundle/ProductAdmin/listProductFilteredByCategory.html.twig')]
  234.     public function listProductFilteredByCategoryAction(Request $request$productId){
  235.         $this->init($request);
  236.         
  237.         list($defaultCulture,$defaultCountry) = explode("_",$this->request->get("_locale"));
  238.         
  239.         $param $this->request->get('_route_params');
  240.         $culture $this->request->get('language',$defaultCulture);
  241.         $country $this->request->get('country',$defaultCountry);
  242.         $countryId $this->serviceContainer->getParameter('country')[$country]['id'];
  243.         //echo $countryId= $this->country_;exit;
  244.         $activeCulture $culture;
  245.         $searchStatus $this->request->query->get('search_status''');
  246.         $searchQuery $this->request->query->get('search_query''');
  247.         $sortBy $this->request->query->get('sort''updatedAt');
  248.         $sortType $this->request->query->get('direction''desc');
  249.         $searchParam $this->request->query->get('search_param''');
  250.         $supplier_id $this->request->query->get('supplier_id','');
  251.         $brandIds $this->request->query->get('brand_id','');
  252.         $catIds $this->request->query->get('cat_id','');
  253.         
  254.         $cultureCategory =  $activeCulture "_" $country;
  255.         
  256.         // select all of the category ids from categorymapping entity, where product id of entity matches the product id passed in request, and country id of entity matches the country id passed in request
  257.         // then using those category ids we will filter out the products and then we will show only the products coming in these specific categories
  258.         $productCategoryIds $this->productApiManager->getCategoryIds($productId,$countryId);
  259.         $catIds implode(",",$productCategoryIds);
  260.         //print_r($productCategoryIds);exit;
  261.         $comproductreletedid =   $this->productApiManager->productreletedid($productId);
  262.         $productdetails $this->productDetailManager->getProductDetailById($productId,$cultureCategory);
  263.         $product_title $productdetails[$productId]['basic_information']['title'];
  264.         // For Pagination
  265.         $page $this->request->get('page''1');
  266.         $records_per_page $param['records_per_page'];
  267.         $recordsPerPage $this->request->query->get('recordsPerPage',$records_per_page);
  268.         $start_index = (($page 1) * $recordsPerPage 1);
  269.         // End Pagination
  270.         $projectSetting $this->request->get('project_setting');
  271.         
  272.         $projectId $projectSetting['project_id'];
  273.         $instanceType $projectSetting['instance_type'];
  274.         $productData $this->productApiManager->listProduct($searchStatus,$searchParam$searchQuery$sortType$sortBy,$activeCulture,$country,$supplier_id,$records_per_page,$page,$projectId,$brandIds,$catIds);
  275.         
  276.         /* code for not showing the parent product in related products started */
  277.         if(isset($productData['data']))
  278.         {
  279.             $productIndex 0;  
  280.             foreach($productData['data'] as $singleProductDetail)
  281.             {
  282.                 if(isset($singleProductDetail['product_master_id']))
  283.                 {
  284.                     if($singleProductDetail['product_master_id'] == $productId)
  285.                     { 
  286.                         unset($productData['data'][$productIndex]);
  287.                         //$productData['count'] = $productData['count'] - 1;
  288.                     }
  289.                 }
  290.                 $productIndex++;
  291.             }    
  292.         }
  293.         /* code for not showing the parent product in related products ended */
  294.         
  295.         $supplierData $this->productApiManager->getSupplierNameList($projectId);
  296.         $brandData $this->brandApiManager->getList($culture);
  297.         //GET CATEGORY AND SUBCATEGORY
  298.         $categoryAndSubCategoryData $this->categoryApiManager->getList(array($cultureCategory),array(),true);
  299.         $this->catArrayNew = array();
  300.         if ($categoryAndSubCategoryData) {
  301.             foreach($categoryAndSubCategoryData[$cultureCategory] as $catKey=>$categoryAndSubCategory){
  302.                 $this->recursiveCategory($categoryAndSubCategory);
  303.             }
  304.             // Sort Category array using category name
  305.             usort($this->catArrayNew, function ($a$b) {
  306.                 return strcasecmp($a['cat_name'], $b['cat_name']);
  307.             });
  308.         }
  309.         $data['category_SubCategory_data'] = $this->catArrayNew;
  310.         $paginator  $this->serviceContainer->get('knp_paginator');
  311.         $data['pagination'] = $paginator->paginate($productData$page$recordsPerPage);
  312.         $data['page']=$page;
  313.         $data['search_status']=$searchStatus;
  314.         $data['search_query']=$searchQuery;
  315.         $data['sort_by']=$sortBy;
  316.         $data['sort_type']=$sortType;
  317.         $data['search_param']=$searchParam;
  318.         $data['supplier_id']=$supplier_id;
  319.         $data['records_per_page'] = $recordsPerPage;
  320.         $data['supplier_data'] = $supplierData;
  321.         $data['brand_id']=$brandIds;
  322.         $data['cat_id']=$catIds;
  323.         $data['brand_data']= $brandData[$culture];
  324.         $data['INSTANCE_TYPE'] = $instanceType;
  325.         
  326.         if(array_key_exists('status',$productData) && $productData['status'] == 'error' && is_array($productData))
  327.         {
  328.             $productSentData = array();
  329.             $data['error_message'] = $productData['error_message'];
  330.         }
  331.         else
  332.         {
  333.             if($productData['data']){
  334.                 $data['total_product'] = $productData['count'];
  335.                 $data['image_url'] = (array_key_exists('image_url',$productData)?$productData['image_url']:'');
  336.                 $productSentData $productData['data'];
  337.             }else{
  338.                 $productSentData = array();
  339.                 $data['error_message'] = $this->serviceContainer->get('translator')->trans("product.RECORD_NOT_FOUND");
  340.             }
  341.         }
  342.         
  343.         $data['params_to_append'] = array_merge($this->request->get('_route_params'), $this->request->query->all());
  344.         return array('data'=>$data,'activeCountry' => $country'activeCulture'=>$activeCulture,'productData'=>$productSentData,'productId' => $productId,'comproductreletedid'=> $comproductreletedid,'product_title'=>$product_title);
  345.     }
  346.     
  347.     
  348.     // /**
  349.     //  * EMp Id : 4246
  350.     //  * Description : This Function is Used For Update Product Status According To Parameter
  351.     //  *
  352.     //  * @Route("/change-relation-status/{country}/{set_status}",
  353.     //  * requirements = {"set_status"="1|0"},
  354.     //  * name="officebrain_product_change_relation_status")
  355.     //  */
  356.     
  357.     #[Route(path'/change-relation-status/{country}/{set_status}'
  358.         name'officebrain_product_change_relation_status'
  359.         requirements: ['set_status' => '1|0'])]
  360.     public function changeProductRelationStatusAction(Request $request){
  361.         $this->init($request);
  362.         $param=$this->request->get('_route_params');
  363.         $productId=$this->request->get('productId');
  364.         $setStatus=$this->request->get('set_status');
  365.          
  366.         $relatedProductIds = array();
  367.         $relatedProductIds $this->request->get('ids','');
  368.         $relatedProductIds explode("::",$relatedProductIds);
  369.     
  370.         $projectSetting $this->request->get('project_setting');
  371.         $locale_language $projectSetting['locale_language'];
  372.     
  373.         //$productAdminManager = $this->get('office_brain_product_admin_manager');
  374.          
  375.         if($setStatus == 1)
  376.         {
  377.             $productData $this->productApiManager->insertRelatedProducts($productId,$relatedProductIds,$locale_language);
  378.         }
  379.         else if($setStatus == 0)
  380.         {
  381.             $productData $this->productApiManager->deleteRelatedProducts($productId,$relatedProductIds,$locale_language);
  382.         }
  383.     
  384.         $data = array();
  385.         $data['status'] = 'success';
  386.         $data['message'] = $this->translator->trans('product.PRODUCT_RELATION_UPDATED');
  387.         
  388.         RedisCacheService::removeCacheByPrefix($this->statsh_cache_wrapper,$this->moduleCachePrefix);
  389.         
  390.         return new JsonResponse($data);
  391.     }
  392.     
  393.     
  394.     /**
  395.      * Recursive function for category list
  396.      * 
  397.      * @param array $catArray
  398.      */
  399.     public function recursiveCategory($catArray){
  400.         if (array_key_exists("child",$catArray)) {
  401.             foreach($catArray['child'] as $subCatArray){
  402.                 if (array_key_exists("child",$subCatArray)) {
  403.                    foreach ($subCatArray['child'] as $leafCat) {
  404.                        $this->recursiveCategory($leafCat);
  405.                    }
  406.                 }
  407.                 else{
  408.                     $this->catArrayNew[] = $subCatArray;
  409.                 }
  410.             }
  411.         } 
  412.         else {
  413.               $this->catArrayNew[] = $catArray;
  414.         }
  415.     }
  416.     public function deleteCache($productId=0,$culture)
  417.     {
  418.         
  419.         if(!RedisCacheService::isCacheEnable())
  420.         {
  421.             return null;
  422.         }
  423.         $cacheClient=RedisCacheService::create(null,self::PRODUCT_CACHE_CLIENT);
  424.         //echo "===========$productId.':*'.$culture==========";
  425.         
  426.         // $cacheClient->removeCacheByPrefix($productId.':*'.$culture);
  427.     }
  428.     // /**
  429.     //  * @author Employee Id: 4808
  430.     //  * 
  431.     //  * Description : This function used for Add Product Information 
  432.     //  * @return array 
  433.     //  * @Route("/add", name="officebrain_product_add"),
  434.     //  * @Template("OfficeBrain/Bundle/ProductBundle/ProductAdmin/add.html.twig")
  435.     //  */
  436.     
  437.     #[Route(path'/add'name'officebrain_product_add'methods: ['GET''POST'])]
  438.     #[Template("OfficeBrain/Bundle/ProductBundle/ProductAdmin/add.html.twig")]
  439.     public function addAction(Request $request){
  440.         $this->init($request);
  441.         $projectSetting $this->request->get('project_setting');             
  442.         $instanceType $projectSetting['instance_type'];
  443.         
  444.         $cultureName $this->request->get('culture_name');
  445.         $master_product_id $this->request->get('master_product_id''');
  446.         $param $this->request->get('_route_params');
  447.         $route $this->request->get('_route');
  448.         
  449.         $locale_language $param['_locale'];
  450.         $productAddSettings $projectSetting['configuration_rule']['product']['add_update'];
  451.         $supplier_id 0;
  452.         // set global_pricing_keys which are active
  453.         $globalPricingKeys '';        
  454.         if(array_key_exists('global_pricing'$productAddSettings))
  455.         {
  456.             foreach ($productAddSettings['global_pricing'] as $key => $val
  457.             {
  458.                 if ($val['status'] == 1
  459.                 {
  460.                     $globalPricingKeys .= ($val['pricing_box_id'].':'.$val['pricing_box_name']).',';
  461.                 }
  462.             }
  463.         }
  464.         
  465.         //$supplierData = $this->productApiManager->getSupplierNameList($projectSetting['project_id']);        
  466.         
  467.         if ($this->request->isXmlHttpRequest() && $this->request->getMethod()=='POST') {
  468.             $data $this->request->request->all();
  469.             $data['valid_up_to']=str_replace('/','-',$data['valid_up_to']);
  470.             $data['special_price_valid_up_to']=str_replace('/','-',$data['special_price_valid_up_to']);
  471.             $data['pricing_valid_until']=str_replace('/','-',$data['pricing_valid_until']);
  472.             $data['pricing_valid_starting']=str_replace('/','-',$data['pricing_valid_starting']);
  473.             $data['master_product_id'] = $master_product_id;
  474.             $data['project_id'] = $projectSetting['project_id'];
  475.             $data['locale_language'] = $locale_language;
  476.             $data['instance_type'] = $projectSetting['instance_type'];
  477.             $data['instance_id'] = $projectSetting['instance_id'];
  478.             $data['thumb_width'] =  $this->serviceContainer->getParameter('thumb_width');
  479.             $data['medium_thumb_width'] = $this->serviceContainer->getParameter('medium_thumb_width');
  480.   
  481.             $apiResponse =  $this->productApiManager->add($data$cultureName);
  482.             if ($apiResponse['status']=='success') {
  483.                 $response = array('form_status' => $apiResponse['status'],'success_message'=>$this->serviceContainer->get('translator')->trans($apiResponse['success_message']));
  484.                 $this->session->set('product-list-success'$this->serviceContainer->get('translator')->trans($apiResponse['success_message']));
  485.                 
  486.                 $actionPerformed 'create';
  487.                 if ($master_product_id) { 
  488.                     $actionPerformed 'update';
  489.                     /* Remove Cache Of Product Details Page */
  490.                     $statsh_cache_wrapper RedisCacheService::create();
  491.                     $moduleCachePrefix '__ProductDetailsPageOtherProducts';
  492.                     RedisCacheService::removeCacheByPrefix($statsh_cache_wrapper,$moduleCachePrefix."*product_id#".$master_product_id);
  493.                     /* EO: Remove Cache Of Product Details Page */
  494.                 }
  495.                 if($data['product_name']['en']!=$data['old_name']){
  496.                     $this->deleteCache($apiResponse['master_product_id'],'en_us');
  497.                 }
  498.                 
  499.                 //SOLR SYNC CODE START
  500.                 $is_solr_syn_enabled $this->serviceContainer->getParameter('solr_sync');
  501.                 if($is_solr_syn_enabled){
  502.                     $env $this->serviceContainer->getParameter("kernel.environment");
  503.                     $localization_to_update $this->serviceContainer->getParameter('localization_to_fetch');
  504.                     // $this->productApiManager->updateSolrData($apiResponse['master_product_id'],$localization_to_update,$projectSetting['project_id'],$env,'update'); // symfony 4
  505.                     $this->productApiManager->updateSolrData($apiResponse['master_product_id'],$localization_to_update,$projectSetting['project_id'],$env,$projectSetting['instance_id'],'update');
  506.                 }
  507.                 
  508.                 //SOLR SYNC CODE END
  509.                 
  510.                 // To Integrate With ERP
  511.                 $erpIntegration $projectSetting['configuration_rule']['erp_integration'];
  512.                 if($erpIntegration && $erpIntegration['productManagement'] == && !empty($this->queueApiManager)) {
  513.                     $this->productApiManager->integrateWithErp($this->queueApiManager$actionPerformed$apiResponse['master_product_id']);
  514.                 }
  515.                 if($this->request->get('syncflag')==1){ 
  516.                     if($productAddSettings['asi_call']['status']){
  517.                         foreach ($apiResponse['product_slugs'] as $culture => $slug){
  518.                             if($master_product_id 0)
  519.                             {
  520.                                 $this->productDetailManager->updateSyncDetail($this->request->get('syncflag'),$data['sku']);
  521.                                 $asiurl 'http://demoapi.officebrain.com/update_product_api.php?product_slug='.$slug;
  522.                             }
  523.                             else
  524.                             {
  525.                                 $this->productDetailManager->insertSyncDetail($this->request->get('syncflag'),$data['sku']);
  526.                                 $asiurl 'http://demoapi.officebrain.com/product_api.php?product_slug='.$slug;
  527.                             }
  528.                             //echo $asiurl;die;
  529.                             exec("curl '$asiurl' > /dev/null &");
  530.                         }
  531.                     }
  532.                 }
  533.                 else
  534.                 {
  535.                     if($master_product_id 0)
  536.                     {
  537.                         $this->productDetailManager->updateSyncDetail(0,$data['sku']);
  538.                     }
  539.                     else
  540.                     {
  541.                         $this->productDetailManager->insertSyncDetail(0,$data['sku']);
  542.                     }
  543.                     if(isset($data['sku']) && !empty($data['sku'])){
  544.                         $asiurl 'http://demoapi.officebrain.com/product_delete_api.php?product_sku='.$data['sku'];
  545.                         exec("curl '$asiurl' > /dev/null &");
  546.                     }
  547.                 }
  548.                 
  549.             } else {
  550.                 $response = array('form_status' => $apiResponse['status'],'error_message'=>$this->serviceContainer->get('translator')->trans($apiResponse['message']));
  551.             }
  552.             return new JsonResponse($response);
  553.         }
  554.         $data_to_set =  $this->productApiManager->preSetDataForPlugin($projectSetting['configuration_rule']['product'],$projectSetting['project_id'],'',1);
  555.         $this->viewTwigData['plugin_data'] = $data_to_set['plugin_data'];
  556.         $this->viewTwigData['ATTR_TYPE_IDS'] = $this->serviceContainer->getParameter('attributes_types');
  557.         $this->viewTwigData['ATTR_IMPRINT_POSITION'] = $this->serviceContainer->getParameter('imprint_position_master_id');
  558.         $this->viewTwigData['ATTR_COLOR_ID'] = $this->serviceContainer->getParameter('color_attribute_id');        
  559.         $this->viewTwigData['params_to_append'] = array_merge($this->request->get('_route_params'), $this->request->query->all());
  560.         $this->viewTwigData['form_method'] = 'add';
  561.         $this->viewTwigData['global_pricing_keys'] = trim($globalPricingKeys',');
  562.         $this->viewTwigData['INSTANCE_TYPE'] = strtolower($instanceType);
  563.         return $this->viewTwigData;
  564.     }
  565.     
  566.     // /**
  567.     //  * @author Employee Id: 4045
  568.     //  *
  569.     //  * Description : This function used to Edit Product Information
  570.     //  * @return array
  571.     //  * @Route("/edit/{master_product_id}", name="officebrain_product_edit"),
  572.     //  * @Template("OfficeBrain/Bundle/ProductBundle/ProductAdmin/add.html.twig")
  573.     //  */
  574.     
  575.     #[Route(path'/edit/{master_product_id}'name'officebrain_product_edit'methods: ['GET''POST'])]
  576.     #[Template("OfficeBrain/Bundle/ProductBundle/ProductAdmin/add.html.twig")]
  577.     public function editNewAction(Request $request){
  578.         $this->init($request);
  579.         $projectSetting $this->request->get('project_setting');
  580.         $countryArray $this->serviceContainer->getParameter('country');
  581.         $languageArray $this->serviceContainer->getParameter('language');
  582.         $country_to_pass array_column($countryArray,'short_name');
  583.         $language_to_pass array_keys($languageArray);
  584.         $locale $this->request->get('_locale',$this->serviceContainer->getParameter('locale'));
  585.         @list($default_language,$default_country) = explode("_",$locale);
  586.         $cultureName $this->request->get('culture_name');
  587.         $masterProductId $this->request->get('master_product_id''');
  588.         $param $this->request->get('_route_params');
  589.         $route $this->request->get('_route');
  590.         $quoteId $this->request->get('quote_id',0);
  591.         
  592.         // set global_pricing_keys which are active
  593.         $globalPricingKeys '';
  594.         $productAddSettings $projectSetting['configuration_rule']['product']['add_update'];
  595.         if(array_key_exists('global_pricing'$productAddSettings))
  596.         {
  597.             foreach ($productAddSettings['global_pricing'] as $key => $val)
  598.             {
  599.                 if ($val['status'] == 1)
  600.                 {
  601.                     $globalPricingKeys .= ($val['pricing_box_id'].':'.$val['pricing_box_name']).',';
  602.                 }
  603.             }
  604.         }
  605.         $productInfo $this->productApiManager->editView($masterProductId,$language_to_pass,$country_to_pass,$default_language);
  606.         $syncentityobj$this->productDetailManager->getSyncDetail($productInfo['en']['basic_information']['sku_number']);
  607.        //$supplierData = $this->productApiManager->getSupplierNameList($projectSetting['project_id']);
  608.         if(isset($syncentityobj))
  609.         {
  610.             $productInfo['syncflag']=$syncentityobj['isSync'];
  611.         }
  612.         else
  613.         {
  614.             $productInfo['syncflag']=0;
  615.         }
  616.         if(!count($productInfo)){
  617.             throw $this->createNotFoundException('The product does not exist');
  618.         }
  619.         
  620.         $data_to_set =  $this->productApiManager->preSetDataForPlugin($projectSetting['configuration_rule']['product'], $projectSetting['project_id'],$productInfo);
  621.         $this->viewTwigData['plugin_data'] = $data_to_set['plugin_data'];
  622.         $this->viewTwigData['ATTR_TYPE_IDS'] = $this->serviceContainer->getParameter('attributes_types');
  623.         $this->viewTwigData['ATTR_IMPRINT_POSITION'] = $this->serviceContainer->getParameter('imprint_position_master_id');
  624.         $this->viewTwigData['ATTR_COLOR_ID'] = $this->serviceContainer->getParameter('color_attribute_id');
  625.         $this->viewTwigData['params_to_append'] = array_merge($this->request->get('_route_params'), $this->request->query->all());
  626.         $this->viewTwigData['master_product_id'] = $masterProductId;
  627.         $this->viewTwigData['form_method'] = 'edit';
  628.         $this->viewTwigData['global_pricing_keys'] = trim($globalPricingKeys',');
  629.         return $this->viewTwigData;
  630.     }
  631.     // /**
  632.     //  * @author: Employee Id : 4808
  633.     //  * Description: This Function is Related For Image Library
  634.     //  *
  635.     //  * @Route("/image-library",name="officebrain_product_image_library"),
  636.     //  * @Template("OfficeBrain/Bundle/ProductBundle/ProductAdmin/imageLibrary.html.twig")
  637.     //  */
  638.     
  639.     #[Route(path'/image-library'name'officebrain_product_image_library'methods: ['GET'])]
  640.     #[Template("OfficeBrain/Bundle/ProductBundle/ProductAdmin/imageLibrary.html.twig")]
  641.     public function imageLibraryAction(Request $request){
  642.         //TODO: need to get dynamic product once listing get done
  643.        $this->init($request);
  644.        $this->viewTwigData['data']=array('productId'=>1);
  645.         $mainErrorMessage='';
  646.         $isImageUploaded false;
  647.         if ($this->request->getMethod() == "POST" ) {
  648.             $request $request;
  649.             $fileData $request->files->get("FileUpload");
  650.             $zipData $request->files->get("zipUpload");
  651.             $fileUploadType $request->get('FileUpload_type');
  652.             //TODO: need to get dynamic product once listing get done
  653.             $productId 1;
  654.             $index 0;
  655.             $imageArray = array();
  656.             foreach($fileData as $image){
  657.                 foreach($image as $v){
  658.                     if(!empty($v)){
  659.                         $isImageUploaded true;
  660.                         break;
  661.                     }
  662.                 }
  663.                 if($isImageUploaded) break;
  664.             }
  665.             if(!$isImageUploaded){
  666.                 foreach($zipData as $image){
  667.                     foreach($image as $v){
  668.                         if(!empty($v)){
  669.                             $isImageUploaded true;
  670.                             break;
  671.                         }
  672.                     }
  673.                     if($isImageUploaded) break;
  674.                 }
  675.             }
  676.             $mainErrorMessage='';
  677.             if(!$isImageUploaded){
  678.                 $mainErrorMessage =  $this->serviceContainer->get('translator')->trans('admin.image_template_library.select_files_error_msg');
  679.             }
  680.             $res =  $this->productApiManager->uploadfiles($productId$fileData,'image',$fileUploadType);
  681.             $error_file_upload $res['error_file_upload'];
  682.             $res $this->productApiManager->uploadfiles($productId$zipData,'zip');
  683.             $error_file_upload_zip $res['error_file_upload'];
  684.         }
  685.         $errMsg '';
  686.         $successMsg '';
  687.         if (!empty($error_file_upload) || !empty($error_file_upload_zip)) {
  688.             $errMsg '<ul>';
  689.             $arrImgType = array('web' => 'Web''template' => 'Template''high_res' => 'High Res');
  690.             foreach ($arrImgType as $type => $files) {
  691.                 if (isset($error_file_upload[$type]) || isset($error_file_upload_zip[$type])) {
  692.                     $errMsg.="<li>" $files "<ul>\n";
  693.                     if (isset($error_file_upload[$type])) {
  694.                         foreach ($error_file_upload[$type] as $fileName => $error) {
  695.                             $errMsg.="<li>" $fileName ":<i><b>" $error "</b></i></li>";
  696.                         }
  697.                     }
  698.                     if (isset($error_file_upload_zip[$type])) {
  699.                         foreach ($error_file_upload_zip[$type] as $fileName => $error) {
  700.                             $errMsg.="<li>" $fileName ":<i><b>" $error "</b></i></li>";
  701.                         }
  702.                     }
  703.                     $errMsg.="</ul></li>";
  704.                 }
  705.             }
  706.             $errMsg.='</ul>';
  707.         }elseif($mainErrorMessage != '' ){
  708.             $errMsg '<ul><li>'.$mainErrorMessage.'</li></ul>';
  709.         }elseif($isImageUploaded){
  710.             $successMsg $this->serviceContainer->get('translator')->trans('admin.image_template_library.upload_succ');
  711.         }
  712.        return $this->viewTwigData;
  713.     }
  714.     // /**
  715.     //  * @Route("/browse-product-image", name="OfficeBrainImageLibraryAdmin_browse_product_image", methods={"POST"})
  716.     //  * @Template("OfficeBrain/Bundle/ProductBundle/ProductAdmin/browseProductImage.html.twig")
  717.     //  */
  718.     
  719.     #[Route(path'/browse-product-image'name'OfficeBrainImageLibraryAdmin_browse_product_image'methods: ['POST'])]
  720.     #[Template("OfficeBrain/Bundle/ProductBundle/ProductAdmin/browseProductImage.html.twig")]
  721.     public function browseProductImageAction(Request $request) {
  722.         $this->init($request);
  723.         $this->request $request;
  724.         $productId intval($this->request->get('id'));
  725.         $imageType $this->request->get('type');
  726.         $data $this->productApiManager->productImages($productId,$imageType);
  727.         $imageArray = array();
  728.         if($data){
  729.             if($imageType =='high_res'){
  730.                 foreach($data as $image){
  731.                     
  732.                     if(trim($image['fileType'])!='imprinted')
  733.                         $imageArray['blank'][]=$image;
  734.                     else
  735.                         $imageArray['imprinted'][]=$image;
  736.                 }
  737.             } else {
  738.                 $imageArray $data;
  739.             }
  740.         }
  741.         return array('imageArray' => $imageArray'imageType' => $imageType);
  742.     }
  743.     // /**
  744.     //  * @Route("/remove-product-image",
  745.     //  * name="officebrain_image_library_admin_bundle_remove_product_image", methods={"GET","POST"}),
  746.     //  * @Template()
  747.     //  */
  748.     
  749.     #[Route(path'/remove-product-image'name'officebrain_image_library_admin_bundle_remove_product_image'methods: ['GET''POST'])]
  750.     #[Template()]
  751.     public function removeProductImageAction(Request $request) {
  752.         $this->init($request);
  753.         $productId $this->request->get('productId');
  754.         $imageType $this->request->get('imageType');
  755.         $imageId $this->request->get('imageId');
  756.         
  757.         $result $this->productApiManager->removeProductImage($productId,$imageId);
  758.         if ($result)
  759.             echo $this->serviceContainer->get('translator')->trans('admin.image_template_library.image_removed_succ');
  760.         else
  761.             echo $this->serviceContainer->get('translator')->trans('admin.image_template_library.image_removed_fail');
  762.     }
  763.     // /**
  764.     //  * @author Employee Id: 4246
  765.     //  * Description : This function used for View Product Information
  766.     //  * @Route("/view",
  767.     //  * name="officebrain_product_view")
  768.     //  * @Template("OfficeBrain/Bundle/ProductBundle/ProductAdmin/view.html.twig")
  769.     //  */
  770.     
  771.     #[Route(path'/view'name'officebrain_product_view')]
  772.     #[Template('OfficeBrain/Bundle/ProductBundle/ProductAdmin/view.html.twig')]
  773.     public function viewAction(Request $request){
  774.         $this->init($request);
  775.         $product_culture $this->request->get('product_culture');
  776.         $product_ids $this->request->get('product_ids');
  777.         //$productAdminManager = $this->get('office_brain_product_admin_manager');
  778.         $productData $this->productApiManager->view($product_ids,$product_culture,true);
  779.         
  780.         $projectSetting $this->request->get('project_setting');
  781.         $productAddSettings $projectSetting['configuration_rule']['product']['add_update'];
  782.         if(array_key_exists('global_pricing'$productAddSettings))
  783.         {
  784.             foreach ($productAddSettings['global_pricing'] as $key => $val)
  785.             {
  786.                 if ($val['status'] == 1)
  787.                 {
  788.                     $global_pricing_arr[$key] = 1;
  789.                 }
  790.             }
  791.         }
  792.         
  793.         $culture_id $this->request->get('culture_id');
  794.         if(!count($productData)){
  795.             throw $this->createNotFoundException('The product does not exist');
  796.         }
  797.         if($productData['status'] == "success"){
  798.             $productInfo $productData['data'];
  799.             if(array_key_exists('price_unit',$productInfo[$product_ids])){
  800.                 $priceUnit $this->serviceContainer->getParameter('price_unit');
  801.                 $productInfo[$product_ids]['price_unit'] = array_key_exists(trim($productInfo[$product_ids]['price_unit']),$priceUnit)?$priceUnit[$productInfo[$product_ids]['price_unit']]:$productInfo[$product_ids]['price_unit'];
  802.             }
  803.             $this->viewTwigData['data'] = $productInfo[$product_ids];
  804.         }else{
  805.             $this->viewTwigData['error_message'] = $this->serviceContainer->get('translator')->trans('product.'.$productData['message']);
  806.         }
  807.         $this->viewTwigData['params_to_append'] = array_merge($this->request->get('_route_params'), $this->request->query->all());
  808.         $this->viewTwigData['global_pricing_arr'] = $global_pricing_arr;
  809.         return $this->viewTwigData;
  810.     }
  811.     // /**
  812.     //  * @author Employee Id: 4246
  813.     //  * Description : This function used for Delete Product
  814.     //  * @Route("/delete",
  815.     //  * name="officebrain_product_delete")
  816.     //  */
  817.     
  818.     #[Route(path'/delete'name'officebrain_product_delete')]
  819.     public function deleteAction(Request $request){
  820.         $this->init($request);
  821.         $product_master_id $this->request->get('product_master_id');
  822.         $product_country $this->request->get('product_country');
  823.         $projectSetting $this->request->get('project_setting');
  824.         $project_id $projectSetting['project_id'];
  825.         $locale_language $projectSetting['locale_language'];
  826.         $supplier_id $projectSetting['user_id'];
  827.         $instance_type $projectSetting['instance_type'];
  828.         $instance_id $projectSetting['instance_id'];
  829.         $productData $this->productApiManager->delete($product_master_id$project_id$supplier_id$locale_language$instance_type$instance_id$product_country);
  830.         // Data Array Convert Object To Array
  831.         $productData['data'] = (array)$productData['data'];
  832.         if($productData['status'] == 'success'){
  833.             $data['status'] = 'success_message';
  834.             //SOLR SYNC CODE START
  835.              $is_solr_syn_enabled $this->serviceContainer->getParameter('solr_sync');
  836.              if($is_solr_syn_enabled){
  837.                  $env $this->serviceContainer->getParameter("kernel.environment");
  838.                  $localization_to_update $this->serviceContainer->getParameter('localization_to_fetch');
  839.                  $this->productApiManager->updateSolrData($product_master_id,$localization_to_update,$projectSetting['project_id'],$env,'delete');
  840.              }
  841.             //SOLR SYNC CODE END
  842.                 
  843.             // To Integrate with ERP
  844.             $erpIntegration $projectSetting['configuration_rule']['erp_integration'];
  845.             if($erpIntegration && $erpIntegration['productManagement'] == && !empty($this->queueApiManager)) {
  846.                 $dt = new \DateTime($productData['data']['deleted_at']);
  847.                 $params = array('product_id' => $product_master_id'country_id' => $productData['data']['country_id'], 'deleted_at'=> $dt->format('Y-m-d H:i:s'));
  848.                 $this->productApiManager->integrateWithErp($this->queueApiManager'remove'$product_master_id$params);
  849.             }
  850.         }else{
  851.             $data['status'] = 'error_message';
  852.         }
  853.         $data['message'] = $this->translator->trans($productData['message']);
  854.         return new JsonResponse($data);
  855.     }
  856.     
  857.     // /**
  858.     //  * EMp Id : 4246
  859.     //  * Description : This Function is Used For Update Product Status According To Parameter
  860.     //  * 
  861.     //  * @Route("/changestatus/{country}/{set_status}",
  862.     //  * requirements = {"set_status"="1|0"},
  863.     //  * name="officebrain_product_changestatus")
  864.     //  */
  865.     
  866.     #[Route(
  867.         path'/changestatus/{country}/{set_status}',
  868.         name'officebrain_product_changestatus',
  869.         requirements: ['set_status' => '1|0']
  870.     )]
  871.     public function changeProductStatusAction(Request $request){
  872.         $this->init($request);
  873.         $param=$this->request->get('_route_params');
  874.         
  875.         $ids_to_pass = array();
  876.         $ids $this->request->get('ids','');
  877.         $ids_to_pass explode("::",$ids);
  878.         $productId json_encode($ids_to_pass);
  879.         
  880.         list($defaultCulture,$defaultCountry) = explode("_",$this->request->get("_locale"));
  881.         $projectSetting $this->request->get('project_setting');
  882.         $culture $this->request->get('language',$defaultCulture);
  883.         $country $this->request->get('country');
  884.         $setStatus $this->request->get('set_status');
  885.         $cultureCategory =  $culture"_" $country;
  886.         
  887.         $project_id $projectSetting['project_id'];
  888.         $locale_language $projectSetting['locale_language'];
  889.         $supplier_id $projectSetting['user_id'];
  890.         $instance_type $projectSetting['instance_type'];
  891.         $instance_id $projectSetting['instance_id'];
  892.         
  893.         //$productAdminManager = $this->get('office_brain_product_admin_manager');
  894.         $productData $this->productApiManager->changeProductStatus($productId,$country,$setStatus$project_id$supplier_id$locale_language$instance_type$instance_id);
  895.         $data = array();
  896.         if($productData['status'] == 'success'){            
  897.             //SOLR SYNC CODE START
  898.             $is_solr_syn_enabled $this->serviceContainer->getParameter('solr_sync');
  899.             if($is_solr_syn_enabled){
  900.                 $env $this->serviceContainer->getParameter("kernel.environment");
  901.                 $localization_to_update $this->serviceContainer->getParameter('localization_to_fetch');
  902.                 // $solrProductManager = $this->serviceContainer->get('office_brain_solr_product_mapping_manager');
  903.                 $solrProductManager $this->solrService;
  904.                 foreach($ids_to_pass as $product_id_to_process){
  905.                     if(!$setStatus){
  906.                         $this->productApiManager->updateSolrData($product_id_to_process,$localization_to_update,$projectSetting['project_id'],$env$instance_id,'delete');
  907.                         $productdetails $this->productDetailManager->getProductDetailById($product_id_to_process,$cultureCategory);
  908.                         
  909.                         if(strpos($productdetails[$product_id_to_process]['basic_information']['sku_number'], '-') != false && isset($productdetails[$product_id_to_process]['other_products'])){
  910.                             $main_sku $productdetails[$product_id_to_process]['basic_information']['sku_number'];
  911.                             $main_sku explode('-'$main_sku); // get main sku
  912.                             $mainSku $main_sku[1];                 
  913.                             if(isset($productdetails[$product_id_to_process]['other_products']) && is_array($productdetails[$product_id_to_process]['other_products'])){
  914.                                 $sortOrder = array($mainSku'80-'.$mainSku,'75-'.$mainSku'76-'.$mainSku'81-'.$mainSku,'82-'.$mainSku,'86-'.$mainSku'10-'.$mainSku'42-'.$mainSku'20-'.$mainSku'28-'.$mainSku'25-'.$mainSku );
  915.                                 usort($productdetails[$product_id_to_process]['other_products'], function ($a$b) use ($sortOrder) {
  916.                                     $pos_a array_search($a['sku_number'], $sortOrder);
  917.                                     $pos_b array_search($b['sku_number'], $sortOrder);
  918.                                     return $pos_a $pos_b;
  919.                                 });
  920.                                 
  921.                             }
  922.                             else{
  923.                                 $productdetails[$product_id_to_process]['other_products'] = null;
  924.                             }
  925.                             // Update other Products
  926.                             if(isset($productdetails[$product_id_to_process]['other_products']) && !empty($productdetails[$product_id_to_process]['other_products'])){
  927.                                 foreach($productdetails[$product_id_to_process]['other_products'] as $otherProduct){
  928.                                     if( $otherProduct['id'] == $product_id_to_process ){
  929.                                         $this->productApiManager->updateSolrData($otherProduct['id'],$localization_to_update,$projectSetting['project_id'],$env$instance_id,'delete');
  930.                                     }
  931.                                     else{
  932.                                         $this->productApiManager->updateSolrData($otherProduct['id'],$localization_to_update,$projectSetting['project_id'],$env$instance_id,'update');
  933.                                     }
  934.                                 }
  935.                             }
  936.                         }
  937.                         // update main sku
  938.                         // if($productdetails[$product_id_to_process]['basic_information']['sku_number']){
  939.                         //     $sku_split = explode('-',$productdetails[$product_id_to_process]['basic_information']['sku_number']);
  940.                         //     if(count($sku_split) == 2){
  941.                         //         $productDetailArray =$this->productDetailManager->getProductDetailBySku($sku_split[1],$productdetails[$product_id_to_process]['supplier']['supplier_id'],$cultureCategory);
  942.                         //         $this->productApiManager->updateSolrData($productDetailArray['product_id'],$localization_to_update,$projectSetting['project_id'],$env,'update');
  943.                                 
  944.                         //     }
  945.                         // }
  946.                     }else{
  947.                         $this->productApiManager->updateSolrData($product_id_to_process,$localization_to_update,$projectSetting['project_id'],$env$instance_id,'update');
  948.                         $productdetails $this->productDetailManager->getProductDetailById($product_id_to_process,$cultureCategory);
  949.                         
  950.                         // Update other Products
  951.                         if(strpos($productdetails[$product_id_to_process]['basic_information']['sku_number'], '-') != false && isset($productdetails[$product_id_to_process]['other_products'])){
  952.                             $main_sku $productdetails[$product_id_to_process]['basic_information']['sku_number'];
  953.                             $main_sku explode('-'$main_sku); // get main sku
  954.                             $mainSku $main_sku[1];                 
  955.                             if(isset($productdetails[$product_id_to_process]['other_products']) && is_array($productdetails[$product_id_to_process]['other_products'])){
  956.                                 $sortOrder = array($mainSku'80-'.$mainSku,'75-'.$mainSku'76-'.$mainSku'81-'.$mainSku,'82-'.$mainSku,'86-'.$mainSku'10-'.$mainSku'42-'.$mainSku'20-'.$mainSku'28-'.$mainSku'25-'.$mainSku );
  957.                                 usort($productdetails[$product_id_to_process]['other_products'], function ($a$b) use ($sortOrder) {
  958.                                     $pos_a array_search($a['sku_number'], $sortOrder);
  959.                                     $pos_b array_search($b['sku_number'], $sortOrder);
  960.                                     return $pos_a $pos_b;
  961.                                 });
  962.                                 
  963.                             }
  964.                             else{
  965.                                 $productdetails[$product_id_to_process]['other_products'] = null;
  966.                             }
  967.                         }
  968.                         if(isset($productdetails[$product_id_to_process]['other_products']) && !empty($productdetails[$product_id_to_process]['other_products'])){
  969.                             $index 1;
  970.                             $isFound 0;
  971.                             $operation 'update';
  972.                             foreach($productdetails[$product_id_to_process]['other_products'] as $otherProduct){
  973.                                 if($index == && $otherProduct['id'] == $product_id_to_process){
  974.                                     $isFound 1;
  975.                                     $operation 'update';
  976.                                 }
  977.                                 elseif( $index && $otherProduct['id'] == $product_id_to_process){
  978.                                     $isFound 1;
  979.                                     $operation 'delete';
  980.                                 }
  981.                                 elseif($isFound == 1){
  982.                                     $operation 'delete';
  983.                                 }
  984.                                 else{
  985.                                     $operation 'update';
  986.                                 }
  987.                                 $this->productApiManager->updateSolrData($otherProduct['id'],$localization_to_update,$projectSetting['project_id'],$env$instance_id,$operation);
  988.                                 if($operation == 'delete'){
  989.                                     $this->productApiManager->updateSolrData($otherProduct['id'],$localization_to_update,$projectSetting['project_id'],$env$instance_id,'update');
  990.                                 }
  991.                                 $index++;
  992.                             }
  993.                         }
  994.                         
  995.                         // if($productdetails[$product_id_to_process]['basic_information']['sku_number']){
  996.                         //     $sku_split = explode('-',$productdetails[$product_id_to_process]['basic_information']['sku_number']);
  997.                         //     if(count($sku_split) == 2){
  998.                         //         $productDetailArray =$this->productDetailManager->getProductDetailBySku($sku_split[1],$productdetails[$product_id_to_process]['supplier']['supplier_id'],$cultureCategory);
  999.                         //         $this->productApiManager->updateSolrData($productDetailArray['product_id'],$localization_to_update,$projectSetting['project_id'],$env,'update');
  1000.                         //     }
  1001.                         // }
  1002.                     }
  1003.                 }
  1004.             }
  1005.             //SOLR SYNC CODE END
  1006.             
  1007.             // To Integrate with ERP
  1008.             $productIds json_decode($productId);
  1009.             $erpIntegration $projectSetting['configuration_rule']['erp_integration'];
  1010.             if($erpIntegration && $erpIntegration['productManagement'] == && !empty($this->queueApiManager)) {
  1011.                 foreach ($productData['data'] as $key => $value) {
  1012.                     $params = array('product_id' => $productIds[$key], 'country_id' => $value['countryId'],'status'=> $setStatus);
  1013.                     $this->productApiManager->integrateWithErp($this->queueApiManager'updateStatus'$productIds[$key], $params);
  1014.                 }
  1015.             }
  1016.             $data['status'] = 'success';
  1017.             RedisCacheService::removeCacheByPrefix($this->statsh_cache_wrapper,$this->moduleCachePrefix);
  1018.             
  1019.         }else{
  1020.             $data['status'] = 'error';
  1021.         }
  1022.         $data['message'] = $this->translator->trans('product.'.$productData['message']);
  1023.         return new JsonResponse($data);
  1024.     }
  1025.     
  1026.     // /**
  1027.     //  * EMp Id : 4246
  1028.     //  * Description : This Function is Used For Update Product Status According To Parameter
  1029.     //  *
  1030.     //  * @Route("/check-duplicate-sku",
  1031.     //  * name="officebrain_product_check_duplicate_sku")
  1032.     //  */
  1033.     
  1034.     #[Route(path'/check-duplicate-sku'name'officebrain_product_check_duplicate_sku')]
  1035.     public function checkDuplicateSKU(Request $request){
  1036.         $this->init($request);
  1037.         $sku $this->request->get('sku');
  1038.         $supplierId $this->request->get('supplier_id');
  1039.         $productId $this->request->get('product_id','');
  1040.         $data $this->productApiManager->checkDuplicateSKU($sku,$supplierId,$productId);
  1041.         $data['message'] = $this->translator->trans('product.'.$data['message']);
  1042.         return new JsonResponse($data);
  1043.     }
  1044.     
  1045.     // /**
  1046.     //  * @author Employee Id: 5190
  1047.     //  * Description : This function used for List Matrix Information
  1048.     //  * @Route("/matrix/list",
  1049.     //  * name="officebrain_product_matrix_list")
  1050.     //  * @Template("OfficeBrain/Bundle/ProductBundle/ProductAdmin/listMatrix.html.twig")
  1051.     //  */
  1052.     
  1053.     #[Route(path'/matrix/list'name'officebrain_product_matrix_list')]
  1054.     #[Template('OfficeBrain/Bundle/ProductBundle/ProductAdmin/listMatrix.html.twig')]
  1055.     public function listMatrixAction(Request $request){
  1056.         $this->init($request);
  1057.         $projectSetting $this->request->get('project_setting');
  1058.         $projectId $projectSetting['project_id'];
  1059.         $data['matrix_data'] = $this->productApiManager->getMatrixList($projectId);
  1060.         return array('data'=>$data);
  1061.     }
  1062.     
  1063.     // /**
  1064.     //  * @author Employee Id: 5540
  1065.     //  *
  1066.     //  * Description : This function used to Edit Product Information
  1067.     //  * @return array
  1068.     //  * @Route("/copy/{master_product_id}/{supplier_id}", name="officebrain_product_copy"),
  1069.     //  * @Template("OfficeBrain/Bundle/ProductBundle/ProductAdmin/add.html.twig")
  1070.     //  */
  1071.     #[Route(path'/copy/{master_product_id}/{supplier_id}'name'officebrain_product_copy')]
  1072.     #[Template('OfficeBrain/Bundle/ProductBundle/ProductAdmin/add.html.twig')]
  1073.     public function copyProductAction(Request $request)
  1074.     {
  1075.         //$this->init($request);
  1076.         $supplierId $request->get('supplier_id');
  1077.         $productId $request->get('master_product_id','');
  1078.         $projectSetting $request->get('project_setting');
  1079.         // $returnData = $this->serviceContainer->get("office_brain_product_admin_manager")->copy($supplierId, $productId);
  1080.         $returnData $this->productApiManager->copy($supplierId$productId);
  1081.         $returnData = array('status' => 'success');
  1082.          
  1083.         /*
  1084.         //SOLR SYNC CODE START
  1085.             $is_solr_syn_enabled = $this->container->getParameter('solr_sync');
  1086.                 if($is_solr_syn_enabled)
  1087.                 {
  1088.                 $env = $this->container->getParameter("kernel.environment");
  1089.                 $localization_to_update = $this->container->getParameter('localization_to_fetch');
  1090.                 $this->get("office_brain_product_admin_manager")->updateSolrData($newProductId,$localization_to_update,$projectSetting['project_id'],$env,$projectSetting['instance_id'],'update');
  1091.             }
  1092.         //SOLR SYNC CODE END
  1093.         */
  1094.          
  1095.         if($returnData['status'] == 'success')
  1096.         {
  1097.             $data['status'] = 'success_message';
  1098.             $data['message'] = $this->serviceContainer->get('translator')->trans('product_add_edit.product_copied_successfully');
  1099.         }
  1100.         else
  1101.         {
  1102.             $data['status'] = 'error_message';
  1103.             $data['message'] = $this->serviceContainer->get('translator')->trans('product_add_edit.product_not_copied');
  1104.         }
  1105.          
  1106.         return new JsonResponse($data);
  1107.     }
  1108.     
  1109.     // /**
  1110.     //  * @author Employee Id: 5190
  1111.     //  *
  1112.     //  * Description : This function used for Export Product data culture and country wise
  1113.     //  * @return array
  1114.     //  * @Route("/export", name="officebrain_product_export"),
  1115.     //  * @Template("OfficeBrain/Bundle/ProductBundle/ProductAdmin/export.html.twig")
  1116.     //  */
  1117.     
  1118.     #[Route(path'/export'name'officebrain_product_export')]
  1119.     #[Template('OfficeBrain/Bundle/ProductBundle/ProductAdmin/export.html.twig')]
  1120.     public function exportAction(Request $request)
  1121.     {
  1122.         $this->init($request);
  1123.         $projectSetting $this->request->get('project_setting');
  1124.         $projectId $projectSetting['project_id'];
  1125.         list($defaultCulture,$defaultCountry) = explode("_",$this->request->get("_locale"));
  1126.         $culture $this->request->get('language',$defaultCulture);
  1127.         $country $this->request->get('country',$defaultCountry);
  1128.         $supplier_id $this->request->query->get('supplier_id','');
  1129.         $countryArray $this->serviceContainer->getParameter('country');
  1130.         $languageArray $this->serviceContainer->getParameter('language');
  1131.         $supplierData $this->productApiManager->getSupplierNameList($projectId);
  1132.         $instanceType $projectSetting['instance_type'];
  1133.         // if ($this->user->getUserType()=='admin' && $instanceType=='association'){ // symfony 4
  1134.         if ($this->user && $this->user->getUserType()=='admin' && $instanceType=='association'){
  1135.             $supplier_id $this->request->query->get('supplier_id','');
  1136.         // } else if($this->user && $this->user->getUserType()=='supplier' || $this->user->getUserType()=='distributor' || ($this->user->getUserType() == 'admin' && $instanceType == 'distributor') || ($this->user->getUserType() == 'admin' && $instanceType == 'supplier')){ // symfony 4
  1137.         } elseif ($this->user && (
  1138.             $this->user->getUserType() == 'supplier' || 
  1139.             $this->user->getUserType() == 'distributor' || ( 
  1140.                 $this->user->getUserType() == 'admin' && (
  1141.                     $instanceType == 'distributor' || 
  1142.                     $instanceType == 'supplier'
  1143.                 
  1144.             ) 
  1145.         ) ) {
  1146.             $supplier_id $this->user->getObCustomerId();
  1147.             $supplier_id str_replace(array('OB','ob'), ''$supplier_id);
  1148.     
  1149.             if(empty($supplier_id)){
  1150.                 $supplier_id 0;
  1151.             }
  1152.         }else{
  1153.             $supplier_id 0;
  1154.         }
  1155.     
  1156.         foreach($countryArray as $countryKey => $country){
  1157.             $data['country_data'][] = array('id'=>$country['id'],'code'=>$country['short_name'],'title'=>$country['name'],'language'=>$country['language']);
  1158.         }
  1159.     
  1160.         if ($this->request->isXmlHttpRequest() && $this->request->getMethod()=='POST') {
  1161.             $data $this->request->request->all();
  1162.             $apiResponse =  $this->productApiManager->getExportProduct($data);
  1163.     
  1164.             return new JsonResponse($apiResponse);
  1165.         }
  1166.         $data['project_id']= $projectId;
  1167.         $data['country_array'] = $countryArray;
  1168.         $data['language_data'] = $languageArray;
  1169.         $data['supplier_data'] = $supplierData;
  1170.         $data['INSTANCE_TYPE'] = $instanceType;
  1171.         $data['supplier_id']=$supplier_id;
  1172.     
  1173.         return array('data'=>$data);
  1174.     
  1175.     }
  1176.     // /**
  1177.     //  * @author Employee Id: 5190
  1178.     //  *
  1179.     //  * Description : This function used for Import Product data supplier, culture and country wise
  1180.     //  * @return array
  1181.     //  * @Route("/import", name="officebrain_product_import"),
  1182.     //  * @Template("OfficeBrain/Bundle/ProductBundle/ProductAdmin/import.html.twig")
  1183.     //  */
  1184.     
  1185.     #[Route(path'/import'name'officebrain_product_import')]
  1186.     #[Template('OfficeBrain/Bundle/ProductBundle/ProductAdmin/import.html.twig')]
  1187.     
  1188.     public function importAction(Request $request){
  1189.         $this->init($request);
  1190.         $projectSetting $this->request->get('project_setting');
  1191.         $projectId $projectSetting['project_id'];
  1192.         list($defaultCulture,$defaultCountry) = explode("_",$this->request->get("_locale"));
  1193.         $culture $this->request->get('language',$defaultCulture);
  1194.         $country $this->request->get('country',$defaultCountry);
  1195.         $supplier_id $this->request->query->get('supplier_id','');
  1196.         //echo $supplier_id;die;
  1197.          
  1198.         $countryArray $this->serviceContainer->getParameter('country');
  1199.         $languageArray $this->serviceContainer->getParameter('language');
  1200.     
  1201.         $supplierData $this->productApiManager->getSupplierNameList($projectId);
  1202.         $instanceType $projectSetting['instance_type'];
  1203.         if ($this->user && $this->user->getUserType()=='admin' && $instanceType=='association'){
  1204.             $supplier_id $this->request->query->get('supplier_id','');
  1205.         // } else if($this->user->getUserType()=='supplier' || $this->user->getUserType()=='distributor' || ($this->user->getUserType() == 'admin' && $instanceType == 'distributor') || ($this->user->getUserType() == 'admin' && $instanceType == 'supplier')){ // symfony 4
  1206.         } elseif ($this->user && (
  1207.             $this->user->getUserType() == 'supplier' || 
  1208.             $this->user->getUserType() == 'distributor' || ( 
  1209.                 $this->user->getUserType() == 'admin' && (
  1210.                     $instanceType == 'distributor' || 
  1211.                     $instanceType == 'supplier'
  1212.                 
  1213.             ) 
  1214.         ) ) {
  1215.             $supplier_id $this->user->getObCustomerId();
  1216.             $supplier_id str_replace(array('OB','ob'), ''$supplier_id);
  1217.             if(empty($supplier_id)){
  1218.                 $supplier_id 0;
  1219.             }
  1220.         }else{
  1221.             $supplier_id 0;
  1222.         }
  1223.         foreach($countryArray as $countryKey => $country){
  1224.             $data['country_data'][] = array('id'=>$country['id'],'code'=>$country['short_name'],'title'=>$country['name'],'language'=>$country['language']);
  1225.         }
  1226.     
  1227.         if ($this->request->isXmlHttpRequest() && $this->request->getMethod()=='POST') {
  1228.             $uploadImportFilePath $this->serviceContainer->getParameter('tmp_image_upload_path');;
  1229.             $allwedImportFileMimeType $this->serviceContainer->getParameter('allowed_import_file_mime_type');
  1230.             $translator $this->serviceContainer->get('translator');
  1231.             //echo $uploadImportFilePath;die;
  1232.             if(!IS_DIR($uploadImportFilePath)){
  1233.                 mkdir($uploadImportFilePath,0777,true);
  1234.             }
  1235.     
  1236.             $importFileName '';
  1237.             $error false;
  1238.             $supplierId $this->request->get('supplier_id','');
  1239.             $countryId $this->request->get('country_id','');
  1240.             $cultureId $this->request->get('culture_id','');
  1241.             $userId $this->userId;
  1242.             //echo $supplierId.'---'.$countryId.'---'.$cultureId.'--'.$userId;die;
  1243.             if(!empty($_FILES) && $countryId >&& $cultureId >&& $supplierId>0){
  1244.                 foreach($_FILES as $file)
  1245.                 {
  1246.                     $filename $file['name'];
  1247.                     $extension pathinfo($filenamePATHINFO_EXTENSION);
  1248.                     if($extension != 'xls'){
  1249.                         $error true;
  1250.                         $error_message $translator->trans('product_import_export.allowed_import_file_type');
  1251.                     }
  1252.                     
  1253.                     if(!$error){
  1254.                         $importFileName "import_supplierid_".$supplierId."_countryid_".$countryId."_cultureid_".$cultureId."_".time().".".$extension;
  1255.                         $uploadImportFile $uploadImportFilePath.$importFileName;
  1256.                         $file_moved = @move_uploaded_file($file['tmp_name'], $uploadImportFile);
  1257.                         
  1258.                         if($file_moved){
  1259.                             $response $this->productApiManager->uploadImportFile($supplierId,$countryId,$cultureId,$projectId,$uploadImportFile,$uploadImportFilePath$userId);
  1260.                                                                     
  1261.                             if($response['status'] == 'success'){
  1262.                                 if(file_exists($uploadImportFile)){
  1263.                                     @unlink($uploadImportFile);
  1264.                                 }
  1265.                                 $error false;
  1266.                                 $success_message $translator->trans('product_import_export.import_process_start');
  1267.                             }
  1268.                             else{
  1269.                                 $error true;
  1270.                                 $error_message $translator->trans('product_import_export.file_upload_error_message');
  1271.                             }
  1272.                         }
  1273.                         else {
  1274.                             $error true;
  1275.                             $error_message $translator->trans('product_import_export.file_upload_error_message'); 
  1276.                         }
  1277.                     }
  1278.                 }
  1279.             }
  1280.  
  1281.             
  1282.             else{
  1283.                 $error true;
  1284.                 $error_message $translator->trans('product.file_not_found');   //"Please select file" ;
  1285.             }
  1286.     
  1287.             if(!$error){
  1288.                 $return = array (
  1289.                         'status' => 'success',
  1290.                         'success_message'=> $success_message,
  1291.                 );
  1292.             } else {
  1293.                 $return = array (
  1294.                         'status' => 'error',
  1295.                         'error_message' => $error_message);
  1296.             }
  1297.     
  1298.             return new JsonResponse($return);
  1299.         }
  1300.     
  1301.         $data['country_array'] = $countryArray;
  1302.         $data['language_data'] = $languageArray;
  1303.         $data['supplier_data'] = $supplierData;
  1304.         $data['INSTANCE_TYPE'] = $instanceType;
  1305.         $data['supplier_id']=$supplier_id;
  1306.     
  1307.         return array('data'=>$data);
  1308.     
  1309.     }
  1310.     
  1311.     // /**
  1312.     //  * @author Employee Id: 5190
  1313.     //  *
  1314.     //  * Description : This function used for Import Product data supplier, culture and country wise
  1315.     //  * @return array
  1316.     //  * @Route("/check_import_status", name="officebrain_product_check_import_status"),
  1317.     //  * options={"expose"=true},
  1318.     //  * @Template("OfficeBrain/Bundle/ProductBundle/ProductAdmin/checkImportStatus.html.twig")
  1319.     //  */
  1320.     
  1321.     #[Route(path'/check_import_status'name'officebrain_product_check_import_status'options: ['expose' => true])]
  1322.     #[Template('OfficeBrain/Bundle/ProductBundle/ProductAdmin/checkImportStatus.html.twig')]
  1323.     
  1324.     public function checkImportStatusAction(Request $request){
  1325.         $this->init($request);
  1326.         $supplierId $request->get('supplier_id');
  1327.         $projectSetting $this->request->get('project_setting');
  1328.         $projectId $projectSetting['project_id'];
  1329.     
  1330.         $returnData $this->productApiManager->checkImportStatus($supplierId,$projectId);
  1331.     
  1332.         return array('data'=>$returnData);
  1333.     
  1334.     }
  1335.     
  1336.     // /**
  1337.     //  * @author Employee Id: 5190
  1338.     //  *
  1339.     //  * Description : This function used for add inventory message sku colour wise
  1340.     //  * @return array
  1341.     //  * @Route("/get-inventory-message/{sku}", name="officebrain_product_add_inventory_message"),
  1342.     //  * options={"expose"=true},
  1343.     //  */
  1344.     
  1345.     #[Route(path'/get-inventory-message/{sku}'name'officebrain_product_add_inventory_message'options: ['expose' => true])]
  1346.     public function addInventoryMessageAction(Request $request){
  1347.         $this->init($request);
  1348.         $sku $request->get('sku');
  1349.         $data json_encode(array('message'=>'','sku'=>$sku));
  1350.         $obj $this->productApiManager->getInvMessageBySku($sku);
  1351.         //var_dump($obj); die;
  1352.         if(count($obj)>0){ 
  1353.             $data =  json_encode(array('message'=>$obj[0]->getMessage(),'sku'=>$obj[0]->getProductSku()));
  1354.         }
  1355.         echo $data;
  1356.         die;  
  1357.         //$this->productApiManager;
  1358.     }
  1359.     
  1360.     // /**
  1361.     //  * @author Employee Id: 5190
  1362.     //  *
  1363.     //  * Description : This function used for add inventory message sku colour wise
  1364.     //  * @return array
  1365.     //  * @Route("/add-inventory-message", name="officebrain_product_update_inventory_message"),
  1366.     //  * options={"expose"=true},
  1367.     //  */
  1368.     
  1369.     #[Route(path'/add-inventory-message'name'officebrain_product_update_inventory_message'options: ['expose' => true])]
  1370.     public function updateInventoryMessageAction(Request $request){
  1371.         $this->init($request);
  1372.         $parameters $request->request->all();
  1373.         /*if($parameters['inv_message']==""){
  1374.          $data = json_encode(array('status'=>'error_message','message'=>'Enter Message'));
  1375.          }else{*/
  1376.         $object null;
  1377.         $message $parameters['inv_message'];
  1378.         $sku $parameters['inv_sku'];
  1379.         $obj $this->productApiManager->getInvMessageBySku($sku);
  1380.         if(count($obj)>0){
  1381.             $object $obj[0];
  1382.         }
  1383.         $this->productApiManager->updateMessage($object,$message,$sku);
  1384.         $data json_encode(array('status'=>'success_message','message'=>'Message added successfully'));
  1385.         //}
  1386.         echo $data;
  1387.         die;
  1388.     }
  1389.     // /**
  1390.     //  * @author Employee Id: 5190
  1391.     //  *
  1392.     //  * Description : This function used for get importErrorLog using importId.
  1393.     //  * @return array
  1394.     //  * @Route("/import_error_log/{import_id}", name="officebrain_product_import_error_log"),
  1395.     //  * @Template("")
  1396.     //  */
  1397.     
  1398.     #[Route(path'/import_error_log/{import_id}'name'officebrain_product_import_error_log')]
  1399.     #[Template('')]
  1400.     
  1401.     public function importErrorLogAction(Request $request){
  1402.         $this->init($request);
  1403.         $importId $request->get('import_id');
  1404.         $returnData $this->productApiManager->importErrorLog($importId);
  1405.         $filename "import_error_log_" $importId.".csv";
  1406.         $response $this->render('OfficeBrain/Bundle/ProductBundle/ProductAdmin/importErrorLog.csv.twig',array('data' => $returnData));
  1407.         //$response->setStatusCode(200);
  1408.         $response->headers->set('Content-Type''text/csv');
  1409.         $response->headers->set('Content-Disposition''attachment; filename="'.$filename.'"');
  1410.         $response->headers->set('Pragma''no-cache');
  1411.         $response->headers->set('Expires''0');
  1412.         //$response->sendHeaders();
  1413.         //$response->sendContent();
  1414.         return $response;
  1415.     
  1416.         //return array('data'=>$returnData);
  1417.     }
  1418.     
  1419.     
  1420.     // /**
  1421.     //  * @Route("/suggestedProduct/{id}",
  1422.     //  * name="officebrain_product_bundle_get_suggested_product",
  1423.     //  * options={"expose"=true}, methods={"GET"})
  1424.     //  */
  1425.     
  1426.     #[Route(path'/suggestedProduct/{id}'name'officebrain_product_bundle_get_suggested_product'options: ['expose' => true], methods: ['GET'])]
  1427.     public function getSuggestedProductByProductIdAction(Request $request$id){
  1428.         $this->init($request);
  1429.         $data $this->productApiManager->getSuggestedProductByProductId($id);
  1430.         
  1431.         return new JsonResponse($data);
  1432.     }
  1433.     
  1434.     // /**
  1435.     //  * @Route("/suggestedProduct/{id}",
  1436.     //  * name="officebrain_product_bundle_set_suggested_product",
  1437.     //  * options={"expose"=true}, methods={"POST"})
  1438.     //  */
  1439.     
  1440.     #[Route(path'/suggestedProduct/{id}'name'officebrain_product_bundle_set_suggested_product'options: ['expose' => true], methods: ['POST'])]
  1441.     public function setSuggestedProductByProductIdAction(Request $request$id){
  1442.         $this->init($request);
  1443.         $pmsId $id;
  1444.         $productsSku $this->request->get('products_sku');
  1445.         //         $products =
  1446.         $api_manager $this->serviceContainer->get('officebrain_category_api_manager');
  1447.         $data $this->productApiManager->setSuggestedProductByProductId($pmsId,$productsSku);
  1448.         $data['message'] = $this->translator->trans($data['message']);
  1449.         return new JsonResponse($data);
  1450.     }
  1451.     
  1452.     // /**
  1453.     //  * @author Employee Id: 5429
  1454.     //  *
  1455.     //  * Description : This function used for add inventory message sku colour wise
  1456.     //  * @return array
  1457.     //  * @Route("/get-rsync-status/{sku}/{slug}", name="officebrain_product_rsync_check"),
  1458.     //  * options={"expose"=true},
  1459.     //  */
  1460.     
  1461.     #[Route(path'/get-rsync-status/{sku}/{slug}'name'officebrain_product_rsync_check'options: ['expose' => true])]
  1462.     public function getRsyncStatusAction(Request $request){
  1463.         $this->init($request);
  1464.         $sku $request->get('sku');
  1465.         $slug $request->get('slug');
  1466.         $this->productDetailManager->updateSyncDetail(1,$sku);
  1467.         //$asiurl = 'http://demoapi.officebrain.com/update_product_api.php?product_slug=16-oz-victory-acrylic-tumbler-with-straw-lid-full-color-digital';
  1468.         //$result = exec("curl '$asiurl' > /dev/null &",$output,$return_val);
  1469.         $asiurl 'https://demoapi.officebrain.com/update_product_api.php?product_slug='.$slug;
  1470.        //$asiurl = 'http://demoapi.officebrain.com/update_product_api.php?product_slug=halcyon-r-waterproof-wireless-speaker-full-color-digital';
  1471.       
  1472.         $curl curl_init();
  1473.         curl_setopt_array($curl, array(
  1474.           CURLOPT_URL => $asiurl,
  1475.           CURLOPT_RETURNTRANSFER => true,
  1476.           CURLOPT_ENCODING => '',
  1477.           CURLOPT_MAXREDIRS => 10,
  1478.           CURLOPT_TIMEOUT => 0,
  1479.           CURLOPT_FOLLOWLOCATION => true,
  1480.           CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  1481.           CURLOPT_CUSTOMREQUEST => 'GET',
  1482.           CURLOPT_SSL_VERIFYPEER =>0
  1483.         ));
  1484.         $response curl_exec($curl); 
  1485.         if (curl_errno($curl)) {
  1486.             echo $error_msg curl_error($curl); die;
  1487.         }
  1488.         curl_close($curl); 
  1489.         echo $response;
  1490.        /* $result = exec("curl '$asiurl' 2>&1 &", $output);
  1491.         if(isset($output[3]) && $output[3]!=''){
  1492.             $msg = json_decode($output[3]);
  1493.             $reason = $msg->Errors[0]->Reason;
  1494.             $data = json_encode(array('status'=>'success_message','message'=>'Reason:'.$reason));
  1495.         }else{
  1496.             $data = json_encode(array('status'=>'success_message','message'=>'Product Sync Successfully'));
  1497.         }*/
  1498.        // echo $data;
  1499.         die;
  1500.     }
  1501.     
  1502.     // /**
  1503.     //  * @author Employee Id: 5429
  1504.     //  *
  1505.     //  * Description : This function used for add imprint method on skus
  1506.     //  * @return array
  1507.     //  * @Route("/imprint-skus", name="officebrain_imprint_skus_product"),
  1508.     //  * @Template("OfficeBrain/Bundle/ProductBundle/ProductAdmin/getImprintSkus.html.twig")
  1509.     //  */
  1510.     
  1511.     #[Route(path'/imprint-skus'name'officebrain_imprint_skus_product')]
  1512.     #[Template('OfficeBrain/Bundle/ProductBundle/ProductAdmin/getImprintSkus.html.twig')]
  1513.     
  1514.     public function getImprintSkusAction(Request $request){
  1515.         $searchParameters = array();
  1516.         // $productTagManager = $this->serviceContainer->get('office_brain_product_tag_manager');
  1517.         $productTagManager $this->productTagManager;
  1518.         if(!empty($_REQUEST['sku']) && $_REQUEST['sku']!=""){
  1519.             $culture $request->get('_locale','en_us');
  1520.             // $productDetailManager = $this->serviceContainer->get('office_brain_product_detail_manager');
  1521.             $productDetailManager $this->productDetailManager;
  1522.             $productObj $productDetailManager->getProductDetailBySku($_REQUEST['sku'], 5,$culture,false);
  1523.             if(isset($productObj['product_id'])){
  1524.                 $data['product_id'] = $productObj['product_id'];
  1525.                 $data['imprint'] = $_REQUEST['imprint'];
  1526.                 $data['sku'] = $productObj['basic_information']['sku_number'];
  1527.                 $data['product_title'] = $productObj['basic_information']['title'];
  1528.                 $data['product_image'] = $productObj['basic_information']['default_image_thumb_url'];
  1529.                 $productImprint $productTagManager->getImprintProductByIdAndMethod($data['product_id'],$data['imprint']);
  1530.                 if($productImprint==NULL){
  1531.                     $productTagManager->addImprintProduct($data);
  1532.                      //SOLR SYNC CODE START
  1533.                     // $productApiManager = $this->serviceContainer->get("office_brain_product_admin_manager");
  1534.                     $productApiManager $this->productApiManager;
  1535.                     $is_solr_syn_enabled $this->serviceContainer->getParameter('solr_sync');
  1536.                     if($is_solr_syn_enabled){
  1537.                         $env $this->serviceContainer->getParameter("kernel.environment");
  1538.                         $localization_to_update $this->serviceContainer->getParameter('localization_to_fetch');
  1539.                         $productApiManager->updateSolrData($data['product_id'],$localization_to_update,5,$env,'update');
  1540.                     }
  1541.                     
  1542.                     //SOLR SYNC CODE END
  1543.                 
  1544.                     $this->request->getSession()->getflashbag()->add('success_message''Sku mapped successfully.');
  1545.                 }else{
  1546.                     $this->request->getSession()->getflashbag()->add('error_message''Sku already mapped.');
  1547.                     return $this->redirect($this->generateUrl('officebrain_imprint_skus_product'));
  1548.                 }
  1549.             }
  1550.                 
  1551.         }
  1552.         $searchParameters['search_result_array']['data'] = $productTagManager->getAllImprintProducts();
  1553.         // $this->arrayToPaginationManager = $this->serviceContainer->get('office_brain_array_to_pagination_manager');
  1554.         $this->arrayToPaginationManager $this->arrayToPaginationManager;
  1555.         if(!empty($searchParameters['search_result_array'])){
  1556.             $this->arrayToPaginationManager->setPaginationArray($searchParameters['search_result_array']);
  1557.             $this->arrayToPaginationManager->doConvert();
  1558.             $searchParameters['pagination'] = $this->arrayToPaginationManager->getPagination();
  1559.         }
  1560.         return $searchParameters;
  1561.     }
  1562.     
  1563.     // /**
  1564.     //  * @author Employee Id: 5429
  1565.     //  *
  1566.     //  * Description : This function used for add imprint method on skus
  1567.     //  * @return array
  1568.     //  * @Route("/remove-imprint-skus/{id}", name="officebrain_product_remove_imprint_skus"),
  1569.     //  */
  1570.     
  1571.     #[Route(path'/remove-imprint-skus/{id}'name'officebrain_product_remove_imprint_skus')]
  1572.     public function removeImprintSkusAction(Request $request){
  1573.         $id $request->get('id');
  1574.         $productTagManager $this->productTagManager;
  1575.         $prodData $productTagManager->getImprintProductById($id);
  1576.         if($prodData!=NULL){
  1577.              $productId $prodData->getProductId();
  1578.              $productTagManager->deleteImprintProductById($prodData);
  1579.               //SOLR SYNC CODE START
  1580.                     // $productApiManager = $this->serviceContainer->get("office_brain_product_admin_manager");
  1581.                     $productApiManager $this->productApiManager;
  1582.                     $is_solr_syn_enabled $this->serviceContainer->getParameter('solr_sync');
  1583.                     if($is_solr_syn_enabled){
  1584.                         $env $this->serviceContainer->getParameter("kernel.environment");
  1585.                         $localization_to_update $this->serviceContainer->getParameter('localization_to_fetch');
  1586.                         $productApiManager->updateSolrData($productId,$localization_to_update,5,$env,'update');
  1587.                     }
  1588.                     
  1589.                     //SOLR SYNC CODE END
  1590.              $this->request->getSession()->getflashbag()->add('success_message''Record deleted successfully.');
  1591.         }else{
  1592.             $this->request->getSession()->getflashbag()->add('error_message''no record found');
  1593.         }
  1594.         return $this->redirect($this->generateUrl('officebrain_imprint_skus_product'));
  1595.     }
  1596.     
  1597. }