From 2eebb50e15d4487a7c040f05a86bf546b1aa91e2 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Thu, 23 May 2024 13:13:31 +0530 Subject: [PATCH] Fixed: Sort by price in module catelog page --- .../modules_catalog/modules_list.tpl | 5 ++-- classes/module/Module.php | 12 ++-------- .../admin/AdminModulesCatalogController.php | 24 ++++++++++++------- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/admin/themes/default/template/controllers/modules_catalog/modules_list.tpl b/admin/themes/default/template/controllers/modules_catalog/modules_list.tpl index 22113e45c..9721a7c63 100644 --- a/admin/themes/default/template/controllers/modules_catalog/modules_list.tpl +++ b/admin/themes/default/template/controllers/modules_catalog/modules_list.tpl @@ -35,11 +35,12 @@ {/if}

+ {if isset($element->price)}{if $element->price|floatval == 0}{l s='Free'}{else}{$element->price_formatted}{/if}{/if} + {if isset($element->type) && $element->type == 'addonsMustHave' && !$element->not_on_disk}{l s='In library'}{/if} {if isset($element->type) && $element->type == 'addonsMustHave' && $element->not_on_disk} - {if isset($element->price)}{if $element->price|floatval == 0}{l s='Free'}{elseif isset($element->id_currency)}{displayPrice price=$element->price currency=$element->id_currency}{/if}{/if} {l s='Explore'} {else} - trusted} data-target="#moduleNotTrusted" data-toggle="modal"{/if} data-link="{$element->options.install_url|escape:'html':'UTF-8'}" data-module-display-name="{$element->displayName|escape:'html':'UTF-8'}" data-module-name="{$element->name|escape:'html':'UTF-8'}" data-module-image="{if isset($element->image)}{$element->image}{else}{$modules_uri}/{$element->name}/{$element->logo}{/if}" data-author-name="{$element->author|escape:'html':'UTF-8'}" data-author-uri="{if isset($element->author_uri)}{$element->author_uri|escape:'html':'UTF-8'}{/if}" href="{if !$element->trusted}#{else}{$element->options.install_url|escape:'html':'UTF-8'}{/if}" title="{l s='Install'}">{l s='Install'} + trusted} data-target="#moduleNotTrusted" data-toggle="modal"{/if} data-link="{$element->options.install_url|escape:'html':'UTF-8'}" data-module-display-name="{$element->displayName|escape:'html':'UTF-8'}" data-module-name="{$element->name|escape:'html':'UTF-8'}" data-module-image="{if isset($element->image)}{$element->image}{else}{$modules_uri}/{$element->name}/{$element->logo}{/if}" data-author-name="{$element->author|escape:'html':'UTF-8'}" data-author-uri="{if isset($element->author_uri)}{$element->author_uri|escape:'html':'UTF-8'}{/if}" href="{if !$element->trusted}#{else}{$element->options.install_url|escape:'html':'UTF-8'}{/if}" title="{l s='Install'}">{l s='Install'} {/if}
diff --git a/classes/module/Module.php b/classes/module/Module.php index 95d78ca09..5dd18e9d6 100644 --- a/classes/module/Module.php +++ b/classes/module/Module.php @@ -1665,17 +1665,9 @@ abstract class ModuleCore if ($item->type == 'addonsMustHave') { $item->addons_buy_url = strip_tags((string)$modaddons->url); $prices = (array)$modaddons->price; - $id_default_currency = Configuration::get('PS_CURRENCY_DEFAULT'); - foreach ($prices as $currency => $price) { - if ($id_currency = Currency::getIdByIsoCode($currency)) { - $item->price = (float)$price; - $item->id_currency = (int)$id_currency; - - if ($id_default_currency == $id_currency) { - break; - } - } + foreach ($prices as $key => $value) { + $item->{$key} = $value; } } diff --git a/controllers/admin/AdminModulesCatalogController.php b/controllers/admin/AdminModulesCatalogController.php index 6fb11effa..0fe997e85 100644 --- a/controllers/admin/AdminModulesCatalogController.php +++ b/controllers/admin/AdminModulesCatalogController.php @@ -256,15 +256,23 @@ class AdminModulesCatalogControllerCore extends AdminController if ($criteria == 'name') { return strnatcasecmp($a->displayName, $b->displayName); } else if ($criteria == 'price_increasing') { - if (isset($a->price) && isset($b->price)) - return $a->price > $b->price; - else if (isset($b->price) && $b->price) - return true; + $priceA = $priceB = 0; + if (isset($a->price)) { + $priceA = $a->price; + } + if (isset($b->price)) { + $priceB = $b->price; + } + return $priceA > $priceB; } else if ($criteria == 'price_decreasing') { - if (isset($a->price) && isset($b->price)) - return $a->price < $b->price; - else if (isset($b->price) && $b->price) - return true; + $priceA = $priceB = 0; + if (isset($a->price)) { + $priceA = $a->price; + } + if (isset($b->price)) { + $priceB = $b->price; + } + return $priceA < $priceB; } });