Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
- Correction bug
Browse files Browse the repository at this point in the history
- Ajout du choix de la version de l'API dans le parametrage
  • Loading branch information
kkhelifa-opendsi committed Mar 29, 2023
1 parent 660fce8 commit 7e4d8ff
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 7 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# ChangeLog

## 4.1.45.0
- Correction bug
- Ajout du choix de la version de l'API dans le parametrage

## 4.1.44.0
- Correction de l'enregistrement du parametrage de correspondance entre les attributs et les champs complémentaires
- Suppression de l'option pour forcé la synchronisation du stock à 0 si le stock synchronisé est négatif (elle est active en permanance)
Expand Down
15 changes: 15 additions & 0 deletions admin/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@

$object->type = 2; // WooCommerce
$object->name = GETPOST('site_name', 'alphanohtml');
$object->api_version = GETPOST('site_api_version', 'alphanohtml');
$object->webservice_address = GETPOST('site_webservice_address', 'alphanohtml');
$object->authentication_type = GETPOST('site_authentication_type', 'az09');
$object->user_name = GETPOST('site_user_name', 'alphanohtml');
Expand Down Expand Up @@ -346,6 +347,20 @@
print '<input type="text" class="flat centpercent" name="site_webservice_address" value="' . dol_escape_htmltag($object->webservice_address) . '">' . "\n";
print '</td></tr>' . "\n";

// Site API version
print '<tr class="oddeven">' . "\n";
print '<td class="fieldrequired">'.$langs->trans("ECommerceApiVersion").'</td>'."\n";
print '<td>' . $langs->transnoentities("ECommerceApiVersionDescription") . '</td>' . "\n";
print '<td class="right">' . "\n";
$api_versions = array(
'v1' => 'V1',
'v2' => 'V2',
'v3' => 'V3',
);
if (!in_array($object->api_version, array_keys($api_versions))) $object->api_version = 'v3';
print $form->selectarray('site_api_version', $api_versions, $object->api_version, 0, 0, 0, '', 1, 0, 0, '', 'minwidth200 centpercent') . "\n";
print '</td></tr>' . "\n";

// Site API authentication type
print '<tr class="oddeven">' . "\n";
print '<td class="fieldrequired">'.$langs->trans("ECommerceAuthenticationType").'</td>'."\n";
Expand Down
3 changes: 3 additions & 0 deletions class/client/eCommerceClientApi.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ public function sendToApi($method, $url, $options = [], $without_prefix = false,
} else {
if (isset($response)) {
$boby = strip_tags($response->getBody());
$boby = preg_replace_callback('/\\\\u([0-9a-fA-F]{4})/', function ($match) {
return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE');
}, $boby);
$this->errors[] = '<b>' . $langs->trans('ECommerceResponseCode') . ': </b>' . $response->getStatusCode() . '<br>' .
'<b>' . $langs->trans('ECommerceResponseReasonPhrase') . ': </b>' . $response->getReasonPhrase() .
(!empty($boby) ? '<br><em>' . $boby . '</em>' : '');
Expand Down
16 changes: 11 additions & 5 deletions class/client/eCommerceClientWooCommerceApi.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
*/
class eCommerceClientWooCommerceApi extends eCommerceClientApi
{
/**
* @var string API version
*/
public $api_version;
/**
* @var string Authentication type
*/
Expand All @@ -57,14 +61,15 @@ public function connection($site)
dol_syslog(__METHOD__ . " - authentication_type={$site->authentication_type}, user_name={$site->user_name}, user_password={$site->user_password}, timeout={$site->timeout}", LOG_DEBUG);
$this->errors = array();

$this->api_url = rtrim($site->webservice_address, '/');
$this->api_url_prefix = '/wp-json/wc/v3';

$this->authentication_type = $site->authentication_type;
$this->api_version = !empty($site->api_version) ? $site->api_version : 'v3';
$this->authentication_type = !empty($site->authentication_type) ? $site->authentication_type : 'oauth1_header';
$this->authentication_login = $site->user_name;
$this->authentication_password = $site->user_password;
$timeout = $site->timeout > 0 ? $site->timeout : 30;

$this->api_url = rtrim($site->webservice_address, '/');
$this->api_url_prefix = '/wp-json/wc/' . $this->api_version;

try {
$options = [
// Base URI is used with relative requests
Expand All @@ -81,7 +86,8 @@ public function connection($site)
'consumer_key' => $this->authentication_login,
'consumer_secret' => $this->authentication_password,
'request_method' => $this->authentication_type == 'oauth1_header' ? Oauth1::REQUEST_METHOD_HEADER : Oauth1::REQUEST_METHOD_QUERY,
'signature_method' => Oauth1::SIGNATURE_METHOD_HMACSHA256
'signature_method' => Oauth1::SIGNATURE_METHOD_HMACSHA256,
'api_version' => $this->api_version,
]);
$stack->push($middleware);

Expand Down
10 changes: 10 additions & 0 deletions class/data/eCommerceSite.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class eCommerceSite // extends CommonObject
public $name;
public $type;
public $webservice_address;
public $api_version;
public $authentication_type;
public $user_name;
public $user_password;
Expand Down Expand Up @@ -144,6 +145,7 @@ function create($user, $notrigger=0)
if (isset($this->name)) $this->name=trim($this->name);
if (isset($this->type)) $this->type=trim($this->type);
if (isset($this->webservice_address)) $this->webservice_address=trim($this->webservice_address);
if (isset($this->api_version)) $this->api_version=trim($this->api_version);
if (isset($this->authentication_type)) $this->authentication_type=trim($this->authentication_type);
if (isset($this->user_name)) $this->user_name=trim($this->user_name);
if (isset($this->user_password)) $this->user_password=trim($this->user_password);
Expand All @@ -170,6 +172,7 @@ function create($user, $notrigger=0)
$sql.= "name,";
$sql.= "type,";
$sql.= "webservice_address,";
$sql.= "api_version,";
$sql.= "authentication_type,";
$sql.= "user_name,";
$sql.= "user_password,";
Expand Down Expand Up @@ -197,6 +200,7 @@ function create($user, $notrigger=0)
$sql.= " ".(! isset($this->name)?'NULL':"'".$this->db->escape($this->name)."'").",";
$sql.= " ".(! isset($this->type)?'NULL':"'".$this->type."'").",";
$sql.= " ".(! isset($this->webservice_address)?'NULL':"'".$this->db->escape($this->webservice_address)."'").",";
$sql.= " ".(! isset($this->api_version)?'NULL':"'".$this->db->escape($this->api_version)."'").",";
$sql.= " ".(! isset($this->authentication_type)?'NULL':"'".$this->db->escape($this->authentication_type)."'").",";
$sql.= " ".(! isset($this->user_name)?'NULL':"'".$this->db->escape($this->user_name)."'").",";
$sql.= " ".(! isset($this->user_password)?'NULL':"'".$this->db->escape($this->user_password)."'").",";
Expand Down Expand Up @@ -277,6 +281,7 @@ function fetch($id)
$sql.= " t.name,";
$sql.= " t.type,";
$sql.= " t.webservice_address,";
$sql.= " t.api_version,";
$sql.= " t.authentication_type,";
$sql.= " t.user_name,";
$sql.= " t.user_password,";
Expand Down Expand Up @@ -316,6 +321,7 @@ function fetch($id)
$this->name = $obj->name;
$this->type = $obj->type;
$this->webservice_address = $obj->webservice_address;
$this->api_version = $obj->api_version;
$this->authentication_type = $obj->authentication_type;
$this->user_name = $obj->user_name;
$this->user_password = $obj->user_password;
Expand Down Expand Up @@ -374,6 +380,7 @@ function update($user=0, $notrigger=0)
if (isset($this->name)) $this->name=trim($this->name);
if (isset($this->type)) $this->type=trim($this->type);
if (isset($this->webservice_address)) $this->webservice_address=trim($this->webservice_address);
if (isset($this->api_version)) $this->api_version=trim($this->api_version);
if (isset($this->authentication_type)) $this->authentication_type=trim($this->authentication_type);
if (isset($this->user_name)) $this->user_name=trim($this->user_name);
if (isset($this->user_password)) $this->user_password=trim($this->user_password);
Expand All @@ -399,6 +406,7 @@ function update($user=0, $notrigger=0)
$sql.= " name=".(isset($this->name)?"'".$this->db->escape($this->name)."'":"null").",";
$sql.= " type=".(isset($this->type)?$this->type:"null").",";
$sql.= " webservice_address=".(isset($this->webservice_address)?"'".$this->db->escape($this->webservice_address)."'":"null").",";
$sql.= " api_version=".(isset($this->api_version)?"'".$this->db->escape($this->api_version)."'":"null").",";
$sql.= " authentication_type=".(isset($this->authentication_type)?"'".$this->db->escape($this->authentication_type)."'":"null").",";
$sql.= " user_name=".(isset($this->user_name)?"'".$this->db->escape($this->user_name)."'":"null").",";
$sql.= " user_password=".(isset($this->user_password)?"'".$this->db->escape($this->user_password)."'":"null").",";
Expand Down Expand Up @@ -618,6 +626,7 @@ function initAsSpecimen()
$this->name='';
$this->type='';
$this->webservice_address='';
$this->api_version='';
$this->authentication_type='';
$this->user_name='';
$this->user_password='';
Expand Down Expand Up @@ -857,6 +866,7 @@ public function upgradeParameters()
global $user;

// setup
if (!isset($this->api_version)) $this->api_version = 'v3';
if (!isset($this->authentication_type)) $this->authentication_type = 'oauth1_header';
// stock
if (!isset($this->parameters['order_actions']['valid_invoice_fk_warehouse'])) $this->parameters['order_actions']['valid_invoice_fk_warehouse'] = $this->parameters['order_actions']['valid_order_fk_warehouse'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3368,7 +3368,7 @@ public function createRemoteProduct($object)
dol_syslog(__METHOD__ . ': Error:' . $this->errorsToString(), LOG_ERR);
return false;
}
$results = isset($results['products']) ? $results['products'] : is_array($results) ? $results : [];
$results = isset($results['products']) ? $results['products'] : (is_array($results) ? $results : []);

$remote_id = '';
$remote_url = '';
Expand Down
2 changes: 1 addition & 1 deletion core/modules/modECommerceNg.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function __construct($db)
$this->editor_url = 'http://www.open-dsi.fr';

// Possible values for version are: 'development', 'experimental', 'dolibarr' or version
$this->version = '4.1.44';
$this->version = '4.1.45';
// Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
$this->const_name = 'MAIN_MODULE_' . strtoupper($this->name);
// Where to store the module in setup page (0=common,1=interface,2=others,3=very specific)
Expand Down
2 changes: 2 additions & 0 deletions langs/fr_FR/ecommerce.lang
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ ECommerceFilterLabel
ECommerceFilterValue =Valeur du filtre
ECommerceSiteType =Type de site
ECommerceSiteAddress =Adresse du site
ECommerceApiVersion =Version API
ECommerceApiVersionDescription =Choisissez la version de l'API
ECommerceAuthenticationType =Type d'authentification
ECommerceAuthenticationTypeDescription =Choissiez le type de connexion à WooCommerce<br>- Oauth 1 (Entête) (Les informations de connection sont passées dans l'entête de la requête)<br>- Oauth 1 (Url) (Les informations de connection sont passées en clair dans l'url de la requête)<br>- Basic (Les informations de connection sont passées dans l'entête de la requête)<br>- Url (Les informations de connection sont passées en clair dans l'url de la requête)
ECommerceAuthenticationTypeOauth1Header =Oauth 1 (Entête)
Expand Down
1 change: 1 addition & 0 deletions sql/llx_ecommerce_site.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ CREATE TABLE llx_ecommerce_site (
name varchar(255) NOT NULL,
type integer NOT NULL DEFAULT 1,
webservice_address varchar(255) NOT NULL,
api_version varchar(255) NULL,
authentication_type varchar(255) NULL,
user_name varchar(255) DEFAULT NULL,
user_password varchar(255) DEFAULT NULL,
Expand Down
3 changes: 3 additions & 0 deletions sql/update.sql
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ ALTER TABLE llx_ecommerce_site ADD COLUMN wordpress_authentication_password varc
ALTER TABLE llx_ecommerce_site ADD COLUMN wordpress_timeout integer NOT NULL DEFAULT 30 after wordpress_authentication_password;
ALTER TABLE llx_ecommerce_site ADD COLUMN wordpress_debug integer(1) NULL after wordpress_timeout;
ALTER TABLE llx_ecommerce_product ADD COLUMN last_update_stock datetime default NULL after last_update;

-- v4.1.45
ALTER TABLE llx_ecommerce_site ADD COLUMN api_version varchar(255) NULL after webservice_address;

0 comments on commit 7e4d8ff

Please sign in to comment.