Example #1
0
 function updatetecdoc()
 {
     //$data = array("service" => "login", 'username' => 'dev', 'password' => 'dev', 'appId' => '2000');
     if ($this->getTecdocSupplierId() == null) {
         return;
     }
     global $kernel;
     if ('AppCache' == get_class($kernel)) {
         $kernel = $kernel->getKernel();
     }
     $em = $kernel->getContainer()->get('doctrine.orm.entity_manager');
     //$data_string = json_encode($data);
     $url = $this->getSetting("AppBundle:Entity:tecdocServiceUrl");
     if ($_SERVER["DOCUMENT_ROOT"] == 'C:\\symfony\\alexander\\webb') {
         $fields = array('action' => 'updateTecdoc', 'tecdoc_code' => $this->tecdocCode, 'tecdoc_supplier_id' => $this->getTecdocSupplierId()->getId());
         $fields_string = '';
         foreach ($fields as $key => $value) {
             @($fields_string .= $key . '=' . $value . '&');
         }
         rtrim($fields_string, '&');
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_POST, count($fields));
         curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
         $out = json_decode(curl_exec($ch));
         // print_r($fields);
         //echo $out;
         //echo 'sssssssssss';
     } else {
         $postparams = array("articleNumber" => $this->tecdocCode, "brandno" => $this->getTecdocSupplierId()->getId());
         $tecdoc = new Tecdoc();
         $articleDirectSearchAllNumbers = $tecdoc->getArticleDirectSearchAllNumbers($postparams);
         $tectdoccode = $this->tecdocCode;
         if (count($articleDirectSearchAllNumbers->data->array) == 0) {
             $articleId = $tecdoc->getCorrectArtcleNr($tectdoccode, $postparams["brandno"]);
             if ($article != $tectdoccode) {
                 $params = array("articleNumber" => $articleId, "brandno" => $postparams["brandno"]);
                 $articleDirectSearchAllNumbers = $tecdoc->getArticleDirectSearchAllNumbers($params);
             }
         }
         if (count($articleDirectSearchAllNumbers->data->array) == 0) {
             $articleId = $tecdoc->getCorrectArtcleNr2(strtolower($tectdoccode), $postparams["brandno"]);
             if ($article != strtolower($tectdoccode)) {
                 $params = array("articleNumber" => $articleId, "brandno" => $postparams["brandno"]);
                 $articleDirectSearchAllNumbers = $tecdoc->getArticleDirectSearchAllNumbers($params);
             }
         }
         $out = $articleDirectSearchAllNumbers->data->array[0];
     }
     //print_r($out);
     try {
         //$webserviceProduct = WebserviceProduct::model()->findByAttributes(array('product' =>  $this->id,"webservice"=>$this->webservice));
         //$sql = "Delete from SoftoneBundle:WebserviceProduct p where p.product = '" . $this->id . "'";
         //$em->createQuery($sql)->getResult();
         //$em->execute();
         if (@$out->articleId) {
             $this->setTecdocArticleId($out->articleId);
             $this->setTecdocArticleName($out->articleName);
             //$this->setTecdocGenericArticleId($out->articleName);
             $em->persist($this);
             $em->flush();
         }
     } catch (Exception $e) {
         echo $e->getMessage();
         exit;
     }
     //echo $result;
 }