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)