19 include_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
20 if (!class_exists(
'PrestaShopWebservice'))
22 include_once DOL_DOCUMENT_ROOT.
'/admin/dolistore/class/PSWebServiceLibrary.class.php';
63 $this->url = DOL_URL_ROOT.
'/admin/modules.php?mode=marketplace';
64 $this->shop_url =
'https://www.dolistore.com/index.php?controller=product&id_product=';
65 $this->debug_api = $debug;
67 $langtmp = explode(
'_', $langs->defaultlang);
69 $lang_array = array(
'en'=>1,
'fr'=>2,
'es'=>3,
'it'=>4,
'de'=>5);
70 if (!in_array($lang, array_keys($lang_array))) $lang =
'en';
71 $this->lang = $lang_array[$lang];
85 $this->api =
new PrestaShopWebservice($conf->global->MAIN_MODULE_DOLISTORE_API_SRV, $conf->global->MAIN_MODULE_DOLISTORE_API_KEY, $this->debug_api);
86 dol_syslog(
"Call API with MAIN_MODULE_DOLISTORE_API_SRV = ".$conf->global->MAIN_MODULE_DOLISTORE_API_SRV);
91 $opt[
'resource'] =
'categories';
92 $opt[
'display'] =
'[id,id_parent,nb_products_recursive,active,is_root_category,name,description]';
93 $opt[
'sort'] =
'id_asc';
96 dol_syslog(
"Call API with opt = ".var_export($opt,
true));
97 $xml = $this->api->get($opt);
98 $this->categories = $xml->categories->children();
101 $trace = $e->getTrace();
102 if ($trace[0][
'args'][0] == 404) die(
'Bad ID');
103 elseif ($trace[0][
'args'][0] == 401) die(
'Bad auth key');
105 print 'Can not access to '.$conf->global->MAIN_MODULE_DOLISTORE_API_SRV.
'<br>';
106 print $e->getMessage();
118 public function getRemoteProducts($options = array(
'start' => 0,
'end' => 10,
'per_page' => 50,
'categorie' => 0,
'search' =>
''))
122 $this->start = $options[
'start'];
123 $this->end = $options[
'end'];
124 $this->per_page = $options[
'per_page'];
125 $this->categorie = $options[
'categorie'];
126 $this->search = $options[
'search'];
128 if ($this->end == 0) {
129 $this->end = $this->per_page;
133 $this->api =
new PrestaShopWebservice($conf->global->MAIN_MODULE_DOLISTORE_API_SRV, $conf->global->MAIN_MODULE_DOLISTORE_API_KEY, $this->debug_api);
134 dol_syslog(
"Call API with MAIN_MODULE_DOLISTORE_API_SRV = ".$conf->global->MAIN_MODULE_DOLISTORE_API_SRV);
139 $opt[
'resource'] =
'products';
143 if ($this->search !=
'') {
144 $opt2[
'url'] = $conf->global->MAIN_MODULE_DOLISTORE_API_SRV.
'/api/search?query='.$this->search.
'&language='.$this->lang;
147 dol_syslog(
"Call API with opt2 = ".var_export($opt2,
true));
148 $xml = $this->api->get($opt2);
151 foreach ($xml->products->children() as $product) {
152 $products[] = (int) $product[
'id'];
154 $opt[
'filter[id]'] =
'['.implode(
'|', $products).
']';
155 } elseif ($this->categorie != 0) {
157 $opt2[
'resource'] =
'categories';
158 $opt2[
'id'] = $this->categorie;
161 dol_syslog(
"Call API with opt2 = ".var_export($opt2,
true));
162 $xml = $this->api->get($opt2);
165 foreach ($xml->category->associations->products->children() as $product) {
166 $products[] = (int) $product->id;
168 $opt[
'filter[id]'] =
'['.implode(
'|', $products).
']';
170 $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]';
171 $opt[
'sort'] =
'id_desc';
172 $opt[
'filter[active]'] =
'[1]';
173 $opt[
'limit'] =
"$this->start,$this->end";
177 dol_syslog(
"Call API with opt = ".var_export($opt,
true));
178 $xml = $this->api->get($opt);
179 $this->products = $xml->products->children();
182 $trace = $e->getTrace();
183 if ($trace[0][
'args'][0] == 404) die(
'Bad ID');
184 elseif ($trace[0][
'args'][0] == 401) die(
'Bad auth key');
186 print 'Can not access to '.$conf->global->MAIN_MODULE_DOLISTORE_API_SRV.
'<br>';
187 print $e->getMessage();
202 if (!isset($this->categories)) die(
'not possible');
209 $nbofcateg = count($this->categories);
210 for ($i = 0; $i < $nbofcateg; $i++)
212 $cat = $this->categories[$i];
213 if ($cat->is_root_category == 1 && $parent == 0) {
214 $html .=
'<li class="root"><h3 class="nomargesupinf"><a class="nomargesupinf link2cat" href="?mode=marketplace&categorie='.$cat->id.
'" ';
215 $html .=
'title="'.dol_escape_htmltag(strip_tags($cat->description->language[$this->lang - 1])).
'">'.$cat->name->language[$this->lang - 1].
' <sup>'.$cat->nb_products_recursive.
'</sup></a></h3>';
216 $html .= self::get_categories($cat->id);
218 } elseif (trim($cat->id_parent) == $parent && $cat->active == 1 && trim($cat->id_parent) != 0) {
219 $select = ($cat->id == $this->categorie) ?
' selected' :
'';
220 $html .=
'<li><a class="link2cat'.$select.
'" href="?mode=marketplace&categorie='.$cat->id.
'"';
221 $html .=
' title="'.dol_escape_htmltag(strip_tags($cat->description->language[$this->lang - 1])).
'" ';
222 $html .=
'>'.$cat->name->language[$this->lang - 1].
' <sup>'.$cat->nb_products_recursive.
'</sup></a>';
223 $html .= self::get_categories($cat->id);
228 if ($html ==
'<ul>') {
232 return $html.
'</ul>';
247 global $langs, $conf;
249 $last_month = time() - (30 * 24 * 60 * 60);
250 foreach ($this->products as $product) {
253 if ($last_month < strtotime($product->date_add)) {
254 $newapp .=
'<span class="newApp">'.$langs->trans(
'New').
'</span> ';
258 if ($last_month < strtotime($product->date_upd) && $newapp ==
'') {
259 $newapp .=
'<span class="updatedApp">'.$langs->trans(
'Updated').
'</span> ';
263 if ($product->id_default_image !=
'') {
264 $image_url = DOL_URL_ROOT.
'/admin/dolistore/ajax/image.php?id_product='.$product->id.
'&id_image='.$product->id_default_image;
265 $images =
'<a href="'.$image_url.
'" class="documentpreview" target="_blank" mime="image/png" title="'.$product->name->language[$this->lang - 1].
', '.$langs->trans(
'Version').
' '.$product->module_version.
'">';
266 $images .=
'<img src="'.$image_url.
'&quality=home_default" style="max-height:250px;max-width: 210px;" alt="" /></a>';
268 $images =
'<img src="'.DOL_URL_ROOT.
'/admin/dolistore/img/NoImageAvailable.png" />';
272 if ($product->price > 0) {
273 $price =
'<h3>'.price(
price2num($product->price,
'MT'), 0, $langs, 1, -1, -1,
'EUR').
' '.$langs->trans(
"HT").
'</h3>';
274 $download_link =
'<a target="_blank" href="'.$this->shop_url.$product->id.
'"><img width="32" src="'.DOL_URL_ROOT.
'/admin/dolistore/img/follow.png" /></a>';
276 $price =
'<h3>'.$langs->trans(
'Free').
'</h3>';
277 $download_link =
'<a target="_blank" href="'.$this->shop_url.$product->id.
'"><img width="32" src="'.DOL_URL_ROOT.
'/admin/dolistore/img/Download-128.png" /></a>';
278 $download_link .=
'<br><br><a target="_blank" href="'.$this->shop_url.$product->id.
'"><img width="32" src="'.DOL_URL_ROOT.
'/admin/dolistore/img/follow.png" /></a>';
282 if ($this->
version_compare($product->dolibarr_min, DOL_VERSION) <= 0) {
283 if ($this->
version_compare($product->dolibarr_max, DOL_VERSION) >= 0) {
285 $version =
'<span class="compatible">'.$langs->trans(
'CompatibleUpTo', $product->dolibarr_max,
286 $product->dolibarr_min, $product->dolibarr_max).
'</span>';
290 $version =
'<span class="notcompatible">'.$langs->trans(
'NotCompatible', DOL_VERSION,
291 $product->dolibarr_min, $product->dolibarr_max).
'</span>';
292 $compatible =
'NotCompatible';
296 $version =
'<span class="compatibleafterupdate">'.$langs->trans(
'CompatibleAfterUpdate', DOL_VERSION,
297 $product->dolibarr_min, $product->dolibarr_max).
'</span>';
298 $compatible =
'NotCompatible';
304 $html .=
'<tr class="app oddeven '.$compatible.
'">
305 <td class="center" width="210"><div class="newAppParent">'.$newapp.$images.
'</div></td>
306 <td class="margeCote"><h2 class="appTitle">'.$product->name->language[$this->lang - 1]
307 .
'<br/><small>'.$version.
'</small></h2>
308 <small> '.
dol_print_date(
dol_stringtotime($product->date_upd),
'dayhour').
' - '.$langs->trans(
'Ref').
': '.$product->reference.
' - '.$langs->trans(
'Id').
': '.$product->id.
'</small><br><br>'.$product->description_short->language[$this->lang - 1].
'</td>';
311 $html .=
'<td class="margeCote center">'.$price.
'</td>';
312 $html .=
'<td class="margeCote">'.$download_link.
'</td>';
328 return '<a href="'.$this->get_previous_url().
'" class="button">'.$text.
'</a>';
341 return '<a href="'.$this->get_next_url().
'" class="button">'.$text.
'</a>';
353 $param_array = array();
354 if ($this->start < $this->per_page) {
357 $sub = $this->per_page;
359 $param_array[
'start'] = $this->start - $sub;
360 $param_array[
'end'] = $this->end - $sub;
361 if ($this->categorie != 0) {
362 $param_array[
'categorie'] = $this->categorie;
364 $param = http_build_query($param_array);
365 return $this->url.
"&".$param;
377 $param_array = array();
378 if (count($this->products) < $this->per_page) {
381 $add = $this->per_page;
383 $param_array[
'start'] = $this->start + $add;
384 $param_array[
'end'] = $this->end + $add;
385 if ($this->categorie != 0) {
386 $param_array[
'categorie'] = $this->categorie;
388 $param = http_build_query($param_array);
389 return $this->url.
"&".$param;
403 $v1 = explode(
'.', $v1);
404 $v2 = explode(
'.', $v2);
407 $count1 = count($v1);
408 $count2 = count($v2);
409 $maxcount = max($count1, $count2);
410 while ($level < $maxcount) {
411 $operande1 = isset($v1[$level]) ? $v1[$level] :
'x';
412 $operande2 = isset($v2[$level]) ? $v2[$level] :
'x';
414 if (strtoupper($operande1) ==
'X' || strtoupper($operande2) ==
'X' || $operande1 ==
'*' || $operande2 ==
'*') {
417 if ($operande1 < $operande2) {
421 if ($operande1 > $operande2) {
__construct($debug=false)
Constructor.
get_previous_url()
get previous url
get_next_link($text= '>>')
get next link
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...
version_compare($v1, $v2)
version compare
getRemoteCategories()
Load data from remote Dolistore market place.
get_products()
Return list of product formated for output.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
get_next_url()
get next url
print
Draft customers invoices.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
get_categories($parent=0)
Return tree of Dolistore categories.
getRemoteProducts($options=array('start'=> 0, 'end'=> 10, 'per_page'=> 50, 'categorie'=> 0, 'search'=> ''))
Load data from remote Dolistore market place.
get_previous_link($text= '<<')
get previous link