we have a multistore with many languages. Now the situation exists where 1 language can have a category that the other does not. So store1/en has store1/en/blueshoes and store2/fr does not sell blue shoes. The category is disabled (greyed out) in the category config.
So in short: you click the flag in the header and that store changes language. Only to see that the result is a 404.
I think this can be called a small bug in Magento. Or at least a choice should be give how to solve this in the backend. I can think of three options.
- don't show the flag / language switcher in this situation
- change the link to link to the main page
- keep showing 404 (current behavior)
All these solutions can be created, but only if we can find out that
$_lang->getCurrentUrl() cannot find an active CurrentUrl for the current language shop in the foreach statement. So it returns false or we can detect the existance of the URL via another method: does it exist and/or is it activated. In the case that is does not exist or it is not actived: then revert to options 1,2 and 3 above.
Question: how can we find out if a certain
$_lang->getCurrentUrl() is not activated/does not exist so we can change the behavior and circumvent the 404.
<?php /** * Language switcher template * * @see Mage_Page_Block_Switch */ ?> <?php if(count($this->getStores())>1): ?> <div class="form-language"> <label for="select-language"><?php echo $this->__('Your Language:') ?></label> <select id="select-language" title="<?php echo $this->__('Your Language') ?>" onchange="window.location.href=this.value"> <?php foreach ($this->getStores() as $_lang): ?> <?php $_selected = ($_lang->getId() == $this->getCurrentStoreId()) ? ' selected="selected"' : '' ?> <option value="<?php echo $_lang->getCurrentUrl() ?>"<?php echo $_selected ?>><?php echo $this->escapeHtml($_lang->getName()) ?></option> <?php endforeach; ?> </select> </div> <?php endif; ?>