Fixed catalog rule price processing when only website-scoped prices are used.
Description (*)
This Pull Request resolves an issue in the SQL query generated by Model/Indexer/RuleProductsSelectBuilder.php during catalog price rule indexing. The issue specifically occurs in environments where product prices are managed exclusively at the Website scope, meaning no price entries exist for store_id = 0 (Global/Default Store View) in the database.
The changes include:
-
Removal of Unnecessary Join: The explicit
JOINto the default price table (pp_defaultwithstore_id = 0) has been removed from the product selection query. This join was causing issues when the default price entries were absent. -
Default Value Handling: The logic for the
default_pricecolumn is updated to use SQL'sCOALESCEorIFNULLequivalent to return0if the website-specific price ($tableAlias.value) is not found. This prevents SQL errors related to missing joined records.
This ensures the price rule indexing mechanism correctly handles scenarios where price attribute scope is set to "Website" and the global default price is non-existent.
Related Pull Requests
...
Fixed Issues (if relevant)
- Fixes magento/magento2#<issue_number> ...
Manual testing scenarios (*)
-
Data Preparation:
- Ensure the 'Price' attribute scope is set to "Website".
- Create a new product and set its price only at the Website scope (e.g., $10.00 for Website A).
- Verify that no price entry exists for this product with
store_id = 0in thecatalog_product_entity_decimaltable.
-
Verify Issue Reproduction (Before Fix):
- Attempt to run a full catalog rule reindex:
bin/magento indexer:reindex catalogrule_rule. - Expected Result: Indexing fails or produces incorrect data due to the missing join result.
- Attempt to run a full catalog rule reindex:
-
Verify Fix:
- Apply the changes from this PR.
- Run the catalog rule price reindex again:
bin/magento indexer:reindex catalogrule_rule. - Expected Result: Indexing completes successfully without errors.
Questions or comments
Given the price attribute scope is "Website", the change sets default_price to 0 when no website-specific price is found. Please confirm if setting this value to 0 (instead of attempting to fetch a Global/Default Store value) is acceptable within the indexing context.
Contribution checklist (*)
- [x] Pull request has a meaningful description of its purpose - [x] All commits are accompanied by meaningful commit messages - [ ] All new or changed code is covered with unit/integration tests (if applicable) - [ ] README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update - [x] All automated tests passed successfully (all builds are green)
Hi @mtytula. Thank you for your contribution! Here are some useful tips on how you can test your changes using Magento test environment. :exclamation: Automated tests can be triggered manually with an appropriate comment:
-
@magento run all tests- run or re-run all required tests against the PR changes -
@magento run <test-build(s)>- run or re-run specific test build(s) For example:@magento run Unit Tests
<test-build(s)> is a comma-separated list of build names.
Allowed build names are:
-
Database Compare -
Functional Tests CE -
Functional Tests EE -
Functional Tests B2B -
Integration Tests -
Magento Health Index -
Sample Data Tests CE -
Sample Data Tests EE -
Sample Data Tests B2B -
Static Tests -
Unit Tests -
WebAPI Tests -
Semantic Version Checker
You can find more information about the builds here :information_source: Run only required test builds during development. Run all test builds before sending your pull request for review.
For more details, review the Code Contributions documentation. Join Magento Community Engineering Slack and ask your questions in #github channel.
@magento create issue