Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento: Dash in Store Code

Tags:

seo

magento

I'm using Magento with multiple stores and store views (1 website, 4 stores with one store view each). I activated the option "add store code to urls" and can access my different stores via http://example.com/storecode/, which works fine. However i have one store code which should be named after two words for SEO purposes. Unfortunately Magento only allows to use an underscore (_) instead of a dash (-) as store code:

The store code may contain only letters (a-z), numbers (0-9) or underscore(_), the first character must be a letter.

As dashes are recommended to separate words in URLs, I'm looking for a method to use a dash as store code. Overriding Magento's validation is no problem, but I'm wondering if there's any special reason dashes are disabled here. Does anybody have an idea?

Thanks, Mathias

like image 571
maff Avatar asked Dec 11 '25 12:12

maff


1 Answers

You can always try and make a copy of Mage_Core_Model_Mysql4_Store in app/code/local and modify the regular expression to allow the dash. What may be the reason for it is the way Magento interprets _ as dividers or spaces in naming conventions.

I would presume there is a reason, but what that is specifically I'm not sure. If you do make the changes I would recommend doing it on a copy of your codebase/magento before hand to determine if there's any repercussions before doing it on a production site.

protected function _beforeSave(Mage_Core_Model_Abstract $model)
{
    if(!preg_match('/^[a-z]+[a-z0-9_\-]*$/',$model->getCode())) {
        Mage::throwException(
            Mage::helper('core')->__('The store code may contain only letters (a-z), numbers (0-9) or underscore(_), the first character must be a letter'));
    }

    return $this;
}
like image 142
B00MER Avatar answered Dec 16 '25 03:12

B00MER



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!