diff --git a/htdocs/admin/modules.php b/htdocs/admin/modules.php
index 3b0f8ceb9cc..bd4ab9fde89 100644
--- a/htdocs/admin/modules.php
+++ b/htdocs/admin/modules.php
@@ -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') {
-
+
diff --git a/htdocs/admin/remotestore/class/externalModules.class.php b/htdocs/admin/remotestore/class/externalModules.class.php
index 95a8767a25d..f1fb5427324 100644
--- a/htdocs/admin/remotestore/class/externalModules.class.php
+++ b/htdocs/admin/remotestore/class/externalModules.class.php
@@ -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;
}
}