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?

  • 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 – Sander Mangel Sep 4 '15 at 6:36
  • What does your address bar say in your browser. Is it also extended by the storecode? – Nicolas Sep 4 '15 at 6:39
1

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";
        }
    } } ?>
  • now the url link not contain ___store=en_ca.but store switcher not working – Visakh B Sujathan Apr 13 '17 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.

  • If you mean "Add Store Code to Urls", then I have that set as No. – rtk0407 Sep 4 '15 at 7:45
  • @Smartie then the url shows store code. how to remove both store code and ?___store from url – Visakh B Sujathan Apr 13 '17 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, '', '&') : '')

  • 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 '15 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.) – rtk0407 Sep 4 '15 at 7:43
  • inchoo.net/magento/… is a good article – Smartie Sep 4 '15 at 7:54
  • now the url link not contain ___store=en_ca.but store switcher not working – Visakh B Sujathan Apr 13 '17 at 4:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.