19include_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
20if (!class_exists(
'PrestaShopWebservice')) {
21 include_once DOL_DOCUMENT_ROOT.
'/admin/dolistore/class/PSWebServiceLibrary.class.php';
62 $this->url = DOL_URL_ROOT.
'/admin/modules.php?mode=marketplace';
63 $this->shop_url =
'https://www.dolistore.com/index.php?controller=product&id_product=';
64 $this->debug_api = $debug;
66 $langtmp = explode(
'_', $langs->defaultlang);
68 $lang_array = array(
'en'=>1,
'fr'=>2,
'es'=>3,
'it'=>4,
'de'=>5);
69 if (!in_array($lang, array_keys($lang_array))) {
72 $this->lang = $lang_array[$lang];
86 $this->api =
new PrestaShopWebservice($conf->global->MAIN_MODULE_DOLISTORE_API_SRV, $conf->global->MAIN_MODULE_DOLISTORE_API_KEY, $this->debug_api);
92 $opt[
'resource'] =
'categories';
93 $opt[
'display'] =
'[id,id_parent,nb_products_recursive,active,is_root_category,name,description]';
94 $opt[
'sort'] =
'id_asc';
97 dol_syslog(
"Call API with opt = ".var_export($opt,
true));
98 $xml = $this->api->get($opt);
99 $this->categories = $xml->categories->children();
102 $trace = $e->getTrace();
103 if ($trace[0][
'args'][0] == 404) {
105 } elseif ($trace[0][
'args'][0] == 401) {
108 print
'Can not access to '.$conf->global->MAIN_MODULE_DOLISTORE_API_SRV.
'<br>';
109 print $e->getMessage();
121 public function getRemoteProducts($options = array(
'start' => 0,
'end' => 10,
'per_page' => 50,
'categorie' => 0,
'search' =>
''))
125 $this->start = $options[
'start'];
126 $this->end = $options[
'end'];
127 $this->per_page = $options[
'per_page'];
128 $this->categorie = $options[
'categorie'];
129 $this->search = $options[
'search'];
131 if ($this->end == 0) {
132 $this->end = $this->per_page;
136 $this->api =
new PrestaShopWebservice($conf->global->MAIN_MODULE_DOLISTORE_API_SRV, $conf->global->MAIN_MODULE_DOLISTORE_API_KEY, $this->debug_api);
142 $opt[
'resource'] =
'products';
146 if ($this->search !=
'') {
147 $opt2[
'url'] = $conf->global->MAIN_MODULE_DOLISTORE_API_SRV.
'/api/search?query='.$this->search.
'&language='.$this->lang;
150 dol_syslog(
"Call API with opt2 = ".var_export($opt2,
true));
151 $xml = $this->api->get($opt2);
154 foreach ($xml->products->children() as $product) {
155 $products[] = (int) $product[
'id'];
157 $opt[
'filter[id]'] =
'['.implode(
'|', $products).
']';
158 } elseif ($this->categorie != 0) {
160 $opt2[
'resource'] =
'categories';
161 $opt2[
'id'] = $this->categorie;
164 dol_syslog(
"Call API with opt2 = ".var_export($opt2,
true));
165 $xml = $this->api->get($opt2);
168 foreach ($xml->category->associations->products->children() as $product) {
169 $products[] = (int) $product->id;
171 $opt[
'filter[id]'] =
'['.implode(
'|', $products).
']';
173 $opt[
'display'] =
'[id,name,id_default_image,id_category_default,reference,price,condition,show_price,date_add,date_upd,description_short,description,module_version,dolibarr_min,dolibarr_max]';
174 $opt[
'sort'] =
'id_desc';
175 $opt[
'filter[active]'] =
'[1]';
176 $opt[
'limit'] =
"$this->start,$this->end";
180 dol_syslog(
"Call API with opt = ".var_export($opt,
true));
181 $xml = $this->api->get($opt);
182 $this->products = $xml->products->children();
185 $trace = $e->getTrace();
186 if ($trace[0][
'args'][0] == 404) {
188 } elseif ($trace[0][
'args'][0] == 401) {
191 print
'Can not access to '.$conf->global->MAIN_MODULE_DOLISTORE_API_SRV.
'<br>';
192 print $e->getMessage();
207 if (!isset($this->categories)) {
216 $nbofcateg = count($this->categories);
217 for ($i = 0; $i < $nbofcateg; $i++) {
218 $cat = $this->categories[$i];
219 if ($cat->is_root_category == 1 && $parent == 0) {
220 $html .=
'<li class="root"><h3 class="nomargesupinf"><a class="nomargesupinf link2cat" href="?mode=marketplace&categorie='.((int) $cat->id).
'" ';
221 $html .=
'title="'.dol_escape_htmltag(strip_tags($cat->description->language[$this->lang - 1])).
'">'.
dol_escape_htmltag($cat->name->language[$this->lang - 1]).
' <sup>'.
dol_escape_htmltag($cat->nb_products_recursive).
'</sup></a></h3>';
224 } elseif (trim($cat->id_parent) == $parent && $cat->active == 1 && trim($cat->id_parent) != 0) {
225 $select = ($cat->id == $this->categorie) ?
' selected' :
'';
226 $html .=
'<li><a class="link2cat'.$select.
'" href="?mode=marketplace&categorie='.((int) $cat->id).
'"';
227 $html .=
' title="'.dol_escape_htmltag(strip_tags($cat->description->language[$this->lang - 1])).
'" ';
228 $html .=
'>'.dol_escape_htmltag($cat->name->language[$this->lang - 1]).
' <sup>'.
dol_escape_htmltag($cat->nb_products_recursive).
'</sup></a>';
234 if ($html ==
'<ul>') {
238 return $html.
'</ul>';
253 global $langs, $conf;
255 $last_month = time() - (30 * 24 * 60 * 60);
256 foreach ($this->products as $product) {
259 if ($last_month < strtotime($product->date_add)) {
260 $newapp .=
'<span class="newApp">'.$langs->trans(
'New').
'</span> ';
264 if ($last_month < strtotime($product->date_upd) && $newapp ==
'') {
265 $newapp .=
'<span class="updatedApp">'.$langs->trans(
'Updated').
'</span> ';
269 if ($product->id_default_image !=
'') {
270 $image_url = DOL_URL_ROOT.
'/admin/dolistore/ajax/image.php?id_product='.urlencode(((
int) $product->id)).
'&id_image='.urlencode(((
int) $product->id_default_image));
271 $images =
'<a href="'.$image_url.
'" class="documentpreview" target="_blank" rel="noopener noreferrer" mime="image/png" title="'.
dol_escape_htmltag($product->name->language[$this->lang - 1].
', '.$langs->trans(
'Version').
' '.$product->module_version).
'">';
272 $images .=
'<img src="'.$image_url.
'&quality=home_default" style="max-height:250px;max-width: 210px;" alt="" /></a>';
274 $images =
'<img src="'.DOL_URL_ROOT.
'/admin/dolistore/img/NoImageAvailable.png" />';
278 if ($product->price > 0) {
279 $price =
'<h3>'.price(
price2num($product->price,
'MT'), 0, $langs, 1, -1, -1,
'EUR').
' '.$langs->trans(
"HT").
'</h3>';
280 $download_link =
'<a target="_blank" href="'.$this->shop_url.urlencode($product->id).
'"><img width="32" src="'.DOL_URL_ROOT.
'/admin/dolistore/img/follow.png" /></a>';
282 $price =
'<h3>'.$langs->trans(
'Free').
'</h3>';
283 $download_link =
'<a target="_blank" rel="noopener noreferrer" href="'.$this->shop_url.urlencode($product->id).
'"><img width="32" src="'.DOL_URL_ROOT.
'/admin/dolistore/img/Download-128.png" /></a>';
284 $download_link .=
'<br><br><a target="_blank" href="'.$this->shop_url.urlencode($product->id).
'"><img width="32" src="'.DOL_URL_ROOT.
'/admin/dolistore/img/follow.png" /></a>';
289 if ($this->
version_compare($product->dolibarr_min, DOL_VERSION) <= 0) {
290 if ($this->
version_compare($product->dolibarr_max, DOL_VERSION) >= 0) {
292 $version =
'<span class="compatible">'.$langs->trans(
294 $product->dolibarr_max,
295 $product->dolibarr_min,
296 $product->dolibarr_max
301 $version =
'<span class="notcompatible">'.$langs->trans(
304 $product->dolibarr_min,
305 $product->dolibarr_max
307 $compatible =
'NotCompatible';
311 $version =
'<span class="compatibleafterupdate">'.$langs->trans(
312 'CompatibleAfterUpdate',
314 $product->dolibarr_min,
315 $product->dolibarr_max
317 $compatible =
'NotCompatible';
321 $html .=
'<tr class="app oddeven '.dol_escape_htmltag($compatible).
'">';
322 $html .=
'<td class="center" width="210"><div class="newAppParent">';
323 $html .= $newapp.$images;
324 $html .=
'</div></td>';
325 $html .=
'<td class="margeCote"><h2 class="appTitle">';
327 $html .=
'<br><small>';
329 $html .=
'</small></h2>';
332 $html .=
'<td class="margeCote center">';
335 $html .=
'<td class="margeCote">'.$download_link.
'</td>';
351 return '<a href="'.$this->get_previous_url().
'" class="button">'.
dol_escape_htmltag($text).
'</a>';
364 return '<a href="'.$this->get_next_url().
'" class="button">'.
dol_escape_htmltag($text).
'</a>';
376 $param_array = array();
377 if ($this->start < $this->per_page) {
380 $sub = $this->per_page;
382 $param_array[
'start'] = $this->start - $sub;
383 $param_array[
'end'] = $this->end - $sub;
384 if ($this->categorie != 0) {
385 $param_array[
'categorie'] = $this->categorie;
387 $param = http_build_query($param_array);
388 return $this->url.
"&".$param;
400 $param_array = array();
401 if (count($this->products) < $this->per_page) {
404 $add = $this->per_page;
406 $param_array[
'start'] = $this->start + $add;
407 $param_array[
'end'] = $this->end + $add;
408 if ($this->categorie != 0) {
409 $param_array[
'categorie'] = $this->categorie;
411 $param = http_build_query($param_array);
412 return $this->url.
"&".$param;
426 $v1 = explode(
'.', $v1);
427 $v2 = explode(
'.', $v2);
430 $count1 = count($v1);
431 $count2 = count($v2);
432 $maxcount = max($count1, $count2);
433 while ($level < $maxcount) {
434 $operande1 = isset($v1[$level]) ? $v1[$level] :
'x';
435 $operande2 = isset($v2[$level]) ? $v2[$level] :
'x';
437 if (strtoupper($operande1) ==
'X' || strtoupper($operande2) ==
'X' || $operande1 ==
'*' || $operande2 ==
'*') {
440 if ($operande1 < $operande2) {
444 if ($operande1 > $operande2) {
get_products()
Return list of product formated for output.
getRemoteCategories()
Load data from remote Dolistore market place.
get_next_url()
get next url
__construct($debug=false)
Constructor.
get_categories($parent=0)
Return tree of Dolistore categories.
get_next_link($text='> >')
get next link
version_compare($v1, $v2)
version compare
get_previous_url()
get previous url
get_previous_link($text='<<')
get previous link
getRemoteProducts($options=array('start'=> 0, 'end'=> 10, 'per_page'=> 50, 'categorie'=> 0, 'search'=> ''))
Load data from remote Dolistore market place.
dol_stringtotime($string, $gm=1)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...