-
Notifications
You must be signed in to change notification settings - Fork 131
Description
Prerequisites
- I understand and accept the project's code of conduct.
- I have already searched in existing issues and found no previous report of this bug.
Describe the bug and add attachments
When indexing product prices, the method indexPrices() uses an incorrect loop condition comparing $cursor (last indexed id_product) against $nbProducts (total number of products to index).
Because product IDs may not be sequential and are frequently greater than the total number of products, the loop exits after the first iteration, preventing full indexation.
Expected behavior
Actual result
The loop stops because:
$cursor < $nbProducts
fails, since:
- $cursor is the last indexed product ID (example: 10391)
- $nbProducts is the number of products to index (example: 3525)
IDs are not sequential, therefore the check is invalid.
Expected result
The loop should continue until the number of indexed products reaches $nbProducts, not until $cursor is less than $nbProducts.
Problematic code
From indexPrices():
} while (
$cursor < $nbProducts
&& (Tools::getMemoryLimit() == -1 || Tools::getMemoryLimit() > memory_get_peak_usage())
&& $time_elapsed < $maxExecutiontime
);
Why this is a bug
$cursor is the last product ID returned from: indexPricesUnbreakable().
It is not a counter.
Therefore comparing it to the number of products makes the loop stop incorrectly.
Suggested fix
Replace
$cursor < $nbProducts
with:
$indexedProducts < $nbProducts
Since $indexedProducts already tracks real progress:
$indexedProducts += $length;
Steps to reproduce
- Install PrestaShop 8.x with ps_facetedsearch.
- Have more product IDs than active products (normal in real stores: deleted products, migrations, imports).
- Run price indexation with all products (full = true and default $length = 100).
- The indexation stops after the first batch.
PrestaShop version(s) where the bug happened
8.0.1
PHP version(s) where the bug happened
8.1.33
Your company or customer's name goes here (if applicable).
No response
Metadata
Metadata
Assignees
Labels
Type
Projects
Status