magento2
magento2 copied to clipboard
magento/magento2#39959 catalog_product_save_before observer throws date-related error when using REST API without store-level values (getFinalPrice() issue)
Adjusted the processing of SpecialFromDate to ensure proper formatting when the date is provided as a DateTimeInterface instance. This prevents errors arising during getFinalPrice() execution under certain scenarios.
Description (*)
I focused on investigation error
TypeError: strtotime(): Argument #1 ($datetime) must be of type string, DateTime given in lib/internal/Magento/Framework/Stdlib/DateTime/Timezone.php:275
the reason for it must be
\Magento\Catalog\Observer\SetSpecialPriceStartDate::execute
Related Pull Requests
Fixed Issues (if relevant)
- Fixes magento/magento2#39959
Manual testing scenarios (*)
- Create a custom module with an observer for catalog_product_save_before.
- Inside the observer, call $product->getFinalPrice().
- Save product from storeview scope from admin panel (check the video from issue description)
- Save a product using REST API: POST /rest/default/V1/products
- Use the following JSON payload (no store-level pricing):
payload
{
"product": {
"sku": "testing-special-date",
"price": 120,
"status": 0,
"visibility": 4,
"type_id": "simple",
"extension_attributes": {
"stock_item": {
"stock_id": 1,
"qty": 207,
"is_in_stock": true
}
},
"custom_attributes": [
{
"attribute_code": "tax_class_id",
"value": "2"
},
{
"attribute_code": "special_price",
"value": "100.00"
}
]
},
"saveOptions": true
}
Questions or comments
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)
- [ ] README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
- [ ] All automated tests passed successfully (all builds are green)
Hi @KrasnoshchokBohdan. 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 CompareFunctional Tests CEFunctional Tests EEFunctional Tests B2BIntegration TestsMagento Health IndexSample Data Tests CESample Data Tests EESample Data Tests B2BStatic TestsUnit TestsWebAPI TestsSemantic 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 run all tests
@magento run all tests
@magento run all tests
@magento run Unit Tests
@magento run all tests
@magento run Integration Tests, Unit Tests, Static Tests
@magento run all tests
@magento run Integration Tests
Hello @engcom-Hotel The review comments have been addressed by @KrasnoshchokBohdan hence moving this PR for review.
Thanks!
@magento run Functional Tests B2B, Functional Tests CE
@magento run all tests
@KrasnoshchokBohdan Thank you for the contribution & collaboration.
✔️ QA Passed
Preconditions:
- Install fresh 2.4-develop
Steps to reproduce:
-
Create a custom module and add observer for event "catalog_product_save_before". In the Observer call
$product->getFinalPrice() -
Save product from storeview scope keeping 'Use Default Value' checkbox checked for 'Special Price From' field.
-
Save a product using REST API: POST /rest/default/V1/products. Use payload given in the description.
Before: ❌
An exception caught in the exception.log.Also we were not able to get the value of Final Price.
After: ✔️
The builds are failing hence moving this PR in Extended Testing.
@magento run Functional Tests B2B, Functional Tests EE, Integration Tests
@magento run all tests
@magento run Functional Tests B2B, Functional Tests CE, Functional Tests EE
The Functional B2B Tests failure are inconsistent and flaky. They neither part of PR nor failing because of the PR changes.
Build 1: https://public-results-storage-prod.magento-testing-service.engineering/reports/magento/magento2/pull/40003/b05d0e7fd25ea4c186d590b5b1db626f/Functional/allure-report-b2b/index.html#categories/bdbf199525818fae7a8651db9eafe741
Build 2: https://public-results-storage-prod.magento-testing-service.engineering/reports/magento/magento2/pull/40003/e1e4450bfa89915989e0974b59151eb8/Functional/allure-report-b2b/index.html#categories/8fb3a91ba5aaf9de24cc8a92edc82b5d
The Functional CE Tests failure are inconsistent and flaky. They neither part of PR nor failing because of the PR changes.
Build 1: https://public-results-storage-prod.magento-testing-service.engineering/reports/magento/magento2/pull/40003/fc984899a5304299bcac49c15d727c34/Functional/allure-report-ce/index.html#categories/bdbf199525818fae7a8651db9eafe741
Build 2: https://public-results-storage-prod.magento-testing-service.engineering/reports/magento/magento2/pull/40003/37a17ebce7468af014a4c45bf48c3262/Functional/allure-report-ce/#categories/8fb3a91ba5aaf9de24cc8a92edc82b5d
Hence moving this PR in Merge In Progress.