Some fix with dolistore api
This commit is contained in:
parent
6eb9f13ec2
commit
2e36e5afa5
@ -43,18 +43,18 @@ class Dolistore
|
|||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
function __construct()
|
function __construct($debug=false)
|
||||||
{
|
{
|
||||||
global $conf, $langs;
|
global $conf, $langs;
|
||||||
|
|
||||||
$this->url = DOL_URL_ROOT.'/admin/modules.php?mode=marketplace';
|
$this->url = DOL_URL_ROOT.'/admin/modules.php?mode=marketplace';
|
||||||
$this->shop_url = 'https://www.dolistore.com/index.php?controller=product&id_product=';
|
$this->shop_url = 'https://www.dolistore.com/index.php?controller=product&id_product=';
|
||||||
$this->vat_rate = 1.2; // 20% de TVA
|
$this->vat_rate = 1.2; // 20% de TVA
|
||||||
$this->debug_api = false;
|
$this->debug_api = $debug;
|
||||||
|
|
||||||
$langtmp = explode('_', $langs->defaultlang);
|
$langtmp = explode('_', $langs->defaultlang);
|
||||||
$lang = $langtmp[0];
|
$lang = $langtmp[0];
|
||||||
$lang_array = array('en'=>0, 'fr'=>1, 'es'=>2, 'it'=>3, 'de'=>4); // Into table ps_lang of Prestashop - 1
|
$lang_array = array('en'=>1, 'fr'=>2, 'es'=>3, 'it'=>4, 'de'=>5); // Into table ps_lang of Prestashop - 1
|
||||||
if (! in_array($lang, array_keys($lang_array))) $lang = 'en';
|
if (! in_array($lang, array_keys($lang_array))) $lang = 'en';
|
||||||
$this->lang = $lang_array[$lang];
|
$this->lang = $lang_array[$lang];
|
||||||
}
|
}
|
||||||
@ -81,8 +81,9 @@ class Dolistore
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->api = new PrestaShopWebservice($conf->global->MAIN_MODULE_DOLISTORE_API_SRV,
|
$this->api = new PrestaShopWebservice($conf->global->MAIN_MODULE_DOLISTORE_API_SRV, $conf->global->MAIN_MODULE_DOLISTORE_API_KEY, $this->debug_api);
|
||||||
$conf->global->MAIN_MODULE_DOLISTORE_API_KEY, $this->debug_api);
|
dol_syslog("Call API with MAIN_MODULE_DOLISTORE_API_SRV = ".$conf->global->MAIN_MODULE_DOLISTORE_API_SRV);
|
||||||
|
// $conf->global->MAIN_MODULE_DOLISTORE_API_KEY is for the login of basic auth. There is no password as it is public data.
|
||||||
|
|
||||||
// Here we set the option array for the Webservice : we want products resources
|
// Here we set the option array for the Webservice : we want products resources
|
||||||
$opt = array();
|
$opt = array();
|
||||||
@ -92,7 +93,13 @@ class Dolistore
|
|||||||
if ($this->search != '') {
|
if ($this->search != '') {
|
||||||
$opt2 = array();
|
$opt2 = array();
|
||||||
$opt2['url'] = $conf->global->MAIN_MODULE_DOLISTORE_API_SRV.'/api/search?query='.$this->search.'&language='.$this->lang;
|
$opt2['url'] = $conf->global->MAIN_MODULE_DOLISTORE_API_SRV.'/api/search?query='.$this->search.'&language='.$this->lang;
|
||||||
|
|
||||||
// Call
|
// Call
|
||||||
|
var_dump($this->api);
|
||||||
|
|
||||||
|
dol_syslog("Call API with opt = ".var_export($opt, true));
|
||||||
|
dol_syslog("Call API with opt2 = ".var_export($opt2, true));
|
||||||
|
|
||||||
$xml = $this->api->get($opt2);
|
$xml = $this->api->get($opt2);
|
||||||
$products = array();
|
$products = array();
|
||||||
foreach ($xml->products->children() as $product) {
|
foreach ($xml->products->children() as $product) {
|
||||||
@ -117,7 +124,10 @@ class Dolistore
|
|||||||
$opt['limit'] = "$this->start,$this->end";
|
$opt['limit'] = "$this->start,$this->end";
|
||||||
// $opt['filter[id]'] contais list of product id that are result of search
|
// $opt['filter[id]'] contais list of product id that are result of search
|
||||||
|
|
||||||
|
|
||||||
// Call API to get the detail
|
// Call API to get the detail
|
||||||
|
dol_syslog("Call API with opt = ".var_export($opt, true));
|
||||||
|
dol_syslog("Call API with opt2 = ".var_export($opt2, true));
|
||||||
$xml = $this->api->get($opt);
|
$xml = $this->api->get($opt);
|
||||||
$this->products = $xml->products->children();
|
$this->products = $xml->products->children();
|
||||||
|
|
||||||
@ -135,7 +145,11 @@ class Dolistore
|
|||||||
$trace = $e->getTrace();
|
$trace = $e->getTrace();
|
||||||
if ($trace[0]['args'][0] == 404) die('Bad ID');
|
if ($trace[0]['args'][0] == 404) die('Bad ID');
|
||||||
else if ($trace[0]['args'][0] == 401) die('Bad auth key');
|
else if ($trace[0]['args'][0] == 401) die('Bad auth key');
|
||||||
else die('Can not access to '.$conf->global->MAIN_MODULE_DOLISTORE_API_SRV);
|
else
|
||||||
|
{
|
||||||
|
print 'Can not access to '.$conf->global->MAIN_MODULE_DOLISTORE_API_SRV.'<br>';
|
||||||
|
print $e->getMessage();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -55,7 +55,7 @@ $options['categorie'] = ((GETPOST('categorie', 'int')?GETPOST('categorie', 'int'
|
|||||||
$options['start'] = ((GETPOST('start', 'int')?GETPOST('start', 'int'):0) + 0);
|
$options['start'] = ((GETPOST('start', 'int')?GETPOST('start', 'int'):0) + 0);
|
||||||
$options['end'] = ((GETPOST('end', 'int')?GETPOST('end', 'int'):0) + 0);
|
$options['end'] = ((GETPOST('end', 'int')?GETPOST('end', 'int'):0) + 0);
|
||||||
$options['search'] = GETPOST('search_keyword', 'alpha');
|
$options['search'] = GETPOST('search_keyword', 'alpha');
|
||||||
$dolistore = new Dolistore();
|
$dolistore = new Dolistore(false);
|
||||||
|
|
||||||
|
|
||||||
if (! $user->admin)
|
if (! $user->admin)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user