hib

account_connection = "https://".$account.".hiboutik.com/apirest";
$this->user_connection = $user;
$this->key_connection = $key;
$this->debug = false;
parent::__construct();
$user_agent = "HiboutikAPI v".self::VERSION_API." (+https://github.com/hiboutik/hiboutikapi)";
$user_agent .= " PHP/" . PHP_VERSION;
$curl_version = curl_version();
$user_agent .= ' curl/' . $curl_version['version'];
$this->setUserAgent($user_agent);
$this->setBasicAuthentication($user, $key);
} catch(\Exception $e) {
trigger_error($e->getMessage(), E_USER_ERROR);
}
}
public function debug($debug = false)
{
if($debug === true) {
$this->debug = true;
}
return $this;
}
public function getHiboutik($rest_resource = "")
{
try {
$this->setHeader('Content-Type', 'application/json');
$this->get($this->account_connection."/".$rest_resource."");
if ($this->error) {
throw new \Exception("CURL error: ".$this->errorCode." : ".$this->errorMessage);
} else {
return $this->response;
}
} catch(\Exception $e) {
if($this->debug === true) {
trigger_error($e->getMessage(), E_USER_ERROR);
}
}
}
public function postHiboutik($rest_resource = "", $data = "")
{
try {
if(empty($data)) {
throw new \Exception("HiboutikAPI: post data is empty");
}
$this->setHeader('Content-Type', 'application/json');
$this->post($this->account_connection."/".$rest_resource."", json_encode($data));
if ($this->error) {
throw new \Exception("CURL error: ".$this->errorCode." : ".$this->errorMessage);
} else {
return $this->response;
}
} catch(\Exception $e) {
if($this->debug === true) {
trigger_error($e->getMessage(), E_USER_ERROR);
}
}
}
public function putHiboutik($rest_resource = "", $data = "")
{
try {
if(empty($data)) {
throw new \Exception("HiboutikAPI: put data is empty");
}
$this->setHeader('Content-Type', 'application/json');
$this->put($this->account_connection."/".$rest_resource."", json_encode($data));
if ($this->error) {
throw new \Exception("CURL error: ".$this->errorCode." : ".$this->errorMessage);
} else {
return $this->response;
}
} catch(\Exception $e) {
if($this->debug === true) {
trigger_error($e->getMessage(), E_USER_ERROR);
}
}
}
public function deleteHiboutik($rest_resource = "", $id)
{
try {
if(empty($id)) {
throw new \Exception("HiboutikAPI: deleteHiboutik() method needs an id to delete");
}
if($rest_resource === "") {
throw new \Exception("HiboutikAPI: deleteHiboutik() method -> No resource specified.");
}
$this->setHeader('Content-Type', 'application/json');
$this->delete($this->account_connection."/".$rest_resource."/".$id);
if ($this->error) {
throw new \Exception("CURL error: ".$this->errorCode." : ".$this->errorMessage);
} else {
return $this->response;
}
} catch(\Exception $e) {
if($this->debug === true) {
trigger_error($e->getMessage(), E_USER_ERROR);
}
}
}
}

{
"name": "hiboutik/hiboutikapi",
"type": "library",
"description": "Hiboutik API REST",
"keywords": ["Hiboutik"],
"homepage": "http://www.hiboutik.com/",
"license": "GPLv3",
"authors": [
{
"name": "Hiboutik",
"email": "contact@hiboutik.com",
"homepage": "http://www.hiboutik.com/"
}
],
"require": {
"php": ">=5.3",
"php-curl-class/php-curl-class": "*"
},
"autoload": {
"psr-4": {
"Hiboutik\\": "lib/Hiboutik/"
}
}
}

?>

set_charset("utf8");

$table_product_attribute = $mysql_db_prefix . "product_attribute";
$table_product = $mysql_db_prefix . "product";
$table_stock_available = $mysql_db_prefix . "stock_available";

/*
####################################################################################################
//Connexion à l'API Hiboutik
####################################################################################################
*/
$url = "https://$account.hiboutik.com/apirest";
$ma_date = date("Y-m-d H:i:s");
$maintenant = time();
$ma_date_jour = date("Ymd", $maintenant);
$url_account = preg_replace('/apirest/', '', $url);

$hiboutik = new \Hiboutik\HiboutikAPI($account, $user, $key);

//récupération du stock disponible sur la warehouse 1
$products = $hiboutik->getHiboutik("stock_available/warehouse_id/1");
if ($hiboutik->error)
{
echo 'Error: ' . $hiboutik->errorCode . ': ' . $hiboutik->errorMessage . ' & ' . $hiboutik->response; exit;
}
else
{
foreach ($products as $key => $value) {
$id_prod_sa = $value -> product_id;
$id_prod_taille_sa = $value -> product_size;
$stock_dispo[$id_prod_sa][$id_prod_taille_sa] = $value -> stock_available;
}

$products = $hiboutik->getHiboutik("products");
foreach ($products as $key => $value) {
$my_product_id = $value -> product_id;
$my_product_name[$my_product_id] = $value -> product_model;
$my_product_category[$my_product_id] = $value -> product_category;
$my_product_size_type[$my_product_id] = $value -> product_size_type;
$my_product_product_stock_management[$my_product_id] = $value -> product_stock_management;
}

if ($en_verbose == "1")
{
print("




Hiboutik - $account




");
}

/*
####################################################################################################
//Traitement des produits sans déclinaisons
####################################################################################################
*/
if ($en_verbose == "1")
{
print("

Traitement des produits sans déclinaisons

");
}

$sql_produits_prestashop = "SELECT * FROM $table_product WHERE reference <> '';";
$result_produits_prestashop = mysqli_query ($mysqli, "$sql_produits_prestashop");
$nombreligne_produits_prestashop = $result_produits_prestashop->num_rows;
while ($row = $result_produits_prestashop->fetch_array(MYSQLI_BOTH))
{
$reference = $row["reference"];
$id_product = $row["id_product"];

$qtity = $stock_dispo[$reference]["0"];
$my_class_color = "";
if (is_numeric($qtity))
{
$ma_requete_modif_produit = "UPDATE $table_stock_available SET quantity = '$qtity' WHERE id_product = '$id_product';";
$mysql_query_modif_account = mysqli_query ($mysqli, "$ma_requete_modif_produit");
if ($en_verbose == "1")
{
print("

");
}
}
else
{
$my_class_color = " style=\"background-color: red;\"";
if ($en_verbose == "1")
{
print("

$id_product $reference ? 0 KO

");
}
}

}
$result_produits_prestashop->free();

if ($en_verbose == "1")
{
print("

id Prestashop ref. Prestashop id Hiboutik Stock Etat
$id_product $reference



$qtity OK

");
}

/*
####################################################################################################
//Traitement des produits avec déclinaisons
####################################################################################################
*/
if ($en_verbose == "1")
{
print("

Traitement des produits avec déclinaisons

");
}

$sql_produits_prestashop = "SELECT * FROM $table_product_attribute WHERE reference <> '';";
$result_produits_prestashop = mysqli_query ($mysqli, "$sql_produits_prestashop");
$nombreligne_produits_prestashop = $result_produits_prestashop->num_rows;
while ($row = $result_produits_prestashop->fetch_array(MYSQLI_BOTH))
{
$reference = $row["reference"];
$id_product = $row["id_product"];
$id_product_attribute = $row["id_product_attribute"];

$my_class_color = "";
if (preg_match('/|/', $reference))
{
$reference_presta = explode("|", $reference);
$id_prod_hibou = $reference_presta[0];
$id_taille_hibou = $reference_presta[1];

$qtity = $stock_dispo[$id_prod_hibou][$id_taille_hibou];
if (is_numeric($qtity))
{
$ma_requete_modif_produit = "UPDATE $table_stock_available SET quantity = '$qtity' WHERE id_product_attribute = '$id_product_attribute' AND id_product = '$id_product';";
$mysql_query_modif_account = mysqli_query ($mysqli, "$ma_requete_modif_produit");
if ($en_verbose == "1")
{
print("

");
}
}
}
else
{
$my_class_color = " style=\"background-color: red;\"";
if ($en_verbose == "1")
{
print("

$id_product $reference ? ? 0 KO

");
}
}

}
$result_produits_prestashop->free();

if ($en_verbose == "1")
{

print("

id Prestashop ref. Prestashop id Hiboutik Taille Hiboutik Stock Etat
$id_product $reference



$qtity $id_taille_hibou OK

");

print("



");
}
}

?>

vos mèches en vie