-
Notifications
You must be signed in to change notification settings - Fork 9.4k
magento/magento2#39169: Special Price To Date is wrongly validated on applySpecialPrice #39690
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
KrasnoshchokBohdan
wants to merge
32
commits into
magento:2.4-develop
Choose a base branch
from
KrasnoshchokBohdan:fix-for-issue-39169
base: 2.4-develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+184
−10
Open
Changes from 29 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
9111182
magento/magento2#39169: Special Price To Date is wrongly validated on…
KrasnoshchokBohdan 364b4e5
Merge branch '2.4-develop' into fix-for-issue-39169
KrasnoshchokBohdan 2a9dec5
Merge branch '2.4-develop' into fix-for-issue-39169
engcom-Hotel 131815c
magento/magento2#39169: Special Price To Date is wrongly validated on…
KrasnoshchokBohdan 0d8b6b0
magento/magento2#39169: Special Price To Date is wrongly validated on…
KrasnoshchokBohdan c8c8b35
Merge branch '2.4-develop' into fix-for-issue-39169
KrasnoshchokBohdan e79e0fa
magento/magento2#39169: Special Price To Date is wrongly validated on…
KrasnoshchokBohdan 0e95cd4
magento/magento2#39169: Special Price To Date is wrongly validated on…
KrasnoshchokBohdan 1ce9b74
Merge branch '2.4-develop' into fix-for-issue-39169
KrasnoshchokBohdan a3fe48c
magento/magento2#39169: Special Price To Date is wrongly validated on…
KrasnoshchokBohdan 7f6699e
Merge branch '2.4-develop' into fix-for-issue-39169
KrasnoshchokBohdan 3a45985
Merge branch '2.4-develop' into fix-for-issue-39169
KrasnoshchokBohdan b42fab8
magento/magento2#39169: Special Price To Date is wrongly validated on…
KrasnoshchokBohdan 8ace126
magento/magento2#39169: Special Price To Date is wrongly validated on…
KrasnoshchokBohdan 58b3d98
magento/magento2#39169: Special Price To Date is wrongly validated on…
KrasnoshchokBohdan 5cbfdb6
Merge branch '2.4-develop' into fix-for-issue-39169
KrasnoshchokBohdan cf359ba
Merge branch '2.4-develop' into fix-for-issue-39169
KrasnoshchokBohdan 2cea5b6
magento/magento2#39169: Special Price To Date is wrongly validated on…
KrasnoshchokBohdan ed831bd
Merge branch '2.4-develop' into fix-for-issue-39169
KrasnoshchokBohdan 93c0caa
Merge branch '2.4-develop' into fix-for-issue-39169
KrasnoshchokBohdan 331dc74
magento/magento2#39146: Image resize queue error due to .tmp file han…
KrasnoshchokBohdan 9b27e4d
Merge branch '2.4-develop' into fix-for-issue-39169
KrasnoshchokBohdan fe976d7
magento/magento2#39169: Special Price To Date is wrongly validated on…
KrasnoshchokBohdan 188ece2
Merge branch '2.4-develop' into fix-for-issue-39169
KrasnoshchokBohdan 0a5d7f1
magento/magento2#39169: Special Price To Date is wrongly validated on…
KrasnoshchokBohdan 157c99a
Merge branch '2.4-develop' into fix-for-issue-39169
KrasnoshchokBohdan 706ee4c
Merge branch '2.4-develop' into fix-for-issue-39169
engcom-Hotel db809f1
magento/magento2#39169: Special Price To Date is wrongly validated on…
KrasnoshchokBohdan cff0ee8
Merge branch '2.4-develop' into fix-for-issue-39169
engcom-Hotel 18260e7
magento/magento2#39169: Special Price To Date is wrongly validated on…
KrasnoshchokBohdan 015fd43
magento/magento2#39169: Special Price To Date is wrongly validated on…
KrasnoshchokBohdan 8442ee0
Merge branch '2.4-develop' into fix-for-issue-39169
KrasnoshchokBohdan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
app/code/Magento/Catalog/Model/Pricing/SpecialPriceService.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
/** | ||
* Copyright 2025 Adobe | ||
* All Rights Reserved. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Catalog\Model\Pricing; | ||
|
||
/** | ||
* This class provides functionality to normalize the end date/time of special prices | ||
*/ | ||
class SpecialPriceService | ||
{ | ||
/** | ||
* This class subtracts one day from $dateTo if it contains a specific time (hours, minutes, seconds) | ||
* because \Magento\Framework\Stdlib\DateTime\Timezone::isScopeDateInInterval adds one day. | ||
* This ensures that the special price expires exactly at the specified time | ||
* | ||
* For example, | ||
* - If $dateTo is "2025-05-12 17:00:00", it will be converted to "2025-05-11 17:00:00" | ||
* - If $dateTo is "2024-05-12 00:00:00", it will remain unchanged | ||
* | ||
* @param mixed $dateTo | ||
* @return mixed|string | ||
*/ | ||
public function execute(mixed $dateTo): mixed | ||
{ | ||
if ($dateTo | ||
&& strtotime($dateTo) !== false | ||
&& date('H:i:s', strtotime($dateTo)) !== '00:00:00') { | ||
$dateToTimestamp = strtotime($dateTo); | ||
$dateTo = date('Y-m-d H:i:s', $dateToTimestamp - 86400); | ||
} | ||
|
||
return $dateTo; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
app/code/Magento/Catalog/Test/Unit/Service/SpecialPriceServiceTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
/** | ||
* Copyright 2025 Adobe | ||
* All Rights Reserved. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Catalog\Test\Unit\Service; | ||
|
||
use Magento\Catalog\Model\Pricing\SpecialPriceService; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Test for SpecialPriceService | ||
*/ | ||
class SpecialPriceServiceTest extends TestCase | ||
{ | ||
/** | ||
* @var SpecialPriceService | ||
*/ | ||
private SpecialPriceService $specialPriceService; | ||
|
||
/** | ||
* Set up a test environment | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
$this->specialPriceService = new SpecialPriceService(); | ||
} | ||
|
||
/** | ||
* Data provider for execute method test | ||
* | ||
* @return array | ||
*/ | ||
public static function executeDataProvider(): array | ||
{ | ||
return [ | ||
'invalid_date' => [ | ||
'dateTo' => 'some date to', | ||
'expected' => 'some date to' | ||
], | ||
'date_without_time' => [ | ||
'dateTo' => '2025-05-12 00:00:00', | ||
'expected' => '2025-05-12 00:00:00' | ||
], | ||
'date_with_specific_time' => [ | ||
'dateTo' => '2025-05-12 17:00:00', | ||
'expected' => '2025-05-11 17:00:00' | ||
] | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider executeDataProvider | ||
* @param mixed $dateTo | ||
* @param mixed $expected | ||
*/ | ||
public function testExecute(mixed $dateTo, mixed $expected): void | ||
{ | ||
$result = $this->specialPriceService->execute($dateTo); | ||
$this->assertEquals($expected, $result); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be private
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the comment, I would like to clarify, I use it in the child class \Magento\Bundle\Model\Product\Price so it is not private
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will require Core Team approval.
cc @engcom-Hotel
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @Den4ik,
Thanks for highlighting this point.
Hello @KrasnoshchokBohdan,
Is it possible to make it
private
and if access in subclasses is needed, expose a protected getter as below: