1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved. |
5
|
|
|
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Spryker\Zed\Discount\Business\Validator\ConstraintProvider; |
9
|
|
|
|
10
|
|
|
use Generated\Shared\Transfer\DiscountGeneralTransfer; |
11
|
|
|
use Spryker\Zed\Discount\DiscountConfig; |
12
|
|
|
use Symfony\Component\Validator\Constraints\DateTime; |
13
|
|
|
use Symfony\Component\Validator\Constraints\GreaterThan; |
14
|
|
|
use Symfony\Component\Validator\Constraints\LessThan; |
15
|
|
|
|
16
|
|
|
class DiscountConfiguratorPeriodConstraintProvider implements DiscountConfiguratorConstraintProviderInterface |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @param \Spryker\Zed\Discount\DiscountConfig $discountConfig |
20
|
|
|
*/ |
21
|
|
|
public function __construct(protected DiscountConfig $discountConfig) |
22
|
|
|
{ |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected const ERROR_MESSAGE = 'The discount cannot end before the starting date.'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected const ERROR_MESSAGE_MAX_ALLOWED_DATE = 'Date cannot be later than {{ compared_value }}'; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @return array<string, array<\Symfony\Component\Validator\Constraint>> |
37
|
|
|
*/ |
38
|
|
|
public function getConstraints(): array |
39
|
|
|
{ |
40
|
|
|
return [ |
41
|
|
|
DiscountGeneralTransfer::VALID_FROM => [ |
42
|
|
|
new DateTime(), |
43
|
|
|
new LessThan([ |
44
|
|
|
'value' => $this->discountConfig->getMaxAllowedDatetime(), |
45
|
|
|
'message' => static::ERROR_MESSAGE_MAX_ALLOWED_DATE, |
46
|
|
|
]), |
47
|
|
|
], |
48
|
|
|
DiscountGeneralTransfer::VALID_TO => [ |
49
|
|
|
new DateTime(), |
50
|
|
|
new GreaterThan([ |
51
|
|
|
'propertyPath' => DiscountGeneralTransfer::VALID_FROM, |
52
|
|
|
'message' => static::ERROR_MESSAGE, |
53
|
|
|
]), |
54
|
|
|
new LessThan([ |
55
|
|
|
'value' => $this->discountConfig->getMaxAllowedDatetime(), |
56
|
|
|
'message' => static::ERROR_MESSAGE_MAX_ALLOWED_DATE, |
57
|
|
|
]), |
58
|
|
|
], |
59
|
|
|
]; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|