Advertisement
eyemaginesrobbins

magento: get same url in other store views

Jan 2nd, 2014
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.99 KB | None | 0 0
  1. <?php
  2.  
  3. include 'app/Mage.php';
  4. Mage::app();
  5.  
  6. $langStores = array();
  7. $stores = Mage::app()->getStores();
  8. $currentUrl = Mage::helper('core/url')->getCurrentUrl();
  9. $currentStore = Mage::app()->getStore();
  10. $urlType = Mage_Core_Model_Store::URL_TYPE_LINK;
  11. $xmlLocalPath = Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE;
  12. $isCurrentlySecure = $currentStore->isCurrentlySecure();
  13. $currentBaseUrl = $currentStore->getBaseUrl($urlType, $isCurrentlySecure);
  14.  
  15. foreach ($stores as $store) {
  16.     if ($store->getIsActive() && $store->getId() != $currentStore->getId()) {
  17.         $lang = Mage::getStoreConfig($xmlLocalPath, $store->getId());
  18.         $lang = strtolower(str_replace("_", '-', $lang));
  19.         $langStores[$lang] = $store->getBaseUrl($urlType, $isCurrentlySecure);
  20.     }
  21. }
  22.  
  23. $currentUri = str_replace($currentBaseUrl, '', $currentUrl);
  24.  
  25. foreach ($langStores as $lang => $url) {
  26.     echo '<link rel="alternate" hreflang="' . $lang . '" href="' . $url . $currentUri . '" />' . PHP_EOL;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement