1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Shopware\Core\System\SalesChannel; |
4
|
|
|
|
5
|
|
|
use Shopware\Core\Checkout\Payment\Exception\UnknownPaymentMethodException; |
6
|
|
|
use Shopware\Core\Framework\HttpException; |
7
|
|
|
use Shopware\Core\Framework\Log\Package; |
8
|
|
|
use Shopware\Core\Framework\Routing\Exception\LanguageNotFoundException; |
9
|
|
|
use Shopware\Core\Framework\ShopwareHttpException; |
10
|
|
|
use Symfony\Component\HttpFoundation\Response; |
11
|
|
|
|
12
|
|
|
#[Package('system-settings')] |
13
|
|
|
class SalesChannelException extends HttpException |
14
|
|
|
{ |
15
|
|
|
final public const SALES_CHANNEL_DOES_NOT_EXISTS_EXCEPTION = 'SYSTEM__SALES_CHANNEL_DOES_NOT_EXISTS'; |
16
|
|
|
|
17
|
|
|
final public const LANGUAGE_INVALID_EXCEPTION = 'SYSTEM__LANGUAGE_INVALID_EXCEPTION'; |
18
|
|
|
|
19
|
|
|
final public const COUNTRY_DOES_NOT_EXISTS_EXCEPTION = 'SYSTEM__COUNTRY_DOES_NOT_EXISTS_EXCEPTION'; |
20
|
|
|
|
21
|
|
|
final public const CURRENCY_DOES_NOT_EXISTS_EXCEPTION = 'SYSTEM__CURRENCY_DOES_NOT_EXISTS_EXCEPTION'; |
22
|
|
|
|
23
|
|
|
final public const COUNTRY_STATE_DOES_NOT_EXISTS_EXCEPTION = 'SYSTEM__COUNTRY_STATE_DOES_NOT_EXISTS_EXCEPTION'; |
24
|
|
|
|
25
|
|
|
final public const SALES_CHANNEL_NOT_AVAILABLE_EXCEPTION = 'SYSTEM__SALES_CHANNEL_NOT_AVAILABLE_EXCEPTION'; |
26
|
|
|
|
27
|
|
|
final public const NO_CONTEXT_DATA_EXCEPTION = 'SYSTEM__NO_CONTEXT_DATA_EXCEPTION'; |
28
|
|
|
|
29
|
|
|
public static function salesChannelNotFound(string $salesChannelId): self |
30
|
|
|
{ |
31
|
|
|
return new self( |
32
|
|
|
Response::HTTP_NOT_FOUND, |
33
|
|
|
self::SALES_CHANNEL_DOES_NOT_EXISTS_EXCEPTION, |
34
|
|
|
'Sales channel with id "{{ salesChannelId }}" not found or not valid!.', |
35
|
|
|
['salesChannelId' => $salesChannelId] |
36
|
|
|
); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public static function currencyNotFound(string $currencyId): self |
40
|
|
|
{ |
41
|
|
|
return new self( |
42
|
|
|
Response::HTTP_NOT_FOUND, |
43
|
|
|
self::CURRENCY_DOES_NOT_EXISTS_EXCEPTION, |
44
|
|
|
'Currency with id "{{ currencyId }}" not found!.', |
45
|
|
|
['currencyId' => $currencyId] |
46
|
|
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public static function countryStateNotFound(string $countryStateId): self |
50
|
|
|
{ |
51
|
|
|
return new self( |
52
|
|
|
Response::HTTP_NOT_FOUND, |
53
|
|
|
self::COUNTRY_STATE_DOES_NOT_EXISTS_EXCEPTION, |
54
|
|
|
'Country state with id "{{ countryStateId }}" not found!.', |
55
|
|
|
['countryStateId' => $countryStateId] |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public static function countryNotFound(string $countryId): self |
60
|
|
|
{ |
61
|
|
|
return new self( |
62
|
|
|
Response::HTTP_NOT_FOUND, |
63
|
|
|
self::COUNTRY_DOES_NOT_EXISTS_EXCEPTION, |
64
|
|
|
'Country with id "{{ countryId }}" not found!.', |
65
|
|
|
['countryId' => $countryId] |
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public static function noContextData(string $salesChannelId): self |
70
|
|
|
{ |
71
|
|
|
return new self( |
72
|
|
|
Response::HTTP_PRECONDITION_FAILED, |
73
|
|
|
self::NO_CONTEXT_DATA_EXCEPTION, |
74
|
|
|
'No context data found for SalesChannel "{{ salesChannelId }}"', |
75
|
|
|
['salesChannelId' => $salesChannelId] |
76
|
|
|
); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public static function invalidLanguageId(): ShopwareHttpException |
80
|
|
|
{ |
81
|
|
|
return new self( |
82
|
|
|
Response::HTTP_PRECONDITION_FAILED, |
83
|
|
|
self::LANGUAGE_INVALID_EXCEPTION, |
84
|
|
|
'Provided languageId is not a valid uuid', |
85
|
|
|
); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public static function languageNotFound(string $languageId): ShopwareHttpException |
89
|
|
|
{ |
90
|
|
|
return new LanguageNotFoundException($languageId); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param array<string> $availableLanguages |
95
|
|
|
*/ |
96
|
|
|
public static function providedLanguageNotAvailable(string $languageId, array $availableLanguages): self |
97
|
|
|
{ |
98
|
|
|
return new self( |
99
|
|
|
Response::HTTP_PRECONDITION_FAILED, |
100
|
|
|
self::SALES_CHANNEL_NOT_AVAILABLE_EXCEPTION, |
101
|
|
|
sprintf('Provided language "%s" is not in list of available languages: %s', $languageId, implode(', ', $availableLanguages)), |
102
|
|
|
); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public static function unknownPaymentMethod(string $paymentMethodId): ShopwareHttpException |
106
|
|
|
{ |
107
|
|
|
return new UnknownPaymentMethodException($paymentMethodId); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|