2020
2121final class FeaturesProvider implements FeaturesProviderInterface
2222{
23+ public const COUNTRIES_KEY = 'countries ' ;
24+
25+ public const CURRENCIES_KEY = 'currencies ' ;
26+
27+ public const INVENTORY_KEY = 'inventory ' ;
28+
29+ public const PAYMENT_KEY = 'payment ' ;
30+
31+ public const CATALOG_KEY = 'catalog ' ;
32+
33+ public const SHIPPING_KEY = 'shipping ' ;
34+
35+ public const TAX_KEY = 'tax ' ;
36+
37+ public const ZONES_KEY = 'zones ' ;
38+
39+ public const ADMIN_ROUTES_THAT_CAN_BE_RE_ENABLED = [
40+ self ::COUNTRIES_KEY => [
41+ 'sylius_admin_country ' ,
42+ 'sylius_admin_ajax_render_province_form ' ,
43+ ],
44+ self ::CURRENCIES_KEY => [
45+ 'sylius_admin_currency ' ,
46+ ],
47+ self ::INVENTORY_KEY => [
48+ 'sylius_admin_inventory ' ,
49+ ],
50+ self ::PAYMENT_KEY => [
51+ 'sylius_admin_payment_method ' ,
52+ ],
53+ self ::CATALOG_KEY => [
54+ 'sylius_admin_get_attribute_types ' ,
55+ 'sylius_admin_get_product_attributes ' ,
56+ 'sylius_admin_render_attribute_forms ' ,
57+ 'sylius_admin_product ' ,
58+ 'sylius_admin_ajax_product ' ,
59+ 'sylius_admin_partial_product ' ,
60+ 'sylius_admin_ajax_generate_product_slug ' ,
61+ 'sylius_admin_partial_taxon ' ,
62+ 'sylius_admin_ajax_taxon ' ,
63+ 'sylius_admin_taxon ' ,
64+ 'sylius_admin_ajax_generate_taxon_slug ' ,
65+ ],
66+ self ::SHIPPING_KEY => [
67+ 'sylius_admin_shipping ' ,
68+ ],
69+ self ::TAX_KEY => [
70+ 'sylius_admin_tax_ ' ,
71+ ],
72+ self ::ZONES_KEY => [
73+ 'sylius_admin_zone ' ,
74+ ],
75+ ];
76+
2377 private ChannelContextInterface $ channelContext ;
2478
2579 private SettingsInterface $ nocommerceSettings ;
@@ -38,7 +92,7 @@ public function isNoCommerceEnabledForChannel(?ChannelInterface $channel = null)
3892 if (null === $ channel ) {
3993 $ channel = $ this ->channelContext ->getChannel ();
4094 }
41- // In case we are getting a channel that does not exists yet we return null to have the channel set properly
95+ // In case we are getting a channel that does not exist yet, we return null to have the channel set properly
4296 if (null === $ channel ->getId ()) {
4397 return true ;
4498 }
@@ -48,4 +102,37 @@ public function isNoCommerceEnabledForChannel(?ChannelInterface $channel = null)
48102
49103 return (bool ) $ this ->nocommerceSettings ->getCurrentValue ($ channel , null , 'enabled ' );
50104 }
105+
106+ /**
107+ * @SuppressWarnings(PHPMD.CyclomaticComplexity)
108+ */
109+ public function isRouteForcedEnabled (array $ params = []): bool
110+ {
111+ if (!isset ($ params ['_route ' ])) {
112+ return false ;
113+ }
114+
115+ $ route = $ params ['_route ' ];
116+ $ channel = $ this ->channelContext ->getChannel ();
117+ /** @var ?array $reEnabledAdminRoutes */
118+ $ reEnabledAdminRoutes = $ this ->nocommerceSettings ->getCurrentValue ($ channel , null , 're_enabled_admin_routes ' );
119+
120+ if (empty ($ reEnabledAdminRoutes )) {
121+ return false ;
122+ }
123+
124+ // We are checking if we should re-enable the route
125+ foreach ($ reEnabledAdminRoutes as $ reEnabledAdminSection ) {
126+ if (!isset (self ::ADMIN_ROUTES_THAT_CAN_BE_RE_ENABLED [$ reEnabledAdminSection ])) {
127+ continue ;
128+ }
129+ foreach (self ::ADMIN_ROUTES_THAT_CAN_BE_RE_ENABLED [$ reEnabledAdminSection ] as $ reEnabledAdminRoute ) {
130+ if (false !== strpos ($ route , $ reEnabledAdminRoute )) {
131+ return true ;
132+ }
133+ }
134+ }
135+
136+ return false ;
137+ }
51138}
0 commit comments