src/AppBundle/EventListener/VehicleListener.php line 144

Open in your IDE?
  1. <?php
  2. namespace AppBundle\EventListener;
  3. use AppBundle\Service\UtilService;
  4. use GeoIp2\Util;
  5. use Pimcore\Event\Model\ElementEventInterface;
  6. use Pimcore\Event\Model\DataObjectEvent;
  7. use Pimcore\Event\Model\AssetEvent;
  8. use Pimcore\Event\Model\DocumentEvent;
  9. use Pimcore\Model\DataObject\Accessories;
  10. use Pimcore\Model\DataObject\Vehicle;
  11. use Pimcore\Model\DataObject\VehicleMaster;
  12. use Pimcore\Model\DataObject\VehiclePrice;
  13. use Pimcore\Model\DataObject\VehiclePriceAttribute;
  14. use Pimcore\Model\DataObject\VehiclePriceOptions;
  15. use Pimcore\Model\DataObject\MinBookingAmount;
  16. use Pimcore\Model\DataObject\Tax;
  17. use Symfony\Component\HttpClient\HttpClient;
  18. use \Pimcore\Model\DataObject;
  19. use Symfony\Component\HttpFoundation\Response;
  20. use Symfony\Component\Workflow\Event\TransitionEvent;
  21. use Pimcore\Tool\Frontend;
  22. use Pimcore\Model\DataObject\AccessoryPacks;
  23. use Pimcore\Model\DataObject\Pincode;
  24. use Pimcore\Log\ApplicationLogger;
  25. class VehicleListener {
  26.     public function onApproval(TransitionEvent $event){
  27.         $vehicle $event->getSubject();
  28.             if(!$vehicle->hasChildren()){
  29.                 if($vehicle->getParent() instanceof VehicleMaster){
  30.                     $parentId $vehicle->getParentId();
  31.                     $vehicle VehicleMaster::getById($parentId);
  32.                 }
  33.             }
  34.             $tmpData['id'] = $vehicle->getId();
  35.             $tmpData['lcdv'] = $vehicle->getLcdv();
  36.             $tmpData['startDate'] = $vehicle->getStartDate()->toDateString('Y-m-d');
  37.             $tmpData['endDate'] = $vehicle->getEndDate()->toDateString('Y-m-d');
  38.             $tmpData['name'] = $vehicle->getName();
  39.             $tmpData['commercialDesc'] = $vehicle->getCommercialDescription();
  40.             $tmpData['cubicCapacity'] = $vehicle->getCubicCapacity();
  41.             $tmpData['kilowatt'] = $vehicle->getKilowatt();
  42.             $tmpData['sittingCapacity'] = $vehicle->getSittingCapacity();
  43.             $tmpData['isantiTheftFaceLifted'] = $vehicle->getIsantiTheftFaceLifted();
  44.             $tmpData['dst_is_disabled'] = $vehicle->getDst_is_disabled();
  45.             if($tmpData['dst_is_disabled'] == true){
  46.                 $tmpData['dst_is_disabled'] = 'Yes';
  47.             }
  48.             if($tmpData['dst_is_disabled'] == false){
  49.                 $tmpData['dst_is_disabled'] = 'No';
  50.             }
  51.             $tmpData['dp_is_disabled'] = $vehicle->getDp_is_disabled();
  52.             if($tmpData['dp_is_disabled'] == true){
  53.                 $tmpData['dp_is_disabled'] = 'Yes';
  54.             }
  55.             if($tmpData['dp_is_disabled'] == false){
  56.                 $tmpData['dp_is_disabled'] = 'No';
  57.             }
  58.             $minBookingAmount MinBookingAmount::getByVehicle($vehicle);
  59.             if ($minBookingAmount->getCount() > 0) {
  60.                 $minBookingAmount $minBookingAmount->getData()[0];
  61.                 $tmpData['preBookingAmount'] = $minBookingAmount->getPreBookingAmount()->getValue();
  62.                 $tmpData['bookingAmount'] = $minBookingAmount->getBookingAmount()->getValue();
  63.             } else {
  64.                 $tmpData['preBookingAmount'] = 0;
  65.                 $tmpData['bookingAmount'] = 0;
  66.             }
  67.             $tmpData['lcdvAttributes'] = [];
  68.             $tmpData['lcdvAttributes']['validityStart'] = $vehicle->getValidityStart()->toDateString('Y-m-d');
  69.             $tmpData['lcdvAttributes']['validityEnd'] = $vehicle->getValidityEnd()->toDateString('Y-m-d');
  70.             $tmpData['lcdvAttributes']['Attributes'] = [];
  71.             $couplet = ['Basic''Descriptive''Personal'];
  72.             foreach ($couplet as $value) {
  73.                 if ($value == 'Basic' && !empty($vehicle->getBasicInformation())) {
  74.                     $basicAttributeInfo $vehicle->getBasicInformation()->getItems();
  75.                     $tmpData['lcdvAttributes']['Attributes']['basic'] = UtilService::processAttributes($basicAttributeInfo);
  76.                 } else if ($value == 'Descriptive' && !empty($vehicle->getDescriptiveInformation())) {
  77.                     $descriptiveAttributeInfo $vehicle->getDescriptiveInformation()->getItems();
  78.                     $tmpData['lcdvAttributes']['Attributes']['descriptive'] = UtilService::processAttributes($descriptiveAttributeInfo);
  79.                 } else if ($value == 'Personal' && !empty($vehicle->getPersonalInformation())) {
  80.                     $personalAttributeInfo $vehicle->getPersonalInformation()->getItems();
  81.                     $tmpData['lcdvAttributes']['Attributes']['personal'] = UtilService::processAttributes($personalAttributeInfo);
  82.                 }
  83.             }
  84.             $vehicleData['vehicleInfo'] = $tmpData;
  85.             $vehicleData['variantInfo'] = [];
  86.             if ($vehicle->hasChildren()) {
  87.                 $children $vehicle->getChildren();
  88.                 foreach ($children as $child) {
  89.                     if ($child instanceof VehicleMaster) {
  90.                         //if ($child->isPublished()) {
  91.                             $tmpChildData UtilService::getVehicleChild($child);
  92.                             array_push($vehicleData['variantInfo'], $tmpChildData);
  93.                         //}
  94.                     }
  95.                 }
  96.             }
  97.             $responseArr = [];
  98.             $responseArr['data'] = $vehicleData;
  99.             $apiURLData = \Pimcore\Model\WebsiteSetting::getByName("MAGNETO_APIURL"null);
  100.             $apiURL $apiURLData->getData() . '/rest/V1/productSync';
  101.             $this->callAPI('POST',$apiURL,json_encode($responseArr));
  102.     }
  103.     public function onObjectPostDelete(ElementEventInterface $event){
  104.         if($event instanceof DataObjectEvent) {
  105.             if($event->getObject() instanceof  VehicleMaster){
  106.                 $object $event->getObject();
  107.                 $lcdv $object->getLcdv();
  108.                 $resp = [];
  109.                 $resp['lcdv16']='';
  110.                 $resp['lcdv24']='';
  111.                 if(strlen($lcdv ) == 16){
  112.                     $resp['lcdv16']=$lcdv;
  113.                 }else{
  114.                     $resp['lcdv24']=$lcdv;
  115.                 }
  116.                 $responseArr = [];
  117.                 $responseArr['data'] = $resp;
  118.                 $apiURLData = \Pimcore\Model\WebsiteSetting::getByName("MAGNETO_APIURL"null);
  119.                 $apiURL $apiURLData->getData() . '/rest/V1/productSync';
  120.                 //$this->callAPI('POST',$apiURL,json_encode($responseArr));
  121.             }
  122.         }
  123.     }
  124.     public function onObjectPostUpdate (ElementEventInterface $event) {
  125.         if($event instanceof DataObjectEvent) {
  126.             if($event->getObject() instanceof  VehicleMaster){
  127.                 $object $event->getObject();
  128.                 $id $object->getId();
  129.                 $vehicleData = [];
  130.                 $vehicle VehicleMaster::getById($id);
  131.                 if($vehicle->isPublished()) {
  132.                     if(!$vehicle->hasChildren()){
  133.                         if($vehicle->getParent() instanceof VehicleMaster){
  134.                             $parentId $vehicle->getParentId();
  135.                             $vehicle VehicleMaster::getById($parentId);
  136.                         }
  137.                     }
  138.                     $tmpData['id'] = $vehicle->getId();
  139.                     $tmpData['lcdv'] = $vehicle->getLcdv();
  140.                     $tmpData['startDate'] = $vehicle->getStartDate()->toDateString('Y-m-d');
  141.                     $tmpData['endDate'] = $vehicle->getEndDate()->toDateString('Y-m-d');
  142.                     $tmpData['name'] = $vehicle->getName();
  143.                     $tmpData['commercialDesc'] = $vehicle->getCommercialDescription();
  144.                     $tmpData['model'] = $vehicle->getModelName();
  145.                     $tmpData['variant'] = $vehicle->getVariantName();
  146.                     $tmpData['cubicCapacity'] = $vehicle->getCubicCapacity();
  147.                     $tmpData['kilowatt'] = $vehicle->getKilowatt();
  148.                     $tmpData['sittingCapacity'] = $vehicle->getSittingCapacity();
  149.                     $tmpData['isantiTheftFaceLifted'] = $vehicle->getIsantiTheftFaceLifted();
  150.                     $tmpData['dst_is_disabled'] = $vehicle->getDst_is_disabled();
  151.                     if($tmpData['dst_is_disabled'] == true){
  152.                         $tmpData['dst_is_disabled'] = 'Yes';
  153.                     }
  154.                     if($tmpData['dst_is_disabled'] == false){
  155.                         $tmpData['dst_is_disabled'] = 'No';
  156.                     }
  157.                     $tmpData['dp_is_disabled'] = $vehicle->getDp_is_disabled();
  158.                     if($tmpData['dp_is_disabled'] == true){
  159.                         $tmpData['dp_is_disabled'] = 'Yes';
  160.                     }
  161.                     if($tmpData['dp_is_disabled'] == false){
  162.                         $tmpData['dp_is_disabled'] = 'No';
  163.                     }
  164.                     $minBookingAmount MinBookingAmount::getByVehicle($vehicle);
  165.                     if ($minBookingAmount->getCount() > 0) {
  166.                         $minBookingAmount $minBookingAmount->getData()[0];
  167.                         $tmpData['preBookingAmount'] = $minBookingAmount->getPreBookingAmount()->getValue();
  168.                         $tmpData['bookingAmount'] = $minBookingAmount->getBookingAmount()->getValue();
  169.                     } else {
  170.                         $tmpData['preBookingAmount'] = 0;
  171.                         $tmpData['bookingAmount'] = 0;
  172.                     }
  173.                     $tmpData['lcdvAttributes'] = [];
  174.                     $tmpData['lcdvAttributes']['validityStart'] = $vehicle->getValidityStart()->toDateString('Y-m-d');
  175.                     $tmpData['lcdvAttributes']['validityEnd'] = $vehicle->getValidityEnd()->toDateString('Y-m-d');
  176.                     $tmpData['lcdvAttributes']['Attributes'] = [];
  177.                     $couplet = ['Basic''Descriptive''Personal'];
  178.                     foreach ($couplet as $value) {
  179.                         if ($value == 'Basic' && !empty($vehicle->getBasicInformation())) {
  180.                             $basicAttributeInfo $vehicle->getBasicInformation()->getItems();
  181.                             $tmpData['lcdvAttributes']['Attributes']['basic'] = UtilService::processAttributes($basicAttributeInfo);
  182.                         } else if ($value == 'Descriptive' && !empty($vehicle->getDescriptiveInformation())) {
  183.                             $descriptiveAttributeInfo $vehicle->getDescriptiveInformation()->getItems();
  184.                             $tmpData['lcdvAttributes']['Attributes']['descriptive'] = UtilService::processAttributes($descriptiveAttributeInfo);
  185.                         } else if ($value == 'Personal' && !empty($vehicle->getPersonalInformation())) {
  186.                             $personalAttributeInfo $vehicle->getPersonalInformation()->getItems();
  187.                             $tmpData['lcdvAttributes']['Attributes']['personal'] = UtilService::processAttributes($personalAttributeInfo);
  188.                         }
  189.                     }
  190.                     $vehicleData['vehicleInfo'] = $tmpData;
  191.                     $vehicleData['variantInfo'] = [];
  192.                     if ($vehicle->hasChildren()) {
  193.                         $children $vehicle->getChildren();
  194.                         foreach ($children as $child) {
  195.                             if ($child instanceof VehicleMaster && !empty($child)) {
  196.                                 if ($child->isPublished()) {
  197.                                     $tmpChildData UtilService::getVehicleChild($child);
  198.                                     array_push($vehicleData['variantInfo'], $tmpChildData);
  199.                                 }
  200.                             }
  201.                         }
  202.                     }
  203.                     $vehicleData['axisInfo']=[];
  204.                     $vehicleData['axisInfo']['axisVariantName'] = $vehicle->getAxisVariantName();
  205.                     $vehicleData['axisInfo']['axisbrandId'] = $vehicle->getAxisbrandId();
  206.                     $vehicleData['axisInfo']['axisvariantId'] = $vehicle->getAxisvariantId();
  207.                     $vehicleData['axisInfo']['axismakeId'] = $vehicle->getAxismakeId();
  208.                     $vehicleData['axisInfo']['axiscategory'] = $vehicle->getAxiscategory();
  209. //                        $file = fopen("VMJSON.txt", "w");
  210. //                        $v = fwrite($file, json_encode($vehicleData));
  211. //                        fclose($file);
  212.                     $responseArr = [];
  213.                     $responseArr['data'] = $vehicleData;
  214.                     $apiURLData = \Pimcore\Model\WebsiteSetting::getByName("MAGNETO_APIURL"null);
  215.                     $apiURL $apiURLData->getData() . '/rest/V1/productSync';
  216.                     $this->callAPI('POST',$apiURL,json_encode($responseArr));
  217.                 }else{
  218.                     $responseArr = [];
  219.                     $responseArr['data'] = $vehicle->getLcdv();
  220.                     $apiURLData = \Pimcore\Model\WebsiteSetting::getByName("MAGNETO_APIURL"null);
  221.                     $apiURL $apiURLData->getData() . '/rest/V1/productSync';
  222.                     //$this->callAPI('POST',$apiURL,json_encode($responseArr));
  223.                 }
  224.                 $allVehicles = new DataObject\VehicleMaster\Listing();
  225.                 $allVehicles->setUnpublished(false);
  226.                 $allVehiclesData $allVehicles->load();
  227.                 $tmpAllDataArr = [];
  228.                 if(count($allVehiclesData) > 0){
  229.                     foreach($allVehiclesData as $vehicle){
  230.                         if(strlen($vehicle->getLcdv()) == 16 && $vehicle->isPublished()) {
  231.                             $dataArrModel['car_family'] = substr($vehicle->getLcdv(), 04);
  232.                             $dataArrModel['car_name'] = $vehicle->getName();
  233.                             $dataArrModel['LCDV16'] = $vehicle->getLcdv();
  234.                             $dataArrModel['model_name'] = $vehicle->getModelName();
  235.                             array_push($tmpAllDataArr$dataArrModel);
  236.                             }
  237.                         }
  238.                     $responseArr = [];
  239.                     $responseArr['success'] = 'true';
  240.                     $responseArr['errors'] = [];
  241.                     $responseArr['data'] = $tmpAllDataArr;
  242.                     $apiURLData = \Pimcore\Model\WebsiteSetting::getByName("MAGNETO_APIURL"null);
  243.                     $apiURL $apiURLData->getData() . '/rest/V1/modelSync';
  244.                     $this->callAPI('POST',$apiURL,json_encode($responseArr));
  245.                 }
  246.             } else if($event->getObject() instanceof  Accessories){
  247.                 $object $event->getObject();
  248.                 $id $object->getId();
  249.                 $axsData = [];
  250.                 $axs Accessories::getById($id);
  251.                 if($axs->isPublished()){
  252.                     $tmpData['id'] = $axs->getId();
  253.                     $tmpData['referenceId'] = $axs->getReferenceId();
  254.                     $tmpData['brand'] = $axs->getBrand();
  255.                     $tmpData['vehicleFamily'] = $axs->getVehicleFamily();
  256.                     $tmpData['bodyStyle'] = $axs->getBodystyle();
  257.                     $tmpData['language'] = $axs->getLangue();
  258.                     $tmpData['universe'] = $axs->getUniverse();
  259.                     $tmpData['subUniverse'] = $axs->getSubUniverse();
  260.                     $tmpData['commercialName'] = $axs->getCommercialName();
  261.                     $tmpData['commercialDesc'] = $axs->getCommercialDescription();
  262.                     $tmpData['sellingUnit'] = $axs->getSellingUnit();
  263.                     $tmpData['linkedRefs'] = $axs->getLinkedReferences();
  264.                     $tmpData['prixHt'] = $axs->getPrixHT();
  265.                     $tmpData['prixTTC'] = $axs->getPrixTTC();
  266.                     $tmpData['dealerFitting'] = $axs->getDealerFitting();
  267.                     $tmpData['accessoryRange'] = $axs->getAccessoryRange();
  268.                     $tmpData['date'] = $axs->getDate();
  269.                     $tmpData['accessorycolor'] = $axs->getAccessorycolor();
  270.                     $tmpData['files'] = [];
  271.                     $tmpData['category'] = $axs->getCategory();
  272.                     $tmpData['subCategory'] = $axs->getSubCategory();
  273.                     $tmpData['onlineSales'] = $axs->getOnlineSales();
  274.                     $tmpData['variant'] = $axs->getVariant();
  275.                     if($tmpData['variant'] == null){
  276.                         $tmpData['variant'] = [];
  277.                     }
  278.                     $tmpData['applicable_sol'] = $axs->getApplicable_sol();
  279.                     $files $axs->getFiles();
  280.                     foreach($files as $file){
  281.                         $tmpData['files'] = $file['accImages']->getData();
  282.                     }
  283.                     $tmpData['sitting_capacity'] = $axs->getSitting_capacity();
  284.                     $tmpData['CC24_category'] = $axs->getCC24_category();
  285.                     $tmpData['CC24_subCategory'] = $axs->getCC24_subCategory();
  286.                     $tmpData['CC24_files'] = $axs->getCC24_files();
  287.                     $tmpData['CC22_category'] = $axs->getCC22_category();
  288.                     $tmpData['CC22_subCategory'] = $axs->getCC22_subCategory();
  289.                     $tmpData['CC22_files'] = $axs->getCC22_files();
  290.                     $tmpData['group_id'] = $axs->getGroup_id();
  291.                     $tmpData['Is3D'] = $axs->getIs3D();
  292.                     if($tmpData['Is3D'] == null){
  293.                         $tmpData['Is3D'] = 'No';
  294.                     }
  295.                     array_push($axsData,$tmpData);
  296.                     $apiURLData = \Pimcore\Model\WebsiteSetting::getByName("MAGNETO_APIURL"null);
  297.                     $apiURL $apiURLData->getData().'/rest/V1/accessoriesSync';
  298.                     $this->callAPI('POST',$apiURL,json_encode($axsData));
  299. //                    $myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
  300. //                    fwrite($myfile, json_encode($a->getContent()));
  301.                 }
  302.             }else if($event->getObject() instanceof  AccessoryPacks){
  303.                 $object $event->getObject();
  304.                 $id $object->getId();
  305.                 $axspackData = [];
  306.                 $axs AccessoryPacks::getById($id);
  307.                 if($axs->isPublished()){
  308.                     $tmpData['id'] = $axs->getId();
  309.                     $tmpData['packCode'] = $axs->getPackCode();
  310.                     $tmpData['HSNCODE'] = $axs->getHSNCODE();
  311.                     $tmpData['price'] = $axs->getPrice();
  312.                     $tmpData['packName'] = $axs->getPackName();
  313.                     $tmpData['variant'] = $axs->getVariant();
  314.                     $tmpData['charname'] = $axs->getCharname();
  315.                     $tmpData['charoptions'] = $axs->getCharoptions();
  316.                     $tmpData['sap_pack_id'] = $axs->getSap_pack_id();
  317.                     $tmpData['applicable_sol'] = $axs->getApplicable_sol();
  318.                     // $tmpData['bodycolor'] = $axs->getBodycolor();
  319.                     // $tmpData['roofcolor'] = $axs->getRoofcolor();
  320.                     // $tmpData['ipcolor'] = $axs->getIpcolor();
  321.                     $tmpData['accessories'] = [];
  322.                     $accessories $axs->getAccessories();
  323.                     foreach($accessories as $accessory){
  324.                         //print_r($accessory);
  325.                         $accessoryDetail Accessories::getById($accessory->getObjectId());
  326.                         $tmpData['accessories'][] = $accessoryDetail->getReferenceId();
  327.                     }
  328.                     $tmpData['not_allow_accessory'] = [];
  329.                     $not_allow_accessories $axs->getNotAllowAccessories();
  330.                     foreach($not_allow_accessories as $not_accessory){
  331.                         //print_r($accessory);
  332.                         $not_accessoryDetail Accessories::getById($not_accessory->getObjectId());
  333.                         $tmpData['not_allow_accessory'][] = $not_accessoryDetail->getReferenceId();
  334.                     }
  335.                     $tmpData['3d_code'] = $axs->getCode_3d();
  336.                     $tmpData['sitting_capacity'] = $axs->getSitting_capacity();
  337.                     array_push($axspackData,$tmpData);
  338.                     $apiURLData = \Pimcore\Model\WebsiteSetting::getByName("MAGNETO_APIURL"null);
  339.                     $apiURL $apiURLData->getData().'/rest/V1/accessoryPacksSync';
  340.                     $this->callAPI('POST',$apiURL,json_encode($axspackData));
  341. //                    $myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
  342. //                    fwrite($myfile, json_encode($a->getContent()));
  343.                 }
  344.             }
  345.             else if ($event->getObject() instanceof VehiclePrice){
  346.                 $object $event->getObject();
  347.                 $id $object->getId();
  348.                 $price VehiclePrice::getById($id);
  349.                 if($price->isPublished()){
  350.                     $lcdv $price->getLcdv16();
  351.                     $responseArr = [];
  352.                     $responseArr['lcdv16'] = $lcdv;
  353.                     $apiURLData = \Pimcore\Model\WebsiteSetting::getByName("MAGNETO_APIURL"null);
  354.                     $apiURL $apiURLData->getData() . '/rest/V1/updatedPrice';
  355.                     $this->callAPI('POST',$apiURL,json_encode($responseArr));
  356.                 }
  357.             }
  358.             else if ($event->getObject() instanceof VehiclePriceAttribute){
  359.                 $object $event->getObject();
  360.                 $id $object->getId();
  361.                 $price VehiclePrice::getById($id);
  362.                 if($price->isPublished()){
  363.                     $lcdv $price->getLcdv16();
  364.                     $responseArr = [];
  365.                     $responseArr['lcdv16'] = $lcdv;
  366.                     $apiURLData = \Pimcore\Model\WebsiteSetting::getByName("MAGNETO_APIURL"null);
  367.                     $apiURL $apiURLData->getData() . '/rest/V1/updatedPrice';
  368.                     $this->callAPI('POST',$apiURL,json_encode($responseArr));
  369.                 }
  370.             }
  371.             else if ($event->getObject() instanceof VehiclePriceOptions){
  372.                 $object $event->getObject();
  373.                 $id $object->getId();
  374.                 $price VehiclePrice::getById($id);
  375.                 if(!empty($price) && $price->isPublished()){
  376.                     $lcdv $price->getLcdv16();
  377.                     $responseArr = [];
  378.                     $responseArr['lcdv16'] = $lcdv;
  379.                     $apiURLData = \Pimcore\Model\WebsiteSetting::getByName("MAGNETO_APIURL"null);
  380.                     $apiURL $apiURLData->getData() . '/rest/V1/updatedPrice';
  381.                     $this->callAPI('POST',$apiURL,json_encode($responseArr));
  382.                 }
  383.             }
  384.             else if($event->getObject() instanceof Pincode){
  385.                 $object $event->getObject();
  386.                 $id $object->getId();
  387.                 $pincodeData = [];
  388.                 $pin_code Pincode::getById($id);
  389.                 // print_r($pin_code);exit;
  390.                 if($pin_code->isPublished()){
  391.                     $tmpData['id'] = $pin_code->getId();
  392.                     $tmpData['PostalCode'] = $pin_code->getCode();
  393.                     $tmpData['CityName'] = $pin_code->getDistrictName();
  394.                     $tmpData['CityCode'] = $pin_code->getDistrictCode();
  395.                     $tmpData['StateCode'] = $pin_code->getStateCode();
  396.                     $tmpData['IsActive'] = "true";
  397.                     //Get State Name from State Code
  398.                     $stateDataListing DataObject\Region::getByCode($pin_code->getStateCode());
  399.                     if($stateDataListing->getCount() > 0){
  400.                         $stateData $stateDataListing->load()[0];
  401.                         $tmpData['StateName'] = ucfirst($stateData->getName());
  402.                     }else{
  403.                         $tmpData['StateName'] = '';
  404.                     }
  405.                     array_push($pincodeData,$tmpData);
  406.                     $apiURLData = \Pimcore\Model\WebsiteSetting::getByName("DMS_PINCODE_SYNC_URL"null);
  407.                     $apiURL $apiURLData->getData();
  408.                     $pin_response $this->callAPIPincode('POST',$apiURL,json_encode($pincodeData));
  409.                     $log_data['time'] = date('m/d/Y h:i:s a'time());
  410.                     $log_data['response'] = $pin_response->getContent();
  411.                     $myfile fopen("../var/logs/pincodeLog.txt""a") or die("Unable to open file!");
  412.                     fwrite($myfile"\n".json_encode($log_data));
  413.                 }
  414.             }
  415.         }
  416.     }
  417.     public function callAPI($method$url$data)
  418.     {
  419.         $client HttpClient::create();
  420.         return $response $client->request(
  421.             $method,
  422.             $url,
  423.             [   'headers' => [
  424.                 'Content-Type' => 'application/json',
  425.             ],
  426.                 'body'=>$data]
  427.         );
  428.     }
  429.     public function callAPIPincode($method$url$data)
  430.     {
  431.         try{
  432.             $config =Frontend::getWebsiteConfig();
  433.             $dms_username $config->get('DMS_PINCODE_USERNAME');
  434.             $dms_password $config->get('DMS_PINCODE_PASSWORD');
  435.             $client HttpClient::create();
  436.             return $response $client->request(
  437.                 $method,
  438.                 $url,
  439.                 [   'headers' => [
  440.                     'Content-Type' => 'application/json',
  441.                     "Authorization"=>'Basic '.base64_encode("$dms_username:$dms_password")
  442.                     // "Host" => "13.126.172.20"
  443.                 ],
  444.                     'body'=>$data]
  445.             );
  446.         }catch (\Exception $e){
  447.             echo $e->getMessage();
  448.             exit;
  449.         }
  450.     }
  451. }