src/EventListener/DefaultValueProvider.php line 576

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use Pimcore\Model\Asset;
  4. use Pimcore\Event\Model\ElementEventInterface;
  5. use Pimcore\Event\Model\DataObjectEvent;
  6. use Pimcore\Event\Model\AssetEvent;
  7. use Pimcore\Event\Model\DocumentEvent;
  8. use Pimcore\Event\Model\VersionEvent;
  9. use \Pimcore\Model\DataObject;
  10. use Symfony\Component\EventDispatcher\GenericEvent;
  11. use Pimcore\Model\Element\ValidationException;
  12. use Pimcore\Model\DataObject\Service as DoService;
  13. class DefaultValueProvider extends \Pimcore\Bundle\AdminBundle\Controller\AdminController {
  14.     public function onPostAdd(ElementEventInterface $e) {
  15.         if ($e instanceof DataObjectEvent) {
  16.             $objectData $e->getObject();
  17.             if($objectData->gettype() == 'object'){
  18.                 if($objectData->getClassName() == 'ProductCategory') {
  19.                     // $categoryAddUrl = "https://integration-5ojmyuq-23txbi6folvo6.ap-3.magentosite.cloud/rest/V1/bridge/catalog/category/add";
  20.                     $categoryAddUrl "http://local.itc.com/rest/V1/bridge/catalog/category/addToData";
  21.                     $data = array( 
  22.                         "category_id" => $objectData->getId(),
  23.                         "store_view_id" => "0"
  24.                     ); 
  25.                     $productSyncKey "qzgg1vbpgwk6pjctbv6ku2a65906ocpb";
  26.                     // $productSyncKey = "ah2zed4d9rcqgxc4ds16bh6wssdm8xni";
  27.                     $data_json json_encode(array("data" => $data)); 
  28.                     $curl curl_init(); curl_setopt($curlCURLOPT_CUSTOMREQUEST"PUT"); 
  29.                     curl_setopt($curlCURLOPT_POSTFIELDS$data_json); 
  30.                     curl_setopt($curlCURLOPT_URL$categoryAddUrl); 
  31.                     curl_setopt($curlCURLOPT_HTTPHEADER, array( 'Authorization: Bearer ' $productSyncKey'Accept: application/json''Content-Type:application/json', )); 
  32.                     curl_setopt($curlCURLOPT_RETURNTRANSFER1); 
  33.                     curl_setopt($curlCURLOPT_HTTPAUTHCURLAUTH_BASIC); 
  34.                     $result curl_exec($curl); 
  35.                     $resultArray json_decode($result); 
  36.                     curl_close($curl);
  37.                 }
  38.                 if($objectData->getClassName() == 'Products') {
  39.                     // $productSyncKey = "enlwq7pkg6t2od9blt93coomo7g6p9p0"; // Live Integration
  40.                     $productSyncKey "qzgg1vbpgwk6pjctbv6ku2a65906ocpb"// Local
  41.                     // $productUpdatedUrl = 'https://integration-5ojmyuq-23txbi6folvo6.ap-3.magentosite.cloud/rest/V1/bridge/catalog/product/add';
  42.                     $productUpdatedUrl 'http://local.itc.com/rest/V1/bridge/catalog/product/add';
  43.                     // echo $productUpdatedUrl.'<br>';
  44.                     // echo $productSyncKey;
  45.                     $data = array( "product_id" => $objectData->getId(),"store_view_id" => "0", );
  46.                     $data_json json_encode(array("data" => $data));
  47.                     $curl curl_init();
  48.                     curl_setopt($curlCURLOPT_CUSTOMREQUEST"PUT");
  49.                     curl_setopt($curlCURLOPT_POSTFIELDS$data_json);
  50.                     curl_setopt($curlCURLOPT_URL$productUpdatedUrl);
  51.                     curl_setopt($curlCURLOPT_HTTPHEADER, array( 'Authorization: Bearer ' $productSyncKey'Accept: application/json''Content-Type:application/json', ));
  52.                     curl_setopt($curlCURLOPT_RETURNTRANSFER1);
  53.                     curl_setopt($curlCURLOPT_HTTPAUTHCURLAUTH_BASIC);
  54.                     $result curl_exec($curl);
  55.                     $resultArray json_decode($result);
  56.                     curl_close($curl);
  57.                     // echo '<pre>'; print_r($resultArray); exit;
  58.                 }
  59.                 $productClasses = array(
  60.                     'Products' => 'SAP',
  61.                     'ProductITCStore' => 'ITC Store',
  62.                     'ProductAmazon' => 'Amazon',
  63.                     'ProductBigBasket' => 'Big Basket',
  64.                     'ProductBlinkit' => 'Blinkit',
  65.                     'ProductFlipkart' => 'Flipkart',
  66.                     'ProductJioMart' => 'JioMart',
  67.                     'ProductSwiggy' => 'Swiggy',
  68.                     'ProductZepto' => 'Zepto'
  69.                 );
  70.                 if (array_key_exists($objectData->getClassName(),$productClasses)) {
  71.                     if(!str_contains($objectData->getpath(),"/SAP/Approved")) {
  72.                         $folder DataObject\Service::createFolderByPath('/Products/'.$productClasses[$objectData->getClassName()]);
  73.                         $folderId $folder->getId();
  74.                         $objectData->seto_parentId($folderId);
  75.                         $objectData->save();
  76.                     }
  77.                 }
  78.                 if($objectData->getClassName() == 'Products') {
  79.                     // Create Objects
  80.                     // $productObj = DataObject\Products::getById($objectData->getId());
  81.                     // $this->createMarketPlaceProduct($productObj);
  82.                 }
  83.             } else if($objectData->gettype() == 'folder'){
  84.             }
  85.         }
  86.     }
  87.     public function createMarketPlaceProduct($productObj) {
  88.         $key $productObj->getkey();
  89.         $newObject = new DataObject\ProductAmazon();
  90.         $newObject->setKey(\Pimcore\Model\Element\Service::getValidKey('A_'.$key'object'));
  91.         $newObject->setstoreProduct($productObj);
  92.         $newObject->seto_parentId('1');
  93.         $newObject->save(["versionNote" => "Product created from SAP"]);
  94.         $newObject = new DataObject\ProductBigBasket();
  95.         $newObject->setKey(\Pimcore\Model\Element\Service::getValidKey('BB_'.$key'object'));
  96.         $newObject->seto_parentId('1');
  97.         $newObject->setstoreProduct($productObj);
  98.         $newObject->save(["versionNote" => "Product created from SAP"]);
  99.         $newObject = new DataObject\ProductBlinkit();
  100.         $newObject->setKey(\Pimcore\Model\Element\Service::getValidKey('BI_'.$key'object'));
  101.         $newObject->seto_parentId('1');
  102.         $newObject->setstoreProduct($productObj);
  103.         $newObject->save(["versionNote" => "Product created from SAP"]);
  104.         $newObject = new DataObject\ProductFlipkart();
  105.         $newObject->setKey(\Pimcore\Model\Element\Service::getValidKey('FK_'.$key'object'));
  106.         $newObject->seto_parentId('1');
  107.         $newObject->setstoreProduct($productObj);
  108.         $newObject->save(["versionNote" => "Product created from SAP"]);
  109.         $newObject = new DataObject\ProductJioMart();
  110.         $newObject->setKey(\Pimcore\Model\Element\Service::getValidKey('JM_'.$key'object'));
  111.         $newObject->seto_parentId('1');
  112.         $newObject->setstoreProduct($productObj);
  113.         $newObject->save(["versionNote" => "Product created from SAP"]);
  114.         $newObject = new DataObject\ProductSwiggy();
  115.         $newObject->setKey(\Pimcore\Model\Element\Service::getValidKey('SG_'.$key'object'));
  116.         $newObject->seto_parentId('1');
  117.         $newObject->setstoreProduct($productObj);
  118.         $newObject->save(["versionNote" => "Product created from SAP"]);
  119.         $newObject = new DataObject\ProductZepto();
  120.         $newObject->setKey(\Pimcore\Model\Element\Service::getValidKey('Zepto_'.$key'object'));
  121.         $newObject->seto_parentId('1');
  122.         $newObject->setstoreProduct($productObj);
  123.         $newObject->save(["versionNote" => "Product created from SAP"]);
  124.         $newObject = new DataObject\ProductITCStore();
  125.         $newObject->setKey(\Pimcore\Model\Element\Service::getValidKey('Store_'.$key'object'));
  126.         $newObject->seto_parentId('1');
  127.         $newObject->setstoreProduct($productObj);
  128.         $newObject->save(["versionNote" => "Product created from SAP"]);
  129.     }
  130.     function validateAlphanumeric($str) {
  131.         if (strlen($str) != 40) {
  132.             return false;
  133.         }
  134.         // Check the first 5 characters are numeric
  135.         if (!preg_match('/^\d{5}/'$str)) {
  136.             return false;
  137.         }
  138.     
  139.         // Check the sixth character is a space
  140.         if ($str[5] != ' ') {
  141.             return false;
  142.         }
  143.         // Check the remaining 34 characters are alphabetic
  144.         if (!preg_match('/^[a-zA-Z]{34}$/'substr($str6))) {
  145.             return false;
  146.         }
  147.     
  148.         // String passed all tests, so it's valid
  149.         return true;
  150.     }
  151.     function validateAlphabetsOnly($string) {
  152.         // The regular expression /^[A-Za-z]+$/ matches one or more alphabetical characters from A to Z (both uppercase and lowercase)
  153.         if (preg_match('/^[A-Za-z]+$/'$string)) {
  154.           return true// The string only contains alphabetic characters
  155.         } else {
  156.           return false// The string contains non-alphabetic characters
  157.         }
  158.     }
  159.     public function onPreUpdate(ElementEventInterface $e) {
  160.         if ($e instanceof DataObjectEvent) {
  161.             $objectData $e->getObject();
  162.             if($objectData->gettype() == 'object'){
  163.                 $productClasses = array(
  164.                     'Products' => 'SAP',
  165.                     'ProductITCStore' => 'ITC Store',
  166.                     'ProductAmazon' => 'Amazon',
  167.                     'ProductBigBasket' => 'Big Basket',
  168.                     'ProductBlinkit' => 'Blinkit',
  169.                     'ProductFlipkart' => 'Flipkart',
  170.                     'ProductJioMart' => 'JioMart',
  171.                     'ProductSwiggy' => 'Swiggy',
  172.                     'ProductZepto' => 'Zepto'
  173.                 );
  174.                 if (array_key_exists($objectData->getClassName(),$productClasses)) {
  175.                     $productId $objectData->getId();
  176.                     $dbConnection \Pimcore\Db::get();
  177.                     $workflowInfo $dbConnection->fetchRow("
  178.                         SELECT *
  179.                         FROM `element_workflow_state`
  180.                         WHERE `cid` = '$productId'
  181.                         LIMIT 1
  182.                     ");
  183.                     if(!empty($workflowInfo['place'])) {
  184.                         if($workflowInfo['place'] != 'sap_action') {
  185.                             $folder DataObject\Service::createFolderByPath('/Products/'.$productClasses[$objectData->getClassName()]);
  186.                             $folderId $folder->getId();
  187.                             $objectData->seto_parentId($folderId);
  188.                         }
  189.                     }
  190.                 }
  191.                 if($objectData->getClassName() == 'ProductFlipkart') {
  192.                     $manufacturing_address trim($objectData->getmanufacturing_address());
  193.                     $packer_details trim($objectData->getpacker_details());
  194.                     $errors = array();
  195.                     if(strlen($manufacturing_address) > 120) {
  196.                         $errors[] = '<b>Manufacturing address : </b> should be 120 characters only';
  197.                     }
  198.                     if(strlen($packer_details) > 120) {
  199.                         $errors[] = '<b>Packer details : </b> should be 120 characters only';
  200.                     }
  201.                     if(count($errors)) {
  202.                         $message implode('<br/> ',$errors);
  203.                         throw new \Pimcore\Model\Element\ValidationException($message);
  204.                     }
  205.                 }
  206.                 if($objectData->getClassName() == 'Products') {
  207.                     $objectId $objectData->getId();
  208.                     $division trim($objectData->getdivision());
  209.                     if (empty($objectData->getmrp_controller())) {
  210.                         $mrpcnt = array(
  211.                             'AT' => 'ATT',
  212.                             'BI' => 'BIS',
  213.                             'CF' => 'CON',
  214.                             'CH' => 'CHO',
  215.                             'DF' => 'DFS',
  216.                             'DM' => 'DMS',
  217.                             'DP' => 'DPS',
  218.                             'IC' => 'COF',
  219.                             'JU' => 'JUC',
  220.                             'ND' => 'NDL',
  221.                             'RG' => 'COF',
  222.                             'RI' => 'RIC',
  223.                             'RT' => 'RTE',
  224.                             'SA' => 'SAL',
  225.                             'SI' => 'SPI',
  226.                             'SN' => 'PAS',
  227.                             'SX' => 'SNX',
  228.                             'DB' => 'MFO',
  229.                             'BR' => 'ATT',
  230.                             'SS' => 'ATT',
  231.                             'OL' => 'ATT',
  232.                             'PA' => 'ATT',
  233.                             'MX' => 'ATT',
  234.                             'ZF' => 'FFD',
  235.                             'CP' => 'ATT',
  236.                             'PU' => 'ATT',
  237.                             'BC' => 'ATT',
  238.                             'YB' => 'BIS'
  239.                         );
  240.                         if (!empty($division)) {
  241.                             if (array_key_exists($division,$mrpcnt)) {
  242.                                 $objectData->setmrp_controller($mrpcnt[$division]);
  243.                             }
  244.                         }
  245.                     } else if (empty($objectData->getmaterial_type())) {
  246.                         $mt = array(
  247.                             'AT' => 'FFGD',
  248.                             'BI' => 'FFGD',
  249.                             'CF' => 'FFGD',
  250.                             'CH' => 'FFGD',
  251.                             'DF' => 'FDFG',
  252.                             'DM' => 'FDFG',
  253.                             'DP' => 'FDFG',
  254.                             'GU' => 'FFGD',
  255.                             'IC' => 'FFGD',
  256.                             'JU' => 'FFGD',
  257.                             'ND' => 'FFGD',
  258.                             'RG' => 'FFGD',
  259.                             'RI' => 'FFGD',
  260.                             'RT' => 'FFGD',
  261.                             'SA' => 'FFGD',
  262.                             'SI' => 'FFGD',
  263.                             'SN' => 'FFGD',
  264.                             'SX' => 'FFGD',
  265.                             'DB' => 'FFGD',
  266.                             'BR' => 'FFGD',
  267.                             'SS' => 'FFGD',
  268.                             'OL' => 'FFGD',
  269.                             'PA' => 'FFGD',
  270.                             'MX' => 'FFGD',
  271.                             'ZF' => 'FFGD',
  272.                             'CP' => 'FFGD',
  273.                             'PU' => 'FFGD',
  274.                             'BC' => 'FFGD',
  275.                             'YB' => 'FFGD'
  276.                         );
  277.                         if (!empty($division)) {
  278.                             if (array_key_exists($division,$mt)) {
  279.                                 $objectData->setmaterial_type($mt[$division]);
  280.                             }
  281.                         }
  282.                     } else if(empty($objectData->getuom())) {
  283.                         $uom = array(
  284.                             'AT' => 'KG',
  285.                             'BI' => 'KG',
  286.                             'CF' => 'KG',
  287.                             'CH' => 'EA',
  288.                             'DF' => 'KG',
  289.                             'DM' => 'L',
  290.                             'DP' => 'KG',
  291.                             'IC' => 'KG',
  292.                             'JU' => 'L',
  293.                             'ND' => 'KG',
  294.                             'RG' => 'EA',
  295.                             'RI' => 'KG',
  296.                             'RT' => 'EA',
  297.                             'SA' => 'KG',
  298.                             'SI' => 'KG',
  299.                             'SN' => 'KG',
  300.                             'SX' => 'KG',
  301.                             'DB' => 'L',
  302.                             'BR' => 'KG',
  303.                             'SS' => 'KG',
  304.                             'OL' => 'L',
  305.                             'PA' => 'KG',
  306.                             'MX' => 'KG',
  307.                             'ZF' => 'KG',
  308.                             'CP' => 'KG',
  309.                             'PU' => 'KG',
  310.                             'BC' => 'KG',
  311.                             'YB' => 'KG'
  312.                         );
  313.                         if (!empty($division)) {
  314.                             if (array_key_exists($division,$uom)) {
  315.                                 $objectData->setuom($uom[$division]);
  316.                             }
  317.                         }
  318.                     }
  319.                     $errors = array();
  320.                     // if(!$this->validateAlphanumeric($objectData->getsku())) {
  321.                     //     $errors[] = '<b>SKU : </b> Please enter valid sku code';
  322.                     // }
  323.                     // if(!$this->validateAlphabetsOnly($objectData->getname())) {
  324.                     //     $errors[] = '<b>Product name : </b> Please enter valid product name';
  325.                     // }
  326.                     // if(!empty($objectData->getprice())) {
  327.                     //     if (!preg_match('/^[0-9\s]+$/', $objectData->getprice())) {
  328.                     //         // The input contains only numeric characters and spaces
  329.                     //         $errors[] = '<b>Price : </b> Only numeric value is allowed';
  330.                     //     }
  331.                     // }
  332.                     if(!empty($objectData->getpack_weight()) && !empty($objectData->getno_packs())) {
  333.                         $objectData->setcfcweight($objectData->getpack_weight() * $objectData->getno_packs());
  334.                     }
  335.                     // if(!empty($objectData->getmaterial_number()) && !$this->validateAlphabetsOnly($objectData->getmaterial_number())) {
  336.                     //     $errors[] = '<b>SAP SKU Code : </b> Please enter valid SAP sku code (Alphanumeric)';
  337.                     // }
  338.                     if(!empty($objectData->gettax_category()) && !$this->validateAlphabetsOnly($objectData->gettax_category())) {
  339.                         $errors[] = '<b>Tax category : </b> Please enter valid tax category';
  340.                     }
  341.                     if(!empty($objectData->getbatch_management()) && !$this->validateAlphabetsOnly($objectData->getbatch_management())) {
  342.                         $errors[] = '<b>Batch management : </b> Please enter valid batch management';
  343.                     }
  344.                     // if(empty($objectData->getdivision())) {
  345.                     //     $errors[] = '<b>Division : </b> Please select a division';
  346.                     // }
  347.                     if(count($errors)) {
  348.                         $message implode('<br/> ',$errors);
  349.                         throw new \Pimcore\Model\Element\ValidationException($message);
  350.                     } else {
  351.                     }
  352.                 }
  353.             }
  354.         }
  355.     }
  356.     public function onPostUpdate(ElementEventInterface $e) {
  357.         if ($e instanceof DataObjectEvent) {
  358.             $objectData $e->getObject();
  359.             if($objectData->gettype() == 'object'){
  360.                 // if($objectData->getClassName() == 'ProductCategory') {
  361.                 //     // $categoryAddUrl = "https://integration-5ojmyuq-23txbi6folvo6.ap-3.magentosite.cloud/rest/V1/bridge/catalog/category/add";
  362.                 //     $categoryAddUrl = "http://local.itc.com/rest/V1/bridge/catalog/category/add";
  363.                 //     $data = array( 
  364.                 //         "category_id" => $objectData->getId(),
  365.                 //         "store_view_id" => "0"
  366.                 //     ); 
  367.                 //     $productSyncKey = "qzgg1vbpgwk6pjctbv6ku2a65906ocpb";
  368.                 //     // $productSyncKey = "ah2zed4d9rcqgxc4ds16bh6wssdm8xni";
  369.                 //     $data_json = json_encode(array("data" => $data)); 
  370.                 //     $curl = curl_init(); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); 
  371.                 //     curl_setopt($curl, CURLOPT_POSTFIELDS, $data_json); 
  372.                 //     curl_setopt($curl, CURLOPT_URL, $categoryAddUrl); 
  373.                 //     curl_setopt($curl, CURLOPT_HTTPHEADER, array( 'Authorization: Bearer ' . $productSyncKey, 'Accept: application/json', 'Content-Type:application/json', )); 
  374.                 //     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
  375.                 //     curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 
  376.                 //     $result = curl_exec($curl); 
  377.                 //     $resultArray = json_decode($result); 
  378.                 //     curl_close($curl);
  379.                 // }
  380.                 if($objectData->getClassName() == 'Products') {
  381.                     $productId $objectData->getId();
  382.                     $dbConnection \Pimcore\Db::get();
  383.                     $workflowInfo $dbConnection->fetchRow("
  384.                         SELECT *
  385.                         FROM `element_workflow_state`
  386.                         WHERE `cid` = '$productId'
  387.                         LIMIT 1
  388.                     ");
  389.                     if(!empty($workflowInfo['place']) && $workflowInfo['place'] == 'approved') {
  390.                         // $productSyncKey = "enlwq7pkg6t2od9blt93coomo7g6p9p0"; // Live Integration
  391.                         $productSyncKey "qzgg1vbpgwk6pjctbv6ku2a65906ocpb"// Local
  392.                         // $productUpdatedUrl = 'https://integration-5ojmyuq-23txbi6folvo6.ap-3.magentosite.cloud/rest/V1/bridge/catalog/product/add';
  393.                         $productUpdatedUrl 'http://local.itc.com/rest/V1/bridge/catalog/product/add';
  394.                         // echo $productUpdatedUrl.'<br>';
  395.                         // echo $productSyncKey;
  396.                         $data = array( "product_id" => $productId,"store_view_id" => "0", );
  397.                         $data_json json_encode(array("data" => $data));
  398.                         $curl curl_init();
  399.                         curl_setopt($curlCURLOPT_CUSTOMREQUEST"PUT");
  400.                         curl_setopt($curlCURLOPT_POSTFIELDS$data_json);
  401.                         curl_setopt($curlCURLOPT_URL$productUpdatedUrl);
  402.                         curl_setopt($curlCURLOPT_HTTPHEADER, array( 'Authorization: Bearer ' $productSyncKey'Accept: application/json''Content-Type:application/json', ));
  403.                         curl_setopt($curlCURLOPT_RETURNTRANSFER1);
  404.                         curl_setopt($curlCURLOPT_HTTPAUTHCURLAUTH_BASIC);
  405.                         $result curl_exec($curl);
  406.                         $resultArray json_decode($result);
  407.                         curl_close($curl);
  408.                         // echo '<pre>'; print_r($resultArray); exit;
  409.                     }
  410.                 } else if($objectData->getClassName() == 'ProductByName') {
  411.                     $dbConnection \Pimcore\Db::get();
  412.                     $objectId $objectData->getid();
  413.                     $wfInfo $dbConnection->fetchAssociative("
  414.                         SELECT * FROM `element_workflow_state`
  415.                         WHERE cid = '$objectId'
  416.                     ");
  417.                     $wfplace $wfInfo['place'];
  418.                     $products $objectData->getproducts();
  419.                     foreach ($products as $key => $value) {
  420.                         $productId $value->getId();
  421.                         $dbConnection->query("
  422.                             UPDATE `element_workflow_state` 
  423.                             SET `place` = '$wfplace'
  424.                             WHERE `cid` = '$productId'
  425.                         ");
  426.                     }
  427.                 }
  428.             } else if($objectData->gettype() == 'folder'){
  429.             }
  430.         }
  431.     }
  432.     public function onAssetPostAdd(\Pimcore\Event\Model\AssetEvent $event) {
  433.         $data false;
  434.         if($event instanceof AssetEvent) {
  435.             $data $event->getAsset(); 
  436.         } else if ($event instanceof DocumentEvent) {
  437.             $data $event->getDocument(); 
  438.         } else if ($event instanceof DataObjectEvent) {
  439.             $data $event->getObject(); 
  440.         }
  441.         if ($data) {
  442.             $id $data->getId();
  443.             // $productSyncKey = "enlwq7pkg6t2od9blt93coomo7g6p9p0"; // Live Integration
  444.             $productSyncKey "qzgg1vbpgwk6pjctbv6ku2a65906ocpb"// Local
  445.             // $productUpdatedUrl = 'https://integration-5ojmyuq-23txbi6folvo6.ap-3.magentosite.cloud/rest/V1/bridge/catalog/product/add';
  446.             $productUpdatedUrl 'http://local.itc.com/rest/V1/bridge/asset/add';
  447.             // echo $productUpdatedUrl.'<br>';
  448.             // echo $productSyncKey;
  449.             $data = array( "asset_id" => $id,"store_view_id" => "0", );
  450.             $data_json json_encode(array("data" => $data));
  451.             $curl curl_init();
  452.             curl_setopt($curlCURLOPT_CUSTOMREQUEST"PUT");
  453.             curl_setopt($curlCURLOPT_POSTFIELDS$data_json);
  454.             curl_setopt($curlCURLOPT_URL$productUpdatedUrl);
  455.             curl_setopt($curlCURLOPT_HTTPHEADER, array( 'Authorization: Bearer ' $productSyncKey'Accept: application/json''Content-Type:application/json', ));
  456.             curl_setopt($curlCURLOPT_RETURNTRANSFER1);
  457.             curl_setopt($curlCURLOPT_HTTPAUTHCURLAUTH_BASIC);
  458.             $result curl_exec($curl);
  459.             $resultArray json_decode($result);
  460.             curl_close($curl);
  461.         }
  462.     }
  463.     public function onPreDelete(ElementEventInterface $e) {
  464.         if ($e instanceof DataObjectEvent) {
  465.             $objectData $e->getObject();
  466.             if($objectData->gettype() == 'object'){
  467.                 if($objectData->getClassName() == 'ItcAddFaq') {
  468.                     $faqId $objectData->getfaqId();
  469.                     $faqQuestion $objectData->getfaqQuestion();
  470.                     $faqAnswer $objectData->getfaqAnswer();
  471.                     $location_code $objectData->getlocation_code();
  472.                     $faqType $objectData->getfaqType();
  473.                     $faqDir DoService::createFolderByPath('/FAQ/');
  474.                     $faqDirId $faqDir->getId();
  475.                     $faqObj = new DataObject\ItcAddFaq();
  476.                     $faqObj->setKey(\Pimcore\Model\Element\Service::getValidKey('FAQ_'.$faqId.'_'.rand(1,9), 'object'));
  477.                     $faqObj->setParentId($faqDirId);
  478.                     $faqObj->setfaqId($faqId);
  479.                     $faqObj->setfaqQuestion($faqQuestion);
  480.                     $faqObj->setfaqAnswer($faqAnswer);
  481.                     $faqObj->setlocation_code($location_code);
  482.                     $faqObj->setfaqType($faqType);
  483.                     $faqObj->setPublished(true);
  484.                     $faqObj->save();
  485.                 }
  486.             }
  487.         }
  488.     }
  489. }