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 static function codeAlreadyRedeemed(string $code): self |
24
|
|
|
{ |
25
|
|
|
return new self( |
26
|
|
|
Response::HTTP_BAD_REQUEST, |
27
|
|
|
self::PROMOTION_CODE_ALREADY_REDEEMED, |
28
|
|
|
'Promotion with code "{{ code }}" has already been marked as redeemed!', |
29
|
|
|
['code' => $code] |
30
|
|
|
); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public static function invalidCodePattern(string $codePattern): self |
34
|
|
|
{ |
35
|
|
|
return new self( |
36
|
|
|
Response::HTTP_BAD_REQUEST, |
37
|
|
|
self::INVALID_CODE_PATTERN, |
38
|
|
|
'Invalid code pattern "{{ codePattern }}".', |
39
|
|
|
['codePattern' => $codePattern] |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public static function patternNotComplexEnough(): self |
44
|
|
|
{ |
45
|
|
|
if (!Feature::isActive('v6.6.0.0')) { |
46
|
|
|
return new PatternNotComplexEnoughException(); |
|
|
|
|
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
return new self( |
50
|
|
|
Response::HTTP_BAD_REQUEST, |
51
|
|
|
self::PATTERN_NOT_COMPLEX_ENOUGH, |
52
|
|
|
'The amount of possible codes is too low for the current pattern. Make sure your pattern is sufficiently complex.' |
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public static function patternAlreadyInUse(): self |
57
|
|
|
{ |
58
|
|
|
if (!Feature::isActive('v6.6.0.0')) { |
59
|
|
|
return new PatternAlreadyInUseException(); |
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return new self( |
63
|
|
|
Response::HTTP_BAD_REQUEST, |
64
|
|
|
self::PATTERN_ALREADY_IN_USE, |
65
|
|
|
'Code pattern already exists in another promotion. Please provide a different pattern.' |
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|