Skip to content

Scheduled price rule time zone correction #28973

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Mar 18, 2021

Conversation

AntonEvers
Copy link
Contributor

@AntonEvers AntonEvers commented Jul 2, 2020

Description (*)

Apply the same logic for time zone correction on \Magento\CatalogRule\Model\Indexer\IndexBuilder::assignProductToRule as in \Magento\CatalogRule\Model\Indexer\ReindexRuleProduct::execute.

The problem here is that Magento 2.3 uses the method \Magento\CatalogRule\Model\Indexer\IndexBuilder::assignProductToRule. In Magento 2.4 this method is no longer used, but it is also not deprecated. So we can expect customers to use this method through the @api method \Magento\CatalogRule\Model\Indexer\IndexBuilder::reindexById. So even though the code in this PR is not used anywhere in vanilla M2.4, it is an @api method that could result in catalog rules starting and ending at wrong time which is equal to the configured timezone offset.

Applying this PR makes sure that time zones are applied equally in \Magento\CatalogRule\Model\Indexer\IndexBuilder::reindexById as they are in \Magento\CatalogRule\Model\Indexer\IndexBuilder::reindexByIds. Currently they differ.

Related Pull Requests

Fixed Issues (if relevant)

Manual testing scenarios (*)

  1. Set time zone to Europe/Amsterdam
  2. Set indexers to scheduled
  3. Deleta all present Catalog Price Rules
  4. Create a Catalog Price Rule for 50% off on all products, but disabled
  5. Schedule the price rule to be enabled at a minute or so in the future using catalog staging
  6. Wait until catalog stating rules are active and indexer is up to date
  7. Run this query: SELECT DISTINCT from_time, to_time FROM catalogrule_product;
  8. It should output only one row, after all, the rule is applied on all product at the same time.
  9. Install app.zip
  10. Run bin/magento reindex:product 10
  11. Run this query: SELECT DISTINCT from_time, to_time FROM catalogrule_product;
  12. Now you see two rows: one from before and one with a time offset 2 hours into the future. The Europe/Amsterdam timezone is not converted to UTC here. This is the issue.

Questions or comments

\Magento\CatalogRule\Model\Indexer\IndexBuilder::assignProductToRule and \Magento\CatalogRule\Model\Indexer\ReindexRuleProduct::execute do contain duplicate code. Maybe, after approving this PR, it would be worth while to deprecate or merge some of the methods.

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

Resolved issues:

  1. resolves [Issue] Scheduled price rule time zone correction #29549: Scheduled price rule time zone correction

@m2-assistant
Copy link

m2-assistant bot commented Jul 2, 2020

Hi @AntonEvers. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ 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:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests

You can find more information about the builds here

ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review.

For more details, please, review the Magento Contributor Guide documentation.

@AntonEvers
Copy link
Contributor Author

@magento run Unit Tests
@magento run Static Tests

@AntonEvers AntonEvers changed the title WIP Scheduled price rule time zone correction Scheduled price rule time zone correction Jul 3, 2020
@AntonEvers
Copy link
Contributor Author

@magento run all tests

1 similar comment
@AntonEvers
Copy link
Contributor Author

@magento run all tests

@AntonEvers
Copy link
Contributor Author

@magento run all tests

@sidolov
Copy link
Contributor

sidolov commented Aug 14, 2020

@magento create issue

@sidolov sidolov added Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. labels Aug 14, 2020
Copy link
Contributor

@sidolov sidolov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, cover your changes with any kind of automated tests.

$sortOrder = (int)$rule->getSortOrder();
$actionOperator = $rule->getSimpleAction();
$actionAmount = $rule->getDiscountAmount();
$actionStop = $rule->getStopRulesProcessing();

$rows = [];
foreach ($websiteIds as $websiteId) {
$scopeTz = new \DateTimeZone(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, use framework TimeZone and DateTime object instead of generic PHP.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed the entire method, as it appears to be duplicate code. Instead I have done this: https://github.com/magento/magento2/pull/28973/files#r474752002

}

$this->reindexRuleGroupWebsite->execute();
$this->doReindexByIds([$id]);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main change in this file, the rest is removal of unused private methods (containing also duplicate code) after this change and adding of imports.

@AntonEvers
Copy link
Contributor Author

@magento run all tests

@engcom-Charlie
Copy link
Contributor

Hi, @AntonEvers could you please merge conflict and cover changes with the automated tests?
Thank you.

@engcom-Foxtrot engcom-Foxtrot self-assigned this Sep 9, 2020
# Conflicts:
#	app/code/Magento/CatalogRule/Model/Indexer/IndexBuilder.php
@engcom-Foxtrot
Copy link
Contributor

@magento run all tests

@engcom-Foxtrot
Copy link
Contributor

@magento run all tests

@gabrieldagama
Copy link
Contributor

@magento run all tests

Copy link
Contributor

@engcom-Bravo engcom-Bravo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ QA Failed

Switched to the PR and Performed the steps from the Manual Testing scenario
After the last step, still, only one row is displayed in the SQL query
after

@engcom-Bravo
Copy link
Contributor

Further investigation discovered that the previous comment #28973 (review) is actually the Expected behavior

✔️ QA Passed

Manual testing scenario

  1. Set time zone to Europe/Amsterdam
  2. Set indexers to scheduled
  3. Deleta all present Catalog Price Rules
  4. Create a Catalog Price Rule for 50% off on all products, but disabled
  5. Schedule the price rule to be enabled at a minute or so in the future using catalog staging
  6. Wait until catalog stating rules are active and indexer is up to date
  7. Run this query: SELECT DISTINCT from_time, to_time FROM catalogrule_product;
  8. It should output only one row, after all, the rule is applied on all product at the same time.
  9. Install app.zip
  10. Run bin/magento reindex:product 10
  11. Run this query: SELECT DISTINCT from_time, to_time FROM catalogrule_product;

Actual Result
Only one row is displayed in the SQL query
after

@m2-assistant
Copy link

m2-assistant bot commented Mar 18, 2021

Hi @AntonEvers, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Component: CatalogRule Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: accept QA: Added to Regression Scope Scenario was analysed and added to Regression Testing Scope Release Line: 2.4 Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. Type: Bug Fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Issue] Scheduled price rule time zone correction
7 participants