magento2 icon indicating copy to clipboard operation
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)

Open KrasnoshchokBohdan opened this issue 4 months ago • 3 comments

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 image

Related Pull Requests

Fixed Issues (if relevant)

  1. Fixes magento/magento2#39959

Manual testing scenarios (*)

  1. Create a custom module with an observer for catalog_product_save_before.
  2. Inside the observer, call $product->getFinalPrice().
  3. Save product from storeview scope from admin panel (check the video from issue description)
  4. Save a product using REST API: POST /rest/default/V1/products
  5. 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)

KrasnoshchokBohdan avatar Jun 17 '25 16:06 KrasnoshchokBohdan