fix: apply price post-filtering before counting and pagination - #1281
Open
florianthomi wants to merge 1 commit into
Open
fix: apply price post-filtering before counting and pagination#1281florianthomi wants to merge 1 commit into
florianthomi wants to merge 1 commit into
Conversation
The price post-filter recomputes each product's real price for the current customer group and drops the ones outside the requested range. It ran after array_slice(), so the total and page count kept their pre-filter values and a whole page could end up empty while the listing announced dozens of results. Applying it to the full result list keeps the count, the pagination and the rendered products consistent.
|
Hello @florianthomi! This is your first pull request on ps_facetedsearch repository of the PrestaShop project. Thank you, and welcome to this Open Source community! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The price post-filter recomputes each product's real price for the current customer group and drops the ones outside the requested range. It ran after array_slice(), so the total and page count kept their pre-filter values and a whole page could end up empty while the listing announced dozens of results.
Applying it to the full result list keeps the count, the pagination and the rendered products consistent.
dev.Problem
Products::getProductByFilters()builds the result list in this order:ps_layered_price_index, which stores, per product, the envelope of prices across all customer groups and specific prices;count(): the total shown to the customer;array_slice(): the current page;pricePostFiltering(): recomputes each product's real price for the current customer group viaProduct::getPriceStatic()and drops the ones outside the requested range.Step 4 only ever sees the current page, and it runs after the count. So the total and the page count keep their pre-filter values while the grid is silently shortened. On a shop where several groups have a discount, the indexed envelope is much wider than any single visitor's real price, and a whole page can be emptied: the listing announces "62 results / 6 pages" and renders nothing.
The same slice is also used to decide what page 2 contains, so products dropped on page 1 are never shown at all, they are not pushed to the next page.
Fix
Apply the post-filter to the full result list, before counting and slicing.
How to test
ps_facetedsearchenabled with a price filter on a category.ps_facetedsearch-price-indexer.php).Before: the header announces a large number of results across several pages, while the grid shows few or no products; summing the products across all pages never reaches the announced total.
After: the announced total equals the number of products actually reachable across the pages, every page is full except the last, and no product appears twice or goes missing.
Trade-off
Product::getPriceStatic()now runs for every product whose indexed range straddles a filter bound, instead of only those on the current page. It is only reached when a price filter is active, only for straddling products, andgetPriceStatic()has a static cache, but on a large catalogue with wide group discounts this is more work per request than before. It seemed preferable to a listing that reports numbers it cannot deliver.