|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Shopware\Core\Checkout\Promotion; |
|
4
|
|
|
|
|
5
|
|
|
use Shopware\Core\Checkout\Promotion\Exception\PatternAlreadyInUseException; |
|
6
|
|
|
use Shopware\Core\Checkout\Promotion\Exception\PatternNotComplexEnoughException; |
|
7
|
|
|
use Shopware\Core\Framework\Feature; |
|
8
|
|
|
use Shopware\Core\Framework\HttpException; |
|
9
|
|
|
use Shopware\Core\Framework\Log\Package; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
11
|
|
|
|
|
12
|
|
|
#[Package('checkout')] |
|
13
|
|
|
class PromotionException extends HttpException |
|
14
|
|
|
{ |
|
15
|
|
|
public const PROMOTION_CODE_ALREADY_REDEEMED = 'CHECKOUT__CODE_ALREADY_REDEEMED'; |
|
16
|
|
|
|
|
17
|
|
|
public const INVALID_CODE_PATTERN = 'CHECKOUT__INVALID_CODE_PATTERN'; |
|
18
|
|
|
|
|
19
|
|
|
public const PATTERN_NOT_COMPLEX_ENOUGH = 'PROMOTION__INDIVIDUAL_CODES_PATTERN_INSUFFICIENTLY_COMPLEX'; |
|
20
|
|
|
|
|
21
|
|
|
public const PATTERN_ALREADY_IN_USE = 'PROMOTION__INDIVIDUAL_CODES_PATTERN_ALREADY_IN_USE'; |
|
22
|
|
|
|
|
23
|
|
|
public const PROMOTION_NOT_FOUND = 'CHECKOUT__PROMOTION__NOT_FOUND'; |
|
24
|
|
|
|
|
25
|
|
|
public const PROMOTION_DISCOUNT_NOT_FOUND = 'CHECKOUT__PROMOTION_DISCOUNT_NOT_FOUND'; |
|
26
|
|
|
|
|
27
|
|
|
public static function codeAlreadyRedeemed(string $code): self |
|
28
|
|
|
{ |
|
29
|
|
|
return new self( |
|
30
|
|
|
Response::HTTP_BAD_REQUEST, |
|
31
|
|
|
self::PROMOTION_CODE_ALREADY_REDEEMED, |
|
32
|
|
|
'Promotion with code "{{ code }}" has already been marked as redeemed!', |
|
33
|
|
|
['code' => $code] |
|
34
|
|
|
); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public static function invalidCodePattern(string $codePattern): self |
|
38
|
|
|
{ |
|
39
|
|
|
return new self( |
|
40
|
|
|
Response::HTTP_BAD_REQUEST, |
|
41
|
|
|
self::INVALID_CODE_PATTERN, |
|
42
|
|
|
'Invalid code pattern "{{ codePattern }}".', |
|
43
|
|
|
['codePattern' => $codePattern] |
|
44
|
|
|
); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public static function patternNotComplexEnough(): self |
|
48
|
|
|
{ |
|
49
|
|
|
if (!Feature::isActive('v6.6.0.0')) { |
|
50
|
|
|
return new PatternNotComplexEnoughException(); |
|
|
|
|
|
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
return new self( |
|
54
|
|
|
Response::HTTP_BAD_REQUEST, |
|
55
|
|
|
self::PATTERN_NOT_COMPLEX_ENOUGH, |
|
56
|
|
|
'The amount of possible codes is too low for the current pattern. Make sure your pattern is sufficiently complex.' |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public static function patternAlreadyInUse(): self |
|
61
|
|
|
{ |
|
62
|
|
|
if (!Feature::isActive('v6.6.0.0')) { |
|
63
|
|
|
return new PatternAlreadyInUseException(); |
|
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return new self( |
|
67
|
|
|
Response::HTTP_BAD_REQUEST, |
|
68
|
|
|
self::PATTERN_ALREADY_IN_USE, |
|
69
|
|
|
'Code pattern already exists in another promotion. Please provide a different pattern.' |
|
70
|
|
|
); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @param string[] $ids |
|
75
|
|
|
*/ |
|
76
|
|
|
public static function promotionsNotFound(array $ids): self |
|
77
|
|
|
{ |
|
78
|
|
|
return new self( |
|
79
|
|
|
Response::HTTP_NOT_FOUND, |
|
80
|
|
|
self::PROMOTION_NOT_FOUND, |
|
81
|
|
|
'These promotions "{{ ids }}" are not found', |
|
82
|
|
|
['ids' => implode(', ', $ids)] |
|
83
|
|
|
); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @param string[] $ids |
|
88
|
|
|
*/ |
|
89
|
|
|
public static function discountsNotFound(array $ids): self |
|
90
|
|
|
{ |
|
91
|
|
|
return new self( |
|
92
|
|
|
Response::HTTP_NOT_FOUND, |
|
93
|
|
|
self::PROMOTION_DISCOUNT_NOT_FOUND, |
|
94
|
|
|
'These promotion discounts "{{ ids }}" are not found', |
|
95
|
|
|
['ids' => implode(', ', $ids)] |
|
96
|
|
|
); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|