<?php
// Presupunând că ai ID-ul adresei de facturare
$billingAddressId = '{order_billing_address_id}';
// Conexiunea la baza de date Joomla
$db = JFactory::getDbo();
// Construim prima interogare pentru a obține detalii despre adresă
$query = $db->getQuery(true);
$query->select($db->quoteName(array('address_company', 'address_vat', 'address_firstname', 'address_lastname', 'address_street', 'address_state', 'address_country')));
$query->from($db->quoteName('db_name_hikashop_address'));
$query->where($db->quoteName('address_id') . ' = ' . $db->quote($billingAddressId));
// Executăm prima interogare
$db->setQuery($query);
$addressResult = $db->loadAssoc();
if ($addressResult) {
// Extragem codul de stat și codul țării
$stateCode = substr($addressResult['address_state'], strrpos($addressResult['address_state'], '_') + 1);
$countryCode = substr($addressResult['address_country'], strrpos($addressResult['address_country'], '_') + 1);
// Interogare pentru numele zonei
$query = $db->getQuery(true);
$query->select($db->quoteName('zone_name'));
$query->from($db->quoteName('db_name_hikashop_zone'));
$query->where($db->quoteName('zone_id') . ' = ' . $db->quote($stateCode));
$db->setQuery($query);
$zoneName = $db->loadResult();
// Interogare pentru numele țării
$query = $db->getQuery(true);
$query->select($db->quoteName('zone_name'));
$query->from($db->quoteName('db_name_hikashop_zone'));
$query->where($db->quoteName('zone_id') . ' = ' . $db->quote($countryCode));
$db->setQuery($query);
$countryName = $db->loadResult();
// Pregătim datele pentru API-ul SmartBill
$smartBillData = [
"data" => date("Y-m-d"),
"client" => [
"nume" => $addressResult['address_firstname'] . " " . $addressResult['address_lastname'],
"cif" => "48956989",
"regCom" => "",
"adresa" => $addressResult['address_street'] . ", " . ($zoneName ? $zoneName : 'Unknown') . ", " . ($countryName ? $countryName : 'Unknown'),
// Alte detalii despre client
],
// Produsele sau serviciile facturate
// ...
];
// URL-ul API-ului SmartBill
$url = 'https://api.invoice-web-app-ro';
// Inițializăm sesiunea cURL
$ch = curl_init($url);
// Setăm opțiunile cURL necesare
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($smartBillData));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Authorization: Basic ' . base64_encode("mail:tokenkey")
]);
// Executăm cererea cURL
$response = curl_exec($ch);
$curlError = curl_error($ch);
// Închidem sesiunea cURL
curl_close($ch);
// Afișăm răspunsul sau eroarea în consola JavaScript
echo "<script type='text/javascript'>";
if ($curlError) {
echo "console.error('Eroare cURL: " . json_encode($curlError) . "');";
} else {
echo "console.log('Răspuns SmartBill: " . json_encode($response) . "');";
}
echo "</script>";
} else {
echo "<script>console.log('No address or zone result found');</script>";
}
?>
I tested the version of the php code that brings certain information to the console to do tests and it works perfectly.
// Presupunând că ai ID-ul adresei de facturare
$billingAddressId = '{order_billing_address_id}'; // Înlocuiește cu eticheta corectă
// Conexiunea la baza de date Joomla
$db = JFactory::getDbo();
// Construim prima interogare pentru a obține detalii despre adresă
$query = $db->getQuery(true);
$query->select($db->quoteName(array('address_company', 'address_vat', 'address_firstname', 'address_lastname', 'address_street', 'address_state', 'address_country')));
$query->from($db->quoteName('db_name_hikashop_address'));
$query->where($db->quoteName('address_id') . ' = ' . $db->quote($billingAddressId));
// Executăm prima interogare
$db->setQuery($query);
$addressResult = $db->loadAssoc();
if ($addressResult) {
// Extragem codul de stat și codul țării
$stateCode = substr($addressResult['address_state'], strrpos($addressResult['address_state'], '_') + 1);
$countryCode = substr($addressResult['address_country'], strrpos($addressResult['address_country'], '_') + 1);
// Interogare pentru numele zonei
$query = $db->getQuery(true);
$query->select($db->quoteName('zone_name'));
$query->from($db->quoteName('db_name_hikashop_zone'));
$query->where($db->quoteName('zone_id') . ' = ' . $db->quote($stateCode));
$db->setQuery($query);
$zoneName = $db->loadResult();
// Interogare pentru numele țării
$query = $db->getQuery(true);
$query->select($db->quoteName('zone_name'));
$query->from($db->quoteName('db_name_hikashop_zone'));
$query->where($db->quoteName('zone_id') . ' = ' . $db->quote($countryCode));
$db->setQuery($query);
$countryName = $db->loadResult();
// Pregătim informațiile pentru afișare
$company = addslashes($addressResult['address_company']);
$vat = addslashes($addressResult['address_vat']);
$firstname = addslashes($addressResult['address_firstname']);
$lastname = addslashes($addressResult['address_lastname']);
$street = addslashes($addressResult['address_street']);
$state = $zoneName ? addslashes($zoneName) : 'Unknown';
$country = $countryName ? addslashes($countryName) : 'Unknown';
// Afișăm informațiile în consola JavaScript
echo "<script>console.log('Address Company: $company, VAT: $vat, First Name: $firstname, Last Name: $lastname, Street: $street, State: $state, Country: $country');</script>";
} else {
echo "<script>console.log('No address result found');</script>";
}
I tested php code with cURL for simplified test but I get the same error
<?php
$url = "https://bcc-heritage.com/component/hikashop/product/1523-albania-p-41s2-1976-3-leke";
// Inițializarea sesiunii cURL
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
// Execută cererea cURL
$response = curl_exec($curl);
curl_close($curl);
// Verifică dacă cererea a reușit
if ($response) {
// Caută titlul în răspunsul HTML
if (preg_match('/<title>(.*?)<\/title>/', $response, $matches)) {
$title = $matches[1];
echo "Titlul paginii este: " . $title;
} else {
echo "Nu s-a putut găsi titlul în HTML.";
}
} else {
echo "Cererea cURL a eșuat.";
}
?>
At this moment I don't know what I should try to be able to send the code to the invoicing system API.
Please help me understand where I am wrong or what I should do.