architecture icon indicating copy to clipboard operation
architecture copied to clipboard

Scope management for 'web/url/use_store' config value

Open Nolwennig-Jeulin opened this issue 6 months ago • 3 comments

Hi,

I wonder why Plugin/RouteParamsResolver getValue scope by store then that impossible to set store_view scope for field id="use_store" value ?

https://github.com/magento/magento2/blob/a947b306335294f61ab633ef75d9047c29988a9b/app/code/Magento/Backend/etc/adminhtml/system.xml#L511 <field id="use_store" translate="label comment" type="select" sortOrder="10" showInDefault="1" canRestore="1">

https://github.com/magento/magento2/blob/a947b306335294f61ab633ef75d9047c29988a9b/app/code/Magento/Store/Url/Plugin/RouteParamsResolver.php#L77

$useStoreInUrl = $this->scopeConfig->getValue(
       Store::XML_PATH_STORE_IN_URL,
-->    StoreScopeInterface::SCOPE_STORE,
       $storeCode
);

(since 2014 at https://github.com/magento/magento2/blob/9c2b633621e69bf2ea0480c1759c4d66739af29b/app/code/Magento/Core/Model/Url/RouteParamsResolver.php#L130 )


This is not a completely selfless request because I would need a website with the store_code in the URL and another website with no store_code in the URL. And this on the same Magento instance.

Nolwennig-Jeulin avatar Jul 11 '25 09:07 Nolwennig-Jeulin

Hi @Nolwennig-Jeulin I faced the same issue by the past and come with this module: https://github.com/opengento/magento2-store-path-url

It should do exactly what you are looking for, it allows you to set how the path in the url should be (store code, country, locale...). You can then check an option to not use the store path if your website contains a single store view (so it act like by default, and the store is resolved thanks to the configured base url).

You can also setup custom path by store if you want to. Store that are not part of the map wont have store path in url.

thomas-kl1 avatar Jul 11 '25 09:07 thomas-kl1

However to answer your first concern, Magento can't resolve if it should interpret a store code in the path, because it needs first to resolve the current store for that (egg or chicken problem).

The only case where you may have a store setup at bootstrap is if the variables MAGE_RUN_CODE and MAGE_RUN_TYPE are set. In this case fetching if the current store has store code in the path is not relevant and the config should be global.

thomas-kl1 avatar Jul 11 '25 10:07 thomas-kl1

Great !!!

This do perfectly the job !!

Nolwennig-Jeulin avatar Jul 15 '25 14:07 Nolwennig-Jeulin