/**
  * @Route("/order/getcategories")
  */
 function getcategories(Request $request)
 {
     /*
      $url = $this->getSetting("AppBundle:Entity:tecdocServiceUrl");
      $fields = array(
      'action' => 'getcarcategories',
      'linkingTargetId' => $request->request->get("car")
      );
      $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);
      $data = curl_exec($ch);
      $data = unserialize($data);
     */
     $em = $this->getDoctrine()->getManager();
     $tecdoc = new Tecdoc();
     $params["linkingTargetId"] = $request->request->get("car");
     $data = $tecdoc->linkedChildNodesAllLinkingTargetTree($params);
     $articleIds = array();
     foreach ($data as $key => $dt) {
         foreach ((array) $dt->articleIds as $articleId) {
             $articleIds[] = $articleId;
         }
     }
     $tecdocArticleIds = array();
     if (count($articleIds)) {
         $query = $em->createQuery("SELECT  p.tecdocArticleId\r\n                        FROM 'SoftoneBundle:Product' p\r\n                        where p.tecdocArticleId in (" . implode(",", $articleIds) . ")");
         /*
         echo "SELECT  p.tecdocArticleId
                     FROM 'SoftoneBundle:Product' p
                     where p.tecdocArticleId in (" . implode(",", $articleIds) . ")";
         */
         $products = $query->getResult();
         //print_r($products);
         foreach ($products as $product) {
             $tecdocArticleIds[] = $product["tecdocArticleId"];
         }
     }
     //print_r($tecdocArticleIds);
     $tecdocEdiArticleIds = array();
     if (count($articleIds)) {
         $query = $em->createQuery("SELECT  p.tecdocArticleId\r\n                        FROM 'EdiBundle:EdiItem' p, EdiBundle:Edi e\r\n                        where \r\n                            e.id = p.Edi AND p.tecdocArticleId in (" . implode(",", $articleIds) . ")");
         $products = $query->getResult();
         foreach ($products as $product) {
             $tecdocEdiArticleIds[] = $product["tecdocArticleId"];
         }
     }
     foreach ($data as $key => $dt) {
         $matched = array_intersect(@(array) $dt->articleIds, $tecdocArticleIds);
         $edimatched = array_intersect(@(array) $dt->articleIds, $tecdocEdiArticleIds);
         $dt->matched = array();
         $dt->matched = base64_encode(serialize($matched));
         $dt->matched_count = count($matched);
         $dt->edimatched = array();
         $dt->edimatched = base64_encode(serialize($edimatched));
         $dt->edimatched_count = count($edimatched);
         $all["matched"] = (array) $matched;
         $all["edimatched"] = (array) $edimatched;
         $all["articleIds"] = @(array) $dt->articleIds;
         $dt->all = base64_encode(serialize($all));
         //$data[$key] = $dt;
     }
     $json = json_encode($data);
     //$data = unserialize($data);
     return new Response($json, 200, array('Content-Type' => 'application/json'));
 }
Example #2
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;
 }
 public function getArticlesSearch($search)
 {
     // if (file_exists(Yii::app()->params['root'] . "cache/terms/" . md5($search) . ".term")) {
     //    $data = file_get_contents(Yii::app()->params['root'] . "cache/terms/" . md5($search) . ".term");
     //   return $data;
     //} else {
     //ADBRP002
     /*
      $url = $this->getSetting("AppBundle:Entity:tecdocServiceUrl");
      $fields = array(
      'action' => 'getSearch',
      'search' => $search
      );
      $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);
      $data = curl_exec($ch);
      return $data;
     */
     //}
     $tecdoc = new Tecdoc();
     $articles = $tecdoc->getArticlesSearch(array('search' => $this->clearstring($search)));
     //print_r($articles);
     //echo $search;
     foreach ($articles->data->array as $v) {
         $articleIds[] = $v->articleId;
     }
     return serialize($articleIds);
 }
 public function getArticlesSearchByIds($search)
 {
     //if (file_exists(Yii::app()->params['root'] . "cache/terms/" . md5($search) . ".term")) {
     //$data = file_get_contents(Yii::app()->params['root'] . "cache/terms/" . md5($search) . ".term");
     //return $data;
     //} else {
     /*
     $url = $this->getSetting("AppBundle:Entity:tecdocServiceUrl");
     $fields = array(
         'action' => 'getSearchByIds',
         'search' => $search
     );
     $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);
     $data = curl_exec($ch);
     */
     //file_put_contents(Yii::app()->params['root'] . "cache/terms/" . md5($search) . ".term", $data);
     $params = array('search' => $search);
     $tecdoc = new Tecdoc();
     $data = $tecdoc->getArticlesSearchByIds($params);
     return $data->data->array;
     //return $data;
     //}
 }