I have a Magento 2.3 store with several store views for different languages, accessed via site.com/it, site.com/fr etc etc
The majority of products are accessible on all views but some are restricted to base only.
I'm having an issue where if a product is only assigned to the base store view, the site will load it in an incorrect store view. In most cases it loads it in Italian. Interestingly, if I go to the same url with the IT store code (e.g. if the problem url is domain.com/product, I go to domain.com/it/product) it 404's.
The funny thing is, I don't know why it's choosing a particular store view to load as default. There's no reason why Italian is treated as the store to display (as it alongside French and Netherlands has a sort order of 0).
Other things I have noticed:
- If I change the theme to base, the issue still occurs
- If I assign a product to more than 1 store view (for example base and italian) it loads the correct store view
getCurrentStoreCode();in the language switcher returns the incorrect store code, but
$store->getWebsite()->getCode()(from a custom extension) loads the correct code.
If anyone can shed some light on this, I would be most grateful. I have a feeling it could be how the stores are set up, but I'm fairly certain I've done it correctly.