Skip to content

Commit 3c3000c

Browse files
committed
extract endpoints for capacity All, fix a return type for filters on All capacity file
1 parent ca7e08f commit 3c3000c

File tree

2 files changed

+97
-12
lines changed

2 files changed

+97
-12
lines changed

src/Builder/Search.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99

1010
final class Search implements Builder
1111
{
12-
public function __construct(private array $filters = [])
13-
{
14-
}
12+
public function __construct(
13+
private array $filters = []
14+
) {}
1515

1616
public function addFilter(
1717
Node\Expr $field,
1818
Node\Expr $operator,
1919
Node\Expr $value = null,
20-
?Node\Expr $scope = null,
21-
?Node\Expr $locale = null
20+
Node\Expr $scope = null,
21+
Node\Expr $locale = null
2222
): self {
2323
$arguments = [
2424
new Node\Arg(
@@ -28,7 +28,7 @@ public function addFilter(
2828
value: $operator,
2929
),
3030
new Node\Arg(
31-
value: $value,
31+
value: $value ?? new Node\Expr\ConstFetch(new Node\Name('null')),
3232
),
3333
];
3434

@@ -41,7 +41,7 @@ public function addFilter(
4141
}
4242
if (null !== $locale) {
4343
$options[] = new Node\Expr\ArrayItem(
44-
value: $scope,
44+
value: $locale,
4545
key: new Node\Scalar\String_('locale'),
4646
);
4747
}
@@ -60,7 +60,7 @@ public function addFilter(
6060
return $this;
6161
}
6262

63-
public function getNode(): Node
63+
public function getNode(): Node\Expr
6464
{
6565
$instance = new Node\Expr\New_(
6666
class: new Node\Name\FullyQualified(\Diglin\Sylius\ApiClient\Search\SearchBuilder::class)

src/Capacity/All.php

Lines changed: 89 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
final class All implements CapacityInterface
1515
{
16-
private static array $endpoints = [
16+
private static array $endpointsLegacy = [
1717
// Simple resources Endpoints
1818
'channels',
1919
'countries',
@@ -41,26 +41,111 @@ final class All implements CapacityInterface
4141
'zones',
4242
];
4343

44-
private static array $doubleEndpoints = [
44+
private static array $endpointsAdmin = [
45+
// Simple Ressource Endpoints
46+
'adjustment',
47+
'administrator',
48+
'catalogPromotion',
49+
'channel',
50+
'country',
51+
'currency',
52+
'customerGroup',
53+
'exchangeRate',
54+
'locale',
55+
'order',
56+
'payment',
57+
'product',
58+
'productAssociationType',
59+
'productImage',
60+
'productOption',
61+
'productOptionValue',
62+
'productReview',
63+
'productTaxon',
64+
'productVariant',
65+
'promotion',
66+
'province',
67+
'shipment',
68+
'shippingCategory',
69+
'shippingMethod',
70+
'ShopBillingData',
71+
'taxCategory',
72+
'taxon',
73+
'taxonTranslation',
74+
'zone',
75+
'zoneMember',
76+
];
77+
78+
private static array $endpointsShop = [
79+
// Simple Ressource Endpoints
80+
'address',
81+
'adjustment',
82+
'country',
83+
'currency',
84+
'locale',
85+
'order',
86+
'orderItem',
87+
'payment',
88+
'paymentMethod',
89+
'product',
90+
'productReview',
91+
'productVariant',
92+
'shipment',
93+
'shippingMethod',
94+
'taxon',
95+
];
96+
97+
private static array $doubleEndpointsLegacy = [
4598
// Double resources Endpoints
4699
'productReviews',
47100
'productVariants',
48101
'promotionCoupons',
49102
];
50103

104+
private static array $doubleEndpointsAdmin = [
105+
// Double resources Endpoints
106+
'adjustment',
107+
'province',
108+
'shopBillingData',
109+
'zoneMember',
110+
];
111+
112+
private static array $doubleEndpointsShop = [
113+
// Double resources Endpoints
114+
'adjustment',
115+
'order',
116+
];
117+
51118
public function __construct(private readonly ExpressionLanguage $interpreter)
52119
{
53120
}
54121

55122
public function applies(array $config): bool
56123
{
124+
switch($config['api_type']) {
125+
case 'admin':
126+
$endpoints = self::$endpointsAdmin;
127+
$doubleEndpoints = self::$doubleEndpointsAdmin;
128+
break;
129+
case 'shop':
130+
$endpoints = self::$endpointsShop;
131+
$doubleEndpoints = self::$doubleEndpointsShop;
132+
break;
133+
case 'legacy':
134+
$endpoints = self::$endpointsLegacy;
135+
$doubleEndpoints = self::$doubleEndpointsLegacy;
136+
break;
137+
default:
138+
$endpoints = [];
139+
$doubleEndpoints = [];
140+
break;
141+
}
57142
return isset($config['type'])
58-
&& (\in_array($config['type'], self::$endpoints) || \in_array($config['type'], self::$doubleEndpoints))
143+
&& (\in_array($config['type'], $endpoints) || \in_array($config['type'], $doubleEndpoints))
59144
&& isset($config['method'])
60145
&& 'all' === $config['method'];
61146
}
62147

63-
private function compileFilters(array ...$filters): Node
148+
private function compileFilters(array ...$filters): Node\Expr
64149
{
65150
$builder = new Sylius\Builder\Search();
66151
foreach ($filters as $filter) {

0 commit comments

Comments
 (0)