1313
1414namespace MonsieurBiz \SyliusNoCommercePlugin \Kernel ;
1515
16+ use Exception ;
1617use MonsieurBiz \SyliusNoCommercePlugin \Model \Config ;
1718use MonsieurBiz \SyliusNoCommercePlugin \Model \ConfigInterface ;
19+ use MonsieurBiz \SyliusNoCommercePlugin \Provider \FeaturesProviderInterface ;
1820use Symfony \Bundle \FrameworkBundle \Kernel \MicroKernelTrait ;
1921use Symfony \Component \Config \Loader \LoaderInterface ;
2022use Symfony \Component \Routing \RouteCollection ;
@@ -25,186 +27,6 @@ trait SyliusNoCommerceKernelTrait
2527 MicroKernelTrait::loadRoutes as parentLoadRoutes;
2628 }
2729
28- private array $ routesToRemove = [
29- // Customers & Account & Users
30- 'customer ' => [
31- 'sylius_admin_partial_customer ' ,
32- 'sylius_admin_customer ' ,
33- 'api_customer ' ,
34- 'sylius_shop_log ' ,
35- 'sylius_shop_register ' ,
36- 'sylius_shop_request_password_reset_token ' ,
37- 'sylius_shop_password_reset ' ,
38- 'sylius_shop_user_request_verification_token ' ,
39- 'sylius_shop_user_verification ' ,
40- 'sylius_shop_account ' ,
41- 'api_register_shop_users_post_collection ' ,
42- 'sylius_api_shop_authentication_token ' ,
43- 'sylius_shop_ajax_user_check_action ' ,
44- ],
45-
46- // Products
47- 'product ' => [
48- 'sylius_admin_product ' ,
49- 'sylius_admin_api_product ' ,
50- 'sylius_admin_ajax_product ' ,
51- 'sylius_shop_partial_product ' ,
52- 'sylius_shop_product ' ,
53- 'sylius_admin_partial_product ' ,
54- 'sylius_admin_ajax_generate_product_slug ' ,
55- 'api_product ' ,
56- ],
57-
58- // Taxons
59- 'taxon ' => [
60- 'sylius_admin_partial_taxon ' ,
61- 'sylius_admin_ajax_taxon ' ,
62- 'sylius_admin_taxon ' ,
63- 'sylius_admin_api_taxon ' ,
64- 'sylius_shop_partial_taxon ' ,
65- 'sylius_admin_ajax_generate_taxon_slug ' ,
66- 'sylius_shop_partial_channel_menu_taxon_index ' ,
67- 'api_taxon ' ,
68- ],
69-
70- // Checkout
71- 'checkout ' => [
72- 'sylius_admin_api_checkout ' ,
73- 'sylius_shop_checkout ' ,
74- 'sylius_shop_register_after_checkout ' ,
75- ],
76-
77- // Addresses
78- 'address ' => [
79- 'sylius_shop_account_address ' ,
80- 'sylius_admin_partial_address ' ,
81- ],
82-
83- // Orders
84- 'order ' => [
85- 'sylius_admin_order ' ,
86- 'sylius_admin_api_order ' ,
87- 'sylius_shop_account_order ' ,
88- 'sylius_shop_order ' ,
89- 'sylius_admin_partial_order ' ,
90- 'sylius_admin_customer_order ' ,
91- 'sylius_admin_api_customer_order ' ,
92- 'api_order ' ,
93- ],
94-
95- // Adjustments
96- 'adjustment ' => [
97- 'sylius_admin_api_adjustment ' ,
98- 'sylius_shop_ajax_render_province_form ' ,
99- 'api_adjustment ' ,
100- ],
101-
102- // Promotions
103- 'promotion ' => [
104- 'sylius_admin_partial_promotion ' ,
105- 'sylius_admin_promotion ' ,
106- 'sylius_admin_api_promotion ' ,
107- 'api_promo ' ,
108- ],
109-
110- // Shipping and Shipments
111- 'shipment ' => [
112- 'sylius_admin_partial_shipment ' ,
113- 'sylius_admin_ship ' ,
114- 'sylius_admin_api_ship ' ,
115- 'api_ship ' ,
116- ],
117-
118- // Inventory
119- 'inventory ' => [
120- 'sylius_admin_inventory ' ,
121- ],
122-
123- // Attributes
124- 'attribute ' => [
125- 'sylius_admin_get_attribute_types ' ,
126- 'sylius_admin_get_product_attributes ' ,
127- 'sylius_admin_render_attribute_forms ' ,
128- ],
129-
130- // Payments
131- 'payment ' => [
132- 'sylius_admin_payment ' ,
133- 'sylius_admin_get_payment ' ,
134- 'payum_ ' ,
135- 'sylius_admin_api_payment ' ,
136- 'api_pay ' ,
137- ],
138-
139- // PayPal
140- 'paypal ' => [
141- 'sylius_paypal ' ,
142- ],
143-
144- // Taxes
145- 'tax ' => [
146- 'sylius_admin_tax_ ' ,
147- 'sylius_admin_api_tax_ ' ,
148- 'api_tax ' ,
149- ],
150-
151- // Currencies
152- 'currency ' => [
153- 'sylius_admin_currency ' ,
154- 'sylius_admin_api_currency ' ,
155- 'sylius_shop_switch_currency ' ,
156- 'api_currencies ' ,
157- ],
158-
159- // Exchange rates
160- 'exchange ' => [
161- 'sylius_admin_exchange ' ,
162- 'sylius_admin_api_exchange ' ,
163- 'api_exchange ' ,
164- ],
165-
166- // Zones
167- 'zone ' => [
168- 'sylius_admin_zone ' ,
169- 'sylius_admin_api_zone ' ,
170- 'api_zone ' ,
171- ],
172-
173- // Countries
174- 'country ' => [
175- 'sylius_admin_country ' ,
176- 'sylius_admin_api_country ' ,
177- 'api_countries ' ,
178- ],
179-
180- // Provinces
181- 'province ' => [
182- 'sylius_admin_api_province ' ,
183- 'sylius_admin_ajax_render_province_form ' ,
184- 'api_province ' ,
185- ],
186-
187- // Carts
188- 'cart ' => [
189- 'sylius_admin_api_cart ' ,
190- 'sylius_shop_ajax_cart ' ,
191- 'sylius_shop_partial_cart ' ,
192- 'sylius_shop_cart ' ,
193- 'api_cart ' ,
194- ],
195-
196- // Dashboard
197- 'dashboard ' => [
198- 'sylius_admin_dashboard_statistics ' ,
199- ],
200-
201- // Others
202- 'other ' => [
203- 'api_shop_billing ' ,
204- 'api_channels_shop ' ,
205- ],
206- ];
207-
20830 /**
20931 * @SuppressWarnings(PHPMD.CyclomaticComplexity)
21032 */
@@ -216,7 +38,7 @@ public function loadRoutes(LoaderInterface $loader): RouteCollection
21638 foreach ($ collection as $ name => $ route ) {
21739 foreach ($ routesToRemove as $ routeToRemove ) {
21840 if (false !== strpos ($ name , $ routeToRemove )) {
219- $ route ->setCondition ('not context.checkNoCommerce(params ) ' );
41+ $ route ->setCondition ('not context.checkNoCommerce() ' );
22042 }
22143 }
22244 }
@@ -239,27 +61,58 @@ private function getConfig(): ConfigInterface
23961 *
24062 * @SuppressWarnings(PHPMD.CyclomaticComplexity)
24163 */
242- private function getRoutesToRemove (): array
64+ public function getRoutesToRemove (): array
24365 {
24466 $ config = $ this ->getConfig ();
24567 $ routesToRemove = [];
68+ $ this ->routesToRemove = ConfigInterface::ROUTES_BY_GROUP ;
24669
70+ /** @deprecated */
24771 if ($ config ->areCustomersAllowed ()) {
24872 unset($ this ->routesToRemove ['customer ' ]);
24973 }
25074
75+ /** @deprecated */
25176 if ($ config ->areZonesAllowed ()) {
25277 unset($ this ->routesToRemove ['zone ' ]);
25378 }
25479
80+ /** @deprecated */
25581 if ($ config ->areZonesAllowed () || $ config ->areCountriesAllowed ()) {
25682 unset($ this ->routesToRemove ['country ' ]);
25783 }
25884
85+ // Loop on settings to add routes
86+ /** @var FeaturesProviderInterface $featuresProvider */
87+ $ featuresProvider = $ this ->container ->get ('monsieurbiz.no_commerce.provider.features_provider ' );
88+
89+ try {
90+ $ routesToEnable = $ featuresProvider ->getRoutesToEnable ();
91+ } catch (Exception $ e ) {
92+ $ routesToEnable = [];
93+ }
94+
95+ foreach ($ routesToEnable as $ route ) {
96+ $ this ->enableRoute ($ route );
97+ }
98+
25999 foreach ($ this ->routesToRemove as $ routes ) {
260100 $ routesToRemove = array_merge ($ routesToRemove , $ routes );
261101 }
262102
263103 return $ routesToRemove ;
264104 }
105+
106+ private function enableRoute (string $ route ): void
107+ {
108+ foreach ($ this ->routesToRemove as $ group => $ routes ) {
109+ if (false !== ($ key = array_search ($ route , $ routes , true ))) {
110+ unset($ this ->routesToRemove [$ group ][$ key ]);
111+ }
112+
113+ if (empty ($ this ->routesToRemove [$ group ])) {
114+ unset($ this ->routesToRemove [$ group ]);
115+ }
116+ }
117+ }
265118}
0 commit comments