From 7274ed19c2520ce1746cbbbc7043ffcf2bcf4c61 Mon Sep 17 00:00:00 2001 From: KrasnoshchokBohdan Date: Tue, 17 Jun 2025 19:25:32 +0300 Subject: [PATCH 1/3] 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. --- app/code/Magento/Catalog/Model/Product/Type/Price.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Model/Product/Type/Price.php b/app/code/Magento/Catalog/Model/Product/Type/Price.php index 091e623e7bc29..29a6457650d12 100644 --- a/app/code/Magento/Catalog/Model/Product/Type/Price.php +++ b/app/code/Magento/Catalog/Model/Product/Type/Price.php @@ -451,10 +451,16 @@ protected function _getCustomerGroupId($product) */ protected function _applySpecialPrice($product, $finalPrice) { + + $specialPriceFrom = $product->getSpecialFromDate(); + if ($specialPriceFrom instanceof \DateTimeInterface) { + $specialPriceFrom = $specialPriceFrom->format('Y-m-d H:i:s'); + } + return $this->calculateSpecialPrice( $finalPrice, $product->getSpecialPrice(), - $product->getSpecialFromDate(), + $specialPriceFrom, $product->getSpecialToDate(), WebsiteInterface::ADMIN_CODE ); From 7cac36eb5fc0a719231ec9dfaef7ef35abc496bf Mon Sep 17 00:00:00 2001 From: KrasnoshchokBohdan Date: Thu, 19 Jun 2025 17:13:13 +0300 Subject: [PATCH 2/3] magento/magento2#39959 catalog_product_save_before observer throws date-related error when using REST API without store-level values (getFinalPrice() issue) Updated special price logic to ensure date formats are handled consistently when calculating and setting the "special from" date. This improves compatibility and prevents potential type issues with date-related operations. --- app/code/Magento/Catalog/Model/Product/Type/Price.php | 8 +------- .../Magento/Catalog/Observer/SetSpecialPriceStartDate.php | 3 ++- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product/Type/Price.php b/app/code/Magento/Catalog/Model/Product/Type/Price.php index f420687dd6052..d9d5d748ce4cc 100644 --- a/app/code/Magento/Catalog/Model/Product/Type/Price.php +++ b/app/code/Magento/Catalog/Model/Product/Type/Price.php @@ -451,16 +451,10 @@ protected function _getCustomerGroupId($product) */ protected function _applySpecialPrice($product, $finalPrice) { - - $specialPriceFrom = $product->getSpecialFromDate(); - if ($specialPriceFrom instanceof \DateTimeInterface) { - $specialPriceFrom = $specialPriceFrom->format('Y-m-d H:i:s'); - } - return $this->calculateSpecialPrice( $finalPrice, $product->getSpecialPrice(), - $specialPriceFrom, + $product->getSpecialFromDate(), $product->getSpecialToDate(), WebsiteInterface::ADMIN_CODE ); diff --git a/app/code/Magento/Catalog/Observer/SetSpecialPriceStartDate.php b/app/code/Magento/Catalog/Observer/SetSpecialPriceStartDate.php index 280357069f967..20e0d76b967ac 100644 --- a/app/code/Magento/Catalog/Observer/SetSpecialPriceStartDate.php +++ b/app/code/Magento/Catalog/Observer/SetSpecialPriceStartDate.php @@ -39,7 +39,8 @@ public function execute(\Magento\Framework\Event\Observer $observer) /** @var $product \Magento\Catalog\Model\Product */ $product = $observer->getEvent()->getProduct(); if ($product->getSpecialPrice() && $product->getSpecialFromDate() === null) { - $product->setData('special_from_date', $this->localeDate->date()->setTime(0, 0)); + $product->setData('special_from_date', + $this->localeDate->date()->setTime(0, 0)->format('Y-m-d H:i:s')); } return $this; } From c4210d544a6cf6352a48d97cf877fc2be0327495 Mon Sep 17 00:00:00 2001 From: KrasnoshchokBohdan Date: Mon, 23 Jun 2025 09:34:57 +0300 Subject: [PATCH 3/3] magento/magento2#39959 catalog_product_save_before observer throws date-related error when using REST API without store-level values (getFinalPrice() issue) - fix static test errors --- .../Magento/Catalog/Observer/SetSpecialPriceStartDate.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Catalog/Observer/SetSpecialPriceStartDate.php b/app/code/Magento/Catalog/Observer/SetSpecialPriceStartDate.php index 20e0d76b967ac..1a553c0508895 100644 --- a/app/code/Magento/Catalog/Observer/SetSpecialPriceStartDate.php +++ b/app/code/Magento/Catalog/Observer/SetSpecialPriceStartDate.php @@ -39,8 +39,10 @@ public function execute(\Magento\Framework\Event\Observer $observer) /** @var $product \Magento\Catalog\Model\Product */ $product = $observer->getEvent()->getProduct(); if ($product->getSpecialPrice() && $product->getSpecialFromDate() === null) { - $product->setData('special_from_date', - $this->localeDate->date()->setTime(0, 0)->format('Y-m-d H:i:s')); + $product->setData( + 'special_from_date', + $this->localeDate->date()->setTime(0, 0)->format('Y-m-d H:i:s') + ); } return $this; }