Skip to content

Commit 7cac36e

Browse files
#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.
1 parent ceaafc0 commit 7cac36e

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

app/code/Magento/Catalog/Model/Product/Type/Price.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -451,16 +451,10 @@ protected function _getCustomerGroupId($product)
451451
*/
452452
protected function _applySpecialPrice($product, $finalPrice)
453453
{
454-
455-
$specialPriceFrom = $product->getSpecialFromDate();
456-
if ($specialPriceFrom instanceof \DateTimeInterface) {
457-
$specialPriceFrom = $specialPriceFrom->format('Y-m-d H:i:s');
458-
}
459-
460454
return $this->calculateSpecialPrice(
461455
$finalPrice,
462456
$product->getSpecialPrice(),
463-
$specialPriceFrom,
457+
$product->getSpecialFromDate(),
464458
$product->getSpecialToDate(),
465459
WebsiteInterface::ADMIN_CODE
466460
);

app/code/Magento/Catalog/Observer/SetSpecialPriceStartDate.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public function execute(\Magento\Framework\Event\Observer $observer)
3939
/** @var $product \Magento\Catalog\Model\Product */
4040
$product = $observer->getEvent()->getProduct();
4141
if ($product->getSpecialPrice() && $product->getSpecialFromDate() === null) {
42-
$product->setData('special_from_date', $this->localeDate->date()->setTime(0, 0));
42+
$product->setData('special_from_date',
43+
$this->localeDate->date()->setTime(0, 0)->format('Y-m-d H:i:s'));
4344
}
4445
return $this;
4546
}

0 commit comments

Comments
 (0)