Skip to content

Hide out of stock products from any filter - #984

Closed
msaustral wants to merge 1 commit into
PrestaShop:devfrom
msaustral:dev
Closed

Hide out of stock products from any filter#984
msaustral wants to merge 1 commit into
PrestaShop:devfrom
msaustral:dev

Conversation

@msaustral

Copy link
Copy Markdown
Questions Answers
Description? We have add an option on the settings to hide products without stock, this solve the issue PrestaShop/PrestaShop#10018. Also when this option is enable, it disable the Availability filter, if the filter was enabled before activating the option "Hide out of stock", it deletes from table layered_category any availability type register to disable it
Type? improvement
BC breaks? no
Deprecations? no
Fixed ticket? PrestaShop/PrestaShop#10018
How to test? On the setting enable the option: "Hide out of stock"

image

@msaustral

Copy link
Copy Markdown
Author

also solve issue: PrestaShop/PrestaShop#16952

@Hlavtox

Hlavtox commented Feb 14, 2024

Copy link
Copy Markdown
Member

What's the purpose of this filter? You can just click "Available" in Availability filter and it will show you the exact same thing.

@msaustral

Copy link
Copy Markdown
Author

Hi, for example, on fashion industry, if a client filter T-shirt size M, you do not want products without stock on M to appear on the list.

Some industry do not want to show products without stock on the product list other do, that is why the function is optional.

If someone want to show products without stocks, it works as normal.

@gdoleczek

Copy link
Copy Markdown

Hi, what is the progress on this review.
It would be useful on our projects as well.

@boo-code

boo-code commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

The stock filter is dropped from getDefaultFilters() on every shop that upgrades, rather than only on shops that asked for it.

if (Configuration::get('PS_LAYERED_FILTER_HIDE_OUT_OF_STOCK') === '0'){

PS_LAYERED_FILTER_HIDE_OUT_OF_STOCK is created only in install(), and this PR adds no upgrade script, so a shop that already has the module installed has no row for it. Configuration::get() is declared get($key, $idLang = null, $idShopGroup = null, $idShop = null, $default = false) and ends with return $default; when hasKey() misses, so the call returns false, not '0'. false === '0' is false, so layered_selection_stock is never merged in and the Availability filter disappears from the filter templates screen — for merchants who never enabled the new setting.

Two things would close it:

  • compare on the value rather than its type and spelling. The same file already does this two methods down: 'hide_out_of_stock' => (bool) Configuration::get('PS_LAYERED_FILTER_HIDE_OUT_OF_STOCK') in renderAdminMain(). if (!Configuration::get('PS_LAYERED_FILTER_HIDE_OUT_OF_STOCK')) reads the same on a missing key and on a stored 0.
  • add the upgrade script that sets the default, next to the existing upgrade/upgrade-4.0.4.php, so the key exists on upgraded shops for the rest of the code that reads it.

Worth noting for whoever reviews the behaviour rather than the code: the DELETE FROM ps_layered_category WHERE type = "availability" in getContent() is not reversible from the UI. Turning the setting on and off again leaves the availability filter removed from every saved template, and it has to be re-added by hand.

@Hlavtox

Hlavtox commented Sep 2, 2026

Copy link
Copy Markdown
Member

Hello @msaustral, you can now implement your behavior easily via actionFacetedSearchFilters hook.

public function hookActionFacetedSearchFilters($params) {
  $params['search']->getSearchAdapter()->addOperationsFilter(
    'with_stock_management',
    [[['quantity', [0], '>']]]
  );
}

@Hlavtox Hlavtox closed this Sep 2, 2026
@github-project-automation github-project-automation Bot moved this from Ready for review to Closed in PR Dashboard Sep 2, 2026
@msaustral

Copy link
Copy Markdown
Author

Hi @Hlavtox the idea of opening this in 2024 (WOW), was to converted in a function that comes already with in the native module without need of building another module on top.

Just adding couple of lines you allow salers to have the control of showing or not productos or attributes out sock

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Closed

Development

Successfully merging this pull request may close these issues.

4 participants