Skip to content

[Issue] Fixed catalog rule price processing when only website-scoped prices are used. #40370

@m2-assistant

Description

@m2-assistant

This issue is automatically created based on existing pull request: #40358: 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:

  1. Removal of Unnecessary Join: The explicit JOIN to the default price table (pp_default with store_id = 0) has been removed from the product selection query. This join was causing issues when the default price entries were absent.
  2. Default Value Handling: The logic for the default_price column is updated to use SQL's COALESCE or IFNULL equivalent to return 0 if 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)

  1. Fixes magento/magento2#<issue_number>
    ...

Manual testing scenarios (*)

  1. 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 = 0 in the catalog_product_entity_decimal table.
  2. 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.
  3. 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)

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Ready for Confirmation

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions