2014-11-24 48 views
0

我想根據Magento中的位置更改商店。爲此,當用戶在瀏覽器中打開網站時,我創建了一個位置下拉菜單,他/她需要選擇它的位置,網站將根據他/她的輸入值重定向。根據Magento中的位置更改商店/網站

public function getLocationInfoByIp($observer) { 

     $location = $_POST['location']; 
     switch ($location) { 

      case "US": { 
        Mage::app()->setCurrentStore('en'); 
        break; 
      } 
      case "IN": { 
       Mage::app()->setCurrentStore('de'); 
       break; 
      } 
      default: { 
       Mage::app()->setCurrentStore('en'); 
       break; 
      } 
     } 
} 

從下拉菜單選擇位置之後提交彈出式時,變更商店。但刷新後再次將商店更改爲默認。

所以請建議解決此問題。

+0

使用其提供以下的geoip的位置 – Muk 2014-11-24 07:29:43

+0

可能的複製任何擴展: http://stackoverflow.com/questions/16103103/change-store-view-programtically-using-magento-event-observer – Harit 2014-11-24 07:34:25

+0

@Muk我不想要使用geoip擴展。其實我想讓訪客那裏的位置和在那裏的位置的基礎上,我想換magento的商店/網站 – gopising 2014-11-24 08:16:01

回答

-1

您需要更改條件

public function getLocationInfoByIp($observer) { 
    $store = ''; 
    $location = $_POST['location']; 
    if($location=='US' && Mage::app()->getStore()->getCode()!='en') 
    { 
     Mage::app()->setCurrentStore('en'); 

    }else if($location=='IN' && Mage::app()->getStore()->getCode()!='de') 
    { 
     Mage::app()->setCurrentStore('de'); 
    }else if(Mage::app()->getStore()->getCode()!='en') 
    { 
     Mage::app()->setCurrentStore('en'); 
    } 
} 
+0

這段代碼看起來和我用過的一樣,在我的代碼中,我使用了switch case,並且在其他條件下使用 – gopising 2014-11-24 09:42:59

0

當您在的index.php文件設置一個默認存儲,編輯這些線路可能發生這種情況;

/* Store or website code */ 
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : ''; //check this line 

/* Run store or run website */ 
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store'; 

Mage::run($mageRunCode, $mageRunType); 

如果設置一個商家代碼運行代碼更改爲默認(空白)這樣的詩句。