2
<?php foreach (Mage::app()->getWebsites() as $website) {
    foreach ($website->getGroups() as $group) {
        $stores = $group->getStores();
        foreach ($stores as $store) {
            $storeCode = $store->getCode();
            echo '<link rel="alternate" hreflang="' . $storeCode . '" href="' . $store->getCurrentUrl(false) . '"/>' . "\n";
        }
    } } ?>

This produces, for example,

<link rel="alternate" hreflang="en_ca" href="http://mywebsite.com/en/?___store=en_ca">

But I want to remove ?___store=en_ca part.

I tried replacing:

$this->_href = $this->_href . $symbol . "___store=" . $store->getCode();

into:

$this->_href = $this->_href;

in app/code/core/Mage/Catalog/Block/Widget/Link.php

But didn't work.

How can I achieve this?

2
  • Why not remove it from the phtml file for the store/language switcher? Magento does however use this variable tho so it could have negative side effects to remove it Sep 4, 2015 at 6:36
  • What does your address bar say in your browser. Is it also extended by the storecode?
    – Nicolas
    Sep 4, 2015 at 6:39

3 Answers 3

0

Why not keep it simple.

Instead of making new module etc just remove last part of your string containing ?___store=en_ca

<?php foreach (Mage::app()->getWebsites() as $website) {
    foreach ($website->getGroups() as $group) {
        $stores = $group->getStores();
        foreach ($stores as $store) {

            // check if $url contain ?, if yes then strip last part of url
            $url = $store->getCurrentUrl(false); 
            if((strpos($url, '?') !== false)){ 
                $url = substr($url, 0, strrpos($url, "?"));
            }

            $storeCode = $store->getCode(); // addad url as variable
            echo '<link rel="alternate" hreflang="' . $storeCode . '" href="' . $url . '"/>' . "\n";
        }
    } } ?>
1
  • now the url link not contain ___store=en_ca.but store switcher not working Apr 13, 2017 at 4:34
0

You can change this setting in the admin area by going to System -> Configuration -> Web (under General) and it is in the Url Options tab.

2
  • If you mean "Add Store Code to Urls", then I have that set as No.
    – user9839
    Sep 4, 2015 at 7:45
  • @Smartie then the url shows store code. how to remove both store code and ?___store from url Apr 13, 2017 at 5:13
0

Found a solution here.

Copy app/code/core/mage/core/model/store.php to app/code/local/mage/core/model/store.php and

change from

return $storeParsedUrl['scheme'] . '://' . $storeParsedUrl['host']
            . (isset($storeParsedUrl['port']) ? ':' . $storeParsedUrl['port'] : '')
            . $storeParsedUrl['path'] . $requestString
            . ($storeParsedQuery ? '?'.http_build_query($storeParsedQuery, '', '&amp;') : '');

to

return $storeParsedUrl['scheme'] . '://' . $storeParsedUrl['host']
            . (isset($storeParsedUrl['port']) ? ':' . $storeParsedUrl['port'] : '')
            . $storeParsedUrl['path'] . $requestString;

So, remove . ($storeParsedQuery ? '?'.http_build_query($storeParsedQuery, '', '&') : '')

4
  • 1
    Even IF it required you to modify a core model class this is not the way to do it. You should use rewrites instead of just copying the file in to the local code pool.
    – Smartie
    Sep 4, 2015 at 7:39
  • How can I do that? I have this issue only with the URL output of hreflang link in <head>. I don't have this issue with the pages of the store (eg, product page etc.)
    – user9839
    Sep 4, 2015 at 7:43
  • inchoo.net/magento/… is a good article
    – Smartie
    Sep 4, 2015 at 7:54
  • now the url link not contain ___store=en_ca.but store switcher not working Apr 13, 2017 at 4:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.