<?php
namespace App\project\OfficeBrain\CustomBundle\ProductBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Translation\Translator;
use App\project\OfficeBrain\CustomBundle\ProductBundle\Entity\SellingIdeas;
use App\project\OfficeBrain\CustomBundle\ProductBundle\Form\SellingIdeasType;
use App\project\OfficeBrain\CustomBundle\ProductBundle\Entity\PsaDeal;
use App\project\OfficeBrain\CustomBundle\ProductBundle\Form\PsaDealType;
use App\project\OfficeBrain\CustomBundle\ProductBundle\Entity\QRCode;
use App\project\OfficeBrain\CustomBundle\ProductBundle\Form\QRCodeType;
use App\OfficeBrain\Bundle\ProductBundle\Controller\ProductConfigureController as BaseProductConfigureController;
use App\project\OfficeBrain\CustomBundle\ProductBundle\Entity\ProductAdvertise;
use App\project\OfficeBrain\CustomBundle\ProductBundle\Form\ProductAdvertiseType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\DependencyInjection\ContainerInterface;
use App\OfficeBrain\Bundle\ProductBundle\Manager\Service\ProductAdminManager;
use App\OfficeBrain\Bundle\UserBundle\Manager\Service\UserService;
use App\OfficeBrain\Bundle\ProductBundle\Manager\Service\ProductDetailService;
use App\OfficeBrain\Bundle\ProductBundle\Manager\Service\BrandApiManager;
use App\project\OfficeBrain\CustomBundle\ProductBundle\Manager\Service\ProductDetailService as CustomProductDetailService;
use App\OfficeBrain\Bundle\ProductTagBundle\Manager\Service\ProductTagManager;
use App\OfficeBrain\Bundle\CoreBundle\Service\ArrayToPaginationManager;
use App\OfficeBrain\Bundle\SolrBundle\Manager\Service\SolrService;
use App\OfficeBrain\Bundle\QueueBundle\Manager\Service\ApiManager as QueueApiManager;
/**
* @Route("/admin/{_locale}/product")
*/
class ProductConfigureController extends BaseProductConfigureController
{
public function __construct(ContainerInterface $container, ProductAdminManager $productAdminManager, UserService $userService, ProductDetailService $productDetailService, BrandApiManager $brandApiManager, CustomProductDetailService $customProductDetailService, ProductTagManager $productTagManager, ArrayToPaginationManager $arrayToPaginationManager, SolrService $solrService, QueueApiManager $queueApiManager)
{
$this->serviceContainer = $container;
$this->productApiManager = $productAdminManager;
$this->userService = $userService->getUserExtended();
$this->productDetailManager = $productDetailService->getProductApiExtended();
$this->brandApiManager = $brandApiManager;
$this->arrayToPaginationManager = $arrayToPaginationManager;
$this->customProductDetailService = $customProductDetailService;
$this->solrService = $solrService->getSolrServiceExtended();
$this->productTagManager = $productTagManager->getProductTagManagerExtended();
$this->queueApiManager = $queueApiManager->getQueueInstance();
}
const COMMAND_BASIC = "bin/console";
public function init(Request $request)
{
parent::init($request);
// $this->productDetailManager = $this->serviceContainer->get('office_brain_product_detail_manager_custom');
$this->productDetailManager = $this->customProductDetailService->getProductApiExtended();
$this->cultureCode = $this->projectSetting['culture_code'];
}
/**
*
* @author Employee Id: 5429
*
* Description : List action
*
* @param : null
*
* @return Array
*
* @throws null
*
* @Route("/selling-ideas/list/{productId}", name="officebrain_custombundle_productbundle_sellingIdeas_list",
* requirements={"records_per_page"="12|24|48|100|996","page"="\d+"},
* defaults={"records_per_page"=100,"page"=1})
*
* @Template("project/OfficeBrain/CustomBundle/ProductBundle/ProductAdmin/listSellingIdeas.html.twig")
*
**/
public function listSellingIdeasAction(Request $request, $productId)
{
$this->init($request);
$param = $this->request->get('_route_params');
$recordsPerPage = $param['records_per_page'];
$page = $this->request->get('page', '1');
$this->responseArray['data'] = $this->productDetailManager->listSellingIdeas($page,$recordsPerPage,$productId);
//$paginator = $this->get('knp_paginator');
//$this->responseArray['pagination'] = $paginator->paginate($this->responseArray['data'], $page, $recordsPerPage);
$this->responseArray['page']=$page;
$this->responseArray['productId']=$productId;
return $this->responseArray;
}
/**
* @author Employee Id: 5429
*
* Description : This function used for List Product Information
* @Route("/selling-ideas/add/{productId}",name="officebrain_custombundle_productbundle_sellingIdeas", methods={"GET","POST"})
* @Template("project/OfficeBrain/CustomBundle/ProductBundle/ProductAdmin/addSellingIdeas.html.twig")
*
*
*/
public function sellingIdeasAction(Request $request, $productId)
{
$this->init($request);
$RootDir = $this->serviceContainer->get('kernel')->getProjectDir();
$id = $this->request->request->get('id','');
$SellingIdeasentityobj = new SellingIdeas();
$SellingIdeasformObj = SellingIdeasType::class;
$ImagePath='';
if($id>0)
{
$SellingIdeasentityobj= $this->productDetailManager->sellingIdeasfindById($id);
$ImagePath=$SellingIdeasentityobj->getPdfPath();
$SellingIdeasentityobj->setStartDate($SellingIdeasentityobj->getStartDate()->format('m/d/Y'));
$SellingIdeasentityobj->setEndDate($SellingIdeasentityobj->getEndDate()->format('m/d/Y'));
}
$this->form = $this->createForm($SellingIdeasformObj, $SellingIdeasentityobj, [
'id' => $id,
]);
$this->form->handleRequest($this->request);
if($this->form->isSubmitted())
{
if ($this->form->isValid())
{
$formdata=$this->form->getdata();
$this->productDetailManager->saveSellingIdeas($formdata,$productId,$SellingIdeasentityobj,$RootDir,$ImagePath);
$this->get('session')->getFlashBag()->add('success_message', $this->translator->trans('admin.selling_ideas_save_msg'));
$response['Message'] = "success";
return new JsonResponse($response);
}
return new JsonResponse ( $this->prepareFormJsonError ($this->form) );
}
return array('form_selling_ideas'=>$this->form->createView(),'productId'=>$productId,'id'=>$id,'ImagePathedit'=>$ImagePath);
}
/**
* @author Employee Id: 5429
*
* Description : This function used for List Product Information
* @Route("/delete-selling-ideas/",name="officebrain_custombundle_productbundle_sellingIdeas_delete", methods={"GET","POST"})
* @Template()
*
*
*/
public function deleteSellingIdeasAction(Request $request)
{
$this->init($request);
$id = $this->request->request->get('id','');
$Message = $this->productDetailManager->sellingIdeaDdeleteRecords($id);
$this->get('session')->getFlashBag()->add('success_message', $this->translator->trans('admin.selling_ideas_delete_msg'));
return new JsonResponse();
die;
}
/**
*
* @author Employee Id: 5429
*
* Description : List action
*
* @param : null
*
* @return Array
*
* @throws null
*
* @Route("/psa-special/list/{productId}", name="officebrain_custombundle_productbundle_psaSpecial_list",
* requirements={"records_per_page"="12|24|48|100|996","page"="\d+"},
* defaults={"records_per_page"=100,"page"=1})
*
* @Template("project/OfficeBrain/CustomBundle/ProductBundle/ProductAdmin/listPsaSpecial.html.twig")
*
**/
public function listPsaSpecialAction(Request $request, $productId)
{
$this->init($request);
$param = $this->request->get('_route_params');
$recordsPerPage = $param['records_per_page'];
$page = $this->request->get('page', '1');
$this->responseArray['data'] = $this->productDetailManager->listPsaSpecial($page,$recordsPerPage,$productId);
//$paginator = $this->get('knp_paginator');
//$this->responseArray['pagination'] = $paginator->paginate($this->responseArray['data'], $page, $recordsPerPage);
$this->responseArray['page']=$page;
$this->responseArray['productId']=$productId;
return $this->responseArray;
}
/**
* @author Employee Id: 5429
*
* Description : This function used for List Product Information
* @Route("/psa-special/add/{productId}",name="officebrain_custombundle_productbundle_psaSpecial", methods={"GET","POST"})
* @Template("project/OfficeBrain/CustomBundle/ProductBundle/ProductAdmin/addPsaSpecial.html.twig")
*
*
*/
public function psaSpecialAction(Request $request, $productId)
{
$this->init($request);
$RootDir = $this->serviceContainer->get('kernel')->getProjectDir();
$id = $this->request->request->get('id','');
$PsaDealentityobj = new PsaDeal();
$PsaDealformObj = PsaDealType::class;
$ImagePath='';
if($id>0)
{
$PsaDealentityobj = $this->productDetailManager->findById($id);
$ImagePath=$PsaDealentityobj->getImagePath();
$PsaDealentityobj->setStartDate($PsaDealentityobj->getStartDate()->format('m/d/Y'));
$PsaDealentityobj->setEndDate($PsaDealentityobj->getEndDate()->format('m/d/Y'));
}
$this->form = $this->createForm($PsaDealformObj, $PsaDealentityobj, [
'id' => $id,
]);
$this->form->handleRequest($this->request);
if($this->form->isSubmitted())
{
if ($this->form->isValid())
{
$formdata=$this->form->getdata();
$this->productDetailManager->savePsaSpecial($formdata,$productId,$PsaDealentityobj,$RootDir,$ImagePath);
$this->get('session')->getFlashBag()->add('success_message', $this->translator->trans('admin.psa_save_msg'));
$response['Message'] = "success";
return new JsonResponse($response);
}
return new JsonResponse ( $this->prepareFormJsonError ($this->form) );
}
return array('form_psa_deal'=>$this->form->createView(),'productId'=>$productId,'id'=>$id,'ImagePathedit'=>$ImagePath);
}
private function prepareFormJsonError()
{
return array(
'form_name' => $this->form->getName(),
'form_status' => 'error',
'form_errors' => $this->formErrorManager->prepareErrorArray($this->serviceContainer->get('validator')->validate($this->form))
);
}
/**
* @author Employee Id: 5429
*
* Description : This function used for List Product Information
* @Route("/delete-psa-special/",name="officebrain_custombundle_productbundle_psaSpecial_delete", methods={"GET","POST"})
* @Template()
*
*
*/
public function deletePsaSpecialAction(Request $request)
{
$this->init($request);
$id = $this->request->request->get('id','');
$Message = $this->productDetailManager->deleteRecords($id);
$this->get('session')->getFlashBag()->add('success_message', $this->translator->trans('admin.psa_management.psa_delete_msg'));
return new JsonResponse();
die;
}
/**
*
* @author Employee Id: 5429
*
* Description : List action
*
* @param : null
*
* @return Array
*
* @throws null
*
* @Route("/QRcode/list/", name="office_brain_custom_bundle_qr_code_list",
* requirements={"records_per_page"="12|24|48|100|996","page"="\d+"},
* defaults={"records_per_page"=100,"page"=1})
*
* @Template("project/OfficeBrain/CustomBundle/ProductBundle/ProductAdmin/listQRcode.html.twig")
*
**/
public function listQRcodeAction(Request $request)
{
$this->init($request);
$param = $this->request->get('_route_params');
$recordsPerPage = $param['records_per_page'];
$page = $this->request->get('page', '1');
$this->responseArray['max'] = $this->productDetailManager->MaxQRCodeid();
$this->responseArray['data'] = $this->productDetailManager->listQRCode($page,$recordsPerPage);
//$paginator = $this->get('knp_paginator');
//$this->responseArray['pagination'] = $paginator->paginate($this->responseArray['data'], $page, $recordsPerPage);
$this->responseArray['page']=$page;
return $this->responseArray;
}
/**
* @author Employee Id: 5429
*
* Description : This function used for List Product Information
* @Route("/QRcode/add/",name="officebrain_custombundle_productbundle_qrcodeadd", methods={"GET","POST"})
* @Template("project/OfficeBrain/CustomBundle/ProductBundle/ProductAdmin/addQRCode.html.twig")
*
*
*/
public function qrCodeAction(Request $request)
{
$this->init($request);
$RootDir = $this->serviceContainer->get('kernel')->getProjectDir();
$id = $this->request->request->get('id','');
$maxid = $this->request->request->get('maxid','');
$PsaDealentityobj = new QRCode();
$PsaDealformObj = QRCodeType::class;
$qrCodeImagePath='';
$ImagePath='';
$LogoImagePath='';
if($id>0)
{
$PsaDealentityobj = $this->productDetailManager->qrcodefindById($id);
$qrCodeImagePath=$PsaDealentityobj->getQrCodeImage();
$ImagePath=$PsaDealentityobj->getOfferImage();
$LogoImagePath=$PsaDealentityobj->getlogoImage();
}
// $this->form = $this->createForm($PsaDealformObj,$PsaDealentityobj);
$this->form = $this->createForm($PsaDealformObj, $PsaDealentityobj, [
'id' => $id,
]);
$this->form->handleRequest($this->request);
if($this->form->isSubmitted())
{
if ($this->form->isValid())
{
$formdata=$this->form->getdata();
$this->productDetailManager->saveQRCode($formdata,$PsaDealentityobj,$RootDir,$qrCodeImagePath,$ImagePath,$LogoImagePath);
$this->get('session')->getFlashBag()->add('success_message', $this->translator->trans('admin.qr_save_msg'));
$response['Message'] = "success";
return new JsonResponse($response);
}
return new JsonResponse ( $this->prepareFormJsonError ($this->form) );
}
return array('form_qr_code'=>$this->form->createView(),'id'=>$id,'qrCodeImagePath'=>$qrCodeImagePath,'ImagePathedit'=>$ImagePath,'maxid'=>$maxid,'logoImagePathedit'=>$LogoImagePath);
}
/**
* @author Employee Id: 5429
*
* Description : This function used for List Product Information
* @Route("/delete-qr/",name="officebrain_custombundle_productbundle_qrcode_delete", methods={"GET","POST"})
* @Template()
*
*
*/
public function deleteQrcodeAction(Request $request)
{
$this->init($request);
$id = $this->request->request->get('id','');
$Message = $this->productDetailManager->qrCodedeleteRecords($id);
$this->get('session')->getFlashBag()->add('success_message', $this->translator->trans('admin.psa_delete_msg'));
return new JsonResponse();
die;
}
/**
* @author Employee Id: 6799
*
* Desciption: Get Colors From Inventory
*
* @return json Response
*
* @Route("/get-product-inventory-colors",
* name="officebrain_product_bundle_product_inventory_colors"
* )
*
* @Template("project/OfficeBrain/CustomBundle/ProductBundle/ProductAdmin/productInventoryColors.html.twig")
*/
public function productInventoryColorsAction(Request $request)
{
$this->init($request);
$itemNo=$this->request->get("itemno");
$prodctid=$this->request->get("prodctid");
$this->responseArray['productSku']=$itemNo;
$this->responseArray['recordSet'][]=$this->productDetailManager->getProductInventoryDetails($itemNo);
$this->responseArray['productcolor']=$this->productDetailManager->getProductDetailById($prodctid, $this->cultureCode);
/* Color Available Date */
$inventoryColorDateData=$this->productDetailManager->getProductInventoryColorDateData($itemNo);
/*if(!empty($inventoryColorDateData)){
foreach($this->responseArray['recordSet'] as $key=>$inventoryData){
if(isset($inventoryData['lstItemInv']['ItemInventory'])){
if(isset($inventoryData['lstItemInv']['ItemInventory']['color'])){
$dateArrayKey = $this->productDetailManager->searchForColor($inventoryData['lstItemInv']['ItemInventory']['color'][1],$inventoryColorDateData);
$this->responseArray['recordSet'][$key]['lstItemInv']['ItemInventory']['availableDate'] = $inventoryColorDateData[$dateArrayKey]['availableDate'];
}else{
foreach($inventoryData['lstItemInv']['ItemInventory'] as $colorKey=>$colorValue){
$dateArrayKey = $this->productDetailManager->searchForColor($colorValue['color'][1],$inventoryColorDateData);
$this->responseArray['recordSet'][$key]['lstItemInv']['ItemInventory'][$colorKey]['availableDate'] = $inventoryColorDateData[$dateArrayKey]['availableDate'];
}
}
}
}
}*/
if(!empty($inventoryColorDateData)){
foreach($this->responseArray['recordSet'] as $key=>$inventoryData){
if(isset($inventoryData['lstItemInv']['ItemInventory']['color'])){
//$dateArrayKey = $this->productDetailManager->searchForColor($inventoryData['lstItemInv']['ItemInventory']['color'][1],$inventoryColorDateData);
$dateArrayKey = $this->productDetailManager->searchForColor($inventoryData['lstItemInv']['ItemInventory']['color'],$inventoryColorDateData);
$this->responseArray['recordSet'][$key]['lstItemInv']['ItemInventory']['availableDate'] = $inventoryColorDateData[$dateArrayKey]['availableDate'];
}else{
if(isset($inventoryData['lstItemInv']['ItemInventory'])){
foreach($inventoryData['lstItemInv']['ItemInventory'] as $colorKey=>$colorValue){
//$dateArrayKey = $this->productDetailManager->searchForColor($colorValue['color'][1],$inventoryColorDateData);
$dateArrayKey = $this->productDetailManager->searchForColor($colorValue['color'],$inventoryColorDateData);
if(isset($inventoryColorDateData[$dateArrayKey])){
$this->responseArray['recordSet'][$key]['lstItemInv']['ItemInventory'][$colorKey]['availableDate'] = $inventoryColorDateData[$dateArrayKey]['availableDate'];
}
}
}
}
}
}
//echo "<pre>";
//print_r($this->responseArray); die;
/* EO: Color Available Date */
return $this->responseArray;
}
/**
* @author Employee Id: 6799
*
* Desciption: Get Colors From Inventory
*
* @return json Response
*
* @Route("/get-product-inventory-colors-submit",
* name="officebrain_product_bundle_product_inventory_colors_submit"
* )
*
* @Template("project/OfficeBrain/CustomBundle/ProductBundle/ProductAdmin/productInventoryColors.html.twig")
*/
public function productInventoryColorsSubmitAction(Request $request)
{
$this->init($request);
$colorValidUntilDate = $this->request->get('pricing_valid_until');
$inventoryColors = $this->request->get('inventory_color');
$productSku = $this->request->get('product_sku');
$returnData = $this->productDetailManager->setInventoryColorDate($colorValidUntilDate,$inventoryColors,$productSku);
if(!empty($returnData)){
return new JsonResponse(array("status"=>"success","message"=>"Data Successfully Saved.."));;
}
else{
return new JsonResponse(array("status"=>"error","message"=>"There is some error please try again later"));;
}
}
/**
*
* @author(Kjethi)
*
* Description : List action
*
* @param : null
*
* @return Array
*
* @throws null
*
* @Route("/product-advertise/list/{productId}", name="officebrain_custombundle_productbundle_productadvertise_list",
* requirements={"records_per_page"="12|24|48|100|996","page"="\d+"},
* defaults={"records_per_page"=100,"page"=1})
*
* @Template("project/OfficeBrain/CustomBundle/ProductBundle/ProductAdmin/listProductAdvertise.html.twig")
*
**/
public function listProductAdvertiseAction(Request $request, $productId)
{
$this->init($request);
$param = $this->request->get('_route_params');
$recordsPerPage = $param['records_per_page'];
$page = $this->request->get('page', '1');
$this->responseArray['data'] = $this->productDetailManager->listProductAdvertise($page,$recordsPerPage,$productId);
//$paginator = $this->get('knp_paginator');
//$this->responseArray['pagination'] = $paginator->paginate($this->responseArray['data'], $page, $recordsPerPage);
$this->responseArray['page']=$page;
$this->responseArray['productId']=$productId;
$this->responseArray['type']= 'product';
// print_r($this->responseArray['data']);exit;
return $this->responseArray;
}
/**
* @author(Kjethi)
*
* Description : This function used for Add Product Advertise
* @Route("/product-advertise/add/{refId}",name="officebrain_custombundle_productbundle_addproductadvertise", methods={"GET","POST"})
* @Template("project/OfficeBrain/CustomBundle/ProductBundle/ProductAdmin/addProductAdvertise.html.twig")
*
*/
public function productAdvertiseAction(Request $request, $refId)
{
$this->init($request);
$RootDir = $this->serviceContainer->get('kernel')->getProjectDir();
$id = $this->request->request->get('id','');
$type = $this->request->request->get('type','product');
$ProductAdvDealentityobj = new ProductAdvertise();
$ProductAdvformObj = ProductAdvertiseType::class;
$ImagePath='';
if($id>0)
{
$ProductAdvDealentityobj = $this->productDetailManager->findProductAdvertiseById($id)[0];
$ImagePath=$ProductAdvDealentityobj->getUploadImage();
}
$this->form = $this->createForm($ProductAdvformObj, $ProductAdvDealentityobj, array(
'id' => $id,
'type' => $type,
));
$this->form->handleRequest($this->request);
if($this->form->isSubmitted())
{
if ($this->form->isValid())
{
$formdata=$this->form->getdata();
$this->productDetailManager->saveProductAdvertise($formdata,$refId,$ProductAdvDealentityobj,$RootDir,$ImagePath);
if($id){
$this->get('session')->getFlashBag()->add('success_message', $this->translator->trans('admin.productadvertise_update_msg'));
}
else{
$this->get('session')->getFlashBag()->add('success_message', $this->translator->trans('admin.productadvertise_save_msg'));
}
$response['Message'] = "success";
return new JsonResponse($response);
}
return new JsonResponse ( $this->prepareFormJsonError ($this->form) );
}
return array('form_psa_deal'=>$this->form->createView(),'refId'=>$refId,'id'=>$id,'ImagePathedit'=>$ImagePath,'type' => $type);
}
/**
*
* @author Kjethi
*
* Description : Change Status Product Advertise.
*
*
*
* @return type : JsonResponse object
*
* @throws Exception: No exception
*
* @Route("/product-advertise/change-status", name="officebrain_custombundle_productbundle_productadvertise_change_status",
*
* options={"expose"=true}, methods={"POST"}
* )
*
* @Template()
*
*/
public function changeStatusAction(Request $request)
{
$this->init($request);
$id = $this->request->get('id');
if ($id) {
$status = $this->productDetailManager->productAdvertiseChangeStatus($id);
if ($status) {
return new JsonResponse(array('status' => 'success', 'status_message' => $this->translator->trans('admin.productadvertise_status_message_success')));
}
}
return new JsonResponse(array('status' => 'fail', 'status_message' => $this->translator->trans('admin.productadvertise_status_message_fail')));
}
/**
* @author Kjethi
*
* Description : Delete
* @Route("/delete-product-advertise1",name="officebrain_custombundle_productbundle_productadvertise_product_advertise", methods={"GET","POST"})
* @Template()
*
*
*/
public function deleteProductAdvertiseAction(Request $request)
{
$this->init($request);
$id = $this->request->request->get('id','');
$Message = $this->productDetailManager->deleteProductAdvertiseRecords($id);
$this->get('session')->getFlashBag()->add('success_message', 'Advertise deleted successfully');
return new JsonResponse();
}
/**
* @author 6799
*
* Description : Get Esp Product Data
* @Route("/get-esp-product-data/{productSku}",name="officebrain_custombundle_product_bundle_get_esp_product_data", methods={"GET","POST"})
* @Template("project/OfficeBrain/CustomBundle/ProductBundle/ProductAdmin/addEspProductData.html.twig")
*
*
*/
public function getEspProductDataAction(Request $request)
{
$this->init($request);
$productSku = $this->request->get('productSku','');
$selectedData = $this->productDetailManager->getEspProductData($productSku);
$this->Response['data']['selected_product_type'] = "";
if($selectedData){
$this->Response['data']['selected_categories'] = $selectedData->getEspProductCategory();
$this->Response['data']['selected_product_type'] = $selectedData->getEspProductType();
}
$categoryDataApiUrl = "https://productservice.asicentral.com/api/v5/lookup/categorieslist";
$espCategoriesData = $this->productDetailManager->getDataFromEspApi($categoryDataApiUrl);
$espCategoriesData = json_decode($espCategoriesData,true);
$this->Response['data']['categories'] = $espCategoriesData["categories"];
$typeDataApiUrl ="https://productservice.asicentral.com/api/v5/lookup/producttypes";
$espProductTypes = $this->productDetailManager->getDataFromEspApi($typeDataApiUrl);
$espProductTypes = json_decode($espProductTypes,true);
$this->Response['data']['product_types'] = $espProductTypes["productTypes"];
$this->Response['data']['product_sku'] = $productSku;
return $this->Response;
}
/**
* @author 6799
*
* Description : SET Esp Product Data
* @Route("/set-esp-product-data/{productSku}",name="officebrain_custombundle_product_bundle_set_esp_product_data", methods={"GET","POST"})
* @Template()
*
*
*/
public function setEspProductDataAction(Request $request)
{
$this->init($request);
$productSku = $this->request->get("productSku");
$formData = $request->request->all();
$responseData = $this->productDetailManager->setEspProductData($productSku,$formData);
if(!empty($responseData)){
$data['status'] = "success_message";
$data['message'] = "Data Updated Successfully!!";
}
else{
$data['status'] = "error_message";
$data['message'] = "Something went wrong please try again later!!";
}
return new JsonResponse($data);
}
/**
* @author Employee Id: 6799
*
* Description : This function used for Import esp Data
* @return array
* @Route("/esp-data-import", name="officebrain_product_esp_data_import"),
* @Template("project/OfficeBrain/CustomBundle/ProductBundle/ProductAdmin/espDataImport.html.twig")
*/
public function espDataimportAction(Request $request){
$this->init($request);
$response = null;
if ($this->request->isXmlHttpRequest() && $this->request->getMethod()=='POST') {
if(!empty($_FILES)){
$file = $_FILES["esp_data_file"];
$response = $this->productDetailManager->importEspProductData($file);
}
if($response){
$return = array (
'status' => 'success',
'success_message'=> "Data Successfully Imported",
);
} else {
$return = array (
'status' => 'error',
'error_message' => "Something went wrong please try again later!"
);
}
return new JsonResponse($return);
}
}
/**
* @author Employee Id: 6799
*
* Description : This function used for Export esp Data
* @return array
* @Route("/esp-data-export.csv", name="officebrain_product_esp_data_export"),
* @Template()
*/
public function espDataExportAction(Request $request){
$this->init($request);
$responseData = $this->productDetailManager->getAllEspProductData();
$data = array("product_sku","esp_product_type","esp_category");
$rows[] = implode(',', $data);
foreach($responseData as $espData){
$rows[] = '"'.$espData->getProductSku().'","'.$espData->getEspProductType().'","'.$espData->getEspProductCategory().'"';
}
$content = implode("\n", $rows);
$response = new Response($content);
$response->headers->set('Content-Type', 'text/csv');
return $response;
}
/**
* @author Employee Id: 6799
*
* @return array
* @Route("/allowed-user-list", name="office_brain_custom_bundle_allowed_user_list"),
* @Template("project/OfficeBrain/CustomBundle/ProductBundle/ProductAdmin/allowed_user_list.html.twig")
*/
public function allowedUserListAction(Request $request)
{
$this->init($request);
$url = "https://psservices.aakronline.com/";
$jsonUsers = @file_get_contents($url."allowed-users");
$users = json_decode($jsonUsers, true);
return $users;
}
/**
* @author Employee Id: 6799
*
* @return array
* @Route("/add-user", name="office_brain_custom_bundle_add_user_allowed"),
* @Template("project/OfficeBrain/CustomBundle/ProductBundle/ProductAdmin/allowed_user_list.html.twig")
*/
public function addAllowedUserAction(Request $request)
{
$this->init($request);
$username = $this->request->get('username','');
$password = $this->request->get('password','');
$url = "https://psservices.aakronline.com/";
$jsonUsers = @file_get_contents($url."add-user?uu=".$username."&up=".$password);
$users = json_decode($jsonUsers, true);
if($users['status']==0){
$message = $users['message'];
$this->get('session')->getFlashBag()->add('error_message', $message);
}else{
$message = $users['message'];
$this->get('session')->getFlashBag()->add('success_message', $message);
}
return $this->redirect($this->generateUrl('office_brain_custom_bundle_allowed_user_list'));
}
/**
* @author Employee Id: 6799
*
* @return array
* @Route("/delete-user-list/{id}", name="office_brain_custom_bundle_delete_user_list"),
* @Template("project/OfficeBrain/CustomBundle/ProductBundle/ProductAdmin/allowed_user_list.html.twig")
*/
public function deleteAllowedUserAction(Request $request)
{
$this->init($request);
$id = $this->request->get('id','');
$url = "https://psservices.aakronline.com/";
$jsonUsers = @file_get_contents($url."delete-user?indx=".$id);
$this->get('session')->getFlashBag()->add('success_message', 'Allowed User deleted successfully');
return $this->redirect($this->generateUrl('office_brain_custom_bundle_allowed_user_list'));
}
/**
* @author Employee Id: 4246
*
* Description : This function used for Sync Product data to solr
*
* @Route("/sync-product-data",
* name="officebrain_custom_bundle_product_sync_product_data",
* options={"expose"=true})
* @Template("project/OfficeBrain/CustomBundle/ProductBundle/ProductAdmin/syncProductData.html.twig")
*/
public function syncProductDataAction(Request $request){
$this->init($request);
$connection = $this->entityManager->getConnection();
$projectSetting = $this->request->get('project_setting');
$projectId = $projectSetting['project_id'];
list($defaultCulture,$defaultCountry) = explode("_",$this->request->get("_locale"));
$culture = $this->request->get('language',$defaultCulture);
$country = $this->request->get('country',$defaultCountry);
$supplier_id = $this->request->query->get('supplier_id',5);
$countryArray = $this->serviceContainer->getParameter('country');
$languageArray = $this->serviceContainer->getParameter('language');
$supplierData = $this->productApiManager->getSupplierNameList($projectId);
$instanceType = $projectSetting['instance_type'];
//$country_to_pass = array_column($countryArray,'short_name');
//$language_to_pass = array_keys($languageArray);
// if ($this->user->getUserType()=='admin' && $instanceType=='association'){ // symfony 4
if ($this->user && $this->user->getUserType()=='admin' && $instanceType=='association'){
$supplier_id = $this->request->query->get('supplier_id','');
// } else if($this->user->getUserType()=='supplier' || $this->user->getUserType()=='distributor' || ($this->user->getUserType() == 'admin' && $instanceType == 'distributor') || ($this->user->getUserType() == 'admin' && $instanceType == 'supplier')){ // symfony 4
} elseif ($this->user && (
$this->user->getUserType() == 'supplier' ||
$this->user->getUserType() == 'distributor' || (
$this->user->getUserType() == 'admin' && (
$instanceType == 'distributor' ||
$instanceType == 'supplier'
)
)
) ) {
$supplier_id = $this->user->getObCustomerId();
$supplier_id = str_replace(array('OB','ob'), '', $supplier_id);
if(empty($supplier_id)){
$supplier_id = 0;
}
}else{
$supplier_id = 0;
}
foreach($countryArray as $countryKey => $country){
$data['country_data'][] = array('id'=>$country['id'],'code'=>$country['short_name'],'title'=>$country['name'],'language'=>$country['language']);
}
if ($this->request->isXmlHttpRequest() && $this->request->getMethod()=='POST') {
$data = $this->request->request->all();
if($data['country_short_name'] != "" && $data['language_short_name'] != ""){
$culture = $data['language_short_name']."_".$data['country_short_name'];
}else{
$culture = $this->request->get("_locale");
}
$imprintMethodMasterId = $this->serviceContainer->getParameter('imprint_method_master_id');
$imprintPositionMasterId = $this->serviceContainer->getParameter('imprint_position_master_id');
$packagingTypeMasterId = $this->serviceContainer->getParameter('packaging_type_master_id');
/* Data Mapping */
/*
$brandData = $this->brandApiManager->doBrandMappingFromProjectId($projectId);
$attributeData = $this->attributeApiManager->doAttributeMappingFromProjectId($projectId);
$imprintMethodAttributeData = $this->attributeApiManager->doAttributeMappingFromProjectId($projectId,'imprint_method',$imprintMethodMasterId);
$imprintLocationAttributeData = $this->attributeApiManager->doAttributeMappingFromProjectId($projectId,'imprint_location',$imprintPositionMasterId);
$imprintLocationAttributeData = $this->attributeApiManager->doAttributeMappingFromProjectId($projectId,'packaging',$imprintPositionMasterId);
$attributeMappingData = $this->attributeApiManager->doAttributeMapping();
$categoryMapping = $this->categoryApiManager->doCategoryMapping($projectId);
$productCategoryMapping = $this->productApiManager->doProductCategoryMapping($projectId,$data['country_id']);
*/
/* End Data Mapping */
$this->phpPath = $this->serviceContainer->getParameter('office_brain_ob_solr_operation.php_path');
$this->applicationPath = $this->serviceContainer->getParameter('office_brain_ob_solr_operation.application_path');
// $command = 'office_brain:solr:sync:product --projectId='.$data["project_id"].' --supplierId='.$data["supplier_id"].' --culture='.$culture.' > /dev/null 2>/dev/null &'; // symfony 4
$command = $this->phpPath . ' ' . $this->applicationPath . self::COMMAND_BASIC . ' ' . 'office_brain:solr:sync:product --projectId='.$data["project_id"].' --supplierId='.$data["supplier_id"].' --culture='.$culture;
$command = 'nohup ' . $command . ' > /dev/null 2>/dev/null &';
// $command = 'nohup php ' . $this->get('kernel')->getRootDir() . '/console ' .$command ; // symfony 4
shell_exec($command);
unset($command);
$statement = $connection->prepare(
'UPDATE `tbl_solar_sync_status` SET status=0 WHERE id = :id'
);
$statement->bindValue('id', 1);
$statement->execute();
return new JsonResponse(array('status'=>'success','message'=>'Sync is on progress'));
/*if($output){
$time = date('d_m_Y_H_i_s');
$fp = fopen($this->get('kernel')->getRootDir()."/../web/solr_logs/solr_sync_error_log_".$time.".txt", 'w+');
fwrite($fp, $output);
fclose($fp);
return new JsonResponse(array('status'=>'success'));
}else{
return new JsonResponse(array('status'=>'fail','message'=>"There is some issue please check after some time"));
}*/
}
/*$statement = $connection->prepare(
'UPDATE `tbl_solar_sync_status` SET status=1 WHERE id = :id'
);
$statement->bindValue('id', 1);
$statement->execute();
*/
// commented for symfony 5
// $statement = $connection->prepare(
// 'SELECT status FROM `tbl_solar_sync_status` WHERE id = :id'
// );
// $statement->bindValue('id', 1);
// $statement->execute();
// $result = $statement->fetchAll();
$query = 'SELECT status FROM tbl_solar_sync_status WHERE id = :id';
$result = $connection->executeQuery($query, ['id' => 1]);
$result = $result->fetchAllAssociative();
$data['solar_sync_status']=$result[0]['status'];
$data['project_id'] = $projectId;
$data['country_array'] = $countryArray;
$data['language_data'] = $languageArray;
$data['supplier_data'] = $supplierData;
$data['INSTANCE_TYPE'] = $instanceType;
$data['supplier_id']=$supplier_id;
return array('data'=>$data);
}
/**
* @author Employee Id: 5190
*
* Description : This function used for solar sync status
* @return array
* @Route("/check-solar-sync-status", name="officebrain_product_check_solar_sync_status"),
*
*/
public function checkSolarSyncStatus(Request $request){
$this->init($request);
$connection = $this->entityManager->getConnection();
$query = 'SELECT status FROM `tbl_solar_sync_status` WHERE id = :id';
$result = $connection->executeQuery($query, ['id' => 1]);
$result = $result->fetchAllAssociative();
// $statement->bindValue('id', 1);
// $statement->execute();
// $result = $statement->fetchAll();
$data = array();
$data['status'] = 'success';
$data['solar_sync_status']=$result[0]['status'];
return new JsonResponse($data);
}
}