4
votes

Magento has fields for a Product and Category to create custom SEO friendly URL keys. But when you have multiple stores, then you cannot normally have different URL keys for different stores because the field url_key is ‘GLOBAL’ by default. For products, you can update the url_key attribute’s is_default field to ‘Store Views‘ from Attribute Management. But for the category’s url_key field, you don’t have that option in Magento. But the field does exist in the database with the same attribute code but having different backend_model so you need to go to the database directly and change the ‘is_global’ field 1 to 0.

reference: http://www.devraju.com/magento/different-category-url-keys-for-different-store-views-in-magento/ see comments on the bottom of the page.

same issue here: Magento multilanguage - double change in language resuts in 404 (or how to change language within stores not views)

This strategy seems to work in older versions, but in 7.1 I am having trouble. When I go to Catalog >> Attributes >> Manage Attributes, the url_key attribute is already set to store view. See image below.

enter image description here

Furthermore the attribute table looks properly configured. See SQL below.

The Switching code looks like this:

    <?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->htmlEscape($_lang->getName()) ?></option>
        <?php endforeach; ?>
        </select>
    </div>
    <?php endif; ?>        

SQLs

SELECT * FROM eav_attribute WHERE attribute_code LIKE '%url_key%';  

attribute_id Attribute Id   entity_type_id Entity Type Id   attribute_code Attribute 
    Edit    Delete  43  3   url_key  catalog/category_attribute_backend_urlkey  
    Edit    Delete  97  4   url_key  catalog/product_attribute_backend_urlkey  


SELECT attribute_id, is_global FROM catalog_eav_attribute WHERE attribute_id=43;
SELECT attribute_id, is_global FROM catalog_eav_attribute WHERE attribute_id=97;


Full Texts  attribute_id Attribute ID   is_global Is Global
    Edit    Delete  43  0


Full Texts  attribute_id Attribute ID   is_global Is Global
    Edit    Delete  97  0

I also tried to solve it using re-write rules, but re-write rules do not seem to cover language switching. ref: http://www.magentocommerce.com/wiki/modules_reference/english/mage_adminhtml/urlrewrite/index

i am looking for solution with appropriate code modifications.

4
works well on a Vanilla Magento 1.7.0.2 ... so it's something on your end... did you run a reindex after changing url_key to store view level?FlorinelChis

4 Answers

1
votes

This thing took my couple of days too. I applied changing is_global field in related table but that only worked on my local server, could not make it working on live server(dont know why).

Trying number of solutions, I came across a simple solution from admin panel.

try

catalog-> URl rewirte management -> add url Rewrite -> select 'for category' ->select Category -> select store, add url, select redirect 'No' and save.

Note: This might not effect your menus links, you can add custom URLS in your menu category links.

0
votes

What if you duplicate the current category root tree and use a different url key, then assign each store it own root category tree. (Not the ideal solution but should work without any modification or programming)

See Creating and Assigning Root Categories

0
votes

I had a same problem, showing error while creating new products "product with "url_key" attribute already exists"

I changed url_key into as optional field, and it worked for me.