Fix duplicates answers

This commit is contained in:
Laurent Destailleur
2025-10-16 19:34:59 +02:00
parent 4fdf50752f
commit fa166d62a8
2 changed files with 33 additions and 7 deletions

View File

@@ -1323,7 +1323,7 @@ if ($mode == 'marketplace') {
$categories_tree = $remotestore->getCategories($options['categorie']); // Call API to get the categories
$products_list = $remotestore->getProducts($options);
$products_list = $remotestore->getProducts($options); // Get list of product from all sources
$previouslink = $remotestore->get_previous_link();
@@ -1337,7 +1337,7 @@ if ($mode == 'marketplace') {
<input type="hidden" name="mode" value="marketplace">
<input type="hidden" name="page_y" value="">
<div class="divsearchfield">
<input name="search_keyword" placeholder="<?php echo $langs->trans('Keyword') ?>" id="search_keyword" type="text" class="minwidth200" value="<?php echo dolPrintHTMLForAttribute($options['search']) ?>">
<input name="search_keyword" placeholder="<?php echo $langs->trans('Keyword') ?>" id="search_keyword" type="text" class="minwidth200" value="<?php echo dolPrintHTMLForAttribute($options['search']) ?>" spellcheck="false">
</div>
<div class="divsearchfield">
<input name="buttonsubmit" class="button buttongen reposition" value="<?php echo $langs->trans('Search') ?>" type="submit">

View File

@@ -352,10 +352,13 @@ class ExternalModules
'lang' => $this->lang
];
$this->numberTotalOfProducts = 0;
// Fetch the products from Dolistore source
$dolistoreProducts = array();
$dolistoreProductsTotal = 0;
$this->numberTotalOfProducts = 0;
if ($this->dolistoreApiStatus > 0 && getDolGlobalInt('MAIN_ENABLE_EXTERNALMODULES_DOLISTORE')) {
$getDolistoreProducts = $this->callApi('products', $data);
@@ -368,8 +371,9 @@ class ExternalModules
$this->numberTotalOfProducts += $dolistoreProductsTotal;
}
}
var_dump($dolistoreProducts);
// Fetch the products from the github repo
$fileProducts = array();
$fileProductsTotal = 0;
if (!empty($this->githubFileStatus) && getDolGlobalInt('MAIN_ENABLE_EXTERNALMODULES_COMMUNITY')) {
@@ -389,8 +393,22 @@ class ExternalModules
// Number of pages
$this->numberTotalOfPages = (int) ceil(max($fileProductsTotal / $this->per_page, $dolistoreProductsTotal / $this->per_page));
// merge both sources
$this->products = array_values(array_merge($fileProducts, $dolistoreProducts));
// Merge both sources (github community modules have priority on dolistore).
$this->products = $dolistoreProducts;
foreach ($fileProducts as $fileProduct) {
$id = $fileProduct['id'];
if ($id > 0) {
if (empty($this->products[$id])) { // Not already present in array
array_unshift($this->products, $fileProduct);
} else {
$this->products[$id] = $fileProduct;
$this->products[$id]['category'] = $fileProduct['category'];
}
} else {
array_unshift($this->products, $fileProduct);
}
}
$i = 0;
foreach ($this->products as $product) {
@@ -975,7 +993,15 @@ class ExternalModules
continue;
}
// Check if there is a known ID
$reg = array();
$id = 0;
if (!empty($package['dolistore-download']) && preg_match('/www\.dolistore\.com\/product\.php\?id=(\d+)/', $package['dolistore-download'], $reg)) {
$id = $reg[1];
}
$adaptedPackage = [
'id' => $id,
'ref' => str_replace(' ', '', $package['modulename'] . '-' . $package['current_version'] . '@' .
(array_key_exists('author', $package) ? $package['author'] : 'unkownauthor')),
'label' => !empty($package['label'][substr($this->lang, 0, 2)])
@@ -1064,7 +1090,7 @@ class ExternalModules
'status' => empty($package['status']) ? '' : $package['status']
];
$adaptedData[] = $adaptedPackage;
$adaptedData[$package['id']] = $adaptedPackage;
}
}