Jump to content

Arda ALTAY

Members
  • Posts

    1
  • Joined

  • Last visited

Arda ALTAY's Achievements

  1. The getPresenter method in the service_changes module always returns an empty JSON. This is because the object “Blesta\Core\Pricing\Presenter\Type\ServiceChangePresenter” is returned and this object cannot be JSON serialized But if I use the php extension instead, I can get a result Since I was trying to get data from a laravel application, I parsed it with the code below as a temporary and quick solution. As I said before, if anyone has a better solution or refactor the code below better and share it, I would appreciate it. Maybe I can do a module and api. But for the moment I needed a quick solution. Maybe someone who made and used it might want to share it. class UnserializeHandler { public static function unserializeData($serializedData) { $pattern = '/O:\d+:"[^"]+"/'; // Tüm sınıf referanslarını stdClass'a çevir $convertedData = preg_replace($pattern, 'O:8:"stdClass"', $serializedData); return unserialize($convertedData); } } private function getPresenterLocal(){ $result = []; $result['kdvOran'] = 0; $result['kdvDescription'] = ''; $result['price'] = 0; $result['qty'] = 0; $result['description'] = ''; $result['total'] = 0; $result['totalWithTax'] = 0; $result['error'] = ''; $result['sonuc'] = true; try { $response = Http::withBasicAuth('username', 'password') ->withoutVerifying() // SSL sertifika doğrulamasını devre dışı bırakır ->get('https://blesta.test/api/service_changes/getpresenter.php', [ 'service_id' => 51, 'vars' => [ 'pricing_id' => 16, 'qty' => 1 ] ]); // Serialize edilmiş veriyi al $serializedData = $response->body(); // Özel handler ile unserialize yap $data = UnserializeHandler::unserializeData(serializedData: $serializedData); $collectionArray = (array)$data['response']; if(array_key_exists('0',$collectionArray) && $collectionArray[0] == false){ $result['sonuc'] = false; dd($result); //return $result; } $reflection = new \ReflectionObject($data['response']); $key = $reflection->getProperties()[0]; $responseData = $collectionArray[$key->name]; $reflection = new \ReflectionObject($responseData); $key = $reflection->getProperties()[0]; $metaItem = ((array)$responseData)[$key->name]; $priceItem = $metaItem[0]; foreach((array)$priceItem as $key => $value){ if(is_array($value) && str_contains($key, 'taxes')){ foreach($value as $k => $v){ if(is_array($v)){ $taxArray = (array)$v[0]; foreach($taxArray as $kk => $vv){ if(str_contains($kk, 'amount')){ $result['kdvOran'] = $vv; } if(str_contains($kk, 'description')){ $result['kdvDescription'] = $vv; } } } } } else{ if(gettype($key) == 'string' && str_contains($key, 'price')){ $result['price'] = $value; } if(gettype($key) == 'string' && str_contains($key, 'qty')){ $result['qty'] = $value; } if(gettype($key) == 'string' && str_contains($key, 'description')){ $result['description'] = $value; } } } if($result['price'] > 0 && $result['qty'] > 0){ $result['total'] = $result['price'] * $result['qty']; $result['totalWithTax'] = $result['total'] + ($result['total'] * $result['kdvOran'] / 100); } } catch (\Throwable $th) { //throw $th; $result['error'] = $th->getMessage(); } dd($result); }
×
×
  • Create New...