Everything you need to know about NexoPOS.
Each module has by default its web and API routes loaded on NexoPOS 4.x once it's enabled. However, if you would like your module to be working within a sub-store, you'll need to register your routes (web and API) for the MultiStore module.
Throughout his life cycle, the Multi-Store module triggers various events that can be used to include a module route that will be extended by the multi-store module. It will extend these by adding a prefix on each route and route name.
Within your service provider, you need to listen to the event "Modules\NsMultiStore\Events\MultiStoreWebRoutesLoadedEvent" and "Modules\NsMutliStore\Events\MultiStoreApiRoutesLoadedEvent" in order to include your routes file. Here is how you'll proceed.
Note that here, instead of loading "web.php" for the web routes, we're loading the "multistore" file. For every module that wants to add support for the multistore module, they'll need to define all their route on a "mutlistore.php", and from the "web.php", that file should be included like so :
Note that here we need to include that route within the prefixed group "dashboard".
If your route uses a static name, then on multistore, only the last store route will overwrite others. This means, for example, if you have 2 stores, the multistore module will generate routes like this.
// store 1 route /dashboard/store/1/mymodule/orders // store 2 route /dashboard/store/2/mymodule/orders
If the same name is used for both routes, then by calling "route" helper, only the route for the second route will be returned. We, therefore, need to provide a prefix for the route's name. Here is how you'll proceed :
Note that here, we haven't mentioned the "dashboard" prefix. This means ideally, that you should have a file named "mutlistore.php" prefix as all modules routes, either on web.php or api.php are prefixed by "/dashboard" already.
Now it might be useful to know how you can use these route names as using the traditional "route()" function helper won't work. We'll use another helper available in the CoreService class, that is : ns()->route(). This function is extended by the Multi-Store module and inject a store prefix whenever the function is called within a store.
Here is how you'll do it while creating a menu.